3 * Low-level SCSI driver for sym53c416 chip.
4 * Copyright (C) 1998 Lieven Willems (lw_linux@hotmail.com)
8 * Marcelo Tosatti <marcelo@conectiva.com.br> : Added io_request_lock locking
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
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>
35 #include <asm/system.h>
37 #include <linux/blk.h>
38 #include <linux/version.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 */
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
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
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
167 #define RESET_ATN 0x1B
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
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;
199 /* Macro for debugging purposes */
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
;
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
;
259 int timeout
= READ_TIMEOUT
;
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)
276 for(; bytes_left
> 0; bytes_left
--)
277 *(buffer
++) = inb(base
+ PIO_FIFO_1
);
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
)
288 if(inb(base
+ PIO_INT_REG
) & EMPTY
)
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
;
303 unsigned int timeout
= WRITE_TIMEOUT
;
308 while(len
&& timeout
)
310 bufferfree
= PIO_SIZE
- inb(base
+ PIO_FIFO_CNT
);
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)
322 for(; bufferfree
> 0; bufferfree
--)
323 outb(*(buffer
++), base
+ PIO_FIFO_1
);
327 i
= jiffies
+ timeout
;
328 restore_flags(flags
);
329 while(jiffies
< i
&& (inb(base
+ PIO_INT_REG
) & FULL
) && timeout
)
333 if(inb(base
+ PIO_INT_REG
) & FULL
)
337 restore_flags(flags
);
338 return orig_len
- len
;
341 static void sym53c416_intr_handle(int irq
, void *dev_id
, struct pt_regs
*regs
)
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... */
359 printk("sym53c416: No host adapter defined for interrupt %d\n", irq
);
362 /* Now we have the base address and we can start handling the interrupt */
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
);
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
);
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
);
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
);
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
);
421 if(int_reg
& DIS
) /* Disconnect */
423 if(current_command
->SCp
.phase
!= message_in
)
424 current_command
->result
= DID_NO_CONNECT
<< 16;
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
);
434 /* Now we handle SCSI phases */
435 switch(status_reg
& PHBITS
) /* Filter SCSI phase out of status reg */
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
);
449 sgcount
= current_command
->use_sg
;
450 sglist
= current_command
->request_buffer
;
453 tot_trans
+= sym53c416_write(base
, sglist
->address
, sglist
->length
);
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
);
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
);
474 sgcount
= current_command
->use_sg
;
475 sglist
= current_command
->request_buffer
;
478 tot_trans
+= sym53c416_read(base
, sglist
->address
, sglist
->length
);
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
);
489 current_command
->SCp
.phase
= command_ph
;
490 printk("sym53c416: Warning: Unknown interrupt in command phase\n");
495 current_command
->SCp
.phase
= status_ph
;
496 outb(FLUSH_FIFO
, base
+ COMMAND_REG
);
497 outb(INIT_COMM_COMPLETE_SEQ
, base
+ COMMAND_REG
);
500 case PHASE_RESERVED_1
:
501 case PHASE_RESERVED_2
:
503 printk("sym53c416: Warning: Reserved phase\n");
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
);
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
);
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
)
545 /* Clear interrupt register */
547 /* Start probing for irq's */
548 irqs
= probe_irq_on();
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 */
558 while(i
> jiffies
&& !(inb(base
+ STATUS_REG
) & SCI
))
560 if(i
<= jiffies
) /* timed out */
562 /* Get occurred irq */
563 irq
= probe_irq_off(irqs
);
564 sym53c416_init(base
, scsi_id
);
568 /* Setup: sym53c416=base,irq */
569 void sym53c416_setup(char *str
, int *ints
)
573 if(host_index
>= MAXHOSTS
)
575 printk("sym53c416.c: Too many hosts defined\n");
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");
586 for(i
= 0; i
< host_index
&& i
>= 0; i
++)
587 if(hosts
[i
].base
== ints
[1])
591 hosts
[host_index
].base
= ints
[1];
592 hosts
[host_index
].irq
= (ints
[0] == 2)? ints
[2] : 0;
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
)
605 if(!inb(base
+ TC_HIGH
) || inb(base
+ TC_HIGH
) == 0xFF)
607 if((inb(base
+ PIO_INT_REG
) & (FULL
| EMPTY
| CE
| OUE
| FIE
| EIE
)) != EMPTY
)
612 void sym53c416_probe(void)
614 int *base
= probeaddrs
;
619 if(!check_region(*base
, IO_RANGE
) && sym53c416_test(*base
))
622 sym53c416_setup(NULL
, ints
);
626 int sym53c416_detect(Scsi_Host_Template
*tpnt
)
629 struct Scsi_Host
* shpnt
= NULL
;
639 ints
[1] = sym53c416_base
;
640 ints
[2] = sym53c416_irq
;
641 sym53c416_setup(NULL
, ints
);
645 ints
[1] = sym53c416_base_1
;
646 ints
[2] = sym53c416_irq_1
;
647 sym53c416_setup(NULL
, ints
);
651 ints
[1] = sym53c416_base_2
;
652 ints
[2] = sym53c416_irq_2
;
653 sym53c416_setup(NULL
, ints
);
657 ints
[1] = sym53c416_base_3
;
658 ints
[2] = sym53c416_irq_3
;
659 sym53c416_setup(NULL
, ints
);
663 printk("sym53c416.c: %s\n", VERSION_STRING
);
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
);
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);
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
);
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
);
702 restore_flags(flags
);
709 const char *sym53c416_info(struct Scsi_Host
*SChost
)
712 int base
= SChost
->io_port
;
713 int irq
= SChost
->irq
;
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");
724 int sym53c416_queuecommand(Scsi_Cmnd
*SCpnt
, void (*done
)(Scsi_Cmnd
*))
727 unsigned long flags
= 0;
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;
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
);
752 static void internal_done(Scsi_Cmnd
*SCpnt
)
757 int sym53c416_command(Scsi_Cmnd
*SCpnt
)
759 sym53c416_queuecommand(SCpnt
, internal_done
);
760 SCpnt
->SCp
.Status
= 0;
761 while(!SCpnt
->SCp
.Status
)
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
)
780 printk("sym53c416_reset\n");
781 base
= SCpnt
->host
->io_port
;
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
)
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 */
809 /* Loadable module support */
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");
820 static Scsi_Host_Template driver_template
= SYM53C416
;
822 #include "scsi_module.c"