This source file includes following definitions.
- aha1542_stat
- aha1542_out
- aha1542_in
- makecode
- aha1542_test_port
- aha1542_info
- aha1542_intr_handle
- aha1542_queuecommand
- internal_done
- aha1542_command
- setup_mailboxes
- aha1542_getconfig
- aha1542_mbenable
- aha1542_query
- aha1542_detect
- aha1542_abort
- aha1542_reset
- aha1542_biosparam
1
2
3
4
5
6
7
8
9
10
11
12
13
14 #include <linux/kernel.h>
15 #include <linux/head.h>
16 #include <linux/types.h>
17 #include <linux/string.h>
18 #include <linux/ioport.h>
19 #include <linux/config.h>
20
21 #include <linux/sched.h>
22 #include <asm/dma.h>
23
24 #include <asm/system.h>
25 #include <asm/io.h>
26 #include "../block/blk.h"
27 #include "scsi.h"
28 #include "hosts.h"
29
30 #include "aha1542.h"
31
32 #ifdef DEBUG
33 #define DEB(x) x
34 #else
35 #define DEB(x)
36 #endif
37
38
39
40
41
42
43
44
45
46 static unsigned int bases[]={0x330, 0x334};
47
48
49
50 #define DMA_MODE_REG 0xd6
51 #define DMA_MASK_REG 0xd4
52 #define CASCADE 0xc0
53
54 #define BIOS_TRANSLATION_1632 0
55 #define BIOS_TRANSLATION_6432 1
56 #define BIOS_TRANSLATION_25563 2
57
58 struct aha1542_hostdata{
59
60 int bios_translation;
61 int aha1542_last_mbi_used;
62 int aha1542_last_mbo_used;
63 Scsi_Cmnd * SCint[AHA1542_MAILBOXES];
64 struct mailbox mb[2*AHA1542_MAILBOXES];
65 struct ccb ccb[AHA1542_MAILBOXES];
66 };
67
68 #define HOSTDATA(host) ((struct aha1542_hostdata *) &host->hostdata)
69
70 static struct Scsi_Host * aha_host[7] = {NULL,};
71
72
73
74
75 #define WAITnexttimeout 3000000
76
77 static void setup_mailboxes(int base_io, struct Scsi_Host * shpnt);
78
79 #define aha1542_intr_reset(base) outb(IRST, CONTROL(base))
80
81 #define WAIT(port, mask, allof, noneof) \
82 { register WAITbits; \
83 register WAITtimeout = WAITnexttimeout; \
84 while (1) { \
85 WAITbits = inb(port) & (mask); \
86 if ((WAITbits & (allof)) == (allof) && ((WAITbits & (noneof)) == 0)) \
87 break; \
88 if (--WAITtimeout == 0) goto fail; \
89 } \
90 }
91
92 static void aha1542_stat(void)
93 {
94
95
96 }
97
98
99
100
101
102 static int aha1542_out(unsigned int base, unchar *cmdp, int len)
103 {
104 if(len == 1) {
105 while(1==1){
106 WAIT(STATUS(base), CDF, 0, CDF);
107 cli();
108 if(inb(STATUS(base)) & CDF) {sti(); continue;}
109 outb(*cmdp, DATA(base));
110 sti();
111 return 0;
112 }
113 } else {
114 cli();
115 while (len--)
116 {
117 WAIT(STATUS(base), CDF, 0, CDF);
118 outb(*cmdp++, DATA(base));
119 }
120 sti();
121 }
122 return 0;
123 fail:
124 sti();
125 printk("aha1542_out failed(%d): ", len+1); aha1542_stat();
126 return 1;
127 }
128
129
130
131 static int aha1542_in(unsigned int base, unchar *cmdp, int len)
132 {
133 cli();
134 while (len--)
135 {
136 WAIT(STATUS(base), DF, DF, 0);
137 *cmdp++ = inb(DATA(base));
138 }
139 sti();
140 return 0;
141 fail:
142 sti();
143 printk("aha1542_in failed(%d): ", len+1); aha1542_stat();
144 return 1;
145 }
146
147 static int makecode(unsigned hosterr, unsigned scsierr)
148 {
149 switch (hosterr) {
150 case 0x0:
151 case 0xa:
152 case 0xb:
153 hosterr = 0;
154 break;
155
156 case 0x11:
157
158 hosterr = DID_TIME_OUT;
159 break;
160
161 case 0x12:
162
163
164
165 case 0x13:
166
167 case 0x15:
168
169
170 case 0x16:
171
172
173 case 0x17:
174
175
176 case 0x18:
177
178
179 case 0x19:
180
181
182
183 case 0x1a:
184
185
186 DEB(printk("Aha1542: %x %x\n", hosterr, scsierr));
187 hosterr = DID_ERROR;
188 break;
189
190 case 0x14:
191
192
193
194 hosterr = DID_RESET;
195 break;
196 default:
197 printk("makecode: unknown hoststatus %x\n", hosterr);
198 break;
199 }
200 return scsierr|(hosterr << 16);
201 }
202
203 static int aha1542_test_port(int bse, struct Scsi_Host * shpnt)
204 {
205 int i;
206 unchar inquiry_cmd[] = {CMD_INQUIRY };
207 unchar inquiry_result[4];
208 unchar *cmdp;
209 int len;
210 volatile int debug = 0;
211
212
213 if(inb(STATUS(bse)) == 0xff) return 0;
214
215
216
217
218
219 outb(SRST|IRST, CONTROL(bse));
220
221 i = jiffies + 2;
222 while (i>jiffies);
223
224 debug = 1;
225
226 WAIT(STATUS(bse), STATMASK, INIT|IDLE, STST|DIAGF|INVDCMD|DF|CDF);
227
228 debug = 2;
229
230 if (inb(INTRFLAGS(bse))&INTRMASK) goto fail;
231
232
233
234
235
236 aha1542_out(bse, inquiry_cmd, 1);
237
238 debug = 3;
239 len = 4;
240 cmdp = &inquiry_result[0];
241
242 while (len--)
243 {
244 WAIT(STATUS(bse), DF, DF, 0);
245 *cmdp++ = inb(DATA(bse));
246 }
247
248 debug = 8;
249
250 if (inb(STATUS(bse)) & DF) goto fail;
251
252 debug = 9;
253
254 WAIT(INTRFLAGS(bse), HACC, HACC, 0);
255
256
257 debug = 10;
258
259 outb(IRST, CONTROL(bse));
260
261 debug = 11;
262
263 return debug;
264 fail:
265 return 0;
266 }
267
268 static const char aha_ident[] = "Adaptec 1542";
269
270
271 const char *aha1542_info(void)
272 {
273 return aha_ident;
274 }
275
276
277 static void aha1542_intr_handle(int foo)
278 {
279 void (*my_done)(Scsi_Cmnd *) = NULL;
280 int errstatus, mbi, mbo, mbistatus;
281 int number_serviced;
282 struct Scsi_Host * shost;
283 Scsi_Cmnd * SCtmp;
284 int irqno, * irqp;
285 struct mailbox * mb;
286 struct ccb *ccb;
287
288 irqp = (int *) foo;
289 irqp -= 2;
290 irqno = *irqp;
291
292 shost = aha_host[irqno - 9];
293 mb = HOSTDATA(shost)->mb;
294 ccb = HOSTDATA(shost)->ccb;
295
296 if(!shost) panic("Splunge!");
297
298 #ifdef DEBUG
299 {
300 int flag = inb(INTRFLAGS(shost->io_port));
301 printk("aha1542_intr_handle: ");
302 if (!(flag&ANYINTR)) printk("no interrupt?");
303 if (flag&MBIF) printk("MBIF ");
304 if (flag&MBOA) printk("MBOF ");
305 if (flag&HACC) printk("HACC ");
306 if (flag&SCRD) printk("SCRD ");
307 printk("status %02x\n", inb(STATUS(shost->io_port)));
308 };
309 #endif
310 number_serviced = 0;
311
312 while(1==1){
313 aha1542_intr_reset(shost->io_port);
314
315 cli();
316 mbi = HOSTDATA(shost)->aha1542_last_mbi_used + 1;
317 if (mbi >= 2*AHA1542_MAILBOXES) mbi = AHA1542_MAILBOXES;
318
319 do{
320 if(mb[mbi].status != 0) break;
321 mbi++;
322 if (mbi >= 2*AHA1542_MAILBOXES) mbi = AHA1542_MAILBOXES;
323 } while (mbi != HOSTDATA(shost)->aha1542_last_mbi_used);
324
325 if(mb[mbi].status == 0){
326 sti();
327
328 if (number_serviced) return;
329 printk("aha1542.c: interrupt received, but no mail.\n");
330 return;
331 };
332
333 mbo = (scsi2int(mb[mbi].ccbptr) - ((unsigned int) &ccb[0])) / sizeof(struct ccb);
334 mbistatus = mb[mbi].status;
335 mb[mbi].status = 0;
336 HOSTDATA(shost)->aha1542_last_mbi_used = mbi;
337 sti();
338
339 #ifdef DEBUG
340 {
341 if (ccb[mbo].tarstat|ccb[mbo].hastat)
342 printk("aha1542_command: returning %x (status %d)\n",
343 ccb[mbo].tarstat + ((int) ccb[mbo].hastat << 16), mb[mbi].status);
344 };
345 #endif
346
347 if(mbistatus == 3) continue;
348
349 #ifdef DEBUG
350 printk("...done %d %d\n",mbo, mbi);
351 #endif
352
353 SCtmp = HOSTDATA(shost)->SCint[mbo];
354
355 if (!SCtmp || !SCtmp->scsi_done) {
356 printk("aha1542_intr_handle: Unexpected interrupt\n");
357 return;
358 }
359
360 my_done = SCtmp->scsi_done;
361 if (SCtmp->host_scribble) scsi_free(SCtmp->host_scribble, 512);
362
363
364
365
366 if (ccb[mbo].tarstat == 2)
367 memcpy(SCtmp->sense_buffer, &ccb[mbo].cdb[ccb[mbo].cdblen],
368 sizeof(SCtmp->sense_buffer));
369
370
371
372
373
374 if (mbistatus != 1)
375
376 errstatus = makecode(ccb[mbo].hastat, ccb[mbo].tarstat);
377 else
378 errstatus = 0;
379
380 #ifdef DEBUG
381 if(errstatus) printk("(aha1542 error:%x %x %x) ",errstatus,
382 ccb[mbo].hastat, ccb[mbo].tarstat);
383 #endif
384
385 if (ccb[mbo].tarstat == 2) {
386 #ifdef DEBUG
387 int i;
388 #endif
389 DEB(printk("aha1542_intr_handle: sense:"));
390 #ifdef DEBUG
391 for (i = 0; i < 12; i++)
392 printk("%02x ", ccb[mbo].cdb[ccb[mbo].cdblen+i]);
393 printk("\n");
394 #endif
395
396
397
398
399
400
401 }
402 DEB(if (errstatus) printk("aha1542_intr_handle: returning %6x\n", errstatus));
403 SCtmp->result = errstatus;
404 HOSTDATA(shost)->SCint[mbo] = NULL;
405
406 my_done(SCtmp);
407 number_serviced++;
408 };
409 }
410
411 int aha1542_queuecommand(Scsi_Cmnd * SCpnt, void (*done)(Scsi_Cmnd *))
412 {
413 unchar ahacmd = CMD_START_SCSI;
414 unchar direction;
415 unchar *cmd = (unchar *) SCpnt->cmnd;
416 unchar target = SCpnt->target;
417 unchar lun = SCpnt->lun;
418 void *buff = SCpnt->request_buffer;
419 int bufflen = SCpnt->request_bufflen;
420 int mbo;
421 struct mailbox * mb;
422 struct ccb *ccb;
423
424 DEB(int i);
425
426 mb = HOSTDATA(SCpnt->host)->mb;
427 ccb = HOSTDATA(SCpnt->host)->ccb;
428
429 DEB(if (target > 1) {
430 SCpnt->result = DID_TIME_OUT << 16;
431 done(SCpnt); return 0;});
432
433 if(*cmd == REQUEST_SENSE){
434 #ifndef DEBUG
435 if (bufflen != sizeof(SCpnt->sense_buffer)) {
436 printk("Wrong buffer length supplied for request sense (%d)\n",bufflen);
437 panic("aha1542.c");
438 };
439 #endif
440 SCpnt->result = 0;
441 done(SCpnt);
442 return 0;
443 };
444
445 #ifdef DEBUG
446 if (*cmd == READ_10 || *cmd == WRITE_10)
447 i = xscsi2int(cmd+2);
448 else if (*cmd == READ_6 || *cmd == WRITE_6)
449 i = scsi2int(cmd+2);
450 else
451 i = -1;
452 if (done)
453 printk("aha1542_queuecommand: dev %d cmd %02x pos %d len %d ", target, *cmd, i, bufflen);
454 else
455 printk("aha1542_command: dev %d cmd %02x pos %d len %d ", target, *cmd, i, bufflen);
456 aha1542_stat();
457 printk("aha1542_queuecommand: dumping scsi cmd:");
458 for (i = 0; i < (COMMAND_SIZE(*cmd)); i++) printk("%02x ", cmd[i]);
459 printk("\n");
460 if (*cmd == WRITE_10 || *cmd == WRITE_6)
461 return 0;
462 #endif
463
464
465
466 cli();
467 mbo = HOSTDATA(SCpnt->host)->aha1542_last_mbo_used + 1;
468 if (mbo >= AHA1542_MAILBOXES) mbo = 0;
469
470 do{
471 if(mb[mbo].status == 0 && HOSTDATA(SCpnt->host)->SCint[mbo] == NULL)
472 break;
473 mbo++;
474 if (mbo >= AHA1542_MAILBOXES) mbo = 0;
475 } while (mbo != HOSTDATA(SCpnt->host)->aha1542_last_mbo_used);
476
477 if(mb[mbo].status || HOSTDATA(SCpnt->host)->SCint[mbo])
478 panic("Unable to find empty mailbox for aha1542.\n");
479
480 HOSTDATA(SCpnt->host)->SCint[mbo] = SCpnt;
481
482
483 HOSTDATA(SCpnt->host)->aha1542_last_mbo_used = mbo;
484 sti();
485
486 #ifdef DEBUG
487 printk("Sending command (%d %x)...",mbo, done);
488 #endif
489
490 any2scsi(mb[mbo].ccbptr, &ccb[mbo]);
491
492 memset(&ccb[mbo], 0, sizeof(struct ccb));
493
494 ccb[mbo].cdblen = COMMAND_SIZE(*cmd);
495
496 direction = 0;
497 if (*cmd == READ_10 || *cmd == READ_6)
498 direction = 8;
499 else if (*cmd == WRITE_10 || *cmd == WRITE_6)
500 direction = 16;
501
502 memcpy(ccb[mbo].cdb, cmd, ccb[mbo].cdblen);
503
504 if (SCpnt->use_sg) {
505 struct scatterlist * sgpnt;
506 struct chain * cptr;
507 #ifdef DEBUG
508 unsigned char * ptr;
509 #endif
510 int i;
511 ccb[mbo].op = 2;
512 SCpnt->host_scribble = (unsigned char *) scsi_malloc(512);
513 sgpnt = (struct scatterlist *) SCpnt->request_buffer;
514 cptr = (struct chain *) SCpnt->host_scribble;
515 if (cptr == NULL) panic("aha1542.c: unable to allocate DMA memory\n");
516 for(i=0; i<SCpnt->use_sg; i++) {
517 if(sgpnt[i].length == 0 || SCpnt->use_sg > 16 ||
518 (((int)sgpnt[i].address) & 1) || (sgpnt[i].length & 1)){
519 unsigned char * ptr;
520 printk("Bad segment list supplied to aha1542.c (%d, %d)\n",SCpnt->use_sg,i);
521 for(i=0;i<SCpnt->use_sg;i++){
522 printk("%d: %x %x %d\n",i,(unsigned int) sgpnt[i].address, (unsigned int) sgpnt[i].alt_address,
523 sgpnt[i].length);
524 };
525 printk("cptr %x: ",(unsigned int) cptr);
526 ptr = (unsigned char *) &cptr[i];
527 for(i=0;i<18;i++) printk("%02x ", ptr[i]);
528 panic("Foooooooood fight!");
529 };
530 any2scsi(cptr[i].dataptr, sgpnt[i].address);
531 if(((unsigned int) sgpnt[i].address) & 0xff000000) goto baddma;
532 any2scsi(cptr[i].datalen, sgpnt[i].length);
533 };
534 any2scsi(ccb[mbo].datalen, SCpnt->use_sg * sizeof(struct chain));
535 if(((unsigned int) buff & 0xff000000)) goto baddma;
536 any2scsi(ccb[mbo].dataptr, cptr);
537 #ifdef DEBUG
538 printk("cptr %x: ",cptr);
539 ptr = (unsigned char *) cptr;
540 for(i=0;i<18;i++) printk("%02x ", ptr[i]);
541 #endif
542 } else {
543 ccb[mbo].op = 0;
544 SCpnt->host_scribble = NULL;
545 any2scsi(ccb[mbo].datalen, bufflen);
546 any2scsi(ccb[mbo].dataptr, buff);
547 };
548 ccb[mbo].idlun = (target&7)<<5 | direction | (lun & 7);
549 ccb[mbo].rsalen = 12;
550 ccb[mbo].linkptr[0] = ccb[mbo].linkptr[1] = ccb[mbo].linkptr[2] = 0;
551 ccb[mbo].commlinkid = 0;
552
553 #ifdef DEBUGd
554 { int i;
555 printk("aha1542_command: sending.. ");
556 for (i = 0; i < sizeof(ccb[mbo])-10; i++)
557 printk("%02x ", ((unchar *)&ccb[mbo])[i]);
558 };
559 #endif
560
561 if (done) {
562 DEB(printk("aha1542_queuecommand: now waiting for interrupt "); aha1542_stat());
563 SCpnt->scsi_done = done;
564 mb[mbo].status = 1;
565 aha1542_out(SCpnt->host->io_port, &ahacmd, 1);
566 DEB(aha1542_stat());
567 }
568 else
569 printk("aha1542_queuecommand: done can't be NULL\n");
570
571 return 0;
572 baddma:
573 panic("Buffer at address > 16Mb used for 1542B");
574 }
575
576 static void internal_done(Scsi_Cmnd * SCpnt)
577 {
578 SCpnt->SCp.Status++;
579 }
580
581 int aha1542_command(Scsi_Cmnd * SCpnt)
582 {
583 DEB(printk("aha1542_command: ..calling aha1542_queuecommand\n"));
584
585 aha1542_queuecommand(SCpnt, internal_done);
586
587 SCpnt->SCp.Status = 0;
588 while (!SCpnt->SCp.Status);
589 return SCpnt->result;
590 }
591
592
593 static void setup_mailboxes(int bse, struct Scsi_Host * shpnt)
594 {
595 int i;
596 struct mailbox * mb;
597 struct ccb *ccb;
598
599 unchar cmd[5] = {CMD_MBINIT, AHA1542_MAILBOXES, 0, 0, 0};
600
601 mb = HOSTDATA(shpnt)->mb;
602 ccb = HOSTDATA(shpnt)->ccb;
603
604 for(i=0; i<AHA1542_MAILBOXES; i++){
605 mb[i].status = mb[AHA1542_MAILBOXES+i].status = 0;
606 any2scsi(mb[i].ccbptr, &ccb[i]);
607 };
608 aha1542_intr_reset(bse);
609 any2scsi((cmd+2), mb);
610 aha1542_out(bse, cmd, 5);
611 WAIT(INTRFLAGS(bse), INTRMASK, HACC, 0);
612 while (0) {
613 fail:
614 printk("aha1542_detect: failed setting up mailboxes\n");
615 }
616 aha1542_intr_reset(bse);
617 }
618
619 static int aha1542_getconfig(int base_io, unsigned char * irq_level, unsigned char * dma_chan)
620 {
621 unchar inquiry_cmd[] = {CMD_RETCONF };
622 unchar inquiry_result[3];
623 int i;
624 i = inb(STATUS(base_io));
625 if (i & DF) {
626 i = inb(DATA(base_io));
627 };
628 aha1542_out(base_io, inquiry_cmd, 1);
629 aha1542_in(base_io, inquiry_result, 3);
630 WAIT(INTRFLAGS(base_io), INTRMASK, HACC, 0);
631 while (0) {
632 fail:
633 printk("aha1542_detect: query board settings\n");
634 }
635 aha1542_intr_reset(base_io);
636 switch(inquiry_result[0]){
637 case 0x80:
638 *dma_chan = 7;
639 break;
640 case 0x40:
641 *dma_chan = 6;
642 break;
643 case 0x20:
644 *dma_chan = 5;
645 break;
646 case 0x01:
647 printk("DMA priority 0 not available for Adaptec driver\n");
648 return -1;
649 case 0:
650
651
652 *dma_chan = 0xFF;
653 break;
654 default:
655 printk("Unable to determine Adaptec DMA priority. Disabling board\n");
656 return -1;
657 };
658 switch(inquiry_result[1]){
659 case 0x40:
660 *irq_level = 15;
661 break;
662 case 0x20:
663 *irq_level = 14;
664 break;
665 case 0x8:
666 *irq_level = 12;
667 break;
668 case 0x4:
669 *irq_level = 11;
670 break;
671 case 0x2:
672 *irq_level = 10;
673 break;
674 case 0x1:
675 *irq_level = 9;
676 break;
677 default:
678 printk("Unable to determine Adaptec IRQ level. Disabling board\n");
679 return -1;
680 };
681 return 0;
682 }
683
684
685
686
687 static int aha1542_mbenable(int base)
688 {
689 static unchar mbenable_cmd[3];
690 static unchar mbenable_result[2];
691 int retval;
692
693 retval = BIOS_TRANSLATION_6432;
694
695 mbenable_cmd[0]=CMD_EXTBIOS;
696 aha1542_out(base,mbenable_cmd,1);
697 aha1542_in(base,mbenable_result,2);
698 WAIT(INTRFLAGS(base),INTRMASK,HACC,0);
699 aha1542_intr_reset(base);
700
701 if ((mbenable_result[0] & 0x08) || mbenable_result[1]) {
702 mbenable_cmd[0]=CMD_MBENABLE;
703 mbenable_cmd[1]=0;
704 mbenable_cmd[2]=mbenable_result[1];
705 if(mbenable_result[1] & 1) retval = BIOS_TRANSLATION_25563;
706 aha1542_out(base,mbenable_cmd,3);
707 WAIT(INTRFLAGS(base),INTRMASK,HACC,0);
708 };
709 while(0) {
710 fail:
711 printk("aha1542_mbenable: Mailbox init failed\n");
712 }
713 aha1542_intr_reset(base);
714 return retval;
715 }
716
717
718 static int aha1542_query(int base_io, int * transl)
719 {
720 unchar inquiry_cmd[] = {CMD_INQUIRY };
721 unchar inquiry_result[4];
722 int i;
723 i = inb(STATUS(base_io));
724 if (i & DF) {
725 i = inb(DATA(base_io));
726 };
727 aha1542_out(base_io, inquiry_cmd, 1);
728 aha1542_in(base_io, inquiry_result, 4);
729 WAIT(INTRFLAGS(base_io), INTRMASK, HACC, 0);
730 while (0) {
731 fail:
732 printk("aha1542_detect: query card type\n");
733 }
734 aha1542_intr_reset(base_io);
735
736 *transl = BIOS_TRANSLATION_6432;
737
738
739
740
741
742
743
744 if (inquiry_result[0] == 0x43) {
745 printk("aha1542.c: Emulation mode not supported for AHA 174N hardware.\n");
746 return 1;
747 };
748
749
750 if (inquiry_result[0] == 0x44 || inquiry_result[0] == 0x45)
751 {
752 *transl = aha1542_mbenable(base_io);
753 };
754 return 0;
755 }
756
757
758
759 int aha1542_detect(int hostnum)
760 {
761 unsigned char dma_chan;
762 unsigned char irq_level;
763 unsigned int base_io;
764 int trans;
765 struct Scsi_Host * shpnt = NULL;
766 int count = 0;
767 int indx;
768
769 DEB(printk("aha1542_detect: \n"));
770
771 for(indx = 0; indx < sizeof(bases)/sizeof(bases[0]); indx++)
772 if(!check_region(bases[indx], 4)) {
773 shpnt = scsi_register(hostnum,
774 sizeof(struct aha1542_hostdata));
775
776 if(!aha1542_test_port(bases[indx], shpnt)) goto unregister;
777
778
779 base_io = bases[indx];
780
781
782 {
783 unchar oncmd[] = {CMD_BUSON_TIME, 7};
784 unchar offcmd[] = {CMD_BUSOFF_TIME, 5};
785
786 aha1542_intr_reset(base_io);
787 aha1542_out(base_io, oncmd, 2);
788 WAIT(INTRFLAGS(base_io), INTRMASK, HACC, 0);
789 aha1542_intr_reset(base_io);
790 aha1542_out(base_io, offcmd, 2);
791 WAIT(INTRFLAGS(base_io), INTRMASK, HACC, 0);
792 while (0) {
793 fail:
794 printk("aha1542_detect: setting bus on/off-time failed\n");
795 }
796 aha1542_intr_reset(base_io);
797 }
798 if(aha1542_query(base_io, &trans)) goto unregister;
799
800 if (aha1542_getconfig(base_io, &irq_level, &dma_chan) == -1) goto unregister;
801
802 printk("Configuring Adaptec at IO:%x, IRQ %d",base_io, irq_level);
803 if (dma_chan != 0xFF)
804 printk(", DMA priority %d", dma_chan);
805 printk("\n");
806
807 DEB(aha1542_stat());
808 setup_mailboxes(base_io, shpnt);
809
810 DEB(aha1542_stat());
811
812 DEB(printk("aha1542_detect: enable interrupt channel %d\n", irq_level));
813 cli();
814 if (request_irq(irq_level,aha1542_intr_handle)) {
815 printk("Unable to allocate IRQ for adaptec controller.\n");
816 goto unregister;
817 }
818
819 if (dma_chan != 0xFF) {
820 if (request_dma(dma_chan)) {
821 printk("Unable to allocate DMA channel for Adaptec.\n");
822 free_irq(irq_level);
823 goto unregister;
824 }
825
826 if (dma_chan >= 5) {
827 outb((dma_chan - 4) | CASCADE, DMA_MODE_REG);
828 outb(dma_chan - 4, DMA_MASK_REG);
829 }
830 }
831 aha_host[irq_level - 9] = shpnt;
832 shpnt->io_port = base_io;
833 shpnt->dma_channel = dma_chan;
834 shpnt->irq = irq_level;
835 HOSTDATA(shpnt)->bios_translation = trans;
836 if(trans == 2)
837 printk("aha1542.c: Using extended bios translation\n");
838 HOSTDATA(shpnt)->aha1542_last_mbi_used = (2*AHA1542_MAILBOXES - 1);
839 HOSTDATA(shpnt)->aha1542_last_mbo_used = (AHA1542_MAILBOXES - 1);
840 memset(HOSTDATA(shpnt)->SCint, 0, sizeof(HOSTDATA(shpnt)->SCint));
841 sti();
842 #if 0
843 DEB(printk(" *** READ CAPACITY ***\n"));
844
845 {
846 unchar buf[8];
847 static unchar cmd[] = { READ_CAPACITY, 0, 0, 0, 0, 0, 0, 0, 0, 0};
848 int i;
849
850 for (i = 0; i < sizeof(buf); ++i) buf[i] = 0x87;
851 for (i = 0; i < 2; ++i)
852 if (!aha1542_command(i, cmd, buf, sizeof(buf))) {
853 printk("aha_detect: LU %d sector_size %d device_size %d\n",
854 i, xscsi2int(buf+4), xscsi2int(buf));
855 }
856 }
857
858 DEB(printk(" *** NOW RUNNING MY OWN TEST *** \n"));
859
860 for (i = 0; i < 4; ++i)
861 {
862 unsigned char cmd[10];
863 static buffer[512];
864
865 cmd[0] = READ_10;
866 cmd[1] = 0;
867 xany2scsi(cmd+2, i);
868 cmd[6] = 0;
869 cmd[7] = 0;
870 cmd[8] = 1;
871 cmd[9] = 0;
872 aha1542_command(0, cmd, buffer, 512);
873 }
874 #endif
875 snarf_region(bases[indx], 4);
876 count++;
877 continue;
878 unregister:
879 scsi_unregister(shpnt, sizeof(struct aha1542_hostdata));
880 continue;
881
882 };
883 return count;
884 }
885
886
887
888
889
890 int aha1542_abort(Scsi_Cmnd * SCpnt, int i)
891 {
892 #if 0
893 unchar ahacmd = CMD_START_SCSI;
894 int mbo;
895 #endif
896 DEB(printk("aha1542_abort\n"));
897 #if 0
898 cli();
899 for(mbo = 0; mbo < AHA1542_MAILBOXES; mbo++)
900 if (SCpnt == HOSTDATA(SCpnt->host)->SCint[mbo]){
901 mb[mbo].status = 2;
902 aha1542_out(&ahacmd, 1);
903 sti();
904 break;
905 };
906 #endif
907 return 0;
908 }
909
910
911
912
913
914 int aha1542_reset(Scsi_Cmnd * SCpnt)
915 {
916 DEB(printk("aha1542_reset called\n"));
917 if(SCpnt) SCpnt->flags |= NEEDS_JUMPSTART;
918 return 0;
919 }
920
921 #ifdef CONFIG_BLK_DEV_SD
922 #include "sd.h"
923 #endif
924
925 int aha1542_biosparam(int size, int dev, int * ip)
926 {
927 int translation_algorithm;
928 #ifdef CONFIG_BLK_DEV_SD
929 Scsi_Device *disk;
930
931 disk = rscsi_disks[MINOR(dev) >> 4].device;
932 translation_algorithm = HOSTDATA(disk->host)->bios_translation;
933
934 if((size>>11) > 1024 && translation_algorithm == 2) {
935
936 ip[0] = 255;
937 ip[1] = 63;
938 ip[2] = size /255/63;
939 } else {
940 ip[0] = 64;
941 ip[1] = 32;
942 ip[2] = size >> 11;
943 };
944
945 #endif
946 return 0;
947 }