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