1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20#define DAC960_DriverVersion "2.5.49"
21#define DAC960_DriverDate "21 Aug 2007"
22
23
24#include <linux/module.h>
25#include <linux/types.h>
26#include <linux/miscdevice.h>
27#include <linux/blkdev.h>
28#include <linux/bio.h>
29#include <linux/completion.h>
30#include <linux/delay.h>
31#include <linux/genhd.h>
32#include <linux/hdreg.h>
33#include <linux/blkpg.h>
34#include <linux/dma-mapping.h>
35#include <linux/interrupt.h>
36#include <linux/ioport.h>
37#include <linux/mm.h>
38#include <linux/slab.h>
39#include <linux/proc_fs.h>
40#include <linux/reboot.h>
41#include <linux/spinlock.h>
42#include <linux/timer.h>
43#include <linux/pci.h>
44#include <linux/init.h>
45#include <linux/jiffies.h>
46#include <linux/random.h>
47#include <linux/scatterlist.h>
48#include <asm/io.h>
49#include <asm/uaccess.h>
50#include "DAC960.h"
51
52#define DAC960_GAM_MINOR 252
53
54
55static DAC960_Controller_T *DAC960_Controllers[DAC960_MaxControllers];
56static int DAC960_ControllerCount;
57static struct proc_dir_entry *DAC960_ProcDirectoryEntry;
58
59static long disk_size(DAC960_Controller_T *p, int drive_nr)
60{
61 if (p->FirmwareType == DAC960_V1_Controller) {
62 if (drive_nr >= p->LogicalDriveCount)
63 return 0;
64 return p->V1.LogicalDriveInformation[drive_nr].
65 LogicalDriveSize;
66 } else {
67 DAC960_V2_LogicalDeviceInfo_T *i =
68 p->V2.LogicalDeviceInformation[drive_nr];
69 if (i == NULL)
70 return 0;
71 return i->ConfigurableDeviceSize;
72 }
73}
74
75static int DAC960_open(struct inode *inode, struct file *file)
76{
77 struct gendisk *disk = inode->i_bdev->bd_disk;
78 DAC960_Controller_T *p = disk->queue->queuedata;
79 int drive_nr = (long)disk->private_data;
80
81 if (p->FirmwareType == DAC960_V1_Controller) {
82 if (p->V1.LogicalDriveInformation[drive_nr].
83 LogicalDriveState == DAC960_V1_LogicalDrive_Offline)
84 return -ENXIO;
85 } else {
86 DAC960_V2_LogicalDeviceInfo_T *i =
87 p->V2.LogicalDeviceInformation[drive_nr];
88 if (!i || i->LogicalDeviceState == DAC960_V2_LogicalDevice_Offline)
89 return -ENXIO;
90 }
91
92 check_disk_change(inode->i_bdev);
93
94 if (!get_capacity(p->disks[drive_nr]))
95 return -ENXIO;
96 return 0;
97}
98
99static int DAC960_getgeo(struct block_device *bdev, struct hd_geometry *geo)
100{
101 struct gendisk *disk = bdev->bd_disk;
102 DAC960_Controller_T *p = disk->queue->queuedata;
103 int drive_nr = (long)disk->private_data;
104
105 if (p->FirmwareType == DAC960_V1_Controller) {
106 geo->heads = p->V1.GeometryTranslationHeads;
107 geo->sectors = p->V1.GeometryTranslationSectors;
108 geo->cylinders = p->V1.LogicalDriveInformation[drive_nr].
109 LogicalDriveSize / (geo->heads * geo->sectors);
110 } else {
111 DAC960_V2_LogicalDeviceInfo_T *i =
112 p->V2.LogicalDeviceInformation[drive_nr];
113 switch (i->DriveGeometry) {
114 case DAC960_V2_Geometry_128_32:
115 geo->heads = 128;
116 geo->sectors = 32;
117 break;
118 case DAC960_V2_Geometry_255_63:
119 geo->heads = 255;
120 geo->sectors = 63;
121 break;
122 default:
123 DAC960_Error("Illegal Logical Device Geometry %d\n",
124 p, i->DriveGeometry);
125 return -EINVAL;
126 }
127
128 geo->cylinders = i->ConfigurableDeviceSize /
129 (geo->heads * geo->sectors);
130 }
131
132 return 0;
133}
134
135static int DAC960_media_changed(struct gendisk *disk)
136{
137 DAC960_Controller_T *p = disk->queue->queuedata;
138 int drive_nr = (long)disk->private_data;
139
140 if (!p->LogicalDriveInitiallyAccessible[drive_nr])
141 return 1;
142 return 0;
143}
144
145static int DAC960_revalidate_disk(struct gendisk *disk)
146{
147 DAC960_Controller_T *p = disk->queue->queuedata;
148 int unit = (long)disk->private_data;
149
150 set_capacity(disk, disk_size(p, unit));
151 return 0;
152}
153
154static struct block_device_operations DAC960_BlockDeviceOperations = {
155 .owner = THIS_MODULE,
156 .open = DAC960_open,
157 .getgeo = DAC960_getgeo,
158 .media_changed = DAC960_media_changed,
159 .revalidate_disk = DAC960_revalidate_disk,
160};
161
162
163
164
165
166
167
168static void DAC960_AnnounceDriver(DAC960_Controller_T *Controller)
169{
170 DAC960_Announce("***** DAC960 RAID Driver Version "
171 DAC960_DriverVersion " of "
172 DAC960_DriverDate " *****\n", Controller);
173 DAC960_Announce("Copyright 1998-2001 by Leonard N. Zubkoff "
174 "<lnz@dandelion.com>\n", Controller);
175}
176
177
178
179
180
181
182static bool DAC960_Failure(DAC960_Controller_T *Controller,
183 unsigned char *ErrorMessage)
184{
185 DAC960_Error("While configuring DAC960 PCI RAID Controller at\n",
186 Controller);
187 if (Controller->IO_Address == 0)
188 DAC960_Error("PCI Bus %d Device %d Function %d I/O Address N/A "
189 "PCI Address 0x%X\n", Controller,
190 Controller->Bus, Controller->Device,
191 Controller->Function, Controller->PCI_Address);
192 else DAC960_Error("PCI Bus %d Device %d Function %d I/O Address "
193 "0x%X PCI Address 0x%X\n", Controller,
194 Controller->Bus, Controller->Device,
195 Controller->Function, Controller->IO_Address,
196 Controller->PCI_Address);
197 DAC960_Error("%s FAILED - DETACHING\n", Controller, ErrorMessage);
198 return false;
199}
200
201
202
203
204
205
206
207
208
209
210
211static bool init_dma_loaf(struct pci_dev *dev, struct dma_loaf *loaf,
212 size_t len)
213{
214 void *cpu_addr;
215 dma_addr_t dma_handle;
216
217 cpu_addr = pci_alloc_consistent(dev, len, &dma_handle);
218 if (cpu_addr == NULL)
219 return false;
220
221 loaf->cpu_free = loaf->cpu_base = cpu_addr;
222 loaf->dma_free =loaf->dma_base = dma_handle;
223 loaf->length = len;
224 memset(cpu_addr, 0, len);
225 return true;
226}
227
228static void *slice_dma_loaf(struct dma_loaf *loaf, size_t len,
229 dma_addr_t *dma_handle)
230{
231 void *cpu_end = loaf->cpu_free + len;
232 void *cpu_addr = loaf->cpu_free;
233
234 BUG_ON(cpu_end > loaf->cpu_base + loaf->length);
235 *dma_handle = loaf->dma_free;
236 loaf->cpu_free = cpu_end;
237 loaf->dma_free += len;
238 return cpu_addr;
239}
240
241static void free_dma_loaf(struct pci_dev *dev, struct dma_loaf *loaf_handle)
242{
243 if (loaf_handle->cpu_base != NULL)
244 pci_free_consistent(dev, loaf_handle->length,
245 loaf_handle->cpu_base, loaf_handle->dma_base);
246}
247
248
249
250
251
252
253
254
255static bool DAC960_CreateAuxiliaryStructures(DAC960_Controller_T *Controller)
256{
257 int CommandAllocationLength, CommandAllocationGroupSize;
258 int CommandsRemaining = 0, CommandIdentifier, CommandGroupByteCount;
259 void *AllocationPointer = NULL;
260 void *ScatterGatherCPU = NULL;
261 dma_addr_t ScatterGatherDMA;
262 struct pci_pool *ScatterGatherPool;
263 void *RequestSenseCPU = NULL;
264 dma_addr_t RequestSenseDMA;
265 struct pci_pool *RequestSensePool = NULL;
266
267 if (Controller->FirmwareType == DAC960_V1_Controller)
268 {
269 CommandAllocationLength = offsetof(DAC960_Command_T, V1.EndMarker);
270 CommandAllocationGroupSize = DAC960_V1_CommandAllocationGroupSize;
271 ScatterGatherPool = pci_pool_create("DAC960_V1_ScatterGather",
272 Controller->PCIDevice,
273 DAC960_V1_ScatterGatherLimit * sizeof(DAC960_V1_ScatterGatherSegment_T),
274 sizeof(DAC960_V1_ScatterGatherSegment_T), 0);
275 if (ScatterGatherPool == NULL)
276 return DAC960_Failure(Controller,
277 "AUXILIARY STRUCTURE CREATION (SG)");
278 Controller->ScatterGatherPool = ScatterGatherPool;
279 }
280 else
281 {
282 CommandAllocationLength = offsetof(DAC960_Command_T, V2.EndMarker);
283 CommandAllocationGroupSize = DAC960_V2_CommandAllocationGroupSize;
284 ScatterGatherPool = pci_pool_create("DAC960_V2_ScatterGather",
285 Controller->PCIDevice,
286 DAC960_V2_ScatterGatherLimit * sizeof(DAC960_V2_ScatterGatherSegment_T),
287 sizeof(DAC960_V2_ScatterGatherSegment_T), 0);
288 if (ScatterGatherPool == NULL)
289 return DAC960_Failure(Controller,
290 "AUXILIARY STRUCTURE CREATION (SG)");
291 RequestSensePool = pci_pool_create("DAC960_V2_RequestSense",
292 Controller->PCIDevice, sizeof(DAC960_SCSI_RequestSense_T),
293 sizeof(int), 0);
294 if (RequestSensePool == NULL) {
295 pci_pool_destroy(ScatterGatherPool);
296 return DAC960_Failure(Controller,
297 "AUXILIARY STRUCTURE CREATION (SG)");
298 }
299 Controller->ScatterGatherPool = ScatterGatherPool;
300 Controller->V2.RequestSensePool = RequestSensePool;
301 }
302 Controller->CommandAllocationGroupSize = CommandAllocationGroupSize;
303 Controller->FreeCommands = NULL;
304 for (CommandIdentifier = 1;
305 CommandIdentifier <= Controller->DriverQueueDepth;
306 CommandIdentifier++)
307 {
308 DAC960_Command_T *Command;
309 if (--CommandsRemaining <= 0)
310 {
311 CommandsRemaining =
312 Controller->DriverQueueDepth - CommandIdentifier + 1;
313 if (CommandsRemaining > CommandAllocationGroupSize)
314 CommandsRemaining = CommandAllocationGroupSize;
315 CommandGroupByteCount =
316 CommandsRemaining * CommandAllocationLength;
317 AllocationPointer = kzalloc(CommandGroupByteCount, GFP_ATOMIC);
318 if (AllocationPointer == NULL)
319 return DAC960_Failure(Controller,
320 "AUXILIARY STRUCTURE CREATION");
321 }
322 Command = (DAC960_Command_T *) AllocationPointer;
323 AllocationPointer += CommandAllocationLength;
324 Command->CommandIdentifier = CommandIdentifier;
325 Command->Controller = Controller;
326 Command->Next = Controller->FreeCommands;
327 Controller->FreeCommands = Command;
328 Controller->Commands[CommandIdentifier-1] = Command;
329 ScatterGatherCPU = pci_pool_alloc(ScatterGatherPool, GFP_ATOMIC,
330 &ScatterGatherDMA);
331 if (ScatterGatherCPU == NULL)
332 return DAC960_Failure(Controller, "AUXILIARY STRUCTURE CREATION");
333
334 if (RequestSensePool != NULL) {
335 RequestSenseCPU = pci_pool_alloc(RequestSensePool, GFP_ATOMIC,
336 &RequestSenseDMA);
337 if (RequestSenseCPU == NULL) {
338 pci_pool_free(ScatterGatherPool, ScatterGatherCPU,
339 ScatterGatherDMA);
340 return DAC960_Failure(Controller,
341 "AUXILIARY STRUCTURE CREATION");
342 }
343 }
344 if (Controller->FirmwareType == DAC960_V1_Controller) {
345 Command->cmd_sglist = Command->V1.ScatterList;
346 Command->V1.ScatterGatherList =
347 (DAC960_V1_ScatterGatherSegment_T *)ScatterGatherCPU;
348 Command->V1.ScatterGatherListDMA = ScatterGatherDMA;
349 sg_init_table(Command->cmd_sglist, DAC960_V1_ScatterGatherLimit);
350 } else {
351 Command->cmd_sglist = Command->V2.ScatterList;
352 Command->V2.ScatterGatherList =
353 (DAC960_V2_ScatterGatherSegment_T *)ScatterGatherCPU;
354 Command->V2.ScatterGatherListDMA = ScatterGatherDMA;
355 Command->V2.RequestSense =
356 (DAC960_SCSI_RequestSense_T *)RequestSenseCPU;
357 Command->V2.RequestSenseDMA = RequestSenseDMA;
358 sg_init_table(Command->cmd_sglist, DAC960_V2_ScatterGatherLimit);
359 }
360 }
361 return true;
362}
363
364
365
366
367
368
369
370static void DAC960_DestroyAuxiliaryStructures(DAC960_Controller_T *Controller)
371{
372 int i;
373 struct pci_pool *ScatterGatherPool = Controller->ScatterGatherPool;
374 struct pci_pool *RequestSensePool = NULL;
375 void *ScatterGatherCPU;
376 dma_addr_t ScatterGatherDMA;
377 void *RequestSenseCPU;
378 dma_addr_t RequestSenseDMA;
379 DAC960_Command_T *CommandGroup = NULL;
380
381
382 if (Controller->FirmwareType == DAC960_V2_Controller)
383 RequestSensePool = Controller->V2.RequestSensePool;
384
385 Controller->FreeCommands = NULL;
386 for (i = 0; i < Controller->DriverQueueDepth; i++)
387 {
388 DAC960_Command_T *Command = Controller->Commands[i];
389
390 if (Command == NULL)
391 continue;
392
393 if (Controller->FirmwareType == DAC960_V1_Controller) {
394 ScatterGatherCPU = (void *)Command->V1.ScatterGatherList;
395 ScatterGatherDMA = Command->V1.ScatterGatherListDMA;
396 RequestSenseCPU = NULL;
397 RequestSenseDMA = (dma_addr_t)0;
398 } else {
399 ScatterGatherCPU = (void *)Command->V2.ScatterGatherList;
400 ScatterGatherDMA = Command->V2.ScatterGatherListDMA;
401 RequestSenseCPU = (void *)Command->V2.RequestSense;
402 RequestSenseDMA = Command->V2.RequestSenseDMA;
403 }
404 if (ScatterGatherCPU != NULL)
405 pci_pool_free(ScatterGatherPool, ScatterGatherCPU, ScatterGatherDMA);
406 if (RequestSenseCPU != NULL)
407 pci_pool_free(RequestSensePool, RequestSenseCPU, RequestSenseDMA);
408
409 if ((Command->CommandIdentifier
410 % Controller->CommandAllocationGroupSize) == 1) {
411
412
413
414
415
416
417 kfree(CommandGroup);
418 CommandGroup = Command;
419 }
420 Controller->Commands[i] = NULL;
421 }
422 kfree(CommandGroup);
423
424 if (Controller->CombinedStatusBuffer != NULL)
425 {
426 kfree(Controller->CombinedStatusBuffer);
427 Controller->CombinedStatusBuffer = NULL;
428 Controller->CurrentStatusBuffer = NULL;
429 }
430
431 if (ScatterGatherPool != NULL)
432 pci_pool_destroy(ScatterGatherPool);
433 if (Controller->FirmwareType == DAC960_V1_Controller)
434 return;
435
436 if (RequestSensePool != NULL)
437 pci_pool_destroy(RequestSensePool);
438
439 for (i = 0; i < DAC960_MaxLogicalDrives; i++) {
440 kfree(Controller->V2.LogicalDeviceInformation[i]);
441 Controller->V2.LogicalDeviceInformation[i] = NULL;
442 }
443
444 for (i = 0; i < DAC960_V2_MaxPhysicalDevices; i++)
445 {
446 kfree(Controller->V2.PhysicalDeviceInformation[i]);
447 Controller->V2.PhysicalDeviceInformation[i] = NULL;
448 kfree(Controller->V2.InquiryUnitSerialNumber[i]);
449 Controller->V2.InquiryUnitSerialNumber[i] = NULL;
450 }
451}
452
453
454
455
456
457
458
459static inline void DAC960_V1_ClearCommand(DAC960_Command_T *Command)
460{
461 DAC960_V1_CommandMailbox_T *CommandMailbox = &Command->V1.CommandMailbox;
462 memset(CommandMailbox, 0, sizeof(DAC960_V1_CommandMailbox_T));
463 Command->V1.CommandStatus = 0;
464}
465
466
467
468
469
470
471
472static inline void DAC960_V2_ClearCommand(DAC960_Command_T *Command)
473{
474 DAC960_V2_CommandMailbox_T *CommandMailbox = &Command->V2.CommandMailbox;
475 memset(CommandMailbox, 0, sizeof(DAC960_V2_CommandMailbox_T));
476 Command->V2.CommandStatus = 0;
477}
478
479
480
481
482
483
484
485
486
487static inline DAC960_Command_T *DAC960_AllocateCommand(DAC960_Controller_T
488 *Controller)
489{
490 DAC960_Command_T *Command = Controller->FreeCommands;
491 if (Command == NULL) return NULL;
492 Controller->FreeCommands = Command->Next;
493 Command->Next = NULL;
494 return Command;
495}
496
497
498
499
500
501
502
503static inline void DAC960_DeallocateCommand(DAC960_Command_T *Command)
504{
505 DAC960_Controller_T *Controller = Command->Controller;
506
507 Command->Request = NULL;
508 Command->Next = Controller->FreeCommands;
509 Controller->FreeCommands = Command;
510}
511
512
513
514
515
516
517static void DAC960_WaitForCommand(DAC960_Controller_T *Controller)
518{
519 spin_unlock_irq(&Controller->queue_lock);
520 __wait_event(Controller->CommandWaitQueue, Controller->FreeCommands);
521 spin_lock_irq(&Controller->queue_lock);
522}
523
524
525
526
527
528static void DAC960_GEM_QueueCommand(DAC960_Command_T *Command)
529{
530 DAC960_Controller_T *Controller = Command->Controller;
531 void __iomem *ControllerBaseAddress = Controller->BaseAddress;
532 DAC960_V2_CommandMailbox_T *CommandMailbox = &Command->V2.CommandMailbox;
533 DAC960_V2_CommandMailbox_T *NextCommandMailbox =
534 Controller->V2.NextCommandMailbox;
535
536 CommandMailbox->Common.CommandIdentifier = Command->CommandIdentifier;
537 DAC960_GEM_WriteCommandMailbox(NextCommandMailbox, CommandMailbox);
538
539 if (Controller->V2.PreviousCommandMailbox1->Words[0] == 0 ||
540 Controller->V2.PreviousCommandMailbox2->Words[0] == 0)
541 DAC960_GEM_MemoryMailboxNewCommand(ControllerBaseAddress);
542
543 Controller->V2.PreviousCommandMailbox2 =
544 Controller->V2.PreviousCommandMailbox1;
545 Controller->V2.PreviousCommandMailbox1 = NextCommandMailbox;
546
547 if (++NextCommandMailbox > Controller->V2.LastCommandMailbox)
548 NextCommandMailbox = Controller->V2.FirstCommandMailbox;
549
550 Controller->V2.NextCommandMailbox = NextCommandMailbox;
551}
552
553
554
555
556
557static void DAC960_BA_QueueCommand(DAC960_Command_T *Command)
558{
559 DAC960_Controller_T *Controller = Command->Controller;
560 void __iomem *ControllerBaseAddress = Controller->BaseAddress;
561 DAC960_V2_CommandMailbox_T *CommandMailbox = &Command->V2.CommandMailbox;
562 DAC960_V2_CommandMailbox_T *NextCommandMailbox =
563 Controller->V2.NextCommandMailbox;
564 CommandMailbox->Common.CommandIdentifier = Command->CommandIdentifier;
565 DAC960_BA_WriteCommandMailbox(NextCommandMailbox, CommandMailbox);
566 if (Controller->V2.PreviousCommandMailbox1->Words[0] == 0 ||
567 Controller->V2.PreviousCommandMailbox2->Words[0] == 0)
568 DAC960_BA_MemoryMailboxNewCommand(ControllerBaseAddress);
569 Controller->V2.PreviousCommandMailbox2 =
570 Controller->V2.PreviousCommandMailbox1;
571 Controller->V2.PreviousCommandMailbox1 = NextCommandMailbox;
572 if (++NextCommandMailbox > Controller->V2.LastCommandMailbox)
573 NextCommandMailbox = Controller->V2.FirstCommandMailbox;
574 Controller->V2.NextCommandMailbox = NextCommandMailbox;
575}
576
577
578
579
580
581
582static void DAC960_LP_QueueCommand(DAC960_Command_T *Command)
583{
584 DAC960_Controller_T *Controller = Command->Controller;
585 void __iomem *ControllerBaseAddress = Controller->BaseAddress;
586 DAC960_V2_CommandMailbox_T *CommandMailbox = &Command->V2.CommandMailbox;
587 DAC960_V2_CommandMailbox_T *NextCommandMailbox =
588 Controller->V2.NextCommandMailbox;
589 CommandMailbox->Common.CommandIdentifier = Command->CommandIdentifier;
590 DAC960_LP_WriteCommandMailbox(NextCommandMailbox, CommandMailbox);
591 if (Controller->V2.PreviousCommandMailbox1->Words[0] == 0 ||
592 Controller->V2.PreviousCommandMailbox2->Words[0] == 0)
593 DAC960_LP_MemoryMailboxNewCommand(ControllerBaseAddress);
594 Controller->V2.PreviousCommandMailbox2 =
595 Controller->V2.PreviousCommandMailbox1;
596 Controller->V2.PreviousCommandMailbox1 = NextCommandMailbox;
597 if (++NextCommandMailbox > Controller->V2.LastCommandMailbox)
598 NextCommandMailbox = Controller->V2.FirstCommandMailbox;
599 Controller->V2.NextCommandMailbox = NextCommandMailbox;
600}
601
602
603
604
605
606
607
608static void DAC960_LA_QueueCommandDualMode(DAC960_Command_T *Command)
609{
610 DAC960_Controller_T *Controller = Command->Controller;
611 void __iomem *ControllerBaseAddress = Controller->BaseAddress;
612 DAC960_V1_CommandMailbox_T *CommandMailbox = &Command->V1.CommandMailbox;
613 DAC960_V1_CommandMailbox_T *NextCommandMailbox =
614 Controller->V1.NextCommandMailbox;
615 CommandMailbox->Common.CommandIdentifier = Command->CommandIdentifier;
616 DAC960_LA_WriteCommandMailbox(NextCommandMailbox, CommandMailbox);
617 if (Controller->V1.PreviousCommandMailbox1->Words[0] == 0 ||
618 Controller->V1.PreviousCommandMailbox2->Words[0] == 0)
619 DAC960_LA_MemoryMailboxNewCommand(ControllerBaseAddress);
620 Controller->V1.PreviousCommandMailbox2 =
621 Controller->V1.PreviousCommandMailbox1;
622 Controller->V1.PreviousCommandMailbox1 = NextCommandMailbox;
623 if (++NextCommandMailbox > Controller->V1.LastCommandMailbox)
624 NextCommandMailbox = Controller->V1.FirstCommandMailbox;
625 Controller->V1.NextCommandMailbox = NextCommandMailbox;
626}
627
628
629
630
631
632
633
634static void DAC960_LA_QueueCommandSingleMode(DAC960_Command_T *Command)
635{
636 DAC960_Controller_T *Controller = Command->Controller;
637 void __iomem *ControllerBaseAddress = Controller->BaseAddress;
638 DAC960_V1_CommandMailbox_T *CommandMailbox = &Command->V1.CommandMailbox;
639 DAC960_V1_CommandMailbox_T *NextCommandMailbox =
640 Controller->V1.NextCommandMailbox;
641 CommandMailbox->Common.CommandIdentifier = Command->CommandIdentifier;
642 DAC960_LA_WriteCommandMailbox(NextCommandMailbox, CommandMailbox);
643 if (Controller->V1.PreviousCommandMailbox1->Words[0] == 0 ||
644 Controller->V1.PreviousCommandMailbox2->Words[0] == 0)
645 DAC960_LA_HardwareMailboxNewCommand(ControllerBaseAddress);
646 Controller->V1.PreviousCommandMailbox2 =
647 Controller->V1.PreviousCommandMailbox1;
648 Controller->V1.PreviousCommandMailbox1 = NextCommandMailbox;
649 if (++NextCommandMailbox > Controller->V1.LastCommandMailbox)
650 NextCommandMailbox = Controller->V1.FirstCommandMailbox;
651 Controller->V1.NextCommandMailbox = NextCommandMailbox;
652}
653
654
655
656
657
658
659
660static void DAC960_PG_QueueCommandDualMode(DAC960_Command_T *Command)
661{
662 DAC960_Controller_T *Controller = Command->Controller;
663 void __iomem *ControllerBaseAddress = Controller->BaseAddress;
664 DAC960_V1_CommandMailbox_T *CommandMailbox = &Command->V1.CommandMailbox;
665 DAC960_V1_CommandMailbox_T *NextCommandMailbox =
666 Controller->V1.NextCommandMailbox;
667 CommandMailbox->Common.CommandIdentifier = Command->CommandIdentifier;
668 DAC960_PG_WriteCommandMailbox(NextCommandMailbox, CommandMailbox);
669 if (Controller->V1.PreviousCommandMailbox1->Words[0] == 0 ||
670 Controller->V1.PreviousCommandMailbox2->Words[0] == 0)
671 DAC960_PG_MemoryMailboxNewCommand(ControllerBaseAddress);
672 Controller->V1.PreviousCommandMailbox2 =
673 Controller->V1.PreviousCommandMailbox1;
674 Controller->V1.PreviousCommandMailbox1 = NextCommandMailbox;
675 if (++NextCommandMailbox > Controller->V1.LastCommandMailbox)
676 NextCommandMailbox = Controller->V1.FirstCommandMailbox;
677 Controller->V1.NextCommandMailbox = NextCommandMailbox;
678}
679
680
681
682
683
684
685
686static void DAC960_PG_QueueCommandSingleMode(DAC960_Command_T *Command)
687{
688 DAC960_Controller_T *Controller = Command->Controller;
689 void __iomem *ControllerBaseAddress = Controller->BaseAddress;
690 DAC960_V1_CommandMailbox_T *CommandMailbox = &Command->V1.CommandMailbox;
691 DAC960_V1_CommandMailbox_T *NextCommandMailbox =
692 Controller->V1.NextCommandMailbox;
693 CommandMailbox->Common.CommandIdentifier = Command->CommandIdentifier;
694 DAC960_PG_WriteCommandMailbox(NextCommandMailbox, CommandMailbox);
695 if (Controller->V1.PreviousCommandMailbox1->Words[0] == 0 ||
696 Controller->V1.PreviousCommandMailbox2->Words[0] == 0)
697 DAC960_PG_HardwareMailboxNewCommand(ControllerBaseAddress);
698 Controller->V1.PreviousCommandMailbox2 =
699 Controller->V1.PreviousCommandMailbox1;
700 Controller->V1.PreviousCommandMailbox1 = NextCommandMailbox;
701 if (++NextCommandMailbox > Controller->V1.LastCommandMailbox)
702 NextCommandMailbox = Controller->V1.FirstCommandMailbox;
703 Controller->V1.NextCommandMailbox = NextCommandMailbox;
704}
705
706
707
708
709
710
711static void DAC960_PD_QueueCommand(DAC960_Command_T *Command)
712{
713 DAC960_Controller_T *Controller = Command->Controller;
714 void __iomem *ControllerBaseAddress = Controller->BaseAddress;
715 DAC960_V1_CommandMailbox_T *CommandMailbox = &Command->V1.CommandMailbox;
716 CommandMailbox->Common.CommandIdentifier = Command->CommandIdentifier;
717 while (DAC960_PD_MailboxFullP(ControllerBaseAddress))
718 udelay(1);
719 DAC960_PD_WriteCommandMailbox(ControllerBaseAddress, CommandMailbox);
720 DAC960_PD_NewCommand(ControllerBaseAddress);
721}
722
723
724
725
726
727
728static void DAC960_P_QueueCommand(DAC960_Command_T *Command)
729{
730 DAC960_Controller_T *Controller = Command->Controller;
731 void __iomem *ControllerBaseAddress = Controller->BaseAddress;
732 DAC960_V1_CommandMailbox_T *CommandMailbox = &Command->V1.CommandMailbox;
733 CommandMailbox->Common.CommandIdentifier = Command->CommandIdentifier;
734 switch (CommandMailbox->Common.CommandOpcode)
735 {
736 case DAC960_V1_Enquiry:
737 CommandMailbox->Common.CommandOpcode = DAC960_V1_Enquiry_Old;
738 break;
739 case DAC960_V1_GetDeviceState:
740 CommandMailbox->Common.CommandOpcode = DAC960_V1_GetDeviceState_Old;
741 break;
742 case DAC960_V1_Read:
743 CommandMailbox->Common.CommandOpcode = DAC960_V1_Read_Old;
744 DAC960_PD_To_P_TranslateReadWriteCommand(CommandMailbox);
745 break;
746 case DAC960_V1_Write:
747 CommandMailbox->Common.CommandOpcode = DAC960_V1_Write_Old;
748 DAC960_PD_To_P_TranslateReadWriteCommand(CommandMailbox);
749 break;
750 case DAC960_V1_ReadWithScatterGather:
751 CommandMailbox->Common.CommandOpcode =
752 DAC960_V1_ReadWithScatterGather_Old;
753 DAC960_PD_To_P_TranslateReadWriteCommand(CommandMailbox);
754 break;
755 case DAC960_V1_WriteWithScatterGather:
756 CommandMailbox->Common.CommandOpcode =
757 DAC960_V1_WriteWithScatterGather_Old;
758 DAC960_PD_To_P_TranslateReadWriteCommand(CommandMailbox);
759 break;
760 default:
761 break;
762 }
763 while (DAC960_PD_MailboxFullP(ControllerBaseAddress))
764 udelay(1);
765 DAC960_PD_WriteCommandMailbox(ControllerBaseAddress, CommandMailbox);
766 DAC960_PD_NewCommand(ControllerBaseAddress);
767}
768
769
770
771
772
773
774static void DAC960_ExecuteCommand(DAC960_Command_T *Command)
775{
776 DAC960_Controller_T *Controller = Command->Controller;
777 DECLARE_COMPLETION_ONSTACK(Completion);
778 unsigned long flags;
779 Command->Completion = &Completion;
780
781 spin_lock_irqsave(&Controller->queue_lock, flags);
782 DAC960_QueueCommand(Command);
783 spin_unlock_irqrestore(&Controller->queue_lock, flags);
784
785 if (in_interrupt())
786 return;
787 wait_for_completion(&Completion);
788}
789
790
791
792
793
794
795
796
797static bool DAC960_V1_ExecuteType3(DAC960_Controller_T *Controller,
798 DAC960_V1_CommandOpcode_T CommandOpcode,
799 dma_addr_t DataDMA)
800{
801 DAC960_Command_T *Command = DAC960_AllocateCommand(Controller);
802 DAC960_V1_CommandMailbox_T *CommandMailbox = &Command->V1.CommandMailbox;
803 DAC960_V1_CommandStatus_T CommandStatus;
804 DAC960_V1_ClearCommand(Command);
805 Command->CommandType = DAC960_ImmediateCommand;
806 CommandMailbox->Type3.CommandOpcode = CommandOpcode;
807 CommandMailbox->Type3.BusAddress = DataDMA;
808 DAC960_ExecuteCommand(Command);
809 CommandStatus = Command->V1.CommandStatus;
810 DAC960_DeallocateCommand(Command);
811 return (CommandStatus == DAC960_V1_NormalCompletion);
812}
813
814
815
816
817
818
819
820
821static bool DAC960_V1_ExecuteType3B(DAC960_Controller_T *Controller,
822 DAC960_V1_CommandOpcode_T CommandOpcode,
823 unsigned char CommandOpcode2,
824 dma_addr_t DataDMA)
825{
826 DAC960_Command_T *Command = DAC960_AllocateCommand(Controller);
827 DAC960_V1_CommandMailbox_T *CommandMailbox = &Command->V1.CommandMailbox;
828 DAC960_V1_CommandStatus_T CommandStatus;
829 DAC960_V1_ClearCommand(Command);
830 Command->CommandType = DAC960_ImmediateCommand;
831 CommandMailbox->Type3B.CommandOpcode = CommandOpcode;
832 CommandMailbox->Type3B.CommandOpcode2 = CommandOpcode2;
833 CommandMailbox->Type3B.BusAddress = DataDMA;
834 DAC960_ExecuteCommand(Command);
835 CommandStatus = Command->V1.CommandStatus;
836 DAC960_DeallocateCommand(Command);
837 return (CommandStatus == DAC960_V1_NormalCompletion);
838}
839
840
841
842
843
844
845
846
847static bool DAC960_V1_ExecuteType3D(DAC960_Controller_T *Controller,
848 DAC960_V1_CommandOpcode_T CommandOpcode,
849 unsigned char Channel,
850 unsigned char TargetID,
851 dma_addr_t DataDMA)
852{
853 DAC960_Command_T *Command = DAC960_AllocateCommand(Controller);
854 DAC960_V1_CommandMailbox_T *CommandMailbox = &Command->V1.CommandMailbox;
855 DAC960_V1_CommandStatus_T CommandStatus;
856 DAC960_V1_ClearCommand(Command);
857 Command->CommandType = DAC960_ImmediateCommand;
858 CommandMailbox->Type3D.CommandOpcode = CommandOpcode;
859 CommandMailbox->Type3D.Channel = Channel;
860 CommandMailbox->Type3D.TargetID = TargetID;
861 CommandMailbox->Type3D.BusAddress = DataDMA;
862 DAC960_ExecuteCommand(Command);
863 CommandStatus = Command->V1.CommandStatus;
864 DAC960_DeallocateCommand(Command);
865 return (CommandStatus == DAC960_V1_NormalCompletion);
866}
867
868
869
870
871
872
873
874
875
876
877static bool DAC960_V2_GeneralInfo(DAC960_Controller_T *Controller)
878{
879 DAC960_Command_T *Command = DAC960_AllocateCommand(Controller);
880 DAC960_V2_CommandMailbox_T *CommandMailbox = &Command->V2.CommandMailbox;
881 DAC960_V2_CommandStatus_T CommandStatus;
882 DAC960_V2_ClearCommand(Command);
883 Command->CommandType = DAC960_ImmediateCommand;
884 CommandMailbox->Common.CommandOpcode = DAC960_V2_IOCTL;
885 CommandMailbox->Common.CommandControlBits
886 .DataTransferControllerToHost = true;
887 CommandMailbox->Common.CommandControlBits
888 .NoAutoRequestSense = true;
889 CommandMailbox->Common.DataTransferSize = sizeof(DAC960_V2_HealthStatusBuffer_T);
890 CommandMailbox->Common.IOCTL_Opcode = DAC960_V2_GetHealthStatus;
891 CommandMailbox->Common.DataTransferMemoryAddress
892 .ScatterGatherSegments[0]
893 .SegmentDataPointer =
894 Controller->V2.HealthStatusBufferDMA;
895 CommandMailbox->Common.DataTransferMemoryAddress
896 .ScatterGatherSegments[0]
897 .SegmentByteCount =
898 CommandMailbox->Common.DataTransferSize;
899 DAC960_ExecuteCommand(Command);
900 CommandStatus = Command->V2.CommandStatus;
901 DAC960_DeallocateCommand(Command);
902 return (CommandStatus == DAC960_V2_NormalCompletion);
903}
904
905
906
907
908
909
910
911
912
913
914
915static bool DAC960_V2_NewControllerInfo(DAC960_Controller_T *Controller)
916{
917 DAC960_Command_T *Command = DAC960_AllocateCommand(Controller);
918 DAC960_V2_CommandMailbox_T *CommandMailbox = &Command->V2.CommandMailbox;
919 DAC960_V2_CommandStatus_T CommandStatus;
920 DAC960_V2_ClearCommand(Command);
921 Command->CommandType = DAC960_ImmediateCommand;
922 CommandMailbox->ControllerInfo.CommandOpcode = DAC960_V2_IOCTL;
923 CommandMailbox->ControllerInfo.CommandControlBits
924 .DataTransferControllerToHost = true;
925 CommandMailbox->ControllerInfo.CommandControlBits
926 .NoAutoRequestSense = true;
927 CommandMailbox->ControllerInfo.DataTransferSize = sizeof(DAC960_V2_ControllerInfo_T);
928 CommandMailbox->ControllerInfo.ControllerNumber = 0;
929 CommandMailbox->ControllerInfo.IOCTL_Opcode = DAC960_V2_GetControllerInfo;
930 CommandMailbox->ControllerInfo.DataTransferMemoryAddress
931 .ScatterGatherSegments[0]
932 .SegmentDataPointer =
933 Controller->V2.NewControllerInformationDMA;
934 CommandMailbox->ControllerInfo.DataTransferMemoryAddress
935 .ScatterGatherSegments[0]
936 .SegmentByteCount =
937 CommandMailbox->ControllerInfo.DataTransferSize;
938 DAC960_ExecuteCommand(Command);
939 CommandStatus = Command->V2.CommandStatus;
940 DAC960_DeallocateCommand(Command);
941 return (CommandStatus == DAC960_V2_NormalCompletion);
942}
943
944
945
946
947
948
949
950
951
952
953static bool DAC960_V2_NewLogicalDeviceInfo(DAC960_Controller_T *Controller,
954 unsigned short LogicalDeviceNumber)
955{
956 DAC960_Command_T *Command = DAC960_AllocateCommand(Controller);
957 DAC960_V2_CommandMailbox_T *CommandMailbox = &Command->V2.CommandMailbox;
958 DAC960_V2_CommandStatus_T CommandStatus;
959
960 DAC960_V2_ClearCommand(Command);
961 Command->CommandType = DAC960_ImmediateCommand;
962 CommandMailbox->LogicalDeviceInfo.CommandOpcode =
963 DAC960_V2_IOCTL;
964 CommandMailbox->LogicalDeviceInfo.CommandControlBits
965 .DataTransferControllerToHost = true;
966 CommandMailbox->LogicalDeviceInfo.CommandControlBits
967 .NoAutoRequestSense = true;
968 CommandMailbox->LogicalDeviceInfo.DataTransferSize =
969 sizeof(DAC960_V2_LogicalDeviceInfo_T);
970 CommandMailbox->LogicalDeviceInfo.LogicalDevice.LogicalDeviceNumber =
971 LogicalDeviceNumber;
972 CommandMailbox->LogicalDeviceInfo.IOCTL_Opcode = DAC960_V2_GetLogicalDeviceInfoValid;
973 CommandMailbox->LogicalDeviceInfo.DataTransferMemoryAddress
974 .ScatterGatherSegments[0]
975 .SegmentDataPointer =
976 Controller->V2.NewLogicalDeviceInformationDMA;
977 CommandMailbox->LogicalDeviceInfo.DataTransferMemoryAddress
978 .ScatterGatherSegments[0]
979 .SegmentByteCount =
980 CommandMailbox->LogicalDeviceInfo.DataTransferSize;
981 DAC960_ExecuteCommand(Command);
982 CommandStatus = Command->V2.CommandStatus;
983 DAC960_DeallocateCommand(Command);
984 return (CommandStatus == DAC960_V2_NormalCompletion);
985}
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004static bool DAC960_V2_NewPhysicalDeviceInfo(DAC960_Controller_T *Controller,
1005 unsigned char Channel,
1006 unsigned char TargetID,
1007 unsigned char LogicalUnit)
1008{
1009 DAC960_Command_T *Command = DAC960_AllocateCommand(Controller);
1010 DAC960_V2_CommandMailbox_T *CommandMailbox = &Command->V2.CommandMailbox;
1011 DAC960_V2_CommandStatus_T CommandStatus;
1012
1013 DAC960_V2_ClearCommand(Command);
1014 Command->CommandType = DAC960_ImmediateCommand;
1015 CommandMailbox->PhysicalDeviceInfo.CommandOpcode = DAC960_V2_IOCTL;
1016 CommandMailbox->PhysicalDeviceInfo.CommandControlBits
1017 .DataTransferControllerToHost = true;
1018 CommandMailbox->PhysicalDeviceInfo.CommandControlBits
1019 .NoAutoRequestSense = true;
1020 CommandMailbox->PhysicalDeviceInfo.DataTransferSize =
1021 sizeof(DAC960_V2_PhysicalDeviceInfo_T);
1022 CommandMailbox->PhysicalDeviceInfo.PhysicalDevice.LogicalUnit = LogicalUnit;
1023 CommandMailbox->PhysicalDeviceInfo.PhysicalDevice.TargetID = TargetID;
1024 CommandMailbox->PhysicalDeviceInfo.PhysicalDevice.Channel = Channel;
1025 CommandMailbox->PhysicalDeviceInfo.IOCTL_Opcode =
1026 DAC960_V2_GetPhysicalDeviceInfoValid;
1027 CommandMailbox->PhysicalDeviceInfo.DataTransferMemoryAddress
1028 .ScatterGatherSegments[0]
1029 .SegmentDataPointer =
1030 Controller->V2.NewPhysicalDeviceInformationDMA;
1031 CommandMailbox->PhysicalDeviceInfo.DataTransferMemoryAddress
1032 .ScatterGatherSegments[0]
1033 .SegmentByteCount =
1034 CommandMailbox->PhysicalDeviceInfo.DataTransferSize;
1035 DAC960_ExecuteCommand(Command);
1036 CommandStatus = Command->V2.CommandStatus;
1037 DAC960_DeallocateCommand(Command);
1038 return (CommandStatus == DAC960_V2_NormalCompletion);
1039}
1040
1041
1042static void DAC960_V2_ConstructNewUnitSerialNumber(
1043 DAC960_Controller_T *Controller,
1044 DAC960_V2_CommandMailbox_T *CommandMailbox, int Channel, int TargetID,
1045 int LogicalUnit)
1046{
1047 CommandMailbox->SCSI_10.CommandOpcode = DAC960_V2_SCSI_10_Passthru;
1048 CommandMailbox->SCSI_10.CommandControlBits
1049 .DataTransferControllerToHost = true;
1050 CommandMailbox->SCSI_10.CommandControlBits
1051 .NoAutoRequestSense = true;
1052 CommandMailbox->SCSI_10.DataTransferSize =
1053 sizeof(DAC960_SCSI_Inquiry_UnitSerialNumber_T);
1054 CommandMailbox->SCSI_10.PhysicalDevice.LogicalUnit = LogicalUnit;
1055 CommandMailbox->SCSI_10.PhysicalDevice.TargetID = TargetID;
1056 CommandMailbox->SCSI_10.PhysicalDevice.Channel = Channel;
1057 CommandMailbox->SCSI_10.CDBLength = 6;
1058 CommandMailbox->SCSI_10.SCSI_CDB[0] = 0x12;
1059 CommandMailbox->SCSI_10.SCSI_CDB[1] = 1;
1060 CommandMailbox->SCSI_10.SCSI_CDB[2] = 0x80;
1061 CommandMailbox->SCSI_10.SCSI_CDB[3] = 0;
1062 CommandMailbox->SCSI_10.SCSI_CDB[4] =
1063 sizeof(DAC960_SCSI_Inquiry_UnitSerialNumber_T);
1064 CommandMailbox->SCSI_10.SCSI_CDB[5] = 0;
1065 CommandMailbox->SCSI_10.DataTransferMemoryAddress
1066 .ScatterGatherSegments[0]
1067 .SegmentDataPointer =
1068 Controller->V2.NewInquiryUnitSerialNumberDMA;
1069 CommandMailbox->SCSI_10.DataTransferMemoryAddress
1070 .ScatterGatherSegments[0]
1071 .SegmentByteCount =
1072 CommandMailbox->SCSI_10.DataTransferSize;
1073}
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089static bool DAC960_V2_NewInquiryUnitSerialNumber(DAC960_Controller_T *Controller,
1090 int Channel, int TargetID, int LogicalUnit)
1091{
1092 DAC960_Command_T *Command;
1093 DAC960_V2_CommandMailbox_T *CommandMailbox;
1094 DAC960_V2_CommandStatus_T CommandStatus;
1095
1096 Command = DAC960_AllocateCommand(Controller);
1097 CommandMailbox = &Command->V2.CommandMailbox;
1098 DAC960_V2_ClearCommand(Command);
1099 Command->CommandType = DAC960_ImmediateCommand;
1100
1101 DAC960_V2_ConstructNewUnitSerialNumber(Controller, CommandMailbox,
1102 Channel, TargetID, LogicalUnit);
1103
1104 DAC960_ExecuteCommand(Command);
1105 CommandStatus = Command->V2.CommandStatus;
1106 DAC960_DeallocateCommand(Command);
1107 return (CommandStatus == DAC960_V2_NormalCompletion);
1108}
1109
1110
1111
1112
1113
1114
1115
1116
1117static bool DAC960_V2_DeviceOperation(DAC960_Controller_T *Controller,
1118 DAC960_V2_IOCTL_Opcode_T IOCTL_Opcode,
1119 DAC960_V2_OperationDevice_T
1120 OperationDevice)
1121{
1122 DAC960_Command_T *Command = DAC960_AllocateCommand(Controller);
1123 DAC960_V2_CommandMailbox_T *CommandMailbox = &Command->V2.CommandMailbox;
1124 DAC960_V2_CommandStatus_T CommandStatus;
1125 DAC960_V2_ClearCommand(Command);
1126 Command->CommandType = DAC960_ImmediateCommand;
1127 CommandMailbox->DeviceOperation.CommandOpcode = DAC960_V2_IOCTL;
1128 CommandMailbox->DeviceOperation.CommandControlBits
1129 .DataTransferControllerToHost = true;
1130 CommandMailbox->DeviceOperation.CommandControlBits
1131 .NoAutoRequestSense = true;
1132 CommandMailbox->DeviceOperation.IOCTL_Opcode = IOCTL_Opcode;
1133 CommandMailbox->DeviceOperation.OperationDevice = OperationDevice;
1134 DAC960_ExecuteCommand(Command);
1135 CommandStatus = Command->V2.CommandStatus;
1136 DAC960_DeallocateCommand(Command);
1137 return (CommandStatus == DAC960_V2_NormalCompletion);
1138}
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149static bool DAC960_V1_EnableMemoryMailboxInterface(DAC960_Controller_T
1150 *Controller)
1151{
1152 void __iomem *ControllerBaseAddress = Controller->BaseAddress;
1153 DAC960_HardwareType_T hw_type = Controller->HardwareType;
1154 struct pci_dev *PCI_Device = Controller->PCIDevice;
1155 struct dma_loaf *DmaPages = &Controller->DmaPages;
1156 size_t DmaPagesSize;
1157 size_t CommandMailboxesSize;
1158 size_t StatusMailboxesSize;
1159
1160 DAC960_V1_CommandMailbox_T *CommandMailboxesMemory;
1161 dma_addr_t CommandMailboxesMemoryDMA;
1162
1163 DAC960_V1_StatusMailbox_T *StatusMailboxesMemory;
1164 dma_addr_t StatusMailboxesMemoryDMA;
1165
1166 DAC960_V1_CommandMailbox_T CommandMailbox;
1167 DAC960_V1_CommandStatus_T CommandStatus;
1168 int TimeoutCounter;
1169 int i;
1170
1171
1172 if (pci_set_dma_mask(Controller->PCIDevice, DMA_32BIT_MASK))
1173 return DAC960_Failure(Controller, "DMA mask out of range");
1174 Controller->BounceBufferLimit = DMA_32BIT_MASK;
1175
1176 if ((hw_type == DAC960_PD_Controller) || (hw_type == DAC960_P_Controller)) {
1177 CommandMailboxesSize = 0;
1178 StatusMailboxesSize = 0;
1179 } else {
1180 CommandMailboxesSize = DAC960_V1_CommandMailboxCount * sizeof(DAC960_V1_CommandMailbox_T);
1181 StatusMailboxesSize = DAC960_V1_StatusMailboxCount * sizeof(DAC960_V1_StatusMailbox_T);
1182 }
1183 DmaPagesSize = CommandMailboxesSize + StatusMailboxesSize +
1184 sizeof(DAC960_V1_DCDB_T) + sizeof(DAC960_V1_Enquiry_T) +
1185 sizeof(DAC960_V1_ErrorTable_T) + sizeof(DAC960_V1_EventLogEntry_T) +
1186 sizeof(DAC960_V1_RebuildProgress_T) +
1187 sizeof(DAC960_V1_LogicalDriveInformationArray_T) +
1188 sizeof(DAC960_V1_BackgroundInitializationStatus_T) +
1189 sizeof(DAC960_V1_DeviceState_T) + sizeof(DAC960_SCSI_Inquiry_T) +
1190 sizeof(DAC960_SCSI_Inquiry_UnitSerialNumber_T);
1191
1192 if (!init_dma_loaf(PCI_Device, DmaPages, DmaPagesSize))
1193 return false;
1194
1195
1196 if ((hw_type == DAC960_PD_Controller) || (hw_type == DAC960_P_Controller))
1197 goto skip_mailboxes;
1198
1199 CommandMailboxesMemory = slice_dma_loaf(DmaPages,
1200 CommandMailboxesSize, &CommandMailboxesMemoryDMA);
1201
1202
1203 Controller->V1.FirstCommandMailbox = CommandMailboxesMemory;
1204 Controller->V1.FirstCommandMailboxDMA = CommandMailboxesMemoryDMA;
1205
1206 CommandMailboxesMemory += DAC960_V1_CommandMailboxCount - 1;
1207 Controller->V1.LastCommandMailbox = CommandMailboxesMemory;
1208 Controller->V1.NextCommandMailbox = Controller->V1.FirstCommandMailbox;
1209 Controller->V1.PreviousCommandMailbox1 = Controller->V1.LastCommandMailbox;
1210 Controller->V1.PreviousCommandMailbox2 =
1211 Controller->V1.LastCommandMailbox - 1;
1212
1213
1214 StatusMailboxesMemory = slice_dma_loaf(DmaPages,
1215 StatusMailboxesSize, &StatusMailboxesMemoryDMA);
1216
1217 Controller->V1.FirstStatusMailbox = StatusMailboxesMemory;
1218 Controller->V1.FirstStatusMailboxDMA = StatusMailboxesMemoryDMA;
1219 StatusMailboxesMemory += DAC960_V1_StatusMailboxCount - 1;
1220 Controller->V1.LastStatusMailbox = StatusMailboxesMemory;
1221 Controller->V1.NextStatusMailbox = Controller->V1.FirstStatusMailbox;
1222
1223skip_mailboxes:
1224 Controller->V1.MonitoringDCDB = slice_dma_loaf(DmaPages,
1225 sizeof(DAC960_V1_DCDB_T),
1226 &Controller->V1.MonitoringDCDB_DMA);
1227
1228 Controller->V1.NewEnquiry = slice_dma_loaf(DmaPages,
1229 sizeof(DAC960_V1_Enquiry_T),
1230 &Controller->V1.NewEnquiryDMA);
1231
1232 Controller->V1.NewErrorTable = slice_dma_loaf(DmaPages,
1233 sizeof(DAC960_V1_ErrorTable_T),
1234 &Controller->V1.NewErrorTableDMA);
1235
1236 Controller->V1.EventLogEntry = slice_dma_loaf(DmaPages,
1237 sizeof(DAC960_V1_EventLogEntry_T),
1238 &Controller->V1.EventLogEntryDMA);
1239
1240 Controller->V1.RebuildProgress = slice_dma_loaf(DmaPages,
1241 sizeof(DAC960_V1_RebuildProgress_T),
1242 &Controller->V1.RebuildProgressDMA);
1243
1244 Controller->V1.NewLogicalDriveInformation = slice_dma_loaf(DmaPages,
1245 sizeof(DAC960_V1_LogicalDriveInformationArray_T),
1246 &Controller->V1.NewLogicalDriveInformationDMA);
1247
1248 Controller->V1.BackgroundInitializationStatus = slice_dma_loaf(DmaPages,
1249 sizeof(DAC960_V1_BackgroundInitializationStatus_T),
1250 &Controller->V1.BackgroundInitializationStatusDMA);
1251
1252 Controller->V1.NewDeviceState = slice_dma_loaf(DmaPages,
1253 sizeof(DAC960_V1_DeviceState_T),
1254 &Controller->V1.NewDeviceStateDMA);
1255
1256 Controller->V1.NewInquiryStandardData = slice_dma_loaf(DmaPages,
1257 sizeof(DAC960_SCSI_Inquiry_T),
1258 &Controller->V1.NewInquiryStandardDataDMA);
1259
1260 Controller->V1.NewInquiryUnitSerialNumber = slice_dma_loaf(DmaPages,
1261 sizeof(DAC960_SCSI_Inquiry_UnitSerialNumber_T),
1262 &Controller->V1.NewInquiryUnitSerialNumberDMA);
1263
1264 if ((hw_type == DAC960_PD_Controller) || (hw_type == DAC960_P_Controller))
1265 return true;
1266
1267
1268 Controller->V1.DualModeMemoryMailboxInterface = true;
1269 CommandMailbox.TypeX.CommandOpcode = 0x2B;
1270 CommandMailbox.TypeX.CommandIdentifier = 0;
1271 CommandMailbox.TypeX.CommandOpcode2 = 0x14;
1272 CommandMailbox.TypeX.CommandMailboxesBusAddress =
1273 Controller->V1.FirstCommandMailboxDMA;
1274 CommandMailbox.TypeX.StatusMailboxesBusAddress =
1275 Controller->V1.FirstStatusMailboxDMA;
1276#define TIMEOUT_COUNT 1000000
1277
1278 for (i = 0; i < 2; i++)
1279 switch (Controller->HardwareType)
1280 {
1281 case DAC960_LA_Controller:
1282 TimeoutCounter = TIMEOUT_COUNT;
1283 while (--TimeoutCounter >= 0)
1284 {
1285 if (!DAC960_LA_HardwareMailboxFullP(ControllerBaseAddress))
1286 break;
1287 udelay(10);
1288 }
1289 if (TimeoutCounter < 0) return false;
1290 DAC960_LA_WriteHardwareMailbox(ControllerBaseAddress, &CommandMailbox);
1291 DAC960_LA_HardwareMailboxNewCommand(ControllerBaseAddress);
1292 TimeoutCounter = TIMEOUT_COUNT;
1293 while (--TimeoutCounter >= 0)
1294 {
1295 if (DAC960_LA_HardwareMailboxStatusAvailableP(
1296 ControllerBaseAddress))
1297 break;
1298 udelay(10);
1299 }
1300 if (TimeoutCounter < 0) return false;
1301 CommandStatus = DAC960_LA_ReadStatusRegister(ControllerBaseAddress);
1302 DAC960_LA_AcknowledgeHardwareMailboxInterrupt(ControllerBaseAddress);
1303 DAC960_LA_AcknowledgeHardwareMailboxStatus(ControllerBaseAddress);
1304 if (CommandStatus == DAC960_V1_NormalCompletion) return true;
1305 Controller->V1.DualModeMemoryMailboxInterface = false;
1306 CommandMailbox.TypeX.CommandOpcode2 = 0x10;
1307 break;
1308 case DAC960_PG_Controller:
1309 TimeoutCounter = TIMEOUT_COUNT;
1310 while (--TimeoutCounter >= 0)
1311 {
1312 if (!DAC960_PG_HardwareMailboxFullP(ControllerBaseAddress))
1313 break;
1314 udelay(10);
1315 }
1316 if (TimeoutCounter < 0) return false;
1317 DAC960_PG_WriteHardwareMailbox(ControllerBaseAddress, &CommandMailbox);
1318 DAC960_PG_HardwareMailboxNewCommand(ControllerBaseAddress);
1319
1320 TimeoutCounter = TIMEOUT_COUNT;
1321 while (--TimeoutCounter >= 0)
1322 {
1323 if (DAC960_PG_HardwareMailboxStatusAvailableP(
1324 ControllerBaseAddress))
1325 break;
1326 udelay(10);
1327 }
1328 if (TimeoutCounter < 0) return false;
1329 CommandStatus = DAC960_PG_ReadStatusRegister(ControllerBaseAddress);
1330 DAC960_PG_AcknowledgeHardwareMailboxInterrupt(ControllerBaseAddress);
1331 DAC960_PG_AcknowledgeHardwareMailboxStatus(ControllerBaseAddress);
1332 if (CommandStatus == DAC960_V1_NormalCompletion) return true;
1333 Controller->V1.DualModeMemoryMailboxInterface = false;
1334 CommandMailbox.TypeX.CommandOpcode2 = 0x10;
1335 break;
1336 default:
1337 DAC960_Failure(Controller, "Unknown Controller Type\n");
1338 break;
1339 }
1340 return false;
1341}
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355static bool DAC960_V2_EnableMemoryMailboxInterface(DAC960_Controller_T
1356 *Controller)
1357{
1358 void __iomem *ControllerBaseAddress = Controller->BaseAddress;
1359 struct pci_dev *PCI_Device = Controller->PCIDevice;
1360 struct dma_loaf *DmaPages = &Controller->DmaPages;
1361 size_t DmaPagesSize;
1362 size_t CommandMailboxesSize;
1363 size_t StatusMailboxesSize;
1364
1365 DAC960_V2_CommandMailbox_T *CommandMailboxesMemory;
1366 dma_addr_t CommandMailboxesMemoryDMA;
1367
1368 DAC960_V2_StatusMailbox_T *StatusMailboxesMemory;
1369 dma_addr_t StatusMailboxesMemoryDMA;
1370
1371 DAC960_V2_CommandMailbox_T *CommandMailbox;
1372 dma_addr_t CommandMailboxDMA;
1373 DAC960_V2_CommandStatus_T CommandStatus;
1374
1375 if (!pci_set_dma_mask(Controller->PCIDevice, DMA_64BIT_MASK))
1376 Controller->BounceBufferLimit = DMA_64BIT_MASK;
1377 else if (!pci_set_dma_mask(Controller->PCIDevice, DMA_32BIT_MASK))
1378 Controller->BounceBufferLimit = DMA_32BIT_MASK;
1379 else
1380 return DAC960_Failure(Controller, "DMA mask out of range");
1381
1382
1383 CommandMailbox = pci_alloc_consistent(PCI_Device,
1384 sizeof(DAC960_V2_CommandMailbox_T), &CommandMailboxDMA);
1385 if (CommandMailbox == NULL)
1386 return false;
1387
1388 CommandMailboxesSize = DAC960_V2_CommandMailboxCount * sizeof(DAC960_V2_CommandMailbox_T);
1389 StatusMailboxesSize = DAC960_V2_StatusMailboxCount * sizeof(DAC960_V2_StatusMailbox_T);
1390 DmaPagesSize =
1391 CommandMailboxesSize + StatusMailboxesSize +
1392 sizeof(DAC960_V2_HealthStatusBuffer_T) +
1393 sizeof(DAC960_V2_ControllerInfo_T) +
1394 sizeof(DAC960_V2_LogicalDeviceInfo_T) +
1395 sizeof(DAC960_V2_PhysicalDeviceInfo_T) +
1396 sizeof(DAC960_SCSI_Inquiry_UnitSerialNumber_T) +
1397 sizeof(DAC960_V2_Event_T) +
1398 sizeof(DAC960_V2_PhysicalToLogicalDevice_T);
1399
1400 if (!init_dma_loaf(PCI_Device, DmaPages, DmaPagesSize)) {
1401 pci_free_consistent(PCI_Device, sizeof(DAC960_V2_CommandMailbox_T),
1402 CommandMailbox, CommandMailboxDMA);
1403 return false;
1404 }
1405
1406 CommandMailboxesMemory = slice_dma_loaf(DmaPages,
1407 CommandMailboxesSize, &CommandMailboxesMemoryDMA);
1408
1409
1410 Controller->V2.FirstCommandMailbox = CommandMailboxesMemory;
1411 Controller->V2.FirstCommandMailboxDMA = CommandMailboxesMemoryDMA;
1412
1413 CommandMailboxesMemory += DAC960_V2_CommandMailboxCount - 1;
1414 Controller->V2.LastCommandMailbox = CommandMailboxesMemory;
1415 Controller->V2.NextCommandMailbox = Controller->V2.FirstCommandMailbox;
1416 Controller->V2.PreviousCommandMailbox1 = Controller->V2.LastCommandMailbox;
1417 Controller->V2.PreviousCommandMailbox2 =
1418 Controller->V2.LastCommandMailbox - 1;
1419
1420
1421 StatusMailboxesMemory = slice_dma_loaf(DmaPages,
1422 StatusMailboxesSize, &StatusMailboxesMemoryDMA);
1423
1424 Controller->V2.FirstStatusMailbox = StatusMailboxesMemory;
1425 Controller->V2.FirstStatusMailboxDMA = StatusMailboxesMemoryDMA;
1426 StatusMailboxesMemory += DAC960_V2_StatusMailboxCount - 1;
1427 Controller->V2.LastStatusMailbox = StatusMailboxesMemory;
1428 Controller->V2.NextStatusMailbox = Controller->V2.FirstStatusMailbox;
1429
1430 Controller->V2.HealthStatusBuffer = slice_dma_loaf(DmaPages,
1431 sizeof(DAC960_V2_HealthStatusBuffer_T),
1432 &Controller->V2.HealthStatusBufferDMA);
1433
1434 Controller->V2.NewControllerInformation = slice_dma_loaf(DmaPages,
1435 sizeof(DAC960_V2_ControllerInfo_T),
1436 &Controller->V2.NewControllerInformationDMA);
1437
1438 Controller->V2.NewLogicalDeviceInformation = slice_dma_loaf(DmaPages,
1439 sizeof(DAC960_V2_LogicalDeviceInfo_T),
1440 &Controller->V2.NewLogicalDeviceInformationDMA);
1441
1442 Controller->V2.NewPhysicalDeviceInformation = slice_dma_loaf(DmaPages,
1443 sizeof(DAC960_V2_PhysicalDeviceInfo_T),
1444 &Controller->V2.NewPhysicalDeviceInformationDMA);
1445
1446 Controller->V2.NewInquiryUnitSerialNumber = slice_dma_loaf(DmaPages,
1447 sizeof(DAC960_SCSI_Inquiry_UnitSerialNumber_T),
1448 &Controller->V2.NewInquiryUnitSerialNumberDMA);
1449
1450 Controller->V2.Event = slice_dma_loaf(DmaPages,
1451 sizeof(DAC960_V2_Event_T),
1452 &Controller->V2.EventDMA);
1453
1454 Controller->V2.PhysicalToLogicalDevice = slice_dma_loaf(DmaPages,
1455 sizeof(DAC960_V2_PhysicalToLogicalDevice_T),
1456 &Controller->V2.PhysicalToLogicalDeviceDMA);
1457
1458
1459
1460
1461
1462
1463
1464
1465 memset(CommandMailbox, 0, sizeof(DAC960_V2_CommandMailbox_T));
1466 CommandMailbox->SetMemoryMailbox.CommandIdentifier = 1;
1467 CommandMailbox->SetMemoryMailbox.CommandOpcode = DAC960_V2_IOCTL;
1468 CommandMailbox->SetMemoryMailbox.CommandControlBits.NoAutoRequestSense = true;
1469 CommandMailbox->SetMemoryMailbox.FirstCommandMailboxSizeKB =
1470 (DAC960_V2_CommandMailboxCount * sizeof(DAC960_V2_CommandMailbox_T)) >> 10;
1471 CommandMailbox->SetMemoryMailbox.FirstStatusMailboxSizeKB =
1472 (DAC960_V2_StatusMailboxCount * sizeof(DAC960_V2_StatusMailbox_T)) >> 10;
1473 CommandMailbox->SetMemoryMailbox.SecondCommandMailboxSizeKB = 0;
1474 CommandMailbox->SetMemoryMailbox.SecondStatusMailboxSizeKB = 0;
1475 CommandMailbox->SetMemoryMailbox.RequestSenseSize = 0;
1476 CommandMailbox->SetMemoryMailbox.IOCTL_Opcode = DAC960_V2_SetMemoryMailbox;
1477 CommandMailbox->SetMemoryMailbox.HealthStatusBufferSizeKB = 1;
1478 CommandMailbox->SetMemoryMailbox.HealthStatusBufferBusAddress =
1479 Controller->V2.HealthStatusBufferDMA;
1480 CommandMailbox->SetMemoryMailbox.FirstCommandMailboxBusAddress =
1481 Controller->V2.FirstCommandMailboxDMA;
1482 CommandMailbox->SetMemoryMailbox.FirstStatusMailboxBusAddress =
1483 Controller->V2.FirstStatusMailboxDMA;
1484 switch (Controller->HardwareType)
1485 {
1486 case DAC960_GEM_Controller:
1487 while (DAC960_GEM_HardwareMailboxFullP(ControllerBaseAddress))
1488 udelay(1);
1489 DAC960_GEM_WriteHardwareMailbox(ControllerBaseAddress, CommandMailboxDMA);
1490 DAC960_GEM_HardwareMailboxNewCommand(ControllerBaseAddress);
1491 while (!DAC960_GEM_HardwareMailboxStatusAvailableP(ControllerBaseAddress))
1492 udelay(1);
1493 CommandStatus = DAC960_GEM_ReadCommandStatus(ControllerBaseAddress);
1494 DAC960_GEM_AcknowledgeHardwareMailboxInterrupt(ControllerBaseAddress);
1495 DAC960_GEM_AcknowledgeHardwareMailboxStatus(ControllerBaseAddress);
1496 break;
1497 case DAC960_BA_Controller:
1498 while (DAC960_BA_HardwareMailboxFullP(ControllerBaseAddress))
1499 udelay(1);
1500 DAC960_BA_WriteHardwareMailbox(ControllerBaseAddress, CommandMailboxDMA);
1501 DAC960_BA_HardwareMailboxNewCommand(ControllerBaseAddress);
1502 while (!DAC960_BA_HardwareMailboxStatusAvailableP(ControllerBaseAddress))
1503 udelay(1);
1504 CommandStatus = DAC960_BA_ReadCommandStatus(ControllerBaseAddress);
1505 DAC960_BA_AcknowledgeHardwareMailboxInterrupt(ControllerBaseAddress);
1506 DAC960_BA_AcknowledgeHardwareMailboxStatus(ControllerBaseAddress);
1507 break;
1508 case DAC960_LP_Controller:
1509 while (DAC960_LP_HardwareMailboxFullP(ControllerBaseAddress))
1510 udelay(1);
1511 DAC960_LP_WriteHardwareMailbox(ControllerBaseAddress, CommandMailboxDMA);
1512 DAC960_LP_HardwareMailboxNewCommand(ControllerBaseAddress);
1513 while (!DAC960_LP_HardwareMailboxStatusAvailableP(ControllerBaseAddress))
1514 udelay(1);
1515 CommandStatus = DAC960_LP_ReadCommandStatus(ControllerBaseAddress);
1516 DAC960_LP_AcknowledgeHardwareMailboxInterrupt(ControllerBaseAddress);
1517 DAC960_LP_AcknowledgeHardwareMailboxStatus(ControllerBaseAddress);
1518 break;
1519 default:
1520 DAC960_Failure(Controller, "Unknown Controller Type\n");
1521 CommandStatus = DAC960_V2_AbormalCompletion;
1522 break;
1523 }
1524 pci_free_consistent(PCI_Device, sizeof(DAC960_V2_CommandMailbox_T),
1525 CommandMailbox, CommandMailboxDMA);
1526 return (CommandStatus == DAC960_V2_NormalCompletion);
1527}
1528
1529
1530
1531
1532
1533
1534
1535static bool DAC960_V1_ReadControllerConfiguration(DAC960_Controller_T
1536 *Controller)
1537{
1538 DAC960_V1_Enquiry2_T *Enquiry2;
1539 dma_addr_t Enquiry2DMA;
1540 DAC960_V1_Config2_T *Config2;
1541 dma_addr_t Config2DMA;
1542 int LogicalDriveNumber, Channel, TargetID;
1543 struct dma_loaf local_dma;
1544
1545 if (!init_dma_loaf(Controller->PCIDevice, &local_dma,
1546 sizeof(DAC960_V1_Enquiry2_T) + sizeof(DAC960_V1_Config2_T)))
1547 return DAC960_Failure(Controller, "LOGICAL DEVICE ALLOCATION");
1548
1549 Enquiry2 = slice_dma_loaf(&local_dma, sizeof(DAC960_V1_Enquiry2_T), &Enquiry2DMA);
1550 Config2 = slice_dma_loaf(&local_dma, sizeof(DAC960_V1_Config2_T), &Config2DMA);
1551
1552 if (!DAC960_V1_ExecuteType3(Controller, DAC960_V1_Enquiry,
1553 Controller->V1.NewEnquiryDMA)) {
1554 free_dma_loaf(Controller->PCIDevice, &local_dma);
1555 return DAC960_Failure(Controller, "ENQUIRY");
1556 }
1557 memcpy(&Controller->V1.Enquiry, Controller->V1.NewEnquiry,
1558 sizeof(DAC960_V1_Enquiry_T));
1559
1560 if (!DAC960_V1_ExecuteType3(Controller, DAC960_V1_Enquiry2, Enquiry2DMA)) {
1561 free_dma_loaf(Controller->PCIDevice, &local_dma);
1562 return DAC960_Failure(Controller, "ENQUIRY2");
1563 }
1564
1565 if (!DAC960_V1_ExecuteType3(Controller, DAC960_V1_ReadConfig2, Config2DMA)) {
1566 free_dma_loaf(Controller->PCIDevice, &local_dma);
1567 return DAC960_Failure(Controller, "READ CONFIG2");
1568 }
1569
1570 if (!DAC960_V1_ExecuteType3(Controller, DAC960_V1_GetLogicalDriveInformation,
1571 Controller->V1.NewLogicalDriveInformationDMA)) {
1572 free_dma_loaf(Controller->PCIDevice, &local_dma);
1573 return DAC960_Failure(Controller, "GET LOGICAL DRIVE INFORMATION");
1574 }
1575 memcpy(&Controller->V1.LogicalDriveInformation,
1576 Controller->V1.NewLogicalDriveInformation,
1577 sizeof(DAC960_V1_LogicalDriveInformationArray_T));
1578
1579 for (Channel = 0; Channel < Enquiry2->ActualChannels; Channel++)
1580 for (TargetID = 0; TargetID < Enquiry2->MaxTargets; TargetID++) {
1581 if (!DAC960_V1_ExecuteType3D(Controller, DAC960_V1_GetDeviceState,
1582 Channel, TargetID,
1583 Controller->V1.NewDeviceStateDMA)) {
1584 free_dma_loaf(Controller->PCIDevice, &local_dma);
1585 return DAC960_Failure(Controller, "GET DEVICE STATE");
1586 }
1587 memcpy(&Controller->V1.DeviceState[Channel][TargetID],
1588 Controller->V1.NewDeviceState, sizeof(DAC960_V1_DeviceState_T));
1589 }
1590
1591
1592
1593 switch (Enquiry2->HardwareID.SubModel)
1594 {
1595 case DAC960_V1_P_PD_PU:
1596 if (Enquiry2->SCSICapability.BusSpeed == DAC960_V1_Ultra)
1597 strcpy(Controller->ModelName, "DAC960PU");
1598 else strcpy(Controller->ModelName, "DAC960PD");
1599 break;
1600 case DAC960_V1_PL:
1601 strcpy(Controller->ModelName, "DAC960PL");
1602 break;
1603 case DAC960_V1_PG:
1604 strcpy(Controller->ModelName, "DAC960PG");
1605 break;
1606 case DAC960_V1_PJ:
1607 strcpy(Controller->ModelName, "DAC960PJ");
1608 break;
1609 case DAC960_V1_PR:
1610 strcpy(Controller->ModelName, "DAC960PR");
1611 break;
1612 case DAC960_V1_PT:
1613 strcpy(Controller->ModelName, "DAC960PT");
1614 break;
1615 case DAC960_V1_PTL0:
1616 strcpy(Controller->ModelName, "DAC960PTL0");
1617 break;
1618 case DAC960_V1_PRL:
1619 strcpy(Controller->ModelName, "DAC960PRL");
1620 break;
1621 case DAC960_V1_PTL1:
1622 strcpy(Controller->ModelName, "DAC960PTL1");
1623 break;
1624 case DAC960_V1_1164P:
1625 strcpy(Controller->ModelName, "DAC1164P");
1626 break;
1627 default:
1628 free_dma_loaf(Controller->PCIDevice, &local_dma);
1629 return DAC960_Failure(Controller, "MODEL VERIFICATION");
1630 }
1631 strcpy(Controller->FullModelName, "Mylex ");
1632 strcat(Controller->FullModelName, Controller->ModelName);
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642#if defined(CONFIG_ALPHA)
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657# define FIRMWARE_27X "2.70"
1658#else
1659# define FIRMWARE_27X "2.73"
1660#endif
1661
1662 if (Enquiry2->FirmwareID.MajorVersion == 0)
1663 {
1664 Enquiry2->FirmwareID.MajorVersion =
1665 Controller->V1.Enquiry.MajorFirmwareVersion;
1666 Enquiry2->FirmwareID.MinorVersion =
1667 Controller->V1.Enquiry.MinorFirmwareVersion;
1668 Enquiry2->FirmwareID.FirmwareType = '0';
1669 Enquiry2->FirmwareID.TurnID = 0;
1670 }
1671 sprintf(Controller->FirmwareVersion, "%d.%02d-%c-%02d",
1672 Enquiry2->FirmwareID.MajorVersion, Enquiry2->FirmwareID.MinorVersion,
1673 Enquiry2->FirmwareID.FirmwareType, Enquiry2->FirmwareID.TurnID);
1674 if (!((Controller->FirmwareVersion[0] == '5' &&
1675 strcmp(Controller->FirmwareVersion, "5.06") >= 0) ||
1676 (Controller->FirmwareVersion[0] == '4' &&
1677 strcmp(Controller->FirmwareVersion, "4.06") >= 0) ||
1678 (Controller->FirmwareVersion[0] == '3' &&
1679 strcmp(Controller->FirmwareVersion, "3.51") >= 0) ||
1680 (Controller->FirmwareVersion[0] == '2' &&
1681 strcmp(Controller->FirmwareVersion, FIRMWARE_27X) >= 0)))
1682 {
1683 DAC960_Failure(Controller, "FIRMWARE VERSION VERIFICATION");
1684 DAC960_Error("Firmware Version = '%s'\n", Controller,
1685 Controller->FirmwareVersion);
1686 free_dma_loaf(Controller->PCIDevice, &local_dma);
1687 return false;
1688 }
1689
1690
1691
1692
1693 Controller->Channels = Enquiry2->ActualChannels;
1694 Controller->Targets = Enquiry2->MaxTargets;
1695 Controller->MemorySize = Enquiry2->MemorySize >> 20;
1696 Controller->V1.SAFTE_EnclosureManagementEnabled =
1697 (Enquiry2->FaultManagementType == DAC960_V1_SAFTE);
1698
1699
1700
1701
1702
1703
1704
1705 Controller->ControllerQueueDepth = Controller->V1.Enquiry.MaxCommands;
1706 Controller->DriverQueueDepth = Controller->ControllerQueueDepth - 1;
1707 if (Controller->DriverQueueDepth > DAC960_MaxDriverQueueDepth)
1708 Controller->DriverQueueDepth = DAC960_MaxDriverQueueDepth;
1709 Controller->LogicalDriveCount =
1710 Controller->V1.Enquiry.NumberOfLogicalDrives;
1711 Controller->MaxBlocksPerCommand = Enquiry2->MaxBlocksPerCommand;
1712 Controller->ControllerScatterGatherLimit = Enquiry2->MaxScatterGatherEntries;
1713 Controller->DriverScatterGatherLimit =
1714 Controller->ControllerScatterGatherLimit;
1715 if (Controller->DriverScatterGatherLimit > DAC960_V1_ScatterGatherLimit)
1716 Controller->DriverScatterGatherLimit = DAC960_V1_ScatterGatherLimit;
1717
1718
1719
1720 Controller->V1.StripeSize = Config2->BlocksPerStripe * Config2->BlockFactor
1721 >> (10 - DAC960_BlockSizeBits);
1722 Controller->V1.SegmentSize = Config2->BlocksPerCacheLine * Config2->BlockFactor
1723 >> (10 - DAC960_BlockSizeBits);
1724 switch (Config2->DriveGeometry)
1725 {
1726 case DAC960_V1_Geometry_128_32:
1727 Controller->V1.GeometryTranslationHeads = 128;
1728 Controller->V1.GeometryTranslationSectors = 32;
1729 break;
1730 case DAC960_V1_Geometry_255_63:
1731 Controller->V1.GeometryTranslationHeads = 255;
1732 Controller->V1.GeometryTranslationSectors = 63;
1733 break;
1734 default:
1735 free_dma_loaf(Controller->PCIDevice, &local_dma);
1736 return DAC960_Failure(Controller, "CONFIG2 DRIVE GEOMETRY");
1737 }
1738
1739
1740
1741 if ((Controller->FirmwareVersion[0] == '4' &&
1742 strcmp(Controller->FirmwareVersion, "4.08") >= 0) ||
1743 (Controller->FirmwareVersion[0] == '5' &&
1744 strcmp(Controller->FirmwareVersion, "5.08") >= 0))
1745 {
1746 Controller->V1.BackgroundInitializationStatusSupported = true;
1747 DAC960_V1_ExecuteType3B(Controller,
1748 DAC960_V1_BackgroundInitializationControl, 0x20,
1749 Controller->
1750 V1.BackgroundInitializationStatusDMA);
1751 memcpy(&Controller->V1.LastBackgroundInitializationStatus,
1752 Controller->V1.BackgroundInitializationStatus,
1753 sizeof(DAC960_V1_BackgroundInitializationStatus_T));
1754 }
1755
1756
1757
1758 for (LogicalDriveNumber = 0;
1759 LogicalDriveNumber < Controller->LogicalDriveCount;
1760 LogicalDriveNumber++)
1761 if (Controller->V1.LogicalDriveInformation
1762 [LogicalDriveNumber].LogicalDriveState !=
1763 DAC960_V1_LogicalDrive_Offline)
1764 Controller->LogicalDriveInitiallyAccessible[LogicalDriveNumber] = true;
1765 Controller->V1.LastRebuildStatus = DAC960_V1_NoRebuildOrCheckInProgress;
1766 free_dma_loaf(Controller->PCIDevice, &local_dma);
1767 return true;
1768}
1769
1770
1771
1772
1773
1774
1775
1776static bool DAC960_V2_ReadControllerConfiguration(DAC960_Controller_T
1777 *Controller)
1778{
1779 DAC960_V2_ControllerInfo_T *ControllerInfo =
1780 &Controller->V2.ControllerInformation;
1781 unsigned short LogicalDeviceNumber = 0;
1782 int ModelNameLength;
1783
1784
1785 if (!DAC960_V2_NewControllerInfo(Controller))
1786 return DAC960_Failure(Controller, "GET CONTROLLER INFO");
1787 memcpy(ControllerInfo, Controller->V2.NewControllerInformation,
1788 sizeof(DAC960_V2_ControllerInfo_T));
1789
1790
1791 if (!DAC960_V2_GeneralInfo(Controller))
1792 return DAC960_Failure(Controller, "GET HEALTH STATUS");
1793
1794
1795
1796
1797 ModelNameLength = sizeof(ControllerInfo->ControllerName);
1798 if (ModelNameLength > sizeof(Controller->ModelName)-1)
1799 ModelNameLength = sizeof(Controller->ModelName)-1;
1800 memcpy(Controller->ModelName, ControllerInfo->ControllerName,
1801 ModelNameLength);
1802 ModelNameLength--;
1803 while (Controller->ModelName[ModelNameLength] == ' ' ||
1804 Controller->ModelName[ModelNameLength] == '\0')
1805 ModelNameLength--;
1806 Controller->ModelName[++ModelNameLength] = '\0';
1807 strcpy(Controller->FullModelName, "Mylex ");
1808 strcat(Controller->FullModelName, Controller->ModelName);
1809
1810
1811
1812 sprintf(Controller->FirmwareVersion, "%d.%02d-%02d",
1813 ControllerInfo->FirmwareMajorVersion,
1814 ControllerInfo->FirmwareMinorVersion,
1815 ControllerInfo->FirmwareTurnNumber);
1816 if (ControllerInfo->FirmwareMajorVersion == 6 &&
1817 ControllerInfo->FirmwareMinorVersion == 0 &&
1818 ControllerInfo->FirmwareTurnNumber < 1)
1819 {
1820 DAC960_Info("FIRMWARE VERSION %s DOES NOT PROVIDE THE CONTROLLER\n",
1821 Controller, Controller->FirmwareVersion);
1822 DAC960_Info("STATUS MONITORING FUNCTIONALITY NEEDED BY THIS DRIVER.\n",
1823 Controller);
1824 DAC960_Info("PLEASE UPGRADE TO VERSION 6.00-01 OR ABOVE.\n",
1825 Controller);
1826 }
1827
1828
1829
1830 Controller->Channels = ControllerInfo->NumberOfPhysicalChannelsPresent;
1831 Controller->Targets =
1832 ControllerInfo->MaximumTargetsPerChannel
1833 [ControllerInfo->NumberOfPhysicalChannelsPresent-1];
1834 Controller->MemorySize = ControllerInfo->MemorySizeMB;
1835
1836
1837
1838
1839
1840
1841
1842 Controller->ControllerQueueDepth = ControllerInfo->MaximumParallelCommands;
1843 Controller->DriverQueueDepth = Controller->ControllerQueueDepth - 1;
1844 if (Controller->DriverQueueDepth > DAC960_MaxDriverQueueDepth)
1845 Controller->DriverQueueDepth = DAC960_MaxDriverQueueDepth;
1846 Controller->LogicalDriveCount = ControllerInfo->LogicalDevicesPresent;
1847 Controller->MaxBlocksPerCommand =
1848 ControllerInfo->MaximumDataTransferSizeInBlocks;
1849 Controller->ControllerScatterGatherLimit =
1850 ControllerInfo->MaximumScatterGatherEntries;
1851 Controller->DriverScatterGatherLimit =
1852 Controller->ControllerScatterGatherLimit;
1853 if (Controller->DriverScatterGatherLimit > DAC960_V2_ScatterGatherLimit)
1854 Controller->DriverScatterGatherLimit = DAC960_V2_ScatterGatherLimit;
1855
1856
1857
1858 while (true)
1859 {
1860 DAC960_V2_LogicalDeviceInfo_T *NewLogicalDeviceInfo =
1861 Controller->V2.NewLogicalDeviceInformation;
1862 DAC960_V2_LogicalDeviceInfo_T *LogicalDeviceInfo;
1863 DAC960_V2_PhysicalDevice_T PhysicalDevice;
1864
1865 if (!DAC960_V2_NewLogicalDeviceInfo(Controller, LogicalDeviceNumber))
1866 break;
1867 LogicalDeviceNumber = NewLogicalDeviceInfo->LogicalDeviceNumber;
1868 if (LogicalDeviceNumber >= DAC960_MaxLogicalDrives) {
1869 DAC960_Error("DAC960: Logical Drive Number %d not supported\n",
1870 Controller, LogicalDeviceNumber);
1871 break;
1872 }
1873 if (NewLogicalDeviceInfo->DeviceBlockSizeInBytes != DAC960_BlockSize) {
1874 DAC960_Error("DAC960: Logical Drive Block Size %d not supported\n",
1875 Controller, NewLogicalDeviceInfo->DeviceBlockSizeInBytes);
1876 LogicalDeviceNumber++;
1877 continue;
1878 }
1879 PhysicalDevice.Controller = 0;
1880 PhysicalDevice.Channel = NewLogicalDeviceInfo->Channel;
1881 PhysicalDevice.TargetID = NewLogicalDeviceInfo->TargetID;
1882 PhysicalDevice.LogicalUnit = NewLogicalDeviceInfo->LogicalUnit;
1883 Controller->V2.LogicalDriveToVirtualDevice[LogicalDeviceNumber] =
1884 PhysicalDevice;
1885 if (NewLogicalDeviceInfo->LogicalDeviceState !=
1886 DAC960_V2_LogicalDevice_Offline)
1887 Controller->LogicalDriveInitiallyAccessible[LogicalDeviceNumber] = true;
1888 LogicalDeviceInfo = kmalloc(sizeof(DAC960_V2_LogicalDeviceInfo_T),
1889 GFP_ATOMIC);
1890 if (LogicalDeviceInfo == NULL)
1891 return DAC960_Failure(Controller, "LOGICAL DEVICE ALLOCATION");
1892 Controller->V2.LogicalDeviceInformation[LogicalDeviceNumber] =
1893 LogicalDeviceInfo;
1894 memcpy(LogicalDeviceInfo, NewLogicalDeviceInfo,
1895 sizeof(DAC960_V2_LogicalDeviceInfo_T));
1896 LogicalDeviceNumber++;
1897 }
1898 return true;
1899}
1900
1901
1902
1903
1904
1905
1906
1907static bool DAC960_ReportControllerConfiguration(DAC960_Controller_T
1908 *Controller)
1909{
1910 DAC960_Info("Configuring Mylex %s PCI RAID Controller\n",
1911 Controller, Controller->ModelName);
1912 DAC960_Info(" Firmware Version: %s, Channels: %d, Memory Size: %dMB\n",
1913 Controller, Controller->FirmwareVersion,
1914 Controller->Channels, Controller->MemorySize);
1915 DAC960_Info(" PCI Bus: %d, Device: %d, Function: %d, I/O Address: ",
1916 Controller, Controller->Bus,
1917 Controller->Device, Controller->Function);
1918 if (Controller->IO_Address == 0)
1919 DAC960_Info("Unassigned\n", Controller);
1920 else DAC960_Info("0x%X\n", Controller, Controller->IO_Address);
1921 DAC960_Info(" PCI Address: 0x%X mapped at 0x%lX, IRQ Channel: %d\n",
1922 Controller, Controller->PCI_Address,
1923 (unsigned long) Controller->BaseAddress,
1924 Controller->IRQ_Channel);
1925 DAC960_Info(" Controller Queue Depth: %d, "
1926 "Maximum Blocks per Command: %d\n",
1927 Controller, Controller->ControllerQueueDepth,
1928 Controller->MaxBlocksPerCommand);
1929 DAC960_Info(" Driver Queue Depth: %d, "
1930 "Scatter/Gather Limit: %d of %d Segments\n",
1931 Controller, Controller->DriverQueueDepth,
1932 Controller->DriverScatterGatherLimit,
1933 Controller->ControllerScatterGatherLimit);
1934 if (Controller->FirmwareType == DAC960_V1_Controller)
1935 {
1936 DAC960_Info(" Stripe Size: %dKB, Segment Size: %dKB, "
1937 "BIOS Geometry: %d/%d\n", Controller,
1938 Controller->V1.StripeSize,
1939 Controller->V1.SegmentSize,
1940 Controller->V1.GeometryTranslationHeads,
1941 Controller->V1.GeometryTranslationSectors);
1942 if (Controller->V1.SAFTE_EnclosureManagementEnabled)
1943 DAC960_Info(" SAF-TE Enclosure Management Enabled\n", Controller);
1944 }
1945 return true;
1946}
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956static bool DAC960_V1_ReadDeviceConfiguration(DAC960_Controller_T
1957 *Controller)
1958{
1959 struct dma_loaf local_dma;
1960
1961 dma_addr_t DCDBs_dma[DAC960_V1_MaxChannels];
1962 DAC960_V1_DCDB_T *DCDBs_cpu[DAC960_V1_MaxChannels];
1963
1964 dma_addr_t SCSI_Inquiry_dma[DAC960_V1_MaxChannels];
1965 DAC960_SCSI_Inquiry_T *SCSI_Inquiry_cpu[DAC960_V1_MaxChannels];
1966
1967 dma_addr_t SCSI_NewInquiryUnitSerialNumberDMA[DAC960_V1_MaxChannels];
1968 DAC960_SCSI_Inquiry_UnitSerialNumber_T *SCSI_NewInquiryUnitSerialNumberCPU[DAC960_V1_MaxChannels];
1969
1970 struct completion Completions[DAC960_V1_MaxChannels];
1971 unsigned long flags;
1972 int Channel, TargetID;
1973
1974 if (!init_dma_loaf(Controller->PCIDevice, &local_dma,
1975 DAC960_V1_MaxChannels*(sizeof(DAC960_V1_DCDB_T) +
1976 sizeof(DAC960_SCSI_Inquiry_T) +
1977 sizeof(DAC960_SCSI_Inquiry_UnitSerialNumber_T))))
1978 return DAC960_Failure(Controller,
1979 "DMA ALLOCATION FAILED IN ReadDeviceConfiguration");
1980
1981 for (Channel = 0; Channel < Controller->Channels; Channel++) {
1982 DCDBs_cpu[Channel] = slice_dma_loaf(&local_dma,
1983 sizeof(DAC960_V1_DCDB_T), DCDBs_dma + Channel);
1984 SCSI_Inquiry_cpu[Channel] = slice_dma_loaf(&local_dma,
1985 sizeof(DAC960_SCSI_Inquiry_T),
1986 SCSI_Inquiry_dma + Channel);
1987 SCSI_NewInquiryUnitSerialNumberCPU[Channel] = slice_dma_loaf(&local_dma,
1988 sizeof(DAC960_SCSI_Inquiry_UnitSerialNumber_T),
1989 SCSI_NewInquiryUnitSerialNumberDMA + Channel);
1990 }
1991
1992 for (TargetID = 0; TargetID < Controller->Targets; TargetID++)
1993 {
1994
1995
1996
1997
1998
1999
2000 for (Channel = 0; Channel < Controller->Channels; Channel++)
2001 {
2002 dma_addr_t NewInquiryStandardDataDMA = SCSI_Inquiry_dma[Channel];
2003 DAC960_V1_DCDB_T *DCDB = DCDBs_cpu[Channel];
2004 dma_addr_t DCDB_dma = DCDBs_dma[Channel];
2005 DAC960_Command_T *Command = Controller->Commands[Channel];
2006 struct completion *Completion = &Completions[Channel];
2007
2008 init_completion(Completion);
2009 DAC960_V1_ClearCommand(Command);
2010 Command->CommandType = DAC960_ImmediateCommand;
2011 Command->Completion = Completion;
2012 Command->V1.CommandMailbox.Type3.CommandOpcode = DAC960_V1_DCDB;
2013 Command->V1.CommandMailbox.Type3.BusAddress = DCDB_dma;
2014 DCDB->Channel = Channel;
2015 DCDB->TargetID = TargetID;
2016 DCDB->Direction = DAC960_V1_DCDB_DataTransferDeviceToSystem;
2017 DCDB->EarlyStatus = false;
2018 DCDB->Timeout = DAC960_V1_DCDB_Timeout_10_seconds;
2019 DCDB->NoAutomaticRequestSense = false;
2020 DCDB->DisconnectPermitted = true;
2021 DCDB->TransferLength = sizeof(DAC960_SCSI_Inquiry_T);
2022 DCDB->BusAddress = NewInquiryStandardDataDMA;
2023 DCDB->CDBLength = 6;
2024 DCDB->TransferLengthHigh4 = 0;
2025 DCDB->SenseLength = sizeof(DCDB->SenseData);
2026 DCDB->CDB[0] = 0x12;
2027 DCDB->CDB[1] = 0;
2028 DCDB->CDB[2] = 0;
2029 DCDB->CDB[3] = 0;
2030 DCDB->CDB[4] = sizeof(DAC960_SCSI_Inquiry_T);
2031 DCDB->CDB[5] = 0;
2032
2033 spin_lock_irqsave(&Controller->queue_lock, flags);
2034 DAC960_QueueCommand(Command);
2035 spin_unlock_irqrestore(&Controller->queue_lock, flags);
2036 }
2037
2038
2039
2040
2041
2042 for (Channel = 0; Channel < Controller->Channels; Channel++)
2043 {
2044 DAC960_SCSI_Inquiry_T *InquiryStandardData =
2045 &Controller->V1.InquiryStandardData[Channel][TargetID];
2046 DAC960_SCSI_Inquiry_T *NewInquiryStandardData = SCSI_Inquiry_cpu[Channel];
2047 dma_addr_t NewInquiryUnitSerialNumberDMA =
2048 SCSI_NewInquiryUnitSerialNumberDMA[Channel];
2049 DAC960_SCSI_Inquiry_UnitSerialNumber_T *NewInquiryUnitSerialNumber =
2050 SCSI_NewInquiryUnitSerialNumberCPU[Channel];
2051 DAC960_SCSI_Inquiry_UnitSerialNumber_T *InquiryUnitSerialNumber =
2052 &Controller->V1.InquiryUnitSerialNumber[Channel][TargetID];
2053 DAC960_Command_T *Command = Controller->Commands[Channel];
2054 DAC960_V1_DCDB_T *DCDB = DCDBs_cpu[Channel];
2055 struct completion *Completion = &Completions[Channel];
2056
2057 wait_for_completion(Completion);
2058
2059 if (Command->V1.CommandStatus != DAC960_V1_NormalCompletion) {
2060 memset(InquiryStandardData, 0, sizeof(DAC960_SCSI_Inquiry_T));
2061 InquiryStandardData->PeripheralDeviceType = 0x1F;
2062 continue;
2063 } else
2064 memcpy(InquiryStandardData, NewInquiryStandardData, sizeof(DAC960_SCSI_Inquiry_T));
2065
2066
2067 Command->Completion = Completion;
2068 DCDB->TransferLength = sizeof(DAC960_SCSI_Inquiry_UnitSerialNumber_T);
2069 DCDB->BusAddress = NewInquiryUnitSerialNumberDMA;
2070 DCDB->SenseLength = sizeof(DCDB->SenseData);
2071 DCDB->CDB[0] = 0x12;
2072 DCDB->CDB[1] = 1;
2073 DCDB->CDB[2] = 0x80;
2074 DCDB->CDB[3] = 0;
2075 DCDB->CDB[4] = sizeof(DAC960_SCSI_Inquiry_UnitSerialNumber_T);
2076 DCDB->CDB[5] = 0;
2077
2078 spin_lock_irqsave(&Controller->queue_lock, flags);
2079 DAC960_QueueCommand(Command);
2080 spin_unlock_irqrestore(&Controller->queue_lock, flags);
2081 wait_for_completion(Completion);
2082
2083 if (Command->V1.CommandStatus != DAC960_V1_NormalCompletion) {
2084 memset(InquiryUnitSerialNumber, 0,
2085 sizeof(DAC960_SCSI_Inquiry_UnitSerialNumber_T));
2086 InquiryUnitSerialNumber->PeripheralDeviceType = 0x1F;
2087 } else
2088 memcpy(InquiryUnitSerialNumber, NewInquiryUnitSerialNumber,
2089 sizeof(DAC960_SCSI_Inquiry_UnitSerialNumber_T));
2090 }
2091 }
2092 free_dma_loaf(Controller->PCIDevice, &local_dma);
2093 return true;
2094}
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104static bool DAC960_V2_ReadDeviceConfiguration(DAC960_Controller_T
2105 *Controller)
2106{
2107 unsigned char Channel = 0, TargetID = 0, LogicalUnit = 0;
2108 unsigned short PhysicalDeviceIndex = 0;
2109
2110 while (true)
2111 {
2112 DAC960_V2_PhysicalDeviceInfo_T *NewPhysicalDeviceInfo =
2113 Controller->V2.NewPhysicalDeviceInformation;
2114 DAC960_V2_PhysicalDeviceInfo_T *PhysicalDeviceInfo;
2115 DAC960_SCSI_Inquiry_UnitSerialNumber_T *NewInquiryUnitSerialNumber =
2116 Controller->V2.NewInquiryUnitSerialNumber;
2117 DAC960_SCSI_Inquiry_UnitSerialNumber_T *InquiryUnitSerialNumber;
2118
2119 if (!DAC960_V2_NewPhysicalDeviceInfo(Controller, Channel, TargetID, LogicalUnit))
2120 break;
2121
2122 PhysicalDeviceInfo = kmalloc(sizeof(DAC960_V2_PhysicalDeviceInfo_T),
2123 GFP_ATOMIC);
2124 if (PhysicalDeviceInfo == NULL)
2125 return DAC960_Failure(Controller, "PHYSICAL DEVICE ALLOCATION");
2126 Controller->V2.PhysicalDeviceInformation[PhysicalDeviceIndex] =
2127 PhysicalDeviceInfo;
2128 memcpy(PhysicalDeviceInfo, NewPhysicalDeviceInfo,
2129 sizeof(DAC960_V2_PhysicalDeviceInfo_T));
2130
2131 InquiryUnitSerialNumber = kmalloc(
2132 sizeof(DAC960_SCSI_Inquiry_UnitSerialNumber_T), GFP_ATOMIC);
2133 if (InquiryUnitSerialNumber == NULL) {
2134 kfree(PhysicalDeviceInfo);
2135 return DAC960_Failure(Controller, "SERIAL NUMBER ALLOCATION");
2136 }
2137 Controller->V2.InquiryUnitSerialNumber[PhysicalDeviceIndex] =
2138 InquiryUnitSerialNumber;
2139
2140 Channel = NewPhysicalDeviceInfo->Channel;
2141 TargetID = NewPhysicalDeviceInfo->TargetID;
2142 LogicalUnit = NewPhysicalDeviceInfo->LogicalUnit;
2143
2144
2145
2146
2147
2148
2149
2150 if (!DAC960_V2_NewInquiryUnitSerialNumber(Controller, Channel, TargetID, LogicalUnit)) {
2151 memset(InquiryUnitSerialNumber, 0,
2152 sizeof(DAC960_SCSI_Inquiry_UnitSerialNumber_T));
2153 InquiryUnitSerialNumber->PeripheralDeviceType = 0x1F;
2154 } else
2155 memcpy(InquiryUnitSerialNumber, NewInquiryUnitSerialNumber,
2156 sizeof(DAC960_SCSI_Inquiry_UnitSerialNumber_T));
2157
2158 PhysicalDeviceIndex++;
2159 LogicalUnit++;
2160 }
2161 return true;
2162}
2163
2164
2165
2166
2167
2168
2169
2170
2171static void DAC960_SanitizeInquiryData(DAC960_SCSI_Inquiry_T
2172 *InquiryStandardData,
2173 DAC960_SCSI_Inquiry_UnitSerialNumber_T
2174 *InquiryUnitSerialNumber,
2175 unsigned char *Vendor,
2176 unsigned char *Model,
2177 unsigned char *Revision,
2178 unsigned char *SerialNumber)
2179{
2180 int SerialNumberLength, i;
2181 if (InquiryStandardData->PeripheralDeviceType == 0x1F) return;
2182 for (i = 0; i < sizeof(InquiryStandardData->VendorIdentification); i++)
2183 {
2184 unsigned char VendorCharacter =
2185 InquiryStandardData->VendorIdentification[i];
2186 Vendor[i] = (VendorCharacter >= ' ' && VendorCharacter <= '~'
2187 ? VendorCharacter : ' ');
2188 }
2189 Vendor[sizeof(InquiryStandardData->VendorIdentification)] = '\0';
2190 for (i = 0; i < sizeof(InquiryStandardData->ProductIdentification); i++)
2191 {
2192 unsigned char ModelCharacter =
2193 InquiryStandardData->ProductIdentification[i];
2194 Model[i] = (ModelCharacter >= ' ' && ModelCharacter <= '~'
2195 ? ModelCharacter : ' ');
2196 }
2197 Model[sizeof(InquiryStandardData->ProductIdentification)] = '\0';
2198 for (i = 0; i < sizeof(InquiryStandardData->ProductRevisionLevel); i++)
2199 {
2200 unsigned char RevisionCharacter =
2201 InquiryStandardData->ProductRevisionLevel[i];
2202 Revision[i] = (RevisionCharacter >= ' ' && RevisionCharacter <= '~'
2203 ? RevisionCharacter : ' ');
2204 }
2205 Revision[sizeof(InquiryStandardData->ProductRevisionLevel)] = '\0';
2206 if (InquiryUnitSerialNumber->PeripheralDeviceType == 0x1F) return;
2207 SerialNumberLength = InquiryUnitSerialNumber->PageLength;
2208 if (SerialNumberLength >
2209 sizeof(InquiryUnitSerialNumber->ProductSerialNumber))
2210 SerialNumberLength = sizeof(InquiryUnitSerialNumber->ProductSerialNumber);
2211 for (i = 0; i < SerialNumberLength; i++)
2212 {
2213 unsigned char SerialNumberCharacter =
2214 InquiryUnitSerialNumber->ProductSerialNumber[i];
2215 SerialNumber[i] =
2216 (SerialNumberCharacter >= ' ' && SerialNumberCharacter <= '~'
2217 ? SerialNumberCharacter : ' ');
2218 }
2219 SerialNumber[SerialNumberLength] = '\0';
2220}
2221
2222
2223
2224
2225
2226
2227
2228static bool DAC960_V1_ReportDeviceConfiguration(DAC960_Controller_T
2229 *Controller)
2230{
2231 int LogicalDriveNumber, Channel, TargetID;
2232 DAC960_Info(" Physical Devices:\n", Controller);
2233 for (Channel = 0; Channel < Controller->Channels; Channel++)
2234 for (TargetID = 0; TargetID < Controller->Targets; TargetID++)
2235 {
2236 DAC960_SCSI_Inquiry_T *InquiryStandardData =
2237 &Controller->V1.InquiryStandardData[Channel][TargetID];
2238 DAC960_SCSI_Inquiry_UnitSerialNumber_T *InquiryUnitSerialNumber =
2239 &Controller->V1.InquiryUnitSerialNumber[Channel][TargetID];
2240 DAC960_V1_DeviceState_T *DeviceState =
2241 &Controller->V1.DeviceState[Channel][TargetID];
2242 DAC960_V1_ErrorTableEntry_T *ErrorEntry =
2243 &Controller->V1.ErrorTable.ErrorTableEntries[Channel][TargetID];
2244 char Vendor[1+sizeof(InquiryStandardData->VendorIdentification)];
2245 char Model[1+sizeof(InquiryStandardData->ProductIdentification)];
2246 char Revision[1+sizeof(InquiryStandardData->ProductRevisionLevel)];
2247 char SerialNumber[1+sizeof(InquiryUnitSerialNumber
2248 ->ProductSerialNumber)];
2249 if (InquiryStandardData->PeripheralDeviceType == 0x1F) continue;
2250 DAC960_SanitizeInquiryData(InquiryStandardData, InquiryUnitSerialNumber,
2251 Vendor, Model, Revision, SerialNumber);
2252 DAC960_Info(" %d:%d%s Vendor: %s Model: %s Revision: %s\n",
2253 Controller, Channel, TargetID, (TargetID < 10 ? " " : ""),
2254 Vendor, Model, Revision);
2255 if (InquiryUnitSerialNumber->PeripheralDeviceType != 0x1F)
2256 DAC960_Info(" Serial Number: %s\n", Controller, SerialNumber);
2257 if (DeviceState->Present &&
2258 DeviceState->DeviceType == DAC960_V1_DiskType)
2259 {
2260 if (Controller->V1.DeviceResetCount[Channel][TargetID] > 0)
2261 DAC960_Info(" Disk Status: %s, %u blocks, %d resets\n",
2262 Controller,
2263 (DeviceState->DeviceState == DAC960_V1_Device_Dead
2264 ? "Dead"
2265 : DeviceState->DeviceState
2266 == DAC960_V1_Device_WriteOnly
2267 ? "Write-Only"
2268 : DeviceState->DeviceState
2269 == DAC960_V1_Device_Online
2270 ? "Online" : "Standby"),
2271 DeviceState->DiskSize,
2272 Controller->V1.DeviceResetCount[Channel][TargetID]);
2273 else
2274 DAC960_Info(" Disk Status: %s, %u blocks\n", Controller,
2275 (DeviceState->DeviceState == DAC960_V1_Device_Dead
2276 ? "Dead"
2277 : DeviceState->DeviceState
2278 == DAC960_V1_Device_WriteOnly
2279 ? "Write-Only"
2280 : DeviceState->DeviceState
2281 == DAC960_V1_Device_Online
2282 ? "Online" : "Standby"),
2283 DeviceState->DiskSize);
2284 }
2285 if (ErrorEntry->ParityErrorCount > 0 ||
2286 ErrorEntry->SoftErrorCount > 0 ||
2287 ErrorEntry->HardErrorCount > 0 ||
2288 ErrorEntry->MiscErrorCount > 0)
2289 DAC960_Info(" Errors - Parity: %d, Soft: %d, "
2290 "Hard: %d, Misc: %d\n", Controller,
2291 ErrorEntry->ParityErrorCount,
2292 ErrorEntry->SoftErrorCount,
2293 ErrorEntry->HardErrorCount,
2294 ErrorEntry->MiscErrorCount);
2295 }
2296 DAC960_Info(" Logical Drives:\n", Controller);
2297 for (LogicalDriveNumber = 0;
2298 LogicalDriveNumber < Controller->LogicalDriveCount;
2299 LogicalDriveNumber++)
2300 {
2301 DAC960_V1_LogicalDriveInformation_T *LogicalDriveInformation =
2302 &Controller->V1.LogicalDriveInformation[LogicalDriveNumber];
2303 DAC960_Info(" /dev/rd/c%dd%d: RAID-%d, %s, %u blocks, %s\n",
2304 Controller, Controller->ControllerNumber, LogicalDriveNumber,
2305 LogicalDriveInformation->RAIDLevel,
2306 (LogicalDriveInformation->LogicalDriveState
2307 == DAC960_V1_LogicalDrive_Online
2308 ? "Online"
2309 : LogicalDriveInformation->LogicalDriveState
2310 == DAC960_V1_LogicalDrive_Critical
2311 ? "Critical" : "Offline"),
2312 LogicalDriveInformation->LogicalDriveSize,
2313 (LogicalDriveInformation->WriteBack
2314 ? "Write Back" : "Write Thru"));
2315 }
2316 return true;
2317}
2318
2319
2320
2321
2322
2323
2324
2325static bool DAC960_V2_ReportDeviceConfiguration(DAC960_Controller_T
2326 *Controller)
2327{
2328 int PhysicalDeviceIndex, LogicalDriveNumber;
2329 DAC960_Info(" Physical Devices:\n", Controller);
2330 for (PhysicalDeviceIndex = 0;
2331 PhysicalDeviceIndex < DAC960_V2_MaxPhysicalDevices;
2332 PhysicalDeviceIndex++)
2333 {
2334 DAC960_V2_PhysicalDeviceInfo_T *PhysicalDeviceInfo =
2335 Controller->V2.PhysicalDeviceInformation[PhysicalDeviceIndex];
2336 DAC960_SCSI_Inquiry_T *InquiryStandardData =
2337 (DAC960_SCSI_Inquiry_T *) &PhysicalDeviceInfo->SCSI_InquiryData;
2338 DAC960_SCSI_Inquiry_UnitSerialNumber_T *InquiryUnitSerialNumber =
2339 Controller->V2.InquiryUnitSerialNumber[PhysicalDeviceIndex];
2340 char Vendor[1+sizeof(InquiryStandardData->VendorIdentification)];
2341 char Model[1+sizeof(InquiryStandardData->ProductIdentification)];
2342 char Revision[1+sizeof(InquiryStandardData->ProductRevisionLevel)];
2343 char SerialNumber[1+sizeof(InquiryUnitSerialNumber->ProductSerialNumber)];
2344 if (PhysicalDeviceInfo == NULL) break;
2345 DAC960_SanitizeInquiryData(InquiryStandardData, InquiryUnitSerialNumber,
2346 Vendor, Model, Revision, SerialNumber);
2347 DAC960_Info(" %d:%d%s Vendor: %s Model: %s Revision: %s\n",
2348 Controller,
2349 PhysicalDeviceInfo->Channel,
2350 PhysicalDeviceInfo->TargetID,
2351 (PhysicalDeviceInfo->TargetID < 10 ? " " : ""),
2352 Vendor, Model, Revision);
2353 if (PhysicalDeviceInfo->NegotiatedSynchronousMegaTransfers == 0)
2354 DAC960_Info(" %sAsynchronous\n", Controller,
2355 (PhysicalDeviceInfo->NegotiatedDataWidthBits == 16
2356 ? "Wide " :""));
2357 else
2358 DAC960_Info(" %sSynchronous at %d MB/sec\n", Controller,
2359 (PhysicalDeviceInfo->NegotiatedDataWidthBits == 16
2360 ? "Wide " :""),
2361 (PhysicalDeviceInfo->NegotiatedSynchronousMegaTransfers
2362 * PhysicalDeviceInfo->NegotiatedDataWidthBits/8));
2363 if (InquiryUnitSerialNumber->PeripheralDeviceType != 0x1F)
2364 DAC960_Info(" Serial Number: %s\n", Controller, SerialNumber);
2365 if (PhysicalDeviceInfo->PhysicalDeviceState ==
2366 DAC960_V2_Device_Unconfigured)
2367 continue;
2368 DAC960_Info(" Disk Status: %s, %u blocks\n", Controller,
2369 (PhysicalDeviceInfo->PhysicalDeviceState
2370 == DAC960_V2_Device_Online
2371 ? "Online"
2372 : PhysicalDeviceInfo->PhysicalDeviceState
2373 == DAC960_V2_Device_Rebuild
2374 ? "Rebuild"
2375 : PhysicalDeviceInfo->PhysicalDeviceState
2376 == DAC960_V2_Device_Missing
2377 ? "Missing"
2378 : PhysicalDeviceInfo->PhysicalDeviceState
2379 == DAC960_V2_Device_Critical
2380 ? "Critical"
2381 : PhysicalDeviceInfo->PhysicalDeviceState
2382 == DAC960_V2_Device_Dead
2383 ? "Dead"
2384 : PhysicalDeviceInfo->PhysicalDeviceState
2385 == DAC960_V2_Device_SuspectedDead
2386 ? "Suspected-Dead"
2387 : PhysicalDeviceInfo->PhysicalDeviceState
2388 == DAC960_V2_Device_CommandedOffline
2389 ? "Commanded-Offline"
2390 : PhysicalDeviceInfo->PhysicalDeviceState
2391 == DAC960_V2_Device_Standby
2392 ? "Standby" : "Unknown"),
2393 PhysicalDeviceInfo->ConfigurableDeviceSize);
2394 if (PhysicalDeviceInfo->ParityErrors == 0 &&
2395 PhysicalDeviceInfo->SoftErrors == 0 &&
2396 PhysicalDeviceInfo->HardErrors == 0 &&
2397 PhysicalDeviceInfo->MiscellaneousErrors == 0 &&
2398 PhysicalDeviceInfo->CommandTimeouts == 0 &&
2399 PhysicalDeviceInfo->Retries == 0 &&
2400 PhysicalDeviceInfo->Aborts == 0 &&
2401 PhysicalDeviceInfo->PredictedFailuresDetected == 0)
2402 continue;
2403 DAC960_Info(" Errors - Parity: %d, Soft: %d, "
2404 "Hard: %d, Misc: %d\n", Controller,
2405 PhysicalDeviceInfo->ParityErrors,
2406 PhysicalDeviceInfo->SoftErrors,
2407 PhysicalDeviceInfo->HardErrors,
2408 PhysicalDeviceInfo->MiscellaneousErrors);
2409 DAC960_Info(" Timeouts: %d, Retries: %d, "
2410 "Aborts: %d, Predicted: %d\n", Controller,
2411 PhysicalDeviceInfo->CommandTimeouts,
2412 PhysicalDeviceInfo->Retries,
2413 PhysicalDeviceInfo->Aborts,
2414 PhysicalDeviceInfo->PredictedFailuresDetected);
2415 }
2416 DAC960_Info(" Logical Drives:\n", Controller);
2417 for (LogicalDriveNumber = 0;
2418 LogicalDriveNumber < DAC960_MaxLogicalDrives;
2419 LogicalDriveNumber++)
2420 {
2421 DAC960_V2_LogicalDeviceInfo_T *LogicalDeviceInfo =
2422 Controller->V2.LogicalDeviceInformation[LogicalDriveNumber];
2423 unsigned char *ReadCacheStatus[] = { "Read Cache Disabled",
2424 "Read Cache Enabled",
2425 "Read Ahead Enabled",
2426 "Intelligent Read Ahead Enabled",
2427 "-", "-", "-", "-" };
2428 unsigned char *WriteCacheStatus[] = { "Write Cache Disabled",
2429 "Logical Device Read Only",
2430 "Write Cache Enabled",
2431 "Intelligent Write Cache Enabled",
2432 "-", "-", "-", "-" };
2433 unsigned char *GeometryTranslation;
2434 if (LogicalDeviceInfo == NULL) continue;
2435 switch (LogicalDeviceInfo->DriveGeometry)
2436 {
2437 case DAC960_V2_Geometry_128_32:
2438 GeometryTranslation = "128/32";
2439 break;
2440 case DAC960_V2_Geometry_255_63:
2441 GeometryTranslation = "255/63";
2442 break;
2443 default:
2444 GeometryTranslation = "Invalid";
2445 DAC960_Error("Illegal Logical Device Geometry %d\n",
2446 Controller, LogicalDeviceInfo->DriveGeometry);
2447 break;
2448 }
2449 DAC960_Info(" /dev/rd/c%dd%d: RAID-%d, %s, %u blocks\n",
2450 Controller, Controller->ControllerNumber, LogicalDriveNumber,
2451 LogicalDeviceInfo->RAIDLevel,
2452 (LogicalDeviceInfo->LogicalDeviceState
2453 == DAC960_V2_LogicalDevice_Online
2454 ? "Online"
2455 : LogicalDeviceInfo->LogicalDeviceState
2456 == DAC960_V2_LogicalDevice_Critical
2457 ? "Critical" : "Offline"),
2458 LogicalDeviceInfo->ConfigurableDeviceSize);
2459 DAC960_Info(" Logical Device %s, BIOS Geometry: %s\n",
2460 Controller,
2461 (LogicalDeviceInfo->LogicalDeviceControl
2462 .LogicalDeviceInitialized
2463 ? "Initialized" : "Uninitialized"),
2464 GeometryTranslation);
2465 if (LogicalDeviceInfo->StripeSize == 0)
2466 {
2467 if (LogicalDeviceInfo->CacheLineSize == 0)
2468 DAC960_Info(" Stripe Size: N/A, "
2469 "Segment Size: N/A\n", Controller);
2470 else
2471 DAC960_Info(" Stripe Size: N/A, "
2472 "Segment Size: %dKB\n", Controller,
2473 1 << (LogicalDeviceInfo->CacheLineSize - 2));
2474 }
2475 else
2476 {
2477 if (LogicalDeviceInfo->CacheLineSize == 0)
2478 DAC960_Info(" Stripe Size: %dKB, "
2479 "Segment Size: N/A\n", Controller,
2480 1 << (LogicalDeviceInfo->StripeSize - 2));
2481 else
2482 DAC960_Info(" Stripe Size: %dKB, "
2483 "Segment Size: %dKB\n", Controller,
2484 1 << (LogicalDeviceInfo->StripeSize - 2),
2485 1 << (LogicalDeviceInfo->CacheLineSize - 2));
2486 }
2487 DAC960_Info(" %s, %s\n", Controller,
2488 ReadCacheStatus[
2489 LogicalDeviceInfo->LogicalDeviceControl.ReadCache],
2490 WriteCacheStatus[
2491 LogicalDeviceInfo->LogicalDeviceControl.WriteCache]);
2492 if (LogicalDeviceInfo->SoftErrors > 0 ||
2493 LogicalDeviceInfo->CommandsFailed > 0 ||
2494 LogicalDeviceInfo->DeferredWriteErrors)
2495 DAC960_Info(" Errors - Soft: %d, Failed: %d, "
2496 "Deferred Write: %d\n", Controller,
2497 LogicalDeviceInfo->SoftErrors,
2498 LogicalDeviceInfo->CommandsFailed,
2499 LogicalDeviceInfo->DeferredWriteErrors);
2500
2501 }
2502 return true;
2503}
2504
2505
2506
2507
2508
2509
2510static bool DAC960_RegisterBlockDevice(DAC960_Controller_T *Controller)
2511{
2512 int MajorNumber = DAC960_MAJOR + Controller->ControllerNumber;
2513 int n;
2514
2515
2516
2517
2518 if (register_blkdev(MajorNumber, "dac960") < 0)
2519 return false;
2520
2521 for (n = 0; n < DAC960_MaxLogicalDrives; n++) {
2522 struct gendisk *disk = Controller->disks[n];
2523 struct request_queue *RequestQueue;
2524
2525
2526 RequestQueue = blk_init_queue(DAC960_RequestFunction,&Controller->queue_lock);
2527 if (!RequestQueue) {
2528 printk("DAC960: failure to allocate request queue\n");
2529 continue;
2530 }
2531 Controller->RequestQueue[n] = RequestQueue;
2532 blk_queue_bounce_limit(RequestQueue, Controller->BounceBufferLimit);
2533 RequestQueue->queuedata = Controller;
2534 blk_queue_max_hw_segments(RequestQueue, Controller->DriverScatterGatherLimit);
2535 blk_queue_max_phys_segments(RequestQueue, Controller->DriverScatterGatherLimit);
2536 blk_queue_max_sectors(RequestQueue, Controller->MaxBlocksPerCommand);
2537 disk->queue = RequestQueue;
2538 sprintf(disk->disk_name, "rd/c%dd%d", Controller->ControllerNumber, n);
2539 disk->major = MajorNumber;
2540 disk->first_minor = n << DAC960_MaxPartitionsBits;
2541 disk->fops = &DAC960_BlockDeviceOperations;
2542 }
2543
2544
2545
2546 return true;
2547}
2548
2549
2550
2551
2552
2553
2554
2555static void DAC960_UnregisterBlockDevice(DAC960_Controller_T *Controller)
2556{
2557 int MajorNumber = DAC960_MAJOR + Controller->ControllerNumber;
2558 int disk;
2559
2560
2561 for (disk = 0; disk < DAC960_MaxLogicalDrives; disk++) {
2562 del_gendisk(Controller->disks[disk]);
2563 blk_cleanup_queue(Controller->RequestQueue[disk]);
2564 Controller->RequestQueue[disk] = NULL;
2565 }
2566
2567
2568
2569
2570 unregister_blkdev(MajorNumber, "dac960");
2571}
2572
2573
2574
2575
2576
2577
2578static void DAC960_ComputeGenericDiskInfo(DAC960_Controller_T *Controller)
2579{
2580 int disk;
2581 for (disk = 0; disk < DAC960_MaxLogicalDrives; disk++)
2582 set_capacity(Controller->disks[disk], disk_size(Controller, disk));
2583}
2584
2585
2586
2587
2588
2589
2590
2591static bool DAC960_ReportErrorStatus(DAC960_Controller_T *Controller,
2592 unsigned char ErrorStatus,
2593 unsigned char Parameter0,
2594 unsigned char Parameter1)
2595{
2596 switch (ErrorStatus)
2597 {
2598 case 0x00:
2599 DAC960_Notice("Physical Device %d:%d Not Responding\n",
2600 Controller, Parameter1, Parameter0);
2601 break;
2602 case 0x08:
2603 if (Controller->DriveSpinUpMessageDisplayed) break;
2604 DAC960_Notice("Spinning Up Drives\n", Controller);
2605 Controller->DriveSpinUpMessageDisplayed = true;
2606 break;
2607 case 0x30:
2608 DAC960_Notice("Configuration Checksum Error\n", Controller);
2609 break;
2610 case 0x60:
2611 DAC960_Notice("Mirror Race Recovery Failed\n", Controller);
2612 break;
2613 case 0x70:
2614 DAC960_Notice("Mirror Race Recovery In Progress\n", Controller);
2615 break;
2616 case 0x90:
2617 DAC960_Notice("Physical Device %d:%d COD Mismatch\n",
2618 Controller, Parameter1, Parameter0);
2619 break;
2620 case 0xA0:
2621 DAC960_Notice("Logical Drive Installation Aborted\n", Controller);
2622 break;
2623 case 0xB0:
2624 DAC960_Notice("Mirror Race On A Critical Logical Drive\n", Controller);
2625 break;
2626 case 0xD0:
2627 DAC960_Notice("New Controller Configuration Found\n", Controller);
2628 break;
2629 case 0xF0:
2630 DAC960_Error("Fatal Memory Parity Error for Controller at\n", Controller);
2631 return true;
2632 default:
2633 DAC960_Error("Unknown Initialization Error %02X for Controller at\n",
2634 Controller, ErrorStatus);
2635 return true;
2636 }
2637 return false;
2638}
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650static void DAC960_DetectCleanup(DAC960_Controller_T *Controller)
2651{
2652 int i;
2653
2654
2655 free_dma_loaf(Controller->PCIDevice, &Controller->DmaPages);
2656 if (Controller->MemoryMappedAddress) {
2657 switch(Controller->HardwareType)
2658 {
2659 case DAC960_GEM_Controller:
2660 DAC960_GEM_DisableInterrupts(Controller->BaseAddress);
2661 break;
2662 case DAC960_BA_Controller:
2663 DAC960_BA_DisableInterrupts(Controller->BaseAddress);
2664 break;
2665 case DAC960_LP_Controller:
2666 DAC960_LP_DisableInterrupts(Controller->BaseAddress);
2667 break;
2668 case DAC960_LA_Controller:
2669 DAC960_LA_DisableInterrupts(Controller->BaseAddress);
2670 break;
2671 case DAC960_PG_Controller:
2672 DAC960_PG_DisableInterrupts(Controller->BaseAddress);
2673 break;
2674 case DAC960_PD_Controller:
2675 DAC960_PD_DisableInterrupts(Controller->BaseAddress);
2676 break;
2677 case DAC960_P_Controller:
2678 DAC960_PD_DisableInterrupts(Controller->BaseAddress);
2679 break;
2680 }
2681 iounmap(Controller->MemoryMappedAddress);
2682 }
2683 if (Controller->IRQ_Channel)
2684 free_irq(Controller->IRQ_Channel, Controller);
2685 if (Controller->IO_Address)
2686 release_region(Controller->IO_Address, 0x80);
2687 pci_disable_device(Controller->PCIDevice);
2688 for (i = 0; (i < DAC960_MaxLogicalDrives) && Controller->disks[i]; i++)
2689 put_disk(Controller->disks[i]);
2690 DAC960_Controllers[Controller->ControllerNumber] = NULL;
2691 kfree(Controller);
2692}
2693
2694
2695
2696
2697
2698
2699
2700
2701static DAC960_Controller_T *
2702DAC960_DetectController(struct pci_dev *PCI_Device,
2703 const struct pci_device_id *entry)
2704{
2705 struct DAC960_privdata *privdata =
2706 (struct DAC960_privdata *)entry->driver_data;
2707 irq_handler_t InterruptHandler = privdata->InterruptHandler;
2708 unsigned int MemoryWindowSize = privdata->MemoryWindowSize;
2709 DAC960_Controller_T *Controller = NULL;
2710 unsigned char DeviceFunction = PCI_Device->devfn;
2711 unsigned char ErrorStatus, Parameter0, Parameter1;
2712 unsigned int IRQ_Channel;
2713 void __iomem *BaseAddress;
2714 int i;
2715
2716 Controller = kzalloc(sizeof(DAC960_Controller_T), GFP_ATOMIC);
2717 if (Controller == NULL) {
2718 DAC960_Error("Unable to allocate Controller structure for "
2719 "Controller at\n", NULL);
2720 return NULL;
2721 }
2722 Controller->ControllerNumber = DAC960_ControllerCount;
2723 DAC960_Controllers[DAC960_ControllerCount++] = Controller;
2724 Controller->Bus = PCI_Device->bus->number;
2725 Controller->FirmwareType = privdata->FirmwareType;
2726 Controller->HardwareType = privdata->HardwareType;
2727 Controller->Device = DeviceFunction >> 3;
2728 Controller->Function = DeviceFunction & 0x7;
2729 Controller->PCIDevice = PCI_Device;
2730 strcpy(Controller->FullModelName, "DAC960");
2731
2732 if (pci_enable_device(PCI_Device))
2733 goto Failure;
2734
2735 switch (Controller->HardwareType)
2736 {
2737 case DAC960_GEM_Controller:
2738 Controller->PCI_Address = pci_resource_start(PCI_Device, 0);
2739 break;
2740 case DAC960_BA_Controller:
2741 Controller->PCI_Address = pci_resource_start(PCI_Device, 0);
2742 break;
2743 case DAC960_LP_Controller:
2744 Controller->PCI_Address = pci_resource_start(PCI_Device, 0);
2745 break;
2746 case DAC960_LA_Controller:
2747 Controller->PCI_Address = pci_resource_start(PCI_Device, 0);
2748 break;
2749 case DAC960_PG_Controller:
2750 Controller->PCI_Address = pci_resource_start(PCI_Device, 0);
2751 break;
2752 case DAC960_PD_Controller:
2753 Controller->IO_Address = pci_resource_start(PCI_Device, 0);
2754 Controller->PCI_Address = pci_resource_start(PCI_Device, 1);
2755 break;
2756 case DAC960_P_Controller:
2757 Controller->IO_Address = pci_resource_start(PCI_Device, 0);
2758 Controller->PCI_Address = pci_resource_start(PCI_Device, 1);
2759 break;
2760 }
2761
2762 pci_set_drvdata(PCI_Device, (void *)((long)Controller->ControllerNumber));
2763 for (i = 0; i < DAC960_MaxLogicalDrives; i++) {
2764 Controller->disks[i] = alloc_disk(1<<DAC960_MaxPartitionsBits);
2765 if (!Controller->disks[i])
2766 goto Failure;
2767 Controller->disks[i]->private_data = (void *)((long)i);
2768 }
2769 init_waitqueue_head(&Controller->CommandWaitQueue);
2770 init_waitqueue_head(&Controller->HealthStatusWaitQueue);
2771 spin_lock_init(&Controller->queue_lock);
2772 DAC960_AnnounceDriver(Controller);
2773
2774
2775
2776 if (MemoryWindowSize < PAGE_SIZE)
2777 MemoryWindowSize = PAGE_SIZE;
2778 Controller->MemoryMappedAddress =
2779 ioremap_nocache(Controller->PCI_Address & PAGE_MASK, MemoryWindowSize);
2780 Controller->BaseAddress =
2781 Controller->MemoryMappedAddress + (Controller->PCI_Address & ~PAGE_MASK);
2782 if (Controller->MemoryMappedAddress == NULL)
2783 {
2784 DAC960_Error("Unable to map Controller Register Window for "
2785 "Controller at\n", Controller);
2786 goto Failure;
2787 }
2788 BaseAddress = Controller->BaseAddress;
2789 switch (Controller->HardwareType)
2790 {
2791 case DAC960_GEM_Controller:
2792 DAC960_GEM_DisableInterrupts(BaseAddress);
2793 DAC960_GEM_AcknowledgeHardwareMailboxStatus(BaseAddress);
2794 udelay(1000);
2795 while (DAC960_GEM_InitializationInProgressP(BaseAddress))
2796 {
2797 if (DAC960_GEM_ReadErrorStatus(BaseAddress, &ErrorStatus,
2798 &Parameter0, &Parameter1) &&
2799 DAC960_ReportErrorStatus(Controller, ErrorStatus,
2800 Parameter0, Parameter1))
2801 goto Failure;
2802 udelay(10);
2803 }
2804 if (!DAC960_V2_EnableMemoryMailboxInterface(Controller))
2805 {
2806 DAC960_Error("Unable to Enable Memory Mailbox Interface "
2807 "for Controller at\n", Controller);
2808 goto Failure;
2809 }
2810 DAC960_GEM_EnableInterrupts(BaseAddress);
2811 Controller->QueueCommand = DAC960_GEM_QueueCommand;
2812 Controller->ReadControllerConfiguration =
2813 DAC960_V2_ReadControllerConfiguration;
2814 Controller->ReadDeviceConfiguration =
2815 DAC960_V2_ReadDeviceConfiguration;
2816 Controller->ReportDeviceConfiguration =
2817 DAC960_V2_ReportDeviceConfiguration;
2818 Controller->QueueReadWriteCommand =
2819 DAC960_V2_QueueReadWriteCommand;
2820 break;
2821 case DAC960_BA_Controller:
2822 DAC960_BA_DisableInterrupts(BaseAddress);
2823 DAC960_BA_AcknowledgeHardwareMailboxStatus(BaseAddress);
2824 udelay(1000);
2825 while (DAC960_BA_InitializationInProgressP(BaseAddress))
2826 {
2827 if (DAC960_BA_ReadErrorStatus(BaseAddress, &ErrorStatus,
2828 &Parameter0, &Parameter1) &&
2829 DAC960_ReportErrorStatus(Controller, ErrorStatus,
2830 Parameter0, Parameter1))
2831 goto Failure;
2832 udelay(10);
2833 }
2834 if (!DAC960_V2_EnableMemoryMailboxInterface(Controller))
2835 {
2836 DAC960_Error("Unable to Enable Memory Mailbox Interface "
2837 "for Controller at\n", Controller);
2838 goto Failure;
2839 }
2840 DAC960_BA_EnableInterrupts(BaseAddress);
2841 Controller->QueueCommand = DAC960_BA_QueueCommand;
2842 Controller->ReadControllerConfiguration =
2843 DAC960_V2_ReadControllerConfiguration;
2844 Controller->ReadDeviceConfiguration =
2845 DAC960_V2_ReadDeviceConfiguration;
2846 Controller->ReportDeviceConfiguration =
2847 DAC960_V2_ReportDeviceConfiguration;
2848 Controller->QueueReadWriteCommand =
2849 DAC960_V2_QueueReadWriteCommand;
2850 break;
2851 case DAC960_LP_Controller:
2852 DAC960_LP_DisableInterrupts(BaseAddress);
2853 DAC960_LP_AcknowledgeHardwareMailboxStatus(BaseAddress);
2854 udelay(1000);
2855 while (DAC960_LP_InitializationInProgressP(BaseAddress))
2856 {
2857 if (DAC960_LP_ReadErrorStatus(BaseAddress, &ErrorStatus,
2858 &Parameter0, &Parameter1) &&
2859 DAC960_ReportErrorStatus(Controller, ErrorStatus,
2860 Parameter0, Parameter1))
2861 goto Failure;
2862 udelay(10);
2863 }
2864 if (!DAC960_V2_EnableMemoryMailboxInterface(Controller))
2865 {
2866 DAC960_Error("Unable to Enable Memory Mailbox Interface "
2867 "for Controller at\n", Controller);
2868 goto Failure;
2869 }
2870 DAC960_LP_EnableInterrupts(BaseAddress);
2871 Controller->QueueCommand = DAC960_LP_QueueCommand;
2872 Controller->ReadControllerConfiguration =
2873 DAC960_V2_ReadControllerConfiguration;
2874 Controller->ReadDeviceConfiguration =
2875 DAC960_V2_ReadDeviceConfiguration;
2876 Controller->ReportDeviceConfiguration =
2877 DAC960_V2_ReportDeviceConfiguration;
2878 Controller->QueueReadWriteCommand =
2879 DAC960_V2_QueueReadWriteCommand;
2880 break;
2881 case DAC960_LA_Controller:
2882 DAC960_LA_DisableInterrupts(BaseAddress);
2883 DAC960_LA_AcknowledgeHardwareMailboxStatus(BaseAddress);
2884 udelay(1000);
2885 while (DAC960_LA_InitializationInProgressP(BaseAddress))
2886 {
2887 if (DAC960_LA_ReadErrorStatus(BaseAddress, &ErrorStatus,
2888 &Parameter0, &Parameter1) &&
2889 DAC960_ReportErrorStatus(Controller, ErrorStatus,
2890 Parameter0, Parameter1))
2891 goto Failure;
2892 udelay(10);
2893 }
2894 if (!DAC960_V1_EnableMemoryMailboxInterface(Controller))
2895 {
2896 DAC960_Error("Unable to Enable Memory Mailbox Interface "
2897 "for Controller at\n", Controller);
2898 goto Failure;
2899 }
2900 DAC960_LA_EnableInterrupts(BaseAddress);
2901 if (Controller->V1.DualModeMemoryMailboxInterface)
2902 Controller->QueueCommand = DAC960_LA_QueueCommandDualMode;
2903 else Controller->QueueCommand = DAC960_LA_QueueCommandSingleMode;
2904 Controller->ReadControllerConfiguration =
2905 DAC960_V1_ReadControllerConfiguration;
2906 Controller->ReadDeviceConfiguration =
2907 DAC960_V1_ReadDeviceConfiguration;
2908 Controller->ReportDeviceConfiguration =
2909 DAC960_V1_ReportDeviceConfiguration;
2910 Controller->QueueReadWriteCommand =
2911 DAC960_V1_QueueReadWriteCommand;
2912 break;
2913 case DAC960_PG_Controller:
2914 DAC960_PG_DisableInterrupts(BaseAddress);
2915 DAC960_PG_AcknowledgeHardwareMailboxStatus(BaseAddress);
2916 udelay(1000);
2917 while (DAC960_PG_InitializationInProgressP(BaseAddress))
2918 {
2919 if (DAC960_PG_ReadErrorStatus(BaseAddress, &ErrorStatus,
2920 &Parameter0, &Parameter1) &&
2921 DAC960_ReportErrorStatus(Controller, ErrorStatus,
2922 Parameter0, Parameter1))
2923 goto Failure;
2924 udelay(10);
2925 }
2926 if (!DAC960_V1_EnableMemoryMailboxInterface(Controller))
2927 {
2928 DAC960_Error("Unable to Enable Memory Mailbox Interface "
2929 "for Controller at\n", Controller);
2930 goto Failure;
2931 }
2932 DAC960_PG_EnableInterrupts(BaseAddress);
2933 if (Controller->V1.DualModeMemoryMailboxInterface)
2934 Controller->QueueCommand = DAC960_PG_QueueCommandDualMode;
2935 else Controller->QueueCommand = DAC960_PG_QueueCommandSingleMode;
2936 Controller->ReadControllerConfiguration =
2937 DAC960_V1_ReadControllerConfiguration;
2938 Controller->ReadDeviceConfiguration =
2939 DAC960_V1_ReadDeviceConfiguration;
2940 Controller->ReportDeviceConfiguration =
2941 DAC960_V1_ReportDeviceConfiguration;
2942 Controller->QueueReadWriteCommand =
2943 DAC960_V1_QueueReadWriteCommand;
2944 break;
2945 case DAC960_PD_Controller:
2946 if (!request_region(Controller->IO_Address, 0x80,
2947 Controller->FullModelName)) {
2948 DAC960_Error("IO port 0x%d busy for Controller at\n",
2949 Controller, Controller->IO_Address);
2950 goto Failure;
2951 }
2952 DAC960_PD_DisableInterrupts(BaseAddress);
2953 DAC960_PD_AcknowledgeStatus(BaseAddress);
2954 udelay(1000);
2955 while (DAC960_PD_InitializationInProgressP(BaseAddress))
2956 {
2957 if (DAC960_PD_ReadErrorStatus(BaseAddress, &ErrorStatus,
2958 &Parameter0, &Parameter1) &&
2959 DAC960_ReportErrorStatus(Controller, ErrorStatus,
2960 Parameter0, Parameter1))
2961 goto Failure;
2962 udelay(10);
2963 }
2964 if (!DAC960_V1_EnableMemoryMailboxInterface(Controller))
2965 {
2966 DAC960_Error("Unable to allocate DMA mapped memory "
2967 "for Controller at\n", Controller);
2968 goto Failure;
2969 }
2970 DAC960_PD_EnableInterrupts(BaseAddress);
2971 Controller->QueueCommand = DAC960_PD_QueueCommand;
2972 Controller->ReadControllerConfiguration =
2973 DAC960_V1_ReadControllerConfiguration;
2974 Controller->ReadDeviceConfiguration =
2975 DAC960_V1_ReadDeviceConfiguration;
2976 Controller->ReportDeviceConfiguration =
2977 DAC960_V1_ReportDeviceConfiguration;
2978 Controller->QueueReadWriteCommand =
2979 DAC960_V1_QueueReadWriteCommand;
2980 break;
2981 case DAC960_P_Controller:
2982 if (!request_region(Controller->IO_Address, 0x80,
2983 Controller->FullModelName)){
2984 DAC960_Error("IO port 0x%d busy for Controller at\n",
2985 Controller, Controller->IO_Address);
2986 goto Failure;
2987 }
2988 DAC960_PD_DisableInterrupts(BaseAddress);
2989 DAC960_PD_AcknowledgeStatus(BaseAddress);
2990 udelay(1000);
2991 while (DAC960_PD_InitializationInProgressP(BaseAddress))
2992 {
2993 if (DAC960_PD_ReadErrorStatus(BaseAddress, &ErrorStatus,
2994 &Parameter0, &Parameter1) &&
2995 DAC960_ReportErrorStatus(Controller, ErrorStatus,
2996 Parameter0, Parameter1))
2997 goto Failure;
2998 udelay(10);
2999 }
3000 if (!DAC960_V1_EnableMemoryMailboxInterface(Controller))
3001 {
3002 DAC960_Error("Unable to allocate DMA mapped memory"
3003 "for Controller at\n", Controller);
3004 goto Failure;
3005 }
3006 DAC960_PD_EnableInterrupts(BaseAddress);
3007 Controller->QueueCommand = DAC960_P_QueueCommand;
3008 Controller->ReadControllerConfiguration =
3009 DAC960_V1_ReadControllerConfiguration;
3010 Controller->ReadDeviceConfiguration =
3011 DAC960_V1_ReadDeviceConfiguration;
3012 Controller->ReportDeviceConfiguration =
3013 DAC960_V1_ReportDeviceConfiguration;
3014 Controller->QueueReadWriteCommand =
3015 DAC960_V1_QueueReadWriteCommand;
3016 break;
3017 }
3018
3019
3020
3021 IRQ_Channel = PCI_Device->irq;
3022 if (request_irq(IRQ_Channel, InterruptHandler, IRQF_SHARED,
3023 Controller->FullModelName, Controller) < 0)
3024 {
3025 DAC960_Error("Unable to acquire IRQ Channel %d for Controller at\n",
3026 Controller, Controller->IRQ_Channel);
3027 goto Failure;
3028 }
3029 Controller->IRQ_Channel = IRQ_Channel;
3030 Controller->InitialCommand.CommandIdentifier = 1;
3031 Controller->InitialCommand.Controller = Controller;
3032 Controller->Commands[0] = &Controller->InitialCommand;
3033 Controller->FreeCommands = &Controller->InitialCommand;
3034 return Controller;
3035
3036Failure:
3037 if (Controller->IO_Address == 0)
3038 DAC960_Error("PCI Bus %d Device %d Function %d I/O Address N/A "
3039 "PCI Address 0x%X\n", Controller,
3040 Controller->Bus, Controller->Device,
3041 Controller->Function, Controller->PCI_Address);
3042 else
3043 DAC960_Error("PCI Bus %d Device %d Function %d I/O Address "
3044 "0x%X PCI Address 0x%X\n", Controller,
3045 Controller->Bus, Controller->Device,
3046 Controller->Function, Controller->IO_Address,
3047 Controller->PCI_Address);
3048 DAC960_DetectCleanup(Controller);
3049 DAC960_ControllerCount--;
3050 return NULL;
3051}
3052
3053
3054
3055
3056
3057static bool
3058DAC960_InitializeController(DAC960_Controller_T *Controller)
3059{
3060 if (DAC960_ReadControllerConfiguration(Controller) &&
3061 DAC960_ReportControllerConfiguration(Controller) &&
3062 DAC960_CreateAuxiliaryStructures(Controller) &&
3063 DAC960_ReadDeviceConfiguration(Controller) &&
3064 DAC960_ReportDeviceConfiguration(Controller) &&
3065 DAC960_RegisterBlockDevice(Controller))
3066 {
3067
3068
3069
3070 init_timer(&Controller->MonitoringTimer);
3071 Controller->MonitoringTimer.expires =
3072 jiffies + DAC960_MonitoringTimerInterval;
3073 Controller->MonitoringTimer.data = (unsigned long) Controller;
3074 Controller->MonitoringTimer.function = DAC960_MonitoringTimerFunction;
3075 add_timer(&Controller->MonitoringTimer);
3076 Controller->ControllerInitialized = true;
3077 return true;
3078 }
3079 return false;
3080}
3081
3082
3083
3084
3085
3086
3087static void DAC960_FinalizeController(DAC960_Controller_T *Controller)
3088{
3089 if (Controller->ControllerInitialized)
3090 {
3091 unsigned long flags;
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110 spin_lock_irqsave(&Controller->queue_lock, flags);
3111 Controller->ShutdownMonitoringTimer = 1;
3112 spin_unlock_irqrestore(&Controller->queue_lock, flags);
3113
3114 del_timer_sync(&Controller->MonitoringTimer);
3115 if (Controller->FirmwareType == DAC960_V1_Controller)
3116 {
3117 DAC960_Notice("Flushing Cache...", Controller);
3118 DAC960_V1_ExecuteType3(Controller, DAC960_V1_Flush, 0);
3119 DAC960_Notice("done\n", Controller);
3120
3121 if (Controller->HardwareType == DAC960_PD_Controller)
3122 release_region(Controller->IO_Address, 0x80);
3123 }
3124 else
3125 {
3126 DAC960_Notice("Flushing Cache...", Controller);
3127 DAC960_V2_DeviceOperation(Controller, DAC960_V2_PauseDevice,
3128 DAC960_V2_RAID_Controller);
3129 DAC960_Notice("done\n", Controller);
3130 }
3131 }
3132 DAC960_UnregisterBlockDevice(Controller);
3133 DAC960_DestroyAuxiliaryStructures(Controller);
3134 DAC960_DestroyProcEntries(Controller);
3135 DAC960_DetectCleanup(Controller);
3136}
3137
3138
3139
3140
3141
3142
3143
3144static int
3145DAC960_Probe(struct pci_dev *dev, const struct pci_device_id *entry)
3146{
3147 int disk;
3148 DAC960_Controller_T *Controller;
3149
3150 if (DAC960_ControllerCount == DAC960_MaxControllers)
3151 {
3152 DAC960_Error("More than %d DAC960 Controllers detected - "
3153 "ignoring from Controller at\n",
3154 NULL, DAC960_MaxControllers);
3155 return -ENODEV;
3156 }
3157
3158 Controller = DAC960_DetectController(dev, entry);
3159 if (!Controller)
3160 return -ENODEV;
3161
3162 if (!DAC960_InitializeController(Controller)) {
3163 DAC960_FinalizeController(Controller);
3164 return -ENODEV;
3165 }
3166
3167 for (disk = 0; disk < DAC960_MaxLogicalDrives; disk++) {
3168 set_capacity(Controller->disks[disk], disk_size(Controller, disk));
3169 add_disk(Controller->disks[disk]);
3170 }
3171 DAC960_CreateProcEntries(Controller);
3172 return 0;
3173}
3174
3175
3176
3177
3178
3179
3180static void DAC960_Remove(struct pci_dev *PCI_Device)
3181{
3182 int Controller_Number = (long)pci_get_drvdata(PCI_Device);
3183 DAC960_Controller_T *Controller = DAC960_Controllers[Controller_Number];
3184 if (Controller != NULL)
3185 DAC960_FinalizeController(Controller);
3186}
3187
3188
3189
3190
3191
3192
3193
3194static void DAC960_V1_QueueReadWriteCommand(DAC960_Command_T *Command)
3195{
3196 DAC960_Controller_T *Controller = Command->Controller;
3197 DAC960_V1_CommandMailbox_T *CommandMailbox = &Command->V1.CommandMailbox;
3198 DAC960_V1_ScatterGatherSegment_T *ScatterGatherList =
3199 Command->V1.ScatterGatherList;
3200 struct scatterlist *ScatterList = Command->V1.ScatterList;
3201
3202 DAC960_V1_ClearCommand(Command);
3203
3204 if (Command->SegmentCount == 1)
3205 {
3206 if (Command->DmaDirection == PCI_DMA_FROMDEVICE)
3207 CommandMailbox->Type5.CommandOpcode = DAC960_V1_Read;
3208 else
3209 CommandMailbox->Type5.CommandOpcode = DAC960_V1_Write;
3210
3211 CommandMailbox->Type5.LD.TransferLength = Command->BlockCount;
3212 CommandMailbox->Type5.LD.LogicalDriveNumber = Command->LogicalDriveNumber;
3213 CommandMailbox->Type5.LogicalBlockAddress = Command->BlockNumber;
3214 CommandMailbox->Type5.BusAddress =
3215 (DAC960_BusAddress32_T)sg_dma_address(ScatterList);
3216 }
3217 else
3218 {
3219 int i;
3220
3221 if (Command->DmaDirection == PCI_DMA_FROMDEVICE)
3222 CommandMailbox->Type5.CommandOpcode = DAC960_V1_ReadWithScatterGather;
3223 else
3224 CommandMailbox->Type5.CommandOpcode = DAC960_V1_WriteWithScatterGather;
3225
3226 CommandMailbox->Type5.LD.TransferLength = Command->BlockCount;
3227 CommandMailbox->Type5.LD.LogicalDriveNumber = Command->LogicalDriveNumber;
3228 CommandMailbox->Type5.LogicalBlockAddress = Command->BlockNumber;
3229 CommandMailbox->Type5.BusAddress = Command->V1.ScatterGatherListDMA;
3230
3231 CommandMailbox->Type5.ScatterGatherCount = Command->SegmentCount;
3232
3233 for (i = 0; i < Command->SegmentCount; i++, ScatterList++, ScatterGatherList++) {
3234 ScatterGatherList->SegmentDataPointer =
3235 (DAC960_BusAddress32_T)sg_dma_address(ScatterList);
3236 ScatterGatherList->SegmentByteCount =
3237 (DAC960_ByteCount32_T)sg_dma_len(ScatterList);
3238 }
3239 }
3240 DAC960_QueueCommand(Command);
3241}
3242
3243
3244
3245
3246
3247
3248
3249static void DAC960_V2_QueueReadWriteCommand(DAC960_Command_T *Command)
3250{
3251 DAC960_Controller_T *Controller = Command->Controller;
3252 DAC960_V2_CommandMailbox_T *CommandMailbox = &Command->V2.CommandMailbox;
3253 struct scatterlist *ScatterList = Command->V2.ScatterList;
3254
3255 DAC960_V2_ClearCommand(Command);
3256
3257 CommandMailbox->SCSI_10.CommandOpcode = DAC960_V2_SCSI_10;
3258 CommandMailbox->SCSI_10.CommandControlBits.DataTransferControllerToHost =
3259 (Command->DmaDirection == PCI_DMA_FROMDEVICE);
3260 CommandMailbox->SCSI_10.DataTransferSize =
3261 Command->BlockCount << DAC960_BlockSizeBits;
3262 CommandMailbox->SCSI_10.RequestSenseBusAddress = Command->V2.RequestSenseDMA;
3263 CommandMailbox->SCSI_10.PhysicalDevice =
3264 Controller->V2.LogicalDriveToVirtualDevice[Command->LogicalDriveNumber];
3265 CommandMailbox->SCSI_10.RequestSenseSize = sizeof(DAC960_SCSI_RequestSense_T);
3266 CommandMailbox->SCSI_10.CDBLength = 10;
3267 CommandMailbox->SCSI_10.SCSI_CDB[0] =
3268 (Command->DmaDirection == PCI_DMA_FROMDEVICE ? 0x28 : 0x2A);
3269 CommandMailbox->SCSI_10.SCSI_CDB[2] = Command->BlockNumber >> 24;
3270 CommandMailbox->SCSI_10.SCSI_CDB[3] = Command->BlockNumber >> 16;
3271 CommandMailbox->SCSI_10.SCSI_CDB[4] = Command->BlockNumber >> 8;
3272 CommandMailbox->SCSI_10.SCSI_CDB[5] = Command->BlockNumber;
3273 CommandMailbox->SCSI_10.SCSI_CDB[7] = Command->BlockCount >> 8;
3274 CommandMailbox->SCSI_10.SCSI_CDB[8] = Command->BlockCount;
3275
3276 if (Command->SegmentCount == 1)
3277 {
3278 CommandMailbox->SCSI_10.DataTransferMemoryAddress
3279 .ScatterGatherSegments[0]
3280 .SegmentDataPointer =
3281 (DAC960_BusAddress64_T)sg_dma_address(ScatterList);
3282 CommandMailbox->SCSI_10.DataTransferMemoryAddress
3283 .ScatterGatherSegments[0]
3284 .SegmentByteCount =
3285 CommandMailbox->SCSI_10.DataTransferSize;
3286 }
3287 else
3288 {
3289 DAC960_V2_ScatterGatherSegment_T *ScatterGatherList;
3290 int i;
3291
3292 if (Command->SegmentCount > 2)
3293 {
3294 ScatterGatherList = Command->V2.ScatterGatherList;
3295 CommandMailbox->SCSI_10.CommandControlBits
3296 .AdditionalScatterGatherListMemory = true;
3297 CommandMailbox->SCSI_10.DataTransferMemoryAddress
3298 .ExtendedScatterGather.ScatterGatherList0Length = Command->SegmentCount;
3299 CommandMailbox->SCSI_10.DataTransferMemoryAddress
3300 .ExtendedScatterGather.ScatterGatherList0Address =
3301 Command->V2.ScatterGatherListDMA;
3302 }
3303 else
3304 ScatterGatherList = CommandMailbox->SCSI_10.DataTransferMemoryAddress
3305 .ScatterGatherSegments;
3306
3307 for (i = 0; i < Command->SegmentCount; i++, ScatterList++, ScatterGatherList++) {
3308 ScatterGatherList->SegmentDataPointer =
3309 (DAC960_BusAddress64_T)sg_dma_address(ScatterList);
3310 ScatterGatherList->SegmentByteCount =
3311 (DAC960_ByteCount64_T)sg_dma_len(ScatterList);
3312 }
3313 }
3314 DAC960_QueueCommand(Command);
3315}
3316
3317
3318static int DAC960_process_queue(DAC960_Controller_T *Controller, struct request_queue *req_q)
3319{
3320 struct request *Request;
3321 DAC960_Command_T *Command;
3322
3323 while(1) {
3324 Request = elv_next_request(req_q);
3325 if (!Request)
3326 return 1;
3327
3328 Command = DAC960_AllocateCommand(Controller);
3329 if (Command == NULL)
3330 return 0;
3331
3332 if (rq_data_dir(Request) == READ) {
3333 Command->DmaDirection = PCI_DMA_FROMDEVICE;
3334 Command->CommandType = DAC960_ReadCommand;
3335 } else {
3336 Command->DmaDirection = PCI_DMA_TODEVICE;
3337 Command->CommandType = DAC960_WriteCommand;
3338 }
3339 Command->Completion = Request->end_io_data;
3340 Command->LogicalDriveNumber = (long)Request->rq_disk->private_data;
3341 Command->BlockNumber = Request->sector;
3342 Command->BlockCount = Request->nr_sectors;
3343 Command->Request = Request;
3344 blkdev_dequeue_request(Request);
3345 Command->SegmentCount = blk_rq_map_sg(req_q,
3346 Command->Request, Command->cmd_sglist);
3347
3348 Command->SegmentCount = pci_map_sg(Controller->PCIDevice, Command->cmd_sglist,
3349 Command->SegmentCount, Command->DmaDirection);
3350
3351 DAC960_QueueReadWriteCommand(Command);
3352 }
3353}
3354
3355
3356
3357
3358
3359
3360
3361static void DAC960_ProcessRequest(DAC960_Controller_T *controller)
3362{
3363 int i;
3364
3365 if (!controller->ControllerInitialized)
3366 return;
3367
3368
3369 for (i = controller->req_q_index; i < DAC960_MaxLogicalDrives; i++) {
3370 struct request_queue *req_q = controller->RequestQueue[i];
3371
3372 if (req_q == NULL)
3373 continue;
3374
3375 if (!DAC960_process_queue(controller, req_q)) {
3376 controller->req_q_index = i;
3377 return;
3378 }
3379 }
3380
3381 if (controller->req_q_index == 0)
3382 return;
3383
3384 for (i = 0; i < controller->req_q_index; i++) {
3385 struct request_queue *req_q = controller->RequestQueue[i];
3386
3387 if (req_q == NULL)
3388 continue;
3389
3390 if (!DAC960_process_queue(controller, req_q)) {
3391 controller->req_q_index = i;
3392 return;
3393 }
3394 }
3395}
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407static void DAC960_queue_partial_rw(DAC960_Command_T *Command)
3408{
3409 DAC960_Controller_T *Controller = Command->Controller;
3410 struct request *Request = Command->Request;
3411 struct request_queue *req_q = Controller->RequestQueue[Command->LogicalDriveNumber];
3412
3413 if (Command->DmaDirection == PCI_DMA_FROMDEVICE)
3414 Command->CommandType = DAC960_ReadRetryCommand;
3415 else
3416 Command->CommandType = DAC960_WriteRetryCommand;
3417
3418
3419
3420
3421
3422
3423
3424 (void)blk_rq_map_sg(req_q, Command->Request, Command->cmd_sglist);
3425
3426 (void)pci_map_sg(Controller->PCIDevice, Command->cmd_sglist, 1, Command->DmaDirection);
3427
3428
3429
3430
3431
3432
3433 Command->SegmentCount = 1;
3434 Command->BlockNumber = Request->sector;
3435 Command->BlockCount = 1;
3436 DAC960_QueueReadWriteCommand(Command);
3437 return;
3438}
3439
3440
3441
3442
3443
3444static void DAC960_RequestFunction(struct request_queue *RequestQueue)
3445{
3446 DAC960_ProcessRequest(RequestQueue->queuedata);
3447}
3448
3449
3450
3451
3452
3453
3454static inline bool DAC960_ProcessCompletedRequest(DAC960_Command_T *Command,
3455 bool SuccessfulIO)
3456{
3457 struct request *Request = Command->Request;
3458 int Error = SuccessfulIO ? 0 : -EIO;
3459
3460 pci_unmap_sg(Command->Controller->PCIDevice, Command->cmd_sglist,
3461 Command->SegmentCount, Command->DmaDirection);
3462
3463 if (!__blk_end_request(Request, Error, Command->BlockCount << 9)) {
3464 if (Command->Completion) {
3465 complete(Command->Completion);
3466 Command->Completion = NULL;
3467 }
3468 return true;
3469 }
3470 return false;
3471}
3472
3473
3474
3475
3476
3477
3478static void DAC960_V1_ReadWriteError(DAC960_Command_T *Command)
3479{
3480 DAC960_Controller_T *Controller = Command->Controller;
3481 unsigned char *CommandName = "UNKNOWN";
3482 switch (Command->CommandType)
3483 {
3484 case DAC960_ReadCommand:
3485 case DAC960_ReadRetryCommand:
3486 CommandName = "READ";
3487 break;
3488 case DAC960_WriteCommand:
3489 case DAC960_WriteRetryCommand:
3490 CommandName = "WRITE";
3491 break;
3492 case DAC960_MonitoringCommand:
3493 case DAC960_ImmediateCommand:
3494 case DAC960_QueuedCommand:
3495 break;
3496 }
3497 switch (Command->V1.CommandStatus)
3498 {
3499 case DAC960_V1_IrrecoverableDataError:
3500 DAC960_Error("Irrecoverable Data Error on %s:\n",
3501 Controller, CommandName);
3502 break;
3503 case DAC960_V1_LogicalDriveNonexistentOrOffline:
3504 DAC960_Error("Logical Drive Nonexistent or Offline on %s:\n",
3505 Controller, CommandName);
3506 break;
3507 case DAC960_V1_AccessBeyondEndOfLogicalDrive:
3508 DAC960_Error("Attempt to Access Beyond End of Logical Drive "
3509 "on %s:\n", Controller, CommandName);
3510 break;
3511 case DAC960_V1_BadDataEncountered:
3512 DAC960_Error("Bad Data Encountered on %s:\n", Controller, CommandName);
3513 break;
3514 default:
3515 DAC960_Error("Unexpected Error Status %04X on %s:\n",
3516 Controller, Command->V1.CommandStatus, CommandName);
3517 break;
3518 }
3519 DAC960_Error(" /dev/rd/c%dd%d: absolute blocks %u..%u\n",
3520 Controller, Controller->ControllerNumber,
3521 Command->LogicalDriveNumber, Command->BlockNumber,
3522 Command->BlockNumber + Command->BlockCount - 1);
3523}
3524
3525
3526
3527
3528
3529
3530
3531static void DAC960_V1_ProcessCompletedCommand(DAC960_Command_T *Command)
3532{
3533 DAC960_Controller_T *Controller = Command->Controller;
3534 DAC960_CommandType_T CommandType = Command->CommandType;
3535 DAC960_V1_CommandOpcode_T CommandOpcode =
3536 Command->V1.CommandMailbox.Common.CommandOpcode;
3537 DAC960_V1_CommandStatus_T CommandStatus = Command->V1.CommandStatus;
3538
3539 if (CommandType == DAC960_ReadCommand ||
3540 CommandType == DAC960_WriteCommand)
3541 {
3542
3543#ifdef FORCE_RETRY_DEBUG
3544 CommandStatus = DAC960_V1_IrrecoverableDataError;
3545#endif
3546
3547 if (CommandStatus == DAC960_V1_NormalCompletion) {
3548
3549 if (!DAC960_ProcessCompletedRequest(Command, true))
3550 BUG();
3551
3552 } else if (CommandStatus == DAC960_V1_IrrecoverableDataError ||
3553 CommandStatus == DAC960_V1_BadDataEncountered)
3554 {
3555
3556
3557
3558
3559 DAC960_queue_partial_rw(Command);
3560 return;
3561 }
3562 else
3563 {
3564 if (CommandStatus != DAC960_V1_LogicalDriveNonexistentOrOffline)
3565 DAC960_V1_ReadWriteError(Command);
3566
3567 if (!DAC960_ProcessCompletedRequest(Command, false))
3568 BUG();
3569 }
3570 }
3571 else if (CommandType == DAC960_ReadRetryCommand ||
3572 CommandType == DAC960_WriteRetryCommand)
3573 {
3574 bool normal_completion;
3575#ifdef FORCE_RETRY_FAILURE_DEBUG
3576 static int retry_count = 1;
3577#endif
3578
3579
3580
3581
3582 normal_completion = true;
3583 if (CommandStatus != DAC960_V1_NormalCompletion) {
3584 normal_completion = false;
3585 if (CommandStatus != DAC960_V1_LogicalDriveNonexistentOrOffline)
3586 DAC960_V1_ReadWriteError(Command);
3587 }
3588
3589#ifdef FORCE_RETRY_FAILURE_DEBUG
3590 if (!(++retry_count % 10000)) {
3591 printk("V1 error retry failure test\n");
3592 normal_completion = false;
3593 DAC960_V1_ReadWriteError(Command);
3594 }
3595#endif
3596
3597 if (!DAC960_ProcessCompletedRequest(Command, normal_completion)) {
3598 DAC960_queue_partial_rw(Command);
3599 return;
3600 }
3601 }
3602
3603 else if (CommandType == DAC960_MonitoringCommand)
3604 {
3605 if (Controller->ShutdownMonitoringTimer)
3606 return;
3607 if (CommandOpcode == DAC960_V1_Enquiry)
3608 {
3609 DAC960_V1_Enquiry_T *OldEnquiry = &Controller->V1.Enquiry;
3610 DAC960_V1_Enquiry_T *NewEnquiry = Controller->V1.NewEnquiry;
3611 unsigned int OldCriticalLogicalDriveCount =
3612 OldEnquiry->CriticalLogicalDriveCount;
3613 unsigned int NewCriticalLogicalDriveCount =
3614 NewEnquiry->CriticalLogicalDriveCount;
3615 if (NewEnquiry->NumberOfLogicalDrives > Controller->LogicalDriveCount)
3616 {
3617 int LogicalDriveNumber = Controller->LogicalDriveCount - 1;
3618 while (++LogicalDriveNumber < NewEnquiry->NumberOfLogicalDrives)
3619 DAC960_Critical("Logical Drive %d (/dev/rd/c%dd%d) "
3620 "Now Exists\n", Controller,
3621 LogicalDriveNumber,
3622 Controller->ControllerNumber,
3623 LogicalDriveNumber);
3624 Controller->LogicalDriveCount = NewEnquiry->NumberOfLogicalDrives;
3625 DAC960_ComputeGenericDiskInfo(Controller);
3626 }
3627 if (NewEnquiry->NumberOfLogicalDrives < Controller->LogicalDriveCount)
3628 {
3629 int LogicalDriveNumber = NewEnquiry->NumberOfLogicalDrives - 1;
3630 while (++LogicalDriveNumber < Controller->LogicalDriveCount)
3631 DAC960_Critical("Logical Drive %d (/dev/rd/c%dd%d) "
3632 "No Longer Exists\n", Controller,
3633 LogicalDriveNumber,
3634 Controller->ControllerNumber,
3635 LogicalDriveNumber);
3636 Controller->LogicalDriveCount = NewEnquiry->NumberOfLogicalDrives;
3637 DAC960_ComputeGenericDiskInfo(Controller);
3638 }
3639 if (NewEnquiry->StatusFlags.DeferredWriteError !=
3640 OldEnquiry->StatusFlags.DeferredWriteError)
3641 DAC960_Critical("Deferred Write Error Flag is now %s\n", Controller,
3642 (NewEnquiry->StatusFlags.DeferredWriteError
3643 ? "TRUE" : "FALSE"));
3644 if ((NewCriticalLogicalDriveCount > 0 ||
3645 NewCriticalLogicalDriveCount != OldCriticalLogicalDriveCount) ||
3646 (NewEnquiry->OfflineLogicalDriveCount > 0 ||
3647 NewEnquiry->OfflineLogicalDriveCount !=
3648 OldEnquiry->OfflineLogicalDriveCount) ||
3649 (NewEnquiry->DeadDriveCount > 0 ||
3650 NewEnquiry->DeadDriveCount !=
3651 OldEnquiry->DeadDriveCount) ||
3652 (NewEnquiry->EventLogSequenceNumber !=
3653 OldEnquiry->EventLogSequenceNumber) ||
3654 Controller->MonitoringTimerCount == 0 ||
3655 time_after_eq(jiffies, Controller->SecondaryMonitoringTime
3656 + DAC960_SecondaryMonitoringInterval))
3657 {
3658 Controller->V1.NeedLogicalDriveInformation = true;
3659 Controller->V1.NewEventLogSequenceNumber =
3660 NewEnquiry->EventLogSequenceNumber;
3661 Controller->V1.NeedErrorTableInformation = true;
3662 Controller->V1.NeedDeviceStateInformation = true;
3663 Controller->V1.StartDeviceStateScan = true;
3664 Controller->V1.NeedBackgroundInitializationStatus =
3665 Controller->V1.BackgroundInitializationStatusSupported;
3666 Controller->SecondaryMonitoringTime = jiffies;
3667 }
3668 if (NewEnquiry->RebuildFlag == DAC960_V1_StandbyRebuildInProgress ||
3669 NewEnquiry->RebuildFlag
3670 == DAC960_V1_BackgroundRebuildInProgress ||
3671 OldEnquiry->RebuildFlag == DAC960_V1_StandbyRebuildInProgress ||
3672 OldEnquiry->RebuildFlag == DAC960_V1_BackgroundRebuildInProgress)
3673 {
3674 Controller->V1.NeedRebuildProgress = true;
3675 Controller->V1.RebuildProgressFirst =
3676 (NewEnquiry->CriticalLogicalDriveCount <
3677 OldEnquiry->CriticalLogicalDriveCount);
3678 }
3679 if (OldEnquiry->RebuildFlag == DAC960_V1_BackgroundCheckInProgress)
3680 switch (NewEnquiry->RebuildFlag)
3681 {
3682 case DAC960_V1_NoStandbyRebuildOrCheckInProgress:
3683 DAC960_Progress("Consistency Check Completed Successfully\n",
3684 Controller);
3685 break;
3686 case DAC960_V1_StandbyRebuildInProgress:
3687 case DAC960_V1_BackgroundRebuildInProgress:
3688 break;
3689 case DAC960_V1_BackgroundCheckInProgress:
3690 Controller->V1.NeedConsistencyCheckProgress = true;
3691 break;
3692 case DAC960_V1_StandbyRebuildCompletedWithError:
3693 DAC960_Progress("Consistency Check Completed with Error\n",
3694 Controller);
3695 break;
3696 case DAC960_V1_BackgroundRebuildOrCheckFailed_DriveFailed:
3697 DAC960_Progress("Consistency Check Failed - "
3698 "Physical Device Failed\n", Controller);
3699 break;
3700 case DAC960_V1_BackgroundRebuildOrCheckFailed_LogicalDriveFailed:
3701 DAC960_Progress("Consistency Check Failed - "
3702 "Logical Drive Failed\n", Controller);
3703 break;
3704 case DAC960_V1_BackgroundRebuildOrCheckFailed_OtherCauses:
3705 DAC960_Progress("Consistency Check Failed - Other Causes\n",
3706 Controller);
3707 break;
3708 case DAC960_V1_BackgroundRebuildOrCheckSuccessfullyTerminated:
3709 DAC960_Progress("Consistency Check Successfully Terminated\n",
3710 Controller);
3711 break;
3712 }
3713 else if (NewEnquiry->RebuildFlag
3714 == DAC960_V1_BackgroundCheckInProgress)
3715 Controller->V1.NeedConsistencyCheckProgress = true;
3716 Controller->MonitoringAlertMode =
3717 (NewEnquiry->CriticalLogicalDriveCount > 0 ||
3718 NewEnquiry->OfflineLogicalDriveCount > 0 ||
3719 NewEnquiry->DeadDriveCount > 0);
3720 if (NewEnquiry->RebuildFlag > DAC960_V1_BackgroundCheckInProgress)
3721 {
3722 Controller->V1.PendingRebuildFlag = NewEnquiry->RebuildFlag;
3723 Controller->V1.RebuildFlagPending = true;
3724 }
3725 memcpy(&Controller->V1.Enquiry, &Controller->V1.NewEnquiry,
3726 sizeof(DAC960_V1_Enquiry_T));
3727 }
3728 else if (CommandOpcode == DAC960_V1_PerformEventLogOperation)
3729 {
3730 static char
3731 *DAC960_EventMessages[] =
3732 { "killed because write recovery failed",
3733 "killed because of SCSI bus reset failure",
3734 "killed because of double check condition",
3735 "killed because it was removed",
3736 "killed because of gross error on SCSI chip",
3737 "killed because of bad tag returned from drive",
3738 "killed because of timeout on SCSI command",
3739 "killed because of reset SCSI command issued from system",
3740 "killed because busy or parity error count exceeded limit",
3741 "killed because of 'kill drive' command from system",
3742 "killed because of selection timeout",
3743 "killed due to SCSI phase sequence error",
3744 "killed due to unknown status" };
3745 DAC960_V1_EventLogEntry_T *EventLogEntry =
3746 Controller->V1.EventLogEntry;
3747 if (EventLogEntry->SequenceNumber ==
3748 Controller->V1.OldEventLogSequenceNumber)
3749 {
3750 unsigned char SenseKey = EventLogEntry->SenseKey;
3751 unsigned char AdditionalSenseCode =
3752 EventLogEntry->AdditionalSenseCode;
3753 unsigned char AdditionalSenseCodeQualifier =
3754 EventLogEntry->AdditionalSenseCodeQualifier;
3755 if (SenseKey == DAC960_SenseKey_VendorSpecific &&
3756 AdditionalSenseCode == 0x80 &&
3757 AdditionalSenseCodeQualifier <
3758 ARRAY_SIZE(DAC960_EventMessages))
3759 DAC960_Critical("Physical Device %d:%d %s\n", Controller,
3760 EventLogEntry->Channel,
3761 EventLogEntry->TargetID,
3762 DAC960_EventMessages[
3763 AdditionalSenseCodeQualifier]);
3764 else if (SenseKey == DAC960_SenseKey_UnitAttention &&
3765 AdditionalSenseCode == 0x29)
3766 {
3767 if (Controller->MonitoringTimerCount > 0)
3768 Controller->V1.DeviceResetCount[EventLogEntry->Channel]
3769 [EventLogEntry->TargetID]++;
3770 }
3771 else if (!(SenseKey == DAC960_SenseKey_NoSense ||
3772 (SenseKey == DAC960_SenseKey_NotReady &&
3773 AdditionalSenseCode == 0x04 &&
3774 (AdditionalSenseCodeQualifier == 0x01 ||
3775 AdditionalSenseCodeQualifier == 0x02))))
3776 {
3777 DAC960_Critical("Physical Device %d:%d Error Log: "
3778 "Sense Key = %X, ASC = %02X, ASCQ = %02X\n",
3779 Controller,
3780 EventLogEntry->Channel,
3781 EventLogEntry->TargetID,
3782 SenseKey,
3783 AdditionalSenseCode,
3784 AdditionalSenseCodeQualifier);
3785 DAC960_Critical("Physical Device %d:%d Error Log: "
3786 "Information = %02X%02X%02X%02X "
3787 "%02X%02X%02X%02X\n",
3788 Controller,
3789 EventLogEntry->Channel,
3790 EventLogEntry->TargetID,
3791 EventLogEntry->Information[0],
3792 EventLogEntry->Information[1],
3793 EventLogEntry->Information[2],
3794 EventLogEntry->Information[3],
3795 EventLogEntry->CommandSpecificInformation[0],
3796 EventLogEntry->CommandSpecificInformation[1],
3797 EventLogEntry->CommandSpecificInformation[2],
3798 EventLogEntry->CommandSpecificInformation[3]);
3799 }
3800 }
3801 Controller->V1.OldEventLogSequenceNumber++;
3802 }
3803 else if (CommandOpcode == DAC960_V1_GetErrorTable)
3804 {
3805 DAC960_V1_ErrorTable_T *OldErrorTable = &Controller->V1.ErrorTable;
3806 DAC960_V1_ErrorTable_T *NewErrorTable = Controller->V1.NewErrorTable;
3807 int Channel, TargetID;
3808 for (Channel = 0; Channel < Controller->Channels; Channel++)
3809 for (TargetID = 0; TargetID < Controller->Targets; TargetID++)
3810 {
3811 DAC960_V1_ErrorTableEntry_T *NewErrorEntry =
3812 &NewErrorTable->ErrorTableEntries[Channel][TargetID];
3813 DAC960_V1_ErrorTableEntry_T *OldErrorEntry =
3814 &OldErrorTable->ErrorTableEntries[Channel][TargetID];
3815 if ((NewErrorEntry->ParityErrorCount !=
3816 OldErrorEntry->ParityErrorCount) ||
3817 (NewErrorEntry->SoftErrorCount !=
3818 OldErrorEntry->SoftErrorCount) ||
3819 (NewErrorEntry->HardErrorCount !=
3820 OldErrorEntry->HardErrorCount) ||
3821 (NewErrorEntry->MiscErrorCount !=
3822 OldErrorEntry->MiscErrorCount))
3823 DAC960_Critical("Physical Device %d:%d Errors: "
3824 "Parity = %d, Soft = %d, "
3825 "Hard = %d, Misc = %d\n",
3826 Controller, Channel, TargetID,
3827 NewErrorEntry->ParityErrorCount,
3828 NewErrorEntry->SoftErrorCount,
3829 NewErrorEntry->HardErrorCount,
3830 NewErrorEntry->MiscErrorCount);
3831 }
3832 memcpy(&Controller->V1.ErrorTable, Controller->V1.NewErrorTable,
3833 sizeof(DAC960_V1_ErrorTable_T));
3834 }
3835 else if (CommandOpcode == DAC960_V1_GetDeviceState)
3836 {
3837 DAC960_V1_DeviceState_T *OldDeviceState =
3838 &Controller->V1.DeviceState[Controller->V1.DeviceStateChannel]
3839 [Controller->V1.DeviceStateTargetID];
3840 DAC960_V1_DeviceState_T *NewDeviceState =
3841 Controller->V1.NewDeviceState;
3842 if (NewDeviceState->DeviceState != OldDeviceState->DeviceState)
3843 DAC960_Critical("Physical Device %d:%d is now %s\n", Controller,
3844 Controller->V1.DeviceStateChannel,
3845 Controller->V1.DeviceStateTargetID,
3846 (NewDeviceState->DeviceState
3847 == DAC960_V1_Device_Dead
3848 ? "DEAD"
3849 : NewDeviceState->DeviceState
3850 == DAC960_V1_Device_WriteOnly
3851 ? "WRITE-ONLY"
3852 : NewDeviceState->DeviceState
3853 == DAC960_V1_Device_Online
3854 ? "ONLINE" : "STANDBY"));
3855 if (OldDeviceState->DeviceState == DAC960_V1_Device_Dead &&
3856 NewDeviceState->DeviceState != DAC960_V1_Device_Dead)
3857 {
3858 Controller->V1.NeedDeviceInquiryInformation = true;
3859 Controller->V1.NeedDeviceSerialNumberInformation = true;
3860 Controller->V1.DeviceResetCount
3861 [Controller->V1.DeviceStateChannel]
3862 [Controller->V1.DeviceStateTargetID] = 0;
3863 }
3864 memcpy(OldDeviceState, NewDeviceState,
3865 sizeof(DAC960_V1_DeviceState_T));
3866 }
3867 else if (CommandOpcode == DAC960_V1_GetLogicalDriveInformation)
3868 {
3869 int LogicalDriveNumber;
3870 for (LogicalDriveNumber = 0;
3871 LogicalDriveNumber < Controller->LogicalDriveCount;
3872 LogicalDriveNumber++)
3873 {
3874 DAC960_V1_LogicalDriveInformation_T *OldLogicalDriveInformation =
3875 &Controller->V1.LogicalDriveInformation[LogicalDriveNumber];
3876 DAC960_V1_LogicalDriveInformation_T *NewLogicalDriveInformation =
3877 &(*Controller->V1.NewLogicalDriveInformation)[LogicalDriveNumber];
3878 if (NewLogicalDriveInformation->LogicalDriveState !=
3879 OldLogicalDriveInformation->LogicalDriveState)
3880 DAC960_Critical("Logical Drive %d (/dev/rd/c%dd%d) "
3881 "is now %s\n", Controller,
3882 LogicalDriveNumber,
3883 Controller->ControllerNumber,
3884 LogicalDriveNumber,
3885 (NewLogicalDriveInformation->LogicalDriveState
3886 == DAC960_V1_LogicalDrive_Online
3887 ? "ONLINE"
3888 : NewLogicalDriveInformation->LogicalDriveState
3889 == DAC960_V1_LogicalDrive_Critical
3890 ? "CRITICAL" : "OFFLINE"));
3891 if (NewLogicalDriveInformation->WriteBack !=
3892 OldLogicalDriveInformation->WriteBack)
3893 DAC960_Critical("Logical Drive %d (/dev/rd/c%dd%d) "
3894 "is now %s\n", Controller,
3895 LogicalDriveNumber,
3896 Controller->ControllerNumber,
3897 LogicalDriveNumber,
3898 (NewLogicalDriveInformation->WriteBack
3899 ? "WRITE BACK" : "WRITE THRU"));
3900 }
3901 memcpy(&Controller->V1.LogicalDriveInformation,
3902 Controller->V1.NewLogicalDriveInformation,
3903 sizeof(DAC960_V1_LogicalDriveInformationArray_T));
3904 }
3905 else if (CommandOpcode == DAC960_V1_GetRebuildProgress)
3906 {
3907 unsigned int LogicalDriveNumber =
3908 Controller->V1.RebuildProgress->LogicalDriveNumber;
3909 unsigned int LogicalDriveSize =
3910 Controller->V1.RebuildProgress->LogicalDriveSize;
3911 unsigned int BlocksCompleted =
3912 LogicalDriveSize - Controller->V1.RebuildProgress->RemainingBlocks;
3913 if (CommandStatus == DAC960_V1_NoRebuildOrCheckInProgress &&
3914 Controller->V1.LastRebuildStatus == DAC960_V1_NormalCompletion)
3915 CommandStatus = DAC960_V1_RebuildSuccessful;
3916 switch (CommandStatus)
3917 {
3918 case DAC960_V1_NormalCompletion:
3919 Controller->EphemeralProgressMessage = true;
3920 DAC960_Progress("Rebuild in Progress: "
3921 "Logical Drive %d (/dev/rd/c%dd%d) "
3922 "%d%% completed\n",
3923 Controller, LogicalDriveNumber,
3924 Controller->ControllerNumber,
3925 LogicalDriveNumber,
3926 (100 * (BlocksCompleted >> 7))
3927 / (LogicalDriveSize >> 7));
3928 Controller->EphemeralProgressMessage = false;
3929 break;
3930 case DAC960_V1_RebuildFailed_LogicalDriveFailure:
3931 DAC960_Progress("Rebuild Failed due to "
3932 "Logical Drive Failure\n", Controller);
3933 break;
3934 case DAC960_V1_RebuildFailed_BadBlocksOnOther:
3935 DAC960_Progress("Rebuild Failed due to "
3936 "Bad Blocks on Other Drives\n", Controller);
3937 break;
3938 case DAC960_V1_RebuildFailed_NewDriveFailed:
3939 DAC960_Progress("Rebuild Failed due to "
3940 "Failure of Drive Being Rebuilt\n", Controller);
3941 break;
3942 case DAC960_V1_NoRebuildOrCheckInProgress:
3943 break;
3944 case DAC960_V1_RebuildSuccessful:
3945 DAC960_Progress("Rebuild Completed Successfully\n", Controller);
3946 break;
3947 case DAC960_V1_RebuildSuccessfullyTerminated:
3948 DAC960_Progress("Rebuild Successfully Terminated\n", Controller);
3949 break;
3950 }
3951 Controller->V1.LastRebuildStatus = CommandStatus;
3952 if (CommandType != DAC960_MonitoringCommand &&
3953 Controller->V1.RebuildStatusPending)
3954 {
3955 Command->V1.CommandStatus = Controller->V1.PendingRebuildStatus;
3956 Controller->V1.RebuildStatusPending = false;
3957 }
3958 else if (CommandType == DAC960_MonitoringCommand &&
3959 CommandStatus != DAC960_V1_NormalCompletion &&
3960 CommandStatus != DAC960_V1_NoRebuildOrCheckInProgress)
3961 {
3962 Controller->V1.PendingRebuildStatus = CommandStatus;
3963 Controller->V1.RebuildStatusPending = true;
3964 }
3965 }
3966 else if (CommandOpcode == DAC960_V1_RebuildStat)
3967 {
3968 unsigned int LogicalDriveNumber =
3969 Controller->V1.RebuildProgress->LogicalDriveNumber;
3970 unsigned int LogicalDriveSize =
3971 Controller->V1.RebuildProgress->LogicalDriveSize;
3972 unsigned int BlocksCompleted =
3973 LogicalDriveSize - Controller->V1.RebuildProgress->RemainingBlocks;
3974 if (CommandSt