DAC960.c
上传用户:ajay2009
上传日期:2009-05-22
资源大小:495k
文件大小:260k
源码类别:

驱动编程

开发平台:

Unix_Linux

  1. /*
  2.   Linux Driver for Mylex DAC960/AcceleRAID/eXtremeRAID PCI RAID Controllers
  3.   Copyright 1998-2001 by Leonard N. Zubkoff <lnz@dandelion.com>
  4.   Portions Copyright 2002 by Mylex (An IBM Business Unit)
  5.   This program is free software; you may redistribute and/or modify it under
  6.   the terms of the GNU General Public License Version 2 as published by the
  7.   Free Software Foundation.
  8.   This program is distributed in the hope that it will be useful, but
  9.   WITHOUT ANY WARRANTY, without even the implied warranty of MERCHANTABILITY
  10.   or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  11.   for complete details.
  12. */
  13. #define DAC960_DriverVersion "2.5.47"
  14. #define DAC960_DriverDate "14 November 2002"
  15. #include <linux/module.h>
  16. #include <linux/types.h>
  17. #include <linux/miscdevice.h>
  18. #include <linux/blkdev.h>
  19. #include <linux/bio.h>
  20. #include <linux/completion.h>
  21. #include <linux/delay.h>
  22. #include <linux/genhd.h>
  23. #include <linux/hdreg.h>
  24. #include <linux/blkpg.h>
  25. #include <linux/interrupt.h>
  26. #include <linux/ioport.h>
  27. #include <linux/mm.h>
  28. #include <linux/slab.h>
  29. #include <linux/proc_fs.h>
  30. #include <linux/reboot.h>
  31. #include <linux/spinlock.h>
  32. #include <linux/timer.h>
  33. #include <linux/pci.h>
  34. #include <linux/init.h>
  35. #include <asm/io.h>
  36. #include <asm/uaccess.h>
  37. #include "DAC960.h"
  38. #define DAC960_GAM_MINOR 252
  39. static DAC960_Controller_T *DAC960_Controllers[DAC960_MaxControllers];
  40. static int DAC960_ControllerCount;
  41. static struct proc_dir_entry *DAC960_ProcDirectoryEntry;
  42. static long disk_size(DAC960_Controller_T *p, int drive_nr)
  43. {
  44. if (p->FirmwareType == DAC960_V1_Controller) {
  45. if (drive_nr >= p->LogicalDriveCount)
  46. return 0;
  47. return p->V1.LogicalDriveInformation[drive_nr].
  48. LogicalDriveSize;
  49. } else {
  50. DAC960_V2_LogicalDeviceInfo_T *i =
  51. p->V2.LogicalDeviceInformation[drive_nr];
  52. if (i == NULL)
  53. return 0;
  54. return i->ConfigurableDeviceSize;
  55. }
  56. }
  57. static int DAC960_open(struct inode *inode, struct file *file)
  58. {
  59. struct gendisk *disk = inode->i_bdev->bd_disk;
  60. DAC960_Controller_T *p = disk->queue->queuedata;
  61. int drive_nr = (long)disk->private_data;
  62. if (p->FirmwareType == DAC960_V1_Controller) {
  63. if (p->V1.LogicalDriveInformation[drive_nr].
  64.     LogicalDriveState == DAC960_V1_LogicalDrive_Offline)
  65. return -ENXIO;
  66. } else {
  67. DAC960_V2_LogicalDeviceInfo_T *i =
  68. p->V2.LogicalDeviceInformation[drive_nr];
  69. if (!i || i->LogicalDeviceState == DAC960_V2_LogicalDevice_Offline)
  70. return -ENXIO;
  71. }
  72. check_disk_change(inode->i_bdev);
  73. if (!get_capacity(p->disks[drive_nr]))
  74. return -ENXIO;
  75. return 0;
  76. }
  77. static int DAC960_ioctl(struct inode *inode, struct file *file,
  78. unsigned int cmd, unsigned long arg)
  79. {
  80. struct gendisk *disk = inode->i_bdev->bd_disk;
  81. DAC960_Controller_T *p = disk->queue->queuedata;
  82. int drive_nr = (long)disk->private_data;
  83. struct hd_geometry g;
  84. struct hd_geometry __user *loc = (struct hd_geometry __user *)arg;
  85. if (cmd != HDIO_GETGEO || !loc)
  86. return -EINVAL;
  87. if (p->FirmwareType == DAC960_V1_Controller) {
  88. g.heads = p->V1.GeometryTranslationHeads;
  89. g.sectors = p->V1.GeometryTranslationSectors;
  90. g.cylinders = p->V1.LogicalDriveInformation[drive_nr].
  91. LogicalDriveSize / (g.heads * g.sectors);
  92. } else {
  93. DAC960_V2_LogicalDeviceInfo_T *i =
  94. p->V2.LogicalDeviceInformation[drive_nr];
  95. switch (i->DriveGeometry) {
  96. case DAC960_V2_Geometry_128_32:
  97. g.heads = 128;
  98. g.sectors = 32;
  99. break;
  100. case DAC960_V2_Geometry_255_63:
  101. g.heads = 255;
  102. g.sectors = 63;
  103. break;
  104. default:
  105. DAC960_Error("Illegal Logical Device Geometry %dn",
  106. p, i->DriveGeometry);
  107. return -EINVAL;
  108. }
  109. g.cylinders = i->ConfigurableDeviceSize / (g.heads * g.sectors);
  110. }
  111. g.start = get_start_sect(inode->i_bdev);
  112. return copy_to_user(loc, &g, sizeof g) ? -EFAULT : 0; 
  113. }
  114. static int DAC960_media_changed(struct gendisk *disk)
  115. {
  116. DAC960_Controller_T *p = disk->queue->queuedata;
  117. int drive_nr = (long)disk->private_data;
  118. if (!p->LogicalDriveInitiallyAccessible[drive_nr])
  119. return 1;
  120. return 0;
  121. }
  122. static int DAC960_revalidate_disk(struct gendisk *disk)
  123. {
  124. DAC960_Controller_T *p = disk->queue->queuedata;
  125. int unit = (long)disk->private_data;
  126. set_capacity(disk, disk_size(p, unit));
  127. return 0;
  128. }
  129. static struct block_device_operations DAC960_BlockDeviceOperations = {
  130. .owner = THIS_MODULE,
  131. .open = DAC960_open,
  132. .ioctl = DAC960_ioctl,
  133. .media_changed = DAC960_media_changed,
  134. .revalidate_disk = DAC960_revalidate_disk,
  135. };
  136. /*
  137.   DAC960_AnnounceDriver announces the Driver Version and Date, Author's Name,
  138.   Copyright Notice, and Electronic Mail Address.
  139. */
  140. static void DAC960_AnnounceDriver(DAC960_Controller_T *Controller)
  141. {
  142.   DAC960_Announce("***** DAC960 RAID Driver Version "
  143.   DAC960_DriverVersion " of "
  144.   DAC960_DriverDate " *****n", Controller);
  145.   DAC960_Announce("Copyright 1998-2001 by Leonard N. Zubkoff "
  146.   "<lnz@dandelion.com>n", Controller);
  147. }
  148. /*
  149.   DAC960_Failure prints a standardized error message, and then returns false.
  150. */
  151. static boolean DAC960_Failure(DAC960_Controller_T *Controller,
  152.       unsigned char *ErrorMessage)
  153. {
  154.   DAC960_Error("While configuring DAC960 PCI RAID Controller atn",
  155.        Controller);
  156.   if (Controller->IO_Address == 0)
  157.     DAC960_Error("PCI Bus %d Device %d Function %d I/O Address N/A "
  158.  "PCI Address 0x%Xn", Controller,
  159.  Controller->Bus, Controller->Device,
  160.  Controller->Function, Controller->PCI_Address);
  161.   else DAC960_Error("PCI Bus %d Device %d Function %d I/O Address "
  162.     "0x%X PCI Address 0x%Xn", Controller,
  163.     Controller->Bus, Controller->Device,
  164.     Controller->Function, Controller->IO_Address,
  165.     Controller->PCI_Address);
  166.   DAC960_Error("%s FAILED - DETACHINGn", Controller, ErrorMessage);
  167.   return false;
  168. }
  169. /*
  170.   init_dma_loaf() and slice_dma_loaf() are helper functions for
  171.   aggregating the dma-mapped memory for a well-known collection of
  172.   data structures that are of different lengths.
  173.   These routines don't guarantee any alignment.  The caller must
  174.   include any space needed for alignment in the sizes of the structures
  175.   that are passed in.
  176.  */
  177. static boolean init_dma_loaf(struct pci_dev *dev, struct dma_loaf *loaf,
  178.  size_t len)
  179. {
  180. void *cpu_addr;
  181. dma_addr_t dma_handle;
  182. cpu_addr = pci_alloc_consistent(dev, len, &dma_handle);
  183. if (cpu_addr == NULL)
  184. return false;
  185. loaf->cpu_free = loaf->cpu_base = cpu_addr;
  186. loaf->dma_free =loaf->dma_base = dma_handle;
  187. loaf->length = len;
  188. memset(cpu_addr, 0, len);
  189. return true;
  190. }
  191. static void *slice_dma_loaf(struct dma_loaf *loaf, size_t len,
  192. dma_addr_t *dma_handle)
  193. {
  194. void *cpu_end = loaf->cpu_free + len;
  195. void *cpu_addr = loaf->cpu_free;
  196. if (cpu_end > loaf->cpu_base + loaf->length)
  197. BUG();
  198. *dma_handle = loaf->dma_free;
  199. loaf->cpu_free = cpu_end;
  200. loaf->dma_free += len;
  201. return cpu_addr;
  202. }
  203. static void free_dma_loaf(struct pci_dev *dev, struct dma_loaf *loaf_handle)
  204. {
  205. if (loaf_handle->cpu_base != NULL)
  206. pci_free_consistent(dev, loaf_handle->length,
  207. loaf_handle->cpu_base, loaf_handle->dma_base);
  208. }
  209. /*
  210.   DAC960_CreateAuxiliaryStructures allocates and initializes the auxiliary
  211.   data structures for Controller.  It returns true on success and false on
  212.   failure.
  213. */
  214. static boolean DAC960_CreateAuxiliaryStructures(DAC960_Controller_T *Controller)
  215. {
  216.   int CommandAllocationLength, CommandAllocationGroupSize;
  217.   int CommandsRemaining = 0, CommandIdentifier, CommandGroupByteCount;
  218.   void *AllocationPointer = NULL;
  219.   void *ScatterGatherCPU = NULL;
  220.   dma_addr_t ScatterGatherDMA;
  221.   struct pci_pool *ScatterGatherPool;
  222.   void *RequestSenseCPU = NULL;
  223.   dma_addr_t RequestSenseDMA;
  224.   struct pci_pool *RequestSensePool = NULL;
  225.   if (Controller->FirmwareType == DAC960_V1_Controller)
  226.     {
  227.       CommandAllocationLength = offsetof(DAC960_Command_T, V1.EndMarker);
  228.       CommandAllocationGroupSize = DAC960_V1_CommandAllocationGroupSize;
  229.       ScatterGatherPool = pci_pool_create("DAC960_V1_ScatterGather",
  230. Controller->PCIDevice,
  231. DAC960_V1_ScatterGatherLimit * sizeof(DAC960_V1_ScatterGatherSegment_T),
  232. sizeof(DAC960_V1_ScatterGatherSegment_T), 0);
  233.       if (ScatterGatherPool == NULL)
  234.     return DAC960_Failure(Controller,
  235. "AUXILIARY STRUCTURE CREATION (SG)");
  236.       Controller->ScatterGatherPool = ScatterGatherPool;
  237.     }
  238.   else
  239.     {
  240.       CommandAllocationLength = offsetof(DAC960_Command_T, V2.EndMarker);
  241.       CommandAllocationGroupSize = DAC960_V2_CommandAllocationGroupSize;
  242.       ScatterGatherPool = pci_pool_create("DAC960_V2_ScatterGather",
  243. Controller->PCIDevice,
  244. DAC960_V2_ScatterGatherLimit * sizeof(DAC960_V2_ScatterGatherSegment_T),
  245. sizeof(DAC960_V2_ScatterGatherSegment_T), 0);
  246.       if (ScatterGatherPool == NULL)
  247.     return DAC960_Failure(Controller,
  248. "AUXILIARY STRUCTURE CREATION (SG)");
  249.       RequestSensePool = pci_pool_create("DAC960_V2_RequestSense",
  250. Controller->PCIDevice, sizeof(DAC960_SCSI_RequestSense_T),
  251. sizeof(int), 0);
  252.       if (RequestSensePool == NULL) {
  253.     pci_pool_destroy(ScatterGatherPool);
  254.     return DAC960_Failure(Controller,
  255. "AUXILIARY STRUCTURE CREATION (SG)");
  256.       }
  257.       Controller->ScatterGatherPool = ScatterGatherPool;
  258.       Controller->V2.RequestSensePool = RequestSensePool;
  259.     }
  260.   Controller->CommandAllocationGroupSize = CommandAllocationGroupSize;
  261.   Controller->FreeCommands = NULL;
  262.   for (CommandIdentifier = 1;
  263.        CommandIdentifier <= Controller->DriverQueueDepth;
  264.        CommandIdentifier++)
  265.     {
  266.       DAC960_Command_T *Command;
  267.       if (--CommandsRemaining <= 0)
  268. {
  269.   CommandsRemaining =
  270. Controller->DriverQueueDepth - CommandIdentifier + 1;
  271.   if (CommandsRemaining > CommandAllocationGroupSize)
  272. CommandsRemaining = CommandAllocationGroupSize;
  273.   CommandGroupByteCount =
  274. CommandsRemaining * CommandAllocationLength;
  275.   AllocationPointer = kmalloc(CommandGroupByteCount, GFP_ATOMIC);
  276.   if (AllocationPointer == NULL)
  277. return DAC960_Failure(Controller,
  278. "AUXILIARY STRUCTURE CREATION");
  279.   memset(AllocationPointer, 0, CommandGroupByteCount);
  280.  }
  281.       Command = (DAC960_Command_T *) AllocationPointer;
  282.       AllocationPointer += CommandAllocationLength;
  283.       Command->CommandIdentifier = CommandIdentifier;
  284.       Command->Controller = Controller;
  285.       Command->Next = Controller->FreeCommands;
  286.       Controller->FreeCommands = Command;
  287.       Controller->Commands[CommandIdentifier-1] = Command;
  288.       ScatterGatherCPU = pci_pool_alloc(ScatterGatherPool, SLAB_ATOMIC,
  289. &ScatterGatherDMA);
  290.       if (ScatterGatherCPU == NULL)
  291.   return DAC960_Failure(Controller, "AUXILIARY STRUCTURE CREATION");
  292.       if (RequestSensePool != NULL) {
  293.      RequestSenseCPU = pci_pool_alloc(RequestSensePool, SLAB_ATOMIC,
  294. &RequestSenseDMA);
  295.      if (RequestSenseCPU == NULL) {
  296.                 pci_pool_free(ScatterGatherPool, ScatterGatherCPU,
  297.                                 ScatterGatherDMA);
  298.      return DAC960_Failure(Controller,
  299. "AUXILIARY STRUCTURE CREATION");
  300.   }
  301.         }
  302.      if (Controller->FirmwareType == DAC960_V1_Controller) {
  303.         Command->cmd_sglist = Command->V1.ScatterList;
  304. Command->V1.ScatterGatherList =
  305. (DAC960_V1_ScatterGatherSegment_T *)ScatterGatherCPU;
  306. Command->V1.ScatterGatherListDMA = ScatterGatherDMA;
  307.       } else {
  308.         Command->cmd_sglist = Command->V2.ScatterList;
  309. Command->V2.ScatterGatherList =
  310. (DAC960_V2_ScatterGatherSegment_T *)ScatterGatherCPU;
  311. Command->V2.ScatterGatherListDMA = ScatterGatherDMA;
  312. Command->V2.RequestSense =
  313. (DAC960_SCSI_RequestSense_T *)RequestSenseCPU;
  314. Command->V2.RequestSenseDMA = RequestSenseDMA;
  315.       }
  316.     }
  317.   return true;
  318. }
  319. /*
  320.   DAC960_DestroyAuxiliaryStructures deallocates the auxiliary data
  321.   structures for Controller.
  322. */
  323. static void DAC960_DestroyAuxiliaryStructures(DAC960_Controller_T *Controller)
  324. {
  325.   int i;
  326.   struct pci_pool *ScatterGatherPool = Controller->ScatterGatherPool;
  327.   struct pci_pool *RequestSensePool = NULL;
  328.   void *ScatterGatherCPU;
  329.   dma_addr_t ScatterGatherDMA;
  330.   void *RequestSenseCPU;
  331.   dma_addr_t RequestSenseDMA;
  332.   DAC960_Command_T *CommandGroup = NULL;
  333.   
  334.   if (Controller->FirmwareType == DAC960_V2_Controller)
  335.         RequestSensePool = Controller->V2.RequestSensePool;
  336.   Controller->FreeCommands = NULL;
  337.   for (i = 0; i < Controller->DriverQueueDepth; i++)
  338.     {
  339.       DAC960_Command_T *Command = Controller->Commands[i];
  340.       if (Command == NULL)
  341.   continue;
  342.       if (Controller->FirmwareType == DAC960_V1_Controller) {
  343.   ScatterGatherCPU = (void *)Command->V1.ScatterGatherList;
  344.   ScatterGatherDMA = Command->V1.ScatterGatherListDMA;
  345.   RequestSenseCPU = NULL;
  346.   RequestSenseDMA = (dma_addr_t)0;
  347.       } else {
  348.           ScatterGatherCPU = (void *)Command->V2.ScatterGatherList;
  349.   ScatterGatherDMA = Command->V2.ScatterGatherListDMA;
  350.   RequestSenseCPU = (void *)Command->V2.RequestSense;
  351.   RequestSenseDMA = Command->V2.RequestSenseDMA;
  352.       }
  353.       if (ScatterGatherCPU != NULL)
  354.           pci_pool_free(ScatterGatherPool, ScatterGatherCPU, ScatterGatherDMA);
  355.       if (RequestSenseCPU != NULL)
  356.           pci_pool_free(RequestSensePool, RequestSenseCPU, RequestSenseDMA);
  357.       if ((Command->CommandIdentifier
  358.    % Controller->CommandAllocationGroupSize) == 1) {
  359.    /*
  360.     * We can't free the group of commands until all of the
  361.     * request sense and scatter gather dma structures are free.
  362.             * Remember the beginning of the group, but don't free it
  363.     * until we've reached the beginning of the next group.
  364.     */
  365.    if (CommandGroup != NULL)
  366. kfree(CommandGroup);
  367.     CommandGroup = Command;
  368.       }
  369.       Controller->Commands[i] = NULL;
  370.     }
  371.   if (CommandGroup != NULL)
  372.       kfree(CommandGroup);
  373.   if (Controller->CombinedStatusBuffer != NULL)
  374.     {
  375.       kfree(Controller->CombinedStatusBuffer);
  376.       Controller->CombinedStatusBuffer = NULL;
  377.       Controller->CurrentStatusBuffer = NULL;
  378.     }
  379.   if (ScatterGatherPool != NULL)
  380.    pci_pool_destroy(ScatterGatherPool);
  381.   if (Controller->FirmwareType == DAC960_V1_Controller) return;
  382.   if (RequestSensePool != NULL)
  383. pci_pool_destroy(RequestSensePool);
  384.   for (i = 0; i < DAC960_MaxLogicalDrives; i++)
  385.     if (Controller->V2.LogicalDeviceInformation[i] != NULL)
  386.       {
  387. kfree(Controller->V2.LogicalDeviceInformation[i]);
  388. Controller->V2.LogicalDeviceInformation[i] = NULL;
  389.       }
  390.   for (i = 0; i < DAC960_V2_MaxPhysicalDevices; i++)
  391.     {
  392.       if (Controller->V2.PhysicalDeviceInformation[i] != NULL)
  393. {
  394.   kfree(Controller->V2.PhysicalDeviceInformation[i]);
  395.   Controller->V2.PhysicalDeviceInformation[i] = NULL;
  396. }
  397.       if (Controller->V2.InquiryUnitSerialNumber[i] != NULL)
  398. {
  399.   kfree(Controller->V2.InquiryUnitSerialNumber[i]);
  400.   Controller->V2.InquiryUnitSerialNumber[i] = NULL;
  401. }
  402.     }
  403. }
  404. /*
  405.   DAC960_V1_ClearCommand clears critical fields of Command for DAC960 V1
  406.   Firmware Controllers.
  407. */
  408. static inline void DAC960_V1_ClearCommand(DAC960_Command_T *Command)
  409. {
  410.   DAC960_V1_CommandMailbox_T *CommandMailbox = &Command->V1.CommandMailbox;
  411.   memset(CommandMailbox, 0, sizeof(DAC960_V1_CommandMailbox_T));
  412.   Command->V1.CommandStatus = 0;
  413. }
  414. /*
  415.   DAC960_V2_ClearCommand clears critical fields of Command for DAC960 V2
  416.   Firmware Controllers.
  417. */
  418. static inline void DAC960_V2_ClearCommand(DAC960_Command_T *Command)
  419. {
  420.   DAC960_V2_CommandMailbox_T *CommandMailbox = &Command->V2.CommandMailbox;
  421.   memset(CommandMailbox, 0, sizeof(DAC960_V2_CommandMailbox_T));
  422.   Command->V2.CommandStatus = 0;
  423. }
  424. /*
  425.   DAC960_AllocateCommand allocates a Command structure from Controller's
  426.   free list.  During driver initialization, a special initialization command
  427.   has been placed on the free list to guarantee that command allocation can
  428.   never fail.
  429. */
  430. static inline DAC960_Command_T *DAC960_AllocateCommand(DAC960_Controller_T
  431.        *Controller)
  432. {
  433.   DAC960_Command_T *Command = Controller->FreeCommands;
  434.   if (Command == NULL) return NULL;
  435.   Controller->FreeCommands = Command->Next;
  436.   Command->Next = NULL;
  437.   return Command;
  438. }
  439. /*
  440.   DAC960_DeallocateCommand deallocates Command, returning it to Controller's
  441.   free list.
  442. */
  443. static inline void DAC960_DeallocateCommand(DAC960_Command_T *Command)
  444. {
  445.   DAC960_Controller_T *Controller = Command->Controller;
  446.   Command->Request = NULL;
  447.   Command->Next = Controller->FreeCommands;
  448.   Controller->FreeCommands = Command;
  449. }
  450. /*
  451.   DAC960_WaitForCommand waits for a wake_up on Controller's Command Wait Queue.
  452. */
  453. static void DAC960_WaitForCommand(DAC960_Controller_T *Controller)
  454. {
  455.   spin_unlock_irq(&Controller->queue_lock);
  456.   __wait_event(Controller->CommandWaitQueue, Controller->FreeCommands);
  457.   spin_lock_irq(&Controller->queue_lock);
  458. }
  459. /*
  460.   DAC960_GEM_QueueCommand queues Command for DAC960 GEM Series Controllers.
  461. */
  462. static void DAC960_GEM_QueueCommand(DAC960_Command_T *Command)
  463. {
  464.   DAC960_Controller_T *Controller = Command->Controller;
  465.   void __iomem *ControllerBaseAddress = Controller->BaseAddress;
  466.   DAC960_V2_CommandMailbox_T *CommandMailbox = &Command->V2.CommandMailbox;
  467.   DAC960_V2_CommandMailbox_T *NextCommandMailbox =
  468.       Controller->V2.NextCommandMailbox;
  469.   CommandMailbox->Common.CommandIdentifier = Command->CommandIdentifier;
  470.   DAC960_GEM_WriteCommandMailbox(NextCommandMailbox, CommandMailbox);
  471.   if (Controller->V2.PreviousCommandMailbox1->Words[0] == 0 ||
  472.       Controller->V2.PreviousCommandMailbox2->Words[0] == 0)
  473.       DAC960_GEM_MemoryMailboxNewCommand(ControllerBaseAddress);
  474.   Controller->V2.PreviousCommandMailbox2 =
  475.       Controller->V2.PreviousCommandMailbox1;
  476.   Controller->V2.PreviousCommandMailbox1 = NextCommandMailbox;
  477.   if (++NextCommandMailbox > Controller->V2.LastCommandMailbox)
  478.       NextCommandMailbox = Controller->V2.FirstCommandMailbox;
  479.   Controller->V2.NextCommandMailbox = NextCommandMailbox;
  480. }
  481. /*
  482.   DAC960_BA_QueueCommand queues Command for DAC960 BA Series Controllers.
  483. */
  484. static void DAC960_BA_QueueCommand(DAC960_Command_T *Command)
  485. {
  486.   DAC960_Controller_T *Controller = Command->Controller;
  487.   void __iomem *ControllerBaseAddress = Controller->BaseAddress;
  488.   DAC960_V2_CommandMailbox_T *CommandMailbox = &Command->V2.CommandMailbox;
  489.   DAC960_V2_CommandMailbox_T *NextCommandMailbox =
  490.     Controller->V2.NextCommandMailbox;
  491.   CommandMailbox->Common.CommandIdentifier = Command->CommandIdentifier;
  492.   DAC960_BA_WriteCommandMailbox(NextCommandMailbox, CommandMailbox);
  493.   if (Controller->V2.PreviousCommandMailbox1->Words[0] == 0 ||
  494.       Controller->V2.PreviousCommandMailbox2->Words[0] == 0)
  495.     DAC960_BA_MemoryMailboxNewCommand(ControllerBaseAddress);
  496.   Controller->V2.PreviousCommandMailbox2 =
  497.     Controller->V2.PreviousCommandMailbox1;
  498.   Controller->V2.PreviousCommandMailbox1 = NextCommandMailbox;
  499.   if (++NextCommandMailbox > Controller->V2.LastCommandMailbox)
  500.     NextCommandMailbox = Controller->V2.FirstCommandMailbox;
  501.   Controller->V2.NextCommandMailbox = NextCommandMailbox;
  502. }
  503. /*
  504.   DAC960_LP_QueueCommand queues Command for DAC960 LP Series Controllers.
  505. */
  506. static void DAC960_LP_QueueCommand(DAC960_Command_T *Command)
  507. {
  508.   DAC960_Controller_T *Controller = Command->Controller;
  509.   void __iomem *ControllerBaseAddress = Controller->BaseAddress;
  510.   DAC960_V2_CommandMailbox_T *CommandMailbox = &Command->V2.CommandMailbox;
  511.   DAC960_V2_CommandMailbox_T *NextCommandMailbox =
  512.     Controller->V2.NextCommandMailbox;
  513.   CommandMailbox->Common.CommandIdentifier = Command->CommandIdentifier;
  514.   DAC960_LP_WriteCommandMailbox(NextCommandMailbox, CommandMailbox);
  515.   if (Controller->V2.PreviousCommandMailbox1->Words[0] == 0 ||
  516.       Controller->V2.PreviousCommandMailbox2->Words[0] == 0)
  517.     DAC960_LP_MemoryMailboxNewCommand(ControllerBaseAddress);
  518.   Controller->V2.PreviousCommandMailbox2 =
  519.     Controller->V2.PreviousCommandMailbox1;
  520.   Controller->V2.PreviousCommandMailbox1 = NextCommandMailbox;
  521.   if (++NextCommandMailbox > Controller->V2.LastCommandMailbox)
  522.     NextCommandMailbox = Controller->V2.FirstCommandMailbox;
  523.   Controller->V2.NextCommandMailbox = NextCommandMailbox;
  524. }
  525. /*
  526.   DAC960_LA_QueueCommandDualMode queues Command for DAC960 LA Series
  527.   Controllers with Dual Mode Firmware.
  528. */
  529. static void DAC960_LA_QueueCommandDualMode(DAC960_Command_T *Command)
  530. {
  531.   DAC960_Controller_T *Controller = Command->Controller;
  532.   void __iomem *ControllerBaseAddress = Controller->BaseAddress;
  533.   DAC960_V1_CommandMailbox_T *CommandMailbox = &Command->V1.CommandMailbox;
  534.   DAC960_V1_CommandMailbox_T *NextCommandMailbox =
  535.     Controller->V1.NextCommandMailbox;
  536.   CommandMailbox->Common.CommandIdentifier = Command->CommandIdentifier;
  537.   DAC960_LA_WriteCommandMailbox(NextCommandMailbox, CommandMailbox);
  538.   if (Controller->V1.PreviousCommandMailbox1->Words[0] == 0 ||
  539.       Controller->V1.PreviousCommandMailbox2->Words[0] == 0)
  540.     DAC960_LA_MemoryMailboxNewCommand(ControllerBaseAddress);
  541.   Controller->V1.PreviousCommandMailbox2 =
  542.     Controller->V1.PreviousCommandMailbox1;
  543.   Controller->V1.PreviousCommandMailbox1 = NextCommandMailbox;
  544.   if (++NextCommandMailbox > Controller->V1.LastCommandMailbox)
  545.     NextCommandMailbox = Controller->V1.FirstCommandMailbox;
  546.   Controller->V1.NextCommandMailbox = NextCommandMailbox;
  547. }
  548. /*
  549.   DAC960_LA_QueueCommandSingleMode queues Command for DAC960 LA Series
  550.   Controllers with Single Mode Firmware.
  551. */
  552. static void DAC960_LA_QueueCommandSingleMode(DAC960_Command_T *Command)
  553. {
  554.   DAC960_Controller_T *Controller = Command->Controller;
  555.   void __iomem *ControllerBaseAddress = Controller->BaseAddress;
  556.   DAC960_V1_CommandMailbox_T *CommandMailbox = &Command->V1.CommandMailbox;
  557.   DAC960_V1_CommandMailbox_T *NextCommandMailbox =
  558.     Controller->V1.NextCommandMailbox;
  559.   CommandMailbox->Common.CommandIdentifier = Command->CommandIdentifier;
  560.   DAC960_LA_WriteCommandMailbox(NextCommandMailbox, CommandMailbox);
  561.   if (Controller->V1.PreviousCommandMailbox1->Words[0] == 0 ||
  562.       Controller->V1.PreviousCommandMailbox2->Words[0] == 0)
  563.     DAC960_LA_HardwareMailboxNewCommand(ControllerBaseAddress);
  564.   Controller->V1.PreviousCommandMailbox2 =
  565.     Controller->V1.PreviousCommandMailbox1;
  566.   Controller->V1.PreviousCommandMailbox1 = NextCommandMailbox;
  567.   if (++NextCommandMailbox > Controller->V1.LastCommandMailbox)
  568.     NextCommandMailbox = Controller->V1.FirstCommandMailbox;
  569.   Controller->V1.NextCommandMailbox = NextCommandMailbox;
  570. }
  571. /*
  572.   DAC960_PG_QueueCommandDualMode queues Command for DAC960 PG Series
  573.   Controllers with Dual Mode Firmware.
  574. */
  575. static void DAC960_PG_QueueCommandDualMode(DAC960_Command_T *Command)
  576. {
  577.   DAC960_Controller_T *Controller = Command->Controller;
  578.   void __iomem *ControllerBaseAddress = Controller->BaseAddress;
  579.   DAC960_V1_CommandMailbox_T *CommandMailbox = &Command->V1.CommandMailbox;
  580.   DAC960_V1_CommandMailbox_T *NextCommandMailbox =
  581.     Controller->V1.NextCommandMailbox;
  582.   CommandMailbox->Common.CommandIdentifier = Command->CommandIdentifier;
  583.   DAC960_PG_WriteCommandMailbox(NextCommandMailbox, CommandMailbox);
  584.   if (Controller->V1.PreviousCommandMailbox1->Words[0] == 0 ||
  585.       Controller->V1.PreviousCommandMailbox2->Words[0] == 0)
  586.     DAC960_PG_MemoryMailboxNewCommand(ControllerBaseAddress);
  587.   Controller->V1.PreviousCommandMailbox2 =
  588.     Controller->V1.PreviousCommandMailbox1;
  589.   Controller->V1.PreviousCommandMailbox1 = NextCommandMailbox;
  590.   if (++NextCommandMailbox > Controller->V1.LastCommandMailbox)
  591.     NextCommandMailbox = Controller->V1.FirstCommandMailbox;
  592.   Controller->V1.NextCommandMailbox = NextCommandMailbox;
  593. }
  594. /*
  595.   DAC960_PG_QueueCommandSingleMode queues Command for DAC960 PG Series
  596.   Controllers with Single Mode Firmware.
  597. */
  598. static void DAC960_PG_QueueCommandSingleMode(DAC960_Command_T *Command)
  599. {
  600.   DAC960_Controller_T *Controller = Command->Controller;
  601.   void __iomem *ControllerBaseAddress = Controller->BaseAddress;
  602.   DAC960_V1_CommandMailbox_T *CommandMailbox = &Command->V1.CommandMailbox;
  603.   DAC960_V1_CommandMailbox_T *NextCommandMailbox =
  604.     Controller->V1.NextCommandMailbox;
  605.   CommandMailbox->Common.CommandIdentifier = Command->CommandIdentifier;
  606.   DAC960_PG_WriteCommandMailbox(NextCommandMailbox, CommandMailbox);
  607.   if (Controller->V1.PreviousCommandMailbox1->Words[0] == 0 ||
  608.       Controller->V1.PreviousCommandMailbox2->Words[0] == 0)
  609.     DAC960_PG_HardwareMailboxNewCommand(ControllerBaseAddress);
  610.   Controller->V1.PreviousCommandMailbox2 =
  611.     Controller->V1.PreviousCommandMailbox1;
  612.   Controller->V1.PreviousCommandMailbox1 = NextCommandMailbox;
  613.   if (++NextCommandMailbox > Controller->V1.LastCommandMailbox)
  614.     NextCommandMailbox = Controller->V1.FirstCommandMailbox;
  615.   Controller->V1.NextCommandMailbox = NextCommandMailbox;
  616. }
  617. /*
  618.   DAC960_PD_QueueCommand queues Command for DAC960 PD Series Controllers.
  619. */
  620. static void DAC960_PD_QueueCommand(DAC960_Command_T *Command)
  621. {
  622.   DAC960_Controller_T *Controller = Command->Controller;
  623.   void __iomem *ControllerBaseAddress = Controller->BaseAddress;
  624.   DAC960_V1_CommandMailbox_T *CommandMailbox = &Command->V1.CommandMailbox;
  625.   CommandMailbox->Common.CommandIdentifier = Command->CommandIdentifier;
  626.   while (DAC960_PD_MailboxFullP(ControllerBaseAddress))
  627.     udelay(1);
  628.   DAC960_PD_WriteCommandMailbox(ControllerBaseAddress, CommandMailbox);
  629.   DAC960_PD_NewCommand(ControllerBaseAddress);
  630. }
  631. /*
  632.   DAC960_P_QueueCommand queues Command for DAC960 P Series Controllers.
  633. */
  634. static void DAC960_P_QueueCommand(DAC960_Command_T *Command)
  635. {
  636.   DAC960_Controller_T *Controller = Command->Controller;
  637.   void __iomem *ControllerBaseAddress = Controller->BaseAddress;
  638.   DAC960_V1_CommandMailbox_T *CommandMailbox = &Command->V1.CommandMailbox;
  639.   CommandMailbox->Common.CommandIdentifier = Command->CommandIdentifier;
  640.   switch (CommandMailbox->Common.CommandOpcode)
  641.     {
  642.     case DAC960_V1_Enquiry:
  643.       CommandMailbox->Common.CommandOpcode = DAC960_V1_Enquiry_Old;
  644.       break;
  645.     case DAC960_V1_GetDeviceState:
  646.       CommandMailbox->Common.CommandOpcode = DAC960_V1_GetDeviceState_Old;
  647.       break;
  648.     case DAC960_V1_Read:
  649.       CommandMailbox->Common.CommandOpcode = DAC960_V1_Read_Old;
  650.       DAC960_PD_To_P_TranslateReadWriteCommand(CommandMailbox);
  651.       break;
  652.     case DAC960_V1_Write:
  653.       CommandMailbox->Common.CommandOpcode = DAC960_V1_Write_Old;
  654.       DAC960_PD_To_P_TranslateReadWriteCommand(CommandMailbox);
  655.       break;
  656.     case DAC960_V1_ReadWithScatterGather:
  657.       CommandMailbox->Common.CommandOpcode =
  658. DAC960_V1_ReadWithScatterGather_Old;
  659.       DAC960_PD_To_P_TranslateReadWriteCommand(CommandMailbox);
  660.       break;
  661.     case DAC960_V1_WriteWithScatterGather:
  662.       CommandMailbox->Common.CommandOpcode =
  663. DAC960_V1_WriteWithScatterGather_Old;
  664.       DAC960_PD_To_P_TranslateReadWriteCommand(CommandMailbox);
  665.       break;
  666.     default:
  667.       break;
  668.     }
  669.   while (DAC960_PD_MailboxFullP(ControllerBaseAddress))
  670.     udelay(1);
  671.   DAC960_PD_WriteCommandMailbox(ControllerBaseAddress, CommandMailbox);
  672.   DAC960_PD_NewCommand(ControllerBaseAddress);
  673. }
  674. /*
  675.   DAC960_ExecuteCommand executes Command and waits for completion.
  676. */
  677. static void DAC960_ExecuteCommand(DAC960_Command_T *Command)
  678. {
  679.   DAC960_Controller_T *Controller = Command->Controller;
  680.   DECLARE_COMPLETION(Completion);
  681.   unsigned long flags;
  682.   Command->Completion = &Completion;
  683.   spin_lock_irqsave(&Controller->queue_lock, flags);
  684.   DAC960_QueueCommand(Command);
  685.   spin_unlock_irqrestore(&Controller->queue_lock, flags);
  686.  
  687.   if (in_interrupt())
  688.   return;
  689.   wait_for_completion(&Completion);
  690. }
  691. /*
  692.   DAC960_V1_ExecuteType3 executes a DAC960 V1 Firmware Controller Type 3
  693.   Command and waits for completion.  It returns true on success and false
  694.   on failure.
  695. */
  696. static boolean DAC960_V1_ExecuteType3(DAC960_Controller_T *Controller,
  697.       DAC960_V1_CommandOpcode_T CommandOpcode,
  698.       dma_addr_t DataDMA)
  699. {
  700.   DAC960_Command_T *Command = DAC960_AllocateCommand(Controller);
  701.   DAC960_V1_CommandMailbox_T *CommandMailbox = &Command->V1.CommandMailbox;
  702.   DAC960_V1_CommandStatus_T CommandStatus;
  703.   DAC960_V1_ClearCommand(Command);
  704.   Command->CommandType = DAC960_ImmediateCommand;
  705.   CommandMailbox->Type3.CommandOpcode = CommandOpcode;
  706.   CommandMailbox->Type3.BusAddress = DataDMA;
  707.   DAC960_ExecuteCommand(Command);
  708.   CommandStatus = Command->V1.CommandStatus;
  709.   DAC960_DeallocateCommand(Command);
  710.   return (CommandStatus == DAC960_V1_NormalCompletion);
  711. }
  712. /*
  713.   DAC960_V1_ExecuteTypeB executes a DAC960 V1 Firmware Controller Type 3B
  714.   Command and waits for completion.  It returns true on success and false
  715.   on failure.
  716. */
  717. static boolean DAC960_V1_ExecuteType3B(DAC960_Controller_T *Controller,
  718.        DAC960_V1_CommandOpcode_T CommandOpcode,
  719.        unsigned char CommandOpcode2,
  720.        dma_addr_t DataDMA)
  721. {
  722.   DAC960_Command_T *Command = DAC960_AllocateCommand(Controller);
  723.   DAC960_V1_CommandMailbox_T *CommandMailbox = &Command->V1.CommandMailbox;
  724.   DAC960_V1_CommandStatus_T CommandStatus;
  725.   DAC960_V1_ClearCommand(Command);
  726.   Command->CommandType = DAC960_ImmediateCommand;
  727.   CommandMailbox->Type3B.CommandOpcode = CommandOpcode;
  728.   CommandMailbox->Type3B.CommandOpcode2 = CommandOpcode2;
  729.   CommandMailbox->Type3B.BusAddress = DataDMA;
  730.   DAC960_ExecuteCommand(Command);
  731.   CommandStatus = Command->V1.CommandStatus;
  732.   DAC960_DeallocateCommand(Command);
  733.   return (CommandStatus == DAC960_V1_NormalCompletion);
  734. }
  735. /*
  736.   DAC960_V1_ExecuteType3D executes a DAC960 V1 Firmware Controller Type 3D
  737.   Command and waits for completion.  It returns true on success and false
  738.   on failure.
  739. */
  740. static boolean DAC960_V1_ExecuteType3D(DAC960_Controller_T *Controller,
  741.        DAC960_V1_CommandOpcode_T CommandOpcode,
  742.        unsigned char Channel,
  743.        unsigned char TargetID,
  744.        dma_addr_t DataDMA)
  745. {
  746.   DAC960_Command_T *Command = DAC960_AllocateCommand(Controller);
  747.   DAC960_V1_CommandMailbox_T *CommandMailbox = &Command->V1.CommandMailbox;
  748.   DAC960_V1_CommandStatus_T CommandStatus;
  749.   DAC960_V1_ClearCommand(Command);
  750.   Command->CommandType = DAC960_ImmediateCommand;
  751.   CommandMailbox->Type3D.CommandOpcode = CommandOpcode;
  752.   CommandMailbox->Type3D.Channel = Channel;
  753.   CommandMailbox->Type3D.TargetID = TargetID;
  754.   CommandMailbox->Type3D.BusAddress = DataDMA;
  755.   DAC960_ExecuteCommand(Command);
  756.   CommandStatus = Command->V1.CommandStatus;
  757.   DAC960_DeallocateCommand(Command);
  758.   return (CommandStatus == DAC960_V1_NormalCompletion);
  759. }
  760. /*
  761.   DAC960_V2_GeneralInfo executes a DAC960 V2 Firmware General Information
  762.   Reading IOCTL Command and waits for completion.  It returns true on success
  763.   and false on failure.
  764.   Return data in The controller's HealthStatusBuffer, which is dma-able memory
  765. */
  766. static boolean DAC960_V2_GeneralInfo(DAC960_Controller_T *Controller)
  767. {
  768.   DAC960_Command_T *Command = DAC960_AllocateCommand(Controller);
  769.   DAC960_V2_CommandMailbox_T *CommandMailbox = &Command->V2.CommandMailbox;
  770.   DAC960_V2_CommandStatus_T CommandStatus;
  771.   DAC960_V2_ClearCommand(Command);
  772.   Command->CommandType = DAC960_ImmediateCommand;
  773.   CommandMailbox->Common.CommandOpcode = DAC960_V2_IOCTL;
  774.   CommandMailbox->Common.CommandControlBits
  775. .DataTransferControllerToHost = true;
  776.   CommandMailbox->Common.CommandControlBits
  777. .NoAutoRequestSense = true;
  778.   CommandMailbox->Common.DataTransferSize = sizeof(DAC960_V2_HealthStatusBuffer_T);
  779.   CommandMailbox->Common.IOCTL_Opcode = DAC960_V2_GetHealthStatus;
  780.   CommandMailbox->Common.DataTransferMemoryAddress
  781. .ScatterGatherSegments[0]
  782. .SegmentDataPointer =
  783.     Controller->V2.HealthStatusBufferDMA;
  784.   CommandMailbox->Common.DataTransferMemoryAddress
  785. .ScatterGatherSegments[0]
  786. .SegmentByteCount =
  787.     CommandMailbox->Common.DataTransferSize;
  788.   DAC960_ExecuteCommand(Command);
  789.   CommandStatus = Command->V2.CommandStatus;
  790.   DAC960_DeallocateCommand(Command);
  791.   return (CommandStatus == DAC960_V2_NormalCompletion);
  792. }
  793. /*
  794.   DAC960_V2_ControllerInfo executes a DAC960 V2 Firmware Controller
  795.   Information Reading IOCTL Command and waits for completion.  It returns
  796.   true on success and false on failure.
  797.   Data is returned in the controller's V2.NewControllerInformation dma-able
  798.   memory buffer.
  799. */
  800. static boolean DAC960_V2_NewControllerInfo(DAC960_Controller_T *Controller)
  801. {
  802.   DAC960_Command_T *Command = DAC960_AllocateCommand(Controller);
  803.   DAC960_V2_CommandMailbox_T *CommandMailbox = &Command->V2.CommandMailbox;
  804.   DAC960_V2_CommandStatus_T CommandStatus;
  805.   DAC960_V2_ClearCommand(Command);
  806.   Command->CommandType = DAC960_ImmediateCommand;
  807.   CommandMailbox->ControllerInfo.CommandOpcode = DAC960_V2_IOCTL;
  808.   CommandMailbox->ControllerInfo.CommandControlBits
  809. .DataTransferControllerToHost = true;
  810.   CommandMailbox->ControllerInfo.CommandControlBits
  811. .NoAutoRequestSense = true;
  812.   CommandMailbox->ControllerInfo.DataTransferSize = sizeof(DAC960_V2_ControllerInfo_T);
  813.   CommandMailbox->ControllerInfo.ControllerNumber = 0;
  814.   CommandMailbox->ControllerInfo.IOCTL_Opcode = DAC960_V2_GetControllerInfo;
  815.   CommandMailbox->ControllerInfo.DataTransferMemoryAddress
  816. .ScatterGatherSegments[0]
  817. .SegmentDataPointer =
  818.      Controller->V2.NewControllerInformationDMA;
  819.   CommandMailbox->ControllerInfo.DataTransferMemoryAddress
  820. .ScatterGatherSegments[0]
  821. .SegmentByteCount =
  822.     CommandMailbox->ControllerInfo.DataTransferSize;
  823.   DAC960_ExecuteCommand(Command);
  824.   CommandStatus = Command->V2.CommandStatus;
  825.   DAC960_DeallocateCommand(Command);
  826.   return (CommandStatus == DAC960_V2_NormalCompletion);
  827. }
  828. /*
  829.   DAC960_V2_LogicalDeviceInfo executes a DAC960 V2 Firmware Controller Logical
  830.   Device Information Reading IOCTL Command and waits for completion.  It
  831.   returns true on success and false on failure.
  832.   Data is returned in the controller's V2.NewLogicalDeviceInformation
  833. */
  834. static boolean DAC960_V2_NewLogicalDeviceInfo(DAC960_Controller_T *Controller,
  835.    unsigned short LogicalDeviceNumber)
  836. {
  837.   DAC960_Command_T *Command = DAC960_AllocateCommand(Controller);
  838.   DAC960_V2_CommandMailbox_T *CommandMailbox = &Command->V2.CommandMailbox;
  839.   DAC960_V2_CommandStatus_T CommandStatus;
  840.   DAC960_V2_ClearCommand(Command);
  841.   Command->CommandType = DAC960_ImmediateCommand;
  842.   CommandMailbox->LogicalDeviceInfo.CommandOpcode =
  843. DAC960_V2_IOCTL;
  844.   CommandMailbox->LogicalDeviceInfo.CommandControlBits
  845.    .DataTransferControllerToHost = true;
  846.   CommandMailbox->LogicalDeviceInfo.CommandControlBits
  847.    .NoAutoRequestSense = true;
  848.   CommandMailbox->LogicalDeviceInfo.DataTransferSize = 
  849. sizeof(DAC960_V2_LogicalDeviceInfo_T);
  850.   CommandMailbox->LogicalDeviceInfo.LogicalDevice.LogicalDeviceNumber =
  851.     LogicalDeviceNumber;
  852.   CommandMailbox->LogicalDeviceInfo.IOCTL_Opcode = DAC960_V2_GetLogicalDeviceInfoValid;
  853.   CommandMailbox->LogicalDeviceInfo.DataTransferMemoryAddress
  854.    .ScatterGatherSegments[0]
  855.    .SegmentDataPointer =
  856.      Controller->V2.NewLogicalDeviceInformationDMA;
  857.   CommandMailbox->LogicalDeviceInfo.DataTransferMemoryAddress
  858.    .ScatterGatherSegments[0]
  859.    .SegmentByteCount =
  860.     CommandMailbox->LogicalDeviceInfo.DataTransferSize;
  861.   DAC960_ExecuteCommand(Command);
  862.   CommandStatus = Command->V2.CommandStatus;
  863.   DAC960_DeallocateCommand(Command);
  864.   return (CommandStatus == DAC960_V2_NormalCompletion);
  865. }
  866. /*
  867.   DAC960_V2_PhysicalDeviceInfo executes a DAC960 V2 Firmware Controller "Read
  868.   Physical Device Information" IOCTL Command and waits for completion.  It
  869.   returns true on success and false on failure.
  870.   The Channel, TargetID, LogicalUnit arguments should be 0 the first time
  871.   this function is called for a given controller.  This will return data
  872.   for the "first" device on that controller.  The returned data includes a
  873.   Channel, TargetID, LogicalUnit that can be passed in to this routine to
  874.   get data for the NEXT device on that controller.
  875.   Data is stored in the controller's V2.NewPhysicalDeviceInfo dma-able
  876.   memory buffer.
  877. */
  878. static boolean DAC960_V2_NewPhysicalDeviceInfo(DAC960_Controller_T *Controller,
  879.     unsigned char Channel,
  880.     unsigned char TargetID,
  881.     unsigned char LogicalUnit)
  882. {
  883.   DAC960_Command_T *Command = DAC960_AllocateCommand(Controller);
  884.   DAC960_V2_CommandMailbox_T *CommandMailbox = &Command->V2.CommandMailbox;
  885.   DAC960_V2_CommandStatus_T CommandStatus;
  886.   DAC960_V2_ClearCommand(Command);
  887.   Command->CommandType = DAC960_ImmediateCommand;
  888.   CommandMailbox->PhysicalDeviceInfo.CommandOpcode = DAC960_V2_IOCTL;
  889.   CommandMailbox->PhysicalDeviceInfo.CommandControlBits
  890.     .DataTransferControllerToHost = true;
  891.   CommandMailbox->PhysicalDeviceInfo.CommandControlBits
  892.     .NoAutoRequestSense = true;
  893.   CommandMailbox->PhysicalDeviceInfo.DataTransferSize =
  894. sizeof(DAC960_V2_PhysicalDeviceInfo_T);
  895.   CommandMailbox->PhysicalDeviceInfo.PhysicalDevice.LogicalUnit = LogicalUnit;
  896.   CommandMailbox->PhysicalDeviceInfo.PhysicalDevice.TargetID = TargetID;
  897.   CommandMailbox->PhysicalDeviceInfo.PhysicalDevice.Channel = Channel;
  898.   CommandMailbox->PhysicalDeviceInfo.IOCTL_Opcode =
  899. DAC960_V2_GetPhysicalDeviceInfoValid;
  900.   CommandMailbox->PhysicalDeviceInfo.DataTransferMemoryAddress
  901.     .ScatterGatherSegments[0]
  902.     .SegmentDataPointer =
  903.      Controller->V2.NewPhysicalDeviceInformationDMA;
  904.   CommandMailbox->PhysicalDeviceInfo.DataTransferMemoryAddress
  905.     .ScatterGatherSegments[0]
  906.     .SegmentByteCount =
  907.     CommandMailbox->PhysicalDeviceInfo.DataTransferSize;
  908.   DAC960_ExecuteCommand(Command);
  909.   CommandStatus = Command->V2.CommandStatus;
  910.   DAC960_DeallocateCommand(Command);
  911.   return (CommandStatus == DAC960_V2_NormalCompletion);
  912. }
  913. static void DAC960_V2_ConstructNewUnitSerialNumber(
  914. DAC960_Controller_T *Controller,
  915. DAC960_V2_CommandMailbox_T *CommandMailbox, int Channel, int TargetID,
  916. int LogicalUnit)
  917. {
  918.       CommandMailbox->SCSI_10.CommandOpcode = DAC960_V2_SCSI_10_Passthru;
  919.       CommandMailbox->SCSI_10.CommandControlBits
  920.      .DataTransferControllerToHost = true;
  921.       CommandMailbox->SCSI_10.CommandControlBits
  922.      .NoAutoRequestSense = true;
  923.       CommandMailbox->SCSI_10.DataTransferSize =
  924. sizeof(DAC960_SCSI_Inquiry_UnitSerialNumber_T);
  925.       CommandMailbox->SCSI_10.PhysicalDevice.LogicalUnit = LogicalUnit;
  926.       CommandMailbox->SCSI_10.PhysicalDevice.TargetID = TargetID;
  927.       CommandMailbox->SCSI_10.PhysicalDevice.Channel = Channel;
  928.       CommandMailbox->SCSI_10.CDBLength = 6;
  929.       CommandMailbox->SCSI_10.SCSI_CDB[0] = 0x12; /* INQUIRY */
  930.       CommandMailbox->SCSI_10.SCSI_CDB[1] = 1; /* EVPD = 1 */
  931.       CommandMailbox->SCSI_10.SCSI_CDB[2] = 0x80; /* Page Code */
  932.       CommandMailbox->SCSI_10.SCSI_CDB[3] = 0; /* Reserved */
  933.       CommandMailbox->SCSI_10.SCSI_CDB[4] =
  934. sizeof(DAC960_SCSI_Inquiry_UnitSerialNumber_T);
  935.       CommandMailbox->SCSI_10.SCSI_CDB[5] = 0; /* Control */
  936.       CommandMailbox->SCSI_10.DataTransferMemoryAddress
  937.      .ScatterGatherSegments[0]
  938.      .SegmentDataPointer =
  939. Controller->V2.NewInquiryUnitSerialNumberDMA;
  940.       CommandMailbox->SCSI_10.DataTransferMemoryAddress
  941.      .ScatterGatherSegments[0]
  942.      .SegmentByteCount =
  943. CommandMailbox->SCSI_10.DataTransferSize;
  944. }
  945. /*
  946.   DAC960_V2_NewUnitSerialNumber executes an SCSI pass-through
  947.   Inquiry command to a SCSI device identified by Channel number,
  948.   Target id, Logical Unit Number.  This function Waits for completion
  949.   of the command.
  950.   The return data includes Unit Serial Number information for the
  951.   specified device.
  952.   Data is stored in the controller's V2.NewPhysicalDeviceInfo dma-able
  953.   memory buffer.
  954. */
  955. static boolean DAC960_V2_NewInquiryUnitSerialNumber(DAC960_Controller_T *Controller,
  956. int Channel, int TargetID, int LogicalUnit)
  957. {
  958.       DAC960_Command_T *Command;
  959.       DAC960_V2_CommandMailbox_T *CommandMailbox;
  960.       DAC960_V2_CommandStatus_T CommandStatus;
  961.       Command = DAC960_AllocateCommand(Controller);
  962.       CommandMailbox = &Command->V2.CommandMailbox;
  963.       DAC960_V2_ClearCommand(Command);
  964.       Command->CommandType = DAC960_ImmediateCommand;
  965.       DAC960_V2_ConstructNewUnitSerialNumber(Controller, CommandMailbox,
  966. Channel, TargetID, LogicalUnit);
  967.       DAC960_ExecuteCommand(Command);
  968.       CommandStatus = Command->V2.CommandStatus;
  969.       DAC960_DeallocateCommand(Command);
  970.       return (CommandStatus == DAC960_V2_NormalCompletion);
  971. }
  972. /*
  973.   DAC960_V2_DeviceOperation executes a DAC960 V2 Firmware Controller Device
  974.   Operation IOCTL Command and waits for completion.  It returns true on
  975.   success and false on failure.
  976. */
  977. static boolean DAC960_V2_DeviceOperation(DAC960_Controller_T *Controller,
  978.  DAC960_V2_IOCTL_Opcode_T IOCTL_Opcode,
  979.  DAC960_V2_OperationDevice_T
  980.    OperationDevice)
  981. {
  982.   DAC960_Command_T *Command = DAC960_AllocateCommand(Controller);
  983.   DAC960_V2_CommandMailbox_T *CommandMailbox = &Command->V2.CommandMailbox;
  984.   DAC960_V2_CommandStatus_T CommandStatus;
  985.   DAC960_V2_ClearCommand(Command);
  986.   Command->CommandType = DAC960_ImmediateCommand;
  987.   CommandMailbox->DeviceOperation.CommandOpcode = DAC960_V2_IOCTL;
  988.   CommandMailbox->DeviceOperation.CommandControlBits
  989.  .DataTransferControllerToHost = true;
  990.   CommandMailbox->DeviceOperation.CommandControlBits
  991.       .NoAutoRequestSense = true;
  992.   CommandMailbox->DeviceOperation.IOCTL_Opcode = IOCTL_Opcode;
  993.   CommandMailbox->DeviceOperation.OperationDevice = OperationDevice;
  994.   DAC960_ExecuteCommand(Command);
  995.   CommandStatus = Command->V2.CommandStatus;
  996.   DAC960_DeallocateCommand(Command);
  997.   return (CommandStatus == DAC960_V2_NormalCompletion);
  998. }
  999. /*
  1000.   DAC960_V1_EnableMemoryMailboxInterface enables the Memory Mailbox Interface
  1001.   for DAC960 V1 Firmware Controllers.
  1002.   PD and P controller types have no memory mailbox, but still need the
  1003.   other dma mapped memory.
  1004. */
  1005. static boolean DAC960_V1_EnableMemoryMailboxInterface(DAC960_Controller_T
  1006.       *Controller)
  1007. {
  1008.   void __iomem *ControllerBaseAddress = Controller->BaseAddress;
  1009.   DAC960_HardwareType_T hw_type = Controller->HardwareType;
  1010.   struct pci_dev *PCI_Device = Controller->PCIDevice;
  1011.   struct dma_loaf *DmaPages = &Controller->DmaPages;
  1012.   size_t DmaPagesSize;
  1013.   size_t CommandMailboxesSize;
  1014.   size_t StatusMailboxesSize;
  1015.   DAC960_V1_CommandMailbox_T *CommandMailboxesMemory;
  1016.   dma_addr_t CommandMailboxesMemoryDMA;
  1017.   DAC960_V1_StatusMailbox_T *StatusMailboxesMemory;
  1018.   dma_addr_t StatusMailboxesMemoryDMA;
  1019.   DAC960_V1_CommandMailbox_T CommandMailbox;
  1020.   DAC960_V1_CommandStatus_T CommandStatus;
  1021.   int TimeoutCounter;
  1022.   int i;
  1023.   
  1024.   if (pci_set_dma_mask(Controller->PCIDevice, DAC690_V1_PciDmaMask))
  1025. return DAC960_Failure(Controller, "DMA mask out of range");
  1026.   Controller->BounceBufferLimit = DAC690_V1_PciDmaMask;
  1027.   if ((hw_type == DAC960_PD_Controller) || (hw_type == DAC960_P_Controller)) {
  1028.     CommandMailboxesSize =  0;
  1029.     StatusMailboxesSize = 0;
  1030.   } else {
  1031.     CommandMailboxesSize =  DAC960_V1_CommandMailboxCount * sizeof(DAC960_V1_CommandMailbox_T);
  1032.     StatusMailboxesSize = DAC960_V1_StatusMailboxCount * sizeof(DAC960_V1_StatusMailbox_T);
  1033.   }
  1034.   DmaPagesSize = CommandMailboxesSize + StatusMailboxesSize + 
  1035. sizeof(DAC960_V1_DCDB_T) + sizeof(DAC960_V1_Enquiry_T) +
  1036. sizeof(DAC960_V1_ErrorTable_T) + sizeof(DAC960_V1_EventLogEntry_T) +
  1037. sizeof(DAC960_V1_RebuildProgress_T) +
  1038. sizeof(DAC960_V1_LogicalDriveInformationArray_T) +
  1039. sizeof(DAC960_V1_BackgroundInitializationStatus_T) +
  1040. sizeof(DAC960_V1_DeviceState_T) + sizeof(DAC960_SCSI_Inquiry_T) +
  1041. sizeof(DAC960_SCSI_Inquiry_UnitSerialNumber_T);
  1042.   if (!init_dma_loaf(PCI_Device, DmaPages, DmaPagesSize))
  1043. return false;
  1044.   if ((hw_type == DAC960_PD_Controller) || (hw_type == DAC960_P_Controller)) 
  1045. goto skip_mailboxes;
  1046.   CommandMailboxesMemory = slice_dma_loaf(DmaPages,
  1047.                 CommandMailboxesSize, &CommandMailboxesMemoryDMA);
  1048.   
  1049.   /* These are the base addresses for the command memory mailbox array */
  1050.   Controller->V1.FirstCommandMailbox = CommandMailboxesMemory;
  1051.   Controller->V1.FirstCommandMailboxDMA = CommandMailboxesMemoryDMA;
  1052.   CommandMailboxesMemory += DAC960_V1_CommandMailboxCount - 1;
  1053.   Controller->V1.LastCommandMailbox = CommandMailboxesMemory;
  1054.   Controller->V1.NextCommandMailbox = Controller->V1.FirstCommandMailbox;
  1055.   Controller->V1.PreviousCommandMailbox1 = Controller->V1.LastCommandMailbox;
  1056.   Controller->V1.PreviousCommandMailbox2 =
  1057.    Controller->V1.LastCommandMailbox - 1;
  1058.   /* These are the base addresses for the status memory mailbox array */
  1059.   StatusMailboxesMemory = slice_dma_loaf(DmaPages,
  1060.                 StatusMailboxesSize, &StatusMailboxesMemoryDMA);
  1061.   Controller->V1.FirstStatusMailbox = StatusMailboxesMemory;
  1062.   Controller->V1.FirstStatusMailboxDMA = StatusMailboxesMemoryDMA;
  1063.   StatusMailboxesMemory += DAC960_V1_StatusMailboxCount - 1;
  1064.   Controller->V1.LastStatusMailbox = StatusMailboxesMemory;
  1065.   Controller->V1.NextStatusMailbox = Controller->V1.FirstStatusMailbox;
  1066. skip_mailboxes:
  1067.   Controller->V1.MonitoringDCDB = slice_dma_loaf(DmaPages,
  1068.                 sizeof(DAC960_V1_DCDB_T),
  1069.                 &Controller->V1.MonitoringDCDB_DMA);
  1070.   Controller->V1.NewEnquiry = slice_dma_loaf(DmaPages,
  1071.                 sizeof(DAC960_V1_Enquiry_T),
  1072.                 &Controller->V1.NewEnquiryDMA);
  1073.   Controller->V1.NewErrorTable = slice_dma_loaf(DmaPages,
  1074.                 sizeof(DAC960_V1_ErrorTable_T),
  1075.                 &Controller->V1.NewErrorTableDMA);
  1076.   Controller->V1.EventLogEntry = slice_dma_loaf(DmaPages,
  1077.                 sizeof(DAC960_V1_EventLogEntry_T),
  1078.                 &Controller->V1.EventLogEntryDMA);
  1079.   Controller->V1.RebuildProgress = slice_dma_loaf(DmaPages,
  1080.                 sizeof(DAC960_V1_RebuildProgress_T),
  1081.                 &Controller->V1.RebuildProgressDMA);
  1082.   Controller->V1.NewLogicalDriveInformation = slice_dma_loaf(DmaPages,
  1083.                 sizeof(DAC960_V1_LogicalDriveInformationArray_T),
  1084.                 &Controller->V1.NewLogicalDriveInformationDMA);
  1085.   Controller->V1.BackgroundInitializationStatus = slice_dma_loaf(DmaPages,
  1086.                 sizeof(DAC960_V1_BackgroundInitializationStatus_T),
  1087.                 &Controller->V1.BackgroundInitializationStatusDMA);
  1088.   Controller->V1.NewDeviceState = slice_dma_loaf(DmaPages,
  1089.                 sizeof(DAC960_V1_DeviceState_T),
  1090.                 &Controller->V1.NewDeviceStateDMA);
  1091.   Controller->V1.NewInquiryStandardData = slice_dma_loaf(DmaPages,
  1092.                 sizeof(DAC960_SCSI_Inquiry_T),
  1093.                 &Controller->V1.NewInquiryStandardDataDMA);
  1094.   Controller->V1.NewInquiryUnitSerialNumber = slice_dma_loaf(DmaPages,
  1095.                 sizeof(DAC960_SCSI_Inquiry_UnitSerialNumber_T),
  1096.                 &Controller->V1.NewInquiryUnitSerialNumberDMA);
  1097.   if ((hw_type == DAC960_PD_Controller) || (hw_type == DAC960_P_Controller))
  1098. return true;
  1099.  
  1100.   /* Enable the Memory Mailbox Interface. */
  1101.   Controller->V1.DualModeMemoryMailboxInterface = true;
  1102.   CommandMailbox.TypeX.CommandOpcode = 0x2B;
  1103.   CommandMailbox.TypeX.CommandIdentifier = 0;
  1104.   CommandMailbox.TypeX.CommandOpcode2 = 0x14;
  1105.   CommandMailbox.TypeX.CommandMailboxesBusAddress =
  1106.      Controller->V1.FirstCommandMailboxDMA;
  1107.   CommandMailbox.TypeX.StatusMailboxesBusAddress =
  1108.      Controller->V1.FirstStatusMailboxDMA;
  1109. #define TIMEOUT_COUNT 1000000
  1110.   for (i = 0; i < 2; i++)
  1111.     switch (Controller->HardwareType)
  1112.       {
  1113.       case DAC960_LA_Controller:
  1114. TimeoutCounter = TIMEOUT_COUNT;
  1115. while (--TimeoutCounter >= 0)
  1116.   {
  1117.     if (!DAC960_LA_HardwareMailboxFullP(ControllerBaseAddress))
  1118.       break;
  1119.     udelay(10);
  1120.   }
  1121. if (TimeoutCounter < 0) return false;
  1122. DAC960_LA_WriteHardwareMailbox(ControllerBaseAddress, &CommandMailbox);
  1123. DAC960_LA_HardwareMailboxNewCommand(ControllerBaseAddress);
  1124. TimeoutCounter = TIMEOUT_COUNT;
  1125. while (--TimeoutCounter >= 0)
  1126.   {
  1127.     if (DAC960_LA_HardwareMailboxStatusAvailableP(
  1128.   ControllerBaseAddress))
  1129.       break;
  1130.     udelay(10);
  1131.   }
  1132. if (TimeoutCounter < 0) return false;
  1133. CommandStatus = DAC960_LA_ReadStatusRegister(ControllerBaseAddress);
  1134. DAC960_LA_AcknowledgeHardwareMailboxInterrupt(ControllerBaseAddress);
  1135. DAC960_LA_AcknowledgeHardwareMailboxStatus(ControllerBaseAddress);
  1136. if (CommandStatus == DAC960_V1_NormalCompletion) return true;
  1137. Controller->V1.DualModeMemoryMailboxInterface = false;
  1138. CommandMailbox.TypeX.CommandOpcode2 = 0x10;
  1139. break;
  1140.       case DAC960_PG_Controller:
  1141. TimeoutCounter = TIMEOUT_COUNT;
  1142. while (--TimeoutCounter >= 0)
  1143.   {
  1144.     if (!DAC960_PG_HardwareMailboxFullP(ControllerBaseAddress))
  1145.       break;
  1146.     udelay(10);
  1147.   }
  1148. if (TimeoutCounter < 0) return false;
  1149. DAC960_PG_WriteHardwareMailbox(ControllerBaseAddress, &CommandMailbox);
  1150. DAC960_PG_HardwareMailboxNewCommand(ControllerBaseAddress);
  1151. TimeoutCounter = TIMEOUT_COUNT;
  1152. while (--TimeoutCounter >= 0)
  1153.   {
  1154.     if (DAC960_PG_HardwareMailboxStatusAvailableP(
  1155.   ControllerBaseAddress))
  1156.       break;
  1157.     udelay(10);
  1158.   }
  1159. if (TimeoutCounter < 0) return false;
  1160. CommandStatus = DAC960_PG_ReadStatusRegister(ControllerBaseAddress);
  1161. DAC960_PG_AcknowledgeHardwareMailboxInterrupt(ControllerBaseAddress);
  1162. DAC960_PG_AcknowledgeHardwareMailboxStatus(ControllerBaseAddress);
  1163. if (CommandStatus == DAC960_V1_NormalCompletion) return true;
  1164. Controller->V1.DualModeMemoryMailboxInterface = false;
  1165. CommandMailbox.TypeX.CommandOpcode2 = 0x10;
  1166. break;
  1167.       default:
  1168.         DAC960_Failure(Controller, "Unknown Controller Typen");
  1169. break;
  1170.       }
  1171.   return false;
  1172. }
  1173. /*
  1174.   DAC960_V2_EnableMemoryMailboxInterface enables the Memory Mailbox Interface
  1175.   for DAC960 V2 Firmware Controllers.
  1176.   Aggregate the space needed for the controller's memory mailbox and
  1177.   the other data structures that will be targets of dma transfers with
  1178.   the controller.  Allocate a dma-mapped region of memory to hold these
  1179.   structures.  Then, save CPU pointers and dma_addr_t values to reference
  1180.   the structures that are contained in that region.
  1181. */
  1182. static boolean DAC960_V2_EnableMemoryMailboxInterface(DAC960_Controller_T
  1183.       *Controller)
  1184. {
  1185.   void __iomem *ControllerBaseAddress = Controller->BaseAddress;
  1186.   struct pci_dev *PCI_Device = Controller->PCIDevice;
  1187.   struct dma_loaf *DmaPages = &Controller->DmaPages;
  1188.   size_t DmaPagesSize;
  1189.   size_t CommandMailboxesSize;
  1190.   size_t StatusMailboxesSize;
  1191.   DAC960_V2_CommandMailbox_T *CommandMailboxesMemory;
  1192.   dma_addr_t CommandMailboxesMemoryDMA;
  1193.   DAC960_V2_StatusMailbox_T *StatusMailboxesMemory;
  1194.   dma_addr_t StatusMailboxesMemoryDMA;
  1195.   DAC960_V2_CommandMailbox_T *CommandMailbox;
  1196.   dma_addr_t CommandMailboxDMA;
  1197.   DAC960_V2_CommandStatus_T CommandStatus;
  1198.   if (pci_set_dma_mask(Controller->PCIDevice, DAC690_V2_PciDmaMask))
  1199. return DAC960_Failure(Controller, "DMA mask out of range");
  1200.   Controller->BounceBufferLimit = DAC690_V2_PciDmaMask;
  1201.   /* This is a temporary dma mapping, used only in the scope of this function */
  1202.   CommandMailbox =
  1203.   (DAC960_V2_CommandMailbox_T *)pci_alloc_consistent( PCI_Device,
  1204. sizeof(DAC960_V2_CommandMailbox_T), &CommandMailboxDMA);
  1205.   if (CommandMailbox == NULL)
  1206.   return false;
  1207.   CommandMailboxesSize = DAC960_V2_CommandMailboxCount * sizeof(DAC960_V2_CommandMailbox_T);
  1208.   StatusMailboxesSize = DAC960_V2_StatusMailboxCount * sizeof(DAC960_V2_StatusMailbox_T);
  1209.   DmaPagesSize =
  1210.     CommandMailboxesSize + StatusMailboxesSize +
  1211.     sizeof(DAC960_V2_HealthStatusBuffer_T) +
  1212.     sizeof(DAC960_V2_ControllerInfo_T) +
  1213.     sizeof(DAC960_V2_LogicalDeviceInfo_T) +
  1214.     sizeof(DAC960_V2_PhysicalDeviceInfo_T) +
  1215.     sizeof(DAC960_SCSI_Inquiry_UnitSerialNumber_T) +
  1216.     sizeof(DAC960_V2_Event_T) +
  1217.     sizeof(DAC960_V2_PhysicalToLogicalDevice_T);
  1218.   if (!init_dma_loaf(PCI_Device, DmaPages, DmaPagesSize)) {
  1219.    pci_free_consistent(PCI_Device, sizeof(DAC960_V2_CommandMailbox_T),
  1220. CommandMailbox, CommandMailboxDMA);
  1221. return false;
  1222.   }
  1223.   CommandMailboxesMemory = slice_dma_loaf(DmaPages,
  1224. CommandMailboxesSize, &CommandMailboxesMemoryDMA);
  1225.   /* These are the base addresses for the command memory mailbox array */
  1226.   Controller->V2.FirstCommandMailbox = CommandMailboxesMemory;
  1227.   Controller->V2.FirstCommandMailboxDMA = CommandMailboxesMemoryDMA;
  1228.   CommandMailboxesMemory += DAC960_V2_CommandMailboxCount - 1;
  1229.   Controller->V2.LastCommandMailbox = CommandMailboxesMemory;
  1230.   Controller->V2.NextCommandMailbox = Controller->V2.FirstCommandMailbox;
  1231.   Controller->V2.PreviousCommandMailbox1 = Controller->V2.LastCommandMailbox;
  1232.   Controller->V2.PreviousCommandMailbox2 =
  1233.      Controller->V2.LastCommandMailbox - 1;
  1234.   /* These are the base addresses for the status memory mailbox array */
  1235.   StatusMailboxesMemory = slice_dma_loaf(DmaPages,
  1236. StatusMailboxesSize, &StatusMailboxesMemoryDMA);
  1237.   Controller->V2.FirstStatusMailbox = StatusMailboxesMemory;
  1238.   Controller->V2.FirstStatusMailboxDMA = StatusMailboxesMemoryDMA;
  1239.   StatusMailboxesMemory += DAC960_V2_StatusMailboxCount - 1;
  1240.   Controller->V2.LastStatusMailbox = StatusMailboxesMemory;
  1241.   Controller->V2.NextStatusMailbox = Controller->V2.FirstStatusMailbox;
  1242.   Controller->V2.HealthStatusBuffer = slice_dma_loaf(DmaPages,
  1243. sizeof(DAC960_V2_HealthStatusBuffer_T),
  1244. &Controller->V2.HealthStatusBufferDMA);
  1245.   Controller->V2.NewControllerInformation = slice_dma_loaf(DmaPages,
  1246.                 sizeof(DAC960_V2_ControllerInfo_T), 
  1247.                 &Controller->V2.NewControllerInformationDMA);
  1248.   Controller->V2.NewLogicalDeviceInformation =  slice_dma_loaf(DmaPages,
  1249.                 sizeof(DAC960_V2_LogicalDeviceInfo_T),
  1250.                 &Controller->V2.NewLogicalDeviceInformationDMA);
  1251.   Controller->V2.NewPhysicalDeviceInformation = slice_dma_loaf(DmaPages,
  1252.                 sizeof(DAC960_V2_PhysicalDeviceInfo_T),
  1253.                 &Controller->V2.NewPhysicalDeviceInformationDMA);
  1254.   Controller->V2.NewInquiryUnitSerialNumber = slice_dma_loaf(DmaPages,
  1255.                 sizeof(DAC960_SCSI_Inquiry_UnitSerialNumber_T),
  1256.                 &Controller->V2.NewInquiryUnitSerialNumberDMA);
  1257.   Controller->V2.Event = slice_dma_loaf(DmaPages,
  1258.                 sizeof(DAC960_V2_Event_T),
  1259.                 &Controller->V2.EventDMA);
  1260.   Controller->V2.PhysicalToLogicalDevice = slice_dma_loaf(DmaPages,
  1261.                 sizeof(DAC960_V2_PhysicalToLogicalDevice_T),
  1262.                 &Controller->V2.PhysicalToLogicalDeviceDMA);
  1263.   /*
  1264.     Enable the Memory Mailbox Interface.
  1265.     
  1266.     I don't know why we can't just use one of the memory mailboxes
  1267.     we just allocated to do this, instead of using this temporary one.
  1268.     Try this change later.
  1269.   */
  1270.   memset(CommandMailbox, 0, sizeof(DAC960_V2_CommandMailbox_T));
  1271.   CommandMailbox->SetMemoryMailbox.CommandIdentifier = 1;
  1272.   CommandMailbox->SetMemoryMailbox.CommandOpcode = DAC960_V2_IOCTL;
  1273.   CommandMailbox->SetMemoryMailbox.CommandControlBits.NoAutoRequestSense = true;
  1274.   CommandMailbox->SetMemoryMailbox.FirstCommandMailboxSizeKB =
  1275.     (DAC960_V2_CommandMailboxCount * sizeof(DAC960_V2_CommandMailbox_T)) >> 10;
  1276.   CommandMailbox->SetMemoryMailbox.FirstStatusMailboxSizeKB =
  1277.     (DAC960_V2_StatusMailboxCount * sizeof(DAC960_V2_StatusMailbox_T)) >> 10;
  1278.   CommandMailbox->SetMemoryMailbox.SecondCommandMailboxSizeKB = 0;
  1279.   CommandMailbox->SetMemoryMailbox.SecondStatusMailboxSizeKB = 0;
  1280.   CommandMailbox->SetMemoryMailbox.RequestSenseSize = 0;
  1281.   CommandMailbox->SetMemoryMailbox.IOCTL_Opcode = DAC960_V2_SetMemoryMailbox;
  1282.   CommandMailbox->SetMemoryMailbox.HealthStatusBufferSizeKB = 1;
  1283.   CommandMailbox->SetMemoryMailbox.HealthStatusBufferBusAddress =
  1284.      Controller->V2.HealthStatusBufferDMA;
  1285.   CommandMailbox->SetMemoryMailbox.FirstCommandMailboxBusAddress =
  1286.      Controller->V2.FirstCommandMailboxDMA;
  1287.   CommandMailbox->SetMemoryMailbox.FirstStatusMailboxBusAddress =
  1288.      Controller->V2.FirstStatusMailboxDMA;
  1289.   switch (Controller->HardwareType)
  1290.     {
  1291.     case DAC960_GEM_Controller:
  1292.       while (DAC960_GEM_HardwareMailboxFullP(ControllerBaseAddress))
  1293. udelay(1);
  1294.       DAC960_GEM_WriteHardwareMailbox(ControllerBaseAddress, CommandMailboxDMA);
  1295.       DAC960_GEM_HardwareMailboxNewCommand(ControllerBaseAddress);
  1296.       while (!DAC960_GEM_HardwareMailboxStatusAvailableP(ControllerBaseAddress))
  1297. udelay(1);
  1298.       CommandStatus = DAC960_GEM_ReadCommandStatus(ControllerBaseAddress);
  1299.       DAC960_GEM_AcknowledgeHardwareMailboxInterrupt(ControllerBaseAddress);
  1300.       DAC960_GEM_AcknowledgeHardwareMailboxStatus(ControllerBaseAddress);
  1301.       break;
  1302.     case DAC960_BA_Controller:
  1303.       while (DAC960_BA_HardwareMailboxFullP(ControllerBaseAddress))
  1304. udelay(1);
  1305.       DAC960_BA_WriteHardwareMailbox(ControllerBaseAddress, CommandMailboxDMA);
  1306.       DAC960_BA_HardwareMailboxNewCommand(ControllerBaseAddress);
  1307.       while (!DAC960_BA_HardwareMailboxStatusAvailableP(ControllerBaseAddress))
  1308. udelay(1);
  1309.       CommandStatus = DAC960_BA_ReadCommandStatus(ControllerBaseAddress);
  1310.       DAC960_BA_AcknowledgeHardwareMailboxInterrupt(ControllerBaseAddress);
  1311.       DAC960_BA_AcknowledgeHardwareMailboxStatus(ControllerBaseAddress);
  1312.       break;
  1313.     case DAC960_LP_Controller:
  1314.       while (DAC960_LP_HardwareMailboxFullP(ControllerBaseAddress))
  1315. udelay(1);
  1316.       DAC960_LP_WriteHardwareMailbox(ControllerBaseAddress, CommandMailboxDMA);
  1317.       DAC960_LP_HardwareMailboxNewCommand(ControllerBaseAddress);
  1318.       while (!DAC960_LP_HardwareMailboxStatusAvailableP(ControllerBaseAddress))
  1319. udelay(1);
  1320.       CommandStatus = DAC960_LP_ReadCommandStatus(ControllerBaseAddress);
  1321.       DAC960_LP_AcknowledgeHardwareMailboxInterrupt(ControllerBaseAddress);
  1322.       DAC960_LP_AcknowledgeHardwareMailboxStatus(ControllerBaseAddress);
  1323.       break;
  1324.     default:
  1325.       DAC960_Failure(Controller, "Unknown Controller Typen");
  1326.       CommandStatus = DAC960_V2_AbormalCompletion;
  1327.       break;
  1328.     }
  1329.   pci_free_consistent(PCI_Device, sizeof(DAC960_V2_CommandMailbox_T),
  1330. CommandMailbox, CommandMailboxDMA);
  1331.   return (CommandStatus == DAC960_V2_NormalCompletion);
  1332. }
  1333. /*
  1334.   DAC960_V1_ReadControllerConfiguration reads the Configuration Information
  1335.   from DAC960 V1 Firmware Controllers and initializes the Controller structure.
  1336. */
  1337. static boolean DAC960_V1_ReadControllerConfiguration(DAC960_Controller_T
  1338.      *Controller)
  1339. {
  1340.   DAC960_V1_Enquiry2_T *Enquiry2;
  1341.   dma_addr_t Enquiry2DMA;
  1342.   DAC960_V1_Config2_T *Config2;
  1343.   dma_addr_t Config2DMA;
  1344.   int LogicalDriveNumber, Channel, TargetID;
  1345.   struct dma_loaf local_dma;
  1346.   if (!init_dma_loaf(Controller->PCIDevice, &local_dma,
  1347. sizeof(DAC960_V1_Enquiry2_T) + sizeof(DAC960_V1_Config2_T)))
  1348. return DAC960_Failure(Controller, "LOGICAL DEVICE ALLOCATION");
  1349.   Enquiry2 = slice_dma_loaf(&local_dma, sizeof(DAC960_V1_Enquiry2_T), &Enquiry2DMA);
  1350.   Config2 = slice_dma_loaf(&local_dma, sizeof(DAC960_V1_Config2_T), &Config2DMA);
  1351.   if (!DAC960_V1_ExecuteType3(Controller, DAC960_V1_Enquiry,
  1352.       Controller->V1.NewEnquiryDMA)) {
  1353.     free_dma_loaf(Controller->PCIDevice, &local_dma);
  1354.     return DAC960_Failure(Controller, "ENQUIRY");
  1355.   }
  1356.   memcpy(&Controller->V1.Enquiry, Controller->V1.NewEnquiry,
  1357. sizeof(DAC960_V1_Enquiry_T));
  1358.   if (!DAC960_V1_ExecuteType3(Controller, DAC960_V1_Enquiry2, Enquiry2DMA)) {
  1359.     free_dma_loaf(Controller->PCIDevice, &local_dma);
  1360.     return DAC960_Failure(Controller, "ENQUIRY2");
  1361.   }
  1362.   if (!DAC960_V1_ExecuteType3(Controller, DAC960_V1_ReadConfig2, Config2DMA)) {
  1363.     free_dma_loaf(Controller->PCIDevice, &local_dma);
  1364.     return DAC960_Failure(Controller, "READ CONFIG2");
  1365.   }
  1366.   if (!DAC960_V1_ExecuteType3(Controller, DAC960_V1_GetLogicalDriveInformation,
  1367.       Controller->V1.NewLogicalDriveInformationDMA)) {
  1368.     free_dma_loaf(Controller->PCIDevice, &local_dma);
  1369.     return DAC960_Failure(Controller, "GET LOGICAL DRIVE INFORMATION");
  1370.   }
  1371.   memcpy(&Controller->V1.LogicalDriveInformation,
  1372. Controller->V1.NewLogicalDriveInformation,
  1373. sizeof(DAC960_V1_LogicalDriveInformationArray_T));
  1374.   for (Channel = 0; Channel < Enquiry2->ActualChannels; Channel++)
  1375.     for (TargetID = 0; TargetID < Enquiry2->MaxTargets; TargetID++) {
  1376.       if (!DAC960_V1_ExecuteType3D(Controller, DAC960_V1_GetDeviceState,
  1377.    Channel, TargetID,
  1378.    Controller->V1.NewDeviceStateDMA)) {
  1379.      free_dma_loaf(Controller->PCIDevice, &local_dma);
  1380. return DAC960_Failure(Controller, "GET DEVICE STATE");
  1381. }
  1382. memcpy(&Controller->V1.DeviceState[Channel][TargetID],
  1383. Controller->V1.NewDeviceState, sizeof(DAC960_V1_DeviceState_T));
  1384.      }
  1385.   /*
  1386.     Initialize the Controller Model Name and Full Model Name fields.
  1387.   */
  1388.   switch (Enquiry2->HardwareID.SubModel)
  1389.     {
  1390.     case DAC960_V1_P_PD_PU:
  1391.       if (Enquiry2->SCSICapability.BusSpeed == DAC960_V1_Ultra)
  1392. strcpy(Controller->ModelName, "DAC960PU");
  1393.       else strcpy(Controller->ModelName, "DAC960PD");
  1394.       break;
  1395.     case DAC960_V1_PL:
  1396.       strcpy(Controller->ModelName, "DAC960PL");
  1397.       break;
  1398.     case DAC960_V1_PG:
  1399.       strcpy(Controller->ModelName, "DAC960PG");
  1400.       break;
  1401.     case DAC960_V1_PJ:
  1402.       strcpy(Controller->ModelName, "DAC960PJ");
  1403.       break;
  1404.     case DAC960_V1_PR:
  1405.       strcpy(Controller->ModelName, "DAC960PR");
  1406.       break;
  1407.     case DAC960_V1_PT:
  1408.       strcpy(Controller->ModelName, "DAC960PT");
  1409.       break;
  1410.     case DAC960_V1_PTL0:
  1411.       strcpy(Controller->ModelName, "DAC960PTL0");
  1412.       break;
  1413.     case DAC960_V1_PRL:
  1414.       strcpy(Controller->ModelName, "DAC960PRL");
  1415.       break;
  1416.     case DAC960_V1_PTL1:
  1417.       strcpy(Controller->ModelName, "DAC960PTL1");
  1418.       break;
  1419.     case DAC960_V1_1164P:
  1420.       strcpy(Controller->ModelName, "DAC1164P");
  1421.       break;
  1422.     default:
  1423.       free_dma_loaf(Controller->PCIDevice, &local_dma);
  1424.       return DAC960_Failure(Controller, "MODEL VERIFICATION");
  1425.     }
  1426.   strcpy(Controller->FullModelName, "Mylex ");
  1427.   strcat(Controller->FullModelName, Controller->ModelName);
  1428.   /*
  1429.     Initialize the Controller Firmware Version field and verify that it
  1430.     is a supported firmware version.  The supported firmware versions are:
  1431.     DAC1164P     5.06 and above
  1432.     DAC960PTL/PRL/PJ/PG     4.06 and above
  1433.     DAC960PU/PD/PL     3.51 and above
  1434.     DAC960PU/PD/PL/P     2.73 and above
  1435.   */
  1436. #if defined(CONFIG_ALPHA)
  1437.   /*
  1438.     DEC Alpha machines were often equipped with DAC960 cards that were
  1439.     OEMed from Mylex, and had their own custom firmware. Version 2.70,
  1440.     the last custom FW revision to be released by DEC for these older
  1441.     controllers, appears to work quite well with this driver.
  1442.     Cards tested successfully were several versions each of the PD and
  1443.     PU, called by DEC the KZPSC and KZPAC, respectively, and having
  1444.     the Manufacturer Numbers (from Mylex), usually on a sticker on the
  1445.     back of the board, of:
  1446.     KZPSC:  D040347 (1-channel) or D040348 (2-channel) or D040349 (3-channel)
  1447.     KZPAC:  D040395 (1-channel) or D040396 (2-channel) or D040397 (3-channel)
  1448.   */
  1449. # define FIRMWARE_27X "2.70"
  1450. #else
  1451. # define FIRMWARE_27X "2.73"
  1452. #endif
  1453.   if (Enquiry2->FirmwareID.MajorVersion == 0)
  1454.     {
  1455.       Enquiry2->FirmwareID.MajorVersion =
  1456. Controller->V1.Enquiry.MajorFirmwareVersion;
  1457.       Enquiry2->FirmwareID.MinorVersion =
  1458. Controller->V1.Enquiry.MinorFirmwareVersion;
  1459.       Enquiry2->FirmwareID.FirmwareType = '0';
  1460.       Enquiry2->FirmwareID.TurnID = 0;
  1461.     }
  1462.   sprintf(Controller->FirmwareVersion, "%d.%02d-%c-%02d",
  1463.   Enquiry2->FirmwareID.MajorVersion, Enquiry2->FirmwareID.MinorVersion,
  1464.   Enquiry2->FirmwareID.FirmwareType, Enquiry2->FirmwareID.TurnID);
  1465.   if (!((Controller->FirmwareVersion[0] == '5' &&
  1466.  strcmp(Controller->FirmwareVersion, "5.06") >= 0) ||
  1467. (Controller->FirmwareVersion[0] == '4' &&
  1468.  strcmp(Controller->FirmwareVersion, "4.06") >= 0) ||
  1469. (Controller->FirmwareVersion[0] == '3' &&
  1470.  strcmp(Controller->FirmwareVersion, "3.51") >= 0) ||
  1471. (Controller->FirmwareVersion[0] == '2' &&
  1472.  strcmp(Controller->FirmwareVersion, FIRMWARE_27X) >= 0)))
  1473.     {
  1474.       DAC960_Failure(Controller, "FIRMWARE VERSION VERIFICATION");
  1475.       DAC960_Error("Firmware Version = '%s'n", Controller,
  1476.    Controller->FirmwareVersion);
  1477.       free_dma_loaf(Controller->PCIDevice, &local_dma);
  1478.       return false;
  1479.     }
  1480.   /*
  1481.     Initialize the Controller Channels, Targets, Memory Size, and SAF-TE
  1482.     Enclosure Management Enabled fields.
  1483.   */
  1484.   Controller->Channels = Enquiry2->ActualChannels;
  1485.   Controller->Targets = Enquiry2->MaxTargets;
  1486.   Controller->MemorySize = Enquiry2->MemorySize >> 20;
  1487.   Controller->V1.SAFTE_EnclosureManagementEnabled =
  1488.     (Enquiry2->FaultManagementType == DAC960_V1_SAFTE);
  1489.   /*
  1490.     Initialize the Controller Queue Depth, Driver Queue Depth, Logical Drive
  1491.     Count, Maximum Blocks per Command, Controller Scatter/Gather Limit, and
  1492.     Driver Scatter/Gather Limit.  The Driver Queue Depth must be at most one
  1493.     less than the Controller Queue Depth to allow for an automatic drive
  1494.     rebuild operation.
  1495.   */
  1496.   Controller->ControllerQueueDepth = Controller->V1.Enquiry.MaxCommands;
  1497.   Controller->DriverQueueDepth = Controller->ControllerQueueDepth - 1;
  1498.   if (Controller->DriverQueueDepth > DAC960_MaxDriverQueueDepth)
  1499.     Controller->DriverQueueDepth = DAC960_MaxDriverQueueDepth;
  1500.   Controller->LogicalDriveCount =
  1501.     Controller->V1.Enquiry.NumberOfLogicalDrives;
  1502.   Controller->MaxBlocksPerCommand = Enquiry2->MaxBlocksPerCommand;
  1503.   Controller->ControllerScatterGatherLimit = Enquiry2->MaxScatterGatherEntries;
  1504.   Controller->DriverScatterGatherLimit =
  1505.     Controller->ControllerScatterGatherLimit;
  1506.   if (Controller->DriverScatterGatherLimit > DAC960_V1_ScatterGatherLimit)
  1507.     Controller->DriverScatterGatherLimit = DAC960_V1_ScatterGatherLimit;
  1508.   /*
  1509.     Initialize the Stripe Size, Segment Size, and Geometry Translation.
  1510.   */
  1511.   Controller->V1.StripeSize = Config2->BlocksPerStripe * Config2->BlockFactor
  1512.       >> (10 - DAC960_BlockSizeBits);
  1513.   Controller->V1.SegmentSize = Config2->BlocksPerCacheLine * Config2->BlockFactor
  1514.        >> (10 - DAC960_BlockSizeBits);
  1515.   switch (Config2->DriveGeometry)
  1516.     {
  1517.     case DAC960_V1_Geometry_128_32:
  1518.       Controller->V1.GeometryTranslationHeads = 128;
  1519.       Controller->V1.GeometryTranslationSectors = 32;
  1520.       break;
  1521.     case DAC960_V1_Geometry_255_63:
  1522.       Controller->V1.GeometryTranslationHeads = 255;
  1523.       Controller->V1.GeometryTranslationSectors = 63;
  1524.       break;
  1525.     default:
  1526.       free_dma_loaf(Controller->PCIDevice, &local_dma);
  1527.       return DAC960_Failure(Controller, "CONFIG2 DRIVE GEOMETRY");
  1528.     }
  1529.   /*
  1530.     Initialize the Background Initialization Status.
  1531.   */
  1532.   if ((Controller->FirmwareVersion[0] == '4' &&
  1533.       strcmp(Controller->FirmwareVersion, "4.08") >= 0) ||
  1534.       (Controller->FirmwareVersion[0] == '5' &&
  1535.        strcmp(Controller->FirmwareVersion, "5.08") >= 0))
  1536.     {
  1537.       Controller->V1.BackgroundInitializationStatusSupported = true;
  1538.       DAC960_V1_ExecuteType3B(Controller,
  1539.       DAC960_V1_BackgroundInitializationControl, 0x20,
  1540.       Controller->
  1541.        V1.BackgroundInitializationStatusDMA);
  1542.       memcpy(&Controller->V1.LastBackgroundInitializationStatus,
  1543. Controller->V1.BackgroundInitializationStatus,
  1544. sizeof(DAC960_V1_BackgroundInitializationStatus_T));
  1545.     }
  1546.   /*
  1547.     Initialize the Logical Drive Initially Accessible flag.
  1548.   */
  1549.   for (LogicalDriveNumber = 0;
  1550.        LogicalDriveNumber < Controller->LogicalDriveCount;
  1551.        LogicalDriveNumber++)
  1552.     if (Controller->V1.LogicalDriveInformation
  1553.        [LogicalDriveNumber].LogicalDriveState !=
  1554. DAC960_V1_LogicalDrive_Offline)
  1555.       Controller->LogicalDriveInitiallyAccessible[LogicalDriveNumber] = true;
  1556.   Controller->V1.LastRebuildStatus = DAC960_V1_NoRebuildOrCheckInProgress;
  1557.   free_dma_loaf(Controller->PCIDevice, &local_dma);
  1558.   return true;
  1559. }
  1560. /*
  1561.   DAC960_V2_ReadControllerConfiguration reads the Configuration Information
  1562.   from DAC960 V2 Firmware Controllers and initializes the Controller structure.
  1563. */
  1564. static boolean DAC960_V2_ReadControllerConfiguration(DAC960_Controller_T
  1565.      *Controller)
  1566. {
  1567.   DAC960_V2_ControllerInfo_T *ControllerInfo =
  1568.      &Controller->V2.ControllerInformation;
  1569.   unsigned short LogicalDeviceNumber = 0;
  1570.   int ModelNameLength;
  1571.   /* Get data into dma-able area, then copy into permanant location */
  1572.   if (!DAC960_V2_NewControllerInfo(Controller))
  1573.     return DAC960_Failure(Controller, "GET CONTROLLER INFO");
  1574.   memcpy(ControllerInfo, Controller->V2.NewControllerInformation,
  1575. sizeof(DAC960_V2_ControllerInfo_T));
  1576.  
  1577.   
  1578.   if (!DAC960_V2_GeneralInfo(Controller))
  1579.     return DAC960_Failure(Controller, "GET HEALTH STATUS");
  1580.   /*
  1581.     Initialize the Controller Model Name and Full Model Name fields.
  1582.   */
  1583.   ModelNameLength = sizeof(ControllerInfo->ControllerName);
  1584.   if (ModelNameLength > sizeof(Controller->ModelName)-1)
  1585.     ModelNameLength = sizeof(Controller->ModelName)-1;
  1586.   memcpy(Controller->ModelName, ControllerInfo->ControllerName,
  1587.  ModelNameLength);
  1588.   ModelNameLength--;
  1589.   while (Controller->ModelName[ModelNameLength] == ' ' ||
  1590.  Controller->ModelName[ModelNameLength] == '')
  1591.     ModelNameLength--;
  1592.   Controller->ModelName[++ModelNameLength] = '';
  1593.   strcpy(Controller->FullModelName, "Mylex ");
  1594.   strcat(Controller->FullModelName, Controller->ModelName);
  1595.   /*
  1596.     Initialize the Controller Firmware Version field.
  1597.   */
  1598.   sprintf(Controller->FirmwareVersion, "%d.%02d-%02d",
  1599.   ControllerInfo->FirmwareMajorVersion,
  1600.   ControllerInfo->FirmwareMinorVersion,
  1601.   ControllerInfo->FirmwareTurnNumber);
  1602.   if (ControllerInfo->FirmwareMajorVersion == 6 &&
  1603.       ControllerInfo->FirmwareMinorVersion == 0 &&
  1604.       ControllerInfo->FirmwareTurnNumber < 1)
  1605.     {
  1606.       DAC960_Info("FIRMWARE VERSION %s DOES NOT PROVIDE THE CONTROLLERn",
  1607.   Controller, Controller->FirmwareVersion);
  1608.       DAC960_Info("STATUS MONITORING FUNCTIONALITY NEEDED BY THIS DRIVER.n",
  1609.   Controller);
  1610.       DAC960_Info("PLEASE UPGRADE TO VERSION 6.00-01 OR ABOVE.n",
  1611.   Controller);
  1612.     }
  1613.   /*
  1614.     Initialize the Controller Channels, Targets, and Memory Size.
  1615.   */
  1616.   Controller->Channels = ControllerInfo->NumberOfPhysicalChannelsPresent;
  1617.   Controller->Targets =
  1618.     ControllerInfo->MaximumTargetsPerChannel
  1619.     [ControllerInfo->NumberOfPhysicalChannelsPresent-1];
  1620.   Controller->MemorySize = ControllerInfo->MemorySizeMB;
  1621.   /*
  1622.     Initialize the Controller Queue Depth, Driver Queue Depth, Logical Drive
  1623.     Count, Maximum Blocks per Command, Controller Scatter/Gather Limit, and
  1624.     Driver Scatter/Gather Limit.  The Driver Queue Depth must be at most one
  1625.     less than the Controller Queue Depth to allow for an automatic drive
  1626.     rebuild operation.
  1627.   */
  1628.   Controller->ControllerQueueDepth = ControllerInfo->MaximumParallelCommands;
  1629.   Controller->DriverQueueDepth = Controller->ControllerQueueDepth - 1;
  1630.   if (Controller->DriverQueueDepth > DAC960_MaxDriverQueueDepth)
  1631.     Controller->DriverQueueDepth = DAC960_MaxDriverQueueDepth;
  1632.   Controller->LogicalDriveCount = ControllerInfo->LogicalDevicesPresent;
  1633.   Controller->MaxBlocksPerCommand =
  1634.     ControllerInfo->MaximumDataTransferSizeInBlocks;
  1635.   Controller->ControllerScatterGatherLimit =
  1636.     ControllerInfo->MaximumScatterGatherEntries;
  1637.   Controller->DriverScatterGatherLimit =
  1638.     Controller->ControllerScatterGatherLimit;
  1639.   if (Controller->DriverScatterGatherLimit > DAC960_V2_ScatterGatherLimit)
  1640.     Controller->DriverScatterGatherLimit = DAC960_V2_ScatterGatherLimit;
  1641.   /*
  1642.     Initialize the Logical Device Information.
  1643.   */
  1644.   while (true)
  1645.     {
  1646.       DAC960_V2_LogicalDeviceInfo_T *NewLogicalDeviceInfo =
  1647. Controller->V2.NewLogicalDeviceInformation;
  1648.       DAC960_V2_LogicalDeviceInfo_T *LogicalDeviceInfo;
  1649.       DAC960_V2_PhysicalDevice_T PhysicalDevice;
  1650.       if (!DAC960_V2_NewLogicalDeviceInfo(Controller, LogicalDeviceNumber))
  1651. break;
  1652.       LogicalDeviceNumber = NewLogicalDeviceInfo->LogicalDeviceNumber;
  1653.       if (LogicalDeviceNumber >= DAC960_MaxLogicalDrives) {
  1654. DAC960_Error("DAC960: Logical Drive Number %d not supportedn",
  1655.        Controller, LogicalDeviceNumber);
  1656. break;
  1657.       }
  1658.       if (NewLogicalDeviceInfo->DeviceBlockSizeInBytes != DAC960_BlockSize) {
  1659. DAC960_Error("DAC960: Logical Drive Block Size %d not supportedn",
  1660.       Controller, NewLogicalDeviceInfo->DeviceBlockSizeInBytes);
  1661.         LogicalDeviceNumber++;
  1662.         continue;
  1663.       }
  1664.       PhysicalDevice.Controller = 0;
  1665.       PhysicalDevice.Channel = NewLogicalDeviceInfo->Channel;
  1666.       PhysicalDevice.TargetID = NewLogicalDeviceInfo->TargetID;
  1667.       PhysicalDevice.LogicalUnit = NewLogicalDeviceInfo->LogicalUnit;
  1668.       Controller->V2.LogicalDriveToVirtualDevice[LogicalDeviceNumber] =
  1669. PhysicalDevice;
  1670.       if (NewLogicalDeviceInfo->LogicalDeviceState !=
  1671.   DAC960_V2_LogicalDevice_Offline)
  1672. Controller->LogicalDriveInitiallyAccessible[LogicalDeviceNumber] = true;
  1673.       LogicalDeviceInfo = (DAC960_V2_LogicalDeviceInfo_T *)
  1674. kmalloc(sizeof(DAC960_V2_LogicalDeviceInfo_T), GFP_ATOMIC);
  1675.       if (LogicalDeviceInfo == NULL)
  1676. return DAC960_Failure(Controller, "LOGICAL DEVICE ALLOCATION");
  1677.       Controller->V2.LogicalDeviceInformation[LogicalDeviceNumber] =
  1678. LogicalDeviceInfo;
  1679.       memcpy(LogicalDeviceInfo, NewLogicalDeviceInfo,
  1680.      sizeof(DAC960_V2_LogicalDeviceInfo_T));
  1681.       LogicalDeviceNumber++;
  1682.     }
  1683.   return true;
  1684. }
  1685. /*
  1686.   DAC960_ReportControllerConfiguration reports the Configuration Information
  1687.   for Controller.
  1688. */
  1689. static boolean DAC960_ReportControllerConfiguration(DAC960_Controller_T
  1690.     *Controller)
  1691. {
  1692.   DAC960_Info("Configuring Mylex %s PCI RAID Controllern",
  1693.       Controller, Controller->ModelName);
  1694.   DAC960_Info("  Firmware Version: %s, Channels: %d, Memory Size: %dMBn",
  1695.       Controller, Controller->FirmwareVersion,
  1696.       Controller->Channels, Controller->MemorySize);
  1697.   DAC960_Info("  PCI Bus: %d, Device: %d, Function: %d, I/O Address: ",
  1698.       Controller, Controller->Bus,
  1699.       Controller->Device, Controller->Function);
  1700.   if (Controller->IO_Address == 0)
  1701.     DAC960_Info("Unassignedn", Controller);
  1702.   else DAC960_Info("0x%Xn", Controller, Controller->IO_Address);
  1703.   DAC960_Info("  PCI Address: 0x%X mapped at 0x%lX, IRQ Channel: %dn",
  1704.       Controller, Controller->PCI_Address,
  1705.       (unsigned long) Controller->BaseAddress,
  1706.       Controller->IRQ_Channel);
  1707.   DAC960_Info("  Controller Queue Depth: %d, "
  1708.       "Maximum Blocks per Command: %dn",
  1709.       Controller, Controller->ControllerQueueDepth,
  1710.       Controller->MaxBlocksPerCommand);
  1711.   DAC960_Info("  Driver Queue Depth: %d, "
  1712.       "Scatter/Gather Limit: %d of %d Segmentsn",
  1713.       Controller, Controller->DriverQueueDepth,
  1714.       Controller->DriverScatterGatherLimit,
  1715.       Controller->ControllerScatterGatherLimit);
  1716.   if (Controller->FirmwareType == DAC960_V1_Controller)
  1717.     {
  1718.       DAC960_Info("  Stripe Size: %dKB, Segment Size: %dKB, "
  1719.   "BIOS Geometry: %d/%dn", Controller,
  1720.   Controller->V1.StripeSize,
  1721.   Controller->V1.SegmentSize,
  1722.   Controller->V1.GeometryTranslationHeads,
  1723.   Controller->V1.GeometryTranslationSectors);
  1724.       if (Controller->V1.SAFTE_EnclosureManagementEnabled)
  1725. DAC960_Info("  SAF-TE Enclosure Management Enabledn", Controller);
  1726.     }
  1727.   return true;
  1728. }
  1729. /*
  1730.   DAC960_V1_ReadDeviceConfiguration reads the Device Configuration Information
  1731.   for DAC960 V1 Firmware Controllers by requesting the SCSI Inquiry and SCSI
  1732.   Inquiry Unit Serial Number information for each device connected to
  1733.   Controller.
  1734. */
  1735. static boolean DAC960_V1_ReadDeviceConfiguration(DAC960_Controller_T
  1736.  *Controller)
  1737. {
  1738.   struct dma_loaf local_dma;
  1739.   dma_addr_t DCDBs_dma[DAC960_V1_MaxChannels];
  1740.   DAC960_V1_DCDB_T *DCDBs_cpu[DAC960_V1_MaxChannels];
  1741.   dma_addr_t SCSI_Inquiry_dma[DAC960_V1_MaxChannels];
  1742.   DAC960_SCSI_Inquiry_T *SCSI_Inquiry_cpu[DAC960_V1_MaxChannels];
  1743.   dma_addr_t SCSI_NewInquiryUnitSerialNumberDMA[DAC960_V1_MaxChannels];
  1744.   DAC960_SCSI_Inquiry_UnitSerialNumber_T *SCSI_NewInquiryUnitSerialNumberCPU[DAC960_V1_MaxChannels];
  1745.   struct completion Completions[DAC960_V1_MaxChannels];
  1746.   unsigned long flags;
  1747.   int Channel, TargetID;
  1748.   if (!init_dma_loaf(Controller->PCIDevice, &local_dma, 
  1749. DAC960_V1_MaxChannels*(sizeof(DAC960_V1_DCDB_T) +
  1750. sizeof(DAC960_SCSI_Inquiry_T) +
  1751. sizeof(DAC960_SCSI_Inquiry_UnitSerialNumber_T))))
  1752.      return DAC960_Failure(Controller,
  1753.                         "DMA ALLOCATION FAILED IN ReadDeviceConfiguration"); 
  1754.    
  1755.   for (Channel = 0; Channel < Controller->Channels; Channel++) {
  1756. DCDBs_cpu[Channel] = slice_dma_loaf(&local_dma,
  1757. sizeof(DAC960_V1_DCDB_T), DCDBs_dma + Channel);
  1758. SCSI_Inquiry_cpu[Channel] = slice_dma_loaf(&local_dma,
  1759. sizeof(DAC960_SCSI_Inquiry_T),
  1760. SCSI_Inquiry_dma + Channel);
  1761. SCSI_NewInquiryUnitSerialNumberCPU[Channel] = slice_dma_loaf(&local_dma,
  1762. sizeof(DAC960_SCSI_Inquiry_UnitSerialNumber_T),
  1763. SCSI_NewInquiryUnitSerialNumberDMA + Channel);
  1764.   }
  1765.   for (TargetID = 0; TargetID < Controller->Targets; TargetID++)
  1766.     {
  1767.       /*
  1768.        * For each channel, submit a probe for a device on that channel.
  1769.        * The timeout interval for a device that is present is 10 seconds.
  1770.        * With this approach, the timeout periods can elapse in parallel
  1771.        * on each channel.
  1772.        */
  1773.       for (Channel = 0; Channel < Controller->Channels; Channel++)
  1774. {
  1775.   dma_addr_t NewInquiryStandardDataDMA = SCSI_Inquiry_dma[Channel];
  1776.      DAC960_V1_DCDB_T *DCDB = DCDBs_cpu[Channel];
  1777.      dma_addr_t DCDB_dma = DCDBs_dma[Channel];
  1778.   DAC960_Command_T *Command = Controller->Commands[Channel];
  1779.           struct completion *Completion = &Completions[Channel];
  1780.   init_completion(Completion);
  1781.   DAC960_V1_ClearCommand(Command);
  1782.   Command->CommandType = DAC960_ImmediateCommand;
  1783.   Command->Completion = Completion;
  1784.   Command->V1.CommandMailbox.Type3.CommandOpcode = DAC960_V1_DCDB;
  1785.   Command->V1.CommandMailbox.Type3.BusAddress = DCDB_dma;
  1786.   DCDB->Channel = Channel;
  1787.   DCDB->TargetID = TargetID;
  1788.   DCDB->Direction = DAC960_V1_DCDB_DataTransferDeviceToSystem;
  1789.   DCDB->EarlyStatus = false;
  1790.   DCDB->Timeout = DAC960_V1_DCDB_Timeout_10_seconds;
  1791.   DCDB->NoAutomaticRequestSense = false;
  1792.   DCDB->DisconnectPermitted = true;
  1793.   DCDB->TransferLength = sizeof(DAC960_SCSI_Inquiry_T);
  1794.   DCDB->BusAddress = NewInquiryStandardDataDMA;
  1795.   DCDB->CDBLength = 6;
  1796.   DCDB->TransferLengthHigh4 = 0;
  1797.   DCDB->SenseLength = sizeof(DCDB->SenseData);
  1798.   DCDB->CDB[0] = 0x12; /* INQUIRY */
  1799.   DCDB->CDB[1] = 0; /* EVPD = 0 */
  1800.   DCDB->CDB[2] = 0; /* Page Code */
  1801.   DCDB->CDB[3] = 0; /* Reserved */
  1802.   DCDB->CDB[4] = sizeof(DAC960_SCSI_Inquiry_T);
  1803.   DCDB->CDB[5] = 0; /* Control */
  1804.   spin_lock_irqsave(&Controller->queue_lock, flags);
  1805.   DAC960_QueueCommand(Command);
  1806.   spin_unlock_irqrestore(&Controller->queue_lock, flags);
  1807. }
  1808.       /*
  1809.        * Wait for the problems submitted in the previous loop
  1810.        * to complete.  On the probes that are successful, 
  1811.        * get the serial number of the device that was found.
  1812.        */
  1813.       for (Channel = 0; Channel < Controller->Channels; Channel++)
  1814. {
  1815.   DAC960_SCSI_Inquiry_T *InquiryStandardData =
  1816.     &Controller->V1.InquiryStandardData[Channel][TargetID];
  1817.   DAC960_SCSI_Inquiry_T *NewInquiryStandardData = SCSI_Inquiry_cpu[Channel];
  1818.   dma_addr_t NewInquiryUnitSerialNumberDMA =
  1819. SCSI_NewInquiryUnitSerialNumberDMA[Channel];
  1820.   DAC960_SCSI_Inquiry_UnitSerialNumber_T *NewInquiryUnitSerialNumber =
  1821.      SCSI_NewInquiryUnitSerialNumberCPU[Channel];
  1822.   DAC960_SCSI_Inquiry_UnitSerialNumber_T *InquiryUnitSerialNumber =
  1823.     &Controller->V1.InquiryUnitSerialNumber[Channel][TargetID];
  1824.   DAC960_Command_T *Command = Controller->Commands[Channel];
  1825.      DAC960_V1_DCDB_T *DCDB = DCDBs_cpu[Channel];
  1826.           struct completion *Completion = &Completions[Channel];
  1827.   wait_for_completion(Completion);
  1828.   if (Command->V1.CommandStatus != DAC960_V1_NormalCompletion) {
  1829.     memset(InquiryStandardData, 0, sizeof(DAC960_SCSI_Inquiry_T));
  1830.     InquiryStandardData->PeripheralDeviceType = 0x1F;
  1831.     continue;
  1832.   } else
  1833.     memcpy(InquiryStandardData, NewInquiryStandardData, sizeof(DAC960_SCSI_Inquiry_T));
  1834.   /* Preserve Channel and TargetID values from the previous loop */
  1835.   Command->Completion = Completion;
  1836.   DCDB->TransferLength = sizeof(DAC960_SCSI_Inquiry_UnitSerialNumber_T);
  1837.   DCDB->BusAddress = NewInquiryUnitSerialNumberDMA;
  1838.   DCDB->SenseLength = sizeof(DCDB->SenseData);
  1839.   DCDB->CDB[0] = 0x12; /* INQUIRY */
  1840.   DCDB->CDB[1] = 1; /* EVPD = 1 */
  1841.   DCDB->CDB[2] = 0x80; /* Page Code */
  1842.   DCDB->CDB[3] = 0; /* Reserved */
  1843.   DCDB->CDB[4] = sizeof(DAC960_SCSI_Inquiry_UnitSerialNumber_T);
  1844.   DCDB->CDB[5] = 0; /* Control */
  1845.   spin_lock_irqsave(&Controller->queue_lock, flags);
  1846.   DAC960_QueueCommand(Command);
  1847.   spin_unlock_irqrestore(&Controller->queue_lock, flags);
  1848.   wait_for_completion(Completion);
  1849.   if (Command->V1.CommandStatus != DAC960_V1_NormalCompletion) {
  1850.    memset(InquiryUnitSerialNumber, 0,
  1851. sizeof(DAC960_SCSI_Inquiry_UnitSerialNumber_T));
  1852.    InquiryUnitSerialNumber->PeripheralDeviceType = 0x1F;
  1853.   } else
  1854.    memcpy(InquiryUnitSerialNumber, NewInquiryUnitSerialNumber,
  1855. sizeof(DAC960_SCSI_Inquiry_UnitSerialNumber_T));
  1856. }
  1857.     }
  1858.     free_dma_loaf(Controller->PCIDevice, &local_dma);
  1859.   return true;
  1860. }
  1861. /*
  1862.   DAC960_V2_ReadDeviceConfiguration reads the Device Configuration Information
  1863.   for DAC960 V2 Firmware Controllers by requesting the Physical Device
  1864.   Information and SCSI Inquiry Unit Serial Number information for each
  1865.   device connected to Controller.
  1866. */
  1867. static boolean DAC960_V2_ReadDeviceConfiguration(DAC960_Controller_T
  1868.  *Controller)
  1869. {
  1870.   unsigned char Channel = 0, TargetID = 0, LogicalUnit = 0;
  1871.   unsigned short PhysicalDeviceIndex = 0;
  1872.   while (true)
  1873.     {
  1874.       DAC960_V2_PhysicalDeviceInfo_T *NewPhysicalDeviceInfo =
  1875. Controller->V2.NewPhysicalDeviceInformation;
  1876.       DAC960_V2_PhysicalDeviceInfo_T *PhysicalDeviceInfo;
  1877.       DAC960_SCSI_Inquiry_UnitSerialNumber_T *NewInquiryUnitSerialNumber =
  1878. Controller->V2.NewInquiryUnitSerialNumber;
  1879.       DAC960_SCSI_Inquiry_UnitSerialNumber_T *InquiryUnitSerialNumber;
  1880.       if (!DAC960_V2_NewPhysicalDeviceInfo(Controller, Channel, TargetID, LogicalUnit))
  1881.   break;
  1882.       PhysicalDeviceInfo = (DAC960_V2_PhysicalDeviceInfo_T *)
  1883. kmalloc(sizeof(DAC960_V2_PhysicalDeviceInfo_T), GFP_ATOMIC);
  1884.       if (PhysicalDeviceInfo == NULL)
  1885. return DAC960_Failure(Controller, "PHYSICAL DEVICE ALLOCATION");
  1886.       Controller->V2.PhysicalDeviceInformation[PhysicalDeviceIndex] =
  1887. PhysicalDeviceInfo;
  1888.       memcpy(PhysicalDeviceInfo, NewPhysicalDeviceInfo,
  1889. sizeof(DAC960_V2_PhysicalDeviceInfo_T));
  1890.       InquiryUnitSerialNumber = (DAC960_SCSI_Inquiry_UnitSerialNumber_T *)
  1891. kmalloc(sizeof(DAC960_SCSI_Inquiry_UnitSerialNumber_T), GFP_ATOMIC);
  1892.       if (InquiryUnitSerialNumber == NULL) {
  1893. kfree(PhysicalDeviceInfo);
  1894. return DAC960_Failure(Controller, "SERIAL NUMBER ALLOCATION");
  1895.       }
  1896.       Controller->V2.InquiryUnitSerialNumber[PhysicalDeviceIndex] =
  1897. InquiryUnitSerialNumber;
  1898.       Channel = NewPhysicalDeviceInfo->Channel;
  1899.       TargetID = NewPhysicalDeviceInfo->TargetID;
  1900.       LogicalUnit = NewPhysicalDeviceInfo->LogicalUnit;
  1901.       /*
  1902.  Some devices do NOT have Unit Serial Numbers.
  1903.  This command fails for them.  But, we still want to
  1904.  remember those devices are there.  Construct a
  1905.  UnitSerialNumber structure for the failure case.
  1906.       */
  1907.       if (!DAC960_V2_NewInquiryUnitSerialNumber(Controller, Channel, TargetID, LogicalUnit)) {
  1908.        memset(InquiryUnitSerialNumber, 0,
  1909.              sizeof(DAC960_SCSI_Inquiry_UnitSerialNumber_T));
  1910.       InquiryUnitSerialNumber->PeripheralDeviceType = 0x1F;
  1911.       } else
  1912.        memcpy(InquiryUnitSerialNumber, NewInquiryUnitSerialNumber,
  1913. sizeof(DAC960_SCSI_Inquiry_UnitSerialNumber_T));
  1914.       PhysicalDeviceIndex++;
  1915.       LogicalUnit++;
  1916.     }
  1917.   return true;
  1918. }
  1919. /*
  1920.   DAC960_SanitizeInquiryData sanitizes the Vendor, Model, Revision, and
  1921.   Product Serial Number fields of the Inquiry Standard Data and Inquiry
  1922.   Unit Serial Number structures.
  1923. */
  1924. static void DAC960_SanitizeInquiryData(DAC960_SCSI_Inquiry_T
  1925.  *InquiryStandardData,
  1926.        DAC960_SCSI_Inquiry_UnitSerialNumber_T
  1927.  *InquiryUnitSerialNumber,
  1928.        unsigned char *Vendor,
  1929.        unsigned char *Model,
  1930.        unsigned char *Revision,
  1931.        unsigned char *SerialNumber)
  1932. {
  1933.   int SerialNumberLength, i;
  1934.   if (InquiryStandardData->PeripheralDeviceType == 0x1F) return;
  1935.   for (i = 0; i < sizeof(InquiryStandardData->VendorIdentification); i++)
  1936.     {
  1937.       unsigned char VendorCharacter =
  1938. InquiryStandardData->VendorIdentification[i];
  1939.       Vendor[i] = (VendorCharacter >= ' ' && VendorCharacter <= '~'
  1940.    ? VendorCharacter : ' ');
  1941.     }
  1942.   Vendor[sizeof(InquiryStandardData->VendorIdentification)] = '';
  1943.   for (i = 0; i < sizeof(InquiryStandardData->ProductIdentification); i++)
  1944.     {
  1945.       unsigned char ModelCharacter =
  1946. InquiryStandardData->ProductIdentification[i];
  1947.       Model[i] = (ModelCharacter >= ' ' && ModelCharacter <= '~'
  1948.   ? ModelCharacter : ' ');
  1949.     }
  1950.   Model[sizeof(InquiryStandardData->ProductIdentification)] = '';
  1951.   for (i = 0; i < sizeof(InquiryStandardData->ProductRevisionLevel); i++)
  1952.     {
  1953.       unsigned char RevisionCharacter =
  1954. InquiryStandardData->ProductRevisionLevel[i];
  1955.       Revision[i] = (RevisionCharacter >= ' ' && RevisionCharacter <= '~'
  1956.      ? RevisionCharacter : ' ');
  1957.     }
  1958.   Revision[sizeof(InquiryStandardData->ProductRevisionLevel)] = '';
  1959.   if (InquiryUnitSerialNumber->PeripheralDeviceType == 0x1F) return;
  1960.   SerialNumberLength = InquiryUnitSerialNumber->PageLength;
  1961.   if (SerialNumberLength >
  1962.       sizeof(InquiryUnitSerialNumber->ProductSerialNumber))
  1963.     SerialNumberLength = sizeof(InquiryUnitSerialNumber->ProductSerialNumber);
  1964.   for (i = 0; i < SerialNumberLength; i++)
  1965.     {
  1966.       unsigned char SerialNumberCharacter =
  1967. InquiryUnitSerialNumber->ProductSerialNumber[i];
  1968.       SerialNumber[i] =
  1969. (SerialNumberCharacter >= ' ' && SerialNumberCharacter <= '~'
  1970.  ? SerialNumberCharacter : ' ');
  1971.     }
  1972.   SerialNumber[SerialNumberLength] = '';
  1973. }
  1974. /*
  1975.   DAC960_V1_ReportDeviceConfiguration reports the Device Configuration
  1976.   Information for DAC960 V1 Firmware Controllers.
  1977. */
  1978. static boolean DAC960_V1_ReportDeviceConfiguration(DAC960_Controller_T
  1979.    *Controller)
  1980. {
  1981.   int LogicalDriveNumber, Channel, TargetID;
  1982.   DAC960_Info("  Physical Devices:n", Controller);
  1983.   for (Channel = 0; Channel < Controller->Channels; Channel++)
  1984.     for (TargetID = 0; TargetID < Controller->Targets; TargetID++)
  1985.       {
  1986. DAC960_SCSI_Inquiry_T *InquiryStandardData =
  1987.   &Controller->V1.InquiryStandardData[Channel][TargetID];
  1988. DAC960_SCSI_Inquiry_UnitSerialNumber_T *InquiryUnitSerialNumber =
  1989.   &Controller->V1.InquiryUnitSerialNumber[Channel][TargetID];
  1990. DAC960_V1_DeviceState_T *DeviceState =
  1991.   &Controller->V1.DeviceState[Channel][TargetID];
  1992. DAC960_V1_ErrorTableEntry_T *ErrorEntry =
  1993.   &Controller->V1.ErrorTable.ErrorTableEntries[Channel][TargetID];
  1994. char Vendor[1+sizeof(InquiryStandardData->VendorIdentification)];
  1995. char Model[1+sizeof(InquiryStandardData->ProductIdentification)];
  1996. char Revision[1+sizeof(InquiryStandardData->ProductRevisionLevel)];
  1997. char SerialNumber[1+sizeof(InquiryUnitSerialNumber
  1998.    ->ProductSerialNumber)];
  1999. if (InquiryStandardData->PeripheralDeviceType == 0x1F) continue;
  2000. DAC960_SanitizeInquiryData(InquiryStandardData, InquiryUnitSerialNumber,
  2001.    Vendor, Model, Revision, SerialNumber);
  2002. DAC960_Info("    %d:%d%s Vendor: %s  Model: %s  Revision: %sn",
  2003.     Controller, Channel, TargetID, (TargetID < 10 ? " " : ""),
  2004.     Vendor, Model, Revision);
  2005. if (InquiryUnitSerialNumber->PeripheralDeviceType != 0x1F)
  2006.   DAC960_Info("         Serial Number: %sn", Controller, SerialNumber);
  2007. if (DeviceState->Present &&
  2008.     DeviceState->DeviceType == DAC960_V1_DiskType)
  2009.   {
  2010.     if (Controller->V1.DeviceResetCount[Channel][TargetID] > 0)
  2011.       DAC960_Info("         Disk Status: %s, %u blocks, %d resetsn",
  2012.   Controller,
  2013.   (DeviceState->DeviceState == DAC960_V1_Device_Dead
  2014.    ? "Dead"
  2015.    : DeviceState->DeviceState
  2016.      == DAC960_V1_Device_WriteOnly
  2017.      ? "Write-Only"
  2018.      : DeviceState->DeviceState
  2019.        == DAC960_V1_Device_Online
  2020.        ? "Online" : "Standby"),
  2021.   DeviceState->DiskSize,
  2022.   Controller->V1.DeviceResetCount[Channel][TargetID]);
  2023.     else
  2024.       DAC960_Info("         Disk Status: %s, %u blocksn", Controller,
  2025.   (DeviceState->DeviceState == DAC960_V1_Device_Dead
  2026.    ? "Dead"
  2027.    : DeviceState->DeviceState
  2028.      == DAC960_V1_Device_WriteOnly
  2029.      ? "Write-Only"
  2030.      : DeviceState->DeviceState
  2031.        == DAC960_V1_Device_Online
  2032.        ? "Online" : "Standby"),
  2033.   DeviceState->DiskSize);
  2034.   }
  2035. if (ErrorEntry->ParityErrorCount > 0 ||
  2036.     ErrorEntry->SoftErrorCount > 0 ||
  2037.     ErrorEntry->HardErrorCount > 0 ||
  2038.     ErrorEntry->MiscErrorCount > 0)
  2039.   DAC960_Info("         Errors - Parity: %d, Soft: %d, "
  2040.       "Hard: %d, Misc: %dn", Controller,
  2041.       ErrorEntry->ParityErrorCount,
  2042.       ErrorEntry->SoftErrorCount,
  2043.       ErrorEntry->HardErrorCount,
  2044.       ErrorEntry->MiscErrorCount);
  2045.       }
  2046.   DAC960_Info("  Logical Drives:n", Controller);
  2047.   for (LogicalDriveNumber = 0;
  2048.        LogicalDriveNumber < Controller->LogicalDriveCount;
  2049.        LogicalDriveNumber++)
  2050.     {
  2051.       DAC960_V1_LogicalDriveInformation_T *LogicalDriveInformation =
  2052. &Controller->V1.LogicalDriveInformation[LogicalDriveNumber];
  2053.       DAC960_Info("    /dev/rd/c%dd%d: RAID-%d, %s, %u blocks, %sn",
  2054.   Controller, Controller->ControllerNumber, LogicalDriveNumber,
  2055.   LogicalDriveInformation->RAIDLevel,
  2056.   (LogicalDriveInformation->LogicalDriveState
  2057.    == DAC960_V1_LogicalDrive_Online
  2058.    ? "Online"
  2059.    : LogicalDriveInformation->LogicalDriveState
  2060.      == DAC960_V1_LogicalDrive_Critical
  2061.      ? "Critical" : "Offline"),
  2062.   LogicalDriveInformation->LogicalDriveSize,
  2063.   (LogicalDriveInformation->WriteBack
  2064.    ? "Write Back" : "Write Thru"));
  2065.     }
  2066.   return true;
  2067. }
  2068. /*
  2069.   DAC960_V2_ReportDeviceConfiguration reports the Device Configuration
  2070.   Information for DAC960 V2 Firmware Controllers.
  2071. */
  2072. static boolean DAC960_V2_ReportDeviceConfiguration(DAC960_Controller_T
  2073.    *Controller)
  2074. {
  2075.   int PhysicalDeviceIndex, LogicalDriveNumber;
  2076.   DAC960_Info("  Physical Devices:n", Controller);
  2077.   for (PhysicalDeviceIndex = 0;
  2078.        PhysicalDeviceIndex < DAC960_V2_MaxPhysicalDevices;
  2079.        PhysicalDeviceIndex++)
  2080.     {
  2081.       DAC960_V2_PhysicalDeviceInfo_T *PhysicalDeviceInfo =
  2082. Controller->V2.PhysicalDeviceInformation[PhysicalDeviceIndex];
  2083.       DAC960_SCSI_Inquiry_T *InquiryStandardData =
  2084. (DAC960_SCSI_Inquiry_T *) &PhysicalDeviceInfo->SCSI_InquiryData;
  2085.       DAC960_SCSI_Inquiry_UnitSerialNumber_T *InquiryUnitSerialNumber =
  2086. Controller->V2.InquiryUnitSerialNumber[PhysicalDeviceIndex];
  2087.       char Vendor[1+sizeof(InquiryStandardData->VendorIdentification)];
  2088.       char Model[1+sizeof(InquiryStandardData->ProductIdentification)];
  2089.       char Revision[1+sizeof(InquiryStandardData->ProductRevisionLevel)];
  2090.       char SerialNumber[1+sizeof(InquiryUnitSerialNumber->ProductSerialNumber)];
  2091.       if (PhysicalDeviceInfo == NULL) break;
  2092.       DAC960_SanitizeInquiryData(InquiryStandardData, InquiryUnitSerialNumber,
  2093.  Vendor, Model, Revision, SerialNumber);
  2094.       DAC960_Info("    %d:%d%s Vendor: %s  Model: %s  Revision: %sn",
  2095.   Controller,
  2096.   PhysicalDeviceInfo->Channel,
  2097.   PhysicalDeviceInfo->TargetID,
  2098.   (PhysicalDeviceInfo->TargetID < 10 ? " " : ""),
  2099.   Vendor, Model, Revision);
  2100.       if (PhysicalDeviceInfo->NegotiatedSynchronousMegaTransfers == 0)
  2101. DAC960_Info("         %sAsynchronousn", Controller,
  2102.     (PhysicalDeviceInfo->NegotiatedDataWidthBits == 16
  2103.      ? "Wide " :""));
  2104.       else
  2105. DAC960_Info("         %sSynchronous at %d MB/secn", Controller,
  2106.     (PhysicalDeviceInfo->NegotiatedDataWidthBits == 16
  2107.      ? "Wide " :""),
  2108.     (PhysicalDeviceInfo->NegotiatedSynchronousMegaTransfers
  2109.      * PhysicalDeviceInfo->NegotiatedDataWidthBits/8));
  2110.       if (InquiryUnitSerialNumber->PeripheralDeviceType != 0x1F)
  2111. DAC960_Info("         Serial Number: %sn", Controller, SerialNumber);
  2112.       if (PhysicalDeviceInfo->PhysicalDeviceState ==
  2113.   DAC960_V2_Device_Unconfigured)
  2114. continue;
  2115.       DAC960_Info("         Disk Status: %s, %u blocksn", Controller,
  2116.   (PhysicalDeviceInfo->PhysicalDeviceState
  2117.    == DAC960_V2_Device_Online
  2118.    ? "Online"
  2119.    : PhysicalDeviceInfo->PhysicalDeviceState
  2120.      == DAC960_V2_Device_Rebuild
  2121.      ? "Rebuild"
  2122.      : PhysicalDeviceInfo->PhysicalDeviceState
  2123.        == DAC960_V2_Device_Missing
  2124.        ? "Missing"
  2125.        : PhysicalDeviceInfo->PhysicalDeviceState
  2126.  == DAC960_V2_Device_Critical
  2127.  ? "Critical"
  2128.  : PhysicalDeviceInfo->PhysicalDeviceState
  2129.    == DAC960_V2_Device_Dead
  2130.    ? "Dead"
  2131.    : PhysicalDeviceInfo->PhysicalDeviceState
  2132.      == DAC960_V2_Device_SuspectedDead
  2133.      ? "Suspected-Dead"
  2134.      : PhysicalDeviceInfo->PhysicalDeviceState
  2135.        == DAC960_V2_Device_CommandedOffline
  2136.        ? "Commanded-Offline"
  2137.        : PhysicalDeviceInfo->PhysicalDeviceState
  2138.  == DAC960_V2_Device_Standby
  2139.  ? "Standby" : "Unknown"),
  2140.   PhysicalDeviceInfo->ConfigurableDeviceSize);
  2141.       if (PhysicalDeviceInfo->ParityErrors == 0 &&
  2142.   PhysicalDeviceInfo->SoftErrors == 0 &&
  2143.   PhysicalDeviceInfo->HardErrors == 0 &&
  2144.   PhysicalDeviceInfo->MiscellaneousErrors == 0 &&
  2145.   PhysicalDeviceInfo->CommandTimeouts == 0 &&
  2146.   PhysicalDeviceInfo->Retries == 0 &&
  2147.   PhysicalDeviceInfo->Aborts == 0 &&
  2148.   PhysicalDeviceInfo->PredictedFailuresDetected == 0)