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