Commit | Line | Data |
---|---|---|
1da177e4 | 1 | /* aha152x.c -- Adaptec AHA-152x driver |
96de0e25 JE |
2 | * Author: Jürgen E. Fischer, fischer@norbit.de |
3 | * Copyright 1993-2004 Jürgen E. Fischer | |
1da177e4 LT |
4 | * |
5 | * This program is free software; you can redistribute it and/or modify it | |
6 | * under the terms of the GNU General Public License as published by the | |
7 | * Free Software Foundation; either version 2, or (at your option) any | |
8 | * later version. | |
9 | * | |
10 | * This program is distributed in the hope that it will be useful, but | |
11 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 | * General Public License for more details. | |
14 | * | |
15 | * | |
16 | * $Id: aha152x.c,v 2.7 2004/01/24 11:42:59 fischer Exp $ | |
17 | * | |
18 | * $Log: aha152x.c,v $ | |
19 | * Revision 2.7 2004/01/24 11:42:59 fischer | |
20 | * - gather code that is not used by PCMCIA at the end | |
21 | * - move request_region for !PCMCIA case to detection | |
22 | * - migration to new scsi host api (remove legacy code) | |
23 | * - free host scribble before scsi_done | |
24 | * - fix error handling | |
25 | * - one isapnp device added to id_table | |
26 | * | |
27 | * Revision 2.6 2003/10/30 20:52:47 fischer | |
28 | * - interfaces changes for kernel 2.6 | |
29 | * - aha152x_probe_one introduced for pcmcia stub | |
30 | * - fixed pnpdev handling | |
31 | * - instead of allocation a new one, reuse command for request sense after check condition and reset | |
32 | * - fixes race in is_complete | |
33 | * | |
34 | * Revision 2.5 2002/04/14 11:24:53 fischer | |
35 | * - isapnp support | |
36 | * - abort fixed | |
37 | * - 2.5 support | |
38 | * | |
39 | * Revision 2.4 2000/12/16 12:53:56 fischer | |
40 | * - allow REQUEST SENSE to be queued | |
41 | * - handle shared PCI interrupts | |
42 | * | |
43 | * Revision 2.3 2000/11/04 16:40:26 fischer | |
44 | * - handle data overruns | |
45 | * - extend timeout for data phases | |
46 | * | |
47 | * Revision 2.2 2000/08/08 19:54:53 fischer | |
48 | * - minor changes | |
49 | * | |
50 | * Revision 2.1 2000/05/17 16:23:17 fischer | |
51 | * - signature update | |
52 | * - fix for data out w/o scatter gather | |
53 | * | |
54 | * Revision 2.0 1999/12/25 15:07:32 fischer | |
55 | * - interrupt routine completly reworked | |
56 | * - basic support for new eh code | |
57 | * | |
58 | * Revision 1.21 1999/11/10 23:46:36 fischer | |
59 | * - default to synchronous operation | |
60 | * - synchronous negotiation fixed | |
61 | * - added timeout to loops | |
62 | * - debugging output can be controlled through procfs | |
63 | * | |
64 | * Revision 1.20 1999/11/07 18:37:31 fischer | |
65 | * - synchronous operation works | |
66 | * - resid support for sg driver | |
67 | * | |
68 | * Revision 1.19 1999/11/02 22:39:59 fischer | |
69 | * - moved leading comments to README.aha152x | |
70 | * - new additional module parameters | |
71 | * - updates for 2.3 | |
72 | * - support for the Tripace TC1550 controller | |
73 | * - interrupt handling changed | |
74 | * | |
75 | * Revision 1.18 1996/09/07 20:10:40 fischer | |
76 | * - fixed can_queue handling (multiple outstanding commands working again) | |
77 | * | |
78 | * Revision 1.17 1996/08/17 16:05:14 fischer | |
79 | * - biosparam improved | |
80 | * - interrupt verification | |
81 | * - updated documentation | |
82 | * - cleanups | |
83 | * | |
84 | * Revision 1.16 1996/06/09 00:04:56 root | |
85 | * - added configuration symbols for insmod (aha152x/aha152x1) | |
86 | * | |
87 | * Revision 1.15 1996/04/30 14:52:06 fischer | |
88 | * - proc info fixed | |
89 | * - support for extended translation for >1GB disks | |
90 | * | |
91 | * Revision 1.14 1996/01/17 15:11:20 fischer | |
92 | * - fixed lockup in MESSAGE IN phase after reconnection | |
93 | * | |
94 | * Revision 1.13 1996/01/09 02:15:53 fischer | |
95 | * - some cleanups | |
96 | * - moved request_irq behind controller initialization | |
97 | * (to avoid spurious interrupts) | |
98 | * | |
99 | * Revision 1.12 1995/12/16 12:26:07 fischer | |
100 | * - barrier()s added | |
101 | * - configurable RESET delay added | |
102 | * | |
103 | * Revision 1.11 1995/12/06 21:18:35 fischer | |
104 | * - some minor updates | |
105 | * | |
106 | * Revision 1.10 1995/07/22 19:18:45 fischer | |
107 | * - support for 2 controllers | |
108 | * - started synchronous data transfers (not working yet) | |
109 | * | |
110 | * Revision 1.9 1995/03/18 09:20:24 root | |
111 | * - patches for PCMCIA and modules | |
112 | * | |
113 | * Revision 1.8 1995/01/21 22:07:19 root | |
114 | * - snarf_region => request_region | |
115 | * - aha152x_intr interface change | |
116 | * | |
117 | * Revision 1.7 1995/01/02 23:19:36 root | |
118 | * - updated COMMAND_SIZE to cmd_len | |
119 | * - changed sti() to restore_flags() | |
120 | * - fixed some #ifdef which generated warnings | |
121 | * | |
122 | * Revision 1.6 1994/11/24 20:35:27 root | |
123 | * - problem with odd number of bytes in fifo fixed | |
124 | * | |
125 | * Revision 1.5 1994/10/30 14:39:56 root | |
126 | * - abort code fixed | |
127 | * - debugging improved | |
128 | * | |
129 | * Revision 1.4 1994/09/12 11:33:01 root | |
130 | * - irqaction to request_irq | |
131 | * - abortion updated | |
132 | * | |
133 | * Revision 1.3 1994/08/04 13:53:05 root | |
134 | * - updates for mid-level-driver changes | |
135 | * - accept unexpected BUSFREE phase as error condition | |
136 | * - parity check now configurable | |
137 | * | |
138 | * Revision 1.2 1994/07/03 12:56:36 root | |
139 | * - cleaned up debugging code | |
140 | * - more tweaking on reset delays | |
141 | * - updated abort/reset code (pretty untested...) | |
142 | * | |
143 | * Revision 1.1 1994/05/28 21:18:49 root | |
144 | * - update for mid-level interface change (abort-reset) | |
145 | * - delays after resets adjusted for some slow devices | |
146 | * | |
147 | * Revision 1.0 1994/03/25 12:52:00 root | |
148 | * - Fixed "more data than expected" problem | |
149 | * - added new BIOS signatures | |
150 | * | |
151 | * Revision 0.102 1994/01/31 20:44:12 root | |
152 | * - minor changes in insw/outsw handling | |
153 | * | |
154 | * Revision 0.101 1993/12/13 01:16:27 root | |
155 | * - fixed STATUS phase (non-GOOD stati were dropped sometimes; | |
156 | * fixes problems with CD-ROM sector size detection & media change) | |
157 | * | |
158 | * Revision 0.100 1993/12/10 16:58:47 root | |
159 | * - fix for unsuccessful selections in case of non-continuous id assignments | |
160 | * on the scsi bus. | |
161 | * | |
162 | * Revision 0.99 1993/10/24 16:19:59 root | |
163 | * - fixed DATA IN (rare read errors gone) | |
164 | * | |
165 | * Revision 0.98 1993/10/17 12:54:44 root | |
166 | * - fixed some recent fixes (shame on me) | |
167 | * - moved initialization of scratch area to aha152x_queue | |
168 | * | |
169 | * Revision 0.97 1993/10/09 18:53:53 root | |
170 | * - DATA IN fixed. Rarely left data in the fifo. | |
171 | * | |
172 | * Revision 0.96 1993/10/03 00:53:59 root | |
173 | * - minor changes on DATA IN | |
174 | * | |
175 | * Revision 0.95 1993/09/24 10:36:01 root | |
176 | * - change handling of MSGI after reselection | |
177 | * - fixed sti/cli | |
178 | * - minor changes | |
179 | * | |
180 | * Revision 0.94 1993/09/18 14:08:22 root | |
181 | * - fixed bug in multiple outstanding command code | |
182 | * - changed detection | |
183 | * - support for kernel command line configuration | |
184 | * - reset corrected | |
185 | * - changed message handling | |
186 | * | |
187 | * Revision 0.93 1993/09/15 20:41:19 root | |
188 | * - fixed bugs with multiple outstanding commands | |
189 | * | |
190 | * Revision 0.92 1993/09/13 02:46:33 root | |
191 | * - multiple outstanding commands work (no problems with IBM drive) | |
192 | * | |
193 | * Revision 0.91 1993/09/12 20:51:46 root | |
194 | * added multiple outstanding commands | |
195 | * (some problem with this $%&? IBM device remain) | |
196 | * | |
197 | * Revision 0.9 1993/09/12 11:11:22 root | |
198 | * - corrected auto-configuration | |
199 | * - changed the auto-configuration (added some '#define's) | |
200 | * - added support for dis-/reconnection | |
201 | * | |
202 | * Revision 0.8 1993/09/06 23:09:39 root | |
203 | * - added support for the drive activity light | |
204 | * - minor changes | |
205 | * | |
206 | * Revision 0.7 1993/09/05 14:30:15 root | |
207 | * - improved phase detection | |
208 | * - now using the new snarf_region code of 0.99pl13 | |
209 | * | |
210 | * Revision 0.6 1993/09/02 11:01:38 root | |
211 | * first public release; added some signatures and biosparam() | |
212 | * | |
213 | * Revision 0.5 1993/08/30 10:23:30 root | |
214 | * fixed timing problems with my IBM drive | |
215 | * | |
216 | * Revision 0.4 1993/08/29 14:06:52 root | |
217 | * fixed some problems with timeouts due incomplete commands | |
218 | * | |
219 | * Revision 0.3 1993/08/28 15:55:03 root | |
220 | * writing data works too. mounted and worked on a dos partition | |
221 | * | |
222 | * Revision 0.2 1993/08/27 22:42:07 root | |
223 | * reading data works. Mounted a msdos partition. | |
224 | * | |
225 | * Revision 0.1 1993/08/25 13:38:30 root | |
226 | * first "damn thing doesn't work" version | |
227 | * | |
228 | * Revision 0.0 1993/08/14 19:54:25 root | |
229 | * empty function bodies; detect() works. | |
230 | * | |
231 | * | |
232 | ************************************************************************** | |
f75ae8ed | 233 | |
1da177e4 LT |
234 | see Documentation/scsi/aha152x.txt for configuration details |
235 | ||
236 | **************************************************************************/ | |
237 | ||
238 | #include <linux/module.h> | |
1da177e4 | 239 | #include <asm/irq.h> |
53d5ed62 | 240 | #include <linux/io.h> |
1da177e4 | 241 | #include <linux/blkdev.h> |
0f06bb34 | 242 | #include <linux/completion.h> |
1da177e4 LT |
243 | #include <linux/errno.h> |
244 | #include <linux/string.h> | |
245 | #include <linux/wait.h> | |
246 | #include <linux/ioport.h> | |
247 | #include <linux/delay.h> | |
248 | #include <linux/proc_fs.h> | |
249 | #include <linux/interrupt.h> | |
250 | #include <linux/init.h> | |
251 | #include <linux/kernel.h> | |
252 | #include <linux/isapnp.h> | |
253 | #include <linux/spinlock.h> | |
254 | #include <linux/workqueue.h> | |
5fcda422 | 255 | #include <linux/list.h> |
5a0e3ad6 | 256 | #include <linux/slab.h> |
1da177e4 LT |
257 | #include <scsi/scsicam.h> |
258 | ||
259 | #include "scsi.h" | |
db9dff36 | 260 | #include <scsi/scsi_dbg.h> |
1da177e4 | 261 | #include <scsi/scsi_host.h> |
1abfd370 | 262 | #include <scsi/scsi_transport_spi.h> |
73d2cb16 | 263 | #include <scsi/scsi_eh.h> |
1da177e4 LT |
264 | #include "aha152x.h" |
265 | ||
5fcda422 JB |
266 | static LIST_HEAD(aha152x_host_list); |
267 | ||
1da177e4 LT |
268 | |
269 | /* DEFINES */ | |
270 | ||
271 | /* For PCMCIA cards, always use AUTOCONF */ | |
272 | #if defined(PCMCIA) || defined(MODULE) | |
273 | #if !defined(AUTOCONF) | |
274 | #define AUTOCONF | |
275 | #endif | |
276 | #endif | |
277 | ||
278 | #if !defined(AUTOCONF) && !defined(SETUP0) | |
279 | #error define AUTOCONF or SETUP0 | |
280 | #endif | |
281 | ||
1da177e4 LT |
282 | #define DO_LOCK(flags) spin_lock_irqsave(&QLOCK,flags) |
283 | #define DO_UNLOCK(flags) spin_unlock_irqrestore(&QLOCK,flags) | |
1da177e4 LT |
284 | |
285 | #define LEAD "(scsi%d:%d:%d) " | |
1da177e4 | 286 | #define INFO_LEAD KERN_INFO LEAD |
1da177e4 LT |
287 | #define CMDINFO(cmd) \ |
288 | (cmd) ? ((cmd)->device->host->host_no) : -1, \ | |
289 | (cmd) ? ((cmd)->device->id & 0x0f) : -1, \ | |
9cb78c16 | 290 | (cmd) ? ((u8)(cmd)->device->lun & 0x07) : -1 |
1da177e4 | 291 | |
2338545a BH |
292 | static inline void |
293 | CMD_INC_RESID(struct scsi_cmnd *cmd, int inc) | |
294 | { | |
295 | scsi_set_resid(cmd, scsi_get_resid(cmd) + inc); | |
296 | } | |
297 | ||
1da177e4 LT |
298 | #define DELAY_DEFAULT 1000 |
299 | ||
300 | #if defined(PCMCIA) | |
301 | #define IRQ_MIN 0 | |
302 | #define IRQ_MAX 16 | |
303 | #else | |
304 | #define IRQ_MIN 9 | |
305 | #if defined(__PPC) | |
171ac6ae | 306 | #define IRQ_MAX (nr_irqs-1) |
1da177e4 LT |
307 | #else |
308 | #define IRQ_MAX 12 | |
309 | #endif | |
310 | #endif | |
311 | ||
312 | enum { | |
313 | not_issued = 0x0001, /* command not yet issued */ | |
f75ae8ed | 314 | selecting = 0x0002, /* target is being selected */ |
1da177e4 LT |
315 | identified = 0x0004, /* IDENTIFY was sent */ |
316 | disconnected = 0x0008, /* target disconnected */ | |
f75ae8ed | 317 | completed = 0x0010, /* target sent COMMAND COMPLETE */ |
1da177e4 LT |
318 | aborted = 0x0020, /* ABORT was sent */ |
319 | resetted = 0x0040, /* BUS DEVICE RESET was sent */ | |
320 | spiordy = 0x0080, /* waiting for SPIORDY to raise */ | |
321 | syncneg = 0x0100, /* synchronous negotiation in progress */ | |
322 | aborting = 0x0200, /* ABORT is pending */ | |
323 | resetting = 0x0400, /* BUS DEVICE RESET is pending */ | |
324 | check_condition = 0x0800, /* requesting sense after CHECK CONDITION */ | |
325 | }; | |
326 | ||
96de0e25 | 327 | MODULE_AUTHOR("Jürgen Fischer"); |
1da177e4 LT |
328 | MODULE_DESCRIPTION(AHA152X_REVID); |
329 | MODULE_LICENSE("GPL"); | |
330 | ||
331 | #if !defined(PCMCIA) | |
332 | #if defined(MODULE) | |
333 | static int io[] = {0, 0}; | |
88f06b76 | 334 | module_param_hw_array(io, int, ioport, NULL, 0); |
1da177e4 LT |
335 | MODULE_PARM_DESC(io,"base io address of controller"); |
336 | ||
337 | static int irq[] = {0, 0}; | |
88f06b76 | 338 | module_param_hw_array(irq, int, irq, NULL, 0); |
1da177e4 LT |
339 | MODULE_PARM_DESC(irq,"interrupt for controller"); |
340 | ||
341 | static int scsiid[] = {7, 7}; | |
342 | module_param_array(scsiid, int, NULL, 0); | |
343 | MODULE_PARM_DESC(scsiid,"scsi id of controller"); | |
344 | ||
345 | static int reconnect[] = {1, 1}; | |
346 | module_param_array(reconnect, int, NULL, 0); | |
347 | MODULE_PARM_DESC(reconnect,"allow targets to disconnect"); | |
348 | ||
349 | static int parity[] = {1, 1}; | |
350 | module_param_array(parity, int, NULL, 0); | |
351 | MODULE_PARM_DESC(parity,"use scsi parity"); | |
352 | ||
353 | static int sync[] = {1, 1}; | |
354 | module_param_array(sync, int, NULL, 0); | |
355 | MODULE_PARM_DESC(sync,"use synchronous transfers"); | |
356 | ||
357 | static int delay[] = {DELAY_DEFAULT, DELAY_DEFAULT}; | |
358 | module_param_array(delay, int, NULL, 0); | |
359 | MODULE_PARM_DESC(delay,"scsi reset delay"); | |
360 | ||
361 | static int exttrans[] = {0, 0}; | |
362 | module_param_array(exttrans, int, NULL, 0); | |
363 | MODULE_PARM_DESC(exttrans,"use extended translation"); | |
364 | ||
1da177e4 LT |
365 | static int aha152x[] = {0, 11, 7, 1, 1, 0, DELAY_DEFAULT, 0}; |
366 | module_param_array(aha152x, int, NULL, 0); | |
367 | MODULE_PARM_DESC(aha152x, "parameters for first controller"); | |
368 | ||
369 | static int aha152x1[] = {0, 11, 7, 1, 1, 0, DELAY_DEFAULT, 0}; | |
370 | module_param_array(aha152x1, int, NULL, 0); | |
371 | MODULE_PARM_DESC(aha152x1, "parameters for second controller"); | |
1da177e4 LT |
372 | #endif /* MODULE */ |
373 | ||
374 | #ifdef __ISAPNP__ | |
6f039790 | 375 | static struct isapnp_device_id id_table[] = { |
50f87f91 OZ |
376 | { ISAPNP_ANY_ID, ISAPNP_ANY_ID, ISAPNP_VENDOR('A', 'D', 'P'), ISAPNP_FUNCTION(0x1502), 0 }, |
377 | { ISAPNP_ANY_ID, ISAPNP_ANY_ID, ISAPNP_VENDOR('A', 'D', 'P'), ISAPNP_FUNCTION(0x1505), 0 }, | |
378 | { ISAPNP_ANY_ID, ISAPNP_ANY_ID, ISAPNP_VENDOR('A', 'D', 'P'), ISAPNP_FUNCTION(0x1510), 0 }, | |
379 | { ISAPNP_ANY_ID, ISAPNP_ANY_ID, ISAPNP_VENDOR('A', 'D', 'P'), ISAPNP_FUNCTION(0x1515), 0 }, | |
380 | { ISAPNP_ANY_ID, ISAPNP_ANY_ID, ISAPNP_VENDOR('A', 'D', 'P'), ISAPNP_FUNCTION(0x1520), 0 }, | |
381 | { ISAPNP_ANY_ID, ISAPNP_ANY_ID, ISAPNP_VENDOR('A', 'D', 'P'), ISAPNP_FUNCTION(0x2015), 0 }, | |
382 | { ISAPNP_ANY_ID, ISAPNP_ANY_ID, ISAPNP_VENDOR('A', 'D', 'P'), ISAPNP_FUNCTION(0x1522), 0 }, | |
383 | { ISAPNP_ANY_ID, ISAPNP_ANY_ID, ISAPNP_VENDOR('A', 'D', 'P'), ISAPNP_FUNCTION(0x2215), 0 }, | |
384 | { ISAPNP_ANY_ID, ISAPNP_ANY_ID, ISAPNP_VENDOR('A', 'D', 'P'), ISAPNP_FUNCTION(0x1530), 0 }, | |
385 | { ISAPNP_ANY_ID, ISAPNP_ANY_ID, ISAPNP_VENDOR('A', 'D', 'P'), ISAPNP_FUNCTION(0x3015), 0 }, | |
386 | { ISAPNP_ANY_ID, ISAPNP_ANY_ID, ISAPNP_VENDOR('A', 'D', 'P'), ISAPNP_FUNCTION(0x1532), 0 }, | |
387 | { ISAPNP_ANY_ID, ISAPNP_ANY_ID, ISAPNP_VENDOR('A', 'D', 'P'), ISAPNP_FUNCTION(0x3215), 0 }, | |
388 | { ISAPNP_ANY_ID, ISAPNP_ANY_ID, ISAPNP_VENDOR('A', 'D', 'P'), ISAPNP_FUNCTION(0x6360), 0 }, | |
1da177e4 LT |
389 | { ISAPNP_DEVICE_SINGLE_END, } |
390 | }; | |
391 | MODULE_DEVICE_TABLE(isapnp, id_table); | |
392 | #endif /* ISAPNP */ | |
393 | ||
394 | #endif /* !PCMCIA */ | |
395 | ||
d0be4a7d | 396 | static struct scsi_host_template aha152x_driver_template; |
1da177e4 LT |
397 | |
398 | /* | |
399 | * internal states of the host | |
400 | * | |
f75ae8ed | 401 | */ |
1da177e4 LT |
402 | enum aha152x_state { |
403 | idle=0, | |
404 | unknown, | |
405 | seldo, | |
406 | seldi, | |
407 | selto, | |
408 | busfree, | |
409 | msgo, | |
410 | cmd, | |
411 | msgi, | |
412 | status, | |
413 | datai, | |
414 | datao, | |
415 | parerr, | |
416 | rsti, | |
417 | maxstate | |
418 | }; | |
419 | ||
420 | /* | |
421 | * current state information of the host | |
422 | * | |
423 | */ | |
424 | struct aha152x_hostdata { | |
91ebc1fa | 425 | struct scsi_cmnd *issue_SC; |
1da177e4 LT |
426 | /* pending commands to issue */ |
427 | ||
91ebc1fa | 428 | struct scsi_cmnd *current_SC; |
1da177e4 LT |
429 | /* current command on the bus */ |
430 | ||
91ebc1fa | 431 | struct scsi_cmnd *disconnected_SC; |
1da177e4 LT |
432 | /* commands that disconnected */ |
433 | ||
91ebc1fa | 434 | struct scsi_cmnd *done_SC; |
1da177e4 LT |
435 | /* command that was completed */ |
436 | ||
437 | spinlock_t lock; | |
438 | /* host lock */ | |
439 | ||
1da177e4 | 440 | #if defined(AHA152X_STAT) |
f75ae8ed | 441 | int total_commands; |
1da177e4 LT |
442 | int disconnections; |
443 | int busfree_without_any_action; | |
444 | int busfree_without_old_command; | |
445 | int busfree_without_new_command; | |
446 | int busfree_without_done_command; | |
447 | int busfree_with_check_condition; | |
f75ae8ed HR |
448 | int count[maxstate]; |
449 | int count_trans[maxstate]; | |
1da177e4 LT |
450 | unsigned long time[maxstate]; |
451 | #endif | |
452 | ||
453 | int commands; /* current number of commands */ | |
454 | ||
455 | int reconnect; /* disconnection allowed */ | |
456 | int parity; /* parity checking enabled */ | |
457 | int synchronous; /* synchronous transferes enabled */ | |
458 | int delay; /* reset out delay */ | |
459 | int ext_trans; /* extended translation enabled */ | |
460 | ||
f75ae8ed | 461 | int swint; /* software-interrupt was fired during detect() */ |
1da177e4 LT |
462 | int service; /* bh needs to be run */ |
463 | int in_intr; /* bh is running */ | |
464 | ||
465 | /* current state, | |
466 | previous state, | |
467 | last state different from current state */ | |
468 | enum aha152x_state state, prevstate, laststate; | |
469 | ||
470 | int target; | |
471 | /* reconnecting target */ | |
472 | ||
473 | unsigned char syncrate[8]; | |
474 | /* current synchronous transfer agreements */ | |
475 | ||
476 | unsigned char syncneg[8]; | |
477 | /* 0: no negotiation; | |
478 | * 1: negotiation in progress; | |
479 | * 2: negotiation completed | |
480 | */ | |
481 | ||
482 | int cmd_i; | |
483 | /* number of sent bytes of current command */ | |
484 | ||
485 | int msgi_len; | |
486 | /* number of received message bytes */ | |
487 | unsigned char msgi[256]; | |
488 | /* received message bytes */ | |
489 | ||
f75ae8ed | 490 | int msgo_i, msgo_len; |
1da177e4 LT |
491 | /* number of sent bytes and length of current messages */ |
492 | unsigned char msgo[256]; | |
493 | /* pending messages */ | |
494 | ||
495 | int data_len; | |
496 | /* number of sent/received bytes in dataphase */ | |
497 | ||
498 | unsigned long io_port0; | |
499 | unsigned long io_port1; | |
500 | ||
501 | #ifdef __ISAPNP__ | |
502 | struct pnp_dev *pnpdev; | |
503 | #endif | |
5fcda422 | 504 | struct list_head host_list; |
1da177e4 LT |
505 | }; |
506 | ||
507 | ||
508 | /* | |
509 | * host specific command extension | |
510 | * | |
511 | */ | |
512 | struct aha152x_scdata { | |
91ebc1fa | 513 | struct scsi_cmnd *next; /* next sc in queue */ |
0f06bb34 | 514 | struct completion *done;/* semaphore to block on */ |
73d2cb16 | 515 | struct scsi_eh_save ses; |
1da177e4 LT |
516 | }; |
517 | ||
1da177e4 LT |
518 | /* access macros for hostdata */ |
519 | ||
520 | #define HOSTDATA(shpnt) ((struct aha152x_hostdata *) &shpnt->hostdata) | |
521 | ||
522 | #define HOSTNO ((shpnt)->host_no) | |
523 | ||
524 | #define CURRENT_SC (HOSTDATA(shpnt)->current_SC) | |
525 | #define DONE_SC (HOSTDATA(shpnt)->done_SC) | |
526 | #define ISSUE_SC (HOSTDATA(shpnt)->issue_SC) | |
527 | #define DISCONNECTED_SC (HOSTDATA(shpnt)->disconnected_SC) | |
528 | #define QLOCK (HOSTDATA(shpnt)->lock) | |
529 | #define QLOCKER (HOSTDATA(shpnt)->locker) | |
530 | #define QLOCKERL (HOSTDATA(shpnt)->lockerl) | |
531 | ||
532 | #define STATE (HOSTDATA(shpnt)->state) | |
533 | #define PREVSTATE (HOSTDATA(shpnt)->prevstate) | |
534 | #define LASTSTATE (HOSTDATA(shpnt)->laststate) | |
535 | ||
536 | #define RECONN_TARGET (HOSTDATA(shpnt)->target) | |
537 | ||
538 | #define CMD_I (HOSTDATA(shpnt)->cmd_i) | |
539 | ||
540 | #define MSGO(i) (HOSTDATA(shpnt)->msgo[i]) | |
541 | #define MSGO_I (HOSTDATA(shpnt)->msgo_i) | |
542 | #define MSGOLEN (HOSTDATA(shpnt)->msgo_len) | |
543 | #define ADDMSGO(x) (MSGOLEN<256 ? (void)(MSGO(MSGOLEN++)=x) : aha152x_error(shpnt,"MSGO overflow")) | |
544 | ||
545 | #define MSGI(i) (HOSTDATA(shpnt)->msgi[i]) | |
546 | #define MSGILEN (HOSTDATA(shpnt)->msgi_len) | |
547 | #define ADDMSGI(x) (MSGILEN<256 ? (void)(MSGI(MSGILEN++)=x) : aha152x_error(shpnt,"MSGI overflow")) | |
548 | ||
549 | #define DATA_LEN (HOSTDATA(shpnt)->data_len) | |
550 | ||
551 | #define SYNCRATE (HOSTDATA(shpnt)->syncrate[CURRENT_SC->device->id]) | |
552 | #define SYNCNEG (HOSTDATA(shpnt)->syncneg[CURRENT_SC->device->id]) | |
553 | ||
554 | #define DELAY (HOSTDATA(shpnt)->delay) | |
555 | #define EXT_TRANS (HOSTDATA(shpnt)->ext_trans) | |
556 | #define TC1550 (HOSTDATA(shpnt)->tc1550) | |
557 | #define RECONNECT (HOSTDATA(shpnt)->reconnect) | |
558 | #define PARITY (HOSTDATA(shpnt)->parity) | |
559 | #define SYNCHRONOUS (HOSTDATA(shpnt)->synchronous) | |
560 | ||
561 | #define HOSTIOPORT0 (HOSTDATA(shpnt)->io_port0) | |
562 | #define HOSTIOPORT1 (HOSTDATA(shpnt)->io_port1) | |
563 | ||
564 | #define SCDATA(SCpnt) ((struct aha152x_scdata *) (SCpnt)->host_scribble) | |
565 | #define SCNEXT(SCpnt) SCDATA(SCpnt)->next | |
0f06bb34 | 566 | #define SCSEM(SCpnt) SCDATA(SCpnt)->done |
1da177e4 | 567 | |
45711f1a | 568 | #define SG_ADDRESS(buffer) ((char *) sg_virt((buffer))) |
1da177e4 LT |
569 | |
570 | /* state handling */ | |
571 | static void seldi_run(struct Scsi_Host *shpnt); | |
572 | static void seldo_run(struct Scsi_Host *shpnt); | |
573 | static void selto_run(struct Scsi_Host *shpnt); | |
574 | static void busfree_run(struct Scsi_Host *shpnt); | |
575 | ||
576 | static void msgo_init(struct Scsi_Host *shpnt); | |
577 | static void msgo_run(struct Scsi_Host *shpnt); | |
578 | static void msgo_end(struct Scsi_Host *shpnt); | |
579 | ||
580 | static void cmd_init(struct Scsi_Host *shpnt); | |
581 | static void cmd_run(struct Scsi_Host *shpnt); | |
582 | static void cmd_end(struct Scsi_Host *shpnt); | |
583 | ||
584 | static void datai_init(struct Scsi_Host *shpnt); | |
585 | static void datai_run(struct Scsi_Host *shpnt); | |
586 | static void datai_end(struct Scsi_Host *shpnt); | |
587 | ||
588 | static void datao_init(struct Scsi_Host *shpnt); | |
589 | static void datao_run(struct Scsi_Host *shpnt); | |
590 | static void datao_end(struct Scsi_Host *shpnt); | |
591 | ||
592 | static void status_run(struct Scsi_Host *shpnt); | |
593 | ||
594 | static void msgi_run(struct Scsi_Host *shpnt); | |
595 | static void msgi_end(struct Scsi_Host *shpnt); | |
596 | ||
597 | static void parerr_run(struct Scsi_Host *shpnt); | |
598 | static void rsti_run(struct Scsi_Host *shpnt); | |
599 | ||
600 | static void is_complete(struct Scsi_Host *shpnt); | |
601 | ||
602 | /* | |
603 | * driver states | |
604 | * | |
605 | */ | |
606 | static struct { | |
607 | char *name; | |
608 | void (*init)(struct Scsi_Host *); | |
609 | void (*run)(struct Scsi_Host *); | |
610 | void (*end)(struct Scsi_Host *); | |
611 | int spio; | |
612 | } states[] = { | |
613 | { "idle", NULL, NULL, NULL, 0}, | |
614 | { "unknown", NULL, NULL, NULL, 0}, | |
615 | { "seldo", NULL, seldo_run, NULL, 0}, | |
616 | { "seldi", NULL, seldi_run, NULL, 0}, | |
617 | { "selto", NULL, selto_run, NULL, 0}, | |
618 | { "busfree", NULL, busfree_run, NULL, 0}, | |
619 | { "msgo", msgo_init, msgo_run, msgo_end, 1}, | |
620 | { "cmd", cmd_init, cmd_run, cmd_end, 1}, | |
621 | { "msgi", NULL, msgi_run, msgi_end, 1}, | |
622 | { "status", NULL, status_run, NULL, 1}, | |
623 | { "datai", datai_init, datai_run, datai_end, 0}, | |
624 | { "datao", datao_init, datao_run, datao_end, 0}, | |
625 | { "parerr", NULL, parerr_run, NULL, 0}, | |
626 | { "rsti", NULL, rsti_run, NULL, 0}, | |
627 | }; | |
628 | ||
629 | /* setup & interrupt */ | |
7d12e780 | 630 | static irqreturn_t intr(int irq, void *dev_id); |
1da177e4 LT |
631 | static void reset_ports(struct Scsi_Host *shpnt); |
632 | static void aha152x_error(struct Scsi_Host *shpnt, char *msg); | |
633 | static void done(struct Scsi_Host *shpnt, int error); | |
634 | ||
635 | /* diagnostics */ | |
91ebc1fa | 636 | static void show_command(struct scsi_cmnd * ptr); |
1da177e4 LT |
637 | static void show_queues(struct Scsi_Host *shpnt); |
638 | static void disp_enintr(struct Scsi_Host *shpnt); | |
639 | ||
640 | ||
641 | /* | |
642 | * queue services: | |
643 | * | |
644 | */ | |
91ebc1fa | 645 | static inline void append_SC(struct scsi_cmnd **SC, struct scsi_cmnd *new_SC) |
1da177e4 | 646 | { |
91ebc1fa | 647 | struct scsi_cmnd *end; |
1da177e4 LT |
648 | |
649 | SCNEXT(new_SC) = NULL; | |
650 | if (!*SC) | |
651 | *SC = new_SC; | |
652 | else { | |
653 | for (end = *SC; SCNEXT(end); end = SCNEXT(end)) | |
654 | ; | |
655 | SCNEXT(end) = new_SC; | |
656 | } | |
657 | } | |
658 | ||
91ebc1fa | 659 | static inline struct scsi_cmnd *remove_first_SC(struct scsi_cmnd ** SC) |
1da177e4 | 660 | { |
91ebc1fa | 661 | struct scsi_cmnd *ptr; |
1da177e4 LT |
662 | |
663 | ptr = *SC; | |
664 | if (ptr) { | |
665 | *SC = SCNEXT(*SC); | |
666 | SCNEXT(ptr)=NULL; | |
667 | } | |
668 | return ptr; | |
669 | } | |
670 | ||
91ebc1fa JT |
671 | static inline struct scsi_cmnd *remove_lun_SC(struct scsi_cmnd ** SC, |
672 | int target, int lun) | |
1da177e4 | 673 | { |
91ebc1fa | 674 | struct scsi_cmnd *ptr, *prev; |
1da177e4 LT |
675 | |
676 | for (ptr = *SC, prev = NULL; | |
677 | ptr && ((ptr->device->id != target) || (ptr->device->lun != lun)); | |
678 | prev = ptr, ptr = SCNEXT(ptr)) | |
679 | ; | |
680 | ||
681 | if (ptr) { | |
682 | if (prev) | |
683 | SCNEXT(prev) = SCNEXT(ptr); | |
684 | else | |
685 | *SC = SCNEXT(ptr); | |
686 | ||
687 | SCNEXT(ptr)=NULL; | |
688 | } | |
689 | ||
690 | return ptr; | |
691 | } | |
692 | ||
91ebc1fa JT |
693 | static inline struct scsi_cmnd *remove_SC(struct scsi_cmnd **SC, |
694 | struct scsi_cmnd *SCp) | |
1da177e4 | 695 | { |
91ebc1fa | 696 | struct scsi_cmnd *ptr, *prev; |
1da177e4 LT |
697 | |
698 | for (ptr = *SC, prev = NULL; | |
699 | ptr && SCp!=ptr; | |
700 | prev = ptr, ptr = SCNEXT(ptr)) | |
701 | ; | |
702 | ||
703 | if (ptr) { | |
704 | if (prev) | |
705 | SCNEXT(prev) = SCNEXT(ptr); | |
706 | else | |
707 | *SC = SCNEXT(ptr); | |
708 | ||
709 | SCNEXT(ptr)=NULL; | |
710 | } | |
711 | ||
712 | return ptr; | |
713 | } | |
714 | ||
7d12e780 | 715 | static irqreturn_t swintr(int irqno, void *dev_id) |
1da177e4 | 716 | { |
c7bec5ab | 717 | struct Scsi_Host *shpnt = dev_id; |
1da177e4 LT |
718 | |
719 | HOSTDATA(shpnt)->swint++; | |
720 | ||
721 | SETPORT(DMACNTRL0, INTEN); | |
722 | return IRQ_HANDLED; | |
723 | } | |
724 | ||
725 | struct Scsi_Host *aha152x_probe_one(struct aha152x_setup *setup) | |
726 | { | |
727 | struct Scsi_Host *shpnt; | |
728 | ||
729 | shpnt = scsi_host_alloc(&aha152x_driver_template, sizeof(struct aha152x_hostdata)); | |
730 | if (!shpnt) { | |
731 | printk(KERN_ERR "aha152x: scsi_host_alloc failed\n"); | |
732 | return NULL; | |
733 | } | |
734 | ||
1da177e4 | 735 | memset(HOSTDATA(shpnt), 0, sizeof *HOSTDATA(shpnt)); |
5fcda422 JB |
736 | INIT_LIST_HEAD(&HOSTDATA(shpnt)->host_list); |
737 | ||
738 | /* need to have host registered before triggering any interrupt */ | |
739 | list_add_tail(&HOSTDATA(shpnt)->host_list, &aha152x_host_list); | |
1da177e4 LT |
740 | |
741 | shpnt->io_port = setup->io_port; | |
742 | shpnt->n_io_port = IO_RANGE; | |
743 | shpnt->irq = setup->irq; | |
744 | ||
745 | if (!setup->tc1550) { | |
746 | HOSTIOPORT0 = setup->io_port; | |
747 | HOSTIOPORT1 = setup->io_port; | |
748 | } else { | |
749 | HOSTIOPORT0 = setup->io_port+0x10; | |
750 | HOSTIOPORT1 = setup->io_port-0x10; | |
751 | } | |
752 | ||
753 | spin_lock_init(&QLOCK); | |
754 | RECONNECT = setup->reconnect; | |
755 | SYNCHRONOUS = setup->synchronous; | |
756 | PARITY = setup->parity; | |
757 | DELAY = setup->delay; | |
758 | EXT_TRANS = setup->ext_trans; | |
759 | ||
1da177e4 LT |
760 | SETPORT(SCSIID, setup->scsiid << 4); |
761 | shpnt->this_id = setup->scsiid; | |
762 | ||
763 | if (setup->reconnect) | |
764 | shpnt->can_queue = AHA152X_MAXQUEUE; | |
765 | ||
766 | /* RESET OUT */ | |
767 | printk("aha152x: resetting bus...\n"); | |
768 | SETPORT(SCSISEQ, SCSIRSTO); | |
769 | mdelay(256); | |
770 | SETPORT(SCSISEQ, 0); | |
771 | mdelay(DELAY); | |
772 | ||
773 | reset_ports(shpnt); | |
774 | ||
775 | printk(KERN_INFO | |
776 | "aha152x%d%s: " | |
777 | "vital data: rev=%x, " | |
778 | "io=0x%03lx (0x%03lx/0x%03lx), " | |
779 | "irq=%d, " | |
780 | "scsiid=%d, " | |
781 | "reconnect=%s, " | |
782 | "parity=%s, " | |
783 | "synchronous=%s, " | |
784 | "delay=%d, " | |
785 | "extended translation=%s\n", | |
786 | shpnt->host_no, setup->tc1550 ? " (tc1550 mode)" : "", | |
787 | GETPORT(REV) & 0x7, | |
788 | shpnt->io_port, HOSTIOPORT0, HOSTIOPORT1, | |
789 | shpnt->irq, | |
790 | shpnt->this_id, | |
791 | RECONNECT ? "enabled" : "disabled", | |
792 | PARITY ? "enabled" : "disabled", | |
793 | SYNCHRONOUS ? "enabled" : "disabled", | |
794 | DELAY, | |
795 | EXT_TRANS ? "enabled" : "disabled"); | |
796 | ||
797 | /* not expecting any interrupts */ | |
798 | SETPORT(SIMODE0, 0); | |
799 | SETPORT(SIMODE1, 0); | |
800 | ||
4909cc2b | 801 | if (request_irq(shpnt->irq, swintr, IRQF_SHARED, "aha152x", shpnt)) { |
1da177e4 LT |
802 | printk(KERN_ERR "aha152x%d: irq %d busy.\n", shpnt->host_no, shpnt->irq); |
803 | goto out_host_put; | |
804 | } | |
805 | ||
806 | HOSTDATA(shpnt)->swint = 0; | |
807 | ||
808 | printk(KERN_INFO "aha152x%d: trying software interrupt, ", shpnt->host_no); | |
809 | ||
810 | mb(); | |
811 | SETPORT(DMACNTRL0, SWINT|INTEN); | |
812 | mdelay(1000); | |
813 | free_irq(shpnt->irq, shpnt); | |
814 | ||
815 | if (!HOSTDATA(shpnt)->swint) { | |
816 | if (TESTHI(DMASTAT, INTSTAT)) { | |
817 | printk("lost.\n"); | |
818 | } else { | |
819 | printk("failed.\n"); | |
820 | } | |
821 | ||
822 | SETPORT(DMACNTRL0, INTEN); | |
823 | ||
824 | printk(KERN_ERR "aha152x%d: irq %d possibly wrong. " | |
825 | "Please verify.\n", shpnt->host_no, shpnt->irq); | |
826 | goto out_host_put; | |
827 | } | |
828 | printk("ok.\n"); | |
829 | ||
830 | ||
831 | /* clear interrupts */ | |
832 | SETPORT(SSTAT0, 0x7f); | |
833 | SETPORT(SSTAT1, 0xef); | |
834 | ||
4909cc2b | 835 | if (request_irq(shpnt->irq, intr, IRQF_SHARED, "aha152x", shpnt)) { |
1da177e4 LT |
836 | printk(KERN_ERR "aha152x%d: failed to reassign irq %d.\n", shpnt->host_no, shpnt->irq); |
837 | goto out_host_put; | |
838 | } | |
839 | ||
840 | if( scsi_add_host(shpnt, NULL) ) { | |
841 | free_irq(shpnt->irq, shpnt); | |
842 | printk(KERN_ERR "aha152x%d: failed to add host.\n", shpnt->host_no); | |
843 | goto out_host_put; | |
844 | } | |
845 | ||
846 | scsi_scan_host(shpnt); | |
847 | ||
1da177e4 LT |
848 | return shpnt; |
849 | ||
850 | out_host_put: | |
5fcda422 | 851 | list_del(&HOSTDATA(shpnt)->host_list); |
1da177e4 LT |
852 | scsi_host_put(shpnt); |
853 | ||
854 | return NULL; | |
855 | } | |
856 | ||
857 | void aha152x_release(struct Scsi_Host *shpnt) | |
858 | { | |
1bd40573 | 859 | if (!shpnt) |
1da177e4 LT |
860 | return; |
861 | ||
1bd40573 | 862 | scsi_remove_host(shpnt); |
1da177e4 LT |
863 | if (shpnt->irq) |
864 | free_irq(shpnt->irq, shpnt); | |
865 | ||
866 | #if !defined(PCMCIA) | |
867 | if (shpnt->io_port) | |
868 | release_region(shpnt->io_port, IO_RANGE); | |
869 | #endif | |
870 | ||
871 | #ifdef __ISAPNP__ | |
872 | if (HOSTDATA(shpnt)->pnpdev) | |
873 | pnp_device_detach(HOSTDATA(shpnt)->pnpdev); | |
874 | #endif | |
875 | ||
5fcda422 | 876 | list_del(&HOSTDATA(shpnt)->host_list); |
1da177e4 LT |
877 | scsi_host_put(shpnt); |
878 | } | |
879 | ||
880 | ||
881 | /* | |
882 | * setup controller to generate interrupts depending | |
883 | * on current state (lock has to be acquired) | |
884 | * | |
f75ae8ed | 885 | */ |
1da177e4 LT |
886 | static int setup_expected_interrupts(struct Scsi_Host *shpnt) |
887 | { | |
888 | if(CURRENT_SC) { | |
889 | CURRENT_SC->SCp.phase |= 1 << 16; | |
f75ae8ed | 890 | |
1da177e4 | 891 | if(CURRENT_SC->SCp.phase & selecting) { |
1da177e4 LT |
892 | SETPORT(SSTAT1, SELTO); |
893 | SETPORT(SIMODE0, ENSELDO | (DISCONNECTED_SC ? ENSELDI : 0)); | |
894 | SETPORT(SIMODE1, ENSELTIMO); | |
895 | } else { | |
1da177e4 | 896 | SETPORT(SIMODE0, (CURRENT_SC->SCp.phase & spiordy) ? ENSPIORDY : 0); |
f75ae8ed | 897 | SETPORT(SIMODE1, ENPHASEMIS | ENSCSIRST | ENSCSIPERR | ENBUSFREE); |
1da177e4 LT |
898 | } |
899 | } else if(STATE==seldi) { | |
1da177e4 | 900 | SETPORT(SIMODE0, 0); |
f75ae8ed | 901 | SETPORT(SIMODE1, ENPHASEMIS | ENSCSIRST | ENSCSIPERR | ENBUSFREE); |
1da177e4 | 902 | } else { |
1da177e4 LT |
903 | SETPORT(SIMODE0, DISCONNECTED_SC ? ENSELDI : 0); |
904 | SETPORT(SIMODE1, ENSCSIRST | ( (ISSUE_SC||DONE_SC) ? ENBUSFREE : 0)); | |
905 | } | |
906 | ||
907 | if(!HOSTDATA(shpnt)->in_intr) | |
908 | SETBITS(DMACNTRL0, INTEN); | |
909 | ||
910 | return TESTHI(DMASTAT, INTSTAT); | |
911 | } | |
912 | ||
913 | ||
f75ae8ed | 914 | /* |
1da177e4 LT |
915 | * Queue a command and setup interrupts for a free bus. |
916 | */ | |
91ebc1fa JT |
917 | static int aha152x_internal_queue(struct scsi_cmnd *SCpnt, |
918 | struct completion *complete, | |
919 | int phase, void (*done)(struct scsi_cmnd *)) | |
1da177e4 LT |
920 | { |
921 | struct Scsi_Host *shpnt = SCpnt->device->host; | |
922 | unsigned long flags; | |
923 | ||
1da177e4 | 924 | SCpnt->scsi_done = done; |
1da177e4 | 925 | SCpnt->SCp.phase = not_issued | phase; |
0ceb4798 | 926 | SCpnt->SCp.Status = 0x1; /* Ilegal status by SCSI standard */ |
1da177e4 LT |
927 | SCpnt->SCp.Message = 0; |
928 | SCpnt->SCp.have_data_in = 0; | |
929 | SCpnt->SCp.sent_command = 0; | |
930 | ||
931 | if(SCpnt->SCp.phase & (resetting|check_condition)) { | |
172c122d | 932 | if (!SCpnt->host_scribble || SCSEM(SCpnt) || SCNEXT(SCpnt)) { |
f75ae8ed | 933 | scmd_printk(KERN_ERR, SCpnt, "cannot reuse command\n"); |
1da177e4 LT |
934 | return FAILED; |
935 | } | |
936 | } else { | |
937 | SCpnt->host_scribble = kmalloc(sizeof(struct aha152x_scdata), GFP_ATOMIC); | |
172c122d | 938 | if(!SCpnt->host_scribble) { |
f75ae8ed | 939 | scmd_printk(KERN_ERR, SCpnt, "allocation failed\n"); |
1da177e4 LT |
940 | return FAILED; |
941 | } | |
942 | } | |
943 | ||
944 | SCNEXT(SCpnt) = NULL; | |
0f06bb34 | 945 | SCSEM(SCpnt) = complete; |
1da177e4 LT |
946 | |
947 | /* setup scratch area | |
948 | SCp.ptr : buffer pointer | |
949 | SCp.this_residual : buffer length | |
950 | SCp.buffer : next buffer | |
951 | SCp.buffers_residual : left buffers in list | |
952 | SCp.phase : current state of the command */ | |
66acdb03 | 953 | |
73d2cb16 BH |
954 | if ((phase & resetting) || !scsi_sglist(SCpnt)) { |
955 | SCpnt->SCp.ptr = NULL; | |
956 | SCpnt->SCp.this_residual = 0; | |
957 | scsi_set_resid(SCpnt, 0); | |
66acdb03 BH |
958 | SCpnt->SCp.buffer = NULL; |
959 | SCpnt->SCp.buffers_residual = 0; | |
960 | } else { | |
2338545a BH |
961 | scsi_set_resid(SCpnt, scsi_bufflen(SCpnt)); |
962 | SCpnt->SCp.buffer = scsi_sglist(SCpnt); | |
1da177e4 LT |
963 | SCpnt->SCp.ptr = SG_ADDRESS(SCpnt->SCp.buffer); |
964 | SCpnt->SCp.this_residual = SCpnt->SCp.buffer->length; | |
2338545a | 965 | SCpnt->SCp.buffers_residual = scsi_sg_count(SCpnt) - 1; |
66acdb03 | 966 | } |
1da177e4 LT |
967 | |
968 | DO_LOCK(flags); | |
969 | ||
970 | #if defined(AHA152X_STAT) | |
971 | HOSTDATA(shpnt)->total_commands++; | |
972 | #endif | |
973 | ||
974 | /* Turn led on, when this is the first command. */ | |
975 | HOSTDATA(shpnt)->commands++; | |
976 | if (HOSTDATA(shpnt)->commands==1) | |
977 | SETPORT(PORTA, 1); | |
978 | ||
979 | append_SC(&ISSUE_SC, SCpnt); | |
980 | ||
981 | if(!HOSTDATA(shpnt)->in_intr) | |
982 | setup_expected_interrupts(shpnt); | |
983 | ||
984 | DO_UNLOCK(flags); | |
985 | ||
986 | return 0; | |
987 | } | |
988 | ||
989 | /* | |
990 | * queue a command | |
991 | * | |
992 | */ | |
91ebc1fa JT |
993 | static int aha152x_queue_lck(struct scsi_cmnd *SCpnt, |
994 | void (*done)(struct scsi_cmnd *)) | |
1da177e4 | 995 | { |
1da177e4 LT |
996 | return aha152x_internal_queue(SCpnt, NULL, 0, done); |
997 | } | |
998 | ||
f281233d JG |
999 | static DEF_SCSI_QCMD(aha152x_queue) |
1000 | ||
1da177e4 LT |
1001 | |
1002 | /* | |
1da177e4 LT |
1003 | * |
1004 | */ | |
91ebc1fa | 1005 | static void reset_done(struct scsi_cmnd *SCpnt) |
1da177e4 | 1006 | { |
1da177e4 | 1007 | if(SCSEM(SCpnt)) { |
0f06bb34 | 1008 | complete(SCSEM(SCpnt)); |
1da177e4 | 1009 | } else { |
0f06bb34 | 1010 | printk(KERN_ERR "aha152x: reset_done w/o completion\n"); |
1da177e4 LT |
1011 | } |
1012 | } | |
1013 | ||
1014 | /* | |
1015 | * Abort a command | |
1016 | * | |
1017 | */ | |
91ebc1fa | 1018 | static int aha152x_abort(struct scsi_cmnd *SCpnt) |
1da177e4 LT |
1019 | { |
1020 | struct Scsi_Host *shpnt = SCpnt->device->host; | |
91ebc1fa | 1021 | struct scsi_cmnd *ptr; |
1da177e4 LT |
1022 | unsigned long flags; |
1023 | ||
1da177e4 LT |
1024 | DO_LOCK(flags); |
1025 | ||
1026 | ptr=remove_SC(&ISSUE_SC, SCpnt); | |
1027 | ||
1028 | if(ptr) { | |
1da177e4 LT |
1029 | HOSTDATA(shpnt)->commands--; |
1030 | if (!HOSTDATA(shpnt)->commands) | |
1031 | SETPORT(PORTA, 0); | |
1032 | DO_UNLOCK(flags); | |
1033 | ||
1034 | kfree(SCpnt->host_scribble); | |
1035 | SCpnt->host_scribble=NULL; | |
1036 | ||
1037 | return SUCCESS; | |
f75ae8ed | 1038 | } |
1da177e4 LT |
1039 | |
1040 | DO_UNLOCK(flags); | |
1041 | ||
1042 | /* | |
1043 | * FIXME: | |
1044 | * for current command: queue ABORT for message out and raise ATN | |
1045 | * for disconnected command: pseudo SC with ABORT message or ABORT on reselection? | |
1046 | * | |
1047 | */ | |
1048 | ||
f75ae8ed HR |
1049 | scmd_printk(KERN_ERR, SCpnt, |
1050 | "cannot abort running or disconnected command\n"); | |
1da177e4 LT |
1051 | |
1052 | return FAILED; | |
1053 | } | |
1054 | ||
1da177e4 LT |
1055 | /* |
1056 | * Reset a device | |
1057 | * | |
1058 | */ | |
91ebc1fa | 1059 | static int aha152x_device_reset(struct scsi_cmnd * SCpnt) |
1da177e4 LT |
1060 | { |
1061 | struct Scsi_Host *shpnt = SCpnt->device->host; | |
0f06bb34 | 1062 | DECLARE_COMPLETION(done); |
1da177e4 | 1063 | int ret, issued, disconnected; |
631c228c | 1064 | unsigned char old_cmd_len = SCpnt->cmd_len; |
1da177e4 | 1065 | unsigned long flags; |
0f06bb34 | 1066 | unsigned long timeleft; |
1da177e4 | 1067 | |
1da177e4 | 1068 | if(CURRENT_SC==SCpnt) { |
f75ae8ed | 1069 | scmd_printk(KERN_ERR, SCpnt, "cannot reset current device\n"); |
1da177e4 LT |
1070 | return FAILED; |
1071 | } | |
1072 | ||
1073 | DO_LOCK(flags); | |
172c122d | 1074 | issued = remove_SC(&ISSUE_SC, SCpnt) == NULL; |
1da177e4 LT |
1075 | disconnected = issued && remove_SC(&DISCONNECTED_SC, SCpnt); |
1076 | DO_UNLOCK(flags); | |
1077 | ||
1078 | SCpnt->cmd_len = 0; | |
1da177e4 | 1079 | |
0f06bb34 | 1080 | aha152x_internal_queue(SCpnt, &done, resetting, reset_done); |
1da177e4 | 1081 | |
0f06bb34 CH |
1082 | timeleft = wait_for_completion_timeout(&done, 100*HZ); |
1083 | if (!timeleft) { | |
1084 | /* remove command from issue queue */ | |
1085 | DO_LOCK(flags); | |
1086 | remove_SC(&ISSUE_SC, SCpnt); | |
1087 | DO_UNLOCK(flags); | |
1088 | } | |
631c228c CH |
1089 | |
1090 | SCpnt->cmd_len = old_cmd_len; | |
1da177e4 LT |
1091 | |
1092 | DO_LOCK(flags); | |
1093 | ||
1094 | if(SCpnt->SCp.phase & resetted) { | |
1095 | HOSTDATA(shpnt)->commands--; | |
1096 | if (!HOSTDATA(shpnt)->commands) | |
1097 | SETPORT(PORTA, 0); | |
1098 | kfree(SCpnt->host_scribble); | |
1099 | SCpnt->host_scribble=NULL; | |
1100 | ||
1101 | ret = SUCCESS; | |
1102 | } else { | |
1103 | /* requeue */ | |
1104 | if(!issued) { | |
1105 | append_SC(&ISSUE_SC, SCpnt); | |
1106 | } else if(disconnected) { | |
1107 | append_SC(&DISCONNECTED_SC, SCpnt); | |
1108 | } | |
f75ae8ed | 1109 | |
1da177e4 LT |
1110 | ret = FAILED; |
1111 | } | |
1112 | ||
1113 | DO_UNLOCK(flags); | |
1da177e4 LT |
1114 | return ret; |
1115 | } | |
1116 | ||
91ebc1fa JT |
1117 | static void free_hard_reset_SCs(struct Scsi_Host *shpnt, |
1118 | struct scsi_cmnd **SCs) | |
1da177e4 | 1119 | { |
91ebc1fa | 1120 | struct scsi_cmnd *ptr; |
1da177e4 LT |
1121 | |
1122 | ptr=*SCs; | |
1123 | while(ptr) { | |
91ebc1fa | 1124 | struct scsi_cmnd *next; |
1da177e4 LT |
1125 | |
1126 | if(SCDATA(ptr)) { | |
1127 | next = SCNEXT(ptr); | |
1128 | } else { | |
f75ae8ed HR |
1129 | scmd_printk(KERN_DEBUG, ptr, |
1130 | "queue corrupted at %p\n", ptr); | |
1da177e4 LT |
1131 | next = NULL; |
1132 | } | |
1133 | ||
1134 | if (!ptr->device->soft_reset) { | |
1da177e4 LT |
1135 | remove_SC(SCs, ptr); |
1136 | HOSTDATA(shpnt)->commands--; | |
1137 | kfree(ptr->host_scribble); | |
1138 | ptr->host_scribble=NULL; | |
1139 | } | |
1140 | ||
1141 | ptr = next; | |
1142 | } | |
1143 | } | |
1144 | ||
1145 | /* | |
1146 | * Reset the bus | |
1147 | * | |
819f80c9 HR |
1148 | * AIC-6260 has a hard reset (MRST signal), but apparently |
1149 | * one cannot trigger it via software. So live with | |
1150 | * a soft reset; no-one seemed to have cared. | |
1da177e4 | 1151 | */ |