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