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
26 #include <linux/module.h>
28 #include <linux/kernel.h>
29 #include <linux/types.h>
30 #include <linux/string.h>
31 #include <linux/ioport.h>
32 #include <linux/delay.h>
33 #include <linux/sched.h>
34 #include <linux/proc_fs.h>
35 #include <linux/init.h>
36 #include <linux/spinlock.h>
38 #include <asm/system.h>
40 #include <linux/blk.h>
47 #define SCSI_PA(address) virt_to_bus(address)
49 #define BAD_DMA(msg, address, length) \
51 printk(KERN_CRIT "%s address %p length %d\n", msg, address, length); \
52 panic("Buffer at physical address > 16Mb used for aha1542"); \
55 #include<linux/stat.h>
57 struct proc_dir_entry proc_scsi_aha1542
= {
58 PROC_SCSI_AHA1542
, 7, "aha1542",
59 S_IFDIR
| S_IRUGO
| S_IXUGO
, 2
68 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 $";
71 /* The adaptec can be configured for quite a number of addresses, but
72 I generally do not want the card poking around at random. We allow
73 two addresses - this allows people to use the Adaptec with a Midi
74 card, which also used 0x330 -- can be overridden with LILO! */
76 #define MAXBOARDS 2 /* Increase this and the sizes of the
77 arrays below, if you need more.. */
79 static unsigned int bases
[MAXBOARDS
]={0x330, 0x334};
81 /* set by aha1542_setup according to the command line */
82 static int setup_called
[MAXBOARDS
] = {0,0};
83 static int setup_buson
[MAXBOARDS
] = {0,0};
84 static int setup_busoff
[MAXBOARDS
] = {0,0};
85 static int setup_dmaspeed
[MAXBOARDS
] = {-1,-1};
87 static char *setup_str
[MAXBOARDS
] = {(char *)NULL
,(char *)NULL
};
90 * LILO/Module params: aha1542=<PORTBASE>[,<BUSON>,<BUSOFF>[,<DMASPEED>]]
92 * Where: <PORTBASE> is any of the valid AHA addresses:
93 * 0x130, 0x134, 0x230, 0x234, 0x330, 0x334
94 * <BUSON> is the time (in microsecs) that AHA spends on the AT-bus
95 * when transferring data. 1542A power-on default is 11us,
96 * valid values are in range: 2..15 (decimal)
97 * <BUSOFF> is the time that AHA spends OFF THE BUS after while
98 * it is transferring data (not to monopolize the bus).
99 * Power-on default is 4us, valid range: 1..64 microseconds.
100 * <DMASPEED> Default is jumper selected (1542A: on the J1),
101 * but experimenter can alter it with this.
102 * Valid values: 5, 6, 7, 8, 10 (MB/s)
103 * Factory default is 5 MB/s.
107 int aha1542
[] = { 0x330, 11, 4, -1 };
108 MODULE_PARM(aha1542
, "1-4i");
111 #define BIOS_TRANSLATION_1632 0 /* Used by some old 1542A boards */
112 #define BIOS_TRANSLATION_6432 1 /* Default case these days */
113 #define BIOS_TRANSLATION_25563 2 /* Big disk case */
115 struct aha1542_hostdata
{
116 /* This will effectively start both of them at the first mailbox */
117 int bios_translation
; /* Mapping bios uses - for compatibility */
118 int aha1542_last_mbi_used
;
119 int aha1542_last_mbo_used
;
120 Scsi_Cmnd
* SCint
[AHA1542_MAILBOXES
];
121 struct mailbox mb
[2*AHA1542_MAILBOXES
];
122 struct ccb ccb
[AHA1542_MAILBOXES
];
125 #define HOSTDATA(host) ((struct aha1542_hostdata *) &host->hostdata)
127 static struct Scsi_Host
* aha_host
[7] = {NULL
,}; /* One for each IRQ level (9-15) */
132 #define WAITnexttimeout 3000000
134 static void setup_mailboxes(int base_io
, struct Scsi_Host
* shpnt
);
135 static int aha1542_restart(struct Scsi_Host
* shost
);
136 static void aha1542_intr_handle(int irq
, void *dev_id
, struct pt_regs
*regs
);
137 static void do_aha1542_intr_handle(int irq
, void *dev_id
, struct pt_regs
*regs
);
139 #define aha1542_intr_reset(base) outb(IRST, CONTROL(base))
141 #define WAIT(port, mask, allof, noneof) \
142 { register int WAITbits; \
143 register int WAITtimeout = WAITnexttimeout; \
145 WAITbits = inb(port) & (mask); \
146 if ((WAITbits & (allof)) == (allof) && ((WAITbits & (noneof)) == 0)) \
148 if (--WAITtimeout == 0) goto fail; \
152 /* Similar to WAIT, except we use the udelay call to regulate the
153 amount of time we wait. */
154 #define WAITd(port, mask, allof, noneof, timeout) \
155 { register int WAITbits; \
156 register int WAITtimeout = timeout; \
158 WAITbits = inb(port) & (mask); \
159 if ((WAITbits & (allof)) == (allof) && ((WAITbits & (noneof)) == 0)) \
162 if (--WAITtimeout == 0) goto fail; \
166 static void aha1542_stat(void)
168 /* int s = inb(STATUS), i = inb(INTRFLAGS);
169 printk("status=%x intrflags=%x\n", s, i, WAITnexttimeout-WAITtimeout); */
172 /* This is a bit complicated, but we need to make sure that an interrupt
173 routine does not send something out while we are in the middle of this.
174 Fortunately, it is only at boot time that multi-byte messages
176 static int aha1542_out(unsigned int base
, unchar
*cmdp
, int len
)
178 unsigned long flags
= 0;
183 WAIT(STATUS(base
), CDF
, 0, CDF
);
185 if(inb(STATUS(base
)) & CDF
) {restore_flags(flags
); continue;}
186 outb(*cmdp
, DATA(base
));
187 restore_flags(flags
);
194 WAIT(STATUS(base
), CDF
, 0, CDF
);
195 outb(*cmdp
++, DATA(base
));
197 restore_flags(flags
);
201 restore_flags(flags
);
202 printk("aha1542_out failed(%d): ", len
+1); aha1542_stat();
206 /* Only used at boot time, so we do not need to worry about latency as much
208 static int aha1542_in(unsigned int base
, unchar
*cmdp
, int len
)
216 WAIT(STATUS(base
), DF
, DF
, 0);
217 *cmdp
++ = inb(DATA(base
));
219 restore_flags(flags
);
222 restore_flags(flags
);
223 printk("aha1542_in failed(%d): ", len
+1); aha1542_stat();
227 /* Similar to aha1542_in, except that we wait a very short period of time.
228 We use this if we know the board is alive and awake, but we are not sure
229 if the board will respond to the command we are about to send or not */
230 static int aha1542_in1(unsigned int base
, unchar
*cmdp
, int len
)
238 WAITd(STATUS(base
), DF
, DF
, 0, 100);
239 *cmdp
++ = inb(DATA(base
));
241 restore_flags(flags
);
244 restore_flags(flags
);
248 static int makecode(unsigned hosterr
, unsigned scsierr
)
252 case 0xa: /* Linked command complete without error and linked normally */
253 case 0xb: /* Linked command complete without error, interrupt generated */
257 case 0x11: /* Selection time out-The initiator selection or target
258 reselection was not complete within the SCSI Time out period */
259 hosterr
= DID_TIME_OUT
;
262 case 0x12: /* Data overrun/underrun-The target attempted to transfer more data
263 than was allocated by the Data Length field or the sum of the
264 Scatter / Gather Data Length fields. */
266 case 0x13: /* Unexpected bus free-The target dropped the SCSI BSY at an unexpected time. */
268 case 0x15: /* MBO command was not 00, 01 or 02-The first byte of the CB was
269 invalid. This usually indicates a software failure. */
271 case 0x16: /* Invalid CCB Operation Code-The first byte of the CCB was invalid.
272 This usually indicates a software failure. */
274 case 0x17: /* Linked CCB does not have the same LUN-A subsequent CCB of a set
275 of linked CCB's does not specify the same logical unit number as
277 case 0x18: /* Invalid Target Direction received from Host-The direction of a
278 Target Mode CCB was invalid. */
280 case 0x19: /* Duplicate CCB Received in Target Mode-More than once CCB was
281 received to service data transfer between the same target LUN
282 and initiator SCSI ID in the same direction. */
284 case 0x1a: /* Invalid CCB or Segment List Parameter-A segment list with a zero
285 length segment or invalid segment list boundaries was received.
286 A CCB parameter was invalid. */
287 DEB(printk("Aha1542: %x %x\n", hosterr
, scsierr
));
288 hosterr
= DID_ERROR
; /* Couldn't find any better */
291 case 0x14: /* Target bus phase sequence failure-An invalid bus phase or bus
292 phase sequence was requested by the target. The host adapter
293 will generate a SCSI Reset Condition, notifying the host with
298 printk("makecode: unknown hoststatus %x\n", hosterr
);
301 return scsierr
|(hosterr
<< 16);
304 static int aha1542_test_port(int bse
, struct Scsi_Host
* shpnt
)
306 unchar inquiry_cmd
[] = {CMD_INQUIRY
};
307 unchar inquiry_result
[4];
310 volatile int debug
= 0;
312 /* Quick and dirty test for presence of the card. */
313 if(inb(STATUS(bse
)) == 0xff) return 0;
315 /* Reset the adapter. I ought to make a hard reset, but it's not really necessary */
317 /* DEB(printk("aha1542_test_port called \n")); */
319 /* In case some other card was probing here, reset interrupts */
320 aha1542_intr_reset(bse
); /* reset interrupts, so they don't block */
322 outb(SRST
|IRST
/*|SCRST*/, CONTROL(bse
));
324 mdelay(20); /* Wait a little bit for things to settle down. */
327 /* Expect INIT and IDLE, any of the others are bad */
328 WAIT(STATUS(bse
), STATMASK
, INIT
|IDLE
, STST
|DIAGF
|INVDCMD
|DF
|CDF
);
331 /* Shouldn't have generated any interrupts during reset */
332 if (inb(INTRFLAGS(bse
))&INTRMASK
) goto fail
;
335 /* Perform a host adapter inquiry instead so we do not need to set
336 up the mailboxes ahead of time */
338 aha1542_out(bse
, inquiry_cmd
, 1);
342 cmdp
= &inquiry_result
[0];
346 WAIT(STATUS(bse
), DF
, DF
, 0);
347 *cmdp
++ = inb(DATA(bse
));
351 /* Reading port should reset DF */
352 if (inb(STATUS(bse
)) & DF
) goto fail
;
355 /* When HACC, command is completed, and we're though testing */
356 WAIT(INTRFLAGS(bse
), HACC
, HACC
, 0);
357 /* now initialize adapter */
360 /* Clear interrupts */
361 outb(IRST
, CONTROL(bse
));
365 return debug
; /* 1 = ok */
367 return 0; /* 0 = not ok */
370 /* A quick wrapper for do_aha1542_intr_handle to grab the spin lock */
371 static void do_aha1542_intr_handle(int irq
, void *dev_id
, struct pt_regs
*regs
)
375 spin_lock_irqsave(&io_request_lock
, flags
);
376 aha1542_intr_handle(irq
, dev_id
, regs
);
377 spin_unlock_irqrestore(&io_request_lock
, flags
);
380 /* A "high" level interrupt handler */
381 static void aha1542_intr_handle(int irq
, void *dev_id
, struct pt_regs
*regs
)
383 void (*my_done
)(Scsi_Cmnd
*) = NULL
;
384 int errstatus
, mbi
, mbo
, mbistatus
;
387 struct Scsi_Host
* shost
;
394 shost
= aha_host
[irq
- 9];
395 if(!shost
) panic("Splunge!");
397 mb
= HOSTDATA(shost
)->mb
;
398 ccb
= HOSTDATA(shost
)->ccb
;
402 flag
= inb(INTRFLAGS(shost
->io_port
));
403 printk("aha1542_intr_handle: ");
404 if (!(flag
&ANYINTR
)) printk("no interrupt?");
405 if (flag
&MBIF
) printk("MBIF ");
406 if (flag
&MBOA
) printk("MBOF ");
407 if (flag
&HACC
) printk("HACC ");
408 if (flag
&SCRD
) printk("SCRD ");
409 printk("status %02x\n", inb(STATUS(shost
->io_port
)));
416 flag
= inb(INTRFLAGS(shost
->io_port
));
418 /* Check for unusual interrupts. If any of these happen, we should
419 probably do something special, but for now just printing a message
420 is sufficient. A SCSI reset detected is something that we really
421 need to deal with in some way. */
423 if (flag
&MBOA
) printk("MBOF ");
424 if (flag
&HACC
) printk("HACC ");
431 aha1542_intr_reset(shost
->io_port
);
435 mbi
= HOSTDATA(shost
)->aha1542_last_mbi_used
+ 1;
436 if (mbi
>= 2*AHA1542_MAILBOXES
) mbi
= AHA1542_MAILBOXES
;
439 if(mb
[mbi
].status
!= 0) break;
441 if (mbi
>= 2*AHA1542_MAILBOXES
) mbi
= AHA1542_MAILBOXES
;
442 } while (mbi
!= HOSTDATA(shost
)->aha1542_last_mbi_used
);
444 if(mb
[mbi
].status
== 0){
445 restore_flags(flags
);
446 /* Hmm, no mail. Must have read it the last time around */
447 if (!number_serviced
&& !needs_restart
)
448 printk("aha1542.c: interrupt received, but no mail.\n");
449 /* We detected a reset. Restart all pending commands for
450 devices that use the hard reset option */
451 if(needs_restart
) aha1542_restart(shost
);
455 mbo
= (scsi2int(mb
[mbi
].ccbptr
) - (SCSI_PA(&ccb
[0]))) / sizeof(struct ccb
);
456 mbistatus
= mb
[mbi
].status
;
458 HOSTDATA(shost
)->aha1542_last_mbi_used
= mbi
;
459 restore_flags(flags
);
463 if (ccb
[mbo
].tarstat
|ccb
[mbo
].hastat
)
464 printk("aha1542_command: returning %x (status %d)\n",
465 ccb
[mbo
].tarstat
+ ((int) ccb
[mbo
].hastat
<< 16), mb
[mbi
].status
);
469 if(mbistatus
== 3) continue; /* Aborted command not found */
472 printk("...done %d %d\n",mbo
, mbi
);
475 SCtmp
= HOSTDATA(shost
)->SCint
[mbo
];
477 if (!SCtmp
|| !SCtmp
->scsi_done
) {
478 printk("aha1542_intr_handle: Unexpected interrupt\n");
479 printk("tarstat=%x, hastat=%x idlun=%x ccb#=%d \n", ccb
[mbo
].tarstat
,
480 ccb
[mbo
].hastat
, ccb
[mbo
].idlun
, mbo
);
484 my_done
= SCtmp
->scsi_done
;
485 if (SCtmp
->host_scribble
) scsi_free(SCtmp
->host_scribble
, 512);
487 /* Fetch the sense data, and tuck it away, in the required slot. The
488 Adaptec automatically fetches it, and there is no guarantee that
489 we will still have it in the cdb when we come back */
490 if (ccb
[mbo
].tarstat
== 2)
491 memcpy(SCtmp
->sense_buffer
, &ccb
[mbo
].cdb
[ccb
[mbo
].cdblen
],
492 sizeof(SCtmp
->sense_buffer
));
495 /* is there mail :-) */
497 /* more error checking left out here */
499 /* This is surely wrong, but I don't know what's right */
500 errstatus
= makecode(ccb
[mbo
].hastat
, ccb
[mbo
].tarstat
);
505 if(errstatus
) printk("(aha1542 error:%x %x %x) ",errstatus
,
506 ccb
[mbo
].hastat
, ccb
[mbo
].tarstat
);
509 if (ccb
[mbo
].tarstat
== 2) {
513 DEB(printk("aha1542_intr_handle: sense:"));
515 for (i
= 0; i
< 12; i
++)
516 printk("%02x ", ccb
[mbo
].cdb
[ccb
[mbo
].cdblen
+i
]);
520 DEB(printk("aha1542_intr_handle: buf:"));
521 for (i = 0; i < bufflen; i++)
522 printk("%02x ", ((unchar *)buff)[i]);
526 DEB(if (errstatus
) printk("aha1542_intr_handle: returning %6x\n", errstatus
));
527 SCtmp
->result
= errstatus
;
528 HOSTDATA(shost
)->SCint
[mbo
] = NULL
; /* This effectively frees up the mailbox slot, as
529 far as queuecommand is concerned */
535 int aha1542_queuecommand(Scsi_Cmnd
* SCpnt
, void (*done
)(Scsi_Cmnd
*))
537 unchar ahacmd
= CMD_START_SCSI
;
539 unchar
*cmd
= (unchar
*) SCpnt
->cmnd
;
540 unchar target
= SCpnt
->target
;
541 unchar lun
= SCpnt
->lun
;
543 void *buff
= SCpnt
->request_buffer
;
544 int bufflen
= SCpnt
->request_bufflen
;
551 mb
= HOSTDATA(SCpnt
->host
)->mb
;
552 ccb
= HOSTDATA(SCpnt
->host
)->ccb
;
554 DEB(if (target
> 1) {
555 SCpnt
->result
= DID_TIME_OUT
<< 16;
556 done(SCpnt
); return 0;});
558 if(*cmd
== REQUEST_SENSE
){
560 if (bufflen
!= sizeof(SCpnt
->sense_buffer
)) {
561 printk("Wrong buffer length supplied for request sense (%d)\n",bufflen
);
570 if (*cmd
== READ_10
|| *cmd
== WRITE_10
)
571 i
= xscsi2int(cmd
+2);
572 else if (*cmd
== READ_6
|| *cmd
== WRITE_6
)
577 printk("aha1542_queuecommand: dev %d cmd %02x pos %d len %d ", target
, *cmd
, i
, bufflen
);
579 printk("aha1542_command: dev %d cmd %02x pos %d len %d ", target
, *cmd
, i
, bufflen
);
581 printk("aha1542_queuecommand: dumping scsi cmd:");
582 for (i
= 0; i
< SCpnt
->cmd_len
; i
++) printk("%02x ", cmd
[i
]);
584 if (*cmd
== WRITE_10
|| *cmd
== WRITE_6
)
585 return 0; /* we are still testing, so *don't* write */
587 /* Use the outgoing mailboxes in a round-robin fashion, because this
588 is how the host adapter will scan for them */
592 mbo
= HOSTDATA(SCpnt
->host
)->aha1542_last_mbo_used
+ 1;
593 if (mbo
>= AHA1542_MAILBOXES
) mbo
= 0;
596 if(mb
[mbo
].status
== 0 && HOSTDATA(SCpnt
->host
)->SCint
[mbo
] == NULL
)
599 if (mbo
>= AHA1542_MAILBOXES
) mbo
= 0;
600 } while (mbo
!= HOSTDATA(SCpnt
->host
)->aha1542_last_mbo_used
);
602 if(mb
[mbo
].status
|| HOSTDATA(SCpnt
->host
)->SCint
[mbo
])
603 panic("Unable to find empty mailbox for aha1542.\n");
605 HOSTDATA(SCpnt
->host
)->SCint
[mbo
] = SCpnt
; /* This will effectively prevent someone else from
606 screwing with this cdb. */
608 HOSTDATA(SCpnt
->host
)->aha1542_last_mbo_used
= mbo
;
609 restore_flags(flags
);
612 printk("Sending command (%d %x)...",mbo
, done
);
615 any2scsi(mb
[mbo
].ccbptr
, SCSI_PA(&ccb
[mbo
])); /* This gets trashed for some reason*/
617 memset(&ccb
[mbo
], 0, sizeof(struct ccb
));
619 ccb
[mbo
].cdblen
= SCpnt
->cmd_len
;
622 if (*cmd
== READ_10
|| *cmd
== READ_6
)
624 else if (*cmd
== WRITE_10
|| *cmd
== WRITE_6
)
627 memcpy(ccb
[mbo
].cdb
, cmd
, ccb
[mbo
].cdblen
);
630 struct scatterlist
* sgpnt
;
636 ccb
[mbo
].op
= 2; /* SCSI Initiator Command w/scatter-gather*/
637 SCpnt
->host_scribble
= (unsigned char *) scsi_malloc(512);
638 sgpnt
= (struct scatterlist
*) SCpnt
->request_buffer
;
639 cptr
= (struct chain
*) SCpnt
->host_scribble
;
640 if (cptr
== NULL
) panic("aha1542.c: unable to allocate DMA memory\n");
641 for(i
=0; i
<SCpnt
->use_sg
; i
++) {
642 if(sgpnt
[i
].length
== 0 || SCpnt
->use_sg
> 16 ||
643 (((int)sgpnt
[i
].address
) & 1) || (sgpnt
[i
].length
& 1)){
645 printk("Bad segment list supplied to aha1542.c (%d, %d)\n",SCpnt
->use_sg
,i
);
646 for(i
=0;i
<SCpnt
->use_sg
;i
++){
647 printk("%d: %x %x %d\n",i
,(unsigned int) sgpnt
[i
].address
, (unsigned int) sgpnt
[i
].alt_address
,
650 printk("cptr %x: ",(unsigned int) cptr
);
651 ptr
= (unsigned char *) &cptr
[i
];
652 for(i
=0;i
<18;i
++) printk("%02x ", ptr
[i
]);
653 panic("Foooooooood fight!");
655 any2scsi(cptr
[i
].dataptr
, SCSI_PA(sgpnt
[i
].address
));
656 if(SCSI_PA(sgpnt
[i
].address
+sgpnt
[i
].length
-1) > ISA_DMA_THRESHOLD
)
657 BAD_DMA("sgpnt", sgpnt
[i
].address
, sgpnt
[i
].length
);
658 any2scsi(cptr
[i
].datalen
, sgpnt
[i
].length
);
660 any2scsi(ccb
[mbo
].datalen
, SCpnt
->use_sg
* sizeof(struct chain
));
661 any2scsi(ccb
[mbo
].dataptr
, SCSI_PA(cptr
));
663 printk("cptr %x: ",cptr
);
664 ptr
= (unsigned char *) cptr
;
665 for(i
=0;i
<18;i
++) printk("%02x ", ptr
[i
]);
668 ccb
[mbo
].op
= 0; /* SCSI Initiator Command */
669 SCpnt
->host_scribble
= NULL
;
670 any2scsi(ccb
[mbo
].datalen
, bufflen
);
671 if(buff
&& SCSI_PA(buff
+bufflen
-1) > ISA_DMA_THRESHOLD
)
672 BAD_DMA("buff", buff
, bufflen
);
673 any2scsi(ccb
[mbo
].dataptr
, SCSI_PA(buff
));
675 ccb
[mbo
].idlun
= (target
&7)<<5 | direction
| (lun
& 7); /*SCSI Target Id*/
676 ccb
[mbo
].rsalen
= 16;
677 ccb
[mbo
].linkptr
[0] = ccb
[mbo
].linkptr
[1] = ccb
[mbo
].linkptr
[2] = 0;
678 ccb
[mbo
].commlinkid
= 0;
682 printk("aha1542_command: sending.. ");
683 for (i
= 0; i
< sizeof(ccb
[mbo
])-10; i
++)
684 printk("%02x ", ((unchar
*)&ccb
[mbo
])[i
]);
689 DEB(printk("aha1542_queuecommand: now waiting for interrupt "); aha1542_stat());
690 SCpnt
->scsi_done
= done
;
692 aha1542_out(SCpnt
->host
->io_port
, &ahacmd
, 1); /* start scsi command */
696 printk("aha1542_queuecommand: done can't be NULL\n");
701 static void internal_done(Scsi_Cmnd
* SCpnt
)
706 int aha1542_command(Scsi_Cmnd
* SCpnt
)
708 DEB(printk("aha1542_command: ..calling aha1542_queuecommand\n"));
710 aha1542_queuecommand(SCpnt
, internal_done
);
712 SCpnt
->SCp
.Status
= 0;
713 while (!SCpnt
->SCp
.Status
)
715 return SCpnt
->result
;
718 /* Initialize mailboxes */
719 static void setup_mailboxes(int bse
, struct Scsi_Host
* shpnt
)
725 unchar cmd
[5] = {CMD_MBINIT
, AHA1542_MAILBOXES
, 0, 0, 0};
727 mb
= HOSTDATA(shpnt
)->mb
;
728 ccb
= HOSTDATA(shpnt
)->ccb
;
730 for(i
=0; i
<AHA1542_MAILBOXES
; i
++){
731 mb
[i
].status
= mb
[AHA1542_MAILBOXES
+i
].status
= 0;
732 any2scsi(mb
[i
].ccbptr
, SCSI_PA(&ccb
[i
]));
734 aha1542_intr_reset(bse
); /* reset interrupts, so they don't block */
735 any2scsi((cmd
+2), SCSI_PA(mb
));
736 aha1542_out(bse
, cmd
, 5);
737 WAIT(INTRFLAGS(bse
), INTRMASK
, HACC
, 0);
740 printk("aha1542_detect: failed setting up mailboxes\n");
742 aha1542_intr_reset(bse
);
745 static int aha1542_getconfig(int base_io
, unsigned char * irq_level
, unsigned char * dma_chan
, unsigned char * scsi_id
)
747 unchar inquiry_cmd
[] = {CMD_RETCONF
};
748 unchar inquiry_result
[3];
750 i
= inb(STATUS(base_io
));
752 i
= inb(DATA(base_io
));
754 aha1542_out(base_io
, inquiry_cmd
, 1);
755 aha1542_in(base_io
, inquiry_result
, 3);
756 WAIT(INTRFLAGS(base_io
), INTRMASK
, HACC
, 0);
759 printk("aha1542_detect: query board settings\n");
761 aha1542_intr_reset(base_io
);
762 switch(inquiry_result
[0]){
776 /* This means that the adapter, although Adaptec 1542 compatible, doesn't use a DMA channel.
777 Currently only aware of the BusLogic BT-445S VL-Bus adapter which needs this. */
781 printk("Unable to determine Adaptec DMA priority. Disabling board\n");
784 switch(inquiry_result
[1]){
804 printk("Unable to determine Adaptec IRQ level. Disabling board\n");
807 *scsi_id
=inquiry_result
[2] & 7;
811 /* This function should only be called for 1542C boards - we can detect
812 the special firmware settings and unlock the board */
814 static int aha1542_mbenable(int base
)
816 static unchar mbenable_cmd
[3];
817 static unchar mbenable_result
[2];
820 retval
= BIOS_TRANSLATION_6432
;
822 mbenable_cmd
[0]=CMD_EXTBIOS
;
823 aha1542_out(base
,mbenable_cmd
,1);
824 if(aha1542_in1(base
,mbenable_result
,2))
826 WAITd(INTRFLAGS(base
),INTRMASK
,HACC
,0,100);
827 aha1542_intr_reset(base
);
829 if ((mbenable_result
[0] & 0x08) || mbenable_result
[1]) {
830 mbenable_cmd
[0]=CMD_MBENABLE
;
832 mbenable_cmd
[2]=mbenable_result
[1];
834 if((mbenable_result
[0] & 0x08) && (mbenable_result
[1] & 0x03))
835 retval
= BIOS_TRANSLATION_25563
;
837 aha1542_out(base
,mbenable_cmd
,3);
838 WAIT(INTRFLAGS(base
),INTRMASK
,HACC
,0);
842 printk("aha1542_mbenable: Mailbox init failed\n");
844 aha1542_intr_reset(base
);
848 /* Query the board to find out if it is a 1542 or a 1740, or whatever. */
849 static int aha1542_query(int base_io
, int * transl
)
851 unchar inquiry_cmd
[] = {CMD_INQUIRY
};
852 unchar inquiry_result
[4];
854 i
= inb(STATUS(base_io
));
856 i
= inb(DATA(base_io
));
858 aha1542_out(base_io
, inquiry_cmd
, 1);
859 aha1542_in(base_io
, inquiry_result
, 4);
860 WAIT(INTRFLAGS(base_io
), INTRMASK
, HACC
, 0);
863 printk("aha1542_detect: query card type\n");
865 aha1542_intr_reset(base_io
);
867 *transl
= BIOS_TRANSLATION_6432
; /* Default case */
869 /* For an AHA1740 series board, we ignore the board since there is a
870 hardware bug which can lead to wrong blocks being returned if the board
871 is operating in the 1542 emulation mode. Since there is an extended mode
872 driver, we simply ignore the board and let the 1740 driver pick it up.
875 if (inquiry_result
[0] == 0x43) {
876 printk("aha1542.c: Emulation mode not supported for AHA 174N hardware.\n");
880 /* Always call this - boards that do not support extended bios translation
881 will ignore the command, and we will set the proper default */
883 *transl
= aha1542_mbenable(base_io
);
888 /* called from init/main.c */
889 void __init
aha1542_setup( char *str
, int *ints
)
891 const char *ahausage
= "aha1542: usage: aha1542=<PORTBASE>[,<BUSON>,<BUSOFF>[,<DMASPEED>]]\n";
892 static int setup_idx
= 0;
895 if(setup_idx
>= MAXBOARDS
)
897 printk("aha1542: aha1542_setup called too many times! Bad LILO params ?\n");
898 printk(" Entryline 1: %s\n",setup_str
[0]);
899 printk(" Entryline 2: %s\n",setup_str
[1]);
900 printk(" This line: %s\n",str
);
903 if (ints
[0] < 1 || ints
[0] > 4)
905 printk("aha1542: %s\n", str
);
907 printk("aha1542: Wrong parameters may cause system malfunction.. We try anyway..\n");
910 setup_called
[setup_idx
]=ints
[0];
911 setup_str
[setup_idx
]=str
;
913 setup_portbase
= ints
[0] >= 1 ? ints
[1] : 0; /* Preserve the default value.. */
914 setup_buson
[setup_idx
] = ints
[0] >= 2 ? ints
[2] : 7;
915 setup_busoff
[setup_idx
] = ints
[0] >= 3 ? ints
[3] : 5;
935 printk("aha1542: %s\n", str
);
937 printk("aha1542: Valid values for DMASPEED are 5-8, 10 MB/s. Using jumper defaults.\n");
940 setup_dmaspeed
[setup_idx
] = atbt
;
943 if (setup_portbase
!= 0)
944 bases
[setup_idx
] = setup_portbase
;
949 /* return non-zero on detection */
950 int aha1542_detect(Scsi_Host_Template
* tpnt
)
952 unsigned char dma_chan
;
953 unsigned char irq_level
;
954 unsigned char scsi_id
;
956 unsigned int base_io
;
958 struct Scsi_Host
* shpnt
= NULL
;
962 DEB(printk("aha1542_detect: \n"));
964 tpnt
->proc_dir
= &proc_scsi_aha1542
;
968 bases
[1] = aha1542
[0];
969 bases
[2] = aha1542
[1];
970 bases
[3] = aha1542
[2];
971 bases
[4] = aha1542
[3];
974 for(indx
= 0; indx
< sizeof(bases
)/sizeof(bases
[0]); indx
++)
975 if(bases
[indx
] != 0 && !check_region(bases
[indx
], 4)) {
976 shpnt
= scsi_register(tpnt
,
977 sizeof(struct aha1542_hostdata
));
979 /* For now we do this - until kmalloc is more intelligent
980 we are resigned to stupid hacks like this */
981 if (SCSI_PA(shpnt
) >= ISA_DMA_THRESHOLD
) {
982 printk("Invalid address for shpnt with 1542.\n");
986 if(!aha1542_test_port(bases
[indx
], shpnt
)) goto unregister
;
989 base_io
= bases
[indx
];
991 /* Set the Bus on/off-times as not to ruin floppy performance */
993 unchar oncmd
[] = {CMD_BUSON_TIME
, 7};
994 unchar offcmd
[] = {CMD_BUSOFF_TIME
, 5};
996 if(setup_called
[indx
])
998 oncmd
[1] = setup_buson
[indx
];
999 offcmd
[1] = setup_busoff
[indx
];
1002 aha1542_intr_reset(base_io
);
1003 aha1542_out(base_io
, oncmd
, 2);
1004 WAIT(INTRFLAGS(base_io
), INTRMASK
, HACC
, 0);
1005 aha1542_intr_reset(base_io
);
1006 aha1542_out(base_io
, offcmd
, 2);
1007 WAIT(INTRFLAGS(base_io
), INTRMASK
, HACC
, 0);
1008 if (setup_dmaspeed
[indx
] >= 0)
1010 unchar dmacmd
[] = {CMD_DMASPEED
, 0};
1011 dmacmd
[1] = setup_dmaspeed
[indx
];
1012 aha1542_intr_reset(base_io
);
1013 aha1542_out(base_io
, dmacmd
, 2);
1014 WAIT(INTRFLAGS(base_io
), INTRMASK
, HACC
, 0);
1018 printk("aha1542_detect: setting bus on/off-time failed\n");
1020 aha1542_intr_reset(base_io
);
1022 if(aha1542_query(base_io
, &trans
)) goto unregister
;
1024 if (aha1542_getconfig(base_io
, &irq_level
, &dma_chan
, &scsi_id
) == -1) goto unregister
;
1026 printk("Configuring Adaptec (SCSI-ID %d) at IO:%x, IRQ %d", scsi_id
, base_io
, irq_level
);
1027 if (dma_chan
!= 0xFF)
1028 printk(", DMA priority %d", dma_chan
);
1031 DEB(aha1542_stat());
1032 setup_mailboxes(base_io
, shpnt
);
1034 DEB(aha1542_stat());
1036 DEB(printk("aha1542_detect: enable interrupt channel %d\n", irq_level
));
1039 if (request_irq(irq_level
,do_aha1542_intr_handle
, 0, "aha1542", NULL
)) {
1040 printk("Unable to allocate IRQ for adaptec controller.\n");
1041 restore_flags(flags
);
1045 if (dma_chan
!= 0xFF) {
1046 if (request_dma(dma_chan
,"aha1542")) {
1047 printk("Unable to allocate DMA channel for Adaptec.\n");
1048 free_irq(irq_level
, NULL
);
1049 restore_flags(flags
);
1053 if (dma_chan
== 0 || dma_chan
>= 5) {
1054 set_dma_mode(dma_chan
, DMA_MODE_CASCADE
);
1055 enable_dma(dma_chan
);
1058 aha_host
[irq_level
- 9] = shpnt
;
1059 shpnt
->this_id
= scsi_id
;
1060 shpnt
->unique_id
= base_io
;
1061 shpnt
->io_port
= base_io
;
1062 shpnt
->n_io_port
= 4; /* Number of bytes of I/O space used */
1063 shpnt
->dma_channel
= dma_chan
;
1064 shpnt
->irq
= irq_level
;
1065 HOSTDATA(shpnt
)->bios_translation
= trans
;
1066 if(trans
== BIOS_TRANSLATION_25563
)
1067 printk("aha1542.c: Using extended bios translation\n");
1068 HOSTDATA(shpnt
)->aha1542_last_mbi_used
= (2*AHA1542_MAILBOXES
- 1);
1069 HOSTDATA(shpnt
)->aha1542_last_mbo_used
= (AHA1542_MAILBOXES
- 1);
1070 memset(HOSTDATA(shpnt
)->SCint
, 0, sizeof(HOSTDATA(shpnt
)->SCint
));
1071 restore_flags(flags
);
1073 DEB(printk(" *** READ CAPACITY ***\n"));
1077 static unchar cmd
[] = { READ_CAPACITY
, 0, 0, 0, 0, 0, 0, 0, 0, 0};
1080 for (i
= 0; i
< sizeof(buf
); ++i
) buf
[i
] = 0x87;
1081 for (i
= 0; i
< 2; ++i
)
1082 if (!aha1542_command(i
, cmd
, buf
, sizeof(buf
))) {
1083 printk("aha_detect: LU %d sector_size %d device_size %d\n",
1084 i
, xscsi2int(buf
+4), xscsi2int(buf
));
1088 DEB(printk(" *** NOW RUNNING MY OWN TEST *** \n"));
1090 for (i
= 0; i
< 4; ++i
)
1092 unsigned char cmd
[10];
1097 xany2scsi(cmd
+2, i
);
1102 aha1542_command(0, cmd
, buffer
, 512);
1105 request_region(bases
[indx
], 4,"aha1542"); /* Register the IO ports that we use */
1109 scsi_unregister(shpnt
);
1117 static int aha1542_restart(struct Scsi_Host
* shost
)
1122 unchar ahacmd
= CMD_START_SCSI
;
1125 for(i
=0; i
< AHA1542_MAILBOXES
; i
++)
1126 if(HOSTDATA(shost
)->SCint
[i
] &&
1127 !(HOSTDATA(shost
)->SCint
[i
]->device
->soft_reset
))
1130 HOSTDATA(shost
)->mb
[i
].status
= 1; /* Indicate ready to restart... */
1135 printk("Potential to restart %d stalled commands...\n", count
);
1137 /* start scsi command */
1138 if (count
) aha1542_out(shost
->io_port
, &ahacmd
, 1);
1143 int aha1542_abort(Scsi_Cmnd
* SCpnt
)
1147 * The abort command does not leave the device in a clean state where
1148 * it is available to be used again. Until this gets worked out, we
1149 * will leave it commented out.
1152 printk("aha1542.c: Unable to abort command for target %d\n",
1158 * This is a device reset. This is handled by sending a special command
1161 int aha1542_dev_reset(Scsi_Cmnd
* SCpnt
)
1163 unsigned long flags
;
1164 struct mailbox
* mb
;
1165 unchar target
= SCpnt
->target
;
1166 unchar lun
= SCpnt
->lun
;
1169 unchar ahacmd
= CMD_START_SCSI
;
1171 ccb
= HOSTDATA(SCpnt
->host
)->ccb
;
1172 mb
= HOSTDATA(SCpnt
->host
)->mb
;
1176 mbo
= HOSTDATA(SCpnt
->host
)->aha1542_last_mbo_used
+ 1;
1177 if (mbo
>= AHA1542_MAILBOXES
) mbo
= 0;
1180 if(mb
[mbo
].status
== 0 && HOSTDATA(SCpnt
->host
)->SCint
[mbo
] == NULL
)
1183 if (mbo
>= AHA1542_MAILBOXES
) mbo
= 0;
1184 } while (mbo
!= HOSTDATA(SCpnt
->host
)->aha1542_last_mbo_used
);
1186 if(mb
[mbo
].status
|| HOSTDATA(SCpnt
->host
)->SCint
[mbo
])
1187 panic("Unable to find empty mailbox for aha1542.\n");
1189 HOSTDATA(SCpnt
->host
)->SCint
[mbo
] = SCpnt
; /* This will effectively
1190 prevent someone else from
1191 screwing with this cdb. */
1193 HOSTDATA(SCpnt
->host
)->aha1542_last_mbo_used
= mbo
;
1194 restore_flags(flags
);
1196 any2scsi(mb
[mbo
].ccbptr
, SCSI_PA(&ccb
[mbo
])); /* This gets trashed for some reason*/
1198 memset(&ccb
[mbo
], 0, sizeof(struct ccb
));
1200 ccb
[mbo
].op
= 0x81; /* BUS DEVICE RESET */
1202 ccb
[mbo
].idlun
= (target
&7)<<5 | (lun
& 7); /*SCSI Target Id*/
1204 ccb
[mbo
].linkptr
[0] = ccb
[mbo
].linkptr
[1] = ccb
[mbo
].linkptr
[2] = 0;
1205 ccb
[mbo
].commlinkid
= 0;
1208 * Now tell the 1542 to flush all pending commands for this
1211 aha1542_out(SCpnt
->host
->io_port
, &ahacmd
, 1);
1213 printk("aha1542.c: Trying device reset for target %d\n", SCpnt
->target
);
1218 #ifdef ERIC_neverdef
1220 * With the 1542 we apparently never get an interrupt to
1221 * acknowledge a device reset being sent. Then again, Leonard
1222 * says we are doing this wrong in the first place...
1224 * Take a wait and see attitude. If we get spurious interrupts,
1225 * then the device reset is doing something sane and useful, and
1226 * we will wait for the interrupt to post completion.
1228 printk("Sent BUS DEVICE RESET to target %d\n", SCpnt
->target
);
1231 * Free the command block for all commands running on this
1234 for(i
=0; i
< AHA1542_MAILBOXES
; i
++)
1236 if(HOSTDATA(SCpnt
->host
)->SCint
[i
] &&
1237 HOSTDATA(SCpnt
->host
)->SCint
[i
]->target
== SCpnt
->target
)
1240 SCtmp
= HOSTDATA(SCpnt
->host
)->SCint
[i
];
1241 if (SCtmp
->host_scribble
)
1243 scsi_free(SCtmp
->host_scribble
, 512);
1246 HOSTDATA(SCpnt
->host
)->SCint
[i
] = NULL
;
1247 HOSTDATA(SCpnt
->host
)->mb
[i
].status
= 0;
1253 #endif /* ERIC_neverdef */
1256 int aha1542_bus_reset(Scsi_Cmnd
* SCpnt
)
1261 * This does a scsi reset for all devices on the bus.
1262 * In principle, we could also reset the 1542 - should
1263 * we do this? Try this first, and we can add that later
1264 * if it turns out to be useful.
1266 outb(SCRST
, CONTROL(SCpnt
->host
->io_port
));
1269 * Wait for the thing to settle down a bit. Unfortunately
1270 * this is going to basically lock up the machine while we
1271 * wait for this to complete. To be 100% correct, we need to
1272 * check for timeout, and if we are doing something like this
1273 * we are pretty desperate anyways.
1277 WAIT(STATUS(SCpnt
->host
->io_port
),
1278 STATMASK
, INIT
|IDLE
, STST
|DIAGF
|INVDCMD
|DF
|CDF
);
1281 * Now try to pick up the pieces. For all pending commands,
1282 * free any internal data structures, and basically clear things
1283 * out. We do not try and restart any commands or anything -
1284 * the strategy handler takes care of that crap.
1286 printk("Sent BUS RESET to scsi host %d\n", SCpnt
->host
->host_no
);
1288 for(i
=0; i
< AHA1542_MAILBOXES
; i
++)
1290 if(HOSTDATA(SCpnt
->host
)->SCint
[i
] != NULL
)
1293 SCtmp
= HOSTDATA(SCpnt
->host
)->SCint
[i
];
1296 if( SCtmp
->device
->soft_reset
)
1299 * If this device implements the soft reset option,
1300 * then it is still holding onto the command, and
1301 * may yet complete it. In this case, we don't
1307 if (SCtmp
->host_scribble
)
1309 scsi_free(SCtmp
->host_scribble
, 512);
1312 HOSTDATA(SCpnt
->host
)->SCint
[i
] = NULL
;
1313 HOSTDATA(SCpnt
->host
)->mb
[i
].status
= 0;
1323 int aha1542_host_reset(Scsi_Cmnd
* SCpnt
)
1328 * This does a scsi reset for all devices on the bus.
1329 * In principle, we could also reset the 1542 - should
1330 * we do this? Try this first, and we can add that later
1331 * if it turns out to be useful.
1333 outb(HRST
| SCRST
, CONTROL(SCpnt
->host
->io_port
));
1336 * Wait for the thing to settle down a bit. Unfortunately
1337 * this is going to basically lock up the machine while we
1338 * wait for this to complete. To be 100% correct, we need to
1339 * check for timeout, and if we are doing something like this
1340 * we are pretty desperate anyways.
1344 WAIT(STATUS(SCpnt
->host
->io_port
),
1345 STATMASK
, INIT
|IDLE
, STST
|DIAGF
|INVDCMD
|DF
|CDF
);
1348 * We need to do this too before the 1542 can interact with
1351 setup_mailboxes(SCpnt
->host
->io_port
, SCpnt
->host
);
1354 * Now try to pick up the pieces. For all pending commands,
1355 * free any internal data structures, and basically clear things
1356 * out. We do not try and restart any commands or anything -
1357 * the strategy handler takes care of that crap.
1359 printk("Sent BUS RESET to scsi host %d\n", SCpnt
->host
->host_no
);
1361 for(i
=0; i
< AHA1542_MAILBOXES
; i
++)
1363 if(HOSTDATA(SCpnt
->host
)->SCint
[i
] != NULL
)
1366 SCtmp
= HOSTDATA(SCpnt
->host
)->SCint
[i
];
1368 if( SCtmp
->device
->soft_reset
)
1371 * If this device implements the soft reset option,
1372 * then it is still holding onto the command, and
1373 * may yet complete it. In this case, we don't
1379 if (SCtmp
->host_scribble
)
1381 scsi_free(SCtmp
->host_scribble
, 512);
1384 HOSTDATA(SCpnt
->host
)->SCint
[i
] = NULL
;
1385 HOSTDATA(SCpnt
->host
)->mb
[i
].status
= 0;
1396 * These are the old error handling routines. They are only temporarily
1397 * here while we play with the new error handling code.
1399 int aha1542_old_abort(Scsi_Cmnd
* SCpnt
)
1402 unchar ahacmd
= CMD_START_SCSI
;
1403 unsigned long flags
;
1404 struct mailbox
* mb
;
1407 printk("In aha1542_abort: %x %x\n",
1408 inb(STATUS(SCpnt
->host
->io_port
)),
1409 inb(INTRFLAGS(SCpnt
->host
->io_port
)));
1413 mb
= HOSTDATA(SCpnt
->host
)->mb
;
1414 mbi
= HOSTDATA(SCpnt
->host
)->aha1542_last_mbi_used
+ 1;
1415 if (mbi
>= 2*AHA1542_MAILBOXES
) mbi
= AHA1542_MAILBOXES
;
1418 if(mb
[mbi
].status
!= 0) break;
1420 if (mbi
>= 2*AHA1542_MAILBOXES
) mbi
= AHA1542_MAILBOXES
;
1421 } while (mbi
!= HOSTDATA(SCpnt
->host
)->aha1542_last_mbi_used
);
1422 restore_flags(flags
);
1424 if(mb
[mbi
].status
) {
1425 printk("Lost interrupt discovered on irq %d - attempting to recover\n",
1427 aha1542_intr_handle(SCpnt
->host
->irq
, NULL
);
1431 /* OK, no lost interrupt. Try looking to see how many pending commands
1432 we think we have. */
1434 for(i
=0; i
< AHA1542_MAILBOXES
; i
++)
1435 if(HOSTDATA(SCpnt
->host
)->SCint
[i
])
1437 if(HOSTDATA(SCpnt
->host
)->SCint
[i
] == SCpnt
) {
1438 printk("Timed out command pending for %s\n",
1439 kdevname(SCpnt
->request
.rq_dev
));
1440 if (HOSTDATA(SCpnt
->host
)->mb
[i
].status
) {
1441 printk("OGMB still full - restarting\n");
1442 aha1542_out(SCpnt
->host
->io_port
, &ahacmd
, 1);
1445 printk("Other pending command %s\n",
1446 kdevname(SCpnt
->request
.rq_dev
));
1451 DEB(printk("aha1542_abort\n"));
1455 for(mbo
= 0; mbo
< AHA1542_MAILBOXES
; mbo
++)
1456 if (SCpnt
== HOSTDATA(SCpnt
->host
)->SCint
[mbo
]){
1457 mb
[mbo
].status
= 2; /* Abort command */
1458 aha1542_out(SCpnt
->host
->io_port
, &ahacmd
, 1); /* start scsi command */
1459 restore_flags(flags
);
1463 return SCSI_ABORT_SNOOZE
;
1466 /* We do not implement a reset function here, but the upper level code
1467 assumes that it will get some kind of response for the command in
1468 SCpnt. We must oblige, or the command will hang the scsi system.
1469 For a first go, we assume that the 1542 notifies us with all of the
1470 pending commands (it does implement soft reset, after all). */
1472 int aha1542_old_reset(Scsi_Cmnd
* SCpnt
, unsigned int reset_flags
)
1474 unchar ahacmd
= CMD_START_SCSI
;
1478 * See if a bus reset was suggested.
1480 if( reset_flags
& SCSI_RESET_SUGGEST_BUS_RESET
)
1483 * This does a scsi reset for all devices on the bus.
1484 * In principle, we could also reset the 1542 - should
1485 * we do this? Try this first, and we can add that later
1486 * if it turns out to be useful.
1488 outb(HRST
| SCRST
, CONTROL(SCpnt
->host
->io_port
));
1491 * Wait for the thing to settle down a bit. Unfortunately
1492 * this is going to basically lock up the machine while we
1493 * wait for this to complete. To be 100% correct, we need to
1494 * check for timeout, and if we are doing something like this
1495 * we are pretty desperate anyways.
1497 WAIT(STATUS(SCpnt
->host
->io_port
),
1498 STATMASK
, INIT
|IDLE
, STST
|DIAGF
|INVDCMD
|DF
|CDF
);
1501 * We need to do this too before the 1542 can interact with
1504 setup_mailboxes(SCpnt
->host
->io_port
, SCpnt
->host
);
1507 * Now try to pick up the pieces. Restart all commands
1508 * that are currently active on the bus, and reset all of
1509 * the datastructures. We have some time to kill while
1510 * things settle down, so print a nice message.
1512 printk("Sent BUS RESET to scsi host %d\n", SCpnt
->host
->host_no
);
1514 for(i
=0; i
< AHA1542_MAILBOXES
; i
++)
1515 if(HOSTDATA(SCpnt
->host
)->SCint
[i
] != NULL
)
1518 SCtmp
= HOSTDATA(SCpnt
->host
)->SCint
[i
];
1519 SCtmp
->result
= DID_RESET
<< 16;
1520 if (SCtmp
->host_scribble
) scsi_free(SCtmp
->host_scribble
, 512);
1521 printk("Sending DID_RESET for target %d\n", SCpnt
->target
);
1522 SCtmp
->scsi_done(SCpnt
);
1524 HOSTDATA(SCpnt
->host
)->SCint
[i
] = NULL
;
1525 HOSTDATA(SCpnt
->host
)->mb
[i
].status
= 0;
1528 * Now tell the mid-level code what we did here. Since
1529 * we have restarted all of the outstanding commands,
1530 * then report SUCCESS.
1532 return (SCSI_RESET_SUCCESS
| SCSI_RESET_BUS_RESET
);
1534 printk("aha1542.c: Unable to perform hard reset.\n");
1535 printk("Power cycle machine to reset\n");
1536 return (SCSI_RESET_ERROR
| SCSI_RESET_BUS_RESET
);
1542 /* This does a selective reset of just the one device */
1543 /* First locate the ccb for this command */
1544 for(i
=0; i
< AHA1542_MAILBOXES
; i
++)
1545 if(HOSTDATA(SCpnt
->host
)->SCint
[i
] == SCpnt
)
1547 HOSTDATA(SCpnt
->host
)->ccb
[i
].op
= 0x81; /* BUS DEVICE RESET */
1548 /* Now tell the 1542 to flush all pending commands for this target */
1549 aha1542_out(SCpnt
->host
->io_port
, &ahacmd
, 1);
1551 /* Here is the tricky part. What to do next. Do we get an interrupt
1552 for the commands that we aborted with the specified target, or
1553 do we generate this on our own? Try it without first and see
1555 printk("Sent BUS DEVICE RESET to target %d\n", SCpnt
->target
);
1557 /* If the first does not work, then try the second. I think the
1558 first option is more likely to be correct. Free the command
1559 block for all commands running on this target... */
1560 for(i
=0; i
< AHA1542_MAILBOXES
; i
++)
1561 if(HOSTDATA(SCpnt
->host
)->SCint
[i
] &&
1562 HOSTDATA(SCpnt
->host
)->SCint
[i
]->target
== SCpnt
->target
)
1565 SCtmp
= HOSTDATA(SCpnt
->host
)->SCint
[i
];
1566 SCtmp
->result
= DID_RESET
<< 16;
1567 if (SCtmp
->host_scribble
) scsi_free(SCtmp
->host_scribble
, 512);
1568 printk("Sending DID_RESET for target %d\n", SCpnt
->target
);
1569 SCtmp
->scsi_done(SCpnt
);
1571 HOSTDATA(SCpnt
->host
)->SCint
[i
] = NULL
;
1572 HOSTDATA(SCpnt
->host
)->mb
[i
].status
= 0;
1574 return SCSI_RESET_SUCCESS
;
1577 /* No active command at this time, so this means that each time we got
1578 some kind of response the last time through. Tell the mid-level code
1579 to request sense information in order to decide what to do next. */
1580 return SCSI_RESET_PUNT
;
1585 int aha1542_biosparam(Scsi_Disk
* disk
, kdev_t dev
, int * ip
)
1587 int translation_algorithm
;
1588 int size
= disk
->capacity
;
1590 translation_algorithm
= HOSTDATA(disk
->device
->host
)->bios_translation
;
1592 if((size
>>11) > 1024 && translation_algorithm
== BIOS_TRANSLATION_25563
) {
1593 /* Please verify that this is the same as what DOS returns */
1596 ip
[2] = size
/255/63;
1608 /* Eventually this will go into an include file, but this will be later */
1609 Scsi_Host_Template driver_template
= AHA1542
;
1611 #include "scsi_module.c"