Diff markup
1 /* 1 /*
2 * eata.c - Low-level driver for EATA/DMA 2 * eata.c - Low-level driver for EATA/DMA SCSI host adapters.
3 * 3 *
4 * 03 Jun 2003 Rev. 8.10 for linux-2.5.70 4 * 03 Jun 2003 Rev. 8.10 for linux-2.5.70
5 * + Update for new IRQ API. 5 * + Update for new IRQ API.
6 * + Use "goto" when appropriate. 6 * + Use "goto" when appropriate.
7 * + Drop eata.h. 7 * + Drop eata.h.
8 * + Update for new module_param API. 8 * + Update for new module_param API.
9 * + Module parameters can now be spec 9 * + Module parameters can now be specified only in the
10 * same format as the kernel boot opt 10 * same format as the kernel boot options.
11 * 11 *
12 * boot option old module param 12 * boot option old module param
13 * ----------- ---------------- 13 * ----------- ------------------
14 * addr,... io_port=addr,... 14 * addr,... io_port=addr,...
15 * lc:[y|n] linked_comm=[1|0 15 * lc:[y|n] linked_comm=[1|0]
16 * mq:xx max_queue_depth= 16 * mq:xx max_queue_depth=xx
17 * tm:[0|1|2] tag_mode=[0|1|2] 17 * tm:[0|1|2] tag_mode=[0|1|2]
18 * et:[y|n] ext_tran=[1|0] 18 * et:[y|n] ext_tran=[1|0]
19 * rs:[y|n] rev_scan=[1|0] 19 * rs:[y|n] rev_scan=[1|0]
20 * ip:[y|n] isa_probe=[1|0] 20 * ip:[y|n] isa_probe=[1|0]
21 * ep:[y|n] eisa_probe=[1|0] 21 * ep:[y|n] eisa_probe=[1|0]
22 * pp:[y|n] pci_probe=[1|0] 22 * pp:[y|n] pci_probe=[1|0]
23 * 23 *
24 * A valid example using the new para 24 * A valid example using the new parameter format is:
25 * modprobe eata "eata=0x7410,0x230,l 25 * modprobe eata "eata=0x7410,0x230,lc:y,tm:0,mq:4,ep:n"
26 * 26 *
27 * which is equivalent to the old for 27 * which is equivalent to the old format:
28 * modprobe eata io_port=0x7410,0x230 28 * modprobe eata io_port=0x7410,0x230 linked_comm=1 tag_mode=0 \
29 * max_queue_depth=4 ei 29 * max_queue_depth=4 eisa_probe=0
30 * 30 *
31 * 12 Feb 2003 Rev. 8.04 for linux 2.5.60 31 * 12 Feb 2003 Rev. 8.04 for linux 2.5.60
32 * + Release irq before calling scsi_re 32 * + Release irq before calling scsi_register.
33 * 33 *
34 * 12 Nov 2002 Rev. 8.02 for linux 2.5.47 34 * 12 Nov 2002 Rev. 8.02 for linux 2.5.47
35 * + Release driver_lock before calling 35 * + Release driver_lock before calling scsi_register.
36 * 36 *
37 * 11 Nov 2002 Rev. 8.01 for linux 2.5.47 37 * 11 Nov 2002 Rev. 8.01 for linux 2.5.47
38 * + Fixed bios_param and scsicam_bios_ 38 * + Fixed bios_param and scsicam_bios_param calling parameters.
39 * 39 *
40 * 28 Oct 2002 Rev. 8.00 for linux 2.5.44 40 * 28 Oct 2002 Rev. 8.00 for linux 2.5.44-ac4
41 * + Use new tcq and adjust_queue_depth 41 * + Use new tcq and adjust_queue_depth api.
42 * + New command line option (tm:[0-2]) 42 * + New command line option (tm:[0-2]) to choose the type of tags:
43 * 0 -> disable tagging ; 1 -> simple 43 * 0 -> disable tagging ; 1 -> simple tags ; 2 -> ordered tags.
44 * Default is tm:0 (tagged commands d 44 * Default is tm:0 (tagged commands disabled).
45 * For compatibility the "tc:" option 45 * For compatibility the "tc:" option is an alias of the "tm:"
46 * option; tc:n is equivalent to tm:0 46 * option; tc:n is equivalent to tm:0 and tc:y is equivalent to
47 * tm:1. 47 * tm:1.
48 * + The tagged_comm module parameter h 48 * + The tagged_comm module parameter has been removed, use tag_mode
49 * instead, equivalent to the "tm:" b 49 * instead, equivalent to the "tm:" boot option.
50 * 50 *
51 * 10 Oct 2002 Rev. 7.70 for linux 2.5.42 51 * 10 Oct 2002 Rev. 7.70 for linux 2.5.42
52 * + Foreport from revision 6.70. 52 * + Foreport from revision 6.70.
53 * 53 *
54 * 25 Jun 2002 Rev. 6.70 for linux 2.4.19 54 * 25 Jun 2002 Rev. 6.70 for linux 2.4.19
55 * + This release is the first one test 55 * + This release is the first one tested on a Big Endian platform:
56 * fixed endian-ness problem due to b 56 * fixed endian-ness problem due to bitfields;
57 * fixed endian-ness problem in read_ 57 * fixed endian-ness problem in read_pio.
58 * + Added new options for selectively 58 * + Added new options for selectively probing ISA, EISA and PCI bus:
59 * 59 *
60 * Boot option Parameter name De 60 * Boot option Parameter name Default according to
61 * 61 *
62 * ip:[y|n] isa_probe=[1|0] CO 62 * ip:[y|n] isa_probe=[1|0] CONFIG_ISA defined
63 * ep:[y|n] eisa_probe=[1|0] CO 63 * ep:[y|n] eisa_probe=[1|0] CONFIG_EISA defined
64 * pp:[y|n] pci_probe=[1|0] CO 64 * pp:[y|n] pci_probe=[1|0] CONFIG_PCI defined
65 * 65 *
66 * The default action is to perform p 66 * The default action is to perform probing if the corrisponding
67 * bus is configured and to skip prob 67 * bus is configured and to skip probing otherwise.
68 * 68 *
69 * + If pci_probe is in effect and a li 69 * + If pci_probe is in effect and a list of I/O ports is specified
70 * as parameter or boot option, pci_e 70 * as parameter or boot option, pci_enable_device() is performed
71 * on all pci devices matching PCI_CL 71 * on all pci devices matching PCI_CLASS_STORAGE_SCSI.
72 * 72 *
73 * 21 Feb 2002 Rev. 6.52 for linux 2.4.18 73 * 21 Feb 2002 Rev. 6.52 for linux 2.4.18
74 * + Backport from rev. 7.22 (use io_re 74 * + Backport from rev. 7.22 (use io_request_lock).
75 * 75 *
76 * 20 Feb 2002 Rev. 7.22 for linux 2.5.5 76 * 20 Feb 2002 Rev. 7.22 for linux 2.5.5
77 * + Remove any reference to virt_to_bu 77 * + Remove any reference to virt_to_bus().
78 * + Fix pio hang while detecting multi 78 * + Fix pio hang while detecting multiple HBAs.
79 * + Fixed a board detection bug: in a 79 * + Fixed a board detection bug: in a system with
80 * multiple ISA/EISA boards, all but 80 * multiple ISA/EISA boards, all but the first one
81 * were erroneously detected as PCI. 81 * were erroneously detected as PCI.
82 * 82 *
83 * 01 Jan 2002 Rev. 7.20 for linux 2.5.1 83 * 01 Jan 2002 Rev. 7.20 for linux 2.5.1
84 * + Use the dynamic DMA mapping API. 84 * + Use the dynamic DMA mapping API.
85 * 85 *
86 * 19 Dec 2001 Rev. 7.02 for linux 2.5.1 86 * 19 Dec 2001 Rev. 7.02 for linux 2.5.1
87 * + Use SCpnt->sc_data_direction if se 87 * + Use SCpnt->sc_data_direction if set.
88 * + Use sglist.page instead of sglist. 88 * + Use sglist.page instead of sglist.address.
89 * 89 *
90 * 11 Dec 2001 Rev. 7.00 for linux 2.5.1 90 * 11 Dec 2001 Rev. 7.00 for linux 2.5.1
91 * + Use host->host_lock instead of io_ 91 * + Use host->host_lock instead of io_request_lock.
92 * 92 *
93 * 1 May 2001 Rev. 6.05 for linux 2.4.4 93 * 1 May 2001 Rev. 6.05 for linux 2.4.4
94 * + Clean up all pci related routines. 94 * + Clean up all pci related routines.
95 * + Fix data transfer direction for op 95 * + Fix data transfer direction for opcode SEND_CUE_SHEET (0x5d)
96 * 96 *
97 * 30 Jan 2001 Rev. 6.04 for linux 2.4.1 97 * 30 Jan 2001 Rev. 6.04 for linux 2.4.1
98 * + Call pci_resource_start after pci_ 98 * + Call pci_resource_start after pci_enable_device.
99 * 99 *
100 * 25 Jan 2001 Rev. 6.03 for linux 2.4.0 100 * 25 Jan 2001 Rev. 6.03 for linux 2.4.0
101 * + "check_region" call replaced by "r 101 * + "check_region" call replaced by "request_region".
102 * 102 *
103 * 22 Nov 2000 Rev. 6.02 for linux 2.4.0- 103 * 22 Nov 2000 Rev. 6.02 for linux 2.4.0-test11
104 * + Return code checked when calling p 104 * + Return code checked when calling pci_enable_device.
105 * + Removed old scsi error handling su 105 * + Removed old scsi error handling support.
106 * + The obsolete boot option flag eh:n 106 * + The obsolete boot option flag eh:n is silently ignored.
107 * + Removed error messages while a dis 107 * + Removed error messages while a disk drive is powered up at
108 * boot time. 108 * boot time.
109 * + Improved boot messages: all tagged 109 * + Improved boot messages: all tagged capable device are
110 * indicated as "tagged" or "soft-tag 110 * indicated as "tagged" or "soft-tagged" :
111 * - "soft-tagged" means that the dr 111 * - "soft-tagged" means that the driver is trying to do its
112 * own tagging (i.e. the tc:y optio 112 * own tagging (i.e. the tc:y option is in effect);
113 * - "tagged" means that the device s 113 * - "tagged" means that the device supports tagged commands,
114 * but the driver lets the HBA be r 114 * but the driver lets the HBA be responsible for tagging
115 * support. 115 * support.
116 * 116 *
117 * 16 Sep 1999 Rev. 5.11 for linux 2.2.12 117 * 16 Sep 1999 Rev. 5.11 for linux 2.2.12 and 2.3.18
118 * + Updated to the new __setup interfa 118 * + Updated to the new __setup interface for boot command line options.
119 * + When loaded as a module, accepts t 119 * + When loaded as a module, accepts the new parameter boot_options
120 * which value is a string with the s 120 * which value is a string with the same format of the kernel boot
121 * command line options. A valid exam 121 * command line options. A valid example is:
122 * modprobe eata 'boot_options="0x741 122 * modprobe eata 'boot_options="0x7410,0x230,lc:y,tc:n,mq:4"'
123 * 123 *
124 * 9 Sep 1999 Rev. 5.10 for linux 2.2.12 124 * 9 Sep 1999 Rev. 5.10 for linux 2.2.12 and 2.3.17
125 * + 64bit cleanup for Linux/Alpha plat 125 * + 64bit cleanup for Linux/Alpha platform support
126 * (contribution from H.J. Lu). 126 * (contribution from H.J. Lu).
127 * 127 *
128 * 22 Jul 1999 Rev. 5.00 for linux 2.2.10 128 * 22 Jul 1999 Rev. 5.00 for linux 2.2.10 and 2.3.11
129 * + Removed pre-2.2 source code compat 129 * + Removed pre-2.2 source code compatibility.
130 * + Added call to pci_set_master. 130 * + Added call to pci_set_master.
131 * 131 *
132 * 26 Jul 1998 Rev. 4.33 for linux 2.0.35 132 * 26 Jul 1998 Rev. 4.33 for linux 2.0.35 and 2.1.111
133 * + Added command line option (rs:[y|n 133 * + Added command line option (rs:[y|n]) to reverse the scan order
134 * of PCI boards. The default is rs:y 134 * of PCI boards. The default is rs:y, which reverses the BIOS order
135 * while registering PCI boards. The 135 * while registering PCI boards. The default value rs:y generates
136 * the same order of all previous rev 136 * the same order of all previous revisions of this driver.
137 * Pls. note that "BIOS order" might 137 * Pls. note that "BIOS order" might have been reversed itself
138 * after the 2.1.9x PCI modifications 138 * after the 2.1.9x PCI modifications in the linux kernel.
139 * The rs value is ignored when the e 139 * The rs value is ignored when the explicit list of addresses
140 * is used by the "eata=port0,port1,. 140 * is used by the "eata=port0,port1,..." command line option.
141 * + Added command line option (et:[y|n 141 * + Added command line option (et:[y|n]) to force use of extended
142 * translation (255 heads, 63 sectors 142 * translation (255 heads, 63 sectors) as disk geometry.
143 * The default is et:n, which uses th 143 * The default is et:n, which uses the disk geometry returned
144 * by scsicam_bios_param. The default 144 * by scsicam_bios_param. The default value et:n is compatible with
145 * all previous revisions of this dri 145 * all previous revisions of this driver.
146 * 146 *
147 * 28 May 1998 Rev. 4.32 for linux 2.0.33 147 * 28 May 1998 Rev. 4.32 for linux 2.0.33 and 2.1.104
148 * Increased busy timeout from 10 mse 148 * Increased busy timeout from 10 msec. to 200 msec. while
149 * processing interrupts. 149 * processing interrupts.
150 * 150 *
151 * 16 May 1998 Rev. 4.31 for linux 2.0.33 151 * 16 May 1998 Rev. 4.31 for linux 2.0.33 and 2.1.102
152 * Improved abort handling during the 152 * Improved abort handling during the eh recovery process.
153 * 153 *
154 * 13 May 1998 Rev. 4.30 for linux 2.0.33 154 * 13 May 1998 Rev. 4.30 for linux 2.0.33 and 2.1.101
155 * The driver is now fully SMP safe, 155 * The driver is now fully SMP safe, including the
156 * abort and reset routines. 156 * abort and reset routines.
157 * Added command line options (eh:[y| 157 * Added command line options (eh:[y|n]) to choose between
158 * new_eh_code and the old scsi code. 158 * new_eh_code and the old scsi code.
159 * If linux version >= 2.1.101 the de 159 * If linux version >= 2.1.101 the default is eh:y, while the eh
160 * option is ignored for previous rel 160 * option is ignored for previous releases and the old scsi code
161 * is used. 161 * is used.
162 * 162 *
163 * 18 Apr 1998 Rev. 4.20 for linux 2.0.33 163 * 18 Apr 1998 Rev. 4.20 for linux 2.0.33 and 2.1.97
164 * Reworked interrupt handler. 164 * Reworked interrupt handler.
165 * 165 *
166 * 11 Apr 1998 rev. 4.05 for linux 2.0.33 166 * 11 Apr 1998 rev. 4.05 for linux 2.0.33 and 2.1.95
167 * Major reliability improvement: whe 167 * Major reliability improvement: when a batch with overlapping
168 * requests is detected, requests are 168 * requests is detected, requests are queued one at a time
169 * eliminating any possible board or 169 * eliminating any possible board or drive reordering.
170 * 170 *
171 * 10 Apr 1998 rev. 4.04 for linux 2.0.33 171 * 10 Apr 1998 rev. 4.04 for linux 2.0.33 and 2.1.95
172 * Improved SMP support (if linux ver 172 * Improved SMP support (if linux version >= 2.1.95).
173 * 173 *
174 * 9 Apr 1998 rev. 4.03 for linux 2.0.33 174 * 9 Apr 1998 rev. 4.03 for linux 2.0.33 and 2.1.94
175 * Added support for new PCI code and 175 * Added support for new PCI code and IO-APIC remapping of irqs.
176 * Performance improvement: when sequ 176 * Performance improvement: when sequential i/o is detected,
177 * always use direct sort instead of 177 * always use direct sort instead of reverse sort.
178 * 178 *
179 * 4 Apr 1998 rev. 4.02 for linux 2.0.33 179 * 4 Apr 1998 rev. 4.02 for linux 2.0.33 and 2.1.92
180 * io_port is now unsigned long. 180 * io_port is now unsigned long.
181 * 181 *
182 * 17 Mar 1998 rev. 4.01 for linux 2.0.33 182 * 17 Mar 1998 rev. 4.01 for linux 2.0.33 and 2.1.88
183 * Use new scsi error handling code ( 183 * Use new scsi error handling code (if linux version >= 2.1.88).
184 * Use new interrupt code. 184 * Use new interrupt code.
185 * 185 *
186 * 12 Sep 1997 rev. 3.11 for linux 2.0.30 186 * 12 Sep 1997 rev. 3.11 for linux 2.0.30 and 2.1.55
187 * Use of udelay inside the wait loop 187 * Use of udelay inside the wait loops to avoid timeout
188 * problems with fast cpus. 188 * problems with fast cpus.
189 * Removed check about useless calls 189 * Removed check about useless calls to the interrupt service
190 * routine (reported on SMP systems o 190 * routine (reported on SMP systems only).
191 * At initialization time "sorted/uns 191 * At initialization time "sorted/unsorted" is displayed instead
192 * of "linked/unlinked" to reinforce 192 * of "linked/unlinked" to reinforce the fact that "linking" is
193 * nothing but "elevator sorting" in 193 * nothing but "elevator sorting" in the actual implementation.
194 * 194 *
195 * 17 May 1997 rev. 3.10 for linux 2.0.30 195 * 17 May 1997 rev. 3.10 for linux 2.0.30 and 2.1.38
196 * Use of serial_number_at_timeout in 196 * Use of serial_number_at_timeout in abort and reset processing.
197 * Use of the __initfunc and __initda 197 * Use of the __initfunc and __initdata macro in setup code.
198 * Minor cleanups in the list_statist 198 * Minor cleanups in the list_statistics code.
199 * Increased controller busy timeout 199 * Increased controller busy timeout in order to better support
200 * slow SCSI devices. 200 * slow SCSI devices.
201 * 201 *
202 * 24 Feb 1997 rev. 3.00 for linux 2.0.29 202 * 24 Feb 1997 rev. 3.00 for linux 2.0.29 and 2.1.26
203 * When loading as a module, paramete 203 * When loading as a module, parameter passing is now supported
204 * both in 2.0 and in 2.1 style. 204 * both in 2.0 and in 2.1 style.
205 * Fixed data transfer direction for 205 * Fixed data transfer direction for some SCSI opcodes.
206 * Immediate acknowledge to request s 206 * Immediate acknowledge to request sense commands.
207 * Linked commands to each disk devic 207 * Linked commands to each disk device are now reordered by elevator
208 * sorting. Rare cases in which reord 208 * sorting. Rare cases in which reordering of write requests could
209 * cause wrong results are managed. 209 * cause wrong results are managed.
210 * Fixed spurious timeouts caused by 210 * Fixed spurious timeouts caused by long simple queue tag sequences.
211 * New command line option (tm:[0-3]) 211 * New command line option (tm:[0-3]) to choose the type of tags:
212 * 0 -> mixed (default); 1 -> simple; 212 * 0 -> mixed (default); 1 -> simple; 2 -> head; 3 -> ordered.
213 * 213 *
214 * 18 Jan 1997 rev. 2.60 for linux 2.1.21 214 * 18 Jan 1997 rev. 2.60 for linux 2.1.21 and 2.0.28
215 * Added command line options to enab 215 * Added command line options to enable/disable linked commands
216 * (lc:[y|n]), tagged commands (tc:[y 216 * (lc:[y|n]), tagged commands (tc:[y|n]) and to set the max queue
217 * depth (mq:xx). Default is "eata=lc 217 * depth (mq:xx). Default is "eata=lc:n,tc:n,mq:16".
218 * Improved command linking. 218 * Improved command linking.
219 * Documented how to setup RAID-0 wit 219 * Documented how to setup RAID-0 with DPT SmartRAID boards.
220 * 220 *
221 * 8 Jan 1997 rev. 2.50 for linux 2.1.20 221 * 8 Jan 1997 rev. 2.50 for linux 2.1.20 and 2.0.27
222 * Added linked command support. 222 * Added linked command support.
223 * Improved detection of PCI boards u 223 * Improved detection of PCI boards using ISA base addresses.
224 * 224 *
225 * 3 Dec 1996 rev. 2.40 for linux 2.1.14 225 * 3 Dec 1996 rev. 2.40 for linux 2.1.14 and 2.0.27
226 * Added support for tagged commands 226 * Added support for tagged commands and queue depth adjustment.
227 * 227 *
228 * 22 Nov 1996 rev. 2.30 for linux 2.1.12 228 * 22 Nov 1996 rev. 2.30 for linux 2.1.12 and 2.0.26
229 * When CONFIG_PCI is defined, BIOS32 229 * When CONFIG_PCI is defined, BIOS32 is used to include in the
230 * list of i/o ports to be probed all 230 * list of i/o ports to be probed all the PCI SCSI controllers.
231 * The list of i/o ports to be probed 231 * The list of i/o ports to be probed can be overwritten by the
232 * "eata=port0,port1,...." boot comma 232 * "eata=port0,port1,...." boot command line option.
233 * Scatter/gather lists are now alloc 233 * Scatter/gather lists are now allocated by a number of kmalloc
234 * calls, in order to avoid the previ 234 * calls, in order to avoid the previous size limit of 64Kb.
235 * 235 *
236 * 16 Nov 1996 rev. 2.20 for linux 2.1.10 236 * 16 Nov 1996 rev. 2.20 for linux 2.1.10 and 2.0.25
237 * Added support for EATA 2.0C, PCI, 237 * Added support for EATA 2.0C, PCI, multichannel and wide SCSI.
238 * 238 *
239 * 27 Sep 1996 rev. 2.12 for linux 2.1.0 239 * 27 Sep 1996 rev. 2.12 for linux 2.1.0
240 * Portability cleanups (virtual/bus 240 * Portability cleanups (virtual/bus addressing, little/big endian
241 * support). 241 * support).
242 * 242 *
243 * 09 Jul 1996 rev. 2.11 for linux 2.0.4 243 * 09 Jul 1996 rev. 2.11 for linux 2.0.4
244 * Number of internal retries is now 244 * Number of internal retries is now limited.
245 * 245 *
246 * 16 Apr 1996 rev. 2.10 for linux 1.3.90 246 * 16 Apr 1996 rev. 2.10 for linux 1.3.90
247 * New argument "reset_flags" to the 247 * New argument "reset_flags" to the reset routine.
248 * 248 *
249 * 6 Jul 1995 rev. 2.01 for linux 1.3.7 249 * 6 Jul 1995 rev. 2.01 for linux 1.3.7
250 * Update required by the new /proc/s 250 * Update required by the new /proc/scsi support.
251 * 251 *
252 * 11 Mar 1995 rev. 2.00 for linux 1.2.0 252 * 11 Mar 1995 rev. 2.00 for linux 1.2.0
253 * Fixed a bug which prevented media 253 * Fixed a bug which prevented media change detection for removable
254 * disk drives. 254 * disk drives.
255 * 255 *
256 * 23 Feb 1995 rev. 1.18 for linux 1.1.94 256 * 23 Feb 1995 rev. 1.18 for linux 1.1.94
257 * Added a check for scsi_register re 257 * Added a check for scsi_register returning NULL.
258 * 258 *
259 * 11 Feb 1995 rev. 1.17 for linux 1.1.91 259 * 11 Feb 1995 rev. 1.17 for linux 1.1.91
260 * Now DEBUG_RESET is disabled by def 260 * Now DEBUG_RESET is disabled by default.
261 * Register a board even if it does n 261 * Register a board even if it does not assert DMA protocol support
262 * (DPT SK2011B does not report corre 262 * (DPT SK2011B does not report correctly the dmasup bit).
263 * 263 *
264 * 9 Feb 1995 rev. 1.16 for linux 1.1.90 264 * 9 Feb 1995 rev. 1.16 for linux 1.1.90
265 * Use host->wish_block instead of ho 265 * Use host->wish_block instead of host->block.
266 * New list of Data Out SCSI commands 266 * New list of Data Out SCSI commands.
267 * 267 *
268 * 8 Feb 1995 rev. 1.15 for linux 1.1.89 268 * 8 Feb 1995 rev. 1.15 for linux 1.1.89
269 * Cleared target_time_out counter wh 269 * Cleared target_time_out counter while performing a reset.
270 * All external symbols renamed to av 270 * All external symbols renamed to avoid possible name conflicts.
271 * 271 *
272 * 28 Jan 1995 rev. 1.14 for linux 1.1.86 272 * 28 Jan 1995 rev. 1.14 for linux 1.1.86
273 * Added module support. 273 * Added module support.
274 * Log and do a retry when a disk dri 274 * Log and do a retry when a disk drive returns a target status
275 * different from zero on a recovered 275 * different from zero on a recovered error.
276 * 276 *
277 * 24 Jan 1995 rev. 1.13 for linux 1.1.85 277 * 24 Jan 1995 rev. 1.13 for linux 1.1.85
278 * Use optimized board configuration, 278 * Use optimized board configuration, with a measured performance
279 * increase in the range 10%-20% on i 279 * increase in the range 10%-20% on i/o throughput.
280 * 280 *
281 * 16 Jan 1995 rev. 1.12 for linux 1.1.81 281 * 16 Jan 1995 rev. 1.12 for linux 1.1.81
282 * Fix mscp structure comments (no fu 282 * Fix mscp structure comments (no functional change).
283 * Display a message if check_region 283 * Display a message if check_region detects a port address
284 * already in use. 284 * already in use.
285 * 285 *
286 * 17 Dec 1994 rev. 1.11 for linux 1.1.74 286 * 17 Dec 1994 rev. 1.11 for linux 1.1.74
287 * Use the scsicam_bios_param routine 287 * Use the scsicam_bios_param routine. This allows an easy
288 * migration path from disk partition 288 * migration path from disk partition tables created using
289 * different SCSI drivers and non opt 289 * different SCSI drivers and non optimal disk geometry.
290 * 290 *
291 * 15 Dec 1994 rev. 1.10 for linux 1.1.74 291 * 15 Dec 1994 rev. 1.10 for linux 1.1.74
292 * Added support for ISA EATA boards 292 * Added support for ISA EATA boards (DPT PM2011, DPT PM2021).
293 * The host->block flag is set for al 293 * The host->block flag is set for all the detected ISA boards.
294 * The detect routine no longer enfor 294 * The detect routine no longer enforces LEVEL triggering
295 * for EISA boards, it just prints a 295 * for EISA boards, it just prints a warning message.
296 * 296 *
297 * 30 Nov 1994 rev. 1.09 for linux 1.1.68 297 * 30 Nov 1994 rev. 1.09 for linux 1.1.68
298 * Redo i/o on target status CHECK_CO 298 * Redo i/o on target status CHECK_CONDITION for TYPE_DISK only.
299 * Added optional support for using a 299 * Added optional support for using a single board at a time.
300 * 300 *
301 * 18 Nov 1994 rev. 1.08 for linux 1.1.64 301 * 18 Nov 1994 rev. 1.08 for linux 1.1.64
302 * Forces sg_tablesize = 64 and can_q 302 * Forces sg_tablesize = 64 and can_queue = 64 if these
303 * values are not correctly detected 303 * values are not correctly detected (DPT PM2012).
304 * 304 *
305 * 14 Nov 1994 rev. 1.07 for linux 1.1.63 305 * 14 Nov 1994 rev. 1.07 for linux 1.1.63 Final BETA release.
306 * 04 Aug 1994 rev. 1.00 for linux 1.1.39 306 * 04 Aug 1994 rev. 1.00 for linux 1.1.39 First BETA release.
307 * 307 *
308 * 308 *
309 * This driver is based on the CAM (C 309 * This driver is based on the CAM (Common Access Method Committee)
310 * EATA (Enhanced AT Bus Attachment) 310 * EATA (Enhanced AT Bus Attachment) rev. 2.0A, using DMA protocol.
311 * 311 *
312 * Copyright (C) 1994-2003 Dario Ballabio (ba 312 * Copyright (C) 1994-2003 Dario Ballabio (ballabio_dario@emc.com)
313 * 313 *
314 * Alternate email: dario.ballabio@inwind.it, 314 * Alternate email: dario.ballabio@inwind.it, dario.ballabio@tiscalinet.it
315 * 315 *
316 * Redistribution and use in source and binar 316 * Redistribution and use in source and binary forms, with or without
317 * modification, are permitted provided that 317 * modification, are permitted provided that redistributions of source
318 * code retain the above copyright notice and 318 * code retain the above copyright notice and this comment without
319 * modification. 319 * modification.
320 * 320 *
321 */ 321 */
322 322
323 /* 323 /*
324 * 324 *
325 * Here is a brief description of the DPT SCS 325 * Here is a brief description of the DPT SCSI host adapters.
326 * All these boards provide an EATA/DMA compa 326 * All these boards provide an EATA/DMA compatible programming interface
327 * and are fully supported by this driver in 327 * and are fully supported by this driver in any configuration, including
328 * multiple SCSI channels: 328 * multiple SCSI channels:
329 * 329 *
330 * PM2011B/9X - Entry Level ISA 330 * PM2011B/9X - Entry Level ISA
331 * PM2021A/9X - High Performance ISA 331 * PM2021A/9X - High Performance ISA
332 * PM2012A Old EISA 332 * PM2012A Old EISA
333 * PM2012B Old EISA 333 * PM2012B Old EISA
334 * PM2022A/9X - Entry Level EISA 334 * PM2022A/9X - Entry Level EISA
335 * PM2122A/9X - High Performance EISA 335 * PM2122A/9X - High Performance EISA
336 * PM2322A/9X - Extra High Performance EISA 336 * PM2322A/9X - Extra High Performance EISA
337 * PM3021 - SmartRAID Adapter for ISA 337 * PM3021 - SmartRAID Adapter for ISA
338 * PM3222 - SmartRAID Adapter for EISA ( 338 * PM3222 - SmartRAID Adapter for EISA (PM3222W is 16-bit wide SCSI)
339 * PM3224 - SmartRAID Adapter for PCI ( 339 * PM3224 - SmartRAID Adapter for PCI (PM3224W is 16-bit wide SCSI)
340 * PM33340UW - SmartRAID Adapter for PCI u 340 * PM33340UW - SmartRAID Adapter for PCI ultra wide multichannel
341 * 341 *
342 * The above list is just an indication: as a 342 * The above list is just an indication: as a matter of fact all DPT
343 * boards using the EATA/DMA protocol are sup 343 * boards using the EATA/DMA protocol are supported by this driver,
344 * since they use exactely the same programmi 344 * since they use exactely the same programming interface.
345 * 345 *
346 * The DPT PM2001 provides only the EATA/PIO 346 * The DPT PM2001 provides only the EATA/PIO interface and hence is not
347 * supported by this driver. 347 * supported by this driver.
348 * 348 *
349 * This code has been tested with up to 3 Dis 349 * This code has been tested with up to 3 Distributed Processing Technology
350 * PM2122A/9X (DPT SCSI BIOS v002.D1, firmwar 350 * PM2122A/9X (DPT SCSI BIOS v002.D1, firmware v05E.0) EISA controllers,
351 * in any combination of private and shared I 351 * in any combination of private and shared IRQ.
352 * PCI support has been tested using up to 2 352 * PCI support has been tested using up to 2 DPT PM3224W (DPT SCSI BIOS
353 * v003.D0, firmware v07G.0). 353 * v003.D0, firmware v07G.0).
354 * 354 *
355 * DPT SmartRAID boards support "Hardware Arr 355 * DPT SmartRAID boards support "Hardware Array" - a group of disk drives
356 * which are all members of the same RAID-0, 356 * which are all members of the same RAID-0, RAID-1 or RAID-5 array implemented
357 * in host adapter hardware. Hardware Arrays 357 * in host adapter hardware. Hardware Arrays are fully compatible with this
358 * driver, since they look to it as a single 358 * driver, since they look to it as a single disk drive.
359 * 359 *
360 * WARNING: to create a RAID-0 "Hardware Arra 360 * WARNING: to create a RAID-0 "Hardware Array" you must select "Other Unix"
361 * as the current OS in the DPTMGR "Initial S 361 * as the current OS in the DPTMGR "Initial System Installation" menu.
362 * Otherwise RAID-0 is generated as an "Array 362 * Otherwise RAID-0 is generated as an "Array Group" (i.e. software RAID-0),
363 * which is not supported by the actual SCSI 363 * which is not supported by the actual SCSI subsystem.
364 * To get the "Array Group" functionality, th 364 * To get the "Array Group" functionality, the Linux MD driver must be used
365 * instead of the DPT "Array Group" feature. 365 * instead of the DPT "Array Group" feature.
366 * 366 *
367 * Multiple ISA, EISA and PCI boards can be c 367 * Multiple ISA, EISA and PCI boards can be configured in the same system.
368 * It is suggested to put all the EISA boards 368 * It is suggested to put all the EISA boards on the same IRQ level, all
369 * the PCI boards on another IRQ level, whil 369 * the PCI boards on another IRQ level, while ISA boards cannot share
370 * interrupts. 370 * interrupts.
371 * 371 *
372 * If you configure multiple boards on the sa 372 * If you configure multiple boards on the same IRQ, the interrupt must
373 * be _level_ triggered (not _edge_ triggered 373 * be _level_ triggered (not _edge_ triggered).
374 * 374 *
375 * This driver detects EATA boards by probes 375 * This driver detects EATA boards by probes at fixed port addresses,
376 * so no BIOS32 or PCI BIOS support is requir 376 * so no BIOS32 or PCI BIOS support is required.
377 * The suggested way to detect a generic EATA 377 * The suggested way to detect a generic EATA PCI board is to force on it
378 * any unused EISA address, even if there are 378 * any unused EISA address, even if there are other controllers on the EISA
379 * bus, or even if you system has no EISA bus 379 * bus, or even if you system has no EISA bus at all.
380 * Do not force any ISA address on EATA PCI b 380 * Do not force any ISA address on EATA PCI boards.
381 * 381 *
382 * If PCI bios support is configured into the 382 * If PCI bios support is configured into the kernel, BIOS32 is used to
383 * include in the list of i/o ports to be pro 383 * include in the list of i/o ports to be probed all the PCI SCSI controllers.
384 * 384 *
385 * Due to a DPT BIOS "feature", it might not 385 * Due to a DPT BIOS "feature", it might not be possible to force an EISA
386 * address on more than a single DPT PCI boar 386 * address on more than a single DPT PCI board, so in this case you have to
387 * let the PCI BIOS assign the addresses. 387 * let the PCI BIOS assign the addresses.
388 * 388 *
389 * The sequence of detection probes is: 389 * The sequence of detection probes is:
390 * 390 *
391 * - ISA 0x1F0; 391 * - ISA 0x1F0;
392 * - PCI SCSI controllers (only if BIOS32 is 392 * - PCI SCSI controllers (only if BIOS32 is available);
393 * - EISA/PCI 0x1C88 through 0xFC88 (correspo 393 * - EISA/PCI 0x1C88 through 0xFC88 (corresponding to EISA slots 1 to 15);
394 * - ISA 0x170, 0x230, 0x330. 394 * - ISA 0x170, 0x230, 0x330.
395 * 395 *
396 * The above list of detection probes can be 396 * The above list of detection probes can be totally replaced by the
397 * boot command line option: "eata=port0,port 397 * boot command line option: "eata=port0,port1,port2,...", where the
398 * port0, port1... arguments are ISA/EISA/PCI 398 * port0, port1... arguments are ISA/EISA/PCI addresses to be probed.
399 * For example using "eata=0x7410,0x7450,0x23 399 * For example using "eata=0x7410,0x7450,0x230", the driver probes
400 * only the two PCI addresses 0x7410 and 0x74 400 * only the two PCI addresses 0x7410 and 0x7450 and the ISA address 0x230,
401 * in this order; "eata=0" totally disables t 401 * in this order; "eata=0" totally disables this driver.
402 * 402 *
403 * After the optional list of detection probe 403 * After the optional list of detection probes, other possible command line
404 * options are: 404 * options are:
405 * 405 *
406 * et:y force use of extended translation (2 406 * et:y force use of extended translation (255 heads, 63 sectors);
407 * et:n use disk geometry detected by scsica 407 * et:n use disk geometry detected by scsicam_bios_param;
408 * rs:y reverse scan order while detecting P 408 * rs:y reverse scan order while detecting PCI boards;
409 * rs:n use BIOS order while detecting PCI b 409 * rs:n use BIOS order while detecting PCI boards;
410 * lc:y enables linked commands; 410 * lc:y enables linked commands;
411 * lc:n disables linked commands; 411 * lc:n disables linked commands;
412 * tm:0 disables tagged commands (same as tc 412 * tm:0 disables tagged commands (same as tc:n);
413 * tm:1 use simple queue tags (same as tc:y) 413 * tm:1 use simple queue tags (same as tc:y);
414 * tm:2 use ordered queue tags (same as tc:2 414 * tm:2 use ordered queue tags (same as tc:2);
415 * mq:xx set the max queue depth to the value 415 * mq:xx set the max queue depth to the value xx (2 <= xx <= 32).
416 * 416 *
417 * The default value is: "eata=lc:n,mq:16,tm: 417 * The default value is: "eata=lc:n,mq:16,tm:0,et:n,rs:n".
418 * An example using the list of detection pro 418 * An example using the list of detection probes could be:
419 * "eata=0x7410,0x230,lc:y,tm:2,mq:4,et:n". 419 * "eata=0x7410,0x230,lc:y,tm:2,mq:4,et:n".
420 * 420 *
421 * When loading as a module, parameters can b 421 * When loading as a module, parameters can be specified as well.
422 * The above example would be (use 1 in place 422 * The above example would be (use 1 in place of y and 0 in place of n):
423 * 423 *
424 * modprobe eata io_port=0x7410,0x230 linked_ 424 * modprobe eata io_port=0x7410,0x230 linked_comm=1 \
425 * max_queue_depth=4 ext_tran=0 425 * max_queue_depth=4 ext_tran=0 tag_mode=2 \
426 * rev_scan=1 426 * rev_scan=1
427 * 427 *
428 * ------------------------------------------ 428 * ----------------------------------------------------------------------------
429 * In this implementation, linked commands ar 429 * In this implementation, linked commands are designed to work with any DISK
430 * or CD-ROM, since this linking has only the 430 * or CD-ROM, since this linking has only the intent of clustering (time-wise)
431 * and reordering by elevator sorting command 431 * and reordering by elevator sorting commands directed to each device,
432 * without any relation with the actual SCSI 432 * without any relation with the actual SCSI protocol between the controller
433 * and the device. 433 * and the device.
434 * If Q is the queue depth reported at boot t 434 * If Q is the queue depth reported at boot time for each device (also named
435 * cmds/lun) and Q > 2, whenever there is alr 435 * cmds/lun) and Q > 2, whenever there is already an active command to the
436 * device all other commands to the same devi 436 * device all other commands to the same device (up to Q-1) are kept waiting
437 * in the elevator sorting queue. When the ac 437 * in the elevator sorting queue. When the active command completes, the
438 * commands in this queue are sorted by secto 438 * commands in this queue are sorted by sector address. The sort is chosen
439 * between increasing or decreasing by minimi 439 * between increasing or decreasing by minimizing the seek distance between
440 * the sector of the commands just completed 440 * the sector of the commands just completed and the sector of the first
441 * command in the list to be sorted. 441 * command in the list to be sorted.
442 * Trivial math assures that the unsorted ave 442 * Trivial math assures that the unsorted average seek distance when doing
443 * random seeks over S sectors is S/3. 443 * random seeks over S sectors is S/3.
444 * When (Q-1) requests are uniformly distribu 444 * When (Q-1) requests are uniformly distributed over S sectors, the average
445 * distance between two adjacent requests is 445 * distance between two adjacent requests is S/((Q-1) + 1), so the sorted
446 * average seek distance for (Q-1) random req 446 * average seek distance for (Q-1) random requests over S sectors is S/Q.
447 * The elevator sorting hence divides the see 447 * The elevator sorting hence divides the seek distance by a factor Q/3.
448 * The above pure geometric remarks are valid 448 * The above pure geometric remarks are valid in all cases and the
449 * driver effectively reduces the seek distan 449 * driver effectively reduces the seek distance by the predicted factor
450 * when there are Q concurrent read i/o opera 450 * when there are Q concurrent read i/o operations on the device, but this
451 * does not necessarily results in a noticeab 451 * does not necessarily results in a noticeable performance improvement:
452 * your mileage may vary.... 452 * your mileage may vary....
453 * 453 *
454 * Note: command reordering inside a batch of 454 * Note: command reordering inside a batch of queued commands could cause
455 * wrong results only if there is at le 455 * wrong results only if there is at least one write request and the
456 * intersection (sector-wise) of all re 456 * intersection (sector-wise) of all requests is not empty.
457 * When the driver detects a batch incl 457 * When the driver detects a batch including overlapping requests
458 * (a really rare event) strict serial 458 * (a really rare event) strict serial (pid) order is enforced.
459 * ------------------------------------------ 459 * ----------------------------------------------------------------------------
460 * The extended translation option (et:y) is 460 * The extended translation option (et:y) is useful when using large physical
461 * disks/arrays. It could also be useful when 461 * disks/arrays. It could also be useful when switching between Adaptec boards
462 * and DPT boards without reformatting the di 462 * and DPT boards without reformatting the disk.
463 * When a boot disk is partitioned with exten 463 * When a boot disk is partitioned with extended translation, in order to
464 * be able to boot it with a DPT board is cou 464 * be able to boot it with a DPT board is could be necessary to add to
465 * lilo.conf additional commands as in the fo 465 * lilo.conf additional commands as in the following example:
466 * 466 *
467 * fix-table 467 * fix-table
468 * disk=/dev/sda bios=0x80 sectors=63 heads=1 468 * disk=/dev/sda bios=0x80 sectors=63 heads=128 cylindres=546
469 * 469 *
470 * where the above geometry should be replace 470 * where the above geometry should be replaced with the one reported at
471 * power up by the DPT controller. 471 * power up by the DPT controller.
472 * ------------------------------------------ 472 * ----------------------------------------------------------------------------
473 * 473 *
474 * The boards are named EATA0, EATA1,... acco 474 * The boards are named EATA0, EATA1,... according to the detection order.
475 * 475 *
476 * In order to support multiple ISA boards in 476 * In order to support multiple ISA boards in a reliable way,
477 * the driver sets host->wish_block = 1 for a 477 * the driver sets host->wish_block = 1 for all ISA boards.
478 */ 478 */
479 479
>> 480 #include <linux/config.h>
480 #include <linux/string.h> 481 #include <linux/string.h>
481 #include <linux/kernel.h> 482 #include <linux/kernel.h>
482 #include <linux/ioport.h> 483 #include <linux/ioport.h>
483 #include <linux/delay.h> 484 #include <linux/delay.h>
484 #include <linux/proc_fs.h> 485 #include <linux/proc_fs.h>
485 #include <linux/blkdev.h> 486 #include <linux/blkdev.h>
486 #include <linux/interrupt.h> 487 #include <linux/interrupt.h>
487 #include <linux/stat.h> 488 #include <linux/stat.h>
488 #include <linux/pci.h> 489 #include <linux/pci.h>
489 #include <linux/init.h> 490 #include <linux/init.h>
490 #include <linux/ctype.h> 491 #include <linux/ctype.h>
491 #include <linux/spinlock.h> 492 #include <linux/spinlock.h>
492 #include <linux/dma-mapping.h> <<
493 #include <asm/byteorder.h> 493 #include <asm/byteorder.h>
494 #include <asm/dma.h> 494 #include <asm/dma.h>
495 #include <asm/io.h> 495 #include <asm/io.h>
496 #include <asm/irq.h> 496 #include <asm/irq.h>
497 497
498 #include <scsi/scsi.h> 498 #include <scsi/scsi.h>
499 #include <scsi/scsi_cmnd.h> 499 #include <scsi/scsi_cmnd.h>
500 #include <scsi/scsi_device.h> 500 #include <scsi/scsi_device.h>
501 #include <scsi/scsi_host.h> 501 #include <scsi/scsi_host.h>
502 #include <scsi/scsi_tcq.h> 502 #include <scsi/scsi_tcq.h>
503 #include <scsi/scsicam.h> 503 #include <scsi/scsicam.h>
504 504
505 static int eata2x_detect(struct scsi_host_temp 505 static int eata2x_detect(struct scsi_host_template *);
506 static int eata2x_release(struct Scsi_Host *); 506 static int eata2x_release(struct Scsi_Host *);
507 static int eata2x_queuecommand(struct scsi_cmn 507 static int eata2x_queuecommand(struct scsi_cmnd *,
508 void (*done) (s 508 void (*done) (struct scsi_cmnd *));
509 static int eata2x_eh_abort(struct scsi_cmnd *) 509 static int eata2x_eh_abort(struct scsi_cmnd *);
510 static int eata2x_eh_host_reset(struct scsi_cm 510 static int eata2x_eh_host_reset(struct scsi_cmnd *);
511 static int eata2x_bios_param(struct scsi_devic 511 static int eata2x_bios_param(struct scsi_device *, struct block_device *,
512 sector_t, int *); 512 sector_t, int *);
513 static int eata2x_slave_configure(struct scsi_ 513 static int eata2x_slave_configure(struct scsi_device *);
514 514
515 static struct scsi_host_template driver_templa 515 static struct scsi_host_template driver_template = {
516 .name = "EATA/DMA 2.0x rev. 8.10.00 ", 516 .name = "EATA/DMA 2.0x rev. 8.10.00 ",
517 .detect = eata2x_detect, 517 .detect = eata2x_detect,
518 .release = eata2x_release, 518 .release = eata2x_release,
519 .queuecommand = eata2x_queuecommand, 519 .queuecommand = eata2x_queuecommand,
520 .eh_abort_handler = eata2x_eh_abort, 520 .eh_abort_handler = eata2x_eh_abort,
>> 521 .eh_device_reset_handler = NULL,
>> 522 .eh_bus_reset_handler = NULL,
521 .eh_host_reset_handler = eata2x_eh_hos 523 .eh_host_reset_handler = eata2x_eh_host_reset,
522 .bios_param = eata2x_bios_param, 524 .bios_param = eata2x_bios_param,
523 .slave_configure = eata2x_slave_config 525 .slave_configure = eata2x_slave_configure,
524 .this_id = 7, 526 .this_id = 7,
525 .unchecked_isa_dma = 1, 527 .unchecked_isa_dma = 1,
526 .use_clustering = ENABLE_CLUSTERING, !! 528 .use_clustering = ENABLE_CLUSTERING
527 }; 529 };
528 530
529 #if !defined(__BIG_ENDIAN_BITFIELD) && !define 531 #if !defined(__BIG_ENDIAN_BITFIELD) && !defined(__LITTLE_ENDIAN_BITFIELD)
530 #error "Adjust your <asm/byteorder.h> defines" 532 #error "Adjust your <asm/byteorder.h> defines"
531 #endif 533 #endif
532 534
533 /* Subversion values */ 535 /* Subversion values */
534 #define ISA 0 536 #define ISA 0
535 #define ESA 1 537 #define ESA 1
536 538
537 #undef FORCE_CONFIG 539 #undef FORCE_CONFIG
538 540
539 #undef DEBUG_LINKED_COMMANDS 541 #undef DEBUG_LINKED_COMMANDS
540 #undef DEBUG_DETECT 542 #undef DEBUG_DETECT
541 #undef DEBUG_PCI_DETECT 543 #undef DEBUG_PCI_DETECT
542 #undef DEBUG_INTERRUPT 544 #undef DEBUG_INTERRUPT
543 #undef DEBUG_RESET 545 #undef DEBUG_RESET
544 #undef DEBUG_GENERATE_ERRORS 546 #undef DEBUG_GENERATE_ERRORS
545 #undef DEBUG_GENERATE_ABORTS 547 #undef DEBUG_GENERATE_ABORTS
546 #undef DEBUG_GEOMETRY 548 #undef DEBUG_GEOMETRY
547 549
548 #define MAX_ISA 4 550 #define MAX_ISA 4
549 #define MAX_VESA 0 551 #define MAX_VESA 0
550 #define MAX_EISA 15 552 #define MAX_EISA 15
551 #define MAX_PCI 16 553 #define MAX_PCI 16
552 #define MAX_BOARDS (MAX_ISA + MAX_VESA + MAX_E 554 #define MAX_BOARDS (MAX_ISA + MAX_VESA + MAX_EISA + MAX_PCI)
553 #define MAX_CHANNEL 4 555 #define MAX_CHANNEL 4
554 #define MAX_LUN 32 556 #define MAX_LUN 32
555 #define MAX_TARGET 32 557 #define MAX_TARGET 32
556 #define MAX_MAILBOXES 64 558 #define MAX_MAILBOXES 64
557 #define MAX_SGLIST 64 559 #define MAX_SGLIST 64
558 #define MAX_LARGE_SGLIST 122 560 #define MAX_LARGE_SGLIST 122
559 #define MAX_INTERNAL_RETRIES 64 561 #define MAX_INTERNAL_RETRIES 64
560 #define MAX_CMD_PER_LUN 2 562 #define MAX_CMD_PER_LUN 2
561 #define MAX_TAGGED_CMD_PER_LUN (MAX_MAILBOXES 563 #define MAX_TAGGED_CMD_PER_LUN (MAX_MAILBOXES - MAX_CMD_PER_LUN)
562 564
563 #define SKIP ULONG_MAX 565 #define SKIP ULONG_MAX
564 #define FREE 0 566 #define FREE 0
565 #define IN_USE 1 567 #define IN_USE 1
566 #define LOCKED 2 568 #define LOCKED 2
567 #define IN_RESET 3 569 #define IN_RESET 3
568 #define IGNORE 4 570 #define IGNORE 4
569 #define READY 5 571 #define READY 5
570 #define ABORTING 6 572 #define ABORTING 6
571 #define NO_DMA 0xff 573 #define NO_DMA 0xff
572 #define MAXLOOP 10000 574 #define MAXLOOP 10000
573 #define TAG_DISABLED 0 575 #define TAG_DISABLED 0
574 #define TAG_SIMPLE 1 576 #define TAG_SIMPLE 1
575 #define TAG_ORDERED 2 577 #define TAG_ORDERED 2
576 578
577 #define REG_CMD 7 579 #define REG_CMD 7
578 #define REG_STATUS 7 580 #define REG_STATUS 7
579 #define REG_AUX_STATUS 8 581 #define REG_AUX_STATUS 8
580 #define REG_DATA 0 582 #define REG_DATA 0
581 #define REG_DATA2 1 583 #define REG_DATA2 1
582 #define REG_SEE 6 584 #define REG_SEE 6
583 #define REG_LOW 2 585 #define REG_LOW 2
584 #define REG_LM 3 586 #define REG_LM 3
585 #define REG_MID 4 587 #define REG_MID 4
586 #define REG_MSB 5 588 #define REG_MSB 5
587 #define REGION_SIZE 9UL 589 #define REGION_SIZE 9UL
588 #define MAX_ISA_ADDR 0x03ff 590 #define MAX_ISA_ADDR 0x03ff
589 #define MIN_EISA_ADDR 0x1c88 591 #define MIN_EISA_ADDR 0x1c88
590 #define MAX_EISA_ADDR 0xfc88 592 #define MAX_EISA_ADDR 0xfc88
591 #define BSY_ASSERTED 0x80 593 #define BSY_ASSERTED 0x80
592 #define DRQ_ASSERTED 0x08 594 #define DRQ_ASSERTED 0x08
593 #define ABSY_ASSERTED 0x01 595 #define ABSY_ASSERTED 0x01
594 #define IRQ_ASSERTED 0x02 596 #define IRQ_ASSERTED 0x02
595 #define READ_CONFIG_PIO 0xf0 597 #define READ_CONFIG_PIO 0xf0
596 #define SET_CONFIG_PIO 0xf1 598 #define SET_CONFIG_PIO 0xf1
597 #define SEND_CP_PIO 0xf2 599 #define SEND_CP_PIO 0xf2
598 #define RECEIVE_SP_PIO 0xf3 600 #define RECEIVE_SP_PIO 0xf3
599 #define TRUNCATE_XFR_PIO 0xf4 601 #define TRUNCATE_XFR_PIO 0xf4
600 #define RESET_PIO 0xf9 602 #define RESET_PIO 0xf9
601 #define READ_CONFIG_DMA 0xfd 603 #define READ_CONFIG_DMA 0xfd
602 #define SET_CONFIG_DMA 0xfe 604 #define SET_CONFIG_DMA 0xfe
603 #define SEND_CP_DMA 0xff 605 #define SEND_CP_DMA 0xff
604 #define ASOK 0x00 606 #define ASOK 0x00
605 #define ASST 0x01 607 #define ASST 0x01
606 608
607 #define YESNO(a) ((a) ? 'y' : 'n') 609 #define YESNO(a) ((a) ? 'y' : 'n')
608 #define TLDEV(type) ((type) == TYPE_DISK || (t 610 #define TLDEV(type) ((type) == TYPE_DISK || (type) == TYPE_ROM)
609 611
610 /* "EATA", in Big Endian format */ 612 /* "EATA", in Big Endian format */
611 #define EATA_SIG_BE 0x45415441 613 #define EATA_SIG_BE 0x45415441
612 614
613 /* Number of valid bytes in the board config s 615 /* Number of valid bytes in the board config structure for EATA 2.0x */
614 #define EATA_2_0A_SIZE 28 616 #define EATA_2_0A_SIZE 28
615 #define EATA_2_0B_SIZE 30 617 #define EATA_2_0B_SIZE 30
616 #define EATA_2_0C_SIZE 34 618 #define EATA_2_0C_SIZE 34
617 619
618 /* Board info structure */ 620 /* Board info structure */
619 struct eata_info { 621 struct eata_info {
620 u_int32_t data_len; /* Number of v 622 u_int32_t data_len; /* Number of valid bytes after this field */
621 u_int32_t sign; /* ASCII "EATA 623 u_int32_t sign; /* ASCII "EATA" signature */
622 624
623 #if defined(__BIG_ENDIAN_BITFIELD) 625 #if defined(__BIG_ENDIAN_BITFIELD)
624 unchar version : 4, 626 unchar version : 4,
625 : 4; 627 : 4;
626 unchar haaval : 1, 628 unchar haaval : 1,
627 ata : 1, 629 ata : 1,
628 drqvld : 1, 630 drqvld : 1,
629 dmasup : 1, 631 dmasup : 1,
630 morsup : 1, 632 morsup : 1,
631 trnxfr : 1, 633 trnxfr : 1,
632 tarsup : 1, 634 tarsup : 1,
633 ocsena : 1; 635 ocsena : 1;
634 #else 636 #else
635 unchar : 4, /* unused low 637 unchar : 4, /* unused low nibble */
636 version : 4; /* EATA versio 638 version : 4; /* EATA version, should be 0x1 */
637 unchar ocsena : 1, /* Overlap Com 639 unchar ocsena : 1, /* Overlap Command Support Enabled */
638 tarsup : 1, /* Target Mode 640 tarsup : 1, /* Target Mode Supported */
639 trnxfr : 1, /* Truncate Tr 641 trnxfr : 1, /* Truncate Transfer Cmd NOT Necessary */
640 morsup : 1, /* More Suppor 642 morsup : 1, /* More Supported */
641 dmasup : 1, /* DMA Support 643 dmasup : 1, /* DMA Supported */
642 drqvld : 1, /* DRQ Index ( 644 drqvld : 1, /* DRQ Index (DRQX) is valid */
643 ata : 1, /* This is an 645 ata : 1, /* This is an ATA device */
644 haaval : 1; /* Host Adapte 646 haaval : 1; /* Host Adapter Address Valid */
645 #endif 647 #endif
646 648
647 ushort cp_pad_len; /* Number of p 649 ushort cp_pad_len; /* Number of pad bytes after cp_len */
648 unchar host_addr[4]; /* Host Adapte 650 unchar host_addr[4]; /* Host Adapter SCSI ID for channels 3, 2, 1, 0 */
649 u_int32_t cp_len; /* Number of v 651 u_int32_t cp_len; /* Number of valid bytes in cp */
650 u_int32_t sp_len; /* Number of v 652 u_int32_t sp_len; /* Number of valid bytes in sp */
651 ushort queue_size; /* Max number 653 ushort queue_size; /* Max number of cp that can be queued */
652 ushort unused; 654 ushort unused;
653 ushort scatt_size; /* Max number 655 ushort scatt_size; /* Max number of entries in scatter/gather table */
654 656
655 #if defined(__BIG_ENDIAN_BITFIELD) 657 #if defined(__BIG_ENDIAN_BITFIELD)
656 unchar drqx : 2, 658 unchar drqx : 2,
657 second : 1, 659 second : 1,
658 irq_tr : 1, 660 irq_tr : 1,
659 irq : 4; 661 irq : 4;
660 unchar sync; 662 unchar sync;
661 unchar : 4, 663 unchar : 4,
662 res1 : 1, 664 res1 : 1,
663 large_sg : 1, 665 large_sg : 1,
664 forcaddr : 1, 666 forcaddr : 1,
665 isaena : 1; 667 isaena : 1;
666 unchar max_chan : 3, 668 unchar max_chan : 3,
667 max_id : 5; 669 max_id : 5;
668 unchar max_lun; 670 unchar max_lun;
669 unchar eisa : 1, 671 unchar eisa : 1,
670 pci : 1, 672 pci : 1,
671 idquest : 1, 673 idquest : 1,
672 m1 : 1, 674 m1 : 1,
673 : 4; 675 : 4;
674 #else 676 #else
675 unchar irq : 4, /* Interrupt R 677 unchar irq : 4, /* Interrupt Request assigned to this controller */
676 irq_tr : 1, /* 0 for edge 678 irq_tr : 1, /* 0 for edge triggered, 1 for level triggered */
677 second : 1, /* 1 if this i 679 second : 1, /* 1 if this is a secondary (not primary) controller */
678 drqx : 2; /* DRQ Index ( 680 drqx : 2; /* DRQ Index (0=DMA0, 1=DMA7, 2=DMA6, 3=DMA5) */
679 unchar sync; /* 1 if scsi t 681 unchar sync; /* 1 if scsi target id 7...0 is running sync scsi */
680 682
681 /* Structure extension defined in EATA 683 /* Structure extension defined in EATA 2.0B */
682 unchar isaena : 1, /* ISA i/o add 684 unchar isaena : 1, /* ISA i/o addressing is disabled/enabled */
683 forcaddr : 1, /* Port addres 685 forcaddr : 1, /* Port address has been forced */
684 large_sg : 1, /* 1 if large 686 large_sg : 1, /* 1 if large SG lists are supported */
685 res1 : 1, 687 res1 : 1,
686 : 4; 688 : 4;
687 unchar max_id : 5, /* Max SCSI ta 689 unchar max_id : 5, /* Max SCSI target ID number */
688 max_chan : 3; /* Max SCSI ch 690 max_chan : 3; /* Max SCSI channel number on this board */
689 691
690 /* Structure extension defined in EATA 692 /* Structure extension defined in EATA 2.0C */
691 unchar max_lun; /* Max SCSI LU 693 unchar max_lun; /* Max SCSI LUN number */
692 unchar 694 unchar
693 : 4, 695 : 4,
694 m1 : 1, /* This is a P 696 m1 : 1, /* This is a PCI with an M1 chip installed */
695 idquest : 1, /* RAIDNUM ret 697 idquest : 1, /* RAIDNUM returned is questionable */
696 pci : 1, /* This board 698 pci : 1, /* This board is PCI */
697 eisa : 1; /* This board 699 eisa : 1; /* This board is EISA */
698 #endif 700 #endif
699 701
700 unchar raidnum; /* Uniquely id 702 unchar raidnum; /* Uniquely identifies this HBA in a system */
701 unchar notused; 703 unchar notused;
702 704
703 ushort ipad[247]; 705 ushort ipad[247];
704 }; 706 };
705 707
706 /* Board config structure */ 708 /* Board config structure */
707 struct eata_config { 709 struct eata_config {
708 ushort len; /* Number of b 710 ushort len; /* Number of bytes following this field */
709 711
710 #if defined(__BIG_ENDIAN_BITFIELD) 712 #if defined(__BIG_ENDIAN_BITFIELD)
711 unchar : 4, 713 unchar : 4,
712 tarena : 1, 714 tarena : 1,
713 mdpena : 1, 715 mdpena : 1,
714 ocena : 1, 716 ocena : 1,
715 edis : 1; 717 edis : 1;
716 #else 718 #else
717 unchar edis : 1, /* Disable EAT 719 unchar edis : 1, /* Disable EATA interface after config command */
718 ocena : 1, /* Overlapped 720 ocena : 1, /* Overlapped Commands Enabled */
719 mdpena : 1, /* Transfer al 721 mdpena : 1, /* Transfer all Modified Data Pointer Messages */
720 tarena : 1, /* Target Mode 722 tarena : 1, /* Target Mode Enabled for this controller */
721 : 4; 723 : 4;
722 #endif 724 #endif
723 unchar cpad[511]; 725 unchar cpad[511];
724 }; 726 };
725 727
726 /* Returned status packet structure */ 728 /* Returned status packet structure */
727 struct mssp { 729 struct mssp {
728 #if defined(__BIG_ENDIAN_BITFIELD) 730 #if defined(__BIG_ENDIAN_BITFIELD)
729 unchar eoc : 1, 731 unchar eoc : 1,
730 adapter_status : 7; 732 adapter_status : 7;
731 #else 733 #else
732 unchar adapter_status : 7, /* Sta 734 unchar adapter_status : 7, /* State related to current command */
733 eoc : 1; /* End 735 eoc : 1; /* End Of Command (1 = command completed) */
734 #endif 736 #endif
735 unchar target_status; /* SCSI status 737 unchar target_status; /* SCSI status received after data transfer */
736 unchar unused[2]; 738 unchar unused[2];
737 u_int32_t inv_res_len; /* Number of b 739 u_int32_t inv_res_len; /* Number of bytes not transferred */
738 u_int32_t cpp_index; /* Index of ad 740 u_int32_t cpp_index; /* Index of address set in cp */
739 char mess[12]; 741 char mess[12];
740 }; 742 };
741 743
742 struct sg_list { 744 struct sg_list {
743 unsigned int address; /* Segment Add 745 unsigned int address; /* Segment Address */
744 unsigned int num_bytes; /* Segment Len 746 unsigned int num_bytes; /* Segment Length */
745 }; 747 };
746 748
747 /* MailBox SCSI Command Packet */ 749 /* MailBox SCSI Command Packet */
748 struct mscp { 750 struct mscp {
749 #if defined(__BIG_ENDIAN_BITFIELD) 751 #if defined(__BIG_ENDIAN_BITFIELD)
750 unchar din : 1, 752 unchar din : 1,
751 dout : 1, 753 dout : 1,
752 interp : 1, 754 interp : 1,
753 : 1, 755 : 1,
754 sg : 1, 756 sg : 1,
755 reqsen :1, 757 reqsen :1,
756 init : 1, 758 init : 1,
757 sreset : 1; 759 sreset : 1;
758 unchar sense_len; 760 unchar sense_len;
759 unchar unused[3]; 761 unchar unused[3];
760 unchar : 7, 762 unchar : 7,
761 fwnest : 1; 763 fwnest : 1;
762 unchar : 5, 764 unchar : 5,
763 hbaci : 1, 765 hbaci : 1,
764 iat : 1, 766 iat : 1,
765 phsunit : 1; 767 phsunit : 1;
766 unchar channel : 3, 768 unchar channel : 3,
767 target : 5; 769 target : 5;
768 unchar one : 1, 770 unchar one : 1,
769 dispri : 1, 771 dispri : 1,
770 luntar : 1, 772 luntar : 1,
771 lun : 5; 773 lun : 5;
772 #else 774 #else
773 unchar sreset :1, /* SCSI Bus Re 775 unchar sreset :1, /* SCSI Bus Reset Signal should be asserted */
774 init :1, /* Re-initiali 776 init :1, /* Re-initialize controller and self test */
775 reqsen :1, /* Transfer Re 777 reqsen :1, /* Transfer Request Sense Data to addr using DMA */
776 sg :1, /* Use Scatter 778 sg :1, /* Use Scatter/Gather */
777 :1, 779 :1,
778 interp :1, /* The control 780 interp :1, /* The controller interprets cp, not the target */
779 dout :1, /* Direction o 781 dout :1, /* Direction of Transfer is Out (Host to Target) */
780 din :1; /* Direction o 782 din :1; /* Direction of Transfer is In (Target to Host) */
781 unchar sense_len; /* Request Sen 783 unchar sense_len; /* Request Sense Length */
782 unchar unused[3]; 784 unchar unused[3];
783 unchar fwnest : 1, /* Send comman 785 unchar fwnest : 1, /* Send command to a component of an Array Group */
784 : 7; 786 : 7;
785 unchar phsunit : 1, /* Send to Tar 787 unchar phsunit : 1, /* Send to Target Physical Unit (bypass RAID) */
786 iat : 1, /* Inhibit Add 788 iat : 1, /* Inhibit Address Translation */
787 hbaci : 1, /* Inhibit HBA 789 hbaci : 1, /* Inhibit HBA Caching for this command */
788 : 5; 790 : 5;
789 unchar target : 5, /* SCSI target 791 unchar target : 5, /* SCSI target ID */
790 channel : 3; /* SCSI channe 792 channel : 3; /* SCSI channel number */
791 unchar lun : 5, /* SCSI logica 793 unchar lun : 5, /* SCSI logical unit number */
792 luntar : 1, /* This cp is 794 luntar : 1, /* This cp is for Target (not LUN) */
793 dispri : 1, /* Disconnect 795 dispri : 1, /* Disconnect Privilege granted */
794 one : 1; /* 1 */ 796 one : 1; /* 1 */
795 #endif 797 #endif
796 798
797 unchar mess[3]; /* Massage to/ 799 unchar mess[3]; /* Massage to/from Target */
798 unchar cdb[12]; /* Command Des 800 unchar cdb[12]; /* Command Descriptor Block */
799 u_int32_t data_len; /* If sg=0 Dat 801 u_int32_t data_len; /* If sg=0 Data Length, if sg=1 sglist length */
800 u_int32_t cpp_index; /* Index of ad 802 u_int32_t cpp_index; /* Index of address to be returned in sp */
801 u_int32_t data_address; /* If sg=0 Dat 803 u_int32_t data_address; /* If sg=0 Data Address, if sg=1 sglist address */
802 u_int32_t sp_dma_addr; /* Address whe 804 u_int32_t sp_dma_addr; /* Address where sp is DMA'ed when cp completes */
803 u_int32_t sense_addr; /* Address whe 805 u_int32_t sense_addr; /* Address where Sense Data is DMA'ed on error */
804 806
805 /* Additional fields begin here. */ 807 /* Additional fields begin here. */
806 struct scsi_cmnd *SCpnt; 808 struct scsi_cmnd *SCpnt;
807 809
808 /* All the cp structure is zero filled 810 /* All the cp structure is zero filled by queuecommand except the
809 following CP_TAIL_SIZE bytes, initi 811 following CP_TAIL_SIZE bytes, initialized by detect */
810 dma_addr_t cp_dma_addr; /* dma handle 812 dma_addr_t cp_dma_addr; /* dma handle for this cp structure */
811 struct sg_list *sglist; /* pointer to 813 struct sg_list *sglist; /* pointer to the allocated SG list */
812 }; 814 };
813 815
814 #define CP_TAIL_SIZE (sizeof(struct sglist *) 816 #define CP_TAIL_SIZE (sizeof(struct sglist *) + sizeof(dma_addr_t))
815 817
816 struct hostdata { 818 struct hostdata {
817 struct mscp cp[MAX_MAILBOXES]; /* Mai 819 struct mscp cp[MAX_MAILBOXES]; /* Mailboxes for this board */
818 unsigned int cp_stat[MAX_MAILBOXES]; 820 unsigned int cp_stat[MAX_MAILBOXES]; /* FREE, IN_USE, LOCKED, IN_RESET */
819 unsigned int last_cp_used; /* Ind 821 unsigned int last_cp_used; /* Index of last mailbox used */
820 unsigned int iocount; /* Total i/o d 822 unsigned int iocount; /* Total i/o done for this board */
821 int board_number; /* Number of t 823 int board_number; /* Number of this board */
822 char board_name[16]; /* Name of thi 824 char board_name[16]; /* Name of this board */
823 int in_reset; /* True if boa 825 int in_reset; /* True if board is doing a reset */
824 int target_to[MAX_TARGET][MAX_CHANNEL] 826 int target_to[MAX_TARGET][MAX_CHANNEL]; /* N. of timeout errors on target */
825 int target_redo[MAX_TARGET][MAX_CHANNE 827 int target_redo[MAX_TARGET][MAX_CHANNEL]; /* If 1 redo i/o on target */
826 unsigned int retries; /* Number of i 828 unsigned int retries; /* Number of internal retries */
827 unsigned long last_retried_pid; /* Pid 829 unsigned long last_retried_pid; /* Pid of last retried command */
828 unsigned char subversion; /* Bus 830 unsigned char subversion; /* Bus type, either ISA or EISA/PCI */
829 unsigned char protocol_rev; /* EAT 831 unsigned char protocol_rev; /* EATA 2.0 rev., 'A' or 'B' or 'C' */
830 unsigned char is_pci; /* 1 is bus ty 832 unsigned char is_pci; /* 1 is bus type is PCI */
831 struct pci_dev *pdev; /* pdev for PC 833 struct pci_dev *pdev; /* pdev for PCI bus, NULL otherwise */
832 struct mssp *sp_cpu_addr; /* cpu 834 struct mssp *sp_cpu_addr; /* cpu addr for DMA buffer sp */
833 dma_addr_t sp_dma_addr; /* dma handle 835 dma_addr_t sp_dma_addr; /* dma handle for DMA buffer sp */
834 struct mssp sp; /* Local copy 836 struct mssp sp; /* Local copy of sp buffer */
835 }; 837 };
836 838
837 static struct Scsi_Host *sh[MAX_BOARDS]; 839 static struct Scsi_Host *sh[MAX_BOARDS];
838 static const char *driver_name = "EATA"; 840 static const char *driver_name = "EATA";
839 static char sha[MAX_BOARDS]; 841 static char sha[MAX_BOARDS];
840 static DEFINE_SPINLOCK(driver_lock); 842 static DEFINE_SPINLOCK(driver_lock);
841 843
842 /* Initialize num_boards so that ihdlr can wor 844 /* Initialize num_boards so that ihdlr can work while detect is in progress */
843 static unsigned int num_boards = MAX_BOARDS; 845 static unsigned int num_boards = MAX_BOARDS;
844 846
845 static unsigned long io_port[] = { 847 static unsigned long io_port[] = {
846 848
847 /* Space for MAX_INT_PARAM ports usabl 849 /* Space for MAX_INT_PARAM ports usable while loading as a module */
848 SKIP, SKIP, SKIP, SKIP, SKIP, SKIP, SK 850 SKIP, SKIP, SKIP, SKIP, SKIP, SKIP, SKIP, SKIP,
849 SKIP, SKIP, 851 SKIP, SKIP,
850 852
851 /* First ISA */ 853 /* First ISA */
852 0x1f0, 854 0x1f0,
853 855
854 /* Space for MAX_PCI ports possibly re 856 /* Space for MAX_PCI ports possibly reported by PCI_BIOS */
855 SKIP, SKIP, SKIP, SKIP, SKIP, SKIP, SK 857 SKIP, SKIP, SKIP, SKIP, SKIP, SKIP, SKIP, SKIP,
856 SKIP, SKIP, SKIP, SKIP, SKIP, SKIP, SK 858 SKIP, SKIP, SKIP, SKIP, SKIP, SKIP, SKIP, SKIP,
857 859
858 /* MAX_EISA ports */ 860 /* MAX_EISA ports */
859 0x1c88, 0x2c88, 0x3c88, 0x4c88, 0x5c88 861 0x1c88, 0x2c88, 0x3c88, 0x4c88, 0x5c88, 0x6c88, 0x7c88, 0x8c88,
860 0x9c88, 0xac88, 0xbc88, 0xcc88, 0xdc88 862 0x9c88, 0xac88, 0xbc88, 0xcc88, 0xdc88, 0xec88, 0xfc88,
861 863
862 /* Other (MAX_ISA - 1) ports */ 864 /* Other (MAX_ISA - 1) ports */
863 0x170, 0x230, 0x330, 865 0x170, 0x230, 0x330,
864 866
865 /* End of list */ 867 /* End of list */
866 0x0 868 0x0
867 }; 869 };
868 870
869 /* Device is Big Endian */ 871 /* Device is Big Endian */
870 #define H2DEV(x) cpu_to_be32(x) 872 #define H2DEV(x) cpu_to_be32(x)
871 #define DEV2H(x) be32_to_cpu(x) 873 #define DEV2H(x) be32_to_cpu(x)
872 #define H2DEV16(x) cpu_to_be16(x) 874 #define H2DEV16(x) cpu_to_be16(x)
873 #define DEV2H16(x) be16_to_cpu(x) 875 #define DEV2H16(x) be16_to_cpu(x)
874 876
875 /* But transfer orientation from the 16 bit da 877 /* But transfer orientation from the 16 bit data register is Little Endian */
876 #define REG2H(x) le16_to_cpu(x) 878 #define REG2H(x) le16_to_cpu(x)
877 879
878 static irqreturn_t do_interrupt_handler(int, v !! 880 static irqreturn_t do_interrupt_handler(int, void *, struct pt_regs *);
879 static void flush_dev(struct scsi_device *, un 881 static void flush_dev(struct scsi_device *, unsigned long, struct hostdata *,
880 unsigned int); 882 unsigned int);
881 static int do_trace = 0; 883 static int do_trace = 0;
882 static int setup_done = 0; 884 static int setup_done = 0;
883 static int link_statistics; 885 static int link_statistics;
884 static int ext_tran = 0; 886 static int ext_tran = 0;
885 static int rev_scan = 1; 887 static int rev_scan = 1;
886 888
887 #if defined(CONFIG_SCSI_EATA_TAGGED_QUEUE) 889 #if defined(CONFIG_SCSI_EATA_TAGGED_QUEUE)
888 static int tag_mode = TAG_SIMPLE; 890 static int tag_mode = TAG_SIMPLE;
889 #else 891 #else
890 static int tag_mode = TAG_DISABLED; 892 static int tag_mode = TAG_DISABLED;
891 #endif 893 #endif
892 894
893 #if defined(CONFIG_SCSI_EATA_LINKED_COMMANDS) 895 #if defined(CONFIG_SCSI_EATA_LINKED_COMMANDS)
894 static int linked_comm = 1; 896 static int linked_comm = 1;
895 #else 897 #else
896 static int linked_comm = 0; 898 static int linked_comm = 0;
897 #endif 899 #endif
898 900
899 #if defined(CONFIG_SCSI_EATA_MAX_TAGS) 901 #if defined(CONFIG_SCSI_EATA_MAX_TAGS)
900 static int max_queue_depth = CONFIG_SCSI_EATA_ 902 static int max_queue_depth = CONFIG_SCSI_EATA_MAX_TAGS;
901 #else 903 #else
902 static int max_queue_depth = MAX_CMD_PER_LUN; 904 static int max_queue_depth = MAX_CMD_PER_LUN;
903 #endif 905 #endif
904 906
905 #if defined(CONFIG_ISA) 907 #if defined(CONFIG_ISA)
906 static int isa_probe = 1; 908 static int isa_probe = 1;
907 #else 909 #else
908 static int isa_probe = 0; 910 static int isa_probe = 0;
909 #endif 911 #endif
910 912
911 #if defined(CONFIG_EISA) 913 #if defined(CONFIG_EISA)
912 static int eisa_probe = 1; 914 static int eisa_probe = 1;
913 #else 915 #else
914 static int eisa_probe = 0; 916 static int eisa_probe = 0;
915 #endif 917 #endif
916 918
917 #if defined(CONFIG_PCI) 919 #if defined(CONFIG_PCI)
918 static int pci_probe = 1; 920 static int pci_probe = 1;
919 #else 921 #else
920 static int pci_probe = 0; 922 static int pci_probe = 0;
921 #endif 923 #endif
922 924
923 #define MAX_INT_PARAM 10 925 #define MAX_INT_PARAM 10
924 #define MAX_BOOT_OPTIONS_SIZE 256 926 #define MAX_BOOT_OPTIONS_SIZE 256
925 static char boot_options[MAX_BOOT_OPTIONS_SIZE 927 static char boot_options[MAX_BOOT_OPTIONS_SIZE];
926 928
927 #if defined(MODULE) 929 #if defined(MODULE)
928 #include <linux/module.h> 930 #include <linux/module.h>
929 #include <linux/moduleparam.h> 931 #include <linux/moduleparam.h>
930 932
931 module_param_string(eata, boot_options, MAX_BO 933 module_param_string(eata, boot_options, MAX_BOOT_OPTIONS_SIZE, 0);
932 MODULE_PARM_DESC(eata, " equivalent to the \"e 934 MODULE_PARM_DESC(eata, " equivalent to the \"eata=...\" kernel boot option."
933 " Example: modprob 935 " Example: modprobe eata \"eata=0x7410,0x230,lc:y,tm:0,mq:4,ep:n\"");
934 MODULE_AUTHOR("Dario Ballabio"); 936 MODULE_AUTHOR("Dario Ballabio");
935 MODULE_LICENSE("GPL"); 937 MODULE_LICENSE("GPL");
936 MODULE_DESCRIPTION("EATA/DMA SCSI Driver"); 938 MODULE_DESCRIPTION("EATA/DMA SCSI Driver");
937 939
938 #endif 940 #endif
939 941
940 static int eata2x_slave_configure(struct scsi_ 942 static int eata2x_slave_configure(struct scsi_device *dev)
941 { 943 {
942 int tqd, utqd; 944 int tqd, utqd;
943 char *tag_suffix, *link_suffix; 945 char *tag_suffix, *link_suffix;
>> 946 struct Scsi_Host *shost = dev->host;
>> 947 struct hostdata *ha = (struct hostdata *)shost->hostdata;
944 948
945 utqd = MAX_CMD_PER_LUN; 949 utqd = MAX_CMD_PER_LUN;
946 tqd = max_queue_depth; 950 tqd = max_queue_depth;
947 951
948 if (TLDEV(dev->type) && dev->tagged_su 952 if (TLDEV(dev->type) && dev->tagged_supported) {
949 if (tag_mode == TAG_SIMPLE) { 953 if (tag_mode == TAG_SIMPLE) {
950 scsi_adjust_queue_dept 954 scsi_adjust_queue_depth(dev, MSG_SIMPLE_TAG, tqd);
951 tag_suffix = ", simple 955 tag_suffix = ", simple tags";
952 } else if (tag_mode == TAG_ORD 956 } else if (tag_mode == TAG_ORDERED) {
953 scsi_adjust_queue_dept 957 scsi_adjust_queue_depth(dev, MSG_ORDERED_TAG, tqd);
954 tag_suffix = ", ordere 958 tag_suffix = ", ordered tags";
955 } else { 959 } else {
956 scsi_adjust_queue_dept 960 scsi_adjust_queue_depth(dev, 0, tqd);
957 tag_suffix = ", no tag 961 tag_suffix = ", no tags";
958 } 962 }
959 } else if (TLDEV(dev->type) && linked_ 963 } else if (TLDEV(dev->type) && linked_comm) {
960 scsi_adjust_queue_depth(dev, 0 964 scsi_adjust_queue_depth(dev, 0, tqd);
961 tag_suffix = ", untagged"; 965 tag_suffix = ", untagged";
962 } else { 966 } else {
963 scsi_adjust_queue_depth(dev, 0 967 scsi_adjust_queue_depth(dev, 0, utqd);
964 tag_suffix = ""; 968 tag_suffix = "";
965 } 969 }
966 970
967 if (TLDEV(dev->type) && linked_comm && 971 if (TLDEV(dev->type) && linked_comm && dev->queue_depth > 2)
968 link_suffix = ", sorted"; 972 link_suffix = ", sorted";
969 else if (TLDEV(dev->type)) 973 else if (TLDEV(dev->type))
970 link_suffix = ", unsorted"; 974 link_suffix = ", unsorted";
971 else 975 else
972 link_suffix = ""; 976 link_suffix = "";
973 977
974 sdev_printk(KERN_INFO, dev, !! 978 printk("%s: scsi%d, channel %d, id %d, lun %d, cmds/lun %d%s%s.\n",
975 "cmds/lun %d%s%s.\n", !! 979 ha->board_name, shost->host_no, dev->channel, dev->id, dev->lun,
976 dev->queue_depth, link_suffix, 980 dev->queue_depth, link_suffix, tag_suffix);
977 981
978 return 0; 982 return 0;
979 } 983 }
980 984
981 static int wait_on_busy(unsigned long iobase, 985 static int wait_on_busy(unsigned long iobase, unsigned int loop)
982 { 986 {
983 while (inb(iobase + REG_AUX_STATUS) & 987 while (inb(iobase + REG_AUX_STATUS) & ABSY_ASSERTED) {
984 udelay(1L); 988 udelay(1L);
985 if (--loop == 0) 989 if (--loop == 0)
986 return 1; 990 return 1;
987 } 991 }
988 return 0; 992 return 0;
989 } 993 }
990 994
991 static int do_dma(unsigned long iobase, unsign 995 static int do_dma(unsigned long iobase, unsigned long addr, unchar cmd)
992 { 996 {
993 unsigned char *byaddr; 997 unsigned char *byaddr;
994 unsigned long devaddr; 998 unsigned long devaddr;
995 999
996 if (wait_on_busy(iobase, (addr ? MAXLO 1000 if (wait_on_busy(iobase, (addr ? MAXLOOP * 100 : MAXLOOP)))
997 return 1; 1001 return 1;
998 1002
999 if (addr) { 1003 if (addr) {
1000 devaddr = H2DEV(addr); 1004 devaddr = H2DEV(addr);
1001 byaddr = (unsigned char *)&de 1005 byaddr = (unsigned char *)&devaddr;
1002 outb(byaddr[3], iobase + REG_ 1006 outb(byaddr[3], iobase + REG_LOW);
1003 outb(byaddr[2], iobase + REG_ 1007 outb(byaddr[2], iobase + REG_LM);
1004 outb(byaddr[1], iobase + REG_ 1008 outb(byaddr[1], iobase + REG_MID);
1005 outb(byaddr[0], iobase + REG_ 1009 outb(byaddr[0], iobase + REG_MSB);
1006 } 1010 }
1007 1011
1008 outb(cmd, iobase + REG_CMD); 1012 outb(cmd, iobase + REG_CMD);
1009 return 0; 1013 return 0;
1010 } 1014 }
1011 1015
1012 static int read_pio(unsigned long iobase, ush 1016 static int read_pio(unsigned long iobase, ushort * start, ushort * end)
1013 { 1017 {
1014 unsigned int loop = MAXLOOP; 1018 unsigned int loop = MAXLOOP;
1015 ushort *p; 1019 ushort *p;
1016 1020
1017 for (p = start; p <= end; p++) { 1021 for (p = start; p <= end; p++) {
1018 while (!(inb(iobase + REG_STA 1022 while (!(inb(iobase + REG_STATUS) & DRQ_ASSERTED)) {
1019 udelay(1L); 1023 udelay(1L);
1020 if (--loop == 0) 1024 if (--loop == 0)
1021 return 1; 1025 return 1;
1022 } 1026 }
1023 loop = MAXLOOP; 1027 loop = MAXLOOP;
1024 *p = REG2H(inw(iobase)); 1028 *p = REG2H(inw(iobase));
1025 } 1029 }
1026 1030
1027 return 0; 1031 return 0;
1028 } 1032 }
1029 1033
1030 static struct pci_dev *get_pci_dev(unsigned l 1034 static struct pci_dev *get_pci_dev(unsigned long port_base)
1031 { 1035 {
1032 #if defined(CONFIG_PCI) 1036 #if defined(CONFIG_PCI)
1033 unsigned int addr; 1037 unsigned int addr;
1034 struct pci_dev *dev = NULL; 1038 struct pci_dev *dev = NULL;
1035 1039
1036 while ((dev = pci_get_class(PCI_CLASS 1040 while ((dev = pci_get_class(PCI_CLASS_STORAGE_SCSI << 8, dev))) {
1037 addr = pci_resource_start(dev 1041 addr = pci_resource_start(dev, 0);
1038 1042
1039 #if defined(DEBUG_PCI_DETECT) 1043 #if defined(DEBUG_PCI_DETECT)
1040 printk("%s: get_pci_dev, bus 1044 printk("%s: get_pci_dev, bus %d, devfn 0x%x, addr 0x%x.\n",
1041 driver_name, dev->bus- 1045 driver_name, dev->bus->number, dev->devfn, addr);
1042 #endif 1046 #endif
1043 1047
1044 /* we are in so much trouble 1048 /* we are in so much trouble for a pci hotplug system with this driver
1045 * anyway, so doing this at l 1049 * anyway, so doing this at least lets people unload the driver and not
1046 * cause memory problems, but 1050 * cause memory problems, but in general this is a bad thing to do (this
1047 * driver needs to be convert 1051 * driver needs to be converted to the proper PCI api someday... */
1048 pci_dev_put(dev); 1052 pci_dev_put(dev);
1049 if (addr + PCI_BASE_ADDRESS_0 1053 if (addr + PCI_BASE_ADDRESS_0 == port_base)
1050 return dev; 1054 return dev;
1051 } 1055 }
1052 #endif /* end CONFIG 1056 #endif /* end CONFIG_PCI */
1053 return NULL; 1057 return NULL;
1054 } 1058 }
1055 1059
1056 static void enable_pci_ports(void) 1060 static void enable_pci_ports(void)
1057 { 1061 {
1058 #if defined(CONFIG_PCI) 1062 #if defined(CONFIG_PCI)
1059 struct pci_dev *dev = NULL; 1063 struct pci_dev *dev = NULL;
1060 1064
1061 while ((dev = pci_get_class(PCI_CLASS 1065 while ((dev = pci_get_class(PCI_CLASS_STORAGE_SCSI << 8, dev))) {
1062 #if defined(DEBUG_PCI_DETECT) 1066 #if defined(DEBUG_PCI_DETECT)
1063 printk("%s: enable_pci_ports, 1067 printk("%s: enable_pci_ports, bus %d, devfn 0x%x.\n",
1064 driver_name, dev->bus- 1068 driver_name, dev->bus->number, dev->devfn);
1065 #endif 1069 #endif
1066 1070
1067 if (pci_enable_device(dev)) 1071 if (pci_enable_device(dev))
1068 printk 1072 printk
1069 ("%s: warning, pc 1073 ("%s: warning, pci_enable_device failed, bus %d devfn 0x%x.\n",
1070 driver_name, dev 1074 driver_name, dev->bus->number, dev->devfn);
1071 } 1075 }
1072 1076
1073 #endif /* end CONFIG 1077 #endif /* end CONFIG_PCI */
1074 } 1078 }
1075 1079
1076 static int port_detect(unsigned long port_bas 1080 static int port_detect(unsigned long port_base, unsigned int j,
1077 struct scsi_host_template *tp 1081 struct scsi_host_template *tpnt)
1078 { 1082 {
1079 unsigned char irq, dma_channel, subve 1083 unsigned char irq, dma_channel, subversion, i, is_pci = 0;
1080 unsigned char protocol_rev; 1084 unsigned char protocol_rev;
1081 struct eata_info info; 1085 struct eata_info info;
1082 char *bus_type, dma_name[16]; 1086 char *bus_type, dma_name[16];
1083 struct pci_dev *pdev; 1087 struct pci_dev *pdev;
1084 /* Allowed DMA channels for ISA (0 in 1088 /* Allowed DMA channels for ISA (0 indicates reserved) */
1085 unsigned char dma_channel_table[4] = 1089 unsigned char dma_channel_table[4] = { 5, 6, 7, 0 };
1086 struct Scsi_Host *shost; 1090 struct Scsi_Host *shost;
1087 struct hostdata *ha; 1091 struct hostdata *ha;
1088 char name[16]; 1092 char name[16];
1089 1093
1090 sprintf(name, "%s%d", driver_name, j) 1094 sprintf(name, "%s%d", driver_name, j);
1091 1095
1092 if (!request_region(port_base, REGION 1096 if (!request_region(port_base, REGION_SIZE, driver_name)) {
1093 #if defined(DEBUG_DETECT) 1097 #if defined(DEBUG_DETECT)
1094 printk("%s: address 0x%03lx i 1098 printk("%s: address 0x%03lx in use, skipping probe.\n", name,
1095 port_base); 1099 port_base);
1096 #endif 1100 #endif
1097 goto fail; 1101 goto fail;
1098 } 1102 }
1099 1103
1100 spin_lock_irq(&driver_lock); 1104 spin_lock_irq(&driver_lock);
1101 1105
1102 if (do_dma(port_base, 0, READ_CONFIG_ 1106 if (do_dma(port_base, 0, READ_CONFIG_PIO)) {
1103 #if defined(DEBUG_DETECT) 1107 #if defined(DEBUG_DETECT)
1104 printk("%s: detect, do_dma fa 1108 printk("%s: detect, do_dma failed at 0x%03lx.\n", name,
1105 port_base); 1109 port_base);
1106 #endif 1110 #endif
1107 goto freelock; 1111 goto freelock;
1108 } 1112 }
1109 1113
1110 /* Read the info structure */ 1114 /* Read the info structure */
1111 if (read_pio(port_base, (ushort *) & 1115 if (read_pio(port_base, (ushort *) & info, (ushort *) & info.ipad[0])) {
1112 #if defined(DEBUG_DETECT) 1116 #if defined(DEBUG_DETECT)
1113 printk("%s: detect, read_pio 1117 printk("%s: detect, read_pio failed at 0x%03lx.\n", name,
1114 port_base); 1118 port_base);
1115 #endif 1119 #endif
1116 goto freelock; 1120 goto freelock;
1117 } 1121 }
1118 1122
1119 info.data_len = DEV2H(info.data_len); 1123 info.data_len = DEV2H(info.data_len);
1120 info.sign = DEV2H(info.sign); 1124 info.sign = DEV2H(info.sign);
1121 info.cp_pad_len = DEV2H16(info.cp_pad 1125 info.cp_pad_len = DEV2H16(info.cp_pad_len);
1122 info.cp_len = DEV2H(info.cp_len); 1126 info.cp_len = DEV2H(info.cp_len);
1123 info.sp_len = DEV2H(info.sp_len); 1127 info.sp_len = DEV2H(info.sp_len);
1124 info.scatt_size = DEV2H16(info.scatt_ 1128 info.scatt_size = DEV2H16(info.scatt_size);
1125 info.queue_size = DEV2H16(info.queue_ 1129 info.queue_size = DEV2H16(info.queue_size);
1126 1130
1127 /* Check the controller "EATA" signat 1131 /* Check the controller "EATA" signature */
1128 if (info.sign != EATA_SIG_BE) { 1132 if (info.sign != EATA_SIG_BE) {
1129 #if defined(DEBUG_DETECT) 1133 #if defined(DEBUG_DETECT)
1130 printk("%s: signature 0x%04x 1134 printk("%s: signature 0x%04x discarded.\n", name, info.sign);
1131 #endif 1135 #endif
1132 goto freelock; 1136 goto freelock;
1133 } 1137 }
1134 1138
1135 if (info.data_len < EATA_2_0A_SIZE) { 1139 if (info.data_len < EATA_2_0A_SIZE) {
1136 printk 1140 printk
1137 ("%s: config structure si 1141 ("%s: config structure size (%d bytes) too short, detaching.\n",
1138 name, info.data_len); 1142 name, info.data_len);
1139 goto freelock; 1143 goto freelock;
1140 } else if (info.data_len == EATA_2_0A 1144 } else if (info.data_len == EATA_2_0A_SIZE)
1141 protocol_rev = 'A'; 1145 protocol_rev = 'A';
1142 else if (info.data_len == EATA_2_0B_S 1146 else if (info.data_len == EATA_2_0B_SIZE)
1143 protocol_rev = 'B'; 1147 protocol_rev = 'B';
1144 else 1148 else
1145 protocol_rev = 'C'; 1149 protocol_rev = 'C';
1146 1150
1147 if (protocol_rev != 'A' && info.forca 1151 if (protocol_rev != 'A' && info.forcaddr) {
1148 printk("%s: warning, port add 1152 printk("%s: warning, port address has been forced.\n", name);
1149 bus_type = "PCI"; 1153 bus_type = "PCI";
1150 is_pci = 1; 1154 is_pci = 1;
1151 subversion = ESA; 1155 subversion = ESA;
1152 } else if (port_base > MAX_EISA_ADDR 1156 } else if (port_base > MAX_EISA_ADDR
1153 || (protocol_rev == 'C' && 1157 || (protocol_rev == 'C' && info.pci)) {
1154 bus_type = "PCI"; 1158 bus_type = "PCI";
1155 is_pci = 1; 1159 is_pci = 1;
1156 subversion = ESA; 1160 subversion = ESA;
1157 } else if (port_base >= MIN_EISA_ADDR 1161 } else if (port_base >= MIN_EISA_ADDR
1158 || (protocol_rev == 'C' && 1162 || (protocol_rev == 'C' && info.eisa)) {
1159 bus_type = "EISA"; 1163 bus_type = "EISA";
1160 subversion = ESA; 1164 subversion = ESA;
1161 } else if (protocol_rev == 'C' && !in 1165 } else if (protocol_rev == 'C' && !info.eisa && !info.pci) {
1162 bus_type = "ISA"; 1166 bus_type = "ISA";
1163 subversion = ISA; 1167 subversion = ISA;
1164 } else if (port_base > MAX_ISA_ADDR) 1168 } else if (port_base > MAX_ISA_ADDR) {
1165 bus_type = "PCI"; 1169 bus_type = "PCI";
1166 is_pci = 1; 1170 is_pci = 1;
1167 subversion = ESA; 1171 subversion = ESA;
1168 } else { 1172 } else {
1169 bus_type = "ISA"; 1173 bus_type = "ISA";
1170 subversion = ISA; 1174 subversion = ISA;
1171 } 1175 }
1172 1176
1173 if (!info.haaval || info.ata) { 1177 if (!info.haaval || info.ata) {
1174 printk 1178 printk
1175 ("%s: address 0x%03lx, un 1179 ("%s: address 0x%03lx, unusable %s board (%d%d), detaching.\n",
1176 name, port_base, bus_typ 1180 name, port_base, bus_type, info.haaval, info.ata);
1177 goto freelock; 1181 goto freelock;
1178 } 1182 }
1179 1183
1180 if (info.drqvld) { 1184 if (info.drqvld) {
1181 if (subversion == ESA) 1185 if (subversion == ESA)
1182 printk("%s: warning, 1186 printk("%s: warning, weird %s board using DMA.\n", name,
1183 bus_type); 1187 bus_type);
1184 1188
1185 subversion = ISA; 1189 subversion = ISA;
1186 dma_channel = dma_channel_tab 1190 dma_channel = dma_channel_table[3 - info.drqx];
1187 } else { 1191 } else {
1188 if (subversion == ISA) 1192 if (subversion == ISA)
1189 printk("%s: warning, 1193 printk("%s: warning, weird %s board not using DMA.\n",
1190 name, bus_type 1194 name, bus_type);
1191 1195
1192 subversion = ESA; 1196 subversion = ESA;
1193 dma_channel = NO_DMA; 1197 dma_channel = NO_DMA;
1194 } 1198 }
1195 1199
1196 if (!info.dmasup) 1200 if (!info.dmasup)
1197 printk("%s: warning, DMA prot 1201 printk("%s: warning, DMA protocol support not asserted.\n",
1198 name); 1202 name);
1199 1203
1200 irq = info.irq; 1204 irq = info.irq;
1201 1205
1202 if (subversion == ESA && !info.irq_tr 1206 if (subversion == ESA && !info.irq_tr)
1203 printk 1207 printk
1204 ("%s: warning, LEVEL trig 1208 ("%s: warning, LEVEL triggering is suggested for IRQ %u.\n",
1205 name, irq); 1209 name, irq);
1206 1210
1207 if (is_pci) { 1211 if (is_pci) {
1208 pdev = get_pci_dev(port_base) 1212 pdev = get_pci_dev(port_base);
1209 if (!pdev) 1213 if (!pdev)
1210 printk 1214 printk
1211 ("%s: warning, fa 1215 ("%s: warning, failed to get pci_dev structure.\n",
1212 name); 1216 name);
1213 } else 1217 } else
1214 pdev = NULL; 1218 pdev = NULL;
1215 1219
1216 if (pdev && (irq != pdev->irq)) { 1220 if (pdev && (irq != pdev->irq)) {
1217 printk("%s: IRQ %u mapped to 1221 printk("%s: IRQ %u mapped to IO-APIC IRQ %u.\n", name, irq,
1218 pdev->irq); 1222 pdev->irq);
1219 irq = pdev->irq; 1223 irq = pdev->irq;
1220 } 1224 }
1221 1225
1222 /* Board detected, allocate its IRQ * 1226 /* Board detected, allocate its IRQ */
1223 if (request_irq(irq, do_interrupt_han 1227 if (request_irq(irq, do_interrupt_handler,
1224 IRQF_DISABLED | ((sub !! 1228 SA_INTERRUPT | ((subversion == ESA) ? SA_SHIRQ : 0),
1225 driver_name, (void *) 1229 driver_name, (void *)&sha[j])) {
1226 printk("%s: unable to allocat 1230 printk("%s: unable to allocate IRQ %u, detaching.\n", name,
1227 irq); 1231 irq);
1228 goto freelock; 1232 goto freelock;
1229 } 1233 }
1230 1234
1231 if (subversion == ISA && request_dma( 1235 if (subversion == ISA && request_dma(dma_channel, driver_name)) {
1232 printk("%s: unable to allocat 1236 printk("%s: unable to allocate DMA channel %u, detaching.\n",
1233 name, dma_channel); 1237 name, dma_channel);
1234 goto freeirq; 1238 goto freeirq;
1235 } 1239 }
1236 #if defined(FORCE_CONFIG) 1240 #if defined(FORCE_CONFIG)
1237 { 1241 {
1238 struct eata_config *cf; 1242 struct eata_config *cf;
1239 dma_addr_t cf_dma_addr; 1243 dma_addr_t cf_dma_addr;
1240 1244
1241 cf = pci_alloc_consistent(pde 1245 cf = pci_alloc_consistent(pdev, sizeof(struct eata_config),
1242 &cf 1246 &cf_dma_addr);
1243 1247
1244 if (!cf) { 1248 if (!cf) {
1245 printk 1249 printk
1246 ("%s: config, pci 1250 ("%s: config, pci_alloc_consistent failed, detaching.\n",
1247 name); 1251 name);
1248 goto freedma; 1252 goto freedma;
1249 } 1253 }
1250 1254
1251 /* Set board configuration */ 1255 /* Set board configuration */
1252 memset((char *)cf, 0, sizeof( 1256 memset((char *)cf, 0, sizeof(struct eata_config));
1253 cf->len = (ushort) H2DEV16((u 1257 cf->len = (ushort) H2DEV16((ushort) 510);
1254 cf->ocena = 1; 1258 cf->ocena = 1;
1255 1259
1256 if (do_dma(port_base, cf_dma_ 1260 if (do_dma(port_base, cf_dma_addr, SET_CONFIG_DMA)) {
1257 printk 1261 printk
1258 ("%s: busy timeou 1262 ("%s: busy timeout sending configuration, detaching.\n",
1259 name); 1263 name);
1260 pci_free_consistent(p 1264 pci_free_consistent(pdev, sizeof(struct eata_config),
1261 c 1265 cf, cf_dma_addr);
1262 goto freedma; 1266 goto freedma;
1263 } 1267 }
1264 1268
1265 } 1269 }
1266 #endif 1270 #endif
1267 1271
1268 spin_unlock_irq(&driver_lock); 1272 spin_unlock_irq(&driver_lock);
1269 sh[j] = shost = scsi_register(tpnt, s 1273 sh[j] = shost = scsi_register(tpnt, sizeof(struct hostdata));
1270 spin_lock_irq(&driver_lock); 1274 spin_lock_irq(&driver_lock);
1271 1275
1272 if (shost == NULL) { 1276 if (shost == NULL) {
1273 printk("%s: unable to registe 1277 printk("%s: unable to register host, detaching.\n", name);
1274 goto freedma; 1278 goto freedma;
1275 } 1279 }
1276 1280
1277 shost->io_port = port_base; 1281 shost->io_port = port_base;
1278 shost->unique_id = port_base; 1282 shost->unique_id = port_base;
1279 shost->n_io_port = REGION_SIZE; 1283 shost->n_io_port = REGION_SIZE;
1280 shost->dma_channel = dma_channel; 1284 shost->dma_channel = dma_channel;
1281 shost->irq = irq; 1285 shost->irq = irq;
1282 shost->sg_tablesize = (ushort) info.s 1286 shost->sg_tablesize = (ushort) info.scatt_size;
1283 shost->this_id = (ushort) info.host_a 1287 shost->this_id = (ushort) info.host_addr[3];
1284 shost->can_queue = (ushort) info.queu 1288 shost->can_queue = (ushort) info.queue_size;
1285 shost->cmd_per_lun = MAX_CMD_PER_LUN; 1289 shost->cmd_per_lun = MAX_CMD_PER_LUN;
1286 1290
1287 ha = (struct hostdata *)shost->hostda 1291 ha = (struct hostdata *)shost->hostdata;
1288 1292
1289 memset(ha, 0, sizeof(struct hostdata) 1293 memset(ha, 0, sizeof(struct hostdata));
1290 ha->subversion = subversion; 1294 ha->subversion = subversion;
1291 ha->protocol_rev = protocol_rev; 1295 ha->protocol_rev = protocol_rev;
1292 ha->is_pci = is_pci; 1296 ha->is_pci = is_pci;
1293 ha->pdev = pdev; 1297 ha->pdev = pdev;
1294 ha->board_number = j; 1298 ha->board_number = j;
1295 1299
1296 if (ha->subversion == ESA) 1300 if (ha->subversion == ESA)
1297 shost->unchecked_isa_dma = 0; 1301 shost->unchecked_isa_dma = 0;
1298 else { 1302 else {
1299 unsigned long flags; 1303 unsigned long flags;
1300 shost->unchecked_isa_dma = 1; 1304 shost->unchecked_isa_dma = 1;
1301 1305
1302 flags = claim_dma_lock(); 1306 flags = claim_dma_lock();
1303 disable_dma(dma_channel); 1307 disable_dma(dma_channel);
1304 clear_dma_ff(dma_channel); 1308 clear_dma_ff(dma_channel);
1305 set_dma_mode(dma_channel, DMA 1309 set_dma_mode(dma_channel, DMA_MODE_CASCADE);
1306 enable_dma(dma_channel); 1310 enable_dma(dma_channel);
1307 release_dma_lock(flags); 1311 release_dma_lock(flags);
1308 1312
1309 } 1313 }
1310 1314
1311 strcpy(ha->board_name, name); 1315 strcpy(ha->board_name, name);
1312 1316
1313 /* DPT PM2012 does not allow to detec 1317 /* DPT PM2012 does not allow to detect sg_tablesize correctly */
1314 if (shost->sg_tablesize > MAX_SGLIST 1318 if (shost->sg_tablesize > MAX_SGLIST || shost->sg_tablesize < 2) {
1315 printk("%s: detect, wrong n. 1319 printk("%s: detect, wrong n. of SG lists %d, fixed.\n",
1316 ha->board_name, shost- 1320 ha->board_name, shost->sg_tablesize);
1317 shost->sg_tablesize = MAX_SGL 1321 shost->sg_tablesize = MAX_SGLIST;
1318 } 1322 }
1319 1323
1320 /* DPT PM2012 does not allow to detec 1324 /* DPT PM2012 does not allow to detect can_queue correctly */
1321 if (shost->can_queue > MAX_MAILBOXES 1325 if (shost->can_queue > MAX_MAILBOXES || shost->can_queue < 2) {
1322 printk("%s: detect, wrong n. 1326 printk("%s: detect, wrong n. of mbox %d, fixed.\n",
1323 ha->board_name, shost- 1327 ha->board_name, shost->can_queue);
1324 shost->can_queue = MAX_MAILBO 1328 shost->can_queue = MAX_MAILBOXES;
1325 } 1329 }
1326 1330
1327 if (protocol_rev != 'A') { 1331 if (protocol_rev != 'A') {
1328 if (info.max_chan > 0 && info 1332 if (info.max_chan > 0 && info.max_chan < MAX_CHANNEL)
1329 shost->max_channel = 1333 shost->max_channel = info.max_chan;
1330 1334
1331 if (info.max_id > 7 && info.m 1335 if (info.max_id > 7 && info.max_id < MAX_TARGET)
1332 shost->max_id = info. 1336 shost->max_id = info.max_id + 1;
1333 1337
1334 if (info.large_sg && shost->s 1338 if (info.large_sg && shost->sg_tablesize == MAX_SGLIST)
1335 shost->sg_tablesize = 1339 shost->sg_tablesize = MAX_LARGE_SGLIST;
1336 } 1340 }
1337 1341
1338 if (protocol_rev == 'C') { 1342 if (protocol_rev == 'C') {
1339 if (info.max_lun > 7 && info. 1343 if (info.max_lun > 7 && info.max_lun < MAX_LUN)
1340 shost->max_lun = info 1344 shost->max_lun = info.max_lun + 1;
1341 } 1345 }
1342 1346
1343 if (dma_channel == NO_DMA) 1347 if (dma_channel == NO_DMA)
1344 sprintf(dma_name, "%s", "BMST 1348 sprintf(dma_name, "%s", "BMST");
1345 else 1349 else
1346 sprintf(dma_name, "DMA %u", d 1350 sprintf(dma_name, "DMA %u", dma_channel);
1347 1351
1348 spin_unlock_irq(&driver_lock); 1352 spin_unlock_irq(&driver_lock);
1349 1353
1350 for (i = 0; i < shost->can_queue; i++ 1354 for (i = 0; i < shost->can_queue; i++)
1351 ha->cp[i].cp_dma_addr = pci_m 1355 ha->cp[i].cp_dma_addr = pci_map_single(ha->pdev,
1352 1356 &ha->cp[i],
1353 1357 sizeof(struct mscp),
1354 1358 PCI_DMA_BIDIRECTIONAL);
1355 1359
1356 for (i = 0; i < shost->can_queue; i++ 1360 for (i = 0; i < shost->can_queue; i++) {
1357 size_t sz = shost->sg_tablesi 1361 size_t sz = shost->sg_tablesize *sizeof(struct sg_list);
1358 gfp_t gfp_mask = (shost->unch !! 1362 unsigned int gfp_mask = (shost->unchecked_isa_dma ? GFP_DMA : 0) | GFP_ATOMIC;
1359 ha->cp[i].sglist = kmalloc(sz 1363 ha->cp[i].sglist = kmalloc(sz, gfp_mask);
1360 if (!ha->cp[i].sglist) { 1364 if (!ha->cp[i].sglist) {
1361 printk 1365 printk
1362 ("%s: kmalloc SGl 1366 ("%s: kmalloc SGlist failed, mbox %d, detaching.\n",
1363 ha->board_name, 1367 ha->board_name, i);
1364 goto release; 1368 goto release;
1365 } 1369 }
1366 } 1370 }
1367 1371
1368 if (!(ha->sp_cpu_addr = pci_alloc_con 1372 if (!(ha->sp_cpu_addr = pci_alloc_consistent(ha->pdev,
1369 1373 sizeof(struct mssp),
1370 1374 &ha->sp_dma_addr))) {
1371 printk("%s: pci_alloc_consist 1375 printk("%s: pci_alloc_consistent failed, detaching.\n", ha->board_name);
1372 goto release; 1376 goto release;
1373 } 1377 }
1374 1378
1375 if (max_queue_depth > MAX_TAGGED_CMD_ 1379 if (max_queue_depth > MAX_TAGGED_CMD_PER_LUN)
1376 max_queue_depth = MAX_TAGGED_ 1380 max_queue_depth = MAX_TAGGED_CMD_PER_LUN;
1377 1381
1378 if (max_queue_depth < MAX_CMD_PER_LUN 1382 if (max_queue_depth < MAX_CMD_PER_LUN)
1379 max_queue_depth = MAX_CMD_PER 1383 max_queue_depth = MAX_CMD_PER_LUN;
1380 1384
1381 if (tag_mode != TAG_DISABLED && tag_m 1385 if (tag_mode != TAG_DISABLED && tag_mode != TAG_SIMPLE)
1382 tag_mode = TAG_ORDERED; 1386 tag_mode = TAG_ORDERED;
1383 1387
1384 if (j == 0) { 1388 if (j == 0) {
1385 printk 1389 printk
1386 ("EATA/DMA 2.0x: Copyrigh 1390 ("EATA/DMA 2.0x: Copyright (C) 1994-2003 Dario Ballabio.\n");
1387 printk 1391 printk
1388 ("%s config options -> tm 1392 ("%s config options -> tm:%d, lc:%c, mq:%d, rs:%c, et:%c, "
1389 "ip:%c, ep:%c, pp:%c.\n" 1393 "ip:%c, ep:%c, pp:%c.\n", driver_name, tag_mode,
1390 YESNO(linked_comm), max_ 1394 YESNO(linked_comm), max_queue_depth, YESNO(rev_scan),
1391 YESNO(ext_tran), YESNO(i 1395 YESNO(ext_tran), YESNO(isa_probe), YESNO(eisa_probe),
1392 YESNO(pci_probe)); 1396 YESNO(pci_probe));
1393 } 1397 }
1394 1398
1395 printk("%s: 2.0%c, %s 0x%03lx, IRQ %u 1399 printk("%s: 2.0%c, %s 0x%03lx, IRQ %u, %s, SG %d, MB %d.\n",
1396 ha->board_name, ha->protocol_r 1400 ha->board_name, ha->protocol_rev, bus_type,
1397 (unsigned long)shost->io_port, 1401 (unsigned long)shost->io_port, shost->irq, dma_name,
1398 shost->sg_tablesize, shost->ca 1402 shost->sg_tablesize, shost->can_queue);
1399 1403
1400 if (shost->max_id > 8 || shost->max_l 1404 if (shost->max_id > 8 || shost->max_lun > 8)
1401 printk 1405 printk
1402 ("%s: wide SCSI support e 1406 ("%s: wide SCSI support enabled, max_id %u, max_lun %u.\n",
1403 ha->board_name, shost->m 1407 ha->board_name, shost->max_id, shost->max_lun);
1404 1408
1405 for (i = 0; i <= shost->max_channel; 1409 for (i = 0; i <= shost->max_channel; i++)
1406 printk("%s: SCSI channel %u e 1410 printk("%s: SCSI channel %u enabled, host target ID %d.\n",
1407 ha->board_name, i, inf 1411 ha->board_name, i, info.host_addr[3 - i]);
1408 1412
1409 #if defined(DEBUG_DETECT) 1413 #if defined(DEBUG_DETECT)
1410 printk("%s: Vers. 0x%x, ocs %u, tar % 1414 printk("%s: Vers. 0x%x, ocs %u, tar %u, trnxfr %u, more %u, SYNC 0x%x, "
1411 "sec. %u, infol %d, cpl %d spl 1415 "sec. %u, infol %d, cpl %d spl %d.\n", name, info.version,
1412 info.ocsena, info.tarsup, info 1416 info.ocsena, info.tarsup, info.trnxfr, info.morsup, info.sync,
1413 info.second, info.data_len, in 1417 info.second, info.data_len, info.cp_len, info.sp_len);
1414 1418
1415 if (protocol_rev == 'B' || protocol_r 1419 if (protocol_rev == 'B' || protocol_rev == 'C')
1416 printk("%s: isaena %u, forcad 1420 printk("%s: isaena %u, forcaddr %u, max_id %u, max_chan %u, "
1417 "large_sg %u, res1 %u. 1421 "large_sg %u, res1 %u.\n", name, info.isaena,
1418 info.forcaddr, info.ma 1422 info.forcaddr, info.max_id, info.max_chan, info.large_sg,
1419 info.res1); 1423 info.res1);
1420 1424
1421 if (protocol_rev == 'C') 1425 if (protocol_rev == 'C')
1422 printk("%s: max_lun %u, m1 %u 1426 printk("%s: max_lun %u, m1 %u, idquest %u, pci %u, eisa %u, "
1423 "raidnum %u.\n", name, 1427 "raidnum %u.\n", name, info.max_lun, info.m1,
1424 info.idquest, info.pci 1428 info.idquest, info.pci, info.eisa, info.raidnum);
1425 #endif 1429 #endif
1426 1430
1427 if (ha->pdev) { 1431 if (ha->pdev) {
1428 pci_set_master(ha->pdev); 1432 pci_set_master(ha->pdev);
1429 if (pci_set_dma_mask(ha->pdev !! 1433 if (pci_set_dma_mask(ha->pdev, 0xffffffff))
1430 printk("%s: warning, 1434 printk("%s: warning, pci_set_dma_mask failed.\n",
1431 ha->board_name 1435 ha->board_name);
1432 } 1436 }
1433 1437
1434 return 1; 1438 return 1;
1435 1439
1436 freedma: 1440 freedma:
1437 if (subversion == ISA) 1441 if (subversion == ISA)
1438 free_dma(dma_channel); 1442 free_dma(dma_channel);
1439 freeirq: 1443 freeirq:
1440 free_irq(irq, &sha[j]); 1444 free_irq(irq, &sha[j]);
1441 freelock: 1445 freelock:
1442 spin_unlock_irq(&driver_lock); 1446 spin_unlock_irq(&driver_lock);
1443 release_region(port_base, REGION_SIZE 1447 release_region(port_base, REGION_SIZE);
1444 fail: 1448 fail:
1445 return 0; 1449 return 0;
1446 1450
1447 release: 1451 release:
1448 eata2x_release(shost); 1452 eata2x_release(shost);
1449 return 0; 1453 return 0;
1450 } 1454 }
1451 1455
1452 static void internal_setup(char *str, int *in 1456 static void internal_setup(char *str, int *ints)
1453 { 1457 {
1454 int i, argc = ints[0]; 1458 int i, argc = ints[0];
1455 char *cur = str, *pc; 1459 char *cur = str, *pc;
1456 1460
1457 if (argc > 0) { 1461 if (argc > 0) {
1458 if (argc > MAX_INT_PARAM) 1462 if (argc > MAX_INT_PARAM)
1459 argc = MAX_INT_PARAM; 1463 argc = MAX_INT_PARAM;
1460 1464
1461 for (i = 0; i < argc; i++) 1465 for (i = 0; i < argc; i++)
1462 io_port[i] = ints[i + 1466 io_port[i] = ints[i + 1];
1463 1467
1464 io_port[i] = 0; 1468 io_port[i] = 0;
1465 setup_done = 1; 1469 setup_done = 1;
1466 } 1470 }
1467 1471
1468 while (cur && (pc = strchr(cur, ':')) 1472 while (cur && (pc = strchr(cur, ':'))) {
1469 int val = 0, c = *++pc; 1473 int val = 0, c = *++pc;
1470 1474
1471 if (c == 'n' || c == 'N') 1475 if (c == 'n' || c == 'N')
1472 val = 0; 1476 val = 0;
1473 else if (c == 'y' || c == 'Y' 1477 else if (c == 'y' || c == 'Y')
1474 val = 1; 1478 val = 1;
1475 else 1479 else
1476 val = (int)simple_str 1480 val = (int)simple_strtoul(pc, NULL, 0);
1477 1481
1478 if (!strncmp(cur, "lc:", 3)) 1482 if (!strncmp(cur, "lc:", 3))
1479 linked_comm = val; 1483 linked_comm = val;
1480 else if (!strncmp(cur, "tm:", 1484 else if (!strncmp(cur, "tm:", 3))
1481 tag_mode = val; 1485 tag_mode = val;
1482 else if (!strncmp(cur, "tc:", 1486 else if (!strncmp(cur, "tc:", 3))
1483 tag_mode = val; 1487 tag_mode = val;
1484 else if (!strncmp(cur, "mq:", 1488 else if (!strncmp(cur, "mq:", 3))
1485 max_queue_depth = val 1489 max_queue_depth = val;
1486 else if (!strncmp(cur, "ls:", 1490 else if (!strncmp(cur, "ls:", 3))
1487 link_statistics = val 1491 link_statistics = val;
1488 else if (!strncmp(cur, "et:", 1492 else if (!strncmp(cur, "et:", 3))
1489 ext_tran = val; 1493 ext_tran = val;
1490 else if (!strncmp(cur, "rs:", 1494 else if (!strncmp(cur, "rs:", 3))
1491 rev_scan = val; 1495 rev_scan = val;
1492 else if (!strncmp(cur, "ip:", 1496 else if (!strncmp(cur, "ip:", 3))
1493 isa_probe = val; 1497 isa_probe = val;
1494 else if (!strncmp(cur, "ep:", 1498 else if (!strncmp(cur, "ep:", 3))
1495 eisa_probe = val; 1499 eisa_probe = val;
1496 else if (!strncmp(cur, "pp:", 1500 else if (!strncmp(cur, "pp:", 3))
1497 pci_probe = val; 1501 pci_probe = val;
1498 1502
1499 if ((cur = strchr(cur, ','))) 1503 if ((cur = strchr(cur, ',')))
1500 ++cur; 1504 ++cur;
1501 } 1505 }
1502 1506
1503 return; 1507 return;
1504 } 1508 }
1505 1509
1506 static int option_setup(char *str) 1510 static int option_setup(char *str)
1507 { 1511 {
1508 int ints[MAX_INT_PARAM]; 1512 int ints[MAX_INT_PARAM];
1509 char *cur = str; 1513 char *cur = str;
1510 int i = 1; 1514 int i = 1;
1511 1515
1512 while (cur && isdigit(*cur) && i <= M 1516 while (cur && isdigit(*cur) && i <= MAX_INT_PARAM) {
1513 ints[i++] = simple_strtoul(cu 1517 ints[i++] = simple_strtoul(cur, NULL, 0);
1514 1518
1515 if ((cur = strchr(cur, ',')) 1519 if ((cur = strchr(cur, ',')) != NULL)
1516 cur++; 1520 cur++;
1517 } 1521 }
1518 1522
1519 ints[0] = i - 1; 1523 ints[0] = i - 1;
1520 internal_setup(cur, ints); 1524 internal_setup(cur, ints);
1521 return 1; 1525 return 1;
1522 } 1526 }
1523 1527
1524 static void add_pci_ports(void) 1528 static void add_pci_ports(void)
1525 { 1529 {
1526 #if defined(CONFIG_PCI) 1530 #if defined(CONFIG_PCI)
1527 unsigned int addr, k; 1531 unsigned int addr, k;
1528 struct pci_dev *dev = NULL; 1532 struct pci_dev *dev = NULL;
1529 1533
1530 for (k = 0; k < MAX_PCI; k++) { 1534 for (k = 0; k < MAX_PCI; k++) {
1531 1535
1532 if (!(dev = pci_get_class(PCI 1536 if (!(dev = pci_get_class(PCI_CLASS_STORAGE_SCSI << 8, dev)))
1533 break; 1537 break;
1534 1538
1535 if (pci_enable_device(dev)) { 1539 if (pci_enable_device(dev)) {
1536 #if defined(DEBUG_PCI_DETECT) 1540 #if defined(DEBUG_PCI_DETECT)
1537 printk 1541 printk
1538 ("%s: detect, bus 1542 ("%s: detect, bus %d, devfn 0x%x, pci_enable_device failed.\n",
1539 driver_name, dev 1543 driver_name, dev->bus->number, dev->devfn);
1540 #endif 1544 #endif
1541 1545
1542 continue; 1546 continue;
1543 } 1547 }
1544 1548
1545 addr = pci_resource_start(dev 1549 addr = pci_resource_start(dev, 0);
1546 1550
1547 #if defined(DEBUG_PCI_DETECT) 1551 #if defined(DEBUG_PCI_DETECT)
1548 printk("%s: detect, seq. %d, 1552 printk("%s: detect, seq. %d, bus %d, devfn 0x%x, addr 0x%x.\n",
1549 driver_name, k, dev->b 1553 driver_name, k, dev->bus->number, dev->devfn, addr);
1550 #endif 1554 #endif
1551 1555
1552 /* Order addresses according 1556 /* Order addresses according to rev_scan value */
1553 io_port[MAX_INT_PARAM + (rev_ 1557 io_port[MAX_INT_PARAM + (rev_scan ? (MAX_PCI - k) : (1 + k))] =
1554 addr + PCI_BASE_ADDRESS_0 1558 addr + PCI_BASE_ADDRESS_0;
1555 } 1559 }
1556 1560
1557 pci_dev_put(dev); 1561 pci_dev_put(dev);
1558 #endif /* end CONFIG 1562 #endif /* end CONFIG_PCI */
1559 } 1563 }
1560 1564
1561 static int eata2x_detect(struct scsi_host_tem 1565 static int eata2x_detect(struct scsi_host_template *tpnt)
1562 { 1566 {
1563 unsigned int j = 0, k; 1567 unsigned int j = 0, k;
1564 1568
1565 tpnt->proc_name = "eata2x"; 1569 tpnt->proc_name = "eata2x";
1566 1570
1567 if (strlen(boot_options)) 1571 if (strlen(boot_options))
1568 option_setup(boot_options); 1572 option_setup(boot_options);
1569 1573
1570 #if defined(MODULE) 1574 #if defined(MODULE)
1571 /* io_port could have been modified w 1575 /* io_port could have been modified when loading as a module */
1572 if (io_port[0] != SKIP) { 1576 if (io_port[0] != SKIP) {
1573 setup_done = 1; 1577 setup_done = 1;
1574 io_port[MAX_INT_PARAM] = 0; 1578 io_port[MAX_INT_PARAM] = 0;
1575 } 1579 }
1576 #endif 1580 #endif
1577 1581
1578 for (k = MAX_INT_PARAM; io_port[k]; k 1582 for (k = MAX_INT_PARAM; io_port[k]; k++)
1579 if (io_port[k] == SKIP) 1583 if (io_port[k] == SKIP)
1580 continue; 1584 continue;
1581 else if (io_port[k] <= MAX_IS 1585 else if (io_port[k] <= MAX_ISA_ADDR) {
1582 if (!isa_probe) 1586 if (!isa_probe)
1583 io_port[k] = 1587 io_port[k] = SKIP;
1584 } else if (io_port[k] >= MIN_ 1588 } else if (io_port[k] >= MIN_EISA_ADDR
1585 && io_port[k] <= M 1589 && io_port[k] <= MAX_EISA_ADDR) {
1586 if (!eisa_probe) 1590 if (!eisa_probe)
1587 io_port[k] = 1591 io_port[k] = SKIP;
1588 } 1592 }
1589 1593
1590 if (pci_probe) { 1594 if (pci_probe) {
1591 if (!setup_done) 1595 if (!setup_done)
1592 add_pci_ports(); 1596 add_pci_ports();
1593 else 1597 else
1594 enable_pci_ports(); 1598 enable_pci_ports();
1595 } 1599 }
1596 1600
1597 for (k = 0; io_port[k]; k++) { 1601 for (k = 0; io_port[k]; k++) {
1598 1602
1599 if (io_port[k] == SKIP) 1603 if (io_port[k] == SKIP)
1600 continue; 1604 continue;
1601 1605
1602 if (j < MAX_BOARDS && port_de 1606 if (j < MAX_BOARDS && port_detect(io_port[k], j, tpnt))
1603 j++; 1607 j++;
1604 } 1608 }
1605 1609
1606 num_boards = j; 1610 num_boards = j;
1607 return j; 1611 return j;
1608 } 1612 }
1609 1613
1610 static void map_dma(unsigned int i, struct ho 1614 static void map_dma(unsigned int i, struct hostdata *ha)
1611 { 1615 {
1612 unsigned int k, pci_dir; !! 1616 unsigned int k, count, pci_dir;
1613 int count; !! 1617 struct scatterlist *sgpnt;
1614 struct scatterlist *sg; <<
1615 struct mscp *cpp; 1618 struct mscp *cpp;
1616 struct scsi_cmnd *SCpnt; 1619 struct scsi_cmnd *SCpnt;
1617 1620
1618 cpp = &ha->cp[i]; 1621 cpp = &ha->cp[i];
1619 SCpnt = cpp->SCpnt; 1622 SCpnt = cpp->SCpnt;
1620 pci_dir = SCpnt->sc_data_direction; 1623 pci_dir = SCpnt->sc_data_direction;
1621 1624
1622 if (SCpnt->sense_buffer) 1625 if (SCpnt->sense_buffer)
1623 cpp->sense_addr = 1626 cpp->sense_addr =
1624 H2DEV(pci_map_single(ha-> 1627 H2DEV(pci_map_single(ha->pdev, SCpnt->sense_buffer,
1625 SCSI_SENSE_BUFFERS !! 1628 sizeof SCpnt->sense_buffer, PCI_DMA_FROMDEVICE));
>> 1629
>> 1630 cpp->sense_len = sizeof SCpnt->sense_buffer;
>> 1631
>> 1632 if (!SCpnt->use_sg) {
1626 1633
1627 cpp->sense_len = SCSI_SENSE_BUFFERSIZ !! 1634 /* If we get here with PCI_DMA_NONE, pci_map_single triggers a BUG() */
>> 1635 if (!SCpnt->request_bufflen)
>> 1636 pci_dir = PCI_DMA_BIDIRECTIONAL;
1628 1637
1629 if (!scsi_sg_count(SCpnt)) { !! 1638 if (SCpnt->request_buffer)
1630 cpp->data_len = 0; !! 1639 cpp->data_address = H2DEV(pci_map_single(ha->pdev,
>> 1640 SCpnt->
>> 1641 request_buffer,
>> 1642 SCpnt->
>> 1643 request_bufflen,
>> 1644 pci_dir));
>> 1645
>> 1646 cpp->data_len = H2DEV(SCpnt->request_bufflen);
1631 return; 1647 return;
1632 } 1648 }
1633 1649
1634 count = pci_map_sg(ha->pdev, scsi_sgl !! 1650 sgpnt = (struct scatterlist *)SCpnt->request_buffer;
1635 pci_dir); !! 1651 count = pci_map_sg(ha->pdev, sgpnt, SCpnt->use_sg, pci_dir);
1636 BUG_ON(!count); !! 1652
1637 !! 1653 for (k = 0; k < count; k++) {
1638 scsi_for_each_sg(SCpnt, sg, count, k) !! 1654 cpp->sglist[k].address = H2DEV(sg_dma_address(&sgpnt[k]));
1639 cpp->sglist[k].address = H2DE !! 1655 cpp->sglist[k].num_bytes = H2DEV(sg_dma_len(&sgpnt[k]));
1640 cpp->sglist[k].num_bytes = H2 <<
1641 } 1656 }
1642 1657
1643 cpp->sg = 1; 1658 cpp->sg = 1;
1644 cpp->data_address = H2DEV(pci_map_sin 1659 cpp->data_address = H2DEV(pci_map_single(ha->pdev, cpp->sglist,
1645 !! 1660 SCpnt->use_sg *
1646 1661 sizeof(struct sg_list),
1647 1662 pci_dir));
1648 cpp->data_len = H2DEV((scsi_sg_count( !! 1663 cpp->data_len = H2DEV((SCpnt->use_sg * sizeof(struct sg_list)));
1649 } 1664 }
1650 1665
1651 static void unmap_dma(unsigned int i, struct 1666 static void unmap_dma(unsigned int i, struct hostdata *ha)
1652 { 1667 {
1653 unsigned int pci_dir; 1668 unsigned int pci_dir;
1654 struct mscp *cpp; 1669 struct mscp *cpp;
1655 struct scsi_cmnd *SCpnt; 1670 struct scsi_cmnd *SCpnt;
1656 1671
1657 cpp = &ha->cp[i]; 1672 cpp = &ha->cp[i];
1658 SCpnt = cpp->SCpnt; 1673 SCpnt = cpp->SCpnt;
1659 pci_dir = SCpnt->sc_data_direction; 1674 pci_dir = SCpnt->sc_data_direction;
1660 1675
1661 if (DEV2H(cpp->sense_addr)) 1676 if (DEV2H(cpp->sense_addr))
1662 pci_unmap_single(ha->pdev, DE 1677 pci_unmap_single(ha->pdev, DEV2H(cpp->sense_addr),
1663 DEV2H(cpp->s 1678 DEV2H(cpp->sense_len), PCI_DMA_FROMDEVICE);
1664 1679
1665 if (scsi_sg_count(SCpnt)) !! 1680 if (SCpnt->use_sg)
1666 pci_unmap_sg(ha->pdev, scsi_s !! 1681 pci_unmap_sg(ha->pdev, SCpnt->request_buffer, SCpnt->use_sg,
1667 pci_dir); 1682 pci_dir);
1668 1683
1669 if (!DEV2H(cpp->data_len)) 1684 if (!DEV2H(cpp->data_len))
1670 pci_dir = PCI_DMA_BIDIRECTION 1685 pci_dir = PCI_DMA_BIDIRECTIONAL;
1671 1686
1672 if (DEV2H(cpp->data_address)) 1687 if (DEV2H(cpp->data_address))
1673 pci_unmap_single(ha->pdev, DE 1688 pci_unmap_single(ha->pdev, DEV2H(cpp->data_address),
1674 DEV2H(cpp->d 1689 DEV2H(cpp->data_len), pci_dir);
1675 } 1690 }
1676 1691
1677 static void sync_dma(unsigned int i, struct h 1692 static void sync_dma(unsigned int i, struct hostdata *ha)
1678 { 1693 {
1679 unsigned int pci_dir; 1694 unsigned int pci_dir;
1680 struct mscp *cpp; 1695 struct mscp *cpp;
1681 struct scsi_cmnd *SCpnt; 1696 struct scsi_cmnd *SCpnt;
1682 1697
1683 cpp = &ha->cp[i]; 1698 cpp = &ha->cp[i];
1684 SCpnt = cpp->SCpnt; 1699 SCpnt = cpp->SCpnt;
1685 pci_dir = SCpnt->sc_data_direction; 1700 pci_dir = SCpnt->sc_data_direction;
1686 1701
1687 if (DEV2H(cpp->sense_addr)) 1702 if (DEV2H(cpp->sense_addr))
1688 pci_dma_sync_single_for_cpu(h 1703 pci_dma_sync_single_for_cpu(ha->pdev, DEV2H(cpp->sense_addr),
1689 D 1704 DEV2H(cpp->sense_len),
1690 P 1705 PCI_DMA_FROMDEVICE);
1691 1706
1692 if (scsi_sg_count(SCpnt)) !! 1707 if (SCpnt->use_sg)
1693 pci_dma_sync_sg_for_cpu(ha->p !! 1708 pci_dma_sync_sg_for_cpu(ha->pdev, SCpnt->request_buffer,
1694 scsi_ !! 1709 SCpnt->use_sg, pci_dir);
1695 1710
1696 if (!DEV2H(cpp->data_len)) 1711 if (!DEV2H(cpp->data_len))
1697 pci_dir = PCI_DMA_BIDIRECTION 1712 pci_dir = PCI_DMA_BIDIRECTIONAL;
1698 1713
1699 if (DEV2H(cpp->data_address)) 1714 if (DEV2H(cpp->data_address))
1700 pci_dma_sync_single_for_cpu(h 1715 pci_dma_sync_single_for_cpu(ha->pdev,
1701 D 1716 DEV2H(cpp->data_address),
1702 D 1717 DEV2H(cpp->data_len), pci_dir);
1703 } 1718 }
1704 1719
1705 static void scsi_to_dev_dir(unsigned int i, s 1720 static void scsi_to_dev_dir(unsigned int i, struct hostdata *ha)
1706 { 1721 {
1707 unsigned int k; 1722 unsigned int k;
1708 1723
1709 static const unsigned char data_out_c 1724 static const unsigned char data_out_cmds[] = {
1710 0x0a, 0x2a, 0x15, 0x55, 0x04, 1725 0x0a, 0x2a, 0x15, 0x55, 0x04, 0x07, 0x18, 0x1d, 0x24, 0x2e,
1711 0x30, 0x31, 0x32, 0x38, 0x39, 1726 0x30, 0x31, 0x32, 0x38, 0x39, 0x3a, 0x3b, 0x3d, 0x3f, 0x40,
1712 0x41, 0x4c, 0xaa, 0xae, 0xb0, 1727 0x41, 0x4c, 0xaa, 0xae, 0xb0, 0xb1, 0xb2, 0xb6, 0xea, 0x1b, 0x5d
1713 }; 1728 };
1714 1729
1715 static const unsigned char data_none_ 1730 static const unsigned char data_none_cmds[] = {
1716 0x01, 0x0b, 0x10, 0x11, 0x13, 1731 0x01, 0x0b, 0x10, 0x11, 0x13, 0x16, 0x17, 0x19, 0x2b, 0x1e,
1717 0x2c, 0xac, 0x2f, 0xaf, 0x33, 1732 0x2c, 0xac, 0x2f, 0xaf, 0x33, 0xb3, 0x35, 0x36, 0x45, 0x47,
1718 0x48, 0x49, 0xa9, 0x4b, 0xa5, 1733 0x48, 0x49, 0xa9, 0x4b, 0xa5, 0xa6, 0xb5, 0x00
1719 }; 1734 };
1720 1735
1721 struct mscp *cpp; 1736 struct mscp *cpp;
1722 struct scsi_cmnd *SCpnt; 1737 struct scsi_cmnd *SCpnt;
1723 1738
1724 cpp = &ha->cp[i]; 1739 cpp = &ha->cp[i];
1725 SCpnt = cpp->SCpnt; 1740 SCpnt = cpp->SCpnt;
1726 1741
1727 if (SCpnt->sc_data_direction == DMA_F 1742 if (SCpnt->sc_data_direction == DMA_FROM_DEVICE) {
1728 cpp->din = 1; 1743 cpp->din = 1;
1729 cpp->dout = 0; 1744 cpp->dout = 0;
1730 return; 1745 return;
1731 } else if (SCpnt->sc_data_direction = 1746 } else if (SCpnt->sc_data_direction == DMA_TO_DEVICE) {
1732 cpp->din = 0; 1747 cpp->din = 0;
1733 cpp->dout = 1; 1748 cpp->dout = 1;
1734 return; 1749 return;
1735 } else if (SCpnt->sc_data_direction = 1750 } else if (SCpnt->sc_data_direction == DMA_NONE) {
1736 cpp->din = 0; 1751 cpp->din = 0;
1737 cpp->dout = 0; 1752 cpp->dout = 0;
1738 return; 1753 return;
1739 } 1754 }
1740 1755
1741 if (SCpnt->sc_data_direction != DMA_B 1756 if (SCpnt->sc_data_direction != DMA_BIDIRECTIONAL)
1742 panic("%s: qcomm, invalid SCp 1757 panic("%s: qcomm, invalid SCpnt->sc_data_direction.\n",
1743 ha->board_nam 1758 ha->board_name);
1744 1759
1745 for (k = 0; k < ARRAY_SIZE(data_out_c 1760 for (k = 0; k < ARRAY_SIZE(data_out_cmds); k++)
1746 if (SCpnt->cmnd[0] == data_ou 1761 if (SCpnt->cmnd[0] == data_out_cmds[k]) {
1747 cpp->dout = 1; 1762 cpp->dout = 1;
1748 break; 1763 break;
1749 } 1764 }
1750 1765
1751 if ((cpp->din = !cpp->dout)) 1766 if ((cpp->din = !cpp->dout))
1752 for (k = 0; k < ARRAY_SIZE(da 1767 for (k = 0; k < ARRAY_SIZE(data_none_cmds); k++)
1753 if (SCpnt->cmnd[0] == 1768 if (SCpnt->cmnd[0] == data_none_cmds[k]) {
1754 cpp->din = 0; 1769 cpp->din = 0;
1755 break; 1770 break;
1756 } 1771 }
1757 1772
1758 } 1773 }
1759 1774
1760 static int eata2x_queuecommand(struct scsi_cm 1775 static int eata2x_queuecommand(struct scsi_cmnd *SCpnt,
1761 void (*done) ( 1776 void (*done) (struct scsi_cmnd *))
1762 { 1777 {
1763 struct Scsi_Host *shost = SCpnt->devi 1778 struct Scsi_Host *shost = SCpnt->device->host;
1764 struct hostdata *ha = (struct hostdat 1779 struct hostdata *ha = (struct hostdata *)shost->hostdata;
1765 unsigned int i, k; 1780 unsigned int i, k;
1766 struct mscp *cpp; 1781 struct mscp *cpp;
1767 1782
1768 if (SCpnt->host_scribble) 1783 if (SCpnt->host_scribble)
1769 panic("%s: qcomm, pid %ld, SC 1784 panic("%s: qcomm, pid %ld, SCpnt %p already active.\n",
1770 ha->board_name, SCpnt-> !! 1785 ha->board_name, SCpnt->pid, SCpnt);
1771 1786
1772 /* i is the mailbox number, look for 1787 /* i is the mailbox number, look for the first free mailbox
1773 starting from last_cp_used */ 1788 starting from last_cp_used */
1774 i = ha->last_cp_used + 1; 1789 i = ha->last_cp_used + 1;
1775 1790
1776 for (k = 0; k < shost->can_queue; k++ 1791 for (k = 0; k < shost->can_queue; k++, i++) {
1777 if (i >= shost->can_queue) 1792 if (i >= shost->can_queue)
1778 i = 0; 1793 i = 0;
1779 if (ha->cp_stat[i] == FREE) { 1794 if (ha->cp_stat[i] == FREE) {
1780 ha->last_cp_used = i; 1795 ha->last_cp_used = i;
1781 break; 1796 break;
1782 } 1797 }
1783 } 1798 }
1784 1799
1785 if (k == shost->can_queue) { 1800 if (k == shost->can_queue) {
1786 printk("%s: qcomm, no free ma 1801 printk("%s: qcomm, no free mailbox.\n", ha->board_name);
1787 return 1; 1802 return 1;
1788 } 1803 }
1789 1804
1790 /* Set pointer to control packet stru 1805 /* Set pointer to control packet structure */
1791 cpp = &ha->cp[i]; 1806 cpp = &ha->cp[i];
1792 1807
1793 memset(cpp, 0, sizeof(struct mscp) - 1808 memset(cpp, 0, sizeof(struct mscp) - CP_TAIL_SIZE);
1794 1809
1795 /* Set pointer to status packet struc 1810 /* Set pointer to status packet structure, Big Endian format */
1796 cpp->sp_dma_addr = H2DEV(ha->sp_dma_a 1811 cpp->sp_dma_addr = H2DEV(ha->sp_dma_addr);
1797 1812
1798 SCpnt->scsi_done = done; 1813 SCpnt->scsi_done = done;
1799 cpp->cpp_index = i; 1814 cpp->cpp_index = i;
1800 SCpnt->host_scribble = (unsigned char 1815 SCpnt->host_scribble = (unsigned char *)&cpp->cpp_index;
1801 1816
1802 if (do_trace) 1817 if (do_trace)
1803 scmd_printk(KERN_INFO, SCpnt, !! 1818 printk("%s: qcomm, mbox %d, target %d.%d:%d, pid %ld.\n",
1804 "qcomm, mbox %d, pid !! 1819 ha->board_name, i, SCpnt->device->channel, SCpnt->device->id,
>> 1820 SCpnt->device->lun, SCpnt->pid);
1805 1821
1806 cpp->reqsen = 1; 1822 cpp->reqsen = 1;
1807 cpp->dispri = 1; 1823 cpp->dispri = 1;
1808 #if 0 1824 #if 0
1809 if (SCpnt->device->type == TYPE_TAPE) 1825 if (SCpnt->device->type == TYPE_TAPE)
1810 cpp->hbaci = 1; 1826 cpp->hbaci = 1;
1811 #endif 1827 #endif
1812 cpp->one = 1; 1828 cpp->one = 1;
1813 cpp->channel = SCpnt->device->channel 1829 cpp->channel = SCpnt->device->channel;
1814 cpp->target = SCpnt->device->id; 1830 cpp->target = SCpnt->device->id;
1815 cpp->lun = SCpnt->device->lun; 1831 cpp->lun = SCpnt->device->lun;
1816 cpp->SCpnt = SCpnt; 1832 cpp->SCpnt = SCpnt;
1817 memcpy(cpp->cdb, SCpnt->cmnd, SCpnt-> 1833 memcpy(cpp->cdb, SCpnt->cmnd, SCpnt->cmd_len);
1818 1834
1819 /* Use data transfer direction SCpnt- 1835 /* Use data transfer direction SCpnt->sc_data_direction */
1820 scsi_to_dev_dir(i, ha); 1836 scsi_to_dev_dir(i, ha);
1821 1837
1822 /* Map DMA buffers and SG list */ 1838 /* Map DMA buffers and SG list */
1823 map_dma(i, ha); 1839 map_dma(i, ha);
1824 1840
1825 if (linked_comm && SCpnt->device->que 1841 if (linked_comm && SCpnt->device->queue_depth > 2
1826 && TLDEV(SCpnt->device->type)) { 1842 && TLDEV(SCpnt->device->type)) {
1827 ha->cp_stat[i] = READY; 1843 ha->cp_stat[i] = READY;
1828 flush_dev(SCpnt->device, blk_ !! 1844 flush_dev(SCpnt->device, SCpnt->request->sector, ha, 0);
1829 return 0; 1845 return 0;
1830 } 1846 }
1831 1847
1832 /* Send control packet to the board * 1848 /* Send control packet to the board */
1833 if (do_dma(shost->io_port, cpp->cp_dm 1849 if (do_dma(shost->io_port, cpp->cp_dma_addr, SEND_CP_DMA)) {
1834 unmap_dma(i, ha); 1850 unmap_dma(i, ha);
1835 SCpnt->host_scribble = NULL; 1851 SCpnt->host_scribble = NULL;
1836 scmd_printk(KERN_INFO, SCpnt, !! 1852 printk("%s: qcomm, target %d.%d:%d, pid %ld, adapter busy.\n",
1837 "qcomm, pid %ld, adap !! 1853 ha->board_name, SCpnt->device->channel, SCpnt->device->id,
>> 1854 SCpnt->device->lun, SCpnt->pid);
1838 return 1; 1855 return 1;
1839 } 1856 }
1840 1857
1841 ha->cp_stat[i] = IN_USE; 1858 ha->cp_stat[i] = IN_USE;
1842 return 0; 1859 return 0;
1843 } 1860 }
1844 1861
1845 static int eata2x_eh_abort(struct scsi_cmnd * 1862 static int eata2x_eh_abort(struct scsi_cmnd *SCarg)
1846 { 1863 {
1847 struct Scsi_Host *shost = SCarg->devi 1864 struct Scsi_Host *shost = SCarg->device->host;
1848 struct hostdata *ha = (struct hostdat 1865 struct hostdata *ha = (struct hostdata *)shost->hostdata;
1849 unsigned int i; 1866 unsigned int i;
1850 1867
1851 if (SCarg->host_scribble == NULL) { 1868 if (SCarg->host_scribble == NULL) {
1852 scmd_printk(KERN_INFO, SCarg, !! 1869 printk("%s: abort, target %d.%d:%d, pid %ld inactive.\n",
1853 "abort, pid %ld inact !! 1870 ha->board_name, SCarg->device->channel, SCarg->device->id,
>> 1871 SCarg->device->lun, SCarg->pid);
1854 return SUCCESS; 1872 return SUCCESS;
1855 } 1873 }
1856 1874
1857 i = *(unsigned int *)SCarg->host_scri 1875 i = *(unsigned int *)SCarg->host_scribble;
1858 scmd_printk(KERN_WARNING, SCarg, !! 1876 printk("%s: abort, mbox %d, target %d.%d:%d, pid %ld.\n",
1859 "abort, mbox %d, pid %ld.\n", !! 1877 ha->board_name, i, SCarg->device->channel, SCarg->device->id,
>> 1878 SCarg->device->lun, SCarg->pid);
1860 1879
1861 if (i >= shost->can_queue) 1880 if (i >= shost->can_queue)
1862 panic("%s: abort, invalid SCa 1881 panic("%s: abort, invalid SCarg->host_scribble.\n", ha->board_name);
1863 1882
1864 if (wait_on_busy(shost->io_port, MAXL 1883 if (wait_on_busy(shost->io_port, MAXLOOP)) {
1865 printk("%s: abort, timeout er 1884 printk("%s: abort, timeout error.\n", ha->board_name);
1866 return FAILED; 1885 return FAILED;
1867 } 1886 }
1868 1887
1869 if (ha->cp_stat[i] == FREE) { 1888 if (ha->cp_stat[i] == FREE) {
1870 printk("%s: abort, mbox %d is 1889 printk("%s: abort, mbox %d is free.\n", ha->board_name, i);
1871 return SUCCESS; 1890 return SUCCESS;
1872 } 1891 }
1873 1892
1874 if (ha->cp_stat[i] == IN_USE) { 1893 if (ha->cp_stat[i] == IN_USE) {
1875 printk("%s: abort, mbox %d is 1894 printk("%s: abort, mbox %d is in use.\n", ha->board_name, i);
1876 1895
1877 if (SCarg != ha->cp[i].SCpnt) 1896 if (SCarg != ha->cp[i].SCpnt)
1878 panic("%s: abort, mbo 1897 panic("%s: abort, mbox %d, SCarg %p, cp SCpnt %p.\n",
1879 ha->board_name, 1898 ha->board_name, i, SCarg, ha->cp[i].SCpnt);
1880 1899
1881 if (inb(shost->io_port + REG_ 1900 if (inb(shost->io_port + REG_AUX_STATUS) & IRQ_ASSERTED)
1882 printk("%s: abort, mb 1901 printk("%s: abort, mbox %d, interrupt pending.\n",
1883 ha->board_name 1902 ha->board_name, i);
1884 1903
>> 1904 if (SCarg->eh_state == SCSI_STATE_TIMEOUT) {
>> 1905 unmap_dma(i, ha);
>> 1906 SCarg->host_scribble = NULL;
>> 1907 ha->cp_stat[i] = FREE;
>> 1908 printk
>> 1909 ("%s, abort, mbox %d, eh_state timeout, pid %ld.\n",
>> 1910 ha->board_name, i, SCarg->pid);
>> 1911 return SUCCESS;
>> 1912 }
>> 1913
1885 return FAILED; 1914 return FAILED;
1886 } 1915 }
1887 1916
1888 if (ha->cp_stat[i] == IN_RESET) { 1917 if (ha->cp_stat[i] == IN_RESET) {
1889 printk("%s: abort, mbox %d is 1918 printk("%s: abort, mbox %d is in reset.\n", ha->board_name, i);
1890 return FAILED; 1919 return FAILED;
1891 } 1920 }
1892 1921
1893 if (ha->cp_stat[i] == LOCKED) { 1922 if (ha->cp_stat[i] == LOCKED) {
1894 printk("%s: abort, mbox %d is 1923 printk("%s: abort, mbox %d is locked.\n", ha->board_name, i);
1895 return SUCCESS; 1924 return SUCCESS;
1896 } 1925 }
1897 1926
1898 if (ha->cp_stat[i] == READY || ha->cp 1927 if (ha->cp_stat[i] == READY || ha->cp_stat[i] == ABORTING) {
1899 unmap_dma(i, ha); 1928 unmap_dma(i, ha);
1900 SCarg->result = DID_ABORT << 1929 SCarg->result = DID_ABORT << 16;
1901 SCarg->host_scribble = NULL; 1930 SCarg->host_scribble = NULL;
1902 ha->cp_stat[i] = FREE; 1931 ha->cp_stat[i] = FREE;
1903 printk("%s, abort, mbox %d re 1932 printk("%s, abort, mbox %d ready, DID_ABORT, pid %ld done.\n",
1904 ha->board_name, i, SCa !! 1933 ha->board_name, i, SCarg->pid);
1905 SCarg->scsi_done(SCarg); 1934 SCarg->scsi_done(SCarg);
1906 return SUCCESS; 1935 return SUCCESS;
1907 } 1936 }
1908 1937
1909 panic("%s: abort, mbox %d, invalid cp 1938 panic("%s: abort, mbox %d, invalid cp_stat.\n", ha->board_name, i);
1910 } 1939 }
1911 1940
1912 static int eata2x_eh_host_reset(struct scsi_c 1941 static int eata2x_eh_host_reset(struct scsi_cmnd *SCarg)
1913 { 1942 {
1914 unsigned int i, time, k, c, limit = 0 1943 unsigned int i, time, k, c, limit = 0;
1915 int arg_done = 0; 1944 int arg_done = 0;
1916 struct scsi_cmnd *SCpnt; 1945 struct scsi_cmnd *SCpnt;
1917 struct Scsi_Host *shost = SCarg->devi 1946 struct Scsi_Host *shost = SCarg->device->host;
1918 struct hostdata *ha = (struct hostdat 1947 struct hostdata *ha = (struct hostdata *)shost->hostdata;
1919 1948
1920 scmd_printk(KERN_INFO, SCarg, !! 1949 printk("%s: reset, enter, target %d.%d:%d, pid %ld.\n",
1921 "reset, enter, pid %ld.\n", S !! 1950 ha->board_name, SCarg->device->channel, SCarg->device->id,
1922 !! 1951 SCarg->device->lun, SCarg->pid);
1923 spin_lock_irq(shost->host_lock); <<
1924 1952
1925 if (SCarg->host_scribble == NULL) 1953 if (SCarg->host_scribble == NULL)
1926 printk("%s: reset, pid %ld in !! 1954 printk("%s: reset, pid %ld inactive.\n", ha->board_name, SCarg->pid);
1927 1955
1928 if (ha->in_reset) { 1956 if (ha->in_reset) {
1929 printk("%s: reset, exit, alre 1957 printk("%s: reset, exit, already in reset.\n", ha->board_name);
1930 spin_unlock_irq(shost->host_l <<
1931 return FAILED; 1958 return FAILED;
1932 } 1959 }
1933 1960
1934 if (wait_on_busy(shost->io_port, MAXL 1961 if (wait_on_busy(shost->io_port, MAXLOOP)) {
1935 printk("%s: reset, exit, time 1962 printk("%s: reset, exit, timeout error.\n", ha->board_name);
1936 spin_unlock_irq(shost->host_l <<
1937 return FAILED; 1963 return FAILED;
1938 } 1964 }
1939 1965
1940 ha->retries = 0; 1966 ha->retries = 0;
1941 1967
1942 for (c = 0; c <= shost->max_channel; 1968 for (c = 0; c <= shost->max_channel; c++)
1943 for (k = 0; k < shost->max_id 1969 for (k = 0; k < shost->max_id; k++) {
1944 ha->target_redo[k][c] 1970 ha->target_redo[k][c] = 1;
1945 ha->target_to[k][c] = 1971 ha->target_to[k][c] = 0;
1946 } 1972 }
1947 1973
1948 for (i = 0; i < shost->can_queue; i++ 1974 for (i = 0; i < shost->can_queue; i++) {
1949 1975
1950 if (ha->cp_stat[i] == FREE) 1976 if (ha->cp_stat[i] == FREE)
1951 continue; 1977 continue;
1952 1978
1953 if (ha->cp_stat[i] == LOCKED) 1979 if (ha->cp_stat[i] == LOCKED) {
1954 ha->cp_stat[i] = FREE 1980 ha->cp_stat[i] = FREE;
1955 printk("%s: reset, lo 1981 printk("%s: reset, locked mbox %d forced free.\n",
1956 ha->board_name 1982 ha->board_name, i);
1957 continue; 1983 continue;
1958 } 1984 }
1959 1985
1960 if (!(SCpnt = ha->cp[i].SCpnt 1986 if (!(SCpnt = ha->cp[i].SCpnt))
1961 panic("%s: reset, mbo 1987 panic("%s: reset, mbox %d, SCpnt == NULL.\n", ha->board_name, i);
1962 1988
1963 if (ha->cp_stat[i] == READY | 1989 if (ha->cp_stat[i] == READY || ha->cp_stat[i] == ABORTING) {
1964 ha->cp_stat[i] = ABOR 1990 ha->cp_stat[i] = ABORTING;
1965 printk("%s: reset, mb 1991 printk("%s: reset, mbox %d aborting, pid %ld.\n",
1966 ha->board_name !! 1992 ha->board_name, i, SCpnt->pid);
1967 } 1993 }
1968 1994
1969 else { 1995 else {
1970 ha->cp_stat[i] = IN_R 1996 ha->cp_stat[i] = IN_RESET;
1971 printk("%s: reset, mb 1997 printk("%s: reset, mbox %d in reset, pid %ld.\n",
1972 ha->board_name !! 1998 ha->board_name, i, SCpnt->pid);
1973 } 1999 }
1974 2000
1975 if (SCpnt->host_scribble == N 2001 if (SCpnt->host_scribble == NULL)
1976 panic("%s: reset, mbo 2002 panic("%s: reset, mbox %d, garbled SCpnt.\n", ha->board_name, i);
1977 2003
1978 if (*(unsigned int *)SCpnt->h 2004 if (*(unsigned int *)SCpnt->host_scribble != i)
1979 panic("%s: reset, mbo 2005 panic("%s: reset, mbox %d, index mismatch.\n", ha->board_name, i);
1980 2006
1981 if (SCpnt->scsi_done == NULL) 2007 if (SCpnt->scsi_done == NULL)
1982 panic("%s: reset, mbo 2008 panic("%s: reset, mbox %d, SCpnt->scsi_done == NULL.\n",
1983 ha->board_name, 2009 ha->board_name, i);
1984 2010
1985 if (SCpnt == SCarg) 2011 if (SCpnt == SCarg)
1986 arg_done = 1; 2012 arg_done = 1;
1987 } 2013 }
1988 2014
1989 if (do_dma(shost->io_port, 0, RESET_P 2015 if (do_dma(shost->io_port, 0, RESET_PIO)) {
1990 printk("%s: reset, cannot res 2016 printk("%s: reset, cannot reset, timeout error.\n", ha->board_name);
1991 spin_unlock_irq(shost->host_l <<
1992 return FAILED; 2017 return FAILED;
1993 } 2018 }
1994 2019
1995 printk("%s: reset, board reset done, 2020 printk("%s: reset, board reset done, enabling interrupts.\n", ha->board_name);
1996 2021
1997 #if defined(DEBUG_RESET) 2022 #if defined(DEBUG_RESET)
1998 do_trace = 1; 2023 do_trace = 1;
1999 #endif 2024 #endif
2000 2025
2001 ha->in_reset = 1; 2026 ha->in_reset = 1;
2002 2027
2003 spin_unlock_irq(shost->host_lock); 2028 spin_unlock_irq(shost->host_lock);
2004 <<
2005 /* FIXME: use a sleep instead */ <<
2006 time = jiffies; 2029 time = jiffies;
2007 while ((jiffies - time) < (10 * HZ) & 2030 while ((jiffies - time) < (10 * HZ) && limit++ < 200000)
2008 udelay(100L); 2031 udelay(100L);
2009 <<
2010 spin_lock_irq(shost->host_lock); 2032 spin_lock_irq(shost->host_lock);
2011 2033
2012 printk("%s: reset, interrupts disable 2034 printk("%s: reset, interrupts disabled, loops %d.\n", ha->board_name, limit);
2013 2035
2014 for (i = 0; i < shost->can_queue; i++ 2036 for (i = 0; i < shost->can_queue; i++) {
2015 2037
2016 if (ha->cp_stat[i] == IN_RESE 2038 if (ha->cp_stat[i] == IN_RESET) {
2017 SCpnt = ha->cp[i].SCp 2039 SCpnt = ha->cp[i].SCpnt;
2018 unmap_dma(i, ha); 2040 unmap_dma(i, ha);
2019 SCpnt->result = DID_R 2041 SCpnt->result = DID_RESET << 16;
2020 SCpnt->host_scribble 2042 SCpnt->host_scribble = NULL;
2021 2043
2022 /* This mailbox is st 2044 /* This mailbox is still waiting for its interrupt */
2023 ha->cp_stat[i] = LOCK 2045 ha->cp_stat[i] = LOCKED;
2024 2046
2025 printk 2047 printk
2026 ("%s, reset, mbox 2048 ("%s, reset, mbox %d locked, DID_RESET, pid %ld done.\n",
2027 ha->board_name, !! 2049 ha->board_name, i, SCpnt->pid);
2028 } 2050 }
2029 2051
2030 else if (ha->cp_stat[i] == AB 2052 else if (ha->cp_stat[i] == ABORTING) {
2031 SCpnt = ha->cp[i].SCp 2053 SCpnt = ha->cp[i].SCpnt;
2032 unmap_dma(i, ha); 2054 unmap_dma(i, ha);
2033 SCpnt->result = DID_R 2055 SCpnt->result = DID_RESET << 16;
2034 SCpnt->host_scribble 2056 SCpnt->host_scribble = NULL;
2035 2057
2036 /* This mailbox was n 2058 /* This mailbox was never queued to the adapter */
2037 ha->cp_stat[i] = FREE 2059 ha->cp_stat[i] = FREE;
2038 2060
2039 printk 2061 printk
2040 ("%s, reset, mbox 2062 ("%s, reset, mbox %d aborting, DID_RESET, pid %ld done.\n",
2041 ha->board_name, !! 2063 ha->board_name, i, SCpnt->pid);
2042 } 2064 }
2043 2065
2044 else 2066 else
2045 /* Any other mailbox 2067 /* Any other mailbox has already been set free by interrupt */
2046 continue; 2068 continue;
2047 2069
2048 SCpnt->scsi_done(SCpnt); 2070 SCpnt->scsi_done(SCpnt);
2049 } 2071 }
2050 2072
2051 ha->in_reset = 0; 2073 ha->in_reset = 0;
2052 do_trace = 0; 2074 do_trace = 0;
2053 2075
2054 if (arg_done) 2076 if (arg_done)
2055 printk("%s: reset, exit, pid !! 2077 printk("%s: reset, exit, pid %ld done.\n", ha->board_name, SCarg->pid);
2056 else 2078 else
2057 printk("%s: reset, exit.\n", 2079 printk("%s: reset, exit.\n", ha->board_name);
2058 2080
2059 spin_unlock_irq(shost->host_lock); <<
2060 return SUCCESS; 2081 return SUCCESS;
2061 } 2082 }
2062 2083
2063 int eata2x_bios_param(struct scsi_device *sde 2084 int eata2x_bios_param(struct scsi_device *sdev, struct block_device *bdev,
2064 sector_t capacity, int 2085 sector_t capacity, int *dkinfo)
2065 { 2086 {
2066 unsigned int size = capacity; 2087 unsigned int size = capacity;
2067 2088
2068 if (ext_tran || (scsicam_bios_param(b 2089 if (ext_tran || (scsicam_bios_param(bdev, capacity, dkinfo) < 0)) {
2069 dkinfo[0] = 255; 2090 dkinfo[0] = 255;
2070 dkinfo[1] = 63; 2091 dkinfo[1] = 63;
2071 dkinfo[2] = size / (dkinfo[0] 2092 dkinfo[2] = size / (dkinfo[0] * dkinfo[1]);
2072 } 2093 }
2073 #if defined (DEBUG_GEOMETRY) 2094 #if defined (DEBUG_GEOMETRY)
2074 printk("%s: bios_param, head=%d, sec= 2095 printk("%s: bios_param, head=%d, sec=%d, cyl=%d.\n", driver_name,
2075 dkinfo[0], dkinfo[1], dkinfo[2 2096 dkinfo[0], dkinfo[1], dkinfo[2]);
2076 #endif 2097 #endif
2077 2098
2078 return 0; 2099 return 0;
2079 } 2100 }
2080 2101
2081 static void sort(unsigned long sk[], unsigned 2102 static void sort(unsigned long sk[], unsigned int da[], unsigned int n,
2082 unsigned int rev) 2103 unsigned int rev)
2083 { 2104 {
2084 unsigned int i, j, k, y; 2105 unsigned int i, j, k, y;
2085 unsigned long x; 2106 unsigned long x;
2086 2107
2087 for (i = 0; i < n - 1; i++) { 2108 for (i = 0; i < n - 1; i++) {
2088 k = i; 2109 k = i;
2089 2110
2090 for (j = k + 1; j < n; j++) 2111 for (j = k + 1; j < n; j++)
2091 if (rev) { 2112 if (rev) {
2092 if (sk[j] > s 2113 if (sk[j] > sk[k])
2093 k = j 2114 k = j;
2094 } else { 2115 } else {
2095 if (sk[j] < s 2116 if (sk[j] < sk[k])
2096 k = j 2117 k = j;
2097 } 2118 }
2098 2119
2099 if (k != i) { 2120 if (k != i) {
2100 x = sk[k]; 2121 x = sk[k];
2101 sk[k] = sk[i]; 2122 sk[k] = sk[i];
2102 sk[i] = x; 2123 sk[i] = x;
2103 y = da[k]; 2124 y = da[k];
2104 da[k] = da[i]; 2125 da[k] = da[i];
2105 da[i] = y; 2126 da[i] = y;
2106 } 2127 }
2107 } 2128 }
2108 2129
2109 return; 2130 return;
2110 } 2131 }
2111 2132
2112 static int reorder(struct hostdata *ha, unsig 2133 static int reorder(struct hostdata *ha, unsigned long cursec,
2113 unsigned int ihdlr, unsign 2134 unsigned int ihdlr, unsigned int il[], unsigned int n_ready)
2114 { 2135 {
2115 struct scsi_cmnd *SCpnt; 2136 struct scsi_cmnd *SCpnt;
2116 struct mscp *cpp; 2137 struct mscp *cpp;
2117 unsigned int k, n; 2138 unsigned int k, n;
2118 unsigned int rev = 0, s = 1, r = 1; 2139 unsigned int rev = 0, s = 1, r = 1;
2119 unsigned int input_only = 1, overlap 2140 unsigned int input_only = 1, overlap = 0;
2120 unsigned long sl[n_ready], pl[n_ready 2141 unsigned long sl[n_ready], pl[n_ready], ll[n_ready];
2121 unsigned long maxsec = 0, minsec = UL 2142 unsigned long maxsec = 0, minsec = ULONG_MAX, seek = 0, iseek = 0;
2122 unsigned long ioseek = 0; 2143 unsigned long ioseek = 0;
2123 2144
2124 static unsigned int flushcount = 0, b 2145 static unsigned int flushcount = 0, batchcount = 0, sortcount = 0;
2125 static unsigned int readycount = 0, o 2146 static unsigned int readycount = 0, ovlcount = 0, inputcount = 0;
2126 static unsigned int readysorted = 0, 2147 static unsigned int readysorted = 0, revcount = 0;
2127 static unsigned long seeksorted = 0, 2148 static unsigned long seeksorted = 0, seeknosort = 0;
2128 2149
2129 if (link_statistics && !(++flushcount 2150 if (link_statistics && !(++flushcount % link_statistics))
2130 printk("fc %d bc %d ic %d oc 2151 printk("fc %d bc %d ic %d oc %d rc %d rs %d sc %d re %d"
2131 " av %ldK as %ldK.\n", 2152 " av %ldK as %ldK.\n", flushcount, batchcount,
2132 inputcount, ovlcount, 2153 inputcount, ovlcount, readycount, readysorted, sortcount,
2133 revcount, seeknosort / 2154 revcount, seeknosort / (readycount + 1),
2134 seeksorted / (readycou 2155 seeksorted / (readycount + 1));
2135 2156
2136 if (n_ready <= 1) 2157 if (n_ready <= 1)
2137 return 0; 2158 return 0;
2138 2159
2139 for (n = 0; n < n_ready; n++) { 2160 for (n = 0; n < n_ready; n++) {
2140 k = il[n]; 2161 k = il[n];
2141 cpp = &ha->cp[k]; 2162 cpp = &ha->cp[k];
2142 SCpnt = cpp->SCpnt; 2163 SCpnt = cpp->SCpnt;
2143 2164
2144 if (!cpp->din) 2165 if (!cpp->din)
2145 input_only = 0; 2166 input_only = 0;
2146 2167
2147 if (blk_rq_pos(SCpnt->request !! 2168 if (SCpnt->request->sector < minsec)
2148 minsec = blk_rq_pos(S !! 2169 minsec = SCpnt->request->sector;
2149 if (blk_rq_pos(SCpnt->request !! 2170 if (SCpnt->request->sector > maxsec)
2150 maxsec = blk_rq_pos(S !! 2171 maxsec = SCpnt->request->sector;
2151 2172
2152 sl[n] = blk_rq_pos(SCpnt->req !! 2173 sl[n] = SCpnt->request->sector;
2153 ioseek += blk_rq_sectors(SCpn !! 2174 ioseek += SCpnt->request->nr_sectors;
2154 2175
2155 if (!n) 2176 if (!n)
2156 continue; 2177 continue;
2157 2178
2158 if (sl[n] < sl[n - 1]) 2179 if (sl[n] < sl[n - 1])
2159 s = 0; 2180 s = 0;
2160 if (sl[n] > sl[n - 1]) 2181 if (sl[n] > sl[n - 1])
2161 r = 0; 2182 r = 0;
2162 2183
2163 if (link_statistics) { 2184 if (link_statistics) {
2164 if (sl[n] > sl[n - 1] 2185 if (sl[n] > sl[n - 1])
2165 seek += sl[n] 2186 seek += sl[n] - sl[n - 1];
2166 else 2187 else
2167 seek += sl[n 2188 seek += sl[n - 1] - sl[n];
2168 } 2189 }
2169 2190
2170 } 2191 }
2171 2192
2172 if (link_statistics) { 2193 if (link_statistics) {
2173 if (cursec > sl[0]) 2194 if (cursec > sl[0])
2174 seek += cursec - sl[0 2195 seek += cursec - sl[0];
2175 else 2196 else
2176 seek += sl[0] - curse 2197 seek += sl[0] - cursec;
2177 } 2198 }
2178 2199
2179 if (cursec > ((maxsec + minsec) / 2)) 2200 if (cursec > ((maxsec + minsec) / 2))
2180 rev = 1; 2201 rev = 1;
2181 2202
2182 if (ioseek > ((maxsec - minsec) / 2)) 2203 if (ioseek > ((maxsec - minsec) / 2))
2183 rev = 0; 2204 rev = 0;
2184 2205
2185 if (!((rev && r) || (!rev && s))) 2206 if (!((rev && r) || (!rev && s)))
2186 sort(sl, il, n_ready, rev); 2207 sort(sl, il, n_ready, rev);
2187 2208
2188 if (!input_only) 2209 if (!input_only)
2189 for (n = 0; n < n_ready; n++) 2210 for (n = 0; n < n_ready; n++) {
2190 k = il[n]; 2211 k = il[n];
2191 cpp = &ha->cp[k]; 2212 cpp = &ha->cp[k];
2192 SCpnt = cpp->SCpnt; 2213 SCpnt = cpp->SCpnt;
2193 ll[n] = blk_rq_sector !! 2214 ll[n] = SCpnt->request->nr_sectors;
2194 pl[n] = SCpnt->serial !! 2215 pl[n] = SCpnt->pid;
2195 2216
2196 if (!n) 2217 if (!n)
2197 continue; 2218 continue;
2198 2219
2199 if ((sl[n] == sl[n - 2220 if ((sl[n] == sl[n - 1])
2200 || (!rev && ((sl[ 2221 || (!rev && ((sl[n - 1] + ll[n - 1]) > sl[n]))
2201 || (rev && ((sl[n 2222 || (rev && ((sl[n] + ll[n]) > sl[n - 1])))
2202 overlap = 1; 2223 overlap = 1;
2203 } 2224 }
2204 2225
2205 if (overlap) 2226 if (overlap)
2206 sort(pl, il, n_ready, 0); 2227 sort(pl, il, n_ready, 0);
2207 2228
2208 if (link_statistics) { 2229 if (link_statistics) {
2209 if (cursec > sl[0]) 2230 if (cursec > sl[0])
2210 iseek = cursec - sl[0 2231 iseek = cursec - sl[0];
2211 else 2232 else
2212 iseek = sl[0] - curse 2233 iseek = sl[0] - cursec;
2213 batchcount++; 2234 batchcount++;
2214 readycount += n_ready; 2235 readycount += n_ready;
2215 seeknosort += seek / 1024; 2236 seeknosort += seek / 1024;
2216 if (input_only) 2237 if (input_only)
2217 inputcount++; 2238 inputcount++;
2218 if (overlap) { 2239 if (overlap) {
2219 ovlcount++; 2240 ovlcount++;
2220 seeksorted += iseek / 2241 seeksorted += iseek / 1024;
2221 } else 2242 } else
2222 seeksorted += (iseek 2243 seeksorted += (iseek + maxsec - minsec) / 1024;
2223 if (rev && !r) { 2244 if (rev && !r) {
2224 revcount++; 2245 revcount++;
2225 readysorted += n_read 2246 readysorted += n_ready;
2226 } 2247 }
2227 if (!rev && !s) { 2248 if (!rev && !s) {
2228 sortcount++; 2249 sortcount++;
2229 readysorted += n_read 2250 readysorted += n_ready;
2230 } 2251 }
2231 } 2252 }
2232 #if defined(DEBUG_LINKED_COMMANDS) 2253 #if defined(DEBUG_LINKED_COMMANDS)
2233 if (link_statistics && (overlap || !( 2254 if (link_statistics && (overlap || !(flushcount % link_statistics)))
2234 for (n = 0; n < n_ready; n++) 2255 for (n = 0; n < n_ready; n++) {
2235 k = il[n]; 2256 k = il[n];
2236 cpp = &ha->cp[k]; 2257 cpp = &ha->cp[k];
2237 SCpnt = cpp->SCpnt; 2258 SCpnt = cpp->SCpnt;
2238 scmd_printk(KERN_INFO !! 2259 printk
2239 "%s pid %ld mb %d !! 2260 ("%s %d.%d:%d pid %ld mb %d fc %d nr %d sec %ld ns %ld"
2240 " cur %ld s:%c r 2261 " cur %ld s:%c r:%c rev:%c in:%c ov:%c xd %d.\n",
2241 (ihdlr ? "ihdlr" 2262 (ihdlr ? "ihdlr" : "qcomm"),
2242 SCpnt->serial_nu !! 2263 SCpnt->device->channel, SCpnt->device->id,
2243 n_ready, blk_rq_ !! 2264 SCpnt->device->lun, SCpnt->pid, k, flushcount,
2244 blk_rq_sectors(S !! 2265 n_ready, SCpnt->request->sector,
>> 2266 SCpnt->request->nr_sectors, cursec, YESNO(s),
2245 YESNO(r), YESNO( 2267 YESNO(r), YESNO(rev), YESNO(input_only),
2246 YESNO(overlap), 2268 YESNO(overlap), cpp->din);
2247 } 2269 }
2248 #endif 2270 #endif
2249 return overlap; 2271 return overlap;
2250 } 2272 }
2251 2273
2252 static void flush_dev(struct scsi_device *dev 2274 static void flush_dev(struct scsi_device *dev, unsigned long cursec,
2253 struct hostdata *ha, un 2275 struct hostdata *ha, unsigned int ihdlr)
2254 { 2276 {
2255 struct scsi_cmnd *SCpnt; 2277 struct scsi_cmnd *SCpnt;
2256 struct mscp *cpp; 2278 struct mscp *cpp;
2257 unsigned int k, n, n_ready = 0, il[MA 2279 unsigned int k, n, n_ready = 0, il[MAX_MAILBOXES];
2258 2280
2259 for (k = 0; k < dev->host->can_queue; 2281 for (k = 0; k < dev->host->can_queue; k++) {
2260 2282
2261 if (ha->cp_stat[k] != READY & 2283 if (ha->cp_stat[k] != READY && ha->cp_stat[k] != IN_USE)
2262 continue; 2284 continue;
2263 2285
2264 cpp = &ha->cp[k]; 2286 cpp = &ha->cp[k];
2265 SCpnt = cpp->SCpnt; 2287 SCpnt = cpp->SCpnt;
2266 2288
2267 if (SCpnt->device != dev) 2289 if (SCpnt->device != dev)
2268 continue; 2290 continue;
2269 2291
2270 if (ha->cp_stat[k] == IN_USE) 2292 if (ha->cp_stat[k] == IN_USE)
2271 return; 2293 return;
2272 2294
2273 il[n_ready++] = k; 2295 il[n_ready++] = k;
2274 } 2296 }
2275 2297
2276 if (reorder(ha, cursec, ihdlr, il, n_ 2298 if (reorder(ha, cursec, ihdlr, il, n_ready))
2277 n_ready = 1; 2299 n_ready = 1;
2278 2300
2279 for (n = 0; n < n_ready; n++) { 2301 for (n = 0; n < n_ready; n++) {
2280 k = il[n]; 2302 k = il[n];
2281 cpp = &ha->cp[k]; 2303 cpp = &ha->cp[k];
2282 SCpnt = cpp->SCpnt; 2304 SCpnt = cpp->SCpnt;
2283 2305
2284 if (do_dma(dev->host->io_port 2306 if (do_dma(dev->host->io_port, cpp->cp_dma_addr, SEND_CP_DMA)) {
2285 scmd_printk(KERN_INFO !! 2307 printk
2286 "%s, pid %ld, mbo !! 2308 ("%s: %s, target %d.%d:%d, pid %ld, mbox %d, adapter"
2287 " busy, will abo !! 2309 " busy, will abort.\n", ha->board_name,
2288 (ihdlr ? "ihdlr" 2310 (ihdlr ? "ihdlr" : "qcomm"),
2289 SCpnt->serial_nu !! 2311 SCpnt->device->channel, SCpnt->device->id,
>> 2312 SCpnt->device->lun, SCpnt->pid, k);
2290 ha->cp_stat[k] = ABOR 2313 ha->cp_stat[k] = ABORTING;
2291 continue; 2314 continue;
2292 } 2315 }
2293 2316
2294 ha->cp_stat[k] = IN_USE; 2317 ha->cp_stat[k] = IN_USE;
2295 } 2318 }
2296 } 2319 }
2297 2320
2298 static irqreturn_t ihdlr(struct Scsi_Host *sh !! 2321 static irqreturn_t ihdlr(int irq, struct Scsi_Host *shost)
2299 { 2322 {
2300 struct scsi_cmnd *SCpnt; 2323 struct scsi_cmnd *SCpnt;
2301 unsigned int i, k, c, status, tstatus 2324 unsigned int i, k, c, status, tstatus, reg;
2302 struct mssp *spp; 2325 struct mssp *spp;
2303 struct mscp *cpp; 2326 struct mscp *cpp;
2304 struct hostdata *ha = (struct hostdat 2327 struct hostdata *ha = (struct hostdata *)shost->hostdata;
2305 int irq = shost->irq; !! 2328
>> 2329 if (shost->irq != irq)
>> 2330 panic("%s: ihdlr, irq %d, shost->irq %d.\n", ha->board_name, irq,
>> 2331 shost->irq);
2306 2332
2307 /* Check if this board need to be ser 2333 /* Check if this board need to be serviced */
2308 if (!(inb(shost->io_port + REG_AUX_ST 2334 if (!(inb(shost->io_port + REG_AUX_STATUS) & IRQ_ASSERTED))
2309 goto none; 2335 goto none;
2310 2336
2311 ha->iocount++; 2337 ha->iocount++;
2312 2338
2313 if (do_trace) 2339 if (do_trace)
2314 printk("%s: ihdlr, enter, irq 2340 printk("%s: ihdlr, enter, irq %d, count %d.\n", ha->board_name, irq,
2315 ha->iocount); 2341 ha->iocount);
2316 2342
2317 /* Check if this board is still busy 2343 /* Check if this board is still busy */
2318 if (wait_on_busy(shost->io_port, 20 * 2344 if (wait_on_busy(shost->io_port, 20 * MAXLOOP)) {
2319 reg = inb(shost->io_port + RE 2345 reg = inb(shost->io_port + REG_STATUS);
2320 printk 2346 printk
2321 ("%s: ihdlr, busy timeout 2347 ("%s: ihdlr, busy timeout error, irq %d, reg 0x%x, count %d.\n",
2322 ha->board_name, irq, reg 2348 ha->board_name, irq, reg, ha->iocount);
2323 goto none; 2349 goto none;
2324 } 2350 }
2325 2351
2326 spp = &ha->sp; 2352 spp = &ha->sp;
2327 2353
2328 /* Make a local copy just before clea 2354 /* Make a local copy just before clearing the interrupt indication */
2329 memcpy(spp, ha->sp_cpu_addr, sizeof(s 2355 memcpy(spp, ha->sp_cpu_addr, sizeof(struct mssp));
2330 2356
2331 /* Clear the completion flag and cp p 2357 /* Clear the completion flag and cp pointer on the dynamic copy of sp */
2332 memset(ha->sp_cpu_addr, 0, sizeof(str 2358 memset(ha->sp_cpu_addr, 0, sizeof(struct mssp));
2333 2359
2334 /* Read the status register to clear 2360 /* Read the status register to clear the interrupt indication */
2335 reg = inb(shost->io_port + REG_STATUS 2361 reg = inb(shost->io_port + REG_STATUS);
2336 2362
2337 #if defined (DEBUG_INTERRUPT) 2363 #if defined (DEBUG_INTERRUPT)
2338 { 2364 {
2339 unsigned char *bytesp; 2365 unsigned char *bytesp;
2340 int cnt; 2366 int cnt;
2341 bytesp = (unsigned char *)spp 2367 bytesp = (unsigned char *)spp;
2342 if (ha->iocount < 200) { 2368 if (ha->iocount < 200) {
2343 printk("sp[] ="); 2369 printk("sp[] =");
2344 for (cnt = 0; cnt < 1 2370 for (cnt = 0; cnt < 15; cnt++)
2345 printk(" 0x%x 2371 printk(" 0x%x", bytesp[cnt]);
2346 printk("\n"); 2372 printk("\n");
2347 } 2373 }
2348 } 2374 }
2349 #endif 2375 #endif
2350 2376
2351 /* Reject any sp with supspect data * 2377 /* Reject any sp with supspect data */
2352 if (spp->eoc == 0 && ha->iocount > 1) 2378 if (spp->eoc == 0 && ha->iocount > 1)
2353 printk 2379 printk
2354 ("%s: ihdlr, spp->eoc == 2380 ("%s: ihdlr, spp->eoc == 0, irq %d, reg 0x%x, count %d.\n",
2355 ha->board_name, irq, reg 2381 ha->board_name, irq, reg, ha->iocount);
2356 if (spp->cpp_index < 0 || spp->cpp_in 2382 if (spp->cpp_index < 0 || spp->cpp_index >= shost->can_queue)
2357 printk 2383 printk
2358 ("%s: ihdlr, bad spp->cpp 2384 ("%s: ihdlr, bad spp->cpp_index %d, irq %d, reg 0x%x, count %d.\n",
2359 ha->board_name, spp->cpp 2385 ha->board_name, spp->cpp_index, irq, reg, ha->iocount);
2360 if (spp->eoc == 0 || spp->cpp_index < 2386 if (spp->eoc == 0 || spp->cpp_index < 0
2361 || spp->cpp_index >= shost->can_q 2387 || spp->cpp_index >= shost->can_queue)
2362 goto handled; 2388 goto handled;
2363 2389
2364 /* Find the mailbox to be serviced on 2390 /* Find the mailbox to be serviced on this board */
2365 i = spp->cpp_index; 2391 i = spp->cpp_index;
2366 2392
2367 cpp = &(ha->cp[i]); 2393 cpp = &(ha->cp[i]);
2368 2394
2369 #if defined(DEBUG_GENERATE_ABORTS) 2395 #if defined(DEBUG_GENERATE_ABORTS)
2370 if ((ha->iocount > 500) && ((ha->ioco 2396 if ((ha->iocount > 500) && ((ha->iocount % 500) < 3))
2371 goto handled; 2397 goto handled;
2372 #endif 2398 #endif
2373 2399
2374 if (ha->cp_stat[i] == IGNORE) { 2400 if (ha->cp_stat[i] == IGNORE) {
2375 ha->cp_stat[i] = FREE; 2401 ha->cp_stat[i] = FREE;
2376 goto handled; 2402 goto handled;
2377 } else if (ha->cp_stat[i] == LOCKED) 2403 } else if (ha->cp_stat[i] == LOCKED) {
2378 ha->cp_stat[i] = FREE; 2404 ha->cp_stat[i] = FREE;
2379 printk("%s: ihdlr, mbox %d un 2405 printk("%s: ihdlr, mbox %d unlocked, count %d.\n", ha->board_name, i,
2380 ha->iocount); 2406 ha->iocount);
2381 goto handled; 2407 goto handled;
2382 } else if (ha->cp_stat[i] == FREE) { 2408 } else if (ha->cp_stat[i] == FREE) {
2383 printk("%s: ihdlr, mbox %d is 2409 printk("%s: ihdlr, mbox %d is free, count %d.\n", ha->board_name, i,
2384 ha->iocount); 2410 ha->iocount);
2385 goto handled; 2411 goto handled;
2386 } else if (ha->cp_stat[i] == IN_RESET 2412 } else if (ha->cp_stat[i] == IN_RESET)
2387 printk("%s: ihdlr, mbox %d is 2413 printk("%s: ihdlr, mbox %d is in reset.\n", ha->board_name, i);
2388 else if (ha->cp_stat[i] != IN_USE) 2414 else if (ha->cp_stat[i] != IN_USE)
2389 panic("%s: ihdlr, mbox %d, in 2415 panic("%s: ihdlr, mbox %d, invalid cp_stat: %d.\n",
2390 ha->board_name, i, ha-> 2416 ha->board_name, i, ha->cp_stat[i]);
2391 2417
2392 ha->cp_stat[i] = FREE; 2418 ha->cp_stat[i] = FREE;
2393 SCpnt = cpp->SCpnt; 2419 SCpnt = cpp->SCpnt;
2394 2420
2395 if (SCpnt == NULL) 2421 if (SCpnt == NULL)
2396 panic("%s: ihdlr, mbox %d, SC 2422 panic("%s: ihdlr, mbox %d, SCpnt == NULL.\n", ha->board_name, i);
2397 2423
2398 if (SCpnt->host_scribble == NULL) 2424 if (SCpnt->host_scribble == NULL)
2399 panic("%s: ihdlr, mbox %d, pi 2425 panic("%s: ihdlr, mbox %d, pid %ld, SCpnt %p garbled.\n", ha->board_name,
2400 i, SCpnt->serial_number !! 2426 i, SCpnt->pid, SCpnt);
2401 2427
2402 if (*(unsigned int *)SCpnt->host_scri 2428 if (*(unsigned int *)SCpnt->host_scribble != i)
2403 panic("%s: ihdlr, mbox %d, pi 2429 panic("%s: ihdlr, mbox %d, pid %ld, index mismatch %d.\n",
2404 ha->board_name, i, SCpn !! 2430 ha->board_name, i, SCpnt->pid,
2405 *(unsigned int *)SCpnt- 2431 *(unsigned int *)SCpnt->host_scribble);
2406 2432
2407 sync_dma(i, ha); 2433 sync_dma(i, ha);
2408 2434
2409 if (linked_comm && SCpnt->device->que 2435 if (linked_comm && SCpnt->device->queue_depth > 2
2410 && TLDEV(SCpnt->device->type)) 2436 && TLDEV(SCpnt->device->type))
2411 flush_dev(SCpnt->device, blk_ !! 2437 flush_dev(SCpnt->device, SCpnt->request->sector, ha, 1);
2412 2438
2413 tstatus = status_byte(spp->target_sta 2439 tstatus = status_byte(spp->target_status);
2414 2440
2415 #if defined(DEBUG_GENERATE_ERRORS) 2441 #if defined(DEBUG_GENERATE_ERRORS)
2416 if ((ha->iocount > 500) && ((ha->ioco 2442 if ((ha->iocount > 500) && ((ha->iocount % 200) < 2))
2417 spp->adapter_status = 0x01; 2443 spp->adapter_status = 0x01;
2418 #endif 2444 #endif
2419 2445
2420 switch (spp->adapter_status) { 2446 switch (spp->adapter_status) {
2421 case ASOK: /* status OK 2447 case ASOK: /* status OK */
2422 2448
2423 /* Forces a reset if a disk d 2449 /* Forces a reset if a disk drive keeps returning BUSY */
2424 if (tstatus == BUSY && SCpnt- 2450 if (tstatus == BUSY && SCpnt->device->type != TYPE_TAPE)
2425 status = DID_ERROR << 2451 status = DID_ERROR << 16;
2426 2452
2427 /* If there was a bus reset, 2453 /* If there was a bus reset, redo operation on each target */
2428 else if (tstatus != GOOD && S 2454 else if (tstatus != GOOD && SCpnt->device->type == TYPE_DISK
2429 && ha->target_redo[S 2455 && ha->target_redo[SCpnt->device->id][SCpnt->
2430 2456 device->
2431 2457 channel])
2432 status = DID_BUS_BUSY 2458 status = DID_BUS_BUSY << 16;
2433 2459
2434 /* Works around a flaw in scs 2460 /* Works around a flaw in scsi.c */
2435 else if (tstatus == CHECK_CON 2461 else if (tstatus == CHECK_CONDITION
2436 && SCpnt->device->ty 2462 && SCpnt->device->type == TYPE_DISK
2437 && (SCpnt->sense_buf 2463 && (SCpnt->sense_buffer[2] & 0xf) == RECOVERED_ERROR)
2438 status = DID_BUS_BUSY 2464 status = DID_BUS_BUSY << 16;
2439 2465
2440 else 2466 else
2441 status = DID_OK << 16 2467 status = DID_OK << 16;
2442 2468
2443 if (tstatus == GOOD) 2469 if (tstatus == GOOD)
2444 ha->target_redo[SCpnt 2470 ha->target_redo[SCpnt->device->id][SCpnt->device->
2445 2471 channel] = 0;
2446 2472
2447 if (spp->target_status && SCp 2473 if (spp->target_status && SCpnt->device->type == TYPE_DISK &&
2448 (!(tstatus == CHECK_CONDI 2474 (!(tstatus == CHECK_CONDITION && ha->iocount <= 1000 &&
2449 (SCpnt->sense_buffer[2 2475 (SCpnt->sense_buffer[2] & 0xf) == NOT_READY)))
2450 printk("%s: ihdlr, ta 2476 printk("%s: ihdlr, target %d.%d:%d, pid %ld, "
2451 "target_status 2477 "target_status 0x%x, sense key 0x%x.\n",
2452 ha->board_name 2478 ha->board_name,
2453 SCpnt->device- 2479 SCpnt->device->channel, SCpnt->device->id,
2454 SCpnt->device- !! 2480 SCpnt->device->lun, SCpnt->pid,
2455 spp->target_st 2481 spp->target_status, SCpnt->sense_buffer[2]);
2456 2482
2457 ha->target_to[SCpnt->device-> 2483 ha->target_to[SCpnt->device->id][SCpnt->device->channel] = 0;
2458 2484
2459 if (ha->last_retried_pid == S !! 2485 if (ha->last_retried_pid == SCpnt->pid)
2460 ha->retries = 0; 2486 ha->retries = 0;
2461 2487
2462 break; 2488 break;
2463 case ASST: /* Selection 2489 case ASST: /* Selection Time Out */
2464 case 0x02: /* Command Ti 2490 case 0x02: /* Command Time Out */
2465 2491
2466 if (ha->target_to[SCpnt->devi 2492 if (ha->target_to[SCpnt->device->id][SCpnt->device->channel] > 1)
2467 status = DID_ERROR << 2493 status = DID_ERROR << 16;
2468 else { 2494 else {
2469 status = DID_TIME_OUT 2495 status = DID_TIME_OUT << 16;
2470 ha->target_to[SCpnt-> 2496 ha->target_to[SCpnt->device->id][SCpnt->device->
2471 2497 channel]++;
2472 } 2498 }
2473 2499
2474 break; 2500 break;
2475 2501
2476 /* Perform a limited number o 2502 /* Perform a limited number of internal retries */
2477 case 0x03: /* SCSI Bus R 2503 case 0x03: /* SCSI Bus Reset Received */
2478 case 0x04: /* Initial Co 2504 case 0x04: /* Initial Controller Power-up */
2479 2505
2480 for (c = 0; c <= shost->max_c 2506 for (c = 0; c <= shost->max_channel; c++)
2481 for (k = 0; k < shost 2507 for (k = 0; k < shost->max_id; k++)
2482 ha->target_re 2508 ha->target_redo[k][c] = 1;
2483 2509
2484 if (SCpnt->device->type != TY 2510 if (SCpnt->device->type != TYPE_TAPE
2485 && ha->retries < MAX_INTE 2511 && ha->retries < MAX_INTERNAL_RETRIES) {
2486 2512
2487 #if defined(DID_SOFT_ERROR) 2513 #if defined(DID_SOFT_ERROR)
2488 status = DID_SOFT_ERR 2514 status = DID_SOFT_ERROR << 16;
2489 #else 2515 #else
2490 status = DID_BUS_BUSY 2516 status = DID_BUS_BUSY << 16;
2491 #endif 2517 #endif
2492 2518
2493 ha->retries++; 2519 ha->retries++;
2494 ha->last_retried_pid !! 2520 ha->last_retried_pid = SCpnt->pid;
2495 } else 2521 } else
2496 status = DID_ERROR << 2522 status = DID_ERROR << 16;
2497 2523
2498 break; 2524 break;
2499 case 0x05: /* Unexpected 2525 case 0x05: /* Unexpected Bus Phase */
2500 case 0x06: /* Unexpected 2526 case 0x06: /* Unexpected Bus Free */
2501 case 0x07: /* Bus Parity 2527 case 0x07: /* Bus Parity Error */
2502 case 0x08: /* SCSI Hung 2528 case 0x08: /* SCSI Hung */
2503 case 0x09: /* Unexpected 2529 case 0x09: /* Unexpected Message Reject */
2504 case 0x0a: /* SCSI Bus R 2530 case 0x0a: /* SCSI Bus Reset Stuck */
2505 case 0x0b: /* Auto Reque 2531 case 0x0b: /* Auto Request-Sense Failed */
2506 case 0x0c: /* Controller 2532 case 0x0c: /* Controller Ram Parity Error */
2507 default: 2533 default:
2508 status = DID_ERROR << 16; 2534 status = DID_ERROR << 16;
2509 break; 2535 break;
2510 } 2536 }
2511 2537
2512 SCpnt->result = status | spp->target_ 2538 SCpnt->result = status | spp->target_status;
2513 2539
2514 #if defined(DEBUG_INTERRUPT) 2540 #if defined(DEBUG_INTERRUPT)
2515 if (SCpnt->result || do_trace) 2541 if (SCpnt->result || do_trace)
2516 #else 2542 #else
2517 if ((spp->adapter_status != ASOK && h 2543 if ((spp->adapter_status != ASOK && ha->iocount > 1000) ||
2518 (spp->adapter_status != ASOK && 2544 (spp->adapter_status != ASOK &&
2519 spp->adapter_status != ASST && h 2545 spp->adapter_status != ASST && ha->iocount <= 1000) ||
2520 do_trace || msg_byte(spp->target_ 2546 do_trace || msg_byte(spp->target_status))
2521 #endif 2547 #endif
2522 scmd_printk(KERN_INFO, SCpnt, !! 2548 printk("%s: ihdlr, mbox %2d, err 0x%x:%x,"
2523 " pid %ld, reg 0x%x, c !! 2549 " target %d.%d:%d, pid %ld, reg 0x%x, count %d.\n",
2524 i, spp->adapter_status !! 2550 ha->board_name, i, spp->adapter_status, spp->target_status,
2525 SCpnt->serial_number, !! 2551 SCpnt->device->channel, SCpnt->device->id,
>> 2552 SCpnt->device->lun, SCpnt->pid, reg, ha->iocount);
2526 2553
2527 unmap_dma(i, ha); 2554 unmap_dma(i, ha);
2528 2555
2529 /* Set the command state to inactive 2556 /* Set the command state to inactive */
2530 SCpnt->host_scribble = NULL; 2557 SCpnt->host_scribble = NULL;
2531 2558
2532 SCpnt->scsi_done(SCpnt); 2559 SCpnt->scsi_done(SCpnt);
2533 2560
2534 if (do_trace) 2561 if (do_trace)
2535 printk("%s: ihdlr, exit, irq 2562 printk("%s: ihdlr, exit, irq %d, count %d.\n", ha->board_name,
2536 irq, ha->ioco 2563 irq, ha->iocount);
2537 2564
2538 handled: 2565 handled:
2539 return IRQ_HANDLED; 2566 return IRQ_HANDLED;
2540 none: 2567 none:
2541 return IRQ_NONE; 2568 return IRQ_NONE;
2542 } 2569 }
2543 2570
2544 static irqreturn_t do_interrupt_handler(int d !! 2571 static irqreturn_t do_interrupt_handler(int irq, void *shap,
>> 2572 struct pt_regs *regs)
2545 { 2573 {
2546 struct Scsi_Host *shost; 2574 struct Scsi_Host *shost;
2547 unsigned int j; 2575 unsigned int j;
2548 unsigned long spin_flags; 2576 unsigned long spin_flags;
2549 irqreturn_t ret; 2577 irqreturn_t ret;
2550 2578
2551 /* Check if the interrupt must be pro 2579 /* Check if the interrupt must be processed by this handler */
2552 if ((j = (unsigned int)((char *)shap 2580 if ((j = (unsigned int)((char *)shap - sha)) >= num_boards)
2553 return IRQ_NONE; 2581 return IRQ_NONE;
2554 shost = sh[j]; 2582 shost = sh[j];
2555 2583
2556 spin_lock_irqsave(shost->host_lock, s 2584 spin_lock_irqsave(shost->host_lock, spin_flags);
2557 ret = ihdlr(shost); !! 2585 ret = ihdlr(irq, shost);
2558 spin_unlock_irqrestore(shost->host_lo 2586 spin_unlock_irqrestore(shost->host_lock, spin_flags);
2559 return ret; 2587 return ret;
2560 } 2588 }
2561 2589
2562 static int eata2x_release(struct Scsi_Host *s 2590 static int eata2x_release(struct Scsi_Host *shost)
2563 { 2591 {
2564 struct hostdata *ha = (struct hostdat 2592 struct hostdata *ha = (struct hostdata *)shost->hostdata;
2565 unsigned int i; 2593 unsigned int i;
2566 2594
2567 for (i = 0; i < shost->can_queue; i++ 2595 for (i = 0; i < shost->can_queue; i++)
2568 kfree((&ha->cp[i])->sglist); !! 2596 if ((&ha->cp[i])->sglist)
>> 2597 kfree((&ha->cp[i])->sglist);
2569 2598
2570 for (i = 0; i < shost->can_queue; i++ 2599 for (i = 0; i < shost->can_queue; i++)
2571 pci_unmap_single(ha->pdev, ha 2600 pci_unmap_single(ha->pdev, ha->cp[i].cp_dma_addr,
2572 sizeof(struc 2601 sizeof(struct mscp), PCI_DMA_BIDIRECTIONAL);
2573 2602
2574 if (ha->sp_cpu_addr) 2603 if (ha->sp_cpu_addr)
2575 pci_free_consistent(ha->pdev, 2604 pci_free_consistent(ha->pdev, sizeof(struct mssp),
2576 ha->sp_cp 2605 ha->sp_cpu_addr, ha->sp_dma_addr);
2577 2606
2578 free_irq(shost->irq, &sha[ha->board_n 2607 free_irq(shost->irq, &sha[ha->board_number]);
2579 2608
2580 if (shost->dma_channel != NO_DMA) 2609 if (shost->dma_channel != NO_DMA)
2581 free_dma(shost->dma_channel); 2610 free_dma(shost->dma_channel);
2582 2611
2583 release_region(shost->io_port, shost- 2612 release_region(shost->io_port, shost->n_io_port);
2584 scsi_unregister(shost); 2613 scsi_unregister(shost);
2585 return 0; 2614 return 0;
2586 } 2615 }
2587 2616
2588 #include "scsi_module.c" 2617 #include "scsi_module.c"
2589 2618
2590 #ifndef MODULE 2619 #ifndef MODULE
2591 __setup("eata=", option_setup); 2620 __setup("eata=", option_setup);
2592 #endif /* end MODULE 2621 #endif /* end MODULE */
2593 2622
|
This page was automatically generated by the
LXR engine.
|