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