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