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