Ok. I didn't make 2.4.0 in 2000. Tough. I tried, but we had some
[davej-history.git] / drivers / scsi / sym53c416.c
blob733abc939f22cc0d673a643425d8e7af1b0c1d3a
1 /*
2 * sym53c416.c
3 * Low-level SCSI driver for sym53c416 chip.
4 * Copyright (C) 1998 Lieven Willems (lw_linux@hotmail.com)
5 *
6 * Changes :
7 *
8 * Marcelo Tosatti <marcelo@conectiva.com.br> : Added io_request_lock locking
9 *
10 * LILO command line usage: sym53c416=<PORTBASE>[,<IRQ>]
12 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by the
14 * Free Software Foundation; either version 2, or (at your option) any
15 * later version.
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
24 #include <linux/module.h>
25 #include <linux/kernel.h>
26 #include <linux/types.h>
27 #include <linux/string.h>
28 #include <linux/ioport.h>
29 #include <linux/sched.h>
30 #include <linux/interrupt.h>
31 #include <linux/delay.h>
32 #include <linux/proc_fs.h>
33 #include <linux/spinlock.h>
34 #include <asm/dma.h>
35 #include <asm/system.h>
36 #include <asm/io.h>
37 #include <linux/blk.h>
38 #include <linux/version.h>
39 #include "scsi.h"
40 #include "hosts.h"
41 #include "sd.h"
42 #include "sym53c416.h"
44 #define VERSION_STRING "Version 1.0.0"
46 #define TC_LOW 0x00 /* Transfer counter low */
47 #define TC_MID 0x01 /* Transfer counter mid */
48 #define SCSI_FIFO 0x02 /* SCSI FIFO register */
49 #define COMMAND_REG 0x03 /* Command Register */
50 #define STATUS_REG 0x04 /* Status Register (READ) */
51 #define DEST_BUS_ID 0x04 /* Destination Bus ID (WRITE) */
52 #define INT_REG 0x05 /* Interrupt Register (READ) */
53 #define TOM 0x05 /* Time out multiplier (WRITE) */
54 #define STP 0x06 /* Synchronous Transfer period */
55 #define SYNC_OFFSET 0x07 /* Synchronous Offset */
56 #define CONF_REG_1 0x08 /* Configuration register 1 */
57 #define CONF_REG_2 0x0B /* Configuration register 2 */
58 #define CONF_REG_3 0x0C /* Configuration register 3 */
59 #define CONF_REG_4 0x0D /* Configuration register 4 */
60 #define TC_HIGH 0x0E /* Transfer counter high */
61 #define PIO_FIFO_1 0x10 /* PIO FIFO register 1 */
62 #define PIO_FIFO_2 0x11 /* PIO FIFO register 2 */
63 #define PIO_FIFO_3 0x12 /* PIO FIFO register 3 */
64 #define PIO_FIFO_4 0x13 /* PIO FIFO register 4 */
65 #define PIO_FIFO_CNT 0x14 /* PIO FIFO count */
66 #define PIO_INT_REG 0x15 /* PIO interrupt register */
67 #define CONF_REG_5 0x16 /* Configuration register 5 */
68 #define FEATURE_EN 0x1D /* Feature Enable register */
70 /* Configuration register 1 entries: */
71 /* Bits 2-0: SCSI ID of host adapter */
72 #define SCM 0x80 /* Slow Cable Mode */
73 #define SRID 0x40 /* SCSI Reset Interrupt Disable */
74 #define PTM 0x20 /* Parity Test Mode */
75 #define EPC 0x10 /* Enable Parity Checking */
76 #define CTME 0x08 /* Special Test Mode */
78 /* Configuration register 2 entries: */
79 #define FE 0x40 /* Features Enable */
80 #define SCSI2 0x08 /* SCSI 2 Enable */
81 #define TBPA 0x04 /* Target Bad Parity Abort */
83 /* Configuration register 3 entries: */
84 #define IDMRC 0x80 /* ID Message Reserved Check */
85 #define QTE 0x40 /* Queue Tag Enable */
86 #define CDB10 0x20 /* Command Descriptor Block 10 */
87 #define FSCSI 0x10 /* FastSCSI */
88 #define FCLK 0x08 /* FastClock */
90 /* Configuration register 4 entries: */
91 #define RBS 0x08 /* Register bank select */
92 #define EAN 0x04 /* Enable Active Negotiation */
94 /* Configuration register 5 entries: */
95 #define LPSR 0x80 /* Lower Power SCSI Reset */
96 #define IE 0x20 /* Interrupt Enable */
97 #define LPM 0x02 /* Low Power Mode */
98 #define WSE0 0x01 /* 0WS Enable */
100 /* Interrupt register entries: */
101 #define SRST 0x80 /* SCSI Reset */
102 #define ILCMD 0x40 /* Illegal Command */
103 #define DIS 0x20 /* Disconnect */
104 #define BS 0x10 /* Bus Service */
105 #define FC 0x08 /* Function Complete */
106 #define RESEL 0x04 /* Reselected */
107 #define SI 0x03 /* Selection Interrupt */
109 /* Status Register Entries: */
110 #define SCI 0x80 /* SCSI Core Int */
111 #define GE 0x40 /* Gross Error */
112 #define PE 0x20 /* Parity Error */
113 #define TC 0x10 /* Terminal Count */
114 #define VGC 0x08 /* Valid Group Code */
115 #define PHBITS 0x07 /* Phase bits */
117 /* PIO Interrupt Register Entries: */
118 #define SCI 0x80 /* SCSI Core Int */
119 #define PFI 0x40 /* PIO FIFO Interrupt */
120 #define FULL 0x20 /* PIO FIFO Full */
121 #define EMPTY 0x10 /* PIO FIFO Empty */
122 #define CE 0x08 /* Collision Error */
123 #define OUE 0x04 /* Overflow / Underflow error */
124 #define FIE 0x02 /* Full Interrupt Enable */
125 #define EIE 0x01 /* Empty Interrupt Enable */
127 /* SYM53C416 SCSI phases (lower 3 bits of SYM53C416_STATUS_REG) */
128 #define PHASE_DATA_OUT 0x00
129 #define PHASE_DATA_IN 0x01
130 #define PHASE_COMMAND 0x02
131 #define PHASE_STATUS 0x03
132 #define PHASE_RESERVED_1 0x04
133 #define PHASE_RESERVED_2 0x05
134 #define PHASE_MESSAGE_OUT 0x06
135 #define PHASE_MESSAGE_IN 0x07
137 /* SYM53C416 core commands */
138 #define NOOP 0x00
139 #define FLUSH_FIFO 0x01
140 #define RESET_CHIP 0x02
141 #define RESET_SCSI_BUS 0x03
142 #define DISABLE_SEL_RESEL 0x45
143 #define RESEL_SEQ 0x40
144 #define SEL_WITHOUT_ATN_SEQ 0x41
145 #define SEL_WITH_ATN_SEQ 0x42
146 #define SEL_WITH_ATN_AND_STOP_SEQ 0x43
147 #define ENABLE_SEL_RESEL 0x44
148 #define SEL_WITH_ATN3_SEQ 0x46
149 #define RESEL3_SEQ 0x47
150 #define SND_MSG 0x20
151 #define SND_STAT 0x21
152 #define SND_DATA 0x22
153 #define DISCONNECT_SEQ 0x23
154 #define TERMINATE_SEQ 0x24
155 #define TARGET_COMM_COMPLETE_SEQ 0x25
156 #define DISCONN 0x27
157 #define RECV_MSG_SEQ 0x28
158 #define RECV_CMD 0x29
159 #define RECV_DATA 0x2A
160 #define RECV_CMD_SEQ 0x2B
161 #define TARGET_ABORT_PIO 0x04
162 #define TRANSFER_INFORMATION 0x10
163 #define INIT_COMM_COMPLETE_SEQ 0x11
164 #define MSG_ACCEPTED 0x12
165 #define TRANSFER_PAD 0x18
166 #define SET_ATN 0x1A
167 #define RESET_ATN 0x1B
168 #define ILLEGAL 0xFF
170 #define PIO_MODE 0x80
172 #define IO_RANGE 0x20 /* 0x00 - 0x1F */
173 #define ID "sym53c416" /* Attention: copied to the sym53c416.h */
174 #define PIO_SIZE 128 /* Size of PIO fifo is 128 bytes */
176 #define READ_TIMEOUT 150
177 #define WRITE_TIMEOUT 150
179 #ifdef MODULE
181 #define sym53c416_base sym53c416
182 #define sym53c416_base_1 sym53c416_1
183 #define sym53c416_base_2 sym53c416_2
184 #define sym53c416_base_3 sym53c416_3
186 static unsigned short sym53c416_base = 0;
187 static unsigned int sym53c416_irq = 0;
188 static unsigned short sym53c416_base_1 = 0;
189 static unsigned int sym53c416_irq_1 = 0;
190 static unsigned short sym53c416_base_2 = 0;
191 static unsigned int sym53c416_irq_2 = 0;
192 static unsigned short sym53c416_base_3 = 0;
193 static unsigned int sym53c416_irq_3 = 0;
195 #endif
197 /* #define DEBUG */
199 /* Macro for debugging purposes */
201 #ifdef DEBUG
202 #define DEB(x) x
203 #else
204 #define DEB(x)
205 #endif
207 #define MAXHOSTS 4
209 enum phases
211 idle,
212 data_out,
213 data_in,
214 command_ph,
215 status_ph,
216 message_out,
217 message_in
220 typedef struct
222 int base;
223 int irq;
224 int scsi_id;
225 } host;
227 host hosts[MAXHOSTS] = {
228 {0, 0, SYM53C416_SCSI_ID},
229 {0, 0, SYM53C416_SCSI_ID},
230 {0, 0, SYM53C416_SCSI_ID},
231 {0, 0, SYM53C416_SCSI_ID}
234 static int host_index = 0;
236 static char info[120];
238 static Scsi_Cmnd *current_command = NULL;
240 int fastpio = 1;
242 int probeaddrs[] = {0x200, 0x220, 0x240, 0};
244 static void sym53c416_set_transfer_counter(int base, unsigned int len)
246 /* Program Transfer Counter */
247 outb(len & 0x0000FF, base + TC_LOW);
248 outb((len & 0x00FF00) >> 8, base + TC_MID);
249 outb((len & 0xFF0000) >> 16, base + TC_HIGH);
252 /* Returns the number of bytes read */
253 static __inline__ unsigned int sym53c416_read(int base, unsigned char *buffer, unsigned int len)
255 unsigned int orig_len = len;
256 unsigned long flags = 0;
257 unsigned int bytes_left;
258 int i;
259 int timeout = READ_TIMEOUT;
261 /* Do transfer */
262 save_flags(flags);
263 cli();
264 while(len && timeout)
266 bytes_left = inb(base + PIO_FIFO_CNT); /* Number of bytes in the PIO FIFO */
267 if(fastpio && bytes_left > 3)
269 insl(base + PIO_FIFO_1, buffer, bytes_left >> 2);
270 buffer += bytes_left & 0xFC;
271 len -= bytes_left & 0xFC;
273 else if(bytes_left > 0)
275 len -= bytes_left;
276 for(; bytes_left > 0; bytes_left--)
277 *(buffer++) = inb(base + PIO_FIFO_1);
279 else
281 i = jiffies + timeout;
282 restore_flags(flags);
283 while(jiffies < i && (inb(base + PIO_INT_REG) & EMPTY) && timeout)
284 if(inb(base + PIO_INT_REG) & SCI)
285 timeout = 0;
286 save_flags(flags);
287 cli();
288 if(inb(base + PIO_INT_REG) & EMPTY)
289 timeout = 0;
292 restore_flags(flags);
293 return orig_len - len;
296 /* Returns the number of bytes written */
297 static __inline__ unsigned int sym53c416_write(int base, unsigned char *buffer, unsigned int len)
299 unsigned int orig_len = len;
300 unsigned long flags = 0;
301 unsigned int bufferfree;
302 unsigned int i;
303 unsigned int timeout = WRITE_TIMEOUT;
305 /* Do transfer */
306 save_flags(flags);
307 cli();
308 while(len && timeout)
310 bufferfree = PIO_SIZE - inb(base + PIO_FIFO_CNT);
311 if(bufferfree > len)
312 bufferfree = len;
313 if(fastpio && bufferfree > 3)
315 outsl(base + PIO_FIFO_1, buffer, bufferfree >> 2);
316 buffer += bufferfree & 0xFC;
317 len -= bufferfree & 0xFC;
319 else if(bufferfree > 0)
321 len -= bufferfree;
322 for(; bufferfree > 0; bufferfree--)
323 outb(*(buffer++), base + PIO_FIFO_1);
325 else
327 i = jiffies + timeout;
328 restore_flags(flags);
329 while(jiffies < i && (inb(base + PIO_INT_REG) & FULL) && timeout)
331 save_flags(flags);
332 cli();
333 if(inb(base + PIO_INT_REG) & FULL)
334 timeout = 0;
337 restore_flags(flags);
338 return orig_len - len;
341 static void sym53c416_intr_handle(int irq, void *dev_id, struct pt_regs *regs)
343 int base = 0;
344 int i;
345 unsigned long flags = 0;
346 unsigned char status_reg, pio_int_reg, int_reg;
347 struct scatterlist *sglist;
348 unsigned int sgcount;
349 unsigned int tot_trans = 0;
351 /* We search the base address of the host adapter which caused the interrupt */
352 for(i = 0; i < host_index && !base; i++)
353 if(irq == hosts[i].irq)
354 base = hosts[i].base;
355 /* If no adapter found, we cannot handle the interrupt. Leave a message */
356 /* and continue. This should never happen... */
357 if(!base)
359 printk("sym53c416: No host adapter defined for interrupt %d\n", irq);
360 return;
362 /* Now we have the base address and we can start handling the interrupt */
363 save_flags(flags);
364 cli();
365 status_reg = inb(base + STATUS_REG);
366 pio_int_reg = inb(base + PIO_INT_REG);
367 int_reg = inb(base + INT_REG);
368 restore_flags(flags);
370 /* First, we handle error conditions */
371 if(int_reg & SCI) /* SCSI Reset */
373 printk("sym53c416: Warning: Reset received\n");
374 current_command->SCp.phase = idle;
375 current_command->result = DID_RESET << 16;
376 spin_lock_irqsave(&io_request_lock, flags);
377 current_command->scsi_done(current_command);
378 spin_unlock_irqrestore(&io_request_lock, flags);
379 return;
381 if(int_reg & ILCMD) /* Illegal Command */
383 printk("sym53c416: Warning: Illegal Command: 0x%02x\n", inb(base + COMMAND_REG));
384 current_command->SCp.phase = idle;
385 current_command->result = DID_ERROR << 16;
386 spin_lock_irqsave(&io_request_lock, flags);
387 current_command->scsi_done(current_command);
388 spin_unlock_irqrestore(&io_request_lock, flags);
389 return;
391 if(status_reg & GE) /* Gross Error */
393 printk("sym53c416: Warning: Gross Error\n");
394 current_command->SCp.phase = idle;
395 current_command->result = DID_ERROR << 16;
396 spin_lock_irqsave(&io_request_lock, flags);
397 current_command->scsi_done(current_command);
398 spin_unlock_irqrestore(&io_request_lock, flags);
399 return;
401 if(status_reg & PE) /* Parity Error */
403 printk("sym53c416: Warning: Parity Error\n");
404 current_command->SCp.phase = idle;
405 current_command->result = DID_PARITY << 16;
406 spin_lock_irqsave(&io_request_lock, flags);
407 current_command->scsi_done(current_command);
408 spin_unlock_irqrestore(&io_request_lock, flags);
409 return;
411 if(pio_int_reg & (CE | OUE))
413 printk("sym53c416: Warning: PIO Interrupt Error\n");
414 current_command->SCp.phase = idle;
415 current_command->result = DID_ERROR << 16;
416 spin_lock_irqsave(&io_request_lock, flags);
417 current_command->scsi_done(current_command);
418 spin_unlock_irqrestore(&io_request_lock, flags);
419 return;
421 if(int_reg & DIS) /* Disconnect */
423 if(current_command->SCp.phase != message_in)
424 current_command->result = DID_NO_CONNECT << 16;
425 else
426 current_command->result = (current_command->SCp.Status & 0xFF) | ((current_command->SCp.Message & 0xFF) << 8) | (DID_OK << 16);
427 current_command->SCp.phase = idle;
429 spin_lock_irqsave(&io_request_lock, flags);
430 current_command->scsi_done(current_command);
431 spin_unlock_irqrestore(&io_request_lock, flags);
432 return;
434 /* Now we handle SCSI phases */
435 switch(status_reg & PHBITS) /* Filter SCSI phase out of status reg */
437 case PHASE_DATA_OUT:
439 if(int_reg & BS)
441 current_command->SCp.phase = data_out;
442 outb(FLUSH_FIFO, base + COMMAND_REG);
443 sym53c416_set_transfer_counter(base, current_command->request_bufflen);
444 outb(TRANSFER_INFORMATION | PIO_MODE, base + COMMAND_REG);
445 if(!current_command->use_sg)
446 tot_trans = sym53c416_write(base, current_command->request_buffer, current_command->request_bufflen);
447 else
449 sgcount = current_command->use_sg;
450 sglist = current_command->request_buffer;
451 while(sgcount--)
453 tot_trans += sym53c416_write(base, sglist->address, sglist->length);
454 sglist++;
457 if(tot_trans < current_command->underflow)
458 printk("sym53c416: Warning: underflow, wrote %d bytes, request for %d bytes\n", tot_trans, current_command->underflow);
460 break;
462 case PHASE_DATA_IN:
464 if(int_reg & BS)
466 current_command->SCp.phase = data_in;
467 outb(FLUSH_FIFO, base + COMMAND_REG);
468 sym53c416_set_transfer_counter(base, current_command->request_bufflen);
469 outb(TRANSFER_INFORMATION | PIO_MODE, base + COMMAND_REG);
470 if(!current_command->use_sg)
471 tot_trans = sym53c416_read(base, current_command->request_buffer, current_command->request_bufflen);
472 else
474 sgcount = current_command->use_sg;
475 sglist = current_command->request_buffer;
476 while(sgcount--)
478 tot_trans += sym53c416_read(base, sglist->address, sglist->length);
479 sglist++;
482 if(tot_trans < current_command->underflow)
483 printk("sym53c416: Warning: underflow, read %d bytes, request for %d bytes\n", tot_trans, current_command->underflow);
485 break;
487 case PHASE_COMMAND:
489 current_command->SCp.phase = command_ph;
490 printk("sym53c416: Warning: Unknown interrupt in command phase\n");
491 break;
493 case PHASE_STATUS:
495 current_command->SCp.phase = status_ph;
496 outb(FLUSH_FIFO, base + COMMAND_REG);
497 outb(INIT_COMM_COMPLETE_SEQ, base + COMMAND_REG);
498 break;
500 case PHASE_RESERVED_1:
501 case PHASE_RESERVED_2:
503 printk("sym53c416: Warning: Reserved phase\n");
504 break;
506 case PHASE_MESSAGE_OUT:
508 current_command->SCp.phase = message_out;
509 outb(SET_ATN, base + COMMAND_REG);
510 outb(MSG_ACCEPTED, base + COMMAND_REG);
511 break;
513 case PHASE_MESSAGE_IN:
515 current_command->SCp.phase = message_in;
516 current_command->SCp.Status = inb(base + SCSI_FIFO);
517 current_command->SCp.Message = inb(base + SCSI_FIFO);
518 if(current_command->SCp.Message == SAVE_POINTERS || current_command->SCp.Message == DISCONNECT)
519 outb(SET_ATN, base + COMMAND_REG);
520 outb(MSG_ACCEPTED, base + COMMAND_REG);
521 break;
526 static void sym53c416_init(int base, int scsi_id)
528 outb(RESET_CHIP, base + COMMAND_REG);
529 outb(NOOP, base + COMMAND_REG);
530 outb(0x99, base + TOM); /* Time out of 250 ms */
531 outb(0x05, base + STP);
532 outb(0x00, base + SYNC_OFFSET);
533 outb(EPC | scsi_id, base + CONF_REG_1);
534 outb(FE | SCSI2 | TBPA, base + CONF_REG_2);
535 outb(IDMRC | QTE | CDB10 | FSCSI | FCLK, base + CONF_REG_3);
536 outb(0x83 | EAN, base + CONF_REG_4);
537 outb(IE | WSE0, base + CONF_REG_5);
538 outb(0, base + FEATURE_EN);
541 static int sym53c416_probeirq(int base, int scsi_id)
543 int irq, irqs, i;
545 /* Clear interrupt register */
546 inb(base + INT_REG);
547 /* Start probing for irq's */
548 irqs = probe_irq_on();
549 /* Reinit chip */
550 sym53c416_init(base, scsi_id);
551 /* Cause interrupt */
552 outb(NOOP, base + COMMAND_REG);
553 outb(ILLEGAL, base + COMMAND_REG);
554 outb(0x07, base + DEST_BUS_ID);
555 outb(0x00, base + DEST_BUS_ID);
556 /* Wait for interrupt to occur */
557 i = jiffies + 20;
558 while(i > jiffies && !(inb(base + STATUS_REG) & SCI))
559 barrier();
560 if(i <= jiffies) /* timed out */
561 return 0;
562 /* Get occurred irq */
563 irq = probe_irq_off(irqs);
564 sym53c416_init(base, scsi_id);
565 return irq;
568 /* Setup: sym53c416=base,irq */
569 void sym53c416_setup(char *str, int *ints)
571 int i;
573 if(host_index >= MAXHOSTS)
575 printk("sym53c416.c: Too many hosts defined\n");
577 else
579 if(ints[0] < 1 || ints[0] > 2)
581 printk("sym53c416.c: Wrong number of parameters:\n");
582 printk("sym53c416.c: usage: sym53c416=<base>[,<irq>]\n");
584 else
586 for(i = 0; i < host_index && i >= 0; i++)
587 if(hosts[i].base == ints[1])
588 i = -2;
589 if(i >= 0)
591 hosts[host_index].base = ints[1];
592 hosts[host_index].irq = (ints[0] == 2)? ints[2] : 0;
593 host_index++;
599 static int sym53c416_test(int base)
601 outb(RESET_CHIP, base + COMMAND_REG);
602 outb(NOOP, base + COMMAND_REG);
603 if(inb(base + COMMAND_REG) != NOOP)
604 return 0;
605 if(!inb(base + TC_HIGH) || inb(base + TC_HIGH) == 0xFF)
606 return 0;
607 if((inb(base + PIO_INT_REG) & (FULL | EMPTY | CE | OUE | FIE | EIE)) != EMPTY)
608 return 0;
609 return 1;
612 void sym53c416_probe(void)
614 int *base = probeaddrs;
615 int ints[2];
617 ints[0] = 1;
618 for(; *base; base++)
619 if(!check_region(*base, IO_RANGE) && sym53c416_test(*base))
621 ints[1] = *base;
622 sym53c416_setup(NULL, ints);
626 int sym53c416_detect(Scsi_Host_Template *tpnt)
628 unsigned long flags;
629 struct Scsi_Host * shpnt = NULL;
630 int i;
631 int count;
633 #ifdef MODULE
634 int ints[3];
636 ints[0] = 2;
637 if(sym53c416_base)
639 ints[1] = sym53c416_base;
640 ints[2] = sym53c416_irq;
641 sym53c416_setup(NULL, ints);
643 if(sym53c416_base_1)
645 ints[1] = sym53c416_base_1;
646 ints[2] = sym53c416_irq_1;
647 sym53c416_setup(NULL, ints);
649 if(sym53c416_base_2)
651 ints[1] = sym53c416_base_2;
652 ints[2] = sym53c416_irq_2;
653 sym53c416_setup(NULL, ints);
655 if(sym53c416_base_3)
657 ints[1] = sym53c416_base_3;
658 ints[2] = sym53c416_irq_3;
659 sym53c416_setup(NULL, ints);
661 #endif
663 printk("sym53c416.c: %s\n", VERSION_STRING);
665 sym53c416_probe();
667 /* Now we register and set up each host adapter found... */
668 for(count = 0, i = 0; i < host_index; i++)
669 if(!sym53c416_test(hosts[i].base))
670 printk("No sym53c416 found at address 0x%03x\n", hosts[i].base);
671 else
673 if(hosts[i].irq == 0)
674 /* We don't have an irq yet, so we should probe for one */
675 if((hosts[i].irq = sym53c416_probeirq(hosts[i].base, hosts[i].scsi_id)) == 0)
676 printk("irq autoprobing failed for sym53c416 at address 0x%03x\n", hosts[i].base);
677 if(hosts[i].irq && !check_region(hosts[i].base, IO_RANGE))
679 shpnt = scsi_register(tpnt, 0);
680 if(shpnt==NULL)
681 continue;
682 save_flags(flags);
683 cli();
684 /* Request for specified IRQ */
685 if(request_irq(hosts[i].irq, sym53c416_intr_handle, 0, ID, NULL))
687 restore_flags(flags);
688 printk("Unable to assign IRQ %d\n", hosts[i].irq);
689 scsi_unregister(shpnt);
691 else
693 /* Inform the kernel of our IO range */
694 request_region(hosts[i].base, IO_RANGE, ID);
695 shpnt->unique_id = hosts[i].base;
696 shpnt->io_port = hosts[i].base;
697 shpnt->n_io_port = IO_RANGE;
698 shpnt->irq = hosts[i].irq;
699 shpnt->this_id = hosts[i].scsi_id;
700 sym53c416_init(hosts[i].base, hosts[i].scsi_id);
701 count++;
702 restore_flags(flags);
706 return count;
709 const char *sym53c416_info(struct Scsi_Host *SChost)
711 int i;
712 int base = SChost->io_port;
713 int irq = SChost->irq;
714 int scsi_id = 0;
715 int rev = inb(base + TC_HIGH);
717 for(i = 0; i < host_index; i++)
718 if(hosts[i].base == base)
719 scsi_id = hosts[i].scsi_id;
720 sprintf(info, "Symbios Logic 53c416 (rev. %d) at 0x%03x, irq %d, SCSI-ID %d, %s pio", rev, base, irq, scsi_id, (fastpio)? "fast" : "slow");
721 return info;
724 int sym53c416_queuecommand(Scsi_Cmnd *SCpnt, void (*done)(Scsi_Cmnd *))
726 int base;
727 unsigned long flags = 0;
728 int i;
730 /* Store base register as we can have more than one controller in the system */
731 base = SCpnt->host->io_port;
732 current_command = SCpnt; /* set current command */
733 current_command->scsi_done = done; /* set ptr to done function */
734 current_command->SCp.phase = command_ph; /* currect phase is the command phase */
735 current_command->SCp.Status = 0;
736 current_command->SCp.Message = 0;
738 save_flags(flags);
739 cli();
740 outb(SCpnt->target, base + DEST_BUS_ID); /* Set scsi id target */
741 outb(FLUSH_FIFO, base + COMMAND_REG); /* Flush SCSI and PIO FIFO's */
742 /* Write SCSI command into the SCSI fifo */
743 for(i = 0; i < SCpnt->cmd_len; i++)
744 outb(SCpnt->cmnd[i], base + SCSI_FIFO);
745 /* Start selection sequence */
746 outb(SEL_WITHOUT_ATN_SEQ, base + COMMAND_REG);
747 /* Now an interrupt will be generated which we will catch in out interrupt routine */
748 restore_flags(flags);
749 return 0;
752 static void internal_done(Scsi_Cmnd *SCpnt)
754 SCpnt->SCp.Status++;
757 int sym53c416_command(Scsi_Cmnd *SCpnt)
759 sym53c416_queuecommand(SCpnt, internal_done);
760 SCpnt->SCp.Status = 0;
761 while(!SCpnt->SCp.Status)
762 barrier();
763 return SCpnt->result;
766 int sym53c416_abort(Scsi_Cmnd *SCpnt)
768 printk("sym53c416_abort\n");
770 /* We don't know how to abort for the moment */
771 return SCSI_ABORT_SNOOZE;
774 int sym53c416_reset(Scsi_Cmnd *SCpnt, unsigned int reset_flags)
776 int base;
777 int scsi_id = -1;
778 int i;
780 printk("sym53c416_reset\n");
781 base = SCpnt->host->io_port;
782 /* search scsi_id */
783 for(i = 0; i < host_index && scsi_id != -1; i++)
784 if(hosts[i].base == base)
785 scsi_id = hosts[i].scsi_id;
786 outb(RESET_CHIP, base + COMMAND_REG);
787 outb(NOOP | PIO_MODE, base + COMMAND_REG);
788 outb(RESET_SCSI_BUS, base + COMMAND_REG);
789 sym53c416_init(base, scsi_id);
790 return SCSI_RESET_PENDING;
793 int sym53c416_bios_param(Disk *disk, kdev_t dev, int *ip)
795 int size;
797 size = disk->capacity;
798 ip[0] = 64; /* heads */
799 ip[1] = 32; /* sectors */
800 if((ip[2] = size >> 11) > 1024) /* cylinders, test for big disk */
802 ip[0] = 255; /* heads */
803 ip[1] = 63; /* sectors */
804 ip[2] = size / (255 * 63); /* cylinders */
806 return 0;
809 /* Loadable module support */
810 #ifdef MODULE
812 MODULE_AUTHOR("Lieven Willems");
813 MODULE_PARM(sym53c416, "1-2i");
814 MODULE_PARM(sym53c416_1, "1-2i");
815 MODULE_PARM(sym53c416_2, "1-2i");
816 MODULE_PARM(sym53c416_3, "1-2i");
818 #endif
820 static Scsi_Host_Template driver_template = SYM53C416;
822 #include "scsi_module.c"