This source file includes following definitions.
- eata_scsi_done
- eata_release
- eata_info
- eata_int_handler
- eata_send_command
- eata_queue
- internal_done
- eata_command
- eata_abort
- eata_reset
- get_board_data
- check_blink_state
- get_conf_PIO
- print_config
- register_HBA
- find_EISA
- find_ISA
- find_PCI
- eata_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
41
42
43
44
45
46
47
48
49
50
51
52 #ifdef MODULE
53 #include <linux/module.h>
54 #endif
55
56 #include <linux/kernel.h>
57 #include <linux/sched.h>
58 #include <linux/string.h>
59 #include <linux/ioport.h>
60 #include <linux/malloc.h>
61 #include <linux/in.h>
62 #include <linux/bios32.h>
63 #include <linux/pci.h>
64 #include <asm/io.h>
65 #include <asm/dma.h>
66 #include "../block/blk.h"
67 #include "scsi.h"
68 #include "sd.h"
69 #include "hosts.h"
70 #include <linux/scsicam.h>
71 #include "eata_dma.h"
72
73 #if EATA_DMA_PROC
74 #include "eata_dma_proc.h"
75 ulong reads[13];
76 ulong writes[13];
77 #endif
78
79 static uint ISAbases[] =
80 {0x1F0, 0x170, 0x330, 0x230};
81 static unchar EISAbases[] =
82 {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
83 static uint registered_HBAs = 0;
84 static struct Scsi_Host *last_HBA = NULL;
85 static struct Scsi_Host *first_HBA = NULL;
86 static unchar reg_IRQ[] =
87 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
88 static unchar reg_IRQL[] =
89 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
90 static struct eata_sp status[MAXIRQ];
91
92 static uint internal_command_finished = TRUE;
93 static unchar HBA_interpret = FALSE;
94 static struct geom_emul geometry;
95
96 static ulong int_counter = 0;
97 static ulong queue_counter = 0;
98
99 void eata_scsi_done (Scsi_Cmnd * SCpnt)
100 {
101 return;
102 }
103
104 #if EATA_DMA_PROC
105 #include "eata_dma_proc.c"
106 #endif
107
108 int eata_release(struct Scsi_Host *sh)
109 {
110 if (sh->irq && reg_IRQ[sh->irq] == 1) free_irq(sh->irq);
111 else reg_IRQ[sh->irq]--;
112 if (SD(sh)->channel == 0) {
113 if (sh->dma_channel != 0xff) free_dma(sh->dma_channel);
114 if (sh->io_port && sh->n_io_port)
115 release_region(sh->io_port, sh->n_io_port);
116 }
117 return(TRUE);
118 }
119
120 const char *eata_info(struct Scsi_Host *host)
121 {
122 static char *information = "EATA SCSI HBA Driver";
123 return information;
124 }
125
126 void eata_int_handler(int irq, struct pt_regs * regs)
127 {
128 uint i, result;
129 uint hba_stat, scsi_stat, eata_stat;
130 Scsi_Cmnd *cmd;
131 struct eata_ccb *cp;
132 struct eata_sp *sp;
133 uint base;
134 ulong flags;
135 uint x;
136 struct Scsi_Host *sh;
137
138 save_flags(flags);
139 cli();
140
141 for (x = 1, sh = first_HBA; x <= registered_HBAs; x++, sh = SD(sh)->prev) {
142 if (sh->irq != irq)
143 continue;
144 if (!(inb((uint)sh->base + HA_RAUXSTAT) & HA_AIRQ))
145 continue;
146
147 int_counter++;
148
149 sp=&SD(sh)->sp;
150
151 cp = sp->ccb;
152 cmd = cp->cmd;
153 base = (uint) cmd->host->base;
154
155 hba_stat = sp->hba_stat;
156
157 scsi_stat = (sp->scsi_stat >> 1) && 0x1f;
158
159 if (sp->EOC == FALSE) {
160 eata_stat = inb(base + HA_RSTATUS);
161 printk("eata_dma: int_handler, board: %x cmd %lx returned "
162 "unfinished.\nEATA: %x HBA: %x SCSI: %x spadr %lx spadrirq "
163 "%lx, irq%d\n", base, (long)cp, eata_stat, hba_stat,
164 scsi_stat,(long)&status, (long)&status[irq], irq);
165 DBG(DBG_DELAY,DEL2(800));
166 restore_flags(flags);
167 return;
168 }
169
170 if (cp->status == LOCKED) {
171 cp->status = FREE;
172 eata_stat = inb(base + HA_RSTATUS);
173 printk("eata_dma: int_handler, freeing locked queueslot\n");
174 DBG(DBG_INTR&&DBG_DELAY,DEL2(800));
175 restore_flags(flags);
176 return;
177 }
178
179 eata_stat = inb(base + HA_RSTATUS);
180 DBG(DBG_INTR, printk("IRQ %d received, base %#.4x, pid %ld, target: "
181 "%x, lun: %x, ea_s: %#.2x, hba_s: %#.2x \n",
182 irq, base, cmd->pid, cmd->target, cmd->lun,
183 eata_stat, hba_stat));
184
185 switch (hba_stat) {
186 case 0x00:
187 if (scsi_stat == CONDITION_GOOD
188 && cmd->device->type == TYPE_DISK
189 && (HD(cmd)->t_state[cmd->target] == RESET))
190 result = DID_BUS_BUSY << 16;
191 else
192 result = DID_OK << 16;
193 if (scsi_stat == GOOD)
194 HD(cmd)->t_state[cmd->target] = FALSE;
195 HD(cmd)->t_timeout[cmd->target] = 0;
196 break;
197 case 0x01:
198 result = DID_BAD_TARGET << 16;
199 break;
200 case 0x02:
201 if (HD(cmd)->t_timeout[cmd->target] > 1)
202 result = DID_ERROR << 16;
203 else {
204 result = DID_TIME_OUT << 16;
205 HD(cmd)->t_timeout[cmd->target]++;
206 }
207 break;
208 case 0x03:
209 if (cmd->device->type != TYPE_TAPE)
210 result = DID_BUS_BUSY << 16;
211 else
212 result = DID_ERROR << 16;
213
214 for (i = 0; i < MAXTARGET; i++)
215 HD(cmd)->t_state[i] = RESET;
216 break;
217 case 0x07:
218 case 0x0c:
219 case 0x04:
220 case 0x05:
221 case 0x06:
222 case 0x08:
223 case 0x09:
224 case 0x0a:
225 case 0x0b:
226 default:
227 result = DID_ERROR << 16;
228 break;
229 }
230 cmd->result = result | scsi_stat;
231 if (in_scan_scsis && scsi_stat == CHECK_CONDITION &&
232 (cmd->sense_buffer[2] & 0xf) == UNIT_ATTENTION)
233 cmd->result |= (DRIVER_SENSE << 24);
234
235 #if DBG_INTR2
236 if (scsi_stat || result || hba_stat || eata_stat != 0x50)
237 printk("eata_stat: %#x hba_stat: %#.2x,scsi_stat: %#.2x, "
238 "sense_key: %#x, result: %#.8x\n", eata_stat, hba_stat,
239 scsi_stat,cmd->sense_buffer[2] & 0xf, cmd->result);
240 DBG(DBG_INTR&&DBG_DELAY,DEL2(800));
241 #endif
242
243 cp->status = FREE;
244
245 restore_flags(flags);
246 if(cmd->scsi_done != eata_scsi_done) cmd->scsi_done(cmd);
247 else {
248 internal_command_finished = TRUE;
249 HBA_interpret = FALSE;
250 }
251 save_flags(flags);
252 cli();
253 }
254 restore_flags(flags);
255
256 return;
257 }
258
259 inline uint eata_send_command(ulong addr, uint base, unchar command)
260 {
261 uint loop = R_LIMIT;
262
263 while (inb(base + HA_RAUXSTAT) & HA_ABUSY)
264 if (--loop == 0)
265 return(TRUE);
266
267 outb(addr & 0x000000ff, base + HA_WDMAADDR);
268 outb((addr & 0x0000ff00) >> 8, base + HA_WDMAADDR + 1);
269 outb((addr & 0x00ff0000) >> 16, base + HA_WDMAADDR + 2);
270 outb((addr & 0xff000000) >> 24, base + HA_WDMAADDR + 3);
271 outb(command, base + HA_WCOMMAND);
272 return(FALSE);
273 }
274
275 int eata_queue(Scsi_Cmnd * cmd, void *(done) (Scsi_Cmnd *))
276 {
277 uint i, x, y;
278 long flags;
279
280 hostdata *hd;
281 struct Scsi_Host *sh;
282 struct eata_ccb *cp;
283 struct scatterlist *sl;
284
285 save_flags(flags);
286 cli();
287
288 queue_counter++;
289
290 if (done == (void *)eata_scsi_done) {
291 if (internal_command_finished == TRUE)
292 internal_command_finished = FALSE;
293 else
294 cmd->result = (DID_ERROR << 16) + QUEUE_FULL;
295 }
296
297 hd = HD(cmd);
298 sh = cmd->host;
299
300
301 for (y = hd->last_ccb + 1, x = 0; x < sh->can_queue; x++, y++) {
302 if (y >= sh->can_queue)
303 y = 0;
304 if (hd->ccb[y].status == FREE)
305 break;
306 }
307
308 hd->last_ccb = y;
309
310 if (x == sh->can_queue) {
311
312 DBG(DBG_QUEUE, printk("can_queue %d, x %d, y %d\n",sh->can_queue,x,y));
313 #if DEBUG_EATA
314 panic("eata_dma: run out of queue slots cmdno:%ld intrno: %ld\n",
315 queue_counter, int_counter);
316 #else
317 panic("eata_dma: run out of queue slots....\n");
318 #endif
319 }
320
321 cp = &hd->ccb[y];
322
323 memset(cp, 0, sizeof(struct eata_ccb));
324
325 cp->status = USED;
326
327 DBG(DBG_QUEUE, printk("eata_queue pid %ld, target: %x, lun: %x, y %d\n",
328 cmd->pid, cmd->target, cmd->lun, y));
329 DBG(DBG_QUEUE && DBG_DELAY, DEL2(250));
330
331 cmd->scsi_done = (void *)done;
332
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 0x3f: case 0x41: case 0xb1:
341 case 0xb0: case 0xb2: case 0xaa:
342 case 0xae: case 0x24: case 0x38:
343 case 0x3d: case 0xb6:
344 case 0xea:
345 cp->DataOut = TRUE;
346 break;
347 case 0x00:
348 default:
349 cp->DataIn = TRUE;
350 }
351
352 if (done == (void *) eata_scsi_done && HBA_interpret == TRUE)
353 cp->Interpret = TRUE;
354
355 if (cmd->use_sg) {
356 cp->scatter = TRUE;
357 cp->cp_dataDMA = htonl((long)&cp->sg_list);
358 cp->cp_datalen = htonl(cmd->use_sg*8);
359 sl=(struct scatterlist *)cmd->request_buffer;
360
361 for(i = 0; i < cmd->use_sg; i++, sl++){
362 cp->sg_list[i].data = htonl((ulong) sl->address);
363 cp->sg_list[i].len = htonl((ulong) sl->length);
364 }
365 } else {
366 cp->scatter = FALSE;
367 cp->cp_datalen = htonl(cmd->request_bufflen);
368 cp->cp_dataDMA = htonl((ulong)cmd->request_buffer);
369 }
370
371 cp->Auto_Req_Sen = TRUE;
372 cp->cp_reqDMA = htonl((ulong) cmd->sense_buffer);
373 cp->reqlen = sizeof(cmd->sense_buffer);
374
375 cp->cp_id = cmd->target;
376 cp->cp_lun = cmd->lun;
377 cp->cp_dispri = TRUE;
378 cp->cp_identify = TRUE;
379 memcpy(cp->cp_cdb, cmd->cmnd, COMMAND_SIZE(*cmd->cmnd));
380
381 cp->cp_statDMA = htonl((ulong) &(hd->sp));
382
383 cp->cp_viraddr = cp;
384 cp->cmd = cmd;
385 cmd->host_scribble = (char *)&hd->ccb[y];
386
387 if(eata_send_command((ulong) cp, (uint) sh->base, EATA_CMD_DMA_SEND_CP)) {
388 cmd->result = DID_ERROR << 16;
389 printk("eata_queue target %d, pid %ld, HBA busy, returning DID_ERROR, done.\n",
390 cmd->target, cmd->pid);
391 restore_flags(flags);
392 if(done != (void *)eata_scsi_done) done(cmd);
393 return (0);
394 }
395 DBG(DBG_QUEUE,printk("Queued base %#.4lx pid: %ld target: %x lun: %x slot %d irq %d\n",
396 (long)sh->base, cmd->pid, cmd->target, cmd->lun, y, sh->irq));
397 DBG(DBG_QUEUE && DBG_DELAY, DEL2(200));
398 restore_flags(flags);
399 return (0);
400 }
401
402 static volatile int internal_done_flag = 0;
403 static volatile int internal_done_errcode = 0;
404
405 static void internal_done(Scsi_Cmnd * cmd)
406 {
407 internal_done_errcode = cmd->result;
408 ++internal_done_flag;
409 }
410
411 int eata_command(Scsi_Cmnd * cmd)
412 {
413
414 DBG(DBG_COM, printk("eata_command: calling eata_queue\n"));
415
416 eata_queue(cmd, (void *)internal_done);
417
418 while (!internal_done_flag);
419 internal_done_flag = 0;
420 return (internal_done_errcode);
421 }
422
423 int eata_abort(Scsi_Cmnd * cmd)
424 {
425 ulong flags;
426 uint loop = R_LIMIT;
427
428 save_flags(flags);
429 cli();
430
431 DBG(DBG_ABNORM, printk("eata_abort called pid: %ld target: %x lun: %x reason %x\n",
432 cmd->pid, cmd->target, cmd->lun, cmd->abort_reason));
433 DBG(DBG_ABNORM && DBG_DELAY, DEL2(500));
434
435
436 while (inb((uint)(cmd->host->base) + HA_RAUXSTAT) & HA_ABUSY)
437 if (--loop == 0) {
438 printk("eata_dma: abort, timeout error.\n");
439 restore_flags(flags);
440 DBG(DBG_ABNORM && DBG_DELAY, DEL2(500));
441 return (SCSI_ABORT_ERROR);
442 }
443 if (CD(cmd)->status == FREE) {
444 DBG(DBG_ABNORM, printk("Returning: SCSI_ABORT_NOT_RUNNING\n"));
445 restore_flags(flags);
446 return (SCSI_ABORT_NOT_RUNNING);
447 }
448 if (CD(cmd)->status == USED) {
449 DBG(DBG_ABNORM, printk("Returning: SCSI_ABORT_BUSY\n"));
450 restore_flags(flags);
451 return (SCSI_ABORT_BUSY);
452 }
453 if (CD(cmd)->status == RESET) {
454 restore_flags(flags);
455 printk("eata_dma: abort, command reset error.\n");
456 DBG(DBG_ABNORM && DBG_DELAY, DEL2(500));
457 return (SCSI_ABORT_ERROR);
458 }
459 if (CD(cmd)->status == LOCKED) {
460 restore_flags(flags);
461 DBG(DBG_ABNORM, printk("eata_dma: abort, queue slot locked.\n"));
462 DBG(DBG_ABNORM && DBG_DELAY, DEL2(500));
463 return (SCSI_ABORT_NOT_RUNNING);
464 } else
465 panic("eata_dma: abort: invalid slot status\n");
466 }
467
468 int eata_reset(Scsi_Cmnd * cmd)
469 {
470 uint x, z, time, limit = 0;
471 uint loop = R_LIMIT;
472 ulong flags;
473 unchar success = FALSE;
474 Scsi_Cmnd *sp;
475
476 save_flags(flags);
477 cli();
478
479 DBG(DBG_ABNORM, printk("eata_reset called pid:%ld target: %x lun: %x reason %x\n",
480 cmd->pid, cmd->target, cmd->lun, cmd->abort_reason));
481
482
483 if (HD(cmd)->state == RESET) {
484 printk("eata_reset: exit, already in reset.\n");
485 restore_flags(flags);
486 DBG(DBG_ABNORM && DBG_DELAY, DEL2(500));
487 return (SCSI_RESET_ERROR);
488 }
489
490 while (inb((uint)(cmd->host->base) + HA_RAUXSTAT) & HA_ABUSY)
491 if (--loop == 0) {
492 printk("eata_reset: exit, timeout error.\n");
493 restore_flags(flags);
494 DBG(DBG_ABNORM && DBG_DELAY, DEL2(500));
495 return (SCSI_RESET_ERROR);
496 }
497 for (z = 0; z < MAXTARGET; z++)
498 HD(cmd)->t_state[z] = RESET;
499
500 for (x = 0; x < cmd->host->can_queue; x++) {
501
502 if (HD(cmd)->ccb[x].status == FREE)
503 continue;
504
505 if (HD(cmd)->ccb[x].status == LOCKED) {
506 HD(cmd)->ccb[x].status = FREE;
507 printk("eata_reset: locked slot %d forced free.\n", x);
508 DBG(DBG_ABNORM && DBG_DELAY, DEL2(500));
509 continue;
510 }
511 sp = HD(cmd)->ccb[x].cmd;
512 HD(cmd)->ccb[x].status = RESET;
513 printk("eata_reset: slot %d in reset, pid %ld.\n", x, sp->pid);
514 DBG(DBG_ABNORM && DBG_DELAY, DEL2(500));
515
516 if (sp == NULL)
517 panic("eata_reset: slot %d, sp==NULL.\n", x);
518 DBG(DBG_ABNORM && DBG_DELAY, DEL2(500));
519
520 if (sp == cmd)
521 success = TRUE;
522 }
523
524
525 inb((uint) (cmd->host->base) + HA_RSTATUS);
526 eata_send_command(0, (uint) cmd->host->base, EATA_CMD_RESET);
527
528 DBG(DBG_ABNORM, printk("eata_reset: board reset done, enabling interrupts.\n"));
529 HD(cmd)->state = RESET;
530
531 restore_flags(flags);
532
533 time = jiffies;
534 while (jiffies < (time + 300) && limit++ < 10000000);
535
536 save_flags(flags);
537 cli();
538
539 DBG(DBG_ABNORM, printk("eata_reset: interrupts disabled, loops %d.\n", limit));
540 DBG(DBG_ABNORM && DBG_DELAY, DEL2(500));
541
542 for (x = 0; x < cmd->host->can_queue; x++) {
543
544
545 if (HD(cmd)->ccb[x].status != RESET)
546 continue;
547
548 sp = HD(cmd)->ccb[x].cmd;
549 sp->result = DID_RESET << 16;
550
551
552 HD(cmd)->ccb[x].status = LOCKED;
553
554 printk("eata_reset: slot %d locked, DID_RESET, pid %ld done.\n",
555 x, sp->pid);
556 DBG(DBG_ABNORM && DBG_DELAY, DEL2(500));
557 restore_flags(flags);
558 sp->scsi_done(sp);
559 cli();
560 }
561
562 HD(cmd)->state = FALSE;
563 restore_flags(flags);
564
565 if (success) {
566 DBG(DBG_ABNORM, printk("eata_reset: exit, success.\n"));
567 DBG(DBG_ABNORM && DBG_DELAY, DEL2(500));
568 return (SCSI_RESET_SUCCESS);
569 } else {
570 DBG(DBG_ABNORM, printk("eata_reset: exit, wakeup.\n"));
571 DBG(DBG_ABNORM && DBG_DELAY, DEL2(500));
572 return (SCSI_RESET_PUNT);
573 }
574 }
575
576 char * get_board_data(ulong base, uint irq, uint id)
577 {
578 struct eata_ccb cp;
579 struct eata_sp sp;
580 static char buff[256];
581
582 memset(&cp, 0, sizeof(struct eata_ccb));
583 memset(buff, 0, sizeof(buff));
584
585 cp.DataIn = TRUE;
586 cp.Interpret = TRUE;
587
588 cp.cp_datalen = htonl(255);
589 cp.cp_dataDMA = htonl((long)buff);
590
591 cp.cp_id = id;
592 cp.cp_lun = 0;
593
594 cp.cp_cdb[0] = INQUIRY;
595 cp.cp_cdb[1] = 0;
596 cp.cp_cdb[2] = 0;
597 cp.cp_cdb[3] = 0;
598 cp.cp_cdb[4] = 255;
599 cp.cp_cdb[5] = 0;
600
601 cp.cp_statDMA = htonl((ulong) &sp);
602
603 eata_send_command((ulong) &cp, (uint) base, EATA_CMD_DMA_SEND_CP);
604 while (!(inb(base + HA_RAUXSTAT) & HA_AIRQ));
605 if(inb((uint) base + HA_RSTATUS) & 1)
606 return (NULL);
607 else
608 return (buff);
609 }
610
611 int check_blink_state(long base)
612 {
613 uint ret = 0;
614 uint loops = 10;
615 ulong blinkindicator = 0x42445054;
616 ulong state = 0x12345678;
617 ulong oldstate = 0;
618
619 while ((loops--) && (state != oldstate)) {
620 oldstate = state;
621 state = inl((uint) base + 1);
622 }
623
624 if ((state == oldstate) && (state == blinkindicator))
625 ret = 1;
626 DBG(DBG_BLINK, printk("Did Blink check. Status: %d\n", ret));
627 return (ret);
628 }
629
630 int get_conf_PIO(struct eata_register *base, struct get_conf *buf)
631 {
632 ulong loop = R_LIMIT;
633 ushort *p;
634
635 if(check_region((uint)base, 9))
636 return (FALSE);
637
638 memset(buf, 0, sizeof(struct get_conf));
639
640 while (inb((uint) base + HA_RSTATUS) & HA_SBUSY)
641 if (--loop == 0)
642 return (FALSE);
643
644 DBG(DBG_PIO && DBG_PROBE,printk("Issuing PIO READ CONFIG to HBA at %lx\n",
645 (long)base));
646 eata_send_command(0, (uint) base, EATA_CMD_PIO_READ_CONFIG);
647 loop = R_LIMIT;
648 for (p = (ushort *) buf;
649 (long)p <= ((long)buf + (sizeof(struct get_conf)/ 2)); p++) {
650 while (!(inb((uint) base + HA_RSTATUS) & HA_SDRQ))
651 if (--loop == 0)
652 return (FALSE);
653 loop = R_LIMIT;
654 *p = inw((uint) base + HA_RDATA);
655 }
656 if (!(inb((uint) base + HA_RSTATUS) & HA_SERROR)) {
657 DBG(DBG_PIO&&DBG_PROBE, printk("\nSignature: %c%c%c%c\n",
658 (char)buf->sig[0], (char)buf->sig[1],
659 (char)buf->sig[2], (char)buf->sig[3]));
660
661 if ((buf->sig[0] == 'E') && (buf->sig[1] == 'A')
662 && (buf->sig[2] == 'T') && (buf->sig[3] == 'A')) {
663 DBG(DBG_PIO&&DBG_PROBE, printk("EATA Controller found at %x "
664 "EATA Level: %x\n", (uint) base, (uint) (buf->version)));
665
666 while (inb((uint) base + HA_RSTATUS) & HA_SDRQ)
667 inw((uint) base + HA_RDATA);
668 return (TRUE);
669 }
670 } else {
671 printk("eata_dma: get_conf_PIO, error during transfer for HBA at %lx",
672 (long)base);
673 }
674 return (FALSE);
675 }
676
677 void print_config(struct get_conf *gc)
678 {
679 printk("Please check values: (read config data)\n");
680 printk("LEN: %d ver:%d OCS:%d TAR:%d TRNXFR:%d MORES:%d DMAS:%d\n",
681 (uint) ntohl(gc->len), gc->version,
682 gc->OCS_enabled, gc->TAR_support, gc->TRNXFR, gc->MORE_support,
683 gc->DMA_support);
684 printk("DMAV:%d HAAV:%d SCSIID0:%d ID1:%d ID2:%d QUEUE:%d SG:%d SEC:%d\n",
685 gc->DMA_valid, gc->HAA_valid, gc->scsi_id[3], gc->scsi_id[2],
686 gc->scsi_id[1], ntohs(gc->queuesiz), ntohs(gc->SGsiz), gc->SECOND);
687 printk("IRQ:%d IRQT:%d DMAC:%d FORCADR:%d MCH:%d RIDQ:%d PCI:%d EISA:%d\n",
688 gc->IRQ, gc->IRQ_TR, (8 - gc->DMA_channel) & 7, gc->FORCADR,
689 gc->MAX_CHAN, gc->ID_qest, gc->is_PCI, gc->is_EISA);
690 DBG(DPT_DEBUG, DELAY(1400));
691 }
692
693 int register_HBA(long base, struct get_conf *gc, Scsi_Host_Template * tpnt)
694 {
695 ulong size = 0;
696 unchar dma_channel = 0;
697 char *buff;
698 uint i;
699 struct Scsi_Host *sh;
700 hostdata *hd;
701
702 DBG(DBG_REGISTER, print_config(gc));
703
704 if (!gc->DMA_support) {
705 printk("HBA at %#.8lx doesn't support DMA. Sorry\n",base);
706 return (FALSE);
707 }
708
709 if ((buff = get_board_data((uint)base, gc->IRQ, gc->scsi_id[3])) == NULL){
710 printk("HBA at %#lx didn't react on INQUIRY. Sorry.\n", (ulong) base);
711 return (FALSE);
712 }
713
714 if(gc->HAA_valid == FALSE || ntohl(gc->len) <= 0x1e)
715 gc->MAX_CHAN = 0;
716
717 if(strncmp("PM2322", &buff[16], 6) && strncmp("PM3021", &buff[16], 6)
718 && strncmp("PM3222", &buff[16], 6) && strncmp("PM3224", &buff[16], 6))
719 gc->MAX_CHAN = 0;
720
721
722 dma_channel = 0xff;
723 if (gc->DMA_valid) {
724 if (request_dma(dma_channel = (8 - gc->DMA_channel) & 7, "DPT_PM2011")) {
725 printk("Unable to allocate DMA channel %d for HBA PM2011.\n",
726 dma_channel);
727 return (FALSE);
728 }
729 }
730
731 if (!reg_IRQ[gc->IRQ]) {
732 if (!request_irq(gc->IRQ, eata_int_handler, SA_INTERRUPT, "EATA-DMA")){
733 reg_IRQ[gc->IRQ] += (gc->MAX_CHAN+1);
734 if (!gc->IRQ_TR)
735 reg_IRQL[gc->IRQ] = TRUE;
736
737
738
739 free_irq(gc->IRQ);
740 } else {
741 printk("Couldn't allocate IRQ %d, Sorry.", gc->IRQ);
742 return (FALSE);
743 }
744 } else {
745 if (reg_IRQL[gc->IRQ] == TRUE) {
746 printk("Can't support more than one HBA on this IRQ,\n"
747 " if the IRQ is edge triggered. Sorry.\n");
748 return (FALSE);
749 } else
750 reg_IRQ[gc->IRQ] += (gc->MAX_CHAN+1);
751 }
752
753 request_region(base, 9, "eata_dma");
754
755 if(ntohs(gc->queuesiz) == 0) {
756 gc->queuesiz = ntohs(64);
757 printk("Warning: Queue size had to be corrected.\n"
758 "This might be a PM2012 with a defective Firmware\n");
759 }
760
761 size = sizeof(hostdata) + ((sizeof(struct eata_ccb) * ntohs(gc->queuesiz))/
762 (gc->MAX_CHAN + 1));
763
764 if (gc->MAX_CHAN) {
765 printk("This is a multichannel HBA. Linux doesn't support them,\n");
766 printk("so we'll try to register every channel as a virtual HBA.\n");
767 }
768
769 for (i = 0; i <= gc->MAX_CHAN; i++) {
770
771 sh = scsi_register(tpnt, size);
772 hd = SD(sh);
773
774 memset(hd->ccb, 0, (sizeof(struct eata_ccb) * ntohs(gc->queuesiz)) /
775 (gc->MAX_CHAN + 1));
776 memset(hd->reads, 0, sizeof(ulong) * 26);
777
778 strncpy(SD(sh)->vendor, &buff[8], 8);
779 SD(sh)->vendor[8] = 0;
780 strncpy(SD(sh)->name, &buff[16], 17);
781 SD(sh)->name[17] = 0;
782 SD(sh)->revision[0] = buff[32];
783 SD(sh)->revision[1] = buff[33];
784 SD(sh)->revision[2] = buff[34];
785 SD(sh)->revision[3] = '.';
786 SD(sh)->revision[4] = buff[35];
787 SD(sh)->revision[5] = 0;
788 switch (ntohl(gc->len)) {
789 case 0x1c:
790 SD(sh)->EATA_revision = 'a';
791 break;
792 case 0x1e:
793 SD(sh)->EATA_revision = 'b';
794 break;
795 case 0x22:
796 SD(sh)->EATA_revision = 'c';
797 break;
798 default:
799 SD(sh)->EATA_revision = '?';
800 }
801 sh->base = (char *) base;
802 sh->io_port = (ushort) base;
803 sh->n_io_port = 9;
804 sh->irq = gc->IRQ;
805 sh->dma_channel = dma_channel;
806 sh->this_id = gc->scsi_id[3 - i];
807 sh->can_queue = ntohs(gc->queuesiz) / (gc->MAX_CHAN + 1);
808
809 if (gc->OCS_enabled == TRUE) {
810 sh->cmd_per_lun = sh->can_queue/C_P_L_DIV;
811 if (sh->cmd_per_lun > C_P_L_CURRENT_MAX)
812 sh->cmd_per_lun = C_P_L_CURRENT_MAX;
813 } else {
814 sh->cmd_per_lun = 1;
815 }
816 sh->sg_tablesize = ntohs(gc->SGsiz);
817 if (sh->sg_tablesize > SG_SIZE || sh->sg_tablesize == 0) {
818 sh->sg_tablesize = SG_SIZE;
819 if (ntohs(gc->SGsiz) == 0)
820 printk("Warning: SG size had to be corrected.\n"
821 "This might be a PM2012 with a defective Firmware\n");
822 }
823
824 hd->channel = i;
825
826 if (buff[21] == '4')
827 hd->bustype = 'P';
828 else if (buff[21] == '2')
829 hd->bustype = 'E';
830 else
831 hd->bustype = 'I';
832
833 if (gc->SECOND)
834 hd->primary = FALSE;
835 else
836 hd->primary = TRUE;
837
838 if (hd->bustype != 'I') {
839 sh->unchecked_isa_dma = FALSE;
840 sh->wish_block = FALSE;
841 }
842 else {
843 sh->unchecked_isa_dma = TRUE;
844 sh->wish_block = TRUE;
845 }
846 if((hd->primary == TRUE) && (i == 0) && HARDCODED){
847 geometry.drv[0].heads = HEADS0;
848 geometry.drv[0].sectors = SECTORS0;
849 geometry.drv[0].cylinder = CYLINDER0;
850 geometry.drv[0].id = ID0;
851 geometry.drv[0].trans = TRUE;
852 geometry.drv[1].heads = HEADS1;
853 geometry.drv[1].sectors = SECTORS1;
854 geometry.drv[1].cylinder = CYLINDER1;
855 geometry.drv[1].id = ID1;
856 geometry.drv[1].trans = TRUE;
857 } else {
858 geometry.drv[0].id=-1;
859 geometry.drv[1].id=-1;
860 }
861
862 hd->next = NULL;
863 hd->prev = last_HBA;
864 if(hd->prev != NULL)
865 SD(hd->prev)->next = sh;
866 last_HBA = sh;
867 if (first_HBA == NULL)
868 first_HBA = sh;
869 registered_HBAs++;
870 }
871 return (1);
872 }
873
874
875 long find_EISA(struct get_conf *buf)
876 {
877 struct eata_register *base;
878 int i;
879
880 #if CHECKPAL
881 unsigned char pal1, pal2, pal3, *p;
882 #endif
883
884 for (i = 0; i < MAXEISA; i++) {
885 if (EISAbases[i] == TRUE) {
886
887 base = (void *)0x1c88 + (i * 0x1000);
888 #if CHECKPAL
889 p = (char *)base;
890 pal1 = *(p - 8);
891 pal2 = *(p - 7);
892 pal3 = *(p - 6);
893
894 if (((pal1 == 0x12) && (pal2 == 0x14)) ||
895 ((pal1 == 0x38) && (pal2 == 0xa3) && (pal3 == 0x82)) ||
896 ((pal1 == 0x06) && (pal2 == 0x94) && (pal3 == 0x24))) {
897 DBG(DBG_PROBE, printk("EISA EATA id tags found: %x %x %x \n",
898 (int)pal1, (int)pal2, (int)pal3));
899 #endif
900 if (get_conf_PIO(base, buf) == TRUE) {
901 DBG(DBG_PROBE&&DBG_EISA,print_config(buf));
902 if (buf->IRQ) {
903
904
905
906 EISAbases[i] = 0;
907 return ((ulong)base);
908 }
909 printk("No valid IRQ. HBA removed from list\n");
910 }
911
912 EISAbases[i] = 0;
913 #if CHECKPAL
914 }
915 #endif
916 }
917 }
918 return (0l);
919 }
920
921 long find_ISA(struct get_conf *buf)
922 {
923 int l;
924 long ret;
925
926 for (l = 0; l < MAXISA; l++) {
927 if (ISAbases[l]) {
928 if (get_conf_PIO((struct eata_register *)ISAbases[l],buf) == TRUE){
929 ret = ISAbases[l];
930 ISAbases[l] = 0;
931 return (ret);
932 } else
933 ISAbases[l] = 0;
934 }
935 }
936 return ((long)NULL);
937 }
938
939 void find_PCI(struct get_conf *buf, Scsi_Host_Template * tpnt)
940 {
941
942 #ifndef CONFIG_PCI
943 printk("Kernel PCI support not enabled. Skipping.\n");
944 #else
945
946 unchar pci_bus, pci_device_fn;
947 static short pci_index = 0;
948 ulong base = 0;
949 ushort com_adr;
950 ushort rev_device;
951 uint error, i, x;
952
953 if (pcibios_present()) {
954 for (i = 0; i <= MAXPCI; ++i, ++pci_index) {
955
956 if (pcibios_find_device(PCI_VENDOR_ID_DPT, PCI_DEVICE_ID_DPT,
957 pci_index, &pci_bus, &pci_device_fn))
958 break;
959 DBG(DBG_PROBE && DBG_PCI, printk("eata_dma: HBA at bus %d, device %d,"
960 " function %d, index %d\n", (int)pci_bus,
961 (int)((pci_device_fn & 0xf8) >> 3),
962 (int)(pci_device_fn & 7), pci_index));
963
964 if (!(error = pcibios_read_config_word(pci_bus, pci_device_fn,
965 PCI_CLASS_DEVICE, &rev_device))) {
966 if (rev_device == PCI_CLASS_STORAGE_SCSI) {
967 if (!(error = pcibios_read_config_word(pci_bus,
968 pci_device_fn, PCI_COMMAND,
969 (ushort *) & com_adr))) {
970 if (!((com_adr & PCI_COMMAND_IO) &&
971 (com_adr & PCI_COMMAND_MASTER))) {
972 printk("HBA has IO or BUSMASTER mode disabled\n");
973 continue;
974 }
975 } else
976 printk("error %x while reading PCI_COMMAND\n", error);
977 } else
978 printk("DEVICECLASSID %x didn't match\n", rev_device);
979 } else {
980 printk("error %x while reading PCI_CLASS_BASE\n", error);
981 continue;
982 }
983
984 if (!(error = pcibios_read_config_dword(pci_bus, pci_device_fn,
985 PCI_BASE_ADDRESS_0, &base))){
986
987
988 if (base & 0x01) {
989 base &= 0xfffffffe;
990
991 if ((inb(base) == 0x12) && (inb(base + 1) == 0x14))
992 continue;
993 base += 0x10;
994 if (base != 0x1f8) {
995
996 if (get_conf_PIO((struct eata_register *)base, buf)) {
997 if (buf->FORCADR)
998 continue;
999
1000
1001
1002
1003
1004
1005 register_HBA(base, buf, tpnt);
1006
1007 if (base < 0x1000) {
1008 for (x = 0; x < MAXISA; ++x) {
1009 if (ISAbases[x] == base) {
1010 ISAbases[x] = 0;
1011 break;
1012 }
1013 }
1014 } else if ((base & 0x0fff) == 0x0c88) {
1015 x = (base >> 12) & 0x0f;
1016 EISAbases[x] = 0;
1017 }
1018 continue;
1019 } else if (check_blink_state(base)) {
1020 printk("HBA is in BLINK state. Consult your HBAs "
1021 " Manual to correct this.\n");
1022 }
1023 }
1024 }
1025 } else
1026 printk("error %x while reading PCI_BASE_ADDRESS_0\n", error);
1027 }
1028 } else
1029 printk("No BIOS32 extensions present. This release still depends on it."
1030 " Sorry.\n");
1031 #endif
1032 return;
1033 }
1034
1035 int eata_detect(Scsi_Host_Template * tpnt)
1036 {
1037 struct Scsi_Host *HBA_ptr;
1038 struct get_conf gc;
1039 ulong base = 0;
1040 int i;
1041
1042 geometry.drv[0].trans = geometry.drv[1].trans = 0;
1043
1044 printk("EATA (Extended Attachment) driver version: %d.%d%s\n"
1045 "developed in co-operation with DPT\n"
1046 "(c) 1993-95 Michael Neuffer neuffer@goofy.zdv.uni-mainz.de\n",
1047 VER_MAJOR, VER_MINOR, VER_SUB);
1048
1049 DBG((DBG_PROBE && DBG_DELAY)|| DPT_DEBUG,
1050 printk("Using lots of delays to let you read the debugging output\n"));
1051
1052 find_PCI(&gc, tpnt);
1053
1054 for (i = 0; i < MAXEISA; i++) {
1055 base = find_EISA(&gc);
1056 if (base)
1057 register_HBA(base, &gc, tpnt);
1058 }
1059
1060 for (i = 0; i <= MAXISA; i++) {
1061 base = find_ISA(&gc);
1062 if (base)
1063 register_HBA(base, &gc, tpnt);
1064 }
1065
1066 for (i = 0; i <= MAXIRQ; i++)
1067 if (reg_IRQ[i])
1068 request_irq(i, eata_int_handler, SA_INTERRUPT, "EATA-DMA");
1069
1070 HBA_ptr = first_HBA;
1071
1072 printk("Registered HBAs:\n");
1073 printk("HBA no. Boardtype: Revis: EATA: Bus: BaseIO: IRQ: DMA: Ch: ID: Pr: QS: SG: CPL:\n");
1074 for (i = 1; i <= registered_HBAs; i++) {
1075 printk("scsi%-2d: %.10s v%s 2.0%c %s %#.4x %2d %2x %d %d %d %2d %2d %2d\n",
1076 HBA_ptr->host_no, SD(HBA_ptr)->name, SD(HBA_ptr)->revision,
1077 SD(HBA_ptr)->EATA_revision, (SD(HBA_ptr)->bustype == 'P')?
1078 "PCI ":(SD(HBA_ptr)->bustype == 'E')?"EISA":"ISA ",
1079 (uint) HBA_ptr->base, HBA_ptr->irq, HBA_ptr->dma_channel,
1080 SD(HBA_ptr)->channel, HBA_ptr->this_id, SD(HBA_ptr)->primary,
1081 HBA_ptr->can_queue, HBA_ptr->sg_tablesize, HBA_ptr->cmd_per_lun);
1082 HBA_ptr = SD(HBA_ptr)->next;
1083 }
1084 DBG(DPT_DEBUG,DELAY(1200));
1085
1086 return (registered_HBAs);
1087 }
1088
1089 #ifdef MODULE
1090
1091 Scsi_Host_Template driver_template = EATA_DMA;
1092
1093 #include "scsi_module.c"
1094 #endif
1095
1096