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