ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / drivers / scsi / BusLogic.h
1 /*
2
3   Linux Driver for BusLogic MultiMaster and FlashPoint SCSI Host Adapters
4
5   Copyright 1995-1998 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   Special thanks to Wayne Yen, Jin-Lon Hon, and Alex Win of BusLogic, whose
20   advice has been invaluable, to David Gentzel, for writing the original Linux
21   BusLogic driver, and to Paul Gortmaker, for being such a dedicated test site.
22
23   Finally, special thanks to Mylex/BusLogic for making the FlashPoint SCCB
24   Manager available as freely redistributable source code.
25
26 */
27
28 #ifndef _BUSLOGIC_H
29 #define _BUSLOGIC_H
30
31 #include <linux/config.h>
32
33 #ifndef PACKED
34 #define PACKED __attribute__((packed))
35 #endif
36
37 /*
38   FlashPoint support is only available for the Intel x86 Architecture with
39   CONFIG_PCI set.
40 */
41
42 #ifndef __i386__
43 #undef CONFIG_SCSI_OMIT_FLASHPOINT
44 #define CONFIG_SCSI_OMIT_FLASHPOINT
45 #endif
46
47 #ifndef CONFIG_PCI
48 #undef CONFIG_SCSI_OMIT_FLASHPOINT
49 #define CONFIG_SCSI_OMIT_FLASHPOINT
50 #define BusLogic_InitializeProbeInfoListISA BusLogic_InitializeProbeInfoList
51 #endif
52
53
54 /*
55   Define the maximum number of BusLogic Host Adapters supported by this driver.
56 */
57
58 #define BusLogic_MaxHostAdapters                16
59
60
61 /*
62   Define the maximum number of Target Devices supported by this driver.
63 */
64
65 #define BusLogic_MaxTargetDevices               16
66
67
68 /*
69   Define the maximum number of Scatter/Gather Segments used by this driver.
70   For optimal performance, it is important that this limit be at least as
71   large as the largest single request generated by the I/O Subsystem.
72 */
73
74 #define BusLogic_ScatterGatherLimit             128
75
76
77 /*
78   Define the maximum, maximum automatic, minimum automatic, and default Queue
79   Depth to allow for Target Devices depending on whether or not they support
80   Tagged Queuing and whether or not ISA Bounce Buffers are required.
81 */
82
83 #define BusLogic_MaxTaggedQueueDepth            64
84 #define BusLogic_MaxAutomaticTaggedQueueDepth   28
85 #define BusLogic_MinAutomaticTaggedQueueDepth   7
86 #define BusLogic_TaggedQueueDepthBB             3
87 #define BusLogic_UntaggedQueueDepth             3
88 #define BusLogic_UntaggedQueueDepthBB           2
89
90
91 /*
92   Define the default amount of time in seconds to wait between a Host Adapter
93   Hard Reset which initiates a SCSI Bus Reset and issuing any SCSI commands.
94   Some SCSI devices get confused if they receive SCSI commands too soon after
95   a SCSI Bus Reset.
96 */
97
98 #define BusLogic_DefaultBusSettleTime           2
99
100
101 /*
102   Define the maximum number of Mailboxes that should be used for MultiMaster
103   Host Adapters.  This number is chosen to be larger than the maximum Host
104   Adapter Queue Depth and small enough so that the Host Adapter structure
105   does not cross an allocation block size boundary.
106 */
107
108 #define BusLogic_MaxMailboxes                   211
109
110
111 /*
112   Define the number of CCBs that should be allocated as a group to optimize
113   Kernel memory allocation.
114 */
115
116 #define BusLogic_CCB_AllocationGroupSize        7
117
118
119 /*
120   Define the Host Adapter Line and Message Buffer Sizes.
121 */
122
123 #define BusLogic_LineBufferSize                 100
124 #define BusLogic_MessageBufferSize              9700
125
126
127 /*
128   Define the Driver Message Levels.
129 */
130
131 enum BusLogic_MessageLevel
132 {
133   BusLogic_AnnounceLevel =                      0,
134   BusLogic_InfoLevel =                          1,
135   BusLogic_NoticeLevel =                        2,
136   BusLogic_WarningLevel =                       3,
137   BusLogic_ErrorLevel =                         4
138 };
139
140 static char *BusLogic_MessageLevelMap[] =
141     { KERN_NOTICE, KERN_NOTICE, KERN_NOTICE, KERN_WARNING, KERN_ERR };
142
143
144 /*
145   Define Driver Message macros.
146 */
147
148 #define BusLogic_Announce(Format, Arguments...) \
149   BusLogic_Message(BusLogic_AnnounceLevel, Format, ##Arguments)
150
151 #define BusLogic_Info(Format, Arguments...) \
152   BusLogic_Message(BusLogic_InfoLevel, Format, ##Arguments)
153
154 #define BusLogic_Notice(Format, Arguments...) \
155   BusLogic_Message(BusLogic_NoticeLevel, Format, ##Arguments)
156
157 #define BusLogic_Warning(Format, Arguments...) \
158   BusLogic_Message(BusLogic_WarningLevel, Format, ##Arguments)
159
160 #define BusLogic_Error(Format, Arguments...) \
161   BusLogic_Message(BusLogic_ErrorLevel, Format, ##Arguments)
162
163
164 /*
165   Define the types of BusLogic Host Adapters that are supported and the number
166   of I/O Addresses required by each type.
167 */
168
169 enum BusLogic_HostAdapterType
170 {
171   BusLogic_MultiMaster =                        1,
172   BusLogic_FlashPoint =                         2
173 } PACKED;
174
175 #define BusLogic_MultiMasterAddressCount        4
176 #define BusLogic_FlashPointAddressCount         256
177
178 static int BusLogic_HostAdapterAddressCount[3] =
179     { 0, BusLogic_MultiMasterAddressCount, BusLogic_FlashPointAddressCount };
180
181
182 /*
183   Define macros for testing the Host Adapter Type.
184 */
185
186 #ifndef CONFIG_SCSI_OMIT_FLASHPOINT
187
188 #define BusLogic_MultiMasterHostAdapterP(HostAdapter) \
189   (HostAdapter->HostAdapterType == BusLogic_MultiMaster)
190
191 #define BusLogic_FlashPointHostAdapterP(HostAdapter) \
192   (HostAdapter->HostAdapterType == BusLogic_FlashPoint)
193
194 #else
195
196 #define BusLogic_MultiMasterHostAdapterP(HostAdapter) \
197   (true)
198
199 #define BusLogic_FlashPointHostAdapterP(HostAdapter) \
200   (false)
201
202 #endif
203
204
205 /*
206   Define the possible Host Adapter Bus Types.
207 */
208
209 enum BusLogic_HostAdapterBusType
210 {
211   BusLogic_Unknown_Bus =                        0,
212   BusLogic_ISA_Bus =                            1,
213   BusLogic_EISA_Bus =                           2,
214   BusLogic_PCI_Bus =                            3,
215   BusLogic_VESA_Bus =                           4,
216   BusLogic_MCA_Bus =                            5
217 } PACKED;
218
219 static char *BusLogic_HostAdapterBusNames[] =
220     { "Unknown", "ISA", "EISA", "PCI", "VESA", "MCA" };
221
222 static enum BusLogic_HostAdapterBusType BusLogic_HostAdapterBusTypes[] =
223 {
224   BusLogic_VESA_Bus,                            /* BT-4xx */
225   BusLogic_ISA_Bus,                             /* BT-5xx */
226   BusLogic_MCA_Bus,                             /* BT-6xx */
227   BusLogic_EISA_Bus,                            /* BT-7xx */
228   BusLogic_Unknown_Bus,                         /* BT-8xx */
229   BusLogic_PCI_Bus                              /* BT-9xx */
230 };
231
232 /*
233   Define the possible Host Adapter BIOS Disk Geometry Translations.
234 */
235
236 enum BusLogic_BIOS_DiskGeometryTranslation
237 {
238   BusLogic_BIOS_Disk_Not_Installed =            0,
239   BusLogic_BIOS_Disk_Installed_64x32 =          1,
240   BusLogic_BIOS_Disk_Installed_128x32 =         2,
241   BusLogic_BIOS_Disk_Installed_255x63 =         3
242 } PACKED;
243
244
245 /*
246   Define a Boolean data type.
247 */
248
249 typedef enum {
250   false,
251   true
252 } PACKED boolean;
253
254 /*
255   Define a 10^18 Statistics Byte Counter data type.
256 */
257
258 struct BusLogic_ByteCounter
259 {
260   unsigned int Units;
261   unsigned int Billions;
262 };
263
264
265 /*
266   Define the structure for I/O Address and Bus Probing Information.
267 */
268
269 struct BusLogic_ProbeInfo
270 {
271   enum BusLogic_HostAdapterType HostAdapterType;
272   enum BusLogic_HostAdapterBusType HostAdapterBusType;
273   unsigned long IO_Address;
274   unsigned long PCI_Address;
275   struct pci_dev *PCI_Device;
276   unsigned char Bus;
277   unsigned char Device;
278   unsigned char IRQ_Channel;
279 };
280
281 /*
282   Define the Probe Options.
283 */
284
285 struct BusLogic_ProbeOptions
286 {
287   boolean NoProbe:1;                                    /* Bit 0 */
288   boolean NoProbeISA:1;                                 /* Bit 1 */
289   boolean NoProbePCI:1;                                 /* Bit 2 */
290   boolean NoSortPCI:1;                                  /* Bit 3 */
291   boolean MultiMasterFirst:1;                           /* Bit 4 */
292   boolean FlashPointFirst:1;                            /* Bit 5 */
293   boolean LimitedProbeISA:1;                            /* Bit 6 */
294   boolean Probe330:1;                                   /* Bit 7 */
295   boolean Probe334:1;                                   /* Bit 8 */
296   boolean Probe230:1;                                   /* Bit 9 */
297   boolean Probe234:1;                                   /* Bit 10 */
298   boolean Probe130:1;                                   /* Bit 11 */
299   boolean Probe134:1;                                   /* Bit 12 */
300 };
301
302 /*
303   Define the Global Options.
304 */
305
306 struct BusLogic_GlobalOptions
307 {
308   boolean TraceProbe:1;                                 /* Bit 0 */
309   boolean TraceHardwareReset:1;                         /* Bit 1 */
310   boolean TraceConfiguration:1;                         /* Bit 2 */
311   boolean TraceErrors:1;                                /* Bit 3 */
312 };
313
314 /*
315   Define the Local Options.
316 */
317
318 struct BusLogic_LocalOptions
319 {
320   boolean InhibitTargetInquiry:1;                       /* Bit 0 */
321 };
322
323 /*
324   Define the BusLogic SCSI Host Adapter I/O Register Offsets.
325 */
326
327 #define BusLogic_ControlRegisterOffset          0       /* WO register */
328 #define BusLogic_StatusRegisterOffset           0       /* RO register */
329 #define BusLogic_CommandParameterRegisterOffset 1       /* WO register */
330 #define BusLogic_DataInRegisterOffset           1       /* RO register */
331 #define BusLogic_InterruptRegisterOffset        2       /* RO register */
332 #define BusLogic_GeometryRegisterOffset         3       /* RO register */
333
334 /*
335   Define the structure of the write-only Control Register.
336 */
337
338 union BusLogic_ControlRegister
339 {
340   unsigned char All;
341   struct {
342     unsigned char :4;                                   /* Bits 0-3 */
343     boolean SCSIBusReset:1;                             /* Bit 4 */
344     boolean InterruptReset:1;                           /* Bit 5 */
345     boolean SoftReset:1;                                /* Bit 6 */
346     boolean HardReset:1;                                /* Bit 7 */
347   } cr;
348 };
349
350 /*
351   Define the structure of the read-only Status Register.
352 */
353
354 union BusLogic_StatusRegister
355 {
356   unsigned char All;
357   struct {
358     boolean CommandInvalid:1;                           /* Bit 0 */
359     boolean Reserved:1;                                 /* Bit 1 */
360     boolean DataInRegisterReady:1;                      /* Bit 2 */
361     boolean CommandParameterRegisterBusy:1;             /* Bit 3 */
362     boolean HostAdapterReady:1;                         /* Bit 4 */
363     boolean InitializationRequired:1;                   /* Bit 5 */
364     boolean DiagnosticFailure:1;                        /* Bit 6 */
365     boolean DiagnosticActive:1;                         /* Bit 7 */
366   } sr;
367 };
368
369 /*
370   Define the structure of the read-only Interrupt Register.
371 */
372
373 union BusLogic_InterruptRegister
374 {
375   unsigned char All;
376   struct {
377     boolean IncomingMailboxLoaded:1;                    /* Bit 0 */
378     boolean OutgoingMailboxAvailable:1;                 /* Bit 1 */
379     boolean CommandComplete:1;                          /* Bit 2 */
380     boolean ExternalBusReset:1;                         /* Bit 3 */
381     unsigned char Reserved:3;                           /* Bits 4-6 */
382     boolean InterruptValid:1;                           /* Bit 7 */
383   } ir;
384 };
385
386 /*
387   Define the structure of the read-only Geometry Register.
388 */
389
390 union BusLogic_GeometryRegister
391 {
392   unsigned char All;
393   struct {
394     enum BusLogic_BIOS_DiskGeometryTranslation Drive0Geometry:2;/* Bits 0-1 */
395     enum BusLogic_BIOS_DiskGeometryTranslation Drive1Geometry:2;/* Bits 2-3 */
396     unsigned char :3;                                           /* Bits 4-6 */
397     boolean ExtendedTranslationEnabled:1;                       /* Bit 7 */
398   } gr;
399 };
400
401 /*
402   Define the BusLogic SCSI Host Adapter Command Register Operation Codes.
403 */
404
405 enum BusLogic_OperationCode
406 {
407   BusLogic_TestCommandCompleteInterrupt =               0x00,
408   BusLogic_InitializeMailbox =                          0x01,
409   BusLogic_ExecuteMailboxCommand =                      0x02,
410   BusLogic_ExecuteBIOSCommand =                         0x03,
411   BusLogic_InquireBoardID =                             0x04,
412   BusLogic_EnableOutgoingMailboxAvailableInt =          0x05,
413   BusLogic_SetSCSISelectionTimeout =                    0x06,
414   BusLogic_SetPreemptTimeOnBus =                        0x07,
415   BusLogic_SetTimeOffBus =                              0x08,
416   BusLogic_SetBusTransferRate =                         0x09,
417   BusLogic_InquireInstalledDevicesID0to7 =              0x0A,
418   BusLogic_InquireConfiguration =                       0x0B,
419   BusLogic_EnableTargetMode =                           0x0C,
420   BusLogic_InquireSetupInformation =                    0x0D,
421   BusLogic_WriteAdapterLocalRAM =                       0x1A,
422   BusLogic_ReadAdapterLocalRAM =                        0x1B,
423   BusLogic_WriteBusMasterChipFIFO =                     0x1C,
424   BusLogic_ReadBusMasterChipFIFO =                      0x1D,
425   BusLogic_EchoCommandData =                            0x1F,
426   BusLogic_HostAdapterDiagnostic =                      0x20,
427   BusLogic_SetAdapterOptions =                          0x21,
428   BusLogic_InquireInstalledDevicesID8to15 =             0x23,
429   BusLogic_InquireTargetDevices =                       0x24,
430   BusLogic_DisableHostAdapterInterrupt =                0x25,
431   BusLogic_InitializeExtendedMailbox =                  0x81,
432   BusLogic_ExecuteSCSICommand =                         0x83,
433   BusLogic_InquireFirmwareVersion3rdDigit =             0x84,
434   BusLogic_InquireFirmwareVersionLetter =               0x85,
435   BusLogic_InquirePCIHostAdapterInformation =           0x86,
436   BusLogic_InquireHostAdapterModelNumber =              0x8B,
437   BusLogic_InquireSynchronousPeriod =                   0x8C,
438   BusLogic_InquireExtendedSetupInformation =            0x8D,
439   BusLogic_EnableStrictRoundRobinMode =                 0x8F,
440   BusLogic_StoreHostAdapterLocalRAM =                   0x90,
441   BusLogic_FetchHostAdapterLocalRAM =                   0x91,
442   BusLogic_StoreLocalDataInEEPROM =                     0x92,
443   BusLogic_UploadAutoSCSICode =                         0x94,
444   BusLogic_ModifyIOAddress =                            0x95,
445   BusLogic_SetCCBFormat =                               0x96,
446   BusLogic_WriteInquiryBuffer =                         0x9A,
447   BusLogic_ReadInquiryBuffer =                          0x9B,
448   BusLogic_FlashROMUploadDownload =                     0xA7,
449   BusLogic_ReadSCAMData =                               0xA8,
450   BusLogic_WriteSCAMData =                              0xA9
451 };
452
453 /*
454   Define the Inquire Board ID reply structure.
455 */
456
457 struct BusLogic_BoardID
458 {
459   unsigned char BoardType;                              /* Byte 0 */
460   unsigned char CustomFeatures;                         /* Byte 1 */
461   unsigned char FirmwareVersion1stDigit;                /* Byte 2 */
462   unsigned char FirmwareVersion2ndDigit;                /* Byte 3 */
463 };
464
465 /*
466   Define the Inquire Configuration reply structure.
467 */
468
469 struct BusLogic_Configuration
470 {
471   unsigned char :5;                                     /* Byte 0 Bits 0-4 */
472   boolean DMA_Channel5:1;                               /* Byte 0 Bit 5 */
473   boolean DMA_Channel6:1;                               /* Byte 0 Bit 6 */
474   boolean DMA_Channel7:1;                               /* Byte 0 Bit 7 */
475   boolean IRQ_Channel9:1;                               /* Byte 1 Bit 0 */
476   boolean IRQ_Channel10:1;                              /* Byte 1 Bit 1 */
477   boolean IRQ_Channel11:1;                              /* Byte 1 Bit 2 */
478   boolean IRQ_Channel12:1;                              /* Byte 1 Bit 3 */
479   unsigned char :1;                                     /* Byte 1 Bit 4 */
480   boolean IRQ_Channel14:1;                              /* Byte 1 Bit 5 */
481   boolean IRQ_Channel15:1;                              /* Byte 1 Bit 6 */
482   unsigned char :1;                                     /* Byte 1 Bit 7 */
483   unsigned char HostAdapterID:4;                        /* Byte 2 Bits 0-3 */
484   unsigned char :4;                                     /* Byte 2 Bits 4-7 */
485 };
486
487 /*
488   Define the Inquire Setup Information reply structure.
489 */
490
491 struct BusLogic_SynchronousValue
492 {
493   unsigned char Offset:4;                               /* Bits 0-3 */
494   unsigned char TransferPeriod:3;                       /* Bits 4-6 */
495   boolean Synchronous:1;                                /* Bit 7 */
496 };
497
498 struct BusLogic_SetupInformation
499 {
500   boolean SynchronousInitiationEnabled:1;               /* Byte 0 Bit 0 */
501   boolean ParityCheckingEnabled:1;                      /* Byte 0 Bit 1 */
502   unsigned char :6;                                     /* Byte 0 Bits 2-7 */
503   unsigned char BusTransferRate;                        /* Byte 1 */
504   unsigned char PreemptTimeOnBus;                       /* Byte 2 */
505   unsigned char TimeOffBus;                             /* Byte 3 */
506   unsigned char MailboxCount;                           /* Byte 4 */
507   unsigned char MailboxAddress[3];                      /* Bytes 5-7 */
508   struct BusLogic_SynchronousValue SynchronousValuesID0to7[8];/* Bytes 8-15 */
509   unsigned char DisconnectPermittedID0to7;              /* Byte 16 */
510   unsigned char Signature;                              /* Byte 17 */
511   unsigned char CharacterD;                             /* Byte 18 */
512   unsigned char HostBusType;                            /* Byte 19 */
513   unsigned char WideTransfersPermittedID0to7;           /* Byte 20 */
514   unsigned char WideTransfersActiveID0to7;              /* Byte 21 */
515   struct BusLogic_SynchronousValue SynchronousValuesID8to15[8]; /* Bytes 22-29 */
516   unsigned char DisconnectPermittedID8to15;             /* Byte 30 */
517   unsigned char :8;                                     /* Byte 31 */
518   unsigned char WideTransfersPermittedID8to15;          /* Byte 32 */
519   unsigned char WideTransfersActiveID8to15;             /* Byte 33 */
520 };
521
522 /*
523   Define the Initialize Extended Mailbox request structure.
524 */
525
526 struct BusLogic_ExtendedMailboxRequest
527 {
528   unsigned char MailboxCount;                           /* Byte 0 */
529   u32 BaseMailboxAddress;                               /* Bytes 1-4 */
530 } PACKED;
531
532
533 /*
534   Define the Inquire PCI Host Adapter Information reply type.  The ISA
535   Compatible I/O Port values are defined here and are also used with
536   the Modify I/O Address command.
537 */
538
539 enum BusLogic_ISACompatibleIOPort
540 {
541   BusLogic_IO_330 =                             0,
542   BusLogic_IO_334 =                             1,
543   BusLogic_IO_230 =                             2,
544   BusLogic_IO_234 =                             3,
545   BusLogic_IO_130 =                             4,
546   BusLogic_IO_134 =                             5,
547   BusLogic_IO_Disable =                         6,
548   BusLogic_IO_Disable2 =                        7
549 } PACKED;
550
551 struct BusLogic_PCIHostAdapterInformation
552 {
553   enum BusLogic_ISACompatibleIOPort ISACompatibleIOPort;/* Byte 0 */
554   unsigned char PCIAssignedIRQChannel;                  /* Byte 1 */
555   boolean LowByteTerminated:1;                          /* Byte 2 Bit 0 */
556   boolean HighByteTerminated:1;                         /* Byte 2 Bit 1 */
557   unsigned char :2;                                     /* Byte 2 Bits 2-3 */
558   boolean JP1:1;                                        /* Byte 2 Bit 4 */
559   boolean JP2:1;                                        /* Byte 2 Bit 5 */
560   boolean JP3:1;                                        /* Byte 2 Bit 6 */
561   boolean GenericInfoValid:1;                           /* Byte 2 Bit 7 */
562   unsigned char :8;                                     /* Byte 3 */
563 };
564
565 /*
566   Define the Inquire Extended Setup Information reply structure.
567 */
568
569 struct BusLogic_ExtendedSetupInformation
570 {
571   unsigned char BusType;                                /* Byte 0 */
572   unsigned char BIOS_Address;                           /* Byte 1 */
573   unsigned short ScatterGatherLimit;                    /* Bytes 2-3 */
574   unsigned char MailboxCount;                           /* Byte 4 */
575   u32 BaseMailboxAddress;                               /* Bytes 5-8 */
576   struct {
577            unsigned char :2;                            /* Byte 9 Bits 0-1 */
578            boolean FastOnEISA:1;                        /* Byte 9 Bit 2 */
579            unsigned char :3;                            /* Byte 9 Bits 3-5 */
580            boolean LevelSensitiveInterrupt:1;           /* Byte 9 Bit 6 */
581            unsigned char :1;                            /* Byte 9 Bit 7 */
582   } Misc;
583   unsigned char FirmwareRevision[3];                    /* Bytes 10-12 */
584   boolean HostWideSCSI:1;                               /* Byte 13 Bit 0 */
585   boolean HostDifferentialSCSI:1;                       /* Byte 13 Bit 1 */
586   boolean HostSupportsSCAM:1;                           /* Byte 13 Bit 2 */
587   boolean HostUltraSCSI:1;                              /* Byte 13 Bit 3 */
588   boolean HostSmartTermination:1;                       /* Byte 13 Bit 4 */
589   unsigned char :3;                                     /* Byte 13 Bits 5-7 */
590 } PACKED;
591
592 /*
593   Define the Enable Strict Round Robin Mode request type.
594 */
595
596 enum BusLogic_RoundRobinModeRequest
597 {
598   BusLogic_AggressiveRoundRobinMode =           0,
599   BusLogic_StrictRoundRobinMode =               1
600 } PACKED;
601
602
603 /*
604   Define the Fetch Host Adapter Local RAM request type.
605 */
606
607 #define BusLogic_BIOS_BaseOffset                0
608 #define BusLogic_AutoSCSI_BaseOffset            64
609
610 struct BusLogic_FetchHostAdapterLocalRAMRequest
611 {
612   unsigned char ByteOffset;                             /* Byte 0 */
613   unsigned char ByteCount;                              /* Byte 1 */
614 };
615
616 /*
617   Define the Host Adapter Local RAM AutoSCSI structure.
618 */
619
620 struct BusLogic_AutoSCSIData
621 {
622   unsigned char InternalFactorySignature[2];            /* Bytes 0-1 */
623   unsigned char InformationByteCount;                   /* Byte 2 */
624   unsigned char HostAdapterType[6];                     /* Bytes 3-8 */
625   unsigned char :8;                                     /* Byte 9 */
626   boolean FloppyEnabled:1;                              /* Byte 10 Bit 0 */
627   boolean FloppySecondary:1;                            /* Byte 10 Bit 1 */
628   boolean LevelSensitiveInterrupt:1;                    /* Byte 10 Bit 2 */
629   unsigned char :2;                                     /* Byte 10 Bits 3-4 */
630   unsigned char SystemRAMAreaForBIOS:3;                 /* Byte 10 Bits 5-7 */
631   unsigned char DMA_Channel:7;                          /* Byte 11 Bits 0-6 */
632   boolean DMA_AutoConfiguration:1;                      /* Byte 11 Bit 7 */
633   unsigned char IRQ_Channel:7;                          /* Byte 12 Bits 0-6 */
634   boolean IRQ_AutoConfiguration:1;                      /* Byte 12 Bit 7 */
635   unsigned char DMA_TransferRate;                       /* Byte 13 */
636   unsigned char SCSI_ID;                                /* Byte 14 */
637   boolean LowByteTerminated:1;                          /* Byte 15 Bit 0 */
638   boolean ParityCheckingEnabled:1;                      /* Byte 15 Bit 1 */
639   boolean HighByteTerminated:1;                         /* Byte 15 Bit 2 */
640   boolean NoisyCablingEnvironment:1;                    /* Byte 15 Bit 3 */
641   boolean FastSynchronousNegotiation:1;                 /* Byte 15 Bit 4 */
642   boolean BusResetEnabled:1;                            /* Byte 15 Bit 5 */
643   boolean :1;                                           /* Byte 15 Bit 6 */
644   boolean ActiveNegationEnabled:1;                      /* Byte 15 Bit 7 */
645   unsigned char BusOnDelay;                             /* Byte 16 */
646   unsigned char BusOffDelay;                            /* Byte 17 */
647   boolean HostAdapterBIOSEnabled:1;                     /* Byte 18 Bit 0 */
648   boolean BIOSRedirectionOfINT19Enabled:1;              /* Byte 18 Bit 1 */
649   boolean ExtendedTranslationEnabled:1;                 /* Byte 18 Bit 2 */
650   boolean MapRemovableAsFixedEnabled:1;                 /* Byte 18 Bit 3 */
651   boolean :1;                                           /* Byte 18 Bit 4 */
652   boolean BIOSSupportsMoreThan2DrivesEnabled:1;         /* Byte 18 Bit 5 */
653   boolean BIOSInterruptModeEnabled:1;                   /* Byte 18 Bit 6 */
654   boolean FlopticalSupportEnabled:1;                    /* Byte 19 Bit 7 */
655   unsigned short DeviceEnabled;                         /* Bytes 19-20 */
656   unsigned short WidePermitted;                         /* Bytes 21-22 */
657   unsigned short FastPermitted;                         /* Bytes 23-24 */
658   unsigned short SynchronousPermitted;                  /* Bytes 25-26 */
659   unsigned short DisconnectPermitted;                   /* Bytes 27-28 */
660   unsigned short SendStartUnitCommand;                  /* Bytes 29-30 */
661   unsigned short IgnoreInBIOSScan;                      /* Bytes 31-32 */
662   unsigned char PCIInterruptPin:2;                      /* Byte 33 Bits 0-1 */
663   unsigned char HostAdapterIOPortAddress:2;             /* Byte 33 Bits 2-3 */
664   boolean StrictRoundRobinModeEnabled:1;                /* Byte 33 Bit 4 */
665   boolean VESABusSpeedGreaterThan33MHz:1;               /* Byte 33 Bit 5 */
666   boolean VESABurstWriteEnabled:1;                      /* Byte 33 Bit 6 */
667   boolean VESABurstReadEnabled:1;                       /* Byte 33 Bit 7 */
668   unsigned short UltraPermitted;                        /* Bytes 34-35 */
669   unsigned int :32;                                     /* Bytes 36-39 */
670   unsigned char :8;                                     /* Byte 40 */
671   unsigned char AutoSCSIMaximumLUN;                     /* Byte 41 */
672   boolean :1;                                           /* Byte 42 Bit 0 */
673   boolean SCAM_Dominant:1;                              /* Byte 42 Bit 1 */
674   boolean SCAM_Enabled:1;                               /* Byte 42 Bit 2 */
675   boolean SCAM_Level2:1;                                /* Byte 42 Bit 3 */
676   unsigned char :4;                                     /* Byte 42 Bits 4-7 */
677   boolean INT13ExtensionEnabled:1;                      /* Byte 43 Bit 0 */
678   boolean :1;                                           /* Byte 43 Bit 1 */
679   boolean CDROMBootEnabled:1;                           /* Byte 43 Bit 2 */
680   unsigned char :5;                                     /* Byte 43 Bits 3-7 */
681   unsigned char BootTargetID:4;                         /* Byte 44 Bits 0-3 */
682   unsigned char BootChannel:4;                          /* Byte 44 Bits 4-7 */
683   unsigned char ForceBusDeviceScanningOrder:1;          /* Byte 45 Bit 0 */
684   unsigned char :7;                                     /* Byte 45 Bits 1-7 */
685   unsigned short NonTaggedToAlternateLUNPermitted;      /* Bytes 46-47 */
686   unsigned short RenegotiateSyncAfterCheckCondition;    /* Bytes 48-49 */
687   unsigned char Reserved[10];                           /* Bytes 50-59 */
688   unsigned char ManufacturingDiagnostic[2];             /* Bytes 60-61 */
689   unsigned short Checksum;                              /* Bytes 62-63 */
690 } PACKED;
691
692 /*
693   Define the Host Adapter Local RAM Auto SCSI Byte 45 structure.
694 */
695
696 struct BusLogic_AutoSCSIByte45
697 {
698   unsigned char ForceBusDeviceScanningOrder:1;          /* Bit 0 */
699   unsigned char :7;                                     /* Bits 1-7 */
700 };
701
702 /*
703   Define the Host Adapter Local RAM BIOS Drive Map Byte structure.
704 */
705
706 #define BusLogic_BIOS_DriveMapOffset            17
707
708 struct BusLogic_BIOSDriveMapByte
709 {
710   unsigned char TargetIDBit3:1;                         /* Bit 0 */
711   unsigned char :2;                                     /* Bits 1-2 */
712   enum BusLogic_BIOS_DiskGeometryTranslation DiskGeometry:2; /* Bits 3-4 */
713   unsigned char TargetID:3;                             /* Bits 5-7 */
714 };
715
716 /*
717   Define the Set CCB Format request type.  Extended LUN Format CCBs are
718   necessary to support more than 8 Logical Units per Target Device.
719 */
720
721 enum BusLogic_SetCCBFormatRequest
722 {
723   BusLogic_LegacyLUNFormatCCB =                 0,
724   BusLogic_ExtendedLUNFormatCCB =               1
725 } PACKED;
726
727 /*
728   Define the Outgoing Mailbox Action Codes.
729 */
730
731 enum BusLogic_ActionCode
732 {
733   BusLogic_OutgoingMailboxFree =                0x00,
734   BusLogic_MailboxStartCommand =                0x01,
735   BusLogic_MailboxAbortCommand =                0x02
736 } PACKED;
737
738
739 /*
740   Define the Incoming Mailbox Completion Codes.  The MultiMaster Firmware
741   only uses codes 0 - 4.  The FlashPoint SCCB Manager has no mailboxes, so
742   completion codes are stored in the CCB; it only uses codes 1, 2, 4, and 5.
743 */
744
745 enum BusLogic_CompletionCode
746 {
747   BusLogic_IncomingMailboxFree =                0x00,
748   BusLogic_CommandCompletedWithoutError =       0x01,
749   BusLogic_CommandAbortedAtHostRequest =        0x02,
750   BusLogic_AbortedCommandNotFound =             0x03,
751   BusLogic_CommandCompletedWithError =          0x04,
752   BusLogic_InvalidCCB =                         0x05
753 } PACKED;
754
755 /*
756   Define the Command Control Block (CCB) Opcodes.
757 */
758
759 enum BusLogic_CCB_Opcode
760 {
761   BusLogic_InitiatorCCB =                       0x00,
762   BusLogic_TargetCCB =                          0x01,
763   BusLogic_InitiatorCCB_ScatterGather =         0x02,
764   BusLogic_InitiatorCCB_ResidualDataLength =    0x03,
765   BusLogic_InitiatorCCB_ScatterGatherResidual = 0x04,
766   BusLogic_BusDeviceReset =                     0x81
767 } PACKED;
768
769
770 /*
771   Define the CCB Data Direction Codes.
772 */
773
774 enum BusLogic_DataDirection
775 {
776   BusLogic_UncheckedDataTransfer =              0,
777   BusLogic_DataInLengthChecked =                1,
778   BusLogic_DataOutLengthChecked =               2,
779   BusLogic_NoDataTransfer =                     3
780 };
781
782
783 /*
784   Define the Host Adapter Status Codes.  The MultiMaster Firmware does not
785   return status code 0x0C; it uses 0x12 for both overruns and underruns.
786 */
787
788 enum BusLogic_HostAdapterStatus
789 {
790   BusLogic_CommandCompletedNormally =           0x00,
791   BusLogic_LinkedCommandCompleted =             0x0A,
792   BusLogic_LinkedCommandCompletedWithFlag =     0x0B,
793   BusLogic_DataUnderRun =                       0x0C,
794   BusLogic_SCSISelectionTimeout =               0x11,
795   BusLogic_DataOverRun =                        0x12,
796   BusLogic_UnexpectedBusFree =                  0x13,
797   BusLogic_InvalidBusPhaseRequested =           0x14,
798   BusLogic_InvalidOutgoingMailboxActionCode =   0x15,
799   BusLogic_InvalidCommandOperationCode =        0x16,
800   BusLogic_LinkedCCBhasInvalidLUN =             0x17,
801   BusLogic_InvalidCommandParameter =            0x1A,
802   BusLogic_AutoRequestSenseFailed =             0x1B,
803   BusLogic_TaggedQueuingMessageRejected =       0x1C,
804   BusLogic_UnsupportedMessageReceived =         0x1D,
805   BusLogic_HostAdapterHardwareFailed =          0x20,
806   BusLogic_TargetFailedResponseToATN =          0x21,
807   BusLogic_HostAdapterAssertedRST =             0x22,
808   BusLogic_OtherDeviceAssertedRST =             0x23,
809   BusLogic_TargetDeviceReconnectedImproperly =  0x24,
810   BusLogic_HostAdapterAssertedBusDeviceReset =  0x25,
811   BusLogic_AbortQueueGenerated =                0x26,
812   BusLogic_HostAdapterSoftwareError =           0x27,
813   BusLogic_HostAdapterHardwareTimeoutError =    0x30,
814   BusLogic_SCSIParityErrorDetected =            0x34
815 } PACKED;
816
817
818 /*
819   Define the SCSI Target Device Status Codes.
820 */
821
822 enum BusLogic_TargetDeviceStatus
823 {
824   BusLogic_OperationGood =                      0x00,
825   BusLogic_CheckCondition =                     0x02,
826   BusLogic_DeviceBusy =                         0x08
827 } PACKED;
828
829 /*
830   Define the Queue Tag Codes.
831 */
832
833 enum BusLogic_QueueTag
834 {
835   BusLogic_SimpleQueueTag =                     0,
836   BusLogic_HeadOfQueueTag =                     1,
837   BusLogic_OrderedQueueTag =                    2,
838   BusLogic_ReservedQT =                         3
839 };
840
841 /*
842   Define the SCSI Command Descriptor Block (CDB).
843 */
844
845 #define BusLogic_CDB_MaxLength                  12
846
847 typedef unsigned char SCSI_CDB_T[BusLogic_CDB_MaxLength];
848
849
850 /*
851   Define the Scatter/Gather Segment structure required by the MultiMaster
852   Firmware Interface and the FlashPoint SCCB Manager.
853 */
854
855 struct BusLogic_ScatterGatherSegment
856 {
857   u32 SegmentByteCount;                                 /* Bytes 0-3 */
858   u32 SegmentDataPointer;                               /* Bytes 4-7 */
859 };
860
861 /*
862   Define the Driver CCB Status Codes.
863 */
864
865 enum BusLogic_CCB_Status
866 {
867   BusLogic_CCB_Free =                           0,
868   BusLogic_CCB_Active =                         1,
869   BusLogic_CCB_Completed =                      2,
870   BusLogic_CCB_Reset =                          3
871 } PACKED;
872
873
874 /*
875   Define the 32 Bit Mode Command Control Block (CCB) structure.  The first 40
876   bytes are defined by and common to both the MultiMaster Firmware and the
877   FlashPoint SCCB Manager.  The next 60 bytes are defined by the FlashPoint
878   SCCB Manager.  The remaining components are defined by the Linux BusLogic
879   Driver.  Extended LUN Format CCBs differ from Legacy LUN Format 32 Bit Mode
880   CCBs only in having the TagEnable and QueueTag fields moved from byte 17 to
881   byte 1, and the Logical Unit field in byte 17 expanded to 6 bits.  In theory,
882   Extended LUN Format CCBs can support up to 64 Logical Units, but in practice
883   many devices will respond improperly to Logical Units between 32 and 63, and
884   the SCSI-2 specification defines Bit 5 as LUNTAR.  Extended LUN Format CCBs
885   are used by recent versions of the MultiMaster Firmware, as well as by the
886   FlashPoint SCCB Manager; the FlashPoint SCCB Manager only supports 32 Logical
887   Units.  Since 64 Logical Units are unlikely to be needed in practice, and
888   since they are problematic for the above reasons, and since limiting them to
889   5 bits simplifies the CCB structure definition, this driver only supports
890   32 Logical Units per Target Device.
891 */
892
893 struct BusLogic_CCB
894 {
895   /*
896     MultiMaster Firmware and FlashPoint SCCB Manager Common Portion.
897   */
898   enum BusLogic_CCB_Opcode Opcode;                      /* Byte 0 */
899   unsigned char :3;                                     /* Byte 1 Bits 0-2 */
900   enum BusLogic_DataDirection DataDirection:2;          /* Byte 1 Bits 3-4 */
901   boolean TagEnable:1;                                  /* Byte 1 Bit 5 */
902   enum BusLogic_QueueTag QueueTag:2;                    /* Byte 1 Bits 6-7 */
903   unsigned char CDB_Length;                             /* Byte 2 */
904   unsigned char SenseDataLength;                        /* Byte 3 */
905   u32 DataLength;                                       /* Bytes 4-7 */
906   u32 DataPointer;                                      /* Bytes 8-11 */
907   unsigned char :8;                                     /* Byte 12 */
908   unsigned char :8;                                     /* Byte 13 */
909   enum BusLogic_HostAdapterStatus HostAdapterStatus;    /* Byte 14 */
910   enum BusLogic_TargetDeviceStatus TargetDeviceStatus;  /* Byte 15 */
911   unsigned char TargetID;                               /* Byte 16 */
912   unsigned char LogicalUnit:5;                          /* Byte 17 Bits 0-4 */
913   boolean LegacyTagEnable:1;                            /* Byte 17 Bit 5 */
914   enum BusLogic_QueueTag LegacyQueueTag:2;              /* Byte 17 Bits 6-7 */
915   SCSI_CDB_T CDB;                                       /* Bytes 18-29 */
916   unsigned char :8;                                     /* Byte 30 */
917   unsigned char :8;                                     /* Byte 31 */
918   unsigned int :32;                                     /* Bytes 32-35 */
919   u32 SenseDataPointer;                                 /* Bytes 36-39 */
920   /*
921     FlashPoint SCCB Manager Defined Portion.
922   */
923   void (*CallbackFunction)(struct BusLogic_CCB *);      /* Bytes 40-43 */
924   u32 BaseAddress;                                      /* Bytes 44-47 */
925   enum BusLogic_CompletionCode CompletionCode;          /* Byte 48 */
926 #ifndef CONFIG_SCSI_OMIT_FLASHPOINT
927   unsigned char :8;                                     /* Byte 49 */
928   unsigned short OS_Flags;                              /* Bytes 50-51 */
929   unsigned char Private[48];                            /* Bytes 52-99 */
930 #endif
931   /*
932     BusLogic Linux Driver Defined Portion.
933   */
934   dma_addr_t AllocationGroupHead;
935   unsigned int AllocationGroupSize;
936   u32 DMA_Handle;
937   enum BusLogic_CCB_Status Status;
938   unsigned long SerialNumber;
939   struct scsi_cmnd *Command;
940   struct BusLogic_HostAdapter *HostAdapter;
941   struct BusLogic_CCB *Next;
942   struct BusLogic_CCB *NextAll;
943   struct BusLogic_ScatterGatherSegment
944     ScatterGatherList[BusLogic_ScatterGatherLimit];
945 };
946
947 /*
948   Define the 32 Bit Mode Outgoing Mailbox structure.
949 */
950
951 struct BusLogic_OutgoingMailbox
952 {
953   u32 CCB;                                              /* Bytes 0-3 */
954   unsigned int :24;                                     /* Bytes 4-6 */
955   enum BusLogic_ActionCode ActionCode;                  /* Byte 7 */
956 };
957
958 /*
959   Define the 32 Bit Mode Incoming Mailbox structure.
960 */
961
962 struct BusLogic_IncomingMailbox
963 {
964   u32 CCB;                                              /* Bytes 0-3 */
965   enum BusLogic_HostAdapterStatus HostAdapterStatus;    /* Byte 4 */
966   enum BusLogic_TargetDeviceStatus TargetDeviceStatus;  /* Byte 5 */
967   unsigned char :8;                                     /* Byte 6 */
968   enum BusLogic_CompletionCode CompletionCode;          /* Byte 7 */
969 };
970
971
972 /*
973   Define the BusLogic Driver Options structure.
974 */
975
976 struct BusLogic_DriverOptions
977 {
978   unsigned short TaggedQueuingPermitted;
979   unsigned short TaggedQueuingPermittedMask;
980   unsigned short BusSettleTime;
981   struct BusLogic_LocalOptions LocalOptions;
982   unsigned char CommonQueueDepth;
983   unsigned char QueueDepth[BusLogic_MaxTargetDevices];
984 };
985
986 /*
987   Define the Host Adapter Target Flags structure.
988 */
989
990 struct BusLogic_TargetFlags
991 {
992   boolean TargetExists:1;
993   boolean TaggedQueuingSupported:1;
994   boolean WideTransfersSupported:1;
995   boolean TaggedQueuingActive:1;
996   boolean WideTransfersActive:1;
997   boolean CommandSuccessfulFlag:1;
998   boolean TargetInfoReported:1;
999 };
1000
1001 /*
1002   Define the Host Adapter Target Statistics structure.
1003 */
1004
1005 #define BusLogic_SizeBuckets                    10
1006
1007 typedef unsigned int BusLogic_CommandSizeBuckets_T[BusLogic_SizeBuckets];
1008
1009 struct BusLogic_TargetStatistics
1010 {
1011   unsigned int CommandsAttempted;
1012   unsigned int CommandsCompleted;
1013   unsigned int ReadCommands;
1014   unsigned int WriteCommands;
1015   struct BusLogic_ByteCounter TotalBytesRead;
1016   struct BusLogic_ByteCounter TotalBytesWritten;
1017   BusLogic_CommandSizeBuckets_T ReadCommandSizeBuckets;
1018   BusLogic_CommandSizeBuckets_T WriteCommandSizeBuckets;
1019   unsigned short CommandAbortsRequested;
1020   unsigned short CommandAbortsAttempted;
1021   unsigned short CommandAbortsCompleted;
1022   unsigned short BusDeviceResetsRequested;
1023   unsigned short BusDeviceResetsAttempted;
1024   unsigned short BusDeviceResetsCompleted;
1025   unsigned short HostAdapterResetsRequested;
1026   unsigned short HostAdapterResetsAttempted;
1027   unsigned short HostAdapterResetsCompleted;
1028 };
1029
1030 /*
1031   Define the FlashPoint Card Handle data type.
1032 */
1033
1034 #define FlashPoint_BadCardHandle                0xFFFFFFFF
1035
1036 typedef unsigned int FlashPoint_CardHandle_T;
1037
1038
1039 /*
1040   Define the FlashPoint Information structure.  This structure is defined
1041   by the FlashPoint SCCB Manager.
1042 */
1043
1044 struct FlashPoint_Info
1045 {
1046   u32 BaseAddress;                                      /* Bytes 0-3 */
1047   boolean Present;                                      /* Byte 4 */
1048   unsigned char IRQ_Channel;                            /* Byte 5 */
1049   unsigned char SCSI_ID;                                /* Byte 6 */
1050   unsigned char SCSI_LUN;                               /* Byte 7 */
1051   unsigned short FirmwareRevision;                      /* Bytes 8-9 */
1052   unsigned short SynchronousPermitted;                  /* Bytes 10-11 */
1053   unsigned short FastPermitted;                         /* Bytes 12-13 */
1054   unsigned short UltraPermitted;                        /* Bytes 14-15 */
1055   unsigned short DisconnectPermitted;                   /* Bytes 16-17 */
1056   unsigned short WidePermitted;                         /* Bytes 18-19 */
1057   boolean ParityCheckingEnabled:1;                      /* Byte 20 Bit 0 */
1058   boolean HostWideSCSI:1;                               /* Byte 20 Bit 1 */
1059   boolean HostSoftReset:1;                              /* Byte 20 Bit 2 */
1060   boolean ExtendedTranslationEnabled:1;                 /* Byte 20 Bit 3 */
1061   boolean LowByteTerminated:1;                          /* Byte 20 Bit 4 */
1062   boolean HighByteTerminated:1;                         /* Byte 20 Bit 5 */
1063   boolean ReportDataUnderrun:1;                         /* Byte 20 Bit 6 */
1064   boolean SCAM_Enabled:1;                               /* Byte 20 Bit 7 */
1065   boolean SCAM_Level2:1;                                /* Byte 21 Bit 0 */
1066   unsigned char :7;                                     /* Byte 21 Bits 1-7 */
1067   unsigned char Family;                                 /* Byte 22 */
1068   unsigned char BusType;                                /* Byte 23 */
1069   unsigned char ModelNumber[3];                         /* Bytes 24-26 */
1070   unsigned char RelativeCardNumber;                     /* Byte 27 */
1071   unsigned char Reserved[4];                            /* Bytes 28-31 */
1072   unsigned int OS_Reserved;                             /* Bytes 32-35 */
1073   unsigned char TranslationInfo[4];                     /* Bytes 36-39 */
1074   unsigned int Reserved2[5];                            /* Bytes 40-59 */
1075   unsigned int SecondaryRange;                          /* Bytes 60-63 */
1076 };
1077
1078 /*
1079   Define the BusLogic Driver Host Adapter structure.
1080 */
1081
1082 struct BusLogic_HostAdapter
1083 {
1084   struct Scsi_Host *SCSI_Host;
1085   struct pci_dev *PCI_Device;
1086   enum BusLogic_HostAdapterType HostAdapterType;
1087   enum BusLogic_HostAdapterBusType HostAdapterBusType;
1088   unsigned long IO_Address;
1089   unsigned long PCI_Address;
1090   unsigned short AddressCount;
1091   unsigned char HostNumber;
1092   unsigned char ModelName[9];
1093   unsigned char FirmwareVersion[6];
1094   unsigned char FullModelName[18];
1095   unsigned char Bus;
1096   unsigned char Device;
1097   unsigned char IRQ_Channel;
1098   unsigned char DMA_Channel;
1099   unsigned char SCSI_ID;
1100   boolean IRQ_ChannelAcquired:1;
1101   boolean DMA_ChannelAcquired:1;
1102   boolean ExtendedTranslationEnabled:1;
1103   boolean ParityCheckingEnabled:1;
1104   boolean BusResetEnabled:1;
1105   boolean LevelSensitiveInterrupt:1;
1106   boolean HostWideSCSI:1;
1107   boolean HostDifferentialSCSI:1;
1108   boolean HostSupportsSCAM:1;
1109   boolean HostUltraSCSI:1;
1110   boolean ExtendedLUNSupport:1;
1111   boolean TerminationInfoValid:1;
1112   boolean LowByteTerminated:1;
1113   boolean HighByteTerminated:1;
1114   boolean BounceBuffersRequired:1;
1115   boolean StrictRoundRobinModeSupport:1;
1116   boolean SCAM_Enabled:1;
1117   boolean SCAM_Level2:1;
1118   boolean HostAdapterInitialized:1;
1119   boolean HostAdapterExternalReset:1;
1120   boolean HostAdapterInternalError:1;
1121   boolean ProcessCompletedCCBsActive;
1122   volatile boolean HostAdapterCommandCompleted;
1123   unsigned short HostAdapterScatterGatherLimit;
1124   unsigned short DriverScatterGatherLimit;
1125   unsigned short MaxTargetDevices;
1126   unsigned short MaxLogicalUnits;
1127   unsigned short MailboxCount;
1128   unsigned short InitialCCBs;
1129   unsigned short IncrementalCCBs;
1130   unsigned short AllocatedCCBs;
1131   unsigned short DriverQueueDepth;
1132   unsigned short HostAdapterQueueDepth;
1133   unsigned short UntaggedQueueDepth;
1134   unsigned short CommonQueueDepth;
1135   unsigned short BusSettleTime;
1136   unsigned short SynchronousPermitted;
1137   unsigned short FastPermitted;
1138   unsigned short UltraPermitted;
1139   unsigned short WidePermitted;
1140   unsigned short DisconnectPermitted;
1141   unsigned short TaggedQueuingPermitted;
1142   unsigned short ExternalHostAdapterResets;
1143   unsigned short HostAdapterInternalErrors;
1144   unsigned short TargetDeviceCount;
1145   unsigned short MessageBufferLength;
1146   u32 BIOS_Address;
1147   struct BusLogic_DriverOptions *DriverOptions;
1148   struct FlashPoint_Info FlashPointInfo;
1149   FlashPoint_CardHandle_T CardHandle;
1150   struct BusLogic_HostAdapter *Next;
1151   struct BusLogic_CCB *All_CCBs;
1152   struct BusLogic_CCB *Free_CCBs;
1153   struct BusLogic_CCB *FirstCompletedCCB;
1154   struct BusLogic_CCB *LastCompletedCCB;
1155   struct BusLogic_CCB *BusDeviceResetPendingCCB[BusLogic_MaxTargetDevices];
1156   struct BusLogic_TargetFlags TargetFlags[BusLogic_MaxTargetDevices];
1157   unsigned char QueueDepth[BusLogic_MaxTargetDevices];
1158   unsigned char SynchronousPeriod[BusLogic_MaxTargetDevices];
1159   unsigned char SynchronousOffset[BusLogic_MaxTargetDevices];
1160   unsigned char ActiveCommands[BusLogic_MaxTargetDevices];
1161   unsigned int CommandsSinceReset[BusLogic_MaxTargetDevices];
1162   unsigned long LastSequencePoint[BusLogic_MaxTargetDevices];
1163   unsigned long LastResetAttempted[BusLogic_MaxTargetDevices];
1164   unsigned long LastResetCompleted[BusLogic_MaxTargetDevices];
1165   struct BusLogic_OutgoingMailbox *FirstOutgoingMailbox;
1166   struct BusLogic_OutgoingMailbox *LastOutgoingMailbox;
1167   struct BusLogic_OutgoingMailbox *NextOutgoingMailbox;
1168   struct BusLogic_IncomingMailbox *FirstIncomingMailbox;
1169   struct BusLogic_IncomingMailbox *LastIncomingMailbox;
1170   struct BusLogic_IncomingMailbox *NextIncomingMailbox;
1171   struct BusLogic_TargetStatistics TargetStatistics[BusLogic_MaxTargetDevices];
1172   unsigned char *MailboxSpace;
1173   dma_addr_t MailboxSpaceHandle;
1174   unsigned int MailboxSize;
1175   unsigned long CCB_Offset;
1176   char MessageBuffer[BusLogic_MessageBufferSize];
1177 };
1178
1179 /*
1180   Define a structure for the BIOS Disk Parameters.
1181 */
1182
1183 struct BIOS_DiskParameters
1184 {
1185   int Heads;
1186   int Sectors;
1187   int Cylinders;
1188 };
1189
1190 /*
1191   Define a structure for the SCSI Inquiry command results.
1192 */
1193
1194 struct SCSI_Inquiry
1195 {
1196   unsigned char PeripheralDeviceType:5;                 /* Byte 0 Bits 0-4 */
1197   unsigned char PeripheralQualifier:3;                  /* Byte 0 Bits 5-7 */
1198   unsigned char DeviceTypeModifier:7;                   /* Byte 1 Bits 0-6 */
1199   boolean RMB:1;                                        /* Byte 1 Bit 7 */
1200   unsigned char ANSI_ApprovedVersion:3;                 /* Byte 2 Bits 0-2 */
1201   unsigned char ECMA_Version:3;                         /* Byte 2 Bits 3-5 */
1202   unsigned char ISO_Version:2;                          /* Byte 2 Bits 6-7 */
1203   unsigned char ResponseDataFormat:4;                   /* Byte 3 Bits 0-3 */
1204   unsigned char :2;                                     /* Byte 3 Bits 4-5 */
1205   boolean TrmIOP:1;                                     /* Byte 3 Bit 6 */
1206   boolean AENC:1;                                       /* Byte 3 Bit 7 */
1207   unsigned char AdditionalLength;                       /* Byte 4 */
1208   unsigned char :8;                                     /* Byte 5 */
1209   unsigned char :8;                                     /* Byte 6 */
1210   boolean SftRe:1;                                      /* Byte 7 Bit 0 */
1211   boolean CmdQue:1;                                     /* Byte 7 Bit 1 */
1212   boolean :1;                                           /* Byte 7 Bit 2 */
1213   boolean Linked:1;                                     /* Byte 7 Bit 3 */
1214   boolean Sync:1;                                       /* Byte 7 Bit 4 */
1215   boolean WBus16:1;                                     /* Byte 7 Bit 5 */
1216   boolean WBus32:1;                                     /* Byte 7 Bit 6 */
1217   boolean RelAdr:1;                                     /* Byte 7 Bit 7 */
1218   unsigned char VendorIdentification[8];                /* Bytes 8-15 */
1219   unsigned char ProductIdentification[16];              /* Bytes 16-31 */
1220   unsigned char ProductRevisionLevel[4];                /* Bytes 32-35 */
1221 };
1222
1223 /*
1224   BusLogic_AcquireHostAdapterLock acquires exclusive access to Host Adapter.
1225 */
1226
1227 static inline void BusLogic_AcquireHostAdapterLock(struct BusLogic_HostAdapter *HostAdapter)
1228 {
1229   spin_lock_irq(HostAdapter->SCSI_Host->host_lock);
1230 }
1231
1232 /*
1233   BusLogic_ReleaseHostAdapterLock releases exclusive access to Host Adapter.
1234 */
1235
1236 static inline void BusLogic_ReleaseHostAdapterLock(struct BusLogic_HostAdapter *HostAdapter)
1237 {
1238   spin_unlock_irq(HostAdapter->SCSI_Host->host_lock);
1239 }
1240
1241
1242 /*
1243   BusLogic_AcquireHostAdapterLockIH acquires exclusive access to Host Adapter,
1244   but is only called from the interrupt handler.
1245 */
1246
1247 static inline void BusLogic_AcquireHostAdapterLockIH(struct BusLogic_HostAdapter *HostAdapter,
1248                                                      unsigned long *ProcessorFlags)
1249 {
1250   spin_lock_irqsave(HostAdapter->SCSI_Host->host_lock, *ProcessorFlags);
1251 }
1252
1253
1254 /*
1255   BusLogic_ReleaseHostAdapterLockIH releases exclusive access to Host Adapter,
1256   but is only called from the interrupt handler.
1257 */
1258
1259 static inline void BusLogic_ReleaseHostAdapterLockIH(struct BusLogic_HostAdapter *HostAdapter,
1260                                                      unsigned long *ProcessorFlags)
1261 {
1262   spin_unlock_irqrestore(HostAdapter->SCSI_Host->host_lock, *ProcessorFlags);
1263 }
1264
1265
1266 /*
1267   Define functions to provide an abstraction for reading and writing the
1268   Host Adapter I/O Registers.
1269 */
1270
1271 static inline void BusLogic_SCSIBusReset(struct BusLogic_HostAdapter *HostAdapter)
1272 {
1273   union BusLogic_ControlRegister ControlRegister;
1274   ControlRegister.All = 0;
1275   ControlRegister.cr.SCSIBusReset = true;
1276   outb(ControlRegister.All,
1277        HostAdapter->IO_Address + BusLogic_ControlRegisterOffset);
1278 }
1279
1280 static inline void BusLogic_InterruptReset(struct BusLogic_HostAdapter *HostAdapter)
1281 {
1282   union BusLogic_ControlRegister ControlRegister;
1283   ControlRegister.All = 0;
1284   ControlRegister.cr.InterruptReset = true;
1285   outb(ControlRegister.All,
1286        HostAdapter->IO_Address + BusLogic_ControlRegisterOffset);
1287 }
1288
1289 static inline void BusLogic_SoftReset(struct BusLogic_HostAdapter *HostAdapter)
1290 {
1291   union BusLogic_ControlRegister ControlRegister;
1292   ControlRegister.All = 0;
1293   ControlRegister.cr.SoftReset = true;
1294   outb(ControlRegister.All,
1295        HostAdapter->IO_Address + BusLogic_ControlRegisterOffset);
1296 }
1297
1298 static inline void BusLogic_HardReset(struct BusLogic_HostAdapter *HostAdapter)
1299 {
1300   union BusLogic_ControlRegister ControlRegister;
1301   ControlRegister.All = 0;
1302   ControlRegister.cr.HardReset = true;
1303   outb(ControlRegister.All,
1304        HostAdapter->IO_Address + BusLogic_ControlRegisterOffset);
1305 }
1306
1307 static inline unsigned char BusLogic_ReadStatusRegister(struct BusLogic_HostAdapter *HostAdapter)
1308 {
1309   return inb(HostAdapter->IO_Address + BusLogic_StatusRegisterOffset);
1310 }
1311
1312 static inline void BusLogic_WriteCommandParameterRegister(struct BusLogic_HostAdapter
1313                                                           *HostAdapter,
1314                                                           unsigned char Value)
1315 {
1316   outb(Value, HostAdapter->IO_Address + BusLogic_CommandParameterRegisterOffset);
1317 }
1318
1319 static inline unsigned char BusLogic_ReadDataInRegister(struct BusLogic_HostAdapter *HostAdapter)
1320 {
1321   return inb(HostAdapter->IO_Address + BusLogic_DataInRegisterOffset);
1322 }
1323
1324 static inline unsigned char BusLogic_ReadInterruptRegister(struct BusLogic_HostAdapter *HostAdapter)
1325 {
1326   return inb(HostAdapter->IO_Address + BusLogic_InterruptRegisterOffset);
1327 }
1328
1329 static inline unsigned char BusLogic_ReadGeometryRegister(struct BusLogic_HostAdapter *HostAdapter)
1330 {
1331   return inb(HostAdapter->IO_Address + BusLogic_GeometryRegisterOffset);
1332 }
1333
1334 /*
1335   BusLogic_StartMailboxCommand issues an Execute Mailbox Command, which
1336   notifies the Host Adapter that an entry has been made in an Outgoing
1337   Mailbox.
1338 */
1339
1340 static inline void BusLogic_StartMailboxCommand(struct BusLogic_HostAdapter *HostAdapter)
1341 {
1342   BusLogic_WriteCommandParameterRegister(HostAdapter, BusLogic_ExecuteMailboxCommand);
1343 }
1344
1345 /*
1346   BusLogic_Delay waits for Seconds to elapse.
1347 */
1348
1349 static inline void BusLogic_Delay(int Seconds)
1350 {
1351   mdelay(1000 * Seconds);
1352 }
1353
1354 /*
1355   Virtual_to_Bus and Bus_to_Virtual map between Kernel Virtual Addresses
1356   and PCI/VLB/EISA/ISA Bus Addresses.
1357 */
1358
1359 static inline u32 Virtual_to_Bus(void *VirtualAddress)
1360 {
1361   return (u32) virt_to_bus(VirtualAddress);
1362 }
1363
1364 static inline void *Bus_to_Virtual(u32 BusAddress)
1365 {
1366   return (void *) bus_to_virt(BusAddress);
1367 }
1368
1369 /*
1370   Virtual_to_32Bit_Virtual maps between Kernel Virtual Addresses and
1371   32 bit Kernel Virtual Addresses.  This avoids compilation warnings
1372   on 64 bit architectures.
1373 */
1374
1375 static inline u32 Virtual_to_32Bit_Virtual(void *VirtualAddress)
1376 {
1377   return (u32) (unsigned long) VirtualAddress;
1378 }
1379
1380 /*
1381   BusLogic_IncrementErrorCounter increments Error Counter by 1, stopping at
1382   65535 rather than wrapping around to 0.
1383 */
1384
1385 static inline void BusLogic_IncrementErrorCounter(unsigned short *ErrorCounter)
1386 {
1387   if (*ErrorCounter < 65535) (*ErrorCounter)++;
1388 }
1389
1390 /*
1391   BusLogic_IncrementByteCounter increments Byte Counter by Amount.
1392 */
1393
1394 static inline void BusLogic_IncrementByteCounter(struct BusLogic_ByteCounter
1395                                                  *ByteCounter,
1396                                                  unsigned int Amount)
1397 {
1398   ByteCounter->Units += Amount;
1399   if (ByteCounter->Units > 999999999)
1400     {
1401       ByteCounter->Units -= 1000000000;
1402       ByteCounter->Billions++;
1403     }
1404 }
1405
1406 /*
1407   BusLogic_IncrementSizeBucket increments the Bucket for Amount.
1408 */
1409
1410 static inline void BusLogic_IncrementSizeBucket(BusLogic_CommandSizeBuckets_T
1411                                                 CommandSizeBuckets,
1412                                                 unsigned int Amount)
1413 {
1414   int Index = 0;
1415   if (Amount < 8*1024)
1416     {
1417       if (Amount < 2*1024)
1418         Index = (Amount < 1*1024 ? 0 : 1);
1419       else Index = (Amount < 4*1024 ? 2 : 3);
1420     }
1421   else if (Amount < 128*1024)
1422     {
1423       if (Amount < 32*1024)
1424         Index = (Amount < 16*1024 ? 4 : 5);
1425       else Index = (Amount < 64*1024 ? 6 : 7);
1426     }
1427   else Index = (Amount < 256*1024 ? 8 : 9);
1428   CommandSizeBuckets[Index]++;
1429 }
1430
1431 /*
1432   Define the version number of the FlashPoint Firmware (SCCB Manager).
1433 */
1434
1435 #define FlashPoint_FirmwareVersion              "5.02"
1436
1437 /*
1438   Define the possible return values from FlashPoint_HandleInterrupt.
1439 */
1440
1441 #define FlashPoint_NormalInterrupt              0x00
1442 #define FlashPoint_InternalError                0xFE
1443 #define FlashPoint_ExternalBusReset             0xFF
1444
1445 /*
1446   Define prototypes for the forward referenced BusLogic Driver
1447   Internal Functions.
1448 */
1449
1450 static const char *BusLogic_DriverInfo(struct Scsi_Host *);
1451 static int BusLogic_DetectHostAdapter(struct scsi_host_template *);
1452 static int BusLogic_ReleaseHostAdapter(struct Scsi_Host *);
1453 static int BusLogic_QueueCommand(struct scsi_cmnd *,
1454                                  void (*CompletionRoutine)(struct scsi_cmnd *));
1455 static int BusLogic_BIOSDiskParameters(struct scsi_device *,
1456                                        struct block_device *,
1457                                        sector_t, int *);
1458 static int BusLogic_ProcDirectoryInfo(struct Scsi_Host *, char *,
1459                                       char **, off_t, int, int);
1460 static int BusLogic_SlaveConfigure(struct scsi_device *);
1461 static void BusLogic_QueueCompletedCCB(struct BusLogic_CCB *);
1462 static irqreturn_t BusLogic_InterruptHandler(int, void *, struct pt_regs *);
1463 static int BusLogic_ResetHostAdapter(struct BusLogic_HostAdapter *,
1464                                      boolean HardReset);
1465 static void BusLogic_Message(enum BusLogic_MessageLevel, char *,
1466                              struct BusLogic_HostAdapter *, ...);
1467 static int __init BusLogic_Setup(char *);
1468
1469 #endif /* _BUSLOGIC_H */