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