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