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