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