1 /************************************************************
3 * Linux EATA SCSI PIO driver *
5 * based on the CAM document CAM/89-004 rev. 2.0c, *
6 * DPT's driver kit, some internal documents and source, *
7 * and several other Linux scsi drivers and kernel docs. *
9 * The driver currently: *
10 * -supports all EATA-PIO boards *
11 * -only supports DASD devices *
13 * (c)1993-96 Michael Neuffer, Alfred Arnold *
14 * neuffer@goofy.zdv.uni-mainz.de *
15 * a.arnold@kfa-juelich.de *
17 * Updated 2002 by Alan Cox <alan@redhat.com> for Linux *
18 * 2.5.x and the newer locking and error handling *
20 * This program is free software; you can redistribute it *
21 * and/or modify it under the terms of the GNU General *
22 * Public License as published by the Free Software *
23 * Foundation; either version 2 of the License, or *
24 * (at your option) any later version. *
26 * This program is distributed in the hope that it will be *
27 * useful, but WITHOUT ANY WARRANTY; without even the *
28 * implied warranty of MERCHANTABILITY or FITNESS FOR A *
29 * PARTICULAR PURPOSE. See the GNU General Public License *
32 * You should have received a copy of the GNU General *
33 * Public License along with this kernel; if not, write to *
34 * the Free Software Foundation, Inc., 675 Mass Ave, *
35 * Cambridge, MA 02139, USA. *
37 * For the avoidance of doubt the "preferred form" of this *
38 * code is one which is in an open non patent encumbered *
39 * format. Where cryptographic key signing forms part of *
40 * the process of creating an executable the information *
41 * including keys needed to generate an equivalently *
42 * functional executable are deemed to be part of the *
43 * source code are deemed to be part of the source code. *
45 ************************************************************
46 * last change: 2002/11/02 OS: Linux 2.5.45 *
47 ************************************************************/
49 #include <linux/config.h>
50 #include <linux/module.h>
51 #include <linux/kernel.h>
52 #include <linux/sched.h>
53 #include <linux/string.h>
54 #include <linux/ioport.h>
55 #include <linux/slab.h>
57 #include <linux/pci.h>
58 #include <linux/proc_fs.h>
59 #include <linux/interrupt.h>
60 #include <linux/blkdev.h>
61 #include <linux/spinlock.h>
62 #include <linux/delay.h>
66 #include <scsi/scsi.h>
67 #include <scsi/scsi_cmnd.h>
68 #include <scsi/scsi_device.h>
69 #include <scsi/scsi_host.h>
71 #include "eata_generic.h"
75 static uint ISAbases[MAXISA] = {
76 0x1F0, 0x170, 0x330, 0x230
79 static uint ISAirqs[MAXISA] = {
83 static unsigned char EISAbases[] = {
84 1, 1, 1, 1, 1, 1, 1, 1,
85 1, 1, 1, 1, 1, 1, 1, 1
88 static uint registered_HBAs;
89 static struct Scsi_Host *last_HBA;
90 static struct Scsi_Host *first_HBA;
91 static unsigned char reg_IRQ[16];
92 static unsigned char reg_IRQL[16];
93 static unsigned long int_counter;
94 static unsigned long queue_counter;
96 static struct scsi_host_template driver_template;
100 * inout : decides on the direction of the dataflow and the meaning of the
102 * buffer: If inout==FALSE data is being written to it else read from it
103 * *start: If inout==FALSE start of the valid data in the buffer
104 * offset: If inout==FALSE offset from the beginning of the imaginary file
105 * from which we start writing into the buffer
106 * length: If inout==FALSE max number of bytes to be written into the buffer
107 * else number of bytes in the buffer
109 static int eata_pio_proc_info(struct Scsi_Host *shost, char *buffer, char **start, off_t offset,
114 off_t begin = 0, pos = 0;
119 memset(buff, 0, sizeof(buff));
121 size = sprintf(buffer+len, "EATA (Extended Attachment) PIO driver version: "
122 "%d.%d%s\n",VER_MAJOR, VER_MINOR, VER_SUB);
123 len += size; pos = begin + len;
124 size = sprintf(buffer + len, "queued commands: %10ld\n"
125 "processed interrupts:%10ld\n", queue_counter, int_counter);
126 len += size; pos = begin + len;
128 size = sprintf(buffer + len, "\nscsi%-2d: HBA %.10s\n",
129 shost->host_no, SD(shost)->name);
132 size = sprintf(buffer + len, "Firmware revision: v%s\n",
133 SD(shost)->revision);
136 size = sprintf(buffer + len, "IO: PIO\n");
139 size = sprintf(buffer + len, "Base IO : %#.4x\n", (u32) shost->base);
142 size = sprintf(buffer + len, "Host Bus: %s\n",
143 (SD(shost)->bustype == 'P')?"PCI ":
144 (SD(shost)->bustype == 'E')?"EISA":"ISA ");
153 if (pos > offset + length)
157 DBG(DBG_PROC, printk("2pos: %ld offset: %ld len: %d\n", pos, offset, len));
158 *start=buffer+(offset-begin); /* Start of wanted data */
159 len-=(offset-begin); /* Start slop */
161 len = length; /* Ending slop */
162 DBG(DBG_PROC, printk("3pos: %ld offset: %ld len: %d\n", pos, offset, len));
167 static int eata_pio_release(struct Scsi_Host *sh)
169 if (sh->irq && reg_IRQ[sh->irq] == 1)
170 free_irq(sh->irq, NULL);
173 if (SD(sh)->channel == 0) {
174 if (sh->io_port && sh->n_io_port)
175 release_region(sh->io_port, sh->n_io_port);
180 static void IncStat(struct scsi_pointer *SCp, uint Increment)
182 SCp->ptr += Increment;
183 if ((SCp->this_residual -= Increment) == 0) {
184 if ((--SCp->buffers_residual) == 0)
188 SCp->ptr = page_address(SCp->buffer->page) + SCp->buffer->offset;
189 SCp->this_residual = SCp->buffer->length;
194 static void eata_pio_int_handler(int irq, void *dev_id, struct pt_regs *regs);
196 static irqreturn_t do_eata_pio_int_handler(int irq, void *dev_id,
197 struct pt_regs *regs)
200 struct Scsi_Host *dev = dev_id;
202 spin_lock_irqsave(dev->host_lock, flags);
203 eata_pio_int_handler(irq, dev_id, regs);
204 spin_unlock_irqrestore(dev->host_lock, flags);
208 static void eata_pio_int_handler(int irq, void *dev_id, struct pt_regs *regs)
210 uint eata_stat = 0xfffff;
211 struct scsi_cmnd *cmd;
216 struct Scsi_Host *sh;
217 unsigned short zwickel = 0;
218 unsigned char stat, odd;
220 for (x = 1, sh = first_HBA; x <= registered_HBAs; x++, sh = SD(sh)->prev)
224 if (inb((uint) sh->base + HA_RSTATUS) & HA_SBUSY)
233 base = (uint) cmd->device->host->base;
236 stat = inb(base + HA_RSTATUS);
237 if (stat & HA_SDRQ) {
241 while ((cmd->SCp.Status) && ((z > 0) || (odd))) {
243 *(cmd->SCp.ptr) = zwickel >> 8;
244 IncStat(&cmd->SCp, 1);
247 x = min_t(unsigned int, z, cmd->SCp.this_residual / 2);
248 insw(base + HA_RDATA, cmd->SCp.ptr, x);
250 IncStat(&cmd->SCp, 2 * x);
251 if ((z > 0) && (cmd->SCp.this_residual == 1)) {
252 zwickel = inw(base + HA_RDATA);
253 *(cmd->SCp.ptr) = zwickel & 0xff;
254 IncStat(&cmd->SCp, 1);
260 zwickel = inw(base + HA_RDATA);
263 } else { /* cp->DataOut */
267 while ((cmd->SCp.Status) && ((z > 0) || (odd))) {
269 zwickel += *(cmd->SCp.ptr) << 8;
270 IncStat(&cmd->SCp, 1);
271 outw(zwickel, base + HA_RDATA);
275 x = min_t(unsigned int, z, cmd->SCp.this_residual / 2);
276 outsw(base + HA_RDATA, cmd->SCp.ptr, x);
278 IncStat(&cmd->SCp, 2 * x);
279 if ((z > 0) && (cmd->SCp.this_residual == 1)) {
280 zwickel = *(cmd->SCp.ptr);
282 IncStat(&cmd->SCp, 1);
286 while (z > 0 || odd) {
287 outw(zwickel, base + HA_RDATA);
294 while ((stat & HA_SDRQ) || ((stat & HA_SMORE) && hd->moresupport));
296 /* terminate handler if HBA goes busy again, i.e. transfers
302 /* OK, this is quite stupid, but I haven't found any correct
303 * way to get HBA&SCSI status so far */
305 if (!(inb(base + HA_RSTATUS) & HA_SERROR)) {
306 cmd->result = (DID_OK << 16);
307 hd->devflags |= (1 << cp->cp_id);
308 } else if (hd->devflags & 1 << cp->cp_id)
309 cmd->result = (DID_OK << 16) + 0x02;
311 cmd->result = (DID_NO_CONNECT << 16);
313 if (cp->status == LOCKED) {
315 eata_stat = inb(base + HA_RSTATUS);
316 printk(KERN_CRIT "eata_pio: int_handler, freeing locked " "queueslot\n");
321 printk(KERN_DEBUG "stat: %#.2x, result: %#.8x\n", stat, cmd->result);
324 cp->status = FREE; /* now we can release the slot */
332 static inline uint eata_pio_send_command(uint base, unsigned char command)
336 while (inb(base + HA_RSTATUS) & HA_SBUSY)
340 /* Enable interrupts for HBA. It is not the best way to do it at this
341 * place, but I hope that it doesn't interfere with the IDE driver
342 * initialization this way */
344 outb(HA_CTRL_8HEADS, base + HA_CTRLREG);
346 outb(command, base + HA_WCOMMAND);
350 static int eata_pio_queue(struct scsi_cmnd *cmd,
351 void (*done)(struct scsi_cmnd *))
357 struct Scsi_Host *sh;
363 sh = cmd->device->host;
364 base = (uint) sh->base;
366 /* use only slot 0, as 2001 can handle only one cmd at a time */
370 if (hd->ccb[y].status != FREE) {
372 DBG(DBG_QUEUE, printk(KERN_EMERG "can_queue %d, x %d, y %d\n", sh->can_queue, x, y));
374 panic(KERN_EMERG "eata_pio: run out of queue slots cmdno:%ld " "intrno: %ld\n", queue_counter, int_counter);
376 panic(KERN_EMERG "eata_pio: run out of queue slots....\n");
382 memset(cp, 0, sizeof(struct eata_ccb));
383 memset(cmd->sense_buffer, 0, sizeof(cmd->sense_buffer));
385 cp->status = USED; /* claim free slot */
387 DBG(DBG_QUEUE, printk(KERN_DEBUG "eata_pio_queue pid %ld, target: %x, lun:" " %x, y %d\n", cmd->pid, cmd->device->id, cmd->device->lun, y));
389 cmd->scsi_done = (void *) done;
391 if (cmd->sc_data_direction == DMA_TO_DEVICE)
392 cp->DataOut = 1; /* Output mode */
394 cp->DataIn = 0; /* Input mode */
396 cp->Interpret = (cmd->device->id == hd->hostid);
397 cp->cp_datalen = htonl((unsigned long) cmd->request_bufflen);
398 cp->Auto_Req_Sen = 0;
399 cp->cp_reqDMA = htonl(0);
402 cp->cp_id = cmd->device->id;
403 cp->cp_lun = cmd->device->lun;
406 memcpy(cp->cp_cdb, cmd->cmnd, COMMAND_SIZE(*cmd->cmnd));
408 cp->cp_statDMA = htonl(0);
412 cmd->host_scribble = (char *) &hd->ccb[y];
414 if (cmd->use_sg == 0) {
415 cmd->SCp.buffers_residual = 1;
416 cmd->SCp.ptr = cmd->request_buffer;
417 cmd->SCp.this_residual = cmd->request_bufflen;
418 cmd->SCp.buffer = NULL;
420 cmd->SCp.buffer = cmd->request_buffer;
421 cmd->SCp.buffers_residual = cmd->use_sg;
422 cmd->SCp.ptr = page_address(cmd->SCp.buffer->page) + cmd->SCp.buffer->offset;
423 cmd->SCp.this_residual = cmd->SCp.buffer->length;
425 cmd->SCp.Status = (cmd->SCp.this_residual != 0); /* TRUE as long as bytes
428 if (eata_pio_send_command(base, EATA_CMD_PIO_SEND_CP)) {
429 cmd->result = DID_BUS_BUSY << 16;
430 printk(KERN_NOTICE "eata_pio_queue target %d, pid %ld, HBA busy, " "returning DID_BUS_BUSY, done.\n", cmd->device->id, cmd->pid);
436 while (!(inb(base + HA_RSTATUS) & HA_SDRQ))
438 outsw(base + HA_RDATA, cp, hd->cplen);
439 outb(EATA_CMD_PIO_TRUNC, base + HA_WCOMMAND);
440 for (x = 0; x < hd->cppadlen; x++)
441 outw(0, base + HA_RDATA);
443 DBG(DBG_QUEUE, printk(KERN_DEBUG "Queued base %#.4lx pid: %ld target: %x " "lun: %x slot %d irq %d\n", (long) sh->base, cmd->pid, cmd->device->id, cmd->device->lun, y, sh->irq));
448 static int eata_pio_abort(struct scsi_cmnd *cmd)
452 DBG(DBG_ABNORM, printk(KERN_WARNING "eata_pio_abort called pid: %ld " "target: %x lun: %x\n", cmd->pid, cmd->device->id, cmd->device->lun));
455 while (inb(cmd->device->host->base + HA_RAUXSTAT) & HA_ABUSY)
457 printk(KERN_WARNING "eata_pio: abort, timeout error.\n");
460 if (CD(cmd)->status == FREE) {
461 DBG(DBG_ABNORM, printk(KERN_WARNING "Returning: SCSI_ABORT_NOT_RUNNING\n"));
464 if (CD(cmd)->status == USED) {
465 DBG(DBG_ABNORM, printk(KERN_WARNING "Returning: SCSI_ABORT_BUSY\n"));
466 /* We want to sleep a bit more here */
467 return FAILED; /* SNOOZE */
469 if (CD(cmd)->status == RESET) {
470 printk(KERN_WARNING "eata_pio: abort, command reset error.\n");
473 if (CD(cmd)->status == LOCKED) {
474 DBG(DBG_ABNORM, printk(KERN_WARNING "eata_pio: abort, queue slot " "locked.\n"));
477 panic("eata_pio: abort: invalid slot status\n");
480 static int eata_pio_host_reset(struct scsi_cmnd *cmd)
483 unsigned char success = 0;
484 struct scsi_cmnd *sp;
485 struct Scsi_Host *host = cmd->device->host;
487 DBG(DBG_ABNORM, printk(KERN_WARNING "eata_pio_reset called pid:%ld target:" " %x lun: %x\n", cmd->pid, cmd->device->id, cmd->device->lun));
489 spin_lock_irq(host->host_lock);
491 if (HD(cmd)->state == RESET) {
492 printk(KERN_WARNING "eata_pio_reset: exit, already in reset.\n");
493 spin_unlock_irq(host->host_lock);
497 /* force all slots to be free */
499 for (x = 0; x < cmd->device->host->can_queue; x++) {
501 if (HD(cmd)->ccb[x].status == FREE)
504 sp = HD(cmd)->ccb[x].cmd;
505 HD(cmd)->ccb[x].status = RESET;
506 printk(KERN_WARNING "eata_pio_reset: slot %d in reset, pid %ld.\n", x, sp->pid);
509 panic("eata_pio_reset: slot %d, sp==NULL.\n", x);
512 /* hard reset the HBA */
513 outb(EATA_CMD_RESET, (uint) cmd->device->host->base + HA_WCOMMAND);
515 DBG(DBG_ABNORM, printk(KERN_WARNING "eata_pio_reset: board reset done.\n"));
516 HD(cmd)->state = RESET;
518 spin_unlock_irq(host->host_lock);
520 spin_lock_irq(host->host_lock);
522 DBG(DBG_ABNORM, printk(KERN_WARNING "eata_pio_reset: interrupts disabled, " "loops %d.\n", limit));
524 for (x = 0; x < cmd->device->host->can_queue; x++) {
526 /* Skip slots already set free by interrupt */
527 if (HD(cmd)->ccb[x].status != RESET)
530 sp = HD(cmd)->ccb[x].cmd;
531 sp->result = DID_RESET << 16;
533 /* This mailbox is terminated */
534 printk(KERN_WARNING "eata_pio_reset: reset ccb %d.\n", x);
535 HD(cmd)->ccb[x].status = FREE;
542 spin_unlock_irq(host->host_lock);
544 if (success) { /* hmmm... */
545 DBG(DBG_ABNORM, printk(KERN_WARNING "eata_pio_reset: exit, success.\n"));
548 DBG(DBG_ABNORM, printk(KERN_WARNING "eata_pio_reset: exit, wakeup.\n"));
553 static char *get_pio_board_data(unsigned long base, uint irq, uint id, unsigned long cplen, unsigned short cppadlen)
556 static char buff[256];
559 memset(&cp, 0, sizeof(struct eata_ccb));
560 memset(buff, 0, sizeof(buff));
563 cp.Interpret = 1; /* Interpret command */
565 cp.cp_datalen = htonl(254);
566 cp.cp_dataDMA = htonl(0);
571 cp.cp_cdb[0] = INQUIRY;
578 if (eata_pio_send_command((uint) base, EATA_CMD_PIO_SEND_CP))
580 while (!(inb(base + HA_RSTATUS) & HA_SDRQ));
581 outsw(base + HA_RDATA, &cp, cplen);
582 outb(EATA_CMD_PIO_TRUNC, base + HA_WCOMMAND);
583 for (z = 0; z < cppadlen; z++)
584 outw(0, base + HA_RDATA);
586 while (inb(base + HA_RSTATUS) & HA_SBUSY);
587 if (inb(base + HA_RSTATUS) & HA_SERROR)
589 else if (!(inb(base + HA_RSTATUS) & HA_SDRQ))
592 insw(base + HA_RDATA, &buff, 127);
593 while (inb(base + HA_RSTATUS) & HA_SDRQ)
594 inw(base + HA_RDATA);
599 static int get_pio_conf_PIO(u32 base, struct get_conf *buf)
601 unsigned long loop = HZ / 2;
605 if (!request_region(base, 9, "eata_pio"))
608 memset(buf, 0, sizeof(struct get_conf));
610 while (inb(base + HA_RSTATUS) & HA_SBUSY)
614 DBG(DBG_PIO && DBG_PROBE, printk(KERN_DEBUG "Issuing PIO READ CONFIG to HBA at %#x\n", base));
615 eata_pio_send_command(base, EATA_CMD_PIO_READ_CONFIG);
618 for (p = (unsigned short *) buf; (long) p <= ((long) buf + (sizeof(struct get_conf) / 2)); p++) {
619 while (!(inb(base + HA_RSTATUS) & HA_SDRQ))
624 *p = inw(base + HA_RDATA);
626 if (inb(base + HA_RSTATUS) & HA_SERROR) {
627 DBG(DBG_PROBE, printk("eata_dma: get_conf_PIO, error during "
628 "transfer for HBA at %x\n", base));
632 if (htonl(EATA_SIGNATURE) != buf->signature)
635 DBG(DBG_PIO && DBG_PROBE, printk(KERN_NOTICE "EATA Controller found "
636 "at %#4x EATA Level: %x\n",
637 base, (uint) (buf->version)));
639 while (inb(base + HA_RSTATUS) & HA_SDRQ)
640 inw(base + HA_RDATA);
642 if (!ALLOW_DMA_BOARDS) {
643 for (z = 0; z < MAXISA; z++)
644 if (base == ISAbases[z]) {
645 buf->IRQ = ISAirqs[z];
653 release_region(base, 9);
657 static void print_pio_config(struct get_conf *gc)
659 printk("Please check values: (read config data)\n");
660 printk("LEN: %d ver:%d OCS:%d TAR:%d TRNXFR:%d MORES:%d\n", (uint) ntohl(gc->len), gc->version, gc->OCS_enabled, gc->TAR_support, gc->TRNXFR, gc->MORE_support);
661 printk("HAAV:%d SCSIID0:%d ID1:%d ID2:%d QUEUE:%d SG:%d SEC:%d\n", gc->HAA_valid, gc->scsi_id[3], gc->scsi_id[2], gc->scsi_id[1], ntohs(gc->queuesiz), ntohs(gc->SGsiz), gc->SECOND);
662 printk("IRQ:%d IRQT:%d FORCADR:%d MCH:%d RIDQ:%d\n", gc->IRQ, gc->IRQ_TR, gc->FORCADR, gc->MAX_CHAN, gc->ID_qest);
665 static uint print_selftest(uint base)
667 unsigned char buffer[512];
672 printk("eata_pio: executing controller self test & setup...\n");
673 while (inb(base + HA_RSTATUS) & HA_SBUSY);
674 outb(EATA_CMD_PIO_SETUPTEST, base + HA_WCOMMAND);
676 while (inb(base + HA_RSTATUS) & HA_SBUSY)
678 if (inb(base + HA_RSTATUS) & HA_SDRQ) {
679 insw(base + HA_RDATA, &buffer, 256);
681 /* no beeps please... */
682 for (z = 0; z < 511 && buffer[z]; z++)
684 printk("%c", buffer[z]);
687 } while (inb(base + HA_RSTATUS) & (HA_SBUSY | HA_SDRQ));
689 return (!(inb(base + HA_RSTATUS) & HA_SERROR));
692 static int register_pio_HBA(long base, struct get_conf *gc)
694 unsigned long size = 0;
697 unsigned short cppadlen;
698 struct Scsi_Host *sh;
701 DBG(DBG_REGISTER, print_pio_config(gc));
703 if (gc->DMA_support) {
704 printk("HBA at %#.4lx supports DMA. Please use EATA-DMA driver.\n", base);
705 if (!ALLOW_DMA_BOARDS)
709 if ((buff = get_pio_board_data((uint) base, gc->IRQ, gc->scsi_id[3], cplen = (htonl(gc->cplen) + 1) / 2, cppadlen = (htons(gc->cppadlen) + 1) / 2)) == NULL) {
710 printk("HBA at %#lx didn't react on INQUIRY. Sorry.\n", (unsigned long) base);
714 if (!print_selftest(base) && !ALLOW_DMA_BOARDS) {
715 printk("HBA at %#lx failed while performing self test & setup.\n", (unsigned long) base);
719 size = sizeof(hostdata) + (sizeof(struct eata_ccb) * ntohs(gc->queuesiz));
721 sh = scsi_register(&driver_template, size);
725 if (!reg_IRQ[gc->IRQ]) { /* Interrupt already registered ? */
726 if (!request_irq(gc->IRQ, do_eata_pio_int_handler, SA_INTERRUPT, "EATA-PIO", sh)) {
729 reg_IRQL[gc->IRQ] = 1; /* IRQ is edge triggered */
731 printk("Couldn't allocate IRQ %d, Sorry.\n", gc->IRQ);
734 } else { /* More than one HBA on this IRQ */
735 if (reg_IRQL[gc->IRQ]) {
736 printk("Can't support more than one HBA on this IRQ,\n" " if the IRQ is edge triggered. Sorry.\n");
744 memset(hd->ccb, 0, (sizeof(struct eata_ccb) * ntohs(gc->queuesiz)));
745 memset(hd->reads, 0, sizeof(unsigned long) * 26);
747 strlcpy(SD(sh)->vendor, &buff[8], sizeof(SD(sh)->vendor));
748 strlcpy(SD(sh)->name, &buff[16], sizeof(SD(sh)->name));
749 SD(sh)->revision[0] = buff[32];
750 SD(sh)->revision[1] = buff[33];
751 SD(sh)->revision[2] = buff[34];
752 SD(sh)->revision[3] = '.';
753 SD(sh)->revision[4] = buff[35];
754 SD(sh)->revision[5] = 0;
756 switch (ntohl(gc->len)) {
758 SD(sh)->EATA_revision = 'a';
761 SD(sh)->EATA_revision = 'b';
764 SD(sh)->EATA_revision = 'c';
767 SD(sh)->EATA_revision = 'z';
769 SD(sh)->EATA_revision = '?';
772 if (ntohl(gc->len) >= 0x22) {
774 hd->bustype = IS_PCI;
775 else if (gc->is_EISA)
776 hd->bustype = IS_EISA;
778 hd->bustype = IS_ISA;
781 hd->bustype = IS_PCI;
782 else if (buff[21] == '2')
783 hd->bustype = IS_EISA;
785 hd->bustype = IS_ISA;
788 SD(sh)->cplen = cplen;
789 SD(sh)->cppadlen = cppadlen;
790 SD(sh)->hostid = gc->scsi_id[3];
791 SD(sh)->devflags = 1 << gc->scsi_id[3];
792 SD(sh)->moresupport = gc->MORE_support;
793 sh->unique_id = base;
798 sh->dma_channel = PIO;
799 sh->this_id = gc->scsi_id[3];
802 sh->sg_tablesize = SG_ALL;
814 sh->unchecked_isa_dma = 0; /* We can only do PIO */
816 hd->next = NULL; /* build a linked list of all HBAs */
818 if (hd->prev != NULL)
819 SD(hd->prev)->next = sh;
821 if (first_HBA == NULL)
827 static void find_pio_ISA(struct get_conf *buf)
831 for (i = 0; i < MAXISA; i++) {
834 if (!get_pio_conf_PIO(ISAbases[i], buf))
836 if (!register_pio_HBA(ISAbases[i], buf))
837 release_region(ISAbases[i], 9);
844 static void find_pio_EISA(struct get_conf *buf)
853 for (i = 0; i < MAXEISA; i++) {
854 if (EISAbases[i]) { /* Still a possibility ? */
856 base = 0x1c88 + (i * 0x1000);
858 pal1 = inb((u16) base - 8);
859 pal2 = inb((u16) base - 7);
860 pal3 = inb((u16) base - 6);
862 if (((pal1 == 0x12) && (pal2 == 0x14)) || ((pal1 == 0x38) && (pal2 == 0xa3) && (pal3 == 0x82)) || ((pal1 == 0x06) && (pal2 == 0x94) && (pal3 == 0x24))) {
863 DBG(DBG_PROBE, printk(KERN_NOTICE "EISA EATA id tags found: " "%x %x %x \n", (int) pal1, (int) pal2, (int) pal3));
865 if (get_pio_conf_PIO(base, buf)) {
866 DBG(DBG_PROBE && DBG_EISA, print_pio_config(buf));
868 if (!register_pio_HBA(base, buf))
869 release_region(base, 9);
871 printk(KERN_NOTICE "eata_dma: No valid IRQ. HBA " "removed from list\n");
872 release_region(base, 9);
875 /* Nothing found here so we take it from the list */
885 static void find_pio_PCI(struct get_conf *buf)
888 printk("eata_dma: kernel PCI support not enabled. Skipping scan for PCI HBAs.\n");
890 struct pci_dev *dev = NULL;
893 while ((dev = pci_find_device(PCI_VENDOR_ID_DPT, PCI_DEVICE_ID_DPT, dev)) != NULL) {
894 DBG(DBG_PROBE && DBG_PCI, printk("eata_pio: find_PCI, HBA at %s\n", pci_name(dev)));
895 if (pci_enable_device(dev))
898 base = pci_resource_flags(dev, 0);
899 if (base & IORESOURCE_MEM) {
900 printk("eata_pio: invalid base address of device %s\n", pci_name(dev));
903 base = pci_resource_start(dev, 0);
904 /* EISA tag there ? */
905 if ((inb(base) == 0x12) && (inb(base + 1) == 0x14))
906 continue; /* Jep, it's forced, so move on */
907 base += 0x10; /* Now, THIS is the real address */
909 /* We didn't find it in the primary search */
910 if (get_pio_conf_PIO(base, buf)) {
911 if (buf->FORCADR) { /* If the address is forced */
912 release_region(base, 9);
913 continue; /* we'll find it later */
916 /* OK. We made it till here, so we can go now
917 * and register it. We only have to check and
918 * eventually remove it from the EISA and ISA list
921 if (!register_pio_HBA(base, buf)) {
922 release_region(base, 9);
927 for (x = 0; x < MAXISA; ++x) {
928 if (ISAbases[x] == base) {
933 } else if ((base & 0x0fff) == 0x0c88) {
934 x = (base >> 12) & 0x0f;
939 else if (check_blink_state(base)) {
940 printk("eata_pio: HBA is in BLINK state.\n" "Consult your HBAs manual to correct this.\n");
945 #endif /* #ifndef CONFIG_PCI */
948 static int eata_pio_detect(struct scsi_host_template *tpnt)
950 struct Scsi_Host *HBA_ptr;
958 for (i = 0; i <= MAXIRQ; i++)
960 request_irq(i, do_eata_pio_int_handler, SA_INTERRUPT, "EATA-PIO", NULL);
964 if (registered_HBAs != 0) {
965 printk("EATA (Extended Attachment) PIO driver version: %d.%d%s\n"
966 "(c) 1993-95 Michael Neuffer, neuffer@goofy.zdv.uni-mainz.de\n" " Alfred Arnold, a.arnold@kfa-juelich.de\n" "This release only supports DASD devices (harddisks)\n", VER_MAJOR, VER_MINOR, VER_SUB);
968 printk("Registered HBAs:\n");
969 printk("HBA no. Boardtype: Revis: EATA: Bus: BaseIO: IRQ: Ch: ID: Pr:" " QS: SG: CPL:\n");
970 for (i = 1; i <= registered_HBAs; i++) {
971 printk("scsi%-2d: %.10s v%s 2.0%c %s %#.4x %2d %d %d %c"
973 HBA_ptr->host_no, SD(HBA_ptr)->name, SD(HBA_ptr)->revision,
974 SD(HBA_ptr)->EATA_revision, (SD(HBA_ptr)->bustype == 'P') ?
975 "PCI " : (SD(HBA_ptr)->bustype == 'E') ? "EISA" : "ISA ",
976 (uint) HBA_ptr->base, HBA_ptr->irq, SD(HBA_ptr)->channel, HBA_ptr->this_id,
977 SD(HBA_ptr)->primary ? 'Y' : 'N', HBA_ptr->can_queue,
978 HBA_ptr->sg_tablesize, HBA_ptr->cmd_per_lun);
979 HBA_ptr = SD(HBA_ptr)->next;
982 return (registered_HBAs);
985 static struct scsi_host_template driver_template = {
986 .proc_name = "eata_pio",
987 .name = "EATA (Extended Attachment) PIO driver",
988 .proc_info = eata_pio_proc_info,
989 .detect = eata_pio_detect,
990 .release = eata_pio_release,
991 .queuecommand = eata_pio_queue,
992 .eh_abort_handler = eata_pio_abort,
993 .eh_host_reset_handler = eata_pio_host_reset,
994 .use_clustering = ENABLE_CLUSTERING,
997 MODULE_AUTHOR("Michael Neuffer, Alfred Arnold");
998 MODULE_DESCRIPTION("EATA SCSI PIO driver");
999 MODULE_LICENSE("GPL");
1001 #include "scsi_module.c"