]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blame - drivers/scsi/aha152x.c
[SCSI] add DID_REQUEUE string to scsi_show_result host table
[mirror_ubuntu-zesty-kernel.git] / drivers / scsi / aha152x.c
CommitLineData
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>
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>
1da177e4
LT
263#include "aha152x.h"
264
5fcda422
JB
265static LIST_HEAD(aha152x_host_list);
266
1da177e4
LT
267
268/* DEFINES */
269
270/* For PCMCIA cards, always use AUTOCONF */
271#if defined(PCMCIA) || defined(MODULE)
272#if !defined(AUTOCONF)
273#define AUTOCONF
274#endif
275#endif
276
277#if !defined(AUTOCONF) && !defined(SETUP0)
278#error define AUTOCONF or SETUP0
279#endif
280
281#if defined(AHA152X_DEBUG)
282#define DEBUG_DEFAULT debug_eh
283
284#define DPRINTK(when,msgs...) \
285 do { if(HOSTDATA(shpnt)->debug & (when)) printk(msgs); } while(0)
286
287#define DO_LOCK(flags) \
288 do { \
289 if(spin_is_locked(&QLOCK)) { \
290 DPRINTK(debug_intr, DEBUG_LEAD "(%s:%d) already locked at %s:%d\n", CMDINFO(CURRENT_SC), __FUNCTION__, __LINE__, QLOCKER, QLOCKERL); \
291 } \
50535df3 292 DPRINTK(debug_locking, DEBUG_LEAD "(%s:%d) locking\n", CMDINFO(CURRENT_SC), __FUNCTION__, __LINE__); \
1da177e4 293 spin_lock_irqsave(&QLOCK,flags); \
50535df3 294 DPRINTK(debug_locking, DEBUG_LEAD "(%s:%d) locked\n", CMDINFO(CURRENT_SC), __FUNCTION__, __LINE__); \
1da177e4
LT
295 QLOCKER=__FUNCTION__; \
296 QLOCKERL=__LINE__; \
297 } while(0)
298
299#define DO_UNLOCK(flags) \
300 do { \
50535df3 301 DPRINTK(debug_locking, DEBUG_LEAD "(%s:%d) unlocking (locked at %s:%d)\n", CMDINFO(CURRENT_SC), __FUNCTION__, __LINE__, QLOCKER, QLOCKERL); \
1da177e4 302 spin_unlock_irqrestore(&QLOCK,flags); \
50535df3 303 DPRINTK(debug_locking, DEBUG_LEAD "(%s:%d) unlocked\n", CMDINFO(CURRENT_SC), __FUNCTION__, __LINE__); \
1da177e4
LT
304 QLOCKER="(not locked)"; \
305 QLOCKERL=0; \
306 } while(0)
307
308#else
309#define DPRINTK(when,msgs...)
310#define DO_LOCK(flags) spin_lock_irqsave(&QLOCK,flags)
311#define DO_UNLOCK(flags) spin_unlock_irqrestore(&QLOCK,flags)
312#endif
313
314#define LEAD "(scsi%d:%d:%d) "
315#define WARN_LEAD KERN_WARNING LEAD
316#define INFO_LEAD KERN_INFO LEAD
317#define NOTE_LEAD KERN_NOTICE LEAD
318#define ERR_LEAD KERN_ERR LEAD
319#define DEBUG_LEAD KERN_DEBUG LEAD
320#define CMDINFO(cmd) \
321 (cmd) ? ((cmd)->device->host->host_no) : -1, \
322 (cmd) ? ((cmd)->device->id & 0x0f) : -1, \
323 (cmd) ? ((cmd)->device->lun & 0x07) : -1
324
2338545a
BH
325static inline void
326CMD_INC_RESID(struct scsi_cmnd *cmd, int inc)
327{
328 scsi_set_resid(cmd, scsi_get_resid(cmd) + inc);
329}
330
1da177e4
LT
331#define DELAY_DEFAULT 1000
332
333#if defined(PCMCIA)
334#define IRQ_MIN 0
335#define IRQ_MAX 16
336#else
337#define IRQ_MIN 9
338#if defined(__PPC)
339#define IRQ_MAX (NR_IRQS-1)
340#else
341#define IRQ_MAX 12
342#endif
343#endif
344
345enum {
346 not_issued = 0x0001, /* command not yet issued */
347 selecting = 0x0002, /* target is beeing selected */
348 identified = 0x0004, /* IDENTIFY was sent */
349 disconnected = 0x0008, /* target disconnected */
350 completed = 0x0010, /* target sent COMMAND COMPLETE */
351 aborted = 0x0020, /* ABORT was sent */
352 resetted = 0x0040, /* BUS DEVICE RESET was sent */
353 spiordy = 0x0080, /* waiting for SPIORDY to raise */
354 syncneg = 0x0100, /* synchronous negotiation in progress */
355 aborting = 0x0200, /* ABORT is pending */
356 resetting = 0x0400, /* BUS DEVICE RESET is pending */
357 check_condition = 0x0800, /* requesting sense after CHECK CONDITION */
358};
359
96de0e25 360MODULE_AUTHOR("Jürgen Fischer");
1da177e4
LT
361MODULE_DESCRIPTION(AHA152X_REVID);
362MODULE_LICENSE("GPL");
363
364#if !defined(PCMCIA)
365#if defined(MODULE)
366static int io[] = {0, 0};
367module_param_array(io, int, NULL, 0);
368MODULE_PARM_DESC(io,"base io address of controller");
369
370static int irq[] = {0, 0};
371module_param_array(irq, int, NULL, 0);
372MODULE_PARM_DESC(irq,"interrupt for controller");
373
374static int scsiid[] = {7, 7};
375module_param_array(scsiid, int, NULL, 0);
376MODULE_PARM_DESC(scsiid,"scsi id of controller");
377
378static int reconnect[] = {1, 1};
379module_param_array(reconnect, int, NULL, 0);
380MODULE_PARM_DESC(reconnect,"allow targets to disconnect");
381
382static int parity[] = {1, 1};
383module_param_array(parity, int, NULL, 0);
384MODULE_PARM_DESC(parity,"use scsi parity");
385
386static int sync[] = {1, 1};
387module_param_array(sync, int, NULL, 0);
388MODULE_PARM_DESC(sync,"use synchronous transfers");
389
390static int delay[] = {DELAY_DEFAULT, DELAY_DEFAULT};
391module_param_array(delay, int, NULL, 0);
392MODULE_PARM_DESC(delay,"scsi reset delay");
393
394static int exttrans[] = {0, 0};
395module_param_array(exttrans, int, NULL, 0);
396MODULE_PARM_DESC(exttrans,"use extended translation");
397
398#if !defined(AHA152X_DEBUG)
399static int aha152x[] = {0, 11, 7, 1, 1, 0, DELAY_DEFAULT, 0};
400module_param_array(aha152x, int, NULL, 0);
401MODULE_PARM_DESC(aha152x, "parameters for first controller");
402
403static int aha152x1[] = {0, 11, 7, 1, 1, 0, DELAY_DEFAULT, 0};
404module_param_array(aha152x1, int, NULL, 0);
405MODULE_PARM_DESC(aha152x1, "parameters for second controller");
406#else
407static int debug[] = {DEBUG_DEFAULT, DEBUG_DEFAULT};
408module_param_array(debug, int, NULL, 0);
409MODULE_PARM_DESC(debug, "flags for driver debugging");
410
411static int aha152x[] = {0, 11, 7, 1, 1, 1, DELAY_DEFAULT, 0, DEBUG_DEFAULT};
412module_param_array(aha152x, int, NULL, 0);
413MODULE_PARM_DESC(aha152x, "parameters for first controller");
414
415static int aha152x1[] = {0, 11, 7, 1, 1, 1, DELAY_DEFAULT, 0, DEBUG_DEFAULT};
416module_param_array(aha152x1, int, NULL, 0);
417MODULE_PARM_DESC(aha152x1, "parameters for second controller");
418#endif /* !defined(AHA152X_DEBUG) */
419#endif /* MODULE */
420
421#ifdef __ISAPNP__
422static struct isapnp_device_id id_table[] __devinitdata = {
423 { ISAPNP_ANY_ID, ISAPNP_ANY_ID,
424 ISAPNP_VENDOR('A','D','P'), ISAPNP_FUNCTION(0x1505), 0 },
425 { ISAPNP_ANY_ID, ISAPNP_ANY_ID,
426 ISAPNP_VENDOR('A','D','P'), ISAPNP_FUNCTION(0x1530), 0 },
427 { ISAPNP_DEVICE_SINGLE_END, }
428};
429MODULE_DEVICE_TABLE(isapnp, id_table);
430#endif /* ISAPNP */
431
432#endif /* !PCMCIA */
433
d0be4a7d 434static struct scsi_host_template aha152x_driver_template;
1da177e4
LT
435
436/*
437 * internal states of the host
438 *
439 */
440enum aha152x_state {
441 idle=0,
442 unknown,
443 seldo,
444 seldi,
445 selto,
446 busfree,
447 msgo,
448 cmd,
449 msgi,
450 status,
451 datai,
452 datao,
453 parerr,
454 rsti,
455 maxstate
456};
457
458/*
459 * current state information of the host
460 *
461 */
462struct aha152x_hostdata {
463 Scsi_Cmnd *issue_SC;
464 /* pending commands to issue */
465
466 Scsi_Cmnd *current_SC;
467 /* current command on the bus */
468
469 Scsi_Cmnd *disconnected_SC;
470 /* commands that disconnected */
471
472 Scsi_Cmnd *done_SC;
473 /* command that was completed */
474
475 spinlock_t lock;
476 /* host lock */
477
478#if defined(AHA152X_DEBUG)
479 const char *locker;
480 /* which function has the lock */
481 int lockerl; /* where did it get it */
482
483 int debug; /* current debugging setting */
484#endif
485
486#if defined(AHA152X_STAT)
487 int total_commands;
488 int disconnections;
489 int busfree_without_any_action;
490 int busfree_without_old_command;
491 int busfree_without_new_command;
492 int busfree_without_done_command;
493 int busfree_with_check_condition;
494 int count[maxstate];
495 int count_trans[maxstate];
496 unsigned long time[maxstate];
497#endif
498
499 int commands; /* current number of commands */
500
501 int reconnect; /* disconnection allowed */
502 int parity; /* parity checking enabled */
503 int synchronous; /* synchronous transferes enabled */
504 int delay; /* reset out delay */
505 int ext_trans; /* extended translation enabled */
506
507 int swint; /* software-interrupt was fired during detect() */
508 int service; /* bh needs to be run */
509 int in_intr; /* bh is running */
510
511 /* current state,
512 previous state,
513 last state different from current state */
514 enum aha152x_state state, prevstate, laststate;
515
516 int target;
517 /* reconnecting target */
518
519 unsigned char syncrate[8];
520 /* current synchronous transfer agreements */
521
522 unsigned char syncneg[8];
523 /* 0: no negotiation;
524 * 1: negotiation in progress;
525 * 2: negotiation completed
526 */
527
528 int cmd_i;
529 /* number of sent bytes of current command */
530
531 int msgi_len;
532 /* number of received message bytes */
533 unsigned char msgi[256];
534 /* received message bytes */
535
536 int msgo_i, msgo_len;
537 /* number of sent bytes and length of current messages */
538 unsigned char msgo[256];
539 /* pending messages */
540
541 int data_len;
542 /* number of sent/received bytes in dataphase */
543
544 unsigned long io_port0;
545 unsigned long io_port1;
546
547#ifdef __ISAPNP__
548 struct pnp_dev *pnpdev;
549#endif
5fcda422 550 struct list_head host_list;
1da177e4
LT
551};
552
553
554/*
555 * host specific command extension
556 *
557 */
558struct aha152x_scdata {
559 Scsi_Cmnd *next; /* next sc in queue */
0f06bb34 560 struct completion *done;/* semaphore to block on */
45333ffa
BH
561 unsigned char aha_orig_cmd_len;
562 unsigned char aha_orig_cmnd[MAX_COMMAND_SIZE];
563 int aha_orig_resid;
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 */
619static void seldi_run(struct Scsi_Host *shpnt);
620static void seldo_run(struct Scsi_Host *shpnt);
621static void selto_run(struct Scsi_Host *shpnt);
622static void busfree_run(struct Scsi_Host *shpnt);
623
624static void msgo_init(struct Scsi_Host *shpnt);
625static void msgo_run(struct Scsi_Host *shpnt);
626static void msgo_end(struct Scsi_Host *shpnt);
627
628static void cmd_init(struct Scsi_Host *shpnt);
629static void cmd_run(struct Scsi_Host *shpnt);
630static void cmd_end(struct Scsi_Host *shpnt);
631
632static void datai_init(struct Scsi_Host *shpnt);
633static void datai_run(struct Scsi_Host *shpnt);
634static void datai_end(struct Scsi_Host *shpnt);
635
636static void datao_init(struct Scsi_Host *shpnt);
637static void datao_run(struct Scsi_Host *shpnt);
638static void datao_end(struct Scsi_Host *shpnt);
639
640static void status_run(struct Scsi_Host *shpnt);
641
642static void msgi_run(struct Scsi_Host *shpnt);
643static void msgi_end(struct Scsi_Host *shpnt);
644
645static void parerr_run(struct Scsi_Host *shpnt);
646static void rsti_run(struct Scsi_Host *shpnt);
647
648static void is_complete(struct Scsi_Host *shpnt);
649
650/*
651 * driver states
652 *
653 */
654static 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 678static irqreturn_t intr(int irq, void *dev_id);
1da177e4
LT
679static void reset_ports(struct Scsi_Host *shpnt);
680static void aha152x_error(struct Scsi_Host *shpnt, char *msg);
681static void done(struct Scsi_Host *shpnt, int error);
682
683/* diagnostics */
684static void disp_ports(struct Scsi_Host *shpnt);
685static void show_command(Scsi_Cmnd * ptr);
686static void show_queues(struct Scsi_Host *shpnt);
687static void disp_enintr(struct Scsi_Host *shpnt);
688
689
690/*
691 * queue services:
692 *
693 */
694static 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
708static 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
720static 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
741static 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 762static 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
772struct 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
901out_host_put:
5fcda422 902 list_del(&HOSTDATA(shpnt)->host_list);
1da177e4
LT
903 scsi_host_put(shpnt);
904
905 return NULL;
906}
907
908void 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 */
937static 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
975static 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)) {
998 if(SCpnt->host_scribble==0 || SCSEM(SCpnt) || SCNEXT(SCpnt)) {
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);
1004 if(SCpnt->host_scribble==0) {
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
2338545a 1020 if ((phase & (check_condition|resetting)) || !scsi_sglist(SCpnt)) {
45333ffa
BH
1021 if (phase & check_condition) {
1022 SCpnt->SCp.ptr = SCpnt->sense_buffer;
1023 SCpnt->SCp.this_residual = sizeof(SCpnt->sense_buffer);
2338545a 1024 scsi_set_resid(SCpnt, sizeof(SCpnt->sense_buffer));
45333ffa
BH
1025 } else {
1026 SCpnt->SCp.ptr = NULL;
1027 SCpnt->SCp.this_residual = 0;
2338545a 1028 scsi_set_resid(SCpnt, 0);
45333ffa 1029 }
66acdb03
BH
1030 SCpnt->SCp.buffer = NULL;
1031 SCpnt->SCp.buffers_residual = 0;
1032 } else {
2338545a
BH
1033 scsi_set_resid(SCpnt, scsi_bufflen(SCpnt));
1034 SCpnt->SCp.buffer = scsi_sglist(SCpnt);
1da177e4
LT
1035 SCpnt->SCp.ptr = SG_ADDRESS(SCpnt->SCp.buffer);
1036 SCpnt->SCp.this_residual = SCpnt->SCp.buffer->length;
2338545a 1037 SCpnt->SCp.buffers_residual = scsi_sg_count(SCpnt) - 1;
66acdb03 1038 }
1da177e4
LT
1039
1040 DO_LOCK(flags);
1041
1042#if defined(AHA152X_STAT)
1043 HOSTDATA(shpnt)->total_commands++;
1044#endif
1045
1046 /* Turn led on, when this is the first command. */
1047 HOSTDATA(shpnt)->commands++;
1048 if (HOSTDATA(shpnt)->commands==1)
1049 SETPORT(PORTA, 1);
1050
1051 append_SC(&ISSUE_SC, SCpnt);
1052
1053 if(!HOSTDATA(shpnt)->in_intr)
1054 setup_expected_interrupts(shpnt);
1055
1056 DO_UNLOCK(flags);
1057
1058 return 0;
1059}
1060
1061/*
1062 * queue a command
1063 *
1064 */
1065static int aha152x_queue(Scsi_Cmnd *SCpnt, void (*done)(Scsi_Cmnd *))
1066{
1067#if 0
1068 if(*SCpnt->cmnd == REQUEST_SENSE) {
1069 SCpnt->result = 0;
1070 done(SCpnt);
1071
1072 return 0;
1073 }
1074#endif
1075
1076 return aha152x_internal_queue(SCpnt, NULL, 0, done);
1077}
1078
1079
1080/*
1081 *
1082 *
1083 */
1084static void reset_done(Scsi_Cmnd *SCpnt)
1085{
1086#if 0
1087 struct Scsi_Host *shpnt = SCpnt->host;
1088 DPRINTK(debug_eh, INFO_LEAD "reset_done called\n", CMDINFO(SCpnt));
1089#endif
1090 if(SCSEM(SCpnt)) {
0f06bb34 1091 complete(SCSEM(SCpnt));
1da177e4 1092 } else {
0f06bb34 1093 printk(KERN_ERR "aha152x: reset_done w/o completion\n");
1da177e4
LT
1094 }
1095}
1096
1097/*
1098 * Abort a command
1099 *
1100 */
1101static int aha152x_abort(Scsi_Cmnd *SCpnt)
1102{
1103 struct Scsi_Host *shpnt = SCpnt->device->host;
1104 Scsi_Cmnd *ptr;
1105 unsigned long flags;
1106
1107#if defined(AHA152X_DEBUG)
1108 if(HOSTDATA(shpnt)->debug & debug_eh) {
1109 printk(DEBUG_LEAD "abort(%p)", CMDINFO(SCpnt), SCpnt);
1110 show_queues(shpnt);
1111 }
1112#endif
1113
1114 DO_LOCK(flags);
1115
1116 ptr=remove_SC(&ISSUE_SC, SCpnt);
1117
1118 if(ptr) {
1119 DPRINTK(debug_eh, DEBUG_LEAD "not yet issued - SUCCESS\n", CMDINFO(SCpnt));
1120
1121 HOSTDATA(shpnt)->commands--;
1122 if (!HOSTDATA(shpnt)->commands)
1123 SETPORT(PORTA, 0);
1124 DO_UNLOCK(flags);
1125
1126 kfree(SCpnt->host_scribble);
1127 SCpnt->host_scribble=NULL;
1128
1129 return SUCCESS;
1130 }
1131
1132 DO_UNLOCK(flags);
1133
1134 /*
1135 * FIXME:
1136 * for current command: queue ABORT for message out and raise ATN
1137 * for disconnected command: pseudo SC with ABORT message or ABORT on reselection?
1138 *
1139 */
1140
1141 printk(ERR_LEAD "cannot abort running or disconnected command\n", CMDINFO(SCpnt));
1142
1143 return FAILED;
1144}
1145
1da177e4
LT
1146/*
1147 * Reset a device
1148 *
1149 */
1150static int aha152x_device_reset(Scsi_Cmnd * SCpnt)
1151{
1152 struct Scsi_Host *shpnt = SCpnt->device->host;
0f06bb34 1153 DECLARE_COMPLETION(done);
1da177e4 1154 int ret, issued, disconnected;
631c228c 1155 unsigned char old_cmd_len = SCpnt->cmd_len;
1da177e4 1156 unsigned long flags;
0f06bb34 1157 unsigned long timeleft;
1da177e4
LT
1158
1159#if defined(AHA152X_DEBUG)
1160 if(HOSTDATA(shpnt)->debug & debug_eh) {
1161 printk(INFO_LEAD "aha152x_device_reset(%p)", CMDINFO(SCpnt), SCpnt);
1162 show_queues(shpnt);
1163 }
1164#endif
1165
1166 if(CURRENT_SC==SCpnt) {
1167 printk(ERR_LEAD "cannot reset current device\n", CMDINFO(SCpnt));
1168 return FAILED;
1169 }
1170
1171 DO_LOCK(flags);
1172 issued = remove_SC(&ISSUE_SC, SCpnt)==0;
1173 disconnected = issued && remove_SC(&DISCONNECTED_SC, SCpnt);
1174 DO_UNLOCK(flags);
1175
1176 SCpnt->cmd_len = 0;
1da177e4 1177
0f06bb34 1178 aha152x_internal_queue(SCpnt, &done, resetting, reset_done);
1da177e4 1179
0f06bb34
CH
1180 timeleft = wait_for_completion_timeout(&done, 100*HZ);
1181 if (!timeleft) {
1182 /* remove command from issue queue */
1183 DO_LOCK(flags);
1184 remove_SC(&ISSUE_SC, SCpnt);
1185 DO_UNLOCK(flags);
1186 }
631c228c
CH
1187
1188 SCpnt->cmd_len = old_cmd_len;
1da177e4
LT
1189
1190 DO_LOCK(flags);
1191
1192 if(SCpnt->SCp.phase & resetted) {
1193 HOSTDATA(shpnt)->commands--;
1194 if (!HOSTDATA(shpnt)->commands)
1195 SETPORT(PORTA, 0);
1196 kfree(SCpnt->host_scribble);
1197 SCpnt->host_scribble=NULL;
1198
1199 ret = SUCCESS;
1200 } else {
1201 /* requeue */
1202 if(!issued) {
1203 append_SC(&ISSUE_SC, SCpnt);
1204 } else if(disconnected) {
1205 append_SC(&DISCONNECTED_SC, SCpnt);
1206 }
1207
1208 ret = FAILED;
1209 }
1210
1211 DO_UNLOCK(flags);
1da177e4
LT
1212 return ret;
1213}
1214
1215static void free_hard_reset_SCs(struct Scsi_Host *shpnt, Scsi_Cmnd **SCs)
1216{
1217 Scsi_Cmnd *ptr;
1218
1219 ptr=*SCs;
1220 while(ptr) {
1221 Scsi_Cmnd *next;
1222
1223 if(SCDATA(ptr)) {
1224 next = SCNEXT(ptr);
1225 } else {
1226 printk(DEBUG_LEAD "queue corrupted at %p\n", CMDINFO(ptr), ptr);
1227 next = NULL;
1228 }
1229
1230 if (!ptr->device->soft_reset) {
1231 DPRINTK(debug_eh, DEBUG_LEAD "disconnected command %p removed\n", CMDINFO(ptr), ptr);
1232 remove_SC(SCs, ptr);
1233 HOSTDATA(shpnt)->commands--;
1234 kfree(ptr->host_scribble);
1235 ptr->host_scribble=NULL;
1236 }
1237
1238 ptr = next;
1239 }
1240}
1241
1242/*
1243 * Reset the bus
1244 *
1245 */