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