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