1 /*
2
3 Linux Driver for Mylex DAC960/AcceleRAID/eXtremeRAID PCI RAID Controllers
4
5 Copyright 1998-2001 by Leonard N. Zubkoff <lnz@dandelion.com>
6
7 This program is free software; you may redistribute and/or modify it under
8 the terms of the GNU General Public License Version 2 as published by the
9 Free Software Foundation.
10
11 This program is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY, without even the implied warranty of MERCHANTABILITY
13 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 for complete details.
15
16 The author respectfully requests that any modifications to this software be
17 sent directly to him for evaluation and testing.
18
19 */
20
21
22 #define DAC960_DriverVersion "2.4.11"
23 #define DAC960_DriverDate "11 October 2001"
24
25
26 #include <linux/version.h>
27 #include <linux/module.h>
28 #include <linux/types.h>
29 #include <linux/blk.h>
30 #include <linux/blkdev.h>
31 #include <linux/completion.h>
32 #include <linux/delay.h>
33 #include <linux/hdreg.h>
34 #include <linux/blkpg.h>
35 #include <linux/interrupt.h>
36 #include <linux/ioport.h>
37 #include <linux/locks.h>
38 #include <linux/mm.h>
39 #include <linux/slab.h>
40 #include <linux/proc_fs.h>
41 #include <linux/reboot.h>
42 #include <linux/spinlock.h>
43 #include <linux/timer.h>
44 #include <linux/pci.h>
45 #include <linux/init.h>
46 #include <asm/io.h>
47 #include <asm/segment.h>
48 #include <asm/uaccess.h>
49 #include "DAC960.h"
50
51
52 /*
53 DAC960_ControllerCount is the number of DAC960 Controllers detected.
54 */
55
56 static int
57 DAC960_ControllerCount = 0;
58
59
60 /*
61 DAC960_ActiveControllerCount is the number of active DAC960 Controllers
62 detected.
63 */
64
65 static int
66 DAC960_ActiveControllerCount = 0;
67
68
69 /*
70 DAC960_Controllers is an array of pointers to the DAC960 Controller
71 structures.
72 */
73
74 static DAC960_Controller_T
75 *DAC960_Controllers[DAC960_MaxControllers] = { NULL };
76
77
78 /*
79 DAC960_BlockDeviceOperations is the Block Device Operations structure for
80 DAC960 Logical Disk Devices.
81 */
82
83 static BlockDeviceOperations_T
84 DAC960_BlockDeviceOperations =
85 { owner: THIS_MODULE,
86 open: DAC960_Open,
87 release: DAC960_Release,
88 ioctl: DAC960_IOCTL };
89
90
91 /*
92 DAC960_ProcDirectoryEntry is the DAC960 /proc/rd directory entry.
93 */
94
95 static PROC_DirectoryEntry_T
96 *DAC960_ProcDirectoryEntry;
97
98
99 /*
100 DAC960_NotifierBlock is the Notifier Block structure for DAC960 Driver.
101 */
102
103 static NotifierBlock_T
104 DAC960_NotifierBlock = { DAC960_Notifier, NULL, 0 };
105
106
107 /*
108 DAC960_AnnounceDriver announces the Driver Version and Date, Author's Name,
109 Copyright Notice, and Electronic Mail Address.
110 */
111
DAC960_AnnounceDriver(DAC960_Controller_T * Controller)112 static void DAC960_AnnounceDriver(DAC960_Controller_T *Controller)
113 {
114 DAC960_Announce("***** DAC960 RAID Driver Version "
115 DAC960_DriverVersion " of "
116 DAC960_DriverDate " *****\n", Controller);
117 DAC960_Announce("Copyright 1998-2001 by Leonard N. Zubkoff "
118 "<lnz@dandelion.com>\n", Controller);
119 }
120
121
122 /*
123 DAC960_Failure prints a standardized error message, and then returns false.
124 */
125
DAC960_Failure(DAC960_Controller_T * Controller,unsigned char * ErrorMessage)126 static boolean DAC960_Failure(DAC960_Controller_T *Controller,
127 unsigned char *ErrorMessage)
128 {
129 DAC960_Error("While configuring DAC960 PCI RAID Controller at\n",
130 Controller);
131 if (Controller->IO_Address == 0)
132 DAC960_Error("PCI Bus %d Device %d Function %d I/O Address N/A "
133 "PCI Address 0x%X\n", Controller,
134 Controller->Bus, Controller->Device,
135 Controller->Function, Controller->PCI_Address);
136 else DAC960_Error("PCI Bus %d Device %d Function %d I/O Address "
137 "0x%X PCI Address 0x%X\n", Controller,
138 Controller->Bus, Controller->Device,
139 Controller->Function, Controller->IO_Address,
140 Controller->PCI_Address);
141 DAC960_Error("%s FAILED - DETACHING\n", Controller, ErrorMessage);
142 return false;
143 }
144
145
146 /*
147 DAC960_CreateAuxiliaryStructures allocates and initializes the auxiliary
148 data structures for Controller. It returns true on success and false on
149 failure.
150 */
151
DAC960_CreateAuxiliaryStructures(DAC960_Controller_T * Controller)152 static boolean DAC960_CreateAuxiliaryStructures(DAC960_Controller_T *Controller)
153 {
154 int CommandAllocationLength, CommandAllocationGroupSize;
155 int CommandsRemaining = 0, CommandIdentifier, CommandGroupByteCount;
156 void *AllocationPointer = NULL;
157 if (Controller->FirmwareType == DAC960_V1_Controller)
158 {
159 CommandAllocationLength = offsetof(DAC960_Command_T, V1.EndMarker);
160 CommandAllocationGroupSize = DAC960_V1_CommandAllocationGroupSize;
161 }
162 else
163 {
164 CommandAllocationLength = offsetof(DAC960_Command_T, V2.EndMarker);
165 CommandAllocationGroupSize = DAC960_V2_CommandAllocationGroupSize;
166 }
167 Controller->CommandAllocationGroupSize = CommandAllocationGroupSize;
168 Controller->FreeCommands = NULL;
169 for (CommandIdentifier = 1;
170 CommandIdentifier <= Controller->DriverQueueDepth;
171 CommandIdentifier++)
172 {
173 DAC960_Command_T *Command;
174 if (--CommandsRemaining <= 0)
175 {
176 CommandsRemaining =
177 Controller->DriverQueueDepth - CommandIdentifier + 1;
178 if (CommandsRemaining > CommandAllocationGroupSize)
179 CommandsRemaining = CommandAllocationGroupSize;
180 CommandGroupByteCount =
181 CommandsRemaining * CommandAllocationLength;
182 AllocationPointer = kmalloc(CommandGroupByteCount, GFP_ATOMIC);
183 if (AllocationPointer == NULL)
184 return DAC960_Failure(Controller, "AUXILIARY STRUCTURE CREATION");
185 memset(AllocationPointer, 0, CommandGroupByteCount);
186 }
187 Command = (DAC960_Command_T *) AllocationPointer;
188 AllocationPointer += CommandAllocationLength;
189 Command->CommandIdentifier = CommandIdentifier;
190 Command->Controller = Controller;
191 Command->Next = Controller->FreeCommands;
192 Controller->FreeCommands = Command;
193 Controller->Commands[CommandIdentifier-1] = Command;
194 }
195 return true;
196 }
197
198
199 /*
200 DAC960_DestroyAuxiliaryStructures deallocates the auxiliary data
201 structures for Controller.
202 */
203
DAC960_DestroyAuxiliaryStructures(DAC960_Controller_T * Controller)204 static void DAC960_DestroyAuxiliaryStructures(DAC960_Controller_T *Controller)
205 {
206 int i;
207 Controller->FreeCommands = NULL;
208 for (i = 0; i < Controller->DriverQueueDepth; i++)
209 {
210 DAC960_Command_T *Command = Controller->Commands[i];
211 if (Command != NULL &&
212 (Command->CommandIdentifier
213 % Controller->CommandAllocationGroupSize) == 1)
214 kfree(Command);
215 Controller->Commands[i] = NULL;
216 }
217 if (Controller->CombinedStatusBuffer != NULL)
218 {
219 kfree(Controller->CombinedStatusBuffer);
220 Controller->CombinedStatusBuffer = NULL;
221 Controller->CurrentStatusBuffer = NULL;
222 }
223 if (Controller->FirmwareType == DAC960_V1_Controller) return;
224 for (i = 0; i < DAC960_MaxLogicalDrives; i++)
225 if (Controller->V2.LogicalDeviceInformation[i] != NULL)
226 {
227 kfree(Controller->V2.LogicalDeviceInformation[i]);
228 Controller->V2.LogicalDeviceInformation[i] = NULL;
229 }
230 for (i = 0; i < DAC960_V2_MaxPhysicalDevices; i++)
231 {
232 if (Controller->V2.PhysicalDeviceInformation[i] != NULL)
233 {
234 kfree(Controller->V2.PhysicalDeviceInformation[i]);
235 Controller->V2.PhysicalDeviceInformation[i] = NULL;
236 }
237 if (Controller->V2.InquiryUnitSerialNumber[i] != NULL)
238 {
239 kfree(Controller->V2.InquiryUnitSerialNumber[i]);
240 Controller->V2.InquiryUnitSerialNumber[i] = NULL;
241 }
242 }
243 }
244
245
246 /*
247 DAC960_V1_ClearCommand clears critical fields of Command for DAC960 V1
248 Firmware Controllers.
249 */
250
DAC960_V1_ClearCommand(DAC960_Command_T * Command)251 static inline void DAC960_V1_ClearCommand(DAC960_Command_T *Command)
252 {
253 DAC960_V1_CommandMailbox_T *CommandMailbox = &Command->V1.CommandMailbox;
254 memset(CommandMailbox, 0, sizeof(DAC960_V1_CommandMailbox_T));
255 Command->V1.CommandStatus = 0;
256 }
257
258
259 /*
260 DAC960_V2_ClearCommand clears critical fields of Command for DAC960 V2
261 Firmware Controllers.
262 */
263
DAC960_V2_ClearCommand(DAC960_Command_T * Command)264 static inline void DAC960_V2_ClearCommand(DAC960_Command_T *Command)
265 {
266 DAC960_V2_CommandMailbox_T *CommandMailbox = &Command->V2.CommandMailbox;
267 memset(CommandMailbox, 0, sizeof(DAC960_V2_CommandMailbox_T));
268 Command->V2.CommandStatus = 0;
269 }
270
271
272 /*
273 DAC960_AllocateCommand allocates a Command structure from Controller's
274 free list. During driver initialization, a special initialization command
275 has been placed on the free list to guarantee that command allocation can
276 never fail.
277 */
278
DAC960_AllocateCommand(DAC960_Controller_T * Controller)279 static inline DAC960_Command_T *DAC960_AllocateCommand(DAC960_Controller_T
280 *Controller)
281 {
282 DAC960_Command_T *Command = Controller->FreeCommands;
283 if (Command == NULL) return NULL;
284 Controller->FreeCommands = Command->Next;
285 Command->Next = NULL;
286 return Command;
287 }
288
289
290 /*
291 DAC960_DeallocateCommand deallocates Command, returning it to Controller's
292 free list.
293 */
294
DAC960_DeallocateCommand(DAC960_Command_T * Command)295 static inline void DAC960_DeallocateCommand(DAC960_Command_T *Command)
296 {
297 DAC960_Controller_T *Controller = Command->Controller;
298 Command->Next = Controller->FreeCommands;
299 Controller->FreeCommands = Command;
300 }
301
302
303 /*
304 DAC960_WaitForCommand waits for a wake_up on Controller's Command Wait Queue.
305 */
306
DAC960_WaitForCommand(DAC960_Controller_T * Controller)307 static void DAC960_WaitForCommand(DAC960_Controller_T *Controller)
308 {
309 spin_unlock_irq(&io_request_lock);
310 __wait_event(Controller->CommandWaitQueue, Controller->FreeCommands);
311 spin_lock_irq(&io_request_lock);
312 }
313
314
315 /*
316 DAC960_BA_QueueCommand queues Command for DAC960 BA Series Controllers.
317 */
318
DAC960_BA_QueueCommand(DAC960_Command_T * Command)319 static void DAC960_BA_QueueCommand(DAC960_Command_T *Command)
320 {
321 DAC960_Controller_T *Controller = Command->Controller;
322 void *ControllerBaseAddress = Controller->BaseAddress;
323 DAC960_V2_CommandMailbox_T *CommandMailbox = &Command->V2.CommandMailbox;
324 DAC960_V2_CommandMailbox_T *NextCommandMailbox =
325 Controller->V2.NextCommandMailbox;
326 CommandMailbox->Common.CommandIdentifier = Command->CommandIdentifier;
327 DAC960_BA_WriteCommandMailbox(NextCommandMailbox, CommandMailbox);
328 if (Controller->V2.PreviousCommandMailbox1->Words[0] == 0 ||
329 Controller->V2.PreviousCommandMailbox2->Words[0] == 0)
330 DAC960_BA_MemoryMailboxNewCommand(ControllerBaseAddress);
331 Controller->V2.PreviousCommandMailbox2 =
332 Controller->V2.PreviousCommandMailbox1;
333 Controller->V2.PreviousCommandMailbox1 = NextCommandMailbox;
334 if (++NextCommandMailbox > Controller->V2.LastCommandMailbox)
335 NextCommandMailbox = Controller->V2.FirstCommandMailbox;
336 Controller->V2.NextCommandMailbox = NextCommandMailbox;
337 }
338
339
340 /*
341 DAC960_LP_QueueCommand queues Command for DAC960 LP Series Controllers.
342 */
343
DAC960_LP_QueueCommand(DAC960_Command_T * Command)344 static void DAC960_LP_QueueCommand(DAC960_Command_T *Command)
345 {
346 DAC960_Controller_T *Controller = Command->Controller;
347 void *ControllerBaseAddress = Controller->BaseAddress;
348 DAC960_V2_CommandMailbox_T *CommandMailbox = &Command->V2.CommandMailbox;
349 DAC960_V2_CommandMailbox_T *NextCommandMailbox =
350 Controller->V2.NextCommandMailbox;
351 CommandMailbox->Common.CommandIdentifier = Command->CommandIdentifier;
352 DAC960_LP_WriteCommandMailbox(NextCommandMailbox, CommandMailbox);
353 if (Controller->V2.PreviousCommandMailbox1->Words[0] == 0 ||
354 Controller->V2.PreviousCommandMailbox2->Words[0] == 0)
355 DAC960_LP_MemoryMailboxNewCommand(ControllerBaseAddress);
356 Controller->V2.PreviousCommandMailbox2 =
357 Controller->V2.PreviousCommandMailbox1;
358 Controller->V2.PreviousCommandMailbox1 = NextCommandMailbox;
359 if (++NextCommandMailbox > Controller->V2.LastCommandMailbox)
360 NextCommandMailbox = Controller->V2.FirstCommandMailbox;
361 Controller->V2.NextCommandMailbox = NextCommandMailbox;
362 }
363
364
365 /*
366 DAC960_LA_QueueCommandDualMode queues Command for DAC960 LA Series
367 Controllers with Dual Mode Firmware.
368 */
369
DAC960_LA_QueueCommandDualMode(DAC960_Command_T * Command)370 static void DAC960_LA_QueueCommandDualMode(DAC960_Command_T *Command)
371 {
372 DAC960_Controller_T *Controller = Command->Controller;
373 void *ControllerBaseAddress = Controller->BaseAddress;
374 DAC960_V1_CommandMailbox_T *CommandMailbox = &Command->V1.CommandMailbox;
375 DAC960_V1_CommandMailbox_T *NextCommandMailbox =
376 Controller->V1.NextCommandMailbox;
377 CommandMailbox->Common.CommandIdentifier = Command->CommandIdentifier;
378 DAC960_LA_WriteCommandMailbox(NextCommandMailbox, CommandMailbox);
379 if (Controller->V1.PreviousCommandMailbox1->Words[0] == 0 ||
380 Controller->V1.PreviousCommandMailbox2->Words[0] == 0)
381 DAC960_LA_MemoryMailboxNewCommand(ControllerBaseAddress);
382 Controller->V1.PreviousCommandMailbox2 =
383 Controller->V1.PreviousCommandMailbox1;
384 Controller->V1.PreviousCommandMailbox1 = NextCommandMailbox;
385 if (++NextCommandMailbox > Controller->V1.LastCommandMailbox)
386 NextCommandMailbox = Controller->V1.FirstCommandMailbox;
387 Controller->V1.NextCommandMailbox = NextCommandMailbox;
388 }
389
390
391 /*
392 DAC960_LA_QueueCommandSingleMode queues Command for DAC960 LA Series
393 Controllers with Single Mode Firmware.
394 */
395
DAC960_LA_QueueCommandSingleMode(DAC960_Command_T * Command)396 static void DAC960_LA_QueueCommandSingleMode(DAC960_Command_T *Command)
397 {
398 DAC960_Controller_T *Controller = Command->Controller;
399 void *ControllerBaseAddress = Controller->BaseAddress;
400 DAC960_V1_CommandMailbox_T *CommandMailbox = &Command->V1.CommandMailbox;
401 DAC960_V1_CommandMailbox_T *NextCommandMailbox =
402 Controller->V1.NextCommandMailbox;
403 CommandMailbox->Common.CommandIdentifier = Command->CommandIdentifier;
404 DAC960_LA_WriteCommandMailbox(NextCommandMailbox, CommandMailbox);
405 if (Controller->V1.PreviousCommandMailbox1->Words[0] == 0 ||
406 Controller->V1.PreviousCommandMailbox2->Words[0] == 0)
407 DAC960_LA_HardwareMailboxNewCommand(ControllerBaseAddress);
408 Controller->V1.PreviousCommandMailbox2 =
409 Controller->V1.PreviousCommandMailbox1;
410 Controller->V1.PreviousCommandMailbox1 = NextCommandMailbox;
411 if (++NextCommandMailbox > Controller->V1.LastCommandMailbox)
412 NextCommandMailbox = Controller->V1.FirstCommandMailbox;
413 Controller->V1.NextCommandMailbox = NextCommandMailbox;
414 }
415
416
417 /*
418 DAC960_PG_QueueCommandDualMode queues Command for DAC960 PG Series
419 Controllers with Dual Mode Firmware.
420 */
421
DAC960_PG_QueueCommandDualMode(DAC960_Command_T * Command)422 static void DAC960_PG_QueueCommandDualMode(DAC960_Command_T *Command)
423 {
424 DAC960_Controller_T *Controller = Command->Controller;
425 void *ControllerBaseAddress = Controller->BaseAddress;
426 DAC960_V1_CommandMailbox_T *CommandMailbox = &Command->V1.CommandMailbox;
427 DAC960_V1_CommandMailbox_T *NextCommandMailbox =
428 Controller->V1.NextCommandMailbox;
429 CommandMailbox->Common.CommandIdentifier = Command->CommandIdentifier;
430 DAC960_PG_WriteCommandMailbox(NextCommandMailbox, CommandMailbox);
431 if (Controller->V1.PreviousCommandMailbox1->Words[0] == 0 ||
432 Controller->V1.PreviousCommandMailbox2->Words[0] == 0)
433 DAC960_PG_MemoryMailboxNewCommand(ControllerBaseAddress);
434 Controller->V1.PreviousCommandMailbox2 =
435 Controller->V1.PreviousCommandMailbox1;
436 Controller->V1.PreviousCommandMailbox1 = NextCommandMailbox;
437 if (++NextCommandMailbox > Controller->V1.LastCommandMailbox)
438 NextCommandMailbox = Controller->V1.FirstCommandMailbox;
439 Controller->V1.NextCommandMailbox = NextCommandMailbox;
440 }
441
442
443 /*
444 DAC960_PG_QueueCommandSingleMode queues Command for DAC960 PG Series
445 Controllers with Single Mode Firmware.
446 */
447
DAC960_PG_QueueCommandSingleMode(DAC960_Command_T * Command)448 static void DAC960_PG_QueueCommandSingleMode(DAC960_Command_T *Command)
449 {
450 DAC960_Controller_T *Controller = Command->Controller;
451 void *ControllerBaseAddress = Controller->BaseAddress;
452 DAC960_V1_CommandMailbox_T *CommandMailbox = &Command->V1.CommandMailbox;
453 DAC960_V1_CommandMailbox_T *NextCommandMailbox =
454 Controller->V1.NextCommandMailbox;
455 CommandMailbox->Common.CommandIdentifier = Command->CommandIdentifier;
456 DAC960_PG_WriteCommandMailbox(NextCommandMailbox, CommandMailbox);
457 if (Controller->V1.PreviousCommandMailbox1->Words[0] == 0 ||
458 Controller->V1.PreviousCommandMailbox2->Words[0] == 0)
459 DAC960_PG_HardwareMailboxNewCommand(ControllerBaseAddress);
460 Controller->V1.PreviousCommandMailbox2 =
461 Controller->V1.PreviousCommandMailbox1;
462 Controller->V1.PreviousCommandMailbox1 = NextCommandMailbox;
463 if (++NextCommandMailbox > Controller->V1.LastCommandMailbox)
464 NextCommandMailbox = Controller->V1.FirstCommandMailbox;
465 Controller->V1.NextCommandMailbox = NextCommandMailbox;
466 }
467
468
469 /*
470 DAC960_PD_QueueCommand queues Command for DAC960 PD Series Controllers.
471 */
472
DAC960_PD_QueueCommand(DAC960_Command_T * Command)473 static void DAC960_PD_QueueCommand(DAC960_Command_T *Command)
474 {
475 DAC960_Controller_T *Controller = Command->Controller;
476 void *ControllerBaseAddress = Controller->BaseAddress;
477 DAC960_V1_CommandMailbox_T *CommandMailbox = &Command->V1.CommandMailbox;
478 CommandMailbox->Common.CommandIdentifier = Command->CommandIdentifier;
479 while (DAC960_PD_MailboxFullP(ControllerBaseAddress))
480 udelay(1);
481 DAC960_PD_WriteCommandMailbox(ControllerBaseAddress, CommandMailbox);
482 DAC960_PD_NewCommand(ControllerBaseAddress);
483 }
484
485
486 /*
487 DAC960_P_QueueCommand queues Command for DAC960 P Series Controllers.
488 */
489
DAC960_P_QueueCommand(DAC960_Command_T * Command)490 static void DAC960_P_QueueCommand(DAC960_Command_T *Command)
491 {
492 DAC960_Controller_T *Controller = Command->Controller;
493 void *ControllerBaseAddress = Controller->BaseAddress;
494 DAC960_V1_CommandMailbox_T *CommandMailbox = &Command->V1.CommandMailbox;
495 CommandMailbox->Common.CommandIdentifier = Command->CommandIdentifier;
496 switch (CommandMailbox->Common.CommandOpcode)
497 {
498 case DAC960_V1_Enquiry:
499 CommandMailbox->Common.CommandOpcode = DAC960_V1_Enquiry_Old;
500 break;
501 case DAC960_V1_GetDeviceState:
502 CommandMailbox->Common.CommandOpcode = DAC960_V1_GetDeviceState_Old;
503 break;
504 case DAC960_V1_Read:
505 CommandMailbox->Common.CommandOpcode = DAC960_V1_Read_Old;
506 DAC960_PD_To_P_TranslateReadWriteCommand(CommandMailbox);
507 break;
508 case DAC960_V1_Write:
509 CommandMailbox->Common.CommandOpcode = DAC960_V1_Write_Old;
510 DAC960_PD_To_P_TranslateReadWriteCommand(CommandMailbox);
511 break;
512 case DAC960_V1_ReadWithScatterGather:
513 CommandMailbox->Common.CommandOpcode =
514 DAC960_V1_ReadWithScatterGather_Old;
515 DAC960_PD_To_P_TranslateReadWriteCommand(CommandMailbox);
516 break;
517 case DAC960_V1_WriteWithScatterGather:
518 CommandMailbox->Common.CommandOpcode =
519 DAC960_V1_WriteWithScatterGather_Old;
520 DAC960_PD_To_P_TranslateReadWriteCommand(CommandMailbox);
521 break;
522 default:
523 break;
524 }
525 while (DAC960_PD_MailboxFullP(ControllerBaseAddress))
526 udelay(1);
527 DAC960_PD_WriteCommandMailbox(ControllerBaseAddress, CommandMailbox);
528 DAC960_PD_NewCommand(ControllerBaseAddress);
529 }
530
531
532 /*
533 DAC960_ExecuteCommand executes Command and waits for completion.
534 */
535
DAC960_ExecuteCommand(DAC960_Command_T * Command)536 static void DAC960_ExecuteCommand(DAC960_Command_T *Command)
537 {
538 DAC960_Controller_T *Controller = Command->Controller;
539 DECLARE_COMPLETION(Completion);
540 unsigned long ProcessorFlags;
541 Command->Completion = &Completion;
542 DAC960_AcquireControllerLock(Controller, &ProcessorFlags);
543 DAC960_QueueCommand(Command);
544 DAC960_ReleaseControllerLock(Controller, &ProcessorFlags);
545 if (in_interrupt()) return;
546 wait_for_completion(&Completion);
547 }
548
549
550 /*
551 DAC960_V1_ExecuteType3 executes a DAC960 V1 Firmware Controller Type 3
552 Command and waits for completion. It returns true on success and false
553 on failure.
554 */
555
DAC960_V1_ExecuteType3(DAC960_Controller_T * Controller,DAC960_V1_CommandOpcode_T CommandOpcode,void * DataPointer)556 static boolean DAC960_V1_ExecuteType3(DAC960_Controller_T *Controller,
557 DAC960_V1_CommandOpcode_T CommandOpcode,
558 void *DataPointer)
559 {
560 DAC960_Command_T *Command = DAC960_AllocateCommand(Controller);
561 DAC960_V1_CommandMailbox_T *CommandMailbox = &Command->V1.CommandMailbox;
562 DAC960_V1_CommandStatus_T CommandStatus;
563 DAC960_V1_ClearCommand(Command);
564 Command->CommandType = DAC960_ImmediateCommand;
565 CommandMailbox->Type3.CommandOpcode = CommandOpcode;
566 CommandMailbox->Type3.BusAddress = Virtual_to_Bus32(DataPointer);
567 DAC960_ExecuteCommand(Command);
568 CommandStatus = Command->V1.CommandStatus;
569 DAC960_DeallocateCommand(Command);
570 return (CommandStatus == DAC960_V1_NormalCompletion);
571 }
572
573
574 /*
575 DAC960_V1_ExecuteTypeB executes a DAC960 V1 Firmware Controller Type 3B
576 Command and waits for completion. It returns true on success and false
577 on failure.
578 */
579
DAC960_V1_ExecuteType3B(DAC960_Controller_T * Controller,DAC960_V1_CommandOpcode_T CommandOpcode,unsigned char CommandOpcode2,void * DataPointer)580 static boolean DAC960_V1_ExecuteType3B(DAC960_Controller_T *Controller,
581 DAC960_V1_CommandOpcode_T CommandOpcode,
582 unsigned char CommandOpcode2,
583 void *DataPointer)
584 {
585 DAC960_Command_T *Command = DAC960_AllocateCommand(Controller);
586 DAC960_V1_CommandMailbox_T *CommandMailbox = &Command->V1.CommandMailbox;
587 DAC960_V1_CommandStatus_T CommandStatus;
588 DAC960_V1_ClearCommand(Command);
589 Command->CommandType = DAC960_ImmediateCommand;
590 CommandMailbox->Type3B.CommandOpcode = CommandOpcode;
591 CommandMailbox->Type3B.CommandOpcode2 = CommandOpcode2;
592 CommandMailbox->Type3B.BusAddress = Virtual_to_Bus32(DataPointer);
593 DAC960_ExecuteCommand(Command);
594 CommandStatus = Command->V1.CommandStatus;
595 DAC960_DeallocateCommand(Command);
596 return (CommandStatus == DAC960_V1_NormalCompletion);
597 }
598
599
600 /*
601 DAC960_V1_ExecuteType3D executes a DAC960 V1 Firmware Controller Type 3D
602 Command and waits for completion. It returns true on success and false
603 on failure.
604 */
605
DAC960_V1_ExecuteType3D(DAC960_Controller_T * Controller,DAC960_V1_CommandOpcode_T CommandOpcode,unsigned char Channel,unsigned char TargetID,void * DataPointer)606 static boolean DAC960_V1_ExecuteType3D(DAC960_Controller_T *Controller,
607 DAC960_V1_CommandOpcode_T CommandOpcode,
608 unsigned char Channel,
609 unsigned char TargetID,
610 void *DataPointer)
611 {
612 DAC960_Command_T *Command = DAC960_AllocateCommand(Controller);
613 DAC960_V1_CommandMailbox_T *CommandMailbox = &Command->V1.CommandMailbox;
614 DAC960_V1_CommandStatus_T CommandStatus;
615 DAC960_V1_ClearCommand(Command);
616 Command->CommandType = DAC960_ImmediateCommand;
617 CommandMailbox->Type3D.CommandOpcode = CommandOpcode;
618 CommandMailbox->Type3D.Channel = Channel;
619 CommandMailbox->Type3D.TargetID = TargetID;
620 CommandMailbox->Type3D.BusAddress = Virtual_to_Bus32(DataPointer);
621 DAC960_ExecuteCommand(Command);
622 CommandStatus = Command->V1.CommandStatus;
623 DAC960_DeallocateCommand(Command);
624 return (CommandStatus == DAC960_V1_NormalCompletion);
625 }
626
627
628 /*
629 DAC960_V2_GeneralInfo executes a DAC960 V2 Firmware General Information
630 Reading IOCTL Command and waits for completion. It returns true on success
631 and false on failure.
632 */
633
DAC960_V2_GeneralInfo(DAC960_Controller_T * Controller,DAC960_V2_IOCTL_Opcode_T IOCTL_Opcode,void * DataPointer,unsigned int DataByteCount)634 static boolean DAC960_V2_GeneralInfo(DAC960_Controller_T *Controller,
635 DAC960_V2_IOCTL_Opcode_T IOCTL_Opcode,
636 void *DataPointer,
637 unsigned int DataByteCount)
638 {
639 DAC960_Command_T *Command = DAC960_AllocateCommand(Controller);
640 DAC960_V2_CommandMailbox_T *CommandMailbox = &Command->V2.CommandMailbox;
641 DAC960_V2_CommandStatus_T CommandStatus;
642 DAC960_V2_ClearCommand(Command);
643 Command->CommandType = DAC960_ImmediateCommand;
644 CommandMailbox->Common.CommandOpcode = DAC960_V2_IOCTL;
645 CommandMailbox->Common.CommandControlBits
646 .DataTransferControllerToHost = true;
647 CommandMailbox->Common.CommandControlBits
648 .NoAutoRequestSense = true;
649 CommandMailbox->Common.DataTransferSize = DataByteCount;
650 CommandMailbox->Common.IOCTL_Opcode = IOCTL_Opcode;
651 CommandMailbox->Common.DataTransferMemoryAddress
652 .ScatterGatherSegments[0]
653 .SegmentDataPointer =
654 Virtual_to_Bus64(DataPointer);
655 CommandMailbox->Common.DataTransferMemoryAddress
656 .ScatterGatherSegments[0]
657 .SegmentByteCount =
658 CommandMailbox->Common.DataTransferSize;
659 DAC960_ExecuteCommand(Command);
660 CommandStatus = Command->V2.CommandStatus;
661 DAC960_DeallocateCommand(Command);
662 return (CommandStatus == DAC960_V2_NormalCompletion);
663 }
664
665
666 /*
667 DAC960_V2_ControllerInfo executes a DAC960 V2 Firmware Controller
668 Information Reading IOCTL Command and waits for completion. It returns
669 true on success and false on failure.
670 */
671
DAC960_V2_ControllerInfo(DAC960_Controller_T * Controller,DAC960_V2_IOCTL_Opcode_T IOCTL_Opcode,void * DataPointer,unsigned int DataByteCount)672 static boolean DAC960_V2_ControllerInfo(DAC960_Controller_T *Controller,
673 DAC960_V2_IOCTL_Opcode_T IOCTL_Opcode,
674 void *DataPointer,
675 unsigned int DataByteCount)
676 {
677 DAC960_Command_T *Command = DAC960_AllocateCommand(Controller);
678 DAC960_V2_CommandMailbox_T *CommandMailbox = &Command->V2.CommandMailbox;
679 DAC960_V2_CommandStatus_T CommandStatus;
680 DAC960_V2_ClearCommand(Command);
681 Command->CommandType = DAC960_ImmediateCommand;
682 CommandMailbox->ControllerInfo.CommandOpcode = DAC960_V2_IOCTL;
683 CommandMailbox->ControllerInfo.CommandControlBits
684 .DataTransferControllerToHost = true;
685 CommandMailbox->ControllerInfo.CommandControlBits
686 .NoAutoRequestSense = true;
687 CommandMailbox->ControllerInfo.DataTransferSize = DataByteCount;
688 CommandMailbox->ControllerInfo.ControllerNumber = 0;
689 CommandMailbox->ControllerInfo.IOCTL_Opcode = IOCTL_Opcode;
690 CommandMailbox->ControllerInfo.DataTransferMemoryAddress
691 .ScatterGatherSegments[0]
692 .SegmentDataPointer =
693 Virtual_to_Bus64(DataPointer);
694 CommandMailbox->ControllerInfo.DataTransferMemoryAddress
695 .ScatterGatherSegments[0]
696 .SegmentByteCount =
697 CommandMailbox->ControllerInfo.DataTransferSize;
698 DAC960_ExecuteCommand(Command);
699 CommandStatus = Command->V2.CommandStatus;
700 DAC960_DeallocateCommand(Command);
701 return (CommandStatus == DAC960_V2_NormalCompletion);
702 }
703
704
705 /*
706 DAC960_V2_LogicalDeviceInfo executes a DAC960 V2 Firmware Controller Logical
707 Device Information Reading IOCTL Command and waits for completion. It
708 returns true on success and false on failure.
709 */
710
DAC960_V2_LogicalDeviceInfo(DAC960_Controller_T * Controller,DAC960_V2_IOCTL_Opcode_T IOCTL_Opcode,unsigned short LogicalDeviceNumber,void * DataPointer,unsigned int DataByteCount)711 static boolean DAC960_V2_LogicalDeviceInfo(DAC960_Controller_T *Controller,
712 DAC960_V2_IOCTL_Opcode_T
713 IOCTL_Opcode,
714 unsigned short
715 LogicalDeviceNumber,
716 void *DataPointer,
717 unsigned int DataByteCount)
718 {
719 DAC960_Command_T *Command = DAC960_AllocateCommand(Controller);
720 DAC960_V2_CommandMailbox_T *CommandMailbox = &Command->V2.CommandMailbox;
721 DAC960_V2_CommandStatus_T CommandStatus;
722 DAC960_V2_ClearCommand(Command);
723 Command->CommandType = DAC960_ImmediateCommand;
724 CommandMailbox->LogicalDeviceInfo.CommandOpcode = DAC960_V2_IOCTL;
725 CommandMailbox->LogicalDeviceInfo.CommandControlBits
726 .DataTransferControllerToHost = true;
727 CommandMailbox->LogicalDeviceInfo.CommandControlBits
728 .NoAutoRequestSense = true;
729 CommandMailbox->LogicalDeviceInfo.DataTransferSize = DataByteCount;
730 CommandMailbox->LogicalDeviceInfo.LogicalDevice.LogicalDeviceNumber =
731 LogicalDeviceNumber;
732 CommandMailbox->LogicalDeviceInfo.IOCTL_Opcode = IOCTL_Opcode;
733 CommandMailbox->LogicalDeviceInfo.DataTransferMemoryAddress
734 .ScatterGatherSegments[0]
735 .SegmentDataPointer =
736 Virtual_to_Bus64(DataPointer);
737 CommandMailbox->LogicalDeviceInfo.DataTransferMemoryAddress
738 .ScatterGatherSegments[0]
739 .SegmentByteCount =
740 CommandMailbox->LogicalDeviceInfo.DataTransferSize;
741 DAC960_ExecuteCommand(Command);
742 CommandStatus = Command->V2.CommandStatus;
743 DAC960_DeallocateCommand(Command);
744 return (CommandStatus == DAC960_V2_NormalCompletion);
745 }
746
747
748 /*
749 DAC960_V2_PhysicalDeviceInfo executes a DAC960 V2 Firmware Controller Physical
750 Device Information Reading IOCTL Command and waits for completion. It
751 returns true on success and false on failure.
752 */
753
DAC960_V2_PhysicalDeviceInfo(DAC960_Controller_T * Controller,DAC960_V2_IOCTL_Opcode_T IOCTL_Opcode,unsigned char Channel,unsigned char TargetID,unsigned char LogicalUnit,void * DataPointer,unsigned int DataByteCount)754 static boolean DAC960_V2_PhysicalDeviceInfo(DAC960_Controller_T *Controller,
755 DAC960_V2_IOCTL_Opcode_T
756 IOCTL_Opcode,
757 unsigned char Channel,
758 unsigned char TargetID,
759 unsigned char LogicalUnit,
760 void *DataPointer,
761 unsigned int DataByteCount)
762 {
763 DAC960_Command_T *Command = DAC960_AllocateCommand(Controller);
764 DAC960_V2_CommandMailbox_T *CommandMailbox = &Command->V2.CommandMailbox;
765 DAC960_V2_CommandStatus_T CommandStatus;
766 DAC960_V2_ClearCommand(Command);
767 Command->CommandType = DAC960_ImmediateCommand;
768 CommandMailbox->PhysicalDeviceInfo.CommandOpcode = DAC960_V2_IOCTL;
769 CommandMailbox->PhysicalDeviceInfo.CommandControlBits
770 .DataTransferControllerToHost = true;
771 CommandMailbox->PhysicalDeviceInfo.CommandControlBits
772 .NoAutoRequestSense = true;
773 CommandMailbox->PhysicalDeviceInfo.DataTransferSize = DataByteCount;
774 CommandMailbox->PhysicalDeviceInfo.PhysicalDevice.LogicalUnit = LogicalUnit;
775 CommandMailbox->PhysicalDeviceInfo.PhysicalDevice.TargetID = TargetID;
776 CommandMailbox->PhysicalDeviceInfo.PhysicalDevice.Channel = Channel;
777 CommandMailbox->PhysicalDeviceInfo.IOCTL_Opcode = IOCTL_Opcode;
778 CommandMailbox->PhysicalDeviceInfo.DataTransferMemoryAddress
779 .ScatterGatherSegments[0]
780 .SegmentDataPointer =
781 Virtual_to_Bus64(DataPointer);
782 CommandMailbox->PhysicalDeviceInfo.DataTransferMemoryAddress
783 .ScatterGatherSegments[0]
784 .SegmentByteCount =
785 CommandMailbox->PhysicalDeviceInfo.DataTransferSize;
786 DAC960_ExecuteCommand(Command);
787 CommandStatus = Command->V2.CommandStatus;
788 DAC960_DeallocateCommand(Command);
789 return (CommandStatus == DAC960_V2_NormalCompletion);
790 }
791
792
793 /*
794 DAC960_V2_DeviceOperation executes a DAC960 V2 Firmware Controller Device
795 Operation IOCTL Command and waits for completion. It returns true on
796 success and false on failure.
797 */
798
DAC960_V2_DeviceOperation(DAC960_Controller_T * Controller,DAC960_V2_IOCTL_Opcode_T IOCTL_Opcode,DAC960_V2_OperationDevice_T OperationDevice)799 static boolean DAC960_V2_DeviceOperation(DAC960_Controller_T *Controller,
800 DAC960_V2_IOCTL_Opcode_T IOCTL_Opcode,
801 DAC960_V2_OperationDevice_T
802 OperationDevice)
803 {
804 DAC960_Command_T *Command = DAC960_AllocateCommand(Controller);
805 DAC960_V2_CommandMailbox_T *CommandMailbox = &Command->V2.CommandMailbox;
806 DAC960_V2_CommandStatus_T CommandStatus;
807 DAC960_V2_ClearCommand(Command);
808 Command->CommandType = DAC960_ImmediateCommand;
809 CommandMailbox->DeviceOperation.CommandOpcode = DAC960_V2_IOCTL;
810 CommandMailbox->DeviceOperation.CommandControlBits
811 .DataTransferControllerToHost = true;
812 CommandMailbox->DeviceOperation.CommandControlBits
813 .NoAutoRequestSense = true;
814 CommandMailbox->DeviceOperation.IOCTL_Opcode = IOCTL_Opcode;
815 CommandMailbox->DeviceOperation.OperationDevice = OperationDevice;
816 DAC960_ExecuteCommand(Command);
817 CommandStatus = Command->V2.CommandStatus;
818 DAC960_DeallocateCommand(Command);
819 return (CommandStatus == DAC960_V2_NormalCompletion);
820 }
821
822
823 /*
824 DAC960_V1_EnableMemoryMailboxInterface enables the Memory Mailbox Interface
825 for DAC960 V1 Firmware Controllers.
826 */
827
DAC960_V1_EnableMemoryMailboxInterface(DAC960_Controller_T * Controller)828 static boolean DAC960_V1_EnableMemoryMailboxInterface(DAC960_Controller_T
829 *Controller)
830 {
831 void *ControllerBaseAddress = Controller->BaseAddress;
832 DAC960_V1_CommandMailbox_T *CommandMailboxesMemory;
833 DAC960_V1_StatusMailbox_T *StatusMailboxesMemory;
834 DAC960_V1_CommandMailbox_T CommandMailbox;
835 DAC960_V1_CommandStatus_T CommandStatus;
836 unsigned long MemoryMailboxPagesAddress;
837 unsigned long MemoryMailboxPagesOrder;
838 unsigned long MemoryMailboxPagesSize;
839 void *SavedMemoryMailboxesAddress = NULL;
840 short NextCommandMailboxIndex = 0;
841 short NextStatusMailboxIndex = 0;
842 int TimeoutCounter = 1000000, i;
843 MemoryMailboxPagesOrder = 0;
844 MemoryMailboxPagesSize =
845 DAC960_V1_CommandMailboxCount * sizeof(DAC960_V1_CommandMailbox_T) +
846 DAC960_V1_StatusMailboxCount * sizeof(DAC960_V1_StatusMailbox_T);
847 while (MemoryMailboxPagesSize > PAGE_SIZE << MemoryMailboxPagesOrder)
848 MemoryMailboxPagesOrder++;
849 if (Controller->HardwareType == DAC960_LA_Controller)
850 DAC960_LA_RestoreMemoryMailboxInfo(Controller,
851 &SavedMemoryMailboxesAddress,
852 &NextCommandMailboxIndex,
853 &NextStatusMailboxIndex);
854 else DAC960_PG_RestoreMemoryMailboxInfo(Controller,
855 &SavedMemoryMailboxesAddress,
856 &NextCommandMailboxIndex,
857 &NextStatusMailboxIndex);
858 if (SavedMemoryMailboxesAddress == NULL)
859 {
860 MemoryMailboxPagesAddress =
861 __get_free_pages(GFP_KERNEL, MemoryMailboxPagesOrder);
862 Controller->MemoryMailboxPagesAddress = MemoryMailboxPagesAddress;
863 CommandMailboxesMemory =
864 (DAC960_V1_CommandMailbox_T *) MemoryMailboxPagesAddress;
865 }
866 else CommandMailboxesMemory = SavedMemoryMailboxesAddress;
867 if (CommandMailboxesMemory == NULL) return false;
868 Controller->MemoryMailboxPagesOrder = MemoryMailboxPagesOrder;
869 memset(CommandMailboxesMemory, 0, MemoryMailboxPagesSize);
870 Controller->V1.FirstCommandMailbox = CommandMailboxesMemory;
871 CommandMailboxesMemory += DAC960_V1_CommandMailboxCount - 1;
872 Controller->V1.LastCommandMailbox = CommandMailboxesMemory;
873 Controller->V1.NextCommandMailbox =
874 &Controller->V1.FirstCommandMailbox[NextCommandMailboxIndex];
875 if (--NextCommandMailboxIndex < 0)
876 NextCommandMailboxIndex = DAC960_V1_CommandMailboxCount - 1;
877 Controller->V1.PreviousCommandMailbox1 =
878 &Controller->V1.FirstCommandMailbox[NextCommandMailboxIndex];
879 if (--NextCommandMailboxIndex < 0)
880 NextCommandMailboxIndex = DAC960_V1_CommandMailboxCount - 1;
881 Controller->V1.PreviousCommandMailbox2 =
882 &Controller->V1.FirstCommandMailbox[NextCommandMailboxIndex];
883 StatusMailboxesMemory =
884 (DAC960_V1_StatusMailbox_T *) (CommandMailboxesMemory + 1);
885 Controller->V1.FirstStatusMailbox = StatusMailboxesMemory;
886 StatusMailboxesMemory += DAC960_V1_StatusMailboxCount - 1;
887 Controller->V1.LastStatusMailbox = StatusMailboxesMemory;
888 Controller->V1.NextStatusMailbox =
889 &Controller->V1.FirstStatusMailbox[NextStatusMailboxIndex];
890 if (SavedMemoryMailboxesAddress != NULL) return true;
891 /* Enable the Memory Mailbox Interface. */
892 Controller->V1.DualModeMemoryMailboxInterface = true;
893 CommandMailbox.TypeX.CommandOpcode = 0x2B;
894 CommandMailbox.TypeX.CommandIdentifier = 0;
895 CommandMailbox.TypeX.CommandOpcode2 = 0x14;
896 CommandMailbox.TypeX.CommandMailboxesBusAddress =
897 Virtual_to_Bus32(Controller->V1.FirstCommandMailbox);
898 CommandMailbox.TypeX.StatusMailboxesBusAddress =
899 Virtual_to_Bus32(Controller->V1.FirstStatusMailbox);
900 for (i = 0; i < 2; i++)
901 switch (Controller->HardwareType)
902 {
903 case DAC960_LA_Controller:
904 while (--TimeoutCounter >= 0)
905 {
906 if (!DAC960_LA_HardwareMailboxFullP(ControllerBaseAddress))
907 break;
908 udelay(10);
909 }
910 if (TimeoutCounter < 0) return false;
911 DAC960_LA_WriteHardwareMailbox(ControllerBaseAddress, &CommandMailbox);
912 DAC960_LA_HardwareMailboxNewCommand(ControllerBaseAddress);
913 while (--TimeoutCounter >= 0)
914 {
915 if (DAC960_LA_HardwareMailboxStatusAvailableP(
916 ControllerBaseAddress))
917 break;
918 udelay(10);
919 }
920 if (TimeoutCounter < 0) return false;
921 CommandStatus = DAC960_LA_ReadStatusRegister(ControllerBaseAddress);
922 DAC960_LA_AcknowledgeHardwareMailboxInterrupt(ControllerBaseAddress);
923 DAC960_LA_AcknowledgeHardwareMailboxStatus(ControllerBaseAddress);
924 if (CommandStatus == DAC960_V1_NormalCompletion) return true;
925 Controller->V1.DualModeMemoryMailboxInterface = false;
926 CommandMailbox.TypeX.CommandOpcode2 = 0x10;
927 break;
928 case DAC960_PG_Controller:
929 while (--TimeoutCounter >= 0)
930 {
931 if (!DAC960_PG_HardwareMailboxFullP(ControllerBaseAddress))
932 break;
933 udelay(10);
934 }
935 if (TimeoutCounter < 0) return false;
936 DAC960_PG_WriteHardwareMailbox(ControllerBaseAddress, &CommandMailbox);
937 DAC960_PG_HardwareMailboxNewCommand(ControllerBaseAddress);
938 while (--TimeoutCounter >= 0)
939 {
940 if (DAC960_PG_HardwareMailboxStatusAvailableP(
941 ControllerBaseAddress))
942 break;
943 udelay(10);
944 }
945 if (TimeoutCounter < 0) return false;
946 CommandStatus = DAC960_PG_ReadStatusRegister(ControllerBaseAddress);
947 DAC960_PG_AcknowledgeHardwareMailboxInterrupt(ControllerBaseAddress);
948 DAC960_PG_AcknowledgeHardwareMailboxStatus(ControllerBaseAddress);
949 if (CommandStatus == DAC960_V1_NormalCompletion) return true;
950 Controller->V1.DualModeMemoryMailboxInterface = false;
951 CommandMailbox.TypeX.CommandOpcode2 = 0x10;
952 break;
953 default:
954 break;
955 }
956 return false;
957 }
958
959
960 /*
961 DAC960_V2_EnableMemoryMailboxInterface enables the Memory Mailbox Interface
962 for DAC960 V2 Firmware Controllers.
963 */
964
DAC960_V2_EnableMemoryMailboxInterface(DAC960_Controller_T * Controller)965 static boolean DAC960_V2_EnableMemoryMailboxInterface(DAC960_Controller_T
966 *Controller)
967 {
968 void *ControllerBaseAddress = Controller->BaseAddress;
969 DAC960_V2_CommandMailbox_T *CommandMailboxesMemory;
970 DAC960_V2_StatusMailbox_T *StatusMailboxesMemory;
971 DAC960_V2_CommandMailbox_T CommandMailbox;
972 DAC960_V2_CommandStatus_T CommandStatus = 0;
973 unsigned long MemoryMailboxPagesAddress;
974 unsigned long MemoryMailboxPagesOrder;
975 unsigned long MemoryMailboxPagesSize;
976 MemoryMailboxPagesOrder = 0;
977 MemoryMailboxPagesSize =
978 DAC960_V2_CommandMailboxCount * sizeof(DAC960_V2_CommandMailbox_T) +
979 DAC960_V2_StatusMailboxCount * sizeof(DAC960_V2_StatusMailbox_T) +
980 sizeof(DAC960_V2_HealthStatusBuffer_T);
981 while (MemoryMailboxPagesSize > PAGE_SIZE << MemoryMailboxPagesOrder)
982 MemoryMailboxPagesOrder++;
983 MemoryMailboxPagesAddress =
984 __get_free_pages(GFP_KERNEL, MemoryMailboxPagesOrder);
985 Controller->MemoryMailboxPagesAddress = MemoryMailboxPagesAddress;
986 CommandMailboxesMemory =
987 (DAC960_V2_CommandMailbox_T *) MemoryMailboxPagesAddress;
988 if (CommandMailboxesMemory == NULL) return false;
989 Controller->MemoryMailboxPagesOrder = MemoryMailboxPagesOrder;
990 memset(CommandMailboxesMemory, 0, MemoryMailboxPagesSize);
991 Controller->V2.FirstCommandMailbox = CommandMailboxesMemory;
992 CommandMailboxesMemory += DAC960_V2_CommandMailboxCount - 1;
993 Controller->V2.LastCommandMailbox = CommandMailboxesMemory;
994 Controller->V2.NextCommandMailbox = Controller->V2.FirstCommandMailbox;
995 Controller->V2.PreviousCommandMailbox1 = Controller->V2.LastCommandMailbox;
996 Controller->V2.PreviousCommandMailbox2 =
997 Controller->V2.LastCommandMailbox - 1;
998 StatusMailboxesMemory =
999 (DAC960_V2_StatusMailbox_T *) (CommandMailboxesMemory + 1);
1000 Controller->V2.FirstStatusMailbox = StatusMailboxesMemory;
1001 StatusMailboxesMemory += DAC960_V2_StatusMailboxCount - 1;
1002 Controller->V2.LastStatusMailbox = StatusMailboxesMemory;
1003 Controller->V2.NextStatusMailbox = Controller->V2.FirstStatusMailbox;
1004 Controller->V2.HealthStatusBuffer =
1005 (DAC960_V2_HealthStatusBuffer_T *) (StatusMailboxesMemory + 1);
1006 /* Enable the Memory Mailbox Interface. */
1007 memset(&CommandMailbox, 0, sizeof(DAC960_V2_CommandMailbox_T));
1008 CommandMailbox.SetMemoryMailbox.CommandIdentifier = 1;
1009 CommandMailbox.SetMemoryMailbox.CommandOpcode = DAC960_V2_IOCTL;
1010 CommandMailbox.SetMemoryMailbox.CommandControlBits.NoAutoRequestSense = true;
1011 CommandMailbox.SetMemoryMailbox.FirstCommandMailboxSizeKB =
1012 (DAC960_V2_CommandMailboxCount * sizeof(DAC960_V2_CommandMailbox_T)) >> 10;
1013 CommandMailbox.SetMemoryMailbox.FirstStatusMailboxSizeKB =
1014 (DAC960_V2_StatusMailboxCount * sizeof(DAC960_V2_StatusMailbox_T)) >> 10;
1015 CommandMailbox.SetMemoryMailbox.SecondCommandMailboxSizeKB = 0;
1016 CommandMailbox.SetMemoryMailbox.SecondStatusMailboxSizeKB = 0;
1017 CommandMailbox.SetMemoryMailbox.RequestSenseSize = 0;
1018 CommandMailbox.SetMemoryMailbox.IOCTL_Opcode = DAC960_V2_SetMemoryMailbox;
1019 CommandMailbox.SetMemoryMailbox.HealthStatusBufferSizeKB = 1;
1020 CommandMailbox.SetMemoryMailbox.HealthStatusBufferBusAddress =
1021 Virtual_to_Bus64(Controller->V2.HealthStatusBuffer);
1022 CommandMailbox.SetMemoryMailbox.FirstCommandMailboxBusAddress =
1023 Virtual_to_Bus64(Controller->V2.FirstCommandMailbox);
1024 CommandMailbox.SetMemoryMailbox.FirstStatusMailboxBusAddress =
1025 Virtual_to_Bus64(Controller->V2.FirstStatusMailbox);
1026 switch (Controller->HardwareType)
1027 {
1028 case DAC960_BA_Controller:
1029 while (DAC960_BA_HardwareMailboxFullP(ControllerBaseAddress))
1030 udelay(1);
1031 DAC960_BA_WriteHardwareMailbox(ControllerBaseAddress, &CommandMailbox);
1032 DAC960_BA_HardwareMailboxNewCommand(ControllerBaseAddress);
1033 while (!DAC960_BA_HardwareMailboxStatusAvailableP(ControllerBaseAddress))
1034 udelay(1);
1035 CommandStatus = DAC960_BA_ReadCommandStatus(ControllerBaseAddress);
1036 DAC960_BA_AcknowledgeHardwareMailboxInterrupt(ControllerBaseAddress);
1037 DAC960_BA_AcknowledgeHardwareMailboxStatus(ControllerBaseAddress);
1038 break;
1039 case DAC960_LP_Controller:
1040 while (DAC960_LP_HardwareMailboxFullP(ControllerBaseAddress))
1041 udelay(1);
1042 DAC960_LP_WriteHardwareMailbox(ControllerBaseAddress, &CommandMailbox);
1043 DAC960_LP_HardwareMailboxNewCommand(ControllerBaseAddress);
1044 while (!DAC960_LP_HardwareMailboxStatusAvailableP(ControllerBaseAddress))
1045 udelay(1);
1046 CommandStatus = DAC960_LP_ReadCommandStatus(ControllerBaseAddress);
1047 DAC960_LP_AcknowledgeHardwareMailboxInterrupt(ControllerBaseAddress);
1048 DAC960_LP_AcknowledgeHardwareMailboxStatus(ControllerBaseAddress);
1049 break;
1050 default:
1051 break;
1052 }
1053 return (CommandStatus == DAC960_V2_NormalCompletion);
1054 }
1055
1056
1057 /*
1058 DAC960_V1_ReadControllerConfiguration reads the Configuration Information
1059 from DAC960 V1 Firmware Controllers and initializes the Controller structure.
1060 */
1061
DAC960_V1_ReadControllerConfiguration(DAC960_Controller_T * Controller)1062 static boolean DAC960_V1_ReadControllerConfiguration(DAC960_Controller_T
1063 *Controller)
1064 {
1065 DAC960_V1_Enquiry2_T Enquiry2;
1066 DAC960_V1_Config2_T Config2;
1067 int LogicalDriveNumber, Channel, TargetID;
1068 if (!DAC960_V1_ExecuteType3(Controller, DAC960_V1_Enquiry,
1069 &Controller->V1.Enquiry))
1070 return DAC960_Failure(Controller, "ENQUIRY");
1071 if (!DAC960_V1_ExecuteType3(Controller, DAC960_V1_Enquiry2, &Enquiry2))
1072 return DAC960_Failure(Controller, "ENQUIRY2");
1073 if (!DAC960_V1_ExecuteType3(Controller, DAC960_V1_ReadConfig2, &Config2))
1074 return DAC960_Failure(Controller, "READ CONFIG2");
1075 if (!DAC960_V1_ExecuteType3(Controller, DAC960_V1_GetLogicalDriveInformation,
1076 &Controller->V1.LogicalDriveInformation))
1077 return DAC960_Failure(Controller, "GET LOGICAL DRIVE INFORMATION");
1078 for (Channel = 0; Channel < Enquiry2.ActualChannels; Channel++)
1079 for (TargetID = 0; TargetID < Enquiry2.MaxTargets; TargetID++)
1080 if (!DAC960_V1_ExecuteType3D(Controller, DAC960_V1_GetDeviceState,
1081 Channel, TargetID,
1082 &Controller->V1.DeviceState
1083 [Channel][TargetID]))
1084 return DAC960_Failure(Controller, "GET DEVICE STATE");
1085 /*
1086 Initialize the Controller Model Name and Full Model Name fields.
1087 */
1088 switch (Enquiry2.HardwareID.SubModel)
1089 {
1090 case DAC960_V1_P_PD_PU:
1091 if (Enquiry2.SCSICapability.BusSpeed == DAC960_V1_Ultra)
1092 strcpy(Controller->ModelName, "DAC960PU");
1093 else strcpy(Controller->ModelName, "DAC960PD");
1094 break;
1095 case DAC960_V1_PL:
1096 strcpy(Controller->ModelName, "DAC960PL");
1097 break;
1098 case DAC960_V1_PG:
1099 strcpy(Controller->ModelName, "DAC960PG");
1100 break;
1101 case DAC960_V1_PJ:
1102 strcpy(Controller->ModelName, "DAC960PJ");
1103 break;
1104 case DAC960_V1_PR:
1105 strcpy(Controller->ModelName, "DAC960PR");
1106 break;
1107 case DAC960_V1_PT:
1108 strcpy(Controller->ModelName, "DAC960PT");
1109 break;
1110 case DAC960_V1_PTL0:
1111 strcpy(Controller->ModelName, "DAC960PTL0");
1112 break;
1113 case DAC960_V1_PRL:
1114 strcpy(Controller->ModelName, "DAC960PRL");
1115 break;
1116 case DAC960_V1_PTL1:
1117 strcpy(Controller->ModelName, "DAC960PTL1");
1118 break;
1119 case DAC960_V1_1164P:
1120 strcpy(Controller->ModelName, "DAC1164P");
1121 break;
1122 default:
1123 return DAC960_Failure(Controller, "MODEL VERIFICATION");
1124 }
1125 strcpy(Controller->FullModelName, "Mylex ");
1126 strcat(Controller->FullModelName, Controller->ModelName);
1127 /*
1128 Initialize the Controller Firmware Version field and verify that it
1129 is a supported firmware version. The supported firmware versions are:
1130
1131 DAC1164P 5.06 and above
1132 DAC960PTL/PRL/PJ/PG 4.06 and above
1133 DAC960PU/PD/PL 3.51 and above
1134 DAC960PU/PD/PL/P 2.73 and above
1135 */
1136 #if defined(__alpha__)
1137 /*
1138 DEC Alpha machines were often equipped with DAC960 cards that were
1139 OEMed from Mylex, and had their own custom firmware. Version 2.70,
1140 the last custom FW revision to be released by DEC for these older
1141 controllers, appears to work quite well with this driver.
1142
1143 Cards tested successfully were several versions each of the PD and
1144 PU, called by DEC the KZPSC and KZPAC, respectively, and having
1145 the Manufacturer Numbers (from Mylex), usually on a sticker on the
1146 back of the board, of:
1147
1148 KZPSC D040347 (1ch) or D040348 (2ch) or D040349 (3ch)
1149 KZPAC D040395 (1ch) or D040396 (2ch) or D040397 (3ch)
1150 */
1151 # define FIRMWARE_27x "2.70"
1152 #else
1153 # define FIRMWARE_27x "2.73"
1154 #endif
1155
1156 if (Enquiry2.FirmwareID.MajorVersion == 0)
1157 {
1158 Enquiry2.FirmwareID.MajorVersion =
1159 Controller->V1.Enquiry.MajorFirmwareVersion;
1160 Enquiry2.FirmwareID.MinorVersion =
1161 Controller->V1.Enquiry.MinorFirmwareVersion;
1162 Enquiry2.FirmwareID.FirmwareType = '0';
1163 Enquiry2.FirmwareID.TurnID = 0;
1164 }
1165 sprintf(Controller->FirmwareVersion, "%d.%02d-%c-%02d",
1166 Enquiry2.FirmwareID.MajorVersion, Enquiry2.FirmwareID.MinorVersion,
1167 Enquiry2.FirmwareID.FirmwareType, Enquiry2.FirmwareID.TurnID);
1168 if (!((Controller->FirmwareVersion[0] == '5' &&
1169 strcmp(Controller->FirmwareVersion, "5.06") >= 0) ||
1170 (Controller->FirmwareVersion[0] == '4' &&
1171 strcmp(Controller->FirmwareVersion, "4.06") >= 0) ||
1172 (Controller->FirmwareVersion[0] == '3' &&
1173 strcmp(Controller->FirmwareVersion, "3.51") >= 0) ||
1174 (Controller->FirmwareVersion[0] == '2' &&
1175 strcmp(Controller->FirmwareVersion, FIRMWARE_27x) >= 0)))
1176 {
1177 DAC960_Failure(Controller, "FIRMWARE VERSION VERIFICATION");
1178 DAC960_Error("Firmware Version = '%s'\n", Controller,
1179 Controller->FirmwareVersion);
1180 return false;
1181 }
1182 /*
1183 Initialize the Controller Channels, Targets, Memory Size, and SAF-TE
1184 Enclosure Management Enabled fields.
1185 */
1186 Controller->Channels = Enquiry2.ActualChannels;
1187 Controller->Targets = Enquiry2.MaxTargets;
1188 Controller->MemorySize = Enquiry2.MemorySize >> 20;
1189 Controller->V1.SAFTE_EnclosureManagementEnabled =
1190 (Enquiry2.FaultManagementType == DAC960_V1_SAFTE);
1191 /*
1192 Initialize the Controller Queue Depth, Driver Queue Depth, Logical Drive
1193 Count, Maximum Blocks per Command, Controller Scatter/Gather Limit, and
1194 Driver Scatter/Gather Limit. The Driver Queue Depth must be at most one
1195 less than the Controller Queue Depth to allow for an automatic drive
1196 rebuild operation.
1197 */
1198 Controller->ControllerQueueDepth = Controller->V1.Enquiry.MaxCommands;
1199 Controller->DriverQueueDepth = Controller->ControllerQueueDepth - 1;
1200 if (Controller->DriverQueueDepth > DAC960_MaxDriverQueueDepth)
1201 Controller->DriverQueueDepth = DAC960_MaxDriverQueueDepth;
1202 Controller->LogicalDriveCount =
1203 Controller->V1.Enquiry.NumberOfLogicalDrives;
1204 Controller->MaxBlocksPerCommand = Enquiry2.MaxBlocksPerCommand;
1205 Controller->ControllerScatterGatherLimit = Enquiry2.MaxScatterGatherEntries;
1206 Controller->DriverScatterGatherLimit =
1207 Controller->ControllerScatterGatherLimit;
1208 if (Controller->DriverScatterGatherLimit > DAC960_V1_ScatterGatherLimit)
1209 Controller->DriverScatterGatherLimit = DAC960_V1_ScatterGatherLimit;
1210 /*
1211 Initialize the Stripe Size, Segment Size, and Geometry Translation.
1212 */
1213 Controller->V1.StripeSize = Config2.BlocksPerStripe * Config2.BlockFactor
1214 >> (10 - DAC960_BlockSizeBits);
1215 Controller->V1.SegmentSize = Config2.BlocksPerCacheLine * Config2.BlockFactor
1216 >> (10 - DAC960_BlockSizeBits);
1217 switch (Config2.DriveGeometry)
1218 {
1219 case DAC960_V1_Geometry_128_32:
1220 Controller->V1.GeometryTranslationHeads = 128;
1221 Controller->V1.GeometryTranslationSectors = 32;
1222 break;
1223 case DAC960_V1_Geometry_255_63:
1224 Controller->V1.GeometryTranslationHeads = 255;
1225 Controller->V1.GeometryTranslationSectors = 63;
1226 break;
1227 default:
1228 return DAC960_Failure(Controller, "CONFIG2 DRIVE GEOMETRY");
1229 }
1230 /*
1231 Initialize the Background Initialization Status.
1232 */
1233 if ((Controller->FirmwareVersion[0] == '4' &&
1234 strcmp(Controller->FirmwareVersion, "4.08") >= 0) ||
1235 (Controller->FirmwareVersion[0] == '5' &&
1236 strcmp(Controller->FirmwareVersion, "5.08") >= 0))
1237 {
1238 Controller->V1.BackgroundInitializationStatusSupported = true;
1239 DAC960_V1_ExecuteType3B(Controller,
1240 DAC960_V1_BackgroundInitializationControl, 0x20,
1241 &Controller->
1242 V1.LastBackgroundInitializationStatus);
1243 }
1244 /*
1245 Initialize the Logical Drive Initially Accessible flag.
1246 */
1247 for (LogicalDriveNumber = 0;
1248 LogicalDriveNumber < Controller->LogicalDriveCount;
1249 LogicalDriveNumber++)
1250 if (Controller->V1.LogicalDriveInformation
1251 [LogicalDriveNumber].LogicalDriveState !=
1252 DAC960_V1_LogicalDrive_Offline)
1253 Controller->LogicalDriveInitiallyAccessible[LogicalDriveNumber] = true;
1254 Controller->V1.LastRebuildStatus = DAC960_V1_NoRebuildOrCheckInProgress;
1255 return true;
1256 }
1257
1258
1259 /*
1260 DAC960_V2_ReadControllerConfiguration reads the Configuration Information
1261 from DAC960 V2 Firmware Controllers and initializes the Controller structure.
1262 */
1263
DAC960_V2_ReadControllerConfiguration(DAC960_Controller_T * Controller)1264 static boolean DAC960_V2_ReadControllerConfiguration(DAC960_Controller_T
1265 *Controller)
1266 {
1267 DAC960_V2_ControllerInfo_T *ControllerInfo =
1268 &Controller->V2.ControllerInformation;
1269 unsigned short LogicalDeviceNumber = 0;
1270 int ModelNameLength;
1271 if (!DAC960_V2_ControllerInfo(Controller, DAC960_V2_GetControllerInfo,
1272 ControllerInfo,
1273 sizeof(DAC960_V2_ControllerInfo_T)))
1274 return DAC960_Failure(Controller, "GET CONTROLLER INFO");
1275 if (!DAC960_V2_GeneralInfo(Controller, DAC960_V2_GetHealthStatus,
1276 Controller->V2.HealthStatusBuffer,
1277 sizeof(DAC960_V2_HealthStatusBuffer_T)))
1278 return DAC960_Failure(Controller, "GET HEALTH STATUS");
1279 /*
1280 Initialize the Controller Model Name and Full Model Name fields.
1281 */
1282 ModelNameLength = sizeof(ControllerInfo->ControllerName);
1283 if (ModelNameLength > sizeof(Controller->ModelName)-1)
1284 ModelNameLength = sizeof(Controller->ModelName)-1;
1285 memcpy(Controller->ModelName, ControllerInfo->ControllerName,
1286 ModelNameLength);
1287 ModelNameLength--;
1288 while (Controller->ModelName[ModelNameLength] == ' ' ||
1289 Controller->ModelName[ModelNameLength] == '\0')
1290 ModelNameLength--;
1291 Controller->ModelName[++ModelNameLength] = '\0';
1292 strcpy(Controller->FullModelName, "Mylex ");
1293 strcat(Controller->FullModelName, Controller->ModelName);
1294 /*
1295 Initialize the Controller Firmware Version field.
1296 */
1297 sprintf(Controller->FirmwareVersion, "%d.%02d-%02d",
1298 ControllerInfo->FirmwareMajorVersion,
1299 ControllerInfo->FirmwareMinorVersion,
1300 ControllerInfo->FirmwareTurnNumber);
1301 if (ControllerInfo->FirmwareMajorVersion == 6 &&
1302 ControllerInfo->FirmwareMinorVersion == 0 &&
1303 ControllerInfo->FirmwareTurnNumber < 1)
1304 {
1305 DAC960_Info("FIRMWARE VERSION %s DOES NOT PROVIDE THE CONTROLLER\n",
1306 Controller, Controller->FirmwareVersion);
1307 DAC960_Info("STATUS MONITORING FUNCTIONALITY NEEDED BY THIS DRIVER.\n",
1308 Controller);
1309 DAC960_Info("PLEASE UPGRADE TO VERSION 6.00-01 OR ABOVE.\n",
1310 Controller);
1311 }
1312 /*
1313 Initialize the Controller Channels, Targets, and Memory Size.
1314 */
1315 Controller->Channels = ControllerInfo->NumberOfPhysicalChannelsPresent;
1316 Controller->Targets =
1317 ControllerInfo->MaximumTargetsPerChannel
1318 [ControllerInfo->NumberOfPhysicalChannelsPresent-1];
1319 Controller->MemorySize = ControllerInfo->MemorySizeMB;
1320 /*
1321 Initialize the Controller Queue Depth, Driver Queue Depth, Logical Drive
1322 Count, Maximum Blocks per Command, Controller Scatter/Gather Limit, and
1323 Driver Scatter/Gather Limit. The Driver Queue Depth must be at most one
1324 less than the Controller Queue Depth to allow for an automatic drive
1325 rebuild operation.
1326 */
1327 Controller->ControllerQueueDepth = ControllerInfo->MaximumParallelCommands;
1328 Controller->DriverQueueDepth = Controller->ControllerQueueDepth - 1;
1329 if (Controller->DriverQueueDepth > DAC960_MaxDriverQueueDepth)
1330 Controller->DriverQueueDepth = DAC960_MaxDriverQueueDepth;
1331 Controller->LogicalDriveCount = ControllerInfo->LogicalDevicesPresent;
1332 Controller->MaxBlocksPerCommand =
1333 ControllerInfo->MaximumDataTransferSizeInBlocks;
1334 Controller->ControllerScatterGatherLimit =
1335 ControllerInfo->MaximumScatterGatherEntries;
1336 Controller->DriverScatterGatherLimit =
1337 Controller->ControllerScatterGatherLimit;
1338 if (Controller->DriverScatterGatherLimit > DAC960_V2_ScatterGatherLimit)
1339 Controller->DriverScatterGatherLimit = DAC960_V2_ScatterGatherLimit;
1340 /*
1341 Initialize the Logical Device Information.
1342 */
1343 while (true)
1344 {
1345 DAC960_V2_LogicalDeviceInfo_T *NewLogicalDeviceInfo =
1346 &Controller->V2.NewLogicalDeviceInformation;
1347 DAC960_V2_LogicalDeviceInfo_T *LogicalDeviceInfo;
1348 DAC960_V2_PhysicalDevice_T PhysicalDevice;
1349 if (!DAC960_V2_LogicalDeviceInfo(Controller,
1350 DAC960_V2_GetLogicalDeviceInfoValid,
1351 LogicalDeviceNumber,
1352 NewLogicalDeviceInfo,
1353 sizeof(DAC960_V2_LogicalDeviceInfo_T)))
1354 break;
1355 LogicalDeviceNumber = NewLogicalDeviceInfo->LogicalDeviceNumber;
1356 if (LogicalDeviceNumber > DAC960_MaxLogicalDrives)
1357 panic("DAC960: Logical Drive Number %d not supported\n",
1358 LogicalDeviceNumber);
1359 if (NewLogicalDeviceInfo->DeviceBlockSizeInBytes != DAC960_BlockSize)
1360 panic("DAC960: Logical Drive Block Size %d not supported\n",
1361 NewLogicalDeviceInfo->DeviceBlockSizeInBytes);
1362 PhysicalDevice.Controller = 0;
1363 PhysicalDevice.Channel = NewLogicalDeviceInfo->Channel;
1364 PhysicalDevice.TargetID = NewLogicalDeviceInfo->TargetID;
1365 PhysicalDevice.LogicalUnit = NewLogicalDeviceInfo->LogicalUnit;
1366 Controller->V2.LogicalDriveToVirtualDevice[LogicalDeviceNumber] =
1367 PhysicalDevice;
1368 if (NewLogicalDeviceInfo->LogicalDeviceState !=
1369 DAC960_V2_LogicalDevice_Offline)
1370 Controller->LogicalDriveInitiallyAccessible[LogicalDeviceNumber] = true;
1371 LogicalDeviceInfo = (DAC960_V2_LogicalDeviceInfo_T *)
1372 kmalloc(sizeof(DAC960_V2_LogicalDeviceInfo_T), GFP_ATOMIC);
1373 if (LogicalDeviceInfo == NULL)
1374 return DAC960_Failure(Controller, "LOGICAL DEVICE ALLOCATION");
1375 Controller->V2.LogicalDeviceInformation[LogicalDeviceNumber] =
1376 LogicalDeviceInfo;
1377 memcpy(LogicalDeviceInfo, NewLogicalDeviceInfo,
1378 sizeof(DAC960_V2_LogicalDeviceInfo_T));
1379 LogicalDeviceNumber++;
1380 }
1381 return true;
1382 }
1383
1384
1385 /*
1386 DAC960_ReportControllerConfiguration reports the Configuration Information
1387 for Controller.
1388 */
1389
DAC960_ReportControllerConfiguration(DAC960_Controller_T * Controller)1390 static boolean DAC960_ReportControllerConfiguration(DAC960_Controller_T
1391 *Controller)
1392 {
1393 DAC960_Info("Configuring Mylex %s PCI RAID Controller\n",
1394 Controller, Controller->ModelName);
1395 DAC960_Info(" Firmware Version: %s, Channels: %d, Memory Size: %dMB\n",
1396 Controller, Controller->FirmwareVersion,
1397 Controller->Channels, Controller->MemorySize);
1398 DAC960_Info(" PCI Bus: %d, Device: %d, Function: %d, I/O Address: ",
1399 Controller, Controller->Bus,
1400 Controller->Device, Controller->Function);
1401 if (Controller->IO_Address == 0)
1402 DAC960_Info("Unassigned\n", Controller);
1403 else DAC960_Info("0x%X\n", Controller, Controller->IO_Address);
1404 DAC960_Info(" PCI Address: 0x%X mapped at 0x%lX, IRQ Channel: %d\n",
1405 Controller, Controller->PCI_Address,
1406 (unsigned long) Controller->BaseAddress,
1407 Controller->IRQ_Channel);
1408 DAC960_Info(" Controller Queue Depth: %d, "
1409 "Maximum Blocks per Command: %d\n",
1410 Controller, Controller->ControllerQueueDepth,
1411 Controller->MaxBlocksPerCommand);
1412 DAC960_Info(" Driver Queue Depth: %d, "
1413 "Scatter/Gather Limit: %d of %d Segments\n",
1414 Controller, Controller->DriverQueueDepth,
1415 Controller->DriverScatterGatherLimit,
1416 Controller->ControllerScatterGatherLimit);
1417 if (Controller->FirmwareType == DAC960_V1_Controller)
1418 {
1419 DAC960_Info(" Stripe Size: %dKB, Segment Size: %dKB, "
1420 "BIOS Geometry: %d/%d\n", Controller,
1421 Controller->V1.StripeSize,
1422 Controller->V1.SegmentSize,
1423 Controller->V1.GeometryTranslationHeads,
1424 Controller->V1.GeometryTranslationSectors);
1425 if (Controller->V1.SAFTE_EnclosureManagementEnabled)
1426 DAC960_Info(" SAF-TE Enclosure Management Enabled\n", Controller);
1427 }
1428 return true;
1429 }
1430
1431
1432 /*
1433 DAC960_V1_ReadDeviceConfiguration reads the Device Configuration Information
1434 for DAC960 V1 Firmware Controllers by requesting the SCSI Inquiry and SCSI
1435 Inquiry Unit Serial Number information for each device connected to
1436 Controller.
1437 */
1438
DAC960_V1_ReadDeviceConfiguration(DAC960_Controller_T * Controller)1439 static boolean DAC960_V1_ReadDeviceConfiguration(DAC960_Controller_T
1440 *Controller)
1441 {
1442 DAC960_V1_DCDB_T DCDBs[DAC960_V1_MaxChannels], *DCDB;
1443 Completion_T Completions[DAC960_V1_MaxChannels], *Completion;
1444 unsigned long ProcessorFlags;
1445 int Channel, TargetID;
1446 for (TargetID = 0; TargetID < Controller->Targets; TargetID++)
1447 {
1448 for (Channel = 0; Channel < Controller->Channels; Channel++)
1449 {
1450 DAC960_Command_T *Command = Controller->Commands[Channel];
1451 DAC960_SCSI_Inquiry_T *InquiryStandardData =
1452 &Controller->V1.InquiryStandardData[Channel][TargetID];
1453 InquiryStandardData->PeripheralDeviceType = 0x1F;
1454 Completion = &Completions[Channel];
1455 init_completion(Completion);
1456 DCDB = &DCDBs[Channel];
1457 DAC960_V1_ClearCommand(Command);
1458 Command->CommandType = DAC960_ImmediateCommand;
1459 Command->Completion = Completion;
1460 Command->V1.CommandMailbox.Type3.CommandOpcode = DAC960_V1_DCDB;
1461 Command->V1.CommandMailbox.Type3.BusAddress = Virtual_to_Bus32(DCDB);
1462 DCDB->Channel = Channel;
1463 DCDB->TargetID = TargetID;
1464 DCDB->Direction = DAC960_V1_DCDB_DataTransferDeviceToSystem;
1465 DCDB->EarlyStatus = false;
1466 DCDB->Timeout = DAC960_V1_DCDB_Timeout_10_seconds;
1467 DCDB->NoAutomaticRequestSense = false;
1468 DCDB->DisconnectPermitted = true;
1469 DCDB->TransferLength = sizeof(DAC960_SCSI_Inquiry_T);
1470 DCDB->BusAddress = Virtual_to_Bus32(InquiryStandardData);
1471 DCDB->CDBLength = 6;
1472 DCDB->TransferLengthHigh4 = 0;
1473 DCDB->SenseLength = sizeof(DCDB->SenseData);
1474 DCDB->CDB[0] = 0x12; /* INQUIRY */
1475 DCDB->CDB[1] = 0; /* EVPD = 0 */
1476 DCDB->CDB[2] = 0; /* Page Code */
1477 DCDB->CDB[3] = 0; /* Reserved */
1478 DCDB->CDB[4] = sizeof(DAC960_SCSI_Inquiry_T);
1479 DCDB->CDB[5] = 0; /* Control */
1480 DAC960_AcquireControllerLock(Controller, &ProcessorFlags);
1481 DAC960_QueueCommand(Command);
1482 DAC960_ReleaseControllerLock(Controller, &ProcessorFlags);
1483 }
1484 for (Channel = 0; Channel < Controller->Channels; Channel++)
1485 {
1486 DAC960_Command_T *Command = Controller->Commands[Channel];
1487 DAC960_SCSI_Inquiry_UnitSerialNumber_T *InquiryUnitSerialNumber =
1488 &Controller->V1.InquiryUnitSerialNumber[Channel][TargetID];
1489 InquiryUnitSerialNumber->PeripheralDeviceType = 0x1F;
1490 Completion = &Completions[Channel];
1491 wait_for_completion(Completion);
1492 if (Command->V1.CommandStatus != DAC960_V1_NormalCompletion)
1493 continue;
1494 Command->Completion = Completion;
1495 DCDB = &DCDBs[Channel];
1496 DCDB->TransferLength = sizeof(DAC960_SCSI_Inquiry_UnitSerialNumber_T);
1497 DCDB->BusAddress = Virtual_to_Bus32(InquiryUnitSerialNumber);
1498 DCDB->SenseLength = sizeof(DCDB->SenseData);
1499 DCDB->CDB[0] = 0x12; /* INQUIRY */
1500 DCDB->CDB[1] = 1; /* EVPD = 1 */
1501 DCDB->CDB[2] = 0x80; /* Page Code */
1502 DCDB->CDB[3] = 0; /* Reserved */
1503 DCDB->CDB[4] = sizeof(DAC960_SCSI_Inquiry_UnitSerialNumber_T);
1504 DCDB->CDB[5] = 0; /* Control */
1505 DAC960_AcquireControllerLock(Controller, &ProcessorFlags);
1506 DAC960_QueueCommand(Command);
1507 DAC960_ReleaseControllerLock(Controller, &ProcessorFlags);
1508 wait_for_completion(Completion);
1509 }
1510 }
1511 return true;
1512 }
1513
1514
1515 /*
1516 DAC960_V2_ReadDeviceConfiguration reads the Device Configuration Information
1517 for DAC960 V2 Firmware Controllers by requesting the Physical Device
1518 Information and SCSI Inquiry Unit Serial Number information for each
1519 device connected to Controller.
1520 */
1521
DAC960_V2_ReadDeviceConfiguration(DAC960_Controller_T * Controller)1522 static boolean DAC960_V2_ReadDeviceConfiguration(DAC960_Controller_T
1523 *Controller)
1524 {
1525 unsigned char Channel = 0, TargetID = 0, LogicalUnit = 0;
1526 unsigned short PhysicalDeviceIndex = 0;
1527 while (true)
1528 {
1529 DAC960_V2_PhysicalDeviceInfo_T *NewPhysicalDeviceInfo =
1530 &Controller->V2.NewPhysicalDeviceInformation;
1531 DAC960_V2_PhysicalDeviceInfo_T *PhysicalDeviceInfo;
1532 DAC960_SCSI_Inquiry_UnitSerialNumber_T *InquiryUnitSerialNumber;
1533 DAC960_Command_T *Command;
1534 DAC960_V2_CommandMailbox_T *CommandMailbox;
1535 if (!DAC960_V2_PhysicalDeviceInfo(Controller,
1536 DAC960_V2_GetPhysicalDeviceInfoValid,
1537 Channel,
1538 TargetID,
1539 LogicalUnit,
1540 NewPhysicalDeviceInfo,
1541 sizeof(DAC960_V2_PhysicalDeviceInfo_T)))
1542 break;
1543 Channel = NewPhysicalDeviceInfo->Channel;
1544 TargetID = NewPhysicalDeviceInfo->TargetID;
1545 LogicalUnit = NewPhysicalDeviceInfo->LogicalUnit;
1546 PhysicalDeviceInfo = (DAC960_V2_PhysicalDeviceInfo_T *)
1547 kmalloc(sizeof(DAC960_V2_PhysicalDeviceInfo_T), GFP_ATOMIC);
1548 if (PhysicalDeviceInfo == NULL)
1549 return DAC960_Failure(Controller, "PHYSICAL DEVICE ALLOCATION");
1550 Controller->V2.PhysicalDeviceInformation[PhysicalDeviceIndex] =
1551 PhysicalDeviceInfo;
1552 memcpy(PhysicalDeviceInfo, NewPhysicalDeviceInfo,
1553 sizeof(DAC960_V2_PhysicalDeviceInfo_T));
1554 InquiryUnitSerialNumber = (DAC960_SCSI_Inquiry_UnitSerialNumber_T *)
1555 kmalloc(sizeof(DAC960_SCSI_Inquiry_UnitSerialNumber_T), GFP_ATOMIC);
1556 if (InquiryUnitSerialNumber == NULL)
1557 return DAC960_Failure(Controller, "SERIAL NUMBER ALLOCATION");
1558 Controller->V2.InquiryUnitSerialNumber[PhysicalDeviceIndex] =
1559 InquiryUnitSerialNumber;
1560 memset(InquiryUnitSerialNumber, 0,
1561 sizeof(DAC960_SCSI_Inquiry_UnitSerialNumber_T));
1562 InquiryUnitSerialNumber->PeripheralDeviceType = 0x1F;
1563 Command = DAC960_AllocateCommand(Controller);
1564 CommandMailbox = &Command->V2.CommandMailbox;
1565 DAC960_V2_ClearCommand(Command);
1566 Command->CommandType = DAC960_ImmediateCommand;
1567 CommandMailbox->SCSI_10.CommandOpcode = DAC960_V2_SCSI_10_Passthru;
1568 CommandMailbox->SCSI_10.CommandControlBits
1569 .DataTransferControllerToHost = true;
1570 CommandMailbox->SCSI_10.CommandControlBits
1571 .NoAutoRequestSense = true;
1572 CommandMailbox->SCSI_10.DataTransferSize =
1573 sizeof(DAC960_SCSI_Inquiry_UnitSerialNumber_T);
1574 CommandMailbox->SCSI_10.PhysicalDevice.LogicalUnit = LogicalUnit;
1575 CommandMailbox->SCSI_10.PhysicalDevice.TargetID = TargetID;
1576 CommandMailbox->SCSI_10.PhysicalDevice.Channel = Channel;
1577 CommandMailbox->SCSI_10.CDBLength = 6;
1578 CommandMailbox->SCSI_10.SCSI_CDB[0] = 0x12; /* INQUIRY */
1579 CommandMailbox->SCSI_10.SCSI_CDB[1] = 1; /* EVPD = 1 */
1580 CommandMailbox->SCSI_10.SCSI_CDB[2] = 0x80; /* Page Code */
1581 CommandMailbox->SCSI_10.SCSI_CDB[3] = 0; /* Reserved */
1582 CommandMailbox->SCSI_10.SCSI_CDB[4] =
1583 sizeof(DAC960_SCSI_Inquiry_UnitSerialNumber_T);
1584 CommandMailbox->SCSI_10.SCSI_CDB[5] = 0; /* Control */
1585 CommandMailbox->SCSI_10.DataTransferMemoryAddress
1586 .ScatterGatherSegments[0]
1587 .SegmentDataPointer =
1588 Virtual_to_Bus64(InquiryUnitSerialNumber);
1589 CommandMailbox->SCSI_10.DataTransferMemoryAddress
1590 .ScatterGatherSegments[0]
1591 .SegmentByteCount =
1592 CommandMailbox->SCSI_10.DataTransferSize;
1593 DAC960_ExecuteCommand(Command);
1594 DAC960_DeallocateCommand(Command);
1595 PhysicalDeviceIndex++;
1596 LogicalUnit++;
1597 }
1598 return true;
1599 }
1600
1601
1602 /*
1603 DAC960_SanitizeInquiryData sanitizes the Vendor, Model, Revision, and
1604 Product Serial Number fields of the Inquiry Standard Data and Inquiry
1605 Unit Serial Number structures.
1606 */
1607
DAC960_SanitizeInquiryData(DAC960_SCSI_Inquiry_T * InquiryStandardData,DAC960_SCSI_Inquiry_UnitSerialNumber_T * InquiryUnitSerialNumber,unsigned char * Vendor,unsigned char * Model,unsigned char * Revision,unsigned char * SerialNumber)1608 static void DAC960_SanitizeInquiryData(DAC960_SCSI_Inquiry_T
1609 *InquiryStandardData,
1610 DAC960_SCSI_Inquiry_UnitSerialNumber_T
1611 *InquiryUnitSerialNumber,
1612 unsigned char *Vendor,
1613 unsigned char *Model,
1614 unsigned char *Revision,
1615 unsigned char *SerialNumber)
1616 {
1617 int SerialNumberLength, i;
1618 if (InquiryStandardData->PeripheralDeviceType == 0x1F) return;
1619 for (i = 0; i < sizeof(InquiryStandardData->VendorIdentification); i++)
1620 {
1621 unsigned char VendorCharacter =
1622 InquiryStandardData->VendorIdentification[i];
1623 Vendor[i] = (VendorCharacter >= ' ' && VendorCharacter <= '~'
1624 ? VendorCharacter : ' ');
1625 }
1626 Vendor[sizeof(InquiryStandardData->VendorIdentification)] = '\0';
1627 for (i = 0; i < sizeof(InquiryStandardData->ProductIdentification); i++)
1628 {
1629 unsigned char ModelCharacter =
1630 InquiryStandardData->ProductIdentification[i];
1631 Model[i] = (ModelCharacter >= ' ' && ModelCharacter <= '~'
1632 ? ModelCharacter : ' ');
1633 }
1634 Model[sizeof(InquiryStandardData->ProductIdentification)] = '\0';
1635 for (i = 0; i < sizeof(InquiryStandardData->ProductRevisionLevel); i++)
1636 {
1637 unsigned char RevisionCharacter =
1638 InquiryStandardData->ProductRevisionLevel[i];
1639 Revision[i] = (RevisionCharacter >= ' ' && RevisionCharacter <= '~'
1640 ? RevisionCharacter : ' ');
1641 }
1642 Revision[sizeof(InquiryStandardData->ProductRevisionLevel)] = '\0';
1643 if (InquiryUnitSerialNumber->PeripheralDeviceType == 0x1F) return;
1644 SerialNumberLength = InquiryUnitSerialNumber->PageLength;
1645 if (SerialNumberLength >
1646 sizeof(InquiryUnitSerialNumber->ProductSerialNumber))
1647 SerialNumberLength = sizeof(InquiryUnitSerialNumber->ProductSerialNumber);
1648 for (i = 0; i < SerialNumberLength; i++)
1649 {
1650 unsigned char SerialNumberCharacter =
1651 InquiryUnitSerialNumber->ProductSerialNumber[i];
1652 SerialNumber[i] =
1653 (SerialNumberCharacter >= ' ' && SerialNumberCharacter <= '~'
1654 ? SerialNumberCharacter : ' ');
1655 }
1656 SerialNumber[SerialNumberLength] = '\0';
1657 }
1658
1659
1660 /*
1661 DAC960_V1_ReportDeviceConfiguration reports the Device Configuration
1662 Information for DAC960 V1 Firmware Controllers.
1663 */
1664
DAC960_V1_ReportDeviceConfiguration(DAC960_Controller_T * Controller)1665 static boolean DAC960_V1_ReportDeviceConfiguration(DAC960_Controller_T
1666 *Controller)
1667 {
1668 int LogicalDriveNumber, Channel, TargetID;
1669 DAC960_Info(" Physical Devices:\n", Controller);
1670 for (Channel = 0; Channel < Controller->Channels; Channel++)
1671 for (TargetID = 0; TargetID < Controller->Targets; TargetID++)
1672 {
1673 DAC960_SCSI_Inquiry_T *InquiryStandardData =
1674 &Controller->V1.InquiryStandardData[Channel][TargetID];
1675 DAC960_SCSI_Inquiry_UnitSerialNumber_T *InquiryUnitSerialNumber =
1676 &Controller->V1.InquiryUnitSerialNumber[Channel][TargetID];
1677 DAC960_V1_DeviceState_T *DeviceState =
1678 &Controller->V1.DeviceState[Channel][TargetID];
1679 DAC960_V1_ErrorTableEntry_T *ErrorEntry =
1680 &Controller->V1.ErrorTable.ErrorTableEntries[Channel][TargetID];
1681 char Vendor[1+sizeof(InquiryStandardData->VendorIdentification)];
1682 char Model[1+sizeof(InquiryStandardData->ProductIdentification)];
1683 char Revision[1+sizeof(InquiryStandardData->ProductRevisionLevel)];
1684 char SerialNumber[1+sizeof(InquiryUnitSerialNumber
1685 ->ProductSerialNumber)];
1686 if (InquiryStandardData->PeripheralDeviceType == 0x1F) continue;
1687 DAC960_SanitizeInquiryData(InquiryStandardData, InquiryUnitSerialNumber,
1688 Vendor, Model, Revision, SerialNumber);
1689 DAC960_Info(" %d:%d%s Vendor: %s Model: %s Revision: %s\n",
1690 Controller, Channel, TargetID, (TargetID < 10 ? " " : ""),
1691 Vendor, Model, Revision);
1692 if (InquiryUnitSerialNumber->PeripheralDeviceType != 0x1F)
1693 DAC960_Info(" Serial Number: %s\n", Controller, SerialNumber);
1694 if (DeviceState->Present &&
1695 DeviceState->DeviceType == DAC960_V1_DiskType)
1696 {
1697 if (Controller->V1.DeviceResetCount[Channel][TargetID] > 0)
1698 DAC960_Info(" Disk Status: %s, %u blocks, %d resets\n",
1699 Controller,
1700 (DeviceState->DeviceState == DAC960_V1_Device_Dead
1701 ? "Dead"
1702 : DeviceState->DeviceState
1703 == DAC960_V1_Device_WriteOnly
1704 ? "Write-Only"
1705 : DeviceState->DeviceState
1706 == DAC960_V1_Device_Online
1707 ? "Online" : "Standby"),
1708 DeviceState->DiskSize,
1709 Controller->V1.DeviceResetCount[Channel][TargetID]);
1710 else
1711 DAC960_Info(" Disk Status: %s, %u blocks\n", Controller,
1712 (DeviceState->DeviceState == DAC960_V1_Device_Dead
1713 ? "Dead"
1714 : DeviceState->DeviceState
1715 == DAC960_V1_Device_WriteOnly
1716 ? "Write-Only"
1717 : DeviceState->DeviceState
1718 == DAC960_V1_Device_Online
1719 ? "Online" : "Standby"),
1720 DeviceState->DiskSize);
1721 }
1722 if (ErrorEntry->ParityErrorCount > 0 ||
1723 ErrorEntry->SoftErrorCount > 0 ||
1724 ErrorEntry->HardErrorCount > 0 ||
1725 ErrorEntry->MiscErrorCount > 0)
1726 DAC960_Info(" Errors - Parity: %d, Soft: %d, "
1727 "Hard: %d, Misc: %d\n", Controller,
1728 ErrorEntry->ParityErrorCount,
1729 ErrorEntry->SoftErrorCount,
1730 ErrorEntry->HardErrorCount,
1731 ErrorEntry->MiscErrorCount);
1732 }
1733 DAC960_Info(" Logical Drives:\n", Controller);
1734 for (LogicalDriveNumber = 0;
1735 LogicalDriveNumber < Controller->LogicalDriveCount;
1736 LogicalDriveNumber++)
1737 {
1738 DAC960_V1_LogicalDriveInformation_T *LogicalDriveInformation =
1739 &Controller->V1.LogicalDriveInformation[LogicalDriveNumber];
1740 DAC960_Info(" /dev/rd/c%dd%d: RAID-%d, %s, %u blocks, %s\n",
1741 Controller, Controller->ControllerNumber, LogicalDriveNumber,
1742 LogicalDriveInformation->RAIDLevel,
1743 (LogicalDriveInformation->LogicalDriveState
1744 == DAC960_V1_LogicalDrive_Online
1745 ? "Online"
1746 : LogicalDriveInformation->LogicalDriveState
1747 == DAC960_V1_LogicalDrive_Critical
1748 ? "Critical" : "Offline"),
1749 LogicalDriveInformation->LogicalDriveSize,
1750 (LogicalDriveInformation->WriteBack
1751 ? "Write Back" : "Write Thru"));
1752 }
1753 return true;
1754 }
1755
1756
1757 /*
1758 DAC960_V2_ReportDeviceConfiguration reports the Device Configuration
1759 Information for DAC960 V2 Firmware Controllers.
1760 */
1761
DAC960_V2_ReportDeviceConfiguration(DAC960_Controller_T * Controller)1762 static boolean DAC960_V2_ReportDeviceConfiguration(DAC960_Controller_T
1763 *Controller)
1764 {
1765 int PhysicalDeviceIndex, LogicalDriveNumber;
1766 DAC960_Info(" Physical Devices:\n", Controller);
1767 for (PhysicalDeviceIndex = 0;
1768 PhysicalDeviceIndex < DAC960_V2_MaxPhysicalDevices;
1769 PhysicalDeviceIndex++)
1770 {
1771 DAC960_V2_PhysicalDeviceInfo_T *PhysicalDeviceInfo =
1772 Controller->V2.PhysicalDeviceInformation[PhysicalDeviceIndex];
1773 DAC960_SCSI_Inquiry_T *InquiryStandardData =
1774 (DAC960_SCSI_Inquiry_T *) &PhysicalDeviceInfo->SCSI_InquiryData;
1775 DAC960_SCSI_Inquiry_UnitSerialNumber_T *InquiryUnitSerialNumber =
1776 Controller->V2.InquiryUnitSerialNumber[PhysicalDeviceIndex];
1777 char Vendor[1+sizeof(InquiryStandardData->VendorIdentification)];
1778 char Model[1+sizeof(InquiryStandardData->ProductIdentification)];
1779 char Revision[1+sizeof(InquiryStandardData->ProductRevisionLevel)];
1780 char SerialNumber[1+sizeof(InquiryUnitSerialNumber->ProductSerialNumber)];
1781 if (PhysicalDeviceInfo == NULL) break;
1782 DAC960_SanitizeInquiryData(InquiryStandardData, InquiryUnitSerialNumber,
1783 Vendor, Model, Revision, SerialNumber);
1784 DAC960_Info(" %d:%d%s Vendor: %s Model: %s Revision: %s\n",
1785 Controller,
1786 PhysicalDeviceInfo->Channel,
1787 PhysicalDeviceInfo->TargetID,
1788 (PhysicalDeviceInfo->TargetID < 10 ? " " : ""),
1789 Vendor, Model, Revision);
1790 if (PhysicalDeviceInfo->NegotiatedSynchronousMegaTransfers == 0)
1791 DAC960_Info(" %sAsynchronous\n", Controller,
1792 (PhysicalDeviceInfo->NegotiatedDataWidthBits == 16
1793 ? "Wide " :""));
1794 else
1795 DAC960_Info(" %sSynchronous at %d MB/sec\n", Controller,
1796 (PhysicalDeviceInfo->NegotiatedDataWidthBits == 16
1797 ? "Wide " :""),
1798 (PhysicalDeviceInfo->NegotiatedSynchronousMegaTransfers
1799 * (PhysicalDeviceInfo->NegotiatedDataWidthBits == 16
1800 ? 2 : 1)));
1801 if (InquiryUnitSerialNumber->PeripheralDeviceType != 0x1F)
1802 DAC960_Info(" Serial Number: %s\n", Controller, SerialNumber);
1803 if (PhysicalDeviceInfo->PhysicalDeviceState ==
1804 DAC960_V2_Device_Unconfigured)
1805 continue;
1806 DAC960_Info(" Disk Status: %s, %u blocks\n", Controller,
1807 (PhysicalDeviceInfo->PhysicalDeviceState
1808 == DAC960_V2_Device_Online
1809 ? "Online"
1810 : PhysicalDeviceInfo->PhysicalDeviceState
1811 == DAC960_V2_Device_Rebuild
1812 ? "Rebuild"
1813 : PhysicalDeviceInfo->PhysicalDeviceState
1814 == DAC960_V2_Device_Missing
1815 ? "Missing"
1816 : PhysicalDeviceInfo->PhysicalDeviceState
1817 == DAC960_V2_Device_Critical
1818 ? "Critical"
1819 : PhysicalDeviceInfo->PhysicalDeviceState
1820 == DAC960_V2_Device_Dead
1821 ? "Dead"
1822 : PhysicalDeviceInfo->PhysicalDeviceState
1823 == DAC960_V2_Device_SuspectedDead
1824 ? "Suspected-Dead"
1825 : PhysicalDeviceInfo->PhysicalDeviceState
1826 == DAC960_V2_Device_CommandedOffline
1827 ? "Commanded-Offline"
1828 : PhysicalDeviceInfo->PhysicalDeviceState
1829 == DAC960_V2_Device_Standby
1830 ? "Standby" : "Unknown"),
1831 PhysicalDeviceInfo->ConfigurableDeviceSize);
1832 if (PhysicalDeviceInfo->ParityErrors == 0 &&
1833 PhysicalDeviceInfo->SoftErrors == 0 &&
1834 PhysicalDeviceInfo->HardErrors == 0 &&
1835 PhysicalDeviceInfo->MiscellaneousErrors == 0 &&
1836 PhysicalDeviceInfo->CommandTimeouts == 0 &&
1837 PhysicalDeviceInfo->Retries == 0 &&
1838 PhysicalDeviceInfo->Aborts == 0 &&
1839 PhysicalDeviceInfo->PredictedFailuresDetected == 0)
1840 continue;
1841 DAC960_Info(" Errors - Parity: %d, Soft: %d, "
1842 "Hard: %d, Misc: %d\n", Controller,
1843 PhysicalDeviceInfo->ParityErrors,
1844 PhysicalDeviceInfo->SoftErrors,
1845 PhysicalDeviceInfo->HardErrors,
1846 PhysicalDeviceInfo->MiscellaneousErrors);
1847 DAC960_Info(" Timeouts: %d, Retries: %d, "
1848 "Aborts: %d, Predicted: %d\n", Controller,
1849 PhysicalDeviceInfo->CommandTimeouts,
1850 PhysicalDeviceInfo->Retries,
1851 PhysicalDeviceInfo->Aborts,
1852 PhysicalDeviceInfo->PredictedFailuresDetected);
1853 }
1854 DAC960_Info(" Logical Drives:\n", Controller);
1855 for (LogicalDriveNumber = 0;
1856 LogicalDriveNumber < DAC960_MaxLogicalDrives;
1857 LogicalDriveNumber++)
1858 {
1859 DAC960_V2_LogicalDeviceInfo_T *LogicalDeviceInfo =
1860 Controller->V2.LogicalDeviceInformation[LogicalDriveNumber];
1861 unsigned char *ReadCacheStatus[] = { "Read Cache Disabled",
1862 "Read Cache Enabled",
1863 "Read Ahead Enabled",
1864 "Intelligent Read Ahead Enabled",
1865 "-", "-", "-", "-" };
1866 unsigned char *WriteCacheStatus[] = { "Write Cache Disabled",
1867 "Logical Device Read Only",
1868 "Write Cache Enabled",
1869 "Intelligent Write Cache Enabled",
1870 "-", "-", "-", "-" };
1871 unsigned char *GeometryTranslation;
1872 if (LogicalDeviceInfo == NULL) continue;
1873 switch (LogicalDeviceInfo->DriveGeometry)
1874 {
1875 case DAC960_V2_Geometry_128_32:
1876 GeometryTranslation = "128/32";
1877 break;
1878 case DAC960_V2_Geometry_255_63:
1879 GeometryTranslation = "255/63";
1880 break;
1881 default:
1882 GeometryTranslation = "Invalid";
1883 DAC960_Error("Illegal Logical Device Geometry %d\n",
1884 Controller, LogicalDeviceInfo->DriveGeometry);
1885 break;
1886 }
1887 DAC960_Info(" /dev/rd/c%dd%d: RAID-%d, %s, %u blocks\n",
1888 Controller, Controller->ControllerNumber, LogicalDriveNumber,
1889 LogicalDeviceInfo->RAIDLevel,
1890 (LogicalDeviceInfo->LogicalDeviceState
1891 == DAC960_V2_LogicalDevice_Online
1892 ? "Online"
1893 : LogicalDeviceInfo->LogicalDeviceState
1894 == DAC960_V2_LogicalDevice_Critical
1895 ? "Critical" : "Offline"),
1896 LogicalDeviceInfo->ConfigurableDeviceSize);
1897 DAC960_Info(" Logical Device %s, BIOS Geometry: %s\n",
1898 Controller,
1899 (LogicalDeviceInfo->LogicalDeviceControl
1900 .LogicalDeviceInitialized
1901 ? "Initialized" : "Uninitialized"),
1902 GeometryTranslation);
1903 if (LogicalDeviceInfo->StripeSize == 0)
1904 {
1905 if (LogicalDeviceInfo->CacheLineSize == 0)
1906 DAC960_Info(" Stripe Size: N/A, "
1907 "Segment Size: N/A\n", Controller);
1908 else
1909 DAC960_Info(" Stripe Size: N/A, "
1910 "Segment Size: %dKB\n", Controller,
1911 1 << (LogicalDeviceInfo->CacheLineSize - 2));
1912 }
1913 else
1914 {
1915 if (LogicalDeviceInfo->CacheLineSize == 0)
1916 DAC960_Info(" Stripe Size: %dKB, "
1917 "Segment Size: N/A\n", Controller,
1918 1 << (LogicalDeviceInfo->StripeSize - 2));
1919 else
1920 DAC960_Info(" Stripe Size: %dKB, "
1921 "Segment Size: %dKB\n", Controller,
1922 1 << (LogicalDeviceInfo->StripeSize - 2),
1923 1 << (LogicalDeviceInfo->CacheLineSize - 2));
1924 }
1925 DAC960_Info(" %s, %s\n", Controller,
1926 ReadCacheStatus[
1927 LogicalDeviceInfo->LogicalDeviceControl.ReadCache],
1928 WriteCacheStatus[
1929 LogicalDeviceInfo->LogicalDeviceControl.WriteCache]);
1930 if (LogicalDeviceInfo->SoftErrors > 0 ||
1931 LogicalDeviceInfo->CommandsFailed > 0 ||
1932 LogicalDeviceInfo->DeferredWriteErrors)
1933 DAC960_Info(" Errors - Soft: %d, Failed: %d, "
1934 "Deferred Write: %d\n", Controller,
1935 LogicalDeviceInfo->SoftErrors,
1936 LogicalDeviceInfo->CommandsFailed,
1937 LogicalDeviceInfo->DeferredWriteErrors);
1938
1939 }
1940 return true;
1941 }
1942
1943
1944 /*
1945 DAC960_BackMergeFunction is the Back Merge Function for the DAC960 driver.
1946 */
1947
DAC960_BackMergeFunction(RequestQueue_T * RequestQueue,IO_Request_T * Request,BufferHeader_T * BufferHeader,int MaxSegments)1948 static int DAC960_BackMergeFunction(RequestQueue_T *RequestQueue,
1949 IO_Request_T *Request,
1950 BufferHeader_T *BufferHeader,
1951 int MaxSegments)
1952 {
1953 DAC960_Controller_T *Controller =
1954 (DAC960_Controller_T *) RequestQueue->queuedata;
1955 if (Request->bhtail->b_data + Request->bhtail->b_size == BufferHeader->b_data)
1956 return true;
1957 if (Request->nr_segments < MaxSegments &&
1958 Request->nr_segments < Controller->DriverScatterGatherLimit)
1959 {
1960 Request->nr_segments++;
1961 return true;
1962 }
1963 return false;
1964 }
1965
1966
1967 /*
1968 DAC960_FrontMergeFunction is the Front Merge Function for the DAC960 driver.
1969 */
1970
DAC960_FrontMergeFunction(RequestQueue_T * RequestQueue,IO_Request_T * Request,BufferHeader_T * BufferHeader,int MaxSegments)1971 static int DAC960_FrontMergeFunction(RequestQueue_T *RequestQueue,
1972 IO_Request_T *Request,
1973 BufferHeader_T *BufferHeader,
1974 int MaxSegments)
1975 {
1976 DAC960_Controller_T *Controller =
1977 (DAC960_Controller_T *) RequestQueue->queuedata;
1978 if (BufferHeader->b_data + BufferHeader->b_size == Request->bh->b_data)
1979 return true;
1980 if (Request->nr_segments < MaxSegments &&
1981 Request->nr_segments < Controller->DriverScatterGatherLimit)
1982 {
1983 Request->nr_segments++;
1984 return true;
1985 }
1986 return false;
1987 }
1988
1989
1990 /*
1991 DAC960_MergeRequestsFunction is the Merge Requests Function for the
1992 DAC960 driver.
1993 */
1994
DAC960_MergeRequestsFunction(RequestQueue_T * RequestQueue,IO_Request_T * Request,IO_Request_T * NextRequest,int MaxSegments)1995 static int DAC960_MergeRequestsFunction(RequestQueue_T *RequestQueue,
1996 IO_Request_T *Request,
1997 IO_Request_T *NextRequest,
1998 int MaxSegments)
1999 {
2000 DAC960_Controller_T *Controller =
2001 (DAC960_Controller_T *) RequestQueue->queuedata;
2002 int TotalSegments = Request->nr_segments + NextRequest->nr_segments;
2003 if (Request->bhtail->b_data + Request->bhtail->b_size
2004 == NextRequest->bh->b_data)
2005 TotalSegments--;
2006 if (TotalSegments > MaxSegments ||
2007 TotalSegments > Controller->DriverScatterGatherLimit)
2008 return false;
2009 Request->nr_segments = TotalSegments;
2010 return true;
2011 }
2012
2013
2014 /*
2015 DAC960_RegisterBlockDevice registers the Block Device structures
2016 associated with Controller.
2017 */
2018
DAC960_RegisterBlockDevice(DAC960_Controller_T * Controller)2019 static boolean DAC960_RegisterBlockDevice(DAC960_Controller_T *Controller)
2020 {
2021 int MajorNumber = DAC960_MAJOR + Controller->ControllerNumber;
2022 RequestQueue_T *RequestQueue;
2023 int MinorNumber;
2024 /*
2025 Register the Block Device Major Number for this DAC960 Controller.
2026 */
2027 if (devfs_register_blkdev(MajorNumber, "dac960",
2028 &DAC960_BlockDeviceOperations) < 0)
2029 {
2030 DAC960_Error("UNABLE TO ACQUIRE MAJOR NUMBER %d - DETACHING\n",
2031 Controller, MajorNumber);
2032 return false;
2033 }
2034 /*
2035 Initialize the I/O Request Queue.
2036 */
2037 RequestQueue = BLK_DEFAULT_QUEUE(MajorNumber);
2038 blk_init_queue(RequestQueue, DAC960_RequestFunction);
2039 blk_queue_headactive(RequestQueue, 0);
2040 RequestQueue->back_merge_fn = DAC960_BackMergeFunction;
2041 RequestQueue->front_merge_fn = DAC960_FrontMergeFunction;
2042 RequestQueue->merge_requests_fn = DAC960_MergeRequestsFunction;
2043 RequestQueue->queuedata = Controller;
2044 Controller->RequestQueue = RequestQueue;
2045 /*
2046 Initialize the Max Sectors per Request array.
2047 */
2048 for (MinorNumber = 0; MinorNumber < DAC960_MinorCount; MinorNumber++)
2049 Controller->MaxSectorsPerRequest[MinorNumber] =
2050 Controller->MaxBlocksPerCommand;
2051 Controller->GenericDiskInfo.part = Controller->DiskPartitions;
2052 Controller->GenericDiskInfo.sizes = Controller->PartitionSizes;
2053 blksize_size[MajorNumber] = Controller->BlockSizes;
2054 max_sectors[MajorNumber] = Controller->MaxSectorsPerRequest;
2055 /*
2056 Initialize Read Ahead to 128 sectors.
2057 */
2058 read_ahead[MajorNumber] = 128;
2059 /*
2060 Complete initialization of the Generic Disk Information structure.
2061 */
2062 Controller->GenericDiskInfo.major = MajorNumber;
2063 Controller->GenericDiskInfo.major_name = "rd";
2064 Controller->GenericDiskInfo.minor_shift = DAC960_MaxPartitionsBits;
2065 Controller->GenericDiskInfo.max_p = DAC960_MaxPartitions;
2066 Controller->GenericDiskInfo.nr_real = DAC960_MaxLogicalDrives;
2067 Controller->GenericDiskInfo.real_devices = Controller;
2068 Controller->GenericDiskInfo.next = NULL;
2069 Controller->GenericDiskInfo.fops = &DAC960_BlockDeviceOperations;
2070 /*
2071 Install the Generic Disk Information structure at the end of the list.
2072 */
2073 add_gendisk(&Controller->GenericDiskInfo);
2074 /*
2075 Indicate the Block Device Registration completed successfully,
2076 */
2077 return true;
2078 }
2079
2080
2081 /*
2082 DAC960_UnregisterBlockDevice unregisters the Block Device structures
2083 associated with Controller.
2084 */
2085
DAC960_UnregisterBlockDevice(DAC960_Controller_T * Controller)2086 static void DAC960_UnregisterBlockDevice(DAC960_Controller_T *Controller)
2087 {
2088 int MajorNumber = DAC960_MAJOR + Controller->ControllerNumber;
2089 /*
2090 Unregister the Block Device Major Number for this DAC960 Controller.
2091 */
2092 devfs_unregister_blkdev(MajorNumber, "dac960");
2093 /*
2094 Remove the I/O Request Queue.
2095 */
2096 blk_cleanup_queue(BLK_DEFAULT_QUEUE(MajorNumber));
2097 /*
2098 Remove the Disk Partitions array, Partition Sizes array, Block Sizes
2099 array, Max Sectors per Request array, and Max Segments per Request array.
2100 */
2101 Controller->GenericDiskInfo.part = NULL;
2102 Controller->GenericDiskInfo.sizes = NULL;
2103 blk_size[MajorNumber] = NULL;
2104 blksize_size[MajorNumber] = NULL;
2105 max_sectors[MajorNumber] = NULL;
2106 /*
2107 Remove the Generic Disk Information structure from the list.
2108 */
2109 del_gendisk(&Controller->GenericDiskInfo);
2110 }
2111
2112
2113 /*
2114 DAC960_ComputeGenericDiskInfo computes the values for the Generic Disk
2115 Information Partition Sector Counts and Block Sizes.
2116 */
2117
DAC960_ComputeGenericDiskInfo(GenericDiskInfo_T * GenericDiskInfo)2118 static void DAC960_ComputeGenericDiskInfo(GenericDiskInfo_T *GenericDiskInfo)
2119 {
2120 DAC960_Controller_T *Controller =
2121 (DAC960_Controller_T *) GenericDiskInfo->real_devices;
2122 int LogicalDriveNumber, i;
2123 for (LogicalDriveNumber = 0;
2124 LogicalDriveNumber < DAC960_MaxLogicalDrives;
2125 LogicalDriveNumber++)
2126 {
2127 int MinorNumber = DAC960_MinorNumber(LogicalDriveNumber, 0);
2128 if (Controller->FirmwareType == DAC960_V1_Controller)
2129 {
2130 if (LogicalDriveNumber < Controller->LogicalDriveCount)
2131 GenericDiskInfo->part[MinorNumber].nr_sects =
2132 Controller->V1.LogicalDriveInformation
2133 [LogicalDriveNumber].LogicalDriveSize;
2134 else GenericDiskInfo->part[MinorNumber].nr_sects = 0;
2135 }
2136 else
2137 {
2138 DAC960_V2_LogicalDeviceInfo_T *LogicalDeviceInfo =
2139 Controller->V2.LogicalDeviceInformation[LogicalDriveNumber];
2140 if (LogicalDeviceInfo != NULL)
2141 GenericDiskInfo->part[MinorNumber].nr_sects =
2142 LogicalDeviceInfo->ConfigurableDeviceSize;
2143 else GenericDiskInfo->part[MinorNumber].nr_sects = 0;
2144 }
2145 for (i = 0; i < DAC960_MaxPartitions; i++)
2146 if (GenericDiskInfo->part[MinorNumber].nr_sects > 0)
2147 Controller->BlockSizes[MinorNumber + i] = BLOCK_SIZE;
2148 else Controller->BlockSizes[MinorNumber + i] = 0;
2149 }
2150 }
2151
2152
2153 /*
2154 DAC960_RegisterDisk registers the DAC960 Logical Disk Device for Logical
2155 Drive Number if it exists.
2156 */
2157
DAC960_RegisterDisk(DAC960_Controller_T * Controller,int LogicalDriveNumber)2158 static void DAC960_RegisterDisk(DAC960_Controller_T *Controller,
2159 int LogicalDriveNumber)
2160 {
2161 if (Controller->FirmwareType == DAC960_V1_Controller)
2162 {
2163 if (LogicalDriveNumber > Controller->LogicalDriveCount - 1) return;
2164 register_disk(&Controller->GenericDiskInfo,
2165 DAC960_KernelDevice(Controller->ControllerNumber,
2166 LogicalDriveNumber, 0),
2167 DAC960_MaxPartitions,
2168 &DAC960_BlockDeviceOperations,
2169 Controller->V1.LogicalDriveInformation
2170 [LogicalDriveNumber].LogicalDriveSize);
2171 }
2172 else
2173 {
2174 DAC960_V2_LogicalDeviceInfo_T *LogicalDeviceInfo =
2175 Controller->V2.LogicalDeviceInformation[LogicalDriveNumber];
2176 if (LogicalDeviceInfo == NULL) return;
2177 register_disk(&Controller->GenericDiskInfo,
2178 DAC960_KernelDevice(Controller->ControllerNumber,
2179 LogicalDriveNumber, 0),
2180 DAC960_MaxPartitions,
2181 &DAC960_BlockDeviceOperations,
2182 LogicalDeviceInfo->ConfigurableDeviceSize);
2183 }
2184 }
2185
2186
2187 /*
2188 DAC960_ReportErrorStatus reports Controller BIOS Messages passed through
2189 the Error Status Register when the driver performs the BIOS handshaking.
2190 It returns true for fatal errors and false otherwise.
2191 */
2192
DAC960_ReportErrorStatus(DAC960_Controller_T * Controller,unsigned char ErrorStatus,unsigned char Parameter0,unsigned char Parameter1)2193 static boolean DAC960_ReportErrorStatus(DAC960_Controller_T *Controller,
2194 unsigned char ErrorStatus,
2195 unsigned char Parameter0,
2196 unsigned char Parameter1)
2197 {
2198 switch (ErrorStatus)
2199 {
2200 case 0x00:
2201 DAC960_Notice("Physical Device %d:%d Not Responding\n",
2202 Controller, Parameter1, Parameter0);
2203 break;
2204 case 0x08:
2205 if (Controller->DriveSpinUpMessageDisplayed) break;
2206 DAC960_Notice("Spinning Up Drives\n", Controller);
2207 Controller->DriveSpinUpMessageDisplayed = true;
2208 break;
2209 case 0x30:
2210 DAC960_Notice("Configuration Checksum Error\n", Controller);
2211 break;
2212 case 0x60:
2213 DAC960_Notice("Mirror Race Recovery Failed\n", Controller);
2214 break;
2215 case 0x70:
2216 DAC960_Notice("Mirror Race Recovery In Progress\n", Controller);
2217 break;
2218 case 0x90:
2219 DAC960_Notice("Physical Device %d:%d COD Mismatch\n",
2220 Controller, Parameter1, Parameter0);
2221 break;
2222 case 0xA0:
2223 DAC960_Notice("Logical Drive Installation Aborted\n", Controller);
2224 break;
2225 case 0xB0:
2226 DAC960_Notice("Mirror Race On A Critical Logical Drive\n", Controller);
2227 break;
2228 case 0xD0:
2229 DAC960_Notice("New Controller Configuration Found\n", Controller);
2230 break;
2231 case 0xF0:
2232 DAC960_Error("Fatal Memory Parity Error for Controller at\n", Controller);
2233 return true;
2234 default:
2235 DAC960_Error("Unknown Initialization Error %02X for Controller at\n",
2236 Controller, ErrorStatus);
2237 return true;
2238 }
2239 return false;
2240 }
2241
2242
2243 /*
2244 DAC960_DetectControllers detects Mylex DAC960/AcceleRAID/eXtremeRAID
2245 PCI RAID Controllers by interrogating the PCI Configuration Space for
2246 Controller Type.
2247 */
2248
DAC960_DetectControllers(DAC960_HardwareType_T HardwareType)2249 static void DAC960_DetectControllers(DAC960_HardwareType_T HardwareType)
2250 {
2251 void (*InterruptHandler)(int, void *, Registers_T *) = NULL;
2252 DAC960_FirmwareType_T FirmwareType = 0;
2253 unsigned short VendorID = 0, DeviceID = 0;
2254 unsigned int MemoryWindowSize = 0;
2255 PCI_Device_T *PCI_Device = NULL;
2256 switch (HardwareType)
2257 {
2258 case DAC960_BA_Controller:
2259 VendorID = PCI_VENDOR_ID_MYLEX;
2260 DeviceID = PCI_DEVICE_ID_MYLEX_DAC960_BA;
2261 FirmwareType = DAC960_V2_Controller;
2262 InterruptHandler = DAC960_BA_InterruptHandler;
2263 MemoryWindowSize = DAC960_BA_RegisterWindowSize;
2264 break;
2265 case DAC960_LP_Controller:
2266 VendorID = PCI_VENDOR_ID_MYLEX;
2267 DeviceID = PCI_DEVICE_ID_MYLEX_DAC960_LP;
2268 FirmwareType = DAC960_LP_Controller;
2269 InterruptHandler = DAC960_LP_InterruptHandler;
2270 MemoryWindowSize = DAC960_LP_RegisterWindowSize;
2271 break;
2272 case DAC960_LA_Controller:
2273 VendorID = PCI_VENDOR_ID_DEC;
2274 DeviceID = PCI_DEVICE_ID_DEC_21285;
2275 FirmwareType = DAC960_V1_Controller;
2276 InterruptHandler = DAC960_LA_InterruptHandler;
2277 MemoryWindowSize = DAC960_LA_RegisterWindowSize;
2278 break;
2279 case DAC960_PG_Controller:
2280 VendorID = PCI_VENDOR_ID_MYLEX;
2281 DeviceID = PCI_DEVICE_ID_MYLEX_DAC960_PG;
2282 FirmwareType = DAC960_V1_Controller;
2283 InterruptHandler = DAC960_PG_InterruptHandler;
2284 MemoryWindowSize = DAC960_PG_RegisterWindowSize;
2285 break;
2286 case DAC960_PD_Controller:
2287 VendorID = PCI_VENDOR_ID_MYLEX;
2288 DeviceID = PCI_DEVICE_ID_MYLEX_DAC960_PD;
2289 FirmwareType = DAC960_V1_Controller;
2290 InterruptHandler = DAC960_PD_InterruptHandler;
2291 MemoryWindowSize = DAC960_PD_RegisterWindowSize;
2292 break;
2293 case DAC960_P_Controller:
2294 VendorID = PCI_VENDOR_ID_MYLEX;
2295 DeviceID = PCI_DEVICE_ID_MYLEX_DAC960_P;
2296 FirmwareType = DAC960_V1_Controller;
2297 InterruptHandler = DAC960_P_InterruptHandler;
2298 MemoryWindowSize = DAC960_PD_RegisterWindowSize;
2299 break;
2300 }
2301 while ((PCI_Device = pci_find_device(VendorID, DeviceID, PCI_Device)) != NULL)
2302 {
2303 DAC960_Controller_T *Controller = NULL;
2304 DAC960_IO_Address_T IO_Address = 0;
2305 DAC960_PCI_Address_T PCI_Address = 0;
2306 unsigned char Bus = PCI_Device->bus->number;
2307 unsigned char DeviceFunction = PCI_Device->devfn;
2308 unsigned char Device = DeviceFunction >> 3;
2309 unsigned char Function = DeviceFunction & 0x7;
2310 unsigned char ErrorStatus, Parameter0, Parameter1;
2311 unsigned int IRQ_Channel = PCI_Device->irq;
2312 void *BaseAddress;
2313 if (pci_enable_device(PCI_Device) != 0) continue;
2314 switch (HardwareType)
2315 {
2316 case DAC960_BA_Controller:
2317 PCI_Address = pci_resource_start(PCI_Device, 0);
2318 break;
2319 case DAC960_LP_Controller:
2320 PCI_Address = pci_resource_start(PCI_Device, 0);
2321 break;
2322 case DAC960_LA_Controller:
2323 if (!(PCI_Device->subsystem_vendor == PCI_VENDOR_ID_MYLEX &&
2324 PCI_Device->subsystem_device == PCI_DEVICE_ID_MYLEX_DAC960_LA))
2325 continue;
2326 PCI_Address = pci_resource_start(PCI_Device, 0);
2327 break;
2328 case DAC960_PG_Controller:
2329 PCI_Address = pci_resource_start(PCI_Device, 0);
2330 break;
2331 case DAC960_PD_Controller:
2332 IO_Address = pci_resource_start(PCI_Device, 0);
2333 PCI_Address = pci_resource_start(PCI_Device, 1);
2334 break;
2335 case DAC960_P_Controller:
2336 IO_Address = pci_resource_start(PCI_Device, 0);
2337 PCI_Address = pci_resource_start(PCI_Device, 1);
2338 break;
2339 }
2340 if (DAC960_ControllerCount == DAC960_MaxControllers)
2341 {
2342 DAC960_Error("More than %d DAC960 Controllers detected - "
2343 "ignoring from Controller at\n",
2344 NULL, DAC960_MaxControllers);
2345 goto Failure;
2346 }
2347 Controller = (DAC960_Controller_T *)
2348 kmalloc(sizeof(DAC960_Controller_T), GFP_ATOMIC);
2349 if (Controller == NULL)
2350 {
2351 DAC960_Error("Unable to allocate Controller structure for "
2352 "Controller at\n", NULL);
2353 goto Failure;
2354 }
2355 memset(Controller, 0, sizeof(DAC960_Controller_T));
2356 Controller->ControllerNumber = DAC960_ControllerCount;
2357 init_waitqueue_head(&Controller->CommandWaitQueue);
2358 init_waitqueue_head(&Controller->HealthStatusWaitQueue);
2359 DAC960_Controllers[DAC960_ControllerCount++] = Controller;
2360 DAC960_AnnounceDriver(Controller);
2361 Controller->FirmwareType = FirmwareType;
2362 Controller->HardwareType = HardwareType;
2363 Controller->IO_Address = IO_Address;
2364 Controller->PCI_Address = PCI_Address;
2365 Controller->Bus = Bus;
2366 Controller->Device = Device;
2367 Controller->Function = Function;
2368 /*
2369 Map the Controller Register Window.
2370 */
2371 if (MemoryWindowSize < PAGE_SIZE)
2372 MemoryWindowSize = PAGE_SIZE;
2373 Controller->MemoryMappedAddress =
2374 ioremap_nocache(PCI_Address & PAGE_MASK, MemoryWindowSize);
2375 Controller->BaseAddress =
2376 Controller->MemoryMappedAddress + (PCI_Address & ~PAGE_MASK);
2377 if (Controller->MemoryMappedAddress == NULL)
2378 {
2379 DAC960_Error("Unable to map Controller Register Window for "
2380 "Controller at\n", Controller);
2381 goto Failure;
2382 }
2383 BaseAddress = Controller->BaseAddress;
2384 switch (HardwareType)
2385 {
2386 case DAC960_BA_Controller:
2387 DAC960_BA_DisableInterrupts(Controller->BaseAddress);
2388 DAC960_BA_AcknowledgeHardwareMailboxStatus(BaseAddress);
2389 udelay(1000);
2390 while (DAC960_BA_InitializationInProgressP(BaseAddress))
2391 {
2392 if (DAC960_BA_ReadErrorStatus(BaseAddress, &ErrorStatus,
2393 &Parameter0, &Parameter1) &&
2394 DAC960_ReportErrorStatus(Controller, ErrorStatus,
2395 Parameter0, Parameter1))
2396 goto Failure;
2397 udelay(10);
2398 }
2399 if (!DAC960_V2_EnableMemoryMailboxInterface(Controller))
2400 {
2401 DAC960_Error("Unable to Enable Memory Mailbox Interface "
2402 "for Controller at\n", Controller);
2403 goto Failure;
2404 }
2405 DAC960_BA_EnableInterrupts(Controller->BaseAddress);
2406 Controller->QueueCommand = DAC960_BA_QueueCommand;
2407 Controller->ReadControllerConfiguration =
2408 DAC960_V2_ReadControllerConfiguration;
2409 Controller->ReadDeviceConfiguration =
2410 DAC960_V2_ReadDeviceConfiguration;
2411 Controller->ReportDeviceConfiguration =
2412 DAC960_V2_ReportDeviceConfiguration;
2413 Controller->QueueReadWriteCommand =
2414 DAC960_V2_QueueReadWriteCommand;
2415 break;
2416 case DAC960_LP_Controller:
2417 DAC960_LP_DisableInterrupts(Controller->BaseAddress);
2418 DAC960_LP_AcknowledgeHardwareMailboxStatus(BaseAddress);
2419 udelay(1000);
2420 while (DAC960_LP_InitializationInProgressP(BaseAddress))
2421 {
2422 if (DAC960_LP_ReadErrorStatus(BaseAddress, &ErrorStatus,
2423 &Parameter0, &Parameter1) &&
2424 DAC960_ReportErrorStatus(Controller, ErrorStatus,
2425 Parameter0, Parameter1))
2426 goto Failure;
2427 udelay(10);
2428 }
2429 if (!DAC960_V2_EnableMemoryMailboxInterface(Controller))
2430 {
2431 DAC960_Error("Unable to Enable Memory Mailbox Interface "
2432 "for Controller at\n", Controller);
2433 goto Failure;
2434 }
2435 DAC960_LP_EnableInterrupts(Controller->BaseAddress);
2436 Controller->QueueCommand = DAC960_LP_QueueCommand;
2437 Controller->ReadControllerConfiguration =
2438 DAC960_V2_ReadControllerConfiguration;
2439 Controller->ReadDeviceConfiguration =
2440 DAC960_V2_ReadDeviceConfiguration;
2441 Controller->ReportDeviceConfiguration =
2442 DAC960_V2_ReportDeviceConfiguration;
2443 Controller->QueueReadWriteCommand =
2444 DAC960_V2_QueueReadWriteCommand;
2445 break;
2446 case DAC960_LA_Controller:
2447 DAC960_LA_DisableInterrupts(Controller->BaseAddress);
2448 DAC960_LA_AcknowledgeHardwareMailboxStatus(BaseAddress);
2449 udelay(1000);
2450 while (DAC960_LA_InitializationInProgressP(BaseAddress))
2451 {
2452 if (DAC960_LA_ReadErrorStatus(BaseAddress, &ErrorStatus,
2453 &Parameter0, &Parameter1) &&
2454 DAC960_ReportErrorStatus(Controller, ErrorStatus,
2455 Parameter0, Parameter1))
2456 goto Failure;
2457 udelay(10);
2458 }
2459 if (!DAC960_V1_EnableMemoryMailboxInterface(Controller))
2460 {
2461 DAC960_Error("Unable to Enable Memory Mailbox Interface "
2462 "for Controller at\n", Controller);
2463 goto Failure;
2464 }
2465 DAC960_LA_EnableInterrupts(Controller->BaseAddress);
2466 if (Controller->V1.DualModeMemoryMailboxInterface)
2467 Controller->QueueCommand = DAC960_LA_QueueCommandDualMode;
2468 else Controller->QueueCommand = DAC960_LA_QueueCommandSingleMode;
2469 Controller->ReadControllerConfiguration =
2470 DAC960_V1_ReadControllerConfiguration;
2471 Controller->ReadDeviceConfiguration =
2472 DAC960_V1_ReadDeviceConfiguration;
2473 Controller->ReportDeviceConfiguration =
2474 DAC960_V1_ReportDeviceConfiguration;
2475 Controller->QueueReadWriteCommand =
2476 DAC960_V1_QueueReadWriteCommand;
2477 break;
2478 case DAC960_PG_Controller:
2479 DAC960_PG_DisableInterrupts(Controller->BaseAddress);
2480 DAC960_PG_AcknowledgeHardwareMailboxStatus(BaseAddress);
2481 udelay(1000);
2482 while (DAC960_PG_InitializationInProgressP(BaseAddress))
2483 {
2484 if (DAC960_PG_ReadErrorStatus(BaseAddress, &ErrorStatus,
2485 &Parameter0, &Parameter1) &&
2486 DAC960_ReportErrorStatus(Controller, ErrorStatus,
2487 Parameter0, Parameter1))
2488 goto Failure;
2489 udelay(10);
2490 }
2491 if (!DAC960_V1_EnableMemoryMailboxInterface(Controller))
2492 {
2493 DAC960_Error("Unable to Enable Memory Mailbox Interface "
2494 "for Controller at\n", Controller);
2495 goto Failure;
2496 }
2497 DAC960_PG_EnableInterrupts(Controller->BaseAddress);
2498 if (Controller->V1.DualModeMemoryMailboxInterface)
2499 Controller->QueueCommand = DAC960_PG_QueueCommandDualMode;
2500 else Controller->QueueCommand = DAC960_PG_QueueCommandSingleMode;
2501 Controller->ReadControllerConfiguration =
2502 DAC960_V1_ReadControllerConfiguration;
2503 Controller->ReadDeviceConfiguration =
2504 DAC960_V1_ReadDeviceConfiguration;
2505 Controller->ReportDeviceConfiguration =
2506 DAC960_V1_ReportDeviceConfiguration;
2507 Controller->QueueReadWriteCommand =
2508 DAC960_V1_QueueReadWriteCommand;
2509 break;
2510 case DAC960_PD_Controller:
2511 if (!request_region(Controller->IO_Address, 0x80,
2512 Controller->FullModelName)) {
2513 DAC960_Error("IO port 0x%d busy for Controller at\n",
2514 Controller, Controller->IO_Address);
2515 goto Failure;
2516 }
2517 DAC960_PD_DisableInterrupts(BaseAddress);
2518 DAC960_PD_AcknowledgeStatus(BaseAddress);
2519 udelay(1000);
2520 while (DAC960_PD_InitializationInProgressP(BaseAddress))
2521 {
2522 if (DAC960_PD_ReadErrorStatus(BaseAddress, &ErrorStatus,
2523 &Parameter0, &Parameter1) &&
2524 DAC960_ReportErrorStatus(Controller, ErrorStatus,
2525 Parameter0, Parameter1))
2526 goto Failure1;
2527 udelay(10);
2528 }
2529 DAC960_PD_EnableInterrupts(Controller->BaseAddress);
2530 Controller->QueueCommand = DAC960_PD_QueueCommand;
2531 Controller->ReadControllerConfiguration =
2532 DAC960_V1_ReadControllerConfiguration;
2533 Controller->ReadDeviceConfiguration =
2534 DAC960_V1_ReadDeviceConfiguration;
2535 Controller->ReportDeviceConfiguration =
2536 DAC960_V1_ReportDeviceConfiguration;
2537 Controller->QueueReadWriteCommand =
2538 DAC960_V1_QueueReadWriteCommand;
2539 break;
2540 case DAC960_P_Controller:
2541 if (!request_region(Controller->IO_Address, 0x80,
2542 Controller->FullModelName)){
2543 DAC960_Error("IO port 0x%d busy for Controller at\n",
2544 Controller, Controller->IO_Address);
2545 goto Failure;
2546 }
2547 DAC960_PD_DisableInterrupts(BaseAddress);
2548 DAC960_PD_AcknowledgeStatus(BaseAddress);
2549 udelay(1000);
2550 while (DAC960_PD_InitializationInProgressP(BaseAddress))
2551 {
2552 if (DAC960_PD_ReadErrorStatus(BaseAddress, &ErrorStatus,
2553 &Parameter0, &Parameter1) &&
2554 DAC960_ReportErrorStatus(Controller, ErrorStatus,
2555 Parameter0, Parameter1))
2556 goto Failure1;
2557 udelay(10);
2558 }
2559 DAC960_PD_EnableInterrupts(Controller->BaseAddress);
2560 Controller->QueueCommand = DAC960_P_QueueCommand;
2561 Controller->ReadControllerConfiguration =
2562 DAC960_V1_ReadControllerConfiguration;
2563 Controller->ReadDeviceConfiguration =
2564 DAC960_V1_ReadDeviceConfiguration;
2565 Controller->ReportDeviceConfiguration =
2566 DAC960_V1_ReportDeviceConfiguration;
2567 Controller->QueueReadWriteCommand =
2568 DAC960_V1_QueueReadWriteCommand;
2569 break;
2570 }
2571 /*
2572 Acquire shared access to the IRQ Channel.
2573 */
2574 if (IRQ_Channel == 0)
2575 {
2576 DAC960_Error("IRQ Channel %d illegal for Controller at\n",
2577 Controller, IRQ_Channel);
2578 goto Failure1;
2579 }
2580 strcpy(Controller->FullModelName, "DAC960");
2581 if (request_irq(IRQ_Channel, InterruptHandler, SA_SHIRQ,
2582 Controller->FullModelName, Controller) < 0)
2583 {
2584 DAC960_Error("Unable to acquire IRQ Channel %d for Controller at\n",
2585 Controller, IRQ_Channel);
2586 goto Failure1;
2587 }
2588 Controller->IRQ_Channel = IRQ_Channel;
2589 DAC960_ActiveControllerCount++;
2590 Controller->InitialCommand.CommandIdentifier = 1;
2591 Controller->InitialCommand.Controller = Controller;
2592 Controller->Commands[0] = &Controller->InitialCommand;
2593 Controller->FreeCommands = &Controller->InitialCommand;
2594 Controller->ControllerDetectionSuccessful = true;
2595 continue;
2596 Failure1:
2597 if (Controller->IO_Address) release_region(Controller->IO_Address, 0x80);
2598 Failure:
2599 if (IO_Address == 0)
2600 DAC960_Error("PCI Bus %d Device %d Function %d I/O Address N/A "
2601 "PCI Address 0x%X\n", Controller,
2602 Bus, Device, Function, PCI_Address);
2603 else DAC960_Error("PCI Bus %d Device %d Function %d I/O Address "
2604 "0x%X PCI Address 0x%X\n", Controller,
2605 Bus, Device, Function, IO_Address, PCI_Address);
2606 if (Controller == NULL) break;
2607 if (Controller->MemoryMappedAddress != NULL)
2608 iounmap(Controller->MemoryMappedAddress);
2609 if (Controller->IRQ_Channel > 0)
2610 free_irq(IRQ_Channel, Controller);
2611 }
2612 }
2613
2614
2615 /*
2616 DAC960_SortControllers sorts the Controllers by PCI Bus and Device Number.
2617 */
2618
DAC960_SortControllers(void)2619 static void DAC960_SortControllers(void)
2620 {
2621 int ControllerNumber, LastInterchange, Bound, j;
2622 LastInterchange = DAC960_ControllerCount-1;
2623 while (LastInterchange > 0)
2624 {
2625 Bound = LastInterchange;
2626 LastInterchange = 0;
2627 for (j = 0; j < Bound; j++)
2628 {
2629 DAC960_Controller_T *Controller1 = DAC960_Controllers[j];
2630 DAC960_Controller_T *Controller2 = DAC960_Controllers[j+1];
2631 if (Controller1->Bus > Controller2->Bus ||
2632 (Controller1->Bus == Controller2->Bus &&
2633 (Controller1->Device > Controller2->Device)))
2634 {
2635 Controller2->ControllerNumber = j;
2636 DAC960_Controllers[j] = Controller2;
2637 Controller1->ControllerNumber = j+1;
2638 DAC960_Controllers[j+1] = Controller1;
2639 LastInterchange = j;
2640 }
2641 }
2642 }
2643 for (ControllerNumber = 0;
2644 ControllerNumber < DAC960_ControllerCount;
2645 ControllerNumber++)
2646 {
2647 DAC960_Controller_T *Controller = DAC960_Controllers[ControllerNumber];
2648 if (!Controller->ControllerDetectionSuccessful)
2649 {
2650 DAC960_Controllers[ControllerNumber] = NULL;
2651 kfree(Controller);
2652 }
2653 }
2654 }
2655
2656
2657 /*
2658 DAC960_InitializeController initializes Controller.
2659 */
2660
DAC960_InitializeController(DAC960_Controller_T * Controller)2661 static void DAC960_InitializeController(DAC960_Controller_T *Controller)
2662 {
2663 if (DAC960_ReadControllerConfiguration(Controller) &&
2664 DAC960_ReportControllerConfiguration(Controller) &&
2665 DAC960_CreateAuxiliaryStructures(Controller) &&
2666 DAC960_ReadDeviceConfiguration(Controller) &&
2667 DAC960_ReportDeviceConfiguration(Controller) &&
2668 DAC960_RegisterBlockDevice(Controller))
2669 {
2670 /*
2671 Initialize the Monitoring Timer.
2672 */
2673 init_timer(&Controller->MonitoringTimer);
2674 Controller->MonitoringTimer.expires =
2675 jiffies + DAC960_MonitoringTimerInterval;
2676 Controller->MonitoringTimer.data = (unsigned long) Controller;
2677 Controller->MonitoringTimer.function = DAC960_MonitoringTimerFunction;
2678 add_timer(&Controller->MonitoringTimer);
2679 Controller->ControllerInitialized = true;
2680 }
2681 else DAC960_FinalizeController(Controller);
2682 }
2683
2684
2685 /*
2686 DAC960_FinalizeController finalizes Controller.
2687 */
2688
DAC960_FinalizeController(DAC960_Controller_T * Controller)2689 static void DAC960_FinalizeController(DAC960_Controller_T *Controller)
2690 {
2691 if (Controller->ControllerInitialized)
2692 {
2693 del_timer(&Controller->MonitoringTimer);
2694 if (Controller->FirmwareType == DAC960_V1_Controller)
2695 {
2696 DAC960_Notice("Flushing Cache...", Controller);
2697 DAC960_V1_ExecuteType3(Controller, DAC960_V1_Flush, NULL);
2698 DAC960_Notice("done\n", Controller);
2699 switch (Controller->HardwareType)
2700 {
2701 case DAC960_LA_Controller:
2702 if (Controller->V1.DualModeMemoryMailboxInterface)
2703 free_pages(Controller->MemoryMailboxPagesAddress,
2704 Controller->MemoryMailboxPagesOrder);
2705 else DAC960_LA_SaveMemoryMailboxInfo(Controller);
2706 break;
2707 case DAC960_PG_Controller:
2708 if (Controller->V1.DualModeMemoryMailboxInterface)
2709 free_pages(Controller->MemoryMailboxPagesAddress,
2710 Controller->MemoryMailboxPagesOrder);
2711 else DAC960_PG_SaveMemoryMailboxInfo(Controller);
2712 break;
2713 case DAC960_PD_Controller:
2714 release_region(Controller->IO_Address, 0x80);
2715 break;
2716 default:
2717 break;
2718 }
2719 }
2720 else
2721 {
2722 DAC960_Notice("Flushing Cache...", Controller);
2723 DAC960_V2_DeviceOperation(Controller, DAC960_V2_PauseDevice,
2724 DAC960_V2_RAID_Controller);
2725 DAC960_Notice("done\n", Controller);
2726 free_pages(Controller->MemoryMailboxPagesAddress,
2727 Controller->MemoryMailboxPagesOrder);
2728 }
2729 }
2730 free_irq(Controller->IRQ_Channel, Controller);
2731 iounmap(Controller->MemoryMappedAddress);
2732 DAC960_UnregisterBlockDevice(Controller);
2733 DAC960_DestroyAuxiliaryStructures(Controller);
2734 DAC960_Controllers[Controller->ControllerNumber] = NULL;
2735 kfree(Controller);
2736 }
2737
2738
2739 /*
2740 DAC960_Initialize initializes the DAC960 Driver.
2741 */
2742
DAC960_Initialize(void)2743 static int DAC960_Initialize(void)
2744 {
2745 int ControllerNumber;
2746 DAC960_DetectControllers(DAC960_BA_Controller);
2747 DAC960_DetectControllers(DAC960_LP_Controller);
2748 DAC960_DetectControllers(DAC960_LA_Controller);
2749 DAC960_DetectControllers(DAC960_PG_Controller);
2750 DAC960_DetectControllers(DAC960_PD_Controller);
2751 DAC960_DetectControllers(DAC960_P_Controller);
2752 DAC960_SortControllers();
2753 if (DAC960_ActiveControllerCount == 0) return -ENODEV;
2754 for (ControllerNumber = 0;
2755 ControllerNumber < DAC960_ControllerCount;
2756 ControllerNumber++)
2757 {
2758 DAC960_Controller_T *Controller = DAC960_Controllers[ControllerNumber];
2759 int LogicalDriveNumber;
2760 if (Controller == NULL) continue;
2761 DAC960_InitializeController(Controller);
2762 DAC960_ComputeGenericDiskInfo(&Controller->GenericDiskInfo);
2763 for (LogicalDriveNumber = 0;
2764 LogicalDriveNumber < DAC960_MaxLogicalDrives;
2765 LogicalDriveNumber++)
2766 DAC960_RegisterDisk(Controller, LogicalDriveNumber);
2767 }
2768 DAC960_CreateProcEntries();
2769 register_reboot_notifier(&DAC960_NotifierBlock);
2770 return 0;
2771 }
2772
2773
2774 /*
2775 DAC960_Finalize finalizes the DAC960 Driver.
2776 */
2777
DAC960_Finalize(void)2778 static void DAC960_Finalize(void)
2779 {
2780 int ControllerNumber;
2781 if (DAC960_ActiveControllerCount == 0) return;
2782 for (ControllerNumber = 0;
2783 ControllerNumber < DAC960_ControllerCount;
2784 ControllerNumber++)
2785 if (DAC960_Controllers[ControllerNumber] != NULL)
2786 DAC960_FinalizeController(DAC960_Controllers[ControllerNumber]);
2787 DAC960_DestroyProcEntries();
2788 unregister_reboot_notifier(&DAC960_NotifierBlock);
2789 }
2790
2791
2792 /*
2793 DAC960_Notifier is the notifier for the DAC960 Driver.
2794 */
2795
DAC960_Notifier(NotifierBlock_T * NotifierBlock,unsigned long Event,void * Buffer)2796 static int DAC960_Notifier(NotifierBlock_T *NotifierBlock,
2797 unsigned long Event,
2798 void *Buffer)
2799 {
2800 if (!(Event == SYS_RESTART || Event == SYS_HALT || Event == SYS_POWER_OFF))
2801 return NOTIFY_DONE;
2802 DAC960_Finalize();
2803 return NOTIFY_OK;
2804 }
2805
2806
2807 /*
2808 DAC960_V1_QueueReadWriteCommand prepares and queues a Read/Write Command for
2809 DAC960 V1 Firmware Controllers.
2810 */
2811
DAC960_V1_QueueReadWriteCommand(DAC960_Command_T * Command)2812 static void DAC960_V1_QueueReadWriteCommand(DAC960_Command_T *Command)
2813 {
2814 DAC960_Controller_T *Controller = Command->Controller;
2815 DAC960_V1_CommandMailbox_T *CommandMailbox = &Command->V1.CommandMailbox;
2816 DAC960_V1_ClearCommand(Command);
2817 if (Command->SegmentCount == 1)
2818 {
2819 if (Command->CommandType == DAC960_ReadCommand)
2820 CommandMailbox->Type5.CommandOpcode = DAC960_V1_Read;
2821 else CommandMailbox->Type5.CommandOpcode = DAC960_V1_Write;
2822 CommandMailbox->Type5.LD.TransferLength = Command->BlockCount;
2823 CommandMailbox->Type5.LD.LogicalDriveNumber = Command->LogicalDriveNumber;
2824 CommandMailbox->Type5.LogicalBlockAddress = Command->BlockNumber;
2825 CommandMailbox->Type5.BusAddress =
2826 Virtual_to_Bus32(Command->RequestBuffer);
2827 }
2828 else
2829 {
2830 DAC960_V1_ScatterGatherSegment_T
2831 *ScatterGatherList = Command->V1.ScatterGatherList;
2832 BufferHeader_T *BufferHeader = Command->BufferHeader;
2833 char *LastDataEndPointer = NULL;
2834 int SegmentNumber = 0;
2835 if (Command->CommandType == DAC960_ReadCommand)
2836 CommandMailbox->Type5.CommandOpcode = DAC960_V1_ReadWithScatterGather;
2837 else
2838 CommandMailbox->Type5.CommandOpcode = DAC960_V1_WriteWithScatterGather;
2839 CommandMailbox->Type5.LD.TransferLength = Command->BlockCount;
2840 CommandMailbox->Type5.LD.LogicalDriveNumber = Command->LogicalDriveNumber;
2841 CommandMailbox->Type5.LogicalBlockAddress = Command->BlockNumber;
2842 CommandMailbox->Type5.BusAddress = Virtual_to_Bus32(ScatterGatherList);
2843 CommandMailbox->Type5.ScatterGatherCount = Command->SegmentCount;
2844 while (BufferHeader != NULL)
2845 {
2846 if (BufferHeader->b_data == LastDataEndPointer)
2847 {
2848 ScatterGatherList[SegmentNumber-1].SegmentByteCount +=
2849 BufferHeader->b_size;
2850 LastDataEndPointer += BufferHeader->b_size;
2851 }
2852 else
2853 {
2854 ScatterGatherList[SegmentNumber].SegmentDataPointer =
2855 Virtual_to_Bus32(BufferHeader->b_data);
2856 ScatterGatherList[SegmentNumber].SegmentByteCount =
2857 BufferHeader->b_size;
2858 LastDataEndPointer = BufferHeader->b_data + BufferHeader->b_size;
2859 if (SegmentNumber++ > Controller->DriverScatterGatherLimit)
2860 panic("DAC960: Scatter/Gather Segment Overflow\n");
2861 }
2862 BufferHeader = BufferHeader->b_reqnext;
2863 }
2864 if (SegmentNumber != Command->SegmentCount)
2865 panic("DAC960: SegmentNumber != SegmentCount\n");
2866 }
2867 DAC960_QueueCommand(Command);
2868 }
2869
2870
2871 /*
2872 DAC960_V2_QueueReadWriteCommand prepares and queues a Read/Write Command for
2873 DAC960 V2 Firmware Controllers.
2874 */
2875
DAC960_V2_QueueReadWriteCommand(DAC960_Command_T * Command)2876 static void DAC960_V2_QueueReadWriteCommand(DAC960_Command_T *Command)
2877 {
2878 DAC960_Controller_T *Controller = Command->Controller;
2879 DAC960_V2_CommandMailbox_T *CommandMailbox = &Command->V2.CommandMailbox;
2880 DAC960_V2_ClearCommand(Command);
2881 CommandMailbox->SCSI_10.CommandOpcode = DAC960_V2_SCSI_10;
2882 CommandMailbox->SCSI_10.CommandControlBits.DataTransferControllerToHost =
2883 (Command->CommandType == DAC960_ReadCommand);
2884 CommandMailbox->SCSI_10.DataTransferSize =
2885 Command->BlockCount << DAC960_BlockSizeBits;
2886 CommandMailbox->SCSI_10.RequestSenseBusAddress =
2887 Virtual_to_Bus64(&Command->V2.RequestSense);
2888 CommandMailbox->SCSI_10.PhysicalDevice =
2889 Controller->V2.LogicalDriveToVirtualDevice[Command->LogicalDriveNumber];
2890 CommandMailbox->SCSI_10.RequestSenseSize =
2891 sizeof(DAC960_SCSI_RequestSense_T);
2892 CommandMailbox->SCSI_10.CDBLength = 10;
2893 CommandMailbox->SCSI_10.SCSI_CDB[0] =
2894 (Command->CommandType == DAC960_ReadCommand ? 0x28 : 0x2A);
2895 CommandMailbox->SCSI_10.SCSI_CDB[2] = Command->BlockNumber >> 24;
2896 CommandMailbox->SCSI_10.SCSI_CDB[3] = Command->BlockNumber >> 16;
2897 CommandMailbox->SCSI_10.SCSI_CDB[4] = Command->BlockNumber >> 8;
2898 CommandMailbox->SCSI_10.SCSI_CDB[5] = Command->BlockNumber;
2899 CommandMailbox->SCSI_10.SCSI_CDB[7] = Command->BlockCount >> 8;
2900 CommandMailbox->SCSI_10.SCSI_CDB[8] = Command->BlockCount;
2901 if (Command->SegmentCount == 1)
2902 {
2903 CommandMailbox->SCSI_10.DataTransferMemoryAddress
2904 .ScatterGatherSegments[0]
2905 .SegmentDataPointer =
2906 Virtual_to_Bus64(Command->RequestBuffer);
2907 CommandMailbox->SCSI_10.DataTransferMemoryAddress
2908 .ScatterGatherSegments[0]
2909 .SegmentByteCount =
2910 CommandMailbox->SCSI_10.DataTransferSize;
2911 }
2912 else
2913 {
2914 DAC960_V2_ScatterGatherSegment_T
2915 *ScatterGatherList = Command->V2.ScatterGatherList;
2916 BufferHeader_T *BufferHeader = Command->BufferHeader;
2917 char *LastDataEndPointer = NULL;
2918 int SegmentNumber = 0;
2919 if (Command->SegmentCount > 2)
2920 {
2921 CommandMailbox->SCSI_10.CommandControlBits
2922 .AdditionalScatterGatherListMemory = true;
2923 CommandMailbox->SCSI_10.DataTransferMemoryAddress
2924 .ExtendedScatterGather.ScatterGatherList0Length =
2925 Command->SegmentCount;
2926 CommandMailbox->SCSI_10.DataTransferMemoryAddress
2927 .ExtendedScatterGather.ScatterGatherList0Address =
2928 Virtual_to_Bus64(ScatterGatherList);
2929 }
2930 else
2931 ScatterGatherList =
2932 CommandMailbox->SCSI_10.DataTransferMemoryAddress
2933 .ScatterGatherSegments;
2934 while (BufferHeader != NULL)
2935 {
2936 if (BufferHeader->b_data == LastDataEndPointer)
2937 {
2938 ScatterGatherList[SegmentNumber-1].SegmentByteCount +=
2939 BufferHeader->b_size;
2940 LastDataEndPointer += BufferHeader->b_size;
2941 }
2942 else
2943 {
2944 ScatterGatherList[SegmentNumber].SegmentDataPointer =
2945 Virtual_to_Bus64(BufferHeader->b_data);
2946 ScatterGatherList[SegmentNumber].SegmentByteCount =
2947 BufferHeader->b_size;
2948 LastDataEndPointer = BufferHeader->b_data + BufferHeader->b_size;
2949 if (SegmentNumber++ > Controller->DriverScatterGatherLimit)
2950 panic("DAC960: Scatter/Gather Segment Overflow\n");
2951 }
2952 BufferHeader = BufferHeader->b_reqnext;
2953 }
2954 if (SegmentNumber != Command->SegmentCount)
2955 panic("DAC960: SegmentNumber != SegmentCount\n");
2956 }
2957 DAC960_QueueCommand(Command);
2958 }
2959
2960
2961 /*
2962 DAC960_ProcessRequest attempts to remove one I/O Request from Controller's
2963 I/O Request Queue and queues it to the Controller. WaitForCommand is true if
2964 this function should wait for a Command to become available if necessary.
2965 This function returns true if an I/O Request was queued and false otherwise.
2966 */
2967
DAC960_ProcessRequest(DAC960_Controller_T * Controller,boolean WaitForCommand)2968 static boolean DAC960_ProcessRequest(DAC960_Controller_T *Controller,
2969 boolean WaitForCommand)
2970 {
2971 RequestQueue_T *RequestQueue = Controller->RequestQueue;
2972 ListHead_T *RequestQueueHead;
2973 IO_Request_T *Request;
2974 DAC960_Command_T *Command;
2975 if (RequestQueue == NULL) return false;
2976 RequestQueueHead = &RequestQueue->queue_head;
2977 while (true)
2978 {
2979 if (list_empty(RequestQueueHead)) return false;
2980 Request = blkdev_entry_next_request(RequestQueueHead);
2981 Command = DAC960_AllocateCommand(Controller);
2982 if (Command != NULL) break;
2983 if (!WaitForCommand) return false;
2984 DAC960_WaitForCommand(Controller);
2985 }
2986 if (Request->cmd == READ)
2987 Command->CommandType = DAC960_ReadCommand;
2988 else Command->CommandType = DAC960_WriteCommand;
2989 Command->Completion = Request->waiting;
2990 Command->LogicalDriveNumber = DAC960_LogicalDriveNumber(Request->rq_dev);
2991 Command->BlockNumber =
2992 Request->sector
2993 + Controller->GenericDiskInfo.part[MINOR(Request->rq_dev)].start_sect;
2994 Command->BlockCount = Request->nr_sectors;
2995 Command->SegmentCount = Request->nr_segments;
2996 Command->BufferHeader = Request->bh;
2997 Command->RequestBuffer = Request->buffer;
2998 blkdev_dequeue_request(Request);
2999 blkdev_release_request(Request);
3000 DAC960_QueueReadWriteCommand(Command);
3001 return true;
3002 }
3003
3004
3005 /*
3006 DAC960_ProcessRequests attempts to remove as many I/O Requests as possible
3007 from Controller's I/O Request Queue and queue them to the Controller.
3008 */
3009
DAC960_ProcessRequests(DAC960_Controller_T * Controller)3010 static inline void DAC960_ProcessRequests(DAC960_Controller_T *Controller)
3011 {
3012 int Counter = 0;
3013 while (DAC960_ProcessRequest(Controller, Counter++ == 0)) ;
3014 }
3015
3016
3017 /*
3018 DAC960_RequestFunction is the I/O Request Function for DAC960 Controllers.
3019 */
3020
DAC960_RequestFunction(RequestQueue_T * RequestQueue)3021 static void DAC960_RequestFunction(RequestQueue_T *RequestQueue)
3022 {
3023 DAC960_Controller_T *Controller =
3024 (DAC960_Controller_T *) RequestQueue->queuedata;
3025 ProcessorFlags_T ProcessorFlags;
3026 /*
3027 Acquire exclusive access to Controller.
3028 */
3029 DAC960_AcquireControllerLockRF(Controller, &ProcessorFlags);
3030 /*
3031 Process I/O Requests for Controller.
3032 */
3033 DAC960_ProcessRequests(Controller);
3034 /*
3035 Release exclusive access to Controller.
3036 */
3037 DAC960_ReleaseControllerLockRF(Controller, &ProcessorFlags);
3038 }
3039
3040
3041 /*
3042 DAC960_ProcessCompletedBuffer performs completion processing for an
3043 individual Buffer.
3044 */
3045
DAC960_ProcessCompletedBuffer(BufferHeader_T * BufferHeader,boolean SuccessfulIO)3046 static inline void DAC960_ProcessCompletedBuffer(BufferHeader_T *BufferHeader,
3047 boolean SuccessfulIO)
3048 {
3049 blk_finished_io(BufferHeader->b_size >> 9);
3050 BufferHeader->b_end_io(BufferHeader, SuccessfulIO);
3051 }
3052
3053
3054 /*
3055 DAC960_V1_ReadWriteError prints an appropriate error message for Command
3056 when an error occurs on a Read or Write operation.
3057 */
3058
DAC960_V1_ReadWriteError(DAC960_Command_T * Command)3059 static void DAC960_V1_ReadWriteError(DAC960_Command_T *Command)
3060 {
3061 DAC960_Controller_T *Controller = Command->Controller;
3062 unsigned char *CommandName = "UNKNOWN";
3063 switch (Command->CommandType)
3064 {
3065 case DAC960_ReadCommand:
3066 case DAC960_ReadRetryCommand:
3067 CommandName = "READ";
3068 break;
3069 case DAC960_WriteCommand:
3070 case DAC960_WriteRetryCommand:
3071 CommandName = "WRITE";
3072 break;
3073 case DAC960_MonitoringCommand:
3074 case DAC960_ImmediateCommand:
3075 case DAC960_QueuedCommand:
3076 break;
3077 }
3078 switch (Command->V1.CommandStatus)
3079 {
3080 case DAC960_V1_IrrecoverableDataError:
3081 DAC960_Error("Irrecoverable Data Error on %s:\n",
3082 Controller, CommandName);
3083 break;
3084 case DAC960_V1_LogicalDriveNonexistentOrOffline:
3085 DAC960_Error("Logical Drive Nonexistent or Offline on %s:\n",
3086 Controller, CommandName);
3087 break;
3088 case DAC960_V1_AccessBeyondEndOfLogicalDrive:
3089 DAC960_Error("Attempt to Access Beyond End of Logical Drive "
3090 "on %s:\n", Controller, CommandName);
3091 break;
3092 case DAC960_V1_BadDataEncountered:
3093 DAC960_Error("Bad Data Encountered on %s:\n", Controller, CommandName);
3094 break;
3095 default:
3096 DAC960_Error("Unexpected Error Status %04X on %s:\n",
3097 Controller, Command->V1.CommandStatus, CommandName);
3098 break;
3099 }
3100 DAC960_Error(" /dev/rd/c%dd%d: absolute blocks %u..%u\n",
3101 Controller, Controller->ControllerNumber,
3102 Command->LogicalDriveNumber, Command->BlockNumber,
3103 Command->BlockNumber + Command->BlockCount - 1);
3104 if (DAC960_PartitionNumber(Command->BufferHeader->b_rdev) > 0)
3105 DAC960_Error(" /dev/rd/c%dd%dp%d: relative blocks %u..%u\n",
3106 Controller, Controller->ControllerNumber,
3107 Command->LogicalDriveNumber,
3108 DAC960_PartitionNumber(Command->BufferHeader->b_rdev),
3109 Command->BufferHeader->b_rsector,
3110 Command->BufferHeader->b_rsector + Command->BlockCount - 1);
3111 }
3112
3113
3114 /*
3115 DAC960_V1_ProcessCompletedCommand performs completion processing for Command
3116 for DAC960 V1 Firmware Controllers.
3117 */
3118
DAC960_V1_ProcessCompletedCommand(DAC960_Command_T * Command)3119 static void DAC960_V1_ProcessCompletedCommand(DAC960_Command_T *Command)
3120 {
3121 DAC960_Controller_T *Controller = Command->Controller;
3122 DAC960_CommandType_T CommandType = Command->CommandType;
3123 DAC960_V1_CommandOpcode_T CommandOpcode =
3124 Command->V1.CommandMailbox.Common.CommandOpcode;
3125 DAC960_V1_CommandStatus_T CommandStatus = Command->V1.CommandStatus;
3126 BufferHeader_T *BufferHeader = Command->BufferHeader;
3127 if (CommandType == DAC960_ReadCommand ||
3128 CommandType == DAC960_WriteCommand)
3129 {
3130 if (CommandStatus == DAC960_V1_NormalCompletion)
3131 {
3132 /*
3133 Perform completion processing for all buffers in this I/O Request.
3134 */
3135 while (BufferHeader != NULL)
3136 {
3137 BufferHeader_T *NextBufferHeader = BufferHeader->b_reqnext;
3138 BufferHeader->b_reqnext = NULL;
3139 DAC960_ProcessCompletedBuffer(BufferHeader, true);
3140 BufferHeader = NextBufferHeader;
3141 }
3142 if (Command->Completion != NULL)
3143 {
3144 complete(Command->Completion);
3145 Command->Completion = NULL;
3146 }
3147 add_blkdev_randomness(DAC960_MAJOR + Controller->ControllerNumber);
3148 }
3149 else if ((CommandStatus == DAC960_V1_IrrecoverableDataError ||
3150 CommandStatus == DAC960_V1_BadDataEncountered) &&
3151 BufferHeader != NULL &&
3152 BufferHeader->b_reqnext != NULL)
3153 {
3154 DAC960_V1_CommandMailbox_T *CommandMailbox =
3155 &Command->V1.CommandMailbox;
3156 if (CommandType == DAC960_ReadCommand)
3157 {
3158 Command->CommandType = DAC960_ReadRetryCommand;
3159 CommandMailbox->Type5.CommandOpcode = DAC960_V1_Read;
3160 }
3161 else
3162 {
3163 Command->CommandType = DAC960_WriteRetryCommand;
3164 CommandMailbox->Type5.CommandOpcode = DAC960_V1_Write;
3165 }
3166 Command->BlockCount = BufferHeader->b_size >> DAC960_BlockSizeBits;
3167 CommandMailbox->Type5.LD.TransferLength = Command->BlockCount;
3168 CommandMailbox->Type5.BusAddress =
3169 Virtual_to_Bus32(BufferHeader->b_data);
3170 DAC960_QueueCommand(Command);
3171 return;
3172 }
3173 else
3174 {
3175 if (CommandStatus != DAC960_V1_LogicalDriveNonexistentOrOffline)
3176 DAC960_V1_ReadWriteError(Command);
3177 /*
3178 Perform completion processing for all buffers in this I/O Request.
3179 */
3180 while (BufferHeader != NULL)
3181 {
3182 BufferHeader_T *NextBufferHeader = BufferHeader->b_reqnext;
3183 BufferHeader->b_reqnext = NULL;
3184 DAC960_ProcessCompletedBuffer(BufferHeader, false);
3185 BufferHeader = NextBufferHeader;
3186 }
3187 if (Command->Completion != NULL)
3188 {
3189 complete(Command->Completion);
3190 Command->Completion = NULL;
3191 }
3192 }
3193 }
3194 else if (CommandType == DAC960_ReadRetryCommand ||
3195 CommandType == DAC960_WriteRetryCommand)
3196 {
3197 BufferHeader_T *NextBufferHeader = BufferHeader->b_reqnext;
3198 BufferHeader->b_reqnext = NULL;
3199 /*
3200 Perform completion processing for this single buffer.
3201 */
3202 if (CommandStatus == DAC960_V1_NormalCompletion)
3203 DAC960_ProcessCompletedBuffer(BufferHeader, true);
3204 else
3205 {
3206 if (CommandStatus != DAC960_V1_LogicalDriveNonexistentOrOffline)
3207 DAC960_V1_ReadWriteError(Command);
3208 DAC960_ProcessCompletedBuffer(BufferHeader, false);
3209 }
3210 if (NextBufferHeader != NULL)
3211 {
3212 DAC960_V1_CommandMailbox_T *CommandMailbox =
3213 &Command->V1.CommandMailbox;
3214 Command->BlockNumber +=
3215 BufferHeader->b_size >> DAC960_BlockSizeBits;
3216 Command->BlockCount =
3217 NextBufferHeader->b_size >> DAC960_BlockSizeBits;
3218 Command->BufferHeader = NextBufferHeader;
3219 CommandMailbox->Type5.LD.TransferLength = Command->BlockCount;
3220 CommandMailbox->Type5.LogicalBlockAddress = Command->BlockNumber;
3221 CommandMailbox->Type5.BusAddress =
3222 Virtual_to_Bus32(NextBufferHeader->b_data);
3223 DAC960_QueueCommand(Command);
3224 return;
3225 }
3226 }
3227 else if (CommandType == DAC960_MonitoringCommand ||
3228 CommandOpcode == DAC960_V1_Enquiry ||
3229 CommandOpcode == DAC960_V1_GetRebuildProgress)
3230 {
3231 if (CommandType != DAC960_MonitoringCommand)
3232 {
3233 if (CommandOpcode == DAC960_V1_Enquiry)
3234 memcpy(&Controller->V1.NewEnquiry,
3235 Bus32_to_Virtual(Command->V1.CommandMailbox
3236 .Type3.BusAddress),
3237 sizeof(DAC960_V1_Enquiry_T));
3238 else if (CommandOpcode == DAC960_V1_GetRebuildProgress)
3239 memcpy(&Controller->V1.RebuildProgress,
3240 Bus32_to_Virtual(Command->V1.CommandMailbox
3241 .Type3.BusAddress),
3242 sizeof(DAC960_V1_RebuildProgress_T));
3243 }
3244 if (CommandOpcode == DAC960_V1_Enquiry &&
3245 Controller->ControllerInitialized)
3246 {
3247 DAC960_V1_Enquiry_T *OldEnquiry = &Controller->V1.Enquiry;
3248 DAC960_V1_Enquiry_T *NewEnquiry = &Controller->V1.NewEnquiry;
3249 unsigned int OldCriticalLogicalDriveCount =
3250 OldEnquiry->CriticalLogicalDriveCount;
3251 unsigned int NewCriticalLogicalDriveCount =
3252 NewEnquiry->CriticalLogicalDriveCount;
3253 if (NewEnquiry->NumberOfLogicalDrives > Controller->LogicalDriveCount)
3254 {
3255 int LogicalDriveNumber = Controller->LogicalDriveCount - 1;
3256 while (++LogicalDriveNumber < NewEnquiry->NumberOfLogicalDrives)
3257 DAC960_Critical("Logical Drive %d (/dev/rd/c%dd%d) "
3258 "Now Exists\n", Controller,
3259 LogicalDriveNumber,
3260 Controller->ControllerNumber,
3261 LogicalDriveNumber);
3262 Controller->LogicalDriveCount = NewEnquiry->NumberOfLogicalDrives;
3263 DAC960_ComputeGenericDiskInfo(&Controller->GenericDiskInfo);
3264 }
3265 if (NewEnquiry->NumberOfLogicalDrives < Controller->LogicalDriveCount)
3266 {
3267 int LogicalDriveNumber = NewEnquiry->NumberOfLogicalDrives - 1;
3268 while (++LogicalDriveNumber < Controller->LogicalDriveCount)
3269 DAC960_Critical("Logical Drive %d (/dev/rd/c%dd%d) "
3270 "No Longer Exists\n", Controller,
3271 LogicalDriveNumber,
3272 Controller->ControllerNumber,
3273 LogicalDriveNumber);
3274 Controller->LogicalDriveCount = NewEnquiry->NumberOfLogicalDrives;
3275 DAC960_ComputeGenericDiskInfo(&Controller->GenericDiskInfo);
3276 }
3277 if (NewEnquiry->StatusFlags.DeferredWriteError !=
3278 OldEnquiry->StatusFlags.DeferredWriteError)
3279 DAC960_Critical("Deferred Write Error Flag is now %s\n", Controller,
3280 (NewEnquiry->StatusFlags.DeferredWriteError
3281 ? "TRUE" : "FALSE"));
3282 if ((NewCriticalLogicalDriveCount > 0 ||
3283 NewCriticalLogicalDriveCount != OldCriticalLogicalDriveCount) ||
3284 (NewEnquiry->OfflineLogicalDriveCount > 0 ||
3285 NewEnquiry->OfflineLogicalDriveCount !=
3286 OldEnquiry->OfflineLogicalDriveCount) ||
3287 (NewEnquiry->DeadDriveCount > 0 ||
3288 NewEnquiry->DeadDriveCount !=
3289 OldEnquiry->DeadDriveCount) ||
3290 (NewEnquiry->EventLogSequenceNumber !=
3291 OldEnquiry->EventLogSequenceNumber) ||
3292 Controller->MonitoringTimerCount == 0 ||
3293 (jiffies - Controller->SecondaryMonitoringTime
3294 >= DAC960_SecondaryMonitoringInterval))
3295 {
3296 Controller->V1.NeedLogicalDriveInformation = true;
3297 Controller->V1.NewEventLogSequenceNumber =
3298 NewEnquiry->EventLogSequenceNumber;
3299 Controller->V1.NeedErrorTableInformation = true;
3300 Controller->V1.NeedDeviceStateInformation = true;
3301 Controller->V1.StartDeviceStateScan = true;
3302 Controller->V1.NeedBackgroundInitializationStatus =
3303 Controller->V1.BackgroundInitializationStatusSupported;
3304 Controller->SecondaryMonitoringTime = jiffies;
3305 }
3306 if (NewEnquiry->RebuildFlag == DAC960_V1_StandbyRebuildInProgress ||
3307 NewEnquiry->RebuildFlag
3308 == DAC960_V1_BackgroundRebuildInProgress ||
3309 OldEnquiry->RebuildFlag == DAC960_V1_StandbyRebuildInProgress ||
3310 OldEnquiry->RebuildFlag == DAC960_V1_BackgroundRebuildInProgress)
3311 {
3312 Controller->V1.NeedRebuildProgress = true;
3313 Controller->V1.RebuildProgressFirst =
3314 (NewEnquiry->CriticalLogicalDriveCount <
3315 OldEnquiry->CriticalLogicalDriveCount);
3316 }
3317 if (OldEnquiry->RebuildFlag == DAC960_V1_BackgroundCheckInProgress)
3318 switch (NewEnquiry->RebuildFlag)
3319 {
3320 case DAC960_V1_NoStandbyRebuildOrCheckInProgress:
3321 DAC960_Progress("Consistency Check Completed Successfully\n",
3322 Controller);
3323 break;
3324 case DAC960_V1_StandbyRebuildInProgress:
3325 case DAC960_V1_BackgroundRebuildInProgress:
3326 break;
3327 case DAC960_V1_BackgroundCheckInProgress:
3328 Controller->V1.NeedConsistencyCheckProgress = true;
3329 break;
3330 case DAC960_V1_StandbyRebuildCompletedWithError:
3331 DAC960_Progress("Consistency Check Completed with Error\n",
3332 Controller);
3333 break;
3334 case DAC960_V1_BackgroundRebuildOrCheckFailed_DriveFailed:
3335 DAC960_Progress("Consistency Check Failed - "
3336 "Physical Device Failed\n", Controller);
3337 break;
3338 case DAC960_V1_BackgroundRebuildOrCheckFailed_LogicalDriveFailed:
3339 DAC960_Progress("Consistency Check Failed - "
3340 "Logical Drive Failed\n", Controller);
3341 break;
3342 case DAC960_V1_BackgroundRebuildOrCheckFailed_OtherCauses:
3343 DAC960_Progress("Consistency Check Failed - Other Causes\n",
3344 Controller);
3345 break;
3346 case DAC960_V1_BackgroundRebuildOrCheckSuccessfullyTerminated:
3347 DAC960_Progress("Consistency Check Successfully Terminated\n",
3348 Controller);
3349 break;
3350 }
3351 else if (NewEnquiry->RebuildFlag
3352 == DAC960_V1_BackgroundCheckInProgress)
3353 Controller->V1.NeedConsistencyCheckProgress = true;
3354 Controller->MonitoringAlertMode =
3355 (NewEnquiry->CriticalLogicalDriveCount > 0 ||
3356 NewEnquiry->OfflineLogicalDriveCount > 0 ||
3357 NewEnquiry->DeadDriveCount > 0);
3358 if (CommandType != DAC960_MonitoringCommand &&
3359 Controller->V1.RebuildFlagPending)
3360 {
3361 DAC960_V1_Enquiry_T *Enquiry = (DAC960_V1_Enquiry_T *)
3362 Bus32_to_Virtual(Command->V1.CommandMailbox.Type3.BusAddress);
3363 Enquiry->RebuildFlag = Controller->V1.PendingRebuildFlag;
3364 Controller->V1.RebuildFlagPending = false;
3365 }
3366 else if (CommandType == DAC960_MonitoringCommand &&
3367 NewEnquiry->RebuildFlag >
3368 DAC960_V1_BackgroundCheckInProgress)
3369 {
3370 Controller->V1.PendingRebuildFlag = NewEnquiry->RebuildFlag;
3371 Controller->V1.RebuildFlagPending = true;
3372 }
3373 memcpy(&Controller->V1.Enquiry, &Controller->V1.NewEnquiry,
3374 sizeof(DAC960_V1_Enquiry_T));
3375 }
3376 else if (CommandOpcode == DAC960_V1_PerformEventLogOperation)
3377 {
3378 static char
3379 *DAC960_EventMessages[] =
3380 { "killed because write recovery failed",
3381 "killed because of SCSI bus reset failure",
3382 "killed because of double check condition",
3383 "killed because it was removed",
3384 "killed because of gross error on SCSI chip",
3385 "killed because of bad tag returned from drive",
3386 "killed because of timeout on SCSI command",
3387 "killed because of reset SCSI command issued from system",
3388 "killed because busy or parity error count exceeded limit",
3389 "killed because of 'kill drive' command from system",
3390 "killed because of selection timeout",
3391 "killed due to SCSI phase sequence error",
3392 "killed due to unknown status" };
3393 DAC960_V1_EventLogEntry_T *EventLogEntry =
3394 &Controller->V1.EventLogEntry;
3395 if (EventLogEntry->SequenceNumber ==
3396 Controller->V1.OldEventLogSequenceNumber)
3397 {
3398 unsigned char SenseKey = EventLogEntry->SenseKey;
3399 unsigned char AdditionalSenseCode =
3400 EventLogEntry->AdditionalSenseCode;
3401 unsigned char AdditionalSenseCodeQualifier =
3402 EventLogEntry->AdditionalSenseCodeQualifier;
3403 if (SenseKey == DAC960_SenseKey_VendorSpecific &&
3404 AdditionalSenseCode == 0x80 &&
3405 AdditionalSenseCodeQualifier <
3406 sizeof(DAC960_EventMessages) / sizeof(char *))
3407 DAC960_Critical("Physical Device %d:%d %s\n", Controller,
3408 EventLogEntry->Channel,
3409 EventLogEntry->TargetID,
3410 DAC960_EventMessages[
3411 AdditionalSenseCodeQualifier]);
3412 else if (SenseKey == DAC960_SenseKey_UnitAttention &&
3413 AdditionalSenseCode == 0x29)
3414 {
3415 if (Controller->MonitoringTimerCount > 0)
3416 Controller->V1.DeviceResetCount[EventLogEntry->Channel]
3417 [EventLogEntry->TargetID]++;
3418 }
3419 else if (!(SenseKey == DAC960_SenseKey_NoSense ||
3420 (SenseKey == DAC960_SenseKey_NotReady &&
3421 AdditionalSenseCode == 0x04 &&
3422 (AdditionalSenseCodeQualifier == 0x01 ||
3423 AdditionalSenseCodeQualifier == 0x02))))
3424 {
3425 DAC960_Critical("Physical Device %d:%d Error Log: "
3426 "Sense Key = %X, ASC = %02X, ASCQ = %02X\n",
3427 Controller,
3428 EventLogEntry->Channel,
3429 EventLogEntry->TargetID,
3430 SenseKey,
3431 AdditionalSenseCode,
3432 AdditionalSenseCodeQualifier);
3433 DAC960_Critical("Physical Device %d:%d Error Log: "
3434 "Information = %02X%02X%02X%02X "
3435 "%02X%02X%02X%02X\n",
3436 Controller,
3437 EventLogEntry->Channel,
3438 EventLogEntry->TargetID,
3439 EventLogEntry->Information[0],
3440 EventLogEntry->Information[1],
3441 EventLogEntry->Information[2],
3442 EventLogEntry->Information[3],
3443 EventLogEntry->CommandSpecificInformation[0],
3444 EventLogEntry->CommandSpecificInformation[1],
3445 EventLogEntry->CommandSpecificInformation[2],
3446 EventLogEntry->CommandSpecificInformation[3]);
3447 }
3448 }
3449 Controller->V1.OldEventLogSequenceNumber++;
3450 }
3451 else if (CommandOpcode == DAC960_V1_GetErrorTable)
3452 {
3453 DAC960_V1_ErrorTable_T *OldErrorTable = &Controller->V1.ErrorTable;
3454 DAC960_V1_ErrorTable_T *NewErrorTable = &Controller->V1.NewErrorTable;
3455 int Channel, TargetID;
3456 for (Channel = 0; Channel < Controller->Channels; Channel++)
3457 for (TargetID = 0; TargetID < Controller->Targets; TargetID++)
3458 {
3459 DAC960_V1_ErrorTableEntry_T *NewErrorEntry =
3460 &NewErrorTable->ErrorTableEntries[Channel][TargetID];
3461 DAC960_V1_ErrorTableEntry_T *OldErrorEntry =
3462 &OldErrorTable->ErrorTableEntries[Channel][TargetID];
3463 if ((NewErrorEntry->ParityErrorCount !=
3464 OldErrorEntry->ParityErrorCount) ||
3465 (NewErrorEntry->SoftErrorCount !=
3466 OldErrorEntry->SoftErrorCount) ||
3467 (NewErrorEntry->HardErrorCount !=
3468 OldErrorEntry->HardErrorCount) ||
3469 (NewErrorEntry->MiscErrorCount !=
3470 OldErrorEntry->MiscErrorCount))
3471 DAC960_Critical("Physical Device %d:%d Errors: "
3472 "Parity = %d, Soft = %d, "
3473 "Hard = %d, Misc = %d\n",
3474 Controller, Channel, TargetID,
3475 NewErrorEntry->ParityErrorCount,
3476 NewErrorEntry->SoftErrorCount,
3477 NewErrorEntry->HardErrorCount,
3478 NewErrorEntry->MiscErrorCount);
3479 }
3480 memcpy(&Controller->V1.ErrorTable, &Controller->V1.NewErrorTable,
3481 sizeof(DAC960_V1_ErrorTable_T));
3482 }
3483 else if (CommandOpcode == DAC960_V1_GetDeviceState)
3484 {
3485 DAC960_V1_DeviceState_T *OldDeviceState =
3486 &Controller->V1.DeviceState[Controller->V1.DeviceStateChannel]
3487 [Controller->V1.DeviceStateTargetID];
3488 DAC960_V1_DeviceState_T *NewDeviceState =
3489 &Controller->V1.NewDeviceState;
3490 if (NewDeviceState->DeviceState != OldDeviceState->DeviceState)
3491 DAC960_Critical("Physical Device %d:%d is now %s\n", Controller,
3492 Controller->V1.DeviceStateChannel,
3493 Controller->V1.DeviceStateTargetID,
3494 (NewDeviceState->DeviceState
3495 == DAC960_V1_Device_Dead
3496 ? "DEAD"
3497 : NewDeviceState->DeviceState
3498 == DAC960_V1_Device_WriteOnly
3499 ? "WRITE-ONLY"
3500 : NewDeviceState->DeviceState
3501 == DAC960_V1_Device_Online
3502 ? "ONLINE" : "STANDBY"));
3503 if (OldDeviceState->DeviceState == DAC960_V1_Device_Dead &&
3504 NewDeviceState->DeviceState != DAC960_V1_Device_Dead)
3505 {
3506 Controller->V1.NeedDeviceInquiryInformation = true;
3507 Controller->V1.NeedDeviceSerialNumberInformation = true;
3508 Controller->V1.DeviceResetCount
3509 [Controller->V1.DeviceStateChannel]
3510 [Controller->V1.DeviceStateTargetID] = 0;
3511 }
3512 memcpy(OldDeviceState, NewDeviceState,
3513 sizeof(DAC960_V1_DeviceState_T));
3514 }
3515 else if (CommandOpcode == DAC960_V1_GetLogicalDriveInformation)
3516 {
3517 int LogicalDriveNumber;
3518 for (LogicalDriveNumber = 0;
3519 LogicalDriveNumber < Controller->LogicalDriveCount;
3520 LogicalDriveNumber++)
3521 {
3522 DAC960_V1_LogicalDriveInformation_T *OldLogicalDriveInformation =
3523 &Controller->V1.LogicalDriveInformation[LogicalDriveNumber];
3524 DAC960_V1_LogicalDriveInformation_T *NewLogicalDriveInformation =
3525 &Controller->V1.NewLogicalDriveInformation[LogicalDriveNumber];
3526 if (NewLogicalDriveInformation->LogicalDriveState !=
3527 OldLogicalDriveInformation->LogicalDriveState)
3528 DAC960_Critical("Logical Drive %d (/dev/rd/c%dd%d) "
3529 "is now %s\n", Controller,
3530 LogicalDriveNumber,
3531 Controller->ControllerNumber,
3532 LogicalDriveNumber,
3533 (NewLogicalDriveInformation->LogicalDriveState
3534 == DAC960_V1_LogicalDrive_Online
3535 ? "ONLINE"
3536 : NewLogicalDriveInformation->LogicalDriveState
3537 == DAC960_V1_LogicalDrive_Critical
3538 ? "CRITICAL" : "OFFLINE"));
3539 if (NewLogicalDriveInformation->WriteBack !=
3540 OldLogicalDriveInformation->WriteBack)
3541 DAC960_Critical("Logical Drive %d (/dev/rd/c%dd%d) "
3542 "is now %s\n", Controller,
3543 LogicalDriveNumber,
3544 Controller->ControllerNumber,
3545 LogicalDriveNumber,
3546 (NewLogicalDriveInformation->WriteBack
3547 ? "WRITE BACK" : "WRITE THRU"));
3548 }
3549 memcpy(&Controller->V1.LogicalDriveInformation,
3550 &Controller->V1.NewLogicalDriveInformation,
3551 sizeof(DAC960_V1_LogicalDriveInformationArray_T));
3552 }
3553 else if (CommandOpcode == DAC960_V1_GetRebuildProgress)
3554 {
3555 unsigned int LogicalDriveNumber =
3556 Controller->V1.RebuildProgress.LogicalDriveNumber;
3557 unsigned int LogicalDriveSize =
3558 Controller->V1.RebuildProgress.LogicalDriveSize;
3559 unsigned int BlocksCompleted =
3560 LogicalDriveSize - Controller->V1.RebuildProgress.RemainingBlocks;
3561 if (CommandStatus == DAC960_V1_NoRebuildOrCheckInProgress &&
3562 Controller->V1.LastRebuildStatus == DAC960_V1_NormalCompletion)
3563 CommandStatus = DAC960_V1_RebuildSuccessful;
3564 switch (CommandStatus)
3565 {
3566 case DAC960_V1_NormalCompletion:
3567 Controller->EphemeralProgressMessage = true;
3568 DAC960_Progress("Rebuild in Progress: "
3569 "Logical Drive %d (/dev/rd/c%dd%d) "
3570 "%d%% completed\n",
3571 Controller, LogicalDriveNumber,
3572 Controller->ControllerNumber,
3573 LogicalDriveNumber,
3574 (100 * (BlocksCompleted >> 7))
3575 / (LogicalDriveSize >> 7));
3576 Controller->EphemeralProgressMessage = false;
3577 break;
3578 case DAC960_V1_RebuildFailed_LogicalDriveFailure:
3579 DAC960_Progress("Rebuild Failed due to "
3580 "Logical Drive Failure\n", Controller);
3581 break;
3582 case DAC960_V1_RebuildFailed_BadBlocksOnOther:
3583 DAC960_Progress("Rebuild Failed due to "
3584 "Bad Blocks on Other Drives\n", Controller);
3585 break;
3586 case DAC960_V1_RebuildFailed_NewDriveFailed:
3587 DAC960_Progress("Rebuild Failed due to "
3588 "Failure of Drive Being Rebuilt\n", Controller);
3589 break;
3590 case DAC960_V1_NoRebuildOrCheckInProgress:
3591 break;
3592 case DAC960_V1_RebuildSuccessful:
3593 DAC960_Progress("Rebuild Completed Successfully\n", Controller);
3594 break;
3595 case DAC960_V1_RebuildSuccessfullyTerminated:
3596 DAC960_Progress("Rebuild Successfully Terminated\n", Controller);
3597 break;
3598 }
3599 Controller->V1.LastRebuildStatus = CommandStatus;
3600 if (CommandType != DAC960_MonitoringCommand &&
3601 Controller->V1.RebuildStatusPending)
3602 {
3603 Command->V1.CommandStatus = Controller->V1.PendingRebuildStatus;
3604 Controller->V1.RebuildStatusPending = false;
3605 }
3606 else if (CommandType == DAC960_MonitoringCommand &&
3607 CommandStatus != DAC960_V1_NormalCompletion &&
3608 CommandStatus != DAC960_V1_NoRebuildOrCheckInProgress)
3609 {
3610 Controller->V1.PendingRebuildStatus = CommandStatus;
3611 Controller->V1.RebuildStatusPending = true;
3612 }
3613 }
3614 else if (CommandOpcode == DAC960_V1_RebuildStat)
3615 {
3616 unsigned int LogicalDriveNumber =
3617 Controller->V1.RebuildProgress.LogicalDriveNumber;
3618 unsigned int LogicalDriveSize =
3619 Controller->V1.RebuildProgress.LogicalDriveSize;
3620 unsigned int BlocksCompleted =
3621 LogicalDriveSize - Controller->V1.RebuildProgress.RemainingBlocks;
3622 if (CommandStatus == DAC960_V1_NormalCompletion)
3623 {
3624 Controller->EphemeralProgressMessage = true;
3625 DAC960_Progress("Consistency Check in Progress: "
3626 "Logical Drive %d (/dev/rd/c%dd%d) "
3627 "%d%% completed\n",
3628 Controller, LogicalDriveNumber,
3629 Controller->ControllerNumber,
3630 LogicalDriveNumber,
3631 (100 * (BlocksCompleted >> 7))
3632 / (LogicalDriveSize >> 7));
3633 Controller->EphemeralProgressMessage = false;
3634 }
3635 }
3636 else if (CommandOpcode == DAC960_V1_BackgroundInitializationControl)
3637 {
3638 unsigned int LogicalDriveNumber =
3639 Controller->V1.BackgroundInitializationStatus.LogicalDriveNumber;
3640 unsigned int LogicalDriveSize =
3641 Controller->V1.BackgroundInitializationStatus.LogicalDriveSize;
3642 unsigned int BlocksCompleted =
3643 Controller->V1.BackgroundInitializationStatus.BlocksCompleted;
3644 switch (CommandStatus)
3645 {
3646 case DAC960_V1_NormalCompletion:
3647 switch (Controller->V1.BackgroundInitializationStatus.Status)
3648 {
3649 case DAC960_V1_BackgroundInitializationInvalid:
3650 break;
3651 case DAC960_V1_BackgroundInitializationStarted:
3652 DAC960_Progress("Background Initialization Started\n",
3653 Controller);
3654 break;
3655 case DAC960_V1_BackgroundInitializationInProgress:
3656 if (BlocksCompleted ==
3657 Controller->V1.LastBackgroundInitializationStatus
3658 .BlocksCompleted &&
3659 LogicalDriveNumber ==
3660 Controller->V1.LastBackgroundInitializationStatus
3661 .LogicalDriveNumber)
3662 break;
3663 Controller->EphemeralProgressMessage = true;
3664 DAC960_Progress("Background Initialization in Progress: "
3665 "Logical Drive %d (/dev/rd/c%dd%d) "
3666 "%d%% completed\n",
3667 Controller, LogicalDriveNumber,
3668 Controller->ControllerNumber,
3669 LogicalDriveNumber,
3670 (100 * (BlocksCompleted >> 7))
3671 / (LogicalDriveSize >> 7));
3672 Controller->EphemeralProgressMessage = false;
3673 break;
3674 case DAC960_V1_BackgroundInitializationSuspended:
3675 DAC960_Progress("Background Initialization Suspended\n",
3676 Controller);
3677 break;
3678 case DAC960_V1_BackgroundInitializationCancelled:
3679 DAC960_Progress("Background Initialization Cancelled\n",
3680 Controller);
3681 break;
3682 }
3683 memcpy(&Controller->V1.LastBackgroundInitializationStatus,
3684 &Controller->V1.BackgroundInitializationStatus,
3685 sizeof(DAC960_V1_BackgroundInitializationStatus_T));
3686 break;
3687 case DAC960_V1_BackgroundInitSuccessful:
3688 if (Controller->V1.BackgroundInitializationStatus.Status ==
3689 DAC960_V1_BackgroundInitializationInProgress)
3690 DAC960_Progress("Background Initialization "
3691 "Completed Successfully\n", Controller);
3692 Controller->V1.BackgroundInitializationStatus.Status =
3693 DAC960_V1_BackgroundInitializationInvalid;
3694 break;
3695 case DAC960_V1_BackgroundInitAborted:
3696 if (Controller->V1.BackgroundInitializationStatus.Status ==
3697 DAC960_V1_BackgroundInitializationInProgress)
3698 DAC960_Progress("Background Initialization Aborted\n",
3699 Controller);
3700 Controller->V1.BackgroundInitializationStatus.Status =
3701 DAC960_V1_BackgroundInitializationInvalid;
3702 break;
3703 case DAC960_V1_NoBackgroundInitInProgress:
3704 break;
3705 }
3706 }
3707 }
3708 if (CommandType == DAC960_MonitoringCommand)
3709 {
3710 if (Controller->V1.NewEventLogSequenceNumber
3711 - Controller->V1.OldEventLogSequenceNumber > 0)
3712 {
3713 Command->V1.CommandMailbox.Type3E.CommandOpcode =
3714 DAC960_V1_PerformEventLogOperation;
3715 Command->V1.CommandMailbox.Type3E.OperationType =
3716 DAC960_V1_GetEventLogEntry;
3717 Command->V1.CommandMailbox.Type3E.OperationQualifier = 1;
3718 Command->V1.CommandMailbox.Type3E.SequenceNumber =
3719 Controller->V1.OldEventLogSequenceNumber;
3720 Command->V1.CommandMailbox.Type3E.BusAddress =
3721 Virtual_to_Bus32(&Controller->V1.EventLogEntry);
3722 DAC960_QueueCommand(Command);
3723 return;
3724 }
3725 if (Controller->V1.NeedErrorTableInformation)
3726 {
3727 Controller->V1.NeedErrorTableInformation = false;
3728 Command->V1.CommandMailbox.Type3.CommandOpcode =
3729 DAC960_V1_GetErrorTable;
3730 Command->V1.CommandMailbox.Type3.BusAddress =
3731 Virtual_to_Bus32(&Controller->V1.NewErrorTable);
3732 DAC960_QueueCommand(Command);
3733 return;
3734 }
3735 if (Controller->V1.NeedRebuildProgress &&
3736 Controller->V1.RebuildProgressFirst)
3737 {
3738 Controller->V1.NeedRebuildProgress = false;
3739 Command->V1.CommandMailbox.Type3.CommandOpcode =
3740 DAC960_V1_GetRebuildProgress;
3741 Command->V1.CommandMailbox.Type3.BusAddress =
3742 Virtual_to_Bus32(&Controller->V1.RebuildProgress);
3743 DAC960_QueueCommand(Command);
3744 return;
3745 }
3746 if (Controller->V1.NeedDeviceStateInformation)
3747 {
3748 if (Controller->V1.NeedDeviceInquiryInformation)
3749 {
3750 DAC960_V1_DCDB_T *DCDB = &Controller->V1.MonitoringDCDB;
3751 DAC960_SCSI_Inquiry_T *InquiryStandardData =
3752 &Controller->V1.InquiryStandardData
3753 [Controller->V1.DeviceStateChannel]
3754 [Controller->V1.DeviceStateTargetID];
3755 InquiryStandardData->PeripheralDeviceType = 0x1F;
3756 Command->V1.CommandMailbox.Type3.CommandOpcode = DAC960_V1_DCDB;
3757 Command->V1.CommandMailbox.Type3.BusAddress =
3758 Virtual_to_Bus32(DCDB);
3759 DCDB->Channel = Controller->V1.DeviceStateChannel;
3760 DCDB->TargetID = Controller->V1.DeviceStateTargetID;
3761 DCDB->Direction = DAC960_V1_DCDB_DataTransferDeviceToSystem;
3762 DCDB->EarlyStatus = false;
3763 DCDB->Timeout = DAC960_V1_DCDB_Timeout_10_seconds;
3764 DCDB->NoAutomaticRequestSense = false;
3765 DCDB->DisconnectPermitted = true;
3766 DCDB->TransferLength = sizeof(DAC960_SCSI_Inquiry_T);
3767 DCDB->BusAddress = Virtual_to_Bus32(InquiryStandardData);
3768 DCDB->CDBLength = 6;
3769 DCDB->TransferLengthHigh4 = 0;
3770 DCDB->SenseLength = sizeof(DCDB->SenseData);
3771 DCDB->CDB[0] = 0x12; /* INQUIRY */
3772 DCDB->CDB[1] = 0; /* EVPD = 0 */
3773 DCDB->CDB[2] = 0; /* Page Code */
3774 DCDB->CDB[3] = 0; /* Reserved */
3775 DCDB->CDB[4] = sizeof(DAC960_SCSI_Inquiry_T);
3776 DCDB->CDB[5] = 0; /* Control */
3777 DAC960_QueueCommand(Command);
3778 Controller->V1.NeedDeviceInquiryInformation = false;
3779 return;
3780 }
3781 if (Controller->V1.NeedDeviceSerialNumberInformation)
3782 {
3783 DAC960_V1_DCDB_T *DCDB = &Controller->V1.MonitoringDCDB;
3784 DAC960_SCSI_Inquiry_UnitSerialNumber_T *InquiryUnitSerialNumber =
3785 &Controller->V1.InquiryUnitSerialNumber
3786 [Controller->V1.DeviceStateChannel]
3787 [Controller->V1.DeviceStateTargetID];
3788 InquiryUnitSerialNumber->PeripheralDeviceType = 0x1F;
3789 Command->V1.CommandMailbox.Type3.CommandOpcode = DAC960_V1_DCDB;
3790 Command->V1.CommandMailbox.Type3.BusAddress =
3791 Virtual_to_Bus32(DCDB);
3792 DCDB->Channel = Controller->V1.DeviceStateChannel;
3793 DCDB->TargetID = Controller->V1.DeviceStateTargetID;
3794 DCDB->Direction = DAC960_V1_DCDB_DataTransferDeviceToSystem;
3795 DCDB->EarlyStatus = false;
3796 DCDB->Timeout = DAC960_V1_DCDB_Timeout_10_seconds;
3797 DCDB->NoAutomaticRequestSense = false;
3798 DCDB->DisconnectPermitted = true;
3799 DCDB->TransferLength =
3800 sizeof(DAC960_SCSI_Inquiry_UnitSerialNumber_T);
3801 DCDB->BusAddress = Virtual_to_Bus32(InquiryUnitSerialNumber);
3802 DCDB->CDBLength = 6;
3803 DCDB->TransferLengthHigh4 = 0;
3804 DCDB->SenseLength = sizeof(DCDB->SenseData);
3805 DCDB->CDB[0] = 0x12; /* INQUIRY */
3806 DCDB->CDB[1] = 1; /* EVPD = 1 */
3807 DCDB->CDB[2] = 0x80; /* Page Code */
3808 DCDB->CDB[3] = 0; /* Reserved */
3809 DCDB->CDB[4] = sizeof(DAC960_SCSI_Inquiry_UnitSerialNumber_T);
3810 DCDB->CDB[5] = 0; /* Control */
3811 DAC960_QueueCommand(Command);
3812 Controller->V1.NeedDeviceSerialNumberInformation = false;
3813 return;
3814 }
3815 if (Controller->V1.StartDeviceStateScan)
3816 {
3817 Controller->V1.DeviceStateChannel = 0;
3818 Controller->V1.DeviceStateTargetID = 0;
3819 Controller->V1.StartDeviceStateScan = false;
3820 }
3821 else if (++Controller->V1.DeviceStateTargetID == Controller->Targets)
3822 {
3823 Controller->V1.DeviceStateChannel++;
3824 Controller->V1.DeviceStateTargetID = 0;
3825 }
3826 if (Controller->V1.DeviceStateChannel < Controller->Channels)
3827 {
3828 Controller->V1.NewDeviceState.DeviceState =
3829 DAC960_V1_Device_Dead;
3830 Command->V1.CommandMailbox.Type3D.CommandOpcode =
3831 DAC960_V1_GetDeviceState;
3832 Command->V1.CommandMailbox.Type3D.Channel =
3833 Controller->V1.DeviceStateChannel;
3834 Command->V1.CommandMailbox.Type3D.TargetID =
3835 Controller->V1.DeviceStateTargetID;
3836 Command->V1.CommandMailbox.Type3D.BusAddress =
3837 Virtual_to_Bus32(&Controller->V1.NewDeviceState);
3838 DAC960_QueueCommand(Command);
3839 return;
3840 }
3841 Controller->V1.NeedDeviceStateInformation = false;
3842 }
3843 if (Controller->V1.NeedLogicalDriveInformation)
3844 {
3845 Controller->V1.NeedLogicalDriveInformation = false;
3846 Command->V1.CommandMailbox.Type3.CommandOpcode =
3847 DAC960_V1_GetLogicalDriveInformation;
3848 Command->V1.CommandMailbox.Type3.BusAddress =
3849 Virtual_to_Bus32(&Controller->V1.NewLogicalDriveInformation);
3850 DAC960_QueueCommand(Command);
3851 return;
3852 }
3853 if (Controller->V1.NeedRebuildProgress)
3854 {
3855 Controller->V1.NeedRebuildProgress = false;
3856 Command->V1.CommandMailbox.Type3.CommandOpcode =
3857 DAC960_V1_GetRebuildProgress;
3858 Command->V1.CommandMailbox.Type3.BusAddress =
3859 Virtual_to_Bus32(&Controller->V1.RebuildProgress);
3860 DAC960_QueueCommand(Command);
3861 return;
3862 }
3863 if (Controller->V1.NeedConsistencyCheckProgress)
3864 {
3865 Controller->V1.NeedConsistencyCheckProgress = false;
3866 Command->V1.CommandMailbox.Type3.CommandOpcode =
3867 DAC960_V1_RebuildStat;
3868 Command->V1.CommandMailbox.Type3.BusAddress =
3869 Virtual_to_Bus32(&Controller->V1.RebuildProgress);
3870 DAC960_QueueCommand(Command);
3871 return;
3872 }
3873 if (Controller->V1.NeedBackgroundInitializationStatus)
3874 {
3875 Controller->V1.NeedBackgroundInitializationStatus = false;
3876 Command->V1.CommandMailbox.Type3B.CommandOpcode =
3877 DAC960_V1_BackgroundInitializationControl;
3878 Command->V1.CommandMailbox.Type3B.CommandOpcode2 = 0x20;
3879 Command->V1.CommandMailbox.Type3B.BusAddress =
3880 Virtual_to_Bus32(&Controller->V1.BackgroundInitializationStatus);
3881 DAC960_QueueCommand(Command);
3882 return;
3883 }
3884 Controller->MonitoringTimerCount++;
3885 Controller->MonitoringTimer.expires =
3886 jiffies + DAC960_MonitoringTimerInterval;
3887 add_timer(&Controller->MonitoringTimer);
3888 }
3889 if (CommandType == DAC960_ImmediateCommand)
3890 {
3891 complete(Command->Completion);
3892 Command->Completion = NULL;
3893 return;
3894 }
3895 if (CommandType == DAC960_QueuedCommand)
3896 {
3897 DAC960_V1_KernelCommand_T *KernelCommand = Command->V1.KernelCommand;
3898 KernelCommand->CommandStatus = Command->V1.CommandStatus;
3899 Command->V1.KernelCommand = NULL;
3900 if (CommandOpcode == DAC960_V1_DCDB)
3901 Controller->V1.DirectCommandActive[KernelCommand->DCDB->Channel]
3902 [KernelCommand->DCDB->TargetID] =
3903 false;
3904 DAC960_DeallocateCommand(Command);
3905 KernelCommand->CompletionFunction(KernelCommand);
3906 return;
3907 }
3908 /*
3909 Queue a Status Monitoring Command to the Controller using the just
3910 completed Command if one was deferred previously due to lack of a
3911 free Command when the Monitoring Timer Function was called.
3912 */
3913 if (Controller->MonitoringCommandDeferred)
3914 {
3915 Controller->MonitoringCommandDeferred = false;
3916 DAC960_V1_QueueMonitoringCommand(Command);
3917 return;
3918 }
3919 /*
3920 Deallocate the Command.
3921 */
3922 DAC960_DeallocateCommand(Command);
3923 /*
3924 Wake up any processes waiting on a free Command.
3925 */
3926 wake_up(&Controller->CommandWaitQueue);
3927 }
3928
3929
3930 /*
3931 DAC960_V2_ReadWriteError prints an appropriate error message for Command
3932 when an error occurs on a Read or Write operation.
3933 */
3934
DAC960_V2_ReadWriteError(DAC960_Command_T * Command)3935 static void DAC960_V2_ReadWriteError(DAC960_Command_T *Command)
3936 {
3937 DAC960_Controller_T *Controller = Command->Controller;
3938 unsigned char *SenseErrors[] = { "NO SENSE", "RECOVERED ERROR",
3939 "NOT READY", "MEDIUM ERROR",
3940 "HARDWARE ERROR", "ILLEGAL REQUEST",
3941 "UNIT ATTENTION", "DATA PROTECT",
3942 "BLANK CHECK", "VENDOR-SPECIFIC",
3943 "COPY ABORTED", "ABORTED COMMAND",
3944 "EQUAL", "VOLUME OVERFLOW",
3945 "MISCOMPARE", "RESERVED" };
3946 unsigned char *CommandName = "UNKNOWN";
3947 switch (Command->CommandType)
3948 {
3949 case DAC960_ReadCommand:
3950 case DAC960_ReadRetryCommand:
3951 CommandName = "READ";
3952 break;
3953 case DAC960_WriteCommand:
3954 case DAC960_WriteRetryCommand:
3955 CommandName = "WRITE";
3956 break;
3957 case DAC960_MonitoringCommand:
3958 case DAC960_ImmediateCommand:
3959 case DAC960_QueuedCommand:
3960 break;
3961 }
3962 DAC960_Error("Error Condition %s on %s:\n", Controller,
3963 SenseErrors[Command->V2.RequestSense.SenseKey], CommandName);
3964 DAC960_Error(" /dev/rd/c%dd%d: absolute blocks %u..%u\n",
3965 Controller, Controller->ControllerNumber,
3966 Command->LogicalDriveNumber, Command->BlockNumber,
3967 Command->BlockNumber + Command->BlockCount - 1);
3968 if (DAC960_PartitionNumber(Command->BufferHeader->b_rdev) > 0)
3969 DAC960_Error(" /dev/rd/c%dd%dp%d: relative blocks %u..%u\n",
3970 Controller, Controller->ControllerNumber,
3971 Command->LogicalDriveNumber,
3972 DAC960_PartitionNumber(Command->BufferHeader->b_rdev),
3973 Command->BufferHeader->b_rsector,
3974 Command->BufferHeader->b_rsector + Command->BlockCount - 1);
3975 }
3976
3977
3978 /*
3979 DAC960_V2_ReportEvent prints an appropriate message when a Controller Event
3980 occurs.
3981 */
3982
DAC960_V2_ReportEvent(DAC960_Controller_T * Controller,DAC960_V2_Event_T * Event)3983 static void DAC960_V2_ReportEvent(DAC960_Controller_T *Controller,
3984 DAC960_V2_Event_T *Event)
3985 {
3986 DAC960_SCSI_RequestSense_T *RequestSense =
3987 (DAC960_SCSI_RequestSense_T *) &Event->RequestSenseData;
3988 unsigned char MessageBuffer[DAC960_LineBufferSize];
3989 static struct { int EventCode; unsigned char *EventMessage; } EventList[] =
3990 { /* Physical Device Events (0x0000 - 0x007F) */
3991 { 0x0001, "P Online" },
3992 { 0x0002, "P Standby" },
3993 { 0x0005, "P Automatic Rebuild Started" },
3994 { 0x0006, "P Manual Rebuild Started" },
3995 { 0x0007, "P Rebuild Completed" },
3996 { 0x0008, "P Rebuild Cancelled" },
3997 { 0x0009, "P Rebuild Failed for Unknown Reasons" },
3998 { 0x000A, "P Rebuild Failed due to New Physical Device" },
3999 { 0x000B, "P Rebuild Failed due to Logical Drive Failure" },
4000 { 0x000C, "S Offline" },
4001 { 0x000D, "P Found" },
4002 { 0x000E, "P Removed" },
4003 { 0x000F, "P Unconfigured" },
4004 { 0x0010, "P Expand Capacity Started" },
4005 { 0x0011, "P Expand Capacity Completed" },
4006 { 0x0012, "P Expand Capacity Failed" },
4007 { 0x0013, "P Command Timed Out" },
4008 { 0x0014, "P Command Aborted" },
4009 { 0x0015, "P Command Retried" },
4010 { 0x0016, "P Parity Error" },
4011 { 0x0017, "P Soft Error" },
4012 { 0x0018, "P Miscellaneous Error" },
4013 { 0x0019, "P Reset" },
4014 { 0x001A, "P Active Spare Found" },
4015 { 0x001B, "P Warm Spare Found" },
4016 { 0x001C, "S Sense Data Received" },
4017 { 0x001D, "P Initialization Started" },
4018 { 0x001E, "P Initialization Completed" },
4019 { 0x001F, "P Initialization Failed" },
4020 { 0x0020, "P Initialization Cancelled" },
4021 { 0x0021, "P Failed because Write Recovery Failed" },
4022 { 0x0022, "P Failed because SCSI Bus Reset Failed" },
4023 { 0x0023, "P Failed because of Double Check Condition" },
4024 { 0x0024, "P Failed because Device Cannot Be Accessed" },
4025 { 0x0025, "P Failed because of Gross Error on SCSI Processor" },
4026 { 0x0026, "P Failed because of Bad Tag from Device" },
4027 { 0x0027, "P Failed because of Command Timeout" },
4028 { 0x0028, "P Failed because of System Reset" },
4029 { 0x0029, "P Failed because of Busy Status or Parity Error" },
4030 { 0x002A, "P Failed because Host Set Device to Failed State" },
4031 { 0x002B, "P Failed because of Selection Timeout" },
4032 { 0x002C, "P Failed because of SCSI Bus Phase Error" },
4033 { 0x002D, "P Failed because Device Returned Unknown Status" },
4034 { 0x002E, "P Failed because Device Not Ready" },
4035 { 0x002F, "P Failed because Device Not Found at Startup" },
4036 { 0x0030, "P Failed because COD Write Operation Failed" },
4037 { 0x0031, "P Failed because BDT Write Operation Failed" },
4038 { 0x0039, "P Missing at Startup" },
4039 { 0x003A, "P Start Rebuild Failed due to Physical Drive Too Small" },
4040 { 0x003C, "P Temporarily Offline Device Automatically Made Online" },
4041 { 0x003D, "P Standby Rebuild Started" },
4042 /* Logical Device Events (0x0080 - 0x00FF) */
4043 { 0x0080, "M Consistency Check Started" },
4044 { 0x0081, "M Consistency Check Completed" },
4045 { 0x0082, "M Consistency Check Cancelled" },
4046 { 0x0083, "M Consistency Check Completed With Errors" },
4047 { 0x0084, "M Consistency Check Failed due to Logical Drive Failure" },
4048 { 0x0085, "M Consistency Check Failed due to Physical Device Failure" },
4049 { 0x0086, "L Offline" },
4050 { 0x0087, "L Critical" },
4051 { 0x0088, "L Online" },
4052 { 0x0089, "M Automatic Rebuild Started" },
4053 { 0x008A, "M Manual Rebuild Started" },
4054 { 0x008B, "M Rebuild Completed" },
4055 { 0x008C, "M Rebuild Cancelled" },
4056 { 0x008D, "M Rebuild Failed for Unknown Reasons" },
4057 { 0x008E, "M Rebuild Failed due to New Physical Device" },
4058 { 0x008F, "M Rebuild Failed due to Logical Drive Failure" },
4059 { 0x0090, "M Initialization Started" },
4060 { 0x0091, "M Initialization Completed" },
4061 { 0x0092, "M Initialization Cancelled" },
4062 { 0x0093, "M Initialization Failed" },
4063 { 0x0094, "L Found" },
4064 { 0x0095, "L Deleted" },
4065 { 0x0096, "M Expand Capacity Started" },
4066 { 0x0097, "M Expand Capacity Completed" },
4067 { 0x0098, "M Expand Capacity Failed" },
4068 { 0x0099, "L Bad Block Found" },
4069 { 0x009A, "L Size Changed" },
4070 { 0x009B, "L Type Changed" },
4071 { 0x009C, "L Bad Data Block Found" },
4072 { 0x009E, "L Read of Data Block in BDT" },
4073 { 0x009F, "L Write Back Data for Disk Block Lost" },
4074 { 0x00A0, "L Temporarily Offline RAID-5/3 Drive Made Online" },
4075 { 0x00A1, "L Temporarily Offline RAID-6/1/0/7 Drive Made Online" },
4076 { 0x00A2, "L Standby Rebuild Started" },
4077 /* Fault Management Events (0x0100 - 0x017F) */
4078 { 0x0140, "E Fan %d Failed" },
4079 { 0x0141, "E Fan %d OK" },
4080 { 0x0142, "E Fan %d Not Present" },
4081 { 0x0143, "E Power Supply %d Failed" },
4082 { 0x0144, "E Power Supply %d OK" },
4083 { 0x0145, "E Power Supply %d Not Present" },
4084 { 0x0146, "E Temperature Sensor %d Temperature Exceeds Safe Limit" },
4085 { 0x0147, "E Temperature Sensor %d Temperature Exceeds Working Limit" },
4086 { 0x0148, "E Temperature Sensor %d Temperature Normal" },
4087 { 0x0149, "E Temperature Sensor %d Not Present" },
4088 { 0x014A, "E Enclosure Management Unit %d Access Critical" },
4089 { 0x014B, "E Enclosure Management Unit %d Access OK" },
4090 { 0x014C, "E Enclosure Management Unit %d Access Offline" },
4091 /* Controller Events (0x0180 - 0x01FF) */
4092 { 0x0181, "C Cache Write Back Error" },
4093 { 0x0188, "C Battery Backup Unit Found" },
4094 { 0x0189, "C Battery Backup Unit Charge Level Low" },
4095 { 0x018A, "C Battery Backup Unit Charge Level OK" },
4096 { 0x0193, "C Installation Aborted" },
4097 { 0x0195, "C Battery Backup Unit Physically Removed" },
4098 { 0x0196, "C Memory Error During Warm Boot" },
4099 { 0x019E, "C Memory Soft ECC Error Corrected" },
4100 { 0x019F, "C Memory Hard ECC Error Corrected" },
4101 { 0x01A2, "C Battery Backup Unit Failed" },
4102 { 0x01AB, "C Mirror Race Recovery Failed" },
4103 { 0x01AC, "C Mirror Race on Critical Drive" },
4104 /* Controller Internal Processor Events */
4105 { 0x0380, "C Internal Controller Hung" },
4106 { 0x0381, "C Internal Controller Firmware Breakpoint" },
4107 { 0x0390, "C Internal Controller i960 Processor Specific Error" },
4108 { 0x03A0, "C Internal Controller StrongARM Processor Specific Error" },
4109 { 0, "" } };
4110 int EventListIndex = 0, EventCode;
4111 unsigned char EventType, *EventMessage;
4112 if (Event->EventCode == 0x1C &&
4113 RequestSense->SenseKey == DAC960_SenseKey_VendorSpecific &&
4114 (RequestSense->AdditionalSenseCode == 0x80 ||
4115 RequestSense->AdditionalSenseCode == 0x81))
4116 Event->EventCode = ((RequestSense->AdditionalSenseCode - 0x80) << 8) |
4117 RequestSense->AdditionalSenseCodeQualifier;
4118 while (true)
4119 {
4120 EventCode = EventList[EventListIndex].EventCode;
4121 if (EventCode == Event->EventCode || EventCode == 0) break;
4122 EventListIndex++;
4123 }
4124 EventType = EventList[EventListIndex].EventMessage[0];
4125 EventMessage = &EventList[EventListIndex].EventMessage[2];
4126 if (EventCode == 0)
4127 {
4128 DAC960_Critical("Unknown Controller Event Code %04X\n",
4129 Controller, Event->EventCode);
4130 return;
4131 }
4132 switch (EventType)
4133 {
4134 case 'P':
4135 DAC960_Critical("Physical Device %d:%d %s\n", Controller,
4136 Event->Channel, Event->TargetID, EventMessage);
4137 break;
4138 case 'L':
4139 DAC960_Critical("Logical Drive %d (/dev/rd/c%dd%d) %s\n", Controller,
4140 Event->LogicalUnit, Controller->ControllerNumber,
4141 Event->LogicalUnit, EventMessage);
4142 break;
4143 case 'M':
4144 DAC960_Progress("Logical Drive %d (/dev/rd/c%dd%d) %s\n", Controller,
4145 Event->LogicalUnit, Controller->ControllerNumber,
4146 Event->LogicalUnit, EventMessage);
4147 break;
4148 case 'S':
4149 if (RequestSense->SenseKey == DAC960_SenseKey_NoSense ||
4150 (RequestSense->SenseKey == DAC960_SenseKey_NotReady &&
4151 RequestSense->AdditionalSenseCode == 0x04 &&
4152 (RequestSense->AdditionalSenseCodeQualifier == 0x01 ||
4153 RequestSense->AdditionalSenseCodeQualifier == 0x02)))
4154 break;
4155 DAC960_Critical("Physical Device %d:%d %s\n", Controller,
4156 Event->Channel, Event->TargetID, EventMessage);
4157 DAC960_Critical("Physical Device %d:%d Request Sense: "
4158 "Sense Key = %X, ASC = %02X, ASCQ = %02X\n",
4159 Controller,
4160 Event->Channel,
4161 Event->TargetID,
4162 RequestSense->SenseKey,
4163 RequestSense->AdditionalSenseCode,
4164 RequestSense->AdditionalSenseCodeQualifier);
4165 DAC960_Critical("Physical Device %d:%d Request Sense: "
4166 "Information = %02X%02X%02X%02X "
4167 "%02X%02X%02X%02X\n",
4168 Controller,
4169 Event->Channel,
4170 Event->TargetID,
4171 RequestSense->Information[0],
4172 RequestSense->Information[1],
4173 RequestSense->Information[2],
4174 RequestSense->Information[3],
4175 RequestSense->CommandSpecificInformation[0],
4176 RequestSense->CommandSpecificInformation[1],
4177 RequestSense->CommandSpecificInformation[2],
4178 RequestSense->CommandSpecificInformation[3]);
4179 break;
4180 case 'E':
4181 if (Controller->SuppressEnclosureMessages) break;
4182 sprintf(MessageBuffer, EventMessage, Event->LogicalUnit);
4183 DAC960_Critical("Enclosure %d %s\n", Controller,
4184 Event->TargetID, MessageBuffer);
4185 break;
4186 case 'C':
4187 DAC960_Critical("Controller %s\n", Controller, EventMessage);
4188 break;
4189 default:
4190 DAC960_Critical("Unknown Controller Event Code %04X\n",
4191 Controller, Event->EventCode);
4192 break;
4193 }
4194 }
4195
4196
4197 /*
4198 DAC960_V2_ReportProgress prints an appropriate progress message for
4199 Logical Device Long Operations.
4200 */
4201
DAC960_V2_ReportProgress(DAC960_Controller_T * Controller,unsigned char * MessageString,unsigned int LogicalDeviceNumber,unsigned long BlocksCompleted,unsigned long LogicalDeviceSize)4202 static void DAC960_V2_ReportProgress(DAC960_Controller_T *Controller,
4203 unsigned char *MessageString,
4204 unsigned int LogicalDeviceNumber,
4205 unsigned long BlocksCompleted,
4206 unsigned long LogicalDeviceSize)
4207 {
4208 Controller->EphemeralProgressMessage = true;
4209 DAC960_Progress("%s in Progress: Logical Drive %d (/dev/rd/c%dd%d) "
4210 "%d%% completed\n", Controller,
4211 MessageString,
4212 LogicalDeviceNumber,
4213 Controller->ControllerNumber,
4214 LogicalDeviceNumber,
4215 (100 * (BlocksCompleted >> 7)) / (LogicalDeviceSize >> 7));
4216 Controller->EphemeralProgressMessage = false;
4217 }
4218
4219
4220 /*
4221 DAC960_V2_ProcessCompletedCommand performs completion processing for Command
4222 for DAC960 V2 Firmware Controllers.
4223 */
4224
DAC960_V2_ProcessCompletedCommand(DAC960_Command_T * Command)4225 static void DAC960_V2_ProcessCompletedCommand(DAC960_Command_T *Command)
4226 {
4227 DAC960_Controller_T *Controller = Command->Controller;
4228 DAC960_CommandType_T CommandType = Command->CommandType;
4229 DAC960_V2_CommandMailbox_T *CommandMailbox = &Command->V2.CommandMailbox;
4230 DAC960_V2_IOCTL_Opcode_T CommandOpcode = CommandMailbox->Common.IOCTL_Opcode;
4231 DAC960_V2_CommandStatus_T CommandStatus = Command->V2.CommandStatus;
4232 BufferHeader_T *BufferHeader = Command->BufferHeader;
4233 if (CommandType == DAC960_ReadCommand ||
4234 CommandType == DAC960_WriteCommand)
4235 {
4236 if (CommandStatus == DAC960_V2_NormalCompletion)
4237 {
4238 /*
4239 Perform completion processing for all buffers in this I/O Request.
4240 */
4241 while (BufferHeader != NULL)
4242 {
4243 BufferHeader_T *NextBufferHeader = BufferHeader->b_reqnext;
4244 BufferHeader->b_reqnext = NULL;
4245 DAC960_ProcessCompletedBuffer(BufferHeader, true);
4246 BufferHeader = NextBufferHeader;
4247 }
4248 if (Command->Completion != NULL)
4249 {
4250 complete(Command->Completion);
4251 Command->Completion = NULL;
4252 }
4253 add_blkdev_randomness(DAC960_MAJOR + Controller->ControllerNumber);
4254 }
4255 else if (Command->V2.RequestSense.SenseKey
4256 == DAC960_SenseKey_MediumError &&
4257 BufferHeader != NULL &&
4258 BufferHeader->b_reqnext != NULL)
4259 {
4260 if (CommandType == DAC960_ReadCommand)
4261 Command->CommandType = DAC960_ReadRetryCommand;
4262 else Command->CommandType = DAC960_WriteRetryCommand;
4263 Command->BlockCount = BufferHeader->b_size >> DAC960_BlockSizeBits;
4264 CommandMailbox->SCSI_10.CommandControlBits
4265 .AdditionalScatterGatherListMemory = false;
4266 CommandMailbox->SCSI_10.DataTransferSize =
4267 Command->BlockCount << DAC960_BlockSizeBits;
4268 CommandMailbox->SCSI_10.DataTransferMemoryAddress
4269 .ScatterGatherSegments[0].SegmentDataPointer =
4270 Virtual_to_Bus64(BufferHeader->b_data);
4271 CommandMailbox->SCSI_10.DataTransferMemoryAddress
4272 .ScatterGatherSegments[0].SegmentByteCount =
4273 CommandMailbox->SCSI_10.DataTransferSize;
4274 CommandMailbox->SCSI_10.SCSI_CDB[7] = Command->BlockCount >> 8;
4275 CommandMailbox->SCSI_10.SCSI_CDB[8] = Command->BlockCount;
4276 DAC960_QueueCommand(Command);
4277 return;
4278 }
4279 else
4280 {
4281 if (Command->V2.RequestSense.SenseKey != DAC960_SenseKey_NotReady)
4282 DAC960_V2_ReadWriteError(Command);
4283 /*
4284 Perform completion processing for all buffers in this I/O Request.
4285 */
4286 while (BufferHeader != NULL)
4287 {
4288 BufferHeader_T *NextBufferHeader = BufferHeader->b_reqnext;
4289 BufferHeader->b_reqnext = NULL;
4290 DAC960_ProcessCompletedBuffer(BufferHeader, false);
4291 BufferHeader = NextBufferHeader;
4292 }
4293 if (Command->Completion != NULL)
4294 {
4295 complete(Command->Completion);
4296 Command->Completion = NULL;
4297 }
4298 }
4299 }
4300 else if (CommandType == DAC960_ReadRetryCommand ||
4301 CommandType == DAC960_WriteRetryCommand)
4302 {
4303 BufferHeader_T *NextBufferHeader = BufferHeader->b_reqnext;
4304 BufferHeader->b_reqnext = NULL;
4305 /*
4306 Perform completion processing for this single buffer.
4307 */
4308 if (CommandStatus == DAC960_V2_NormalCompletion)
4309 DAC960_ProcessCompletedBuffer(BufferHeader, true);
4310 else
4311 {
4312 if (Command->V2.RequestSense.SenseKey != DAC960_SenseKey_NotReady)
4313 DAC960_V2_ReadWriteError(Command);
4314 DAC960_ProcessCompletedBuffer(BufferHeader, false);
4315 }
4316 if (NextBufferHeader != NULL)
4317 {
4318 Command->BlockNumber +=
4319 BufferHeader->b_size >> DAC960_BlockSizeBits;
4320 Command->BlockCount =
4321 NextBufferHeader->b_size >> DAC960_BlockSizeBits;
4322 Command->BufferHeader = NextBufferHeader;
4323 CommandMailbox->SCSI_10.DataTransferSize =
4324 Command->BlockCount << DAC960_BlockSizeBits;
4325 CommandMailbox->SCSI_10.DataTransferMemoryAddress
4326 .ScatterGatherSegments[0]
4327 .SegmentDataPointer =
4328 Virtual_to_Bus64(NextBufferHeader->b_data);
4329 CommandMailbox->SCSI_10.DataTransferMemoryAddress
4330 .ScatterGatherSegments[0]
4331 .SegmentByteCount =
4332 CommandMailbox->SCSI_10.DataTransferSize;
4333 CommandMailbox->SCSI_10.SCSI_CDB[2] = Command->BlockNumber >> 24;
4334 CommandMailbox->SCSI_10.SCSI_CDB[3] = Command->BlockNumber >> 16;
4335 CommandMailbox->SCSI_10.SCSI_CDB[4] = Command->BlockNumber >> 8;
4336 CommandMailbox->SCSI_10.SCSI_CDB[5] = Command->BlockNumber;
4337 CommandMailbox->SCSI_10.SCSI_CDB[7] = Command->BlockCount >> 8;
4338 CommandMailbox->SCSI_10.SCSI_CDB[8] = Command->BlockCount;
4339 DAC960_QueueCommand(Command);
4340 return;
4341 }
4342 }
4343 else if (CommandType == DAC960_MonitoringCommand)
4344 {
4345 if (CommandOpcode == DAC960_V2_GetControllerInfo)
4346 {
4347 DAC960_V2_ControllerInfo_T *NewControllerInfo =
4348 &Controller->V2.NewControllerInformation;
4349 DAC960_V2_ControllerInfo_T *ControllerInfo =
4350 &Controller->V2.ControllerInformation;
4351 Controller->LogicalDriveCount =
4352 NewControllerInfo->LogicalDevicesPresent;
4353 Controller->V2.NeedLogicalDeviceInformation = true;
4354 Controller->V2.NeedPhysicalDeviceInformation = true;
4355 Controller->V2.StartLogicalDeviceInformationScan = true;
4356 Controller->V2.StartPhysicalDeviceInformationScan = true;
4357 Controller->MonitoringAlertMode =
4358 (NewControllerInfo->LogicalDevicesCritical > 0 ||
4359 NewControllerInfo->LogicalDevicesOffline > 0 ||
4360 NewControllerInfo->PhysicalDisksCritical > 0 ||
4361 NewControllerInfo->PhysicalDisksOffline > 0);
4362 memcpy(ControllerInfo, NewControllerInfo,
4363 sizeof(DAC960_V2_ControllerInfo_T));
4364 }
4365 else if (CommandOpcode == DAC960_V2_GetEvent)
4366 {
4367 if (CommandStatus == DAC960_V2_NormalCompletion)
4368 DAC960_V2_ReportEvent(Controller, &Controller->V2.Event);
4369 Controller->V2.NextEventSequenceNumber++;
4370 }
4371 else if (CommandOpcode == DAC960_V2_GetPhysicalDeviceInfoValid &&
4372 CommandStatus == DAC960_V2_NormalCompletion)
4373 {
4374 DAC960_V2_PhysicalDeviceInfo_T *NewPhysicalDeviceInfo =
4375 &Controller->V2.NewPhysicalDeviceInformation;
4376 unsigned int PhysicalDeviceIndex = Controller->V2.PhysicalDeviceIndex;
4377 DAC960_V2_PhysicalDeviceInfo_T *PhysicalDeviceInfo =
4378 Controller->V2.PhysicalDeviceInformation[PhysicalDeviceIndex];
4379 DAC960_SCSI_Inquiry_UnitSerialNumber_T *InquiryUnitSerialNumber =
4380 Controller->V2.InquiryUnitSerialNumber[PhysicalDeviceIndex];
4381 unsigned int DeviceIndex;
4382 while (PhysicalDeviceInfo != NULL &&
4383 (NewPhysicalDeviceInfo->Channel >
4384 PhysicalDeviceInfo->Channel ||
4385 (NewPhysicalDeviceInfo->Channel ==
4386 PhysicalDeviceInfo->Channel &&
4387 (NewPhysicalDeviceInfo->TargetID >
4388 PhysicalDeviceInfo->TargetID ||
4389 (NewPhysicalDeviceInfo->TargetID ==
4390 PhysicalDeviceInfo->TargetID &&
4391 NewPhysicalDeviceInfo->LogicalUnit >
4392 PhysicalDeviceInfo->LogicalUnit)))))
4393 {
4394 DAC960_Critical("Physical Device %d:%d No Longer Exists\n",
4395 Controller,
4396 PhysicalDeviceInfo->Channel,
4397 PhysicalDeviceInfo->TargetID);
4398 Controller->V2.PhysicalDeviceInformation
4399 [PhysicalDeviceIndex] = NULL;
4400 Controller->V2.InquiryUnitSerialNumber
4401 [PhysicalDeviceIndex] = NULL;
4402 kfree(PhysicalDeviceInfo);
4403 kfree(InquiryUnitSerialNumber);
4404 for (DeviceIndex = PhysicalDeviceIndex;
4405 DeviceIndex < DAC960_V2_MaxPhysicalDevices - 1;
4406 DeviceIndex++)
4407 {
4408 Controller->V2.PhysicalDeviceInformation[DeviceIndex] =
4409 Controller->V2.PhysicalDeviceInformation[DeviceIndex+1];
4410 Controller->V2.InquiryUnitSerialNumber[DeviceIndex] =
4411 Controller->V2.InquiryUnitSerialNumber[DeviceIndex+1];
4412 }
4413 Controller->V2.PhysicalDeviceInformation
4414 [DAC960_V2_MaxPhysicalDevices-1] = NULL;
4415 Controller->V2.InquiryUnitSerialNumber
4416 [DAC960_V2_MaxPhysicalDevices-1] = NULL;
4417 PhysicalDeviceInfo =
4418 Controller->V2.PhysicalDeviceInformation[PhysicalDeviceIndex];
4419 InquiryUnitSerialNumber =
4420 Controller->V2.InquiryUnitSerialNumber[PhysicalDeviceIndex];
4421 }
4422 if (PhysicalDeviceInfo == NULL ||
4423 (NewPhysicalDeviceInfo->Channel !=
4424 PhysicalDeviceInfo->Channel) ||
4425 (NewPhysicalDeviceInfo->TargetID !=
4426 PhysicalDeviceInfo->TargetID) ||
4427 (NewPhysicalDeviceInfo->LogicalUnit !=
4428 PhysicalDeviceInfo->LogicalUnit))
4429 {
4430 PhysicalDeviceInfo = (DAC960_V2_PhysicalDeviceInfo_T *)
4431 kmalloc(sizeof(DAC960_V2_PhysicalDeviceInfo_T), GFP_ATOMIC);
4432 InquiryUnitSerialNumber =
4433 (DAC960_SCSI_Inquiry_UnitSerialNumber_T *)
4434 kmalloc(sizeof(DAC960_SCSI_Inquiry_UnitSerialNumber_T),
4435 GFP_ATOMIC);
4436 if (InquiryUnitSerialNumber == NULL &&
4437 PhysicalDeviceInfo != NULL)
4438 {
4439 kfree(PhysicalDeviceInfo);
4440 PhysicalDeviceInfo = NULL;
4441 }
4442 DAC960_Critical("Physical Device %d:%d Now Exists%s\n",
4443 Controller,
4444 NewPhysicalDeviceInfo->Channel,
4445 NewPhysicalDeviceInfo->TargetID,
4446 (PhysicalDeviceInfo != NULL
4447 ? "" : " - Allocation Failed"));
4448 if (PhysicalDeviceInfo != NULL)
4449 {
4450 memset(PhysicalDeviceInfo, 0,
4451 sizeof(DAC960_V2_PhysicalDeviceInfo_T));
4452 PhysicalDeviceInfo->PhysicalDeviceState =
4453 DAC960_V2_Device_InvalidState;
4454 memset(InquiryUnitSerialNumber, 0,
4455 sizeof(DAC960_SCSI_Inquiry_UnitSerialNumber_T));
4456 InquiryUnitSerialNumber->PeripheralDeviceType = 0x1F;
4457 for (DeviceIndex = DAC960_V2_MaxPhysicalDevices - 1;
4458 DeviceIndex > PhysicalDeviceIndex;
4459 DeviceIndex--)
4460 {
4461 Controller->V2.PhysicalDeviceInformation[DeviceIndex] =
4462 Controller->V2.PhysicalDeviceInformation[DeviceIndex-1];
4463 Controller->V2.InquiryUnitSerialNumber[DeviceIndex] =
4464 Controller->V2.InquiryUnitSerialNumber[DeviceIndex-1];
4465 }
4466 Controller->V2.PhysicalDeviceInformation
4467 [PhysicalDeviceIndex] =
4468 PhysicalDeviceInfo;
4469 Controller->V2.InquiryUnitSerialNumber
4470 [PhysicalDeviceIndex] =
4471 InquiryUnitSerialNumber;
4472 Controller->V2.NeedDeviceSerialNumberInformation = true;
4473 }
4474 }
4475 if (PhysicalDeviceInfo != NULL)
4476 {
4477 if (NewPhysicalDeviceInfo->PhysicalDeviceState !=
4478 PhysicalDeviceInfo->PhysicalDeviceState)
4479 DAC960_Critical(
4480 "Physical Device %d:%d is now %s\n", Controller,
4481 NewPhysicalDeviceInfo->Channel,
4482 NewPhysicalDeviceInfo->TargetID,
4483 (NewPhysicalDeviceInfo->PhysicalDeviceState
4484 == DAC960_V2_Device_Online
4485 ? "ONLINE"
4486 : NewPhysicalDeviceInfo->PhysicalDeviceState
4487 == DAC960_V2_Device_Rebuild
4488 ? "REBUILD"
4489 : NewPhysicalDeviceInfo->PhysicalDeviceState
4490 == DAC960_V2_Device_Missing
4491 ? "MISSING"
4492 : NewPhysicalDeviceInfo->PhysicalDeviceState
4493 == DAC960_V2_Device_Critical
4494 ? "CRITICAL"
4495 : NewPhysicalDeviceInfo->PhysicalDeviceState
4496 == DAC960_V2_Device_Dead
4497 ? "DEAD"
4498 : NewPhysicalDeviceInfo->PhysicalDeviceState
4499 == DAC960_V2_Device_SuspectedDead
4500 ? "SUSPECTED-DEAD"
4501 : NewPhysicalDeviceInfo->PhysicalDeviceState
4502 == DAC960_V2_Device_CommandedOffline
4503 ? "COMMANDED-OFFLINE"
4504 : NewPhysicalDeviceInfo->PhysicalDeviceState
4505 == DAC960_V2_Device_Standby
4506 ? "STANDBY" : "UNKNOWN"));
4507 if ((NewPhysicalDeviceInfo->ParityErrors !=
4508 PhysicalDeviceInfo->ParityErrors) ||
4509 (NewPhysicalDeviceInfo->SoftErrors !=
4510 PhysicalDeviceInfo->SoftErrors) ||
4511 (NewPhysicalDeviceInfo->HardErrors !=
4512 PhysicalDeviceInfo->HardErrors) ||
4513 (NewPhysicalDeviceInfo->MiscellaneousErrors !=
4514 PhysicalDeviceInfo->MiscellaneousErrors) ||
4515 (NewPhysicalDeviceInfo->CommandTimeouts !=
4516 PhysicalDeviceInfo->CommandTimeouts) ||
4517 (NewPhysicalDeviceInfo->Retries !=
4518 PhysicalDeviceInfo->Retries) ||
4519 (NewPhysicalDeviceInfo->Aborts !=
4520 PhysicalDeviceInfo->Aborts) ||
4521 (NewPhysicalDeviceInfo->PredictedFailuresDetected !=
4522 PhysicalDeviceInfo->PredictedFailuresDetected))
4523 {
4524 DAC960_Critical("Physical Device %d:%d Errors: "
4525 "Parity = %d, Soft = %d, "
4526 "Hard = %d, Misc = %d\n",
4527 Controller,
4528 NewPhysicalDeviceInfo->Channel,
4529 NewPhysicalDeviceInfo->TargetID,
4530 NewPhysicalDeviceInfo->ParityErrors,
4531 NewPhysicalDeviceInfo->SoftErrors,
4532 NewPhysicalDeviceInfo->HardErrors,
4533 NewPhysicalDeviceInfo->MiscellaneousErrors);
4534 DAC960_Critical("Physical Device %d:%d Errors: "
4535 "Timeouts = %d, Retries = %d, "
4536 "Aborts = %d, Predicted = %d\n",
4537 Controller,
4538 NewPhysicalDeviceInfo->Channel,
4539 NewPhysicalDeviceInfo->TargetID,
4540 NewPhysicalDeviceInfo->CommandTimeouts,
4541 NewPhysicalDeviceInfo->Retries,
4542 NewPhysicalDeviceInfo->Aborts,
4543 NewPhysicalDeviceInfo
4544 ->PredictedFailuresDetected);
4545 }
4546 if ((PhysicalDeviceInfo->PhysicalDeviceState
4547 == DAC960_V2_Device_Dead ||
4548 PhysicalDeviceInfo->PhysicalDeviceState
4549 == DAC960_V2_Device_InvalidState) &&
4550 NewPhysicalDeviceInfo->PhysicalDeviceState
4551 != DAC960_V2_Device_Dead)
4552 Controller->V2.NeedDeviceSerialNumberInformation = true;
4553 memcpy(PhysicalDeviceInfo, NewPhysicalDeviceInfo,
4554 sizeof(DAC960_V2_PhysicalDeviceInfo_T));
4555 }
4556 NewPhysicalDeviceInfo->LogicalUnit++;
4557 Controller->V2.PhysicalDeviceIndex++;
4558 }
4559 else if (CommandOpcode == DAC960_V2_GetPhysicalDeviceInfoValid)
4560 {
4561 unsigned int DeviceIndex;
4562 for (DeviceIndex = Controller->V2.PhysicalDeviceIndex;
4563 DeviceIndex < DAC960_V2_MaxPhysicalDevices;
4564 DeviceIndex++)
4565 {
4566 DAC960_V2_PhysicalDeviceInfo_T *PhysicalDeviceInfo =
4567 Controller->V2.PhysicalDeviceInformation[DeviceIndex];
4568 DAC960_SCSI_Inquiry_UnitSerialNumber_T *InquiryUnitSerialNumber =
4569 Controller->V2.InquiryUnitSerialNumber[DeviceIndex];
4570 if (PhysicalDeviceInfo == NULL) break;
4571 DAC960_Critical("Physical Device %d:%d No Longer Exists\n",
4572 Controller,
4573 PhysicalDeviceInfo->Channel,
4574 PhysicalDeviceInfo->TargetID);
4575 Controller->V2.PhysicalDeviceInformation[DeviceIndex] = NULL;
4576 Controller->V2.InquiryUnitSerialNumber[DeviceIndex] = NULL;
4577 kfree(PhysicalDeviceInfo);
4578 kfree(InquiryUnitSerialNumber);
4579 }
4580 Controller->V2.NeedPhysicalDeviceInformation = false;
4581 }
4582 else if (CommandOpcode == DAC960_V2_GetLogicalDeviceInfoValid &&
4583 CommandStatus == DAC960_V2_NormalCompletion)
4584 {
4585 DAC960_V2_LogicalDeviceInfo_T *NewLogicalDeviceInfo =
4586 &Controller->V2.NewLogicalDeviceInformation;
4587 unsigned short LogicalDeviceNumber =
4588 NewLogicalDeviceInfo->LogicalDeviceNumber;
4589 DAC960_V2_LogicalDeviceInfo_T *LogicalDeviceInfo =
4590 Controller->V2.LogicalDeviceInformation[LogicalDeviceNumber];
4591 if (LogicalDeviceInfo == NULL)
4592 {
4593 DAC960_V2_PhysicalDevice_T PhysicalDevice;
4594 PhysicalDevice.Controller = 0;
4595 PhysicalDevice.Channel = NewLogicalDeviceInfo->Channel;
4596 PhysicalDevice.TargetID = NewLogicalDeviceInfo->TargetID;
4597 PhysicalDevice.LogicalUnit = NewLogicalDeviceInfo->LogicalUnit;
4598 Controller->V2.LogicalDriveToVirtualDevice[LogicalDeviceNumber] =
4599 PhysicalDevice;
4600 LogicalDeviceInfo = (DAC960_V2_LogicalDeviceInfo_T *)
4601 kmalloc(sizeof(DAC960_V2_LogicalDeviceInfo_T), GFP_ATOMIC);
4602 Controller->V2.LogicalDeviceInformation[LogicalDeviceNumber] =
4603 LogicalDeviceInfo;
4604 DAC960_Critical("Logical Drive %d (/dev/rd/c%dd%d) "
4605 "Now Exists%s\n", Controller,
4606 LogicalDeviceNumber,
4607 Controller->ControllerNumber,
4608 LogicalDeviceNumber,
4609 (LogicalDeviceInfo != NULL
4610 ? "" : " - Allocation Failed"));
4611 if (LogicalDeviceInfo != NULL)
4612 {
4613 memset(LogicalDeviceInfo, 0,
4614 sizeof(DAC960_V2_LogicalDeviceInfo_T));
4615 DAC960_ComputeGenericDiskInfo(&Controller->GenericDiskInfo);
4616 }
4617 }
4618 if (LogicalDeviceInfo != NULL)
4619 {
4620 unsigned long LogicalDeviceSize =
4621 NewLogicalDeviceInfo->ConfigurableDeviceSize;
4622 if (NewLogicalDeviceInfo->LogicalDeviceState !=
4623 LogicalDeviceInfo->LogicalDeviceState)
4624 DAC960_Critical("Logical Drive %d (/dev/rd/c%dd%d) "
4625 "is now %s\n", Controller,
4626 LogicalDeviceNumber,
4627 Controller->ControllerNumber,
4628 LogicalDeviceNumber,
4629 (NewLogicalDeviceInfo->LogicalDeviceState
4630 == DAC960_V2_LogicalDevice_Online
4631 ? "ONLINE"
4632 : NewLogicalDeviceInfo->LogicalDeviceState
4633 == DAC960_V2_LogicalDevice_Critical
4634 ? "CRITICAL" : "OFFLINE"));
4635 if ((NewLogicalDeviceInfo->SoftErrors !=
4636 LogicalDeviceInfo->SoftErrors) ||
4637 (NewLogicalDeviceInfo->CommandsFailed !=
4638 LogicalDeviceInfo->CommandsFailed) ||
4639 (NewLogicalDeviceInfo->DeferredWriteErrors !=
4640 LogicalDeviceInfo->DeferredWriteErrors))
4641 DAC960_Critical("Logical Drive %d (/dev/rd/c%dd%d) Errors: "
4642 "Soft = %d, Failed = %d, Deferred Write = %d\n",
4643 Controller, LogicalDeviceNumber,
4644 Controller->ControllerNumber,
4645 LogicalDeviceNumber,
4646 NewLogicalDeviceInfo->SoftErrors,
4647 NewLogicalDeviceInfo->CommandsFailed,
4648 NewLogicalDeviceInfo->DeferredWriteErrors);
4649 if (NewLogicalDeviceInfo->ConsistencyCheckInProgress)
4650 DAC960_V2_ReportProgress(Controller,
4651 "Consistency Check",
4652 LogicalDeviceNumber,
4653 NewLogicalDeviceInfo
4654 ->ConsistencyCheckBlockNumber,
4655 LogicalDeviceSize);
4656 else if (NewLogicalDeviceInfo->RebuildInProgress)
4657 DAC960_V2_ReportProgress(Controller,
4658 "Rebuild",
4659 LogicalDeviceNumber,
4660 NewLogicalDeviceInfo
4661 ->RebuildBlockNumber,
4662 LogicalDeviceSize);
4663 else if (NewLogicalDeviceInfo->BackgroundInitializationInProgress)
4664 DAC960_V2_ReportProgress(Controller,
4665 "Background Initialization",
4666 LogicalDeviceNumber,
4667 NewLogicalDeviceInfo
4668 ->BackgroundInitializationBlockNumber,
4669 LogicalDeviceSize);
4670 else if (NewLogicalDeviceInfo->ForegroundInitializationInProgress)
4671 DAC960_V2_ReportProgress(Controller,
4672 "Foreground Initialization",
4673 LogicalDeviceNumber,
4674 NewLogicalDeviceInfo
4675 ->ForegroundInitializationBlockNumber,
4676 LogicalDeviceSize);
4677 else if (NewLogicalDeviceInfo->DataMigrationInProgress)
4678 DAC960_V2_ReportProgress(Controller,
4679 "Data Migration",
4680 LogicalDeviceNumber,
4681 NewLogicalDeviceInfo
4682 ->DataMigrationBlockNumber,
4683 LogicalDeviceSize);
4684 else if (NewLogicalDeviceInfo->PatrolOperationInProgress)
4685 DAC960_V2_ReportProgress(Controller,
4686 "Patrol Operation",
4687 LogicalDeviceNumber,
4688 NewLogicalDeviceInfo
4689 ->PatrolOperationBlockNumber,
4690 LogicalDeviceSize);
4691 if (LogicalDeviceInfo->BackgroundInitializationInProgress &&
4692 !NewLogicalDeviceInfo->BackgroundInitializationInProgress)
4693 DAC960_Progress("Logical Drive %d (/dev/rd/c%dd%d) "
4694 "Background Initialization %s\n",
4695 Controller,
4696 LogicalDeviceNumber,
4697 Controller->ControllerNumber,
4698 LogicalDeviceNumber,
4699 (NewLogicalDeviceInfo->LogicalDeviceControl
4700 .LogicalDeviceInitialized
4701 ? "Completed" : "Failed"));
4702 memcpy(LogicalDeviceInfo, NewLogicalDeviceInfo,
4703 sizeof(DAC960_V2_LogicalDeviceInfo_T));
4704 }
4705 Controller->V2.LogicalDriveFoundDuringScan
4706 [LogicalDeviceNumber] = true;
4707 NewLogicalDeviceInfo->LogicalDeviceNumber++;
4708 }
4709 else if (CommandOpcode == DAC960_V2_GetLogicalDeviceInfoValid)
4710 {
4711 int LogicalDriveNumber;
4712 for (LogicalDriveNumber = 0;
4713 LogicalDriveNumber < DAC960_MaxLogicalDrives;
4714 LogicalDriveNumber++)
4715 {
4716 DAC960_V2_LogicalDeviceInfo_T *LogicalDeviceInfo =
4717 Controller->V2.LogicalDeviceInformation[LogicalDriveNumber];
4718 if (LogicalDeviceInfo == NULL ||
4719 Controller->V2.LogicalDriveFoundDuringScan
4720 [LogicalDriveNumber])
4721 continue;
4722 DAC960_Critical("Logical Drive %d (/dev/rd/c%dd%d) "
4723 "No Longer Exists\n", Controller,
4724 LogicalDriveNumber,
4725 Controller->ControllerNumber,
4726 LogicalDriveNumber);
4727 Controller->V2.LogicalDeviceInformation
4728 [LogicalDriveNumber] = NULL;
4729 kfree(LogicalDeviceInfo);
4730 Controller->LogicalDriveInitiallyAccessible
4731 [LogicalDriveNumber] = false;
4732 DAC960_ComputeGenericDiskInfo(&Controller->GenericDiskInfo);
4733 }
4734 Controller->V2.NeedLogicalDeviceInformation = false;
4735 }
4736 if (Controller->V2.HealthStatusBuffer->NextEventSequenceNumber
4737 - Controller->V2.NextEventSequenceNumber > 0)
4738 {
4739 CommandMailbox->GetEvent.CommandOpcode = DAC960_V2_IOCTL;
4740 CommandMailbox->GetEvent.DataTransferSize = sizeof(DAC960_V2_Event_T);
4741 CommandMailbox->GetEvent.EventSequenceNumberHigh16 =
4742 Controller->V2.NextEventSequenceNumber >> 16;
4743 CommandMailbox->GetEvent.ControllerNumber = 0;
4744 CommandMailbox->GetEvent.IOCTL_Opcode =
4745 DAC960_V2_GetEvent;
4746 CommandMailbox->GetEvent.EventSequenceNumberLow16 =
4747 Controller->V2.NextEventSequenceNumber & 0xFFFF;
4748 CommandMailbox->GetEvent.DataTransferMemoryAddress
4749 .ScatterGatherSegments[0]
4750 .SegmentDataPointer =
4751 Virtual_to_Bus64(&Controller->V2.Event);
4752 CommandMailbox->GetEvent.DataTransferMemoryAddress
4753 .ScatterGatherSegments[0]
4754 .SegmentByteCount =
4755 CommandMailbox->GetEvent.DataTransferSize;
4756 DAC960_QueueCommand(Command);
4757 return;
4758 }
4759 if (Controller->V2.NeedPhysicalDeviceInformation)
4760 {
4761 if (Controller->V2.NeedDeviceSerialNumberInformation)
4762 {
4763 DAC960_SCSI_Inquiry_UnitSerialNumber_T *InquiryUnitSerialNumber =
4764 Controller->V2.InquiryUnitSerialNumber
4765 [Controller->V2.PhysicalDeviceIndex - 1];
4766 InquiryUnitSerialNumber->PeripheralDeviceType = 0x1F;
4767 CommandMailbox->SCSI_10.CommandOpcode =
4768 DAC960_V2_SCSI_10_Passthru;
4769 CommandMailbox->SCSI_10.DataTransferSize =
4770 sizeof(DAC960_SCSI_Inquiry_UnitSerialNumber_T);
4771 CommandMailbox->SCSI_10.PhysicalDevice.LogicalUnit =
4772 Controller->V2.NewPhysicalDeviceInformation.LogicalUnit - 1;
4773 CommandMailbox->SCSI_10.PhysicalDevice.TargetID =
4774 Controller->V2.NewPhysicalDeviceInformation.TargetID;
4775 CommandMailbox->SCSI_10.PhysicalDevice.Channel =
4776 Controller->V2.NewPhysicalDeviceInformation.Channel;
4777 CommandMailbox->SCSI_10.CDBLength = 6;
4778 CommandMailbox->SCSI_10.SCSI_CDB[0] = 0x12; /* INQUIRY */
4779 CommandMailbox->SCSI_10.SCSI_CDB[1] = 1; /* EVPD = 1 */
4780 CommandMailbox->SCSI_10.SCSI_CDB[2] = 0x80; /* Page Code */
4781 CommandMailbox->SCSI_10.SCSI_CDB[3] = 0; /* Reserved */
4782 CommandMailbox->SCSI_10.SCSI_CDB[4] =
4783 sizeof(DAC960_SCSI_Inquiry_UnitSerialNumber_T);
4784 CommandMailbox->SCSI_10.SCSI_CDB[5] = 0; /* Control */
4785 CommandMailbox->SCSI_10.DataTransferMemoryAddress
4786 .ScatterGatherSegments[0]
4787 .SegmentDataPointer =
4788 Virtual_to_Bus64(InquiryUnitSerialNumber);
4789 CommandMailbox->SCSI_10.DataTransferMemoryAddress
4790 .ScatterGatherSegments[0]
4791 .SegmentByteCount =
4792 CommandMailbox->SCSI_10.DataTransferSize;
4793 DAC960_QueueCommand(Command);
4794 Controller->V2.NeedDeviceSerialNumberInformation = false;
4795 return;
4796 }
4797 if (Controller->V2.StartPhysicalDeviceInformationScan)
4798 {
4799 Controller->V2.PhysicalDeviceIndex = 0;
4800 Controller->V2.NewPhysicalDeviceInformation.Channel = 0;
4801 Controller->V2.NewPhysicalDeviceInformation.TargetID = 0;
4802 Controller->V2.NewPhysicalDeviceInformation.LogicalUnit = 0;
4803 Controller->V2.StartPhysicalDeviceInformationScan = false;
4804 }
4805 CommandMailbox->PhysicalDeviceInfo.CommandOpcode = DAC960_V2_IOCTL;
4806 CommandMailbox->PhysicalDeviceInfo.DataTransferSize =
4807 sizeof(DAC960_V2_PhysicalDeviceInfo_T);
4808 CommandMailbox->PhysicalDeviceInfo.PhysicalDevice.LogicalUnit =
4809 Controller->V2.NewPhysicalDeviceInformation.LogicalUnit;
4810 CommandMailbox->PhysicalDeviceInfo.PhysicalDevice.TargetID =
4811 Controller->V2.NewPhysicalDeviceInformation.TargetID;
4812 CommandMailbox->PhysicalDeviceInfo.PhysicalDevice.Channel =
4813 Controller->V2.NewPhysicalDeviceInformation.Channel;
4814 CommandMailbox->PhysicalDeviceInfo.IOCTL_Opcode =
4815 DAC960_V2_GetPhysicalDeviceInfoValid;
4816 CommandMailbox->PhysicalDeviceInfo.DataTransferMemoryAddress
4817 .ScatterGatherSegments[0]
4818 .SegmentDataPointer =
4819 Virtual_to_Bus64(&Controller->V2.NewPhysicalDeviceInformation);
4820 CommandMailbox->PhysicalDeviceInfo.DataTransferMemoryAddress
4821 .ScatterGatherSegments[0]
4822 .SegmentByteCount =
4823 CommandMailbox->PhysicalDeviceInfo.DataTransferSize;
4824 DAC960_QueueCommand(Command);
4825 return;
4826 }
4827 if (Controller->V2.NeedLogicalDeviceInformation)
4828 {
4829 if (Controller->V2.StartLogicalDeviceInformationScan)
4830 {
4831 int LogicalDriveNumber;
4832 for (LogicalDriveNumber = 0;
4833 LogicalDriveNumber < DAC960_MaxLogicalDrives;
4834 LogicalDriveNumber++)
4835 Controller->V2.LogicalDriveFoundDuringScan
4836 [LogicalDriveNumber] = false;
4837 Controller->V2.NewLogicalDeviceInformation
4838 .LogicalDeviceNumber = 0;
4839 Controller->V2.StartLogicalDeviceInformationScan = false;
4840 }
4841 CommandMailbox->LogicalDeviceInfo.CommandOpcode = DAC960_V2_IOCTL;
4842 CommandMailbox->LogicalDeviceInfo.DataTransferSize =
4843 sizeof(DAC960_V2_LogicalDeviceInfo_T);
4844 CommandMailbox->LogicalDeviceInfo.LogicalDevice.LogicalDeviceNumber =
4845 Controller->V2.NewLogicalDeviceInformation.LogicalDeviceNumber;
4846 CommandMailbox->LogicalDeviceInfo.IOCTL_Opcode =
4847 DAC960_V2_GetLogicalDeviceInfoValid;
4848 CommandMailbox->LogicalDeviceInfo.DataTransferMemoryAddress
4849 .ScatterGatherSegments[0]
4850 .SegmentDataPointer =
4851 Virtual_to_Bus64(&Controller->V2.NewLogicalDeviceInformation);
4852 CommandMailbox->LogicalDeviceInfo.DataTransferMemoryAddress
4853 .ScatterGatherSegments[0]
4854 .SegmentByteCount =
4855 CommandMailbox->LogicalDeviceInfo.DataTransferSize;
4856 DAC960_QueueCommand(Command);
4857 return;
4858 }
4859 Controller->MonitoringTimerCount++;
4860 Controller->MonitoringTimer.expires =
4861 jiffies + DAC960_HealthStatusMonitoringInterval;
4862 add_timer(&Controller->MonitoringTimer);
4863 }
4864 if (CommandType == DAC960_ImmediateCommand)
4865 {
4866 complete(Command->Completion);
4867 Command->Completion = NULL;
4868 return;
4869 }
4870 if (CommandType == DAC960_QueuedCommand)
4871 {
4872 DAC960_V2_KernelCommand_T *KernelCommand = Command->V2.KernelCommand;
4873 KernelCommand->CommandStatus = CommandStatus;
4874 KernelCommand->RequestSenseLength = Command->V2.RequestSenseLength;
4875 KernelCommand->DataTransferLength = Command->V2.DataTransferResidue;
4876 Command->V2.KernelCommand = NULL;
4877 DAC960_DeallocateCommand(Command);
4878 KernelCommand->CompletionFunction(KernelCommand);
4879 return;
4880 }
4881 /*
4882 Queue a Status Monitoring Command to the Controller using the just
4883 completed Command if one was deferred previously due to lack of a
4884 free Command when the Monitoring Timer Function was called.
4885 */
4886 if (Controller->MonitoringCommandDeferred)
4887 {
4888 Controller->MonitoringCommandDeferred = false;
4889 DAC960_V2_QueueMonitoringCommand(Command);
4890 return;
4891 }
4892 /*
4893 Deallocate the Command.
4894 */
4895 DAC960_DeallocateCommand(Command);
4896 /*
4897 Wake up any processes waiting on a free Command.
4898 */
4899 wake_up(&Controller->CommandWaitQueue);
4900 }
4901
4902
4903 /*
4904 DAC960_BA_InterruptHandler handles hardware interrupts from DAC960 BA Series
4905 Controllers.
4906 */
4907
DAC960_BA_InterruptHandler(int IRQ_Channel,void * DeviceIdentifier,Registers_T * InterruptRegisters)4908 static void DAC960_BA_InterruptHandler(int IRQ_Channel,
4909 void *DeviceIdentifier,
4910 Registers_T *InterruptRegisters)
4911 {
4912 DAC960_Controller_T *Controller = (DAC960_Controller_T *) DeviceIdentifier;
4913 void *ControllerBaseAddress = Controller->BaseAddress;
4914 DAC960_V2_StatusMailbox_T *NextStatusMailbox;
4915 ProcessorFlags_T ProcessorFlags;
4916 /*
4917 Acquire exclusive access to Controller.
4918 */
4919 DAC960_AcquireControllerLockIH(Controller, &ProcessorFlags);
4920 /*
4921 Process Hardware Interrupts for Controller.
4922 */
4923 DAC960_BA_AcknowledgeInterrupt(ControllerBaseAddress);
4924 NextStatusMailbox = Controller->V2.NextStatusMailbox;
4925 while (NextStatusMailbox->Fields.CommandIdentifier > 0)
4926 {
4927 DAC960_V2_CommandIdentifier_T CommandIdentifier =
4928 NextStatusMailbox->Fields.CommandIdentifier;
4929 DAC960_Command_T *Command = Controller->Commands[CommandIdentifier-1];
4930 Command->V2.CommandStatus = NextStatusMailbox->Fields.CommandStatus;
4931 Command->V2.RequestSenseLength =
4932 NextStatusMailbox->Fields.RequestSenseLength;
4933 Command->V2.DataTransferResidue =
4934 NextStatusMailbox->Fields.DataTransferResidue;
4935 NextStatusMailbox->Words[0] = 0;
4936 if (++NextStatusMailbox > Controller->V2.LastStatusMailbox)
4937 NextStatusMailbox = Controller->V2.FirstStatusMailbox;
4938 DAC960_V2_ProcessCompletedCommand(Command);
4939 }
4940 Controller->V2.NextStatusMailbox = NextStatusMailbox;
4941 /*
4942 Attempt to remove additional I/O Requests from the Controller's
4943 I/O Request Queue and queue them to the Controller.
4944 */
4945 while (DAC960_ProcessRequest(Controller, false)) ;
4946 /*
4947 Release exclusive access to Controller.
4948 */
4949 DAC960_ReleaseControllerLockIH(Controller, &ProcessorFlags);
4950 }
4951
4952
4953 /*
4954 DAC960_LP_InterruptHandler handles hardware interrupts from DAC960 LP Series
4955 Controllers.
4956 */
4957
DAC960_LP_InterruptHandler(int IRQ_Channel,void * DeviceIdentifier,Registers_T * InterruptRegisters)4958 static void DAC960_LP_InterruptHandler(int IRQ_Channel,
4959 void *DeviceIdentifier,
4960 Registers_T *InterruptRegisters)
4961 {
4962 DAC960_Controller_T *Controller = (DAC960_Controller_T *) DeviceIdentifier;
4963 void *ControllerBaseAddress = Controller->BaseAddress;
4964 DAC960_V2_StatusMailbox_T *NextStatusMailbox;
4965 ProcessorFlags_T ProcessorFlags;
4966 /*
4967 Acquire exclusive access to Controller.
4968 */
4969 DAC960_AcquireControllerLockIH(Controller, &ProcessorFlags);
4970 /*
4971 Process Hardware Interrupts for Controller.
4972 */
4973 DAC960_LP_AcknowledgeInterrupt(ControllerBaseAddress);
4974 NextStatusMailbox = Controller->V2.NextStatusMailbox;
4975 while (NextStatusMailbox->Fields.CommandIdentifier > 0)
4976 {
4977 DAC960_V2_CommandIdentifier_T CommandIdentifier =
4978 NextStatusMailbox->Fields.CommandIdentifier;
4979 DAC960_Command_T *Command = Controller->Commands[CommandIdentifier-1];
4980 Command->V2.CommandStatus = NextStatusMailbox->Fields.CommandStatus;
4981 Command->V2.RequestSenseLength =
4982 NextStatusMailbox->Fields.RequestSenseLength;
4983 Command->V2.DataTransferResidue =
4984 NextStatusMailbox->Fields.DataTransferResidue;
4985 NextStatusMailbox->Words[0] = 0;
4986 if (++NextStatusMailbox > Controller->V2.LastStatusMailbox)
4987 NextStatusMailbox = Controller->V2.FirstStatusMailbox;
4988 DAC960_V2_ProcessCompletedCommand(Command);
4989 }
4990 Controller->V2.NextStatusMailbox = NextStatusMailbox;
4991 /*
4992 Attempt to remove additional I/O Requests from the Controller's
4993 I/O Request Queue and queue them to the Controller.
4994 */
4995 while (DAC960_ProcessRequest(Controller, false)) ;
4996 /*
4997 Release exclusive access to Controller.
4998 */
4999 DAC960_ReleaseControllerLockIH(Controller, &ProcessorFlags);
5000 }
5001
5002
5003 /*
5004 DAC960_LA_InterruptHandler handles hardware interrupts from DAC960 LA Series
5005 Controllers.
5006 */
5007
DAC960_LA_InterruptHandler(int IRQ_Channel,void * DeviceIdentifier,Registers_T * InterruptRegisters)5008 static void DAC960_LA_InterruptHandler(int IRQ_Channel,
5009 void *DeviceIdentifier,
5010 Registers_T *InterruptRegisters)
5011 {
5012 DAC960_Controller_T *Controller = (DAC960_Controller_T *) DeviceIdentifier;
5013 void *ControllerBaseAddress = Controller->BaseAddress;
5014 DAC960_V1_StatusMailbox_T *NextStatusMailbox;
5015 ProcessorFlags_T ProcessorFlags;
5016 /*
5017 Acquire exclusive access to Controller.
5018 */
5019 DAC960_AcquireControllerLockIH(Controller, &ProcessorFlags);
5020 /*
5021 Process Hardware Interrupts for Controller.
5022 */
5023 DAC960_LA_AcknowledgeInterrupt(ControllerBaseAddress);
5024 NextStatusMailbox = Controller->V1.NextStatusMailbox;
5025 while (NextStatusMailbox->Fields.Valid)
5026 {
5027 DAC960_V1_CommandIdentifier_T CommandIdentifier =
5028 NextStatusMailbox->Fields.CommandIdentifier;
5029 DAC960_Command_T *Command = Controller->Commands[CommandIdentifier-1];
5030 Command->V1.CommandStatus = NextStatusMailbox->Fields.CommandStatus;
5031 NextStatusMailbox->Word = 0;
5032 if (++NextStatusMailbox > Controller->V1.LastStatusMailbox)
5033 NextStatusMailbox = Controller->V1.FirstStatusMailbox;
5034 DAC960_V1_ProcessCompletedCommand(Command);
5035 }
5036 Controller->V1.NextStatusMailbox = NextStatusMailbox;
5037 /*
5038 Attempt to remove additional I/O Requests from the Controller's
5039 I/O Request Queue and queue them to the Controller.
5040 */
5041 while (DAC960_ProcessRequest(Controller, false)) ;
5042 /*
5043 Release exclusive access to Controller.
5044 */
5045 DAC960_ReleaseControllerLockIH(Controller, &ProcessorFlags);
5046 }
5047
5048
5049 /*
5050 DAC960_PG_InterruptHandler handles hardware interrupts from DAC960 PG Series
5051 Controllers.
5052 */
5053
DAC960_PG_InterruptHandler(int IRQ_Channel,void * DeviceIdentifier,Registers_T * InterruptRegisters)5054 static void DAC960_PG_InterruptHandler(int IRQ_Channel,
5055 void *DeviceIdentifier,
5056 Registers_T *InterruptRegisters)
5057 {
5058 DAC960_Controller_T *Controller = (DAC960_Controller_T *) DeviceIdentifier;
5059 void *ControllerBaseAddress = Controller->BaseAddress;
5060 DAC960_V1_StatusMailbox_T *NextStatusMailbox;
5061 ProcessorFlags_T ProcessorFlags;
5062 /*
5063 Acquire exclusive access to Controller.
5064 */
5065 DAC960_AcquireControllerLockIH(Controller, &ProcessorFlags);
5066 /*
5067 Process Hardware Interrupts for Controller.
5068 */
5069 DAC960_PG_AcknowledgeInterrupt(ControllerBaseAddress);
5070 NextStatusMailbox = Controller->V1.NextStatusMailbox;
5071 while (NextStatusMailbox->Fields.Valid)
5072 {
5073 DAC960_V1_CommandIdentifier_T CommandIdentifier =
5074 NextStatusMailbox->Fields.CommandIdentifier;
5075 DAC960_Command_T *Command = Controller->Commands[CommandIdentifier-1];
5076 Command->V1.CommandStatus = NextStatusMailbox->Fields.CommandStatus;
5077 NextStatusMailbox->Word = 0;
5078 if (++NextStatusMailbox > Controller->V1.LastStatusMailbox)
5079 NextStatusMailbox = Controller->V1.FirstStatusMailbox;
5080 DAC960_V1_ProcessCompletedCommand(Command);
5081 }
5082 Controller->V1.NextStatusMailbox = NextStatusMailbox;
5083 /*
5084 Attempt to remove additional I/O Requests from the Controller's
5085 I/O Request Queue and queue them to the Controller.
5086 */
5087 while (DAC960_ProcessRequest(Controller, false)) ;
5088 /*
5089 Release exclusive access to Controller.
5090 */
5091 DAC960_ReleaseControllerLockIH(Controller, &ProcessorFlags);
5092 }
5093
5094
5095 /*
5096 DAC960_PD_InterruptHandler handles hardware interrupts from DAC960 PD Series
5097 Controllers.
5098 */
5099
DAC960_PD_InterruptHandler(int IRQ_Channel,void * DeviceIdentifier,Registers_T * InterruptRegisters)5100 static void DAC960_PD_InterruptHandler(int IRQ_Channel,
5101 void *DeviceIdentifier,
5102 Registers_T *InterruptRegisters)
5103 {
5104 DAC960_Controller_T *Controller = (DAC960_Controller_T *) DeviceIdentifier;
5105 void *ControllerBaseAddress = Controller->BaseAddress;
5106 ProcessorFlags_T ProcessorFlags;
5107 /*
5108 Acquire exclusive access to Controller.
5109 */
5110 DAC960_AcquireControllerLockIH(Controller, &ProcessorFlags);
5111 /*
5112 Process Hardware Interrupts for Controller.
5113 */
5114 while (DAC960_PD_StatusAvailableP(ControllerBaseAddress))
5115 {
5116 DAC960_V1_CommandIdentifier_T CommandIdentifier =
5117 DAC960_PD_ReadStatusCommandIdentifier(ControllerBaseAddress);
5118 DAC960_Command_T *Command = Controller->Commands[CommandIdentifier-1];
5119 Command->V1.CommandStatus =
5120 DAC960_PD_ReadStatusRegister(ControllerBaseAddress);
5121 DAC960_PD_AcknowledgeInterrupt(ControllerBaseAddress);
5122 DAC960_PD_AcknowledgeStatus(ControllerBaseAddress);
5123 DAC960_V1_ProcessCompletedCommand(Command);
5124 }
5125 /*
5126 Attempt to remove additional I/O Requests from the Controller's
5127 I/O Request Queue and queue them to the Controller.
5128 */
5129 while (DAC960_ProcessRequest(Controller, false)) ;
5130 /*
5131 Release exclusive access to Controller.
5132 */
5133 DAC960_ReleaseControllerLockIH(Controller, &ProcessorFlags);
5134 }
5135
5136
5137 /*
5138 DAC960_P_InterruptHandler handles hardware interrupts from DAC960 P Series
5139 Controllers.
5140 */
5141
DAC960_P_InterruptHandler(int IRQ_Channel,void * DeviceIdentifier,Registers_T * InterruptRegisters)5142 static void DAC960_P_InterruptHandler(int IRQ_Channel,
5143 void *DeviceIdentifier,
5144 Registers_T *InterruptRegisters)
5145 {
5146 DAC960_Controller_T *Controller = (DAC960_Controller_T *) DeviceIdentifier;
5147 void *ControllerBaseAddress = Controller->BaseAddress;
5148 ProcessorFlags_T ProcessorFlags;
5149 /*
5150 Acquire exclusive access to Controller.
5151 */
5152 DAC960_AcquireControllerLockIH(Controller, &ProcessorFlags);
5153 /*
5154 Process Hardware Interrupts for Controller.
5155 */
5156 while (DAC960_PD_StatusAvailableP(ControllerBaseAddress))
5157 {
5158 DAC960_V1_CommandIdentifier_T CommandIdentifier =
5159 DAC960_PD_ReadStatusCommandIdentifier(ControllerBaseAddress);
5160 DAC960_Command_T *Command = Controller->Commands[CommandIdentifier-1];
5161 DAC960_V1_CommandMailbox_T *CommandMailbox = &Command->V1.CommandMailbox;
5162 DAC960_V1_CommandOpcode_T CommandOpcode =
5163 CommandMailbox->Common.CommandOpcode;
5164 Command->V1.CommandStatus =
5165 DAC960_PD_ReadStatusRegister(ControllerBaseAddress);
5166 DAC960_PD_AcknowledgeInterrupt(ControllerBaseAddress);
5167 DAC960_PD_AcknowledgeStatus(ControllerBaseAddress);
5168 switch (CommandOpcode)
5169 {
5170 case DAC960_V1_Enquiry_Old:
5171 Command->V1.CommandMailbox.Common.CommandOpcode = DAC960_V1_Enquiry;
5172 DAC960_P_To_PD_TranslateEnquiry(
5173 Bus32_to_Virtual(CommandMailbox->Type3.BusAddress));
5174 break;
5175 case DAC960_V1_GetDeviceState_Old:
5176 Command->V1.CommandMailbox.Common.CommandOpcode =
5177 DAC960_V1_GetDeviceState;
5178 DAC960_P_To_PD_TranslateDeviceState(
5179 Bus32_to_Virtual(CommandMailbox->Type3.BusAddress));
5180 break;
5181 case DAC960_V1_Read_Old:
5182 Command->V1.CommandMailbox.Common.CommandOpcode = DAC960_V1_Read;
5183 DAC960_P_To_PD_TranslateReadWriteCommand(CommandMailbox);
5184 break;
5185 case DAC960_V1_Write_Old:
5186 Command->V1.CommandMailbox.Common.CommandOpcode = DAC960_V1_Write;
5187 DAC960_P_To_PD_TranslateReadWriteCommand(CommandMailbox);
5188 break;
5189 case DAC960_V1_ReadWithScatterGather_Old:
5190 Command->V1.CommandMailbox.Common.CommandOpcode =
5191 DAC960_V1_ReadWithScatterGather;
5192 DAC960_P_To_PD_TranslateReadWriteCommand(CommandMailbox);
5193 break;
5194 case DAC960_V1_WriteWithScatterGather_Old:
5195 Command->V1.CommandMailbox.Common.CommandOpcode =
5196 DAC960_V1_WriteWithScatterGather;
5197 DAC960_P_To_PD_TranslateReadWriteCommand(CommandMailbox);
5198 break;
5199 default:
5200 break;
5201 }
5202 DAC960_V1_ProcessCompletedCommand(Command);
5203 }
5204 /*
5205 Attempt to remove additional I/O Requests from the Controller's
5206 I/O Request Queue and queue them to the Controller.
5207 */
5208 while (DAC960_ProcessRequest(Controller, false)) ;
5209 /*
5210 Release exclusive access to Controller.
5211 */
5212 DAC960_ReleaseControllerLockIH(Controller, &ProcessorFlags);
5213 }
5214
5215
5216 /*
5217 DAC960_V1_QueueMonitoringCommand queues a Monitoring Command to DAC960 V1
5218 Firmware Controllers.
5219 */
5220
DAC960_V1_QueueMonitoringCommand(DAC960_Command_T * Command)5221 static void DAC960_V1_QueueMonitoringCommand(DAC960_Command_T *Command)
5222 {
5223 DAC960_Controller_T *Controller = Command->Controller;
5224 DAC960_V1_CommandMailbox_T *CommandMailbox = &Command->V1.CommandMailbox;
5225 DAC960_V1_ClearCommand(Command);
5226 Command->CommandType = DAC960_MonitoringCommand;
5227 CommandMailbox->Type3.CommandOpcode = DAC960_V1_Enquiry;
5228 CommandMailbox->Type3.BusAddress =
5229 Virtual_to_Bus32(&Controller->V1.NewEnquiry);
5230 DAC960_QueueCommand(Command);
5231 }
5232
5233
5234 /*
5235 DAC960_V2_QueueMonitoringCommand queues a Monitoring Command to DAC960 V2
5236 Firmware Controllers.
5237 */
5238
DAC960_V2_QueueMonitoringCommand(DAC960_Command_T * Command)5239 static void DAC960_V2_QueueMonitoringCommand(DAC960_Command_T *Command)
5240 {
5241 DAC960_Controller_T *Controller = Command->Controller;
5242 DAC960_V2_CommandMailbox_T *CommandMailbox = &Command->V2.CommandMailbox;
5243 DAC960_V2_ClearCommand(Command);
5244 Command->CommandType = DAC960_MonitoringCommand;
5245 CommandMailbox->ControllerInfo.CommandOpcode = DAC960_V2_IOCTL;
5246 CommandMailbox->ControllerInfo.CommandControlBits
5247 .DataTransferControllerToHost = true;
5248 CommandMailbox->ControllerInfo.CommandControlBits
5249 .NoAutoRequestSense = true;
5250 CommandMailbox->ControllerInfo.DataTransferSize =
5251 sizeof(DAC960_V2_ControllerInfo_T);
5252 CommandMailbox->ControllerInfo.ControllerNumber = 0;
5253 CommandMailbox->ControllerInfo.IOCTL_Opcode = DAC960_V2_GetControllerInfo;
5254 CommandMailbox->ControllerInfo.DataTransferMemoryAddress
5255 .ScatterGatherSegments[0]
5256 .SegmentDataPointer =
5257 Virtual_to_Bus64(&Controller->V2.NewControllerInformation);
5258 CommandMailbox->ControllerInfo.DataTransferMemoryAddress
5259 .ScatterGatherSegments[0]
5260 .SegmentByteCount =
5261 CommandMailbox->ControllerInfo.DataTransferSize;
5262 DAC960_QueueCommand(Command);
5263 }
5264
5265
5266 /*
5267 DAC960_MonitoringTimerFunction is the timer function for monitoring
5268 the status of DAC960 Controllers.
5269 */
5270
DAC960_MonitoringTimerFunction(unsigned long TimerData)5271 static void DAC960_MonitoringTimerFunction(unsigned long TimerData)
5272 {
5273 DAC960_Controller_T *Controller = (DAC960_Controller_T *) TimerData;
5274 DAC960_Command_T *Command;
5275 ProcessorFlags_T ProcessorFlags;
5276 if (Controller->FirmwareType == DAC960_V1_Controller)
5277 {
5278 /*
5279 Acquire exclusive access to Controller.
5280 */
5281 DAC960_AcquireControllerLock(Controller, &ProcessorFlags);
5282 /*
5283 Queue a Status Monitoring Command to Controller.
5284 */
5285 Command = DAC960_AllocateCommand(Controller);
5286 if (Command != NULL)
5287 DAC960_V1_QueueMonitoringCommand(Command);
5288 else Controller->MonitoringCommandDeferred = true;
5289 /*
5290 Release exclusive access to Controller.
5291 */
5292 DAC960_ReleaseControllerLock(Controller, &ProcessorFlags);
5293 }
5294 else
5295 {
5296 DAC960_V2_ControllerInfo_T *ControllerInfo =
5297 &Controller->V2.ControllerInformation;
5298 unsigned int StatusChangeCounter =
5299 Controller->V2.HealthStatusBuffer->StatusChangeCounter;
5300 boolean ForceMonitoringCommand = false;
5301 if (jiffies - Controller->SecondaryMonitoringTime
5302 > DAC960_SecondaryMonitoringInterval)
5303 {
5304 int LogicalDriveNumber;
5305 for (LogicalDriveNumber = 0;
5306 LogicalDriveNumber < DAC960_MaxLogicalDrives;
5307 LogicalDriveNumber++)
5308 {
5309 DAC960_V2_LogicalDeviceInfo_T *LogicalDeviceInfo =
5310 Controller->V2.LogicalDeviceInformation[LogicalDriveNumber];
5311 if (LogicalDeviceInfo == NULL) continue;
5312 if (!LogicalDeviceInfo->LogicalDeviceControl
5313 .LogicalDeviceInitialized)
5314 {
5315 ForceMonitoringCommand = true;
5316 break;
5317 }
5318 }
5319 Controller->SecondaryMonitoringTime = jiffies;
5320 }
5321 if (StatusChangeCounter == Controller->V2.StatusChangeCounter &&
5322 Controller->V2.HealthStatusBuffer->NextEventSequenceNumber
5323 == Controller->V2.NextEventSequenceNumber &&
5324 (ControllerInfo->BackgroundInitializationsActive +
5325 ControllerInfo->LogicalDeviceInitializationsActive +
5326 ControllerInfo->PhysicalDeviceInitializationsActive +
5327 ControllerInfo->ConsistencyChecksActive +
5328 ControllerInfo->RebuildsActive +
5329 ControllerInfo->OnlineExpansionsActive == 0 ||
5330 jiffies - Controller->PrimaryMonitoringTime
5331 < DAC960_MonitoringTimerInterval) &&
5332 !ForceMonitoringCommand)
5333 {
5334 Controller->MonitoringTimer.expires =
5335 jiffies + DAC960_HealthStatusMonitoringInterval;
5336 add_timer(&Controller->MonitoringTimer);
5337 return;
5338 }
5339 Controller->V2.StatusChangeCounter = StatusChangeCounter;
5340 Controller->PrimaryMonitoringTime = jiffies;
5341 /*
5342 Acquire exclusive access to Controller.
5343 */
5344 DAC960_AcquireControllerLock(Controller, &ProcessorFlags);
5345 /*
5346 Queue a Status Monitoring Command to Controller.
5347 */
5348 Command = DAC960_AllocateCommand(Controller);
5349 if (Command != NULL)
5350 DAC960_V2_QueueMonitoringCommand(Command);
5351 else Controller->MonitoringCommandDeferred = true;
5352 /*
5353 Release exclusive access to Controller.
5354 */
5355 DAC960_ReleaseControllerLock(Controller, &ProcessorFlags);
5356 /*
5357 Wake up any processes waiting on a Health Status Buffer change.
5358 */
5359 wake_up(&Controller->HealthStatusWaitQueue);
5360 }
5361 }
5362
5363
5364 /*
5365 DAC960_Open is the Device Open Function for the DAC960 Driver.
5366 */
5367
DAC960_Open(Inode_T * Inode,File_T * File)5368 static int DAC960_Open(Inode_T *Inode, File_T *File)
5369 {
5370 int ControllerNumber = DAC960_ControllerNumber(Inode->i_rdev);
5371 int LogicalDriveNumber = DAC960_LogicalDriveNumber(Inode->i_rdev);
5372 DAC960_Controller_T *Controller;
5373 if (ControllerNumber == 0 && LogicalDriveNumber == 0 &&
5374 (File->f_flags & O_NONBLOCK))
5375 goto ModuleOnly;
5376 if (ControllerNumber < 0 || ControllerNumber > DAC960_ControllerCount - 1)
5377 return -ENXIO;
5378 Controller = DAC960_Controllers[ControllerNumber];
5379 if (Controller == NULL) return -ENXIO;
5380 if (Controller->FirmwareType == DAC960_V1_Controller)
5381 {
5382 if (LogicalDriveNumber > Controller->LogicalDriveCount - 1)
5383 return -ENXIO;
5384 if (Controller->V1.LogicalDriveInformation
5385 [LogicalDriveNumber].LogicalDriveState
5386 == DAC960_V1_LogicalDrive_Offline)
5387 return -ENXIO;
5388 }
5389 else
5390 {
5391 DAC960_V2_LogicalDeviceInfo_T *LogicalDeviceInfo =
5392 Controller->V2.LogicalDeviceInformation[LogicalDriveNumber];
5393 if (LogicalDeviceInfo == NULL ||
5394 LogicalDeviceInfo->LogicalDeviceState
5395 == DAC960_V2_LogicalDevice_Offline)
5396 return -ENXIO;
5397 }
5398 if (!Controller->LogicalDriveInitiallyAccessible[LogicalDriveNumber])
5399 {
5400 Controller->LogicalDriveInitiallyAccessible[LogicalDriveNumber] = true;
5401 DAC960_ComputeGenericDiskInfo(&Controller->GenericDiskInfo);
5402 DAC960_RegisterDisk(Controller, LogicalDriveNumber);
5403 }
5404 if (Controller->GenericDiskInfo.sizes[MINOR(Inode->i_rdev)] == 0)
5405 return -ENXIO;
5406 /*
5407 Increment Controller and Logical Drive Usage Counts.
5408 */
5409 Controller->ControllerUsageCount++;
5410 Controller->LogicalDriveUsageCount[LogicalDriveNumber]++;
5411 ModuleOnly:
5412 return 0;
5413 }
5414
5415
5416 /*
5417 DAC960_Release is the Device Release Function for the DAC960 Driver.
5418 */
5419
DAC960_Release(Inode_T * Inode,File_T * File)5420 static int DAC960_Release(Inode_T *Inode, File_T *File)
5421 {
5422 int ControllerNumber = DAC960_ControllerNumber(Inode->i_rdev);
5423 int LogicalDriveNumber = DAC960_LogicalDriveNumber(Inode->i_rdev);
5424 DAC960_Controller_T *Controller = DAC960_Controllers[ControllerNumber];
5425 if (ControllerNumber == 0 && LogicalDriveNumber == 0 &&
5426 File != NULL && (File->f_flags & O_NONBLOCK))
5427 goto ModuleOnly;
5428 /*
5429 Decrement the Logical Drive and Controller Usage Counts.
5430 */
5431 Controller->LogicalDriveUsageCount[LogicalDriveNumber]--;
5432 Controller->ControllerUsageCount--;
5433 ModuleOnly:
5434 return 0;
5435 }
5436
5437
5438 /*
5439 DAC960_IOCTL is the Device IOCTL Function for the DAC960 Driver.
5440 */
5441
DAC960_IOCTL(Inode_T * Inode,File_T * File,unsigned int Request,unsigned long Argument)5442 static int DAC960_IOCTL(Inode_T *Inode, File_T *File,
5443 unsigned int Request, unsigned long Argument)
5444 {
5445 int ControllerNumber = DAC960_ControllerNumber(Inode->i_rdev);
5446 int LogicalDriveNumber = DAC960_LogicalDriveNumber(Inode->i_rdev);
5447 DiskGeometry_T Geometry, *UserGeometry;
5448 DAC960_Controller_T *Controller;
5449 int PartitionNumber;
5450 if (File != NULL && (File->f_flags & O_NONBLOCK))
5451 return DAC960_UserIOCTL(Inode, File, Request, Argument);
5452 if (ControllerNumber < 0 || ControllerNumber > DAC960_ControllerCount - 1)
5453 return -ENXIO;
5454 Controller = DAC960_Controllers[ControllerNumber];
5455 if (Controller == NULL) return -ENXIO;
5456 switch (Request)
5457 {
5458 case HDIO_GETGEO:
5459 /* Get BIOS Disk Geometry. */
5460 UserGeometry = (DiskGeometry_T *) Argument;
5461 if (UserGeometry == NULL) return -EINVAL;
5462 if (Controller->FirmwareType == DAC960_V1_Controller)
5463 {
5464 if (LogicalDriveNumber > Controller->LogicalDriveCount - 1)
5465 return -ENXIO;
5466 Geometry.heads = Controller->V1.GeometryTranslationHeads;
5467 Geometry.sectors = Controller->V1.GeometryTranslationSectors;
5468 Geometry.cylinders =
5469 Controller->V1.LogicalDriveInformation[LogicalDriveNumber]
5470 .LogicalDriveSize
5471 / (Geometry.heads * Geometry.sectors);
5472 }
5473 else
5474 {
5475 DAC960_V2_LogicalDeviceInfo_T *LogicalDeviceInfo =
5476 Controller->V2.LogicalDeviceInformation[LogicalDriveNumber];
5477 if (LogicalDeviceInfo == NULL)
5478 return -EINVAL;
5479 switch (LogicalDeviceInfo->DriveGeometry)
5480 {
5481 case DAC960_V2_Geometry_128_32:
5482 Geometry.heads = 128;
5483 Geometry.sectors = 32;
5484 break;
5485 case DAC960_V2_Geometry_255_63:
5486 Geometry.heads = 255;
5487 Geometry.sectors = 63;
5488 break;
5489 default:
5490 DAC960_Error("Illegal Logical Device Geometry %d\n",
5491 Controller, LogicalDeviceInfo->DriveGeometry);
5492 return -EINVAL;
5493 }
5494 Geometry.cylinders =
5495 LogicalDeviceInfo->ConfigurableDeviceSize
5496 / (Geometry.heads * Geometry.sectors);
5497 }
5498 Geometry.start =
5499 Controller->GenericDiskInfo.part[MINOR(Inode->i_rdev)].start_sect;
5500 return (copy_to_user(UserGeometry, &Geometry,
5501 sizeof(DiskGeometry_T)) ? -EFAULT : 0);
5502 case BLKGETSIZE:
5503 /* Get Device Size. */
5504 if ((unsigned long *) Argument == NULL) return -EINVAL;
5505 return put_user(Controller->GenericDiskInfo.part[MINOR(Inode->i_rdev)]
5506 .nr_sects,
5507 (unsigned long *) Argument);
5508 case BLKGETSIZE64:
5509 if ((u64 *) Argument == NULL) return -EINVAL;
5510 return put_user((u64) Controller->GenericDiskInfo
5511 .part[MINOR(Inode->i_rdev)]
5512 .nr_sects << 9,
5513 (u64 *) Argument);
5514 case BLKRAGET:
5515 case BLKRASET:
5516 case BLKFLSBUF:
5517 case BLKBSZGET:
5518 case BLKBSZSET:
5519 return blk_ioctl(Inode->i_rdev, Request, Argument);
5520 case BLKRRPART:
5521 /* Re-Read Partition Table. */
5522 if (!capable(CAP_SYS_ADMIN)) return -EACCES;
5523 if (Controller->LogicalDriveUsageCount[LogicalDriveNumber] > 1)
5524 return -EBUSY;
5525 for (PartitionNumber = 0;
5526 PartitionNumber < DAC960_MaxPartitions;
5527 PartitionNumber++)
5528 {
5529 KernelDevice_T Device = DAC960_KernelDevice(ControllerNumber,
5530 LogicalDriveNumber,
5531 PartitionNumber);
5532 int MinorNumber = DAC960_MinorNumber(LogicalDriveNumber,
5533 PartitionNumber);
5534 if (Controller->GenericDiskInfo.part[MinorNumber].nr_sects == 0)
5535 continue;
5536 /*
5537 Flush all changes and invalidate buffered state.
5538 */
5539 invalidate_device(Device, 1);
5540 /*
5541 Clear existing partition sizes.
5542 */
5543 if (PartitionNumber > 0)
5544 {
5545 Controller->GenericDiskInfo.part[MinorNumber].start_sect = 0;
5546 Controller->GenericDiskInfo.part[MinorNumber].nr_sects = 0;
5547 }
5548 /*
5549 Reset the Block Size so that the partition table can be read.
5550 */
5551 set_blocksize(Device, BLOCK_SIZE);
5552 }
5553 DAC960_RegisterDisk(Controller, LogicalDriveNumber);
5554 return 0;
5555 }
5556 return -EINVAL;
5557 }
5558
5559
5560 /*
5561 DAC960_UserIOCTL is the User IOCTL Function for the DAC960 Driver.
5562 */
5563
DAC960_UserIOCTL(Inode_T * Inode,File_T * File,unsigned int Request,unsigned long Argument)5564 static int DAC960_UserIOCTL(Inode_T *Inode, File_T *File,
5565 unsigned int Request, unsigned long Argument)
5566 {
5567 int ErrorCode = 0 ;
5568 if (!capable(CAP_SYS_ADMIN)) return -EACCES;
5569 switch (Request)
5570 {
5571 case DAC960_IOCTL_GET_CONTROLLER_COUNT:
5572 return DAC960_ControllerCount;
5573 case DAC960_IOCTL_GET_CONTROLLER_INFO:
5574 {
5575 DAC960_ControllerInfo_T *UserSpaceControllerInfo =
5576 (DAC960_ControllerInfo_T *) Argument;
5577 DAC960_ControllerInfo_T ControllerInfo;
5578 DAC960_Controller_T *Controller;
5579 int ControllerNumber;
5580 if (UserSpaceControllerInfo == NULL) return -EINVAL;
5581 ErrorCode = get_user(ControllerNumber,
5582 &UserSpaceControllerInfo->ControllerNumber);
5583 if (ErrorCode != 0) return ErrorCode;
5584 if (ControllerNumber < 0 ||
5585 ControllerNumber > DAC960_ControllerCount - 1)
5586 return -ENXIO;
5587 Controller = DAC960_Controllers[ControllerNumber];
5588 if (Controller == NULL) return -ENXIO;
5589 memset(&ControllerInfo, 0, sizeof(DAC960_ControllerInfo_T));
5590 ControllerInfo.ControllerNumber = ControllerNumber;
5591 ControllerInfo.FirmwareType = Controller->FirmwareType;
5592 ControllerInfo.Channels = Controller->Channels;
5593 ControllerInfo.Targets = Controller->Targets;
5594 ControllerInfo.PCI_Bus = Controller->Bus;
5595 ControllerInfo.PCI_Device = Controller->Device;
5596 ControllerInfo.PCI_Function = Controller->Function;
5597 ControllerInfo.IRQ_Channel = Controller->IRQ_Channel;
5598 ControllerInfo.PCI_Address = Controller->PCI_Address;
5599 strcpy(ControllerInfo.ModelName, Controller->ModelName);
5600 strcpy(ControllerInfo.FirmwareVersion, Controller->FirmwareVersion);
5601 return (copy_to_user(UserSpaceControllerInfo, &ControllerInfo,
5602 sizeof(DAC960_ControllerInfo_T)) ? -EFAULT : 0);
5603 }
5604 case DAC960_IOCTL_V1_EXECUTE_COMMAND:
5605 {
5606 DAC960_V1_UserCommand_T *UserSpaceUserCommand =
5607 (DAC960_V1_UserCommand_T *) Argument;
5608 DAC960_V1_UserCommand_T UserCommand;
5609 DAC960_Controller_T *Controller;
5610 DAC960_Command_T *Command = NULL;
5611 DAC960_V1_CommandOpcode_T CommandOpcode;
5612 DAC960_V1_CommandStatus_T CommandStatus;
5613 DAC960_V1_DCDB_T DCDB;
5614 ProcessorFlags_T ProcessorFlags;
5615 int ControllerNumber, DataTransferLength;
5616 unsigned char *DataTransferBuffer = NULL;
5617 if (UserSpaceUserCommand == NULL) return -EINVAL;
5618 if (copy_from_user(&UserCommand, UserSpaceUserCommand,
5619 sizeof(DAC960_V1_UserCommand_T))) {
5620 ErrorCode = -EFAULT;
5621 goto Failure1;
5622 }
5623 ControllerNumber = UserCommand.ControllerNumber;
5624 if (ControllerNumber < 0 ||
5625 ControllerNumber > DAC960_ControllerCount - 1)
5626 return -ENXIO;
5627 Controller = DAC960_Controllers[ControllerNumber];
5628 if (Controller == NULL) return -ENXIO;
5629 if (Controller->FirmwareType != DAC960_V1_Controller) return -EINVAL;
5630 CommandOpcode = UserCommand.CommandMailbox.Common.CommandOpcode;
5631 DataTransferLength = UserCommand.DataTransferLength;
5632 if (CommandOpcode & 0x80) return -EINVAL;
5633 if (CommandOpcode == DAC960_V1_DCDB)
5634 {
5635 if (copy_from_user(&DCDB, UserCommand.DCDB,
5636 sizeof(DAC960_V1_DCDB_T))) {
5637 ErrorCode = -EFAULT;
5638 goto Failure1;
5639 }
5640 if (DCDB.Channel >= DAC960_V1_MaxChannels) return -EINVAL;
5641 if (!((DataTransferLength == 0 &&
5642 DCDB.Direction
5643 == DAC960_V1_DCDB_NoDataTransfer) ||
5644 (DataTransferLength > 0 &&
5645 DCDB.Direction
5646 == DAC960_V1_DCDB_DataTransferDeviceToSystem) ||
5647 (DataTransferLength < 0 &&
5648 DCDB.Direction
5649 == DAC960_V1_DCDB_DataTransferSystemToDevice)))
5650 return -EINVAL;
5651 if (((DCDB.TransferLengthHigh4 << 16) | DCDB.TransferLength)
5652 != abs(DataTransferLength))
5653 return -EINVAL;
5654 }
5655 if (DataTransferLength > 0)
5656 {
5657 DataTransferBuffer = kmalloc(DataTransferLength, GFP_KERNEL);
5658 if (DataTransferBuffer == NULL) return -ENOMEM;
5659 memset(DataTransferBuffer, 0, DataTransferLength);
5660 }
5661 else if (DataTransferLength < 0)
5662 {
5663 DataTransferBuffer = kmalloc(-DataTransferLength, GFP_KERNEL);
5664 if (DataTransferBuffer == NULL) return -ENOMEM;
5665 if (copy_from_user(DataTransferBuffer,
5666 UserCommand.DataTransferBuffer,
5667 -DataTransferLength)) {
5668 ErrorCode = -EFAULT;
5669 goto Failure1;
5670 }
5671 }
5672 if (CommandOpcode == DAC960_V1_DCDB)
5673 {
5674 DAC960_AcquireControllerLock(Controller, &ProcessorFlags);
5675 while ((Command = DAC960_AllocateCommand(Controller)) == NULL)
5676 DAC960_WaitForCommand(Controller);
5677 while (Controller->V1.DirectCommandActive[DCDB.Channel]
5678 [DCDB.TargetID])
5679 {
5680 spin_unlock_irq(&io_request_lock);
5681 __wait_event(Controller->CommandWaitQueue,
5682 !Controller->V1.DirectCommandActive
5683 [DCDB.Channel][DCDB.TargetID]);
5684 spin_lock_irq(&io_request_lock);
5685 }
5686 Controller->V1.DirectCommandActive[DCDB.Channel]
5687 [DCDB.TargetID] = true;
5688 DAC960_ReleaseControllerLock(Controller, &ProcessorFlags);
5689 DAC960_V1_ClearCommand(Command);
5690 Command->CommandType = DAC960_ImmediateCommand;
5691 memcpy(&Command->V1.CommandMailbox, &UserCommand.CommandMailbox,
5692 sizeof(DAC960_V1_CommandMailbox_T));
5693 Command->V1.CommandMailbox.Type3.BusAddress =
5694 Virtual_to_Bus32(&DCDB);
5695 DCDB.BusAddress = Virtual_to_Bus32(DataTransferBuffer);
5696 }
5697 else
5698 {
5699 DAC960_AcquireControllerLock(Controller, &ProcessorFlags);
5700 while ((Command = DAC960_AllocateCommand(Controller)) == NULL)
5701 DAC960_WaitForCommand(Controller);
5702 DAC960_ReleaseControllerLock(Controller, &ProcessorFlags);
5703 DAC960_V1_ClearCommand(Command);
5704 Command->CommandType = DAC960_ImmediateCommand;
5705 memcpy(&Command->V1.CommandMailbox, &UserCommand.CommandMailbox,
5706 sizeof(DAC960_V1_CommandMailbox_T));
5707 if (DataTransferBuffer != NULL)
5708 Command->V1.CommandMailbox.Type3.BusAddress =
5709 Virtual_to_Bus32(DataTransferBuffer);
5710 }
5711 DAC960_ExecuteCommand(Command);
5712 CommandStatus = Command->V1.CommandStatus;
5713 DAC960_AcquireControllerLock(Controller, &ProcessorFlags);
5714 DAC960_DeallocateCommand(Command);
5715 DAC960_ReleaseControllerLock(Controller, &ProcessorFlags);
5716 if (DataTransferLength > 0)
5717 {
5718 if (copy_to_user(UserCommand.DataTransferBuffer,
5719 DataTransferBuffer, DataTransferLength))
5720 ErrorCode = -EFAULT;
5721 goto Failure1;
5722 }
5723 if (CommandOpcode == DAC960_V1_DCDB)
5724 {
5725 Controller->V1.DirectCommandActive[DCDB.Channel]
5726 [DCDB.TargetID] = false;
5727 if (copy_to_user(UserCommand.DCDB, &DCDB,
5728 sizeof(DAC960_V1_DCDB_T))) {
5729 ErrorCode = -EFAULT;
5730 goto Failure1;
5731 }
5732 }
5733 ErrorCode = CommandStatus;
5734 Failure1:
5735 if (DataTransferBuffer != NULL)
5736 kfree(DataTransferBuffer);
5737 return ErrorCode;
5738 }
5739 case DAC960_IOCTL_V2_EXECUTE_COMMAND:
5740 {
5741 DAC960_V2_UserCommand_T *UserSpaceUserCommand =
5742 (DAC960_V2_UserCommand_T *) Argument;
5743 DAC960_V2_UserCommand_T UserCommand;
5744 DAC960_Controller_T *Controller;
5745 DAC960_Command_T *Command = NULL;
5746 DAC960_V2_CommandMailbox_T *CommandMailbox;
5747 DAC960_V2_CommandStatus_T CommandStatus;
5748 ProcessorFlags_T ProcessorFlags;
5749 int ControllerNumber, DataTransferLength;
5750 int DataTransferResidue, RequestSenseLength;
5751 unsigned char *DataTransferBuffer = NULL;
5752 unsigned char *RequestSenseBuffer = NULL;
5753 if (UserSpaceUserCommand == NULL) return -EINVAL;
5754 if (copy_from_user(&UserCommand, UserSpaceUserCommand,
5755 sizeof(DAC960_V2_UserCommand_T))) {
5756 ErrorCode = -EFAULT;
5757 goto Failure2;
5758 }
5759 ControllerNumber = UserCommand.ControllerNumber;
5760 if (ControllerNumber < 0 ||
5761 ControllerNumber > DAC960_ControllerCount - 1)
5762 return -ENXIO;
5763 Controller = DAC960_Controllers[ControllerNumber];
5764 if (Controller == NULL) return -ENXIO;
5765 if (Controller->FirmwareType != DAC960_V2_Controller) return -EINVAL;
5766 DataTransferLength = UserCommand.DataTransferLength;
5767 if (DataTransferLength > 0)
5768 {
5769 DataTransferBuffer = kmalloc(DataTransferLength, GFP_KERNEL);
5770 if (DataTransferBuffer == NULL) return -ENOMEM;
5771 memset(DataTransferBuffer, 0, DataTransferLength);
5772 }
5773 else if (DataTransferLength < 0)
5774 {
5775 DataTransferBuffer = kmalloc(-DataTransferLength, GFP_KERNEL);
5776 if (DataTransferBuffer == NULL) return -ENOMEM;
5777 if (copy_from_user(DataTransferBuffer,
5778 UserCommand.DataTransferBuffer,
5779 -DataTransferLength)) {
5780 ErrorCode = -EFAULT;
5781 goto Failure2;
5782 }
5783 }
5784 RequestSenseLength = UserCommand.RequestSenseLength;
5785 if (RequestSenseLength > 0)
5786 {
5787 RequestSenseBuffer = kmalloc(RequestSenseLength, GFP_KERNEL);
5788 if (RequestSenseBuffer == NULL)
5789 {
5790 ErrorCode = -ENOMEM;
5791 goto Failure2;
5792 }
5793 memset(RequestSenseBuffer, 0, RequestSenseLength);
5794 }
5795 DAC960_AcquireControllerLock(Controller, &ProcessorFlags);
5796 while ((Command = DAC960_AllocateCommand(Controller)) == NULL)
5797 DAC960_WaitForCommand(Controller);
5798 DAC960_ReleaseControllerLock(Controller, &ProcessorFlags);
5799 DAC960_V2_ClearCommand(Command);
5800 Command->CommandType = DAC960_ImmediateCommand;
5801 CommandMailbox = &Command->V2.CommandMailbox;
5802 memcpy(CommandMailbox, &UserCommand.CommandMailbox,
5803 sizeof(DAC960_V2_CommandMailbox_T));
5804 CommandMailbox->Common.CommandControlBits
5805 .AdditionalScatterGatherListMemory = false;
5806 CommandMailbox->Common.CommandControlBits
5807 .NoAutoRequestSense = true;
5808 CommandMailbox->Common.DataTransferSize = 0;
5809 CommandMailbox->Common.DataTransferPageNumber = 0;
5810 memset(&CommandMailbox->Common.DataTransferMemoryAddress, 0,
5811 sizeof(DAC960_V2_DataTransferMemoryAddress_T));
5812 if (DataTransferLength != 0)
5813 {
5814 if (DataTransferLength > 0)
5815 {
5816 CommandMailbox->Common.CommandControlBits
5817 .DataTransferControllerToHost = true;
5818 CommandMailbox->Common.DataTransferSize = DataTransferLength;
5819 }
5820 else
5821 {
5822 CommandMailbox->Common.CommandControlBits
5823 .DataTransferControllerToHost = false;
5824 CommandMailbox->Common.DataTransferSize = -DataTransferLength;
5825 }
5826 CommandMailbox->Common.DataTransferMemoryAddress
5827 .ScatterGatherSegments[0]
5828 .SegmentDataPointer =
5829 Virtual_to_Bus64(DataTransferBuffer);
5830 CommandMailbox->Common.DataTransferMemoryAddress
5831 .ScatterGatherSegments[0]
5832 .SegmentByteCount =
5833 CommandMailbox->Common.DataTransferSize;
5834 }
5835 if (RequestSenseLength > 0)
5836 {
5837 CommandMailbox->Common.CommandControlBits
5838 .NoAutoRequestSense = false;
5839 CommandMailbox->Common.RequestSenseSize = RequestSenseLength;
5840 CommandMailbox->Common.RequestSenseBusAddress =
5841 Virtual_to_Bus64(RequestSenseBuffer);
5842 }
5843 DAC960_ExecuteCommand(Command);
5844 CommandStatus = Command->V2.CommandStatus;
5845 RequestSenseLength = Command->V2.RequestSenseLength;
5846 DataTransferResidue = Command->V2.DataTransferResidue;
5847 DAC960_AcquireControllerLock(Controller, &ProcessorFlags);
5848 DAC960_DeallocateCommand(Command);
5849 DAC960_ReleaseControllerLock(Controller, &ProcessorFlags);
5850 if (RequestSenseLength > UserCommand.RequestSenseLength)
5851 RequestSenseLength = UserCommand.RequestSenseLength;
5852 if (copy_to_user(&UserSpaceUserCommand->DataTransferLength,
5853 &DataTransferResidue,
5854 sizeof(DataTransferResidue))) {
5855 ErrorCode = -EFAULT;
5856 goto Failure2;
5857 }
5858 if (copy_to_user(&UserSpaceUserCommand->RequestSenseLength,
5859 &RequestSenseLength, sizeof(RequestSenseLength))) {
5860 ErrorCode = -EFAULT;
5861 goto Failure2;
5862 }
5863 if (DataTransferLength > 0)
5864 {
5865 if (copy_to_user(UserCommand.DataTransferBuffer,
5866 DataTransferBuffer, DataTransferLength)) {
5867 ErrorCode = -EFAULT;
5868 goto Failure2;
5869 }
5870 }
5871 if (RequestSenseLength > 0)
5872 {
5873 if (copy_to_user(UserCommand.RequestSenseBuffer,
5874 RequestSenseBuffer, RequestSenseLength)) {
5875 ErrorCode = -EFAULT;
5876 goto Failure2;
5877 }
5878 }
5879 ErrorCode = CommandStatus;
5880 Failure2:
5881 if (DataTransferBuffer != NULL)
5882 kfree(DataTransferBuffer);
5883 if (RequestSenseBuffer != NULL)
5884 kfree(RequestSenseBuffer);
5885 return ErrorCode;
5886 }
5887 case DAC960_IOCTL_V2_GET_HEALTH_STATUS:
5888 {
5889 DAC960_V2_GetHealthStatus_T *UserSpaceGetHealthStatus =
5890 (DAC960_V2_GetHealthStatus_T *) Argument;
5891 DAC960_V2_GetHealthStatus_T GetHealthStatus;
5892 DAC960_V2_HealthStatusBuffer_T HealthStatusBuffer;
5893 DAC960_Controller_T *Controller;
5894 int ControllerNumber;
5895 if (UserSpaceGetHealthStatus == NULL) return -EINVAL;
5896 if (copy_from_user(&GetHealthStatus, UserSpaceGetHealthStatus,
5897 sizeof(DAC960_V2_GetHealthStatus_T)))
5898 return -EFAULT;
5899 ControllerNumber = GetHealthStatus.ControllerNumber;
5900 if (ControllerNumber < 0 ||
5901 ControllerNumber > DAC960_ControllerCount - 1)
5902 return -ENXIO;
5903 Controller = DAC960_Controllers[ControllerNumber];
5904 if (Controller == NULL) return -ENXIO;
5905 if (Controller->FirmwareType != DAC960_V2_Controller) return -EINVAL;
5906 if (copy_from_user(&HealthStatusBuffer,
5907 GetHealthStatus.HealthStatusBuffer,
5908 sizeof(DAC960_V2_HealthStatusBuffer_T)))
5909 return -EFAULT;
5910 while (Controller->V2.HealthStatusBuffer->StatusChangeCounter
5911 == HealthStatusBuffer.StatusChangeCounter &&
5912 Controller->V2.HealthStatusBuffer->NextEventSequenceNumber
5913 == HealthStatusBuffer.NextEventSequenceNumber)
5914 {
5915 interruptible_sleep_on_timeout(&Controller->HealthStatusWaitQueue,
5916 DAC960_MonitoringTimerInterval);
5917 if (signal_pending(current)) return -EINTR;
5918 }
5919 if (copy_to_user(GetHealthStatus.HealthStatusBuffer,
5920 Controller->V2.HealthStatusBuffer,
5921 sizeof(DAC960_V2_HealthStatusBuffer_T)))
5922 return -EFAULT;
5923 return 0;
5924 }
5925 }
5926 return -EINVAL;
5927 }
5928
5929
5930 /*
5931 DAC960_KernelIOCTL is the Kernel IOCTL Function for the DAC960 Driver.
5932 */
5933
DAC960_KernelIOCTL(unsigned int Request,void * Argument)5934 int DAC960_KernelIOCTL(unsigned int Request, void *Argument)
5935 {
5936 switch (Request)
5937 {
5938 case DAC960_IOCTL_GET_CONTROLLER_COUNT:
5939 return DAC960_ControllerCount;
5940 case DAC960_IOCTL_GET_CONTROLLER_INFO:
5941 {
5942 DAC960_ControllerInfo_T *ControllerInfo =
5943 (DAC960_ControllerInfo_T *) Argument;
5944 DAC960_Controller_T *Controller;
5945 int ControllerNumber;
5946 if (ControllerInfo == NULL) return -EINVAL;
5947 ControllerNumber = ControllerInfo->ControllerNumber;
5948 if (ControllerNumber < 0 ||
5949 ControllerNumber > DAC960_ControllerCount - 1)
5950 return -ENXIO;
5951 Controller = DAC960_Controllers[ControllerNumber];
5952 if (Controller == NULL) return -ENXIO;
5953 memset(ControllerInfo, 0, sizeof(DAC960_ControllerInfo_T));
5954 ControllerInfo->ControllerNumber = ControllerNumber;
5955 ControllerInfo->FirmwareType = Controller->FirmwareType;
5956 ControllerInfo->Channels = Controller->Channels;
5957 ControllerInfo->Targets = Controller->Targets;
5958 ControllerInfo->PCI_Bus = Controller->Bus;
5959 ControllerInfo->PCI_Device = Controller->Device;
5960 ControllerInfo->PCI_Function = Controller->Function;
5961 ControllerInfo->IRQ_Channel = Controller->IRQ_Channel;
5962 ControllerInfo->PCI_Address = Controller->PCI_Address;
5963 strcpy(ControllerInfo->ModelName, Controller->ModelName);
5964 strcpy(ControllerInfo->FirmwareVersion, Controller->FirmwareVersion);
5965 return 0;
5966 }
5967 case DAC960_IOCTL_V1_EXECUTE_COMMAND:
5968 {
5969 DAC960_V1_KernelCommand_T *KernelCommand =
5970 (DAC960_V1_KernelCommand_T *) Argument;
5971 DAC960_Controller_T *Controller;
5972 DAC960_Command_T *Command = NULL;
5973 DAC960_V1_CommandOpcode_T CommandOpcode;
5974 DAC960_V1_DCDB_T *DCDB = NULL;
5975 ProcessorFlags_T ProcessorFlags;
5976 int ControllerNumber, DataTransferLength;
5977 unsigned char *DataTransferBuffer = NULL;
5978 if (KernelCommand == NULL) return -EINVAL;
5979 ControllerNumber = KernelCommand->ControllerNumber;
5980 if (ControllerNumber < 0 ||
5981 ControllerNumber > DAC960_ControllerCount - 1)
5982 return -ENXIO;
5983 Controller = DAC960_Controllers[ControllerNumber];
5984 if (Controller == NULL) return -ENXIO;
5985 if (Controller->FirmwareType != DAC960_V1_Controller) return -EINVAL;
5986 CommandOpcode = KernelCommand->CommandMailbox.Common.CommandOpcode;
5987 DataTransferLength = KernelCommand->DataTransferLength;
5988 DataTransferBuffer = KernelCommand->DataTransferBuffer;
5989 if (CommandOpcode & 0x80) return -EINVAL;
5990 if (CommandOpcode == DAC960_V1_DCDB)
5991 {
5992 DCDB = KernelCommand->DCDB;
5993 if (DCDB->Channel >= DAC960_V1_MaxChannels) return -EINVAL;
5994 if (!((DataTransferLength == 0 &&
5995 DCDB->Direction == DAC960_V1_DCDB_NoDataTransfer) ||
5996 (DataTransferLength > 0 &&
5997 DCDB->Direction
5998 == DAC960_V1_DCDB_DataTransferDeviceToSystem) ||
5999 (DataTransferLength < 0 &&
6000 DCDB->Direction
6001 == DAC960_V1_DCDB_DataTransferSystemToDevice)))
6002 return -EINVAL;
6003 if (((DCDB->TransferLengthHigh4 << 16) | DCDB->TransferLength)
6004 != abs(DataTransferLength))
6005 return -EINVAL;
6006 }
6007 if (DataTransferLength != 0 && DataTransferBuffer == NULL)
6008 return -EINVAL;
6009 if (DataTransferLength > 0)
6010 memset(DataTransferBuffer, 0, DataTransferLength);
6011 if (CommandOpcode == DAC960_V1_DCDB)
6012 {
6013 DAC960_AcquireControllerLock(Controller, &ProcessorFlags);
6014 if (!Controller->V1.DirectCommandActive[DCDB->Channel]
6015 [DCDB->TargetID])
6016 Command = DAC960_AllocateCommand(Controller);
6017 if (Command == NULL)
6018 {
6019 DAC960_ReleaseControllerLock(Controller, &ProcessorFlags);
6020 return -EBUSY;
6021 }
6022 else Controller->V1.DirectCommandActive[DCDB->Channel]
6023 [DCDB->TargetID] = true;
6024 DAC960_V1_ClearCommand(Command);
6025 Command->CommandType = DAC960_QueuedCommand;
6026 memcpy(&Command->V1.CommandMailbox, &KernelCommand->CommandMailbox,
6027 sizeof(DAC960_V1_CommandMailbox_T));
6028 Command->V1.CommandMailbox.Type3.BusAddress =
6029 Virtual_to_Bus32(DCDB);
6030 Command->V1.KernelCommand = KernelCommand;
6031 DCDB->BusAddress = Virtual_to_Bus32(DataTransferBuffer);
6032 DAC960_QueueCommand(Command);
6033 DAC960_ReleaseControllerLock(Controller, &ProcessorFlags);
6034 }
6035 else
6036 {
6037 DAC960_AcquireControllerLock(Controller, &ProcessorFlags);
6038 Command = DAC960_AllocateCommand(Controller);
6039 if (Command == NULL)
6040 {
6041 DAC960_ReleaseControllerLock(Controller, &ProcessorFlags);
6042 return -EBUSY;
6043 }
6044 DAC960_V1_ClearCommand(Command);
6045 Command->CommandType = DAC960_QueuedCommand;
6046 memcpy(&Command->V1.CommandMailbox, &KernelCommand->CommandMailbox,
6047 sizeof(DAC960_V1_CommandMailbox_T));
6048 if (DataTransferBuffer != NULL)
6049 Command->V1.CommandMailbox.Type3.BusAddress =
6050 Virtual_to_Bus32(DataTransferBuffer);
6051 Command->V1.KernelCommand = KernelCommand;
6052 DAC960_QueueCommand(Command);
6053 DAC960_ReleaseControllerLock(Controller, &ProcessorFlags);
6054 }
6055 return 0;
6056 }
6057 case DAC960_IOCTL_V2_EXECUTE_COMMAND:
6058 {
6059 DAC960_V2_KernelCommand_T *KernelCommand =
6060 (DAC960_V2_KernelCommand_T *) Argument;
6061 DAC960_Controller_T *Controller;
6062 DAC960_Command_T *Command = NULL;
6063 DAC960_V2_CommandMailbox_T *CommandMailbox;
6064 ProcessorFlags_T ProcessorFlags;
6065 int ControllerNumber, DataTransferLength, RequestSenseLength;
6066 unsigned char *DataTransferBuffer = NULL;
6067 unsigned char *RequestSenseBuffer = NULL;
6068 if (KernelCommand == NULL) return -EINVAL;
6069 ControllerNumber = KernelCommand->ControllerNumber;
6070 if (ControllerNumber < 0 ||
6071 ControllerNumber > DAC960_ControllerCount - 1)
6072 return -ENXIO;
6073 Controller = DAC960_Controllers[ControllerNumber];
6074 if (Controller == NULL) return -ENXIO;
6075 if (Controller->FirmwareType != DAC960_V2_Controller) return -EINVAL;
6076 DataTransferLength = KernelCommand->DataTransferLength;
6077 RequestSenseLength = KernelCommand->RequestSenseLength;
6078 DataTransferBuffer = KernelCommand->DataTransferBuffer;
6079 RequestSenseBuffer = KernelCommand->RequestSenseBuffer;
6080 if (DataTransferLength != 0 && DataTransferBuffer == NULL)
6081 return -EINVAL;
6082 if (RequestSenseLength < 0)
6083 return -EINVAL;
6084 if (RequestSenseLength > 0 && RequestSenseBuffer == NULL)
6085 return -EINVAL;
6086 if (DataTransferLength > 0)
6087 memset(DataTransferBuffer, 0, DataTransferLength);
6088 if (RequestSenseLength > 0)
6089 memset(RequestSenseBuffer, 0, RequestSenseLength);
6090 DAC960_AcquireControllerLock(Controller, &ProcessorFlags);
6091 Command = DAC960_AllocateCommand(Controller);
6092 if (Command == NULL)
6093 {
6094 DAC960_ReleaseControllerLock(Controller, &ProcessorFlags);
6095 return -EBUSY;
6096 }
6097 DAC960_V2_ClearCommand(Command);
6098 Command->CommandType = DAC960_QueuedCommand;
6099 CommandMailbox = &Command->V2.CommandMailbox;
6100 memcpy(CommandMailbox, &KernelCommand->CommandMailbox,
6101 sizeof(DAC960_V2_CommandMailbox_T));
6102 CommandMailbox->Common.CommandControlBits
6103 .AdditionalScatterGatherListMemory = false;
6104 CommandMailbox->Common.CommandControlBits
6105 .NoAutoRequestSense = true;
6106 CommandMailbox->Common.DataTransferSize = 0;
6107 CommandMailbox->Common.DataTransferPageNumber = 0;
6108 memset(&CommandMailbox->Common.DataTransferMemoryAddress, 0,
6109 sizeof(DAC960_V2_DataTransferMemoryAddress_T));
6110 if (DataTransferLength != 0)
6111 {
6112 if (DataTransferLength > 0)
6113 {
6114 CommandMailbox->Common.CommandControlBits
6115 .DataTransferControllerToHost = true;
6116 CommandMailbox->Common.DataTransferSize = DataTransferLength;
6117 }
6118 else
6119 {
6120 CommandMailbox->Common.CommandControlBits
6121 .DataTransferControllerToHost = false;
6122 CommandMailbox->Common.DataTransferSize = -DataTransferLength;
6123 }
6124 CommandMailbox->Common.DataTransferMemoryAddress
6125 .ScatterGatherSegments[0]
6126 .SegmentDataPointer =
6127 Virtual_to_Bus64(DataTransferBuffer);
6128 CommandMailbox->Common.DataTransferMemoryAddress
6129 .ScatterGatherSegments[0]
6130 .SegmentByteCount =
6131 CommandMailbox->Common.DataTransferSize;
6132 }
6133 if (RequestSenseLength > 0)
6134 {
6135 CommandMailbox->Common.CommandControlBits
6136 .NoAutoRequestSense = false;
6137 CommandMailbox->Common.RequestSenseBusAddress =
6138 Virtual_to_Bus64(RequestSenseBuffer);
6139 }
6140 Command->V2.KernelCommand = KernelCommand;
6141 DAC960_QueueCommand(Command);
6142 DAC960_ReleaseControllerLock(Controller, &ProcessorFlags);
6143 return 0;
6144 }
6145 }
6146 return -EINVAL;
6147 }
6148
6149
6150 /*
6151 DAC960_CheckStatusBuffer verifies that there is room to hold ByteCount
6152 additional bytes in the Combined Status Buffer and grows the buffer if
6153 necessary. It returns true if there is enough room and false otherwise.
6154 */
6155
DAC960_CheckStatusBuffer(DAC960_Controller_T * Controller,unsigned int ByteCount)6156 static boolean DAC960_CheckStatusBuffer(DAC960_Controller_T *Controller,
6157 unsigned int ByteCount)
6158 {
6159 unsigned char *NewStatusBuffer;
6160 if (Controller->InitialStatusLength + 1 +
6161 Controller->CurrentStatusLength + ByteCount + 1 <=
6162 Controller->CombinedStatusBufferLength)
6163 return true;
6164 if (Controller->CombinedStatusBufferLength == 0)
6165 {
6166 unsigned int NewStatusBufferLength = DAC960_InitialStatusBufferSize;
6167 while (NewStatusBufferLength < ByteCount)
6168 NewStatusBufferLength *= 2;
6169 Controller->CombinedStatusBuffer =
6170 (unsigned char *) kmalloc(NewStatusBufferLength, GFP_ATOMIC);
6171 if (Controller->CombinedStatusBuffer == NULL) return false;
6172 Controller->CombinedStatusBufferLength = NewStatusBufferLength;
6173 return true;
6174 }
6175 NewStatusBuffer = (unsigned char *)
6176 kmalloc(2 * Controller->CombinedStatusBufferLength, GFP_ATOMIC);
6177 if (NewStatusBuffer == NULL)
6178 {
6179 DAC960_Warning("Unable to expand Combined Status Buffer - Truncating\n",
6180 Controller);
6181 return false;
6182 }
6183 memcpy(NewStatusBuffer, Controller->CombinedStatusBuffer,
6184 Controller->CombinedStatusBufferLength);
6185 kfree(Controller->CombinedStatusBuffer);
6186 Controller->CombinedStatusBuffer = NewStatusBuffer;
6187 Controller->CombinedStatusBufferLength *= 2;
6188 Controller->CurrentStatusBuffer =
6189 &NewStatusBuffer[Controller->InitialStatusLength + 1];
6190 return true;
6191 }
6192
6193
6194 /*
6195 DAC960_Message prints Driver Messages.
6196 */
6197
DAC960_Message(DAC960_MessageLevel_T MessageLevel,unsigned char * Format,DAC960_Controller_T * Controller,...)6198 static void DAC960_Message(DAC960_MessageLevel_T MessageLevel,
6199 unsigned char *Format,
6200 DAC960_Controller_T *Controller,
6201 ...)
6202 {
6203 static unsigned char Buffer[DAC960_LineBufferSize];
6204 static boolean BeginningOfLine = true;
6205 va_list Arguments;
6206 int Length = 0;
6207 va_start(Arguments, Controller);
6208 Length = vsprintf(Buffer, Format, Arguments);
6209 va_end(Arguments);
6210 if (Controller == NULL)
6211 printk("%sDAC960#%d: %s", DAC960_MessageLevelMap[MessageLevel],
6212 DAC960_ControllerCount, Buffer);
6213 else if (MessageLevel == DAC960_AnnounceLevel ||
6214 MessageLevel == DAC960_InfoLevel)
6215 {
6216 if (!Controller->ControllerInitialized)
6217 {
6218 if (DAC960_CheckStatusBuffer(Controller, Length))
6219 {
6220 strcpy(&Controller->CombinedStatusBuffer
6221 [Controller->InitialStatusLength],
6222 Buffer);
6223 Controller->InitialStatusLength += Length;
6224 Controller->CurrentStatusBuffer =
6225 &Controller->CombinedStatusBuffer
6226 [Controller->InitialStatusLength + 1];
6227 }
6228 if (MessageLevel == DAC960_AnnounceLevel)
6229 {
6230 static int AnnouncementLines = 0;
6231 if (++AnnouncementLines <= 2)
6232 printk("%sDAC960: %s", DAC960_MessageLevelMap[MessageLevel],
6233 Buffer);
6234 }
6235 else
6236 {
6237 if (BeginningOfLine)
6238 {
6239 if (Buffer[0] != '\n' || Length > 1)
6240 printk("%sDAC960#%d: %s",
6241 DAC960_MessageLevelMap[MessageLevel],
6242 Controller->ControllerNumber, Buffer);
6243 }
6244 else printk("%s", Buffer);
6245 }
6246 }
6247 else if (DAC960_CheckStatusBuffer(Controller, Length))
6248 {
6249 strcpy(&Controller->CurrentStatusBuffer[
6250 Controller->CurrentStatusLength], Buffer);
6251 Controller->CurrentStatusLength += Length;
6252 }
6253 }
6254 else if (MessageLevel == DAC960_ProgressLevel)
6255 {
6256 strcpy(Controller->ProgressBuffer, Buffer);
6257 Controller->ProgressBufferLength = Length;
6258 if (Controller->EphemeralProgressMessage)
6259 {
6260 if (jiffies - Controller->LastProgressReportTime
6261 >= DAC960_ProgressReportingInterval)
6262 {
6263 printk("%sDAC960#%d: %s", DAC960_MessageLevelMap[MessageLevel],
6264 Controller->ControllerNumber, Buffer);
6265 Controller->LastProgressReportTime = jiffies;
6266 }
6267 }
6268 else printk("%sDAC960#%d: %s", DAC960_MessageLevelMap[MessageLevel],
6269 Controller->ControllerNumber, Buffer);
6270 }
6271 else if (MessageLevel == DAC960_UserCriticalLevel)
6272 {
6273 strcpy(&Controller->UserStatusBuffer[Controller->UserStatusLength],
6274 Buffer);
6275 Controller->UserStatusLength += Length;
6276 if (Buffer[0] != '\n' || Length > 1)
6277 printk("%sDAC960#%d: %s", DAC960_MessageLevelMap[MessageLevel],
6278 Controller->ControllerNumber, Buffer);
6279 }
6280 else
6281 {
6282 if (BeginningOfLine)
6283 printk("%sDAC960#%d: %s", DAC960_MessageLevelMap[MessageLevel],
6284 Controller->ControllerNumber, Buffer);
6285 else printk("%s", Buffer);
6286 }
6287 BeginningOfLine = (Buffer[Length-1] == '\n');
6288 }
6289
6290
6291 /*
6292 DAC960_ParsePhysicalDevice parses spaces followed by a Physical Device
6293 Channel:TargetID specification from a User Command string. It updates
6294 Channel and TargetID and returns true on success and false on failure.
6295 */
6296
DAC960_ParsePhysicalDevice(DAC960_Controller_T * Controller,char * UserCommandString,unsigned char * Channel,unsigned char * TargetID)6297 static boolean DAC960_ParsePhysicalDevice(DAC960_Controller_T *Controller,
6298 char *UserCommandString,
6299 unsigned char *Channel,
6300 unsigned char *TargetID)
6301 {
6302 char *NewUserCommandString = UserCommandString;
6303 unsigned long XChannel, XTargetID;
6304 while (*UserCommandString == ' ') UserCommandString++;
6305 if (UserCommandString == NewUserCommandString)
6306 return false;
6307 XChannel = simple_strtoul(UserCommandString, &NewUserCommandString, 10);
6308 if (NewUserCommandString == UserCommandString ||
6309 *NewUserCommandString != ':' ||
6310 XChannel >= Controller->Channels)
6311 return false;
6312 UserCommandString = ++NewUserCommandString;
6313 XTargetID = simple_strtoul(UserCommandString, &NewUserCommandString, 10);
6314 if (NewUserCommandString == UserCommandString ||
6315 *NewUserCommandString != '\0' ||
6316 XTargetID >= Controller->Targets)
6317 return false;
6318 *Channel = XChannel;
6319 *TargetID = XTargetID;
6320 return true;
6321 }
6322
6323
6324 /*
6325 DAC960_ParseLogicalDrive parses spaces followed by a Logical Drive Number
6326 specification from a User Command string. It updates LogicalDriveNumber and
6327 returns true on success and false on failure.
6328 */
6329
DAC960_ParseLogicalDrive(DAC960_Controller_T * Controller,char * UserCommandString,unsigned char * LogicalDriveNumber)6330 static boolean DAC960_ParseLogicalDrive(DAC960_Controller_T *Controller,
6331 char *UserCommandString,
6332 unsigned char *LogicalDriveNumber)
6333 {
6334 char *NewUserCommandString = UserCommandString;
6335 unsigned long XLogicalDriveNumber;
6336 while (*UserCommandString == ' ') UserCommandString++;
6337 if (UserCommandString == NewUserCommandString)
6338 return false;
6339 XLogicalDriveNumber =
6340 simple_strtoul(UserCommandString, &NewUserCommandString, 10);
6341 if (NewUserCommandString == UserCommandString ||
6342 *NewUserCommandString != '\0' ||
6343 XLogicalDriveNumber > DAC960_MaxLogicalDrives - 1)
6344 return false;
6345 *LogicalDriveNumber = XLogicalDriveNumber;
6346 return true;
6347 }
6348
6349
6350 /*
6351 DAC960_V1_SetDeviceState sets the Device State for a Physical Device for
6352 DAC960 V1 Firmware Controllers.
6353 */
6354
DAC960_V1_SetDeviceState(DAC960_Controller_T * Controller,DAC960_Command_T * Command,unsigned char Channel,unsigned char TargetID,DAC960_V1_PhysicalDeviceState_T DeviceState,const unsigned char * DeviceStateString)6355 static void DAC960_V1_SetDeviceState(DAC960_Controller_T *Controller,
6356 DAC960_Command_T *Command,
6357 unsigned char Channel,
6358 unsigned char TargetID,
6359 DAC960_V1_PhysicalDeviceState_T
6360 DeviceState,
6361 const unsigned char *DeviceStateString)
6362 {
6363 DAC960_V1_CommandMailbox_T *CommandMailbox = &Command->V1.CommandMailbox;
6364 CommandMailbox->Type3D.CommandOpcode = DAC960_V1_StartDevice;
6365 CommandMailbox->Type3D.Channel = Channel;
6366 CommandMailbox->Type3D.TargetID = TargetID;
6367 CommandMailbox->Type3D.DeviceState = DeviceState;
6368 CommandMailbox->Type3D.Modifier = 0;
6369 DAC960_ExecuteCommand(Command);
6370 switch (Command->V1.CommandStatus)
6371 {
6372 case DAC960_V1_NormalCompletion:
6373 DAC960_UserCritical("%s of Physical Device %d:%d Succeeded\n", Controller,
6374 DeviceStateString, Channel, TargetID);
6375 break;
6376 case DAC960_V1_UnableToStartDevice:
6377 DAC960_UserCritical("%s of Physical Device %d:%d Failed - "
6378 "Unable to Start Device\n", Controller,
6379 DeviceStateString, Channel, TargetID);
6380 break;
6381 case DAC960_V1_NoDeviceAtAddress:
6382 DAC960_UserCritical("%s of Physical Device %d:%d Failed - "
6383 "No Device at Address\n", Controller,
6384 DeviceStateString, Channel, TargetID);
6385 break;
6386 case DAC960_V1_InvalidChannelOrTargetOrModifier:
6387 DAC960_UserCritical("%s of Physical Device %d:%d Failed - "
6388 "Invalid Channel or Target or Modifier\n",
6389 Controller, DeviceStateString, Channel, TargetID);
6390 break;
6391 case DAC960_V1_ChannelBusy:
6392 DAC960_UserCritical("%s of Physical Device %d:%d Failed - "
6393 "Channel Busy\n", Controller,
6394 DeviceStateString, Channel, TargetID);
6395 break;
6396 default:
6397 DAC960_UserCritical("%s of Physical Device %d:%d Failed - "
6398 "Unexpected Status %04X\n", Controller,
6399 DeviceStateString, Channel, TargetID,
6400 Command->V1.CommandStatus);
6401 break;
6402 }
6403 }
6404
6405
6406 /*
6407 DAC960_V1_ExecuteUserCommand executes a User Command for DAC960 V1 Firmware
6408 Controllers.
6409 */
6410
DAC960_V1_ExecuteUserCommand(DAC960_Controller_T * Controller,unsigned char * UserCommand)6411 static boolean DAC960_V1_ExecuteUserCommand(DAC960_Controller_T *Controller,
6412 unsigned char *UserCommand)
6413 {
6414 DAC960_Command_T *Command;
6415 DAC960_V1_CommandMailbox_T *CommandMailbox;
6416 ProcessorFlags_T ProcessorFlags;
6417 unsigned char Channel, TargetID, LogicalDriveNumber;
6418 DAC960_AcquireControllerLock(Controller, &ProcessorFlags);
6419 while ((Command = DAC960_AllocateCommand(Controller)) == NULL)
6420 DAC960_WaitForCommand(Controller);
6421 DAC960_ReleaseControllerLock(Controller, &ProcessorFlags);
6422 Controller->UserStatusLength = 0;
6423 DAC960_V1_ClearCommand(Command);
6424 Command->CommandType = DAC960_ImmediateCommand;
6425 CommandMailbox = &Command->V1.CommandMailbox;
6426 if (strcmp(UserCommand, "flush-cache") == 0)
6427 {
6428 CommandMailbox->Type3.CommandOpcode = DAC960_V1_Flush;
6429 DAC960_ExecuteCommand(Command);
6430 DAC960_UserCritical("Cache Flush Completed\n", Controller);
6431 }
6432 else if (strncmp(UserCommand, "kill", 4) == 0 &&
6433 DAC960_ParsePhysicalDevice(Controller, &UserCommand[4],
6434 &Channel, &TargetID))
6435 {
6436 DAC960_V1_DeviceState_T *DeviceState =
6437 &Controller->V1.DeviceState[Channel][TargetID];
6438 if (DeviceState->Present &&
6439 DeviceState->DeviceType == DAC960_V1_DiskType &&
6440 DeviceState->DeviceState != DAC960_V1_Device_Dead)
6441 DAC960_V1_SetDeviceState(Controller, Command, Channel, TargetID,
6442 DAC960_V1_Device_Dead, "Kill");
6443 else DAC960_UserCritical("Kill of Physical Device %d:%d Illegal\n",
6444 Controller, Channel, TargetID);
6445 }
6446 else if (strncmp(UserCommand, "make-online", 11) == 0 &&
6447 DAC960_ParsePhysicalDevice(Controller, &UserCommand[11],
6448 &Channel, &TargetID))
6449 {
6450 DAC960_V1_DeviceState_T *DeviceState =
6451 &Controller->V1.DeviceState[Channel][TargetID];
6452 if (DeviceState->Present &&
6453 DeviceState->DeviceType == DAC960_V1_DiskType &&
6454 DeviceState->DeviceState == DAC960_V1_Device_Dead)
6455 DAC960_V1_SetDeviceState(Controller, Command, Channel, TargetID,
6456 DAC960_V1_Device_Online, "Make Online");
6457 else DAC960_UserCritical("Make Online of Physical Device %d:%d Illegal\n",
6458 Controller, Channel, TargetID);
6459
6460 }
6461 else if (strncmp(UserCommand, "make-standby", 12) == 0 &&
6462 DAC960_ParsePhysicalDevice(Controller, &UserCommand[12],
6463 &Channel, &TargetID))
6464 {
6465 DAC960_V1_DeviceState_T *DeviceState =
6466 &Controller->V1.DeviceState[Channel][TargetID];
6467 if (DeviceState->Present &&
6468 DeviceState->DeviceType == DAC960_V1_DiskType &&
6469 DeviceState->DeviceState == DAC960_V1_Device_Dead)
6470 DAC960_V1_SetDeviceState(Controller, Command, Channel, TargetID,
6471 DAC960_V1_Device_Standby, "Make Standby");
6472 else DAC960_UserCritical("Make Standby of Physical "
6473 "Device %d:%d Illegal\n",
6474 Controller, Channel, TargetID);
6475 }
6476 else if (strncmp(UserCommand, "rebuild", 7) == 0 &&
6477 DAC960_ParsePhysicalDevice(Controller, &UserCommand[7],
6478 &Channel, &TargetID))
6479 {
6480 CommandMailbox->Type3D.CommandOpcode = DAC960_V1_RebuildAsync;
6481 CommandMailbox->Type3D.Channel = Channel;
6482 CommandMailbox->Type3D.TargetID = TargetID;
6483 DAC960_ExecuteCommand(Command);
6484 switch (Command->V1.CommandStatus)
6485 {
6486 case DAC960_V1_NormalCompletion:
6487 DAC960_UserCritical("Rebuild of Physical Device %d:%d Initiated\n",
6488 Controller, Channel, TargetID);
6489 break;
6490 case DAC960_V1_AttemptToRebuildOnlineDrive:
6491 DAC960_UserCritical("Rebuild of Physical Device %d:%d Failed - "
6492 "Attempt to Rebuild Online or "
6493 "Unresponsive Drive\n",
6494 Controller, Channel, TargetID);
6495 break;
6496 case DAC960_V1_NewDiskFailedDuringRebuild:
6497 DAC960_UserCritical("Rebuild of Physical Device %d:%d Failed - "
6498 "New Disk Failed During Rebuild\n",
6499 Controller, Channel, TargetID);
6500 break;
6501 case DAC960_V1_InvalidDeviceAddress:
6502 DAC960_UserCritical("Rebuild of Physical Device %d:%d Failed - "
6503 "Invalid Device Address\n",
6504 Controller, Channel, TargetID);
6505 break;
6506 case DAC960_V1_RebuildOrCheckAlreadyInProgress:
6507 DAC960_UserCritical("Rebuild of Physical Device %d:%d Failed - "
6508 "Rebuild or Consistency Check Already "
6509 "in Progress\n", Controller, Channel, TargetID);
6510 break;
6511 default:
6512 DAC960_UserCritical("Rebuild of Physical Device %d:%d Failed - "
6513 "Unexpected Status %04X\n", Controller,
6514 Channel, TargetID, Command->V1.CommandStatus);
6515 break;
6516 }
6517 }
6518 else if (strncmp(UserCommand, "check-consistency", 17) == 0 &&
6519 DAC960_ParseLogicalDrive(Controller, &UserCommand[17],
6520 &LogicalDriveNumber))
6521 {
6522 CommandMailbox->Type3C.CommandOpcode = DAC960_V1_CheckConsistencyAsync;
6523 CommandMailbox->Type3C.LogicalDriveNumber = LogicalDriveNumber;
6524 CommandMailbox->Type3C.AutoRestore = true;
6525 DAC960_ExecuteCommand(Command);
6526 switch (Command->V1.CommandStatus)
6527 {
6528 case DAC960_V1_NormalCompletion:
6529 DAC960_UserCritical("Consistency Check of Logical Drive %d "
6530 "(/dev/rd/c%dd%d) Initiated\n",
6531 Controller, LogicalDriveNumber,
6532 Controller->ControllerNumber,
6533 LogicalDriveNumber);
6534 break;
6535 case DAC960_V1_DependentDiskIsDead:
6536 DAC960_UserCritical("Consistency Check of Logical Drive %d "
6537 "(/dev/rd/c%dd%d) Failed - "
6538 "Dependent Physical Device is DEAD\n",
6539 Controller, LogicalDriveNumber,
6540 Controller->ControllerNumber,
6541 LogicalDriveNumber);
6542 break;
6543 case DAC960_V1_InvalidOrNonredundantLogicalDrive:
6544 DAC960_UserCritical("Consistency Check of Logical Drive %d "
6545 "(/dev/rd/c%dd%d) Failed - "
6546 "Invalid or Nonredundant Logical Drive\n",
6547 Controller, LogicalDriveNumber,
6548 Controller->ControllerNumber,
6549 LogicalDriveNumber);
6550 break;
6551 case DAC960_V1_RebuildOrCheckAlreadyInProgress:
6552 DAC960_UserCritical("Consistency Check of Logical Drive %d "
6553 "(/dev/rd/c%dd%d) Failed - Rebuild or "
6554 "Consistency Check Already in Progress\n",
6555 Controller, LogicalDriveNumber,
6556 Controller->ControllerNumber,
6557 LogicalDriveNumber);
6558 break;
6559 default:
6560 DAC960_UserCritical("Consistency Check of Logical Drive %d "
6561 "(/dev/rd/c%dd%d) Failed - "
6562 "Unexpected Status %04X\n",
6563 Controller, LogicalDriveNumber,
6564 Controller->ControllerNumber,
6565 LogicalDriveNumber, Command->V1.CommandStatus);
6566 break;
6567 }
6568 }
6569 else if (strcmp(UserCommand, "cancel-rebuild") == 0 ||
6570 strcmp(UserCommand, "cancel-consistency-check") == 0)
6571 {
6572 unsigned char OldRebuildRateConstant;
6573 CommandMailbox->Type3R.CommandOpcode = DAC960_V1_RebuildControl;
6574 CommandMailbox->Type3R.RebuildRateConstant = 0xFF;
6575 CommandMailbox->Type3R.BusAddress =
6576 Virtual_to_Bus32(&OldRebuildRateConstant);
6577 DAC960_ExecuteCommand(Command);
6578 switch (Command->V1.CommandStatus)
6579 {
6580 case DAC960_V1_NormalCompletion:
6581 DAC960_UserCritical("Rebuild or Consistency Check Cancelled\n",
6582 Controller);
6583 break;
6584 default:
6585 DAC960_UserCritical("Cancellation of Rebuild or "
6586 "Consistency Check Failed - "
6587 "Unexpected Status %04X\n",
6588 Controller, Command->V1.CommandStatus);
6589 break;
6590 }
6591 }
6592 else DAC960_UserCritical("Illegal User Command: '%s'\n",
6593 Controller, UserCommand);
6594 DAC960_AcquireControllerLock(Controller, &ProcessorFlags);
6595 DAC960_DeallocateCommand(Command);
6596 DAC960_ReleaseControllerLock(Controller, &ProcessorFlags);
6597 return true;
6598 }
6599
6600
6601 /*
6602 DAC960_V2_TranslatePhysicalDevice translates a Physical Device Channel and
6603 TargetID into a Logical Device. It returns true on success and false
6604 on failure.
6605 */
6606
DAC960_V2_TranslatePhysicalDevice(DAC960_Command_T * Command,unsigned char Channel,unsigned char TargetID,unsigned short * LogicalDeviceNumber)6607 static boolean DAC960_V2_TranslatePhysicalDevice(DAC960_Command_T *Command,
6608 unsigned char Channel,
6609 unsigned char TargetID,
6610 unsigned short
6611 *LogicalDeviceNumber)
6612 {
6613 DAC960_V2_CommandMailbox_T SavedCommandMailbox, *CommandMailbox;
6614 DAC960_V2_PhysicalToLogicalDevice_T PhysicalToLogicalDevice;
6615 CommandMailbox = &Command->V2.CommandMailbox;
6616 memcpy(&SavedCommandMailbox, CommandMailbox,
6617 sizeof(DAC960_V2_CommandMailbox_T));
6618 CommandMailbox->PhysicalDeviceInfo.CommandOpcode = DAC960_V2_IOCTL;
6619 CommandMailbox->PhysicalDeviceInfo.CommandControlBits
6620 .DataTransferControllerToHost = true;
6621 CommandMailbox->PhysicalDeviceInfo.CommandControlBits
6622 .NoAutoRequestSense = true;
6623 CommandMailbox->PhysicalDeviceInfo.DataTransferSize =
6624 sizeof(DAC960_V2_PhysicalToLogicalDevice_T);
6625 CommandMailbox->PhysicalDeviceInfo.PhysicalDevice.TargetID = TargetID;
6626 CommandMailbox->PhysicalDeviceInfo.PhysicalDevice.Channel = Channel;
6627 CommandMailbox->PhysicalDeviceInfo.IOCTL_Opcode =
6628 DAC960_V2_TranslatePhysicalToLogicalDevice;
6629 CommandMailbox->Common.DataTransferMemoryAddress
6630 .ScatterGatherSegments[0]
6631 .SegmentDataPointer =
6632 Virtual_to_Bus64(&PhysicalToLogicalDevice);
6633 CommandMailbox->Common.DataTransferMemoryAddress
6634 .ScatterGatherSegments[0]
6635 .SegmentByteCount =
6636 CommandMailbox->Common.DataTransferSize;
6637 DAC960_ExecuteCommand(Command);
6638 memcpy(CommandMailbox, &SavedCommandMailbox,
6639 sizeof(DAC960_V2_CommandMailbox_T));
6640 *LogicalDeviceNumber = PhysicalToLogicalDevice.LogicalDeviceNumber;
6641 return (Command->V2.CommandStatus == DAC960_V2_NormalCompletion);
6642 }
6643
6644
6645 /*
6646 DAC960_V2_ExecuteUserCommand executes a User Command for DAC960 V2 Firmware
6647 Controllers.
6648 */
6649
DAC960_V2_ExecuteUserCommand(DAC960_Controller_T * Controller,unsigned char * UserCommand)6650 static boolean DAC960_V2_ExecuteUserCommand(DAC960_Controller_T *Controller,
6651 unsigned char *UserCommand)
6652 {
6653 DAC960_Command_T *Command;
6654 DAC960_V2_CommandMailbox_T *CommandMailbox;
6655 ProcessorFlags_T ProcessorFlags;
6656 unsigned char Channel, TargetID, LogicalDriveNumber;
6657 unsigned short LogicalDeviceNumber;
6658 DAC960_AcquireControllerLock(Controller, &ProcessorFlags);
6659 while ((Command = DAC960_AllocateCommand(Controller)) == NULL)
6660 DAC960_WaitForCommand(Controller);
6661 DAC960_ReleaseControllerLock(Controller, &ProcessorFlags);
6662 Controller->UserStatusLength = 0;
6663 DAC960_V2_ClearCommand(Command);
6664 Command->CommandType = DAC960_ImmediateCommand;
6665 CommandMailbox = &Command->V2.CommandMailbox;
6666 CommandMailbox->Common.CommandOpcode = DAC960_V2_IOCTL;
6667 CommandMailbox->Common.CommandControlBits.DataTransferControllerToHost = true;
6668 CommandMailbox->Common.CommandControlBits.NoAutoRequestSense = true;
6669 if (strcmp(UserCommand, "flush-cache") == 0)
6670 {
6671 CommandMailbox->DeviceOperation.IOCTL_Opcode = DAC960_V2_PauseDevice;
6672 CommandMailbox->DeviceOperation.OperationDevice =
6673 DAC960_V2_RAID_Controller;
6674 DAC960_ExecuteCommand(Command);
6675 DAC960_UserCritical("Cache Flush Completed\n", Controller);
6676 }
6677 else if (strncmp(UserCommand, "kill", 4) == 0 &&
6678 DAC960_ParsePhysicalDevice(Controller, &UserCommand[4],
6679 &Channel, &TargetID) &&
6680 DAC960_V2_TranslatePhysicalDevice(Command, Channel, TargetID,
6681 &LogicalDeviceNumber))
6682 {
6683 CommandMailbox->SetDeviceState.LogicalDevice.LogicalDeviceNumber =
6684 LogicalDeviceNumber;
6685 CommandMailbox->SetDeviceState.IOCTL_Opcode =
6686 DAC960_V2_SetDeviceState;
6687 CommandMailbox->SetDeviceState.DeviceState.PhysicalDeviceState =
6688 DAC960_V2_Device_Dead;
6689 DAC960_ExecuteCommand(Command);
6690 DAC960_UserCritical("Kill of Physical Device %d:%d %s\n",
6691 Controller, Channel, TargetID,
6692 (Command->V2.CommandStatus
6693 == DAC960_V2_NormalCompletion
6694 ? "Succeeded" : "Failed"));
6695 }
6696 else if (strncmp(UserCommand, "make-online", 11) == 0 &&
6697 DAC960_ParsePhysicalDevice(Controller, &UserCommand[11],
6698 &Channel, &TargetID) &&
6699 DAC960_V2_TranslatePhysicalDevice(Command, Channel, TargetID,
6700 &LogicalDeviceNumber))
6701 {
6702 CommandMailbox->SetDeviceState.LogicalDevice.LogicalDeviceNumber =
6703 LogicalDeviceNumber;
6704 CommandMailbox->SetDeviceState.IOCTL_Opcode =
6705 DAC960_V2_SetDeviceState;
6706 CommandMailbox->SetDeviceState.DeviceState.PhysicalDeviceState =
6707 DAC960_V2_Device_Online;
6708 DAC960_ExecuteCommand(Command);
6709 DAC960_UserCritical("Make Online of Physical Device %d:%d %s\n",
6710 Controller, Channel, TargetID,
6711 (Command->V2.CommandStatus
6712 == DAC960_V2_NormalCompletion
6713 ? "Succeeded" : "Failed"));
6714 }
6715 else if (strncmp(UserCommand, "make-standby", 12) == 0 &&
6716 DAC960_ParsePhysicalDevice(Controller, &UserCommand[12],
6717 &Channel, &TargetID) &&
6718 DAC960_V2_TranslatePhysicalDevice(Command, Channel, TargetID,
6719 &LogicalDeviceNumber))
6720 {
6721 CommandMailbox->SetDeviceState.LogicalDevice.LogicalDeviceNumber =
6722 LogicalDeviceNumber;
6723 CommandMailbox->SetDeviceState.IOCTL_Opcode =
6724 DAC960_V2_SetDeviceState;
6725 CommandMailbox->SetDeviceState.DeviceState.PhysicalDeviceState =
6726 DAC960_V2_Device_Standby;
6727 DAC960_ExecuteCommand(Command);
6728 DAC960_UserCritical("Make Standby of Physical Device %d:%d %s\n",
6729 Controller, Channel, TargetID,
6730 (Command->V2.CommandStatus
6731 == DAC960_V2_NormalCompletion
6732 ? "Succeeded" : "Failed"));
6733 }
6734 else if (strncmp(UserCommand, "rebuild", 7) == 0 &&
6735 DAC960_ParsePhysicalDevice(Controller, &UserCommand[7],
6736 &Channel, &TargetID) &&
6737 DAC960_V2_TranslatePhysicalDevice(Command, Channel, TargetID,
6738 &LogicalDeviceNumber))
6739 {
6740 CommandMailbox->LogicalDeviceInfo.LogicalDevice.LogicalDeviceNumber =
6741 LogicalDeviceNumber;
6742 CommandMailbox->LogicalDeviceInfo.IOCTL_Opcode =
6743 DAC960_V2_RebuildDeviceStart;
6744 DAC960_ExecuteCommand(Command);
6745 DAC960_UserCritical("Rebuild of Physical Device %d:%d %s\n",
6746 Controller, Channel, TargetID,
6747 (Command->V2.CommandStatus
6748 == DAC960_V2_NormalCompletion
6749 ? "Initiated" : "Not Initiated"));
6750 }
6751 else if (strncmp(UserCommand, "cancel-rebuild", 14) == 0 &&
6752 DAC960_ParsePhysicalDevice(Controller, &UserCommand[14],
6753 &Channel, &TargetID) &&
6754 DAC960_V2_TranslatePhysicalDevice(Command, Channel, TargetID,
6755 &LogicalDeviceNumber))
6756 {
6757 CommandMailbox->LogicalDeviceInfo.LogicalDevice.LogicalDeviceNumber =
6758 LogicalDeviceNumber;
6759 CommandMailbox->LogicalDeviceInfo.IOCTL_Opcode =
6760 DAC960_V2_RebuildDeviceStop;
6761 DAC960_ExecuteCommand(Command);
6762 DAC960_UserCritical("Rebuild of Physical Device %d:%d %s\n",
6763 Controller, Channel, TargetID,
6764 (Command->V2.CommandStatus
6765 == DAC960_V2_NormalCompletion
6766 ? "Cancelled" : "Not Cancelled"));
6767 }
6768 else if (strncmp(UserCommand, "check-consistency", 17) == 0 &&
6769 DAC960_ParseLogicalDrive(Controller, &UserCommand[17],
6770 &LogicalDriveNumber))
6771 {
6772 CommandMailbox->ConsistencyCheck.LogicalDevice.LogicalDeviceNumber =
6773 LogicalDriveNumber;
6774 CommandMailbox->ConsistencyCheck.IOCTL_Opcode =
6775 DAC960_V2_ConsistencyCheckStart;
6776 CommandMailbox->ConsistencyCheck.RestoreConsistency = true;
6777 CommandMailbox->ConsistencyCheck.InitializedAreaOnly = false;
6778 DAC960_ExecuteCommand(Command);
6779 DAC960_UserCritical("Consistency Check of Logical Drive %d "
6780 "(/dev/rd/c%dd%d) %s\n",
6781 Controller, LogicalDriveNumber,
6782 Controller->ControllerNumber,
6783 LogicalDriveNumber,
6784 (Command->V2.CommandStatus
6785 == DAC960_V2_NormalCompletion
6786 ? "Initiated" : "Not Initiated"));
6787 }
6788 else if (strncmp(UserCommand, "cancel-consistency-check", 24) == 0 &&
6789 DAC960_ParseLogicalDrive(Controller, &UserCommand[24],
6790 &LogicalDriveNumber))
6791 {
6792 CommandMailbox->ConsistencyCheck.LogicalDevice.LogicalDeviceNumber =
6793 LogicalDriveNumber;
6794 CommandMailbox->ConsistencyCheck.IOCTL_Opcode =
6795 DAC960_V2_ConsistencyCheckStop;
6796 DAC960_ExecuteCommand(Command);
6797 DAC960_UserCritical("Consistency Check of Logical Drive %d "
6798 "(/dev/rd/c%dd%d) %s\n",
6799 Controller, LogicalDriveNumber,
6800 Controller->ControllerNumber,
6801 LogicalDriveNumber,
6802 (Command->V2.CommandStatus
6803 == DAC960_V2_NormalCompletion
6804 ? "Cancelled" : "Not Cancelled"));
6805 }
6806 else if (strcmp(UserCommand, "perform-discovery") == 0)
6807 {
6808 CommandMailbox->Common.IOCTL_Opcode = DAC960_V2_StartDiscovery;
6809 DAC960_ExecuteCommand(Command);
6810 DAC960_UserCritical("Discovery %s\n", Controller,
6811 (Command->V2.CommandStatus
6812 == DAC960_V2_NormalCompletion
6813 ? "Initiated" : "Not Initiated"));
6814 if (Command->V2.CommandStatus == DAC960_V2_NormalCompletion)
6815 {
6816 CommandMailbox->ControllerInfo.CommandOpcode = DAC960_V2_IOCTL;
6817 CommandMailbox->ControllerInfo.CommandControlBits
6818 .DataTransferControllerToHost = true;
6819 CommandMailbox->ControllerInfo.CommandControlBits
6820 .NoAutoRequestSense = true;
6821 CommandMailbox->ControllerInfo.DataTransferSize =
6822 sizeof(DAC960_V2_ControllerInfo_T);
6823 CommandMailbox->ControllerInfo.ControllerNumber = 0;
6824 CommandMailbox->ControllerInfo.IOCTL_Opcode =
6825 DAC960_V2_GetControllerInfo;
6826 CommandMailbox->ControllerInfo.DataTransferMemoryAddress
6827 .ScatterGatherSegments[0]
6828 .SegmentDataPointer =
6829 Virtual_to_Bus64(&Controller->V2.NewControllerInformation);
6830 CommandMailbox->ControllerInfo.DataTransferMemoryAddress
6831 .ScatterGatherSegments[0]
6832 .SegmentByteCount =
6833 CommandMailbox->ControllerInfo.DataTransferSize;
6834 DAC960_ExecuteCommand(Command);
6835 while (Controller->V2.NewControllerInformation.PhysicalScanActive)
6836 {
6837 DAC960_ExecuteCommand(Command);
6838 sleep_on_timeout(&Controller->CommandWaitQueue, HZ);
6839 }
6840 DAC960_UserCritical("Discovery Completed\n", Controller);
6841 }
6842 }
6843 else if (strcmp(UserCommand, "suppress-enclosure-messages") == 0)
6844 Controller->SuppressEnclosureMessages = true;
6845 else DAC960_UserCritical("Illegal User Command: '%s'\n",
6846 Controller, UserCommand);
6847 DAC960_AcquireControllerLock(Controller, &ProcessorFlags);
6848 DAC960_DeallocateCommand(Command);
6849 DAC960_ReleaseControllerLock(Controller, &ProcessorFlags);
6850 return true;
6851 }
6852
6853
6854 /*
6855 DAC960_ProcReadStatus implements reading /proc/rd/status.
6856 */
6857
DAC960_ProcReadStatus(char * Page,char ** Start,off_t Offset,int Count,int * EOF,void * Data)6858 static int DAC960_ProcReadStatus(char *Page, char **Start, off_t Offset,
6859 int Count, int *EOF, void *Data)
6860 {
6861 unsigned char *StatusMessage = "OK\n";
6862 int ControllerNumber, BytesAvailable;
6863 for (ControllerNumber = 0;
6864 ControllerNumber < DAC960_ControllerCount;
6865 ControllerNumber++)
6866 {
6867 DAC960_Controller_T *Controller = DAC960_Controllers[ControllerNumber];
6868 if (Controller == NULL) continue;
6869 if (Controller->MonitoringAlertMode)
6870 {
6871 StatusMessage = "ALERT\n";
6872 break;
6873 }
6874 }
6875 BytesAvailable = strlen(StatusMessage) - Offset;
6876 if (Count >= BytesAvailable)
6877 {
6878 Count = BytesAvailable;
6879 *EOF = true;
6880 }
6881 if (Count <= 0) return 0;
6882 *Start = Page;
6883 memcpy(Page, &StatusMessage[Offset], Count);
6884 return Count;
6885 }
6886
6887
6888 /*
6889 DAC960_ProcReadInitialStatus implements reading /proc/rd/cN/initial_status.
6890 */
6891
DAC960_ProcReadInitialStatus(char * Page,char ** Start,off_t Offset,int Count,int * EOF,void * Data)6892 static int DAC960_ProcReadInitialStatus(char *Page, char **Start, off_t Offset,
6893 int Count, int *EOF, void *Data)
6894 {
6895 DAC960_Controller_T *Controller = (DAC960_Controller_T *) Data;
6896 int BytesAvailable = Controller->InitialStatusLength - Offset;
6897 if (Count >= BytesAvailable)
6898 {
6899 Count = BytesAvailable;
6900 *EOF = true;
6901 }
6902 if (Count <= 0) return 0;
6903 *Start = Page;
6904 memcpy(Page, &Controller->CombinedStatusBuffer[Offset], Count);
6905 return Count;
6906 }
6907
6908
6909 /*
6910 DAC960_ProcReadCurrentStatus implements reading /proc/rd/cN/current_status.
6911 */
6912
DAC960_ProcReadCurrentStatus(char * Page,char ** Start,off_t Offset,int Count,int * EOF,void * Data)6913 static int DAC960_ProcReadCurrentStatus(char *Page, char **Start, off_t Offset,
6914 int Count, int *EOF, void *Data)
6915 {
6916 DAC960_Controller_T *Controller = (DAC960_Controller_T *) Data;
6917 unsigned char *StatusMessage =
6918 "No Rebuild or Consistency Check in Progress\n";
6919 int ProgressMessageLength = strlen(StatusMessage);
6920 int BytesAvailable;
6921 if (jiffies != Controller->LastCurrentStatusTime)
6922 {
6923 Controller->CurrentStatusLength = 0;
6924 DAC960_AnnounceDriver(Controller);
6925 DAC960_ReportControllerConfiguration(Controller);
6926 DAC960_ReportDeviceConfiguration(Controller);
6927 if (Controller->ProgressBufferLength > 0)
6928 ProgressMessageLength = Controller->ProgressBufferLength;
6929 if (DAC960_CheckStatusBuffer(Controller, 2 + ProgressMessageLength))
6930 {
6931 unsigned char *CurrentStatusBuffer = Controller->CurrentStatusBuffer;
6932 CurrentStatusBuffer[Controller->CurrentStatusLength++] = ' ';
6933 CurrentStatusBuffer[Controller->CurrentStatusLength++] = ' ';
6934 if (Controller->ProgressBufferLength > 0)
6935 strcpy(&CurrentStatusBuffer[Controller->CurrentStatusLength],
6936 Controller->ProgressBuffer);
6937 else
6938 strcpy(&CurrentStatusBuffer[Controller->CurrentStatusLength],
6939 StatusMessage);
6940 Controller->CurrentStatusLength += ProgressMessageLength;
6941 }
6942 Controller->LastCurrentStatusTime = jiffies;
6943 }
6944 BytesAvailable = Controller->CurrentStatusLength - Offset;
6945 if (Count >= BytesAvailable)
6946 {
6947 Count = BytesAvailable;
6948 *EOF = true;
6949 }
6950 if (Count <= 0) return 0;
6951 *Start = Page;
6952 memcpy(Page, &Controller->CurrentStatusBuffer[Offset], Count);
6953 return Count;
6954 }
6955
6956
6957 /*
6958 DAC960_ProcReadUserCommand implements reading /proc/rd/cN/user_command.
6959 */
6960
DAC960_ProcReadUserCommand(char * Page,char ** Start,off_t Offset,int Count,int * EOF,void * Data)6961 static int DAC960_ProcReadUserCommand(char *Page, char **Start, off_t Offset,
6962 int Count, int *EOF, void *Data)
6963 {
6964 DAC960_Controller_T *Controller = (DAC960_Controller_T *) Data;
6965 int BytesAvailable = Controller->UserStatusLength - Offset;
6966 if (Count >= BytesAvailable)
6967 {
6968 Count = BytesAvailable;
6969 *EOF = true;
6970 }
6971 if (Count <= 0) return 0;
6972 *Start = Page;
6973 memcpy(Page, &Controller->UserStatusBuffer[Offset], Count);
6974 return Count;
6975 }
6976
6977
6978 /*
6979 DAC960_ProcWriteUserCommand implements writing /proc/rd/cN/user_command.
6980 */
6981
DAC960_ProcWriteUserCommand(File_T * File,const char * Buffer,unsigned long Count,void * Data)6982 static int DAC960_ProcWriteUserCommand(File_T *File, const char *Buffer,
6983 unsigned long Count, void *Data)
6984 {
6985 DAC960_Controller_T *Controller = (DAC960_Controller_T *) Data;
6986 unsigned char CommandBuffer[80];
6987 int Length;
6988 if (Count > sizeof(CommandBuffer)-1) return -EINVAL;
6989 if (copy_from_user(CommandBuffer, Buffer, Count)) return -EFAULT;
6990 CommandBuffer[Count] = '\0';
6991 Length = strlen(CommandBuffer);
6992 if (CommandBuffer[Length-1] == '\n')
6993 CommandBuffer[--Length] = '\0';
6994 if (Controller->FirmwareType == DAC960_V1_Controller)
6995 return (DAC960_V1_ExecuteUserCommand(Controller, CommandBuffer)
6996 ? Count : -EBUSY);
6997 else
6998 return (DAC960_V2_ExecuteUserCommand(Controller, CommandBuffer)
6999 ? Count : -EBUSY);
7000 }
7001
7002
7003 /*
7004 DAC960_CreateProcEntries creates the /proc/rd/... entries for the
7005 DAC960 Driver.
7006 */
7007
DAC960_CreateProcEntries(void)7008 static void DAC960_CreateProcEntries(void)
7009 {
7010 PROC_DirectoryEntry_T *StatusProcEntry;
7011 int ControllerNumber;
7012 DAC960_ProcDirectoryEntry = proc_mkdir("rd", NULL);
7013 StatusProcEntry = create_proc_read_entry("status", 0,
7014 DAC960_ProcDirectoryEntry,
7015 DAC960_ProcReadStatus, NULL);
7016 for (ControllerNumber = 0;
7017 ControllerNumber < DAC960_ControllerCount;
7018 ControllerNumber++)
7019 {
7020 DAC960_Controller_T *Controller = DAC960_Controllers[ControllerNumber];
7021 PROC_DirectoryEntry_T *ControllerProcEntry;
7022 PROC_DirectoryEntry_T *UserCommandProcEntry;
7023 if (Controller == NULL) continue;
7024 sprintf(Controller->ControllerName, "c%d", Controller->ControllerNumber);
7025 ControllerProcEntry = proc_mkdir(Controller->ControllerName,
7026 DAC960_ProcDirectoryEntry);
7027 create_proc_read_entry("initial_status", 0, ControllerProcEntry,
7028 DAC960_ProcReadInitialStatus, Controller);
7029 create_proc_read_entry("current_status", 0, ControllerProcEntry,
7030 DAC960_ProcReadCurrentStatus, Controller);
7031 UserCommandProcEntry =
7032 create_proc_read_entry("user_command", S_IWUSR | S_IRUSR,
7033 ControllerProcEntry, DAC960_ProcReadUserCommand,
7034 Controller);
7035 UserCommandProcEntry->write_proc = DAC960_ProcWriteUserCommand;
7036 Controller->ControllerProcEntry = ControllerProcEntry;
7037 }
7038 }
7039
7040
7041 /*
7042 DAC960_DestroyProcEntries destroys the /proc/rd/... entries for the
7043 DAC960 Driver.
7044 */
7045
DAC960_DestroyProcEntries(void)7046 static void DAC960_DestroyProcEntries(void)
7047 {
7048 int ControllerNumber;
7049 for (ControllerNumber = 0;
7050 ControllerNumber < DAC960_ControllerCount;
7051 ControllerNumber++)
7052 {
7053 DAC960_Controller_T *Controller = DAC960_Controllers[ControllerNumber];
7054 if (Controller == NULL) continue;
7055 remove_proc_entry("initial_status", Controller->ControllerProcEntry);
7056 remove_proc_entry("current_status", Controller->ControllerProcEntry);
7057 remove_proc_entry("user_command", Controller->ControllerProcEntry);
7058 remove_proc_entry(Controller->ControllerName, DAC960_ProcDirectoryEntry);
7059 }
7060 remove_proc_entry("rd/status", NULL);
7061 remove_proc_entry("rd", NULL);
7062 }
7063
7064
7065 module_init(DAC960_Initialize);
7066 module_exit(DAC960_Finalize);
7067
7068 MODULE_LICENSE("GPL");
7069