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