1 /* aha152x.c -- Adaptec AHA-152x driver
2 * Author: Jürgen E. Fischer, fischer@norbit.de
3 * Copyright 1993-2000 Jürgen E. Fischer
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
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.
16 * $Id: aha152x.c,v 2.5 2002/04/14 11:24:53 fischer Exp $
19 * Revision 2.5 2002/04/14 11:24:53 fischer
24 * Revision 2.4 2000/12/16 12:53:56 fischer
25 * - allow REQUEST SENSE to be queued
26 * - handle shared PCI interrupts
28 * Revision 2.3 2000/11/04 16:40:26 fischer
29 * - handle data overruns
30 * - extend timeout for data phases
32 * Revision 2.2 2000/08/08 19:54:53 fischer
35 * Revision 2.1 2000/05/17 16:23:17 fischer
37 * - fix for data out w/o scatter gather
39 * Revision 2.0 1999/12/25 15:07:32 fischer
40 * - interrupt routine completly reworked
41 * - basic support for new eh code
43 * Revision 1.21 1999/11/10 23:46:36 fischer
44 * - default to synchronous operation
45 * - synchronous negotiation fixed
46 * - added timeout to loops
47 * - debugging output can be controlled through procfs
49 * Revision 1.20 1999/11/07 18:37:31 fischer
50 * - synchronous operation works
51 * - resid support for sg driver
53 * Revision 1.19 1999/11/02 22:39:59 fischer
54 * - moved leading comments to README.aha152x
55 * - new additional module parameters
57 * - support for the Tripace TC1550 controller
58 * - interrupt handling changed
60 * Revision 1.18 1996/09/07 20:10:40 fischer
61 * - fixed can_queue handling (multiple outstanding commands working again)
63 * Revision 1.17 1996/08/17 16:05:14 fischer
64 * - biosparam improved
65 * - interrupt verification
66 * - updated documentation
69 * Revision 1.16 1996/06/09 00:04:56 root
70 * - added configuration symbols for insmod (aha152x/aha152x1)
72 * Revision 1.15 1996/04/30 14:52:06 fischer
74 * - support for extended translation for >1GB disks
76 * Revision 1.14 1996/01/17 15:11:20 fischer
77 * - fixed lockup in MESSAGE IN phase after reconnection
79 * Revision 1.13 1996/01/09 02:15:53 fischer
81 * - moved request_irq behind controller initialization
82 * (to avoid spurious interrupts)
84 * Revision 1.12 1995/12/16 12:26:07 fischer
86 * - configurable RESET delay added
88 * Revision 1.11 1995/12/06 21:18:35 fischer
89 * - some minor updates
91 * Revision 1.10 1995/07/22 19:18:45 fischer
92 * - support for 2 controllers
93 * - started synchronous data transfers (not working yet)
95 * Revision 1.9 1995/03/18 09:20:24 root
96 * - patches for PCMCIA and modules
98 * Revision 1.8 1995/01/21 22:07:19 root
99 * - snarf_region => request_region
100 * - aha152x_intr interface change
102 * Revision 1.7 1995/01/02 23:19:36 root
103 * - updated COMMAND_SIZE to cmd_len
104 * - changed sti() to restore_flags()
105 * - fixed some #ifdef which generated warnings
107 * Revision 1.6 1994/11/24 20:35:27 root
108 * - problem with odd number of bytes in fifo fixed
110 * Revision 1.5 1994/10/30 14:39:56 root
112 * - debugging improved
114 * Revision 1.4 1994/09/12 11:33:01 root
115 * - irqaction to request_irq
118 * Revision 1.3 1994/08/04 13:53:05 root
119 * - updates for mid-level-driver changes
120 * - accept unexpected BUSFREE phase as error condition
121 * - parity check now configurable
123 * Revision 1.2 1994/07/03 12:56:36 root
124 * - cleaned up debugging code
125 * - more tweaking on reset delays
126 * - updated abort/reset code (pretty untested...)
128 * Revision 1.1 1994/05/28 21:18:49 root
129 * - update for mid-level interface change (abort-reset)
130 * - delays after resets adjusted for some slow devices
132 * Revision 1.0 1994/03/25 12:52:00 root
133 * - Fixed "more data than expected" problem
134 * - added new BIOS signatures
136 * Revision 0.102 1994/01/31 20:44:12 root
137 * - minor changes in insw/outsw handling
139 * Revision 0.101 1993/12/13 01:16:27 root
140 * - fixed STATUS phase (non-GOOD stati were dropped sometimes;
141 * fixes problems with CD-ROM sector size detection & media change)
143 * Revision 0.100 1993/12/10 16:58:47 root
144 * - fix for unsuccessful selections in case of non-continuous id assignments
147 * Revision 0.99 1993/10/24 16:19:59 root
148 * - fixed DATA IN (rare read errors gone)
150 * Revision 0.98 1993/10/17 12:54:44 root
151 * - fixed some recent fixes (shame on me)
152 * - moved initialization of scratch area to aha152x_queue
154 * Revision 0.97 1993/10/09 18:53:53 root
155 * - DATA IN fixed. Rarely left data in the fifo.
157 * Revision 0.96 1993/10/03 00:53:59 root
158 * - minor changes on DATA IN
160 * Revision 0.95 1993/09/24 10:36:01 root
161 * - change handling of MSGI after reselection
165 * Revision 0.94 1993/09/18 14:08:22 root
166 * - fixed bug in multiple outstanding command code
167 * - changed detection
168 * - support for kernel command line configuration
170 * - changed message handling
172 * Revision 0.93 1993/09/15 20:41:19 root
173 * - fixed bugs with multiple outstanding commands
175 * Revision 0.92 1993/09/13 02:46:33 root
176 * - multiple outstanding commands work (no problems with IBM drive)
178 * Revision 0.91 1993/09/12 20:51:46 root
179 * added multiple outstanding commands
180 * (some problem with this $%&? IBM device remain)
182 * Revision 0.9 1993/09/12 11:11:22 root
183 * - corrected auto-configuration
184 * - changed the auto-configuration (added some '#define's)
185 * - added support for dis-/reconnection
187 * Revision 0.8 1993/09/06 23:09:39 root
188 * - added support for the drive activity light
191 * Revision 0.7 1993/09/05 14:30:15 root
192 * - improved phase detection
193 * - now using the new snarf_region code of 0.99pl13
195 * Revision 0.6 1993/09/02 11:01:38 root
196 * first public release; added some signatures and biosparam()
198 * Revision 0.5 1993/08/30 10:23:30 root
199 * fixed timing problems with my IBM drive
201 * Revision 0.4 1993/08/29 14:06:52 root
202 * fixed some problems with timeouts due incomplete commands
204 * Revision 0.3 1993/08/28 15:55:03 root
205 * writing data works too. mounted and worked on a dos partition
207 * Revision 0.2 1993/08/27 22:42:07 root
208 * reading data works. Mounted a msdos partition.
210 * Revision 0.1 1993/08/25 13:38:30 root
211 * first "damn thing doesn't work" version
213 * Revision 0.0 1993/08/14 19:54:25 root
214 * empty function bodies; detect() works.
217 **************************************************************************
219 see README.aha152x for configuration details
221 **************************************************************************/
223 #include <linux/module.h>
225 #include <linux/sched.h>
228 #include <linux/version.h>
229 #include <linux/blk.h>
233 #include "constants.h"
234 #include <asm/system.h>
235 #include <linux/errno.h>
236 #include <linux/string.h>
237 #include <linux/wait.h>
238 #include <linux/ioport.h>
239 #include <linux/delay.h>
240 #include <linux/proc_fs.h>
241 #include <linux/interrupt.h>
242 #include <linux/init.h>
243 #include <linux/kernel.h>
244 #include <linux/isapnp.h>
245 #include <asm/semaphore.h>
246 #include <linux/spinlock.h>
249 #include <linux/stat.h>
251 #include <scsi/scsicam.h>
259 /* For PCMCIA cards, always use AUTOCONF */
260 #if defined(PCMCIA) || defined(MODULE)
261 #if !defined(AUTOCONF)
266 #if !defined(AUTOCONF) && !defined(SETUP0)
267 #error define AUTOCONF or SETUP0
270 #if defined(AHA152X_DEBUG)
271 #define DEBUG_DEFAULT debug_eh
273 #define DPRINTK(when,msgs...) \
274 do { if(HOSTDATA(shpnt)->debug & (when)) printk(msgs); } while(0)
276 #define DO_LOCK(flags) \
278 if(spin_is_locked(&QLOCK)) { \
279 DPRINTK(debug_intr, DEBUG_LEAD "(%s:%d) already locked at %s:%d\n", CMDINFO(CURRENT_SC), __FUNCTION__, __LINE__, QLOCKER, QLOCKERL); \
281 DPRINTK(debug_locks, DEBUG_LEAD "(%s:%d) locking\n", CMDINFO(CURRENT_SC), __FUNCTION__, __LINE__); \
282 spin_lock_irqsave(&QLOCK,flags); \
283 DPRINTK(debug_locks, DEBUG_LEAD "(%s:%d) locked\n", CMDINFO(CURRENT_SC), __FUNCTION__, __LINE__); \
284 QLOCKER=__FUNCTION__; \
288 #define DO_UNLOCK(flags) \
290 DPRINTK(debug_locks, DEBUG_LEAD "(%s:%d) unlocking (locked at %s:%d)\n", CMDINFO(CURRENT_SC), __FUNCTION__, __LINE__, QLOCKER, QLOCKERL); \
291 spin_unlock_irqrestore(&QLOCK,flags); \
292 DPRINTK(debug_locks, DEBUG_LEAD "(%s:%d) unlocked\n", CMDINFO(CURRENT_SC), __FUNCTION__, __LINE__); \
293 QLOCKER="(not locked)"; \
298 #define DPRINTK(when,msgs...)
299 #define DO_LOCK(flags) spin_lock_irqsave(&QLOCK,flags)
300 #define DO_UNLOCK(flags) spin_unlock_irqrestore(&QLOCK,flags)
303 #define LEAD "(scsi%d:%d:%d) "
304 #define WARN_LEAD KERN_WARNING LEAD
305 #define INFO_LEAD KERN_INFO LEAD
306 #define NOTE_LEAD KERN_NOTICE LEAD
307 #define ERR_LEAD KERN_ERR LEAD
308 #define DEBUG_LEAD KERN_DEBUG LEAD
309 #define CMDINFO(cmd) \
310 (cmd) ? ((cmd)->host->host_no) : -1, \
311 (cmd) ? ((cmd)->target & 0x0f) : -1, \
312 (cmd) ? ((cmd)->lun & 0x07) : -1
314 #define DELAY_DEFAULT 1000
322 #define IRQ_MAX (NR_IRQS-1)
329 not_issued = 0x0001, /* command not yet issued */
330 selecting = 0x0002, /* target is beeing selected */
331 identified = 0x0004, /* IDENTIFY was sent */
332 disconnected = 0x0008, /* target disconnected */
333 completed = 0x0010, /* target sent COMMAND COMPLETE */
334 aborted = 0x0020, /* ABORT was sent */
335 resetted = 0x0040, /* BUS DEVICE RESET was sent */
336 spiordy = 0x0080, /* waiting for SPIORDY to raise */
337 syncneg = 0x0100, /* synchronous negotiation in progress */
338 aborting = 0x0200, /* ABORT is pending */
339 resetting = 0x0400, /* BUS DEVICE RESET is pending */
343 MODULE_AUTHOR("Jürgen Fischer");
344 MODULE_DESCRIPTION(AHA152X_REVID);
345 MODULE_LICENSE("GPL");
347 MODULE_PARM(io, "1-2i");
348 MODULE_PARM_DESC(io,"base io address of controller");
349 static int io[] = {0, 0};
351 MODULE_PARM(irq, "1-2i");
352 MODULE_PARM_DESC(irq,"interrupt for controller");
353 static int irq[] = {0, 0};
355 MODULE_PARM(scsiid, "1-2i");
356 MODULE_PARM_DESC(scsiid,"scsi id of controller");
357 static int scsiid[] = {7, 7};
359 MODULE_PARM(reconnect, "1-2i");
360 MODULE_PARM_DESC(reconnect,"allow targets to disconnect");
361 static int reconnect[] = {1, 1};
363 MODULE_PARM(parity, "1-2i");
364 MODULE_PARM_DESC(parity,"use scsi parity");
365 static int parity[] = {1, 1};
367 MODULE_PARM(sync, "1-2i");
368 MODULE_PARM_DESC(sync,"use synchronous transfers");
369 static int sync[] = {1, 1};
371 MODULE_PARM(delay, "1-2i");
372 MODULE_PARM_DESC(delay,"scsi reset delay");
373 static int delay[] = {DELAY_DEFAULT, DELAY_DEFAULT};
375 MODULE_PARM(exttrans, "1-2i");
376 MODULE_PARM_DESC(exttrans,"use extended translation");
377 static int exttrans[] = {0, 0};
379 #if !defined(AHA152X_DEBUG)
380 MODULE_PARM(aha152x, "1-8i");
381 MODULE_PARM_DESC(aha152x, "parameters for first controller");
382 static int aha152x[] = {0, 11, 7, 1, 1, 0, DELAY_DEFAULT, 0};
384 MODULE_PARM(aha152x1, "1-8i");
385 MODULE_PARM_DESC(aha152x1, "parameters for second controller");
386 static int aha152x1[] = {0, 11, 7, 1, 1, 0, DELAY_DEFAULT, 0};
388 MODULE_PARM(debug, "1-2i");
389 MODULE_PARM_DESC(debug, "flags for driver debugging");
390 static int debug[] = {DEBUG_DEFAULT, DEBUG_DEFAULT};
392 MODULE_PARM(aha152x, "1-9i");
393 MODULE_PARM_DESC(aha152x, "parameters for first controller");
394 static int aha152x[] = {0, 11, 7, 1, 1, 1, DELAY_DEFAULT, 0, DEBUG_DEFAULT};
396 MODULE_PARM(aha152x1, "1-9i");
397 MODULE_PARM_DESC(aha152x1, "parameters for second controller");
398 static int aha152x1[] = {0, 11, 7, 1, 1, 1, DELAY_DEFAULT, 0, DEBUG_DEFAULT};
399 #endif /* !defined(AHA152X_DEBUG) */
402 static struct isapnp_device_id id_table[] __devinitdata = {
403 { ISAPNP_DEVICE_SINGLE('A','D','P',0x1505, 'A','D','P',0x1505), },
404 { ISAPNP_DEVICE_SINGLE_END, }
406 MODULE_DEVICE_TABLE(isapnp, id_table);
410 /* set by aha152x_setup according to the command line */
411 static int setup_count = 0;
412 static int registered_count = 0;
413 static struct aha152x_setup {
423 #if defined(AHA152X_DEBUG)
429 static struct Scsi_Host *aha152x_host[2];
432 * internal states of the host
454 * current state information of the host
457 struct aha152x_hostdata {
459 /* pending commands to issue */
461 Scsi_Cmnd *current_SC;
462 /* current command on the bus */
464 Scsi_Cmnd *disconnected_SC;
465 /* commands that disconnected */
468 /* command that was completed */
473 #if defined(AHA152X_DEBUG)
474 char *locker; /* which function has the lock */
475 int lockerl; /* where did it get it */
477 int debug; /* current debugging setting */
480 #if defined(AHA152X_STAT)
483 int busfree_without_any_action;
484 int busfree_without_old_command;
485 int busfree_without_new_command;
486 int busfree_without_done_command;
487 int busfree_with_check_condition;
489 int count_trans[maxstate];
490 unsigned long time[maxstate];
493 int commands; /* current number of commands */
495 int reconnect; /* disconnection allowed */
496 int parity; /* parity checking enabled */
497 int synchronous; /* synchronous transferes enabled */
498 int delay; /* reset out delay */
499 int ext_trans; /* extended translation enabled */
501 int swint; /* software-interrupt was fired during detect() */
502 int service; /* bh needs to be run */
503 int in_intr; /* bh is running */
507 last state different from current state */
508 enum aha152x_state state, prevstate, laststate;
511 /* reconnecting target */
513 unsigned char syncrate[8];
514 /* current synchronous transfer agreements */
516 unsigned char syncneg[8];
517 /* 0: no negotiation;
518 * 1: negotiation in progress;
519 * 2: negotiation completed
523 /* number of sent bytes of current command */
526 /* number of received message bytes */
527 unsigned char msgi[256];
528 /* received message bytes */
530 int msgo_i, msgo_len;
531 /* number of sent bytes and length of current messages */
532 unsigned char msgo[256];
533 /* pending messages */
536 /* number of sent/received bytes in dataphase */
538 unsigned long io_port0;
539 unsigned long io_port1;
544 * host specific command extension
547 struct aha152x_scdata {
548 Scsi_Cmnd *next; /* next sc in queue */
549 Scsi_Cmnd *done; /* done command */
550 struct semaphore *sem; /* semaphore to block on */
554 /* access macros for hostdata */
556 #define HOSTDATA(shpnt) ((struct aha152x_hostdata *) &shpnt->hostdata)
558 #define HOSTNO ((shpnt)->host_no)
560 #define CURRENT_SC (HOSTDATA(shpnt)->current_SC)
561 #define DONE_SC (HOSTDATA(shpnt)->done_SC)
562 #define ISSUE_SC (HOSTDATA(shpnt)->issue_SC)
563 #define DISCONNECTED_SC (HOSTDATA(shpnt)->disconnected_SC)
564 #define QLOCK (HOSTDATA(shpnt)->lock)
565 #define QLOCKER (HOSTDATA(shpnt)->locker)
566 #define QLOCKERL (HOSTDATA(shpnt)->lockerl)
568 #define STATE (HOSTDATA(shpnt)->state)
569 #define PREVSTATE (HOSTDATA(shpnt)->prevstate)
570 #define LASTSTATE (HOSTDATA(shpnt)->laststate)
572 #define RECONN_TARGET (HOSTDATA(shpnt)->target)
574 #define CMD_I (HOSTDATA(shpnt)->cmd_i)
576 #define MSGO(i) (HOSTDATA(shpnt)->msgo[i])
577 #define MSGO_I (HOSTDATA(shpnt)->msgo_i)
578 #define MSGOLEN (HOSTDATA(shpnt)->msgo_len)
579 #define ADDMSGO(x) (MSGOLEN<256 ? MSGO(MSGOLEN++)=x : aha152x_error(shpnt,"MSGO overflow"))
581 #define MSGI(i) (HOSTDATA(shpnt)->msgi[i])
582 #define MSGILEN (HOSTDATA(shpnt)->msgi_len)
583 #define ADDMSGI(x) (MSGILEN<256 ? MSGI(MSGILEN++)=x : aha152x_error(shpnt,"MSGI overflow"))
585 #define DATA_LEN (HOSTDATA(shpnt)->data_len)
587 #define SYNCRATE (HOSTDATA(shpnt)->syncrate[CURRENT_SC->target])
588 #define SYNCNEG (HOSTDATA(shpnt)->syncneg[CURRENT_SC->target])
590 #define DELAY (HOSTDATA(shpnt)->delay)
591 #define EXT_TRANS (HOSTDATA(shpnt)->ext_trans)
592 #define TC1550 (HOSTDATA(shpnt)->tc1550)
593 #define RECONNECT (HOSTDATA(shpnt)->reconnect)
594 #define PARITY (HOSTDATA(shpnt)->parity)
595 #define SYNCHRONOUS (HOSTDATA(shpnt)->synchronous)
597 #define HOSTIOPORT0 (HOSTDATA(shpnt)->io_port0)
598 #define HOSTIOPORT1 (HOSTDATA(shpnt)->io_port1)
600 #define SCDATA(SCpnt) ((struct aha152x_scdata *) (SCpnt)->host_scribble)
601 #define SCNEXT(SCpnt) SCDATA(SCpnt)->next
602 #define SCDONE(SCpnt) SCDATA(SCpnt)->done
603 #define SCSEM(SCpnt) SCDATA(SCpnt)->sem
605 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
606 #define SG_ADDRESS(buffer) ((buffer)->address)
608 #define SG_ADDRESS(buffer) ((char *) (page_address((buffer)->page)+(buffer)->offset))
612 static void seldi_run(struct Scsi_Host *shpnt);
613 static void seldo_run(struct Scsi_Host *shpnt);
614 static void selto_run(struct Scsi_Host *shpnt);
615 static void busfree_run(struct Scsi_Host *shpnt);
617 static void msgo_init(struct Scsi_Host *shpnt);
618 static void msgo_run(struct Scsi_Host *shpnt);
619 static void msgo_end(struct Scsi_Host *shpnt);
621 static void cmd_init(struct Scsi_Host *shpnt);
622 static void cmd_run(struct Scsi_Host *shpnt);
623 static void cmd_end(struct Scsi_Host *shpnt);
625 static void datai_init(struct Scsi_Host *shpnt);
626 static void datai_run(struct Scsi_Host *shpnt);
627 static void datai_end(struct Scsi_Host *shpnt);
629 static void datao_init(struct Scsi_Host *shpnt);
630 static void datao_run(struct Scsi_Host *shpnt);
631 static void datao_end(struct Scsi_Host *shpnt);
633 static void status_run(struct Scsi_Host *shpnt);
635 static void msgi_run(struct Scsi_Host *shpnt);
636 static void msgi_end(struct Scsi_Host *shpnt);
638 static void parerr_run(struct Scsi_Host *shpnt);
639 static void rsti_run(struct Scsi_Host *shpnt);
641 static void is_complete(struct Scsi_Host *shpnt);
649 void (*init)(struct Scsi_Host *);
650 void (*run)(struct Scsi_Host *);
651 void (*end)(struct Scsi_Host *);
654 { "idle", 0, 0, 0, 0},
655 { "unknown", 0, 0, 0, 0},
656 { "seldo", 0, seldo_run, 0, 0},
657 { "seldi", 0, seldi_run, 0, 0},
658 { "selto", 0, selto_run, 0, 0},
659 { "busfree", 0, busfree_run, 0, 0},
660 { "msgo", msgo_init, msgo_run, msgo_end, 1},
661 { "cmd", cmd_init, cmd_run, cmd_end, 1},
662 { "msgi", 0, msgi_run, msgi_end, 1},
663 { "status", 0, status_run, 0, 1},
664 { "datai", datai_init, datai_run, datai_end, 0},
665 { "datao", datao_init, datao_run, datao_end, 0},
666 { "parerr", 0, parerr_run, 0, 0},
667 { "rsti", 0, rsti_run, 0, 0},
670 /* setup & interrupt */
671 static void intr(int irq, void *dev_id, struct pt_regs *);
672 static void reset_ports(struct Scsi_Host *shpnt);
673 static void aha152x_error(struct Scsi_Host *shpnt, char *msg);
674 static void done(struct Scsi_Host *shpnt, int error);
675 static int checksetup(struct aha152x_setup *setup);
678 static void disp_ports(struct Scsi_Host *shpnt);
679 static void show_command(Scsi_Cmnd * ptr);
680 static void show_queues(struct Scsi_Host *shpnt);
681 static void disp_enintr(struct Scsi_Host *shpnt);
683 /* possible i/o addresses for the AIC-6260; default first */
684 static unsigned short ports[] = { 0x340, 0x140 };
686 #if !defined(SKIP_BIOSTEST)
687 /* possible locations for the Adaptec BIOS; defaults first */
688 static unsigned int addresses[] =
690 0xdc000, /* default first */
697 0xeb800, /* VTech Platinum SMP */
701 /* signatures for various AIC-6[23]60 based controllers.
702 The point in detecting signatures is to avoid useless and maybe
703 harmful probes on ports. I'm not sure that all listed boards pass
704 auto-configuration. For those which fail the BIOS signature is
705 obsolete, because user intervention to supply the configuration is
706 needed anyway. May be an information whether or not the BIOS supports
707 extended translation could be also useful here. */
708 static struct signature {
709 unsigned char *signature;
714 { "Adaptec AHA-1520 BIOS", 0x102e, 21 },
716 { "Adaptec AHA-1520B", 0x000b, 17 },
717 /* Adaptec 152x rev B */
718 { "Adaptec AHA-1520B", 0x0026, 17 },
719 /* Iomega Jaz Jet ISA (AIC6370Q) */
720 { "Adaptec ASW-B626 BIOS", 0x1029, 21 },
721 /* on-board controller */
722 { "Adaptec BIOS: ASW-B626", 0x000f, 22 },
723 /* on-board controller */
724 { "Adaptec ASW-B626 S2", 0x2e6c, 19 },
725 /* on-board controller */
726 { "Adaptec BIOS:AIC-6360", 0x000c, 21 },
727 /* on-board controller */
728 { "ScsiPro SP-360 BIOS", 0x2873, 19 },
729 /* ScsiPro-Controller */
730 { "GA-400 LOCAL BUS SCSI BIOS", 0x102e, 26 },
731 /* Gigabyte Local-Bus-SCSI */
732 { "Adaptec BIOS:AVA-282X", 0x000c, 21 },
734 { "Adaptec IBM Dock II SCSI", 0x2edd, 24 },
735 /* IBM Thinkpad Dock II */
736 { "Adaptec BIOS:AHA-1532P", 0x001c, 22 },
737 /* IBM Thinkpad Dock II SCSI */
738 { "DTC3520A Host Adapter BIOS", 0x318a, 26 },
739 /* DTC 3520A ISA SCSI */
748 static inline void append_SC(Scsi_Cmnd **SC, Scsi_Cmnd *new_SC)
752 SCNEXT(new_SC) = NULL;
756 for (end = *SC; SCNEXT(end); end = SCNEXT(end))
758 SCNEXT(end) = new_SC;
762 static inline Scsi_Cmnd *remove_first_SC(Scsi_Cmnd ** SC)
774 static inline Scsi_Cmnd *remove_lun_SC(Scsi_Cmnd ** SC, int target, int lun)
776 Scsi_Cmnd *ptr, *prev;
778 for (ptr = *SC, prev = NULL;
779 ptr && ((ptr->target != target) || (ptr->lun != lun));
780 prev = ptr, ptr = SCNEXT(ptr))
785 SCNEXT(prev) = SCNEXT(ptr);
795 static inline Scsi_Cmnd *remove_SC(Scsi_Cmnd **SC, Scsi_Cmnd *SCp)
797 Scsi_Cmnd *ptr, *prev;
799 for (ptr = *SC, prev = NULL;
801 prev = ptr, ptr = SCNEXT(ptr))
806 SCNEXT(prev) = SCNEXT(ptr);
816 #if defined(PCMCIA) || !defined(MODULE)
817 void aha152x_setup(char *str, int *ints)
819 if(setup_count>=ARRAY_SIZE(setup)) {
820 printk(KERN_ERR "aha152x: you can only configure up to two controllers\n");
824 setup[setup_count].conf = str;
825 setup[setup_count].io_port = ints[0] >= 1 ? ints[1] : 0x340;
826 setup[setup_count].irq = ints[0] >= 2 ? ints[2] : 11;
827 setup[setup_count].scsiid = ints[0] >= 3 ? ints[3] : 7;
828 setup[setup_count].reconnect = ints[0] >= 4 ? ints[4] : 1;
829 setup[setup_count].parity = ints[0] >= 5 ? ints[5] : 1;
830 setup[setup_count].synchronous = ints[0] >= 6 ? ints[6] : 1;
831 setup[setup_count].delay = ints[0] >= 7 ? ints[7] : DELAY_DEFAULT;
832 setup[setup_count].ext_trans = ints[0] >= 8 ? ints[8] : 0;
833 #if defined(AHA152X_DEBUG)
834 setup[setup_count].debug = ints[0] >= 9 ? ints[9] : DEBUG_DEFAULT;
836 printk(KERN_NOTICE "aha152x: usage: aha152x=<IOBASE>[,<IRQ>[,<SCSI ID>"
837 "[,<RECONNECT>[,<PARITY>[,<SYNCHRONOUS>[,<DELAY>[,<EXT_TRANS>[,<DEBUG>]]]]]]]]\n");
839 if (ints[0] > 8) { /*}*/
840 printk(KERN_NOTICE "aha152x: usage: aha152x=<IOBASE>[,<IRQ>[,<SCSI ID>"
841 "[,<RECONNECT>[,<PARITY>[,<SYNCHRONOUS>[,<DELAY>[,<EXT_TRANS>]]]]]]]\n");
852 static int __init do_setup(char *str)
855 #if defined(AHA152X_DEBUG)
860 int count=setup_count;
862 get_options(str, ARRAY_SIZE(ints), ints);
863 aha152x_setup(str,ints);
865 return count<setup_count;
868 __setup("aha152x=", do_setup);
872 * Test, if port_base is valid.
875 static int aha152x_porttest(int io_port)
879 if (check_region(io_port, IO_RANGE))
882 SETPORT(io_port + O_DMACNTRL1, 0); /* reset stack pointer */
883 for (i = 0; i < 16; i++)
884 SETPORT(io_port + O_STACK, i);
886 SETPORT(io_port + O_DMACNTRL1, 0); /* reset stack pointer */
887 for (i = 0; i < 16 && GETPORT(io_port + O_STACK) == i; i++)
893 static int tc1550_porttest(int io_port)
897 if (check_region(io_port, IO_RANGE))
900 SETPORT(io_port + O_TC_DMACNTRL1, 0); /* reset stack pointer */
901 for (i = 0; i < 16; i++)
902 SETPORT(io_port + O_STACK, i);
904 SETPORT(io_port + O_TC_DMACNTRL1, 0); /* reset stack pointer */
905 for (i = 0; i < 16 && GETPORT(io_port + O_TC_STACK) == i; i++)
911 static int checksetup(struct aha152x_setup *setup)
916 for (i = 0; i < ARRAY_SIZE(ports) && (setup->io_port != ports[i]); i++)
919 if (i == ARRAY_SIZE(ports))
923 if(aha152x_porttest(setup->io_port)) {
925 } else if(tc1550_porttest(setup->io_port)) {
930 if ((setup->irq < IRQ_MIN) || (setup->irq > IRQ_MAX))
933 if ((setup->scsiid < 0) || (setup->scsiid > 7))
936 if ((setup->reconnect < 0) || (setup->reconnect > 1))
939 if ((setup->parity < 0) || (setup->parity > 1))
942 if ((setup->synchronous < 0) || (setup->synchronous > 1))
945 if ((setup->ext_trans < 0) || (setup->ext_trans > 1))
952 static inline struct Scsi_Host *lookup_irq(int irqno)
956 for(i=0; i<ARRAY_SIZE(aha152x_host); i++)
957 if(aha152x_host[i] && aha152x_host[i]->irq==irqno)
958 return aha152x_host[i];
963 static void swintr(int irqno, void *dev_id, struct pt_regs *regs)
965 struct Scsi_Host *shpnt = lookup_irq(irqno);
968 printk(KERN_ERR "aha152x%d: catched software interrupt %d for unknown controller.\n", HOSTNO, irqno);
972 HOSTDATA(shpnt)->swint++;
974 SETPORT(DMACNTRL0, INTEN);
978 static struct pci_dev *pnpdev[2];
979 static int num_pnpdevs;
981 int aha152x_detect(Scsi_Host_Template * tpnt)
984 #if defined(AUTOCONF)
987 struct pci_dev *dev = NULL;
990 tpnt->proc_name = "aha152x";
992 for (i = 0; i < ARRAY_SIZE(aha152x_host); i++)
993 aha152x_host[i] = (struct Scsi_Host *) NULL;
996 printk(KERN_INFO "aha152x: processing commandline: ");
998 for (i = 0; i < setup_count; i++)
999 if (!checksetup(&setup[i])) {
1000 printk(KERN_ERR "\naha152x: %s\n", setup[i].conf);
1001 printk(KERN_ERR "aha152x: invalid line\n");
1007 if (setup_count < ARRAY_SIZE(setup)) {
1008 struct aha152x_setup override = SETUP0;
1010 if (setup_count == 0 || (override.io_port != setup[0].io_port)) {
1011 if (!checksetup(&override)) {
1012 printk(KERN_ERR "\naha152x: invalid override SETUP0={0x%x,%d,%d,%d,%d,%d,%d,%d}\n",
1018 override.synchronous,
1020 override.ext_trans);
1022 setup[setup_count++] = override;
1028 if (setup_count < ARRAY_SIZE(setup)) {
1029 struct aha152x_setup override = SETUP1;
1031 if (setup_count == 0 || (override.io_port != setup[0].io_port)) {
1032 if (!checksetup(&override)) {
1033 printk(KERN_ERR "\naha152x: invalid override SETUP1={0x%x,%d,%d,%d,%d,%d,%d,%d}\n",
1039 override.synchronous,
1041 override.ext_trans);
1043 setup[setup_count++] = override;
1049 if (setup_count<ARRAY_SIZE(setup) && (aha152x[0]!=0 || io[0]!=0 || irq[0]!=0)) {
1051 setup[setup_count].conf = "";
1052 setup[setup_count].io_port = aha152x[0];
1053 setup[setup_count].irq = aha152x[1];
1054 setup[setup_count].scsiid = aha152x[2];
1055 setup[setup_count].reconnect = aha152x[3];
1056 setup[setup_count].parity = aha152x[4];
1057 setup[setup_count].synchronous = aha152x[5];
1058 setup[setup_count].delay = aha152x[6];
1059 setup[setup_count].ext_trans = aha152x[7];
1060 #if defined(AHA152X_DEBUG)
1061 setup[setup_count].debug = aha152x[8];
1063 } else if(io[0]!=0 || irq[0]!=0) {
1064 if(io[0]!=0) setup[setup_count].io_port = io[0];
1065 if(irq[0]!=0) setup[setup_count].irq = irq[0];
1067 setup[setup_count].scsiid = scsiid[0];
1068 setup[setup_count].reconnect = reconnect[0];
1069 setup[setup_count].parity = parity[0];
1070 setup[setup_count].synchronous = sync[0];
1071 setup[setup_count].delay = delay[0];
1072 setup[setup_count].ext_trans = exttrans[0];
1073 #if defined(AHA152X_DEBUG)
1074 setup[setup_count].debug = debug[0];
1078 if (checksetup(&setup[setup_count]))
1081 printk(KERN_ERR "aha152x: invalid module params io=0x%x, irq=%d,scsiid=%d,reconnect=%d,parity=%d,sync=%d,delay=%d,exttrans=%d\n",
1082 setup[setup_count].io_port,
1083 setup[setup_count].irq,
1084 setup[setup_count].scsiid,
1085 setup[setup_count].reconnect,
1086 setup[setup_count].parity,
1087 setup[setup_count].synchronous,
1088 setup[setup_count].delay,
1089 setup[setup_count].ext_trans);
1092 if (setup_count<ARRAY_SIZE(setup) && (aha152x1[0]!=0 || io[1]!=0 || irq[1]!=0)) {
1093 if(aha152x1[0]!=0) {
1094 setup[setup_count].conf = "";
1095 setup[setup_count].io_port = aha152x1[0];
1096 setup[setup_count].irq = aha152x1[1];
1097 setup[setup_count].scsiid = aha152x1[2];
1098 setup[setup_count].reconnect = aha152x1[3];
1099 setup[setup_count].parity = aha152x1[4];
1100 setup[setup_count].synchronous = aha152x1[5];
1101 setup[setup_count].delay = aha152x1[6];
1102 setup[setup_count].ext_trans = aha152x1[7];
1103 #if defined(AHA152X_DEBUG)
1104 setup[setup_count].debug = aha152x1[8];
1106 } else if(io[1]!=0 || irq[1]!=0) {
1107 if(io[1]!=0) setup[setup_count].io_port = io[1];
1108 if(irq[1]!=0) setup[setup_count].irq = irq[1];
1110 setup[setup_count].scsiid = scsiid[1];
1111 setup[setup_count].reconnect = reconnect[1];
1112 setup[setup_count].parity = parity[1];
1113 setup[setup_count].synchronous = sync[1];
1114 setup[setup_count].delay = delay[1];
1115 setup[setup_count].ext_trans = exttrans[1];
1116 #if defined(AHA152X_DEBUG)
1117 setup[setup_count].debug = debug[1];
1120 if (checksetup(&setup[setup_count]))
1123 printk(KERN_ERR "aha152x: invalid module params io=0x%x, irq=%d,scsiid=%d,reconnect=%d,parity=%d,sync=%d,delay=%d,exttrans=%d\n",
1124 setup[setup_count].io_port,
1125 setup[setup_count].irq,
1126 setup[setup_count].scsiid,
1127 setup[setup_count].reconnect,
1128 setup[setup_count].parity,
1129 setup[setup_count].synchronous,
1130 setup[setup_count].delay,
1131 setup[setup_count].ext_trans);
1136 while ( setup_count<ARRAY_SIZE(setup) && (dev=isapnp_find_dev(NULL, ISAPNP_VENDOR('A','D','P'), ISAPNP_FUNCTION(0x1505), dev)) ) {
1137 if (dev->prepare(dev) < 0)
1141 if (!(dev->resource[0].flags & IORESOURCE_IO))
1143 dev->resource[0].flags |= IORESOURCE_AUTO;
1144 if (dev->activate(dev) < 0)
1146 if ( setup_count==1 && dev->resource[0].start==setup[0].io_port) {
1147 dev->deactivate(dev);
1150 setup[setup_count].io_port = dev->resource[0].start;
1151 setup[setup_count].irq = dev->irq_resource[0].start;
1152 setup[setup_count].scsiid = 7;
1153 setup[setup_count].reconnect = 1;
1154 setup[setup_count].parity = 1;
1155 setup[setup_count].synchronous = 1;
1156 setup[setup_count].delay = DELAY_DEFAULT;
1157 setup[setup_count].ext_trans = 0;
1158 #if defined(AHA152X_DEBUG)
1159 setup[setup_count].debug = DEBUG_DEFAULT;
1161 pnpdev[num_pnpdevs++] = dev;
1163 "aha152x: found ISAPnP AVA-1505A at io=0x%03x, irq=%d\n",
1164 setup[setup_count].io_port, setup[setup_count].irq);
1170 #if defined(AUTOCONF)
1171 if (setup_count<ARRAY_SIZE(setup)) {
1172 #if !defined(SKIP_BIOSTEST)
1174 for (i = 0; i < ARRAY_SIZE(addresses) && !ok; i++)
1175 for (j = 0; j<ARRAY_SIZE(signatures) && !ok; j++)
1176 ok = isa_check_signature(addresses[i] + signatures[j].sig_offset,
1177 signatures[j].signature, signatures[j].sig_length);
1179 if (!ok && setup_count == 0)
1182 printk(KERN_INFO "aha152x: BIOS test: passed, ");
1184 printk(KERN_INFO "aha152x: ");
1185 #endif /* !SKIP_BIOSTEST */
1188 for (i = 0; i < ARRAY_SIZE(ports) && setup_count < 2; i++) {
1189 if ((setup_count == 1) && (setup[0].io_port == ports[i]))
1192 if (aha152x_porttest(ports[i])) {
1194 setup[setup_count].io_port = ports[i];
1195 setup[setup_count].tc1550 = 0;
1198 (GETPORT(ports[i] + O_PORTA) << 8) + GETPORT(ports[i] + O_PORTB);
1200 setup[setup_count].irq = IRQ_MIN + conf.cf_irq;
1201 setup[setup_count].scsiid = conf.cf_id;
1202 setup[setup_count].reconnect = conf.cf_tardisc;
1203 setup[setup_count].parity = !conf.cf_parity;
1204 setup[setup_count].synchronous = conf.cf_syncneg;
1205 setup[setup_count].delay = DELAY_DEFAULT;
1206 setup[setup_count].ext_trans = 0;
1207 #if defined(AHA152X_DEBUG)
1208 setup[setup_count].debug = DEBUG_DEFAULT;
1211 } else if (tc1550_porttest(ports[i])) {
1213 setup[setup_count].io_port = ports[i];
1214 setup[setup_count].tc1550 = 1;
1217 (GETPORT(ports[i] + O_PORTA) << 8) + GETPORT(ports[i] + O_PORTB);
1219 setup[setup_count].irq = IRQ_MIN + conf.cf_irq;
1220 setup[setup_count].scsiid = conf.cf_id;
1221 setup[setup_count].reconnect = conf.cf_tardisc;
1222 setup[setup_count].parity = !conf.cf_parity;
1223 setup[setup_count].synchronous = conf.cf_syncneg;
1224 setup[setup_count].delay = DELAY_DEFAULT;
1225 setup[setup_count].ext_trans = 0;
1226 #if defined(AHA152X_DEBUG)
1227 setup[setup_count].debug = DEBUG_DEFAULT;
1234 printk("auto configuration: ok, ");
1238 printk("detected %d controller(s)\n", setup_count);
1240 for (i=0; i<setup_count; i++) {
1241 struct Scsi_Host *shpnt;
1243 aha152x_host[registered_count] = shpnt =
1244 scsi_register(tpnt, sizeof(struct aha152x_hostdata));
1247 printk(KERN_ERR "aha152x: scsi_register failed\n");
1253 shpnt->io_port = setup[i].io_port;
1254 shpnt->n_io_port = IO_RANGE;
1255 shpnt->irq = setup[i].irq;
1257 if(!setup[i].tc1550) {
1258 HOSTIOPORT0 = setup[i].io_port;
1259 HOSTIOPORT1 = setup[i].io_port;
1261 HOSTIOPORT0 = setup[i].io_port+0x10;
1262 HOSTIOPORT1 = setup[i].io_port-0x10;
1268 DISCONNECTED_SC = 0;
1270 QLOCK = SPIN_LOCK_UNLOCKED;
1279 RECONNECT = setup[i].reconnect;
1280 SYNCHRONOUS = setup[i].synchronous;
1281 PARITY = setup[i].parity;
1282 DELAY = setup[i].delay;
1283 EXT_TRANS = setup[i].ext_trans;
1284 #if defined(AHA152X_DEBUG)
1285 HOSTDATA(shpnt)->debug = setup[i].debug;
1287 HOSTDATA(shpnt)->in_intr = 0;
1288 HOSTDATA(shpnt)->commands = 0;
1290 #if defined(AHA152X_STAT)
1291 HOSTDATA(shpnt)->total_commands=0;
1292 HOSTDATA(shpnt)->disconnections=0;
1293 HOSTDATA(shpnt)->busfree_without_any_action=0;
1294 HOSTDATA(shpnt)->busfree_without_old_command=0;
1295 HOSTDATA(shpnt)->busfree_without_new_command=0;
1296 HOSTDATA(shpnt)->busfree_without_done_command=0;
1297 HOSTDATA(shpnt)->busfree_with_check_condition=0;
1298 for (j = idle; j<maxstate; j++) {
1299 HOSTDATA(shpnt)->count[j]=0;
1300 HOSTDATA(shpnt)->count_trans[j]=0;
1301 HOSTDATA(shpnt)->time[j]=0;
1305 for (j = 0; j < 8; j++) {
1306 HOSTDATA(shpnt)->syncrate[j] = 0;
1307 HOSTDATA(shpnt)->syncneg[j] = 0;
1310 SETPORT(SCSIID, setup[i].scsiid << 4);
1311 shpnt->this_id = setup[i].scsiid;
1313 if (setup[i].reconnect)
1314 shpnt->can_queue = AHA152X_MAXQUEUE;
1317 printk("aha152x: resetting bus...\n");
1318 SETPORT(SCSISEQ, SCSIRSTO);
1320 SETPORT(SCSISEQ, 0);
1327 "vital data: rev=%x, "
1328 "io=0x%03lx (0x%03lx/0x%03lx), "
1335 "extended translation=%s\n",
1336 HOSTNO, setup[i].tc1550 ? " (tc1550 mode)" : "",
1338 shpnt->io_port, HOSTIOPORT0, HOSTIOPORT1,
1341 RECONNECT ? "enabled" : "disabled",
1342 PARITY ? "enabled" : "disabled",
1343 SYNCHRONOUS ? "enabled" : "disabled",
1345 EXT_TRANS ? "enabled" : "disabled");
1347 request_region(shpnt->io_port, IO_RANGE, "aha152x");
1349 /* not expecting any interrupts */
1350 SETPORT(SIMODE0, 0);
1351 SETPORT(SIMODE1, 0);
1353 ok = request_irq(shpnt->irq, swintr, SA_INTERRUPT|SA_SHIRQ, "aha152x", shpnt);
1356 printk(KERN_ERR "aha152x%d: bad IRQ %d.\n", HOSTNO, shpnt->irq);
1358 printk(KERN_ERR "aha152x%d: IRQ %d already in use.\n", HOSTNO, shpnt->irq);
1360 printk(KERN_ERR "aha152x%d: Unexpected error code %d on requesting IRQ %d.\n", HOSTNO, ok, shpnt->irq);
1362 printk(KERN_ERR "aha152x%d: driver needs an IRQ.\n", HOSTNO);
1364 scsi_unregister(shpnt);
1366 release_region(shpnt->io_port, IO_RANGE);
1367 aha152x_host[registered_count] = 0;
1371 HOSTDATA(shpnt)->swint = 0;
1373 printk(KERN_INFO "aha152x%d: trying software interrupt, ", HOSTNO);
1374 SETPORT(DMACNTRL0, SWINT|INTEN);
1375 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
1376 spin_unlock_irq(&io_request_lock);
1379 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
1380 spin_lock_irq(&io_request_lock);
1382 free_irq(shpnt->irq, shpnt);
1384 if (!HOSTDATA(shpnt)->swint) {
1385 if (TESTHI(DMASTAT, INTSTAT)) {
1388 printk("failed.\n");
1391 SETPORT(DMACNTRL0, INTEN);
1393 printk(KERN_ERR "aha152x%d: IRQ %d possibly wrong. Please verify.\n", HOSTNO, shpnt->irq);
1396 release_region(shpnt->io_port, IO_RANGE);
1397 aha152x_host[registered_count] = 0;
1398 scsi_unregister(shpnt);
1405 /* clear interrupts */
1406 SETPORT(SSTAT0, 0x7f);
1407 SETPORT(SSTAT1, 0xef);
1409 if (request_irq(shpnt->irq, intr, SA_INTERRUPT|SA_SHIRQ, "aha152x", shpnt) < 0) {
1410 printk(KERN_ERR "aha152x%d: failed to reassign interrupt.\n", HOSTNO);
1413 release_region(shpnt->io_port, IO_RANGE);
1414 aha152x_host[registered_count] = 0;
1415 scsi_unregister(shpnt);
1421 return registered_count>0;
1425 int aha152x_release(struct Scsi_Host *shpnt)
1428 free_irq(shpnt->irq, shpnt);
1431 release_region(shpnt->io_port, IO_RANGE);
1434 while (num_pnpdevs--)
1435 pnpdev[num_pnpdevs]->deactivate(pnpdev[num_pnpdevs]);
1437 scsi_unregister(shpnt);
1443 * setup controller to generate interrupts depending
1444 * on current state (lock has to be acquired)
1447 static int setup_expected_interrupts(struct Scsi_Host *shpnt)
1449 ASSERT_LOCK(&QLOCK,1);
1452 CURRENT_SC->SCp.phase |= 1 << 16;
1454 if(CURRENT_SC->SCp.phase & selecting) {
1455 DPRINTK(debug_intr, DEBUG_LEAD "expecting: (seldo) (seltimo) (seldi)\n", CMDINFO(CURRENT_SC));
1456 SETPORT(SSTAT1, SELTO);
1457 SETPORT(SIMODE0, ENSELDO | (DISCONNECTED_SC ? ENSELDI : 0));
1458 SETPORT(SIMODE1, ENSELTIMO);
1460 DPRINTK(debug_intr, DEBUG_LEAD "expecting: (phase change) (busfree) %s\n", CMDINFO(CURRENT_SC), CURRENT_SC->SCp.phase & spiordy ? "(spiordy)" : "");
1461 SETPORT(SIMODE0, (CURRENT_SC->SCp.phase & spiordy) ? ENSPIORDY : 0);
1462 SETPORT(SIMODE1, ENPHASEMIS | ENSCSIRST | ENSCSIPERR | ENBUSFREE);
1464 } else if(STATE==seldi) {
1465 DPRINTK(debug_intr, DEBUG_LEAD "expecting: (phase change) (identify)\n", CMDINFO(CURRENT_SC));
1466 SETPORT(SIMODE0, 0);
1467 SETPORT(SIMODE1, ENPHASEMIS | ENSCSIRST | ENSCSIPERR | ENBUSFREE);
1469 DPRINTK(debug_intr, DEBUG_LEAD "expecting: %s %s\n",
1470 CMDINFO(CURRENT_SC),
1471 DISCONNECTED_SC ? "(reselection)" : "",
1472 ISSUE_SC ? "(busfree)" : "");
1473 SETPORT(SIMODE0, DISCONNECTED_SC ? ENSELDI : 0);
1474 SETPORT(SIMODE1, ENSCSIRST | ( (ISSUE_SC||DONE_SC) ? ENBUSFREE : 0));
1477 if(!HOSTDATA(shpnt)->in_intr)
1478 SETBITS(DMACNTRL0, INTEN);
1480 return TESTHI(DMASTAT, INTSTAT);
1485 * Queue a command and setup interrupts for a free bus.
1487 int aha152x_internal_queue(Scsi_Cmnd *SCpnt, struct semaphore *sem, int phase, Scsi_Cmnd *done_SC, void (*done)(Scsi_Cmnd *))
1489 struct Scsi_Host *shpnt = SCpnt->host;
1490 unsigned long flags;
1492 #if defined(AHA152X_DEBUG)
1493 if (HOSTDATA(shpnt)->debug & debug_queue) {
1494 printk(INFO_LEAD "queue: cmd_len=%d pieces=%d size=%u cmnd=",
1495 CMDINFO(SCpnt), SCpnt->cmd_len, SCpnt->use_sg, SCpnt->request_bufflen);
1496 print_command(SCpnt->cmnd);
1500 SCpnt->scsi_done = done;
1501 SCpnt->resid = SCpnt->request_bufflen;
1502 SCpnt->SCp.phase = not_issued | phase;
1503 SCpnt->SCp.Status = CHECK_CONDITION;
1504 SCpnt->SCp.Message = 0;
1505 SCpnt->SCp.have_data_in = 0;
1506 SCpnt->SCp.sent_command = 0;
1507 SCpnt->host_scribble = kmalloc(sizeof(struct aha152x_scdata), GFP_ATOMIC);
1508 if(!SCpnt->host_scribble) {
1509 printk(ERR_LEAD "allocation failed\n", CMDINFO(SCpnt));
1514 SCDONE(SCpnt) = done_SC;
1517 /* setup scratch area
1518 SCp.ptr : buffer pointer
1519 SCp.this_residual : buffer length
1520 SCp.buffer : next buffer
1521 SCp.buffers_residual : left buffers in list
1522 SCp.phase : current state of the command */
1523 if (SCpnt->use_sg) {
1524 SCpnt->SCp.buffer = (struct scatterlist *) SCpnt->request_buffer;
1525 SCpnt->SCp.ptr = SG_ADDRESS(SCpnt->SCp.buffer);
1526 SCpnt->SCp.this_residual = SCpnt->SCp.buffer->length;
1527 SCpnt->SCp.buffers_residual = SCpnt->use_sg - 1;
1529 SCpnt->SCp.ptr = (char *) SCpnt->request_buffer;
1530 SCpnt->SCp.this_residual = SCpnt->request_bufflen;
1531 SCpnt->SCp.buffer = NULL;
1532 SCpnt->SCp.buffers_residual = 0;
1537 #if defined(AHA152X_STAT)
1538 HOSTDATA(shpnt)->total_commands++;
1541 /* Turn led on, when this is the first command. */
1542 HOSTDATA(shpnt)->commands++;
1543 if (HOSTDATA(shpnt)->commands==1)
1546 append_SC(&ISSUE_SC, SCpnt);
1548 if(!HOSTDATA(shpnt)->in_intr)
1549 setup_expected_interrupts(shpnt);
1556 int aha152x_queue(Scsi_Cmnd *SCpnt, void (*done)(Scsi_Cmnd *))
1559 if(*SCpnt->cmnd == REQUEST_SENSE) {
1567 return aha152x_internal_queue(SCpnt, 0, 0, 0, done);
1575 void internal_done(Scsi_Cmnd *SCpnt)
1578 struct Scsi_Host *shpnt = SCpnt->host;
1580 DPRINTK(debug_eh, INFO_LEAD "internal_done called\n", CMDINFO(SCpnt));
1586 int aha152x_command(Scsi_Cmnd * SCpnt)
1588 DECLARE_MUTEX_LOCKED(sem);
1590 aha152x_internal_queue(SCpnt, &sem, 0, 0, internal_done);
1600 int aha152x_abort(Scsi_Cmnd *SCpnt)
1602 struct Scsi_Host *shpnt = SCpnt->host;
1604 unsigned long flags;
1607 printk(ERR_LEAD "abort(%p): no host structure\n", CMDINFO(SCpnt), SCpnt);
1611 #if defined(AHA152X_DEBUG)
1612 if(HOSTDATA(shpnt)->debug & debug_eh) {
1613 printk(DEBUG_LEAD "abort(%p)", CMDINFO(SCpnt), SCpnt);
1620 ptr=remove_SC(&ISSUE_SC, SCpnt);
1623 DPRINTK(debug_eh, DEBUG_LEAD "not yet issued - SUCCESS\n", CMDINFO(SCpnt));
1625 HOSTDATA(shpnt)->commands--;
1626 if (!HOSTDATA(shpnt)->commands)
1630 kfree(SCpnt->host_scribble);
1631 SCpnt->host_scribble=0;
1640 * for current command: queue ABORT for message out and raise ATN
1641 * for disconnected command: pseudo SC with ABORT message or ABORT on reselection?
1645 printk(ERR_LEAD "cannot abort running or disconnected command\n", CMDINFO(SCpnt));
1650 static void timer_expired(unsigned long p)
1652 Scsi_Cmnd *SCp = (Scsi_Cmnd *)p;
1653 struct semaphore *sem = SCSEM(SCp);
1654 struct Scsi_Host *shpnt = SCp->host;
1656 /* remove command from issue queue */
1657 if(remove_SC(&ISSUE_SC, SCp)) {
1658 printk(KERN_INFO "aha152x: ABORT timed out - removed from issue queue\n");
1659 kfree(SCp->host_scribble);
1660 SCp->host_scribble=0;
1662 printk(KERN_INFO "aha152x: ABORT timed out - not on issue queue\n");
1671 * FIXME: never seen this live. might lockup...
1674 int aha152x_device_reset(Scsi_Cmnd * SCpnt)
1676 struct Scsi_Host *shpnt = SCpnt->host;
1677 DECLARE_MUTEX_LOCKED(sem);
1678 struct timer_list timer;
1681 #if defined(AHA152X_DEBUG)
1682 if(HOSTDATA(shpnt)->debug & debug_eh) {
1683 printk(INFO_LEAD "aha152x_device_reset(%p)", CMDINFO(SCpnt), SCpnt);
1688 if(CURRENT_SC==SCpnt) {
1689 printk(ERR_LEAD "cannot reset current device\n", CMDINFO(SCpnt));
1694 cmnd.host = SCpnt->host;
1695 cmnd.target = SCpnt->target;
1696 cmnd.lun = SCpnt->lun;
1698 cmnd.request_buffer = 0;
1699 cmnd.request_bufflen = 0;
1702 timer.data = (unsigned long) &cmnd;
1703 timer.expires = jiffies + 100*HZ; /* 10s */
1704 timer.function = (void (*)(unsigned long)) timer_expired;
1706 aha152x_internal_queue(&cmnd, &sem, resetting, 0, internal_done);
1713 if(cmnd.SCp.phase & resetted) {
1720 void free_hard_reset_SCs(struct Scsi_Host *shpnt, Scsi_Cmnd **SCs)
1723 unsigned long flags;
1729 Scsi_Cmnd *next = SCNEXT(ptr);
1731 if (!ptr->device->soft_reset) {
1732 DPRINTK(debug_eh, DEBUG_LEAD "disconnected command %p removed\n", CMDINFO(ptr), ptr);
1733 remove_SC(SCs, ptr);
1734 HOSTDATA(shpnt)->commands--;
1735 kfree(ptr->host_scribble);
1736 ptr->host_scribble=0;
1749 int aha152x_bus_reset(Scsi_Cmnd *SCpnt)
1751 struct Scsi_Host *shpnt = SCpnt->host;
1752 unsigned long flags;
1754 #if defined(AHA152X_DEBUG)
1755 if(HOSTDATA(shpnt)->debug & debug_eh) {
1756 printk(DEBUG_LEAD "aha152x_bus_reset(%p)", CMDINFO(SCpnt), SCpnt);
1761 free_hard_reset_SCs(shpnt, &ISSUE_SC);
1762 free_hard_reset_SCs(shpnt, &DISCONNECTED_SC);
1764 DPRINTK(debug_eh, DEBUG_LEAD "resetting bus\n", CMDINFO(SCpnt));
1766 SETPORT(SCSISEQ, SCSIRSTO);
1768 SETPORT(SCSISEQ, 0);
1771 DPRINTK(debug_eh, DEBUG_LEAD "bus reset returns\n", CMDINFO(SCpnt));
1774 setup_expected_interrupts(shpnt);
1775 if(HOSTDATA(shpnt)->commands==0)
1784 * Restore default values to the AIC-6260 registers and reset the fifos
1787 static void reset_ports(struct Scsi_Host *shpnt)
1789 unsigned long flags;
1791 /* disable interrupts */
1792 SETPORT(DMACNTRL0, RSTFIFO);
1794 SETPORT(SCSISEQ, 0);
1796 SETPORT(SXFRCTL1, 0);
1797 SETPORT(SCSISIG, 0);
1800 /* clear all interrupt conditions */
1801 SETPORT(SSTAT0, 0x7f);
1802 SETPORT(SSTAT1, 0xef);
1804 SETPORT(SSTAT4, SYNCERR | FWERR | FRERR);
1806 SETPORT(DMACNTRL0, 0);
1807 SETPORT(DMACNTRL1, 0);
1809 SETPORT(BRSTCNTRL, 0xf1);
1811 /* clear SCSI fifos and transfer count */
1812 SETPORT(SXFRCTL0, CH1|CLRCH1|CLRSTCNT);
1813 SETPORT(SXFRCTL0, CH1);
1816 setup_expected_interrupts(shpnt);
1821 * Reset the host (bus and controller)
1824 int aha152x_host_reset(Scsi_Cmnd * SCpnt)
1826 #if defined(AHA152X_DEBUG)
1827 struct Scsi_Host *shpnt = SCpnt->host;
1830 DPRINTK(debug_eh, DEBUG_LEAD "aha152x_host_reset(%p)\n", CMDINFO(SCpnt), SCpnt);
1832 aha152x_bus_reset(SCpnt);
1834 DPRINTK(debug_eh, DEBUG_LEAD "resetting ports\n", CMDINFO(SCpnt));
1835 reset_ports(SCpnt->host);
1841 * Return the "logical geometry"
1844 int aha152x_biosparam(Scsi_Disk * disk, kdev_t dev, int *info_array)
1846 struct Scsi_Host *shpnt = disk->device->host;
1848 /* try default translation */
1851 info_array[2] = disk->capacity / (64 * 32);
1853 /* for disks >1GB do some guessing */
1854 if (info_array[2] >= 1024) {
1857 /* try to figure out the geometry from the partition table */
1858 if (scsicam_bios_param(disk, dev, info) < 0 ||
1859 !((info[0] == 64 && info[1] == 32) || (info[0] == 255 && info[1] == 63))) {
1862 "aha152x: unable to verify geometry for disk with >1GB.\n"
1863 " using extended translation.\n");
1864 info_array[0] = 255;
1866 info_array[2] = disk->capacity / (255 * 63);
1869 "aha152x: unable to verify geometry for disk with >1GB.\n"
1870 " Using default translation. Please verify yourself.\n"
1871 " Perhaps you need to enable extended translation in the driver.\n"
1872 " See /usr/src/linux/drivers/scsi/README.aha152x for details.\n");
1875 info_array[0] = info[0];
1876 info_array[1] = info[1];
1877 info_array[2] = info[2];
1879 if (info[0] == 255 && !EXT_TRANS) {
1881 "aha152x: current partition table is using extended translation.\n"
1882 " using it also, although it's not explicitly enabled.\n");
1891 * Internal done function
1894 static void done(struct Scsi_Host *shpnt, int error)
1898 printk(ERR_LEAD "there's already a completed command %p - will cause abort\n", CMDINFO(CURRENT_SC), DONE_SC);
1900 DONE_SC = CURRENT_SC;
1902 DONE_SC->result = error;
1904 printk(KERN_ERR "aha152x: done() called outside of command\n");
1907 static struct tq_struct aha152x_tq;
1910 * Run service completions on the card with interrupts enabled.
1913 static void run(void)
1916 for (i = 0; i<ARRAY_SIZE(aha152x_host); i++) {
1917 struct Scsi_Host *shpnt = aha152x_host[i];
1918 if (shpnt && HOSTDATA(shpnt)->service) {
1919 HOSTDATA(shpnt)->service=0;
1926 * Interrupts handler
1930 static void intr(int irqno, void *dev_id, struct pt_regs *regs)
1932 struct Scsi_Host *shpnt = lookup_irq(irqno);
1933 unsigned char rev, dmacntrl0;
1936 printk(KERN_ERR "aha152x: catched interrupt %d for unknown controller.\n", irqno);
1941 * Read a couple of registers that are known to not be all 1's. If
1942 * we read all 1's (-1), that means that either:
1943 * a. The host adapter chip has gone bad, and we cannot control it,
1945 * b. The host adapter is a PCMCIA card that has been ejected
1946 * In either case, we cannot do anything with the host adapter at
1947 * this point in time. So just ignore the interrupt and return.
1948 * In the latter case, the interrupt might actually be meant for
1949 * someone else sharing this IRQ, and that driver will handle it
1952 dmacntrl0 = GETPORT(DMACNTRL0);
1953 if ((rev == 0xFF) && (dmacntrl0 == 0xFF)) {
1957 /* no more interrupts from the controller, while we're busy.
1958 INTEN is restored by the BH handler */
1959 CLRBITS(DMACNTRL0, INTEN);
1962 /* check if there is already something to be
1963 serviced; should not happen */
1964 if(HOSTDATA(shpnt)->service) {
1965 printk(KERN_ERR "aha152x%d: lost interrupt (%d)\n", HOSTNO, HOSTDATA(shpnt)->service);
1970 /* Poke the BH handler */
1971 HOSTDATA(shpnt)->service++;
1972 aha152x_tq.routine = (void *) run;
1973 queue_task(&aha152x_tq, &tq_immediate);
1974 mark_bh(IMMEDIATE_BH);
1979 * - handle completition/disconnection/error of current command
1980 * - start selection for next command (if any)
1982 static void busfree_run(struct Scsi_Host *shpnt)
1984 unsigned long flags;
1985 #if defined(AHA152X_STAT)
1989 SETPORT(SXFRCTL0, CH1|CLRCH1|CLRSTCNT);
1990 SETPORT(SXFRCTL0, CH1);
1992 SETPORT(SSTAT1, CLRBUSFREE);
1995 #if defined(AHA152X_STAT)
1998 CURRENT_SC->SCp.phase &= ~syncneg;
2000 if(CURRENT_SC->SCp.phase & completed) {
2001 /* target sent COMMAND COMPLETE */
2002 done(shpnt, (CURRENT_SC->SCp.Status & 0xff) | ((CURRENT_SC->SCp.Message & 0xff) << 8) | (DID_OK << 16));
2004 } else if(CURRENT_SC->SCp.phase & aborted) {
2005 DPRINTK(debug_eh, DEBUG_LEAD "ABORT sent\n", CMDINFO(CURRENT_SC));
2006 done(shpnt, (CURRENT_SC->SCp.Status & 0xff) | ((CURRENT_SC->SCp.Message & 0xff) << 8) | (DID_ABORT << 16));
2008 } else if(CURRENT_SC->SCp.phase & resetted) {
2009 DPRINTK(debug_eh, DEBUG_LEAD "BUS DEVICE RESET sent\n", CMDINFO(CURRENT_SC));
2010 done(shpnt, (CURRENT_SC->SCp.Status & 0xff) | ((CURRENT_SC->SCp.Message & 0xff) << 8) | (DID_RESET << 16));
2012 } else if(CURRENT_SC->SCp.phase & disconnected) {
2013 /* target sent DISCONNECT */
2014 DPRINTK(debug_selection, DEBUG_LEAD "target disconnected at %d/%d\n",
2015 CMDINFO(CURRENT_SC),
2017 CURRENT_SC->request_bufflen);
2018 #if defined(AHA152X_STAT)
2019 HOSTDATA(shpnt)->disconnections++;
2021 append_SC(&DISCONNECTED_SC, CURRENT_SC);
2022 CURRENT_SC->SCp.phase |= 1 << 16;
2026 done(shpnt, DID_ERROR << 16);
2028 #if defined(AHA152X_STAT)
2030 HOSTDATA(shpnt)->busfree_without_old_command++;
2037 #if defined(AHA152X_STAT)
2040 if(SCDONE(DONE_SC)) {
2041 Scsi_Cmnd *ptr=DONE_SC;
2042 DONE_SC=SCDONE(DONE_SC);
2045 if(HOSTDATA(shpnt)->debug & debug_eh) {
2046 printk(ERR_LEAD "received sense: ", CMDINFO(ptr));
2047 print_sense("bh", DONE_SC);
2051 HOSTDATA(shpnt)->commands--;
2052 if (!HOSTDATA(shpnt)->commands)
2053 SETPORT(PORTA, 0); /* turn led off */
2055 kfree(ptr->host_scribble);
2057 } else if(DONE_SC->SCp.Status==0x02) {
2058 #if defined(AHA152X_STAT)
2059 HOSTDATA(shpnt)->busfree_with_check_condition++;
2062 DPRINTK(debug_eh, ERR_LEAD "CHECK CONDITION found\n", CMDINFO(DONE_SC));
2065 if(!(DONE_SC->SCp.Status & not_issued)) {
2066 Scsi_Cmnd *cmnd = kmalloc(sizeof(Scsi_Cmnd), GFP_ATOMIC);
2069 Scsi_Cmnd *ptr=DONE_SC;
2073 DPRINTK(debug_eh, ERR_LEAD "requesting sense\n", CMDINFO(ptr));
2076 cmnd->cmnd[0] = REQUEST_SENSE;
2080 cmnd->cmnd[4] = sizeof(ptr->sense_buffer);
2083 cmnd->host = ptr->host;
2084 cmnd->target = ptr->target;
2085 cmnd->lun = ptr->lun;
2087 cmnd->request_buffer = ptr->sense_buffer;
2088 cmnd->request_bufflen = sizeof(ptr->sense_buffer);
2091 aha152x_internal_queue(cmnd, 0, 0, ptr, internal_done);
2094 printk(ERR_LEAD "allocation failed\n", CMDINFO(CURRENT_SC));
2100 DPRINTK(debug_eh, ERR_LEAD "command not issued - CHECK CONDITION ignored\n", CMDINFO(DONE_SC));
2105 if(DONE_SC && DONE_SC->scsi_done) {
2106 /* turn led off, when no commands are in the driver */
2107 HOSTDATA(shpnt)->commands--;
2108 if (!HOSTDATA(shpnt)->commands)
2109 SETPORT(PORTA, 0); /* turn led off */
2112 DPRINTK(debug_done, DEBUG_LEAD "calling scsi_done(%p)\n", CMDINFO(DONE_SC), DONE_SC);
2113 DONE_SC->scsi_done(DONE_SC);
2114 DPRINTK(debug_done, DEBUG_LEAD "scsi_done(%p) returned\n", CMDINFO(DONE_SC), DONE_SC);
2117 kfree(DONE_SC->host_scribble);
2118 DONE_SC->host_scribble=0;
2122 #if defined(AHA152X_STAT)
2124 HOSTDATA(shpnt)->busfree_without_done_command++;
2129 CURRENT_SC = remove_first_SC(&ISSUE_SC);
2134 #if defined(AHA152X_STAT)
2137 CURRENT_SC->SCp.phase |= selecting;
2139 DPRINTK(debug_selection, DEBUG_LEAD "selecting target\n", CMDINFO(CURRENT_SC));
2141 /* clear selection timeout */
2142 SETPORT(SSTAT1, SELTO);
2144 SETPORT(SCSIID, (shpnt->this_id << OID_) | CURRENT_SC->target);
2145 SETPORT(SXFRCTL1, (PARITY ? ENSPCHK : 0 ) | ENSTIMER);
2146 SETPORT(SCSISEQ, ENSELO | ENAUTOATNO | (DISCONNECTED_SC ? ENRESELI : 0));
2148 #if defined(AHA152X_STAT)
2149 HOSTDATA(shpnt)->busfree_without_new_command++;
2151 SETPORT(SCSISEQ, DISCONNECTED_SC ? ENRESELI : 0);
2154 #if defined(AHA152X_STAT)
2156 HOSTDATA(shpnt)->busfree_without_any_action++;
2161 * Selection done (OUT)
2162 * - queue IDENTIFY message and SDTR to selected target for message out
2163 * (ATN asserted automagically via ENAUTOATNO in busfree())
2165 static void seldo_run(struct Scsi_Host *shpnt)
2167 SETPORT(SCSISIG, 0);
2168 SETPORT(SSTAT1, CLRBUSFREE);
2169 SETPORT(SSTAT1, CLRPHASECHG);
2171 CURRENT_SC->SCp.phase &= ~(selecting|not_issued);
2173 SETPORT(SCSISEQ, 0);
2175 if (TESTLO(SSTAT0, SELDO)) {
2176 printk(ERR_LEAD "aha152x: passing bus free condition\n", CMDINFO(CURRENT_SC));
2177 done(shpnt, DID_NO_CONNECT << 16);
2181 SETPORT(SSTAT0, CLRSELDO);
2183 ADDMSGO(IDENTIFY(RECONNECT, CURRENT_SC->lun));
2185 if (CURRENT_SC->SCp.phase & aborting) {
2187 } else if (CURRENT_SC->SCp.phase & resetting) {
2188 ADDMSGO(BUS_DEVICE_RESET);
2189 } else if (SYNCNEG==0 && SYNCHRONOUS) {
2190 CURRENT_SC->SCp.phase |= syncneg;
2191 ADDMSGO(EXTENDED_MESSAGE);
2193 ADDMSGO(EXTENDED_SDTR);
2194 ADDMSGO(50); /* 200ns */
2195 ADDMSGO(8); /* 8 byte req/ack offset */
2197 SYNCNEG=1; /* negotiation in progress */
2205 * - return command to mid-level with failure cause
2208 static void selto_run(struct Scsi_Host *shpnt)
2210 SETPORT(SCSISEQ, 0);
2211 SETPORT(SSTAT1, CLRSELTIMO);
2213 DPRINTK(debug_selection, DEBUG_LEAD "selection timeout\n", CMDINFO(CURRENT_SC));
2216 DPRINTK(debug_selection, DEBUG_LEAD "!CURRENT_SC\n", CMDINFO(CURRENT_SC));
2220 CURRENT_SC->SCp.phase &= ~selecting;
2222 if (CURRENT_SC->SCp.phase & aborted) {
2223 DPRINTK(debug_selection, DEBUG_LEAD "aborted\n", CMDINFO(CURRENT_SC));
2224 done(shpnt, DID_ABORT << 16);
2225 } else if (TESTLO(SSTAT0, SELINGO)) {
2226 DPRINTK(debug_selection, DEBUG_LEAD "arbitration not won\n", CMDINFO(CURRENT_SC));
2227 done(shpnt, DID_BUS_BUSY << 16);
2229 /* ARBITRATION won, but SELECTION failed */
2230 DPRINTK(debug_selection, DEBUG_LEAD "selection failed\n", CMDINFO(CURRENT_SC));
2231 done(shpnt, DID_NO_CONNECT << 16);
2237 * - put current command back to issue queue
2238 * (reconnection of a disconnected nexus instead
2239 * of successful selection out)
2242 static void seldi_run(struct Scsi_Host *shpnt)
2246 unsigned long flags;
2248 SETPORT(SCSISIG, 0);
2249 SETPORT(SSTAT0, CLRSELDI);
2250 SETPORT(SSTAT1, CLRBUSFREE);
2251 SETPORT(SSTAT1, CLRPHASECHG);
2254 if(!(CURRENT_SC->SCp.phase & not_issued))
2255 printk(ERR_LEAD "command should not have been issued yet\n", CMDINFO(CURRENT_SC));
2257 DPRINTK(debug_selection, ERR_LEAD "command requeued - reselection\n", CMDINFO(CURRENT_SC));
2260 append_SC(&ISSUE_SC, CURRENT_SC);
2266 if(!DISCONNECTED_SC) {
2267 DPRINTK(debug_selection, DEBUG_LEAD "unexpected SELDI ", CMDINFO(CURRENT_SC));
2273 selid = GETPORT(SELID) & ~(1 << shpnt->this_id);
2276 printk("aha152x%d: target id unknown (%02x)\n", HOSTNO, selid);
2280 for(target=7; !(selid & (1 << target)); target--)
2283 if(selid & ~(1 << target)) {
2284 printk("aha152x%d: multiple targets reconnected (%02x)\n",
2289 SETPORT(SCSIID, (shpnt->this_id << OID_) | target);
2290 SETPORT(SCSISEQ, 0);
2292 SETRATE(HOSTDATA(shpnt)->syncrate[target]);
2294 RECONN_TARGET=target;
2295 DPRINTK(debug_selection, DEBUG_LEAD "target %d reselected (%02x).\n", CMDINFO(CURRENT_SC), target, selid);
2300 * - handle initial message after reconnection to identify
2301 * reconnecting nexus
2302 * - queue command on DISCONNECTED_SC on DISCONNECT message
2303 * - set completed flag on COMMAND COMPLETE
2304 * (other completition code moved to busfree_run)
2305 * - handle response to SDTR
2306 * - clear synchronous transfer agreements on BUS RESET
2308 * FIXME: what about SAVE POINTERS, RESTORE POINTERS?
2311 static void msgi_run(struct Scsi_Host *shpnt)
2314 int sstat1 = GETPORT(SSTAT1);
2316 if(sstat1 & (PHASECHG|PHASEMIS|BUSFREE) || !(sstat1 & REQINIT))
2319 if(TESTLO(SSTAT0,SPIORDY)) {
2320 DPRINTK(debug_msgi, DEBUG_LEAD "!SPIORDY\n", CMDINFO(CURRENT_SC));
2324 ADDMSGI(GETPORT(SCSIDAT));
2326 #if defined(AHA152X_DEBUG)
2327 if (HOSTDATA(shpnt)->debug & debug_msgi) {
2328 printk(INFO_LEAD "inbound message %02x ", CMDINFO(CURRENT_SC), MSGI(0));
2329 print_msg(&MSGI(0));
2335 if(LASTSTATE!=seldi) {
2336 printk(KERN_ERR "aha152x%d: message in w/o current command not after reselection\n", HOSTNO);
2340 * Handle reselection
2342 if(!(MSGI(0) & IDENTIFY_BASE)) {
2343 printk(KERN_ERR "aha152x%d: target didn't identify after reselection\n", HOSTNO);
2347 CURRENT_SC = remove_lun_SC(&DISCONNECTED_SC, RECONN_TARGET, MSGI(0) & 0x3f);
2351 printk(KERN_ERR "aha152x%d: no disconnected command for target %d/%d\n", HOSTNO, RECONN_TARGET, MSGI(0) & 0x3f);
2355 DPRINTK(debug_msgi, DEBUG_LEAD "target reconnected\n", CMDINFO(CURRENT_SC));
2357 CURRENT_SC->SCp.Message = MSGI(0);
2358 CURRENT_SC->SCp.phase &= ~disconnected;
2362 /* next message if any */
2366 CURRENT_SC->SCp.Message = MSGI(0);
2371 printk(WARN_LEAD "target was not allowed to disconnect\n", CMDINFO(CURRENT_SC));
2373 CURRENT_SC->SCp.phase |= disconnected;
2376 case COMMAND_COMPLETE:
2377 if(CURRENT_SC->SCp.phase & completed)
2378 DPRINTK(debug_msgi, DEBUG_LEAD "again COMMAND COMPLETE\n", CMDINFO(CURRENT_SC));
2380 CURRENT_SC->SCp.phase |= completed;
2383 case MESSAGE_REJECT:
2385 printk(INFO_LEAD "Synchronous Data Transfer Request was rejected\n", CMDINFO(CURRENT_SC));
2386 SYNCNEG=2; /* negotiation completed */
2388 printk(INFO_LEAD "inbound message (MESSAGE REJECT)\n", CMDINFO(CURRENT_SC));
2394 case RESTORE_POINTERS:
2397 case EXTENDED_MESSAGE:
2398 if(MSGILEN<2 || MSGILEN<MSGI(1)+2) {
2399 /* not yet completed */
2409 printk(ERR_LEAD "SDTR message length!=3\n", CMDINFO(CURRENT_SC));
2413 if (!HOSTDATA(shpnt)->synchronous)
2416 printk(INFO_LEAD, CMDINFO(CURRENT_SC));
2417 print_msg(&MSGI(0));
2420 ticks = (MSGI(3) * 4 + 49) / 50;
2423 /* negotiation in progress */
2424 if (ticks > 9 || MSGI(4) < 1 || MSGI(4) > 8) {
2425 ADDMSGO(MESSAGE_REJECT);
2426 printk(INFO_LEAD "received Synchronous Data Transfer Request invalid - rejected\n", CMDINFO(CURRENT_SC));
2430 SYNCRATE |= ((ticks - 2) << 4) + MSGI(4);
2431 } else if (ticks <= 9 && MSGI(4) >= 1) {
2432 ADDMSGO(EXTENDED_MESSAGE);
2434 ADDMSGO(EXTENDED_SDTR);
2446 SYNCRATE |= ((ticks - 2) << 4) + MSGI(4);
2448 /* requested SDTR is too slow, do it asynchronously */
2449 printk(INFO_LEAD "Synchronous Data Transfer Request too slow - Rejecting\n", CMDINFO(CURRENT_SC));
2450 ADDMSGO(MESSAGE_REJECT);
2453 SYNCNEG=2; /* negotiation completed */
2458 case BUS_DEVICE_RESET:
2462 for(i=0; i<8; i++) {
2463 HOSTDATA(shpnt)->syncrate[i]=0;
2464 HOSTDATA(shpnt)->syncneg[i]=0;
2470 case EXTENDED_MODIFY_DATA_POINTER:
2471 case EXTENDED_EXTENDED_IDENTIFY:
2474 ADDMSGO(MESSAGE_REJECT);
2484 static void msgi_end(struct Scsi_Host *shpnt)
2487 printk(WARN_LEAD "target left before message completed (%d)\n", CMDINFO(CURRENT_SC), MSGILEN);
2489 if (MSGOLEN > 0 && !(GETPORT(SSTAT1) & BUSFREE)) {
2490 DPRINTK(debug_msgi, DEBUG_LEAD "msgo pending\n", CMDINFO(CURRENT_SC));
2491 SETPORT(SCSISIG, P_MSGI | SIG_ATNO);
2499 static void msgo_init(struct Scsi_Host *shpnt)
2502 if((CURRENT_SC->SCp.phase & syncneg) && SYNCNEG==2 && SYNCRATE==0) {
2503 ADDMSGO(IDENTIFY(RECONNECT, CURRENT_SC->lun));
2505 printk(INFO_LEAD "unexpected MESSAGE OUT phase; rejecting\n", CMDINFO(CURRENT_SC));
2506 ADDMSGO(MESSAGE_REJECT);
2510 #if defined(AHA152X_DEBUG)
2511 if(HOSTDATA(shpnt)->debug & debug_msgo) {
2514 printk(DEBUG_LEAD "messages( ", CMDINFO(CURRENT_SC));
2515 for (i=0; i<MSGOLEN; i+=print_msg(&MSGO(i)), printk(" "))
2526 static void msgo_run(struct Scsi_Host *shpnt)
2529 DPRINTK(debug_msgo, DEBUG_LEAD "messages all sent (%d/%d)\n", CMDINFO(CURRENT_SC), MSGO_I, MSGOLEN);
2531 while(MSGO_I<MSGOLEN) {
2532 DPRINTK(debug_msgo, DEBUG_LEAD "message byte %02x (%d/%d)\n", CMDINFO(CURRENT_SC), MSGO(MSGO_I), MSGO_I, MSGOLEN);
2534 if(TESTLO(SSTAT0, SPIORDY)) {
2535 DPRINTK(debug_msgo, DEBUG_LEAD "!SPIORDY\n", CMDINFO(CURRENT_SC));
2539 if (MSGO_I==MSGOLEN-1) {
2540 /* Leave MESSAGE OUT after transfer */
2541 SETPORT(SSTAT1, CLRATNO);
2545 if (MSGO(MSGO_I) & IDENTIFY_BASE)
2546 CURRENT_SC->SCp.phase |= identified;
2548 if (MSGO(MSGO_I)==ABORT)
2549 CURRENT_SC->SCp.phase |= aborted;
2551 if (MSGO(MSGO_I)==BUS_DEVICE_RESET)
2552 CURRENT_SC->SCp.phase |= resetted;
2554 SETPORT(SCSIDAT, MSGO(MSGO_I++));
2558 static void msgo_end(struct Scsi_Host *shpnt)
2560 if(MSGO_I<MSGOLEN) {
2561 printk(ERR_LEAD "message sent incompletely (%d/%d)\n", CMDINFO(CURRENT_SC), MSGO_I, MSGOLEN);
2563 printk(INFO_LEAD "Synchronous Data Transfer Request was rejected\n", CMDINFO(CURRENT_SC));
2576 static void cmd_init(struct Scsi_Host *shpnt)
2578 if (CURRENT_SC->SCp.sent_command) {
2579 printk(ERR_LEAD "command already sent\n", CMDINFO(CURRENT_SC));
2580 done(shpnt, DID_ERROR << 16);
2584 #if defined(AHA152X_DEBUG)
2585 if (HOSTDATA(shpnt)->debug & debug_cmd) {
2586 printk(DEBUG_LEAD "cmd_init: ", CMDINFO(CURRENT_SC));
2587 print_command(CURRENT_SC->cmnd);
2598 static void cmd_run(struct Scsi_Host *shpnt)
2600 if(CMD_I==CURRENT_SC->cmd_len) {
2601 DPRINTK(debug_cmd, DEBUG_LEAD "command already completely sent (%d/%d)", CMDINFO(CURRENT_SC), CMD_I, CURRENT_SC->cmd_len);
2605 while(CMD_I<CURRENT_SC->cmd_len) {
2606 DPRINTK(debug_cmd, DEBUG_LEAD "command byte %02x (%d/%d)\n", CMDINFO(CURRENT_SC), CURRENT_SC->cmnd[CMD_I], CMD_I, CURRENT_SC->cmd_len);
2608 if(TESTLO(SSTAT0, SPIORDY)) {
2609 DPRINTK(debug_cmd, DEBUG_LEAD "!SPIORDY\n", CMDINFO(CURRENT_SC));
2613 SETPORT(SCSIDAT, CURRENT_SC->cmnd[CMD_I++]);
2617 static void cmd_end(struct Scsi_Host *shpnt)
2619 if(CMD_I<CURRENT_SC->cmd_len)
2620 printk(ERR_LEAD "command sent incompletely (%d/%d)\n", CMDINFO(CURRENT_SC), CMD_I, CURRENT_SC->cmd_len);
2622 CURRENT_SC->SCp.sent_command++;
2629 static void status_run(struct Scsi_Host *shpnt)
2631 if(TESTLO(SSTAT0,SPIORDY)) {
2632 DPRINTK(debug_status, DEBUG_LEAD "!SPIORDY\n", CMDINFO(CURRENT_SC));
2636 CURRENT_SC->SCp.Status = GETPORT(SCSIDAT);
2638 #if defined(AHA152X_DEBUG)
2639 if (HOSTDATA(shpnt)->debug & debug_status) {
2640 printk(DEBUG_LEAD "inbound status %02x ", CMDINFO(CURRENT_SC), CURRENT_SC->SCp.Status);
2641 print_status(CURRENT_SC->SCp.Status);
2651 static void datai_init(struct Scsi_Host *shpnt)
2653 SETPORT(DMACNTRL0, RSTFIFO);
2654 SETPORT(DMACNTRL0, RSTFIFO|ENDMA);
2656 SETPORT(SXFRCTL0, CH1|CLRSTCNT);
2657 SETPORT(SXFRCTL0, CH1|SCSIEN|DMAEN);
2659 SETPORT(SIMODE0, 0);
2660 SETPORT(SIMODE1, ENSCSIPERR | ENSCSIRST | ENPHASEMIS | ENBUSFREE);
2663 DPRINTK(debug_datai,
2664 DEBUG_LEAD "datai_init: request_bufflen=%d resid=%d\n",
2665 CMDINFO(CURRENT_SC), CURRENT_SC->request_bufflen, CURRENT_SC->resid);
2668 static void datai_run(struct Scsi_Host *shpnt)
2670 unsigned long the_time;
2671 int fifodata, data_count;
2674 * loop while the phase persists or the fifos are not empty
2677 while(TESTLO(DMASTAT, INTSTAT) || TESTLO(DMASTAT, DFIFOEMP) || TESTLO(SSTAT2, SEMPTY)) {
2678 /* FIXME: maybe this should be done by setting up
2679 * STCNT to trigger ENSWRAP interrupt, instead of
2680 * polling for DFIFOFULL
2682 the_time=jiffies + 100*HZ;
2683 while(TESTLO(DMASTAT, DFIFOFULL|INTSTAT) && time_before(jiffies,the_time))
2686 if(TESTLO(DMASTAT, DFIFOFULL|INTSTAT)) {
2687 printk(ERR_LEAD "datai timeout", CMDINFO(CURRENT_SC));
2692 if(TESTHI(DMASTAT, DFIFOFULL)) {
2695 the_time=jiffies + 100*HZ;
2696 while(TESTLO(SSTAT2, SEMPTY) && time_before(jiffies,the_time))
2699 if(TESTLO(SSTAT2, SEMPTY)) {
2700 printk(ERR_LEAD "datai sempty timeout", CMDINFO(CURRENT_SC));
2705 fifodata = GETPORT(FIFOSTAT);
2708 if(CURRENT_SC->SCp.this_residual>0) {
2709 while(fifodata>0 && CURRENT_SC->SCp.this_residual>0) {
2710 data_count = fifodata>CURRENT_SC->SCp.this_residual ?
2711 CURRENT_SC->SCp.this_residual :
2713 fifodata -= data_count;
2715 if(data_count & 1) {
2716 DPRINTK(debug_datai, DEBUG_LEAD "8bit\n", CMDINFO(CURRENT_SC));
2717 SETPORT(DMACNTRL0, ENDMA|_8BIT);
2718 *CURRENT_SC->SCp.ptr++ = GETPORT(DATAPORT);
2719 CURRENT_SC->SCp.this_residual--;
2721 SETPORT(DMACNTRL0, ENDMA);
2724 if(data_count > 1) {
2725 DPRINTK(debug_datai, DEBUG_LEAD "16bit(%d)\n", CMDINFO(CURRENT_SC), data_count);
2727 insw(DATAPORT, CURRENT_SC->SCp.ptr, data_count);
2728 CURRENT_SC->SCp.ptr += 2 * data_count;
2729 CURRENT_SC->SCp.this_residual -= 2 * data_count;
2730 DATA_LEN += 2 * data_count;
2733 if(CURRENT_SC->SCp.this_residual==0 && CURRENT_SC->SCp.buffers_residual>0) {
2734 /* advance to next buffer */
2735 CURRENT_SC->SCp.buffers_residual--;
2736 CURRENT_SC->SCp.buffer++;
2737 CURRENT_SC->SCp.ptr = SG_ADDRESS(CURRENT_SC->SCp.buffer);
2738 CURRENT_SC->SCp.this_residual = CURRENT_SC->SCp.buffer->length;
2741 } else if(fifodata>0) {
2742 printk(ERR_LEAD "no buffers left for %d(%d) bytes (data overrun!?)\n", CMDINFO(CURRENT_SC), fifodata, GETPORT(FIFOSTAT));
2743 SETPORT(DMACNTRL0, ENDMA|_8BIT);
2746 data=GETPORT(DATAPORT);
2747 DPRINTK(debug_datai, DEBUG_LEAD "data=%02x\n", CMDINFO(CURRENT_SC), data);
2751 SETPORT(DMACNTRL0, ENDMA|_8BIT);
2755 if(TESTLO(DMASTAT, INTSTAT) ||
2756 TESTLO(DMASTAT, DFIFOEMP) ||
2757 TESTLO(SSTAT2, SEMPTY) ||
2758 GETPORT(FIFOSTAT)>0) {
2760 * something went wrong, if there's something left in the fifos
2761 * or the phase didn't change
2763 printk(ERR_LEAD "fifos should be empty and phase should have changed\n", CMDINFO(CURRENT_SC));
2767 if(DATA_LEN!=GETSTCNT()) {
2769 "manual transfer count differs from automatic (count=%d;stcnt=%d;diff=%d;fifostat=%d)",
2770 CMDINFO(CURRENT_SC), DATA_LEN, GETSTCNT(), GETSTCNT()-DATA_LEN, GETPORT(FIFOSTAT));
2776 static void datai_end(struct Scsi_Host *shpnt)
2778 CURRENT_SC->resid -= GETSTCNT();
2780 DPRINTK(debug_datai,
2781 DEBUG_LEAD "datai_end: request_bufflen=%d resid=%d stcnt=%d\n",
2782 CMDINFO(CURRENT_SC), CURRENT_SC->request_bufflen, CURRENT_SC->resid, GETSTCNT());
2784 SETPORT(SXFRCTL0, CH1|CLRSTCNT);
2785 SETPORT(DMACNTRL0, 0);
2792 static void datao_init(struct Scsi_Host *shpnt)
2794 SETPORT(DMACNTRL0, WRITE_READ | RSTFIFO);
2795 SETPORT(DMACNTRL0, WRITE_READ | ENDMA);
2797 SETPORT(SXFRCTL0, CH1|CLRSTCNT);
2798 SETPORT(SXFRCTL0, CH1|SCSIEN|DMAEN);
2800 SETPORT(SIMODE0, 0);
2801 SETPORT(SIMODE1, ENSCSIPERR | ENSCSIRST | ENPHASEMIS | ENBUSFREE );
2803 DATA_LEN = CURRENT_SC->resid;
2805 DPRINTK(debug_datao,
2806 DEBUG_LEAD "datao_init: request_bufflen=%d; resid=%d\n",
2807 CMDINFO(CURRENT_SC), CURRENT_SC->request_bufflen, CURRENT_SC->resid);
2810 static void datao_run(struct Scsi_Host *shpnt)
2812 unsigned long the_time;
2815 /* until phase changes or all data sent */
2816 while(TESTLO(DMASTAT, INTSTAT) && CURRENT_SC->SCp.this_residual>0) {
2818 if(data_count > CURRENT_SC->SCp.this_residual)
2819 data_count=CURRENT_SC->SCp.this_residual;
2821 if(TESTLO(DMASTAT, DFIFOEMP)) {
2822 printk(ERR_LEAD "datao fifo not empty (%d)", CMDINFO(CURRENT_SC), GETPORT(FIFOSTAT));
2827 if(data_count & 1) {
2828 SETPORT(DMACNTRL0,WRITE_READ|ENDMA|_8BIT);
2829 SETPORT(DATAPORT, *CURRENT_SC->SCp.ptr++);
2830 CURRENT_SC->SCp.this_residual--;
2831 CURRENT_SC->resid--;
2832 SETPORT(DMACNTRL0,WRITE_READ|ENDMA);
2835 if(data_count > 1) {
2837 outsw(DATAPORT, CURRENT_SC->SCp.ptr, data_count);
2838 CURRENT_SC->SCp.ptr += 2 * data_count;
2839 CURRENT_SC->SCp.this_residual -= 2 * data_count;
2840 CURRENT_SC->resid -= 2 * data_count;
2843 if(CURRENT_SC->SCp.this_residual==0 && CURRENT_SC->SCp.buffers_residual>0) {
2844 /* advance to next buffer */
2845 CURRENT_SC->SCp.buffers_residual--;
2846 CURRENT_SC->SCp.buffer++;
2847 CURRENT_SC->SCp.ptr = SG_ADDRESS(CURRENT_SC->SCp.buffer);
2848 CURRENT_SC->SCp.this_residual = CURRENT_SC->SCp.buffer->length;
2851 the_time=jiffies + 100*HZ;
2852 while(TESTLO(DMASTAT, DFIFOEMP|INTSTAT) && time_before(jiffies,the_time))
2855 if(TESTLO(DMASTAT, DFIFOEMP|INTSTAT)) {
2856 printk(ERR_LEAD "dataout timeout", CMDINFO(CURRENT_SC));
2863 static void datao_end(struct Scsi_Host *shpnt)
2865 if(TESTLO(DMASTAT, DFIFOEMP)) {
2866 int data_count = (DATA_LEN - CURRENT_SC->resid) - GETSTCNT();
2868 DPRINTK(debug_datao, DEBUG_LEAD "datao: %d bytes to resend (%d written, %d transferred)\n",
2869 CMDINFO(CURRENT_SC),
2871 DATA_LEN-CURRENT_SC->resid,
2874 CURRENT_SC->resid += data_count;
2876 if(CURRENT_SC->use_sg) {
2877 data_count -= CURRENT_SC->SCp.ptr - SG_ADDRESS(CURRENT_SC->SCp.buffer);
2878 while(data_count>0) {
2879 CURRENT_SC->SCp.buffer--;
2880 CURRENT_SC->SCp.buffers_residual++;
2881 data_count -= CURRENT_SC->SCp.buffer->length;
2883 CURRENT_SC->SCp.ptr = SG_ADDRESS(CURRENT_SC->SCp.buffer) - data_count;
2884 CURRENT_SC->SCp.this_residual = CURRENT_SC->SCp.buffer->length + data_count;
2886 CURRENT_SC->SCp.ptr -= data_count;
2887 CURRENT_SC->SCp.this_residual += data_count;
2891 DPRINTK(debug_datao, DEBUG_LEAD "datao_end: request_bufflen=%d; resid=%d; stcnt=%d\n",
2892 CMDINFO(CURRENT_SC),
2893 CURRENT_SC->request_bufflen,
2897 SETPORT(SXFRCTL0, CH1|CLRCH1|CLRSTCNT);
2898 SETPORT(SXFRCTL0, CH1);
2900 SETPORT(DMACNTRL0, 0);
2904 * figure out what state we're in
2907 static int update_state(struct Scsi_Host *shpnt)
2910 unsigned int stat0 = GETPORT(SSTAT0);
2911 unsigned int stat1 = GETPORT(SSTAT1);
2916 if(stat1 & SCSIRSTI) {
2919 SETPORT(SSTAT1,SCSIRSTI);
2920 } else if(stat0 & SELDI && PREVSTATE==busfree) {
2922 } else if(stat0 & SELDO && CURRENT_SC && (CURRENT_SC->SCp.phase & selecting)) {
2924 } else if(stat1 & SELTO) {
2926 } else if(stat1 & BUSFREE) {
2928 SETPORT(SSTAT1,BUSFREE);
2929 } else if(stat1 & SCSIPERR) {
2931 SETPORT(SSTAT1,SCSIPERR);
2932 } else if(stat1 & REQINIT) {
2933 switch(GETPORT(SCSISIG) & P_MASK) {
2934 case P_MSGI: STATE=msgi; break;
2935 case P_MSGO: STATE=msgo; break;
2936 case P_DATAO: STATE=datao; break;
2937 case P_DATAI: STATE=datai; break;
2938 case P_STATUS: STATE=status; break;
2939 case P_CMD: STATE=cmd; break;
2944 if((stat0 & SELDI) && STATE!=seldi && !dataphase) {
2945 printk(INFO_LEAD "reselection missed?", CMDINFO(CURRENT_SC));
2949 if(STATE!=PREVSTATE) {
2950 LASTSTATE=PREVSTATE;
2957 * handle parity error
2959 * FIXME: in which phase?
2962 static void parerr_run(struct Scsi_Host *shpnt)
2964 printk(ERR_LEAD "parity error\n", CMDINFO(CURRENT_SC));
2965 done(shpnt, DID_PARITY << 16);
2972 static void rsti_run(struct Scsi_Host *shpnt)
2976 printk(KERN_NOTICE "aha152x%d: scsi reset in\n", HOSTNO);
2978 ptr=DISCONNECTED_SC;
2980 Scsi_Cmnd *next = SCNEXT(ptr);
2982 if (!ptr->device->soft_reset) {
2983 remove_SC(&DISCONNECTED_SC, ptr);
2985 ptr->result = DID_RESET << 16;
2986 ptr->scsi_done(ptr);
2988 kfree(ptr->host_scribble);
2989 ptr->host_scribble=0;
2995 if(CURRENT_SC && !CURRENT_SC->device->soft_reset)
2996 done(shpnt, DID_RESET << 16 );
3001 * bottom-half handler
3004 static void is_complete(struct Scsi_Host *shpnt)
3007 unsigned long flags;
3011 if(HOSTDATA(shpnt)->in_intr!=0) {
3013 /* aha152x_error never returns.. */
3014 aha152x_error(shpnt, "bottom-half already running!?");
3016 HOSTDATA(shpnt)->in_intr++;
3020 * loop while there are interrupt conditions pending
3024 unsigned long start = jiffies;
3025 dataphase=update_state(shpnt);
3027 DPRINTK(debug_phases, LEAD "start %s %s(%s)\n", CMDINFO(CURRENT_SC), states[STATE].name, states[PREVSTATE].name, states[LASTSTATE].name);
3030 * end previous state
3033 if(PREVSTATE!=STATE && states[PREVSTATE].end)
3034 states[PREVSTATE].end(shpnt);
3037 * disable SPIO mode if previous phase used it
3038 * and this one doesn't
3041 if(states[PREVSTATE].spio && !states[STATE].spio) {
3042 SETPORT(SXFRCTL0, CH1);
3043 SETPORT(DMACNTRL0, 0);
3045 CURRENT_SC->SCp.phase &= ~spiordy;
3049 * accept current dataphase phase
3053 SETPORT(SSTAT0, REQINIT);
3054 SETPORT(SCSISIG, GETPORT(SCSISIG) & P_MASK);
3055 SETPORT(SSTAT1, PHASECHG);
3059 * enable SPIO mode if previous didn't use it
3063 if(!states[PREVSTATE].spio && states[STATE].spio) {
3064 SETPORT(DMACNTRL0, 0);
3065 SETPORT(SXFRCTL0, CH1|SPIOEN);
3067 CURRENT_SC->SCp.phase |= spiordy;
3071 * initialize for new state
3074 if(PREVSTATE!=STATE && states[STATE].init)
3075 states[STATE].init(shpnt);
3078 * handle current state
3081 if(states[STATE].run)
3082 states[STATE].run(shpnt);
3084 printk(ERR_LEAD "unexpected state (%x)\n", CMDINFO(CURRENT_SC), STATE);
3087 * setup controller to interrupt on
3088 * the next expected condition and
3089 * loop if it's already there
3093 pending=setup_expected_interrupts(shpnt);
3094 #if defined(AHA152X_STAT)
3095 HOSTDATA(shpnt)->count[STATE]++;
3096 if(PREVSTATE!=STATE)
3097 HOSTDATA(shpnt)->count_trans[STATE]++;
3098 HOSTDATA(shpnt)->time[STATE] += jiffies-start;
3102 DPRINTK(debug_phases, LEAD "end %s %s(%s)\n", CMDINFO(CURRENT_SC), states[STATE].name, states[PREVSTATE].name, states[LASTSTATE].name);
3106 * enable interrupts and leave bottom-half
3110 HOSTDATA(shpnt)->in_intr--;
3111 SETBITS(DMACNTRL0, INTEN);
3117 * Dump the current driver status and panic
3119 static void aha152x_error(struct Scsi_Host *shpnt, char *msg)
3121 printk(KERN_EMERG "\naha152x%d: %s\n", HOSTNO, msg);
3123 panic("aha152x panic\n");
3127 * Display registers of AIC-6260
3129 static void disp_ports(struct Scsi_Host *shpnt)
3131 #if defined(AHA152X_DEBUG)
3134 printk("\n%s: %s(%s) ",
3135 CURRENT_SC ? "busy" : "waiting",
3137 states[PREVSTATE].name);
3139 s = GETPORT(SCSISEQ);
3140 printk("SCSISEQ( ");
3142 printk("TARGET MODE ");
3150 printk("AUTOATNO ");
3152 printk("AUTOATNI ");
3154 printk("AUTOATNP ");
3156 printk("SCSIRSTO ");
3159 printk(" SCSISIG(");
3160 s = GETPORT(SCSISIG);
3161 switch (s & P_MASK) {
3175 printk("MESSAGE OUT");
3178 printk("MESSAGE IN");
3181 printk("*illegal*");
3187 printk("INTSTAT (%s); ", TESTHI(DMASTAT, INTSTAT) ? "hi" : "lo");
3190 s = GETPORT(SSTAT0);
3208 s = GETPORT(SSTAT1);
3214 printk("SCSIRSTI ");
3216 printk("PHASEMIS ");
3220 printk("SCSIPERR ");
3222 printk("PHASECHG ");
3230 s = GETPORT(SSTAT0) & GETPORT(SIMODE0);
3249 s = GETPORT(SSTAT1) & GETPORT(SIMODE1);
3256 printk("SCSIRSTI ");
3258 printk("PHASEMIS ");
3262 printk("SCSIPERR ");
3264 printk("PHASECHG ");
3269 printk("SXFRCTL0( ");
3271 s = GETPORT(SXFRCTL0);
3279 printk("CLRSTCNT ");
3288 s = GETPORT(SCSISIG);
3301 printk("SELID (%02x), ", GETPORT(SELID));
3303 printk("STCNT (%d), ", GETSTCNT());
3307 s = GETPORT(SSTAT2);
3314 printk("); SFCNT (%d); ", s & (SFULL | SFCNT));
3316 s = GETPORT(SSTAT3);
3317 printk("SCSICNT (%d), OFFCNT(%d), ", (s & 0xf0) >> 4, s & 0x0f);
3320 s = GETPORT(SSTAT4);
3329 printk("DMACNTRL0( ");
3330 s = GETPORT(DMACNTRL0);
3331 printk("%s ", s & _8BIT ? "8BIT" : "16BIT");
3332 printk("%s ", s & DMA ? "DMA" : "PIO");
3333 printk("%s ", s & WRITE_READ ? "WRITE" : "READ");
3344 printk("DMASTAT( ");
3345 s = GETPORT(DMASTAT);
3351 printk("DFIFOFULL ");
3353 printk("DFIFOEMP ");
3359 * display enabled interrupts
3361 static void disp_enintr(struct Scsi_Host *shpnt)
3365 printk(KERN_DEBUG "enabled interrupts ( ");
3367 s = GETPORT(SIMODE0);
3373 printk("ENSELINGO ");
3379 printk("ENSPIORDY ");
3381 printk("ENDMADONE ");
3383 s = GETPORT(SIMODE1);
3385 printk("ENSELTIMO ");
3387 printk("ENATNTARG ");
3389 printk("ENPHASEMIS ");
3391 printk("ENBUSFREE ");
3393 printk("ENSCSIPERR ");
3395 printk("ENPHASECHG ");
3397 printk("ENREQINIT ");
3402 * Show the command data of a command
3404 static void show_command(Scsi_Cmnd *ptr)
3406 printk(KERN_DEBUG "0x%08x: target=%d; lun=%d; cmnd=(",
3407 (unsigned int) ptr, ptr->target, ptr->lun);
3409 print_command(ptr->cmnd);
3411 printk(KERN_DEBUG "); request_bufflen=%d; resid=%d; phase |",
3412 ptr->request_bufflen, ptr->resid);
3414 if (ptr->SCp.phase & not_issued)
3415 printk("not issued|");
3416 if (ptr->SCp.phase & selecting)
3417 printk("selecting|");
3418 if (ptr->SCp.phase & identified)
3419 printk("identified|");
3420 if (ptr->SCp.phase & disconnected)
3421 printk("disconnected|");
3422 if (ptr->SCp.phase & completed)
3423 printk("completed|");
3424 if (ptr->SCp.phase & spiordy)
3426 if (ptr->SCp.phase & syncneg)
3428 if (ptr->SCp.phase & aborted)
3430 if (ptr->SCp.phase & resetted)
3431 printk("resetted|");
3432 printk("; next=0x%p\n", SCNEXT(ptr));
3436 * Dump the queued data
3438 static void show_queues(struct Scsi_Host *shpnt)
3441 unsigned long flags;
3444 printk(KERN_DEBUG "\nqueue status:\nissue_SC:\n");
3445 for (ptr = ISSUE_SC; ptr; ptr = SCNEXT(ptr))
3449 printk(KERN_DEBUG "current_SC:\n");
3451 show_command(CURRENT_SC);
3453 printk(KERN_DEBUG "none\n");
3455 printk(KERN_DEBUG "disconnected_SC:\n");
3456 for (ptr = DISCONNECTED_SC; ptr; ptr = SCNEXT(ptr))
3464 #define SPRINTF(args...) pos += sprintf(pos, ## args)
3466 static int get_command(char *pos, Scsi_Cmnd * ptr)
3471 SPRINTF("0x%08x: target=%d; lun=%d; cmnd=( ",
3472 (unsigned int) ptr, ptr->target, ptr->lun);
3474 for (i = 0; i < COMMAND_SIZE(ptr->cmnd[0]); i++)
3475 SPRINTF("0x%02x ", ptr->cmnd[i]);
3477 SPRINTF("); resid=%d; residual=%d; buffers=%d; phase |",
3478 ptr->resid, ptr->SCp.this_residual, ptr->SCp.buffers_residual);
3480 if (ptr->SCp.phase & not_issued)
3481 SPRINTF("not issued|");
3482 if (ptr->SCp.phase & selecting)
3483 SPRINTF("selecting|");
3484 if (ptr->SCp.phase & disconnected)
3485 SPRINTF("disconnected|");
3486 if (ptr->SCp.phase & aborted)
3487 SPRINTF("aborted|");
3488 if (ptr->SCp.phase & identified)
3489 SPRINTF("identified|");
3490 if (ptr->SCp.phase & completed)
3491 SPRINTF("completed|");
3492 if (ptr->SCp.phase & spiordy)
3493 SPRINTF("spiordy|");
3494 if (ptr->SCp.phase & syncneg)
3495 SPRINTF("syncneg|");
3496 SPRINTF("; next=0x%p\n", SCNEXT(ptr));
3498 return (pos - start);
3501 static int get_ports(struct Scsi_Host *shpnt, char *pos)
3506 SPRINTF("\n%s: %s(%s) ", CURRENT_SC ? "on bus" : "waiting", states[STATE].name, states[PREVSTATE].name);
3508 s = GETPORT(SCSISEQ);
3509 SPRINTF("SCSISEQ( ");
3511 SPRINTF("TARGET MODE ");
3519 SPRINTF("AUTOATNO ");
3521 SPRINTF("AUTOATNI ");
3523 SPRINTF("AUTOATNP ");
3525 SPRINTF("SCSIRSTO ");
3528 SPRINTF(" SCSISIG(");
3529 s = GETPORT(SCSISIG);
3530 switch (s & P_MASK) {
3532 SPRINTF("DATA OUT");
3544 SPRINTF("MESSAGE OUT");
3547 SPRINTF("MESSAGE IN");
3550 SPRINTF("*illegal*");
3556 SPRINTF("INTSTAT (%s); ", TESTHI(DMASTAT, INTSTAT) ? "hi" : "lo");
3559 s = GETPORT(SSTAT0);
3567 SPRINTF("SELINGO ");
3573 SPRINTF("SPIORDY ");
3575 SPRINTF("DMADONE ");
3577 s = GETPORT(SSTAT1);
3581 SPRINTF("ATNTARG ");
3583 SPRINTF("SCSIRSTI ");
3585 SPRINTF("PHASEMIS ");
3587 SPRINTF("BUSFREE ");
3589 SPRINTF("SCSIPERR ");
3591 SPRINTF("PHASECHG ");
3593 SPRINTF("REQINIT ");
3599 s = GETPORT(SSTAT0) & GETPORT(SIMODE0);
3608 SPRINTF("SELINGO ");
3614 SPRINTF("SPIORDY ");
3616 SPRINTF("DMADONE ");
3618 s = GETPORT(SSTAT1) & GETPORT(SIMODE1);
3623 SPRINTF("ATNTARG ");
3625 SPRINTF("SCSIRSTI ");
3627 SPRINTF("PHASEMIS ");
3629 SPRINTF("BUSFREE ");
3631 SPRINTF("SCSIPERR ");
3633 SPRINTF("PHASECHG ");
3635 SPRINTF("REQINIT ");
3638 SPRINTF("SXFRCTL0( ");
3640 s = GETPORT(SXFRCTL0);
3648 SPRINTF("CLRSTCNT ");
3655 SPRINTF("SIGNAL( ");
3657 s = GETPORT(SCSISIG);
3670 SPRINTF("SELID(%02x), ", GETPORT(SELID));
3672 SPRINTF("STCNT(%d), ", GETSTCNT());
3674 SPRINTF("SSTAT2( ");
3676 s = GETPORT(SSTAT2);
3678 SPRINTF("SOFFSET ");
3683 SPRINTF("); SFCNT (%d); ", s & (SFULL | SFCNT));
3685 s = GETPORT(SSTAT3);
3686 SPRINTF("SCSICNT (%d), OFFCNT(%d), ", (s & 0xf0) >> 4, s & 0x0f);
3688 SPRINTF("SSTAT4( ");
3689 s = GETPORT(SSTAT4);
3691 SPRINTF("SYNCERR ");
3698 SPRINTF("DMACNTRL0( ");
3699 s = GETPORT(DMACNTRL0);
3700 SPRINTF("%s ", s & _8BIT ? "8BIT" : "16BIT");
3701 SPRINTF("%s ", s & DMA ? "DMA" : "PIO");
3702 SPRINTF("%s ", s & WRITE_READ ? "WRITE" : "READ");
3708 SPRINTF("RSTFIFO ");
3713 SPRINTF("DMASTAT( ");
3714 s = GETPORT(DMASTAT);
3718 SPRINTF("WORDRDY ");
3720 SPRINTF("DFIFOFULL ");
3722 SPRINTF("DFIFOEMP ");
3725 SPRINTF("enabled interrupts( ");
3727 s = GETPORT(SIMODE0);
3729 SPRINTF("ENSELDO ");
3731 SPRINTF("ENSELDI ");
3733 SPRINTF("ENSELINGO ");
3735 SPRINTF("ENSWRAP ");
3737 SPRINTF("ENSDONE ");
3739 SPRINTF("ENSPIORDY ");
3741 SPRINTF("ENDMADONE ");
3743 s = GETPORT(SIMODE1);
3745 SPRINTF("ENSELTIMO ");
3747 SPRINTF("ENATNTARG ");
3749 SPRINTF("ENPHASEMIS ");
3751 SPRINTF("ENBUSFREE ");
3753 SPRINTF("ENSCSIPERR ");
3755 SPRINTF("ENPHASECHG ");
3757 SPRINTF("ENREQINIT ");
3760 return (pos - start);
3763 int aha152x_set_info(char *buffer, int length, struct Scsi_Host *shpnt)
3765 if(!shpnt || !buffer || length<8 || strncmp("aha152x ", buffer, 8)!=0)
3768 #if defined(AHA152X_DEBUG)
3769 if(length>14 && strncmp("debug ", buffer+8, 6)==0) {
3770 int debug = HOSTDATA(shpnt)->debug;
3772 HOSTDATA(shpnt)->debug = simple_strtoul(buffer+14, NULL, 0);
3774 printk(KERN_INFO "aha152x%d: debugging options set to 0x%04x (were 0x%04x)\n", HOSTNO, HOSTDATA(shpnt)->debug, debug);
3777 #if defined(AHA152X_STAT)
3778 if(length>13 && strncmp("reset", buffer+8, 5)==0) {
3781 HOSTDATA(shpnt)->total_commands=0;
3782 HOSTDATA(shpnt)->disconnections=0;
3783 HOSTDATA(shpnt)->busfree_without_any_action=0;
3784 HOSTDATA(shpnt)->busfree_without_old_command=0;
3785 HOSTDATA(shpnt)->busfree_without_new_command=0;
3786 HOSTDATA(shpnt)->busfree_without_done_command=0;
3787 HOSTDATA(shpnt)->busfree_with_check_condition=0;
3788 for (i = idle; i<maxstate; i++) {
3789 HOSTDATA(shpnt)->count[i]=0;
3790 HOSTDATA(shpnt)->count_trans[i]=0;
3791 HOSTDATA(shpnt)->time[i]=0;
3794 printk(KERN_INFO "aha152x%d: stats reseted.\n", HOSTNO);
3807 #define SPRINTF(args...) \
3808 do { if(pos < buffer + length) pos += sprintf(pos, ## args); } while(0)
3810 int aha152x_proc_info(char *buffer, char **start,
3811 off_t offset, int length, int hostno, int inout)
3815 struct Scsi_Host *shpnt;
3817 unsigned long flags;
3820 for (i = 0, shpnt = (struct Scsi_Host *) NULL; i<ARRAY_SIZE(aha152x_host); i++)
3821 if (aha152x_host[i] && aha152x_host[i]->host_no == hostno)
3822 shpnt = aha152x_host[i];
3827 DPRINTK(debug_procinfo,
3828 KERN_DEBUG "aha152x_proc_info: buffer=%p offset=%ld length=%d hostno=%d inout=%d\n",
3829 buffer, offset, length, hostno, inout);
3833 return aha152x_set_info(buffer, length, shpnt);
3835 SPRINTF(AHA152X_REVID "\n");
3837 SPRINTF("ioports 0x%04lx to 0x%04lx\n",
3838 shpnt->io_port, shpnt->io_port + shpnt->n_io_port - 1);
3839 SPRINTF("interrupt 0x%02x\n", shpnt->irq);
3840 SPRINTF("disconnection/reconnection %s\n",
3841 RECONNECT ? "enabled" : "disabled");
3842 SPRINTF("parity checking %s\n",
3843 PARITY ? "enabled" : "disabled");
3844 SPRINTF("synchronous transfers %s\n",
3845 SYNCHRONOUS ? "enabled" : "disabled");
3846 SPRINTF("%d commands currently queued\n", HOSTDATA(shpnt)->commands);
3849 SPRINTF("synchronously operating targets (tick=50 ns):\n");
3850 for (i = 0; i < 8; i++)
3851 if (HOSTDATA(shpnt)->syncrate[i] & 0x7f)
3852 SPRINTF("target %d: period %dT/%dns; req/ack offset %d\n",
3854 (((HOSTDATA(shpnt)->syncrate[i] & 0x70) >> 4) + 2),
3855 (((HOSTDATA(shpnt)->syncrate[i] & 0x70) >> 4) + 2) * 50,
3856 HOSTDATA(shpnt)->syncrate[i] & 0x0f);
3858 #if defined(AHA152X_DEBUG)
3859 #define PDEBUG(flags,txt) \
3860 if(HOSTDATA(shpnt)->debug & flags) SPRINTF("(%s) ", txt);
3862 SPRINTF("enabled debugging options: ");
3864 PDEBUG(debug_procinfo, "procinfo");
3865 PDEBUG(debug_queue, "queue");
3866 PDEBUG(debug_intr, "interrupt");
3867 PDEBUG(debug_selection, "selection");
3868 PDEBUG(debug_msgo, "message out");
3869 PDEBUG(debug_msgi, "message in");
3870 PDEBUG(debug_status, "status");
3871 PDEBUG(debug_cmd, "command");
3872 PDEBUG(debug_datai, "data in");
3873 PDEBUG(debug_datao, "data out");
3874 PDEBUG(debug_eh, "eh");
3875 PDEBUG(debug_locks, "locks");
3876 PDEBUG(debug_phases, "phases");
3881 SPRINTF("\nqueue status:\n");
3884 SPRINTF("not yet issued commands:\n");
3885 for (ptr = ISSUE_SC; ptr; ptr = SCNEXT(ptr))
3886 pos += get_command(pos, ptr);
3888 SPRINTF("no not yet issued commands\n");
3892 SPRINTF("current command:\n");
3893 pos += get_command(pos, CURRENT_SC);
3895 SPRINTF("no current command\n");
3897 if (DISCONNECTED_SC) {
3898 SPRINTF("disconnected commands:\n");
3899 for (ptr = DISCONNECTED_SC; ptr; ptr = SCNEXT(ptr))
3900 pos += get_command(pos, ptr);
3902 SPRINTF("no disconnected commands\n");
3904 pos += get_ports(shpnt, pos);
3906 #if defined(AHA152X_STAT)
3907 SPRINTF("statistics:\n"
3908 "total commands: %d\n"
3909 "disconnections: %d\n"
3910 "busfree with check condition: %d\n"
3911 "busfree without old command: %d\n"
3912 "busfree without new command: %d\n"
3913 "busfree without done command: %d\n"
3914 "busfree without any action: %d\n"
3919 HOSTDATA(shpnt)->total_commands,
3920 HOSTDATA(shpnt)->disconnections,
3921 HOSTDATA(shpnt)->busfree_with_check_condition,
3922 HOSTDATA(shpnt)->busfree_without_old_command,
3923 HOSTDATA(shpnt)->busfree_without_new_command,
3924 HOSTDATA(shpnt)->busfree_without_done_command,
3925 HOSTDATA(shpnt)->busfree_without_any_action);
3926 for(i=0; i<maxstate; i++) {
3927 SPRINTF("%-10s %-12d %-12d %-12ld\n",
3929 HOSTDATA(shpnt)->count_trans[i],
3930 HOSTDATA(shpnt)->count[i],
3931 HOSTDATA(shpnt)->time[i]);
3935 DPRINTK(debug_procinfo, KERN_DEBUG "aha152x_proc_info: pos=%p\n", pos);
3937 thislength = pos - (buffer + offset);
3938 DPRINTK(debug_procinfo, KERN_DEBUG "aha152x_proc_info: length=%d thislength=%d\n", length, thislength);
3941 DPRINTK(debug_procinfo, KERN_DEBUG "aha152x_proc_info: output too short\n");
3946 thislength = thislength<length ? thislength : length;
3948 DPRINTK(debug_procinfo, KERN_DEBUG "aha152x_proc_info: return %d\n", thislength);
3950 *start = buffer + offset;
3951 return thislength < length ? thislength : length;
3955 /* Eventually this will go into an include file, but this will be later */
3956 static Scsi_Host_Template driver_template = AHA152X;
3958 #include "scsi_module.c"