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