Import 2.3.18pre1
[davej-history.git] / drivers / scsi / eata_pio.c
blob5ad320c682bdbe45995f51c3ec3c50687f7cdf64
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 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] =
69 {14,12,15,11};
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"
85 #ifdef MODULE
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);
94 return(TRUE);
96 #endif
98 void IncStat(Scsi_Pointer *SCp, uint Increment)
100 SCp->ptr+=Increment;
101 if ((SCp->this_residual-=Increment)==0)
103 if ((--SCp->buffers_residual)==0) SCp->Status=FALSE;
104 else
106 SCp->buffer++;
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)
117 unsigned long flags;
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;
127 Scsi_Cmnd *cmd;
128 hostdata *hd;
129 struct eata_ccb *cp;
130 uint base;
131 ulong flags;
132 uint x,z;
133 struct Scsi_Host *sh;
134 ushort zwickel=0;
135 unchar stat,odd;
137 save_flags(flags);
138 cli();
140 for (x = 1, sh = first_HBA; x <= registered_HBAs; x++, sh = SD(sh)->prev) {
141 if (sh->irq != irq)
142 continue;
143 if (inb((uint)sh->base + HA_RSTATUS) & HA_SBUSY)
144 continue;
146 int_counter++;
148 hd=SD(sh);
150 cp = &hd->ccb[0];
151 cmd = cp->cmd;
152 base = (uint) cmd->host->base;
156 stat=inb(base+HA_RSTATUS);
157 if (stat&HA_SDRQ) {
158 if (cp->DataIn)
160 z=256; odd=FALSE;
161 while ((cmd->SCp.Status)&&((z>0)||(odd)))
163 if (odd)
165 *(cmd->SCp.ptr)=zwickel>>8;
166 IncStat(&cmd->SCp,1);
167 odd=FALSE;
169 x=min(z,cmd->SCp.this_residual/2);
170 insw(base+HA_RDATA,cmd->SCp.ptr,x);
171 z-=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--;
178 odd=TRUE;
181 while (z>0) {
182 zwickel=inw(base+HA_RDATA);
183 z--;
186 else /* cp->DataOut */
188 odd=FALSE; z=256;
189 while ((cmd->SCp.Status)&&((z>0)||(odd)))
191 if (odd)
193 zwickel+=*(cmd->SCp.ptr)<<8;
194 IncStat(&cmd->SCp,1);
195 outw(zwickel,base+HA_RDATA);
196 z--;
197 odd=FALSE;
199 x=min(z,cmd->SCp.this_residual/2);
200 outsw(base+HA_RDATA,cmd->SCp.ptr,x);
201 z-=x;
202 IncStat(&cmd->SCp,2*x);
203 if ((z>0)&&(cmd->SCp.this_residual==1))
205 zwickel=*(cmd->SCp.ptr);
206 zwickel&=0xff;
207 IncStat(&cmd->SCp,1);
208 odd=TRUE;
211 while (z>0||odd) {
212 outw(zwickel,base+HA_RDATA);
213 z--;
214 odd=FALSE;
219 while ((stat&HA_SDRQ)||((stat&HA_SMORE)&&hd->moresupport));
221 /* terminate handler if HBA goes busy again, i.e. transfers
222 * more data */
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) {
239 cp->status = FREE;
240 eata_stat = inb(base + HA_RSTATUS);
241 printk(KERN_NOTICE "eata_pio: int_handler, freeing locked "
242 "queueslot\n");
243 DBG(DBG_INTR&&DBG_DELAY,DELAY(1));
244 restore_flags(flags);
245 return;
248 #if DBG_INTR2
249 if (stat != 0x50)
250 printk(KERN_DEBUG "stat: %#.2x, result: %#.8x\n", stat,
251 cmd->result);
252 DBG(DBG_INTR&&DBG_DELAY,DELAY(1));
253 #endif
255 cp->status = FREE; /* now we can release the slot */
257 restore_flags(flags);
258 cmd->scsi_done(cmd);
259 save_flags(flags);
260 cli();
262 restore_flags(flags);
264 return;
267 inline uint eata_pio_send_command(uint base, unchar command)
269 uint loop = HZ/2;
271 while (inb(base + HA_RSTATUS) & HA_SBUSY)
272 if (--loop == 0)
273 return(TRUE);
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);
282 return(FALSE);
285 int eata_pio_queue(Scsi_Cmnd * cmd, void (*done) (Scsi_Cmnd *))
287 uint x, y;
288 long flags;
289 uint base;
291 hostdata *hd;
292 struct Scsi_Host *sh;
293 struct eata_ccb *cp;
295 save_flags(flags);
296 cli();
298 queue_counter++;
300 hd = HD(cmd);
301 sh = cmd->host;
302 base = (uint) sh->base;
304 /* use only slot 0, as 2001 can handle only one cmd at a time */
306 y = x = 0;
308 if (hd->ccb[y].status!=FREE) {
310 DBG(DBG_QUEUE, printk(KERN_EMERG "can_queue %d, x %d, y %d\n",
311 sh->can_queue,x,y));
312 #if DEBUG_EATA
313 panic(KERN_EMERG "eata_pio: run out of queue slots cmdno:%ld "
314 "intrno: %ld\n", queue_counter, int_counter);
315 #else
316 panic(KERN_EMERG "eata_pio: run out of queue slots....\n");
317 #endif
320 cp = &hd->ccb[y];
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 */
346 break;
347 case TEST_UNIT_READY:
348 default:
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);
356 cp->reqlen = 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);
366 cp->cp_viraddr = cp;
367 cp->cmd = cmd;
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;
376 } else {
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
383 * are to transfer */
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);
390 done(cmd);
391 cp->status = FREE;
392 restore_flags(flags);
393 return (0);
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);
406 return (0);
409 int eata_pio_abort(Scsi_Cmnd * cmd)
411 ulong flags;
412 uint loop = HZ;
414 save_flags(flags);
415 cli();
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)
424 if (--loop == 0) {
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 "
449 "locked.\n"));
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;
460 ulong flags;
461 unchar success = FALSE;
462 Scsi_Cmnd *sp;
464 save_flags(flags);
465 cli();
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)
482 continue;
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,
487 sp->pid);
488 DBG(DBG_ABNORM && DBG_DELAY, DELAY(1));
490 if (sp == NULL)
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;
501 time = jiffies;
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)
512 continue;
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);
522 sp->scsi_done(sp);
523 cli();
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);
533 } else {
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)
542 struct eata_ccb cp;
543 static char buff[256];
544 int z;
546 memset(&cp, 0, sizeof(struct eata_ccb));
547 memset(buff, 0, sizeof(buff));
549 cp.DataIn = TRUE;
550 cp.Interpret = TRUE; /* Interpret command */
552 cp.cp_datalen = htonl(254);
553 cp.cp_dataDMA = htonl(0);
555 cp.cp_id = id;
556 cp.cp_lun = 0;
558 cp.cp_cdb[0] = INQUIRY;
559 cp.cp_cdb[1] = 0;
560 cp.cp_cdb[2] = 0;
561 cp.cp_cdb[3] = 0;
562 cp.cp_cdb[4] = 254;
563 cp.cp_cdb[5] = 0;
565 if (eata_pio_send_command((uint) base, EATA_CMD_PIO_SEND_CP))
566 return (NULL);
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)
574 return (NULL);
575 else if (!(inb(base + HA_RSTATUS) & HA_SDRQ))
576 return (NULL);
577 else
579 insw(base+HA_RDATA, &buff, 127);
580 while (inb(base + HA_RSTATUS)&HA_SDRQ) inw(base + HA_RDATA);
581 return (buff);
585 int get_pio_conf_PIO(u32 base, struct get_conf *buf)
587 ulong loop = HZ/2;
588 int z;
589 ushort *p;
591 if(check_region(base, 9))
592 return (FALSE);
594 memset(buf, 0, sizeof(struct get_conf));
596 while (inb(base + HA_RSTATUS) & HA_SBUSY)
597 if (--loop == 0)
598 return (FALSE);
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);
604 loop = HZ/2;
605 for (p = (ushort *) buf;
606 (long)p <= ((long)buf + (sizeof(struct get_conf) / 2)); p++) {
607 while (!(inb(base + HA_RSTATUS) & HA_SDRQ))
608 if (--loop == 0)
609 return (FALSE);
611 loop = HZ/2;
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];
626 break;
629 return (TRUE);
631 } else {
632 DBG(DBG_PROBE, printk("eata_dma: get_conf_PIO, error during transfer "
633 "for HBA at %x\n", base));
635 return (FALSE);
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)
655 unchar buffer[512];
656 #ifdef VERBOSE_SETUP
657 int z;
658 #endif
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);
663 do {
664 while (inb(base + HA_RSTATUS) & HA_SBUSY)
665 /* nothing */ ;
666 if (inb(base + HA_RSTATUS) & HA_SDRQ)
668 insw(base + HA_RDATA, &buffer, 256);
669 #ifdef VERBOSE_SETUP
670 /* no beeps please... */
671 for (z = 0; z < 511 && buffer[z]; z++)
672 if (buffer[z] != 7) printk("%c", buffer[z]);
673 #endif
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)
682 ulong size = 0;
683 char *buff;
684 ulong cplen;
685 ushort cppadlen;
686 struct Scsi_Host *sh;
687 hostdata *hd;
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)
694 return (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);
702 return (FALSE);
705 if (print_selftest(base) == FALSE && ALLOW_DMA_BOARDS == FALSE)
707 printk("HBA at %#lx failed while performing self test & setup.\n",
708 (ulong) base);
709 return (FALSE);
712 if (!reg_IRQ[gc->IRQ]) { /* Interrupt already registered ? */
713 if (!request_irq(gc->IRQ, do_eata_pio_int_handler, SA_INTERRUPT,
714 "EATA-PIO", NULL)){
715 reg_IRQ[gc->IRQ]++;
716 if (!gc->IRQ_TR)
717 reg_IRQL[gc->IRQ] = TRUE; /* IRQ is edge triggered */
718 } else {
719 printk("Couldn't allocate IRQ %d, Sorry.\n", gc->IRQ);
720 return (FALSE);
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");
726 return (FALSE);
727 } else
728 reg_IRQ[gc->IRQ]++;
731 request_region(base, 8, "eata_pio");
733 size = sizeof(hostdata) + (sizeof(struct eata_ccb) * ntohs(gc->queuesiz));
735 sh = scsi_register(tpnt, size);
736 hd = SD(sh);
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)) {
753 case 0x1c:
754 SD(sh)->EATA_revision = 'a';
755 break;
756 case 0x1e:
757 SD(sh)->EATA_revision = 'b';
758 break;
759 case 0x22:
760 SD(sh)->EATA_revision = 'c';
761 break;
762 case 0x24:
763 SD(sh)->EATA_revision = 'z';
764 default:
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;
773 else
774 hd->bustype = IS_ISA;
775 } else {
776 if (buff[21] == '4')
777 hd->bustype = IS_PCI;
778 else if (buff[21] == '2')
779 hd->bustype = IS_EISA;
780 else
781 hd->bustype = IS_ISA;
784 SD(sh)->cplen=cplen;
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;
791 sh->io_port = base;
792 sh->n_io_port = 8;
793 sh->irq = gc->IRQ;
794 sh->dma_channel = PIO;
795 sh->this_id = gc->scsi_id[3];
796 sh->can_queue = 1;
797 sh->cmd_per_lun = 1;
798 sh->sg_tablesize = SG_ALL;
800 hd->channel = 0;
802 sh->max_id = 8;
803 sh->max_lun = 8;
805 if (gc->SECOND)
806 hd->primary = FALSE;
807 else
808 hd->primary = TRUE;
810 sh->unchecked_isa_dma = FALSE; /* We can only do PIO */
812 hd->next = NULL; /* build a linked list of all HBAs */
813 hd->prev = last_HBA;
814 if(hd->prev != NULL)
815 SD(hd->prev)->next = sh;
816 last_HBA = sh;
817 if (first_HBA == NULL)
818 first_HBA = sh;
819 registered_HBAs++;
820 return (1);
823 void find_pio_ISA(struct get_conf *buf, Scsi_Host_Template * tpnt)
825 int i;
827 for (i = 0; i < MAXISA; i++) {
828 if (ISAbases[i]) {
829 if (get_pio_conf_PIO(ISAbases[i], buf) == TRUE){
830 register_pio_HBA(ISAbases[i], buf, tpnt);
832 ISAbases[i] = 0;
835 return;
838 void find_pio_EISA(struct get_conf *buf, Scsi_Host_Template * tpnt)
840 u32 base;
841 int i;
843 #if CHECKPAL
844 u8 pal1, pal2, pal3;
845 #endif
847 for (i = 0; i < MAXEISA; i++) {
848 if (EISAbases[i] == TRUE) { /* Still a possibility ? */
850 base = 0x1c88 + (i * 0x1000);
851 #if CHECKPAL
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: "
860 "%x %x %x \n",
861 (int)pal1, (int)pal2, (int)pal3));
862 #endif
863 if (get_pio_conf_PIO(base, buf) == TRUE) {
864 DBG(DBG_PROBE && DBG_EISA, print_pio_config(buf));
865 if (buf->IRQ) {
866 register_pio_HBA(base, buf, tpnt);
867 } else
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 */
872 EISAbases[i] = 0;
873 #if CHECKPAL
875 #endif
878 return;
881 void find_pio_PCI(struct get_conf *buf, Scsi_Host_Template * tpnt)
883 #ifndef CONFIG_PCI
884 printk("eata_dma: kernel PCI support not enabled. Skipping scan for PCI HBAs.\n");
885 #else
886 struct pci_dev *dev;
887 u32 base, x;
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));
892 pci_set_master(dev);
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);
896 continue;
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 */
903 if (base != 0x1f8) {
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);
916 if (base < 0x1000) {
917 for (x = 0; x < MAXISA; ++x) {
918 if (ISAbases[x] == base) {
919 ISAbases[x] = 0;
920 break;
923 } else if ((base & 0x0fff) == 0x0c88) {
924 x = (base >> 12) & 0x0f;
925 EISAbases[x] = 0;
928 #if CHECK_BLINK
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");
933 #endif
936 #endif /* #ifndef CONFIG_PCI */
940 int eata_pio_detect(Scsi_Host_Template * tpnt)
942 struct Scsi_Host *HBA_ptr;
943 struct get_conf gc;
944 int i;
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++)
958 if (reg_IRQ[i])
959 request_irq(i, do_eata_pio_int_handler, SA_INTERRUPT, "EATA-PIO", NULL);
961 HBA_ptr = first_HBA;
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:"
972 " QS: SG: CPL:\n");
973 for (i = 1; i <= registered_HBAs; i++) {
974 printk("scsi%-2d: %.10s v%s 2.0%c %s %#.4x %2d %d %d %c"
975 " %2d %2d %2d\n",
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);
991 #ifdef MODULE
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"
996 #endif
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
1002 * of the file.
1003 * ---------------------------------------------------------------------------
1004 * Local variables:
1005 * c-indent-level: 4
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
1013 * tab-width: 8
1014 * End: