2 * u14-34f.c - Low-level driver for UltraStor 14F/34F SCSI host adapters.
4 * 01 Nov 2000 Rev. 6.02 for linux 2.4.0-test11
5 * + Removed old scsi error handling support.
6 * + The obsolete boot option flag eh:n is silently ignored.
7 * + Removed error messages while a disk drive is powered up at
9 * + Improved boot messages: all tagged capable device are
10 * indicated as "tagged".
12 * 16 Sep 1999 Rev. 5.11 for linux 2.2.12 and 2.3.18
13 * + Updated to the new __setup interface for boot command line options.
14 * + When loaded as a module, accepts the new parameter boot_options
15 * which value is a string with the same format of the kernel boot
16 * command line options. A valid example is:
17 * modprobe u14-34f boot_options=\"0x230,0x340,lc:y,mq:4\"
19 * 22 Jul 1999 Rev. 5.00 for linux 2.2.10 and 2.3.11
20 * + Removed pre-2.2 source code compatibility.
22 * 26 Jul 1998 Rev. 4.33 for linux 2.0.35 and 2.1.111
23 * Added command line option (et:[y|n]) to use the existing
24 * translation (returned by scsicam_bios_param) as disk geometry.
25 * The default is et:n, which uses the disk geometry jumpered
27 * The default value et:n is compatible with all previous revisions
30 * 28 May 1998 Rev. 4.32 for linux 2.0.33 and 2.1.104
31 * Increased busy timeout from 10 msec. to 200 msec. while
32 * processing interrupts.
34 * 18 May 1998 Rev. 4.31 for linux 2.0.33 and 2.1.102
35 * Improved abort handling during the eh recovery process.
37 * 13 May 1998 Rev. 4.30 for linux 2.0.33 and 2.1.101
38 * The driver is now fully SMP safe, including the
39 * abort and reset routines.
40 * Added command line options (eh:[y|n]) to choose between
41 * new_eh_code and the old scsi code.
42 * If linux version >= 2.1.101 the default is eh:y, while the eh
43 * option is ignored for previous releases and the old scsi code
46 * 18 Apr 1998 Rev. 4.20 for linux 2.0.33 and 2.1.97
47 * Reworked interrupt handler.
49 * 11 Apr 1998 rev. 4.05 for linux 2.0.33 and 2.1.95
50 * Major reliability improvement: when a batch with overlapping
51 * requests is detected, requests are queued one at a time
52 * eliminating any possible board or drive reordering.
54 * 10 Apr 1998 rev. 4.04 for linux 2.0.33 and 2.1.95
55 * Improved SMP support (if linux version >= 2.1.95).
57 * 9 Apr 1998 rev. 4.03 for linux 2.0.33 and 2.1.94
58 * Performance improvement: when sequential i/o is detected,
59 * always use direct sort instead of reverse sort.
61 * 4 Apr 1998 rev. 4.02 for linux 2.0.33 and 2.1.92
62 * io_port is now unsigned long.
64 * 17 Mar 1998 rev. 4.01 for linux 2.0.33 and 2.1.88
65 * Use new scsi error handling code (if linux version >= 2.1.88).
66 * Use new interrupt code.
68 * 12 Sep 1997 rev. 3.11 for linux 2.0.30 and 2.1.55
69 * Use of udelay inside the wait loops to avoid timeout
70 * problems with fast cpus.
71 * Removed check about useless calls to the interrupt service
72 * routine (reported on SMP systems only).
73 * At initialization time "sorted/unsorted" is displayed instead
74 * of "linked/unlinked" to reinforce the fact that "linking" is
75 * nothing but "elevator sorting" in the actual implementation.
77 * 17 May 1997 rev. 3.10 for linux 2.0.30 and 2.1.38
78 * Use of serial_number_at_timeout in abort and reset processing.
79 * Use of the __initfunc and __initdata macro in setup code.
80 * Minor cleanups in the list_statistics code.
82 * 24 Feb 1997 rev. 3.00 for linux 2.0.29 and 2.1.26
83 * When loading as a module, parameter passing is now supported
84 * both in 2.0 and in 2.1 style.
85 * Fixed data transfer direction for some SCSI opcodes.
86 * Immediate acknowledge to request sense commands.
87 * Linked commands to each disk device are now reordered by elevator
88 * sorting. Rare cases in which reordering of write requests could
89 * cause wrong results are managed.
91 * 18 Jan 1997 rev. 2.60 for linux 2.1.21 and 2.0.28
92 * Added command line options to enable/disable linked commands
93 * (lc:[y|n]), old firmware support (of:[y|n]) and to set the max
94 * queue depth (mq:xx). Default is "u14-34f=lc:n,of:n,mq:8".
95 * Improved command linking.
97 * 8 Jan 1997 rev. 2.50 for linux 2.1.20 and 2.0.27
98 * Added linked command support.
100 * 3 Dec 1996 rev. 2.40 for linux 2.1.14 and 2.0.27
101 * Added queue depth adjustment.
103 * 22 Nov 1996 rev. 2.30 for linux 2.1.12 and 2.0.26
104 * The list of i/o ports to be probed can be overwritten by the
105 * "u14-34f=port0,port1,...." boot command line option.
106 * Scatter/gather lists are now allocated by a number of kmalloc
107 * calls, in order to avoid the previous size limit of 64Kb.
109 * 16 Nov 1996 rev. 2.20 for linux 2.1.10 and 2.0.25
110 * Added multichannel support.
112 * 27 Sep 1996 rev. 2.12 for linux 2.1.0
113 * Portability cleanups (virtual/bus addressing, little/big endian
116 * 09 Jul 1996 rev. 2.11 for linux 2.0.4
117 * "Data over/under-run" no longer implies a redo on all targets.
118 * Number of internal retries is now limited.
120 * 16 Apr 1996 rev. 2.10 for linux 1.3.90
121 * New argument "reset_flags" to the reset routine.
123 * 21 Jul 1995 rev. 2.02 for linux 1.3.11
124 * Fixed Data Transfer Direction for some SCSI commands.
126 * 13 Jun 1995 rev. 2.01 for linux 1.2.10
127 * HAVE_OLD_UX4F_FIRMWARE should be defined for U34F boards when
128 * the firmware prom is not the latest one (28008-006).
130 * 11 Mar 1995 rev. 2.00 for linux 1.2.0
131 * Fixed a bug which prevented media change detection for removable
134 * 23 Feb 1995 rev. 1.18 for linux 1.1.94
135 * Added a check for scsi_register returning NULL.
137 * 11 Feb 1995 rev. 1.17 for linux 1.1.91
138 * U14F qualified to run with 32 sglists.
139 * Now DEBUG_RESET is disabled by default.
141 * 9 Feb 1995 rev. 1.16 for linux 1.1.90
142 * Use host->wish_block instead of host->block.
144 * 8 Feb 1995 rev. 1.15 for linux 1.1.89
145 * Cleared target_time_out counter while performing a reset.
147 * 28 Jan 1995 rev. 1.14 for linux 1.1.86
148 * Added module support.
149 * Log and do a retry when a disk drive returns a target status
150 * different from zero on a recovered error.
151 * Auto detects if U14F boards have an old firmware revision.
152 * Max number of scatter/gather lists set to 16 for all boards
153 * (most installation run fine using 33 sglists, while other
154 * has problems when using more then 16).
156 * 16 Jan 1995 rev. 1.13 for linux 1.1.81
157 * Display a message if check_region detects a port address
160 * 15 Dec 1994 rev. 1.12 for linux 1.1.74
161 * The host->block flag is set for all the detected ISA boards.
163 * 30 Nov 1994 rev. 1.11 for linux 1.1.68
164 * Redo i/o on target status CHECK_CONDITION for TYPE_DISK only.
165 * Added optional support for using a single board at a time.
167 * 14 Nov 1994 rev. 1.10 for linux 1.1.63
169 * 28 Oct 1994 rev. 1.09 for linux 1.1.58 Final BETA release.
170 * 16 Jul 1994 rev. 1.00 for linux 1.1.29 Initial ALPHA release.
172 * This driver is a total replacement of the original UltraStor
173 * scsi driver, but it supports ONLY the 14F and 34F boards.
174 * It can be configured in the same kernel in which the original
175 * ultrastor driver is configured to allow the original U24F
178 * Multiple U14F and/or U34F host adapters are supported.
180 * Copyright (C) 1994-2000 Dario Ballabio (ballabio_dario@emc.com)
182 * Alternate email: dario.ballabio@inwind.it, dario.ballabio@tiscalinet.it
184 * Redistribution and use in source and binary forms, with or without
185 * modification, are permitted provided that redistributions of source
186 * code retain the above copyright notice and this comment without
189 * WARNING: if your 14/34F board has an old firmware revision (see below)
190 * you must change "#undef" into "#define" in the following
193 #undef HAVE_OLD_UX4F_FIRMWARE
195 * The UltraStor 14F, 24F, and 34F are a family of intelligent, high
196 * performance SCSI-2 host adapters.
197 * Here is the scoop on the various models:
199 * 14F - ISA first-party DMA HA with floppy support and WD1003 emulation.
200 * 24F - EISA Bus Master HA with floppy support and WD1003 emulation.
201 * 34F - VESA Local-Bus Bus Master HA (no WD1003 emulation).
203 * This code has been tested with up to two U14F boards, using both
204 * firmware 28004-005/38004-004 (BIOS rev. 2.00) and the latest firmware
205 * 28004-006/38004-005 (BIOS rev. 2.01).
207 * The latest firmware is required in order to get reliable operations when
208 * clustering is enabled. ENABLE_CLUSTERING provides a performance increase
209 * up to 50% on sequential access.
211 * Since the Scsi_Host_Template structure is shared among all 14F and 34F,
212 * the last setting of use_clustering is in effect for all of these boards.
214 * Here a sample configuration using two U14F boards:
216 U14F0: ISA 0x330, BIOS 0xc8000, IRQ 11, DMA 5, SG 32, MB 16, of:n, lc:y, mq:8.
217 U14F1: ISA 0x340, BIOS 0x00000, IRQ 10, DMA 6, SG 32, MB 16, of:n, lc:y, mq:8.
219 * The boot controller must have its BIOS enabled, while other boards can
220 * have their BIOS disabled, or enabled to an higher address.
221 * Boards are named Ux4F0, Ux4F1..., according to the port address order in
222 * the io_port[] array.
224 * The following facts are based on real testing results (not on
225 * documentation) on the above U14F board.
227 * - The U14F board should be jumpered for bus on time less or equal to 7
228 * microseconds, while the default is 11 microseconds. This is order to
229 * get acceptable performance while using floppy drive and hard disk
230 * together. The jumpering for 7 microseconds is: JP13 pin 15-16,
231 * JP14 pin 7-8 and pin 9-10.
232 * The reduction has a little impact on scsi performance.
234 * - If scsi bus length exceeds 3m., the scsi bus speed needs to be reduced
235 * from 10Mhz to 5Mhz (do this by inserting a jumper on JP13 pin 7-8).
237 * - If U14F on board firmware is older than 28004-006/38004-005,
238 * the U14F board is unable to provide reliable operations if the scsi
239 * request length exceeds 16Kbyte. When this length is exceeded the
241 * - adapter_status equal 0x96 or 0xa3 or 0x93 or 0x94;
242 * - adapter_status equal 0 and target_status equal 2 on for all targets
243 * in the next operation following the reset.
244 * This sequence takes a long time (>3 seconds), so in the meantime
245 * the SD_TIMEOUT in sd.c could expire giving rise to scsi aborts
246 * (SD_TIMEOUT has been increased from 3 to 6 seconds in 1.1.31).
247 * Because of this I had to DISABLE_CLUSTERING and to work around the
248 * bus reset in the interrupt service routine, returning DID_BUS_BUSY
249 * so that the operations are retried without complains from the scsi.c
251 * Any reset of the scsi bus is going to kill tape operations, since
252 * no retry is allowed for tapes. Bus resets are more likely when the
253 * scsi bus is under heavy load.
254 * Requests using scatter/gather have a maximum length of 16 x 1024 bytes
255 * when DISABLE_CLUSTERING is in effect, but unscattered requests could be
256 * larger than 16Kbyte.
258 * The new firmware has fixed all the above problems.
260 * For U34F boards the latest bios prom is 38008-002 (BIOS rev. 2.01),
261 * the latest firmware prom is 28008-006. Older firmware 28008-005 has
262 * problems when using more then 16 scatter/gather lists.
264 * The list of i/o ports to be probed can be totally replaced by the
265 * boot command line option: "u14-34f=port0,port1,port2,...", where the
266 * port0, port1... arguments are ISA/VESA addresses to be probed.
267 * For example using "u14-34f=0x230,0x340", the driver probes only the two
268 * addresses 0x230 and 0x340 in this order; "u14-34f=0" totally disables
271 * After the optional list of detection probes, other possible command line
274 * et:y use disk geometry returned by scsicam_bios_param;
275 * et:n use disk geometry jumpered on the board;
276 * lc:y enables linked commands;
277 * lc:n disables linked commands;
278 * of:y enables old firmware support;
279 * of:n disables old firmware support;
280 * mq:xx set the max queue depth to the value xx (2 <= xx <= 8).
282 * The default value is: "u14-34f=lc:n,of:n,mq:8,et:n".
283 * An example using the list of detection probes could be:
284 * "u14-34f=0x230,0x340,lc:y,of:n,mq:4,et:n".
286 * When loading as a module, parameters can be specified as well.
287 * The above example would be (use 1 in place of y and 0 in place of n):
289 * modprobe u14-34f io_port=0x230,0x340 linked_comm=1 have_old_firmware=0 \
290 * max_queue_depth=4 ext_tran=0
292 * ----------------------------------------------------------------------------
293 * In this implementation, linked commands are designed to work with any DISK
294 * or CD-ROM, since this linking has only the intent of clustering (time-wise)
295 * and reordering by elevator sorting commands directed to each device,
296 * without any relation with the actual SCSI protocol between the controller
298 * If Q is the queue depth reported at boot time for each device (also named
299 * cmds/lun) and Q > 2, whenever there is already an active command to the
300 * device all other commands to the same device (up to Q-1) are kept waiting
301 * in the elevator sorting queue. When the active command completes, the
302 * commands in this queue are sorted by sector address. The sort is chosen
303 * between increasing or decreasing by minimizing the seek distance between
304 * the sector of the commands just completed and the sector of the first
305 * command in the list to be sorted.
306 * Trivial math assures that the unsorted average seek distance when doing
307 * random seeks over S sectors is S/3.
308 * When (Q-1) requests are uniformly distributed over S sectors, the average
309 * distance between two adjacent requests is S/((Q-1) + 1), so the sorted
310 * average seek distance for (Q-1) random requests over S sectors is S/Q.
311 * The elevator sorting hence divides the seek distance by a factor Q/3.
312 * The above pure geometric remarks are valid in all cases and the
313 * driver effectively reduces the seek distance by the predicted factor
314 * when there are Q concurrent read i/o operations on the device, but this
315 * does not necessarily results in a noticeable performance improvement:
316 * your mileage may vary....
318 * Note: command reordering inside a batch of queued commands could cause
319 * wrong results only if there is at least one write request and the
320 * intersection (sector-wise) of all requests is not empty.
321 * When the driver detects a batch including overlapping requests
322 * (a really rare event) strict serial (pid) order is enforced.
323 * ----------------------------------------------------------------------------
325 * The boards are named Ux4F0, Ux4F1,... according to the detection order.
327 * In order to support multiple ISA boards in a reliable way,
328 * the driver sets host->wish_block = TRUE for all ISA boards.
331 #include <linux/version.h>
333 #ifndef LinuxVersionCode
334 #define LinuxVersionCode(v, p, s) (((v)<<16)+((p)<<8)+(s))
337 #define MAX_INT_PARAM 10
340 #include <linux/module.h>
342 MODULE_PARM(boot_options
, "s");
343 MODULE_PARM(io_port
, "1-" __MODULE_STRING(MAX_INT_PARAM
) "i");
344 MODULE_PARM(linked_comm
, "i");
345 MODULE_PARM(have_old_firmware
, "i");
346 MODULE_PARM(link_statistics
, "i");
347 MODULE_PARM(max_queue_depth
, "i");
348 MODULE_PARM(ext_tran
, "i");
349 MODULE_AUTHOR("Dario Ballabio");
353 #include <linux/string.h>
354 #include <linux/sched.h>
355 #include <linux/kernel.h>
356 #include <linux/ioport.h>
357 #include <linux/delay.h>
359 #include <asm/system.h>
360 #include <asm/byteorder.h>
361 #include <linux/proc_fs.h>
362 #include <linux/blk.h>
369 #include <linux/stat.h>
370 #include <linux/config.h>
371 #include <linux/init.h>
372 #include <linux/ctype.h>
373 #include <linux/spinlock.h>
375 #define SPIN_FLAGS unsigned long spin_flags;
376 #define SPIN_LOCK spin_lock_irq(&io_request_lock);
377 #define SPIN_LOCK_SAVE spin_lock_irqsave(&io_request_lock, spin_flags);
378 #define SPIN_UNLOCK spin_unlock_irq(&io_request_lock);
379 #define SPIN_UNLOCK_RESTORE \
380 spin_unlock_irqrestore(&io_request_lock, spin_flags);
382 /* Values for the PRODUCT_ID ports for the 14/34F */
383 #define PRODUCT_ID1 0x56
384 #define PRODUCT_ID2 0x40 /* NOTE: Only upper nibble is used */
386 /* Subversion values */
390 #define OP_HOST_ADAPTER 0x1
397 #define HA_CMD_INQUIRY 0x1
398 #define HA_CMD_SELF_DIAG 0x2
399 #define HA_CMD_READ_BUFF 0x3
400 #define HA_CMD_WRITE_BUFF 0x4
402 #undef DEBUG_LINKED_COMMANDS
404 #undef DEBUG_INTERRUPT
406 #undef DEBUG_GENERATE_ERRORS
407 #undef DEBUG_GENERATE_ABORTS
408 #undef DEBUG_GEOMETRY
414 #define MAX_BOARDS (MAX_ISA + MAX_VESA + MAX_EISA + MAX_PCI)
415 #define MAX_CHANNEL 1
418 #define MAX_MAILBOXES 16
419 #define MAX_SGLIST 32
420 #define MAX_SAFE_SGLIST 16
421 #define MAX_INTERNAL_RETRIES 64
422 #define MAX_CMD_PER_LUN 2
423 #define MAX_TAGGED_CMD_PER_LUN (MAX_MAILBOXES - MAX_CMD_PER_LUN)
425 #define SKIP ULONG_MAX
436 #define MAXLOOP 10000
438 #define REG_LCL_MASK 0
439 #define REG_LCL_INTR 1
440 #define REG_SYS_MASK 2
441 #define REG_SYS_INTR 3
442 #define REG_PRODUCT_ID1 4
443 #define REG_PRODUCT_ID2 5
444 #define REG_CONFIG1 6
445 #define REG_CONFIG2 7
448 #define REGION_SIZE 13
449 #define BSY_ASSERTED 0x01
450 #define IRQ_ASSERTED 0x01
451 #define CMD_RESET 0xc0
452 #define CMD_OGM_INTR 0x01
453 #define CMD_CLR_INTR 0x01
454 #define CMD_ENA_INTR 0x81
458 #define YESNO(a) ((a) ? 'y' : 'n')
459 #define TLDEV(type) ((type) == TYPE_DISK || (type) == TYPE_ROM)
461 #define PACKED __attribute__((packed))
464 unsigned int address
; /* Segment Address */
465 unsigned int num_bytes
; /* Segment Length */
468 /* MailBox SCSI Command Packet */
470 unsigned char opcode
: 3; /* type of command */
471 unsigned char xdir
: 2; /* data transfer direction */
472 unsigned char dcn
: 1; /* disable disconnect */
473 unsigned char ca
: 1; /* use cache (if available) */
474 unsigned char sg
: 1; /* scatter/gather operation */
475 unsigned char target
: 3; /* SCSI target id */
476 unsigned char channel
: 2; /* SCSI channel number */
477 unsigned char lun
: 3; /* SCSI logical unit number */
478 unsigned int data_address PACKED
; /* transfer data pointer */
479 unsigned int data_len PACKED
; /* length in bytes */
480 unsigned int link_address PACKED
; /* for linking command chains */
481 unsigned char clink_id
; /* identifies command in chain */
482 unsigned char use_sg
; /* (if sg is set) 8 bytes per list */
483 unsigned char sense_len
;
484 unsigned char scsi_cdbs_len
; /* 6, 10, or 12 */
485 unsigned char scsi_cdbs
[12]; /* SCSI commands */
486 unsigned char adapter_status
; /* non-zero indicates HA error */
487 unsigned char target_status
; /* non-zero indicates target error */
488 unsigned int sense_addr PACKED
;
490 unsigned int index
; /* cp index */
491 struct sg_list
*sglist
;
495 struct mscp cp
[MAX_MAILBOXES
]; /* Mailboxes for this board */
496 unsigned int cp_stat
[MAX_MAILBOXES
]; /* FREE, IN_USE, LOCKED, IN_RESET */
497 unsigned int last_cp_used
; /* Index of last mailbox used */
498 unsigned int iocount
; /* Total i/o done for this board */
499 int board_number
; /* Number of this board */
500 char board_name
[16]; /* Name of this board */
501 char board_id
[256]; /* data from INQUIRY on this board */
502 int in_reset
; /* True if board is doing a reset */
503 int target_to
[MAX_TARGET
][MAX_CHANNEL
]; /* N. of timeout errors on target */
504 int target_redo
[MAX_TARGET
][MAX_CHANNEL
]; /* If TRUE redo i/o on target */
505 unsigned int retries
; /* Number of internal retries */
506 unsigned long last_retried_pid
; /* Pid of last retried command */
507 unsigned char subversion
; /* Bus type, either ISA or ESA */
509 unsigned char sectors
;
511 /* slot != 0 for the U24F, slot == 0 for both the U14F and U34F */
515 static struct Scsi_Host
*sh
[MAX_BOARDS
+ 1];
516 static const char *driver_name
= "Ux4F";
517 static char sha
[MAX_BOARDS
];
519 /* Initialize num_boards so that ihdlr can work while detect is in progress */
520 static unsigned int num_boards
= MAX_BOARDS
;
522 static unsigned long io_port
[] = {
524 /* Space for MAX_INT_PARAM ports usable while loading as a module */
525 SKIP
, SKIP
, SKIP
, SKIP
, SKIP
, SKIP
, SKIP
, SKIP
,
528 /* Possible ISA/VESA ports */
529 0x330, 0x340, 0x230, 0x240, 0x210, 0x130, 0x140,
535 #define HD(board) ((struct hostdata *) &sh[board]->hostdata)
536 #define BN(board) (HD(board)->board_name)
538 #define SWAP_BYTE(x) ((unsigned long)( \
539 (((unsigned long)(x) & 0x000000ffU) << 24) | \
540 (((unsigned long)(x) & 0x0000ff00U) << 8) | \
541 (((unsigned long)(x) & 0x00ff0000U) >> 8) | \
542 (((unsigned long)(x) & 0xff000000U) >> 24)))
544 #if defined(__BIG_ENDIAN)
545 #define H2DEV(x) SWAP_BYTE(x)
550 #define DEV2H(x) H2DEV(x)
551 #define V2DEV(addr) ((addr) ? H2DEV(virt_to_bus((void *)addr)) : 0)
552 #define DEV2V(addr) ((addr) ? DEV2H(bus_to_virt((unsigned long)addr)) : 0)
554 static void do_interrupt_handler(int, void *, struct pt_regs
*);
555 static void flush_dev(Scsi_Device
*, unsigned long, unsigned int, unsigned int);
556 static int do_trace
= FALSE
;
557 static int setup_done
= FALSE
;
558 static int link_statistics
;
559 static int ext_tran
= FALSE
;
560 static char *boot_options
;
562 #if defined(HAVE_OLD_UX4F_FIRMWARE)
563 static int have_old_firmware
= TRUE
;
565 static int have_old_firmware
= FALSE
;
568 #if defined(CONFIG_SCSI_U14_34F_LINKED_COMMANDS)
569 static int linked_comm
= TRUE
;
571 static int linked_comm
= FALSE
;
574 #if defined(CONFIG_SCSI_U14_34F_MAX_TAGS)
575 static int max_queue_depth
= CONFIG_SCSI_U14_34F_MAX_TAGS
;
577 static int max_queue_depth
= MAX_CMD_PER_LUN
;
580 static void select_queue_depths(struct Scsi_Host
*host
, Scsi_Device
*devlist
) {
582 int j
, ntag
= 0, nuntag
= 0, tqd
, utqd
;
584 j
= ((struct hostdata
*) host
->hostdata
)->board_number
;
586 for(dev
= devlist
; dev
; dev
= dev
->next
) {
588 if (dev
->host
!= host
) continue;
590 if (TLDEV(dev
->type
) && (dev
->tagged_supported
|| linked_comm
))
596 utqd
= MAX_CMD_PER_LUN
;
598 tqd
= (host
->can_queue
- utqd
* nuntag
) / (ntag
? ntag
: 1);
600 if (tqd
> max_queue_depth
) tqd
= max_queue_depth
;
602 if (tqd
< MAX_CMD_PER_LUN
) tqd
= MAX_CMD_PER_LUN
;
604 for(dev
= devlist
; dev
; dev
= dev
->next
) {
605 char *tag_suffix
= "", *link_suffix
= "";
607 if (dev
->host
!= host
) continue;
609 if (TLDEV(dev
->type
) && (dev
->tagged_supported
|| linked_comm
))
610 dev
->queue_depth
= tqd
;
612 dev
->queue_depth
= utqd
;
614 if (TLDEV(dev
->type
)) {
615 if (linked_comm
&& dev
->queue_depth
> 2)
616 link_suffix
= ", sorted";
618 link_suffix
= ", unsorted";
621 if (dev
->tagged_supported
&& TLDEV(dev
->type
) && dev
->tagged_queue
)
622 tag_suffix
= ", soft-tagged";
623 else if (dev
->tagged_supported
&& TLDEV(dev
->type
))
624 tag_suffix
= ", tagged";
626 printk("%s: scsi%d, channel %d, id %d, lun %d, cmds/lun %d%s%s.\n",
627 BN(j
), host
->host_no
, dev
->channel
, dev
->id
, dev
->lun
,
628 dev
->queue_depth
, link_suffix
, tag_suffix
);
634 static inline int wait_on_busy(unsigned long iobase
, unsigned int loop
) {
636 while (inb(iobase
+ REG_LCL_INTR
) & BSY_ASSERTED
) {
638 if (--loop
== 0) return TRUE
;
644 static int board_inquiry(unsigned int j
) {
646 unsigned int time
, limit
= 0;
649 memset(cpp
, 0, sizeof(struct mscp
));
650 cpp
->opcode
= OP_HOST_ADAPTER
;
652 cpp
->data_address
= V2DEV(HD(j
)->board_id
);
653 cpp
->data_len
= H2DEV(sizeof(HD(j
)->board_id
));
654 cpp
->scsi_cdbs_len
= 6;
655 cpp
->scsi_cdbs
[0] = HA_CMD_INQUIRY
;
657 if (wait_on_busy(sh
[j
]->io_port
, MAXLOOP
)) {
658 printk("%s: board_inquiry, adapter busy.\n", BN(j
));
662 HD(j
)->cp_stat
[0] = IGNORE
;
664 /* Clear the interrupt indication */
665 outb(CMD_CLR_INTR
, sh
[j
]->io_port
+ REG_SYS_INTR
);
667 /* Store pointer in OGM address bytes */
668 outl(V2DEV(cpp
), sh
[j
]->io_port
+ REG_OGM
);
670 /* Issue OGM interrupt */
671 outb(CMD_OGM_INTR
, sh
[j
]->io_port
+ REG_LCL_INTR
);
675 while ((jiffies
- time
) < HZ
&& limit
++ < 20000) udelay(100L);
678 if (cpp
->adapter_status
|| HD(j
)->cp_stat
[0] != FREE
) {
679 HD(j
)->cp_stat
[0] = FREE
;
680 printk("%s: board_inquiry, err 0x%x.\n", BN(j
), cpp
->adapter_status
);
687 static inline int port_detect \
688 (unsigned long port_base
, unsigned int j
, Scsi_Host_Template
*tpnt
) {
689 unsigned char irq
, dma_channel
, subversion
, i
;
690 unsigned char in_byte
;
691 char *bus_type
, dma_name
[16];
693 /* Allowed BIOS base addresses (NULL indicates reserved) */
694 unsigned long bios_segment_table
[8] = {
696 0xc4000, 0xc8000, 0xcc000, 0xd0000,
697 0xd4000, 0xd8000, 0xdc000
701 unsigned char interrupt_table
[4] = { 15, 14, 11, 10 };
703 /* Allowed DMA channels for ISA (0 indicates reserved) */
704 unsigned char dma_channel_table
[4] = { 5, 6, 7, 0 };
706 /* Head/sector mappings */
709 unsigned char sectors
;
710 } mapping_table
[4] = {
711 { 16, 63 }, { 64, 32 }, { 64, 63 }, { 64, 32 }
715 unsigned char bios_segment
: 3;
716 unsigned char removable_disks_as_fixed
: 1;
717 unsigned char interrupt
: 2;
718 unsigned char dma_channel
: 2;
722 unsigned char ha_scsi_id
: 3;
723 unsigned char mapping_mode
: 2;
724 unsigned char bios_drive_number
: 1;
725 unsigned char tfr_port
: 2;
730 sprintf(name
, "%s%d", driver_name
, j
);
732 if(check_region(port_base
, REGION_SIZE
)) {
733 #if defined(DEBUG_DETECT)
734 printk("%s: address 0x%03lx in use, skipping probe.\n", name
, port_base
);
739 if (inb(port_base
+ REG_PRODUCT_ID1
) != PRODUCT_ID1
) return FALSE
;
741 in_byte
= inb(port_base
+ REG_PRODUCT_ID2
);
743 if ((in_byte
& 0xf0) != PRODUCT_ID2
) return FALSE
;
745 *(char *)&config_1
= inb(port_base
+ REG_CONFIG1
);
746 *(char *)&config_2
= inb(port_base
+ REG_CONFIG2
);
748 irq
= interrupt_table
[config_1
.interrupt
];
749 dma_channel
= dma_channel_table
[config_1
.dma_channel
];
750 subversion
= (in_byte
& 0x0f);
752 /* Board detected, allocate its IRQ */
753 if (request_irq(irq
, do_interrupt_handler
,
754 SA_INTERRUPT
| ((subversion
== ESA
) ? SA_SHIRQ
: 0),
755 driver_name
, (void *) &sha
[j
])) {
756 printk("%s: unable to allocate IRQ %u, detaching.\n", name
, irq
);
760 if (subversion
== ISA
&& request_dma(dma_channel
, driver_name
)) {
761 printk("%s: unable to allocate DMA channel %u, detaching.\n",
763 free_irq(irq
, &sha
[j
]);
767 if (have_old_firmware
) tpnt
->use_clustering
= DISABLE_CLUSTERING
;
769 sh
[j
] = scsi_register(tpnt
, sizeof(struct hostdata
));
772 printk("%s: unable to register host, detaching.\n", name
);
774 free_irq(irq
, &sha
[j
]);
776 if (subversion
== ISA
) free_dma(dma_channel
);
781 sh
[j
]->io_port
= port_base
;
782 sh
[j
]->unique_id
= port_base
;
783 sh
[j
]->n_io_port
= REGION_SIZE
;
784 sh
[j
]->base
= bios_segment_table
[config_1
.bios_segment
];
786 sh
[j
]->sg_tablesize
= MAX_SGLIST
;
787 sh
[j
]->this_id
= config_2
.ha_scsi_id
;
788 sh
[j
]->can_queue
= MAX_MAILBOXES
;
789 sh
[j
]->cmd_per_lun
= MAX_CMD_PER_LUN
;
790 sh
[j
]->select_queue_depths
= select_queue_depths
;
792 #if defined(DEBUG_DETECT)
794 unsigned char sys_mask
, lcl_mask
;
796 sys_mask
= inb(sh
[j
]->io_port
+ REG_SYS_MASK
);
797 lcl_mask
= inb(sh
[j
]->io_port
+ REG_LCL_MASK
);
798 printk("SYS_MASK 0x%x, LCL_MASK 0x%x.\n", sys_mask
, lcl_mask
);
802 /* Probably a bogus host scsi id, set it to the dummy value */
803 if (sh
[j
]->this_id
== 0) sh
[j
]->this_id
= -1;
805 /* If BIOS is disabled, force enable interrupts */
806 if (sh
[j
]->base
== 0) outb(CMD_ENA_INTR
, sh
[j
]->io_port
+ REG_SYS_MASK
);
808 /* Register the I/O space that we use */
809 request_region(sh
[j
]->io_port
, sh
[j
]->n_io_port
, driver_name
);
811 memset(HD(j
), 0, sizeof(struct hostdata
));
812 HD(j
)->heads
= mapping_table
[config_2
.mapping_mode
].heads
;
813 HD(j
)->sectors
= mapping_table
[config_2
.mapping_mode
].sectors
;
814 HD(j
)->subversion
= subversion
;
815 HD(j
)->board_number
= j
;
817 if (have_old_firmware
) sh
[j
]->sg_tablesize
= MAX_SAFE_SGLIST
;
819 if (HD(j
)->subversion
== ESA
) {
820 sh
[j
]->unchecked_isa_dma
= FALSE
;
821 sh
[j
]->dma_channel
= NO_DMA
;
822 sprintf(BN(j
), "U34F%d", j
);
827 scsi_register_blocked_host(sh
[j
]);
828 sh
[j
]->unchecked_isa_dma
= TRUE
;
830 flags
=claim_dma_lock();
831 disable_dma(dma_channel
);
832 clear_dma_ff(dma_channel
);
833 set_dma_mode(dma_channel
, DMA_MODE_CASCADE
);
834 enable_dma(dma_channel
);
835 release_dma_lock(flags
);
837 sh
[j
]->dma_channel
= dma_channel
;
838 sprintf(BN(j
), "U14F%d", j
);
842 sh
[j
]->max_channel
= MAX_CHANNEL
- 1;
843 sh
[j
]->max_id
= MAX_TARGET
;
844 sh
[j
]->max_lun
= MAX_LUN
;
846 if (HD(j
)->subversion
== ISA
&& !board_inquiry(j
)) {
847 HD(j
)->board_id
[40] = 0;
849 if (strcmp(&HD(j
)->board_id
[32], "06000600")) {
850 printk("%s: %s.\n", BN(j
), &HD(j
)->board_id
[8]);
851 printk("%s: firmware %s is outdated, FW PROM should be 28004-006.\n",
852 BN(j
), &HD(j
)->board_id
[32]);
853 sh
[j
]->hostt
->use_clustering
= DISABLE_CLUSTERING
;
854 sh
[j
]->sg_tablesize
= MAX_SAFE_SGLIST
;
858 if (dma_channel
== NO_DMA
) sprintf(dma_name
, "%s", "BMST");
859 else sprintf(dma_name
, "DMA %u", dma_channel
);
861 for (i
= 0; i
< sh
[j
]->can_queue
; i
++)
862 if (! ((&HD(j
)->cp
[i
])->sglist
= kmalloc(
863 sh
[j
]->sg_tablesize
* sizeof(struct sg_list
),
864 (sh
[j
]->unchecked_isa_dma
? GFP_DMA
: 0) | GFP_ATOMIC
))) {
865 printk("%s: kmalloc SGlist failed, mbox %d, detaching.\n", BN(j
), i
);
866 u14_34f_release(sh
[j
]);
870 if (max_queue_depth
> MAX_TAGGED_CMD_PER_LUN
)
871 max_queue_depth
= MAX_TAGGED_CMD_PER_LUN
;
873 if (max_queue_depth
< MAX_CMD_PER_LUN
) max_queue_depth
= MAX_CMD_PER_LUN
;
876 printk("UltraStor 14F/34F: Copyright (C) 1994-2000 Dario Ballabio.\n");
877 printk("%s config options -> of:%c, lc:%c, mq:%d, et:%c.\n",
878 driver_name
, YESNO(have_old_firmware
), YESNO(linked_comm
),
879 max_queue_depth
, YESNO(ext_tran
));
882 printk("%s: %s 0x%03lx, BIOS 0x%05x, IRQ %u, %s, SG %d, MB %d.\n",
883 BN(j
), bus_type
, (unsigned long)sh
[j
]->io_port
, (int)sh
[j
]->base
,
884 sh
[j
]->irq
, dma_name
, sh
[j
]->sg_tablesize
, sh
[j
]->can_queue
);
886 if (sh
[j
]->max_id
> 8 || sh
[j
]->max_lun
> 8)
887 printk("%s: wide SCSI support enabled, max_id %u, max_lun %u.\n",
888 BN(j
), sh
[j
]->max_id
, sh
[j
]->max_lun
);
890 for (i
= 0; i
<= sh
[j
]->max_channel
; i
++)
891 printk("%s: SCSI channel %u enabled, host target ID %d.\n",
892 BN(j
), i
, sh
[j
]->this_id
);
897 static void internal_setup(char *str
, int *ints
) {
898 int i
, argc
= ints
[0];
899 char *cur
= str
, *pc
;
903 if (argc
> MAX_INT_PARAM
) argc
= MAX_INT_PARAM
;
905 for (i
= 0; i
< argc
; i
++) io_port
[i
] = ints
[i
+ 1];
911 while (cur
&& (pc
= strchr(cur
, ':'))) {
912 int val
= 0, c
= *++pc
;
914 if (c
== 'n' || c
== 'N') val
= FALSE
;
915 else if (c
== 'y' || c
== 'Y') val
= TRUE
;
916 else val
= (int) simple_strtoul(pc
, NULL
, 0);
918 if (!strncmp(cur
, "lc:", 3)) linked_comm
= val
;
919 else if (!strncmp(cur
, "of:", 3)) have_old_firmware
= val
;
920 else if (!strncmp(cur
, "mq:", 3)) max_queue_depth
= val
;
921 else if (!strncmp(cur
, "ls:", 3)) link_statistics
= val
;
922 else if (!strncmp(cur
, "et:", 3)) ext_tran
= val
;
924 if ((cur
= strchr(cur
, ','))) ++cur
;
930 static int option_setup(char *str
) {
931 int ints
[MAX_INT_PARAM
];
935 while (cur
&& isdigit(*cur
) && i
<= MAX_INT_PARAM
) {
936 ints
[i
++] = simple_strtoul(cur
, NULL
, 0);
938 if ((cur
= strchr(cur
, ',')) != NULL
) cur
++;
942 internal_setup(cur
, ints
);
946 int u14_34f_detect(Scsi_Host_Template
*tpnt
)
948 unsigned int j
= 0, k
;
950 tpnt
->proc_name
= "u14-34f";
952 if(boot_options
) option_setup(boot_options
);
955 /* io_port could have been modified when loading as a module */
956 if(io_port
[0] != SKIP
) {
958 io_port
[MAX_INT_PARAM
] = 0;
962 for (k
= 0; k
< MAX_BOARDS
+ 1; k
++) sh
[k
] = NULL
;
964 for (k
= 0; io_port
[k
]; k
++) {
966 if (io_port
[k
] == SKIP
) continue;
968 if (j
< MAX_BOARDS
&& port_detect(io_port
[k
], j
, tpnt
)) j
++;
975 static inline void build_sg_list(struct mscp
*cpp
, Scsi_Cmnd
*SCpnt
) {
976 unsigned int k
, data_len
= 0;
977 struct scatterlist
*sgpnt
;
979 sgpnt
= (struct scatterlist
*) SCpnt
->request_buffer
;
981 for (k
= 0; k
< SCpnt
->use_sg
; k
++) {
982 cpp
->sglist
[k
].address
= V2DEV(sgpnt
[k
].address
);
983 cpp
->sglist
[k
].num_bytes
= H2DEV(sgpnt
[k
].length
);
984 data_len
+= sgpnt
[k
].length
;
987 cpp
->use_sg
= SCpnt
->use_sg
;
988 cpp
->data_address
= V2DEV(cpp
->sglist
);
989 cpp
->data_len
= H2DEV(data_len
);
992 static inline int do_qcomm(Scsi_Cmnd
*SCpnt
, void (*done
)(Scsi_Cmnd
*)) {
993 unsigned int i
, j
, k
;
996 static const unsigned char data_out_cmds
[] = {
997 0x0a, 0x2a, 0x15, 0x55, 0x04, 0x07, 0x18, 0x1d, 0x24, 0x2e,
998 0x30, 0x31, 0x32, 0x38, 0x39, 0x3a, 0x3b, 0x3d, 0x3f, 0x40,
999 0x41, 0x4c, 0xaa, 0xae, 0xb0, 0xb1, 0xb2, 0xb6, 0xea, 0x1b
1002 static const unsigned char data_none_cmds
[] = {
1003 0x01, 0x0b, 0x10, 0x11, 0x13, 0x16, 0x17, 0x19, 0x2b, 0x1e,
1004 0x2c, 0xac, 0x2f, 0xaf, 0x33, 0xb3, 0x35, 0x36, 0x45, 0x47,
1005 0x48, 0x49, 0xa9, 0x4b, 0xa5, 0xa6, 0xb5
1008 /* j is the board number */
1009 j
= ((struct hostdata
*) SCpnt
->host
->hostdata
)->board_number
;
1011 if (SCpnt
->host_scribble
)
1012 panic("%s: qcomm, pid %ld, SCpnt %p already active.\n",
1013 BN(j
), SCpnt
->pid
, SCpnt
);
1015 /* i is the mailbox number, look for the first free mailbox
1016 starting from last_cp_used */
1017 i
= HD(j
)->last_cp_used
+ 1;
1019 for (k
= 0; k
< sh
[j
]->can_queue
; k
++, i
++) {
1021 if (i
>= sh
[j
]->can_queue
) i
= 0;
1023 if (HD(j
)->cp_stat
[i
] == FREE
) {
1024 HD(j
)->last_cp_used
= i
;
1029 if (k
== sh
[j
]->can_queue
) {
1030 printk("%s: qcomm, no free mailbox.\n", BN(j
));
1034 /* Set pointer to control packet structure */
1035 cpp
= &HD(j
)->cp
[i
];
1037 memset(cpp
, 0, sizeof(struct mscp
) - sizeof(struct sg_list
*));
1038 SCpnt
->scsi_done
= done
;
1040 SCpnt
->host_scribble
= (unsigned char *) &cpp
->index
;
1042 if (do_trace
) printk("%s: qcomm, mbox %d, target %d.%d:%d, pid %ld.\n",
1043 BN(j
), i
, SCpnt
->channel
, SCpnt
->target
,
1044 SCpnt
->lun
, SCpnt
->pid
);
1048 for (k
= 0; k
< ARRAY_SIZE(data_out_cmds
); k
++)
1049 if (SCpnt
->cmnd
[0] == data_out_cmds
[k
]) {
1050 cpp
->xdir
= DTD_OUT
;
1054 if (cpp
->xdir
== DTD_IN
)
1055 for (k
= 0; k
< ARRAY_SIZE(data_none_cmds
); k
++)
1056 if (SCpnt
->cmnd
[0] == data_none_cmds
[k
]) {
1057 cpp
->xdir
= DTD_NONE
;
1061 cpp
->opcode
= OP_SCSI
;
1062 cpp
->channel
= SCpnt
->channel
;
1063 cpp
->target
= SCpnt
->target
;
1064 cpp
->lun
= SCpnt
->lun
;
1066 cpp
->sense_addr
= V2DEV(SCpnt
->sense_buffer
);
1067 cpp
->sense_len
= sizeof SCpnt
->sense_buffer
;
1069 if (SCpnt
->use_sg
) {
1071 build_sg_list(cpp
, SCpnt
);
1074 cpp
->data_address
= V2DEV(SCpnt
->request_buffer
);
1075 cpp
->data_len
= H2DEV(SCpnt
->request_bufflen
);
1078 cpp
->scsi_cdbs_len
= SCpnt
->cmd_len
;
1079 memcpy(cpp
->scsi_cdbs
, SCpnt
->cmnd
, cpp
->scsi_cdbs_len
);
1081 if (linked_comm
&& SCpnt
->device
->queue_depth
> 2
1082 && TLDEV(SCpnt
->device
->type
)) {
1083 HD(j
)->cp_stat
[i
] = READY
;
1084 flush_dev(SCpnt
->device
, SCpnt
->request
.sector
, j
, FALSE
);
1088 if (wait_on_busy(sh
[j
]->io_port
, MAXLOOP
)) {
1089 SCpnt
->host_scribble
= NULL
;
1090 printk("%s: qcomm, target %d.%d:%d, pid %ld, adapter busy.\n",
1091 BN(j
), SCpnt
->channel
, SCpnt
->target
, SCpnt
->lun
, SCpnt
->pid
);
1095 /* Store pointer in OGM address bytes */
1096 outl(V2DEV(cpp
), sh
[j
]->io_port
+ REG_OGM
);
1098 /* Issue OGM interrupt */
1099 outb(CMD_OGM_INTR
, sh
[j
]->io_port
+ REG_LCL_INTR
);
1101 HD(j
)->cp_stat
[i
] = IN_USE
;
1105 int u14_34f_queuecommand(Scsi_Cmnd
*SCpnt
, void (*done
)(Scsi_Cmnd
*)) {
1108 rtn
= do_qcomm(SCpnt
, done
);
1112 static inline int do_abort(Scsi_Cmnd
*SCarg
) {
1115 j
= ((struct hostdata
*) SCarg
->host
->hostdata
)->board_number
;
1117 if (SCarg
->host_scribble
== NULL
) {
1118 printk("%s: abort, target %d.%d:%d, pid %ld inactive.\n",
1119 BN(j
), SCarg
->channel
, SCarg
->target
, SCarg
->lun
, SCarg
->pid
);
1123 i
= *(unsigned int *)SCarg
->host_scribble
;
1124 printk("%s: abort, mbox %d, target %d.%d:%d, pid %ld.\n",
1125 BN(j
), i
, SCarg
->channel
, SCarg
->target
, SCarg
->lun
, SCarg
->pid
);
1127 if (i
>= sh
[j
]->can_queue
)
1128 panic("%s: abort, invalid SCarg->host_scribble.\n", BN(j
));
1130 if (wait_on_busy(sh
[j
]->io_port
, MAXLOOP
)) {
1131 printk("%s: abort, timeout error.\n", BN(j
));
1135 if (HD(j
)->cp_stat
[i
] == FREE
) {
1136 printk("%s: abort, mbox %d is free.\n", BN(j
), i
);
1140 if (HD(j
)->cp_stat
[i
] == IN_USE
) {
1141 printk("%s: abort, mbox %d is in use.\n", BN(j
), i
);
1143 if (SCarg
!= HD(j
)->cp
[i
].SCpnt
)
1144 panic("%s: abort, mbox %d, SCarg %p, cp SCpnt %p.\n",
1145 BN(j
), i
, SCarg
, HD(j
)->cp
[i
].SCpnt
);
1147 if (inb(sh
[j
]->io_port
+ REG_SYS_INTR
) & IRQ_ASSERTED
)
1148 printk("%s: abort, mbox %d, interrupt pending.\n", BN(j
), i
);
1150 if (SCarg
->eh_state
== SCSI_STATE_TIMEOUT
) {
1151 SCarg
->host_scribble
= NULL
;
1152 HD(j
)->cp_stat
[i
] = FREE
;
1153 printk("%s, abort, mbox %d, eh_state timeout, pid %ld.\n",
1154 BN(j
), i
, SCarg
->pid
);
1161 if (HD(j
)->cp_stat
[i
] == IN_RESET
) {
1162 printk("%s: abort, mbox %d is in reset.\n", BN(j
), i
);
1166 if (HD(j
)->cp_stat
[i
] == LOCKED
) {
1167 printk("%s: abort, mbox %d is locked.\n", BN(j
), i
);
1171 if (HD(j
)->cp_stat
[i
] == READY
|| HD(j
)->cp_stat
[i
] == ABORTING
) {
1172 SCarg
->result
= DID_ABORT
<< 16;
1173 SCarg
->host_scribble
= NULL
;
1174 HD(j
)->cp_stat
[i
] = FREE
;
1175 printk("%s, abort, mbox %d ready, DID_ABORT, pid %ld done.\n",
1176 BN(j
), i
, SCarg
->pid
);
1177 SCarg
->scsi_done(SCarg
);
1181 panic("%s: abort, mbox %d, invalid cp_stat.\n", BN(j
), i
);
1184 int u14_34f_abort(Scsi_Cmnd
*SCarg
) {
1186 return do_abort(SCarg
);
1189 static inline int do_reset(Scsi_Cmnd
*SCarg
) {
1190 unsigned int i
, j
, time
, k
, c
, limit
= 0;
1191 int arg_done
= FALSE
;
1194 j
= ((struct hostdata
*) SCarg
->host
->hostdata
)->board_number
;
1195 printk("%s: reset, enter, target %d.%d:%d, pid %ld.\n",
1196 BN(j
), SCarg
->channel
, SCarg
->target
, SCarg
->lun
, SCarg
->pid
);
1198 if (SCarg
->host_scribble
== NULL
)
1199 printk("%s: reset, pid %ld inactive.\n", BN(j
), SCarg
->pid
);
1201 if (HD(j
)->in_reset
) {
1202 printk("%s: reset, exit, already in reset.\n", BN(j
));
1206 if (wait_on_busy(sh
[j
]->io_port
, MAXLOOP
)) {
1207 printk("%s: reset, exit, timeout error.\n", BN(j
));
1213 for (c
= 0; c
<= sh
[j
]->max_channel
; c
++)
1214 for (k
= 0; k
< sh
[j
]->max_id
; k
++) {
1215 HD(j
)->target_redo
[k
][c
] = TRUE
;
1216 HD(j
)->target_to
[k
][c
] = 0;
1219 for (i
= 0; i
< sh
[j
]->can_queue
; i
++) {
1221 if (HD(j
)->cp_stat
[i
] == FREE
) continue;
1223 if (HD(j
)->cp_stat
[i
] == LOCKED
) {
1224 HD(j
)->cp_stat
[i
] = FREE
;
1225 printk("%s: reset, locked mbox %d forced free.\n", BN(j
), i
);
1229 if (!(SCpnt
= HD(j
)->cp
[i
].SCpnt
))
1230 panic("%s: reset, mbox %d, SCpnt == NULL.\n", BN(j
), i
);
1232 if (HD(j
)->cp_stat
[i
] == READY
|| HD(j
)->cp_stat
[i
] == ABORTING
) {
1233 HD(j
)->cp_stat
[i
] = ABORTING
;
1234 printk("%s: reset, mbox %d aborting, pid %ld.\n",
1235 BN(j
), i
, SCpnt
->pid
);
1239 HD(j
)->cp_stat
[i
] = IN_RESET
;
1240 printk("%s: reset, mbox %d in reset, pid %ld.\n",
1241 BN(j
), i
, SCpnt
->pid
);
1244 if (SCpnt
->host_scribble
== NULL
)
1245 panic("%s: reset, mbox %d, garbled SCpnt.\n", BN(j
), i
);
1247 if (*(unsigned int *)SCpnt
->host_scribble
!= i
)
1248 panic("%s: reset, mbox %d, index mismatch.\n", BN(j
), i
);
1250 if (SCpnt
->scsi_done
== NULL
)
1251 panic("%s: reset, mbox %d, SCpnt->scsi_done == NULL.\n", BN(j
), i
);
1253 if (SCpnt
== SCarg
) arg_done
= TRUE
;
1256 if (wait_on_busy(sh
[j
]->io_port
, MAXLOOP
)) {
1257 printk("%s: reset, cannot reset, timeout error.\n", BN(j
));
1261 outb(CMD_RESET
, sh
[j
]->io_port
+ REG_LCL_INTR
);
1262 printk("%s: reset, board reset done, enabling interrupts.\n", BN(j
));
1264 #if defined(DEBUG_RESET)
1268 HD(j
)->in_reset
= TRUE
;
1271 while ((jiffies
- time
) < (10 * HZ
) && limit
++ < 200000) udelay(100L);
1273 printk("%s: reset, interrupts disabled, loops %d.\n", BN(j
), limit
);
1275 for (i
= 0; i
< sh
[j
]->can_queue
; i
++) {
1277 if (HD(j
)->cp_stat
[i
] == IN_RESET
) {
1278 SCpnt
= HD(j
)->cp
[i
].SCpnt
;
1279 SCpnt
->result
= DID_RESET
<< 16;
1280 SCpnt
->host_scribble
= NULL
;
1282 /* This mailbox is still waiting for its interrupt */
1283 HD(j
)->cp_stat
[i
] = LOCKED
;
1285 printk("%s, reset, mbox %d locked, DID_RESET, pid %ld done.\n",
1286 BN(j
), i
, SCpnt
->pid
);
1289 else if (HD(j
)->cp_stat
[i
] == ABORTING
) {
1290 SCpnt
= HD(j
)->cp
[i
].SCpnt
;
1291 SCpnt
->result
= DID_RESET
<< 16;
1292 SCpnt
->host_scribble
= NULL
;
1294 /* This mailbox was never queued to the adapter */
1295 HD(j
)->cp_stat
[i
] = FREE
;
1297 printk("%s, reset, mbox %d aborting, DID_RESET, pid %ld done.\n",
1298 BN(j
), i
, SCpnt
->pid
);
1303 /* Any other mailbox has already been set free by interrupt */
1306 SCpnt
->scsi_done(SCpnt
);
1309 HD(j
)->in_reset
= FALSE
;
1312 if (arg_done
) printk("%s: reset, exit, pid %ld done.\n", BN(j
), SCarg
->pid
);
1313 else printk("%s: reset, exit.\n", BN(j
));
1318 int u14_34f_reset(Scsi_Cmnd
*SCarg
) {
1320 return do_reset(SCarg
);
1323 int u14_34f_biosparam(Disk
*disk
, kdev_t dev
, int *dkinfo
) {
1325 int size
= disk
->capacity
;
1327 dkinfo
[0] = HD(j
)->heads
;
1328 dkinfo
[1] = HD(j
)->sectors
;
1329 dkinfo
[2] = size
/ (HD(j
)->heads
* HD(j
)->sectors
);
1331 if (ext_tran
&& (scsicam_bios_param(disk
, dev
, dkinfo
) < 0)) {
1334 dkinfo
[2] = size
/ (dkinfo
[0] * dkinfo
[1]);
1337 #if defined (DEBUG_GEOMETRY)
1338 printk ("%s: biosparam, head=%d, sec=%d, cyl=%d.\n", driver_name
,
1339 dkinfo
[0], dkinfo
[1], dkinfo
[2]);
1345 static void sort(unsigned long sk
[], unsigned int da
[], unsigned int n
,
1347 unsigned int i
, j
, k
, y
;
1350 for (i
= 0; i
< n
- 1; i
++) {
1353 for (j
= k
+ 1; j
< n
; j
++)
1355 if (sk
[j
] > sk
[k
]) k
= j
;
1358 if (sk
[j
] < sk
[k
]) k
= j
;
1362 x
= sk
[k
]; sk
[k
] = sk
[i
]; sk
[i
] = x
;
1363 y
= da
[k
]; da
[k
] = da
[i
]; da
[i
] = y
;
1370 static inline int reorder(unsigned int j
, unsigned long cursec
,
1371 unsigned int ihdlr
, unsigned int il
[], unsigned int n_ready
) {
1375 unsigned int rev
= FALSE
, s
= TRUE
, r
= TRUE
;
1376 unsigned int input_only
= TRUE
, overlap
= FALSE
;
1377 unsigned long sl
[n_ready
], pl
[n_ready
], ll
[n_ready
];
1378 unsigned long maxsec
= 0, minsec
= ULONG_MAX
, seek
= 0, iseek
= 0;
1379 unsigned long ioseek
= 0;
1381 static unsigned int flushcount
= 0, batchcount
= 0, sortcount
= 0;
1382 static unsigned int readycount
= 0, ovlcount
= 0, inputcount
= 0;
1383 static unsigned int readysorted
= 0, revcount
= 0;
1384 static unsigned long seeksorted
= 0, seeknosort
= 0;
1386 if (link_statistics
&& !(++flushcount
% link_statistics
))
1387 printk("fc %d bc %d ic %d oc %d rc %d rs %d sc %d re %d"\
1388 " av %ldK as %ldK.\n", flushcount
, batchcount
, inputcount
,
1389 ovlcount
, readycount
, readysorted
, sortcount
, revcount
,
1390 seeknosort
/ (readycount
+ 1),
1391 seeksorted
/ (readycount
+ 1));
1393 if (n_ready
<= 1) return FALSE
;
1395 for (n
= 0; n
< n_ready
; n
++) {
1396 k
= il
[n
]; cpp
= &HD(j
)->cp
[k
]; SCpnt
= cpp
->SCpnt
;
1398 if (!(cpp
->xdir
== DTD_IN
)) input_only
= FALSE
;
1400 if (SCpnt
->request
.sector
< minsec
) minsec
= SCpnt
->request
.sector
;
1401 if (SCpnt
->request
.sector
> maxsec
) maxsec
= SCpnt
->request
.sector
;
1403 sl
[n
] = SCpnt
->request
.sector
;
1404 ioseek
+= SCpnt
->request
.nr_sectors
;
1408 if (sl
[n
] < sl
[n
- 1]) s
= FALSE
;
1409 if (sl
[n
] > sl
[n
- 1]) r
= FALSE
;
1411 if (link_statistics
) {
1412 if (sl
[n
] > sl
[n
- 1])
1413 seek
+= sl
[n
] - sl
[n
- 1];
1415 seek
+= sl
[n
- 1] - sl
[n
];
1420 if (link_statistics
) {
1421 if (cursec
> sl
[0]) seek
+= cursec
- sl
[0]; else seek
+= sl
[0] - cursec
;
1424 if (cursec
> ((maxsec
+ minsec
) / 2)) rev
= TRUE
;
1426 if (ioseek
> ((maxsec
- minsec
) / 2)) rev
= FALSE
;
1428 if (!((rev
&& r
) || (!rev
&& s
))) sort(sl
, il
, n_ready
, rev
);
1430 if (!input_only
) for (n
= 0; n
< n_ready
; n
++) {
1431 k
= il
[n
]; cpp
= &HD(j
)->cp
[k
]; SCpnt
= cpp
->SCpnt
;
1432 ll
[n
] = SCpnt
->request
.nr_sectors
; pl
[n
] = SCpnt
->pid
;
1436 if ((sl
[n
] == sl
[n
- 1]) || (!rev
&& ((sl
[n
- 1] + ll
[n
- 1]) > sl
[n
]))
1437 || (rev
&& ((sl
[n
] + ll
[n
]) > sl
[n
- 1]))) overlap
= TRUE
;
1440 if (overlap
) sort(pl
, il
, n_ready
, FALSE
);
1442 if (link_statistics
) {
1443 if (cursec
> sl
[0]) iseek
= cursec
- sl
[0]; else iseek
= sl
[0] - cursec
;
1444 batchcount
++; readycount
+= n_ready
; seeknosort
+= seek
/ 1024;
1445 if (input_only
) inputcount
++;
1446 if (overlap
) { ovlcount
++; seeksorted
+= iseek
/ 1024; }
1447 else seeksorted
+= (iseek
+ maxsec
- minsec
) / 1024;
1448 if (rev
&& !r
) { revcount
++; readysorted
+= n_ready
; }
1449 if (!rev
&& !s
) { sortcount
++; readysorted
+= n_ready
; }
1452 #if defined(DEBUG_LINKED_COMMANDS)
1453 if (link_statistics
&& (overlap
|| !(flushcount
% link_statistics
)))
1454 for (n
= 0; n
< n_ready
; n
++) {
1455 k
= il
[n
]; cpp
= &HD(j
)->cp
[k
]; SCpnt
= cpp
->SCpnt
;
1456 printk("%s %d.%d:%d pid %ld mb %d fc %d nr %d sec %ld ns %ld"\
1457 " cur %ld s:%c r:%c rev:%c in:%c ov:%c xd %d.\n",
1458 (ihdlr
? "ihdlr" : "qcomm"), SCpnt
->channel
, SCpnt
->target
,
1459 SCpnt
->lun
, SCpnt
->pid
, k
, flushcount
, n_ready
,
1460 SCpnt
->request
.sector
, SCpnt
->request
.nr_sectors
, cursec
,
1461 YESNO(s
), YESNO(r
), YESNO(rev
), YESNO(input_only
),
1462 YESNO(overlap
), cpp
->xdir
);
1468 static void flush_dev(Scsi_Device
*dev
, unsigned long cursec
, unsigned int j
,
1469 unsigned int ihdlr
) {
1472 unsigned int k
, n
, n_ready
= 0, il
[MAX_MAILBOXES
];
1474 for (k
= 0; k
< sh
[j
]->can_queue
; k
++) {
1476 if (HD(j
)->cp_stat
[k
] != READY
&& HD(j
)->cp_stat
[k
] != IN_USE
) continue;
1478 cpp
= &HD(j
)->cp
[k
]; SCpnt
= cpp
->SCpnt
;
1480 if (SCpnt
->device
!= dev
) continue;
1482 if (HD(j
)->cp_stat
[k
] == IN_USE
) return;
1487 if (reorder(j
, cursec
, ihdlr
, il
, n_ready
)) n_ready
= 1;
1489 for (n
= 0; n
< n_ready
; n
++) {
1490 k
= il
[n
]; cpp
= &HD(j
)->cp
[k
]; SCpnt
= cpp
->SCpnt
;
1492 if (wait_on_busy(sh
[j
]->io_port
, MAXLOOP
)) {
1493 printk("%s: %s, target %d.%d:%d, pid %ld, mbox %d, adapter"\
1494 " busy, will abort.\n", BN(j
), (ihdlr
? "ihdlr" : "qcomm"),
1495 SCpnt
->channel
, SCpnt
->target
, SCpnt
->lun
, SCpnt
->pid
, k
);
1496 HD(j
)->cp_stat
[k
] = ABORTING
;
1500 outl(V2DEV(cpp
), sh
[j
]->io_port
+ REG_OGM
);
1501 outb(CMD_OGM_INTR
, sh
[j
]->io_port
+ REG_LCL_INTR
);
1502 HD(j
)->cp_stat
[k
] = IN_USE
;
1507 static inline void ihdlr(int irq
, unsigned int j
) {
1509 unsigned int i
, k
, c
, status
, tstatus
, reg
, ret
;
1510 struct mscp
*spp
, *cpp
;
1512 if (sh
[j
]->irq
!= irq
)
1513 panic("%s: ihdlr, irq %d, sh[j]->irq %d.\n", BN(j
), irq
, sh
[j
]->irq
);
1515 /* Check if this board need to be serviced */
1516 if (!((reg
= inb(sh
[j
]->io_port
+ REG_SYS_INTR
)) & IRQ_ASSERTED
)) return;
1520 if (do_trace
) printk("%s: ihdlr, enter, irq %d, count %d.\n", BN(j
), irq
,
1523 /* Check if this board is still busy */
1524 if (wait_on_busy(sh
[j
]->io_port
, 20 * MAXLOOP
)) {
1525 outb(CMD_CLR_INTR
, sh
[j
]->io_port
+ REG_SYS_INTR
);
1526 printk("%s: ihdlr, busy timeout error, irq %d, reg 0x%x, count %d.\n",
1527 BN(j
), irq
, reg
, HD(j
)->iocount
);
1531 spp
= (struct mscp
*)DEV2V(ret
= inl(sh
[j
]->io_port
+ REG_ICM
));
1534 /* Clear interrupt pending flag */
1535 outb(CMD_CLR_INTR
, sh
[j
]->io_port
+ REG_SYS_INTR
);
1537 #if defined(DEBUG_GENERATE_ABORTS)
1538 if ((HD(j
)->iocount
> 500) && ((HD(j
)->iocount
% 500) < 3)) return;
1541 /* Find the mailbox to be serviced on this board */
1542 i
= cpp
- HD(j
)->cp
;
1544 if (cpp
< HD(j
)->cp
|| cpp
>= HD(j
)->cp
+ sh
[j
]->can_queue
1545 || i
>= sh
[j
]->can_queue
)
1546 panic("%s: ihdlr, invalid mscp bus address %p, cp0 %p.\n", BN(j
),
1547 (void *)ret
, HD(j
)->cp
);
1549 if (HD(j
)->cp_stat
[i
] == IGNORE
) {
1550 HD(j
)->cp_stat
[i
] = FREE
;
1553 else if (HD(j
)->cp_stat
[i
] == LOCKED
) {
1554 HD(j
)->cp_stat
[i
] = FREE
;
1555 printk("%s: ihdlr, mbox %d unlocked, count %d.\n", BN(j
), i
,
1559 else if (HD(j
)->cp_stat
[i
] == FREE
) {
1560 printk("%s: ihdlr, mbox %d is free, count %d.\n", BN(j
), i
,
1564 else if (HD(j
)->cp_stat
[i
] == IN_RESET
)
1565 printk("%s: ihdlr, mbox %d is in reset.\n", BN(j
), i
);
1566 else if (HD(j
)->cp_stat
[i
] != IN_USE
)
1567 panic("%s: ihdlr, mbox %d, invalid cp_stat: %d.\n",
1568 BN(j
), i
, HD(j
)->cp_stat
[i
]);
1570 HD(j
)->cp_stat
[i
] = FREE
;
1573 if (SCpnt
== NULL
) panic("%s: ihdlr, mbox %d, SCpnt == NULL.\n", BN(j
), i
);
1575 if (SCpnt
->host_scribble
== NULL
)
1576 panic("%s: ihdlr, mbox %d, pid %ld, SCpnt %p garbled.\n", BN(j
), i
,
1579 if (*(unsigned int *)SCpnt
->host_scribble
!= i
)
1580 panic("%s: ihdlr, mbox %d, pid %ld, index mismatch %d.\n",
1581 BN(j
), i
, SCpnt
->pid
, *(unsigned int *)SCpnt
->host_scribble
);
1583 if (linked_comm
&& SCpnt
->device
->queue_depth
> 2
1584 && TLDEV(SCpnt
->device
->type
))
1585 flush_dev(SCpnt
->device
, SCpnt
->request
.sector
, j
, TRUE
);
1587 tstatus
= status_byte(spp
->target_status
);
1589 #if defined(DEBUG_GENERATE_ERRORS)
1590 if ((HD(j
)->iocount
> 500) && ((HD(j
)->iocount
% 200) < 2))
1591 spp
->adapter_status
= 0x01;
1594 switch (spp
->adapter_status
) {
1595 case ASOK
: /* status OK */
1597 /* Forces a reset if a disk drive keeps returning BUSY */
1598 if (tstatus
== BUSY
&& SCpnt
->device
->type
!= TYPE_TAPE
)
1599 status
= DID_ERROR
<< 16;
1601 /* If there was a bus reset, redo operation on each target */
1602 else if (tstatus
!= GOOD
&& SCpnt
->device
->type
== TYPE_DISK
1603 && HD(j
)->target_redo
[SCpnt
->target
][SCpnt
->channel
])
1604 status
= DID_BUS_BUSY
<< 16;
1606 /* Works around a flaw in scsi.c */
1607 else if (tstatus
== CHECK_CONDITION
1608 && SCpnt
->device
->type
== TYPE_DISK
1609 && (SCpnt
->sense_buffer
[2] & 0xf) == RECOVERED_ERROR
)
1610 status
= DID_BUS_BUSY
<< 16;
1613 status
= DID_OK
<< 16;
1615 if (tstatus
== GOOD
)
1616 HD(j
)->target_redo
[SCpnt
->target
][SCpnt
->channel
] = FALSE
;
1618 if (spp
->target_status
&& SCpnt
->device
->type
== TYPE_DISK
&&
1619 (!(tstatus
== CHECK_CONDITION
&& HD(j
)->iocount
<= 1000 &&
1620 (SCpnt
->sense_buffer
[2] & 0xf) == NOT_READY
)))
1621 printk("%s: ihdlr, target %d.%d:%d, pid %ld, "\
1622 "target_status 0x%x, sense key 0x%x.\n", BN(j
),
1623 SCpnt
->channel
, SCpnt
->target
, SCpnt
->lun
,
1624 SCpnt
->pid
, spp
->target_status
,
1625 SCpnt
->sense_buffer
[2]);
1627 HD(j
)->target_to
[SCpnt
->target
][SCpnt
->channel
] = 0;
1629 if (HD(j
)->last_retried_pid
== SCpnt
->pid
) HD(j
)->retries
= 0;
1632 case ASST
: /* Selection Time Out */
1634 if (HD(j
)->target_to
[SCpnt
->target
][SCpnt
->channel
] > 1)
1635 status
= DID_ERROR
<< 16;
1637 status
= DID_TIME_OUT
<< 16;
1638 HD(j
)->target_to
[SCpnt
->target
][SCpnt
->channel
]++;
1643 /* Perform a limited number of internal retries */
1644 case 0x93: /* Unexpected bus free */
1645 case 0x94: /* Target bus phase sequence failure */
1646 case 0x96: /* Illegal SCSI command */
1647 case 0xa3: /* SCSI bus reset error */
1649 for (c
= 0; c
<= sh
[j
]->max_channel
; c
++)
1650 for (k
= 0; k
< sh
[j
]->max_id
; k
++)
1651 HD(j
)->target_redo
[k
][c
] = TRUE
;
1654 case 0x92: /* Data over/under-run */
1656 if (SCpnt
->device
->type
!= TYPE_TAPE
1657 && HD(j
)->retries
< MAX_INTERNAL_RETRIES
) {
1659 #if defined(DID_SOFT_ERROR)
1660 status
= DID_SOFT_ERROR
<< 16;
1662 status
= DID_BUS_BUSY
<< 16;
1666 HD(j
)->last_retried_pid
= SCpnt
->pid
;
1669 status
= DID_ERROR
<< 16;
1672 case 0x01: /* Invalid command */
1673 case 0x02: /* Invalid parameters */
1674 case 0x03: /* Invalid data list */
1675 case 0x84: /* SCSI bus abort error */
1676 case 0x9b: /* Auto request sense error */
1677 case 0x9f: /* Unexpected command complete message error */
1678 case 0xff: /* Invalid parameter in the S/G list */
1680 status
= DID_ERROR
<< 16;
1684 SCpnt
->result
= status
| spp
->target_status
;
1686 #if defined(DEBUG_INTERRUPT)
1687 if (SCpnt
->result
|| do_trace
)
1689 if ((spp
->adapter_status
!= ASOK
&& HD(j
)->iocount
> 1000) ||
1690 (spp
->adapter_status
!= ASOK
&&
1691 spp
->adapter_status
!= ASST
&& HD(j
)->iocount
<= 1000) ||
1692 do_trace
|| msg_byte(spp
->target_status
))
1694 printk("%s: ihdlr, mbox %2d, err 0x%x:%x,"\
1695 " target %d.%d:%d, pid %ld, reg 0x%x, count %d.\n",
1696 BN(j
), i
, spp
->adapter_status
, spp
->target_status
,
1697 SCpnt
->channel
, SCpnt
->target
, SCpnt
->lun
, SCpnt
->pid
,
1698 reg
, HD(j
)->iocount
);
1700 /* Set the command state to inactive */
1701 SCpnt
->host_scribble
= NULL
;
1703 SCpnt
->scsi_done(SCpnt
);
1705 if (do_trace
) printk("%s: ihdlr, exit, irq %d, count %d.\n", BN(j
), irq
,
1711 static void do_interrupt_handler(int irq
, void *shap
, struct pt_regs
*regs
) {
1715 /* Check if the interrupt must be processed by this handler */
1716 if ((j
= (unsigned int)((char *)shap
- sha
)) >= num_boards
) return;
1723 int u14_34f_release(struct Scsi_Host
*shpnt
) {
1726 for (j
= 0; sh
[j
] != NULL
&& sh
[j
] != shpnt
; j
++);
1728 if (sh
[j
] == NULL
) panic("%s: release, invalid Scsi_Host pointer.\n",
1731 if( sh
[j
]->unchecked_isa_dma
) {
1732 scsi_deregister_blocked_host(sh
[j
]);
1735 for (i
= 0; i
< sh
[j
]->can_queue
; i
++)
1736 if ((&HD(j
)->cp
[i
])->sglist
) kfree((&HD(j
)->cp
[i
])->sglist
);
1738 free_irq(sh
[j
]->irq
, &sha
[j
]);
1740 if (sh
[j
]->dma_channel
!= NO_DMA
) free_dma(sh
[j
]->dma_channel
);
1742 release_region(sh
[j
]->io_port
, sh
[j
]->n_io_port
);
1743 scsi_unregister(sh
[j
]);
1747 static Scsi_Host_Template driver_template
= ULTRASTOR_14_34F
;
1749 #include "scsi_module.c"
1752 __setup("u14-34f=", option_setup
);
1753 #endif /* end MODULE */