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