1 /* $Id: aha1542.c,v 1.1 1992/07/24 06:27:38 root Exp root $
2 * linux/kernel/aha1542.c
4 * Copyright (C) 1992 Tommy Thorn
5 * Copyright (C) 1993, 1994, 1995 Eric Youngdale
7 * Modified by Eric Youngdale
8 * Use request_irq and request_dma to help prevent unexpected conflicts
9 * Set up on-board DMA controller, such that we do not have to
10 * have the bios enabled to use the aha1542.
11 * Modified by David Gentzel
12 * Don't call request_dma if dma mask is 0 (for BusLogic BT-445S VL-Bus
14 * Modified by Matti Aarnio
15 * Accept parameters from LILO cmd-line. -- 1-Oct-94
16 * Modified by Mike McLagan <mike.mclagan@linux.org>
17 * Recognise extended mode on AHA1542CP, different bit than 1542CF
19 * Modified by Bjorn L. Thordarson and Einar Thor Einarsson
20 * Recognize that DMA0 is valid DMA channel -- 13-Jul-98
21 * Modified by Chris Faulhaber <jedgar@fxp.org>
22 * Added module command-line options
24 * Modified by Adam Fritzler <mid@auk.cx>
25 * Added proper detection of the AHA-1640 (MCA version of AHA-1540)
28 #include <linux/config.h>
29 #include <linux/module.h>
31 #include <linux/kernel.h>
32 #include <linux/types.h>
33 #include <linux/string.h>
34 #include <linux/ioport.h>
35 #include <linux/delay.h>
36 #include <linux/sched.h>
37 #include <linux/proc_fs.h>
38 #include <linux/init.h>
39 #include <linux/spinlock.h>
40 #include <linux/pci.h>
41 #include <linux/isapnp.h>
43 #include <asm/system.h>
45 #include <linux/blk.h>
46 #include <linux/mca.h>
54 #define SCSI_PA(address) virt_to_bus(address)
56 static void BAD_DMA(void *address, unsigned int length)
58 printk(KERN_CRIT "buf vaddress %p paddress 0x%lx length %d\n",
62 panic("Buffer at physical address > 16Mb used for aha1542");
65 static void BAD_SG_DMA(Scsi_Cmnd * SCpnt,
66 struct scatterlist *sgpnt,
70 printk(KERN_CRIT "sgpnt[%d:%d] addr %p/0x%lx length %d\n",
72 sgpnt[badseg].address,
73 SCSI_PA(sgpnt[badseg].address),
74 sgpnt[badseg].length);
77 * Not safe to continue.
79 panic("Buffer at physical address > 16Mb used for aha1542");
82 #include<linux/stat.h>
91 static const char RCSid[] = "$Header: /usr/src/linux/kernel/blk_drv/scsi/RCS/aha1542.c,v 1.1 1992/07/24 06:27:38 root Exp root $";
94 /* The adaptec can be configured for quite a number of addresses, but
95 I generally do not want the card poking around at random. We allow
96 two addresses - this allows people to use the Adaptec with a Midi
97 card, which also used 0x330 -- can be overridden with LILO! */
99 #define MAXBOARDS 4 /* Increase this and the sizes of the
100 arrays below, if you need more.. */
102 /* Boards 3,4 slots are reserved for ISAPnP/MCA scans */
104 static unsigned int bases[MAXBOARDS] __initdata = {0x330, 0x334, 0, 0};
106 /* set by aha1542_setup according to the command line; they also may
107 be marked __initdata, but require zero initializers then */
109 static int setup_called[MAXBOARDS];
110 static int setup_buson[MAXBOARDS];
111 static int setup_busoff[MAXBOARDS];
112 static int setup_dmaspeed[MAXBOARDS] __initdata = { -1, -1, -1, -1 };
115 * LILO/Module params: aha1542=<PORTBASE>[,<BUSON>,<BUSOFF>[,<DMASPEED>]]
117 * Where: <PORTBASE> is any of the valid AHA addresses:
118 * 0x130, 0x134, 0x230, 0x234, 0x330, 0x334
119 * <BUSON> is the time (in microsecs) that AHA spends on the AT-bus
120 * when transferring data. 1542A power-on default is 11us,
121 * valid values are in range: 2..15 (decimal)
122 * <BUSOFF> is the time that AHA spends OFF THE BUS after while
123 * it is transferring data (not to monopolize the bus).
124 * Power-on default is 4us, valid range: 1..64 microseconds.
125 * <DMASPEED> Default is jumper selected (1542A: on the J1),
126 * but experimenter can alter it with this.
127 * Valid values: 5, 6, 7, 8, 10 (MB/s)
128 * Factory default is 5 MB/s.
133 int aha1542[] = {0x330, 11, 4, -1};
134 MODULE_PARM(aha1542, "1-4i");
135 MODULE_PARM(isapnp, "i");
137 static struct isapnp_device_id id_table[] __initdata = {
139 ISAPNP_ANY_ID, ISAPNP_ANY_ID,
140 ISAPNP_VENDOR('A', 'D', 'P'), ISAPNP_FUNCTION(0x1542),
146 MODULE_DEVICE_TABLE(isapnp, id_table);
149 static int isapnp = 1;
152 #define BIOS_TRANSLATION_1632 0 /* Used by some old 1542A boards */
153 #define BIOS_TRANSLATION_6432 1 /* Default case these days */
154 #define BIOS_TRANSLATION_25563 2 /* Big disk case */
156 struct aha1542_hostdata {
157 /* This will effectively start both of them at the first mailbox */
158 int bios_translation; /* Mapping bios uses - for compatibility */
159 int aha1542_last_mbi_used;
160 int aha1542_last_mbo_used;
161 Scsi_Cmnd *SCint[AHA1542_MAILBOXES];
162 struct mailbox mb[2 * AHA1542_MAILBOXES];
163 struct ccb ccb[AHA1542_MAILBOXES];
166 #define HOSTDATA(host) ((struct aha1542_hostdata *) &host->hostdata)
168 static struct Scsi_Host *aha_host[7]; /* One for each IRQ level (9-15) */
173 #define WAITnexttimeout 3000000
175 static void setup_mailboxes(int base_io, struct Scsi_Host *shpnt);
176 static int aha1542_restart(struct Scsi_Host *shost);
177 static void aha1542_intr_handle(int irq, void *dev_id, struct pt_regs *regs);
178 static void do_aha1542_intr_handle(int irq, void *dev_id, struct pt_regs *regs);
180 #define aha1542_intr_reset(base) outb(IRST, CONTROL(base))
182 #define WAIT(port, mask, allof, noneof) \
183 { register int WAITbits; \
184 register int WAITtimeout = WAITnexttimeout; \
186 WAITbits = inb(port) & (mask); \
187 if ((WAITbits & (allof)) == (allof) && ((WAITbits & (noneof)) == 0)) \
189 if (--WAITtimeout == 0) goto fail; \
193 /* Similar to WAIT, except we use the udelay call to regulate the
194 amount of time we wait. */
195 #define WAITd(port, mask, allof, noneof, timeout) \
196 { register int WAITbits; \
197 register int WAITtimeout = timeout; \
199 WAITbits = inb(port) & (mask); \
200 if ((WAITbits & (allof)) == (allof) && ((WAITbits & (noneof)) == 0)) \
203 if (--WAITtimeout == 0) goto fail; \
207 static void aha1542_stat(void)
209 /* int s = inb(STATUS), i = inb(INTRFLAGS);
210 printk("status=%x intrflags=%x\n", s, i, WAITnexttimeout-WAITtimeout); */
213 /* This is a bit complicated, but we need to make sure that an interrupt
214 routine does not send something out while we are in the middle of this.
215 Fortunately, it is only at boot time that multi-byte messages
217 static int aha1542_out(unsigned int base, unchar * cmdp, int len)
219 unsigned long flags = 0;
224 WAIT(STATUS(base), CDF, 0, CDF);
226 if (inb(STATUS(base)) & CDF) {
227 restore_flags(flags);
230 outb(*cmdp, DATA(base));
231 restore_flags(flags);
237 WAIT(STATUS(base), CDF, 0, CDF);
238 outb(*cmdp++, DATA(base));
240 restore_flags(flags);
244 restore_flags(flags);
245 printk(KERN_ERR "aha1542_out failed(%d): ", len + 1);
250 /* Only used at boot time, so we do not need to worry about latency as much
253 static int __init aha1542_in(unsigned int base, unchar * cmdp, int len)
260 WAIT(STATUS(base), DF, DF, 0);
261 *cmdp++ = inb(DATA(base));
263 restore_flags(flags);
266 restore_flags(flags);
267 printk(KERN_ERR "aha1542_in failed(%d): ", len + 1);
272 /* Similar to aha1542_in, except that we wait a very short period of time.
273 We use this if we know the board is alive and awake, but we are not sure
274 if the board will respond to the command we are about to send or not */
275 static int __init aha1542_in1(unsigned int base, unchar * cmdp, int len)
282 WAITd(STATUS(base), DF, DF, 0, 100);
283 *cmdp++ = inb(DATA(base));
285 restore_flags(flags);
288 restore_flags(flags);
292 static int makecode(unsigned hosterr, unsigned scsierr)
296 case 0xa: /* Linked command complete without error and linked normally */
297 case 0xb: /* Linked command complete without error, interrupt generated */
301 case 0x11: /* Selection time out-The initiator selection or target
302 reselection was not complete within the SCSI Time out period */
303 hosterr = DID_TIME_OUT;
306 case 0x12: /* Data overrun/underrun-The target attempted to transfer more data
307 than was allocated by the Data Length field or the sum of the
308 Scatter / Gather Data Length fields. */
310 case 0x13: /* Unexpected bus free-The target dropped the SCSI BSY at an unexpected time. */
312 case 0x15: /* MBO command was not 00, 01 or 02-The first byte of the CB was
313 invalid. This usually indicates a software failure. */
315 case 0x16: /* Invalid CCB Operation Code-The first byte of the CCB was invalid.
316 This usually indicates a software failure. */
318 case 0x17: /* Linked CCB does not have the same LUN-A subsequent CCB of a set
319 of linked CCB's does not specify the same logical unit number as
321 case 0x18: /* Invalid Target Direction received from Host-The direction of a
322 Target Mode CCB was invalid. */
324 case 0x19: /* Duplicate CCB Received in Target Mode-More than once CCB was
325 received to service data transfer between the same target LUN
326 and initiator SCSI ID in the same direction. */
328 case 0x1a: /* Invalid CCB or Segment List Parameter-A segment list with a zero
329 length segment or invalid segment list boundaries was received.
330 A CCB parameter was invalid. */
331 DEB(printk("Aha1542: %x %x\n", hosterr, scsierr));
332 hosterr = DID_ERROR; /* Couldn't find any better */
335 case 0x14: /* Target bus phase sequence failure-An invalid bus phase or bus
336 phase sequence was requested by the target. The host adapter
337 will generate a SCSI Reset Condition, notifying the host with
342 printk(KERN_ERR "aha1542: makecode: unknown hoststatus %x\n", hosterr);
345 return scsierr | (hosterr << 16);
348 static int __init aha1542_test_port(int bse, struct Scsi_Host *shpnt)
350 unchar inquiry_cmd[] = {CMD_INQUIRY};
351 unchar inquiry_result[4];
354 volatile int debug = 0;
356 /* Quick and dirty test for presence of the card. */
357 if (inb(STATUS(bse)) == 0xff)
360 /* Reset the adapter. I ought to make a hard reset, but it's not really necessary */
362 /* DEB(printk("aha1542_test_port called \n")); */
364 /* In case some other card was probing here, reset interrupts */
365 aha1542_intr_reset(bse); /* reset interrupts, so they don't block */
367 outb(SRST | IRST /*|SCRST */ , CONTROL(bse));
369 mdelay(20); /* Wait a little bit for things to settle down. */
372 /* Expect INIT and IDLE, any of the others are bad */
373 WAIT(STATUS(bse), STATMASK, INIT | IDLE, STST | DIAGF | INVDCMD | DF | CDF);
376 /* Shouldn't have generated any interrupts during reset */
377 if (inb(INTRFLAGS(bse)) & INTRMASK)
381 /* Perform a host adapter inquiry instead so we do not need to set
382 up the mailboxes ahead of time */
384 aha1542_out(bse, inquiry_cmd, 1);
388 cmdp = &inquiry_result[0];
391 WAIT(STATUS(bse), DF, DF, 0);
392 *cmdp++ = inb(DATA(bse));
396 /* Reading port should reset DF */
397 if (inb(STATUS(bse)) & DF)
401 /* When HACC, command is completed, and we're though testing */
402 WAIT(INTRFLAGS(bse), HACC, HACC, 0);
403 /* now initialize adapter */
406 /* Clear interrupts */
407 outb(IRST, CONTROL(bse));
411 return debug; /* 1 = ok */
413 return 0; /* 0 = not ok */
416 /* A quick wrapper for do_aha1542_intr_handle to grab the spin lock */
417 static void do_aha1542_intr_handle(int irq, void *dev_id, struct pt_regs *regs)
421 spin_lock_irqsave(&io_request_lock, flags);
422 aha1542_intr_handle(irq, dev_id, regs);
423 spin_unlock_irqrestore(&io_request_lock, flags);
426 /* A "high" level interrupt handler */
427 static void aha1542_intr_handle(int irq, void *dev_id, struct pt_regs *regs)
429 void (*my_done) (Scsi_Cmnd *) = NULL;
430 int errstatus, mbi, mbo, mbistatus;
433 struct Scsi_Host *shost;
440 shost = aha_host[irq - 9];
444 mb = HOSTDATA(shost)->mb;
445 ccb = HOSTDATA(shost)->ccb;
449 flag = inb(INTRFLAGS(shost->io_port));
450 printk(KERN_DEBUG "aha1542_intr_handle: ");
451 if (!(flag & ANYINTR))
452 printk("no interrupt?");
461 printk("status %02x\n", inb(STATUS(shost->io_port)));
468 flag = inb(INTRFLAGS(shost->io_port));
470 /* Check for unusual interrupts. If any of these happen, we should
471 probably do something special, but for now just printing a message
472 is sufficient. A SCSI reset detected is something that we really
473 need to deal with in some way. */
484 aha1542_intr_reset(shost->io_port);
488 mbi = HOSTDATA(shost)->aha1542_last_mbi_used + 1;
489 if (mbi >= 2 * AHA1542_MAILBOXES)
490 mbi = AHA1542_MAILBOXES;
493 if (mb[mbi].status != 0)
496 if (mbi >= 2 * AHA1542_MAILBOXES)
497 mbi = AHA1542_MAILBOXES;
498 } while (mbi != HOSTDATA(shost)->aha1542_last_mbi_used);
500 if (mb[mbi].status == 0) {
501 restore_flags(flags);
502 /* Hmm, no mail. Must have read it the last time around */
503 if (!number_serviced && !needs_restart)
504 printk(KERN_WARNING "aha1542.c: interrupt received, but no mail.\n");
505 /* We detected a reset. Restart all pending commands for
506 devices that use the hard reset option */
508 aha1542_restart(shost);
512 mbo = (scsi2int(mb[mbi].ccbptr) - (SCSI_PA(&ccb[0]))) / sizeof(struct ccb);
513 mbistatus = mb[mbi].status;
515 HOSTDATA(shost)->aha1542_last_mbi_used = mbi;
516 restore_flags(flags);
520 if (ccb[mbo].tarstat | ccb[mbo].hastat)
521 printk(KERN_DEBUG "aha1542_command: returning %x (status %d)\n",
522 ccb[mbo].tarstat + ((int) ccb[mbo].hastat << 16), mb[mbi].status);
527 continue; /* Aborted command not found */
530 printk(KERN_DEBUG "...done %d %d\n", mbo, mbi);
533 SCtmp = HOSTDATA(shost)->SCint[mbo];
535 if (!SCtmp || !SCtmp->scsi_done) {
536 printk(KERN_WARNING "aha1542_intr_handle: Unexpected interrupt\n");
537 printk(KERN_WARNING "tarstat=%x, hastat=%x idlun=%x ccb#=%d \n", ccb[mbo].tarstat,
538 ccb[mbo].hastat, ccb[mbo].idlun, mbo);
541 my_done = SCtmp->scsi_done;
542 if (SCtmp->host_scribble) {
543 scsi_free(SCtmp->host_scribble, 512);
544 SCtmp->host_scribble = 0;
546 /* Fetch the sense data, and tuck it away, in the required slot. The
547 Adaptec automatically fetches it, and there is no guarantee that
548 we will still have it in the cdb when we come back */
549 if (ccb[mbo].tarstat == 2)
550 memcpy(SCtmp->sense_buffer, &ccb[mbo].cdb[ccb[mbo].cdblen],
551 sizeof(SCtmp->sense_buffer));
554 /* is there mail :-) */
556 /* more error checking left out here */
558 /* This is surely wrong, but I don't know what's right */
559 errstatus = makecode(ccb[mbo].hastat, ccb[mbo].tarstat);
565 printk(KERN_DEBUG "(aha1542 error:%x %x %x) ", errstatus,
566 ccb[mbo].hastat, ccb[mbo].tarstat);
569 if (ccb[mbo].tarstat == 2) {
573 DEB(printk("aha1542_intr_handle: sense:"));
575 for (i = 0; i < 12; i++)
576 printk("%02x ", ccb[mbo].cdb[ccb[mbo].cdblen + i]);
580 DEB(printk("aha1542_intr_handle: buf:"));
581 for (i = 0; i < bufflen; i++)
582 printk("%02x ", ((unchar *)buff)[i]);
586 DEB(if (errstatus) printk("aha1542_intr_handle: returning %6x\n", errstatus));
587 SCtmp->result = errstatus;
588 HOSTDATA(shost)->SCint[mbo] = NULL; /* This effectively frees up the mailbox slot, as
589 far as queuecommand is concerned */
595 static int aha1542_queuecommand(Scsi_Cmnd * SCpnt, void (*done) (Scsi_Cmnd *))
597 unchar ahacmd = CMD_START_SCSI;
599 unchar *cmd = (unchar *) SCpnt->cmnd;
600 unchar target = SCpnt->target;
601 unchar lun = SCpnt->lun;
603 void *buff = SCpnt->request_buffer;
604 int bufflen = SCpnt->request_bufflen;
611 mb = HOSTDATA(SCpnt->host)->mb;
612 ccb = HOSTDATA(SCpnt->host)->ccb;
614 DEB(if (target > 1) {
615 SCpnt->result = DID_TIME_OUT << 16;
616 done(SCpnt); return 0;
620 if (*cmd == REQUEST_SENSE) {
621 /* Don't do the command - we have the sense data already */
623 /* scsi_request_sense() provides a buffer of size 256,
624 so there is no reason to expect equality */
625 if (bufflen != sizeof(SCpnt->sense_buffer))
626 printk(KERN_CRIT "aha1542: Wrong buffer length supplied "
627 "for request sense (%d)\n", bufflen);
634 if (*cmd == READ_10 || *cmd == WRITE_10)
635 i = xscsi2int(cmd + 2);
636 else if (*cmd == READ_6 || *cmd == WRITE_6)
637 i = scsi2int(cmd + 2);
641 printk(KERN_DEBUG "aha1542_queuecommand: dev %d cmd %02x pos %d len %d ", target, *cmd, i, bufflen);
643 printk(KERN_DEBUG "aha1542_command: dev %d cmd %02x pos %d len %d ", target, *cmd, i, bufflen);
645 printk(KERN_DEBUG "aha1542_queuecommand: dumping scsi cmd:");
646 for (i = 0; i < SCpnt->cmd_len; i++)
647 printk("%02x ", cmd[i]);
649 if (*cmd == WRITE_10 || *cmd == WRITE_6)
650 return 0; /* we are still testing, so *don't* write */
652 /* Use the outgoing mailboxes in a round-robin fashion, because this
653 is how the host adapter will scan for them */
657 mbo = HOSTDATA(SCpnt->host)->aha1542_last_mbo_used + 1;
658 if (mbo >= AHA1542_MAILBOXES)
662 if (mb[mbo].status == 0 && HOSTDATA(SCpnt->host)->SCint[mbo] == NULL)
665 if (mbo >= AHA1542_MAILBOXES)
667 } while (mbo != HOSTDATA(SCpnt->host)->aha1542_last_mbo_used);
669 if (mb[mbo].status || HOSTDATA(SCpnt->host)->SCint[mbo])
670 panic("Unable to find empty mailbox for aha1542.\n");
672 HOSTDATA(SCpnt->host)->SCint[mbo] = SCpnt; /* This will effectively prevent someone else from
673 screwing with this cdb. */
675 HOSTDATA(SCpnt->host)->aha1542_last_mbo_used = mbo;
676 restore_flags(flags);
679 printk(KERN_DEBUG "Sending command (%d %x)...", mbo, done);
682 any2scsi(mb[mbo].ccbptr, SCSI_PA(&ccb[mbo])); /* This gets trashed for some reason */
684 memset(&ccb[mbo], 0, sizeof(struct ccb));
686 ccb[mbo].cdblen = SCpnt->cmd_len;
689 if (*cmd == READ_10 || *cmd == READ_6)
691 else if (*cmd == WRITE_10 || *cmd == WRITE_6)
694 memcpy(ccb[mbo].cdb, cmd, ccb[mbo].cdblen);
697 struct scatterlist *sgpnt;
703 ccb[mbo].op = 2; /* SCSI Initiator Command w/scatter-gather */
704 SCpnt->host_scribble = (unsigned char *) scsi_malloc(512);
705 sgpnt = (struct scatterlist *) SCpnt->request_buffer;
706 cptr = (struct chain *) SCpnt->host_scribble;
708 panic("aha1542.c: unable to allocate DMA memory\n");
709 for (i = 0; i < SCpnt->use_sg; i++) {
710 if (sgpnt[i].length == 0 || SCpnt->use_sg > 16 ||
711 (((int) sgpnt[i].address) & 1) || (sgpnt[i].length & 1)) {
713 printk(KERN_CRIT "Bad segment list supplied to aha1542.c (%d, %d)\n", SCpnt->use_sg, i);
714 for (i = 0; i < SCpnt->use_sg; i++) {
715 printk(KERN_CRIT "%d: %p %d\n", i, sgpnt[i].address,
718 printk(KERN_CRIT "cptr %x: ", (unsigned int) cptr);
719 ptr = (unsigned char *) &cptr[i];
720 for (i = 0; i < 18; i++)
721 printk("%02x ", ptr[i]);
722 panic("Foooooooood fight!");
724 any2scsi(cptr[i].dataptr, SCSI_PA(sgpnt[i].address));
725 if (SCSI_PA(sgpnt[i].address + sgpnt[i].length - 1) > ISA_DMA_THRESHOLD)
726 BAD_SG_DMA(SCpnt, sgpnt, SCpnt->use_sg, i);
727 any2scsi(cptr[i].datalen, sgpnt[i].length);
729 any2scsi(ccb[mbo].datalen, SCpnt->use_sg * sizeof(struct chain));
730 any2scsi(ccb[mbo].dataptr, SCSI_PA(cptr));
732 printk("cptr %x: ", cptr);
733 ptr = (unsigned char *) cptr;
734 for (i = 0; i < 18; i++)
735 printk("%02x ", ptr[i]);
738 ccb[mbo].op = 0; /* SCSI Initiator Command */
739 SCpnt->host_scribble = NULL;
740 any2scsi(ccb[mbo].datalen, bufflen);
741 if (buff && SCSI_PA(buff + bufflen - 1) > ISA_DMA_THRESHOLD)
742 BAD_DMA(buff, bufflen);
743 any2scsi(ccb[mbo].dataptr, SCSI_PA(buff));
745 ccb[mbo].idlun = (target & 7) << 5 | direction | (lun & 7); /*SCSI Target Id */
746 ccb[mbo].rsalen = 16;
747 ccb[mbo].linkptr[0] = ccb[mbo].linkptr[1] = ccb[mbo].linkptr[2] = 0;
748 ccb[mbo].commlinkid = 0;
753 printk(KERN_DEBUG "aha1542_command: sending.. ");
754 for (i = 0; i < sizeof(ccb[mbo]) - 10; i++)
755 printk("%02x ", ((unchar *) & ccb[mbo])[i]);
760 DEB(printk("aha1542_queuecommand: now waiting for interrupt ");
762 SCpnt->scsi_done = done;
764 aha1542_out(SCpnt->host->io_port, &ahacmd, 1); /* start scsi command */
767 printk("aha1542_queuecommand: done can't be NULL\n");
772 static void internal_done(Scsi_Cmnd * SCpnt)
777 static int aha1542_command(Scsi_Cmnd * SCpnt)
779 DEB(printk("aha1542_command: ..calling aha1542_queuecommand\n"));
781 aha1542_queuecommand(SCpnt, internal_done);
783 SCpnt->SCp.Status = 0;
784 while (!SCpnt->SCp.Status)
786 return SCpnt->result;
789 /* Initialize mailboxes */
790 static void setup_mailboxes(int bse, struct Scsi_Host *shpnt)
796 unchar cmd[5] = { CMD_MBINIT, AHA1542_MAILBOXES, 0, 0, 0};
798 mb = HOSTDATA(shpnt)->mb;
799 ccb = HOSTDATA(shpnt)->ccb;
801 for (i = 0; i < AHA1542_MAILBOXES; i++) {
802 mb[i].status = mb[AHA1542_MAILBOXES + i].status = 0;
803 any2scsi(mb[i].ccbptr, SCSI_PA(&ccb[i]));
805 aha1542_intr_reset(bse); /* reset interrupts, so they don't block */
806 any2scsi((cmd + 2), SCSI_PA(mb));
807 aha1542_out(bse, cmd, 5);
808 WAIT(INTRFLAGS(bse), INTRMASK, HACC, 0);
811 printk(KERN_ERR "aha1542_detect: failed setting up mailboxes\n");
813 aha1542_intr_reset(bse);
816 static int __init aha1542_getconfig(int base_io, unsigned char *irq_level, unsigned char *dma_chan, unsigned char *scsi_id)
818 unchar inquiry_cmd[] = {CMD_RETCONF};
819 unchar inquiry_result[3];
821 i = inb(STATUS(base_io));
823 i = inb(DATA(base_io));
825 aha1542_out(base_io, inquiry_cmd, 1);
826 aha1542_in(base_io, inquiry_result, 3);
827 WAIT(INTRFLAGS(base_io), INTRMASK, HACC, 0);
830 printk(KERN_ERR "aha1542_detect: query board settings\n");
832 aha1542_intr_reset(base_io);
833 switch (inquiry_result[0]) {
847 /* This means that the adapter, although Adaptec 1542 compatible, doesn't use a DMA channel.
848 Currently only aware of the BusLogic BT-445S VL-Bus adapter which needs this. */
852 printk(KERN_ERR "Unable to determine Adaptec DMA priority. Disabling board\n");
855 switch (inquiry_result[1]) {
875 printk(KERN_ERR "Unable to determine Adaptec IRQ level. Disabling board\n");
878 *scsi_id = inquiry_result[2] & 7;
882 /* This function should only be called for 1542C boards - we can detect
883 the special firmware settings and unlock the board */
885 static int __init aha1542_mbenable(int base)
887 static unchar mbenable_cmd[3];
888 static unchar mbenable_result[2];
891 retval = BIOS_TRANSLATION_6432;
893 mbenable_cmd[0] = CMD_EXTBIOS;
894 aha1542_out(base, mbenable_cmd, 1);
895 if (aha1542_in1(base, mbenable_result, 2))
897 WAITd(INTRFLAGS(base), INTRMASK, HACC, 0, 100);
898 aha1542_intr_reset(base);
900 if ((mbenable_result[0] & 0x08) || mbenable_result[1]) {
901 mbenable_cmd[0] = CMD_MBENABLE;
903 mbenable_cmd[2] = mbenable_result[1];
905 if ((mbenable_result[0] & 0x08) && (mbenable_result[1] & 0x03))
906 retval = BIOS_TRANSLATION_25563;
908 aha1542_out(base, mbenable_cmd, 3);
909 WAIT(INTRFLAGS(base), INTRMASK, HACC, 0);
913 printk(KERN_ERR "aha1542_mbenable: Mailbox init failed\n");
915 aha1542_intr_reset(base);
919 /* Query the board to find out if it is a 1542 or a 1740, or whatever. */
920 static int __init aha1542_query(int base_io, int *transl)
922 unchar inquiry_cmd[] = {CMD_INQUIRY};
923 unchar inquiry_result[4];
925 i = inb(STATUS(base_io));
927 i = inb(DATA(base_io));
929 aha1542_out(base_io, inquiry_cmd, 1);
930 aha1542_in(base_io, inquiry_result, 4);
931 WAIT(INTRFLAGS(base_io), INTRMASK, HACC, 0);
934 printk(KERN_ERR "aha1542_detect: query card type\n");
936 aha1542_intr_reset(base_io);
938 *transl = BIOS_TRANSLATION_6432; /* Default case */
940 /* For an AHA1740 series board, we ignore the board since there is a
941 hardware bug which can lead to wrong blocks being returned if the board
942 is operating in the 1542 emulation mode. Since there is an extended mode
943 driver, we simply ignore the board and let the 1740 driver pick it up.
946 if (inquiry_result[0] == 0x43) {
947 printk(KERN_INFO "aha1542.c: Emulation mode not supported for AHA 174N hardware.\n");
951 /* Always call this - boards that do not support extended bios translation
952 will ignore the command, and we will set the proper default */
954 *transl = aha1542_mbenable(base_io);
960 static int setup_idx = 0;
961 static char *setup_str[MAXBOARDS] __initdata;
963 void __init aha1542_setup(char *str, int *ints)
965 const char *ahausage = "aha1542: usage: aha1542=<PORTBASE>[,<BUSON>,<BUSOFF>[,<DMASPEED>]]\n";
968 if (setup_idx >= MAXBOARDS) {
969 printk(KERN_ERR "aha1542: aha1542_setup called too many times! Bad LILO params ?\n");
970 printk(KERN_ERR " Entryline 1: %s\n", setup_str[0]);
971 printk(KERN_ERR " Entryline 2: %s\n", setup_str[1]);
972 printk(KERN_ERR " This line: %s\n", str);
975 if (ints[0] < 1 || ints[0] > 4) {
976 printk(KERN_ERR "aha1542: %s\n", str);
978 printk(KERN_ERR "aha1542: Wrong parameters may cause system malfunction.. We try anyway..\n");
980 setup_called[setup_idx] = ints[0];
981 setup_str[setup_idx] = str;
983 setup_portbase = ints[0] >= 1 ? ints[1] : 0; /* Preserve the default value.. */
984 setup_buson[setup_idx] = ints[0] >= 2 ? ints[2] : 7;
985 setup_busoff[setup_idx] = ints[0] >= 3 ? ints[3] : 5;
1006 printk(KERN_ERR "aha1542: %s\n", str);
1008 printk(KERN_ERR "aha1542: Valid values for DMASPEED are 5-8, 10 MB/s. Using jumper defaults.\n");
1011 setup_dmaspeed[setup_idx] = atbt;
1013 if (setup_portbase != 0)
1014 bases[setup_idx] = setup_portbase;
1019 static int __init do_setup(char *str)
1023 int count=setup_idx;
1025 get_options(str, sizeof(ints)/sizeof(int), ints);
1026 aha1542_setup(str,ints);
1028 return count<setup_idx;
1031 __setup("aha1542=",do_setup);
1034 /* return non-zero on detection */
1035 static int __init aha1542_detect(Scsi_Host_Template * tpnt)
1037 unsigned char dma_chan;
1038 unsigned char irq_level;
1039 unsigned char scsi_id;
1040 unsigned long flags;
1041 unsigned int base_io;
1043 struct Scsi_Host *shpnt = NULL;
1047 DEB(printk("aha1542_detect: \n"));
1049 tpnt->proc_name = "aha1542";
1052 bases[0] = aha1542[0];
1053 setup_buson[0] = aha1542[1];
1054 setup_busoff[0] = aha1542[2];
1057 switch (aha1542[3]) {
1074 setup_dmaspeed[0] = atbt;
1079 * Find MicroChannel cards (AHA1640)
1086 for (indx = 0; (slot != MCA_NOTFOUND) &&
1087 (indx < sizeof(bases)/sizeof(bases[0])); indx++) {
1092 /* Detect only AHA-1640 cards -- MCA ID 0F1F */
1093 slot = mca_find_unused_adapter(0x0f1f, slot);
1094 if (slot == MCA_NOTFOUND)
1099 pos = mca_read_stored_pos(slot, 3);
1101 /* Decode address */
1105 bases[indx] = 0x334;
1107 bases[indx] = 0x234;
1110 bases[indx] = 0x134;
1115 bases[indx] = 0x330;
1117 bases[indx] = 0x230;
1120 bases[indx] = 0x130;
1124 /* No need to decode IRQ and Arb level -- those are
1125 * read off the card later.
1127 printk(KERN_INFO "Found an AHA-1640 in MCA slot %d, I/O 0x%04x\n", slot, bases[indx]);
1129 mca_set_adapter_name(slot, "Adapter AHA-1640");
1130 mca_set_adapter_procfn(slot, NULL, NULL);
1131 mca_mark_as_used(slot);
1141 * Hunt for ISA Plug'n'Pray Adaptecs (AHA1535)
1146 struct pci_dev *pdev = NULL;
1147 for(indx = 0; indx <sizeof(bases)/sizeof(bases[0]);indx++)
1151 pdev = isapnp_find_dev(NULL, ISAPNP_VENDOR('A', 'D', 'P'),
1152 ISAPNP_FUNCTION(0x1542), pdev);
1156 * Activate the PnP card
1159 if(pdev->prepare(pdev)<0)
1162 if(!(pdev->resource[0].flags&IORESOURCE_IO))
1165 pdev->resource[0].flags|=IORESOURCE_AUTO;
1167 if(pdev->activate(pdev)<0)
1170 bases[indx] = pdev->resource[0].start;
1172 /* The card can be queried for its DMA, we have
1173 the DMA set up that is enough */
1175 printk(KERN_INFO "ISAPnP found an AHA1535 at I/O 0x%03X\n", bases[indx]);
1178 for (indx = 0; indx < sizeof(bases) / sizeof(bases[0]); indx++)
1179 if (bases[indx] != 0 && !check_region(bases[indx], 4)) {
1180 shpnt = scsi_register(tpnt,
1181 sizeof(struct aha1542_hostdata));
1185 /* For now we do this - until kmalloc is more intelligent
1186 we are resigned to stupid hacks like this */
1187 if (SCSI_PA(shpnt) >= ISA_DMA_THRESHOLD) {
1188 printk(KERN_ERR "Invalid address for shpnt with 1542.\n");
1191 if (!aha1542_test_port(bases[indx], shpnt))
1195 base_io = bases[indx];
1197 /* Set the Bus on/off-times as not to ruin floppy performance */
1199 unchar oncmd[] = {CMD_BUSON_TIME, 7};
1200 unchar offcmd[] = {CMD_BUSOFF_TIME, 5};
1202 if (setup_called[indx]) {
1203 oncmd[1] = setup_buson[indx];
1204 offcmd[1] = setup_busoff[indx];
1206 aha1542_intr_reset(base_io);
1207 aha1542_out(base_io, oncmd, 2);
1208 WAIT(INTRFLAGS(base_io), INTRMASK, HACC, 0);
1209 aha1542_intr_reset(base_io);
1210 aha1542_out(base_io, offcmd, 2);
1211 WAIT(INTRFLAGS(base_io), INTRMASK, HACC, 0);
1212 if (setup_dmaspeed[indx] >= 0) {
1213 unchar dmacmd[] = {CMD_DMASPEED, 0};
1214 dmacmd[1] = setup_dmaspeed[indx];
1215 aha1542_intr_reset(base_io);
1216 aha1542_out(base_io, dmacmd, 2);
1217 WAIT(INTRFLAGS(base_io), INTRMASK, HACC, 0);
1221 printk(KERN_ERR "aha1542_detect: setting bus on/off-time failed\n");
1223 aha1542_intr_reset(base_io);
1225 if (aha1542_query(base_io, &trans))
1228 if (aha1542_getconfig(base_io, &irq_level, &dma_chan, &scsi_id) == -1)
1231 printk(KERN_INFO "Configuring Adaptec (SCSI-ID %d) at IO:%x, IRQ %d", scsi_id, base_io, irq_level);
1232 if (dma_chan != 0xFF)
1233 printk(", DMA priority %d", dma_chan);
1236 DEB(aha1542_stat());
1237 setup_mailboxes(base_io, shpnt);
1239 DEB(aha1542_stat());
1241 DEB(printk("aha1542_detect: enable interrupt channel %d\n", irq_level));
1244 if (request_irq(irq_level, do_aha1542_intr_handle, 0, "aha1542", NULL)) {
1245 printk(KERN_ERR "Unable to allocate IRQ for adaptec controller.\n");
1246 restore_flags(flags);
1249 if (dma_chan != 0xFF) {
1250 if (request_dma(dma_chan, "aha1542")) {
1251 printk(KERN_ERR "Unable to allocate DMA channel for Adaptec.\n");
1252 free_irq(irq_level, NULL);
1253 restore_flags(flags);
1256 if (dma_chan == 0 || dma_chan >= 5) {
1257 set_dma_mode(dma_chan, DMA_MODE_CASCADE);
1258 enable_dma(dma_chan);
1261 aha_host[irq_level - 9] = shpnt;
1262 shpnt->this_id = scsi_id;
1263 shpnt->unique_id = base_io;
1264 shpnt->io_port = base_io;
1265 shpnt->n_io_port = 4; /* Number of bytes of I/O space used */
1266 shpnt->dma_channel = dma_chan;
1267 shpnt->irq = irq_level;
1268 HOSTDATA(shpnt)->bios_translation = trans;
1269 if (trans == BIOS_TRANSLATION_25563)
1270 printk(KERN_INFO "aha1542.c: Using extended bios translation\n");
1271 HOSTDATA(shpnt)->aha1542_last_mbi_used = (2 * AHA1542_MAILBOXES - 1);
1272 HOSTDATA(shpnt)->aha1542_last_mbo_used = (AHA1542_MAILBOXES - 1);
1273 memset(HOSTDATA(shpnt)->SCint, 0, sizeof(HOSTDATA(shpnt)->SCint));
1274 restore_flags(flags);
1276 DEB(printk(" *** READ CAPACITY ***\n"));
1280 static unchar cmd[] = { READ_CAPACITY, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
1283 for (i = 0; i < sizeof(buf); ++i)
1285 for (i = 0; i < 2; ++i)
1286 if (!aha1542_command(i, cmd, buf, sizeof(buf))) {
1287 printk(KERN_DEBUG "aha_detect: LU %d sector_size %d device_size %d\n",
1288 i, xscsi2int(buf + 4), xscsi2int(buf));
1292 DEB(printk(" *** NOW RUNNING MY OWN TEST *** \n"));
1294 for (i = 0; i < 4; ++i) {
1295 unsigned char cmd[10];
1300 xany2scsi(cmd + 2, i);
1305 aha1542_command(0, cmd, buffer, 512);
1308 request_region(bases[indx], 4, "aha1542"); /* Register the IO ports that we use */
1312 scsi_unregister(shpnt);
1320 static int aha1542_restart(struct Scsi_Host *shost)
1325 unchar ahacmd = CMD_START_SCSI;
1328 for (i = 0; i < AHA1542_MAILBOXES; i++)
1329 if (HOSTDATA(shost)->SCint[i] &&
1330 !(HOSTDATA(shost)->SCint[i]->device->soft_reset)) {
1332 HOSTDATA(shost)->mb[i].status = 1; /* Indicate ready to restart... */
1336 printk(KERN_DEBUG "Potential to restart %d stalled commands...\n", count);
1338 /* start scsi command */
1340 aha1542_out(shost->io_port, &ahacmd, 1);
1345 static int aha1542_abort(Scsi_Cmnd * SCpnt)
1349 * The abort command does not leave the device in a clean state where
1350 * it is available to be used again. Until this gets worked out, we
1351 * will leave it commented out.
1354 printk(KERN_ERR "aha1542.c: Unable to abort command for target %d\n",
1360 * This is a device reset. This is handled by sending a special command
1363 static int aha1542_dev_reset(Scsi_Cmnd * SCpnt)
1365 unsigned long flags;
1367 unchar target = SCpnt->target;
1368 unchar lun = SCpnt->lun;
1371 unchar ahacmd = CMD_START_SCSI;
1373 ccb = HOSTDATA(SCpnt->host)->ccb;
1374 mb = HOSTDATA(SCpnt->host)->mb;
1378 mbo = HOSTDATA(SCpnt->host)->aha1542_last_mbo_used + 1;
1379 if (mbo >= AHA1542_MAILBOXES)
1383 if (mb[mbo].status == 0 && HOSTDATA(SCpnt->host)->SCint[mbo] == NULL)
1386 if (mbo >= AHA1542_MAILBOXES)
1388 } while (mbo != HOSTDATA(SCpnt->host)->aha1542_last_mbo_used);
1390 if (mb[mbo].status || HOSTDATA(SCpnt->host)->SCint[mbo])
1391 panic("Unable to find empty mailbox for aha1542.\n");
1393 HOSTDATA(SCpnt->host)->SCint[mbo] = SCpnt; /* This will effectively
1394 prevent someone else from
1395 screwing with this cdb. */
1397 HOSTDATA(SCpnt->host)->aha1542_last_mbo_used = mbo;
1398 restore_flags(flags);
1400 any2scsi(mb[mbo].ccbptr, SCSI_PA(&ccb[mbo])); /* This gets trashed for some reason */
1402 memset(&ccb[mbo], 0, sizeof(struct ccb));
1404 ccb[mbo].op = 0x81; /* BUS DEVICE RESET */
1406 ccb[mbo].idlun = (target & 7) << 5 | (lun & 7); /*SCSI Target Id */
1408 ccb[mbo].linkptr[0] = ccb[mbo].linkptr[1] = ccb[mbo].linkptr[2] = 0;
1409 ccb[mbo].commlinkid = 0;
1412 * Now tell the 1542 to flush all pending commands for this
1415 aha1542_out(SCpnt->host->io_port, &ahacmd, 1);
1417 printk(KERN_WARNING "aha1542.c: Trying device reset for target %d\n", SCpnt->target);
1422 #ifdef ERIC_neverdef
1424 * With the 1542 we apparently never get an interrupt to
1425 * acknowledge a device reset being sent. Then again, Leonard
1426 * says we are doing this wrong in the first place...
1428 * Take a wait and see attitude. If we get spurious interrupts,
1429 * then the device reset is doing something sane and useful, and
1430 * we will wait for the interrupt to post completion.
1432 printk(KERN_WARNING "Sent BUS DEVICE RESET to target %d\n", SCpnt->target);
1435 * Free the command block for all commands running on this
1438 for (i = 0; i < AHA1542_MAILBOXES; i++) {
1439 if (HOSTDATA(SCpnt->host)->SCint[i] &&
1440 HOSTDATA(SCpnt->host)->SCint[i]->target == SCpnt->target) {
1442 SCtmp = HOSTDATA(SCpnt->host)->SCint[i];
1443 if (SCtmp->host_scribble) {
1444 scsi_free(SCtmp->host_scribble, 512);
1445 SCtmp->host_scribble = NULL;
1447 HOSTDATA(SCpnt->host)->SCint[i] = NULL;
1448 HOSTDATA(SCpnt->host)->mb[i].status = 0;
1454 #endif /* ERIC_neverdef */
1457 static int aha1542_bus_reset(Scsi_Cmnd * SCpnt)
1462 * This does a scsi reset for all devices on the bus.
1463 * In principle, we could also reset the 1542 - should
1464 * we do this? Try this first, and we can add that later
1465 * if it turns out to be useful.
1467 outb(SCRST, CONTROL(SCpnt->host->io_port));
1470 * Wait for the thing to settle down a bit. Unfortunately
1471 * this is going to basically lock up the machine while we
1472 * wait for this to complete. To be 100% correct, we need to
1473 * check for timeout, and if we are doing something like this
1474 * we are pretty desperate anyways.
1476 spin_unlock_irq(&io_request_lock);
1478 spin_lock_irq(&io_request_lock);
1480 WAIT(STATUS(SCpnt->host->io_port),
1481 STATMASK, INIT | IDLE, STST | DIAGF | INVDCMD | DF | CDF);
1484 * Now try to pick up the pieces. For all pending commands,
1485 * free any internal data structures, and basically clear things
1486 * out. We do not try and restart any commands or anything -
1487 * the strategy handler takes care of that crap.
1489 printk(KERN_WARNING "Sent BUS RESET to scsi host %d\n", SCpnt->host->host_no);
1491 for (i = 0; i < AHA1542_MAILBOXES; i++) {
1492 if (HOSTDATA(SCpnt->host)->SCint[i] != NULL) {
1494 SCtmp = HOSTDATA(SCpnt->host)->SCint[i];
1497 if (SCtmp->device->soft_reset) {
1499 * If this device implements the soft reset option,
1500 * then it is still holding onto the command, and
1501 * may yet complete it. In this case, we don't
1506 if (SCtmp->host_scribble) {
1507 scsi_free(SCtmp->host_scribble, 512);
1508 SCtmp->host_scribble = NULL;
1510 HOSTDATA(SCpnt->host)->SCint[i] = NULL;
1511 HOSTDATA(SCpnt->host)->mb[i].status = 0;
1521 static int aha1542_host_reset(Scsi_Cmnd * SCpnt)
1526 * This does a scsi reset for all devices on the bus.
1527 * In principle, we could also reset the 1542 - should
1528 * we do this? Try this first, and we can add that later
1529 * if it turns out to be useful.
1531 outb(HRST | SCRST, CONTROL(SCpnt->host->io_port));
1534 * Wait for the thing to settle down a bit. Unfortunately
1535 * this is going to basically lock up the machine while we
1536 * wait for this to complete. To be 100% correct, we need to
1537 * check for timeout, and if we are doing something like this
1538 * we are pretty desperate anyways.
1540 spin_unlock_irq(&io_request_lock);
1542 spin_lock_irq(&io_request_lock);
1544 WAIT(STATUS(SCpnt->host->io_port),
1545 STATMASK, INIT | IDLE, STST | DIAGF | INVDCMD | DF | CDF);
1548 * We need to do this too before the 1542 can interact with
1551 setup_mailboxes(SCpnt->host->io_port, SCpnt->host);
1554 * Now try to pick up the pieces. For all pending commands,
1555 * free any internal data structures, and basically clear things
1556 * out. We do not try and restart any commands or anything -
1557 * the strategy handler takes care of that crap.
1559 printk(KERN_WARNING "Sent BUS RESET to scsi host %d\n", SCpnt->host->host_no);
1561 for (i = 0; i < AHA1542_MAILBOXES; i++) {
1562 if (HOSTDATA(SCpnt->host)->SCint[i] != NULL) {
1564 SCtmp = HOSTDATA(SCpnt->host)->SCint[i];
1566 if (SCtmp->device->soft_reset) {
1568 * If this device implements the soft reset option,
1569 * then it is still holding onto the command, and
1570 * may yet complete it. In this case, we don't
1575 if (SCtmp->host_scribble) {
1576 scsi_free(SCtmp->host_scribble, 512);
1577 SCtmp->host_scribble = NULL;
1579 HOSTDATA(SCpnt->host)->SCint[i] = NULL;
1580 HOSTDATA(SCpnt->host)->mb[i].status = 0;
1591 * These are the old error handling routines. They are only temporarily
1592 * here while we play with the new error handling code.
1594 static int aha1542_old_abort(Scsi_Cmnd * SCpnt)
1597 unchar ahacmd = CMD_START_SCSI;
1598 unsigned long flags;
1602 printk(KERN_DEBUG "In aha1542_abort: %x %x\n",
1603 inb(STATUS(SCpnt->host->io_port)),
1604 inb(INTRFLAGS(SCpnt->host->io_port)));
1608 mb = HOSTDATA(SCpnt->host)->mb;
1609 mbi = HOSTDATA(SCpnt->host)->aha1542_last_mbi_used + 1;
1610 if (mbi >= 2 * AHA1542_MAILBOXES)
1611 mbi = AHA1542_MAILBOXES;
1614 if (mb[mbi].status != 0)
1617 if (mbi >= 2 * AHA1542_MAILBOXES)
1618 mbi = AHA1542_MAILBOXES;
1619 } while (mbi != HOSTDATA(SCpnt->host)->aha1542_last_mbi_used);
1620 restore_flags(flags);
1622 if (mb[mbi].status) {
1623 printk(KERN_ERR "Lost interrupt discovered on irq %d - attempting to recover\n",
1625 aha1542_intr_handle(SCpnt->host->irq, NULL);
1628 /* OK, no lost interrupt. Try looking to see how many pending commands
1629 we think we have. */
1631 for (i = 0; i < AHA1542_MAILBOXES; i++)
1632 if (HOSTDATA(SCpnt->host)->SCint[i]) {
1633 if (HOSTDATA(SCpnt->host)->SCint[i] == SCpnt) {
1634 printk(KERN_ERR "Timed out command pending for %s\n",
1635 kdevname(SCpnt->request.rq_dev));
1636 if (HOSTDATA(SCpnt->host)->mb[i].status) {
1637 printk(KERN_ERR "OGMB still full - restarting\n");
1638 aha1542_out(SCpnt->host->io_port, &ahacmd, 1);
1641 printk(KERN_ERR "Other pending command %s\n",
1642 kdevname(SCpnt->request.rq_dev));
1646 DEB(printk("aha1542_abort\n"));
1650 for (mbo = 0; mbo < AHA1542_MAILBOXES; mbo++)
1651 if (SCpnt == HOSTDATA(SCpnt->host)->SCint[mbo]) {
1652 mb[mbo].status = 2; /* Abort command */
1653 aha1542_out(SCpnt->host->io_port, &ahacmd, 1); /* start scsi command */
1654 restore_flags(flags);
1658 return SCSI_ABORT_SNOOZE;
1661 /* We do not implement a reset function here, but the upper level code
1662 assumes that it will get some kind of response for the command in
1663 SCpnt. We must oblige, or the command will hang the scsi system.
1664 For a first go, we assume that the 1542 notifies us with all of the
1665 pending commands (it does implement soft reset, after all). */
1667 static int aha1542_old_reset(Scsi_Cmnd * SCpnt, unsigned int reset_flags)
1669 unchar ahacmd = CMD_START_SCSI;
1673 * See if a bus reset was suggested.
1675 if (reset_flags & SCSI_RESET_SUGGEST_BUS_RESET) {
1677 * This does a scsi reset for all devices on the bus.
1678 * In principle, we could also reset the 1542 - should
1679 * we do this? Try this first, and we can add that later
1680 * if it turns out to be useful.
1682 outb(HRST | SCRST, CONTROL(SCpnt->host->io_port));
1685 * Wait for the thing to settle down a bit. Unfortunately
1686 * this is going to basically lock up the machine while we
1687 * wait for this to complete. To be 100% correct, we need to
1688 * check for timeout, and if we are doing something like this
1689 * we are pretty desperate anyways.
1691 WAIT(STATUS(SCpnt->host->io_port),
1692 STATMASK, INIT | IDLE, STST | DIAGF | INVDCMD | DF | CDF);
1695 * We need to do this too before the 1542 can interact with
1698 setup_mailboxes(SCpnt->host->io_port, SCpnt->host);
1701 * Now try to pick up the pieces. Restart all commands
1702 * that are currently active on the bus, and reset all of
1703 * the datastructures. We have some time to kill while
1704 * things settle down, so print a nice message.
1706 printk(KERN_WARNING "Sent BUS RESET to scsi host %d\n", SCpnt->host->host_no);
1708 for (i = 0; i < AHA1542_MAILBOXES; i++)
1709 if (HOSTDATA(SCpnt->host)->SCint[i] != NULL) {
1711 SCtmp = HOSTDATA(SCpnt->host)->SCint[i];
1712 SCtmp->result = DID_RESET << 16;
1713 if (SCtmp->host_scribble) {
1714 scsi_free(SCtmp->host_scribble, 512);
1715 SCtmp->host_scribble = NULL;
1717 printk(KERN_WARNING "Sending DID_RESET for target %d\n", SCpnt->target);
1718 SCtmp->scsi_done(SCpnt);
1720 HOSTDATA(SCpnt->host)->SCint[i] = NULL;
1721 HOSTDATA(SCpnt->host)->mb[i].status = 0;
1724 * Now tell the mid-level code what we did here. Since
1725 * we have restarted all of the outstanding commands,
1726 * then report SUCCESS.
1728 return (SCSI_RESET_SUCCESS | SCSI_RESET_BUS_RESET);
1730 printk(KERN_CRIT "aha1542.c: Unable to perform hard reset.\n");
1731 printk(KERN_CRIT "Power cycle machine to reset\n");
1732 return (SCSI_RESET_ERROR | SCSI_RESET_BUS_RESET);
1736 /* This does a selective reset of just the one device */
1737 /* First locate the ccb for this command */
1738 for (i = 0; i < AHA1542_MAILBOXES; i++)
1739 if (HOSTDATA(SCpnt->host)->SCint[i] == SCpnt) {
1740 HOSTDATA(SCpnt->host)->ccb[i].op = 0x81; /* BUS DEVICE RESET */
1741 /* Now tell the 1542 to flush all pending commands for this target */
1742 aha1542_out(SCpnt->host->io_port, &ahacmd, 1);
1744 /* Here is the tricky part. What to do next. Do we get an interrupt
1745 for the commands that we aborted with the specified target, or
1746 do we generate this on our own? Try it without first and see
1748 printk(KERN_WARNING "Sent BUS DEVICE RESET to target %d\n", SCpnt->target);
1750 /* If the first does not work, then try the second. I think the
1751 first option is more likely to be correct. Free the command
1752 block for all commands running on this target... */
1753 for (i = 0; i < AHA1542_MAILBOXES; i++)
1754 if (HOSTDATA(SCpnt->host)->SCint[i] &&
1755 HOSTDATA(SCpnt->host)->SCint[i]->target == SCpnt->target) {
1757 SCtmp = HOSTDATA(SCpnt->host)->SCint[i];
1758 SCtmp->result = DID_RESET << 16;
1759 if (SCtmp->host_scribble) {
1760 scsi_free(SCtmp->host_scribble, 512);
1761 SCtmp->host_scribble = NULL;
1763 printk(KERN_WARNING "Sending DID_RESET for target %d\n", SCpnt->target);
1764 SCtmp->scsi_done(SCpnt);
1766 HOSTDATA(SCpnt->host)->SCint[i] = NULL;
1767 HOSTDATA(SCpnt->host)->mb[i].status = 0;
1769 return SCSI_RESET_SUCCESS;
1772 /* No active command at this time, so this means that each time we got
1773 some kind of response the last time through. Tell the mid-level code
1774 to request sense information in order to decide what to do next. */
1775 return SCSI_RESET_PUNT;
1780 static int aha1542_biosparam(Scsi_Disk * disk, kdev_t dev, int *ip)
1782 int translation_algorithm;
1783 int size = disk->capacity;
1785 translation_algorithm = HOSTDATA(disk->device->host)->bios_translation;
1787 if ((size >> 11) > 1024 && translation_algorithm == BIOS_TRANSLATION_25563) {
1788 /* Please verify that this is the same as what DOS returns */
1791 ip[2] = size / 255 / 63;
1800 MODULE_LICENSE("GPL");
1803 /* Eventually this will go into an include file, but this will be later */
1804 static Scsi_Host_Template driver_template = AHA1542;
1806 #include "scsi_module.c"