1 /* $Id: aha1542.c,v 1.1.1.1 2005/04/11 02:50:35 jack Exp $
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: /cvshome/samwise/ppclinux/drivers/scsi/aha1542.c,v 1.1.1.1 2005/04/11 02:50:35 jack Exp $";
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 };
114 static char *setup_str[MAXBOARDS] __initdata;
117 * LILO/Module params: aha1542=<PORTBASE>[,<BUSON>,<BUSOFF>[,<DMASPEED>]]
119 * Where: <PORTBASE> is any of the valid AHA addresses:
120 * 0x130, 0x134, 0x230, 0x234, 0x330, 0x334
121 * <BUSON> is the time (in microsecs) that AHA spends on the AT-bus
122 * when transferring data. 1542A power-on default is 11us,
123 * valid values are in range: 2..15 (decimal)
124 * <BUSOFF> is the time that AHA spends OFF THE BUS after while
125 * it is transferring data (not to monopolize the bus).
126 * Power-on default is 4us, valid range: 1..64 microseconds.
127 * <DMASPEED> Default is jumper selected (1542A: on the J1),
128 * but experimenter can alter it with this.
129 * Valid values: 5, 6, 7, 8, 10 (MB/s)
130 * Factory default is 5 MB/s.
135 int aha1542[] = {0x330, 11, 4, -1};
136 MODULE_PARM(aha1542, "1-4i");
137 MODULE_PARM(isapnp, "i");
139 static struct isapnp_device_id id_table[] __initdata = {
141 ISAPNP_ANY_ID, ISAPNP_ANY_ID,
142 ISAPNP_VENDOR('A', 'D', 'P'), ISAPNP_FUNCTION(0x1542),
148 MODULE_DEVICE_TABLE(isapnp, id_table);
151 static int isapnp = 1;
154 #define BIOS_TRANSLATION_1632 0 /* Used by some old 1542A boards */
155 #define BIOS_TRANSLATION_6432 1 /* Default case these days */
156 #define BIOS_TRANSLATION_25563 2 /* Big disk case */
158 struct aha1542_hostdata {
159 /* This will effectively start both of them at the first mailbox */
160 int bios_translation; /* Mapping bios uses - for compatibility */
161 int aha1542_last_mbi_used;
162 int aha1542_last_mbo_used;
163 Scsi_Cmnd *SCint[AHA1542_MAILBOXES];
164 struct mailbox mb[2 * AHA1542_MAILBOXES];
165 struct ccb ccb[AHA1542_MAILBOXES];
168 #define HOSTDATA(host) ((struct aha1542_hostdata *) &host->hostdata)
170 static struct Scsi_Host *aha_host[7]; /* One for each IRQ level (9-15) */
175 #define WAITnexttimeout 3000000
177 static void setup_mailboxes(int base_io, struct Scsi_Host *shpnt);
178 static int aha1542_restart(struct Scsi_Host *shost);
179 static void aha1542_intr_handle(int irq, void *dev_id, struct pt_regs *regs);
180 static void do_aha1542_intr_handle(int irq, void *dev_id, struct pt_regs *regs);
182 #define aha1542_intr_reset(base) outb(IRST, CONTROL(base))
184 #define WAIT(port, mask, allof, noneof) \
185 { register int WAITbits; \
186 register int WAITtimeout = WAITnexttimeout; \
188 WAITbits = inb(port) & (mask); \
189 if ((WAITbits & (allof)) == (allof) && ((WAITbits & (noneof)) == 0)) \
191 if (--WAITtimeout == 0) goto fail; \
195 /* Similar to WAIT, except we use the udelay call to regulate the
196 amount of time we wait. */
197 #define WAITd(port, mask, allof, noneof, timeout) \
198 { register int WAITbits; \
199 register int WAITtimeout = timeout; \
201 WAITbits = inb(port) & (mask); \
202 if ((WAITbits & (allof)) == (allof) && ((WAITbits & (noneof)) == 0)) \
205 if (--WAITtimeout == 0) goto fail; \
209 static void aha1542_stat(void)
211 /* int s = inb(STATUS), i = inb(INTRFLAGS);
212 printk("status=%x intrflags=%x\n", s, i, WAITnexttimeout-WAITtimeout); */
215 /* This is a bit complicated, but we need to make sure that an interrupt
216 routine does not send something out while we are in the middle of this.
217 Fortunately, it is only at boot time that multi-byte messages
219 static int aha1542_out(unsigned int base, unchar * cmdp, int len)
221 unsigned long flags = 0;
226 WAIT(STATUS(base), CDF, 0, CDF);
228 if (inb(STATUS(base)) & CDF) {
229 restore_flags(flags);
232 outb(*cmdp, DATA(base));
233 restore_flags(flags);
239 WAIT(STATUS(base), CDF, 0, CDF);
240 outb(*cmdp++, DATA(base));
242 restore_flags(flags);
246 restore_flags(flags);
247 printk(KERN_ERR "aha1542_out failed(%d): ", len + 1);
252 /* Only used at boot time, so we do not need to worry about latency as much
255 static int __init aha1542_in(unsigned int base, unchar * cmdp, int len)
262 WAIT(STATUS(base), DF, DF, 0);
263 *cmdp++ = inb(DATA(base));
265 restore_flags(flags);
268 restore_flags(flags);
269 printk(KERN_ERR "aha1542_in failed(%d): ", len + 1);
274 /* Similar to aha1542_in, except that we wait a very short period of time.
275 We use this if we know the board is alive and awake, but we are not sure
276 if the board will respond to the command we are about to send or not */
277 static int __init aha1542_in1(unsigned int base, unchar * cmdp, int len)
284 WAITd(STATUS(base), DF, DF, 0, 100);
285 *cmdp++ = inb(DATA(base));
287 restore_flags(flags);
290 restore_flags(flags);
294 static int makecode(unsigned hosterr, unsigned scsierr)
298 case 0xa: /* Linked command complete without error and linked normally */
299 case 0xb: /* Linked command complete without error, interrupt generated */
303 case 0x11: /* Selection time out-The initiator selection or target
304 reselection was not complete within the SCSI Time out period */
305 hosterr = DID_TIME_OUT;
308 case 0x12: /* Data overrun/underrun-The target attempted to transfer more data
309 than was allocated by the Data Length field or the sum of the
310 Scatter / Gather Data Length fields. */
312 case 0x13: /* Unexpected bus free-The target dropped the SCSI BSY at an unexpected time. */
314 case 0x15: /* MBO command was not 00, 01 or 02-The first byte of the CB was
315 invalid. This usually indicates a software failure. */
317 case 0x16: /* Invalid CCB Operation Code-The first byte of the CCB was invalid.
318 This usually indicates a software failure. */
320 case 0x17: /* Linked CCB does not have the same LUN-A subsequent CCB of a set
321 of linked CCB's does not specify the same logical unit number as
323 case 0x18: /* Invalid Target Direction received from Host-The direction of a
324 Target Mode CCB was invalid. */
326 case 0x19: /* Duplicate CCB Received in Target Mode-More than once CCB was
327 received to service data transfer between the same target LUN
328 and initiator SCSI ID in the same direction. */
330 case 0x1a: /* Invalid CCB or Segment List Parameter-A segment list with a zero
331 length segment or invalid segment list boundaries was received.
332 A CCB parameter was invalid. */
333 DEB(printk("Aha1542: %x %x\n", hosterr, scsierr));
334 hosterr = DID_ERROR; /* Couldn't find any better */
337 case 0x14: /* Target bus phase sequence failure-An invalid bus phase or bus
338 phase sequence was requested by the target. The host adapter
339 will generate a SCSI Reset Condition, notifying the host with
344 printk(KERN_ERR "aha1542: makecode: unknown hoststatus %x\n", hosterr);
347 return scsierr | (hosterr << 16);
350 static int __init aha1542_test_port(int bse, struct Scsi_Host *shpnt)
352 unchar inquiry_cmd[] = {CMD_INQUIRY};
353 unchar inquiry_result[4];
356 volatile int debug = 0;
358 /* Quick and dirty test for presence of the card. */
359 if (inb(STATUS(bse)) == 0xff)
362 /* Reset the adapter. I ought to make a hard reset, but it's not really necessary */
364 /* DEB(printk("aha1542_test_port called \n")); */
366 /* In case some other card was probing here, reset interrupts */
367 aha1542_intr_reset(bse); /* reset interrupts, so they don't block */
369 outb(SRST | IRST /*|SCRST */ , CONTROL(bse));
371 mdelay(20); /* Wait a little bit for things to settle down. */
374 /* Expect INIT and IDLE, any of the others are bad */
375 WAIT(STATUS(bse), STATMASK, INIT | IDLE, STST | DIAGF | INVDCMD | DF | CDF);
378 /* Shouldn't have generated any interrupts during reset */
379 if (inb(INTRFLAGS(bse)) & INTRMASK)
383 /* Perform a host adapter inquiry instead so we do not need to set
384 up the mailboxes ahead of time */
386 aha1542_out(bse, inquiry_cmd, 1);
390 cmdp = &inquiry_result[0];
393 WAIT(STATUS(bse), DF, DF, 0);
394 *cmdp++ = inb(DATA(bse));
398 /* Reading port should reset DF */
399 if (inb(STATUS(bse)) & DF)
403 /* When HACC, command is completed, and we're though testing */
404 WAIT(INTRFLAGS(bse), HACC, HACC, 0);
405 /* now initialize adapter */
408 /* Clear interrupts */
409 outb(IRST, CONTROL(bse));
413 return debug; /* 1 = ok */
415 return 0; /* 0 = not ok */
418 /* A quick wrapper for do_aha1542_intr_handle to grab the spin lock */
419 static void do_aha1542_intr_handle(int irq, void *dev_id, struct pt_regs *regs)
423 spin_lock_irqsave(&io_request_lock, flags);
424 aha1542_intr_handle(irq, dev_id, regs);
425 spin_unlock_irqrestore(&io_request_lock, flags);
428 /* A "high" level interrupt handler */
429 static void aha1542_intr_handle(int irq, void *dev_id, struct pt_regs *regs)
431 void (*my_done) (Scsi_Cmnd *) = NULL;
432 int errstatus, mbi, mbo, mbistatus;
435 struct Scsi_Host *shost;
442 shost = aha_host[irq - 9];
446 mb = HOSTDATA(shost)->mb;
447 ccb = HOSTDATA(shost)->ccb;
451 flag = inb(INTRFLAGS(shost->io_port));
452 printk(KERN_DEBUG "aha1542_intr_handle: ");
453 if (!(flag & ANYINTR))
454 printk("no interrupt?");
463 printk("status %02x\n", inb(STATUS(shost->io_port)));
470 flag = inb(INTRFLAGS(shost->io_port));
472 /* Check for unusual interrupts. If any of these happen, we should
473 probably do something special, but for now just printing a message
474 is sufficient. A SCSI reset detected is something that we really
475 need to deal with in some way. */
486 aha1542_intr_reset(shost->io_port);
490 mbi = HOSTDATA(shost)->aha1542_last_mbi_used + 1;
491 if (mbi >= 2 * AHA1542_MAILBOXES)
492 mbi = AHA1542_MAILBOXES;
495 if (mb[mbi].status != 0)
498 if (mbi >= 2 * AHA1542_MAILBOXES)
499 mbi = AHA1542_MAILBOXES;
500 } while (mbi != HOSTDATA(shost)->aha1542_last_mbi_used);
502 if (mb[mbi].status == 0) {
503 restore_flags(flags);
504 /* Hmm, no mail. Must have read it the last time around */
505 if (!number_serviced && !needs_restart)
506 printk(KERN_WARNING "aha1542.c: interrupt received, but no mail.\n");
507 /* We detected a reset. Restart all pending commands for
508 devices that use the hard reset option */
510 aha1542_restart(shost);
514 mbo = (scsi2int(mb[mbi].ccbptr) - (SCSI_PA(&ccb[0]))) / sizeof(struct ccb);
515 mbistatus = mb[mbi].status;
517 HOSTDATA(shost)->aha1542_last_mbi_used = mbi;
518 restore_flags(flags);
522 if (ccb[mbo].tarstat | ccb[mbo].hastat)
523 printk(KERN_DEBUG "aha1542_command: returning %x (status %d)\n",
524 ccb[mbo].tarstat + ((int) ccb[mbo].hastat << 16), mb[mbi].status);
529 continue; /* Aborted command not found */
532 printk(KERN_DEBUG "...done %d %d\n", mbo, mbi);
535 SCtmp = HOSTDATA(shost)->SCint[mbo];
537 if (!SCtmp || !SCtmp->scsi_done) {
538 printk(KERN_WARNING "aha1542_intr_handle: Unexpected interrupt\n");
539 printk(KERN_WARNING "tarstat=%x, hastat=%x idlun=%x ccb#=%d \n", ccb[mbo].tarstat,
540 ccb[mbo].hastat, ccb[mbo].idlun, mbo);
543 my_done = SCtmp->scsi_done;
544 if (SCtmp->host_scribble) {
545 scsi_free(SCtmp->host_scribble, 512);
546 SCtmp->host_scribble = 0;
548 /* Fetch the sense data, and tuck it away, in the required slot. The
549 Adaptec automatically fetches it, and there is no guarantee that
550 we will still have it in the cdb when we come back */
551 if (ccb[mbo].tarstat == 2)
552 memcpy(SCtmp->sense_buffer, &ccb[mbo].cdb[ccb[mbo].cdblen],
553 sizeof(SCtmp->sense_buffer));
556 /* is there mail :-) */
558 /* more error checking left out here */
560 /* This is surely wrong, but I don't know what's right */
561 errstatus = makecode(ccb[mbo].hastat, ccb[mbo].tarstat);
567 printk(KERN_DEBUG "(aha1542 error:%x %x %x) ", errstatus,
568 ccb[mbo].hastat, ccb[mbo].tarstat);
571 if (ccb[mbo].tarstat == 2) {
575 DEB(printk("aha1542_intr_handle: sense:"));
577 for (i = 0; i < 12; i++)
578 printk("%02x ", ccb[mbo].cdb[ccb[mbo].cdblen + i]);
582 DEB(printk("aha1542_intr_handle: buf:"));
583 for (i = 0; i < bufflen; i++)
584 printk("%02x ", ((unchar *)buff)[i]);
588 DEB(if (errstatus) printk("aha1542_intr_handle: returning %6x\n", errstatus));
589 SCtmp->result = errstatus;
590 HOSTDATA(shost)->SCint[mbo] = NULL; /* This effectively frees up the mailbox slot, as
591 far as queuecommand is concerned */
597 static int aha1542_queuecommand(Scsi_Cmnd * SCpnt, void (*done) (Scsi_Cmnd *))
599 unchar ahacmd = CMD_START_SCSI;
601 unchar *cmd = (unchar *) SCpnt->cmnd;
602 unchar target = SCpnt->target;
603 unchar lun = SCpnt->lun;
605 void *buff = SCpnt->request_buffer;
606 int bufflen = SCpnt->request_bufflen;
613 mb = HOSTDATA(SCpnt->host)->mb;
614 ccb = HOSTDATA(SCpnt->host)->ccb;
616 DEB(if (target > 1) {
617 SCpnt->result = DID_TIME_OUT << 16;
618 done(SCpnt); return 0;
622 if (*cmd == REQUEST_SENSE) {
623 /* Don't do the command - we have the sense data already */
625 /* scsi_request_sense() provides a buffer of size 256,
626 so there is no reason to expect equality */
627 if (bufflen != sizeof(SCpnt->sense_buffer))
628 printk(KERN_CRIT "aha1542: Wrong buffer length supplied "
629 "for request sense (%d)\n", bufflen);
636 if (*cmd == READ_10 || *cmd == WRITE_10)
637 i = xscsi2int(cmd + 2);
638 else if (*cmd == READ_6 || *cmd == WRITE_6)
639 i = scsi2int(cmd + 2);
643 printk(KERN_DEBUG "aha1542_queuecommand: dev %d cmd %02x pos %d len %d ", target, *cmd, i, bufflen);
645 printk(KERN_DEBUG "aha1542_command: dev %d cmd %02x pos %d len %d ", target, *cmd, i, bufflen);
647 printk(KERN_DEBUG "aha1542_queuecommand: dumping scsi cmd:");
648 for (i = 0; i < SCpnt->cmd_len; i++)
649 printk("%02x ", cmd[i]);
651 if (*cmd == WRITE_10 || *cmd == WRITE_6)
652 return 0; /* we are still testing, so *don't* write */
654 /* Use the outgoing mailboxes in a round-robin fashion, because this
655 is how the host adapter will scan for them */
659 mbo = HOSTDATA(SCpnt->host)->aha1542_last_mbo_used + 1;
660 if (mbo >= AHA1542_MAILBOXES)
664 if (mb[mbo].status == 0 && HOSTDATA(SCpnt->host)->SCint[mbo] == NULL)
667 if (mbo >= AHA1542_MAILBOXES)
669 } while (mbo != HOSTDATA(SCpnt->host)->aha1542_last_mbo_used);
671 if (mb[mbo].status || HOSTDATA(SCpnt->host)->SCint[mbo])
672 panic("Unable to find empty mailbox for aha1542.\n");
674 HOSTDATA(SCpnt->host)->SCint[mbo] = SCpnt; /* This will effectively prevent someone else from
675 screwing with this cdb. */
677 HOSTDATA(SCpnt->host)->aha1542_last_mbo_used = mbo;
678 restore_flags(flags);
681 printk(KERN_DEBUG "Sending command (%d %x)...", mbo, done);
684 any2scsi(mb[mbo].ccbptr, SCSI_PA(&ccb[mbo])); /* This gets trashed for some reason */
686 memset(&ccb[mbo], 0, sizeof(struct ccb));
688 ccb[mbo].cdblen = SCpnt->cmd_len;
691 if (*cmd == READ_10 || *cmd == READ_6)
693 else if (*cmd == WRITE_10 || *cmd == WRITE_6)
696 memcpy(ccb[mbo].cdb, cmd, ccb[mbo].cdblen);
699 struct scatterlist *sgpnt;
705 ccb[mbo].op = 2; /* SCSI Initiator Command w/scatter-gather */
706 SCpnt->host_scribble = (unsigned char *) scsi_malloc(512);
707 sgpnt = (struct scatterlist *) SCpnt->request_buffer;
708 cptr = (struct chain *) SCpnt->host_scribble;
710 panic("aha1542.c: unable to allocate DMA memory\n");
711 for (i = 0; i < SCpnt->use_sg; i++) {
712 if (sgpnt[i].length == 0 || SCpnt->use_sg > 16 ||
713 (((int) sgpnt[i].address) & 1) || (sgpnt[i].length & 1)) {
715 printk(KERN_CRIT "Bad segment list supplied to aha1542.c (%d, %d)\n", SCpnt->use_sg, i);
716 for (i = 0; i < SCpnt->use_sg; i++) {
717 printk(KERN_CRIT "%d: %p %d\n", i, sgpnt[i].address,
720 printk(KERN_CRIT "cptr %x: ", (unsigned int) cptr);
721 ptr = (unsigned char *) &cptr[i];
722 for (i = 0; i < 18; i++)
723 printk("%02x ", ptr[i]);
724 panic("Foooooooood fight!");
726 any2scsi(cptr[i].dataptr, SCSI_PA(sgpnt[i].address));
727 if (SCSI_PA(sgpnt[i].address + sgpnt[i].length - 1) > ISA_DMA_THRESHOLD)
728 BAD_SG_DMA(SCpnt, sgpnt, SCpnt->use_sg, i);
729 any2scsi(cptr[i].datalen, sgpnt[i].length);
731 any2scsi(ccb[mbo].datalen, SCpnt->use_sg * sizeof(struct chain));
732 any2scsi(ccb[mbo].dataptr, SCSI_PA(cptr));
734 printk("cptr %x: ", cptr);
735 ptr = (unsigned char *) cptr;
736 for (i = 0; i < 18; i++)
737 printk("%02x ", ptr[i]);
740 ccb[mbo].op = 0; /* SCSI Initiator Command */
741 SCpnt->host_scribble = NULL;
742 any2scsi(ccb[mbo].datalen, bufflen);
743 if (buff && SCSI_PA(buff + bufflen - 1) > ISA_DMA_THRESHOLD)
744 BAD_DMA(buff, bufflen);
745 any2scsi(ccb[mbo].dataptr, SCSI_PA(buff));
747 ccb[mbo].idlun = (target & 7) << 5 | direction | (lun & 7); /*SCSI Target Id */
748 ccb[mbo].rsalen = 16;
749 ccb[mbo].linkptr[0] = ccb[mbo].linkptr[1] = ccb[mbo].linkptr[2] = 0;
750 ccb[mbo].commlinkid = 0;
755 printk(KERN_DEBUG "aha1542_command: sending.. ");
756 for (i = 0; i < sizeof(ccb[mbo]) - 10; i++)
757 printk("%02x ", ((unchar *) & ccb[mbo])[i]);
762 DEB(printk("aha1542_queuecommand: now waiting for interrupt ");
764 SCpnt->scsi_done = done;
766 aha1542_out(SCpnt->host->io_port, &ahacmd, 1); /* start scsi command */
769 printk("aha1542_queuecommand: done can't be NULL\n");
774 static void internal_done(Scsi_Cmnd * SCpnt)
779 static int aha1542_command(Scsi_Cmnd * SCpnt)
781 DEB(printk("aha1542_command: ..calling aha1542_queuecommand\n"));
783 aha1542_queuecommand(SCpnt, internal_done);
785 SCpnt->SCp.Status = 0;
786 while (!SCpnt->SCp.Status)
788 return SCpnt->result;
791 /* Initialize mailboxes */
792 static void setup_mailboxes(int bse, struct Scsi_Host *shpnt)
798 unchar cmd[5] = { CMD_MBINIT, AHA1542_MAILBOXES, 0, 0, 0};
800 mb = HOSTDATA(shpnt)->mb;
801 ccb = HOSTDATA(shpnt)->ccb;
803 for (i = 0; i < AHA1542_MAILBOXES; i++) {
804 mb[i].status = mb[AHA1542_MAILBOXES + i].status = 0;
805 any2scsi(mb[i].ccbptr, SCSI_PA(&ccb[i]));
807 aha1542_intr_reset(bse); /* reset interrupts, so they don't block */
808 any2scsi((cmd + 2), SCSI_PA(mb));
809 aha1542_out(bse, cmd, 5);
810 WAIT(INTRFLAGS(bse), INTRMASK, HACC, 0);
813 printk(KERN_ERR "aha1542_detect: failed setting up mailboxes\n");
815 aha1542_intr_reset(bse);
818 static int __init aha1542_getconfig(int base_io, unsigned char *irq_level, unsigned char *dma_chan, unsigned char *scsi_id)
820 unchar inquiry_cmd[] = {CMD_RETCONF};
821 unchar inquiry_result[3];
823 i = inb(STATUS(base_io));
825 i = inb(DATA(base_io));
827 aha1542_out(base_io, inquiry_cmd, 1);
828 aha1542_in(base_io, inquiry_result, 3);
829 WAIT(INTRFLAGS(base_io), INTRMASK, HACC, 0);
832 printk(KERN_ERR "aha1542_detect: query board settings\n");
834 aha1542_intr_reset(base_io);
835 switch (inquiry_result[0]) {
849 /* This means that the adapter, although Adaptec 1542 compatible, doesn't use a DMA channel.
850 Currently only aware of the BusLogic BT-445S VL-Bus adapter which needs this. */
854 printk(KERN_ERR "Unable to determine Adaptec DMA priority. Disabling board\n");
857 switch (inquiry_result[1]) {
877 printk(KERN_ERR "Unable to determine Adaptec IRQ level. Disabling board\n");
880 *scsi_id = inquiry_result[2] & 7;
884 /* This function should only be called for 1542C boards - we can detect
885 the special firmware settings and unlock the board */
887 static int __init aha1542_mbenable(int base)
889 static unchar mbenable_cmd[3];
890 static unchar mbenable_result[2];
893 retval = BIOS_TRANSLATION_6432;
895 mbenable_cmd[0] = CMD_EXTBIOS;
896 aha1542_out(base, mbenable_cmd, 1);
897 if (aha1542_in1(base, mbenable_result, 2))
899 WAITd(INTRFLAGS(base), INTRMASK, HACC, 0, 100);
900 aha1542_intr_reset(base);
902 if ((mbenable_result[0] & 0x08) || mbenable_result[1]) {
903 mbenable_cmd[0] = CMD_MBENABLE;
905 mbenable_cmd[2] = mbenable_result[1];
907 if ((mbenable_result[0] & 0x08) && (mbenable_result[1] & 0x03))
908 retval = BIOS_TRANSLATION_25563;
910 aha1542_out(base, mbenable_cmd, 3);
911 WAIT(INTRFLAGS(base), INTRMASK, HACC, 0);
915 printk(KERN_ERR "aha1542_mbenable: Mailbox init failed\n");
917 aha1542_intr_reset(base);
921 /* Query the board to find out if it is a 1542 or a 1740, or whatever. */
922 static int __init aha1542_query(int base_io, int *transl)
924 unchar inquiry_cmd[] = {CMD_INQUIRY};
925 unchar inquiry_result[4];
927 i = inb(STATUS(base_io));
929 i = inb(DATA(base_io));
931 aha1542_out(base_io, inquiry_cmd, 1);
932 aha1542_in(base_io, inquiry_result, 4);
933 WAIT(INTRFLAGS(base_io), INTRMASK, HACC, 0);
936 printk(KERN_ERR "aha1542_detect: query card type\n");
938 aha1542_intr_reset(base_io);
940 *transl = BIOS_TRANSLATION_6432; /* Default case */
942 /* For an AHA1740 series board, we ignore the board since there is a
943 hardware bug which can lead to wrong blocks being returned if the board
944 is operating in the 1542 emulation mode. Since there is an extended mode
945 driver, we simply ignore the board and let the 1740 driver pick it up.
948 if (inquiry_result[0] == 0x43) {
949 printk(KERN_INFO "aha1542.c: Emulation mode not supported for AHA 174N hardware.\n");
953 /* Always call this - boards that do not support extended bios translation
954 will ignore the command, and we will set the proper default */
956 *transl = aha1542_mbenable(base_io);
962 static int setup_idx = 0;
964 void __init aha1542_setup(char *str, int *ints)
966 const char *ahausage = "aha1542: usage: aha1542=<PORTBASE>[,<BUSON>,<BUSOFF>[,<DMASPEED>]]\n";
969 if (setup_idx >= MAXBOARDS) {
970 printk(KERN_ERR "aha1542: aha1542_setup called too many times! Bad LILO params ?\n");
971 printk(KERN_ERR " Entryline 1: %s\n", setup_str[0]);
972 printk(KERN_ERR " Entryline 2: %s\n", setup_str[1]);
973 printk(KERN_ERR " This line: %s\n", str);
976 if (ints[0] < 1 || ints[0] > 4) {
977 printk(KERN_ERR "aha1542: %s\n", str);
979 printk(KERN_ERR "aha1542: Wrong parameters may cause system malfunction.. We try anyway..\n");
981 setup_called[setup_idx] = ints[0];
982 setup_str[setup_idx] = str;
984 setup_portbase = ints[0] >= 1 ? ints[1] : 0; /* Preserve the default value.. */
985 setup_buson[setup_idx] = ints[0] >= 2 ? ints[2] : 7;
986 setup_busoff[setup_idx] = ints[0] >= 3 ? ints[3] : 5;
1007 printk(KERN_ERR "aha1542: %s\n", str);
1009 printk(KERN_ERR "aha1542: Valid values for DMASPEED are 5-8, 10 MB/s. Using jumper defaults.\n");
1012 setup_dmaspeed[setup_idx] = atbt;
1014 if (setup_portbase != 0)
1015 bases[setup_idx] = setup_portbase;
1020 static int __init do_setup(char *str)
1024 int count=setup_idx;
1026 get_options(str, sizeof(ints)/sizeof(int), ints);
1027 aha1542_setup(str,ints);
1029 return count<setup_idx;
1032 __setup("aha1542=",do_setup);
1035 /* return non-zero on detection */
1036 static int __init aha1542_detect(Scsi_Host_Template * tpnt)
1038 unsigned char dma_chan;
1039 unsigned char irq_level;
1040 unsigned char scsi_id;
1041 unsigned long flags;
1042 unsigned int base_io;
1044 struct Scsi_Host *shpnt = NULL;
1048 DEB(printk("aha1542_detect: \n"));
1050 tpnt->proc_name = "aha1542";
1053 bases[0] = aha1542[0];
1054 setup_buson[0] = aha1542[1];
1055 setup_busoff[0] = aha1542[2];
1058 switch (aha1542[3]) {
1075 setup_dmaspeed[0] = atbt;
1080 * Find MicroChannel cards (AHA1640)
1087 for (indx = 0; (slot != MCA_NOTFOUND) &&
1088 (indx < sizeof(bases)/sizeof(bases[0])); indx++) {
1093 /* Detect only AHA-1640 cards -- MCA ID 0F1F */
1094 slot = mca_find_unused_adapter(0x0f1f, slot);
1095 if (slot == MCA_NOTFOUND)
1100 pos = mca_read_stored_pos(slot, 3);
1102 /* Decode address */
1106 bases[indx] = 0x334;
1108 bases[indx] = 0x234;
1111 bases[indx] = 0x134;
1116 bases[indx] = 0x330;
1118 bases[indx] = 0x230;
1121 bases[indx] = 0x130;
1125 /* No need to decode IRQ and Arb level -- those are
1126 * read off the card later.
1128 printk(KERN_INFO "Found an AHA-1640 in MCA slot %d, I/O 0x%04x\n", slot, bases[indx]);
1130 mca_set_adapter_name(slot, "Adapter AHA-1640");
1131 mca_set_adapter_procfn(slot, NULL, NULL);
1132 mca_mark_as_used(slot);
1142 * Hunt for ISA Plug'n'Pray Adaptecs (AHA1535)
1147 struct pci_dev *pdev = NULL;
1148 for(indx = 0; indx <sizeof(bases)/sizeof(bases[0]);indx++)
1152 pdev = isapnp_find_dev(NULL, ISAPNP_VENDOR('A', 'D', 'P'),
1153 ISAPNP_FUNCTION(0x1542), pdev);
1157 * Activate the PnP card
1160 if(pdev->prepare(pdev)<0)
1163 if(!(pdev->resource[0].flags&IORESOURCE_IO))
1166 pdev->resource[0].flags|=IORESOURCE_AUTO;
1168 if(pdev->activate(pdev)<0)
1171 bases[indx] = pdev->resource[0].start;
1173 /* The card can be queried for its DMA, we have
1174 the DMA set up that is enough */
1176 printk(KERN_INFO "ISAPnP found an AHA1535 at I/O 0x%03X\n", bases[indx]);
1179 for (indx = 0; indx < sizeof(bases) / sizeof(bases[0]); indx++)
1180 if (bases[indx] != 0 && !check_region(bases[indx], 4)) {
1181 shpnt = scsi_register(tpnt,
1182 sizeof(struct aha1542_hostdata));
1186 /* For now we do this - until kmalloc is more intelligent
1187 we are resigned to stupid hacks like this */
1188 if (SCSI_PA(shpnt) >= ISA_DMA_THRESHOLD) {
1189 printk(KERN_ERR "Invalid address for shpnt with 1542.\n");
1192 if (!aha1542_test_port(bases[indx], shpnt))
1196 base_io = bases[indx];
1198 /* Set the Bus on/off-times as not to ruin floppy performance */
1200 unchar oncmd[] = {CMD_BUSON_TIME, 7};
1201 unchar offcmd[] = {CMD_BUSOFF_TIME, 5};
1203 if (setup_called[indx]) {
1204 oncmd[1] = setup_buson[indx];
1205 offcmd[1] = setup_busoff[indx];
1207 aha1542_intr_reset(base_io);
1208 aha1542_out(base_io, oncmd, 2);
1209 WAIT(INTRFLAGS(base_io), INTRMASK, HACC, 0);
1210 aha1542_intr_reset(base_io);
1211 aha1542_out(base_io, offcmd, 2);
1212 WAIT(INTRFLAGS(base_io), INTRMASK, HACC, 0);
1213 if (setup_dmaspeed[indx] >= 0) {
1214 unchar dmacmd[] = {CMD_DMASPEED, 0};
1215 dmacmd[1] = setup_dmaspeed[indx];
1216 aha1542_intr_reset(base_io);
1217 aha1542_out(base_io, dmacmd, 2);
1218 WAIT(INTRFLAGS(base_io), INTRMASK, HACC, 0);
1222 printk(KERN_ERR "aha1542_detect: setting bus on/off-time failed\n");
1224 aha1542_intr_reset(base_io);
1226 if (aha1542_query(base_io, &trans))
1229 if (aha1542_getconfig(base_io, &irq_level, &dma_chan, &scsi_id) == -1)
1232 printk(KERN_INFO "Configuring Adaptec (SCSI-ID %d) at IO:%x, IRQ %d", scsi_id, base_io, irq_level);
1233 if (dma_chan != 0xFF)
1234 printk(", DMA priority %d", dma_chan);
1237 DEB(aha1542_stat());
1238 setup_mailboxes(base_io, shpnt);
1240 DEB(aha1542_stat());
1242 DEB(printk("aha1542_detect: enable interrupt channel %d\n", irq_level));
1245 if (request_irq(irq_level, do_aha1542_intr_handle, 0, "aha1542", NULL)) {
1246 printk(KERN_ERR "Unable to allocate IRQ for adaptec controller.\n");
1247 restore_flags(flags);
1250 if (dma_chan != 0xFF) {
1251 if (request_dma(dma_chan, "aha1542")) {
1252 printk(KERN_ERR "Unable to allocate DMA channel for Adaptec.\n");
1253 free_irq(irq_level, NULL);
1254 restore_flags(flags);
1257 if (dma_chan == 0 || dma_chan >= 5) {
1258 set_dma_mode(dma_chan, DMA_MODE_CASCADE);
1259 enable_dma(dma_chan);
1262 aha_host[irq_level - 9] = shpnt;
1263 shpnt->this_id = scsi_id;
1264 shpnt->unique_id = base_io;
1265 shpnt->io_port = base_io;
1266 shpnt->n_io_port = 4; /* Number of bytes of I/O space used */
1267 shpnt->dma_channel = dma_chan;
1268 shpnt->irq = irq_level;
1269 HOSTDATA(shpnt)->bios_translation = trans;
1270 if (trans == BIOS_TRANSLATION_25563)
1271 printk(KERN_INFO "aha1542.c: Using extended bios translation\n");
1272 HOSTDATA(shpnt)->aha1542_last_mbi_used = (2 * AHA1542_MAILBOXES - 1);
1273 HOSTDATA(shpnt)->aha1542_last_mbo_used = (AHA1542_MAILBOXES - 1);
1274 memset(HOSTDATA(shpnt)->SCint, 0, sizeof(HOSTDATA(shpnt)->SCint));
1275 restore_flags(flags);
1277 DEB(printk(" *** READ CAPACITY ***\n"));
1281 static unchar cmd[] = { READ_CAPACITY, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
1284 for (i = 0; i < sizeof(buf); ++i)
1286 for (i = 0; i < 2; ++i)
1287 if (!aha1542_command(i, cmd, buf, sizeof(buf))) {
1288 printk(KERN_DEBUG "aha_detect: LU %d sector_size %d device_size %d\n",
1289 i, xscsi2int(buf + 4), xscsi2int(buf));
1293 DEB(printk(" *** NOW RUNNING MY OWN TEST *** \n"));
1295 for (i = 0; i < 4; ++i) {
1296 unsigned char cmd[10];
1301 xany2scsi(cmd + 2, i);
1306 aha1542_command(0, cmd, buffer, 512);
1309 request_region(bases[indx], 4, "aha1542"); /* Register the IO ports that we use */
1313 scsi_unregister(shpnt);
1321 static int aha1542_restart(struct Scsi_Host *shost)
1326 unchar ahacmd = CMD_START_SCSI;
1329 for (i = 0; i < AHA1542_MAILBOXES; i++)
1330 if (HOSTDATA(shost)->SCint[i] &&
1331 !(HOSTDATA(shost)->SCint[i]->device->soft_reset)) {
1333 HOSTDATA(shost)->mb[i].status = 1; /* Indicate ready to restart... */
1337 printk(KERN_DEBUG "Potential to restart %d stalled commands...\n", count);
1339 /* start scsi command */
1341 aha1542_out(shost->io_port, &ahacmd, 1);
1346 static int aha1542_abort(Scsi_Cmnd * SCpnt)
1350 * The abort command does not leave the device in a clean state where
1351 * it is available to be used again. Until this gets worked out, we
1352 * will leave it commented out.
1355 printk(KERN_ERR "aha1542.c: Unable to abort command for target %d\n",
1361 * This is a device reset. This is handled by sending a special command
1364 static int aha1542_dev_reset(Scsi_Cmnd * SCpnt)
1366 unsigned long flags;
1368 unchar target = SCpnt->target;
1369 unchar lun = SCpnt->lun;
1372 unchar ahacmd = CMD_START_SCSI;
1374 ccb = HOSTDATA(SCpnt->host)->ccb;
1375 mb = HOSTDATA(SCpnt->host)->mb;
1379 mbo = HOSTDATA(SCpnt->host)->aha1542_last_mbo_used + 1;
1380 if (mbo >= AHA1542_MAILBOXES)
1384 if (mb[mbo].status == 0 && HOSTDATA(SCpnt->host)->SCint[mbo] == NULL)
1387 if (mbo >= AHA1542_MAILBOXES)
1389 } while (mbo != HOSTDATA(SCpnt->host)->aha1542_last_mbo_used);
1391 if (mb[mbo].status || HOSTDATA(SCpnt->host)->SCint[mbo])
1392 panic("Unable to find empty mailbox for aha1542.\n");
1394 HOSTDATA(SCpnt->host)->SCint[mbo] = SCpnt; /* This will effectively
1395 prevent someone else from
1396 screwing with this cdb. */
1398 HOSTDATA(SCpnt->host)->aha1542_last_mbo_used = mbo;
1399 restore_flags(flags);
1401 any2scsi(mb[mbo].ccbptr, SCSI_PA(&ccb[mbo])); /* This gets trashed for some reason */
1403 memset(&ccb[mbo], 0, sizeof(struct ccb));
1405 ccb[mbo].op = 0x81; /* BUS DEVICE RESET */
1407 ccb[mbo].idlun = (target & 7) << 5 | (lun & 7); /*SCSI Target Id */
1409 ccb[mbo].linkptr[0] = ccb[mbo].linkptr[1] = ccb[mbo].linkptr[2] = 0;
1410 ccb[mbo].commlinkid = 0;
1413 * Now tell the 1542 to flush all pending commands for this
1416 aha1542_out(SCpnt->host->io_port, &ahacmd, 1);
1418 printk(KERN_WARNING "aha1542.c: Trying device reset for target %d\n", SCpnt->target);
1423 #ifdef ERIC_neverdef
1425 * With the 1542 we apparently never get an interrupt to
1426 * acknowledge a device reset being sent. Then again, Leonard
1427 * says we are doing this wrong in the first place...
1429 * Take a wait and see attitude. If we get spurious interrupts,
1430 * then the device reset is doing something sane and useful, and
1431 * we will wait for the interrupt to post completion.
1433 printk(KERN_WARNING "Sent BUS DEVICE RESET to target %d\n", SCpnt->target);
1436 * Free the command block for all commands running on this
1439 for (i = 0; i < AHA1542_MAILBOXES; i++) {
1440 if (HOSTDATA(SCpnt->host)->SCint[i] &&
1441 HOSTDATA(SCpnt->host)->SCint[i]->target == SCpnt->target) {
1443 SCtmp = HOSTDATA(SCpnt->host)->SCint[i];
1444 if (SCtmp->host_scribble) {
1445 scsi_free(SCtmp->host_scribble, 512);
1446 SCtmp->host_scribble = NULL;
1448 HOSTDATA(SCpnt->host)->SCint[i] = NULL;
1449 HOSTDATA(SCpnt->host)->mb[i].status = 0;
1455 #endif /* ERIC_neverdef */
1458 static int aha1542_bus_reset(Scsi_Cmnd * SCpnt)
1463 * This does a scsi reset for all devices on the bus.
1464 * In principle, we could also reset the 1542 - should
1465 * we do this? Try this first, and we can add that later
1466 * if it turns out to be useful.
1468 outb(SCRST, CONTROL(SCpnt->host->io_port));
1471 * Wait for the thing to settle down a bit. Unfortunately
1472 * this is going to basically lock up the machine while we
1473 * wait for this to complete. To be 100% correct, we need to
1474 * check for timeout, and if we are doing something like this
1475 * we are pretty desperate anyways.
1477 spin_unlock_irq(&io_request_lock);
1479 spin_lock_irq(&io_request_lock);
1481 WAIT(STATUS(SCpnt->host->io_port),
1482 STATMASK, INIT | IDLE, STST | DIAGF | INVDCMD | DF | CDF);
1485 * Now try to pick up the pieces. For all pending commands,
1486 * free any internal data structures, and basically clear things
1487 * out. We do not try and restart any commands or anything -
1488 * the strategy handler takes care of that crap.
1490 printk(KERN_WARNING "Sent BUS RESET to scsi host %d\n", SCpnt->host->host_no);
1492 for (i = 0; i < AHA1542_MAILBOXES; i++) {
1493 if (HOSTDATA(SCpnt->host)->SCint[i] != NULL) {
1495 SCtmp = HOSTDATA(SCpnt->host)->SCint[i];
1498 if (SCtmp->device->soft_reset) {
1500 * If this device implements the soft reset option,
1501 * then it is still holding onto the command, and
1502 * may yet complete it. In this case, we don't
1507 if (SCtmp->host_scribble) {
1508 scsi_free(SCtmp->host_scribble, 512);
1509 SCtmp->host_scribble = NULL;
1511 HOSTDATA(SCpnt->host)->SCint[i] = NULL;
1512 HOSTDATA(SCpnt->host)->mb[i].status = 0;
1522 static int aha1542_host_reset(Scsi_Cmnd * SCpnt)
1527 * This does a scsi reset for all devices on the bus.
1528 * In principle, we could also reset the 1542 - should
1529 * we do this? Try this first, and we can add that later
1530 * if it turns out to be useful.
1532 outb(HRST | SCRST, CONTROL(SCpnt->host->io_port));
1535 * Wait for the thing to settle down a bit. Unfortunately
1536 * this is going to basically lock up the machine while we
1537 * wait for this to complete. To be 100% correct, we need to
1538 * check for timeout, and if we are doing something like this
1539 * we are pretty desperate anyways.
1541 spin_unlock_irq(&io_request_lock);
1543 spin_lock_irq(&io_request_lock);
1545 WAIT(STATUS(SCpnt->host->io_port),
1546 STATMASK, INIT | IDLE, STST | DIAGF | INVDCMD | DF | CDF);
1549 * We need to do this too before the 1542 can interact with
1552 setup_mailboxes(SCpnt->host->io_port, SCpnt->host);
1555 * Now try to pick up the pieces. For all pending commands,
1556 * free any internal data structures, and basically clear things
1557 * out. We do not try and restart any commands or anything -
1558 * the strategy handler takes care of that crap.
1560 printk(KERN_WARNING "Sent BUS RESET to scsi host %d\n", SCpnt->host->host_no);
1562 for (i = 0; i < AHA1542_MAILBOXES; i++) {
1563 if (HOSTDATA(SCpnt->host)->SCint[i] != NULL) {
1565 SCtmp = HOSTDATA(SCpnt->host)->SCint[i];
1567 if (SCtmp->device->soft_reset) {
1569 * If this device implements the soft reset option,
1570 * then it is still holding onto the command, and
1571 * may yet complete it. In this case, we don't
1576 if (SCtmp->host_scribble) {
1577 scsi_free(SCtmp->host_scribble, 512);
1578 SCtmp->host_scribble = NULL;
1580 HOSTDATA(SCpnt->host)->SCint[i] = NULL;
1581 HOSTDATA(SCpnt->host)->mb[i].status = 0;
1592 * These are the old error handling routines. They are only temporarily
1593 * here while we play with the new error handling code.
1595 static int aha1542_old_abort(Scsi_Cmnd * SCpnt)
1598 unchar ahacmd = CMD_START_SCSI;
1599 unsigned long flags;
1603 printk(KERN_DEBUG "In aha1542_abort: %x %x\n",
1604 inb(STATUS(SCpnt->host->io_port)),
1605 inb(INTRFLAGS(SCpnt->host->io_port)));
1609 mb = HOSTDATA(SCpnt->host)->mb;
1610 mbi = HOSTDATA(SCpnt->host)->aha1542_last_mbi_used + 1;
1611 if (mbi >= 2 * AHA1542_MAILBOXES)
1612 mbi = AHA1542_MAILBOXES;
1615 if (mb[mbi].status != 0)
1618 if (mbi >= 2 * AHA1542_MAILBOXES)
1619 mbi = AHA1542_MAILBOXES;
1620 } while (mbi != HOSTDATA(SCpnt->host)->aha1542_last_mbi_used);
1621 restore_flags(flags);
1623 if (mb[mbi].status) {
1624 printk(KERN_ERR "Lost interrupt discovered on irq %d - attempting to recover\n",
1626 aha1542_intr_handle(SCpnt->host->irq, NULL);
1629 /* OK, no lost interrupt. Try looking to see how many pending commands
1630 we think we have. */
1632 for (i = 0; i < AHA1542_MAILBOXES; i++)
1633 if (HOSTDATA(SCpnt->host)->SCint[i]) {
1634 if (HOSTDATA(SCpnt->host)->SCint[i] == SCpnt) {
1635 printk(KERN_ERR "Timed out command pending for %s\n",
1636 kdevname(SCpnt->request.rq_dev));
1637 if (HOSTDATA(SCpnt->host)->mb[i].status) {
1638 printk(KERN_ERR "OGMB still full - restarting\n");
1639 aha1542_out(SCpnt->host->io_port, &ahacmd, 1);
1642 printk(KERN_ERR "Other pending command %s\n",
1643 kdevname(SCpnt->request.rq_dev));
1647 DEB(printk("aha1542_abort\n"));
1651 for (mbo = 0; mbo < AHA1542_MAILBOXES; mbo++)
1652 if (SCpnt == HOSTDATA(SCpnt->host)->SCint[mbo]) {
1653 mb[mbo].status = 2; /* Abort command */
1654 aha1542_out(SCpnt->host->io_port, &ahacmd, 1); /* start scsi command */
1655 restore_flags(flags);
1659 return SCSI_ABORT_SNOOZE;
1662 /* We do not implement a reset function here, but the upper level code
1663 assumes that it will get some kind of response for the command in
1664 SCpnt. We must oblige, or the command will hang the scsi system.
1665 For a first go, we assume that the 1542 notifies us with all of the
1666 pending commands (it does implement soft reset, after all). */
1668 static int aha1542_old_reset(Scsi_Cmnd * SCpnt, unsigned int reset_flags)
1670 unchar ahacmd = CMD_START_SCSI;
1674 * See if a bus reset was suggested.
1676 if (reset_flags & SCSI_RESET_SUGGEST_BUS_RESET) {
1678 * This does a scsi reset for all devices on the bus.
1679 * In principle, we could also reset the 1542 - should
1680 * we do this? Try this first, and we can add that later
1681 * if it turns out to be useful.
1683 outb(HRST | SCRST, CONTROL(SCpnt->host->io_port));
1686 * Wait for the thing to settle down a bit. Unfortunately
1687 * this is going to basically lock up the machine while we
1688 * wait for this to complete. To be 100% correct, we need to
1689 * check for timeout, and if we are doing something like this
1690 * we are pretty desperate anyways.
1692 WAIT(STATUS(SCpnt->host->io_port),
1693 STATMASK, INIT | IDLE, STST | DIAGF | INVDCMD | DF | CDF);
1696 * We need to do this too before the 1542 can interact with
1699 setup_mailboxes(SCpnt->host->io_port, SCpnt->host);
1702 * Now try to pick up the pieces. Restart all commands
1703 * that are currently active on the bus, and reset all of
1704 * the datastructures. We have some time to kill while
1705 * things settle down, so print a nice message.
1707 printk(KERN_WARNING "Sent BUS RESET to scsi host %d\n", SCpnt->host->host_no);
1709 for (i = 0; i < AHA1542_MAILBOXES; i++)
1710 if (HOSTDATA(SCpnt->host)->SCint[i] != NULL) {
1712 SCtmp = HOSTDATA(SCpnt->host)->SCint[i];
1713 SCtmp->result = DID_RESET << 16;
1714 if (SCtmp->host_scribble) {
1715 scsi_free(SCtmp->host_scribble, 512);
1716 SCtmp->host_scribble = NULL;
1718 printk(KERN_WARNING "Sending DID_RESET for target %d\n", SCpnt->target);
1719 SCtmp->scsi_done(SCpnt);
1721 HOSTDATA(SCpnt->host)->SCint[i] = NULL;
1722 HOSTDATA(SCpnt->host)->mb[i].status = 0;
1725 * Now tell the mid-level code what we did here. Since
1726 * we have restarted all of the outstanding commands,
1727 * then report SUCCESS.
1729 return (SCSI_RESET_SUCCESS | SCSI_RESET_BUS_RESET);
1731 printk(KERN_CRIT "aha1542.c: Unable to perform hard reset.\n");
1732 printk(KERN_CRIT "Power cycle machine to reset\n");
1733 return (SCSI_RESET_ERROR | SCSI_RESET_BUS_RESET);
1737 /* This does a selective reset of just the one device */
1738 /* First locate the ccb for this command */
1739 for (i = 0; i < AHA1542_MAILBOXES; i++)
1740 if (HOSTDATA(SCpnt->host)->SCint[i] == SCpnt) {
1741 HOSTDATA(SCpnt->host)->ccb[i].op = 0x81; /* BUS DEVICE RESET */
1742 /* Now tell the 1542 to flush all pending commands for this target */
1743 aha1542_out(SCpnt->host->io_port, &ahacmd, 1);
1745 /* Here is the tricky part. What to do next. Do we get an interrupt
1746 for the commands that we aborted with the specified target, or
1747 do we generate this on our own? Try it without first and see
1749 printk(KERN_WARNING "Sent BUS DEVICE RESET to target %d\n", SCpnt->target);
1751 /* If the first does not work, then try the second. I think the
1752 first option is more likely to be correct. Free the command
1753 block for all commands running on this target... */
1754 for (i = 0; i < AHA1542_MAILBOXES; i++)
1755 if (HOSTDATA(SCpnt->host)->SCint[i] &&
1756 HOSTDATA(SCpnt->host)->SCint[i]->target == SCpnt->target) {
1758 SCtmp = HOSTDATA(SCpnt->host)->SCint[i];
1759 SCtmp->result = DID_RESET << 16;
1760 if (SCtmp->host_scribble) {
1761 scsi_free(SCtmp->host_scribble, 512);
1762 SCtmp->host_scribble = NULL;
1764 printk(KERN_WARNING "Sending DID_RESET for target %d\n", SCpnt->target);
1765 SCtmp->scsi_done(SCpnt);
1767 HOSTDATA(SCpnt->host)->SCint[i] = NULL;
1768 HOSTDATA(SCpnt->host)->mb[i].status = 0;
1770 return SCSI_RESET_SUCCESS;
1773 /* No active command at this time, so this means that each time we got
1774 some kind of response the last time through. Tell the mid-level code
1775 to request sense information in order to decide what to do next. */
1776 return SCSI_RESET_PUNT;
1781 static int aha1542_biosparam(Scsi_Disk * disk, kdev_t dev, int *ip)
1783 int translation_algorithm;
1784 int size = disk->capacity;
1786 translation_algorithm = HOSTDATA(disk->device->host)->bios_translation;
1788 if ((size >> 11) > 1024 && translation_algorithm == BIOS_TRANSLATION_25563) {
1789 /* Please verify that this is the same as what DOS returns */
1792 ip[2] = size / 255 / 63;
1801 MODULE_LICENSE("GPL");
1804 /* Eventually this will go into an include file, but this will be later */
1805 static Scsi_Host_Template driver_template = AHA1542;
1807 #include "scsi_module.c"