1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /* aha152x.c -- Adaptec AHA-152x driver
3 * Author: Jürgen E. Fischer, fischer@norbit.de
4 * Copyright 1993-2004 Jürgen E. Fischer
6 * $Id: aha152x.c,v 2.7 2004/01/24 11:42:59 fischer Exp $
9 * Revision 2.7 2004/01/24 11:42:59 fischer
10 * - gather code that is not used by PCMCIA at the end
11 * - move request_region for !PCMCIA case to detection
12 * - migration to new scsi host api (remove legacy code)
13 * - free host scribble before scsi_done
14 * - fix error handling
15 * - one isapnp device added to id_table
17 * Revision 2.6 2003/10/30 20:52:47 fischer
18 * - interfaces changes for kernel 2.6
19 * - aha152x_probe_one introduced for pcmcia stub
20 * - fixed pnpdev handling
21 * - instead of allocation a new one, reuse command for request sense after check condition and reset
22 * - fixes race in is_complete
24 * Revision 2.5 2002/04/14 11:24:53 fischer
29 * Revision 2.4 2000/12/16 12:53:56 fischer
30 * - allow REQUEST SENSE to be queued
31 * - handle shared PCI interrupts
33 * Revision 2.3 2000/11/04 16:40:26 fischer
34 * - handle data overruns
35 * - extend timeout for data phases
37 * Revision 2.2 2000/08/08 19:54:53 fischer
40 * Revision 2.1 2000/05/17 16:23:17 fischer
42 * - fix for data out w/o scatter gather
44 * Revision 2.0 1999/12/25 15:07:32 fischer
45 * - interrupt routine completly reworked
46 * - basic support for new eh code
48 * Revision 1.21 1999/11/10 23:46:36 fischer
49 * - default to synchronous operation
50 * - synchronous negotiation fixed
51 * - added timeout to loops
52 * - debugging output can be controlled through procfs
54 * Revision 1.20 1999/11/07 18:37:31 fischer
55 * - synchronous operation works
56 * - resid support for sg driver
58 * Revision 1.19 1999/11/02 22:39:59 fischer
59 * - moved leading comments to README.aha152x
60 * - new additional module parameters
62 * - support for the Tripace TC1550 controller
63 * - interrupt handling changed
65 * Revision 1.18 1996/09/07 20:10:40 fischer
66 * - fixed can_queue handling (multiple outstanding commands working again)
68 * Revision 1.17 1996/08/17 16:05:14 fischer
69 * - biosparam improved
70 * - interrupt verification
71 * - updated documentation
74 * Revision 1.16 1996/06/09 00:04:56 root
75 * - added configuration symbols for insmod (aha152x/aha152x1)
77 * Revision 1.15 1996/04/30 14:52:06 fischer
79 * - support for extended translation for >1GB disks
81 * Revision 1.14 1996/01/17 15:11:20 fischer
82 * - fixed lockup in MESSAGE IN phase after reconnection
84 * Revision 1.13 1996/01/09 02:15:53 fischer
86 * - moved request_irq behind controller initialization
87 * (to avoid spurious interrupts)
89 * Revision 1.12 1995/12/16 12:26:07 fischer
91 * - configurable RESET delay added
93 * Revision 1.11 1995/12/06 21:18:35 fischer
94 * - some minor updates
96 * Revision 1.10 1995/07/22 19:18:45 fischer
97 * - support for 2 controllers
98 * - started synchronous data transfers (not working yet)
100 * Revision 1.9 1995/03/18 09:20:24 root
101 * - patches for PCMCIA and modules
103 * Revision 1.8 1995/01/21 22:07:19 root
104 * - snarf_region => request_region
105 * - aha152x_intr interface change
107 * Revision 1.7 1995/01/02 23:19:36 root
108 * - updated COMMAND_SIZE to cmd_len
109 * - changed sti() to restore_flags()
110 * - fixed some #ifdef which generated warnings
112 * Revision 1.6 1994/11/24 20:35:27 root
113 * - problem with odd number of bytes in fifo fixed
115 * Revision 1.5 1994/10/30 14:39:56 root
117 * - debugging improved
119 * Revision 1.4 1994/09/12 11:33:01 root
120 * - irqaction to request_irq
123 * Revision 1.3 1994/08/04 13:53:05 root
124 * - updates for mid-level-driver changes
125 * - accept unexpected BUSFREE phase as error condition
126 * - parity check now configurable
128 * Revision 1.2 1994/07/03 12:56:36 root
129 * - cleaned up debugging code
130 * - more tweaking on reset delays
131 * - updated abort/reset code (pretty untested...)
133 * Revision 1.1 1994/05/28 21:18:49 root
134 * - update for mid-level interface change (abort-reset)
135 * - delays after resets adjusted for some slow devices
137 * Revision 1.0 1994/03/25 12:52:00 root
138 * - Fixed "more data than expected" problem
139 * - added new BIOS signatures
141 * Revision 0.102 1994/01/31 20:44:12 root
142 * - minor changes in insw/outsw handling
144 * Revision 0.101 1993/12/13 01:16:27 root
145 * - fixed STATUS phase (non-GOOD stati were dropped sometimes;
146 * fixes problems with CD-ROM sector size detection & media change)
148 * Revision 0.100 1993/12/10 16:58:47 root
149 * - fix for unsuccessful selections in case of non-continuous id assignments
152 * Revision 0.99 1993/10/24 16:19:59 root
153 * - fixed DATA IN (rare read errors gone)
155 * Revision 0.98 1993/10/17 12:54:44 root
156 * - fixed some recent fixes (shame on me)
157 * - moved initialization of scratch area to aha152x_queue
159 * Revision 0.97 1993/10/09 18:53:53 root
160 * - DATA IN fixed. Rarely left data in the fifo.
162 * Revision 0.96 1993/10/03 00:53:59 root
163 * - minor changes on DATA IN
165 * Revision 0.95 1993/09/24 10:36:01 root
166 * - change handling of MSGI after reselection
170 * Revision 0.94 1993/09/18 14:08:22 root
171 * - fixed bug in multiple outstanding command code
172 * - changed detection
173 * - support for kernel command line configuration
175 * - changed message handling
177 * Revision 0.93 1993/09/15 20:41:19 root
178 * - fixed bugs with multiple outstanding commands
180 * Revision 0.92 1993/09/13 02:46:33 root
181 * - multiple outstanding commands work (no problems with IBM drive)
183 * Revision 0.91 1993/09/12 20:51:46 root
184 * added multiple outstanding commands
185 * (some problem with this $%&? IBM device remain)
187 * Revision 0.9 1993/09/12 11:11:22 root
188 * - corrected auto-configuration
189 * - changed the auto-configuration (added some '#define's)
190 * - added support for dis-/reconnection
192 * Revision 0.8 1993/09/06 23:09:39 root
193 * - added support for the drive activity light
196 * Revision 0.7 1993/09/05 14:30:15 root
197 * - improved phase detection
198 * - now using the new snarf_region code of 0.99pl13
200 * Revision 0.6 1993/09/02 11:01:38 root
201 * first public release; added some signatures and biosparam()
203 * Revision 0.5 1993/08/30 10:23:30 root
204 * fixed timing problems with my IBM drive
206 * Revision 0.4 1993/08/29 14:06:52 root
207 * fixed some problems with timeouts due incomplete commands
209 * Revision 0.3 1993/08/28 15:55:03 root
210 * writing data works too. mounted and worked on a dos partition
212 * Revision 0.2 1993/08/27 22:42:07 root
213 * reading data works. Mounted a msdos partition.
215 * Revision 0.1 1993/08/25 13:38:30 root
216 * first "damn thing doesn't work" version
218 * Revision 0.0 1993/08/14 19:54:25 root
219 * empty function bodies; detect() works.
221 **************************************************************************
223 see Documentation/scsi/aha152x.rst for configuration details
225 **************************************************************************/
227 #include <linux/module.h>
229 #include <linux/io.h>
230 #include <linux/blkdev.h>
231 #include <linux/completion.h>
232 #include <linux/errno.h>
233 #include <linux/string.h>
234 #include <linux/wait.h>
235 #include <linux/ioport.h>
236 #include <linux/delay.h>
237 #include <linux/proc_fs.h>
238 #include <linux/interrupt.h>
239 #include <linux/init.h>
240 #include <linux/kernel.h>
241 #include <linux/isapnp.h>
242 #include <linux/spinlock.h>
243 #include <linux/workqueue.h>
244 #include <linux/list.h>
245 #include <linux/slab.h>
247 #include <scsi/scsi.h>
248 #include <scsi/scsi_cmnd.h>
249 #include <scsi/scsi_dbg.h>
250 #include <scsi/scsi_device.h>
251 #include <scsi/scsi_eh.h>
252 #include <scsi/scsi_host.h>
253 #include <scsi/scsi_tcq.h>
254 #include <scsi/scsi_transport_spi.h>
255 #include <scsi/scsicam.h>
258 static LIST_HEAD(aha152x_host_list);
263 /* For PCMCIA cards, always use AUTOCONF */
264 #if defined(AHA152X_PCMCIA) || defined(MODULE)
265 #if !defined(AUTOCONF)
270 #if !defined(AUTOCONF) && !defined(SETUP0)
271 #error define AUTOCONF or SETUP0
274 #define DO_LOCK(flags) spin_lock_irqsave(&QLOCK,flags)
275 #define DO_UNLOCK(flags) spin_unlock_irqrestore(&QLOCK,flags)
277 #define LEAD "(scsi%d:%d:%d) "
278 #define INFO_LEAD KERN_INFO LEAD
279 #define CMDINFO(cmd) \
280 (cmd) ? ((cmd)->device->host->host_no) : -1, \
281 (cmd) ? ((cmd)->device->id & 0x0f) : -1, \
282 (cmd) ? ((u8)(cmd)->device->lun & 0x07) : -1
285 CMD_INC_RESID(struct scsi_cmnd *cmd, int inc)
287 scsi_set_resid(cmd, scsi_get_resid(cmd) + inc);
290 #define DELAY_DEFAULT 1000
292 #if defined(AHA152X_PCMCIA)
298 #define IRQ_MAX (nr_irqs-1)
305 not_issued = 0x0001, /* command not yet issued */
306 selecting = 0x0002, /* target is being selected */
307 identified = 0x0004, /* IDENTIFY was sent */
308 disconnected = 0x0008, /* target disconnected */
309 completed = 0x0010, /* target sent COMMAND COMPLETE */
310 aborted = 0x0020, /* ABORT was sent */
311 resetted = 0x0040, /* BUS DEVICE RESET was sent */
312 spiordy = 0x0080, /* waiting for SPIORDY to raise */
313 syncneg = 0x0100, /* synchronous negotiation in progress */
314 aborting = 0x0200, /* ABORT is pending */
315 resetting = 0x0400, /* BUS DEVICE RESET is pending */
316 check_condition = 0x0800, /* requesting sense after CHECK CONDITION */
319 struct aha152x_cmd_priv {
320 struct scsi_pointer scsi_pointer;
323 static struct scsi_pointer *aha152x_scsi_pointer(struct scsi_cmnd *cmd)
325 struct aha152x_cmd_priv *acmd = scsi_cmd_priv(cmd);
327 return &acmd->scsi_pointer;
330 MODULE_AUTHOR("Jürgen Fischer");
331 MODULE_DESCRIPTION(AHA152X_REVID);
332 MODULE_LICENSE("GPL");
334 #if !defined(AHA152X_PCMCIA)
336 static int io[] = {0, 0};
337 module_param_hw_array(io, int, ioport, NULL, 0);
338 MODULE_PARM_DESC(io,"base io address of controller");
340 static int irq[] = {0, 0};
341 module_param_hw_array(irq, int, irq, NULL, 0);
342 MODULE_PARM_DESC(irq,"interrupt for controller");
344 static int scsiid[] = {7, 7};
345 module_param_array(scsiid, int, NULL, 0);
346 MODULE_PARM_DESC(scsiid,"scsi id of controller");
348 static int reconnect[] = {1, 1};
349 module_param_array(reconnect, int, NULL, 0);
350 MODULE_PARM_DESC(reconnect,"allow targets to disconnect");
352 static int parity[] = {1, 1};
353 module_param_array(parity, int, NULL, 0);
354 MODULE_PARM_DESC(parity,"use scsi parity");
356 static int sync[] = {1, 1};
357 module_param_array(sync, int, NULL, 0);
358 MODULE_PARM_DESC(sync,"use synchronous transfers");
360 static int delay[] = {DELAY_DEFAULT, DELAY_DEFAULT};
361 module_param_array(delay, int, NULL, 0);
362 MODULE_PARM_DESC(delay,"scsi reset delay");
364 static int exttrans[] = {0, 0};
365 module_param_array(exttrans, int, NULL, 0);
366 MODULE_PARM_DESC(exttrans,"use extended translation");
368 static int aha152x[] = {0, 11, 7, 1, 1, 0, DELAY_DEFAULT, 0};
369 module_param_array(aha152x, int, NULL, 0);
370 MODULE_PARM_DESC(aha152x, "parameters for first controller");
372 static int aha152x1[] = {0, 11, 7, 1, 1, 0, DELAY_DEFAULT, 0};
373 module_param_array(aha152x1, int, NULL, 0);
374 MODULE_PARM_DESC(aha152x1, "parameters for second controller");
378 static struct isapnp_device_id id_table[] = {
379 { ISAPNP_ANY_ID, ISAPNP_ANY_ID, ISAPNP_VENDOR('A', 'D', 'P'), ISAPNP_FUNCTION(0x1502), 0 },
380 { ISAPNP_ANY_ID, ISAPNP_ANY_ID, ISAPNP_VENDOR('A', 'D', 'P'), ISAPNP_FUNCTION(0x1505), 0 },
381 { ISAPNP_ANY_ID, ISAPNP_ANY_ID, ISAPNP_VENDOR('A', 'D', 'P'), ISAPNP_FUNCTION(0x1510), 0 },
382 { ISAPNP_ANY_ID, ISAPNP_ANY_ID, ISAPNP_VENDOR('A', 'D', 'P'), ISAPNP_FUNCTION(0x1515), 0 },
383 { ISAPNP_ANY_ID, ISAPNP_ANY_ID, ISAPNP_VENDOR('A', 'D', 'P'), ISAPNP_FUNCTION(0x1520), 0 },
384 { ISAPNP_ANY_ID, ISAPNP_ANY_ID, ISAPNP_VENDOR('A', 'D', 'P'), ISAPNP_FUNCTION(0x2015), 0 },
385 { ISAPNP_ANY_ID, ISAPNP_ANY_ID, ISAPNP_VENDOR('A', 'D', 'P'), ISAPNP_FUNCTION(0x1522), 0 },
386 { ISAPNP_ANY_ID, ISAPNP_ANY_ID, ISAPNP_VENDOR('A', 'D', 'P'), ISAPNP_FUNCTION(0x2215), 0 },
387 { ISAPNP_ANY_ID, ISAPNP_ANY_ID, ISAPNP_VENDOR('A', 'D', 'P'), ISAPNP_FUNCTION(0x1530), 0 },
388 { ISAPNP_ANY_ID, ISAPNP_ANY_ID, ISAPNP_VENDOR('A', 'D', 'P'), ISAPNP_FUNCTION(0x3015), 0 },
389 { ISAPNP_ANY_ID, ISAPNP_ANY_ID, ISAPNP_VENDOR('A', 'D', 'P'), ISAPNP_FUNCTION(0x1532), 0 },
390 { ISAPNP_ANY_ID, ISAPNP_ANY_ID, ISAPNP_VENDOR('A', 'D', 'P'), ISAPNP_FUNCTION(0x3215), 0 },
391 { ISAPNP_ANY_ID, ISAPNP_ANY_ID, ISAPNP_VENDOR('A', 'D', 'P'), ISAPNP_FUNCTION(0x6360), 0 },
392 { ISAPNP_DEVICE_SINGLE_END, }
394 MODULE_DEVICE_TABLE(isapnp, id_table);
397 #endif /* !AHA152X_PCMCIA */
399 static struct scsi_host_template aha152x_driver_template;
402 * internal states of the host
424 * current state information of the host
427 struct aha152x_hostdata {
428 struct scsi_cmnd *issue_SC;
429 /* pending commands to issue */
431 struct scsi_cmnd *current_SC;
432 /* current command on the bus */
434 struct scsi_cmnd *disconnected_SC;
435 /* commands that disconnected */
437 struct scsi_cmnd *done_SC;
438 /* command that was completed */
443 #if defined(AHA152X_STAT)
446 int busfree_without_any_action;
447 int busfree_without_old_command;
448 int busfree_without_new_command;
449 int busfree_without_done_command;
450 int busfree_with_check_condition;
452 int count_trans[maxstate];
453 unsigned long time[maxstate];
456 int commands; /* current number of commands */
458 int reconnect; /* disconnection allowed */
459 int parity; /* parity checking enabled */
460 int synchronous; /* synchronous transferes enabled */
461 int delay; /* reset out delay */
462 int ext_trans; /* extended translation enabled */
464 int swint; /* software-interrupt was fired during detect() */
465 int service; /* bh needs to be run */
466 int in_intr; /* bh is running */
470 last state different from current state */
471 enum aha152x_state state, prevstate, laststate;
474 /* reconnecting target */
476 unsigned char syncrate[8];
477 /* current synchronous transfer agreements */
479 unsigned char syncneg[8];
480 /* 0: no negotiation;
481 * 1: negotiation in progress;
482 * 2: negotiation completed
486 /* number of sent bytes of current command */
489 /* number of received message bytes */
490 unsigned char msgi[256];
491 /* received message bytes */
493 int msgo_i, msgo_len;
494 /* number of sent bytes and length of current messages */
495 unsigned char msgo[256];
496 /* pending messages */
499 /* number of sent/received bytes in dataphase */
501 unsigned long io_port0;
502 unsigned long io_port1;
505 struct pnp_dev *pnpdev;
507 struct list_head host_list;
512 * host specific command extension
515 struct aha152x_scdata {
516 struct scsi_cmnd *next; /* next sc in queue */
517 struct completion *done;/* semaphore to block on */
518 struct scsi_eh_save ses;
521 /* access macros for hostdata */
523 #define HOSTDATA(shpnt) ((struct aha152x_hostdata *) &shpnt->hostdata)
525 #define HOSTNO ((shpnt)->host_no)
527 #define CURRENT_SC (HOSTDATA(shpnt)->current_SC)
528 #define DONE_SC (HOSTDATA(shpnt)->done_SC)
529 #define ISSUE_SC (HOSTDATA(shpnt)->issue_SC)
530 #define DISCONNECTED_SC (HOSTDATA(shpnt)->disconnected_SC)
531 #define QLOCK (HOSTDATA(shpnt)->lock)
532 #define QLOCKER (HOSTDATA(shpnt)->locker)
533 #define QLOCKERL (HOSTDATA(shpnt)->lockerl)
535 #define STATE (HOSTDATA(shpnt)->state)
536 #define PREVSTATE (HOSTDATA(shpnt)->prevstate)
537 #define LASTSTATE (HOSTDATA(shpnt)->laststate)
539 #define RECONN_TARGET (HOSTDATA(shpnt)->target)
541 #define CMD_I (HOSTDATA(shpnt)->cmd_i)
543 #define MSGO(i) (HOSTDATA(shpnt)->msgo[i])
544 #define MSGO_I (HOSTDATA(shpnt)->msgo_i)
545 #define MSGOLEN (HOSTDATA(shpnt)->msgo_len)
546 #define ADDMSGO(x) (MSGOLEN<256 ? (void)(MSGO(MSGOLEN++)=x) : aha152x_error(shpnt,"MSGO overflow"))
548 #define MSGI(i) (HOSTDATA(shpnt)->msgi[i])
549 #define MSGILEN (HOSTDATA(shpnt)->msgi_len)
550 #define ADDMSGI(x) (MSGILEN<256 ? (void)(MSGI(MSGILEN++)=x) : aha152x_error(shpnt,"MSGI overflow"))
552 #define DATA_LEN (HOSTDATA(shpnt)->data_len)
554 #define SYNCRATE (HOSTDATA(shpnt)->syncrate[CURRENT_SC->device->id])
555 #define SYNCNEG (HOSTDATA(shpnt)->syncneg[CURRENT_SC->device->id])
557 #define DELAY (HOSTDATA(shpnt)->delay)
558 #define EXT_TRANS (HOSTDATA(shpnt)->ext_trans)
559 #define TC1550 (HOSTDATA(shpnt)->tc1550)
560 #define RECONNECT (HOSTDATA(shpnt)->reconnect)
561 #define PARITY (HOSTDATA(shpnt)->parity)
562 #define SYNCHRONOUS (HOSTDATA(shpnt)->synchronous)
564 #define HOSTIOPORT0 (HOSTDATA(shpnt)->io_port0)
565 #define HOSTIOPORT1 (HOSTDATA(shpnt)->io_port1)
567 #define SCDATA(SCpnt) ((struct aha152x_scdata *) (SCpnt)->host_scribble)
568 #define SCNEXT(SCpnt) SCDATA(SCpnt)->next
569 #define SCSEM(SCpnt) SCDATA(SCpnt)->done
571 #define SG_ADDRESS(buffer) ((char *) sg_virt((buffer)))
574 static void seldi_run(struct Scsi_Host *shpnt);
575 static void seldo_run(struct Scsi_Host *shpnt);
576 static void selto_run(struct Scsi_Host *shpnt);
577 static void busfree_run(struct Scsi_Host *shpnt);
579 static void msgo_init(struct Scsi_Host *shpnt);
580 static void msgo_run(struct Scsi_Host *shpnt);
581 static void msgo_end(struct Scsi_Host *shpnt);
583 static void cmd_init(struct Scsi_Host *shpnt);
584 static void cmd_run(struct Scsi_Host *shpnt);
585 static void cmd_end(struct Scsi_Host *shpnt);
587 static void datai_init(struct Scsi_Host *shpnt);
588 static void datai_run(struct Scsi_Host *shpnt);
589 static void datai_end(struct Scsi_Host *shpnt);
591 static void datao_init(struct Scsi_Host *shpnt);
592 static void datao_run(struct Scsi_Host *shpnt);
593 static void datao_end(struct Scsi_Host *shpnt);
595 static void status_run(struct Scsi_Host *shpnt);
597 static void msgi_run(struct Scsi_Host *shpnt);
598 static void msgi_end(struct Scsi_Host *shpnt);
600 static void parerr_run(struct Scsi_Host *shpnt);
601 static void rsti_run(struct Scsi_Host *shpnt);
603 static void is_complete(struct Scsi_Host *shpnt);
611 void (*init)(struct Scsi_Host *);
612 void (*run)(struct Scsi_Host *);
613 void (*end)(struct Scsi_Host *);
616 { "idle", NULL, NULL, NULL, 0},
617 { "unknown", NULL, NULL, NULL, 0},
618 { "seldo", NULL, seldo_run, NULL, 0},
619 { "seldi", NULL, seldi_run, NULL, 0},
620 { "selto", NULL, selto_run, NULL, 0},
621 { "busfree", NULL, busfree_run, NULL, 0},
622 { "msgo", msgo_init, msgo_run, msgo_end, 1},
623 { "cmd", cmd_init, cmd_run, cmd_end, 1},
624 { "msgi", NULL, msgi_run, msgi_end, 1},
625 { "status", NULL, status_run, NULL, 1},
626 { "datai", datai_init, datai_run, datai_end, 0},
627 { "datao", datao_init, datao_run, datao_end, 0},
628 { "parerr", NULL, parerr_run, NULL, 0},
629 { "rsti", NULL, rsti_run, NULL, 0},
632 /* setup & interrupt */
633 static irqreturn_t intr(int irq, void *dev_id);
634 static void reset_ports(struct Scsi_Host *shpnt);
635 static void aha152x_error(struct Scsi_Host *shpnt, char *msg);
636 static void done(struct Scsi_Host *shpnt, unsigned char status_byte,
637 unsigned char host_byte);
640 static void show_command(struct scsi_cmnd * ptr);
641 static void show_queues(struct Scsi_Host *shpnt);
642 static void disp_enintr(struct Scsi_Host *shpnt);
649 static inline void append_SC(struct scsi_cmnd **SC, struct scsi_cmnd *new_SC)
651 struct scsi_cmnd *end;
653 SCNEXT(new_SC) = NULL;
657 for (end = *SC; SCNEXT(end); end = SCNEXT(end))
659 SCNEXT(end) = new_SC;
663 static inline struct scsi_cmnd *remove_first_SC(struct scsi_cmnd ** SC)
665 struct scsi_cmnd *ptr;
675 static inline struct scsi_cmnd *remove_lun_SC(struct scsi_cmnd ** SC,
678 struct scsi_cmnd *ptr, *prev;
680 for (ptr = *SC, prev = NULL;
681 ptr && ((ptr->device->id != target) || (ptr->device->lun != lun));
682 prev = ptr, ptr = SCNEXT(ptr))
687 SCNEXT(prev) = SCNEXT(ptr);
697 static inline struct scsi_cmnd *remove_SC(struct scsi_cmnd **SC,
698 struct scsi_cmnd *SCp)
700 struct scsi_cmnd *ptr, *prev;
702 for (ptr = *SC, prev = NULL;
704 prev = ptr, ptr = SCNEXT(ptr))
709 SCNEXT(prev) = SCNEXT(ptr);
719 static irqreturn_t swintr(int irqno, void *dev_id)
721 struct Scsi_Host *shpnt = dev_id;
723 HOSTDATA(shpnt)->swint++;
725 SETPORT(DMACNTRL0, INTEN);
729 struct Scsi_Host *aha152x_probe_one(struct aha152x_setup *setup)
731 struct Scsi_Host *shpnt;
733 shpnt = scsi_host_alloc(&aha152x_driver_template, sizeof(struct aha152x_hostdata));
735 printk(KERN_ERR "aha152x: scsi_host_alloc failed\n");
739 memset(HOSTDATA(shpnt), 0, sizeof *HOSTDATA(shpnt));
740 INIT_LIST_HEAD(&HOSTDATA(shpnt)->host_list);
742 /* need to have host registered before triggering any interrupt */
743 list_add_tail(&HOSTDATA(shpnt)->host_list, &aha152x_host_list);
745 shpnt->io_port = setup->io_port;
746 shpnt->n_io_port = IO_RANGE;
747 shpnt->irq = setup->irq;
749 if (!setup->tc1550) {
750 HOSTIOPORT0 = setup->io_port;
751 HOSTIOPORT1 = setup->io_port;
753 HOSTIOPORT0 = setup->io_port+0x10;
754 HOSTIOPORT1 = setup->io_port-0x10;
757 spin_lock_init(&QLOCK);
758 RECONNECT = setup->reconnect;
759 SYNCHRONOUS = setup->synchronous;
760 PARITY = setup->parity;
761 DELAY = setup->delay;
762 EXT_TRANS = setup->ext_trans;
764 SETPORT(SCSIID, setup->scsiid << 4);
765 shpnt->this_id = setup->scsiid;
767 if (setup->reconnect)
768 shpnt->can_queue = AHA152X_MAXQUEUE;
771 printk("aha152x: resetting bus...\n");
772 SETPORT(SCSISEQ, SCSIRSTO);
781 "vital data: rev=%x, "
782 "io=0x%03lx (0x%03lx/0x%03lx), "
789 "extended translation=%s\n",
790 shpnt->host_no, setup->tc1550 ? " (tc1550 mode)" : "",
792 shpnt->io_port, HOSTIOPORT0, HOSTIOPORT1,
795 RECONNECT ? "enabled" : "disabled",
796 PARITY ? "enabled" : "disabled",
797 SYNCHRONOUS ? "enabled" : "disabled",
799 EXT_TRANS ? "enabled" : "disabled");
801 /* not expecting any interrupts */
805 if (request_irq(shpnt->irq, swintr, IRQF_SHARED, "aha152x", shpnt)) {
806 printk(KERN_ERR "aha152x%d: irq %d busy.\n", shpnt->host_no, shpnt->irq);
810 HOSTDATA(shpnt)->swint = 0;
812 printk(KERN_INFO "aha152x%d: trying software interrupt, ", shpnt->host_no);
815 SETPORT(DMACNTRL0, SWINT|INTEN);
817 free_irq(shpnt->irq, shpnt);
819 if (!HOSTDATA(shpnt)->swint) {
820 if (TESTHI(DMASTAT, INTSTAT)) {
826 SETPORT(DMACNTRL0, INTEN);
828 printk(KERN_ERR "aha152x%d: irq %d possibly wrong. "
829 "Please verify.\n", shpnt->host_no, shpnt->irq);
835 /* clear interrupts */
836 SETPORT(SSTAT0, 0x7f);
837 SETPORT(SSTAT1, 0xef);
839 if (request_irq(shpnt->irq, intr, IRQF_SHARED, "aha152x", shpnt)) {
840 printk(KERN_ERR "aha152x%d: failed to reassign irq %d.\n", shpnt->host_no, shpnt->irq);
844 if( scsi_add_host(shpnt, NULL) ) {
845 free_irq(shpnt->irq, shpnt);
846 printk(KERN_ERR "aha152x%d: failed to add host.\n", shpnt->host_no);
850 scsi_scan_host(shpnt);
855 list_del(&HOSTDATA(shpnt)->host_list);
856 scsi_host_put(shpnt);
861 void aha152x_release(struct Scsi_Host *shpnt)
866 scsi_remove_host(shpnt);
868 free_irq(shpnt->irq, shpnt);
870 #if !defined(AHA152X_PCMCIA)
872 release_region(shpnt->io_port, IO_RANGE);
876 if (HOSTDATA(shpnt)->pnpdev)
877 pnp_device_detach(HOSTDATA(shpnt)->pnpdev);
880 list_del(&HOSTDATA(shpnt)->host_list);
881 scsi_host_put(shpnt);
886 * setup controller to generate interrupts depending
887 * on current state (lock has to be acquired)
890 static int setup_expected_interrupts(struct Scsi_Host *shpnt)
893 struct scsi_pointer *scsi_pointer =
894 aha152x_scsi_pointer(CURRENT_SC);
896 scsi_pointer->phase |= 1 << 16;
898 if (scsi_pointer->phase & selecting) {
899 SETPORT(SSTAT1, SELTO);
900 SETPORT(SIMODE0, ENSELDO | (DISCONNECTED_SC ? ENSELDI : 0));
901 SETPORT(SIMODE1, ENSELTIMO);
903 SETPORT(SIMODE0, (scsi_pointer->phase & spiordy) ? ENSPIORDY : 0);
904 SETPORT(SIMODE1, ENPHASEMIS | ENSCSIRST | ENSCSIPERR | ENBUSFREE);
906 } else if(STATE==seldi) {
908 SETPORT(SIMODE1, ENPHASEMIS | ENSCSIRST | ENSCSIPERR | ENBUSFREE);
910 SETPORT(SIMODE0, DISCONNECTED_SC ? ENSELDI : 0);
911 SETPORT(SIMODE1, ENSCSIRST | ( (ISSUE_SC||DONE_SC) ? ENBUSFREE : 0));
914 if(!HOSTDATA(shpnt)->in_intr)
915 SETBITS(DMACNTRL0, INTEN);
917 return TESTHI(DMASTAT, INTSTAT);
922 * Queue a command and setup interrupts for a free bus.
924 static int aha152x_internal_queue(struct scsi_cmnd *SCpnt,
925 struct completion *complete, int phase)
927 struct scsi_pointer *scsi_pointer = aha152x_scsi_pointer(SCpnt);
928 struct Scsi_Host *shpnt = SCpnt->device->host;
931 scsi_pointer->phase = not_issued | phase;
932 scsi_pointer->Status = 0x1; /* Ilegal status by SCSI standard */
933 scsi_pointer->Message = 0;
934 scsi_pointer->have_data_in = 0;
935 scsi_pointer->sent_command = 0;
937 if (scsi_pointer->phase & (resetting | check_condition)) {
938 if (!SCpnt->host_scribble || SCSEM(SCpnt) || SCNEXT(SCpnt)) {
939 scmd_printk(KERN_ERR, SCpnt, "cannot reuse command\n");
943 SCpnt->host_scribble = kmalloc(sizeof(struct aha152x_scdata), GFP_ATOMIC);
944 if(!SCpnt->host_scribble) {
945 scmd_printk(KERN_ERR, SCpnt, "allocation failed\n");
950 SCNEXT(SCpnt) = NULL;
951 SCSEM(SCpnt) = complete;
953 /* setup scratch area
954 SCp.ptr : buffer pointer
955 SCp.this_residual : buffer length
956 SCp.buffer : next buffer
957 SCp.phase : current state of the command */
959 if ((phase & resetting) || !scsi_sglist(SCpnt)) {
960 scsi_pointer->ptr = NULL;
961 scsi_pointer->this_residual = 0;
962 scsi_set_resid(SCpnt, 0);
963 scsi_pointer->buffer = NULL;
965 scsi_set_resid(SCpnt, scsi_bufflen(SCpnt));
966 scsi_pointer->buffer = scsi_sglist(SCpnt);
967 scsi_pointer->ptr = SG_ADDRESS(scsi_pointer->buffer);
968 scsi_pointer->this_residual = scsi_pointer->buffer->length;
973 #if defined(AHA152X_STAT)
974 HOSTDATA(shpnt)->total_commands++;
977 /* Turn led on, when this is the first command. */
978 HOSTDATA(shpnt)->commands++;
979 if (HOSTDATA(shpnt)->commands==1)
982 append_SC(&ISSUE_SC, SCpnt);
984 if(!HOSTDATA(shpnt)->in_intr)
985 setup_expected_interrupts(shpnt);
996 static int aha152x_queue_lck(struct scsi_cmnd *SCpnt)
998 return aha152x_internal_queue(SCpnt, NULL, 0);
1001 static DEF_SCSI_QCMD(aha152x_queue)
1007 static void reset_done(struct scsi_cmnd *SCpnt)
1010 complete(SCSEM(SCpnt));
1012 printk(KERN_ERR "aha152x: reset_done w/o completion\n");
1016 static void aha152x_scsi_done(struct scsi_cmnd *SCpnt)
1018 if (aha152x_scsi_pointer(SCpnt)->phase & resetting)
1028 static int aha152x_abort(struct scsi_cmnd *SCpnt)
1030 struct Scsi_Host *shpnt = SCpnt->device->host;
1031 struct scsi_cmnd *ptr;
1032 unsigned long flags;
1036 ptr=remove_SC(&ISSUE_SC, SCpnt);
1039 HOSTDATA(shpnt)->commands--;
1040 if (!HOSTDATA(shpnt)->commands)
1044 kfree(SCpnt->host_scribble);
1045 SCpnt->host_scribble=NULL;
1054 * for current command: queue ABORT for message out and raise ATN
1055 * for disconnected command: pseudo SC with ABORT message or ABORT on reselection?
1059 scmd_printk(KERN_ERR, SCpnt,
1060 "cannot abort running or disconnected command\n");
1069 static int aha152x_device_reset(struct scsi_cmnd * SCpnt)
1071 struct Scsi_Host *shpnt = SCpnt->device->host;
1072 DECLARE_COMPLETION(done);
1073 int ret, issued, disconnected;
1074 unsigned char old_cmd_len = SCpnt->cmd_len;
1075 unsigned long flags;
1076 unsigned long timeleft;
1078 if(CURRENT_SC==SCpnt) {
1079 scmd_printk(KERN_ERR, SCpnt, "cannot reset current device\n");
1084 issued = remove_SC(&ISSUE_SC, SCpnt) == NULL;
1085 disconnected = issued && remove_SC(&DISCONNECTED_SC, SCpnt);
1090 aha152x_internal_queue(SCpnt, &done, resetting);
1092 timeleft = wait_for_completion_timeout(&done, 100*HZ);
1094 /* remove command from issue queue */
1096 remove_SC(&ISSUE_SC, SCpnt);
1100 SCpnt->cmd_len = old_cmd_len;
1104 if (aha152x_scsi_pointer(SCpnt)->phase & resetted) {
1105 HOSTDATA(shpnt)->commands--;
1106 if (!HOSTDATA(shpnt)->commands)
1108 kfree(SCpnt->host_scribble);
1109 SCpnt->host_scribble=NULL;
1115 append_SC(&ISSUE_SC, SCpnt);
1116 } else if(disconnected) {
1117 append_SC(&DISCONNECTED_SC, SCpnt);
1127 static void free_hard_reset_SCs(struct Scsi_Host *shpnt,
1128 struct scsi_cmnd **SCs)
1130 struct scsi_cmnd *ptr;
1134 struct scsi_cmnd *next;
1139 scmd_printk(KERN_DEBUG, ptr,
1140 "queue corrupted at %p\n", ptr);
1144 if (!ptr->device->soft_reset) {
1145 remove_SC(SCs, ptr);
1146 HOSTDATA(shpnt)->commands--;
1147 kfree(ptr->host_scribble);
1148 ptr->host_scribble=NULL;
1158 * AIC-6260 has a hard reset (MRST signal), but apparently
1159 * one cannot trigger it via software. So live with
1160 * a soft reset; no-one seemed to have cared.
1162 static int aha152x_bus_reset_host(struct Scsi_Host *shpnt)
1164 unsigned long flags;
1168 free_hard_reset_SCs(shpnt, &ISSUE_SC);
1169 free_hard_reset_SCs(shpnt, &DISCONNECTED_SC);
1171 SETPORT(SCSISEQ, SCSIRSTO);
1173 SETPORT(SCSISEQ, 0);
1176 setup_expected_interrupts(shpnt);
1177 if(HOSTDATA(shpnt)->commands==0)
1189 static int aha152x_bus_reset(struct scsi_cmnd *SCpnt)
1191 return aha152x_bus_reset_host(SCpnt->device->host);
1195 * Restore default values to the AIC-6260 registers and reset the fifos
1198 static void reset_ports(struct Scsi_Host *shpnt)
1200 unsigned long flags;
1202 /* disable interrupts */
1203 SETPORT(DMACNTRL0, RSTFIFO);
1205 SETPORT(SCSISEQ, 0);
1207 SETPORT(SXFRCTL1, 0);
1208 SETPORT(SCSISIG, 0);
1211 /* clear all interrupt conditions */
1212 SETPORT(SSTAT0, 0x7f);
1213 SETPORT(SSTAT1, 0xef);
1215 SETPORT(SSTAT4, SYNCERR | FWERR | FRERR);
1217 SETPORT(DMACNTRL0, 0);
1218 SETPORT(DMACNTRL1, 0);
1220 SETPORT(BRSTCNTRL, 0xf1);
1222 /* clear SCSI fifos and transfer count */
1223 SETPORT(SXFRCTL0, CH1|CLRCH1|CLRSTCNT);
1224 SETPORT(SXFRCTL0, CH1);
1227 setup_expected_interrupts(shpnt);
1232 * Reset the host (bus and controller)
1235 int aha152x_host_reset_host(struct Scsi_Host *shpnt)
1237 aha152x_bus_reset_host(shpnt);
1244 * Return the "logical geometry"
1247 static int aha152x_biosparam(struct scsi_device *sdev, struct block_device *bdev,
1248 sector_t capacity, int *info_array)
1250 struct Scsi_Host *shpnt = sdev->host;
1252 /* try default translation */
1255 info_array[2] = (unsigned long)capacity / (64 * 32);
1257 /* for disks >1GB do some guessing */
1258 if (info_array[2] >= 1024) {
1261 /* try to figure out the geometry from the partition table */
1262 if (scsicam_bios_param(bdev, capacity, info) < 0 ||
1263 !((info[0] == 64 && info[1] == 32) || (info[0] == 255 && info[1] == 63))) {
1266 "aha152x: unable to verify geometry for disk with >1GB.\n"
1267 " using extended translation.\n");
1268 info_array[0] = 255;
1270 info_array[2] = (unsigned long)capacity / (255 * 63);
1273 "aha152x: unable to verify geometry for disk with >1GB.\n"
1274 " Using default translation. Please verify yourself.\n"
1275 " Perhaps you need to enable extended translation in the driver.\n"
1276 " See Documentation/scsi/aha152x.rst for details.\n");
1279 info_array[0] = info[0];
1280 info_array[1] = info[1];
1281 info_array[2] = info[2];
1283 if (info[0] == 255 && !EXT_TRANS) {
1285 "aha152x: current partition table is using extended translation.\n"
1286 " using it also, although it's not explicitly enabled.\n");
1295 * Internal done function
1298 static void done(struct Scsi_Host *shpnt, unsigned char status_byte,
1299 unsigned char host_byte)
1303 scmd_printk(KERN_ERR, CURRENT_SC,
1304 "there's already a completed command %p "
1305 "- will cause abort\n", DONE_SC);
1307 DONE_SC = CURRENT_SC;
1309 set_status_byte(DONE_SC, status_byte);
1310 set_host_byte(DONE_SC, host_byte);
1312 printk(KERN_ERR "aha152x: done() called outside of command\n");
1315 static struct work_struct aha152x_tq;
1318 * Run service completions on the card with interrupts enabled.
1321 static void run(struct work_struct *work)
1323 struct aha152x_hostdata *hd;
1325 list_for_each_entry(hd, &aha152x_host_list, host_list) {
1326 struct Scsi_Host *shost = container_of((void *)hd, struct Scsi_Host, hostdata);
1336 static irqreturn_t intr(int irqno, void *dev_id)
1338 struct Scsi_Host *shpnt = dev_id;
1339 unsigned long flags;
1340 unsigned char rev, dmacntrl0;
1343 * Read a couple of registers that are known to not be all 1's. If
1344 * we read all 1's (-1), that means that either:
1346 * a. The host adapter chip has gone bad, and we cannot control it,
1348 * b. The host adapter is a PCMCIA card that has been ejected
1350 * In either case, we cannot do anything with the host adapter at
1351 * this point in time. So just ignore the interrupt and return.
1352 * In the latter case, the interrupt might actually be meant for
1353 * someone else sharing this IRQ, and that driver will handle it.
1356 dmacntrl0 = GETPORT(DMACNTRL0);
1357 if ((rev == 0xFF) && (dmacntrl0 == 0xFF))
1360 if( TESTLO(DMASTAT, INTSTAT) )
1363 /* no more interrupts from the controller, while we're busy.
1364 INTEN is restored by the BH handler */
1365 CLRBITS(DMACNTRL0, INTEN);
1368 if( HOSTDATA(shpnt)->service==0 ) {
1369 HOSTDATA(shpnt)->service=1;
1371 /* Poke the BH handler */
1372 INIT_WORK(&aha152x_tq, run);
1373 schedule_work(&aha152x_tq);
1382 * - handle completition/disconnection/error of current command
1383 * - start selection for next command (if any)
1385 static void busfree_run(struct Scsi_Host *shpnt)
1387 unsigned long flags;
1388 #if defined(AHA152X_STAT)
1392 SETPORT(SXFRCTL0, CH1|CLRCH1|CLRSTCNT);
1393 SETPORT(SXFRCTL0, CH1);
1395 SETPORT(SSTAT1, CLRBUSFREE);
1398 struct scsi_pointer *scsi_pointer =
1399 aha152x_scsi_pointer(CURRENT_SC);
1401 #if defined(AHA152X_STAT)
1404 scsi_pointer->phase &= ~syncneg;
1406 if (scsi_pointer->phase & completed) {
1407 /* target sent COMMAND COMPLETE */
1408 done(shpnt, scsi_pointer->Status, DID_OK);
1410 } else if (scsi_pointer->phase & aborted) {
1411 done(shpnt, scsi_pointer->Status, DID_ABORT);
1413 } else if (scsi_pointer->phase & resetted) {
1414 done(shpnt, scsi_pointer->Status, DID_RESET);
1416 } else if (scsi_pointer->phase & disconnected) {
1417 /* target sent DISCONNECT */
1418 #if defined(AHA152X_STAT)
1419 HOSTDATA(shpnt)->disconnections++;
1421 append_SC(&DISCONNECTED_SC, CURRENT_SC);
1422 scsi_pointer->phase |= 1 << 16;
1426 done(shpnt, SAM_STAT_GOOD, DID_ERROR);
1428 #if defined(AHA152X_STAT)
1430 HOSTDATA(shpnt)->busfree_without_old_command++;
1437 #if defined(AHA152X_STAT)
1441 if (aha152x_scsi_pointer(DONE_SC)->phase & check_condition) {
1442 struct scsi_cmnd *cmd = HOSTDATA(shpnt)->done_SC;
1443 struct aha152x_scdata *sc = SCDATA(cmd);
1445 scsi_eh_restore_cmnd(cmd, &sc->ses);
1447 aha152x_scsi_pointer(cmd)->Status = SAM_STAT_CHECK_CONDITION;
1449 HOSTDATA(shpnt)->commands--;
1450 if (!HOSTDATA(shpnt)->commands)
1451 SETPORT(PORTA, 0); /* turn led off */
1452 } else if (aha152x_scsi_pointer(DONE_SC)->Status ==
1453 SAM_STAT_CHECK_CONDITION) {
1454 #if defined(AHA152X_STAT)
1455 HOSTDATA(shpnt)->busfree_with_check_condition++;
1458 if(!(aha152x_scsi_pointer(DONE_SC)->phase & not_issued)) {
1459 struct aha152x_scdata *sc;
1460 struct scsi_cmnd *ptr = DONE_SC;
1464 /* It was allocated in aha152x_internal_queue? */
1466 scsi_eh_prep_cmnd(ptr, &sc->ses, NULL, 0, ~0);
1469 aha152x_internal_queue(ptr, NULL, check_condition);
1475 struct scsi_cmnd *ptr = DONE_SC;
1478 /* turn led off, when no commands are in the driver */
1479 HOSTDATA(shpnt)->commands--;
1480 if (!HOSTDATA(shpnt)->commands)
1481 SETPORT(PORTA, 0); /* turn led off */
1483 if (!(aha152x_scsi_pointer(ptr)->phase & resetting)) {
1484 kfree(ptr->host_scribble);
1485 ptr->host_scribble=NULL;
1489 aha152x_scsi_done(ptr);
1494 #if defined(AHA152X_STAT)
1496 HOSTDATA(shpnt)->busfree_without_done_command++;
1501 CURRENT_SC = remove_first_SC(&ISSUE_SC);
1506 struct scsi_pointer *scsi_pointer =
1507 aha152x_scsi_pointer(CURRENT_SC);
1509 #if defined(AHA152X_STAT)
1512 scsi_pointer->phase |= selecting;
1514 /* clear selection timeout */
1515 SETPORT(SSTAT1, SELTO);
1517 SETPORT(SCSIID, (shpnt->this_id << OID_) | CURRENT_SC->device->id);
1518 SETPORT(SXFRCTL1, (PARITY ? ENSPCHK : 0 ) | ENSTIMER);
1519 SETPORT(SCSISEQ, ENSELO | ENAUTOATNO | (DISCONNECTED_SC ? ENRESELI : 0));
1521 #if defined(AHA152X_STAT)
1522 HOSTDATA(shpnt)->busfree_without_new_command++;
1524 SETPORT(SCSISEQ, DISCONNECTED_SC ? ENRESELI : 0);
1527 #if defined(AHA152X_STAT)
1529 HOSTDATA(shpnt)->busfree_without_any_action++;
1534 * Selection done (OUT)
1535 * - queue IDENTIFY message and SDTR to selected target for message out
1536 * (ATN asserted automagically via ENAUTOATNO in busfree())
1538 static void seldo_run(struct Scsi_Host *shpnt)
1540 struct scsi_pointer *scsi_pointer = aha152x_scsi_pointer(CURRENT_SC);
1542 SETPORT(SCSISIG, 0);
1543 SETPORT(SSTAT1, CLRBUSFREE);
1544 SETPORT(SSTAT1, CLRPHASECHG);
1546 scsi_pointer->phase &= ~(selecting | not_issued);
1548 SETPORT(SCSISEQ, 0);
1550 if (TESTLO(SSTAT0, SELDO)) {
1551 scmd_printk(KERN_ERR, CURRENT_SC,
1552 "aha152x: passing bus free condition\n");
1553 done(shpnt, SAM_STAT_GOOD, DID_NO_CONNECT);
1557 SETPORT(SSTAT0, CLRSELDO);
1559 ADDMSGO(IDENTIFY(RECONNECT, CURRENT_SC->device->lun));
1561 if (scsi_pointer->phase & aborting) {
1563 } else if (scsi_pointer->phase & resetting) {
1564 ADDMSGO(BUS_DEVICE_RESET);
1565 } else if (SYNCNEG==0 && SYNCHRONOUS) {
1566 scsi_pointer->phase |= syncneg;
1567 MSGOLEN += spi_populate_sync_msg(&MSGO(MSGOLEN), 50, 8);
1568 SYNCNEG=1; /* negotiation in progress */
1576 * - return command to mid-level with failure cause
1579 static void selto_run(struct Scsi_Host *shpnt)
1581 struct scsi_pointer *scsi_pointer = aha152x_scsi_pointer(CURRENT_SC);
1583 SETPORT(SCSISEQ, 0);
1584 SETPORT(SSTAT1, CLRSELTIMO);
1589 scsi_pointer->phase &= ~selecting;
1591 if (scsi_pointer->phase & aborted)
1592 done(shpnt, SAM_STAT_GOOD, DID_ABORT);
1593 else if (TESTLO(SSTAT0, SELINGO))
1594 done(shpnt, SAM_STAT_GOOD, DID_BUS_BUSY);
1596 /* ARBITRATION won, but SELECTION failed */
1597 done(shpnt, SAM_STAT_GOOD, DID_NO_CONNECT);
1602 * - put current command back to issue queue
1603 * (reconnection of a disconnected nexus instead
1604 * of successful selection out)
1607 static void seldi_run(struct Scsi_Host *shpnt)
1611 unsigned long flags;
1613 SETPORT(SCSISIG, 0);
1614 SETPORT(SSTAT0, CLRSELDI);
1615 SETPORT(SSTAT1, CLRBUSFREE);
1616 SETPORT(SSTAT1, CLRPHASECHG);
1619 struct scsi_pointer *scsi_pointer =
1620 aha152x_scsi_pointer(CURRENT_SC);
1622 if (!(scsi_pointer->phase & not_issued))
1623 scmd_printk(KERN_ERR, CURRENT_SC,
1624 "command should not have been issued yet\n");
1627 append_SC(&ISSUE_SC, CURRENT_SC);
1633 if (!DISCONNECTED_SC)
1638 selid = GETPORT(SELID) & ~(1 << shpnt->this_id);
1641 shost_printk(KERN_INFO, shpnt,
1642 "target id unknown (%02x)\n", selid);
1646 for(target=7; !(selid & (1 << target)); target--)
1649 if(selid & ~(1 << target)) {
1650 shost_printk(KERN_INFO, shpnt,
1651 "multiple targets reconnected (%02x)\n", selid);
1655 SETPORT(SCSIID, (shpnt->this_id << OID_) | target);
1656 SETPORT(SCSISEQ, 0);
1658 SETRATE(HOSTDATA(shpnt)->syncrate[target]);
1660 RECONN_TARGET=target;
1665 * - handle initial message after reconnection to identify
1666 * reconnecting nexus
1667 * - queue command on DISCONNECTED_SC on DISCONNECT message
1668 * - set completed flag on COMMAND COMPLETE
1669 * (other completition code moved to busfree_run)
1670 * - handle response to SDTR
1671 * - clear synchronous transfer agreements on BUS RESET
1673 * FIXME: what about SAVE POINTERS, RESTORE POINTERS?
1676 static void msgi_run(struct Scsi_Host *shpnt)
1679 struct scsi_pointer *scsi_pointer;
1680 int sstat1 = GETPORT(SSTAT1);
1682 if(sstat1 & (PHASECHG|PHASEMIS|BUSFREE) || !(sstat1 & REQINIT))
1685 if (TESTLO(SSTAT0, SPIORDY))
1688 ADDMSGI(GETPORT(SCSIDAT));
1691 if(LASTSTATE!=seldi) {
1692 shost_printk(KERN_ERR, shpnt,
1693 "message in w/o current command"
1694 " not after reselection\n");
1698 * Handle reselection
1700 if(!(MSGI(0) & IDENTIFY_BASE)) {
1701 shost_printk(KERN_ERR, shpnt,
1702 "target didn't identify after reselection\n");
1706 CURRENT_SC = remove_lun_SC(&DISCONNECTED_SC, RECONN_TARGET, MSGI(0) & 0x3f);
1710 shost_printk(KERN_ERR, shpnt,
1711 "no disconnected command"
1712 " for target %d/%d\n",
1713 RECONN_TARGET, MSGI(0) & 0x3f);
1717 scsi_pointer = aha152x_scsi_pointer(CURRENT_SC);
1718 scsi_pointer->Message = MSGI(0);
1719 scsi_pointer->phase &= ~disconnected;
1723 /* next message if any */
1727 scsi_pointer = aha152x_scsi_pointer(CURRENT_SC);
1728 scsi_pointer->Message = MSGI(0);
1733 scmd_printk(KERN_WARNING, CURRENT_SC,
1734 "target was not allowed to disconnect\n");
1736 scsi_pointer->phase |= disconnected;
1739 case COMMAND_COMPLETE:
1740 scsi_pointer->phase |= completed;
1743 case MESSAGE_REJECT:
1745 scmd_printk(KERN_INFO, CURRENT_SC,
1746 "Synchronous Data Transfer Request"
1748 SYNCNEG=2; /* negotiation completed */
1750 scmd_printk(KERN_INFO, CURRENT_SC,
1751 "inbound message (MESSAGE REJECT)\n");
1757 case RESTORE_POINTERS:
1760 case EXTENDED_MESSAGE:
1761 if(MSGILEN<2 || MSGILEN<MSGI(1)+2) {
1762 /* not yet completed */
1772 scmd_printk(KERN_ERR, CURRENT_SC,
1773 "SDTR message length!=3\n");
1777 if (!HOSTDATA(shpnt)->synchronous)
1780 printk(INFO_LEAD, CMDINFO(CURRENT_SC));
1781 spi_print_msg(&MSGI(0));
1784 ticks = (MSGI(3) * 4 + 49) / 50;
1787 /* negotiation in progress */
1788 if (ticks > 9 || MSGI(4) < 1 || MSGI(4) > 8) {
1789 ADDMSGO(MESSAGE_REJECT);
1790 scmd_printk(KERN_INFO,
1792 "received Synchronous Data Transfer Request invalid - rejected\n");
1796 SYNCRATE |= ((ticks - 2) << 4) + MSGI(4);
1797 } else if (ticks <= 9 && MSGI(4) >= 1) {
1798 ADDMSGO(EXTENDED_MESSAGE);
1800 ADDMSGO(EXTENDED_SDTR);
1812 SYNCRATE |= ((ticks - 2) << 4) + MSGI(4);
1814 /* requested SDTR is too slow, do it asynchronously */
1815 scmd_printk(KERN_INFO,
1817 "Synchronous Data Transfer Request too slow - Rejecting\n");
1818 ADDMSGO(MESSAGE_REJECT);
1821 /* negotiation completed */
1827 case BUS_DEVICE_RESET:
1831 for(i=0; i<8; i++) {
1832 HOSTDATA(shpnt)->syncrate[i]=0;
1833 HOSTDATA(shpnt)->syncneg[i]=0;
1839 case EXTENDED_MODIFY_DATA_POINTER:
1840 case EXTENDED_EXTENDED_IDENTIFY:
1843 ADDMSGO(MESSAGE_REJECT);
1853 static void msgi_end(struct Scsi_Host *shpnt)
1856 scmd_printk(KERN_WARNING, CURRENT_SC,
1857 "target left before message completed (%d)\n",
1860 if (MSGOLEN > 0 && !(GETPORT(SSTAT1) & BUSFREE))
1861 SETPORT(SCSISIG, P_MSGI | SIG_ATNO);
1868 static void msgo_init(struct Scsi_Host *shpnt)
1870 struct scsi_pointer *scsi_pointer = aha152x_scsi_pointer(CURRENT_SC);
1873 if ((scsi_pointer->phase & syncneg) && SYNCNEG==2 &&
1875 ADDMSGO(IDENTIFY(RECONNECT, CURRENT_SC->device->lun));
1877 scmd_printk(KERN_INFO, CURRENT_SC,
1878 "unexpected MESSAGE OUT phase; rejecting\n");
1879 ADDMSGO(MESSAGE_REJECT);
1889 static void msgo_run(struct Scsi_Host *shpnt)
1891 struct scsi_pointer *scsi_pointer = aha152x_scsi_pointer(CURRENT_SC);
1893 while(MSGO_I<MSGOLEN) {
1894 if (TESTLO(SSTAT0, SPIORDY))
1897 if (MSGO_I==MSGOLEN-1) {
1898 /* Leave MESSAGE OUT after transfer */
1899 SETPORT(SSTAT1, CLRATNO);
1903 if (MSGO(MSGO_I) & IDENTIFY_BASE)
1904 scsi_pointer->phase |= identified;
1906 if (MSGO(MSGO_I)==ABORT)
1907 scsi_pointer->phase |= aborted;
1909 if (MSGO(MSGO_I)==BUS_DEVICE_RESET)
1910 scsi_pointer->phase |= resetted;
1912 SETPORT(SCSIDAT, MSGO(MSGO_I++));
1916 static void msgo_end(struct Scsi_Host *shpnt)
1918 if(MSGO_I<MSGOLEN) {
1919 scmd_printk(KERN_ERR, CURRENT_SC,
1920 "message sent incompletely (%d/%d)\n",
1923 scmd_printk(KERN_INFO, CURRENT_SC,
1924 "Synchronous Data Transfer Request was rejected\n");
1937 static void cmd_init(struct Scsi_Host *shpnt)
1939 if (aha152x_scsi_pointer(CURRENT_SC)->sent_command) {
1940 scmd_printk(KERN_ERR, CURRENT_SC,
1941 "command already sent\n");
1942 done(shpnt, SAM_STAT_GOOD, DID_ERROR);
1953 static void cmd_run(struct Scsi_Host *shpnt)
1955 while(CMD_I<CURRENT_SC->cmd_len) {
1956 if (TESTLO(SSTAT0, SPIORDY))
1959 SETPORT(SCSIDAT, CURRENT_SC->cmnd[CMD_I++]);
1963 static void cmd_end(struct Scsi_Host *shpnt)
1965 if(CMD_I<CURRENT_SC->cmd_len)
1966 scmd_printk(KERN_ERR, CURRENT_SC,
1967 "command sent incompletely (%d/%d)\n",
1968 CMD_I, CURRENT_SC->cmd_len);
1970 aha152x_scsi_pointer(CURRENT_SC)->sent_command++;
1977 static void status_run(struct Scsi_Host *shpnt)
1979 if (TESTLO(SSTAT0, SPIORDY))
1982 aha152x_scsi_pointer(CURRENT_SC)->Status = GETPORT(SCSIDAT);
1990 static void datai_init(struct Scsi_Host *shpnt)
1992 SETPORT(DMACNTRL0, RSTFIFO);
1993 SETPORT(DMACNTRL0, RSTFIFO|ENDMA);
1995 SETPORT(SXFRCTL0, CH1|CLRSTCNT);
1996 SETPORT(SXFRCTL0, CH1|SCSIEN|DMAEN);
1998 SETPORT(SIMODE0, 0);
1999 SETPORT(SIMODE1, ENSCSIPERR | ENSCSIRST | ENPHASEMIS | ENBUSFREE);
2004 static void datai_run(struct Scsi_Host *shpnt)
2006 struct scsi_pointer *scsi_pointer;
2007 unsigned long the_time;
2008 int fifodata, data_count;
2011 * loop while the phase persists or the fifos are not empty
2014 while(TESTLO(DMASTAT, INTSTAT) || TESTLO(DMASTAT, DFIFOEMP) || TESTLO(SSTAT2, SEMPTY)) {
2015 /* FIXME: maybe this should be done by setting up
2016 * STCNT to trigger ENSWRAP interrupt, instead of
2017 * polling for DFIFOFULL
2019 the_time=jiffies + 100*HZ;
2020 while(TESTLO(DMASTAT, DFIFOFULL|INTSTAT) && time_before(jiffies,the_time))
2023 if(TESTLO(DMASTAT, DFIFOFULL|INTSTAT)) {
2024 scmd_printk(KERN_ERR, CURRENT_SC, "datai timeout\n");
2028 if(TESTHI(DMASTAT, DFIFOFULL)) {
2031 the_time=jiffies + 100*HZ;
2032 while(TESTLO(SSTAT2, SEMPTY) && time_before(jiffies,the_time))
2035 if(TESTLO(SSTAT2, SEMPTY)) {
2036 scmd_printk(KERN_ERR, CURRENT_SC,
2037 "datai sempty timeout");
2041 fifodata = GETPORT(FIFOSTAT);
2044 scsi_pointer = aha152x_scsi_pointer(CURRENT_SC);
2045 if (scsi_pointer->this_residual > 0) {
2046 while (fifodata > 0 && scsi_pointer->this_residual > 0) {
2047 data_count = fifodata > scsi_pointer->this_residual ?
2048 scsi_pointer->this_residual :
2050 fifodata -= data_count;
2052 if (data_count & 1) {
2053 SETPORT(DMACNTRL0, ENDMA|_8BIT);
2054 *scsi_pointer->ptr++ = GETPORT(DATAPORT);
2055 scsi_pointer->this_residual--;
2057 SETPORT(DMACNTRL0, ENDMA);
2060 if (data_count > 1) {
2062 insw(DATAPORT, scsi_pointer->ptr, data_count);
2063 scsi_pointer->ptr += 2 * data_count;
2064 scsi_pointer->this_residual -= 2 * data_count;
2065 DATA_LEN += 2 * data_count;
2068 if (scsi_pointer->this_residual == 0 &&
2069 !sg_is_last(scsi_pointer->buffer)) {
2070 /* advance to next buffer */
2071 scsi_pointer->buffer = sg_next(scsi_pointer->buffer);
2072 scsi_pointer->ptr = SG_ADDRESS(scsi_pointer->buffer);
2073 scsi_pointer->this_residual = scsi_pointer->buffer->length;
2076 } else if (fifodata > 0) {
2077 scmd_printk(KERN_ERR, CURRENT_SC,
2078 "no buffers left for %d(%d) bytes"
2079 " (data overrun!?)\n",
2080 fifodata, GETPORT(FIFOSTAT));
2081 SETPORT(DMACNTRL0, ENDMA|_8BIT);
2087 SETPORT(DMACNTRL0, ENDMA|_8BIT);
2091 if(TESTLO(DMASTAT, INTSTAT) ||
2092 TESTLO(DMASTAT, DFIFOEMP) ||
2093 TESTLO(SSTAT2, SEMPTY) ||
2094 GETPORT(FIFOSTAT)>0) {
2096 * something went wrong, if there's something left in the fifos
2097 * or the phase didn't change
2099 scmd_printk(KERN_ERR, CURRENT_SC,
2100 "fifos should be empty and phase should have changed\n");
2103 if(DATA_LEN!=GETSTCNT()) {
2104 scmd_printk(KERN_ERR, CURRENT_SC,
2105 "manual transfer count differs from automatic "
2106 "(count=%d;stcnt=%d;diff=%d;fifostat=%d)",
2107 DATA_LEN, GETSTCNT(), GETSTCNT()-DATA_LEN,
2113 static void datai_end(struct Scsi_Host *shpnt)
2115 CMD_INC_RESID(CURRENT_SC, -GETSTCNT());
2117 SETPORT(SXFRCTL0, CH1|CLRSTCNT);
2118 SETPORT(DMACNTRL0, 0);
2125 static void datao_init(struct Scsi_Host *shpnt)
2127 SETPORT(DMACNTRL0, WRITE_READ | RSTFIFO);
2128 SETPORT(DMACNTRL0, WRITE_READ | ENDMA);
2130 SETPORT(SXFRCTL0, CH1|CLRSTCNT);
2131 SETPORT(SXFRCTL0, CH1|SCSIEN|DMAEN);
2133 SETPORT(SIMODE0, 0);
2134 SETPORT(SIMODE1, ENSCSIPERR | ENSCSIRST | ENPHASEMIS | ENBUSFREE );
2136 DATA_LEN = scsi_get_resid(CURRENT_SC);
2139 static void datao_run(struct Scsi_Host *shpnt)
2141 struct scsi_pointer *scsi_pointer = aha152x_scsi_pointer(CURRENT_SC);
2142 unsigned long the_time;
2145 /* until phase changes or all data sent */
2146 while (TESTLO(DMASTAT, INTSTAT) && scsi_pointer->this_residual > 0) {
2148 if (data_count > scsi_pointer->this_residual)
2149 data_count = scsi_pointer->this_residual;
2151 if(TESTLO(DMASTAT, DFIFOEMP)) {
2152 scmd_printk(KERN_ERR, CURRENT_SC,
2153 "datao fifo not empty (%d)",
2158 if(data_count & 1) {
2159 SETPORT(DMACNTRL0,WRITE_READ|ENDMA|_8BIT);
2160 SETPORT(DATAPORT, *scsi_pointer->ptr++);
2161 scsi_pointer->this_residual--;
2162 CMD_INC_RESID(CURRENT_SC, -1);
2163 SETPORT(DMACNTRL0,WRITE_READ|ENDMA);
2166 if(data_count > 1) {
2168 outsw(DATAPORT, scsi_pointer->ptr, data_count);
2169 scsi_pointer->ptr += 2 * data_count;
2170 scsi_pointer->this_residual -= 2 * data_count;
2171 CMD_INC_RESID(CURRENT_SC, -2 * data_count);
2174 if (scsi_pointer->this_residual == 0 &&
2175 !sg_is_last(scsi_pointer->buffer)) {
2176 /* advance to next buffer */
2177 scsi_pointer->buffer = sg_next(scsi_pointer->buffer);
2178 scsi_pointer->ptr = SG_ADDRESS(scsi_pointer->buffer);
2179 scsi_pointer->this_residual = scsi_pointer->buffer->length;
2182 the_time=jiffies + 100*HZ;
2183 while(TESTLO(DMASTAT, DFIFOEMP|INTSTAT) && time_before(jiffies,the_time))
2186 if(TESTLO(DMASTAT, DFIFOEMP|INTSTAT)) {
2187 scmd_printk(KERN_ERR, CURRENT_SC, "dataout timeout\n");
2193 static void datao_end(struct Scsi_Host *shpnt)
2195 struct scsi_pointer *scsi_pointer = aha152x_scsi_pointer(CURRENT_SC);
2197 if(TESTLO(DMASTAT, DFIFOEMP)) {
2198 u32 datao_cnt = GETSTCNT();
2199 int datao_out = DATA_LEN - scsi_get_resid(CURRENT_SC);
2201 struct scatterlist *sg = scsi_sglist(CURRENT_SC);
2203 CMD_INC_RESID(CURRENT_SC, datao_out - datao_cnt);
2205 done = scsi_bufflen(CURRENT_SC) - scsi_get_resid(CURRENT_SC);
2206 /* Locate the first SG entry not yet sent */
2207 while (done > 0 && !sg_is_last(sg)) {
2208 if (done < sg->length)
2214 scsi_pointer->buffer = sg;
2215 scsi_pointer->ptr = SG_ADDRESS(scsi_pointer->buffer) + done;
2216 scsi_pointer->this_residual = scsi_pointer->buffer->length -
2220 SETPORT(SXFRCTL0, CH1|CLRCH1|CLRSTCNT);
2221 SETPORT(SXFRCTL0, CH1);
2223 SETPORT(DMACNTRL0, 0);
2227 * figure out what state we're in
2230 static int update_state(struct Scsi_Host *shpnt)
2232 struct scsi_pointer *scsi_pointer = aha152x_scsi_pointer(CURRENT_SC);
2234 unsigned int stat0 = GETPORT(SSTAT0);
2235 unsigned int stat1 = GETPORT(SSTAT1);
2240 if(stat1 & SCSIRSTI) {
2243 SETPORT(SSTAT1,SCSIRSTI);
2244 } else if (stat0 & SELDI && PREVSTATE == busfree) {
2246 } else if (stat0 & SELDO && CURRENT_SC &&
2247 (scsi_pointer->phase & selecting)) {
2249 } else if(stat1 & SELTO) {
2251 } else if(stat1 & BUSFREE) {
2253 SETPORT(SSTAT1,BUSFREE);
2254 } else if(stat1 & SCSIPERR) {
2256 SETPORT(SSTAT1,SCSIPERR);
2257 } else if(stat1 & REQINIT) {
2258 switch(GETPORT(SCSISIG) & P_MASK) {
2259 case P_MSGI: STATE=msgi; break;
2260 case P_MSGO: STATE=msgo; break;
2261 case P_DATAO: STATE=datao; break;
2262 case P_DATAI: STATE=datai; break;
2263 case P_STATUS: STATE=status; break;
2264 case P_CMD: STATE=cmd; break;
2269 if((stat0 & SELDI) && STATE!=seldi && !dataphase) {
2270 scmd_printk(KERN_INFO, CURRENT_SC, "reselection missed?");
2273 if(STATE!=PREVSTATE) {
2274 LASTSTATE=PREVSTATE;
2281 * handle parity error
2283 * FIXME: in which phase?
2286 static void parerr_run(struct Scsi_Host *shpnt)
2288 scmd_printk(KERN_ERR, CURRENT_SC, "parity error\n");
2289 done(shpnt, SAM_STAT_GOOD, DID_PARITY);
2296 static void rsti_run(struct Scsi_Host *shpnt)
2298 struct scsi_cmnd *ptr;
2300 shost_printk(KERN_NOTICE, shpnt, "scsi reset in\n");
2302 ptr=DISCONNECTED_SC;
2304 struct scsi_cmnd *next = SCNEXT(ptr);
2306 if (!ptr->device->soft_reset) {
2307 remove_SC(&DISCONNECTED_SC, ptr);
2309 kfree(ptr->host_scribble);
2310 ptr->host_scribble=NULL;
2312 set_host_byte(ptr, DID_RESET);
2313 aha152x_scsi_done(ptr);
2319 if(CURRENT_SC && !CURRENT_SC->device->soft_reset)
2320 done(shpnt, SAM_STAT_GOOD, DID_RESET);
2325 * bottom-half handler
2328 static void is_complete(struct Scsi_Host *shpnt)
2331 unsigned long flags;
2339 if( HOSTDATA(shpnt)->service==0 ) {
2344 HOSTDATA(shpnt)->service = 0;
2346 if(HOSTDATA(shpnt)->in_intr) {
2348 /* aha152x_error never returns.. */
2349 aha152x_error(shpnt, "bottom-half already running!?");
2351 HOSTDATA(shpnt)->in_intr++;
2354 * loop while there are interrupt conditions pending
2358 unsigned long start = jiffies;
2361 dataphase=update_state(shpnt);
2364 * end previous state
2367 if(PREVSTATE!=STATE && states[PREVSTATE].end)
2368 states[PREVSTATE].end(shpnt);
2371 * disable SPIO mode if previous phase used it
2372 * and this one doesn't
2375 if(states[PREVSTATE].spio && !states[STATE].spio) {
2376 SETPORT(SXFRCTL0, CH1);
2377 SETPORT(DMACNTRL0, 0);
2379 aha152x_scsi_pointer(CURRENT_SC)->phase &=
2384 * accept current dataphase phase
2388 SETPORT(SSTAT0, REQINIT);
2389 SETPORT(SCSISIG, GETPORT(SCSISIG) & P_MASK);
2390 SETPORT(SSTAT1, PHASECHG);
2394 * enable SPIO mode if previous didn't use it
2398 if(!states[PREVSTATE].spio && states[STATE].spio) {
2399 SETPORT(DMACNTRL0, 0);
2400 SETPORT(SXFRCTL0, CH1|SPIOEN);
2402 aha152x_scsi_pointer(CURRENT_SC)->phase |=
2407 * initialize for new state
2410 if(PREVSTATE!=STATE && states[STATE].init)
2411 states[STATE].init(shpnt);
2414 * handle current state
2417 if(states[STATE].run)
2418 states[STATE].run(shpnt);
2420 scmd_printk(KERN_ERR, CURRENT_SC,
2421 "unexpected state (%x)\n", STATE);
2424 * setup controller to interrupt on
2425 * the next expected condition and
2426 * loop if it's already there
2430 pending=setup_expected_interrupts(shpnt);
2431 #if defined(AHA152X_STAT)
2432 HOSTDATA(shpnt)->count[STATE]++;
2433 if(PREVSTATE!=STATE)
2434 HOSTDATA(shpnt)->count_trans[STATE]++;
2435 HOSTDATA(shpnt)->time[STATE] += jiffies-start;
2441 * enable interrupts and leave bottom-half
2444 HOSTDATA(shpnt)->in_intr--;
2445 SETBITS(DMACNTRL0, INTEN);
2451 * Dump the current driver status and panic
2453 static void aha152x_error(struct Scsi_Host *shpnt, char *msg)
2455 shost_printk(KERN_EMERG, shpnt, "%s\n", msg);
2457 panic("aha152x panic\n");
2461 * display enabled interrupts
2463 static void disp_enintr(struct Scsi_Host *shpnt)
2467 s0 = GETPORT(SIMODE0);
2468 s1 = GETPORT(SIMODE1);
2470 shost_printk(KERN_DEBUG, shpnt,
2471 "enabled interrupts (%s%s%s%s%s%s%s%s%s%s%s%s%s%s)\n",
2472 (s0 & ENSELDO) ? "ENSELDO " : "",
2473 (s0 & ENSELDI) ? "ENSELDI " : "",
2474 (s0 & ENSELINGO) ? "ENSELINGO " : "",
2475 (s0 & ENSWRAP) ? "ENSWRAP " : "",
2476 (s0 & ENSDONE) ? "ENSDONE " : "",
2477 (s0 & ENSPIORDY) ? "ENSPIORDY " : "",
2478 (s0 & ENDMADONE) ? "ENDMADONE " : "",
2479 (s1 & ENSELTIMO) ? "ENSELTIMO " : "",
2480 (s1 & ENATNTARG) ? "ENATNTARG " : "",
2481 (s1 & ENPHASEMIS) ? "ENPHASEMIS " : "",
2482 (s1 & ENBUSFREE) ? "ENBUSFREE " : "",
2483 (s1 & ENSCSIPERR) ? "ENSCSIPERR " : "",
2484 (s1 & ENPHASECHG) ? "ENPHASECHG " : "",
2485 (s1 & ENREQINIT) ? "ENREQINIT " : "");
2489 * Show the command data of a command
2491 static void show_command(struct scsi_cmnd *ptr)
2493 const int phase = aha152x_scsi_pointer(ptr)->phase;
2495 scsi_print_command(ptr);
2496 scmd_printk(KERN_DEBUG, ptr,
2497 "request_bufflen=%d; resid=%d; "
2498 "phase |%s%s%s%s%s%s%s%s%s; next=0x%p",
2499 scsi_bufflen(ptr), scsi_get_resid(ptr),
2500 phase & not_issued ? "not issued|" : "",
2501 phase & selecting ? "selecting|" : "",
2502 phase & identified ? "identified|" : "",
2503 phase & disconnected ? "disconnected|" : "",
2504 phase & completed ? "completed|" : "",
2505 phase & spiordy ? "spiordy|" : "",
2506 phase & syncneg ? "syncneg|" : "",
2507 phase & aborted ? "aborted|" : "",
2508 phase & resetted ? "resetted|" : "",
2509 SCDATA(ptr) ? SCNEXT(ptr) : NULL);
2513 * Dump the queued data
2515 static void show_queues(struct Scsi_Host *shpnt)
2517 struct scsi_cmnd *ptr;
2518 unsigned long flags;
2521 printk(KERN_DEBUG "\nqueue status:\nissue_SC:\n");
2522 for (ptr = ISSUE_SC; ptr; ptr = SCNEXT(ptr))
2526 printk(KERN_DEBUG "current_SC:\n");
2528 show_command(CURRENT_SC);
2530 printk(KERN_DEBUG "none\n");
2532 printk(KERN_DEBUG "disconnected_SC:\n");
2533 for (ptr = DISCONNECTED_SC; ptr; ptr = SCDATA(ptr) ? SCNEXT(ptr) : NULL)
2539 static void get_command(struct seq_file *m, struct scsi_cmnd * ptr)
2541 struct scsi_pointer *scsi_pointer = aha152x_scsi_pointer(ptr);
2542 const int phase = scsi_pointer->phase;
2545 seq_printf(m, "%p: target=%d; lun=%d; cmnd=( ",
2546 ptr, ptr->device->id, (u8)ptr->device->lun);
2548 for (i = 0; i < COMMAND_SIZE(ptr->cmnd[0]); i++)
2549 seq_printf(m, "0x%02x ", ptr->cmnd[i]);
2551 seq_printf(m, "); resid=%d; residual=%d; buffers=%d; phase |",
2552 scsi_get_resid(ptr), scsi_pointer->this_residual,
2553 sg_nents(scsi_pointer->buffer) - 1);
2555 if (phase & not_issued)
2556 seq_puts(m, "not issued|");
2557 if (phase & selecting)
2558 seq_puts(m, "selecting|");
2559 if (phase & disconnected)
2560 seq_puts(m, "disconnected|");
2561 if (phase & aborted)
2562 seq_puts(m, "aborted|");
2563 if (phase & identified)
2564 seq_puts(m, "identified|");
2565 if (phase & completed)
2566 seq_puts(m, "completed|");
2567 if (phase & spiordy)
2568 seq_puts(m, "spiordy|");
2569 if (phase & syncneg)
2570 seq_puts(m, "syncneg|");
2571 seq_printf(m, "; next=0x%p\n", SCNEXT(ptr));
2574 static void get_ports(struct seq_file *m, struct Scsi_Host *shpnt)
2578 seq_printf(m, "\n%s: %s(%s) ", CURRENT_SC ? "on bus" : "waiting", states[STATE].name, states[PREVSTATE].name);
2580 s = GETPORT(SCSISEQ);
2581 seq_puts(m, "SCSISEQ( ");
2583 seq_puts(m, "TARGET MODE ");
2585 seq_puts(m, "SELO ");
2587 seq_puts(m, "SELI ");
2589 seq_puts(m, "RESELI ");
2591 seq_puts(m, "AUTOATNO ");
2593 seq_puts(m, "AUTOATNI ");
2595 seq_puts(m, "AUTOATNP ");
2597 seq_puts(m, "SCSIRSTO ");
2600 seq_puts(m, " SCSISIG(");
2601 s = GETPORT(SCSISIG);
2602 switch (s & P_MASK) {
2604 seq_puts(m, "DATA OUT");
2607 seq_puts(m, "DATA IN");
2610 seq_puts(m, "COMMAND");
2613 seq_puts(m, "STATUS");
2616 seq_puts(m, "MESSAGE OUT");
2619 seq_puts(m, "MESSAGE IN");
2622 seq_puts(m, "*invalid*");
2628 seq_printf(m, "INTSTAT (%s); ", TESTHI(DMASTAT, INTSTAT) ? "hi" : "lo");
2630 seq_puts(m, "SSTAT( ");
2631 s = GETPORT(SSTAT0);
2633 seq_puts(m, "TARGET ");
2635 seq_puts(m, "SELDO ");
2637 seq_puts(m, "SELDI ");
2639 seq_puts(m, "SELINGO ");
2641 seq_puts(m, "SWRAP ");
2643 seq_puts(m, "SDONE ");
2645 seq_puts(m, "SPIORDY ");
2647 seq_puts(m, "DMADONE ");
2649 s = GETPORT(SSTAT1);
2651 seq_puts(m, "SELTO ");
2653 seq_puts(m, "ATNTARG ");
2655 seq_puts(m, "SCSIRSTI ");
2657 seq_puts(m, "PHASEMIS ");
2659 seq_puts(m, "BUSFREE ");
2661 seq_puts(m, "SCSIPERR ");
2663 seq_puts(m, "PHASECHG ");
2665 seq_puts(m, "REQINIT ");
2669 seq_puts(m, "SSTAT( ");
2671 s = GETPORT(SSTAT0) & GETPORT(SIMODE0);
2674 seq_puts(m, "TARGET ");
2676 seq_puts(m, "SELDO ");
2678 seq_puts(m, "SELDI ");
2680 seq_puts(m, "SELINGO ");
2682 seq_puts(m, "SWRAP ");
2684 seq_puts(m, "SDONE ");
2686 seq_puts(m, "SPIORDY ");
2688 seq_puts(m, "DMADONE ");
2690 s = GETPORT(SSTAT1) & GETPORT(SIMODE1);
2693 seq_puts(m, "SELTO ");
2695 seq_puts(m, "ATNTARG ");
2697 seq_puts(m, "SCSIRSTI ");
2699 seq_puts(m, "PHASEMIS ");
2701 seq_puts(m, "BUSFREE ");
2703 seq_puts(m, "SCSIPERR ");
2705 seq_puts(m, "PHASECHG ");
2707 seq_puts(m, "REQINIT ");
2710 seq_puts(m, "SXFRCTL0( ");
2712 s = GETPORT(SXFRCTL0);
2714 seq_puts(m, "SCSIEN ");
2716 seq_puts(m, "DMAEN ");
2718 seq_puts(m, "CH1 ");
2720 seq_puts(m, "CLRSTCNT ");
2722 seq_puts(m, "SPIOEN ");
2724 seq_puts(m, "CLRCH1 ");
2727 seq_puts(m, "SIGNAL( ");
2729 s = GETPORT(SCSISIG);
2731 seq_puts(m, "ATNI ");
2733 seq_puts(m, "SELI ");
2735 seq_puts(m, "BSYI ");
2737 seq_puts(m, "REQI ");
2739 seq_puts(m, "ACKI ");
2742 seq_printf(m, "SELID(%02x), ", GETPORT(SELID));
2744 seq_printf(m, "STCNT(%d), ", GETSTCNT());
2746 seq_puts(m, "SSTAT2( ");
2748 s = GETPORT(SSTAT2);
2750 seq_puts(m, "SOFFSET ");
2752 seq_puts(m, "SEMPTY ");
2754 seq_puts(m, "SFULL ");
2755 seq_printf(m, "); SFCNT (%d); ", s & (SFULL | SFCNT));
2757 s = GETPORT(SSTAT3);
2758 seq_printf(m, "SCSICNT (%d), OFFCNT(%d), ", (s & 0xf0) >> 4, s & 0x0f);
2760 seq_puts(m, "SSTAT4( ");
2761 s = GETPORT(SSTAT4);
2763 seq_puts(m, "SYNCERR ");
2765 seq_puts(m, "FWERR ");
2767 seq_puts(m, "FRERR ");
2770 seq_puts(m, "DMACNTRL0( ");
2771 s = GETPORT(DMACNTRL0);
2772 seq_printf(m, "%s ", s & _8BIT ? "8BIT" : "16BIT");
2773 seq_printf(m, "%s ", s & DMA ? "DMA" : "PIO");
2774 seq_printf(m, "%s ", s & WRITE_READ ? "WRITE" : "READ");
2776 seq_puts(m, "ENDMA ");
2778 seq_puts(m, "INTEN ");
2780 seq_puts(m, "RSTFIFO ");
2782 seq_puts(m, "SWINT ");
2785 seq_puts(m, "DMASTAT( ");
2786 s = GETPORT(DMASTAT);
2788 seq_puts(m, "ATDONE ");
2790 seq_puts(m, "WORDRDY ");
2792 seq_puts(m, "DFIFOFULL ");
2794 seq_puts(m, "DFIFOEMP ");
2797 seq_puts(m, "enabled interrupts( ");
2799 s = GETPORT(SIMODE0);
2801 seq_puts(m, "ENSELDO ");
2803 seq_puts(m, "ENSELDI ");
2805 seq_puts(m, "ENSELINGO ");
2807 seq_puts(m, "ENSWRAP ");
2809 seq_puts(m, "ENSDONE ");
2811 seq_puts(m, "ENSPIORDY ");
2813 seq_puts(m, "ENDMADONE ");
2815 s = GETPORT(SIMODE1);
2817 seq_puts(m, "ENSELTIMO ");
2819 seq_puts(m, "ENATNTARG ");
2821 seq_puts(m, "ENPHASEMIS ");
2823 seq_puts(m, "ENBUSFREE ");
2825 seq_puts(m, "ENSCSIPERR ");
2827 seq_puts(m, "ENPHASECHG ");
2829 seq_puts(m, "ENREQINIT ");
2833 static int aha152x_set_info(struct Scsi_Host *shpnt, char *buffer, int length)
2835 if(!shpnt || !buffer || length<8 || strncmp("aha152x ", buffer, 8)!=0)
2838 #if defined(AHA152X_STAT)
2839 if(length>13 && strncmp("reset", buffer+8, 5)==0) {
2842 HOSTDATA(shpnt)->total_commands=0;
2843 HOSTDATA(shpnt)->disconnections=0;
2844 HOSTDATA(shpnt)->busfree_without_any_action=0;
2845 HOSTDATA(shpnt)->busfree_without_old_command=0;
2846 HOSTDATA(shpnt)->busfree_without_new_command=0;
2847 HOSTDATA(shpnt)->busfree_without_done_command=0;
2848 HOSTDATA(shpnt)->busfree_with_check_condition=0;
2849 for (i = idle; i<maxstate; i++) {
2850 HOSTDATA(shpnt)->count[i]=0;
2851 HOSTDATA(shpnt)->count_trans[i]=0;
2852 HOSTDATA(shpnt)->time[i]=0;
2855 shost_printk(KERN_INFO, shpnt, "aha152x: stats reset.\n");
2867 static int aha152x_show_info(struct seq_file *m, struct Scsi_Host *shpnt)
2870 struct scsi_cmnd *ptr;
2871 unsigned long flags;
2873 seq_puts(m, AHA152X_REVID "\n");
2875 seq_printf(m, "ioports 0x%04lx to 0x%04lx\n",
2876 shpnt->io_port, shpnt->io_port + shpnt->n_io_port - 1);
2877 seq_printf(m, "interrupt 0x%02x\n", shpnt->irq);
2878 seq_printf(m, "disconnection/reconnection %s\n",
2879 RECONNECT ? "enabled" : "disabled");
2880 seq_printf(m, "parity checking %s\n",
2881 PARITY ? "enabled" : "disabled");
2882 seq_printf(m, "synchronous transfers %s\n",
2883 SYNCHRONOUS ? "enabled" : "disabled");
2884 seq_printf(m, "%d commands currently queued\n", HOSTDATA(shpnt)->commands);
2887 seq_puts(m, "synchronously operating targets (tick=50 ns):\n");
2888 for (i = 0; i < 8; i++)
2889 if (HOSTDATA(shpnt)->syncrate[i] & 0x7f)
2890 seq_printf(m, "target %d: period %dT/%dns; req/ack offset %d\n",
2892 (((HOSTDATA(shpnt)->syncrate[i] & 0x70) >> 4) + 2),
2893 (((HOSTDATA(shpnt)->syncrate[i] & 0x70) >> 4) + 2) * 50,
2894 HOSTDATA(shpnt)->syncrate[i] & 0x0f);
2896 seq_puts(m, "\nqueue status:\n");
2899 seq_puts(m, "not yet issued commands:\n");
2900 for (ptr = ISSUE_SC; ptr; ptr = SCNEXT(ptr))
2901 get_command(m, ptr);
2903 seq_puts(m, "no not yet issued commands\n");
2907 seq_puts(m, "current command:\n");
2908 get_command(m, CURRENT_SC);
2910 seq_puts(m, "no current command\n");
2912 if (DISCONNECTED_SC) {
2913 seq_puts(m, "disconnected commands:\n");
2914 for (ptr = DISCONNECTED_SC; ptr; ptr = SCNEXT(ptr))
2915 get_command(m, ptr);
2917 seq_puts(m, "no disconnected commands\n");
2919 get_ports(m, shpnt);
2921 #if defined(AHA152X_STAT)
2922 seq_printf(m, "statistics:\n"
2923 "total commands: %d\n"
2924 "disconnections: %d\n"
2925 "busfree with check condition: %d\n"
2926 "busfree without old command: %d\n"
2927 "busfree without new command: %d\n"
2928 "busfree without done command: %d\n"
2929 "busfree without any action: %d\n"
2934 HOSTDATA(shpnt)->total_commands,
2935 HOSTDATA(shpnt)->disconnections,
2936 HOSTDATA(shpnt)->busfree_with_check_condition,
2937 HOSTDATA(shpnt)->busfree_without_old_command,
2938 HOSTDATA(shpnt)->busfree_without_new_command,
2939 HOSTDATA(shpnt)->busfree_without_done_command,
2940 HOSTDATA(shpnt)->busfree_without_any_action);
2941 for(i=0; i<maxstate; i++) {
2942 seq_printf(m, "%-10s %-12d %-12d %-12ld\n",
2944 HOSTDATA(shpnt)->count_trans[i],
2945 HOSTDATA(shpnt)->count[i],
2946 HOSTDATA(shpnt)->time[i]);
2952 static int aha152x_adjust_queue(struct scsi_device *device)
2954 blk_queue_bounce_limit(device->request_queue, BLK_BOUNCE_HIGH);
2958 static struct scsi_host_template aha152x_driver_template = {
2959 .module = THIS_MODULE,
2960 .name = AHA152X_REVID,
2961 .proc_name = "aha152x",
2962 .show_info = aha152x_show_info,
2963 .write_info = aha152x_set_info,
2964 .queuecommand = aha152x_queue,
2965 .eh_abort_handler = aha152x_abort,
2966 .eh_device_reset_handler = aha152x_device_reset,
2967 .eh_bus_reset_handler = aha152x_bus_reset,
2968 .bios_param = aha152x_biosparam,
2971 .sg_tablesize = SG_ALL,
2972 .dma_boundary = PAGE_SIZE - 1,
2973 .slave_alloc = aha152x_adjust_queue,
2974 .cmd_size = sizeof(struct aha152x_cmd_priv),
2977 #if !defined(AHA152X_PCMCIA)
2978 static int setup_count;
2979 static struct aha152x_setup setup[2];
2981 /* possible i/o addresses for the AIC-6260; default first */
2982 static unsigned short ports[] = { 0x340, 0x140 };
2984 #if !defined(SKIP_BIOSTEST)
2985 /* possible locations for the Adaptec BIOS; defaults first */
2986 static unsigned int addresses[] =
2988 0xdc000, /* default first */
2995 0xeb800, /* VTech Platinum SMP */
2999 /* signatures for various AIC-6[23]60 based controllers.
3000 The point in detecting signatures is to avoid useless and maybe
3001 harmful probes on ports. I'm not sure that all listed boards pass
3002 auto-configuration. For those which fail the BIOS signature is
3003 obsolete, because user intervention to supply the configuration is
3004 needed anyway. May be an information whether or not the BIOS supports
3005 extended translation could be also useful here. */
3006 static struct signature {
3007 unsigned char *signature;
3012 { "Adaptec AHA-1520 BIOS", 0x102e, 21 },
3014 { "Adaptec AHA-1520B", 0x000b, 17 },
3015 /* Adaptec 152x rev B */
3016 { "Adaptec AHA-1520B", 0x0026, 17 },
3017 /* Iomega Jaz Jet ISA (AIC6370Q) */
3018 { "Adaptec ASW-B626 BIOS", 0x1029, 21 },
3019 /* on-board controller */
3020 { "Adaptec BIOS: ASW-B626", 0x000f, 22 },
3021 /* on-board controller */
3022 { "Adaptec ASW-B626 S2", 0x2e6c, 19 },
3023 /* on-board controller */
3024 { "Adaptec BIOS:AIC-6360", 0x000c, 21 },
3025 /* on-board controller */
3026 { "ScsiPro SP-360 BIOS", 0x2873, 19 },
3027 /* ScsiPro-Controller */
3028 { "GA-400 LOCAL BUS SCSI BIOS", 0x102e, 26 },
3029 /* Gigabyte Local-Bus-SCSI */
3030 { "Adaptec BIOS:AVA-282X", 0x000c, 21 },
3032 { "Adaptec IBM Dock II SCSI", 0x2edd, 24 },
3033 /* IBM Thinkpad Dock II */
3034 { "Adaptec BIOS:AHA-1532P", 0x001c, 22 },
3035 /* IBM Thinkpad Dock II SCSI */
3036 { "DTC3520A Host Adapter BIOS", 0x318a, 26 },
3037 /* DTC 3520A ISA SCSI */
3039 #endif /* !SKIP_BIOSTEST */
3042 * Test, if port_base is valid.
3045 static int aha152x_porttest(int io_port)
3049 SETPORT(io_port + O_DMACNTRL1, 0); /* reset stack pointer */
3050 for (i = 0; i < 16; i++)
3051 SETPORT(io_port + O_STACK, i);
3053 SETPORT(io_port + O_DMACNTRL1, 0); /* reset stack pointer */
3054 for (i = 0; i < 16 && GETPORT(io_port + O_STACK) == i; i++)
3060 static int tc1550_porttest(int io_port)
3064 SETPORT(io_port + O_TC_DMACNTRL1, 0); /* reset stack pointer */
3065 for (i = 0; i < 16; i++)
3066 SETPORT(io_port + O_STACK, i);
3068 SETPORT(io_port + O_TC_DMACNTRL1, 0); /* reset stack pointer */
3069 for (i = 0; i < 16 && GETPORT(io_port + O_TC_STACK) == i; i++)
3076 static int checksetup(struct aha152x_setup *setup)
3079 for (i = 0; i < ARRAY_SIZE(ports) && (setup->io_port != ports[i]); i++)
3082 if (i == ARRAY_SIZE(ports))
3085 if (!request_region(setup->io_port, IO_RANGE, "aha152x")) {
3086 printk(KERN_ERR "aha152x: io port 0x%x busy.\n", setup->io_port);
3090 if( aha152x_porttest(setup->io_port) ) {
3092 } else if( tc1550_porttest(setup->io_port) ) {
3095 release_region(setup->io_port, IO_RANGE);
3099 release_region(setup->io_port, IO_RANGE);
3101 if ((setup->irq < IRQ_MIN) || (setup->irq > IRQ_MAX))
3104 if ((setup->scsiid < 0) || (setup->scsiid > 7))
3107 if ((setup->reconnect < 0) || (setup->reconnect > 1))
3110 if ((setup->parity < 0) || (setup->parity > 1))
3113 if ((setup->synchronous < 0) || (setup->synchronous > 1))
3116 if ((setup->ext_trans < 0) || (setup->ext_trans > 1))
3124 static int __init aha152x_init(void)
3127 #if defined(AUTOCONF)
3128 aha152x_config conf;
3131 struct pnp_dev *dev=NULL, *pnpdev[2] = {NULL, NULL};
3134 if ( setup_count ) {
3135 printk(KERN_INFO "aha152x: processing commandline: ");
3137 for (i = 0; i<setup_count; i++) {
3138 if (!checksetup(&setup[i])) {
3139 printk(KERN_ERR "\naha152x: %s\n", setup[i].conf);
3140 printk(KERN_ERR "aha152x: invalid line\n");
3147 if (setup_count < ARRAY_SIZE(setup)) {
3148 struct aha152x_setup override = SETUP0;
3150 if (setup_count == 0 || (override.io_port != setup[0].io_port)) {
3151 if (!checksetup(&override)) {
3152 printk(KERN_ERR "\naha152x: invalid override SETUP0={0x%x,%d,%d,%d,%d,%d,%d,%d}\n",
3158 override.synchronous,
3160 override.ext_trans);
3162 setup[setup_count++] = override;
3168 if (setup_count < ARRAY_SIZE(setup)) {
3169 struct aha152x_setup override = SETUP1;
3171 if (setup_count == 0 || (override.io_port != setup[0].io_port)) {
3172 if (!checksetup(&override)) {
3173 printk(KERN_ERR "\naha152x: invalid override SETUP1={0x%x,%d,%d,%d,%d,%d,%d,%d}\n",
3179 override.synchronous,
3181 override.ext_trans);
3183 setup[setup_count++] = override;
3189 if (setup_count<ARRAY_SIZE(setup) && (aha152x[0]!=0 || io[0]!=0 || irq[0]!=0)) {
3191 setup[setup_count].conf = "";
3192 setup[setup_count].io_port = aha152x[0];
3193 setup[setup_count].irq = aha152x[1];
3194 setup[setup_count].scsiid = aha152x[2];
3195 setup[setup_count].reconnect = aha152x[3];
3196 setup[setup_count].parity = aha152x[4];
3197 setup[setup_count].synchronous = aha152x[5];
3198 setup[setup_count].delay = aha152x[6];
3199 setup[setup_count].ext_trans = aha152x[7];
3200 } else if (io[0] != 0 || irq[0] != 0) {
3201 if(io[0]!=0) setup[setup_count].io_port = io[0];
3202 if(irq[0]!=0) setup[setup_count].irq = irq[0];
3204 setup[setup_count].scsiid = scsiid[0];
3205 setup[setup_count].reconnect = reconnect[0];
3206 setup[setup_count].parity = parity[0];
3207 setup[setup_count].synchronous = sync[0];
3208 setup[setup_count].delay = delay[0];
3209 setup[setup_count].ext_trans = exttrans[0];
3212 if (checksetup(&setup[setup_count]))
3215 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",
3216 setup[setup_count].io_port,
3217 setup[setup_count].irq,
3218 setup[setup_count].scsiid,
3219 setup[setup_count].reconnect,
3220 setup[setup_count].parity,
3221 setup[setup_count].synchronous,
3222 setup[setup_count].delay,
3223 setup[setup_count].ext_trans);
3226 if (setup_count<ARRAY_SIZE(setup) && (aha152x1[0]!=0 || io[1]!=0 || irq[1]!=0)) {
3227 if(aha152x1[0]!=0) {
3228 setup[setup_count].conf = "";
3229 setup[setup_count].io_port = aha152x1[0];
3230 setup[setup_count].irq = aha152x1[1];
3231 setup[setup_count].scsiid = aha152x1[2];
3232 setup[setup_count].reconnect = aha152x1[3];
3233 setup[setup_count].parity = aha152x1[4];
3234 setup[setup_count].synchronous = aha152x1[5];
3235 setup[setup_count].delay = aha152x1[6];
3236 setup[setup_count].ext_trans = aha152x1[7];
3237 } else if (io[1] != 0 || irq[1] != 0) {
3238 if(io[1]!=0) setup[setup_count].io_port = io[1];
3239 if(irq[1]!=0) setup[setup_count].irq = irq[1];
3241 setup[setup_count].scsiid = scsiid[1];
3242 setup[setup_count].reconnect = reconnect[1];
3243 setup[setup_count].parity = parity[1];
3244 setup[setup_count].synchronous = sync[1];
3245 setup[setup_count].delay = delay[1];
3246 setup[setup_count].ext_trans = exttrans[1];
3248 if (checksetup(&setup[setup_count]))
3251 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",
3252 setup[setup_count].io_port,
3253 setup[setup_count].irq,
3254 setup[setup_count].scsiid,
3255 setup[setup_count].reconnect,
3256 setup[setup_count].parity,
3257 setup[setup_count].synchronous,
3258 setup[setup_count].delay,
3259 setup[setup_count].ext_trans);
3264 for(i=0; setup_count<ARRAY_SIZE(setup) && id_table[i].vendor; i++) {
3265 while ( setup_count<ARRAY_SIZE(setup) &&
3266 (dev=pnp_find_dev(NULL, id_table[i].vendor, id_table[i].function, dev)) ) {
3267 if (pnp_device_attach(dev) < 0)
3270 if (pnp_activate_dev(dev) < 0) {
3271 pnp_device_detach(dev);
3275 if (!pnp_port_valid(dev, 0)) {
3276 pnp_device_detach(dev);
3280 if (setup_count==1 && pnp_port_start(dev, 0)==setup[0].io_port) {
3281 pnp_device_detach(dev);
3285 setup[setup_count].io_port = pnp_port_start(dev, 0);
3286 setup[setup_count].irq = pnp_irq(dev, 0);
3287 setup[setup_count].scsiid = 7;
3288 setup[setup_count].reconnect = 1;
3289 setup[setup_count].parity = 1;
3290 setup[setup_count].synchronous = 1;
3291 setup[setup_count].delay = DELAY_DEFAULT;
3292 setup[setup_count].ext_trans = 0;
3293 #if defined(__ISAPNP__)
3294 pnpdev[setup_count] = dev;
3297 "aha152x: found ISAPnP adapter at io=0x%03x, irq=%d\n",
3298 setup[setup_count].io_port, setup[setup_count].irq);
3304 #if defined(AUTOCONF)
3305 if (setup_count<ARRAY_SIZE(setup)) {
3306 #if !defined(SKIP_BIOSTEST)
3308 for (i = 0; i < ARRAY_SIZE(addresses) && !ok; i++) {
3309 void __iomem *p = ioremap(addresses[i], 0x4000);
3312 for (j = 0; j<ARRAY_SIZE(signatures) && !ok; j++)
3313 ok = check_signature(p + signatures[j].sig_offset,
3314 signatures[j].signature, signatures[j].sig_length);
3317 if (!ok && setup_count == 0)
3320 printk(KERN_INFO "aha152x: BIOS test: passed, ");
3322 printk(KERN_INFO "aha152x: ");
3323 #endif /* !SKIP_BIOSTEST */
3326 for (i = 0; i < ARRAY_SIZE(ports) && setup_count < 2; i++) {
3327 if ((setup_count == 1) && (setup[0].io_port == ports[i]))
3330 if (!request_region(ports[i], IO_RANGE, "aha152x")) {
3331 printk(KERN_ERR "aha152x: io port 0x%x busy.\n", ports[i]);
3335 if (aha152x_porttest(ports[i])) {
3336 setup[setup_count].tc1550 = 0;
3339 (GETPORT(ports[i] + O_PORTA) << 8) + GETPORT(ports[i] + O_PORTB);
3340 } else if (tc1550_porttest(ports[i])) {
3341 setup[setup_count].tc1550 = 1;
3344 (GETPORT(ports[i] + O_TC_PORTA) << 8) + GETPORT(ports[i] + O_TC_PORTB);
3346 release_region(ports[i], IO_RANGE);
3350 release_region(ports[i], IO_RANGE);
3353 setup[setup_count].io_port = ports[i];
3354 setup[setup_count].irq = IRQ_MIN + conf.cf_irq;
3355 setup[setup_count].scsiid = conf.cf_id;
3356 setup[setup_count].reconnect = conf.cf_tardisc;
3357 setup[setup_count].parity = !conf.cf_parity;
3358 setup[setup_count].synchronous = conf.cf_syncneg;
3359 setup[setup_count].delay = DELAY_DEFAULT;
3360 setup[setup_count].ext_trans = 0;
3366 printk("auto configuration: ok, ");
3370 printk("%d controller(s) configured\n", setup_count);
3372 for (i=0; i<setup_count; i++) {
3373 if ( request_region(setup[i].io_port, IO_RANGE, "aha152x") ) {
3374 struct Scsi_Host *shpnt = aha152x_probe_one(&setup[i]);
3377 release_region(setup[i].io_port, IO_RANGE);
3378 #if defined(__ISAPNP__)
3379 } else if( pnpdev[i] ) {
3380 HOSTDATA(shpnt)->pnpdev=pnpdev[i];
3385 printk(KERN_ERR "aha152x: io port 0x%x busy.\n", setup[i].io_port);
3388 #if defined(__ISAPNP__)
3390 pnp_device_detach(pnpdev[i]);
3397 static void __exit aha152x_exit(void)
3399 struct aha152x_hostdata *hd, *tmp;
3401 list_for_each_entry_safe(hd, tmp, &aha152x_host_list, host_list) {
3402 struct Scsi_Host *shost = container_of((void *)hd, struct Scsi_Host, hostdata);
3404 aha152x_release(shost);
3408 module_init(aha152x_init);
3409 module_exit(aha152x_exit);
3411 #if !defined(MODULE)
3412 static int __init aha152x_setup(char *str)
3416 get_options(str, ARRAY_SIZE(ints), ints);
3418 if(setup_count>=ARRAY_SIZE(setup)) {
3419 printk(KERN_ERR "aha152x: you can only configure up to two controllers\n");
3423 setup[setup_count].conf = str;
3424 setup[setup_count].io_port = ints[0] >= 1 ? ints[1] : 0x340;
3425 setup[setup_count].irq = ints[0] >= 2 ? ints[2] : 11;
3426 setup[setup_count].scsiid = ints[0] >= 3 ? ints[3] : 7;
3427 setup[setup_count].reconnect = ints[0] >= 4 ? ints[4] : 1;
3428 setup[setup_count].parity = ints[0] >= 5 ? ints[5] : 1;
3429 setup[setup_count].synchronous = ints[0] >= 6 ? ints[6] : 1;
3430 setup[setup_count].delay = ints[0] >= 7 ? ints[7] : DELAY_DEFAULT;
3431 setup[setup_count].ext_trans = ints[0] >= 8 ? ints[8] : 0;
3433 printk(KERN_NOTICE "aha152x: usage: aha152x=<IOBASE>[,<IRQ>[,<SCSI ID>"
3434 "[,<RECONNECT>[,<PARITY>[,<SYNCHRONOUS>[,<DELAY>[,<EXT_TRANS>]]]]]]]\n");
3440 __setup("aha152x=", aha152x_setup);
3443 #endif /* !AHA152X_PCMCIA */