Linux Audio

Check our new training course

Loading...
v3.1
   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
  32#ifndef PACKED
  33#define PACKED __attribute__((packed))
  34#endif
  35
  36/*
  37  Define the maximum number of BusLogic Host Adapters supported by this driver.
  38*/
  39
  40#define BusLogic_MaxHostAdapters		16
  41
  42
  43/*
  44  Define the maximum number of Target Devices supported by this driver.
  45*/
  46
  47#define BusLogic_MaxTargetDevices		16
  48
  49
  50/*
  51  Define the maximum number of Scatter/Gather Segments used by this driver.
  52  For optimal performance, it is important that this limit be at least as
  53  large as the largest single request generated by the I/O Subsystem.
  54*/
  55
  56#define BusLogic_ScatterGatherLimit		128
  57
  58
  59/*
  60  Define the maximum, maximum automatic, minimum automatic, and default Queue
  61  Depth to allow for Target Devices depending on whether or not they support
  62  Tagged Queuing and whether or not ISA Bounce Buffers are required.
  63*/
  64
  65#define BusLogic_MaxTaggedQueueDepth		64
  66#define BusLogic_MaxAutomaticTaggedQueueDepth	28
  67#define BusLogic_MinAutomaticTaggedQueueDepth	7
  68#define BusLogic_TaggedQueueDepthBB		3
  69#define BusLogic_UntaggedQueueDepth		3
  70#define BusLogic_UntaggedQueueDepthBB		2
  71
  72
  73/*
  74  Define the default amount of time in seconds to wait between a Host Adapter
  75  Hard Reset which initiates a SCSI Bus Reset and issuing any SCSI commands.
  76  Some SCSI devices get confused if they receive SCSI commands too soon after
  77  a SCSI Bus Reset.
  78*/
  79
  80#define BusLogic_DefaultBusSettleTime		2
  81
  82
  83/*
  84  Define the maximum number of Mailboxes that should be used for MultiMaster
  85  Host Adapters.  This number is chosen to be larger than the maximum Host
  86  Adapter Queue Depth and small enough so that the Host Adapter structure
  87  does not cross an allocation block size boundary.
  88*/
  89
  90#define BusLogic_MaxMailboxes			211
  91
  92
  93/*
  94  Define the number of CCBs that should be allocated as a group to optimize
  95  Kernel memory allocation.
  96*/
  97
  98#define BusLogic_CCB_AllocationGroupSize	7
  99
 100
 101/*
 102  Define the Host Adapter Line and Message Buffer Sizes.
 103*/
 104
 105#define BusLogic_LineBufferSize			100
 106#define BusLogic_MessageBufferSize		9700
 107
 108
 109/*
 110  Define the Driver Message Levels.
 111*/
 112
 113enum BusLogic_MessageLevel {
 114	BusLogic_AnnounceLevel = 0,
 115	BusLogic_InfoLevel = 1,
 116	BusLogic_NoticeLevel = 2,
 117	BusLogic_WarningLevel = 3,
 118	BusLogic_ErrorLevel = 4
 119};
 120
 121static char *BusLogic_MessageLevelMap[] = { KERN_NOTICE, KERN_NOTICE, KERN_NOTICE, KERN_WARNING, KERN_ERR };
 122
 123
 124/*
 125  Define Driver Message macros.
 126*/
 127
 128#define BusLogic_Announce(Format, Arguments...) \
 129  BusLogic_Message(BusLogic_AnnounceLevel, Format, ##Arguments)
 130
 131#define BusLogic_Info(Format, Arguments...) \
 132  BusLogic_Message(BusLogic_InfoLevel, Format, ##Arguments)
 133
 134#define BusLogic_Notice(Format, Arguments...) \
 135  BusLogic_Message(BusLogic_NoticeLevel, Format, ##Arguments)
 136
 137#define BusLogic_Warning(Format, Arguments...) \
 138  BusLogic_Message(BusLogic_WarningLevel, Format, ##Arguments)
 139
 140#define BusLogic_Error(Format, Arguments...) \
 141  BusLogic_Message(BusLogic_ErrorLevel, Format, ##Arguments)
 142
 143
 144/*
 145  Define the types of BusLogic Host Adapters that are supported and the number
 146  of I/O Addresses required by each type.
 147*/
 148
 149enum BusLogic_HostAdapterType {
 150	BusLogic_MultiMaster = 1,
 151	BusLogic_FlashPoint = 2
 152} PACKED;
 153
 154#define BusLogic_MultiMasterAddressCount	4
 155#define BusLogic_FlashPointAddressCount		256
 156
 157static int BusLogic_HostAdapterAddressCount[3] = { 0, BusLogic_MultiMasterAddressCount, BusLogic_FlashPointAddressCount };
 158
 159
 160/*
 161  Define macros for testing the Host Adapter Type.
 162*/
 163
 164#ifdef CONFIG_SCSI_FLASHPOINT
 165
 166#define BusLogic_MultiMasterHostAdapterP(HostAdapter) \
 167  (HostAdapter->HostAdapterType == BusLogic_MultiMaster)
 168
 169#define BusLogic_FlashPointHostAdapterP(HostAdapter) \
 170  (HostAdapter->HostAdapterType == BusLogic_FlashPoint)
 171
 172#else
 173
 174#define BusLogic_MultiMasterHostAdapterP(HostAdapter) \
 175  (true)
 176
 177#define BusLogic_FlashPointHostAdapterP(HostAdapter) \
 178  (false)
 179
 180#endif
 181
 182
 183/*
 184  Define the possible Host Adapter Bus Types.
 185*/
 186
 187enum BusLogic_HostAdapterBusType {
 188	BusLogic_Unknown_Bus = 0,
 189	BusLogic_ISA_Bus = 1,
 190	BusLogic_EISA_Bus = 2,
 191	BusLogic_PCI_Bus = 3,
 192	BusLogic_VESA_Bus = 4,
 193	BusLogic_MCA_Bus = 5
 194} PACKED;
 195
 196static char *BusLogic_HostAdapterBusNames[] = { "Unknown", "ISA", "EISA", "PCI", "VESA", "MCA" };
 197
 198static enum BusLogic_HostAdapterBusType BusLogic_HostAdapterBusTypes[] = {
 199	BusLogic_VESA_Bus,	/* BT-4xx */
 200	BusLogic_ISA_Bus,	/* BT-5xx */
 201	BusLogic_MCA_Bus,	/* BT-6xx */
 202	BusLogic_EISA_Bus,	/* BT-7xx */
 203	BusLogic_Unknown_Bus,	/* BT-8xx */
 204	BusLogic_PCI_Bus	/* BT-9xx */
 205};
 206
 207/*
 208  Define the possible Host Adapter BIOS Disk Geometry Translations.
 209*/
 210
 211enum BusLogic_BIOS_DiskGeometryTranslation {
 212	BusLogic_BIOS_Disk_Not_Installed = 0,
 213	BusLogic_BIOS_Disk_Installed_64x32 = 1,
 214	BusLogic_BIOS_Disk_Installed_128x32 = 2,
 215	BusLogic_BIOS_Disk_Installed_255x63 = 3
 216} PACKED;
 217
 218
 219/*
 220  Define a 10^18 Statistics Byte Counter data type.
 221*/
 222
 223struct BusLogic_ByteCounter {
 224	unsigned int Units;
 225	unsigned int Billions;
 226};
 227
 228
 229/*
 230  Define the structure for I/O Address and Bus Probing Information.
 231*/
 232
 233struct BusLogic_ProbeInfo {
 234	enum BusLogic_HostAdapterType HostAdapterType;
 235	enum BusLogic_HostAdapterBusType HostAdapterBusType;
 236	unsigned long IO_Address;
 237	unsigned long PCI_Address;
 238	struct pci_dev *PCI_Device;
 239	unsigned char Bus;
 240	unsigned char Device;
 241	unsigned char IRQ_Channel;
 242};
 243
 244/*
 245  Define the Probe Options.
 246*/
 247
 248struct BusLogic_ProbeOptions {
 249	bool NoProbe:1;		/* Bit 0 */
 250	bool NoProbeISA:1;	/* Bit 1 */
 251	bool NoProbePCI:1;	/* Bit 2 */
 252	bool NoSortPCI:1;	/* Bit 3 */
 253	bool MultiMasterFirst:1;/* Bit 4 */
 254	bool FlashPointFirst:1;	/* Bit 5 */
 255	bool LimitedProbeISA:1;	/* Bit 6 */
 256	bool Probe330:1;	/* Bit 7 */
 257	bool Probe334:1;	/* Bit 8 */
 258	bool Probe230:1;	/* Bit 9 */
 259	bool Probe234:1;	/* Bit 10 */
 260	bool Probe130:1;	/* Bit 11 */
 261	bool Probe134:1;	/* Bit 12 */
 262};
 263
 264/*
 265  Define the Global Options.
 266*/
 267
 268struct BusLogic_GlobalOptions {
 269	bool TraceProbe:1;	/* Bit 0 */
 270	bool TraceHardwareReset:1;	/* Bit 1 */
 271	bool TraceConfiguration:1;	/* Bit 2 */
 272	bool TraceErrors:1;	/* Bit 3 */
 273};
 274
 275/*
 276  Define the Local Options.
 277*/
 278
 279struct BusLogic_LocalOptions {
 280	bool InhibitTargetInquiry:1;	/* Bit 0 */
 281};
 282
 283/*
 284  Define the BusLogic SCSI Host Adapter I/O Register Offsets.
 285*/
 286
 287#define BusLogic_ControlRegisterOffset		0	/* WO register */
 288#define BusLogic_StatusRegisterOffset		0	/* RO register */
 289#define BusLogic_CommandParameterRegisterOffset	1	/* WO register */
 290#define BusLogic_DataInRegisterOffset		1	/* RO register */
 291#define BusLogic_InterruptRegisterOffset	2	/* RO register */
 292#define BusLogic_GeometryRegisterOffset		3	/* RO register */
 293
 294/*
 295  Define the structure of the write-only Control Register.
 296*/
 297
 298union BusLogic_ControlRegister {
 299	unsigned char All;
 300	struct {
 301		unsigned char:4;	/* Bits 0-3 */
 302		bool SCSIBusReset:1;	/* Bit 4 */
 303		bool InterruptReset:1;	/* Bit 5 */
 304		bool SoftReset:1;	/* Bit 6 */
 305		bool HardReset:1;	/* Bit 7 */
 306	} cr;
 307};
 308
 309/*
 310  Define the structure of the read-only Status Register.
 311*/
 312
 313union BusLogic_StatusRegister {
 314	unsigned char All;
 315	struct {
 316		bool CommandInvalid:1;		/* Bit 0 */
 317		bool Reserved:1;		/* Bit 1 */
 318		bool DataInRegisterReady:1;	/* Bit 2 */
 319		bool CommandParameterRegisterBusy:1;	/* Bit 3 */
 320		bool HostAdapterReady:1;	/* Bit 4 */
 321		bool InitializationRequired:1;	/* Bit 5 */
 322		bool DiagnosticFailure:1;	/* Bit 6 */
 323		bool DiagnosticActive:1;	/* Bit 7 */
 324	} sr;
 325};
 326
 327/*
 328  Define the structure of the read-only Interrupt Register.
 329*/
 330
 331union BusLogic_InterruptRegister {
 332	unsigned char All;
 333	struct {
 334		bool IncomingMailboxLoaded:1;	/* Bit 0 */
 335		bool OutgoingMailboxAvailable:1;/* Bit 1 */
 336		bool CommandComplete:1;		/* Bit 2 */
 337		bool ExternalBusReset:1;	/* Bit 3 */
 338		unsigned char Reserved:3;	/* Bits 4-6 */
 339		bool InterruptValid:1;		/* Bit 7 */
 340	} ir;
 341};
 342
 343/*
 344  Define the structure of the read-only Geometry Register.
 345*/
 346
 347union BusLogic_GeometryRegister {
 348	unsigned char All;
 349	struct {
 350		enum BusLogic_BIOS_DiskGeometryTranslation Drive0Geometry:2;	/* Bits 0-1 */
 351		enum BusLogic_BIOS_DiskGeometryTranslation Drive1Geometry:2;	/* Bits 2-3 */
 352		unsigned char:3;	/* Bits 4-6 */
 353		bool ExtendedTranslationEnabled:1;	/* Bit 7 */
 354	} gr;
 355};
 356
 357/*
 358  Define the BusLogic SCSI Host Adapter Command Register Operation Codes.
 359*/
 360
 361enum BusLogic_OperationCode {
 362	BusLogic_TestCommandCompleteInterrupt = 0x00,
 363	BusLogic_InitializeMailbox = 0x01,
 364	BusLogic_ExecuteMailboxCommand = 0x02,
 365	BusLogic_ExecuteBIOSCommand = 0x03,
 366	BusLogic_InquireBoardID = 0x04,
 367	BusLogic_EnableOutgoingMailboxAvailableInt = 0x05,
 368	BusLogic_SetSCSISelectionTimeout = 0x06,
 369	BusLogic_SetPreemptTimeOnBus = 0x07,
 370	BusLogic_SetTimeOffBus = 0x08,
 371	BusLogic_SetBusTransferRate = 0x09,
 372	BusLogic_InquireInstalledDevicesID0to7 = 0x0A,
 373	BusLogic_InquireConfiguration = 0x0B,
 374	BusLogic_EnableTargetMode = 0x0C,
 375	BusLogic_InquireSetupInformation = 0x0D,
 376	BusLogic_WriteAdapterLocalRAM = 0x1A,
 377	BusLogic_ReadAdapterLocalRAM = 0x1B,
 378	BusLogic_WriteBusMasterChipFIFO = 0x1C,
 379	BusLogic_ReadBusMasterChipFIFO = 0x1D,
 380	BusLogic_EchoCommandData = 0x1F,
 381	BusLogic_HostAdapterDiagnostic = 0x20,
 382	BusLogic_SetAdapterOptions = 0x21,
 383	BusLogic_InquireInstalledDevicesID8to15 = 0x23,
 384	BusLogic_InquireTargetDevices = 0x24,
 385	BusLogic_DisableHostAdapterInterrupt = 0x25,
 386	BusLogic_InitializeExtendedMailbox = 0x81,
 387	BusLogic_ExecuteSCSICommand = 0x83,
 388	BusLogic_InquireFirmwareVersion3rdDigit = 0x84,
 389	BusLogic_InquireFirmwareVersionLetter = 0x85,
 390	BusLogic_InquirePCIHostAdapterInformation = 0x86,
 391	BusLogic_InquireHostAdapterModelNumber = 0x8B,
 392	BusLogic_InquireSynchronousPeriod = 0x8C,
 393	BusLogic_InquireExtendedSetupInformation = 0x8D,
 394	BusLogic_EnableStrictRoundRobinMode = 0x8F,
 395	BusLogic_StoreHostAdapterLocalRAM = 0x90,
 396	BusLogic_FetchHostAdapterLocalRAM = 0x91,
 397	BusLogic_StoreLocalDataInEEPROM = 0x92,
 398	BusLogic_UploadAutoSCSICode = 0x94,
 399	BusLogic_ModifyIOAddress = 0x95,
 400	BusLogic_SetCCBFormat = 0x96,
 401	BusLogic_WriteInquiryBuffer = 0x9A,
 402	BusLogic_ReadInquiryBuffer = 0x9B,
 403	BusLogic_FlashROMUploadDownload = 0xA7,
 404	BusLogic_ReadSCAMData = 0xA8,
 405	BusLogic_WriteSCAMData = 0xA9
 406};
 407
 408/*
 409  Define the Inquire Board ID reply structure.
 410*/
 411
 412struct BusLogic_BoardID {
 413	unsigned char BoardType;	/* Byte 0 */
 414	unsigned char CustomFeatures;	/* Byte 1 */
 415	unsigned char FirmwareVersion1stDigit;	/* Byte 2 */
 416	unsigned char FirmwareVersion2ndDigit;	/* Byte 3 */
 417};
 418
 419/*
 420  Define the Inquire Configuration reply structure.
 421*/
 422
 423struct BusLogic_Configuration {
 424	unsigned char:5;	/* Byte 0 Bits 0-4 */
 425	bool DMA_Channel5:1;	/* Byte 0 Bit 5 */
 426	bool DMA_Channel6:1;	/* Byte 0 Bit 6 */
 427	bool DMA_Channel7:1;	/* Byte 0 Bit 7 */
 428	bool IRQ_Channel9:1;	/* Byte 1 Bit 0 */
 429	bool IRQ_Channel10:1;	/* Byte 1 Bit 1 */
 430	bool IRQ_Channel11:1;	/* Byte 1 Bit 2 */
 431	bool IRQ_Channel12:1;	/* Byte 1 Bit 3 */
 432	unsigned char:1;	/* Byte 1 Bit 4 */
 433	bool IRQ_Channel14:1;	/* Byte 1 Bit 5 */
 434	bool IRQ_Channel15:1;	/* Byte 1 Bit 6 */
 435	unsigned char:1;	/* Byte 1 Bit 7 */
 436	unsigned char HostAdapterID:4;	/* Byte 2 Bits 0-3 */
 437	unsigned char:4;	/* Byte 2 Bits 4-7 */
 438};
 439
 440/*
 441  Define the Inquire Setup Information reply structure.
 442*/
 443
 444struct BusLogic_SynchronousValue {
 445	unsigned char Offset:4;	/* Bits 0-3 */
 446	unsigned char TransferPeriod:3;	/* Bits 4-6 */
 447	bool Synchronous:1;	/* Bit 7 */
 448};
 449
 450struct BusLogic_SetupInformation {
 451	bool SynchronousInitiationEnabled:1;	/* Byte 0 Bit 0 */
 452	bool ParityCheckingEnabled:1;		/* Byte 0 Bit 1 */
 453	unsigned char:6;	/* Byte 0 Bits 2-7 */
 454	unsigned char BusTransferRate;	/* Byte 1 */
 455	unsigned char PreemptTimeOnBus;	/* Byte 2 */
 456	unsigned char TimeOffBus;	/* Byte 3 */
 457	unsigned char MailboxCount;	/* Byte 4 */
 458	unsigned char MailboxAddress[3];	/* Bytes 5-7 */
 459	struct BusLogic_SynchronousValue SynchronousValuesID0to7[8];	/* Bytes 8-15 */
 460	unsigned char DisconnectPermittedID0to7;	/* Byte 16 */
 461	unsigned char Signature;	/* Byte 17 */
 462	unsigned char CharacterD;	/* Byte 18 */
 463	unsigned char HostBusType;	/* Byte 19 */
 464	unsigned char WideTransfersPermittedID0to7;	/* Byte 20 */
 465	unsigned char WideTransfersActiveID0to7;	/* Byte 21 */
 466	struct BusLogic_SynchronousValue SynchronousValuesID8to15[8];	/* Bytes 22-29 */
 467	unsigned char DisconnectPermittedID8to15;	/* Byte 30 */
 468	unsigned char:8;	/* Byte 31 */
 469	unsigned char WideTransfersPermittedID8to15;	/* Byte 32 */
 470	unsigned char WideTransfersActiveID8to15;	/* Byte 33 */
 471};
 472
 473/*
 474  Define the Initialize Extended Mailbox request structure.
 475*/
 476
 477struct BusLogic_ExtendedMailboxRequest {
 478	unsigned char MailboxCount;	/* Byte 0 */
 479	u32 BaseMailboxAddress;	/* Bytes 1-4 */
 480} PACKED;
 481
 482
 483/*
 484  Define the Inquire PCI Host Adapter Information reply type.  The ISA
 485  Compatible I/O Port values are defined here and are also used with
 486  the Modify I/O Address command.
 487*/
 488
 489enum BusLogic_ISACompatibleIOPort {
 490	BusLogic_IO_330 = 0,
 491	BusLogic_IO_334 = 1,
 492	BusLogic_IO_230 = 2,
 493	BusLogic_IO_234 = 3,
 494	BusLogic_IO_130 = 4,
 495	BusLogic_IO_134 = 5,
 496	BusLogic_IO_Disable = 6,
 497	BusLogic_IO_Disable2 = 7
 498} PACKED;
 499
 500struct BusLogic_PCIHostAdapterInformation {
 501	enum BusLogic_ISACompatibleIOPort ISACompatibleIOPort;	/* Byte 0 */
 502	unsigned char PCIAssignedIRQChannel;	/* Byte 1 */
 503	bool LowByteTerminated:1;	/* Byte 2 Bit 0 */
 504	bool HighByteTerminated:1;	/* Byte 2 Bit 1 */
 505	unsigned char:2;	/* Byte 2 Bits 2-3 */
 506	bool JP1:1;		/* Byte 2 Bit 4 */
 507	bool JP2:1;		/* Byte 2 Bit 5 */
 508	bool JP3:1;		/* Byte 2 Bit 6 */
 509	bool GenericInfoValid:1;/* Byte 2 Bit 7 */
 510	unsigned char:8;	/* Byte 3 */
 511};
 512
 513/*
 514  Define the Inquire Extended Setup Information reply structure.
 515*/
 516
 517struct BusLogic_ExtendedSetupInformation {
 518	unsigned char BusType;	/* Byte 0 */
 519	unsigned char BIOS_Address;	/* Byte 1 */
 520	unsigned short ScatterGatherLimit;	/* Bytes 2-3 */
 521	unsigned char MailboxCount;	/* Byte 4 */
 522	u32 BaseMailboxAddress;	/* Bytes 5-8 */
 523	struct {
 524		unsigned char:2;	/* Byte 9 Bits 0-1 */
 525		bool FastOnEISA:1;	/* Byte 9 Bit 2 */
 526		unsigned char:3;	/* Byte 9 Bits 3-5 */
 527		bool LevelSensitiveInterrupt:1;	/* Byte 9 Bit 6 */
 528		unsigned char:1;	/* Byte 9 Bit 7 */
 529	} Misc;
 530	unsigned char FirmwareRevision[3];	/* Bytes 10-12 */
 531	bool HostWideSCSI:1;		/* Byte 13 Bit 0 */
 532	bool HostDifferentialSCSI:1;	/* Byte 13 Bit 1 */
 533	bool HostSupportsSCAM:1;	/* Byte 13 Bit 2 */
 534	bool HostUltraSCSI:1;		/* Byte 13 Bit 3 */
 535	bool HostSmartTermination:1;	/* Byte 13 Bit 4 */
 536	unsigned char:3;	/* Byte 13 Bits 5-7 */
 537} PACKED;
 538
 539/*
 540  Define the Enable Strict Round Robin Mode request type.
 541*/
 542
 543enum BusLogic_RoundRobinModeRequest {
 544	BusLogic_AggressiveRoundRobinMode = 0,
 545	BusLogic_StrictRoundRobinMode = 1
 546} PACKED;
 547
 548
 549/*
 550  Define the Fetch Host Adapter Local RAM request type.
 551*/
 552
 553#define BusLogic_BIOS_BaseOffset		0
 554#define BusLogic_AutoSCSI_BaseOffset		64
 555
 556struct BusLogic_FetchHostAdapterLocalRAMRequest {
 557	unsigned char ByteOffset;	/* Byte 0 */
 558	unsigned char ByteCount;	/* Byte 1 */
 559};
 560
 561/*
 562  Define the Host Adapter Local RAM AutoSCSI structure.
 563*/
 564
 565struct BusLogic_AutoSCSIData {
 566	unsigned char InternalFactorySignature[2];	/* Bytes 0-1 */
 567	unsigned char InformationByteCount;	/* Byte 2 */
 568	unsigned char HostAdapterType[6];	/* Bytes 3-8 */
 569	unsigned char:8;	/* Byte 9 */
 570	bool FloppyEnabled:1;		/* Byte 10 Bit 0 */
 571	bool FloppySecondary:1;		/* Byte 10 Bit 1 */
 572	bool LevelSensitiveInterrupt:1;	/* Byte 10 Bit 2 */
 573	unsigned char:2;	/* Byte 10 Bits 3-4 */
 574	unsigned char SystemRAMAreaForBIOS:3;	/* Byte 10 Bits 5-7 */
 575	unsigned char DMA_Channel:7;	/* Byte 11 Bits 0-6 */
 576	bool DMA_AutoConfiguration:1;	/* Byte 11 Bit 7 */
 577	unsigned char IRQ_Channel:7;	/* Byte 12 Bits 0-6 */
 578	bool IRQ_AutoConfiguration:1;	/* Byte 12 Bit 7 */
 579	unsigned char DMA_TransferRate;	/* Byte 13 */
 580	unsigned char SCSI_ID;	/* Byte 14 */
 581	bool LowByteTerminated:1;	/* Byte 15 Bit 0 */
 582	bool ParityCheckingEnabled:1;	/* Byte 15 Bit 1 */
 583	bool HighByteTerminated:1;	/* Byte 15 Bit 2 */
 584	bool NoisyCablingEnvironment:1;	/* Byte 15 Bit 3 */
 585	bool FastSynchronousNegotiation:1;	/* Byte 15 Bit 4 */
 586	bool BusResetEnabled:1;		/* Byte 15 Bit 5 */
 587	 bool:1;		/* Byte 15 Bit 6 */
 588	bool ActiveNegationEnabled:1;	/* Byte 15 Bit 7 */
 589	unsigned char BusOnDelay;	/* Byte 16 */
 590	unsigned char BusOffDelay;	/* Byte 17 */
 591	bool HostAdapterBIOSEnabled:1;		/* Byte 18 Bit 0 */
 592	bool BIOSRedirectionOfINT19Enabled:1;	/* Byte 18 Bit 1 */
 593	bool ExtendedTranslationEnabled:1;	/* Byte 18 Bit 2 */
 594	bool MapRemovableAsFixedEnabled:1;	/* Byte 18 Bit 3 */
 595	 bool:1;		/* Byte 18 Bit 4 */
 596	bool BIOSSupportsMoreThan2DrivesEnabled:1;	/* Byte 18 Bit 5 */
 597	bool BIOSInterruptModeEnabled:1;	/* Byte 18 Bit 6 */
 598	bool FlopticalSupportEnabled:1;		/* Byte 19 Bit 7 */
 599	unsigned short DeviceEnabled;	/* Bytes 19-20 */
 600	unsigned short WidePermitted;	/* Bytes 21-22 */
 601	unsigned short FastPermitted;	/* Bytes 23-24 */
 602	unsigned short SynchronousPermitted;	/* Bytes 25-26 */
 603	unsigned short DisconnectPermitted;	/* Bytes 27-28 */
 604	unsigned short SendStartUnitCommand;	/* Bytes 29-30 */
 605	unsigned short IgnoreInBIOSScan;	/* Bytes 31-32 */
 606	unsigned char PCIInterruptPin:2;	/* Byte 33 Bits 0-1 */
 607	unsigned char HostAdapterIOPortAddress:2;	/* Byte 33 Bits 2-3 */
 608	bool StrictRoundRobinModeEnabled:1;	/* Byte 33 Bit 4 */
 609	bool VESABusSpeedGreaterThan33MHz:1;	/* Byte 33 Bit 5 */
 610	bool VESABurstWriteEnabled:1;	/* Byte 33 Bit 6 */
 611	bool VESABurstReadEnabled:1;	/* Byte 33 Bit 7 */
 612	unsigned short UltraPermitted;	/* Bytes 34-35 */
 613	unsigned int:32;	/* Bytes 36-39 */
 614	unsigned char:8;	/* Byte 40 */
 615	unsigned char AutoSCSIMaximumLUN;	/* Byte 41 */
 616	 bool:1;		/* Byte 42 Bit 0 */
 617	bool SCAM_Dominant:1;	/* Byte 42 Bit 1 */
 618	bool SCAM_Enabled:1;	/* Byte 42 Bit 2 */
 619	bool SCAM_Level2:1;	/* Byte 42 Bit 3 */
 620	unsigned char:4;	/* Byte 42 Bits 4-7 */
 621	bool INT13ExtensionEnabled:1;	/* Byte 43 Bit 0 */
 622	 bool:1;		/* Byte 43 Bit 1 */
 623	bool CDROMBootEnabled:1;	/* Byte 43 Bit 2 */
 624	unsigned char:5;	/* Byte 43 Bits 3-7 */
 625	unsigned char BootTargetID:4;	/* Byte 44 Bits 0-3 */
 626	unsigned char BootChannel:4;	/* Byte 44 Bits 4-7 */
 627	unsigned char ForceBusDeviceScanningOrder:1;	/* Byte 45 Bit 0 */
 628	unsigned char:7;	/* Byte 45 Bits 1-7 */
 629	unsigned short NonTaggedToAlternateLUNPermitted;	/* Bytes 46-47 */
 630	unsigned short RenegotiateSyncAfterCheckCondition;	/* Bytes 48-49 */
 631	unsigned char Reserved[10];	/* Bytes 50-59 */
 632	unsigned char ManufacturingDiagnostic[2];	/* Bytes 60-61 */
 633	unsigned short Checksum;	/* Bytes 62-63 */
 634} PACKED;
 635
 636/*
 637  Define the Host Adapter Local RAM Auto SCSI Byte 45 structure.
 638*/
 639
 640struct BusLogic_AutoSCSIByte45 {
 641	unsigned char ForceBusDeviceScanningOrder:1;	/* Bit 0 */
 642	unsigned char:7;	/* Bits 1-7 */
 643};
 644
 645/*
 646  Define the Host Adapter Local RAM BIOS Drive Map Byte structure.
 647*/
 648
 649#define BusLogic_BIOS_DriveMapOffset		17
 650
 651struct BusLogic_BIOSDriveMapByte {
 652	unsigned char TargetIDBit3:1;	/* Bit 0 */
 653	unsigned char:2;	/* Bits 1-2 */
 654	enum BusLogic_BIOS_DiskGeometryTranslation DiskGeometry:2;	/* Bits 3-4 */
 655	unsigned char TargetID:3;	/* Bits 5-7 */
 656};
 657
 658/*
 659  Define the Set CCB Format request type.  Extended LUN Format CCBs are
 660  necessary to support more than 8 Logical Units per Target Device.
 661*/
 662
 663enum BusLogic_SetCCBFormatRequest {
 664	BusLogic_LegacyLUNFormatCCB = 0,
 665	BusLogic_ExtendedLUNFormatCCB = 1
 666} PACKED;
 667
 668/*
 669  Define the Outgoing Mailbox Action Codes.
 670*/
 671
 672enum BusLogic_ActionCode {
 673	BusLogic_OutgoingMailboxFree = 0x00,
 674	BusLogic_MailboxStartCommand = 0x01,
 675	BusLogic_MailboxAbortCommand = 0x02
 676} PACKED;
 677
 678
 679/*
 680  Define the Incoming Mailbox Completion Codes.  The MultiMaster Firmware
 681  only uses codes 0 - 4.  The FlashPoint SCCB Manager has no mailboxes, so
 682  completion codes are stored in the CCB; it only uses codes 1, 2, 4, and 5.
 683*/
 684
 685enum BusLogic_CompletionCode {
 686	BusLogic_IncomingMailboxFree = 0x00,
 687	BusLogic_CommandCompletedWithoutError = 0x01,
 688	BusLogic_CommandAbortedAtHostRequest = 0x02,
 689	BusLogic_AbortedCommandNotFound = 0x03,
 690	BusLogic_CommandCompletedWithError = 0x04,
 691	BusLogic_InvalidCCB = 0x05
 692} PACKED;
 693
 694/*
 695  Define the Command Control Block (CCB) Opcodes.
 696*/
 697
 698enum BusLogic_CCB_Opcode {
 699	BusLogic_InitiatorCCB = 0x00,
 700	BusLogic_TargetCCB = 0x01,
 701	BusLogic_InitiatorCCB_ScatterGather = 0x02,
 702	BusLogic_InitiatorCCB_ResidualDataLength = 0x03,
 703	BusLogic_InitiatorCCB_ScatterGatherResidual = 0x04,
 704	BusLogic_BusDeviceReset = 0x81
 705} PACKED;
 706
 707
 708/*
 709  Define the CCB Data Direction Codes.
 710*/
 711
 712enum BusLogic_DataDirection {
 713	BusLogic_UncheckedDataTransfer = 0,
 714	BusLogic_DataInLengthChecked = 1,
 715	BusLogic_DataOutLengthChecked = 2,
 716	BusLogic_NoDataTransfer = 3
 717};
 718
 719
 720/*
 721  Define the Host Adapter Status Codes.  The MultiMaster Firmware does not
 722  return status code 0x0C; it uses 0x12 for both overruns and underruns.
 723*/
 724
 725enum BusLogic_HostAdapterStatus {
 726	BusLogic_CommandCompletedNormally = 0x00,
 727	BusLogic_LinkedCommandCompleted = 0x0A,
 728	BusLogic_LinkedCommandCompletedWithFlag = 0x0B,
 729	BusLogic_DataUnderRun = 0x0C,
 730	BusLogic_SCSISelectionTimeout = 0x11,
 731	BusLogic_DataOverRun = 0x12,
 732	BusLogic_UnexpectedBusFree = 0x13,
 733	BusLogic_InvalidBusPhaseRequested = 0x14,
 734	BusLogic_InvalidOutgoingMailboxActionCode = 0x15,
 735	BusLogic_InvalidCommandOperationCode = 0x16,
 736	BusLogic_LinkedCCBhasInvalidLUN = 0x17,
 737	BusLogic_InvalidCommandParameter = 0x1A,
 738	BusLogic_AutoRequestSenseFailed = 0x1B,
 739	BusLogic_TaggedQueuingMessageRejected = 0x1C,
 740	BusLogic_UnsupportedMessageReceived = 0x1D,
 741	BusLogic_HostAdapterHardwareFailed = 0x20,
 742	BusLogic_TargetFailedResponseToATN = 0x21,
 743	BusLogic_HostAdapterAssertedRST = 0x22,
 744	BusLogic_OtherDeviceAssertedRST = 0x23,
 745	BusLogic_TargetDeviceReconnectedImproperly = 0x24,
 746	BusLogic_HostAdapterAssertedBusDeviceReset = 0x25,
 747	BusLogic_AbortQueueGenerated = 0x26,
 748	BusLogic_HostAdapterSoftwareError = 0x27,
 749	BusLogic_HostAdapterHardwareTimeoutError = 0x30,
 750	BusLogic_SCSIParityErrorDetected = 0x34
 751} PACKED;
 752
 753
 754/*
 755  Define the SCSI Target Device Status Codes.
 756*/
 757
 758enum BusLogic_TargetDeviceStatus {
 759	BusLogic_OperationGood = 0x00,
 760	BusLogic_CheckCondition = 0x02,
 761	BusLogic_DeviceBusy = 0x08
 762} PACKED;
 763
 764/*
 765  Define the Queue Tag Codes.
 766*/
 767
 768enum BusLogic_QueueTag {
 769	BusLogic_SimpleQueueTag = 0,
 770	BusLogic_HeadOfQueueTag = 1,
 771	BusLogic_OrderedQueueTag = 2,
 772	BusLogic_ReservedQT = 3
 773};
 774
 775/*
 776  Define the SCSI Command Descriptor Block (CDB).
 777*/
 778
 779#define BusLogic_CDB_MaxLength			12
 780
 781typedef unsigned char SCSI_CDB_T[BusLogic_CDB_MaxLength];
 782
 783
 784/*
 785  Define the Scatter/Gather Segment structure required by the MultiMaster
 786  Firmware Interface and the FlashPoint SCCB Manager.
 787*/
 788
 789struct BusLogic_ScatterGatherSegment {
 790	u32 SegmentByteCount;	/* Bytes 0-3 */
 791	u32 SegmentDataPointer;	/* Bytes 4-7 */
 792};
 793
 794/*
 795  Define the Driver CCB Status Codes.
 796*/
 797
 798enum BusLogic_CCB_Status {
 799	BusLogic_CCB_Free = 0,
 800	BusLogic_CCB_Active = 1,
 801	BusLogic_CCB_Completed = 2,
 802	BusLogic_CCB_Reset = 3
 803} PACKED;
 804
 805
 806/*
 807  Define the 32 Bit Mode Command Control Block (CCB) structure.  The first 40
 808  bytes are defined by and common to both the MultiMaster Firmware and the
 809  FlashPoint SCCB Manager.  The next 60 bytes are defined by the FlashPoint
 810  SCCB Manager.  The remaining components are defined by the Linux BusLogic
 811  Driver.  Extended LUN Format CCBs differ from Legacy LUN Format 32 Bit Mode
 812  CCBs only in having the TagEnable and QueueTag fields moved from byte 17 to
 813  byte 1, and the Logical Unit field in byte 17 expanded to 6 bits.  In theory,
 814  Extended LUN Format CCBs can support up to 64 Logical Units, but in practice
 815  many devices will respond improperly to Logical Units between 32 and 63, and
 816  the SCSI-2 specification defines Bit 5 as LUNTAR.  Extended LUN Format CCBs
 817  are used by recent versions of the MultiMaster Firmware, as well as by the
 818  FlashPoint SCCB Manager; the FlashPoint SCCB Manager only supports 32 Logical
 819  Units.  Since 64 Logical Units are unlikely to be needed in practice, and
 820  since they are problematic for the above reasons, and since limiting them to
 821  5 bits simplifies the CCB structure definition, this driver only supports
 822  32 Logical Units per Target Device.
 823*/
 824
 825struct BusLogic_CCB {
 826	/*
 827	   MultiMaster Firmware and FlashPoint SCCB Manager Common Portion.
 828	 */
 829	enum BusLogic_CCB_Opcode Opcode;	/* Byte 0 */
 830	unsigned char:3;	/* Byte 1 Bits 0-2 */
 831	enum BusLogic_DataDirection DataDirection:2;	/* Byte 1 Bits 3-4 */
 832	bool TagEnable:1;	/* Byte 1 Bit 5 */
 833	enum BusLogic_QueueTag QueueTag:2;	/* Byte 1 Bits 6-7 */
 834	unsigned char CDB_Length;	/* Byte 2 */
 835	unsigned char SenseDataLength;	/* Byte 3 */
 836	u32 DataLength;		/* Bytes 4-7 */
 837	u32 DataPointer;	/* Bytes 8-11 */
 838	unsigned char:8;	/* Byte 12 */
 839	unsigned char:8;	/* Byte 13 */
 840	enum BusLogic_HostAdapterStatus HostAdapterStatus;	/* Byte 14 */
 841	enum BusLogic_TargetDeviceStatus TargetDeviceStatus;	/* Byte 15 */
 842	unsigned char TargetID;	/* Byte 16 */
 843	unsigned char LogicalUnit:5;	/* Byte 17 Bits 0-4 */
 844	bool LegacyTagEnable:1;	/* Byte 17 Bit 5 */
 845	enum BusLogic_QueueTag LegacyQueueTag:2;	/* Byte 17 Bits 6-7 */
 846	SCSI_CDB_T CDB;		/* Bytes 18-29 */
 847	unsigned char:8;	/* Byte 30 */
 848	unsigned char:8;	/* Byte 31 */
 849	unsigned int:32;	/* Bytes 32-35 */
 850	u32 SenseDataPointer;	/* Bytes 36-39 */
 851	/*
 852	   FlashPoint SCCB Manager Defined Portion.
 853	 */
 854	void (*CallbackFunction) (struct BusLogic_CCB *);	/* Bytes 40-43 */
 855	u32 BaseAddress;	/* Bytes 44-47 */
 856	enum BusLogic_CompletionCode CompletionCode;	/* Byte 48 */
 857#ifdef CONFIG_SCSI_FLASHPOINT
 858	unsigned char:8;	/* Byte 49 */
 859	unsigned short OS_Flags;	/* Bytes 50-51 */
 860	unsigned char Private[48];	/* Bytes 52-99 */
 
 
 
 861#endif
 862	/*
 863	   BusLogic Linux Driver Defined Portion.
 864	 */
 865	dma_addr_t AllocationGroupHead;
 866	unsigned int AllocationGroupSize;
 867	u32 DMA_Handle;
 868	enum BusLogic_CCB_Status Status;
 869	unsigned long SerialNumber;
 870	struct scsi_cmnd *Command;
 871	struct BusLogic_HostAdapter *HostAdapter;
 872	struct BusLogic_CCB *Next;
 873	struct BusLogic_CCB *NextAll;
 874	struct BusLogic_ScatterGatherSegment
 875	 ScatterGatherList[BusLogic_ScatterGatherLimit];
 876};
 877
 878/*
 879  Define the 32 Bit Mode Outgoing Mailbox structure.
 880*/
 881
 882struct BusLogic_OutgoingMailbox {
 883	u32 CCB;		/* Bytes 0-3 */
 884	unsigned int:24;	/* Bytes 4-6 */
 885	enum BusLogic_ActionCode ActionCode;	/* Byte 7 */
 886};
 887
 888/*
 889  Define the 32 Bit Mode Incoming Mailbox structure.
 890*/
 891
 892struct BusLogic_IncomingMailbox {
 893	u32 CCB;		/* Bytes 0-3 */
 894	enum BusLogic_HostAdapterStatus HostAdapterStatus;	/* Byte 4 */
 895	enum BusLogic_TargetDeviceStatus TargetDeviceStatus;	/* Byte 5 */
 896	unsigned char:8;	/* Byte 6 */
 897	enum BusLogic_CompletionCode CompletionCode;	/* Byte 7 */
 898};
 899
 900
 901/*
 902  Define the BusLogic Driver Options structure.
 903*/
 904
 905struct BusLogic_DriverOptions {
 906	unsigned short TaggedQueuingPermitted;
 907	unsigned short TaggedQueuingPermittedMask;
 908	unsigned short BusSettleTime;
 909	struct BusLogic_LocalOptions LocalOptions;
 910	unsigned char CommonQueueDepth;
 911	unsigned char QueueDepth[BusLogic_MaxTargetDevices];
 912};
 913
 914/*
 915  Define the Host Adapter Target Flags structure.
 916*/
 917
 918struct BusLogic_TargetFlags {
 919	bool TargetExists:1;
 920	bool TaggedQueuingSupported:1;
 921	bool WideTransfersSupported:1;
 922	bool TaggedQueuingActive:1;
 923	bool WideTransfersActive:1;
 924	bool CommandSuccessfulFlag:1;
 925	bool TargetInfoReported:1;
 926};
 927
 928/*
 929  Define the Host Adapter Target Statistics structure.
 930*/
 931
 932#define BusLogic_SizeBuckets			10
 933
 934typedef unsigned int BusLogic_CommandSizeBuckets_T[BusLogic_SizeBuckets];
 935
 936struct BusLogic_TargetStatistics {
 937	unsigned int CommandsAttempted;
 938	unsigned int CommandsCompleted;
 939	unsigned int ReadCommands;
 940	unsigned int WriteCommands;
 941	struct BusLogic_ByteCounter TotalBytesRead;
 942	struct BusLogic_ByteCounter TotalBytesWritten;
 943	BusLogic_CommandSizeBuckets_T ReadCommandSizeBuckets;
 944	BusLogic_CommandSizeBuckets_T WriteCommandSizeBuckets;
 945	unsigned short CommandAbortsRequested;
 946	unsigned short CommandAbortsAttempted;
 947	unsigned short CommandAbortsCompleted;
 948	unsigned short BusDeviceResetsRequested;
 949	unsigned short BusDeviceResetsAttempted;
 950	unsigned short BusDeviceResetsCompleted;
 951	unsigned short HostAdapterResetsRequested;
 952	unsigned short HostAdapterResetsAttempted;
 953	unsigned short HostAdapterResetsCompleted;
 954};
 955
 956/*
 957  Define the FlashPoint Card Handle data type.
 958*/
 959
 960#define FlashPoint_BadCardHandle		0xFFFFFFFF
 961
 962typedef unsigned int FlashPoint_CardHandle_T;
 963
 964
 965/*
 966  Define the FlashPoint Information structure.  This structure is defined
 967  by the FlashPoint SCCB Manager.
 968*/
 969
 970struct FlashPoint_Info {
 971	u32 BaseAddress;	/* Bytes 0-3 */
 972	bool Present;		/* Byte 4 */
 973	unsigned char IRQ_Channel;	/* Byte 5 */
 974	unsigned char SCSI_ID;	/* Byte 6 */
 975	unsigned char SCSI_LUN;	/* Byte 7 */
 976	unsigned short FirmwareRevision;	/* Bytes 8-9 */
 977	unsigned short SynchronousPermitted;	/* Bytes 10-11 */
 978	unsigned short FastPermitted;	/* Bytes 12-13 */
 979	unsigned short UltraPermitted;	/* Bytes 14-15 */
 980	unsigned short DisconnectPermitted;	/* Bytes 16-17 */
 981	unsigned short WidePermitted;	/* Bytes 18-19 */
 982	bool ParityCheckingEnabled:1;	/* Byte 20 Bit 0 */
 983	bool HostWideSCSI:1;		/* Byte 20 Bit 1 */
 984	bool HostSoftReset:1;		/* Byte 20 Bit 2 */
 985	bool ExtendedTranslationEnabled:1;	/* Byte 20 Bit 3 */
 986	bool LowByteTerminated:1;	/* Byte 20 Bit 4 */
 987	bool HighByteTerminated:1;	/* Byte 20 Bit 5 */
 988	bool ReportDataUnderrun:1;	/* Byte 20 Bit 6 */
 989	bool SCAM_Enabled:1;	/* Byte 20 Bit 7 */
 990	bool SCAM_Level2:1;	/* Byte 21 Bit 0 */
 991	unsigned char:7;	/* Byte 21 Bits 1-7 */
 992	unsigned char Family;	/* Byte 22 */
 993	unsigned char BusType;	/* Byte 23 */
 994	unsigned char ModelNumber[3];	/* Bytes 24-26 */
 995	unsigned char RelativeCardNumber;	/* Byte 27 */
 996	unsigned char Reserved[4];	/* Bytes 28-31 */
 997	unsigned int OS_Reserved;	/* Bytes 32-35 */
 998	unsigned char TranslationInfo[4];	/* Bytes 36-39 */
 999	unsigned int Reserved2[5];	/* Bytes 40-59 */
1000	unsigned int SecondaryRange;	/* Bytes 60-63 */
1001};
1002
1003/*
1004  Define the BusLogic Driver Host Adapter structure.
1005*/
1006
1007struct BusLogic_HostAdapter {
1008	struct Scsi_Host *SCSI_Host;
1009	struct pci_dev *PCI_Device;
1010	enum BusLogic_HostAdapterType HostAdapterType;
1011	enum BusLogic_HostAdapterBusType HostAdapterBusType;
1012	unsigned long IO_Address;
1013	unsigned long PCI_Address;
1014	unsigned short AddressCount;
1015	unsigned char HostNumber;
1016	unsigned char ModelName[9];
1017	unsigned char FirmwareVersion[6];
1018	unsigned char FullModelName[18];
1019	unsigned char Bus;
1020	unsigned char Device;
1021	unsigned char IRQ_Channel;
1022	unsigned char DMA_Channel;
1023	unsigned char SCSI_ID;
1024	bool IRQ_ChannelAcquired:1;
1025	bool DMA_ChannelAcquired:1;
1026	bool ExtendedTranslationEnabled:1;
1027	bool ParityCheckingEnabled:1;
1028	bool BusResetEnabled:1;
1029	bool LevelSensitiveInterrupt:1;
1030	bool HostWideSCSI:1;
1031	bool HostDifferentialSCSI:1;
1032	bool HostSupportsSCAM:1;
1033	bool HostUltraSCSI:1;
1034	bool ExtendedLUNSupport:1;
1035	bool TerminationInfoValid:1;
1036	bool LowByteTerminated:1;
1037	bool HighByteTerminated:1;
1038	bool BounceBuffersRequired:1;
1039	bool StrictRoundRobinModeSupport:1;
1040	bool SCAM_Enabled:1;
1041	bool SCAM_Level2:1;
1042	bool HostAdapterInitialized:1;
1043	bool HostAdapterExternalReset:1;
1044	bool HostAdapterInternalError:1;
1045	bool ProcessCompletedCCBsActive;
1046	volatile bool HostAdapterCommandCompleted;
1047	unsigned short HostAdapterScatterGatherLimit;
1048	unsigned short DriverScatterGatherLimit;
1049	unsigned short MaxTargetDevices;
1050	unsigned short MaxLogicalUnits;
1051	unsigned short MailboxCount;
1052	unsigned short InitialCCBs;
1053	unsigned short IncrementalCCBs;
1054	unsigned short AllocatedCCBs;
1055	unsigned short DriverQueueDepth;
1056	unsigned short HostAdapterQueueDepth;
1057	unsigned short UntaggedQueueDepth;
1058	unsigned short CommonQueueDepth;
1059	unsigned short BusSettleTime;
1060	unsigned short SynchronousPermitted;
1061	unsigned short FastPermitted;
1062	unsigned short UltraPermitted;
1063	unsigned short WidePermitted;
1064	unsigned short DisconnectPermitted;
1065	unsigned short TaggedQueuingPermitted;
1066	unsigned short ExternalHostAdapterResets;
1067	unsigned short HostAdapterInternalErrors;
1068	unsigned short TargetDeviceCount;
1069	unsigned short MessageBufferLength;
1070	u32 BIOS_Address;
1071	struct BusLogic_DriverOptions *DriverOptions;
1072	struct FlashPoint_Info FlashPointInfo;
1073	FlashPoint_CardHandle_T CardHandle;
1074	struct list_head host_list;
1075	struct BusLogic_CCB *All_CCBs;
1076	struct BusLogic_CCB *Free_CCBs;
1077	struct BusLogic_CCB *FirstCompletedCCB;
1078	struct BusLogic_CCB *LastCompletedCCB;
1079	struct BusLogic_CCB *BusDeviceResetPendingCCB[BusLogic_MaxTargetDevices];
1080	struct BusLogic_TargetFlags TargetFlags[BusLogic_MaxTargetDevices];
1081	unsigned char QueueDepth[BusLogic_MaxTargetDevices];
1082	unsigned char SynchronousPeriod[BusLogic_MaxTargetDevices];
1083	unsigned char SynchronousOffset[BusLogic_MaxTargetDevices];
1084	unsigned char ActiveCommands[BusLogic_MaxTargetDevices];
1085	unsigned int CommandsSinceReset[BusLogic_MaxTargetDevices];
1086	unsigned long LastSequencePoint[BusLogic_MaxTargetDevices];
1087	unsigned long LastResetAttempted[BusLogic_MaxTargetDevices];
1088	unsigned long LastResetCompleted[BusLogic_MaxTargetDevices];
1089	struct BusLogic_OutgoingMailbox *FirstOutgoingMailbox;
1090	struct BusLogic_OutgoingMailbox *LastOutgoingMailbox;
1091	struct BusLogic_OutgoingMailbox *NextOutgoingMailbox;
1092	struct BusLogic_IncomingMailbox *FirstIncomingMailbox;
1093	struct BusLogic_IncomingMailbox *LastIncomingMailbox;
1094	struct BusLogic_IncomingMailbox *NextIncomingMailbox;
1095	struct BusLogic_TargetStatistics TargetStatistics[BusLogic_MaxTargetDevices];
1096	unsigned char *MailboxSpace;
1097	dma_addr_t MailboxSpaceHandle;
1098	unsigned int MailboxSize;
1099	unsigned long CCB_Offset;
1100	char MessageBuffer[BusLogic_MessageBufferSize];
1101};
1102
1103/*
1104  Define a structure for the BIOS Disk Parameters.
1105*/
1106
1107struct BIOS_DiskParameters {
1108	int Heads;
1109	int Sectors;
1110	int Cylinders;
1111};
1112
1113/*
1114  Define a structure for the SCSI Inquiry command results.
1115*/
1116
1117struct SCSI_Inquiry {
1118	unsigned char PeripheralDeviceType:5;	/* Byte 0 Bits 0-4 */
1119	unsigned char PeripheralQualifier:3;	/* Byte 0 Bits 5-7 */
1120	unsigned char DeviceTypeModifier:7;	/* Byte 1 Bits 0-6 */
1121	bool RMB:1;		/* Byte 1 Bit 7 */
1122	unsigned char ANSI_ApprovedVersion:3;	/* Byte 2 Bits 0-2 */
1123	unsigned char ECMA_Version:3;	/* Byte 2 Bits 3-5 */
1124	unsigned char ISO_Version:2;	/* Byte 2 Bits 6-7 */
1125	unsigned char ResponseDataFormat:4;	/* Byte 3 Bits 0-3 */
1126	unsigned char:2;	/* Byte 3 Bits 4-5 */
1127	bool TrmIOP:1;		/* Byte 3 Bit 6 */
1128	bool AENC:1;		/* Byte 3 Bit 7 */
1129	unsigned char AdditionalLength;	/* Byte 4 */
1130	unsigned char:8;	/* Byte 5 */
1131	unsigned char:8;	/* Byte 6 */
1132	bool SftRe:1;		/* Byte 7 Bit 0 */
1133	bool CmdQue:1;		/* Byte 7 Bit 1 */
1134	 bool:1;		/* Byte 7 Bit 2 */
1135	bool Linked:1;		/* Byte 7 Bit 3 */
1136	bool Sync:1;		/* Byte 7 Bit 4 */
1137	bool WBus16:1;		/* Byte 7 Bit 5 */
1138	bool WBus32:1;		/* Byte 7 Bit 6 */
1139	bool RelAdr:1;		/* Byte 7 Bit 7 */
1140	unsigned char VendorIdentification[8];	/* Bytes 8-15 */
1141	unsigned char ProductIdentification[16];	/* Bytes 16-31 */
1142	unsigned char ProductRevisionLevel[4];	/* Bytes 32-35 */
1143};
1144
1145
1146/*
1147  Define functions to provide an abstraction for reading and writing the
1148  Host Adapter I/O Registers.
1149*/
1150
1151static inline void BusLogic_SCSIBusReset(struct BusLogic_HostAdapter *HostAdapter)
1152{
1153	union BusLogic_ControlRegister ControlRegister;
1154	ControlRegister.All = 0;
1155	ControlRegister.cr.SCSIBusReset = true;
1156	outb(ControlRegister.All, HostAdapter->IO_Address + BusLogic_ControlRegisterOffset);
1157}
1158
1159static inline void BusLogic_InterruptReset(struct BusLogic_HostAdapter *HostAdapter)
1160{
1161	union BusLogic_ControlRegister ControlRegister;
1162	ControlRegister.All = 0;
1163	ControlRegister.cr.InterruptReset = true;
1164	outb(ControlRegister.All, HostAdapter->IO_Address + BusLogic_ControlRegisterOffset);
1165}
1166
1167static inline void BusLogic_SoftReset(struct BusLogic_HostAdapter *HostAdapter)
1168{
1169	union BusLogic_ControlRegister ControlRegister;
1170	ControlRegister.All = 0;
1171	ControlRegister.cr.SoftReset = true;
1172	outb(ControlRegister.All, HostAdapter->IO_Address + BusLogic_ControlRegisterOffset);
1173}
1174
1175static inline void BusLogic_HardReset(struct BusLogic_HostAdapter *HostAdapter)
1176{
1177	union BusLogic_ControlRegister ControlRegister;
1178	ControlRegister.All = 0;
1179	ControlRegister.cr.HardReset = true;
1180	outb(ControlRegister.All, HostAdapter->IO_Address + BusLogic_ControlRegisterOffset);
1181}
1182
1183static inline unsigned char BusLogic_ReadStatusRegister(struct BusLogic_HostAdapter *HostAdapter)
1184{
1185	return inb(HostAdapter->IO_Address + BusLogic_StatusRegisterOffset);
1186}
1187
1188static inline void BusLogic_WriteCommandParameterRegister(struct BusLogic_HostAdapter
1189							  *HostAdapter, unsigned char Value)
1190{
1191	outb(Value, HostAdapter->IO_Address + BusLogic_CommandParameterRegisterOffset);
1192}
1193
1194static inline unsigned char BusLogic_ReadDataInRegister(struct BusLogic_HostAdapter *HostAdapter)
1195{
1196	return inb(HostAdapter->IO_Address + BusLogic_DataInRegisterOffset);
1197}
1198
1199static inline unsigned char BusLogic_ReadInterruptRegister(struct BusLogic_HostAdapter *HostAdapter)
1200{
1201	return inb(HostAdapter->IO_Address + BusLogic_InterruptRegisterOffset);
1202}
1203
1204static inline unsigned char BusLogic_ReadGeometryRegister(struct BusLogic_HostAdapter *HostAdapter)
1205{
1206	return inb(HostAdapter->IO_Address + BusLogic_GeometryRegisterOffset);
1207}
1208
1209/*
1210  BusLogic_StartMailboxCommand issues an Execute Mailbox Command, which
1211  notifies the Host Adapter that an entry has been made in an Outgoing
1212  Mailbox.
1213*/
1214
1215static inline void BusLogic_StartMailboxCommand(struct BusLogic_HostAdapter *HostAdapter)
1216{
1217	BusLogic_WriteCommandParameterRegister(HostAdapter, BusLogic_ExecuteMailboxCommand);
1218}
1219
1220/*
1221  BusLogic_Delay waits for Seconds to elapse.
1222*/
1223
1224static inline void BusLogic_Delay(int Seconds)
1225{
1226	mdelay(1000 * Seconds);
1227}
1228
1229/*
1230  Virtual_to_Bus and Bus_to_Virtual map between Kernel Virtual Addresses
1231  and PCI/VLB/EISA/ISA Bus Addresses.
1232*/
1233
1234static inline u32 Virtual_to_Bus(void *VirtualAddress)
1235{
1236	return (u32) virt_to_bus(VirtualAddress);
1237}
1238
1239static inline void *Bus_to_Virtual(u32 BusAddress)
1240{
1241	return (void *) bus_to_virt(BusAddress);
1242}
1243
1244/*
1245  Virtual_to_32Bit_Virtual maps between Kernel Virtual Addresses and
1246  32 bit Kernel Virtual Addresses.  This avoids compilation warnings
1247  on 64 bit architectures.
1248*/
1249
1250static inline u32 Virtual_to_32Bit_Virtual(void *VirtualAddress)
1251{
1252	return (u32) (unsigned long) VirtualAddress;
1253}
1254
1255/*
1256  BusLogic_IncrementErrorCounter increments Error Counter by 1, stopping at
1257  65535 rather than wrapping around to 0.
1258*/
1259
1260static inline void BusLogic_IncrementErrorCounter(unsigned short *ErrorCounter)
1261{
1262	if (*ErrorCounter < 65535)
1263		(*ErrorCounter)++;
1264}
1265
1266/*
1267  BusLogic_IncrementByteCounter increments Byte Counter by Amount.
1268*/
1269
1270static inline void BusLogic_IncrementByteCounter(struct BusLogic_ByteCounter
1271						 *ByteCounter, unsigned int Amount)
1272{
1273	ByteCounter->Units += Amount;
1274	if (ByteCounter->Units > 999999999) {
1275		ByteCounter->Units -= 1000000000;
1276		ByteCounter->Billions++;
1277	}
1278}
1279
1280/*
1281  BusLogic_IncrementSizeBucket increments the Bucket for Amount.
1282*/
1283
1284static inline void BusLogic_IncrementSizeBucket(BusLogic_CommandSizeBuckets_T CommandSizeBuckets, unsigned int Amount)
 
1285{
1286	int Index = 0;
1287	if (Amount < 8 * 1024) {
1288		if (Amount < 2 * 1024)
1289			Index = (Amount < 1 * 1024 ? 0 : 1);
1290		else
1291			Index = (Amount < 4 * 1024 ? 2 : 3);
1292	} else if (Amount < 128 * 1024) {
1293		if (Amount < 32 * 1024)
1294			Index = (Amount < 16 * 1024 ? 4 : 5);
1295		else
1296			Index = (Amount < 64 * 1024 ? 6 : 7);
1297	} else
1298		Index = (Amount < 256 * 1024 ? 8 : 9);
1299	CommandSizeBuckets[Index]++;
1300}
1301
1302/*
1303  Define the version number of the FlashPoint Firmware (SCCB Manager).
1304*/
1305
1306#define FlashPoint_FirmwareVersion		"5.02"
1307
1308/*
1309  Define the possible return values from FlashPoint_HandleInterrupt.
1310*/
1311
1312#define FlashPoint_NormalInterrupt		0x00
1313#define FlashPoint_InternalError		0xFE
1314#define FlashPoint_ExternalBusReset		0xFF
1315
1316/*
1317  Define prototypes for the forward referenced BusLogic Driver
1318  Internal Functions.
1319*/
1320
1321static const char *BusLogic_DriverInfo(struct Scsi_Host *);
1322static int BusLogic_QueueCommand(struct Scsi_Host *h, struct scsi_cmnd *);
1323static int BusLogic_BIOSDiskParameters(struct scsi_device *, struct block_device *, sector_t, int *);
1324static int BusLogic_ProcDirectoryInfo(struct Scsi_Host *, char *, char **, off_t, int, int);
1325static int BusLogic_SlaveConfigure(struct scsi_device *);
1326static void BusLogic_QueueCompletedCCB(struct BusLogic_CCB *);
1327static irqreturn_t BusLogic_InterruptHandler(int, void *);
1328static int BusLogic_ResetHostAdapter(struct BusLogic_HostAdapter *, bool HardReset);
1329static void BusLogic_Message(enum BusLogic_MessageLevel, char *, struct BusLogic_HostAdapter *, ...);
1330static int __init BusLogic_Setup(char *);
1331
1332#endif				/* _BUSLOGIC_H */
v3.15
   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
  32#ifndef PACKED
  33#define PACKED __attribute__((packed))
  34#endif
  35
  36/*
  37  Define the maximum number of BusLogic Host Adapters supported by this driver.
  38*/
  39
  40#define BLOGIC_MAX_ADAPTERS		16
  41
  42
  43/*
  44  Define the maximum number of Target Devices supported by this driver.
  45*/
  46
  47#define BLOGIC_MAXDEV			16
  48
  49
  50/*
  51  Define the maximum number of Scatter/Gather Segments used by this driver.
  52  For optimal performance, it is important that this limit be at least as
  53  large as the largest single request generated by the I/O Subsystem.
  54*/
  55
  56#define BLOGIC_SG_LIMIT		128
  57
  58
  59/*
  60  Define the maximum, maximum automatic, minimum automatic, and default Queue
  61  Depth to allow for Target Devices depending on whether or not they support
  62  Tagged Queuing and whether or not ISA Bounce Buffers are required.
  63*/
  64
  65#define BLOGIC_MAX_TAG_DEPTH		64
  66#define BLOGIC_MAX_AUTO_TAG_DEPTH	28
  67#define BLOGIC_MIN_AUTO_TAG_DEPTH	7
  68#define BLOGIC_TAG_DEPTH_BB		3
  69#define BLOGIC_UNTAG_DEPTH		3
  70#define BLOGIC_UNTAG_DEPTH_BB		2
  71
  72
  73/*
  74  Define the default amount of time in seconds to wait between a Host Adapter
  75  Hard Reset which initiates a SCSI Bus Reset and issuing any SCSI commands.
  76  Some SCSI devices get confused if they receive SCSI commands too soon after
  77  a SCSI Bus Reset.
  78*/
  79
  80#define BLOGIC_BUS_SETTLE_TIME		2
  81
  82
  83/*
  84  Define the maximum number of Mailboxes that should be used for MultiMaster
  85  Host Adapters.  This number is chosen to be larger than the maximum Host
  86  Adapter Queue Depth and small enough so that the Host Adapter structure
  87  does not cross an allocation block size boundary.
  88*/
  89
  90#define BLOGIC_MAX_MAILBOX		211
  91
  92
  93/*
  94  Define the number of CCBs that should be allocated as a group to optimize
  95  Kernel memory allocation.
  96*/
  97
  98#define BLOGIC_CCB_GRP_ALLOCSIZE	7
  99
 100
 101/*
 102  Define the Host Adapter Line and Message Buffer Sizes.
 103*/
 104
 105#define BLOGIC_LINEBUF_SIZE		100
 106#define BLOGIC_MSGBUF_SIZE		9700
 107
 108
 109/*
 110  Define the Driver Message Levels.
 111*/
 112
 113enum blogic_msglevel {
 114	BLOGIC_ANNOUNCE_LEVEL = 0,
 115	BLOGIC_INFO_LEVEL = 1,
 116	BLOGIC_NOTICE_LEVEL = 2,
 117	BLOGIC_WARN_LEVEL = 3,
 118	BLOGIC_ERR_LEVEL = 4
 119};
 120
 121static char *blogic_msglevelmap[] = { KERN_NOTICE, KERN_NOTICE, KERN_NOTICE, KERN_WARNING, KERN_ERR };
 122
 123
 124/*
 125  Define Driver Message macros.
 126*/
 127
 128#define blogic_announce(format, args...) \
 129	blogic_msg(BLOGIC_ANNOUNCE_LEVEL, format, ##args)
 130
 131#define blogic_info(format, args...) \
 132	blogic_msg(BLOGIC_INFO_LEVEL, format, ##args)
 133
 134#define blogic_notice(format, args...) \
 135	blogic_msg(BLOGIC_NOTICE_LEVEL, format, ##args)
 136
 137#define blogic_warn(format, args...) \
 138	blogic_msg(BLOGIC_WARN_LEVEL, format, ##args)
 139
 140#define blogic_err(format, args...) \
 141	blogic_msg(BLOGIC_ERR_LEVEL, format, ##args)
 142
 143
 144/*
 145  Define the types of BusLogic Host Adapters that are supported and the number
 146  of I/O Addresses required by each type.
 147*/
 148
 149enum blogic_adapter_type {
 150	BLOGIC_MULTIMASTER = 1,
 151	BLOGIC_FLASHPOINT = 2
 152} PACKED;
 153
 154#define BLOGIC_MULTIMASTER_ADDR_COUNT	4
 155#define BLOGIC_FLASHPOINT_ADDR_COUNT	256
 156
 157static int blogic_adapter_addr_count[3] = { 0, BLOGIC_MULTIMASTER_ADDR_COUNT, BLOGIC_FLASHPOINT_ADDR_COUNT };
 158
 159
 160/*
 161  Define macros for testing the Host Adapter Type.
 162*/
 163
 164#ifdef CONFIG_SCSI_FLASHPOINT
 165
 166#define blogic_multimaster_type(adapter) \
 167	(adapter->adapter_type == BLOGIC_MULTIMASTER)
 168
 169#define blogic_flashpoint_type(adapter) \
 170	(adapter->adapter_type == BLOGIC_FLASHPOINT)
 171
 172#else
 173
 174#define blogic_multimaster_type(adapter)	(true)
 175#define blogic_flashpoint_type(adapter)		(false)
 
 
 
 176
 177#endif
 178
 179
 180/*
 181  Define the possible Host Adapter Bus Types.
 182*/
 183
 184enum blogic_adapter_bus_type {
 185	BLOGIC_UNKNOWN_BUS = 0,
 186	BLOGIC_ISA_BUS = 1,
 187	BLOGIC_EISA_BUS = 2,
 188	BLOGIC_PCI_BUS = 3,
 189	BLOGIC_VESA_BUS = 4,
 190	BLOGIC_MCA_BUS = 5
 191} PACKED;
 192
 193static char *blogic_adapter_busnames[] = { "Unknown", "ISA", "EISA", "PCI", "VESA", "MCA" };
 194
 195static enum blogic_adapter_bus_type blogic_adater_bus_types[] = {
 196	BLOGIC_VESA_BUS,	/* BT-4xx */
 197	BLOGIC_ISA_BUS,		/* BT-5xx */
 198	BLOGIC_MCA_BUS,		/* BT-6xx */
 199	BLOGIC_EISA_BUS,	/* BT-7xx */
 200	BLOGIC_UNKNOWN_BUS,	/* BT-8xx */
 201	BLOGIC_PCI_BUS		/* BT-9xx */
 202};
 203
 204/*
 205  Define the possible Host Adapter BIOS Disk Geometry Translations.
 206*/
 207
 208enum blogic_bios_diskgeometry {
 209	BLOGIC_BIOS_NODISK = 0,
 210	BLOGIC_BIOS_DISK64x32 = 1,
 211	BLOGIC_BIOS_DISK128x32 = 2,
 212	BLOGIC_BIOS_DISK255x63 = 3
 213} PACKED;
 214
 215
 216/*
 217  Define a 10^18 Statistics Byte Counter data type.
 218*/
 219
 220struct blogic_byte_count {
 221	unsigned int units;
 222	unsigned int billions;
 223};
 224
 225
 226/*
 227  Define the structure for I/O Address and Bus Probing Information.
 228*/
 229
 230struct blogic_probeinfo {
 231	enum blogic_adapter_type adapter_type;
 232	enum blogic_adapter_bus_type adapter_bus_type;
 233	unsigned long io_addr;
 234	unsigned long pci_addr;
 235	struct pci_dev *pci_device;
 236	unsigned char bus;
 237	unsigned char dev;
 238	unsigned char irq_ch;
 239};
 240
 241/*
 242  Define the Probe Options.
 243*/
 244
 245struct blogic_probe_options {
 246	bool noprobe:1;			/* Bit 0 */
 247	bool noprobe_isa:1;		/* Bit 1 */
 248	bool noprobe_pci:1;		/* Bit 2 */
 249	bool nosort_pci:1;		/* Bit 3 */
 250	bool multimaster_first:1;	/* Bit 4 */
 251	bool flashpoint_first:1;	/* Bit 5 */
 252	bool limited_isa:1;		/* Bit 6 */
 253	bool probe330:1;		/* Bit 7 */
 254	bool probe334:1;		/* Bit 8 */
 255	bool probe230:1;		/* Bit 9 */
 256	bool probe234:1;		/* Bit 10 */
 257	bool probe130:1;		/* Bit 11 */
 258	bool probe134:1;		/* Bit 12 */
 259};
 260
 261/*
 262  Define the Global Options.
 263*/
 264
 265struct blogic_global_options {
 266	bool trace_probe:1;	/* Bit 0 */
 267	bool trace_hw_reset:1;	/* Bit 1 */
 268	bool trace_config:1;	/* Bit 2 */
 269	bool trace_err:1;	/* Bit 3 */
 
 
 
 
 
 
 
 
 270};
 271
 272/*
 273  Define the BusLogic SCSI Host Adapter I/O Register Offsets.
 274*/
 275
 276#define BLOGIC_CNTRL_REG	0	/* WO register */
 277#define BLOGIC_STATUS_REG	0	/* RO register */
 278#define BLOGIC_CMD_PARM_REG	1	/* WO register */
 279#define BLOGIC_DATAIN_REG	1	/* RO register */
 280#define BLOGIC_INT_REG		2	/* RO register */
 281#define BLOGIC_GEOMETRY_REG	3	/* RO register */
 282
 283/*
 284  Define the structure of the write-only Control Register.
 285*/
 286
 287union blogic_cntrl_reg {
 288	unsigned char all;
 289	struct {
 290		unsigned char:4;	/* Bits 0-3 */
 291		bool bus_reset:1;	/* Bit 4 */
 292		bool int_reset:1;	/* Bit 5 */
 293		bool soft_reset:1;	/* Bit 6 */
 294		bool hard_reset:1;	/* Bit 7 */
 295	} cr;
 296};
 297
 298/*
 299  Define the structure of the read-only Status Register.
 300*/
 301
 302union blogic_stat_reg {
 303	unsigned char all;
 304	struct {
 305		bool cmd_invalid:1;	/* Bit 0 */
 306		bool rsvd:1;		/* Bit 1 */
 307		bool datain_ready:1;	/* Bit 2 */
 308		bool cmd_param_busy:1;	/* Bit 3 */
 309		bool adapter_ready:1;	/* Bit 4 */
 310		bool init_reqd:1;	/* Bit 5 */
 311		bool diag_failed:1;	/* Bit 6 */
 312		bool diag_active:1;	/* Bit 7 */
 313	} sr;
 314};
 315
 316/*
 317  Define the structure of the read-only Interrupt Register.
 318*/
 319
 320union blogic_int_reg {
 321	unsigned char all;
 322	struct {
 323		bool mailin_loaded:1;	/* Bit 0 */
 324		bool mailout_avail:1;	/* Bit 1 */
 325		bool cmd_complete:1;	/* Bit 2 */
 326		bool ext_busreset:1;	/* Bit 3 */
 327		unsigned char rsvd:3;	/* Bits 4-6 */
 328		bool int_valid:1;	/* Bit 7 */
 329	} ir;
 330};
 331
 332/*
 333  Define the structure of the read-only Geometry Register.
 334*/
 335
 336union blogic_geo_reg {
 337	unsigned char all;
 338	struct {
 339		enum blogic_bios_diskgeometry d0_geo:2;	/* Bits 0-1 */
 340		enum blogic_bios_diskgeometry d1_geo:2;	/* Bits 2-3 */
 341		unsigned char:3;	/* Bits 4-6 */
 342		bool ext_trans_enable:1;	/* Bit 7 */
 343	} gr;
 344};
 345
 346/*
 347  Define the BusLogic SCSI Host Adapter Command Register Operation Codes.
 348*/
 349
 350enum blogic_opcode {
 351	BLOGIC_TEST_CMP_COMPLETE = 0x00,
 352	BLOGIC_INIT_MBOX = 0x01,
 353	BLOGIC_EXEC_MBOX_CMD = 0x02,
 354	BLOGIC_EXEC_BIOS_CMD = 0x03,
 355	BLOGIC_GET_BOARD_ID = 0x04,
 356	BLOGIC_ENABLE_OUTBOX_AVAIL_INT = 0x05,
 357	BLOGIC_SET_SELECT_TIMEOUT = 0x06,
 358	BLOGIC_SET_PREEMPT_TIME = 0x07,
 359	BLOGIC_SET_TIMEOFF_BUS = 0x08,
 360	BLOGIC_SET_TXRATE = 0x09,
 361	BLOGIC_INQ_DEV0TO7 = 0x0A,
 362	BLOGIC_INQ_CONFIG = 0x0B,
 363	BLOGIC_TGT_MODE = 0x0C,
 364	BLOGIC_INQ_SETUPINFO = 0x0D,
 365	BLOGIC_WRITE_LOCALRAM = 0x1A,
 366	BLOGIC_READ_LOCALRAM = 0x1B,
 367	BLOGIC_WRITE_BUSMASTER_FIFO = 0x1C,
 368	BLOGIC_READ_BUSMASTER_FIFO = 0x1D,
 369	BLOGIC_ECHO_CMDDATA = 0x1F,
 370	BLOGIC_ADAPTER_DIAG = 0x20,
 371	BLOGIC_SET_OPTIONS = 0x21,
 372	BLOGIC_INQ_DEV8TO15 = 0x23,
 373	BLOGIC_INQ_DEV = 0x24,
 374	BLOGIC_DISABLE_INT = 0x25,
 375	BLOGIC_INIT_EXT_MBOX = 0x81,
 376	BLOGIC_EXEC_SCS_CMD = 0x83,
 377	BLOGIC_INQ_FWVER_D3 = 0x84,
 378	BLOGIC_INQ_FWVER_LETTER = 0x85,
 379	BLOGIC_INQ_PCI_INFO = 0x86,
 380	BLOGIC_INQ_MODELNO = 0x8B,
 381	BLOGIC_INQ_SYNC_PERIOD = 0x8C,
 382	BLOGIC_INQ_EXTSETUP = 0x8D,
 383	BLOGIC_STRICT_RR = 0x8F,
 384	BLOGIC_STORE_LOCALRAM = 0x90,
 385	BLOGIC_FETCH_LOCALRAM = 0x91,
 386	BLOGIC_STORE_TO_EEPROM = 0x92,
 387	BLOGIC_LOAD_AUTOSCSICODE = 0x94,
 388	BLOGIC_MOD_IOADDR = 0x95,
 389	BLOGIC_SETCCB_FMT = 0x96,
 390	BLOGIC_WRITE_INQBUF = 0x9A,
 391	BLOGIC_READ_INQBUF = 0x9B,
 392	BLOGIC_FLASH_LOAD = 0xA7,
 393	BLOGIC_READ_SCAMDATA = 0xA8,
 394	BLOGIC_WRITE_SCAMDATA = 0xA9
 395};
 396
 397/*
 398  Define the Inquire Board ID reply structure.
 399*/
 400
 401struct blogic_board_id {
 402	unsigned char type;		/* Byte 0 */
 403	unsigned char custom_features;	/* Byte 1 */
 404	unsigned char fw_ver_digit1;	/* Byte 2 */
 405	unsigned char fw_ver_digit2;	/* Byte 3 */
 406};
 407
 408/*
 409  Define the Inquire Configuration reply structure.
 410*/
 411
 412struct blogic_config {
 413	unsigned char:5;	/* Byte 0 Bits 0-4 */
 414	bool dma_ch5:1;		/* Byte 0 Bit 5 */
 415	bool dma_ch6:1;		/* Byte 0 Bit 6 */
 416	bool dma_ch7:1;		/* Byte 0 Bit 7 */
 417	bool irq_ch9:1;		/* Byte 1 Bit 0 */
 418	bool irq_ch10:1;	/* Byte 1 Bit 1 */
 419	bool irq_ch11:1;	/* Byte 1 Bit 2 */
 420	bool irq_ch12:1;	/* Byte 1 Bit 3 */
 421	unsigned char:1;	/* Byte 1 Bit 4 */
 422	bool irq_ch14:1;	/* Byte 1 Bit 5 */
 423	bool irq_ch15:1;	/* Byte 1 Bit 6 */
 424	unsigned char:1;	/* Byte 1 Bit 7 */
 425	unsigned char id:4;	/* Byte 2 Bits 0-3 */
 426	unsigned char:4;	/* Byte 2 Bits 4-7 */
 427};
 428
 429/*
 430  Define the Inquire Setup Information reply structure.
 431*/
 432
 433struct blogic_syncval {
 434	unsigned char offset:4;		/* Bits 0-3 */
 435	unsigned char tx_period:3;	/* Bits 4-6 */
 436	bool sync:1;			/* Bit 7 */
 437};
 438
 439struct blogic_setup_info {
 440	bool sync:1;				/* Byte 0 Bit 0 */
 441	bool parity:1;				/* Byte 0 Bit 1 */
 442	unsigned char:6;			/* Byte 0 Bits 2-7 */
 443	unsigned char tx_rate;			/* Byte 1 */
 444	unsigned char preempt_time;		/* Byte 2 */
 445	unsigned char timeoff_bus;		/* Byte 3 */
 446	unsigned char mbox_count;		/* Byte 4 */
 447	unsigned char mbox_addr[3];		/* Bytes 5-7 */
 448	struct blogic_syncval sync0to7[8];	/* Bytes 8-15 */
 449	unsigned char disconnect_ok0to7;	/* Byte 16 */
 450	unsigned char sig;			/* Byte 17 */
 451	unsigned char char_d;			/* Byte 18 */
 452	unsigned char bus_type;			/* Byte 19 */
 453	unsigned char wide_tx_ok0to7;		/* Byte 20 */
 454	unsigned char wide_tx_active0to7;	/* Byte 21 */
 455	struct blogic_syncval sync8to15[8];	/* Bytes 22-29 */
 456	unsigned char disconnect_ok8to15;	/* Byte 30 */
 457	unsigned char:8;			/* Byte 31 */
 458	unsigned char wide_tx_ok8to15;		/* Byte 32 */
 459	unsigned char wide_tx_active8to15;	/* Byte 33 */
 460};
 461
 462/*
 463  Define the Initialize Extended Mailbox request structure.
 464*/
 465
 466struct blogic_extmbox_req {
 467	unsigned char mbox_count;	/* Byte 0 */
 468	u32 base_mbox_addr;		/* Bytes 1-4 */
 469} PACKED;
 470
 471
 472/*
 473  Define the Inquire PCI Host Adapter Information reply type.  The ISA
 474  Compatible I/O Port values are defined here and are also used with
 475  the Modify I/O Address command.
 476*/
 477
 478enum blogic_isa_ioport {
 479	BLOGIC_IO_330 = 0,
 480	BLOGIC_IO_334 = 1,
 481	BLOGIC_IO_230 = 2,
 482	BLOGIC_IO_234 = 3,
 483	BLOGIC_IO_130 = 4,
 484	BLOGIC_IO_134 = 5,
 485	BLOGIC_IO_DISABLE = 6,
 486	BLOGIC_IO_DISABLE2 = 7
 487} PACKED;
 488
 489struct blogic_adapter_info {
 490	enum blogic_isa_ioport isa_port;	/* Byte 0 */
 491	unsigned char irq_ch;		/* Byte 1 */
 492	bool low_term:1;		/* Byte 2 Bit 0 */
 493	bool high_term:1;		/* Byte 2 Bit 1 */
 494	unsigned char:2;		/* Byte 2 Bits 2-3 */
 495	bool JP1:1;			/* Byte 2 Bit 4 */
 496	bool JP2:1;			/* Byte 2 Bit 5 */
 497	bool JP3:1;			/* Byte 2 Bit 6 */
 498	bool genericinfo_valid:1;	/* Byte 2 Bit 7 */
 499	unsigned char:8;		/* Byte 3 */
 500};
 501
 502/*
 503  Define the Inquire Extended Setup Information reply structure.
 504*/
 505
 506struct blogic_ext_setup {
 507	unsigned char bus_type;		/* Byte 0 */
 508	unsigned char bios_addr;	/* Byte 1 */
 509	unsigned short sg_limit;	/* Bytes 2-3 */
 510	unsigned char mbox_count;	/* Byte 4 */
 511	u32 base_mbox_addr;		/* Bytes 5-8 */
 512	struct {
 513		unsigned char:2;	/* Byte 9 Bits 0-1 */
 514		bool fast_on_eisa:1;	/* Byte 9 Bit 2 */
 515		unsigned char:3;	/* Byte 9 Bits 3-5 */
 516		bool level_int:1;	/* Byte 9 Bit 6 */
 517		unsigned char:1;	/* Byte 9 Bit 7 */
 518	} misc;
 519	unsigned char fw_rev[3];	/* Bytes 10-12 */
 520	bool wide:1;			/* Byte 13 Bit 0 */
 521	bool differential:1;		/* Byte 13 Bit 1 */
 522	bool scam:1;			/* Byte 13 Bit 2 */
 523	bool ultra:1;			/* Byte 13 Bit 3 */
 524	bool smart_term:1;		/* Byte 13 Bit 4 */
 525	unsigned char:3;		/* Byte 13 Bits 5-7 */
 526} PACKED;
 527
 528/*
 529  Define the Enable Strict Round Robin Mode request type.
 530*/
 531
 532enum blogic_rr_req {
 533	BLOGIC_AGGRESSIVE_RR = 0,
 534	BLOGIC_STRICT_RR_MODE = 1
 535} PACKED;
 536
 537
 538/*
 539  Define the Fetch Host Adapter Local RAM request type.
 540*/
 541
 542#define BLOGIC_BIOS_BASE		0
 543#define BLOGIC_AUTOSCSI_BASE		64
 544
 545struct blogic_fetch_localram {
 546	unsigned char offset;	/* Byte 0 */
 547	unsigned char count;	/* Byte 1 */
 548};
 549
 550/*
 551  Define the Host Adapter Local RAM AutoSCSI structure.
 552*/
 553
 554struct blogic_autoscsi {
 555	unsigned char factory_sig[2];		/* Bytes 0-1 */
 556	unsigned char info_bytes;		/* Byte 2 */
 557	unsigned char adapter_type[6];		/* Bytes 3-8 */
 558	unsigned char:8;			/* Byte 9 */
 559	bool floppy:1;				/* Byte 10 Bit 0 */
 560	bool floppy_sec:1;			/* Byte 10 Bit 1 */
 561	bool level_int:1;			/* Byte 10 Bit 2 */
 562	unsigned char:2;			/* Byte 10 Bits 3-4 */
 563	unsigned char systemram_bios:3;		/* Byte 10 Bits 5-7 */
 564	unsigned char dma_ch:7;			/* Byte 11 Bits 0-6 */
 565	bool dma_autoconf:1;			/* Byte 11 Bit 7 */
 566	unsigned char irq_ch:7;			/* Byte 12 Bits 0-6 */
 567	bool irq_autoconf:1;			/* Byte 12 Bit 7 */
 568	unsigned char dma_tx_rate;		/* Byte 13 */
 569	unsigned char scsi_id;			/* Byte 14 */
 570	bool low_term:1;			/* Byte 15 Bit 0 */
 571	bool parity:1;				/* Byte 15 Bit 1 */
 572	bool high_term:1;			/* Byte 15 Bit 2 */
 573	bool noisy_cable:1;			/* Byte 15 Bit 3 */
 574	bool fast_sync_neg:1;			/* Byte 15 Bit 4 */
 575	bool reset_enabled:1;			/* Byte 15 Bit 5 */
 576	bool:1;					/* Byte 15 Bit 6 */
 577	bool active_negation:1;			/* Byte 15 Bit 7 */
 578	unsigned char bus_on_delay;		/* Byte 16 */
 579	unsigned char bus_off_delay;		/* Byte 17 */
 580	bool bios_enabled:1;			/* Byte 18 Bit 0 */
 581	bool int19_redir_enabled:1;		/* Byte 18 Bit 1 */
 582	bool ext_trans_enable:1;		/* Byte 18 Bit 2 */
 583	bool removable_as_fixed:1;		/* Byte 18 Bit 3 */
 584	bool:1;					/* Byte 18 Bit 4 */
 585	bool morethan2_drives:1;		/* Byte 18 Bit 5 */
 586	bool bios_int:1;			/* Byte 18 Bit 6 */
 587	bool floptical:1;			/* Byte 19 Bit 7 */
 588	unsigned short dev_enabled;		/* Bytes 19-20 */
 589	unsigned short wide_ok;			/* Bytes 21-22 */
 590	unsigned short fast_ok;			/* Bytes 23-24 */
 591	unsigned short sync_ok;			/* Bytes 25-26 */
 592	unsigned short discon_ok;		/* Bytes 27-28 */
 593	unsigned short send_start_unit;		/* Bytes 29-30 */
 594	unsigned short ignore_bios_scan;	/* Bytes 31-32 */
 595	unsigned char pci_int_pin:2;		/* Byte 33 Bits 0-1 */
 596	unsigned char adapter_ioport:2;		/* Byte 33 Bits 2-3 */
 597	bool strict_rr_enabled:1;		/* Byte 33 Bit 4 */
 598	bool vesabus_33mhzplus:1;		/* Byte 33 Bit 5 */
 599	bool vesa_burst_write:1;		/* Byte 33 Bit 6 */
 600	bool vesa_burst_read:1;			/* Byte 33 Bit 7 */
 601	unsigned short ultra_ok;		/* Bytes 34-35 */
 602	unsigned int:32;			/* Bytes 36-39 */
 603	unsigned char:8;			/* Byte 40 */
 604	unsigned char autoscsi_maxlun;		/* Byte 41 */
 605	bool:1;					/* Byte 42 Bit 0 */
 606	bool scam_dominant:1;			/* Byte 42 Bit 1 */
 607	bool scam_enabled:1;			/* Byte 42 Bit 2 */
 608	bool scam_lev2:1;			/* Byte 42 Bit 3 */
 609	unsigned char:4;			/* Byte 42 Bits 4-7 */
 610	bool int13_exten:1;			/* Byte 43 Bit 0 */
 611	bool:1;					/* Byte 43 Bit 1 */
 612	bool cd_boot:1;				/* Byte 43 Bit 2 */
 613	unsigned char:5;			/* Byte 43 Bits 3-7 */
 614	unsigned char boot_id:4;		/* Byte 44 Bits 0-3 */
 615	unsigned char boot_ch:4;		/* Byte 44 Bits 4-7 */
 616	unsigned char force_scan_order:1;	/* Byte 45 Bit 0 */
 617	unsigned char:7;			/* Byte 45 Bits 1-7 */
 618	unsigned short nontagged_to_alt_ok;	/* Bytes 46-47 */
 619	unsigned short reneg_sync_on_check;	/* Bytes 48-49 */
 620	unsigned char rsvd[10];			/* Bytes 50-59 */
 621	unsigned char manuf_diag[2];		/* Bytes 60-61 */
 622	unsigned short cksum;			/* Bytes 62-63 */
 623} PACKED;
 624
 625/*
 626  Define the Host Adapter Local RAM Auto SCSI Byte 45 structure.
 627*/
 628
 629struct blogic_autoscsi_byte45 {
 630	unsigned char force_scan_order:1;	/* Bit 0 */
 631	unsigned char:7;	/* Bits 1-7 */
 632};
 633
 634/*
 635  Define the Host Adapter Local RAM BIOS Drive Map Byte structure.
 636*/
 637
 638#define BLOGIC_BIOS_DRVMAP		17
 639
 640struct blogic_bios_drvmap {
 641	unsigned char tgt_idbit3:1;			/* Bit 0 */
 642	unsigned char:2;				/* Bits 1-2 */
 643	enum blogic_bios_diskgeometry diskgeom:2;	/* Bits 3-4 */
 644	unsigned char tgt_id:3;				/* Bits 5-7 */
 645};
 646
 647/*
 648  Define the Set CCB Format request type.  Extended LUN Format CCBs are
 649  necessary to support more than 8 Logical Units per Target Device.
 650*/
 651
 652enum blogic_setccb_fmt {
 653	BLOGIC_LEGACY_LUN_CCB = 0,
 654	BLOGIC_EXT_LUN_CCB = 1
 655} PACKED;
 656
 657/*
 658  Define the Outgoing Mailbox Action Codes.
 659*/
 660
 661enum blogic_action {
 662	BLOGIC_OUTBOX_FREE = 0x00,
 663	BLOGIC_MBOX_START = 0x01,
 664	BLOGIC_MBOX_ABORT = 0x02
 665} PACKED;
 666
 667
 668/*
 669  Define the Incoming Mailbox Completion Codes.  The MultiMaster Firmware
 670  only uses codes 0 - 4.  The FlashPoint SCCB Manager has no mailboxes, so
 671  completion codes are stored in the CCB; it only uses codes 1, 2, 4, and 5.
 672*/
 673
 674enum blogic_cmplt_code {
 675	BLOGIC_INBOX_FREE = 0x00,
 676	BLOGIC_CMD_COMPLETE_GOOD = 0x01,
 677	BLOGIC_CMD_ABORT_BY_HOST = 0x02,
 678	BLOGIC_CMD_NOTFOUND = 0x03,
 679	BLOGIC_CMD_COMPLETE_ERROR = 0x04,
 680	BLOGIC_INVALID_CCB = 0x05
 681} PACKED;
 682
 683/*
 684  Define the Command Control Block (CCB) Opcodes.
 685*/
 686
 687enum blogic_ccb_opcode {
 688	BLOGIC_INITIATOR_CCB = 0x00,
 689	BLOGIC_TGT_CCB = 0x01,
 690	BLOGIC_INITIATOR_CCB_SG = 0x02,
 691	BLOGIC_INITIATOR_CCBB_RESIDUAL = 0x03,
 692	BLOGIC_INITIATOR_CCB_SG_RESIDUAL = 0x04,
 693	BLOGIC_BDR = 0x81
 694} PACKED;
 695
 696
 697/*
 698  Define the CCB Data Direction Codes.
 699*/
 700
 701enum blogic_datadir {
 702	BLOGIC_UNCHECKED_TX = 0,
 703	BLOGIC_DATAIN_CHECKED = 1,
 704	BLOGIC_DATAOUT_CHECKED = 2,
 705	BLOGIC_NOTX = 3
 706};
 707
 708
 709/*
 710  Define the Host Adapter Status Codes.  The MultiMaster Firmware does not
 711  return status code 0x0C; it uses 0x12 for both overruns and underruns.
 712*/
 713
 714enum blogic_adapter_status {
 715	BLOGIC_CMD_CMPLT_NORMAL = 0x00,
 716	BLOGIC_LINK_CMD_CMPLT = 0x0A,
 717	BLOGIC_LINK_CMD_CMPLT_FLAG = 0x0B,
 718	BLOGIC_DATA_UNDERRUN = 0x0C,
 719	BLOGIC_SELECT_TIMEOUT = 0x11,
 720	BLOGIC_DATA_OVERRUN = 0x12,
 721	BLOGIC_NOEXPECT_BUSFREE = 0x13,
 722	BLOGIC_INVALID_BUSPHASE = 0x14,
 723	BLOGIC_INVALID_OUTBOX_CODE = 0x15,
 724	BLOGIC_INVALID_CMD_CODE = 0x16,
 725	BLOGIC_LINKCCB_BADLUN = 0x17,
 726	BLOGIC_BAD_CMD_PARAM = 0x1A,
 727	BLOGIC_AUTOREQSENSE_FAIL = 0x1B,
 728	BLOGIC_TAGQUEUE_REJECT = 0x1C,
 729	BLOGIC_BAD_MSG_RCVD = 0x1D,
 730	BLOGIC_HW_FAIL = 0x20,
 731	BLOGIC_NORESPONSE_TO_ATN = 0x21,
 732	BLOGIC_HW_RESET = 0x22,
 733	BLOGIC_RST_FROM_OTHERDEV = 0x23,
 734	BLOGIC_BAD_RECONNECT = 0x24,
 735	BLOGIC_HW_BDR = 0x25,
 736	BLOGIC_ABRT_QUEUE = 0x26,
 737	BLOGIC_ADAPTER_SW_ERROR = 0x27,
 738	BLOGIC_HW_TIMEOUT = 0x30,
 739	BLOGIC_PARITY_ERR = 0x34
 740} PACKED;
 741
 742
 743/*
 744  Define the SCSI Target Device Status Codes.
 745*/
 746
 747enum blogic_tgt_status {
 748	BLOGIC_OP_GOOD = 0x00,
 749	BLOGIC_CHECKCONDITION = 0x02,
 750	BLOGIC_DEVBUSY = 0x08
 751} PACKED;
 752
 753/*
 754  Define the Queue Tag Codes.
 755*/
 756
 757enum blogic_queuetag {
 758	BLOGIC_SIMPLETAG = 0,
 759	BLOGIC_HEADTAG = 1,
 760	BLOGIC_ORDEREDTAG = 2,
 761	BLOGIC_RSVDTAG = 3
 762};
 763
 764/*
 765  Define the SCSI Command Descriptor Block (CDB).
 766*/
 767
 768#define BLOGIC_CDB_MAXLEN			12
 
 
 769
 770
 771/*
 772  Define the Scatter/Gather Segment structure required by the MultiMaster
 773  Firmware Interface and the FlashPoint SCCB Manager.
 774*/
 775
 776struct blogic_sg_seg {
 777	u32 segbytes;	/* Bytes 0-3 */
 778	u32 segdata;	/* Bytes 4-7 */
 779};
 780
 781/*
 782  Define the Driver CCB Status Codes.
 783*/
 784
 785enum blogic_ccb_status {
 786	BLOGIC_CCB_FREE = 0,
 787	BLOGIC_CCB_ACTIVE = 1,
 788	BLOGIC_CCB_COMPLETE = 2,
 789	BLOGIC_CCB_RESET = 3
 790} PACKED;
 791
 792
 793/*
 794  Define the 32 Bit Mode Command Control Block (CCB) structure.  The first 40
 795  bytes are defined by and common to both the MultiMaster Firmware and the
 796  FlashPoint SCCB Manager.  The next 60 bytes are defined by the FlashPoint
 797  SCCB Manager.  The remaining components are defined by the Linux BusLogic
 798  Driver.  Extended LUN Format CCBs differ from Legacy LUN Format 32 Bit Mode
 799  CCBs only in having the TagEnable and QueueTag fields moved from byte 17 to
 800  byte 1, and the Logical Unit field in byte 17 expanded to 6 bits.  In theory,
 801  Extended LUN Format CCBs can support up to 64 Logical Units, but in practice
 802  many devices will respond improperly to Logical Units between 32 and 63, and
 803  the SCSI-2 specification defines Bit 5 as LUNTAR.  Extended LUN Format CCBs
 804  are used by recent versions of the MultiMaster Firmware, as well as by the
 805  FlashPoint SCCB Manager; the FlashPoint SCCB Manager only supports 32 Logical
 806  Units.  Since 64 Logical Units are unlikely to be needed in practice, and
 807  since they are problematic for the above reasons, and since limiting them to
 808  5 bits simplifies the CCB structure definition, this driver only supports
 809  32 Logical Units per Target Device.
 810*/
 811
 812struct blogic_ccb {
 813	/*
 814	   MultiMaster Firmware and FlashPoint SCCB Manager Common Portion.
 815	 */
 816	enum blogic_ccb_opcode opcode;			/* Byte 0 */
 817	unsigned char:3;				/* Byte 1 Bits 0-2 */
 818	enum blogic_datadir datadir:2;			/* Byte 1 Bits 3-4 */
 819	bool tag_enable:1;				/* Byte 1 Bit 5 */
 820	enum blogic_queuetag queuetag:2;		/* Byte 1 Bits 6-7 */
 821	unsigned char cdblen;				/* Byte 2 */
 822	unsigned char sense_datalen;			/* Byte 3 */
 823	u32 datalen;					/* Bytes 4-7 */
 824	void *data;					/* Bytes 8-11 */
 825	unsigned char:8;				/* Byte 12 */
 826	unsigned char:8;				/* Byte 13 */
 827	enum blogic_adapter_status adapter_status;	/* Byte 14 */
 828	enum blogic_tgt_status tgt_status;		/* Byte 15 */
 829	unsigned char tgt_id;				/* Byte 16 */
 830	unsigned char lun:5;				/* Byte 17 Bits 0-4 */
 831	bool legacytag_enable:1;			/* Byte 17 Bit 5 */
 832	enum blogic_queuetag legacy_tag:2;		/* Byte 17 Bits 6-7 */
 833	unsigned char cdb[BLOGIC_CDB_MAXLEN];		/* Bytes 18-29 */
 834	unsigned char:8;				/* Byte 30 */
 835	unsigned char:8;				/* Byte 31 */
 836	u32 rsvd_int;					/* Bytes 32-35 */
 837	u32 sensedata;					/* Bytes 36-39 */
 838	/*
 839	   FlashPoint SCCB Manager Defined Portion.
 840	 */
 841	void (*callback) (struct blogic_ccb *);		/* Bytes 40-43 */
 842	u32 base_addr;					/* Bytes 44-47 */
 843	enum blogic_cmplt_code comp_code;		/* Byte 48 */
 844#ifdef CONFIG_SCSI_FLASHPOINT
 845	unsigned char:8;				/* Byte 49 */
 846	u16 os_flags;					/* Bytes 50-51 */
 847	unsigned char private[24];			/* Bytes 52-99 */
 848	void *rsvd1;
 849	void *rsvd2;
 850	unsigned char private2[16];
 851#endif
 852	/*
 853	   BusLogic Linux Driver Defined Portion.
 854	 */
 855	dma_addr_t allocgrp_head;
 856	unsigned int allocgrp_size;
 857	u32 dma_handle;
 858	enum blogic_ccb_status status;
 859	unsigned long serial;
 860	struct scsi_cmnd *command;
 861	struct blogic_adapter *adapter;
 862	struct blogic_ccb *next;
 863	struct blogic_ccb *next_all;
 864	struct blogic_sg_seg sglist[BLOGIC_SG_LIMIT];
 
 865};
 866
 867/*
 868  Define the 32 Bit Mode Outgoing Mailbox structure.
 869*/
 870
 871struct blogic_outbox {
 872	u32 ccb;			/* Bytes 0-3 */
 873	u32:24;				/* Bytes 4-6 */
 874	enum blogic_action action;	/* Byte 7 */
 875};
 876
 877/*
 878  Define the 32 Bit Mode Incoming Mailbox structure.
 879*/
 880
 881struct blogic_inbox {
 882	u32 ccb;					/* Bytes 0-3 */
 883	enum blogic_adapter_status adapter_status;	/* Byte 4 */
 884	enum blogic_tgt_status tgt_status;		/* Byte 5 */
 885	unsigned char:8;				/* Byte 6 */
 886	enum blogic_cmplt_code comp_code;		/* Byte 7 */
 887};
 888
 889
 890/*
 891  Define the BusLogic Driver Options structure.
 892*/
 893
 894struct blogic_drvr_options {
 895	unsigned short tagq_ok;
 896	unsigned short tagq_ok_mask;
 897	unsigned short bus_settle_time;
 898	unsigned short stop_tgt_inquiry;
 899	unsigned char common_qdepth;
 900	unsigned char qdepth[BLOGIC_MAXDEV];
 901};
 902
 903/*
 904  Define the Host Adapter Target Flags structure.
 905*/
 906
 907struct blogic_tgt_flags {
 908	bool tgt_exists:1;
 909	bool tagq_ok:1;
 910	bool wide_ok:1;
 911	bool tagq_active:1;
 912	bool wide_active:1;
 913	bool cmd_good:1;
 914	bool tgt_info_in:1;
 915};
 916
 917/*
 918  Define the Host Adapter Target Statistics structure.
 919*/
 920
 921#define BLOGIC_SZ_BUCKETS			10
 922
 923struct blogic_tgt_stats {
 924	unsigned int cmds_tried;
 925	unsigned int cmds_complete;
 926	unsigned int read_cmds;
 927	unsigned int write_cmds;
 928	struct blogic_byte_count bytesread;
 929	struct blogic_byte_count byteswritten;
 930	unsigned int read_sz_buckets[BLOGIC_SZ_BUCKETS];
 931	unsigned int write_sz_buckets[BLOGIC_SZ_BUCKETS];
 932	unsigned short aborts_request;
 933	unsigned short aborts_tried;
 934	unsigned short aborts_done;
 935	unsigned short bdr_request;
 936	unsigned short bdr_tried;
 937	unsigned short bdr_done;
 938	unsigned short adatper_reset_req;
 939	unsigned short adapter_reset_attempt;
 940	unsigned short adapter_reset_done;
 
 
 941};
 942
 943/*
 944  Define the FlashPoint Card Handle data type.
 945*/
 946
 947#define FPOINT_BADCARD_HANDLE		0xFFFFFFFFL
 
 
 948
 949
 950/*
 951  Define the FlashPoint Information structure.  This structure is defined
 952  by the FlashPoint SCCB Manager.
 953*/
 954
 955struct fpoint_info {
 956	u32 base_addr;				/* Bytes 0-3 */
 957	bool present;				/* Byte 4 */
 958	unsigned char irq_ch;			/* Byte 5 */
 959	unsigned char scsi_id;			/* Byte 6 */
 960	unsigned char scsi_lun;			/* Byte 7 */
 961	u16 fw_rev;				/* Bytes 8-9 */
 962	u16 sync_ok;				/* Bytes 10-11 */
 963	u16 fast_ok;				/* Bytes 12-13 */
 964	u16 ultra_ok;				/* Bytes 14-15 */
 965	u16 discon_ok;				/* Bytes 16-17 */
 966	u16 wide_ok;				/* Bytes 18-19 */
 967	bool parity:1;				/* Byte 20 Bit 0 */
 968	bool wide:1;				/* Byte 20 Bit 1 */
 969	bool softreset:1;			/* Byte 20 Bit 2 */
 970	bool ext_trans_enable:1;		/* Byte 20 Bit 3 */
 971	bool low_term:1;			/* Byte 20 Bit 4 */
 972	bool high_term:1;			/* Byte 20 Bit 5 */
 973	bool report_underrun:1;			/* Byte 20 Bit 6 */
 974	bool scam_enabled:1;			/* Byte 20 Bit 7 */
 975	bool scam_lev2:1;			/* Byte 21 Bit 0 */
 976	unsigned char:7;			/* Byte 21 Bits 1-7 */
 977	unsigned char family;			/* Byte 22 */
 978	unsigned char bus_type;			/* Byte 23 */
 979	unsigned char model[3];			/* Bytes 24-26 */
 980	unsigned char relative_cardnum;		/* Byte 27 */
 981	unsigned char rsvd[4];			/* Bytes 28-31 */
 982	u32 os_rsvd;				/* Bytes 32-35 */
 983	unsigned char translation_info[4];	/* Bytes 36-39 */
 984	u32 rsvd2[5];				/* Bytes 40-59 */
 985	u32 sec_range;				/* Bytes 60-63 */
 986};
 987
 988/*
 989  Define the BusLogic Driver Host Adapter structure.
 990*/
 991
 992struct blogic_adapter {
 993	struct Scsi_Host *scsi_host;
 994	struct pci_dev *pci_device;
 995	enum blogic_adapter_type adapter_type;
 996	enum blogic_adapter_bus_type adapter_bus_type;
 997	unsigned long io_addr;
 998	unsigned long pci_addr;
 999	unsigned short addr_count;
1000	unsigned char host_no;
1001	unsigned char model[9];
1002	unsigned char fw_ver[6];
1003	unsigned char full_model[18];
1004	unsigned char bus;
1005	unsigned char dev;
1006	unsigned char irq_ch;
1007	unsigned char dma_ch;
1008	unsigned char scsi_id;
1009	bool irq_acquired:1;
1010	bool dma_chan_acquired:1;
1011	bool ext_trans_enable:1;
1012	bool parity:1;
1013	bool reset_enabled:1;
1014	bool level_int:1;
1015	bool wide:1;
1016	bool differential:1;
1017	bool scam:1;
1018	bool ultra:1;
1019	bool ext_lun:1;
1020	bool terminfo_valid:1;
1021	bool low_term:1;
1022	bool high_term:1;
1023	bool need_bouncebuf:1;
1024	bool strict_rr:1;
1025	bool scam_enabled:1;
1026	bool scam_lev2:1;
1027	bool adapter_initd:1;
1028	bool adapter_extreset:1;
1029	bool adapter_intern_err:1;
1030	bool processing_ccbs;
1031	volatile bool adapter_cmd_complete;
1032	unsigned short adapter_sglimit;
1033	unsigned short drvr_sglimit;
1034	unsigned short maxdev;
1035	unsigned short maxlun;
1036	unsigned short mbox_count;
1037	unsigned short initccbs;
1038	unsigned short inc_ccbs;
1039	unsigned short alloc_ccbs;
1040	unsigned short drvr_qdepth;
1041	unsigned short adapter_qdepth;
1042	unsigned short untag_qdepth;
1043	unsigned short common_qdepth;
1044	unsigned short bus_settle_time;
1045	unsigned short sync_ok;
1046	unsigned short fast_ok;
1047	unsigned short ultra_ok;
1048	unsigned short wide_ok;
1049	unsigned short discon_ok;
1050	unsigned short tagq_ok;
1051	unsigned short ext_resets;
1052	unsigned short adapter_intern_errors;
1053	unsigned short tgt_count;
1054	unsigned short msgbuflen;
1055	u32 bios_addr;
1056	struct blogic_drvr_options *drvr_opts;
1057	struct fpoint_info fpinfo;
1058	void *cardhandle;
1059	struct list_head host_list;
1060	struct blogic_ccb *all_ccbs;
1061	struct blogic_ccb *free_ccbs;
1062	struct blogic_ccb *firstccb;
1063	struct blogic_ccb *lastccb;
1064	struct blogic_ccb *bdr_pend[BLOGIC_MAXDEV];
1065	struct blogic_tgt_flags tgt_flags[BLOGIC_MAXDEV];
1066	unsigned char qdepth[BLOGIC_MAXDEV];
1067	unsigned char sync_period[BLOGIC_MAXDEV];
1068	unsigned char sync_offset[BLOGIC_MAXDEV];
1069	unsigned char active_cmds[BLOGIC_MAXDEV];
1070	unsigned int cmds_since_rst[BLOGIC_MAXDEV];
1071	unsigned long last_seqpoint[BLOGIC_MAXDEV];
1072	unsigned long last_resettried[BLOGIC_MAXDEV];
1073	unsigned long last_resetdone[BLOGIC_MAXDEV];
1074	struct blogic_outbox *first_outbox;
1075	struct blogic_outbox *last_outbox;
1076	struct blogic_outbox *next_outbox;
1077	struct blogic_inbox *first_inbox;
1078	struct blogic_inbox *last_inbox;
1079	struct blogic_inbox *next_inbox;
1080	struct blogic_tgt_stats tgt_stats[BLOGIC_MAXDEV];
1081	unsigned char *mbox_space;
1082	dma_addr_t mbox_space_handle;
1083	unsigned int mbox_sz;
1084	unsigned long ccb_offset;
1085	char msgbuf[BLOGIC_MSGBUF_SIZE];
1086};
1087
1088/*
1089  Define a structure for the BIOS Disk Parameters.
1090*/
1091
1092struct bios_diskparam {
1093	int heads;
1094	int sectors;
1095	int cylinders;
1096};
1097
1098/*
1099  Define a structure for the SCSI Inquiry command results.
1100*/
1101
1102struct scsi_inquiry {
1103	unsigned char devtype:5;	/* Byte 0 Bits 0-4 */
1104	unsigned char dev_qual:3;	/* Byte 0 Bits 5-7 */
1105	unsigned char dev_modifier:7;	/* Byte 1 Bits 0-6 */
1106	bool rmb:1;			/* Byte 1 Bit 7 */
1107	unsigned char ansi_ver:3;	/* Byte 2 Bits 0-2 */
1108	unsigned char ecma_ver:3;	/* Byte 2 Bits 3-5 */
1109	unsigned char iso_ver:2;	/* Byte 2 Bits 6-7 */
1110	unsigned char resp_fmt:4;	/* Byte 3 Bits 0-3 */
1111	unsigned char:2;		/* Byte 3 Bits 4-5 */
1112	bool TrmIOP:1;			/* Byte 3 Bit 6 */
1113	bool AENC:1;			/* Byte 3 Bit 7 */
1114	unsigned char addl_len;		/* Byte 4 */
1115	unsigned char:8;		/* Byte 5 */
1116	unsigned char:8;		/* Byte 6 */
1117	bool SftRe:1;			/* Byte 7 Bit 0 */
1118	bool CmdQue:1;			/* Byte 7 Bit 1 */
1119	bool:1;				/* Byte 7 Bit 2 */
1120	bool linked:1;			/* Byte 7 Bit 3 */
1121	bool sync:1;			/* Byte 7 Bit 4 */
1122	bool WBus16:1;			/* Byte 7 Bit 5 */
1123	bool WBus32:1;			/* Byte 7 Bit 6 */
1124	bool RelAdr:1;			/* Byte 7 Bit 7 */
1125	unsigned char vendor[8];	/* Bytes 8-15 */
1126	unsigned char product[16];	/* Bytes 16-31 */
1127	unsigned char product_rev[4];	/* Bytes 32-35 */
1128};
1129
1130
1131/*
1132  Define functions to provide an abstraction for reading and writing the
1133  Host Adapter I/O Registers.
1134*/
1135
1136static inline void blogic_busreset(struct blogic_adapter *adapter)
1137{
1138	union blogic_cntrl_reg cr;
1139	cr.all = 0;
1140	cr.cr.bus_reset = true;
1141	outb(cr.all, adapter->io_addr + BLOGIC_CNTRL_REG);
1142}
1143
1144static inline void blogic_intreset(struct blogic_adapter *adapter)
1145{
1146	union blogic_cntrl_reg cr;
1147	cr.all = 0;
1148	cr.cr.int_reset = true;
1149	outb(cr.all, adapter->io_addr + BLOGIC_CNTRL_REG);
1150}
1151
1152static inline void blogic_softreset(struct blogic_adapter *adapter)
1153{
1154	union blogic_cntrl_reg cr;
1155	cr.all = 0;
1156	cr.cr.soft_reset = true;
1157	outb(cr.all, adapter->io_addr + BLOGIC_CNTRL_REG);
1158}
1159
1160static inline void blogic_hardreset(struct blogic_adapter *adapter)
1161{
1162	union blogic_cntrl_reg cr;
1163	cr.all = 0;
1164	cr.cr.hard_reset = true;
1165	outb(cr.all, adapter->io_addr + BLOGIC_CNTRL_REG);
1166}
1167
1168static inline unsigned char blogic_rdstatus(struct blogic_adapter *adapter)
1169{
1170	return inb(adapter->io_addr + BLOGIC_STATUS_REG);
1171}
1172
1173static inline void blogic_setcmdparam(struct blogic_adapter *adapter,
1174					unsigned char value)
1175{
1176	outb(value, adapter->io_addr + BLOGIC_CMD_PARM_REG);
1177}
1178
1179static inline unsigned char blogic_rddatain(struct blogic_adapter *adapter)
1180{
1181	return inb(adapter->io_addr + BLOGIC_DATAIN_REG);
1182}
1183
1184static inline unsigned char blogic_rdint(struct blogic_adapter *adapter)
1185{
1186	return inb(adapter->io_addr + BLOGIC_INT_REG);
1187}
1188
1189static inline unsigned char blogic_rdgeom(struct blogic_adapter *adapter)
1190{
1191	return inb(adapter->io_addr + BLOGIC_GEOMETRY_REG);
1192}
1193
1194/*
1195  blogic_execmbox issues an Execute Mailbox Command, which
1196  notifies the Host Adapter that an entry has been made in an Outgoing
1197  Mailbox.
1198*/
1199
1200static inline void blogic_execmbox(struct blogic_adapter *adapter)
1201{
1202	blogic_setcmdparam(adapter, BLOGIC_EXEC_MBOX_CMD);
1203}
1204
1205/*
1206  blogic_delay waits for Seconds to elapse.
1207*/
1208
1209static inline void blogic_delay(int seconds)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1210{
1211	mdelay(1000 * seconds);
1212}
1213
1214/*
1215  virt_to_32bit_virt maps between Kernel Virtual Addresses and
1216  32 bit Kernel Virtual Addresses.  This avoids compilation warnings
1217  on 64 bit architectures.
1218*/
1219
1220static inline u32 virt_to_32bit_virt(void *virt_addr)
1221{
1222	return (u32) (unsigned long) virt_addr;
1223}
1224
1225/*
1226  blogic_inc_count increments counter by 1, stopping at
1227  65535 rather than wrapping around to 0.
1228*/
1229
1230static inline void blogic_inc_count(unsigned short *count)
1231{
1232	if (*count < 65535)
1233		(*count)++;
1234}
1235
1236/*
1237  blogic_addcount increments Byte Counter by Amount.
1238*/
1239
1240static inline void blogic_addcount(struct blogic_byte_count *bytecount,
1241					unsigned int amount)
1242{
1243	bytecount->units += amount;
1244	if (bytecount->units > 999999999) {
1245		bytecount->units -= 1000000000;
1246		bytecount->billions++;
1247	}
1248}
1249
1250/*
1251  blogic_incszbucket increments the Bucket for Amount.
1252*/
1253
1254static inline void blogic_incszbucket(unsigned int *cmdsz_buckets,
1255					unsigned int amount)
1256{
1257	int index = 0;
1258	if (amount < 8 * 1024) {
1259		if (amount < 2 * 1024)
1260			index = (amount < 1 * 1024 ? 0 : 1);
1261		else
1262			index = (amount < 4 * 1024 ? 2 : 3);
1263	} else if (amount < 128 * 1024) {
1264		if (amount < 32 * 1024)
1265			index = (amount < 16 * 1024 ? 4 : 5);
1266		else
1267			index = (amount < 64 * 1024 ? 6 : 7);
1268	} else
1269		index = (amount < 256 * 1024 ? 8 : 9);
1270	cmdsz_buckets[index]++;
1271}
1272
1273/*
1274  Define the version number of the FlashPoint Firmware (SCCB Manager).
1275*/
1276
1277#define FLASHPOINT_FW_VER		"5.02"
1278
1279/*
1280  Define the possible return values from FlashPoint_HandleInterrupt.
1281*/
1282
1283#define FPOINT_NORMAL_INT		0x00
1284#define FPOINT_INTERN_ERR		0xFE
1285#define FPOINT_EXT_RESET		0xFF
1286
1287/*
1288  Define prototypes for the forward referenced BusLogic Driver
1289  Internal Functions.
1290*/
1291
1292static const char *blogic_drvr_info(struct Scsi_Host *);
1293static int blogic_qcmd(struct Scsi_Host *h, struct scsi_cmnd *);
1294static int blogic_diskparam(struct scsi_device *, struct block_device *, sector_t, int *);
1295static int blogic_slaveconfig(struct scsi_device *);
1296static void blogic_qcompleted_ccb(struct blogic_ccb *);
1297static irqreturn_t blogic_inthandler(int, void *);
1298static int blogic_resetadapter(struct blogic_adapter *, bool hard_reset);
1299static void blogic_msg(enum blogic_msglevel, char *, struct blogic_adapter *, ...);
1300static int __init blogic_setup(char *);
 
1301
1302#endif				/* _BUSLOGIC_H */