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