|
|
1.1 root 1: /*
2: * eata.c - Low-level driver for EATA/DMA SCSI host adapters.
3: *
4: * 26 Jul 1998 Rev. 4.33 for linux 2.0.35 and 2.1.111
5: * + Added command line option (rs:[y|n]) to reverse the scan order
6: * of PCI boards. The default is rs:y, which reverses the BIOS order
7: * while registering PCI boards. The default value rs:y generates
8: * the same order of all previous revisions of this driver.
9: * Pls. note that "BIOS order" might have been reversed itself
10: * after the 2.1.9x PCI modifications in the linux kernel.
11: * The rs value is ignored when the explicit list of addresses
12: * is used by the "eata=port0,port1,..." command line option.
13: * + Added command line option (et:[y|n]) to force use of extended
14: * translation (255 heads, 63 sectors) as disk geometry.
15: * The default is et:n, which uses the disk geometry returned
16: * by scsicam_bios_param. The default value et:n is compatible with
17: * all previous revisions of this driver.
18: *
19: * 28 May 1998 Rev. 4.32 for linux 2.0.33 and 2.1.104
20: * Increased busy timeout from 10 msec. to 200 msec. while
21: * processing interrupts.
22: *
23: * 16 May 1998 Rev. 4.31 for linux 2.0.33 and 2.1.102
24: * Improved abort handling during the eh recovery process.
25: *
26: * 13 May 1998 Rev. 4.30 for linux 2.0.33 and 2.1.101
27: * The driver is now fully SMP safe, including the
28: * abort and reset routines.
29: * Added command line options (eh:[y|n]) to choose between
30: * new_eh_code and the old scsi code.
31: * If linux version >= 2.1.101 the default is eh:y, while the eh
32: * option is ignored for previous releases and the old scsi code
33: * is used.
34: *
35: * 18 Apr 1998 Rev. 4.20 for linux 2.0.33 and 2.1.97
36: * Reworked interrupt handler.
37: *
38: * 11 Apr 1998 rev. 4.05 for linux 2.0.33 and 2.1.95
39: * Major reliability improvement: when a batch with overlapping
40: * requests is detected, requests are queued one at a time
41: * eliminating any possible board or drive reordering.
42: *
43: * 10 Apr 1998 rev. 4.04 for linux 2.0.33 and 2.1.95
44: * Improved SMP support (if linux version >= 2.1.95).
45: *
46: * 9 Apr 1998 rev. 4.03 for linux 2.0.33 and 2.1.94
47: * Added support for new PCI code and IO-APIC remapping of irqs.
48: * Performance improvement: when sequential i/o is detected,
49: * always use direct sort instead of reverse sort.
50: *
51: * 4 Apr 1998 rev. 4.02 for linux 2.0.33 and 2.1.92
52: * io_port is now unsigned long.
53: *
54: * 17 Mar 1998 rev. 4.01 for linux 2.0.33 and 2.1.88
55: * Use new scsi error handling code (if linux version >= 2.1.88).
56: * Use new interrupt code.
57: *
58: * 12 Sep 1997 rev. 3.11 for linux 2.0.30 and 2.1.55
59: * Use of udelay inside the wait loops to avoid timeout
60: * problems with fast cpus.
61: * Removed check about useless calls to the interrupt service
62: * routine (reported on SMP systems only).
63: * At initialization time "sorted/unsorted" is displayed instead
64: * of "linked/unlinked" to reinforce the fact that "linking" is
65: * nothing but "elevator sorting" in the actual implementation.
66: *
67: * 17 May 1997 rev. 3.10 for linux 2.0.30 and 2.1.38
68: * Use of serial_number_at_timeout in abort and reset processing.
69: * Use of the __initfunc and __initdata macro in setup code.
70: * Minor cleanups in the list_statistics code.
71: * Increased controller busy timeout in order to better support
72: * slow SCSI devices.
73: *
74: * 24 Feb 1997 rev. 3.00 for linux 2.0.29 and 2.1.26
75: * When loading as a module, parameter passing is now supported
76: * both in 2.0 and in 2.1 style.
77: * Fixed data transfer direction for some SCSI opcodes.
78: * Immediate acknowledge to request sense commands.
79: * Linked commands to each disk device are now reordered by elevator
80: * sorting. Rare cases in which reordering of write requests could
81: * cause wrong results are managed.
82: * Fixed spurious timeouts caused by long simple queue tag sequences.
83: * New command line option (tm:[0-3]) to choose the type of tags:
84: * 0 -> mixed (default); 1 -> simple; 2 -> head; 3 -> ordered.
85: *
86: * 18 Jan 1997 rev. 2.60 for linux 2.1.21 and 2.0.28
87: * Added command line options to enable/disable linked commands
88: * (lc:[y|n]), tagged commands (tc:[y|n]) and to set the max queue
89: * depth (mq:xx). Default is "eata=lc:n,tc:n,mq:16".
90: * Improved command linking.
91: * Documented how to setup RAID-0 with DPT SmartRAID boards.
92: *
93: * 8 Jan 1997 rev. 2.50 for linux 2.1.20 and 2.0.27
94: * Added linked command support.
95: * Improved detection of PCI boards using ISA base addresses.
96: *
97: * 3 Dec 1996 rev. 2.40 for linux 2.1.14 and 2.0.27
98: * Added support for tagged commands and queue depth adjustment.
99: *
100: * 22 Nov 1996 rev. 2.30 for linux 2.1.12 and 2.0.26
101: * When CONFIG_PCI is defined, BIOS32 is used to include in the
102: * list of i/o ports to be probed all the PCI SCSI controllers.
103: * The list of i/o ports to be probed can be overwritten by the
104: * "eata=port0,port1,...." boot command line option.
105: * Scatter/gather lists are now allocated by a number of kmalloc
106: * calls, in order to avoid the previous size limit of 64Kb.
107: *
108: * 16 Nov 1996 rev. 2.20 for linux 2.1.10 and 2.0.25
109: * Added support for EATA 2.0C, PCI, multichannel and wide SCSI.
110: *
111: * 27 Sep 1996 rev. 2.12 for linux 2.1.0
112: * Portability cleanups (virtual/bus addressing, little/big endian
113: * support).
114: *
115: * 09 Jul 1996 rev. 2.11 for linux 2.0.4
116: * Number of internal retries is now limited.
117: *
118: * 16 Apr 1996 rev. 2.10 for linux 1.3.90
119: * New argument "reset_flags" to the reset routine.
120: *
121: * 6 Jul 1995 rev. 2.01 for linux 1.3.7
122: * Update required by the new /proc/scsi support.
123: *
124: * 11 Mar 1995 rev. 2.00 for linux 1.2.0
125: * Fixed a bug which prevented media change detection for removable
126: * disk drives.
127: *
128: * 23 Feb 1995 rev. 1.18 for linux 1.1.94
129: * Added a check for scsi_register returning NULL.
130: *
131: * 11 Feb 1995 rev. 1.17 for linux 1.1.91
132: * Now DEBUG_RESET is disabled by default.
133: * Register a board even if it does not assert DMA protocol support
134: * (DPT SK2011B does not report correctly the dmasup bit).
135: *
136: * 9 Feb 1995 rev. 1.16 for linux 1.1.90
137: * Use host->wish_block instead of host->block.
138: * New list of Data Out SCSI commands.
139: *
140: * 8 Feb 1995 rev. 1.15 for linux 1.1.89
141: * Cleared target_time_out counter while performing a reset.
142: * All external symbols renamed to avoid possible name conflicts.
143: *
144: * 28 Jan 1995 rev. 1.14 for linux 1.1.86
145: * Added module support.
146: * Log and do a retry when a disk drive returns a target status
147: * different from zero on a recovered error.
148: *
149: * 24 Jan 1995 rev. 1.13 for linux 1.1.85
150: * Use optimized board configuration, with a measured performance
151: * increase in the range 10%-20% on i/o throughput.
152: *
153: * 16 Jan 1995 rev. 1.12 for linux 1.1.81
154: * Fix mscp structure comments (no functional change).
155: * Display a message if check_region detects a port address
156: * already in use.
157: *
158: * 17 Dec 1994 rev. 1.11 for linux 1.1.74
159: * Use the scsicam_bios_param routine. This allows an easy
160: * migration path from disk partition tables created using
161: * different SCSI drivers and non optimal disk geometry.
162: *
163: * 15 Dec 1994 rev. 1.10 for linux 1.1.74
164: * Added support for ISA EATA boards (DPT PM2011, DPT PM2021).
165: * The host->block flag is set for all the detected ISA boards.
166: * The detect routine no longer enforces LEVEL triggering
167: * for EISA boards, it just prints a warning message.
168: *
169: * 30 Nov 1994 rev. 1.09 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: * 18 Nov 1994 rev. 1.08 for linux 1.1.64
174: * Forces sg_tablesize = 64 and can_queue = 64 if these
175: * values are not correctly detected (DPT PM2012).
176: *
177: * 14 Nov 1994 rev. 1.07 for linux 1.1.63 Final BETA release.
178: * 04 Aug 1994 rev. 1.00 for linux 1.1.39 First BETA release.
179: *
180: *
181: * This driver is based on the CAM (Common Access Method Committee)
182: * EATA (Enhanced AT Bus Attachment) rev. 2.0A, using DMA protocol.
183: *
184: * Copyright (C) 1994-1998 Dario Ballabio ([email protected])
185: *
186: * Redistribution and use in source and binary forms, with or without
187: * modification, are permitted provided that redistributions of source
188: * code retain the above copyright notice and this comment without
189: * modification.
190: *
191: */
192:
193: /*
194: *
195: * Here is a brief description of the DPT SCSI host adapters.
196: * All these boards provide an EATA/DMA compatible programming interface
197: * and are fully supported by this driver in any configuration, including
198: * multiple SCSI channels:
199: *
200: * PM2011B/9X - Entry Level ISA
201: * PM2021A/9X - High Performance ISA
202: * PM2012A Old EISA
203: * PM2012B Old EISA
204: * PM2022A/9X - Entry Level EISA
205: * PM2122A/9X - High Performance EISA
206: * PM2322A/9X - Extra High Performance EISA
207: * PM3021 - SmartRAID Adapter for ISA
208: * PM3222 - SmartRAID Adapter for EISA (PM3222W is 16-bit wide SCSI)
209: * PM3224 - SmartRAID Adapter for PCI (PM3224W is 16-bit wide SCSI)
210: *
211: * The above list is just an indication: as a matter of fact all DPT
212: * boards using the EATA/DMA protocol are supported by this driver,
213: * since they use exactely the same programming interface.
214: *
215: * The DPT PM2001 provides only the EATA/PIO interface and hence is not
216: * supported by this driver.
217: *
218: * This code has been tested with up to 3 Distributed Processing Technology
219: * PM2122A/9X (DPT SCSI BIOS v002.D1, firmware v05E.0) EISA controllers,
220: * in any combination of private and shared IRQ.
221: * PCI support has been tested using up to 2 DPT PM3224W (DPT SCSI BIOS
222: * v003.D0, firmware v07G.0).
223: *
224: * DPT SmartRAID boards support "Hardware Array" - a group of disk drives
225: * which are all members of the same RAID-0, RAID-1 or RAID-5 array implemented
226: * in host adapter hardware. Hardware Arrays are fully compatible with this
227: * driver, since they look to it as a single disk drive.
228: *
229: * WARNING: to create a RAID-0 "Hardware Array" you must select "Other Unix"
230: * as the current OS in the DPTMGR "Initial System Installation" menu.
231: * Otherwise RAID-0 is generated as an "Array Group" (i.e. software RAID-0),
232: * which is not supported by the actual SCSI subsystem.
233: * To get the "Array Group" functionality, the Linux MD driver must be used
234: * instead of the DPT "Array Group" feature.
235: *
236: * Multiple ISA, EISA and PCI boards can be configured in the same system.
237: * It is suggested to put all the EISA boards on the same IRQ level, all
238: * the PCI boards on another IRQ level, while ISA boards cannot share
239: * interrupts.
240: *
241: * If you configure multiple boards on the same IRQ, the interrupt must
242: * be _level_ triggered (not _edge_ triggered).
243: *
244: * This driver detects EATA boards by probes at fixed port addresses,
245: * so no BIOS32 or PCI BIOS support is required.
246: * The suggested way to detect a generic EATA PCI board is to force on it
247: * any unused EISA address, even if there are other controllers on the EISA
248: * bus, or even if you system has no EISA bus at all.
249: * Do not force any ISA address on EATA PCI boards.
250: *
251: * If PCI bios support is configured into the kernel, BIOS32 is used to
252: * include in the list of i/o ports to be probed all the PCI SCSI controllers.
253: *
254: * Due to a DPT BIOS "feature", it might not be possible to force an EISA
255: * address on more then a single DPT PCI board, so in this case you have to
256: * let the PCI BIOS assign the addresses.
257: *
258: * The sequence of detection probes is:
259: *
260: * - ISA 0x1F0;
261: * - PCI SCSI controllers (only if BIOS32 is available);
262: * - EISA/PCI 0x1C88 through 0xFC88 (corresponding to EISA slots 1 to 15);
263: * - ISA 0x170, 0x230, 0x330.
264: *
265: * The above list of detection probes can be totally replaced by the
266: * boot command line option: "eata=port0,port1,port2,...", where the
267: * port0, port1... arguments are ISA/EISA/PCI addresses to be probed.
268: * For example using "eata=0x7410,0x7450,0x230", the driver probes
269: * only the two PCI addresses 0x7410 and 0x7450 and the ISA address 0x230,
270: * in this order; "eata=0" totally disables this driver.
271: *
272: * After the optional list of detection probes, other possible command line
273: * options are:
274: *
275: * eh:y use new scsi code (linux 2.2 only);
276: * eh:n use old scsi code;
277: * et:y force use of extended translation (255 heads, 63 sectors);
278: * et:n use disk geometry detected by scsicam_bios_param;
279: * rs:y reverse scan order while detecting PCI boards;
280: * rs:n use BIOS order while detecting PCI boards;
281: * lc:y enables linked commands;
282: * lc:n disables linked commands;
283: * tc:y enables tagged commands;
284: * tc:n disables tagged commands;
285: * tm:0 use head/simple/ordered queue tag sequences;
286: * tm:1 use only simple queue tags;
287: * tm:2 use only head of queue tags;
288: * tm:3 use only ordered queue tags;
289: * mq:xx set the max queue depth to the value xx (2 <= xx <= 32).
290: *
291: * The default value is: "eata=lc:n,tc:n,mq:16,tm:0,et:n,rs:n".
292: * An example using the list of detection probes could be:
293: * "eata=0x7410,0x230,lc:y,tc:n,mq:4,eh:n,et:n".
294: *
295: * When loading as a module, parameters can be specified as well.
296: * The above example would be (use 1 in place of y and 0 in place of n):
297: *
298: * modprobe eata io_port=0x7410,0x230 linked_comm=1 tagged_comm=0 \
299: * max_queue_depth=4 tag_mode=0 use_new_eh_code=0 \
300: * ext_tran=0 rev_scan=1
301: *
302: * ----------------------------------------------------------------------------
303: * In this implementation, linked commands are designed to work with any DISK
304: * or CD-ROM, since this linking has only the intent of clustering (time-wise)
305: * and reordering by elevator sorting commands directed to each device,
306: * without any relation with the actual SCSI protocol between the controller
307: * and the device.
308: * If Q is the queue depth reported at boot time for each device (also named
309: * cmds/lun) and Q > 2, whenever there is already an active command to the
310: * device all other commands to the same device (up to Q-1) are kept waiting
311: * in the elevator sorting queue. When the active command completes, the
312: * commands in this queue are sorted by sector address. The sort is chosen
313: * between increasing or decreasing by minimizing the seek distance between
314: * the sector of the commands just completed and the sector of the first
315: * command in the list to be sorted.
316: * Trivial math assures that the unsorted average seek distance when doing
317: * random seeks over S sectors is S/3.
318: * When (Q-1) requests are uniformly distributed over S sectors, the average
319: * distance between two adjacent requests is S/((Q-1) + 1), so the sorted
320: * average seek distance for (Q-1) random requests over S sectors is S/Q.
321: * The elevator sorting hence divides the seek distance by a factor Q/3.
322: * The above pure geometric remarks are valid in all cases and the
323: * driver effectively reduces the seek distance by the predicted factor
324: * when there are Q concurrent read i/o operations on the device, but this
325: * does not necessarily results in a noticeable performance improvement:
326: * your mileage may vary....
327: *
328: * Note: command reordering inside a batch of queued commands could cause
329: * wrong results only if there is at least one write request and the
330: * intersection (sector-wise) of all requests is not empty.
331: * When the driver detects a batch including overlapping requests
332: * (a really rare event) strict serial (pid) order is enforced.
333: * ----------------------------------------------------------------------------
334: * The extended translation option (et:y) is useful when using large physical
335: * disks/arrays. It could also be useful when switching between Adaptec boards
336: * and DPT boards without reformatting the disk.
337: * When a boot disk is partitioned with extended translation, in order to
338: * be able to boot it with a DPT board is could be necessary to add to
339: * lilo.conf additional commands as in the following example:
340: *
341: * fix-table
342: * disk=/dev/sda bios=0x80 sectors=63 heads=128 cylindres=546
343: *
344: * where the above geometry should be replaced with the one reported at
345: * power up by the DPT controller.
346: * ----------------------------------------------------------------------------
347: *
348: * The boards are named EATA0, EATA1,... according to the detection order.
349: *
350: * In order to support multiple ISA boards in a reliable way,
351: * the driver sets host->wish_block = TRUE for all ISA boards.
352: */
353:
354: #include <linux/version.h>
355:
356: #define LinuxVersionCode(v, p, s) (((v)<<16)+((p)<<8)+(s))
357: #define MAX_INT_PARAM 10
358:
359: #if defined(MODULE)
360: #include <linux/module.h>
361:
362: #if LINUX_VERSION_CODE >= LinuxVersionCode(2,1,26)
363: MODULE_PARM(io_port, "1-" __MODULE_STRING(MAX_INT_PARAM) "i");
364: MODULE_PARM(linked_comm, "i");
365: MODULE_PARM(tagged_comm, "i");
366: MODULE_PARM(link_statistics, "i");
367: MODULE_PARM(max_queue_depth, "i");
368: MODULE_PARM(tag_mode, "i");
369: MODULE_PARM(use_new_eh_code, "i");
370: MODULE_PARM(ext_tran, "i");
371: MODULE_PARM(rev_scan, "i");
372: MODULE_AUTHOR("Dario Ballabio");
373: #endif
374:
375: #endif
376:
377: #include <linux/string.h>
378: #include <linux/sched.h>
379: #include <linux/kernel.h>
380: #include <linux/ioport.h>
381: #include <linux/delay.h>
382: #include <asm/io.h>
383: #include <asm/system.h>
384: #include <asm/byteorder.h>
385: #include <linux/proc_fs.h>
386: #include <linux/blk.h>
387: #include "scsi.h"
388: #include "hosts.h"
389: #include "sd.h"
390: #include <asm/dma.h>
391: #include <asm/irq.h>
392: #include "eata.h"
393: #include <linux/stat.h>
394: #include <linux/config.h>
395: #include <linux/pci.h>
396:
397: #if LINUX_VERSION_CODE < LinuxVersionCode(2,1,93)
398: #include <linux/bios32.h>
399: #endif
400:
401: #if LINUX_VERSION_CODE >= LinuxVersionCode(2,1,36)
402: #include <linux/init.h>
403: #else
404: #define __initfunc(A) A
405: #define __initdata
406: #define __init
407: #endif
408:
409: #if LINUX_VERSION_CODE >= LinuxVersionCode(2,1,101)
410: #include <asm/spinlock.h>
411: #define IRQ_FLAGS
412: #define IRQ_LOCK
413: #define IRQ_LOCK_SAVE
414: #define IRQ_UNLOCK
415: #define IRQ_UNLOCK_RESTORE
416: #define SPIN_FLAGS unsigned long spin_flags;
417: #define SPIN_LOCK spin_lock_irq(&io_request_lock);
418: #define SPIN_LOCK_SAVE spin_lock_irqsave(&io_request_lock, spin_flags);
419: #define SPIN_UNLOCK spin_unlock_irq(&io_request_lock);
420: #define SPIN_UNLOCK_RESTORE \
421: spin_unlock_irqrestore(&io_request_lock, spin_flags);
422: static int use_new_eh_code = TRUE;
423: #else
424: #define IRQ_FLAGS unsigned long irq_flags;
425: #define IRQ_LOCK cli();
426: #define IRQ_LOCK_SAVE do {save_flags(irq_flags); cli();} while (0);
427: #define IRQ_UNLOCK sti();
428: #define IRQ_UNLOCK_RESTORE do {restore_flags(irq_flags);} while (0);
429: #define SPIN_FLAGS
430: #define SPIN_LOCK
431: #define SPIN_LOCK_SAVE
432: #define SPIN_UNLOCK
433: #define SPIN_UNLOCK_RESTORE
434: static int use_new_eh_code = FALSE;
435: #endif
436:
437: struct proc_dir_entry proc_scsi_eata2x = {
438: PROC_SCSI_EATA2X, 6, "eata2x",
439: S_IFDIR | S_IRUGO | S_IXUGO, 2
440: };
441:
442: /* Subversion values */
443: #define ISA 0
444: #define ESA 1
445:
446: #undef FORCE_CONFIG
447:
448: #undef DEBUG_LINKED_COMMANDS
449: #undef DEBUG_DETECT
450: #undef DEBUG_PCI_DETECT
451: #undef DEBUG_INTERRUPT
452: #undef DEBUG_RESET
453: #undef DEBUG_GENERATE_ERRORS
454: #undef DEBUG_GENERATE_ABORTS
455: #undef DEBUG_GEOMETRY
456:
457: #define MAX_ISA 4
458: #define MAX_VESA 0
459: #define MAX_EISA 15
460: #define MAX_PCI 16
461: #define MAX_BOARDS (MAX_ISA + MAX_VESA + MAX_EISA + MAX_PCI)
462: #define MAX_CHANNEL 4
463: #define MAX_LUN 32
464: #define MAX_TARGET 32
465: #define MAX_MAILBOXES 64
466: #define MAX_SGLIST 64
467: #define MAX_LARGE_SGLIST 122
468: #define MAX_INTERNAL_RETRIES 64
469: #define MAX_CMD_PER_LUN 2
470: #define MAX_TAGGED_CMD_PER_LUN (MAX_MAILBOXES - MAX_CMD_PER_LUN)
471:
472: #define SKIP ULONG_MAX
473: #define FALSE 0
474: #define TRUE 1
475: #define FREE 0
476: #define IN_USE 1
477: #define LOCKED 2
478: #define IN_RESET 3
479: #define IGNORE 4
480: #define READY 5
481: #define ABORTING 6
482: #define NO_DMA 0xff
483: #define MAXLOOP 10000
484: #define TAG_MIXED 0
485: #define TAG_SIMPLE 1
486: #define TAG_HEAD 2
487: #define TAG_ORDERED 3
488:
489: #define REG_CMD 7
490: #define REG_STATUS 7
491: #define REG_AUX_STATUS 8
492: #define REG_DATA 0
493: #define REG_DATA2 1
494: #define REG_SEE 6
495: #define REG_LOW 2
496: #define REG_LM 3
497: #define REG_MID 4
498: #define REG_MSB 5
499: #define REGION_SIZE 9
500: #define MAX_ISA_ADDR 0x03ff
501: #define MIN_EISA_ADDR 0x1c88
502: #define MAX_EISA_ADDR 0xfc88
503: #define BSY_ASSERTED 0x80
504: #define DRQ_ASSERTED 0x08
505: #define ABSY_ASSERTED 0x01
506: #define IRQ_ASSERTED 0x02
507: #define READ_CONFIG_PIO 0xf0
508: #define SET_CONFIG_PIO 0xf1
509: #define SEND_CP_PIO 0xf2
510: #define RECEIVE_SP_PIO 0xf3
511: #define TRUNCATE_XFR_PIO 0xf4
512: #define RESET_PIO 0xf9
513: #define READ_CONFIG_DMA 0xfd
514: #define SET_CONFIG_DMA 0xfe
515: #define SEND_CP_DMA 0xff
516: #define ASOK 0x00
517: #define ASST 0x01
518:
519: #define ARRAY_SIZE(arr) (sizeof (arr) / sizeof (arr)[0])
520: #define YESNO(a) ((a) ? 'y' : 'n')
521: #define TLDEV(type) ((type) == TYPE_DISK || (type) == TYPE_ROM)
522:
523: /* "EATA", in Big Endian format */
524: #define EATA_SIGNATURE 0x41544145
525:
526: /* Number of valid bytes in the board config structure for EATA 2.0x */
527: #define EATA_2_0A_SIZE 28
528: #define EATA_2_0B_SIZE 30
529: #define EATA_2_0C_SIZE 34
530:
531: /* Board info structure */
532: struct eata_info {
533: ulong data_len; /* Number of valid bytes after this field */
534: ulong sign; /* ASCII "EATA" signature */
535: unchar :4, /* unused low nibble */
536: version:4; /* EATA version, should be 0x1 */
537: unchar ocsena:1, /* Overlap Command Support Enabled */
538: tarsup:1, /* Target Mode Supported */
539: trnxfr:1, /* Truncate Transfer Cmd NOT Necessary */
540: morsup:1, /* More Supported */
541: dmasup:1, /* DMA Supported */
542: drqvld:1, /* DRQ Index (DRQX) is valid */
543: ata:1, /* This is an ATA device */
544: haaval:1; /* Host Adapter Address Valid */
545: ushort cp_pad_len; /* Number of pad bytes after cp_len */
546: unchar host_addr[4]; /* Host Adapter SCSI ID for channels 3, 2, 1, 0 */
547: ulong cp_len; /* Number of valid bytes in cp */
548: ulong sp_len; /* Number of valid bytes in sp */
549: ushort queue_size; /* Max number of cp that can be queued */
550: ushort unused;
551: ushort scatt_size; /* Max number of entries in scatter/gather table */
552: unchar irq:4, /* Interrupt Request assigned to this controller */
553: irq_tr:1, /* 0 for edge triggered, 1 for level triggered */
554: second:1, /* 1 if this is a secondary (not primary) controller */
555: drqx:2; /* DRQ Index (0=DMA0, 1=DMA7, 2=DMA6, 3=DMA5) */
556: unchar sync; /* 1 if scsi target id 7...0 is running sync scsi */
557:
558: /* Structure extension defined in EATA 2.0B */
559: unchar isaena:1, /* ISA i/o addressing is disabled/enabled */
560: forcaddr:1, /* Port address has been forced */
561: large_sg:1, /* 1 if large SG lists are supported */
562: res1:1,
563: :4;
564: unchar max_id:5, /* Max SCSI target ID number */
565: max_chan:3; /* Max SCSI channel number on this board */
566:
567: /* Structure extension defined in EATA 2.0C */
568: unchar max_lun; /* Max SCSI LUN number */
569: unchar :4,
570: m1:1, /* This is a PCI with an M1 chip installed */
571: idquest:1, /* RAIDNUM returned is questionable */
572: pci:1, /* This board is PCI */
573: eisa:1; /* This board is EISA */
574: unchar raidnum; /* Uniquely identifies this HBA in a system */
575: unchar notused;
576:
577: ushort ipad[247];
578: };
579:
580: /* Board config structure */
581: struct eata_config {
582: ushort len; /* Number of bytes following this field */
583: unchar edis:1, /* Disable EATA interface after config command */
584: ocena:1, /* Overlapped Commands Enabled */
585: mdpena:1, /* Transfer all Modified Data Pointer Messages */
586: tarena:1, /* Target Mode Enabled for this controller */
587: :4;
588: unchar cpad[511];
589: };
590:
591: /* Returned status packet structure */
592: struct mssp {
593: unchar adapter_status:7, /* State related to current command */
594: eoc:1; /* End Of Command (1 = command completed) */
595: unchar target_status; /* SCSI status received after data transfer */
596: unchar unused[2];
597: ulong inv_res_len; /* Number of bytes not transferred */
598: struct mscp *cpp; /* Address set in cp */
599: char mess[12];
600: };
601:
602: struct sg_list {
603: unsigned int address; /* Segment Address */
604: unsigned int num_bytes; /* Segment Length */
605: };
606:
607: /* MailBox SCSI Command Packet */
608: struct mscp {
609: unchar sreset:1, /* SCSI Bus Reset Signal should be asserted */
610: init:1, /* Re-initialize controller and self test */
611: reqsen:1, /* Transfer Request Sense Data to addr using DMA */
612: sg:1, /* Use Scatter/Gather */
613: :1,
614: interp:1, /* The controller interprets cp, not the target */
615: dout:1, /* Direction of Transfer is Out (Host to Target) */
616: din:1; /* Direction of Transfer is In (Target to Host) */
617: unchar sense_len; /* Request Sense Length */
618: unchar unused[3];
619: unchar fwnest:1, /* Send command to a component of an Array Group */
620: :7;
621: unchar phsunit:1, /* Send to Target Physical Unit (bypass RAID) */
622: iat:1, /* Inhibit Address Translation */
623: hbaci:1, /* Inhibit HBA Caching for this command */
624: :5;
625: unchar target:5, /* SCSI target ID */
626: channel:3; /* SCSI channel number */
627: unchar lun:5, /* SCSI logical unit number */
628: luntar:1, /* This cp is for Target (not LUN) */
629: dispri:1, /* Disconnect Privilege granted */
630: one:1; /* 1 */
631: unchar mess[3]; /* Massage to/from Target */
632: unchar cdb[12]; /* Command Descriptor Block */
633: ulong data_len; /* If sg=0 Data Length, if sg=1 sglist length */
634: struct mscp *cpp; /* Address to be returned in sp */
635: ulong data_address; /* If sg=0 Data Address, if sg=1 sglist address */
636: ulong sp_addr; /* Address where sp is DMA'ed when cp completes */
637: ulong sense_addr; /* Address where Sense Data is DMA'ed on error */
638: Scsi_Cmnd *SCpnt;
639: unsigned int index; /* cp index */
640: struct sg_list *sglist;
641: };
642:
643: struct hostdata {
644: struct mscp cp[MAX_MAILBOXES]; /* Mailboxes for this board */
645: unsigned int cp_stat[MAX_MAILBOXES]; /* FREE, IN_USE, LOCKED, IN_RESET */
646: unsigned int last_cp_used; /* Index of last mailbox used */
647: unsigned int iocount; /* Total i/o done for this board */
648: int board_number; /* Number of this board */
649: char board_name[16]; /* Name of this board */
650: char board_id[256]; /* data from INQUIRY on this board */
651: int in_reset; /* True if board is doing a reset */
652: int target_to[MAX_TARGET][MAX_CHANNEL]; /* N. of timeout errors on target */
653: int target_redo[MAX_TARGET][MAX_CHANNEL]; /* If TRUE redo i/o on target */
654: unsigned int retries; /* Number of internal retries */
655: unsigned long last_retried_pid; /* Pid of last retried command */
656: unsigned char subversion; /* Bus type, either ISA or EISA/PCI */
657: unsigned char protocol_rev; /* EATA 2.0 rev., 'A' or 'B' or 'C' */
658: struct mssp sp[2]; /* Returned status for this board */
659: };
660:
661: static struct Scsi_Host *sh[MAX_BOARDS + 1];
662: static const char *driver_name = "EATA";
663: static char sha[MAX_BOARDS];
664:
665: /* Initialize num_boards so that ihdlr can work while detect is in progress */
666: static unsigned int num_boards = MAX_BOARDS;
667:
668: static unsigned long io_port[] __initdata = {
669:
670: /* Space for MAX_INT_PARAM ports usable while loading as a module */
671: SKIP, SKIP, SKIP, SKIP, SKIP, SKIP, SKIP, SKIP,
672: SKIP, SKIP,
673:
674: /* First ISA */
675: 0x1f0,
676:
677: /* Space for MAX_PCI ports possibly reported by PCI_BIOS */
678: SKIP, SKIP, SKIP, SKIP, SKIP, SKIP, SKIP, SKIP,
679: SKIP, SKIP, SKIP, SKIP, SKIP, SKIP, SKIP, SKIP,
680:
681: /* MAX_EISA ports */
682: 0x1c88, 0x2c88, 0x3c88, 0x4c88, 0x5c88, 0x6c88, 0x7c88, 0x8c88,
683: 0x9c88, 0xac88, 0xbc88, 0xcc88, 0xdc88, 0xec88, 0xfc88,
684:
685: /* Other (MAX_ISA - 1) ports */
686: 0x170, 0x230, 0x330,
687:
688: /* End of list */
689: 0x0
690: };
691:
692: #define HD(board) ((struct hostdata *) &sh[board]->hostdata)
693: #define BN(board) (HD(board)->board_name)
694:
695: #define H2DEV(x) htonl(x)
696: #define DEV2H(x) H2DEV(x)
697: #define V2DEV(addr) ((addr) ? H2DEV(virt_to_bus((void *)addr)) : 0)
698: #define DEV2V(addr) ((addr) ? DEV2H(bus_to_virt((unsigned long)addr)) : 0)
699:
700: static void do_interrupt_handler(int, void *, struct pt_regs *);
701: static void flush_dev(Scsi_Device *, unsigned long, unsigned int, unsigned int);
702: static int do_trace = FALSE;
703: static int setup_done = FALSE;
704: static int link_statistics = 0;
705: static int tag_mode = TAG_MIXED;
706: static int ext_tran = FALSE;
707: static int rev_scan = TRUE;
708:
709: #if defined(CONFIG_SCSI_EATA_TAGGED_QUEUE)
710: static int tagged_comm = TRUE;
711: #else
712: static int tagged_comm = FALSE;
713: #endif
714:
715: #if defined(CONFIG_SCSI_EATA_LINKED_COMMANDS)
716: static int linked_comm = TRUE;
717: #else
718: static int linked_comm = FALSE;
719: #endif
720:
721: #if defined(CONFIG_SCSI_EATA_MAX_TAGS)
722: static int max_queue_depth = CONFIG_SCSI_EATA_MAX_TAGS;
723: #else
724: static int max_queue_depth = MAX_CMD_PER_LUN;
725: #endif
726:
727: static void select_queue_depths(struct Scsi_Host *host, Scsi_Device *devlist) {
728: Scsi_Device *dev;
729: int j, ntag = 0, nuntag = 0, tqd, utqd;
730: IRQ_FLAGS
731:
732: IRQ_LOCK_SAVE
733: j = ((struct hostdata *) host->hostdata)->board_number;
734:
735: for(dev = devlist; dev; dev = dev->next) {
736:
737: if (dev->host != host) continue;
738:
739: if (TLDEV(dev->type) && (dev->tagged_supported || linked_comm))
740: ntag++;
741: else
742: nuntag++;
743: }
744:
745: utqd = MAX_CMD_PER_LUN;
746:
747: tqd = (host->can_queue - utqd * nuntag) / (ntag ? ntag : 1);
748:
749: if (tqd > max_queue_depth) tqd = max_queue_depth;
750:
751: if (tqd < MAX_CMD_PER_LUN) tqd = MAX_CMD_PER_LUN;
752:
753: for(dev = devlist; dev; dev = dev->next) {
754: char *tag_suffix = "", *link_suffix = "";
755:
756: if (dev->host != host) continue;
757:
758: if (TLDEV(dev->type) && (dev->tagged_supported || linked_comm))
759: dev->queue_depth = tqd;
760: else
761: dev->queue_depth = utqd;
762:
763: if (TLDEV(dev->type)) {
764: if (linked_comm && dev->queue_depth > 2)
765: link_suffix = ", sorted";
766: else
767: link_suffix = ", unsorted";
768: }
769:
770: if (tagged_comm && dev->tagged_supported && TLDEV(dev->type)) {
771: dev->tagged_queue = 1;
772: dev->current_tag = 1;
773: }
774:
775: if (dev->tagged_supported && TLDEV(dev->type) && dev->tagged_queue)
776: tag_suffix = ", tagged";
777: else if (dev->tagged_supported && TLDEV(dev->type))
778: tag_suffix = ", untagged";
779:
780: printk("%s: scsi%d, channel %d, id %d, lun %d, cmds/lun %d%s%s.\n",
781: BN(j), host->host_no, dev->channel, dev->id, dev->lun,
782: dev->queue_depth, link_suffix, tag_suffix);
783: }
784:
785: IRQ_UNLOCK_RESTORE
786: return;
787: }
788:
789: static inline int wait_on_busy(unsigned long iobase, unsigned int loop) {
790:
791: while (inb(iobase + REG_AUX_STATUS) & ABSY_ASSERTED) {
792: udelay(1L);
793: if (--loop == 0) return TRUE;
794: }
795:
796: return FALSE;
797: }
798:
799: static inline int do_dma(unsigned long iobase, unsigned int addr, unchar cmd) {
800:
801: if (wait_on_busy(iobase, (addr ? MAXLOOP * 100 : MAXLOOP))) return TRUE;
802:
803: if ((addr = V2DEV(addr))) {
804: outb((char) (addr >> 24), iobase + REG_LOW);
805: outb((char) (addr >> 16), iobase + REG_LM);
806: outb((char) (addr >> 8), iobase + REG_MID);
807: outb((char) addr, iobase + REG_MSB);
808: }
809:
810: outb(cmd, iobase + REG_CMD);
811: return FALSE;
812: }
813:
814: static inline int read_pio(unsigned long iobase, ushort *start, ushort *end) {
815: unsigned int loop = MAXLOOP;
816: ushort *p;
817:
818: for (p = start; p <= end; p++) {
819:
820: while (!(inb(iobase + REG_STATUS) & DRQ_ASSERTED)) {
821: udelay(1L);
822: if (--loop == 0) return TRUE;
823: }
824:
825: loop = MAXLOOP;
826: *p = inw(iobase);
827: }
828:
829: return FALSE;
830: }
831:
832: __initfunc (static inline int
833: get_pci_irq(unsigned long port_base, unsigned char *apic_irq)) {
834:
835: #if defined(CONFIG_PCI)
836:
837: #if LINUX_VERSION_CODE >= LinuxVersionCode(2,1,93)
838:
839: unsigned int addr;
840: struct pci_dev *dev = NULL;
841:
842: if (!pci_present()) return FALSE;
843:
844: while((dev = pci_find_class(PCI_CLASS_STORAGE_SCSI << 8, dev))) {
845:
846: if (pci_read_config_dword(dev, PCI_BASE_ADDRESS_0, &addr)) continue;
847:
848: #if defined(DEBUG_PCI_DETECT)
849: printk("%s: get_pci_irq, bus %d, devfn 0x%x, addr 0x%x, apic_irq %u.\n",
850: driver_name, dev->bus->number, dev->devfn, addr, dev->irq);
851: #endif
852:
853: if ((addr & PCI_BASE_ADDRESS_SPACE) != PCI_BASE_ADDRESS_SPACE_IO)
854: continue;
855:
856: if ((addr & PCI_BASE_ADDRESS_IO_MASK) + PCI_BASE_ADDRESS_0 == port_base) {
857: *apic_irq = dev->irq;
858: return TRUE;
859: }
860:
861: }
862:
863: #endif /* end new style PCI code */
864:
865: #endif /* end CONFIG_PCI */
866:
867: return FALSE;
868: }
869:
870: __initfunc (static inline int port_detect \
871: (unsigned long port_base, unsigned int j, Scsi_Host_Template *tpnt)) {
872: unsigned char irq, dma_channel, subversion, i;
873: unsigned char protocol_rev, apic_irq;
874: struct eata_info info;
875: char *bus_type, dma_name[16], tag_type;
876:
877: /* Allowed DMA channels for ISA (0 indicates reserved) */
878: unsigned char dma_channel_table[4] = { 5, 6, 7, 0 };
879:
880: char name[16];
881:
882: sprintf(name, "%s%d", driver_name, j);
883:
1.1.1.2 ! root 884: printk("\rprobing eata on %lx", port_base);
! 885:
1.1 root 886: if(check_region(port_base, REGION_SIZE)) {
887: printk("%s: address 0x%03lx in use, skipping probe.\n", name, port_base);
888: return FALSE;
889: }
890:
891: if (do_dma(port_base, 0, READ_CONFIG_PIO)) return FALSE;
892:
893: /* Read the info structure */
894: if (read_pio(port_base, (ushort *)&info, (ushort *)&info.ipad[0]))
895: return FALSE;
896:
897: /* Check the controller "EATA" signature */
898: if (info.sign != EATA_SIGNATURE) return FALSE;
899:
900: if (DEV2H(info.data_len) < EATA_2_0A_SIZE) {
901: printk("%s: config structure size (%ld bytes) too short, detaching.\n",
902: name, DEV2H(info.data_len));
903: return FALSE;
904: }
905: else if (DEV2H(info.data_len) == EATA_2_0A_SIZE)
906: protocol_rev = 'A';
907: else if (DEV2H(info.data_len) == EATA_2_0B_SIZE)
908: protocol_rev = 'B';
909: else
910: protocol_rev = 'C';
911:
912: if (!setup_done && j > 0 && j <= MAX_PCI) {
913: bus_type = "PCI";
914: subversion = ESA;
915: }
916: else if (port_base > MAX_EISA_ADDR || (protocol_rev == 'C' && info.pci)) {
917: bus_type = "PCI";
918: subversion = ESA;
919: }
920: else if (port_base >= MIN_EISA_ADDR || (protocol_rev == 'C' && info.eisa)) {
921: bus_type = "EISA";
922: subversion = ESA;
923: }
924: else if (protocol_rev == 'C' && !info.eisa && !info.pci) {
925: bus_type = "ISA";
926: subversion = ISA;
927: }
928: else if (port_base > MAX_ISA_ADDR) {
929: bus_type = "PCI";
930: subversion = ESA;
931: }
932: else {
933: bus_type = "ISA";
934: subversion = ISA;
935: }
936:
937: if (!info.haaval || info.ata) {
938: printk("%s: address 0x%03lx, unusable %s board (%d%d), detaching.\n",
939: name, port_base, bus_type, info.haaval, info.ata);
940: return FALSE;
941: }
942:
943: if (info.drqvld) {
944:
945: if (subversion == ESA)
946: printk("%s: warning, weird %s board using DMA.\n", name, bus_type);
947:
948: subversion = ISA;
949: dma_channel = dma_channel_table[3 - info.drqx];
950: }
951: else {
952:
953: if (subversion == ISA)
954: printk("%s: warning, weird %s board not using DMA.\n", name, bus_type);
955:
956: subversion = ESA;
957: dma_channel = NO_DMA;
958: }
959:
960: if (!info.dmasup)
961: printk("%s: warning, DMA protocol support not asserted.\n", name);
962:
963: irq = info.irq;
964:
965: if (subversion == ESA && !info.irq_tr)
966: printk("%s: warning, LEVEL triggering is suggested for IRQ %u.\n",
967: name, irq);
968:
969: if (get_pci_irq(port_base, &apic_irq) && (irq != apic_irq)) {
970: printk("%s: IRQ %u mapped to IO-APIC IRQ %u.\n", name, irq, apic_irq);
971: irq = apic_irq;
972: }
973:
974: /* Board detected, allocate its IRQ */
975: if (request_irq(irq, do_interrupt_handler,
976: SA_INTERRUPT | ((subversion == ESA) ? SA_SHIRQ : 0),
977: driver_name, (void *) &sha[j])) {
978: printk("%s: unable to allocate IRQ %u, detaching.\n", name, irq);
979: return FALSE;
980: }
981:
982: if (subversion == ISA && request_dma(dma_channel, driver_name)) {
983: printk("%s: unable to allocate DMA channel %u, detaching.\n",
984: name, dma_channel);
985: free_irq(irq, &sha[j]);
986: return FALSE;
987: }
988:
989: #if defined(FORCE_CONFIG)
990: {
991: struct eata_config config;
992:
993: /* Set board configuration */
994: memset((char *)&config, 0, sizeof(struct eata_config));
995: config.len = (ushort) htons((ushort)510);
996: config.ocena = TRUE;
997:
998: if (do_dma(port_base, (unsigned int)&config, SET_CONFIG_DMA)) {
999: printk("%s: busy timeout sending configuration, detaching.\n", name);
1000: return FALSE;
1001: }
1002: }
1003: #endif
1004:
1005: sh[j] = scsi_register(tpnt, sizeof(struct hostdata));
1006:
1007: if (sh[j] == NULL) {
1008: printk("%s: unable to register host, detaching.\n", name);
1009:
1010: free_irq(irq, &sha[j]);
1011:
1012: if (subversion == ISA) free_dma(dma_channel);
1013:
1014: return FALSE;
1015: }
1016:
1017: sh[j]->io_port = port_base;
1018: sh[j]->unique_id = port_base;
1019: sh[j]->n_io_port = REGION_SIZE;
1020: sh[j]->dma_channel = dma_channel;
1021: sh[j]->irq = irq;
1022: sh[j]->sg_tablesize = (ushort) ntohs(info.scatt_size);
1023: sh[j]->this_id = (ushort) info.host_addr[3];
1024: sh[j]->can_queue = (ushort) ntohs(info.queue_size);
1025: sh[j]->cmd_per_lun = MAX_CMD_PER_LUN;
1026: sh[j]->select_queue_depths = select_queue_depths;
1027:
1028: /* Register the I/O space that we use */
1029: request_region(sh[j]->io_port, sh[j]->n_io_port, driver_name);
1030:
1031: memset(HD(j), 0, sizeof(struct hostdata));
1032: HD(j)->subversion = subversion;
1033: HD(j)->protocol_rev = protocol_rev;
1034: HD(j)->board_number = j;
1035:
1036: if (HD(j)->subversion == ESA)
1037: sh[j]->unchecked_isa_dma = FALSE;
1038: else {
1039: sh[j]->wish_block = TRUE;
1040: sh[j]->unchecked_isa_dma = TRUE;
1041: disable_dma(dma_channel);
1042: clear_dma_ff(dma_channel);
1043: set_dma_mode(dma_channel, DMA_MODE_CASCADE);
1044: enable_dma(dma_channel);
1045: }
1046:
1047: strcpy(BN(j), name);
1048:
1049: /* DPT PM2012 does not allow to detect sg_tablesize correctly */
1050: if (sh[j]->sg_tablesize > MAX_SGLIST || sh[j]->sg_tablesize < 2) {
1051: printk("%s: detect, wrong n. of SG lists %d, fixed.\n",
1052: BN(j), sh[j]->sg_tablesize);
1053: sh[j]->sg_tablesize = MAX_SGLIST;
1054: }
1055:
1056: /* DPT PM2012 does not allow to detect can_queue correctly */
1057: if (sh[j]->can_queue > MAX_MAILBOXES || sh[j]->can_queue < 2) {
1058: printk("%s: detect, wrong n. of mbox %d, fixed.\n",
1059: BN(j), sh[j]->can_queue);
1060: sh[j]->can_queue = MAX_MAILBOXES;
1061: }
1062:
1063: if (protocol_rev != 'A') {
1064:
1065: if (info.max_chan > 0 && info.max_chan < MAX_CHANNEL)
1066: sh[j]->max_channel = info.max_chan;
1067:
1068: if (info.max_id > 7 && info.max_id < MAX_TARGET)
1069: sh[j]->max_id = info.max_id + 1;
1070:
1071: if (info.large_sg && sh[j]->sg_tablesize == MAX_SGLIST)
1072: sh[j]->sg_tablesize = MAX_LARGE_SGLIST;
1073: }
1074:
1075: if (protocol_rev == 'C') {
1076:
1077: if (info.max_lun > 7 && info.max_lun < MAX_LUN)
1078: sh[j]->max_lun = info.max_lun + 1;
1079: }
1080:
1081: if (dma_channel == NO_DMA) sprintf(dma_name, "%s", "BMST");
1082: else sprintf(dma_name, "DMA %u", dma_channel);
1083:
1084: for (i = 0; i < sh[j]->can_queue; i++)
1085: if (! ((&HD(j)->cp[i])->sglist = kmalloc(
1086: sh[j]->sg_tablesize * sizeof(struct sg_list),
1087: (sh[j]->unchecked_isa_dma ? GFP_DMA : 0) | GFP_ATOMIC))) {
1088: printk("%s: kmalloc SGlist failed, mbox %d, detaching.\n", BN(j), i);
1089: eata2x_release(sh[j]);
1090: return FALSE;
1091: }
1092:
1093: if (max_queue_depth > MAX_TAGGED_CMD_PER_LUN)
1094: max_queue_depth = MAX_TAGGED_CMD_PER_LUN;
1095:
1096: if (max_queue_depth < MAX_CMD_PER_LUN) max_queue_depth = MAX_CMD_PER_LUN;
1097:
1098: if (tagged_comm) {
1099: if (tag_mode == TAG_SIMPLE) tag_type = '1';
1100: else if (tag_mode == TAG_HEAD) tag_type = '2';
1101: else if (tag_mode == TAG_ORDERED) tag_type = '3';
1102: else tag_type = 'y';
1103: }
1104: else tag_type = 'n';
1105:
1106: #if LINUX_VERSION_CODE >= LinuxVersionCode(2,1,101)
1107: sh[j]->hostt->use_new_eh_code = use_new_eh_code;
1108: #else
1109: use_new_eh_code = FALSE;
1110: #endif
1111:
1112: if (j == 0) {
1113: printk("EATA/DMA 2.0x: Copyright (C) 1994-1998 Dario Ballabio.\n");
1114: printk("%s config options -> tc:%c, lc:%c, mq:%d, eh:%c, rs:%c, et:%c.\n",
1115: driver_name, tag_type, YESNO(linked_comm), max_queue_depth,
1116: YESNO(use_new_eh_code), YESNO(rev_scan), YESNO(ext_tran));
1117: }
1118:
1119: printk("%s: 2.0%c, %s 0x%03lx, IRQ %u, %s, SG %d, MB %d.\n",
1120: BN(j), HD(j)->protocol_rev, bus_type, (unsigned long)sh[j]->io_port,
1121: sh[j]->irq, dma_name, sh[j]->sg_tablesize, sh[j]->can_queue);
1122:
1123: if (sh[j]->max_id > 8 || sh[j]->max_lun > 8)
1124: printk("%s: wide SCSI support enabled, max_id %u, max_lun %u.\n",
1125: BN(j), sh[j]->max_id, sh[j]->max_lun);
1126:
1127: for (i = 0; i <= sh[j]->max_channel; i++)
1128: printk("%s: SCSI channel %u enabled, host target ID %d.\n",
1129: BN(j), i, info.host_addr[3 - i]);
1130:
1131: #if defined(DEBUG_DETECT)
1132: printk("%s: Vers. 0x%x, ocs %u, tar %u, trnxfr %u, more %u, SYNC 0x%x, "\
1133: "sec. %u, infol %ld, cpl %ld spl %ld.\n", name, info.version,
1134: info.ocsena, info.tarsup, info.trnxfr, info.morsup, info.sync,
1135: info.second, DEV2H(info.data_len), DEV2H(info.cp_len),
1136: DEV2H(info.sp_len));
1137:
1138: if (protocol_rev == 'B' || protocol_rev == 'C')
1139: printk("%s: isaena %u, forcaddr %u, max_id %u, max_chan %u, "\
1140: "large_sg %u, res1 %u.\n", name, info.isaena, info.forcaddr,
1141: info.max_id, info.max_chan, info.large_sg, info.res1);
1142:
1143: if (protocol_rev == 'C')
1144: printk("%s: max_lun %u, m1 %u, idquest %u, pci %u, eisa %u, "\
1145: "raidnum %u.\n", name, info.max_lun, info.m1, info.idquest,
1146: info.pci, info.eisa, info.raidnum);
1147: #endif
1148:
1149: return TRUE;
1150: }
1151:
1152: __initfunc (void eata2x_setup(char *str, int *ints)) {
1153: int i, argc = ints[0];
1154: char *cur = str, *pc;
1155:
1156: if (argc > 0) {
1157:
1158: if (argc > MAX_INT_PARAM) argc = MAX_INT_PARAM;
1159:
1160: for (i = 0; i < argc; i++) io_port[i] = ints[i + 1];
1161:
1162: io_port[i] = 0;
1163: setup_done = TRUE;
1164: }
1165:
1166: while (cur && (pc = strchr(cur, ':'))) {
1167: int val = 0, c = *++pc;
1168:
1169: if (c == 'n' || c == 'N') val = FALSE;
1170: else if (c == 'y' || c == 'Y') val = TRUE;
1171: else val = (int) simple_strtoul(pc, NULL, 0);
1172:
1173: if (!strncmp(cur, "lc:", 3)) linked_comm = val;
1174: else if (!strncmp(cur, "tc:", 3)) tagged_comm = val;
1175: else if (!strncmp(cur, "tm:", 3)) tag_mode = val;
1176: else if (!strncmp(cur, "mq:", 3)) max_queue_depth = val;
1177: else if (!strncmp(cur, "ls:", 3)) link_statistics = val;
1178: else if (!strncmp(cur, "eh:", 3)) use_new_eh_code = val;
1179: else if (!strncmp(cur, "et:", 3)) ext_tran = val;
1180: else if (!strncmp(cur, "rs:", 3)) rev_scan = val;
1181:
1182: if ((cur = strchr(cur, ','))) ++cur;
1183: }
1184:
1185: return;
1186: }
1187:
1188: __initfunc (static void add_pci_ports(void)) {
1189:
1190: #if defined(CONFIG_PCI)
1191:
1192: unsigned int addr, k;
1193:
1194: #if LINUX_VERSION_CODE >= LinuxVersionCode(2,1,93)
1195:
1196: struct pci_dev *dev = NULL;
1197:
1198: if (!pci_present()) return;
1199:
1200: for (k = 0; k < MAX_PCI; k++) {
1201:
1202: if (!(dev = pci_find_class(PCI_CLASS_STORAGE_SCSI << 8, dev))) break;
1203:
1204: if (pci_read_config_dword(dev, PCI_BASE_ADDRESS_0, &addr)) continue;
1205:
1206: #if defined(DEBUG_PCI_DETECT)
1207: printk("%s: detect, seq. %d, bus %d, devfn 0x%x, addr 0x%x.\n",
1208: driver_name, k, dev->bus->number, dev->devfn, addr);
1209: #endif
1210:
1211: if ((addr & PCI_BASE_ADDRESS_SPACE) != PCI_BASE_ADDRESS_SPACE_IO)
1212: continue;
1213:
1214: /* Order addresses according to rev_scan value */
1215: io_port[MAX_INT_PARAM + (rev_scan ? (MAX_PCI - k) : (1 + k))] =
1216: (addr & PCI_BASE_ADDRESS_IO_MASK) + PCI_BASE_ADDRESS_0;
1217: }
1218:
1219: #else /* else old style PCI code */
1220:
1221: unsigned short i = 0;
1222: unsigned char bus, devfn;
1223:
1224: if (!pcibios_present()) return;
1225:
1226: for (k = 0; k < MAX_PCI; k++) {
1227:
1228: if (pcibios_find_class(PCI_CLASS_STORAGE_SCSI << 8, i++, &bus, &devfn)
1229: != PCIBIOS_SUCCESSFUL) break;
1230:
1231: if (pcibios_read_config_dword(bus, devfn, PCI_BASE_ADDRESS_0, &addr)
1232: != PCIBIOS_SUCCESSFUL) continue;
1233:
1234: #if defined(DEBUG_PCI_DETECT)
1235: printk("%s: detect, seq. %d, bus %d, devfn 0x%x, addr 0x%x.\n",
1236: driver_name, k, bus, devfn, addr);
1237: #endif
1238:
1239: if ((addr & PCI_BASE_ADDRESS_SPACE) != PCI_BASE_ADDRESS_SPACE_IO)
1240: continue;
1241:
1242: /* Order addresses according to rev_scan value */
1243: io_port[MAX_INT_PARAM + (rev_scan ? (MAX_PCI - k) : (1 + k))] =
1244: (addr & PCI_BASE_ADDRESS_IO_MASK) + PCI_BASE_ADDRESS_0;
1245: }
1246:
1247: #endif /* end old style PCI code */
1248:
1249: #endif /* end CONFIG_PCI */
1250:
1251: return;
1252: }
1253:
1254: __initfunc (int eata2x_detect(Scsi_Host_Template *tpnt)) {
1255: unsigned int j = 0, k;
1256: IRQ_FLAGS
1257:
1258: IRQ_LOCK_SAVE
1259: tpnt->proc_dir = &proc_scsi_eata2x;
1260:
1261: #if defined(MODULE)
1262: /* io_port could have been modified when loading as a module */
1263: if(io_port[0] != SKIP) {
1264: setup_done = TRUE;
1265: io_port[MAX_INT_PARAM] = 0;
1266: }
1267: #endif
1268:
1269: for (k = 0; k < MAX_BOARDS + 1; k++) sh[k] = NULL;
1270:
1271: if (!setup_done) add_pci_ports();
1272:
1273: for (k = 0; io_port[k]; k++) {
1274:
1275: if (io_port[k] == SKIP) continue;
1276:
1277: if (j < MAX_BOARDS && port_detect(io_port[k], j, tpnt)) j++;
1278: }
1279:
1280: num_boards = j;
1281: IRQ_UNLOCK_RESTORE
1282: return j;
1283: }
1284:
1285: static inline void build_sg_list(struct mscp *cpp, Scsi_Cmnd *SCpnt) {
1286: unsigned int k;
1287: struct scatterlist *sgpnt;
1288:
1289: sgpnt = (struct scatterlist *) SCpnt->request_buffer;
1290:
1291: for (k = 0; k < SCpnt->use_sg; k++) {
1292: cpp->sglist[k].address = V2DEV(sgpnt[k].address);
1293: cpp->sglist[k].num_bytes = H2DEV(sgpnt[k].length);
1294: }
1295:
1296: cpp->data_address = V2DEV(cpp->sglist);
1297: cpp->data_len = H2DEV((SCpnt->use_sg * sizeof(struct sg_list)));
1298: }
1299:
1300: static inline int do_qcomm(Scsi_Cmnd *SCpnt, void (*done)(Scsi_Cmnd *)) {
1301: unsigned int i, j, k;
1302: struct mscp *cpp;
1303: struct mssp *spp;
1304:
1305: static const unsigned char data_out_cmds[] = {
1306: 0x0a, 0x2a, 0x15, 0x55, 0x04, 0x07, 0x18, 0x1d, 0x24, 0x2e,
1307: 0x30, 0x31, 0x32, 0x38, 0x39, 0x3a, 0x3b, 0x3d, 0x3f, 0x40,
1308: 0x41, 0x4c, 0xaa, 0xae, 0xb0, 0xb1, 0xb2, 0xb6, 0xea, 0x1b
1309: };
1310:
1311: static const unsigned char data_none_cmds[] = {
1312: 0x01, 0x0b, 0x10, 0x11, 0x13, 0x16, 0x17, 0x19, 0x2b, 0x1e,
1313: 0x2c, 0xac, 0x2f, 0xaf, 0x33, 0xb3, 0x35, 0x36, 0x45, 0x47,
1314: 0x48, 0x49, 0xa9, 0x4b, 0xa5, 0xa6, 0xb5
1315: };
1316:
1317: /* j is the board number */
1318: j = ((struct hostdata *) SCpnt->host->hostdata)->board_number;
1319:
1320: if (SCpnt->host_scribble)
1321: panic("%s: qcomm, pid %ld, SCpnt %p already active.\n",
1322: BN(j), SCpnt->pid, SCpnt);
1323:
1324: /* i is the mailbox number, look for the first free mailbox
1325: starting from last_cp_used */
1326: i = HD(j)->last_cp_used + 1;
1327:
1328: for (k = 0; k < sh[j]->can_queue; k++, i++) {
1329:
1330: if (i >= sh[j]->can_queue) i = 0;
1331:
1332: if (HD(j)->cp_stat[i] == FREE) {
1333: HD(j)->last_cp_used = i;
1334: break;
1335: }
1336: }
1337:
1338: if (k == sh[j]->can_queue) {
1339: printk("%s: qcomm, no free mailbox.\n", BN(j));
1340: return 1;
1341: }
1342:
1343: /* Set pointer to control packet structure */
1344: cpp = &HD(j)->cp[i];
1345:
1346: memset(cpp, 0, sizeof(struct mscp) - sizeof(struct sg_list *));
1347:
1348: /* Set pointer to status packet structure */
1349: spp = &HD(j)->sp[0];
1350:
1351: /* The EATA protocol uses Big Endian format */
1352: cpp->sp_addr = V2DEV(spp);
1353:
1354: cpp->cpp = cpp;
1355: SCpnt->scsi_done = done;
1356: cpp->index = i;
1357: SCpnt->host_scribble = (unsigned char *) &cpp->index;
1358:
1359: if (do_trace) printk("%s: qcomm, mbox %d, target %d.%d:%d, pid %ld.\n",
1360: BN(j), i, SCpnt->channel, SCpnt->target,
1361: SCpnt->lun, SCpnt->pid);
1362:
1363: for (k = 0; k < ARRAY_SIZE(data_out_cmds); k++)
1364: if (SCpnt->cmnd[0] == data_out_cmds[k]) {
1365: cpp->dout = TRUE;
1366: break;
1367: }
1368:
1369: if ((cpp->din = !cpp->dout))
1370: for (k = 0; k < ARRAY_SIZE(data_none_cmds); k++)
1371: if (SCpnt->cmnd[0] == data_none_cmds[k]) {
1372: cpp->din = FALSE;
1373: break;
1374: }
1375:
1376: cpp->reqsen = TRUE;
1377: cpp->dispri = TRUE;
1378: #if 0
1379: if (SCpnt->device->type == TYPE_TAPE) cpp->hbaci = TRUE;
1380: #endif
1381: cpp->one = TRUE;
1382: cpp->channel = SCpnt->channel;
1383: cpp->target = SCpnt->target;
1384: cpp->lun = SCpnt->lun;
1385: cpp->SCpnt = SCpnt;
1386: cpp->sense_addr = V2DEV(SCpnt->sense_buffer);
1387: cpp->sense_len = sizeof SCpnt->sense_buffer;
1388:
1389: if (SCpnt->device->tagged_queue) {
1390:
1391: if (HD(j)->target_redo[SCpnt->target][SCpnt->channel] ||
1392: HD(j)->target_to[SCpnt->target][SCpnt->channel])
1393: cpp->mess[0] = ORDERED_QUEUE_TAG;
1394: else if (tag_mode == TAG_SIMPLE) cpp->mess[0] = SIMPLE_QUEUE_TAG;
1395: else if (tag_mode == TAG_HEAD) cpp->mess[0] = HEAD_OF_QUEUE_TAG;
1396: else if (tag_mode == TAG_ORDERED) cpp->mess[0] = ORDERED_QUEUE_TAG;
1397: else if (SCpnt->device->current_tag == 0)
1398: cpp->mess[0] = ORDERED_QUEUE_TAG;
1399: else if (SCpnt->device->current_tag == 1)
1400: cpp->mess[0] = HEAD_OF_QUEUE_TAG;
1401: else
1402: cpp->mess[0] = SIMPLE_QUEUE_TAG;
1403:
1404: cpp->mess[1] = SCpnt->device->current_tag++;
1405: }
1406:
1407: if (SCpnt->use_sg) {
1408: cpp->sg = TRUE;
1409: build_sg_list(cpp, SCpnt);
1410: }
1411: else {
1412: cpp->data_address = V2DEV(SCpnt->request_buffer);
1413: cpp->data_len = H2DEV(SCpnt->request_bufflen);
1414: }
1415:
1416: memcpy(cpp->cdb, SCpnt->cmnd, SCpnt->cmd_len);
1417:
1418: if (linked_comm && SCpnt->device->queue_depth > 2
1419: && TLDEV(SCpnt->device->type)) {
1420: HD(j)->cp_stat[i] = READY;
1421: flush_dev(SCpnt->device, SCpnt->request.sector, j, FALSE);
1422: return 0;
1423: }
1424:
1425: /* Send control packet to the board */
1426: if (do_dma(sh[j]->io_port, (unsigned int) cpp, SEND_CP_DMA)) {
1427: SCpnt->host_scribble = NULL;
1428: printk("%s: qcomm, target %d.%d:%d, pid %ld, adapter busy.\n",
1429: BN(j), SCpnt->channel, SCpnt->target, SCpnt->lun, SCpnt->pid);
1430: return 1;
1431: }
1432:
1433: HD(j)->cp_stat[i] = IN_USE;
1434: return 0;
1435: }
1436:
1437: int eata2x_queuecommand(Scsi_Cmnd *SCpnt, void (*done)(Scsi_Cmnd *)) {
1438: int rtn;
1439: IRQ_FLAGS
1440:
1441: IRQ_LOCK_SAVE
1442: rtn = do_qcomm(SCpnt, done);
1443: IRQ_UNLOCK_RESTORE
1444: return rtn;
1445: }
1446:
1447: static inline int do_old_abort(Scsi_Cmnd *SCarg) {
1448: unsigned int i, j;
1449:
1450: j = ((struct hostdata *) SCarg->host->hostdata)->board_number;
1451:
1452: if (SCarg->host_scribble == NULL ||
1453: (SCarg->serial_number_at_timeout &&
1454: (SCarg->serial_number != SCarg->serial_number_at_timeout))) {
1455: printk("%s: abort, target %d.%d:%d, pid %ld inactive.\n",
1456: BN(j), SCarg->channel, SCarg->target, SCarg->lun, SCarg->pid);
1457: return SCSI_ABORT_NOT_RUNNING;
1458: }
1459:
1460: i = *(unsigned int *)SCarg->host_scribble;
1461: printk("%s: abort, mbox %d, target %d.%d:%d, pid %ld.\n",
1462: BN(j), i, SCarg->channel, SCarg->target, SCarg->lun, SCarg->pid);
1463:
1464: if (i >= sh[j]->can_queue)
1465: panic("%s: abort, invalid SCarg->host_scribble.\n", BN(j));
1466:
1467: if (wait_on_busy(sh[j]->io_port, MAXLOOP)) {
1468: printk("%s: abort, timeout error.\n", BN(j));
1469: return SCSI_ABORT_ERROR;
1470: }
1471:
1472: if (HD(j)->cp_stat[i] == FREE) {
1473: printk("%s: abort, mbox %d is free.\n", BN(j), i);
1474: return SCSI_ABORT_NOT_RUNNING;
1475: }
1476:
1477: if (HD(j)->cp_stat[i] == IN_USE) {
1478: printk("%s: abort, mbox %d is in use.\n", BN(j), i);
1479:
1480: if (SCarg != HD(j)->cp[i].SCpnt)
1481: panic("%s: abort, mbox %d, SCarg %p, cp SCpnt %p.\n",
1482: BN(j), i, SCarg, HD(j)->cp[i].SCpnt);
1483:
1484: if (inb(sh[j]->io_port + REG_AUX_STATUS) & IRQ_ASSERTED)
1485: printk("%s: abort, mbox %d, interrupt pending.\n", BN(j), i);
1486:
1487: return SCSI_ABORT_SNOOZE;
1488: }
1489:
1490: if (HD(j)->cp_stat[i] == IN_RESET) {
1491: printk("%s: abort, mbox %d is in reset.\n", BN(j), i);
1492: return SCSI_ABORT_ERROR;
1493: }
1494:
1495: if (HD(j)->cp_stat[i] == LOCKED) {
1496: printk("%s: abort, mbox %d is locked.\n", BN(j), i);
1497: return SCSI_ABORT_NOT_RUNNING;
1498: }
1499:
1500: if (HD(j)->cp_stat[i] == READY || HD(j)->cp_stat[i] == ABORTING) {
1501: SCarg->result = DID_ABORT << 16;
1502: SCarg->host_scribble = NULL;
1503: HD(j)->cp_stat[i] = FREE;
1504: printk("%s, abort, mbox %d ready, DID_ABORT, pid %ld done.\n",
1505: BN(j), i, SCarg->pid);
1506: SCarg->scsi_done(SCarg);
1507: return SCSI_ABORT_SUCCESS;
1508: }
1509:
1510: panic("%s: abort, mbox %d, invalid cp_stat.\n", BN(j), i);
1511: }
1512:
1513: int eata2x_old_abort(Scsi_Cmnd *SCarg) {
1514: int rtn;
1515: IRQ_FLAGS
1516:
1517: IRQ_LOCK_SAVE
1518: rtn = do_old_abort(SCarg);
1519: IRQ_UNLOCK_RESTORE
1520: return rtn;
1521: }
1522:
1523: #if LINUX_VERSION_CODE >= LinuxVersionCode(2,1,101)
1524:
1525: static inline int do_abort(Scsi_Cmnd *SCarg) {
1526: unsigned int i, j;
1527:
1528: j = ((struct hostdata *) SCarg->host->hostdata)->board_number;
1529:
1530: if (SCarg->host_scribble == NULL) {
1531: printk("%s: abort, target %d.%d:%d, pid %ld inactive.\n",
1532: BN(j), SCarg->channel, SCarg->target, SCarg->lun, SCarg->pid);
1533: return SUCCESS;
1534: }
1535:
1536: i = *(unsigned int *)SCarg->host_scribble;
1537: printk("%s: abort, mbox %d, target %d.%d:%d, pid %ld.\n",
1538: BN(j), i, SCarg->channel, SCarg->target, SCarg->lun, SCarg->pid);
1539:
1540: if (i >= sh[j]->can_queue)
1541: panic("%s: abort, invalid SCarg->host_scribble.\n", BN(j));
1542:
1543: if (wait_on_busy(sh[j]->io_port, MAXLOOP)) {
1544: printk("%s: abort, timeout error.\n", BN(j));
1545: return FAILED;
1546: }
1547:
1548: if (HD(j)->cp_stat[i] == FREE) {
1549: printk("%s: abort, mbox %d is free.\n", BN(j), i);
1550: return SUCCESS;
1551: }
1552:
1553: if (HD(j)->cp_stat[i] == IN_USE) {
1554: printk("%s: abort, mbox %d is in use.\n", BN(j), i);
1555:
1556: if (SCarg != HD(j)->cp[i].SCpnt)
1557: panic("%s: abort, mbox %d, SCarg %p, cp SCpnt %p.\n",
1558: BN(j), i, SCarg, HD(j)->cp[i].SCpnt);
1559:
1560: if (inb(sh[j]->io_port + REG_AUX_STATUS) & IRQ_ASSERTED)
1561: printk("%s: abort, mbox %d, interrupt pending.\n", BN(j), i);
1562:
1563: if (SCarg->eh_state == SCSI_STATE_TIMEOUT) {
1564: SCarg->host_scribble = NULL;
1565: HD(j)->cp_stat[i] = FREE;
1566: printk("%s, abort, mbox %d, eh_state timeout, pid %ld.\n",
1567: BN(j), i, SCarg->pid);
1568: return SUCCESS;
1569: }
1570:
1571: return FAILED;
1572: }
1573:
1574: if (HD(j)->cp_stat[i] == IN_RESET) {
1575: printk("%s: abort, mbox %d is in reset.\n", BN(j), i);
1576: return FAILED;
1577: }
1578:
1579: if (HD(j)->cp_stat[i] == LOCKED) {
1580: printk("%s: abort, mbox %d is locked.\n", BN(j), i);
1581: return SUCCESS;
1582: }
1583:
1584: if (HD(j)->cp_stat[i] == READY || HD(j)->cp_stat[i] == ABORTING) {
1585: SCarg->result = DID_ABORT << 16;
1586: SCarg->host_scribble = NULL;
1587: HD(j)->cp_stat[i] = FREE;
1588: printk("%s, abort, mbox %d ready, DID_ABORT, pid %ld done.\n",
1589: BN(j), i, SCarg->pid);
1590: SCarg->scsi_done(SCarg);
1591: return SUCCESS;
1592: }
1593:
1594: panic("%s: abort, mbox %d, invalid cp_stat.\n", BN(j), i);
1595: }
1596:
1597: int eata2x_abort(Scsi_Cmnd *SCarg) {
1598:
1599: return do_abort(SCarg);
1600: }
1601:
1602: #endif /* new_eh_code */
1603:
1604: static inline int do_old_reset(Scsi_Cmnd *SCarg) {
1605: unsigned int i, j, time, k, c, limit = 0;
1606: int arg_done = FALSE;
1607: Scsi_Cmnd *SCpnt;
1608:
1609: j = ((struct hostdata *) SCarg->host->hostdata)->board_number;
1610: printk("%s: reset, enter, target %d.%d:%d, pid %ld.\n",
1611: BN(j), SCarg->channel, SCarg->target, SCarg->lun, SCarg->pid);
1612:
1613: if (SCarg->host_scribble == NULL)
1614: printk("%s: reset, pid %ld inactive.\n", BN(j), SCarg->pid);
1615:
1616: if (SCarg->serial_number_at_timeout &&
1617: (SCarg->serial_number != SCarg->serial_number_at_timeout)) {
1618: printk("%s: reset, pid %ld, reset not running.\n", BN(j), SCarg->pid);
1619: return SCSI_RESET_NOT_RUNNING;
1620: }
1621:
1622: if (HD(j)->in_reset) {
1623: printk("%s: reset, exit, already in reset.\n", BN(j));
1624: return SCSI_RESET_ERROR;
1625: }
1626:
1627: if (wait_on_busy(sh[j]->io_port, MAXLOOP)) {
1628: printk("%s: reset, exit, timeout error.\n", BN(j));
1629: return SCSI_RESET_ERROR;
1630: }
1631:
1632: HD(j)->retries = 0;
1633:
1634: for (c = 0; c <= sh[j]->max_channel; c++)
1635: for (k = 0; k < sh[j]->max_id; k++) {
1636: HD(j)->target_redo[k][c] = TRUE;
1637: HD(j)->target_to[k][c] = 0;
1638: }
1639:
1640: for (i = 0; i < sh[j]->can_queue; i++) {
1641:
1642: if (HD(j)->cp_stat[i] == FREE) continue;
1643:
1644: if (HD(j)->cp_stat[i] == LOCKED) {
1645: HD(j)->cp_stat[i] = FREE;
1646: printk("%s: reset, locked mbox %d forced free.\n", BN(j), i);
1647: continue;
1648: }
1649:
1650: if (!(SCpnt = HD(j)->cp[i].SCpnt))
1651: panic("%s: reset, mbox %d, SCpnt == NULL.\n", BN(j), i);
1652:
1653: if (HD(j)->cp_stat[i] == READY || HD(j)->cp_stat[i] == ABORTING) {
1654: HD(j)->cp_stat[i] = ABORTING;
1655: printk("%s: reset, mbox %d aborting, pid %ld.\n",
1656: BN(j), i, SCpnt->pid);
1657: }
1658:
1659: else {
1660: HD(j)->cp_stat[i] = IN_RESET;
1661: printk("%s: reset, mbox %d in reset, pid %ld.\n",
1662: BN(j), i, SCpnt->pid);
1663: }
1664:
1665: if (SCpnt->host_scribble == NULL)
1666: panic("%s: reset, mbox %d, garbled SCpnt.\n", BN(j), i);
1667:
1668: if (*(unsigned int *)SCpnt->host_scribble != i)
1669: panic("%s: reset, mbox %d, index mismatch.\n", BN(j), i);
1670:
1671: if (SCpnt->scsi_done == NULL)
1672: panic("%s: reset, mbox %d, SCpnt->scsi_done == NULL.\n", BN(j), i);
1673:
1674: if (SCpnt == SCarg) arg_done = TRUE;
1675: }
1676:
1677: if (do_dma(sh[j]->io_port, 0, RESET_PIO)) {
1678: printk("%s: reset, cannot reset, timeout error.\n", BN(j));
1679: return SCSI_RESET_ERROR;
1680: }
1681:
1682: printk("%s: reset, board reset done, enabling interrupts.\n", BN(j));
1683:
1684: #if defined(DEBUG_RESET)
1685: do_trace = TRUE;
1686: #endif
1687:
1688: HD(j)->in_reset = TRUE;
1689: SPIN_UNLOCK
1690: IRQ_UNLOCK
1691: time = jiffies;
1692: while ((jiffies - time) < (10 * HZ) && limit++ < 200000) udelay(100L);
1693: IRQ_LOCK
1694: SPIN_LOCK
1695: printk("%s: reset, interrupts disabled, loops %d.\n", BN(j), limit);
1696:
1697: for (i = 0; i < sh[j]->can_queue; i++) {
1698:
1699: if (HD(j)->cp_stat[i] == IN_RESET) {
1700: SCpnt = HD(j)->cp[i].SCpnt;
1701: SCpnt->result = DID_RESET << 16;
1702: SCpnt->host_scribble = NULL;
1703:
1704: /* This mailbox is still waiting for its interrupt */
1705: HD(j)->cp_stat[i] = LOCKED;
1706:
1707: printk("%s, reset, mbox %d locked, DID_RESET, pid %ld done.\n",
1708: BN(j), i, SCpnt->pid);
1709: }
1710:
1711: else if (HD(j)->cp_stat[i] == ABORTING) {
1712: SCpnt = HD(j)->cp[i].SCpnt;
1713: SCpnt->result = DID_RESET << 16;
1714: SCpnt->host_scribble = NULL;
1715:
1716: /* This mailbox was never queued to the adapter */
1717: HD(j)->cp_stat[i] = FREE;
1718:
1719: printk("%s, reset, mbox %d aborting, DID_RESET, pid %ld done.\n",
1720: BN(j), i, SCpnt->pid);
1721: }
1722:
1723: else
1724:
1725: /* Any other mailbox has already been set free by interrupt */
1726: continue;
1727:
1728: SCpnt->scsi_done(SCpnt);
1729: IRQ_LOCK
1730: }
1731:
1732: HD(j)->in_reset = FALSE;
1733: do_trace = FALSE;
1734:
1735: if (arg_done) {
1736: printk("%s: reset, exit, success.\n", BN(j));
1737: return SCSI_RESET_SUCCESS;
1738: }
1739: else {
1740: printk("%s: reset, exit, wakeup.\n", BN(j));
1741: return SCSI_RESET_PUNT;
1742: }
1743: }
1744:
1745: int eata2x_old_reset(Scsi_Cmnd *SCarg, unsigned int reset_flags) {
1746: int rtn;
1747: IRQ_FLAGS
1748:
1749: IRQ_LOCK_SAVE
1750: rtn = do_old_reset(SCarg);
1751: IRQ_UNLOCK_RESTORE
1752: return rtn;
1753: }
1754:
1755: #if LINUX_VERSION_CODE >= LinuxVersionCode(2,1,101)
1756:
1757: static inline int do_reset(Scsi_Cmnd *SCarg) {
1758: unsigned int i, j, time, k, c, limit = 0;
1759: int arg_done = FALSE;
1760: Scsi_Cmnd *SCpnt;
1761:
1762: j = ((struct hostdata *) SCarg->host->hostdata)->board_number;
1763: printk("%s: reset, enter, target %d.%d:%d, pid %ld.\n",
1764: BN(j), SCarg->channel, SCarg->target, SCarg->lun, SCarg->pid);
1765:
1766: if (SCarg->host_scribble == NULL)
1767: printk("%s: reset, pid %ld inactive.\n", BN(j), SCarg->pid);
1768:
1769: if (HD(j)->in_reset) {
1770: printk("%s: reset, exit, already in reset.\n", BN(j));
1771: return FAILED;
1772: }
1773:
1774: if (wait_on_busy(sh[j]->io_port, MAXLOOP)) {
1775: printk("%s: reset, exit, timeout error.\n", BN(j));
1776: return FAILED;
1777: }
1778:
1779: HD(j)->retries = 0;
1780:
1781: for (c = 0; c <= sh[j]->max_channel; c++)
1782: for (k = 0; k < sh[j]->max_id; k++) {
1783: HD(j)->target_redo[k][c] = TRUE;
1784: HD(j)->target_to[k][c] = 0;
1785: }
1786:
1787: for (i = 0; i < sh[j]->can_queue; i++) {
1788:
1789: if (HD(j)->cp_stat[i] == FREE) continue;
1790:
1791: if (HD(j)->cp_stat[i] == LOCKED) {
1792: HD(j)->cp_stat[i] = FREE;
1793: printk("%s: reset, locked mbox %d forced free.\n", BN(j), i);
1794: continue;
1795: }
1796:
1797: if (!(SCpnt = HD(j)->cp[i].SCpnt))
1798: panic("%s: reset, mbox %d, SCpnt == NULL.\n", BN(j), i);
1799:
1800: if (HD(j)->cp_stat[i] == READY || HD(j)->cp_stat[i] == ABORTING) {
1801: HD(j)->cp_stat[i] = ABORTING;
1802: printk("%s: reset, mbox %d aborting, pid %ld.\n",
1803: BN(j), i, SCpnt->pid);
1804: }
1805:
1806: else {
1807: HD(j)->cp_stat[i] = IN_RESET;
1808: printk("%s: reset, mbox %d in reset, pid %ld.\n",
1809: BN(j), i, SCpnt->pid);
1810: }
1811:
1812: if (SCpnt->host_scribble == NULL)
1813: panic("%s: reset, mbox %d, garbled SCpnt.\n", BN(j), i);
1814:
1815: if (*(unsigned int *)SCpnt->host_scribble != i)
1816: panic("%s: reset, mbox %d, index mismatch.\n", BN(j), i);
1817:
1818: if (SCpnt->scsi_done == NULL)
1819: panic("%s: reset, mbox %d, SCpnt->scsi_done == NULL.\n", BN(j), i);
1820:
1821: if (SCpnt == SCarg) arg_done = TRUE;
1822: }
1823:
1824: if (do_dma(sh[j]->io_port, 0, RESET_PIO)) {
1825: printk("%s: reset, cannot reset, timeout error.\n", BN(j));
1826: return FAILED;
1827: }
1828:
1829: printk("%s: reset, board reset done, enabling interrupts.\n", BN(j));
1830:
1831: #if defined(DEBUG_RESET)
1832: do_trace = TRUE;
1833: #endif
1834:
1835: HD(j)->in_reset = TRUE;
1836: SPIN_UNLOCK
1837: IRQ_UNLOCK
1838: time = jiffies;
1839: while ((jiffies - time) < (10 * HZ) && limit++ < 200000) udelay(100L);
1840: IRQ_LOCK
1841: SPIN_LOCK
1842: printk("%s: reset, interrupts disabled, loops %d.\n", BN(j), limit);
1843:
1844: for (i = 0; i < sh[j]->can_queue; i++) {
1845:
1846: if (HD(j)->cp_stat[i] == IN_RESET) {
1847: SCpnt = HD(j)->cp[i].SCpnt;
1848: SCpnt->result = DID_RESET << 16;
1849: SCpnt->host_scribble = NULL;
1850:
1851: /* This mailbox is still waiting for its interrupt */
1852: HD(j)->cp_stat[i] = LOCKED;
1853:
1854: printk("%s, reset, mbox %d locked, DID_RESET, pid %ld done.\n",
1855: BN(j), i, SCpnt->pid);
1856: }
1857:
1858: else if (HD(j)->cp_stat[i] == ABORTING) {
1859: SCpnt = HD(j)->cp[i].SCpnt;
1860: SCpnt->result = DID_RESET << 16;
1861: SCpnt->host_scribble = NULL;
1862:
1863: /* This mailbox was never queued to the adapter */
1864: HD(j)->cp_stat[i] = FREE;
1865:
1866: printk("%s, reset, mbox %d aborting, DID_RESET, pid %ld done.\n",
1867: BN(j), i, SCpnt->pid);
1868: }
1869:
1870: else
1871:
1872: /* Any other mailbox has already been set free by interrupt */
1873: continue;
1874:
1875: SCpnt->scsi_done(SCpnt);
1876: IRQ_LOCK
1877: }
1878:
1879: HD(j)->in_reset = FALSE;
1880: do_trace = FALSE;
1881:
1882: if (arg_done) printk("%s: reset, exit, pid %ld done.\n", BN(j), SCarg->pid);
1883: else printk("%s: reset, exit.\n", BN(j));
1884:
1885: return SUCCESS;
1886: }
1887:
1888: int eata2x_reset(Scsi_Cmnd *SCarg) {
1889:
1890: return do_reset(SCarg);
1891: }
1892:
1893: #endif /* new_eh_code */
1894:
1895: int eata2x_biosparam(Disk *disk, kdev_t dev, int *dkinfo) {
1896: int size = disk->capacity;
1897:
1898: if (ext_tran || (scsicam_bios_param(disk, dev, dkinfo) < 0)) {
1899: dkinfo[0] = 255;
1900: dkinfo[1] = 63;
1901: dkinfo[2] = size / (dkinfo[0] * dkinfo[1]);
1902: }
1903:
1904: #if defined (DEBUG_GEOMETRY)
1905: printk ("%s: biosparam, head=%d, sec=%d, cyl=%d.\n", driver_name,
1906: dkinfo[0], dkinfo[1], dkinfo[2]);
1907: #endif
1908:
1909: return FALSE;
1910: }
1911:
1912: static void sort(unsigned long sk[], unsigned int da[], unsigned int n,
1913: unsigned int rev) {
1914: unsigned int i, j, k, y;
1915: unsigned long x;
1916:
1917: for (i = 0; i < n - 1; i++) {
1918: k = i;
1919:
1920: for (j = k + 1; j < n; j++)
1921: if (rev) {
1922: if (sk[j] > sk[k]) k = j;
1923: }
1924: else {
1925: if (sk[j] < sk[k]) k = j;
1926: }
1927:
1928: if (k != i) {
1929: x = sk[k]; sk[k] = sk[i]; sk[i] = x;
1930: y = da[k]; da[k] = da[i]; da[i] = y;
1931: }
1932: }
1933:
1934: return;
1935: }
1936:
1937: static inline int reorder(unsigned int j, unsigned long cursec,
1938: unsigned int ihdlr, unsigned int il[], unsigned int n_ready) {
1939: Scsi_Cmnd *SCpnt;
1940: struct mscp *cpp;
1941: unsigned int k, n;
1942: unsigned int rev = FALSE, s = TRUE, r = TRUE;
1943: unsigned int input_only = TRUE, overlap = FALSE;
1944: unsigned long sl[n_ready], pl[n_ready], ll[n_ready];
1945: unsigned long maxsec = 0, minsec = ULONG_MAX, seek = 0, iseek = 0;
1946: unsigned long ioseek = 0;
1947:
1948: static unsigned int flushcount = 0, batchcount = 0, sortcount = 0;
1949: static unsigned int readycount = 0, ovlcount = 0, inputcount = 0;
1950: static unsigned int readysorted = 0, revcount = 0;
1951: static unsigned long seeksorted = 0, seeknosort = 0;
1952:
1953: if (link_statistics && !(++flushcount % link_statistics))
1954: printk("fc %d bc %d ic %d oc %d rc %d rs %d sc %d re %d"\
1955: " av %ldK as %ldK.\n", flushcount, batchcount, inputcount,
1956: ovlcount, readycount, readysorted, sortcount, revcount,
1957: seeknosort / (readycount + 1),
1958: seeksorted / (readycount + 1));
1959:
1960: if (n_ready <= 1) return FALSE;
1961:
1962: for (n = 0; n < n_ready; n++) {
1963: k = il[n]; cpp = &HD(j)->cp[k]; SCpnt = cpp->SCpnt;
1964:
1965: if (!cpp->din) input_only = FALSE;
1966:
1967: if (SCpnt->request.sector < minsec) minsec = SCpnt->request.sector;
1968: if (SCpnt->request.sector > maxsec) maxsec = SCpnt->request.sector;
1969:
1970: sl[n] = SCpnt->request.sector;
1971: ioseek += SCpnt->request.nr_sectors;
1972:
1973: if (!n) continue;
1974:
1975: if (sl[n] < sl[n - 1]) s = FALSE;
1976: if (sl[n] > sl[n - 1]) r = FALSE;
1977:
1978: if (link_statistics) {
1979: if (sl[n] > sl[n - 1])
1980: seek += sl[n] - sl[n - 1];
1981: else
1982: seek += sl[n - 1] - sl[n];
1983: }
1984:
1985: }
1986:
1987: if (link_statistics) {
1988: if (cursec > sl[0]) seek += cursec - sl[0]; else seek += sl[0] - cursec;
1989: }
1990:
1991: if (cursec > ((maxsec + minsec) / 2)) rev = TRUE;
1992:
1993: if (ioseek > ((maxsec - minsec) / 2)) rev = FALSE;
1994:
1995: if (!((rev && r) || (!rev && s))) sort(sl, il, n_ready, rev);
1996:
1997: if (!input_only) for (n = 0; n < n_ready; n++) {
1998: k = il[n]; cpp = &HD(j)->cp[k]; SCpnt = cpp->SCpnt;
1999: ll[n] = SCpnt->request.nr_sectors; pl[n] = SCpnt->pid;
2000:
2001: if (!n) continue;
2002:
2003: if ((sl[n] == sl[n - 1]) || (!rev && ((sl[n - 1] + ll[n - 1]) > sl[n]))
2004: || (rev && ((sl[n] + ll[n]) > sl[n - 1]))) overlap = TRUE;
2005: }
2006:
2007: if (overlap) sort(pl, il, n_ready, FALSE);
2008:
2009: if (link_statistics) {
2010: if (cursec > sl[0]) iseek = cursec - sl[0]; else iseek = sl[0] - cursec;
2011: batchcount++; readycount += n_ready, seeknosort += seek / 1024;
2012: if (input_only) inputcount++;
2013: if (overlap) { ovlcount++; seeksorted += iseek / 1024; }
2014: else seeksorted += (iseek + maxsec - minsec) / 1024;
2015: if (rev && !r) { revcount++; readysorted += n_ready; }
2016: if (!rev && !s) { sortcount++; readysorted += n_ready; }
2017: }
2018:
2019: #if defined(DEBUG_LINKED_COMMANDS)
2020: if (link_statistics && (overlap || !(flushcount % link_statistics)))
2021: for (n = 0; n < n_ready; n++) {
2022: k = il[n]; cpp = &HD(j)->cp[k]; SCpnt = cpp->SCpnt;
2023: printk("%s %d.%d:%d pid %ld mb %d fc %d nr %d sec %ld ns %ld"\
2024: " cur %ld s:%c r:%c rev:%c in:%c ov:%c xd %d.\n",
2025: (ihdlr ? "ihdlr" : "qcomm"), SCpnt->channel, SCpnt->target,
2026: SCpnt->lun, SCpnt->pid, k, flushcount, n_ready,
2027: SCpnt->request.sector, SCpnt->request.nr_sectors, cursec,
2028: YESNO(s), YESNO(r), YESNO(rev), YESNO(input_only),
2029: YESNO(overlap), cpp->din);
2030: }
2031: #endif
2032: return overlap;
2033: }
2034:
2035: static void flush_dev(Scsi_Device *dev, unsigned long cursec, unsigned int j,
2036: unsigned int ihdlr) {
2037: Scsi_Cmnd *SCpnt;
2038: struct mscp *cpp;
2039: unsigned int k, n, n_ready = 0, il[MAX_MAILBOXES];
2040:
2041: for (k = 0; k < sh[j]->can_queue; k++) {
2042:
2043: if (HD(j)->cp_stat[k] != READY && HD(j)->cp_stat[k] != IN_USE) continue;
2044:
2045: cpp = &HD(j)->cp[k]; SCpnt = cpp->SCpnt;
2046:
2047: if (SCpnt->device != dev) continue;
2048:
2049: if (HD(j)->cp_stat[k] == IN_USE) return;
2050:
2051: il[n_ready++] = k;
2052: }
2053:
2054: if (reorder(j, cursec, ihdlr, il, n_ready)) n_ready = 1;
2055:
2056: for (n = 0; n < n_ready; n++) {
2057: k = il[n]; cpp = &HD(j)->cp[k]; SCpnt = cpp->SCpnt;
2058:
2059: if (do_dma(sh[j]->io_port, (unsigned int) cpp, SEND_CP_DMA)) {
2060: printk("%s: %s, target %d.%d:%d, pid %ld, mbox %d, adapter"\
2061: " busy, will abort.\n", BN(j), (ihdlr ? "ihdlr" : "qcomm"),
2062: SCpnt->channel, SCpnt->target, SCpnt->lun, SCpnt->pid, k);
2063: HD(j)->cp_stat[k] = ABORTING;
2064: continue;
2065: }
2066:
2067: HD(j)->cp_stat[k] = IN_USE;
2068: }
2069:
2070: }
2071:
2072: static inline void ihdlr(int irq, unsigned int j) {
2073: Scsi_Cmnd *SCpnt;
2074: unsigned int i, k, c, status, tstatus, reg;
2075: struct mssp *dspp, *spp;
2076: struct mscp *cpp;
2077:
2078: if (sh[j]->irq != irq)
2079: panic("%s: ihdlr, irq %d, sh[j]->irq %d.\n", BN(j), irq, sh[j]->irq);
2080:
2081: /* Check if this board need to be serviced */
2082: if (!(inb(sh[j]->io_port + REG_AUX_STATUS) & IRQ_ASSERTED)) return;
2083:
2084: HD(j)->iocount++;
2085:
2086: if (do_trace) printk("%s: ihdlr, enter, irq %d, count %d.\n", BN(j), irq,
2087: HD(j)->iocount);
2088:
2089: /* Check if this board is still busy */
2090: if (wait_on_busy(sh[j]->io_port, 20 * MAXLOOP)) {
2091: reg = inb(sh[j]->io_port + REG_STATUS);
2092: printk("%s: ihdlr, busy timeout error, irq %d, reg 0x%x, count %d.\n",
2093: BN(j), irq, reg, HD(j)->iocount);
2094: return;
2095: }
2096:
2097: dspp = &HD(j)->sp[0];
2098: spp = &HD(j)->sp[1];
2099:
2100: /* Make a local copy just before clearing the interrupt indication */
2101: memcpy(spp, dspp, sizeof(struct mssp));
2102:
2103: /* Clear the completion flag and cp pointer on the dynamic copy of sp */
2104: memset(dspp, 0, sizeof(struct mssp));
2105:
2106: /* Read the status register to clear the interrupt indication */
2107: reg = inb(sh[j]->io_port + REG_STATUS);
2108:
2109: /* Reject any sp with supspect data */
2110: if (spp->eoc == FALSE)
2111: printk("%s: ihdlr, spp->eoc == FALSE, irq %d, reg 0x%x, count %d.\n",
2112: BN(j), irq, reg, HD(j)->iocount);
2113: if (spp->cpp == NULL)
2114: printk("%s: ihdlr, spp->cpp == NULL, irq %d, reg 0x%x, count %d.\n",
2115: BN(j), irq, reg, HD(j)->iocount);
2116: if (spp->eoc == FALSE || spp->cpp == NULL) return;
2117:
2118: cpp = spp->cpp;
2119:
2120: #if defined(DEBUG_GENERATE_ABORTS)
2121: if ((HD(j)->iocount > 500) && ((HD(j)->iocount % 500) < 3)) return;
2122: #endif
2123:
2124: /* Find the mailbox to be serviced on this board */
2125: i = cpp - HD(j)->cp;
2126:
2127: if (cpp < HD(j)->cp || cpp >= HD(j)->cp + sh[j]->can_queue
2128: || i >= sh[j]->can_queue)
2129: panic("%s: ihdlr, invalid mscp bus address %p, cp0 %p.\n", BN(j),
2130: cpp, HD(j)->cp);
2131:
2132: if (HD(j)->cp_stat[i] == IGNORE) {
2133: HD(j)->cp_stat[i] = FREE;
2134: return;
2135: }
2136: else if (HD(j)->cp_stat[i] == LOCKED) {
2137: HD(j)->cp_stat[i] = FREE;
2138: printk("%s: ihdlr, mbox %d unlocked, count %d.\n", BN(j), i,
2139: HD(j)->iocount);
2140: return;
2141: }
2142: else if (HD(j)->cp_stat[i] == FREE) {
2143: printk("%s: ihdlr, mbox %d is free, count %d.\n", BN(j), i,
2144: HD(j)->iocount);
2145: return;
2146: }
2147: else if (HD(j)->cp_stat[i] == IN_RESET)
2148: printk("%s: ihdlr, mbox %d is in reset.\n", BN(j), i);
2149: else if (HD(j)->cp_stat[i] != IN_USE)
2150: panic("%s: ihdlr, mbox %d, invalid cp_stat: %d.\n",
2151: BN(j), i, HD(j)->cp_stat[i]);
2152:
2153: HD(j)->cp_stat[i] = FREE;
2154: SCpnt = cpp->SCpnt;
2155:
2156: if (SCpnt == NULL) panic("%s: ihdlr, mbox %d, SCpnt == NULL.\n", BN(j), i);
2157:
2158: if (SCpnt->host_scribble == NULL)
2159: panic("%s: ihdlr, mbox %d, pid %ld, SCpnt %p garbled.\n", BN(j), i,
2160: SCpnt->pid, SCpnt);
2161:
2162: if (*(unsigned int *)SCpnt->host_scribble != i)
2163: panic("%s: ihdlr, mbox %d, pid %ld, index mismatch %d.\n",
2164: BN(j), i, SCpnt->pid, *(unsigned int *)SCpnt->host_scribble);
2165:
2166: if (linked_comm && SCpnt->device->queue_depth > 2
2167: && TLDEV(SCpnt->device->type))
2168: flush_dev(SCpnt->device, SCpnt->request.sector, j, TRUE);
2169:
2170: tstatus = status_byte(spp->target_status);
2171:
2172: #if defined(DEBUG_GENERATE_ERRORS)
2173: if ((HD(j)->iocount > 500) && ((HD(j)->iocount % 200) < 2))
2174: spp->adapter_status = 0x01;
2175: #endif
2176:
2177: switch (spp->adapter_status) {
2178: case ASOK: /* status OK */
2179:
2180: /* Forces a reset if a disk drive keeps returning BUSY */
2181: if (tstatus == BUSY && SCpnt->device->type != TYPE_TAPE)
2182: status = DID_ERROR << 16;
2183:
2184: /* If there was a bus reset, redo operation on each target */
2185: else if (tstatus != GOOD && SCpnt->device->type == TYPE_DISK
2186: && HD(j)->target_redo[SCpnt->target][SCpnt->channel])
2187: status = DID_BUS_BUSY << 16;
2188:
2189: /* Works around a flaw in scsi.c */
2190: else if (tstatus == CHECK_CONDITION
2191: && SCpnt->device->type == TYPE_DISK
2192: && (SCpnt->sense_buffer[2] & 0xf) == RECOVERED_ERROR)
2193: status = DID_BUS_BUSY << 16;
2194:
2195: else
2196: status = DID_OK << 16;
2197:
2198: if (tstatus == GOOD)
2199: HD(j)->target_redo[SCpnt->target][SCpnt->channel] = FALSE;
2200:
2201: if (spp->target_status && SCpnt->device->type == TYPE_DISK)
2202: printk("%s: ihdlr, target %d.%d:%d, pid %ld, "\
2203: "target_status 0x%x, sense key 0x%x.\n", BN(j),
2204: SCpnt->channel, SCpnt->target, SCpnt->lun,
2205: SCpnt->pid, spp->target_status,
2206: SCpnt->sense_buffer[2]);
2207:
2208: HD(j)->target_to[SCpnt->target][SCpnt->channel] = 0;
2209:
2210: if (HD(j)->last_retried_pid == SCpnt->pid) HD(j)->retries = 0;
2211:
2212: break;
2213: case ASST: /* Selection Time Out */
2214: case 0x02: /* Command Time Out */
2215:
2216: if (HD(j)->target_to[SCpnt->target][SCpnt->channel] > 1)
2217: status = DID_ERROR << 16;
2218: else {
2219: status = DID_TIME_OUT << 16;
2220: HD(j)->target_to[SCpnt->target][SCpnt->channel]++;
2221: }
2222:
2223: break;
2224:
2225: /* Perform a limited number of internal retries */
2226: case 0x03: /* SCSI Bus Reset Received */
2227: case 0x04: /* Initial Controller Power-up */
2228:
2229: for (c = 0; c <= sh[j]->max_channel; c++)
2230: for (k = 0; k < sh[j]->max_id; k++)
2231: HD(j)->target_redo[k][c] = TRUE;
2232:
2233: if (SCpnt->device->type != TYPE_TAPE
2234: && HD(j)->retries < MAX_INTERNAL_RETRIES) {
2235:
2236: #if defined(DID_SOFT_ERROR)
2237: status = DID_SOFT_ERROR << 16;
2238: #else
2239: status = DID_BUS_BUSY << 16;
2240: #endif
2241: HD(j)->retries++;
2242: HD(j)->last_retried_pid = SCpnt->pid;
2243: }
2244: else
2245: status = DID_ERROR << 16;
2246:
2247: break;
2248: case 0x05: /* Unexpected Bus Phase */
2249: case 0x06: /* Unexpected Bus Free */
2250: case 0x07: /* Bus Parity Error */
2251: case 0x08: /* SCSI Hung */
2252: case 0x09: /* Unexpected Message Reject */
2253: case 0x0a: /* SCSI Bus Reset Stuck */
2254: case 0x0b: /* Auto Request-Sense Failed */
2255: case 0x0c: /* Controller Ram Parity Error */
2256: default:
2257: status = DID_ERROR << 16;
2258: break;
2259: }
2260:
2261: SCpnt->result = status | spp->target_status;
2262:
2263: #if defined(DEBUG_INTERRUPT)
2264: if (SCpnt->result || do_trace)
2265: #else
2266: if ((spp->adapter_status != ASOK && HD(j)->iocount > 1000) ||
2267: (spp->adapter_status != ASOK &&
2268: spp->adapter_status != ASST && HD(j)->iocount <= 1000) ||
2269: do_trace || msg_byte(spp->target_status))
2270: #endif
2271: printk("%s: ihdlr, mbox %2d, err 0x%x:%x,"\
2272: " target %d.%d:%d, pid %ld, reg 0x%x, count %d.\n",
2273: BN(j), i, spp->adapter_status, spp->target_status,
2274: SCpnt->channel, SCpnt->target, SCpnt->lun, SCpnt->pid,
2275: reg, HD(j)->iocount);
2276:
2277: /* Set the command state to inactive */
2278: SCpnt->host_scribble = NULL;
2279:
2280: SCpnt->scsi_done(SCpnt);
2281:
2282: if (do_trace) printk("%s: ihdlr, exit, irq %d, count %d.\n", BN(j), irq,
2283: HD(j)->iocount);
2284:
2285: return;
2286: }
2287:
2288: static void do_interrupt_handler(int irq, void *shap, struct pt_regs *regs) {
2289: unsigned int j;
2290: IRQ_FLAGS
2291: SPIN_FLAGS
2292:
2293: /* Check if the interrupt must be processed by this handler */
2294: if ((j = (unsigned int)((char *)shap - sha)) >= num_boards) return;
2295:
2296: SPIN_LOCK_SAVE
2297: IRQ_LOCK_SAVE
2298: ihdlr(irq, j);
2299: IRQ_UNLOCK_RESTORE
2300: SPIN_UNLOCK_RESTORE
2301: }
2302:
2303: int eata2x_release(struct Scsi_Host *shpnt) {
2304: unsigned int i, j;
2305: IRQ_FLAGS
2306:
2307: IRQ_LOCK_SAVE
2308:
2309: for (j = 0; sh[j] != NULL && sh[j] != shpnt; j++);
2310:
2311: if (sh[j] == NULL) panic("%s: release, invalid Scsi_Host pointer.\n",
2312: driver_name);
2313:
2314: for (i = 0; i < sh[j]->can_queue; i++)
2315: if ((&HD(j)->cp[i])->sglist) kfree((&HD(j)->cp[i])->sglist);
2316:
2317: free_irq(sh[j]->irq, &sha[j]);
2318:
2319: if (sh[j]->dma_channel != NO_DMA) free_dma(sh[j]->dma_channel);
2320:
2321: release_region(sh[j]->io_port, sh[j]->n_io_port);
2322: scsi_unregister(sh[j]);
2323: IRQ_UNLOCK_RESTORE
2324: return FALSE;
2325: }
2326:
2327: #if defined(MODULE)
2328: Scsi_Host_Template driver_template = EATA;
2329:
2330: #include "scsi_module.c"
2331: #endif
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.