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 #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 static inline void build_sg_list(struct mscp *cpp, Scsi_Cmnd *SCpnt) {
371 unsigned int k;
372 struct scatterlist * sgpnt;
373
374 sgpnt = (struct scatterlist *) SCpnt->request_buffer;
375
376 for(k = 0; k < SCpnt->use_sg; k++) {
377 cpp->sglist[k].address = htonl((unsigned int) sgpnt[k].address);
378 cpp->sglist[k].num_bytes = htonl((unsigned int) sgpnt[k].length);
379 }
380
381 cpp->data_address = htonl((unsigned int) cpp->sglist);
382 cpp->data_len = htonl((SCpnt->use_sg * sizeof(struct sg_list)));
383 }
384
385 int eata_queuecommand (Scsi_Cmnd *SCpnt, void (*done)(Scsi_Cmnd *)) {
386 unsigned int i, j, k, flags;
387 struct mscp *cpp;
388 struct mssp *spp;
389
390 save_flags(flags);
391 cli();
392
393 j = ((struct hostdata *) SCpnt->host->hostdata)->board_number;
394
395 if (!done) panic("%s: qcomm, pid %ld, null done.\n", BN(j), SCpnt->pid);
396
397
398
399 i = HD(j)->last_cp_used + 1;
400
401 for(k = 0; k < sh[j]->can_queue; k++, i++) {
402
403 if (i >= sh[j]->can_queue) i = 0;
404
405 if (HD(j)->cp_stat[i] == FREE) {
406 HD(j)->last_cp_used = i;
407 break;
408 }
409 }
410
411 if (k == sh[j]->can_queue) {
412 printk("%s: qcomm, no free mailbox, resetting.\n", BN(j));
413
414 if (HD(j)->in_reset)
415 printk("%s: qcomm, already in reset.\n", BN(j));
416 else if (eata_reset(SCpnt) == SCSI_RESET_SUCCESS)
417 panic("%s: qcomm, SCSI_RESET_SUCCESS.\n", BN(j));
418
419 SCpnt->result = DID_BUS_BUSY << 16;
420 SCpnt->host_scribble = NULL;
421 printk("%s: qcomm, pid %ld, DID_BUS_BUSY, done.\n", BN(j), SCpnt->pid);
422 restore_flags(flags);
423 done(SCpnt);
424 return 0;
425 }
426
427
428 cpp = &HD(j)->cp[i];
429
430 memset(cpp, 0, sizeof(struct mscp));
431
432
433 spp = &HD(j)->sp[i];
434
435 memset(spp, 0, sizeof(struct mssp));
436
437
438 cpp->sp_addr = htonl((unsigned int) spp);
439
440 SCpnt->scsi_done = done;
441 cpp->index = i;
442 SCpnt->host_scribble = (unsigned char *) &cpp->index;
443
444 if (do_trace) printk("%s: qcomm, mbox %d, target %d, pid %ld.\n",
445 BN(j), i, SCpnt->target, SCpnt->pid);
446
447 if (SCpnt->cmnd[0] == WRITE_10 || SCpnt->cmnd[0] == WRITE_6)
448 cpp->dout = TRUE;
449 else
450 cpp->din = TRUE;
451
452 cpp->reqsen = TRUE;
453 cpp->dispri = TRUE;
454 cpp->one = TRUE;
455 cpp->target = SCpnt->target;
456 cpp->lun = SCpnt->lun;
457 cpp->SCpnt = SCpnt;
458 cpp->sense_addr = htonl((unsigned int) SCpnt->sense_buffer);
459 cpp->sense_len = sizeof SCpnt->sense_buffer;
460
461 if (SCpnt->use_sg) {
462 cpp->sg = TRUE;
463 build_sg_list(cpp, SCpnt);
464 }
465 else {
466 cpp->data_address = htonl((unsigned int) SCpnt->request_buffer);
467 cpp->data_len = htonl(SCpnt->request_bufflen);
468 }
469
470 memcpy(cpp->cdb, SCpnt->cmnd, SCpnt->cmd_len);
471
472
473 if (do_dma(sh[j]->io_port, (unsigned int) cpp, SEND_CP_DMA)) {
474 SCpnt->result = DID_ERROR << 16;
475 SCpnt->host_scribble = NULL;
476 printk("%s: qcomm, target %d, pid %ld, adapter busy, DID_ERROR, done.\n",
477 BN(j), SCpnt->target, SCpnt->pid);
478 restore_flags(flags);
479 done(SCpnt);
480 return 0;
481 }
482
483 HD(j)->cp_stat[i] = IN_USE;
484 restore_flags(flags);
485 return 0;
486 }
487
488 int eata_abort (Scsi_Cmnd *SCarg) {
489 unsigned int i, j, flags;
490
491 save_flags(flags);
492 cli();
493 j = ((struct hostdata *) SCarg->host->hostdata)->board_number;
494
495 if (SCarg->host_scribble == NULL) {
496 printk("%s: abort, target %d, pid %ld inactive.\n",
497 BN(j), SCarg->target, SCarg->pid);
498 return SCSI_ABORT_NOT_RUNNING;
499 }
500
501 i = *(unsigned int *)SCarg->host_scribble;
502 printk("%s: abort, mbox %d, target %d, pid %ld.\n",
503 BN(j), i, SCarg->target, SCarg->pid);
504
505 if (i >= sh[j]->can_queue)
506 panic("%s: abort, invalid SCarg->host_scribble.\n", BN(j));
507
508 if (wait_on_busy(sh[j]->io_port)) {
509 printk("%s: abort, timeout error.\n", BN(j));
510 restore_flags(flags);
511 return SCSI_ABORT_ERROR;
512 }
513
514 if (HD(j)->cp_stat[i] == FREE) {
515 printk("%s: abort, mbox %d is free.\n", BN(j), i);
516 restore_flags(flags);
517 return SCSI_ABORT_NOT_RUNNING;
518 }
519
520 if (HD(j)->cp_stat[i] == IN_USE) {
521 printk("%s: abort, mbox %d is in use.\n", BN(j), i);
522
523 if (SCarg != HD(j)->cp[i].SCpnt)
524 panic("%s: abort, mbox %d, SCarg %p, cp SCpnt %p.\n",
525 BN(j), i, SCarg, HD(j)->cp[i].SCpnt);
526
527 restore_flags(flags);
528 return SCSI_ABORT_SNOOZE;
529 }
530
531 if (HD(j)->cp_stat[i] == IN_RESET) {
532 printk("%s: abort, mbox %d is in reset.\n", BN(j), i);
533 restore_flags(flags);
534 return SCSI_ABORT_ERROR;
535 }
536
537 if (HD(j)->cp_stat[i] == LOCKED) {
538 printk("%s: abort, mbox %d is locked.\n", BN(j), i);
539 restore_flags(flags);
540 return SCSI_ABORT_NOT_RUNNING;
541 }
542 else
543 panic("%s: abort, mbox %d, invalid cp_stat.\n", BN(j), i);
544 }
545
546 int eata_reset (Scsi_Cmnd *SCarg) {
547 unsigned int i, j, flags, time, k, limit = 0;
548 int arg_done = FALSE;
549 Scsi_Cmnd *SCpnt;
550
551 save_flags(flags);
552 cli();
553 j = ((struct hostdata *) SCarg->host->hostdata)->board_number;
554 printk("%s: reset, enter, target %d, pid %ld.\n",
555 BN(j), SCarg->target, SCarg->pid);
556
557 if (SCarg->host_scribble == NULL)
558 printk("%s: reset, pid %ld inactive.\n", BN(j), SCarg->pid);
559
560 if (HD(j)->in_reset) {
561 printk("%s: reset, exit, already in reset.\n", BN(j));
562 restore_flags(flags);
563 return SCSI_RESET_ERROR;
564 }
565
566 if (wait_on_busy(sh[j]->io_port)) {
567 printk("%s: reset, exit, timeout error.\n", BN(j));
568 restore_flags(flags);
569 return SCSI_RESET_ERROR;
570 }
571
572 for (k = 0; k < MAX_TARGET; k++) HD(j)->target_reset[k] = TRUE;
573
574 for (i = 0; i < sh[j]->can_queue; i++) {
575
576 if (HD(j)->cp_stat[i] == FREE) continue;
577
578 if (HD(j)->cp_stat[i] == LOCKED) {
579 HD(j)->cp_stat[i] = FREE;
580 printk("%s: reset, locked mbox %d forced free.\n", BN(j), i);
581 continue;
582 }
583
584 SCpnt = HD(j)->cp[i].SCpnt;
585 HD(j)->cp_stat[i] = IN_RESET;
586 printk("%s: reset, mbox %d in reset, pid %ld.\n",
587 BN(j), i, SCpnt->pid);
588
589 if (SCpnt == NULL)
590 panic("%s: reset, mbox %d, SCpnt == NULL.\n", BN(j), i);
591
592 if (SCpnt->host_scribble == NULL)
593 panic("%s: reset, mbox %d, garbled SCpnt.\n", BN(j), i);
594
595 if (*(unsigned int *)SCpnt->host_scribble != i)
596 panic("%s: reset, mbox %d, index mismatch.\n", BN(j), i);
597
598 if (SCpnt->scsi_done == NULL)
599 panic("%s: reset, mbox %d, SCpnt->scsi_done == NULL.\n", BN(j), i);
600
601 if (SCpnt == SCarg) arg_done = TRUE;
602 }
603
604 if (do_dma(sh[j]->io_port, 0, RESET_PIO)) {
605 printk("%s: reset, cannot reset, timeout error.\n", BN(j));
606 restore_flags(flags);
607 return SCSI_RESET_ERROR;
608 }
609
610 printk("%s: reset, board reset done, enabling interrupts.\n", BN(j));
611 do_trace = TRUE;
612 HD(j)->in_reset = TRUE;
613 sti();
614 time = jiffies;
615 while (jiffies < (time + 200) && limit++ < 100000000) sti();
616 cli();
617 printk("%s: reset, interrupts disabled, loops %d.\n", BN(j), limit);
618
619 for (i = 0; i < sh[j]->can_queue; i++) {
620
621
622 if (HD(j)->cp_stat[i] != IN_RESET) continue;
623
624 SCpnt = HD(j)->cp[i].SCpnt;
625 SCpnt->result = DID_RESET << 16;
626 SCpnt->host_scribble = NULL;
627
628
629 HD(j)->cp_stat[i] = LOCKED;
630
631 printk("%s, reset, mbox %d locked, DID_RESET, pid %ld done.\n",
632 BN(j), i, SCpnt->pid);
633 restore_flags(flags);
634 SCpnt->scsi_done(SCpnt);
635 cli();
636 }
637
638 HD(j)->in_reset = FALSE;
639 do_trace = FALSE;
640 restore_flags(flags);
641
642 if (arg_done) {
643 printk("%s: reset, exit, success.\n", BN(j));
644 return SCSI_RESET_SUCCESS;
645 }
646 else {
647 printk("%s: reset, exit, wakeup.\n", BN(j));
648 return SCSI_RESET_PUNT;
649 }
650 }
651
652 int eata_bios_param (Disk * disk, int dev, int *ip) {
653 int size = disk->capacity;
654
655 if(size < 0x200000) {
656 ip[0]=64;
657 ip[1]=32;
658 }
659 else if (size < 0x400000) {
660 ip[0]=65;
661 ip[1]=63;
662 }
663 else if(size < 0x800000) {
664 ip[0]=128;
665 ip[1]=63;
666 }
667 else {
668 ip[0]=255;
669 ip[1]=63;
670 }
671
672 ip[2] = size / (ip[0] * ip[1]);
673 return 0;
674 }
675
676 static void eata_interrupt_handler(int irq) {
677 Scsi_Cmnd *SCpnt;
678 unsigned int i, j, k, flags, status, loops, total_loops = 0;
679 struct mssp *spp;
680 struct mscp *cpp;
681
682 save_flags(flags);
683 cli();
684
685 if (irqlist[irq] == NO_IRQ) {
686 printk("%s, ihdlr, irq %d, unexpected interrupt.\n", driver_name, irq);
687 restore_flags(flags);
688 return;
689 }
690
691 if (do_trace) printk("%s: ihdlr, enter, irq %d, calls %d.\n",
692 driver_name, irq, calls[irq]);
693
694
695 for (j = 0; sh[j] != NULL; j++) {
696
697 if (sh[j]->irq != irq) continue;
698
699 loops = 0;
700
701
702 while (inb(sh[j]->io_port + REG_AUX_STATUS) & IRQ_ASSERTED) {
703 total_loops++;
704 loops++;
705
706 if (do_trace) printk("%s: ihdlr, start service, count %d.\n",
707 BN(j), HD(j)->iocount);
708
709
710 inb(sh[j]->io_port + REG_STATUS);
711
712
713 for(i = 0; i < sh[j]->can_queue; i++) {
714 spp = &HD(j)->sp[i];
715
716
717 if (spp->eoc == FALSE) continue;
718
719 spp->eoc = FALSE;
720
721 if (HD(j)->cp_stat[i] == LOCKED) {
722 HD(j)->cp_stat[i] = FREE;
723 printk("%s: ihdlr, mbox %d unlocked, count %d.\n",
724 BN(j), i, HD(j)->iocount);
725 continue;
726 }
727 else if (HD(j)->cp_stat[i] == FREE) {
728 printk("%s: ihdlr, mbox %d is free, count %d.\n",
729 BN(j), i, HD(j)->iocount);
730 continue;
731 }
732 else if (HD(j)->cp_stat[i] == IN_RESET)
733 printk("%s: ihdlr, mbox %d is in reset.\n", BN(j), i);
734 else if (HD(j)->cp_stat[i] != IN_USE)
735 panic("%s: ihdlr, mbox %d, invalid cp_stat.\n", BN(j), i);
736
737 HD(j)->cp_stat[i] = FREE;
738 cpp = &HD(j)->cp[i];
739 SCpnt = spp->SCpnt;
740
741 if (SCpnt == NULL)
742 panic("%s: ihdlr, mbox %d, SCpnt == NULL.\n", BN(j), i);
743
744 if (SCpnt != cpp->SCpnt)
745 panic("%s: ihdlr, mbox %d, sp SCpnt %p, cp SCpnt %p.\n",
746 BN(j), i, SCpnt, cpp->SCpnt);
747
748 if (SCpnt->host_scribble == NULL)
749 panic("%s: ihdlr, mbox %d, pid %ld, SCpnt %p garbled.\n",
750 BN(j), i, SCpnt->pid, SCpnt);
751
752 if (*(unsigned int *)SCpnt->host_scribble != i)
753 panic("%s: ihdlr, mbox %d, pid %ld, index mismatch %d,"\
754 " irq %d.\n", BN(j), i, SCpnt->pid,
755 *(unsigned int *)SCpnt->host_scribble, irq);
756
757 switch (spp->adapter_status) {
758 case ASOK:
759
760
761 if (spp->target_status == INTERMEDIATE_GOOD
762 && SCpnt->device->type != TYPE_TAPE)
763 status = DID_ERROR << 16;
764
765
766 else if (spp->target_status == CONDITION_GOOD
767 && SCpnt->device->type != TYPE_TAPE
768 && HD(j)->target_reset[SCpnt->target])
769 status = DID_BUS_BUSY << 16;
770 else
771 status = DID_OK << 16;
772
773 if (spp->target_status == 0)
774 HD(j)->target_reset[SCpnt->target] = FALSE;
775
776 HD(j)->target_time_out[SCpnt->target] = 0;
777
778 break;
779 case ASST:
780 case 0x02:
781
782 if (HD(j)->target_time_out[SCpnt->target] > 1)
783 status = DID_ERROR << 16;
784 else {
785 status = DID_TIME_OUT << 16;
786 HD(j)->target_time_out[SCpnt->target]++;
787 }
788
789 break;
790 case 0x03:
791
792 if (SCpnt->device->type != TYPE_TAPE)
793 status = DID_BUS_BUSY << 16;
794 else
795 status = DID_ERROR << 16;
796
797 for (k = 0; k < MAX_TARGET; k++)
798 HD(j)->target_reset[k] = TRUE;
799
800 break;
801 case 0x07:
802 case 0x0c:
803 case 0x04:
804 case 0x05:
805 case 0x06:
806 case 0x08:
807 case 0x09:
808 case 0x0a:
809 case 0x0b:
810 default:
811 status = DID_ERROR << 16;
812 break;
813 }
814
815 SCpnt->result = status | spp->target_status;
816 HD(j)->iocount++;
817
818 if (loops > 1) HD(j)->multicount++;
819
820 #if defined (DEBUG_INTERRUPT)
821 if (SCpnt->result || do_trace)
822 #else
823 if ((spp->adapter_status != ASOK && HD(j)->iocount > 1000) ||
824 (spp->adapter_status != ASOK &&
825 spp->adapter_status != ASST && HD(j)->iocount <= 1000) ||
826 do_trace)
827 #endif
828 printk("%s: ihdlr, mbox %d, err 0x%x:%x,"\
829 " target %d:%d, pid %ld, count %d.\n",
830 BN(j), i, spp->adapter_status, spp->target_status,
831 SCpnt->target, SCpnt->lun, SCpnt->pid, HD(j)->iocount);
832
833
834 SCpnt->host_scribble = NULL;
835
836 restore_flags(flags);
837 SCpnt->scsi_done(SCpnt);
838 cli();
839
840 }
841
842 }
843
844 }
845
846 calls[irq]++;
847
848 if (total_loops == 0)
849 printk("%s: ihdlr, irq %d, no command completed, calls %d.\n",
850 driver_name, irq, calls[irq]);
851
852 if (do_trace) printk("%s: ihdlr, exit, irq %d, calls %d.\n",
853 driver_name, irq, calls[irq]);
854
855 #if defined (DEBUG_STATISTICS)
856 if ((calls[irq] % 100000) == 10000)
857 for (j = 0; sh[j] != NULL; j++)
858 printk("%s: ihdlr, calls %d, count %d, multi %d.\n", BN(j),
859 calls[(sh[j]->irq)], HD(j)->iocount, HD(j)->multicount);
860 #endif
861
862 restore_flags(flags);
863 return;
864 }