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 irq, struct pt_regs * regs)
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 base, flag;
434 int needs_restart;
435 struct mailbox *mb;
436 struct ccb *ccb;
437
438 shpnt = host[irq - 9];
439 if (!shpnt)
440 panic("buslogic_interrupt: NULL SCSI host entry");
441
442 mb = HOSTDATA(shpnt)->mb;
443 ccb = HOSTDATA(shpnt)->ccbs;
444 base = shpnt->io_port;
445
446 #if (BUSLOGIC_DEBUG & BD_INTERRUPT)
447 flag = inb(INTERRUPT(base));
448
449 buslogic_printk("");
450 if (!(flag & INTV))
451 printk("no interrupt? ");
452 if (flag & IMBL)
453 printk("IMBL ");
454 if (flag & MBOR)
455 printk("MBOR ");
456 if (flag & CMDC)
457 printk("CMDC ");
458 if (flag & RSTS)
459 printk("RSTS ");
460 printk("status %02X\n", inb(STATUS(base)));
461 #endif
462
463 number_serviced = 0;
464 needs_restart = 0;
465
466 for (;;) {
467 flag = inb(INTERRUPT(base));
468
469
470
471
472
473 if (flag & (MBOR | CMDC | RSTS)) {
474 buslogic_printk("unusual flag:");
475 if (flag & MBOR)
476 printk(" MBOR");
477 if (flag & CMDC)
478 printk(" CMDC");
479 if (flag & RSTS) {
480 needs_restart = 1;
481 printk(" RSTS");
482 }
483 printk("\n");
484 }
485
486 INTR_RESET(base);
487
488 save_flags(flags);
489 cli();
490
491 mbi = HOSTDATA(shpnt)->last_mbi_used + 1;
492 if (mbi >= 2 * BUSLOGIC_MAILBOXES)
493 mbi = BUSLOGIC_MAILBOXES;
494
495
496
497
498 found = FALSE;
499 do {
500 if (mb[mbi].status != MBX_NOT_IN_USE) {
501 found = TRUE;
502 break;
503 }
504 mbi++;
505 if (mbi >= 2 * BUSLOGIC_MAILBOXES)
506 mbi = BUSLOGIC_MAILBOXES;
507 } while (mbi != HOSTDATA(shpnt)->last_mbi_used);
508
509 if (found) {
510 mbo = (struct ccb *)mb[mbi].ccbptr - ccb;
511 mbistatus = mb[mbi].status;
512 mb[mbi].status = MBX_NOT_IN_USE;
513 HOSTDATA(shpnt)->last_mbi_used = mbi;
514 }
515
516 restore_flags(flags);
517
518 if (!found) {
519
520 if (!number_serviced && !needs_restart)
521 buslogic_printk("interrupt received, but no mail.\n");
522
523
524 if (needs_restart)
525 restart(shpnt);
526 return;
527 }
528
529 #if (BUSLOGIC_DEBUG & BD_INTERRUPT)
530 if (ccb[mbo].tarstat || ccb[mbo].hastat)
531 buslogic_printk("returning %08X (status %d).\n",
532 ((int)ccb[mbo].hastat << 16) | ccb[mbo].tarstat,
533 mb[mbi].status);
534 #endif
535
536 if (mbistatus == MBX_COMPLETION_NOT_FOUND)
537 continue;
538
539 #if (BUSLOGIC_DEBUG & BD_INTERRUPT)
540 buslogic_printk("...done %u %u\n", mbo, mbi);
541 #endif
542
543 sctmp = HOSTDATA(shpnt)->sc[mbo];
544
545 if (!sctmp || !sctmp->scsi_done) {
546 buslogic_printk("unexpected interrupt.\n");
547 buslogic_printk("tarstat=%02X, hastat=%02X id=%d lun=%d ccb#=%u\n",
548 ccb[mbo].tarstat, ccb[mbo].hastat,
549 ccb[mbo].id, ccb[mbo].lun, mbo);
550 return;
551 }
552
553 my_done = sctmp->scsi_done;
554 if (sctmp->host_scribble)
555 scsi_free(sctmp->host_scribble, BUSLOGIC_SG_MALLOC);
556
557
558 if (mbistatus != MBX_COMPLETION_OK) {
559
560 errstatus = makecode(ccb[mbo].hastat, ccb[mbo].tarstat);
561 } else
562 errstatus = 0;
563
564 #if (BUSLOGIC_DEBUG & BD_INTERRUPT)
565 if (errstatus)
566 buslogic_printk("error: %04X %04X\n",
567 ccb[mbo].hastat, ccb[mbo].tarstat);
568
569 if (status_byte(ccb[mbo].tarstat) == CHECK_CONDITION) {
570 size_t i;
571
572 buslogic_printk("sense:");
573 for (i = 0; i < sizeof sctmp->sense_buffer; i++)
574 printk(" %02X", sctmp->sense_buffer[i]);
575 printk("\n");
576 }
577
578 if (errstatus)
579 buslogic_printk("returning %08X.\n", errstatus);
580 #endif
581
582 sctmp->result = errstatus;
583 HOSTDATA(shpnt)->sc[mbo] = NULL;
584
585
586
587 my_done(sctmp);
588 number_serviced++;
589 }
590 }
591
592
593 int buslogic_queuecommand(Scsi_Cmnd *scpnt, void (*done)(Scsi_Cmnd *))
594 {
595 static const unsigned char buscmd[] = { CMD_START_SCSI };
596 unsigned char direction;
597 unsigned char *cmd = (unsigned char *)scpnt->cmnd;
598 unsigned char target = scpnt->target;
599 unsigned char lun = scpnt->lun;
600 void *buff = scpnt->request_buffer;
601 int bufflen = scpnt->request_bufflen;
602 int mbo;
603 unsigned long flags;
604 struct mailbox *mb;
605 struct ccb *ccb;
606 struct Scsi_Host *shpnt = scpnt->host;
607
608 #if (BUSLOGIC_DEBUG & BD_COMMAND)
609 if (target > 1) {
610 scpnt->result = DID_TIME_OUT << 16;
611 done(scpnt);
612 return 0;
613 }
614 #endif
615
616 if (*cmd == REQUEST_SENSE) {
617 #if (BUSLOGIC_DEBUG & (BD_COMMAND | BD_ERRORS))
618 if (bufflen != sizeof scpnt->sense_buffer) {
619 buslogic_printk("wrong buffer length supplied for request sense"
620 " (%d).\n",
621 bufflen);
622 }
623 #endif
624 scpnt->result = 0;
625 done(scpnt);
626 return 0;
627 }
628
629 #if (BUSLOGIC_DEBUG & BD_COMMAND)
630 {
631 int i;
632
633 if (*cmd == READ_10 || *cmd == WRITE_10
634 || *cmd == READ_6 || *cmd == WRITE_6)
635 i = *(int *)(cmd + 2);
636 else
637 i = -1;
638 buslogic_printk("dev %d cmd %02X pos %d len %d ",
639 target, *cmd, i, bufflen);
640 buslogic_stat(shpnt->io_port);
641 buslogic_printk("dumping scsi cmd:");
642 for (i = 0; i < scpnt->cmd_len; i++)
643 printk(" %02X", cmd[i]);
644 printk("\n");
645 if (*cmd == WRITE_10 || *cmd == WRITE_6)
646 return 0;
647 }
648 #endif
649
650 mb = HOSTDATA(shpnt)->mb;
651 ccb = HOSTDATA(shpnt)->ccbs;
652
653
654
655
656 save_flags(flags);
657 cli();
658
659 mbo = HOSTDATA(shpnt)->last_mbo_used + 1;
660 if (mbo >= BUSLOGIC_MAILBOXES)
661 mbo = 0;
662
663 do {
664 if (mb[mbo].status == MBX_NOT_IN_USE
665 && HOSTDATA(shpnt)->sc[mbo] == NULL)
666 break;
667 mbo++;
668 if (mbo >= BUSLOGIC_MAILBOXES)
669 mbo = 0;
670 } while (mbo != HOSTDATA(shpnt)->last_mbo_used);
671
672 if (mb[mbo].status != MBX_NOT_IN_USE || HOSTDATA(shpnt)->sc[mbo]) {
673
674
675 restore_flags(flags);
676 buslogic_printk("unable to find empty mailbox.\n");
677 goto fail;
678 }
679
680 HOSTDATA(shpnt)->sc[mbo] = scpnt;
681
682
683
684 HOSTDATA(shpnt)->last_mbo_used = mbo;
685
686 restore_flags(flags);
687
688 #if (BUSLOGIC_DEBUG & BD_COMMAND)
689 buslogic_printk("sending command (%d %08X)...", mbo, done);
690 #endif
691
692
693 mb[mbo].ccbptr = &ccb[mbo];
694
695 memset(&ccb[mbo], 0, sizeof (struct ccb));
696
697 ccb[mbo].cdblen = scpnt->cmd_len;
698
699
700 direction = 0;
701 if (*cmd == READ_10 || *cmd == READ_6)
702 direction = 8;
703 else if (*cmd == WRITE_10 || *cmd == WRITE_6)
704 direction = 16;
705
706 memcpy(ccb[mbo].cdb, cmd, ccb[mbo].cdblen);
707
708 if (scpnt->use_sg) {
709 struct scatterlist *sgpnt;
710 struct chain *cptr;
711 size_t i;
712
713 ccb[mbo].op = CCB_OP_INIT_SG;
714
715 scpnt->host_scribble
716 = (unsigned char *)scsi_malloc(BUSLOGIC_SG_MALLOC);
717 if (scpnt->host_scribble == NULL) {
718 buslogic_printk("unable to allocate DMA memory.\n");
719 goto fail;
720 }
721 sgpnt = (struct scatterlist *)scpnt->request_buffer;
722 cptr = (struct chain *)scpnt->host_scribble;
723 if (scpnt->use_sg > shpnt->sg_tablesize) {
724 buslogic_printk("bad segment list, %d > %d.\n",
725 scpnt->use_sg, shpnt->sg_tablesize);
726 goto fail;
727 }
728 for (i = 0; i < scpnt->use_sg; i++) {
729 CHECK_DMA_ADDR(shpnt->unchecked_isa_dma, sgpnt[i].address,
730 goto baddma);
731 cptr[i].dataptr = sgpnt[i].address;
732 cptr[i].datalen = sgpnt[i].length;
733 }
734 ccb[mbo].datalen = scpnt->use_sg * sizeof (struct chain);
735 ccb[mbo].dataptr = cptr;
736 #if (BUSLOGIC_DEBUG & BD_COMMAND)
737 {
738 unsigned char *ptr;
739
740 buslogic_printk("cptr %08X:", cptr);
741 ptr = (unsigned char *)cptr;
742 for (i = 0; i < 18; i++)
743 printk(" %02X", ptr[i]);
744 printk("\n");
745 }
746 #endif
747 } else {
748 ccb[mbo].op = CCB_OP_INIT;
749 scpnt->host_scribble = NULL;
750 CHECK_DMA_ADDR(shpnt->unchecked_isa_dma, buff, goto baddma);
751 ccb[mbo].datalen = bufflen;
752 ccb[mbo].dataptr = buff;
753 }
754 ccb[mbo].id = target;
755 ccb[mbo].lun = lun;
756 ccb[mbo].dir = direction;
757 ccb[mbo].rsalen = sizeof scpnt->sense_buffer;
758 ccb[mbo].senseptr = scpnt->sense_buffer;
759 ccb[mbo].linkptr = NULL;
760 ccb[mbo].commlinkid = 0;
761
762 #if (BUSLOGIC_DEBUG & BD_COMMAND)
763 {
764 size_t i;
765
766 buslogic_printk("sending...");
767 for (i = 0; i < sizeof ccb[mbo] - 10; i++)
768 printk(" %02X", ((unsigned char *)&ccb[mbo])[i]);
769 printk("\n");
770 }
771 #endif
772
773 if (done) {
774 #if (BUSLOGIC_DEBUG & BD_COMMAND)
775 buslogic_printk("now waiting for interrupt: ");
776 buslogic_stat(shpnt->io_port);
777 #endif
778 scpnt->scsi_done = done;
779 mb[mbo].status = MBX_ACTION_START;
780
781 buslogic_out(shpnt->io_port, buscmd, sizeof buscmd);
782 #if (BUSLOGIC_DEBUG & BD_COMMAND)
783 buslogic_stat(shpnt->io_port);
784 #endif
785 } else
786 buslogic_printk("done can't be NULL.\n");
787
788 while (0) {
789 #if defined(MODULE) && !defined(GFP_DMA)
790 baddma:
791 buslogic_printk("address > 16MB used for ISA HA.\n");
792 #endif
793 fail:
794 scpnt->result = DID_ERROR << 16;
795 done(scpnt);
796 }
797
798 return 0;
799 }
800
801 #if 0
802 static void internal_done(Scsi_Cmnd *scpnt)
803 {
804 scpnt->SCp.Status++;
805 }
806
807 int buslogic_command(Scsi_Cmnd *scpnt)
808 {
809 #if (BUSLOGIC_DEBUG & BD_COMMAND)
810 buslogic_printk("calling buslogic_queuecommand.\n");
811 #endif
812
813 buslogic_queuecommand(scpnt, internal_done);
814
815 scpnt->SCp.Status = 0;
816 while (!scpnt->SCp.Status)
817 continue;
818 return scpnt->result;
819 }
820 #endif
821
822
823 static int setup_mailboxes(unsigned int base, struct Scsi_Host *shpnt)
824 {
825 size_t i;
826 int ok = FALSE;
827 struct mailbox *mb = HOSTDATA(shpnt)->mb;
828 struct ccb *ccb = HOSTDATA(shpnt)->ccbs;
829 struct {
830 unsigned char cmd, count;
831 void *base PACKED;
832 } cmd = { CMD_INITEXTMB, BUSLOGIC_MAILBOXES, mb };
833
834 for (i = 0; i < BUSLOGIC_MAILBOXES; i++) {
835 mb[i].status = mb[BUSLOGIC_MAILBOXES + i].status = MBX_NOT_IN_USE;
836 mb[i].ccbptr = &ccb[i];
837 }
838 INTR_RESET(base);
839
840 if (buslogic_out(base, (unsigned char *)&cmd, sizeof cmd))
841 goto fail;
842 WAIT_UNTIL(INTERRUPT(base), CMDC);
843
844 ok = TRUE;
845
846 while (0) {
847 fail:
848 buslogic_printk("failed setting up mailboxes.\n");
849 }
850
851 INTR_RESET(base);
852
853 return !ok;
854 }
855
856 static int getconfig(unsigned int base, unsigned char *irq,
857 unsigned char *dma, unsigned char *id,
858 char *bus_type, unsigned short *max_sg,
859 const unsigned char **bios)
860 {
861 unsigned char inquiry_cmd[2];
862 unsigned char inquiry_result[4];
863 int i;
864
865 #if (BUSLOGIC_DEBUG & BD_DETECT)
866 buslogic_printk("called\n");
867 #endif
868
869 i = inb(STATUS(base));
870 if (i & DIRRDY)
871 i = inb(DATA_IN(base));
872 inquiry_cmd[0] = CMD_RETCONF;
873 buslogic_out(base, inquiry_cmd, 1);
874 if (buslogic_in(base, inquiry_result, 3))
875 goto fail;
876 WAIT_UNTIL_FAST(INTERRUPT(base), CMDC);
877 INTR_RESET(base);
878
879 *dma = inquiry_result[0];
880 switch (inquiry_result[1]) {
881 case 0x01:
882 *irq = 9;
883 break;
884 case 0x02:
885 *irq = 10;
886 break;
887 case 0x04:
888 *irq = 11;
889 break;
890 case 0x08:
891 *irq = 12;
892 break;
893 case 0x20:
894 *irq = 14;
895 break;
896 case 0x40:
897 *irq = 15;
898 break;
899 default:
900 buslogic_printk("unable to determine BusLogic IRQ level, "
901 " disabling board.\n");
902 goto fail;
903 }
904 *id = inquiry_result[2] & 0x7;
905
906
907 inquiry_cmd[0] = CMD_INQEXTSETUP;
908 inquiry_cmd[1] = 4;
909 if (buslogic_out(base, inquiry_cmd, 2))
910 goto fail;
911 if (buslogic_in(base, inquiry_result, inquiry_cmd[1]))
912 goto fail;
913 WAIT_UNTIL_FAST(INTERRUPT(base), CMDC);
914 if (inb(STATUS(base)) & CMDINV)
915 goto fail;
916 INTR_RESET(base);
917
918 *bus_type = inquiry_result[0];
919 CHECK(*bus_type == 'A' || *bus_type == 'E' || *bus_type == 'M');
920
921 *bios = (const unsigned char *)((unsigned int)inquiry_result[1] << 12);
922
923 *max_sg = (inquiry_result[3] << 8) | inquiry_result[2];
924
925
926
927
928
929 if (*bus_type == 'A')
930 switch (*dma) {
931 case 0:
932 *dma = 0;
933 break;
934 case 0x20:
935 *dma = 5;
936 break;
937 case 0x40:
938 *dma = 6;
939 break;
940 case 0x80:
941 *dma = 7;
942 break;
943 default:
944 buslogic_printk("unable to determine BusLogic DMA channel,"
945 " disabling board.\n");
946 goto fail;
947 }
948 else
949 *dma = 0;
950
951 while (0) {
952 fail:
953 #if (BUSLOGIC_DEBUG & BD_DETECT)
954 buslogic_printk("query board settings\n");
955 #endif
956 return TRUE;
957 }
958
959 return FALSE;
960 }
961
962
963
964 static int buslogic_query(unsigned int base, unsigned char *trans,
965 unsigned char *irq, unsigned char *dma,
966 unsigned char *id, char *bus_type,
967 unsigned short *max_sg, const unsigned char **bios,
968 char *model, char *firmware_rev)
969 {
970 unsigned char inquiry_cmd[2];
971 unsigned char inquiry_result[6];
972 unsigned char geo;
973 unsigned int i;
974
975 #if (BUSLOGIC_DEBUG & BD_DETECT)
976 buslogic_printk("called\n");
977 #endif
978
979
980 if (inb(STATUS(base)) == 0xFF)
981 goto fail;
982
983
984 geo = inb(GEOMETRY(base));
985 #if (BUSLOGIC_DEBUG & BD_DETECT)
986 buslogic_printk("geometry bits: %02X\n", geo);
987 #endif
988
989
990 if (geo == 0xFF)
991 goto fail;
992
993
994 INTR_RESET(base);
995
996
997
998 outb(RSOFT | RINT, CONTROL(base));
999
1000
1001 i = jiffies + 2;
1002 while (i > jiffies);
1003
1004
1005 WAIT(STATUS(base), INREQ | HARDY, DACT | DFAIL | CMDINV | DIRRDY | CPRBSY);
1006
1007
1008 if (inb(INTERRUPT(base)) & INTRMASK)
1009 goto fail;
1010
1011
1012
1013
1014
1015 inquiry_cmd[0] = CMD_INQUIRY;
1016 buslogic_out(base, inquiry_cmd, 1);
1017 if (buslogic_in(base, inquiry_result, 4))
1018 goto fail;
1019
1020 if (inb(STATUS(base)) & DIRRDY)
1021 goto fail;
1022 WAIT_UNTIL_FAST(INTERRUPT(base), CMDC);
1023 INTR_RESET(base);
1024 firmware_rev[0] = inquiry_result[2];
1025 firmware_rev[1] = '.';
1026 firmware_rev[2] = inquiry_result[3];
1027 firmware_rev[3] = '\0';
1028 #if 0
1029 buslogic_printk("inquiry bytes: %02X(%c) %02X(%c)\n",
1030 inquiry_result[0], inquiry_result[0],
1031 inquiry_result[1], inquiry_result[1]);
1032 #endif
1033
1034 if (getconfig(base, irq, dma, id, bus_type, max_sg, bios))
1035 goto fail;
1036
1037
1038 #ifdef BIOS_TRANSLATION_OVERRIDE
1039 *trans = BIOS_TRANSLATION_OVERRIDE;
1040 #else
1041 *trans = BIOS_TRANSLATION_DEFAULT;
1042 #endif
1043 model[0] = '\0';
1044 model[6] = 0;
1045
1046
1047
1048
1049 do {
1050
1051
1052
1053 if (geo == 0x00)
1054 break;
1055 #ifndef BIOS_TRANSLATION_OVERRIDE
1056 *trans = ((geo & GEO_GT_1GB)
1057 ? BIOS_TRANSLATION_BIG : BIOS_TRANSLATION_DEFAULT);
1058 #endif
1059
1060 inquiry_cmd[0] = CMD_VER_NO_LAST;
1061 buslogic_out(base, inquiry_cmd, 1);
1062 if (buslogic_in(base, inquiry_result, 1))
1063 break;
1064 WAIT_UNTIL_FAST(INTERRUPT(base), CMDC);
1065 INTR_RESET(base);
1066 firmware_rev[3] = inquiry_result[0];
1067 firmware_rev[4] = '\0';
1068
1069 inquiry_cmd[0] = CMD_VER_NO_LETTER;
1070 buslogic_out(base, inquiry_cmd, 1);
1071 if (buslogic_in(base, inquiry_result, 1))
1072 break;
1073 WAIT_UNTIL_FAST(INTERRUPT(base), CMDC);
1074 INTR_RESET(base);
1075 firmware_rev[4] = inquiry_result[0];
1076 firmware_rev[5] = '\0';
1077
1078
1079
1080 inquiry_cmd[0] = CMD_RET_MODEL_NO;
1081 inquiry_cmd[1] = 6;
1082 buslogic_out(base, inquiry_cmd, 2);
1083 if (buslogic_in(base, inquiry_result, inquiry_cmd[1]))
1084 break;
1085 WAIT_UNTIL_FAST(INTERRUPT(base), CMDC);
1086 INTR_RESET(base);
1087 memcpy(model, inquiry_result, 5);
1088 model[5] = '\0';
1089 model[6] = inquiry_result[5];
1090 } while (0);
1091
1092
1093
1094
1095
1096 switch (*bus_type) {
1097 case 'E':
1098 switch (model[0]) {
1099 case '4':
1100 *bus_type = 'V';
1101 break;
1102 case '9':
1103 *bus_type = 'P';
1104 break;
1105 case '7':
1106 break;
1107 default:
1108 *bus_type = 'X';
1109 break;
1110 }
1111 break;
1112 default:
1113 break;
1114 }
1115
1116 while (0) {
1117 fail:
1118 #if (BUSLOGIC_DEBUG & BD_DETECT)
1119 buslogic_printk("query board settings\n");
1120 #endif
1121 return TRUE;
1122 }
1123
1124 return FALSE;
1125 }
1126
1127
1128 int buslogic_detect(Scsi_Host_Template *tpnt)
1129 {
1130 unsigned char dma;
1131 unsigned char irq;
1132 unsigned int base;
1133 unsigned char id;
1134 char bus_type;
1135 unsigned short max_sg;
1136 unsigned char bios_translation;
1137 unsigned long flags;
1138 const unsigned char *bios;
1139 char *model;
1140 char *firmware_rev;
1141 struct Scsi_Host *shpnt;
1142 size_t indx;
1143 int unchecked_isa_dma;
1144 int count = 0;
1145
1146 #if (BUSLOGIC_DEBUG & BD_DETECT)
1147 buslogic_printk("called\n");
1148 #endif
1149
1150 tpnt->can_queue = BUSLOGIC_MAILBOXES;
1151 for (indx = 0; bases[indx] != 0; indx++)
1152 if (!check_region(bases[indx], 4)) {
1153 shpnt = scsi_register(tpnt, sizeof (struct hostdata));
1154
1155 base = bases[indx];
1156
1157 model = HOSTDATA(shpnt)->model;
1158 firmware_rev = HOSTDATA(shpnt)->firmware_rev;
1159 if (buslogic_query(base, &bios_translation, &irq, &dma, &id,
1160 &bus_type, &max_sg, &bios, model, firmware_rev))
1161 goto unregister;
1162
1163 #if (BUSLOGIC_DEBUG & BD_DETECT)
1164 buslogic_stat(base);
1165 #endif
1166
1167
1168 unchecked_isa_dma = (bus_type == 'A');
1169 #ifndef CONFIG_NO_BUGGY_BUSLOGIC
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181 if (bus_type == 'V'
1182 && firmware_rev[0] <= '3'
1183 && bios != NULL) {
1184 #if 1
1185
1186
1187
1188 shpnt->forbidden_addr = (unsigned long)bios;
1189 shpnt->forbidden_size = 16 * 1024;
1190 #else
1191
1192 unchecked_isa_dma = TRUE;
1193 #endif
1194 }
1195 #endif
1196
1197 CHECK_DMA_ADDR(unchecked_isa_dma, shpnt, goto unregister);
1198
1199 if (setup_mailboxes(base, shpnt))
1200 goto unregister;
1201
1202
1203
1204
1205 if (bus_type != 'E' && bus_type != 'P') {
1206
1207 static const unsigned char oncmd[] = { CMD_BUSON_TIME, 7 };
1208 static const unsigned char offcmd[] = { CMD_BUSOFF_TIME, 5 };
1209
1210 INTR_RESET(base);
1211 buslogic_out(base, oncmd, sizeof oncmd);
1212 WAIT_UNTIL(INTERRUPT(base), CMDC);
1213 INTR_RESET(base);
1214 buslogic_out(base, offcmd, sizeof offcmd);
1215 WAIT_UNTIL(INTERRUPT(base), CMDC);
1216 while (0) {
1217 fail:
1218 buslogic_printk("setting bus on/off-time failed.\n");
1219 }
1220 INTR_RESET(base);
1221 }
1222
1223 buslogic_printk("configuring %s HA at port 0x%03X, IRQ %u",
1224 (bus_type == 'A' ? "ISA"
1225 : (bus_type == 'E' ? "EISA"
1226 : (bus_type == 'M' ? "MCA"
1227 : (bus_type == 'P' ? "PCI"
1228 : (bus_type == 'V' ? "VESA"
1229 : (bus_type == 'X' ? "EISA/VESA/PCI"
1230 : "Unknown")))))),
1231 base, irq);
1232 if (bios != NULL)
1233 printk(", BIOS 0x%05X", (unsigned int)bios);
1234 if (dma != 0)
1235 printk(", DMA %u", dma);
1236 printk(", ID %u\n", id);
1237 buslogic_printk("Model Number: %s",
1238 (model[0] ? model : "Unknown"));
1239 if (model[0])
1240 printk(" (revision %d)", model[6]);
1241 printk("\n");
1242 buslogic_printk("firmware revision: %s\n", firmware_rev);
1243
1244 #if (BUSLOGIC_DEBUG & BD_DETECT)
1245 buslogic_stat(base);
1246 #endif
1247
1248 #if (BUSLOGIC_DEBUG & BD_DETECT)
1249 buslogic_printk("enable interrupt channel %d.\n", irq);
1250 #endif
1251
1252 save_flags(flags);
1253 cli();
1254 if (request_irq(irq, buslogic_interrupt, 0, "buslogic")) {
1255 buslogic_printk("unable to allocate IRQ for "
1256 "BusLogic controller.\n");
1257 restore_flags(flags);
1258 goto unregister;
1259 }
1260
1261 if (dma) {
1262 if (request_dma(dma, "buslogic")) {
1263 buslogic_printk("unable to allocate DMA channel for "
1264 "BusLogic controller.\n");
1265 free_irq(irq);
1266 restore_flags(flags);
1267 goto unregister;
1268 }
1269
1270
1271
1272
1273 set_dma_mode(dma, DMA_MODE_CASCADE);
1274 enable_dma(dma);
1275 }
1276
1277 host[irq - 9] = shpnt;
1278 shpnt->this_id = id;
1279 shpnt->unchecked_isa_dma = unchecked_isa_dma;
1280
1281
1282 shpnt->cmd_per_lun = (unchecked_isa_dma ? 1 : BUSLOGIC_CMDLUN);
1283 shpnt->sg_tablesize = max_sg;
1284 if (shpnt->sg_tablesize > BUSLOGIC_MAX_SG)
1285 shpnt->sg_tablesize = BUSLOGIC_MAX_SG;
1286
1287 shpnt->base = (unsigned char *)bios;
1288 shpnt->io_port = base;
1289 shpnt->n_io_port = 4;
1290 shpnt->dma_channel = dma;
1291 shpnt->irq = irq;
1292 HOSTDATA(shpnt)->bios_translation = bios_translation;
1293 if (bios_translation == BIOS_TRANSLATION_BIG)
1294 buslogic_printk("using extended bios translation.\n");
1295 HOSTDATA(shpnt)->last_mbi_used = 2 * BUSLOGIC_MAILBOXES - 1;
1296 HOSTDATA(shpnt)->last_mbo_used = BUSLOGIC_MAILBOXES - 1;
1297 memset(HOSTDATA(shpnt)->sc, 0, sizeof HOSTDATA(shpnt)->sc);
1298 restore_flags(flags);
1299
1300 #if 0
1301 {
1302 unsigned char buf[8];
1303 unsigned char cmd[]
1304 = { READ_CAPACITY, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
1305 size_t i;
1306
1307 #if (BUSLOGIC_DEBUG & BD_DETECT)
1308 buslogic_printk("*** READ CAPACITY ***\n");
1309 #endif
1310 for (i = 0; i < sizeof buf; i++)
1311 buf[i] = 0x87;
1312 for (i = 0; i < 2; i++)
1313 if (!buslogic_command(i, cmd, buf, sizeof buf)) {
1314 buslogic_printk("LU %u sector_size %d device_size %d\n",
1315 i, *(int *)(buf + 4), *(int *)buf);
1316 }
1317
1318 #if (BUSLOGIC_DEBUG & BD_DETECT)
1319 buslogic_printk("*** NOW RUNNING MY OWN TEST ***\n");
1320 #endif
1321 for (i = 0; i < 4; i++) {
1322 static buffer[512];
1323
1324 cmd[0] = READ_10;
1325 cmd[1] = 0;
1326 xany2scsi(cmd + 2, i);
1327 cmd[6] = 0;
1328 cmd[7] = 0;
1329 cmd[8] = 1;
1330 cmd[9] = 0;
1331 buslogic_command(0, cmd, buffer, sizeof buffer);
1332 }
1333 }
1334 #endif
1335
1336 request_region(bases[indx], 4,"buslogic");
1337
1338 count++;
1339 continue;
1340 unregister:
1341 scsi_unregister(shpnt);
1342 }
1343 return count;
1344 }
1345
1346 static int restart(struct Scsi_Host *shpnt)
1347 {
1348 unsigned int i;
1349 unsigned int count = 0;
1350 #if 0
1351 static const unsigned char buscmd[] = { CMD_START_SCSI };
1352 #endif
1353
1354 for (i = 0; i < BUSLOGIC_MAILBOXES; i++)
1355 if (HOSTDATA(shpnt)->sc[i]
1356 && !HOSTDATA(shpnt)->sc[i]->device->soft_reset) {
1357 #if 0
1358 HOSTDATA(shpnt)->mb[i].status
1359 = MBX_ACTION_START;
1360 #endif
1361 count++;
1362 }
1363
1364 buslogic_printk("potential to restart %d stalled commands...\n", count);
1365 #if 0
1366
1367 if (count)
1368 buslogic_out(shpnt->host->io_port, buscmd, sizeof buscmd);
1369 #endif
1370 return 0;
1371 }
1372
1373
1374
1375
1376
1377 int buslogic_abort(Scsi_Cmnd *scpnt)
1378 {
1379 #if 1
1380 static const unsigned char buscmd[] = { CMD_START_SCSI };
1381 struct mailbox *mb;
1382 size_t mbi, mbo;
1383 unsigned long flags;
1384 unsigned int i;
1385
1386 buslogic_printk("%X %X\n",
1387 inb(STATUS(scpnt->host->io_port)),
1388 inb(INTERRUPT(scpnt->host->io_port)));
1389
1390 save_flags(flags);
1391 cli();
1392 mb = HOSTDATA(scpnt->host)->mb;
1393 mbi = HOSTDATA(scpnt->host)->last_mbi_used + 1;
1394 if (mbi >= 2 * BUSLOGIC_MAILBOXES)
1395 mbi = BUSLOGIC_MAILBOXES;
1396
1397 do {
1398 if (mb[mbi].status != MBX_NOT_IN_USE)
1399 break;
1400 mbi++;
1401 if (mbi >= 2 * BUSLOGIC_MAILBOXES)
1402 mbi = BUSLOGIC_MAILBOXES;
1403 } while (mbi != HOSTDATA(scpnt->host)->last_mbi_used);
1404 restore_flags(flags);
1405
1406 if (mb[mbi].status != MBX_NOT_IN_USE) {
1407 buslogic_printk("lost interrupt discovered on irq %d"
1408 " - attempting to recover...\n",
1409 scpnt->host->irq);
1410 {
1411 int intval[3];
1412
1413 intval[0] = scpnt->host->irq;
1414 buslogic_interrupt((int)&intval[2]);
1415 return SCSI_ABORT_SUCCESS;
1416 }
1417 }
1418
1419
1420
1421 for (i = 0; i < BUSLOGIC_MAILBOXES; i++)
1422 if (HOSTDATA(scpnt->host)->sc[i]) {
1423 if (HOSTDATA(scpnt->host)->sc[i] == scpnt) {
1424 buslogic_printk("timed out command pending for %4.4X.\n",
1425 scpnt->request.dev);
1426 if (HOSTDATA(scpnt->host)->mb[i].status != MBX_NOT_IN_USE) {
1427 buslogic_printk("OGMB still full - restarting...\n");
1428 buslogic_out(scpnt->host->io_port, buscmd, sizeof buscmd);
1429 }
1430 } else
1431 buslogic_printk("other pending command: %4.4X\n",
1432 scpnt->request.dev);
1433 }
1434 #endif
1435
1436 #if (BUSLOGIC_DEBUG & BD_ABORT)
1437 buslogic_printk("called\n");
1438 #endif
1439
1440 #if 1
1441
1442
1443 save_flags(flags);
1444 cli();
1445 for (mbo = 0; mbo < BUSLOGIC_MAILBOXES; mbo++)
1446 if (scpnt == HOSTDATA(scpnt->host)->sc[mbo]) {
1447 mb[mbo].status = MBX_ACTION_ABORT;
1448 buslogic_out(scpnt->host->io_port, buscmd, sizeof buscmd);
1449 break;
1450 }
1451 restore_flags(flags);
1452 #endif
1453
1454 return SCSI_ABORT_SNOOZE;
1455 }
1456
1457
1458
1459
1460
1461
1462 int buslogic_reset(Scsi_Cmnd *scpnt)
1463 {
1464 static const unsigned char buscmd[] = { CMD_START_SCSI };
1465 unsigned int i;
1466
1467 #if (BUSLOGIC_DEBUG & BD_RESET)
1468 buslogic_printk("called\n");
1469 #endif
1470 #if 0
1471
1472 outb(RSBUS, CONTROL(scpnt->host->io_port));
1473 #else
1474
1475
1476 for (i = 0; i < BUSLOGIC_MAILBOXES; i++)
1477 if (HOSTDATA(scpnt->host)->sc[i] == scpnt) {
1478 HOSTDATA(scpnt->host)->ccbs[i].op = CCB_OP_BUS_RESET;
1479
1480
1481
1482 buslogic_out(scpnt->host->io_port, buscmd, sizeof buscmd);
1483
1484
1485
1486
1487
1488 buslogic_printk("sent BUS DEVICE RESET to target %d.\n",
1489 scpnt->target);
1490
1491
1492
1493
1494 #if 1
1495 for (i = 0; i < BUSLOGIC_MAILBOXES; i++)
1496 if (HOSTDATA(scpnt->host)->sc[i]
1497 && HOSTDATA(scpnt->host)->sc[i]->target == scpnt->target) {
1498 Scsi_Cmnd *sctmp = HOSTDATA(scpnt->host)->sc[i];
1499
1500 sctmp->result = DID_RESET << 16;
1501 if (sctmp->host_scribble)
1502 scsi_free(sctmp->host_scribble, BUSLOGIC_SG_MALLOC);
1503 buslogic_printk("sending DID_RESET for target %d.\n",
1504 scpnt->target);
1505 sctmp->scsi_done(scpnt);
1506
1507 HOSTDATA(scpnt->host)->sc[i] = NULL;
1508 HOSTDATA(scpnt->host)->mb[i].status = MBX_NOT_IN_USE;
1509 }
1510 return SCSI_RESET_SUCCESS;
1511 #else
1512 return SCSI_RESET_PENDING;
1513 #endif
1514 }
1515 #endif
1516
1517
1518
1519 return SCSI_RESET_PUNT;
1520 }
1521
1522
1523
1524
1525
1526
1527 int buslogic_biosparam(Disk *disk, int dev, int *ip)
1528 {
1529 unsigned int size = disk->capacity;
1530
1531
1532 if (HOSTDATA(disk->device->host)->bios_translation == BIOS_TRANSLATION_BIG
1533 && size >= 0x200000) {
1534 if (size >= 0x400000) {
1535 #if 0
1536 if (mb >= 0x800000) {
1537 ip[0] = 256;
1538 ip[1] = 64;
1539 } else {
1540 ip[0] = 256;
1541 ip[1] = 32;
1542 }
1543 #else
1544 ip[0] = 256;
1545 ip[1] = 64;
1546 #endif
1547 } else {
1548 ip[0] = 128;
1549 ip[1] = 32;
1550 }
1551 } else {
1552 ip[0] = 64;
1553 ip[1] = 32;
1554 }
1555 ip[2] = size / (ip[0] * ip[1]);
1556
1557
1558 return 0;
1559 }
1560
1561
1562 void buslogic_setup(char *str, int *ints)
1563 {
1564 static const unsigned short valid_bases[]
1565 = { 0x130, 0x134, 0x230, 0x234, 0x330, 0x334 };
1566 static size_t setup_idx = 0;
1567 size_t i;
1568
1569 if (setup_idx >= ARRAY_SIZE(bases) - 1) {
1570 buslogic_printk("called too many times. Bad LILO params?\n");
1571 return;
1572 }
1573 if (ints[0] != 1) {
1574 buslogic_printk("malformed command line.\n");
1575 buslogic_printk("usage: buslogic=<portbase>\n");
1576 return;
1577 }
1578 for (i = 0; i < ARRAY_SIZE(valid_bases); i++)
1579 if (valid_bases[i] == ints[1]) {
1580 bases[setup_idx++] = ints[1];
1581 bases[setup_idx] = 0;
1582 return;
1583 }
1584 buslogic_printk("invalid base 0x%X specified.\n", ints[i]);
1585 }
1586
1587 #ifdef MODULE
1588
1589 Scsi_Host_Template driver_template = BUSLOGIC;
1590
1591 # include "scsi_module.c"
1592 #endif