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
6 * Modified by Eric Youngdale
7 * Use request_irq and request_dma to help prevent unexpected conflicts
8 * Set up on-board DMA controller, such that we do not have to
9 * have the bios enabled to use the aha1542.
10 * Modified by David Gentzel
11 * Don't call request_dma if dma mask is 0 (for BusLogic BT-445S VL-Bus controller).
14 #include <linux/kernel.h>
15 #include <linux/head.h>
16 #include <linux/types.h>
17 #include <linux/string.h>
18 #include <linux/ioport.h>
19 #include <linux/config.h>
21 #include <linux/sched.h>
24 #include <asm/system.h>
26 #include "../block/blk.h"
38 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 $";
41 /* The adaptec can be configured for quite a number of addresses, but
42 I generally do not want the card poking around at random. We allow
43 two addresses - this allows people to use the Adaptec with a Midi
44 card, which also used 0x330 */
46 static unsigned int bases
[]={0x330, 0x334};
48 /* The DMA-Controller. We need to fool with this because we want to
49 be able to use the aha1542 without having to have the bios enabled */
50 #define DMA_MODE_REG 0xd6
51 #define DMA_MASK_REG 0xd4
54 #define BIOS_TRANSLATION_1632 0 /* Used by some old 1542A boards */
55 #define BIOS_TRANSLATION_6432 1 /* Default case these days */
56 #define BIOS_TRANSLATION_25563 2 /* Big disk case */
58 struct aha1542_hostdata
{
59 /* This will effectively start both of them at the first mailbox */
60 int bios_translation
; /* Mapping bios uses - for compatibility */
61 int aha1542_last_mbi_used
;
62 int aha1542_last_mbo_used
;
63 Scsi_Cmnd
* SCint
[AHA1542_MAILBOXES
];
64 struct mailbox mb
[2*AHA1542_MAILBOXES
];
65 struct ccb ccb
[AHA1542_MAILBOXES
];
68 #define HOSTDATA(host) ((struct aha1542_hostdata *) &host->hostdata)
70 static struct Scsi_Host
* aha_host
[7] = {NULL
,}; /* One for each IRQ level (9-15) */
75 #define WAITnexttimeout 3000000
77 static void setup_mailboxes(int base_io
, struct Scsi_Host
* shpnt
);
79 #define aha1542_intr_reset(base) outb(IRST, CONTROL(base))
81 #define WAIT(port, mask, allof, noneof) \
82 { register WAITbits; \
83 register WAITtimeout = WAITnexttimeout; \
85 WAITbits = inb(port) & (mask); \
86 if ((WAITbits & (allof)) == (allof) && ((WAITbits & (noneof)) == 0)) \
88 if (--WAITtimeout == 0) goto fail; \
92 static void aha1542_stat(void)
94 /* int s = inb(STATUS), i = inb(INTRFLAGS);
95 printk("status=%x intrflags=%x\n", s, i, WAITnexttimeout-WAITtimeout); */
98 static int aha1542_out(unsigned int base
, unchar
*cmdp
, int len
)
102 WAIT(STATUS(base
), CDF
, 0, CDF
);
103 outb(*cmdp
++, DATA(base
));
107 printk("aha1542_out failed(%d): ", len
+1); aha1542_stat();
111 static int aha1542_in(unsigned int base
, unchar
*cmdp
, int len
)
115 WAIT(STATUS(base
), DF
, DF
, 0);
116 *cmdp
++ = inb(DATA(base
));
120 printk("aha1542_in failed(%d): ", len
+1); aha1542_stat();
124 static int makecode(unsigned hosterr
, unsigned scsierr
)
128 case 0xa: /* Linked command complete without error and linked normally */
129 case 0xb: /* Linked command complete without error, interrupt generated */
133 case 0x11: /* Selection time out-The initiator selection or target
134 reselection was not complete within the SCSI Time out period */
135 hosterr
= DID_TIME_OUT
;
138 case 0x12: /* Data overrun/underrun-The target attempted to transfer more data
139 thean was allocated by the Data Length field or the sum of the
140 Scatter / Gather Data Length fields. */
142 case 0x13: /* Unexpected bus free-The target dropped the SCSI BSY at an unexpected time. */
144 case 0x15: /* MBO command was not 00, 01 or 02-The first byte of the CB was
145 invalid. This usually indicates a software failure. */
147 case 0x16: /* Invalid CCB Operation Code-The first byte of the CCB was invalid.
148 This usually indicates a software failure. */
150 case 0x17: /* Linked CCB does not have the same LUN-A subsequent CCB of a set
151 of linked CCB's does not specify the same logical unit number as
153 case 0x18: /* Invalid Target Direction received from Host-The direction of a
154 Target Mode CCB was invalid. */
156 case 0x19: /* Duplicate CCB Received in Target Mode-More than once CCB was
157 received to service data transfer between the same target LUN
158 and initiator SCSI ID in the same direction. */
160 case 0x1a: /* Invalid CCB or Segment List Parameter-A segment list with a zero
161 length segment or invalid segment list boundaries was received.
162 A CCB parameter was invalid. */
163 DEB(printk("Aha1542: %x %x\n", hosterr
, scsierr
));
164 hosterr
= DID_ERROR
; /* Couldn't find any better */
167 case 0x14: /* Target bus phase sequence failure-An invalid bus phase or bus
168 phase sequence was requested by the target. The host adapter
169 will generate a SCSI Reset Condition, notifying the host with
174 printk("makecode: unknown hoststatus %x\n", hosterr
);
177 return scsierr
|(hosterr
<< 16);
180 static int aha1542_test_port(int bse
, struct Scsi_Host
* shpnt
)
183 unchar inquiry_cmd
[] = {CMD_INQUIRY
};
184 unchar inquiry_result
[4];
187 volatile int debug
= 0;
189 /* Quick and dirty test for presence of the card. */
190 if(inb(STATUS(bse
)) == 0xff) return 0;
192 /* Reset the adapter. I ought to make a hard reset, but it's not really nessesary */
194 /* DEB(printk("aha1542_test_port called \n")); */
196 outb(SRST
|IRST
/*|SCRST*/, CONTROL(bse
));
199 while (i
>jiffies
); /* Wait a little bit for things to settle down. */
202 /* Expect INIT and IDLE, any of the others are bad */
203 WAIT(STATUS(bse
), STATMASK
, INIT
|IDLE
, STST
|DIAGF
|INVDCMD
|DF
|CDF
);
206 /* Shouldn't have generated any interrupts during reset */
207 if (inb(INTRFLAGS(bse
))&INTRMASK
) goto fail
;
210 /* Perform a host adapter inquiry instead so we do not need to set
211 up the mailboxes ahead of time */
213 aha1542_out(bse
, inquiry_cmd
, 1);
217 cmdp
= &inquiry_result
[0];
221 WAIT(STATUS(bse
), DF
, DF
, 0);
222 *cmdp
++ = inb(DATA(bse
));
226 /* Reading port should reset DF */
227 if (inb(STATUS(bse
)) & DF
) goto fail
;
230 /* When HACC, command is completed, and we're though testing */
231 WAIT(INTRFLAGS(bse
), HACC
, HACC
, 0);
232 /* now initialize adapter */
235 /* Clear interrupts */
236 outb(IRST
, CONTROL(bse
));
240 return debug
; /* 1 = ok */
242 return 0; /* 0 = not ok */
245 static const char aha_ident
[] = "Adaptec 1542";
247 /* What's this little function for? */
248 const char *aha1542_info(void)
253 /* A "high" level interrupt handler */
254 static void aha1542_intr_handle(int foo
)
256 void (*my_done
)(Scsi_Cmnd
*) = NULL
;
257 int errstatus
, mbi
, mbo
, mbistatus
;
259 struct Scsi_Host
* shost
;
266 irqp
-= 2; /* Magic - this is only required for slow interrupt handlers */
269 shost
= aha_host
[irqno
- 9];
270 mb
= HOSTDATA(shost
)->mb
;
271 ccb
= HOSTDATA(shost
)->ccb
;
273 if(!shost
) panic("Splunge!");
277 int flag
= inb(INTRFLAGS(shost
->io_port
));
278 printk("aha1542_intr_handle: ");
279 if (!(flag
&ANYINTR
)) printk("no interrupt?");
280 if (flag
&MBIF
) printk("MBIF ");
281 if (flag
&MBOA
) printk("MBOF ");
282 if (flag
&HACC
) printk("HACC ");
283 if (flag
&SCRD
) printk("SCRD ");
284 printk("status %02x\n", inb(STATUS(shost
->io_port
)));
290 aha1542_intr_reset(shost
->io_port
);
293 mbi
= HOSTDATA(shost
)->aha1542_last_mbi_used
+ 1;
294 if (mbi
>= 2*AHA1542_MAILBOXES
) mbi
= AHA1542_MAILBOXES
;
297 if(mb
[mbi
].status
!= 0) break;
299 if (mbi
>= 2*AHA1542_MAILBOXES
) mbi
= AHA1542_MAILBOXES
;
300 } while (mbi
!= HOSTDATA(shost
)->aha1542_last_mbi_used
);
302 if(mb
[mbi
].status
== 0){
304 /* Hmm, no mail. Must have read it the last time around */
305 if (number_serviced
) return;
306 printk("aha1542.c: interrupt received, but no mail.\n");
310 mbo
= (scsi2int(mb
[mbi
].ccbptr
) - ((unsigned int) &ccb
[0])) / sizeof(struct ccb
);
311 mbistatus
= mb
[mbi
].status
;
313 HOSTDATA(shost
)->aha1542_last_mbi_used
= mbi
;
318 if (ccb
[mbo
].tarstat
|ccb
[mbo
].hastat
)
319 printk("aha1542_command: returning %x (status %d)\n",
320 ccb
[mbo
].tarstat
+ ((int) ccb
[mbo
].hastat
<< 16), mb
[mbi
].status
);
324 if(mbistatus
== 3) continue; /* Aborted command not found */
327 printk("...done %d %d\n",mbo
, mbi
);
330 SCtmp
= HOSTDATA(shost
)->SCint
[mbo
];
332 if (!SCtmp
|| !SCtmp
->scsi_done
) {
333 printk("aha1542_intr_handle: Unexpected interrupt\n");
337 my_done
= SCtmp
->scsi_done
;
338 if (SCtmp
->host_scribble
) scsi_free(SCtmp
->host_scribble
, 512);
340 /* Fetch the sense data, and tuck it away, in the required slot. The
341 Adaptec automatically fetches it, and there is no guarantee that
342 we will still have it in the cdb when we come back */
343 if (ccb
[mbo
].tarstat
== 2)
344 memcpy(SCtmp
->sense_buffer
, &ccb
[mbo
].cdb
[ccb
[mbo
].cdblen
],
345 sizeof(SCtmp
->sense_buffer
));
348 /* is there mail :-) */
350 /* more error checking left out here */
352 /* This is surely wrong, but I don't know what's right */
353 errstatus
= makecode(ccb
[mbo
].hastat
, ccb
[mbo
].tarstat
);
358 if(errstatus
) printk("(aha1542 error:%x %x %x) ",errstatus
,
359 ccb
[mbo
].hastat
, ccb
[mbo
].tarstat
);
362 if (ccb
[mbo
].tarstat
== 2) {
366 DEB(printk("aha1542_intr_handle: sense:"));
368 for (i
= 0; i
< 12; i
++)
369 printk("%02x ", ccb
[mbo
].cdb
[ccb
[mbo
].cdblen
+i
]);
373 DEB(printk("aha1542_intr_handle: buf:"));
374 for (i = 0; i < bufflen; i++)
375 printk("%02x ", ((unchar *)buff)[i]);
379 DEB(if (errstatus
) printk("aha1542_intr_handle: returning %6x\n", errstatus
));
380 SCtmp
->result
= errstatus
;
381 HOSTDATA(shost
)->SCint
[mbo
] = NULL
; /* This effectively frees up the mailbox slot, as
382 far as queuecommand is concerned */
388 int aha1542_queuecommand(Scsi_Cmnd
* SCpnt
, void (*done
)(Scsi_Cmnd
*))
390 unchar ahacmd
= CMD_START_SCSI
;
392 unchar
*cmd
= (unchar
*) SCpnt
->cmnd
;
393 unchar target
= SCpnt
->target
;
394 unchar lun
= SCpnt
->lun
;
395 void *buff
= SCpnt
->request_buffer
;
396 int bufflen
= SCpnt
->request_bufflen
;
403 mb
= HOSTDATA(SCpnt
->host
)->mb
;
404 ccb
= HOSTDATA(SCpnt
->host
)->ccb
;
406 DEB(if (target
> 1) {
407 SCpnt
->result
= DID_TIME_OUT
<< 16;
408 done(SCpnt
); return 0;});
410 if(*cmd
== REQUEST_SENSE
){
412 if (bufflen
!= sizeof(SCpnt
->sense_buffer
)) {
413 printk("Wrong buffer length supplied for request sense (%d)\n",bufflen
);
423 if (*cmd
== READ_10
|| *cmd
== WRITE_10
)
424 i
= xscsi2int(cmd
+2);
425 else if (*cmd
== READ_6
|| *cmd
== WRITE_6
)
430 printk("aha1542_queuecommand: dev %d cmd %02x pos %d len %d ", target
, *cmd
, i
, bufflen
);
432 printk("aha1542_command: dev %d cmd %02x pos %d len %d ", target
, *cmd
, i
, bufflen
);
434 printk("aha1542_queuecommand: dumping scsi cmd:");
435 for (i
= 0; i
< (COMMAND_SIZE(*cmd
)); i
++) printk("%02x ", cmd
[i
]);
437 if (*cmd
== WRITE_10
|| *cmd
== WRITE_6
)
438 return 0; /* we are still testing, so *don't* write */
440 /* Use the outgoing mailboxes in a round-robin fashion, because this
441 is how the host adapter will scan for them */
444 mbo
= HOSTDATA(SCpnt
->host
)->aha1542_last_mbo_used
+ 1;
445 if (mbo
>= AHA1542_MAILBOXES
) mbo
= 0;
448 if(mb
[mbo
].status
== 0 && HOSTDATA(SCpnt
->host
)->SCint
[mbo
] == NULL
)
451 if (mbo
>= AHA1542_MAILBOXES
) mbo
= 0;
452 } while (mbo
!= HOSTDATA(SCpnt
->host
)->aha1542_last_mbo_used
);
454 if(mb
[mbo
].status
|| HOSTDATA(SCpnt
->host
)->SCint
[mbo
])
455 panic("Unable to find empty mailbox for aha1542.\n");
457 HOSTDATA(SCpnt
->host
)->SCint
[mbo
] = SCpnt
; /* This will effectively prevent someone else from
458 screwing with this cdb. */
460 HOSTDATA(SCpnt
->host
)->aha1542_last_mbo_used
= mbo
;
464 printk("Sending command (%d %x)...",mbo
, done
);
467 any2scsi(mb
[mbo
].ccbptr
, &ccb
[mbo
]); /* This gets trashed for some reason*/
469 memset(&ccb
[mbo
], 0, sizeof(struct ccb
));
471 ccb
[mbo
].cdblen
= COMMAND_SIZE(*cmd
); /* SCSI Command Descriptor Block Length */
474 if (*cmd
== READ_10
|| *cmd
== READ_6
)
476 else if (*cmd
== WRITE_10
|| *cmd
== WRITE_6
)
479 memcpy(ccb
[mbo
].cdb
, cmd
, ccb
[mbo
].cdblen
);
482 struct scatterlist
* sgpnt
;
488 ccb
[mbo
].op
= 2; /* SCSI Initiator Command w/scatter-gather*/
489 SCpnt
->host_scribble
= (unsigned char *) scsi_malloc(512);
490 sgpnt
= (struct scatterlist
*) SCpnt
->request_buffer
;
491 cptr
= (struct chain
*) SCpnt
->host_scribble
;
492 if (cptr
== NULL
) panic("aha1542.c: unable to allocate DMA memory\n");
493 for(i
=0; i
<SCpnt
->use_sg
; i
++) {
494 if(sgpnt
[i
].length
== 0 || SCpnt
->use_sg
> 16 ||
495 (((int)sgpnt
[i
].address
) & 1) || (sgpnt
[i
].length
& 1)){
497 printk("Bad segment list supplied to aha1542.c (%d, %d)\n",SCpnt
->use_sg
,i
);
498 for(i
=0;i
<SCpnt
->use_sg
;i
++){
499 printk("%d: %x %x %d\n",i
,(unsigned int) sgpnt
[i
].address
, (unsigned int) sgpnt
[i
].alt_address
,
502 printk("cptr %x: ",(unsigned int) cptr
);
503 ptr
= (unsigned char *) &cptr
[i
];
504 for(i
=0;i
<18;i
++) printk("%02x ", ptr
[i
]);
505 panic("Foooooooood fight!");
507 any2scsi(cptr
[i
].dataptr
, sgpnt
[i
].address
);
508 if(((unsigned int) sgpnt
[i
].address
) & 0xff000000) goto baddma
;
509 any2scsi(cptr
[i
].datalen
, sgpnt
[i
].length
);
511 any2scsi(ccb
[mbo
].datalen
, SCpnt
->use_sg
* sizeof(struct chain
));
512 if(((unsigned int) buff
& 0xff000000)) goto baddma
;
513 any2scsi(ccb
[mbo
].dataptr
, cptr
);
515 printk("cptr %x: ",cptr
);
516 ptr
= (unsigned char *) cptr
;
517 for(i
=0;i
<18;i
++) printk("%02x ", ptr
[i
]);
520 ccb
[mbo
].op
= 0; /* SCSI Initiator Command */
521 SCpnt
->host_scribble
= NULL
;
522 any2scsi(ccb
[mbo
].datalen
, bufflen
);
523 any2scsi(ccb
[mbo
].dataptr
, buff
);
525 ccb
[mbo
].idlun
= (target
&7)<<5 | direction
| (lun
& 7); /*SCSI Target Id*/
526 ccb
[mbo
].rsalen
= 12;
527 ccb
[mbo
].linkptr
[0] = ccb
[mbo
].linkptr
[1] = ccb
[mbo
].linkptr
[2] = 0;
528 ccb
[mbo
].commlinkid
= 0;
532 printk("aha1542_command: sending.. ");
533 for (i
= 0; i
< sizeof(ccb
[mbo
])-10; i
++)
534 printk("%02x ", ((unchar
*)&ccb
[mbo
])[i
]);
539 DEB(printk("aha1542_queuecommand: now waiting for interrupt "); aha1542_stat());
540 SCpnt
->scsi_done
= done
;
542 aha1542_out(SCpnt
->host
->io_port
, &ahacmd
, 1); /* start scsi command */
546 printk("aha1542_queuecommand: done can't be NULL\n");
550 panic("Buffer at address > 16Mb used for 1542B");
553 static void internal_done(Scsi_Cmnd
* SCpnt
)
558 int aha1542_command(Scsi_Cmnd
* SCpnt
)
560 DEB(printk("aha1542_command: ..calling aha1542_queuecommand\n"));
562 aha1542_queuecommand(SCpnt
, internal_done
);
564 SCpnt
->SCp
.Status
= 0;
565 while (!SCpnt
->SCp
.Status
);
566 return SCpnt
->result
;
569 /* Initialize mailboxes */
570 static void setup_mailboxes(int bse
, struct Scsi_Host
* shpnt
)
576 unchar cmd
[5] = {CMD_MBINIT
, AHA1542_MAILBOXES
};
578 mb
= HOSTDATA(shpnt
)->mb
;
579 ccb
= HOSTDATA(shpnt
)->ccb
;
581 for(i
=0; i
<AHA1542_MAILBOXES
; i
++){
582 mb
[i
].status
= mb
[AHA1542_MAILBOXES
+i
].status
= 0;
583 any2scsi(mb
[i
].ccbptr
, &ccb
[i
]);
585 aha1542_intr_reset(bse
); /* reset interrupts, so they don't block */
586 any2scsi((cmd
+2), mb
);
587 aha1542_out(bse
, cmd
, 5);
588 WAIT(INTRFLAGS(bse
), INTRMASK
, HACC
, 0);
591 printk("aha1542_detect: failed setting up mailboxes\n");
593 aha1542_intr_reset(bse
);
596 static int aha1542_getconfig(int base_io
, unsigned char * irq_level
, unsigned char * dma_chan
)
598 unchar inquiry_cmd
[] = {CMD_RETCONF
};
599 unchar inquiry_result
[3];
601 i
= inb(STATUS(base_io
));
603 i
= inb(DATA(base_io
));
605 aha1542_out(base_io
, inquiry_cmd
, 1);
606 aha1542_in(base_io
, inquiry_result
, 3);
607 WAIT(INTRFLAGS(base_io
), INTRMASK
, HACC
, 0);
610 printk("aha1542_detect: query board settings\n");
612 aha1542_intr_reset(base_io
);
613 switch(inquiry_result
[0]){
624 printk("DMA priority 0 not available for Adaptec driver\n");
627 /* This means that the adapter, although Adaptec 1542 compatible, doesn't use a DMA channel.
628 Currently only aware of the BusLogic BT-445S VL-Bus adapter which needs this. */
632 printk("Unable to determine Adaptec DMA priority. Disabling board\n");
635 switch(inquiry_result
[1]){
655 printk("Unable to determine Adaptec IRQ level. Disabling board\n");
661 /* This function should only be called for 1542C boards - we can detect
662 the special firmware settings and unlock the board */
664 static int aha1542_mbenable(int base
)
666 static unchar mbenable_cmd
[3];
667 static unchar mbenable_result
[2];
670 retval
= BIOS_TRANSLATION_6432
;
672 mbenable_cmd
[0]=CMD_EXTBIOS
;
673 aha1542_out(base
,mbenable_cmd
,1);
674 aha1542_in(base
,mbenable_result
,2);
675 WAIT(INTRFLAGS(base
),INTRMASK
,HACC
,0);
676 aha1542_intr_reset(base
);
678 if (mbenable_result
[0] & 0x08) {
679 mbenable_cmd
[0]=CMD_MBENABLE
;
681 mbenable_cmd
[2]=mbenable_result
[1];
682 if(mbenable_result
[1] & 1) retval
= BIOS_TRANSLATION_25563
;
683 aha1542_out(base
,mbenable_cmd
,3);
684 WAIT(INTRFLAGS(base
),INTRMASK
,HACC
,0);
688 printk("aha1542_mbenable: Mailbox init failed\n");
690 aha1542_intr_reset(base
);
694 /* Query the board to find out if it is a 1542 or a 1740, or whatever. */
695 static int aha1542_query(int base_io
, int * transl
)
697 unchar inquiry_cmd
[] = {CMD_INQUIRY
};
698 unchar inquiry_result
[4];
700 i
= inb(STATUS(base_io
));
702 i
= inb(DATA(base_io
));
704 aha1542_out(base_io
, inquiry_cmd
, 1);
705 aha1542_in(base_io
, inquiry_result
, 4);
706 WAIT(INTRFLAGS(base_io
), INTRMASK
, HACC
, 0);
709 printk("aha1542_detect: query card type\n");
711 aha1542_intr_reset(base_io
);
713 *transl
= BIOS_TRANSLATION_6432
; /* Default case */
715 /* For an AHA1740 series board, we ignore the board since there is a
716 hardware bug which can lead to wrong blocks being returned if the board
717 is operating in the 1542 emulation mode. Since there is an extended mode
718 driver, we simply ignore the board and let the 1740 driver pick it up.
721 if (inquiry_result
[0] == 0x43) {
722 printk("aha1542.c: Emulation mode not supported for AHA 174N hardware.\n");
726 /* 1542C returns 0x44, 1542CF returns 0x45 */
727 if (inquiry_result
[0] == 0x44 || inquiry_result
[0] == 0x45)
729 *transl
= aha1542_mbenable(base_io
);
735 /* return non-zero on detection */
736 int aha1542_detect(int hostnum
)
738 unsigned char dma_chan
;
739 unsigned char irq_level
;
740 unsigned int base_io
;
742 struct Scsi_Host
* shpnt
= NULL
;
746 DEB(printk("aha1542_detect: \n"));
748 for(indx
= 0; indx
< sizeof(bases
)/sizeof(bases
[0]); indx
++)
749 if(!check_region(bases
[indx
], 4)) {
750 shpnt
= scsi_register(hostnum
,
751 sizeof(struct aha1542_hostdata
));
753 if(!aha1542_test_port(bases
[indx
], shpnt
)) goto unregister
;
756 base_io
= bases
[indx
];
758 /* Set the Bus on/off-times as not to ruin floppy performance */
760 unchar oncmd
[] = {CMD_BUSON_TIME
, 7};
761 unchar offcmd
[] = {CMD_BUSOFF_TIME
, 5};
763 aha1542_intr_reset(base_io
);
764 aha1542_out(base_io
, oncmd
, 2);
765 WAIT(INTRFLAGS(base_io
), INTRMASK
, HACC
, 0);
766 aha1542_intr_reset(base_io
);
767 aha1542_out(base_io
, offcmd
, 2);
768 WAIT(INTRFLAGS(base_io
), INTRMASK
, HACC
, 0);
771 printk("aha1542_detect: setting bus on/off-time failed\n");
773 aha1542_intr_reset(base_io
);
775 if(aha1542_query(base_io
, &trans
)) goto unregister
;
777 if (aha1542_getconfig(base_io
, &irq_level
, &dma_chan
) == -1) goto unregister
;
779 printk("Configuring Adaptec at IO:%x, IRQ %d",base_io
, irq_level
);
780 if (dma_chan
!= 0xFF)
781 printk(", DMA priority %d", dma_chan
);
785 setup_mailboxes(base_io
, shpnt
);
789 DEB(printk("aha1542_detect: enable interrupt channel %d\n", irq_level
));
791 if (request_irq(irq_level
,aha1542_intr_handle
)) {
792 printk("Unable to allocate IRQ for adaptec controller.\n");
796 if (dma_chan
!= 0xFF) {
797 if (request_dma(dma_chan
)) {
798 printk("Unable to allocate DMA channel for Adaptec.\n");
804 outb((dma_chan
- 4) | CASCADE
, DMA_MODE_REG
);
805 outb(dma_chan
- 4, DMA_MASK_REG
);
808 aha_host
[irq_level
- 9] = shpnt
;
809 shpnt
->io_port
= base_io
;
810 shpnt
->dma_channel
= dma_chan
;
811 shpnt
->irq
= irq_level
;
812 HOSTDATA(shpnt
)->bios_translation
= trans
;
814 printk("aha1542.c: Using extended bios translation\n");
815 HOSTDATA(shpnt
)->aha1542_last_mbi_used
= (2*AHA1542_MAILBOXES
- 1);
816 HOSTDATA(shpnt
)->aha1542_last_mbo_used
= (AHA1542_MAILBOXES
- 1);
817 memset(HOSTDATA(shpnt
)->SCint
, 0, sizeof(HOSTDATA(shpnt
)->SCint
));
820 DEB(printk(" *** READ CAPACITY ***\n"));
824 static unchar cmd
[] = { READ_CAPACITY
, 0, 0, 0, 0, 0, 0, 0, 0, 0};
827 for (i
= 0; i
< sizeof(buf
); ++i
) buf
[i
] = 0x87;
828 for (i
= 0; i
< 2; ++i
)
829 if (!aha1542_command(i
, cmd
, buf
, sizeof(buf
))) {
830 printk("aha_detect: LU %d sector_size %d device_size %d\n",
831 i
, xscsi2int(buf
+4), xscsi2int(buf
));
835 DEB(printk(" *** NOW RUNNING MY OWN TEST *** \n"));
837 for (i
= 0; i
< 4; ++i
)
839 unsigned char cmd
[10];
849 aha1542_command(0, cmd
, buffer
, 512);
852 snarf_region(bases
[indx
], 4); /* Register the IO ports that we use */
856 scsi_unregister(shpnt
, sizeof(struct aha1542_hostdata
));
863 /* The abort command does not leave the device in a clean state where
864 it is available to be used again. Until this gets worked out, we will
865 leave it commented out. */
867 int aha1542_abort(Scsi_Cmnd
* SCpnt
, int i
)
870 unchar ahacmd
= CMD_START_SCSI
;
873 DEB(printk("aha1542_abort\n"));
876 for(mbo
= 0; mbo
< AHA1542_MAILBOXES
; mbo
++)
877 if (SCpnt
== HOSTDATA(SCpnt
->host
)->SCint
[mbo
]){
878 mb
[mbo
].status
= 2; /* Abort command */
879 aha1542_out(&ahacmd
, 1); /* start scsi command */
887 /* We do not implement a reset function here, but the upper level code assumes
888 that it will get some kind of response for the command in SCpnt. We must
889 oblige, or the command will hang the scsi system */
891 int aha1542_reset(Scsi_Cmnd
* SCpnt
)
893 DEB(printk("aha1542_reset called\n"));
894 if(SCpnt
) SCpnt
->flags
|= NEEDS_JUMPSTART
;
898 #ifdef CONFIG_BLK_DEV_SD
902 int aha1542_biosparam(int size
, int dev
, int * ip
)
904 int translation_algorithm
;
905 #ifdef CONFIG_BLK_DEV_SD
908 disk
= rscsi_disks
[MINOR(dev
) >> 4].device
;
909 translation_algorithm
= HOSTDATA(disk
->host
)->bios_translation
;
910 /* Should this be > 1024, or >= 1024? Enquiring minds want to know. */
911 if((size
>>11) > 1024 && translation_algorithm
== 2) {
912 /* Please verify that this is the same as what DOS returns */
915 ip
[2] = size
/255/63;
921 /* if (ip[2] >= 1024) ip[2] = 1024; */