- pre4:
[davej-history.git] / drivers / scsi / eata_pio.c
blobb276f86293f0bb642bac41c12c8fbffa80ec9814
1 /************************************************************
2 * *
3 * Linux EATA SCSI PIO driver *
4 * *
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. *
8 * *
9 * The driver currently: *
10 * -supports all EATA-PIO boards *
11 * -only supports DASD devices *
12 * *
13 * (c)1993-96 Michael Neuffer, Alfred Arnold *
14 * neuffer@goofy.zdv.uni-mainz.de *
15 * a.arnold@kfa-juelich.de *
16 * *
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. *
22 * *
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 *
27 * for more details. *
28 * *
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. *
33 * *
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>
47 #include <linux/in.h>
48 #include <linux/pci.h>
49 #include <linux/proc_fs.h>
50 #include <asm/io.h>
51 #include "eata_pio.h"
52 #include "eata_dma_proc.h"
53 #include "scsi.h"
54 #include "sd.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 static uint ISAbases[MAXISA] =
62 {0x1F0, 0x170, 0x330, 0x230};
63 static uint ISAirqs[MAXISA] =
64 {14,12,15,11};
65 static unchar EISAbases[] =
66 {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
67 static uint registered_HBAs = 0;
68 static struct Scsi_Host *last_HBA = NULL;
69 static struct Scsi_Host *first_HBA = NULL;
70 static unchar reg_IRQ[] =
71 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
72 static unchar reg_IRQL[] =
73 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
75 static ulong int_counter = 0;
76 static ulong queue_counter = 0;
78 #include "eata_pio_proc.c"
80 #ifdef MODULE
81 int eata_pio_release(struct Scsi_Host *sh)
83 if (sh->irq && reg_IRQ[sh->irq] == 1) free_irq(sh->irq, NULL);
84 else reg_IRQ[sh->irq]--;
85 if (SD(sh)->channel == 0) {
86 if (sh->io_port && sh->n_io_port)
87 release_region(sh->io_port, sh->n_io_port);
89 return(TRUE);
91 #endif
93 void IncStat(Scsi_Pointer *SCp, uint Increment)
95 SCp->ptr+=Increment;
96 if ((SCp->this_residual-=Increment)==0)
98 if ((--SCp->buffers_residual)==0) SCp->Status=FALSE;
99 else
101 SCp->buffer++;
102 SCp->ptr=SCp->buffer->address;
103 SCp->this_residual=SCp->buffer->length;
108 void eata_pio_int_handler(int irq, void *dev_id, struct pt_regs * regs);
110 void do_eata_pio_int_handler(int irq, void *dev_id, struct pt_regs * regs)
112 unsigned long flags;
114 spin_lock_irqsave(&io_request_lock, flags);
115 eata_pio_int_handler(irq, dev_id, regs);
116 spin_unlock_irqrestore(&io_request_lock, flags);
119 void eata_pio_int_handler(int irq, void *dev_id, struct pt_regs * regs)
121 uint eata_stat = 0xfffff;
122 Scsi_Cmnd *cmd;
123 hostdata *hd;
124 struct eata_ccb *cp;
125 uint base;
126 ulong flags;
127 uint x,z;
128 struct Scsi_Host *sh;
129 ushort zwickel=0;
130 unchar stat,odd;
132 save_flags(flags);
133 cli();
135 for (x = 1, sh = first_HBA; x <= registered_HBAs; x++, sh = SD(sh)->prev) {
136 if (sh->irq != irq)
137 continue;
138 if (inb((uint)sh->base + HA_RSTATUS) & HA_SBUSY)
139 continue;
141 int_counter++;
143 hd=SD(sh);
145 cp = &hd->ccb[0];
146 cmd = cp->cmd;
147 base = (uint) cmd->host->base;
151 stat=inb(base+HA_RSTATUS);
152 if (stat&HA_SDRQ) {
153 if (cp->DataIn)
155 z=256; odd=FALSE;
156 while ((cmd->SCp.Status)&&((z>0)||(odd)))
158 if (odd)
160 *(cmd->SCp.ptr)=zwickel>>8;
161 IncStat(&cmd->SCp,1);
162 odd=FALSE;
164 x=min(z,cmd->SCp.this_residual/2);
165 insw(base+HA_RDATA,cmd->SCp.ptr,x);
166 z-=x;
167 IncStat(&cmd->SCp,2*x);
168 if ((z>0)&&(cmd->SCp.this_residual==1))
170 zwickel=inw(base+HA_RDATA);
171 *(cmd->SCp.ptr)=zwickel&0xff;
172 IncStat(&cmd->SCp,1); z--;
173 odd=TRUE;
176 while (z>0) {
177 zwickel=inw(base+HA_RDATA);
178 z--;
181 else /* cp->DataOut */
183 odd=FALSE; z=256;
184 while ((cmd->SCp.Status)&&((z>0)||(odd)))
186 if (odd)
188 zwickel+=*(cmd->SCp.ptr)<<8;
189 IncStat(&cmd->SCp,1);
190 outw(zwickel,base+HA_RDATA);
191 z--;
192 odd=FALSE;
194 x=min(z,cmd->SCp.this_residual/2);
195 outsw(base+HA_RDATA,cmd->SCp.ptr,x);
196 z-=x;
197 IncStat(&cmd->SCp,2*x);
198 if ((z>0)&&(cmd->SCp.this_residual==1))
200 zwickel=*(cmd->SCp.ptr);
201 zwickel&=0xff;
202 IncStat(&cmd->SCp,1);
203 odd=TRUE;
206 while (z>0||odd) {
207 outw(zwickel,base+HA_RDATA);
208 z--;
209 odd=FALSE;
214 while ((stat&HA_SDRQ)||((stat&HA_SMORE)&&hd->moresupport));
216 /* terminate handler if HBA goes busy again, i.e. transfers
217 * more data */
219 if (stat&HA_SBUSY) break;
221 /* OK, this is quite stupid, but I haven't found any correct
222 * way to get HBA&SCSI status so far */
224 if (!(inb(base+HA_RSTATUS)&HA_SERROR))
226 cmd->result=(DID_OK<<16);
227 hd->devflags|=(1<<cp->cp_id);
229 else if (hd->devflags&1<<cp->cp_id)
230 cmd->result=(DID_OK<<16)+0x02;
231 else cmd->result=(DID_NO_CONNECT<<16);
233 if (cp->status == LOCKED) {
234 cp->status = FREE;
235 eata_stat = inb(base + HA_RSTATUS);
236 printk(KERN_NOTICE "eata_pio: int_handler, freeing locked "
237 "queueslot\n");
238 DBG(DBG_INTR&&DBG_DELAY,DELAY(1));
239 restore_flags(flags);
240 return;
243 #if DBG_INTR2
244 if (stat != 0x50)
245 printk(KERN_DEBUG "stat: %#.2x, result: %#.8x\n", stat,
246 cmd->result);
247 DBG(DBG_INTR&&DBG_DELAY,DELAY(1));
248 #endif
250 cp->status = FREE; /* now we can release the slot */
252 restore_flags(flags);
253 cmd->scsi_done(cmd);
254 save_flags(flags);
255 cli();
257 restore_flags(flags);
259 return;
262 inline uint eata_pio_send_command(uint base, unchar command)
264 uint loop = HZ/2;
266 while (inb(base + HA_RSTATUS) & HA_SBUSY)
267 if (--loop == 0)
268 return(TRUE);
270 /* Enable interrupts for HBA. It is not the best way to do it at this
271 * place, but I hope that it doesn't interfere with the IDE driver
272 * initialization this way */
274 outb(HA_CTRL_8HEADS,base+HA_CTRLREG);
276 outb(command, base + HA_WCOMMAND);
277 return(FALSE);
280 int eata_pio_queue(Scsi_Cmnd * cmd, void (*done) (Scsi_Cmnd *))
282 uint x, y;
283 long flags;
284 uint base;
286 hostdata *hd;
287 struct Scsi_Host *sh;
288 struct eata_ccb *cp;
290 save_flags(flags);
291 cli();
293 queue_counter++;
295 hd = HD(cmd);
296 sh = cmd->host;
297 base = (uint) sh->base;
299 /* use only slot 0, as 2001 can handle only one cmd at a time */
301 y = x = 0;
303 if (hd->ccb[y].status!=FREE) {
305 DBG(DBG_QUEUE, printk(KERN_EMERG "can_queue %d, x %d, y %d\n",
306 sh->can_queue,x,y));
307 #if DEBUG_EATA
308 panic(KERN_EMERG "eata_pio: run out of queue slots cmdno:%ld "
309 "intrno: %ld\n", queue_counter, int_counter);
310 #else
311 panic(KERN_EMERG "eata_pio: run out of queue slots....\n");
312 #endif
315 cp = &hd->ccb[y];
317 memset(cp, 0, sizeof(struct eata_ccb));
318 memset(cmd->sense_buffer, 0, sizeof(cmd->sense_buffer));
320 cp->status = USED; /* claim free slot */
322 DBG(DBG_QUEUE, printk(KERN_DEBUG "eata_pio_queue pid %ld, target: %x, lun:"
323 " %x, y %d\n", cmd->pid, cmd->target, cmd->lun, y));
324 DBG(DBG_QUEUE && DBG_DELAY, DELAY(1));
326 cmd->scsi_done = (void *)done;
328 switch (cmd->cmnd[0]) {
329 case CHANGE_DEFINITION: case COMPARE: case COPY:
330 case COPY_VERIFY: case LOG_SELECT: case MODE_SELECT:
331 case MODE_SELECT_10: case SEND_DIAGNOSTIC: case WRITE_BUFFER:
332 case FORMAT_UNIT: case REASSIGN_BLOCKS: case RESERVE:
333 case SEARCH_EQUAL: case SEARCH_HIGH: case SEARCH_LOW:
334 case WRITE_6: case WRITE_10: case WRITE_VERIFY:
335 case UPDATE_BLOCK: case WRITE_LONG: case WRITE_SAME:
336 case SEARCH_HIGH_12: case SEARCH_EQUAL_12: case SEARCH_LOW_12:
337 case WRITE_12: case WRITE_VERIFY_12: case SET_WINDOW:
338 case MEDIUM_SCAN: case SEND_VOLUME_TAG:
339 case 0xea: /* alternate number for WRITE LONG */
340 cp->DataOut = TRUE; /* Output mode */
341 break;
342 case TEST_UNIT_READY:
343 default:
344 cp->DataIn = TRUE; /* Input mode */
347 cp->Interpret = (cmd->target == hd->hostid);
348 cp->cp_datalen = htonl((ulong)cmd->request_bufflen);
349 cp->Auto_Req_Sen = FALSE;
350 cp->cp_reqDMA = htonl(0);
351 cp->reqlen = 0;
353 cp->cp_id = cmd->target;
354 cp->cp_lun = cmd->lun;
355 cp->cp_dispri = FALSE;
356 cp->cp_identify = TRUE;
357 memcpy(cp->cp_cdb, cmd->cmnd, COMMAND_SIZE(*cmd->cmnd));
359 cp->cp_statDMA = htonl(0);
361 cp->cp_viraddr = cp;
362 cp->cmd = cmd;
363 cmd->host_scribble = (char *)&hd->ccb[y];
365 if (cmd->use_sg == 0)
367 cmd->SCp.buffers_residual=1;
368 cmd->SCp.ptr = cmd->request_buffer;
369 cmd->SCp.this_residual = cmd->request_bufflen;
370 cmd->SCp.buffer = NULL;
371 } else {
372 cmd->SCp.buffer = cmd->request_buffer;
373 cmd->SCp.buffers_residual = cmd->use_sg;
374 cmd->SCp.ptr = cmd->SCp.buffer->address;
375 cmd->SCp.this_residual = cmd->SCp.buffer->length;
377 cmd->SCp.Status = (cmd->SCp.this_residual != 0); /* TRUE as long as bytes
378 * are to transfer */
380 if (eata_pio_send_command(base, EATA_CMD_PIO_SEND_CP))
382 cmd->result = DID_BUS_BUSY << 16;
383 printk(KERN_NOTICE "eata_pio_queue target %d, pid %ld, HBA busy, "
384 "returning DID_BUS_BUSY, done.\n", cmd->target, cmd->pid);
385 done(cmd);
386 cp->status = FREE;
387 restore_flags(flags);
388 return (0);
390 while (!(inb(base + HA_RSTATUS) & HA_SDRQ));
391 outsw(base + HA_RDATA, cp, hd->cplen);
392 outb(EATA_CMD_PIO_TRUNC, base + HA_WCOMMAND);
393 for (x = 0; x < hd->cppadlen; x++) outw(0, base + HA_RDATA);
395 DBG(DBG_QUEUE,printk(KERN_DEBUG "Queued base %#.4lx pid: %ld target: %x "
396 "lun: %x slot %d irq %d\n", (long)sh->base, cmd->pid,
397 cmd->target, cmd->lun, y, sh->irq));
398 DBG(DBG_QUEUE && DBG_DELAY, DELAY(1));
400 restore_flags(flags);
401 return (0);
404 int eata_pio_abort(Scsi_Cmnd * cmd)
406 ulong flags;
407 uint loop = HZ;
409 save_flags(flags);
410 cli();
412 DBG(DBG_ABNORM, printk(KERN_WARNING "eata_pio_abort called pid: %ld "
413 "target: %x lun: %x reason %x\n", cmd->pid,
414 cmd->target, cmd->lun, cmd->abort_reason));
415 DBG(DBG_ABNORM && DBG_DELAY, DELAY(1));
418 while (inb((uint)(cmd->host->base) + HA_RAUXSTAT) & HA_ABUSY)
419 if (--loop == 0) {
420 printk(KERN_WARNING "eata_pio: abort, timeout error.\n");
421 restore_flags(flags);
422 DBG(DBG_ABNORM && DBG_DELAY, DELAY(1));
423 return (SCSI_ABORT_ERROR);
425 if (CD(cmd)->status == FREE) {
426 DBG(DBG_ABNORM, printk(KERN_WARNING "Returning: SCSI_ABORT_NOT_RUNNING\n"));
427 restore_flags(flags);
428 return (SCSI_ABORT_NOT_RUNNING);
430 if (CD(cmd)->status == USED) {
431 DBG(DBG_ABNORM, printk(KERN_WARNING "Returning: SCSI_ABORT_BUSY\n"));
432 restore_flags(flags);
433 return (SCSI_ABORT_BUSY); /* SNOOZE */
435 if (CD(cmd)->status == RESET) {
436 restore_flags(flags);
437 printk(KERN_WARNING "eata_pio: abort, command reset error.\n");
438 DBG(DBG_ABNORM && DBG_DELAY, DELAY(1));
439 return (SCSI_ABORT_ERROR);
441 if (CD(cmd)->status == LOCKED) {
442 restore_flags(flags);
443 DBG(DBG_ABNORM, printk(KERN_WARNING "eata_pio: abort, queue slot "
444 "locked.\n"));
445 DBG(DBG_ABNORM && DBG_DELAY, DELAY(1));
446 return (SCSI_ABORT_NOT_RUNNING);
448 restore_flags(flags);
449 panic("eata_pio: abort: invalid slot status\n");
452 int eata_pio_reset(Scsi_Cmnd * cmd, unsigned int dummy)
454 uint x, time, limit = 0;
455 ulong flags;
456 unchar success = FALSE;
457 Scsi_Cmnd *sp;
459 save_flags(flags);
460 cli();
461 DBG(DBG_ABNORM, printk(KERN_WARNING "eata_pio_reset called pid:%ld target:"
462 " %x lun: %x reason %x\n", cmd->pid, cmd->target,
463 cmd->lun, cmd->abort_reason));
465 if (HD(cmd)->state == RESET) {
466 printk(KERN_WARNING "eata_pio_reset: exit, already in reset.\n");
467 restore_flags(flags);
468 DBG(DBG_ABNORM && DBG_DELAY, DELAY(1));
469 return (SCSI_RESET_ERROR);
472 /* force all slots to be free */
474 for (x = 0; x < cmd->host->can_queue; x++) {
476 if (HD(cmd)->ccb[x].status == FREE)
477 continue;
479 sp = HD(cmd)->ccb[x].cmd;
480 HD(cmd)->ccb[x].status = RESET;
481 printk(KERN_WARNING "eata_pio_reset: slot %d in reset, pid %ld.\n", x,
482 sp->pid);
483 DBG(DBG_ABNORM && DBG_DELAY, DELAY(1));
485 if (sp == NULL)
486 panic("eata_pio_reset: slot %d, sp==NULL.\n", x);
487 DBG(DBG_ABNORM && DBG_DELAY, DELAY(1));
490 /* hard reset the HBA */
491 outb(EATA_CMD_RESET, (uint) cmd->host->base+HA_WCOMMAND);
493 DBG(DBG_ABNORM, printk(KERN_WARNING "eata_pio_reset: board reset done.\n"));
494 HD(cmd)->state = RESET;
496 time = jiffies;
497 while (time_before(jiffies, time + 3 * HZ) && limit++ < 10000000);
499 DBG(DBG_ABNORM, printk(KERN_WARNING "eata_pio_reset: interrupts disabled, "
500 "loops %d.\n", limit));
501 DBG(DBG_ABNORM && DBG_DELAY, DELAY(1));
503 for (x = 0; x < cmd->host->can_queue; x++) {
505 /* Skip slots already set free by interrupt */
506 if (HD(cmd)->ccb[x].status != RESET)
507 continue;
509 sp = HD(cmd)->ccb[x].cmd;
510 sp->result = DID_RESET << 16;
512 /* This mailbox is terminated */
513 printk(KERN_WARNING "eata_pio_reset: reset ccb %d.\n",x);
514 HD(cmd)->ccb[x].status = FREE;
516 restore_flags(flags);
517 sp->scsi_done(sp);
518 cli();
521 HD(cmd)->state = FALSE;
522 restore_flags(flags);
524 if (success) { /* hmmm... */
525 DBG(DBG_ABNORM, printk(KERN_WARNING "eata_pio_reset: exit, success.\n"));
526 DBG(DBG_ABNORM && DBG_DELAY, DELAY(1));
527 return (SCSI_RESET_SUCCESS);
528 } else {
529 DBG(DBG_ABNORM, printk(KERN_WARNING "eata_pio_reset: exit, wakeup.\n"));
530 DBG(DBG_ABNORM && DBG_DELAY, DELAY(1));
531 return (SCSI_RESET_PUNT);
535 char * get_pio_board_data(ulong base, uint irq, uint id, ulong cplen, ushort cppadlen)
537 struct eata_ccb cp;
538 static char buff[256];
539 int z;
541 memset(&cp, 0, sizeof(struct eata_ccb));
542 memset(buff, 0, sizeof(buff));
544 cp.DataIn = TRUE;
545 cp.Interpret = TRUE; /* Interpret command */
547 cp.cp_datalen = htonl(254);
548 cp.cp_dataDMA = htonl(0);
550 cp.cp_id = id;
551 cp.cp_lun = 0;
553 cp.cp_cdb[0] = INQUIRY;
554 cp.cp_cdb[1] = 0;
555 cp.cp_cdb[2] = 0;
556 cp.cp_cdb[3] = 0;
557 cp.cp_cdb[4] = 254;
558 cp.cp_cdb[5] = 0;
560 if (eata_pio_send_command((uint) base, EATA_CMD_PIO_SEND_CP))
561 return (NULL);
562 while (!(inb(base + HA_RSTATUS) & HA_SDRQ));
563 outsw(base + HA_RDATA, &cp, cplen);
564 outb(EATA_CMD_PIO_TRUNC, base + HA_WCOMMAND);
565 for (z = 0; z < cppadlen; z++) outw(0, base + HA_RDATA);
567 while (inb(base + HA_RSTATUS) & HA_SBUSY);
568 if (inb(base + HA_RSTATUS) & HA_SERROR)
569 return (NULL);
570 else if (!(inb(base + HA_RSTATUS) & HA_SDRQ))
571 return (NULL);
572 else
574 insw(base+HA_RDATA, &buff, 127);
575 while (inb(base + HA_RSTATUS)&HA_SDRQ) inw(base + HA_RDATA);
576 return (buff);
580 int get_pio_conf_PIO(u32 base, struct get_conf *buf)
582 ulong loop = HZ/2;
583 int z;
584 ushort *p;
586 if(check_region(base, 9))
587 return (FALSE);
589 memset(buf, 0, sizeof(struct get_conf));
591 while (inb(base + HA_RSTATUS) & HA_SBUSY)
592 if (--loop == 0)
593 return (FALSE);
595 DBG(DBG_PIO && DBG_PROBE,
596 printk(KERN_DEBUG "Issuing PIO READ CONFIG to HBA at %#x\n", base));
597 eata_pio_send_command(base, EATA_CMD_PIO_READ_CONFIG);
599 loop = HZ/2;
600 for (p = (ushort *) buf;
601 (long)p <= ((long)buf + (sizeof(struct get_conf) / 2)); p++) {
602 while (!(inb(base + HA_RSTATUS) & HA_SDRQ))
603 if (--loop == 0)
604 return (FALSE);
606 loop = HZ/2;
607 *p = inw(base + HA_RDATA);
609 if (!(inb(base + HA_RSTATUS) & HA_SERROR)) { /* Error ? */
610 if (htonl(EATA_SIGNATURE) == buf->signature) {
611 DBG(DBG_PIO&&DBG_PROBE, printk(KERN_NOTICE "EATA Controller found "
612 "at %#4x EATA Level: %x\n", base,
613 (uint) (buf->version)));
615 while (inb(base + HA_RSTATUS) & HA_SDRQ)
616 inw(base + HA_RDATA);
617 if(ALLOW_DMA_BOARDS == FALSE) {
618 for (z = 0; z < MAXISA; z++)
619 if (base == ISAbases[z]) {
620 buf->IRQ = ISAirqs[z];
621 break;
624 return (TRUE);
626 } else {
627 DBG(DBG_PROBE, printk("eata_dma: get_conf_PIO, error during transfer "
628 "for HBA at %x\n", base));
630 return (FALSE);
633 void print_pio_config(struct get_conf *gc)
635 printk("Please check values: (read config data)\n");
636 printk("LEN: %d ver:%d OCS:%d TAR:%d TRNXFR:%d MORES:%d\n",
637 (uint) ntohl(gc->len), gc->version,
638 gc->OCS_enabled, gc->TAR_support, gc->TRNXFR, gc->MORE_support);
639 printk("HAAV:%d SCSIID0:%d ID1:%d ID2:%d QUEUE:%d SG:%d SEC:%d\n",
640 gc->HAA_valid, gc->scsi_id[3], gc->scsi_id[2],
641 gc->scsi_id[1], ntohs(gc->queuesiz), ntohs(gc->SGsiz), gc->SECOND);
642 printk("IRQ:%d IRQT:%d FORCADR:%d MCH:%d RIDQ:%d\n",
643 gc->IRQ, gc->IRQ_TR, gc->FORCADR,
644 gc->MAX_CHAN, gc->ID_qest);
645 DBG(DPT_DEBUG, DELAY(14));
648 static uint print_selftest(uint base)
650 unchar buffer[512];
651 #ifdef VERBOSE_SETUP
652 int z;
653 #endif
655 printk("eata_pio: executing controller self test & setup...\n");
656 while (inb(base + HA_RSTATUS) & HA_SBUSY);
657 outb(EATA_CMD_PIO_SETUPTEST, base + HA_WCOMMAND);
658 do {
659 while (inb(base + HA_RSTATUS) & HA_SBUSY)
660 /* nothing */ ;
661 if (inb(base + HA_RSTATUS) & HA_SDRQ)
663 insw(base + HA_RDATA, &buffer, 256);
664 #ifdef VERBOSE_SETUP
665 /* no beeps please... */
666 for (z = 0; z < 511 && buffer[z]; z++)
667 if (buffer[z] != 7) printk("%c", buffer[z]);
668 #endif
670 } while (inb(base+HA_RSTATUS) & (HA_SBUSY|HA_SDRQ));
672 return (!(inb(base+HA_RSTATUS) & HA_SERROR));
675 int register_pio_HBA(long base, struct get_conf *gc, Scsi_Host_Template * tpnt)
677 ulong size = 0;
678 char *buff;
679 ulong cplen;
680 ushort cppadlen;
681 struct Scsi_Host *sh;
682 hostdata *hd;
684 DBG(DBG_REGISTER, print_pio_config(gc));
686 if (gc->DMA_support == TRUE) {
687 printk("HBA at %#.4lx supports DMA. Please use EATA-DMA driver.\n",base);
688 if(ALLOW_DMA_BOARDS == FALSE)
689 return (FALSE);
692 if ((buff = get_pio_board_data((uint)base, gc->IRQ, gc->scsi_id[3],
693 cplen =(htonl(gc->cplen )+1)/2,
694 cppadlen=(htons(gc->cppadlen)+1)/2)) == NULL)
696 printk("HBA at %#lx didn't react on INQUIRY. Sorry.\n", (ulong) base);
697 return (FALSE);
700 if (print_selftest(base) == FALSE && ALLOW_DMA_BOARDS == FALSE)
702 printk("HBA at %#lx failed while performing self test & setup.\n",
703 (ulong) base);
704 return (FALSE);
707 if (!reg_IRQ[gc->IRQ]) { /* Interrupt already registered ? */
708 if (!request_irq(gc->IRQ, do_eata_pio_int_handler, SA_INTERRUPT,
709 "EATA-PIO", NULL)){
710 reg_IRQ[gc->IRQ]++;
711 if (!gc->IRQ_TR)
712 reg_IRQL[gc->IRQ] = TRUE; /* IRQ is edge triggered */
713 } else {
714 printk("Couldn't allocate IRQ %d, Sorry.\n", gc->IRQ);
715 return (FALSE);
717 } else { /* More than one HBA on this IRQ */
718 if (reg_IRQL[gc->IRQ] == TRUE) {
719 printk("Can't support more than one HBA on this IRQ,\n"
720 " if the IRQ is edge triggered. Sorry.\n");
721 return (FALSE);
722 } else
723 reg_IRQ[gc->IRQ]++;
726 request_region(base, 8, "eata_pio");
728 size = sizeof(hostdata) + (sizeof(struct eata_ccb) * ntohs(gc->queuesiz));
730 sh = scsi_register(tpnt, size);
731 hd = SD(sh);
733 memset(hd->ccb, 0, (sizeof(struct eata_ccb) * ntohs(gc->queuesiz)));
734 memset(hd->reads, 0, sizeof(ulong) * 26);
736 strncpy(SD(sh)->vendor, &buff[8], 8);
737 SD(sh)->vendor[8] = 0;
738 strncpy(SD(sh)->name, &buff[16], 17);
739 SD(sh)->name[17] = 0;
740 SD(sh)->revision[0] = buff[32];
741 SD(sh)->revision[1] = buff[33];
742 SD(sh)->revision[2] = buff[34];
743 SD(sh)->revision[3] = '.';
744 SD(sh)->revision[4] = buff[35];
745 SD(sh)->revision[5] = 0;
747 switch (ntohl(gc->len)) {
748 case 0x1c:
749 SD(sh)->EATA_revision = 'a';
750 break;
751 case 0x1e:
752 SD(sh)->EATA_revision = 'b';
753 break;
754 case 0x22:
755 SD(sh)->EATA_revision = 'c';
756 break;
757 case 0x24:
758 SD(sh)->EATA_revision = 'z';
759 default:
760 SD(sh)->EATA_revision = '?';
763 if(ntohl(gc->len) >= 0x22) {
764 if (gc->is_PCI == TRUE)
765 hd->bustype = IS_PCI;
766 else if (gc->is_EISA == TRUE)
767 hd->bustype = IS_EISA;
768 else
769 hd->bustype = IS_ISA;
770 } else {
771 if (buff[21] == '4')
772 hd->bustype = IS_PCI;
773 else if (buff[21] == '2')
774 hd->bustype = IS_EISA;
775 else
776 hd->bustype = IS_ISA;
779 SD(sh)->cplen=cplen;
780 SD(sh)->cppadlen=cppadlen;
781 SD(sh)->hostid=gc->scsi_id[3];
782 SD(sh)->devflags=1<<gc->scsi_id[3];
783 SD(sh)->moresupport=gc->MORE_support;
784 sh->unique_id = base;
785 sh->base = base;
786 sh->io_port = base;
787 sh->n_io_port = 8;
788 sh->irq = gc->IRQ;
789 sh->dma_channel = PIO;
790 sh->this_id = gc->scsi_id[3];
791 sh->can_queue = 1;
792 sh->cmd_per_lun = 1;
793 sh->sg_tablesize = SG_ALL;
795 hd->channel = 0;
797 sh->max_id = 8;
798 sh->max_lun = 8;
800 if (gc->SECOND)
801 hd->primary = FALSE;
802 else
803 hd->primary = TRUE;
805 sh->unchecked_isa_dma = FALSE; /* We can only do PIO */
807 hd->next = NULL; /* build a linked list of all HBAs */
808 hd->prev = last_HBA;
809 if(hd->prev != NULL)
810 SD(hd->prev)->next = sh;
811 last_HBA = sh;
812 if (first_HBA == NULL)
813 first_HBA = sh;
814 registered_HBAs++;
815 return (1);
818 void find_pio_ISA(struct get_conf *buf, Scsi_Host_Template * tpnt)
820 int i;
822 for (i = 0; i < MAXISA; i++) {
823 if (ISAbases[i]) {
824 if (get_pio_conf_PIO(ISAbases[i], buf) == TRUE){
825 register_pio_HBA(ISAbases[i], buf, tpnt);
827 ISAbases[i] = 0;
830 return;
833 void find_pio_EISA(struct get_conf *buf, Scsi_Host_Template * tpnt)
835 u32 base;
836 int i;
838 #if CHECKPAL
839 u8 pal1, pal2, pal3;
840 #endif
842 for (i = 0; i < MAXEISA; i++) {
843 if (EISAbases[i] == TRUE) { /* Still a possibility ? */
845 base = 0x1c88 + (i * 0x1000);
846 #if CHECKPAL
847 pal1 = inb((u16)base - 8);
848 pal2 = inb((u16)base - 7);
849 pal3 = inb((u16)base - 6);
851 if (((pal1 == 0x12) && (pal2 == 0x14)) ||
852 ((pal1 == 0x38) && (pal2 == 0xa3) && (pal3 == 0x82)) ||
853 ((pal1 == 0x06) && (pal2 == 0x94) && (pal3 == 0x24))) {
854 DBG(DBG_PROBE, printk(KERN_NOTICE "EISA EATA id tags found: "
855 "%x %x %x \n",
856 (int)pal1, (int)pal2, (int)pal3));
857 #endif
858 if (get_pio_conf_PIO(base, buf) == TRUE) {
859 DBG(DBG_PROBE && DBG_EISA, print_pio_config(buf));
860 if (buf->IRQ) {
861 register_pio_HBA(base, buf, tpnt);
862 } else
863 printk(KERN_NOTICE "eata_dma: No valid IRQ. HBA "
864 "removed from list\n");
866 /* Nothing found here so we take it from the list */
867 EISAbases[i] = 0;
868 #if CHECKPAL
870 #endif
873 return;
876 void find_pio_PCI(struct get_conf *buf, Scsi_Host_Template * tpnt)
878 #ifndef CONFIG_PCI
879 printk("eata_dma: kernel PCI support not enabled. Skipping scan for PCI HBAs.\n");
880 #else
881 struct pci_dev *dev = NULL;
882 u32 base, x;
884 while ((dev = pci_find_device(PCI_VENDOR_ID_DPT, PCI_DEVICE_ID_DPT, dev)) != NULL) {
885 DBG(DBG_PROBE && DBG_PCI,
886 printk("eata_pio: find_PCI, HBA at %s\n", dev->name));
887 if (pci_enable_device(dev))
888 continue;
889 pci_set_master(dev);
890 base = pci_resource_flags(dev, 0);
891 if (base & IORESOURCE_MEM) {
892 printk("eata_pio: invalid base address of device %s\n", dev->name);
893 continue;
895 base = pci_resource_start(dev, 0);
896 /* EISA tag there ? */
897 if ((inb(base) == 0x12) && (inb(base + 1) == 0x14))
898 continue; /* Jep, it's forced, so move on */
899 base += 0x10; /* Now, THIS is the real address */
900 if (base != 0x1f8) {
901 /* We didn't find it in the primary search */
902 if (get_pio_conf_PIO(base, buf) == TRUE) {
903 if (buf->FORCADR) /* If the address is forced */
904 continue; /* we'll find it later */
906 /* OK. We made it till here, so we can go now
907 * and register it. We only have to check and
908 * eventually remove it from the EISA and ISA list
911 register_pio_HBA(base, buf, tpnt);
913 if (base < 0x1000) {
914 for (x = 0; x < MAXISA; ++x) {
915 if (ISAbases[x] == base) {
916 ISAbases[x] = 0;
917 break;
920 } else if ((base & 0x0fff) == 0x0c88) {
921 x = (base >> 12) & 0x0f;
922 EISAbases[x] = 0;
925 #if CHECK_BLINK
926 else if (check_blink_state(base) == TRUE) {
927 printk("eata_pio: HBA is in BLINK state.\n"
928 "Consult your HBAs manual to correct this.\n");
930 #endif
933 #endif /* #ifndef CONFIG_PCI */
937 int eata_pio_detect(Scsi_Host_Template * tpnt)
939 struct Scsi_Host *HBA_ptr;
940 struct get_conf gc;
941 int i;
943 DBG((DBG_PROBE && DBG_DELAY) || DPT_DEBUG,
944 printk("Using lots of delays to let you read the debugging output\n"));
946 tpnt->proc_name = "eata_pio";
948 find_pio_PCI(&gc, tpnt);
950 find_pio_EISA(&gc, tpnt);
952 find_pio_ISA(&gc, tpnt);
954 for (i = 0; i <= MAXIRQ; i++)
955 if (reg_IRQ[i])
956 request_irq(i, do_eata_pio_int_handler, SA_INTERRUPT, "EATA-PIO", NULL);
958 HBA_ptr = first_HBA;
960 if (registered_HBAs != 0) {
961 printk("EATA (Extended Attachment) PIO driver version: %d.%d%s\n"
962 "(c) 1993-95 Michael Neuffer, neuffer@goofy.zdv.uni-mainz.de\n"
963 " Alfred Arnold, a.arnold@kfa-juelich.de\n"
964 "This release only supports DASD devices (harddisks)\n",
965 VER_MAJOR, VER_MINOR, VER_SUB);
967 printk("Registered HBAs:\n");
968 printk("HBA no. Boardtype: Revis: EATA: Bus: BaseIO: IRQ: Ch: ID: Pr:"
969 " 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"
972 " %2d %2d %2d\n",
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,
977 HBA_ptr->this_id, (SD(HBA_ptr)->primary == TRUE)?'Y':'N',
978 HBA_ptr->can_queue, HBA_ptr->sg_tablesize,
979 HBA_ptr->cmd_per_lun);
980 HBA_ptr = SD(HBA_ptr)->next;
983 DBG(DPT_DEBUG,DELAY(12));
985 return (registered_HBAs);
988 #ifdef MODULE
989 /* Eventually this will go into an include file, but this will be later */
990 Scsi_Host_Template driver_template = EATA_PIO;
992 #include "scsi_module.c"
993 #endif
996 * Overrides for Emacs so that we almost follow Linus's tabbing style.
997 * Emacs will notice this stuff at the end of the file and automatically
998 * adjust the settings for this buffer only. This must remain at the end
999 * of the file.
1000 * ---------------------------------------------------------------------------
1001 * Local variables:
1002 * c-indent-level: 4
1003 * c-brace-imaginary-offset: 0
1004 * c-brace-offset: -4
1005 * c-argdecl-indent: 4
1006 * c-label-offset: -4
1007 * c-continued-statement-offset: 4
1008 * c-continued-brace-offset: 0
1009 * indent-tabs-mode: nil
1010 * tab-width: 8
1011 * End: