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