42 #include <linux/module.h>
43 #include <linux/kernel.h>
44 #include <linux/types.h>
45 #include <linux/string.h>
48 #include <linux/stat.h>
50 #include <linux/device.h>
86 #define HOSTDATA(host) ((struct aha1740_hostdata *) &host->hostdata)
96 return (
struct ecb *)(((
char *) hdata->
ecb) + (
unsigned int) offset);
104 offset = (
char *) cpu - (
char *) hdata->
ecb;
121 len =
sprintf(buffer,
"aha174x at IO:%lx, IRQ %d, SLOT %d.\n"
122 "Extended translation %sabled.\n",
160 printk(
"makecode from %x,%x,%x,%x %x,%x,%x,%x",
161 status[0], status[1], status[2], status[3],
162 sense[0], sense[1], sense[2], sense[3]);
168 switch ( status[2] ) {
201 printk(
"aha1740.c: WARNING: AHA1740 queue overflow!\n");
203 if ( status[0]&0x60 ) {
213 return status[3] | retval << 16;
216 static int aha1740_test_port(
unsigned int base)
221 printk(
"aha174x: Board detected, but not in enhanced mode, so disabled it.\n");
230 int errstatus, adapstat;
241 panic(
"aha1740.c: Irq from unknown host!\n");
249 DEB(
printk(
"aha1740_intr top of loop.\n"));
251 ecbptr = ecb_dma_to_cpu (host,
inl(
MBOXIN0(base)));
261 printk(
"Aha1740 null ecbptr in interrupt (%x,%x,%x,%d)\n",
266 SCtmp = ecbptr->
SCpnt;
268 printk(
"Aha1740 null SCtmp in interrupt (%x,%x,%x,%d)\n",
290 errstatus = aha1740_makecode(ecbptr->
sense,ecbptr->
status);
294 printk(
"aha1740_intr_handle: returning %6x\n",
296 SCtmp->
result = errstatus;
297 my_done = ecbptr->
done;
308 printk(
"aha1740 asynchronous event: %02x %02x %02x %02x %02x\n",
329 spin_unlock_irqrestore(host->
host_lock, flags);
358 printk(
"aha1740_queuecommand: dev %d cmd %02x pos %d len %d ",
371 if (!host->
ecb[ecbno].cmdw)
378 if (host->
ecb[ecbno].cmdw)
379 panic(
"Unable to find empty ecb for aha1740.\n");
385 spin_unlock_irqrestore(SCpnt->
device->host->host_lock, flags);
388 printk(
"Sending command (%d %x)...", ecbno,
done);
421 host->
ecb[ecbno].sg = 1;
429 host->
ecb[ecbno].dataptr = sg_dma;
432 ptr = (
unsigned char *) cptr;
433 for(i=0;i<24;i++)
printk(
"%02x ",
ptr[i]);
436 host->
ecb[ecbno].datalen = 0;
437 host->
ecb[ecbno].dataptr = 0;
439 host->
ecb[ecbno].lun = SCpnt->
device->lun;
440 host->
ecb[ecbno].ses = 1;
442 host->
ecb[ecbno].ars = 1;
443 host->
ecb[ecbno].senselen = 12;
444 host->
ecb[ecbno].senseptr = ecb_cpu_to_dma (SCpnt->
device->host,
445 host->
ecb[ecbno].sense);
446 host->
ecb[ecbno].statusptr = ecb_cpu_to_dma (SCpnt->
device->host,
447 host->
ecb[ecbno].status);
449 host->
ecb[ecbno].SCpnt = SCpnt;
453 printk(
"aha1740_command: sending.. ");
454 for (i = 0; i <
sizeof(host->
ecb[ecbno]) - 10; i++)
472 #define LOOPCNT_WARN 10
473 #define LOOPCNT_MAX 1000000
475 unsigned int base = SCpnt->
device->host->io_port;
476 DEB(
printk(
"aha1740[%d] critical section\n",ecbno));
479 for (loopcnt = 0; ; loopcnt++) {
481 if (loopcnt == LOOPCNT_WARN) {
482 printk(
"aha1740[%d]_mbxout wait!\n",ecbno);
484 if (loopcnt == LOOPCNT_MAX)
485 panic(
"aha1740.c: mbxout busy!\n");
487 outl (ecb_cpu_to_dma (SCpnt->
device->host, host->
ecb + ecbno),
489 for (loopcnt = 0; ; loopcnt++) {
491 if (loopcnt == LOOPCNT_WARN) {
492 printk(
"aha1740[%d]_attn wait!\n",ecbno);
494 if (loopcnt == LOOPCNT_MAX)
495 panic(
"aha1740.c: attn wait failed!\n");
498 spin_unlock_irqrestore(SCpnt->
device->host->host_lock, flags);
499 DEB(
printk(
"aha1740[%d] request queued.\n",ecbno));
510 static
void aha1740_getconfig(
unsigned int base,
unsigned int *irq_level,
511 unsigned int *irq_type,
514 static int intab[] = { 9, 10, 11, 12, 0, 14, 15, 0 };
516 *irq_level = intab[
inb(
INTDEF(base)) & 0x7];
517 *irq_type = (
inb(
INTDEF(base)) & 0x8) >> 3;
518 *translation =
inb(
RESV1(base)) & 0x1;
522 static int aha1740_biosparam(
struct scsi_device *sdev,
530 if (extended && (ip[2] > 1024)) {
533 ip[2] = size / (255 * 63);
558 .proc_name =
"aha1740",
559 .proc_info = aha1740_proc_info,
560 .name =
"Adaptec 174x (EISA)",
561 .queuecommand = aha1740_queuecommand,
562 .bios_param = aha1740_biosparam,
568 .eh_abort_handler = aha1740_eh_abort_handler,
571 static int aha1740_probe (
struct device *dev)
584 if (!aha1740_test_port(slotbase))
585 goto err_release_region;
586 aha1740_getconfig(slotbase,&irq_level,&irq_type,&translation);
588 (G2STAT_MBXOUT|G2STAT_BUSY)) != G2STAT_MBXOUT) {
594 edev->
slot, slotbase, irq_level, irq_type ?
"edge" :
"level");
596 translation ?
"en" :
"dis");
600 goto err_release_region;
605 shpnt->
irq = irq_level;
619 DEB(
printk(
"aha1740_probe: enable interrupt channel %d\n",irq_level));
627 eisa_set_drvdata (edev, shpnt);
629 rc = scsi_add_host (shpnt, dev);
676 .id_table = aha1740_ids,
679 .probe = aha1740_probe,
684 static __init int aha1740_init (
void)
689 static __exit void aha1740_exit (
void)