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