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