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