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 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 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 return SCSI_ABORT_NOT_RUNNING;
719 }
720
721 i = *(unsigned int *)SCarg->host_scribble;
722 printk("%s: abort, mbox %d, target %d, pid %ld.\n",
723 BN(j), i, SCarg->target, SCarg->pid);
724
725 if (i >= sh[j]->can_queue)
726 panic("%s: abort, invalid SCarg->host_scribble.\n", BN(j));
727
728 if (wait_on_busy(sh[j]->io_port)) {
729 printk("%s: abort, timeout error.\n", BN(j));
730 restore_flags(flags);
731 return SCSI_ABORT_ERROR;
732 }
733
734 if (HD(j)->cp_stat[i] == FREE) {
735 printk("%s: abort, mbox %d is free.\n", BN(j), i);
736 restore_flags(flags);
737 return SCSI_ABORT_NOT_RUNNING;
738 }
739
740 if (HD(j)->cp_stat[i] == IN_USE) {
741 printk("%s: abort, mbox %d is in use.\n", BN(j), i);
742
743 if (SCarg != HD(j)->cp[i].SCpnt)
744 panic("%s: abort, mbox %d, SCarg %p, cp SCpnt %p.\n",
745 BN(j), i, SCarg, HD(j)->cp[i].SCpnt);
746
747 restore_flags(flags);
748 return SCSI_ABORT_SNOOZE;
749 }
750
751 if (HD(j)->cp_stat[i] == IN_RESET) {
752 printk("%s: abort, mbox %d is in reset.\n", BN(j), i);
753 restore_flags(flags);
754 return SCSI_ABORT_ERROR;
755 }
756
757 if (HD(j)->cp_stat[i] == LOCKED) {
758 printk("%s: abort, mbox %d is locked.\n", BN(j), i);
759 restore_flags(flags);
760 return SCSI_ABORT_NOT_RUNNING;
761 }
762 else
763 panic("%s: abort, mbox %d, invalid cp_stat.\n", BN(j), i);
764 }
765
766 int eata2x_reset (Scsi_Cmnd *SCarg) {
767 unsigned int i, j, flags, time, k, limit = 0;
768 int arg_done = FALSE;
769 Scsi_Cmnd *SCpnt;
770
771 save_flags(flags);
772 cli();
773 j = ((struct hostdata *) SCarg->host->hostdata)->board_number;
774 printk("%s: reset, enter, target %d, pid %ld.\n",
775 BN(j), SCarg->target, SCarg->pid);
776
777 if (SCarg->host_scribble == NULL)
778 printk("%s: reset, pid %ld inactive.\n", BN(j), SCarg->pid);
779
780 if (HD(j)->in_reset) {
781 printk("%s: reset, exit, already in reset.\n", BN(j));
782 restore_flags(flags);
783 return SCSI_RESET_ERROR;
784 }
785
786 if (wait_on_busy(sh[j]->io_port)) {
787 printk("%s: reset, exit, timeout error.\n", BN(j));
788 restore_flags(flags);
789 return SCSI_RESET_ERROR;
790 }
791
792 for (k = 0; k < MAX_TARGET; k++) HD(j)->target_reset[k] = TRUE;
793
794 for (k = 0; k < MAX_TARGET; k++) HD(j)->target_time_out[k] = 0;
795
796 for (i = 0; i < sh[j]->can_queue; i++) {
797
798 if (HD(j)->cp_stat[i] == FREE) continue;
799
800 if (HD(j)->cp_stat[i] == LOCKED) {
801 HD(j)->cp_stat[i] = FREE;
802 printk("%s: reset, locked mbox %d forced free.\n", BN(j), i);
803 continue;
804 }
805
806 SCpnt = HD(j)->cp[i].SCpnt;
807 HD(j)->cp_stat[i] = IN_RESET;
808 printk("%s: reset, mbox %d in reset, pid %ld.\n",
809 BN(j), i, SCpnt->pid);
810
811 if (SCpnt == NULL)
812 panic("%s: reset, mbox %d, SCpnt == NULL.\n", BN(j), i);
813
814 if (SCpnt->host_scribble == NULL)
815 panic("%s: reset, mbox %d, garbled SCpnt.\n", BN(j), i);
816
817 if (*(unsigned int *)SCpnt->host_scribble != i)
818 panic("%s: reset, mbox %d, index mismatch.\n", BN(j), i);
819
820 if (SCpnt->scsi_done == NULL)
821 panic("%s: reset, mbox %d, SCpnt->scsi_done == NULL.\n", BN(j), i);
822
823 if (SCpnt == SCarg) arg_done = TRUE;
824 }
825
826 if (do_dma(sh[j]->io_port, 0, RESET_PIO)) {
827 printk("%s: reset, cannot reset, timeout error.\n", BN(j));
828 restore_flags(flags);
829 return SCSI_RESET_ERROR;
830 }
831
832 printk("%s: reset, board reset done, enabling interrupts.\n", BN(j));
833
834 #if defined (DEBUG_RESET)
835 do_trace = TRUE;
836 #endif
837
838 HD(j)->in_reset = TRUE;
839 sti();
840 time = jiffies;
841 while (jiffies < (time + 100) && limit++ < 100000000);
842 cli();
843 printk("%s: reset, interrupts disabled, loops %d.\n", BN(j), limit);
844
845 for (i = 0; i < sh[j]->can_queue; i++) {
846
847
848 if (HD(j)->cp_stat[i] != IN_RESET) continue;
849
850 SCpnt = HD(j)->cp[i].SCpnt;
851 SCpnt->result = DID_RESET << 16;
852 SCpnt->host_scribble = NULL;
853
854
855 HD(j)->cp_stat[i] = LOCKED;
856
857 printk("%s, reset, mbox %d locked, DID_RESET, pid %ld done.\n",
858 BN(j), i, SCpnt->pid);
859 restore_flags(flags);
860 SCpnt->scsi_done(SCpnt);
861 cli();
862 }
863
864 HD(j)->in_reset = FALSE;
865 do_trace = FALSE;
866 restore_flags(flags);
867
868 if (arg_done) {
869 printk("%s: reset, exit, success.\n", BN(j));
870 return SCSI_RESET_SUCCESS;
871 }
872 else {
873 printk("%s: reset, exit, wakeup.\n", BN(j));
874 return SCSI_RESET_PUNT;
875 }
876 }
877
878 static void eata2x_interrupt_handler(int irq, struct pt_regs * regs) {
879 Scsi_Cmnd *SCpnt;
880 unsigned int i, j, k, flags, status, tstatus, loops, total_loops = 0;
881 struct mssp *spp;
882 struct mscp *cpp;
883
884 save_flags(flags);
885 cli();
886
887 if (irqlist[irq] == NO_IRQ) {
888 printk("%s, ihdlr, irq %d, unexpected interrupt.\n", driver_name, irq);
889 restore_flags(flags);
890 return;
891 }
892
893 if (do_trace) printk("%s: ihdlr, enter, irq %d, calls %d.\n",
894 driver_name, irq, calls[irq]);
895
896
897 for (j = 0; sh[j] != NULL; j++) {
898
899 if (sh[j]->irq != irq) continue;
900
901 loops = 0;
902
903
904 while (inb(sh[j]->io_port + REG_AUX_STATUS) & IRQ_ASSERTED) {
905 total_loops++;
906 loops++;
907
908 if (do_trace) printk("%s: ihdlr, start service, count %d.\n",
909 BN(j), HD(j)->iocount);
910
911
912 inb(sh[j]->io_port + REG_STATUS);
913
914
915 for (i = 0; i < sh[j]->can_queue; i++) {
916 spp = &HD(j)->sp[i];
917
918
919 if (spp->eoc == FALSE) continue;
920
921 spp->eoc = FALSE;
922
923 if (HD(j)->cp_stat[i] == IGNORE) {
924 HD(j)->cp_stat[i] = FREE;
925 continue;
926 }
927 else if (HD(j)->cp_stat[i] == LOCKED) {
928 HD(j)->cp_stat[i] = FREE;
929 printk("%s: ihdlr, mbox %d unlocked, count %d.\n",
930 BN(j), i, HD(j)->iocount);
931 continue;
932 }
933 else if (HD(j)->cp_stat[i] == FREE) {
934 printk("%s: ihdlr, mbox %d is free, count %d.\n",
935 BN(j), i, HD(j)->iocount);
936 continue;
937 }
938 else if (HD(j)->cp_stat[i] == IN_RESET)
939 printk("%s: ihdlr, mbox %d is in reset.\n", BN(j), i);
940 else if (HD(j)->cp_stat[i] != IN_USE)
941 panic("%s: ihdlr, mbox %d, invalid cp_stat.\n", BN(j), i);
942
943 HD(j)->cp_stat[i] = FREE;
944 cpp = &HD(j)->cp[i];
945 SCpnt = spp->SCpnt;
946
947 if (SCpnt == NULL)
948 panic("%s: ihdlr, mbox %d, SCpnt == NULL.\n", BN(j), i);
949
950 if (SCpnt != cpp->SCpnt)
951 panic("%s: ihdlr, mbox %d, sp SCpnt %p, cp SCpnt %p.\n",
952 BN(j), i, SCpnt, cpp->SCpnt);
953
954 if (SCpnt->host_scribble == NULL)
955 panic("%s: ihdlr, mbox %d, pid %ld, SCpnt %p garbled.\n",
956 BN(j), i, SCpnt->pid, SCpnt);
957
958 if (*(unsigned int *)SCpnt->host_scribble != i)
959 panic("%s: ihdlr, mbox %d, pid %ld, index mismatch %d,"\
960 " irq %d.\n", BN(j), i, SCpnt->pid,
961 *(unsigned int *)SCpnt->host_scribble, irq);
962
963 tstatus = status_byte(spp->target_status);
964
965 switch (spp->adapter_status) {
966 case ASOK:
967
968
969 if (tstatus == BUSY && SCpnt->device->type != TYPE_TAPE)
970 status = DID_ERROR << 16;
971
972
973 else if (tstatus != GOOD
974 && SCpnt->device->type == TYPE_DISK
975 && HD(j)->target_reset[SCpnt->target])
976 status = DID_BUS_BUSY << 16;
977
978
979 else if (tstatus == CHECK_CONDITION
980 && SCpnt->device->type == TYPE_DISK
981 && (SCpnt->sense_buffer[2] & 0xf) == RECOVERED_ERROR)
982 status = DID_BUS_BUSY << 16;
983
984 else
985 status = DID_OK << 16;
986
987 if (tstatus == GOOD)
988 HD(j)->target_reset[SCpnt->target] = FALSE;
989
990 if (spp->target_status && SCpnt->device->type == TYPE_DISK)
991 printk("%s: ihdlr, target %d:%d, pid %ld, target_status "\
992 "0x%x, sense key 0x%x.\n", BN(j),
993 SCpnt->target, SCpnt->lun, SCpnt->pid,
994 spp->target_status, SCpnt->sense_buffer[2]);
995
996 HD(j)->target_time_out[SCpnt->target] = 0;
997
998 break;
999 case ASST:
1000 case 0x02:
1001
1002 if (HD(j)->target_time_out[SCpnt->target] > 1)
1003 status = DID_ERROR << 16;
1004 else {
1005 status = DID_TIME_OUT << 16;
1006 HD(j)->target_time_out[SCpnt->target]++;
1007 }
1008
1009 break;
1010 case 0x03:
1011 case 0x04:
1012
1013 if (SCpnt->device->type != TYPE_TAPE)
1014 status = DID_BUS_BUSY << 16;
1015 else
1016 status = DID_ERROR << 16;
1017
1018 for (k = 0; k < MAX_TARGET; k++)
1019 HD(j)->target_reset[k] = TRUE;
1020
1021 break;
1022 case 0x07:
1023 case 0x0c:
1024 case 0x05:
1025 case 0x06:
1026 case 0x08:
1027 case 0x09:
1028 case 0x0a:
1029 case 0x0b:
1030 default:
1031 status = DID_ERROR << 16;
1032 break;
1033 }
1034
1035 SCpnt->result = status | spp->target_status;
1036 HD(j)->iocount++;
1037
1038 if (loops > 1) HD(j)->multicount++;
1039
1040 #if defined (DEBUG_INTERRUPT)
1041 if (SCpnt->result || do_trace)
1042 #else
1043 if ((spp->adapter_status != ASOK && HD(j)->iocount > 1000) ||
1044 (spp->adapter_status != ASOK &&
1045 spp->adapter_status != ASST && HD(j)->iocount <= 1000) ||
1046 do_trace)
1047 #endif
1048 printk("%s: ihdlr, mbox %d, err 0x%x:%x,"\
1049 " target %d:%d, pid %ld, count %d.\n",
1050 BN(j), i, spp->adapter_status, spp->target_status,
1051 SCpnt->target, SCpnt->lun, SCpnt->pid, HD(j)->iocount);
1052
1053
1054 SCpnt->host_scribble = NULL;
1055
1056 restore_flags(flags);
1057 SCpnt->scsi_done(SCpnt);
1058 cli();
1059
1060 }
1061
1062 }
1063
1064 }
1065
1066 calls[irq]++;
1067
1068 if (total_loops == 0)
1069 printk("%s: ihdlr, irq %d, no command completed, calls %d.\n",
1070 driver_name, irq, calls[irq]);
1071
1072 if (do_trace) printk("%s: ihdlr, exit, irq %d, calls %d.\n",
1073 driver_name, irq, calls[irq]);
1074
1075 #if defined (DEBUG_STATISTICS)
1076 if ((calls[irq] % 100000) == 10000)
1077 for (j = 0; sh[j] != NULL; j++)
1078 printk("%s: ihdlr, calls %d, count %d, multi %d.\n", BN(j),
1079 calls[(sh[j]->irq)], HD(j)->iocount, HD(j)->multicount);
1080 #endif
1081
1082 restore_flags(flags);
1083 return;
1084 }
1085
1086 #if defined(MODULE)
1087 Scsi_Host_Template driver_template = EATA;
1088
1089 #include "scsi_module.c"
1090 #endif