1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28#include <linux/config.h>
29#include <linux/module.h>
30
31#include <linux/kernel.h>
32#include <linux/types.h>
33#include <linux/string.h>
34#include <linux/ioport.h>
35#include <linux/delay.h>
36#include <linux/sched.h>
37#include <linux/proc_fs.h>
38#include <linux/init.h>
39#include <linux/spinlock.h>
40#include <linux/pci.h>
41#include <linux/isapnp.h>
42#include <asm/dma.h>
43#include <asm/system.h>
44#include <asm/io.h>
45#include <linux/blk.h>
46#include <linux/mca.h>
47
48#include "scsi.h"
49#include "hosts.h"
50
51
52#include "aha1542.h"
53
54#define SCSI_PA(address) virt_to_bus(address)
55
56static void BAD_DMA(void *address, unsigned int length)
57{
58 printk(KERN_CRIT "buf vaddress %p paddress 0x%lx length %d\n",
59 address,
60 SCSI_PA(address),
61 length);
62 panic("Buffer at physical address > 16Mb used for aha1542");
63}
64
65static void BAD_SG_DMA(Scsi_Cmnd * SCpnt,
66 struct scatterlist *sgpnt,
67 int nseg,
68 int badseg)
69{
70 printk(KERN_CRIT "sgpnt[%d:%d] addr %p/0x%lx length %d\n",
71 badseg, nseg,
72 sgpnt[badseg].address,
73 SCSI_PA(sgpnt[badseg].address),
74 sgpnt[badseg].length);
75
76
77
78
79 panic("Buffer at physical address > 16Mb used for aha1542");
80}
81
82#include<linux/stat.h>
83
84#ifdef DEBUG
85#define DEB(x) x
86#else
87#define DEB(x)
88#endif
89
90
91
92
93
94
95
96
97
98
99#define MAXBOARDS 4
100
101
102
103
104static unsigned int bases[MAXBOARDS] __initdata = {0x330, 0x334, 0, 0};
105
106
107
108
109static int setup_called[MAXBOARDS];
110static int setup_buson[MAXBOARDS];
111static int setup_busoff[MAXBOARDS];
112static int setup_dmaspeed[MAXBOARDS] __initdata = { -1, -1, -1, -1 };
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131#if defined(MODULE)
132int isapnp = 0;
133int aha1542[] = {0x330, 11, 4, -1};
134MODULE_PARM(aha1542, "1-4i");
135MODULE_PARM(isapnp, "i");
136
137static struct isapnp_device_id id_table[] __initdata = {
138 {
139 ISAPNP_ANY_ID, ISAPNP_ANY_ID,
140 ISAPNP_VENDOR('A', 'D', 'P'), ISAPNP_FUNCTION(0x1542),
141 0
142 },
143 {0}
144};
145
146MODULE_DEVICE_TABLE(isapnp, id_table);
147
148#else
149static int isapnp = 1;
150#endif
151
152#define BIOS_TRANSLATION_1632 0
153#define BIOS_TRANSLATION_6432 1
154#define BIOS_TRANSLATION_25563 2
155
156struct aha1542_hostdata {
157
158 int bios_translation;
159 int aha1542_last_mbi_used;
160 int aha1542_last_mbo_used;
161 Scsi_Cmnd *SCint[AHA1542_MAILBOXES];
162 struct mailbox mb[2 * AHA1542_MAILBOXES];
163 struct ccb ccb[AHA1542_MAILBOXES];
164};
165
166#define HOSTDATA(host) ((struct aha1542_hostdata *) &host->hostdata)
167
168static struct Scsi_Host *aha_host[7];
169
170
171
172
173#define WAITnexttimeout 3000000
174
175static void setup_mailboxes(int base_io, struct Scsi_Host *shpnt);
176static int aha1542_restart(struct Scsi_Host *shost);
177static void aha1542_intr_handle(int irq, void *dev_id, struct pt_regs *regs);
178static void do_aha1542_intr_handle(int irq, void *dev_id, struct pt_regs *regs);
179
180#define aha1542_intr_reset(base) outb(IRST, CONTROL(base))
181
182#define WAIT(port, mask, allof, noneof) \
183 { register int WAITbits; \
184 register int WAITtimeout = WAITnexttimeout; \
185 while (1) { \
186 WAITbits = inb(port) & (mask); \
187 if ((WAITbits & (allof)) == (allof) && ((WAITbits & (noneof)) == 0)) \
188 break; \
189 if (--WAITtimeout == 0) goto fail; \
190 } \
191 }
192
193
194
195#define WAITd(port, mask, allof, noneof, timeout) \
196 { register int WAITbits; \
197 register int WAITtimeout = timeout; \
198 while (1) { \
199 WAITbits = inb(port) & (mask); \
200 if ((WAITbits & (allof)) == (allof) && ((WAITbits & (noneof)) == 0)) \
201 break; \
202 mdelay(1); \
203 if (--WAITtimeout == 0) goto fail; \
204 } \
205 }
206
207static void aha1542_stat(void)
208{
209
210
211}
212
213
214
215
216
217static int aha1542_out(unsigned int base, unchar * cmdp, int len)
218{
219 unsigned long flags = 0;
220
221 save_flags(flags);
222 if (len == 1) {
223 while (1 == 1) {
224 WAIT(STATUS(base), CDF, 0, CDF);
225 cli();
226 if (inb(STATUS(base)) & CDF) {
227 restore_flags(flags);
228 continue;
229 }
230 outb(*cmdp, DATA(base));
231 restore_flags(flags);
232 return 0;
233 }
234 } else {
235 cli();
236 while (len--) {
237 WAIT(STATUS(base), CDF, 0, CDF);
238 outb(*cmdp++, DATA(base));
239 }
240 restore_flags(flags);
241 }
242 return 0;
243fail:
244 restore_flags(flags);
245 printk(KERN_ERR "aha1542_out failed(%d): ", len + 1);
246 aha1542_stat();
247 return 1;
248}
249
250
251
252
253static int __init aha1542_in(unsigned int base, unchar * cmdp, int len)
254{
255 unsigned long flags;
256
257 save_flags(flags);
258 cli();
259 while (len--) {
260 WAIT(STATUS(base), DF, DF, 0);
261 *cmdp++ = inb(DATA(base));
262 }
263 restore_flags(flags);
264 return 0;
265fail:
266 restore_flags(flags);
267 printk(KERN_ERR "aha1542_in failed(%d): ", len + 1);
268 aha1542_stat();
269 return 1;
270}
271
272
273
274
275static int __init aha1542_in1(unsigned int base, unchar * cmdp, int len)
276{
277 unsigned long flags;
278
279 save_flags(flags);
280 cli();
281 while (len--) {
282 WAITd(STATUS(base), DF, DF, 0, 100);
283 *cmdp++ = inb(DATA(base));
284 }
285 restore_flags(flags);
286 return 0;
287fail:
288 restore_flags(flags);
289 return 1;
290}
291
292static int makecode(unsigned hosterr, unsigned scsierr)
293{
294 switch (hosterr) {
295 case 0x0:
296 case 0xa:
297 case 0xb:
298 hosterr = 0;
299 break;
300
301 case 0x11:
302
303 hosterr = DID_TIME_OUT;
304 break;
305
306 case 0x12:
307
308
309
310 case 0x13:
311
312 case 0x15:
313
314
315 case 0x16:
316
317
318 case 0x17:
319
320
321 case 0x18:
322
323
324 case 0x19:
325
326
327
328 case 0x1a:
329
330
331 DEB(printk("Aha1542: %x %x\n", hosterr, scsierr));
332 hosterr = DID_ERROR;
333 break;
334
335 case 0x14:
336
337
338
339 hosterr = DID_RESET;
340 break;
341 default:
342 printk(KERN_ERR "aha1542: makecode: unknown hoststatus %x\n", hosterr);
343 break;
344 }
345 return scsierr | (hosterr << 16);
346}
347
348static int __init aha1542_test_port(int bse, struct Scsi_Host *shpnt)
349{
350 unchar inquiry_cmd[] = {CMD_INQUIRY};
351 unchar inquiry_result[4];
352 unchar *cmdp;
353 int len;
354 volatile int debug = 0;
355
356
357 if (inb(STATUS(bse)) == 0xff)
358 return 0;
359
360
361
362
363
364
365 aha1542_intr_reset(bse);
366
367 outb(SRST | IRST , CONTROL(bse));
368
369 mdelay(20);
370
371 debug = 1;
372
373 WAIT(STATUS(bse), STATMASK, INIT | IDLE, STST | DIAGF | INVDCMD | DF | CDF);
374
375 debug = 2;
376
377 if (inb(INTRFLAGS(bse)) & INTRMASK)
378 goto fail;
379
380
381
382
383
384 aha1542_out(bse, inquiry_cmd, 1);
385
386 debug = 3;
387 len = 4;
388 cmdp = &inquiry_result[0];
389
390 while (len--) {
391 WAIT(STATUS(bse), DF, DF, 0);
392 *cmdp++ = inb(DATA(bse));
393 }
394
395 debug = 8;
396
397 if (inb(STATUS(bse)) & DF)
398 goto fail;
399
400 debug = 9;
401
402 WAIT(INTRFLAGS(bse), HACC, HACC, 0);
403
404
405 debug = 10;
406
407 outb(IRST, CONTROL(bse));
408
409 debug = 11;
410
411 return debug;
412fail:
413 return 0;
414}
415
416
417static void do_aha1542_intr_handle(int irq, void *dev_id, struct pt_regs *regs)
418{
419 unsigned long flags;
420
421 spin_lock_irqsave(&io_request_lock, flags);
422 aha1542_intr_handle(irq, dev_id, regs);
423 spin_unlock_irqrestore(&io_request_lock, flags);
424}
425
426
427static void aha1542_intr_handle(int irq, void *dev_id, struct pt_regs *regs)
428{
429 void (*my_done) (Scsi_Cmnd *) = NULL;
430 int errstatus, mbi, mbo, mbistatus;
431 int number_serviced;
432 unsigned long flags;
433 struct Scsi_Host *shost;
434 Scsi_Cmnd *SCtmp;
435 int flag;
436 int needs_restart;
437 struct mailbox *mb;
438 struct ccb *ccb;
439
440 shost = aha_host[irq - 9];
441 if (!shost)
442 panic("Splunge!");
443
444 mb = HOSTDATA(shost)->mb;
445 ccb = HOSTDATA(shost)->ccb;
446
447#ifdef DEBUG
448 {
449 flag = inb(INTRFLAGS(shost->io_port));
450 printk(KERN_DEBUG "aha1542_intr_handle: ");
451 if (!(flag & ANYINTR))
452 printk("no interrupt?");
453 if (flag & MBIF)
454 printk("MBIF ");
455 if (flag & MBOA)
456 printk("MBOF ");
457 if (flag & HACC)
458 printk("HACC ");
459 if (flag & SCRD)
460 printk("SCRD ");
461 printk("status %02x\n", inb(STATUS(shost->io_port)));
462 };
463#endif
464 number_serviced = 0;
465 needs_restart = 0;
466
467 while (1 == 1) {
468 flag = inb(INTRFLAGS(shost->io_port));
469
470
471
472
473
474 if (flag & ~MBIF) {
475 if (flag & MBOA)
476 printk("MBOF ");
477 if (flag & HACC)
478 printk("HACC ");
479 if (flag & SCRD) {
480 needs_restart = 1;
481 printk("SCRD ");
482 }
483 }
484 aha1542_intr_reset(shost->io_port);
485
486 save_flags(flags);
487 cli();
488 mbi = HOSTDATA(shost)->aha1542_last_mbi_used + 1;
489 if (mbi >= 2 * AHA1542_MAILBOXES)
490 mbi = AHA1542_MAILBOXES;
491
492 do {
493 if (mb[mbi].status != 0)
494 break;
495 mbi++;
496 if (mbi >= 2 * AHA1542_MAILBOXES)
497 mbi = AHA1542_MAILBOXES;
498 } while (mbi != HOSTDATA(shost)->aha1542_last_mbi_used);
499
500 if (mb[mbi].status == 0) {
501 restore_flags(flags);
502
503 if (!number_serviced && !needs_restart)
504 printk(KERN_WARNING "aha1542.c: interrupt received, but no mail.\n");
505
506
507 if (needs_restart)
508 aha1542_restart(shost);
509 return;
510 };
511
512 mbo = (scsi2int(mb[mbi].ccbptr) - (SCSI_PA(&ccb[0]))) / sizeof(struct ccb);
513 mbistatus = mb[mbi].status;
514 mb[mbi].status = 0;
515 HOSTDATA(shost)->aha1542_last_mbi_used = mbi;
516 restore_flags(flags);
517
518#ifdef DEBUG
519 {
520 if (ccb[mbo].tarstat | ccb[mbo].hastat)
521 printk(KERN_DEBUG "aha1542_command: returning %x (status %d)\n",
522 ccb[mbo].tarstat + ((int) ccb[mbo].hastat << 16), mb[mbi].status);
523 };
524#endif
525
526 if (mbistatus == 3)
527 continue;
528
529#ifdef DEBUG
530 printk(KERN_DEBUG "...done %d %d\n", mbo, mbi);
531#endif
532
533 SCtmp = HOSTDATA(shost)->SCint[mbo];
534
535 if (!SCtmp || !SCtmp->scsi_done) {
536 printk(KERN_WARNING "aha1542_intr_handle: Unexpected interrupt\n");
537 printk(KERN_WARNING "tarstat=%x, hastat=%x idlun=%x ccb#=%d \n", ccb[mbo].tarstat,
538 ccb[mbo].hastat, ccb[mbo].idlun, mbo);
539 return;
540 }
541 my_done = SCtmp->scsi_done;
542 if (SCtmp->host_scribble) {
543 scsi_free(SCtmp->host_scribble, 512);
544 SCtmp->host_scribble = 0;
545 }
546
547
548
549 if (ccb[mbo].tarstat == 2)
550 memcpy(SCtmp->sense_buffer, &ccb[mbo].cdb[ccb[mbo].cdblen],
551 sizeof(SCtmp->sense_buffer));
552
553
554
555
556
557 if (mbistatus != 1)
558
559 errstatus = makecode(ccb[mbo].hastat, ccb[mbo].tarstat);
560 else
561 errstatus = 0;
562
563#ifdef DEBUG
564 if (errstatus)
565 printk(KERN_DEBUG "(aha1542 error:%x %x %x) ", errstatus,
566 ccb[mbo].hastat, ccb[mbo].tarstat);
567#endif
568
569 if (ccb[mbo].tarstat == 2) {
570#ifdef DEBUG
571 int i;
572#endif
573 DEB(printk("aha1542_intr_handle: sense:"));
574#ifdef DEBUG
575 for (i = 0; i < 12; i++)
576 printk("%02x ", ccb[mbo].cdb[ccb[mbo].cdblen + i]);
577 printk("\n");
578#endif
579
580
581
582
583
584
585 }
586 DEB(if (errstatus) printk("aha1542_intr_handle: returning %6x\n", errstatus));
587 SCtmp->result = errstatus;
588 HOSTDATA(shost)->SCint[mbo] = NULL;
589
590 my_done(SCtmp);
591 number_serviced++;
592 };
593}
594
595static int aha1542_queuecommand(Scsi_Cmnd * SCpnt, void (*done) (Scsi_Cmnd *))
596{
597 unchar ahacmd = CMD_START_SCSI;
598 unchar direction;
599 unchar *cmd = (unchar *) SCpnt->cmnd;
600 unchar target = SCpnt->target;
601 unchar lun = SCpnt->lun;
602 unsigned long flags;
603 void *buff = SCpnt->request_buffer;
604 int bufflen = SCpnt->request_bufflen;
605 int mbo;
606 struct mailbox *mb;
607 struct ccb *ccb;
608
609 DEB(int i);
610
611 mb = HOSTDATA(SCpnt->host)->mb;
612 ccb = HOSTDATA(SCpnt->host)->ccb;
613
614 DEB(if (target > 1) {
615 SCpnt->result = DID_TIME_OUT << 16;
616 done(SCpnt); return 0;
617 }
618 );
619
620 if (*cmd == REQUEST_SENSE) {
621
622#if 0
623
624
625 if (bufflen != sizeof(SCpnt->sense_buffer))
626 printk(KERN_CRIT "aha1542: Wrong buffer length supplied "
627 "for request sense (%d)\n", bufflen);
628#endif
629 SCpnt->result = 0;
630 done(SCpnt);
631 return 0;
632 }
633#ifdef DEBUG
634 if (*cmd == READ_10 || *cmd == WRITE_10)
635 i = xscsi2int(cmd + 2);
636 else if (*cmd == READ_6 || *cmd == WRITE_6)
637 i = scsi2int(cmd + 2);
638 else
639 i = -1;
640 if (done)
641 printk(KERN_DEBUG "aha1542_queuecommand: dev %d cmd %02x pos %d len %d ", target, *cmd, i, bufflen);
642 else
643 printk(KERN_DEBUG "aha1542_command: dev %d cmd %02x pos %d len %d ", target, *cmd, i, bufflen);
644 aha1542_stat();
645 printk(KERN_DEBUG "aha1542_queuecommand: dumping scsi cmd:");
646 for (i = 0; i < SCpnt->cmd_len; i++)
647 printk("%02x ", cmd[i]);
648 printk("\n");
649 if (*cmd == WRITE_10 || *cmd == WRITE_6)
650 return 0;
651#endif
652
653
654
655 save_flags(flags);
656 cli();
657 mbo = HOSTDATA(SCpnt->host)->aha1542_last_mbo_used + 1;
658 if (mbo >= AHA1542_MAILBOXES)
659 mbo = 0;
660
661 do {
662 if (mb[mbo].status == 0 && HOSTDATA(SCpnt->host)->SCint[mbo] == NULL)
663 break;
664 mbo++;
665 if (mbo >= AHA1542_MAILBOXES)
666 mbo = 0;
667 } while (mbo != HOSTDATA(SCpnt->host)->aha1542_last_mbo_used);
668
669 if (mb[mbo].status || HOSTDATA(SCpnt->host)->SCint[mbo])
670 panic("Unable to find empty mailbox for aha1542.\n");
671
672 HOSTDATA(SCpnt->host)->SCint[mbo] = SCpnt;
673
674
675 HOSTDATA(SCpnt->host)->aha1542_last_mbo_used = mbo;
676 restore_flags(flags);
677
678#ifdef DEBUG
679 printk(KERN_DEBUG "Sending command (%d %x)...", mbo, done);
680#endif
681
682 any2scsi(mb[mbo].ccbptr, SCSI_PA(&ccb[mbo]));
683
684 memset(&ccb[mbo], 0, sizeof(struct ccb));
685
686 ccb[mbo].cdblen = SCpnt->cmd_len;
687
688 direction = 0;
689 if (*cmd == READ_10 || *cmd == READ_6)
690 direction = 8;
691 else if (*cmd == WRITE_10 || *cmd == WRITE_6)
692 direction = 16;
693
694 memcpy(ccb[mbo].cdb, cmd, ccb[mbo].cdblen);
695
696 if (SCpnt->use_sg) {
697 struct scatterlist *sgpnt;
698 struct chain *cptr;
699#ifdef DEBUG
700 unsigned char *ptr;
701#endif
702 int i;
703 ccb[mbo].op = 2;
704 SCpnt->host_scribble = (unsigned char *) scsi_malloc(512);
705 sgpnt = (struct scatterlist *) SCpnt->request_buffer;
706 cptr = (struct chain *) SCpnt->host_scribble;
707 if (cptr == NULL)
708 panic("aha1542.c: unable to allocate DMA memory\n");
709 for (i = 0; i < SCpnt->use_sg; i++) {
710 if (sgpnt[i].length == 0 || SCpnt->use_sg > 16 ||
711 (((int) sgpnt[i].address) & 1) || (sgpnt[i].length & 1)) {
712 unsigned char *ptr;
713 printk(KERN_CRIT "Bad segment list supplied to aha1542.c (%d, %d)\n", SCpnt->use_sg, i);
714 for (i = 0; i < SCpnt->use_sg; i++) {
715 printk(KERN_CRIT "%d: %p %d\n", i, sgpnt[i].address,
716 sgpnt[i].length);
717 };
718 printk(KERN_CRIT "cptr %x: ", (unsigned int) cptr);
719 ptr = (unsigned char *) &cptr[i];
720 for (i = 0; i < 18; i++)
721 printk("%02x ", ptr[i]);
722 panic("Foooooooood fight!");
723 };
724 any2scsi(cptr[i].dataptr, SCSI_PA(sgpnt[i].address));
725 if (SCSI_PA(sgpnt[i].address + sgpnt[i].length - 1) > ISA_DMA_THRESHOLD)
726 BAD_SG_DMA(SCpnt, sgpnt, SCpnt->use_sg, i);
727 any2scsi(cptr[i].datalen, sgpnt[i].length);
728 };
729 any2scsi(ccb[mbo].datalen, SCpnt->use_sg * sizeof(struct chain));
730 any2scsi(ccb[mbo].dataptr, SCSI_PA(cptr));
731#ifdef DEBUG
732 printk("cptr %x: ", cptr);
733 ptr = (unsigned char *) cptr;
734 for (i = 0; i < 18; i++)
735 printk("%02x ", ptr[i]);
736#endif
737 } else {
738 ccb[mbo].op = 0;
739 SCpnt->host_scribble = NULL;
740 any2scsi(ccb[mbo].datalen, bufflen);
741 if (buff && SCSI_PA(buff + bufflen - 1) > ISA_DMA_THRESHOLD)
742 BAD_DMA(buff, bufflen);
743 any2scsi(ccb[mbo].dataptr, SCSI_PA(buff));
744 };
745 ccb[mbo].idlun = (target & 7) << 5 | direction | (lun & 7);
746 ccb[mbo].rsalen = 16;
747 ccb[mbo].linkptr[0] = ccb[mbo].linkptr[1] = ccb[mbo].linkptr[2] = 0;
748 ccb[mbo].commlinkid = 0;
749
750#ifdef DEBUG
751 {
752 int i;
753 printk(KERN_DEBUG "aha1542_command: sending.. ");
754 for (i = 0; i < sizeof(ccb[mbo]) - 10; i++)
755 printk("%02x ", ((unchar *) & ccb[mbo])[i]);
756 };
757#endif
758
759 if (done) {
760 DEB(printk("aha1542_queuecommand: now waiting for interrupt ");
761 aha1542_stat());
762 SCpnt->scsi_done = done;
763 mb[mbo].status = 1;
764 aha1542_out(SCpnt->host->io_port, &ahacmd, 1);
765 DEB(aha1542_stat());
766 } else
767 printk("aha1542_queuecommand: done can't be NULL\n");
768
769 return 0;
770}
771
772static void internal_done(Scsi_Cmnd * SCpnt)
773{
774 SCpnt->SCp.Status++;
775}
776
777static int aha1542_command(Scsi_Cmnd * SCpnt)
778{
779 DEB(printk("aha1542_command: ..calling aha1542_queuecommand\n"));
780
781 aha1542_queuecommand(SCpnt, internal_done);
782
783 SCpnt->SCp.Status = 0;
784 while (!SCpnt->SCp.Status)
785 barrier();
786 return SCpnt->result;
787}
788
789
790static void setup_mailboxes(int bse, struct Scsi_Host *shpnt)
791{
792 int i;
793 struct mailbox *mb;
794 struct ccb *ccb;
795
796 unchar cmd[5] = { CMD_MBINIT, AHA1542_MAILBOXES, 0, 0, 0};
797
798 mb = HOSTDATA(shpnt)->mb;
799 ccb = HOSTDATA(shpnt)->ccb;
800
801 for (i = 0; i < AHA1542_MAILBOXES; i++) {
802 mb[i].status = mb[AHA1542_MAILBOXES + i].status = 0;
803 any2scsi(mb[i].ccbptr, SCSI_PA(&ccb[i]));
804 };
805 aha1542_intr_reset(bse);
806 any2scsi((cmd + 2), SCSI_PA(mb));
807 aha1542_out(bse, cmd, 5);
808 WAIT(INTRFLAGS(bse), INTRMASK, HACC, 0);
809 while (0) {
810fail:
811 printk(KERN_ERR "aha1542_detect: failed setting up mailboxes\n");
812 }
813 aha1542_intr_reset(bse);
814}
815
816static int __init aha1542_getconfig(int base_io, unsigned char *irq_level, unsigned char *dma_chan, unsigned char *scsi_id)
817{
818 unchar inquiry_cmd[] = {CMD_RETCONF};
819 unchar inquiry_result[3];
820 int i;
821 i = inb(STATUS(base_io));
822 if (i & DF) {
823 i = inb(DATA(base_io));
824 };
825 aha1542_out(base_io, inquiry_cmd, 1);
826 aha1542_in(base_io, inquiry_result, 3);
827 WAIT(INTRFLAGS(base_io), INTRMASK, HACC, 0);
828 while (0) {
829fail:
830 printk(KERN_ERR "aha1542_detect: query board settings\n");
831 }
832 aha1542_intr_reset(base_io);
833 switch (inquiry_result[0]) {
834 case 0x80:
835 *dma_chan = 7;
836 break;
837 case 0x40:
838 *dma_chan = 6;
839 break;
840 case 0x20:
841 *dma_chan = 5;
842 break;
843 case 0x01:
844 *dma_chan = 0;
845 break;
846 case 0:
847
848
849 *dma_chan = 0xFF;
850 break;
851 default:
852 printk(KERN_ERR "Unable to determine Adaptec DMA priority. Disabling board\n");
853 return -1;
854 };
855 switch (inquiry_result[1]) {
856 case 0x40:
857 *irq_level = 15;
858 break;
859 case 0x20:
860 *irq_level = 14;
861 break;
862 case 0x8:
863 *irq_level = 12;
864 break;
865 case 0x4:
866 *irq_level = 11;
867 break;
868 case 0x2:
869 *irq_level = 10;
870 break;
871 case 0x1:
872 *irq_level = 9;
873 break;
874 default:
875 printk(KERN_ERR "Unable to determine Adaptec IRQ level. Disabling board\n");
876 return -1;
877 };
878 *scsi_id = inquiry_result[2] & 7;
879 return 0;
880}
881
882
883
884
885static int __init aha1542_mbenable(int base)
886{
887 static unchar mbenable_cmd[3];
888 static unchar mbenable_result[2];
889 int retval;
890
891 retval = BIOS_TRANSLATION_6432;
892
893 mbenable_cmd[0] = CMD_EXTBIOS;
894 aha1542_out(base, mbenable_cmd, 1);
895 if (aha1542_in1(base, mbenable_result, 2))
896 return retval;
897 WAITd(INTRFLAGS(base), INTRMASK, HACC, 0, 100);
898 aha1542_intr_reset(base);
899
900 if ((mbenable_result[0] & 0x08) || mbenable_result[1]) {
901 mbenable_cmd[0] = CMD_MBENABLE;
902 mbenable_cmd[1] = 0;
903 mbenable_cmd[2] = mbenable_result[1];
904
905 if ((mbenable_result[0] & 0x08) && (mbenable_result[1] & 0x03))
906 retval = BIOS_TRANSLATION_25563;
907
908 aha1542_out(base, mbenable_cmd, 3);
909 WAIT(INTRFLAGS(base), INTRMASK, HACC, 0);
910 };
911 while (0) {
912fail:
913 printk(KERN_ERR "aha1542_mbenable: Mailbox init failed\n");
914 }
915 aha1542_intr_reset(base);
916 return retval;
917}
918
919
920static int __init aha1542_query(int base_io, int *transl)
921{
922 unchar inquiry_cmd[] = {CMD_INQUIRY};
923 unchar inquiry_result[4];
924 int i;
925 i = inb(STATUS(base_io));
926 if (i & DF) {
927 i = inb(DATA(base_io));
928 };
929 aha1542_out(base_io, inquiry_cmd, 1);
930 aha1542_in(base_io, inquiry_result, 4);
931 WAIT(INTRFLAGS(base_io), INTRMASK, HACC, 0);
932 while (0) {
933fail:
934 printk(KERN_ERR "aha1542_detect: query card type\n");
935 }
936 aha1542_intr_reset(base_io);
937
938 *transl = BIOS_TRANSLATION_6432;
939
940
941
942
943
944
945
946 if (inquiry_result[0] == 0x43) {
947 printk(KERN_INFO "aha1542.c: Emulation mode not supported for AHA 174N hardware.\n");
948 return 1;
949 };
950
951
952
953
954 *transl = aha1542_mbenable(base_io);
955
956 return 0;
957}
958
959#ifndef MODULE
960static int setup_idx = 0;
961static char *setup_str[MAXBOARDS] __initdata;
962
963void __init aha1542_setup(char *str, int *ints)
964{
965 const char *ahausage = "aha1542: usage: aha1542=<PORTBASE>[,<BUSON>,<BUSOFF>[,<DMASPEED>]]\n";
966 int setup_portbase;
967
968 if (setup_idx >= MAXBOARDS) {
969 printk(KERN_ERR "aha1542: aha1542_setup called too many times! Bad LILO params ?\n");
970 printk(KERN_ERR " Entryline 1: %s\n", setup_str[0]);
971 printk(KERN_ERR " Entryline 2: %s\n", setup_str[1]);
972 printk(KERN_ERR " This line: %s\n", str);
973 return;
974 }
975 if (ints[0] < 1 || ints[0] > 4) {
976 printk(KERN_ERR "aha1542: %s\n", str);
977 printk(ahausage);
978 printk(KERN_ERR "aha1542: Wrong parameters may cause system malfunction.. We try anyway..\n");
979 }
980 setup_called[setup_idx] = ints[0];
981 setup_str[setup_idx] = str;
982
983 setup_portbase = ints[0] >= 1 ? ints[1] : 0;
984 setup_buson[setup_idx] = ints[0] >= 2 ? ints[2] : 7;
985 setup_busoff[setup_idx] = ints[0] >= 3 ? ints[3] : 5;
986 if (ints[0] >= 4)
987 {
988 int atbt = -1;
989 switch (ints[4]) {
990 case 5:
991 atbt = 0x00;
992 break;
993 case 6:
994 atbt = 0x04;
995 break;
996 case 7:
997 atbt = 0x01;
998 break;
999 case 8:
1000 atbt = 0x02;
1001 break;
1002 case 10:
1003 atbt = 0x03;
1004 break;
1005 default:
1006 printk(KERN_ERR "aha1542: %s\n", str);
1007 printk(ahausage);
1008 printk(KERN_ERR "aha1542: Valid values for DMASPEED are 5-8, 10 MB/s. Using jumper defaults.\n");
1009 break;
1010 }
1011 setup_dmaspeed[setup_idx] = atbt;
1012 }
1013 if (setup_portbase != 0)
1014 bases[setup_idx] = setup_portbase;
1015
1016 ++setup_idx;
1017}
1018
1019static int __init do_setup(char *str)
1020{
1021 int ints[4];
1022
1023 int count=setup_idx;
1024
1025 get_options(str, sizeof(ints)/sizeof(int), ints);
1026 aha1542_setup(str,ints);
1027
1028 return count<setup_idx;
1029}
1030
1031__setup("aha1542=",do_setup);
1032#endif
1033
1034
1035static int __init aha1542_detect(Scsi_Host_Template * tpnt)
1036{
1037 unsigned char dma_chan;
1038 unsigned char irq_level;
1039 unsigned char scsi_id;
1040 unsigned long flags;
1041 unsigned int base_io;
1042 int trans;
1043 struct Scsi_Host *shpnt = NULL;
1044 int count = 0;
1045 int indx;
1046
1047 DEB(printk("aha1542_detect: \n"));
1048
1049 tpnt->proc_name = "aha1542";
1050
1051#ifdef MODULE
1052 bases[0] = aha1542[0];
1053 setup_buson[0] = aha1542[1];
1054 setup_busoff[0] = aha1542[2];
1055 {
1056 int atbt = -1;
1057 switch (aha1542[3]) {
1058 case 5:
1059 atbt = 0x00;
1060 break;
1061 case 6:
1062 atbt = 0x04;
1063 break;
1064 case 7:
1065 atbt = 0x01;
1066 break;
1067 case 8:
1068 atbt = 0x02;
1069 break;
1070 case 10:
1071 atbt = 0x03;
1072 break;
1073 };
1074 setup_dmaspeed[0] = atbt;
1075 }
1076#endif
1077
1078
1079
1080
1081#ifdef CONFIG_MCA
1082 if(MCA_bus) {
1083 int slot = 0;
1084 int pos = 0;
1085
1086 for (indx = 0; (slot != MCA_NOTFOUND) &&
1087 (indx < sizeof(bases)/sizeof(bases[0])); indx++) {
1088
1089 if (bases[indx])
1090 continue;
1091
1092
1093 slot = mca_find_unused_adapter(0x0f1f, slot);
1094 if (slot == MCA_NOTFOUND)
1095 break;
1096
1097
1098
1099 pos = mca_read_stored_pos(slot, 3);
1100
1101
1102 if (pos & 0x80) {
1103 if (pos & 0x02) {
1104 if (pos & 0x01)
1105 bases[indx] = 0x334;
1106 else
1107 bases[indx] = 0x234;
1108 } else {
1109 if (pos & 0x01)
1110 bases[indx] = 0x134;
1111 }
1112 } else {
1113 if (pos & 0x02) {
1114 if (pos & 0x01)
1115 bases[indx] = 0x330;
1116 else
1117 bases[indx] = 0x230;
1118 } else {
1119 if (pos & 0x01)
1120 bases[indx] = 0x130;
1121 }
1122 }
1123
1124
1125
1126
1127 printk(KERN_INFO "Found an AHA-1640 in MCA slot %d, I/O 0x%04x\n", slot, bases[indx]);
1128
1129 mca_set_adapter_name(slot, "Adapter AHA-1640");
1130 mca_set_adapter_procfn(slot, NULL, NULL);
1131 mca_mark_as_used(slot);
1132
1133
1134 slot++;
1135 }
1136
1137 }
1138#endif
1139
1140
1141
1142
1143
1144 if(isapnp)
1145 {
1146 struct pci_dev *pdev = NULL;
1147 for(indx = 0; indx <sizeof(bases)/sizeof(bases[0]);indx++)
1148 {
1149 if(bases[indx])
1150 continue;
1151 pdev = isapnp_find_dev(NULL, ISAPNP_VENDOR('A', 'D', 'P'),
1152 ISAPNP_FUNCTION(0x1542), pdev);
1153 if(pdev==NULL)
1154 break;
1155
1156
1157
1158
1159 if(pdev->prepare(pdev)<0)
1160 continue;
1161
1162 if(!(pdev->resource[0].flags&IORESOURCE_IO))
1163 continue;
1164
1165 pdev->resource[0].flags|=IORESOURCE_AUTO;
1166
1167 if(pdev->activate(pdev)<0)
1168 continue;
1169
1170 bases[indx] = pdev->resource[0].start;
1171
1172
1173
1174
1175 printk(KERN_INFO "ISAPnP found an AHA1535 at I/O 0x%03X\n", bases[indx]);
1176 }
1177 }
1178 for (indx = 0; indx < sizeof(bases) / sizeof(bases[0]); indx++)
1179 if (bases[indx] != 0 && !check_region(bases[indx], 4)) {
1180 shpnt = scsi_register(tpnt,
1181 sizeof(struct aha1542_hostdata));
1182
1183 if(shpnt==NULL)
1184 continue;
1185
1186
1187 if (SCSI_PA(shpnt) >= ISA_DMA_THRESHOLD) {
1188 printk(KERN_ERR "Invalid address for shpnt with 1542.\n");
1189 goto unregister;
1190 }
1191 if (!aha1542_test_port(bases[indx], shpnt))
1192 goto unregister;
1193
1194
1195 base_io = bases[indx];
1196
1197
1198 {
1199 unchar oncmd[] = {CMD_BUSON_TIME, 7};
1200 unchar offcmd[] = {CMD_BUSOFF_TIME, 5};
1201
1202 if (setup_called[indx]) {
1203 oncmd[1] = setup_buson[indx];
1204 offcmd[1] = setup_busoff[indx];
1205 }
1206 aha1542_intr_reset(base_io);
1207 aha1542_out(base_io, oncmd, 2);
1208 WAIT(INTRFLAGS(base_io), INTRMASK, HACC, 0);
1209 aha1542_intr_reset(base_io);
1210 aha1542_out(base_io, offcmd, 2);
1211 WAIT(INTRFLAGS(base_io), INTRMASK, HACC, 0);
1212 if (setup_dmaspeed[indx] >= 0) {
1213 unchar dmacmd[] = {CMD_DMASPEED, 0};
1214 dmacmd[1] = setup_dmaspeed[indx];
1215 aha1542_intr_reset(base_io);
1216 aha1542_out(base_io, dmacmd, 2);
1217 WAIT(INTRFLAGS(base_io), INTRMASK, HACC, 0);
1218 }
1219 while (0) {
1220fail:
1221 printk(KERN_ERR "aha1542_detect: setting bus on/off-time failed\n");
1222 }
1223 aha1542_intr_reset(base_io);
1224 }
1225 if (aha1542_query(base_io, &trans))
1226 goto unregister;
1227
1228 if (aha1542_getconfig(base_io, &irq_level, &dma_chan, &scsi_id) == -1)
1229 goto unregister;
1230
1231 printk(KERN_INFO "Configuring Adaptec (SCSI-ID %d) at IO:%x, IRQ %d", scsi_id, base_io, irq_level);
1232 if (dma_chan != 0xFF)
1233 printk(", DMA priority %d", dma_chan);
1234 printk("\n");
1235
1236 DEB(aha1542_stat());
1237 setup_mailboxes(base_io, shpnt);
1238
1239 DEB(aha1542_stat());
1240
1241 DEB(printk("aha1542_detect: enable interrupt channel %d\n", irq_level));
1242 save_flags(flags);
1243 cli();
1244 if (request_irq(irq_level, do_aha1542_intr_handle, 0, "aha1542", NULL)) {
1245 printk(KERN_ERR "Unable to allocate IRQ for adaptec controller.\n");
1246 restore_flags(flags);
1247 goto unregister;
1248 }
1249 if (dma_chan != 0xFF) {
1250 if (request_dma(dma_chan, "aha1542")) {
1251 printk(KERN_ERR "Unable to allocate DMA channel for Adaptec.\n");
1252 free_irq(irq_level, NULL);
1253 restore_flags(flags);
1254 goto unregister;
1255 }
1256 if (dma_chan == 0 || dma_chan >= 5) {
1257 set_dma_mode(dma_chan, DMA_MODE_CASCADE);
1258 enable_dma(dma_chan);
1259 }
1260 }
1261 aha_host[irq_level - 9] = shpnt;
1262 shpnt->this_id = scsi_id;
1263 shpnt->unique_id = base_io;
1264 shpnt->io_port = base_io;
1265 shpnt->n_io_port = 4;
1266 shpnt->dma_channel = dma_chan;
1267 shpnt->irq = irq_level;
1268 HOSTDATA(shpnt)->bios_translation = trans;
1269 if (trans == BIOS_TRANSLATION_25563)
1270 printk(KERN_INFO "aha1542.c: Using extended bios translation\n");
1271 HOSTDATA(shpnt)->aha1542_last_mbi_used = (2 * AHA1542_MAILBOXES - 1);
1272 HOSTDATA(shpnt)->aha1542_last_mbo_used = (AHA1542_MAILBOXES - 1);
1273 memset(HOSTDATA(shpnt)->SCint, 0, sizeof(HOSTDATA(shpnt)->SCint));
1274 restore_flags(flags);
1275#if 0
1276 DEB(printk(" *** READ CAPACITY ***\n"));
1277
1278 {
1279 unchar buf[8];
1280 static unchar cmd[] = { READ_CAPACITY, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
1281 int i;
1282
1283 for (i = 0; i < sizeof(buf); ++i)
1284 buf[i] = 0x87;
1285 for (i = 0; i < 2; ++i)
1286 if (!aha1542_command(i, cmd, buf, sizeof(buf))) {
1287 printk(KERN_DEBUG "aha_detect: LU %d sector_size %d device_size %d\n",
1288 i, xscsi2int(buf + 4), xscsi2int(buf));
1289 }
1290 }
1291
1292 DEB(printk(" *** NOW RUNNING MY OWN TEST *** \n"));
1293
1294 for (i = 0; i < 4; ++i) {
1295 unsigned char cmd[10];
1296 static buffer[512];
1297
1298 cmd[0] = READ_10;
1299 cmd[1] = 0;
1300 xany2scsi(cmd + 2, i);
1301 cmd[6] = 0;
1302 cmd[7] = 0;
1303 cmd[8] = 1;
1304 cmd[9] = 0;
1305 aha1542_command(0, cmd, buffer, 512);
1306 }
1307#endif
1308 request_region(bases[indx], 4, "aha1542");
1309 count++;
1310 continue;
1311unregister:
1312 scsi_unregister(shpnt);
1313 continue;
1314
1315 };
1316
1317 return count;
1318}
1319
1320static int aha1542_restart(struct Scsi_Host *shost)
1321{
1322 int i;
1323 int count = 0;
1324#if 0
1325 unchar ahacmd = CMD_START_SCSI;
1326#endif
1327
1328 for (i = 0; i < AHA1542_MAILBOXES; i++)
1329 if (HOSTDATA(shost)->SCint[i] &&
1330 !(HOSTDATA(shost)->SCint[i]->device->soft_reset)) {
1331#if 0
1332 HOSTDATA(shost)->mb[i].status = 1;
1333#endif
1334 count++;
1335 }
1336 printk(KERN_DEBUG "Potential to restart %d stalled commands...\n", count);
1337#if 0
1338
1339 if (count)
1340 aha1542_out(shost->io_port, &ahacmd, 1);
1341#endif
1342 return 0;
1343}
1344
1345static int aha1542_abort(Scsi_Cmnd * SCpnt)
1346{
1347
1348
1349
1350
1351
1352
1353
1354 printk(KERN_ERR "aha1542.c: Unable to abort command for target %d\n",
1355 SCpnt->target);
1356 return FAILED;
1357}
1358
1359
1360
1361
1362
1363static int aha1542_dev_reset(Scsi_Cmnd * SCpnt)
1364{
1365 unsigned long flags;
1366 struct mailbox *mb;
1367 unchar target = SCpnt->target;
1368 unchar lun = SCpnt->lun;
1369 int mbo;
1370 struct ccb *ccb;
1371 unchar ahacmd = CMD_START_SCSI;
1372
1373 ccb = HOSTDATA(SCpnt->host)->ccb;
1374 mb = HOSTDATA(SCpnt->host)->mb;
1375
1376 save_flags(flags);
1377 cli();
1378 mbo = HOSTDATA(SCpnt->host)->aha1542_last_mbo_used + 1;
1379 if (mbo >= AHA1542_MAILBOXES)
1380 mbo = 0;
1381
1382 do {
1383 if (mb[mbo].status == 0 && HOSTDATA(SCpnt->host)->SCint[mbo] == NULL)
1384 break;
1385 mbo++;
1386 if (mbo >= AHA1542_MAILBOXES)
1387 mbo = 0;
1388 } while (mbo != HOSTDATA(SCpnt->host)->aha1542_last_mbo_used);
1389
1390 if (mb[mbo].status || HOSTDATA(SCpnt->host)->SCint[mbo])
1391 panic("Unable to find empty mailbox for aha1542.\n");
1392
1393 HOSTDATA(SCpnt->host)->SCint[mbo] = SCpnt;
1394
1395
1396
1397 HOSTDATA(SCpnt->host)->aha1542_last_mbo_used = mbo;
1398 restore_flags(flags);
1399
1400 any2scsi(mb[mbo].ccbptr, SCSI_PA(&ccb[mbo]));
1401
1402 memset(&ccb[mbo], 0, sizeof(struct ccb));
1403
1404 ccb[mbo].op = 0x81;
1405
1406 ccb[mbo].idlun = (target & 7) << 5 | (lun & 7);
1407
1408 ccb[mbo].linkptr[0] = ccb[mbo].linkptr[1] = ccb[mbo].linkptr[2] = 0;
1409 ccb[mbo].commlinkid = 0;
1410
1411
1412
1413
1414
1415 aha1542_out(SCpnt->host->io_port, &ahacmd, 1);
1416
1417 printk(KERN_WARNING "aha1542.c: Trying device reset for target %d\n", SCpnt->target);
1418
1419 return SUCCESS;
1420
1421
1422#ifdef ERIC_neverdef
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432 printk(KERN_WARNING "Sent BUS DEVICE RESET to target %d\n", SCpnt->target);
1433
1434
1435
1436
1437
1438 for (i = 0; i < AHA1542_MAILBOXES; i++) {
1439 if (HOSTDATA(SCpnt->host)->SCint[i] &&
1440 HOSTDATA(SCpnt->host)->SCint[i]->target == SCpnt->target) {
1441 Scsi_Cmnd *SCtmp;
1442 SCtmp = HOSTDATA(SCpnt->host)->SCint[i];
1443 if (SCtmp->host_scribble) {
1444 scsi_free(SCtmp->host_scribble, 512);
1445 SCtmp->host_scribble = NULL;
1446 }
1447 HOSTDATA(SCpnt->host)->SCint[i] = NULL;
1448 HOSTDATA(SCpnt->host)->mb[i].status = 0;
1449 }
1450 }
1451 return SUCCESS;
1452
1453 return FAILED;
1454#endif
1455}
1456
1457static int aha1542_bus_reset(Scsi_Cmnd * SCpnt)
1458{
1459 int i;
1460
1461
1462
1463
1464
1465
1466
1467 outb(SCRST, CONTROL(SCpnt->host->io_port));
1468
1469
1470
1471
1472
1473
1474
1475
1476 spin_unlock_irq(&io_request_lock);
1477 scsi_sleep(4 * HZ);
1478 spin_lock_irq(&io_request_lock);
1479
1480 WAIT(STATUS(SCpnt->host->io_port),
1481 STATMASK, INIT | IDLE, STST | DIAGF | INVDCMD | DF | CDF);
1482
1483
1484
1485
1486
1487
1488
1489 printk(KERN_WARNING "Sent BUS RESET to scsi host %d\n", SCpnt->host->host_no);
1490
1491 for (i = 0; i < AHA1542_MAILBOXES; i++) {
1492 if (HOSTDATA(SCpnt->host)->SCint[i] != NULL) {
1493 Scsi_Cmnd *SCtmp;
1494 SCtmp = HOSTDATA(SCpnt->host)->SCint[i];
1495
1496
1497 if (SCtmp->device->soft_reset) {
1498
1499
1500
1501
1502
1503
1504 continue;
1505 }
1506 if (SCtmp->host_scribble) {
1507 scsi_free(SCtmp->host_scribble, 512);
1508 SCtmp->host_scribble = NULL;
1509 }
1510 HOSTDATA(SCpnt->host)->SCint[i] = NULL;
1511 HOSTDATA(SCpnt->host)->mb[i].status = 0;
1512 }
1513 }
1514
1515 return SUCCESS;
1516
1517fail:
1518 return FAILED;
1519}
1520
1521static int aha1542_host_reset(Scsi_Cmnd * SCpnt)
1522{
1523 int i;
1524
1525
1526
1527
1528
1529
1530
1531 outb(HRST | SCRST, CONTROL(SCpnt->host->io_port));
1532
1533
1534
1535
1536
1537
1538
1539
1540 spin_unlock_irq(&io_request_lock);
1541 scsi_sleep(4 * HZ);
1542 spin_lock_irq(&io_request_lock);
1543
1544 WAIT(STATUS(SCpnt->host->io_port),
1545 STATMASK, INIT | IDLE, STST | DIAGF | INVDCMD | DF | CDF);
1546
1547
1548
1549
1550
1551 setup_mailboxes(SCpnt->host->io_port, SCpnt->host);
1552
1553
1554
1555
1556
1557
1558
1559 printk(KERN_WARNING "Sent BUS RESET to scsi host %d\n", SCpnt->host->host_no);
1560
1561 for (i = 0; i < AHA1542_MAILBOXES; i++) {
1562 if (HOSTDATA(SCpnt->host)->SCint[i] != NULL) {
1563 Scsi_Cmnd *SCtmp;
1564 SCtmp = HOSTDATA(SCpnt->host)->SCint[i];
1565
1566 if (SCtmp->device->soft_reset) {
1567
1568
1569
1570
1571
1572
1573 continue;
1574 }
1575 if (SCtmp->host_scribble) {
1576 scsi_free(SCtmp->host_scribble, 512);
1577 SCtmp->host_scribble = NULL;
1578 }
1579 HOSTDATA(SCpnt->host)->SCint[i] = NULL;
1580 HOSTDATA(SCpnt->host)->mb[i].status = 0;
1581 }
1582 }
1583
1584 return SUCCESS;
1585
1586fail:
1587 return FAILED;
1588}
1589
1590
1591
1592
1593
1594static int aha1542_old_abort(Scsi_Cmnd * SCpnt)
1595{
1596#if 0
1597 unchar ahacmd = CMD_START_SCSI;
1598 unsigned long flags;
1599 struct mailbox *mb;
1600 int mbi, mbo, i;
1601
1602 printk(KERN_DEBUG "In aha1542_abort: %x %x\n",
1603 inb(STATUS(SCpnt->host->io_port)),
1604 inb(INTRFLAGS(SCpnt->host->io_port)));
1605
1606 save_flags(flags);
1607 cli();
1608 mb = HOSTDATA(SCpnt->host)->mb;
1609 mbi = HOSTDATA(SCpnt->host)->aha1542_last_mbi_used + 1;
1610 if (mbi >= 2 * AHA1542_MAILBOXES)
1611 mbi = AHA1542_MAILBOXES;
1612
1613 do {
1614 if (mb[mbi].status != 0)
1615 break;
1616 mbi++;
1617 if (mbi >= 2 * AHA1542_MAILBOXES)
1618 mbi = AHA1542_MAILBOXES;
1619 } while (mbi != HOSTDATA(SCpnt->host)->aha1542_last_mbi_used);
1620 restore_flags(flags);
1621
1622 if (mb[mbi].status) {
1623 printk(KERN_ERR "Lost interrupt discovered on irq %d - attempting to recover\n",
1624 SCpnt->host->irq);
1625 aha1542_intr_handle(SCpnt->host->irq, NULL);
1626 return 0;
1627 }
1628
1629
1630
1631 for (i = 0; i < AHA1542_MAILBOXES; i++)
1632 if (HOSTDATA(SCpnt->host)->SCint[i]) {
1633 if (HOSTDATA(SCpnt->host)->SCint[i] == SCpnt) {
1634 printk(KERN_ERR "Timed out command pending for %s\n",
1635 kdevname(SCpnt->request.rq_dev));
1636 if (HOSTDATA(SCpnt->host)->mb[i].status) {
1637 printk(KERN_ERR "OGMB still full - restarting\n");
1638 aha1542_out(SCpnt->host->io_port, &ahacmd, 1);
1639 };
1640 } else
1641 printk(KERN_ERR "Other pending command %s\n",
1642 kdevname(SCpnt->request.rq_dev));
1643 }
1644#endif
1645
1646 DEB(printk("aha1542_abort\n"));
1647#if 0
1648 save_flags(flags);
1649 cli();
1650 for (mbo = 0; mbo < AHA1542_MAILBOXES; mbo++)
1651 if (SCpnt == HOSTDATA(SCpnt->host)->SCint[mbo]) {
1652 mb[mbo].status = 2;
1653 aha1542_out(SCpnt->host->io_port, &ahacmd, 1);
1654 restore_flags(flags);
1655 break;
1656 };
1657#endif
1658 return SCSI_ABORT_SNOOZE;
1659}
1660
1661
1662
1663
1664
1665
1666
1667static int aha1542_old_reset(Scsi_Cmnd * SCpnt, unsigned int reset_flags)
1668{
1669 unchar ahacmd = CMD_START_SCSI;
1670 int i;
1671
1672
1673
1674
1675 if (reset_flags & SCSI_RESET_SUGGEST_BUS_RESET) {
1676
1677
1678
1679
1680
1681
1682 outb(HRST | SCRST, CONTROL(SCpnt->host->io_port));
1683
1684
1685
1686
1687
1688
1689
1690
1691 WAIT(STATUS(SCpnt->host->io_port),
1692 STATMASK, INIT | IDLE, STST | DIAGF | INVDCMD | DF | CDF);
1693
1694
1695
1696
1697
1698 setup_mailboxes(SCpnt->host->io_port, SCpnt->host);
1699
1700
1701
1702
1703
1704
1705
1706 printk(KERN_WARNING "Sent BUS RESET to scsi host %d\n", SCpnt->host->host_no);
1707
1708 for (i = 0; i < AHA1542_MAILBOXES; i++)
1709 if (HOSTDATA(SCpnt->host)->SCint[i] != NULL) {
1710 Scsi_Cmnd *SCtmp;
1711 SCtmp = HOSTDATA(SCpnt->host)->SCint[i];
1712 SCtmp->result = DID_RESET << 16;
1713 if (SCtmp->host_scribble) {
1714 scsi_free(SCtmp->host_scribble, 512);
1715 SCtmp->host_scribble = NULL;
1716 }
1717 printk(KERN_WARNING "Sending DID_RESET for target %d\n", SCpnt->target);
1718 SCtmp->scsi_done(SCpnt);
1719
1720 HOSTDATA(SCpnt->host)->SCint[i] = NULL;
1721 HOSTDATA(SCpnt->host)->mb[i].status = 0;
1722 }
1723
1724
1725
1726
1727
1728 return (SCSI_RESET_SUCCESS | SCSI_RESET_BUS_RESET);
1729fail:
1730 printk(KERN_CRIT "aha1542.c: Unable to perform hard reset.\n");
1731 printk(KERN_CRIT "Power cycle machine to reset\n");
1732 return (SCSI_RESET_ERROR | SCSI_RESET_BUS_RESET);
1733
1734
1735 } else {
1736
1737
1738 for (i = 0; i < AHA1542_MAILBOXES; i++)
1739 if (HOSTDATA(SCpnt->host)->SCint[i] == SCpnt) {
1740 HOSTDATA(SCpnt->host)->ccb[i].op = 0x81;
1741
1742 aha1542_out(SCpnt->host->io_port, &ahacmd, 1);
1743
1744
1745
1746
1747
1748 printk(KERN_WARNING "Sent BUS DEVICE RESET to target %d\n", SCpnt->target);
1749
1750
1751
1752
1753 for (i = 0; i < AHA1542_MAILBOXES; i++)
1754 if (HOSTDATA(SCpnt->host)->SCint[i] &&
1755 HOSTDATA(SCpnt->host)->SCint[i]->target == SCpnt->target) {
1756 Scsi_Cmnd *SCtmp;
1757 SCtmp = HOSTDATA(SCpnt->host)->SCint[i];
1758 SCtmp->result = DID_RESET << 16;
1759 if (SCtmp->host_scribble) {
1760 scsi_free(SCtmp->host_scribble, 512);
1761 SCtmp->host_scribble = NULL;
1762 }
1763 printk(KERN_WARNING "Sending DID_RESET for target %d\n", SCpnt->target);
1764 SCtmp->scsi_done(SCpnt);
1765
1766 HOSTDATA(SCpnt->host)->SCint[i] = NULL;
1767 HOSTDATA(SCpnt->host)->mb[i].status = 0;
1768 }
1769 return SCSI_RESET_SUCCESS;
1770 }
1771 }
1772
1773
1774
1775 return SCSI_RESET_PUNT;
1776}
1777
1778#include "sd.h"
1779
1780static int aha1542_biosparam(Scsi_Disk * disk, kdev_t dev, int *ip)
1781{
1782 int translation_algorithm;
1783 int size = disk->capacity;
1784
1785 translation_algorithm = HOSTDATA(disk->device->host)->bios_translation;
1786
1787 if ((size >> 11) > 1024 && translation_algorithm == BIOS_TRANSLATION_25563) {
1788
1789 ip[0] = 255;
1790 ip[1] = 63;
1791 ip[2] = size / 255 / 63;
1792 } else {
1793 ip[0] = 64;
1794 ip[1] = 32;
1795 ip[2] = size >> 11;
1796 }
1797
1798 return 0;
1799}
1800MODULE_LICENSE("GPL");
1801
1802
1803
1804static Scsi_Host_Template driver_template = AHA1542;
1805
1806#include "scsi_module.c"
1807