This source file includes following definitions.
- wait_on_busy
- port_detect
- u14_34f_detect
- build_sg_list
- u14_34f_queuecommand
- u14_34f_abort
- u14_34f_reset
- u14_34f_biosparam
- u14_34f_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 #undef HAVE_OLD_U14F_FIRMWARE
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102 #include <linux/string.h>
103 #include <linux/sched.h>
104 #include <linux/kernel.h>
105 #include <linux/ioport.h>
106 #include <asm/io.h>
107 #include <asm/system.h>
108 #include "../block/blk.h"
109 #include "scsi.h"
110 #include "hosts.h"
111 #include "sd.h"
112 #include <asm/dma.h>
113 #include <asm/irq.h>
114 #include "u14-34f.h"
115
116
117 #define PRODUCT_ID1 0x56
118 #define PRODUCT_ID2 0x40
119
120
121 #define ISA 0
122 #define ESA 1
123
124 #define OP_HOST_ADAPTER 0x1
125 #define OP_SCSI 0x2
126 #define OP_RESET 0x4
127 #define DTD_SCSI 0x0
128 #define DTD_IN 0x1
129 #define DTD_OUT 0x2
130 #define DTD_NONE 0x3
131 #define HA_CMD_INQUIRY 0x1
132 #define HA_CMD_SELF_DIAG 0x2
133 #define HA_CMD_READ_BUFF 0x3
134 #define HA_CMD_WRITE_BUFF 0x4
135
136 #if defined (HAVE_OLD_U14F_FIRMWARE)
137 #define U14F_MAX_SGLIST 16
138 #define U14F_CLUSTERING DISABLE_CLUSTERING
139 #else
140 #define U14F_MAX_SGLIST 33
141 #define U14F_CLUSTERING ENABLE_CLUSTERING
142 #endif
143
144 #define U34F_MAX_SGLIST 33
145 #define U34F_CLUSTERING ENABLE_CLUSTERING
146
147 #undef DEBUG_DETECT
148 #undef DEBUG_INTERRUPT
149 #undef DEBUG_STATISTICS
150
151 #define MAX_TARGET 8
152 #define MAX_IRQ 16
153 #define MAX_BOARDS 4
154 #define MAX_MAILBOXES 16
155 #define MAX_SGLIST 33
156 #define MAX_CMD_PER_LUN 2
157
158 #define FALSE 0
159 #define TRUE 1
160 #define FREE 0
161 #define IN_USE 1
162 #define LOCKED 2
163 #define IN_RESET 3
164 #define NO_IRQ 0xff
165 #define MAXLOOP 20000
166
167 #define REG_LCL_MASK 0
168 #define REG_LCL_INTR 1
169 #define REG_SYS_MASK 2
170 #define REG_SYS_INTR 3
171 #define REG_PRODUCT_ID1 4
172 #define REG_PRODUCT_ID2 5
173 #define REG_CONFIG1 6
174 #define REG_CONFIG2 7
175 #define REG_OGM 8
176 #define REG_ICM 12
177 #define REG_REGION 0x0c
178 #define BSY_ASSERTED 0x01
179 #define INTR_ASSERTED 0x01
180 #define CMD_RESET 0xc0
181 #define CMD_OGM_INTR 0x01
182 #define CMD_CLR_INTR 0x01
183 #define CMD_ENA_INTR 0x81
184 #define ASOK 0x00
185 #define ASST 0x91
186
187 #define PACKED __attribute__((packed))
188
189
190 struct mscp {
191 unsigned char opcode: 3;
192 unsigned char xdir: 2;
193 unsigned char dcn: 1;
194 unsigned char ca: 1;
195 unsigned char sg: 1;
196 unsigned char target: 3;
197 unsigned char ch_no: 2;
198 unsigned char lun: 3;
199 unsigned int data_address PACKED;
200 unsigned int data_len PACKED;
201 unsigned int command_link PACKED;
202 unsigned char scsi_command_link_id;
203 unsigned char use_sg;
204 unsigned char sense_len;
205 unsigned char scsi_cdbs_len;
206 unsigned char scsi_cdbs[12];
207 unsigned char adapter_status;
208 unsigned char target_status;
209 unsigned int sense_addr PACKED;
210
211 Scsi_Cmnd *SCpnt;
212
213 struct sg_list {
214 unsigned int address;
215 unsigned int num_bytes;
216 } sglist[MAX_SGLIST];
217
218 unsigned int index;
219 };
220
221 struct hostdata {
222 struct mscp cp[MAX_MAILBOXES];
223 unsigned int cp_stat[MAX_MAILBOXES];
224 unsigned int last_cp_used;
225 unsigned int iocount;
226 unsigned int multicount;
227 int board_number;
228 char board_name[16];
229 int in_reset;
230 int target_time_out[MAX_TARGET];
231 int target_reset[MAX_TARGET];
232 unsigned char bios_drive_number: 1;
233 unsigned char heads;
234 unsigned char sectors;
235 unsigned char subversion: 4;
236
237
238 unsigned char slot;
239 };
240
241 static struct Scsi_Host * sh[MAX_BOARDS + 1];
242 static char* driver_name = "Ux4F";
243 static unsigned int irqlist[MAX_IRQ], calls[MAX_IRQ];
244
245 #define HD(board) ((struct hostdata *) &sh[board]->hostdata)
246 #define BN(board) (HD(board)->board_name)
247
248 static void u14_34f_interrupt_handler(int);
249 static int do_trace = FALSE;
250
251 static inline unchar wait_on_busy(ushort iobase) {
252 unsigned int loop = MAXLOOP;
253
254 while (inb(iobase + REG_LCL_INTR) & BSY_ASSERTED)
255 if (--loop == 0) return TRUE;
256
257 return FALSE;
258 }
259
260 static inline int port_detect(ushort *port_base, unsigned int j,
261 Scsi_Host_Template * tpnt) {
262 unsigned char irq, dma_channel, subversion;
263 unsigned char in_byte;
264
265
266 void *bios_segment_table[8] = {
267 NULL,
268 (void *) 0xc4000, (void *) 0xc8000, (void *) 0xcc000, (void *) 0xd0000,
269 (void *) 0xd4000, (void *) 0xd8000, (void *) 0xdc000
270 };
271
272
273 unsigned char interrupt_table[4] = { 15, 14, 11, 10 };
274
275
276 unsigned char dma_channel_table[4] = { 5, 6, 7, 0 };
277
278
279 struct {
280 unsigned char heads;
281 unsigned char sectors;
282 } mapping_table[4] = {
283 { 16, 63 }, { 64, 32 }, { 64, 63 }, { 64, 32 }
284 };
285
286 struct config_1 {
287 unsigned char bios_segment: 3;
288 unsigned char removable_disks_as_fixed: 1;
289 unsigned char interrupt: 2;
290 unsigned char dma_channel: 2;
291 } config_1;
292
293 struct config_2 {
294 unsigned char ha_scsi_id: 3;
295 unsigned char mapping_mode: 2;
296 unsigned char bios_drive_number: 1;
297 unsigned char tfr_port: 2;
298 } config_2;
299
300 char name[16];
301
302 sprintf(name, "%s%d", driver_name, j);
303
304 if(check_region(*port_base, REG_REGION)) return FALSE;
305
306 if (inb(*port_base + REG_PRODUCT_ID1) != PRODUCT_ID1) return FALSE;
307
308 in_byte = inb(*port_base + REG_PRODUCT_ID2);
309
310 if ((in_byte & 0xf0) != PRODUCT_ID2) return FALSE;
311
312 *(char *)&config_1 = inb(*port_base + REG_CONFIG1);
313 *(char *)&config_2 = inb(*port_base + REG_CONFIG2);
314
315 irq = interrupt_table[config_1.interrupt];
316 dma_channel = dma_channel_table[config_1.dma_channel];
317 subversion = (in_byte & 0x0f);
318
319
320 if ((irq >= MAX_IRQ) || ((irqlist[irq] == NO_IRQ) && request_irq
321 (irq, u14_34f_interrupt_handler, SA_INTERRUPT, driver_name))) {
322 printk("%s: unable to allocate IRQ %u, detaching.\n", name, irq);
323 return FALSE;
324 }
325
326 if (subversion == ISA && request_dma(dma_channel, driver_name)) {
327 printk("%s: unable to allocate DMA channel %u, detaching.\n",
328 name, dma_channel);
329 free_irq(irq);
330 return FALSE;
331 }
332
333 sh[j] = scsi_register(tpnt, sizeof(struct hostdata));
334 sh[j]->io_port = *port_base;
335 sh[j]->base = bios_segment_table[config_1.bios_segment];
336 sh[j]->irq = irq;
337 sh[j]->this_id = config_2.ha_scsi_id;
338 sh[j]->can_queue = MAX_MAILBOXES;
339 sh[j]->cmd_per_lun = MAX_CMD_PER_LUN;
340
341 #if defined(DEBUG_DETECT)
342 {
343 unsigned char sys_mask, lcl_mask;
344
345 sys_mask = inb(sh[j]->io_port + REG_SYS_MASK);
346 lcl_mask = inb(sh[j]->io_port + REG_LCL_MASK);
347 printk("SYS_MASK 0x%x, LCL_MASK 0x%x.\n", sys_mask, lcl_mask);
348 }
349 #endif
350
351
352 if (sh[j]->base == 0) outb(CMD_ENA_INTR, sh[j]->io_port + REG_SYS_MASK);
353
354
355 snarf_region(sh[j]->io_port, REG_REGION);
356
357 memset(HD(j), 0, sizeof(struct hostdata));
358 HD(j)->heads = mapping_table[config_2.mapping_mode].heads;
359 HD(j)->sectors = mapping_table[config_2.mapping_mode].sectors;
360 HD(j)->bios_drive_number = config_2.bios_drive_number;
361 HD(j)->subversion = subversion;
362 HD(j)->board_number = j;
363 irqlist[irq] = j;
364
365 if (HD(j)->subversion == ESA) {
366 sh[j]->dma_channel = 0;
367 sh[j]->unchecked_isa_dma = FALSE;
368 sh[j]->sg_tablesize = U34F_MAX_SGLIST;
369 sh[j]->hostt->use_clustering = U34F_CLUSTERING;
370 sprintf(BN(j), "U34F%d", j);
371 }
372 else {
373 sh[j]->dma_channel = dma_channel;
374 sh[j]->block = sh[j];
375 sh[j]->unchecked_isa_dma = TRUE;
376 sh[j]->sg_tablesize = U14F_MAX_SGLIST;
377 sh[j]->hostt->use_clustering = U14F_CLUSTERING;
378 sprintf(BN(j), "U14F%d", j);
379 disable_dma(dma_channel);
380 clear_dma_ff(dma_channel);
381 set_dma_mode(dma_channel, DMA_MODE_CASCADE);
382 enable_dma(dma_channel);
383 }
384
385 printk("%s: PORT 0x%03x, BIOS 0x%05x, IRQ %u, DMA %u, SG %d, "\
386 "Mbox %d, CmdLun %d, C%d.\n", BN(j), sh[j]->io_port,
387 (int)sh[j]->base, sh[j]->irq,
388 sh[j]->dma_channel, sh[j]->sg_tablesize,
389 sh[j]->can_queue, sh[j]->cmd_per_lun,
390 sh[j]->hostt->use_clustering);
391 return TRUE;
392 }
393
394 int u14_34f_detect (Scsi_Host_Template * tpnt) {
395 unsigned int j = 0, k, flags;
396
397 ushort io_port[] = {
398 0x330, 0x340, 0x230, 0x240, 0x210, 0x130, 0x140, 0x0
399 };
400
401 ushort *port_base = io_port;
402
403 save_flags(flags);
404 cli();
405
406 for (k = 0; k < MAX_IRQ; k++) {
407 irqlist[k] = NO_IRQ;
408 calls[k] = 0;
409 }
410
411 for (k = 0; k < MAX_BOARDS + 1; k++) sh[k] = NULL;
412
413 while (*port_base) {
414
415 if (j < MAX_BOARDS && port_detect(port_base, j, tpnt)) j++;
416
417 port_base++;
418 }
419
420 restore_flags(flags);
421 return j;
422 }
423
424 static inline void build_sg_list(struct mscp *cpp, Scsi_Cmnd *SCpnt) {
425 unsigned int k, data_len = 0;
426 struct scatterlist * sgpnt;
427
428 sgpnt = (struct scatterlist *) SCpnt->request_buffer;
429
430 for (k = 0; k < SCpnt->use_sg; k++) {
431 cpp->sglist[k].address = (unsigned int) sgpnt[k].address;
432 cpp->sglist[k].num_bytes = sgpnt[k].length;
433 data_len += sgpnt[k].length;
434 }
435
436 cpp->use_sg = SCpnt->use_sg;
437 cpp->data_address = (unsigned int) cpp->sglist;
438 cpp->data_len = data_len;
439 }
440
441 int u14_34f_queuecommand(Scsi_Cmnd *SCpnt, void (*done)(Scsi_Cmnd *)) {
442 unsigned int i, j, k, flags;
443 struct mscp *cpp;
444
445 save_flags(flags);
446 cli();
447
448 j = ((struct hostdata *) SCpnt->host->hostdata)->board_number;
449
450 if (!done) panic("%s: qcomm, pid %ld, null done.\n", BN(j), SCpnt->pid);
451
452
453
454 i = HD(j)->last_cp_used + 1;
455
456 for (k = 0; k < sh[j]->can_queue; k++, i++) {
457
458 if (i >= sh[j]->can_queue) i = 0;
459
460 if (HD(j)->cp_stat[i] == FREE) {
461 HD(j)->last_cp_used = i;
462 break;
463 }
464 }
465
466 if (k == sh[j]->can_queue) {
467 printk("%s: qcomm, no free mailbox, resetting.\n", BN(j));
468
469 if (HD(j)->in_reset)
470 printk("%s: qcomm, already in reset.\n", BN(j));
471 else if (u14_34f_reset(SCpnt) == SCSI_RESET_SUCCESS)
472 panic("%s: qcomm, SCSI_RESET_SUCCESS.\n", BN(j));
473
474 SCpnt->result = DID_BUS_BUSY << 16;
475 SCpnt->host_scribble = NULL;
476 printk("%s: qcomm, pid %ld, DID_BUS_BUSY, done.\n", BN(j), SCpnt->pid);
477 restore_flags(flags);
478 done(SCpnt);
479 return 0;
480 }
481
482
483 cpp = &HD(j)->cp[i];
484
485 memset(cpp, 0, sizeof(struct mscp));
486 SCpnt->scsi_done = done;
487 cpp->index = i;
488 SCpnt->host_scribble = (unsigned char *) &cpp->index;
489
490 if (do_trace) printk("%s: qcomm, mbox %d, target %d, pid %ld.\n",
491 BN(j), i, SCpnt->target, SCpnt->pid);
492
493 cpp->opcode = OP_SCSI;
494 cpp->xdir = DTD_SCSI;
495 cpp->target = SCpnt->target;
496 cpp->lun = SCpnt->lun;
497 cpp->SCpnt = SCpnt;
498 cpp->sense_addr = (unsigned int) SCpnt->sense_buffer;
499 cpp->sense_len = sizeof SCpnt->sense_buffer;
500
501 if (SCpnt->use_sg) {
502 cpp->sg = TRUE;
503 build_sg_list(cpp, SCpnt);
504 }
505 else {
506 cpp->data_address = (unsigned int)SCpnt->request_buffer;
507 cpp->data_len = SCpnt->request_bufflen;
508 }
509
510 cpp->scsi_cdbs_len = SCpnt->cmd_len;
511 memcpy(cpp->scsi_cdbs, SCpnt->cmnd, cpp->scsi_cdbs_len);
512
513 if (wait_on_busy(sh[j]->io_port)) {
514 SCpnt->result = DID_ERROR << 16;
515 SCpnt->host_scribble = NULL;
516 printk("%s: qcomm, target %d, pid %ld, adapter busy, DID_ERROR, done.\n",
517 BN(j), SCpnt->target, SCpnt->pid);
518 restore_flags(flags);
519 done(SCpnt);
520 return 0;
521 }
522
523
524 outl((unsigned int)cpp, sh[j]->io_port + REG_OGM);
525
526
527 outb(CMD_OGM_INTR, sh[j]->io_port + REG_LCL_INTR);
528
529 HD(j)->cp_stat[i] = IN_USE;
530 restore_flags(flags);
531 return 0;
532 }
533
534 int u14_34f_abort(Scsi_Cmnd *SCarg) {
535 unsigned int i, j, flags;
536
537 save_flags(flags);
538 cli();
539 j = ((struct hostdata *) SCarg->host->hostdata)->board_number;
540
541 if (SCarg->host_scribble == NULL) {
542 printk("%s: abort, target %d, pid %ld inactive.\n",
543 BN(j), SCarg->target, SCarg->pid);
544 return SCSI_ABORT_NOT_RUNNING;
545 }
546
547 i = *(unsigned int *)SCarg->host_scribble;
548 printk("%s: abort, mbox %d, target %d, pid %ld.\n",
549 BN(j), i, SCarg->target, SCarg->pid);
550
551 if (i >= sh[j]->can_queue)
552 panic("%s: abort, invalid SCarg->host_scribble.\n", BN(j));
553
554 if (wait_on_busy(sh[j]->io_port)) {
555 printk("%s: abort, timeout error.\n", BN(j));
556 restore_flags(flags);
557 return SCSI_ABORT_ERROR;
558 }
559
560 if (HD(j)->cp_stat[i] == FREE) {
561 printk("%s: abort, mbox %d is free.\n", BN(j), i);
562 restore_flags(flags);
563 return SCSI_ABORT_NOT_RUNNING;
564 }
565
566 if (HD(j)->cp_stat[i] == IN_USE) {
567 printk("%s: abort, mbox %d is in use.\n", BN(j), i);
568
569 if (SCarg != HD(j)->cp[i].SCpnt)
570 panic("%s: abort, mbox %d, SCarg %p, cp SCpnt %p.\n",
571 BN(j), i, SCarg, HD(j)->cp[i].SCpnt);
572
573 restore_flags(flags);
574 return SCSI_ABORT_SNOOZE;
575 }
576
577 if (HD(j)->cp_stat[i] == IN_RESET) {
578 printk("%s: abort, mbox %d is in reset.\n", BN(j), i);
579 restore_flags(flags);
580 return SCSI_ABORT_ERROR;
581 }
582
583 if (HD(j)->cp_stat[i] == LOCKED) {
584 printk("%s: abort, mbox %d is locked.\n", BN(j), i);
585 restore_flags(flags);
586 return SCSI_ABORT_NOT_RUNNING;
587 }
588 else
589 panic("%s: abort, mbox %d, invalid cp_stat.\n", BN(j), i);
590 }
591
592 int u14_34f_reset(Scsi_Cmnd * SCarg) {
593 unsigned int i, j, flags, time, k, limit = 0;
594 int arg_done = FALSE;
595 Scsi_Cmnd *SCpnt;
596
597 save_flags(flags);
598 cli();
599 j = ((struct hostdata *) SCarg->host->hostdata)->board_number;
600 printk("%s: reset, enter, target %d, pid %ld.\n",
601 BN(j), SCarg->target, SCarg->pid);
602
603 if (SCarg->host_scribble == NULL)
604 printk("%s: reset, pid %ld inactive.\n", BN(j), SCarg->pid);
605
606 if (HD(j)->in_reset) {
607 printk("%s: reset, exit, already in reset.\n", BN(j));
608 restore_flags(flags);
609 return SCSI_RESET_ERROR;
610 }
611
612 if (wait_on_busy(sh[j]->io_port)) {
613 printk("%s: reset, exit, timeout error.\n", BN(j));
614 restore_flags(flags);
615 return SCSI_RESET_ERROR;
616 }
617
618 for (k = 0; k < MAX_TARGET; k++) HD(j)->target_reset[k] = TRUE;
619
620 for (i = 0; i < sh[j]->can_queue; i++) {
621
622 if (HD(j)->cp_stat[i] == FREE) continue;
623
624 if (HD(j)->cp_stat[i] == LOCKED) {
625 HD(j)->cp_stat[i] = FREE;
626 printk("%s: reset, locked mbox %d forced free.\n", BN(j), i);
627 continue;
628 }
629
630 SCpnt = HD(j)->cp[i].SCpnt;
631 HD(j)->cp_stat[i] = IN_RESET;
632 printk("%s: reset, mbox %d in reset, pid %ld.\n",
633 BN(j), i, SCpnt->pid);
634
635 if (SCpnt == NULL)
636 panic("%s: reset, mbox %d, SCpnt == NULL.\n", BN(j), i);
637
638 if (SCpnt->host_scribble == NULL)
639 panic("%s: reset, mbox %d, garbled SCpnt.\n", BN(j), i);
640
641 if (*(unsigned int *)SCpnt->host_scribble != i)
642 panic("%s: reset, mbox %d, index mismatch.\n", BN(j), i);
643
644 if (SCpnt->scsi_done == NULL)
645 panic("%s: reset, mbox %d, SCpnt->scsi_done == NULL.\n", BN(j), i);
646
647 if (SCpnt == SCarg) arg_done = TRUE;
648 }
649
650 if (wait_on_busy(sh[j]->io_port)) {
651 printk("%s: reset, cannot reset, timeout error.\n", BN(j));
652 restore_flags(flags);
653 return SCSI_RESET_ERROR;
654 }
655
656 outb(CMD_RESET, sh[j]->io_port + REG_LCL_INTR);
657 printk("%s: reset, board reset done, enabling interrupts.\n", BN(j));
658 do_trace = TRUE;
659 HD(j)->in_reset = TRUE;
660 sti();
661 time = jiffies;
662 while (jiffies < (time + 200) && limit++ < 100000000) sti();
663 cli();
664 printk("%s: reset, interrupts disabled, loops %d.\n", BN(j), limit);
665
666 for (i = 0; i < sh[j]->can_queue; i++) {
667
668
669 if (HD(j)->cp_stat[i] != IN_RESET) continue;
670
671 SCpnt = HD(j)->cp[i].SCpnt;
672 SCpnt->result = DID_RESET << 16;
673 SCpnt->host_scribble = NULL;
674
675
676 HD(j)->cp_stat[i] = LOCKED;
677
678 printk("%s, reset, mbox %d locked, DID_RESET, pid %ld done.\n",
679 BN(j), i, SCpnt->pid);
680 restore_flags(flags);
681 SCpnt->scsi_done(SCpnt);
682 cli();
683 }
684
685 HD(j)->in_reset = FALSE;
686 do_trace = FALSE;
687 restore_flags(flags);
688
689 if (arg_done) {
690 printk("%s: reset, exit, success.\n", BN(j));
691 return SCSI_RESET_SUCCESS;
692 }
693 else {
694 printk("%s: reset, exit, wakeup.\n", BN(j));
695 return SCSI_RESET_PUNT;
696 }
697 }
698
699 int u14_34f_biosparam(Disk * disk, int dev, int * dkinfo) {
700 unsigned int j = 0;
701 int size = disk->capacity;
702
703 dkinfo[0] = HD(j)->heads;
704 dkinfo[1] = HD(j)->sectors;
705 dkinfo[2] = size / (HD(j)->heads * HD(j)->sectors);
706 return 0;
707 }
708
709 static void u14_34f_interrupt_handler(int irq) {
710 Scsi_Cmnd *SCpnt;
711 unsigned int i, j, k, flags, status, loops, total_loops = 0;
712 struct mscp *spp;
713
714 save_flags(flags);
715 cli();
716
717 if (irqlist[irq] == NO_IRQ) {
718 printk("%s, ihdlr, irq %d, unexpected interrupt.\n", driver_name, irq);
719 restore_flags(flags);
720 return;
721 }
722
723 if (do_trace) printk("%s: ihdlr, enter, irq %d, calls %d.\n",
724 driver_name, irq, calls[irq]);
725
726
727 for (j = 0; sh[j] != NULL; j++) {
728
729 if (sh[j]->irq != irq) continue;
730
731 loops = 0;
732
733
734 while (inb(sh[j]->io_port + REG_SYS_INTR) & INTR_ASSERTED) {
735 total_loops++;
736 loops++;
737
738 if (do_trace) printk("%s: ihdlr, start service, count %d.\n",
739 BN(j), HD(j)->iocount);
740
741 spp = (struct mscp *)inl(sh[j]->io_port + REG_ICM);
742
743
744 outb(CMD_CLR_INTR, sh[j]->io_port + REG_SYS_INTR);
745
746 i = spp - HD(j)->cp;
747
748 if (i >= sh[j]->can_queue)
749 panic("%s: ihdlr, invalid mscp address.\n", BN(j));
750
751 if (HD(j)->cp_stat[i] == LOCKED) {
752 HD(j)->cp_stat[i] = FREE;
753 printk("%s: ihdlr, mbox %d unlocked, count %d.\n",
754 BN(j), i, HD(j)->iocount);
755 continue;
756 }
757 else if (HD(j)->cp_stat[i] == FREE) {
758 printk("%s: ihdlr, mbox %d is free, count %d.\n",
759 BN(j), i, HD(j)->iocount);
760 continue;
761 }
762 else if (HD(j)->cp_stat[i] == IN_RESET)
763 printk("%s: ihdlr, mbox %d is in reset.\n", BN(j), i);
764 else if (HD(j)->cp_stat[i] != IN_USE)
765 panic("%s: ihdlr, mbox %d, invalid cp_stat.\n", BN(j), i);
766
767 HD(j)->cp_stat[i] = FREE;
768 SCpnt = spp->SCpnt;
769
770 if (SCpnt == NULL)
771 panic("%s: ihdlr, mbox %d, SCpnt == NULL.\n", BN(j), i);
772
773 if (SCpnt->host_scribble == NULL)
774 panic("%s: ihdlr, mbox %d, pid %ld, SCpnt %p garbled.\n",
775 BN(j), i, SCpnt->pid, SCpnt);
776
777 if (*(unsigned int *)SCpnt->host_scribble != i)
778 panic("%s: ihdlr, mbox %d, pid %ld, index mismatch %d,"\
779 " irq %d.\n", BN(j), i, SCpnt->pid,
780 *(unsigned int *)SCpnt->host_scribble, irq);
781
782 switch (spp->adapter_status) {
783 case ASOK:
784
785
786 if (spp->target_status == INTERMEDIATE_GOOD
787 && SCpnt->device->type != TYPE_TAPE)
788 status = DID_ERROR << 16;
789
790
791 else if (spp->target_status == CONDITION_GOOD
792 && SCpnt->device->type == TYPE_DISK
793 && HD(j)->target_reset[SCpnt->target])
794 status = DID_BUS_BUSY << 16;
795 else
796 status = DID_OK << 16;
797
798 if (spp->target_status == 0)
799 HD(j)->target_reset[SCpnt->target] = FALSE;
800
801 HD(j)->target_time_out[SCpnt->target] = 0;
802
803 break;
804 case ASST:
805
806 if (HD(j)->target_time_out[SCpnt->target] > 1)
807 status = DID_ERROR << 16;
808 else {
809 status = DID_TIME_OUT << 16;
810 HD(j)->target_time_out[SCpnt->target]++;
811 }
812
813 break;
814 case 0x92:
815 case 0x93:
816 case 0x94:
817 case 0x96:
818 case 0xa3:
819
820 if (SCpnt->device->type != TYPE_TAPE)
821 status = DID_BUS_BUSY << 16;
822 else
823 status = DID_ERROR << 16;
824
825 for (k = 0; k < MAX_TARGET; k++)
826 HD(j)->target_reset[k] = TRUE;
827
828 break;
829 case 0x01:
830 case 0x02:
831 case 0x03:
832 case 0x84:
833 case 0x9b:
834 case 0x9f:
835 case 0xff:
836 default:
837 status = DID_ERROR << 16;
838 break;
839 }
840
841 SCpnt->result = status | spp->target_status;
842 HD(j)->iocount++;
843
844 if (loops > 1) HD(j)->multicount++;
845
846 #if defined (DEBUG_INTERRUPT)
847 if (SCpnt->result || do_trace)
848 #else
849 if ((spp->adapter_status != ASOK && HD(j)->iocount > 1000) ||
850 (spp->adapter_status != ASOK &&
851 spp->adapter_status != ASST && HD(j)->iocount <= 1000) ||
852 do_trace)
853 #endif
854 printk("%s: ihdlr, mbox %d, err 0x%x:%x,"\
855 " target %d:%d, pid %ld, count %d.\n",
856 BN(j), i, spp->adapter_status, spp->target_status,
857 SCpnt->target, SCpnt->lun, SCpnt->pid, HD(j)->iocount);
858
859
860 SCpnt->host_scribble = NULL;
861
862 restore_flags(flags);
863 SCpnt->scsi_done(SCpnt);
864 cli();
865
866 }
867
868 }
869
870 calls[irq]++;
871
872 if (total_loops == 0)
873 printk("%s: ihdlr, irq %d, no command completed, calls %d.\n",
874 driver_name, irq, calls[irq]);
875
876 if (do_trace) printk("%s: ihdlr, exit, irq %d, calls %d.\n",
877 driver_name, irq, calls[irq]);
878
879 #if defined (DEBUG_STATISTICS)
880 if ((calls[irq] % 100000) == 10000)
881 for (j = 0; sh[j] != NULL; j++)
882 printk("%s: ihdlr, calls %d, count %d, multi %d.\n", BN(j),
883 calls[(sh[j]->irq)], HD(j)->iocount, HD(j)->multicount);
884 #endif
885
886 restore_flags(flags);
887 return;
888 }