Bug Summary

File:obj-scan-build/../linux/src/drivers/scsi/eata.c
Location:line 1944, column 18
Description:Declared variable-length array (VLA) has zero size

Annotated Source Code

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 (dario@milano.europe.dg.com)
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)) (((v)<<16)+((p)<<8)+(s))
357#define MAX_INT_PARAM10 10
358
359#if defined(MODULE)
360#include <linux/module.h>
361
362#if LINUX_VERSION_CODE131108 >= LinuxVersionCode(2,1,26)(((2)<<16)+((1)<<8)+(26))
363MODULE_PARM(io_port, "1-" __MODULE_STRING(MAX_INT_PARAM10) "i");
364MODULE_PARM(linked_comm, "i");
365MODULE_PARM(tagged_comm, "i");
366MODULE_PARM(link_statistics, "i");
367MODULE_PARM(max_queue_depth, "i");
368MODULE_PARM(tag_mode, "i");
369MODULE_PARM(use_new_eh_code, "i");
370MODULE_PARM(ext_tran, "i");
371MODULE_PARM(rev_scan, "i");
372MODULE_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_CODE131108 < LinuxVersionCode(2,1,93)(((2)<<16)+((1)<<8)+(93))
398#include <linux/bios32.h>
399#endif
400
401#if LINUX_VERSION_CODE131108 >= LinuxVersionCode(2,1,36)(((2)<<16)+((1)<<8)+(36))
402#include <linux/init.h>
403#else
404#define __initfunc(A)A A
405#define __initdata
406#define __init
407#endif
408
409#if LINUX_VERSION_CODE131108 >= LinuxVersionCode(2,1,101)(((2)<<16)+((1)<<8)+(101))
410#include <asm/spinlock.h>
411#define IRQ_FLAGSunsigned long irq_flags;
412#define IRQ_LOCK__asm__ __volatile__ ("cli": : :"memory");
413#define IRQ_LOCK_SAVEdo {__asm__ __volatile__("pushf ; pop %0" : "=r" (irq_flags):
:"memory"); __asm__ __volatile__ ("cli": : :"memory");} while
(0);
414#define IRQ_UNLOCK__asm__ __volatile__ ("sti": : :"memory");
415#define IRQ_UNLOCK_RESTOREdo {__asm__ __volatile__("push %0 ; popf": :"g" (irq_flags):"memory"
);} while (0);
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);
422static int use_new_eh_code = TRUE1;
423#else
424#define IRQ_FLAGSunsigned long irq_flags; unsigned long irq_flags;
425#define IRQ_LOCK__asm__ __volatile__ ("cli": : :"memory"); cli()__asm__ __volatile__ ("cli": : :"memory");
426#define IRQ_LOCK_SAVEdo {__asm__ __volatile__("pushf ; pop %0" : "=r" (irq_flags):
:"memory"); __asm__ __volatile__ ("cli": : :"memory");} while
(0);
do {save_flags(irq_flags)__asm__ __volatile__("pushf ; pop %0" : "=r" (irq_flags): :"memory"
)
; cli()__asm__ __volatile__ ("cli": : :"memory");} while (0);
427#define IRQ_UNLOCK__asm__ __volatile__ ("sti": : :"memory"); sti()__asm__ __volatile__ ("sti": : :"memory");
428#define IRQ_UNLOCK_RESTOREdo {__asm__ __volatile__("push %0 ; popf": :"g" (irq_flags):"memory"
);} while (0);
do {restore_flags(irq_flags)__asm__ __volatile__("push %0 ; popf": :"g" (irq_flags):"memory"
)
;} while (0);
429#define SPIN_FLAGS
430#define SPIN_LOCK
431#define SPIN_LOCK_SAVE
432#define SPIN_UNLOCK
433#define SPIN_UNLOCK_RESTORE
434static int use_new_eh_code = FALSE0;
435#endif
436
437struct proc_dir_entry proc_scsi_eata2x = {
438 PROC_SCSI_EATA2X, 6, "eata2x",
439 S_IFDIR0040000 | S_IRUGO(00400|00040|00004) | S_IXUGO(00100|00010|00001), 2
440};
441
442/* Subversion values */
443#define ISA0 0
444#define ESA1 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_ISA4 4
458#define MAX_VESA0 0
459#define MAX_EISA15 15
460#define MAX_PCI16 16
461#define MAX_BOARDS(4 + 0 + 15 + 16) (MAX_ISA4 + MAX_VESA0 + MAX_EISA15 + MAX_PCI16)
462#define MAX_CHANNEL4 4
463#define MAX_LUN32 32
464#define MAX_TARGET32 32
465#define MAX_MAILBOXES64 64
466#define MAX_SGLIST64 64
467#define MAX_LARGE_SGLIST122 122
468#define MAX_INTERNAL_RETRIES64 64
469#define MAX_CMD_PER_LUN2 2
470#define MAX_TAGGED_CMD_PER_LUN(64 - 2) (MAX_MAILBOXES64 - MAX_CMD_PER_LUN2)
471
472#define SKIP(~0UL) ULONG_MAX(~0UL)
473#define FALSE0 0
474#define TRUE1 1
475#define FREE0 0
476#define IN_USE1 1
477#define LOCKED2 2
478#define IN_RESET3 3
479#define IGNORE4 4
480#define READY5 5
481#define ABORTING6 6
482#define NO_DMA0xff 0xff
483#define MAXLOOP10000 10000
484#define TAG_MIXED0 0
485#define TAG_SIMPLE1 1
486#define TAG_HEAD2 2
487#define TAG_ORDERED3 3
488
489#define REG_CMD7 7
490#define REG_STATUS7 7
491#define REG_AUX_STATUS8 8
492#define REG_DATA0 0
493#define REG_DATA21 1
494#define REG_SEE6 6
495#define REG_LOW2 2
496#define REG_LM3 3
497#define REG_MID4 4
498#define REG_MSB5 5
499#define REGION_SIZE9 9
500#define MAX_ISA_ADDR0x03ff 0x03ff
501#define MIN_EISA_ADDR0x1c88 0x1c88
502#define MAX_EISA_ADDR0xfc88 0xfc88
503#define BSY_ASSERTED0x80 0x80
504#define DRQ_ASSERTED0x08 0x08
505#define ABSY_ASSERTED0x01 0x01
506#define IRQ_ASSERTED0x02 0x02
507#define READ_CONFIG_PIO0xf0 0xf0
508#define SET_CONFIG_PIO0xf1 0xf1
509#define SEND_CP_PIO0xf2 0xf2
510#define RECEIVE_SP_PIO0xf3 0xf3
511#define TRUNCATE_XFR_PIO0xf4 0xf4
512#define RESET_PIO0xf9 0xf9
513#define READ_CONFIG_DMA0xfd 0xfd
514#define SET_CONFIG_DMA0xfe 0xfe
515#define SEND_CP_DMA0xff 0xff
516#define ASOK0x00 0x00
517#define ASST0x01 0x01
518
519#define ARRAY_SIZE(arr)(sizeof (arr) / sizeof (arr)[0]) (sizeof (arr) / sizeof (arr)[0])
520#define YESNO(a)((a) ? 'y' : 'n') ((a) ? 'y' : 'n')
521#define TLDEV(type)((type) == 0x00 || (type) == 0x05) ((type) == TYPE_DISK0x00 || (type) == TYPE_ROM0x05)
522
523/* "EATA", in Big Endian format */
524#define EATA_SIGNATURE0x41544145 0x41544145
525
526/* Number of valid bytes in the board config structure for EATA 2.0x */
527#define EATA_2_0A_SIZE28 28
528#define EATA_2_0B_SIZE30 30
529#define EATA_2_0C_SIZE34 34
530
531/* Board info structure */
532struct 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 */
581struct 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 */
592struct 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
602struct sg_list {
603 unsigned int address; /* Segment Address */
604 unsigned int num_bytes; /* Segment Length */
605 };
606
607/* MailBox SCSI Command Packet */
608struct 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
643struct hostdata {
644 struct mscp cp[MAX_MAILBOXES64]; /* Mailboxes for this board */
645 unsigned int cp_stat[MAX_MAILBOXES64]; /* 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_TARGET32][MAX_CHANNEL4]; /* N. of timeout errors on target */
653 int target_redo[MAX_TARGET32][MAX_CHANNEL4]; /* 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
661static struct Scsi_Host *sh[MAX_BOARDS(4 + 0 + 15 + 16) + 1];
662static const char *driver_name = "EATA";
663static char sha[MAX_BOARDS(4 + 0 + 15 + 16)];
664
665/* Initialize num_boards so that ihdlr can work while detect is in progress */
666static unsigned int num_boards = MAX_BOARDS(4 + 0 + 15 + 16);
667
668static unsigned long io_port[] __initdata = {
669
670 /* Space for MAX_INT_PARAM ports usable while loading as a module */
671 SKIP(~0UL), SKIP(~0UL), SKIP(~0UL), SKIP(~0UL), SKIP(~0UL), SKIP(~0UL), SKIP(~0UL), SKIP(~0UL),
672 SKIP(~0UL), SKIP(~0UL),
673
674 /* First ISA */
675 0x1f0,
676
677 /* Space for MAX_PCI ports possibly reported by PCI_BIOS */
678 SKIP(~0UL), SKIP(~0UL), SKIP(~0UL), SKIP(~0UL), SKIP(~0UL), SKIP(~0UL), SKIP(~0UL), SKIP(~0UL),
679 SKIP(~0UL), SKIP(~0UL), SKIP(~0UL), SKIP(~0UL), SKIP(~0UL), SKIP(~0UL), SKIP(~0UL), SKIP(~0UL),
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) ((struct hostdata *) &sh[board]->hostdata)
693#define BN(board)(((struct hostdata *) &sh[board]->hostdata)->board_name
)
(HD(board)((struct hostdata *) &sh[board]->hostdata)->board_name)
694
695#define H2DEV(x)htonl(x) htonl(x)
696#define DEV2H(x)htonl(x) H2DEV(x)htonl(x)
697#define V2DEV(addr)((addr) ? htonl(virt_to_phys((void *)addr)) : 0) ((addr) ? H2DEV(virt_to_bus((void *)addr))htonl(virt_to_phys((void *)addr)) : 0)
698#define DEV2V(addr)((addr) ? htonl(phys_to_virt((unsigned long)addr)) : 0) ((addr) ? DEV2H(bus_to_virt((unsigned long)addr))htonl(phys_to_virt((unsigned long)addr)) : 0)
699
700static void do_interrupt_handler(int, void *, struct pt_regs *);
701static void flush_dev(Scsi_Device *, unsigned long, unsigned int, unsigned int);
702static int do_trace = FALSE0;
703static int setup_done = FALSE0;
704static int link_statistics = 0;
705static int tag_mode = TAG_MIXED0;
706static int ext_tran = FALSE0;
707static int rev_scan = TRUE1;
708
709#if defined(CONFIG_SCSI_EATA_TAGGED_QUEUE)
710static int tagged_comm = TRUE1;
711#else
712static int tagged_comm = FALSE0;
713#endif
714
715#if defined(CONFIG_SCSI_EATA_LINKED_COMMANDS)
716static int linked_comm = TRUE1;
717#else
718static int linked_comm = FALSE0;
719#endif
720
721#if defined(CONFIG_SCSI_EATA_MAX_TAGS)
722static int max_queue_depth = CONFIG_SCSI_EATA_MAX_TAGS;
723#else
724static int max_queue_depth = MAX_CMD_PER_LUN2;
725#endif
726
727static 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_FLAGSunsigned long irq_flags;
731
732 IRQ_LOCK_SAVEdo {__asm__ __volatile__("pushf ; pop %0" : "=r" (irq_flags):
:"memory"); __asm__ __volatile__ ("cli": : :"memory");} while
(0);
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->type) == 0x00 || (dev->type) == 0x05) && (dev->tagged_supported || linked_comm))
740 ntag++;
741 else
742 nuntag++;
743 }
744
745 utqd = MAX_CMD_PER_LUN2;
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_LUN2) tqd = MAX_CMD_PER_LUN2;
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->type) == 0x00 || (dev->type) == 0x05) && (dev->tagged_supported || linked_comm))
759 dev->queue_depth = tqd;
760 else
761 dev->queue_depth = utqd;
762
763 if (TLDEV(dev->type)((dev->type) == 0x00 || (dev->type) == 0x05)) {
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)((dev->type) == 0x00 || (dev->type) == 0x05)) {
771 dev->tagged_queue = 1;
772 dev->current_tag = 1;
773 }
774
775 if (dev->tagged_supported && TLDEV(dev->type)((dev->type) == 0x00 || (dev->type) == 0x05) && dev->tagged_queue)
776 tag_suffix = ", tagged";
777 else if (dev->tagged_supported && TLDEV(dev->type)((dev->type) == 0x00 || (dev->type) == 0x05))
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)(((struct hostdata *) &sh[j]->hostdata)->board_name
)
, host->host_no, dev->channel, dev->id, dev->lun,
782 dev->queue_depth, link_suffix, tag_suffix);
783 }
784
785 IRQ_UNLOCK_RESTOREdo {__asm__ __volatile__("push %0 ; popf": :"g" (irq_flags):"memory"
);} while (0);
786 return;
787}
788
789static inlineinline __attribute__((always_inline)) int wait_on_busy(unsigned long iobase, unsigned int loop) {
790
791 while (inb(iobase + REG_AUX_STATUS)((__builtin_constant_p((iobase + 8)) && (iobase + 8) <
256) ? __inbc(iobase + 8) : __inb(iobase + 8))
& ABSY_ASSERTED0x01) {
792 udelay(1L)(__builtin_constant_p(1L) ? __const_udelay((1L) * 0x10c6ul) :
__udelay(1L))
;
793 if (--loop == 0) return TRUE1;
794 }
795
796 return FALSE0;
797}
798
799static inlineinline __attribute__((always_inline)) int do_dma(unsigned long iobase, unsigned int addr, unchar cmd) {
800
801 if (wait_on_busy(iobase, (addr ? MAXLOOP10000 * 100 : MAXLOOP10000))) return TRUE1;
802
803 if ((addr = V2DEV(addr)((addr) ? htonl(virt_to_phys((void *)addr)) : 0))) {
804 outb((char) (addr >> 24), iobase + REG_LOW)((__builtin_constant_p((iobase + 2)) && (iobase + 2) <
256) ? __outbc(((char) (addr >> 24)),(iobase + 2)) : __outb
(((char) (addr >> 24)),(iobase + 2)))
;
805 outb((char) (addr >> 16), iobase + REG_LM)((__builtin_constant_p((iobase + 3)) && (iobase + 3) <
256) ? __outbc(((char) (addr >> 16)),(iobase + 3)) : __outb
(((char) (addr >> 16)),(iobase + 3)))
;
806 outb((char) (addr >> 8), iobase + REG_MID)((__builtin_constant_p((iobase + 4)) && (iobase + 4) <
256) ? __outbc(((char) (addr >> 8)),(iobase + 4)) : __outb
(((char) (addr >> 8)),(iobase + 4)))
;
807 outb((char) addr, iobase + REG_MSB)((__builtin_constant_p((iobase + 5)) && (iobase + 5) <
256) ? __outbc(((char) addr),(iobase + 5)) : __outb(((char) addr
),(iobase + 5)))
;
808 }
809
810 outb(cmd, iobase + REG_CMD)((__builtin_constant_p((iobase + 7)) && (iobase + 7) <
256) ? __outbc((cmd),(iobase + 7)) : __outb((cmd),(iobase + 7
)))
;
811 return FALSE0;
812}
813
814static inlineinline __attribute__((always_inline)) int read_pio(unsigned long iobase, ushort *start, ushort *end) {
815 unsigned int loop = MAXLOOP10000;
816 ushort *p;
817
818 for (p = start; p <= end; p++) {
819
820 while (!(inb(iobase + REG_STATUS)((__builtin_constant_p((iobase + 7)) && (iobase + 7) <
256) ? __inbc(iobase + 7) : __inb(iobase + 7))
& DRQ_ASSERTED0x08)) {
821 udelay(1L)(__builtin_constant_p(1L) ? __const_udelay((1L) * 0x10c6ul) :
__udelay(1L))
;
822 if (--loop == 0) return TRUE1;
823 }
824
825 loop = MAXLOOP10000;
826 *p = inw(iobase)((__builtin_constant_p((iobase)) && (iobase) < 256
) ? __inwc(iobase) : __inw(iobase))
;
827 }
828
829 return FALSE0;
830}
831
832__initfunc (static inline intstatic inline __attribute__((always_inline)) int get_pci_irq(
unsigned long port_base, unsigned char *apic_irq)
833 get_pci_irq(unsigned long port_base, unsigned char *apic_irq))static inline __attribute__((always_inline)) int get_pci_irq(
unsigned long port_base, unsigned char *apic_irq)
{
834
835#if defined(CONFIG_PCI1)
836
837#if LINUX_VERSION_CODE131108 >= LinuxVersionCode(2,1,93)(((2)<<16)+((1)<<8)+(93))
838
839 unsigned int addr;
840 struct pci_dev *dev = NULL((void *) 0);
841
842 if (!pci_present()) return FALSE0;
843
844 while((dev = pci_find_class(PCI_CLASS_STORAGE_SCSI0x0100 << 8, dev))) {
845
846 if (pci_read_config_dword(dev, PCI_BASE_ADDRESS_00x10, &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_SPACE0x01) != PCI_BASE_ADDRESS_SPACE_IO0x01)
854 continue;
855
856 if ((addr & PCI_BASE_ADDRESS_IO_MASK(~0x03)) + PCI_BASE_ADDRESS_00x10 == port_base) {
857 *apic_irq = dev->irq;
858 return TRUE1;
859 }
860
861 }
862
863#endif /* end new style PCI code */
864
865#endif /* end CONFIG_PCI */
866
867 return FALSE0;
868}
869
870__initfunc (static inline int port_detect \static inline __attribute__((always_inline)) int port_detect (
unsigned long port_base, unsigned int j, Scsi_Host_Template *
tpnt)
871 (unsigned long port_base, unsigned int j, Scsi_Host_Template *tpnt))static inline __attribute__((always_inline)) int port_detect (
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 sprintflinux_sprintf(name, "%s%d", driver_name, j);
883
884 printk("\rprobing eata on %lx", port_base);
885
886 if(check_region(port_base, REGION_SIZE9)) {
887 printk("%s: address 0x%03lx in use, skipping probe.\n", name, port_base);
888 return FALSE0;
889 }
890
891 if (do_dma(port_base, 0, READ_CONFIG_PIO0xf0)) return FALSE0;
892
893 /* Read the info structure */
894 if (read_pio(port_base, (ushort *)&info, (ushort *)&info.ipad[0]))
895 return FALSE0;
896
897 /* Check the controller "EATA" signature */
898 if (info.sign != EATA_SIGNATURE0x41544145) return FALSE0;
899
900 if (DEV2H(info.data_len)htonl(info.data_len) < EATA_2_0A_SIZE28) {
901 printk("%s: config structure size (%ld bytes) too short, detaching.\n",
902 name, DEV2H(info.data_len)htonl(info.data_len));
903 return FALSE0;
904 }
905 else if (DEV2H(info.data_len)htonl(info.data_len) == EATA_2_0A_SIZE28)
906 protocol_rev = 'A';
907 else if (DEV2H(info.data_len)htonl(info.data_len) == EATA_2_0B_SIZE30)
908 protocol_rev = 'B';
909 else
910 protocol_rev = 'C';
911
912 if (!setup_done && j > 0 && j <= MAX_PCI16) {
913 bus_type = "PCI";
914 subversion = ESA1;
915 }
916 else if (port_base > MAX_EISA_ADDR0xfc88 || (protocol_rev == 'C' && info.pci)) {
917 bus_type = "PCI";
918 subversion = ESA1;
919 }
920 else if (port_base >= MIN_EISA_ADDR0x1c88 || (protocol_rev == 'C' && info.eisa)) {
921 bus_type = "EISA";
922 subversion = ESA1;
923 }
924 else if (protocol_rev == 'C' && !info.eisa && !info.pci) {
925 bus_type = "ISA";
926 subversion = ISA0;
927 }
928 else if (port_base > MAX_ISA_ADDR0x03ff) {
929 bus_type = "PCI";
930 subversion = ESA1;
931 }
932 else {
933 bus_type = "ISA";
934 subversion = ISA0;
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 FALSE0;
941 }
942
943 if (info.drqvld) {
944
945 if (subversion == ESA1)
946 printk("%s: warning, weird %s board using DMA.\n", name, bus_type);
947
948 subversion = ISA0;
949 dma_channel = dma_channel_table[3 - info.drqx];
950 }
951 else {
952
953 if (subversion == ISA0)
954 printk("%s: warning, weird %s board not using DMA.\n", name, bus_type);
955
956 subversion = ESA1;
957 dma_channel = NO_DMA0xff;
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 == ESA1 && !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_INTERRUPT0x20000000 | ((subversion == ESA1) ? SA_SHIRQ0x04000000 : 0),
977 driver_name, (void *) &sha[j])) {
978 printk("%s: unable to allocate IRQ %u, detaching.\n", name, irq);
979 return FALSE0;
980 }
981
982 if (subversion == ISA0 && 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 FALSE0;
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))(__builtin_constant_p(0) ? (__builtin_constant_p((sizeof(struct
eata_config))) ? __constant_c_and_count_memset((((char *)&
config)),((0x01010101UL*(unsigned char)(0))),((sizeof(struct eata_config
)))) : __constant_c_memset((((char *)&config)),((0x01010101UL
*(unsigned char)(0))),((sizeof(struct eata_config))))) : (__builtin_constant_p
((sizeof(struct eata_config))) ? __memset_generic(((((char *)
&config))),(((0))),(((sizeof(struct eata_config))))) : __memset_generic
((((char *)&config)),((0)),((sizeof(struct eata_config)))
)))
;
995 config.len = (ushort) htons((ushort)510);
996 config.ocena = TRUE1;
997
998 if (do_dma(port_base, (unsigned int)&config, SET_CONFIG_DMA0xfe)) {
999 printk("%s: busy timeout sending configuration, detaching.\n", name);
1000 return FALSE0;
1001 }
1002 }
1003#endif
1004
1005 sh[j] = scsi_register(tpnt, sizeof(struct hostdata));
1006
1007 if (sh[j] == NULL((void *) 0)) {
1008 printk("%s: unable to register host, detaching.\n", name);
1009
1010 free_irq(irq, &sha[j]);
1011
1012 if (subversion == ISA0) free_dma(dma_channel);
1013
1014 return FALSE0;
1015 }
1016
1017 sh[j]->io_port = port_base;
1018 sh[j]->unique_id = port_base;
1019 sh[j]->n_io_port = REGION_SIZE9;
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_LUN2;
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))(__builtin_constant_p(0) ? (__builtin_constant_p((sizeof(struct
hostdata))) ? __constant_c_and_count_memset(((((struct hostdata
*) &sh[j]->hostdata))),((0x01010101UL*(unsigned char)
(0))),((sizeof(struct hostdata)))) : __constant_c_memset(((((
struct hostdata *) &sh[j]->hostdata))),((0x01010101UL*
(unsigned char)(0))),((sizeof(struct hostdata))))) : (__builtin_constant_p
((sizeof(struct hostdata))) ? __memset_generic((((((struct hostdata
*) &sh[j]->hostdata)))),(((0))),(((sizeof(struct hostdata
))))) : __memset_generic(((((struct hostdata *) &sh[j]->
hostdata))),((0)),((sizeof(struct hostdata))))))
;
1032 HD(j)((struct hostdata *) &sh[j]->hostdata)->subversion = subversion;
1033 HD(j)((struct hostdata *) &sh[j]->hostdata)->protocol_rev = protocol_rev;
1034 HD(j)((struct hostdata *) &sh[j]->hostdata)->board_number = j;
1035
1036 if (HD(j)((struct hostdata *) &sh[j]->hostdata)->subversion == ESA1)
1037 sh[j]->unchecked_isa_dma = FALSE0;
1038 else {
1039 sh[j]->wish_block = TRUE1;
1040 sh[j]->unchecked_isa_dma = TRUE1;
1041 disable_dma(dma_channel);
1042 clear_dma_ff(dma_channel);
1043 set_dma_mode(dma_channel, DMA_MODE_CASCADE0xC0);
1044 enable_dma(dma_channel);
1045 }
1046
1047 strcpy(BN(j)(((struct hostdata *) &sh[j]->hostdata)->board_name
)
, name);
1048
1049 /* DPT PM2012 does not allow to detect sg_tablesize correctly */
1050 if (sh[j]->sg_tablesize > MAX_SGLIST64 || sh[j]->sg_tablesize < 2) {
1051 printk("%s: detect, wrong n. of SG lists %d, fixed.\n",
1052 BN(j)(((struct hostdata *) &sh[j]->hostdata)->board_name
)
, sh[j]->sg_tablesize);
1053 sh[j]->sg_tablesize = MAX_SGLIST64;
1054 }
1055
1056 /* DPT PM2012 does not allow to detect can_queue correctly */
1057 if (sh[j]->can_queue > MAX_MAILBOXES64 || sh[j]->can_queue < 2) {
1058 printk("%s: detect, wrong n. of mbox %d, fixed.\n",
1059 BN(j)(((struct hostdata *) &sh[j]->hostdata)->board_name
)
, sh[j]->can_queue);
1060 sh[j]->can_queue = MAX_MAILBOXES64;
1061 }
1062
1063 if (protocol_rev != 'A') {
1064
1065 if (info.max_chan > 0 && info.max_chan < MAX_CHANNEL4)
1066 sh[j]->max_channel = info.max_chan;
1067
1068 if (info.max_id > 7 && info.max_id < MAX_TARGET32)
1069 sh[j]->max_id = info.max_id + 1;
1070
1071 if (info.large_sg && sh[j]->sg_tablesize == MAX_SGLIST64)
1072 sh[j]->sg_tablesize = MAX_LARGE_SGLIST122;
1073 }
1074
1075 if (protocol_rev == 'C') {
1076
1077 if (info.max_lun > 7 && info.max_lun < MAX_LUN32)
1078 sh[j]->max_lun = info.max_lun + 1;
1079 }
1080
1081 if (dma_channel == NO_DMA0xff) sprintflinux_sprintf(dma_name, "%s", "BMST");
1082 else sprintflinux_sprintf(dma_name, "DMA %u", dma_channel);
1083
1084 for (i = 0; i < sh[j]->can_queue; i++)
1085 if (! ((&HD(j)((struct hostdata *) &sh[j]->hostdata)->cp[i])->sglist = kmalloclinux_kmalloc(
1086 sh[j]->sg_tablesize * sizeof(struct sg_list),
1087 (sh[j]->unchecked_isa_dma ? GFP_DMA0x80 : 0) | GFP_ATOMIC0x01))) {
1088 printk("%s: kmalloc SGlist failed, mbox %d, detaching.\n", BN(j)(((struct hostdata *) &sh[j]->hostdata)->board_name
)
, i);
1089 eata2x_release(sh[j]);
1090 return FALSE0;
1091 }
1092
1093 if (max_queue_depth > MAX_TAGGED_CMD_PER_LUN(64 - 2))
1094 max_queue_depth = MAX_TAGGED_CMD_PER_LUN(64 - 2);
1095
1096 if (max_queue_depth < MAX_CMD_PER_LUN2) max_queue_depth = MAX_CMD_PER_LUN2;
1097
1098 if (tagged_comm) {
1099 if (tag_mode == TAG_SIMPLE1) tag_type = '1';
1100 else if (tag_mode == TAG_HEAD2) tag_type = '2';
1101 else if (tag_mode == TAG_ORDERED3) tag_type = '3';
1102 else tag_type = 'y';
1103 }
1104 else tag_type = 'n';
1105
1106#if LINUX_VERSION_CODE131108 >= LinuxVersionCode(2,1,101)(((2)<<16)+((1)<<8)+(101))
1107 sh[j]->hostt->use_new_eh_code = use_new_eh_code;
1108#else
1109 use_new_eh_code = FALSE0;
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)((linked_comm) ? 'y' : 'n'), max_queue_depth,
1116 YESNO(use_new_eh_code)((use_new_eh_code) ? 'y' : 'n'), YESNO(rev_scan)((rev_scan) ? 'y' : 'n'), YESNO(ext_tran)((ext_tran) ? 'y' : 'n'));
1117 }
1118
1119 printk("%s: 2.0%c, %s 0x%03lx, IRQ %u, %s, SG %d, MB %d.\n",
1120 BN(j)(((struct hostdata *) &sh[j]->hostdata)->board_name
)
, HD(j)((struct hostdata *) &sh[j]->hostdata)->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)(((struct hostdata *) &sh[j]->hostdata)->board_name
)
, 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)(((struct hostdata *) &sh[j]->hostdata)->board_name
)
, 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)htonl(info.data_len), DEV2H(info.cp_len)htonl(info.cp_len),
1136 DEV2H(info.sp_len)htonl(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 TRUE1;
1150}
1151
1152__initfunc (void eata2x_setup(char *str, int *ints))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_PARAM10) argc = MAX_INT_PARAM10;
1159
1160 for (i = 0; i < argc; i++) io_port[i] = ints[i + 1];
1161
1162 io_port[i] = 0;
1163 setup_done = TRUE1;
1164 }
1165
1166 while (cur && (pc = strchr(cur, ':'))) {
1167 int val = 0, c = *++pc;
1168
1169 if (c == 'n' || c == 'N') val = FALSE0;
1170 else if (c == 'y' || c == 'Y') val = TRUE1;
1171 else val = (int) simple_strtoul(pc, NULL((void *) 0), 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))static void add_pci_ports(void) {
1189
1190#if defined(CONFIG_PCI1)
1191
1192 unsigned int addr, k;
1193
1194#if LINUX_VERSION_CODE131108 >= LinuxVersionCode(2,1,93)(((2)<<16)+((1)<<8)+(93))
1195
1196 struct pci_dev *dev = NULL((void *) 0);
1197
1198 if (!pci_present()) return;
1199
1200 for (k = 0; k < MAX_PCI16; k++) {
1201
1202 if (!(dev = pci_find_class(PCI_CLASS_STORAGE_SCSI0x0100 << 8, dev))) break;
1203
1204 if (pci_read_config_dword(dev, PCI_BASE_ADDRESS_00x10, &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_SPACE0x01) != PCI_BASE_ADDRESS_SPACE_IO0x01)
1212 continue;
1213
1214 /* Order addresses according to rev_scan value */
1215 io_port[MAX_INT_PARAM10 + (rev_scan ? (MAX_PCI16 - k) : (1 + k))] =
1216 (addr & PCI_BASE_ADDRESS_IO_MASK(~0x03)) + PCI_BASE_ADDRESS_00x10;
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_PCI16; k++) {
1227
1228 if (pcibios_find_class(PCI_CLASS_STORAGE_SCSI0x0100 << 8, i++, &bus, &devfn)
1229 != PCIBIOS_SUCCESSFUL0x00) break;
1230
1231 if (pcibios_read_config_dword(bus, devfn, PCI_BASE_ADDRESS_00x10, &addr)
1232 != PCIBIOS_SUCCESSFUL0x00) 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_SPACE0x01) != PCI_BASE_ADDRESS_SPACE_IO0x01)
1240 continue;
1241
1242 /* Order addresses according to rev_scan value */
1243 io_port[MAX_INT_PARAM10 + (rev_scan ? (MAX_PCI16 - k) : (1 + k))] =
1244 (addr & PCI_BASE_ADDRESS_IO_MASK(~0x03)) + PCI_BASE_ADDRESS_00x10;
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))int eata2x_detect(Scsi_Host_Template *tpnt) {
1255 unsigned int j = 0, k;
1256 IRQ_FLAGSunsigned long irq_flags;
1257
1258 IRQ_LOCK_SAVEdo {__asm__ __volatile__("pushf ; pop %0" : "=r" (irq_flags):
:"memory"); __asm__ __volatile__ ("cli": : :"memory");} while
(0);
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(~0UL)) {
1264 setup_done = TRUE1;
1265 io_port[MAX_INT_PARAM10] = 0;
1266 }
1267#endif
1268
1269 for (k = 0; k < MAX_BOARDS(4 + 0 + 15 + 16) + 1; k++) sh[k] = NULL((void *) 0);
1270
1271 if (!setup_done) add_pci_ports();
1272
1273 for (k = 0; io_port[k]; k++) {
1274
1275 if (io_port[k] == SKIP(~0UL)) continue;
1276
1277 if (j < MAX_BOARDS(4 + 0 + 15 + 16) && port_detect(io_port[k], j, tpnt)) j++;
1278 }
1279
1280 num_boards = j;
1281 IRQ_UNLOCK_RESTOREdo {__asm__ __volatile__("push %0 ; popf": :"g" (irq_flags):"memory"
);} while (0);
1282 return j;
1283}
1284
1285static inlineinline __attribute__((always_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)((sgpnt[k].address) ? htonl(virt_to_phys((void *)sgpnt[k].address
)) : 0)
;
1293 cpp->sglist[k].num_bytes = H2DEV(sgpnt[k].length)htonl(sgpnt[k].length);
1294 }
1295
1296 cpp->data_address = V2DEV(cpp->sglist)((cpp->sglist) ? htonl(virt_to_phys((void *)cpp->sglist
)) : 0)
;
1297 cpp->data_len = H2DEV((SCpnt->use_sg * sizeof(struct sg_list)))htonl((SCpnt->use_sg * sizeof(struct sg_list)));
1298}
1299
1300static inlineinline __attribute__((always_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)
2
Taking false branch
1321 panic("%s: qcomm, pid %ld, SCpnt %p already active.\n",
1322 BN(j)(((struct hostdata *) &sh[j]->hostdata)->board_name
)
, 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)((struct hostdata *) &sh[j]->hostdata)->last_cp_used + 1;
1327
1328 for (k = 0; k < sh[j]->can_queue; k++, i++) {
3
Loop condition is false. Execution continues on line 1338
1329
1330 if (i >= sh[j]->can_queue) i = 0;
1331
1332 if (HD(j)((struct hostdata *) &sh[j]->hostdata)->cp_stat[i] == FREE0) {
1333 HD(j)((struct hostdata *) &sh[j]->hostdata)->last_cp_used = i;
1334 break;
1335 }
1336 }
1337
1338 if (k == sh[j]->can_queue) {
4
Taking false branch
1339 printk("%s: qcomm, no free mailbox.\n", BN(j)(((struct hostdata *) &sh[j]->hostdata)->board_name
)
);
1340 return 1;
1341 }
1342
1343 /* Set pointer to control packet structure */
1344 cpp = &HD(j)((struct hostdata *) &sh[j]->hostdata)->cp[i];
1345
1346 memset(cpp, 0, sizeof(struct mscp) - sizeof(struct sg_list *))(__builtin_constant_p(0) ? (__builtin_constant_p((sizeof(struct
mscp) - sizeof(struct sg_list *))) ? __constant_c_and_count_memset
(((cpp)),((0x01010101UL*(unsigned char)(0))),((sizeof(struct mscp
) - sizeof(struct sg_list *)))) : __constant_c_memset(((cpp))
,((0x01010101UL*(unsigned char)(0))),((sizeof(struct mscp) - sizeof
(struct sg_list *))))) : (__builtin_constant_p((sizeof(struct
mscp) - sizeof(struct sg_list *))) ? __memset_generic((((cpp
))),(((0))),(((sizeof(struct mscp) - sizeof(struct sg_list *)
)))) : __memset_generic(((cpp)),((0)),((sizeof(struct mscp) -
sizeof(struct sg_list *))))))
;
1347
1348 /* Set pointer to status packet structure */
1349 spp = &HD(j)((struct hostdata *) &sh[j]->hostdata)->sp[0];
1350
1351 /* The EATA protocol uses Big Endian format */
1352 cpp->sp_addr = V2DEV(spp)((spp) ? htonl(virt_to_phys((void *)spp)) : 0);
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",
5
Assuming 'do_trace' is 0
6
Taking false branch
1360 BN(j)(((struct hostdata *) &sh[j]->hostdata)->board_name
)
, i, SCpnt->channel, SCpnt->target,
1361 SCpnt->lun, SCpnt->pid);
1362
1363 for (k = 0; k < ARRAY_SIZE(data_out_cmds)(sizeof (data_out_cmds) / sizeof (data_out_cmds)[0]); k++)
7
Loop condition is true. Entering loop body
9
Loop condition is true. Entering loop body
11
Loop condition is true. Entering loop body
13
Loop condition is true. Entering loop body
1364 if (SCpnt->cmnd[0] == data_out_cmds[k]) {
8
Taking false branch
10
Taking false branch
12
Taking false branch
14
Taking true branch
1365 cpp->dout = TRUE1;
1366 break;
15
Execution continues on line 1369
1367 }
1368
1369 if ((cpp->din = !cpp->dout))
16
Taking false branch
1370 for (k = 0; k < ARRAY_SIZE(data_none_cmds)(sizeof (data_none_cmds) / sizeof (data_none_cmds)[0]); k++)
1371 if (SCpnt->cmnd[0] == data_none_cmds[k]) {
1372 cpp->din = FALSE0;
1373 break;
1374 }
1375
1376 cpp->reqsen = TRUE1;
1377 cpp->dispri = TRUE1;
1378#if 0
1379 if (SCpnt->device->type == TYPE_TAPE0x01) cpp->hbaci = TRUE1;
1380#endif
1381 cpp->one = TRUE1;
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)((SCpnt->sense_buffer) ? htonl(virt_to_phys((void *)SCpnt->
sense_buffer)) : 0)
;
1387 cpp->sense_len = sizeof SCpnt->sense_buffer;
1388
1389 if (SCpnt->device->tagged_queue) {
17
Taking false branch
1390
1391 if (HD(j)((struct hostdata *) &sh[j]->hostdata)->target_redo[SCpnt->target][SCpnt->channel] ||
1392 HD(j)((struct hostdata *) &sh[j]->hostdata)->target_to[SCpnt->target][SCpnt->channel])
1393 cpp->mess[0] = ORDERED_QUEUE_TAG0x22;
1394 else if (tag_mode == TAG_SIMPLE1) cpp->mess[0] = SIMPLE_QUEUE_TAG0x20;
1395 else if (tag_mode == TAG_HEAD2) cpp->mess[0] = HEAD_OF_QUEUE_TAG0x21;
1396 else if (tag_mode == TAG_ORDERED3) cpp->mess[0] = ORDERED_QUEUE_TAG0x22;
1397 else if (SCpnt->device->current_tag == 0)
1398 cpp->mess[0] = ORDERED_QUEUE_TAG0x22;
1399 else if (SCpnt->device->current_tag == 1)
1400 cpp->mess[0] = HEAD_OF_QUEUE_TAG0x21;
1401 else
1402 cpp->mess[0] = SIMPLE_QUEUE_TAG0x20;
1403
1404 cpp->mess[1] = SCpnt->device->current_tag++;
1405 }
1406
1407 if (SCpnt->use_sg) {
18
Taking false branch
1408 cpp->sg = TRUE1;
1409 build_sg_list(cpp, SCpnt);
1410 }
1411 else {
1412 cpp->data_address = V2DEV(SCpnt->request_buffer)((SCpnt->request_buffer) ? htonl(virt_to_phys((void *)SCpnt
->request_buffer)) : 0)
;
1413 cpp->data_len = H2DEV(SCpnt->request_bufflen)htonl(SCpnt->request_bufflen);
1414 }
1415
1416 memcpy(cpp->cdb, SCpnt->cmnd, SCpnt->cmd_len)(__builtin_constant_p(SCpnt->cmd_len) ? __constant_memcpy(
(cpp->cdb),(SCpnt->cmnd),(SCpnt->cmd_len)) : __memcpy
((cpp->cdb),(SCpnt->cmnd),(SCpnt->cmd_len)))
;
1417
1418 if (linked_comm && SCpnt->device->queue_depth > 2
19
Taking true branch
1419 && TLDEV(SCpnt->device->type)((SCpnt->device->type) == 0x00 || (SCpnt->device->
type) == 0x05)
) {
1420 HD(j)((struct hostdata *) &sh[j]->hostdata)->cp_stat[i] = READY5;
1421 flush_dev(SCpnt->device, SCpnt->request.sector, j, FALSE0);
20
Calling 'flush_dev'
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_DMA0xff)) {
1427 SCpnt->host_scribble = NULL((void *) 0);
1428 printk("%s: qcomm, target %d.%d:%d, pid %ld, adapter busy.\n",
1429 BN(j)(((struct hostdata *) &sh[j]->hostdata)->board_name
)
, SCpnt->channel, SCpnt->target, SCpnt->lun, SCpnt->pid);
1430 return 1;
1431 }
1432
1433 HD(j)((struct hostdata *) &sh[j]->hostdata)->cp_stat[i] = IN_USE1;
1434 return 0;
1435}
1436
1437int eata2x_queuecommand(Scsi_Cmnd *SCpnt, void (*done)(Scsi_Cmnd *)) {
1438 int rtn;
1439 IRQ_FLAGSunsigned long irq_flags;
1440
1441 IRQ_LOCK_SAVEdo {__asm__ __volatile__("pushf ; pop %0" : "=r" (irq_flags):
:"memory"); __asm__ __volatile__ ("cli": : :"memory");} while
(0);
1442 rtn = do_qcomm(SCpnt, done);
1
Calling 'do_qcomm'
1443 IRQ_UNLOCK_RESTOREdo {__asm__ __volatile__("push %0 ; popf": :"g" (irq_flags):"memory"
);} while (0);
1444 return rtn;
1445}
1446
1447static inlineinline __attribute__((always_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((void *) 0) ||
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)(((struct hostdata *) &sh[j]->hostdata)->board_name
)
, SCarg->channel, SCarg->target, SCarg->lun, SCarg->pid);
1457 return SCSI_ABORT_NOT_RUNNING4;
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)(((struct hostdata *) &sh[j]->hostdata)->board_name
)
, 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)(((struct hostdata *) &sh[j]->hostdata)->board_name
)
);
1466
1467 if (wait_on_busy(sh[j]->io_port, MAXLOOP10000)) {
1468 printk("%s: abort, timeout error.\n", BN(j)(((struct hostdata *) &sh[j]->hostdata)->board_name
)
);
1469 return SCSI_ABORT_ERROR5;
1470 }
1471
1472 if (HD(j)((struct hostdata *) &sh[j]->hostdata)->cp_stat[i] == FREE0) {
1473 printk("%s: abort, mbox %d is free.\n", BN(j)(((struct hostdata *) &sh[j]->hostdata)->board_name
)
, i);
1474 return SCSI_ABORT_NOT_RUNNING4;
1475 }
1476
1477 if (HD(j)((struct hostdata *) &sh[j]->hostdata)->cp_stat[i] == IN_USE1) {
1478 printk("%s: abort, mbox %d is in use.\n", BN(j)(((struct hostdata *) &sh[j]->hostdata)->board_name
)
, i);
1479
1480 if (SCarg != HD(j)((struct hostdata *) &sh[j]->hostdata)->cp[i].SCpnt)
1481 panic("%s: abort, mbox %d, SCarg %p, cp SCpnt %p.\n",
1482 BN(j)(((struct hostdata *) &sh[j]->hostdata)->board_name
)
, i, SCarg, HD(j)((struct hostdata *) &sh[j]->hostdata)->cp[i].SCpnt);
1483
1484 if (inb(sh[j]->io_port + REG_AUX_STATUS)((__builtin_constant_p((sh[j]->io_port + 8)) && (sh
[j]->io_port + 8) < 256) ? __inbc(sh[j]->io_port + 8
) : __inb(sh[j]->io_port + 8))
& IRQ_ASSERTED0x02)
1485 printk("%s: abort, mbox %d, interrupt pending.\n", BN(j)(((struct hostdata *) &sh[j]->hostdata)->board_name
)
, i);
1486
1487 return SCSI_ABORT_SNOOZE0;
1488 }
1489
1490 if (HD(j)((struct hostdata *) &sh[j]->hostdata)->cp_stat[i] == IN_RESET3) {
1491 printk("%s: abort, mbox %d is in reset.\n", BN(j)(((struct hostdata *) &sh[j]->hostdata)->board_name
)
, i);
1492 return SCSI_ABORT_ERROR5;
1493 }
1494
1495 if (HD(j)((struct hostdata *) &sh[j]->hostdata)->cp_stat[i] == LOCKED2) {
1496 printk("%s: abort, mbox %d is locked.\n", BN(j)(((struct hostdata *) &sh[j]->hostdata)->board_name
)
, i);
1497 return SCSI_ABORT_NOT_RUNNING4;
1498 }
1499
1500 if (HD(j)((struct hostdata *) &sh[j]->hostdata)->cp_stat[i] == READY5 || HD(j)((struct hostdata *) &sh[j]->hostdata)->cp_stat[i] == ABORTING6) {
1501 SCarg->result = DID_ABORT0x05 << 16;
1502 SCarg->host_scribble = NULL((void *) 0);
1503 HD(j)((struct hostdata *) &sh[j]->hostdata)->cp_stat[i] = FREE0;
1504 printk("%s, abort, mbox %d ready, DID_ABORT, pid %ld done.\n",
1505 BN(j)(((struct hostdata *) &sh[j]->hostdata)->board_name
)
, i, SCarg->pid);
1506 SCarg->scsi_done(SCarg);
1507 return SCSI_ABORT_SUCCESS1;
1508 }
1509
1510 panic("%s: abort, mbox %d, invalid cp_stat.\n", BN(j)(((struct hostdata *) &sh[j]->hostdata)->board_name
)
, i);
1511}
1512
1513int eata2x_old_abort(Scsi_Cmnd *SCarg) {
1514 int rtn;
1515 IRQ_FLAGSunsigned long irq_flags;
1516
1517 IRQ_LOCK_SAVEdo {__asm__ __volatile__("pushf ; pop %0" : "=r" (irq_flags):
:"memory"); __asm__ __volatile__ ("cli": : :"memory");} while
(0);
1518 rtn = do_old_abort(SCarg);
1519 IRQ_UNLOCK_RESTOREdo {__asm__ __volatile__("push %0 ; popf": :"g" (irq_flags):"memory"
);} while (0);
1520 return rtn;
1521}
1522
1523#if LINUX_VERSION_CODE131108 >= LinuxVersionCode(2,1,101)(((2)<<16)+((1)<<8)+(101))
1524
1525static inlineinline __attribute__((always_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((void *) 0)) {
1531 printk("%s: abort, target %d.%d:%d, pid %ld inactive.\n",
1532 BN(j)(((struct hostdata *) &sh[j]->hostdata)->board_name
)
, 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)(((struct hostdata *) &sh[j]->hostdata)->board_name
)
, 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)(((struct hostdata *) &sh[j]->hostdata)->board_name
)
);
1542
1543 if (wait_on_busy(sh[j]->io_port, MAXLOOP10000)) {
1544 printk("%s: abort, timeout error.\n", BN(j)(((struct hostdata *) &sh[j]->hostdata)->board_name
)
);
1545 return FAILED;
1546 }
1547
1548 if (HD(j)((struct hostdata *) &sh[j]->hostdata)->cp_stat[i] == FREE0) {
1549 printk("%s: abort, mbox %d is free.\n", BN(j)(((struct hostdata *) &sh[j]->hostdata)->board_name
)
, i);
1550 return SUCCESS;
1551 }
1552
1553 if (HD(j)((struct hostdata *) &sh[j]->hostdata)->cp_stat[i] == IN_USE1) {
1554 printk("%s: abort, mbox %d is in use.\n", BN(j)(((struct hostdata *) &sh[j]->hostdata)->board_name
)
, i);
1555
1556 if (SCarg != HD(j)((struct hostdata *) &sh[j]->hostdata)->cp[i].SCpnt)
1557 panic("%s: abort, mbox %d, SCarg %p, cp SCpnt %p.\n",
1558 BN(j)(((struct hostdata *) &sh[j]->hostdata)->board_name
)
, i, SCarg, HD(j)((struct hostdata *) &sh[j]->hostdata)->cp[i].SCpnt);
1559
1560 if (inb(sh[j]->io_port + REG_AUX_STATUS)((__builtin_constant_p((sh[j]->io_port + 8)) && (sh
[j]->io_port + 8) < 256) ? __inbc(sh[j]->io_port + 8
) : __inb(sh[j]->io_port + 8))
& IRQ_ASSERTED0x02)
1561 printk("%s: abort, mbox %d, interrupt pending.\n", BN(j)(((struct hostdata *) &sh[j]->hostdata)->board_name
)
, i);
1562
1563 if (SCarg->eh_state == SCSI_STATE_TIMEOUT) {
1564 SCarg->host_scribble = NULL((void *) 0);
1565 HD(j)((struct hostdata *) &sh[j]->hostdata)->cp_stat[i] = FREE0;
1566 printk("%s, abort, mbox %d, eh_state timeout, pid %ld.\n",
1567 BN(j)(((struct hostdata *) &sh[j]->hostdata)->board_name
)
, i, SCarg->pid);
1568 return SUCCESS;
1569 }
1570
1571 return FAILED;
1572 }
1573
1574 if (HD(j)((struct hostdata *) &sh[j]->hostdata)->cp_stat[i] == IN_RESET3) {
1575 printk("%s: abort, mbox %d is in reset.\n", BN(j)(((struct hostdata *) &sh[j]->hostdata)->board_name
)
, i);
1576 return FAILED;
1577 }
1578
1579 if (HD(j)((struct hostdata *) &sh[j]->hostdata)->cp_stat[i] == LOCKED2) {
1580 printk("%s: abort, mbox %d is locked.\n", BN(j)(((struct hostdata *) &sh[j]->hostdata)->board_name
)
, i);
1581 return SUCCESS;
1582 }
1583
1584 if (HD(j)((struct hostdata *) &sh[j]->hostdata)->cp_stat[i] == READY5 || HD(j)((struct hostdata *) &sh[j]->hostdata)->cp_stat[i] == ABORTING6) {
1585 SCarg->result = DID_ABORT0x05 << 16;
1586 SCarg->host_scribble = NULL((void *) 0);
1587 HD(j)((struct hostdata *) &sh[j]->hostdata)->cp_stat[i] = FREE0;
1588 printk("%s, abort, mbox %d ready, DID_ABORT, pid %ld done.\n",
1589 BN(j)(((struct hostdata *) &sh[j]->hostdata)->board_name
)
, 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)(((struct hostdata *) &sh[j]->hostdata)->board_name
)
, i);
1595}
1596
1597int eata2x_abort(Scsi_Cmnd *SCarg) {
1598
1599 return do_abort(SCarg);
1600}
1601
1602#endif /* new_eh_code */
1603
1604static inlineinline __attribute__((always_inline)) int do_old_reset(Scsi_Cmnd *SCarg) {
1605 unsigned int i, j, time, k, c, limit = 0;
1606 int arg_done = FALSE0;
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)(((struct hostdata *) &sh[j]->hostdata)->board_name
)
, SCarg->channel, SCarg->target, SCarg->lun, SCarg->pid);
1612
1613 if (SCarg->host_scribble == NULL((void *) 0))
1614 printk("%s: reset, pid %ld inactive.\n", BN(j)(((struct hostdata *) &sh[j]->hostdata)->board_name
)
, 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)(((struct hostdata *) &sh[j]->hostdata)->board_name
)
, SCarg->pid);
1619 return SCSI_RESET_NOT_RUNNING5;
1620 }
1621
1622 if (HD(j)((struct hostdata *) &sh[j]->hostdata)->in_reset) {
1623 printk("%s: reset, exit, already in reset.\n", BN(j)(((struct hostdata *) &sh[j]->hostdata)->board_name
)
);
1624 return SCSI_RESET_ERROR6;
1625 }
1626
1627 if (wait_on_busy(sh[j]->io_port, MAXLOOP10000)) {
1628 printk("%s: reset, exit, timeout error.\n", BN(j)(((struct hostdata *) &sh[j]->hostdata)->board_name
)
);
1629 return SCSI_RESET_ERROR6;
1630 }
1631
1632 HD(j)((struct hostdata *) &sh[j]->hostdata)->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)((struct hostdata *) &sh[j]->hostdata)->target_redo[k][c] = TRUE1;
1637 HD(j)((struct hostdata *) &sh[j]->hostdata)->target_to[k][c] = 0;
1638 }
1639
1640 for (i = 0; i < sh[j]->can_queue; i++) {
1641
1642 if (HD(j)((struct hostdata *) &sh[j]->hostdata)->cp_stat[i] == FREE0) continue;
1643
1644 if (HD(j)((struct hostdata *) &sh[j]->hostdata)->cp_stat[i] == LOCKED2) {
1645 HD(j)((struct hostdata *) &sh[j]->hostdata)->cp_stat[i] = FREE0;
1646 printk("%s: reset, locked mbox %d forced free.\n", BN(j)(((struct hostdata *) &sh[j]->hostdata)->board_name
)
, i);
1647 continue;
1648 }
1649
1650 if (!(SCpnt = HD(j)((struct hostdata *) &sh[j]->hostdata)->cp[i].SCpnt))
1651 panic("%s: reset, mbox %d, SCpnt == NULL.\n", BN(j)(((struct hostdata *) &sh[j]->hostdata)->board_name
)
, i);
1652
1653 if (HD(j)((struct hostdata *) &sh[j]->hostdata)->cp_stat[i] == READY5 || HD(j)((struct hostdata *) &sh[j]->hostdata)->cp_stat[i] == ABORTING6) {
1654 HD(j)((struct hostdata *) &sh[j]->hostdata)->cp_stat[i] = ABORTING6;
1655 printk("%s: reset, mbox %d aborting, pid %ld.\n",
1656 BN(j)(((struct hostdata *) &sh[j]->hostdata)->board_name
)
, i, SCpnt->pid);
1657 }
1658
1659 else {
1660 HD(j)((struct hostdata *) &sh[j]->hostdata)->cp_stat[i] = IN_RESET3;
1661 printk("%s: reset, mbox %d in reset, pid %ld.\n",
1662 BN(j)(((struct hostdata *) &sh[j]->hostdata)->board_name
)
, i, SCpnt->pid);
1663 }
1664
1665 if (SCpnt->host_scribble == NULL((void *) 0))
1666 panic("%s: reset, mbox %d, garbled SCpnt.\n", BN(j)(((struct hostdata *) &sh[j]->hostdata)->board_name
)
, i);
1667
1668 if (*(unsigned int *)SCpnt->host_scribble != i)
1669 panic("%s: reset, mbox %d, index mismatch.\n", BN(j)(((struct hostdata *) &sh[j]->hostdata)->board_name
)
, i);
1670
1671 if (SCpnt->scsi_done == NULL((void *) 0))
1672 panic("%s: reset, mbox %d, SCpnt->scsi_done == NULL.\n", BN(j)(((struct hostdata *) &sh[j]->hostdata)->board_name
)
, i);
1673
1674 if (SCpnt == SCarg) arg_done = TRUE1;
1675 }
1676
1677 if (do_dma(sh[j]->io_port, 0, RESET_PIO0xf9)) {
1678 printk("%s: reset, cannot reset, timeout error.\n", BN(j)(((struct hostdata *) &sh[j]->hostdata)->board_name
)
);
1679 return SCSI_RESET_ERROR6;
1680 }
1681
1682 printk("%s: reset, board reset done, enabling interrupts.\n", BN(j)(((struct hostdata *) &sh[j]->hostdata)->board_name
)
);
1683
1684#if defined(DEBUG_RESET)
1685 do_trace = TRUE1;
1686#endif
1687
1688 HD(j)((struct hostdata *) &sh[j]->hostdata)->in_reset = TRUE1;
1689 SPIN_UNLOCK
1690 IRQ_UNLOCK__asm__ __volatile__ ("sti": : :"memory");
1691 time = jiffies;
1692 while ((jiffies - time) < (10 * HZ100) && limit++ < 200000) udelay(100L)(__builtin_constant_p(100L) ? __const_udelay((100L) * 0x10c6ul
) : __udelay(100L))
;
1693 IRQ_LOCK__asm__ __volatile__ ("cli": : :"memory");
1694 SPIN_LOCK
1695 printk("%s: reset, interrupts disabled, loops %d.\n", BN(j)(((struct hostdata *) &sh[j]->hostdata)->board_name
)
, limit);
1696
1697 for (i = 0; i < sh[j]->can_queue; i++) {
1698
1699 if (HD(j)((struct hostdata *) &sh[j]->hostdata)->cp_stat[i] == IN_RESET3) {
1700 SCpnt = HD(j)((struct hostdata *) &sh[j]->hostdata)->cp[i].SCpnt;
1701 SCpnt->result = DID_RESET0x08 << 16;
1702 SCpnt->host_scribble = NULL((void *) 0);
1703
1704 /* This mailbox is still waiting for its interrupt */
1705 HD(j)((struct hostdata *) &sh[j]->hostdata)->cp_stat[i] = LOCKED2;
1706
1707 printk("%s, reset, mbox %d locked, DID_RESET, pid %ld done.\n",
1708 BN(j)(((struct hostdata *) &sh[j]->hostdata)->board_name
)
, i, SCpnt->pid);
1709 }
1710
1711 else if (HD(j)((struct hostdata *) &sh[j]->hostdata)->cp_stat[i] == ABORTING6) {
1712 SCpnt = HD(j)((struct hostdata *) &sh[j]->hostdata)->cp[i].SCpnt;
1713 SCpnt->result = DID_RESET0x08 << 16;
1714 SCpnt->host_scribble = NULL((void *) 0);
1715
1716 /* This mailbox was never queued to the adapter */
1717 HD(j)((struct hostdata *) &sh[j]->hostdata)->cp_stat[i] = FREE0;
1718
1719 printk("%s, reset, mbox %d aborting, DID_RESET, pid %ld done.\n",
1720 BN(j)(((struct hostdata *) &sh[j]->hostdata)->board_name
)
, 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__asm__ __volatile__ ("cli": : :"memory");
1730 }
1731
1732 HD(j)((struct hostdata *) &sh[j]->hostdata)->in_reset = FALSE0;
1733 do_trace = FALSE0;
1734
1735 if (arg_done) {
1736 printk("%s: reset, exit, success.\n", BN(j)(((struct hostdata *) &sh[j]->hostdata)->board_name
)
);
1737 return SCSI_RESET_SUCCESS2;
1738 }
1739 else {
1740 printk("%s: reset, exit, wakeup.\n", BN(j)(((struct hostdata *) &sh[j]->hostdata)->board_name
)
);
1741 return SCSI_RESET_PUNT1;
1742 }
1743}
1744
1745int eata2x_old_reset(Scsi_Cmnd *SCarg, unsigned int reset_flags) {
1746 int rtn;
1747 IRQ_FLAGSunsigned long irq_flags;
1748
1749 IRQ_LOCK_SAVEdo {__asm__ __volatile__("pushf ; pop %0" : "=r" (irq_flags):
:"memory"); __asm__ __volatile__ ("cli": : :"memory");} while
(0);
1750 rtn = do_old_reset(SCarg);
1751 IRQ_UNLOCK_RESTOREdo {__asm__ __volatile__("push %0 ; popf": :"g" (irq_flags):"memory"
);} while (0);
1752 return rtn;
1753}
1754
1755#if LINUX_VERSION_CODE131108 >= LinuxVersionCode(2,1,101)(((2)<<16)+((1)<<8)+(101))
1756
1757static inlineinline __attribute__((always_inline)) int do_reset(Scsi_Cmnd *SCarg) {
1758 unsigned int i, j, time, k, c, limit = 0;
1759 int arg_done = FALSE0;
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)(((struct hostdata *) &sh[j]->hostdata)->board_name
)
, SCarg->channel, SCarg->target, SCarg->lun, SCarg->pid);
1765
1766 if (SCarg->host_scribble == NULL((void *) 0))
1767 printk("%s: reset, pid %ld inactive.\n", BN(j)(((struct hostdata *) &sh[j]->hostdata)->board_name
)
, SCarg->pid);
1768
1769 if (HD(j)((struct hostdata *) &sh[j]->hostdata)->in_reset) {
1770 printk("%s: reset, exit, already in reset.\n", BN(j)(((struct hostdata *) &sh[j]->hostdata)->board_name
)
);
1771 return FAILED;
1772 }
1773
1774 if (wait_on_busy(sh[j]->io_port, MAXLOOP10000)) {
1775 printk("%s: reset, exit, timeout error.\n", BN(j)(((struct hostdata *) &sh[j]->hostdata)->board_name
)
);
1776 return FAILED;
1777 }
1778
1779 HD(j)((struct hostdata *) &sh[j]->hostdata)->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)((struct hostdata *) &sh[j]->hostdata)->target_redo[k][c] = TRUE1;
1784 HD(j)((struct hostdata *) &sh[j]->hostdata)->target_to[k][c] = 0;
1785 }
1786
1787 for (i = 0; i < sh[j]->can_queue; i++) {
1788
1789 if (HD(j)((struct hostdata *) &sh[j]->hostdata)->cp_stat[i] == FREE0) continue;
1790
1791 if (HD(j)((struct hostdata *) &sh[j]->hostdata)->cp_stat[i] == LOCKED2) {
1792 HD(j)((struct hostdata *) &sh[j]->hostdata)->cp_stat[i] = FREE0;
1793 printk("%s: reset, locked mbox %d forced free.\n", BN(j)(((struct hostdata *) &sh[j]->hostdata)->board_name
)
, i);
1794 continue;
1795 }
1796
1797 if (!(SCpnt = HD(j)((struct hostdata *) &sh[j]->hostdata)->cp[i].SCpnt))
1798 panic("%s: reset, mbox %d, SCpnt == NULL.\n", BN(j)(((struct hostdata *) &sh[j]->hostdata)->board_name
)
, i);
1799
1800 if (HD(j)((struct hostdata *) &sh[j]->hostdata)->cp_stat[i] == READY5 || HD(j)((struct hostdata *) &sh[j]->hostdata)->cp_stat[i] == ABORTING6) {
1801 HD(j)((struct hostdata *) &sh[j]->hostdata)->cp_stat[i] = ABORTING6;
1802 printk("%s: reset, mbox %d aborting, pid %ld.\n",
1803 BN(j)(((struct hostdata *) &sh[j]->hostdata)->board_name
)
, i, SCpnt->pid);
1804 }
1805
1806 else {
1807 HD(j)((struct hostdata *) &sh[j]->hostdata)->cp_stat[i] = IN_RESET3;
1808 printk("%s: reset, mbox %d in reset, pid %ld.\n",
1809 BN(j)(((struct hostdata *) &sh[j]->hostdata)->board_name
)
, i, SCpnt->pid);
1810 }
1811
1812 if (SCpnt->host_scribble == NULL((void *) 0))
1813 panic("%s: reset, mbox %d, garbled SCpnt.\n", BN(j)(((struct hostdata *) &sh[j]->hostdata)->board_name
)
, i);
1814
1815 if (*(unsigned int *)SCpnt->host_scribble != i)
1816 panic("%s: reset, mbox %d, index mismatch.\n", BN(j)(((struct hostdata *) &sh[j]->hostdata)->board_name
)
, i);
1817
1818 if (SCpnt->scsi_done == NULL((void *) 0))
1819 panic("%s: reset, mbox %d, SCpnt->scsi_done == NULL.\n", BN(j)(((struct hostdata *) &sh[j]->hostdata)->board_name
)
, i);
1820
1821 if (SCpnt == SCarg) arg_done = TRUE1;
1822 }
1823
1824 if (do_dma(sh[j]->io_port, 0, RESET_PIO0xf9)) {
1825 printk("%s: reset, cannot reset, timeout error.\n", BN(j)(((struct hostdata *) &sh[j]->hostdata)->board_name
)
);
1826 return FAILED;
1827 }
1828
1829 printk("%s: reset, board reset done, enabling interrupts.\n", BN(j)(((struct hostdata *) &sh[j]->hostdata)->board_name
)
);
1830
1831#if defined(DEBUG_RESET)
1832 do_trace = TRUE1;
1833#endif
1834
1835 HD(j)((struct hostdata *) &sh[j]->hostdata)->in_reset = TRUE1;
1836 SPIN_UNLOCK
1837 IRQ_UNLOCK__asm__ __volatile__ ("sti": : :"memory");
1838 time = jiffies;
1839 while ((jiffies - time) < (10 * HZ100) && limit++ < 200000) udelay(100L)(__builtin_constant_p(100L) ? __const_udelay((100L) * 0x10c6ul
) : __udelay(100L))
;
1840 IRQ_LOCK__asm__ __volatile__ ("cli": : :"memory");
1841 SPIN_LOCK
1842 printk("%s: reset, interrupts disabled, loops %d.\n", BN(j)(((struct hostdata *) &sh[j]->hostdata)->board_name
)
, limit);
1843
1844 for (i = 0; i < sh[j]->can_queue; i++) {
1845
1846 if (HD(j)((struct hostdata *) &sh[j]->hostdata)->cp_stat[i] == IN_RESET3) {
1847 SCpnt = HD(j)((struct hostdata *) &sh[j]->hostdata)->cp[i].SCpnt;
1848 SCpnt->result = DID_RESET0x08 << 16;
1849 SCpnt->host_scribble = NULL((void *) 0);
1850
1851 /* This mailbox is still waiting for its interrupt */
1852 HD(j)((struct hostdata *) &sh[j]->hostdata)->cp_stat[i] = LOCKED2;
1853
1854 printk("%s, reset, mbox %d locked, DID_RESET, pid %ld done.\n",
1855 BN(j)(((struct hostdata *) &sh[j]->hostdata)->board_name
)
, i, SCpnt->pid);
1856 }
1857
1858 else if (HD(j)((struct hostdata *) &sh[j]->hostdata)->cp_stat[i] == ABORTING6) {
1859 SCpnt = HD(j)((struct hostdata *) &sh[j]->hostdata)->cp[i].SCpnt;
1860 SCpnt->result = DID_RESET0x08 << 16;
1861 SCpnt->host_scribble = NULL((void *) 0);
1862
1863 /* This mailbox was never queued to the adapter */
1864 HD(j)((struct hostdata *) &sh[j]->hostdata)->cp_stat[i] = FREE0;
1865
1866 printk("%s, reset, mbox %d aborting, DID_RESET, pid %ld done.\n",
1867 BN(j)(((struct hostdata *) &sh[j]->hostdata)->board_name
)
, 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__asm__ __volatile__ ("cli": : :"memory");
1877 }
1878
1879 HD(j)((struct hostdata *) &sh[j]->hostdata)->in_reset = FALSE0;
1880 do_trace = FALSE0;
1881
1882 if (arg_done) printk("%s: reset, exit, pid %ld done.\n", BN(j)(((struct hostdata *) &sh[j]->hostdata)->board_name
)
, SCarg->pid);
1883 else printk("%s: reset, exit.\n", BN(j)(((struct hostdata *) &sh[j]->hostdata)->board_name
)
);
1884
1885 return SUCCESS;
1886}
1887
1888int eata2x_reset(Scsi_Cmnd *SCarg) {
1889
1890 return do_reset(SCarg);
1891}
1892
1893#endif /* new_eh_code */
1894
1895int 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 FALSE0;
1910}
1911
1912static 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
1937static inlineinline __attribute__((always_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 = FALSE0, s = TRUE1, r = TRUE1;
1943 unsigned int input_only = TRUE1, overlap = FALSE0;
1944 unsigned long sl[n_ready], pl[n_ready], ll[n_ready];
24
Declared variable-length array (VLA) has zero size
1945 unsigned long maxsec = 0, minsec = ULONG_MAX(~0UL), 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 FALSE0;
1961
1962 for (n = 0; n < n_ready; n++) {
1963 k = il[n]; cpp = &HD(j)((struct hostdata *) &sh[j]->hostdata)->cp[k]; SCpnt = cpp->SCpnt;
1964
1965 if (!cpp->din) input_only = FALSE0;
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 = FALSE0;
1976 if (sl[n] > sl[n - 1]) r = FALSE0;
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 = TRUE1;
1992
1993 if (ioseek > ((maxsec - minsec) / 2)) rev = FALSE0;
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)((struct hostdata *) &sh[j]->hostdata)->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 = TRUE1;
2005 }
2006
2007 if (overlap) sort(pl, il, n_ready, FALSE0);
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)((struct hostdata *) &sh[j]->hostdata)->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)((s) ? 'y' : 'n'), YESNO(r)((r) ? 'y' : 'n'), YESNO(rev)((rev) ? 'y' : 'n'), YESNO(input_only)((input_only) ? 'y' : 'n'),
2029 YESNO(overlap)((overlap) ? 'y' : 'n'), cpp->din);
2030 }
2031#endif
2032 return overlap;
2033}
2034
2035static 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_MAILBOXES64];
2040
2041 for (k = 0; k < sh[j]->can_queue; k++) {
21
Loop condition is false. Execution continues on line 2054
2042
2043 if (HD(j)((struct hostdata *) &sh[j]->hostdata)->cp_stat[k] != READY5 && HD(j)((struct hostdata *) &sh[j]->hostdata)->cp_stat[k] != IN_USE1) continue;
2044
2045 cpp = &HD(j)((struct hostdata *) &sh[j]->hostdata)->cp[k]; SCpnt = cpp->SCpnt;
2046
2047 if (SCpnt->device != dev) continue;
2048
2049 if (HD(j)((struct hostdata *) &sh[j]->hostdata)->cp_stat[k] == IN_USE1) return;
2050
2051 il[n_ready++] = k;
2052 }
2053
2054 if (reorder(j, cursec, ihdlr, il, n_ready)) n_ready = 1;
22
Passing the value 0 via 5th parameter 'n_ready'
23
Calling 'reorder'
2055
2056 for (n = 0; n < n_ready; n++) {
2057 k = il[n]; cpp = &HD(j)((struct hostdata *) &sh[j]->hostdata)->cp[k]; SCpnt = cpp->SCpnt;
2058
2059 if (do_dma(sh[j]->io_port, (unsigned int) cpp, SEND_CP_DMA0xff)) {
2060 printk("%s: %s, target %d.%d:%d, pid %ld, mbox %d, adapter"\
2061 " busy, will abort.\n", BN(j)(((struct hostdata *) &sh[j]->hostdata)->board_name
)
, (ihdlr ? "ihdlr" : "qcomm"),
2062 SCpnt->channel, SCpnt->target, SCpnt->lun, SCpnt->pid, k);
2063 HD(j)((struct hostdata *) &sh[j]->hostdata)->cp_stat[k] = ABORTING6;
2064 continue;
2065 }
2066
2067 HD(j)((struct hostdata *) &sh[j]->hostdata)->cp_stat[k] = IN_USE1;
2068 }
2069
2070}
2071
2072static inlineinline __attribute__((always_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)(((struct hostdata *) &sh[j]->hostdata)->board_name
)
, irq, sh[j]->irq);
2080
2081 /* Check if this board need to be serviced */
2082 if (!(inb(sh[j]->io_port + REG_AUX_STATUS)((__builtin_constant_p((sh[j]->io_port + 8)) && (sh
[j]->io_port + 8) < 256) ? __inbc(sh[j]->io_port + 8
) : __inb(sh[j]->io_port + 8))
& IRQ_ASSERTED0x02)) return;
2083
2084 HD(j)((struct hostdata *) &sh[j]->hostdata)->iocount++;
2085
2086 if (do_trace) printk("%s: ihdlr, enter, irq %d, count %d.\n", BN(j)(((struct hostdata *) &sh[j]->hostdata)->board_name
)
, irq,
2087 HD(j)((struct hostdata *) &sh[j]->hostdata)->iocount);
2088
2089 /* Check if this board is still busy */
2090 if (wait_on_busy(sh[j]->io_port, 20 * MAXLOOP10000)) {
2091 reg = inb(sh[j]->io_port + REG_STATUS)((__builtin_constant_p((sh[j]->io_port + 7)) && (sh
[j]->io_port + 7) < 256) ? __inbc(sh[j]->io_port + 7
) : __inb(sh[j]->io_port + 7))
;
2092 printk("%s: ihdlr, busy timeout error, irq %d, reg 0x%x, count %d.\n",
2093 BN(j)(((struct hostdata *) &sh[j]->hostdata)->board_name
)
, irq, reg, HD(j)((struct hostdata *) &sh[j]->hostdata)->iocount);
2094 return;
2095 }
2096
2097 dspp = &HD(j)((struct hostdata *) &sh[j]->hostdata)->sp[0];
2098 spp = &HD(j)((struct hostdata *) &sh[j]->hostdata)->sp[1];
2099
2100 /* Make a local copy just before clearing the interrupt indication */
2101 memcpy(spp, dspp, sizeof(struct mssp))(__builtin_constant_p(sizeof(struct mssp)) ? __constant_memcpy
((spp),(dspp),(sizeof(struct mssp))) : __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))(__builtin_constant_p(0) ? (__builtin_constant_p((sizeof(struct
mssp))) ? __constant_c_and_count_memset(((dspp)),((0x01010101UL
*(unsigned char)(0))),((sizeof(struct mssp)))) : __constant_c_memset
(((dspp)),((0x01010101UL*(unsigned char)(0))),((sizeof(struct
mssp))))) : (__builtin_constant_p((sizeof(struct mssp))) ? __memset_generic
((((dspp))),(((0))),(((sizeof(struct mssp))))) : __memset_generic
(((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)((__builtin_constant_p((sh[j]->io_port + 7)) && (sh
[j]->io_port + 7) < 256) ? __inbc(sh[j]->io_port + 7
) : __inb(sh[j]->io_port + 7))
;
2108
2109 /* Reject any sp with supspect data */
2110 if (spp->eoc == FALSE0)
2111 printk("%s: ihdlr, spp->eoc == FALSE, irq %d, reg 0x%x, count %d.\n",
2112 BN(j)(((struct hostdata *) &sh[j]->hostdata)->board_name
)
, irq, reg, HD(j)((struct hostdata *) &sh[j]->hostdata)->iocount);
2113 if (spp->cpp == NULL((void *) 0))
2114 printk("%s: ihdlr, spp->cpp == NULL, irq %d, reg 0x%x, count %d.\n",
2115 BN(j)(((struct hostdata *) &sh[j]->hostdata)->board_name
)
, irq, reg, HD(j)((struct hostdata *) &sh[j]->hostdata)->iocount);
2116 if (spp->eoc == FALSE0 || spp->cpp == NULL((void *) 0)) return;
2117
2118 cpp = spp->cpp;
2119
2120#if defined(DEBUG_GENERATE_ABORTS)
2121 if ((HD(j)((struct hostdata *) &sh[j]->hostdata)->iocount > 500) && ((HD(j)((struct hostdata *) &sh[j]->hostdata)->iocount % 500) < 3)) return;
2122#endif
2123
2124 /* Find the mailbox to be serviced on this board */
2125 i = cpp - HD(j)((struct hostdata *) &sh[j]->hostdata)->cp;
2126
2127 if (cpp < HD(j)((struct hostdata *) &sh[j]->hostdata)->cp || cpp >= HD(j)((struct hostdata *) &sh[j]->hostdata)->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)(((struct hostdata *) &sh[j]->hostdata)->board_name
)
,
2130 cpp, HD(j)((struct hostdata *) &sh[j]->hostdata)->cp);
2131
2132 if (HD(j)((struct hostdata *) &sh[j]->hostdata)->cp_stat[i] == IGNORE4) {
2133 HD(j)((struct hostdata *) &sh[j]->hostdata)->cp_stat[i] = FREE0;
2134 return;
2135 }
2136 else if (HD(j)((struct hostdata *) &sh[j]->hostdata)->cp_stat[i] == LOCKED2) {
2137 HD(j)((struct hostdata *) &sh[j]->hostdata)->cp_stat[i] = FREE0;
2138 printk("%s: ihdlr, mbox %d unlocked, count %d.\n", BN(j)(((struct hostdata *) &sh[j]->hostdata)->board_name
)
, i,
2139 HD(j)((struct hostdata *) &sh[j]->hostdata)->iocount);
2140 return;
2141 }
2142 else if (HD(j)((struct hostdata *) &sh[j]->hostdata)->cp_stat[i] == FREE0) {
2143 printk("%s: ihdlr, mbox %d is free, count %d.\n", BN(j)(((struct hostdata *) &sh[j]->hostdata)->board_name
)
, i,
2144 HD(j)((struct hostdata *) &sh[j]->hostdata)->iocount);
2145 return;
2146 }
2147 else if (HD(j)((struct hostdata *) &sh[j]->hostdata)->cp_stat[i] == IN_RESET3)
2148 printk("%s: ihdlr, mbox %d is in reset.\n", BN(j)(((struct hostdata *) &sh[j]->hostdata)->board_name
)
, i);
2149 else if (HD(j)((struct hostdata *) &sh[j]->hostdata)->cp_stat[i] != IN_USE1)
2150 panic("%s: ihdlr, mbox %d, invalid cp_stat: %d.\n",
2151 BN(j)(((struct hostdata *) &sh[j]->hostdata)->board_name
)
, i, HD(j)((struct hostdata *) &sh[j]->hostdata)->cp_stat[i]);
2152
2153 HD(j)((struct hostdata *) &sh[j]->hostdata)->cp_stat[i] = FREE0;
2154 SCpnt = cpp->SCpnt;
2155
2156 if (SCpnt == NULL((void *) 0)) panic("%s: ihdlr, mbox %d, SCpnt == NULL.\n", BN(j)(((struct hostdata *) &sh[j]->hostdata)->board_name
)
, i);
2157
2158 if (SCpnt->host_scribble == NULL((void *) 0))
2159 panic("%s: ihdlr, mbox %d, pid %ld, SCpnt %p garbled.\n", BN(j)(((struct hostdata *) &sh[j]->hostdata)->board_name
)
, 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)(((struct hostdata *) &sh[j]->hostdata)->board_name
)
, i, SCpnt->pid, *(unsigned int *)SCpnt->host_scribble);
2165
2166 if (linked_comm && SCpnt->device->queue_depth > 2
2167 && TLDEV(SCpnt->device->type)((SCpnt->device->type) == 0x00 || (SCpnt->device->
type) == 0x05)
)
2168 flush_dev(SCpnt->device, SCpnt->request.sector, j, TRUE1);
2169
2170 tstatus = status_byte(spp->target_status)(((spp->target_status) >> 1) & 0x1f);
2171
2172#if defined(DEBUG_GENERATE_ERRORS)
2173 if ((HD(j)((struct hostdata *) &sh[j]->hostdata)->iocount > 500) && ((HD(j)((struct hostdata *) &sh[j]->hostdata)->iocount % 200) < 2))
2174 spp->adapter_status = 0x01;
2175#endif
2176
2177 switch (spp->adapter_status) {
2178 case ASOK0x00: /* status OK */
2179
2180 /* Forces a reset if a disk drive keeps returning BUSY */
2181 if (tstatus == BUSY0x04 && SCpnt->device->type != TYPE_TAPE0x01)
2182 status = DID_ERROR0x07 << 16;
2183
2184 /* If there was a bus reset, redo operation on each target */
2185 else if (tstatus != GOOD0x00 && SCpnt->device->type == TYPE_DISK0x00
2186 && HD(j)((struct hostdata *) &sh[j]->hostdata)->target_redo[SCpnt->target][SCpnt->channel])
2187 status = DID_BUS_BUSY0x02 << 16;
2188
2189 /* Works around a flaw in scsi.c */
2190 else if (tstatus == CHECK_CONDITION0x01
2191 && SCpnt->device->type == TYPE_DISK0x00
2192 && (SCpnt->sense_buffer[2] & 0xf) == RECOVERED_ERROR0x01)
2193 status = DID_BUS_BUSY0x02 << 16;
2194
2195 else
2196 status = DID_OK0x00 << 16;
2197
2198 if (tstatus == GOOD0x00)
2199 HD(j)((struct hostdata *) &sh[j]->hostdata)->target_redo[SCpnt->target][SCpnt->channel] = FALSE0;
2200
2201 if (spp->target_status && SCpnt->device->type == TYPE_DISK0x00)
2202 printk("%s: ihdlr, target %d.%d:%d, pid %ld, "\
2203 "target_status 0x%x, sense key 0x%x.\n", BN(j)(((struct hostdata *) &sh[j]->hostdata)->board_name
)
,
2204 SCpnt->channel, SCpnt->target, SCpnt->lun,
2205 SCpnt->pid, spp->target_status,
2206 SCpnt->sense_buffer[2]);
2207
2208 HD(j)((struct hostdata *) &sh[j]->hostdata)->target_to[SCpnt->target][SCpnt->channel] = 0;
2209
2210 if (HD(j)((struct hostdata *) &sh[j]->hostdata)->last_retried_pid == SCpnt->pid) HD(j)((struct hostdata *) &sh[j]->hostdata)->retries = 0;
2211
2212 break;
2213 case ASST0x01: /* Selection Time Out */
2214 case 0x02: /* Command Time Out */
2215
2216 if (HD(j)((struct hostdata *) &sh[j]->hostdata)->target_to[SCpnt->target][SCpnt->channel] > 1)
2217 status = DID_ERROR0x07 << 16;
2218 else {
2219 status = DID_TIME_OUT0x03 << 16;
2220 HD(j)((struct hostdata *) &sh[j]->hostdata)->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)((struct hostdata *) &sh[j]->hostdata)->target_redo[k][c] = TRUE1;
2232
2233 if (SCpnt->device->type != TYPE_TAPE0x01
2234 && HD(j)((struct hostdata *) &sh[j]->hostdata)->retries < MAX_INTERNAL_RETRIES64) {
2235
2236#if defined(DID_SOFT_ERROR)
2237 status = DID_SOFT_ERROR << 16;
2238#else
2239 status = DID_BUS_BUSY0x02 << 16;
2240#endif
2241 HD(j)((struct hostdata *) &sh[j]->hostdata)->retries++;
2242 HD(j)((struct hostdata *) &sh[j]->hostdata)->last_retried_pid = SCpnt->pid;
2243 }
2244 else
2245 status = DID_ERROR0x07 << 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_ERROR0x07 << 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 != ASOK0x00 && HD(j)((struct hostdata *) &sh[j]->hostdata)->iocount > 1000) ||
2267 (spp->adapter_status != ASOK0x00 &&
2268 spp->adapter_status != ASST0x01 && HD(j)((struct hostdata *) &sh[j]->hostdata)->iocount <= 1000) ||
2269 do_trace || msg_byte(spp->target_status)(((spp->target_status) >> 8) & 0xff))
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)(((struct hostdata *) &sh[j]->hostdata)->board_name
)
, i, spp->adapter_status, spp->target_status,
2274 SCpnt->channel, SCpnt->target, SCpnt->lun, SCpnt->pid,
2275 reg, HD(j)((struct hostdata *) &sh[j]->hostdata)->iocount);
2276
2277 /* Set the command state to inactive */
2278 SCpnt->host_scribble = NULL((void *) 0);
2279
2280 SCpnt->scsi_done(SCpnt);
2281
2282 if (do_trace) printk("%s: ihdlr, exit, irq %d, count %d.\n", BN(j)(((struct hostdata *) &sh[j]->hostdata)->board_name
)
, irq,
2283 HD(j)((struct hostdata *) &sh[j]->hostdata)->iocount);
2284
2285 return;
2286}
2287
2288static void do_interrupt_handler(int irq, void *shap, struct pt_regs *regs) {
2289 unsigned int j;
2290 IRQ_FLAGSunsigned long 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_SAVEdo {__asm__ __volatile__("pushf ; pop %0" : "=r" (irq_flags):
:"memory"); __asm__ __volatile__ ("cli": : :"memory");} while
(0);
2298 ihdlr(irq, j);
2299 IRQ_UNLOCK_RESTOREdo {__asm__ __volatile__("push %0 ; popf": :"g" (irq_flags):"memory"
);} while (0);
2300 SPIN_UNLOCK_RESTORE
2301}
2302
2303int eata2x_release(struct Scsi_Host *shpnt) {
2304 unsigned int i, j;
2305 IRQ_FLAGSunsigned long irq_flags;
2306
2307 IRQ_LOCK_SAVEdo {__asm__ __volatile__("pushf ; pop %0" : "=r" (irq_flags):
:"memory"); __asm__ __volatile__ ("cli": : :"memory");} while
(0);
2308
2309 for (j = 0; sh[j] != NULL((void *) 0) && sh[j] != shpnt; j++);
2310
2311 if (sh[j] == NULL((void *) 0)) 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)((struct hostdata *) &sh[j]->hostdata)->cp[i])->sglist) kfreelinux_kfree((&HD(j)((struct hostdata *) &sh[j]->hostdata)->cp[i])->sglist);
2316
2317 free_irq(sh[j]->irq, &sha[j]);
2318
2319 if (sh[j]->dma_channel != NO_DMA0xff) 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_RESTOREdo {__asm__ __volatile__("push %0 ; popf": :"g" (irq_flags):"memory"
);} while (0);
2324 return FALSE0;
2325}
2326
2327#if defined(MODULE)
2328Scsi_Host_Template driver_template = EATA{ name: "EATA/DMA 2.0x rev. " "4.33.00" " ", detect: eata2x_detect
, release: eata2x_release, queuecommand: eata2x_queuecommand,
abort: eata2x_old_abort, reset: eata2x_old_reset, bios_param
: eata2x_biosparam, this_id: 7, unchecked_isa_dma: 1, use_clustering
: 1 }
;
2329
2330#include "scsi_module.c"
2331#endif