49 #include <linux/module.h>
50 #include <linux/kernel.h>
51 #include <linux/string.h>
54 #include <linux/pci.h>
63 #include <scsi/scsi.h>
72 static unsigned int ISAbases[
MAXISA] = {
73 0x1F0, 0x170, 0x330, 0x230
76 static unsigned int ISAirqs[
MAXISA] = {
80 static unsigned char EISAbases[] = {
81 1, 1, 1, 1, 1, 1, 1, 1,
82 1, 1, 1, 1, 1, 1, 1, 1
85 static unsigned int registered_HBAs;
88 static unsigned char reg_IRQ[16];
89 static unsigned char reg_IRQL[16];
90 static unsigned long int_counter;
91 static unsigned long queue_counter;
115 len +=
sprintf(buffer+len,
"EATA (Extended Attachment) PIO driver version: "
117 len +=
sprintf(buffer + len,
"queued commands: %10ld\n"
118 "processed interrupts:%10ld\n", queue_counter, int_counter);
119 len +=
sprintf(buffer + len,
"\nscsi%-2d: HBA %.10s\n",
121 len +=
sprintf(buffer + len,
"Firmware revision: v%s\n",
123 len +=
sprintf(buffer + len,
"IO: PIO\n");
124 len +=
sprintf(buffer + len,
"Base IO : %#.4x\n", (
u32) shost->
base);
125 len +=
sprintf(buffer + len,
"Host Bus: %s\n",
126 (
SD(shost)->bustype ==
'P')?
"PCI ":
127 (
SD(shost)->bustype ==
'E')?
"EISA":
"ISA ");
135 if (
pos > offset + length)
140 *start = buffer + (offset - begin);
141 len -= (offset - begin);
149 static int eata_pio_release(
struct Scsi_Host *sh)
152 if (sh->
irq && reg_IRQ[sh->
irq] == 1)
166 static void IncStat(
struct scsi_pointer *SCp,
unsigned int Increment)
168 SCp->
ptr += Increment;
189 ret = eata_pio_int_handler(irq, dev_id);
190 spin_unlock_irqrestore(dev->
host_lock, flags);
196 unsigned int eata_stat = 0xfffff;
203 unsigned short zwickel = 0;
204 unsigned char stat, odd;
207 for (x = 1, sh = first_HBA; x <= registered_HBAs; x++, sh =
SD(sh)->prev)
221 base = cmd->
device->host->base;
229 while ((cmd->
SCp.Status) && ((z > 0) || (odd))) {
231 *(cmd->
SCp.ptr) = zwickel >> 8;
232 IncStat(&cmd->
SCp, 1);
235 x =
min_t(
unsigned int, z, cmd->
SCp.this_residual / 2);
238 IncStat(&cmd->
SCp, 2 * x);
239 if ((z > 0) && (cmd->
SCp.this_residual == 1)) {
241 *(cmd->
SCp.ptr) = zwickel & 0xff;
242 IncStat(&cmd->
SCp, 1);
255 while ((cmd->
SCp.Status) && ((z > 0) || (odd))) {
257 zwickel += *(cmd->
SCp.ptr) << 8;
258 IncStat(&cmd->
SCp, 1);
263 x =
min_t(
unsigned int, z, cmd->
SCp.this_residual / 2);
266 IncStat(&cmd->
SCp, 2 * x);
267 if ((z > 0) && (cmd->
SCp.this_residual == 1)) {
268 zwickel = *(cmd->
SCp.ptr);
270 IncStat(&cmd->
SCp, 1);
274 while (z > 0 || odd) {
282 while ((stat & HA_SDRQ) || ((stat &
HA_SMORE) && hd->moresupport));
295 hd->devflags |= (1 << cp->
cp_id);
296 }
else if (hd->devflags & (1 << cp->
cp_id))
304 printk(
KERN_CRIT "eata_pio: int_handler, freeing locked " "queueslot\n");
320 static inline unsigned int eata_pio_send_command(
unsigned long base,
unsigned char command)
322 unsigned int loop = 50;
338 static int eata_pio_queue_lck(
struct scsi_cmnd *cmd,
358 if (hd->ccb[y].status !=
FREE) {
362 panic(
KERN_EMERG "eata_pio: run out of queue slots cmdno:%ld " "intrno: %ld\n", queue_counter, int_counter);
375 "eata_pio_queue 0x%p, y %d\n", cmd, y));
402 if (!scsi_bufflen(cmd)) {
403 cmd->
SCp.buffers_residual = 1;
405 cmd->
SCp.this_residual = 0;
408 cmd->
SCp.buffer = scsi_sglist(cmd);
409 cmd->
SCp.buffers_residual = scsi_sg_count(cmd);
410 cmd->
SCp.ptr = sg_virt(cmd->
SCp.buffer);
411 cmd->
SCp.this_residual = cmd->
SCp.buffer->length;
413 cmd->
SCp.Status = (cmd->
SCp.this_residual != 0);
419 "eata_pio_queue pid 0x%p, HBA busy, "
420 "returning DID_BUS_BUSY, done.\n", cmd);
430 for (x = 0; x < hd->cppadlen; x++)
434 "Queued base %#.4lx cmd: 0x%p "
435 "slot %d irq %d\n", sh->
base, cmd, y, sh->
irq));
444 unsigned int loop = 100;
447 "eata_pio_abort called pid: 0x%p\n", cmd));
471 panic(
"eata_pio: abort: invalid slot status\n");
474 static int eata_pio_host_reset(
struct scsi_cmnd *cmd)
476 unsigned int x,
limit = 0;
477 unsigned char success = 0;
482 "eata_pio_reset called\n"));
494 for (x = 0; x < cmd->
device->host->can_queue; x++) {
499 sp =
HD(cmd)->ccb[
x].cmd;
504 panic(
"eata_pio_reset: slot %d, sp==NULL.\n", x);
519 for (x = 0; x < cmd->
device->host->can_queue; x++) {
525 sp =
HD(cmd)->ccb[
x].cmd;
548 static char *get_pio_board_data(
unsigned long base,
unsigned int irq,
unsigned int id,
unsigned long cplen,
unsigned short cppadlen)
551 static char buff[256];
555 memset(buff, 0,
sizeof(buff));
581 for (z = 0; z < cppadlen; z++)
599 static int get_pio_conf_PIO(
unsigned long base,
struct get_conf *
buf)
601 unsigned long loop =
HZ / 2;
618 for (p = (
unsigned short *) buf; (
long) p <= ((
long) buf + (
sizeof(
struct get_conf) / 2)); p++) {
628 "transfer for HBA at %lx\n", base));
636 "at %#4lx EATA Level: %x\n",
637 base, (
unsigned int) (buf->
version)));
643 for (z = 0; z <
MAXISA; z++)
644 if (base == ISAbases[z]) {
645 buf->
IRQ = ISAirqs[z];
657 static void print_pio_config(
struct get_conf *
gc)
659 printk(
"Please check values: (read config data)\n");
665 static unsigned int print_selftest(
unsigned int base)
667 unsigned char buffer[512];
672 printk(
"eata_pio: executing controller self test & setup...\n");
682 for (z = 0; z < 511 && buffer[z]; z++)
692 static int register_pio_HBA(
long base,
struct get_conf *gc,
struct pci_dev *pdev)
694 unsigned long size = 0;
697 unsigned short cppadlen;
704 printk(
"HBA at %#.4lx supports DMA. Please use EATA-DMA driver.\n", base);
710 printk(
"HBA at %#lx didn't react on INQUIRY. Sorry.\n", base);
715 printk(
"HBA at %#lx failed while performing self test & setup.\n", base);
725 if (!reg_IRQ[gc->
IRQ]) {
729 reg_IRQL[gc->
IRQ] = 1;
731 printk(
"Couldn't allocate IRQ %d, Sorry.\n", gc->
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");
745 memset(hd->reads, 0,
sizeof(hd->reads));
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;
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 =
'?';
782 else if (buff[21] ==
'2')
788 SD(sh)->cplen = cplen;
789 SD(sh)->cppadlen = cppadlen;
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,
NULL))
844 static void find_pio_EISA(
struct get_conf *buf)
853 for (i = 0; i <
MAXEISA; i++) {
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))) {
865 if (get_pio_conf_PIO(base, buf)) {
868 if (!register_pio_HBA(base, buf,
NULL))
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");
891 unsigned long base,
x;
900 printk(
"eata_pio: invalid base address of device %s\n", pci_name(dev));
905 if ((
inb(base) == 0x12) && (
inb(base + 1) == 0x14))
910 if (get_pio_conf_PIO(base, buf)) {
921 if (!register_pio_HBA(base, buf, dev)) {
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");
958 for (i = 0; i <=
MAXIRQ; i++)
964 if (registered_HBAs != 0) {
965 printk(
"EATA (Extended Attachment) PIO driver version: %d.%d%s\n"
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 %#.4lx %2d %d %d %c"
974 SD(HBA_ptr)->EATA_revision, (
SD(HBA_ptr)->bustype ==
'P') ?
975 "PCI " : (
SD(HBA_ptr)->bustype ==
'E') ?
"EISA" :
"ISA ",
979 HBA_ptr =
SD(HBA_ptr)->next;
982 return (registered_HBAs);
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,