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 * This program is free software; you can redistribute it *
18 * and/or modify it under the terms of the GNU General *
19 * Public License as published by the Free Software *
20 * Foundation; either version 2 of the License, or *
21 * (at your option) any later version. *
23 * This program is distributed in the hope that it will be *
24 * useful, but WITHOUT ANY WARRANTY; without even the *
25 * implied warranty of MERCHANTABILITY or FITNESS FOR A *
26 * PARTICULAR PURPOSE. See the GNU General Public License *
29 * You should have received a copy of the GNU General *
30 * Public License along with this kernel; if not, write to *
31 * the Free Software Foundation, Inc., 675 Mass Ave, *
32 * Cambridge, MA 02139, USA. *
34 ************************************************************
35 * last change: 96/07/16 OS: Linux 2.0.8 *
36 ************************************************************/
38 /* Look in eata_pio.h for configuration information */
40 #include <linux/module.h>
42 #include <linux/kernel.h>
43 #include <linux/sched.h>
44 #include <linux/string.h>
45 #include <linux/ioport.h>
46 #include <linux/malloc.h>
48 #include <linux/pci.h>
49 #include <linux/proc_fs.h>
52 #include "eata_dma_proc.h"
56 #include <linux/stat.h>
57 #include <linux/config.h> /* for CONFIG_PCI */
58 #include <linux/blk.h>
59 #include <linux/spinlock.h>
61 struct proc_dir_entry proc_scsi_eata_pio
= {
62 PROC_SCSI_EATA_PIO
, 9, "eata_pio",
63 S_IFDIR
| S_IRUGO
| S_IXUGO
, 2
66 static uint ISAbases
[MAXISA
] =
67 {0x1F0, 0x170, 0x330, 0x230};
68 static uint ISAirqs
[MAXISA
] =
70 static unchar EISAbases
[] =
71 {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
72 static uint registered_HBAs
= 0;
73 static struct Scsi_Host
*last_HBA
= NULL
;
74 static struct Scsi_Host
*first_HBA
= NULL
;
75 static unchar reg_IRQ
[] =
76 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
77 static unchar reg_IRQL
[] =
78 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
80 static ulong int_counter
= 0;
81 static ulong queue_counter
= 0;
83 #include "eata_pio_proc.c"
86 int eata_pio_release(struct Scsi_Host
*sh
)
88 if (sh
->irq
&& reg_IRQ
[sh
->irq
] == 1) free_irq(sh
->irq
, NULL
);
89 else reg_IRQ
[sh
->irq
]--;
90 if (SD(sh
)->channel
== 0) {
91 if (sh
->io_port
&& sh
->n_io_port
)
92 release_region(sh
->io_port
, sh
->n_io_port
);
98 void IncStat(Scsi_Pointer
*SCp
, uint Increment
)
101 if ((SCp
->this_residual
-=Increment
)==0)
103 if ((--SCp
->buffers_residual
)==0) SCp
->Status
=FALSE
;
107 SCp
->ptr
=SCp
->buffer
->address
;
108 SCp
->this_residual
=SCp
->buffer
->length
;
113 void eata_pio_int_handler(int irq
, void *dev_id
, struct pt_regs
* regs
);
115 void do_eata_pio_int_handler(int irq
, void *dev_id
, struct pt_regs
* regs
)
119 spin_lock_irqsave(&io_request_lock
, flags
);
120 eata_pio_int_handler(irq
, dev_id
, regs
);
121 spin_unlock_irqrestore(&io_request_lock
, flags
);
124 void eata_pio_int_handler(int irq
, void *dev_id
, struct pt_regs
* regs
)
126 uint eata_stat
= 0xfffff;
133 struct Scsi_Host
*sh
;
140 for (x
= 1, sh
= first_HBA
; x
<= registered_HBAs
; x
++, sh
= SD(sh
)->prev
) {
143 if (inb((uint
)sh
->base
+ HA_RSTATUS
) & HA_SBUSY
)
152 base
= (uint
) cmd
->host
->base
;
156 stat
=inb(base
+HA_RSTATUS
);
161 while ((cmd
->SCp
.Status
)&&((z
>0)||(odd
)))
165 *(cmd
->SCp
.ptr
)=zwickel
>>8;
166 IncStat(&cmd
->SCp
,1);
169 x
=min(z
,cmd
->SCp
.this_residual
/2);
170 insw(base
+HA_RDATA
,cmd
->SCp
.ptr
,x
);
172 IncStat(&cmd
->SCp
,2*x
);
173 if ((z
>0)&&(cmd
->SCp
.this_residual
==1))
175 zwickel
=inw(base
+HA_RDATA
);
176 *(cmd
->SCp
.ptr
)=zwickel
&0xff;
177 IncStat(&cmd
->SCp
,1); z
--;
182 zwickel
=inw(base
+HA_RDATA
);
186 else /* cp->DataOut */
189 while ((cmd
->SCp
.Status
)&&((z
>0)||(odd
)))
193 zwickel
+=*(cmd
->SCp
.ptr
)<<8;
194 IncStat(&cmd
->SCp
,1);
195 outw(zwickel
,base
+HA_RDATA
);
199 x
=min(z
,cmd
->SCp
.this_residual
/2);
200 outsw(base
+HA_RDATA
,cmd
->SCp
.ptr
,x
);
202 IncStat(&cmd
->SCp
,2*x
);
203 if ((z
>0)&&(cmd
->SCp
.this_residual
==1))
205 zwickel
=*(cmd
->SCp
.ptr
);
207 IncStat(&cmd
->SCp
,1);
212 outw(zwickel
,base
+HA_RDATA
);
219 while ((stat
&HA_SDRQ
)||((stat
&HA_SMORE
)&&hd
->moresupport
));
221 /* terminate handler if HBA goes busy again, i.e. transfers
224 if (stat
&HA_SBUSY
) break;
226 /* OK, this is quite stupid, but I haven't found any correct
227 * way to get HBA&SCSI status so far */
229 if (!(inb(base
+HA_RSTATUS
)&HA_SERROR
))
231 cmd
->result
=(DID_OK
<<16);
232 hd
->devflags
|=(1<<cp
->cp_id
);
234 else if (hd
->devflags
&1<<cp
->cp_id
)
235 cmd
->result
=(DID_OK
<<16)+0x02;
236 else cmd
->result
=(DID_NO_CONNECT
<<16);
238 if (cp
->status
== LOCKED
) {
240 eata_stat
= inb(base
+ HA_RSTATUS
);
241 printk(KERN_NOTICE
"eata_pio: int_handler, freeing locked "
243 DBG(DBG_INTR
&&DBG_DELAY
,DELAY(1));
244 restore_flags(flags
);
250 printk(KERN_DEBUG
"stat: %#.2x, result: %#.8x\n", stat
,
252 DBG(DBG_INTR
&&DBG_DELAY
,DELAY(1));
255 cp
->status
= FREE
; /* now we can release the slot */
257 restore_flags(flags
);
262 restore_flags(flags
);
267 inline uint
eata_pio_send_command(uint base
, unchar command
)
271 while (inb(base
+ HA_RSTATUS
) & HA_SBUSY
)
275 /* Enable interrupts for HBA. It is not the best way to do it at this
276 * place, but I hope that it doesn't interfere with the IDE driver
277 * initialization this way */
279 outb(HA_CTRL_8HEADS
,base
+HA_CTRLREG
);
281 outb(command
, base
+ HA_WCOMMAND
);
285 int eata_pio_queue(Scsi_Cmnd
* cmd
, void (*done
) (Scsi_Cmnd
*))
292 struct Scsi_Host
*sh
;
302 base
= (uint
) sh
->base
;
304 /* use only slot 0, as 2001 can handle only one cmd at a time */
308 if (hd
->ccb
[y
].status
!=FREE
) {
310 DBG(DBG_QUEUE
, printk(KERN_EMERG
"can_queue %d, x %d, y %d\n",
313 panic(KERN_EMERG
"eata_pio: run out of queue slots cmdno:%ld "
314 "intrno: %ld\n", queue_counter
, int_counter
);
316 panic(KERN_EMERG
"eata_pio: run out of queue slots....\n");
322 memset(cp
, 0, sizeof(struct eata_ccb
));
323 memset(cmd
->sense_buffer
, 0, sizeof(cmd
->sense_buffer
));
325 cp
->status
= USED
; /* claim free slot */
327 DBG(DBG_QUEUE
, printk(KERN_DEBUG
"eata_pio_queue pid %ld, target: %x, lun:"
328 " %x, y %d\n", cmd
->pid
, cmd
->target
, cmd
->lun
, y
));
329 DBG(DBG_QUEUE
&& DBG_DELAY
, DELAY(1));
331 cmd
->scsi_done
= (void *)done
;
333 switch (cmd
->cmnd
[0]) {
334 case CHANGE_DEFINITION
: case COMPARE
: case COPY
:
335 case COPY_VERIFY
: case LOG_SELECT
: case MODE_SELECT
:
336 case MODE_SELECT_10
: case SEND_DIAGNOSTIC
: case WRITE_BUFFER
:
337 case FORMAT_UNIT
: case REASSIGN_BLOCKS
: case RESERVE
:
338 case SEARCH_EQUAL
: case SEARCH_HIGH
: case SEARCH_LOW
:
339 case WRITE_6
: case WRITE_10
: case WRITE_VERIFY
:
340 case UPDATE_BLOCK
: case WRITE_LONG
: case WRITE_SAME
:
341 case SEARCH_HIGH_12
: case SEARCH_EQUAL_12
: case SEARCH_LOW_12
:
342 case WRITE_12
: case WRITE_VERIFY_12
: case SET_WINDOW
:
343 case MEDIUM_SCAN
: case SEND_VOLUME_TAG
:
344 case 0xea: /* alternate number for WRITE LONG */
345 cp
->DataOut
= TRUE
; /* Output mode */
347 case TEST_UNIT_READY
:
349 cp
->DataIn
= TRUE
; /* Input mode */
352 cp
->Interpret
= (cmd
->target
== hd
->hostid
);
353 cp
->cp_datalen
= htonl((ulong
)cmd
->request_bufflen
);
354 cp
->Auto_Req_Sen
= FALSE
;
355 cp
->cp_reqDMA
= htonl(0);
358 cp
->cp_id
= cmd
->target
;
359 cp
->cp_lun
= cmd
->lun
;
360 cp
->cp_dispri
= FALSE
;
361 cp
->cp_identify
= TRUE
;
362 memcpy(cp
->cp_cdb
, cmd
->cmnd
, COMMAND_SIZE(*cmd
->cmnd
));
364 cp
->cp_statDMA
= htonl(0);
368 cmd
->host_scribble
= (char *)&hd
->ccb
[y
];
370 if (cmd
->use_sg
== 0)
372 cmd
->SCp
.buffers_residual
=1;
373 cmd
->SCp
.ptr
= cmd
->request_buffer
;
374 cmd
->SCp
.this_residual
= cmd
->request_bufflen
;
375 cmd
->SCp
.buffer
= NULL
;
377 cmd
->SCp
.buffer
= cmd
->request_buffer
;
378 cmd
->SCp
.buffers_residual
= cmd
->use_sg
;
379 cmd
->SCp
.ptr
= cmd
->SCp
.buffer
->address
;
380 cmd
->SCp
.this_residual
= cmd
->SCp
.buffer
->length
;
382 cmd
->SCp
.Status
= (cmd
->SCp
.this_residual
!= 0); /* TRUE as long as bytes
385 if (eata_pio_send_command(base
, EATA_CMD_PIO_SEND_CP
))
387 cmd
->result
= DID_BUS_BUSY
<< 16;
388 printk(KERN_NOTICE
"eata_pio_queue target %d, pid %ld, HBA busy, "
389 "returning DID_BUS_BUSY, done.\n", cmd
->target
, cmd
->pid
);
392 restore_flags(flags
);
395 while (!(inb(base
+ HA_RSTATUS
) & HA_SDRQ
));
396 outsw(base
+ HA_RDATA
, cp
, hd
->cplen
);
397 outb(EATA_CMD_PIO_TRUNC
, base
+ HA_WCOMMAND
);
398 for (x
= 0; x
< hd
->cppadlen
; x
++) outw(0, base
+ HA_RDATA
);
400 DBG(DBG_QUEUE
,printk(KERN_DEBUG
"Queued base %#.4lx pid: %ld target: %x "
401 "lun: %x slot %d irq %d\n", (long)sh
->base
, cmd
->pid
,
402 cmd
->target
, cmd
->lun
, y
, sh
->irq
));
403 DBG(DBG_QUEUE
&& DBG_DELAY
, DELAY(1));
405 restore_flags(flags
);
409 int eata_pio_abort(Scsi_Cmnd
* cmd
)
417 DBG(DBG_ABNORM
, printk(KERN_WARNING
"eata_pio_abort called pid: %ld "
418 "target: %x lun: %x reason %x\n", cmd
->pid
,
419 cmd
->target
, cmd
->lun
, cmd
->abort_reason
));
420 DBG(DBG_ABNORM
&& DBG_DELAY
, DELAY(1));
423 while (inb((uint
)(cmd
->host
->base
) + HA_RAUXSTAT
) & HA_ABUSY
)
425 printk(KERN_WARNING
"eata_pio: abort, timeout error.\n");
426 restore_flags(flags
);
427 DBG(DBG_ABNORM
&& DBG_DELAY
, DELAY(1));
428 return (SCSI_ABORT_ERROR
);
430 if (CD(cmd
)->status
== FREE
) {
431 DBG(DBG_ABNORM
, printk(KERN_WARNING
"Returning: SCSI_ABORT_NOT_RUNNING\n"));
432 restore_flags(flags
);
433 return (SCSI_ABORT_NOT_RUNNING
);
435 if (CD(cmd
)->status
== USED
) {
436 DBG(DBG_ABNORM
, printk(KERN_WARNING
"Returning: SCSI_ABORT_BUSY\n"));
437 restore_flags(flags
);
438 return (SCSI_ABORT_BUSY
); /* SNOOZE */
440 if (CD(cmd
)->status
== RESET
) {
441 restore_flags(flags
);
442 printk(KERN_WARNING
"eata_pio: abort, command reset error.\n");
443 DBG(DBG_ABNORM
&& DBG_DELAY
, DELAY(1));
444 return (SCSI_ABORT_ERROR
);
446 if (CD(cmd
)->status
== LOCKED
) {
447 restore_flags(flags
);
448 DBG(DBG_ABNORM
, printk(KERN_WARNING
"eata_pio: abort, queue slot "
450 DBG(DBG_ABNORM
&& DBG_DELAY
, DELAY(1));
451 return (SCSI_ABORT_NOT_RUNNING
);
453 restore_flags(flags
);
454 panic("eata_pio: abort: invalid slot status\n");
457 int eata_pio_reset(Scsi_Cmnd
* cmd
, unsigned int dummy
)
459 uint x
, time
, limit
= 0;
461 unchar success
= FALSE
;
466 DBG(DBG_ABNORM
, printk(KERN_WARNING
"eata_pio_reset called pid:%ld target:"
467 " %x lun: %x reason %x\n", cmd
->pid
, cmd
->target
,
468 cmd
->lun
, cmd
->abort_reason
));
470 if (HD(cmd
)->state
== RESET
) {
471 printk(KERN_WARNING
"eata_pio_reset: exit, already in reset.\n");
472 restore_flags(flags
);
473 DBG(DBG_ABNORM
&& DBG_DELAY
, DELAY(1));
474 return (SCSI_RESET_ERROR
);
477 /* force all slots to be free */
479 for (x
= 0; x
< cmd
->host
->can_queue
; x
++) {
481 if (HD(cmd
)->ccb
[x
].status
== FREE
)
484 sp
= HD(cmd
)->ccb
[x
].cmd
;
485 HD(cmd
)->ccb
[x
].status
= RESET
;
486 printk(KERN_WARNING
"eata_pio_reset: slot %d in reset, pid %ld.\n", x
,
488 DBG(DBG_ABNORM
&& DBG_DELAY
, DELAY(1));
491 panic("eata_pio_reset: slot %d, sp==NULL.\n", x
);
492 DBG(DBG_ABNORM
&& DBG_DELAY
, DELAY(1));
495 /* hard reset the HBA */
496 outb(EATA_CMD_RESET
, (uint
) cmd
->host
->base
+HA_WCOMMAND
);
498 DBG(DBG_ABNORM
, printk(KERN_WARNING
"eata_pio_reset: board reset done.\n"));
499 HD(cmd
)->state
= RESET
;
502 while (time_before(jiffies
, time
+ 3 * HZ
) && limit
++ < 10000000);
504 DBG(DBG_ABNORM
, printk(KERN_WARNING
"eata_pio_reset: interrupts disabled, "
505 "loops %d.\n", limit
));
506 DBG(DBG_ABNORM
&& DBG_DELAY
, DELAY(1));
508 for (x
= 0; x
< cmd
->host
->can_queue
; x
++) {
510 /* Skip slots already set free by interrupt */
511 if (HD(cmd
)->ccb
[x
].status
!= RESET
)
514 sp
= HD(cmd
)->ccb
[x
].cmd
;
515 sp
->result
= DID_RESET
<< 16;
517 /* This mailbox is terminated */
518 printk(KERN_WARNING
"eata_pio_reset: reset ccb %d.\n",x
);
519 HD(cmd
)->ccb
[x
].status
= FREE
;
521 restore_flags(flags
);
526 HD(cmd
)->state
= FALSE
;
527 restore_flags(flags
);
529 if (success
) { /* hmmm... */
530 DBG(DBG_ABNORM
, printk(KERN_WARNING
"eata_pio_reset: exit, success.\n"));
531 DBG(DBG_ABNORM
&& DBG_DELAY
, DELAY(1));
532 return (SCSI_RESET_SUCCESS
);
534 DBG(DBG_ABNORM
, printk(KERN_WARNING
"eata_pio_reset: exit, wakeup.\n"));
535 DBG(DBG_ABNORM
&& DBG_DELAY
, DELAY(1));
536 return (SCSI_RESET_PUNT
);
540 char * get_pio_board_data(ulong base
, uint irq
, uint id
, ulong cplen
, ushort cppadlen
)
543 static char buff
[256];
546 memset(&cp
, 0, sizeof(struct eata_ccb
));
547 memset(buff
, 0, sizeof(buff
));
550 cp
.Interpret
= TRUE
; /* Interpret command */
552 cp
.cp_datalen
= htonl(254);
553 cp
.cp_dataDMA
= htonl(0);
558 cp
.cp_cdb
[0] = INQUIRY
;
565 if (eata_pio_send_command((uint
) base
, EATA_CMD_PIO_SEND_CP
))
567 while (!(inb(base
+ HA_RSTATUS
) & HA_SDRQ
));
568 outsw(base
+ HA_RDATA
, &cp
, cplen
);
569 outb(EATA_CMD_PIO_TRUNC
, base
+ HA_WCOMMAND
);
570 for (z
= 0; z
< cppadlen
; z
++) outw(0, base
+ HA_RDATA
);
572 while (inb(base
+ HA_RSTATUS
) & HA_SBUSY
);
573 if (inb(base
+ HA_RSTATUS
) & HA_SERROR
)
575 else if (!(inb(base
+ HA_RSTATUS
) & HA_SDRQ
))
579 insw(base
+HA_RDATA
, &buff
, 127);
580 while (inb(base
+ HA_RSTATUS
)&HA_SDRQ
) inw(base
+ HA_RDATA
);
585 int get_pio_conf_PIO(u32 base
, struct get_conf
*buf
)
591 if(check_region(base
, 9))
594 memset(buf
, 0, sizeof(struct get_conf
));
596 while (inb(base
+ HA_RSTATUS
) & HA_SBUSY
)
600 DBG(DBG_PIO
&& DBG_PROBE
,
601 printk(KERN_DEBUG
"Issuing PIO READ CONFIG to HBA at %#x\n", base
));
602 eata_pio_send_command(base
, EATA_CMD_PIO_READ_CONFIG
);
605 for (p
= (ushort
*) buf
;
606 (long)p
<= ((long)buf
+ (sizeof(struct get_conf
) / 2)); p
++) {
607 while (!(inb(base
+ HA_RSTATUS
) & HA_SDRQ
))
612 *p
= inw(base
+ HA_RDATA
);
614 if (!(inb(base
+ HA_RSTATUS
) & HA_SERROR
)) { /* Error ? */
615 if (htonl(EATA_SIGNATURE
) == buf
->signature
) {
616 DBG(DBG_PIO
&&DBG_PROBE
, printk(KERN_NOTICE
"EATA Controller found "
617 "at %#4x EATA Level: %x\n", base
,
618 (uint
) (buf
->version
)));
620 while (inb(base
+ HA_RSTATUS
) & HA_SDRQ
)
621 inw(base
+ HA_RDATA
);
622 if(ALLOW_DMA_BOARDS
== FALSE
) {
623 for (z
= 0; z
< MAXISA
; z
++)
624 if (base
== ISAbases
[z
]) {
625 buf
->IRQ
= ISAirqs
[z
];
632 DBG(DBG_PROBE
, printk("eata_dma: get_conf_PIO, error during transfer "
633 "for HBA at %x\n", base
));
638 void print_pio_config(struct get_conf
*gc
)
640 printk("Please check values: (read config data)\n");
641 printk("LEN: %d ver:%d OCS:%d TAR:%d TRNXFR:%d MORES:%d\n",
642 (uint
) ntohl(gc
->len
), gc
->version
,
643 gc
->OCS_enabled
, gc
->TAR_support
, gc
->TRNXFR
, gc
->MORE_support
);
644 printk("HAAV:%d SCSIID0:%d ID1:%d ID2:%d QUEUE:%d SG:%d SEC:%d\n",
645 gc
->HAA_valid
, gc
->scsi_id
[3], gc
->scsi_id
[2],
646 gc
->scsi_id
[1], ntohs(gc
->queuesiz
), ntohs(gc
->SGsiz
), gc
->SECOND
);
647 printk("IRQ:%d IRQT:%d FORCADR:%d MCH:%d RIDQ:%d\n",
648 gc
->IRQ
, gc
->IRQ_TR
, gc
->FORCADR
,
649 gc
->MAX_CHAN
, gc
->ID_qest
);
650 DBG(DPT_DEBUG
, DELAY(14));
653 static uint
print_selftest(uint base
)
660 printk("eata_pio: executing controller self test & setup...\n");
661 while (inb(base
+ HA_RSTATUS
) & HA_SBUSY
);
662 outb(EATA_CMD_PIO_SETUPTEST
, base
+ HA_WCOMMAND
);
664 while (inb(base
+ HA_RSTATUS
) & HA_SBUSY
)
666 if (inb(base
+ HA_RSTATUS
) & HA_SDRQ
)
668 insw(base
+ HA_RDATA
, &buffer
, 256);
670 /* no beeps please... */
671 for (z
= 0; z
< 511 && buffer
[z
]; z
++)
672 if (buffer
[z
] != 7) printk("%c", buffer
[z
]);
675 } while (inb(base
+HA_RSTATUS
) & (HA_SBUSY
|HA_SDRQ
));
677 return (!(inb(base
+HA_RSTATUS
) & HA_SERROR
));
680 int register_pio_HBA(long base
, struct get_conf
*gc
, Scsi_Host_Template
* tpnt
)
686 struct Scsi_Host
*sh
;
689 DBG(DBG_REGISTER
, print_pio_config(gc
));
691 if (gc
->DMA_support
== TRUE
) {
692 printk("HBA at %#.4lx supports DMA. Please use EATA-DMA driver.\n",base
);
693 if(ALLOW_DMA_BOARDS
== FALSE
)
697 if ((buff
= get_pio_board_data((uint
)base
, gc
->IRQ
, gc
->scsi_id
[3],
698 cplen
=(htonl(gc
->cplen
)+1)/2,
699 cppadlen
=(htons(gc
->cppadlen
)+1)/2)) == NULL
)
701 printk("HBA at %#lx didn't react on INQUIRY. Sorry.\n", (ulong
) base
);
705 if (print_selftest(base
) == FALSE
&& ALLOW_DMA_BOARDS
== FALSE
)
707 printk("HBA at %#lx failed while performing self test & setup.\n",
712 if (!reg_IRQ
[gc
->IRQ
]) { /* Interrupt already registered ? */
713 if (!request_irq(gc
->IRQ
, do_eata_pio_int_handler
, SA_INTERRUPT
,
717 reg_IRQL
[gc
->IRQ
] = TRUE
; /* IRQ is edge triggered */
719 printk("Couldn't allocate IRQ %d, Sorry.\n", gc
->IRQ
);
722 } else { /* More than one HBA on this IRQ */
723 if (reg_IRQL
[gc
->IRQ
] == TRUE
) {
724 printk("Can't support more than one HBA on this IRQ,\n"
725 " if the IRQ is edge triggered. Sorry.\n");
731 request_region(base
, 8, "eata_pio");
733 size
= sizeof(hostdata
) + (sizeof(struct eata_ccb
) * ntohs(gc
->queuesiz
));
735 sh
= scsi_register(tpnt
, size
);
738 memset(hd
->ccb
, 0, (sizeof(struct eata_ccb
) * ntohs(gc
->queuesiz
)));
739 memset(hd
->reads
, 0, sizeof(ulong
) * 26);
741 strncpy(SD(sh
)->vendor
, &buff
[8], 8);
742 SD(sh
)->vendor
[8] = 0;
743 strncpy(SD(sh
)->name
, &buff
[16], 17);
744 SD(sh
)->name
[17] = 0;
745 SD(sh
)->revision
[0] = buff
[32];
746 SD(sh
)->revision
[1] = buff
[33];
747 SD(sh
)->revision
[2] = buff
[34];
748 SD(sh
)->revision
[3] = '.';
749 SD(sh
)->revision
[4] = buff
[35];
750 SD(sh
)->revision
[5] = 0;
752 switch (ntohl(gc
->len
)) {
754 SD(sh
)->EATA_revision
= 'a';
757 SD(sh
)->EATA_revision
= 'b';
760 SD(sh
)->EATA_revision
= 'c';
763 SD(sh
)->EATA_revision
= 'z';
765 SD(sh
)->EATA_revision
= '?';
768 if(ntohl(gc
->len
) >= 0x22) {
769 if (gc
->is_PCI
== TRUE
)
770 hd
->bustype
= IS_PCI
;
771 else if (gc
->is_EISA
== TRUE
)
772 hd
->bustype
= IS_EISA
;
774 hd
->bustype
= IS_ISA
;
777 hd
->bustype
= IS_PCI
;
778 else if (buff
[21] == '2')
779 hd
->bustype
= IS_EISA
;
781 hd
->bustype
= IS_ISA
;
785 SD(sh
)->cppadlen
=cppadlen
;
786 SD(sh
)->hostid
=gc
->scsi_id
[3];
787 SD(sh
)->devflags
=1<<gc
->scsi_id
[3];
788 SD(sh
)->moresupport
=gc
->MORE_support
;
789 sh
->unique_id
= base
;
790 sh
->base
= (char *) base
;
794 sh
->dma_channel
= PIO
;
795 sh
->this_id
= gc
->scsi_id
[3];
798 sh
->sg_tablesize
= SG_ALL
;
810 sh
->unchecked_isa_dma
= FALSE
; /* We can only do PIO */
812 hd
->next
= NULL
; /* build a linked list of all HBAs */
815 SD(hd
->prev
)->next
= sh
;
817 if (first_HBA
== NULL
)
823 void find_pio_ISA(struct get_conf
*buf
, Scsi_Host_Template
* tpnt
)
827 for (i
= 0; i
< MAXISA
; i
++) {
829 if (get_pio_conf_PIO(ISAbases
[i
], buf
) == TRUE
){
830 register_pio_HBA(ISAbases
[i
], buf
, tpnt
);
838 void find_pio_EISA(struct get_conf
*buf
, Scsi_Host_Template
* tpnt
)
847 for (i
= 0; i
< MAXEISA
; i
++) {
848 if (EISAbases
[i
] == TRUE
) { /* Still a possibility ? */
850 base
= 0x1c88 + (i
* 0x1000);
852 pal1
= inb((u16
)base
- 8);
853 pal2
= inb((u16
)base
- 7);
854 pal3
= inb((u16
)base
- 6);
856 if (((pal1
== 0x12) && (pal2
== 0x14)) ||
857 ((pal1
== 0x38) && (pal2
== 0xa3) && (pal3
== 0x82)) ||
858 ((pal1
== 0x06) && (pal2
== 0x94) && (pal3
== 0x24))) {
859 DBG(DBG_PROBE
, printk(KERN_NOTICE
"EISA EATA id tags found: "
861 (int)pal1
, (int)pal2
, (int)pal3
));
863 if (get_pio_conf_PIO(base
, buf
) == TRUE
) {
864 DBG(DBG_PROBE
&& DBG_EISA
, print_pio_config(buf
));
866 register_pio_HBA(base
, buf
, tpnt
);
868 printk(KERN_NOTICE
"eata_dma: No valid IRQ. HBA "
869 "removed from list\n");
871 /* Nothing found here so we take it from the list */
881 void find_pio_PCI(struct get_conf
*buf
, Scsi_Host_Template
* tpnt
)
884 printk("eata_dma: kernel PCI support not enabled. Skipping scan for PCI HBAs.\n");
889 for(dev
=NULL
; dev
= pci_find_device(PCI_VENDOR_ID_DPT
, PCI_DEVICE_ID_DPT
, dev
);) {
890 DBG(DBG_PROBE
&& DBG_PCI
,
891 printk("eata_pio: find_PCI, HBA at %s\n", dev
->name
));
893 base
= dev
->resource
[0].flags
;
894 if (!(base
& PCI_BASE_ADDRESS_SPACE_IO
)) {
895 printk("eata_pio: invalid base address of device %s\n", dev
->name
);
898 base
= dev
->resource
[0].start
;
899 /* EISA tag there ? */
900 if ((inb(base
) == 0x12) && (inb(base
+ 1) == 0x14))
901 continue; /* Jep, it's forced, so move on */
902 base
+= 0x10; /* Now, THIS is the real address */
904 /* We didn't find it in the primary search */
905 if (get_pio_conf_PIO(base
, buf
) == TRUE
) {
906 if (buf
->FORCADR
) /* If the address is forced */
907 continue; /* we'll find it later */
909 /* OK. We made it till here, so we can go now
910 * and register it. We only have to check and
911 * eventually remove it from the EISA and ISA list
914 register_pio_HBA(base
, buf
, tpnt
);
917 for (x
= 0; x
< MAXISA
; ++x
) {
918 if (ISAbases
[x
] == base
) {
923 } else if ((base
& 0x0fff) == 0x0c88) {
924 x
= (base
>> 12) & 0x0f;
929 else if (check_blink_state(base
) == TRUE
) {
930 printk("eata_pio: HBA is in BLINK state.\n"
931 "Consult your HBAs manual to correct this.\n");
936 #endif /* #ifndef CONFIG_PCI */
940 int eata_pio_detect(Scsi_Host_Template
* tpnt
)
942 struct Scsi_Host
*HBA_ptr
;
946 DBG((DBG_PROBE
&& DBG_DELAY
) || DPT_DEBUG
,
947 printk("Using lots of delays to let you read the debugging output\n"));
949 tpnt
->proc_dir
= &proc_scsi_eata_pio
;
951 find_pio_PCI(&gc
, tpnt
);
953 find_pio_EISA(&gc
, tpnt
);
955 find_pio_ISA(&gc
, tpnt
);
957 for (i
= 0; i
<= MAXIRQ
; i
++)
959 request_irq(i
, do_eata_pio_int_handler
, SA_INTERRUPT
, "EATA-PIO", NULL
);
963 if (registered_HBAs
!= 0) {
964 printk("EATA (Extended Attachment) PIO driver version: %d.%d%s\n"
965 "(c) 1993-95 Michael Neuffer, neuffer@goofy.zdv.uni-mainz.de\n"
966 " Alfred Arnold, a.arnold@kfa-juelich.de\n"
967 "This release only supports DASD devices (harddisks)\n",
968 VER_MAJOR
, VER_MINOR
, VER_SUB
);
970 printk("Registered HBAs:\n");
971 printk("HBA no. Boardtype: Revis: EATA: Bus: BaseIO: IRQ: Ch: ID: Pr:"
973 for (i
= 1; i
<= registered_HBAs
; i
++) {
974 printk("scsi%-2d: %.10s v%s 2.0%c %s %#.4x %2d %d %d %c"
976 HBA_ptr
->host_no
, SD(HBA_ptr
)->name
, SD(HBA_ptr
)->revision
,
977 SD(HBA_ptr
)->EATA_revision
, (SD(HBA_ptr
)->bustype
== 'P')?
978 "PCI ":(SD(HBA_ptr
)->bustype
== 'E')?"EISA":"ISA ",
979 (uint
) HBA_ptr
->base
, HBA_ptr
->irq
, SD(HBA_ptr
)->channel
,
980 HBA_ptr
->this_id
, (SD(HBA_ptr
)->primary
== TRUE
)?'Y':'N',
981 HBA_ptr
->can_queue
, HBA_ptr
->sg_tablesize
,
982 HBA_ptr
->cmd_per_lun
);
983 HBA_ptr
= SD(HBA_ptr
)->next
;
986 DBG(DPT_DEBUG
,DELAY(12));
988 return (registered_HBAs
);
992 /* Eventually this will go into an include file, but this will be later */
993 Scsi_Host_Template driver_template
= EATA_PIO
;
995 #include "scsi_module.c"
999 * Overrides for Emacs so that we almost follow Linus's tabbing style.
1000 * Emacs will notice this stuff at the end of the file and automatically
1001 * adjust the settings for this buffer only. This must remain at the end
1003 * ---------------------------------------------------------------------------
1006 * c-brace-imaginary-offset: 0
1007 * c-brace-offset: -4
1008 * c-argdecl-indent: 4
1009 * c-label-offset: -4
1010 * c-continued-statement-offset: 4
1011 * c-continued-brace-offset: 0
1012 * indent-tabs-mode: nil