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 #ifdef MODULE
18 #include <linux/autoconf.h>
19 #include <linux/module.h>
20 #endif
21
22 #include <linux/kernel.h>
23 #include <linux/head.h>
24 #include <linux/types.h>
25 #include <linux/string.h>
26 #include <linux/ioport.h>
27 #include <linux/delay.h>
28 #include <linux/sched.h>
29 #include <linux/proc_fs.h>
30 #include <asm/dma.h>
31 #include <asm/system.h>
32 #include <asm/io.h>
33 #include "../block/blk.h"
34 #include "scsi.h"
35 #include "hosts.h"
36
37
38 #include "aha1542.h"
39
40 #ifdef DEBUG
41 #define DEB(x) x
42 #else
43 #define DEB(x)
44 #endif
45
46
47
48
49
50
51
52
53
54 #define MAXBOARDS 2
55
56
57 static unsigned int bases[MAXBOARDS]={0x330, 0x334};
58
59
60 static int setup_called[MAXBOARDS] = {0,0};
61 static int setup_buson[MAXBOARDS] = {0,0};
62 static int setup_busoff[MAXBOARDS] = {0,0};
63 static int setup_dmaspeed[MAXBOARDS] = {-1,-1};
64
65 static char *setup_str[MAXBOARDS] = {(char *)NULL,(char *)NULL};
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87 #define DMA_MODE_REG 0xd6
88 #define DMA_MASK_REG 0xd4
89 #define CASCADE 0xc0
90
91 #define BIOS_TRANSLATION_1632 0
92 #define BIOS_TRANSLATION_6432 1
93 #define BIOS_TRANSLATION_25563 2
94
95 struct aha1542_hostdata{
96
97 int bios_translation;
98 int aha1542_last_mbi_used;
99 int aha1542_last_mbo_used;
100 Scsi_Cmnd * SCint[AHA1542_MAILBOXES];
101 struct mailbox mb[2*AHA1542_MAILBOXES];
102 struct ccb ccb[AHA1542_MAILBOXES];
103 };
104
105 #define HOSTDATA(host) ((struct aha1542_hostdata *) &host->hostdata)
106
107 static struct Scsi_Host * aha_host[7] = {NULL,};
108
109
110
111
112 #define WAITnexttimeout 3000000
113
114 static void setup_mailboxes(int base_io, struct Scsi_Host * shpnt);
115 static int aha1542_restart(struct Scsi_Host * shost);
116
117 #define aha1542_intr_reset(base) outb(IRST, CONTROL(base))
118
119 #define WAIT(port, mask, allof, noneof) \
120 { register WAITbits; \
121 register WAITtimeout = WAITnexttimeout; \
122 while (1) { \
123 WAITbits = inb(port) & (mask); \
124 if ((WAITbits & (allof)) == (allof) && ((WAITbits & (noneof)) == 0)) \
125 break; \
126 if (--WAITtimeout == 0) goto fail; \
127 } \
128 }
129
130
131
132 #define WAITd(port, mask, allof, noneof, timeout) \
133 { register WAITbits; \
134 register WAITtimeout = timeout; \
135 while (1) { \
136 WAITbits = inb(port) & (mask); \
137 if ((WAITbits & (allof)) == (allof) && ((WAITbits & (noneof)) == 0)) \
138 break; \
139 udelay(1000); \
140 if (--WAITtimeout == 0) goto fail; \
141 } \
142 }
143
144 static void aha1542_stat(void)
145 {
146
147
148 }
149
150
151
152
153
154 static int aha1542_out(unsigned int base, unchar *cmdp, int len)
155 {
156 unsigned long flags = 0;
157
158 if(len == 1) {
159 while(1==1){
160 WAIT(STATUS(base), CDF, 0, CDF);
161 save_flags(flags);
162 cli();
163 if(inb(STATUS(base)) & CDF) {restore_flags(flags); continue;}
164 outb(*cmdp, DATA(base));
165 restore_flags(flags);
166 return 0;
167 }
168 } else {
169 save_flags(flags);
170 cli();
171 while (len--)
172 {
173 WAIT(STATUS(base), CDF, 0, CDF);
174 outb(*cmdp++, DATA(base));
175 }
176 restore_flags(flags);
177 }
178 return 0;
179 fail:
180 restore_flags(flags);
181 printk("aha1542_out failed(%d): ", len+1); aha1542_stat();
182 return 1;
183 }
184
185
186
187 static int aha1542_in(unsigned int base, unchar *cmdp, int len)
188 {
189 unsigned long flags;
190
191 save_flags(flags);
192 cli();
193 while (len--)
194 {
195 WAIT(STATUS(base), DF, DF, 0);
196 *cmdp++ = inb(DATA(base));
197 }
198 restore_flags(flags);
199 return 0;
200 fail:
201 restore_flags(flags);
202 printk("aha1542_in failed(%d): ", len+1); aha1542_stat();
203 return 1;
204 }
205
206
207
208
209 static int aha1542_in1(unsigned int base, unchar *cmdp, int len)
210 {
211 unsigned long flags;
212
213 save_flags(flags);
214 cli();
215 while (len--)
216 {
217 WAITd(STATUS(base), DF, DF, 0, 100);
218 *cmdp++ = inb(DATA(base));
219 }
220 restore_flags(flags);
221 return 0;
222 fail:
223 restore_flags(flags);
224 return 1;
225 }
226
227 static int makecode(unsigned hosterr, unsigned scsierr)
228 {
229 switch (hosterr) {
230 case 0x0:
231 case 0xa:
232 case 0xb:
233 hosterr = 0;
234 break;
235
236 case 0x11:
237
238 hosterr = DID_TIME_OUT;
239 break;
240
241 case 0x12:
242
243
244
245 case 0x13:
246
247 case 0x15:
248
249
250 case 0x16:
251
252
253 case 0x17:
254
255
256 case 0x18:
257
258
259 case 0x19:
260
261
262
263 case 0x1a:
264
265
266 DEB(printk("Aha1542: %x %x\n", hosterr, scsierr));
267 hosterr = DID_ERROR;
268 break;
269
270 case 0x14:
271
272
273
274 hosterr = DID_RESET;
275 break;
276 default:
277 printk("makecode: unknown hoststatus %x\n", hosterr);
278 break;
279 }
280 return scsierr|(hosterr << 16);
281 }
282
283 static int aha1542_test_port(int bse, struct Scsi_Host * shpnt)
284 {
285 int i;
286 unchar inquiry_cmd[] = {CMD_INQUIRY };
287 unchar inquiry_result[4];
288 unchar *cmdp;
289 int len;
290 volatile int debug = 0;
291
292
293 if(inb(STATUS(bse)) == 0xff) return 0;
294
295
296
297
298
299
300 aha1542_intr_reset(bse);
301
302 outb(SRST|IRST, CONTROL(bse));
303
304 i = jiffies + 2;
305 while (i>jiffies);
306
307 debug = 1;
308
309 WAIT(STATUS(bse), STATMASK, INIT|IDLE, STST|DIAGF|INVDCMD|DF|CDF);
310
311 debug = 2;
312
313 if (inb(INTRFLAGS(bse))&INTRMASK) goto fail;
314
315
316
317
318
319 aha1542_out(bse, inquiry_cmd, 1);
320
321 debug = 3;
322 len = 4;
323 cmdp = &inquiry_result[0];
324
325 while (len--)
326 {
327 WAIT(STATUS(bse), DF, DF, 0);
328 *cmdp++ = inb(DATA(bse));
329 }
330
331 debug = 8;
332
333 if (inb(STATUS(bse)) & DF) goto fail;
334
335 debug = 9;
336
337 WAIT(INTRFLAGS(bse), HACC, HACC, 0);
338
339
340 debug = 10;
341
342 outb(IRST, CONTROL(bse));
343
344 debug = 11;
345
346 return debug;
347 fail:
348 return 0;
349 }
350
351
352 static void aha1542_intr_handle(int irq, struct pt_regs *regs)
353 {
354 void (*my_done)(Scsi_Cmnd *) = NULL;
355 int errstatus, mbi, mbo, mbistatus;
356 int number_serviced;
357 unsigned int flags;
358 struct Scsi_Host * shost;
359 Scsi_Cmnd * SCtmp;
360 int flag;
361 int needs_restart;
362 struct mailbox * mb;
363 struct ccb *ccb;
364
365 shost = aha_host[irq - 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 barrier();
686 return SCpnt->result;
687 }
688
689
690 static void setup_mailboxes(int bse, struct Scsi_Host * shpnt)
691 {
692 int i;
693 struct mailbox * mb;
694 struct ccb *ccb;
695
696 unchar cmd[5] = {CMD_MBINIT, AHA1542_MAILBOXES, 0, 0, 0};
697
698 mb = HOSTDATA(shpnt)->mb;
699 ccb = HOSTDATA(shpnt)->ccb;
700
701 for(i=0; i<AHA1542_MAILBOXES; i++){
702 mb[i].status = mb[AHA1542_MAILBOXES+i].status = 0;
703 any2scsi(mb[i].ccbptr, &ccb[i]);
704 };
705 aha1542_intr_reset(bse);
706 any2scsi((cmd+2), mb);
707 aha1542_out(bse, cmd, 5);
708 WAIT(INTRFLAGS(bse), INTRMASK, HACC, 0);
709 while (0) {
710 fail:
711 printk("aha1542_detect: failed setting up mailboxes\n");
712 }
713 aha1542_intr_reset(bse);
714 }
715
716 static int aha1542_getconfig(int base_io, unsigned char * irq_level, unsigned char * dma_chan, unsigned char * scsi_id)
717 {
718 unchar inquiry_cmd[] = {CMD_RETCONF };
719 unchar inquiry_result[3];
720 int i;
721 i = inb(STATUS(base_io));
722 if (i & DF) {
723 i = inb(DATA(base_io));
724 };
725 aha1542_out(base_io, inquiry_cmd, 1);
726 aha1542_in(base_io, inquiry_result, 3);
727 WAIT(INTRFLAGS(base_io), INTRMASK, HACC, 0);
728 while (0) {
729 fail:
730 printk("aha1542_detect: query board settings\n");
731 }
732 aha1542_intr_reset(base_io);
733 switch(inquiry_result[0]){
734 case 0x80:
735 *dma_chan = 7;
736 break;
737 case 0x40:
738 *dma_chan = 6;
739 break;
740 case 0x20:
741 *dma_chan = 5;
742 break;
743 case 0x01:
744 printk("DMA priority 0 not available for Adaptec driver\n");
745 return -1;
746 case 0:
747
748
749 *dma_chan = 0xFF;
750 break;
751 default:
752 printk("Unable to determine Adaptec DMA priority. Disabling board\n");
753 return -1;
754 };
755 switch(inquiry_result[1]){
756 case 0x40:
757 *irq_level = 15;
758 break;
759 case 0x20:
760 *irq_level = 14;
761 break;
762 case 0x8:
763 *irq_level = 12;
764 break;
765 case 0x4:
766 *irq_level = 11;
767 break;
768 case 0x2:
769 *irq_level = 10;
770 break;
771 case 0x1:
772 *irq_level = 9;
773 break;
774 default:
775 printk("Unable to determine Adaptec IRQ level. Disabling board\n");
776 return -1;
777 };
778 *scsi_id=inquiry_result[2] & 7;
779 return 0;
780 }
781
782
783
784
785 static int aha1542_mbenable(int base)
786 {
787 static unchar mbenable_cmd[3];
788 static unchar mbenable_result[2];
789 int retval;
790
791 retval = BIOS_TRANSLATION_6432;
792
793 mbenable_cmd[0]=CMD_EXTBIOS;
794 aha1542_out(base,mbenable_cmd,1);
795 if(aha1542_in1(base,mbenable_result,2))
796 return retval;
797 WAITd(INTRFLAGS(base),INTRMASK,HACC,0,100);
798 aha1542_intr_reset(base);
799
800 if ((mbenable_result[0] & 0x08) || mbenable_result[1]) {
801 mbenable_cmd[0]=CMD_MBENABLE;
802 mbenable_cmd[1]=0;
803 mbenable_cmd[2]=mbenable_result[1];
804 if(mbenable_result[1] & 1) retval = BIOS_TRANSLATION_25563;
805 aha1542_out(base,mbenable_cmd,3);
806 WAIT(INTRFLAGS(base),INTRMASK,HACC,0);
807 };
808 while(0) {
809 fail:
810 printk("aha1542_mbenable: Mailbox init failed\n");
811 }
812 aha1542_intr_reset(base);
813 return retval;
814 }
815
816
817 static int aha1542_query(int base_io, int * transl)
818 {
819 unchar inquiry_cmd[] = {CMD_INQUIRY };
820 unchar inquiry_result[4];
821 int i;
822 i = inb(STATUS(base_io));
823 if (i & DF) {
824 i = inb(DATA(base_io));
825 };
826 aha1542_out(base_io, inquiry_cmd, 1);
827 aha1542_in(base_io, inquiry_result, 4);
828 WAIT(INTRFLAGS(base_io), INTRMASK, HACC, 0);
829 while (0) {
830 fail:
831 printk("aha1542_detect: query card type\n");
832 }
833 aha1542_intr_reset(base_io);
834
835 *transl = BIOS_TRANSLATION_6432;
836
837
838
839
840
841
842
843 if (inquiry_result[0] == 0x43) {
844 printk("aha1542.c: Emulation mode not supported for AHA 174N hardware.\n");
845 return 1;
846 };
847
848
849
850
851 *transl = aha1542_mbenable(base_io);
852
853 return 0;
854 }
855
856
857 void aha1542_setup( char *str, int *ints)
858 {
859 const char *ahausage = "aha1542: usage: aha1542=<PORTBASE>[,<BUSON>,<BUSOFF>[,<DMASPEED>]]\n";
860 static int setup_idx = 0;
861 int setup_portbase;
862
863 if(setup_idx >= MAXBOARDS)
864 {
865 printk("aha1542: aha1542_setup called too many times! Bad LILO params ?\n");
866 printk(" Entryline 1: %s\n",setup_str[0]);
867 printk(" Entryline 2: %s\n",setup_str[1]);
868 printk(" This line: %s\n",str);
869 return;
870 }
871 if (ints[0] < 1 || ints[0] > 4)
872 {
873 printk("aha1542: %s\n", str );
874 printk(ahausage);
875 printk("aha1542: Wrong parameters may cause system malfunction.. We try anyway..\n");
876 }
877
878 setup_called[setup_idx]=ints[0];
879 setup_str[setup_idx]=str;
880
881 setup_portbase = ints[0] >= 1 ? ints[1] : 0;
882 setup_buson [setup_idx] = ints[0] >= 2 ? ints[2] : 7;
883 setup_busoff [setup_idx] = ints[0] >= 3 ? ints[3] : 5;
884 if (ints[0] >= 4) {
885 int atbt = -1;
886 switch (ints[4]) {
887 case 5:
888 atbt = 0x00;
889 break;
890 case 6:
891 atbt = 0x04;
892 break;
893 case 7:
894 atbt = 0x01;
895 break;
896 case 8:
897 atbt = 0x02;
898 break;
899 case 10:
900 atbt = 0x03;
901 break;
902 default:
903 printk("aha1542: %s\n", str );
904 printk(ahausage);
905 printk("aha1542: Valid values for DMASPEED are 5-8, 10 MB/s. Using jumper defaults.\n");
906 break;
907 }
908 setup_dmaspeed[setup_idx] = atbt;
909 }
910
911 if (setup_portbase != 0)
912 bases[setup_idx] = setup_portbase;
913
914 ++setup_idx;
915 }
916
917
918 int aha1542_detect(Scsi_Host_Template * tpnt)
919 {
920 unsigned char dma_chan;
921 unsigned char irq_level;
922 unsigned char scsi_id;
923 unsigned long flags;
924 unsigned int base_io;
925 int trans;
926 struct Scsi_Host * shpnt = NULL;
927 int count = 0;
928 int indx;
929
930 DEB(printk("aha1542_detect: \n"));
931
932 for(indx = 0; indx < sizeof(bases)/sizeof(bases[0]); indx++)
933 if(bases[indx] != 0 && !check_region(bases[indx], 4)) {
934 shpnt = scsi_register(tpnt,
935 sizeof(struct aha1542_hostdata));
936
937
938
939 if ((unsigned int) shpnt > 0xffffff) {
940 printk("Invalid address for shpnt with 1542.\n");
941 goto unregister;
942 }
943
944 if(!aha1542_test_port(bases[indx], shpnt)) goto unregister;
945
946
947 base_io = bases[indx];
948
949
950 {
951 unchar oncmd[] = {CMD_BUSON_TIME, 7};
952 unchar offcmd[] = {CMD_BUSOFF_TIME, 5};
953
954 if(setup_called[indx])
955 {
956 oncmd[1] = setup_buson[indx];
957 offcmd[1] = setup_busoff[indx];
958 }
959
960 aha1542_intr_reset(base_io);
961 aha1542_out(base_io, oncmd, 2);
962 WAIT(INTRFLAGS(base_io), INTRMASK, HACC, 0);
963 aha1542_intr_reset(base_io);
964 aha1542_out(base_io, offcmd, 2);
965 WAIT(INTRFLAGS(base_io), INTRMASK, HACC, 0);
966 if (setup_dmaspeed[indx] >= 0)
967 {
968 unchar dmacmd[] = {CMD_DMASPEED, 0};
969 dmacmd[1] = setup_dmaspeed[indx];
970 aha1542_intr_reset(base_io);
971 aha1542_out(base_io, dmacmd, 2);
972 WAIT(INTRFLAGS(base_io), INTRMASK, HACC, 0);
973 }
974 while (0) {
975 fail:
976 printk("aha1542_detect: setting bus on/off-time failed\n");
977 }
978 aha1542_intr_reset(base_io);
979 }
980 if(aha1542_query(base_io, &trans)) goto unregister;
981
982 if (aha1542_getconfig(base_io, &irq_level, &dma_chan, &scsi_id) == -1) goto unregister;
983
984 printk("Configuring Adaptec (SCSI-ID %d) at IO:%x, IRQ %d", scsi_id, base_io, irq_level);
985 if (dma_chan != 0xFF)
986 printk(", DMA priority %d", dma_chan);
987 printk("\n");
988
989 DEB(aha1542_stat());
990 setup_mailboxes(base_io, shpnt);
991
992 DEB(aha1542_stat());
993
994 DEB(printk("aha1542_detect: enable interrupt channel %d\n", irq_level));
995 save_flags(flags);
996 cli();
997 if (request_irq(irq_level,aha1542_intr_handle, 0, "aha1542")) {
998 printk("Unable to allocate IRQ for adaptec controller.\n");
999 goto unregister;
1000 }
1001
1002 if (dma_chan != 0xFF) {
1003 if (request_dma(dma_chan,"aha1542")) {
1004 printk("Unable to allocate DMA channel for Adaptec.\n");
1005 free_irq(irq_level);
1006 goto unregister;
1007 }
1008
1009 if (dma_chan >= 5) {
1010 outb((dma_chan - 4) | CASCADE, DMA_MODE_REG);
1011 outb(dma_chan - 4, DMA_MASK_REG);
1012 }
1013 }
1014 aha_host[irq_level - 9] = shpnt;
1015 shpnt->io_port = base_io;
1016 shpnt->n_io_port = 4;
1017 shpnt->dma_channel = dma_chan;
1018 shpnt->irq = irq_level;
1019 HOSTDATA(shpnt)->bios_translation = trans;
1020 if(trans == 2)
1021 printk("aha1542.c: Using extended bios translation\n");
1022 HOSTDATA(shpnt)->aha1542_last_mbi_used = (2*AHA1542_MAILBOXES - 1);
1023 HOSTDATA(shpnt)->aha1542_last_mbo_used = (AHA1542_MAILBOXES - 1);
1024 memset(HOSTDATA(shpnt)->SCint, 0, sizeof(HOSTDATA(shpnt)->SCint));
1025 restore_flags(flags);
1026 #if 0
1027 DEB(printk(" *** READ CAPACITY ***\n"));
1028
1029 {
1030 unchar buf[8];
1031 static unchar cmd[] = { READ_CAPACITY, 0, 0, 0, 0, 0, 0, 0, 0, 0};
1032 int i;
1033
1034 for (i = 0; i < sizeof(buf); ++i) buf[i] = 0x87;
1035 for (i = 0; i < 2; ++i)
1036 if (!aha1542_command(i, cmd, buf, sizeof(buf))) {
1037 printk("aha_detect: LU %d sector_size %d device_size %d\n",
1038 i, xscsi2int(buf+4), xscsi2int(buf));
1039 }
1040 }
1041
1042 DEB(printk(" *** NOW RUNNING MY OWN TEST *** \n"));
1043
1044 for (i = 0; i < 4; ++i)
1045 {
1046 unsigned char cmd[10];
1047 static buffer[512];
1048
1049 cmd[0] = READ_10;
1050 cmd[1] = 0;
1051 xany2scsi(cmd+2, i);
1052 cmd[6] = 0;
1053 cmd[7] = 0;
1054 cmd[8] = 1;
1055 cmd[9] = 0;
1056 aha1542_command(0, cmd, buffer, 512);
1057 }
1058 #endif
1059 request_region(bases[indx], 4,"aha1542");
1060 count++;
1061 continue;
1062 unregister:
1063 scsi_unregister(shpnt);
1064 continue;
1065
1066 };
1067 return count;
1068 }
1069
1070 static int aha1542_restart(struct Scsi_Host * shost)
1071 {
1072 int i;
1073 int count = 0;
1074 #if 0
1075 unchar ahacmd = CMD_START_SCSI;
1076 #endif
1077
1078 for(i=0; i< AHA1542_MAILBOXES; i++)
1079 if(HOSTDATA(shost)->SCint[i] &&
1080 !(HOSTDATA(shost)->SCint[i]->device->soft_reset))
1081 {
1082 #if 0
1083 HOSTDATA(shost)->mb[i].status = 1;
1084 #endif
1085 count++;
1086 }
1087
1088 printk("Potential to restart %d stalled commands...\n", count);
1089 #if 0
1090
1091 if (count) aha1542_out(shost->io_port, &ahacmd, 1);
1092 #endif
1093 return 0;
1094 }
1095
1096
1097
1098
1099
1100 int aha1542_abort(Scsi_Cmnd * SCpnt)
1101 {
1102 #if 0
1103 unchar ahacmd = CMD_START_SCSI;
1104 unsigned long flags;
1105 struct mailbox * mb;
1106 int mbi, mbo, i;
1107
1108 printk("In aha1542_abort: %x %x\n",
1109 inb(STATUS(SCpnt->host->io_port)),
1110 inb(INTRFLAGS(SCpnt->host->io_port)));
1111
1112 save_flags(flags);
1113 cli();
1114 mb = HOSTDATA(SCpnt->host)->mb;
1115 mbi = HOSTDATA(SCpnt->host)->aha1542_last_mbi_used + 1;
1116 if (mbi >= 2*AHA1542_MAILBOXES) mbi = AHA1542_MAILBOXES;
1117
1118 do{
1119 if(mb[mbi].status != 0) break;
1120 mbi++;
1121 if (mbi >= 2*AHA1542_MAILBOXES) mbi = AHA1542_MAILBOXES;
1122 } while (mbi != HOSTDATA(SCpnt->host)->aha1542_last_mbi_used);
1123 restore_flags(flags);
1124
1125 if(mb[mbi].status) {
1126 printk("Lost interrupt discovered on irq %d - attempting to recover\n",
1127 SCpnt->host->irq);
1128 aha1542_intr_handle(SCpnt->host->irq, NULL);
1129 return 0;
1130 }
1131
1132
1133
1134
1135 for(i=0; i< AHA1542_MAILBOXES; i++)
1136 if(HOSTDATA(SCpnt->host)->SCint[i])
1137 {
1138 if(HOSTDATA(SCpnt->host)->SCint[i] == SCpnt) {
1139 printk("Timed out command pending for %4.4x\n", SCpnt->request.dev);
1140 if (HOSTDATA(SCpnt->host)->mb[i].status) {
1141 printk("OGMB still full - restarting\n");
1142 aha1542_out(SCpnt->host->io_port, &ahacmd, 1);
1143 };
1144 } else
1145 printk("Other pending command %4.4x\n", SCpnt->request.dev);
1146 }
1147
1148 #endif
1149
1150 DEB(printk("aha1542_abort\n"));
1151 #if 0
1152 save_flags(flags);
1153 cli();
1154 for(mbo = 0; mbo < AHA1542_MAILBOXES; mbo++)
1155 if (SCpnt == HOSTDATA(SCpnt->host)->SCint[mbo]){
1156 mb[mbo].status = 2;
1157 aha1542_out(SCpnt->host->io_port, &ahacmd, 1);
1158 restore_flags(flags);
1159 break;
1160 };
1161 #endif
1162 return SCSI_ABORT_SNOOZE;
1163 }
1164
1165
1166
1167
1168
1169
1170
1171 int aha1542_reset(Scsi_Cmnd * SCpnt)
1172 {
1173 unchar ahacmd = CMD_START_SCSI;
1174 int i;
1175
1176 DEB(printk("aha1542_reset called\n"));
1177 #if 0
1178
1179 outb(SCRST, CONTROL(SCpnt->host->io_port));
1180 #else
1181
1182
1183 for(i=0; i< AHA1542_MAILBOXES; i++)
1184 if(HOSTDATA(SCpnt->host)->SCint[i] == SCpnt)
1185 {
1186 HOSTDATA(SCpnt->host)->ccb[i].op = 0x81;
1187
1188 aha1542_out(SCpnt->host->io_port, &ahacmd, 1);
1189
1190
1191
1192
1193
1194 printk("Sent BUS DEVICE RESET to target %d\n", SCpnt->target);
1195
1196
1197
1198
1199 #if 1
1200 for(i=0; i< AHA1542_MAILBOXES; i++)
1201 if(HOSTDATA(SCpnt->host)->SCint[i] &&
1202 HOSTDATA(SCpnt->host)->SCint[i]->target == SCpnt->target)
1203 {
1204 Scsi_Cmnd * SCtmp;
1205 SCtmp = HOSTDATA(SCpnt->host)->SCint[i];
1206 SCtmp->result = DID_RESET << 16;
1207 if (SCtmp->host_scribble) scsi_free(SCtmp->host_scribble, 512);
1208 printk("Sending DID_RESET for target %d\n", SCpnt->target);
1209 SCtmp->scsi_done(SCpnt);
1210
1211 HOSTDATA(SCpnt->host)->SCint[i] = NULL;
1212 HOSTDATA(SCpnt->host)->mb[i].status = 0;
1213 }
1214 return SCSI_RESET_SUCCESS;
1215 #else
1216 return SCSI_RESET_PENDING;
1217 #endif
1218 }
1219
1220 #endif
1221
1222
1223
1224 return SCSI_RESET_PUNT;
1225 }
1226
1227 #include "sd.h"
1228
1229 int aha1542_biosparam(Scsi_Disk * disk, int dev, int * ip)
1230 {
1231 int translation_algorithm;
1232 int size = disk->capacity;
1233
1234 translation_algorithm = HOSTDATA(disk->device->host)->bios_translation;
1235
1236 if((size>>11) > 1024 && translation_algorithm == 2) {
1237
1238 ip[0] = 255;
1239 ip[1] = 63;
1240 ip[2] = size /255/63;
1241 } else {
1242 ip[0] = 64;
1243 ip[1] = 32;
1244 ip[2] = size >> 11;
1245 };
1246
1247 return 0;
1248 }
1249
1250
1251 #ifdef MODULE
1252
1253 Scsi_Host_Template driver_template = AHA1542;
1254
1255 #include "scsi_module.c"
1256 #endif
1257