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