[PATCH] DAC960: remove redundant (and uninitialized)
[linux-2.6/history.git] / drivers / block / DAC960.c
bloba1522734c6d8b1483b39d6ce45e576d93b3c320f
1 /*
3 Linux Driver for Mylex DAC960/AcceleRAID/eXtremeRAID PCI RAID Controllers
5 Copyright 1998-2001 by Leonard N. Zubkoff <lnz@dandelion.com>
7 This program is free software; you may redistribute and/or modify it under
8 the terms of the GNU General Public License Version 2 as published by the
9 Free Software Foundation.
11 This program is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY, without even the implied warranty of MERCHANTABILITY
13 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 for complete details.
19 #define DAC960_DriverVersion "2.5.47"
20 #define DAC960_DriverDate "14 November 2002"
23 #include <linux/module.h>
24 #include <linux/types.h>
25 #include <linux/miscdevice.h>
26 #include <linux/blkdev.h>
27 #include <linux/bio.h>
28 #include <linux/completion.h>
29 #include <linux/delay.h>
30 #include <linux/genhd.h>
31 #include <linux/hdreg.h>
32 #include <linux/blkpg.h>
33 #include <linux/interrupt.h>
34 #include <linux/ioport.h>
35 #include <linux/mm.h>
36 #include <linux/slab.h>
37 #include <linux/proc_fs.h>
38 #include <linux/reboot.h>
39 #include <linux/spinlock.h>
40 #include <linux/timer.h>
41 #include <linux/pci.h>
42 #include <linux/init.h>
43 #include <asm/io.h>
44 #include <asm/uaccess.h>
45 #include "DAC960.h"
47 #define DAC960_GAM_MINOR 252
50 static DAC960_Controller_T *DAC960_Controllers[DAC960_MaxControllers];
51 static int DAC960_ControllerCount;
52 static struct proc_dir_entry *DAC960_ProcDirectoryEntry;
54 static long disk_size(DAC960_Controller_T *p, int drive_nr)
56 if (p->FirmwareType == DAC960_V1_Controller) {
57 if (drive_nr >= p->LogicalDriveCount)
58 return 0;
59 return p->V1.LogicalDriveInformation[drive_nr].
60 LogicalDriveSize;
61 } else {
62 DAC960_V2_LogicalDeviceInfo_T *i =
63 p->V2.LogicalDeviceInformation[drive_nr];
64 if (i == NULL)
65 return 0;
66 return i->ConfigurableDeviceSize;
70 static int DAC960_open(struct inode *inode, struct file *file)
72 struct gendisk *disk = inode->i_bdev->bd_disk;
73 DAC960_Controller_T *p = disk->queue->queuedata;
74 int drive_nr = (long)disk->private_data;
76 if (p->FirmwareType == DAC960_V1_Controller) {
77 if (p->V1.LogicalDriveInformation[drive_nr].
78 LogicalDriveState == DAC960_V1_LogicalDrive_Offline)
79 return -ENXIO;
80 } else {
81 DAC960_V2_LogicalDeviceInfo_T *i =
82 p->V2.LogicalDeviceInformation[drive_nr];
83 if (!i || i->LogicalDeviceState == DAC960_V2_LogicalDevice_Offline)
84 return -ENXIO;
87 check_disk_change(inode->i_bdev);
89 if (!get_capacity(p->disks[drive_nr]))
90 return -ENXIO;
91 return 0;
94 static int DAC960_ioctl(struct inode *inode, struct file *file,
95 unsigned int cmd, unsigned long arg)
97 struct gendisk *disk = inode->i_bdev->bd_disk;
98 DAC960_Controller_T *p = disk->queue->queuedata;
99 int drive_nr = (long)disk->private_data;
100 struct hd_geometry g, *loc = (struct hd_geometry *)arg;
102 if (cmd != HDIO_GETGEO || !loc)
103 return -EINVAL;
105 if (p->FirmwareType == DAC960_V1_Controller) {
106 g.heads = p->V1.GeometryTranslationHeads;
107 g.sectors = p->V1.GeometryTranslationSectors;
108 g.cylinders = p->V1.LogicalDriveInformation[drive_nr].
109 LogicalDriveSize / (g.heads * g.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 g.heads = 128;
116 g.sectors = 32;
117 break;
118 case DAC960_V2_Geometry_255_63:
119 g.heads = 255;
120 g.sectors = 63;
121 break;
122 default:
123 DAC960_Error("Illegal Logical Device Geometry %d\n",
124 p, i->DriveGeometry);
125 return -EINVAL;
128 g.cylinders = i->ConfigurableDeviceSize / (g.heads * g.sectors);
131 g.start = get_start_sect(inode->i_bdev);
133 return copy_to_user(loc, &g, sizeof g) ? -EFAULT : 0;
136 static int DAC960_media_changed(struct gendisk *disk)
138 DAC960_Controller_T *p = disk->queue->queuedata;
139 int drive_nr = (long)disk->private_data;
141 if (!p->LogicalDriveInitiallyAccessible[drive_nr])
142 return 1;
143 return 0;
146 static int DAC960_revalidate_disk(struct gendisk *disk)
148 DAC960_Controller_T *p = disk->queue->queuedata;
149 int unit = (long)disk->private_data;
151 set_capacity(disk, disk_size(p, unit));
152 return 0;
155 static struct block_device_operations DAC960_BlockDeviceOperations = {
156 .owner = THIS_MODULE,
157 .open = DAC960_open,
158 .ioctl = DAC960_ioctl,
159 .media_changed = DAC960_media_changed,
160 .revalidate_disk = DAC960_revalidate_disk,
165 DAC960_AnnounceDriver announces the Driver Version and Date, Author's Name,
166 Copyright Notice, and Electronic Mail Address.
169 static void DAC960_AnnounceDriver(DAC960_Controller_T *Controller)
171 DAC960_Announce("***** DAC960 RAID Driver Version "
172 DAC960_DriverVersion " of "
173 DAC960_DriverDate " *****\n", Controller);
174 DAC960_Announce("Copyright 1998-2001 by Leonard N. Zubkoff "
175 "<lnz@dandelion.com>\n", Controller);
180 DAC960_Failure prints a standardized error message, and then returns false.
183 static boolean DAC960_Failure(DAC960_Controller_T *Controller,
184 unsigned char *ErrorMessage)
186 DAC960_Error("While configuring DAC960 PCI RAID Controller at\n",
187 Controller);
188 if (Controller->IO_Address == 0)
189 DAC960_Error("PCI Bus %d Device %d Function %d I/O Address N/A "
190 "PCI Address 0x%X\n", Controller,
191 Controller->Bus, Controller->Device,
192 Controller->Function, Controller->PCI_Address);
193 else DAC960_Error("PCI Bus %d Device %d Function %d I/O Address "
194 "0x%X PCI Address 0x%X\n", Controller,
195 Controller->Bus, Controller->Device,
196 Controller->Function, Controller->IO_Address,
197 Controller->PCI_Address);
198 DAC960_Error("%s FAILED - DETACHING\n", Controller, ErrorMessage);
199 return false;
203 init_dma_loaf() and slice_dma_loaf() are helper functions for
204 aggregating the dma-mapped memory for a well-known collection of
205 data structures that are of different lengths.
207 These routines don't guarantee any alignment. The caller must
208 include any space needed for alignment in the sizes of the structures
209 that are passed in.
212 static boolean init_dma_loaf(struct pci_dev *dev, struct dma_loaf *loaf,
213 size_t len)
215 void *cpu_addr;
216 dma_addr_t dma_handle;
218 cpu_addr = pci_alloc_consistent(dev, len, &dma_handle);
219 if (cpu_addr == NULL)
220 return false;
222 loaf->cpu_free = loaf->cpu_base = cpu_addr;
223 loaf->dma_free =loaf->dma_base = dma_handle;
224 loaf->length = len;
225 memset(cpu_addr, 0, len);
226 return true;
229 static void *slice_dma_loaf(struct dma_loaf *loaf, size_t len,
230 dma_addr_t *dma_handle)
232 void *cpu_end = loaf->cpu_free + len;
233 void *cpu_addr = loaf->cpu_free;
235 if (cpu_end > loaf->cpu_base + loaf->length)
236 BUG();
237 *dma_handle = loaf->dma_free;
238 loaf->cpu_free = cpu_end;
239 loaf->dma_free += len;
240 return cpu_addr;
243 static void free_dma_loaf(struct pci_dev *dev, struct dma_loaf *loaf_handle)
245 if (loaf_handle->cpu_base != NULL)
246 pci_free_consistent(dev, loaf_handle->length,
247 loaf_handle->cpu_base, loaf_handle->dma_base);
252 DAC960_CreateAuxiliaryStructures allocates and initializes the auxiliary
253 data structures for Controller. It returns true on success and false on
254 failure.
257 static boolean DAC960_CreateAuxiliaryStructures(DAC960_Controller_T *Controller)
259 int CommandAllocationLength, CommandAllocationGroupSize;
260 int CommandsRemaining = 0, CommandIdentifier, CommandGroupByteCount;
261 void *AllocationPointer = NULL;
262 void *ScatterGatherCPU = NULL;
263 dma_addr_t ScatterGatherDMA;
264 struct pci_pool *ScatterGatherPool;
265 void *RequestSenseCPU = NULL;
266 dma_addr_t RequestSenseDMA;
267 struct pci_pool *RequestSensePool = NULL;
269 if (Controller->FirmwareType == DAC960_V1_Controller)
271 CommandAllocationLength = offsetof(DAC960_Command_T, V1.EndMarker);
272 CommandAllocationGroupSize = DAC960_V1_CommandAllocationGroupSize;
273 ScatterGatherPool = pci_pool_create("DAC960_V1_ScatterGather",
274 Controller->PCIDevice,
275 DAC960_V1_ScatterGatherLimit * sizeof(DAC960_V1_ScatterGatherSegment_T),
276 sizeof(DAC960_V1_ScatterGatherSegment_T), 0);
277 if (ScatterGatherPool == NULL)
278 return DAC960_Failure(Controller,
279 "AUXILIARY STRUCTURE CREATION (SG)");
280 Controller->ScatterGatherPool = ScatterGatherPool;
282 else
284 CommandAllocationLength = offsetof(DAC960_Command_T, V2.EndMarker);
285 CommandAllocationGroupSize = DAC960_V2_CommandAllocationGroupSize;
286 ScatterGatherPool = pci_pool_create("DAC960_V2_ScatterGather",
287 Controller->PCIDevice,
288 DAC960_V2_ScatterGatherLimit * sizeof(DAC960_V2_ScatterGatherSegment_T),
289 sizeof(DAC960_V2_ScatterGatherSegment_T), 0);
290 RequestSensePool = pci_pool_create("DAC960_V2_RequestSense",
291 Controller->PCIDevice, sizeof(DAC960_SCSI_RequestSense_T),
292 sizeof(int), 0);
293 if (ScatterGatherPool == NULL || RequestSensePool == NULL)
294 return DAC960_Failure(Controller,
295 "AUXILIARY STRUCTURE CREATION (SG)");
296 Controller->ScatterGatherPool = ScatterGatherPool;
297 Controller->V2.RequestSensePool = RequestSensePool;
299 Controller->CommandAllocationGroupSize = CommandAllocationGroupSize;
300 Controller->FreeCommands = NULL;
301 for (CommandIdentifier = 1;
302 CommandIdentifier <= Controller->DriverQueueDepth;
303 CommandIdentifier++)
305 DAC960_Command_T *Command;
306 if (--CommandsRemaining <= 0)
308 CommandsRemaining =
309 Controller->DriverQueueDepth - CommandIdentifier + 1;
310 if (CommandsRemaining > CommandAllocationGroupSize)
311 CommandsRemaining = CommandAllocationGroupSize;
312 CommandGroupByteCount =
313 CommandsRemaining * CommandAllocationLength;
314 AllocationPointer = kmalloc(CommandGroupByteCount, GFP_ATOMIC);
315 if (AllocationPointer == NULL)
316 return DAC960_Failure(Controller,
317 "AUXILIARY STRUCTURE CREATION");
318 memset(AllocationPointer, 0, CommandGroupByteCount);
320 Command = (DAC960_Command_T *) AllocationPointer;
321 AllocationPointer += CommandAllocationLength;
322 Command->CommandIdentifier = CommandIdentifier;
323 Command->Controller = Controller;
324 Command->Next = Controller->FreeCommands;
325 Controller->FreeCommands = Command;
326 Controller->Commands[CommandIdentifier-1] = Command;
327 ScatterGatherCPU = pci_pool_alloc(ScatterGatherPool, SLAB_ATOMIC,
328 &ScatterGatherDMA);
329 if (ScatterGatherCPU == NULL)
330 return DAC960_Failure(Controller, "AUXILIARY STRUCTURE CREATION");
332 if (RequestSensePool != NULL) {
333 RequestSenseCPU = pci_pool_alloc(RequestSensePool, SLAB_ATOMIC,
334 &RequestSenseDMA);
335 if (RequestSenseCPU == NULL) {
336 pci_pool_free(ScatterGatherPool, ScatterGatherCPU,
337 ScatterGatherDMA);
338 return DAC960_Failure(Controller,
339 "AUXILIARY STRUCTURE CREATION");
342 if (Controller->FirmwareType == DAC960_V1_Controller) {
343 Command->cmd_sglist = Command->V1.ScatterList;
344 Command->V1.ScatterGatherList =
345 (DAC960_V1_ScatterGatherSegment_T *)ScatterGatherCPU;
346 Command->V1.ScatterGatherListDMA = ScatterGatherDMA;
347 } else {
348 Command->cmd_sglist = Command->V2.ScatterList;
349 Command->V2.ScatterGatherList =
350 (DAC960_V2_ScatterGatherSegment_T *)ScatterGatherCPU;
351 Command->V2.ScatterGatherListDMA = ScatterGatherDMA;
352 Command->V2.RequestSense =
353 (DAC960_SCSI_RequestSense_T *)RequestSenseCPU;
354 Command->V2.RequestSenseDMA = RequestSenseDMA;
357 return true;
362 DAC960_DestroyAuxiliaryStructures deallocates the auxiliary data
363 structures for Controller.
366 static void DAC960_DestroyAuxiliaryStructures(DAC960_Controller_T *Controller)
368 int i;
369 struct pci_pool *ScatterGatherPool = Controller->ScatterGatherPool;
370 struct pci_pool *RequestSensePool = NULL;
371 void *ScatterGatherCPU;
372 dma_addr_t ScatterGatherDMA;
373 void *RequestSenseCPU;
374 dma_addr_t RequestSenseDMA;
375 DAC960_Command_T *CommandGroup = NULL;
378 if (Controller->FirmwareType == DAC960_V2_Controller)
379 RequestSensePool = Controller->V2.RequestSensePool;
381 Controller->FreeCommands = NULL;
382 for (i = 0; i < Controller->DriverQueueDepth; i++)
384 DAC960_Command_T *Command = Controller->Commands[i];
386 if (Command == NULL)
387 continue;
389 if (Controller->FirmwareType == DAC960_V1_Controller) {
390 ScatterGatherCPU = (void *)Command->V1.ScatterGatherList;
391 ScatterGatherDMA = Command->V1.ScatterGatherListDMA;
392 RequestSenseCPU = NULL;
393 RequestSenseDMA = (dma_addr_t)0;
394 } else {
395 ScatterGatherCPU = (void *)Command->V2.ScatterGatherList;
396 ScatterGatherDMA = Command->V2.ScatterGatherListDMA;
397 RequestSenseCPU = (void *)Command->V2.RequestSense;
398 RequestSenseDMA = Command->V2.RequestSenseDMA;
400 if (ScatterGatherCPU != NULL)
401 pci_pool_free(ScatterGatherPool, ScatterGatherCPU, ScatterGatherDMA);
402 if (RequestSenseCPU != NULL)
403 pci_pool_free(RequestSensePool, RequestSenseCPU, RequestSenseDMA);
405 if ((Command->CommandIdentifier
406 % Controller->CommandAllocationGroupSize) == 1) {
408 * We can't free the group of commands until all of the
409 * request sense and scatter gather dma structures are free.
410 * Remember the beginning of the group, but don't free it
411 * until we've reached the beginning of the next group.
413 if (CommandGroup != NULL)
414 kfree(CommandGroup);
415 CommandGroup = Command;
417 Controller->Commands[i] = NULL;
419 if (CommandGroup != NULL)
420 kfree(CommandGroup);
422 if (Controller->CombinedStatusBuffer != NULL)
424 kfree(Controller->CombinedStatusBuffer);
425 Controller->CombinedStatusBuffer = NULL;
426 Controller->CurrentStatusBuffer = NULL;
429 if (ScatterGatherPool != NULL)
430 pci_pool_destroy(ScatterGatherPool);
431 if (Controller->FirmwareType == DAC960_V1_Controller) return;
433 if (RequestSensePool != NULL)
434 pci_pool_destroy(RequestSensePool);
436 for (i = 0; i < DAC960_MaxLogicalDrives; i++)
437 if (Controller->V2.LogicalDeviceInformation[i] != NULL)
439 kfree(Controller->V2.LogicalDeviceInformation[i]);
440 Controller->V2.LogicalDeviceInformation[i] = NULL;
443 for (i = 0; i < DAC960_V2_MaxPhysicalDevices; i++)
445 if (Controller->V2.PhysicalDeviceInformation[i] != NULL)
447 kfree(Controller->V2.PhysicalDeviceInformation[i]);
448 Controller->V2.PhysicalDeviceInformation[i] = NULL;
450 if (Controller->V2.InquiryUnitSerialNumber[i] != NULL)
452 kfree(Controller->V2.InquiryUnitSerialNumber[i]);
453 Controller->V2.InquiryUnitSerialNumber[i] = NULL;
460 DAC960_V1_ClearCommand clears critical fields of Command for DAC960 V1
461 Firmware Controllers.
464 static inline void DAC960_V1_ClearCommand(DAC960_Command_T *Command)
466 DAC960_V1_CommandMailbox_T *CommandMailbox = &Command->V1.CommandMailbox;
467 memset(CommandMailbox, 0, sizeof(DAC960_V1_CommandMailbox_T));
468 Command->V1.CommandStatus = 0;
473 DAC960_V2_ClearCommand clears critical fields of Command for DAC960 V2
474 Firmware Controllers.
477 static inline void DAC960_V2_ClearCommand(DAC960_Command_T *Command)
479 DAC960_V2_CommandMailbox_T *CommandMailbox = &Command->V2.CommandMailbox;
480 memset(CommandMailbox, 0, sizeof(DAC960_V2_CommandMailbox_T));
481 Command->V2.CommandStatus = 0;
486 DAC960_AllocateCommand allocates a Command structure from Controller's
487 free list. During driver initialization, a special initialization command
488 has been placed on the free list to guarantee that command allocation can
489 never fail.
492 static inline DAC960_Command_T *DAC960_AllocateCommand(DAC960_Controller_T
493 *Controller)
495 DAC960_Command_T *Command = Controller->FreeCommands;
496 if (Command == NULL) return NULL;
497 Controller->FreeCommands = Command->Next;
498 Command->Next = NULL;
499 return Command;
504 DAC960_DeallocateCommand deallocates Command, returning it to Controller's
505 free list.
508 static inline void DAC960_DeallocateCommand(DAC960_Command_T *Command)
510 DAC960_Controller_T *Controller = Command->Controller;
512 Command->Request = NULL;
513 Command->Next = Controller->FreeCommands;
514 Controller->FreeCommands = Command;
519 DAC960_WaitForCommand waits for a wake_up on Controller's Command Wait Queue.
522 static void DAC960_WaitForCommand(DAC960_Controller_T *Controller)
524 spin_unlock_irq(&Controller->queue_lock);
525 __wait_event(Controller->CommandWaitQueue, Controller->FreeCommands);
526 spin_lock_irq(&Controller->queue_lock);
531 DAC960_BA_QueueCommand queues Command for DAC960 BA Series Controllers.
534 static void DAC960_BA_QueueCommand(DAC960_Command_T *Command)
536 DAC960_Controller_T *Controller = Command->Controller;
537 void *ControllerBaseAddress = Controller->BaseAddress;
538 DAC960_V2_CommandMailbox_T *CommandMailbox = &Command->V2.CommandMailbox;
539 DAC960_V2_CommandMailbox_T *NextCommandMailbox =
540 Controller->V2.NextCommandMailbox;
541 CommandMailbox->Common.CommandIdentifier = Command->CommandIdentifier;
542 DAC960_BA_WriteCommandMailbox(NextCommandMailbox, CommandMailbox);
543 if (Controller->V2.PreviousCommandMailbox1->Words[0] == 0 ||
544 Controller->V2.PreviousCommandMailbox2->Words[0] == 0)
545 DAC960_BA_MemoryMailboxNewCommand(ControllerBaseAddress);
546 Controller->V2.PreviousCommandMailbox2 =
547 Controller->V2.PreviousCommandMailbox1;
548 Controller->V2.PreviousCommandMailbox1 = NextCommandMailbox;
549 if (++NextCommandMailbox > Controller->V2.LastCommandMailbox)
550 NextCommandMailbox = Controller->V2.FirstCommandMailbox;
551 Controller->V2.NextCommandMailbox = NextCommandMailbox;
556 DAC960_LP_QueueCommand queues Command for DAC960 LP Series Controllers.
559 static void DAC960_LP_QueueCommand(DAC960_Command_T *Command)
561 DAC960_Controller_T *Controller = Command->Controller;
562 void *ControllerBaseAddress = Controller->BaseAddress;
563 DAC960_V2_CommandMailbox_T *CommandMailbox = &Command->V2.CommandMailbox;
564 DAC960_V2_CommandMailbox_T *NextCommandMailbox =
565 Controller->V2.NextCommandMailbox;
566 CommandMailbox->Common.CommandIdentifier = Command->CommandIdentifier;
567 DAC960_LP_WriteCommandMailbox(NextCommandMailbox, CommandMailbox);
568 if (Controller->V2.PreviousCommandMailbox1->Words[0] == 0 ||
569 Controller->V2.PreviousCommandMailbox2->Words[0] == 0)
570 DAC960_LP_MemoryMailboxNewCommand(ControllerBaseAddress);
571 Controller->V2.PreviousCommandMailbox2 =
572 Controller->V2.PreviousCommandMailbox1;
573 Controller->V2.PreviousCommandMailbox1 = NextCommandMailbox;
574 if (++NextCommandMailbox > Controller->V2.LastCommandMailbox)
575 NextCommandMailbox = Controller->V2.FirstCommandMailbox;
576 Controller->V2.NextCommandMailbox = NextCommandMailbox;
581 DAC960_LA_QueueCommandDualMode queues Command for DAC960 LA Series
582 Controllers with Dual Mode Firmware.
585 static void DAC960_LA_QueueCommandDualMode(DAC960_Command_T *Command)
587 DAC960_Controller_T *Controller = Command->Controller;
588 void *ControllerBaseAddress = Controller->BaseAddress;
589 DAC960_V1_CommandMailbox_T *CommandMailbox = &Command->V1.CommandMailbox;
590 DAC960_V1_CommandMailbox_T *NextCommandMailbox =
591 Controller->V1.NextCommandMailbox;
592 CommandMailbox->Common.CommandIdentifier = Command->CommandIdentifier;
593 DAC960_LA_WriteCommandMailbox(NextCommandMailbox, CommandMailbox);
594 if (Controller->V1.PreviousCommandMailbox1->Words[0] == 0 ||
595 Controller->V1.PreviousCommandMailbox2->Words[0] == 0)
596 DAC960_LA_MemoryMailboxNewCommand(ControllerBaseAddress);
597 Controller->V1.PreviousCommandMailbox2 =
598 Controller->V1.PreviousCommandMailbox1;
599 Controller->V1.PreviousCommandMailbox1 = NextCommandMailbox;
600 if (++NextCommandMailbox > Controller->V1.LastCommandMailbox)
601 NextCommandMailbox = Controller->V1.FirstCommandMailbox;
602 Controller->V1.NextCommandMailbox = NextCommandMailbox;
607 DAC960_LA_QueueCommandSingleMode queues Command for DAC960 LA Series
608 Controllers with Single Mode Firmware.
611 static void DAC960_LA_QueueCommandSingleMode(DAC960_Command_T *Command)
613 DAC960_Controller_T *Controller = Command->Controller;
614 void *ControllerBaseAddress = Controller->BaseAddress;
615 DAC960_V1_CommandMailbox_T *CommandMailbox = &Command->V1.CommandMailbox;
616 DAC960_V1_CommandMailbox_T *NextCommandMailbox =
617 Controller->V1.NextCommandMailbox;
618 CommandMailbox->Common.CommandIdentifier = Command->CommandIdentifier;
619 DAC960_LA_WriteCommandMailbox(NextCommandMailbox, CommandMailbox);
620 if (Controller->V1.PreviousCommandMailbox1->Words[0] == 0 ||
621 Controller->V1.PreviousCommandMailbox2->Words[0] == 0)
622 DAC960_LA_HardwareMailboxNewCommand(ControllerBaseAddress);
623 Controller->V1.PreviousCommandMailbox2 =
624 Controller->V1.PreviousCommandMailbox1;
625 Controller->V1.PreviousCommandMailbox1 = NextCommandMailbox;
626 if (++NextCommandMailbox > Controller->V1.LastCommandMailbox)
627 NextCommandMailbox = Controller->V1.FirstCommandMailbox;
628 Controller->V1.NextCommandMailbox = NextCommandMailbox;
633 DAC960_PG_QueueCommandDualMode queues Command for DAC960 PG Series
634 Controllers with Dual Mode Firmware.
637 static void DAC960_PG_QueueCommandDualMode(DAC960_Command_T *Command)
639 DAC960_Controller_T *Controller = Command->Controller;
640 void *ControllerBaseAddress = Controller->BaseAddress;
641 DAC960_V1_CommandMailbox_T *CommandMailbox = &Command->V1.CommandMailbox;
642 DAC960_V1_CommandMailbox_T *NextCommandMailbox =
643 Controller->V1.NextCommandMailbox;
644 CommandMailbox->Common.CommandIdentifier = Command->CommandIdentifier;
645 DAC960_PG_WriteCommandMailbox(NextCommandMailbox, CommandMailbox);
646 if (Controller->V1.PreviousCommandMailbox1->Words[0] == 0 ||
647 Controller->V1.PreviousCommandMailbox2->Words[0] == 0)
648 DAC960_PG_MemoryMailboxNewCommand(ControllerBaseAddress);
649 Controller->V1.PreviousCommandMailbox2 =
650 Controller->V1.PreviousCommandMailbox1;
651 Controller->V1.PreviousCommandMailbox1 = NextCommandMailbox;
652 if (++NextCommandMailbox > Controller->V1.LastCommandMailbox)
653 NextCommandMailbox = Controller->V1.FirstCommandMailbox;
654 Controller->V1.NextCommandMailbox = NextCommandMailbox;
659 DAC960_PG_QueueCommandSingleMode queues Command for DAC960 PG Series
660 Controllers with Single Mode Firmware.
663 static void DAC960_PG_QueueCommandSingleMode(DAC960_Command_T *Command)
665 DAC960_Controller_T *Controller = Command->Controller;
666 void *ControllerBaseAddress = Controller->BaseAddress;
667 DAC960_V1_CommandMailbox_T *CommandMailbox = &Command->V1.CommandMailbox;
668 DAC960_V1_CommandMailbox_T *NextCommandMailbox =
669 Controller->V1.NextCommandMailbox;
670 CommandMailbox->Common.CommandIdentifier = Command->CommandIdentifier;
671 DAC960_PG_WriteCommandMailbox(NextCommandMailbox, CommandMailbox);
672 if (Controller->V1.PreviousCommandMailbox1->Words[0] == 0 ||
673 Controller->V1.PreviousCommandMailbox2->Words[0] == 0)
674 DAC960_PG_HardwareMailboxNewCommand(ControllerBaseAddress);
675 Controller->V1.PreviousCommandMailbox2 =
676 Controller->V1.PreviousCommandMailbox1;
677 Controller->V1.PreviousCommandMailbox1 = NextCommandMailbox;
678 if (++NextCommandMailbox > Controller->V1.LastCommandMailbox)
679 NextCommandMailbox = Controller->V1.FirstCommandMailbox;
680 Controller->V1.NextCommandMailbox = NextCommandMailbox;
685 DAC960_PD_QueueCommand queues Command for DAC960 PD Series Controllers.
688 static void DAC960_PD_QueueCommand(DAC960_Command_T *Command)
690 DAC960_Controller_T *Controller = Command->Controller;
691 void *ControllerBaseAddress = Controller->BaseAddress;
692 DAC960_V1_CommandMailbox_T *CommandMailbox = &Command->V1.CommandMailbox;
693 CommandMailbox->Common.CommandIdentifier = Command->CommandIdentifier;
694 while (DAC960_PD_MailboxFullP(ControllerBaseAddress))
695 udelay(1);
696 DAC960_PD_WriteCommandMailbox(ControllerBaseAddress, CommandMailbox);
697 DAC960_PD_NewCommand(ControllerBaseAddress);
702 DAC960_P_QueueCommand queues Command for DAC960 P Series Controllers.
705 static void DAC960_P_QueueCommand(DAC960_Command_T *Command)
707 DAC960_Controller_T *Controller = Command->Controller;
708 void *ControllerBaseAddress = Controller->BaseAddress;
709 DAC960_V1_CommandMailbox_T *CommandMailbox = &Command->V1.CommandMailbox;
710 CommandMailbox->Common.CommandIdentifier = Command->CommandIdentifier;
711 switch (CommandMailbox->Common.CommandOpcode)
713 case DAC960_V1_Enquiry:
714 CommandMailbox->Common.CommandOpcode = DAC960_V1_Enquiry_Old;
715 break;
716 case DAC960_V1_GetDeviceState:
717 CommandMailbox->Common.CommandOpcode = DAC960_V1_GetDeviceState_Old;
718 break;
719 case DAC960_V1_Read:
720 CommandMailbox->Common.CommandOpcode = DAC960_V1_Read_Old;
721 DAC960_PD_To_P_TranslateReadWriteCommand(CommandMailbox);
722 break;
723 case DAC960_V1_Write:
724 CommandMailbox->Common.CommandOpcode = DAC960_V1_Write_Old;
725 DAC960_PD_To_P_TranslateReadWriteCommand(CommandMailbox);
726 break;
727 case DAC960_V1_ReadWithScatterGather:
728 CommandMailbox->Common.CommandOpcode =
729 DAC960_V1_ReadWithScatterGather_Old;
730 DAC960_PD_To_P_TranslateReadWriteCommand(CommandMailbox);
731 break;
732 case DAC960_V1_WriteWithScatterGather:
733 CommandMailbox->Common.CommandOpcode =
734 DAC960_V1_WriteWithScatterGather_Old;
735 DAC960_PD_To_P_TranslateReadWriteCommand(CommandMailbox);
736 break;
737 default:
738 break;
740 while (DAC960_PD_MailboxFullP(ControllerBaseAddress))
741 udelay(1);
742 DAC960_PD_WriteCommandMailbox(ControllerBaseAddress, CommandMailbox);
743 DAC960_PD_NewCommand(ControllerBaseAddress);
748 DAC960_ExecuteCommand executes Command and waits for completion.
751 static void DAC960_ExecuteCommand(DAC960_Command_T *Command)
753 DAC960_Controller_T *Controller = Command->Controller;
754 DECLARE_COMPLETION(Completion);
755 unsigned long flags;
756 Command->Completion = &Completion;
758 spin_lock_irqsave(&Controller->queue_lock, flags);
759 DAC960_QueueCommand(Command);
760 spin_unlock_irqrestore(&Controller->queue_lock, flags);
762 if (in_interrupt())
763 return;
764 wait_for_completion(&Completion);
769 DAC960_V1_ExecuteType3 executes a DAC960 V1 Firmware Controller Type 3
770 Command and waits for completion. It returns true on success and false
771 on failure.
774 static boolean DAC960_V1_ExecuteType3(DAC960_Controller_T *Controller,
775 DAC960_V1_CommandOpcode_T CommandOpcode,
776 dma_addr_t DataDMA)
778 DAC960_Command_T *Command = DAC960_AllocateCommand(Controller);
779 DAC960_V1_CommandMailbox_T *CommandMailbox = &Command->V1.CommandMailbox;
780 DAC960_V1_CommandStatus_T CommandStatus;
781 DAC960_V1_ClearCommand(Command);
782 Command->CommandType = DAC960_ImmediateCommand;
783 CommandMailbox->Type3.CommandOpcode = CommandOpcode;
784 CommandMailbox->Type3.BusAddress = DataDMA;
785 DAC960_ExecuteCommand(Command);
786 CommandStatus = Command->V1.CommandStatus;
787 DAC960_DeallocateCommand(Command);
788 return (CommandStatus == DAC960_V1_NormalCompletion);
793 DAC960_V1_ExecuteTypeB executes a DAC960 V1 Firmware Controller Type 3B
794 Command and waits for completion. It returns true on success and false
795 on failure.
798 static boolean DAC960_V1_ExecuteType3B(DAC960_Controller_T *Controller,
799 DAC960_V1_CommandOpcode_T CommandOpcode,
800 unsigned char CommandOpcode2,
801 dma_addr_t DataDMA)
803 DAC960_Command_T *Command = DAC960_AllocateCommand(Controller);
804 DAC960_V1_CommandMailbox_T *CommandMailbox = &Command->V1.CommandMailbox;
805 DAC960_V1_CommandStatus_T CommandStatus;
806 DAC960_V1_ClearCommand(Command);
807 Command->CommandType = DAC960_ImmediateCommand;
808 CommandMailbox->Type3B.CommandOpcode = CommandOpcode;
809 CommandMailbox->Type3B.CommandOpcode2 = CommandOpcode2;
810 CommandMailbox->Type3B.BusAddress = DataDMA;
811 DAC960_ExecuteCommand(Command);
812 CommandStatus = Command->V1.CommandStatus;
813 DAC960_DeallocateCommand(Command);
814 return (CommandStatus == DAC960_V1_NormalCompletion);
819 DAC960_V1_ExecuteType3D executes a DAC960 V1 Firmware Controller Type 3D
820 Command and waits for completion. It returns true on success and false
821 on failure.
824 static boolean DAC960_V1_ExecuteType3D(DAC960_Controller_T *Controller,
825 DAC960_V1_CommandOpcode_T CommandOpcode,
826 unsigned char Channel,
827 unsigned char TargetID,
828 dma_addr_t DataDMA)
830 DAC960_Command_T *Command = DAC960_AllocateCommand(Controller);
831 DAC960_V1_CommandMailbox_T *CommandMailbox = &Command->V1.CommandMailbox;
832 DAC960_V1_CommandStatus_T CommandStatus;
833 DAC960_V1_ClearCommand(Command);
834 Command->CommandType = DAC960_ImmediateCommand;
835 CommandMailbox->Type3D.CommandOpcode = CommandOpcode;
836 CommandMailbox->Type3D.Channel = Channel;
837 CommandMailbox->Type3D.TargetID = TargetID;
838 CommandMailbox->Type3D.BusAddress = DataDMA;
839 DAC960_ExecuteCommand(Command);
840 CommandStatus = Command->V1.CommandStatus;
841 DAC960_DeallocateCommand(Command);
842 return (CommandStatus == DAC960_V1_NormalCompletion);
847 DAC960_V2_GeneralInfo executes a DAC960 V2 Firmware General Information
848 Reading IOCTL Command and waits for completion. It returns true on success
849 and false on failure.
851 Return data in The controller's HealthStatusBuffer, which is dma-able memory
854 static boolean DAC960_V2_GeneralInfo(DAC960_Controller_T *Controller)
856 DAC960_Command_T *Command = DAC960_AllocateCommand(Controller);
857 DAC960_V2_CommandMailbox_T *CommandMailbox = &Command->V2.CommandMailbox;
858 DAC960_V2_CommandStatus_T CommandStatus;
859 DAC960_V2_ClearCommand(Command);
860 Command->CommandType = DAC960_ImmediateCommand;
861 CommandMailbox->Common.CommandOpcode = DAC960_V2_IOCTL;
862 CommandMailbox->Common.CommandControlBits
863 .DataTransferControllerToHost = true;
864 CommandMailbox->Common.CommandControlBits
865 .NoAutoRequestSense = true;
866 CommandMailbox->Common.DataTransferSize = sizeof(DAC960_V2_HealthStatusBuffer_T);
867 CommandMailbox->Common.IOCTL_Opcode = DAC960_V2_GetHealthStatus;
868 CommandMailbox->Common.DataTransferMemoryAddress
869 .ScatterGatherSegments[0]
870 .SegmentDataPointer =
871 Controller->V2.HealthStatusBufferDMA;
872 CommandMailbox->Common.DataTransferMemoryAddress
873 .ScatterGatherSegments[0]
874 .SegmentByteCount =
875 CommandMailbox->Common.DataTransferSize;
876 DAC960_ExecuteCommand(Command);
877 CommandStatus = Command->V2.CommandStatus;
878 DAC960_DeallocateCommand(Command);
879 return (CommandStatus == DAC960_V2_NormalCompletion);
884 DAC960_V2_ControllerInfo executes a DAC960 V2 Firmware Controller
885 Information Reading IOCTL Command and waits for completion. It returns
886 true on success and false on failure.
888 Data is returned in the controller's V2.NewControllerInformation dma-able
889 memory buffer.
892 static boolean DAC960_V2_NewControllerInfo(DAC960_Controller_T *Controller)
894 DAC960_Command_T *Command = DAC960_AllocateCommand(Controller);
895 DAC960_V2_CommandMailbox_T *CommandMailbox = &Command->V2.CommandMailbox;
896 DAC960_V2_CommandStatus_T CommandStatus;
897 DAC960_V2_ClearCommand(Command);
898 Command->CommandType = DAC960_ImmediateCommand;
899 CommandMailbox->ControllerInfo.CommandOpcode = DAC960_V2_IOCTL;
900 CommandMailbox->ControllerInfo.CommandControlBits
901 .DataTransferControllerToHost = true;
902 CommandMailbox->ControllerInfo.CommandControlBits
903 .NoAutoRequestSense = true;
904 CommandMailbox->ControllerInfo.DataTransferSize = sizeof(DAC960_V2_ControllerInfo_T);
905 CommandMailbox->ControllerInfo.ControllerNumber = 0;
906 CommandMailbox->ControllerInfo.IOCTL_Opcode = DAC960_V2_GetControllerInfo;
907 CommandMailbox->ControllerInfo.DataTransferMemoryAddress
908 .ScatterGatherSegments[0]
909 .SegmentDataPointer =
910 Controller->V2.NewControllerInformationDMA;
911 CommandMailbox->ControllerInfo.DataTransferMemoryAddress
912 .ScatterGatherSegments[0]
913 .SegmentByteCount =
914 CommandMailbox->ControllerInfo.DataTransferSize;
915 DAC960_ExecuteCommand(Command);
916 CommandStatus = Command->V2.CommandStatus;
917 DAC960_DeallocateCommand(Command);
918 return (CommandStatus == DAC960_V2_NormalCompletion);
923 DAC960_V2_LogicalDeviceInfo executes a DAC960 V2 Firmware Controller Logical
924 Device Information Reading IOCTL Command and waits for completion. It
925 returns true on success and false on failure.
927 Data is returned in the controller's V2.NewLogicalDeviceInformation
930 static boolean DAC960_V2_NewLogicalDeviceInfo(DAC960_Controller_T *Controller,
931 unsigned short LogicalDeviceNumber)
933 DAC960_Command_T *Command = DAC960_AllocateCommand(Controller);
934 DAC960_V2_CommandMailbox_T *CommandMailbox = &Command->V2.CommandMailbox;
935 DAC960_V2_CommandStatus_T CommandStatus;
937 DAC960_V2_ClearCommand(Command);
938 Command->CommandType = DAC960_ImmediateCommand;
939 CommandMailbox->LogicalDeviceInfo.CommandOpcode =
940 DAC960_V2_IOCTL;
941 CommandMailbox->LogicalDeviceInfo.CommandControlBits
942 .DataTransferControllerToHost = true;
943 CommandMailbox->LogicalDeviceInfo.CommandControlBits
944 .NoAutoRequestSense = true;
945 CommandMailbox->LogicalDeviceInfo.DataTransferSize =
946 sizeof(DAC960_V2_LogicalDeviceInfo_T);
947 CommandMailbox->LogicalDeviceInfo.LogicalDevice.LogicalDeviceNumber =
948 LogicalDeviceNumber;
949 CommandMailbox->LogicalDeviceInfo.IOCTL_Opcode = DAC960_V2_GetLogicalDeviceInfoValid;
950 CommandMailbox->LogicalDeviceInfo.DataTransferMemoryAddress
951 .ScatterGatherSegments[0]
952 .SegmentDataPointer =
953 Controller->V2.NewLogicalDeviceInformationDMA;
954 CommandMailbox->LogicalDeviceInfo.DataTransferMemoryAddress
955 .ScatterGatherSegments[0]
956 .SegmentByteCount =
957 CommandMailbox->LogicalDeviceInfo.DataTransferSize;
958 DAC960_ExecuteCommand(Command);
959 CommandStatus = Command->V2.CommandStatus;
960 DAC960_DeallocateCommand(Command);
961 return (CommandStatus == DAC960_V2_NormalCompletion);
966 DAC960_V2_PhysicalDeviceInfo executes a DAC960 V2 Firmware Controller "Read
967 Physical Device Information" IOCTL Command and waits for completion. It
968 returns true on success and false on failure.
970 The Channel, TargetID, LogicalUnit arguments should be 0 the first time
971 this function is called for a given controller. This will return data
972 for the "first" device on that controller. The returned data includes a
973 Channel, TargetID, LogicalUnit that can be passed in to this routine to
974 get data for the NEXT device on that controller.
976 Data is stored in the controller's V2.NewPhysicalDeviceInfo dma-able
977 memory buffer.
981 static boolean DAC960_V2_NewPhysicalDeviceInfo(DAC960_Controller_T *Controller,
982 unsigned char Channel,
983 unsigned char TargetID,
984 unsigned char LogicalUnit)
986 DAC960_Command_T *Command = DAC960_AllocateCommand(Controller);
987 DAC960_V2_CommandMailbox_T *CommandMailbox = &Command->V2.CommandMailbox;
988 DAC960_V2_CommandStatus_T CommandStatus;
990 DAC960_V2_ClearCommand(Command);
991 Command->CommandType = DAC960_ImmediateCommand;
992 CommandMailbox->PhysicalDeviceInfo.CommandOpcode = DAC960_V2_IOCTL;
993 CommandMailbox->PhysicalDeviceInfo.CommandControlBits
994 .DataTransferControllerToHost = true;
995 CommandMailbox->PhysicalDeviceInfo.CommandControlBits
996 .NoAutoRequestSense = true;
997 CommandMailbox->PhysicalDeviceInfo.DataTransferSize =
998 sizeof(DAC960_V2_PhysicalDeviceInfo_T);
999 CommandMailbox->PhysicalDeviceInfo.PhysicalDevice.LogicalUnit = LogicalUnit;
1000 CommandMailbox->PhysicalDeviceInfo.PhysicalDevice.TargetID = TargetID;
1001 CommandMailbox->PhysicalDeviceInfo.PhysicalDevice.Channel = Channel;
1002 CommandMailbox->PhysicalDeviceInfo.IOCTL_Opcode =
1003 DAC960_V2_GetPhysicalDeviceInfoValid;
1004 CommandMailbox->PhysicalDeviceInfo.DataTransferMemoryAddress
1005 .ScatterGatherSegments[0]
1006 .SegmentDataPointer =
1007 Controller->V2.NewPhysicalDeviceInformationDMA;
1008 CommandMailbox->PhysicalDeviceInfo.DataTransferMemoryAddress
1009 .ScatterGatherSegments[0]
1010 .SegmentByteCount =
1011 CommandMailbox->PhysicalDeviceInfo.DataTransferSize;
1012 DAC960_ExecuteCommand(Command);
1013 CommandStatus = Command->V2.CommandStatus;
1014 DAC960_DeallocateCommand(Command);
1015 return (CommandStatus == DAC960_V2_NormalCompletion);
1019 static void DAC960_V2_ConstructNewUnitSerialNumber(
1020 DAC960_Controller_T *Controller,
1021 DAC960_V2_CommandMailbox_T *CommandMailbox, int Channel, int TargetID,
1022 int LogicalUnit)
1024 CommandMailbox->SCSI_10.CommandOpcode = DAC960_V2_SCSI_10_Passthru;
1025 CommandMailbox->SCSI_10.CommandControlBits
1026 .DataTransferControllerToHost = true;
1027 CommandMailbox->SCSI_10.CommandControlBits
1028 .NoAutoRequestSense = true;
1029 CommandMailbox->SCSI_10.DataTransferSize =
1030 sizeof(DAC960_SCSI_Inquiry_UnitSerialNumber_T);
1031 CommandMailbox->SCSI_10.PhysicalDevice.LogicalUnit = LogicalUnit;
1032 CommandMailbox->SCSI_10.PhysicalDevice.TargetID = TargetID;
1033 CommandMailbox->SCSI_10.PhysicalDevice.Channel = Channel;
1034 CommandMailbox->SCSI_10.CDBLength = 6;
1035 CommandMailbox->SCSI_10.SCSI_CDB[0] = 0x12; /* INQUIRY */
1036 CommandMailbox->SCSI_10.SCSI_CDB[1] = 1; /* EVPD = 1 */
1037 CommandMailbox->SCSI_10.SCSI_CDB[2] = 0x80; /* Page Code */
1038 CommandMailbox->SCSI_10.SCSI_CDB[3] = 0; /* Reserved */
1039 CommandMailbox->SCSI_10.SCSI_CDB[4] =
1040 sizeof(DAC960_SCSI_Inquiry_UnitSerialNumber_T);
1041 CommandMailbox->SCSI_10.SCSI_CDB[5] = 0; /* Control */
1042 CommandMailbox->SCSI_10.DataTransferMemoryAddress
1043 .ScatterGatherSegments[0]
1044 .SegmentDataPointer =
1045 Controller->V2.NewInquiryUnitSerialNumberDMA;
1046 CommandMailbox->SCSI_10.DataTransferMemoryAddress
1047 .ScatterGatherSegments[0]
1048 .SegmentByteCount =
1049 CommandMailbox->SCSI_10.DataTransferSize;
1054 DAC960_V2_NewUnitSerialNumber executes an SCSI pass-through
1055 Inquiry command to a SCSI device identified by Channel number,
1056 Target id, Logical Unit Number. This function Waits for completion
1057 of the command.
1059 The return data includes Unit Serial Number information for the
1060 specified device.
1062 Data is stored in the controller's V2.NewPhysicalDeviceInfo dma-able
1063 memory buffer.
1066 static boolean DAC960_V2_NewInquiryUnitSerialNumber(DAC960_Controller_T *Controller,
1067 int Channel, int TargetID, int LogicalUnit)
1069 DAC960_Command_T *Command;
1070 DAC960_V2_CommandMailbox_T *CommandMailbox;
1071 DAC960_V2_CommandStatus_T CommandStatus;
1073 Command = DAC960_AllocateCommand(Controller);
1074 CommandMailbox = &Command->V2.CommandMailbox;
1075 DAC960_V2_ClearCommand(Command);
1076 Command->CommandType = DAC960_ImmediateCommand;
1078 DAC960_V2_ConstructNewUnitSerialNumber(Controller, CommandMailbox,
1079 Channel, TargetID, LogicalUnit);
1081 DAC960_ExecuteCommand(Command);
1082 CommandStatus = Command->V2.CommandStatus;
1083 DAC960_DeallocateCommand(Command);
1084 return (CommandStatus == DAC960_V2_NormalCompletion);
1089 DAC960_V2_DeviceOperation executes a DAC960 V2 Firmware Controller Device
1090 Operation IOCTL Command and waits for completion. It returns true on
1091 success and false on failure.
1094 static boolean DAC960_V2_DeviceOperation(DAC960_Controller_T *Controller,
1095 DAC960_V2_IOCTL_Opcode_T IOCTL_Opcode,
1096 DAC960_V2_OperationDevice_T
1097 OperationDevice)
1099 DAC960_Command_T *Command = DAC960_AllocateCommand(Controller);
1100 DAC960_V2_CommandMailbox_T *CommandMailbox = &Command->V2.CommandMailbox;
1101 DAC960_V2_CommandStatus_T CommandStatus;
1102 DAC960_V2_ClearCommand(Command);
1103 Command->CommandType = DAC960_ImmediateCommand;
1104 CommandMailbox->DeviceOperation.CommandOpcode = DAC960_V2_IOCTL;
1105 CommandMailbox->DeviceOperation.CommandControlBits
1106 .DataTransferControllerToHost = true;
1107 CommandMailbox->DeviceOperation.CommandControlBits
1108 .NoAutoRequestSense = true;
1109 CommandMailbox->DeviceOperation.IOCTL_Opcode = IOCTL_Opcode;
1110 CommandMailbox->DeviceOperation.OperationDevice = OperationDevice;
1111 DAC960_ExecuteCommand(Command);
1112 CommandStatus = Command->V2.CommandStatus;
1113 DAC960_DeallocateCommand(Command);
1114 return (CommandStatus == DAC960_V2_NormalCompletion);
1119 DAC960_V1_EnableMemoryMailboxInterface enables the Memory Mailbox Interface
1120 for DAC960 V1 Firmware Controllers.
1122 PD and P controller types have no memory mailbox, but still need the
1123 other dma mapped memory.
1126 static boolean DAC960_V1_EnableMemoryMailboxInterface(DAC960_Controller_T
1127 *Controller)
1129 void *ControllerBaseAddress = Controller->BaseAddress;
1130 DAC960_HardwareType_T hw_type = Controller->HardwareType;
1131 struct pci_dev *PCI_Device = Controller->PCIDevice;
1132 struct dma_loaf *DmaPages = &Controller->DmaPages;
1133 size_t DmaPagesSize;
1134 size_t CommandMailboxesSize;
1135 size_t StatusMailboxesSize;
1137 DAC960_V1_CommandMailbox_T *CommandMailboxesMemory;
1138 dma_addr_t CommandMailboxesMemoryDMA;
1140 DAC960_V1_StatusMailbox_T *StatusMailboxesMemory;
1141 dma_addr_t StatusMailboxesMemoryDMA;
1143 DAC960_V1_CommandMailbox_T CommandMailbox;
1144 DAC960_V1_CommandStatus_T CommandStatus;
1145 int TimeoutCounter;
1146 int i;
1149 if (pci_set_dma_mask(Controller->PCIDevice, DAC690_V1_PciDmaMask))
1150 return DAC960_Failure(Controller, "DMA mask out of range");
1151 Controller->BounceBufferLimit = DAC690_V1_PciDmaMask;
1153 if ((hw_type == DAC960_PD_Controller) || (hw_type == DAC960_P_Controller)) {
1154 CommandMailboxesSize = 0;
1155 StatusMailboxesSize = 0;
1156 } else {
1157 CommandMailboxesSize = DAC960_V1_CommandMailboxCount * sizeof(DAC960_V1_CommandMailbox_T);
1158 StatusMailboxesSize = DAC960_V1_StatusMailboxCount * sizeof(DAC960_V1_StatusMailbox_T);
1160 DmaPagesSize = CommandMailboxesSize + StatusMailboxesSize +
1161 sizeof(DAC960_V1_DCDB_T) + sizeof(DAC960_V1_Enquiry_T) +
1162 sizeof(DAC960_V1_ErrorTable_T) + sizeof(DAC960_V1_EventLogEntry_T) +
1163 sizeof(DAC960_V1_RebuildProgress_T) +
1164 sizeof(DAC960_V1_LogicalDriveInformationArray_T) +
1165 sizeof(DAC960_V1_BackgroundInitializationStatus_T) +
1166 sizeof(DAC960_V1_DeviceState_T) + sizeof(DAC960_SCSI_Inquiry_T) +
1167 sizeof(DAC960_SCSI_Inquiry_UnitSerialNumber_T);
1169 if (!init_dma_loaf(PCI_Device, DmaPages, DmaPagesSize))
1170 return false;
1173 if ((hw_type == DAC960_PD_Controller) || (hw_type == DAC960_P_Controller))
1174 goto skip_mailboxes;
1176 CommandMailboxesMemory = slice_dma_loaf(DmaPages,
1177 CommandMailboxesSize, &CommandMailboxesMemoryDMA);
1179 /* These are the base addresses for the command memory mailbox array */
1180 Controller->V1.FirstCommandMailbox = CommandMailboxesMemory;
1181 Controller->V1.FirstCommandMailboxDMA = CommandMailboxesMemoryDMA;
1183 CommandMailboxesMemory += DAC960_V1_CommandMailboxCount - 1;
1184 Controller->V1.LastCommandMailbox = CommandMailboxesMemory;
1185 Controller->V1.NextCommandMailbox = Controller->V1.FirstCommandMailbox;
1186 Controller->V1.PreviousCommandMailbox1 = Controller->V1.LastCommandMailbox;
1187 Controller->V1.PreviousCommandMailbox2 =
1188 Controller->V1.LastCommandMailbox - 1;
1190 /* These are the base addresses for the status memory mailbox array */
1191 StatusMailboxesMemory = slice_dma_loaf(DmaPages,
1192 StatusMailboxesSize, &StatusMailboxesMemoryDMA);
1194 Controller->V1.FirstStatusMailbox = StatusMailboxesMemory;
1195 Controller->V1.FirstStatusMailboxDMA = StatusMailboxesMemoryDMA;
1196 StatusMailboxesMemory += DAC960_V1_StatusMailboxCount - 1;
1197 Controller->V1.LastStatusMailbox = StatusMailboxesMemory;
1198 Controller->V1.NextStatusMailbox = Controller->V1.FirstStatusMailbox;
1200 skip_mailboxes:
1201 Controller->V1.MonitoringDCDB = slice_dma_loaf(DmaPages,
1202 sizeof(DAC960_V1_DCDB_T),
1203 &Controller->V1.MonitoringDCDB_DMA);
1205 Controller->V1.NewEnquiry = slice_dma_loaf(DmaPages,
1206 sizeof(DAC960_V1_Enquiry_T),
1207 &Controller->V1.NewEnquiryDMA);
1209 Controller->V1.NewErrorTable = slice_dma_loaf(DmaPages,
1210 sizeof(DAC960_V1_ErrorTable_T),
1211 &Controller->V1.NewErrorTableDMA);
1213 Controller->V1.EventLogEntry = slice_dma_loaf(DmaPages,
1214 sizeof(DAC960_V1_EventLogEntry_T),
1215 &Controller->V1.EventLogEntryDMA);
1217 Controller->V1.RebuildProgress = slice_dma_loaf(DmaPages,
1218 sizeof(DAC960_V1_RebuildProgress_T),
1219 &Controller->V1.RebuildProgressDMA);
1221 Controller->V1.NewLogicalDriveInformation = slice_dma_loaf(DmaPages,
1222 sizeof(DAC960_V1_LogicalDriveInformationArray_T),
1223 &Controller->V1.NewLogicalDriveInformationDMA);
1225 Controller->V1.BackgroundInitializationStatus = slice_dma_loaf(DmaPages,
1226 sizeof(DAC960_V1_BackgroundInitializationStatus_T),
1227 &Controller->V1.BackgroundInitializationStatusDMA);
1229 Controller->V1.NewDeviceState = slice_dma_loaf(DmaPages,
1230 sizeof(DAC960_V1_DeviceState_T),
1231 &Controller->V1.NewDeviceStateDMA);
1233 Controller->V1.NewInquiryStandardData = slice_dma_loaf(DmaPages,
1234 sizeof(DAC960_SCSI_Inquiry_T),
1235 &Controller->V1.NewInquiryStandardDataDMA);
1237 Controller->V1.NewInquiryUnitSerialNumber = slice_dma_loaf(DmaPages,
1238 sizeof(DAC960_SCSI_Inquiry_UnitSerialNumber_T),
1239 &Controller->V1.NewInquiryUnitSerialNumberDMA);
1241 if ((hw_type == DAC960_PD_Controller) || (hw_type == DAC960_P_Controller))
1242 return true;
1244 /* Enable the Memory Mailbox Interface. */
1245 Controller->V1.DualModeMemoryMailboxInterface = true;
1246 CommandMailbox.TypeX.CommandOpcode = 0x2B;
1247 CommandMailbox.TypeX.CommandIdentifier = 0;
1248 CommandMailbox.TypeX.CommandOpcode2 = 0x14;
1249 CommandMailbox.TypeX.CommandMailboxesBusAddress =
1250 Controller->V1.FirstCommandMailboxDMA;
1251 CommandMailbox.TypeX.StatusMailboxesBusAddress =
1252 Controller->V1.FirstStatusMailboxDMA;
1253 #define TIMEOUT_COUNT 1000000
1255 for (i = 0; i < 2; i++)
1256 switch (Controller->HardwareType)
1258 case DAC960_LA_Controller:
1259 TimeoutCounter = TIMEOUT_COUNT;
1260 while (--TimeoutCounter >= 0)
1262 if (!DAC960_LA_HardwareMailboxFullP(ControllerBaseAddress))
1263 break;
1264 udelay(10);
1266 if (TimeoutCounter < 0) return false;
1267 DAC960_LA_WriteHardwareMailbox(ControllerBaseAddress, &CommandMailbox);
1268 DAC960_LA_HardwareMailboxNewCommand(ControllerBaseAddress);
1269 TimeoutCounter = TIMEOUT_COUNT;
1270 while (--TimeoutCounter >= 0)
1272 if (DAC960_LA_HardwareMailboxStatusAvailableP(
1273 ControllerBaseAddress))
1274 break;
1275 udelay(10);
1277 if (TimeoutCounter < 0) return false;
1278 CommandStatus = DAC960_LA_ReadStatusRegister(ControllerBaseAddress);
1279 DAC960_LA_AcknowledgeHardwareMailboxInterrupt(ControllerBaseAddress);
1280 DAC960_LA_AcknowledgeHardwareMailboxStatus(ControllerBaseAddress);
1281 if (CommandStatus == DAC960_V1_NormalCompletion) return true;
1282 Controller->V1.DualModeMemoryMailboxInterface = false;
1283 CommandMailbox.TypeX.CommandOpcode2 = 0x10;
1284 break;
1285 case DAC960_PG_Controller:
1286 TimeoutCounter = TIMEOUT_COUNT;
1287 while (--TimeoutCounter >= 0)
1289 if (!DAC960_PG_HardwareMailboxFullP(ControllerBaseAddress))
1290 break;
1291 udelay(10);
1293 if (TimeoutCounter < 0) return false;
1294 DAC960_PG_WriteHardwareMailbox(ControllerBaseAddress, &CommandMailbox);
1295 DAC960_PG_HardwareMailboxNewCommand(ControllerBaseAddress);
1297 TimeoutCounter = TIMEOUT_COUNT;
1298 while (--TimeoutCounter >= 0)
1300 if (DAC960_PG_HardwareMailboxStatusAvailableP(
1301 ControllerBaseAddress))
1302 break;
1303 udelay(10);
1305 if (TimeoutCounter < 0) return false;
1306 CommandStatus = DAC960_PG_ReadStatusRegister(ControllerBaseAddress);
1307 DAC960_PG_AcknowledgeHardwareMailboxInterrupt(ControllerBaseAddress);
1308 DAC960_PG_AcknowledgeHardwareMailboxStatus(ControllerBaseAddress);
1309 if (CommandStatus == DAC960_V1_NormalCompletion) return true;
1310 Controller->V1.DualModeMemoryMailboxInterface = false;
1311 CommandMailbox.TypeX.CommandOpcode2 = 0x10;
1312 break;
1313 default:
1314 DAC960_Failure(Controller, "Unknown Controller Type\n");
1315 break;
1317 return false;
1322 DAC960_V2_EnableMemoryMailboxInterface enables the Memory Mailbox Interface
1323 for DAC960 V2 Firmware Controllers.
1325 Aggregate the space needed for the controller's memory mailbox and
1326 the other data structures that will be targets of dma transfers with
1327 the controller. Allocate a dma-mapped region of memory to hold these
1328 structures. Then, save CPU pointers and dma_addr_t values to reference
1329 the structures that are contained in that region.
1332 static boolean DAC960_V2_EnableMemoryMailboxInterface(DAC960_Controller_T
1333 *Controller)
1335 void *ControllerBaseAddress = Controller->BaseAddress;
1336 struct pci_dev *PCI_Device = Controller->PCIDevice;
1337 struct dma_loaf *DmaPages = &Controller->DmaPages;
1338 size_t DmaPagesSize;
1339 size_t CommandMailboxesSize;
1340 size_t StatusMailboxesSize;
1342 DAC960_V2_CommandMailbox_T *CommandMailboxesMemory;
1343 dma_addr_t CommandMailboxesMemoryDMA;
1345 DAC960_V2_StatusMailbox_T *StatusMailboxesMemory;
1346 dma_addr_t StatusMailboxesMemoryDMA;
1348 DAC960_V2_CommandMailbox_T *CommandMailbox;
1349 dma_addr_t CommandMailboxDMA;
1350 DAC960_V2_CommandStatus_T CommandStatus;
1352 if (pci_set_dma_mask(Controller->PCIDevice, DAC690_V2_PciDmaMask))
1353 return DAC960_Failure(Controller, "DMA mask out of range");
1354 Controller->BounceBufferLimit = DAC690_V2_PciDmaMask;
1356 /* This is a temporary dma mapping, used only in the scope of this function */
1357 CommandMailbox =
1358 (DAC960_V2_CommandMailbox_T *)pci_alloc_consistent( PCI_Device,
1359 sizeof(DAC960_V2_CommandMailbox_T), &CommandMailboxDMA);
1360 if (CommandMailbox == NULL)
1361 return false;
1363 CommandMailboxesSize = DAC960_V2_CommandMailboxCount * sizeof(DAC960_V2_CommandMailbox_T);
1364 StatusMailboxesSize = DAC960_V2_StatusMailboxCount * sizeof(DAC960_V2_StatusMailbox_T);
1365 DmaPagesSize =
1366 CommandMailboxesSize + StatusMailboxesSize +
1367 sizeof(DAC960_V2_HealthStatusBuffer_T) +
1368 sizeof(DAC960_V2_ControllerInfo_T) +
1369 sizeof(DAC960_V2_LogicalDeviceInfo_T) +
1370 sizeof(DAC960_V2_PhysicalDeviceInfo_T) +
1371 sizeof(DAC960_SCSI_Inquiry_UnitSerialNumber_T) +
1372 sizeof(DAC960_V2_Event_T) +
1373 sizeof(DAC960_V2_PhysicalToLogicalDevice_T);
1375 if (!init_dma_loaf(PCI_Device, DmaPages, DmaPagesSize)) {
1376 pci_free_consistent(PCI_Device, sizeof(DAC960_V2_CommandMailbox_T),
1377 CommandMailbox, CommandMailboxDMA);
1378 return false;
1381 CommandMailboxesMemory = slice_dma_loaf(DmaPages,
1382 CommandMailboxesSize, &CommandMailboxesMemoryDMA);
1384 /* These are the base addresses for the command memory mailbox array */
1385 Controller->V2.FirstCommandMailbox = CommandMailboxesMemory;
1386 Controller->V2.FirstCommandMailboxDMA = CommandMailboxesMemoryDMA;
1388 CommandMailboxesMemory += DAC960_V2_CommandMailboxCount - 1;
1389 Controller->V2.LastCommandMailbox = CommandMailboxesMemory;
1390 Controller->V2.NextCommandMailbox = Controller->V2.FirstCommandMailbox;
1391 Controller->V2.PreviousCommandMailbox1 = Controller->V2.LastCommandMailbox;
1392 Controller->V2.PreviousCommandMailbox2 =
1393 Controller->V2.LastCommandMailbox - 1;
1395 /* These are the base addresses for the status memory mailbox array */
1396 StatusMailboxesMemory = slice_dma_loaf(DmaPages,
1397 StatusMailboxesSize, &StatusMailboxesMemoryDMA);
1399 Controller->V2.FirstStatusMailbox = StatusMailboxesMemory;
1400 Controller->V2.FirstStatusMailboxDMA = StatusMailboxesMemoryDMA;
1401 StatusMailboxesMemory += DAC960_V2_StatusMailboxCount - 1;
1402 Controller->V2.LastStatusMailbox = StatusMailboxesMemory;
1403 Controller->V2.NextStatusMailbox = Controller->V2.FirstStatusMailbox;
1405 Controller->V2.HealthStatusBuffer = slice_dma_loaf(DmaPages,
1406 sizeof(DAC960_V2_HealthStatusBuffer_T),
1407 &Controller->V2.HealthStatusBufferDMA);
1409 Controller->V2.NewControllerInformation = slice_dma_loaf(DmaPages,
1410 sizeof(DAC960_V2_ControllerInfo_T),
1411 &Controller->V2.NewControllerInformationDMA);
1413 Controller->V2.NewLogicalDeviceInformation = slice_dma_loaf(DmaPages,
1414 sizeof(DAC960_V2_LogicalDeviceInfo_T),
1415 &Controller->V2.NewLogicalDeviceInformationDMA);
1417 Controller->V2.NewPhysicalDeviceInformation = slice_dma_loaf(DmaPages,
1418 sizeof(DAC960_V2_PhysicalDeviceInfo_T),
1419 &Controller->V2.NewPhysicalDeviceInformationDMA);
1421 Controller->V2.NewInquiryUnitSerialNumber = slice_dma_loaf(DmaPages,
1422 sizeof(DAC960_SCSI_Inquiry_UnitSerialNumber_T),
1423 &Controller->V2.NewInquiryUnitSerialNumberDMA);
1425 Controller->V2.Event = slice_dma_loaf(DmaPages,
1426 sizeof(DAC960_V2_Event_T),
1427 &Controller->V2.EventDMA);
1429 Controller->V2.PhysicalToLogicalDevice = slice_dma_loaf(DmaPages,
1430 sizeof(DAC960_V2_PhysicalToLogicalDevice_T),
1431 &Controller->V2.PhysicalToLogicalDeviceDMA);
1434 Enable the Memory Mailbox Interface.
1436 I don't know why we can't just use one of the memory mailboxes
1437 we just allocated to do this, instead of using this temporary one.
1438 Try this change later.
1440 memset(CommandMailbox, 0, sizeof(DAC960_V2_CommandMailbox_T));
1441 CommandMailbox->SetMemoryMailbox.CommandIdentifier = 1;
1442 CommandMailbox->SetMemoryMailbox.CommandOpcode = DAC960_V2_IOCTL;
1443 CommandMailbox->SetMemoryMailbox.CommandControlBits.NoAutoRequestSense = true;
1444 CommandMailbox->SetMemoryMailbox.FirstCommandMailboxSizeKB =
1445 (DAC960_V2_CommandMailboxCount * sizeof(DAC960_V2_CommandMailbox_T)) >> 10;
1446 CommandMailbox->SetMemoryMailbox.FirstStatusMailboxSizeKB =
1447 (DAC960_V2_StatusMailboxCount * sizeof(DAC960_V2_StatusMailbox_T)) >> 10;
1448 CommandMailbox->SetMemoryMailbox.SecondCommandMailboxSizeKB = 0;
1449 CommandMailbox->SetMemoryMailbox.SecondStatusMailboxSizeKB = 0;
1450 CommandMailbox->SetMemoryMailbox.RequestSenseSize = 0;
1451 CommandMailbox->SetMemoryMailbox.IOCTL_Opcode = DAC960_V2_SetMemoryMailbox;
1452 CommandMailbox->SetMemoryMailbox.HealthStatusBufferSizeKB = 1;
1453 CommandMailbox->SetMemoryMailbox.HealthStatusBufferBusAddress =
1454 Controller->V2.HealthStatusBufferDMA;
1455 CommandMailbox->SetMemoryMailbox.FirstCommandMailboxBusAddress =
1456 Controller->V2.FirstCommandMailboxDMA;
1457 CommandMailbox->SetMemoryMailbox.FirstStatusMailboxBusAddress =
1458 Controller->V2.FirstStatusMailboxDMA;
1459 switch (Controller->HardwareType)
1461 case DAC960_BA_Controller:
1462 while (DAC960_BA_HardwareMailboxFullP(ControllerBaseAddress))
1463 udelay(1);
1464 DAC960_BA_WriteHardwareMailbox(ControllerBaseAddress, CommandMailboxDMA);
1465 DAC960_BA_HardwareMailboxNewCommand(ControllerBaseAddress);
1466 while (!DAC960_BA_HardwareMailboxStatusAvailableP(ControllerBaseAddress))
1467 udelay(1);
1468 CommandStatus = DAC960_BA_ReadCommandStatus(ControllerBaseAddress);
1469 DAC960_BA_AcknowledgeHardwareMailboxInterrupt(ControllerBaseAddress);
1470 DAC960_BA_AcknowledgeHardwareMailboxStatus(ControllerBaseAddress);
1471 break;
1472 case DAC960_LP_Controller:
1473 while (DAC960_LP_HardwareMailboxFullP(ControllerBaseAddress))
1474 udelay(1);
1475 DAC960_LP_WriteHardwareMailbox(ControllerBaseAddress, CommandMailboxDMA);
1476 DAC960_LP_HardwareMailboxNewCommand(ControllerBaseAddress);
1477 while (!DAC960_LP_HardwareMailboxStatusAvailableP(ControllerBaseAddress))
1478 udelay(1);
1479 CommandStatus = DAC960_LP_ReadCommandStatus(ControllerBaseAddress);
1480 DAC960_LP_AcknowledgeHardwareMailboxInterrupt(ControllerBaseAddress);
1481 DAC960_LP_AcknowledgeHardwareMailboxStatus(ControllerBaseAddress);
1482 break;
1483 default:
1484 DAC960_Failure(Controller, "Unknown Controller Type\n");
1485 CommandStatus = DAC960_V2_AbormalCompletion;
1486 break;
1488 pci_free_consistent(PCI_Device, sizeof(DAC960_V2_CommandMailbox_T),
1489 CommandMailbox, CommandMailboxDMA);
1490 return (CommandStatus == DAC960_V2_NormalCompletion);
1495 DAC960_V1_ReadControllerConfiguration reads the Configuration Information
1496 from DAC960 V1 Firmware Controllers and initializes the Controller structure.
1499 static boolean DAC960_V1_ReadControllerConfiguration(DAC960_Controller_T
1500 *Controller)
1502 DAC960_V1_Enquiry2_T *Enquiry2;
1503 dma_addr_t Enquiry2DMA;
1504 DAC960_V1_Config2_T *Config2;
1505 dma_addr_t Config2DMA;
1506 int LogicalDriveNumber, Channel, TargetID;
1507 struct dma_loaf local_dma;
1509 if (!init_dma_loaf(Controller->PCIDevice, &local_dma,
1510 sizeof(DAC960_V1_Enquiry2_T) + sizeof(DAC960_V1_Config2_T)))
1511 return DAC960_Failure(Controller, "LOGICAL DEVICE ALLOCATION");
1513 Enquiry2 = slice_dma_loaf(&local_dma, sizeof(DAC960_V1_Enquiry2_T), &Enquiry2DMA);
1514 Config2 = slice_dma_loaf(&local_dma, sizeof(DAC960_V1_Config2_T), &Config2DMA);
1516 if (!DAC960_V1_ExecuteType3(Controller, DAC960_V1_Enquiry,
1517 Controller->V1.NewEnquiryDMA)) {
1518 free_dma_loaf(Controller->PCIDevice, &local_dma);
1519 return DAC960_Failure(Controller, "ENQUIRY");
1521 memcpy(&Controller->V1.Enquiry, Controller->V1.NewEnquiry,
1522 sizeof(DAC960_V1_Enquiry_T));
1524 if (!DAC960_V1_ExecuteType3(Controller, DAC960_V1_Enquiry2, Enquiry2DMA)) {
1525 free_dma_loaf(Controller->PCIDevice, &local_dma);
1526 return DAC960_Failure(Controller, "ENQUIRY2");
1529 if (!DAC960_V1_ExecuteType3(Controller, DAC960_V1_ReadConfig2, Config2DMA)) {
1530 free_dma_loaf(Controller->PCIDevice, &local_dma);
1531 return DAC960_Failure(Controller, "READ CONFIG2");
1534 if (!DAC960_V1_ExecuteType3(Controller, DAC960_V1_GetLogicalDriveInformation,
1535 Controller->V1.NewLogicalDriveInformationDMA)) {
1536 free_dma_loaf(Controller->PCIDevice, &local_dma);
1537 return DAC960_Failure(Controller, "GET LOGICAL DRIVE INFORMATION");
1539 memcpy(&Controller->V1.LogicalDriveInformation,
1540 Controller->V1.NewLogicalDriveInformation,
1541 sizeof(DAC960_V1_LogicalDriveInformationArray_T));
1543 for (Channel = 0; Channel < Enquiry2->ActualChannels; Channel++)
1544 for (TargetID = 0; TargetID < Enquiry2->MaxTargets; TargetID++) {
1545 if (!DAC960_V1_ExecuteType3D(Controller, DAC960_V1_GetDeviceState,
1546 Channel, TargetID,
1547 Controller->V1.NewDeviceStateDMA)) {
1548 free_dma_loaf(Controller->PCIDevice, &local_dma);
1549 return DAC960_Failure(Controller, "GET DEVICE STATE");
1551 memcpy(&Controller->V1.DeviceState[Channel][TargetID],
1552 Controller->V1.NewDeviceState, sizeof(DAC960_V1_DeviceState_T));
1555 Initialize the Controller Model Name and Full Model Name fields.
1557 switch (Enquiry2->HardwareID.SubModel)
1559 case DAC960_V1_P_PD_PU:
1560 if (Enquiry2->SCSICapability.BusSpeed == DAC960_V1_Ultra)
1561 strcpy(Controller->ModelName, "DAC960PU");
1562 else strcpy(Controller->ModelName, "DAC960PD");
1563 break;
1564 case DAC960_V1_PL:
1565 strcpy(Controller->ModelName, "DAC960PL");
1566 break;
1567 case DAC960_V1_PG:
1568 strcpy(Controller->ModelName, "DAC960PG");
1569 break;
1570 case DAC960_V1_PJ:
1571 strcpy(Controller->ModelName, "DAC960PJ");
1572 break;
1573 case DAC960_V1_PR:
1574 strcpy(Controller->ModelName, "DAC960PR");
1575 break;
1576 case DAC960_V1_PT:
1577 strcpy(Controller->ModelName, "DAC960PT");
1578 break;
1579 case DAC960_V1_PTL0:
1580 strcpy(Controller->ModelName, "DAC960PTL0");
1581 break;
1582 case DAC960_V1_PRL:
1583 strcpy(Controller->ModelName, "DAC960PRL");
1584 break;
1585 case DAC960_V1_PTL1:
1586 strcpy(Controller->ModelName, "DAC960PTL1");
1587 break;
1588 case DAC960_V1_1164P:
1589 strcpy(Controller->ModelName, "DAC1164P");
1590 break;
1591 default:
1592 free_dma_loaf(Controller->PCIDevice, &local_dma);
1593 return DAC960_Failure(Controller, "MODEL VERIFICATION");
1595 strcpy(Controller->FullModelName, "Mylex ");
1596 strcat(Controller->FullModelName, Controller->ModelName);
1598 Initialize the Controller Firmware Version field and verify that it
1599 is a supported firmware version. The supported firmware versions are:
1601 DAC1164P 5.06 and above
1602 DAC960PTL/PRL/PJ/PG 4.06 and above
1603 DAC960PU/PD/PL 3.51 and above
1604 DAC960PU/PD/PL/P 2.73 and above
1606 #if defined(CONFIG_ALPHA)
1608 DEC Alpha machines were often equipped with DAC960 cards that were
1609 OEMed from Mylex, and had their own custom firmware. Version 2.70,
1610 the last custom FW revision to be released by DEC for these older
1611 controllers, appears to work quite well with this driver.
1613 Cards tested successfully were several versions each of the PD and
1614 PU, called by DEC the KZPSC and KZPAC, respectively, and having
1615 the Manufacturer Numbers (from Mylex), usually on a sticker on the
1616 back of the board, of:
1618 KZPSC: D040347 (1-channel) or D040348 (2-channel) or D040349 (3-channel)
1619 KZPAC: D040395 (1-channel) or D040396 (2-channel) or D040397 (3-channel)
1621 # define FIRMWARE_27X "2.70"
1622 #else
1623 # define FIRMWARE_27X "2.73"
1624 #endif
1626 if (Enquiry2->FirmwareID.MajorVersion == 0)
1628 Enquiry2->FirmwareID.MajorVersion =
1629 Controller->V1.Enquiry.MajorFirmwareVersion;
1630 Enquiry2->FirmwareID.MinorVersion =
1631 Controller->V1.Enquiry.MinorFirmwareVersion;
1632 Enquiry2->FirmwareID.FirmwareType = '0';
1633 Enquiry2->FirmwareID.TurnID = 0;
1635 sprintf(Controller->FirmwareVersion, "%d.%02d-%c-%02d",
1636 Enquiry2->FirmwareID.MajorVersion, Enquiry2->FirmwareID.MinorVersion,
1637 Enquiry2->FirmwareID.FirmwareType, Enquiry2->FirmwareID.TurnID);
1638 if (!((Controller->FirmwareVersion[0] == '5' &&
1639 strcmp(Controller->FirmwareVersion, "5.06") >= 0) ||
1640 (Controller->FirmwareVersion[0] == '4' &&
1641 strcmp(Controller->FirmwareVersion, "4.06") >= 0) ||
1642 (Controller->FirmwareVersion[0] == '3' &&
1643 strcmp(Controller->FirmwareVersion, "3.51") >= 0) ||
1644 (Controller->FirmwareVersion[0] == '2' &&
1645 strcmp(Controller->FirmwareVersion, FIRMWARE_27X) >= 0)))
1647 DAC960_Failure(Controller, "FIRMWARE VERSION VERIFICATION");
1648 DAC960_Error("Firmware Version = '%s'\n", Controller,
1649 Controller->FirmwareVersion);
1650 free_dma_loaf(Controller->PCIDevice, &local_dma);
1651 return false;
1654 Initialize the Controller Channels, Targets, Memory Size, and SAF-TE
1655 Enclosure Management Enabled fields.
1657 Controller->Channels = Enquiry2->ActualChannels;
1658 Controller->Targets = Enquiry2->MaxTargets;
1659 Controller->MemorySize = Enquiry2->MemorySize >> 20;
1660 Controller->V1.SAFTE_EnclosureManagementEnabled =
1661 (Enquiry2->FaultManagementType == DAC960_V1_SAFTE);
1663 Initialize the Controller Queue Depth, Driver Queue Depth, Logical Drive
1664 Count, Maximum Blocks per Command, Controller Scatter/Gather Limit, and
1665 Driver Scatter/Gather Limit. The Driver Queue Depth must be at most one
1666 less than the Controller Queue Depth to allow for an automatic drive
1667 rebuild operation.
1669 Controller->ControllerQueueDepth = Controller->V1.Enquiry.MaxCommands;
1670 Controller->DriverQueueDepth = Controller->ControllerQueueDepth - 1;
1671 if (Controller->DriverQueueDepth > DAC960_MaxDriverQueueDepth)
1672 Controller->DriverQueueDepth = DAC960_MaxDriverQueueDepth;
1673 Controller->LogicalDriveCount =
1674 Controller->V1.Enquiry.NumberOfLogicalDrives;
1675 Controller->MaxBlocksPerCommand = Enquiry2->MaxBlocksPerCommand;
1676 Controller->ControllerScatterGatherLimit = Enquiry2->MaxScatterGatherEntries;
1677 Controller->DriverScatterGatherLimit =
1678 Controller->ControllerScatterGatherLimit;
1679 if (Controller->DriverScatterGatherLimit > DAC960_V1_ScatterGatherLimit)
1680 Controller->DriverScatterGatherLimit = DAC960_V1_ScatterGatherLimit;
1682 Initialize the Stripe Size, Segment Size, and Geometry Translation.
1684 Controller->V1.StripeSize = Config2->BlocksPerStripe * Config2->BlockFactor
1685 >> (10 - DAC960_BlockSizeBits);
1686 Controller->V1.SegmentSize = Config2->BlocksPerCacheLine * Config2->BlockFactor
1687 >> (10 - DAC960_BlockSizeBits);
1688 switch (Config2->DriveGeometry)
1690 case DAC960_V1_Geometry_128_32:
1691 Controller->V1.GeometryTranslationHeads = 128;
1692 Controller->V1.GeometryTranslationSectors = 32;
1693 break;
1694 case DAC960_V1_Geometry_255_63:
1695 Controller->V1.GeometryTranslationHeads = 255;
1696 Controller->V1.GeometryTranslationSectors = 63;
1697 break;
1698 default:
1699 free_dma_loaf(Controller->PCIDevice, &local_dma);
1700 return DAC960_Failure(Controller, "CONFIG2 DRIVE GEOMETRY");
1703 Initialize the Background Initialization Status.
1705 if ((Controller->FirmwareVersion[0] == '4' &&
1706 strcmp(Controller->FirmwareVersion, "4.08") >= 0) ||
1707 (Controller->FirmwareVersion[0] == '5' &&
1708 strcmp(Controller->FirmwareVersion, "5.08") >= 0))
1710 Controller->V1.BackgroundInitializationStatusSupported = true;
1711 DAC960_V1_ExecuteType3B(Controller,
1712 DAC960_V1_BackgroundInitializationControl, 0x20,
1713 Controller->
1714 V1.BackgroundInitializationStatusDMA);
1715 memcpy(&Controller->V1.LastBackgroundInitializationStatus,
1716 Controller->V1.BackgroundInitializationStatus,
1717 sizeof(DAC960_V1_BackgroundInitializationStatus_T));
1720 Initialize the Logical Drive Initially Accessible flag.
1722 for (LogicalDriveNumber = 0;
1723 LogicalDriveNumber < Controller->LogicalDriveCount;
1724 LogicalDriveNumber++)
1725 if (Controller->V1.LogicalDriveInformation
1726 [LogicalDriveNumber].LogicalDriveState !=
1727 DAC960_V1_LogicalDrive_Offline)
1728 Controller->LogicalDriveInitiallyAccessible[LogicalDriveNumber] = true;
1729 Controller->V1.LastRebuildStatus = DAC960_V1_NoRebuildOrCheckInProgress;
1730 free_dma_loaf(Controller->PCIDevice, &local_dma);
1731 return true;
1736 DAC960_V2_ReadControllerConfiguration reads the Configuration Information
1737 from DAC960 V2 Firmware Controllers and initializes the Controller structure.
1740 static boolean DAC960_V2_ReadControllerConfiguration(DAC960_Controller_T
1741 *Controller)
1743 DAC960_V2_ControllerInfo_T *ControllerInfo =
1744 &Controller->V2.ControllerInformation;
1745 unsigned short LogicalDeviceNumber = 0;
1746 int ModelNameLength;
1748 /* Get data into dma-able area, then copy into permanant location */
1749 if (!DAC960_V2_NewControllerInfo(Controller))
1750 return DAC960_Failure(Controller, "GET CONTROLLER INFO");
1751 memcpy(ControllerInfo, Controller->V2.NewControllerInformation,
1752 sizeof(DAC960_V2_ControllerInfo_T));
1755 if (!DAC960_V2_GeneralInfo(Controller))
1756 return DAC960_Failure(Controller, "GET HEALTH STATUS");
1759 Initialize the Controller Model Name and Full Model Name fields.
1761 ModelNameLength = sizeof(ControllerInfo->ControllerName);
1762 if (ModelNameLength > sizeof(Controller->ModelName)-1)
1763 ModelNameLength = sizeof(Controller->ModelName)-1;
1764 memcpy(Controller->ModelName, ControllerInfo->ControllerName,
1765 ModelNameLength);
1766 ModelNameLength--;
1767 while (Controller->ModelName[ModelNameLength] == ' ' ||
1768 Controller->ModelName[ModelNameLength] == '\0')
1769 ModelNameLength--;
1770 Controller->ModelName[++ModelNameLength] = '\0';
1771 strcpy(Controller->FullModelName, "Mylex ");
1772 strcat(Controller->FullModelName, Controller->ModelName);
1774 Initialize the Controller Firmware Version field.
1776 sprintf(Controller->FirmwareVersion, "%d.%02d-%02d",
1777 ControllerInfo->FirmwareMajorVersion,
1778 ControllerInfo->FirmwareMinorVersion,
1779 ControllerInfo->FirmwareTurnNumber);
1780 if (ControllerInfo->FirmwareMajorVersion == 6 &&
1781 ControllerInfo->FirmwareMinorVersion == 0 &&
1782 ControllerInfo->FirmwareTurnNumber < 1)
1784 DAC960_Info("FIRMWARE VERSION %s DOES NOT PROVIDE THE CONTROLLER\n",
1785 Controller, Controller->FirmwareVersion);
1786 DAC960_Info("STATUS MONITORING FUNCTIONALITY NEEDED BY THIS DRIVER.\n",
1787 Controller);
1788 DAC960_Info("PLEASE UPGRADE TO VERSION 6.00-01 OR ABOVE.\n",
1789 Controller);
1792 Initialize the Controller Channels, Targets, and Memory Size.
1794 Controller->Channels = ControllerInfo->NumberOfPhysicalChannelsPresent;
1795 Controller->Targets =
1796 ControllerInfo->MaximumTargetsPerChannel
1797 [ControllerInfo->NumberOfPhysicalChannelsPresent-1];
1798 Controller->MemorySize = ControllerInfo->MemorySizeMB;
1800 Initialize the Controller Queue Depth, Driver Queue Depth, Logical Drive
1801 Count, Maximum Blocks per Command, Controller Scatter/Gather Limit, and
1802 Driver Scatter/Gather Limit. The Driver Queue Depth must be at most one
1803 less than the Controller Queue Depth to allow for an automatic drive
1804 rebuild operation.
1806 Controller->ControllerQueueDepth = ControllerInfo->MaximumParallelCommands;
1807 Controller->DriverQueueDepth = Controller->ControllerQueueDepth - 1;
1808 if (Controller->DriverQueueDepth > DAC960_MaxDriverQueueDepth)
1809 Controller->DriverQueueDepth = DAC960_MaxDriverQueueDepth;
1810 Controller->LogicalDriveCount = ControllerInfo->LogicalDevicesPresent;
1811 Controller->MaxBlocksPerCommand =
1812 ControllerInfo->MaximumDataTransferSizeInBlocks;
1813 Controller->ControllerScatterGatherLimit =
1814 ControllerInfo->MaximumScatterGatherEntries;
1815 Controller->DriverScatterGatherLimit =
1816 Controller->ControllerScatterGatherLimit;
1817 if (Controller->DriverScatterGatherLimit > DAC960_V2_ScatterGatherLimit)
1818 Controller->DriverScatterGatherLimit = DAC960_V2_ScatterGatherLimit;
1820 Initialize the Logical Device Information.
1822 while (true)
1824 DAC960_V2_LogicalDeviceInfo_T *NewLogicalDeviceInfo =
1825 Controller->V2.NewLogicalDeviceInformation;
1826 DAC960_V2_LogicalDeviceInfo_T *LogicalDeviceInfo;
1827 DAC960_V2_PhysicalDevice_T PhysicalDevice;
1829 if (!DAC960_V2_NewLogicalDeviceInfo(Controller, LogicalDeviceNumber))
1830 break;
1831 LogicalDeviceNumber = NewLogicalDeviceInfo->LogicalDeviceNumber;
1832 if (LogicalDeviceNumber >= DAC960_MaxLogicalDrives) {
1833 DAC960_Error("DAC960: Logical Drive Number %d not supported\n",
1834 Controller, LogicalDeviceNumber);
1835 break;
1837 if (NewLogicalDeviceInfo->DeviceBlockSizeInBytes != DAC960_BlockSize) {
1838 DAC960_Error("DAC960: Logical Drive Block Size %d not supported\n",
1839 Controller, NewLogicalDeviceInfo->DeviceBlockSizeInBytes);
1840 LogicalDeviceNumber++;
1841 continue;
1843 PhysicalDevice.Controller = 0;
1844 PhysicalDevice.Channel = NewLogicalDeviceInfo->Channel;
1845 PhysicalDevice.TargetID = NewLogicalDeviceInfo->TargetID;
1846 PhysicalDevice.LogicalUnit = NewLogicalDeviceInfo->LogicalUnit;
1847 Controller->V2.LogicalDriveToVirtualDevice[LogicalDeviceNumber] =
1848 PhysicalDevice;
1849 if (NewLogicalDeviceInfo->LogicalDeviceState !=
1850 DAC960_V2_LogicalDevice_Offline)
1851 Controller->LogicalDriveInitiallyAccessible[LogicalDeviceNumber] = true;
1852 LogicalDeviceInfo = (DAC960_V2_LogicalDeviceInfo_T *)
1853 kmalloc(sizeof(DAC960_V2_LogicalDeviceInfo_T), GFP_ATOMIC);
1854 if (LogicalDeviceInfo == NULL)
1855 return DAC960_Failure(Controller, "LOGICAL DEVICE ALLOCATION");
1856 Controller->V2.LogicalDeviceInformation[LogicalDeviceNumber] =
1857 LogicalDeviceInfo;
1858 memcpy(LogicalDeviceInfo, NewLogicalDeviceInfo,
1859 sizeof(DAC960_V2_LogicalDeviceInfo_T));
1860 LogicalDeviceNumber++;
1862 return true;
1867 DAC960_ReportControllerConfiguration reports the Configuration Information
1868 for Controller.
1871 static boolean DAC960_ReportControllerConfiguration(DAC960_Controller_T
1872 *Controller)
1874 DAC960_Info("Configuring Mylex %s PCI RAID Controller\n",
1875 Controller, Controller->ModelName);
1876 DAC960_Info(" Firmware Version: %s, Channels: %d, Memory Size: %dMB\n",
1877 Controller, Controller->FirmwareVersion,
1878 Controller->Channels, Controller->MemorySize);
1879 DAC960_Info(" PCI Bus: %d, Device: %d, Function: %d, I/O Address: ",
1880 Controller, Controller->Bus,
1881 Controller->Device, Controller->Function);
1882 if (Controller->IO_Address == 0)
1883 DAC960_Info("Unassigned\n", Controller);
1884 else DAC960_Info("0x%X\n", Controller, Controller->IO_Address);
1885 DAC960_Info(" PCI Address: 0x%X mapped at 0x%lX, IRQ Channel: %d\n",
1886 Controller, Controller->PCI_Address,
1887 (unsigned long) Controller->BaseAddress,
1888 Controller->IRQ_Channel);
1889 DAC960_Info(" Controller Queue Depth: %d, "
1890 "Maximum Blocks per Command: %d\n",
1891 Controller, Controller->ControllerQueueDepth,
1892 Controller->MaxBlocksPerCommand);
1893 DAC960_Info(" Driver Queue Depth: %d, "
1894 "Scatter/Gather Limit: %d of %d Segments\n",
1895 Controller, Controller->DriverQueueDepth,
1896 Controller->DriverScatterGatherLimit,
1897 Controller->ControllerScatterGatherLimit);
1898 if (Controller->FirmwareType == DAC960_V1_Controller)
1900 DAC960_Info(" Stripe Size: %dKB, Segment Size: %dKB, "
1901 "BIOS Geometry: %d/%d\n", Controller,
1902 Controller->V1.StripeSize,
1903 Controller->V1.SegmentSize,
1904 Controller->V1.GeometryTranslationHeads,
1905 Controller->V1.GeometryTranslationSectors);
1906 if (Controller->V1.SAFTE_EnclosureManagementEnabled)
1907 DAC960_Info(" SAF-TE Enclosure Management Enabled\n", Controller);
1909 return true;
1914 DAC960_V1_ReadDeviceConfiguration reads the Device Configuration Information
1915 for DAC960 V1 Firmware Controllers by requesting the SCSI Inquiry and SCSI
1916 Inquiry Unit Serial Number information for each device connected to
1917 Controller.
1920 static boolean DAC960_V1_ReadDeviceConfiguration(DAC960_Controller_T
1921 *Controller)
1923 struct dma_loaf local_dma;
1925 dma_addr_t DCDBs_dma[DAC960_V1_MaxChannels];
1926 DAC960_V1_DCDB_T *DCDBs_cpu[DAC960_V1_MaxChannels];
1928 dma_addr_t SCSI_Inquiry_dma[DAC960_V1_MaxChannels];
1929 DAC960_SCSI_Inquiry_T *SCSI_Inquiry_cpu[DAC960_V1_MaxChannels];
1931 dma_addr_t SCSI_NewInquiryUnitSerialNumberDMA[DAC960_V1_MaxChannels];
1932 DAC960_SCSI_Inquiry_UnitSerialNumber_T *SCSI_NewInquiryUnitSerialNumberCPU[DAC960_V1_MaxChannels];
1934 struct completion Completions[DAC960_V1_MaxChannels];
1935 unsigned long flags;
1936 int Channel, TargetID;
1938 if (!init_dma_loaf(Controller->PCIDevice, &local_dma,
1939 DAC960_V1_MaxChannels*(sizeof(DAC960_V1_DCDB_T) +
1940 sizeof(DAC960_SCSI_Inquiry_T) +
1941 sizeof(DAC960_SCSI_Inquiry_UnitSerialNumber_T))))
1942 return DAC960_Failure(Controller,
1943 "DMA ALLOCATION FAILED IN ReadDeviceConfiguration");
1945 for (Channel = 0; Channel < Controller->Channels; Channel++) {
1946 DCDBs_cpu[Channel] = slice_dma_loaf(&local_dma,
1947 sizeof(DAC960_V1_DCDB_T), DCDBs_dma + Channel);
1948 SCSI_Inquiry_cpu[Channel] = slice_dma_loaf(&local_dma,
1949 sizeof(DAC960_SCSI_Inquiry_T),
1950 SCSI_Inquiry_dma + Channel);
1951 SCSI_NewInquiryUnitSerialNumberCPU[Channel] = slice_dma_loaf(&local_dma,
1952 sizeof(DAC960_SCSI_Inquiry_UnitSerialNumber_T),
1953 SCSI_NewInquiryUnitSerialNumberDMA + Channel);
1956 for (TargetID = 0; TargetID < Controller->Targets; TargetID++)
1959 * For each channel, submit a probe for a device on that channel.
1960 * The timeout interval for a device that is present is 10 seconds.
1961 * With this approach, the timeout periods can elapse in parallel
1962 * on each channel.
1964 for (Channel = 0; Channel < Controller->Channels; Channel++)
1966 dma_addr_t NewInquiryStandardDataDMA = SCSI_Inquiry_dma[Channel];
1967 DAC960_V1_DCDB_T *DCDB = DCDBs_cpu[Channel];
1968 dma_addr_t DCDB_dma = DCDBs_dma[Channel];
1969 DAC960_Command_T *Command = Controller->Commands[Channel];
1970 struct completion *Completion = &Completions[Channel];
1972 init_completion(Completion);
1973 DAC960_V1_ClearCommand(Command);
1974 Command->CommandType = DAC960_ImmediateCommand;
1975 Command->Completion = Completion;
1976 Command->V1.CommandMailbox.Type3.CommandOpcode = DAC960_V1_DCDB;
1977 Command->V1.CommandMailbox.Type3.BusAddress = DCDB_dma;
1978 DCDB->Channel = Channel;
1979 DCDB->TargetID = TargetID;
1980 DCDB->Direction = DAC960_V1_DCDB_DataTransferDeviceToSystem;
1981 DCDB->EarlyStatus = false;
1982 DCDB->Timeout = DAC960_V1_DCDB_Timeout_10_seconds;
1983 DCDB->NoAutomaticRequestSense = false;
1984 DCDB->DisconnectPermitted = true;
1985 DCDB->TransferLength = sizeof(DAC960_SCSI_Inquiry_T);
1986 DCDB->BusAddress = NewInquiryStandardDataDMA;
1987 DCDB->CDBLength = 6;
1988 DCDB->TransferLengthHigh4 = 0;
1989 DCDB->SenseLength = sizeof(DCDB->SenseData);
1990 DCDB->CDB[0] = 0x12; /* INQUIRY */
1991 DCDB->CDB[1] = 0; /* EVPD = 0 */
1992 DCDB->CDB[2] = 0; /* Page Code */
1993 DCDB->CDB[3] = 0; /* Reserved */
1994 DCDB->CDB[4] = sizeof(DAC960_SCSI_Inquiry_T);
1995 DCDB->CDB[5] = 0; /* Control */
1997 spin_lock_irqsave(&Controller->queue_lock, flags);
1998 DAC960_QueueCommand(Command);
1999 spin_unlock_irqrestore(&Controller->queue_lock, flags);
2002 * Wait for the problems submitted in the previous loop
2003 * to complete. On the probes that are successful,
2004 * get the serial number of the device that was found.
2006 for (Channel = 0; Channel < Controller->Channels; Channel++)
2008 DAC960_SCSI_Inquiry_T *InquiryStandardData =
2009 &Controller->V1.InquiryStandardData[Channel][TargetID];
2010 DAC960_SCSI_Inquiry_T *NewInquiryStandardData = SCSI_Inquiry_cpu[Channel];
2011 dma_addr_t NewInquiryUnitSerialNumberDMA =
2012 SCSI_NewInquiryUnitSerialNumberDMA[Channel];
2013 DAC960_SCSI_Inquiry_UnitSerialNumber_T *NewInquiryUnitSerialNumber =
2014 SCSI_NewInquiryUnitSerialNumberCPU[Channel];
2015 DAC960_SCSI_Inquiry_UnitSerialNumber_T *InquiryUnitSerialNumber =
2016 &Controller->V1.InquiryUnitSerialNumber[Channel][TargetID];
2017 DAC960_Command_T *Command = Controller->Commands[Channel];
2018 DAC960_V1_DCDB_T *DCDB = DCDBs_cpu[Channel];
2019 struct completion *Completion = &Completions[Channel];
2021 wait_for_completion(Completion);
2023 if (Command->V1.CommandStatus != DAC960_V1_NormalCompletion) {
2024 memset(InquiryStandardData, 0, sizeof(DAC960_SCSI_Inquiry_T));
2025 InquiryStandardData->PeripheralDeviceType = 0x1F;
2026 continue;
2027 } else
2028 memcpy(InquiryStandardData, NewInquiryStandardData, sizeof(DAC960_SCSI_Inquiry_T));
2030 /* Preserve Channel and TargetID values from the previous loop */
2031 Command->Completion = Completion;
2032 DCDB->TransferLength = sizeof(DAC960_SCSI_Inquiry_UnitSerialNumber_T);
2033 DCDB->BusAddress = NewInquiryUnitSerialNumberDMA;
2034 DCDB->SenseLength = sizeof(DCDB->SenseData);
2035 DCDB->CDB[0] = 0x12; /* INQUIRY */
2036 DCDB->CDB[1] = 1; /* EVPD = 1 */
2037 DCDB->CDB[2] = 0x80; /* Page Code */
2038 DCDB->CDB[3] = 0; /* Reserved */
2039 DCDB->CDB[4] = sizeof(DAC960_SCSI_Inquiry_UnitSerialNumber_T);
2040 DCDB->CDB[5] = 0; /* Control */
2042 spin_lock_irqsave(&Controller->queue_lock, flags);
2043 DAC960_QueueCommand(Command);
2044 spin_unlock_irqrestore(&Controller->queue_lock, flags);
2045 wait_for_completion(Completion);
2047 if (Command->V1.CommandStatus != DAC960_V1_NormalCompletion) {
2048 memset(InquiryUnitSerialNumber, 0,
2049 sizeof(DAC960_SCSI_Inquiry_UnitSerialNumber_T));
2050 InquiryUnitSerialNumber->PeripheralDeviceType = 0x1F;
2051 } else
2052 memcpy(InquiryUnitSerialNumber, NewInquiryUnitSerialNumber,
2053 sizeof(DAC960_SCSI_Inquiry_UnitSerialNumber_T));
2056 free_dma_loaf(Controller->PCIDevice, &local_dma);
2057 return true;
2062 DAC960_V2_ReadDeviceConfiguration reads the Device Configuration Information
2063 for DAC960 V2 Firmware Controllers by requesting the Physical Device
2064 Information and SCSI Inquiry Unit Serial Number information for each
2065 device connected to Controller.
2068 static boolean DAC960_V2_ReadDeviceConfiguration(DAC960_Controller_T
2069 *Controller)
2071 unsigned char Channel = 0, TargetID = 0, LogicalUnit = 0;
2072 unsigned short PhysicalDeviceIndex = 0;
2074 while (true)
2076 DAC960_V2_PhysicalDeviceInfo_T *NewPhysicalDeviceInfo =
2077 Controller->V2.NewPhysicalDeviceInformation;
2078 DAC960_V2_PhysicalDeviceInfo_T *PhysicalDeviceInfo;
2079 DAC960_SCSI_Inquiry_UnitSerialNumber_T *NewInquiryUnitSerialNumber =
2080 Controller->V2.NewInquiryUnitSerialNumber;
2081 DAC960_SCSI_Inquiry_UnitSerialNumber_T *InquiryUnitSerialNumber;
2083 if (!DAC960_V2_NewPhysicalDeviceInfo(Controller, Channel, TargetID, LogicalUnit))
2084 break;
2086 PhysicalDeviceInfo = (DAC960_V2_PhysicalDeviceInfo_T *)
2087 kmalloc(sizeof(DAC960_V2_PhysicalDeviceInfo_T), GFP_ATOMIC);
2088 if (PhysicalDeviceInfo == NULL)
2089 return DAC960_Failure(Controller, "PHYSICAL DEVICE ALLOCATION");
2090 Controller->V2.PhysicalDeviceInformation[PhysicalDeviceIndex] =
2091 PhysicalDeviceInfo;
2092 memcpy(PhysicalDeviceInfo, NewPhysicalDeviceInfo,
2093 sizeof(DAC960_V2_PhysicalDeviceInfo_T));
2095 InquiryUnitSerialNumber = (DAC960_SCSI_Inquiry_UnitSerialNumber_T *)
2096 kmalloc(sizeof(DAC960_SCSI_Inquiry_UnitSerialNumber_T), GFP_ATOMIC);
2097 if (InquiryUnitSerialNumber == NULL) {
2098 kfree(PhysicalDeviceInfo);
2099 return DAC960_Failure(Controller, "SERIAL NUMBER ALLOCATION");
2101 Controller->V2.InquiryUnitSerialNumber[PhysicalDeviceIndex] =
2102 InquiryUnitSerialNumber;
2104 Channel = NewPhysicalDeviceInfo->Channel;
2105 TargetID = NewPhysicalDeviceInfo->TargetID;
2106 LogicalUnit = NewPhysicalDeviceInfo->LogicalUnit;
2109 Some devices do NOT have Unit Serial Numbers.
2110 This command fails for them. But, we still want to
2111 remember those devices are there. Construct a
2112 UnitSerialNumber structure for the failure case.
2114 if (!DAC960_V2_NewInquiryUnitSerialNumber(Controller, Channel, TargetID, LogicalUnit)) {
2115 memset(InquiryUnitSerialNumber, 0,
2116 sizeof(DAC960_SCSI_Inquiry_UnitSerialNumber_T));
2117 InquiryUnitSerialNumber->PeripheralDeviceType = 0x1F;
2118 } else
2119 memcpy(InquiryUnitSerialNumber, NewInquiryUnitSerialNumber,
2120 sizeof(DAC960_SCSI_Inquiry_UnitSerialNumber_T));
2122 PhysicalDeviceIndex++;
2123 LogicalUnit++;
2125 return true;
2130 DAC960_SanitizeInquiryData sanitizes the Vendor, Model, Revision, and
2131 Product Serial Number fields of the Inquiry Standard Data and Inquiry
2132 Unit Serial Number structures.
2135 static void DAC960_SanitizeInquiryData(DAC960_SCSI_Inquiry_T
2136 *InquiryStandardData,
2137 DAC960_SCSI_Inquiry_UnitSerialNumber_T
2138 *InquiryUnitSerialNumber,
2139 unsigned char *Vendor,
2140 unsigned char *Model,
2141 unsigned char *Revision,
2142 unsigned char *SerialNumber)
2144 int SerialNumberLength, i;
2145 if (InquiryStandardData->PeripheralDeviceType == 0x1F) return;
2146 for (i = 0; i < sizeof(InquiryStandardData->VendorIdentification); i++)
2148 unsigned char VendorCharacter =
2149 InquiryStandardData->VendorIdentification[i];
2150 Vendor[i] = (VendorCharacter >= ' ' && VendorCharacter <= '~'
2151 ? VendorCharacter : ' ');
2153 Vendor[sizeof(InquiryStandardData->VendorIdentification)] = '\0';
2154 for (i = 0; i < sizeof(InquiryStandardData->ProductIdentification); i++)
2156 unsigned char ModelCharacter =
2157 InquiryStandardData->ProductIdentification[i];
2158 Model[i] = (ModelCharacter >= ' ' && ModelCharacter <= '~'
2159 ? ModelCharacter : ' ');
2161 Model[sizeof(InquiryStandardData->ProductIdentification)] = '\0';
2162 for (i = 0; i < sizeof(InquiryStandardData->ProductRevisionLevel); i++)
2164 unsigned char RevisionCharacter =
2165 InquiryStandardData->ProductRevisionLevel[i];
2166 Revision[i] = (RevisionCharacter >= ' ' && RevisionCharacter <= '~'
2167 ? RevisionCharacter : ' ');
2169 Revision[sizeof(InquiryStandardData->ProductRevisionLevel)] = '\0';
2170 if (InquiryUnitSerialNumber->PeripheralDeviceType == 0x1F) return;
2171 SerialNumberLength = InquiryUnitSerialNumber->PageLength;
2172 if (SerialNumberLength >
2173 sizeof(InquiryUnitSerialNumber->ProductSerialNumber))
2174 SerialNumberLength = sizeof(InquiryUnitSerialNumber->ProductSerialNumber);
2175 for (i = 0; i < SerialNumberLength; i++)
2177 unsigned char SerialNumberCharacter =
2178 InquiryUnitSerialNumber->ProductSerialNumber[i];
2179 SerialNumber[i] =
2180 (SerialNumberCharacter >= ' ' && SerialNumberCharacter <= '~'
2181 ? SerialNumberCharacter : ' ');
2183 SerialNumber[SerialNumberLength] = '\0';
2188 DAC960_V1_ReportDeviceConfiguration reports the Device Configuration
2189 Information for DAC960 V1 Firmware Controllers.
2192 static boolean DAC960_V1_ReportDeviceConfiguration(DAC960_Controller_T
2193 *Controller)
2195 int LogicalDriveNumber, Channel, TargetID;
2196 DAC960_Info(" Physical Devices:\n", Controller);
2197 for (Channel = 0; Channel < Controller->Channels; Channel++)
2198 for (TargetID = 0; TargetID < Controller->Targets; TargetID++)
2200 DAC960_SCSI_Inquiry_T *InquiryStandardData =
2201 &Controller->V1.InquiryStandardData[Channel][TargetID];
2202 DAC960_SCSI_Inquiry_UnitSerialNumber_T *InquiryUnitSerialNumber =
2203 &Controller->V1.InquiryUnitSerialNumber[Channel][TargetID];
2204 DAC960_V1_DeviceState_T *DeviceState =
2205 &Controller->V1.DeviceState[Channel][TargetID];
2206 DAC960_V1_ErrorTableEntry_T *ErrorEntry =
2207 &Controller->V1.ErrorTable.ErrorTableEntries[Channel][TargetID];
2208 char Vendor[1+sizeof(InquiryStandardData->VendorIdentification)];
2209 char Model[1+sizeof(InquiryStandardData->ProductIdentification)];
2210 char Revision[1+sizeof(InquiryStandardData->ProductRevisionLevel)];
2211 char SerialNumber[1+sizeof(InquiryUnitSerialNumber
2212 ->ProductSerialNumber)];
2213 if (InquiryStandardData->PeripheralDeviceType == 0x1F) continue;
2214 DAC960_SanitizeInquiryData(InquiryStandardData, InquiryUnitSerialNumber,
2215 Vendor, Model, Revision, SerialNumber);
2216 DAC960_Info(" %d:%d%s Vendor: %s Model: %s Revision: %s\n",
2217 Controller, Channel, TargetID, (TargetID < 10 ? " " : ""),
2218 Vendor, Model, Revision);
2219 if (InquiryUnitSerialNumber->PeripheralDeviceType != 0x1F)
2220 DAC960_Info(" Serial Number: %s\n", Controller, SerialNumber);
2221 if (DeviceState->Present &&
2222 DeviceState->DeviceType == DAC960_V1_DiskType)
2224 if (Controller->V1.DeviceResetCount[Channel][TargetID] > 0)
2225 DAC960_Info(" Disk Status: %s, %u blocks, %d resets\n",
2226 Controller,
2227 (DeviceState->DeviceState == DAC960_V1_Device_Dead
2228 ? "Dead"
2229 : DeviceState->DeviceState
2230 == DAC960_V1_Device_WriteOnly
2231 ? "Write-Only"
2232 : DeviceState->DeviceState
2233 == DAC960_V1_Device_Online
2234 ? "Online" : "Standby"),
2235 DeviceState->DiskSize,
2236 Controller->V1.DeviceResetCount[Channel][TargetID]);
2237 else
2238 DAC960_Info(" Disk Status: %s, %u blocks\n", Controller,
2239 (DeviceState->DeviceState == DAC960_V1_Device_Dead
2240 ? "Dead"
2241 : DeviceState->DeviceState
2242 == DAC960_V1_Device_WriteOnly
2243 ? "Write-Only"
2244 : DeviceState->DeviceState
2245 == DAC960_V1_Device_Online
2246 ? "Online" : "Standby"),
2247 DeviceState->DiskSize);
2249 if (ErrorEntry->ParityErrorCount > 0 ||
2250 ErrorEntry->SoftErrorCount > 0 ||
2251 ErrorEntry->HardErrorCount > 0 ||
2252 ErrorEntry->MiscErrorCount > 0)
2253 DAC960_Info(" Errors - Parity: %d, Soft: %d, "
2254 "Hard: %d, Misc: %d\n", Controller,
2255 ErrorEntry->ParityErrorCount,
2256 ErrorEntry->SoftErrorCount,
2257 ErrorEntry->HardErrorCount,
2258 ErrorEntry->MiscErrorCount);
2260 DAC960_Info(" Logical Drives:\n", Controller);
2261 for (LogicalDriveNumber = 0;
2262 LogicalDriveNumber < Controller->LogicalDriveCount;
2263 LogicalDriveNumber++)
2265 DAC960_V1_LogicalDriveInformation_T *LogicalDriveInformation =
2266 &Controller->V1.LogicalDriveInformation[LogicalDriveNumber];
2267 DAC960_Info(" /dev/rd/c%dd%d: RAID-%d, %s, %u blocks, %s\n",
2268 Controller, Controller->ControllerNumber, LogicalDriveNumber,
2269 LogicalDriveInformation->RAIDLevel,
2270 (LogicalDriveInformation->LogicalDriveState
2271 == DAC960_V1_LogicalDrive_Online
2272 ? "Online"
2273 : LogicalDriveInformation->LogicalDriveState
2274 == DAC960_V1_LogicalDrive_Critical
2275 ? "Critical" : "Offline"),
2276 LogicalDriveInformation->LogicalDriveSize,
2277 (LogicalDriveInformation->WriteBack
2278 ? "Write Back" : "Write Thru"));
2280 return true;
2285 DAC960_V2_ReportDeviceConfiguration reports the Device Configuration
2286 Information for DAC960 V2 Firmware Controllers.
2289 static boolean DAC960_V2_ReportDeviceConfiguration(DAC960_Controller_T
2290 *Controller)
2292 int PhysicalDeviceIndex, LogicalDriveNumber;
2293 DAC960_Info(" Physical Devices:\n", Controller);
2294 for (PhysicalDeviceIndex = 0;
2295 PhysicalDeviceIndex < DAC960_V2_MaxPhysicalDevices;
2296 PhysicalDeviceIndex++)
2298 DAC960_V2_PhysicalDeviceInfo_T *PhysicalDeviceInfo =
2299 Controller->V2.PhysicalDeviceInformation[PhysicalDeviceIndex];
2300 DAC960_SCSI_Inquiry_T *InquiryStandardData =
2301 (DAC960_SCSI_Inquiry_T *) &PhysicalDeviceInfo->SCSI_InquiryData;
2302 DAC960_SCSI_Inquiry_UnitSerialNumber_T *InquiryUnitSerialNumber =
2303 Controller->V2.InquiryUnitSerialNumber[PhysicalDeviceIndex];
2304 char Vendor[1+sizeof(InquiryStandardData->VendorIdentification)];
2305 char Model[1+sizeof(InquiryStandardData->ProductIdentification)];
2306 char Revision[1+sizeof(InquiryStandardData->ProductRevisionLevel)];
2307 char SerialNumber[1+sizeof(InquiryUnitSerialNumber->ProductSerialNumber)];
2308 if (PhysicalDeviceInfo == NULL) break;
2309 DAC960_SanitizeInquiryData(InquiryStandardData, InquiryUnitSerialNumber,
2310 Vendor, Model, Revision, SerialNumber);
2311 DAC960_Info(" %d:%d%s Vendor: %s Model: %s Revision: %s\n",
2312 Controller,
2313 PhysicalDeviceInfo->Channel,
2314 PhysicalDeviceInfo->TargetID,
2315 (PhysicalDeviceInfo->TargetID < 10 ? " " : ""),
2316 Vendor, Model, Revision);
2317 if (PhysicalDeviceInfo->NegotiatedSynchronousMegaTransfers == 0)
2318 DAC960_Info(" %sAsynchronous\n", Controller,
2319 (PhysicalDeviceInfo->NegotiatedDataWidthBits == 16
2320 ? "Wide " :""));
2321 else
2322 DAC960_Info(" %sSynchronous at %d MB/sec\n", Controller,
2323 (PhysicalDeviceInfo->NegotiatedDataWidthBits == 16
2324 ? "Wide " :""),
2325 (PhysicalDeviceInfo->NegotiatedSynchronousMegaTransfers
2326 * PhysicalDeviceInfo->NegotiatedDataWidthBits/8));
2327 if (InquiryUnitSerialNumber->PeripheralDeviceType != 0x1F)
2328 DAC960_Info(" Serial Number: %s\n", Controller, SerialNumber);
2329 if (PhysicalDeviceInfo->PhysicalDeviceState ==
2330 DAC960_V2_Device_Unconfigured)
2331 continue;
2332 DAC960_Info(" Disk Status: %s, %u blocks\n", Controller,
2333 (PhysicalDeviceInfo->PhysicalDeviceState
2334 == DAC960_V2_Device_Online
2335 ? "Online"
2336 : PhysicalDeviceInfo->PhysicalDeviceState
2337 == DAC960_V2_Device_Rebuild
2338 ? "Rebuild"
2339 : PhysicalDeviceInfo->PhysicalDeviceState
2340 == DAC960_V2_Device_Missing
2341 ? "Missing"
2342 : PhysicalDeviceInfo->PhysicalDeviceState
2343 == DAC960_V2_Device_Critical
2344 ? "Critical"
2345 : PhysicalDeviceInfo->PhysicalDeviceState
2346 == DAC960_V2_Device_Dead
2347 ? "Dead"
2348 : PhysicalDeviceInfo->PhysicalDeviceState
2349 == DAC960_V2_Device_SuspectedDead
2350 ? "Suspected-Dead"
2351 : PhysicalDeviceInfo->PhysicalDeviceState
2352 == DAC960_V2_Device_CommandedOffline
2353 ? "Commanded-Offline"
2354 : PhysicalDeviceInfo->PhysicalDeviceState
2355 == DAC960_V2_Device_Standby
2356 ? "Standby" : "Unknown"),
2357 PhysicalDeviceInfo->ConfigurableDeviceSize);
2358 if (PhysicalDeviceInfo->ParityErrors == 0 &&
2359 PhysicalDeviceInfo->SoftErrors == 0 &&
2360 PhysicalDeviceInfo->HardErrors == 0 &&
2361 PhysicalDeviceInfo->MiscellaneousErrors == 0 &&
2362 PhysicalDeviceInfo->CommandTimeouts == 0 &&
2363 PhysicalDeviceInfo->Retries == 0 &&
2364 PhysicalDeviceInfo->Aborts == 0 &&
2365 PhysicalDeviceInfo->PredictedFailuresDetected == 0)
2366 continue;
2367 DAC960_Info(" Errors - Parity: %d, Soft: %d, "
2368 "Hard: %d, Misc: %d\n", Controller,
2369 PhysicalDeviceInfo->ParityErrors,
2370 PhysicalDeviceInfo->SoftErrors,
2371 PhysicalDeviceInfo->HardErrors,
2372 PhysicalDeviceInfo->MiscellaneousErrors);
2373 DAC960_Info(" Timeouts: %d, Retries: %d, "
2374 "Aborts: %d, Predicted: %d\n", Controller,
2375 PhysicalDeviceInfo->CommandTimeouts,
2376 PhysicalDeviceInfo->Retries,
2377 PhysicalDeviceInfo->Aborts,
2378 PhysicalDeviceInfo->PredictedFailuresDetected);
2380 DAC960_Info(" Logical Drives:\n", Controller);
2381 for (LogicalDriveNumber = 0;
2382 LogicalDriveNumber < DAC960_MaxLogicalDrives;
2383 LogicalDriveNumber++)
2385 DAC960_V2_LogicalDeviceInfo_T *LogicalDeviceInfo =
2386 Controller->V2.LogicalDeviceInformation[LogicalDriveNumber];
2387 unsigned char *ReadCacheStatus[] = { "Read Cache Disabled",
2388 "Read Cache Enabled",
2389 "Read Ahead Enabled",
2390 "Intelligent Read Ahead Enabled",
2391 "-", "-", "-", "-" };
2392 unsigned char *WriteCacheStatus[] = { "Write Cache Disabled",
2393 "Logical Device Read Only",
2394 "Write Cache Enabled",
2395 "Intelligent Write Cache Enabled",
2396 "-", "-", "-", "-" };
2397 unsigned char *GeometryTranslation;
2398 if (LogicalDeviceInfo == NULL) continue;
2399 switch (LogicalDeviceInfo->DriveGeometry)
2401 case DAC960_V2_Geometry_128_32:
2402 GeometryTranslation = "128/32";
2403 break;
2404 case DAC960_V2_Geometry_255_63:
2405 GeometryTranslation = "255/63";
2406 break;
2407 default:
2408 GeometryTranslation = "Invalid";
2409 DAC960_Error("Illegal Logical Device Geometry %d\n",
2410 Controller, LogicalDeviceInfo->DriveGeometry);
2411 break;
2413 DAC960_Info(" /dev/rd/c%dd%d: RAID-%d, %s, %u blocks\n",
2414 Controller, Controller->ControllerNumber, LogicalDriveNumber,
2415 LogicalDeviceInfo->RAIDLevel,
2416 (LogicalDeviceInfo->LogicalDeviceState
2417 == DAC960_V2_LogicalDevice_Online
2418 ? "Online"
2419 : LogicalDeviceInfo->LogicalDeviceState
2420 == DAC960_V2_LogicalDevice_Critical
2421 ? "Critical" : "Offline"),
2422 LogicalDeviceInfo->ConfigurableDeviceSize);
2423 DAC960_Info(" Logical Device %s, BIOS Geometry: %s\n",
2424 Controller,
2425 (LogicalDeviceInfo->LogicalDeviceControl
2426 .LogicalDeviceInitialized
2427 ? "Initialized" : "Uninitialized"),
2428 GeometryTranslation);
2429 if (LogicalDeviceInfo->StripeSize == 0)
2431 if (LogicalDeviceInfo->CacheLineSize == 0)
2432 DAC960_Info(" Stripe Size: N/A, "
2433 "Segment Size: N/A\n", Controller);
2434 else
2435 DAC960_Info(" Stripe Size: N/A, "
2436 "Segment Size: %dKB\n", Controller,
2437 1 << (LogicalDeviceInfo->CacheLineSize - 2));
2439 else
2441 if (LogicalDeviceInfo->CacheLineSize == 0)
2442 DAC960_Info(" Stripe Size: %dKB, "
2443 "Segment Size: N/A\n", Controller,
2444 1 << (LogicalDeviceInfo->StripeSize - 2));
2445 else
2446 DAC960_Info(" Stripe Size: %dKB, "
2447 "Segment Size: %dKB\n", Controller,
2448 1 << (LogicalDeviceInfo->StripeSize - 2),
2449 1 << (LogicalDeviceInfo->CacheLineSize - 2));
2451 DAC960_Info(" %s, %s\n", Controller,
2452 ReadCacheStatus[
2453 LogicalDeviceInfo->LogicalDeviceControl.ReadCache],
2454 WriteCacheStatus[
2455 LogicalDeviceInfo->LogicalDeviceControl.WriteCache]);
2456 if (LogicalDeviceInfo->SoftErrors > 0 ||
2457 LogicalDeviceInfo->CommandsFailed > 0 ||
2458 LogicalDeviceInfo->DeferredWriteErrors)
2459 DAC960_Info(" Errors - Soft: %d, Failed: %d, "
2460 "Deferred Write: %d\n", Controller,
2461 LogicalDeviceInfo->SoftErrors,
2462 LogicalDeviceInfo->CommandsFailed,
2463 LogicalDeviceInfo->DeferredWriteErrors);
2466 return true;
2470 DAC960_RegisterBlockDevice registers the Block Device structures
2471 associated with Controller.
2474 static boolean DAC960_RegisterBlockDevice(DAC960_Controller_T *Controller)
2476 int MajorNumber = DAC960_MAJOR + Controller->ControllerNumber;
2477 struct request_queue *RequestQueue;
2478 int n;
2481 Register the Block Device Major Number for this DAC960 Controller.
2483 if (register_blkdev(MajorNumber, "dac960") < 0)
2484 return false;
2487 Initialize the I/O Request Queue.
2489 RequestQueue = blk_init_queue(DAC960_RequestFunction,&Controller->queue_lock);
2490 if (!RequestQueue) {
2491 unregister_blkdev(MajorNumber, "dac960");
2492 return false;
2494 Controller->RequestQueue = RequestQueue;
2495 blk_queue_bounce_limit(RequestQueue, Controller->BounceBufferLimit);
2496 RequestQueue->queuedata = Controller;
2497 blk_queue_max_hw_segments(RequestQueue,
2498 Controller->DriverScatterGatherLimit);
2499 blk_queue_max_phys_segments(RequestQueue,
2500 Controller->DriverScatterGatherLimit);
2501 blk_queue_max_sectors(RequestQueue, Controller->MaxBlocksPerCommand);
2503 for (n = 0; n < DAC960_MaxLogicalDrives; n++) {
2504 struct gendisk *disk = Controller->disks[n];
2506 disk->queue = RequestQueue;
2507 sprintf(disk->disk_name, "rd/c%dd%d", Controller->ControllerNumber, n);
2508 sprintf(disk->devfs_name, "rd/host%d/target%d", Controller->ControllerNumber, n);
2509 disk->major = MajorNumber;
2510 disk->first_minor = n << DAC960_MaxPartitionsBits;
2511 disk->fops = &DAC960_BlockDeviceOperations;
2514 Indicate the Block Device Registration completed successfully,
2516 return true;
2521 DAC960_UnregisterBlockDevice unregisters the Block Device structures
2522 associated with Controller.
2525 static void DAC960_UnregisterBlockDevice(DAC960_Controller_T *Controller)
2527 int MajorNumber = DAC960_MAJOR + Controller->ControllerNumber;
2528 int disk;
2530 for (disk = 0; disk < DAC960_MaxLogicalDrives; disk++)
2531 del_gendisk(Controller->disks[disk]);
2534 Unregister the Block Device Major Number for this DAC960 Controller.
2536 unregister_blkdev(MajorNumber, "dac960");
2538 Remove the I/O Request Queue.
2540 blk_cleanup_queue(Controller->RequestQueue);
2544 DAC960_ComputeGenericDiskInfo computes the values for the Generic Disk
2545 Information Partition Sector Counts and Block Sizes.
2548 static void DAC960_ComputeGenericDiskInfo(DAC960_Controller_T *Controller)
2550 int disk;
2551 for (disk = 0; disk < DAC960_MaxLogicalDrives; disk++)
2552 set_capacity(Controller->disks[disk], disk_size(Controller, disk));
2556 DAC960_ReportErrorStatus reports Controller BIOS Messages passed through
2557 the Error Status Register when the driver performs the BIOS handshaking.
2558 It returns true for fatal errors and false otherwise.
2561 static boolean DAC960_ReportErrorStatus(DAC960_Controller_T *Controller,
2562 unsigned char ErrorStatus,
2563 unsigned char Parameter0,
2564 unsigned char Parameter1)
2566 switch (ErrorStatus)
2568 case 0x00:
2569 DAC960_Notice("Physical Device %d:%d Not Responding\n",
2570 Controller, Parameter1, Parameter0);
2571 break;
2572 case 0x08:
2573 if (Controller->DriveSpinUpMessageDisplayed) break;
2574 DAC960_Notice("Spinning Up Drives\n", Controller);
2575 Controller->DriveSpinUpMessageDisplayed = true;
2576 break;
2577 case 0x30:
2578 DAC960_Notice("Configuration Checksum Error\n", Controller);
2579 break;
2580 case 0x60:
2581 DAC960_Notice("Mirror Race Recovery Failed\n", Controller);
2582 break;
2583 case 0x70:
2584 DAC960_Notice("Mirror Race Recovery In Progress\n", Controller);
2585 break;
2586 case 0x90:
2587 DAC960_Notice("Physical Device %d:%d COD Mismatch\n",
2588 Controller, Parameter1, Parameter0);
2589 break;
2590 case 0xA0:
2591 DAC960_Notice("Logical Drive Installation Aborted\n", Controller);
2592 break;
2593 case 0xB0:
2594 DAC960_Notice("Mirror Race On A Critical Logical Drive\n", Controller);
2595 break;
2596 case 0xD0:
2597 DAC960_Notice("New Controller Configuration Found\n", Controller);
2598 break;
2599 case 0xF0:
2600 DAC960_Error("Fatal Memory Parity Error for Controller at\n", Controller);
2601 return true;
2602 default:
2603 DAC960_Error("Unknown Initialization Error %02X for Controller at\n",
2604 Controller, ErrorStatus);
2605 return true;
2607 return false;
2612 * DAC960_DetectCleanup releases the resources that were allocated
2613 * during DAC960_DetectController(). DAC960_DetectController can
2614 * has several internal failure points, so not ALL resources may
2615 * have been allocated. It's important to free only
2616 * resources that HAVE been allocated. The code below always
2617 * tests that the resource has been allocated before attempting to
2618 * free it.
2620 static void DAC960_DetectCleanup(DAC960_Controller_T *Controller)
2622 int i;
2624 /* Free the memory mailbox, status, and related structures */
2625 free_dma_loaf(Controller->PCIDevice, &Controller->DmaPages);
2626 if (Controller->MemoryMappedAddress) {
2627 switch(Controller->HardwareType)
2629 case DAC960_BA_Controller:
2630 DAC960_BA_DisableInterrupts(Controller->BaseAddress);
2631 break;
2632 case DAC960_LP_Controller:
2633 DAC960_LP_DisableInterrupts(Controller->BaseAddress);
2634 break;
2635 case DAC960_LA_Controller:
2636 DAC960_LA_DisableInterrupts(Controller->BaseAddress);
2637 break;
2638 case DAC960_PG_Controller:
2639 DAC960_PG_DisableInterrupts(Controller->BaseAddress);
2640 break;
2641 case DAC960_PD_Controller:
2642 DAC960_PD_DisableInterrupts(Controller->BaseAddress);
2643 break;
2644 case DAC960_P_Controller:
2645 DAC960_PD_DisableInterrupts(Controller->BaseAddress);
2646 break;
2648 iounmap(Controller->MemoryMappedAddress);
2650 if (Controller->IRQ_Channel)
2651 free_irq(Controller->IRQ_Channel, Controller);
2652 if (Controller->IO_Address)
2653 release_region(Controller->IO_Address, 0x80);
2654 pci_disable_device(Controller->PCIDevice);
2655 for (i = 0; (i < DAC960_MaxLogicalDrives) && Controller->disks[i]; i++)
2656 put_disk(Controller->disks[i]);
2657 DAC960_Controllers[Controller->ControllerNumber] = NULL;
2658 kfree(Controller);
2663 DAC960_DetectController detects Mylex DAC960/AcceleRAID/eXtremeRAID
2664 PCI RAID Controllers by interrogating the PCI Configuration Space for
2665 Controller Type.
2668 static DAC960_Controller_T *
2669 DAC960_DetectController(struct pci_dev *PCI_Device,
2670 const struct pci_device_id *entry)
2672 struct DAC960_privdata *privdata =
2673 (struct DAC960_privdata *)entry->driver_data;
2674 irqreturn_t (*InterruptHandler)(int, void *, struct pt_regs *) =
2675 privdata->InterruptHandler;
2676 unsigned int MemoryWindowSize = privdata->MemoryWindowSize;
2677 DAC960_Controller_T *Controller = NULL;
2678 unsigned char DeviceFunction = PCI_Device->devfn;
2679 unsigned char ErrorStatus, Parameter0, Parameter1;
2680 unsigned int IRQ_Channel = PCI_Device->irq;
2681 void *BaseAddress;
2682 int i;
2684 Controller = (DAC960_Controller_T *)
2685 kmalloc(sizeof(DAC960_Controller_T), GFP_ATOMIC);
2686 if (Controller == NULL) {
2687 DAC960_Error("Unable to allocate Controller structure for "
2688 "Controller at\n", NULL);
2689 return NULL;
2691 memset(Controller, 0, sizeof(DAC960_Controller_T));
2692 Controller->ControllerNumber = DAC960_ControllerCount;
2693 DAC960_Controllers[DAC960_ControllerCount++] = Controller;
2694 Controller->Bus = PCI_Device->bus->number;
2695 Controller->FirmwareType = privdata->FirmwareType;
2696 Controller->HardwareType = privdata->HardwareType;
2697 Controller->Device = DeviceFunction >> 3;
2698 Controller->Function = DeviceFunction & 0x7;
2699 Controller->PCIDevice = PCI_Device;
2700 strcpy(Controller->FullModelName, "DAC960");
2702 if (pci_enable_device(PCI_Device)) {
2703 kfree(Controller);
2704 goto Failure;
2707 switch (Controller->HardwareType)
2709 case DAC960_BA_Controller:
2710 Controller->PCI_Address = pci_resource_start(PCI_Device, 0);
2711 break;
2712 case DAC960_LP_Controller:
2713 Controller->PCI_Address = pci_resource_start(PCI_Device, 0);
2714 break;
2715 case DAC960_LA_Controller:
2716 Controller->PCI_Address = pci_resource_start(PCI_Device, 0);
2717 break;
2718 case DAC960_PG_Controller:
2719 Controller->PCI_Address = pci_resource_start(PCI_Device, 0);
2720 break;
2721 case DAC960_PD_Controller:
2722 Controller->IO_Address = pci_resource_start(PCI_Device, 0);
2723 Controller->PCI_Address = pci_resource_start(PCI_Device, 1);
2724 break;
2725 case DAC960_P_Controller:
2726 Controller->IO_Address = pci_resource_start(PCI_Device, 0);
2727 Controller->PCI_Address = pci_resource_start(PCI_Device, 1);
2728 break;
2731 pci_set_drvdata(PCI_Device, (void *)((long)Controller->ControllerNumber));
2732 for (i = 0; i < DAC960_MaxLogicalDrives; i++) {
2733 Controller->disks[i] = alloc_disk(1<<DAC960_MaxPartitionsBits);
2734 if (!Controller->disks[i])
2735 goto Failure;
2736 Controller->disks[i]->private_data = (void *)((long)i);
2738 init_waitqueue_head(&Controller->CommandWaitQueue);
2739 init_waitqueue_head(&Controller->HealthStatusWaitQueue);
2740 Controller->queue_lock = SPIN_LOCK_UNLOCKED;
2741 DAC960_AnnounceDriver(Controller);
2743 Map the Controller Register Window.
2745 if (MemoryWindowSize < PAGE_SIZE)
2746 MemoryWindowSize = PAGE_SIZE;
2747 Controller->MemoryMappedAddress =
2748 ioremap_nocache(Controller->PCI_Address & PAGE_MASK, MemoryWindowSize);
2749 Controller->BaseAddress =
2750 Controller->MemoryMappedAddress + (Controller->PCI_Address & ~PAGE_MASK);
2751 if (Controller->MemoryMappedAddress == NULL)
2753 DAC960_Error("Unable to map Controller Register Window for "
2754 "Controller at\n", Controller);
2755 goto Failure;
2757 BaseAddress = Controller->BaseAddress;
2758 switch (Controller->HardwareType)
2760 case DAC960_BA_Controller:
2761 DAC960_BA_DisableInterrupts(BaseAddress);
2762 DAC960_BA_AcknowledgeHardwareMailboxStatus(BaseAddress);
2763 udelay(1000);
2764 while (DAC960_BA_InitializationInProgressP(BaseAddress))
2766 if (DAC960_BA_ReadErrorStatus(BaseAddress, &ErrorStatus,
2767 &Parameter0, &Parameter1) &&
2768 DAC960_ReportErrorStatus(Controller, ErrorStatus,
2769 Parameter0, Parameter1))
2770 goto Failure;
2771 udelay(10);
2773 if (!DAC960_V2_EnableMemoryMailboxInterface(Controller))
2775 DAC960_Error("Unable to Enable Memory Mailbox Interface "
2776 "for Controller at\n", Controller);
2777 goto Failure;
2779 DAC960_BA_EnableInterrupts(BaseAddress);
2780 Controller->QueueCommand = DAC960_BA_QueueCommand;
2781 Controller->ReadControllerConfiguration =
2782 DAC960_V2_ReadControllerConfiguration;
2783 Controller->ReadDeviceConfiguration =
2784 DAC960_V2_ReadDeviceConfiguration;
2785 Controller->ReportDeviceConfiguration =
2786 DAC960_V2_ReportDeviceConfiguration;
2787 Controller->QueueReadWriteCommand =
2788 DAC960_V2_QueueReadWriteCommand;
2789 break;
2790 case DAC960_LP_Controller:
2791 DAC960_LP_DisableInterrupts(BaseAddress);
2792 DAC960_LP_AcknowledgeHardwareMailboxStatus(BaseAddress);
2793 udelay(1000);
2794 while (DAC960_LP_InitializationInProgressP(BaseAddress))
2796 if (DAC960_LP_ReadErrorStatus(BaseAddress, &ErrorStatus,
2797 &Parameter0, &Parameter1) &&
2798 DAC960_ReportErrorStatus(Controller, ErrorStatus,
2799 Parameter0, Parameter1))
2800 goto Failure;
2801 udelay(10);
2803 if (!DAC960_V2_EnableMemoryMailboxInterface(Controller))
2805 DAC960_Error("Unable to Enable Memory Mailbox Interface "
2806 "for Controller at\n", Controller);
2807 goto Failure;
2809 DAC960_LP_EnableInterrupts(BaseAddress);
2810 Controller->QueueCommand = DAC960_LP_QueueCommand;
2811 Controller->ReadControllerConfiguration =
2812 DAC960_V2_ReadControllerConfiguration;
2813 Controller->ReadDeviceConfiguration =
2814 DAC960_V2_ReadDeviceConfiguration;
2815 Controller->ReportDeviceConfiguration =
2816 DAC960_V2_ReportDeviceConfiguration;
2817 Controller->QueueReadWriteCommand =
2818 DAC960_V2_QueueReadWriteCommand;
2819 break;
2820 case DAC960_LA_Controller:
2821 DAC960_LA_DisableInterrupts(BaseAddress);
2822 DAC960_LA_AcknowledgeHardwareMailboxStatus(BaseAddress);
2823 udelay(1000);
2824 while (DAC960_LA_InitializationInProgressP(BaseAddress))
2826 if (DAC960_LA_ReadErrorStatus(BaseAddress, &ErrorStatus,
2827 &Parameter0, &Parameter1) &&
2828 DAC960_ReportErrorStatus(Controller, ErrorStatus,
2829 Parameter0, Parameter1))
2830 goto Failure;
2831 udelay(10);
2833 if (!DAC960_V1_EnableMemoryMailboxInterface(Controller))
2835 DAC960_Error("Unable to Enable Memory Mailbox Interface "
2836 "for Controller at\n", Controller);
2837 goto Failure;
2839 DAC960_LA_EnableInterrupts(BaseAddress);
2840 if (Controller->V1.DualModeMemoryMailboxInterface)
2841 Controller->QueueCommand = DAC960_LA_QueueCommandDualMode;
2842 else Controller->QueueCommand = DAC960_LA_QueueCommandSingleMode;
2843 Controller->ReadControllerConfiguration =
2844 DAC960_V1_ReadControllerConfiguration;
2845 Controller->ReadDeviceConfiguration =
2846 DAC960_V1_ReadDeviceConfiguration;
2847 Controller->ReportDeviceConfiguration =
2848 DAC960_V1_ReportDeviceConfiguration;
2849 Controller->QueueReadWriteCommand =
2850 DAC960_V1_QueueReadWriteCommand;
2851 break;
2852 case DAC960_PG_Controller:
2853 DAC960_PG_DisableInterrupts(BaseAddress);
2854 DAC960_PG_AcknowledgeHardwareMailboxStatus(BaseAddress);
2855 udelay(1000);
2856 while (DAC960_PG_InitializationInProgressP(BaseAddress))
2858 if (DAC960_PG_ReadErrorStatus(BaseAddress, &ErrorStatus,
2859 &Parameter0, &Parameter1) &&
2860 DAC960_ReportErrorStatus(Controller, ErrorStatus,
2861 Parameter0, Parameter1))
2862 goto Failure;
2863 udelay(10);
2865 if (!DAC960_V1_EnableMemoryMailboxInterface(Controller))
2867 DAC960_Error("Unable to Enable Memory Mailbox Interface "
2868 "for Controller at\n", Controller);
2869 goto Failure;
2871 DAC960_PG_EnableInterrupts(BaseAddress);
2872 if (Controller->V1.DualModeMemoryMailboxInterface)
2873 Controller->QueueCommand = DAC960_PG_QueueCommandDualMode;
2874 else Controller->QueueCommand = DAC960_PG_QueueCommandSingleMode;
2875 Controller->ReadControllerConfiguration =
2876 DAC960_V1_ReadControllerConfiguration;
2877 Controller->ReadDeviceConfiguration =
2878 DAC960_V1_ReadDeviceConfiguration;
2879 Controller->ReportDeviceConfiguration =
2880 DAC960_V1_ReportDeviceConfiguration;
2881 Controller->QueueReadWriteCommand =
2882 DAC960_V1_QueueReadWriteCommand;
2883 break;
2884 case DAC960_PD_Controller:
2885 if (!request_region(Controller->IO_Address, 0x80,
2886 Controller->FullModelName)) {
2887 DAC960_Error("IO port 0x%d busy for Controller at\n",
2888 Controller, Controller->IO_Address);
2889 goto Failure;
2891 DAC960_PD_DisableInterrupts(BaseAddress);
2892 DAC960_PD_AcknowledgeStatus(BaseAddress);
2893 udelay(1000);
2894 while (DAC960_PD_InitializationInProgressP(BaseAddress))
2896 if (DAC960_PD_ReadErrorStatus(BaseAddress, &ErrorStatus,
2897 &Parameter0, &Parameter1) &&
2898 DAC960_ReportErrorStatus(Controller, ErrorStatus,
2899 Parameter0, Parameter1))
2900 goto Failure;
2901 udelay(10);
2903 if (!DAC960_V1_EnableMemoryMailboxInterface(Controller))
2905 DAC960_Error("Unable to allocate DMA mapped memory "
2906 "for Controller at\n", Controller);
2907 goto Failure;
2909 DAC960_PD_EnableInterrupts(BaseAddress);
2910 Controller->QueueCommand = DAC960_PD_QueueCommand;
2911 Controller->ReadControllerConfiguration =
2912 DAC960_V1_ReadControllerConfiguration;
2913 Controller->ReadDeviceConfiguration =
2914 DAC960_V1_ReadDeviceConfiguration;
2915 Controller->ReportDeviceConfiguration =
2916 DAC960_V1_ReportDeviceConfiguration;
2917 Controller->QueueReadWriteCommand =
2918 DAC960_V1_QueueReadWriteCommand;
2919 break;
2920 case DAC960_P_Controller:
2921 if (!request_region(Controller->IO_Address, 0x80,
2922 Controller->FullModelName)){
2923 DAC960_Error("IO port 0x%d busy for Controller at\n",
2924 Controller, Controller->IO_Address);
2925 goto Failure;
2927 DAC960_PD_DisableInterrupts(BaseAddress);
2928 DAC960_PD_AcknowledgeStatus(BaseAddress);
2929 udelay(1000);
2930 while (DAC960_PD_InitializationInProgressP(BaseAddress))
2932 if (DAC960_PD_ReadErrorStatus(BaseAddress, &ErrorStatus,
2933 &Parameter0, &Parameter1) &&
2934 DAC960_ReportErrorStatus(Controller, ErrorStatus,
2935 Parameter0, Parameter1))
2936 goto Failure;
2937 udelay(10);
2939 if (!DAC960_V1_EnableMemoryMailboxInterface(Controller))
2941 DAC960_Error("Unable to allocate DMA mapped memory"
2942 "for Controller at\n", Controller);
2943 goto Failure;
2945 DAC960_PD_EnableInterrupts(BaseAddress);
2946 Controller->QueueCommand = DAC960_P_QueueCommand;
2947 Controller->ReadControllerConfiguration =
2948 DAC960_V1_ReadControllerConfiguration;
2949 Controller->ReadDeviceConfiguration =
2950 DAC960_V1_ReadDeviceConfiguration;
2951 Controller->ReportDeviceConfiguration =
2952 DAC960_V1_ReportDeviceConfiguration;
2953 Controller->QueueReadWriteCommand =
2954 DAC960_V1_QueueReadWriteCommand;
2955 break;
2958 Acquire shared access to the IRQ Channel.
2960 if (request_irq(IRQ_Channel, InterruptHandler, SA_SHIRQ,
2961 Controller->FullModelName, Controller) < 0)
2963 DAC960_Error("Unable to acquire IRQ Channel %d for Controller at\n",
2964 Controller, Controller->IRQ_Channel);
2965 goto Failure;
2967 Controller->IRQ_Channel = IRQ_Channel;
2968 Controller->InitialCommand.CommandIdentifier = 1;
2969 Controller->InitialCommand.Controller = Controller;
2970 Controller->Commands[0] = &Controller->InitialCommand;
2971 Controller->FreeCommands = &Controller->InitialCommand;
2972 return Controller;
2974 Failure:
2975 if (Controller->IO_Address == 0)
2976 DAC960_Error("PCI Bus %d Device %d Function %d I/O Address N/A "
2977 "PCI Address 0x%X\n", Controller,
2978 Controller->Bus, Controller->Device,
2979 Controller->Function, Controller->PCI_Address);
2980 else
2981 DAC960_Error("PCI Bus %d Device %d Function %d I/O Address "
2982 "0x%X PCI Address 0x%X\n", Controller,
2983 Controller->Bus, Controller->Device,
2984 Controller->Function, Controller->IO_Address,
2985 Controller->PCI_Address);
2986 DAC960_DetectCleanup(Controller);
2987 DAC960_ControllerCount--;
2988 return NULL;
2992 DAC960_InitializeController initializes Controller.
2995 static boolean
2996 DAC960_InitializeController(DAC960_Controller_T *Controller)
2998 if (DAC960_ReadControllerConfiguration(Controller) &&
2999 DAC960_ReportControllerConfiguration(Controller) &&
3000 DAC960_CreateAuxiliaryStructures(Controller) &&
3001 DAC960_ReadDeviceConfiguration(Controller) &&
3002 DAC960_ReportDeviceConfiguration(Controller) &&
3003 DAC960_RegisterBlockDevice(Controller))
3006 Initialize the Monitoring Timer.
3008 init_timer(&Controller->MonitoringTimer);
3009 Controller->MonitoringTimer.expires =
3010 jiffies + DAC960_MonitoringTimerInterval;
3011 Controller->MonitoringTimer.data = (unsigned long) Controller;
3012 Controller->MonitoringTimer.function = DAC960_MonitoringTimerFunction;
3013 add_timer(&Controller->MonitoringTimer);
3014 Controller->ControllerInitialized = true;
3015 return true;
3017 return false;
3022 DAC960_FinalizeController finalizes Controller.
3025 static void DAC960_FinalizeController(DAC960_Controller_T *Controller)
3027 if (Controller->ControllerInitialized)
3029 unsigned long flags;
3032 * Acquiring and releasing lock here eliminates
3033 * a very low probability race.
3035 * The code below allocates controller command structures
3036 * from the free list without holding the controller lock.
3037 * This is safe assuming there is no other activity on
3038 * the controller at the time.
3040 * But, there might be a monitoring command still
3041 * in progress. Setting the Shutdown flag while holding
3042 * the lock ensures that there is no monitoring command
3043 * in the interrupt handler currently, and any monitoring
3044 * commands that complete from this time on will NOT return
3045 * their command structure to the free list.
3048 spin_lock_irqsave(&Controller->queue_lock, flags);
3049 Controller->ShutdownMonitoringTimer = 1;
3050 spin_unlock_irqrestore(&Controller->queue_lock, flags);
3052 del_timer_sync(&Controller->MonitoringTimer);
3053 if (Controller->FirmwareType == DAC960_V1_Controller)
3055 DAC960_Notice("Flushing Cache...", Controller);
3056 DAC960_V1_ExecuteType3(Controller, DAC960_V1_Flush, 0);
3057 DAC960_Notice("done\n", Controller);
3059 if (Controller->HardwareType == DAC960_PD_Controller)
3060 release_region(Controller->IO_Address, 0x80);
3062 else
3064 DAC960_Notice("Flushing Cache...", Controller);
3065 DAC960_V2_DeviceOperation(Controller, DAC960_V2_PauseDevice,
3066 DAC960_V2_RAID_Controller);
3067 DAC960_Notice("done\n", Controller);
3070 DAC960_UnregisterBlockDevice(Controller);
3071 DAC960_DestroyAuxiliaryStructures(Controller);
3072 DAC960_DestroyProcEntries(Controller);
3073 DAC960_DetectCleanup(Controller);
3078 DAC960_Probe verifies controller's existence and
3079 initializes the DAC960 Driver for that controller.
3082 static int
3083 DAC960_Probe(struct pci_dev *dev, const struct pci_device_id *entry)
3085 int disk;
3086 DAC960_Controller_T *Controller;
3088 if (DAC960_ControllerCount == DAC960_MaxControllers)
3090 DAC960_Error("More than %d DAC960 Controllers detected - "
3091 "ignoring from Controller at\n",
3092 NULL, DAC960_MaxControllers);
3093 return -ENODEV;
3096 Controller = DAC960_DetectController(dev, entry);
3097 if (!Controller)
3098 return -ENODEV;
3100 if (!DAC960_InitializeController(Controller)) {
3101 DAC960_FinalizeController(Controller);
3102 return -ENODEV;
3105 for (disk = 0; disk < DAC960_MaxLogicalDrives; disk++) {
3106 set_capacity(Controller->disks[disk], disk_size(Controller, disk));
3107 add_disk(Controller->disks[disk]);
3109 DAC960_CreateProcEntries(Controller);
3110 return 0;
3115 DAC960_Finalize finalizes the DAC960 Driver.
3118 static void DAC960_Remove(struct pci_dev *PCI_Device)
3120 int Controller_Number = (long)pci_get_drvdata(PCI_Device);
3121 DAC960_Controller_T *Controller = DAC960_Controllers[Controller_Number];
3122 if (Controller != NULL)
3123 DAC960_FinalizeController(Controller);
3128 DAC960_V1_QueueReadWriteCommand prepares and queues a Read/Write Command for
3129 DAC960 V1 Firmware Controllers.
3132 static void DAC960_V1_QueueReadWriteCommand(DAC960_Command_T *Command)
3134 DAC960_Controller_T *Controller = Command->Controller;
3135 DAC960_V1_CommandMailbox_T *CommandMailbox = &Command->V1.CommandMailbox;
3136 DAC960_V1_ScatterGatherSegment_T *ScatterGatherList =
3137 Command->V1.ScatterGatherList;
3138 struct scatterlist *ScatterList = Command->V1.ScatterList;
3140 DAC960_V1_ClearCommand(Command);
3142 if (Command->SegmentCount == 1)
3144 if (Command->DmaDirection == PCI_DMA_FROMDEVICE)
3145 CommandMailbox->Type5.CommandOpcode = DAC960_V1_Read;
3146 else
3147 CommandMailbox->Type5.CommandOpcode = DAC960_V1_Write;
3149 CommandMailbox->Type5.LD.TransferLength = Command->BlockCount;
3150 CommandMailbox->Type5.LD.LogicalDriveNumber = Command->LogicalDriveNumber;
3151 CommandMailbox->Type5.LogicalBlockAddress = Command->BlockNumber;
3152 CommandMailbox->Type5.BusAddress =
3153 (DAC960_BusAddress32_T)sg_dma_address(ScatterList);
3155 else
3157 int i;
3159 if (Command->DmaDirection == PCI_DMA_FROMDEVICE)
3160 CommandMailbox->Type5.CommandOpcode = DAC960_V1_ReadWithScatterGather;
3161 else
3162 CommandMailbox->Type5.CommandOpcode = DAC960_V1_WriteWithScatterGather;
3164 CommandMailbox->Type5.LD.TransferLength = Command->BlockCount;
3165 CommandMailbox->Type5.LD.LogicalDriveNumber = Command->LogicalDriveNumber;
3166 CommandMailbox->Type5.LogicalBlockAddress = Command->BlockNumber;
3167 CommandMailbox->Type5.BusAddress = Command->V1.ScatterGatherListDMA;
3169 CommandMailbox->Type5.ScatterGatherCount = Command->SegmentCount;
3171 for (i = 0; i < Command->SegmentCount; i++, ScatterList++, ScatterGatherList++) {
3172 ScatterGatherList->SegmentDataPointer =
3173 (DAC960_BusAddress32_T)sg_dma_address(ScatterList);
3174 ScatterGatherList->SegmentByteCount =
3175 (DAC960_ByteCount32_T)sg_dma_len(ScatterList);
3178 DAC960_QueueCommand(Command);
3183 DAC960_V2_QueueReadWriteCommand prepares and queues a Read/Write Command for
3184 DAC960 V2 Firmware Controllers.
3187 static void DAC960_V2_QueueReadWriteCommand(DAC960_Command_T *Command)
3189 DAC960_Controller_T *Controller = Command->Controller;
3190 DAC960_V2_CommandMailbox_T *CommandMailbox = &Command->V2.CommandMailbox;
3191 struct scatterlist *ScatterList = Command->V2.ScatterList;
3193 DAC960_V2_ClearCommand(Command);
3195 CommandMailbox->SCSI_10.CommandOpcode = DAC960_V2_SCSI_10;
3196 CommandMailbox->SCSI_10.CommandControlBits.DataTransferControllerToHost =
3197 (Command->DmaDirection == PCI_DMA_FROMDEVICE);
3198 CommandMailbox->SCSI_10.DataTransferSize =
3199 Command->BlockCount << DAC960_BlockSizeBits;
3200 CommandMailbox->SCSI_10.RequestSenseBusAddress = Command->V2.RequestSenseDMA;
3201 CommandMailbox->SCSI_10.PhysicalDevice =
3202 Controller->V2.LogicalDriveToVirtualDevice[Command->LogicalDriveNumber];
3203 CommandMailbox->SCSI_10.RequestSenseSize = sizeof(DAC960_SCSI_RequestSense_T);
3204 CommandMailbox->SCSI_10.CDBLength = 10;
3205 CommandMailbox->SCSI_10.SCSI_CDB[0] =
3206 (Command->DmaDirection == PCI_DMA_FROMDEVICE ? 0x28 : 0x2A);
3207 CommandMailbox->SCSI_10.SCSI_CDB[2] = Command->BlockNumber >> 24;
3208 CommandMailbox->SCSI_10.SCSI_CDB[3] = Command->BlockNumber >> 16;
3209 CommandMailbox->SCSI_10.SCSI_CDB[4] = Command->BlockNumber >> 8;
3210 CommandMailbox->SCSI_10.SCSI_CDB[5] = Command->BlockNumber;
3211 CommandMailbox->SCSI_10.SCSI_CDB[7] = Command->BlockCount >> 8;
3212 CommandMailbox->SCSI_10.SCSI_CDB[8] = Command->BlockCount;
3214 if (Command->SegmentCount == 1)
3216 CommandMailbox->SCSI_10.DataTransferMemoryAddress
3217 .ScatterGatherSegments[0]
3218 .SegmentDataPointer =
3219 (DAC960_BusAddress64_T)sg_dma_address(ScatterList);
3220 CommandMailbox->SCSI_10.DataTransferMemoryAddress
3221 .ScatterGatherSegments[0]
3222 .SegmentByteCount =
3223 CommandMailbox->SCSI_10.DataTransferSize;
3225 else
3227 DAC960_V2_ScatterGatherSegment_T *ScatterGatherList;
3228 int i;
3230 if (Command->SegmentCount > 2)
3232 ScatterGatherList = Command->V2.ScatterGatherList;
3233 CommandMailbox->SCSI_10.CommandControlBits
3234 .AdditionalScatterGatherListMemory = true;
3235 CommandMailbox->SCSI_10.DataTransferMemoryAddress
3236 .ExtendedScatterGather.ScatterGatherList0Length = Command->SegmentCount;
3237 CommandMailbox->SCSI_10.DataTransferMemoryAddress
3238 .ExtendedScatterGather.ScatterGatherList0Address =
3239 Command->V2.ScatterGatherListDMA;
3241 else
3242 ScatterGatherList = CommandMailbox->SCSI_10.DataTransferMemoryAddress
3243 .ScatterGatherSegments;
3245 for (i = 0; i < Command->SegmentCount; i++, ScatterList++, ScatterGatherList++) {
3246 ScatterGatherList->SegmentDataPointer =
3247 (DAC960_BusAddress64_T)sg_dma_address(ScatterList);
3248 ScatterGatherList->SegmentByteCount =
3249 (DAC960_ByteCount64_T)sg_dma_len(ScatterList);
3252 DAC960_QueueCommand(Command);
3257 DAC960_ProcessRequest attempts to remove one I/O Request from Controller's
3258 I/O Request Queue and queues it to the Controller. WaitForCommand is true if
3259 this function should wait for a Command to become available if necessary.
3260 This function returns true if an I/O Request was queued and false otherwise.
3263 static boolean DAC960_ProcessRequest(DAC960_Controller_T *Controller,
3264 boolean WaitForCommand)
3266 struct request_queue *RequestQueue = Controller->RequestQueue;
3267 struct request *Request;
3268 DAC960_Command_T *Command;
3270 if (!Controller->ControllerInitialized)
3271 return false;
3273 while (true) {
3274 Request = elv_next_request(RequestQueue);
3275 if (!Request)
3276 return false;
3278 Command = DAC960_AllocateCommand(Controller);
3279 if (Command != NULL)
3280 break;
3282 if (!WaitForCommand)
3283 return false;
3285 DAC960_WaitForCommand(Controller);
3287 if (rq_data_dir(Request) == READ) {
3288 Command->DmaDirection = PCI_DMA_FROMDEVICE;
3289 Command->CommandType = DAC960_ReadCommand;
3290 } else {
3291 Command->DmaDirection = PCI_DMA_TODEVICE;
3292 Command->CommandType = DAC960_WriteCommand;
3294 Command->Completion = Request->waiting;
3295 Command->LogicalDriveNumber = (long)Request->rq_disk->private_data;
3296 Command->BlockNumber = Request->sector;
3297 Command->BlockCount = Request->nr_sectors;
3298 Command->Request = Request;
3299 blkdev_dequeue_request(Request);
3300 Command->SegmentCount = blk_rq_map_sg(Controller->RequestQueue,
3301 Command->Request, Command->cmd_sglist);
3302 /* pci_map_sg MAY change the value of SegCount */
3303 Command->SegmentCount = pci_map_sg(Controller->PCIDevice, Command->cmd_sglist,
3304 Command->SegmentCount, Command->DmaDirection);
3306 DAC960_QueueReadWriteCommand(Command);
3307 return true;
3312 DAC960_queue_partial_rw extracts one bio from the request already
3313 associated with argument command, and construct a new command block to retry I/O
3314 only on that bio. Queue that command to the controller.
3316 This function re-uses a previously-allocated Command,
3317 there is no failure mode from trying to allocate a command.
3320 static void DAC960_queue_partial_rw(DAC960_Command_T *Command)
3322 DAC960_Controller_T *Controller = Command->Controller;
3323 struct request *Request = Command->Request;
3325 if (Command->DmaDirection == PCI_DMA_FROMDEVICE)
3326 Command->CommandType = DAC960_ReadRetryCommand;
3327 else
3328 Command->CommandType = DAC960_WriteRetryCommand;
3331 * We could be more efficient with these mapping requests
3332 * and map only the portions that we need. But since this
3333 * code should almost never be called, just go with a
3334 * simple coding.
3336 (void)blk_rq_map_sg(Controller->RequestQueue, Command->Request,
3337 Command->cmd_sglist);
3339 (void)pci_map_sg(Controller->PCIDevice, Command->cmd_sglist, 1,
3340 Command->DmaDirection);
3342 * Resubmitting the request sector at a time is really tedious.
3343 * But, this should almost never happen. So, we're willing to pay
3344 * this price so that in the end, as much of the transfer is completed
3345 * successfully as possible.
3347 Command->SegmentCount = 1;
3348 Command->BlockNumber = Request->sector;
3349 Command->BlockCount = 1;
3350 DAC960_QueueReadWriteCommand(Command);
3351 return;
3355 DAC960_RequestFunction is the I/O Request Function for DAC960 Controllers.
3358 static void DAC960_RequestFunction(struct request_queue *RequestQueue)
3360 int i = 0;
3361 while (DAC960_ProcessRequest(RequestQueue->queuedata, (i++ == 0)))
3366 DAC960_ProcessCompletedBuffer performs completion processing for an
3367 individual Buffer.
3370 static inline boolean DAC960_ProcessCompletedRequest(DAC960_Command_T *Command,
3371 boolean SuccessfulIO)
3373 struct request *Request = Command->Request;
3374 int UpToDate;
3376 UpToDate = 0;
3377 if (SuccessfulIO)
3378 UpToDate = 1;
3380 pci_unmap_sg(Command->Controller->PCIDevice, Command->cmd_sglist,
3381 Command->SegmentCount, Command->DmaDirection);
3383 if (!end_that_request_first(Request, UpToDate, Command->BlockCount)) {
3385 end_that_request_last(Request);
3387 if (Command->Completion) {
3388 complete(Command->Completion);
3389 Command->Completion = NULL;
3391 return true;
3393 return false;
3397 DAC960_V1_ReadWriteError prints an appropriate error message for Command
3398 when an error occurs on a Read or Write operation.
3401 static void DAC960_V1_ReadWriteError(DAC960_Command_T *Command)
3403 DAC960_Controller_T *Controller = Command->Controller;
3404 unsigned char *CommandName = "UNKNOWN";
3405 switch (Command->CommandType)
3407 case DAC960_ReadCommand:
3408 case DAC960_ReadRetryCommand:
3409 CommandName = "READ";
3410 break;
3411 case DAC960_WriteCommand:
3412 case DAC960_WriteRetryCommand:
3413 CommandName = "WRITE";
3414 break;
3415 case DAC960_MonitoringCommand:
3416 case DAC960_ImmediateCommand:
3417 case DAC960_QueuedCommand:
3418 break;
3420 switch (Command->V1.CommandStatus)
3422 case DAC960_V1_IrrecoverableDataError:
3423 DAC960_Error("Irrecoverable Data Error on %s:\n",
3424 Controller, CommandName);
3425 break;
3426 case DAC960_V1_LogicalDriveNonexistentOrOffline:
3427 DAC960_Error("Logical Drive Nonexistent or Offline on %s:\n",
3428 Controller, CommandName);
3429 break;
3430 case DAC960_V1_AccessBeyondEndOfLogicalDrive:
3431 DAC960_Error("Attempt to Access Beyond End of Logical Drive "
3432 "on %s:\n", Controller, CommandName);
3433 break;
3434 case DAC960_V1_BadDataEncountered:
3435 DAC960_Error("Bad Data Encountered on %s:\n", Controller, CommandName);
3436 break;
3437 default:
3438 DAC960_Error("Unexpected Error Status %04X on %s:\n",
3439 Controller, Command->V1.CommandStatus, CommandName);
3440 break;
3442 DAC960_Error(" /dev/rd/c%dd%d: absolute blocks %u..%u\n",
3443 Controller, Controller->ControllerNumber,
3444 Command->LogicalDriveNumber, Command->BlockNumber,
3445 Command->BlockNumber + Command->BlockCount - 1);
3450 DAC960_V1_ProcessCompletedCommand performs completion processing for Command
3451 for DAC960 V1 Firmware Controllers.
3454 static void DAC960_V1_ProcessCompletedCommand(DAC960_Command_T *Command)
3456 DAC960_Controller_T *Controller = Command->Controller;
3457 DAC960_CommandType_T CommandType = Command->CommandType;
3458 DAC960_V1_CommandOpcode_T CommandOpcode =
3459 Command->V1.CommandMailbox.Common.CommandOpcode;
3460 DAC960_V1_CommandStatus_T CommandStatus = Command->V1.CommandStatus;
3462 if (CommandType == DAC960_ReadCommand ||
3463 CommandType == DAC960_WriteCommand)
3466 #ifdef FORCE_RETRY_DEBUG
3467 CommandStatus = DAC960_V1_IrrecoverableDataError;
3468 #endif
3470 if (CommandStatus == DAC960_V1_NormalCompletion) {
3472 if (!DAC960_ProcessCompletedRequest(Command, true))
3473 BUG();
3475 } else if (CommandStatus == DAC960_V1_IrrecoverableDataError ||
3476 CommandStatus == DAC960_V1_BadDataEncountered)
3479 * break the command down into pieces and resubmit each
3480 * piece, hoping that some of them will succeed.
3482 DAC960_queue_partial_rw(Command);
3483 return;
3485 else
3487 if (CommandStatus != DAC960_V1_LogicalDriveNonexistentOrOffline)
3488 DAC960_V1_ReadWriteError(Command);
3490 if (!DAC960_ProcessCompletedRequest(Command, false))
3491 BUG();
3494 else if (CommandType == DAC960_ReadRetryCommand ||
3495 CommandType == DAC960_WriteRetryCommand)
3497 boolean normal_completion;
3498 #ifdef FORCE_RETRY_FAILURE_DEBUG
3499 static int retry_count = 1;
3500 #endif
3502 Perform completion processing for the portion that was
3503 retried, and submit the next portion, if any.
3505 normal_completion = true;
3506 if (CommandStatus != DAC960_V1_NormalCompletion) {
3507 normal_completion = false;
3508 if (CommandStatus != DAC960_V1_LogicalDriveNonexistentOrOffline)
3509 DAC960_V1_ReadWriteError(Command);
3512 #ifdef FORCE_RETRY_FAILURE_DEBUG
3513 if (!(++retry_count % 10000)) {
3514 printk("V1 error retry failure test\n");
3515 normal_completion = false;
3516 DAC960_V1_ReadWriteError(Command);
3518 #endif
3520 if (!DAC960_ProcessCompletedRequest(Command, normal_completion)) {
3521 DAC960_queue_partial_rw(Command);
3522 return;
3526 else if (CommandType == DAC960_MonitoringCommand)
3528 if (Controller->ShutdownMonitoringTimer)
3529 return;
3530 if (CommandOpcode == DAC960_V1_Enquiry)
3532 DAC960_V1_Enquiry_T *OldEnquiry = &Controller->V1.Enquiry;
3533 DAC960_V1_Enquiry_T *NewEnquiry = Controller->V1.NewEnquiry;
3534 unsigned int OldCriticalLogicalDriveCount =
3535 OldEnquiry->CriticalLogicalDriveCount;
3536 unsigned int NewCriticalLogicalDriveCount =
3537 NewEnquiry->CriticalLogicalDriveCount;
3538 if (NewEnquiry->NumberOfLogicalDrives > Controller->LogicalDriveCount)
3540 int LogicalDriveNumber = Controller->LogicalDriveCount - 1;
3541 while (++LogicalDriveNumber < NewEnquiry->NumberOfLogicalDrives)
3542 DAC960_Critical("Logical Drive %d (/dev/rd/c%dd%d) "
3543 "Now Exists\n", Controller,
3544 LogicalDriveNumber,
3545 Controller->ControllerNumber,
3546 LogicalDriveNumber);
3547 Controller->LogicalDriveCount = NewEnquiry->NumberOfLogicalDrives;
3548 DAC960_ComputeGenericDiskInfo(Controller);
3550 if (NewEnquiry->NumberOfLogicalDrives < Controller->LogicalDriveCount)
3552 int LogicalDriveNumber = NewEnquiry->NumberOfLogicalDrives - 1;
3553 while (++LogicalDriveNumber < Controller->LogicalDriveCount)
3554 DAC960_Critical("Logical Drive %d (/dev/rd/c%dd%d) "
3555 "No Longer Exists\n", Controller,
3556 LogicalDriveNumber,
3557 Controller->ControllerNumber,
3558 LogicalDriveNumber);
3559 Controller->LogicalDriveCount = NewEnquiry->NumberOfLogicalDrives;
3560 DAC960_ComputeGenericDiskInfo(Controller);
3562 if (NewEnquiry->StatusFlags.DeferredWriteError !=
3563 OldEnquiry->StatusFlags.DeferredWriteError)
3564 DAC960_Critical("Deferred Write Error Flag is now %s\n", Controller,
3565 (NewEnquiry->StatusFlags.DeferredWriteError
3566 ? "TRUE" : "FALSE"));
3567 if ((NewCriticalLogicalDriveCount > 0 ||
3568 NewCriticalLogicalDriveCount != OldCriticalLogicalDriveCount) ||
3569 (NewEnquiry->OfflineLogicalDriveCount > 0 ||
3570 NewEnquiry->OfflineLogicalDriveCount !=
3571 OldEnquiry->OfflineLogicalDriveCount) ||
3572 (NewEnquiry->DeadDriveCount > 0 ||
3573 NewEnquiry->DeadDriveCount !=
3574 OldEnquiry->DeadDriveCount) ||
3575 (NewEnquiry->EventLogSequenceNumber !=
3576 OldEnquiry->EventLogSequenceNumber) ||
3577 Controller->MonitoringTimerCount == 0 ||
3578 (jiffies - Controller->SecondaryMonitoringTime
3579 >= DAC960_SecondaryMonitoringInterval))
3581 Controller->V1.NeedLogicalDriveInformation = true;
3582 Controller->V1.NewEventLogSequenceNumber =
3583 NewEnquiry->EventLogSequenceNumber;
3584 Controller->V1.NeedErrorTableInformation = true;
3585 Controller->V1.NeedDeviceStateInformation = true;
3586 Controller->V1.StartDeviceStateScan = true;
3587 Controller->V1.NeedBackgroundInitializationStatus =
3588 Controller->V1.BackgroundInitializationStatusSupported;
3589 Controller->SecondaryMonitoringTime = jiffies;
3591 if (NewEnquiry->RebuildFlag == DAC960_V1_StandbyRebuildInProgress ||
3592 NewEnquiry->RebuildFlag
3593 == DAC960_V1_BackgroundRebuildInProgress ||
3594 OldEnquiry->RebuildFlag == DAC960_V1_StandbyRebuildInProgress ||
3595 OldEnquiry->RebuildFlag == DAC960_V1_BackgroundRebuildInProgress)
3597 Controller->V1.NeedRebuildProgress = true;
3598 Controller->V1.RebuildProgressFirst =
3599 (NewEnquiry->CriticalLogicalDriveCount <
3600 OldEnquiry->CriticalLogicalDriveCount);
3602 if (OldEnquiry->RebuildFlag == DAC960_V1_BackgroundCheckInProgress)
3603 switch (NewEnquiry->RebuildFlag)
3605 case DAC960_V1_NoStandbyRebuildOrCheckInProgress:
3606 DAC960_Progress("Consistency Check Completed Successfully\n",
3607 Controller);
3608 break;
3609 case DAC960_V1_StandbyRebuildInProgress:
3610 case DAC960_V1_BackgroundRebuildInProgress:
3611 break;
3612 case DAC960_V1_BackgroundCheckInProgress:
3613 Controller->V1.NeedConsistencyCheckProgress = true;
3614 break;
3615 case DAC960_V1_StandbyRebuildCompletedWithError:
3616 DAC960_Progress("Consistency Check Completed with Error\n",
3617 Controller);
3618 break;
3619 case DAC960_V1_BackgroundRebuildOrCheckFailed_DriveFailed:
3620 DAC960_Progress("Consistency Check Failed - "
3621 "Physical Device Failed\n", Controller);
3622 break;
3623 case DAC960_V1_BackgroundRebuildOrCheckFailed_LogicalDriveFailed:
3624 DAC960_Progress("Consistency Check Failed - "
3625 "Logical Drive Failed\n", Controller);
3626 break;
3627 case DAC960_V1_BackgroundRebuildOrCheckFailed_OtherCauses:
3628 DAC960_Progress("Consistency Check Failed - Other Causes\n",
3629 Controller);
3630 break;
3631 case DAC960_V1_BackgroundRebuildOrCheckSuccessfullyTerminated:
3632 DAC960_Progress("Consistency Check Successfully Terminated\n",
3633 Controller);
3634 break;
3636 else if (NewEnquiry->RebuildFlag
3637 == DAC960_V1_BackgroundCheckInProgress)
3638 Controller->V1.NeedConsistencyCheckProgress = true;
3639 Controller->MonitoringAlertMode =
3640 (NewEnquiry->CriticalLogicalDriveCount > 0 ||
3641 NewEnquiry->OfflineLogicalDriveCount > 0 ||
3642 NewEnquiry->DeadDriveCount > 0);
3643 if (NewEnquiry->RebuildFlag > DAC960_V1_BackgroundCheckInProgress)
3645 Controller->V1.PendingRebuildFlag = NewEnquiry->RebuildFlag;
3646 Controller->V1.RebuildFlagPending = true;
3648 memcpy(&Controller->V1.Enquiry, &Controller->V1.NewEnquiry,
3649 sizeof(DAC960_V1_Enquiry_T));
3651 else if (CommandOpcode == DAC960_V1_PerformEventLogOperation)
3653 static char
3654 *DAC960_EventMessages[] =
3655 { "killed because write recovery failed",
3656 "killed because of SCSI bus reset failure",
3657 "killed because of double check condition",
3658 "killed because it was removed",
3659 "killed because of gross error on SCSI chip",
3660 "killed because of bad tag returned from drive",
3661 "killed because of timeout on SCSI command",
3662 "killed because of reset SCSI command issued from system",
3663 "killed because busy or parity error count exceeded limit",
3664 "killed because of 'kill drive' command from system",
3665 "killed because of selection timeout",
3666 "killed due to SCSI phase sequence error",
3667 "killed due to unknown status" };
3668 DAC960_V1_EventLogEntry_T *EventLogEntry =
3669 Controller->V1.EventLogEntry;
3670 if (EventLogEntry->SequenceNumber ==
3671 Controller->V1.OldEventLogSequenceNumber)
3673 unsigned char SenseKey = EventLogEntry->SenseKey;
3674 unsigned char AdditionalSenseCode =
3675 EventLogEntry->AdditionalSenseCode;
3676 unsigned char AdditionalSenseCodeQualifier =
3677 EventLogEntry->AdditionalSenseCodeQualifier;
3678 if (SenseKey == DAC960_SenseKey_VendorSpecific &&
3679 AdditionalSenseCode == 0x80 &&
3680 AdditionalSenseCodeQualifier <
3681 sizeof(DAC960_EventMessages) / sizeof(char *))
3682 DAC960_Critical("Physical Device %d:%d %s\n", Controller,
3683 EventLogEntry->Channel,
3684 EventLogEntry->TargetID,
3685 DAC960_EventMessages[
3686 AdditionalSenseCodeQualifier]);
3687 else if (SenseKey == DAC960_SenseKey_UnitAttention &&
3688 AdditionalSenseCode == 0x29)
3690 if (Controller->MonitoringTimerCount > 0)
3691 Controller->V1.DeviceResetCount[EventLogEntry->Channel]
3692 [EventLogEntry->TargetID]++;
3694 else if (!(SenseKey == DAC960_SenseKey_NoSense ||
3695 (SenseKey == DAC960_SenseKey_NotReady &&
3696 AdditionalSenseCode == 0x04 &&
3697 (AdditionalSenseCodeQualifier == 0x01 ||
3698 AdditionalSenseCodeQualifier == 0x02))))
3700 DAC960_Critical("Physical Device %d:%d Error Log: "
3701 "Sense Key = %X, ASC = %02X, ASCQ = %02X\n",
3702 Controller,
3703 EventLogEntry->Channel,
3704 EventLogEntry->TargetID,
3705 SenseKey,
3706 AdditionalSenseCode,
3707 AdditionalSenseCodeQualifier);
3708 DAC960_Critical("Physical Device %d:%d Error Log: "
3709 "Information = %02X%02X%02X%02X "
3710 "%02X%02X%02X%02X\n",
3711 Controller,
3712 EventLogEntry->Channel,
3713 EventLogEntry->TargetID,
3714 EventLogEntry->Information[0],
3715 EventLogEntry->Information[1],
3716 EventLogEntry->Information[2],
3717 EventLogEntry->Information[3],
3718 EventLogEntry->CommandSpecificInformation[0],
3719 EventLogEntry->CommandSpecificInformation[1],
3720 EventLogEntry->CommandSpecificInformation[2],
3721 EventLogEntry->CommandSpecificInformation[3]);
3724 Controller->V1.OldEventLogSequenceNumber++;
3726 else if (CommandOpcode == DAC960_V1_GetErrorTable)
3728 DAC960_V1_ErrorTable_T *OldErrorTable = &Controller->V1.ErrorTable;
3729 DAC960_V1_ErrorTable_T *NewErrorTable = Controller->V1.NewErrorTable;
3730 int Channel, TargetID;
3731 for (Channel = 0; Channel < Controller->Channels; Channel++)
3732 for (TargetID = 0; TargetID < Controller->Targets; TargetID++)
3734 DAC960_V1_ErrorTableEntry_T *NewErrorEntry =
3735 &NewErrorTable->ErrorTableEntries[Channel][TargetID];
3736 DAC960_V1_ErrorTableEntry_T *OldErrorEntry =
3737 &OldErrorTable->ErrorTableEntries[Channel][TargetID];
3738 if ((NewErrorEntry->ParityErrorCount !=
3739 OldErrorEntry->ParityErrorCount) ||
3740 (NewErrorEntry->SoftErrorCount !=
3741 OldErrorEntry->SoftErrorCount) ||
3742 (NewErrorEntry->HardErrorCount !=
3743 OldErrorEntry->HardErrorCount) ||
3744 (NewErrorEntry->MiscErrorCount !=
3745 OldErrorEntry->MiscErrorCount))
3746 DAC960_Critical("Physical Device %d:%d Errors: "
3747 "Parity = %d, Soft = %d, "
3748 "Hard = %d, Misc = %d\n",
3749 Controller, Channel, TargetID,
3750 NewErrorEntry->ParityErrorCount,
3751 NewErrorEntry->SoftErrorCount,
3752 NewErrorEntry->HardErrorCount,
3753 NewErrorEntry->MiscErrorCount);
3755 memcpy(&Controller->V1.ErrorTable, Controller->V1.NewErrorTable,
3756 sizeof(DAC960_V1_ErrorTable_T));
3758 else if (CommandOpcode == DAC960_V1_GetDeviceState)
3760 DAC960_V1_DeviceState_T *OldDeviceState =
3761 &Controller->V1.DeviceState[Controller->V1.DeviceStateChannel]
3762 [Controller->V1.DeviceStateTargetID];
3763 DAC960_V1_DeviceState_T *NewDeviceState =
3764 Controller->V1.NewDeviceState;
3765 if (NewDeviceState->DeviceState != OldDeviceState->DeviceState)
3766 DAC960_Critical("Physical Device %d:%d is now %s\n", Controller,
3767 Controller->V1.DeviceStateChannel,
3768 Controller->V1.DeviceStateTargetID,
3769 (NewDeviceState->DeviceState
3770 == DAC960_V1_Device_Dead
3771 ? "DEAD"
3772 : NewDeviceState->DeviceState
3773 == DAC960_V1_Device_WriteOnly
3774 ? "WRITE-ONLY"
3775 : NewDeviceState->DeviceState
3776 == DAC960_V1_Device_Online
3777 ? "ONLINE" : "STANDBY"));
3778 if (OldDeviceState->DeviceState == DAC960_V1_Device_Dead &&
3779 NewDeviceState->DeviceState != DAC960_V1_Device_Dead)
3781 Controller->V1.NeedDeviceInquiryInformation = true;
3782 Controller->V1.NeedDeviceSerialNumberInformation = true;
3783 Controller->V1.DeviceResetCount
3784 [Controller->V1.DeviceStateChannel]
3785 [Controller->V1.DeviceStateTargetID] = 0;
3787 memcpy(OldDeviceState, NewDeviceState,
3788 sizeof(DAC960_V1_DeviceState_T));
3790 else if (CommandOpcode == DAC960_V1_GetLogicalDriveInformation)
3792 int LogicalDriveNumber;
3793 for (LogicalDriveNumber = 0;
3794 LogicalDriveNumber < Controller->LogicalDriveCount;
3795 LogicalDriveNumber++)
3797 DAC960_V1_LogicalDriveInformation_T *OldLogicalDriveInformation =
3798 &Controller->V1.LogicalDriveInformation[LogicalDriveNumber];
3799 DAC960_V1_LogicalDriveInformation_T *NewLogicalDriveInformation =
3800 &(*Controller->V1.NewLogicalDriveInformation)[LogicalDriveNumber];
3801 if (NewLogicalDriveInformation->LogicalDriveState !=
3802 OldLogicalDriveInformation->LogicalDriveState)
3803 DAC960_Critical("Logical Drive %d (/dev/rd/c%dd%d) "
3804 "is now %s\n", Controller,
3805 LogicalDriveNumber,
3806 Controller->ControllerNumber,
3807 LogicalDriveNumber,
3808 (NewLogicalDriveInformation->LogicalDriveState
3809 == DAC960_V1_LogicalDrive_Online
3810 ? "ONLINE"
3811 : NewLogicalDriveInformation->LogicalDriveState
3812 == DAC960_V1_LogicalDrive_Critical
3813 ? "CRITICAL" : "OFFLINE"));
3814 if (NewLogicalDriveInformation->WriteBack !=
3815 OldLogicalDriveInformation->WriteBack)
3816 DAC960_Critical("Logical Drive %d (/dev/rd/c%dd%d) "
3817 "is now %s\n", Controller,
3818 LogicalDriveNumber,
3819 Controller->ControllerNumber,
3820 LogicalDriveNumber,
3821 (NewLogicalDriveInformation->WriteBack
3822 ? "WRITE BACK" : "WRITE THRU"));
3824 memcpy(&Controller->V1.LogicalDriveInformation,
3825 Controller->V1.NewLogicalDriveInformation,
3826 sizeof(DAC960_V1_LogicalDriveInformationArray_T));
3828 else if (CommandOpcode == DAC960_V1_GetRebuildProgress)
3830 unsigned int LogicalDriveNumber =
3831 Controller->V1.RebuildProgress->LogicalDriveNumber;
3832 unsigned int LogicalDriveSize =
3833 Controller->V1.RebuildProgress->LogicalDriveSize;
3834 unsigned int BlocksCompleted =
3835 LogicalDriveSize - Controller->V1.RebuildProgress->RemainingBlocks;
3836 if (CommandStatus == DAC960_V1_NoRebuildOrCheckInProgress &&
3837 Controller->V1.LastRebuildStatus == DAC960_V1_NormalCompletion)
3838 CommandStatus = DAC960_V1_RebuildSuccessful;
3839 switch (CommandStatus)
3841 case DAC960_V1_NormalCompletion:
3842 Controller->EphemeralProgressMessage = true;
3843 DAC960_Progress("Rebuild in Progress: "
3844 "Logical Drive %d (/dev/rd/c%dd%d) "
3845 "%d%% completed\n",
3846 Controller, LogicalDriveNumber,
3847 Controller->ControllerNumber,
3848 LogicalDriveNumber,
3849 (100 * (BlocksCompleted >> 7))
3850 / (LogicalDriveSize >> 7));
3851 Controller->EphemeralProgressMessage = false;
3852 break;
3853 case DAC960_V1_RebuildFailed_LogicalDriveFailure:
3854 DAC960_Progress("Rebuild Failed due to "
3855 "Logical Drive Failure\n", Controller);
3856 break;
3857 case DAC960_V1_RebuildFailed_BadBlocksOnOther:
3858 DAC960_Progress("Rebuild Failed due to "
3859 "Bad Blocks on Other Drives\n", Controller);
3860 break;
3861 case DAC960_V1_RebuildFailed_NewDriveFailed:
3862 DAC960_Progress("Rebuild Failed due to "
3863 "Failure of Drive Being Rebuilt\n", Controller);
3864 break;
3865 case DAC960_V1_NoRebuildOrCheckInProgress:
3866 break;
3867 case DAC960_V1_RebuildSuccessful:
3868 DAC960_Progress("Rebuild Completed Successfully\n", Controller);
3869 break;
3870 case DAC960_V1_RebuildSuccessfullyTerminated:
3871 DAC960_Progress("Rebuild Successfully Terminated\n", Controller);
3872 break;
3874 Controller->V1.LastRebuildStatus = CommandStatus;
3875 if (CommandType != DAC960_MonitoringCommand &&
3876 Controller->V1.RebuildStatusPending)
3878 Command->V1.CommandStatus = Controller->V1.PendingRebuildStatus;
3879 Controller->V1.RebuildStatusPending = false;
3881 else if (CommandType == DAC960_MonitoringCommand &&
3882 CommandStatus != DAC960_V1_NormalCompletion &&
3883 CommandStatus != DAC960_V1_NoRebuildOrCheckInProgress)
3885 Controller->V1.PendingRebuildStatus = CommandStatus;
3886 Controller->V1.RebuildStatusPending = true;
3889 else if (CommandOpcode == DAC960_V1_RebuildStat)
3891 unsigned int LogicalDriveNumber =
3892 Controller->V1.RebuildProgress->LogicalDriveNumber;
3893 unsigned int LogicalDriveSize =
3894 Controller->V1.RebuildProgress->LogicalDriveSize;
3895 unsigned int BlocksCompleted =
3896 LogicalDriveSize - Controller->V1.RebuildProgress->RemainingBlocks;
3897 if (CommandStatus == DAC960_V1_NormalCompletion)
3899 Controller->EphemeralProgressMessage = true;
3900 DAC960_Progress("Consistency Check in Progress: "
3901 "Logical Drive %d (/dev/rd/c%dd%d) "
3902 "%d%% completed\n",
3903 Controller, LogicalDriveNumber,
3904 Controller->ControllerNumber,
3905 LogicalDriveNumber,
3906 (100 * (BlocksCompleted >> 7))
3907 / (LogicalDriveSize >> 7));
3908 Controller->EphemeralProgressMessage = false;
3911 else if (CommandOpcode == DAC960_V1_BackgroundInitializationControl)
3913 unsigned int LogicalDriveNumber =
3914 Controller->V1.BackgroundInitializationStatus->LogicalDriveNumber;
3915 unsigned int LogicalDriveSize =
3916 Controller->V1.BackgroundInitializationStatus->LogicalDriveSize;
3917 unsigned int BlocksCompleted =
3918 Controller->V1.BackgroundInitializationStatus->BlocksCompleted;
3919 switch (CommandStatus)
3921 case DAC960_V1_NormalCompletion:
3922 switch (Controller->V1.BackgroundInitializationStatus->Status)
3924 case DAC960_V1_BackgroundInitializationInvalid:
3925 break;
3926 case DAC960_V1_BackgroundInitializationStarted:
3927 DAC960_Progress("Background Initialization Started\n",
3928 Controller);
3929 break;
3930 case DAC960_V1_BackgroundInitializationInProgress:
3931 if (BlocksCompleted ==
3932 Controller->V1.LastBackgroundInitializationStatus.
3933 BlocksCompleted &&
3934 LogicalDriveNumber ==
3935 Controller->V1.LastBackgroundInitializationStatus.
3936 LogicalDriveNumber)
3937 break;
3938 Controller->EphemeralProgressMessage = true;
3939 DAC960_Progress("Background Initialization in Progress: "
3940 "Logical Drive %d (/dev/rd/c%dd%d) "
3941 "%d%% completed\n",
3942 Controller, LogicalDriveNumber,
3943 Controller->ControllerNumber,
3944 LogicalDriveNumber,
3945 (100 * (BlocksCompleted >> 7))
3946 / (LogicalDriveSize >> 7));
3947 Controller->EphemeralProgressMessage = false;
3948 break;
3949 case DAC960_V1_BackgroundInitializationSuspended:
3950 DAC960_Progress("Background Initialization Suspended\n",
3951 Controller);
3952 break;
3953 case DAC960_V1_BackgroundInitializationCancelled:
3954 DAC960_Progress("Background Initialization Cancelled\n",
3955 Controller);
3956 break;
3958 memcpy(&Controller->V1.LastBackgroundInitializationStatus,
3959 Controller->V1.BackgroundInitializationStatus,
3960 sizeof(DAC960_V1_BackgroundInitializationStatus_T));
3961 break;
3962 case DAC960_V1_BackgroundInitSuccessful:
3963 if (Controller->V1.BackgroundInitializationStatus->Status ==
3964 DAC960_V1_BackgroundInitializationInProgress)
3965 DAC960_Progress("Background Initialization "
3966 "Completed Successfully\n", Controller);
3967 Controller->V1.BackgroundInitializationStatus->Status =
3968 DAC960_V1_BackgroundInitializationInvalid;
3969 break;
3970 case DAC960_V1_BackgroundInitAborted:
3971 if (Controller->V1.BackgroundInitializationStatus->Status ==
3972 DAC960_V1_BackgroundInitializationInProgress)
3973 DAC960_Progress("Background Initialization Aborted\n",
3974 Controller);
3975 Controller->V1.BackgroundInitializationStatus->Status =
3976 DAC960_V1_BackgroundInitializationInvalid;
3977 break;
3978 case DAC960_V1_NoBackgroundInitInProgress:
3979 break;
3982 else if (CommandOpcode == DAC960_V1_DCDB)
3985 This is a bit ugly.
3987 The InquiryStandardData and
3988 the InquiryUntitSerialNumber information
3989 retrieval operations BOTH use the DAC960_V1_DCDB
3990 commands. the test above can't distinguish between
3991 these two cases.
3993 Instead, we rely on the order of code later in this
3994 function to ensure that DeviceInquiryInformation commands
3995 are submitted before DeviceSerialNumber commands.
3997 if (Controller->V1.NeedDeviceInquiryInformation)
3999 DAC960_SCSI_Inquiry_T *InquiryStandardData =
4000 &Controller->V1.InquiryStandardData
4001 [Controller->V1.DeviceStateChannel]
4002 [Controller->V1.DeviceStateTargetID];
4003 if (CommandStatus != DAC960_V1_NormalCompletion)
4005 memset(InquiryStandardData, 0,
4006 sizeof(DAC960_SCSI_Inquiry_T));
4007 InquiryStandardData->PeripheralDeviceType = 0x1F;
4009 else
4010 memcpy(InquiryStandardData,
4011 Controller->V1.NewInquiryStandardData,
4012 sizeof(DAC960_SCSI_Inquiry_T));
4013 Controller->V1.NeedDeviceInquiryInformation = false;
4015 else if (Controller->V1.NeedDeviceSerialNumberInformation)
4017 DAC960_SCSI_Inquiry_UnitSerialNumber_T *InquiryUnitSerialNumber =
4018 &Controller->V1.InquiryUnitSerialNumber
4019 [Controller->V1.DeviceStateChannel]
4020 [Controller->V1.DeviceStateTargetID];
4021 if (CommandStatus != DAC960_V1_NormalCompletion)
4023 memset(InquiryUnitSerialNumber, 0,
4024 sizeof(DAC960_SCSI_Inquiry_UnitSerialNumber_T));
4025 InquiryUnitSerialNumber->PeripheralDeviceType = 0x1F;
4027 else
4028 memcpy(InquiryUnitSerialNumber,
4029 Controller->V1.NewInquiryUnitSerialNumber,
4030 sizeof(DAC960_SCSI_Inquiry_UnitSerialNumber_T));
4031 Controller->V1.NeedDeviceSerialNumberInformation = false;
4035 Begin submitting new monitoring commands.
4037 if (Controller->V1.NewEventLogSequenceNumber
4038 - Controller->V1.OldEventLogSequenceNumber > 0)
4040 Command->V1.CommandMailbox.Type3E.CommandOpcode =
4041 DAC960_V1_PerformEventLogOperation;
4042 Command->V1.CommandMailbox.Type3E.OperationType =
4043 DAC960_V1_GetEventLogEntry;
4044 Command->V1.CommandMailbox.Type3E.OperationQualifier = 1;
4045 Command->V1.CommandMailbox.Type3E.SequenceNumber =
4046 Controller->V1.OldEventLogSequenceNumber;
4047 Command->V1.CommandMailbox.Type3E.BusAddress =
4048 Controller->V1.EventLogEntryDMA;
4049 DAC960_QueueCommand(Command);
4050 return;
4052 if (Controller->V1.NeedErrorTableInformation)
4054 Controller->V1.NeedErrorTableInformation = false;
4055 Command->V1.CommandMailbox.Type3.CommandOpcode =
4056 DAC960_V1_GetErrorTable;
4057 Command->V1.CommandMailbox.Type3.BusAddress =
4058 Controller->V1.NewErrorTableDMA;
4059 DAC960_QueueCommand(Command);
4060 return;
4062 if (Controller->V1.NeedRebuildProgress &&
4063 Controller->V1.RebuildProgressFirst)
4065 Controller->V1.NeedRebuildProgress = false;
4066 Command->V1.CommandMailbox.Type3.CommandOpcode =
4067 DAC960_V1_GetRebuildProgress;
4068 Command->V1.CommandMailbox.Type3.BusAddress =
4069 Controller->V1.RebuildProgressDMA;
4070 DAC960_QueueCommand(Command);
4071 return;
4073 if (Controller->V1.NeedDeviceStateInformation)
4075 if (Controller->V1.NeedDeviceInquiryInformation)
4077 DAC960_V1_DCDB_T *DCDB = Controller->V1.MonitoringDCDB;
4078 dma_addr_t DCDB_DMA = Controller->V1.MonitoringDCDB_DMA;
4080 dma_addr_t NewInquiryStandardDataDMA =
4081 Controller->V1.NewInquiryStandardDataDMA;
4083 Command->V1.CommandMailbox.Type3.CommandOpcode = DAC960_V1_DCDB;
4084 Command->V1.CommandMailbox.Type3.BusAddress = DCDB_DMA;
4085 DCDB->Channel = Controller->V1.DeviceStateChannel;
4086 DCDB->TargetID = Controller->V1.DeviceStateTargetID;
4087 DCDB->Direction = DAC960_V1_DCDB_DataTransferDeviceToSystem;
4088 DCDB->EarlyStatus = false;
4089 DCDB->Timeout = DAC960_V1_DCDB_Timeout_10_seconds;
4090 DCDB->NoAutomaticRequestSense = false;
4091 DCDB->DisconnectPermitted = true;
4092 DCDB->TransferLength = sizeof(DAC960_SCSI_Inquiry_T);
4093 DCDB->BusAddress = NewInquiryStandardDataDMA;
4094 DCDB->CDBLength = 6;
4095 DCDB->TransferLengthHigh4 = 0;
4096 DCDB->SenseLength = sizeof(DCDB->SenseData);
4097 DCDB->CDB[0] = 0x12; /* INQUIRY */
4098 DCDB->CDB[1] = 0; /* EVPD = 0 */
4099 DCDB->CDB[2] = 0; /* Page Code */
4100 DCDB->CDB[3] = 0; /* Reserved */
4101 DCDB->CDB[4] = sizeof(DAC960_SCSI_Inquiry_T);
4102 DCDB->CDB[5] = 0; /* Control */
4103 DAC960_QueueCommand(Command);
4104 return;
4106 if (Controller->V1.NeedDeviceSerialNumberInformation)
4108 DAC960_V1_DCDB_T *DCDB = Controller->V1.MonitoringDCDB;
4109 dma_addr_t DCDB_DMA = Controller->V1.MonitoringDCDB_DMA;
4110 dma_addr_t NewInquiryUnitSerialNumberDMA =
4111 Controller->V1.NewInquiryUnitSerialNumberDMA;
4113 Command->V1.CommandMailbox.Type3.CommandOpcode = DAC960_V1_DCDB;
4114 Command->V1.CommandMailbox.Type3.BusAddress = DCDB_DMA;
4115 DCDB->Channel = Controller->V1.DeviceStateChannel;
4116 DCDB->TargetID = Controller->V1.DeviceStateTargetID;
4117 DCDB->Direction = DAC960_V1_DCDB_DataTransferDeviceToSystem;
4118 DCDB->EarlyStatus = false;
4119 DCDB->Timeout = DAC960_V1_DCDB_Timeout_10_seconds;
4120 DCDB->NoAutomaticRequestSense = false;
4121 DCDB->DisconnectPermitted = true;
4122 DCDB->TransferLength =
4123 sizeof(DAC960_SCSI_Inquiry_UnitSerialNumber_T);
4124 DCDB->BusAddress = NewInquiryUnitSerialNumberDMA;
4125 DCDB->CDBLength = 6;
4126 DCDB->TransferLengthHigh4 = 0;
4127 DCDB->SenseLength = sizeof(DCDB->SenseData);
4128 DCDB->CDB[0] = 0x12; /* INQUIRY */
4129 DCDB->CDB[1] = 1; /* EVPD = 1 */
4130 DCDB->CDB[2] = 0x80; /* Page Code */
4131 DCDB->CDB[3] = 0; /* Reserved */
4132 DCDB->CDB[4] = sizeof(DAC960_SCSI_Inquiry_UnitSerialNumber_T);
4133 DCDB->CDB[5] = 0; /* Control */
4134 DAC960_QueueCommand(Command);
4135 return;
4137 if (Controller->V1.StartDeviceStateScan)
4139 Controller->V1.DeviceStateChannel = 0;
4140 Controller->V1.DeviceStateTargetID = 0;
4141 Controller->V1.StartDeviceStateScan = false;
4143 else if (++Controller->V1.DeviceStateTargetID == Controller->Targets)
4145 Controller->V1.DeviceStateChannel++;
4146 Controller->V1.DeviceStateTargetID = 0;
4148 if (Controller->V1.DeviceStateChannel < Controller->Channels)
4150 Controller->V1.NewDeviceState->DeviceState =
4151 DAC960_V1_Device_Dead;
4152 Command->V1.CommandMailbox.Type3D.CommandOpcode =
4153 DAC960_V1_GetDeviceState;
4154 Command->V1.CommandMailbox.Type3D.Channel =
4155 Controller->V1.DeviceStateChannel;
4156 Command->V1.CommandMailbox.Type3D.TargetID =
4157 Controller->V1.DeviceStateTargetID;
4158 Command->V1.CommandMailbox.Type3D.BusAddress =
4159 Controller->V1.NewDeviceStateDMA;
4160 DAC960_QueueCommand(Command);
4161 return;
4163 Controller->V1.NeedDeviceStateInformation = false;
4165 if (Controller->V1.NeedLogicalDriveInformation)
4167 Controller->V1.NeedLogicalDriveInformation = false;
4168 Command->V1.CommandMailbox.Type3.CommandOpcode =
4169 DAC960_V1_GetLogicalDriveInformation;
4170 Command->V1.CommandMailbox.Type3.BusAddress =
4171 Controller->V1.NewLogicalDriveInformationDMA;
4172 DAC960_QueueCommand(Command);
4173 return;
4175 if (Controller->V1.NeedRebuildProgress)
4177 Controller->V1.NeedRebuildProgress = false;
4178 Command->V1.CommandMailbox.Type3.CommandOpcode =
4179 DAC960_V1_GetRebuildProgress;
4180 Command->V1.CommandMailbox.Type3.BusAddress =
4181 Controller->V1.RebuildProgressDMA;
4182 DAC960_QueueCommand(Command);
4183 return;
4185 if (Controller->V1.NeedConsistencyCheckProgress)
4187 Controller->V1.NeedConsistencyCheckProgress = false;
4188 Command->V1.CommandMailbox.Type3.CommandOpcode =
4189 DAC960_V1_RebuildStat;
4190 Command->V1.CommandMailbox.Type3.BusAddress =
4191 Controller->V1.RebuildProgressDMA;
4192 DAC960_QueueCommand(Command);
4193 return;
4195 if (Controller->V1.NeedBackgroundInitializationStatus)
4197 Controller->V1.NeedBackgroundInitializationStatus = false;
4198 Command->V1.CommandMailbox.Type3B.CommandOpcode =
4199 DAC960_V1_BackgroundInitializationControl;
4200 Command->V1.CommandMailbox.Type3B.CommandOpcode2 = 0x20;
4201 Command->V1.CommandMailbox.Type3B.BusAddress =
4202 Controller->V1.BackgroundInitializationStatusDMA;
4203 DAC960_QueueCommand(Command);
4204 return;
4206 Controller->MonitoringTimerCount++;
4207 Controller->MonitoringTimer.expires =
4208 jiffies + DAC960_MonitoringTimerInterval;
4209 add_timer(&Controller->MonitoringTimer);
4211 if (CommandType == DAC960_ImmediateCommand)
4213 complete(Command->Completion);
4214 Command->Completion = NULL;
4215 return;
4217 if (CommandType == DAC960_QueuedCommand)
4219 DAC960_V1_KernelCommand_T *KernelCommand = Command->V1.KernelCommand;
4220 KernelCommand->CommandStatus = Command->V1.CommandStatus;
4221 Command->V1.KernelCommand = NULL;
4222 if (CommandOpcode == DAC960_V1_DCDB)
4223 Controller->V1.DirectCommandActive[KernelCommand->DCDB->Channel]
4224 [KernelCommand->DCDB->TargetID] =
4225 false;
4226 DAC960_DeallocateCommand(Command);
4227 KernelCommand->CompletionFunction(KernelCommand);
4228 return;
4231 Queue a Status Monitoring Command to the Controller using the just
4232 completed Command if one was deferred previously due to lack of a
4233 free Command when the Monitoring Timer Function was called.
4235 if (Controller->MonitoringCommandDeferred)
4237 Controller->MonitoringCommandDeferred = false;
4238 DAC960_V1_QueueMonitoringCommand(Command);
4239 return;
4242 Deallocate the Command.
4244 DAC960_DeallocateCommand(Command);
4246 Wake up any processes waiting on a free Command.
4248 wake_up(&Controller->CommandWaitQueue);
4253 DAC960_V2_ReadWriteError prints an appropriate error message for Command
4254 when an error occurs on a Read or Write operation.
4257 static void DAC960_V2_ReadWriteError(DAC960_Command_T *Command)
4259 DAC960_Controller_T *Controller = Command->Controller;
4260 unsigned char *SenseErrors[] = { "NO SENSE", "RECOVERED ERROR",
4261 "NOT READY", "MEDIUM ERROR",
4262 "HARDWARE ERROR", "ILLEGAL REQUEST",
4263 "UNIT ATTENTION", "DATA PROTECT",
4264 "BLANK CHECK", "VENDOR-SPECIFIC",
4265 "COPY ABORTED", "ABORTED COMMAND",
4266 "EQUAL", "VOLUME OVERFLOW",
4267 "MISCOMPARE", "RESERVED" };
4268 unsigned char *CommandName = "UNKNOWN";
4269 switch (Command->CommandType)
4271 case DAC960_ReadCommand:
4272 case DAC960_ReadRetryCommand:
4273 CommandName = "READ";
4274 break;
4275 case DAC960_WriteCommand:
4276 case DAC960_WriteRetryCommand:
4277 CommandName = "WRITE";
4278 break;
4279 case DAC960_MonitoringCommand:
4280 case DAC960_ImmediateCommand:
4281 case DAC960_QueuedCommand:
4282 break;
4284 DAC960_Error("Error Condition %s on %s:\n", Controller,
4285 SenseErrors[Command->V2.RequestSense->SenseKey], CommandName);
4286 DAC960_Error(" /dev/rd/c%dd%d: absolute blocks %u..%u\n",
4287 Controller, Controller->ControllerNumber,
4288 Command->LogicalDriveNumber, Command->BlockNumber,
4289 Command->BlockNumber + Command->BlockCount - 1);
4294 DAC960_V2_ReportEvent prints an appropriate message when a Controller Event
4295 occurs.
4298 static void DAC960_V2_ReportEvent(DAC960_Controller_T *Controller,
4299 DAC960_V2_Event_T *Event)
4301 DAC960_SCSI_RequestSense_T *RequestSense =
4302 (DAC960_SCSI_RequestSense_T *) &Event->RequestSenseData;
4303 unsigned char MessageBuffer[DAC960_LineBufferSize];
4304 static struct { int EventCode; unsigned char *EventMessage; } EventList[] =
4305 { /* Physical Device Events (0x0000 - 0x007F) */
4306 { 0x0001, "P Online" },
4307 { 0x0002, "P Standby" },
4308 { 0x0005, "P Automatic Rebuild Started" },
4309 { 0x0006, "P Manual Rebuild Started" },
4310 { 0x0007, "P Rebuild Completed" },
4311 { 0x0008, "P Rebuild Cancelled" },
4312 { 0x0009, "P Rebuild Failed for Unknown Reasons" },
4313 { 0x000A, "P Rebuild Failed due to New Physical Device" },
4314 { 0x000B, "P Rebuild Failed due to Logical Drive Failure" },
4315 { 0x000C, "S Offline" },
4316 { 0x000D, "P Found" },
4317 { 0x000E, "P Removed" },
4318 { 0x000F, "P Unconfigured" },
4319 { 0x0010, "P Expand Capacity Started" },
4320 { 0x0011, "P Expand Capacity Completed" },
4321 { 0x0012, "P Expand Capacity Failed" },
4322 { 0x0013, "P Command Timed Out" },
4323 { 0x0014, "P Command Aborted" },
4324 { 0x0015, "P Command Retried" },
4325 { 0x0016, "P Parity Error" },
4326 { 0x0017, "P Soft Error" },
4327 { 0x0018, "P Miscellaneous Error" },
4328 { 0x0019, "P Reset" },
4329 { 0x001A, "P Active Spare Found" },
4330 { 0x001B, "P Warm Spare Found" },
4331 { 0x001C, "S Sense Data Received" },
4332 { 0x001D, "P Initialization Started" },
4333 { 0x001E, "P Initialization Completed" },
4334 { 0x001F, "P Initialization Failed" },
4335 { 0x0020, "P Initialization Cancelled" },
4336 { 0x0021, "P Failed because Write Recovery Failed" },
4337 { 0x0022, "P Failed because SCSI Bus Reset Failed" },
4338 { 0x0023, "P Failed because of Double Check Condition" },
4339 { 0x0024, "P Failed because Device Cannot Be Accessed" },
4340 { 0x0025, "P Failed because of Gross Error on SCSI Processor" },
4341 { 0x0026, "P Failed because of Bad Tag from Device" },
4342 { 0x0027, "P Failed because of Command Timeout" },
4343 { 0x0028, "P Failed because of System Reset" },
4344 { 0x0029, "P Failed because of Busy Status or Parity Error" },
4345 { 0x002A, "P Failed because Host Set Device to Failed State" },
4346 { 0x002B, "P Failed because of Selection Timeout" },
4347 { 0x002C, "P Failed because of SCSI Bus Phase Error" },
4348 { 0x002D, "P Failed because Device Returned Unknown Status" },
4349 { 0x002E, "P Failed because Device Not Ready" },
4350 { 0x002F, "P Failed because Device Not Found at Startup" },
4351 { 0x0030, "P Failed because COD Write Operation Failed" },
4352 { 0x0031, "P Failed because BDT Write Operation Failed" },
4353 { 0x0039, "P Missing at Startup" },
4354 { 0x003A, "P Start Rebuild Failed due to Physical Drive Too Small" },
4355 { 0x003C, "P Temporarily Offline Device Automatically Made Online" },
4356 { 0x003D, "P Standby Rebuild Started" },
4357 /* Logical Device Events (0x0080 - 0x00FF) */
4358 { 0x0080, "M Consistency Check Started" },
4359 { 0x0081, "M Consistency Check Completed" },
4360 { 0x0082, "M Consistency Check Cancelled" },
4361 { 0x0083, "M Consistency Check Completed With Errors" },
4362 { 0x0084, "M Consistency Check Failed due to Logical Drive Failure" },
4363 { 0x0085, "M Consistency Check Failed due to Physical Device Failure" },
4364 { 0x0086, "L Offline" },
4365 { 0x0087, "L Critical" },
4366 { 0x0088, "L Online" },
4367 { 0x0089, "M Automatic Rebuild Started" },
4368 { 0x008A, "M Manual Rebuild Started" },
4369 { 0x008B, "M Rebuild Completed" },
4370 { 0x008C, "M Rebuild Cancelled" },
4371 { 0x008D, "M Rebuild Failed for Unknown Reasons" },
4372 { 0x008E, "M Rebuild Failed due to New Physical Device" },
4373 { 0x008F, "M Rebuild Failed due to Logical Drive Failure" },
4374 { 0x0090, "M Initialization Started" },
4375 { 0x0091, "M Initialization Completed" },
4376 { 0x0092, "M Initialization Cancelled" },
4377 { 0x0093, "M Initialization Failed" },
4378 { 0x0094, "L Found" },
4379 { 0x0095, "L Deleted" },
4380 { 0x0096, "M Expand Capacity Started" },
4381 { 0x0097, "M Expand Capacity Completed" },
4382 { 0x0098, "M Expand Capacity Failed" },
4383 { 0x0099, "L Bad Block Found" },
4384 { 0x009A, "L Size Changed" },
4385 { 0x009B, "L Type Changed" },
4386 { 0x009C, "L Bad Data Block Found" },
4387 { 0x009E, "L Read of Data Block in BDT" },
4388 { 0x009F, "L Write Back Data for Disk Block Lost" },
4389 { 0x00A0, "L Temporarily Offline RAID-5/3 Drive Made Online" },
4390 { 0x00A1, "L Temporarily Offline RAID-6/1/0/7 Drive Made Online" },
4391 { 0x00A2, "L Standby Rebuild Started" },
4392 /* Fault Management Events (0x0100 - 0x017F) */
4393 { 0x0140, "E Fan %d Failed" },
4394 { 0x0141, "E Fan %d OK" },
4395 { 0x0142, "E Fan %d Not Present" },
4396 { 0x0143, "E Power Supply %d Failed" },
4397 { 0x0144, "E Power Supply %d OK" },
4398 { 0x0145, "E Power Supply %d Not Present" },
4399 { 0x0146, "E Temperature Sensor %d Temperature Exceeds Safe Limit" },
4400 { 0x0147, "E Temperature Sensor %d Temperature Exceeds Working Limit" },
4401 { 0x0148, "E Temperature Sensor %d Temperature Normal" },
4402 { 0x0149, "E Temperature Sensor %d Not Present" },
4403 { 0x014A, "E Enclosure Management Unit %d Access Critical" },
4404 { 0x014B, "E Enclosure Management Unit %d Access OK" },
4405 { 0x014C, "E Enclosure Management Unit %d Access Offline" },
4406 /* Controller Events (0x0180 - 0x01FF) */
4407 { 0x0181, "C Cache Write Back Error" },
4408 { 0x0188, "C Battery Backup Unit Found" },
4409 { 0x0189, "C Battery Backup Unit Charge Level Low" },
4410 { 0x018A, "C Battery Backup Unit Charge Level OK" },
4411 { 0x0193, "C Installation Aborted" },
4412 { 0x0195, "C Battery Backup Unit Physically Removed" },
4413 { 0x0196, "C Memory Error During Warm Boot" },
4414 { 0x019E, "C Memory Soft ECC Error Corrected" },
4415 { 0x019F, "C Memory Hard ECC Error Corrected" },
4416 { 0x01A2, "C Battery Backup Unit Failed" },
4417 { 0x01AB, "C Mirror Race Recovery Failed" },
4418 { 0x01AC, "C Mirror Race on Critical Drive" },
4419 /* Controller Internal Processor Events */
4420 { 0x0380, "C Internal Controller Hung" },
4421 { 0x0381, "C Internal Controller Firmware Breakpoint" },
4422 { 0x0390, "C Internal Controller i960 Processor Specific Error" },
4423 { 0x03A0, "C Internal Controller StrongARM Processor Specific Error" },
4424 { 0, "" } };
4425 int EventListIndex = 0, EventCode;
4426 unsigned char EventType, *EventMessage;
4427 if (Event->EventCode == 0x1C &&
4428 RequestSense->SenseKey == DAC960_SenseKey_VendorSpecific &&
4429 (RequestSense->AdditionalSenseCode == 0x80 ||
4430 RequestSense->AdditionalSenseCode == 0x81))
4431 Event->EventCode = ((RequestSense->AdditionalSenseCode - 0x80) << 8) |
4432 RequestSense->AdditionalSenseCodeQualifier;
4433 while (true)
4435 EventCode = EventList[EventListIndex].EventCode;
4436 if (EventCode == Event->EventCode || EventCode == 0) break;
4437 EventListIndex++;
4439 EventType = EventList[EventListIndex].EventMessage[0];
4440 EventMessage = &EventList[EventListIndex].EventMessage[2];
4441 if (EventCode == 0)
4443 DAC960_Critical("Unknown Controller Event Code %04X\n",
4444 Controller, Event->EventCode);
4445 return;
4447 switch (EventType)
4449 case 'P':
4450 DAC960_Critical("Physical Device %d:%d %s\n", Controller,
4451 Event->Channel, Event->TargetID, EventMessage);
4452 break;
4453 case 'L':
4454 DAC960_Critical("Logical Drive %d (/dev/rd/c%dd%d) %s\n", Controller,
4455 Event->LogicalUnit, Controller->ControllerNumber,
4456 Event->LogicalUnit, EventMessage);
4457 break;
4458 case 'M':
4459 DAC960_Progress("Logical Drive %d (/dev/rd/c%dd%d) %s\n", Controller,
4460 Event->LogicalUnit, Controller->ControllerNumber,
4461 Event->LogicalUnit, EventMessage);
4462 break;
4463 case 'S':
4464 if (RequestSense->SenseKey == DAC960_SenseKey_NoSense ||
4465 (RequestSense->SenseKey == DAC960_SenseKey_NotReady &&
4466 RequestSense->AdditionalSenseCode == 0x04 &&
4467 (RequestSense->AdditionalSenseCodeQualifier == 0x01 ||
4468 RequestSense->AdditionalSenseCodeQualifier == 0x02)))
4469 break;
4470 DAC960_Critical("Physical Device %d:%d %s\n", Controller,
4471 Event->Channel, Event->TargetID, EventMessage);
4472 DAC960_Critical("Physical Device %d:%d Request Sense: "
4473 "Sense Key = %X, ASC = %02X, ASCQ = %02X\n",
4474 Controller,
4475 Event->Channel,
4476 Event->TargetID,
4477 RequestSense->SenseKey,
4478 RequestSense->AdditionalSenseCode,
4479 RequestSense->AdditionalSenseCodeQualifier);
4480 DAC960_Critical("Physical Device %d:%d Request Sense: "
4481 "Information = %02X%02X%02X%02X "
4482 "%02X%02X%02X%02X\n",
4483 Controller,
4484 Event->Channel,
4485 Event->TargetID,
4486 RequestSense->Information[0],
4487 RequestSense->Information[1],
4488 RequestSense->Information[2],
4489 RequestSense->Information[3],
4490 RequestSense->CommandSpecificInformation[0],
4491 RequestSense->CommandSpecificInformation[1],
4492 RequestSense->CommandSpecificInformation[2],
4493 RequestSense->CommandSpecificInformation[3]);
4494 break;
4495 case 'E':
4496 if (Controller->SuppressEnclosureMessages) break;
4497 sprintf(MessageBuffer, EventMessage, Event->LogicalUnit);
4498 DAC960_Critical("Enclosure %d %s\n", Controller,
4499 Event->TargetID, MessageBuffer);
4500 break;
4501 case 'C':
4502 DAC960_Critical("Controller %s\n", Controller, EventMessage);
4503 break;
4504 default:
4505 DAC960_Critical("Unknown Controller Event Code %04X\n",
4506 Controller, Event->EventCode);
4507 break;
4513 DAC960_V2_ReportProgress prints an appropriate progress message for
4514 Logical Device Long Operations.
4517 static void DAC960_V2_ReportProgress(DAC960_Controller_T *Controller,
4518 unsigned char *MessageString,
4519 unsigned int LogicalDeviceNumber,
4520 unsigned long BlocksCompleted,
4521 unsigned long LogicalDeviceSize)
4523 Controller->EphemeralProgressMessage = true;
4524 DAC960_Progress("%s in Progress: Logical Drive %d (/dev/rd/c%dd%d) "
4525 "%d%% completed\n", Controller,
4526 MessageString,
4527 LogicalDeviceNumber,
4528 Controller->ControllerNumber,
4529 LogicalDeviceNumber,
4530 (100 * (BlocksCompleted >> 7)) / (LogicalDeviceSize >> 7));
4531 Controller->EphemeralProgressMessage = false;
4536 DAC960_V2_ProcessCompletedCommand performs completion processing for Command
4537 for DAC960 V2 Firmware Controllers.
4540 static void DAC960_V2_ProcessCompletedCommand(DAC960_Command_T *Command)
4542 DAC960_Controller_T *Controller = Command->Controller;
4543 DAC960_CommandType_T CommandType = Command->CommandType;
4544 DAC960_V2_CommandMailbox_T *CommandMailbox = &Command->V2.CommandMailbox;
4545 DAC960_V2_IOCTL_Opcode_T CommandOpcode = CommandMailbox->Common.IOCTL_Opcode;
4546 DAC960_V2_CommandStatus_T CommandStatus = Command->V2.CommandStatus;
4548 if (CommandType == DAC960_ReadCommand ||
4549 CommandType == DAC960_WriteCommand)
4552 #ifdef FORCE_RETRY_DEBUG
4553 CommandStatus = DAC960_V2_AbormalCompletion;
4554 #endif
4555 Command->V2.RequestSense->SenseKey = DAC960_SenseKey_MediumError;
4557 if (CommandStatus == DAC960_V2_NormalCompletion) {
4559 if (!DAC960_ProcessCompletedRequest(Command, true))
4560 BUG();
4562 } else if (Command->V2.RequestSense->SenseKey == DAC960_SenseKey_MediumError)
4565 * break the command down into pieces and resubmit each
4566 * piece, hoping that some of them will succeed.
4568 DAC960_queue_partial_rw(Command);
4569 return;
4571 else
4573 if (Command->V2.RequestSense->SenseKey != DAC960_SenseKey_NotReady)
4574 DAC960_V2_ReadWriteError(Command);
4576 Perform completion processing for all buffers in this I/O Request.
4578 (void)DAC960_ProcessCompletedRequest(Command, false);
4581 else if (CommandType == DAC960_ReadRetryCommand ||
4582 CommandType == DAC960_WriteRetryCommand)
4584 boolean normal_completion;
4586 #ifdef FORCE_RETRY_FAILURE_DEBUG
4587 static int retry_count = 1;
4588 #endif
4590 Perform completion processing for the portion that was
4591 retried, and submit the next portion, if any.
4593 normal_completion = true;
4594 if (CommandStatus != DAC960_V2_NormalCompletion) {
4595 normal_completion = false;
4596 if (Command->V2.RequestSense->SenseKey != DAC960_SenseKey_NotReady)
4597 DAC960_V2_ReadWriteError(Command);
4600 #ifdef FORCE_RETRY_FAILURE_DEBUG
4601 if (!(++retry_count % 10000)) {
4602 printk("V2 error retry failure test\n");
4603 normal_completion = false;
4604 DAC960_V2_ReadWriteError(Command);
4606 #endif
4608 if (!DAC960_ProcessCompletedRequest(Command, normal_completion)) {
4609 DAC960_queue_partial_rw(Command);
4610 return;
4613 else if (CommandType == DAC960_MonitoringCommand)
4615 if (Controller->ShutdownMonitoringTimer)
4616 return;
4617 if (CommandOpcode == DAC960_V2_GetControllerInfo)
4619 DAC960_V2_ControllerInfo_T *NewControllerInfo =
4620 Controller->V2.NewControllerInformation;
4621 DAC960_V2_ControllerInfo_T *ControllerInfo =
4622 &Controller->V2.ControllerInformation;
4623 Controller->LogicalDriveCount =
4624 NewControllerInfo->LogicalDevicesPresent;
4625 Controller->V2.NeedLogicalDeviceInformation = true;
4626 Controller->V2.NeedPhysicalDeviceInformation = true;
4627 Controller->V2.StartLogicalDeviceInformationScan = true;
4628 Controller->V2.StartPhysicalDeviceInformationScan = true;
4629 Controller->MonitoringAlertMode =
4630 (NewControllerInfo->LogicalDevicesCritical > 0 ||
4631 NewControllerInfo->LogicalDevicesOffline > 0 ||
4632 NewControllerInfo->PhysicalDisksCritical > 0 ||
4633 NewControllerInfo->PhysicalDisksOffline > 0);
4634 memcpy(ControllerInfo, NewControllerInfo,
4635 sizeof(DAC960_V2_ControllerInfo_T));
4637 else if (CommandOpcode == DAC960_V2_GetEvent)
4639 if (CommandStatus == DAC960_V2_NormalCompletion) {
4640 DAC960_V2_ReportEvent(Controller, Controller->V2.Event);
4642 Controller->V2.NextEventSequenceNumber++;
4644 else if (CommandOpcode == DAC960_V2_GetPhysicalDeviceInfoValid &&
4645 CommandStatus == DAC960_V2_NormalCompletion)
4647 DAC960_V2_PhysicalDeviceInfo_T *NewPhysicalDeviceInfo =
4648 Controller->V2.NewPhysicalDeviceInformation;
4649 unsigned int PhysicalDeviceIndex = Controller->V2.PhysicalDeviceIndex;
4650 DAC960_V2_PhysicalDeviceInfo_T *PhysicalDeviceInfo =
4651 Controller->V2.PhysicalDeviceInformation[PhysicalDeviceIndex];
4652 DAC960_SCSI_Inquiry_UnitSerialNumber_T *InquiryUnitSerialNumber =
4653 Controller->V2.InquiryUnitSerialNumber[PhysicalDeviceIndex];
4654 unsigned int DeviceIndex;
4655 while (PhysicalDeviceInfo != NULL &&
4656 (NewPhysicalDeviceInfo->Channel >
4657 PhysicalDeviceInfo->Channel ||
4658 (NewPhysicalDeviceInfo->Channel ==
4659 PhysicalDeviceInfo->Channel &&
4660 (NewPhysicalDeviceInfo->TargetID >
4661 PhysicalDeviceInfo->TargetID ||
4662 (NewPhysicalDeviceInfo->TargetID ==
4663 PhysicalDeviceInfo->TargetID &&
4664 NewPhysicalDeviceInfo->LogicalUnit >
4665 PhysicalDeviceInfo->LogicalUnit)))))
4667 DAC960_Critical("Physical Device %d:%d No Longer Exists\n",
4668 Controller,
4669 PhysicalDeviceInfo->Channel,
4670 PhysicalDeviceInfo->TargetID);
4671 Controller->V2.PhysicalDeviceInformation
4672 [PhysicalDeviceIndex] = NULL;
4673 Controller->V2.InquiryUnitSerialNumber
4674 [PhysicalDeviceIndex] = NULL;
4675 kfree(PhysicalDeviceInfo);
4676 kfree(InquiryUnitSerialNumber);
4677 for (DeviceIndex = PhysicalDeviceIndex;
4678 DeviceIndex < DAC960_V2_MaxPhysicalDevices - 1;
4679 DeviceIndex++)
4681 Controller->V2.PhysicalDeviceInformation[DeviceIndex] =
4682 Controller->V2.PhysicalDeviceInformation[DeviceIndex+1];
4683 Controller->V2.InquiryUnitSerialNumber[DeviceIndex] =
4684 Controller->V2.InquiryUnitSerialNumber[DeviceIndex+1];
4686 Controller->V2.PhysicalDeviceInformation
4687 [DAC960_V2_MaxPhysicalDevices-1] = NULL;
4688 Controller->V2.InquiryUnitSerialNumber
4689 [DAC960_V2_MaxPhysicalDevices-1] = NULL;
4690 PhysicalDeviceInfo =
4691 Controller->V2.PhysicalDeviceInformation[PhysicalDeviceIndex];
4692 InquiryUnitSerialNumber =
4693 Controller->V2.InquiryUnitSerialNumber[PhysicalDeviceIndex];
4695 if (PhysicalDeviceInfo == NULL ||
4696 (NewPhysicalDeviceInfo->Channel !=
4697 PhysicalDeviceInfo->Channel) ||
4698 (NewPhysicalDeviceInfo->TargetID !=
4699 PhysicalDeviceInfo->TargetID) ||
4700 (NewPhysicalDeviceInfo->LogicalUnit !=
4701 PhysicalDeviceInfo->LogicalUnit))
4703 PhysicalDeviceInfo = (DAC960_V2_PhysicalDeviceInfo_T *)
4704 kmalloc(sizeof(DAC960_V2_PhysicalDeviceInfo_T), GFP_ATOMIC);
4705 InquiryUnitSerialNumber =
4706 (DAC960_SCSI_Inquiry_UnitSerialNumber_T *)
4707 kmalloc(sizeof(DAC960_SCSI_Inquiry_UnitSerialNumber_T),
4708 GFP_ATOMIC);
4709 if (InquiryUnitSerialNumber == NULL &&
4710 PhysicalDeviceInfo != NULL)
4712 kfree(PhysicalDeviceInfo);
4713 PhysicalDeviceInfo = NULL;
4715 DAC960_Critical("Physical Device %d:%d Now Exists%s\n",
4716 Controller,
4717 NewPhysicalDeviceInfo->Channel,
4718 NewPhysicalDeviceInfo->TargetID,
4719 (PhysicalDeviceInfo != NULL
4720 ? "" : " - Allocation Failed"));
4721 if (PhysicalDeviceInfo != NULL)
4723 memset(PhysicalDeviceInfo, 0,
4724 sizeof(DAC960_V2_PhysicalDeviceInfo_T));
4725 PhysicalDeviceInfo->PhysicalDeviceState =
4726 DAC960_V2_Device_InvalidState;
4727 memset(InquiryUnitSerialNumber, 0,
4728 sizeof(DAC960_SCSI_Inquiry_UnitSerialNumber_T));
4729 InquiryUnitSerialNumber->PeripheralDeviceType = 0x1F;
4730 for (DeviceIndex = DAC960_V2_MaxPhysicalDevices - 1;
4731 DeviceIndex > PhysicalDeviceIndex;
4732 DeviceIndex--)
4734 Controller->V2.PhysicalDeviceInformation[DeviceIndex] =
4735 Controller->V2.PhysicalDeviceInformation[DeviceIndex-1];
4736 Controller->V2.InquiryUnitSerialNumber[DeviceIndex] =
4737 Controller->V2.InquiryUnitSerialNumber[DeviceIndex-1];
4739 Controller->V2.PhysicalDeviceInformation
4740 [PhysicalDeviceIndex] =
4741 PhysicalDeviceInfo;
4742 Controller->V2.InquiryUnitSerialNumber
4743 [PhysicalDeviceIndex] =
4744 InquiryUnitSerialNumber;
4745 Controller->V2.NeedDeviceSerialNumberInformation = true;
4748 if (PhysicalDeviceInfo != NULL)
4750 if (NewPhysicalDeviceInfo->PhysicalDeviceState !=
4751 PhysicalDeviceInfo->PhysicalDeviceState)
4752 DAC960_Critical(
4753 "Physical Device %d:%d is now %s\n", Controller,
4754 NewPhysicalDeviceInfo->Channel,
4755 NewPhysicalDeviceInfo->TargetID,
4756 (NewPhysicalDeviceInfo->PhysicalDeviceState
4757 == DAC960_V2_Device_Online
4758 ? "ONLINE"
4759 : NewPhysicalDeviceInfo->PhysicalDeviceState
4760 == DAC960_V2_Device_Rebuild
4761 ? "REBUILD"
4762 : NewPhysicalDeviceInfo->PhysicalDeviceState
4763 == DAC960_V2_Device_Missing
4764 ? "MISSING"
4765 : NewPhysicalDeviceInfo->PhysicalDeviceState
4766 == DAC960_V2_Device_Critical
4767 ? "CRITICAL"
4768 : NewPhysicalDeviceInfo->PhysicalDeviceState
4769 == DAC960_V2_Device_Dead
4770 ? "DEAD"
4771 : NewPhysicalDeviceInfo->PhysicalDeviceState
4772 == DAC960_V2_Device_SuspectedDead
4773 ? "SUSPECTED-DEAD"
4774 : NewPhysicalDeviceInfo->PhysicalDeviceState
4775 == DAC960_V2_Device_CommandedOffline
4776 ? "COMMANDED-OFFLINE"
4777 : NewPhysicalDeviceInfo->PhysicalDeviceState
4778 == DAC960_V2_Device_Standby
4779 ? "STANDBY" : "UNKNOWN"));
4780 if ((NewPhysicalDeviceInfo->ParityErrors !=
4781 PhysicalDeviceInfo->ParityErrors) ||
4782 (NewPhysicalDeviceInfo->SoftErrors !=
4783 PhysicalDeviceInfo->SoftErrors) ||
4784 (NewPhysicalDeviceInfo->HardErrors !=
4785 PhysicalDeviceInfo->HardErrors) ||
4786 (NewPhysicalDeviceInfo->MiscellaneousErrors !=
4787 PhysicalDeviceInfo->MiscellaneousErrors) ||
4788 (NewPhysicalDeviceInfo->CommandTimeouts !=
4789 PhysicalDeviceInfo->CommandTimeouts) ||
4790 (NewPhysicalDeviceInfo->Retries !=
4791 PhysicalDeviceInfo->Retries) ||
4792 (NewPhysicalDeviceInfo->Aborts !=
4793 PhysicalDeviceInfo->Aborts) ||
4794 (NewPhysicalDeviceInfo->PredictedFailuresDetected !=
4795 PhysicalDeviceInfo->PredictedFailuresDetected))
4797 DAC960_Critical("Physical Device %d:%d Errors: "
4798 "Parity = %d, Soft = %d, "
4799 "Hard = %d, Misc = %d\n",
4800 Controller,
4801 NewPhysicalDeviceInfo->Channel,
4802 NewPhysicalDeviceInfo->TargetID,
4803 NewPhysicalDeviceInfo->ParityErrors,
4804 NewPhysicalDeviceInfo->SoftErrors,
4805 NewPhysicalDeviceInfo->HardErrors,
4806 NewPhysicalDeviceInfo->MiscellaneousErrors);
4807 DAC960_Critical("Physical Device %d:%d Errors: "
4808 "Timeouts = %d, Retries = %d, "
4809 "Aborts = %d, Predicted = %d\n",
4810 Controller,
4811 NewPhysicalDeviceInfo->Channel,
4812 NewPhysicalDeviceInfo->TargetID,
4813 NewPhysicalDeviceInfo->CommandTimeouts,
4814 NewPhysicalDeviceInfo->Retries,
4815 NewPhysicalDeviceInfo->Aborts,
4816 NewPhysicalDeviceInfo
4817 ->PredictedFailuresDetected);
4819 if ((PhysicalDeviceInfo->PhysicalDeviceState
4820 == DAC960_V2_Device_Dead ||
4821 PhysicalDeviceInfo->PhysicalDeviceState
4822 == DAC960_V2_Device_InvalidState) &&
4823 NewPhysicalDeviceInfo->PhysicalDeviceState
4824 != DAC960_V2_Device_Dead)
4825 Controller->V2.NeedDeviceSerialNumberInformation = true;
4826 memcpy(PhysicalDeviceInfo, NewPhysicalDeviceInfo,
4827 sizeof(DAC960_V2_PhysicalDeviceInfo_T));
4829 NewPhysicalDeviceInfo->LogicalUnit++;
4830 Controller->V2.PhysicalDeviceIndex++;
4832 else if (CommandOpcode == DAC960_V2_GetPhysicalDeviceInfoValid)
4834 unsigned int DeviceIndex;
4835 for (DeviceIndex = Controller->V2.PhysicalDeviceIndex;
4836 DeviceIndex < DAC960_V2_MaxPhysicalDevices;
4837 DeviceIndex++)
4839 DAC960_V2_PhysicalDeviceInfo_T *PhysicalDeviceInfo =
4840 Controller->V2.PhysicalDeviceInformation[DeviceIndex];
4841 DAC960_SCSI_Inquiry_UnitSerialNumber_T *InquiryUnitSerialNumber =
4842 Controller->V2.InquiryUnitSerialNumber[DeviceIndex];
4843 if (PhysicalDeviceInfo == NULL) break;
4844 DAC960_Critical("Physical Device %d:%d No Longer Exists\n",
4845 Controller,
4846 PhysicalDeviceInfo->Channel,
4847 PhysicalDeviceInfo->TargetID);
4848 Controller->V2.PhysicalDeviceInformation[DeviceIndex] = NULL;
4849 Controller->V2.InquiryUnitSerialNumber[DeviceIndex] = NULL;
4850 kfree(PhysicalDeviceInfo);
4851 kfree(InquiryUnitSerialNumber);
4853 Controller->V2.NeedPhysicalDeviceInformation = false;
4855 else if (CommandOpcode == DAC960_V2_GetLogicalDeviceInfoValid &&
4856 CommandStatus == DAC960_V2_NormalCompletion)
4858 DAC960_V2_LogicalDeviceInfo_T *NewLogicalDeviceInfo =
4859 Controller->V2.NewLogicalDeviceInformation;
4860 unsigned short LogicalDeviceNumber =
4861 NewLogicalDeviceInfo->LogicalDeviceNumber;
4862 DAC960_V2_LogicalDeviceInfo_T *LogicalDeviceInfo =
4863 Controller->V2.LogicalDeviceInformation[LogicalDeviceNumber];
4864 if (LogicalDeviceInfo == NULL)
4866 DAC960_V2_PhysicalDevice_T PhysicalDevice;
4867 PhysicalDevice.Controller = 0;
4868 PhysicalDevice.Channel = NewLogicalDeviceInfo->Channel;
4869 PhysicalDevice.TargetID = NewLogicalDeviceInfo->TargetID;
4870 PhysicalDevice.LogicalUnit = NewLogicalDeviceInfo->LogicalUnit;
4871 Controller->V2.LogicalDriveToVirtualDevice[LogicalDeviceNumber] =
4872 PhysicalDevice;
4873 LogicalDeviceInfo = (DAC960_V2_LogicalDeviceInfo_T *)
4874 kmalloc(sizeof(DAC960_V2_LogicalDeviceInfo_T), GFP_ATOMIC);
4875 Controller->V2.LogicalDeviceInformation[LogicalDeviceNumber] =
4876 LogicalDeviceInfo;
4877 DAC960_Critical("Logical Drive %d (/dev/rd/c%dd%d) "
4878 "Now Exists%s\n", Controller,
4879 LogicalDeviceNumber,
4880 Controller->ControllerNumber,
4881 LogicalDeviceNumber,
4882 (LogicalDeviceInfo != NULL
4883 ? "" : " - Allocation Failed"));
4884 if (LogicalDeviceInfo != NULL)
4886 memset(LogicalDeviceInfo, 0,
4887 sizeof(DAC960_V2_LogicalDeviceInfo_T));
4888 DAC960_ComputeGenericDiskInfo(Controller);
4891 if (LogicalDeviceInfo != NULL)
4893 unsigned long LogicalDeviceSize =
4894 NewLogicalDeviceInfo->ConfigurableDeviceSize;
4895 if (NewLogicalDeviceInfo->LogicalDeviceState !=
4896 LogicalDeviceInfo->LogicalDeviceState)
4897 DAC960_Critical("Logical Drive %d (/dev/rd/c%dd%d) "
4898 "is now %s\n", Controller,
4899 LogicalDeviceNumber,
4900 Controller->ControllerNumber,
4901 LogicalDeviceNumber,
4902 (NewLogicalDeviceInfo->LogicalDeviceState
4903 == DAC960_V2_LogicalDevice_Online
4904 ? "ONLINE"
4905 : NewLogicalDeviceInfo->LogicalDeviceState
4906 == DAC960_V2_LogicalDevice_Critical
4907 ? "CRITICAL" : "OFFLINE"));
4908 if ((NewLogicalDeviceInfo->SoftErrors !=
4909 LogicalDeviceInfo->SoftErrors) ||
4910 (NewLogicalDeviceInfo->CommandsFailed !=
4911 LogicalDeviceInfo->CommandsFailed) ||
4912 (NewLogicalDeviceInfo->DeferredWriteErrors !=
4913 LogicalDeviceInfo->DeferredWriteErrors))
4914 DAC960_Critical("Logical Drive %d (/dev/rd/c%dd%d) Errors: "
4915 "Soft = %d, Failed = %d, Deferred Write = %d\n",
4916 Controller, LogicalDeviceNumber,
4917 Controller->ControllerNumber,
4918 LogicalDeviceNumber,
4919 NewLogicalDeviceInfo->SoftErrors,
4920 NewLogicalDeviceInfo->CommandsFailed,
4921 NewLogicalDeviceInfo->DeferredWriteErrors);
4922 if (NewLogicalDeviceInfo->ConsistencyCheckInProgress)
4923 DAC960_V2_ReportProgress(Controller,
4924 "Consistency Check",
4925 LogicalDeviceNumber,
4926 NewLogicalDeviceInfo
4927 ->ConsistencyCheckBlockNumber,
4928 LogicalDeviceSize);
4929 else if (NewLogicalDeviceInfo->RebuildInProgress)
4930 DAC960_V2_ReportProgress(Controller,
4931 "Rebuild",
4932 LogicalDeviceNumber,
4933 NewLogicalDeviceInfo
4934 ->RebuildBlockNumber,
4935 LogicalDeviceSize);
4936 else if (NewLogicalDeviceInfo->BackgroundInitializationInProgress)
4937 DAC960_V2_ReportProgress(Controller,
4938 "Background Initialization",
4939 LogicalDeviceNumber,
4940 NewLogicalDeviceInfo
4941 ->BackgroundInitializationBlockNumber,
4942 LogicalDeviceSize);
4943 else if (NewLogicalDeviceInfo->ForegroundInitializationInProgress)
4944 DAC960_V2_ReportProgress(Controller,
4945 "Foreground Initialization",
4946 LogicalDeviceNumber,
4947 NewLogicalDeviceInfo
4948 ->ForegroundInitializationBlockNumber,
4949 LogicalDeviceSize);
4950 else if (NewLogicalDeviceInfo->DataMigrationInProgress)
4951 DAC960_V2_ReportProgress(Controller,
4952 "Data Migration",
4953 LogicalDeviceNumber,
4954 NewLogicalDeviceInfo
4955 ->DataMigrationBlockNumber,
4956 LogicalDeviceSize);
4957 else if (NewLogicalDeviceInfo->PatrolOperationInProgress)
4958 DAC960_V2_ReportProgress(Controller,
4959 "Patrol Operation",
4960 LogicalDeviceNumber,
4961 NewLogicalDeviceInfo
4962 ->PatrolOperationBlockNumber,
4963 LogicalDeviceSize);
4964 if (LogicalDeviceInfo->BackgroundInitializationInProgress &&
4965 !NewLogicalDeviceInfo->BackgroundInitializationInProgress)
4966 DAC960_Progress("Logical Drive %d (/dev/rd/c%dd%d) "
4967 "Background Initialization %s\n",
4968 Controller,
4969 LogicalDeviceNumber,
4970 Controller->ControllerNumber,
4971 LogicalDeviceNumber,
4972 (NewLogicalDeviceInfo->LogicalDeviceControl
4973 .LogicalDeviceInitialized
4974 ? "Completed" : "Failed"));
4975 memcpy(LogicalDeviceInfo, NewLogicalDeviceInfo,
4976 sizeof(DAC960_V2_LogicalDeviceInfo_T));
4978 Controller->V2.LogicalDriveFoundDuringScan
4979 [LogicalDeviceNumber] = true;
4980 NewLogicalDeviceInfo->LogicalDeviceNumber++;
4982 else if (CommandOpcode == DAC960_V2_GetLogicalDeviceInfoValid)
4984 int LogicalDriveNumber;
4985 for (LogicalDriveNumber = 0;
4986 LogicalDriveNumber < DAC960_MaxLogicalDrives;
4987 LogicalDriveNumber++)
4989 DAC960_V2_LogicalDeviceInfo_T *LogicalDeviceInfo =
4990 Controller->V2.LogicalDeviceInformation[LogicalDriveNumber];
4991 if (LogicalDeviceInfo == NULL ||
4992 Controller->V2.LogicalDriveFoundDuringScan
4993 [LogicalDriveNumber])
4994 continue;
4995 DAC960_Critical("Logical Drive %d (/dev/rd/c%dd%d) "
4996 "No Longer Exists\n", Controller,
4997 LogicalDriveNumber,
4998 Controller->ControllerNumber,
4999 LogicalDriveNumber);
5000 Controller->V2.LogicalDeviceInformation
5001 [LogicalDriveNumber] = NULL;
5002 kfree(LogicalDeviceInfo);
5003 Controller->LogicalDriveInitiallyAccessible
5004 [LogicalDriveNumber] = false;
5005 DAC960_ComputeGenericDiskInfo(Controller);
5007 Controller->V2.NeedLogicalDeviceInformation = false;
5009 else if (CommandOpcode == DAC960_V2_SCSI_10_Passthru)
5011 DAC960_SCSI_Inquiry_UnitSerialNumber_T *InquiryUnitSerialNumber =
5012 Controller->V2.InquiryUnitSerialNumber[Controller->V2.PhysicalDeviceIndex - 1];
5014 if (CommandStatus != DAC960_V2_NormalCompletion) {
5015 memset(InquiryUnitSerialNumber,
5016 0, sizeof(DAC960_SCSI_Inquiry_UnitSerialNumber_T));
5017 InquiryUnitSerialNumber->PeripheralDeviceType = 0x1F;
5018 } else
5019 memcpy(InquiryUnitSerialNumber,
5020 Controller->V2.NewInquiryUnitSerialNumber,
5021 sizeof(DAC960_SCSI_Inquiry_UnitSerialNumber_T));
5023 Controller->V2.NeedDeviceSerialNumberInformation = false;
5026 if (Controller->V2.HealthStatusBuffer->NextEventSequenceNumber
5027 - Controller->V2.NextEventSequenceNumber > 0)
5029 CommandMailbox->GetEvent.CommandOpcode = DAC960_V2_IOCTL;
5030 CommandMailbox->GetEvent.DataTransferSize = sizeof(DAC960_V2_Event_T);
5031 CommandMailbox->GetEvent.EventSequenceNumberHigh16 =
5032 Controller->V2.NextEventSequenceNumber >> 16;
5033 CommandMailbox->GetEvent.ControllerNumber = 0;
5034 CommandMailbox->GetEvent.IOCTL_Opcode =
5035 DAC960_V2_GetEvent;
5036 CommandMailbox->GetEvent.EventSequenceNumberLow16 =
5037 Controller->V2.NextEventSequenceNumber & 0xFFFF;
5038 CommandMailbox->GetEvent.DataTransferMemoryAddress
5039 .ScatterGatherSegments[0]
5040 .SegmentDataPointer =
5041 Controller->V2.EventDMA;
5042 CommandMailbox->GetEvent.DataTransferMemoryAddress
5043 .ScatterGatherSegments[0]
5044 .SegmentByteCount =
5045 CommandMailbox->GetEvent.DataTransferSize;
5046 DAC960_QueueCommand(Command);
5047 return;
5049 if (Controller->V2.NeedPhysicalDeviceInformation)
5051 if (Controller->V2.NeedDeviceSerialNumberInformation)
5053 DAC960_SCSI_Inquiry_UnitSerialNumber_T *InquiryUnitSerialNumber =
5054 Controller->V2.NewInquiryUnitSerialNumber;
5055 InquiryUnitSerialNumber->PeripheralDeviceType = 0x1F;
5057 DAC960_V2_ConstructNewUnitSerialNumber(Controller, CommandMailbox,
5058 Controller->V2.NewPhysicalDeviceInformation->Channel,
5059 Controller->V2.NewPhysicalDeviceInformation->TargetID,
5060 Controller->V2.NewPhysicalDeviceInformation->LogicalUnit - 1);
5063 DAC960_QueueCommand(Command);
5064 return;
5066 if (Controller->V2.StartPhysicalDeviceInformationScan)
5068 Controller->V2.PhysicalDeviceIndex = 0;
5069 Controller->V2.NewPhysicalDeviceInformation->Channel = 0;
5070 Controller->V2.NewPhysicalDeviceInformation->TargetID = 0;
5071 Controller->V2.NewPhysicalDeviceInformation->LogicalUnit = 0;
5072 Controller->V2.StartPhysicalDeviceInformationScan = false;
5074 CommandMailbox->PhysicalDeviceInfo.CommandOpcode = DAC960_V2_IOCTL;
5075 CommandMailbox->PhysicalDeviceInfo.DataTransferSize =
5076 sizeof(DAC960_V2_PhysicalDeviceInfo_T);
5077 CommandMailbox->PhysicalDeviceInfo.PhysicalDevice.LogicalUnit =
5078 Controller->V2.NewPhysicalDeviceInformation->LogicalUnit;
5079 CommandMailbox->PhysicalDeviceInfo.PhysicalDevice.TargetID =
5080 Controller->V2.NewPhysicalDeviceInformation->TargetID;
5081 CommandMailbox->PhysicalDeviceInfo.PhysicalDevice.Channel =
5082 Controller->V2.NewPhysicalDeviceInformation->Channel;
5083 CommandMailbox->PhysicalDeviceInfo.IOCTL_Opcode =
5084 DAC960_V2_GetPhysicalDeviceInfoValid;
5085 CommandMailbox->PhysicalDeviceInfo.DataTransferMemoryAddress
5086 .ScatterGatherSegments[0]
5087 .SegmentDataPointer =
5088 Controller->V2.NewPhysicalDeviceInformationDMA;
5089 CommandMailbox->PhysicalDeviceInfo.DataTransferMemoryAddress
5090 .ScatterGatherSegments[0]
5091 .SegmentByteCount =
5092 CommandMailbox->PhysicalDeviceInfo.DataTransferSize;
5093 DAC960_QueueCommand(Command);
5094 return;
5096 if (Controller->V2.NeedLogicalDeviceInformation)
5098 if (Controller->V2.StartLogicalDeviceInformationScan)
5100 int LogicalDriveNumber;
5101 for (LogicalDriveNumber = 0;
5102 LogicalDriveNumber < DAC960_MaxLogicalDrives;
5103 LogicalDriveNumber++)
5104 Controller->V2.LogicalDriveFoundDuringScan
5105 [LogicalDriveNumber] = false;
5106 Controller->V2.NewLogicalDeviceInformation->LogicalDeviceNumber = 0;
5107 Controller->V2.StartLogicalDeviceInformationScan = false;
5109 CommandMailbox->LogicalDeviceInfo.CommandOpcode = DAC960_V2_IOCTL;
5110 CommandMailbox->LogicalDeviceInfo.DataTransferSize =
5111 sizeof(DAC960_V2_LogicalDeviceInfo_T);
5112 CommandMailbox->LogicalDeviceInfo.LogicalDevice.LogicalDeviceNumber =
5113 Controller->V2.NewLogicalDeviceInformation->LogicalDeviceNumber;
5114 CommandMailbox->LogicalDeviceInfo.IOCTL_Opcode =
5115 DAC960_V2_GetLogicalDeviceInfoValid;
5116 CommandMailbox->LogicalDeviceInfo.DataTransferMemoryAddress
5117 .ScatterGatherSegments[0]
5118 .SegmentDataPointer =
5119 Controller->V2.NewLogicalDeviceInformationDMA;
5120 CommandMailbox->LogicalDeviceInfo.DataTransferMemoryAddress
5121 .ScatterGatherSegments[0]
5122 .SegmentByteCount =
5123 CommandMailbox->LogicalDeviceInfo.DataTransferSize;
5124 DAC960_QueueCommand(Command);
5125 return;
5127 Controller->MonitoringTimerCount++;
5128 Controller->MonitoringTimer.expires =
5129 jiffies + DAC960_HealthStatusMonitoringInterval;
5130 add_timer(&Controller->MonitoringTimer);
5132 if (CommandType == DAC960_ImmediateCommand)
5134 complete(Command->Completion);
5135 Command->Completion = NULL;
5136 return;
5138 if (CommandType == DAC960_QueuedCommand)
5140 DAC960_V2_KernelCommand_T *KernelCommand = Command->V2.KernelCommand;
5141 KernelCommand->CommandStatus = CommandStatus;
5142 KernelCommand->RequestSenseLength = Command->V2.RequestSenseLength;
5143 KernelCommand->DataTransferLength = Command->V2.DataTransferResidue;
5144 Command->V2.KernelCommand = NULL;
5145 DAC960_DeallocateCommand(Command);
5146 KernelCommand->CompletionFunction(KernelCommand);
5147 return;
5150 Queue a Status Monitoring Command to the Controller using the just
5151 completed Command if one was deferred previously due to lack of a
5152 free Command when the Monitoring Timer Function was called.
5154 if (Controller->MonitoringCommandDeferred)
5156 Controller->MonitoringCommandDeferred = false;
5157 DAC960_V2_QueueMonitoringCommand(Command);
5158 return;
5161 Deallocate the Command.
5163 DAC960_DeallocateCommand(Command);
5165 Wake up any processes waiting on a free Command.
5167 wake_up(&Controller->CommandWaitQueue);
5172 DAC960_BA_InterruptHandler handles hardware interrupts from DAC960 BA Series
5173 Controllers.
5176 static irqreturn_t DAC960_BA_InterruptHandler(int IRQ_Channel,
5177 void *DeviceIdentifier,
5178 struct pt_regs *InterruptRegisters)
5180 DAC960_Controller_T *Controller = (DAC960_Controller_T *) DeviceIdentifier;
5181 void *ControllerBaseAddress = Controller->BaseAddress;
5182 DAC960_V2_StatusMailbox_T *NextStatusMailbox;
5183 unsigned long flags;
5185 spin_lock_irqsave(&Controller->queue_lock, flags);
5186 DAC960_BA_AcknowledgeInterrupt(ControllerBaseAddress);
5187 NextStatusMailbox = Controller->V2.NextStatusMailbox;
5188 while (NextStatusMailbox->Fields.CommandIdentifier > 0)
5190 DAC960_V2_CommandIdentifier_T CommandIdentifier =
5191 NextStatusMailbox->Fields.CommandIdentifier;
5192 DAC960_Command_T *Command = Controller->Commands[CommandIdentifier-1];
5193 Command->V2.CommandStatus = NextStatusMailbox->Fields.CommandStatus;
5194 Command->V2.RequestSenseLength =
5195 NextStatusMailbox->Fields.RequestSenseLength;
5196 Command->V2.DataTransferResidue =
5197 NextStatusMailbox->Fields.DataTransferResidue;
5198 NextStatusMailbox->Words[0] = 0;
5199 if (++NextStatusMailbox > Controller->V2.LastStatusMailbox)
5200 NextStatusMailbox = Controller->V2.FirstStatusMailbox;
5201 DAC960_V2_ProcessCompletedCommand(Command);
5203 Controller->V2.NextStatusMailbox = NextStatusMailbox;
5205 Attempt to remove additional I/O Requests from the Controller's
5206 I/O Request Queue and queue them to the Controller.
5208 while (DAC960_ProcessRequest(Controller, false))
5210 spin_unlock_irqrestore(&Controller->queue_lock, flags);
5211 return IRQ_HANDLED;
5216 DAC960_LP_InterruptHandler handles hardware interrupts from DAC960 LP Series
5217 Controllers.
5220 static irqreturn_t DAC960_LP_InterruptHandler(int IRQ_Channel,
5221 void *DeviceIdentifier,
5222 struct pt_regs *InterruptRegisters)
5224 DAC960_Controller_T *Controller = (DAC960_Controller_T *) DeviceIdentifier;
5225 void *ControllerBaseAddress = Controller->BaseAddress;
5226 DAC960_V2_StatusMailbox_T *NextStatusMailbox;
5227 unsigned long flags;
5229 spin_lock_irqsave(&Controller->queue_lock, flags);
5230 DAC960_LP_AcknowledgeInterrupt(ControllerBaseAddress);
5231 NextStatusMailbox = Controller->V2.NextStatusMailbox;
5232 while (NextStatusMailbox->Fields.CommandIdentifier > 0)
5234 DAC960_V2_CommandIdentifier_T CommandIdentifier =
5235 NextStatusMailbox->Fields.CommandIdentifier;
5236 DAC960_Command_T *Command = Controller->Commands[CommandIdentifier-1];
5237 Command->V2.CommandStatus = NextStatusMailbox->Fields.CommandStatus;
5238 Command->V2.RequestSenseLength =
5239 NextStatusMailbox->Fields.RequestSenseLength;
5240 Command->V2.DataTransferResidue =
5241 NextStatusMailbox->Fields.DataTransferResidue;
5242 NextStatusMailbox->Words[0] = 0;
5243 if (++NextStatusMailbox > Controller->V2.LastStatusMailbox)
5244 NextStatusMailbox = Controller->V2.FirstStatusMailbox;
5245 DAC960_V2_ProcessCompletedCommand(Command);
5247 Controller->V2.NextStatusMailbox = NextStatusMailbox;
5249 Attempt to remove additional I/O Requests from the Controller's
5250 I/O Request Queue and queue them to the Controller.
5252 while (DAC960_ProcessRequest(Controller, false))
5254 spin_unlock_irqrestore(&Controller->queue_lock, flags);
5255 return IRQ_HANDLED;
5260 DAC960_LA_InterruptHandler handles hardware interrupts from DAC960 LA Series
5261 Controllers.
5264 static irqreturn_t DAC960_LA_InterruptHandler(int IRQ_Channel,
5265 void *DeviceIdentifier,
5266 struct pt_regs *InterruptRegisters)
5268 DAC960_Controller_T *Controller = (DAC960_Controller_T *) DeviceIdentifier;
5269 void *ControllerBaseAddress = Controller->BaseAddress;
5270 DAC960_V1_StatusMailbox_T *NextStatusMailbox;
5271 unsigned long flags;
5273 spin_lock_irqsave(&Controller->queue_lock, flags);
5274 DAC960_LA_AcknowledgeInterrupt(ControllerBaseAddress);
5275 NextStatusMailbox = Controller->V1.NextStatusMailbox;
5276 while (NextStatusMailbox->Fields.Valid)
5278 DAC960_V1_CommandIdentifier_T CommandIdentifier =
5279 NextStatusMailbox->Fields.CommandIdentifier;
5280 DAC960_Command_T *Command = Controller->Commands[CommandIdentifier-1];
5281 Command->V1.CommandStatus = NextStatusMailbox->Fields.CommandStatus;
5282 NextStatusMailbox->Word = 0;
5283 if (++NextStatusMailbox > Controller->V1.LastStatusMailbox)
5284 NextStatusMailbox = Controller->V1.FirstStatusMailbox;
5285 DAC960_V1_ProcessCompletedCommand(Command);
5287 Controller->V1.NextStatusMailbox = NextStatusMailbox;
5289 Attempt to remove additional I/O Requests from the Controller's
5290 I/O Request Queue and queue them to the Controller.
5292 while (DAC960_ProcessRequest(Controller, false))
5294 spin_unlock_irqrestore(&Controller->queue_lock, flags);
5295 return IRQ_HANDLED;
5300 DAC960_PG_InterruptHandler handles hardware interrupts from DAC960 PG Series
5301 Controllers.
5304 static irqreturn_t DAC960_PG_InterruptHandler(int IRQ_Channel,
5305 void *DeviceIdentifier,
5306 struct pt_regs *InterruptRegisters)
5308 DAC960_Controller_T *Controller = (DAC960_Controller_T *) DeviceIdentifier;
5309 void *ControllerBaseAddress = Controller->BaseAddress;
5310 DAC960_V1_StatusMailbox_T *NextStatusMailbox;
5311 unsigned long flags;
5313 spin_lock_irqsave(&Controller->queue_lock, flags);
5314 DAC960_PG_AcknowledgeInterrupt(ControllerBaseAddress);
5315 NextStatusMailbox = Controller->V1.NextStatusMailbox;
5316 while (NextStatusMailbox->Fields.Valid)
5318 DAC960_V1_CommandIdentifier_T CommandIdentifier =
5319 NextStatusMailbox->Fields.CommandIdentifier;
5320 DAC960_Command_T *Command = Controller->Commands[CommandIdentifier-1];
5321 Command->V1.CommandStatus = NextStatusMailbox->Fields.CommandStatus;
5322 NextStatusMailbox->Word = 0;
5323 if (++NextStatusMailbox > Controller->V1.LastStatusMailbox)
5324 NextStatusMailbox = Controller->V1.FirstStatusMailbox;
5325 DAC960_V1_ProcessCompletedCommand(Command);
5327 Controller->V1.NextStatusMailbox = NextStatusMailbox;
5329 Attempt to remove additional I/O Requests from the Controller's
5330 I/O Request Queue and queue them to the Controller.
5332 while (DAC960_ProcessRequest(Controller, false))
5334 spin_unlock_irqrestore(&Controller->queue_lock, flags);
5335 return IRQ_HANDLED;
5340 DAC960_PD_InterruptHandler handles hardware interrupts from DAC960 PD Series
5341 Controllers.
5344 static irqreturn_t DAC960_PD_InterruptHandler(int IRQ_Channel,
5345 void *DeviceIdentifier,
5346 struct pt_regs *InterruptRegisters)
5348 DAC960_Controller_T *Controller = (DAC960_Controller_T *) DeviceIdentifier;
5349 void *ControllerBaseAddress = Controller->BaseAddress;
5350 unsigned long flags;
5352 spin_lock_irqsave(&Controller->queue_lock, flags);
5353 while (DAC960_PD_StatusAvailableP(ControllerBaseAddress))
5355 DAC960_V1_CommandIdentifier_T CommandIdentifier =
5356 DAC960_PD_ReadStatusCommandIdentifier(ControllerBaseAddress);
5357 DAC960_Command_T *Command = Controller->Commands[CommandIdentifier-1];
5358 Command->V1.CommandStatus =
5359 DAC960_PD_ReadStatusRegister(ControllerBaseAddress);
5360 DAC960_PD_AcknowledgeInterrupt(ControllerBaseAddress);
5361 DAC960_PD_AcknowledgeStatus(ControllerBaseAddress);
5362 DAC960_V1_ProcessCompletedCommand(Command);
5365 Attempt to remove additional I/O Requests from the Controller's
5366 I/O Request Queue and queue them to the Controller.
5368 while (DAC960_ProcessRequest(Controller, false))
5370 spin_unlock_irqrestore(&Controller->queue_lock, flags);
5371 return IRQ_HANDLED;
5376 DAC960_P_InterruptHandler handles hardware interrupts from DAC960 P Series
5377 Controllers.
5379 Translations of DAC960_V1_Enquiry and DAC960_V1_GetDeviceState rely
5380 on the data having been placed into DAC960_Controller_T, rather than
5381 an arbitrary buffer.
5384 static irqreturn_t DAC960_P_InterruptHandler(int IRQ_Channel,
5385 void *DeviceIdentifier,
5386 struct pt_regs *InterruptRegisters)
5388 DAC960_Controller_T *Controller = (DAC960_Controller_T *) DeviceIdentifier;
5389 void *ControllerBaseAddress = Controller->BaseAddress;
5390 unsigned long flags;
5392 spin_lock_irqsave(&Controller->queue_lock, flags);
5393 while (DAC960_PD_StatusAvailableP(ControllerBaseAddress))
5395 DAC960_V1_CommandIdentifier_T CommandIdentifier =
5396 DAC960_PD_ReadStatusCommandIdentifier(ControllerBaseAddress);
5397 DAC960_Command_T *Command = Controller->Commands[CommandIdentifier-1];
5398 DAC960_V1_CommandMailbox_T *CommandMailbox = &Command->V1.CommandMailbox;
5399 DAC960_V1_CommandOpcode_T CommandOpcode =
5400 CommandMailbox->Common.CommandOpcode;
5401 Command->V1.CommandStatus =
5402 DAC960_PD_ReadStatusRegister(ControllerBaseAddress);
5403 DAC960_PD_AcknowledgeInterrupt(ControllerBaseAddress);
5404 DAC960_PD_AcknowledgeStatus(ControllerBaseAddress);
5405 switch (CommandOpcode)
5407 case DAC960_V1_Enquiry_Old:
5408 Command->V1.CommandMailbox.Common.CommandOpcode = DAC960_V1_Enquiry;
5409 DAC960_P_To_PD_TranslateEnquiry(Controller->V1.NewEnquiry);
5410 break;
5411 case DAC960_V1_GetDeviceState_Old:
5412 Command->V1.CommandMailbox.Common.CommandOpcode =
5413 DAC960_V1_GetDeviceState;
5414 DAC960_P_To_PD_TranslateDeviceState(Controller->V1.NewDeviceState);
5415 break;
5416 case DAC960_V1_Read_Old:
5417 Command->V1.CommandMailbox.Common.CommandOpcode = DAC960_V1_Read;
5418 DAC960_P_To_PD_TranslateReadWriteCommand(CommandMailbox);
5419 break;
5420 case DAC960_V1_Write_Old:
5421 Command->V1.CommandMailbox.Common.CommandOpcode = DAC960_V1_Write;
5422 DAC960_P_To_PD_TranslateReadWriteCommand(CommandMailbox);
5423 break;
5424 case DAC960_V1_ReadWithScatterGather_Old:
5425 Command->V1.CommandMailbox.Common.CommandOpcode =
5426 DAC960_V1_ReadWithScatterGather;
5427 DAC960_P_To_PD_TranslateReadWriteCommand(CommandMailbox);
5428 break;
5429 case DAC960_V1_WriteWithScatterGather_Old:
5430 Command->V1.CommandMailbox.Common.CommandOpcode =
5431 DAC960_V1_WriteWithScatterGather;
5432 DAC960_P_To_PD_TranslateReadWriteCommand(CommandMailbox);
5433 break;
5434 default:
5435 break;
5437 DAC960_V1_ProcessCompletedCommand(Command);
5440 Attempt to remove additional I/O Requests from the Controller's
5441 I/O Request Queue and queue them to the Controller.
5443 while (DAC960_ProcessRequest(Controller, false))
5445 spin_unlock_irqrestore(&Controller->queue_lock, flags);
5446 return IRQ_HANDLED;
5451 DAC960_V1_QueueMonitoringCommand queues a Monitoring Command to DAC960 V1
5452 Firmware Controllers.
5455 static void DAC960_V1_QueueMonitoringCommand(DAC960_Command_T *Command)
5457 DAC960_Controller_T *Controller = Command->Controller;
5458 DAC960_V1_CommandMailbox_T *CommandMailbox = &Command->V1.CommandMailbox;
5459 DAC960_V1_ClearCommand(Command);
5460 Command->CommandType = DAC960_MonitoringCommand;
5461 CommandMailbox->Type3.CommandOpcode = DAC960_V1_Enquiry;
5462 CommandMailbox->Type3.BusAddress = Controller->V1.NewEnquiryDMA;
5463 DAC960_QueueCommand(Command);
5468 DAC960_V2_QueueMonitoringCommand queues a Monitoring Command to DAC960 V2
5469 Firmware Controllers.
5472 static void DAC960_V2_QueueMonitoringCommand(DAC960_Command_T *Command)
5474 DAC960_Controller_T *Controller = Command->Controller;
5475 DAC960_V2_CommandMailbox_T *CommandMailbox = &Command->V2.CommandMailbox;
5476 DAC960_V2_ClearCommand(Command);
5477 Command->CommandType = DAC960_MonitoringCommand;
5478 CommandMailbox->ControllerInfo.CommandOpcode = DAC960_V2_IOCTL;
5479 CommandMailbox->ControllerInfo.CommandControlBits
5480 .DataTransferControllerToHost = true;
5481 CommandMailbox->ControllerInfo.CommandControlBits
5482 .NoAutoRequestSense = true;
5483 CommandMailbox->ControllerInfo.DataTransferSize =
5484 sizeof(DAC960_V2_ControllerInfo_T);
5485 CommandMailbox->ControllerInfo.ControllerNumber = 0;
5486 CommandMailbox->ControllerInfo.IOCTL_Opcode = DAC960_V2_GetControllerInfo;
5487 CommandMailbox->ControllerInfo.DataTransferMemoryAddress
5488 .ScatterGatherSegments[0]
5489 .SegmentDataPointer =
5490 Controller->V2.NewControllerInformationDMA;
5491 CommandMailbox->ControllerInfo.DataTransferMemoryAddress
5492 .ScatterGatherSegments[0]
5493 .SegmentByteCount =
5494 CommandMailbox->ControllerInfo.DataTransferSize;
5495 DAC960_QueueCommand(Command);
5500 DAC960_MonitoringTimerFunction is the timer function for monitoring
5501 the status of DAC960 Controllers.
5504 static void DAC960_MonitoringTimerFunction(unsigned long TimerData)
5506 DAC960_Controller_T *Controller = (DAC960_Controller_T *) TimerData;
5507 DAC960_Command_T *Command;
5508 unsigned long flags;
5510 if (Controller->FirmwareType == DAC960_V1_Controller)
5512 spin_lock_irqsave(&Controller->queue_lock, flags);
5514 Queue a Status Monitoring Command to Controller.
5516 Command = DAC960_AllocateCommand(Controller);
5517 if (Command != NULL)
5518 DAC960_V1_QueueMonitoringCommand(Command);
5519 else Controller->MonitoringCommandDeferred = true;
5520 spin_unlock_irqrestore(&Controller->queue_lock, flags);
5522 else
5524 DAC960_V2_ControllerInfo_T *ControllerInfo =
5525 &Controller->V2.ControllerInformation;
5526 unsigned int StatusChangeCounter =
5527 Controller->V2.HealthStatusBuffer->StatusChangeCounter;
5528 boolean ForceMonitoringCommand = false;
5529 if (jiffies - Controller->SecondaryMonitoringTime
5530 > DAC960_SecondaryMonitoringInterval)
5532 int LogicalDriveNumber;
5533 for (LogicalDriveNumber = 0;
5534 LogicalDriveNumber < DAC960_MaxLogicalDrives;
5535 LogicalDriveNumber++)
5537 DAC960_V2_LogicalDeviceInfo_T *LogicalDeviceInfo =
5538 Controller->V2.LogicalDeviceInformation[LogicalDriveNumber];
5539 if (LogicalDeviceInfo == NULL) continue;
5540 if (!LogicalDeviceInfo->LogicalDeviceControl
5541 .LogicalDeviceInitialized)
5543 ForceMonitoringCommand = true;
5544 break;
5547 Controller->SecondaryMonitoringTime = jiffies;
5549 if (StatusChangeCounter == Controller->V2.StatusChangeCounter &&
5550 Controller->V2.HealthStatusBuffer->NextEventSequenceNumber
5551 == Controller->V2.NextEventSequenceNumber &&
5552 (ControllerInfo->BackgroundInitializationsActive +
5553 ControllerInfo->LogicalDeviceInitializationsActive +
5554 ControllerInfo->PhysicalDeviceInitializationsActive +
5555 ControllerInfo->ConsistencyChecksActive +
5556 ControllerInfo->RebuildsActive +
5557 ControllerInfo->OnlineExpansionsActive == 0 ||
5558 jiffies - Controller->PrimaryMonitoringTime
5559 < DAC960_MonitoringTimerInterval) &&
5560 !ForceMonitoringCommand)
5562 Controller->MonitoringTimer.expires =
5563 jiffies + DAC960_HealthStatusMonitoringInterval;
5564 add_timer(&Controller->MonitoringTimer);
5565 return;
5567 Controller->V2.StatusChangeCounter = StatusChangeCounter;
5568 Controller->PrimaryMonitoringTime = jiffies;
5570 spin_lock_irqsave(&Controller->queue_lock, flags);
5572 Queue a Status Monitoring Command to Controller.
5574 Command = DAC960_AllocateCommand(Controller);
5575 if (Command != NULL)
5576 DAC960_V2_QueueMonitoringCommand(Command);
5577 else Controller->MonitoringCommandDeferred = true;
5578 spin_unlock_irqrestore(&Controller->queue_lock, flags);
5580 Wake up any processes waiting on a Health Status Buffer change.
5582 wake_up(&Controller->HealthStatusWaitQueue);
5587 DAC960_CheckStatusBuffer verifies that there is room to hold ByteCount
5588 additional bytes in the Combined Status Buffer and grows the buffer if
5589 necessary. It returns true if there is enough room and false otherwise.
5592 static boolean DAC960_CheckStatusBuffer(DAC960_Controller_T *Controller,
5593 unsigned int ByteCount)
5595 unsigned char *NewStatusBuffer;
5596 if (Controller->InitialStatusLength + 1 +
5597 Controller->CurrentStatusLength + ByteCount + 1 <=
5598 Controller->CombinedStatusBufferLength)
5599 return true;
5600 if (Controller->CombinedStatusBufferLength == 0)
5602 unsigned int NewStatusBufferLength = DAC960_InitialStatusBufferSize;
5603 while (NewStatusBufferLength < ByteCount)
5604 NewStatusBufferLength *= 2;
5605 Controller->CombinedStatusBuffer =
5606 (unsigned char *) kmalloc(NewStatusBufferLength, GFP_ATOMIC);
5607 if (Controller->CombinedStatusBuffer == NULL) return false;
5608 Controller->CombinedStatusBufferLength = NewStatusBufferLength;
5609 return true;
5611 NewStatusBuffer = (unsigned char *)
5612 kmalloc(2 * Controller->CombinedStatusBufferLength, GFP_ATOMIC);
5613 if (NewStatusBuffer == NULL)
5615 DAC960_Warning("Unable to expand Combined Status Buffer - Truncating\n",
5616 Controller);
5617 return false;
5619 memcpy(NewStatusBuffer, Controller->CombinedStatusBuffer,
5620 Controller->CombinedStatusBufferLength);
5621 kfree(Controller->CombinedStatusBuffer);
5622 Controller->CombinedStatusBuffer = NewStatusBuffer;
5623 Controller->CombinedStatusBufferLength *= 2;
5624 Controller->CurrentStatusBuffer =
5625 &NewStatusBuffer[Controller->InitialStatusLength + 1];
5626 return true;
5631 DAC960_Message prints Driver Messages.
5634 static void DAC960_Message(DAC960_MessageLevel_T MessageLevel,
5635 unsigned char *Format,
5636 DAC960_Controller_T *Controller,
5637 ...)
5639 static unsigned char Buffer[DAC960_LineBufferSize];
5640 static boolean BeginningOfLine = true;
5641 va_list Arguments;
5642 int Length = 0;
5643 va_start(Arguments, Controller);
5644 Length = vsprintf(Buffer, Format, Arguments);
5645 va_end(Arguments);
5646 if (Controller == NULL)
5647 printk("%sDAC960#%d: %s", DAC960_MessageLevelMap[MessageLevel],
5648 DAC960_ControllerCount, Buffer);
5649 else if (MessageLevel == DAC960_AnnounceLevel ||
5650 MessageLevel == DAC960_InfoLevel)
5652 if (!Controller->ControllerInitialized)
5654 if (DAC960_CheckStatusBuffer(Controller, Length))
5656 strcpy(&Controller->CombinedStatusBuffer
5657 [Controller->InitialStatusLength],
5658 Buffer);
5659 Controller->InitialStatusLength += Length;
5660 Controller->CurrentStatusBuffer =
5661 &Controller->CombinedStatusBuffer
5662 [Controller->InitialStatusLength + 1];
5664 if (MessageLevel == DAC960_AnnounceLevel)
5666 static int AnnouncementLines = 0;
5667 if (++AnnouncementLines <= 2)
5668 printk("%sDAC960: %s", DAC960_MessageLevelMap[MessageLevel],
5669 Buffer);
5671 else
5673 if (BeginningOfLine)
5675 if (Buffer[0] != '\n' || Length > 1)
5676 printk("%sDAC960#%d: %s",
5677 DAC960_MessageLevelMap[MessageLevel],
5678 Controller->ControllerNumber, Buffer);
5680 else printk("%s", Buffer);
5683 else if (DAC960_CheckStatusBuffer(Controller, Length))
5685 strcpy(&Controller->CurrentStatusBuffer[
5686 Controller->CurrentStatusLength], Buffer);
5687 Controller->CurrentStatusLength += Length;
5690 else if (MessageLevel == DAC960_ProgressLevel)
5692 strcpy(Controller->ProgressBuffer, Buffer);
5693 Controller->ProgressBufferLength = Length;
5694 if (Controller->EphemeralProgressMessage)
5696 if (jiffies - Controller->LastProgressReportTime
5697 >= DAC960_ProgressReportingInterval)
5699 printk("%sDAC960#%d: %s", DAC960_MessageLevelMap[MessageLevel],
5700 Controller->ControllerNumber, Buffer);
5701 Controller->LastProgressReportTime = jiffies;
5704 else printk("%sDAC960#%d: %s", DAC960_MessageLevelMap[MessageLevel],
5705 Controller->ControllerNumber, Buffer);
5707 else if (MessageLevel == DAC960_UserCriticalLevel)
5709 strcpy(&Controller->UserStatusBuffer[Controller->UserStatusLength],
5710 Buffer);
5711 Controller->UserStatusLength += Length;
5712 if (Buffer[0] != '\n' || Length > 1)
5713 printk("%sDAC960#%d: %s", DAC960_MessageLevelMap[MessageLevel],
5714 Controller->ControllerNumber, Buffer);
5716 else
5718 if (BeginningOfLine)
5719 printk("%sDAC960#%d: %s", DAC960_MessageLevelMap[MessageLevel],
5720 Controller->ControllerNumber, Buffer);
5721 else printk("%s", Buffer);
5723 BeginningOfLine = (Buffer[Length-1] == '\n');
5728 DAC960_ParsePhysicalDevice parses spaces followed by a Physical Device
5729 Channel:TargetID specification from a User Command string. It updates
5730 Channel and TargetID and returns true on success and false on failure.
5733 static boolean DAC960_ParsePhysicalDevice(DAC960_Controller_T *Controller,
5734 char *UserCommandString,
5735 unsigned char *Channel,
5736 unsigned char *TargetID)
5738 char *NewUserCommandString = UserCommandString;
5739 unsigned long XChannel, XTargetID;
5740 while (*UserCommandString == ' ') UserCommandString++;
5741 if (UserCommandString == NewUserCommandString)
5742 return false;
5743 XChannel = simple_strtoul(UserCommandString, &NewUserCommandString, 10);
5744 if (NewUserCommandString == UserCommandString ||
5745 *NewUserCommandString != ':' ||
5746 XChannel >= Controller->Channels)
5747 return false;
5748 UserCommandString = ++NewUserCommandString;
5749 XTargetID = simple_strtoul(UserCommandString, &NewUserCommandString, 10);
5750 if (NewUserCommandString == UserCommandString ||
5751 *NewUserCommandString != '\0' ||
5752 XTargetID >= Controller->Targets)
5753 return false;
5754 *Channel = XChannel;
5755 *TargetID = XTargetID;
5756 return true;
5761 DAC960_ParseLogicalDrive parses spaces followed by a Logical Drive Number
5762 specification from a User Command string. It updates LogicalDriveNumber and
5763 returns true on success and false on failure.
5766 static boolean DAC960_ParseLogicalDrive(DAC960_Controller_T *Controller,
5767 char *UserCommandString,
5768 unsigned char *LogicalDriveNumber)
5770 char *NewUserCommandString = UserCommandString;
5771 unsigned long XLogicalDriveNumber;
5772 while (*UserCommandString == ' ') UserCommandString++;
5773 if (UserCommandString == NewUserCommandString)
5774 return false;
5775 XLogicalDriveNumber =
5776 simple_strtoul(UserCommandString, &NewUserCommandString, 10);
5777 if (NewUserCommandString == UserCommandString ||
5778 *NewUserCommandString != '\0' ||
5779 XLogicalDriveNumber > DAC960_MaxLogicalDrives - 1)
5780 return false;
5781 *LogicalDriveNumber = XLogicalDriveNumber;
5782 return true;
5787 DAC960_V1_SetDeviceState sets the Device State for a Physical Device for
5788 DAC960 V1 Firmware Controllers.
5791 static void DAC960_V1_SetDeviceState(DAC960_Controller_T *Controller,
5792 DAC960_Command_T *Command,
5793 unsigned char Channel,
5794 unsigned char TargetID,
5795 DAC960_V1_PhysicalDeviceState_T
5796 DeviceState,
5797 const unsigned char *DeviceStateString)
5799 DAC960_V1_CommandMailbox_T *CommandMailbox = &Command->V1.CommandMailbox;
5800 CommandMailbox->Type3D.CommandOpcode = DAC960_V1_StartDevice;
5801 CommandMailbox->Type3D.Channel = Channel;
5802 CommandMailbox->Type3D.TargetID = TargetID;
5803 CommandMailbox->Type3D.DeviceState = DeviceState;
5804 CommandMailbox->Type3D.Modifier = 0;
5805 DAC960_ExecuteCommand(Command);
5806 switch (Command->V1.CommandStatus)
5808 case DAC960_V1_NormalCompletion:
5809 DAC960_UserCritical("%s of Physical Device %d:%d Succeeded\n", Controller,
5810 DeviceStateString, Channel, TargetID);
5811 break;
5812 case DAC960_V1_UnableToStartDevice:
5813 DAC960_UserCritical("%s of Physical Device %d:%d Failed - "
5814 "Unable to Start Device\n", Controller,
5815 DeviceStateString, Channel, TargetID);
5816 break;
5817 case DAC960_V1_NoDeviceAtAddress:
5818 DAC960_UserCritical("%s of Physical Device %d:%d Failed - "
5819 "No Device at Address\n", Controller,
5820 DeviceStateString, Channel, TargetID);
5821 break;
5822 case DAC960_V1_InvalidChannelOrTargetOrModifier:
5823 DAC960_UserCritical("%s of Physical Device %d:%d Failed - "
5824 "Invalid Channel or Target or Modifier\n",
5825 Controller, DeviceStateString, Channel, TargetID);
5826 break;
5827 case DAC960_V1_ChannelBusy:
5828 DAC960_UserCritical("%s of Physical Device %d:%d Failed - "
5829 "Channel Busy\n", Controller,
5830 DeviceStateString, Channel, TargetID);
5831 break;
5832 default:
5833 DAC960_UserCritical("%s of Physical Device %d:%d Failed - "
5834 "Unexpected Status %04X\n", Controller,
5835 DeviceStateString, Channel, TargetID,
5836 Command->V1.CommandStatus);
5837 break;
5843 DAC960_V1_ExecuteUserCommand executes a User Command for DAC960 V1 Firmware
5844 Controllers.
5847 static boolean DAC960_V1_ExecuteUserCommand(DAC960_Controller_T *Controller,
5848 unsigned char *UserCommand)
5850 DAC960_Command_T *Command;
5851 DAC960_V1_CommandMailbox_T *CommandMailbox;
5852 unsigned long flags;
5853 unsigned char Channel, TargetID, LogicalDriveNumber;
5855 spin_lock_irqsave(&Controller->queue_lock, flags);
5856 while ((Command = DAC960_AllocateCommand(Controller)) == NULL)
5857 DAC960_WaitForCommand(Controller);
5858 spin_unlock_irqrestore(&Controller->queue_lock, flags);
5859 Controller->UserStatusLength = 0;
5860 DAC960_V1_ClearCommand(Command);
5861 Command->CommandType = DAC960_ImmediateCommand;
5862 CommandMailbox = &Command->V1.CommandMailbox;
5863 if (strcmp(UserCommand, "flush-cache") == 0)
5865 CommandMailbox->Type3.CommandOpcode = DAC960_V1_Flush;
5866 DAC960_ExecuteCommand(Command);
5867 DAC960_UserCritical("Cache Flush Completed\n", Controller);
5869 else if (strncmp(UserCommand, "kill", 4) == 0 &&
5870 DAC960_ParsePhysicalDevice(Controller, &UserCommand[4],
5871 &Channel, &TargetID))
5873 DAC960_V1_DeviceState_T *DeviceState =
5874 &Controller->V1.DeviceState[Channel][TargetID];
5875 if (DeviceState->Present &&
5876 DeviceState->DeviceType == DAC960_V1_DiskType &&
5877 DeviceState->DeviceState != DAC960_V1_Device_Dead)
5878 DAC960_V1_SetDeviceState(Controller, Command, Channel, TargetID,
5879 DAC960_V1_Device_Dead, "Kill");
5880 else DAC960_UserCritical("Kill of Physical Device %d:%d Illegal\n",
5881 Controller, Channel, TargetID);
5883 else if (strncmp(UserCommand, "make-online", 11) == 0 &&
5884 DAC960_ParsePhysicalDevice(Controller, &UserCommand[11],
5885 &Channel, &TargetID))
5887 DAC960_V1_DeviceState_T *DeviceState =
5888 &Controller->V1.DeviceState[Channel][TargetID];
5889 if (DeviceState->Present &&
5890 DeviceState->DeviceType == DAC960_V1_DiskType &&
5891 DeviceState->DeviceState == DAC960_V1_Device_Dead)
5892 DAC960_V1_SetDeviceState(Controller, Command, Channel, TargetID,
5893 DAC960_V1_Device_Online, "Make Online");
5894 else DAC960_UserCritical("Make Online of Physical Device %d:%d Illegal\n",
5895 Controller, Channel, TargetID);
5898 else if (strncmp(UserCommand, "make-standby", 12) == 0 &&
5899 DAC960_ParsePhysicalDevice(Controller, &UserCommand[12],
5900 &Channel, &TargetID))
5902 DAC960_V1_DeviceState_T *DeviceState =
5903 &Controller->V1.DeviceState[Channel][TargetID];
5904 if (DeviceState->Present &&
5905 DeviceState->DeviceType == DAC960_V1_DiskType &&
5906 DeviceState->DeviceState == DAC960_V1_Device_Dead)
5907 DAC960_V1_SetDeviceState(Controller, Command, Channel, TargetID,
5908 DAC960_V1_Device_Standby, "Make Standby");
5909 else DAC960_UserCritical("Make Standby of Physical "
5910 "Device %d:%d Illegal\n",
5911 Controller, Channel, TargetID);
5913 else if (strncmp(UserCommand, "rebuild", 7) == 0 &&
5914 DAC960_ParsePhysicalDevice(Controller, &UserCommand[7],
5915 &Channel, &TargetID))
5917 CommandMailbox->Type3D.CommandOpcode = DAC960_V1_RebuildAsync;
5918 CommandMailbox->Type3D.Channel = Channel;
5919 CommandMailbox->Type3D.TargetID = TargetID;
5920 DAC960_ExecuteCommand(Command);
5921 switch (Command->V1.CommandStatus)
5923 case DAC960_V1_NormalCompletion:
5924 DAC960_UserCritical("Rebuild of Physical Device %d:%d Initiated\n",
5925 Controller, Channel, TargetID);
5926 break;
5927 case DAC960_V1_AttemptToRebuildOnlineDrive:
5928 DAC960_UserCritical("Rebuild of Physical Device %d:%d Failed - "
5929 "Attempt to Rebuild Online or "
5930 "Unresponsive Drive\n",
5931 Controller, Channel, TargetID);
5932 break;
5933 case DAC960_V1_NewDiskFailedDuringRebuild:
5934 DAC960_UserCritical("Rebuild of Physical Device %d:%d Failed - "
5935 "New Disk Failed During Rebuild\n",
5936 Controller, Channel, TargetID);
5937 break;
5938 case DAC960_V1_InvalidDeviceAddress:
5939 DAC960_UserCritical("Rebuild of Physical Device %d:%d Failed - "
5940 "Invalid Device Address\n",
5941 Controller, Channel, TargetID);
5942 break;
5943 case DAC960_V1_RebuildOrCheckAlreadyInProgress:
5944 DAC960_UserCritical("Rebuild of Physical Device %d:%d Failed - "
5945 "Rebuild or Consistency Check Already "
5946 "in Progress\n", Controller, Channel, TargetID);
5947 break;
5948 default:
5949 DAC960_UserCritical("Rebuild of Physical Device %d:%d Failed - "
5950 "Unexpected Status %04X\n", Controller,
5951 Channel, TargetID, Command->V1.CommandStatus);
5952 break;
5955 else if (strncmp(UserCommand, "check-consistency", 17) == 0 &&
5956 DAC960_ParseLogicalDrive(Controller, &UserCommand[17],
5957 &LogicalDriveNumber))
5959 CommandMailbox->Type3C.CommandOpcode = DAC960_V1_CheckConsistencyAsync;
5960 CommandMailbox->Type3C.LogicalDriveNumber = LogicalDriveNumber;
5961 CommandMailbox->Type3C.AutoRestore = true;
5962 DAC960_ExecuteCommand(Command);
5963 switch (Command->V1.CommandStatus)
5965 case DAC960_V1_NormalCompletion:
5966 DAC960_UserCritical("Consistency Check of Logical Drive %d "
5967 "(/dev/rd/c%dd%d) Initiated\n",
5968 Controller, LogicalDriveNumber,
5969 Controller->ControllerNumber,
5970 LogicalDriveNumber);
5971 break;
5972 case DAC960_V1_DependentDiskIsDead:
5973 DAC960_UserCritical("Consistency Check of Logical Drive %d "
5974 "(/dev/rd/c%dd%d) Failed - "
5975 "Dependent Physical Device is DEAD\n",
5976 Controller, LogicalDriveNumber,
5977 Controller->ControllerNumber,
5978 LogicalDriveNumber);
5979 break;
5980 case DAC960_V1_InvalidOrNonredundantLogicalDrive:
5981 DAC960_UserCritical("Consistency Check of Logical Drive %d "
5982 "(/dev/rd/c%dd%d) Failed - "
5983 "Invalid or Nonredundant Logical Drive\n",
5984 Controller, LogicalDriveNumber,
5985 Controller->ControllerNumber,
5986 LogicalDriveNumber);
5987 break;
5988 case DAC960_V1_RebuildOrCheckAlreadyInProgress:
5989 DAC960_UserCritical("Consistency Check of Logical Drive %d "
5990 "(/dev/rd/c%dd%d) Failed - Rebuild or "
5991 "Consistency Check Already in Progress\n",
5992 Controller, LogicalDriveNumber,
5993 Controller->ControllerNumber,
5994 LogicalDriveNumber);
5995 break;
5996 default:
5997 DAC960_UserCritical("Consistency Check of Logical Drive %d "
5998 "(/dev/rd/c%dd%d) Failed - "
5999 "Unexpected Status %04X\n",
6000 Controller, LogicalDriveNumber,
6001 Controller->ControllerNumber,
6002 LogicalDriveNumber, Command->V1.CommandStatus);
6003 break;
6006 else if (strcmp(UserCommand, "cancel-rebuild") == 0 ||
6007 strcmp(UserCommand, "cancel-consistency-check") == 0)
6010 the OldRebuildRateConstant is never actually used
6011 once its value is retrieved from the controller.
6013 unsigned char *OldRebuildRateConstant;
6014 dma_addr_t OldRebuildRateConstantDMA;
6016 OldRebuildRateConstant = pci_alloc_consistent( Controller->PCIDevice,
6017 sizeof(char), &OldRebuildRateConstantDMA);
6018 if (OldRebuildRateConstant == NULL) {
6019 DAC960_UserCritical("Cancellation of Rebuild or "
6020 "Consistency Check Failed - "
6021 "Out of Memory",
6022 Controller);
6023 goto failure;
6025 CommandMailbox->Type3R.CommandOpcode = DAC960_V1_RebuildControl;
6026 CommandMailbox->Type3R.RebuildRateConstant = 0xFF;
6027 CommandMailbox->Type3R.BusAddress = OldRebuildRateConstantDMA;
6028 DAC960_ExecuteCommand(Command);
6029 switch (Command->V1.CommandStatus)
6031 case DAC960_V1_NormalCompletion:
6032 DAC960_UserCritical("Rebuild or Consistency Check Cancelled\n",
6033 Controller);
6034 break;
6035 default:
6036 DAC960_UserCritical("Cancellation of Rebuild or "
6037 "Consistency Check Failed - "
6038 "Unexpected Status %04X\n",
6039 Controller, Command->V1.CommandStatus);
6040 break;
6042 failure:
6043 pci_free_consistent(Controller->PCIDevice, sizeof(char),
6044 OldRebuildRateConstant, OldRebuildRateConstantDMA);
6046 else DAC960_UserCritical("Illegal User Command: '%s'\n",
6047 Controller, UserCommand);
6049 spin_lock_irqsave(&Controller->queue_lock, flags);
6050 DAC960_DeallocateCommand(Command);
6051 spin_unlock_irqrestore(&Controller->queue_lock, flags);
6052 return true;
6057 DAC960_V2_TranslatePhysicalDevice translates a Physical Device Channel and
6058 TargetID into a Logical Device. It returns true on success and false
6059 on failure.
6062 static boolean DAC960_V2_TranslatePhysicalDevice(DAC960_Command_T *Command,
6063 unsigned char Channel,
6064 unsigned char TargetID,
6065 unsigned short
6066 *LogicalDeviceNumber)
6068 DAC960_V2_CommandMailbox_T SavedCommandMailbox, *CommandMailbox;
6069 DAC960_Controller_T *Controller = Command->Controller;
6071 CommandMailbox = &Command->V2.CommandMailbox;
6072 memcpy(&SavedCommandMailbox, CommandMailbox,
6073 sizeof(DAC960_V2_CommandMailbox_T));
6075 CommandMailbox->PhysicalDeviceInfo.CommandOpcode = DAC960_V2_IOCTL;
6076 CommandMailbox->PhysicalDeviceInfo.CommandControlBits
6077 .DataTransferControllerToHost = true;
6078 CommandMailbox->PhysicalDeviceInfo.CommandControlBits
6079 .NoAutoRequestSense = true;
6080 CommandMailbox->PhysicalDeviceInfo.DataTransferSize =
6081 sizeof(DAC960_V2_PhysicalToLogicalDevice_T);
6082 CommandMailbox->PhysicalDeviceInfo.PhysicalDevice.TargetID = TargetID;
6083 CommandMailbox->PhysicalDeviceInfo.PhysicalDevice.Channel = Channel;
6084 CommandMailbox->PhysicalDeviceInfo.IOCTL_Opcode =
6085 DAC960_V2_TranslatePhysicalToLogicalDevice;
6086 CommandMailbox->Common.DataTransferMemoryAddress
6087 .ScatterGatherSegments[0]
6088 .SegmentDataPointer =
6089 Controller->V2.PhysicalToLogicalDeviceDMA;
6090 CommandMailbox->Common.DataTransferMemoryAddress
6091 .ScatterGatherSegments[0]
6092 .SegmentByteCount =
6093 CommandMailbox->Common.DataTransferSize;
6095 DAC960_ExecuteCommand(Command);
6096 *LogicalDeviceNumber = Controller->V2.PhysicalToLogicalDevice->LogicalDeviceNumber;
6098 memcpy(CommandMailbox, &SavedCommandMailbox,
6099 sizeof(DAC960_V2_CommandMailbox_T));
6100 return (Command->V2.CommandStatus == DAC960_V2_NormalCompletion);
6105 DAC960_V2_ExecuteUserCommand executes a User Command for DAC960 V2 Firmware
6106 Controllers.
6109 static boolean DAC960_V2_ExecuteUserCommand(DAC960_Controller_T *Controller,
6110 unsigned char *UserCommand)
6112 DAC960_Command_T *Command;
6113 DAC960_V2_CommandMailbox_T *CommandMailbox;
6114 unsigned long flags;
6115 unsigned char Channel, TargetID, LogicalDriveNumber;
6116 unsigned short LogicalDeviceNumber;
6118 spin_lock_irqsave(&Controller->queue_lock, flags);
6119 while ((Command = DAC960_AllocateCommand(Controller)) == NULL)
6120 DAC960_WaitForCommand(Controller);
6121 spin_unlock_irqrestore(&Controller->queue_lock, flags);
6122 Controller->UserStatusLength = 0;
6123 DAC960_V2_ClearCommand(Command);
6124 Command->CommandType = DAC960_ImmediateCommand;
6125 CommandMailbox = &Command->V2.CommandMailbox;
6126 CommandMailbox->Common.CommandOpcode = DAC960_V2_IOCTL;
6127 CommandMailbox->Common.CommandControlBits.DataTransferControllerToHost = true;
6128 CommandMailbox->Common.CommandControlBits.NoAutoRequestSense = true;
6129 if (strcmp(UserCommand, "flush-cache") == 0)
6131 CommandMailbox->DeviceOperation.IOCTL_Opcode = DAC960_V2_PauseDevice;
6132 CommandMailbox->DeviceOperation.OperationDevice =
6133 DAC960_V2_RAID_Controller;
6134 DAC960_ExecuteCommand(Command);
6135 DAC960_UserCritical("Cache Flush Completed\n", Controller);
6137 else if (strncmp(UserCommand, "kill", 4) == 0 &&
6138 DAC960_ParsePhysicalDevice(Controller, &UserCommand[4],
6139 &Channel, &TargetID) &&
6140 DAC960_V2_TranslatePhysicalDevice(Command, Channel, TargetID,
6141 &LogicalDeviceNumber))
6143 CommandMailbox->SetDeviceState.LogicalDevice.LogicalDeviceNumber =
6144 LogicalDeviceNumber;
6145 CommandMailbox->SetDeviceState.IOCTL_Opcode =
6146 DAC960_V2_SetDeviceState;
6147 CommandMailbox->SetDeviceState.DeviceState.PhysicalDeviceState =
6148 DAC960_V2_Device_Dead;
6149 DAC960_ExecuteCommand(Command);
6150 DAC960_UserCritical("Kill of Physical Device %d:%d %s\n",
6151 Controller, Channel, TargetID,
6152 (Command->V2.CommandStatus
6153 == DAC960_V2_NormalCompletion
6154 ? "Succeeded" : "Failed"));
6156 else if (strncmp(UserCommand, "make-online", 11) == 0 &&
6157 DAC960_ParsePhysicalDevice(Controller, &UserCommand[11],
6158 &Channel, &TargetID) &&
6159 DAC960_V2_TranslatePhysicalDevice(Command, Channel, TargetID,
6160 &LogicalDeviceNumber))
6162 CommandMailbox->SetDeviceState.LogicalDevice.LogicalDeviceNumber =
6163 LogicalDeviceNumber;
6164 CommandMailbox->SetDeviceState.IOCTL_Opcode =
6165 DAC960_V2_SetDeviceState;
6166 CommandMailbox->SetDeviceState.DeviceState.PhysicalDeviceState =
6167 DAC960_V2_Device_Online;
6168 DAC960_ExecuteCommand(Command);
6169 DAC960_UserCritical("Make Online of Physical Device %d:%d %s\n",
6170 Controller, Channel, TargetID,
6171 (Command->V2.CommandStatus
6172 == DAC960_V2_NormalCompletion
6173 ? "Succeeded" : "Failed"));
6175 else if (strncmp(UserCommand, "make-standby", 12) == 0 &&
6176 DAC960_ParsePhysicalDevice(Controller, &UserCommand[12],
6177 &Channel, &TargetID) &&
6178 DAC960_V2_TranslatePhysicalDevice(Command, Channel, TargetID,
6179 &LogicalDeviceNumber))
6181 CommandMailbox->SetDeviceState.LogicalDevice.LogicalDeviceNumber =
6182 LogicalDeviceNumber;
6183 CommandMailbox->SetDeviceState.IOCTL_Opcode =
6184 DAC960_V2_SetDeviceState;
6185 CommandMailbox->SetDeviceState.DeviceState.PhysicalDeviceState =
6186 DAC960_V2_Device_Standby;
6187 DAC960_ExecuteCommand(Command);
6188 DAC960_UserCritical("Make Standby of Physical Device %d:%d %s\n",
6189 Controller, Channel, TargetID,
6190 (Command->V2.CommandStatus
6191 == DAC960_V2_NormalCompletion
6192 ? "Succeeded" : "Failed"));
6194 else if (strncmp(UserCommand, "rebuild", 7) == 0 &&
6195 DAC960_ParsePhysicalDevice(Controller, &UserCommand[7],
6196 &Channel, &TargetID) &&
6197 DAC960_V2_TranslatePhysicalDevice(Command, Channel, TargetID,
6198 &LogicalDeviceNumber))
6200 CommandMailbox->LogicalDeviceInfo.LogicalDevice.LogicalDeviceNumber =
6201 LogicalDeviceNumber;
6202 CommandMailbox->LogicalDeviceInfo.IOCTL_Opcode =
6203 DAC960_V2_RebuildDeviceStart;
6204 DAC960_ExecuteCommand(Command);
6205 DAC960_UserCritical("Rebuild of Physical Device %d:%d %s\n",
6206 Controller, Channel, TargetID,
6207 (Command->V2.CommandStatus
6208 == DAC960_V2_NormalCompletion
6209 ? "Initiated" : "Not Initiated"));
6211 else if (strncmp(UserCommand, "cancel-rebuild", 14) == 0 &&
6212 DAC960_ParsePhysicalDevice(Controller, &UserCommand[14],
6213 &Channel, &TargetID) &&
6214 DAC960_V2_TranslatePhysicalDevice(Command, Channel, TargetID,
6215 &LogicalDeviceNumber))
6217 CommandMailbox->LogicalDeviceInfo.LogicalDevice.LogicalDeviceNumber =
6218 LogicalDeviceNumber;
6219 CommandMailbox->LogicalDeviceInfo.IOCTL_Opcode =
6220 DAC960_V2_RebuildDeviceStop;
6221 DAC960_ExecuteCommand(Command);
6222 DAC960_UserCritical("Rebuild of Physical Device %d:%d %s\n",
6223 Controller, Channel, TargetID,
6224 (Command->V2.CommandStatus
6225 == DAC960_V2_NormalCompletion
6226 ? "Cancelled" : "Not Cancelled"));
6228 else if (strncmp(UserCommand, "check-consistency", 17) == 0 &&
6229 DAC960_ParseLogicalDrive(Controller, &UserCommand[17],
6230 &LogicalDriveNumber))
6232 CommandMailbox->ConsistencyCheck.LogicalDevice.LogicalDeviceNumber =
6233 LogicalDriveNumber;
6234 CommandMailbox->ConsistencyCheck.IOCTL_Opcode =
6235 DAC960_V2_ConsistencyCheckStart;
6236 CommandMailbox->ConsistencyCheck.RestoreConsistency = true;
6237 CommandMailbox->ConsistencyCheck.InitializedAreaOnly = false;
6238 DAC960_ExecuteCommand(Command);
6239 DAC960_UserCritical("Consistency Check of Logical Drive %d "
6240 "(/dev/rd/c%dd%d) %s\n",
6241 Controller, LogicalDriveNumber,
6242 Controller->ControllerNumber,
6243 LogicalDriveNumber,
6244 (Command->V2.CommandStatus
6245 == DAC960_V2_NormalCompletion
6246 ? "Initiated" : "Not Initiated"));
6248 else if (strncmp(UserCommand, "cancel-consistency-check", 24) == 0 &&
6249 DAC960_ParseLogicalDrive(Controller, &UserCommand[24],
6250 &LogicalDriveNumber))
6252 CommandMailbox->ConsistencyCheck.LogicalDevice.LogicalDeviceNumber =
6253 LogicalDriveNumber;
6254 CommandMailbox->ConsistencyCheck.IOCTL_Opcode =
6255 DAC960_V2_ConsistencyCheckStop;
6256 DAC960_ExecuteCommand(Command);
6257 DAC960_UserCritical("Consistency Check of Logical Drive %d "
6258 "(/dev/rd/c%dd%d) %s\n",
6259 Controller, LogicalDriveNumber,
6260 Controller->ControllerNumber,
6261 LogicalDriveNumber,
6262 (Command->V2.CommandStatus
6263 == DAC960_V2_NormalCompletion
6264 ? "Cancelled" : "Not Cancelled"));
6266 else if (strcmp(UserCommand, "perform-discovery") == 0)
6268 CommandMailbox->Common.IOCTL_Opcode = DAC960_V2_StartDiscovery;
6269 DAC960_ExecuteCommand(Command);
6270 DAC960_UserCritical("Discovery %s\n", Controller,
6271 (Command->V2.CommandStatus
6272 == DAC960_V2_NormalCompletion
6273 ? "Initiated" : "Not Initiated"));
6274 if (Command->V2.CommandStatus == DAC960_V2_NormalCompletion)
6276 CommandMailbox->ControllerInfo.CommandOpcode = DAC960_V2_IOCTL;
6277 CommandMailbox->ControllerInfo.CommandControlBits
6278 .DataTransferControllerToHost = true;
6279 CommandMailbox->ControllerInfo.CommandControlBits
6280 .NoAutoRequestSense = true;
6281 CommandMailbox->ControllerInfo.DataTransferSize =
6282 sizeof(DAC960_V2_ControllerInfo_T);
6283 CommandMailbox->ControllerInfo.ControllerNumber = 0;
6284 CommandMailbox->ControllerInfo.IOCTL_Opcode =
6285 DAC960_V2_GetControllerInfo;
6287 * How does this NOT race with the queued Monitoring
6288 * usage of this structure?
6290 CommandMailbox->ControllerInfo.DataTransferMemoryAddress
6291 .ScatterGatherSegments[0]
6292 .SegmentDataPointer =
6293 Controller->V2.NewControllerInformationDMA;
6294 CommandMailbox->ControllerInfo.DataTransferMemoryAddress
6295 .ScatterGatherSegments[0]
6296 .SegmentByteCount =
6297 CommandMailbox->ControllerInfo.DataTransferSize;
6298 DAC960_ExecuteCommand(Command);
6299 while (Controller->V2.NewControllerInformation->PhysicalScanActive)
6301 DAC960_ExecuteCommand(Command);
6302 sleep_on_timeout(&Controller->CommandWaitQueue, HZ);
6304 DAC960_UserCritical("Discovery Completed\n", Controller);
6307 else if (strcmp(UserCommand, "suppress-enclosure-messages") == 0)
6308 Controller->SuppressEnclosureMessages = true;
6309 else DAC960_UserCritical("Illegal User Command: '%s'\n",
6310 Controller, UserCommand);
6312 spin_lock_irqsave(&Controller->queue_lock, flags);
6313 DAC960_DeallocateCommand(Command);
6314 spin_unlock_irqrestore(&Controller->queue_lock, flags);
6315 return true;
6320 DAC960_ProcReadStatus implements reading /proc/rd/status.
6323 static int DAC960_ProcReadStatus(char *Page, char **Start, off_t Offset,
6324 int Count, int *EOF, void *Data)
6326 unsigned char *StatusMessage = "OK\n";
6327 int ControllerNumber, BytesAvailable;
6328 for (ControllerNumber = 0;
6329 ControllerNumber < DAC960_ControllerCount;
6330 ControllerNumber++)
6332 DAC960_Controller_T *Controller = DAC960_Controllers[ControllerNumber];
6333 if (Controller == NULL) continue;
6334 if (Controller->MonitoringAlertMode)
6336 StatusMessage = "ALERT\n";
6337 break;
6340 BytesAvailable = strlen(StatusMessage) - Offset;
6341 if (Count >= BytesAvailable)
6343 Count = BytesAvailable;
6344 *EOF = true;
6346 if (Count <= 0) return 0;
6347 *Start = Page;
6348 memcpy(Page, &StatusMessage[Offset], Count);
6349 return Count;
6354 DAC960_ProcReadInitialStatus implements reading /proc/rd/cN/initial_status.
6357 static int DAC960_ProcReadInitialStatus(char *Page, char **Start, off_t Offset,
6358 int Count, int *EOF, void *Data)
6360 DAC960_Controller_T *Controller = (DAC960_Controller_T *) Data;
6361 int BytesAvailable = Controller->InitialStatusLength - Offset;
6362 if (Count >= BytesAvailable)
6364 Count = BytesAvailable;
6365 *EOF = true;
6367 if (Count <= 0) return 0;
6368 *Start = Page;
6369 memcpy(Page, &Controller->CombinedStatusBuffer[Offset], Count);
6370 return Count;
6375 DAC960_ProcReadCurrentStatus implements reading /proc/rd/cN/current_status.
6378 static int DAC960_ProcReadCurrentStatus(char *Page, char **Start, off_t Offset,
6379 int Count, int *EOF, void *Data)
6381 DAC960_Controller_T *Controller = (DAC960_Controller_T *) Data;
6382 unsigned char *StatusMessage =
6383 "No Rebuild or Consistency Check in Progress\n";
6384 int ProgressMessageLength = strlen(StatusMessage);
6385 int BytesAvailable;
6386 if (jiffies != Controller->LastCurrentStatusTime)
6388 Controller->CurrentStatusLength = 0;
6389 DAC960_AnnounceDriver(Controller);
6390 DAC960_ReportControllerConfiguration(Controller);
6391 DAC960_ReportDeviceConfiguration(Controller);
6392 if (Controller->ProgressBufferLength > 0)
6393 ProgressMessageLength = Controller->ProgressBufferLength;
6394 if (DAC960_CheckStatusBuffer(Controller, 2 + ProgressMessageLength))
6396 unsigned char *CurrentStatusBuffer = Controller->CurrentStatusBuffer;
6397 CurrentStatusBuffer[Controller->CurrentStatusLength++] = ' ';
6398 CurrentStatusBuffer[Controller->CurrentStatusLength++] = ' ';
6399 if (Controller->ProgressBufferLength > 0)
6400 strcpy(&CurrentStatusBuffer[Controller->CurrentStatusLength],
6401 Controller->ProgressBuffer);
6402 else
6403 strcpy(&CurrentStatusBuffer[Controller->CurrentStatusLength],
6404 StatusMessage);
6405 Controller->CurrentStatusLength += ProgressMessageLength;
6407 Controller->LastCurrentStatusTime = jiffies;
6409 BytesAvailable = Controller->CurrentStatusLength - Offset;
6410 if (Count >= BytesAvailable)
6412 Count = BytesAvailable;
6413 *EOF = true;
6415 if (Count <= 0) return 0;
6416 *Start = Page;
6417 memcpy(Page, &Controller->CurrentStatusBuffer[Offset], Count);
6418 return Count;
6423 DAC960_ProcReadUserCommand implements reading /proc/rd/cN/user_command.
6426 static int DAC960_ProcReadUserCommand(char *Page, char **Start, off_t Offset,
6427 int Count, int *EOF, void *Data)
6429 DAC960_Controller_T *Controller = (DAC960_Controller_T *) Data;
6430 int BytesAvailable = Controller->UserStatusLength - Offset;
6431 if (Count >= BytesAvailable)
6433 Count = BytesAvailable;
6434 *EOF = true;
6436 if (Count <= 0) return 0;
6437 *Start = Page;
6438 memcpy(Page, &Controller->UserStatusBuffer[Offset], Count);
6439 return Count;
6444 DAC960_ProcWriteUserCommand implements writing /proc/rd/cN/user_command.
6447 static int DAC960_ProcWriteUserCommand(struct file *file, const char *Buffer,
6448 unsigned long Count, void *Data)
6450 DAC960_Controller_T *Controller = (DAC960_Controller_T *) Data;
6451 unsigned char CommandBuffer[80];
6452 int Length;
6453 if (Count > sizeof(CommandBuffer)-1) return -EINVAL;
6454 if (copy_from_user(CommandBuffer, Buffer, Count)) return -EFAULT;
6455 CommandBuffer[Count] = '\0';
6456 Length = strlen(CommandBuffer);
6457 if (CommandBuffer[Length-1] == '\n')
6458 CommandBuffer[--Length] = '\0';
6459 if (Controller->FirmwareType == DAC960_V1_Controller)
6460 return (DAC960_V1_ExecuteUserCommand(Controller, CommandBuffer)
6461 ? Count : -EBUSY);
6462 else
6463 return (DAC960_V2_ExecuteUserCommand(Controller, CommandBuffer)
6464 ? Count : -EBUSY);
6469 DAC960_CreateProcEntries creates the /proc/rd/... entries for the
6470 DAC960 Driver.
6473 static void DAC960_CreateProcEntries(DAC960_Controller_T *Controller)
6475 struct proc_dir_entry *StatusProcEntry;
6476 struct proc_dir_entry *ControllerProcEntry;
6477 struct proc_dir_entry *UserCommandProcEntry;
6479 if (DAC960_ProcDirectoryEntry == NULL) {
6480 DAC960_ProcDirectoryEntry = proc_mkdir("rd", NULL);
6481 StatusProcEntry = create_proc_read_entry("status", 0,
6482 DAC960_ProcDirectoryEntry,
6483 DAC960_ProcReadStatus, NULL);
6486 sprintf(Controller->ControllerName, "c%d", Controller->ControllerNumber);
6487 ControllerProcEntry = proc_mkdir(Controller->ControllerName,
6488 DAC960_ProcDirectoryEntry);
6489 create_proc_read_entry("initial_status", 0, ControllerProcEntry,
6490 DAC960_ProcReadInitialStatus, Controller);
6491 create_proc_read_entry("current_status", 0, ControllerProcEntry,
6492 DAC960_ProcReadCurrentStatus, Controller);
6493 UserCommandProcEntry =
6494 create_proc_read_entry("user_command", S_IWUSR | S_IRUSR,
6495 ControllerProcEntry, DAC960_ProcReadUserCommand,
6496 Controller);
6497 UserCommandProcEntry->write_proc = DAC960_ProcWriteUserCommand;
6498 Controller->ControllerProcEntry = ControllerProcEntry;
6503 DAC960_DestroyProcEntries destroys the /proc/rd/... entries for the
6504 DAC960 Driver.
6507 static void DAC960_DestroyProcEntries(DAC960_Controller_T *Controller)
6509 if (Controller->ControllerProcEntry == NULL)
6510 return;
6511 remove_proc_entry("initial_status", Controller->ControllerProcEntry);
6512 remove_proc_entry("current_status", Controller->ControllerProcEntry);
6513 remove_proc_entry("user_command", Controller->ControllerProcEntry);
6514 remove_proc_entry(Controller->ControllerName, DAC960_ProcDirectoryEntry);
6515 Controller->ControllerProcEntry = NULL;
6518 #ifdef DAC960_GAM_MINOR
6521 * DAC960_gam_ioctl is the ioctl function for performing RAID operations.
6524 static int DAC960_gam_ioctl(struct inode *inode, struct file *file,
6525 unsigned int Request, unsigned long Argument)
6527 int ErrorCode = 0;
6528 if (!capable(CAP_SYS_ADMIN)) return -EACCES;
6529 switch (Request)
6531 case DAC960_IOCTL_GET_CONTROLLER_COUNT:
6532 return DAC960_ControllerCount;
6533 case DAC960_IOCTL_GET_CONTROLLER_INFO:
6535 DAC960_ControllerInfo_T *UserSpaceControllerInfo =
6536 (DAC960_ControllerInfo_T *) Argument;
6537 DAC960_ControllerInfo_T ControllerInfo;
6538 DAC960_Controller_T *Controller;
6539 int ControllerNumber;
6540 if (UserSpaceControllerInfo == NULL) return -EINVAL;
6541 ErrorCode = get_user(ControllerNumber,
6542 &UserSpaceControllerInfo->ControllerNumber);
6543 if (ErrorCode != 0) return ErrorCode;
6544 if (ControllerNumber < 0 ||
6545 ControllerNumber > DAC960_ControllerCount - 1)
6546 return -ENXIO;
6547 Controller = DAC960_Controllers[ControllerNumber];
6548 if (Controller == NULL) return -ENXIO;
6549 memset(&ControllerInfo, 0, sizeof(DAC960_ControllerInfo_T));
6550 ControllerInfo.ControllerNumber = ControllerNumber;
6551 ControllerInfo.FirmwareType = Controller->FirmwareType;
6552 ControllerInfo.Channels = Controller->Channels;
6553 ControllerInfo.Targets = Controller->Targets;
6554 ControllerInfo.PCI_Bus = Controller->Bus;
6555 ControllerInfo.PCI_Device = Controller->Device;
6556 ControllerInfo.PCI_Function = Controller->Function;
6557 ControllerInfo.IRQ_Channel = Controller->IRQ_Channel;
6558 ControllerInfo.PCI_Address = Controller->PCI_Address;
6559 strcpy(ControllerInfo.ModelName, Controller->ModelName);
6560 strcpy(ControllerInfo.FirmwareVersion, Controller->FirmwareVersion);
6561 return (copy_to_user(UserSpaceControllerInfo, &ControllerInfo,
6562 sizeof(DAC960_ControllerInfo_T)) ? -EFAULT : 0);
6564 case DAC960_IOCTL_V1_EXECUTE_COMMAND:
6566 DAC960_V1_UserCommand_T *UserSpaceUserCommand =
6567 (DAC960_V1_UserCommand_T *) Argument;
6568 DAC960_V1_UserCommand_T UserCommand;
6569 DAC960_Controller_T *Controller;
6570 DAC960_Command_T *Command = NULL;
6571 DAC960_V1_CommandOpcode_T CommandOpcode;
6572 DAC960_V1_CommandStatus_T CommandStatus;
6573 DAC960_V1_DCDB_T DCDB;
6574 DAC960_V1_DCDB_T *DCDB_IOBUF = NULL;
6575 dma_addr_t DCDB_IOBUFDMA;
6576 unsigned long flags;
6577 int ControllerNumber, DataTransferLength;
6578 unsigned char *DataTransferBuffer = NULL;
6579 dma_addr_t DataTransferBufferDMA;
6580 if (UserSpaceUserCommand == NULL) return -EINVAL;
6581 if (copy_from_user(&UserCommand, UserSpaceUserCommand,
6582 sizeof(DAC960_V1_UserCommand_T))) {
6583 ErrorCode = -EFAULT;
6584 goto Failure1a;
6586 ControllerNumber = UserCommand.ControllerNumber;
6587 if (ControllerNumber < 0 ||
6588 ControllerNumber > DAC960_ControllerCount - 1)
6589 return -ENXIO;
6590 Controller = DAC960_Controllers[ControllerNumber];
6591 if (Controller == NULL) return -ENXIO;
6592 if (Controller->FirmwareType != DAC960_V1_Controller) return -EINVAL;
6593 CommandOpcode = UserCommand.CommandMailbox.Common.CommandOpcode;
6594 DataTransferLength = UserCommand.DataTransferLength;
6595 if (CommandOpcode & 0x80) return -EINVAL;
6596 if (CommandOpcode == DAC960_V1_DCDB)
6598 if (copy_from_user(&DCDB, UserCommand.DCDB,
6599 sizeof(DAC960_V1_DCDB_T))) {
6600 ErrorCode = -EFAULT;
6601 goto Failure1a;
6603 if (DCDB.Channel >= DAC960_V1_MaxChannels) return -EINVAL;
6604 if (!((DataTransferLength == 0 &&
6605 DCDB.Direction
6606 == DAC960_V1_DCDB_NoDataTransfer) ||
6607 (DataTransferLength > 0 &&
6608 DCDB.Direction
6609 == DAC960_V1_DCDB_DataTransferDeviceToSystem) ||
6610 (DataTransferLength < 0 &&
6611 DCDB.Direction
6612 == DAC960_V1_DCDB_DataTransferSystemToDevice)))
6613 return -EINVAL;
6614 if (((DCDB.TransferLengthHigh4 << 16) | DCDB.TransferLength)
6615 != abs(DataTransferLength))
6616 return -EINVAL;
6617 DCDB_IOBUF = pci_alloc_consistent(Controller->PCIDevice,
6618 sizeof(DAC960_V1_DCDB_T), &DCDB_IOBUFDMA);
6619 if (DCDB_IOBUF == NULL)
6620 return -ENOMEM;
6622 if (DataTransferLength > 0)
6624 DataTransferBuffer = pci_alloc_consistent(Controller->PCIDevice,
6625 DataTransferLength, &DataTransferBufferDMA);
6626 if (DataTransferBuffer == NULL) {
6627 ErrorCode = -ENOMEM;
6628 goto Failure1;
6630 memset(DataTransferBuffer, 0, DataTransferLength);
6632 else if (DataTransferLength < 0)
6634 DataTransferBuffer = pci_alloc_consistent(Controller->PCIDevice,
6635 -DataTransferLength, &DataTransferBufferDMA);
6636 if (DataTransferBuffer == NULL) {
6637 ErrorCode = -ENOMEM;
6638 goto Failure1;
6640 if (copy_from_user(DataTransferBuffer,
6641 UserCommand.DataTransferBuffer,
6642 -DataTransferLength)) {
6643 ErrorCode = -EFAULT;
6644 goto Failure1;
6647 if (CommandOpcode == DAC960_V1_DCDB)
6649 spin_lock_irqsave(&Controller->queue_lock, flags);
6650 while ((Command = DAC960_AllocateCommand(Controller)) == NULL)
6651 DAC960_WaitForCommand(Controller);
6652 while (Controller->V1.DirectCommandActive[DCDB.Channel]
6653 [DCDB.TargetID])
6655 spin_unlock_irq(&Controller->queue_lock);
6656 __wait_event(Controller->CommandWaitQueue,
6657 !Controller->V1.DirectCommandActive
6658 [DCDB.Channel][DCDB.TargetID]);
6659 spin_lock_irq(&Controller->queue_lock);
6661 Controller->V1.DirectCommandActive[DCDB.Channel]
6662 [DCDB.TargetID] = true;
6663 spin_unlock_irqrestore(&Controller->queue_lock, flags);
6664 DAC960_V1_ClearCommand(Command);
6665 Command->CommandType = DAC960_ImmediateCommand;
6666 memcpy(&Command->V1.CommandMailbox, &UserCommand.CommandMailbox,
6667 sizeof(DAC960_V1_CommandMailbox_T));
6668 Command->V1.CommandMailbox.Type3.BusAddress = DCDB_IOBUFDMA;
6669 DCDB.BusAddress = DataTransferBufferDMA;
6670 memcpy(DCDB_IOBUF, &DCDB, sizeof(DAC960_V1_DCDB_T));
6672 else
6674 spin_lock_irqsave(&Controller->queue_lock, flags);
6675 while ((Command = DAC960_AllocateCommand(Controller)) == NULL)
6676 DAC960_WaitForCommand(Controller);
6677 spin_unlock_irqrestore(&Controller->queue_lock, flags);
6678 DAC960_V1_ClearCommand(Command);
6679 Command->CommandType = DAC960_ImmediateCommand;
6680 memcpy(&Command->V1.CommandMailbox, &UserCommand.CommandMailbox,
6681 sizeof(DAC960_V1_CommandMailbox_T));
6682 if (DataTransferBuffer != NULL)
6683 Command->V1.CommandMailbox.Type3.BusAddress =
6684 DataTransferBufferDMA;
6686 DAC960_ExecuteCommand(Command);
6687 CommandStatus = Command->V1.CommandStatus;
6688 spin_lock_irqsave(&Controller->queue_lock, flags);
6689 DAC960_DeallocateCommand(Command);
6690 spin_unlock_irqrestore(&Controller->queue_lock, flags);
6691 if (DataTransferLength > 0)
6693 if (copy_to_user(UserCommand.DataTransferBuffer,
6694 DataTransferBuffer, DataTransferLength)) {
6695 ErrorCode = -EFAULT;
6696 goto Failure1;
6699 if (CommandOpcode == DAC960_V1_DCDB)
6702 I don't believe Target or Channel in the DCDB_IOBUF
6703 should be any different from the contents of DCDB.
6705 Controller->V1.DirectCommandActive[DCDB.Channel]
6706 [DCDB.TargetID] = false;
6707 if (copy_to_user(UserCommand.DCDB, DCDB_IOBUF,
6708 sizeof(DAC960_V1_DCDB_T))) {
6709 ErrorCode = -EFAULT;
6710 goto Failure1;
6713 ErrorCode = CommandStatus;
6714 Failure1:
6715 if (DataTransferBuffer != NULL)
6716 pci_free_consistent(Controller->PCIDevice, abs(DataTransferLength),
6717 DataTransferBuffer, DataTransferBufferDMA);
6718 if (DCDB_IOBUF != NULL)
6719 pci_free_consistent(Controller->PCIDevice, sizeof(DAC960_V1_DCDB_T),
6720 DCDB_IOBUF, DCDB_IOBUFDMA);
6721 Failure1a:
6722 return ErrorCode;
6724 case DAC960_IOCTL_V2_EXECUTE_COMMAND:
6726 DAC960_V2_UserCommand_T *UserSpaceUserCommand =
6727 (DAC960_V2_UserCommand_T *) Argument;
6728 DAC960_V2_UserCommand_T UserCommand;
6729 DAC960_Controller_T *Controller;
6730 DAC960_Command_T *Command = NULL;
6731 DAC960_V2_CommandMailbox_T *CommandMailbox;
6732 DAC960_V2_CommandStatus_T CommandStatus;
6733 unsigned long flags;
6734 int ControllerNumber, DataTransferLength;
6735 int DataTransferResidue, RequestSenseLength;
6736 unsigned char *DataTransferBuffer = NULL;
6737 dma_addr_t DataTransferBufferDMA;
6738 unsigned char *RequestSenseBuffer = NULL;
6739 dma_addr_t RequestSenseBufferDMA;
6740 if (UserSpaceUserCommand == NULL) return -EINVAL;
6741 if (copy_from_user(&UserCommand, UserSpaceUserCommand,
6742 sizeof(DAC960_V2_UserCommand_T))) {
6743 ErrorCode = -EFAULT;
6744 goto Failure2a;
6746 ControllerNumber = UserCommand.ControllerNumber;
6747 if (ControllerNumber < 0 ||
6748 ControllerNumber > DAC960_ControllerCount - 1)
6749 return -ENXIO;
6750 Controller = DAC960_Controllers[ControllerNumber];
6751 if (Controller == NULL) return -ENXIO;
6752 if (Controller->FirmwareType != DAC960_V2_Controller) return -EINVAL;
6753 DataTransferLength = UserCommand.DataTransferLength;
6754 if (DataTransferLength > 0)
6756 DataTransferBuffer = pci_alloc_consistent(Controller->PCIDevice,
6757 DataTransferLength, &DataTransferBufferDMA);
6758 if (DataTransferBuffer == NULL) return -ENOMEM;
6759 memset(DataTransferBuffer, 0, DataTransferLength);
6761 else if (DataTransferLength < 0)
6763 DataTransferBuffer = pci_alloc_consistent(Controller->PCIDevice,
6764 -DataTransferLength, &DataTransferBufferDMA);
6765 if (DataTransferBuffer == NULL) return -ENOMEM;
6766 if (copy_from_user(DataTransferBuffer,
6767 UserCommand.DataTransferBuffer,
6768 -DataTransferLength)) {
6769 ErrorCode = -EFAULT;
6770 goto Failure2;
6773 RequestSenseLength = UserCommand.RequestSenseLength;
6774 if (RequestSenseLength > 0)
6776 RequestSenseBuffer = pci_alloc_consistent(Controller->PCIDevice,
6777 RequestSenseLength, &RequestSenseBufferDMA);
6778 if (RequestSenseBuffer == NULL)
6780 ErrorCode = -ENOMEM;
6781 goto Failure2;
6783 memset(RequestSenseBuffer, 0, RequestSenseLength);
6785 spin_lock_irqsave(&Controller->queue_lock, flags);
6786 while ((Command = DAC960_AllocateCommand(Controller)) == NULL)
6787 DAC960_WaitForCommand(Controller);
6788 spin_unlock_irqrestore(&Controller->queue_lock, flags);
6789 DAC960_V2_ClearCommand(Command);
6790 Command->CommandType = DAC960_ImmediateCommand;
6791 CommandMailbox = &Command->V2.CommandMailbox;
6792 memcpy(CommandMailbox, &UserCommand.CommandMailbox,
6793 sizeof(DAC960_V2_CommandMailbox_T));
6794 CommandMailbox->Common.CommandControlBits
6795 .AdditionalScatterGatherListMemory = false;
6796 CommandMailbox->Common.CommandControlBits
6797 .NoAutoRequestSense = true;
6798 CommandMailbox->Common.DataTransferSize = 0;
6799 CommandMailbox->Common.DataTransferPageNumber = 0;
6800 memset(&CommandMailbox->Common.DataTransferMemoryAddress, 0,
6801 sizeof(DAC960_V2_DataTransferMemoryAddress_T));
6802 if (DataTransferLength != 0)
6804 if (DataTransferLength > 0)
6806 CommandMailbox->Common.CommandControlBits
6807 .DataTransferControllerToHost = true;
6808 CommandMailbox->Common.DataTransferSize = DataTransferLength;
6810 else
6812 CommandMailbox->Common.CommandControlBits
6813 .DataTransferControllerToHost = false;
6814 CommandMailbox->Common.DataTransferSize = -DataTransferLength;
6816 CommandMailbox->Common.DataTransferMemoryAddress
6817 .ScatterGatherSegments[0]
6818 .SegmentDataPointer = DataTransferBufferDMA;
6819 CommandMailbox->Common.DataTransferMemoryAddress
6820 .ScatterGatherSegments[0]
6821 .SegmentByteCount =
6822 CommandMailbox->Common.DataTransferSize;
6824 if (RequestSenseLength > 0)
6826 CommandMailbox->Common.CommandControlBits
6827 .NoAutoRequestSense = false;
6828 CommandMailbox->Common.RequestSenseSize = RequestSenseLength;
6829 CommandMailbox->Common.RequestSenseBusAddress =
6830 RequestSenseBufferDMA;
6832 DAC960_ExecuteCommand(Command);
6833 CommandStatus = Command->V2.CommandStatus;
6834 RequestSenseLength = Command->V2.RequestSenseLength;
6835 DataTransferResidue = Command->V2.DataTransferResidue;
6836 spin_lock_irqsave(&Controller->queue_lock, flags);
6837 DAC960_DeallocateCommand(Command);
6838 spin_unlock_irqrestore(&Controller->queue_lock, flags);
6839 if (RequestSenseLength > UserCommand.RequestSenseLength)
6840 RequestSenseLength = UserCommand.RequestSenseLength;
6841 if (copy_to_user(&UserSpaceUserCommand->DataTransferLength,
6842 &DataTransferResidue,
6843 sizeof(DataTransferResidue))) {
6844 ErrorCode = -EFAULT;
6845 goto Failure2;
6847 if (copy_to_user(&UserSpaceUserCommand->RequestSenseLength,
6848 &RequestSenseLength, sizeof(RequestSenseLength))) {
6849 ErrorCode = -EFAULT;
6850 goto Failure2;
6852 if (DataTransferLength > 0)
6854 if (copy_to_user(UserCommand.DataTransferBuffer,
6855 DataTransferBuffer, DataTransferLength)) {
6856 ErrorCode = -EFAULT;
6857 goto Failure2;
6860 if (RequestSenseLength > 0)
6862 if (copy_to_user(UserCommand.RequestSenseBuffer,
6863 RequestSenseBuffer, RequestSenseLength)) {
6864 ErrorCode = -EFAULT;
6865 goto Failure2;
6868 ErrorCode = CommandStatus;
6869 Failure2:
6870 pci_free_consistent(Controller->PCIDevice, abs(DataTransferLength),
6871 DataTransferBuffer, DataTransferBufferDMA);
6872 if (RequestSenseBuffer != NULL)
6873 pci_free_consistent(Controller->PCIDevice, RequestSenseLength,
6874 RequestSenseBuffer, RequestSenseBufferDMA);
6875 Failure2a:
6876 return ErrorCode;
6878 case DAC960_IOCTL_V2_GET_HEALTH_STATUS:
6880 DAC960_V2_GetHealthStatus_T *UserSpaceGetHealthStatus =
6881 (DAC960_V2_GetHealthStatus_T *) Argument;
6882 DAC960_V2_GetHealthStatus_T GetHealthStatus;
6883 DAC960_V2_HealthStatusBuffer_T HealthStatusBuffer;
6884 DAC960_Controller_T *Controller;
6885 int ControllerNumber;
6886 if (UserSpaceGetHealthStatus == NULL) return -EINVAL;
6887 if (copy_from_user(&GetHealthStatus, UserSpaceGetHealthStatus,
6888 sizeof(DAC960_V2_GetHealthStatus_T)))
6889 return -EFAULT;
6890 ControllerNumber = GetHealthStatus.ControllerNumber;
6891 if (ControllerNumber < 0 ||
6892 ControllerNumber > DAC960_ControllerCount - 1)
6893 return -ENXIO;
6894 Controller = DAC960_Controllers[ControllerNumber];
6895 if (Controller == NULL) return -ENXIO;
6896 if (Controller->FirmwareType != DAC960_V2_Controller) return -EINVAL;
6897 if (copy_from_user(&HealthStatusBuffer,
6898 GetHealthStatus.HealthStatusBuffer,
6899 sizeof(DAC960_V2_HealthStatusBuffer_T)))
6900 return -EFAULT;
6901 while (Controller->V2.HealthStatusBuffer->StatusChangeCounter
6902 == HealthStatusBuffer.StatusChangeCounter &&
6903 Controller->V2.HealthStatusBuffer->NextEventSequenceNumber
6904 == HealthStatusBuffer.NextEventSequenceNumber)
6906 interruptible_sleep_on_timeout(&Controller->HealthStatusWaitQueue,
6907 DAC960_MonitoringTimerInterval);
6908 if (signal_pending(current)) return -EINTR;
6910 if (copy_to_user(GetHealthStatus.HealthStatusBuffer,
6911 Controller->V2.HealthStatusBuffer,
6912 sizeof(DAC960_V2_HealthStatusBuffer_T)))
6913 return -EFAULT;
6914 return 0;
6917 return -EINVAL;
6920 static struct file_operations DAC960_gam_fops = {
6921 .owner = THIS_MODULE,
6922 .ioctl = DAC960_gam_ioctl
6925 static struct miscdevice DAC960_gam_dev = {
6926 DAC960_GAM_MINOR,
6927 "dac960_gam",
6928 &DAC960_gam_fops
6931 static int DAC960_gam_init(void)
6933 int ret;
6935 ret = misc_register(&DAC960_gam_dev);
6936 if (ret)
6937 printk(KERN_ERR "DAC960_gam: can't misc_register on minor %d\n", DAC960_GAM_MINOR);
6938 return ret;
6941 static void DAC960_gam_cleanup(void)
6943 misc_deregister(&DAC960_gam_dev);
6946 #endif /* DAC960_GAM_MINOR */
6948 static struct DAC960_privdata DAC960_BA_privdata = {
6949 .HardwareType = DAC960_BA_Controller,
6950 .FirmwareType = DAC960_V2_Controller,
6951 .InterruptHandler = DAC960_BA_InterruptHandler,
6952 .MemoryWindowSize = DAC960_BA_RegisterWindowSize,
6955 static struct DAC960_privdata DAC960_LP_privdata = {
6956 .HardwareType = DAC960_LP_Controller,
6957 .FirmwareType = DAC960_LP_Controller,
6958 .InterruptHandler = DAC960_LP_InterruptHandler,
6959 .MemoryWindowSize = DAC960_LP_RegisterWindowSize,
6962 static struct DAC960_privdata DAC960_LA_privdata = {
6963 .HardwareType = DAC960_LA_Controller,
6964 .FirmwareType = DAC960_V1_Controller,
6965 .InterruptHandler = DAC960_LA_InterruptHandler,
6966 .MemoryWindowSize = DAC960_LA_RegisterWindowSize,
6969 static struct DAC960_privdata DAC960_PG_privdata = {
6970 .HardwareType = DAC960_PG_Controller,
6971 .FirmwareType = DAC960_V1_Controller,
6972 .InterruptHandler = DAC960_PG_InterruptHandler,
6973 .MemoryWindowSize = DAC960_PG_RegisterWindowSize,
6976 static struct DAC960_privdata DAC960_PD_privdata = {
6977 .HardwareType = DAC960_PD_Controller,
6978 .FirmwareType = DAC960_V1_Controller,
6979 .InterruptHandler = DAC960_PD_InterruptHandler,
6980 .MemoryWindowSize = DAC960_PD_RegisterWindowSize,
6983 static struct DAC960_privdata DAC960_P_privdata = {
6984 .HardwareType = DAC960_P_Controller,
6985 .FirmwareType = DAC960_V1_Controller,
6986 .InterruptHandler = DAC960_P_InterruptHandler,
6987 .MemoryWindowSize = DAC960_PD_RegisterWindowSize,
6990 static struct pci_device_id DAC960_id_table[] = {
6992 .vendor = PCI_VENDOR_ID_MYLEX,
6993 .device = PCI_DEVICE_ID_MYLEX_DAC960_BA,
6994 .subvendor = PCI_ANY_ID,
6995 .subdevice = PCI_ANY_ID,
6996 .driver_data = (unsigned long) &DAC960_BA_privdata,
6999 .vendor = PCI_VENDOR_ID_MYLEX,
7000 .device = PCI_DEVICE_ID_MYLEX_DAC960_LP,
7001 .subvendor = PCI_ANY_ID,
7002 .subdevice = PCI_ANY_ID,
7003 .driver_data = (unsigned long) &DAC960_LP_privdata,
7006 .vendor = PCI_VENDOR_ID_DEC,
7007 .device = PCI_DEVICE_ID_DEC_21285,
7008 .subvendor = PCI_VENDOR_ID_MYLEX,
7009 .subdevice = PCI_DEVICE_ID_MYLEX_DAC960_LA,
7010 .driver_data = (unsigned long) &DAC960_LA_privdata,
7013 .vendor = PCI_VENDOR_ID_MYLEX,
7014 .device = PCI_DEVICE_ID_MYLEX_DAC960_PG,
7015 .subvendor = PCI_ANY_ID,
7016 .subdevice = PCI_ANY_ID,
7017 .driver_data = (unsigned long) &DAC960_PG_privdata,
7020 .vendor = PCI_VENDOR_ID_MYLEX,
7021 .device = PCI_DEVICE_ID_MYLEX_DAC960_PD,
7022 .subvendor = PCI_ANY_ID,
7023 .subdevice = PCI_ANY_ID,
7024 .driver_data = (unsigned long) &DAC960_PD_privdata,
7027 .vendor = PCI_VENDOR_ID_MYLEX,
7028 .device = PCI_DEVICE_ID_MYLEX_DAC960_P,
7029 .subvendor = PCI_ANY_ID,
7030 .subdevice = PCI_ANY_ID,
7031 .driver_data = (unsigned long) &DAC960_P_privdata,
7033 {0, },
7036 MODULE_DEVICE_TABLE(pci, DAC960_id_table);
7038 static struct pci_driver DAC960_pci_driver = {
7039 .name = "DAC960",
7040 .id_table = DAC960_id_table,
7041 .probe = DAC960_Probe,
7042 .remove = DAC960_Remove,
7045 static int DAC960_init_module(void)
7047 int ret;
7049 ret = pci_module_init(&DAC960_pci_driver);
7050 #ifdef DAC960_GAM_MINOR
7051 if (!ret)
7052 DAC960_gam_init();
7053 #endif
7054 return ret;
7057 static void DAC960_cleanup_module(void)
7059 int i;
7061 #ifdef DAC960_GAM_MINOR
7062 DAC960_gam_cleanup();
7063 #endif
7065 for (i = 0; i < DAC960_ControllerCount; i++) {
7066 DAC960_Controller_T *Controller = DAC960_Controllers[i];
7067 if (Controller == NULL)
7068 continue;
7069 DAC960_FinalizeController(Controller);
7071 if (DAC960_ProcDirectoryEntry != NULL) {
7072 remove_proc_entry("rd/status", NULL);
7073 remove_proc_entry("rd", NULL);
7075 DAC960_ControllerCount = 0;
7076 pci_unregister_driver(&DAC960_pci_driver);
7079 module_init(DAC960_init_module);
7080 module_exit(DAC960_cleanup_module);
7082 MODULE_LICENSE("GPL");