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