DAC960.c
上传用户:lgb322
上传日期:2013-02-24
资源大小:30529k
文件大小:257k
源码类别:

嵌入式Linux

开发平台:

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