1 /* aha152x.c -- Adaptec AHA-152x driver
2 * Author: Jürgen E. Fischer, fischer@norbit.de
3 * Copyright 1993-1999 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.3 2000/11/04 16:40:26 fischer Exp $
19 * Revision 2.3 2000/11/04 16:40:26 fischer
20 * - handle data overruns
21 * - extend timeout for data phases
23 * Revision 2.2 2000/08/08 19:54:53 fischer
26 * Revision 2.1 2000/05/17 16:23:17 fischer
28 * - fix for data out w/o scatter gather
30 * Revision 2.0 1999/12/25 15:07:32 fischer
31 * - interrupt routine completly reworked
32 * - basic support for new eh code
34 * Revision 1.21 1999/11/10 23:46:36 fischer
35 * - default to synchronous operation
36 * - synchronous negotiation fixed
37 * - added timeout to loops
38 * - debugging output can be controlled through procfs
40 * Revision 1.20 1999/11/07 18:37:31 fischer
41 * - synchronous operation works
42 * - resid support for sg driver
44 * Revision 1.19 1999/11/02 22:39:59 fischer
45 * - moved leading comments to README.aha152x
46 * - new additional module parameters
48 * - support for the Tripace TC1550 controller
49 * - interrupt handling changed
51 * Revision 1.18 1996/09/07 20:10:40 fischer
52 * - fixed can_queue handling (multiple outstanding commands working again)
54 * Revision 1.17 1996/08/17 16:05:14 fischer
55 * - biosparam improved
56 * - interrupt verification
57 * - updated documentation
60 * Revision 1.16 1996/06/09 00:04:56 root
61 * - added configuration symbols for insmod (aha152x/aha152x1)
63 * Revision 1.15 1996/04/30 14:52:06 fischer
65 * - support for extended translation for >1GB disks
67 * Revision 1.14 1996/01/17 15:11:20 fischer
68 * - fixed lockup in MESSAGE IN phase after reconnection
70 * Revision 1.13 1996/01/09 02:15:53 fischer
72 * - moved request_irq behind controller initialization
73 * (to avoid spurious interrupts)
75 * Revision 1.12 1995/12/16 12:26:07 fischer
77 * - configurable RESET delay added
79 * Revision 1.11 1995/12/06 21:18:35 fischer
80 * - some minor updates
82 * Revision 1.10 1995/07/22 19:18:45 fischer
83 * - support for 2 controllers
84 * - started synchronous data transfers (not working yet)
86 * Revision 1.9 1995/03/18 09:20:24 root
87 * - patches for PCMCIA and modules
89 * Revision 1.8 1995/01/21 22:07:19 root
90 * - snarf_region => request_region
91 * - aha152x_intr interface change
93 * Revision 1.7 1995/01/02 23:19:36 root
94 * - updated COMMAND_SIZE to cmd_len
95 * - changed sti() to restore_flags()
96 * - fixed some #ifdef which generated warnings
98 * Revision 1.6 1994/11/24 20:35:27 root
99 * - problem with odd number of bytes in fifo fixed
101 * Revision 1.5 1994/10/30 14:39:56 root
103 * - debugging improved
105 * Revision 1.4 1994/09/12 11:33:01 root
106 * - irqaction to request_irq
109 * Revision 1.3 1994/08/04 13:53:05 root
110 * - updates for mid-level-driver changes
111 * - accept unexpected BUSFREE phase as error condition
112 * - parity check now configurable
114 * Revision 1.2 1994/07/03 12:56:36 root
115 * - cleaned up debugging code
116 * - more tweaking on reset delays
117 * - updated abort/reset code (pretty untested...)
119 * Revision 1.1 1994/05/28 21:18:49 root
120 * - update for mid-level interface change (abort-reset)
121 * - delays after resets adjusted for some slow devices
123 * Revision 1.0 1994/03/25 12:52:00 root
124 * - Fixed "more data than expected" problem
125 * - added new BIOS signatures
127 * Revision 0.102 1994/01/31 20:44:12 root
128 * - minor changes in insw/outsw handling
130 * Revision 0.101 1993/12/13 01:16:27 root
131 * - fixed STATUS phase (non-GOOD stati were dropped sometimes;
132 * fixes problems with CD-ROM sector size detection & media change)
134 * Revision 0.100 1993/12/10 16:58:47 root
135 * - fix for unsuccessful selections in case of non-continuous id assignments
138 * Revision 0.99 1993/10/24 16:19:59 root
139 * - fixed DATA IN (rare read errors gone)
141 * Revision 0.98 1993/10/17 12:54:44 root
142 * - fixed some recent fixes (shame on me)
143 * - moved initialization of scratch area to aha152x_queue
145 * Revision 0.97 1993/10/09 18:53:53 root
146 * - DATA IN fixed. Rarely left data in the fifo.
148 * Revision 0.96 1993/10/03 00:53:59 root
149 * - minor changes on DATA IN
151 * Revision 0.95 1993/09/24 10:36:01 root
152 * - change handling of MSGI after reselection
156 * Revision 0.94 1993/09/18 14:08:22 root
157 * - fixed bug in multiple outstanding command code
158 * - changed detection
159 * - support for kernel command line configuration
161 * - changed message handling
163 * Revision 0.93 1993/09/15 20:41:19 root
164 * - fixed bugs with multiple outstanding commands
166 * Revision 0.92 1993/09/13 02:46:33 root
167 * - multiple outstanding commands work (no problems with IBM drive)
169 * Revision 0.91 1993/09/12 20:51:46 root
170 * added multiple outstanding commands
171 * (some problem with this $%&? IBM device remain)
173 * Revision 0.9 1993/09/12 11:11:22 root
174 * - corrected auto-configuration
175 * - changed the auto-configuration (added some '#define's)
176 * - added support for dis-/reconnection
178 * Revision 0.8 1993/09/06 23:09:39 root
179 * - added support for the drive activity light
182 * Revision 0.7 1993/09/05 14:30:15 root
183 * - improved phase detection
184 * - now using the new snarf_region code of 0.99pl13
186 * Revision 0.6 1993/09/02 11:01:38 root
187 * first public release; added some signatures and biosparam()
189 * Revision 0.5 1993/08/30 10:23:30 root
190 * fixed timing problems with my IBM drive
192 * Revision 0.4 1993/08/29 14:06:52 root
193 * fixed some problems with timeouts due incomplete commands
195 * Revision 0.3 1993/08/28 15:55:03 root
196 * writing data works too. mounted and worked on a dos partition
198 * Revision 0.2 1993/08/27 22:42:07 root
199 * reading data works. Mounted a msdos partition.
201 * Revision 0.1 1993/08/25 13:38:30 root
202 * first "damn thing doesn't work" version
204 * Revision 0.0 1993/08/14 19:54:25 root
205 * empty function bodies; detect() works.
208 **************************************************************************
210 see README.aha152x for configuration details
212 **************************************************************************/
214 #include <linux/module.h>
220 #include <linux/sched.h>
222 #include <linux/blk.h>
226 #include "constants.h"
227 #include <asm/system.h>
228 #include <linux/errno.h>
229 #include <linux/string.h>
230 #include <linux/wait.h>
231 #include <linux/ioport.h>
232 #include <linux/delay.h>
233 #include <linux/proc_fs.h>
234 #include <linux/interrupt.h>
235 #include <linux/init.h>
236 #include <linux/kernel.h>
237 #include <asm/semaphore.h>
238 #include <linux/spinlock.h>
241 #include <linux/stat.h>
243 #include <scsi/scsicam.h>
247 /* For PCMCIA cards, always use AUTOCONF */
248 #if defined(PCMCIA) || defined(MODULE)
249 #if !defined(AUTOCONF)
254 #if !defined(AUTOCONF) && !defined(SETUP0)
255 #error define AUTOCONF or SETUP0
258 #if defined(AHA152X_DEBUG)
259 #define DEBUG_DEFAULT debug_eh
261 #define DPRINTK(when,msgs...) \
262 do { if(HOSTDATA(shpnt)->debug & (when)) printk(msgs); } while(0)
264 #define DO_LOCK(flags) \
266 if(spin_is_locked(&QLOCK)) { \
267 DPRINTK(debug_intr, DEBUG_LEAD "(%s:%d) already locked at %s:%d\n", CMDINFO(CURRENT_SC), __FUNCTION__, __LINE__, QLOCKER, QLOCKERL); \
269 DPRINTK(debug_locks, DEBUG_LEAD "(%s:%d) locking\n", CMDINFO(CURRENT_SC), __FUNCTION__, __LINE__); \
270 spin_lock_irqsave(&QLOCK,flags); \
271 DPRINTK(debug_locks, DEBUG_LEAD "(%s:%d) locked\n", CMDINFO(CURRENT_SC), __FUNCTION__, __LINE__); \
272 QLOCKER=__FUNCTION__; \
276 #define DO_UNLOCK(flags) \
278 DPRINTK(debug_locks, DEBUG_LEAD "(%s:%d) unlocking (locked at %s:%d)\n", CMDINFO(CURRENT_SC), __FUNCTION__, __LINE__, QLOCKER, QLOCKERL); \
279 spin_unlock_irqrestore(&QLOCK,flags); \
280 DPRINTK(debug_locks, DEBUG_LEAD "(%s:%d) unlocked\n", CMDINFO(CURRENT_SC), __FUNCTION__, __LINE__); \
281 QLOCKER="(not locked)"; \
286 #define DPRINTK(when,msgs...)
287 #define DO_LOCK(flags) spin_lock_irqsave(&QLOCK,flags)
288 #define DO_UNLOCK(flags) spin_unlock_irqrestore(&QLOCK,flags)
291 #define LEAD "(scsi%d:%d:%d) "
292 #define WARN_LEAD KERN_WARNING LEAD
293 #define INFO_LEAD KERN_INFO LEAD
294 #define NOTE_LEAD KERN_NOTICE LEAD
295 #define ERR_LEAD KERN_ERR LEAD
296 #define DEBUG_LEAD KERN_DEBUG LEAD
297 #define CMDINFO(cmd) \
298 (cmd) ? ((cmd)->host->host_no) : -1, \
299 (cmd) ? ((cmd)->target & 0x0f) : -1, \
300 (cmd) ? ((cmd)->lun & 0x07) : -1
302 #define DELAY_DEFAULT 100
304 /* possible irq range */
312 #define IRQS IRQ_MAX-IRQ_MIN+1
315 not_issued
= 0x0001, /* command not yet issued */
316 selecting
= 0x0002, /* target is beeing selected */
317 identified
= 0x0004, /* IDENTIFY was sent */
318 disconnected
= 0x0008, /* target disconnected */
319 completed
= 0x0010, /* target sent COMMAND COMPLETE */
320 aborted
= 0x0020, /* ABORT was sent */
321 resetted
= 0x0040, /* BUS DEVICE RESET was sent */
322 spiordy
= 0x0080, /* waiting for SPIORDY to raise */
323 syncneg
= 0x0100, /* synchronous negotiation in progress */
324 aborting
= 0x0200, /* ABORT is pending */
325 resetting
= 0x0400, /* BUS DEVICE RESET is pending */
329 MODULE_AUTHOR("Jürgen Fischer");
330 MODULE_DESCRIPTION(AHA152X_REVID
);
331 MODULE_PARM(io
, "1-2i");
332 MODULE_PARM_DESC(io
,"base io address of controller");
333 static int io
[] = {0, 0};
335 MODULE_PARM(irq
, "1-2i");
336 MODULE_PARM_DESC(irq
,"interrupt for controller");
337 static int irq
[] = {0, 0};
339 MODULE_PARM(scsiid
, "1-2i");
340 MODULE_PARM_DESC(scsiid
,"scsi id of controller");
341 static int scsiid
[] = {7, 7};
343 MODULE_PARM(reconnect
, "1-2i");
344 MODULE_PARM_DESC(reconnect
,"allow targets to disconnect");
345 static int reconnect
[] = {1, 1};
347 MODULE_PARM(parity
, "1-2i");
348 MODULE_PARM_DESC(parity
,"use scsi parity");
349 static int parity
[] = {1, 1};
351 MODULE_PARM(sync
, "1-2i");
352 MODULE_PARM_DESC(sync
,"use synchronous transfers");
353 static int sync
[] = {1, 1};
355 MODULE_PARM(delay
, "1-2i");
356 MODULE_PARM_DESC(delay
,"scsi reset delay");
357 static int delay
[] = {DELAY_DEFAULT
, DELAY_DEFAULT
};
359 MODULE_PARM(exttrans
, "1-2i");
360 MODULE_PARM_DESC(exttrans
,"use extended translation");
361 static int exttrans
[] = {0, 0};
363 #if !defined(AHA152X_DEBUG)
364 MODULE_PARM(aha152x
, "1-8i");
365 MODULE_PARM_DESC(aha152x
, "parameters for first controller");
366 static int aha152x
[] = {0, 11, 7, 1, 1, 0, DELAY_DEFAULT
, 0};
368 MODULE_PARM(aha152x1
, "1-8i");
369 MODULE_PARM_DESC(aha152x1
, "parameters for second controller");
370 static int aha152x1
[] = {0, 11, 7, 1, 1, 0, DELAY_DEFAULT
, 0};
372 MODULE_PARM(debug
, "1-2i");
373 MODULE_PARM_DESC(debug
, "flags for driver debugging");
374 static int debug
[] = {DEBUG_DEFAULT
, DEBUG_DEFAULT
};
376 MODULE_PARM(aha152x
, "1-9i");
377 MODULE_PARM_DESC(aha152x
, "parameters for first controller");
378 static int aha152x
[] = {0, 11, 7, 1, 1, 1, DELAY_DEFAULT
, 0, DEBUG_DEFAULT
};
380 MODULE_PARM(aha152x1
, "1-9i");
381 MODULE_PARM_DESC(aha152x1
, "parameters for second controller");
382 static int aha152x1
[] = {0, 11, 7, 1, 1, 1, DELAY_DEFAULT
, 0, DEBUG_DEFAULT
};
383 #endif /* !defined(AHA152X_DEBUG) */
386 /* set by aha152x_setup according to the command line */
387 static int setup_count
= 0;
388 static int registered_count
= 0;
389 static struct aha152x_setup
{
399 #if defined(AHA152X_DEBUG)
405 static struct Scsi_Host
*aha152x_host
[IRQS
];
408 * internal states of the host
430 * current state information of the host
433 struct aha152x_hostdata
{
435 /* pending commands to issue */
437 Scsi_Cmnd
*current_SC
;
438 /* current command on the bus */
440 Scsi_Cmnd
*disconnected_SC
;
441 /* commands that disconnected */
444 /* command that was completed */
449 #if defined(AHA152X_DEBUG)
450 char *locker
; /* which function has the lock */
451 int lockerl
; /* where did it get it */
453 int debug
; /* current debugging setting */
456 #if defined(AHA152X_STAT)
459 int busfree_without_any_action
;
460 int busfree_without_old_command
;
461 int busfree_without_new_command
;
462 int busfree_without_done_command
;
463 int busfree_with_check_condition
;
465 int count_trans
[maxstate
];
466 unsigned long time
[maxstate
];
469 int commands
; /* current number of commands */
471 int reconnect
; /* disconnection allowed */
472 int parity
; /* parity checking enabled */
473 int synchronous
; /* synchronous transferes enabled */
474 int delay
; /* reset out delay */
475 int ext_trans
; /* extended translation enabled */
477 int swint
; /* software-interrupt was fired during detect() */
478 int service
; /* bh needs to be run */
479 int in_intr
; /* bh is running */
483 last state different from current state */
484 enum aha152x_state state
, prevstate
, laststate
;
487 /* reconnecting target */
489 unsigned char syncrate
[8];
490 /* current synchronous transfer agreements */
492 unsigned char syncneg
[8];
493 /* 0: no negotiation;
494 * 1: negotiation in progress;
495 * 2: negotiation completed
499 /* number of sent bytes of current command */
502 /* number of received message bytes */
503 unsigned char msgi
[256];
504 /* received message bytes */
506 int msgo_i
, msgo_len
;
507 /* number of sent bytes and length of current messages */
508 unsigned char msgo
[256];
509 /* pending messages */
512 /* number of sent/received bytes in dataphase */
514 unsigned long io_port0
;
515 unsigned long io_port1
;
520 * host specific command extension
523 struct aha152x_scdata
{
524 Scsi_Cmnd
*next
; /* next sc in queue */
525 Scsi_Cmnd
*done
; /* done command */
526 struct semaphore
*sem
; /* semaphore to block on */
530 /* access macros for hostdata */
532 #define HOSTDATA(shpnt) ((struct aha152x_hostdata *) &shpnt->hostdata)
534 #define HOSTNO ((shpnt)->host_no)
536 #define CURRENT_SC (HOSTDATA(shpnt)->current_SC)
537 #define DONE_SC (HOSTDATA(shpnt)->done_SC)
538 #define ISSUE_SC (HOSTDATA(shpnt)->issue_SC)
539 #define DISCONNECTED_SC (HOSTDATA(shpnt)->disconnected_SC)
540 #define QLOCK (HOSTDATA(shpnt)->lock)
541 #define QLOCKER (HOSTDATA(shpnt)->locker)
542 #define QLOCKERL (HOSTDATA(shpnt)->lockerl)
544 #define STATE (HOSTDATA(shpnt)->state)
545 #define PREVSTATE (HOSTDATA(shpnt)->prevstate)
546 #define LASTSTATE (HOSTDATA(shpnt)->laststate)
548 #define RECONN_TARGET (HOSTDATA(shpnt)->target)
550 #define CMD_I (HOSTDATA(shpnt)->cmd_i)
552 #define MSGO(i) (HOSTDATA(shpnt)->msgo[i])
553 #define MSGO_I (HOSTDATA(shpnt)->msgo_i)
554 #define MSGOLEN (HOSTDATA(shpnt)->msgo_len)
555 #define ADDMSGO(x) (MSGOLEN<256 ? MSGO(MSGOLEN++)=x : aha152x_error(shpnt,"MSGO overflow"))
557 #define MSGI(i) (HOSTDATA(shpnt)->msgi[i])
558 #define MSGILEN (HOSTDATA(shpnt)->msgi_len)
559 #define ADDMSGI(x) (MSGILEN<256 ? MSGI(MSGILEN++)=x : aha152x_error(shpnt,"MSGI overflow"))
561 #define DATA_LEN (HOSTDATA(shpnt)->data_len)
563 #define SYNCRATE (HOSTDATA(shpnt)->syncrate[CURRENT_SC->target])
564 #define SYNCNEG (HOSTDATA(shpnt)->syncneg[CURRENT_SC->target])
566 #define DELAY (HOSTDATA(shpnt)->delay)
567 #define EXT_TRANS (HOSTDATA(shpnt)->ext_trans)
568 #define TC1550 (HOSTDATA(shpnt)->tc1550)
569 #define RECONNECT (HOSTDATA(shpnt)->reconnect)
570 #define PARITY (HOSTDATA(shpnt)->parity)
571 #define SYNCHRONOUS (HOSTDATA(shpnt)->synchronous)
573 #define HOSTIOPORT0 (HOSTDATA(shpnt)->io_port0)
574 #define HOSTIOPORT1 (HOSTDATA(shpnt)->io_port1)
576 #define SCDATA(SCpnt) ((struct aha152x_scdata *) (SCpnt)->host_scribble)
577 #define SCNEXT(SCpnt) SCDATA(SCpnt)->next
578 #define SCDONE(SCpnt) SCDATA(SCpnt)->done
579 #define SCSEM(SCpnt) SCDATA(SCpnt)->sem
583 static void seldi_run(struct Scsi_Host
*shpnt
);
584 static void seldo_run(struct Scsi_Host
*shpnt
);
585 static void selto_run(struct Scsi_Host
*shpnt
);
586 static void busfree_run(struct Scsi_Host
*shpnt
);
588 static void msgo_init(struct Scsi_Host
*shpnt
);
589 static void msgo_run(struct Scsi_Host
*shpnt
);
590 static void msgo_end(struct Scsi_Host
*shpnt
);
592 static void cmd_init(struct Scsi_Host
*shpnt
);
593 static void cmd_run(struct Scsi_Host
*shpnt
);
594 static void cmd_end(struct Scsi_Host
*shpnt
);
596 static void datai_init(struct Scsi_Host
*shpnt
);
597 static void datai_run(struct Scsi_Host
*shpnt
);
598 static void datai_end(struct Scsi_Host
*shpnt
);
600 static void datao_init(struct Scsi_Host
*shpnt
);
601 static void datao_run(struct Scsi_Host
*shpnt
);
602 static void datao_end(struct Scsi_Host
*shpnt
);
604 static void status_run(struct Scsi_Host
*shpnt
);
606 static void msgi_run(struct Scsi_Host
*shpnt
);
607 static void msgi_end(struct Scsi_Host
*shpnt
);
609 static void parerr_run(struct Scsi_Host
*shpnt
);
610 static void rsti_run(struct Scsi_Host
*shpnt
);
612 static void complete(struct Scsi_Host
*shpnt
);
620 void (*init
)(struct Scsi_Host
*);
621 void (*run
)(struct Scsi_Host
*);
622 void (*end
)(struct Scsi_Host
*);
625 { "idle", 0, 0, 0, 0},
626 { "unknown", 0, 0, 0, 0},
627 { "seldo", 0, seldo_run
, 0, 0},
628 { "seldi", 0, seldi_run
, 0, 0},
629 { "selto", 0, selto_run
, 0, 0},
630 { "busfree", 0, busfree_run
, 0, 0},
631 { "msgo", msgo_init
, msgo_run
, msgo_end
, 1},
632 { "cmd", cmd_init
, cmd_run
, cmd_end
, 1},
633 { "msgi", 0, msgi_run
, msgi_end
, 1},
634 { "status", 0, status_run
, 0, 1},
635 { "datai", datai_init
, datai_run
, datai_end
, 0},
636 { "datao", datao_init
, datao_run
, datao_end
, 0},
637 { "parerr", 0, parerr_run
, 0, 0},
638 { "rsti", 0, rsti_run
, 0, 0},
641 /* setup & interrupt */
642 static void intr(int irq
, void *dev_id
, struct pt_regs
*);
643 static void reset_ports(struct Scsi_Host
*shpnt
);
644 static void aha152x_error(struct Scsi_Host
*shpnt
, char *msg
);
645 static void done(struct Scsi_Host
*shpnt
, int error
);
646 static int checksetup(struct aha152x_setup
*setup
);
649 static void disp_ports(struct Scsi_Host
*shpnt
);
650 static void show_command(Scsi_Cmnd
* ptr
);
651 static void show_queues(struct Scsi_Host
*shpnt
);
652 static void disp_enintr(struct Scsi_Host
*shpnt
);
654 /* possible i/o addresses for the AIC-6260; default first */
655 static unsigned short ports
[] = { 0x340, 0x140 };
656 #define PORT_COUNT (sizeof(ports) / sizeof(unsigned short))
658 #if !defined(SKIP_BIOSTEST)
659 /* possible locations for the Adaptec BIOS; defaults first */
660 static unsigned int addresses
[] =
662 0xdc000, /* default first */
669 0xeb800, /* VTech Platinum SMP */
672 #define ADDRESS_COUNT (sizeof(addresses) / sizeof(unsigned int))
674 /* signatures for various AIC-6[23]60 based controllers.
675 The point in detecting signatures is to avoid useless and maybe
676 harmful probes on ports. I'm not sure that all listed boards pass
677 auto-configuration. For those which fail the BIOS signature is
678 obsolete, because user intervention to supply the configuration is
679 needed anyway. May be an information whether or not the BIOS supports
680 extended translation could be also useful here. */
681 static struct signature
{
682 unsigned char *signature
;
687 { "Adaptec AHA-1520 BIOS", 0x102e, 21 },
689 { "Adaptec AHA-1520B", 0x000b, 17 },
690 /* Adaptec 152x rev B */
691 { "Adaptec AHA-1520B", 0x0026, 17 },
692 /* Iomega Jaz Jet ISA (AIC6370Q) */
693 { "Adaptec ASW-B626 BIOS", 0x1029, 21 },
694 /* on-board controller */
695 { "Adaptec BIOS: ASW-B626", 0x000f, 22 },
696 /* on-board controller */
697 { "Adaptec ASW-B626 S2", 0x2e6c, 19 },
698 /* on-board controller */
699 { "Adaptec BIOS:AIC-6360", 0x000c, 21 },
700 /* on-board controller */
701 { "ScsiPro SP-360 BIOS", 0x2873, 19 },
702 /* ScsiPro-Controller */
703 { "GA-400 LOCAL BUS SCSI BIOS", 0x102e, 26 },
704 /* Gigabyte Local-Bus-SCSI */
705 { "Adaptec BIOS:AVA-282X", 0x000c, 21 },
707 { "Adaptec IBM Dock II SCSI", 0x2edd, 24 },
708 /* IBM Thinkpad Dock II */
709 { "Adaptec BIOS:AHA-1532P", 0x001c, 22 },
710 /* IBM Thinkpad Dock II SCSI */
711 { "DTC3520A Host Adapter BIOS", 0x318a, 26 },
712 /* DTC 3520A ISA SCSI */
715 #define SIGNATURE_COUNT (sizeof(signatures) / sizeof(struct signature))
723 static inline void append_SC(Scsi_Cmnd
**SC
, Scsi_Cmnd
*new_SC
)
727 SCNEXT(new_SC
) = NULL
;
731 for (end
= *SC
; SCNEXT(end
); end
= SCNEXT(end
))
733 SCNEXT(end
) = new_SC
;
737 static inline Scsi_Cmnd
*remove_first_SC(Scsi_Cmnd
** SC
)
749 static inline Scsi_Cmnd
*remove_lun_SC(Scsi_Cmnd
** SC
, int target
, int lun
)
751 Scsi_Cmnd
*ptr
, *prev
;
753 for (ptr
= *SC
, prev
= NULL
;
754 ptr
&& ((ptr
->target
!= target
) || (ptr
->lun
!= lun
));
755 prev
= ptr
, ptr
= SCNEXT(ptr
))
760 SCNEXT(prev
) = SCNEXT(ptr
);
770 static inline Scsi_Cmnd
*remove_SC(Scsi_Cmnd
**SC
, Scsi_Cmnd
*SCp
)
772 Scsi_Cmnd
*ptr
, *prev
;
774 for (ptr
= *SC
, prev
= NULL
;
776 prev
= ptr
, ptr
= SCNEXT(ptr
))
781 SCNEXT(prev
) = SCNEXT(ptr
);
791 #if defined(PCMCIA) || !defined(MODULE)
792 void aha152x_setup(char *str
, int *ints
)
795 printk(KERN_ERR
"aha152x: you can only configure up to two controllers\n");
799 setup
[setup_count
].conf
= str
;
800 setup
[setup_count
].io_port
= ints
[0] >= 1 ? ints
[1] : 0x340;
801 setup
[setup_count
].irq
= ints
[0] >= 2 ? ints
[2] : 11;
802 setup
[setup_count
].scsiid
= ints
[0] >= 3 ? ints
[3] : 7;
803 setup
[setup_count
].reconnect
= ints
[0] >= 4 ? ints
[4] : 1;
804 setup
[setup_count
].parity
= ints
[0] >= 5 ? ints
[5] : 1;
805 setup
[setup_count
].synchronous
= ints
[0] >= 6 ? ints
[6] : 1;
806 setup
[setup_count
].delay
= ints
[0] >= 7 ? ints
[7] : DELAY_DEFAULT
;
807 setup
[setup_count
].ext_trans
= ints
[0] >= 8 ? ints
[8] : 0;
808 #if defined(AHA152X_DEBUG)
809 setup
[setup_count
].debug
= ints
[0] >= 9 ? ints
[9] : DEBUG_DEFAULT
;
811 printk(KERN_NOTICE
"aha152x: usage: aha152x=<IOBASE>[,<IRQ>[,<SCSI ID>"
812 "[,<RECONNECT>[,<PARITY>[,<SYNCHRONOUS>[,<DELAY>[,<EXT_TRANS>[,<DEBUG>]]]]]]]]\n");
814 if (ints
[0] > 8) { /*}*/
815 printk(KERN_NOTICE
"aha152x: usage: aha152x=<IOBASE>[,<IRQ>[,<SCSI ID>"
816 "[,<RECONNECT>[,<PARITY>[,<SYNCHRONOUS>[,<DELAY>[,<EXT_TRANS>]]]]]]]\n");
827 static int __init
do_setup(char *str
)
830 #if defined(AHA152X_DEBUG)
835 int count
=setup_count
;
837 get_options(str
, sizeof(ints
)/sizeof(int), ints
);
838 aha152x_setup(str
,ints
);
840 return count
<setup_count
;
843 __setup("aha152x=", do_setup
);
847 * Test, if port_base is valid.
850 static int aha152x_porttest(int io_port
)
854 if (check_region(io_port
, IO_RANGE
))
857 SETPORT(io_port
+ O_DMACNTRL1
, 0); /* reset stack pointer */
858 for (i
= 0; i
< 16; i
++)
859 SETPORT(io_port
+ O_STACK
, i
);
861 SETPORT(io_port
+ O_DMACNTRL1
, 0); /* reset stack pointer */
862 for (i
= 0; i
< 16 && GETPORT(io_port
+ O_STACK
) == i
; i
++)
868 static int tc1550_porttest(int io_port
)
872 if (check_region(io_port
, IO_RANGE
))
875 SETPORT(io_port
+ O_TC_DMACNTRL1
, 0); /* reset stack pointer */
876 for (i
= 0; i
< 16; i
++)
877 SETPORT(io_port
+ O_STACK
, i
);
879 SETPORT(io_port
+ O_TC_DMACNTRL1
, 0); /* reset stack pointer */
880 for (i
= 0; i
< 16 && GETPORT(io_port
+ O_TC_STACK
) == i
; i
++)
886 static int checksetup(struct aha152x_setup
*setup
)
891 for (i
= 0; i
< PORT_COUNT
&& (setup
->io_port
!= ports
[i
]); i
++)
898 if(aha152x_porttest(setup
->io_port
)) {
900 } else if(tc1550_porttest(setup
->io_port
)) {
905 if ((setup
->irq
< IRQ_MIN
) || (setup
->irq
> IRQ_MAX
))
908 if ((setup
->scsiid
< 0) || (setup
->scsiid
> 7))
911 if ((setup
->reconnect
< 0) || (setup
->reconnect
> 1))
914 if ((setup
->parity
< 0) || (setup
->parity
> 1))
917 if ((setup
->synchronous
< 0) || (setup
->synchronous
> 1))
920 if ((setup
->ext_trans
< 0) || (setup
->ext_trans
> 1))
927 static void swintr(int irqno
, void *dev_id
, struct pt_regs
*regs
)
929 struct Scsi_Host
*shpnt
= aha152x_host
[irqno
- IRQ_MIN
];
932 printk(KERN_ERR
"aha152x%d: catched software interrupt for unknown controller.\n", HOSTNO
);
934 HOSTDATA(shpnt
)->swint
++;
938 int aha152x_detect(Scsi_Host_Template
* tpnt
)
941 #if defined(AUTOCONF)
944 tpnt
->proc_name
= "aha152x";
946 for (i
= 0; i
< IRQS
; i
++)
947 aha152x_host
[i
] = (struct Scsi_Host
*) NULL
;
950 printk(KERN_INFO
"aha152x: processing commandline: ");
952 for (i
= 0; i
< setup_count
; i
++)
953 if (!checksetup(&setup
[i
])) {
954 printk(KERN_ERR
"\naha152x: %s\n", setup
[i
].conf
);
955 printk(KERN_ERR
"aha152x: invalid line\n");
960 if (setup_count
< 2) {
961 struct aha152x_setup override
= SETUP0
;
963 if (setup_count
== 0 || (override
.io_port
!= setup
[0].io_port
)) {
964 if (!checksetup(&override
)) {
965 printk(KERN_ERR
"\naha152x: invalid override SETUP0={0x%x,%d,%d,%d,%d,%d,%d,%d}\n",
971 override
.synchronous
,
975 setup
[setup_count
++] = override
;
981 if (setup_count
< 2) {
982 struct aha152x_setup override
= SETUP1
;
984 if (setup_count
== 0 || (override
.io_port
!= setup
[0].io_port
)) {
985 if (!checksetup(&override
)) {
986 printk(KERN_ERR
"\naha152x: invalid override SETUP1={0x%x,%d,%d,%d,%d,%d,%d,%d}\n",
992 override
.synchronous
,
996 setup
[setup_count
++] = override
;
1002 if (setup_count
<2 && (aha152x
[0]!=0 || io
[0]!=0 || irq
[0]!=0)) {
1004 setup
[setup_count
].conf
= "";
1005 setup
[setup_count
].io_port
= aha152x
[0];
1006 setup
[setup_count
].irq
= aha152x
[1];
1007 setup
[setup_count
].scsiid
= aha152x
[2];
1008 setup
[setup_count
].reconnect
= aha152x
[3];
1009 setup
[setup_count
].parity
= aha152x
[4];
1010 setup
[setup_count
].synchronous
= aha152x
[5];
1011 setup
[setup_count
].delay
= aha152x
[6];
1012 setup
[setup_count
].ext_trans
= aha152x
[7];
1013 #if defined(AHA152X_DEBUG)
1014 setup
[setup_count
].debug
= aha152x
[8];
1016 } else if(io
[0]!=0 || irq
[0]!=0) {
1017 if(io
[0]!=0) setup
[setup_count
].io_port
= io
[0];
1018 if(irq
[0]!=0) setup
[setup_count
].irq
= irq
[0];
1020 setup
[setup_count
].scsiid
= scsiid
[0];
1021 setup
[setup_count
].reconnect
= reconnect
[0];
1022 setup
[setup_count
].parity
= parity
[0];
1023 setup
[setup_count
].synchronous
= sync
[0];
1024 setup
[setup_count
].delay
= delay
[0];
1025 setup
[setup_count
].ext_trans
= exttrans
[0];
1026 #if defined(AHA152X_DEBUG)
1027 setup
[setup_count
].debug
= debug
[0];
1031 if (checksetup(&setup
[setup_count
]))
1034 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",
1035 setup
[setup_count
].io_port
,
1036 setup
[setup_count
].irq
,
1037 setup
[setup_count
].scsiid
,
1038 setup
[setup_count
].reconnect
,
1039 setup
[setup_count
].parity
,
1040 setup
[setup_count
].synchronous
,
1041 setup
[setup_count
].delay
,
1042 setup
[setup_count
].ext_trans
);
1045 if (setup_count
< 2 && (aha152x1
[0]!=0 || io
[1]!=0 || irq
[1]!=0)) {
1046 if(aha152x1
[0]!=0) {
1047 setup
[setup_count
].conf
= "";
1048 setup
[setup_count
].io_port
= aha152x1
[0];
1049 setup
[setup_count
].irq
= aha152x1
[1];
1050 setup
[setup_count
].scsiid
= aha152x1
[2];
1051 setup
[setup_count
].reconnect
= aha152x1
[3];
1052 setup
[setup_count
].parity
= aha152x1
[4];
1053 setup
[setup_count
].synchronous
= aha152x1
[5];
1054 setup
[setup_count
].delay
= aha152x1
[6];
1055 setup
[setup_count
].ext_trans
= aha152x1
[7];
1056 #if defined(AHA152X_DEBUG)
1057 setup
[setup_count
].debug
= aha152x1
[8];
1059 } else if(io
[1]!=0 || irq
[1]!=0) {
1060 if(io
[1]!=0) setup
[setup_count
].io_port
= io
[1];
1061 if(irq
[1]!=0) setup
[setup_count
].irq
= irq
[1];
1063 setup
[setup_count
].scsiid
= scsiid
[1];
1064 setup
[setup_count
].reconnect
= reconnect
[1];
1065 setup
[setup_count
].parity
= parity
[1];
1066 setup
[setup_count
].synchronous
= sync
[1];
1067 setup
[setup_count
].delay
= delay
[1];
1068 setup
[setup_count
].ext_trans
= exttrans
[1];
1069 #if defined(AHA152X_DEBUG)
1070 setup
[setup_count
].debug
= debug
[1];
1073 if (checksetup(&setup
[setup_count
]))
1076 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",
1077 setup
[setup_count
].io_port
,
1078 setup
[setup_count
].irq
,
1079 setup
[setup_count
].scsiid
,
1080 setup
[setup_count
].reconnect
,
1081 setup
[setup_count
].parity
,
1082 setup
[setup_count
].synchronous
,
1083 setup
[setup_count
].delay
,
1084 setup
[setup_count
].ext_trans
);
1088 #if defined(AUTOCONF)
1089 if (setup_count
< 2) {
1090 #if !defined(SKIP_BIOSTEST)
1092 for (i
= 0; i
< ADDRESS_COUNT
&& !ok
; i
++)
1093 for (j
= 0; (j
< SIGNATURE_COUNT
) && !ok
; j
++)
1094 ok
= isa_check_signature(addresses
[i
] + signatures
[j
].sig_offset
,
1095 signatures
[j
].signature
, signatures
[j
].sig_length
);
1097 if (!ok
&& setup_count
== 0)
1100 printk(KERN_INFO
"aha152x: BIOS test: passed, ");
1102 printk(KERN_INFO
"aha152x: ");
1103 #endif /* !SKIP_BIOSTEST */
1106 for (i
= 0; i
< PORT_COUNT
&& setup_count
< 2; i
++) {
1107 if ((setup_count
== 1) && (setup
[0].io_port
== ports
[i
]))
1110 if (aha152x_porttest(ports
[i
])) {
1112 setup
[setup_count
].io_port
= ports
[i
];
1113 setup
[setup_count
].tc1550
= 0;
1116 (GETPORT(ports
[i
] + O_PORTA
) << 8) + GETPORT(ports
[i
] + O_PORTB
);
1118 setup
[setup_count
].irq
= IRQ_MIN
+ conf
.cf_irq
;
1119 setup
[setup_count
].scsiid
= conf
.cf_id
;
1120 setup
[setup_count
].reconnect
= conf
.cf_tardisc
;
1121 setup
[setup_count
].parity
= !conf
.cf_parity
;
1122 setup
[setup_count
].synchronous
= conf
.cf_syncneg
;
1123 setup
[setup_count
].delay
= DELAY_DEFAULT
;
1124 setup
[setup_count
].ext_trans
= 0;
1125 #if defined(AHA152X_DEBUG)
1126 setup
[setup_count
].debug
= DEBUG_DEFAULT
;
1129 } else if (tc1550_porttest(ports
[i
])) {
1131 setup
[setup_count
].io_port
= ports
[i
];
1132 setup
[setup_count
].tc1550
= 1;
1135 (GETPORT(ports
[i
] + O_PORTA
) << 8) + GETPORT(ports
[i
] + O_PORTB
);
1137 setup
[setup_count
].irq
= IRQ_MIN
+ conf
.cf_irq
;
1138 setup
[setup_count
].scsiid
= conf
.cf_id
;
1139 setup
[setup_count
].reconnect
= conf
.cf_tardisc
;
1140 setup
[setup_count
].parity
= !conf
.cf_parity
;
1141 setup
[setup_count
].synchronous
= conf
.cf_syncneg
;
1142 setup
[setup_count
].delay
= DELAY_DEFAULT
;
1143 setup
[setup_count
].ext_trans
= 0;
1144 #if defined(AHA152X_DEBUG)
1145 setup
[setup_count
].debug
= DEBUG_DEFAULT
;
1152 printk("auto configuration: ok, ");
1156 printk("detected %d controller(s)\n", setup_count
);
1158 for (i
=0; i
<setup_count
; i
++) {
1159 struct Scsi_Host
*shpnt
;
1161 aha152x_host
[setup
[i
].irq
- IRQ_MIN
] = shpnt
=
1162 scsi_register(tpnt
, sizeof(struct aha152x_hostdata
));
1165 printk(KERN_ERR
"aha152x: scsi_register failed\n");
1171 shpnt
->io_port
= setup
[i
].io_port
;
1172 shpnt
->n_io_port
= IO_RANGE
;
1173 shpnt
->irq
= setup
[i
].irq
;
1175 if(!setup
[i
].tc1550
) {
1176 HOSTIOPORT0
= setup
[i
].io_port
;
1177 HOSTIOPORT1
= setup
[i
].io_port
;
1179 HOSTIOPORT0
= setup
[i
].io_port
+0x10;
1180 HOSTIOPORT1
= setup
[i
].io_port
-0x10;
1186 DISCONNECTED_SC
= 0;
1188 QLOCK
= SPIN_LOCK_UNLOCKED
;
1197 RECONNECT
= setup
[i
].reconnect
;
1198 SYNCHRONOUS
= setup
[i
].synchronous
;
1199 PARITY
= setup
[i
].parity
;
1200 DELAY
= setup
[i
].delay
;
1201 EXT_TRANS
= setup
[i
].ext_trans
;
1202 #if defined(AHA152X_DEBUG)
1203 HOSTDATA(shpnt
)->debug
= setup
[i
].debug
;
1205 HOSTDATA(shpnt
)->in_intr
= 0;
1206 HOSTDATA(shpnt
)->commands
= 0;
1208 #if defined(AHA152X_STAT)
1209 HOSTDATA(shpnt
)->total_commands
=0;
1210 HOSTDATA(shpnt
)->disconnections
=0;
1211 HOSTDATA(shpnt
)->busfree_without_any_action
=0;
1212 HOSTDATA(shpnt
)->busfree_without_old_command
=0;
1213 HOSTDATA(shpnt
)->busfree_without_new_command
=0;
1214 HOSTDATA(shpnt
)->busfree_without_done_command
=0;
1215 HOSTDATA(shpnt
)->busfree_with_check_condition
=0;
1216 for (j
= idle
; j
<maxstate
; j
++) {
1217 HOSTDATA(shpnt
)->count
[j
]=0;
1218 HOSTDATA(shpnt
)->count_trans
[j
]=0;
1219 HOSTDATA(shpnt
)->time
[j
]=0;
1223 for (j
= 0; j
< 8; j
++) {
1224 HOSTDATA(shpnt
)->syncrate
[j
] = 0;
1225 HOSTDATA(shpnt
)->syncneg
[j
] = 0;
1228 SETPORT(SCSIID
, setup
[i
].scsiid
<< 4);
1229 shpnt
->this_id
= setup
[i
].scsiid
;
1231 if (setup
[i
].reconnect
)
1232 shpnt
->can_queue
= AHA152X_MAXQUEUE
;
1235 if(!shpnt
->hostt
->use_new_eh_code
) {
1238 printk("aha152x: resetting bus...\n");
1239 SETPORT(SCSISEQ
, SCSIRSTO
);
1241 SETPORT(SCSISEQ
, 0);
1251 "vital data: rev=%x, "
1252 "io=0x%03lx (0x%03lx/0x%03lx), "
1259 "extended translation=%s\n",
1260 HOSTNO
, setup
[i
].tc1550
? " (tc1550 mode)" : "",
1262 shpnt
->io_port
, HOSTIOPORT0
, HOSTIOPORT1
,
1265 RECONNECT
? "enabled" : "disabled",
1266 PARITY
? "enabled" : "disabled",
1267 SYNCHRONOUS
? "enabled" : "disabled",
1269 EXT_TRANS
? "enabled" : "disabled");
1271 request_region(shpnt
->io_port
, IO_RANGE
, "aha152x");
1273 /* not expecting any interrupts */
1274 SETPORT(SIMODE0
, 0);
1275 SETPORT(SIMODE1
, 0);
1277 ok
= request_irq(shpnt
->irq
, swintr
, SA_INTERRUPT
, "aha152x", shpnt
);
1280 printk(KERN_ERR
"aha152x%d: bad IRQ %d.\n", HOSTNO
, shpnt
->irq
);
1282 printk(KERN_ERR
"aha152x%d: IRQ %d already in use.\n", HOSTNO
, shpnt
->irq
);
1284 printk(KERN_ERR
"aha152x%d: Unexpected error code %d on requesting IRQ %d.\n", HOSTNO
, ok
, shpnt
->irq
);
1286 printk(KERN_ERR
"aha152x%d: driver needs an IRQ.\n", HOSTNO
);
1288 scsi_unregister(shpnt
);
1290 release_region(shpnt
->io_port
, IO_RANGE
);
1291 aha152x_host
[shpnt
->irq
- IRQ_MIN
] = 0;
1295 HOSTDATA(shpnt
)->swint
= 0;
1297 printk(KERN_INFO
"aha152x%d: trying software interrupt, ", HOSTNO
);
1298 SETPORT(DMACNTRL0
, SWINT
|INTEN
);
1299 spin_unlock_irq(&io_request_lock
);
1301 spin_lock_irq(&io_request_lock
);
1302 free_irq(shpnt
->irq
, shpnt
);
1304 if (!HOSTDATA(shpnt
)->swint
) {
1305 if (TESTHI(DMASTAT
, INTSTAT
)) {
1308 printk("failed.\n");
1311 printk(KERN_ERR
"aha152x%d: IRQ %d possibly wrong. Please verify.\n", HOSTNO
, shpnt
->irq
);
1314 release_region(shpnt
->io_port
, IO_RANGE
);
1315 aha152x_host
[shpnt
->irq
- IRQ_MIN
] = 0;
1316 scsi_unregister(shpnt
);
1322 SETPORT(DMACNTRL0
, INTEN
);
1324 /* clear interrupts */
1325 SETPORT(SSTAT0
, 0x7f);
1326 SETPORT(SSTAT1
, 0xef);
1328 if (request_irq(shpnt
->irq
, intr
, SA_INTERRUPT
, "aha152x", shpnt
) < 0) {
1329 printk(KERN_ERR
"aha152x%d: failed to reassign interrupt.\n", HOSTNO
);
1331 scsi_unregister(shpnt
);
1333 release_region(shpnt
->io_port
, IO_RANGE
);
1334 shpnt
= aha152x_host
[shpnt
->irq
- IRQ_MIN
] = 0;
1339 return registered_count
>0;
1343 int aha152x_release(struct Scsi_Host
*shpnt
)
1346 free_irq(shpnt
->irq
, shpnt
);
1349 release_region(shpnt
->io_port
, IO_RANGE
);
1351 scsi_unregister(shpnt
);
1357 * setup controller to generate interrupts depending
1358 * on current state (lock has to be acquired)
1361 static int setup_expected_interrupts(struct Scsi_Host
*shpnt
)
1363 ASSERT_LOCK(&QLOCK
,1);
1366 CURRENT_SC
->SCp
.phase
|= 1 << 16;
1368 if(CURRENT_SC
->SCp
.phase
& selecting
) {
1369 DPRINTK(debug_intr
, DEBUG_LEAD
"expecting: (seldo) (seltimo) (seldi)\n", CMDINFO(CURRENT_SC
));
1370 SETPORT(SSTAT1
, SELTO
);
1371 SETPORT(SIMODE0
, ENSELDO
| (DISCONNECTED_SC
? ENSELDI
: 0));
1372 SETPORT(SIMODE1
, ENSELTIMO
);
1374 DPRINTK(debug_intr
, DEBUG_LEAD
"expecting: (phase change) (busfree) %s\n", CMDINFO(CURRENT_SC
), CURRENT_SC
->SCp
.phase
& spiordy
? "(spiordy)" : "");
1375 SETPORT(SIMODE0
, (CURRENT_SC
->SCp
.phase
& spiordy
) ? ENSPIORDY
: 0);
1376 SETPORT(SIMODE1
, ENPHASEMIS
| ENSCSIRST
| ENSCSIPERR
| ENBUSFREE
);
1378 } else if(STATE
==seldi
) {
1379 DPRINTK(debug_intr
, DEBUG_LEAD
"expecting: (phase change) (identify)\n", CMDINFO(CURRENT_SC
));
1380 SETPORT(SIMODE0
, 0);
1381 SETPORT(SIMODE1
, ENPHASEMIS
| ENSCSIRST
| ENSCSIPERR
| ENBUSFREE
);
1383 DPRINTK(debug_intr
, DEBUG_LEAD
"expecting: %s %s\n",
1384 CMDINFO(CURRENT_SC
),
1385 DISCONNECTED_SC
? "(reselection)" : "",
1386 ISSUE_SC
? "(busfree)" : "");
1387 SETPORT(SIMODE0
, DISCONNECTED_SC
? ENSELDI
: 0);
1388 SETPORT(SIMODE1
, ENSCSIRST
| ( (ISSUE_SC
||DONE_SC
) ? ENBUSFREE
: 0));
1391 if(!HOSTDATA(shpnt
)->in_intr
)
1392 SETBITS(DMACNTRL0
, INTEN
);
1394 return TESTHI(DMASTAT
, INTSTAT
);
1399 * Queue a command and setup interrupts for a free bus.
1401 int aha152x_internal_queue(Scsi_Cmnd
*SCpnt
, struct semaphore
*sem
, int phase
, Scsi_Cmnd
*done_SC
, void (*done
)(Scsi_Cmnd
*))
1403 struct Scsi_Host
*shpnt
= SCpnt
->host
;
1404 unsigned long flags
;
1406 #if defined(AHA152X_DEBUG)
1407 if (HOSTDATA(shpnt
)->debug
& debug_queue
) {
1408 printk(INFO_LEAD
"queue: cmd_len=%d pieces=%d size=%u cmnd=",
1409 CMDINFO(SCpnt
), SCpnt
->cmd_len
, SCpnt
->use_sg
, SCpnt
->request_bufflen
);
1410 print_command(SCpnt
->cmnd
);
1414 SCpnt
->scsi_done
= done
;
1415 SCpnt
->resid
= SCpnt
->request_bufflen
;
1416 SCpnt
->SCp
.phase
= not_issued
| phase
;
1417 SCpnt
->SCp
.Status
= CHECK_CONDITION
;
1418 SCpnt
->SCp
.Message
= 0;
1419 SCpnt
->SCp
.have_data_in
= 0;
1420 SCpnt
->SCp
.sent_command
= 0;
1421 SCpnt
->host_scribble
= kmalloc(sizeof(struct aha152x_scdata
), GFP_ATOMIC
);
1422 if(!SCpnt
->host_scribble
) {
1423 printk(ERR_LEAD
"allocation failed\n", CMDINFO(SCpnt
));
1428 SCDONE(SCpnt
) = done_SC
;
1431 /* setup scratch area
1432 SCp.ptr : buffer pointer
1433 SCp.this_residual : buffer length
1434 SCp.buffer : next buffer
1435 SCp.buffers_residual : left buffers in list
1436 SCp.phase : current state of the command */
1437 if (SCpnt
->use_sg
) {
1438 SCpnt
->SCp
.buffer
= (struct scatterlist
*) SCpnt
->request_buffer
;
1439 SCpnt
->SCp
.ptr
= SCpnt
->SCp
.buffer
->address
;
1440 SCpnt
->SCp
.this_residual
= SCpnt
->SCp
.buffer
->length
;
1441 SCpnt
->SCp
.buffers_residual
= SCpnt
->use_sg
- 1;
1443 SCpnt
->SCp
.ptr
= (char *) SCpnt
->request_buffer
;
1444 SCpnt
->SCp
.this_residual
= SCpnt
->request_bufflen
;
1445 SCpnt
->SCp
.buffer
= NULL
;
1446 SCpnt
->SCp
.buffers_residual
= 0;
1451 #if defined(AHA152X_STAT)
1452 HOSTDATA(shpnt
)->total_commands
++;
1455 /* Turn led on, when this is the first command. */
1456 HOSTDATA(shpnt
)->commands
++;
1457 if (HOSTDATA(shpnt
)->commands
==1)
1460 append_SC(&ISSUE_SC
, SCpnt
);
1462 if(!HOSTDATA(shpnt
)->in_intr
)
1463 setup_expected_interrupts(shpnt
);
1470 int aha152x_queue(Scsi_Cmnd
*SCpnt
, void (*done
)(Scsi_Cmnd
*))
1472 if(*SCpnt
->cmnd
== REQUEST_SENSE
) {
1479 return aha152x_internal_queue(SCpnt
, 0, 0, 0, done
);
1487 void internal_done(Scsi_Cmnd
*SCpnt
)
1490 struct Scsi_Host
*shpnt
= SCpnt
->host
;
1492 DPRINTK(debug_eh
, INFO_LEAD
"internal_done called\n", CMDINFO(SCpnt
));
1498 int aha152x_command(Scsi_Cmnd
* SCpnt
)
1500 DECLARE_MUTEX_LOCKED(sem
);
1502 aha152x_internal_queue(SCpnt
, &sem
, 0, 0, internal_done
);
1512 int aha152x_abort(Scsi_Cmnd
*SCpnt
)
1514 struct Scsi_Host
*shpnt
= SCpnt
->host
;
1516 unsigned long flags
;
1519 printk(ERR_LEAD
"abort(%p): no host structure\n", CMDINFO(SCpnt
), SCpnt
);
1523 #if defined(AHA152X_DEBUG)
1524 if(HOSTDATA(shpnt
)->debug
& debug_eh
) {
1525 printk(DEBUG_LEAD
"abort(%p)", CMDINFO(SCpnt
), SCpnt
);
1533 ptr
=remove_SC(&ISSUE_SC
, SCpnt
);
1536 DPRINTK(debug_eh
, DEBUG_LEAD
"not yet issued - SUCCESS\n", CMDINFO(SCpnt
));
1538 HOSTDATA(shpnt
)->commands
--;
1539 if (!HOSTDATA(shpnt
)->commands
)
1543 kfree(SCpnt
->host_scribble
);
1544 SCpnt
->host_scribble
=0;
1553 * for current command: queue ABORT for message out and raise ATN
1554 * for disconnected command: pseudo SC with ABORT message or ABORT on reselection?
1558 printk(ERR_LEAD
"cannot abort running or disconnected command\n", CMDINFO(SCpnt
));
1563 static void timer_expired(unsigned long p
)
1565 struct semaphore
*sem
= (void *)p
;
1567 printk(KERN_INFO
"aha152x: timer expired\n");
1574 * FIXME: never seen this live. might lockup...
1577 int aha152x_device_reset(Scsi_Cmnd
* SCpnt
)
1579 struct Scsi_Host
*shpnt
= SCpnt
->host
;
1580 DECLARE_MUTEX_LOCKED(sem
);
1581 struct timer_list timer
;
1584 #if defined(AHA152X_DEBUG)
1585 if(HOSTDATA(shpnt
)->debug
& debug_eh
) {
1586 printk(INFO_LEAD
"aha152x_device_reset(%p)", CMDINFO(SCpnt
), SCpnt
);
1592 if(CURRENT_SC
==SCpnt
) {
1593 printk(ERR_LEAD
"cannot reset current device\n", CMDINFO(SCpnt
));
1598 cmnd
.host
= SCpnt
->host
;
1599 cmnd
.target
= SCpnt
->target
;
1600 cmnd
.lun
= SCpnt
->lun
;
1602 cmnd
.request_buffer
= 0;
1603 cmnd
.request_bufflen
= 0;
1606 timer
.data
= (unsigned long) &sem
;
1607 timer
.expires
= jiffies
+ 10000; /* 10s */
1608 timer
.function
= (void (*)(unsigned long)) timer_expired
;
1611 aha152x_internal_queue(&cmnd
, &sem
, resetting
, 0, internal_done
);
1617 if(cmnd
.SCp
.phase
& resetted
) {
1624 void free_hard_reset_SCs(struct Scsi_Host
*shpnt
, Scsi_Cmnd
**SCs
)
1627 unsigned long flags
;
1633 Scsi_Cmnd
*next
= SCNEXT(ptr
);
1635 if (!ptr
->device
->soft_reset
) {
1636 DPRINTK(debug_eh
, DEBUG_LEAD
"disconnected command %p removed\n", CMDINFO(ptr
), ptr
);
1637 remove_SC(SCs
, ptr
);
1638 HOSTDATA(shpnt
)->commands
--;
1639 kfree(ptr
->host_scribble
);
1640 ptr
->host_scribble
=0;
1653 int aha152x_bus_reset(Scsi_Cmnd
*SCpnt
)
1655 struct Scsi_Host
*shpnt
= SCpnt
->host
;
1656 unsigned long flags
;
1658 #if defined(AHA152X_DEBUG)
1659 if(HOSTDATA(shpnt
)->debug
& debug_eh
) {
1660 printk(DEBUG_LEAD
"aha152x_bus_reset(%p)", CMDINFO(SCpnt
), SCpnt
);
1666 free_hard_reset_SCs(shpnt
, &ISSUE_SC
);
1667 free_hard_reset_SCs(shpnt
, &DISCONNECTED_SC
);
1669 DPRINTK(debug_eh
, DEBUG_LEAD
"resetting bus\n", CMDINFO(SCpnt
));
1671 SETPORT(SCSISEQ
, SCSIRSTO
);
1673 SETPORT(SCSISEQ
, 0);
1676 DPRINTK(debug_eh
, DEBUG_LEAD
"bus reset returns\n", CMDINFO(SCpnt
));
1679 setup_expected_interrupts(shpnt
);
1680 if(HOSTDATA(shpnt
)->commands
==0)
1689 * Restore default values to the AIC-6260 registers and reset the fifos
1692 static void reset_ports(struct Scsi_Host
*shpnt
)
1694 unsigned long flags
;
1696 /* disable interrupts */
1697 SETPORT(DMACNTRL0
, RSTFIFO
);
1699 SETPORT(SCSISEQ
, 0);
1701 SETPORT(SXFRCTL1
, 0);
1702 SETPORT(SCSISIG
, 0);
1705 /* clear all interrupt conditions */
1706 SETPORT(SSTAT0
, 0x7f);
1707 SETPORT(SSTAT1
, 0xef);
1709 SETPORT(SSTAT4
, SYNCERR
| FWERR
| FRERR
);
1711 SETPORT(DMACNTRL0
, 0);
1712 SETPORT(DMACNTRL1
, 0);
1714 SETPORT(BRSTCNTRL
, 0xf1);
1716 /* clear SCSI fifos and transfer count */
1717 SETPORT(SXFRCTL0
, CH1
|CLRCH1
|CLRSTCNT
);
1718 SETPORT(SXFRCTL0
, CH1
);
1721 setup_expected_interrupts(shpnt
);
1726 * Reset the host (bus and controller)
1729 int aha152x_host_reset(Scsi_Cmnd
* SCpnt
)
1731 #if defined(AHA152X_DEBUG)
1732 struct Scsi_Host
*shpnt
= SCpnt
->host
;
1735 DPRINTK(debug_eh
, DEBUG_LEAD
"aha152x_host_reset(%p)\n", CMDINFO(SCpnt
), SCpnt
);
1737 aha152x_bus_reset(SCpnt
);
1739 DPRINTK(debug_eh
, DEBUG_LEAD
"resetting ports\n", CMDINFO(SCpnt
));
1740 reset_ports(SCpnt
->host
);
1746 * Return the "logical geometry"
1749 int aha152x_biosparam(Scsi_Disk
* disk
, kdev_t dev
, int *info_array
)
1751 struct Scsi_Host
*shpnt
= disk
->device
->host
;
1753 /* try default translation */
1756 info_array
[2] = disk
->capacity
/ (64 * 32);
1758 /* for disks >1GB do some guessing */
1759 if (info_array
[2] >= 1024) {
1762 /* try to figure out the geometry from the partition table */
1763 if (scsicam_bios_param(disk
, dev
, info
) < 0 ||
1764 !((info
[0] == 64 && info
[1] == 32) || (info
[0] == 255 && info
[1] == 63))) {
1767 "aha152x: unable to verify geometry for disk with >1GB.\n"
1768 " using extended translation.\n");
1769 info_array
[0] = 255;
1771 info_array
[2] = disk
->capacity
/ (255 * 63);
1774 "aha152x: unable to verify geometry for disk with >1GB.\n"
1775 " Using default translation. Please verify yourself.\n"
1776 " Perhaps you need to enable extended translation in the driver.\n"
1777 " See /usr/src/linux/drivers/scsi/README.aha152x for details.\n");
1780 info_array
[0] = info
[0];
1781 info_array
[1] = info
[1];
1782 info_array
[2] = info
[2];
1784 if (info
[0] == 255 && !EXT_TRANS
) {
1786 "aha152x: current partition table is using extended translation.\n"
1787 " using it also, although it's not explictly enabled.\n");
1796 * Internal done function
1799 static void done(struct Scsi_Host
*shpnt
, int error
)
1803 printk(ERR_LEAD
"there's already a completed command %p - will cause abort\n", CMDINFO(CURRENT_SC
), DONE_SC
);
1805 DONE_SC
= CURRENT_SC
;
1807 DONE_SC
->result
= error
;
1809 printk(KERN_ERR
"aha152x: done() called outside of command\n");
1812 static struct tq_struct aha152x_tq
;
1815 * Run service completions on the card with interrupts enabled.
1818 static void run(void)
1821 for (i
= 0; i
< IRQS
; i
++) {
1822 struct Scsi_Host
*shpnt
= aha152x_host
[i
];
1823 if (shpnt
&& HOSTDATA(shpnt
)->service
) {
1824 HOSTDATA(shpnt
)->service
=0;
1831 * Interrupts handler
1835 static void intr(int irqno
, void *dev_id
, struct pt_regs
*regs
)
1837 struct Scsi_Host
*shpnt
= aha152x_host
[irqno
- IRQ_MIN
];
1840 printk(KERN_ERR
"aha152x: catched interrupt for unknown controller.\n");
1844 /* no more interrupts from the controller, while we're busy.
1845 INTEN is restored by the BH handler */
1846 CLRBITS(DMACNTRL0
, INTEN
);
1849 /* check if there is already something to be
1850 serviced; should not happen */
1851 if(HOSTDATA(shpnt
)->service
) {
1852 printk(KERN_ERR
"aha152x%d: lost interrupt (%d)\n", HOSTNO
, HOSTDATA(shpnt
)->service
);
1857 /* Poke the BH handler */
1858 HOSTDATA(shpnt
)->service
++;
1859 aha152x_tq
.routine
= (void *) run
;
1860 queue_task(&aha152x_tq
, &tq_immediate
);
1861 mark_bh(IMMEDIATE_BH
);
1866 * - handle completition/disconnection/error of current command
1867 * - start selection for next command (if any)
1869 static void busfree_run(struct Scsi_Host
*shpnt
)
1871 unsigned long flags
;
1872 #if defined(AHA152X_STAT)
1876 SETPORT(SXFRCTL0
, CH1
|CLRCH1
|CLRSTCNT
);
1877 SETPORT(SXFRCTL0
, CH1
);
1879 SETPORT(SSTAT1
, CLRBUSFREE
);
1882 #if defined(AHA152X_STAT)
1885 CURRENT_SC
->SCp
.phase
&= ~syncneg
;
1887 if(CURRENT_SC
->SCp
.phase
& completed
) {
1888 /* target sent COMMAND COMPLETE */
1889 done(shpnt
, (CURRENT_SC
->SCp
.Status
& 0xff) | ((CURRENT_SC
->SCp
.Message
& 0xff) << 8) | (DID_OK
<< 16));
1891 } else if(CURRENT_SC
->SCp
.phase
& aborted
) {
1892 DPRINTK(debug_eh
, DEBUG_LEAD
"ABORT sent\n", CMDINFO(CURRENT_SC
));
1893 done(shpnt
, (CURRENT_SC
->SCp
.Status
& 0xff) | ((CURRENT_SC
->SCp
.Message
& 0xff) << 8) | (DID_ABORT
<< 16));
1895 } else if(CURRENT_SC
->SCp
.phase
& resetted
) {
1896 DPRINTK(debug_eh
, DEBUG_LEAD
"BUS DEVICE RESET sent\n", CMDINFO(CURRENT_SC
));
1897 done(shpnt
, (CURRENT_SC
->SCp
.Status
& 0xff) | ((CURRENT_SC
->SCp
.Message
& 0xff) << 8) | (DID_RESET
<< 16));
1899 } else if(CURRENT_SC
->SCp
.phase
& disconnected
) {
1900 /* target sent DISCONNECT */
1901 DPRINTK(debug_selection
, DEBUG_LEAD
"target disconnected at %d/%d\n",
1902 CMDINFO(CURRENT_SC
),
1904 CURRENT_SC
->request_bufflen
);
1905 #if defined(AHA152X_STAT)
1906 HOSTDATA(shpnt
)->disconnections
++;
1908 append_SC(&DISCONNECTED_SC
, CURRENT_SC
);
1909 CURRENT_SC
->SCp
.phase
|= 1 << 16;
1913 done(shpnt
, DID_ERROR
<< 16);
1915 #if defined(AHA152X_STAT)
1917 HOSTDATA(shpnt
)->busfree_without_old_command
++;
1924 #if defined(AHA152X_STAT)
1927 if(SCDONE(DONE_SC
)) {
1928 Scsi_Cmnd
*ptr
=DONE_SC
;
1929 DONE_SC
=SCDONE(DONE_SC
);
1932 if(HOSTDATA(shpnt
)->debug
& debug_eh
) {
1933 printk(ERR_LEAD
"received sense: ", CMDINFO(ptr
));
1934 print_sense("bh", DONE_SC
);
1938 HOSTDATA(shpnt
)->commands
--;
1939 if (!HOSTDATA(shpnt
)->commands
)
1940 SETPORT(PORTA
, 0); /* turn led off */
1942 kfree(ptr
->host_scribble
);
1944 } else if(DONE_SC
->SCp
.Status
==0x02) {
1945 #if defined(AHA152X_STAT)
1946 HOSTDATA(shpnt
)->busfree_with_check_condition
++;
1949 DPRINTK(debug_eh
, ERR_LEAD
"CHECK CONDITION found\n", CMDINFO(DONE_SC
));
1952 if(!(DONE_SC
->SCp
.Status
& not_issued
)) {
1953 Scsi_Cmnd
*cmnd
= kmalloc(sizeof(Scsi_Cmnd
), GFP_ATOMIC
);
1956 Scsi_Cmnd
*ptr
=DONE_SC
;
1960 DPRINTK(debug_eh
, ERR_LEAD
"requesting sense\n", CMDINFO(ptr
));
1963 cmnd
->cmnd
[0] = REQUEST_SENSE
;
1967 cmnd
->cmnd
[4] = sizeof(ptr
->sense_buffer
);
1970 cmnd
->host
= ptr
->host
;
1971 cmnd
->target
= ptr
->target
;
1972 cmnd
->lun
= ptr
->lun
;
1974 cmnd
->request_buffer
= ptr
->sense_buffer
;
1975 cmnd
->request_bufflen
= sizeof(ptr
->sense_buffer
);
1978 aha152x_internal_queue(cmnd
, 0, 0, ptr
, internal_done
);
1981 printk(ERR_LEAD
"allocation failed\n", CMDINFO(CURRENT_SC
));
1987 DPRINTK(debug_eh
, ERR_LEAD
"command not issued - CHECK CONDITION ignored\n", CMDINFO(DONE_SC
));
1992 if(DONE_SC
&& DONE_SC
->scsi_done
) {
1993 /* turn led off, when no commands are in the driver */
1994 HOSTDATA(shpnt
)->commands
--;
1995 if (!HOSTDATA(shpnt
)->commands
)
1996 SETPORT(PORTA
, 0); /* turn led off */
1998 kfree(DONE_SC
->host_scribble
);
1999 DONE_SC
->host_scribble
=0;
2002 DPRINTK(debug_done
, DEBUG_LEAD
"calling scsi_done(%p)\n", CMDINFO(DONE_SC
), DONE_SC
);
2003 DONE_SC
->scsi_done(DONE_SC
);
2004 DPRINTK(debug_done
, DEBUG_LEAD
"scsi_done(%p) returned\n", CMDINFO(DONE_SC
), DONE_SC
);
2009 #if defined(AHA152X_STAT)
2011 HOSTDATA(shpnt
)->busfree_without_done_command
++;
2016 CURRENT_SC
= remove_first_SC(&ISSUE_SC
);
2021 #if defined(AHA152X_STAT)
2024 CURRENT_SC
->SCp
.phase
|= selecting
;
2026 DPRINTK(debug_selection
, DEBUG_LEAD
"selecting target\n", CMDINFO(CURRENT_SC
));
2028 /* clear selection timeout */
2029 SETPORT(SSTAT1
, SELTO
);
2031 SETPORT(SCSIID
, (shpnt
->this_id
<< OID_
) | CURRENT_SC
->target
);
2032 SETPORT(SXFRCTL1
, (PARITY
? ENSPCHK
: 0 ) | ENSTIMER
);
2033 SETPORT(SCSISEQ
, ENSELO
| ENAUTOATNO
| (DISCONNECTED_SC
? ENRESELI
: 0));
2035 #if defined(AHA152X_STAT)
2036 HOSTDATA(shpnt
)->busfree_without_new_command
++;
2038 SETPORT(SCSISEQ
, DISCONNECTED_SC
? ENRESELI
: 0);
2041 #if defined(AHA152X_STAT)
2043 HOSTDATA(shpnt
)->busfree_without_any_action
++;
2048 * Selection done (OUT)
2049 * - queue IDENTIFY message and SDTR to selected target for message out
2050 * (ATN asserted automagically via ENAUTOATNO in busfree())
2052 static void seldo_run(struct Scsi_Host
*shpnt
)
2054 SETPORT(SCSISIG
, 0);
2055 SETPORT(SSTAT1
, CLRBUSFREE
);
2056 SETPORT(SSTAT1
, CLRPHASECHG
);
2058 CURRENT_SC
->SCp
.phase
&= ~(selecting
|not_issued
);
2060 SETPORT(SCSISEQ
, 0);
2062 if (TESTLO(SSTAT0
, SELDO
)) {
2063 printk(ERR_LEAD
"aha152x: passing bus free condition\n", CMDINFO(CURRENT_SC
));
2064 done(shpnt
, DID_NO_CONNECT
<< 16);
2068 SETPORT(SSTAT0
, CLRSELDO
);
2070 ADDMSGO(IDENTIFY(RECONNECT
, CURRENT_SC
->lun
));
2072 if (CURRENT_SC
->SCp
.phase
& aborting
) {
2074 } else if (CURRENT_SC
->SCp
.phase
& resetting
) {
2075 ADDMSGO(BUS_DEVICE_RESET
);
2076 } else if (SYNCNEG
==0 && SYNCHRONOUS
) {
2077 CURRENT_SC
->SCp
.phase
|= syncneg
;
2078 ADDMSGO(EXTENDED_MESSAGE
);
2080 ADDMSGO(EXTENDED_SDTR
);
2081 ADDMSGO(50); /* 200ns */
2082 ADDMSGO(8); /* 8 byte req/ack offset */
2084 SYNCNEG
=1; /* negotiation in progress */
2092 * - return command to mid-level with failure cause
2095 static void selto_run(struct Scsi_Host
*shpnt
)
2097 SETPORT(SCSISEQ
, 0);
2098 SETPORT(SSTAT1
, CLRSELTIMO
);
2100 DPRINTK(debug_selection
, DEBUG_LEAD
"selection timeout\n", CMDINFO(CURRENT_SC
));
2103 DPRINTK(debug_selection
, DEBUG_LEAD
"!CURRENT_SC\n", CMDINFO(CURRENT_SC
));
2107 CURRENT_SC
->SCp
.phase
&= ~selecting
;
2109 if (CURRENT_SC
->SCp
.phase
& aborted
) {
2110 DPRINTK(debug_selection
, DEBUG_LEAD
"aborted\n", CMDINFO(CURRENT_SC
));
2111 done(shpnt
, DID_ABORT
<< 16);
2112 } else if (TESTLO(SSTAT0
, SELINGO
)) {
2113 DPRINTK(debug_selection
, DEBUG_LEAD
"arbitration not won\n", CMDINFO(CURRENT_SC
));
2114 done(shpnt
, DID_BUS_BUSY
<< 16);
2116 /* ARBITRATION won, but SELECTION failed */
2117 DPRINTK(debug_selection
, DEBUG_LEAD
"selection failed\n", CMDINFO(CURRENT_SC
));
2118 done(shpnt
, DID_NO_CONNECT
<< 16);
2124 * - put current command back to issue queue
2125 * (reconnection of a disconnected nexus instead
2126 * of successful selection out)
2129 static void seldi_run(struct Scsi_Host
*shpnt
)
2133 unsigned long flags
;
2135 SETPORT(SCSISIG
, 0);
2136 SETPORT(SSTAT0
, CLRSELDI
);
2137 SETPORT(SSTAT1
, CLRBUSFREE
);
2138 SETPORT(SSTAT1
, CLRPHASECHG
);
2141 if(!(CURRENT_SC
->SCp
.phase
& not_issued
))
2142 printk(ERR_LEAD
"command should not have been issued yet\n", CMDINFO(CURRENT_SC
));
2144 DPRINTK(debug_selection
, ERR_LEAD
"command requeued - reselection\n", CMDINFO(CURRENT_SC
));
2147 append_SC(&ISSUE_SC
, CURRENT_SC
);
2153 if(!DISCONNECTED_SC
) {
2154 DPRINTK(debug_selection
, DEBUG_LEAD
"unexpected SELDI ", CMDINFO(CURRENT_SC
));
2160 selid
= GETPORT(SELID
) & ~(1 << shpnt
->this_id
);
2163 printk("aha152x%d: target id unknown (%02x)\n", HOSTNO
, selid
);
2167 for(target
=7; !(selid
& (1 << target
)); target
--)
2170 if(selid
& ~(1 << target
)) {
2171 printk("aha152x%d: multiple targets reconnected (%02x)\n",
2176 SETPORT(SCSIID
, (shpnt
->this_id
<< OID_
) | target
);
2177 SETPORT(SCSISEQ
, 0);
2179 SETRATE(HOSTDATA(shpnt
)->syncrate
[target
]);
2181 RECONN_TARGET
=target
;
2182 DPRINTK(debug_selection
, DEBUG_LEAD
"target %d reselected (%02x).\n", CMDINFO(CURRENT_SC
), target
, selid
);
2187 * - handle initial message after reconnection to identify
2188 * reconnecting nexus
2189 * - queue command on DISCONNECTED_SC on DISCONNECT message
2190 * - set completed flag on COMMAND COMPLETE
2191 * (other completition code moved to busfree_run)
2192 * - handle response to SDTR
2193 * - clear synchronous transfer agreements on BUS RESET
2195 * FIXME: what about SAVE POINTERS, RESTORE POINTERS?
2198 static void msgi_run(struct Scsi_Host
*shpnt
)
2201 int sstat1
= GETPORT(SSTAT1
);
2203 if(sstat1
& (PHASECHG
|PHASEMIS
|BUSFREE
) || !(sstat1
& REQINIT
))
2206 if(TESTLO(SSTAT0
,SPIORDY
)) {
2207 DPRINTK(debug_msgi
, DEBUG_LEAD
"!SPIORDY\n", CMDINFO(CURRENT_SC
));
2211 ADDMSGI(GETPORT(SCSIDAT
));
2213 #if defined(AHA152X_DEBUG)
2214 if (HOSTDATA(shpnt
)->debug
& debug_msgi
) {
2215 printk(INFO_LEAD
"inbound message %02x ", CMDINFO(CURRENT_SC
), MSGI(0));
2216 print_msg(&MSGI(0));
2222 if(LASTSTATE
!=seldi
) {
2223 printk(KERN_ERR
"aha152x%d: message in w/o current command not after reselection\n", HOSTNO
);
2227 * Handle reselection
2229 if(!(MSGI(0) & IDENTIFY_BASE
)) {
2230 printk(KERN_ERR
"aha152x%d: target didn't identify after reselection\n", HOSTNO
);
2234 CURRENT_SC
= remove_lun_SC(&DISCONNECTED_SC
, RECONN_TARGET
, MSGI(0) & 0x3f);
2238 printk(KERN_ERR
"aha152x%d: no disconnected command for target %d/%d\n", HOSTNO
, RECONN_TARGET
, MSGI(0) & 0x3f);
2242 DPRINTK(debug_msgi
, DEBUG_LEAD
"target reconnected\n", CMDINFO(CURRENT_SC
));
2244 CURRENT_SC
->SCp
.Message
= MSGI(0);
2245 CURRENT_SC
->SCp
.phase
&= ~disconnected
;
2249 /* next message if any */
2253 CURRENT_SC
->SCp
.Message
= MSGI(0);
2258 printk(WARN_LEAD
"target was not allowed to disconnect\n", CMDINFO(CURRENT_SC
));
2260 CURRENT_SC
->SCp
.phase
|= disconnected
;
2263 case COMMAND_COMPLETE
:
2264 if(CURRENT_SC
->SCp
.phase
& completed
)
2265 DPRINTK(debug_msgi
, DEBUG_LEAD
"again COMMAND COMPLETE\n", CMDINFO(CURRENT_SC
));
2267 CURRENT_SC
->SCp
.phase
|= completed
;
2270 case MESSAGE_REJECT
:
2272 printk(INFO_LEAD
"Synchronous Data Transfer Request was rejected\n", CMDINFO(CURRENT_SC
));
2273 SYNCNEG
=2; /* negotiation completed */
2275 printk(INFO_LEAD
"inbound message (MESSAGE REJECT)\n", CMDINFO(CURRENT_SC
));
2281 case RESTORE_POINTERS
:
2284 case EXTENDED_MESSAGE
:
2285 if(MSGILEN
<2 || MSGILEN
<MSGI(1)+2) {
2286 /* not yet completed */
2296 printk(ERR_LEAD
"SDTR message length!=3\n", CMDINFO(CURRENT_SC
));
2300 if (!HOSTDATA(shpnt
)->synchronous
)
2303 printk(INFO_LEAD
, CMDINFO(CURRENT_SC
));
2304 print_msg(&MSGI(0));
2307 ticks
= (MSGI(3) * 4 + 49) / 50;
2310 /* negotiation in progress */
2311 if (ticks
> 9 || MSGI(4) < 1 || MSGI(4) > 8) {
2312 ADDMSGO(MESSAGE_REJECT
);
2313 printk(INFO_LEAD
"received Synchronous Data Transfer Request invalid - rejected\n", CMDINFO(CURRENT_SC
));
2317 SYNCRATE
|= ((ticks
- 2) << 4) + MSGI(4);
2318 } else if (ticks
<= 9 && MSGI(4) >= 1) {
2319 ADDMSGO(EXTENDED_MESSAGE
);
2321 ADDMSGO(EXTENDED_SDTR
);
2333 SYNCRATE
|= ((ticks
- 2) << 4) + MSGI(4);
2335 /* requested SDTR is too slow, do it asynchronously */
2336 printk(INFO_LEAD
"Synchronous Data Transfer Request too slow - Rejecting\n", CMDINFO(CURRENT_SC
));
2337 ADDMSGO(MESSAGE_REJECT
);
2340 SYNCNEG
=2; /* negotiation completed */
2345 case BUS_DEVICE_RESET
:
2349 for(i
=0; i
<8; i
++) {
2350 HOSTDATA(shpnt
)->syncrate
[i
]=0;
2351 HOSTDATA(shpnt
)->syncneg
[i
]=0;
2357 case EXTENDED_MODIFY_DATA_POINTER
:
2358 case EXTENDED_EXTENDED_IDENTIFY
:
2361 ADDMSGO(MESSAGE_REJECT
);
2371 static void msgi_end(struct Scsi_Host
*shpnt
)
2374 printk(WARN_LEAD
"target left before message completed (%d)\n", CMDINFO(CURRENT_SC
), MSGILEN
);
2376 if (MSGOLEN
> 0 && !(GETPORT(SSTAT1
) & BUSFREE
)) {
2377 DPRINTK(debug_msgi
, DEBUG_LEAD
"msgo pending\n", CMDINFO(CURRENT_SC
));
2378 SETPORT(SCSISIG
, P_MSGI
| SIG_ATNO
);
2386 static void msgo_init(struct Scsi_Host
*shpnt
)
2389 if((CURRENT_SC
->SCp
.phase
& syncneg
) && SYNCNEG
==2 && SYNCRATE
==0) {
2390 ADDMSGO(IDENTIFY(RECONNECT
, CURRENT_SC
->lun
));
2392 printk(INFO_LEAD
"unexpected MESSAGE OUT phase; rejecting\n", CMDINFO(CURRENT_SC
));
2393 ADDMSGO(MESSAGE_REJECT
);
2397 #if defined(AHA152X_DEBUG)
2398 if(HOSTDATA(shpnt
)->debug
& debug_msgo
) {
2401 printk(DEBUG_LEAD
"messages( ", CMDINFO(CURRENT_SC
));
2402 for (i
=0; i
<MSGOLEN
; i
+=print_msg(&MSGO(i
)), printk(" "))
2413 static void msgo_run(struct Scsi_Host
*shpnt
)
2416 DPRINTK(debug_msgo
, DEBUG_LEAD
"messages all sent (%d/%d)\n", CMDINFO(CURRENT_SC
), MSGO_I
, MSGOLEN
);
2418 while(MSGO_I
<MSGOLEN
) {
2419 DPRINTK(debug_msgo
, DEBUG_LEAD
"message byte %02x (%d/%d)\n", CMDINFO(CURRENT_SC
), MSGO(MSGO_I
), MSGO_I
, MSGOLEN
);
2421 if(TESTLO(SSTAT0
, SPIORDY
)) {
2422 DPRINTK(debug_msgo
, DEBUG_LEAD
"!SPIORDY\n", CMDINFO(CURRENT_SC
));
2426 if (MSGO_I
==MSGOLEN
-1) {
2427 /* Leave MESSAGE OUT after transfer */
2428 SETPORT(SSTAT1
, CLRATNO
);
2432 if (MSGO(MSGO_I
) & IDENTIFY_BASE
)
2433 CURRENT_SC
->SCp
.phase
|= identified
;
2435 if (MSGO(MSGO_I
)==ABORT
)
2436 CURRENT_SC
->SCp
.phase
|= aborted
;
2438 if (MSGO(MSGO_I
)==BUS_DEVICE_RESET
)
2439 CURRENT_SC
->SCp
.phase
|= resetted
;
2441 SETPORT(SCSIDAT
, MSGO(MSGO_I
++));
2445 static void msgo_end(struct Scsi_Host
*shpnt
)
2447 if(MSGO_I
<MSGOLEN
) {
2448 printk(ERR_LEAD
"message sent incompletely (%d/%d)\n", CMDINFO(CURRENT_SC
), MSGO_I
, MSGOLEN
);
2450 printk(INFO_LEAD
"Synchronous Data Transfer Request was rejected\n", CMDINFO(CURRENT_SC
));
2463 static void cmd_init(struct Scsi_Host
*shpnt
)
2465 if (CURRENT_SC
->SCp
.sent_command
) {
2466 printk(ERR_LEAD
"command already sent\n", CMDINFO(CURRENT_SC
));
2467 done(shpnt
, DID_ERROR
<< 16);
2471 #if defined(AHA152X_DEBUG)
2472 if (HOSTDATA(shpnt
)->debug
& debug_cmd
) {
2473 printk(DEBUG_LEAD
"cmd_init: ", CMDINFO(CURRENT_SC
));
2474 print_command(CURRENT_SC
->cmnd
);
2485 static void cmd_run(struct Scsi_Host
*shpnt
)
2487 if(CMD_I
==CURRENT_SC
->cmd_len
) {
2488 DPRINTK(debug_cmd
, DEBUG_LEAD
"command already completely sent (%d/%d)", CMDINFO(CURRENT_SC
), CMD_I
, CURRENT_SC
->cmd_len
);
2492 while(CMD_I
<CURRENT_SC
->cmd_len
) {
2493 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
);
2495 if(TESTLO(SSTAT0
, SPIORDY
)) {
2496 DPRINTK(debug_cmd
, DEBUG_LEAD
"!SPIORDY\n", CMDINFO(CURRENT_SC
));
2500 SETPORT(SCSIDAT
, CURRENT_SC
->cmnd
[CMD_I
++]);
2504 static void cmd_end(struct Scsi_Host
*shpnt
)
2506 if(CMD_I
<CURRENT_SC
->cmd_len
)
2507 printk(ERR_LEAD
"command sent incompletely (%d/%d)\n", CMDINFO(CURRENT_SC
), CMD_I
, CURRENT_SC
->cmd_len
);
2509 CURRENT_SC
->SCp
.sent_command
++;
2516 static void status_run(struct Scsi_Host
*shpnt
)
2518 if(TESTLO(SSTAT0
,SPIORDY
)) {
2519 DPRINTK(debug_status
, DEBUG_LEAD
"!SPIORDY\n", CMDINFO(CURRENT_SC
));
2523 CURRENT_SC
->SCp
.Status
= GETPORT(SCSIDAT
);
2525 #if defined(AHA152X_DEBUG)
2526 if (HOSTDATA(shpnt
)->debug
& debug_status
) {
2527 printk(DEBUG_LEAD
"inbound status %02x ", CMDINFO(CURRENT_SC
), CURRENT_SC
->SCp
.Status
);
2528 print_status(CURRENT_SC
->SCp
.Status
);
2538 static void datai_init(struct Scsi_Host
*shpnt
)
2540 SETPORT(DMACNTRL0
, RSTFIFO
);
2541 SETPORT(DMACNTRL0
, RSTFIFO
|ENDMA
);
2543 SETPORT(SXFRCTL0
, CH1
|CLRSTCNT
);
2544 SETPORT(SXFRCTL0
, CH1
|SCSIEN
|DMAEN
);
2546 SETPORT(SIMODE0
, 0);
2547 SETPORT(SIMODE1
, ENSCSIPERR
| ENSCSIRST
| ENPHASEMIS
| ENBUSFREE
);
2550 DPRINTK(debug_datai
,
2551 DEBUG_LEAD
"datai_init: request_bufflen=%d resid=%d\n",
2552 CMDINFO(CURRENT_SC
), CURRENT_SC
->request_bufflen
, CURRENT_SC
->resid
);
2555 static void datai_run(struct Scsi_Host
*shpnt
)
2557 unsigned int the_time
;
2558 int fifodata
, data_count
;
2561 * loop while the phase persists or the fifos are not empty
2564 while(TESTLO(DMASTAT
, INTSTAT
) || TESTLO(DMASTAT
, DFIFOEMP
) || TESTLO(SSTAT2
, SEMPTY
)) {
2565 /* FIXME: maybe this should be done by setting up
2566 * STCNT to trigger ENSWRAP interrupt, instead of
2567 * polling for DFIFOFULL
2569 the_time
=jiffies
+ 10*HZ
;
2570 while(TESTLO(DMASTAT
, DFIFOFULL
|INTSTAT
) && time_before(jiffies
,the_time
))
2573 if(TESTLO(DMASTAT
, DFIFOFULL
|INTSTAT
)) {
2574 printk(ERR_LEAD
"datai timeout", CMDINFO(CURRENT_SC
));
2579 if(TESTHI(DMASTAT
, DFIFOFULL
)) {
2582 the_time
=jiffies
+ 100;
2583 while(TESTLO(SSTAT2
, SEMPTY
) && time_before(jiffies
,the_time
))
2586 if(TESTLO(SSTAT2
, SEMPTY
)) {
2587 printk(ERR_LEAD
"datai sempty timeout", CMDINFO(CURRENT_SC
));
2592 fifodata
= GETPORT(FIFOSTAT
);
2595 if(CURRENT_SC
->SCp
.this_residual
>0) {
2596 while(fifodata
>0 && CURRENT_SC
->SCp
.this_residual
>0) {
2597 data_count
= fifodata
>CURRENT_SC
->SCp
.this_residual
?
2598 CURRENT_SC
->SCp
.this_residual
:
2600 fifodata
-= data_count
;
2602 if(data_count
& 1) {
2603 DPRINTK(debug_datai
, DEBUG_LEAD
"8bit\n", CMDINFO(CURRENT_SC
));
2604 SETPORT(DMACNTRL0
, ENDMA
|_8BIT
);
2605 *CURRENT_SC
->SCp
.ptr
++ = GETPORT(DATAPORT
);
2606 CURRENT_SC
->SCp
.this_residual
--;
2608 SETPORT(DMACNTRL0
, ENDMA
);
2611 if(data_count
> 1) {
2612 DPRINTK(debug_datai
, DEBUG_LEAD
"16bit(%d)\n", CMDINFO(CURRENT_SC
), data_count
);
2614 insw(DATAPORT
, CURRENT_SC
->SCp
.ptr
, data_count
);
2615 CURRENT_SC
->SCp
.ptr
+= 2 * data_count
;
2616 CURRENT_SC
->SCp
.this_residual
-= 2 * data_count
;
2617 DATA_LEN
+= 2 * data_count
;
2620 if(CURRENT_SC
->SCp
.this_residual
==0 && CURRENT_SC
->SCp
.buffers_residual
>0) {
2621 /* advance to next buffer */
2622 CURRENT_SC
->SCp
.buffers_residual
--;
2623 CURRENT_SC
->SCp
.buffer
++;
2624 CURRENT_SC
->SCp
.ptr
= CURRENT_SC
->SCp
.buffer
->address
;
2625 CURRENT_SC
->SCp
.this_residual
= CURRENT_SC
->SCp
.buffer
->length
;
2628 } else if(fifodata
>0) {
2629 printk(ERR_LEAD
"no buffers left for %d(%d) bytes (data overrun!?)\n", CMDINFO(CURRENT_SC
), fifodata
, GETPORT(FIFOSTAT
));
2630 SETPORT(DMACNTRL0
, ENDMA
|_8BIT
);
2633 data
=GETPORT(DATAPORT
);
2634 DPRINTK(debug_datai
, DEBUG_LEAD
"data=%02x\n", CMDINFO(CURRENT_SC
), data
);
2638 SETPORT(DMACNTRL0
, ENDMA
|_8BIT
);
2642 if(TESTLO(DMASTAT
, INTSTAT
) ||
2643 TESTLO(DMASTAT
, DFIFOEMP
) ||
2644 TESTLO(SSTAT2
, SEMPTY
) ||
2645 GETPORT(FIFOSTAT
)>0) {
2647 * something went wrong, if there's something left in the fifos
2648 * or the phase didn't change
2650 printk(ERR_LEAD
"fifos should be empty and phase should have changed\n", CMDINFO(CURRENT_SC
));
2654 if(DATA_LEN
!=GETSTCNT()) {
2656 "manual transfer count differs from automatic (count=%d;stcnt=%d;diff=%d;fifostat=%d)",
2657 CMDINFO(CURRENT_SC
), DATA_LEN
, GETSTCNT(), GETSTCNT()-DATA_LEN
, GETPORT(FIFOSTAT
));
2663 static void datai_end(struct Scsi_Host
*shpnt
)
2665 CURRENT_SC
->resid
-= GETSTCNT();
2667 DPRINTK(debug_datai
,
2668 DEBUG_LEAD
"datai_end: request_bufflen=%d resid=%d stcnt=%d\n",
2669 CMDINFO(CURRENT_SC
), CURRENT_SC
->request_bufflen
, CURRENT_SC
->resid
, GETSTCNT());
2671 SETPORT(SXFRCTL0
, CH1
|CLRSTCNT
);
2672 SETPORT(DMACNTRL0
, 0);
2679 static void datao_init(struct Scsi_Host
*shpnt
)
2681 SETPORT(DMACNTRL0
, WRITE_READ
| RSTFIFO
);
2682 SETPORT(DMACNTRL0
, WRITE_READ
| ENDMA
);
2684 SETPORT(SXFRCTL0
, CH1
|CLRSTCNT
);
2685 SETPORT(SXFRCTL0
, CH1
|SCSIEN
|DMAEN
);
2687 SETPORT(SIMODE0
, 0);
2688 SETPORT(SIMODE1
, ENSCSIPERR
| ENSCSIRST
| ENPHASEMIS
| ENBUSFREE
);
2690 DATA_LEN
= CURRENT_SC
->resid
;
2692 DPRINTK(debug_datao
,
2693 DEBUG_LEAD
"datao_init: request_bufflen=%d; resid=%d\n",
2694 CMDINFO(CURRENT_SC
), CURRENT_SC
->request_bufflen
, CURRENT_SC
->resid
);
2697 static void datao_run(struct Scsi_Host
*shpnt
)
2699 unsigned int the_time
;
2702 /* until phase changes or all data sent */
2703 while(TESTLO(DMASTAT
, INTSTAT
) && CURRENT_SC
->SCp
.this_residual
>0) {
2705 if(data_count
> CURRENT_SC
->SCp
.this_residual
)
2706 data_count
=CURRENT_SC
->SCp
.this_residual
;
2708 if(TESTLO(DMASTAT
, DFIFOEMP
)) {
2709 printk(ERR_LEAD
"datao fifo not empty (%d)", CMDINFO(CURRENT_SC
), GETPORT(FIFOSTAT
));
2714 if(data_count
& 1) {
2715 SETPORT(DMACNTRL0
,WRITE_READ
|ENDMA
|_8BIT
);
2716 SETPORT(DATAPORT
, *CURRENT_SC
->SCp
.ptr
++);
2717 CURRENT_SC
->SCp
.this_residual
--;
2718 CURRENT_SC
->resid
--;
2719 SETPORT(DMACNTRL0
,WRITE_READ
|ENDMA
);
2722 if(data_count
> 1) {
2724 outsw(DATAPORT
, CURRENT_SC
->SCp
.ptr
, data_count
);
2725 CURRENT_SC
->SCp
.ptr
+= 2 * data_count
;
2726 CURRENT_SC
->SCp
.this_residual
-= 2 * data_count
;
2727 CURRENT_SC
->resid
-= 2 * data_count
;
2730 if(CURRENT_SC
->SCp
.this_residual
==0 && CURRENT_SC
->SCp
.buffers_residual
>0) {
2731 /* advance to next buffer */
2732 CURRENT_SC
->SCp
.buffers_residual
--;
2733 CURRENT_SC
->SCp
.buffer
++;
2734 CURRENT_SC
->SCp
.ptr
= CURRENT_SC
->SCp
.buffer
->address
;
2735 CURRENT_SC
->SCp
.this_residual
= CURRENT_SC
->SCp
.buffer
->length
;
2738 the_time
=jiffies
+10*HZ
;
2739 while(TESTLO(DMASTAT
, DFIFOEMP
|INTSTAT
) && time_before(jiffies
,the_time
))
2742 if(TESTLO(DMASTAT
, DFIFOEMP
|INTSTAT
)) {
2743 printk(ERR_LEAD
"dataout timeout", CMDINFO(CURRENT_SC
));
2750 static void datao_end(struct Scsi_Host
*shpnt
)
2752 if(TESTLO(DMASTAT
, DFIFOEMP
)) {
2753 int data_count
= (DATA_LEN
- CURRENT_SC
->resid
) - GETSTCNT();
2755 DPRINTK(debug_datao
, DEBUG_LEAD
"datao: %d bytes to resend (%d written, %d transfered)\n",
2756 CMDINFO(CURRENT_SC
),
2758 DATA_LEN
-CURRENT_SC
->resid
,
2761 CURRENT_SC
->resid
+= data_count
;
2763 if(CURRENT_SC
->use_sg
) {
2764 data_count
-= CURRENT_SC
->SCp
.ptr
- CURRENT_SC
->SCp
.buffer
->address
;
2765 while(data_count
>0) {
2766 CURRENT_SC
->SCp
.buffer
--;
2767 CURRENT_SC
->SCp
.buffers_residual
++;
2768 data_count
-= CURRENT_SC
->SCp
.buffer
->length
;
2770 CURRENT_SC
->SCp
.ptr
= CURRENT_SC
->SCp
.buffer
->address
- data_count
;
2771 CURRENT_SC
->SCp
.this_residual
= CURRENT_SC
->SCp
.buffer
->length
+ data_count
;
2773 CURRENT_SC
->SCp
.ptr
-= data_count
;
2774 CURRENT_SC
->SCp
.this_residual
+= data_count
;
2778 DPRINTK(debug_datao
, DEBUG_LEAD
"datao_end: request_bufflen=%d; resid=%d; stcnt=%d\n",
2779 CMDINFO(CURRENT_SC
),
2780 CURRENT_SC
->request_bufflen
,
2784 SETPORT(SXFRCTL0
, CH1
|CLRCH1
|CLRSTCNT
);
2785 SETPORT(SXFRCTL0
, CH1
);
2787 SETPORT(DMACNTRL0
, 0);
2791 * figure out what state we're in
2794 static int update_state(struct Scsi_Host
*shpnt
)
2797 unsigned int stat0
= GETPORT(SSTAT0
);
2798 unsigned int stat1
= GETPORT(SSTAT1
);
2803 if(stat1
& SCSIRSTI
) {
2806 SETPORT(SSTAT1
,SCSIRSTI
);
2807 } else if(stat0
& SELDI
&& PREVSTATE
==busfree
) {
2809 } else if(stat0
& SELDO
&& CURRENT_SC
&& (CURRENT_SC
->SCp
.phase
& selecting
)) {
2811 } else if(stat1
& SELTO
) {
2813 } else if(stat1
& BUSFREE
) {
2815 SETPORT(SSTAT1
,BUSFREE
);
2816 } else if(stat1
& SCSIPERR
) {
2818 SETPORT(SSTAT1
,SCSIPERR
);
2819 } else if(stat1
& REQINIT
) {
2820 switch(GETPORT(SCSISIG
) & P_MASK
) {
2821 case P_MSGI
: STATE
=msgi
; break;
2822 case P_MSGO
: STATE
=msgo
; break;
2823 case P_DATAO
: STATE
=datao
; break;
2824 case P_DATAI
: STATE
=datai
; break;
2825 case P_STATUS
: STATE
=status
; break;
2826 case P_CMD
: STATE
=cmd
; break;
2831 if((stat0
& SELDI
) && STATE
!=seldi
&& !dataphase
) {
2832 printk(INFO_LEAD
"reselection missed?", CMDINFO(CURRENT_SC
));
2836 if(STATE
!=PREVSTATE
) {
2837 LASTSTATE
=PREVSTATE
;
2844 * handle parity error
2846 * FIXME: in which phase?
2849 static void parerr_run(struct Scsi_Host
*shpnt
)
2851 printk(ERR_LEAD
"parity error\n", CMDINFO(CURRENT_SC
));
2852 done(shpnt
, DID_PARITY
<< 16);
2859 static void rsti_run(struct Scsi_Host
*shpnt
)
2863 printk(KERN_NOTICE
"aha152x%d: scsi reset in\n", HOSTNO
);
2865 ptr
=DISCONNECTED_SC
;
2867 Scsi_Cmnd
*next
= SCNEXT(ptr
);
2869 if (!ptr
->device
->soft_reset
) {
2870 remove_SC(&DISCONNECTED_SC
, ptr
);
2872 kfree(ptr
->host_scribble
);
2873 ptr
->host_scribble
=0;
2875 ptr
->result
= DID_RESET
<< 16;
2876 ptr
->scsi_done(ptr
);
2882 if(CURRENT_SC
&& !CURRENT_SC
->device
->soft_reset
)
2883 done(shpnt
, DID_RESET
<< 16 );
2888 * bottom-half handler
2891 static void complete(struct Scsi_Host
*shpnt
)
2894 unsigned long flags
;
2898 if(HOSTDATA(shpnt
)->in_intr
!=0)
2899 aha152x_error(shpnt
, "bottom-half already running!?");
2900 HOSTDATA(shpnt
)->in_intr
++;
2904 * loop while there are interrupt conditions pending
2908 unsigned long start
= jiffies
;
2909 dataphase
=update_state(shpnt
);
2911 DPRINTK(debug_phases
, LEAD
"start %s %s(%s)\n", CMDINFO(CURRENT_SC
), states
[STATE
].name
, states
[PREVSTATE
].name
, states
[LASTSTATE
].name
);
2914 * end previous state
2917 if(PREVSTATE
!=STATE
&& states
[PREVSTATE
].end
)
2918 states
[PREVSTATE
].end(shpnt
);
2921 * disable SPIO mode if previous phase used it
2922 * and this one doesn't
2925 if(states
[PREVSTATE
].spio
&& !states
[STATE
].spio
) {
2926 SETPORT(SXFRCTL0
, CH1
);
2927 SETPORT(DMACNTRL0
, 0);
2929 CURRENT_SC
->SCp
.phase
&= ~spiordy
;
2933 * accept current dataphase phase
2937 SETPORT(SSTAT0
, REQINIT
);
2938 SETPORT(SCSISIG
, GETPORT(SCSISIG
) & P_MASK
);
2939 SETPORT(SSTAT1
, PHASECHG
);
2943 * enable SPIO mode if previous didn't use it
2947 if(!states
[PREVSTATE
].spio
&& states
[STATE
].spio
) {
2948 SETPORT(DMACNTRL0
, 0);
2949 SETPORT(SXFRCTL0
, CH1
|SPIOEN
);
2951 CURRENT_SC
->SCp
.phase
|= spiordy
;
2955 * initialize for new state
2958 if(PREVSTATE
!=STATE
&& states
[STATE
].init
)
2959 states
[STATE
].init(shpnt
);
2962 * handle current state
2965 if(states
[STATE
].run
)
2966 states
[STATE
].run(shpnt
);
2968 printk(ERR_LEAD
"unexpected state (%x)\n", CMDINFO(CURRENT_SC
), STATE
);
2971 * setup controller to interrupt on
2972 * the next expected condition and
2973 * loop if it's already there
2977 pending
=setup_expected_interrupts(shpnt
);
2978 #if defined(AHA152X_STAT)
2979 HOSTDATA(shpnt
)->count
[STATE
]++;
2980 if(PREVSTATE
!=STATE
)
2981 HOSTDATA(shpnt
)->count_trans
[STATE
]++;
2982 HOSTDATA(shpnt
)->time
[STATE
] += jiffies
-start
;
2986 DPRINTK(debug_phases
, LEAD
"end %s %s(%s)\n", CMDINFO(CURRENT_SC
), states
[STATE
].name
, states
[PREVSTATE
].name
, states
[LASTSTATE
].name
);
2990 * enable interrupts and leave bottom-half
2994 HOSTDATA(shpnt
)->in_intr
--;
2995 SETBITS(DMACNTRL0
, INTEN
);
3001 * Dump the current driver status and panic
3003 static void aha152x_error(struct Scsi_Host
*shpnt
, char *msg
)
3005 printk(KERN_EMERG
"\naha152x%d: %s\n", HOSTNO
, msg
);
3007 panic("aha152x panic\n");
3011 * Display registers of AIC-6260
3013 static void disp_ports(struct Scsi_Host
*shpnt
)
3015 #if defined(AHA152X_DEBUG)
3018 printk("\n%s: %s(%s) ",
3019 CURRENT_SC
? "busy" : "waiting",
3021 states
[PREVSTATE
].name
);
3023 s
= GETPORT(SCSISEQ
);
3024 printk("SCSISEQ( ");
3026 printk("TARGET MODE ");
3034 printk("AUTOATNO ");
3036 printk("AUTOATNI ");
3038 printk("AUTOATNP ");
3040 printk("SCSIRSTO ");
3043 printk(" SCSISIG(");
3044 s
= GETPORT(SCSISIG
);
3045 switch (s
& P_MASK
) {
3059 printk("MESSAGE OUT");
3062 printk("MESSAGE IN");
3065 printk("*illegal*");
3071 printk("INTSTAT (%s); ", TESTHI(DMASTAT
, INTSTAT
) ? "hi" : "lo");
3074 s
= GETPORT(SSTAT0
);
3092 s
= GETPORT(SSTAT1
);
3098 printk("SCSIRSTI ");
3100 printk("PHASEMIS ");
3104 printk("SCSIPERR ");
3106 printk("PHASECHG ");
3114 s
= GETPORT(SSTAT0
) & GETPORT(SIMODE0
);
3133 s
= GETPORT(SSTAT1
) & GETPORT(SIMODE1
);
3140 printk("SCSIRSTI ");
3142 printk("PHASEMIS ");
3146 printk("SCSIPERR ");
3148 printk("PHASECHG ");
3153 printk("SXFRCTL0( ");
3155 s
= GETPORT(SXFRCTL0
);
3163 printk("CLRSTCNT ");
3172 s
= GETPORT(SCSISIG
);
3185 printk("SELID (%02x), ", GETPORT(SELID
));
3187 printk("STCNT (%d), ", GETSTCNT());
3191 s
= GETPORT(SSTAT2
);
3198 printk("); SFCNT (%d); ", s
& (SFULL
| SFCNT
));
3200 s
= GETPORT(SSTAT3
);
3201 printk("SCSICNT (%d), OFFCNT(%d), ", (s
& 0xf0) >> 4, s
& 0x0f);
3204 s
= GETPORT(SSTAT4
);
3213 printk("DMACNTRL0( ");
3214 s
= GETPORT(DMACNTRL0
);
3215 printk("%s ", s
& _8BIT
? "8BIT" : "16BIT");
3216 printk("%s ", s
& DMA
? "DMA" : "PIO");
3217 printk("%s ", s
& WRITE_READ
? "WRITE" : "READ");
3228 printk("DMASTAT( ");
3229 s
= GETPORT(DMASTAT
);
3235 printk("DFIFOFULL ");
3237 printk("DFIFOEMP ");
3243 * display enabled interrupts
3245 static void disp_enintr(struct Scsi_Host
*shpnt
)
3249 printk(KERN_DEBUG
"enabled interrupts ( ");
3251 s
= GETPORT(SIMODE0
);
3257 printk("ENSELINGO ");
3263 printk("ENSPIORDY ");
3265 printk("ENDMADONE ");
3267 s
= GETPORT(SIMODE1
);
3269 printk("ENSELTIMO ");
3271 printk("ENATNTARG ");
3273 printk("ENPHASEMIS ");
3275 printk("ENBUSFREE ");
3277 printk("ENSCSIPERR ");
3279 printk("ENPHASECHG ");
3281 printk("ENREQINIT ");
3286 * Show the command data of a command
3288 static void show_command(Scsi_Cmnd
*ptr
)
3290 printk(KERN_DEBUG
"0x%08x: target=%d; lun=%d; cmnd=(",
3291 (unsigned int) ptr
, ptr
->target
, ptr
->lun
);
3293 print_command(ptr
->cmnd
);
3295 printk(KERN_DEBUG
"); request_bufflen=%d; resid=%d; phase |",
3296 ptr
->request_bufflen
, ptr
->resid
);
3298 if (ptr
->SCp
.phase
& not_issued
)
3299 printk("not issued|");
3300 if (ptr
->SCp
.phase
& selecting
)
3301 printk("selecting|");
3302 if (ptr
->SCp
.phase
& identified
)
3303 printk("identified|");
3304 if (ptr
->SCp
.phase
& disconnected
)
3305 printk("disconnected|");
3306 if (ptr
->SCp
.phase
& completed
)
3307 printk("completed|");
3308 if (ptr
->SCp
.phase
& spiordy
)
3310 if (ptr
->SCp
.phase
& syncneg
)
3312 if (ptr
->SCp
.phase
& aborted
)
3314 if (ptr
->SCp
.phase
& resetted
)
3315 printk("resetted|");
3316 printk("; next=0x%p\n", SCNEXT(ptr
));
3320 * Dump the queued data
3322 static void show_queues(struct Scsi_Host
*shpnt
)
3325 unsigned long flags
;
3328 printk(KERN_DEBUG
"\nqueue status:\nissue_SC:\n");
3329 for (ptr
= ISSUE_SC
; ptr
; ptr
= SCNEXT(ptr
))
3333 printk(KERN_DEBUG
"current_SC:\n");
3335 show_command(CURRENT_SC
);
3337 printk(KERN_DEBUG
"none\n");
3339 printk(KERN_DEBUG
"disconnected_SC:\n");
3340 for (ptr
= DISCONNECTED_SC
; ptr
; ptr
= SCNEXT(ptr
))
3348 #define SPRINTF(args...) pos += sprintf(pos, ## args)
3350 static int get_command(char *pos
, Scsi_Cmnd
* ptr
)
3355 SPRINTF("0x%08x: target=%d; lun=%d; cmnd=( ",
3356 (unsigned int) ptr
, ptr
->target
, ptr
->lun
);
3358 for (i
= 0; i
< COMMAND_SIZE(ptr
->cmnd
[0]); i
++)
3359 SPRINTF("0x%02x ", ptr
->cmnd
[i
]);
3361 SPRINTF("); resid=%d; residual=%d; buffers=%d; phase |",
3362 ptr
->resid
, ptr
->SCp
.this_residual
, ptr
->SCp
.buffers_residual
);
3364 if (ptr
->SCp
.phase
& not_issued
)
3365 SPRINTF("not issued|");
3366 if (ptr
->SCp
.phase
& selecting
)
3367 SPRINTF("selecting|");
3368 if (ptr
->SCp
.phase
& disconnected
)
3369 SPRINTF("disconnected|");
3370 if (ptr
->SCp
.phase
& aborted
)
3371 SPRINTF("aborted|");
3372 if (ptr
->SCp
.phase
& identified
)
3373 SPRINTF("identified|");
3374 if (ptr
->SCp
.phase
& completed
)
3375 SPRINTF("completed|");
3376 if (ptr
->SCp
.phase
& spiordy
)
3377 SPRINTF("spiordy|");
3378 if (ptr
->SCp
.phase
& syncneg
)
3379 SPRINTF("syncneg|");
3380 SPRINTF("; next=0x%p\n", SCNEXT(ptr
));
3382 return (pos
- start
);
3385 static int get_ports(struct Scsi_Host
*shpnt
, char *pos
)
3390 SPRINTF("\n%s: %s(%s) ", CURRENT_SC
? "on bus" : "waiting", states
[STATE
].name
, states
[PREVSTATE
].name
);
3392 s
= GETPORT(SCSISEQ
);
3393 SPRINTF("SCSISEQ( ");
3395 SPRINTF("TARGET MODE ");
3403 SPRINTF("AUTOATNO ");
3405 SPRINTF("AUTOATNI ");
3407 SPRINTF("AUTOATNP ");
3409 SPRINTF("SCSIRSTO ");
3412 SPRINTF(" SCSISIG(");
3413 s
= GETPORT(SCSISIG
);
3414 switch (s
& P_MASK
) {
3416 SPRINTF("DATA OUT");
3428 SPRINTF("MESSAGE OUT");
3431 SPRINTF("MESSAGE IN");
3434 SPRINTF("*illegal*");
3440 SPRINTF("INTSTAT (%s); ", TESTHI(DMASTAT
, INTSTAT
) ? "hi" : "lo");
3443 s
= GETPORT(SSTAT0
);
3451 SPRINTF("SELINGO ");
3457 SPRINTF("SPIORDY ");
3459 SPRINTF("DMADONE ");
3461 s
= GETPORT(SSTAT1
);
3465 SPRINTF("ATNTARG ");
3467 SPRINTF("SCSIRSTI ");
3469 SPRINTF("PHASEMIS ");
3471 SPRINTF("BUSFREE ");
3473 SPRINTF("SCSIPERR ");
3475 SPRINTF("PHASECHG ");
3477 SPRINTF("REQINIT ");
3483 s
= GETPORT(SSTAT0
) & GETPORT(SIMODE0
);
3492 SPRINTF("SELINGO ");
3498 SPRINTF("SPIORDY ");
3500 SPRINTF("DMADONE ");
3502 s
= GETPORT(SSTAT1
) & GETPORT(SIMODE1
);
3507 SPRINTF("ATNTARG ");
3509 SPRINTF("SCSIRSTI ");
3511 SPRINTF("PHASEMIS ");
3513 SPRINTF("BUSFREE ");
3515 SPRINTF("SCSIPERR ");
3517 SPRINTF("PHASECHG ");
3519 SPRINTF("REQINIT ");
3522 SPRINTF("SXFRCTL0( ");
3524 s
= GETPORT(SXFRCTL0
);
3532 SPRINTF("CLRSTCNT ");
3539 SPRINTF("SIGNAL( ");
3541 s
= GETPORT(SCSISIG
);
3554 SPRINTF("SELID(%02x), ", GETPORT(SELID
));
3556 SPRINTF("STCNT(%d), ", GETSTCNT());
3558 SPRINTF("SSTAT2( ");
3560 s
= GETPORT(SSTAT2
);
3562 SPRINTF("SOFFSET ");
3567 SPRINTF("); SFCNT (%d); ", s
& (SFULL
| SFCNT
));
3569 s
= GETPORT(SSTAT3
);
3570 SPRINTF("SCSICNT (%d), OFFCNT(%d), ", (s
& 0xf0) >> 4, s
& 0x0f);
3572 SPRINTF("SSTAT4( ");
3573 s
= GETPORT(SSTAT4
);
3575 SPRINTF("SYNCERR ");
3582 SPRINTF("DMACNTRL0( ");
3583 s
= GETPORT(DMACNTRL0
);
3584 SPRINTF("%s ", s
& _8BIT
? "8BIT" : "16BIT");
3585 SPRINTF("%s ", s
& DMA
? "DMA" : "PIO");
3586 SPRINTF("%s ", s
& WRITE_READ
? "WRITE" : "READ");
3592 SPRINTF("RSTFIFO ");
3597 SPRINTF("DMASTAT( ");
3598 s
= GETPORT(DMASTAT
);
3602 SPRINTF("WORDRDY ");
3604 SPRINTF("DFIFOFULL ");
3606 SPRINTF("DFIFOEMP ");
3609 SPRINTF("enabled interrupts( ");
3611 s
= GETPORT(SIMODE0
);
3613 SPRINTF("ENSELDO ");
3615 SPRINTF("ENSELDI ");
3617 SPRINTF("ENSELINGO ");
3619 SPRINTF("ENSWRAP ");
3621 SPRINTF("ENSDONE ");
3623 SPRINTF("ENSPIORDY ");
3625 SPRINTF("ENDMADONE ");
3627 s
= GETPORT(SIMODE1
);
3629 SPRINTF("ENSELTIMO ");
3631 SPRINTF("ENATNTARG ");
3633 SPRINTF("ENPHASEMIS ");
3635 SPRINTF("ENBUSFREE ");
3637 SPRINTF("ENSCSIPERR ");
3639 SPRINTF("ENPHASECHG ");
3641 SPRINTF("ENREQINIT ");
3644 return (pos
- start
);
3647 int aha152x_set_info(char *buffer
, int length
, struct Scsi_Host
*shpnt
)
3649 if(!shpnt
|| !buffer
|| length
<8 || strncmp("aha152x ", buffer
, 8)!=0)
3652 #if defined(AHA152X_DEBUG)
3653 if(length
>14 && strncmp("debug ", buffer
+8, 6)==0) {
3654 int debug
= HOSTDATA(shpnt
)->debug
;
3656 HOSTDATA(shpnt
)->debug
= simple_strtoul(buffer
+14, NULL
, 0);
3658 printk(KERN_INFO
"aha152x%d: debugging options set to 0x%04x (were 0x%04x)\n", HOSTNO
, HOSTDATA(shpnt
)->debug
, debug
);
3661 #if defined(AHA152X_STAT)
3662 if(length
>13 && strncmp("reset", buffer
+8, 5)==0) {
3665 HOSTDATA(shpnt
)->total_commands
=0;
3666 HOSTDATA(shpnt
)->disconnections
=0;
3667 HOSTDATA(shpnt
)->busfree_without_any_action
=0;
3668 HOSTDATA(shpnt
)->busfree_without_old_command
=0;
3669 HOSTDATA(shpnt
)->busfree_without_new_command
=0;
3670 HOSTDATA(shpnt
)->busfree_without_done_command
=0;
3671 HOSTDATA(shpnt
)->busfree_with_check_condition
=0;
3672 for (i
= idle
; i
<maxstate
; i
++) {
3673 HOSTDATA(shpnt
)->count
[i
]=0;
3674 HOSTDATA(shpnt
)->count_trans
[i
]=0;
3675 HOSTDATA(shpnt
)->time
[i
]=0;
3678 printk(KERN_INFO
"aha152x%d: stats reseted.\n", HOSTNO
);
3691 #define SPRINTF(args...) \
3692 do { if(pos < buffer + length) pos += sprintf(pos, ## args); } while(0)
3694 int aha152x_proc_info(char *buffer
, char **start
,
3695 off_t offset
, int length
, int hostno
, int inout
)
3699 struct Scsi_Host
*shpnt
;
3701 unsigned long flags
;
3704 for (i
= 0, shpnt
= (struct Scsi_Host
*) NULL
; i
< IRQS
; i
++)
3705 if (aha152x_host
[i
] && aha152x_host
[i
]->host_no
== hostno
)
3706 shpnt
= aha152x_host
[i
];
3711 DPRINTK(debug_procinfo
,
3712 KERN_DEBUG
"aha152x_proc_info: buffer=%p offset=%ld length=%d hostno=%d inout=%d\n",
3713 buffer
, offset
, length
, hostno
, inout
);
3717 return aha152x_set_info(buffer
, length
, shpnt
);
3719 SPRINTF(AHA152X_REVID
"\n");
3721 SPRINTF("ioports 0x%04lx to 0x%04lx\n",
3722 shpnt
->io_port
, shpnt
->io_port
+ shpnt
->n_io_port
- 1);
3723 SPRINTF("interrupt 0x%02x\n", shpnt
->irq
);
3724 SPRINTF("disconnection/reconnection %s\n",
3725 RECONNECT
? "enabled" : "disabled");
3726 SPRINTF("parity checking %s\n",
3727 PARITY
? "enabled" : "disabled");
3728 SPRINTF("synchronous transfers %s\n",
3729 SYNCHRONOUS
? "enabled" : "disabled");
3730 SPRINTF("%d commands currently queued\n", HOSTDATA(shpnt
)->commands
);
3733 SPRINTF("synchronously operating targets (tick=50 ns):\n");
3734 for (i
= 0; i
< 8; i
++)
3735 if (HOSTDATA(shpnt
)->syncrate
[i
] & 0x7f)
3736 SPRINTF("target %d: period %dT/%dns; req/ack offset %d\n",
3738 (((HOSTDATA(shpnt
)->syncrate
[i
] & 0x70) >> 4) + 2),
3739 (((HOSTDATA(shpnt
)->syncrate
[i
] & 0x70) >> 4) + 2) * 50,
3740 HOSTDATA(shpnt
)->syncrate
[i
] & 0x0f);
3742 #if defined(AHA152X_DEBUG)
3743 #define PDEBUG(flags,txt) \
3744 if(HOSTDATA(shpnt)->debug & flags) SPRINTF("(%s) ", txt);
3746 SPRINTF("enabled debugging options: ");
3748 PDEBUG(debug_procinfo
, "procinfo");
3749 PDEBUG(debug_queue
, "queue");
3750 PDEBUG(debug_intr
, "interrupt");
3751 PDEBUG(debug_selection
, "selection");
3752 PDEBUG(debug_msgo
, "message out");
3753 PDEBUG(debug_msgi
, "message in");
3754 PDEBUG(debug_status
, "status");
3755 PDEBUG(debug_cmd
, "command");
3756 PDEBUG(debug_datai
, "data in");
3757 PDEBUG(debug_datao
, "data out");
3758 PDEBUG(debug_eh
, "eh");
3759 PDEBUG(debug_locks
, "locks");
3760 PDEBUG(debug_phases
, "phases");
3765 SPRINTF("\nqueue status:\n");
3768 SPRINTF("not yet issued commands:\n");
3769 for (ptr
= ISSUE_SC
; ptr
; ptr
= SCNEXT(ptr
))
3770 pos
+= get_command(pos
, ptr
);
3772 SPRINTF("no not yet issued commands\n");
3776 SPRINTF("current command:\n");
3777 pos
+= get_command(pos
, CURRENT_SC
);
3779 SPRINTF("no current command\n");
3781 if (DISCONNECTED_SC
) {
3782 SPRINTF("disconnected commands:\n");
3783 for (ptr
= DISCONNECTED_SC
; ptr
; ptr
= SCNEXT(ptr
))
3784 pos
+= get_command(pos
, ptr
);
3786 SPRINTF("no disconnected commands\n");
3788 pos
+= get_ports(shpnt
, pos
);
3790 #if defined(AHA152X_STAT)
3791 SPRINTF("statistics:\n"
3792 "total commands: %d\n"
3793 "disconnections: %d\n"
3794 "busfree with check condition: %d\n"
3795 "busfree without old command: %d\n"
3796 "busfree without new command: %d\n"
3797 "busfree without done command: %d\n"
3798 "busfree without any action: %d\n"
3803 HOSTDATA(shpnt
)->total_commands
,
3804 HOSTDATA(shpnt
)->disconnections
,
3805 HOSTDATA(shpnt
)->busfree_with_check_condition
,
3806 HOSTDATA(shpnt
)->busfree_without_old_command
,
3807 HOSTDATA(shpnt
)->busfree_without_new_command
,
3808 HOSTDATA(shpnt
)->busfree_without_done_command
,
3809 HOSTDATA(shpnt
)->busfree_without_any_action
);
3810 for(i
=0; i
<maxstate
; i
++) {
3811 SPRINTF("%-10s %-12d %-12d %-12ld\n",
3813 HOSTDATA(shpnt
)->count_trans
[i
],
3814 HOSTDATA(shpnt
)->count
[i
],
3815 HOSTDATA(shpnt
)->time
[i
]);
3819 DPRINTK(debug_procinfo
, KERN_DEBUG
"aha152x_proc_info: pos=%p\n", pos
);
3821 thislength
= pos
- (buffer
+ offset
);
3822 DPRINTK(debug_procinfo
, KERN_DEBUG
"aha152x_proc_info: length=%d thislength=%d\n", length
, thislength
);
3825 DPRINTK(debug_procinfo
, KERN_DEBUG
"aha152x_proc_info: output too short\n");
3830 thislength
= thislength
<length
? thislength
: length
;
3832 DPRINTK(debug_procinfo
, KERN_DEBUG
"aha152x_proc_info: return %d\n", thislength
);
3834 *start
= buffer
+ offset
;
3835 return thislength
< length
? thislength
: length
;
3838 /* Eventually this will go into an include file, but this will be later */
3839 static Scsi_Host_Template driver_template
= AHA152X
;
3841 #include "scsi_module.c"