File: /usr/src/linux/drivers/scsi/u14-34f.c
1 /*
2 * u14-34f.c - Low-level driver for UltraStor 14F/34F SCSI host adapters.
3 *
4 * 1 May 2001 Rev. 6.05 for linux 2.4.4
5 * + Fix data transfer direction for opcode SEND_CUE_SHEET (0x5d)
6 *
7 * 25 Jan 2001 Rev. 6.03 for linux 2.4.0
8 * + "check_region" call replaced by "request_region".
9 *
10 * 22 Nov 2000 Rev. 6.02 for linux 2.4.0-test11
11 * + Removed old scsi error handling support.
12 * + The obsolete boot option flag eh:n is silently ignored.
13 * + Removed error messages while a disk drive is powered up at
14 * boot time.
15 * + Improved boot messages: all tagged capable device are
16 * indicated as "tagged".
17 *
18 * 16 Sep 1999 Rev. 5.11 for linux 2.2.12 and 2.3.18
19 * + Updated to the new __setup interface for boot command line options.
20 * + When loaded as a module, accepts the new parameter boot_options
21 * which value is a string with the same format of the kernel boot
22 * command line options. A valid example is:
23 * modprobe u14-34f boot_options=\"0x230,0x340,lc:y,mq:4\"
24 *
25 * 22 Jul 1999 Rev. 5.00 for linux 2.2.10 and 2.3.11
26 * + Removed pre-2.2 source code compatibility.
27 *
28 * 26 Jul 1998 Rev. 4.33 for linux 2.0.35 and 2.1.111
29 * Added command line option (et:[y|n]) to use the existing
30 * translation (returned by scsicam_bios_param) as disk geometry.
31 * The default is et:n, which uses the disk geometry jumpered
32 * on the board.
33 * The default value et:n is compatible with all previous revisions
34 * of this driver.
35 *
36 * 28 May 1998 Rev. 4.32 for linux 2.0.33 and 2.1.104
37 * Increased busy timeout from 10 msec. to 200 msec. while
38 * processing interrupts.
39 *
40 * 18 May 1998 Rev. 4.31 for linux 2.0.33 and 2.1.102
41 * Improved abort handling during the eh recovery process.
42 *
43 * 13 May 1998 Rev. 4.30 for linux 2.0.33 and 2.1.101
44 * The driver is now fully SMP safe, including the
45 * abort and reset routines.
46 * Added command line options (eh:[y|n]) to choose between
47 * new_eh_code and the old scsi code.
48 * If linux version >= 2.1.101 the default is eh:y, while the eh
49 * option is ignored for previous releases and the old scsi code
50 * is used.
51 *
52 * 18 Apr 1998 Rev. 4.20 for linux 2.0.33 and 2.1.97
53 * Reworked interrupt handler.
54 *
55 * 11 Apr 1998 rev. 4.05 for linux 2.0.33 and 2.1.95
56 * Major reliability improvement: when a batch with overlapping
57 * requests is detected, requests are queued one at a time
58 * eliminating any possible board or drive reordering.
59 *
60 * 10 Apr 1998 rev. 4.04 for linux 2.0.33 and 2.1.95
61 * Improved SMP support (if linux version >= 2.1.95).
62 *
63 * 9 Apr 1998 rev. 4.03 for linux 2.0.33 and 2.1.94
64 * Performance improvement: when sequential i/o is detected,
65 * always use direct sort instead of reverse sort.
66 *
67 * 4 Apr 1998 rev. 4.02 for linux 2.0.33 and 2.1.92
68 * io_port is now unsigned long.
69 *
70 * 17 Mar 1998 rev. 4.01 for linux 2.0.33 and 2.1.88
71 * Use new scsi error handling code (if linux version >= 2.1.88).
72 * Use new interrupt code.
73 *
74 * 12 Sep 1997 rev. 3.11 for linux 2.0.30 and 2.1.55
75 * Use of udelay inside the wait loops to avoid timeout
76 * problems with fast cpus.
77 * Removed check about useless calls to the interrupt service
78 * routine (reported on SMP systems only).
79 * At initialization time "sorted/unsorted" is displayed instead
80 * of "linked/unlinked" to reinforce the fact that "linking" is
81 * nothing but "elevator sorting" in the actual implementation.
82 *
83 * 17 May 1997 rev. 3.10 for linux 2.0.30 and 2.1.38
84 * Use of serial_number_at_timeout in abort and reset processing.
85 * Use of the __initfunc and __initdata macro in setup code.
86 * Minor cleanups in the list_statistics code.
87 *
88 * 24 Feb 1997 rev. 3.00 for linux 2.0.29 and 2.1.26
89 * When loading as a module, parameter passing is now supported
90 * both in 2.0 and in 2.1 style.
91 * Fixed data transfer direction for some SCSI opcodes.
92 * Immediate acknowledge to request sense commands.
93 * Linked commands to each disk device are now reordered by elevator
94 * sorting. Rare cases in which reordering of write requests could
95 * cause wrong results are managed.
96 *
97 * 18 Jan 1997 rev. 2.60 for linux 2.1.21 and 2.0.28
98 * Added command line options to enable/disable linked commands
99 * (lc:[y|n]), old firmware support (of:[y|n]) and to set the max
100 * queue depth (mq:xx). Default is "u14-34f=lc:n,of:n,mq:8".
101 * Improved command linking.
102 *
103 * 8 Jan 1997 rev. 2.50 for linux 2.1.20 and 2.0.27
104 * Added linked command support.
105 *
106 * 3 Dec 1996 rev. 2.40 for linux 2.1.14 and 2.0.27
107 * Added queue depth adjustment.
108 *
109 * 22 Nov 1996 rev. 2.30 for linux 2.1.12 and 2.0.26
110 * The list of i/o ports to be probed can be overwritten by the
111 * "u14-34f=port0,port1,...." boot command line option.
112 * Scatter/gather lists are now allocated by a number of kmalloc
113 * calls, in order to avoid the previous size limit of 64Kb.
114 *
115 * 16 Nov 1996 rev. 2.20 for linux 2.1.10 and 2.0.25
116 * Added multichannel support.
117 *
118 * 27 Sep 1996 rev. 2.12 for linux 2.1.0
119 * Portability cleanups (virtual/bus addressing, little/big endian
120 * support).
121 *
122 * 09 Jul 1996 rev. 2.11 for linux 2.0.4
123 * "Data over/under-run" no longer implies a redo on all targets.
124 * Number of internal retries is now limited.
125 *
126 * 16 Apr 1996 rev. 2.10 for linux 1.3.90
127 * New argument "reset_flags" to the reset routine.
128 *
129 * 21 Jul 1995 rev. 2.02 for linux 1.3.11
130 * Fixed Data Transfer Direction for some SCSI commands.
131 *
132 * 13 Jun 1995 rev. 2.01 for linux 1.2.10
133 * HAVE_OLD_UX4F_FIRMWARE should be defined for U34F boards when
134 * the firmware prom is not the latest one (28008-006).
135 *
136 * 11 Mar 1995 rev. 2.00 for linux 1.2.0
137 * Fixed a bug which prevented media change detection for removable
138 * disk drives.
139 *
140 * 23 Feb 1995 rev. 1.18 for linux 1.1.94
141 * Added a check for scsi_register returning NULL.
142 *
143 * 11 Feb 1995 rev. 1.17 for linux 1.1.91
144 * U14F qualified to run with 32 sglists.
145 * Now DEBUG_RESET is disabled by default.
146 *
147 * 9 Feb 1995 rev. 1.16 for linux 1.1.90
148 * Use host->wish_block instead of host->block.
149 *
150 * 8 Feb 1995 rev. 1.15 for linux 1.1.89
151 * Cleared target_time_out counter while performing a reset.
152 *
153 * 28 Jan 1995 rev. 1.14 for linux 1.1.86
154 * Added module support.
155 * Log and do a retry when a disk drive returns a target status
156 * different from zero on a recovered error.
157 * Auto detects if U14F boards have an old firmware revision.
158 * Max number of scatter/gather lists set to 16 for all boards
159 * (most installation run fine using 33 sglists, while other
160 * has problems when using more then 16).
161 *
162 * 16 Jan 1995 rev. 1.13 for linux 1.1.81
163 * Display a message if check_region detects a port address
164 * already in use.
165 *
166 * 15 Dec 1994 rev. 1.12 for linux 1.1.74
167 * The host->block flag is set for all the detected ISA boards.
168 *
169 * 30 Nov 1994 rev. 1.11 for linux 1.1.68
170 * Redo i/o on target status CHECK_CONDITION for TYPE_DISK only.
171 * Added optional support for using a single board at a time.
172 *
173 * 14 Nov 1994 rev. 1.10 for linux 1.1.63
174 *
175 * 28 Oct 1994 rev. 1.09 for linux 1.1.58 Final BETA release.
176 * 16 Jul 1994 rev. 1.00 for linux 1.1.29 Initial ALPHA release.
177 *
178 * This driver is a total replacement of the original UltraStor
179 * scsi driver, but it supports ONLY the 14F and 34F boards.
180 * It can be configured in the same kernel in which the original
181 * ultrastor driver is configured to allow the original U24F
182 * support.
183 *
184 * Multiple U14F and/or U34F host adapters are supported.
185 *
186 * Copyright (C) 1994-2001 Dario Ballabio (ballabio_dario@emc.com)
187 *
188 * Alternate email: dario.ballabio@inwind.it, dario.ballabio@tiscalinet.it
189 *
190 * Redistribution and use in source and binary forms, with or without
191 * modification, are permitted provided that redistributions of source
192 * code retain the above copyright notice and this comment without
193 * modification.
194 *
195 * WARNING: if your 14/34F board has an old firmware revision (see below)
196 * you must change "#undef" into "#define" in the following
197 * statement.
198 */
199 #undef HAVE_OLD_UX4F_FIRMWARE
200 /*
201 * The UltraStor 14F, 24F, and 34F are a family of intelligent, high
202 * performance SCSI-2 host adapters.
203 * Here is the scoop on the various models:
204 *
205 * 14F - ISA first-party DMA HA with floppy support and WD1003 emulation.
206 * 24F - EISA Bus Master HA with floppy support and WD1003 emulation.
207 * 34F - VESA Local-Bus Bus Master HA (no WD1003 emulation).
208 *
209 * This code has been tested with up to two U14F boards, using both
210 * firmware 28004-005/38004-004 (BIOS rev. 2.00) and the latest firmware
211 * 28004-006/38004-005 (BIOS rev. 2.01).
212 *
213 * The latest firmware is required in order to get reliable operations when
214 * clustering is enabled. ENABLE_CLUSTERING provides a performance increase
215 * up to 50% on sequential access.
216 *
217 * Since the Scsi_Host_Template structure is shared among all 14F and 34F,
218 * the last setting of use_clustering is in effect for all of these boards.
219 *
220 * Here a sample configuration using two U14F boards:
221 *
222 U14F0: ISA 0x330, BIOS 0xc8000, IRQ 11, DMA 5, SG 32, MB 16, of:n, lc:y, mq:8.
223 U14F1: ISA 0x340, BIOS 0x00000, IRQ 10, DMA 6, SG 32, MB 16, of:n, lc:y, mq:8.
224 *
225 * The boot controller must have its BIOS enabled, while other boards can
226 * have their BIOS disabled, or enabled to an higher address.
227 * Boards are named Ux4F0, Ux4F1..., according to the port address order in
228 * the io_port[] array.
229 *
230 * The following facts are based on real testing results (not on
231 * documentation) on the above U14F board.
232 *
233 * - The U14F board should be jumpered for bus on time less or equal to 7
234 * microseconds, while the default is 11 microseconds. This is order to
235 * get acceptable performance while using floppy drive and hard disk
236 * together. The jumpering for 7 microseconds is: JP13 pin 15-16,
237 * JP14 pin 7-8 and pin 9-10.
238 * The reduction has a little impact on scsi performance.
239 *
240 * - If scsi bus length exceeds 3m., the scsi bus speed needs to be reduced
241 * from 10Mhz to 5Mhz (do this by inserting a jumper on JP13 pin 7-8).
242 *
243 * - If U14F on board firmware is older than 28004-006/38004-005,
244 * the U14F board is unable to provide reliable operations if the scsi
245 * request length exceeds 16Kbyte. When this length is exceeded the
246 * behavior is:
247 * - adapter_status equal 0x96 or 0xa3 or 0x93 or 0x94;
248 * - adapter_status equal 0 and target_status equal 2 on for all targets
249 * in the next operation following the reset.
250 * This sequence takes a long time (>3 seconds), so in the meantime
251 * the SD_TIMEOUT in sd.c could expire giving rise to scsi aborts
252 * (SD_TIMEOUT has been increased from 3 to 6 seconds in 1.1.31).
253 * Because of this I had to DISABLE_CLUSTERING and to work around the
254 * bus reset in the interrupt service routine, returning DID_BUS_BUSY
255 * so that the operations are retried without complains from the scsi.c
256 * code.
257 * Any reset of the scsi bus is going to kill tape operations, since
258 * no retry is allowed for tapes. Bus resets are more likely when the
259 * scsi bus is under heavy load.
260 * Requests using scatter/gather have a maximum length of 16 x 1024 bytes
261 * when DISABLE_CLUSTERING is in effect, but unscattered requests could be
262 * larger than 16Kbyte.
263 *
264 * The new firmware has fixed all the above problems.
265 *
266 * For U34F boards the latest bios prom is 38008-002 (BIOS rev. 2.01),
267 * the latest firmware prom is 28008-006. Older firmware 28008-005 has
268 * problems when using more then 16 scatter/gather lists.
269 *
270 * The list of i/o ports to be probed can be totally replaced by the
271 * boot command line option: "u14-34f=port0,port1,port2,...", where the
272 * port0, port1... arguments are ISA/VESA addresses to be probed.
273 * For example using "u14-34f=0x230,0x340", the driver probes only the two
274 * addresses 0x230 and 0x340 in this order; "u14-34f=0" totally disables
275 * this driver.
276 *
277 * After the optional list of detection probes, other possible command line
278 * options are:
279 *
280 * et:y use disk geometry returned by scsicam_bios_param;
281 * et:n use disk geometry jumpered on the board;
282 * lc:y enables linked commands;
283 * lc:n disables linked commands;
284 * of:y enables old firmware support;
285 * of:n disables old firmware support;
286 * mq:xx set the max queue depth to the value xx (2 <= xx <= 8).
287 *
288 * The default value is: "u14-34f=lc:n,of:n,mq:8,et:n".
289 * An example using the list of detection probes could be:
290 * "u14-34f=0x230,0x340,lc:y,of:n,mq:4,et:n".
291 *
292 * When loading as a module, parameters can be specified as well.
293 * The above example would be (use 1 in place of y and 0 in place of n):
294 *
295 * modprobe u14-34f io_port=0x230,0x340 linked_comm=1 have_old_firmware=0 \
296 * max_queue_depth=4 ext_tran=0
297 *
298 * ----------------------------------------------------------------------------
299 * In this implementation, linked commands are designed to work with any DISK
300 * or CD-ROM, since this linking has only the intent of clustering (time-wise)
301 * and reordering by elevator sorting commands directed to each device,
302 * without any relation with the actual SCSI protocol between the controller
303 * and the device.
304 * If Q is the queue depth reported at boot time for each device (also named
305 * cmds/lun) and Q > 2, whenever there is already an active command to the
306 * device all other commands to the same device (up to Q-1) are kept waiting
307 * in the elevator sorting queue. When the active command completes, the
308 * commands in this queue are sorted by sector address. The sort is chosen
309 * between increasing or decreasing by minimizing the seek distance between
310 * the sector of the commands just completed and the sector of the first
311 * command in the list to be sorted.
312 * Trivial math assures that the unsorted average seek distance when doing
313 * random seeks over S sectors is S/3.
314 * When (Q-1) requests are uniformly distributed over S sectors, the average
315 * distance between two adjacent requests is S/((Q-1) + 1), so the sorted
316 * average seek distance for (Q-1) random requests over S sectors is S/Q.
317 * The elevator sorting hence divides the seek distance by a factor Q/3.
318 * The above pure geometric remarks are valid in all cases and the
319 * driver effectively reduces the seek distance by the predicted factor
320 * when there are Q concurrent read i/o operations on the device, but this
321 * does not necessarily results in a noticeable performance improvement:
322 * your mileage may vary....
323 *
324 * Note: command reordering inside a batch of queued commands could cause
325 * wrong results only if there is at least one write request and the
326 * intersection (sector-wise) of all requests is not empty.
327 * When the driver detects a batch including overlapping requests
328 * (a really rare event) strict serial (pid) order is enforced.
329 * ----------------------------------------------------------------------------
330 *
331 * The boards are named Ux4F0, Ux4F1,... according to the detection order.
332 *
333 * In order to support multiple ISA boards in a reliable way,
334 * the driver sets host->wish_block = TRUE for all ISA boards.
335 */
336
337 #include <linux/version.h>
338
339 #ifndef LinuxVersionCode
340 #define LinuxVersionCode(v, p, s) (((v)<<16)+((p)<<8)+(s))
341 #endif
342
343 #define MAX_INT_PARAM 10
344
345 #if defined(MODULE)
346 #include <linux/module.h>
347
348 MODULE_PARM(boot_options, "s");
349 MODULE_PARM(io_port, "1-" __MODULE_STRING(MAX_INT_PARAM) "i");
350 MODULE_PARM(linked_comm, "i");
351 MODULE_PARM(have_old_firmware, "i");
352 MODULE_PARM(link_statistics, "i");
353 MODULE_PARM(max_queue_depth, "i");
354 MODULE_PARM(ext_tran, "i");
355 MODULE_AUTHOR("Dario Ballabio");
356
357 #endif
358
359 #include <linux/string.h>
360 #include <linux/sched.h>
361 #include <linux/kernel.h>
362 #include <linux/ioport.h>
363 #include <linux/delay.h>
364 #include <asm/io.h>
365 #include <asm/system.h>
366 #include <asm/byteorder.h>
367 #include <linux/proc_fs.h>
368 #include <linux/blk.h>
369 #include "scsi.h"
370 #include "hosts.h"
371 #include "sd.h"
372 #include <asm/dma.h>
373 #include <asm/irq.h>
374 #include "u14-34f.h"
375 #include <linux/stat.h>
376 #include <linux/config.h>
377 #include <linux/init.h>
378 #include <linux/ctype.h>
379 #include <linux/spinlock.h>
380
381 #define SPIN_FLAGS unsigned long spin_flags;
382 #define SPIN_LOCK spin_lock_irq(&io_request_lock);
383 #define SPIN_LOCK_SAVE spin_lock_irqsave(&io_request_lock, spin_flags);
384 #define SPIN_UNLOCK spin_unlock_irq(&io_request_lock);
385 #define SPIN_UNLOCK_RESTORE \
386 spin_unlock_irqrestore(&io_request_lock, spin_flags);
387
388 /* Values for the PRODUCT_ID ports for the 14/34F */
389 #define PRODUCT_ID1 0x56
390 #define PRODUCT_ID2 0x40 /* NOTE: Only upper nibble is used */
391
392 /* Subversion values */
393 #define ISA 0
394 #define ESA 1
395
396 #define OP_HOST_ADAPTER 0x1
397 #define OP_SCSI 0x2
398 #define OP_RESET 0x4
399 #define DTD_SCSI 0x0
400 #define DTD_IN 0x1
401 #define DTD_OUT 0x2
402 #define DTD_NONE 0x3
403 #define HA_CMD_INQUIRY 0x1
404 #define HA_CMD_SELF_DIAG 0x2
405 #define HA_CMD_READ_BUFF 0x3
406 #define HA_CMD_WRITE_BUFF 0x4
407
408 #undef DEBUG_LINKED_COMMANDS
409 #undef DEBUG_DETECT
410 #undef DEBUG_INTERRUPT
411 #undef DEBUG_RESET
412 #undef DEBUG_GENERATE_ERRORS
413 #undef DEBUG_GENERATE_ABORTS
414 #undef DEBUG_GEOMETRY
415
416 #define MAX_ISA 3
417 #define MAX_VESA 1
418 #define MAX_EISA 0
419 #define MAX_PCI 0
420 #define MAX_BOARDS (MAX_ISA + MAX_VESA + MAX_EISA + MAX_PCI)
421 #define MAX_CHANNEL 1
422 #define MAX_LUN 8
423 #define MAX_TARGET 8
424 #define MAX_MAILBOXES 16
425 #define MAX_SGLIST 32
426 #define MAX_SAFE_SGLIST 16
427 #define MAX_INTERNAL_RETRIES 64
428 #define MAX_CMD_PER_LUN 2
429 #define MAX_TAGGED_CMD_PER_LUN (MAX_MAILBOXES - MAX_CMD_PER_LUN)
430
431 #define SKIP ULONG_MAX
432 #define FALSE 0
433 #define TRUE 1
434 #define FREE 0
435 #define IN_USE 1
436 #define LOCKED 2
437 #define IN_RESET 3
438 #define IGNORE 4
439 #define READY 5
440 #define ABORTING 6
441 #define NO_DMA 0xff
442 #define MAXLOOP 10000
443
444 #define REG_LCL_MASK 0
445 #define REG_LCL_INTR 1
446 #define REG_SYS_MASK 2
447 #define REG_SYS_INTR 3
448 #define REG_PRODUCT_ID1 4
449 #define REG_PRODUCT_ID2 5
450 #define REG_CONFIG1 6
451 #define REG_CONFIG2 7
452 #define REG_OGM 8
453 #define REG_ICM 12
454 #define REGION_SIZE 13
455 #define BSY_ASSERTED 0x01
456 #define IRQ_ASSERTED 0x01
457 #define CMD_RESET 0xc0
458 #define CMD_OGM_INTR 0x01
459 #define CMD_CLR_INTR 0x01
460 #define CMD_ENA_INTR 0x81
461 #define ASOK 0x00
462 #define ASST 0x91
463
464 #define YESNO(a) ((a) ? 'y' : 'n')
465 #define TLDEV(type) ((type) == TYPE_DISK || (type) == TYPE_ROM)
466
467 #define PACKED __attribute__((packed))
468
469 struct sg_list {
470 unsigned int address; /* Segment Address */
471 unsigned int num_bytes; /* Segment Length */
472 };
473
474 /* MailBox SCSI Command Packet */
475 struct mscp {
476 unsigned char opcode: 3; /* type of command */
477 unsigned char xdir: 2; /* data transfer direction */
478 unsigned char dcn: 1; /* disable disconnect */
479 unsigned char ca: 1; /* use cache (if available) */
480 unsigned char sg: 1; /* scatter/gather operation */
481 unsigned char target: 3; /* SCSI target id */
482 unsigned char channel: 2; /* SCSI channel number */
483 unsigned char lun: 3; /* SCSI logical unit number */
484 unsigned int data_address PACKED; /* transfer data pointer */
485 unsigned int data_len PACKED; /* length in bytes */
486 unsigned int link_address PACKED; /* for linking command chains */
487 unsigned char clink_id; /* identifies command in chain */
488 unsigned char use_sg; /* (if sg is set) 8 bytes per list */
489 unsigned char sense_len;
490 unsigned char scsi_cdbs_len; /* 6, 10, or 12 */
491 unsigned char scsi_cdbs[12]; /* SCSI commands */
492 unsigned char adapter_status; /* non-zero indicates HA error */
493 unsigned char target_status; /* non-zero indicates target error */
494 unsigned int sense_addr PACKED;
495 Scsi_Cmnd *SCpnt;
496 unsigned int index; /* cp index */
497 struct sg_list *sglist;
498 };
499
500 struct hostdata {
501 struct mscp cp[MAX_MAILBOXES]; /* Mailboxes for this board */
502 unsigned int cp_stat[MAX_MAILBOXES]; /* FREE, IN_USE, LOCKED, IN_RESET */
503 unsigned int last_cp_used; /* Index of last mailbox used */
504 unsigned int iocount; /* Total i/o done for this board */
505 int board_number; /* Number of this board */
506 char board_name[16]; /* Name of this board */
507 char board_id[256]; /* data from INQUIRY on this board */
508 int in_reset; /* True if board is doing a reset */
509 int target_to[MAX_TARGET][MAX_CHANNEL]; /* N. of timeout errors on target */
510 int target_redo[MAX_TARGET][MAX_CHANNEL]; /* If TRUE redo i/o on target */
511 unsigned int retries; /* Number of internal retries */
512 unsigned long last_retried_pid; /* Pid of last retried command */
513 unsigned char subversion; /* Bus type, either ISA or ESA */
514 unsigned char heads;
515 unsigned char sectors;
516
517 /* slot != 0 for the U24F, slot == 0 for both the U14F and U34F */
518 unsigned char slot;
519 };
520
521 static struct Scsi_Host *sh[MAX_BOARDS + 1];
522 static const char *driver_name = "Ux4F";
523 static char sha[MAX_BOARDS];
524
525 /* Initialize num_boards so that ihdlr can work while detect is in progress */
526 static unsigned int num_boards = MAX_BOARDS;
527
528 static unsigned long io_port[] = {
529
530 /* Space for MAX_INT_PARAM ports usable while loading as a module */
531 SKIP, SKIP, SKIP, SKIP, SKIP, SKIP, SKIP, SKIP,
532 SKIP, SKIP,
533
534 /* Possible ISA/VESA ports */
535 0x330, 0x340, 0x230, 0x240, 0x210, 0x130, 0x140,
536
537 /* End of list */
538 0x0
539 };
540
541 #define HD(board) ((struct hostdata *) &sh[board]->hostdata)
542 #define BN(board) (HD(board)->board_name)
543
544 #define SWAP_BYTE(x) ((unsigned long)( \
545 (((unsigned long)(x) & 0x000000ffU) << 24) | \
546 (((unsigned long)(x) & 0x0000ff00U) << 8) | \
547 (((unsigned long)(x) & 0x00ff0000U) >> 8) | \
548 (((unsigned long)(x) & 0xff000000U) >> 24)))
549
550 #if defined(__BIG_ENDIAN)
551 #define H2DEV(x) SWAP_BYTE(x)
552 #else
553 #define H2DEV(x) (x)
554 #endif
555
556 #define DEV2H(x) H2DEV(x)
557 #define V2DEV(addr) ((addr) ? H2DEV(virt_to_bus((void *)addr)) : 0)
558 #define DEV2V(addr) ((addr) ? DEV2H(bus_to_virt((unsigned long)addr)) : 0)
559
560 static void do_interrupt_handler(int, void *, struct pt_regs *);
561 static void flush_dev(Scsi_Device *, unsigned long, unsigned int, unsigned int);
562 static int do_trace = FALSE;
563 static int setup_done = FALSE;
564 static int link_statistics;
565 static int ext_tran = FALSE;
566 static char *boot_options;
567
568 #if defined(HAVE_OLD_UX4F_FIRMWARE)
569 static int have_old_firmware = TRUE;
570 #else
571 static int have_old_firmware = FALSE;
572 #endif
573
574 #if defined(CONFIG_SCSI_U14_34F_LINKED_COMMANDS)
575 static int linked_comm = TRUE;
576 #else
577 static int linked_comm = FALSE;
578 #endif
579
580 #if defined(CONFIG_SCSI_U14_34F_MAX_TAGS)
581 static int max_queue_depth = CONFIG_SCSI_U14_34F_MAX_TAGS;
582 #else
583 static int max_queue_depth = MAX_CMD_PER_LUN;
584 #endif
585
586 static void select_queue_depths(struct Scsi_Host *host, Scsi_Device *devlist) {
587 Scsi_Device *dev;
588 int j, ntag = 0, nuntag = 0, tqd, utqd;
589
590 j = ((struct hostdata *) host->hostdata)->board_number;
591
592 for(dev = devlist; dev; dev = dev->next) {
593
594 if (dev->host != host) continue;
595
596 if (TLDEV(dev->type) && (dev->tagged_supported || linked_comm))
597 ntag++;
598 else
599 nuntag++;
600 }
601
602 utqd = MAX_CMD_PER_LUN;
603
604 tqd = (host->can_queue - utqd * nuntag) / (ntag ? ntag : 1);
605
606 if (tqd > max_queue_depth) tqd = max_queue_depth;
607
608 if (tqd < MAX_CMD_PER_LUN) tqd = MAX_CMD_PER_LUN;
609
610 for(dev = devlist; dev; dev = dev->next) {
611 char *tag_suffix = "", *link_suffix = "";
612
613 if (dev->host != host) continue;
614
615 if (TLDEV(dev->type) && (dev->tagged_supported || linked_comm))
616 dev->queue_depth = tqd;
617 else
618 dev->queue_depth = utqd;
619
620 if (TLDEV(dev->type)) {
621 if (linked_comm && dev->queue_depth > 2)
622 link_suffix = ", sorted";
623 else
624 link_suffix = ", unsorted";
625 }
626
627 if (dev->tagged_supported && TLDEV(dev->type) && dev->tagged_queue)
628 tag_suffix = ", soft-tagged";
629 else if (dev->tagged_supported && TLDEV(dev->type))
630 tag_suffix = ", tagged";
631
632 printk("%s: scsi%d, channel %d, id %d, lun %d, cmds/lun %d%s%s.\n",
633 BN(j), host->host_no, dev->channel, dev->id, dev->lun,
634 dev->queue_depth, link_suffix, tag_suffix);
635 }
636
637 return;
638 }
639
640 static inline int wait_on_busy(unsigned long iobase, unsigned int loop) {
641
642 while (inb(iobase + REG_LCL_INTR) & BSY_ASSERTED) {
643 udelay(1L);
644 if (--loop == 0) return TRUE;
645 }
646
647 return FALSE;
648 }
649
650 static int board_inquiry(unsigned int j) {
651 struct mscp *cpp;
652 unsigned int time, limit = 0;
653
654 cpp = &HD(j)->cp[0];
655 memset(cpp, 0, sizeof(struct mscp));
656 cpp->opcode = OP_HOST_ADAPTER;
657 cpp->xdir = DTD_IN;
658 cpp->data_address = V2DEV(HD(j)->board_id);
659 cpp->data_len = H2DEV(sizeof(HD(j)->board_id));
660 cpp->scsi_cdbs_len = 6;
661 cpp->scsi_cdbs[0] = HA_CMD_INQUIRY;
662
663 if (wait_on_busy(sh[j]->io_port, MAXLOOP)) {
664 printk("%s: board_inquiry, adapter busy.\n", BN(j));
665 return TRUE;
666 }
667
668 HD(j)->cp_stat[0] = IGNORE;
669
670 /* Clear the interrupt indication */
671 outb(CMD_CLR_INTR, sh[j]->io_port + REG_SYS_INTR);
672
673 /* Store pointer in OGM address bytes */
674 outl(V2DEV(cpp), sh[j]->io_port + REG_OGM);
675
676 /* Issue OGM interrupt */
677 outb(CMD_OGM_INTR, sh[j]->io_port + REG_LCL_INTR);
678
679 SPIN_UNLOCK
680 time = jiffies;
681 while ((jiffies - time) < HZ && limit++ < 20000) udelay(100L);
682 SPIN_LOCK
683
684 if (cpp->adapter_status || HD(j)->cp_stat[0] != FREE) {
685 HD(j)->cp_stat[0] = FREE;
686 printk("%s: board_inquiry, err 0x%x.\n", BN(j), cpp->adapter_status);
687 return TRUE;
688 }
689
690 return FALSE;
691 }
692
693 static inline int port_detect
694 (unsigned long port_base, unsigned int j, Scsi_Host_Template *tpnt) {
695 unsigned char irq, dma_channel, subversion, i;
696 unsigned char in_byte;
697 char *bus_type, dma_name[16];
698
699 /* Allowed BIOS base addresses (NULL indicates reserved) */
700 unsigned long bios_segment_table[8] = {
701 0,
702 0xc4000, 0xc8000, 0xcc000, 0xd0000,
703 0xd4000, 0xd8000, 0xdc000
704 };
705
706 /* Allowed IRQs */
707 unsigned char interrupt_table[4] = { 15, 14, 11, 10 };
708
709 /* Allowed DMA channels for ISA (0 indicates reserved) */
710 unsigned char dma_channel_table[4] = { 5, 6, 7, 0 };
711
712 /* Head/sector mappings */
713 struct {
714 unsigned char heads;
715 unsigned char sectors;
716 } mapping_table[4] = {
717 { 16, 63 }, { 64, 32 }, { 64, 63 }, { 64, 32 }
718 };
719
720 struct config_1 {
721 unsigned char bios_segment: 3;
722 unsigned char removable_disks_as_fixed: 1;
723 unsigned char interrupt: 2;
724 unsigned char dma_channel: 2;
725 } config_1;
726
727 struct config_2 {
728 unsigned char ha_scsi_id: 3;
729 unsigned char mapping_mode: 2;
730 unsigned char bios_drive_number: 1;
731 unsigned char tfr_port: 2;
732 } config_2;
733
734 char name[16];
735
736 sprintf(name, "%s%d", driver_name, j);
737
738 if(!request_region(port_base, REGION_SIZE, driver_name)) {
739 #if defined(DEBUG_DETECT)
740 printk("%s: address 0x%03lx in use, skipping probe.\n", name, port_base);
741 #endif
742 return FALSE;
743 }
744
745 if (inb(port_base + REG_PRODUCT_ID1) != PRODUCT_ID1) {
746 release_region(port_base, REGION_SIZE);
747 return FALSE;
748 }
749
750 in_byte = inb(port_base + REG_PRODUCT_ID2);
751
752 if ((in_byte & 0xf0) != PRODUCT_ID2) {
753 release_region(port_base, REGION_SIZE);
754 return FALSE;
755 }
756
757 *(char *)&config_1 = inb(port_base + REG_CONFIG1);
758 *(char *)&config_2 = inb(port_base + REG_CONFIG2);
759
760 irq = interrupt_table[config_1.interrupt];
761 dma_channel = dma_channel_table[config_1.dma_channel];
762 subversion = (in_byte & 0x0f);
763
764 /* Board detected, allocate its IRQ */
765 if (request_irq(irq, do_interrupt_handler,
766 SA_INTERRUPT | ((subversion == ESA) ? SA_SHIRQ : 0),
767 driver_name, (void *) &sha[j])) {
768 printk("%s: unable to allocate IRQ %u, detaching.\n", name, irq);
769 release_region(port_base, REGION_SIZE);
770 return FALSE;
771 }
772
773 if (subversion == ISA && request_dma(dma_channel, driver_name)) {
774 printk("%s: unable to allocate DMA channel %u, detaching.\n",
775 name, dma_channel);
776 free_irq(irq, &sha[j]);
777 release_region(port_base, REGION_SIZE);
778 return FALSE;
779 }
780
781 if (have_old_firmware) tpnt->use_clustering = DISABLE_CLUSTERING;
782
783 sh[j] = scsi_register(tpnt, sizeof(struct hostdata));
784
785 if (sh[j] == NULL) {
786 printk("%s: unable to register host, detaching.\n", name);
787
788 free_irq(irq, &sha[j]);
789
790 if (subversion == ISA) free_dma(dma_channel);
791
792 release_region(port_base, REGION_SIZE);
793 return FALSE;
794 }
795
796 sh[j]->io_port = port_base;
797 sh[j]->unique_id = port_base;
798 sh[j]->n_io_port = REGION_SIZE;
799 sh[j]->base = bios_segment_table[config_1.bios_segment];
800 sh[j]->irq = irq;
801 sh[j]->sg_tablesize = MAX_SGLIST;
802 sh[j]->this_id = config_2.ha_scsi_id;
803 sh[j]->can_queue = MAX_MAILBOXES;
804 sh[j]->cmd_per_lun = MAX_CMD_PER_LUN;
805 sh[j]->select_queue_depths = select_queue_depths;
806
807 #if defined(DEBUG_DETECT)
808 {
809 unsigned char sys_mask, lcl_mask;
810
811 sys_mask = inb(sh[j]->io_port + REG_SYS_MASK);
812 lcl_mask = inb(sh[j]->io_port + REG_LCL_MASK);
813 printk("SYS_MASK 0x%x, LCL_MASK 0x%x.\n", sys_mask, lcl_mask);
814 }
815 #endif
816
817 /* Probably a bogus host scsi id, set it to the dummy value */
818 if (sh[j]->this_id == 0) sh[j]->this_id = -1;
819
820 /* If BIOS is disabled, force enable interrupts */
821 if (sh[j]->base == 0) outb(CMD_ENA_INTR, sh[j]->io_port + REG_SYS_MASK);
822
823 memset(HD(j), 0, sizeof(struct hostdata));
824 HD(j)->heads = mapping_table[config_2.mapping_mode].heads;
825 HD(j)->sectors = mapping_table[config_2.mapping_mode].sectors;
826 HD(j)->subversion = subversion;
827 HD(j)->board_number = j;
828
829 if (have_old_firmware) sh[j]->sg_tablesize = MAX_SAFE_SGLIST;
830
831 if (HD(j)->subversion == ESA) {
832 sh[j]->unchecked_isa_dma = FALSE;
833 sh[j]->dma_channel = NO_DMA;
834 sprintf(BN(j), "U34F%d", j);
835 bus_type = "VESA";
836 }
837 else {
838 unsigned long flags;
839 scsi_register_blocked_host(sh[j]);
840 sh[j]->unchecked_isa_dma = TRUE;
841
842 flags=claim_dma_lock();
843 disable_dma(dma_channel);
844 clear_dma_ff(dma_channel);
845 set_dma_mode(dma_channel, DMA_MODE_CASCADE);
846 enable_dma(dma_channel);
847 release_dma_lock(flags);
848
849 sh[j]->dma_channel = dma_channel;
850 sprintf(BN(j), "U14F%d", j);
851 bus_type = "ISA";
852 }
853
854 sh[j]->max_channel = MAX_CHANNEL - 1;
855 sh[j]->max_id = MAX_TARGET;
856 sh[j]->max_lun = MAX_LUN;
857
858 if (HD(j)->subversion == ISA && !board_inquiry(j)) {
859 HD(j)->board_id[40] = 0;
860
861 if (strcmp(&HD(j)->board_id[32], "06000600")) {
862 printk("%s: %s.\n", BN(j), &HD(j)->board_id[8]);
863 printk("%s: firmware %s is outdated, FW PROM should be 28004-006.\n",
864 BN(j), &HD(j)->board_id[32]);
865 sh[j]->hostt->use_clustering = DISABLE_CLUSTERING;
866 sh[j]->sg_tablesize = MAX_SAFE_SGLIST;
867 }
868 }
869
870 if (dma_channel == NO_DMA) sprintf(dma_name, "%s", "BMST");
871 else sprintf(dma_name, "DMA %u", dma_channel);
872
873 for (i = 0; i < sh[j]->can_queue; i++)
874 if (! ((&HD(j)->cp[i])->sglist = kmalloc(
875 sh[j]->sg_tablesize * sizeof(struct sg_list),
876 (sh[j]->unchecked_isa_dma ? GFP_DMA : 0) | GFP_ATOMIC))) {
877 printk("%s: kmalloc SGlist failed, mbox %d, detaching.\n", BN(j), i);
878 u14_34f_release(sh[j]);
879 return FALSE;
880 }
881
882 if (max_queue_depth > MAX_TAGGED_CMD_PER_LUN)
883 max_queue_depth = MAX_TAGGED_CMD_PER_LUN;
884
885 if (max_queue_depth < MAX_CMD_PER_LUN) max_queue_depth = MAX_CMD_PER_LUN;
886
887 if (j == 0) {
888 printk("UltraStor 14F/34F: Copyright (C) 1994-2001 Dario Ballabio.\n");
889 printk("%s config options -> of:%c, lc:%c, mq:%d, et:%c.\n",
890 driver_name, YESNO(have_old_firmware), YESNO(linked_comm),
891 max_queue_depth, YESNO(ext_tran));
892 }
893
894 printk("%s: %s 0x%03lx, BIOS 0x%05x, IRQ %u, %s, SG %d, MB %d.\n",
895 BN(j), bus_type, (unsigned long)sh[j]->io_port, (int)sh[j]->base,
896 sh[j]->irq, dma_name, sh[j]->sg_tablesize, sh[j]->can_queue);
897
898 if (sh[j]->max_id > 8 || sh[j]->max_lun > 8)
899 printk("%s: wide SCSI support enabled, max_id %u, max_lun %u.\n",
900 BN(j), sh[j]->max_id, sh[j]->max_lun);
901
902 for (i = 0; i <= sh[j]->max_channel; i++)
903 printk("%s: SCSI channel %u enabled, host target ID %d.\n",
904 BN(j), i, sh[j]->this_id);
905
906 return TRUE;
907 }
908
909 static void internal_setup(char *str, int *ints) {
910 int i, argc = ints[0];
911 char *cur = str, *pc;
912
913 if (argc > 0) {
914
915 if (argc > MAX_INT_PARAM) argc = MAX_INT_PARAM;
916
917 for (i = 0; i < argc; i++) io_port[i] = ints[i + 1];
918
919 io_port[i] = 0;
920 setup_done = TRUE;
921 }
922
923 while (cur && (pc = strchr(cur, ':'))) {
924 int val = 0, c = *++pc;
925
926 if (c == 'n' || c == 'N') val = FALSE;
927 else if (c == 'y' || c == 'Y') val = TRUE;
928 else val = (int) simple_strtoul(pc, NULL, 0);
929
930 if (!strncmp(cur, "lc:", 3)) linked_comm = val;
931 else if (!strncmp(cur, "of:", 3)) have_old_firmware = val;
932 else if (!strncmp(cur, "mq:", 3)) max_queue_depth = val;
933 else if (!strncmp(cur, "ls:", 3)) link_statistics = val;
934 else if (!strncmp(cur, "et:", 3)) ext_tran = val;
935
936 if ((cur = strchr(cur, ','))) ++cur;
937 }
938
939 return;
940 }
941
942 static int option_setup(char *str) {
943 int ints[MAX_INT_PARAM];
944 char *cur = str;
945 int i = 1;
946
947 while (cur && isdigit(*cur) && i <= MAX_INT_PARAM) {
948 ints[i++] = simple_strtoul(cur, NULL, 0);
949
950 if ((cur = strchr(cur, ',')) != NULL) cur++;
951 }
952
953 ints[0] = i - 1;
954 internal_setup(cur, ints);
955 return 1;
956 }
957
958 int u14_34f_detect(Scsi_Host_Template *tpnt)
959 {
960 unsigned int j = 0, k;
961
962 tpnt->proc_name = "u14-34f";
963
964 if(boot_options) option_setup(boot_options);
965
966 #if defined(MODULE)
967 /* io_port could have been modified when loading as a module */
968 if(io_port[0] != SKIP) {
969 setup_done = TRUE;
970 io_port[MAX_INT_PARAM] = 0;
971 }
972 #endif
973
974 for (k = 0; k < MAX_BOARDS + 1; k++) sh[k] = NULL;
975
976 for (k = 0; io_port[k]; k++) {
977
978 if (io_port[k] == SKIP) continue;
979
980 if (j < MAX_BOARDS && port_detect(io_port[k], j, tpnt)) j++;
981 }
982
983 num_boards = j;
984 return j;
985 }
986
987 static inline void build_sg_list(struct mscp *cpp, Scsi_Cmnd *SCpnt) {
988 unsigned int k, data_len = 0;
989 struct scatterlist *sgpnt;
990
991 sgpnt = (struct scatterlist *) SCpnt->request_buffer;
992
993 for (k = 0; k < SCpnt->use_sg; k++) {
994 cpp->sglist[k].address = V2DEV(sgpnt[k].address);
995 cpp->sglist[k].num_bytes = H2DEV(sgpnt[k].length);
996 data_len += sgpnt[k].length;
997 }
998
999 cpp->use_sg = SCpnt->use_sg;
1000 cpp->data_address = V2DEV(cpp->sglist);
1001 cpp->data_len = H2DEV(data_len);
1002 }
1003
1004 static inline int do_qcomm(Scsi_Cmnd *SCpnt, void (*done)(Scsi_Cmnd *)) {
1005 unsigned int i, j, k;
1006 struct mscp *cpp;
1007
1008 static const unsigned char data_out_cmds[] = {
1009 0x0a, 0x2a, 0x15, 0x55, 0x04, 0x07, 0x18, 0x1d, 0x24, 0x2e,
1010 0x30, 0x31, 0x32, 0x38, 0x39, 0x3a, 0x3b, 0x3d, 0x3f, 0x40,
1011 0x41, 0x4c, 0xaa, 0xae, 0xb0, 0xb1, 0xb2, 0xb6, 0xea, 0x1b, 0x5d
1012 };
1013
1014 static const unsigned char data_none_cmds[] = {
1015 0x01, 0x0b, 0x10, 0x11, 0x13, 0x16, 0x17, 0x19, 0x2b, 0x1e,
1016 0x2c, 0xac, 0x2f, 0xaf, 0x33, 0xb3, 0x35, 0x36, 0x45, 0x47,
1017 0x48, 0x49, 0xa9, 0x4b, 0xa5, 0xa6, 0xb5
1018 };
1019
1020 /* j is the board number */
1021 j = ((struct hostdata *) SCpnt->host->hostdata)->board_number;
1022
1023 if (SCpnt->host_scribble)
1024 panic("%s: qcomm, pid %ld, SCpnt %p already active.\n",
1025 BN(j), SCpnt->pid, SCpnt);
1026
1027 /* i is the mailbox number, look for the first free mailbox
1028 starting from last_cp_used */
1029 i = HD(j)->last_cp_used + 1;
1030
1031 for (k = 0; k < sh[j]->can_queue; k++, i++) {
1032
1033 if (i >= sh[j]->can_queue) i = 0;
1034
1035 if (HD(j)->cp_stat[i] == FREE) {
1036 HD(j)->last_cp_used = i;
1037 break;
1038 }
1039 }
1040
1041 if (k == sh[j]->can_queue) {
1042 printk("%s: qcomm, no free mailbox.\n", BN(j));
1043 return 1;
1044 }
1045
1046 /* Set pointer to control packet structure */
1047 cpp = &HD(j)->cp[i];
1048
1049 memset(cpp, 0, sizeof(struct mscp) - sizeof(struct sg_list *));
1050 SCpnt->scsi_done = done;
1051 cpp->index = i;
1052 SCpnt->host_scribble = (unsigned char *) &cpp->index;
1053
1054 if (do_trace) printk("%s: qcomm, mbox %d, target %d.%d:%d, pid %ld.\n",
1055 BN(j), i, SCpnt->channel, SCpnt->target,
1056 SCpnt->lun, SCpnt->pid);
1057
1058 cpp->xdir = DTD_IN;
1059
1060 for (k = 0; k < ARRAY_SIZE(data_out_cmds); k++)
1061 if (SCpnt->cmnd[0] == data_out_cmds[k]) {
1062 cpp->xdir = DTD_OUT;
1063 break;
1064 }
1065
1066 if (cpp->xdir == DTD_IN)
1067 for (k = 0; k < ARRAY_SIZE(data_none_cmds); k++)
1068 if (SCpnt->cmnd[0] == data_none_cmds[k]) {
1069 cpp->xdir = DTD_NONE;
1070 break;
1071 }
1072
1073 cpp->opcode = OP_SCSI;
1074 cpp->channel = SCpnt->channel;
1075 cpp->target = SCpnt->target;
1076 cpp->lun = SCpnt->lun;
1077 cpp->SCpnt = SCpnt;
1078 cpp->sense_addr = V2DEV(SCpnt->sense_buffer);
1079 cpp->sense_len = sizeof SCpnt->sense_buffer;
1080
1081 if (SCpnt->use_sg) {
1082 cpp->sg = TRUE;
1083 build_sg_list(cpp, SCpnt);
1084 }
1085 else {
1086 cpp->data_address = V2DEV(SCpnt->request_buffer);
1087 cpp->data_len = H2DEV(SCpnt->request_bufflen);
1088 }
1089
1090 cpp->scsi_cdbs_len = SCpnt->cmd_len;
1091 memcpy(cpp->scsi_cdbs, SCpnt->cmnd, cpp->scsi_cdbs_len);
1092
1093 if (linked_comm && SCpnt->device->queue_depth > 2
1094 && TLDEV(SCpnt->device->type)) {
1095 HD(j)->cp_stat[i] = READY;
1096 flush_dev(SCpnt->device, SCpnt->request.sector, j, FALSE);
1097 return 0;
1098 }
1099
1100 if (wait_on_busy(sh[j]->io_port, MAXLOOP)) {
1101 SCpnt->host_scribble = NULL;
1102 printk("%s: qcomm, target %d.%d:%d, pid %ld, adapter busy.\n",
1103 BN(j), SCpnt->channel, SCpnt->target, SCpnt->lun, SCpnt->pid);
1104 return 1;
1105 }
1106
1107 /* Store pointer in OGM address bytes */
1108 outl(V2DEV(cpp), sh[j]->io_port + REG_OGM);
1109
1110 /* Issue OGM interrupt */
1111 outb(CMD_OGM_INTR, sh[j]->io_port + REG_LCL_INTR);
1112
1113 HD(j)->cp_stat[i] = IN_USE;
1114 return 0;
1115 }
1116
1117 int u14_34f_queuecommand(Scsi_Cmnd *SCpnt, void (*done)(Scsi_Cmnd *)) {
1118 int rtn;
1119
1120 rtn = do_qcomm(SCpnt, done);
1121 return rtn;
1122 }
1123
1124 static inline int do_abort(Scsi_Cmnd *SCarg) {
1125 unsigned int i, j;
1126
1127 j = ((struct hostdata *) SCarg->host->hostdata)->board_number;
1128
1129 if (SCarg->host_scribble == NULL) {
1130 printk("%s: abort, target %d.%d:%d, pid %ld inactive.\n",
1131 BN(j), SCarg->channel, SCarg->target, SCarg->lun, SCarg->pid);
1132 return SUCCESS;
1133 }
1134
1135 i = *(unsigned int *)SCarg->host_scribble;
1136 printk("%s: abort, mbox %d, target %d.%d:%d, pid %ld.\n",
1137 BN(j), i, SCarg->channel, SCarg->target, SCarg->lun, SCarg->pid);
1138
1139 if (i >= sh[j]->can_queue)
1140 panic("%s: abort, invalid SCarg->host_scribble.\n", BN(j));
1141
1142 if (wait_on_busy(sh[j]->io_port, MAXLOOP)) {
1143 printk("%s: abort, timeout error.\n", BN(j));
1144 return FAILED;
1145 }
1146
1147 if (HD(j)->cp_stat[i] == FREE) {
1148 printk("%s: abort, mbox %d is free.\n", BN(j), i);
1149 return SUCCESS;
1150 }
1151
1152 if (HD(j)->cp_stat[i] == IN_USE) {
1153 printk("%s: abort, mbox %d is in use.\n", BN(j), i);
1154
1155 if (SCarg != HD(j)->cp[i].SCpnt)
1156 panic("%s: abort, mbox %d, SCarg %p, cp SCpnt %p.\n",
1157 BN(j), i, SCarg, HD(j)->cp[i].SCpnt);
1158
1159 if (inb(sh[j]->io_port + REG_SYS_INTR) & IRQ_ASSERTED)
1160 printk("%s: abort, mbox %d, interrupt pending.\n", BN(j), i);
1161
1162 if (SCarg->eh_state == SCSI_STATE_TIMEOUT) {
1163 SCarg->host_scribble = NULL;
1164 HD(j)->cp_stat[i] = FREE;
1165 printk("%s, abort, mbox %d, eh_state timeout, pid %ld.\n",
1166 BN(j), i, SCarg->pid);
1167 return SUCCESS;
1168 }
1169
1170 return FAILED;
1171 }
1172
1173 if (HD(j)->cp_stat[i] == IN_RESET) {
1174 printk("%s: abort, mbox %d is in reset.\n", BN(j), i);
1175 return FAILED;
1176 }
1177
1178 if (HD(j)->cp_stat[i] == LOCKED) {
1179 printk("%s: abort, mbox %d is locked.\n", BN(j), i);
1180 return SUCCESS;
1181 }
1182
1183 if (HD(j)->cp_stat[i] == READY || HD(j)->cp_stat[i] == ABORTING) {
1184 SCarg->result = DID_ABORT << 16;
1185 SCarg->host_scribble = NULL;
1186 HD(j)->cp_stat[i] = FREE;
1187 printk("%s, abort, mbox %d ready, DID_ABORT, pid %ld done.\n",
1188 BN(j), i, SCarg->pid);
1189 SCarg->scsi_done(SCarg);
1190 return SUCCESS;
1191 }
1192
1193 panic("%s: abort, mbox %d, invalid cp_stat.\n", BN(j), i);
1194 }
1195
1196 int u14_34f_abort(Scsi_Cmnd *SCarg) {
1197
1198 return do_abort(SCarg);
1199 }
1200
1201 static inline int do_reset(Scsi_Cmnd *SCarg) {
1202 unsigned int i, j, time, k, c, limit = 0;
1203 int arg_done = FALSE;
1204 Scsi_Cmnd *SCpnt;
1205
1206 j = ((struct hostdata *) SCarg->host->hostdata)->board_number;
1207 printk("%s: reset, enter, target %d.%d:%d, pid %ld.\n",
1208 BN(j), SCarg->channel, SCarg->target, SCarg->lun, SCarg->pid);
1209
1210 if (SCarg->host_scribble == NULL)
1211 printk("%s: reset, pid %ld inactive.\n", BN(j), SCarg->pid);
1212
1213 if (HD(j)->in_reset) {
1214 printk("%s: reset, exit, already in reset.\n", BN(j));
1215 return FAILED;
1216 }
1217
1218 if (wait_on_busy(sh[j]->io_port, MAXLOOP)) {
1219 printk("%s: reset, exit, timeout error.\n", BN(j));
1220 return FAILED;
1221 }
1222
1223 HD(j)->retries = 0;
1224
1225 for (c = 0; c <= sh[j]->max_channel; c++)
1226 for (k = 0; k < sh[j]->max_id; k++) {
1227 HD(j)->target_redo[k][c] = TRUE;
1228 HD(j)->target_to[k][c] = 0;
1229 }
1230
1231 for (i = 0; i < sh[j]->can_queue; i++) {
1232
1233 if (HD(j)->cp_stat[i] == FREE) continue;
1234
1235 if (HD(j)->cp_stat[i] == LOCKED) {
1236 HD(j)->cp_stat[i] = FREE;
1237 printk("%s: reset, locked mbox %d forced free.\n", BN(j), i);
1238 continue;
1239 }
1240
1241 if (!(SCpnt = HD(j)->cp[i].SCpnt))
1242 panic("%s: reset, mbox %d, SCpnt == NULL.\n", BN(j), i);
1243
1244 if (HD(j)->cp_stat[i] == READY || HD(j)->cp_stat[i] == ABORTING) {
1245 HD(j)->cp_stat[i] = ABORTING;
1246 printk("%s: reset, mbox %d aborting, pid %ld.\n",
1247 BN(j), i, SCpnt->pid);
1248 }
1249
1250 else {
1251 HD(j)->cp_stat[i] = IN_RESET;
1252 printk("%s: reset, mbox %d in reset, pid %ld.\n",
1253 BN(j), i, SCpnt->pid);
1254 }
1255
1256 if (SCpnt->host_scribble == NULL)
1257 panic("%s: reset, mbox %d, garbled SCpnt.\n", BN(j), i);
1258
1259 if (*(unsigned int *)SCpnt->host_scribble != i)
1260 panic("%s: reset, mbox %d, index mismatch.\n", BN(j), i);
1261
1262 if (SCpnt->scsi_done == NULL)
1263 panic("%s: reset, mbox %d, SCpnt->scsi_done == NULL.\n", BN(j), i);
1264
1265 if (SCpnt == SCarg) arg_done = TRUE;
1266 }
1267
1268 if (wait_on_busy(sh[j]->io_port, MAXLOOP)) {
1269 printk("%s: reset, cannot reset, timeout error.\n", BN(j));
1270 return FAILED;
1271 }
1272
1273 outb(CMD_RESET, sh[j]->io_port + REG_LCL_INTR);
1274 printk("%s: reset, board reset done, enabling interrupts.\n", BN(j));
1275
1276 #if defined(DEBUG_RESET)
1277 do_trace = TRUE;
1278 #endif
1279
1280 HD(j)->in_reset = TRUE;
1281 SPIN_UNLOCK
1282 time = jiffies;
1283 while ((jiffies - time) < (10 * HZ) && limit++ < 200000) udelay(100L);
1284 SPIN_LOCK
1285 printk("%s: reset, interrupts disabled, loops %d.\n", BN(j), limit);
1286
1287 for (i = 0; i < sh[j]->can_queue; i++) {
1288
1289 if (HD(j)->cp_stat[i] == IN_RESET) {
1290 SCpnt = HD(j)->cp[i].SCpnt;
1291 SCpnt->result = DID_RESET << 16;
1292 SCpnt->host_scribble = NULL;
1293
1294 /* This mailbox is still waiting for its interrupt */
1295 HD(j)->cp_stat[i] = LOCKED;
1296
1297 printk("%s, reset, mbox %d locked, DID_RESET, pid %ld done.\n",
1298 BN(j), i, SCpnt->pid);
1299 }
1300
1301 else if (HD(j)->cp_stat[i] == ABORTING) {
1302 SCpnt = HD(j)->cp[i].SCpnt;
1303 SCpnt->result = DID_RESET << 16;
1304 SCpnt->host_scribble = NULL;
1305
1306 /* This mailbox was never queued to the adapter */
1307 HD(j)->cp_stat[i] = FREE;
1308
1309 printk("%s, reset, mbox %d aborting, DID_RESET, pid %ld done.\n",
1310 BN(j), i, SCpnt->pid);
1311 }
1312
1313 else
1314
1315 /* Any other mailbox has already been set free by interrupt */
1316 continue;
1317
1318 SCpnt->scsi_done(SCpnt);
1319 }
1320
1321 HD(j)->in_reset = FALSE;
1322 do_trace = FALSE;
1323
1324 if (arg_done) printk("%s: reset, exit, pid %ld done.\n", BN(j), SCarg->pid);
1325 else printk("%s: reset, exit.\n", BN(j));
1326
1327 return SUCCESS;
1328 }
1329
1330 int u14_34f_reset(Scsi_Cmnd *SCarg) {
1331
1332 return do_reset(SCarg);
1333 }
1334
1335 int u14_34f_biosparam(Disk *disk, kdev_t dev, int *dkinfo) {
1336 unsigned int j = 0;
1337 int size = disk->capacity;
1338
1339 dkinfo[0] = HD(j)->heads;
1340 dkinfo[1] = HD(j)->sectors;
1341 dkinfo[2] = size / (HD(j)->heads * HD(j)->sectors);
1342
1343 if (ext_tran && (scsicam_bios_param(disk, dev, dkinfo) < 0)) {
1344 dkinfo[0] = 255;
1345 dkinfo[1] = 63;
1346 dkinfo[2] = size / (dkinfo[0] * dkinfo[1]);
1347 }
1348
1349 #if defined (DEBUG_GEOMETRY)
1350 printk ("%s: biosparam, head=%d, sec=%d, cyl=%d.\n", driver_name,
1351 dkinfo[0], dkinfo[1], dkinfo[2]);
1352 #endif
1353
1354 return FALSE;
1355 }
1356
1357 static void sort(unsigned long sk[], unsigned int da[], unsigned int n,
1358 unsigned int rev) {
1359 unsigned int i, j, k, y;
1360 unsigned long x;
1361
1362 for (i = 0; i < n - 1; i++) {
1363 k = i;
1364
1365 for (j = k + 1; j < n; j++)
1366 if (rev) {
1367 if (sk[j] > sk[k]) k = j;
1368 }
1369 else {
1370 if (sk[j] < sk[k]) k = j;
1371 }
1372
1373 if (k != i) {
1374 x = sk[k]; sk[k] = sk[i]; sk[i] = x;
1375 y = da[k]; da[k] = da[i]; da[i] = y;
1376 }
1377 }
1378
1379 return;
1380 }
1381
1382 static inline int reorder(unsigned int j, unsigned long cursec,
1383 unsigned int ihdlr, unsigned int il[], unsigned int n_ready) {
1384 Scsi_Cmnd *SCpnt;
1385 struct mscp *cpp;
1386 unsigned int k, n;
1387 unsigned int rev = FALSE, s = TRUE, r = TRUE;
1388 unsigned int input_only = TRUE, overlap = FALSE;
1389 unsigned long sl[n_ready], pl[n_ready], ll[n_ready];
1390 unsigned long maxsec = 0, minsec = ULONG_MAX, seek = 0, iseek = 0;
1391 unsigned long ioseek = 0;
1392
1393 static unsigned int flushcount = 0, batchcount = 0, sortcount = 0;
1394 static unsigned int readycount = 0, ovlcount = 0, inputcount = 0;
1395 static unsigned int readysorted = 0, revcount = 0;
1396 static unsigned long seeksorted = 0, seeknosort = 0;
1397
1398 if (link_statistics && !(++flushcount % link_statistics))
1399 printk("fc %d bc %d ic %d oc %d rc %d rs %d sc %d re %d"
1400 " av %ldK as %ldK.\n", flushcount, batchcount, inputcount,
1401 ovlcount, readycount, readysorted, sortcount, revcount,
1402 seeknosort / (readycount + 1),
1403 seeksorted / (readycount + 1));
1404
1405 if (n_ready <= 1) return FALSE;
1406
1407 for (n = 0; n < n_ready; n++) {
1408 k = il[n]; cpp = &HD(j)->cp[k]; SCpnt = cpp->SCpnt;
1409
1410 if (!(cpp->xdir == DTD_IN)) input_only = FALSE;
1411
1412 if (SCpnt->request.sector < minsec) minsec = SCpnt->request.sector;
1413 if (SCpnt->request.sector > maxsec) maxsec = SCpnt->request.sector;
1414
1415 sl[n] = SCpnt->request.sector;
1416 ioseek += SCpnt->request.nr_sectors;
1417
1418 if (!n) continue;
1419
1420 if (sl[n] < sl[n - 1]) s = FALSE;
1421 if (sl[n] > sl[n - 1]) r = FALSE;
1422
1423 if (link_statistics) {
1424 if (sl[n] > sl[n - 1])
1425 seek += sl[n] - sl[n - 1];
1426 else
1427 seek += sl[n - 1] - sl[n];
1428 }
1429
1430 }
1431
1432 if (link_statistics) {
1433 if (cursec > sl[0]) seek += cursec - sl[0]; else seek += sl[0] - cursec;
1434 }
1435
1436 if (cursec > ((maxsec + minsec) / 2)) rev = TRUE;
1437
1438 if (ioseek > ((maxsec - minsec) / 2)) rev = FALSE;
1439
1440 if (!((rev && r) || (!rev && s))) sort(sl, il, n_ready, rev);
1441
1442 if (!input_only) for (n = 0; n < n_ready; n++) {
1443 k = il[n]; cpp = &HD(j)->cp[k]; SCpnt = cpp->SCpnt;
1444 ll[n] = SCpnt->request.nr_sectors; pl[n] = SCpnt->pid;
1445
1446 if (!n) continue;
1447
1448 if ((sl[n] == sl[n - 1]) || (!rev && ((sl[n - 1] + ll[n - 1]) > sl[n]))
1449 || (rev && ((sl[n] + ll[n]) > sl[n - 1]))) overlap = TRUE;
1450 }
1451
1452 if (overlap) sort(pl, il, n_ready, FALSE);
1453
1454 if (link_statistics) {
1455 if (cursec > sl[0]) iseek = cursec - sl[0]; else iseek = sl[0] - cursec;
1456 batchcount++; readycount += n_ready; seeknosort += seek / 1024;
1457 if (input_only) inputcount++;
1458 if (overlap) { ovlcount++; seeksorted += iseek / 1024; }
1459 else seeksorted += (iseek + maxsec - minsec) / 1024;
1460 if (rev && !r) { revcount++; readysorted += n_ready; }
1461 if (!rev && !s) { sortcount++; readysorted += n_ready; }
1462 }
1463
1464 #if defined(DEBUG_LINKED_COMMANDS)
1465 if (link_statistics && (overlap || !(flushcount % link_statistics)))
1466 for (n = 0; n < n_ready; n++) {
1467 k = il[n]; cpp = &HD(j)->cp[k]; SCpnt = cpp->SCpnt;
1468 printk("%s %d.%d:%d pid %ld mb %d fc %d nr %d sec %ld ns %ld"
1469 " cur %ld s:%c r:%c rev:%c in:%c ov:%c xd %d.\n",
1470 (ihdlr ? "ihdlr" : "qcomm"), SCpnt->channel, SCpnt->target,
1471 SCpnt->lun, SCpnt->pid, k, flushcount, n_ready,
1472 SCpnt->request.sector, SCpnt->request.nr_sectors, cursec,
1473 YESNO(s), YESNO(r), YESNO(rev), YESNO(input_only),
1474 YESNO(overlap), cpp->xdir);
1475 }
1476 #endif
1477 return overlap;
1478 }
1479
1480 static void flush_dev(Scsi_Device *dev, unsigned long cursec, unsigned int j,
1481 unsigned int ihdlr) {
1482 Scsi_Cmnd *SCpnt;
1483 struct mscp *cpp;
1484 unsigned int k, n, n_ready = 0, il[MAX_MAILBOXES];
1485
1486 for (k = 0; k < sh[j]->can_queue; k++) {
1487
1488 if (HD(j)->cp_stat[k] != READY && HD(j)->cp_stat[k] != IN_USE) continue;
1489
1490 cpp = &HD(j)->cp[k]; SCpnt = cpp->SCpnt;
1491
1492 if (SCpnt->device != dev) continue;
1493
1494 if (HD(j)->cp_stat[k] == IN_USE) return;
1495
1496 il[n_ready++] = k;
1497 }
1498
1499 if (reorder(j, cursec, ihdlr, il, n_ready)) n_ready = 1;
1500
1501 for (n = 0; n < n_ready; n++) {
1502 k = il[n]; cpp = &HD(j)->cp[k]; SCpnt = cpp->SCpnt;
1503
1504 if (wait_on_busy(sh[j]->io_port, MAXLOOP)) {
1505 printk("%s: %s, target %d.%d:%d, pid %ld, mbox %d, adapter"
1506 " busy, will abort.\n", BN(j), (ihdlr ? "ihdlr" : "qcomm"),
1507 SCpnt->channel, SCpnt->target, SCpnt->lun, SCpnt->pid, k);
1508 HD(j)->cp_stat[k] = ABORTING;
1509 continue;
1510 }
1511
1512 outl(V2DEV(cpp), sh[j]->io_port + REG_OGM);
1513 outb(CMD_OGM_INTR, sh[j]->io_port + REG_LCL_INTR);
1514 HD(j)->cp_stat[k] = IN_USE;
1515 }
1516
1517 }
1518
1519 static inline void ihdlr(int irq, unsigned int j) {
1520 Scsi_Cmnd *SCpnt;
1521 unsigned int i, k, c, status, tstatus, reg, ret;
1522 struct mscp *spp, *cpp;
1523
1524 if (sh[j]->irq != irq)
1525 panic("%s: ihdlr, irq %d, sh[j]->irq %d.\n", BN(j), irq, sh[j]->irq);
1526
1527 /* Check if this board need to be serviced */
1528 if (!((reg = inb(sh[j]->io_port + REG_SYS_INTR)) & IRQ_ASSERTED)) return;
1529
1530 HD(j)->iocount++;
1531
1532 if (do_trace) printk("%s: ihdlr, enter, irq %d, count %d.\n", BN(j), irq,
1533 HD(j)->iocount);
1534
1535 /* Check if this board is still busy */
1536 if (wait_on_busy(sh[j]->io_port, 20 * MAXLOOP)) {
1537 outb(CMD_CLR_INTR, sh[j]->io_port + REG_SYS_INTR);
1538 printk("%s: ihdlr, busy timeout error, irq %d, reg 0x%x, count %d.\n",
1539 BN(j), irq, reg, HD(j)->iocount);
1540 return;
1541 }
1542
1543 spp = (struct mscp *)DEV2V(ret = inl(sh[j]->io_port + REG_ICM));
1544 cpp = spp;
1545
1546 /* Clear interrupt pending flag */
1547 outb(CMD_CLR_INTR, sh[j]->io_port + REG_SYS_INTR);
1548
1549 #if defined(DEBUG_GENERATE_ABORTS)
1550 if ((HD(j)->iocount > 500) && ((HD(j)->iocount % 500) < 3)) return;
1551 #endif
1552
1553 /* Find the mailbox to be serviced on this board */
1554 i = cpp - HD(j)->cp;
1555
1556 if (cpp < HD(j)->cp || cpp >= HD(j)->cp + sh[j]->can_queue
1557 || i >= sh[j]->can_queue)
1558 panic("%s: ihdlr, invalid mscp bus address %p, cp0 %p.\n", BN(j),
1559 (void *)ret, HD(j)->cp);
1560
1561 if (HD(j)->cp_stat[i] == IGNORE) {
1562 HD(j)->cp_stat[i] = FREE;
1563 return;
1564 }
1565 else if (HD(j)->cp_stat[i] == LOCKED) {
1566 HD(j)->cp_stat[i] = FREE;
1567 printk("%s: ihdlr, mbox %d unlocked, count %d.\n", BN(j), i,
1568 HD(j)->iocount);
1569 return;
1570 }
1571 else if (HD(j)->cp_stat[i] == FREE) {
1572 printk("%s: ihdlr, mbox %d is free, count %d.\n", BN(j), i,
1573 HD(j)->iocount);
1574 return;
1575 }
1576 else if (HD(j)->cp_stat[i] == IN_RESET)
1577 printk("%s: ihdlr, mbox %d is in reset.\n", BN(j), i);
1578 else if (HD(j)->cp_stat[i] != IN_USE)
1579 panic("%s: ihdlr, mbox %d, invalid cp_stat: %d.\n",
1580 BN(j), i, HD(j)->cp_stat[i]);
1581
1582 HD(j)->cp_stat[i] = FREE;
1583 SCpnt = cpp->SCpnt;
1584
1585 if (SCpnt == NULL) panic("%s: ihdlr, mbox %d, SCpnt == NULL.\n", BN(j), i);
1586
1587 if (SCpnt->host_scribble == NULL)
1588 panic("%s: ihdlr, mbox %d, pid %ld, SCpnt %p garbled.\n", BN(j), i,
1589 SCpnt->pid, SCpnt);
1590
1591 if (*(unsigned int *)SCpnt->host_scribble != i)
1592 panic("%s: ihdlr, mbox %d, pid %ld, index mismatch %d.\n",
1593 BN(j), i, SCpnt->pid, *(unsigned int *)SCpnt->host_scribble);
1594
1595 if (linked_comm && SCpnt->device->queue_depth > 2
1596 && TLDEV(SCpnt->device->type))
1597 flush_dev(SCpnt->device, SCpnt->request.sector, j, TRUE);
1598
1599 tstatus = status_byte(spp->target_status);
1600
1601 #if defined(DEBUG_GENERATE_ERRORS)
1602 if ((HD(j)->iocount > 500) && ((HD(j)->iocount % 200) < 2))
1603 spp->adapter_status = 0x01;
1604 #endif
1605
1606 switch (spp->adapter_status) {
1607 case ASOK: /* status OK */
1608
1609 /* Forces a reset if a disk drive keeps returning BUSY */
1610 if (tstatus == BUSY && SCpnt->device->type != TYPE_TAPE)
1611 status = DID_ERROR << 16;
1612
1613 /* If there was a bus reset, redo operation on each target */
1614 else if (tstatus != GOOD && SCpnt->device->type == TYPE_DISK
1615 && HD(j)->target_redo[SCpnt->target][SCpnt->channel])
1616 status = DID_BUS_BUSY << 16;
1617
1618 /* Works around a flaw in scsi.c */
1619 else if (tstatus == CHECK_CONDITION
1620 && SCpnt->device->type == TYPE_DISK
1621 && (SCpnt->sense_buffer[2] & 0xf) == RECOVERED_ERROR)
1622 status = DID_BUS_BUSY << 16;
1623
1624 else
1625 status = DID_OK << 16;
1626
1627 if (tstatus == GOOD)
1628 HD(j)->target_redo[SCpnt->target][SCpnt->channel] = FALSE;
1629
1630 if (spp->target_status && SCpnt->device->type == TYPE_DISK &&
1631 (!(tstatus == CHECK_CONDITION && HD(j)->iocount <= 1000 &&
1632 (SCpnt->sense_buffer[2] & 0xf) == NOT_READY)))
1633 printk("%s: ihdlr, target %d.%d:%d, pid %ld, "
1634 "target_status 0x%x, sense key 0x%x.\n", BN(j),
1635 SCpnt->channel, SCpnt->target, SCpnt->lun,
1636 SCpnt->pid, spp->target_status,
1637 SCpnt->sense_buffer[2]);
1638
1639 HD(j)->target_to[SCpnt->target][SCpnt->channel] = 0;
1640
1641 if (HD(j)->last_retried_pid == SCpnt->pid) HD(j)->retries = 0;
1642
1643 break;
1644 case ASST: /* Selection Time Out */
1645
1646 if (HD(j)->target_to[SCpnt->target][SCpnt->channel] > 1)
1647 status = DID_ERROR << 16;
1648 else {
1649 status = DID_TIME_OUT << 16;
1650 HD(j)->target_to[SCpnt->target][SCpnt->channel]++;
1651 }
1652
1653 break;
1654
1655 /* Perform a limited number of internal retries */
1656 case 0x93: /* Unexpected bus free */
1657 case 0x94: /* Target bus phase sequence failure */
1658 case 0x96: /* Illegal SCSI command */
1659 case 0xa3: /* SCSI bus reset error */
1660
1661 for (c = 0; c <= sh[j]->max_channel; c++)
1662 for (k = 0; k < sh[j]->max_id; k++)
1663 HD(j)->target_redo[k][c] = TRUE;
1664
1665
1666 case 0x92: /* Data over/under-run */
1667
1668 if (SCpnt->device->type != TYPE_TAPE
1669 && HD(j)->retries < MAX_INTERNAL_RETRIES) {
1670
1671 #if defined(DID_SOFT_ERROR)
1672 status = DID_SOFT_ERROR << 16;
1673 #else
1674 status = DID_BUS_BUSY << 16;
1675 #endif
1676
1677 HD(j)->retries++;
1678 HD(j)->last_retried_pid = SCpnt->pid;
1679 }
1680 else
1681 status = DID_ERROR << 16;
1682
1683 break;
1684 case 0x01: /* Invalid command */
1685 case 0x02: /* Invalid parameters */
1686 case 0x03: /* Invalid data list */
1687 case 0x84: /* SCSI bus abort error */
1688 case 0x9b: /* Auto request sense error */
1689 case 0x9f: /* Unexpected command complete message error */
1690 case 0xff: /* Invalid parameter in the S/G list */
1691 default:
1692 status = DID_ERROR << 16;
1693 break;
1694 }
1695
1696 SCpnt->result = status | spp->target_status;
1697
1698 #if defined(DEBUG_INTERRUPT)
1699 if (SCpnt->result || do_trace)
1700 #else
1701 if ((spp->adapter_status != ASOK && HD(j)->iocount > 1000) ||
1702 (spp->adapter_status != ASOK &&
1703 spp->adapter_status != ASST && HD(j)->iocount <= 1000) ||
1704 do_trace || msg_byte(spp->target_status))
1705 #endif
1706 printk("%s: ihdlr, mbox %2d, err 0x%x:%x,"
1707 " target %d.%d:%d, pid %ld, reg 0x%x, count %d.\n",
1708 BN(j), i, spp->adapter_status, spp->target_status,
1709 SCpnt->channel, SCpnt->target, SCpnt->lun, SCpnt->pid,
1710 reg, HD(j)->iocount);
1711
1712 /* Set the command state to inactive */
1713 SCpnt->host_scribble = NULL;
1714
1715 SCpnt->scsi_done(SCpnt);
1716
1717 if (do_trace) printk("%s: ihdlr, exit, irq %d, count %d.\n", BN(j), irq,
1718 HD(j)->iocount);
1719
1720 return;
1721 }
1722
1723 static void do_interrupt_handler(int irq, void *shap, struct pt_regs *regs) {
1724 unsigned int j;
1725 SPIN_FLAGS
1726
1727 /* Check if the interrupt must be processed by this handler */
1728 if ((j = (unsigned int)((char *)shap - sha)) >= num_boards) return;
1729
1730 SPIN_LOCK_SAVE
1731 ihdlr(irq, j);
1732 SPIN_UNLOCK_RESTORE
1733 }
1734
1735 int u14_34f_release(struct Scsi_Host *shpnt) {
1736 unsigned int i, j;
1737
1738 for (j = 0; sh[j] != NULL && sh[j] != shpnt; j++);
1739
1740 if (sh[j] == NULL) panic("%s: release, invalid Scsi_Host pointer.\n",
1741 driver_name);
1742
1743 if( sh[j]->unchecked_isa_dma ) {
1744 scsi_deregister_blocked_host(sh[j]);
1745 }
1746
1747 for (i = 0; i < sh[j]->can_queue; i++)
1748 if ((&HD(j)->cp[i])->sglist) kfree((&HD(j)->cp[i])->sglist);
1749
1750 free_irq(sh[j]->irq, &sha[j]);
1751
1752 if (sh[j]->dma_channel != NO_DMA) free_dma(sh[j]->dma_channel);
1753
1754 release_region(sh[j]->io_port, sh[j]->n_io_port);
1755 scsi_unregister(sh[j]);
1756 return FALSE;
1757 }
1758
1759 static Scsi_Host_Template driver_template = ULTRASTOR_14_34F;
1760
1761 #include "scsi_module.c"
1762
1763 #ifndef MODULE
1764 __setup("u14-34f=", option_setup);
1765 #endif /* end MODULE */
1766