blob: 7d1ec10f243052023f6de6512815451b6f88fc21 [file] [log] [blame]
Thomas Gleixner58751752019-05-31 01:09:46 -07001/* SPDX-License-Identifier: GPL-2.0-only */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
3
4 Linux Driver for BusLogic MultiMaster and FlashPoint SCSI Host Adapters
5
6 Copyright 1995-1998 by Leonard N. Zubkoff <lnz@dandelion.com>
7
Linus Torvalds1da177e2005-04-16 15:20:36 -07008
9 The author respectfully requests that any modifications to this software be
10 sent directly to him for evaluation and testing.
11
12 Special thanks to Wayne Yen, Jin-Lon Hon, and Alex Win of BusLogic, whose
13 advice has been invaluable, to David Gentzel, for writing the original Linux
14 BusLogic driver, and to Paul Gortmaker, for being such a dedicated test site.
15
16 Finally, special thanks to Mylex/BusLogic for making the FlashPoint SCCB
17 Manager available as freely redistributable source code.
18
19*/
20
21#ifndef _BUSLOGIC_H
22#define _BUSLOGIC_H
23
Linus Torvalds1da177e2005-04-16 15:20:36 -070024
25#ifndef PACKED
26#define PACKED __attribute__((packed))
27#endif
28
29/*
Linus Torvalds1da177e2005-04-16 15:20:36 -070030 Define the maximum number of BusLogic Host Adapters supported by this driver.
31*/
32
Khalid Aziz839cb992013-05-16 19:44:13 -060033#define BLOGIC_MAX_ADAPTERS 16
Linus Torvalds1da177e2005-04-16 15:20:36 -070034
35
36/*
37 Define the maximum number of Target Devices supported by this driver.
38*/
39
Khalid Aziz839cb992013-05-16 19:44:13 -060040#define BLOGIC_MAXDEV 16
Linus Torvalds1da177e2005-04-16 15:20:36 -070041
42
43/*
44 Define the maximum number of Scatter/Gather Segments used by this driver.
45 For optimal performance, it is important that this limit be at least as
46 large as the largest single request generated by the I/O Subsystem.
47*/
48
Khalid Aziz839cb992013-05-16 19:44:13 -060049#define BLOGIC_SG_LIMIT 128
Linus Torvalds1da177e2005-04-16 15:20:36 -070050
51
52/*
53 Define the maximum, maximum automatic, minimum automatic, and default Queue
54 Depth to allow for Target Devices depending on whether or not they support
55 Tagged Queuing and whether or not ISA Bounce Buffers are required.
56*/
57
Khalid Aziz839cb992013-05-16 19:44:13 -060058#define BLOGIC_MAX_TAG_DEPTH 64
59#define BLOGIC_MAX_AUTO_TAG_DEPTH 28
60#define BLOGIC_MIN_AUTO_TAG_DEPTH 7
61#define BLOGIC_TAG_DEPTH_BB 3
62#define BLOGIC_UNTAG_DEPTH 3
63#define BLOGIC_UNTAG_DEPTH_BB 2
Linus Torvalds1da177e2005-04-16 15:20:36 -070064
65
66/*
67 Define the default amount of time in seconds to wait between a Host Adapter
68 Hard Reset which initiates a SCSI Bus Reset and issuing any SCSI commands.
69 Some SCSI devices get confused if they receive SCSI commands too soon after
70 a SCSI Bus Reset.
71*/
72
Khalid Aziz839cb992013-05-16 19:44:13 -060073#define BLOGIC_BUS_SETTLE_TIME 2
Linus Torvalds1da177e2005-04-16 15:20:36 -070074
75
76/*
77 Define the maximum number of Mailboxes that should be used for MultiMaster
78 Host Adapters. This number is chosen to be larger than the maximum Host
79 Adapter Queue Depth and small enough so that the Host Adapter structure
80 does not cross an allocation block size boundary.
81*/
82
Khalid Aziz839cb992013-05-16 19:44:13 -060083#define BLOGIC_MAX_MAILBOX 211
Linus Torvalds1da177e2005-04-16 15:20:36 -070084
85
86/*
87 Define the number of CCBs that should be allocated as a group to optimize
88 Kernel memory allocation.
89*/
90
Khalid Aziz839cb992013-05-16 19:44:13 -060091#define BLOGIC_CCB_GRP_ALLOCSIZE 7
Linus Torvalds1da177e2005-04-16 15:20:36 -070092
93
94/*
95 Define the Host Adapter Line and Message Buffer Sizes.
96*/
97
Khalid Aziz839cb992013-05-16 19:44:13 -060098#define BLOGIC_LINEBUF_SIZE 100
99#define BLOGIC_MSGBUF_SIZE 9700
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100
101
102/*
103 Define the Driver Message Levels.
104*/
105
Khalid Aziz839cb992013-05-16 19:44:13 -0600106enum blogic_msglevel {
107 BLOGIC_ANNOUNCE_LEVEL = 0,
108 BLOGIC_INFO_LEVEL = 1,
109 BLOGIC_NOTICE_LEVEL = 2,
110 BLOGIC_WARN_LEVEL = 3,
111 BLOGIC_ERR_LEVEL = 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112};
113
Khalid Aziz839cb992013-05-16 19:44:13 -0600114static char *blogic_msglevelmap[] = { KERN_NOTICE, KERN_NOTICE, KERN_NOTICE, KERN_WARNING, KERN_ERR };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115
116
117/*
118 Define Driver Message macros.
119*/
120
Khalid Aziz839cb992013-05-16 19:44:13 -0600121#define blogic_announce(format, args...) \
122 blogic_msg(BLOGIC_ANNOUNCE_LEVEL, format, ##args)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123
Khalid Aziz839cb992013-05-16 19:44:13 -0600124#define blogic_info(format, args...) \
125 blogic_msg(BLOGIC_INFO_LEVEL, format, ##args)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126
Khalid Aziz839cb992013-05-16 19:44:13 -0600127#define blogic_notice(format, args...) \
128 blogic_msg(BLOGIC_NOTICE_LEVEL, format, ##args)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129
Khalid Aziz839cb992013-05-16 19:44:13 -0600130#define blogic_warn(format, args...) \
131 blogic_msg(BLOGIC_WARN_LEVEL, format, ##args)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132
Khalid Aziz839cb992013-05-16 19:44:13 -0600133#define blogic_err(format, args...) \
134 blogic_msg(BLOGIC_ERR_LEVEL, format, ##args)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135
136
137/*
138 Define the types of BusLogic Host Adapters that are supported and the number
139 of I/O Addresses required by each type.
140*/
141
Khalid Aziz839cb992013-05-16 19:44:13 -0600142enum blogic_adapter_type {
143 BLOGIC_MULTIMASTER = 1,
144 BLOGIC_FLASHPOINT = 2
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145} PACKED;
146
Khalid Aziz839cb992013-05-16 19:44:13 -0600147#define BLOGIC_MULTIMASTER_ADDR_COUNT 4
148#define BLOGIC_FLASHPOINT_ADDR_COUNT 256
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149
Khalid Aziz839cb992013-05-16 19:44:13 -0600150static int blogic_adapter_addr_count[3] = { 0, BLOGIC_MULTIMASTER_ADDR_COUNT, BLOGIC_FLASHPOINT_ADDR_COUNT };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151
152
153/*
154 Define macros for testing the Host Adapter Type.
155*/
156
Matthew Wilcox78b4b052008-03-13 06:55:08 -0600157#ifdef CONFIG_SCSI_FLASHPOINT
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158
Khalid Aziz839cb992013-05-16 19:44:13 -0600159#define blogic_multimaster_type(adapter) \
160 (adapter->adapter_type == BLOGIC_MULTIMASTER)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161
Khalid Aziz839cb992013-05-16 19:44:13 -0600162#define blogic_flashpoint_type(adapter) \
163 (adapter->adapter_type == BLOGIC_FLASHPOINT)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164
165#else
166
Khalid Aziz839cb992013-05-16 19:44:13 -0600167#define blogic_multimaster_type(adapter) (true)
168#define blogic_flashpoint_type(adapter) (false)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169
170#endif
171
172
173/*
174 Define the possible Host Adapter Bus Types.
175*/
176
Khalid Aziz839cb992013-05-16 19:44:13 -0600177enum blogic_adapter_bus_type {
178 BLOGIC_UNKNOWN_BUS = 0,
179 BLOGIC_ISA_BUS = 1,
180 BLOGIC_EISA_BUS = 2,
181 BLOGIC_PCI_BUS = 3,
182 BLOGIC_VESA_BUS = 4,
183 BLOGIC_MCA_BUS = 5
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184} PACKED;
185
Khalid Aziz839cb992013-05-16 19:44:13 -0600186static char *blogic_adapter_busnames[] = { "Unknown", "ISA", "EISA", "PCI", "VESA", "MCA" };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187
Khalid Aziz839cb992013-05-16 19:44:13 -0600188static enum blogic_adapter_bus_type blogic_adater_bus_types[] = {
189 BLOGIC_VESA_BUS, /* BT-4xx */
190 BLOGIC_ISA_BUS, /* BT-5xx */
191 BLOGIC_MCA_BUS, /* BT-6xx */
192 BLOGIC_EISA_BUS, /* BT-7xx */
193 BLOGIC_UNKNOWN_BUS, /* BT-8xx */
194 BLOGIC_PCI_BUS /* BT-9xx */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195};
196
197/*
198 Define the possible Host Adapter BIOS Disk Geometry Translations.
199*/
200
Khalid Aziz839cb992013-05-16 19:44:13 -0600201enum blogic_bios_diskgeometry {
202 BLOGIC_BIOS_NODISK = 0,
203 BLOGIC_BIOS_DISK64x32 = 1,
204 BLOGIC_BIOS_DISK128x32 = 2,
205 BLOGIC_BIOS_DISK255x63 = 3
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206} PACKED;
207
208
209/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210 Define a 10^18 Statistics Byte Counter data type.
211*/
212
Khalid Aziz839cb992013-05-16 19:44:13 -0600213struct blogic_byte_count {
214 unsigned int units;
215 unsigned int billions;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216};
217
218
219/*
220 Define the structure for I/O Address and Bus Probing Information.
221*/
222
Khalid Aziz839cb992013-05-16 19:44:13 -0600223struct blogic_probeinfo {
224 enum blogic_adapter_type adapter_type;
225 enum blogic_adapter_bus_type adapter_bus_type;
226 unsigned long io_addr;
227 unsigned long pci_addr;
228 struct pci_dev *pci_device;
229 unsigned char bus;
230 unsigned char dev;
231 unsigned char irq_ch;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232};
233
234/*
235 Define the Probe Options.
236*/
237
Khalid Aziz839cb992013-05-16 19:44:13 -0600238struct blogic_probe_options {
239 bool noprobe:1; /* Bit 0 */
Khalid Aziz839cb992013-05-16 19:44:13 -0600240 bool noprobe_pci:1; /* Bit 2 */
241 bool nosort_pci:1; /* Bit 3 */
242 bool multimaster_first:1; /* Bit 4 */
243 bool flashpoint_first:1; /* Bit 5 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244};
245
246/*
247 Define the Global Options.
248*/
249
Khalid Aziz839cb992013-05-16 19:44:13 -0600250struct blogic_global_options {
251 bool trace_probe:1; /* Bit 0 */
252 bool trace_hw_reset:1; /* Bit 1 */
253 bool trace_config:1; /* Bit 2 */
254 bool trace_err:1; /* Bit 3 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255};
256
257/*
258 Define the BusLogic SCSI Host Adapter I/O Register Offsets.
259*/
260
Khalid Aziz839cb992013-05-16 19:44:13 -0600261#define BLOGIC_CNTRL_REG 0 /* WO register */
262#define BLOGIC_STATUS_REG 0 /* RO register */
263#define BLOGIC_CMD_PARM_REG 1 /* WO register */
264#define BLOGIC_DATAIN_REG 1 /* RO register */
265#define BLOGIC_INT_REG 2 /* RO register */
266#define BLOGIC_GEOMETRY_REG 3 /* RO register */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267
268/*
269 Define the structure of the write-only Control Register.
270*/
271
Khalid Aziz839cb992013-05-16 19:44:13 -0600272union blogic_cntrl_reg {
273 unsigned char all;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274 struct {
275 unsigned char:4; /* Bits 0-3 */
Khalid Aziz839cb992013-05-16 19:44:13 -0600276 bool bus_reset:1; /* Bit 4 */
277 bool int_reset:1; /* Bit 5 */
278 bool soft_reset:1; /* Bit 6 */
279 bool hard_reset:1; /* Bit 7 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280 } cr;
281};
282
283/*
284 Define the structure of the read-only Status Register.
285*/
286
Khalid Aziz839cb992013-05-16 19:44:13 -0600287union blogic_stat_reg {
288 unsigned char all;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289 struct {
Khalid Aziz839cb992013-05-16 19:44:13 -0600290 bool cmd_invalid:1; /* Bit 0 */
291 bool rsvd:1; /* Bit 1 */
292 bool datain_ready:1; /* Bit 2 */
293 bool cmd_param_busy:1; /* Bit 3 */
294 bool adapter_ready:1; /* Bit 4 */
295 bool init_reqd:1; /* Bit 5 */
296 bool diag_failed:1; /* Bit 6 */
297 bool diag_active:1; /* Bit 7 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298 } sr;
299};
300
301/*
302 Define the structure of the read-only Interrupt Register.
303*/
304
Khalid Aziz839cb992013-05-16 19:44:13 -0600305union blogic_int_reg {
306 unsigned char all;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307 struct {
Khalid Aziz839cb992013-05-16 19:44:13 -0600308 bool mailin_loaded:1; /* Bit 0 */
309 bool mailout_avail:1; /* Bit 1 */
310 bool cmd_complete:1; /* Bit 2 */
311 bool ext_busreset:1; /* Bit 3 */
312 unsigned char rsvd:3; /* Bits 4-6 */
313 bool int_valid:1; /* Bit 7 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314 } ir;
315};
316
317/*
318 Define the structure of the read-only Geometry Register.
319*/
320
Khalid Aziz839cb992013-05-16 19:44:13 -0600321union blogic_geo_reg {
322 unsigned char all;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323 struct {
Khalid Aziz839cb992013-05-16 19:44:13 -0600324 enum blogic_bios_diskgeometry d0_geo:2; /* Bits 0-1 */
325 enum blogic_bios_diskgeometry d1_geo:2; /* Bits 2-3 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326 unsigned char:3; /* Bits 4-6 */
Khalid Aziz839cb992013-05-16 19:44:13 -0600327 bool ext_trans_enable:1; /* Bit 7 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328 } gr;
329};
330
331/*
332 Define the BusLogic SCSI Host Adapter Command Register Operation Codes.
333*/
334
Khalid Aziz839cb992013-05-16 19:44:13 -0600335enum blogic_opcode {
336 BLOGIC_TEST_CMP_COMPLETE = 0x00,
337 BLOGIC_INIT_MBOX = 0x01,
338 BLOGIC_EXEC_MBOX_CMD = 0x02,
339 BLOGIC_EXEC_BIOS_CMD = 0x03,
340 BLOGIC_GET_BOARD_ID = 0x04,
341 BLOGIC_ENABLE_OUTBOX_AVAIL_INT = 0x05,
342 BLOGIC_SET_SELECT_TIMEOUT = 0x06,
343 BLOGIC_SET_PREEMPT_TIME = 0x07,
344 BLOGIC_SET_TIMEOFF_BUS = 0x08,
345 BLOGIC_SET_TXRATE = 0x09,
346 BLOGIC_INQ_DEV0TO7 = 0x0A,
347 BLOGIC_INQ_CONFIG = 0x0B,
348 BLOGIC_TGT_MODE = 0x0C,
349 BLOGIC_INQ_SETUPINFO = 0x0D,
350 BLOGIC_WRITE_LOCALRAM = 0x1A,
351 BLOGIC_READ_LOCALRAM = 0x1B,
352 BLOGIC_WRITE_BUSMASTER_FIFO = 0x1C,
353 BLOGIC_READ_BUSMASTER_FIFO = 0x1D,
354 BLOGIC_ECHO_CMDDATA = 0x1F,
355 BLOGIC_ADAPTER_DIAG = 0x20,
356 BLOGIC_SET_OPTIONS = 0x21,
357 BLOGIC_INQ_DEV8TO15 = 0x23,
358 BLOGIC_INQ_DEV = 0x24,
359 BLOGIC_DISABLE_INT = 0x25,
360 BLOGIC_INIT_EXT_MBOX = 0x81,
361 BLOGIC_EXEC_SCS_CMD = 0x83,
362 BLOGIC_INQ_FWVER_D3 = 0x84,
363 BLOGIC_INQ_FWVER_LETTER = 0x85,
364 BLOGIC_INQ_PCI_INFO = 0x86,
365 BLOGIC_INQ_MODELNO = 0x8B,
366 BLOGIC_INQ_SYNC_PERIOD = 0x8C,
367 BLOGIC_INQ_EXTSETUP = 0x8D,
368 BLOGIC_STRICT_RR = 0x8F,
369 BLOGIC_STORE_LOCALRAM = 0x90,
370 BLOGIC_FETCH_LOCALRAM = 0x91,
371 BLOGIC_STORE_TO_EEPROM = 0x92,
372 BLOGIC_LOAD_AUTOSCSICODE = 0x94,
373 BLOGIC_MOD_IOADDR = 0x95,
374 BLOGIC_SETCCB_FMT = 0x96,
375 BLOGIC_WRITE_INQBUF = 0x9A,
376 BLOGIC_READ_INQBUF = 0x9B,
377 BLOGIC_FLASH_LOAD = 0xA7,
378 BLOGIC_READ_SCAMDATA = 0xA8,
379 BLOGIC_WRITE_SCAMDATA = 0xA9
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380};
381
382/*
383 Define the Inquire Board ID reply structure.
384*/
385
Khalid Aziz839cb992013-05-16 19:44:13 -0600386struct blogic_board_id {
387 unsigned char type; /* Byte 0 */
388 unsigned char custom_features; /* Byte 1 */
389 unsigned char fw_ver_digit1; /* Byte 2 */
390 unsigned char fw_ver_digit2; /* Byte 3 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391};
392
393/*
394 Define the Inquire Configuration reply structure.
395*/
396
Khalid Aziz839cb992013-05-16 19:44:13 -0600397struct blogic_config {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398 unsigned char:5; /* Byte 0 Bits 0-4 */
Khalid Aziz839cb992013-05-16 19:44:13 -0600399 bool dma_ch5:1; /* Byte 0 Bit 5 */
400 bool dma_ch6:1; /* Byte 0 Bit 6 */
401 bool dma_ch7:1; /* Byte 0 Bit 7 */
402 bool irq_ch9:1; /* Byte 1 Bit 0 */
403 bool irq_ch10:1; /* Byte 1 Bit 1 */
404 bool irq_ch11:1; /* Byte 1 Bit 2 */
405 bool irq_ch12:1; /* Byte 1 Bit 3 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406 unsigned char:1; /* Byte 1 Bit 4 */
Khalid Aziz839cb992013-05-16 19:44:13 -0600407 bool irq_ch14:1; /* Byte 1 Bit 5 */
408 bool irq_ch15:1; /* Byte 1 Bit 6 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409 unsigned char:1; /* Byte 1 Bit 7 */
Khalid Aziz839cb992013-05-16 19:44:13 -0600410 unsigned char id:4; /* Byte 2 Bits 0-3 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411 unsigned char:4; /* Byte 2 Bits 4-7 */
412};
413
414/*
415 Define the Inquire Setup Information reply structure.
416*/
417
Khalid Aziz839cb992013-05-16 19:44:13 -0600418struct blogic_syncval {
419 unsigned char offset:4; /* Bits 0-3 */
420 unsigned char tx_period:3; /* Bits 4-6 */
421 bool sync:1; /* Bit 7 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422};
423
Khalid Aziz839cb992013-05-16 19:44:13 -0600424struct blogic_setup_info {
425 bool sync:1; /* Byte 0 Bit 0 */
426 bool parity:1; /* Byte 0 Bit 1 */
427 unsigned char:6; /* Byte 0 Bits 2-7 */
428 unsigned char tx_rate; /* Byte 1 */
429 unsigned char preempt_time; /* Byte 2 */
430 unsigned char timeoff_bus; /* Byte 3 */
431 unsigned char mbox_count; /* Byte 4 */
432 unsigned char mbox_addr[3]; /* Bytes 5-7 */
433 struct blogic_syncval sync0to7[8]; /* Bytes 8-15 */
434 unsigned char disconnect_ok0to7; /* Byte 16 */
435 unsigned char sig; /* Byte 17 */
436 unsigned char char_d; /* Byte 18 */
437 unsigned char bus_type; /* Byte 19 */
438 unsigned char wide_tx_ok0to7; /* Byte 20 */
439 unsigned char wide_tx_active0to7; /* Byte 21 */
440 struct blogic_syncval sync8to15[8]; /* Bytes 22-29 */
441 unsigned char disconnect_ok8to15; /* Byte 30 */
442 unsigned char:8; /* Byte 31 */
443 unsigned char wide_tx_ok8to15; /* Byte 32 */
444 unsigned char wide_tx_active8to15; /* Byte 33 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445};
446
447/*
448 Define the Initialize Extended Mailbox request structure.
449*/
450
Khalid Aziz839cb992013-05-16 19:44:13 -0600451struct blogic_extmbox_req {
452 unsigned char mbox_count; /* Byte 0 */
453 u32 base_mbox_addr; /* Bytes 1-4 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454} PACKED;
455
456
457/*
458 Define the Inquire PCI Host Adapter Information reply type. The ISA
459 Compatible I/O Port values are defined here and are also used with
460 the Modify I/O Address command.
461*/
462
Khalid Aziz839cb992013-05-16 19:44:13 -0600463enum blogic_isa_ioport {
464 BLOGIC_IO_330 = 0,
465 BLOGIC_IO_334 = 1,
466 BLOGIC_IO_230 = 2,
467 BLOGIC_IO_234 = 3,
468 BLOGIC_IO_130 = 4,
469 BLOGIC_IO_134 = 5,
470 BLOGIC_IO_DISABLE = 6,
471 BLOGIC_IO_DISABLE2 = 7
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472} PACKED;
473
Khalid Aziz839cb992013-05-16 19:44:13 -0600474struct blogic_adapter_info {
475 enum blogic_isa_ioport isa_port; /* Byte 0 */
476 unsigned char irq_ch; /* Byte 1 */
477 bool low_term:1; /* Byte 2 Bit 0 */
478 bool high_term:1; /* Byte 2 Bit 1 */
479 unsigned char:2; /* Byte 2 Bits 2-3 */
480 bool JP1:1; /* Byte 2 Bit 4 */
481 bool JP2:1; /* Byte 2 Bit 5 */
482 bool JP3:1; /* Byte 2 Bit 6 */
483 bool genericinfo_valid:1; /* Byte 2 Bit 7 */
484 unsigned char:8; /* Byte 3 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485};
486
487/*
488 Define the Inquire Extended Setup Information reply structure.
489*/
490
Khalid Aziz839cb992013-05-16 19:44:13 -0600491struct blogic_ext_setup {
492 unsigned char bus_type; /* Byte 0 */
493 unsigned char bios_addr; /* Byte 1 */
494 unsigned short sg_limit; /* Bytes 2-3 */
495 unsigned char mbox_count; /* Byte 4 */
496 u32 base_mbox_addr; /* Bytes 5-8 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497 struct {
498 unsigned char:2; /* Byte 9 Bits 0-1 */
Khalid Aziz839cb992013-05-16 19:44:13 -0600499 bool fast_on_eisa:1; /* Byte 9 Bit 2 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500 unsigned char:3; /* Byte 9 Bits 3-5 */
Khalid Aziz839cb992013-05-16 19:44:13 -0600501 bool level_int:1; /* Byte 9 Bit 6 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502 unsigned char:1; /* Byte 9 Bit 7 */
Khalid Aziz839cb992013-05-16 19:44:13 -0600503 } misc;
504 unsigned char fw_rev[3]; /* Bytes 10-12 */
505 bool wide:1; /* Byte 13 Bit 0 */
506 bool differential:1; /* Byte 13 Bit 1 */
507 bool scam:1; /* Byte 13 Bit 2 */
508 bool ultra:1; /* Byte 13 Bit 3 */
509 bool smart_term:1; /* Byte 13 Bit 4 */
510 unsigned char:3; /* Byte 13 Bits 5-7 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511} PACKED;
512
513/*
514 Define the Enable Strict Round Robin Mode request type.
515*/
516
Khalid Aziz839cb992013-05-16 19:44:13 -0600517enum blogic_rr_req {
518 BLOGIC_AGGRESSIVE_RR = 0,
519 BLOGIC_STRICT_RR_MODE = 1
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520} PACKED;
521
522
523/*
524 Define the Fetch Host Adapter Local RAM request type.
525*/
526
Khalid Aziz839cb992013-05-16 19:44:13 -0600527#define BLOGIC_BIOS_BASE 0
528#define BLOGIC_AUTOSCSI_BASE 64
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529
Khalid Aziz839cb992013-05-16 19:44:13 -0600530struct blogic_fetch_localram {
531 unsigned char offset; /* Byte 0 */
532 unsigned char count; /* Byte 1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533};
534
535/*
536 Define the Host Adapter Local RAM AutoSCSI structure.
537*/
538
Khalid Aziz839cb992013-05-16 19:44:13 -0600539struct blogic_autoscsi {
540 unsigned char factory_sig[2]; /* Bytes 0-1 */
541 unsigned char info_bytes; /* Byte 2 */
542 unsigned char adapter_type[6]; /* Bytes 3-8 */
543 unsigned char:8; /* Byte 9 */
544 bool floppy:1; /* Byte 10 Bit 0 */
545 bool floppy_sec:1; /* Byte 10 Bit 1 */
546 bool level_int:1; /* Byte 10 Bit 2 */
547 unsigned char:2; /* Byte 10 Bits 3-4 */
548 unsigned char systemram_bios:3; /* Byte 10 Bits 5-7 */
549 unsigned char dma_ch:7; /* Byte 11 Bits 0-6 */
550 bool dma_autoconf:1; /* Byte 11 Bit 7 */
551 unsigned char irq_ch:7; /* Byte 12 Bits 0-6 */
552 bool irq_autoconf:1; /* Byte 12 Bit 7 */
553 unsigned char dma_tx_rate; /* Byte 13 */
554 unsigned char scsi_id; /* Byte 14 */
555 bool low_term:1; /* Byte 15 Bit 0 */
556 bool parity:1; /* Byte 15 Bit 1 */
557 bool high_term:1; /* Byte 15 Bit 2 */
558 bool noisy_cable:1; /* Byte 15 Bit 3 */
559 bool fast_sync_neg:1; /* Byte 15 Bit 4 */
560 bool reset_enabled:1; /* Byte 15 Bit 5 */
561 bool:1; /* Byte 15 Bit 6 */
562 bool active_negation:1; /* Byte 15 Bit 7 */
563 unsigned char bus_on_delay; /* Byte 16 */
564 unsigned char bus_off_delay; /* Byte 17 */
565 bool bios_enabled:1; /* Byte 18 Bit 0 */
566 bool int19_redir_enabled:1; /* Byte 18 Bit 1 */
567 bool ext_trans_enable:1; /* Byte 18 Bit 2 */
568 bool removable_as_fixed:1; /* Byte 18 Bit 3 */
569 bool:1; /* Byte 18 Bit 4 */
570 bool morethan2_drives:1; /* Byte 18 Bit 5 */
571 bool bios_int:1; /* Byte 18 Bit 6 */
572 bool floptical:1; /* Byte 19 Bit 7 */
573 unsigned short dev_enabled; /* Bytes 19-20 */
574 unsigned short wide_ok; /* Bytes 21-22 */
575 unsigned short fast_ok; /* Bytes 23-24 */
576 unsigned short sync_ok; /* Bytes 25-26 */
577 unsigned short discon_ok; /* Bytes 27-28 */
578 unsigned short send_start_unit; /* Bytes 29-30 */
579 unsigned short ignore_bios_scan; /* Bytes 31-32 */
580 unsigned char pci_int_pin:2; /* Byte 33 Bits 0-1 */
581 unsigned char adapter_ioport:2; /* Byte 33 Bits 2-3 */
582 bool strict_rr_enabled:1; /* Byte 33 Bit 4 */
583 bool vesabus_33mhzplus:1; /* Byte 33 Bit 5 */
584 bool vesa_burst_write:1; /* Byte 33 Bit 6 */
585 bool vesa_burst_read:1; /* Byte 33 Bit 7 */
586 unsigned short ultra_ok; /* Bytes 34-35 */
587 unsigned int:32; /* Bytes 36-39 */
588 unsigned char:8; /* Byte 40 */
589 unsigned char autoscsi_maxlun; /* Byte 41 */
590 bool:1; /* Byte 42 Bit 0 */
591 bool scam_dominant:1; /* Byte 42 Bit 1 */
592 bool scam_enabled:1; /* Byte 42 Bit 2 */
593 bool scam_lev2:1; /* Byte 42 Bit 3 */
594 unsigned char:4; /* Byte 42 Bits 4-7 */
595 bool int13_exten:1; /* Byte 43 Bit 0 */
596 bool:1; /* Byte 43 Bit 1 */
597 bool cd_boot:1; /* Byte 43 Bit 2 */
598 unsigned char:5; /* Byte 43 Bits 3-7 */
599 unsigned char boot_id:4; /* Byte 44 Bits 0-3 */
600 unsigned char boot_ch:4; /* Byte 44 Bits 4-7 */
601 unsigned char force_scan_order:1; /* Byte 45 Bit 0 */
602 unsigned char:7; /* Byte 45 Bits 1-7 */
603 unsigned short nontagged_to_alt_ok; /* Bytes 46-47 */
604 unsigned short reneg_sync_on_check; /* Bytes 48-49 */
605 unsigned char rsvd[10]; /* Bytes 50-59 */
606 unsigned char manuf_diag[2]; /* Bytes 60-61 */
607 unsigned short cksum; /* Bytes 62-63 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608} PACKED;
609
610/*
611 Define the Host Adapter Local RAM Auto SCSI Byte 45 structure.
612*/
613
Khalid Aziz839cb992013-05-16 19:44:13 -0600614struct blogic_autoscsi_byte45 {
615 unsigned char force_scan_order:1; /* Bit 0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616 unsigned char:7; /* Bits 1-7 */
617};
618
619/*
620 Define the Host Adapter Local RAM BIOS Drive Map Byte structure.
621*/
622
Khalid Aziz839cb992013-05-16 19:44:13 -0600623#define BLOGIC_BIOS_DRVMAP 17
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624
Khalid Aziz839cb992013-05-16 19:44:13 -0600625struct blogic_bios_drvmap {
626 unsigned char tgt_idbit3:1; /* Bit 0 */
627 unsigned char:2; /* Bits 1-2 */
628 enum blogic_bios_diskgeometry diskgeom:2; /* Bits 3-4 */
629 unsigned char tgt_id:3; /* Bits 5-7 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630};
631
632/*
633 Define the Set CCB Format request type. Extended LUN Format CCBs are
634 necessary to support more than 8 Logical Units per Target Device.
635*/
636
Khalid Aziz839cb992013-05-16 19:44:13 -0600637enum blogic_setccb_fmt {
638 BLOGIC_LEGACY_LUN_CCB = 0,
639 BLOGIC_EXT_LUN_CCB = 1
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640} PACKED;
641
642/*
643 Define the Outgoing Mailbox Action Codes.
644*/
645
Khalid Aziz839cb992013-05-16 19:44:13 -0600646enum blogic_action {
647 BLOGIC_OUTBOX_FREE = 0x00,
648 BLOGIC_MBOX_START = 0x01,
649 BLOGIC_MBOX_ABORT = 0x02
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650} PACKED;
651
652
653/*
654 Define the Incoming Mailbox Completion Codes. The MultiMaster Firmware
655 only uses codes 0 - 4. The FlashPoint SCCB Manager has no mailboxes, so
656 completion codes are stored in the CCB; it only uses codes 1, 2, 4, and 5.
657*/
658
Khalid Aziz839cb992013-05-16 19:44:13 -0600659enum blogic_cmplt_code {
660 BLOGIC_INBOX_FREE = 0x00,
661 BLOGIC_CMD_COMPLETE_GOOD = 0x01,
662 BLOGIC_CMD_ABORT_BY_HOST = 0x02,
663 BLOGIC_CMD_NOTFOUND = 0x03,
664 BLOGIC_CMD_COMPLETE_ERROR = 0x04,
665 BLOGIC_INVALID_CCB = 0x05
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666} PACKED;
667
668/*
669 Define the Command Control Block (CCB) Opcodes.
670*/
671
Khalid Aziz839cb992013-05-16 19:44:13 -0600672enum blogic_ccb_opcode {
673 BLOGIC_INITIATOR_CCB = 0x00,
674 BLOGIC_TGT_CCB = 0x01,
675 BLOGIC_INITIATOR_CCB_SG = 0x02,
676 BLOGIC_INITIATOR_CCBB_RESIDUAL = 0x03,
677 BLOGIC_INITIATOR_CCB_SG_RESIDUAL = 0x04,
678 BLOGIC_BDR = 0x81
Linus Torvalds1da177e2005-04-16 15:20:36 -0700679} PACKED;
680
681
682/*
683 Define the CCB Data Direction Codes.
684*/
685
Khalid Aziz839cb992013-05-16 19:44:13 -0600686enum blogic_datadir {
687 BLOGIC_UNCHECKED_TX = 0,
688 BLOGIC_DATAIN_CHECKED = 1,
689 BLOGIC_DATAOUT_CHECKED = 2,
690 BLOGIC_NOTX = 3
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691};
692
693
694/*
695 Define the Host Adapter Status Codes. The MultiMaster Firmware does not
696 return status code 0x0C; it uses 0x12 for both overruns and underruns.
697*/
698
Khalid Aziz839cb992013-05-16 19:44:13 -0600699enum blogic_adapter_status {
700 BLOGIC_CMD_CMPLT_NORMAL = 0x00,
701 BLOGIC_LINK_CMD_CMPLT = 0x0A,
702 BLOGIC_LINK_CMD_CMPLT_FLAG = 0x0B,
703 BLOGIC_DATA_UNDERRUN = 0x0C,
704 BLOGIC_SELECT_TIMEOUT = 0x11,
705 BLOGIC_DATA_OVERRUN = 0x12,
706 BLOGIC_NOEXPECT_BUSFREE = 0x13,
707 BLOGIC_INVALID_BUSPHASE = 0x14,
708 BLOGIC_INVALID_OUTBOX_CODE = 0x15,
709 BLOGIC_INVALID_CMD_CODE = 0x16,
710 BLOGIC_LINKCCB_BADLUN = 0x17,
711 BLOGIC_BAD_CMD_PARAM = 0x1A,
712 BLOGIC_AUTOREQSENSE_FAIL = 0x1B,
713 BLOGIC_TAGQUEUE_REJECT = 0x1C,
714 BLOGIC_BAD_MSG_RCVD = 0x1D,
715 BLOGIC_HW_FAIL = 0x20,
716 BLOGIC_NORESPONSE_TO_ATN = 0x21,
717 BLOGIC_HW_RESET = 0x22,
718 BLOGIC_RST_FROM_OTHERDEV = 0x23,
719 BLOGIC_BAD_RECONNECT = 0x24,
720 BLOGIC_HW_BDR = 0x25,
721 BLOGIC_ABRT_QUEUE = 0x26,
722 BLOGIC_ADAPTER_SW_ERROR = 0x27,
723 BLOGIC_HW_TIMEOUT = 0x30,
724 BLOGIC_PARITY_ERR = 0x34
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725} PACKED;
726
727
728/*
729 Define the SCSI Target Device Status Codes.
730*/
731
Khalid Aziz839cb992013-05-16 19:44:13 -0600732enum blogic_tgt_status {
733 BLOGIC_OP_GOOD = 0x00,
734 BLOGIC_CHECKCONDITION = 0x02,
735 BLOGIC_DEVBUSY = 0x08
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736} PACKED;
737
738/*
739 Define the Queue Tag Codes.
740*/
741
Khalid Aziz839cb992013-05-16 19:44:13 -0600742enum blogic_queuetag {
743 BLOGIC_SIMPLETAG = 0,
744 BLOGIC_HEADTAG = 1,
745 BLOGIC_ORDEREDTAG = 2,
746 BLOGIC_RSVDTAG = 3
Linus Torvalds1da177e2005-04-16 15:20:36 -0700747};
748
749/*
750 Define the SCSI Command Descriptor Block (CDB).
751*/
752
Khalid Aziz839cb992013-05-16 19:44:13 -0600753#define BLOGIC_CDB_MAXLEN 12
Linus Torvalds1da177e2005-04-16 15:20:36 -0700754
755
756/*
757 Define the Scatter/Gather Segment structure required by the MultiMaster
758 Firmware Interface and the FlashPoint SCCB Manager.
759*/
760
Khalid Aziz839cb992013-05-16 19:44:13 -0600761struct blogic_sg_seg {
762 u32 segbytes; /* Bytes 0-3 */
763 u32 segdata; /* Bytes 4-7 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764};
765
766/*
767 Define the Driver CCB Status Codes.
768*/
769
Khalid Aziz839cb992013-05-16 19:44:13 -0600770enum blogic_ccb_status {
771 BLOGIC_CCB_FREE = 0,
772 BLOGIC_CCB_ACTIVE = 1,
773 BLOGIC_CCB_COMPLETE = 2,
774 BLOGIC_CCB_RESET = 3
Linus Torvalds1da177e2005-04-16 15:20:36 -0700775} PACKED;
776
777
778/*
779 Define the 32 Bit Mode Command Control Block (CCB) structure. The first 40
780 bytes are defined by and common to both the MultiMaster Firmware and the
781 FlashPoint SCCB Manager. The next 60 bytes are defined by the FlashPoint
782 SCCB Manager. The remaining components are defined by the Linux BusLogic
783 Driver. Extended LUN Format CCBs differ from Legacy LUN Format 32 Bit Mode
784 CCBs only in having the TagEnable and QueueTag fields moved from byte 17 to
785 byte 1, and the Logical Unit field in byte 17 expanded to 6 bits. In theory,
786 Extended LUN Format CCBs can support up to 64 Logical Units, but in practice
787 many devices will respond improperly to Logical Units between 32 and 63, and
788 the SCSI-2 specification defines Bit 5 as LUNTAR. Extended LUN Format CCBs
789 are used by recent versions of the MultiMaster Firmware, as well as by the
790 FlashPoint SCCB Manager; the FlashPoint SCCB Manager only supports 32 Logical
791 Units. Since 64 Logical Units are unlikely to be needed in practice, and
792 since they are problematic for the above reasons, and since limiting them to
793 5 bits simplifies the CCB structure definition, this driver only supports
794 32 Logical Units per Target Device.
795*/
796
Khalid Aziz839cb992013-05-16 19:44:13 -0600797struct blogic_ccb {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798 /*
799 MultiMaster Firmware and FlashPoint SCCB Manager Common Portion.
800 */
Khalid Aziz839cb992013-05-16 19:44:13 -0600801 enum blogic_ccb_opcode opcode; /* Byte 0 */
802 unsigned char:3; /* Byte 1 Bits 0-2 */
803 enum blogic_datadir datadir:2; /* Byte 1 Bits 3-4 */
804 bool tag_enable:1; /* Byte 1 Bit 5 */
805 enum blogic_queuetag queuetag:2; /* Byte 1 Bits 6-7 */
806 unsigned char cdblen; /* Byte 2 */
807 unsigned char sense_datalen; /* Byte 3 */
808 u32 datalen; /* Bytes 4-7 */
Matt Wang56f39612021-05-11 03:04:37 +0000809 u32 data; /* Bytes 8-11 */
Khalid Aziz839cb992013-05-16 19:44:13 -0600810 unsigned char:8; /* Byte 12 */
811 unsigned char:8; /* Byte 13 */
812 enum blogic_adapter_status adapter_status; /* Byte 14 */
813 enum blogic_tgt_status tgt_status; /* Byte 15 */
814 unsigned char tgt_id; /* Byte 16 */
815 unsigned char lun:5; /* Byte 17 Bits 0-4 */
816 bool legacytag_enable:1; /* Byte 17 Bit 5 */
817 enum blogic_queuetag legacy_tag:2; /* Byte 17 Bits 6-7 */
818 unsigned char cdb[BLOGIC_CDB_MAXLEN]; /* Bytes 18-29 */
819 unsigned char:8; /* Byte 30 */
820 unsigned char:8; /* Byte 31 */
Khalid Aziz391e2f22013-05-16 19:44:14 -0600821 u32 rsvd_int; /* Bytes 32-35 */
Khalid Aziz839cb992013-05-16 19:44:13 -0600822 u32 sensedata; /* Bytes 36-39 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700823 /*
824 FlashPoint SCCB Manager Defined Portion.
825 */
Khalid Aziz839cb992013-05-16 19:44:13 -0600826 void (*callback) (struct blogic_ccb *); /* Bytes 40-43 */
827 u32 base_addr; /* Bytes 44-47 */
828 enum blogic_cmplt_code comp_code; /* Byte 48 */
Matthew Wilcox78b4b052008-03-13 06:55:08 -0600829#ifdef CONFIG_SCSI_FLASHPOINT
Khalid Aziz839cb992013-05-16 19:44:13 -0600830 unsigned char:8; /* Byte 49 */
Khalid Aziz391e2f22013-05-16 19:44:14 -0600831 u16 os_flags; /* Bytes 50-51 */
832 unsigned char private[24]; /* Bytes 52-99 */
833 void *rsvd1;
834 void *rsvd2;
835 unsigned char private2[16];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700836#endif
837 /*
838 BusLogic Linux Driver Defined Portion.
839 */
Khalid Aziz839cb992013-05-16 19:44:13 -0600840 dma_addr_t allocgrp_head;
841 unsigned int allocgrp_size;
842 u32 dma_handle;
843 enum blogic_ccb_status status;
844 unsigned long serial;
845 struct scsi_cmnd *command;
846 struct blogic_adapter *adapter;
847 struct blogic_ccb *next;
848 struct blogic_ccb *next_all;
849 struct blogic_sg_seg sglist[BLOGIC_SG_LIMIT];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700850};
851
852/*
853 Define the 32 Bit Mode Outgoing Mailbox structure.
854*/
855
Khalid Aziz839cb992013-05-16 19:44:13 -0600856struct blogic_outbox {
857 u32 ccb; /* Bytes 0-3 */
Khalid Aziz391e2f22013-05-16 19:44:14 -0600858 u32:24; /* Bytes 4-6 */
Khalid Aziz839cb992013-05-16 19:44:13 -0600859 enum blogic_action action; /* Byte 7 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700860};
861
862/*
863 Define the 32 Bit Mode Incoming Mailbox structure.
864*/
865
Khalid Aziz839cb992013-05-16 19:44:13 -0600866struct blogic_inbox {
Khalid Aziz391e2f22013-05-16 19:44:14 -0600867 u32 ccb; /* Bytes 0-3 */
Khalid Aziz839cb992013-05-16 19:44:13 -0600868 enum blogic_adapter_status adapter_status; /* Byte 4 */
Khalid Aziz391e2f22013-05-16 19:44:14 -0600869 enum blogic_tgt_status tgt_status; /* Byte 5 */
870 unsigned char:8; /* Byte 6 */
871 enum blogic_cmplt_code comp_code; /* Byte 7 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700872};
873
874
875/*
876 Define the BusLogic Driver Options structure.
877*/
878
Khalid Aziz839cb992013-05-16 19:44:13 -0600879struct blogic_drvr_options {
880 unsigned short tagq_ok;
881 unsigned short tagq_ok_mask;
882 unsigned short bus_settle_time;
883 unsigned short stop_tgt_inquiry;
884 unsigned char common_qdepth;
885 unsigned char qdepth[BLOGIC_MAXDEV];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700886};
887
888/*
889 Define the Host Adapter Target Flags structure.
890*/
891
Khalid Aziz839cb992013-05-16 19:44:13 -0600892struct blogic_tgt_flags {
893 bool tgt_exists:1;
894 bool tagq_ok:1;
895 bool wide_ok:1;
896 bool tagq_active:1;
897 bool wide_active:1;
898 bool cmd_good:1;
899 bool tgt_info_in:1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700900};
901
902/*
903 Define the Host Adapter Target Statistics structure.
904*/
905
Khalid Aziz839cb992013-05-16 19:44:13 -0600906#define BLOGIC_SZ_BUCKETS 10
Linus Torvalds1da177e2005-04-16 15:20:36 -0700907
Khalid Aziz839cb992013-05-16 19:44:13 -0600908struct blogic_tgt_stats {
909 unsigned int cmds_tried;
910 unsigned int cmds_complete;
911 unsigned int read_cmds;
912 unsigned int write_cmds;
913 struct blogic_byte_count bytesread;
914 struct blogic_byte_count byteswritten;
915 unsigned int read_sz_buckets[BLOGIC_SZ_BUCKETS];
916 unsigned int write_sz_buckets[BLOGIC_SZ_BUCKETS];
917 unsigned short aborts_request;
918 unsigned short aborts_tried;
919 unsigned short aborts_done;
920 unsigned short bdr_request;
921 unsigned short bdr_tried;
922 unsigned short bdr_done;
Colin Ian King209610652017-02-21 16:27:11 +0000923 unsigned short adapter_reset_req;
Khalid Aziz839cb992013-05-16 19:44:13 -0600924 unsigned short adapter_reset_attempt;
925 unsigned short adapter_reset_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700926};
927
928/*
929 Define the FlashPoint Card Handle data type.
930*/
931
Khalid Aziz391e2f22013-05-16 19:44:14 -0600932#define FPOINT_BADCARD_HANDLE 0xFFFFFFFFL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700933
934
935/*
936 Define the FlashPoint Information structure. This structure is defined
937 by the FlashPoint SCCB Manager.
938*/
939
Khalid Aziz839cb992013-05-16 19:44:13 -0600940struct fpoint_info {
941 u32 base_addr; /* Bytes 0-3 */
942 bool present; /* Byte 4 */
943 unsigned char irq_ch; /* Byte 5 */
944 unsigned char scsi_id; /* Byte 6 */
945 unsigned char scsi_lun; /* Byte 7 */
Khalid Aziz391e2f22013-05-16 19:44:14 -0600946 u16 fw_rev; /* Bytes 8-9 */
947 u16 sync_ok; /* Bytes 10-11 */
948 u16 fast_ok; /* Bytes 12-13 */
949 u16 ultra_ok; /* Bytes 14-15 */
950 u16 discon_ok; /* Bytes 16-17 */
951 u16 wide_ok; /* Bytes 18-19 */
Khalid Aziz839cb992013-05-16 19:44:13 -0600952 bool parity:1; /* Byte 20 Bit 0 */
953 bool wide:1; /* Byte 20 Bit 1 */
954 bool softreset:1; /* Byte 20 Bit 2 */
955 bool ext_trans_enable:1; /* Byte 20 Bit 3 */
956 bool low_term:1; /* Byte 20 Bit 4 */
957 bool high_term:1; /* Byte 20 Bit 5 */
958 bool report_underrun:1; /* Byte 20 Bit 6 */
959 bool scam_enabled:1; /* Byte 20 Bit 7 */
960 bool scam_lev2:1; /* Byte 21 Bit 0 */
961 unsigned char:7; /* Byte 21 Bits 1-7 */
962 unsigned char family; /* Byte 22 */
963 unsigned char bus_type; /* Byte 23 */
964 unsigned char model[3]; /* Bytes 24-26 */
965 unsigned char relative_cardnum; /* Byte 27 */
966 unsigned char rsvd[4]; /* Bytes 28-31 */
Khalid Aziz391e2f22013-05-16 19:44:14 -0600967 u32 os_rsvd; /* Bytes 32-35 */
Khalid Aziz839cb992013-05-16 19:44:13 -0600968 unsigned char translation_info[4]; /* Bytes 36-39 */
Khalid Aziz391e2f22013-05-16 19:44:14 -0600969 u32 rsvd2[5]; /* Bytes 40-59 */
970 u32 sec_range; /* Bytes 60-63 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700971};
972
973/*
974 Define the BusLogic Driver Host Adapter structure.
975*/
976
Khalid Aziz839cb992013-05-16 19:44:13 -0600977struct blogic_adapter {
978 struct Scsi_Host *scsi_host;
979 struct pci_dev *pci_device;
980 enum blogic_adapter_type adapter_type;
981 enum blogic_adapter_bus_type adapter_bus_type;
982 unsigned long io_addr;
983 unsigned long pci_addr;
984 unsigned short addr_count;
985 unsigned char host_no;
986 unsigned char model[9];
987 unsigned char fw_ver[6];
988 unsigned char full_model[18];
989 unsigned char bus;
990 unsigned char dev;
991 unsigned char irq_ch;
Khalid Aziz839cb992013-05-16 19:44:13 -0600992 unsigned char scsi_id;
993 bool irq_acquired:1;
Khalid Aziz839cb992013-05-16 19:44:13 -0600994 bool ext_trans_enable:1;
995 bool parity:1;
996 bool reset_enabled:1;
997 bool level_int:1;
998 bool wide:1;
999 bool differential:1;
1000 bool scam:1;
1001 bool ultra:1;
1002 bool ext_lun:1;
1003 bool terminfo_valid:1;
1004 bool low_term:1;
1005 bool high_term:1;
Khalid Aziz839cb992013-05-16 19:44:13 -06001006 bool strict_rr:1;
1007 bool scam_enabled:1;
1008 bool scam_lev2:1;
1009 bool adapter_initd:1;
1010 bool adapter_extreset:1;
1011 bool adapter_intern_err:1;
1012 bool processing_ccbs;
1013 volatile bool adapter_cmd_complete;
1014 unsigned short adapter_sglimit;
1015 unsigned short drvr_sglimit;
1016 unsigned short maxdev;
1017 unsigned short maxlun;
1018 unsigned short mbox_count;
1019 unsigned short initccbs;
1020 unsigned short inc_ccbs;
1021 unsigned short alloc_ccbs;
1022 unsigned short drvr_qdepth;
1023 unsigned short adapter_qdepth;
1024 unsigned short untag_qdepth;
1025 unsigned short common_qdepth;
1026 unsigned short bus_settle_time;
1027 unsigned short sync_ok;
1028 unsigned short fast_ok;
1029 unsigned short ultra_ok;
1030 unsigned short wide_ok;
1031 unsigned short discon_ok;
1032 unsigned short tagq_ok;
1033 unsigned short ext_resets;
1034 unsigned short adapter_intern_errors;
1035 unsigned short tgt_count;
1036 unsigned short msgbuflen;
1037 u32 bios_addr;
1038 struct blogic_drvr_options *drvr_opts;
1039 struct fpoint_info fpinfo;
Khalid Aziz391e2f22013-05-16 19:44:14 -06001040 void *cardhandle;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001041 struct list_head host_list;
Khalid Aziz839cb992013-05-16 19:44:13 -06001042 struct blogic_ccb *all_ccbs;
1043 struct blogic_ccb *free_ccbs;
1044 struct blogic_ccb *firstccb;
1045 struct blogic_ccb *lastccb;
1046 struct blogic_ccb *bdr_pend[BLOGIC_MAXDEV];
1047 struct blogic_tgt_flags tgt_flags[BLOGIC_MAXDEV];
1048 unsigned char qdepth[BLOGIC_MAXDEV];
1049 unsigned char sync_period[BLOGIC_MAXDEV];
1050 unsigned char sync_offset[BLOGIC_MAXDEV];
1051 unsigned char active_cmds[BLOGIC_MAXDEV];
1052 unsigned int cmds_since_rst[BLOGIC_MAXDEV];
1053 unsigned long last_seqpoint[BLOGIC_MAXDEV];
1054 unsigned long last_resettried[BLOGIC_MAXDEV];
1055 unsigned long last_resetdone[BLOGIC_MAXDEV];
1056 struct blogic_outbox *first_outbox;
1057 struct blogic_outbox *last_outbox;
1058 struct blogic_outbox *next_outbox;
1059 struct blogic_inbox *first_inbox;
1060 struct blogic_inbox *last_inbox;
1061 struct blogic_inbox *next_inbox;
1062 struct blogic_tgt_stats tgt_stats[BLOGIC_MAXDEV];
1063 unsigned char *mbox_space;
1064 dma_addr_t mbox_space_handle;
1065 unsigned int mbox_sz;
1066 unsigned long ccb_offset;
1067 char msgbuf[BLOGIC_MSGBUF_SIZE];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001068};
1069
1070/*
1071 Define a structure for the BIOS Disk Parameters.
1072*/
1073
Khalid Aziz839cb992013-05-16 19:44:13 -06001074struct bios_diskparam {
1075 int heads;
1076 int sectors;
1077 int cylinders;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001078};
1079
1080/*
1081 Define a structure for the SCSI Inquiry command results.
1082*/
1083
Khalid Aziz839cb992013-05-16 19:44:13 -06001084struct scsi_inquiry {
1085 unsigned char devtype:5; /* Byte 0 Bits 0-4 */
1086 unsigned char dev_qual:3; /* Byte 0 Bits 5-7 */
1087 unsigned char dev_modifier:7; /* Byte 1 Bits 0-6 */
1088 bool rmb:1; /* Byte 1 Bit 7 */
1089 unsigned char ansi_ver:3; /* Byte 2 Bits 0-2 */
1090 unsigned char ecma_ver:3; /* Byte 2 Bits 3-5 */
1091 unsigned char iso_ver:2; /* Byte 2 Bits 6-7 */
1092 unsigned char resp_fmt:4; /* Byte 3 Bits 0-3 */
1093 unsigned char:2; /* Byte 3 Bits 4-5 */
1094 bool TrmIOP:1; /* Byte 3 Bit 6 */
1095 bool AENC:1; /* Byte 3 Bit 7 */
1096 unsigned char addl_len; /* Byte 4 */
1097 unsigned char:8; /* Byte 5 */
1098 unsigned char:8; /* Byte 6 */
1099 bool SftRe:1; /* Byte 7 Bit 0 */
1100 bool CmdQue:1; /* Byte 7 Bit 1 */
1101 bool:1; /* Byte 7 Bit 2 */
1102 bool linked:1; /* Byte 7 Bit 3 */
1103 bool sync:1; /* Byte 7 Bit 4 */
1104 bool WBus16:1; /* Byte 7 Bit 5 */
1105 bool WBus32:1; /* Byte 7 Bit 6 */
1106 bool RelAdr:1; /* Byte 7 Bit 7 */
1107 unsigned char vendor[8]; /* Bytes 8-15 */
1108 unsigned char product[16]; /* Bytes 16-31 */
1109 unsigned char product_rev[4]; /* Bytes 32-35 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001110};
1111
1112
1113/*
1114 Define functions to provide an abstraction for reading and writing the
1115 Host Adapter I/O Registers.
1116*/
1117
Khalid Aziz839cb992013-05-16 19:44:13 -06001118static inline void blogic_busreset(struct blogic_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001119{
Khalid Aziz839cb992013-05-16 19:44:13 -06001120 union blogic_cntrl_reg cr;
1121 cr.all = 0;
1122 cr.cr.bus_reset = true;
1123 outb(cr.all, adapter->io_addr + BLOGIC_CNTRL_REG);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001124}
1125
Khalid Aziz839cb992013-05-16 19:44:13 -06001126static inline void blogic_intreset(struct blogic_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001127{
Khalid Aziz839cb992013-05-16 19:44:13 -06001128 union blogic_cntrl_reg cr;
1129 cr.all = 0;
1130 cr.cr.int_reset = true;
1131 outb(cr.all, adapter->io_addr + BLOGIC_CNTRL_REG);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001132}
1133
Khalid Aziz839cb992013-05-16 19:44:13 -06001134static inline void blogic_softreset(struct blogic_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001135{
Khalid Aziz839cb992013-05-16 19:44:13 -06001136 union blogic_cntrl_reg cr;
1137 cr.all = 0;
1138 cr.cr.soft_reset = true;
1139 outb(cr.all, adapter->io_addr + BLOGIC_CNTRL_REG);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001140}
1141
Khalid Aziz839cb992013-05-16 19:44:13 -06001142static inline void blogic_hardreset(struct blogic_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001143{
Khalid Aziz839cb992013-05-16 19:44:13 -06001144 union blogic_cntrl_reg cr;
1145 cr.all = 0;
1146 cr.cr.hard_reset = true;
1147 outb(cr.all, adapter->io_addr + BLOGIC_CNTRL_REG);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001148}
1149
Khalid Aziz839cb992013-05-16 19:44:13 -06001150static inline unsigned char blogic_rdstatus(struct blogic_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001151{
Khalid Aziz839cb992013-05-16 19:44:13 -06001152 return inb(adapter->io_addr + BLOGIC_STATUS_REG);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001153}
1154
Khalid Aziz839cb992013-05-16 19:44:13 -06001155static inline void blogic_setcmdparam(struct blogic_adapter *adapter,
1156 unsigned char value)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001157{
Khalid Aziz839cb992013-05-16 19:44:13 -06001158 outb(value, adapter->io_addr + BLOGIC_CMD_PARM_REG);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001159}
1160
Khalid Aziz839cb992013-05-16 19:44:13 -06001161static inline unsigned char blogic_rddatain(struct blogic_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001162{
Khalid Aziz839cb992013-05-16 19:44:13 -06001163 return inb(adapter->io_addr + BLOGIC_DATAIN_REG);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001164}
1165
Khalid Aziz839cb992013-05-16 19:44:13 -06001166static inline unsigned char blogic_rdint(struct blogic_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001167{
Khalid Aziz839cb992013-05-16 19:44:13 -06001168 return inb(adapter->io_addr + BLOGIC_INT_REG);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001169}
1170
Khalid Aziz839cb992013-05-16 19:44:13 -06001171static inline unsigned char blogic_rdgeom(struct blogic_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001172{
Khalid Aziz839cb992013-05-16 19:44:13 -06001173 return inb(adapter->io_addr + BLOGIC_GEOMETRY_REG);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001174}
1175
1176/*
Khalid Aziz839cb992013-05-16 19:44:13 -06001177 blogic_execmbox issues an Execute Mailbox Command, which
Linus Torvalds1da177e2005-04-16 15:20:36 -07001178 notifies the Host Adapter that an entry has been made in an Outgoing
1179 Mailbox.
1180*/
1181
Khalid Aziz839cb992013-05-16 19:44:13 -06001182static inline void blogic_execmbox(struct blogic_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001183{
Khalid Aziz839cb992013-05-16 19:44:13 -06001184 blogic_setcmdparam(adapter, BLOGIC_EXEC_MBOX_CMD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001185}
1186
1187/*
Khalid Aziz839cb992013-05-16 19:44:13 -06001188 blogic_delay waits for Seconds to elapse.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001189*/
1190
Khalid Aziz839cb992013-05-16 19:44:13 -06001191static inline void blogic_delay(int seconds)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001192{
Khalid Aziz839cb992013-05-16 19:44:13 -06001193 mdelay(1000 * seconds);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001194}
1195
1196/*
Khalid Aziz839cb992013-05-16 19:44:13 -06001197 virt_to_32bit_virt maps between Kernel Virtual Addresses and
Linus Torvalds1da177e2005-04-16 15:20:36 -07001198 32 bit Kernel Virtual Addresses. This avoids compilation warnings
1199 on 64 bit architectures.
1200*/
1201
Khalid Aziz839cb992013-05-16 19:44:13 -06001202static inline u32 virt_to_32bit_virt(void *virt_addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001203{
Khalid Aziz839cb992013-05-16 19:44:13 -06001204 return (u32) (unsigned long) virt_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001205}
1206
1207/*
Khalid Aziz839cb992013-05-16 19:44:13 -06001208 blogic_inc_count increments counter by 1, stopping at
Linus Torvalds1da177e2005-04-16 15:20:36 -07001209 65535 rather than wrapping around to 0.
1210*/
1211
Khalid Aziz839cb992013-05-16 19:44:13 -06001212static inline void blogic_inc_count(unsigned short *count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001213{
Khalid Aziz839cb992013-05-16 19:44:13 -06001214 if (*count < 65535)
1215 (*count)++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001216}
1217
1218/*
Khalid Aziz839cb992013-05-16 19:44:13 -06001219 blogic_addcount increments Byte Counter by Amount.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001220*/
1221
Khalid Aziz839cb992013-05-16 19:44:13 -06001222static inline void blogic_addcount(struct blogic_byte_count *bytecount,
1223 unsigned int amount)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001224{
Khalid Aziz839cb992013-05-16 19:44:13 -06001225 bytecount->units += amount;
1226 if (bytecount->units > 999999999) {
1227 bytecount->units -= 1000000000;
1228 bytecount->billions++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001229 }
1230}
1231
1232/*
Khalid Aziz839cb992013-05-16 19:44:13 -06001233 blogic_incszbucket increments the Bucket for Amount.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001234*/
1235
Khalid Aziz839cb992013-05-16 19:44:13 -06001236static inline void blogic_incszbucket(unsigned int *cmdsz_buckets,
1237 unsigned int amount)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001238{
Khalid Aziz839cb992013-05-16 19:44:13 -06001239 int index = 0;
1240 if (amount < 8 * 1024) {
1241 if (amount < 2 * 1024)
1242 index = (amount < 1 * 1024 ? 0 : 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001243 else
Khalid Aziz839cb992013-05-16 19:44:13 -06001244 index = (amount < 4 * 1024 ? 2 : 3);
1245 } else if (amount < 128 * 1024) {
1246 if (amount < 32 * 1024)
1247 index = (amount < 16 * 1024 ? 4 : 5);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001248 else
Khalid Aziz839cb992013-05-16 19:44:13 -06001249 index = (amount < 64 * 1024 ? 6 : 7);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001250 } else
Khalid Aziz839cb992013-05-16 19:44:13 -06001251 index = (amount < 256 * 1024 ? 8 : 9);
1252 cmdsz_buckets[index]++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001253}
1254
1255/*
1256 Define the version number of the FlashPoint Firmware (SCCB Manager).
1257*/
1258
Khalid Aziz839cb992013-05-16 19:44:13 -06001259#define FLASHPOINT_FW_VER "5.02"
Linus Torvalds1da177e2005-04-16 15:20:36 -07001260
1261/*
1262 Define the possible return values from FlashPoint_HandleInterrupt.
1263*/
1264
Khalid Aziz839cb992013-05-16 19:44:13 -06001265#define FPOINT_NORMAL_INT 0x00
1266#define FPOINT_INTERN_ERR 0xFE
1267#define FPOINT_EXT_RESET 0xFF
Linus Torvalds1da177e2005-04-16 15:20:36 -07001268
1269/*
1270 Define prototypes for the forward referenced BusLogic Driver
1271 Internal Functions.
1272*/
1273
Khalid Aziz839cb992013-05-16 19:44:13 -06001274static const char *blogic_drvr_info(struct Scsi_Host *);
1275static int blogic_qcmd(struct Scsi_Host *h, struct scsi_cmnd *);
1276static int blogic_diskparam(struct scsi_device *, struct block_device *, sector_t, int *);
1277static int blogic_slaveconfig(struct scsi_device *);
1278static void blogic_qcompleted_ccb(struct blogic_ccb *);
1279static irqreturn_t blogic_inthandler(int, void *);
1280static int blogic_resetadapter(struct blogic_adapter *, bool hard_reset);
1281static void blogic_msg(enum blogic_msglevel, char *, struct blogic_adapter *, ...);
1282static int __init blogic_setup(char *);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001283
1284#endif /* _BUSLOGIC_H */