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