This source file includes following definitions.
- wait_on_busy
- do_dma
- read_pio
- port_detect
- eata2x_detect
- build_sg_list
- eata2x_queuecommand
- eata2x_abort
- eata2x_reset
- eata2x_interrupt_handler
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94 #if defined(MODULE)
95 #include <linux/module.h>
96 #include <linux/version.h>
97 #endif
98
99 #include <linux/string.h>
100 #include <linux/sched.h>
101 #include <linux/kernel.h>
102 #include <linux/ioport.h>
103 #include <asm/io.h>
104 #include <asm/system.h>
105 #include "../block/blk.h"
106 #include "scsi.h"
107 #include "hosts.h"
108 #include "sd.h"
109 #include <asm/dma.h>
110 #include <asm/irq.h>
111 #include "linux/in.h"
112 #include "eata.h"
113
114
115 #define ISA 0
116 #define ESA 1
117
118 #undef FORCE_CONFIG
119
120 #undef DEBUG_DETECT
121 #undef DEBUG_INTERRUPT
122 #undef DEBUG_STATISTICS
123
124 #define MAX_TARGET 8
125 #define MAX_IRQ 16
126 #define MAX_BOARDS 18
127 #define MAX_MAILBOXES 64
128 #define MAX_SGLIST 64
129 #define MAX_CMD_PER_LUN 2
130
131 #define FALSE 0
132 #define TRUE 1
133 #define FREE 0
134 #define IN_USE 1
135 #define LOCKED 2
136 #define IN_RESET 3
137 #define IGNORE 4
138 #define NO_IRQ 0xff
139 #define NO_DMA 0xff
140 #define MAXLOOP 200000
141
142 #define REG_CMD 7
143 #define REG_STATUS 7
144 #define REG_AUX_STATUS 8
145 #define REG_DATA 0
146 #define REG_DATA2 1
147 #define REG_SEE 6
148 #define REG_LOW 2
149 #define REG_LM 3
150 #define REG_MID 4
151 #define REG_MSB 5
152 #define REGION_SIZE 9
153 #define EISA_RANGE 0xf000
154 #define BSY_ASSERTED 0x80
155 #define DRQ_ASSERTED 0x08
156 #define ABSY_ASSERTED 0x01
157 #define IRQ_ASSERTED 0x02
158 #define READ_CONFIG_PIO 0xf0
159 #define SET_CONFIG_PIO 0xf1
160 #define SEND_CP_PIO 0xf2
161 #define RECEIVE_SP_PIO 0xf3
162 #define TRUNCATE_XFR_PIO 0xf4
163 #define RESET_PIO 0xf9
164 #define READ_CONFIG_DMA 0xfd
165 #define SET_CONFIG_DMA 0xfe
166 #define SEND_CP_DMA 0xff
167 #define ASOK 0x00
168 #define ASST 0x01
169
170
171 #define EATA_SIGNATURE 0x41544145
172
173
174 #define EATA_2_0A_SIZE 28
175 #define EATA_2_0B_SIZE 30
176
177
178 struct eata_info {
179 ulong data_len;
180 ulong sign;
181 unchar :4,
182 version:4;
183 unchar ocsena:1,
184 tarsup:1,
185 :2,
186 dmasup:1,
187 drqvld:1,
188 ata:1,
189 haaval:1;
190 ushort cp_pad_len;
191 unchar host_addr[3];
192 unchar reserved;
193 ulong cp_len;
194 ulong sp_len;
195 ushort queue_size;
196 ushort unused;
197 ushort scatt_size;
198 unchar irq:4,
199 irq_tr:1,
200 second:1,
201 drqx:2;
202 unchar sync;
203
204
205 unchar isaena:1,
206 forcaddr:1,
207 :6;
208 unchar max_id:5,
209 max_chan:3;
210
211 ushort ipad[249];
212 };
213
214
215 struct eata_config {
216 ushort len;
217 unchar edis:1,
218 ocena:1,
219 mdpena:1,
220 tarena:1,
221 :4;
222 unchar cpad[511];
223 };
224
225
226 struct mssp {
227 unchar adapter_status:7,
228 eoc:1;
229 unchar target_status;
230 unchar unused[2];
231 ulong inv_res_len;
232 Scsi_Cmnd *SCpnt;
233 char mess[12];
234 };
235
236
237 struct mscp {
238 unchar sreset:1,
239 init:1,
240 reqsen:1,
241 sg:1,
242 :1,
243 interp:1,
244 dout:1,
245 din:1;
246 unchar sense_len;
247 unchar unused[4];
248 unchar phsunit:1,
249 notused:7;
250 unchar target;
251 unchar lun:3,
252 :2,
253 luntar:1,
254 dispri:1,
255 one:1;
256 unchar mess[3];
257 unchar cdb[12];
258 ulong data_len;
259 Scsi_Cmnd *SCpnt;
260 ulong data_address;
261 ulong sp_addr;
262 ulong sense_addr;
263
264 struct sg_list {
265 unsigned int address;
266 unsigned int num_bytes;
267 } sglist[MAX_SGLIST];
268
269 unsigned int index;
270 };
271
272 struct hostdata {
273 struct mscp cp[MAX_MAILBOXES];
274 unsigned int cp_stat[MAX_MAILBOXES];
275 unsigned int last_cp_used;
276 unsigned int iocount;
277 unsigned int multicount;
278 int board_number;
279 char board_name[16];
280 char board_id[256];
281 int in_reset;
282 int target_time_out[MAX_TARGET];
283 int target_reset[MAX_TARGET];
284 unsigned char subversion;
285 unsigned char protocol_rev;
286 struct mssp sp[MAX_MAILBOXES];
287 };
288
289 static struct Scsi_Host * sh[MAX_BOARDS + 1];
290 static char* driver_name = "EATA";
291 static unsigned int irqlist[MAX_IRQ], calls[MAX_IRQ];
292
293 #define HD(board) ((struct hostdata *) &sh[board]->hostdata)
294 #define BN(board) (HD(board)->board_name)
295
296 static void eata2x_interrupt_handler(int, struct pt_regs *);
297 static int do_trace = FALSE;
298
299 static inline unchar wait_on_busy(ushort iobase) {
300 unsigned int loop = MAXLOOP;
301
302 while (inb(iobase + REG_AUX_STATUS) & ABSY_ASSERTED)
303 if (--loop == 0) return TRUE;
304
305 return FALSE;
306 }
307
308 static inline unchar do_dma (ushort iobase, unsigned int addr, unchar cmd) {
309
310 if (wait_on_busy(iobase)) return TRUE;
311
312 if (addr) {
313 outb((char) addr, iobase + REG_LOW);
314 outb((char) (addr >> 8), iobase + REG_LM);
315 outb((char) (addr >> 16), iobase + REG_MID);
316 outb((char) (addr >> 24), iobase + REG_MSB);
317 }
318
319 outb(cmd, iobase + REG_CMD);
320 return FALSE;
321 }
322
323 static inline unchar read_pio (ushort iobase, ushort *start, ushort *end) {
324 unsigned int loop = MAXLOOP;
325 ushort *p;
326
327 for (p = start; p <= end; p++) {
328
329 while (!(inb(iobase + REG_STATUS) & DRQ_ASSERTED))
330 if (--loop == 0) return TRUE;
331
332 loop = MAXLOOP;
333 *p = inw(iobase);
334 }
335
336 return FALSE;
337 }
338
339 static inline int port_detect(ushort *port_base, unsigned int j,
340 Scsi_Host_Template * tpnt) {
341 unsigned char irq, dma_channel, subversion;
342 unsigned char protocol_rev;
343 struct eata_info info;
344 char *board_status;
345
346
347 unsigned char dma_channel_table[4] = { 5, 6, 7, 0 };
348
349 char name[16];
350
351 sprintf(name, "%s%d", driver_name, j);
352
353 if(check_region(*port_base, REGION_SIZE)) {
354 printk("%s: address 0x%03x in use, skipping probe.\n",
355 name, *port_base);
356 return FALSE;
357 }
358
359 if (do_dma(*port_base, 0, READ_CONFIG_PIO)) return FALSE;
360
361
362 if (read_pio(*port_base, (ushort *)&info, (ushort *)&info.ipad[0]))
363 return FALSE;
364
365
366 if (info.sign != EATA_SIGNATURE) return FALSE;
367
368 if (ntohl(info.data_len) < EATA_2_0A_SIZE) {
369 printk("%s: config structure size (%ld bytes) too short, detaching.\n",
370 name, ntohl(info.data_len));
371 return FALSE;
372 }
373 else if (ntohl(info.data_len) == EATA_2_0A_SIZE)
374 protocol_rev = 'A';
375 else if (ntohl(info.data_len) == EATA_2_0B_SIZE)
376 protocol_rev = 'B';
377 else
378 protocol_rev = 'C';
379
380 if (protocol_rev != 'A' && info.max_chan > 0)
381 printk("%s: warning, only scsi channel 0 is supported.\n", name);
382
383 irq = info.irq;
384
385 if (*port_base & EISA_RANGE) {
386
387 if (!info.haaval || info.ata || info.drqvld || !info.dmasup) {
388 printk("%s: unusable EISA board found (%d%d%d%d), detaching.\n",
389 name, info.haaval, info.ata, info.drqvld, info.dmasup);
390 return FALSE;
391 }
392
393 subversion = ESA;
394 dma_channel = NO_DMA;
395 }
396 else {
397
398 if (!info.haaval || info.ata || !info.drqvld || !info.dmasup) {
399 printk("%s: unusable ISA board found (%d%d%d%d), detaching.\n",
400 name, info.haaval, info.ata, info.drqvld, info.dmasup);
401 return FALSE;
402 }
403
404 subversion = ISA;
405 dma_channel = dma_channel_table[3 - info.drqx];
406 }
407
408 if (subversion == ESA && !info.irq_tr)
409 printk("%s: warning, LEVEL triggering is suggested for IRQ %u.\n",
410 name, irq);
411
412 if (info.second)
413 board_status = "Sec.";
414 else
415 board_status = "Prim.";
416
417
418 if ((irq >= MAX_IRQ) || ((irqlist[irq] == NO_IRQ) && request_irq
419 (irq, eata2x_interrupt_handler, SA_INTERRUPT, driver_name))) {
420 printk("%s: unable to allocate IRQ %u, detaching.\n", name, irq);
421 return FALSE;
422 }
423
424 if (subversion == ISA && request_dma(dma_channel, driver_name)) {
425 printk("%s: unable to allocate DMA channel %u, detaching.\n",
426 name, dma_channel);
427 free_irq(irq);
428 return FALSE;
429 }
430
431 #if defined (FORCE_CONFIG)
432 {
433 struct eata_config config;
434
435
436 memset((char *)&config, 0, sizeof(struct eata_config));
437 config.len = (ushort) htons((ushort)510);
438 config.ocena = TRUE;
439
440 if (do_dma(*port_base, (unsigned int)&config, SET_CONFIG_DMA)) {
441 printk("%s: busy timeout sending configuration, detaching.\n", name);
442 return FALSE;
443 }
444 }
445 #endif
446
447 sh[j] = scsi_register(tpnt, sizeof(struct hostdata));
448 sh[j]->io_port = *port_base;
449 sh[j]->n_io_port = REGION_SIZE;
450 sh[j]->dma_channel = dma_channel;
451 sh[j]->irq = irq;
452 sh[j]->sg_tablesize = (ushort) ntohs(info.scatt_size);
453 sh[j]->this_id = (ushort) info.host_addr[3];
454 sh[j]->can_queue = (ushort) ntohs(info.queue_size);
455 sh[j]->cmd_per_lun = MAX_CMD_PER_LUN;
456
457
458 request_region(sh[j]->io_port, REGION_SIZE, driver_name);
459
460 memset(HD(j), 0, sizeof(struct hostdata));
461 HD(j)->subversion = subversion;
462 HD(j)->protocol_rev = protocol_rev;
463 HD(j)->board_number = j;
464 irqlist[irq] = j;
465
466 if (HD(j)->subversion == ESA)
467 sh[j]->unchecked_isa_dma = FALSE;
468 else {
469 sh[j]->block = sh[j];
470 sh[j]->unchecked_isa_dma = TRUE;
471 disable_dma(dma_channel);
472 clear_dma_ff(dma_channel);
473 set_dma_mode(dma_channel, DMA_MODE_CASCADE);
474 enable_dma(dma_channel);
475 }
476
477 strcpy(BN(j), name);
478
479 printk("%s: 2.0%c, %s, ID %d, PORT 0x%03x, IRQ %u, DMA %u, SG %d, "\
480 "Mbox %d, CmdLun %d.\n", BN(j), HD(j)->protocol_rev, board_status,
481 sh[j]->this_id, sh[j]->io_port, sh[j]->irq, sh[j]->dma_channel,
482 sh[j]->sg_tablesize, sh[j]->can_queue, sh[j]->cmd_per_lun);
483
484
485 if (sh[j]->sg_tablesize > MAX_SGLIST || sh[j]->sg_tablesize < 2) {
486 printk("%s: detect, forcing to use %d SG lists.\n", BN(j), MAX_SGLIST);
487 sh[j]->sg_tablesize = MAX_SGLIST;
488 }
489
490
491 if (sh[j]->can_queue > MAX_MAILBOXES || sh[j]->can_queue < 2) {
492 printk("%s: detect, forcing to use %d Mbox.\n", BN(j), MAX_MAILBOXES);
493 sh[j]->can_queue = MAX_MAILBOXES;
494 }
495
496 #if defined (DEBUG_DETECT)
497 if (protocol_rev != 'A')
498 printk("%s: EATA 2.0%c, isaena %u, forcaddr %u, max_id %u,"\
499 " max_chan %u.\n", name, protocol_rev, info.isaena,
500 info.forcaddr, info.max_id, info.max_chan);
501
502 printk("%s: Version 0x%x, SYNC 0x%x, infol %ld, cpl %ld spl %ld.\n",
503 name, info.version, info.sync, ntohl(info.data_len),
504 ntohl(info.cp_len), ntohl(info.sp_len));
505 #endif
506
507 return TRUE;
508 }
509
510 int eata2x_detect (Scsi_Host_Template * tpnt) {
511 unsigned int j = 0, k, flags;
512
513 ushort io_port[] = {
514 0x1c88, 0x2c88, 0x3c88, 0x4c88, 0x5c88, 0x6c88, 0x7c88, 0x8c88,
515 0x9c88, 0xac88, 0xbc88, 0xcc88, 0xdc88, 0xec88, 0xfc88,
516 0x1f0, 0x170, 0x330, 0x230, 0x0
517 };
518
519 ushort *port_base = io_port;
520
521 save_flags(flags);
522 cli();
523
524 for (k = 0; k < MAX_IRQ; k++) {
525 irqlist[k] = NO_IRQ;
526 calls[k] = 0;
527 }
528
529 for (k = 0; k < MAX_BOARDS + 1; k++) sh[k] = NULL;
530
531 while (*port_base) {
532
533 if (j < MAX_BOARDS && port_detect(port_base, j, tpnt)) j++;
534
535 port_base++;
536 }
537
538 if (j > 0)
539 printk("EATA/DMA 2.0x: Copyright (C) 1994, 1995 Dario Ballabio.\n");
540
541 restore_flags(flags);
542 return j;
543 }
544
545 static inline void build_sg_list(struct mscp *cpp, Scsi_Cmnd *SCpnt) {
546 unsigned int k;
547 struct scatterlist * sgpnt;
548
549 sgpnt = (struct scatterlist *) SCpnt->request_buffer;
550
551 for (k = 0; k < SCpnt->use_sg; k++) {
552 cpp->sglist[k].address = htonl((unsigned int) sgpnt[k].address);
553 cpp->sglist[k].num_bytes = htonl((unsigned int) sgpnt[k].length);
554 }
555
556 cpp->data_address = htonl((unsigned int) cpp->sglist);
557 cpp->data_len = htonl((SCpnt->use_sg * sizeof(struct sg_list)));
558 }
559
560 int eata2x_queuecommand (Scsi_Cmnd *SCpnt, void (*done)(Scsi_Cmnd *)) {
561 unsigned int i, j, k, flags;
562 struct mscp *cpp;
563 struct mssp *spp;
564
565 save_flags(flags);
566 cli();
567
568 j = ((struct hostdata *) SCpnt->host->hostdata)->board_number;
569
570 if (!done) panic("%s: qcomm, pid %ld, null done.\n", BN(j), SCpnt->pid);
571
572
573
574 i = HD(j)->last_cp_used + 1;
575
576 for (k = 0; k < sh[j]->can_queue; k++, i++) {
577
578 if (i >= sh[j]->can_queue) i = 0;
579
580 if (HD(j)->cp_stat[i] == FREE) {
581 HD(j)->last_cp_used = i;
582 break;
583 }
584 }
585
586 if (k == sh[j]->can_queue) {
587 printk("%s: qcomm, no free mailbox, resetting.\n", BN(j));
588
589 if (HD(j)->in_reset)
590 printk("%s: qcomm, already in reset.\n", BN(j));
591 else if (eata2x_reset(SCpnt) == SCSI_RESET_SUCCESS)
592 panic("%s: qcomm, SCSI_RESET_SUCCESS.\n", BN(j));
593
594 SCpnt->result = DID_BUS_BUSY << 16;
595 SCpnt->host_scribble = NULL;
596 printk("%s: qcomm, pid %ld, DID_BUS_BUSY, done.\n", BN(j), SCpnt->pid);
597 restore_flags(flags);
598 done(SCpnt);
599 return 0;
600 }
601
602
603 cpp = &HD(j)->cp[i];
604
605 memset(cpp, 0, sizeof(struct mscp));
606
607
608 spp = &HD(j)->sp[i];
609
610 memset(spp, 0, sizeof(struct mssp));
611
612
613 cpp->sp_addr = htonl((unsigned int) spp);
614
615 SCpnt->scsi_done = done;
616 cpp->index = i;
617 SCpnt->host_scribble = (unsigned char *) &cpp->index;
618
619 if (do_trace) printk("%s: qcomm, mbox %d, target %d, pid %ld.\n",
620 BN(j), i, SCpnt->target, SCpnt->pid);
621
622 if (SCpnt->cmnd[0] == WRITE_10 || SCpnt->cmnd[0] == WRITE_6)
623 cpp->dout = TRUE;
624 else
625 cpp->din = TRUE;
626
627 cpp->reqsen = TRUE;
628 cpp->dispri = TRUE;
629 cpp->one = TRUE;
630 cpp->target = SCpnt->target;
631 cpp->lun = SCpnt->lun;
632 cpp->SCpnt = SCpnt;
633 cpp->sense_addr = htonl((unsigned int) SCpnt->sense_buffer);
634 cpp->sense_len = sizeof SCpnt->sense_buffer;
635
636 if (SCpnt->use_sg) {
637 cpp->sg = TRUE;
638 build_sg_list(cpp, SCpnt);
639 }
640 else {
641 cpp->data_address = htonl((unsigned int) SCpnt->request_buffer);
642 cpp->data_len = htonl(SCpnt->request_bufflen);
643 }
644
645 memcpy(cpp->cdb, SCpnt->cmnd, SCpnt->cmd_len);
646
647
648 if (do_dma(sh[j]->io_port, (unsigned int) cpp, SEND_CP_DMA)) {
649 SCpnt->result = DID_ERROR << 16;
650 SCpnt->host_scribble = NULL;
651 printk("%s: qcomm, target %d, pid %ld, adapter busy, DID_ERROR, done.\n",
652 BN(j), SCpnt->target, SCpnt->pid);
653 restore_flags(flags);
654 done(SCpnt);
655 return 0;
656 }
657
658 HD(j)->cp_stat[i] = IN_USE;
659 restore_flags(flags);
660 return 0;
661 }
662
663 int eata2x_abort (Scsi_Cmnd *SCarg) {
664 unsigned int i, j, flags;
665
666 save_flags(flags);
667 cli();
668 j = ((struct hostdata *) SCarg->host->hostdata)->board_number;
669
670 if (SCarg->host_scribble == NULL) {
671 printk("%s: abort, target %d, pid %ld inactive.\n",
672 BN(j), SCarg->target, SCarg->pid);
673 return SCSI_ABORT_NOT_RUNNING;
674 }
675
676 i = *(unsigned int *)SCarg->host_scribble;
677 printk("%s: abort, mbox %d, target %d, pid %ld.\n",
678 BN(j), i, SCarg->target, SCarg->pid);
679
680 if (i >= sh[j]->can_queue)
681 panic("%s: abort, invalid SCarg->host_scribble.\n", BN(j));
682
683 if (wait_on_busy(sh[j]->io_port)) {
684 printk("%s: abort, timeout error.\n", BN(j));
685 restore_flags(flags);
686 return SCSI_ABORT_ERROR;
687 }
688
689 if (HD(j)->cp_stat[i] == FREE) {
690 printk("%s: abort, mbox %d is free.\n", BN(j), i);
691 restore_flags(flags);
692 return SCSI_ABORT_NOT_RUNNING;
693 }
694
695 if (HD(j)->cp_stat[i] == IN_USE) {
696 printk("%s: abort, mbox %d is in use.\n", BN(j), i);
697
698 if (SCarg != HD(j)->cp[i].SCpnt)
699 panic("%s: abort, mbox %d, SCarg %p, cp SCpnt %p.\n",
700 BN(j), i, SCarg, HD(j)->cp[i].SCpnt);
701
702 restore_flags(flags);
703 return SCSI_ABORT_SNOOZE;
704 }
705
706 if (HD(j)->cp_stat[i] == IN_RESET) {
707 printk("%s: abort, mbox %d is in reset.\n", BN(j), i);
708 restore_flags(flags);
709 return SCSI_ABORT_ERROR;
710 }
711
712 if (HD(j)->cp_stat[i] == LOCKED) {
713 printk("%s: abort, mbox %d is locked.\n", BN(j), i);
714 restore_flags(flags);
715 return SCSI_ABORT_NOT_RUNNING;
716 }
717 else
718 panic("%s: abort, mbox %d, invalid cp_stat.\n", BN(j), i);
719 }
720
721 int eata2x_reset (Scsi_Cmnd *SCarg) {
722 unsigned int i, j, flags, time, k, limit = 0;
723 int arg_done = FALSE;
724 Scsi_Cmnd *SCpnt;
725
726 save_flags(flags);
727 cli();
728 j = ((struct hostdata *) SCarg->host->hostdata)->board_number;
729 printk("%s: reset, enter, target %d, pid %ld.\n",
730 BN(j), SCarg->target, SCarg->pid);
731
732 if (SCarg->host_scribble == NULL)
733 printk("%s: reset, pid %ld inactive.\n", BN(j), SCarg->pid);
734
735 if (HD(j)->in_reset) {
736 printk("%s: reset, exit, already in reset.\n", BN(j));
737 restore_flags(flags);
738 return SCSI_RESET_ERROR;
739 }
740
741 if (wait_on_busy(sh[j]->io_port)) {
742 printk("%s: reset, exit, timeout error.\n", BN(j));
743 restore_flags(flags);
744 return SCSI_RESET_ERROR;
745 }
746
747 for (k = 0; k < MAX_TARGET; k++) HD(j)->target_reset[k] = TRUE;
748
749 for (k = 0; k < MAX_TARGET; k++) HD(j)->target_time_out[k] = 0;
750
751 for (i = 0; i < sh[j]->can_queue; i++) {
752
753 if (HD(j)->cp_stat[i] == FREE) continue;
754
755 if (HD(j)->cp_stat[i] == LOCKED) {
756 HD(j)->cp_stat[i] = FREE;
757 printk("%s: reset, locked mbox %d forced free.\n", BN(j), i);
758 continue;
759 }
760
761 SCpnt = HD(j)->cp[i].SCpnt;
762 HD(j)->cp_stat[i] = IN_RESET;
763 printk("%s: reset, mbox %d in reset, pid %ld.\n",
764 BN(j), i, SCpnt->pid);
765
766 if (SCpnt == NULL)
767 panic("%s: reset, mbox %d, SCpnt == NULL.\n", BN(j), i);
768
769 if (SCpnt->host_scribble == NULL)
770 panic("%s: reset, mbox %d, garbled SCpnt.\n", BN(j), i);
771
772 if (*(unsigned int *)SCpnt->host_scribble != i)
773 panic("%s: reset, mbox %d, index mismatch.\n", BN(j), i);
774
775 if (SCpnt->scsi_done == NULL)
776 panic("%s: reset, mbox %d, SCpnt->scsi_done == NULL.\n", BN(j), i);
777
778 if (SCpnt == SCarg) arg_done = TRUE;
779 }
780
781 if (do_dma(sh[j]->io_port, 0, RESET_PIO)) {
782 printk("%s: reset, cannot reset, timeout error.\n", BN(j));
783 restore_flags(flags);
784 return SCSI_RESET_ERROR;
785 }
786
787 printk("%s: reset, board reset done, enabling interrupts.\n", BN(j));
788 do_trace = TRUE;
789 HD(j)->in_reset = TRUE;
790 sti();
791 time = jiffies;
792 while (jiffies < (time + 100) && limit++ < 100000000);
793 cli();
794 printk("%s: reset, interrupts disabled, loops %d.\n", BN(j), limit);
795
796 for (i = 0; i < sh[j]->can_queue; i++) {
797
798
799 if (HD(j)->cp_stat[i] != IN_RESET) continue;
800
801 SCpnt = HD(j)->cp[i].SCpnt;
802 SCpnt->result = DID_RESET << 16;
803 SCpnt->host_scribble = NULL;
804
805
806 HD(j)->cp_stat[i] = LOCKED;
807
808 printk("%s, reset, mbox %d locked, DID_RESET, pid %ld done.\n",
809 BN(j), i, SCpnt->pid);
810 restore_flags(flags);
811 SCpnt->scsi_done(SCpnt);
812 cli();
813 }
814
815 HD(j)->in_reset = FALSE;
816 do_trace = FALSE;
817 restore_flags(flags);
818
819 if (arg_done) {
820 printk("%s: reset, exit, success.\n", BN(j));
821 return SCSI_RESET_SUCCESS;
822 }
823 else {
824 printk("%s: reset, exit, wakeup.\n", BN(j));
825 return SCSI_RESET_PUNT;
826 }
827 }
828
829 static void eata2x_interrupt_handler(int irq, struct pt_regs * regs) {
830 Scsi_Cmnd *SCpnt;
831 unsigned int i, j, k, flags, status, tstatus, loops, total_loops = 0;
832 struct mssp *spp;
833 struct mscp *cpp;
834
835 save_flags(flags);
836 cli();
837
838 if (irqlist[irq] == NO_IRQ) {
839 printk("%s, ihdlr, irq %d, unexpected interrupt.\n", driver_name, irq);
840 restore_flags(flags);
841 return;
842 }
843
844 if (do_trace) printk("%s: ihdlr, enter, irq %d, calls %d.\n",
845 driver_name, irq, calls[irq]);
846
847
848 for (j = 0; sh[j] != NULL; j++) {
849
850 if (sh[j]->irq != irq) continue;
851
852 loops = 0;
853
854
855 while (inb(sh[j]->io_port + REG_AUX_STATUS) & IRQ_ASSERTED) {
856 total_loops++;
857 loops++;
858
859 if (do_trace) printk("%s: ihdlr, start service, count %d.\n",
860 BN(j), HD(j)->iocount);
861
862
863 inb(sh[j]->io_port + REG_STATUS);
864
865
866 for (i = 0; i < sh[j]->can_queue; i++) {
867 spp = &HD(j)->sp[i];
868
869
870 if (spp->eoc == FALSE) continue;
871
872 spp->eoc = FALSE;
873
874 if (HD(j)->cp_stat[i] == IGNORE) {
875 HD(j)->cp_stat[i] = FREE;
876 continue;
877 }
878 else if (HD(j)->cp_stat[i] == LOCKED) {
879 HD(j)->cp_stat[i] = FREE;
880 printk("%s: ihdlr, mbox %d unlocked, count %d.\n",
881 BN(j), i, HD(j)->iocount);
882 continue;
883 }
884 else if (HD(j)->cp_stat[i] == FREE) {
885 printk("%s: ihdlr, mbox %d is free, count %d.\n",
886 BN(j), i, HD(j)->iocount);
887 continue;
888 }
889 else if (HD(j)->cp_stat[i] == IN_RESET)
890 printk("%s: ihdlr, mbox %d is in reset.\n", BN(j), i);
891 else if (HD(j)->cp_stat[i] != IN_USE)
892 panic("%s: ihdlr, mbox %d, invalid cp_stat.\n", BN(j), i);
893
894 HD(j)->cp_stat[i] = FREE;
895 cpp = &HD(j)->cp[i];
896 SCpnt = spp->SCpnt;
897
898 if (SCpnt == NULL)
899 panic("%s: ihdlr, mbox %d, SCpnt == NULL.\n", BN(j), i);
900
901 if (SCpnt != cpp->SCpnt)
902 panic("%s: ihdlr, mbox %d, sp SCpnt %p, cp SCpnt %p.\n",
903 BN(j), i, SCpnt, cpp->SCpnt);
904
905 if (SCpnt->host_scribble == NULL)
906 panic("%s: ihdlr, mbox %d, pid %ld, SCpnt %p garbled.\n",
907 BN(j), i, SCpnt->pid, SCpnt);
908
909 if (*(unsigned int *)SCpnt->host_scribble != i)
910 panic("%s: ihdlr, mbox %d, pid %ld, index mismatch %d,"\
911 " irq %d.\n", BN(j), i, SCpnt->pid,
912 *(unsigned int *)SCpnt->host_scribble, irq);
913
914 tstatus = status_byte(spp->target_status);
915
916 switch (spp->adapter_status) {
917 case ASOK:
918
919
920 if (tstatus == BUSY && SCpnt->device->type != TYPE_TAPE)
921 status = DID_ERROR << 16;
922
923
924 else if (tstatus != GOOD
925 && SCpnt->device->type == TYPE_DISK
926 && HD(j)->target_reset[SCpnt->target])
927 status = DID_BUS_BUSY << 16;
928
929
930 else if (tstatus == CHECK_CONDITION
931 && SCpnt->device->type == TYPE_DISK
932 && (SCpnt->sense_buffer[2] & 0xf) == RECOVERED_ERROR)
933 status = DID_BUS_BUSY << 16;
934
935 else if (tstatus == CHECK_CONDITION
936 && SCpnt->device->type == TYPE_DISK
937 && (SCpnt->sense_buffer[2] & 0xf) == UNIT_ATTENTION)
938 status = DID_ERROR << 16;
939
940 else
941 status = DID_OK << 16;
942
943 if (tstatus == GOOD)
944 HD(j)->target_reset[SCpnt->target] = FALSE;
945
946 if (spp->target_status && SCpnt->device->type == TYPE_DISK)
947 printk("%s: ihdlr, target %d:%d, pid %ld, target_status "\
948 "0x%x, sense key 0x%x.\n", BN(j),
949 SCpnt->target, SCpnt->lun, SCpnt->pid,
950 spp->target_status, SCpnt->sense_buffer[2]);
951
952 HD(j)->target_time_out[SCpnt->target] = 0;
953
954 break;
955 case ASST:
956 case 0x02:
957
958 if (HD(j)->target_time_out[SCpnt->target] > 1)
959 status = DID_ERROR << 16;
960 else {
961 status = DID_TIME_OUT << 16;
962 HD(j)->target_time_out[SCpnt->target]++;
963 }
964
965 break;
966 case 0x03:
967 case 0x04:
968
969 if (SCpnt->device->type != TYPE_TAPE)
970 status = DID_BUS_BUSY << 16;
971 else
972 status = DID_ERROR << 16;
973
974 for (k = 0; k < MAX_TARGET; k++)
975 HD(j)->target_reset[k] = TRUE;
976
977 break;
978 case 0x07:
979 case 0x0c:
980 case 0x05:
981 case 0x06:
982 case 0x08:
983 case 0x09:
984 case 0x0a:
985 case 0x0b:
986 default:
987 status = DID_ERROR << 16;
988 break;
989 }
990
991 SCpnt->result = status | spp->target_status;
992 HD(j)->iocount++;
993
994 if (loops > 1) HD(j)->multicount++;
995
996 #if defined (DEBUG_INTERRUPT)
997 if (SCpnt->result || do_trace)
998 #else
999 if ((spp->adapter_status != ASOK && HD(j)->iocount > 1000) ||
1000 (spp->adapter_status != ASOK &&
1001 spp->adapter_status != ASST && HD(j)->iocount <= 1000) ||
1002 do_trace)
1003 #endif
1004 printk("%s: ihdlr, mbox %d, err 0x%x:%x,"\
1005 " target %d:%d, pid %ld, count %d.\n",
1006 BN(j), i, spp->adapter_status, spp->target_status,
1007 SCpnt->target, SCpnt->lun, SCpnt->pid, HD(j)->iocount);
1008
1009
1010 SCpnt->host_scribble = NULL;
1011
1012 restore_flags(flags);
1013 SCpnt->scsi_done(SCpnt);
1014 cli();
1015
1016 }
1017
1018 }
1019
1020 }
1021
1022 calls[irq]++;
1023
1024 if (total_loops == 0)
1025 printk("%s: ihdlr, irq %d, no command completed, calls %d.\n",
1026 driver_name, irq, calls[irq]);
1027
1028 if (do_trace) printk("%s: ihdlr, exit, irq %d, calls %d.\n",
1029 driver_name, irq, calls[irq]);
1030
1031 #if defined (DEBUG_STATISTICS)
1032 if ((calls[irq] % 100000) == 10000)
1033 for (j = 0; sh[j] != NULL; j++)
1034 printk("%s: ihdlr, calls %d, count %d, multi %d.\n", BN(j),
1035 calls[(sh[j]->irq)], HD(j)->iocount, HD(j)->multicount);
1036 #endif
1037
1038 restore_flags(flags);
1039 return;
1040 }
1041
1042 #if defined(MODULE)
1043 Scsi_Host_Template driver_template = EATA;
1044
1045 #include "scsi_module.c"
1046 #endif