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