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@lxorguk.ukuu.org.uk> for *
18 * Linux 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/module.h>
50 #include <linux/kernel.h>
51 #include <linux/string.h>
52 #include <linux/ioport.h>
54 #include <linux/pci.h>
55 #include <linux/proc_fs.h>
56 #include <linux/interrupt.h>
57 #include <linux/blkdev.h>
58 #include <linux/spinlock.h>
59 #include <linux/delay.h>
63 #include <scsi/scsi.h>
64 #include <scsi/scsi_cmnd.h>
65 #include <scsi/scsi_device.h>
66 #include <scsi/scsi_host.h>
68 #include "eata_generic.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
;
86 static struct Scsi_Host
*last_HBA
;
87 static struct Scsi_Host
*first_HBA
;
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
;
93 static struct scsi_host_template driver_template
;
95 static int eata_pio_show_info(struct seq_file
*m
, struct Scsi_Host
*shost
)
97 seq_printf(m
, "EATA (Extended Attachment) PIO driver version: "
98 "%d.%d%s\n",VER_MAJOR
, VER_MINOR
, VER_SUB
);
99 seq_printf(m
, "queued commands: %10ld\n"
100 "processed interrupts:%10ld\n", queue_counter
, int_counter
);
101 seq_printf(m
, "\nscsi%-2d: HBA %.10s\n",
102 shost
->host_no
, SD(shost
)->name
);
103 seq_printf(m
, "Firmware revision: v%s\n",
104 SD(shost
)->revision
);
105 seq_printf(m
, "IO: PIO\n");
106 seq_printf(m
, "Base IO : %#.4x\n", (u32
) shost
->base
);
107 seq_printf(m
, "Host Bus: %s\n",
108 (SD(shost
)->bustype
== 'P')?"PCI ":
109 (SD(shost
)->bustype
== 'E')?"EISA":"ISA ");
113 static int eata_pio_release(struct Scsi_Host
*sh
)
115 hostdata
*hd
= SD(sh
);
116 if (sh
->irq
&& reg_IRQ
[sh
->irq
] == 1)
117 free_irq(sh
->irq
, NULL
);
120 if (SD(sh
)->channel
== 0) {
121 if (sh
->io_port
&& sh
->n_io_port
)
122 release_region(sh
->io_port
, sh
->n_io_port
);
124 /* At this point the PCI reference can go */
126 pci_dev_put(hd
->pdev
);
130 static void IncStat(struct scsi_pointer
*SCp
, unsigned int Increment
)
132 SCp
->ptr
+= Increment
;
133 if ((SCp
->this_residual
-= Increment
) == 0) {
134 if ((--SCp
->buffers_residual
) == 0)
138 SCp
->ptr
= sg_virt(SCp
->buffer
);
139 SCp
->this_residual
= SCp
->buffer
->length
;
144 static irqreturn_t
eata_pio_int_handler(int irq
, void *dev_id
);
146 static irqreturn_t
do_eata_pio_int_handler(int irq
, void *dev_id
)
149 struct Scsi_Host
*dev
= dev_id
;
152 spin_lock_irqsave(dev
->host_lock
, flags
);
153 ret
= eata_pio_int_handler(irq
, dev_id
);
154 spin_unlock_irqrestore(dev
->host_lock
, flags
);
158 static irqreturn_t
eata_pio_int_handler(int irq
, void *dev_id
)
160 unsigned int eata_stat
= 0xfffff;
161 struct scsi_cmnd
*cmd
;
166 struct Scsi_Host
*sh
;
167 unsigned short zwickel
= 0;
168 unsigned char stat
, odd
;
169 irqreturn_t ret
= IRQ_NONE
;
171 for (x
= 1, sh
= first_HBA
; x
<= registered_HBAs
; x
++, sh
= SD(sh
)->prev
)
175 if (inb(sh
->base
+ HA_RSTATUS
) & HA_SBUSY
)
185 base
= cmd
->device
->host
->base
;
188 stat
= inb(base
+ HA_RSTATUS
);
189 if (stat
& HA_SDRQ
) {
193 while ((cmd
->SCp
.Status
) && ((z
> 0) || (odd
))) {
195 *(cmd
->SCp
.ptr
) = zwickel
>> 8;
196 IncStat(&cmd
->SCp
, 1);
199 x
= min_t(unsigned int, z
, cmd
->SCp
.this_residual
/ 2);
200 insw(base
+ HA_RDATA
, cmd
->SCp
.ptr
, x
);
202 IncStat(&cmd
->SCp
, 2 * x
);
203 if ((z
> 0) && (cmd
->SCp
.this_residual
== 1)) {
204 zwickel
= inw(base
+ HA_RDATA
);
205 *(cmd
->SCp
.ptr
) = zwickel
& 0xff;
206 IncStat(&cmd
->SCp
, 1);
212 zwickel
= inw(base
+ HA_RDATA
);
215 } else { /* cp->DataOut */
219 while ((cmd
->SCp
.Status
) && ((z
> 0) || (odd
))) {
221 zwickel
+= *(cmd
->SCp
.ptr
) << 8;
222 IncStat(&cmd
->SCp
, 1);
223 outw(zwickel
, base
+ HA_RDATA
);
227 x
= min_t(unsigned int, z
, cmd
->SCp
.this_residual
/ 2);
228 outsw(base
+ HA_RDATA
, cmd
->SCp
.ptr
, x
);
230 IncStat(&cmd
->SCp
, 2 * x
);
231 if ((z
> 0) && (cmd
->SCp
.this_residual
== 1)) {
232 zwickel
= *(cmd
->SCp
.ptr
);
234 IncStat(&cmd
->SCp
, 1);
238 while (z
> 0 || odd
) {
239 outw(zwickel
, base
+ HA_RDATA
);
246 while ((stat
& HA_SDRQ
) || ((stat
& HA_SMORE
) && hd
->moresupport
));
248 /* terminate handler if HBA goes busy again, i.e. transfers
254 /* OK, this is quite stupid, but I haven't found any correct
255 * way to get HBA&SCSI status so far */
257 if (!(inb(base
+ HA_RSTATUS
) & HA_SERROR
)) {
258 cmd
->result
= (DID_OK
<< 16);
259 hd
->devflags
|= (1 << cp
->cp_id
);
260 } else if (hd
->devflags
& (1 << cp
->cp_id
))
261 cmd
->result
= (DID_OK
<< 16) + 0x02;
263 cmd
->result
= (DID_NO_CONNECT
<< 16);
265 if (cp
->status
== LOCKED
) {
267 eata_stat
= inb(base
+ HA_RSTATUS
);
268 printk(KERN_CRIT
"eata_pio: int_handler, freeing locked " "queueslot\n");
273 printk(KERN_DEBUG
"stat: %#.2x, result: %#.8x\n", stat
, cmd
->result
);
276 cp
->status
= FREE
; /* now we can release the slot */
284 static inline unsigned int eata_pio_send_command(unsigned long base
, unsigned char command
)
286 unsigned int loop
= 50;
288 while (inb(base
+ HA_RSTATUS
) & HA_SBUSY
)
292 /* Enable interrupts for HBA. It is not the best way to do it at this
293 * place, but I hope that it doesn't interfere with the IDE driver
294 * initialization this way */
296 outb(HA_CTRL_8HEADS
, base
+ HA_CTRLREG
);
298 outb(command
, base
+ HA_WCOMMAND
);
302 static int eata_pio_queue_lck(struct scsi_cmnd
*cmd
,
303 void (*done
)(struct scsi_cmnd
*))
309 struct Scsi_Host
*sh
;
315 sh
= cmd
->device
->host
;
318 /* use only slot 0, as 2001 can handle only one cmd at a time */
322 if (hd
->ccb
[y
].status
!= FREE
) {
324 DBG(DBG_QUEUE
, printk(KERN_EMERG
"can_queue %d, x %d, y %d\n", sh
->can_queue
, x
, y
));
326 panic(KERN_EMERG
"eata_pio: run out of queue slots cmdno:%ld " "intrno: %ld\n", queue_counter
, int_counter
);
328 panic(KERN_EMERG
"eata_pio: run out of queue slots....\n");
334 memset(cp
, 0, sizeof(struct eata_ccb
));
336 cp
->status
= USED
; /* claim free slot */
338 DBG(DBG_QUEUE
, scmd_printk(KERN_DEBUG
, cmd
,
339 "eata_pio_queue 0x%p, y %d\n", cmd
, y
));
341 cmd
->scsi_done
= (void *) done
;
343 if (cmd
->sc_data_direction
== DMA_TO_DEVICE
)
344 cp
->DataOut
= 1; /* Output mode */
346 cp
->DataIn
= 0; /* Input mode */
348 cp
->Interpret
= (cmd
->device
->id
== hd
->hostid
);
349 cp
->cp_datalen
= cpu_to_be32(scsi_bufflen(cmd
));
350 cp
->Auto_Req_Sen
= 0;
354 cp
->cp_id
= cmd
->device
->id
;
355 cp
->cp_lun
= cmd
->device
->lun
;
358 memcpy(cp
->cp_cdb
, cmd
->cmnd
, COMMAND_SIZE(*cmd
->cmnd
));
364 cmd
->host_scribble
= (char *) &hd
->ccb
[y
];
366 if (!scsi_bufflen(cmd
)) {
367 cmd
->SCp
.buffers_residual
= 1;
369 cmd
->SCp
.this_residual
= 0;
370 cmd
->SCp
.buffer
= NULL
;
372 cmd
->SCp
.buffer
= scsi_sglist(cmd
);
373 cmd
->SCp
.buffers_residual
= scsi_sg_count(cmd
);
374 cmd
->SCp
.ptr
= sg_virt(cmd
->SCp
.buffer
);
375 cmd
->SCp
.this_residual
= cmd
->SCp
.buffer
->length
;
377 cmd
->SCp
.Status
= (cmd
->SCp
.this_residual
!= 0); /* TRUE as long as bytes
380 if (eata_pio_send_command(base
, EATA_CMD_PIO_SEND_CP
)) {
381 cmd
->result
= DID_BUS_BUSY
<< 16;
382 scmd_printk(KERN_NOTICE
, cmd
,
383 "eata_pio_queue pid 0x%p, HBA busy, "
384 "returning DID_BUS_BUSY, done.\n", cmd
);
390 while (!(inb(base
+ HA_RSTATUS
) & HA_SDRQ
))
392 outsw(base
+ HA_RDATA
, cp
, hd
->cplen
);
393 outb(EATA_CMD_PIO_TRUNC
, base
+ HA_WCOMMAND
);
394 for (x
= 0; x
< hd
->cppadlen
; x
++)
395 outw(0, base
+ HA_RDATA
);
397 DBG(DBG_QUEUE
, scmd_printk(KERN_DEBUG
, cmd
,
398 "Queued base %#.4lx cmd: 0x%p "
399 "slot %d irq %d\n", sh
->base
, cmd
, y
, sh
->irq
));
404 static DEF_SCSI_QCMD(eata_pio_queue
)
406 static int eata_pio_abort(struct scsi_cmnd
*cmd
)
408 unsigned int loop
= 100;
410 DBG(DBG_ABNORM
, scmd_printk(KERN_WARNING
, cmd
,
411 "eata_pio_abort called pid: 0x%p\n", cmd
));
413 while (inb(cmd
->device
->host
->base
+ HA_RAUXSTAT
) & HA_ABUSY
)
415 printk(KERN_WARNING
"eata_pio: abort, timeout error.\n");
418 if (CD(cmd
)->status
== FREE
) {
419 DBG(DBG_ABNORM
, printk(KERN_WARNING
"Returning: SCSI_ABORT_NOT_RUNNING\n"));
422 if (CD(cmd
)->status
== USED
) {
423 DBG(DBG_ABNORM
, printk(KERN_WARNING
"Returning: SCSI_ABORT_BUSY\n"));
424 /* We want to sleep a bit more here */
425 return FAILED
; /* SNOOZE */
427 if (CD(cmd
)->status
== RESET
) {
428 printk(KERN_WARNING
"eata_pio: abort, command reset error.\n");
431 if (CD(cmd
)->status
== LOCKED
) {
432 DBG(DBG_ABNORM
, printk(KERN_WARNING
"eata_pio: abort, queue slot " "locked.\n"));
435 panic("eata_pio: abort: invalid slot status\n");
438 static int eata_pio_host_reset(struct scsi_cmnd
*cmd
)
440 unsigned int x
, limit
= 0;
441 unsigned char success
= 0;
442 struct scsi_cmnd
*sp
;
443 struct Scsi_Host
*host
= cmd
->device
->host
;
445 DBG(DBG_ABNORM
, scmd_printk(KERN_WARNING
, cmd
,
446 "eata_pio_reset called\n"));
448 spin_lock_irq(host
->host_lock
);
450 if (HD(cmd
)->state
== RESET
) {
451 printk(KERN_WARNING
"eata_pio_reset: exit, already in reset.\n");
452 spin_unlock_irq(host
->host_lock
);
456 /* force all slots to be free */
458 for (x
= 0; x
< cmd
->device
->host
->can_queue
; x
++) {
460 if (HD(cmd
)->ccb
[x
].status
== FREE
)
463 sp
= HD(cmd
)->ccb
[x
].cmd
;
464 HD(cmd
)->ccb
[x
].status
= RESET
;
465 printk(KERN_WARNING
"eata_pio_reset: slot %d in reset.\n", x
);
468 panic("eata_pio_reset: slot %d, sp==NULL.\n", x
);
471 /* hard reset the HBA */
472 outb(EATA_CMD_RESET
, cmd
->device
->host
->base
+ HA_WCOMMAND
);
474 DBG(DBG_ABNORM
, printk(KERN_WARNING
"eata_pio_reset: board reset done.\n"));
475 HD(cmd
)->state
= RESET
;
477 spin_unlock_irq(host
->host_lock
);
479 spin_lock_irq(host
->host_lock
);
481 DBG(DBG_ABNORM
, printk(KERN_WARNING
"eata_pio_reset: interrupts disabled, " "loops %d.\n", limit
));
483 for (x
= 0; x
< cmd
->device
->host
->can_queue
; x
++) {
485 /* Skip slots already set free by interrupt */
486 if (HD(cmd
)->ccb
[x
].status
!= RESET
)
489 sp
= HD(cmd
)->ccb
[x
].cmd
;
490 sp
->result
= DID_RESET
<< 16;
492 /* This mailbox is terminated */
493 printk(KERN_WARNING
"eata_pio_reset: reset ccb %d.\n", x
);
494 HD(cmd
)->ccb
[x
].status
= FREE
;
501 spin_unlock_irq(host
->host_lock
);
503 if (success
) { /* hmmm... */
504 DBG(DBG_ABNORM
, printk(KERN_WARNING
"eata_pio_reset: exit, success.\n"));
507 DBG(DBG_ABNORM
, printk(KERN_WARNING
"eata_pio_reset: exit, wakeup.\n"));
512 static char *get_pio_board_data(unsigned long base
, unsigned int irq
, unsigned int id
, unsigned long cplen
, unsigned short cppadlen
)
515 static char buff
[256];
518 memset(&cp
, 0, sizeof(struct eata_ccb
));
519 memset(buff
, 0, sizeof(buff
));
522 cp
.Interpret
= 1; /* Interpret command */
524 cp
.cp_datalen
= cpu_to_be32(254);
525 cp
.cp_dataDMA
= cpu_to_be32(0);
530 cp
.cp_cdb
[0] = INQUIRY
;
537 if (eata_pio_send_command(base
, EATA_CMD_PIO_SEND_CP
))
540 while (!(inb(base
+ HA_RSTATUS
) & HA_SDRQ
))
543 outsw(base
+ HA_RDATA
, &cp
, cplen
);
544 outb(EATA_CMD_PIO_TRUNC
, base
+ HA_WCOMMAND
);
545 for (z
= 0; z
< cppadlen
; z
++)
546 outw(0, base
+ HA_RDATA
);
548 while (inb(base
+ HA_RSTATUS
) & HA_SBUSY
)
551 if (inb(base
+ HA_RSTATUS
) & HA_SERROR
)
553 else if (!(inb(base
+ HA_RSTATUS
) & HA_SDRQ
))
556 insw(base
+ HA_RDATA
, &buff
, 127);
557 while (inb(base
+ HA_RSTATUS
) & HA_SDRQ
)
558 inw(base
+ HA_RDATA
);
563 static int get_pio_conf_PIO(unsigned long base
, struct get_conf
*buf
)
565 unsigned long loop
= HZ
/ 2;
569 if (!request_region(base
, 9, "eata_pio"))
572 memset(buf
, 0, sizeof(struct get_conf
));
574 while (inb(base
+ HA_RSTATUS
) & HA_SBUSY
)
578 DBG(DBG_PIO
&& DBG_PROBE
, printk(KERN_DEBUG
"Issuing PIO READ CONFIG to HBA at %#lx\n", base
));
579 eata_pio_send_command(base
, EATA_CMD_PIO_READ_CONFIG
);
582 for (p
= (unsigned short *) buf
; (long) p
<= ((long) buf
+ (sizeof(struct get_conf
) / 2)); p
++) {
583 while (!(inb(base
+ HA_RSTATUS
) & HA_SDRQ
))
588 *p
= inw(base
+ HA_RDATA
);
590 if (inb(base
+ HA_RSTATUS
) & HA_SERROR
) {
591 DBG(DBG_PROBE
, printk("eata_dma: get_conf_PIO, error during "
592 "transfer for HBA at %lx\n", base
));
596 if (cpu_to_be32(EATA_SIGNATURE
) != buf
->signature
)
599 DBG(DBG_PIO
&& DBG_PROBE
, printk(KERN_NOTICE
"EATA Controller found "
600 "at %#4lx EATA Level: %x\n",
601 base
, (unsigned int) (buf
->version
)));
603 while (inb(base
+ HA_RSTATUS
) & HA_SDRQ
)
604 inw(base
+ HA_RDATA
);
606 if (!ALLOW_DMA_BOARDS
) {
607 for (z
= 0; z
< MAXISA
; z
++)
608 if (base
== ISAbases
[z
]) {
609 buf
->IRQ
= ISAirqs
[z
];
617 release_region(base
, 9);
621 static void print_pio_config(struct get_conf
*gc
)
623 printk("Please check values: (read config data)\n");
624 printk("LEN: %d ver:%d OCS:%d TAR:%d TRNXFR:%d MORES:%d\n", be32_to_cpu(gc
->len
), gc
->version
, gc
->OCS_enabled
, gc
->TAR_support
, gc
->TRNXFR
, gc
->MORE_support
);
625 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], be16_to_cpu(gc
->queuesiz
), be16_to_cpu(gc
->SGsiz
), gc
->SECOND
);
626 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
);
629 static unsigned int print_selftest(unsigned int base
)
631 unsigned char buffer
[512];
636 printk("eata_pio: executing controller self test & setup...\n");
637 while (inb(base
+ HA_RSTATUS
) & HA_SBUSY
);
638 outb(EATA_CMD_PIO_SETUPTEST
, base
+ HA_WCOMMAND
);
640 while (inb(base
+ HA_RSTATUS
) & HA_SBUSY
)
642 if (inb(base
+ HA_RSTATUS
) & HA_SDRQ
) {
643 insw(base
+ HA_RDATA
, &buffer
, 256);
645 /* no beeps please... */
646 for (z
= 0; z
< 511 && buffer
[z
]; z
++)
648 printk("%c", buffer
[z
]);
651 } while (inb(base
+ HA_RSTATUS
) & (HA_SBUSY
| HA_SDRQ
));
653 return (!(inb(base
+ HA_RSTATUS
) & HA_SERROR
));
656 static int register_pio_HBA(long base
, struct get_conf
*gc
, struct pci_dev
*pdev
)
658 unsigned long size
= 0;
661 unsigned short cppadlen
;
662 struct Scsi_Host
*sh
;
665 DBG(DBG_REGISTER
, print_pio_config(gc
));
667 if (gc
->DMA_support
) {
668 printk("HBA at %#.4lx supports DMA. Please use EATA-DMA driver.\n", base
);
669 if (!ALLOW_DMA_BOARDS
)
673 if ((buff
= get_pio_board_data(base
, gc
->IRQ
, gc
->scsi_id
[3], cplen
= (cpu_to_be32(gc
->cplen
) + 1) / 2, cppadlen
= (cpu_to_be16(gc
->cppadlen
) + 1) / 2)) == NULL
) {
674 printk("HBA at %#lx didn't react on INQUIRY. Sorry.\n", base
);
678 if (!print_selftest(base
) && !ALLOW_DMA_BOARDS
) {
679 printk("HBA at %#lx failed while performing self test & setup.\n", base
);
683 size
= sizeof(hostdata
) + (sizeof(struct eata_ccb
) * be16_to_cpu(gc
->queuesiz
));
685 sh
= scsi_register(&driver_template
, size
);
689 if (!reg_IRQ
[gc
->IRQ
]) { /* Interrupt already registered ? */
690 if (!request_irq(gc
->IRQ
, do_eata_pio_int_handler
, IRQF_DISABLED
, "EATA-PIO", sh
)) {
693 reg_IRQL
[gc
->IRQ
] = 1; /* IRQ is edge triggered */
695 printk("Couldn't allocate IRQ %d, Sorry.\n", gc
->IRQ
);
698 } else { /* More than one HBA on this IRQ */
699 if (reg_IRQL
[gc
->IRQ
]) {
700 printk("Can't support more than one HBA on this IRQ,\n" " if the IRQ is edge triggered. Sorry.\n");
708 memset(hd
->ccb
, 0, (sizeof(struct eata_ccb
) * be16_to_cpu(gc
->queuesiz
)));
709 memset(hd
->reads
, 0, sizeof(hd
->reads
));
711 strlcpy(SD(sh
)->vendor
, &buff
[8], sizeof(SD(sh
)->vendor
));
712 strlcpy(SD(sh
)->name
, &buff
[16], sizeof(SD(sh
)->name
));
713 SD(sh
)->revision
[0] = buff
[32];
714 SD(sh
)->revision
[1] = buff
[33];
715 SD(sh
)->revision
[2] = buff
[34];
716 SD(sh
)->revision
[3] = '.';
717 SD(sh
)->revision
[4] = buff
[35];
718 SD(sh
)->revision
[5] = 0;
720 switch (be32_to_cpu(gc
->len
)) {
722 SD(sh
)->EATA_revision
= 'a';
725 SD(sh
)->EATA_revision
= 'b';
728 SD(sh
)->EATA_revision
= 'c';
731 SD(sh
)->EATA_revision
= 'z';
733 SD(sh
)->EATA_revision
= '?';
736 if (be32_to_cpu(gc
->len
) >= 0x22) {
738 hd
->bustype
= IS_PCI
;
739 else if (gc
->is_EISA
)
740 hd
->bustype
= IS_EISA
;
742 hd
->bustype
= IS_ISA
;
745 hd
->bustype
= IS_PCI
;
746 else if (buff
[21] == '2')
747 hd
->bustype
= IS_EISA
;
749 hd
->bustype
= IS_ISA
;
752 SD(sh
)->cplen
= cplen
;
753 SD(sh
)->cppadlen
= cppadlen
;
754 SD(sh
)->hostid
= gc
->scsi_id
[3];
755 SD(sh
)->devflags
= 1 << gc
->scsi_id
[3];
756 SD(sh
)->moresupport
= gc
->MORE_support
;
757 sh
->unique_id
= base
;
762 sh
->dma_channel
= PIO
;
763 sh
->this_id
= gc
->scsi_id
[3];
766 sh
->sg_tablesize
= SG_ALL
;
770 hd
->pdev
= pci_dev_get(pdev
); /* Keep a PCI reference */
780 hd
->next
= NULL
; /* build a linked list of all HBAs */
782 if (hd
->prev
!= NULL
)
783 SD(hd
->prev
)->next
= sh
;
785 if (first_HBA
== NULL
)
791 static void find_pio_ISA(struct get_conf
*buf
)
795 for (i
= 0; i
< MAXISA
; i
++) {
798 if (!get_pio_conf_PIO(ISAbases
[i
], buf
))
800 if (!register_pio_HBA(ISAbases
[i
], buf
, NULL
))
801 release_region(ISAbases
[i
], 9);
808 static void find_pio_EISA(struct get_conf
*buf
)
817 for (i
= 0; i
< MAXEISA
; i
++) {
818 if (EISAbases
[i
]) { /* Still a possibility ? */
820 base
= 0x1c88 + (i
* 0x1000);
822 pal1
= inb((u16
) base
- 8);
823 pal2
= inb((u16
) base
- 7);
824 pal3
= inb((u16
) base
- 6);
826 if (((pal1
== 0x12) && (pal2
== 0x14)) || ((pal1
== 0x38) && (pal2
== 0xa3) && (pal3
== 0x82)) || ((pal1
== 0x06) && (pal2
== 0x94) && (pal3
== 0x24))) {
827 DBG(DBG_PROBE
, printk(KERN_NOTICE
"EISA EATA id tags found: " "%x %x %x \n", (int) pal1
, (int) pal2
, (int) pal3
));
829 if (get_pio_conf_PIO(base
, buf
)) {
830 DBG(DBG_PROBE
&& DBG_EISA
, print_pio_config(buf
));
832 if (!register_pio_HBA(base
, buf
, NULL
))
833 release_region(base
, 9);
835 printk(KERN_NOTICE
"eata_dma: No valid IRQ. HBA " "removed from list\n");
836 release_region(base
, 9);
839 /* Nothing found here so we take it from the list */
849 static void find_pio_PCI(struct get_conf
*buf
)
852 printk("eata_dma: kernel PCI support not enabled. Skipping scan for PCI HBAs.\n");
854 struct pci_dev
*dev
= NULL
;
855 unsigned long base
, x
;
857 while ((dev
= pci_get_device(PCI_VENDOR_ID_DPT
, PCI_DEVICE_ID_DPT
, dev
)) != NULL
) {
858 DBG(DBG_PROBE
&& DBG_PCI
, printk("eata_pio: find_PCI, HBA at %s\n", pci_name(dev
)));
859 if (pci_enable_device(dev
))
862 base
= pci_resource_flags(dev
, 0);
863 if (base
& IORESOURCE_MEM
) {
864 printk("eata_pio: invalid base address of device %s\n", pci_name(dev
));
867 base
= pci_resource_start(dev
, 0);
868 /* EISA tag there ? */
869 if ((inb(base
) == 0x12) && (inb(base
+ 1) == 0x14))
870 continue; /* Jep, it's forced, so move on */
871 base
+= 0x10; /* Now, THIS is the real address */
873 /* We didn't find it in the primary search */
874 if (get_pio_conf_PIO(base
, buf
)) {
875 if (buf
->FORCADR
) { /* If the address is forced */
876 release_region(base
, 9);
877 continue; /* we'll find it later */
880 /* OK. We made it till here, so we can go now
881 * and register it. We only have to check and
882 * eventually remove it from the EISA and ISA list
885 if (!register_pio_HBA(base
, buf
, dev
)) {
886 release_region(base
, 9);
891 for (x
= 0; x
< MAXISA
; ++x
) {
892 if (ISAbases
[x
] == base
) {
897 } else if ((base
& 0x0fff) == 0x0c88) {
898 x
= (base
>> 12) & 0x0f;
903 else if (check_blink_state(base
)) {
904 printk("eata_pio: HBA is in BLINK state.\n" "Consult your HBAs manual to correct this.\n");
909 #endif /* #ifndef CONFIG_PCI */
912 static int eata_pio_detect(struct scsi_host_template
*tpnt
)
914 struct Scsi_Host
*HBA_ptr
;
922 for (i
= 0; i
< MAXIRQ
; i
++)
924 request_irq(i
, do_eata_pio_int_handler
, IRQF_DISABLED
, "EATA-PIO", NULL
);
928 if (registered_HBAs
!= 0) {
929 printk("EATA (Extended Attachment) PIO driver version: %d.%d%s\n"
930 "(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
);
932 printk("Registered HBAs:\n");
933 printk("HBA no. Boardtype: Revis: EATA: Bus: BaseIO: IRQ: Ch: ID: Pr:" " QS: SG: CPL:\n");
934 for (i
= 1; i
<= registered_HBAs
; i
++) {
935 printk("scsi%-2d: %.10s v%s 2.0%c %s %#.4lx %2d %d %d %c"
937 HBA_ptr
->host_no
, SD(HBA_ptr
)->name
, SD(HBA_ptr
)->revision
,
938 SD(HBA_ptr
)->EATA_revision
, (SD(HBA_ptr
)->bustype
== 'P') ?
939 "PCI " : (SD(HBA_ptr
)->bustype
== 'E') ? "EISA" : "ISA ",
940 HBA_ptr
->base
, HBA_ptr
->irq
, SD(HBA_ptr
)->channel
, HBA_ptr
->this_id
,
941 SD(HBA_ptr
)->primary
? 'Y' : 'N', HBA_ptr
->can_queue
,
942 HBA_ptr
->sg_tablesize
, HBA_ptr
->cmd_per_lun
);
943 HBA_ptr
= SD(HBA_ptr
)->next
;
946 return (registered_HBAs
);
949 static struct scsi_host_template driver_template
= {
950 .proc_name
= "eata_pio",
951 .name
= "EATA (Extended Attachment) PIO driver",
952 .show_info
= eata_pio_show_info
,
953 .detect
= eata_pio_detect
,
954 .release
= eata_pio_release
,
955 .queuecommand
= eata_pio_queue
,
956 .eh_abort_handler
= eata_pio_abort
,
957 .eh_host_reset_handler
= eata_pio_host_reset
,
958 .use_clustering
= ENABLE_CLUSTERING
,
961 MODULE_AUTHOR("Michael Neuffer, Alfred Arnold");
962 MODULE_DESCRIPTION("EATA SCSI PIO driver");
963 MODULE_LICENSE("GPL");
965 #include "scsi_module.c"