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