blob: 8349c0f1438af6bcbadfae7a44a3400d3b8a6a8b [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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
Linus Torvalds1da177e2005-04-16 15:20:36 -070031
32#ifndef PACKED
33#define PACKED __attribute__((packed))
34#endif
35
36/*
Linus Torvalds1da177e2005-04-16 15:20:36 -070037 Define the maximum number of BusLogic Host Adapters supported by this driver.
38*/
39
Khalid Aziz839cb992013-05-16 19:44:13 -060040#define BLOGIC_MAX_ADAPTERS 16
Linus Torvalds1da177e2005-04-16 15:20:36 -070041
42
43/*
44 Define the maximum number of Target Devices supported by this driver.
45*/
46
Khalid Aziz839cb992013-05-16 19:44:13 -060047#define BLOGIC_MAXDEV 16
Linus Torvalds1da177e2005-04-16 15:20:36 -070048
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
Khalid Aziz839cb992013-05-16 19:44:13 -060056#define BLOGIC_SG_LIMIT 128
Linus Torvalds1da177e2005-04-16 15:20:36 -070057
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
Khalid Aziz839cb992013-05-16 19:44:13 -060065#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
Linus Torvalds1da177e2005-04-16 15:20:36 -070071
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
Khalid Aziz839cb992013-05-16 19:44:13 -060080#define BLOGIC_BUS_SETTLE_TIME 2
Linus Torvalds1da177e2005-04-16 15:20:36 -070081
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
Khalid Aziz839cb992013-05-16 19:44:13 -060090#define BLOGIC_MAX_MAILBOX 211
Linus Torvalds1da177e2005-04-16 15:20:36 -070091
92
93/*
94 Define the number of CCBs that should be allocated as a group to optimize
95 Kernel memory allocation.
96*/
97
Khalid Aziz839cb992013-05-16 19:44:13 -060098#define BLOGIC_CCB_GRP_ALLOCSIZE 7
Linus Torvalds1da177e2005-04-16 15:20:36 -070099
100
101/*
102 Define the Host Adapter Line and Message Buffer Sizes.
103*/
104
Khalid Aziz839cb992013-05-16 19:44:13 -0600105#define BLOGIC_LINEBUF_SIZE 100
106#define BLOGIC_MSGBUF_SIZE 9700
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107
108
109/*
110 Define the Driver Message Levels.
111*/
112
Khalid Aziz839cb992013-05-16 19:44:13 -0600113enum 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
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119};
120
Khalid Aziz839cb992013-05-16 19:44:13 -0600121static char *blogic_msglevelmap[] = { KERN_NOTICE, KERN_NOTICE, KERN_NOTICE, KERN_WARNING, KERN_ERR };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122
123
124/*
125 Define Driver Message macros.
126*/
127
Khalid Aziz839cb992013-05-16 19:44:13 -0600128#define blogic_announce(format, args...) \
129 blogic_msg(BLOGIC_ANNOUNCE_LEVEL, format, ##args)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130
Khalid Aziz839cb992013-05-16 19:44:13 -0600131#define blogic_info(format, args...) \
132 blogic_msg(BLOGIC_INFO_LEVEL, format, ##args)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133
Khalid Aziz839cb992013-05-16 19:44:13 -0600134#define blogic_notice(format, args...) \
135 blogic_msg(BLOGIC_NOTICE_LEVEL, format, ##args)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136
Khalid Aziz839cb992013-05-16 19:44:13 -0600137#define blogic_warn(format, args...) \
138 blogic_msg(BLOGIC_WARN_LEVEL, format, ##args)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139
Khalid Aziz839cb992013-05-16 19:44:13 -0600140#define blogic_err(format, args...) \
141 blogic_msg(BLOGIC_ERR_LEVEL, format, ##args)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142
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
Khalid Aziz839cb992013-05-16 19:44:13 -0600149enum blogic_adapter_type {
150 BLOGIC_MULTIMASTER = 1,
151 BLOGIC_FLASHPOINT = 2
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152} PACKED;
153
Khalid Aziz839cb992013-05-16 19:44:13 -0600154#define BLOGIC_MULTIMASTER_ADDR_COUNT 4
155#define BLOGIC_FLASHPOINT_ADDR_COUNT 256
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156
Khalid Aziz839cb992013-05-16 19:44:13 -0600157static int blogic_adapter_addr_count[3] = { 0, BLOGIC_MULTIMASTER_ADDR_COUNT, BLOGIC_FLASHPOINT_ADDR_COUNT };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158
159
160/*
161 Define macros for testing the Host Adapter Type.
162*/
163
Matthew Wilcox78b4b052008-03-13 06:55:08 -0600164#ifdef CONFIG_SCSI_FLASHPOINT
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165
Khalid Aziz839cb992013-05-16 19:44:13 -0600166#define blogic_multimaster_type(adapter) \
167 (adapter->adapter_type == BLOGIC_MULTIMASTER)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168
Khalid Aziz839cb992013-05-16 19:44:13 -0600169#define blogic_flashpoint_type(adapter) \
170 (adapter->adapter_type == BLOGIC_FLASHPOINT)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171
172#else
173
Khalid Aziz839cb992013-05-16 19:44:13 -0600174#define blogic_multimaster_type(adapter) (true)
175#define blogic_flashpoint_type(adapter) (false)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176
177#endif
178
179
180/*
181 Define the possible Host Adapter Bus Types.
182*/
183
Khalid Aziz839cb992013-05-16 19:44:13 -0600184enum 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
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191} PACKED;
192
Khalid Aziz839cb992013-05-16 19:44:13 -0600193static char *blogic_adapter_busnames[] = { "Unknown", "ISA", "EISA", "PCI", "VESA", "MCA" };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194
Khalid Aziz839cb992013-05-16 19:44:13 -0600195static 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 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202};
203
204/*
205 Define the possible Host Adapter BIOS Disk Geometry Translations.
206*/
207
Khalid Aziz839cb992013-05-16 19:44:13 -0600208enum blogic_bios_diskgeometry {
209 BLOGIC_BIOS_NODISK = 0,
210 BLOGIC_BIOS_DISK64x32 = 1,
211 BLOGIC_BIOS_DISK128x32 = 2,
212 BLOGIC_BIOS_DISK255x63 = 3
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213} PACKED;
214
215
216/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217 Define a 10^18 Statistics Byte Counter data type.
218*/
219
Khalid Aziz839cb992013-05-16 19:44:13 -0600220struct blogic_byte_count {
221 unsigned int units;
222 unsigned int billions;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223};
224
225
226/*
227 Define the structure for I/O Address and Bus Probing Information.
228*/
229
Khalid Aziz839cb992013-05-16 19:44:13 -0600230struct 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;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239};
240
241/*
242 Define the Probe Options.
243*/
244
Khalid Aziz839cb992013-05-16 19:44:13 -0600245struct 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 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259};
260
261/*
262 Define the Global Options.
263*/
264
Khalid Aziz839cb992013-05-16 19:44:13 -0600265struct 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 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270};
271
272/*
273 Define the BusLogic SCSI Host Adapter I/O Register Offsets.
274*/
275
Khalid Aziz839cb992013-05-16 19:44:13 -0600276#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 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282
283/*
284 Define the structure of the write-only Control Register.
285*/
286
Khalid Aziz839cb992013-05-16 19:44:13 -0600287union blogic_cntrl_reg {
288 unsigned char all;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289 struct {
290 unsigned char:4; /* Bits 0-3 */
Khalid Aziz839cb992013-05-16 19:44:13 -0600291 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 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295 } cr;
296};
297
298/*
299 Define the structure of the read-only Status Register.
300*/
301
Khalid Aziz839cb992013-05-16 19:44:13 -0600302union blogic_stat_reg {
303 unsigned char all;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304 struct {
Khalid Aziz839cb992013-05-16 19:44:13 -0600305 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 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313 } sr;
314};
315
316/*
317 Define the structure of the read-only Interrupt Register.
318*/
319
Khalid Aziz839cb992013-05-16 19:44:13 -0600320union blogic_int_reg {
321 unsigned char all;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322 struct {
Khalid Aziz839cb992013-05-16 19:44:13 -0600323 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 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329 } ir;
330};
331
332/*
333 Define the structure of the read-only Geometry Register.
334*/
335
Khalid Aziz839cb992013-05-16 19:44:13 -0600336union blogic_geo_reg {
337 unsigned char all;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338 struct {
Khalid Aziz839cb992013-05-16 19:44:13 -0600339 enum blogic_bios_diskgeometry d0_geo:2; /* Bits 0-1 */
340 enum blogic_bios_diskgeometry d1_geo:2; /* Bits 2-3 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341 unsigned char:3; /* Bits 4-6 */
Khalid Aziz839cb992013-05-16 19:44:13 -0600342 bool ext_trans_enable:1; /* Bit 7 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343 } gr;
344};
345
346/*
347 Define the BusLogic SCSI Host Adapter Command Register Operation Codes.
348*/
349
Khalid Aziz839cb992013-05-16 19:44:13 -0600350enum 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
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395};
396
397/*
398 Define the Inquire Board ID reply structure.
399*/
400
Khalid Aziz839cb992013-05-16 19:44:13 -0600401struct 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 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406};
407
408/*
409 Define the Inquire Configuration reply structure.
410*/
411
Khalid Aziz839cb992013-05-16 19:44:13 -0600412struct blogic_config {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413 unsigned char:5; /* Byte 0 Bits 0-4 */
Khalid Aziz839cb992013-05-16 19:44:13 -0600414 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 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421 unsigned char:1; /* Byte 1 Bit 4 */
Khalid Aziz839cb992013-05-16 19:44:13 -0600422 bool irq_ch14:1; /* Byte 1 Bit 5 */
423 bool irq_ch15:1; /* Byte 1 Bit 6 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424 unsigned char:1; /* Byte 1 Bit 7 */
Khalid Aziz839cb992013-05-16 19:44:13 -0600425 unsigned char id:4; /* Byte 2 Bits 0-3 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426 unsigned char:4; /* Byte 2 Bits 4-7 */
427};
428
429/*
430 Define the Inquire Setup Information reply structure.
431*/
432
Khalid Aziz839cb992013-05-16 19:44:13 -0600433struct 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 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437};
438
Khalid Aziz839cb992013-05-16 19:44:13 -0600439struct 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 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460};
461
462/*
463 Define the Initialize Extended Mailbox request structure.
464*/
465
Khalid Aziz839cb992013-05-16 19:44:13 -0600466struct blogic_extmbox_req {
467 unsigned char mbox_count; /* Byte 0 */
468 u32 base_mbox_addr; /* Bytes 1-4 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469} 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
Khalid Aziz839cb992013-05-16 19:44:13 -0600478enum 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
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487} PACKED;
488
Khalid Aziz839cb992013-05-16 19:44:13 -0600489struct 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 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500};
501
502/*
503 Define the Inquire Extended Setup Information reply structure.
504*/
505
Khalid Aziz839cb992013-05-16 19:44:13 -0600506struct 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 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512 struct {
513 unsigned char:2; /* Byte 9 Bits 0-1 */
Khalid Aziz839cb992013-05-16 19:44:13 -0600514 bool fast_on_eisa:1; /* Byte 9 Bit 2 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515 unsigned char:3; /* Byte 9 Bits 3-5 */
Khalid Aziz839cb992013-05-16 19:44:13 -0600516 bool level_int:1; /* Byte 9 Bit 6 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517 unsigned char:1; /* Byte 9 Bit 7 */
Khalid Aziz839cb992013-05-16 19:44:13 -0600518 } 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 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526} PACKED;
527
528/*
529 Define the Enable Strict Round Robin Mode request type.
530*/
531
Khalid Aziz839cb992013-05-16 19:44:13 -0600532enum blogic_rr_req {
533 BLOGIC_AGGRESSIVE_RR = 0,
534 BLOGIC_STRICT_RR_MODE = 1
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535} PACKED;
536
537
538/*
539 Define the Fetch Host Adapter Local RAM request type.
540*/
541
Khalid Aziz839cb992013-05-16 19:44:13 -0600542#define BLOGIC_BIOS_BASE 0
543#define BLOGIC_AUTOSCSI_BASE 64
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544
Khalid Aziz839cb992013-05-16 19:44:13 -0600545struct blogic_fetch_localram {
546 unsigned char offset; /* Byte 0 */
547 unsigned char count; /* Byte 1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548};
549
550/*
551 Define the Host Adapter Local RAM AutoSCSI structure.
552*/
553
Khalid Aziz839cb992013-05-16 19:44:13 -0600554struct 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 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623} PACKED;
624
625/*
626 Define the Host Adapter Local RAM Auto SCSI Byte 45 structure.
627*/
628
Khalid Aziz839cb992013-05-16 19:44:13 -0600629struct blogic_autoscsi_byte45 {
630 unsigned char force_scan_order:1; /* Bit 0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631 unsigned char:7; /* Bits 1-7 */
632};
633
634/*
635 Define the Host Adapter Local RAM BIOS Drive Map Byte structure.
636*/
637
Khalid Aziz839cb992013-05-16 19:44:13 -0600638#define BLOGIC_BIOS_DRVMAP 17
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639
Khalid Aziz839cb992013-05-16 19:44:13 -0600640struct 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 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645};
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
Khalid Aziz839cb992013-05-16 19:44:13 -0600652enum blogic_setccb_fmt {
653 BLOGIC_LEGACY_LUN_CCB = 0,
654 BLOGIC_EXT_LUN_CCB = 1
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655} PACKED;
656
657/*
658 Define the Outgoing Mailbox Action Codes.
659*/
660
Khalid Aziz839cb992013-05-16 19:44:13 -0600661enum blogic_action {
662 BLOGIC_OUTBOX_FREE = 0x00,
663 BLOGIC_MBOX_START = 0x01,
664 BLOGIC_MBOX_ABORT = 0x02
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665} 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
Khalid Aziz839cb992013-05-16 19:44:13 -0600674enum 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
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681} PACKED;
682
683/*
684 Define the Command Control Block (CCB) Opcodes.
685*/
686
Khalid Aziz839cb992013-05-16 19:44:13 -0600687enum 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
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694} PACKED;
695
696
697/*
698 Define the CCB Data Direction Codes.
699*/
700
Khalid Aziz839cb992013-05-16 19:44:13 -0600701enum blogic_datadir {
702 BLOGIC_UNCHECKED_TX = 0,
703 BLOGIC_DATAIN_CHECKED = 1,
704 BLOGIC_DATAOUT_CHECKED = 2,
705 BLOGIC_NOTX = 3
Linus Torvalds1da177e2005-04-16 15:20:36 -0700706};
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
Khalid Aziz839cb992013-05-16 19:44:13 -0600714enum 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
Linus Torvalds1da177e2005-04-16 15:20:36 -0700740} PACKED;
741
742
743/*
744 Define the SCSI Target Device Status Codes.
745*/
746
Khalid Aziz839cb992013-05-16 19:44:13 -0600747enum blogic_tgt_status {
748 BLOGIC_OP_GOOD = 0x00,
749 BLOGIC_CHECKCONDITION = 0x02,
750 BLOGIC_DEVBUSY = 0x08
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751} PACKED;
752
753/*
754 Define the Queue Tag Codes.
755*/
756
Khalid Aziz839cb992013-05-16 19:44:13 -0600757enum blogic_queuetag {
758 BLOGIC_SIMPLETAG = 0,
759 BLOGIC_HEADTAG = 1,
760 BLOGIC_ORDEREDTAG = 2,
761 BLOGIC_RSVDTAG = 3
Linus Torvalds1da177e2005-04-16 15:20:36 -0700762};
763
764/*
765 Define the SCSI Command Descriptor Block (CDB).
766*/
767
Khalid Aziz839cb992013-05-16 19:44:13 -0600768#define BLOGIC_CDB_MAXLEN 12
Linus Torvalds1da177e2005-04-16 15:20:36 -0700769
770
771/*
772 Define the Scatter/Gather Segment structure required by the MultiMaster
773 Firmware Interface and the FlashPoint SCCB Manager.
774*/
775
Khalid Aziz839cb992013-05-16 19:44:13 -0600776struct blogic_sg_seg {
777 u32 segbytes; /* Bytes 0-3 */
778 u32 segdata; /* Bytes 4-7 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700779};
780
781/*
782 Define the Driver CCB Status Codes.
783*/
784
Khalid Aziz839cb992013-05-16 19:44:13 -0600785enum blogic_ccb_status {
786 BLOGIC_CCB_FREE = 0,
787 BLOGIC_CCB_ACTIVE = 1,
788 BLOGIC_CCB_COMPLETE = 2,
789 BLOGIC_CCB_RESET = 3
Linus Torvalds1da177e2005-04-16 15:20:36 -0700790} 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
Khalid Aziz839cb992013-05-16 19:44:13 -0600812struct blogic_ccb {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700813 /*
814 MultiMaster Firmware and FlashPoint SCCB Manager Common Portion.
815 */
Khalid Aziz839cb992013-05-16 19:44:13 -0600816 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 u32 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 unsigned int:32; /* Bytes 32-35 */
837 u32 sensedata; /* Bytes 36-39 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700838 /*
839 FlashPoint SCCB Manager Defined Portion.
840 */
Khalid Aziz839cb992013-05-16 19:44:13 -0600841 void (*callback) (struct blogic_ccb *); /* Bytes 40-43 */
842 u32 base_addr; /* Bytes 44-47 */
843 enum blogic_cmplt_code comp_code; /* Byte 48 */
Matthew Wilcox78b4b052008-03-13 06:55:08 -0600844#ifdef CONFIG_SCSI_FLASHPOINT
Khalid Aziz839cb992013-05-16 19:44:13 -0600845 unsigned char:8; /* Byte 49 */
846 unsigned short os_flags; /* Bytes 50-51 */
847 unsigned char private[48]; /* Bytes 52-99 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700848#endif
849 /*
850 BusLogic Linux Driver Defined Portion.
851 */
Khalid Aziz839cb992013-05-16 19:44:13 -0600852 dma_addr_t allocgrp_head;
853 unsigned int allocgrp_size;
854 u32 dma_handle;
855 enum blogic_ccb_status status;
856 unsigned long serial;
857 struct scsi_cmnd *command;
858 struct blogic_adapter *adapter;
859 struct blogic_ccb *next;
860 struct blogic_ccb *next_all;
861 struct blogic_sg_seg sglist[BLOGIC_SG_LIMIT];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700862};
863
864/*
865 Define the 32 Bit Mode Outgoing Mailbox structure.
866*/
867
Khalid Aziz839cb992013-05-16 19:44:13 -0600868struct blogic_outbox {
869 u32 ccb; /* Bytes 0-3 */
870 unsigned int:24; /* Bytes 4-6 */
871 enum blogic_action action; /* Byte 7 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700872};
873
874/*
875 Define the 32 Bit Mode Incoming Mailbox structure.
876*/
877
Khalid Aziz839cb992013-05-16 19:44:13 -0600878struct blogic_inbox {
879 u32 ccb; /* Bytes 0-3 */
880 enum blogic_adapter_status adapter_status; /* Byte 4 */
881 enum blogic_tgt_status tgt_status; /* Byte 5 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700882 unsigned char:8; /* Byte 6 */
Khalid Aziz839cb992013-05-16 19:44:13 -0600883 enum blogic_cmplt_code comp_code; /* Byte 7 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700884};
885
886
887/*
888 Define the BusLogic Driver Options structure.
889*/
890
Khalid Aziz839cb992013-05-16 19:44:13 -0600891struct blogic_drvr_options {
892 unsigned short tagq_ok;
893 unsigned short tagq_ok_mask;
894 unsigned short bus_settle_time;
895 unsigned short stop_tgt_inquiry;
896 unsigned char common_qdepth;
897 unsigned char qdepth[BLOGIC_MAXDEV];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700898};
899
900/*
901 Define the Host Adapter Target Flags structure.
902*/
903
Khalid Aziz839cb992013-05-16 19:44:13 -0600904struct blogic_tgt_flags {
905 bool tgt_exists:1;
906 bool tagq_ok:1;
907 bool wide_ok:1;
908 bool tagq_active:1;
909 bool wide_active:1;
910 bool cmd_good:1;
911 bool tgt_info_in:1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700912};
913
914/*
915 Define the Host Adapter Target Statistics structure.
916*/
917
Khalid Aziz839cb992013-05-16 19:44:13 -0600918#define BLOGIC_SZ_BUCKETS 10
Linus Torvalds1da177e2005-04-16 15:20:36 -0700919
Khalid Aziz839cb992013-05-16 19:44:13 -0600920struct blogic_tgt_stats {
921 unsigned int cmds_tried;
922 unsigned int cmds_complete;
923 unsigned int read_cmds;
924 unsigned int write_cmds;
925 struct blogic_byte_count bytesread;
926 struct blogic_byte_count byteswritten;
927 unsigned int read_sz_buckets[BLOGIC_SZ_BUCKETS];
928 unsigned int write_sz_buckets[BLOGIC_SZ_BUCKETS];
929 unsigned short aborts_request;
930 unsigned short aborts_tried;
931 unsigned short aborts_done;
932 unsigned short bdr_request;
933 unsigned short bdr_tried;
934 unsigned short bdr_done;
935 unsigned short adatper_reset_req;
936 unsigned short adapter_reset_attempt;
937 unsigned short adapter_reset_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700938};
939
940/*
941 Define the FlashPoint Card Handle data type.
942*/
943
Khalid Aziz839cb992013-05-16 19:44:13 -0600944#define FPOINT_BADCARD_HANDLE 0xFFFFFFFF
Linus Torvalds1da177e2005-04-16 15:20:36 -0700945
946
947/*
948 Define the FlashPoint Information structure. This structure is defined
949 by the FlashPoint SCCB Manager.
950*/
951
Khalid Aziz839cb992013-05-16 19:44:13 -0600952struct fpoint_info {
953 u32 base_addr; /* Bytes 0-3 */
954 bool present; /* Byte 4 */
955 unsigned char irq_ch; /* Byte 5 */
956 unsigned char scsi_id; /* Byte 6 */
957 unsigned char scsi_lun; /* Byte 7 */
958 unsigned short fw_rev; /* Bytes 8-9 */
959 unsigned short sync_ok; /* Bytes 10-11 */
960 unsigned short fast_ok; /* Bytes 12-13 */
961 unsigned short ultra_ok; /* Bytes 14-15 */
962 unsigned short discon_ok; /* Bytes 16-17 */
963 unsigned short wide_ok; /* Bytes 18-19 */
964 bool parity:1; /* Byte 20 Bit 0 */
965 bool wide:1; /* Byte 20 Bit 1 */
966 bool softreset:1; /* Byte 20 Bit 2 */
967 bool ext_trans_enable:1; /* Byte 20 Bit 3 */
968 bool low_term:1; /* Byte 20 Bit 4 */
969 bool high_term:1; /* Byte 20 Bit 5 */
970 bool report_underrun:1; /* Byte 20 Bit 6 */
971 bool scam_enabled:1; /* Byte 20 Bit 7 */
972 bool scam_lev2:1; /* Byte 21 Bit 0 */
973 unsigned char:7; /* Byte 21 Bits 1-7 */
974 unsigned char family; /* Byte 22 */
975 unsigned char bus_type; /* Byte 23 */
976 unsigned char model[3]; /* Bytes 24-26 */
977 unsigned char relative_cardnum; /* Byte 27 */
978 unsigned char rsvd[4]; /* Bytes 28-31 */
979 unsigned int os_rsvd; /* Bytes 32-35 */
980 unsigned char translation_info[4]; /* Bytes 36-39 */
981 unsigned int rsvd2[5]; /* Bytes 40-59 */
982 unsigned int sec_range; /* Bytes 60-63 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700983};
984
985/*
986 Define the BusLogic Driver Host Adapter structure.
987*/
988
Khalid Aziz839cb992013-05-16 19:44:13 -0600989struct blogic_adapter {
990 struct Scsi_Host *scsi_host;
991 struct pci_dev *pci_device;
992 enum blogic_adapter_type adapter_type;
993 enum blogic_adapter_bus_type adapter_bus_type;
994 unsigned long io_addr;
995 unsigned long pci_addr;
996 unsigned short addr_count;
997 unsigned char host_no;
998 unsigned char model[9];
999 unsigned char fw_ver[6];
1000 unsigned char full_model[18];
1001 unsigned char bus;
1002 unsigned char dev;
1003 unsigned char irq_ch;
1004 unsigned char dma_ch;
1005 unsigned char scsi_id;
1006 bool irq_acquired:1;
1007 bool dma_chan_acquired:1;
1008 bool ext_trans_enable:1;
1009 bool parity:1;
1010 bool reset_enabled:1;
1011 bool level_int:1;
1012 bool wide:1;
1013 bool differential:1;
1014 bool scam:1;
1015 bool ultra:1;
1016 bool ext_lun:1;
1017 bool terminfo_valid:1;
1018 bool low_term:1;
1019 bool high_term:1;
1020 bool need_bouncebuf:1;
1021 bool strict_rr:1;
1022 bool scam_enabled:1;
1023 bool scam_lev2:1;
1024 bool adapter_initd:1;
1025 bool adapter_extreset:1;
1026 bool adapter_intern_err:1;
1027 bool processing_ccbs;
1028 volatile bool adapter_cmd_complete;
1029 unsigned short adapter_sglimit;
1030 unsigned short drvr_sglimit;
1031 unsigned short maxdev;
1032 unsigned short maxlun;
1033 unsigned short mbox_count;
1034 unsigned short initccbs;
1035 unsigned short inc_ccbs;
1036 unsigned short alloc_ccbs;
1037 unsigned short drvr_qdepth;
1038 unsigned short adapter_qdepth;
1039 unsigned short untag_qdepth;
1040 unsigned short common_qdepth;
1041 unsigned short bus_settle_time;
1042 unsigned short sync_ok;
1043 unsigned short fast_ok;
1044 unsigned short ultra_ok;
1045 unsigned short wide_ok;
1046 unsigned short discon_ok;
1047 unsigned short tagq_ok;
1048 unsigned short ext_resets;
1049 unsigned short adapter_intern_errors;
1050 unsigned short tgt_count;
1051 unsigned short msgbuflen;
1052 u32 bios_addr;
1053 struct blogic_drvr_options *drvr_opts;
1054 struct fpoint_info fpinfo;
1055 unsigned int cardhandle;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001056 struct list_head host_list;
Khalid Aziz839cb992013-05-16 19:44:13 -06001057 struct blogic_ccb *all_ccbs;
1058 struct blogic_ccb *free_ccbs;
1059 struct blogic_ccb *firstccb;
1060 struct blogic_ccb *lastccb;
1061 struct blogic_ccb *bdr_pend[BLOGIC_MAXDEV];
1062 struct blogic_tgt_flags tgt_flags[BLOGIC_MAXDEV];
1063 unsigned char qdepth[BLOGIC_MAXDEV];
1064 unsigned char sync_period[BLOGIC_MAXDEV];
1065 unsigned char sync_offset[BLOGIC_MAXDEV];
1066 unsigned char active_cmds[BLOGIC_MAXDEV];
1067 unsigned int cmds_since_rst[BLOGIC_MAXDEV];
1068 unsigned long last_seqpoint[BLOGIC_MAXDEV];
1069 unsigned long last_resettried[BLOGIC_MAXDEV];
1070 unsigned long last_resetdone[BLOGIC_MAXDEV];
1071 struct blogic_outbox *first_outbox;
1072 struct blogic_outbox *last_outbox;
1073 struct blogic_outbox *next_outbox;
1074 struct blogic_inbox *first_inbox;
1075 struct blogic_inbox *last_inbox;
1076 struct blogic_inbox *next_inbox;
1077 struct blogic_tgt_stats tgt_stats[BLOGIC_MAXDEV];
1078 unsigned char *mbox_space;
1079 dma_addr_t mbox_space_handle;
1080 unsigned int mbox_sz;
1081 unsigned long ccb_offset;
1082 char msgbuf[BLOGIC_MSGBUF_SIZE];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001083};
1084
1085/*
1086 Define a structure for the BIOS Disk Parameters.
1087*/
1088
Khalid Aziz839cb992013-05-16 19:44:13 -06001089struct bios_diskparam {
1090 int heads;
1091 int sectors;
1092 int cylinders;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001093};
1094
1095/*
1096 Define a structure for the SCSI Inquiry command results.
1097*/
1098
Khalid Aziz839cb992013-05-16 19:44:13 -06001099struct scsi_inquiry {
1100 unsigned char devtype:5; /* Byte 0 Bits 0-4 */
1101 unsigned char dev_qual:3; /* Byte 0 Bits 5-7 */
1102 unsigned char dev_modifier:7; /* Byte 1 Bits 0-6 */
1103 bool rmb:1; /* Byte 1 Bit 7 */
1104 unsigned char ansi_ver:3; /* Byte 2 Bits 0-2 */
1105 unsigned char ecma_ver:3; /* Byte 2 Bits 3-5 */
1106 unsigned char iso_ver:2; /* Byte 2 Bits 6-7 */
1107 unsigned char resp_fmt:4; /* Byte 3 Bits 0-3 */
1108 unsigned char:2; /* Byte 3 Bits 4-5 */
1109 bool TrmIOP:1; /* Byte 3 Bit 6 */
1110 bool AENC:1; /* Byte 3 Bit 7 */
1111 unsigned char addl_len; /* Byte 4 */
1112 unsigned char:8; /* Byte 5 */
1113 unsigned char:8; /* Byte 6 */
1114 bool SftRe:1; /* Byte 7 Bit 0 */
1115 bool CmdQue:1; /* Byte 7 Bit 1 */
1116 bool:1; /* Byte 7 Bit 2 */
1117 bool linked:1; /* Byte 7 Bit 3 */
1118 bool sync:1; /* Byte 7 Bit 4 */
1119 bool WBus16:1; /* Byte 7 Bit 5 */
1120 bool WBus32:1; /* Byte 7 Bit 6 */
1121 bool RelAdr:1; /* Byte 7 Bit 7 */
1122 unsigned char vendor[8]; /* Bytes 8-15 */
1123 unsigned char product[16]; /* Bytes 16-31 */
1124 unsigned char product_rev[4]; /* Bytes 32-35 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001125};
1126
1127
1128/*
1129 Define functions to provide an abstraction for reading and writing the
1130 Host Adapter I/O Registers.
1131*/
1132
Khalid Aziz839cb992013-05-16 19:44:13 -06001133static inline void blogic_busreset(struct blogic_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001134{
Khalid Aziz839cb992013-05-16 19:44:13 -06001135 union blogic_cntrl_reg cr;
1136 cr.all = 0;
1137 cr.cr.bus_reset = true;
1138 outb(cr.all, adapter->io_addr + BLOGIC_CNTRL_REG);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001139}
1140
Khalid Aziz839cb992013-05-16 19:44:13 -06001141static inline void blogic_intreset(struct blogic_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001142{
Khalid Aziz839cb992013-05-16 19:44:13 -06001143 union blogic_cntrl_reg cr;
1144 cr.all = 0;
1145 cr.cr.int_reset = true;
1146 outb(cr.all, adapter->io_addr + BLOGIC_CNTRL_REG);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001147}
1148
Khalid Aziz839cb992013-05-16 19:44:13 -06001149static inline void blogic_softreset(struct blogic_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001150{
Khalid Aziz839cb992013-05-16 19:44:13 -06001151 union blogic_cntrl_reg cr;
1152 cr.all = 0;
1153 cr.cr.soft_reset = true;
1154 outb(cr.all, adapter->io_addr + BLOGIC_CNTRL_REG);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001155}
1156
Khalid Aziz839cb992013-05-16 19:44:13 -06001157static inline void blogic_hardreset(struct blogic_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001158{
Khalid Aziz839cb992013-05-16 19:44:13 -06001159 union blogic_cntrl_reg cr;
1160 cr.all = 0;
1161 cr.cr.hard_reset = true;
1162 outb(cr.all, adapter->io_addr + BLOGIC_CNTRL_REG);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001163}
1164
Khalid Aziz839cb992013-05-16 19:44:13 -06001165static inline unsigned char blogic_rdstatus(struct blogic_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001166{
Khalid Aziz839cb992013-05-16 19:44:13 -06001167 return inb(adapter->io_addr + BLOGIC_STATUS_REG);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001168}
1169
Khalid Aziz839cb992013-05-16 19:44:13 -06001170static inline void blogic_setcmdparam(struct blogic_adapter *adapter,
1171 unsigned char value)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001172{
Khalid Aziz839cb992013-05-16 19:44:13 -06001173 outb(value, adapter->io_addr + BLOGIC_CMD_PARM_REG);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001174}
1175
Khalid Aziz839cb992013-05-16 19:44:13 -06001176static inline unsigned char blogic_rddatain(struct blogic_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001177{
Khalid Aziz839cb992013-05-16 19:44:13 -06001178 return inb(adapter->io_addr + BLOGIC_DATAIN_REG);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001179}
1180
Khalid Aziz839cb992013-05-16 19:44:13 -06001181static inline unsigned char blogic_rdint(struct blogic_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001182{
Khalid Aziz839cb992013-05-16 19:44:13 -06001183 return inb(adapter->io_addr + BLOGIC_INT_REG);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001184}
1185
Khalid Aziz839cb992013-05-16 19:44:13 -06001186static inline unsigned char blogic_rdgeom(struct blogic_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001187{
Khalid Aziz839cb992013-05-16 19:44:13 -06001188 return inb(adapter->io_addr + BLOGIC_GEOMETRY_REG);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001189}
1190
1191/*
Khalid Aziz839cb992013-05-16 19:44:13 -06001192 blogic_execmbox issues an Execute Mailbox Command, which
Linus Torvalds1da177e2005-04-16 15:20:36 -07001193 notifies the Host Adapter that an entry has been made in an Outgoing
1194 Mailbox.
1195*/
1196
Khalid Aziz839cb992013-05-16 19:44:13 -06001197static inline void blogic_execmbox(struct blogic_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001198{
Khalid Aziz839cb992013-05-16 19:44:13 -06001199 blogic_setcmdparam(adapter, BLOGIC_EXEC_MBOX_CMD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001200}
1201
1202/*
Khalid Aziz839cb992013-05-16 19:44:13 -06001203 blogic_delay waits for Seconds to elapse.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001204*/
1205
Khalid Aziz839cb992013-05-16 19:44:13 -06001206static inline void blogic_delay(int seconds)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001207{
Khalid Aziz839cb992013-05-16 19:44:13 -06001208 mdelay(1000 * seconds);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001209}
1210
1211/*
Khalid Aziz839cb992013-05-16 19:44:13 -06001212 virt_to_32bit_virt maps between Kernel Virtual Addresses and
Linus Torvalds1da177e2005-04-16 15:20:36 -07001213 32 bit Kernel Virtual Addresses. This avoids compilation warnings
1214 on 64 bit architectures.
1215*/
1216
Khalid Aziz839cb992013-05-16 19:44:13 -06001217static inline u32 virt_to_32bit_virt(void *virt_addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001218{
Khalid Aziz839cb992013-05-16 19:44:13 -06001219 return (u32) (unsigned long) virt_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001220}
1221
1222/*
Khalid Aziz839cb992013-05-16 19:44:13 -06001223 blogic_inc_count increments counter by 1, stopping at
Linus Torvalds1da177e2005-04-16 15:20:36 -07001224 65535 rather than wrapping around to 0.
1225*/
1226
Khalid Aziz839cb992013-05-16 19:44:13 -06001227static inline void blogic_inc_count(unsigned short *count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001228{
Khalid Aziz839cb992013-05-16 19:44:13 -06001229 if (*count < 65535)
1230 (*count)++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001231}
1232
1233/*
Khalid Aziz839cb992013-05-16 19:44:13 -06001234 blogic_addcount increments Byte Counter by Amount.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001235*/
1236
Khalid Aziz839cb992013-05-16 19:44:13 -06001237static inline void blogic_addcount(struct blogic_byte_count *bytecount,
1238 unsigned int amount)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001239{
Khalid Aziz839cb992013-05-16 19:44:13 -06001240 bytecount->units += amount;
1241 if (bytecount->units > 999999999) {
1242 bytecount->units -= 1000000000;
1243 bytecount->billions++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001244 }
1245}
1246
1247/*
Khalid Aziz839cb992013-05-16 19:44:13 -06001248 blogic_incszbucket increments the Bucket for Amount.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001249*/
1250
Khalid Aziz839cb992013-05-16 19:44:13 -06001251static inline void blogic_incszbucket(unsigned int *cmdsz_buckets,
1252 unsigned int amount)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001253{
Khalid Aziz839cb992013-05-16 19:44:13 -06001254 int index = 0;
1255 if (amount < 8 * 1024) {
1256 if (amount < 2 * 1024)
1257 index = (amount < 1 * 1024 ? 0 : 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001258 else
Khalid Aziz839cb992013-05-16 19:44:13 -06001259 index = (amount < 4 * 1024 ? 2 : 3);
1260 } else if (amount < 128 * 1024) {
1261 if (amount < 32 * 1024)
1262 index = (amount < 16 * 1024 ? 4 : 5);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001263 else
Khalid Aziz839cb992013-05-16 19:44:13 -06001264 index = (amount < 64 * 1024 ? 6 : 7);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001265 } else
Khalid Aziz839cb992013-05-16 19:44:13 -06001266 index = (amount < 256 * 1024 ? 8 : 9);
1267 cmdsz_buckets[index]++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001268}
1269
1270/*
1271 Define the version number of the FlashPoint Firmware (SCCB Manager).
1272*/
1273
Khalid Aziz839cb992013-05-16 19:44:13 -06001274#define FLASHPOINT_FW_VER "5.02"
Linus Torvalds1da177e2005-04-16 15:20:36 -07001275
1276/*
1277 Define the possible return values from FlashPoint_HandleInterrupt.
1278*/
1279
Khalid Aziz839cb992013-05-16 19:44:13 -06001280#define FPOINT_NORMAL_INT 0x00
1281#define FPOINT_INTERN_ERR 0xFE
1282#define FPOINT_EXT_RESET 0xFF
Linus Torvalds1da177e2005-04-16 15:20:36 -07001283
1284/*
1285 Define prototypes for the forward referenced BusLogic Driver
1286 Internal Functions.
1287*/
1288
Khalid Aziz839cb992013-05-16 19:44:13 -06001289static const char *blogic_drvr_info(struct Scsi_Host *);
1290static int blogic_qcmd(struct Scsi_Host *h, struct scsi_cmnd *);
1291static int blogic_diskparam(struct scsi_device *, struct block_device *, sector_t, int *);
1292static int blogic_slaveconfig(struct scsi_device *);
1293static void blogic_qcompleted_ccb(struct blogic_ccb *);
1294static irqreturn_t blogic_inthandler(int, void *);
1295static int blogic_resetadapter(struct blogic_adapter *, bool hard_reset);
1296static void blogic_msg(enum blogic_msglevel, char *, struct blogic_adapter *, ...);
1297static int __init blogic_setup(char *);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001298
1299#endif /* _BUSLOGIC_H */