This source file includes following definitions.
- wait
- buslogic_prefix
- buslogic_stat
- buslogic_out
- buslogic_in
- makecode
- buslogic_info
- buslogic_interrupt
- buslogic_queuecommand
- internal_done
- buslogic_command
- setup_mailboxes
- getconfig
- buslogic_query
- buslogic_detect
- restart
- buslogic_abort
- buslogic_reset
- buslogic_biosparam
- buslogic_setup
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78 #ifdef MODULE
79 #include <linux/module.h>
80 #endif
81
82 #include <linux/string.h>
83 #include <linux/sched.h>
84 #include <linux/kernel.h>
85 #include <linux/head.h>
86 #include <linux/types.h>
87 #include <linux/ioport.h>
88 #include <linux/delay.h>
89 #include <linux/config.h>
90
91 #include <asm/io.h>
92 #include <asm/system.h>
93 #include <asm/dma.h>
94
95 #include "../block/blk.h"
96 #include "scsi.h"
97 #include "hosts.h"
98 #include "sd.h"
99 #define BUSLOGIC_PRIVATE_H
100 #include "buslogic.h"
101
102 #ifndef BUSLOGIC_DEBUG
103 # define BUSLOGIC_DEBUG 0
104 #endif
105
106
107 #undef GFP_DMA
108
109
110
111
112
113
114
115
116
117
118
119
120
121 #define BUSLOGIC_VERSION "1.14"
122
123
124
125
126
127 #define WAITNEXTTIMEOUT 3000000
128
129
130
131
132
133
134
135 #define BUSLOGIC_SG_MALLOC 512
136
137
138 #define BUSLOGIC_MAX_SG (BUSLOGIC_SG_MALLOC / sizeof (struct chain))
139
140
141
142 #define BUSLOGIC_MAILBOXES 16
143
144 #define BUSLOGIC_CMDLUN 4
145
146
147
148
149
150
151
152
153 static unsigned short bases[7] = {
154 #ifdef BUSLOGIC_PORT_OVERRIDE
155 BUSLOGIC_PORT_OVERRIDE,
156 #else
157 0x330, 0x334,
158 #endif
159 0
160 };
161
162 #define BIOS_TRANSLATION_DEFAULT 0
163 #define BIOS_TRANSLATION_BIG 1
164
165 struct hostdata {
166 unsigned int bus_type;
167 unsigned int bios_translation: 1;
168 size_t last_mbi_used;
169 size_t last_mbo_used;
170 char model[7];
171 char firmware_rev[6];
172 Scsi_Cmnd *sc[BUSLOGIC_MAILBOXES];
173 struct mailbox mb[2 * BUSLOGIC_MAILBOXES];
174 struct ccb ccbs[BUSLOGIC_MAILBOXES];
175 };
176
177 #define HOSTDATA(host) ((struct hostdata *)&(host)->hostdata)
178
179
180 static struct Scsi_Host *host[7] = { NULL, };
181
182 static int setup_mailboxes(unsigned int base, struct Scsi_Host *shpnt);
183 static int restart(struct Scsi_Host *shpnt);
184
185 #define INTR_RESET(base) outb(RINT, CONTROL(base))
186
187 #define buslogic_printk buslogic_prefix(__PRETTY_FUNCTION__),printk
188
189 #if defined(MODULE) && !defined(GFP_DMA)
190 # define CHECK_DMA_ADDR(isa, addr, badstmt) \
191 do { if ((isa) && (addr) > (void *)ISA_DMA_THRESHOLD) badstmt; } while (0)
192 #else
193 # define CHECK_DMA_ADDR(isa, addr, badstmt)
194 #endif
195
196 #define CHECK(cond) if (cond) ; else goto fail
197
198 #define WAIT(port, allof, noneof) \
199 CHECK(wait(port, allof, noneof, WAITNEXTTIMEOUT, FALSE))
200 #define WAIT_WHILE(port, mask) WAIT(port, 0, mask)
201 #define WAIT_UNTIL(port, mask) WAIT(port, mask, 0)
202 #define WAIT_FAST(port, allof, noneof) \
203 CHECK(wait(port, allof, noneof, 100, TRUE))
204 #define WAIT_WHILE_FAST(port, mask) WAIT_FAST(port, 0, mask)
205 #define WAIT_UNTIL_FAST(port, mask) WAIT_FAST(port, mask, 0)
206
207
208
209
210
211
212 static __inline__ int wait(unsigned short port,
213 unsigned char allof, unsigned char noneof,
214 unsigned int timeout, int delay)
215 {
216 int bits;
217
218 for (;;) {
219 bits = inb(port);
220 if ((bits & allof) == allof && (bits & noneof) == 0)
221 return TRUE;
222 if (delay)
223 udelay(1000);
224 if (--timeout == 0)
225 return FALSE;
226 }
227 }
228
229 static void buslogic_prefix(const char *func)
230 {
231 printk("BusLogic SCSI: %s: ", func);
232 }
233
234 static void buslogic_stat(unsigned int base)
235 {
236 int s = inb(STATUS(base)), i = inb(INTERRUPT(base));
237
238 buslogic_printk("status=%02X intrflags=%02X\n", s, i);
239 }
240
241
242
243
244
245 static int buslogic_out(unsigned int base, const unsigned char *cmdp,
246 size_t len)
247 {
248 unsigned long flags = 0;
249
250 if (len == 1) {
251 for (;;) {
252 WAIT_WHILE(STATUS(base), CPRBSY);
253 save_flags(flags);
254 cli();
255 if (!(inb(STATUS(base)) & CPRBSY)) {
256 outb(*cmdp, COMMAND_PARAMETER(base));
257 restore_flags(flags);
258 return FALSE;
259 }
260 restore_flags(flags);
261 }
262 } else {
263 save_flags(flags);
264 cli();
265 while (len--) {
266 WAIT_WHILE(STATUS(base), CPRBSY);
267 outb(*cmdp++, COMMAND_PARAMETER(base));
268 }
269 restore_flags(flags);
270 }
271 return FALSE;
272 fail:
273 restore_flags(flags);
274 buslogic_printk("failed(%u): ", len + 1);
275 buslogic_stat(base);
276 return TRUE;
277 }
278
279
280
281
282 static int buslogic_in(unsigned int base, unsigned char *cmdp, size_t len)
283 {
284 unsigned long flags;
285
286 save_flags(flags);
287 cli();
288 while (len--) {
289 WAIT_UNTIL_FAST(STATUS(base), DIRRDY);
290 *cmdp++ = inb(DATA_IN(base));
291 }
292 restore_flags(flags);
293 return FALSE;
294 fail:
295 restore_flags(flags);
296 #if (BUSLOGIC_DEBUG & BD_IO)
297 buslogic_printk("failed(%u): ", len + 1);
298 buslogic_stat(base);
299 #endif
300 return TRUE;
301 }
302
303 static unsigned int makecode(unsigned int haerr, unsigned int scsierr)
304 {
305 unsigned int hosterr;
306 const char *errstr = NULL;
307 #if (BUSLOGIC_DEBUG & BD_ERRORS) && defined(CONFIG_SCSI_CONSTANTS)
308 static const char *const buslogic_status[] = {
309 "Command completed normally",
310 NULL, NULL, NULL, NULL, NULL, NULL, NULL,
311 NULL, NULL,
312 "Linked command completed normally",
313 "Linked command completed normally, interrupt generated",
314 NULL, NULL, NULL, NULL,
315 NULL,
316 "Selection timed out",
317 "Data overrun/underrun",
318 "Unexpected bus free",
319 "Target bus phase sequence failure",
320 "First byte of outgoing MB was invalid",
321 "Invalid CCB Operation Code",
322 "Linked CCB does not have the same LUN",
323 "Invalid Target Direction received from Host",
324 "Duplicate CCB Received in Target Mode",
325 "Invalid CCB or Segment List Parameter",
326 "Auto request sense failed",
327 "SCSI-2 tagged queueing message was rejected by the target",
328 NULL, NULL, NULL,
329 "Host adapter hardware failure",
330 "Target did not respond to SCSI ATN and the HA SCSI bus reset",
331 "Host adapter asserted a SCSI bus reset",
332 "Other SCSI devices asserted a SCSI bus reset",
333 };
334 #endif
335
336 switch (haerr) {
337 case 0x00:
338 case 0x0A:
339
340 case 0x0B:
341
342 hosterr = DID_OK;
343 break;
344
345 case 0x11:
346
347
348 hosterr = DID_TIME_OUT;
349 break;
350
351 case 0x14:
352
353
354
355
356 case 0x21:
357
358
359 case 0x22:
360 hosterr = DID_RESET;
361 break;
362
363 case 0x12:
364
365
366
367 case 0x13:
368
369 case 0x15:
370
371
372 case 0x16:
373
374
375 case 0x17:
376
377
378
379 case 0x18:
380
381 case 0x19:
382
383
384
385 case 0x1A:
386
387
388
389 case 0x1B:
390 case 0x1C:
391
392 case 0x20:
393 case 0x23:
394 hosterr = DID_ERROR;
395 break;
396
397 default:
398 #ifndef CONFIG_SCSI_CONSTANTS
399 errstr = "unknown hoststatus";
400 #endif
401 hosterr = DID_ERROR;
402 break;
403 }
404 #if (BUSLOGIC_DEBUG & BD_ERRORS)
405 # ifdef CONFIG_SCSI_CONSTANTS
406 if (hosterr != DID_OK) {
407 if (haerr < ARRAY_SIZE(buslogic_status))
408 errstr = buslogic_status[haerr];
409 if (errstr == NULL)
410 errstr = "unknown hoststatus";
411 }
412 # else
413 if (hosterr == DID_ERROR)
414 errstr = "";
415 # endif
416 #endif
417 if (errstr != NULL)
418 buslogic_printk("%s (%02X)\n", errstr, haerr);
419 return (hosterr << 16) | scsierr;
420 }
421
422
423 const char *buslogic_info(struct Scsi_Host *shpnt)
424 {
425 return "BusLogic SCSI driver " BUSLOGIC_VERSION;
426 }
427
428
429 static void buslogic_interrupt(int irq, struct pt_regs * regs)
430 {
431 void (*my_done)(Scsi_Cmnd *) = NULL;
432 int errstatus, mbistatus = MBX_NOT_IN_USE, number_serviced, found;
433 size_t mbi, mbo = 0;
434 struct Scsi_Host *shpnt;
435 Scsi_Cmnd *sctmp;
436 unsigned long flags;
437 int base, flag;
438 int needs_restart;
439 struct mailbox *mb;
440 struct ccb *ccb;
441
442 shpnt = host[irq - 9];
443 if (!shpnt)
444 panic("buslogic_interrupt: NULL SCSI host entry");
445
446 mb = HOSTDATA(shpnt)->mb;
447 ccb = HOSTDATA(shpnt)->ccbs;
448 base = shpnt->io_port;
449
450 #if (BUSLOGIC_DEBUG & BD_INTERRUPT)
451 flag = inb(INTERRUPT(base));
452
453 buslogic_printk("");
454 if (!(flag & INTV))
455 printk("no interrupt? ");
456 if (flag & IMBL)
457 printk("IMBL ");
458 if (flag & MBOR)
459 printk("MBOR ");
460 if (flag & CMDC)
461 printk("CMDC ");
462 if (flag & RSTS)
463 printk("RSTS ");
464 printk("status %02X\n", inb(STATUS(base)));
465 #endif
466
467 number_serviced = 0;
468 needs_restart = 0;
469
470 for (;;) {
471 flag = inb(INTERRUPT(base));
472
473
474
475
476
477 if (flag & (MBOR | CMDC | RSTS)) {
478 buslogic_printk("unusual flag:");
479 if (flag & MBOR)
480 printk(" MBOR");
481 if (flag & CMDC)
482 printk(" CMDC");
483 if (flag & RSTS) {
484 needs_restart = 1;
485 printk(" RSTS");
486 }
487 printk("\n");
488 }
489
490 INTR_RESET(base);
491
492 save_flags(flags);
493 cli();
494
495 mbi = HOSTDATA(shpnt)->last_mbi_used + 1;
496 if (mbi >= 2 * BUSLOGIC_MAILBOXES)
497 mbi = BUSLOGIC_MAILBOXES;
498
499
500
501
502 found = FALSE;
503 do {
504 if (mb[mbi].status != MBX_NOT_IN_USE) {
505 found = TRUE;
506 break;
507 }
508 mbi++;
509 if (mbi >= 2 * BUSLOGIC_MAILBOXES)
510 mbi = BUSLOGIC_MAILBOXES;
511 } while (mbi != HOSTDATA(shpnt)->last_mbi_used);
512
513 if (found) {
514 mbo = (struct ccb *)mb[mbi].ccbptr - ccb;
515 mbistatus = mb[mbi].status;
516 mb[mbi].status = MBX_NOT_IN_USE;
517 HOSTDATA(shpnt)->last_mbi_used = mbi;
518 }
519
520 restore_flags(flags);
521
522 if (!found) {
523
524 if (!number_serviced && !needs_restart)
525 buslogic_printk("interrupt received, but no mail.\n");
526
527
528 if (needs_restart)
529 restart(shpnt);
530 return;
531 }
532
533 #if (BUSLOGIC_DEBUG & BD_INTERRUPT)
534 if (ccb[mbo].tarstat || ccb[mbo].hastat)
535 buslogic_printk("returning %08X (status %d).\n",
536 ((int)ccb[mbo].hastat << 16) | ccb[mbo].tarstat,
537 mb[mbi].status);
538 #endif
539
540 if (mbistatus == MBX_COMPLETION_NOT_FOUND)
541 continue;
542
543 #if (BUSLOGIC_DEBUG & BD_INTERRUPT)
544 buslogic_printk("...done %u %u\n", mbo, mbi);
545 #endif
546
547 sctmp = HOSTDATA(shpnt)->sc[mbo];
548
549 if (!sctmp || !sctmp->scsi_done) {
550 buslogic_printk("unexpected interrupt.\n");
551 buslogic_printk("tarstat=%02X, hastat=%02X id=%d lun=%d ccb#=%u\n",
552 ccb[mbo].tarstat, ccb[mbo].hastat,
553 ccb[mbo].id, ccb[mbo].lun, mbo);
554 return;
555 }
556
557 my_done = sctmp->scsi_done;
558 if (sctmp->host_scribble)
559 scsi_free(sctmp->host_scribble, BUSLOGIC_SG_MALLOC);
560
561
562 if (mbistatus != MBX_COMPLETION_OK) {
563
564 errstatus = makecode(ccb[mbo].hastat, ccb[mbo].tarstat);
565 } else
566 errstatus = 0;
567
568 #if (BUSLOGIC_DEBUG & BD_INTERRUPT)
569 if (errstatus)
570 buslogic_printk("error: %04X %04X\n",
571 ccb[mbo].hastat, ccb[mbo].tarstat);
572
573 if (status_byte(ccb[mbo].tarstat) == CHECK_CONDITION) {
574 size_t i;
575
576 buslogic_printk("sense:");
577 for (i = 0; i < sizeof sctmp->sense_buffer; i++)
578 printk(" %02X", sctmp->sense_buffer[i]);
579 printk("\n");
580 }
581
582 if (errstatus)
583 buslogic_printk("returning %08X.\n", errstatus);
584 #endif
585
586 sctmp->result = errstatus;
587 HOSTDATA(shpnt)->sc[mbo] = NULL;
588
589
590
591 my_done(sctmp);
592 number_serviced++;
593 }
594 }
595
596
597 int buslogic_queuecommand(Scsi_Cmnd *scpnt, void (*done)(Scsi_Cmnd *))
598 {
599 static const unsigned char buscmd[] = { CMD_START_SCSI };
600 unsigned char direction;
601 unsigned char *cmd = (unsigned char *)scpnt->cmnd;
602 unsigned char target = scpnt->target;
603 unsigned char lun = scpnt->lun;
604 void *buff = scpnt->request_buffer;
605 int bufflen = scpnt->request_bufflen;
606 int mbo;
607 unsigned long flags;
608 struct mailbox *mb;
609 struct ccb *ccb;
610 struct Scsi_Host *shpnt = scpnt->host;
611
612 #if (BUSLOGIC_DEBUG & BD_COMMAND)
613 if (target > 1) {
614 scpnt->result = DID_TIME_OUT << 16;
615 done(scpnt);
616 return 0;
617 }
618 #endif
619
620 if (*cmd == REQUEST_SENSE) {
621 #if (BUSLOGIC_DEBUG & (BD_COMMAND | BD_ERRORS))
622 if (bufflen != sizeof scpnt->sense_buffer) {
623 buslogic_printk("wrong buffer length supplied for request sense"
624 " (%d).\n",
625 bufflen);
626 }
627 #endif
628 scpnt->result = 0;
629 done(scpnt);
630 return 0;
631 }
632
633 #if (BUSLOGIC_DEBUG & BD_COMMAND)
634 {
635 int i;
636
637 if (*cmd == READ_10 || *cmd == WRITE_10
638 || *cmd == READ_6 || *cmd == WRITE_6)
639 i = *(int *)(cmd + 2);
640 else
641 i = -1;
642 buslogic_printk("dev %d cmd %02X pos %d len %d ",
643 target, *cmd, i, bufflen);
644 buslogic_stat(shpnt->io_port);
645 buslogic_printk("dumping scsi cmd:");
646 for (i = 0; i < scpnt->cmd_len; i++)
647 printk(" %02X", cmd[i]);
648 printk("\n");
649 if (*cmd == WRITE_10 || *cmd == WRITE_6)
650 return 0;
651 }
652 #endif
653
654 mb = HOSTDATA(shpnt)->mb;
655 ccb = HOSTDATA(shpnt)->ccbs;
656
657
658
659
660 save_flags(flags);
661 cli();
662
663 mbo = HOSTDATA(shpnt)->last_mbo_used + 1;
664 if (mbo >= BUSLOGIC_MAILBOXES)
665 mbo = 0;
666
667 do {
668 if (mb[mbo].status == MBX_NOT_IN_USE
669 && HOSTDATA(shpnt)->sc[mbo] == NULL)
670 break;
671 mbo++;
672 if (mbo >= BUSLOGIC_MAILBOXES)
673 mbo = 0;
674 } while (mbo != HOSTDATA(shpnt)->last_mbo_used);
675
676 if (mb[mbo].status != MBX_NOT_IN_USE || HOSTDATA(shpnt)->sc[mbo]) {
677
678
679 restore_flags(flags);
680 buslogic_printk("unable to find empty mailbox.\n");
681 goto fail;
682 }
683
684 HOSTDATA(shpnt)->sc[mbo] = scpnt;
685
686
687
688 HOSTDATA(shpnt)->last_mbo_used = mbo;
689
690 restore_flags(flags);
691
692 #if (BUSLOGIC_DEBUG & BD_COMMAND)
693 buslogic_printk("sending command (%d %08X)...", mbo, done);
694 #endif
695
696
697 mb[mbo].ccbptr = &ccb[mbo];
698
699 memset(&ccb[mbo], 0, sizeof (struct ccb));
700
701 ccb[mbo].cdblen = scpnt->cmd_len;
702
703
704 direction = 0;
705 if (*cmd == READ_10 || *cmd == READ_6)
706 direction = 8;
707 else if (*cmd == WRITE_10 || *cmd == WRITE_6)
708 direction = 16;
709
710 memcpy(ccb[mbo].cdb, cmd, ccb[mbo].cdblen);
711
712 if (scpnt->use_sg) {
713 struct scatterlist *sgpnt;
714 struct chain *cptr;
715 size_t i;
716
717 ccb[mbo].op = CCB_OP_INIT_SG;
718
719 scpnt->host_scribble
720 = (unsigned char *)scsi_malloc(BUSLOGIC_SG_MALLOC);
721 if (scpnt->host_scribble == NULL) {
722 buslogic_printk("unable to allocate DMA memory.\n");
723 goto fail;
724 }
725 sgpnt = (struct scatterlist *)scpnt->request_buffer;
726 cptr = (struct chain *)scpnt->host_scribble;
727 if (scpnt->use_sg > shpnt->sg_tablesize) {
728 buslogic_printk("bad segment list, %d > %d.\n",
729 scpnt->use_sg, shpnt->sg_tablesize);
730 goto fail;
731 }
732 for (i = 0; i < scpnt->use_sg; i++) {
733 CHECK_DMA_ADDR(shpnt->unchecked_isa_dma, sgpnt[i].address,
734 goto baddma);
735 cptr[i].dataptr = sgpnt[i].address;
736 cptr[i].datalen = sgpnt[i].length;
737 }
738 ccb[mbo].datalen = scpnt->use_sg * sizeof (struct chain);
739 ccb[mbo].dataptr = cptr;
740 #if (BUSLOGIC_DEBUG & BD_COMMAND)
741 {
742 unsigned char *ptr;
743
744 buslogic_printk("cptr %08X:", cptr);
745 ptr = (unsigned char *)cptr;
746 for (i = 0; i < 18; i++)
747 printk(" %02X", ptr[i]);
748 printk("\n");
749 }
750 #endif
751 } else {
752 ccb[mbo].op = CCB_OP_INIT;
753 scpnt->host_scribble = NULL;
754 CHECK_DMA_ADDR(shpnt->unchecked_isa_dma, buff, goto baddma);
755 ccb[mbo].datalen = bufflen;
756 ccb[mbo].dataptr = buff;
757 }
758 ccb[mbo].id = target;
759 ccb[mbo].lun = lun;
760 ccb[mbo].dir = direction;
761 ccb[mbo].rsalen = sizeof scpnt->sense_buffer;
762 ccb[mbo].senseptr = scpnt->sense_buffer;
763 ccb[mbo].linkptr = NULL;
764 ccb[mbo].commlinkid = 0;
765
766 #if (BUSLOGIC_DEBUG & BD_COMMAND)
767 {
768 size_t i;
769
770 buslogic_printk("sending...");
771 for (i = 0; i < sizeof ccb[mbo] - 10; i++)
772 printk(" %02X", ((unsigned char *)&ccb[mbo])[i]);
773 printk("\n");
774 }
775 #endif
776
777 if (done) {
778 #if (BUSLOGIC_DEBUG & BD_COMMAND)
779 buslogic_printk("now waiting for interrupt: ");
780 buslogic_stat(shpnt->io_port);
781 #endif
782 scpnt->scsi_done = done;
783 mb[mbo].status = MBX_ACTION_START;
784
785 buslogic_out(shpnt->io_port, buscmd, sizeof buscmd);
786 #if (BUSLOGIC_DEBUG & BD_COMMAND)
787 buslogic_stat(shpnt->io_port);
788 #endif
789 } else
790 buslogic_printk("done can't be NULL.\n");
791
792 while (0) {
793 #if defined(MODULE) && !defined(GFP_DMA)
794 baddma:
795 buslogic_printk("address > 16MB used for ISA HA.\n");
796 #endif
797 fail:
798 scpnt->result = DID_ERROR << 16;
799 done(scpnt);
800 }
801
802 return 0;
803 }
804
805 #if 0
806 static void internal_done(Scsi_Cmnd *scpnt)
807 {
808 scpnt->SCp.Status++;
809 }
810
811 int buslogic_command(Scsi_Cmnd *scpnt)
812 {
813 #if (BUSLOGIC_DEBUG & BD_COMMAND)
814 buslogic_printk("calling buslogic_queuecommand.\n");
815 #endif
816
817 buslogic_queuecommand(scpnt, internal_done);
818
819 scpnt->SCp.Status = 0;
820 while (!scpnt->SCp.Status)
821 continue;
822 return scpnt->result;
823 }
824 #endif
825
826
827 static int setup_mailboxes(unsigned int base, struct Scsi_Host *shpnt)
828 {
829 size_t i;
830 int ok = FALSE;
831 struct mailbox *mb = HOSTDATA(shpnt)->mb;
832 struct ccb *ccb = HOSTDATA(shpnt)->ccbs;
833 struct {
834 unsigned char cmd, count;
835 void *base PACKED;
836 } cmd = { CMD_INITEXTMB, BUSLOGIC_MAILBOXES, mb };
837
838 for (i = 0; i < BUSLOGIC_MAILBOXES; i++) {
839 mb[i].status = mb[BUSLOGIC_MAILBOXES + i].status = MBX_NOT_IN_USE;
840 mb[i].ccbptr = &ccb[i];
841 }
842 INTR_RESET(base);
843
844 if (buslogic_out(base, (unsigned char *)&cmd, sizeof cmd))
845 goto fail;
846 WAIT_UNTIL(INTERRUPT(base), CMDC);
847
848 ok = TRUE;
849
850 while (0) {
851 fail:
852 buslogic_printk("failed setting up mailboxes.\n");
853 }
854
855 INTR_RESET(base);
856
857 return !ok;
858 }
859
860 static int getconfig(unsigned int base, unsigned char *irq,
861 unsigned char *dma, unsigned char *id,
862 char *bus_type, unsigned short *max_sg,
863 const unsigned char **bios)
864 {
865 unsigned char inquiry_cmd[2];
866 unsigned char inquiry_result[4];
867 int i;
868
869 #if (BUSLOGIC_DEBUG & BD_DETECT)
870 buslogic_printk("called\n");
871 #endif
872
873 i = inb(STATUS(base));
874 if (i & DIRRDY)
875 i = inb(DATA_IN(base));
876 inquiry_cmd[0] = CMD_RETCONF;
877 buslogic_out(base, inquiry_cmd, 1);
878 if (buslogic_in(base, inquiry_result, 3))
879 goto fail;
880 WAIT_UNTIL_FAST(INTERRUPT(base), CMDC);
881 INTR_RESET(base);
882
883 *dma = inquiry_result[0];
884 switch (inquiry_result[1]) {
885 case 0x01:
886 *irq = 9;
887 break;
888 case 0x02:
889 *irq = 10;
890 break;
891 case 0x04:
892 *irq = 11;
893 break;
894 case 0x08:
895 *irq = 12;
896 break;
897 case 0x20:
898 *irq = 14;
899 break;
900 case 0x40:
901 *irq = 15;
902 break;
903 default:
904 buslogic_printk("unable to determine BusLogic IRQ level, "
905 " disabling board.\n");
906 goto fail;
907 }
908 *id = inquiry_result[2] & 0x7;
909
910
911 inquiry_cmd[0] = CMD_INQEXTSETUP;
912 inquiry_cmd[1] = 4;
913 if (buslogic_out(base, inquiry_cmd, 2))
914 goto fail;
915 if (buslogic_in(base, inquiry_result, inquiry_cmd[1]))
916 goto fail;
917 WAIT_UNTIL_FAST(INTERRUPT(base), CMDC);
918 if (inb(STATUS(base)) & CMDINV)
919 goto fail;
920 INTR_RESET(base);
921
922 *bus_type = inquiry_result[0];
923 CHECK(*bus_type == 'A' || *bus_type == 'E' || *bus_type == 'M');
924
925 *bios = (const unsigned char *)((unsigned int)inquiry_result[1] << 12);
926
927 *max_sg = (inquiry_result[3] << 8) | inquiry_result[2];
928
929
930
931
932
933 if (*bus_type == 'A')
934 switch (*dma) {
935 case 0:
936 *dma = 0;
937 break;
938 case 0x20:
939 *dma = 5;
940 break;
941 case 0x40:
942 *dma = 6;
943 break;
944 case 0x80:
945 *dma = 7;
946 break;
947 default:
948 buslogic_printk("unable to determine BusLogic DMA channel,"
949 " disabling board.\n");
950 goto fail;
951 }
952 else
953 *dma = 0;
954
955 while (0) {
956 fail:
957 #if (BUSLOGIC_DEBUG & BD_DETECT)
958 buslogic_printk("query board settings\n");
959 #endif
960 return TRUE;
961 }
962
963 return FALSE;
964 }
965
966
967
968 static int buslogic_query(unsigned int base, unsigned char *trans,
969 unsigned char *irq, unsigned char *dma,
970 unsigned char *id, char *bus_type,
971 unsigned short *max_sg, const unsigned char **bios,
972 char *model, char *firmware_rev)
973 {
974 unsigned char inquiry_cmd[2];
975 unsigned char inquiry_result[6];
976 unsigned char geo;
977 unsigned int i;
978
979 #if (BUSLOGIC_DEBUG & BD_DETECT)
980 buslogic_printk("called\n");
981 #endif
982
983
984 if (inb(STATUS(base)) == 0xFF)
985 goto fail;
986
987
988 geo = inb(GEOMETRY(base));
989 #if (BUSLOGIC_DEBUG & BD_DETECT)
990 buslogic_printk("geometry bits: %02X\n", geo);
991 #endif
992
993
994 if (geo == 0xFF)
995 goto fail;
996
997
998 INTR_RESET(base);
999
1000
1001
1002 outb(RSOFT | RINT, CONTROL(base));
1003
1004
1005 i = jiffies + 2;
1006 while (i > jiffies);
1007
1008
1009 WAIT(STATUS(base), INREQ | HARDY, DACT | DFAIL | CMDINV | DIRRDY | CPRBSY);
1010
1011
1012 if (inb(INTERRUPT(base)) & INTRMASK)
1013 goto fail;
1014
1015
1016
1017
1018
1019 inquiry_cmd[0] = CMD_INQUIRY;
1020 buslogic_out(base, inquiry_cmd, 1);
1021 if (buslogic_in(base, inquiry_result, 4))
1022 goto fail;
1023
1024 if (inb(STATUS(base)) & DIRRDY)
1025 goto fail;
1026 WAIT_UNTIL_FAST(INTERRUPT(base), CMDC);
1027 INTR_RESET(base);
1028 firmware_rev[0] = inquiry_result[2];
1029 firmware_rev[1] = '.';
1030 firmware_rev[2] = inquiry_result[3];
1031 firmware_rev[3] = '\0';
1032 #if 0
1033 buslogic_printk("inquiry bytes: %02X(%c) %02X(%c)\n",
1034 inquiry_result[0], inquiry_result[0],
1035 inquiry_result[1], inquiry_result[1]);
1036 #endif
1037
1038 if (getconfig(base, irq, dma, id, bus_type, max_sg, bios))
1039 goto fail;
1040
1041
1042 #ifdef BIOS_TRANSLATION_OVERRIDE
1043 *trans = BIOS_TRANSLATION_OVERRIDE;
1044 #else
1045 *trans = BIOS_TRANSLATION_DEFAULT;
1046 #endif
1047 model[0] = '\0';
1048 model[6] = 0;
1049
1050
1051
1052
1053 do {
1054
1055
1056
1057 if (geo == 0x00)
1058 break;
1059 #ifndef BIOS_TRANSLATION_OVERRIDE
1060 *trans = ((geo & GEO_GT_1GB)
1061 ? BIOS_TRANSLATION_BIG : BIOS_TRANSLATION_DEFAULT);
1062 #endif
1063
1064 inquiry_cmd[0] = CMD_VER_NO_LAST;
1065 buslogic_out(base, inquiry_cmd, 1);
1066 if (buslogic_in(base, inquiry_result, 1))
1067 break;
1068 WAIT_UNTIL_FAST(INTERRUPT(base), CMDC);
1069 INTR_RESET(base);
1070 firmware_rev[3] = inquiry_result[0];
1071 firmware_rev[4] = '\0';
1072
1073 inquiry_cmd[0] = CMD_VER_NO_LETTER;
1074 buslogic_out(base, inquiry_cmd, 1);
1075 if (buslogic_in(base, inquiry_result, 1))
1076 break;
1077 WAIT_UNTIL_FAST(INTERRUPT(base), CMDC);
1078 INTR_RESET(base);
1079 firmware_rev[4] = inquiry_result[0];
1080 firmware_rev[5] = '\0';
1081
1082
1083
1084 inquiry_cmd[0] = CMD_RET_MODEL_NO;
1085 inquiry_cmd[1] = 6;
1086 buslogic_out(base, inquiry_cmd, 2);
1087 if (buslogic_in(base, inquiry_result, inquiry_cmd[1]))
1088 break;
1089 WAIT_UNTIL_FAST(INTERRUPT(base), CMDC);
1090 INTR_RESET(base);
1091 memcpy(model, inquiry_result, 5);
1092 model[5] = '\0';
1093 model[6] = inquiry_result[5];
1094 } while (0);
1095
1096
1097
1098
1099
1100 switch (*bus_type) {
1101 case 'E':
1102 switch (model[0]) {
1103 case '4':
1104 *bus_type = 'V';
1105 break;
1106 case '9':
1107 *bus_type = 'P';
1108 break;
1109 case '7':
1110 break;
1111 default:
1112 *bus_type = 'X';
1113 break;
1114 }
1115 break;
1116 default:
1117 break;
1118 }
1119
1120 while (0) {
1121 fail:
1122 #if (BUSLOGIC_DEBUG & BD_DETECT)
1123 buslogic_printk("query board settings\n");
1124 #endif
1125 return TRUE;
1126 }
1127
1128 return FALSE;
1129 }
1130
1131
1132 int buslogic_detect(Scsi_Host_Template *tpnt)
1133 {
1134 unsigned char dma;
1135 unsigned char irq;
1136 unsigned int base;
1137 unsigned char id;
1138 char bus_type;
1139 unsigned short max_sg;
1140 unsigned char bios_translation;
1141 unsigned long flags;
1142 const unsigned char *bios;
1143 char *model;
1144 char *firmware_rev;
1145 struct Scsi_Host *shpnt;
1146 size_t indx;
1147 int unchecked_isa_dma;
1148 int count = 0;
1149
1150 #if (BUSLOGIC_DEBUG & BD_DETECT)
1151 buslogic_printk("called\n");
1152 #endif
1153
1154 tpnt->can_queue = BUSLOGIC_MAILBOXES;
1155 for (indx = 0; bases[indx] != 0; indx++)
1156 if (!check_region(bases[indx], 4)) {
1157 shpnt = scsi_register(tpnt, sizeof (struct hostdata));
1158
1159 base = bases[indx];
1160
1161 model = HOSTDATA(shpnt)->model;
1162 firmware_rev = HOSTDATA(shpnt)->firmware_rev;
1163 if (buslogic_query(base, &bios_translation, &irq, &dma, &id,
1164 &bus_type, &max_sg, &bios, model, firmware_rev))
1165 goto unregister;
1166
1167 #if (BUSLOGIC_DEBUG & BD_DETECT)
1168 buslogic_stat(base);
1169 #endif
1170
1171
1172 unchecked_isa_dma = (bus_type == 'A');
1173 #ifndef CONFIG_NO_BUGGY_BUSLOGIC
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185 if (bus_type == 'V'
1186 && firmware_rev[0] <= '3'
1187 && bios != NULL) {
1188 #if 1
1189
1190
1191
1192 shpnt->forbidden_addr = (unsigned long)bios;
1193 shpnt->forbidden_size = 16 * 1024;
1194 #else
1195
1196 unchecked_isa_dma = TRUE;
1197 #endif
1198 }
1199 #endif
1200
1201 CHECK_DMA_ADDR(unchecked_isa_dma, shpnt, goto unregister);
1202
1203 if (setup_mailboxes(base, shpnt))
1204 goto unregister;
1205
1206
1207
1208
1209 if (bus_type != 'E' && bus_type != 'P') {
1210
1211 static const unsigned char oncmd[] = { CMD_BUSON_TIME, 7 };
1212 static const unsigned char offcmd[] = { CMD_BUSOFF_TIME, 5 };
1213
1214 INTR_RESET(base);
1215 buslogic_out(base, oncmd, sizeof oncmd);
1216 WAIT_UNTIL(INTERRUPT(base), CMDC);
1217 INTR_RESET(base);
1218 buslogic_out(base, offcmd, sizeof offcmd);
1219 WAIT_UNTIL(INTERRUPT(base), CMDC);
1220 while (0) {
1221 fail:
1222 buslogic_printk("setting bus on/off-time failed.\n");
1223 }
1224 INTR_RESET(base);
1225 }
1226
1227 buslogic_printk("configuring %s HA at port 0x%03X, IRQ %u",
1228 (bus_type == 'A' ? "ISA"
1229 : (bus_type == 'E' ? "EISA"
1230 : (bus_type == 'M' ? "MCA"
1231 : (bus_type == 'P' ? "PCI"
1232 : (bus_type == 'V' ? "VESA"
1233 : (bus_type == 'X' ? "EISA/VESA/PCI"
1234 : "Unknown")))))),
1235 base, irq);
1236 if (bios != NULL)
1237 printk(", BIOS 0x%05X", (unsigned int)bios);
1238 if (dma != 0)
1239 printk(", DMA %u", dma);
1240 printk(", ID %u\n", id);
1241 buslogic_printk("Model Number: %s",
1242 (model[0] ? model : "Unknown"));
1243 if (model[0])
1244 printk(" (revision %d)", model[6]);
1245 printk("\n");
1246 buslogic_printk("firmware revision: %s\n", firmware_rev);
1247
1248 #if (BUSLOGIC_DEBUG & BD_DETECT)
1249 buslogic_stat(base);
1250 #endif
1251
1252 #if (BUSLOGIC_DEBUG & BD_DETECT)
1253 buslogic_printk("enable interrupt channel %d.\n", irq);
1254 #endif
1255
1256 save_flags(flags);
1257 cli();
1258 if (request_irq(irq, buslogic_interrupt, 0, "buslogic")) {
1259 buslogic_printk("unable to allocate IRQ for "
1260 "BusLogic controller.\n");
1261 restore_flags(flags);
1262 goto unregister;
1263 }
1264
1265 if (dma) {
1266 if (request_dma(dma, "buslogic")) {
1267 buslogic_printk("unable to allocate DMA channel for "
1268 "BusLogic controller.\n");
1269 free_irq(irq);
1270 restore_flags(flags);
1271 goto unregister;
1272 }
1273
1274
1275
1276
1277 set_dma_mode(dma, DMA_MODE_CASCADE);
1278 enable_dma(dma);
1279 }
1280
1281 host[irq - 9] = shpnt;
1282 shpnt->this_id = id;
1283 shpnt->unchecked_isa_dma = unchecked_isa_dma;
1284
1285
1286 shpnt->cmd_per_lun = (unchecked_isa_dma ? 1 : BUSLOGIC_CMDLUN);
1287 shpnt->sg_tablesize = max_sg;
1288 if (shpnt->sg_tablesize > BUSLOGIC_MAX_SG)
1289 shpnt->sg_tablesize = BUSLOGIC_MAX_SG;
1290
1291 shpnt->base = (unsigned char *)bios;
1292 shpnt->io_port = base;
1293 shpnt->n_io_port = 4;
1294 shpnt->dma_channel = dma;
1295 shpnt->irq = irq;
1296 HOSTDATA(shpnt)->bios_translation = bios_translation;
1297 if (bios_translation == BIOS_TRANSLATION_BIG)
1298 buslogic_printk("using extended bios translation.\n");
1299 HOSTDATA(shpnt)->last_mbi_used = 2 * BUSLOGIC_MAILBOXES - 1;
1300 HOSTDATA(shpnt)->last_mbo_used = BUSLOGIC_MAILBOXES - 1;
1301 memset(HOSTDATA(shpnt)->sc, 0, sizeof HOSTDATA(shpnt)->sc);
1302 restore_flags(flags);
1303
1304 #if 0
1305 {
1306 unsigned char buf[8];
1307 unsigned char cmd[]
1308 = { READ_CAPACITY, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
1309 size_t i;
1310
1311 #if (BUSLOGIC_DEBUG & BD_DETECT)
1312 buslogic_printk("*** READ CAPACITY ***\n");
1313 #endif
1314 for (i = 0; i < sizeof buf; i++)
1315 buf[i] = 0x87;
1316 for (i = 0; i < 2; i++)
1317 if (!buslogic_command(i, cmd, buf, sizeof buf)) {
1318 buslogic_printk("LU %u sector_size %d device_size %d\n",
1319 i, *(int *)(buf + 4), *(int *)buf);
1320 }
1321
1322 #if (BUSLOGIC_DEBUG & BD_DETECT)
1323 buslogic_printk("*** NOW RUNNING MY OWN TEST ***\n");
1324 #endif
1325 for (i = 0; i < 4; i++) {
1326 static buffer[512];
1327
1328 cmd[0] = READ_10;
1329 cmd[1] = 0;
1330 xany2scsi(cmd + 2, i);
1331 cmd[6] = 0;
1332 cmd[7] = 0;
1333 cmd[8] = 1;
1334 cmd[9] = 0;
1335 buslogic_command(0, cmd, buffer, sizeof buffer);
1336 }
1337 }
1338 #endif
1339
1340 request_region(bases[indx], 4,"buslogic");
1341
1342 count++;
1343 continue;
1344 unregister:
1345 scsi_unregister(shpnt);
1346 }
1347 return count;
1348 }
1349
1350 static int restart(struct Scsi_Host *shpnt)
1351 {
1352 unsigned int i;
1353 unsigned int count = 0;
1354 #if 0
1355 static const unsigned char buscmd[] = { CMD_START_SCSI };
1356 #endif
1357
1358 for (i = 0; i < BUSLOGIC_MAILBOXES; i++)
1359 if (HOSTDATA(shpnt)->sc[i]
1360 && !HOSTDATA(shpnt)->sc[i]->device->soft_reset) {
1361 #if 0
1362 HOSTDATA(shpnt)->mb[i].status
1363 = MBX_ACTION_START;
1364 #endif
1365 count++;
1366 }
1367
1368 buslogic_printk("potential to restart %d stalled commands...\n", count);
1369 #if 0
1370
1371 if (count)
1372 buslogic_out(shpnt->host->io_port, buscmd, sizeof buscmd);
1373 #endif
1374 return 0;
1375 }
1376
1377
1378
1379
1380
1381 int buslogic_abort(Scsi_Cmnd *scpnt)
1382 {
1383 #if 1
1384 static const unsigned char buscmd[] = { CMD_START_SCSI };
1385 struct mailbox *mb;
1386 size_t mbi, mbo;
1387 unsigned long flags;
1388 unsigned int i;
1389
1390 buslogic_printk("%X %X\n",
1391 inb(STATUS(scpnt->host->io_port)),
1392 inb(INTERRUPT(scpnt->host->io_port)));
1393
1394 save_flags(flags);
1395 cli();
1396 mb = HOSTDATA(scpnt->host)->mb;
1397 mbi = HOSTDATA(scpnt->host)->last_mbi_used + 1;
1398 if (mbi >= 2 * BUSLOGIC_MAILBOXES)
1399 mbi = BUSLOGIC_MAILBOXES;
1400
1401 do {
1402 if (mb[mbi].status != MBX_NOT_IN_USE)
1403 break;
1404 mbi++;
1405 if (mbi >= 2 * BUSLOGIC_MAILBOXES)
1406 mbi = BUSLOGIC_MAILBOXES;
1407 } while (mbi != HOSTDATA(scpnt->host)->last_mbi_used);
1408 restore_flags(flags);
1409
1410 if (mb[mbi].status != MBX_NOT_IN_USE) {
1411 buslogic_printk("lost interrupt discovered on irq %d"
1412 " - attempting to recover...\n",
1413 scpnt->host->irq);
1414 {
1415 buslogic_interrupt(scpnt->host->irq, NULL);
1416 return SCSI_ABORT_SUCCESS;
1417 }
1418 }
1419
1420
1421
1422 for (i = 0; i < BUSLOGIC_MAILBOXES; i++)
1423 if (HOSTDATA(scpnt->host)->sc[i]) {
1424 if (HOSTDATA(scpnt->host)->sc[i] == scpnt) {
1425 buslogic_printk("timed out command pending for %4.4X.\n",
1426 scpnt->request.dev);
1427 if (HOSTDATA(scpnt->host)->mb[i].status != MBX_NOT_IN_USE) {
1428 buslogic_printk("OGMB still full - restarting...\n");
1429 buslogic_out(scpnt->host->io_port, buscmd, sizeof buscmd);
1430 }
1431 } else
1432 buslogic_printk("other pending command: %4.4X\n",
1433 scpnt->request.dev);
1434 }
1435 #endif
1436
1437 #if (BUSLOGIC_DEBUG & BD_ABORT)
1438 buslogic_printk("called\n");
1439 #endif
1440
1441 #if 1
1442
1443
1444 save_flags(flags);
1445 cli();
1446 for (mbo = 0; mbo < BUSLOGIC_MAILBOXES; mbo++)
1447 if (scpnt == HOSTDATA(scpnt->host)->sc[mbo]) {
1448 mb[mbo].status = MBX_ACTION_ABORT;
1449 buslogic_out(scpnt->host->io_port, buscmd, sizeof buscmd);
1450 break;
1451 }
1452 restore_flags(flags);
1453 #endif
1454
1455 return SCSI_ABORT_SNOOZE;
1456 }
1457
1458
1459
1460
1461
1462
1463 int buslogic_reset(Scsi_Cmnd *scpnt)
1464 {
1465 static const unsigned char buscmd[] = { CMD_START_SCSI };
1466 unsigned int i;
1467
1468 #if (BUSLOGIC_DEBUG & BD_RESET)
1469 buslogic_printk("called\n");
1470 #endif
1471 #if 0
1472
1473 outb(RSBUS, CONTROL(scpnt->host->io_port));
1474 #else
1475
1476
1477 for (i = 0; i < BUSLOGIC_MAILBOXES; i++)
1478 if (HOSTDATA(scpnt->host)->sc[i] == scpnt) {
1479 HOSTDATA(scpnt->host)->ccbs[i].op = CCB_OP_BUS_RESET;
1480
1481
1482
1483 buslogic_out(scpnt->host->io_port, buscmd, sizeof buscmd);
1484
1485
1486
1487
1488
1489 buslogic_printk("sent BUS DEVICE RESET to target %d.\n",
1490 scpnt->target);
1491
1492
1493
1494
1495 #if 1
1496 for (i = 0; i < BUSLOGIC_MAILBOXES; i++)
1497 if (HOSTDATA(scpnt->host)->sc[i]
1498 && HOSTDATA(scpnt->host)->sc[i]->target == scpnt->target) {
1499 Scsi_Cmnd *sctmp = HOSTDATA(scpnt->host)->sc[i];
1500
1501 sctmp->result = DID_RESET << 16;
1502 if (sctmp->host_scribble)
1503 scsi_free(sctmp->host_scribble, BUSLOGIC_SG_MALLOC);
1504 buslogic_printk("sending DID_RESET for target %d.\n",
1505 scpnt->target);
1506 sctmp->scsi_done(scpnt);
1507
1508 HOSTDATA(scpnt->host)->sc[i] = NULL;
1509 HOSTDATA(scpnt->host)->mb[i].status = MBX_NOT_IN_USE;
1510 }
1511 return SCSI_RESET_SUCCESS;
1512 #else
1513 return SCSI_RESET_PENDING;
1514 #endif
1515 }
1516 #endif
1517
1518
1519
1520 return SCSI_RESET_PUNT;
1521 }
1522
1523
1524
1525
1526
1527
1528 int buslogic_biosparam(Disk *disk, int dev, int *ip)
1529 {
1530 unsigned int size = disk->capacity;
1531
1532
1533 if (HOSTDATA(disk->device->host)->bios_translation == BIOS_TRANSLATION_BIG
1534 && size >= 0x200000) {
1535 if (size >= 0x400000) {
1536 #if 0
1537 if (mb >= 0x800000) {
1538 ip[0] = 256;
1539 ip[1] = 64;
1540 } else {
1541 ip[0] = 256;
1542 ip[1] = 32;
1543 }
1544 #else
1545 ip[0] = 256;
1546 ip[1] = 64;
1547 #endif
1548 } else {
1549 ip[0] = 128;
1550 ip[1] = 32;
1551 }
1552 } else {
1553 ip[0] = 64;
1554 ip[1] = 32;
1555 }
1556 ip[2] = size / (ip[0] * ip[1]);
1557
1558
1559 return 0;
1560 }
1561
1562
1563 void buslogic_setup(char *str, int *ints)
1564 {
1565 static const unsigned short valid_bases[]
1566 = { 0x130, 0x134, 0x230, 0x234, 0x330, 0x334 };
1567 static size_t setup_idx = 0;
1568 size_t i;
1569
1570 if (setup_idx >= ARRAY_SIZE(bases) - 1) {
1571 buslogic_printk("called too many times. Bad LILO params?\n");
1572 return;
1573 }
1574 if (ints[0] != 1) {
1575 buslogic_printk("malformed command line.\n");
1576 buslogic_printk("usage: buslogic=<portbase>\n");
1577 return;
1578 }
1579 for (i = 0; i < ARRAY_SIZE(valid_bases); i++)
1580 if (valid_bases[i] == ints[1]) {
1581 bases[setup_idx++] = ints[1];
1582 bases[setup_idx] = 0;
1583 return;
1584 }
1585 buslogic_printk("invalid base 0x%X specified.\n", ints[i]);
1586 }
1587
1588 #ifdef MODULE
1589
1590 Scsi_Host_Template driver_template = BUSLOGIC;
1591
1592 # include "scsi_module.c"
1593 #endif