This source file includes following definitions.
- hprint
- eata_pio_release
- IncStat
- eata_pio_int_handler
- eata_pio_send_command
- eata_pio_queue
- eata_pio_abort
- eata_pio_reset
- get_pio_board_data
- get_pio_conf_PIO
- print_pio_config
- print_selftest
- register_pio_HBA
- find_pio_ISA
- find_pio_EISA
- find_pio_PCI
- eata_pio_detect
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40 #ifdef MODULE
41 #include <linux/module.h>
42 #include <linux/version.h>
43 #endif
44
45 #include <linux/kernel.h>
46 #include <linux/sched.h>
47 #include <linux/string.h>
48 #include <linux/ioport.h>
49 #include <linux/malloc.h>
50 #include <linux/in.h>
51 #include <linux/bios32.h>
52 #include <linux/pci.h>
53 #include <linux/proc_fs.h>
54 #include <asm/io.h>
55 #include "eata_pio.h"
56 #include "eata_dma_proc.h"
57 #include "scsi.h"
58 #include "sd.h"
59
60 static uint ISAbases[MAXISA] =
61 {0x1F0, 0x170, 0x330, 0x230};
62 static uint ISAirqs[MAXISA] =
63 {14,12,15,11};
64 static unchar EISAbases[] =
65 {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
66 static uint registered_HBAs = 0;
67 static struct Scsi_Host *last_HBA = NULL;
68 static struct Scsi_Host *first_HBA = NULL;
69 static unchar reg_IRQ[] =
70 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
71 static unchar reg_IRQL[] =
72 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
73
74 static ulong int_counter = 0;
75 static ulong queue_counter = 0;
76
77 void hprint(const char *str)
78 {
79 char *hptr =(char *) 0x000b0000;
80 char *hptr2=(char *) 0x000b00a0;
81 char *hptr3=(char *) 0x000b0f00;
82 int z;
83
84 memmove(hptr,hptr2,24*80*2);
85 for (z=0; z<strlen(str); z++)
86 hptr3[z*2]=str[z];
87 for (; z<80; z++)
88 hptr3[z*2]=' ';
89 }
90
91
92 #include "eata_pio_proc.c"
93
94 #ifdef MODULE
95 int eata_pio_release(struct Scsi_Host *sh)
96 {
97 if (sh->irq && reg_IRQ[sh->irq] == 1) free_irq(sh->irq);
98 else reg_IRQ[sh->irq]--;
99 if (SD(sh)->channel == 0) {
100 if (sh->io_port && sh->n_io_port)
101 release_region(sh->io_port, sh->n_io_port);
102 }
103 return(TRUE);
104 }
105 #endif
106
107 void IncStat(Scsi_Pointer *SCp, uint Increment)
108 {
109 SCp->ptr+=Increment;
110 if ((SCp->this_residual-=Increment)==0)
111 {
112 if ((--SCp->buffers_residual)==0) SCp->Status=FALSE;
113 else
114 {
115 SCp->buffer++;
116 SCp->ptr=SCp->buffer->address;
117 SCp->this_residual=SCp->buffer->length;
118 }
119 }
120 }
121
122 void eata_pio_int_handler(int irq, struct pt_regs * regs)
123 {
124 uint eata_stat = 0xfffff;
125 Scsi_Cmnd *cmd;
126 hostdata *hd;
127 struct eata_ccb *cp;
128 uint base;
129 ulong flags;
130 uint x,z;
131 struct Scsi_Host *sh;
132 ushort zwickel=0;
133 unchar stat,odd;
134
135 save_flags(flags);
136 cli();
137
138 for (x = 1, sh = first_HBA; x <= registered_HBAs; x++, sh = SD(sh)->prev) {
139 if (sh->irq != irq)
140 continue;
141 if (inb((uint)sh->base + HA_RSTATUS) & HA_SBUSY)
142 continue;
143
144 int_counter++;
145
146 hd=SD(sh);
147
148 cp = &hd->ccb[0];
149 cmd = cp->cmd;
150 base = (uint) cmd->host->base;
151
152 do
153 {
154 stat=inb(base+HA_RSTATUS);
155 if (stat&HA_SDRQ)
156 if (cp->DataIn)
157 {
158 z=256; odd=FALSE;
159 while ((cmd->SCp.Status)&&((z>0)||(odd)))
160 {
161 if (odd)
162 {
163 *(cmd->SCp.ptr)=zwickel>>8;
164 IncStat(&cmd->SCp,1);
165 odd=FALSE;
166 }
167 x=min(z,cmd->SCp.this_residual/2);
168 insw(base+HA_RDATA,cmd->SCp.ptr,x);
169 z-=x;
170 IncStat(&cmd->SCp,2*x);
171 if ((z>0)&&(cmd->SCp.this_residual==1))
172 {
173 zwickel=inw(base+HA_RDATA);
174 *(cmd->SCp.ptr)=zwickel&0xff;
175 IncStat(&cmd->SCp,1); z--;
176 odd=TRUE;
177 }
178 }
179 while (z>0) {
180 zwickel=inw(base+HA_RDATA);
181 z--;
182 }
183 }
184 else
185 {
186 odd=FALSE; z=256;
187 while ((cmd->SCp.Status)&&((z>0)||(odd)))
188 {
189 if (odd)
190 {
191 zwickel+=*(cmd->SCp.ptr)<<8;
192 IncStat(&cmd->SCp,1);
193 outw(zwickel,base+HA_RDATA);
194 z--;
195 odd=FALSE;
196 }
197 x=min(z,cmd->SCp.this_residual/2);
198 outsw(base+HA_RDATA,cmd->SCp.ptr,x);
199 z-=x;
200 IncStat(&cmd->SCp,2*x);
201 if ((z>0)&&(cmd->SCp.this_residual==1))
202 {
203 zwickel=*(cmd->SCp.ptr);
204 zwickel&=0xff;
205 IncStat(&cmd->SCp,1);
206 odd=TRUE;
207 }
208 }
209 while (z>0||odd) {
210 outw(zwickel,base+HA_RDATA);
211 z--;
212 odd=FALSE;
213 }
214 }
215 }
216 while ((stat&HA_SDRQ)||((stat&HA_SMORE)&&hd->moresupport));
217
218
219
220
221 if (stat&HA_SBUSY) break;
222
223
224
225
226 if (!(inb(base+HA_RSTATUS)&HA_SERROR))
227 {
228 cmd->result=(DID_OK<<16);
229 hd->devflags|=(1<<cp->cp_id);
230 }
231 else if (hd->devflags&1<<cp->cp_id)
232 cmd->result=(DID_OK<<16)+0x02;
233 else cmd->result=(DID_NO_CONNECT<<16);
234
235 if (cp->status == LOCKED) {
236 cp->status = FREE;
237 eata_stat = inb(base + HA_RSTATUS);
238 printk("eata_pio: int_handler, freeing locked queueslot\n");
239 DBG(DBG_INTR&&DBG_DELAY,DEL2(800));
240 restore_flags(flags);
241 return;
242 }
243
244 #if DBG_INTR2
245 if (stat != 0x50)
246 printk("stat: %#.2x, result: %#.8x\n", stat, cmd->result);
247 DBG(DBG_INTR&&DBG_DELAY,DEL2(800));
248 #endif
249
250 cp->status = FREE;
251
252 restore_flags(flags);
253 cmd->scsi_done(cmd);
254 save_flags(flags);
255 cli();
256 }
257 restore_flags(flags);
258
259 return;
260 }
261
262 inline uint eata_pio_send_command(uint base, unchar command)
263 {
264 uint loop = R_LIMIT;
265
266 while (inb(base + HA_RSTATUS) & HA_SBUSY)
267 if (--loop == 0)
268 return(TRUE);
269
270 outb(command, base + HA_WCOMMAND);
271 return(FALSE);
272 }
273
274 int eata_pio_queue(Scsi_Cmnd * cmd, void (*done) (Scsi_Cmnd *))
275 {
276 uint x, y;
277 long flags;
278 uint base;
279
280 hostdata *hd;
281 struct Scsi_Host *sh;
282 struct eata_ccb *cp;
283
284 save_flags(flags);
285 cli();
286
287 queue_counter++;
288
289 hd = HD(cmd);
290 sh = cmd->host;
291 base = (uint) sh->base;
292
293
294
295 y = x = 0;
296
297 if (hd->ccb[y].status!=FREE) {
298
299 DBG(DBG_QUEUE, printk("can_queue %d, x %d, y %d\n",sh->can_queue,x,y));
300 #if DEBUG_EATA
301 panic("eata_pio: run out of queue slots cmdno:%ld intrno: %ld\n",
302 queue_counter, int_counter);
303 #else
304 panic("eata_pio: run out of queue slots....\n");
305 #endif
306 }
307
308 cp = &hd->ccb[y];
309
310 memset(cp, 0, sizeof(struct eata_ccb));
311 memset(cmd->sense_buffer, 0, sizeof(cmd->sense_buffer));
312
313 cp->status = USED;
314
315 DBG(DBG_QUEUE, printk("eata_pio_queue pid %ld, target: %x, lun: %x, y %d\n",
316 cmd->pid, cmd->target, cmd->lun, y));
317 DBG(DBG_QUEUE && DBG_DELAY, DEL2(250));
318
319 cmd->scsi_done = (void *)done;
320
321 switch (cmd->cmnd[0]) {
322 case CHANGE_DEFINITION: case COMPARE: case COPY:
323 case COPY_VERIFY: case LOG_SELECT: case MODE_SELECT:
324 case MODE_SELECT_10: case SEND_DIAGNOSTIC: case WRITE_BUFFER:
325 case FORMAT_UNIT: case REASSIGN_BLOCKS: case RESERVE:
326 case SEARCH_EQUAL: case SEARCH_HIGH: case SEARCH_LOW:
327 case WRITE_6: case WRITE_10: case WRITE_VERIFY:
328 case UPDATE_BLOCK: case WRITE_LONG: case WRITE_SAME:
329 case SEARCH_HIGH_12: case SEARCH_EQUAL_12: case SEARCH_LOW_12:
330 case WRITE_12: case WRITE_VERIFY_12: case SET_WINDOW:
331 case MEDIUM_SCAN: case SEND_VOLUME_TAG:
332 case 0xea:
333 cp->DataOut = TRUE;
334 break;
335 case TEST_UNIT_READY:
336 default:
337 cp->DataIn = TRUE;
338 }
339
340 cp->Interpret = (cmd->target == hd->hostid);
341 cp->cp_datalen = htonl((ulong)cmd->request_bufflen);
342 cp->Auto_Req_Sen = FALSE;
343 cp->cp_reqDMA = htonl(0);
344 cp->reqlen = 0;
345
346 cp->cp_id = cmd->target;
347 cp->cp_lun = cmd->lun;
348 cp->cp_dispri = FALSE;
349 cp->cp_identify = TRUE;
350 memcpy(cp->cp_cdb, cmd->cmnd, COMMAND_SIZE(*cmd->cmnd));
351
352 cp->cp_statDMA = htonl(0);
353
354 cp->cp_viraddr = cp;
355 cp->cmd = cmd;
356 cmd->host_scribble = (char *)&hd->ccb[y];
357
358 if (cmd->use_sg == 0)
359 {
360 cmd->SCp.buffers_residual=1;
361 cmd->SCp.ptr = cmd->request_buffer;
362 cmd->SCp.this_residual = cmd->request_bufflen;
363 cmd->SCp.buffer = NULL;
364 } else {
365 cmd->SCp.buffer = cmd->request_buffer;
366 cmd->SCp.buffers_residual = cmd->use_sg;
367 cmd->SCp.ptr = cmd->SCp.buffer->address;
368 cmd->SCp.this_residual = cmd->SCp.buffer->length;
369 }
370 cmd->SCp.Status = (cmd->SCp.this_residual != 0);
371
372
373 if (eata_pio_send_command(base, EATA_CMD_PIO_SEND_CP))
374 {
375 cmd->result = DID_ERROR << 16;
376 printk("eata_pio_queue target %d, pid %ld, HBA busy, returning "
377 "DID_ERROR, done.\n", cmd->target, cmd->pid);
378 restore_flags(flags);
379 done(cmd);
380 return (0);
381 }
382 while (!(inb(base + HA_RSTATUS) & HA_SDRQ));
383 outsw(base + HA_RDATA, cp, hd->cplen);
384 outb(EATA_CMD_PIO_TRUNC, base + HA_WCOMMAND);
385 for (x = 0; x < hd->cppadlen; x++) outw(0, base + HA_RDATA);
386
387 DBG(DBG_QUEUE,printk("Queued base %#.4lx pid: %ld target: %x lun: %x "
388 "slot %d irq %d\n", (long)sh->base, cmd->pid,
389 cmd->target, cmd->lun, y, sh->irq));
390 DBG(DBG_QUEUE && DBG_DELAY, DEL2(200));
391
392 restore_flags(flags);
393 return (0);
394 }
395
396 int eata_pio_abort(Scsi_Cmnd * cmd)
397 {
398 ulong flags;
399 uint loop = R_LIMIT;
400
401 save_flags(flags);
402 cli();
403
404 DBG(DBG_ABNORM, printk("eata_pio_abort called pid: %ld target: %x lun: %x"
405 " reason %x\n", cmd->pid, cmd->target, cmd->lun,
406 cmd->abort_reason));
407 DBG(DBG_ABNORM && DBG_DELAY, DEL2(500));
408
409
410 while (inb((uint)(cmd->host->base) + HA_RAUXSTAT) & HA_ABUSY)
411 if (--loop == 0) {
412 printk("eata_pio: abort, timeout error.\n");
413 restore_flags(flags);
414 DBG(DBG_ABNORM && DBG_DELAY, DEL2(500));
415 return (SCSI_ABORT_ERROR);
416 }
417 if (CD(cmd)->status == FREE) {
418 DBG(DBG_ABNORM, printk("Returning: SCSI_ABORT_NOT_RUNNING\n"));
419 restore_flags(flags);
420 return (SCSI_ABORT_NOT_RUNNING);
421 }
422 if (CD(cmd)->status == USED) {
423 DBG(DBG_ABNORM, printk("Returning: SCSI_ABORT_BUSY\n"));
424 restore_flags(flags);
425 return (SCSI_ABORT_BUSY);
426 }
427 if (CD(cmd)->status == RESET) {
428 restore_flags(flags);
429 printk("eata_pio: abort, command reset error.\n");
430 DBG(DBG_ABNORM && DBG_DELAY, DEL2(500));
431 return (SCSI_ABORT_ERROR);
432 }
433 if (CD(cmd)->status == LOCKED) {
434 restore_flags(flags);
435 DBG(DBG_ABNORM, printk("eata_pio: abort, queue slot locked.\n"));
436 DBG(DBG_ABNORM && DBG_DELAY, DEL2(500));
437 return (SCSI_ABORT_NOT_RUNNING);
438 }
439 restore_flags(flags);
440 panic("eata_pio: abort: invalid slot status\n");
441 }
442
443 int eata_pio_reset(Scsi_Cmnd * cmd)
444 {
445 uint x, z, time, limit = 0;
446 ulong flags;
447 unchar success = FALSE;
448 Scsi_Cmnd *sp;
449
450 save_flags(flags);
451 cli();
452 hprint("reset");
453 DBG(DBG_ABNORM, printk("eata_pio_reset called pid:%ld target: %x lun: %x "
454 "reason %x\n", cmd->pid, cmd->target, cmd->lun,
455 cmd->abort_reason));
456
457 if (HD(cmd)->state == RESET) {
458 printk("eata_pio_reset: exit, already in reset.\n");
459 restore_flags(flags);
460 DBG(DBG_ABNORM && DBG_DELAY, DEL2(500));
461 return (SCSI_RESET_ERROR);
462 }
463
464 for (z = 0; z < MAXTARGET; z++) {
465 HD(cmd)->t_state[0][z] = RESET;
466 HD(cmd)->t_timeout[0][z] = NO_TIMEOUT;
467 }
468
469
470
471 for (x = 0; x < cmd->host->can_queue; x++) {
472
473 if (HD(cmd)->ccb[x].status == FREE)
474 continue;
475
476 sp = HD(cmd)->ccb[x].cmd;
477 HD(cmd)->ccb[x].status = RESET;
478 printk("eata_pio_reset: slot %d in reset, pid %ld.\n", x, sp->pid);
479 DBG(DBG_ABNORM && DBG_DELAY, DEL2(500));
480
481 if (sp == NULL)
482 panic("eata_pio_reset: slot %d, sp==NULL.\n", x);
483 DBG(DBG_ABNORM && DBG_DELAY, DEL2(500));
484 }
485
486
487 outb((uint) cmd->host->base+HA_WCOMMAND, EATA_CMD_RESET);
488
489 DBG(DBG_ABNORM, printk("eata_pio_reset: board reset done.\n"));
490 HD(cmd)->state = RESET;
491
492 time = jiffies;
493 while (jiffies < (time + (3 * HZ)) && limit++ < 10000000);
494
495 DBG(DBG_ABNORM, printk("eata_pio_reset: interrupts disabled, loops %d.\n", limit));
496 DBG(DBG_ABNORM && DBG_DELAY, DEL2(500));
497
498 for (x = 0; x < cmd->host->can_queue; x++) {
499
500
501 if (HD(cmd)->ccb[x].status != RESET)
502 continue;
503
504 sp = HD(cmd)->ccb[x].cmd;
505 sp->result = DID_RESET << 16;
506
507
508 printk("eata_pio_reset: resetted ccb %d.\n",x);
509 HD(cmd)->ccb[x].status = FREE;
510
511 restore_flags(flags);
512 sp->scsi_done(sp);
513 cli();
514 }
515
516 HD(cmd)->state = FALSE;
517 restore_flags(flags);
518
519 if (success) {
520 DBG(DBG_ABNORM, printk("eata_pio_reset: exit, success.\n"));
521 DBG(DBG_ABNORM && DBG_DELAY, DEL2(500));
522 return (SCSI_RESET_SUCCESS);
523 } else {
524 DBG(DBG_ABNORM, printk("eata_pio_reset: exit, wakeup.\n"));
525 DBG(DBG_ABNORM && DBG_DELAY, DEL2(500));
526 return (SCSI_RESET_PUNT);
527 }
528 }
529
530 char * get_pio_board_data(ulong base, uint irq, uint id, ulong cplen, ushort cppadlen)
531 {
532 struct eata_ccb cp;
533 static char buff[256];
534 int z;
535
536 memset(&cp, 0, sizeof(struct eata_ccb));
537 memset(buff, 0, sizeof(buff));
538
539 cp.DataIn = TRUE;
540 cp.Interpret = TRUE;
541
542 cp.cp_datalen = htonl(254);
543 cp.cp_dataDMA = htonl(0);
544
545 cp.cp_id = id;
546 cp.cp_lun = 0;
547
548 cp.cp_cdb[0] = INQUIRY;
549 cp.cp_cdb[1] = 0;
550 cp.cp_cdb[2] = 0;
551 cp.cp_cdb[3] = 0;
552 cp.cp_cdb[4] = 254;
553 cp.cp_cdb[5] = 0;
554
555 if (eata_pio_send_command((uint) base, EATA_CMD_PIO_SEND_CP))
556 return (NULL);
557 while (!(inb(base + HA_RSTATUS) & HA_SDRQ));
558 outsw(base + HA_RDATA, &cp, cplen);
559 outb(EATA_CMD_PIO_TRUNC, base + HA_WCOMMAND);
560 for (z = 0; z < cppadlen; z++) outw(0, base + HA_RDATA);
561
562 while (inb(base + HA_RSTATUS) & HA_SBUSY);
563 if (inb(base + HA_RSTATUS) & HA_SERROR)
564 return (NULL);
565 else if (!(inb(base + HA_RSTATUS) & HA_SDRQ))
566 return (NULL);
567 else
568 {
569 insw(base+HA_RDATA, &buff, 127);
570 while (inb(base + HA_RSTATUS)&HA_SDRQ) inw(base + HA_RDATA);
571 return (buff);
572 }
573 }
574
575 int get_pio_conf_PIO(u32 base, struct get_conf *buf)
576 {
577 ulong loop = R_LIMIT;
578 int z;
579 ushort *p;
580
581 if(check_region(base, 9))
582 return (FALSE);
583
584 memset(buf, 0, sizeof(struct get_conf));
585
586 while (inb(base + HA_RSTATUS) & HA_SBUSY)
587 if (--loop == 0)
588 return (FALSE);
589
590 DBG(DBG_PIO && DBG_PROBE,
591 printk("Issuing PIO READ CONFIG to HBA at %#x\n", base));
592 eata_pio_send_command(base, EATA_CMD_PIO_READ_CONFIG);
593
594 loop = R_LIMIT;
595 for (p = (ushort *) buf;
596 (long)p <= ((long)buf + (sizeof(struct get_conf) / 2)); p++) {
597 while (!(inb(base + HA_RSTATUS) & HA_SDRQ))
598 if (--loop == 0)
599 return (FALSE);
600
601 loop = R_LIMIT;
602 *p = inw(base + HA_RDATA);
603 }
604 if (!(inb(base + HA_RSTATUS) & HA_SERROR)) {
605 if (htonl(EATA_SIGNATURE) == buf->signature) {
606 DBG(DBG_PIO&&DBG_PROBE, printk("EATA Controller found at %#4x "
607 "EATA Level: %x\n", base,
608 (uint) (buf->version)));
609
610 while (inb(base + HA_RSTATUS) & HA_SDRQ)
611 inw(base + HA_RDATA);
612 if(ALLOW_DMA_BOARDS == FALSE) {
613 for (z = 0; z < MAXISA; z++)
614 if (base == ISAbases[z]) {
615 buf->IRQ = ISAirqs[z];
616 break;
617 }
618 }
619 return (TRUE);
620 }
621 } else {
622 DBG(DBG_PROBE, printk("eata_dma: get_conf_PIO, error during transfer "
623 "for HBA at %x\n", base));
624 }
625 return (FALSE);
626 }
627
628 void print_pio_config(struct get_conf *gc)
629 {
630 printk("Please check values: (read config data)\n");
631 printk("LEN: %d ver:%d OCS:%d TAR:%d TRNXFR:%d MORES:%d\n",
632 (uint) ntohl(gc->len), gc->version,
633 gc->OCS_enabled, gc->TAR_support, gc->TRNXFR, gc->MORE_support);
634 printk("HAAV:%d SCSIID0:%d ID1:%d ID2:%d QUEUE:%d SG:%d SEC:%d\n",
635 gc->HAA_valid, gc->scsi_id[3], gc->scsi_id[2],
636 gc->scsi_id[1], ntohs(gc->queuesiz), ntohs(gc->SGsiz), gc->SECOND);
637 printk("IRQ:%d IRQT:%d FORCADR:%d MCH:%d RIDQ:%d\n",
638 gc->IRQ, gc->IRQ_TR, gc->FORCADR,
639 gc->MAX_CHAN, gc->ID_qest);
640 DBG(DPT_DEBUG, DELAY(14));
641 }
642
643 static uint print_selftest(uint base)
644 {
645 unchar buffer[512];
646 #ifdef VERBOSE_SETUP
647 int z;
648 #endif
649
650 printk("eata_pio: executing controller self test & setup...\n");
651 while (inb(base + HA_RSTATUS) & HA_SBUSY);
652 outb(EATA_CMD_PIO_SETUPTEST, base + HA_WCOMMAND);
653 do {
654 while (inb(base + HA_RSTATUS) & HA_SBUSY)
655 ;
656 if (inb(base + HA_RSTATUS) & HA_SDRQ)
657 {
658 insw(base + HA_RDATA, &buffer, 256);
659 #ifdef VERBOSE_SETUP
660
661 for (z = 0; z < 511 && buffer[z]; z++)
662 if (buffer[z] != 7) printk("%c", buffer[z]);
663 #endif
664 }
665 } while (inb(base+HA_RSTATUS) & (HA_SBUSY|HA_SDRQ));
666
667 return (!(inb(base+HA_RSTATUS) & HA_SERROR));
668 }
669
670 int register_pio_HBA(long base, struct get_conf *gc, Scsi_Host_Template * tpnt)
671 {
672 ulong size = 0;
673 char *buff;
674 ulong cplen;
675 ushort cppadlen;
676 struct Scsi_Host *sh;
677 hostdata *hd;
678
679 DBG(DBG_REGISTER, print_pio_config(gc));
680
681 if (gc->DMA_support == TRUE) {
682 printk("HBA at %#.4lx supports DMA. Please use EATA-DMA driver.\n",base);
683 if(ALLOW_DMA_BOARDS == FALSE)
684 return (FALSE);
685 }
686
687 if ((buff = get_pio_board_data((uint)base, gc->IRQ, gc->scsi_id[3],
688 cplen =(htonl(gc->cplen )+1)/2,
689 cppadlen=(htons(gc->cppadlen)+1)/2)) == NULL)
690 {
691 printk("HBA at %#lx didn't react on INQUIRY. Sorry.\n", (ulong) base);
692 return (FALSE);
693 }
694
695 if (print_selftest(base) == FALSE && ALLOW_DMA_BOARDS == FALSE)
696 {
697 printk("HBA at %#lx failed while performing self test & setup.\n",
698 (ulong) base);
699 return (FALSE);
700 }
701
702 if (!reg_IRQ[gc->IRQ]) {
703 if (!request_irq(gc->IRQ, eata_pio_int_handler, SA_INTERRUPT,
704 "EATA-PIO")){
705 reg_IRQ[gc->IRQ]++;
706 if (!gc->IRQ_TR)
707 reg_IRQL[gc->IRQ] = TRUE;
708 } else {
709 printk("Couldn't allocate IRQ %d, Sorry.", gc->IRQ);
710 return (FALSE);
711 }
712 } else {
713 if (reg_IRQL[gc->IRQ] == TRUE) {
714 printk("Can't support more than one HBA on this IRQ,\n"
715 " if the IRQ is edge triggered. Sorry.\n");
716 return (FALSE);
717 } else
718 reg_IRQ[gc->IRQ]++;
719 }
720
721 request_region(base, 8, "eata_pio");
722
723 size = sizeof(hostdata) + (sizeof(struct eata_ccb) * ntohs(gc->queuesiz));
724
725 sh = scsi_register(tpnt, size);
726 hd = SD(sh);
727
728 memset(hd->ccb, 0, (sizeof(struct eata_ccb) * ntohs(gc->queuesiz)));
729 memset(hd->reads, 0, sizeof(ulong) * 26);
730
731 strncpy(SD(sh)->vendor, &buff[8], 8);
732 SD(sh)->vendor[8] = 0;
733 strncpy(SD(sh)->name, &buff[16], 17);
734 SD(sh)->name[17] = 0;
735 SD(sh)->revision[0] = buff[32];
736 SD(sh)->revision[1] = buff[33];
737 SD(sh)->revision[2] = buff[34];
738 SD(sh)->revision[3] = '.';
739 SD(sh)->revision[4] = buff[35];
740 SD(sh)->revision[5] = 0;
741
742 switch (ntohl(gc->len)) {
743 case 0x1c:
744 SD(sh)->EATA_revision = 'a';
745 break;
746 case 0x1e:
747 SD(sh)->EATA_revision = 'b';
748 break;
749 case 0x22:
750 SD(sh)->EATA_revision = 'c';
751 break;
752 case 0x24:
753 SD(sh)->EATA_revision = 'z';
754 default:
755 SD(sh)->EATA_revision = '?';
756 }
757
758 if(ntohl(gc->len) >= 0x22) {
759 if (gc->is_PCI == TRUE)
760 hd->bustype = IS_PCI;
761 else if (gc->is_EISA == TRUE)
762 hd->bustype = IS_EISA;
763 else
764 hd->bustype = IS_ISA;
765 } else {
766 if (buff[21] == '4')
767 hd->bustype = IS_PCI;
768 else if (buff[21] == '2')
769 hd->bustype = IS_EISA;
770 else
771 hd->bustype = IS_ISA;
772 }
773
774 SD(sh)->cplen=cplen;
775 SD(sh)->cppadlen=cppadlen;
776 SD(sh)->hostid=gc->scsi_id[3];
777 SD(sh)->devflags=1<<gc->scsi_id[3];
778 SD(sh)->moresupport=gc->MORE_support;
779 sh->base = (char *) base;
780 sh->io_port = (ushort) base;
781 sh->n_io_port = 8;
782 sh->irq = gc->IRQ;
783 sh->dma_channel = 0xfe;
784 sh->this_id = gc->scsi_id[3];
785 sh->can_queue = 1;
786 sh->cmd_per_lun = 1;
787 sh->sg_tablesize = SG_ALL;
788
789 hd->channel = 0;
790
791 sh->max_id = 8;
792 sh->max_lun = 8;
793
794 if (gc->SECOND)
795 hd->primary = FALSE;
796 else
797 hd->primary = TRUE;
798
799 sh->unchecked_isa_dma = FALSE;
800
801 hd->next = NULL;
802 hd->prev = last_HBA;
803 if(hd->prev != NULL)
804 SD(hd->prev)->next = sh;
805 last_HBA = sh;
806 if (first_HBA == NULL)
807 first_HBA = sh;
808 registered_HBAs++;
809 return (1);
810 }
811
812 void find_pio_ISA(struct get_conf *buf, Scsi_Host_Template * tpnt)
813 {
814 int i;
815
816 for (i = 0; i < MAXISA; i++) {
817 if (ISAbases[i]) {
818 if (get_pio_conf_PIO(ISAbases[i], buf) == TRUE){
819 register_pio_HBA(ISAbases[i], buf, tpnt);
820 }
821 ISAbases[i] = 0;
822 }
823 }
824 return;
825 }
826
827 void find_pio_EISA(struct get_conf *buf, Scsi_Host_Template * tpnt)
828 {
829 u32 base;
830 int i;
831
832 #if CHECKPAL
833 u8 pal1, pal2, pal3;
834 #endif
835
836 for (i = 0; i < MAXEISA; i++) {
837 if (EISAbases[i] == TRUE) {
838
839 base = 0x1c88 + (i * 0x1000);
840 #if CHECKPAL
841 pal1 = inb((u16)base - 8);
842 pal2 = inb((u16)base - 7);
843 pal3 = inb((u16)base - 6);
844
845 if (((pal1 == 0x12) && (pal2 == 0x14)) ||
846 ((pal1 == 0x38) && (pal2 == 0xa3) && (pal3 == 0x82)) ||
847 ((pal1 == 0x06) && (pal2 == 0x94) && (pal3 == 0x24))) {
848 DBG(DBG_PROBE, printk("EISA EATA id tags found: %x %x %x \n",
849 (int)pal1, (int)pal2, (int)pal3));
850 #endif
851 if (get_pio_conf_PIO(base, buf) == TRUE) {
852 DBG(DBG_PROBE && DBG_EISA, print_pio_config(buf));
853 if (buf->IRQ) {
854 register_pio_HBA(base, buf, tpnt);
855 } else
856 printk("eata_dma: No valid IRQ. HBA removed from list\n");
857 }
858
859 EISAbases[i] = 0;
860 #if CHECKPAL
861 }
862 #endif
863 }
864 }
865 return;
866 }
867
868 void find_pio_PCI(struct get_conf *buf, Scsi_Host_Template * tpnt)
869 {
870
871 #ifndef CONFIG_PCI
872 printk("eata_pio: kernel PCI support not enabled. Skipping scan for PCI HBAs.\n");
873 #else
874
875 u8 pci_bus, pci_device_fn;
876 static s16 pci_index = 0;
877 u32 base = 0;
878 u16 com_adr;
879 u16 rev_device;
880 u32 error, i, x;
881
882 if (pcibios_present()) {
883 for (i = 0; i <= MAXPCI; ++i, ++pci_index) {
884 if (pcibios_find_device(PCI_VENDOR_ID_DPT, PCI_DEVICE_ID_DPT,
885 pci_index, &pci_bus, &pci_device_fn))
886 break;
887 DBG(DBG_PROBE && DBG_PCI,
888 printk("eata_pio: HBA at bus %d, device %d,"
889 " function %d, index %d\n", (s32)pci_bus,
890 (s32)((pci_device_fn & 0xf8) >> 3),
891 (s32)(pci_device_fn & 7), pci_index));
892
893 if (!(error = pcibios_read_config_word(pci_bus, pci_device_fn,
894 PCI_CLASS_DEVICE, &rev_device))) {
895 if (rev_device == PCI_CLASS_STORAGE_SCSI) {
896 if (!(error = pcibios_read_config_word(pci_bus,
897 pci_device_fn, PCI_COMMAND,
898 (u16 *) & com_adr))) {
899 if (!((com_adr & PCI_COMMAND_IO) &&
900 (com_adr & PCI_COMMAND_MASTER))) {
901 printk("HBA has IO or BUSMASTER mode disabled\n");
902 continue;
903 }
904 } else
905 printk("eata_pio: error %x while reading "
906 "PCI_COMMAND\n", error);
907 } else
908 printk("DEVICECLASSID %x didn't match\n", rev_device);
909 } else {
910 printk("eata_pio: error %x while reading PCI_CLASS_BASE\n",
911 error);
912 continue;
913 }
914
915 if (!(error = pcibios_read_config_dword(pci_bus, pci_device_fn,
916 PCI_BASE_ADDRESS_0, (int *) &base))){
917
918
919 if (base & 0x01) {
920 base &= 0xfffffffe;
921
922 if ((inb(base) == 0x12) && (inb(base + 1) == 0x14))
923 continue;
924 base += 0x10;
925 if (base != 0x1f8) {
926
927 if (get_pio_conf_PIO(base, buf) == TRUE) {
928 if (buf->FORCADR)
929 continue;
930
931
932
933
934
935
936 register_pio_HBA(base, buf, tpnt);
937
938 if (base < 0x1000) {
939 for (x = 0; x < MAXISA; ++x) {
940 if (ISAbases[x] == base) {
941 ISAbases[x] = 0;
942 break;
943 }
944 }
945 } else if ((base & 0x0fff) == 0x0c88) {
946 x = (base >> 12) & 0x0f;
947 EISAbases[x] = 0;
948 }
949 continue;
950 }
951 }
952 }
953 } else
954 printk("eata_pio: error %x while reading "
955 "PCI_BASE_ADDRESS_0\n", error);
956 }
957 } else
958 printk("eata_pio: No BIOS32 extensions present. This driver release "
959 "still depends on it.\n"
960 " Skipping scan for PCI HBAs.\n");
961 #endif
962 return;
963 }
964
965
966 int eata_pio_detect(Scsi_Host_Template * tpnt)
967 {
968 struct Scsi_Host *HBA_ptr;
969 struct get_conf gc;
970 int i;
971
972 DBG((DBG_PROBE && DBG_DELAY) || DPT_DEBUG,
973 printk("Using lots of delays to let you read the debugging output\n"));
974
975
976 find_pio_PCI(&gc, tpnt);
977
978 find_pio_EISA(&gc, tpnt);
979
980 find_pio_ISA(&gc, tpnt);
981
982 for (i = 0; i <= MAXIRQ; i++)
983 if (reg_IRQ[i])
984 request_irq(i, eata_pio_int_handler, SA_INTERRUPT, "EATA-PIO");
985
986 HBA_ptr = first_HBA;
987
988 if (registered_HBAs != 0) {
989 printk("EATA (Extended Attachment) PIO driver version: %d.%d%s\n"
990 "(c) 1993-95 Michael Neuffer, neuffer@goofy.zdv.uni-mainz.de\n"
991 " Alfred Arnold, a.arnold@kfa-juelich.de\n"
992 "This release only supports DASD devices (harddisks)\n",
993 VER_MAJOR, VER_MINOR, VER_SUB);
994
995 printk("Registered HBAs:\n");
996 printk("HBA no. Boardtype: Revis: EATA: Bus: BaseIO: IRQ: Ch: ID: Pr:"
997 " QS: SG: CPL:\n");
998 for (i = 1; i <= registered_HBAs; i++) {
999 printk("scsi%-2d: %.10s v%s 2.0%c %s %#.4x %2d %d %d %c"
1000 " %2d %2d %2d\n",
1001 HBA_ptr->host_no, SD(HBA_ptr)->name, SD(HBA_ptr)->revision,
1002 SD(HBA_ptr)->EATA_revision, (SD(HBA_ptr)->bustype == 'P')?
1003 "PCI ":(SD(HBA_ptr)->bustype == 'E')?"EISA":"ISA ",
1004 (uint) HBA_ptr->base, HBA_ptr->irq, SD(HBA_ptr)->channel,
1005 HBA_ptr->this_id, (SD(HBA_ptr)->primary == TRUE)?'Y':'N',
1006 HBA_ptr->can_queue, HBA_ptr->sg_tablesize,
1007 HBA_ptr->cmd_per_lun);
1008 HBA_ptr = SD(HBA_ptr)->next;
1009 }
1010 }
1011 DBG(DPT_DEBUG,DELAY(12));
1012
1013 return (registered_HBAs);
1014 }
1015
1016 #ifdef MODULE
1017
1018 Scsi_Host_Template driver_template = EATA_PIO;
1019
1020 #include "scsi_module.c"
1021 #endif
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040