This source file includes following definitions.
- aha1542_stat
- aha1542_out
- aha1542_in
- aha1542_in1
- makecode
- aha1542_test_port
- aha1542_intr_handle
- aha1542_queuecommand
- internal_done
- aha1542_command
- setup_mailboxes
- aha1542_getconfig
- aha1542_mbenable
- aha1542_query
- aha1542_setup
- aha1542_detect
- aha1542_restart
- aha1542_abort
- aha1542_reset
- aha1542_biosparam
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 #include <linux/kernel.h>
18 #include <linux/head.h>
19 #include <linux/types.h>
20 #include <linux/string.h>
21 #include <linux/ioport.h>
22
23 #include <linux/delay.h>
24
25 #include <linux/sched.h>
26 #include <asm/dma.h>
27
28 #include <asm/system.h>
29 #include <asm/io.h>
30 #include "../block/blk.h"
31 #include "scsi.h"
32 #include "hosts.h"
33
34 #include "aha1542.h"
35
36 #ifdef DEBUG
37 #define DEB(x) x
38 #else
39 #define DEB(x)
40 #endif
41
42
43
44
45
46
47
48
49
50 #define MAXBOARDS 2
51
52
53 static unsigned int bases[MAXBOARDS]={0x330, 0x334};
54
55
56 static int setup_called[MAXBOARDS] = {0,0};
57 static int setup_buson[MAXBOARDS] = {0,0};
58 static int setup_busoff[MAXBOARDS] = {0,0};
59 static int setup_dmaspeed[MAXBOARDS] = {-1,-1};
60
61 static char *setup_str[MAXBOARDS] = {(char *)NULL,(char *)NULL};
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83 #define DMA_MODE_REG 0xd6
84 #define DMA_MASK_REG 0xd4
85 #define CASCADE 0xc0
86
87 #define BIOS_TRANSLATION_1632 0
88 #define BIOS_TRANSLATION_6432 1
89 #define BIOS_TRANSLATION_25563 2
90
91 struct aha1542_hostdata{
92
93 int bios_translation;
94 int aha1542_last_mbi_used;
95 int aha1542_last_mbo_used;
96 Scsi_Cmnd * SCint[AHA1542_MAILBOXES];
97 struct mailbox mb[2*AHA1542_MAILBOXES];
98 struct ccb ccb[AHA1542_MAILBOXES];
99 };
100
101 #define HOSTDATA(host) ((struct aha1542_hostdata *) &host->hostdata)
102
103 static struct Scsi_Host * aha_host[7] = {NULL,};
104
105
106
107
108 #define WAITnexttimeout 3000000
109
110 static void setup_mailboxes(int base_io, struct Scsi_Host * shpnt);
111 static int aha1542_restart(struct Scsi_Host * shost);
112
113 #define aha1542_intr_reset(base) outb(IRST, CONTROL(base))
114
115 #define WAIT(port, mask, allof, noneof) \
116 { register WAITbits; \
117 register WAITtimeout = WAITnexttimeout; \
118 while (1) { \
119 WAITbits = inb(port) & (mask); \
120 if ((WAITbits & (allof)) == (allof) && ((WAITbits & (noneof)) == 0)) \
121 break; \
122 if (--WAITtimeout == 0) goto fail; \
123 } \
124 }
125
126
127
128 #define WAITd(port, mask, allof, noneof, timeout) \
129 { register WAITbits; \
130 register WAITtimeout = timeout; \
131 while (1) { \
132 WAITbits = inb(port) & (mask); \
133 if ((WAITbits & (allof)) == (allof) && ((WAITbits & (noneof)) == 0)) \
134 break; \
135 udelay(1000); \
136 if (--WAITtimeout == 0) goto fail; \
137 } \
138 }
139
140 static void aha1542_stat(void)
141 {
142
143
144 }
145
146
147
148
149
150 static int aha1542_out(unsigned int base, unchar *cmdp, int len)
151 {
152 if(len == 1) {
153 while(1==1){
154 WAIT(STATUS(base), CDF, 0, CDF);
155 cli();
156 if(inb(STATUS(base)) & CDF) {sti(); continue;}
157 outb(*cmdp, DATA(base));
158 sti();
159 return 0;
160 }
161 } else {
162 cli();
163 while (len--)
164 {
165 WAIT(STATUS(base), CDF, 0, CDF);
166 outb(*cmdp++, DATA(base));
167 }
168 sti();
169 }
170 return 0;
171 fail:
172 sti();
173 printk("aha1542_out failed(%d): ", len+1); aha1542_stat();
174 return 1;
175 }
176
177
178
179 static int aha1542_in(unsigned int base, unchar *cmdp, int len)
180 {
181 cli();
182 while (len--)
183 {
184 WAIT(STATUS(base), DF, DF, 0);
185 *cmdp++ = inb(DATA(base));
186 }
187 sti();
188 return 0;
189 fail:
190 sti();
191 printk("aha1542_in failed(%d): ", len+1); aha1542_stat();
192 return 1;
193 }
194
195
196
197
198 static int aha1542_in1(unsigned int base, unchar *cmdp, int len)
199 {
200 cli();
201 while (len--)
202 {
203 WAITd(STATUS(base), DF, DF, 0, 100);
204 *cmdp++ = inb(DATA(base));
205 }
206 sti();
207 return 0;
208 fail:
209 sti();
210 return 1;
211 }
212
213 static int makecode(unsigned hosterr, unsigned scsierr)
214 {
215 switch (hosterr) {
216 case 0x0:
217 case 0xa:
218 case 0xb:
219 hosterr = 0;
220 break;
221
222 case 0x11:
223
224 hosterr = DID_TIME_OUT;
225 break;
226
227 case 0x12:
228
229
230
231 case 0x13:
232
233 case 0x15:
234
235
236 case 0x16:
237
238
239 case 0x17:
240
241
242 case 0x18:
243
244
245 case 0x19:
246
247
248
249 case 0x1a:
250
251
252 DEB(printk("Aha1542: %x %x\n", hosterr, scsierr));
253 hosterr = DID_ERROR;
254 break;
255
256 case 0x14:
257
258
259
260 hosterr = DID_RESET;
261 break;
262 default:
263 printk("makecode: unknown hoststatus %x\n", hosterr);
264 break;
265 }
266 return scsierr|(hosterr << 16);
267 }
268
269 static int aha1542_test_port(int bse, struct Scsi_Host * shpnt)
270 {
271 int i;
272 unchar inquiry_cmd[] = {CMD_INQUIRY };
273 unchar inquiry_result[4];
274 unchar *cmdp;
275 int len;
276 volatile int debug = 0;
277
278
279 if(inb(STATUS(bse)) == 0xff) return 0;
280
281
282
283
284
285
286 aha1542_intr_reset(bse);
287
288 outb(SRST|IRST, CONTROL(bse));
289
290 i = jiffies + 2;
291 while (i>jiffies);
292
293 debug = 1;
294
295 WAIT(STATUS(bse), STATMASK, INIT|IDLE, STST|DIAGF|INVDCMD|DF|CDF);
296
297 debug = 2;
298
299 if (inb(INTRFLAGS(bse))&INTRMASK) goto fail;
300
301
302
303
304
305 aha1542_out(bse, inquiry_cmd, 1);
306
307 debug = 3;
308 len = 4;
309 cmdp = &inquiry_result[0];
310
311 while (len--)
312 {
313 WAIT(STATUS(bse), DF, DF, 0);
314 *cmdp++ = inb(DATA(bse));
315 }
316
317 debug = 8;
318
319 if (inb(STATUS(bse)) & DF) goto fail;
320
321 debug = 9;
322
323 WAIT(INTRFLAGS(bse), HACC, HACC, 0);
324
325
326 debug = 10;
327
328 outb(IRST, CONTROL(bse));
329
330 debug = 11;
331
332 return debug;
333 fail:
334 return 0;
335 }
336
337
338 static void aha1542_intr_handle(int foo)
339 {
340 void (*my_done)(Scsi_Cmnd *) = NULL;
341 int errstatus, mbi, mbo, mbistatus;
342 int number_serviced;
343 struct Scsi_Host * shost;
344 Scsi_Cmnd * SCtmp;
345 int irqno, * irqp, flag;
346 int needs_restart;
347 struct mailbox * mb;
348 struct ccb *ccb;
349
350 irqp = (int *) foo;
351 irqp -= 2;
352 irqno = *irqp;
353
354 shost = aha_host[irqno - 9];
355 if(!shost) panic("Splunge!");
356
357 mb = HOSTDATA(shost)->mb;
358 ccb = HOSTDATA(shost)->ccb;
359
360 #ifdef DEBUG
361 {
362 flag = inb(INTRFLAGS(shost->io_port));
363 printk("aha1542_intr_handle: ");
364 if (!(flag&ANYINTR)) printk("no interrupt?");
365 if (flag&MBIF) printk("MBIF ");
366 if (flag&MBOA) printk("MBOF ");
367 if (flag&HACC) printk("HACC ");
368 if (flag&SCRD) printk("SCRD ");
369 printk("status %02x\n", inb(STATUS(shost->io_port)));
370 };
371 #endif
372 number_serviced = 0;
373 needs_restart = 0;
374
375 while(1==1){
376 flag = inb(INTRFLAGS(shost->io_port));
377
378
379
380
381
382 if (flag & ~MBIF) {
383 if (flag&MBOA) printk("MBOF ");
384 if (flag&HACC) printk("HACC ");
385 if (flag&SCRD) {
386 needs_restart = 1;
387 printk("SCRD ");
388 }
389 }
390
391 aha1542_intr_reset(shost->io_port);
392
393 cli();
394 mbi = HOSTDATA(shost)->aha1542_last_mbi_used + 1;
395 if (mbi >= 2*AHA1542_MAILBOXES) mbi = AHA1542_MAILBOXES;
396
397 do{
398 if(mb[mbi].status != 0) break;
399 mbi++;
400 if (mbi >= 2*AHA1542_MAILBOXES) mbi = AHA1542_MAILBOXES;
401 } while (mbi != HOSTDATA(shost)->aha1542_last_mbi_used);
402
403 if(mb[mbi].status == 0){
404 sti();
405
406 if (!number_serviced && !needs_restart)
407 printk("aha1542.c: interrupt received, but no mail.\n");
408
409
410 if(needs_restart) aha1542_restart(shost);
411 return;
412 };
413
414 mbo = (scsi2int(mb[mbi].ccbptr) - ((unsigned int) &ccb[0])) / sizeof(struct ccb);
415 mbistatus = mb[mbi].status;
416 mb[mbi].status = 0;
417 HOSTDATA(shost)->aha1542_last_mbi_used = mbi;
418 sti();
419
420 #ifdef DEBUG
421 {
422 if (ccb[mbo].tarstat|ccb[mbo].hastat)
423 printk("aha1542_command: returning %x (status %d)\n",
424 ccb[mbo].tarstat + ((int) ccb[mbo].hastat << 16), mb[mbi].status);
425 };
426 #endif
427
428 if(mbistatus == 3) continue;
429
430 #ifdef DEBUG
431 printk("...done %d %d\n",mbo, mbi);
432 #endif
433
434 SCtmp = HOSTDATA(shost)->SCint[mbo];
435
436 if (!SCtmp || !SCtmp->scsi_done) {
437 printk("aha1542_intr_handle: Unexpected interrupt\n");
438 printk("tarstat=%x, hastat=%x idlun=%x ccb#=%d \n", ccb[mbo].tarstat,
439 ccb[mbo].hastat, ccb[mbo].idlun, mbo);
440 return;
441 }
442
443 my_done = SCtmp->scsi_done;
444 if (SCtmp->host_scribble) scsi_free(SCtmp->host_scribble, 512);
445
446
447
448
449 if (ccb[mbo].tarstat == 2)
450 memcpy(SCtmp->sense_buffer, &ccb[mbo].cdb[ccb[mbo].cdblen],
451 sizeof(SCtmp->sense_buffer));
452
453
454
455
456
457 if (mbistatus != 1)
458
459 errstatus = makecode(ccb[mbo].hastat, ccb[mbo].tarstat);
460 else
461 errstatus = 0;
462
463 #ifdef DEBUG
464 if(errstatus) printk("(aha1542 error:%x %x %x) ",errstatus,
465 ccb[mbo].hastat, ccb[mbo].tarstat);
466 #endif
467
468 if (ccb[mbo].tarstat == 2) {
469 #ifdef DEBUG
470 int i;
471 #endif
472 DEB(printk("aha1542_intr_handle: sense:"));
473 #ifdef DEBUG
474 for (i = 0; i < 12; i++)
475 printk("%02x ", ccb[mbo].cdb[ccb[mbo].cdblen+i]);
476 printk("\n");
477 #endif
478
479
480
481
482
483
484 }
485 DEB(if (errstatus) printk("aha1542_intr_handle: returning %6x\n", errstatus));
486 SCtmp->result = errstatus;
487 HOSTDATA(shost)->SCint[mbo] = NULL;
488
489 my_done(SCtmp);
490 number_serviced++;
491 };
492 }
493
494 int aha1542_queuecommand(Scsi_Cmnd * SCpnt, void (*done)(Scsi_Cmnd *))
495 {
496 unchar ahacmd = CMD_START_SCSI;
497 unchar direction;
498 unchar *cmd = (unchar *) SCpnt->cmnd;
499 unchar target = SCpnt->target;
500 unchar lun = SCpnt->lun;
501 void *buff = SCpnt->request_buffer;
502 int bufflen = SCpnt->request_bufflen;
503 int mbo;
504 struct mailbox * mb;
505 struct ccb *ccb;
506
507 DEB(int i);
508
509 mb = HOSTDATA(SCpnt->host)->mb;
510 ccb = HOSTDATA(SCpnt->host)->ccb;
511
512 DEB(if (target > 1) {
513 SCpnt->result = DID_TIME_OUT << 16;
514 done(SCpnt); return 0;});
515
516 if(*cmd == REQUEST_SENSE){
517 #ifndef DEBUG
518 if (bufflen != sizeof(SCpnt->sense_buffer)) {
519 printk("Wrong buffer length supplied for request sense (%d)\n",bufflen);
520 };
521 #endif
522 SCpnt->result = 0;
523 done(SCpnt);
524 return 0;
525 };
526
527 #ifdef DEBUG
528 if (*cmd == READ_10 || *cmd == WRITE_10)
529 i = xscsi2int(cmd+2);
530 else if (*cmd == READ_6 || *cmd == WRITE_6)
531 i = scsi2int(cmd+2);
532 else
533 i = -1;
534 if (done)
535 printk("aha1542_queuecommand: dev %d cmd %02x pos %d len %d ", target, *cmd, i, bufflen);
536 else
537 printk("aha1542_command: dev %d cmd %02x pos %d len %d ", target, *cmd, i, bufflen);
538 aha1542_stat();
539 printk("aha1542_queuecommand: dumping scsi cmd:");
540 for (i = 0; i < SCpnt->cmd_len; i++) printk("%02x ", cmd[i]);
541 printk("\n");
542 if (*cmd == WRITE_10 || *cmd == WRITE_6)
543 return 0;
544 #endif
545
546
547
548 cli();
549 mbo = HOSTDATA(SCpnt->host)->aha1542_last_mbo_used + 1;
550 if (mbo >= AHA1542_MAILBOXES) mbo = 0;
551
552 do{
553 if(mb[mbo].status == 0 && HOSTDATA(SCpnt->host)->SCint[mbo] == NULL)
554 break;
555 mbo++;
556 if (mbo >= AHA1542_MAILBOXES) mbo = 0;
557 } while (mbo != HOSTDATA(SCpnt->host)->aha1542_last_mbo_used);
558
559 if(mb[mbo].status || HOSTDATA(SCpnt->host)->SCint[mbo])
560 panic("Unable to find empty mailbox for aha1542.\n");
561
562 HOSTDATA(SCpnt->host)->SCint[mbo] = SCpnt;
563
564
565 HOSTDATA(SCpnt->host)->aha1542_last_mbo_used = mbo;
566 sti();
567
568 #ifdef DEBUG
569 printk("Sending command (%d %x)...",mbo, done);
570 #endif
571
572 any2scsi(mb[mbo].ccbptr, &ccb[mbo]);
573
574 memset(&ccb[mbo], 0, sizeof(struct ccb));
575
576 ccb[mbo].cdblen = SCpnt->cmd_len;
577
578 direction = 0;
579 if (*cmd == READ_10 || *cmd == READ_6)
580 direction = 8;
581 else if (*cmd == WRITE_10 || *cmd == WRITE_6)
582 direction = 16;
583
584 memcpy(ccb[mbo].cdb, cmd, ccb[mbo].cdblen);
585
586 if (SCpnt->use_sg) {
587 struct scatterlist * sgpnt;
588 struct chain * cptr;
589 #ifdef DEBUG
590 unsigned char * ptr;
591 #endif
592 int i;
593 ccb[mbo].op = 2;
594 SCpnt->host_scribble = (unsigned char *) scsi_malloc(512);
595 sgpnt = (struct scatterlist *) SCpnt->request_buffer;
596 cptr = (struct chain *) SCpnt->host_scribble;
597 if (cptr == NULL) panic("aha1542.c: unable to allocate DMA memory\n");
598 for(i=0; i<SCpnt->use_sg; i++) {
599 if(sgpnt[i].length == 0 || SCpnt->use_sg > 16 ||
600 (((int)sgpnt[i].address) & 1) || (sgpnt[i].length & 1)){
601 unsigned char * ptr;
602 printk("Bad segment list supplied to aha1542.c (%d, %d)\n",SCpnt->use_sg,i);
603 for(i=0;i<SCpnt->use_sg;i++){
604 printk("%d: %x %x %d\n",i,(unsigned int) sgpnt[i].address, (unsigned int) sgpnt[i].alt_address,
605 sgpnt[i].length);
606 };
607 printk("cptr %x: ",(unsigned int) cptr);
608 ptr = (unsigned char *) &cptr[i];
609 for(i=0;i<18;i++) printk("%02x ", ptr[i]);
610 panic("Foooooooood fight!");
611 };
612 any2scsi(cptr[i].dataptr, sgpnt[i].address);
613 if(((unsigned int) sgpnt[i].address) & 0xff000000) goto baddma;
614 any2scsi(cptr[i].datalen, sgpnt[i].length);
615 };
616 any2scsi(ccb[mbo].datalen, SCpnt->use_sg * sizeof(struct chain));
617 any2scsi(ccb[mbo].dataptr, cptr);
618 #ifdef DEBUG
619 printk("cptr %x: ",cptr);
620 ptr = (unsigned char *) cptr;
621 for(i=0;i<18;i++) printk("%02x ", ptr[i]);
622 #endif
623 } else {
624 ccb[mbo].op = 0;
625 SCpnt->host_scribble = NULL;
626 any2scsi(ccb[mbo].datalen, bufflen);
627 if(((unsigned int) buff & 0xff000000)) goto baddma;
628 any2scsi(ccb[mbo].dataptr, buff);
629 };
630 ccb[mbo].idlun = (target&7)<<5 | direction | (lun & 7);
631 ccb[mbo].rsalen = 12;
632 ccb[mbo].linkptr[0] = ccb[mbo].linkptr[1] = ccb[mbo].linkptr[2] = 0;
633 ccb[mbo].commlinkid = 0;
634
635 #ifdef DEBUG
636 { int i;
637 printk("aha1542_command: sending.. ");
638 for (i = 0; i < sizeof(ccb[mbo])-10; i++)
639 printk("%02x ", ((unchar *)&ccb[mbo])[i]);
640 };
641 #endif
642
643 if (done) {
644 DEB(printk("aha1542_queuecommand: now waiting for interrupt "); aha1542_stat());
645 SCpnt->scsi_done = done;
646 mb[mbo].status = 1;
647 aha1542_out(SCpnt->host->io_port, &ahacmd, 1);
648 DEB(aha1542_stat());
649 }
650 else
651 printk("aha1542_queuecommand: done can't be NULL\n");
652
653 return 0;
654 baddma:
655 panic("Buffer at address > 16Mb used for 1542B");
656 }
657
658 static void internal_done(Scsi_Cmnd * SCpnt)
659 {
660 SCpnt->SCp.Status++;
661 }
662
663 int aha1542_command(Scsi_Cmnd * SCpnt)
664 {
665 DEB(printk("aha1542_command: ..calling aha1542_queuecommand\n"));
666
667 aha1542_queuecommand(SCpnt, internal_done);
668
669 SCpnt->SCp.Status = 0;
670 while (!SCpnt->SCp.Status);
671 return SCpnt->result;
672 }
673
674
675 static void setup_mailboxes(int bse, struct Scsi_Host * shpnt)
676 {
677 int i;
678 struct mailbox * mb;
679 struct ccb *ccb;
680
681 unchar cmd[5] = {CMD_MBINIT, AHA1542_MAILBOXES, 0, 0, 0};
682
683 mb = HOSTDATA(shpnt)->mb;
684 ccb = HOSTDATA(shpnt)->ccb;
685
686 for(i=0; i<AHA1542_MAILBOXES; i++){
687 mb[i].status = mb[AHA1542_MAILBOXES+i].status = 0;
688 any2scsi(mb[i].ccbptr, &ccb[i]);
689 };
690 aha1542_intr_reset(bse);
691 any2scsi((cmd+2), mb);
692 aha1542_out(bse, cmd, 5);
693 WAIT(INTRFLAGS(bse), INTRMASK, HACC, 0);
694 while (0) {
695 fail:
696 printk("aha1542_detect: failed setting up mailboxes\n");
697 }
698 aha1542_intr_reset(bse);
699 }
700
701 static int aha1542_getconfig(int base_io, unsigned char * irq_level, unsigned char * dma_chan)
702 {
703 unchar inquiry_cmd[] = {CMD_RETCONF };
704 unchar inquiry_result[3];
705 int i;
706 i = inb(STATUS(base_io));
707 if (i & DF) {
708 i = inb(DATA(base_io));
709 };
710 aha1542_out(base_io, inquiry_cmd, 1);
711 aha1542_in(base_io, inquiry_result, 3);
712 WAIT(INTRFLAGS(base_io), INTRMASK, HACC, 0);
713 while (0) {
714 fail:
715 printk("aha1542_detect: query board settings\n");
716 }
717 aha1542_intr_reset(base_io);
718 switch(inquiry_result[0]){
719 case 0x80:
720 *dma_chan = 7;
721 break;
722 case 0x40:
723 *dma_chan = 6;
724 break;
725 case 0x20:
726 *dma_chan = 5;
727 break;
728 case 0x01:
729 printk("DMA priority 0 not available for Adaptec driver\n");
730 return -1;
731 case 0:
732
733
734 *dma_chan = 0xFF;
735 break;
736 default:
737 printk("Unable to determine Adaptec DMA priority. Disabling board\n");
738 return -1;
739 };
740 switch(inquiry_result[1]){
741 case 0x40:
742 *irq_level = 15;
743 break;
744 case 0x20:
745 *irq_level = 14;
746 break;
747 case 0x8:
748 *irq_level = 12;
749 break;
750 case 0x4:
751 *irq_level = 11;
752 break;
753 case 0x2:
754 *irq_level = 10;
755 break;
756 case 0x1:
757 *irq_level = 9;
758 break;
759 default:
760 printk("Unable to determine Adaptec IRQ level. Disabling board\n");
761 return -1;
762 };
763 return 0;
764 }
765
766
767
768
769 static int aha1542_mbenable(int base)
770 {
771 static unchar mbenable_cmd[3];
772 static unchar mbenable_result[2];
773 int retval;
774
775 retval = BIOS_TRANSLATION_6432;
776
777 mbenable_cmd[0]=CMD_EXTBIOS;
778 aha1542_out(base,mbenable_cmd,1);
779 if(aha1542_in1(base,mbenable_result,2))
780 return retval;
781 WAITd(INTRFLAGS(base),INTRMASK,HACC,0,100);
782 aha1542_intr_reset(base);
783
784 if ((mbenable_result[0] & 0x08) || mbenable_result[1]) {
785 mbenable_cmd[0]=CMD_MBENABLE;
786 mbenable_cmd[1]=0;
787 mbenable_cmd[2]=mbenable_result[1];
788 if(mbenable_result[1] & 1) retval = BIOS_TRANSLATION_25563;
789 aha1542_out(base,mbenable_cmd,3);
790 WAIT(INTRFLAGS(base),INTRMASK,HACC,0);
791 };
792 while(0) {
793 fail:
794 printk("aha1542_mbenable: Mailbox init failed\n");
795 }
796 aha1542_intr_reset(base);
797 return retval;
798 }
799
800
801 static int aha1542_query(int base_io, int * transl)
802 {
803 unchar inquiry_cmd[] = {CMD_INQUIRY };
804 unchar inquiry_result[4];
805 int i;
806 i = inb(STATUS(base_io));
807 if (i & DF) {
808 i = inb(DATA(base_io));
809 };
810 aha1542_out(base_io, inquiry_cmd, 1);
811 aha1542_in(base_io, inquiry_result, 4);
812 WAIT(INTRFLAGS(base_io), INTRMASK, HACC, 0);
813 while (0) {
814 fail:
815 printk("aha1542_detect: query card type\n");
816 }
817 aha1542_intr_reset(base_io);
818
819 *transl = BIOS_TRANSLATION_6432;
820
821
822
823
824
825
826
827 if (inquiry_result[0] == 0x43) {
828 printk("aha1542.c: Emulation mode not supported for AHA 174N hardware.\n");
829 return 1;
830 };
831
832
833
834
835 *transl = aha1542_mbenable(base_io);
836
837 return 0;
838 }
839
840
841 void aha1542_setup( char *str, int *ints)
842 {
843 char *ahausage = "aha1542: usage: aha1542=<PORTBASE>[,<BUSON>,<BUSOFF>[,<DMASPEED>]]\n";
844 static int setup_idx = 0;
845 int setup_portbase;
846
847 if(setup_idx >= MAXBOARDS)
848 {
849 printk("aha1542: aha1542_setup called too many times! Bad LILO params ?\n");
850 printk(" Entryline 1: %s\n",setup_str[0]);
851 printk(" Entryline 2: %s\n",setup_str[1]);
852 printk(" This line: %s\n",str);
853 return;
854 }
855 if (ints[0] < 1 || ints[0] > 4)
856 {
857 printk("aha1542: %s\n", str );
858 printk(ahausage);
859 printk("aha1542: Wrong parameters may cause system malfunction.. We try anyway..\n");
860 }
861
862 setup_called[setup_idx]=ints[0];
863 setup_str[setup_idx]=str;
864
865 setup_portbase = ints[0] >= 1 ? ints[1] : 0;
866 setup_buson [setup_idx] = ints[0] >= 2 ? ints[2] : 7;
867 setup_busoff [setup_idx] = ints[0] >= 3 ? ints[3] : 5;
868 if (ints[0] >= 4) {
869 int atbt = -1;
870 switch (ints[4]) {
871 case 5:
872 atbt = 0x00;
873 break;
874 case 6:
875 atbt = 0x04;
876 break;
877 case 7:
878 atbt = 0x01;
879 break;
880 case 8:
881 atbt = 0x02;
882 break;
883 case 10:
884 atbt = 0x03;
885 break;
886 default:
887 printk("aha1542: %s\n", str );
888 printk(ahausage);
889 printk("aha1542: Valid values for DMASPEED are 5-8, 10 MB/s. Using jumper defaults.\n");
890 break;
891 }
892 setup_dmaspeed[setup_idx] = atbt;
893 }
894
895 if (setup_portbase != 0)
896 bases[setup_idx] = setup_portbase;
897
898 ++setup_idx;
899 }
900
901
902 int aha1542_detect(Scsi_Host_Template * tpnt)
903 {
904 unsigned char dma_chan;
905 unsigned char irq_level;
906 unsigned int base_io;
907 int trans;
908 struct Scsi_Host * shpnt = NULL;
909 int count = 0;
910 int indx;
911
912 DEB(printk("aha1542_detect: \n"));
913
914 for(indx = 0; indx < sizeof(bases)/sizeof(bases[0]); indx++)
915 if(bases[indx] != 0 && !check_region(bases[indx], 4)) {
916 shpnt = scsi_register(tpnt,
917 sizeof(struct aha1542_hostdata));
918
919
920
921 if ((unsigned int) shpnt > 0xffffff) {
922 printk("Invalid address for shpnt with 1542.\n");
923 goto unregister;
924 }
925
926 if(!aha1542_test_port(bases[indx], shpnt)) goto unregister;
927
928
929 base_io = bases[indx];
930
931
932 {
933 unchar oncmd[] = {CMD_BUSON_TIME, 7};
934 unchar offcmd[] = {CMD_BUSOFF_TIME, 5};
935
936 if(setup_called[indx])
937 {
938 oncmd[1] = setup_buson[indx];
939 offcmd[1] = setup_busoff[indx];
940 }
941
942 aha1542_intr_reset(base_io);
943 aha1542_out(base_io, oncmd, 2);
944 WAIT(INTRFLAGS(base_io), INTRMASK, HACC, 0);
945 aha1542_intr_reset(base_io);
946 aha1542_out(base_io, offcmd, 2);
947 WAIT(INTRFLAGS(base_io), INTRMASK, HACC, 0);
948 if (setup_dmaspeed[indx] >= 0)
949 {
950 unchar dmacmd[] = {CMD_DMASPEED, 0};
951 dmacmd[1] = setup_dmaspeed[indx];
952 aha1542_intr_reset(base_io);
953 aha1542_out(base_io, dmacmd, 2);
954 WAIT(INTRFLAGS(base_io), INTRMASK, HACC, 0);
955 }
956 while (0) {
957 fail:
958 printk("aha1542_detect: setting bus on/off-time failed\n");
959 }
960 aha1542_intr_reset(base_io);
961 }
962 if(aha1542_query(base_io, &trans)) goto unregister;
963
964 if (aha1542_getconfig(base_io, &irq_level, &dma_chan) == -1) goto unregister;
965
966 printk("Configuring Adaptec at IO:%x, IRQ %d",base_io, irq_level);
967 if (dma_chan != 0xFF)
968 printk(", DMA priority %d", dma_chan);
969 printk("\n");
970
971 DEB(aha1542_stat());
972 setup_mailboxes(base_io, shpnt);
973
974 DEB(aha1542_stat());
975
976 DEB(printk("aha1542_detect: enable interrupt channel %d\n", irq_level));
977 cli();
978 if (request_irq(irq_level,aha1542_intr_handle, 0, "aha1542")) {
979 printk("Unable to allocate IRQ for adaptec controller.\n");
980 goto unregister;
981 }
982
983 if (dma_chan != 0xFF) {
984 if (request_dma(dma_chan,"aha1542")) {
985 printk("Unable to allocate DMA channel for Adaptec.\n");
986 free_irq(irq_level);
987 goto unregister;
988 }
989
990 if (dma_chan >= 5) {
991 outb((dma_chan - 4) | CASCADE, DMA_MODE_REG);
992 outb(dma_chan - 4, DMA_MASK_REG);
993 }
994 }
995 aha_host[irq_level - 9] = shpnt;
996 shpnt->io_port = base_io;
997 shpnt->n_io_port = 4;
998 shpnt->dma_channel = dma_chan;
999 shpnt->irq = irq_level;
1000 HOSTDATA(shpnt)->bios_translation = trans;
1001 if(trans == 2)
1002 printk("aha1542.c: Using extended bios translation\n");
1003 HOSTDATA(shpnt)->aha1542_last_mbi_used = (2*AHA1542_MAILBOXES - 1);
1004 HOSTDATA(shpnt)->aha1542_last_mbo_used = (AHA1542_MAILBOXES - 1);
1005 memset(HOSTDATA(shpnt)->SCint, 0, sizeof(HOSTDATA(shpnt)->SCint));
1006 sti();
1007 #if 0
1008 DEB(printk(" *** READ CAPACITY ***\n"));
1009
1010 {
1011 unchar buf[8];
1012 static unchar cmd[] = { READ_CAPACITY, 0, 0, 0, 0, 0, 0, 0, 0, 0};
1013 int i;
1014
1015 for (i = 0; i < sizeof(buf); ++i) buf[i] = 0x87;
1016 for (i = 0; i < 2; ++i)
1017 if (!aha1542_command(i, cmd, buf, sizeof(buf))) {
1018 printk("aha_detect: LU %d sector_size %d device_size %d\n",
1019 i, xscsi2int(buf+4), xscsi2int(buf));
1020 }
1021 }
1022
1023 DEB(printk(" *** NOW RUNNING MY OWN TEST *** \n"));
1024
1025 for (i = 0; i < 4; ++i)
1026 {
1027 unsigned char cmd[10];
1028 static buffer[512];
1029
1030 cmd[0] = READ_10;
1031 cmd[1] = 0;
1032 xany2scsi(cmd+2, i);
1033 cmd[6] = 0;
1034 cmd[7] = 0;
1035 cmd[8] = 1;
1036 cmd[9] = 0;
1037 aha1542_command(0, cmd, buffer, 512);
1038 }
1039 #endif
1040 snarf_region(bases[indx], 4);
1041 count++;
1042 continue;
1043 unregister:
1044 scsi_unregister(shpnt);
1045 continue;
1046
1047 };
1048 return count;
1049 }
1050
1051 static int aha1542_restart(struct Scsi_Host * shost)
1052 {
1053 int i;
1054 int count = 0;
1055 #if 0
1056 unchar ahacmd = CMD_START_SCSI;
1057 #endif
1058
1059 for(i=0; i< AHA1542_MAILBOXES; i++)
1060 if(HOSTDATA(shost)->SCint[i] &&
1061 !(HOSTDATA(shost)->SCint[i]->device->soft_reset))
1062 {
1063 #if 0
1064 HOSTDATA(shost)->mb[i].status = 1;
1065 #endif
1066 count++;
1067 }
1068
1069 printk("Potential to restart %d stalled commands...\n", count);
1070 #if 0
1071
1072 if (count) aha1542_out(shost->io_port, &ahacmd, 1);
1073 #endif
1074 return 0;
1075 }
1076
1077
1078
1079
1080
1081 int aha1542_abort(Scsi_Cmnd * SCpnt)
1082 {
1083 #if 0
1084 int intval[3];
1085 unchar ahacmd = CMD_START_SCSI;
1086 struct mailbox * mb;
1087 int mbi, mbo, i;
1088
1089 printk("In aha1542_abort: %x %x\n",
1090 inb(STATUS(SCpnt->host->io_port)),
1091 inb(INTRFLAGS(SCpnt->host->io_port)));
1092
1093 cli();
1094 mb = HOSTDATA(SCpnt->host)->mb;
1095 mbi = HOSTDATA(SCpnt->host)->aha1542_last_mbi_used + 1;
1096 if (mbi >= 2*AHA1542_MAILBOXES) mbi = AHA1542_MAILBOXES;
1097
1098 do{
1099 if(mb[mbi].status != 0) break;
1100 mbi++;
1101 if (mbi >= 2*AHA1542_MAILBOXES) mbi = AHA1542_MAILBOXES;
1102 } while (mbi != HOSTDATA(SCpnt->host)->aha1542_last_mbi_used);
1103 sti();
1104
1105 if(mb[mbi].status) {
1106 printk("Lost interrupt discovered on irq %d - attempting to recover\n",
1107 SCpnt->host->irq);
1108 intval[0] = SCpnt->host->irq;
1109 aha1542_intr_handle((int) &intval[2]);
1110 return 0;
1111 }
1112
1113
1114
1115
1116 for(i=0; i< AHA1542_MAILBOXES; i++)
1117 if(HOSTDATA(SCpnt->host)->SCint[i])
1118 {
1119 if(HOSTDATA(SCpnt->host)->SCint[i] == SCpnt) {
1120 printk("Timed out command pending for %4.4x\n", SCpnt->request.dev);
1121 if (HOSTDATA(SCpnt->host)->mb[i].status) {
1122 printk("OGMB still full - restarting\n");
1123 aha1542_out(SCpnt->host->io_port, &ahacmd, 1);
1124 };
1125 } else
1126 printk("Other pending command %4.4x\n", SCpnt->request.dev);
1127 }
1128
1129 #endif
1130
1131 DEB(printk("aha1542_abort\n"));
1132 #if 0
1133 cli();
1134 for(mbo = 0; mbo < AHA1542_MAILBOXES; mbo++)
1135 if (SCpnt == HOSTDATA(SCpnt->host)->SCint[mbo]){
1136 mb[mbo].status = 2;
1137 aha1542_out(SCpnt->host->io_port, &ahacmd, 1);
1138 sti();
1139 break;
1140 };
1141 #endif
1142 return SCSI_ABORT_SNOOZE;
1143 }
1144
1145
1146
1147
1148
1149
1150
1151 int aha1542_reset(Scsi_Cmnd * SCpnt)
1152 {
1153 unchar ahacmd = CMD_START_SCSI;
1154 int i;
1155
1156 DEB(printk("aha1542_reset called\n"));
1157 #if 0
1158
1159 outb(SCRST, CONTROL(SCpnt->host->io_port));
1160 #else
1161
1162
1163 for(i=0; i< AHA1542_MAILBOXES; i++)
1164 if(HOSTDATA(SCpnt->host)->SCint[i] == SCpnt)
1165 {
1166 HOSTDATA(SCpnt->host)->ccb[i].op = 0x81;
1167
1168 aha1542_out(SCpnt->host->io_port, &ahacmd, 1);
1169
1170
1171
1172
1173
1174 printk("Sent BUS DEVICE RESET to target %d\n", SCpnt->target);
1175
1176
1177
1178
1179 #if 1
1180 for(i=0; i< AHA1542_MAILBOXES; i++)
1181 if(HOSTDATA(SCpnt->host)->SCint[i] &&
1182 HOSTDATA(SCpnt->host)->SCint[i]->target == SCpnt->target)
1183 {
1184 Scsi_Cmnd * SCtmp;
1185 SCtmp = HOSTDATA(SCpnt->host)->SCint[i];
1186 SCtmp->result = DID_RESET << 16;
1187 if (SCtmp->host_scribble) scsi_free(SCtmp->host_scribble, 512);
1188 printk("Sending DID_RESET for target %d\n", SCpnt->target);
1189 SCtmp->scsi_done(SCpnt);
1190
1191 HOSTDATA(SCpnt->host)->SCint[i] = NULL;
1192 HOSTDATA(SCpnt->host)->mb[i].status = 0;
1193 }
1194 return SCSI_RESET_SUCCESS;
1195 #else
1196 return SCSI_RESET_PENDING;
1197 #endif
1198 }
1199
1200 #endif
1201
1202
1203
1204 return SCSI_RESET_PUNT;
1205 }
1206
1207 #include "sd.h"
1208
1209 int aha1542_biosparam(Scsi_Disk * disk, int dev, int * ip)
1210 {
1211 int translation_algorithm;
1212 int size = disk->capacity;
1213
1214 translation_algorithm = HOSTDATA(disk->device->host)->bios_translation;
1215
1216 if((size>>11) > 1024 && translation_algorithm == 2) {
1217
1218 ip[0] = 255;
1219 ip[1] = 63;
1220 ip[2] = size /255/63;
1221 } else {
1222 ip[0] = 64;
1223 ip[1] = 32;
1224 ip[2] = size >> 11;
1225 };
1226
1227 return 0;
1228 }
1229
1230
1231 #ifdef MODULE
1232
1233 Scsi_Host_Template driver_template = AHA1542;
1234
1235 #include "scsi_module.c"
1236 #endif
1237