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