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 const 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 restore_flags(flags);
662 return SCSI_ABORT_NOT_RUNNING;
663 }
664
665 i = *(unsigned int *)SCarg->host_scribble;
666 printk("%s: abort, mbox %d, target %d, pid %ld.\n",
667 BN(j), i, SCarg->target, SCarg->pid);
668
669 if (i >= sh[j]->can_queue)
670 panic("%s: abort, invalid SCarg->host_scribble.\n", BN(j));
671
672 if (wait_on_busy(sh[j]->io_port)) {
673 printk("%s: abort, timeout error.\n", BN(j));
674 restore_flags(flags);
675 return SCSI_ABORT_ERROR;
676 }
677
678 if (HD(j)->cp_stat[i] == FREE) {
679 printk("%s: abort, mbox %d is free.\n", BN(j), i);
680 restore_flags(flags);
681 return SCSI_ABORT_NOT_RUNNING;
682 }
683
684 if (HD(j)->cp_stat[i] == IN_USE) {
685 printk("%s: abort, mbox %d is in use.\n", BN(j), i);
686
687 if (SCarg != HD(j)->cp[i].SCpnt)
688 panic("%s: abort, mbox %d, SCarg %p, cp SCpnt %p.\n",
689 BN(j), i, SCarg, HD(j)->cp[i].SCpnt);
690
691 restore_flags(flags);
692 return SCSI_ABORT_SNOOZE;
693 }
694
695 if (HD(j)->cp_stat[i] == IN_RESET) {
696 printk("%s: abort, mbox %d is in reset.\n", BN(j), i);
697 restore_flags(flags);
698 return SCSI_ABORT_ERROR;
699 }
700
701 if (HD(j)->cp_stat[i] == LOCKED) {
702 printk("%s: abort, mbox %d is locked.\n", BN(j), i);
703 restore_flags(flags);
704 return SCSI_ABORT_NOT_RUNNING;
705 }
706 restore_flags(flags);
707 panic("%s: abort, mbox %d, invalid cp_stat.\n", BN(j), i);
708 }
709
710 int u14_34f_reset(Scsi_Cmnd * SCarg) {
711 unsigned int i, j, flags, time, k, limit = 0;
712 int arg_done = FALSE;
713 Scsi_Cmnd *SCpnt;
714
715 save_flags(flags);
716 cli();
717 j = ((struct hostdata *) SCarg->host->hostdata)->board_number;
718 printk("%s: reset, enter, target %d, pid %ld.\n",
719 BN(j), SCarg->target, SCarg->pid);
720
721 if (SCarg->host_scribble == NULL)
722 printk("%s: reset, pid %ld inactive.\n", BN(j), SCarg->pid);
723
724 if (HD(j)->in_reset) {
725 printk("%s: reset, exit, already in reset.\n", BN(j));
726 restore_flags(flags);
727 return SCSI_RESET_ERROR;
728 }
729
730 if (wait_on_busy(sh[j]->io_port)) {
731 printk("%s: reset, exit, timeout error.\n", BN(j));
732 restore_flags(flags);
733 return SCSI_RESET_ERROR;
734 }
735
736 for (k = 0; k < MAX_TARGET; k++) HD(j)->target_reset[k] = TRUE;
737
738 for (k = 0; k < MAX_TARGET; k++) HD(j)->target_time_out[k] = 0;
739
740 for (i = 0; i < sh[j]->can_queue; i++) {
741
742 if (HD(j)->cp_stat[i] == FREE) continue;
743
744 if (HD(j)->cp_stat[i] == LOCKED) {
745 HD(j)->cp_stat[i] = FREE;
746 printk("%s: reset, locked mbox %d forced free.\n", BN(j), i);
747 continue;
748 }
749
750 SCpnt = HD(j)->cp[i].SCpnt;
751 HD(j)->cp_stat[i] = IN_RESET;
752 printk("%s: reset, mbox %d in reset, pid %ld.\n",
753 BN(j), i, SCpnt->pid);
754
755 if (SCpnt == NULL)
756 panic("%s: reset, mbox %d, SCpnt == NULL.\n", BN(j), i);
757
758 if (SCpnt->host_scribble == NULL)
759 panic("%s: reset, mbox %d, garbled SCpnt.\n", BN(j), i);
760
761 if (*(unsigned int *)SCpnt->host_scribble != i)
762 panic("%s: reset, mbox %d, index mismatch.\n", BN(j), i);
763
764 if (SCpnt->scsi_done == NULL)
765 panic("%s: reset, mbox %d, SCpnt->scsi_done == NULL.\n", BN(j), i);
766
767 if (SCpnt == SCarg) arg_done = TRUE;
768 }
769
770 if (wait_on_busy(sh[j]->io_port)) {
771 printk("%s: reset, cannot reset, timeout error.\n", BN(j));
772 restore_flags(flags);
773 return SCSI_RESET_ERROR;
774 }
775
776 outb(CMD_RESET, sh[j]->io_port + REG_LCL_INTR);
777 printk("%s: reset, board reset done, enabling interrupts.\n", BN(j));
778
779 #if defined (DEBUG_RESET)
780 do_trace = TRUE;
781 #endif
782
783 HD(j)->in_reset = TRUE;
784 sti();
785 time = jiffies;
786 while (jiffies < (time + 100) && limit++ < 100000000);
787 cli();
788 printk("%s: reset, interrupts disabled, loops %d.\n", BN(j), limit);
789
790 for (i = 0; i < sh[j]->can_queue; i++) {
791
792
793 if (HD(j)->cp_stat[i] != IN_RESET) continue;
794
795 SCpnt = HD(j)->cp[i].SCpnt;
796 SCpnt->result = DID_RESET << 16;
797 SCpnt->host_scribble = NULL;
798
799
800 HD(j)->cp_stat[i] = LOCKED;
801
802 printk("%s, reset, mbox %d locked, DID_RESET, pid %ld done.\n",
803 BN(j), i, SCpnt->pid);
804 restore_flags(flags);
805 SCpnt->scsi_done(SCpnt);
806 cli();
807 }
808
809 HD(j)->in_reset = FALSE;
810 do_trace = FALSE;
811 restore_flags(flags);
812
813 if (arg_done) {
814 printk("%s: reset, exit, success.\n", BN(j));
815 return SCSI_RESET_SUCCESS;
816 }
817 else {
818 printk("%s: reset, exit, wakeup.\n", BN(j));
819 return SCSI_RESET_PUNT;
820 }
821 }
822
823 int u14_34f_biosparam(Disk * disk, int dev, int * dkinfo) {
824 unsigned int j = 0;
825 int size = disk->capacity;
826
827 dkinfo[0] = HD(j)->heads;
828 dkinfo[1] = HD(j)->sectors;
829 dkinfo[2] = size / (HD(j)->heads * HD(j)->sectors);
830 return 0;
831 }
832
833 static void u14_34f_interrupt_handler(int irq, struct pt_regs * regs) {
834 Scsi_Cmnd *SCpnt;
835 unsigned int i, j, k, flags, status, tstatus, loops, total_loops = 0;
836 struct mscp *spp;
837
838 save_flags(flags);
839 cli();
840
841 if (irqlist[irq] == NO_IRQ) {
842 printk("%s, ihdlr, irq %d, unexpected interrupt.\n", driver_name, irq);
843 restore_flags(flags);
844 return;
845 }
846
847 if (do_trace) printk("%s: ihdlr, enter, irq %d, calls %d.\n",
848 driver_name, irq, calls[irq]);
849
850
851 for (j = 0; sh[j] != NULL; j++) {
852
853 if (sh[j]->irq != irq) continue;
854
855 loops = 0;
856
857
858 while (inb(sh[j]->io_port + REG_SYS_INTR) & IRQ_ASSERTED) {
859 total_loops++;
860 loops++;
861
862 if (do_trace) printk("%s: ihdlr, start service, count %d.\n",
863 BN(j), HD(j)->iocount);
864
865 spp = (struct mscp *)inl(sh[j]->io_port + REG_ICM);
866
867
868 outb(CMD_CLR_INTR, sh[j]->io_port + REG_SYS_INTR);
869
870 i = spp - HD(j)->cp;
871
872 if (i >= sh[j]->can_queue)
873 panic("%s: ihdlr, invalid mscp address.\n", BN(j));
874
875 if (HD(j)->cp_stat[i] == IGNORE) {
876 HD(j)->cp_stat[i] = FREE;
877 continue;
878 }
879 else if (HD(j)->cp_stat[i] == LOCKED) {
880 HD(j)->cp_stat[i] = FREE;
881 printk("%s: ihdlr, mbox %d unlocked, count %d.\n",
882 BN(j), i, HD(j)->iocount);
883 continue;
884 }
885 else if (HD(j)->cp_stat[i] == FREE) {
886 printk("%s: ihdlr, mbox %d is free, count %d.\n",
887 BN(j), i, HD(j)->iocount);
888 continue;
889 }
890 else if (HD(j)->cp_stat[i] == IN_RESET)
891 printk("%s: ihdlr, mbox %d is in reset.\n", BN(j), i);
892 else if (HD(j)->cp_stat[i] != IN_USE)
893 panic("%s: ihdlr, mbox %d, invalid cp_stat.\n", BN(j), i);
894
895 HD(j)->cp_stat[i] = FREE;
896 SCpnt = spp->SCpnt;
897
898 if (SCpnt == NULL)
899 panic("%s: ihdlr, mbox %d, SCpnt == NULL.\n", BN(j), i);
900
901 if (SCpnt->host_scribble == NULL)
902 panic("%s: ihdlr, mbox %d, pid %ld, SCpnt %p garbled.\n",
903 BN(j), i, SCpnt->pid, SCpnt);
904
905 if (*(unsigned int *)SCpnt->host_scribble != i)
906 panic("%s: ihdlr, mbox %d, pid %ld, index mismatch %d,"\
907 " irq %d.\n", BN(j), i, SCpnt->pid,
908 *(unsigned int *)SCpnt->host_scribble, irq);
909
910 tstatus = status_byte(spp->target_status);
911
912 switch (spp->adapter_status) {
913 case ASOK:
914
915
916 if (tstatus == BUSY && SCpnt->device->type != TYPE_TAPE)
917 status = DID_ERROR << 16;
918
919
920 else if (tstatus != GOOD
921 && SCpnt->device->type == TYPE_DISK
922 && HD(j)->target_reset[SCpnt->target])
923 status = DID_BUS_BUSY << 16;
924
925
926 else if (tstatus == CHECK_CONDITION
927 && SCpnt->device->type == TYPE_DISK
928 && (SCpnt->sense_buffer[2] & 0xf) == RECOVERED_ERROR)
929 status = DID_BUS_BUSY << 16;
930
931 else
932 status = DID_OK << 16;
933
934 if (tstatus == GOOD)
935 HD(j)->target_reset[SCpnt->target] = FALSE;
936
937 if (spp->target_status && SCpnt->device->type == TYPE_DISK)
938 printk("%s: ihdlr, target %d:%d, pid %ld, target_status "\
939 "0x%x, sense key 0x%x.\n", BN(j),
940 SCpnt->target, SCpnt->lun, SCpnt->pid,
941 spp->target_status, SCpnt->sense_buffer[2]);
942
943 HD(j)->target_time_out[SCpnt->target] = 0;
944
945 break;
946 case ASST:
947
948 if (HD(j)->target_time_out[SCpnt->target] > 1)
949 status = DID_ERROR << 16;
950 else {
951 status = DID_TIME_OUT << 16;
952 HD(j)->target_time_out[SCpnt->target]++;
953 }
954
955 break;
956 case 0x92:
957 case 0x93:
958 case 0x94:
959 case 0x96:
960 case 0xa3:
961
962 if (SCpnt->device->type != TYPE_TAPE)
963 status = DID_BUS_BUSY << 16;
964 else
965 status = DID_ERROR << 16;
966
967 for (k = 0; k < MAX_TARGET; k++)
968 HD(j)->target_reset[k] = TRUE;
969
970 break;
971 case 0x01:
972 case 0x02:
973 case 0x03:
974 case 0x84:
975 case 0x9b:
976 case 0x9f:
977 case 0xff:
978 default:
979 status = DID_ERROR << 16;
980 break;
981 }
982
983 SCpnt->result = status | spp->target_status;
984 HD(j)->iocount++;
985
986 if (loops > 1) HD(j)->multicount++;
987
988 #if defined (DEBUG_INTERRUPT)
989 if (SCpnt->result || do_trace)
990 #else
991 if ((spp->adapter_status != ASOK && HD(j)->iocount > 1000) ||
992 (spp->adapter_status != ASOK &&
993 spp->adapter_status != ASST && HD(j)->iocount <= 1000) ||
994 do_trace)
995 #endif
996 printk("%s: ihdlr, mbox %d, err 0x%x:%x,"\
997 " target %d:%d, pid %ld, count %d.\n",
998 BN(j), i, spp->adapter_status, spp->target_status,
999 SCpnt->target, SCpnt->lun, SCpnt->pid, HD(j)->iocount);
1000
1001
1002 SCpnt->host_scribble = NULL;
1003
1004 restore_flags(flags);
1005 SCpnt->scsi_done(SCpnt);
1006 cli();
1007
1008 }
1009
1010 }
1011
1012 calls[irq]++;
1013
1014 if (total_loops == 0)
1015 printk("%s: ihdlr, irq %d, no command completed, calls %d.\n",
1016 driver_name, irq, calls[irq]);
1017
1018 if (do_trace) printk("%s: ihdlr, exit, irq %d, calls %d.\n",
1019 driver_name, irq, calls[irq]);
1020
1021 #if defined (DEBUG_STATISTICS)
1022 if ((calls[irq] % 100000) == 10000)
1023 for (j = 0; sh[j] != NULL; j++)
1024 printk("%s: ihdlr, calls %d, count %d, multi %d.\n", BN(j),
1025 calls[(sh[j]->irq)], HD(j)->iocount, HD(j)->multicount);
1026 #endif
1027
1028 restore_flags(flags);
1029 return;
1030 }
1031
1032 #if defined(MODULE)
1033 Scsi_Host_Template driver_template = ULTRASTOR_14_34F;
1034
1035 #include "scsi_module.c"
1036 #endif