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