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 | ************************************************************************** | |
233 | ||
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 LT |
241 | #include <linux/blkdev.h> |
242 | #include <asm/system.h> | |
0f06bb34 | 243 | #include <linux/completion.h> |
1da177e4 LT |
244 | #include <linux/errno.h> |
245 | #include <linux/string.h> | |
246 | #include <linux/wait.h> | |
247 | #include <linux/ioport.h> | |
248 | #include <linux/delay.h> | |
249 | #include <linux/proc_fs.h> | |
250 | #include <linux/interrupt.h> | |
251 | #include <linux/init.h> | |
252 | #include <linux/kernel.h> | |
253 | #include <linux/isapnp.h> | |
254 | #include <linux/spinlock.h> | |
255 | #include <linux/workqueue.h> | |
5fcda422 | 256 | #include <linux/list.h> |
5a0e3ad6 | 257 | #include <linux/slab.h> |
1da177e4 LT |
258 | #include <scsi/scsicam.h> |
259 | ||
260 | #include "scsi.h" | |
db9dff36 | 261 | #include <scsi/scsi_dbg.h> |
1da177e4 | 262 | #include <scsi/scsi_host.h> |
1abfd370 | 263 | #include <scsi/scsi_transport_spi.h> |
73d2cb16 | 264 | #include <scsi/scsi_eh.h> |
1da177e4 LT |
265 | #include "aha152x.h" |
266 | ||
5fcda422 JB |
267 | static LIST_HEAD(aha152x_host_list); |
268 | ||
1da177e4 LT |
269 | |
270 | /* DEFINES */ | |
271 | ||
272 | /* For PCMCIA cards, always use AUTOCONF */ | |
273 | #if defined(PCMCIA) || defined(MODULE) | |
274 | #if !defined(AUTOCONF) | |
275 | #define AUTOCONF | |
276 | #endif | |
277 | #endif | |
278 | ||
279 | #if !defined(AUTOCONF) && !defined(SETUP0) | |
280 | #error define AUTOCONF or SETUP0 | |
281 | #endif | |
282 | ||
283 | #if defined(AHA152X_DEBUG) | |
284 | #define DEBUG_DEFAULT debug_eh | |
285 | ||
286 | #define DPRINTK(when,msgs...) \ | |
287 | do { if(HOSTDATA(shpnt)->debug & (when)) printk(msgs); } while(0) | |
288 | ||
289 | #define DO_LOCK(flags) \ | |
290 | do { \ | |
291 | if(spin_is_locked(&QLOCK)) { \ | |
cadbd4a5 | 292 | DPRINTK(debug_intr, DEBUG_LEAD "(%s:%d) already locked at %s:%d\n", CMDINFO(CURRENT_SC), __func__, __LINE__, QLOCKER, QLOCKERL); \ |
1da177e4 | 293 | } \ |
cadbd4a5 | 294 | DPRINTK(debug_locking, DEBUG_LEAD "(%s:%d) locking\n", CMDINFO(CURRENT_SC), __func__, __LINE__); \ |
1da177e4 | 295 | spin_lock_irqsave(&QLOCK,flags); \ |
cadbd4a5 HH |
296 | DPRINTK(debug_locking, DEBUG_LEAD "(%s:%d) locked\n", CMDINFO(CURRENT_SC), __func__, __LINE__); \ |
297 | QLOCKER=__func__; \ | |
1da177e4 LT |
298 | QLOCKERL=__LINE__; \ |
299 | } while(0) | |
300 | ||
301 | #define DO_UNLOCK(flags) \ | |
302 | do { \ | |
cadbd4a5 | 303 | DPRINTK(debug_locking, DEBUG_LEAD "(%s:%d) unlocking (locked at %s:%d)\n", CMDINFO(CURRENT_SC), __func__, __LINE__, QLOCKER, QLOCKERL); \ |
1da177e4 | 304 | spin_unlock_irqrestore(&QLOCK,flags); \ |
cadbd4a5 | 305 | DPRINTK(debug_locking, DEBUG_LEAD "(%s:%d) unlocked\n", CMDINFO(CURRENT_SC), __func__, __LINE__); \ |
1da177e4 LT |
306 | QLOCKER="(not locked)"; \ |
307 | QLOCKERL=0; \ | |
308 | } while(0) | |
309 | ||
310 | #else | |
311 | #define DPRINTK(when,msgs...) | |
312 | #define DO_LOCK(flags) spin_lock_irqsave(&QLOCK,flags) | |
313 | #define DO_UNLOCK(flags) spin_unlock_irqrestore(&QLOCK,flags) | |
314 | #endif | |
315 | ||
316 | #define LEAD "(scsi%d:%d:%d) " | |
317 | #define WARN_LEAD KERN_WARNING LEAD | |
318 | #define INFO_LEAD KERN_INFO LEAD | |
319 | #define NOTE_LEAD KERN_NOTICE LEAD | |
320 | #define ERR_LEAD KERN_ERR LEAD | |
321 | #define DEBUG_LEAD KERN_DEBUG LEAD | |
322 | #define CMDINFO(cmd) \ | |
323 | (cmd) ? ((cmd)->device->host->host_no) : -1, \ | |
324 | (cmd) ? ((cmd)->device->id & 0x0f) : -1, \ | |
325 | (cmd) ? ((cmd)->device->lun & 0x07) : -1 | |
326 | ||
2338545a BH |
327 | static inline void |
328 | CMD_INC_RESID(struct scsi_cmnd *cmd, int inc) | |
329 | { | |
330 | scsi_set_resid(cmd, scsi_get_resid(cmd) + inc); | |
331 | } | |
332 | ||
1da177e4 LT |
333 | #define DELAY_DEFAULT 1000 |
334 | ||
335 | #if defined(PCMCIA) | |
336 | #define IRQ_MIN 0 | |
337 | #define IRQ_MAX 16 | |
338 | #else | |
339 | #define IRQ_MIN 9 | |
340 | #if defined(__PPC) | |
171ac6ae | 341 | #define IRQ_MAX (nr_irqs-1) |
1da177e4 LT |
342 | #else |
343 | #define IRQ_MAX 12 | |
344 | #endif | |
345 | #endif | |
346 | ||
347 | enum { | |
348 | not_issued = 0x0001, /* command not yet issued */ | |
349 | selecting = 0x0002, /* target is beeing selected */ | |
350 | identified = 0x0004, /* IDENTIFY was sent */ | |
351 | disconnected = 0x0008, /* target disconnected */ | |
352 | completed = 0x0010, /* target sent COMMAND COMPLETE */ | |
353 | aborted = 0x0020, /* ABORT was sent */ | |
354 | resetted = 0x0040, /* BUS DEVICE RESET was sent */ | |
355 | spiordy = 0x0080, /* waiting for SPIORDY to raise */ | |
356 | syncneg = 0x0100, /* synchronous negotiation in progress */ | |
357 | aborting = 0x0200, /* ABORT is pending */ | |
358 | resetting = 0x0400, /* BUS DEVICE RESET is pending */ | |
359 | check_condition = 0x0800, /* requesting sense after CHECK CONDITION */ | |
360 | }; | |
361 | ||
96de0e25 | 362 | MODULE_AUTHOR("Jürgen Fischer"); |
1da177e4 LT |
363 | MODULE_DESCRIPTION(AHA152X_REVID); |
364 | MODULE_LICENSE("GPL"); | |
365 | ||
366 | #if !defined(PCMCIA) | |
367 | #if defined(MODULE) | |
368 | static int io[] = {0, 0}; | |
369 | module_param_array(io, int, NULL, 0); | |
370 | MODULE_PARM_DESC(io,"base io address of controller"); | |
371 | ||
372 | static int irq[] = {0, 0}; | |
373 | module_param_array(irq, int, NULL, 0); | |
374 | MODULE_PARM_DESC(irq,"interrupt for controller"); | |
375 | ||
376 | static int scsiid[] = {7, 7}; | |
377 | module_param_array(scsiid, int, NULL, 0); | |
378 | MODULE_PARM_DESC(scsiid,"scsi id of controller"); | |
379 | ||
380 | static int reconnect[] = {1, 1}; | |
381 | module_param_array(reconnect, int, NULL, 0); | |
382 | MODULE_PARM_DESC(reconnect,"allow targets to disconnect"); | |
383 | ||
384 | static int parity[] = {1, 1}; | |
385 | module_param_array(parity, int, NULL, 0); | |
386 | MODULE_PARM_DESC(parity,"use scsi parity"); | |
387 | ||
388 | static int sync[] = {1, 1}; | |
389 | module_param_array(sync, int, NULL, 0); | |
390 | MODULE_PARM_DESC(sync,"use synchronous transfers"); | |
391 | ||
392 | static int delay[] = {DELAY_DEFAULT, DELAY_DEFAULT}; | |
393 | module_param_array(delay, int, NULL, 0); | |
394 | MODULE_PARM_DESC(delay,"scsi reset delay"); | |
395 | ||
396 | static int exttrans[] = {0, 0}; | |
397 | module_param_array(exttrans, int, NULL, 0); | |
398 | MODULE_PARM_DESC(exttrans,"use extended translation"); | |
399 | ||
400 | #if !defined(AHA152X_DEBUG) | |
401 | static int aha152x[] = {0, 11, 7, 1, 1, 0, DELAY_DEFAULT, 0}; | |
402 | module_param_array(aha152x, int, NULL, 0); | |
403 | MODULE_PARM_DESC(aha152x, "parameters for first controller"); | |
404 | ||
405 | static int aha152x1[] = {0, 11, 7, 1, 1, 0, DELAY_DEFAULT, 0}; | |
406 | module_param_array(aha152x1, int, NULL, 0); | |
407 | MODULE_PARM_DESC(aha152x1, "parameters for second controller"); | |
408 | #else | |
409 | static int debug[] = {DEBUG_DEFAULT, DEBUG_DEFAULT}; | |
410 | module_param_array(debug, int, NULL, 0); | |
411 | MODULE_PARM_DESC(debug, "flags for driver debugging"); | |
412 | ||
413 | static int aha152x[] = {0, 11, 7, 1, 1, 1, DELAY_DEFAULT, 0, DEBUG_DEFAULT}; | |
414 | module_param_array(aha152x, int, NULL, 0); | |
415 | MODULE_PARM_DESC(aha152x, "parameters for first controller"); | |
416 | ||
417 | static int aha152x1[] = {0, 11, 7, 1, 1, 1, DELAY_DEFAULT, 0, DEBUG_DEFAULT}; | |
418 | module_param_array(aha152x1, int, NULL, 0); | |
419 | MODULE_PARM_DESC(aha152x1, "parameters for second controller"); | |
420 | #endif /* !defined(AHA152X_DEBUG) */ | |
421 | #endif /* MODULE */ | |
422 | ||
423 | #ifdef __ISAPNP__ | |
424 | static struct isapnp_device_id id_table[] __devinitdata = { | |
425 | { ISAPNP_ANY_ID, ISAPNP_ANY_ID, | |
426 | ISAPNP_VENDOR('A','D','P'), ISAPNP_FUNCTION(0x1505), 0 }, | |
427 | { ISAPNP_ANY_ID, ISAPNP_ANY_ID, | |
428 | ISAPNP_VENDOR('A','D','P'), ISAPNP_FUNCTION(0x1530), 0 }, | |
429 | { ISAPNP_DEVICE_SINGLE_END, } | |
430 | }; | |
431 | MODULE_DEVICE_TABLE(isapnp, id_table); | |
432 | #endif /* ISAPNP */ | |
433 | ||
434 | #endif /* !PCMCIA */ | |
435 | ||
d0be4a7d | 436 | static struct scsi_host_template aha152x_driver_template; |
1da177e4 LT |
437 | |
438 | /* | |
439 | * internal states of the host | |
440 | * | |
441 | */ | |
442 | enum aha152x_state { | |
443 | idle=0, | |
444 | unknown, | |
445 | seldo, | |
446 | seldi, | |
447 | selto, | |
448 | busfree, | |
449 | msgo, | |
450 | cmd, | |
451 | msgi, | |
452 | status, | |
453 | datai, | |
454 | datao, | |
455 | parerr, | |
456 | rsti, | |
457 | maxstate | |
458 | }; | |
459 | ||
460 | /* | |
461 | * current state information of the host | |
462 | * | |
463 | */ | |
464 | struct aha152x_hostdata { | |
465 | Scsi_Cmnd *issue_SC; | |
466 | /* pending commands to issue */ | |
467 | ||
468 | Scsi_Cmnd *current_SC; | |
469 | /* current command on the bus */ | |
470 | ||
471 | Scsi_Cmnd *disconnected_SC; | |
472 | /* commands that disconnected */ | |
473 | ||
474 | Scsi_Cmnd *done_SC; | |
475 | /* command that was completed */ | |
476 | ||
477 | spinlock_t lock; | |
478 | /* host lock */ | |
479 | ||
480 | #if defined(AHA152X_DEBUG) | |
481 | const char *locker; | |
482 | /* which function has the lock */ | |
483 | int lockerl; /* where did it get it */ | |
484 | ||
485 | int debug; /* current debugging setting */ | |
486 | #endif | |
487 | ||
488 | #if defined(AHA152X_STAT) | |
489 | int total_commands; | |
490 | int disconnections; | |
491 | int busfree_without_any_action; | |
492 | int busfree_without_old_command; | |
493 | int busfree_without_new_command; | |
494 | int busfree_without_done_command; | |
495 | int busfree_with_check_condition; | |
496 | int count[maxstate]; | |
497 | int count_trans[maxstate]; | |
498 | unsigned long time[maxstate]; | |
499 | #endif | |
500 | ||
501 | int commands; /* current number of commands */ | |
502 | ||
503 | int reconnect; /* disconnection allowed */ | |
504 | int parity; /* parity checking enabled */ | |
505 | int synchronous; /* synchronous transferes enabled */ | |
506 | int delay; /* reset out delay */ | |
507 | int ext_trans; /* extended translation enabled */ | |
508 | ||
509 | int swint; /* software-interrupt was fired during detect() */ | |
510 | int service; /* bh needs to be run */ | |
511 | int in_intr; /* bh is running */ | |
512 | ||
513 | /* current state, | |
514 | previous state, | |
515 | last state different from current state */ | |
516 | enum aha152x_state state, prevstate, laststate; | |
517 | ||
518 | int target; | |
519 | /* reconnecting target */ | |
520 | ||
521 | unsigned char syncrate[8]; | |
522 | /* current synchronous transfer agreements */ | |
523 | ||
524 | unsigned char syncneg[8]; | |
525 | /* 0: no negotiation; | |
526 | * 1: negotiation in progress; | |
527 | * 2: negotiation completed | |
528 | */ | |
529 | ||
530 | int cmd_i; | |
531 | /* number of sent bytes of current command */ | |
532 | ||
533 | int msgi_len; | |
534 | /* number of received message bytes */ | |
535 | unsigned char msgi[256]; | |
536 | /* received message bytes */ | |
537 | ||
538 | int msgo_i, msgo_len; | |
539 | /* number of sent bytes and length of current messages */ | |
540 | unsigned char msgo[256]; | |
541 | /* pending messages */ | |
542 | ||
543 | int data_len; | |
544 | /* number of sent/received bytes in dataphase */ | |
545 | ||
546 | unsigned long io_port0; | |
547 | unsigned long io_port1; | |
548 | ||
549 | #ifdef __ISAPNP__ | |
550 | struct pnp_dev *pnpdev; | |
551 | #endif | |
5fcda422 | 552 | struct list_head host_list; |
1da177e4 LT |
553 | }; |
554 | ||
555 | ||
556 | /* | |
557 | * host specific command extension | |
558 | * | |
559 | */ | |
560 | struct aha152x_scdata { | |
561 | Scsi_Cmnd *next; /* next sc in queue */ | |
0f06bb34 | 562 | struct completion *done;/* semaphore to block on */ |
73d2cb16 | 563 | struct scsi_eh_save ses; |
1da177e4 LT |
564 | }; |
565 | ||
1da177e4 LT |
566 | /* access macros for hostdata */ |
567 | ||
568 | #define HOSTDATA(shpnt) ((struct aha152x_hostdata *) &shpnt->hostdata) | |
569 | ||
570 | #define HOSTNO ((shpnt)->host_no) | |
571 | ||
572 | #define CURRENT_SC (HOSTDATA(shpnt)->current_SC) | |
573 | #define DONE_SC (HOSTDATA(shpnt)->done_SC) | |
574 | #define ISSUE_SC (HOSTDATA(shpnt)->issue_SC) | |
575 | #define DISCONNECTED_SC (HOSTDATA(shpnt)->disconnected_SC) | |
576 | #define QLOCK (HOSTDATA(shpnt)->lock) | |
577 | #define QLOCKER (HOSTDATA(shpnt)->locker) | |
578 | #define QLOCKERL (HOSTDATA(shpnt)->lockerl) | |
579 | ||
580 | #define STATE (HOSTDATA(shpnt)->state) | |
581 | #define PREVSTATE (HOSTDATA(shpnt)->prevstate) | |
582 | #define LASTSTATE (HOSTDATA(shpnt)->laststate) | |
583 | ||
584 | #define RECONN_TARGET (HOSTDATA(shpnt)->target) | |
585 | ||
586 | #define CMD_I (HOSTDATA(shpnt)->cmd_i) | |
587 | ||
588 | #define MSGO(i) (HOSTDATA(shpnt)->msgo[i]) | |
589 | #define MSGO_I (HOSTDATA(shpnt)->msgo_i) | |
590 | #define MSGOLEN (HOSTDATA(shpnt)->msgo_len) | |
591 | #define ADDMSGO(x) (MSGOLEN<256 ? (void)(MSGO(MSGOLEN++)=x) : aha152x_error(shpnt,"MSGO overflow")) | |
592 | ||
593 | #define MSGI(i) (HOSTDATA(shpnt)->msgi[i]) | |
594 | #define MSGILEN (HOSTDATA(shpnt)->msgi_len) | |
595 | #define ADDMSGI(x) (MSGILEN<256 ? (void)(MSGI(MSGILEN++)=x) : aha152x_error(shpnt,"MSGI overflow")) | |
596 | ||
597 | #define DATA_LEN (HOSTDATA(shpnt)->data_len) | |
598 | ||
599 | #define SYNCRATE (HOSTDATA(shpnt)->syncrate[CURRENT_SC->device->id]) | |
600 | #define SYNCNEG (HOSTDATA(shpnt)->syncneg[CURRENT_SC->device->id]) | |
601 | ||
602 | #define DELAY (HOSTDATA(shpnt)->delay) | |
603 | #define EXT_TRANS (HOSTDATA(shpnt)->ext_trans) | |
604 | #define TC1550 (HOSTDATA(shpnt)->tc1550) | |
605 | #define RECONNECT (HOSTDATA(shpnt)->reconnect) | |
606 | #define PARITY (HOSTDATA(shpnt)->parity) | |
607 | #define SYNCHRONOUS (HOSTDATA(shpnt)->synchronous) | |
608 | ||
609 | #define HOSTIOPORT0 (HOSTDATA(shpnt)->io_port0) | |
610 | #define HOSTIOPORT1 (HOSTDATA(shpnt)->io_port1) | |
611 | ||
612 | #define SCDATA(SCpnt) ((struct aha152x_scdata *) (SCpnt)->host_scribble) | |
613 | #define SCNEXT(SCpnt) SCDATA(SCpnt)->next | |
0f06bb34 | 614 | #define SCSEM(SCpnt) SCDATA(SCpnt)->done |
1da177e4 | 615 | |
45711f1a | 616 | #define SG_ADDRESS(buffer) ((char *) sg_virt((buffer))) |
1da177e4 LT |
617 | |
618 | /* state handling */ | |
619 | static void seldi_run(struct Scsi_Host *shpnt); | |
620 | static void seldo_run(struct Scsi_Host *shpnt); | |
621 | static void selto_run(struct Scsi_Host *shpnt); | |
622 | static void busfree_run(struct Scsi_Host *shpnt); | |
623 | ||
624 | static void msgo_init(struct Scsi_Host *shpnt); | |
625 | static void msgo_run(struct Scsi_Host *shpnt); | |
626 | static void msgo_end(struct Scsi_Host *shpnt); | |
627 | ||
628 | static void cmd_init(struct Scsi_Host *shpnt); | |
629 | static void cmd_run(struct Scsi_Host *shpnt); | |
630 | static void cmd_end(struct Scsi_Host *shpnt); | |
631 | ||
632 | static void datai_init(struct Scsi_Host *shpnt); | |
633 | static void datai_run(struct Scsi_Host *shpnt); | |
634 | static void datai_end(struct Scsi_Host *shpnt); | |
635 | ||
636 | static void datao_init(struct Scsi_Host *shpnt); | |
637 | static void datao_run(struct Scsi_Host *shpnt); | |
638 | static void datao_end(struct Scsi_Host *shpnt); | |
639 | ||
640 | static void status_run(struct Scsi_Host *shpnt); | |
641 | ||
642 | static void msgi_run(struct Scsi_Host *shpnt); | |
643 | static void msgi_end(struct Scsi_Host *shpnt); | |
644 | ||
645 | static void parerr_run(struct Scsi_Host *shpnt); | |
646 | static void rsti_run(struct Scsi_Host *shpnt); | |
647 | ||
648 | static void is_complete(struct Scsi_Host *shpnt); | |
649 | ||
650 | /* | |
651 | * driver states | |
652 | * | |
653 | */ | |
654 | static struct { | |
655 | char *name; | |
656 | void (*init)(struct Scsi_Host *); | |
657 | void (*run)(struct Scsi_Host *); | |
658 | void (*end)(struct Scsi_Host *); | |
659 | int spio; | |
660 | } states[] = { | |
661 | { "idle", NULL, NULL, NULL, 0}, | |
662 | { "unknown", NULL, NULL, NULL, 0}, | |
663 | { "seldo", NULL, seldo_run, NULL, 0}, | |
664 | { "seldi", NULL, seldi_run, NULL, 0}, | |
665 | { "selto", NULL, selto_run, NULL, 0}, | |
666 | { "busfree", NULL, busfree_run, NULL, 0}, | |
667 | { "msgo", msgo_init, msgo_run, msgo_end, 1}, | |
668 | { "cmd", cmd_init, cmd_run, cmd_end, 1}, | |
669 | { "msgi", NULL, msgi_run, msgi_end, 1}, | |
670 | { "status", NULL, status_run, NULL, 1}, | |
671 | { "datai", datai_init, datai_run, datai_end, 0}, | |
672 | { "datao", datao_init, datao_run, datao_end, 0}, | |
673 | { "parerr", NULL, parerr_run, NULL, 0}, | |
674 | { "rsti", NULL, rsti_run, NULL, 0}, | |
675 | }; | |
676 | ||
677 | /* setup & interrupt */ | |
7d12e780 | 678 | static irqreturn_t intr(int irq, void *dev_id); |
1da177e4 LT |
679 | static void reset_ports(struct Scsi_Host *shpnt); |
680 | static void aha152x_error(struct Scsi_Host *shpnt, char *msg); | |
681 | static void done(struct Scsi_Host *shpnt, int error); | |
682 | ||
683 | /* diagnostics */ | |
684 | static void disp_ports(struct Scsi_Host *shpnt); | |
685 | static void show_command(Scsi_Cmnd * ptr); | |
686 | static void show_queues(struct Scsi_Host *shpnt); | |
687 | static void disp_enintr(struct Scsi_Host *shpnt); | |
688 | ||
689 | ||
690 | /* | |
691 | * queue services: | |
692 | * | |
693 | */ | |
694 | static inline void append_SC(Scsi_Cmnd **SC, Scsi_Cmnd *new_SC) | |
695 | { | |
696 | Scsi_Cmnd *end; | |
697 | ||
698 | SCNEXT(new_SC) = NULL; | |
699 | if (!*SC) | |
700 | *SC = new_SC; | |
701 | else { | |
702 | for (end = *SC; SCNEXT(end); end = SCNEXT(end)) | |
703 | ; | |
704 | SCNEXT(end) = new_SC; | |
705 | } | |
706 | } | |
707 | ||
708 | static inline Scsi_Cmnd *remove_first_SC(Scsi_Cmnd ** SC) | |
709 | { | |
710 | Scsi_Cmnd *ptr; | |
711 | ||
712 | ptr = *SC; | |
713 | if (ptr) { | |
714 | *SC = SCNEXT(*SC); | |
715 | SCNEXT(ptr)=NULL; | |
716 | } | |
717 | return ptr; | |
718 | } | |
719 | ||
720 | static inline Scsi_Cmnd *remove_lun_SC(Scsi_Cmnd ** SC, int target, int lun) | |
721 | { | |
722 | Scsi_Cmnd *ptr, *prev; | |
723 | ||
724 | for (ptr = *SC, prev = NULL; | |
725 | ptr && ((ptr->device->id != target) || (ptr->device->lun != lun)); | |
726 | prev = ptr, ptr = SCNEXT(ptr)) | |
727 | ; | |
728 | ||
729 | if (ptr) { | |
730 | if (prev) | |
731 | SCNEXT(prev) = SCNEXT(ptr); | |
732 | else | |
733 | *SC = SCNEXT(ptr); | |
734 | ||
735 | SCNEXT(ptr)=NULL; | |
736 | } | |
737 | ||
738 | return ptr; | |
739 | } | |
740 | ||
741 | static inline Scsi_Cmnd *remove_SC(Scsi_Cmnd **SC, Scsi_Cmnd *SCp) | |
742 | { | |
743 | Scsi_Cmnd *ptr, *prev; | |
744 | ||
745 | for (ptr = *SC, prev = NULL; | |
746 | ptr && SCp!=ptr; | |
747 | prev = ptr, ptr = SCNEXT(ptr)) | |
748 | ; | |
749 | ||
750 | if (ptr) { | |
751 | if (prev) | |
752 | SCNEXT(prev) = SCNEXT(ptr); | |
753 | else | |
754 | *SC = SCNEXT(ptr); | |
755 | ||
756 | SCNEXT(ptr)=NULL; | |
757 | } | |
758 | ||
759 | return ptr; | |
760 | } | |
761 | ||
7d12e780 | 762 | static irqreturn_t swintr(int irqno, void *dev_id) |
1da177e4 | 763 | { |
c7bec5ab | 764 | struct Scsi_Host *shpnt = dev_id; |
1da177e4 LT |
765 | |
766 | HOSTDATA(shpnt)->swint++; | |
767 | ||
768 | SETPORT(DMACNTRL0, INTEN); | |
769 | return IRQ_HANDLED; | |
770 | } | |
771 | ||
772 | struct Scsi_Host *aha152x_probe_one(struct aha152x_setup *setup) | |
773 | { | |
774 | struct Scsi_Host *shpnt; | |
775 | ||
776 | shpnt = scsi_host_alloc(&aha152x_driver_template, sizeof(struct aha152x_hostdata)); | |
777 | if (!shpnt) { | |
778 | printk(KERN_ERR "aha152x: scsi_host_alloc failed\n"); | |
779 | return NULL; | |
780 | } | |
781 | ||
1da177e4 | 782 | memset(HOSTDATA(shpnt), 0, sizeof *HOSTDATA(shpnt)); |
5fcda422 JB |
783 | INIT_LIST_HEAD(&HOSTDATA(shpnt)->host_list); |
784 | ||
785 | /* need to have host registered before triggering any interrupt */ | |
786 | list_add_tail(&HOSTDATA(shpnt)->host_list, &aha152x_host_list); | |
1da177e4 LT |
787 | |
788 | shpnt->io_port = setup->io_port; | |
789 | shpnt->n_io_port = IO_RANGE; | |
790 | shpnt->irq = setup->irq; | |
791 | ||
792 | if (!setup->tc1550) { | |
793 | HOSTIOPORT0 = setup->io_port; | |
794 | HOSTIOPORT1 = setup->io_port; | |
795 | } else { | |
796 | HOSTIOPORT0 = setup->io_port+0x10; | |
797 | HOSTIOPORT1 = setup->io_port-0x10; | |
798 | } | |
799 | ||
800 | spin_lock_init(&QLOCK); | |
801 | RECONNECT = setup->reconnect; | |
802 | SYNCHRONOUS = setup->synchronous; | |
803 | PARITY = setup->parity; | |
804 | DELAY = setup->delay; | |
805 | EXT_TRANS = setup->ext_trans; | |
806 | ||
807 | #if defined(AHA152X_DEBUG) | |
808 | HOSTDATA(shpnt)->debug = setup->debug; | |
809 | #endif | |
810 | ||
811 | SETPORT(SCSIID, setup->scsiid << 4); | |
812 | shpnt->this_id = setup->scsiid; | |
813 | ||
814 | if (setup->reconnect) | |
815 | shpnt->can_queue = AHA152X_MAXQUEUE; | |
816 | ||
817 | /* RESET OUT */ | |
818 | printk("aha152x: resetting bus...\n"); | |
819 | SETPORT(SCSISEQ, SCSIRSTO); | |
820 | mdelay(256); | |
821 | SETPORT(SCSISEQ, 0); | |
822 | mdelay(DELAY); | |
823 | ||
824 | reset_ports(shpnt); | |
825 | ||
826 | printk(KERN_INFO | |
827 | "aha152x%d%s: " | |
828 | "vital data: rev=%x, " | |
829 | "io=0x%03lx (0x%03lx/0x%03lx), " | |
830 | "irq=%d, " | |
831 | "scsiid=%d, " | |
832 | "reconnect=%s, " | |
833 | "parity=%s, " | |
834 | "synchronous=%s, " | |
835 | "delay=%d, " | |
836 | "extended translation=%s\n", | |
837 | shpnt->host_no, setup->tc1550 ? " (tc1550 mode)" : "", | |
838 | GETPORT(REV) & 0x7, | |
839 | shpnt->io_port, HOSTIOPORT0, HOSTIOPORT1, | |
840 | shpnt->irq, | |
841 | shpnt->this_id, | |
842 | RECONNECT ? "enabled" : "disabled", | |
843 | PARITY ? "enabled" : "disabled", | |
844 | SYNCHRONOUS ? "enabled" : "disabled", | |
845 | DELAY, | |
846 | EXT_TRANS ? "enabled" : "disabled"); | |
847 | ||
848 | /* not expecting any interrupts */ | |
849 | SETPORT(SIMODE0, 0); | |
850 | SETPORT(SIMODE1, 0); | |
851 | ||
1d6f359a | 852 | if( request_irq(shpnt->irq, swintr, IRQF_DISABLED|IRQF_SHARED, "aha152x", shpnt) ) { |
1da177e4 LT |
853 | printk(KERN_ERR "aha152x%d: irq %d busy.\n", shpnt->host_no, shpnt->irq); |
854 | goto out_host_put; | |
855 | } | |
856 | ||
857 | HOSTDATA(shpnt)->swint = 0; | |
858 | ||
859 | printk(KERN_INFO "aha152x%d: trying software interrupt, ", shpnt->host_no); | |
860 | ||
861 | mb(); | |
862 | SETPORT(DMACNTRL0, SWINT|INTEN); | |
863 | mdelay(1000); | |
864 | free_irq(shpnt->irq, shpnt); | |
865 | ||
866 | if (!HOSTDATA(shpnt)->swint) { | |
867 | if (TESTHI(DMASTAT, INTSTAT)) { | |
868 | printk("lost.\n"); | |
869 | } else { | |
870 | printk("failed.\n"); | |
871 | } | |
872 | ||
873 | SETPORT(DMACNTRL0, INTEN); | |
874 | ||
875 | printk(KERN_ERR "aha152x%d: irq %d possibly wrong. " | |
876 | "Please verify.\n", shpnt->host_no, shpnt->irq); | |
877 | goto out_host_put; | |
878 | } | |
879 | printk("ok.\n"); | |
880 | ||
881 | ||
882 | /* clear interrupts */ | |
883 | SETPORT(SSTAT0, 0x7f); | |
884 | SETPORT(SSTAT1, 0xef); | |
885 | ||
1d6f359a | 886 | if ( request_irq(shpnt->irq, intr, IRQF_DISABLED|IRQF_SHARED, "aha152x", shpnt) ) { |
1da177e4 LT |
887 | printk(KERN_ERR "aha152x%d: failed to reassign irq %d.\n", shpnt->host_no, shpnt->irq); |
888 | goto out_host_put; | |
889 | } | |
890 | ||
891 | if( scsi_add_host(shpnt, NULL) ) { | |
892 | free_irq(shpnt->irq, shpnt); | |
893 | printk(KERN_ERR "aha152x%d: failed to add host.\n", shpnt->host_no); | |
894 | goto out_host_put; | |
895 | } | |
896 | ||
897 | scsi_scan_host(shpnt); | |
898 | ||
1da177e4 LT |
899 | return shpnt; |
900 | ||
901 | out_host_put: | |
5fcda422 | 902 | list_del(&HOSTDATA(shpnt)->host_list); |
1da177e4 LT |
903 | scsi_host_put(shpnt); |
904 | ||
905 | return NULL; | |
906 | } | |
907 | ||
908 | void aha152x_release(struct Scsi_Host *shpnt) | |
909 | { | |
1bd40573 | 910 | if (!shpnt) |
1da177e4 LT |
911 | return; |
912 | ||
1bd40573 | 913 | scsi_remove_host(shpnt); |
1da177e4 LT |
914 | if (shpnt->irq) |
915 | free_irq(shpnt->irq, shpnt); | |
916 | ||
917 | #if !defined(PCMCIA) | |
918 | if (shpnt->io_port) | |
919 | release_region(shpnt->io_port, IO_RANGE); | |
920 | #endif | |
921 | ||
922 | #ifdef __ISAPNP__ | |
923 | if (HOSTDATA(shpnt)->pnpdev) | |
924 | pnp_device_detach(HOSTDATA(shpnt)->pnpdev); | |
925 | #endif | |
926 | ||
5fcda422 | 927 | list_del(&HOSTDATA(shpnt)->host_list); |
1da177e4 LT |
928 | scsi_host_put(shpnt); |
929 | } | |
930 | ||
931 | ||
932 | /* | |
933 | * setup controller to generate interrupts depending | |
934 | * on current state (lock has to be acquired) | |
935 | * | |
936 | */ | |
937 | static int setup_expected_interrupts(struct Scsi_Host *shpnt) | |
938 | { | |
939 | if(CURRENT_SC) { | |
940 | CURRENT_SC->SCp.phase |= 1 << 16; | |
941 | ||
942 | if(CURRENT_SC->SCp.phase & selecting) { | |
943 | DPRINTK(debug_intr, DEBUG_LEAD "expecting: (seldo) (seltimo) (seldi)\n", CMDINFO(CURRENT_SC)); | |
944 | SETPORT(SSTAT1, SELTO); | |
945 | SETPORT(SIMODE0, ENSELDO | (DISCONNECTED_SC ? ENSELDI : 0)); | |
946 | SETPORT(SIMODE1, ENSELTIMO); | |
947 | } else { | |
948 | DPRINTK(debug_intr, DEBUG_LEAD "expecting: (phase change) (busfree) %s\n", CMDINFO(CURRENT_SC), CURRENT_SC->SCp.phase & spiordy ? "(spiordy)" : ""); | |
949 | SETPORT(SIMODE0, (CURRENT_SC->SCp.phase & spiordy) ? ENSPIORDY : 0); | |
950 | SETPORT(SIMODE1, ENPHASEMIS | ENSCSIRST | ENSCSIPERR | ENBUSFREE); | |
951 | } | |
952 | } else if(STATE==seldi) { | |
953 | DPRINTK(debug_intr, DEBUG_LEAD "expecting: (phase change) (identify)\n", CMDINFO(CURRENT_SC)); | |
954 | SETPORT(SIMODE0, 0); | |
955 | SETPORT(SIMODE1, ENPHASEMIS | ENSCSIRST | ENSCSIPERR | ENBUSFREE); | |
956 | } else { | |
957 | DPRINTK(debug_intr, DEBUG_LEAD "expecting: %s %s\n", | |
958 | CMDINFO(CURRENT_SC), | |
959 | DISCONNECTED_SC ? "(reselection)" : "", | |
960 | ISSUE_SC ? "(busfree)" : ""); | |
961 | SETPORT(SIMODE0, DISCONNECTED_SC ? ENSELDI : 0); | |
962 | SETPORT(SIMODE1, ENSCSIRST | ( (ISSUE_SC||DONE_SC) ? ENBUSFREE : 0)); | |
963 | } | |
964 | ||
965 | if(!HOSTDATA(shpnt)->in_intr) | |
966 | SETBITS(DMACNTRL0, INTEN); | |
967 | ||
968 | return TESTHI(DMASTAT, INTSTAT); | |
969 | } | |
970 | ||
971 | ||
972 | /* | |
973 | * Queue a command and setup interrupts for a free bus. | |
974 | */ | |
0f06bb34 CH |
975 | static int aha152x_internal_queue(Scsi_Cmnd *SCpnt, struct completion *complete, |
976 | int phase, void (*done)(Scsi_Cmnd *)) | |
1da177e4 LT |
977 | { |
978 | struct Scsi_Host *shpnt = SCpnt->device->host; | |
979 | unsigned long flags; | |
980 | ||
981 | #if defined(AHA152X_DEBUG) | |
982 | if (HOSTDATA(shpnt)->debug & debug_queue) { | |
983 | printk(INFO_LEAD "queue: %p; cmd_len=%d pieces=%d size=%u cmnd=", | |
2338545a BH |
984 | CMDINFO(SCpnt), SCpnt, SCpnt->cmd_len, |
985 | scsi_sg_count(SCpnt), scsi_bufflen(SCpnt)); | |
db9dff36 | 986 | __scsi_print_command(SCpnt->cmnd); |
1da177e4 LT |
987 | } |
988 | #endif | |
989 | ||
990 | SCpnt->scsi_done = done; | |
1da177e4 | 991 | SCpnt->SCp.phase = not_issued | phase; |
0ceb4798 | 992 | SCpnt->SCp.Status = 0x1; /* Ilegal status by SCSI standard */ |
1da177e4 LT |
993 | SCpnt->SCp.Message = 0; |
994 | SCpnt->SCp.have_data_in = 0; | |
995 | SCpnt->SCp.sent_command = 0; | |
996 | ||
997 | if(SCpnt->SCp.phase & (resetting|check_condition)) { | |
172c122d | 998 | if (!SCpnt->host_scribble || SCSEM(SCpnt) || SCNEXT(SCpnt)) { |
1da177e4 LT |
999 | printk(ERR_LEAD "cannot reuse command\n", CMDINFO(SCpnt)); |
1000 | return FAILED; | |
1001 | } | |
1002 | } else { | |
1003 | SCpnt->host_scribble = kmalloc(sizeof(struct aha152x_scdata), GFP_ATOMIC); | |
172c122d | 1004 | if(!SCpnt->host_scribble) { |
1da177e4 LT |
1005 | printk(ERR_LEAD "allocation failed\n", CMDINFO(SCpnt)); |
1006 | return FAILED; | |
1007 | } | |
1008 | } | |
1009 | ||
1010 | SCNEXT(SCpnt) = NULL; | |
0f06bb34 | 1011 | SCSEM(SCpnt) = complete; |
1da177e4 LT |
1012 | |
1013 | /* setup scratch area | |
1014 | SCp.ptr : buffer pointer | |
1015 | SCp.this_residual : buffer length | |
1016 | SCp.buffer : next buffer | |
1017 | SCp.buffers_residual : left buffers in list | |
1018 | SCp.phase : current state of the command */ | |
66acdb03 | 1019 | |
73d2cb16 BH |
1020 | if ((phase & resetting) || !scsi_sglist(SCpnt)) { |
1021 | SCpnt->SCp.ptr = NULL; | |
1022 | SCpnt->SCp.this_residual = 0; | |
1023 | scsi_set_resid(SCpnt, 0); | |
66acdb03 BH |
1024 | SCpnt->SCp.buffer = NULL; |
1025 | SCpnt->SCp.buffers_residual = 0; | |
1026 | } else { | |
2338545a BH |
1027 | scsi_set_resid(SCpnt, scsi_bufflen(SCpnt)); |
1028 | SCpnt->SCp.buffer = scsi_sglist(SCpnt); | |
1da177e4 LT |
1029 | SCpnt->SCp.ptr = SG_ADDRESS(SCpnt->SCp.buffer); |
1030 | SCpnt->SCp.this_residual = SCpnt->SCp.buffer->length; | |
2338545a | 1031 | SCpnt->SCp.buffers_residual = scsi_sg_count(SCpnt) - 1; |
66acdb03 | 1032 | } |
1da177e4 LT |
1033 | |
1034 | DO_LOCK(flags); | |
1035 | ||
1036 | #if defined(AHA152X_STAT) | |
1037 | HOSTDATA(shpnt)->total_commands++; | |
1038 | #endif | |
1039 | ||
1040 | /* Turn led on, when this is the first command. */ | |
1041 | HOSTDATA(shpnt)->commands++; | |
1042 | if (HOSTDATA(shpnt)->commands==1) | |
1043 | SETPORT(PORTA, 1); | |
1044 | ||
1045 | append_SC(&ISSUE_SC, SCpnt); | |
1046 | ||
1047 | if(!HOSTDATA(shpnt)->in_intr) | |
1048 | setup_expected_interrupts(shpnt); | |
1049 | ||
1050 | DO_UNLOCK(flags); | |
1051 | ||
1052 | return 0; | |
1053 | } | |
1054 | ||
1055 | /* | |
1056 | * queue a command | |
1057 | * | |
1058 | */ | |
f281233d | 1059 | static int aha152x_queue_lck(Scsi_Cmnd *SCpnt, void (*done)(Scsi_Cmnd *)) |
1da177e4 LT |
1060 | { |
1061 | #if 0 | |
1062 | if(*SCpnt->cmnd == REQUEST_SENSE) { | |
1063 | SCpnt->result = 0; | |
1064 | done(SCpnt); | |
1065 | ||
1066 | return 0; | |
1067 | } | |
1068 | #endif | |
1069 | ||
1070 | return aha152x_internal_queue(SCpnt, NULL, 0, done); | |
1071 | } | |
1072 | ||
f281233d JG |
1073 | static DEF_SCSI_QCMD(aha152x_queue) |
1074 | ||
1da177e4 LT |
1075 | |
1076 | /* | |
1077 | * | |
1078 | * | |
1079 | */ | |
1080 | static void reset_done(Scsi_Cmnd *SCpnt) | |
1081 | { | |
1082 | #if 0 | |
1083 | struct Scsi_Host *shpnt = SCpnt->host; | |
1084 | DPRINTK(debug_eh, INFO_LEAD "reset_done called\n", CMDINFO(SCpnt)); | |
1085 | #endif | |
1086 | if(SCSEM(SCpnt)) { | |
0f06bb34 | 1087 | complete(SCSEM(SCpnt)); |
1da177e4 | 1088 | } else { |
0f06bb34 | 1089 | printk(KERN_ERR "aha152x: reset_done w/o completion\n"); |
1da177e4 LT |
1090 | } |
1091 | } | |
1092 | ||
1093 | /* | |
1094 | * Abort a command | |
1095 | * | |
1096 | */ | |
1097 | static int aha152x_abort(Scsi_Cmnd *SCpnt) | |
1098 | { | |
1099 | struct Scsi_Host *shpnt = SCpnt->device->host; | |
1100 | Scsi_Cmnd *ptr; | |
1101 | unsigned long flags; | |
1102 | ||
1103 | #if defined(AHA152X_DEBUG) | |
1104 | if(HOSTDATA(shpnt)->debug & debug_eh) { | |
1105 | printk(DEBUG_LEAD "abort(%p)", CMDINFO(SCpnt), SCpnt); | |
1106 | show_queues(shpnt); | |
1107 | } | |
1108 | #endif | |
1109 | ||
1110 | DO_LOCK(flags); | |
1111 | ||
1112 | ptr=remove_SC(&ISSUE_SC, SCpnt); | |
1113 | ||
1114 | if(ptr) { | |
1115 | DPRINTK(debug_eh, DEBUG_LEAD "not yet issued - SUCCESS\n", CMDINFO(SCpnt)); | |
1116 | ||
1117 | HOSTDATA(shpnt)->commands--; | |
1118 | if (!HOSTDATA(shpnt)->commands) | |
1119 | SETPORT(PORTA, 0); | |
1120 | DO_UNLOCK(flags); | |
1121 | ||
1122 | kfree(SCpnt->host_scribble); | |
1123 | SCpnt->host_scribble=NULL; | |
1124 | ||
1125 | return SUCCESS; | |
1126 | } | |
1127 | ||
1128 | DO_UNLOCK(flags); | |
1129 | ||
1130 | /* | |
1131 | * FIXME: | |
1132 | * for current command: queue ABORT for message out and raise ATN | |
1133 | * for disconnected command: pseudo SC with ABORT message or ABORT on reselection? | |
1134 | * | |
1135 | */ | |
1136 | ||
1137 | printk(ERR_LEAD "cannot abort running or disconnected command\n", CMDINFO(SCpnt)); | |
1138 | ||
1139 | return FAILED; | |
1140 | } | |
1141 | ||
1da177e4 LT |
1142 | /* |
1143 | * Reset a device | |
1144 | * | |
1145 | */ | |
1146 | static int aha152x_device_reset(Scsi_Cmnd * SCpnt) | |
1147 | { | |
1148 | struct Scsi_Host *shpnt = SCpnt->device->host; | |
0f06bb34 | 1149 | DECLARE_COMPLETION(done); |
1da177e4 | 1150 | int ret, issued, disconnected; |
631c228c | 1151 | unsigned char old_cmd_len = SCpnt->cmd_len; |
1da177e4 | 1152 | unsigned long flags; |
0f06bb34 | 1153 | unsigned long timeleft; |
1da177e4 LT |
1154 | |
1155 | #if defined(AHA152X_DEBUG) | |
1156 | if(HOSTDATA(shpnt)->debug & debug_eh) { | |
1157 | printk(INFO_LEAD "aha152x_device_reset(%p)", CMDINFO(SCpnt), SCpnt); | |
1158 | show_queues(shpnt); | |
1159 | } | |
1160 | #endif | |
1161 | ||
1162 | if(CURRENT_SC==SCpnt) { | |
1163 | printk(ERR_LEAD "cannot reset current device\n", CMDINFO(SCpnt)); | |
1164 | return FAILED; | |
1165 | } | |
1166 | ||
1167 | DO_LOCK(flags); | |
172c122d | 1168 | issued = remove_SC(&ISSUE_SC, SCpnt) == NULL; |
1da177e4 LT |
1169 | disconnected = issued && remove_SC(&DISCONNECTED_SC, SCpnt); |
1170 | DO_UNLOCK(flags); | |
1171 | ||
1172 | SCpnt->cmd_len = 0; | |
1da177e4 | 1173 | |
0f06bb34 | 1174 | aha152x_internal_queue(SCpnt, &done, resetting, reset_done); |
1da177e4 | 1175 | |
0f06bb34 CH |
1176 | timeleft = wait_for_completion_timeout(&done, 100*HZ); |
1177 | if (!timeleft) { | |
1178 | /* remove command from issue queue */ | |
1179 | DO_LOCK(flags); | |
1180 | remove_SC(&ISSUE_SC, SCpnt); | |
1181 | DO_UNLOCK(flags); | |
1182 | } | |
631c228c CH |
1183 | |
1184 | SCpnt->cmd_len = old_cmd_len; | |
1da177e4 LT |
1185 | |
1186 | DO_LOCK(flags); | |
1187 | ||
1188 | if(SCpnt->SCp.phase & resetted) { | |
1189 | HOSTDATA(shpnt)->commands--; | |
1190 | if (!HOSTDATA(shpnt)->commands) | |
1191 | SETPORT(PORTA, 0); | |
1192 | kfree(SCpnt->host_scribble); | |
1193 | SCpnt->host_scribble=NULL; | |
1194 | ||
1195 | ret = SUCCESS; | |
1196 | } else { | |
1197 | /* requeue */ | |
1198 | if(!issued) { | |
1199 | append_SC(&ISSUE_SC, SCpnt); | |
1200 | } else if(disconnected) { | |
1201 | append_SC(&DISCONNECTED_SC, SCpnt); | |
1202 | } | |
1203 | ||
1204 | ret = FAILED; | |
1205 | } | |
1206 | ||
1207 | DO_UNLOCK(flags); | |
1da177e4 LT |
1208 | return ret; |
1209 | } | |
1210 | ||
1211 | static void free_hard_reset_SCs(struct Scsi_Host *shpnt, Scsi_Cmnd **SCs) | |
1212 | { | |
1213 | Scsi_Cmnd *ptr; | |
1214 | ||
1215 | ptr=*SCs; | |
1216 | while(ptr) { | |
1217 | Scsi_Cmnd *next; | |
1218 | ||
1219 | if(SCDATA(ptr)) { | |
1220 | next = SCNEXT(ptr); | |
1221 | } else { | |
1222 | printk(DEBUG_LEAD "queue corrupted at %p\n", CMDINFO(ptr), ptr); | |
1223 | next = NULL; | |
1224 | } | |
1225 | ||
1226 | if (!ptr->device->soft_reset) { | |
1227 | DPRINTK(debug_eh, DEBUG_LEAD "disconnected command %p removed\n", CMDINFO(ptr), ptr); | |
1228 | remove_SC(SCs, ptr); | |
1229 | HOSTDATA(shpnt)->commands--; | |
1230 | kfree(ptr->host_scribble); | |
1231 | ptr->host_scribble=NULL; | |
1232 | } | |
1233 | ||
1234 | ptr = next; | |
1235 | } | |
1236 | } | |
1237 | ||
1238 | /* | |
1239 | * Reset the bus | |
1240 | * | |
1241 | */ | |