3 * Low-level SCSI driver for NCR53c406a chip.
4 * Copyright (C) 1994, 1995, 1996 Normunds Saumanis (normunds@fi.ibm.com)
6 * LILO command line usage: ncr53c406a=<PORTBASE>[,<IRQ>[,<FASTPIO>]]
7 * Specify IRQ = 0 for non-interrupt driven mode.
8 * FASTPIO = 1 for fast pio mode, 0 for slow mode.
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by the
12 * Free Software Foundation; either version 2, or (at your option) any
15 * This program is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
22 #define NCR53C406A_DEBUG 0
23 #define VERBOSE_NCR53C406A_DEBUG 0
25 /* Set this to 1 for PIO mode (recommended) or to 0 for DMA mode */
29 /* #define BIOS_ADDR 0xD8000 */ /* define this if autoprobe fails */
30 /* #define PORT_BASE 0x330 */ /* define this if autoprobe fails */
31 /* #define IRQ_LEV 0 */ /* define this if autoprobe fails */
32 #define DMA_CHAN 5 /* this is ignored if DMA is disabled */
34 /* Set this to 0 if you encounter kernel lockups while transferring
36 #define USE_FAST_PIO 1
38 /* ============= End of user configurable parameters ============= */
40 #include <linux/module.h>
42 #include <linux/errno.h>
43 #include <linux/ioport.h>
44 #include <linux/sched.h>
45 #include <linux/interrupt.h>
46 #include <linux/proc_fs.h>
47 #include <linux/stat.h>
48 #include <linux/init.h>
51 #include <asm/bitops.h>
54 #include <linux/blk.h>
55 #include <linux/spinlock.h>
60 #include "NCR53c406a.h"
62 /* ============================================================= */
64 #define WATCHDOG 5000000
66 #define SYNC_MODE 0 /* Synchronous transfer mode */
69 #undef NCR53C406A_DEBUG
70 #define NCR53C406A_DEBUG 1
79 /* Default configuration */
80 #define C1_IMG 0x07 /* ID=7 */
81 #define C2_IMG 0x48 /* FE SCSI2 */
83 #define C3_IMG 0x21 /* CDB TE */
85 #define C3_IMG 0x20 /* CDB */
87 #define C4_IMG 0x04 /* ANE */
88 #define C5_IMG 0xb6 /* AA PI SIE POL */
90 #define REG0 (outb(C4_IMG, CONFIG4))
91 #define REG1 (outb(C5_IMG, CONFIG5))
99 #if VERBOSE_NCR53C406A_DEBUG
105 #define LOAD_DMA_COUNT(count) \
106 outb(count & 0xff, TC_LSB); \
107 outb((count >> 8) & 0xff, TC_MSB); \
108 outb((count >> 16) & 0xff, TC_HIGH);
113 #define SCSI_NOP 0x00
114 #define FLUSH_FIFO 0x01
115 #define CHIP_RESET 0x02
116 #define SCSI_RESET 0x03
117 #define RESELECT 0x40
118 #define SELECT_NO_ATN 0x41
119 #define SELECT_ATN 0x42
120 #define SELECT_ATN_STOP 0x43
121 #define ENABLE_SEL 0x44
122 #define DISABLE_SEL 0x45
123 #define SELECT_ATN3 0x46
124 #define RESELECT3 0x47
125 #define TRANSFER_INFO 0x10
126 #define INIT_CMD_COMPLETE 0x11
127 #define MSG_ACCEPT 0x12
128 #define TRANSFER_PAD 0x18
130 #define RESET_ATN 0x1b
131 #define SEND_MSG 0x20
132 #define SEND_STATUS 0x21
133 #define SEND_DATA 0x22
134 #define DISCONN_SEQ 0x23
135 #define TERMINATE_SEQ 0x24
136 #define TARG_CMD_COMPLETE 0x25
138 #define RECV_MSG 0x28
139 #define RECV_CMD 0x29
140 #define RECV_DATA 0x2a
141 #define RECV_CMD_SEQ 0x2b
142 #define TARGET_ABORT_DMA 0x04
144 /*----------------------------------------------------------------*/
145 /* the following will set the monitor border color (useful to find
146 where something crashed or gets stuck at */
157 #define rtrc(i) {inb(0x3da);outb(0x31,0x3c0);outb((i),0x3c0);}
161 /*----------------------------------------------------------------*/
173 /* Static function prototypes */
174 static void NCR53c406a_intr(int, void *, struct pt_regs
*);
175 static void do_NCR53c406a_intr(int, void *, struct pt_regs
*);
176 static void internal_done(Scsi_Cmnd
*);
177 static void wait_intr(void);
178 static void chip_init(void);
179 static void calc_port_addr(void);
181 static int irq_probe(void);
184 /* ================================================================= */
187 static void *bios_base
= (void *)0;
191 static int port_base
= PORT_BASE
;
193 static int port_base
= 0;
197 static int irq_level
= IRQ_LEV
;
199 static int irq_level
= -1; /* 0 is 'no irq', so use -1 for 'uninitialized'*/
203 static int dma_chan
= 0;
207 static int fast_pio
= USE_FAST_PIO
;
210 static Scsi_Cmnd
*current_SC
= NULL
;
211 static volatile int internal_done_flag
= 0;
212 static volatile int internal_done_errcode
= 0;
213 static char info_msg
[256];
215 /* ================================================================= */
217 /* possible BIOS locations */
219 static void *addresses
[] = {
223 #define ADDRESS_COUNT (sizeof( addresses ) / sizeof( unsigned ))
226 /* possible i/o port addresses */
227 static unsigned short ports
[] =
228 { 0x230, 0x330, 0x280, 0x290, 0x330, 0x340, 0x300, 0x310, 0x348, 0x350 };
229 #define PORT_COUNT (sizeof( ports ) / sizeof( unsigned short ))
231 /* possible interrupt channels */
232 static unsigned short intrs
[] = { 10, 11, 12, 15 };
233 #define INTR_COUNT (sizeof( intrs ) / sizeof( unsigned short ))
235 /* signatures for NCR 53c406a based controllers */
241 } signatures
[] __initdata
= {
243 /* 123456789012345678901234567890123456789012345678901234567890 */
244 { "Copyright (C) Acculogic, Inc.\r\n2.8M Diskette Extension Bios ver 4.04.03 03/01/1993", 61, 82 },
246 #define SIGNATURE_COUNT (sizeof( signatures ) / sizeof( struct signature ))
249 /* ============================================================ */
251 /* Control Register Set 0 */
252 static int TC_LSB
; /* transfer counter lsb */
253 static int TC_MSB
; /* transfer counter msb */
254 static int SCSI_FIFO
; /* scsi fifo register */
255 static int CMD_REG
; /* command register */
256 static int STAT_REG
; /* status register */
257 static int DEST_ID
; /* selection/reselection bus id */
258 static int INT_REG
; /* interrupt status register */
259 static int SRTIMOUT
; /* select/reselect timeout reg */
260 static int SEQ_REG
; /* sequence step register */
261 static int SYNCPRD
; /* synchronous transfer period */
262 static int FIFO_FLAGS
; /* indicates # of bytes in fifo */
263 static int SYNCOFF
; /* synchronous offset register */
264 static int CONFIG1
; /* configuration register */
265 static int CLKCONV
; /* clock conversion reg */
266 /*static int TESTREG;*/ /* test mode register */
267 static int CONFIG2
; /* Configuration 2 Register */
268 static int CONFIG3
; /* Configuration 3 Register */
269 static int CONFIG4
; /* Configuration 4 Register */
270 static int TC_HIGH
; /* Transfer Counter High */
271 /*static int FIFO_BOTTOM;*/ /* Reserve FIFO byte register */
273 /* Control Register Set 1 */
274 /*static int JUMPER_SENSE;*/ /* Jumper sense port reg (r/w) */
275 /*static int SRAM_PTR;*/ /* SRAM address pointer reg (r/w) */
276 /*static int SRAM_DATA;*/ /* SRAM data register (r/w) */
277 static int PIO_FIFO
; /* PIO FIFO registers (r/w) */
278 /*static int PIO_FIFO1;*/ /* */
279 /*static int PIO_FIFO2;*/ /* */
280 /*static int PIO_FIFO3;*/ /* */
281 static int PIO_STATUS
; /* PIO status (r/w) */
282 /*static int ATA_CMD;*/ /* ATA command/status reg (r/w) */
283 /*static int ATA_ERR;*/ /* ATA features/error register (r/w)*/
284 static int PIO_FLAG
; /* PIO flag interrupt enable (r/w) */
285 static int CONFIG5
; /* Configuration 5 register (r/w) */
286 /*static int SIGNATURE;*/ /* Signature Register (r) */
287 /*static int CONFIG6;*/ /* Configuration 6 register (r) */
289 /* ============================================================== */
292 static __inline__
int
293 NCR53c406a_dma_setup (unsigned char *ptr
,
295 unsigned char mode
) {
297 unsigned long flags
= 0;
299 VDEB(printk("dma: before count=%d ", count
));
303 limit
= 65536 - (((unsigned) ptr
) & 0xFFFF);
305 if (count
> (65536<<1))
307 limit
= (65536<<1) - (((unsigned) ptr
) & 0x1FFFF);
310 if (count
> limit
) count
= limit
;
312 VDEB(printk("after count=%d\n", count
));
313 if ((count
& 1) || (((unsigned) ptr
) & 1))
314 panic ("NCR53c406a: attempted unaligned DMA transfer\n");
316 flags
=claim_dma_lock();
317 disable_dma(dma_chan
);
318 clear_dma_ff(dma_chan
);
319 set_dma_addr(dma_chan
, (long) ptr
);
320 set_dma_count(dma_chan
, count
);
321 set_dma_mode(dma_chan
, mode
);
322 enable_dma(dma_chan
);
323 release_dma_lock(flags
);
328 static __inline__
int
329 NCR53c406a_dma_write(unsigned char *src
, unsigned int count
) {
330 return NCR53c406a_dma_setup (src
, count
, DMA_MODE_WRITE
);
333 static __inline__
int
334 NCR53c406a_dma_read(unsigned char *src
, unsigned int count
) {
335 return NCR53c406a_dma_setup (src
, count
, DMA_MODE_READ
);
338 static __inline__
int
339 NCR53c406a_dma_residual (void) {
343 flags
=claim_dma_lock();
344 clear_dma_ff(dma_chan
);
345 tmp
= get_dma_residue(dma_chan
);
346 release_dma_lock(flags
);
353 static __inline__
int NCR53c406a_pio_read(unsigned char *request
,
357 int len
; /* current scsi fifo size */
358 unsigned long flags
= 0;
363 /* VDEB(printk("pio_status=%x\n", i)); */
381 if ((i
& 0x40) && len
== 0) { /* fifo empty and interrupt occurred */
391 if( fast_pio
&& len
> 3 ) {
392 insl(PIO_FIFO
,request
,len
>>2);
393 request
+= len
& 0xfc;
394 reqlen
-= len
& 0xfc;
398 *request
++ = inb(PIO_FIFO
);
402 restore_flags(flags
);
408 static __inline__
int NCR53c406a_pio_write(unsigned char *request
,
412 int len
; /* current scsi fifo size */
413 unsigned long flags
= 0;
416 while (reqlen
&& !(i
&0x40)) {
418 /* VDEB(printk("pio_status=%x\n", i)); */
419 if (i
& 0x80) /* error */
442 if( fast_pio
&& len
> 3 ) {
443 outsl(PIO_FIFO
,request
,len
>>2);
444 request
+= len
& 0xfc;
445 reqlen
-= len
& 0xfc;
449 outb(*request
++, PIO_FIFO
);
453 restore_flags(flags
);
461 NCR53c406a_detect(Scsi_Host_Template
* tpnt
){
462 struct Scsi_Host
*shpnt
;
470 /* look for a valid signature */
471 for( ii
=0; ii
< ADDRESS_COUNT
&& !bios_base
; ii
++)
472 for( jj
=0; (jj
< SIGNATURE_COUNT
) && !bios_base
; jj
++)
473 if(!memcmp((void *) addresses
[ii
]+signatures
[jj
].sig_offset
,
474 (void *) signatures
[jj
].signature
,
475 (int) signatures
[jj
].sig_length
))
476 bios_base
=addresses
[ii
];
479 printk("NCR53c406a: BIOS signature not found\n");
483 DEB(printk("NCR53c406a BIOS found at %X\n", (unsigned int) bios_base
););
487 if (check_region(port_base
, 0x10)) /* ports already snatched */
490 #else /* autodetect */
491 if (port_base
) { /* LILO override */
492 if (check_region(port_base
, 0x10))
496 for(i
=0; i
<PORT_COUNT
&& !port_base
; i
++){
497 if(check_region(ports
[i
], 0x10)){
498 DEB(printk("NCR53c406a: port %x in use\n", ports
[i
]));
501 VDEB(printk("NCR53c406a: port %x available\n", ports
[i
]));
502 outb(C5_IMG
, ports
[i
] + 0x0d); /* reg set 1 */
503 if( (inb(ports
[i
] + 0x0e) ^ inb(ports
[i
] + 0x0e)) == 7
504 && (inb(ports
[i
] + 0x0e) ^ inb(ports
[i
] + 0x0e)) == 7
505 && (inb(ports
[i
] + 0x0e) & 0xf8) == 0x58 ) {
506 VDEB(printk("NCR53c406a: Sig register valid\n"));
507 VDEB(printk("port_base=%x\n", port_base
));
508 port_base
= ports
[i
];
515 if(!port_base
){ /* no ports found */
516 printk("NCR53c406a: no available ports found\n");
520 DEB(printk("NCR53c406a detected\n"));
526 if (irq_level
< 0) { /* LILO override if >= 0*/
527 irq_level
=irq_probe();
528 if (irq_level
< 0) { /* Trouble */
529 printk("NCR53c406a: IRQ problem, irq_level=%d, giving up\n", irq_level
);
535 DEB(printk("NCR53c406a: using port_base %x\n", port_base
));
536 request_region(port_base
, 0x10, "NCR53c406a");
539 if(request_irq(irq_level
, do_NCR53c406a_intr
, 0, "NCR53c406a", NULL
)){
540 printk("NCR53c406a: unable to allocate IRQ %d\n", irq_level
);
544 DEB(printk("NCR53c406a: allocated IRQ %d\n", irq_level
));
546 else if (irq_level
== 0) {
548 DEB(printk("NCR53c406a: No interrupts detected\n"));
550 printk("NCR53c406a: No interrupts found and DMA mode defined. Giving up.\n");
555 DEB(printk("NCR53c406a: Shouldn't get here!\n"));
561 if(request_dma(dma_chan
, "NCR53c406a") != 0){
562 printk("NCR53c406a: unable to allocate DMA channel %d\n", dma_chan
);
566 DEB(printk("Allocated DMA channel %d\n", dma_chan
));
570 tpnt
->proc_name
= "NCR53c406a";
572 shpnt
= scsi_register(tpnt
, 0);
573 shpnt
->irq
= irq_level
;
574 shpnt
->io_port
= port_base
;
575 shpnt
->n_io_port
= 0x10;
577 shpnt
->dma
= dma_chan
;
581 sprintf(info_msg
, "NCR53c406a at 0x%x, IRQ %d, DMA channel %d.",
582 port_base
, irq_level
, dma_chan
);
584 sprintf(info_msg
, "NCR53c406a at 0x%x, IRQ %d, %s PIO mode.",
585 port_base
, irq_level
, fast_pio
? "fast" : "slow");
588 return (tpnt
->present
);
591 /* called from init/main.c */
592 void __init
NCR53c406a_setup(char *str
, int *ints
)
594 static size_t setup_idx
= 0;
597 DEB(printk("NCR53c406a: Setup called\n"););
599 if (setup_idx
>= PORT_COUNT
- 1) {
600 printk("NCR53c406a: Setup called too many times. Bad LILO params?\n");
603 if (ints
[0] < 1 || ints
[0] > 3) {
604 printk("NCR53c406a: Malformed command line\n");
605 printk("NCR53c406a: Usage: ncr53c406a=<PORTBASE>[,<IRQ>[,<FASTPIO>]]\n");
608 for (i
= 0; i
< PORT_COUNT
&& !port_base
; i
++)
609 if (ports
[i
] == ints
[1]) {
611 DEB(printk("NCR53c406a: Specified port_base 0x%X\n", port_base
);)
614 printk("NCR53c406a: Invalid PORTBASE 0x%X specified\n", ints
[1]);
621 DEB(printk("NCR53c406a: Specified irq %d\n", irq_level
);)
624 for (i
= 0; i
< INTR_COUNT
&& irq_level
< 0; i
++)
625 if (intrs
[i
] == ints
[2]) {
627 DEB(printk("NCR53c406a: Specified irq %d\n", port_base
);)
630 printk("NCR53c406a: Invalid IRQ %d specified\n", ints
[2]);
636 DEB(printk("NCR53c406a: port_base=0x%X, irq=%d, fast_pio=%d\n",
637 port_base
, irq_level
, fast_pio
);)
641 NCR53c406a_info(struct Scsi_Host
*SChost
){
642 DEB(printk("NCR53c406a_info called\n"));
646 static void internal_done(Scsi_Cmnd
*SCpnt
) {
647 internal_done_errcode
= SCpnt
->result
;
648 ++internal_done_flag
;
652 static void wait_intr() {
653 int i
= jiffies
+ WATCHDOG
;
655 while(time_after(i
,jiffies
) && !(inb(STAT_REG
)&0xe0)) /* wait for a pseudo-interrupt */
658 if (time_before_eq(i
,jiffies
)) { /* Timed out */
660 current_SC
->result
= DID_TIME_OUT
<< 16;
661 current_SC
->SCp
.phase
= idle
;
662 current_SC
->scsi_done(current_SC
);
666 NCR53c406a_intr(0, NULL
, NULL
);
669 int NCR53c406a_command(Scsi_Cmnd
*SCpnt
){
670 DEB(printk("NCR53c406a_command called\n"));
671 NCR53c406a_queue(SCpnt
, internal_done
);
673 while (!internal_done_flag
);
674 else /* interrupts not supported */
675 while (!internal_done_flag
)
678 internal_done_flag
= 0;
679 return internal_done_errcode
;
684 NCR53c406a_queue(Scsi_Cmnd
*SCpnt
, void (*done
)(Scsi_Cmnd
*)){
686 unsigned long flags
= 0;
688 VDEB(printk("NCR53c406a_queue called\n"));
689 DEB(printk("cmd=%02x, cmd_len=%02x, target=%02x, lun=%02x, bufflen=%d\n",
694 SCpnt
->request_bufflen
));
697 VDEB(for(i
=0; i
<SCpnt
->cmd_len
; i
++)
698 printk("cmd[%d]=%02x ", i
, SCpnt
->cmnd
[i
]));
703 current_SC
->scsi_done
= done
;
704 current_SC
->SCp
.phase
= command_ph
;
705 current_SC
->SCp
.Status
= 0;
706 current_SC
->SCp
.Message
= 0;
711 outb(SCpnt
->target
, DEST_ID
); /* set destination */
712 outb(FLUSH_FIFO
, CMD_REG
); /* reset the fifos */
714 for(i
=0; i
<SCpnt
->cmd_len
; i
++){
715 outb(SCpnt
->cmnd
[i
], SCSI_FIFO
);
717 outb(SELECT_NO_ATN
, CMD_REG
);
718 restore_flags(flags
);
725 NCR53c406a_abort(Scsi_Cmnd
*SCpnt
){
726 DEB(printk("NCR53c406a_abort called\n"));
727 return SCSI_ABORT_SNOOZE
; /* Don't know how to abort */
731 NCR53c406a_reset(Scsi_Cmnd
*SCpnt
, unsigned int ignored
){
732 DEB(printk("NCR53c406a_reset called\n"));
733 outb(C4_IMG
, CONFIG4
); /* Select reg set 0 */
734 outb(CHIP_RESET
, CMD_REG
);
735 outb(SCSI_NOP
, CMD_REG
); /* required after reset */
736 outb(SCSI_RESET
, CMD_REG
);
741 return SCSI_RESET_PENDING
; /* should get an interrupt */
743 return SCSI_RESET_WAKEUP
; /* won't get any interrupts */
747 NCR53c406a_biosparm(Scsi_Disk
*disk
, kdev_t dev
, int* info_array
){
750 DEB(printk("NCR53c406a_biosparm called\n"));
752 size
= disk
->capacity
;
753 info_array
[0] = 64; /* heads */
754 info_array
[1] = 32; /* sectors */
755 info_array
[2] = size
>>11; /* cylinders */
756 if (info_array
[2] > 1024) { /* big disk */
759 info_array
[2] = size
/ (255*63);
765 do_NCR53c406a_intr(int unused
, void *dev_id
, struct pt_regs
*regs
){
768 spin_lock_irqsave(&io_request_lock
, flags
);
769 NCR53c406a_intr(0, dev_id
, regs
);
770 spin_unlock_irqrestore(&io_request_lock
, flags
);
774 NCR53c406a_intr(int unused
, void *dev_id
, struct pt_regs
*regs
){
775 DEB(unsigned char fifo_size
;)
776 DEB(unsigned char seq_reg
;)
777 unsigned char status
, int_reg
;
778 unsigned long flags
= 0;
780 unsigned char pio_status
;
781 struct scatterlist
*sglist
;
782 unsigned int sgcount
;
785 VDEB(printk("NCR53c406a_intr called\n"));
791 pio_status
= inb(PIO_STATUS
);
794 status
= inb(STAT_REG
);
795 DEB(seq_reg
= inb(SEQ_REG
));
796 int_reg
= inb(INT_REG
);
797 DEB(fifo_size
= inb(FIFO_FLAGS
) & 0x1f);
798 restore_flags(flags
);
801 printk("status=%02x, seq_reg=%02x, int_reg=%02x, fifo_size=%02x",
802 status
, seq_reg
, int_reg
, fifo_size
);
806 printk(", pio=%02x\n", pio_status
);
808 #endif NCR53C406A_DEBUG
810 if(int_reg
& 0x80){ /* SCSI reset intr */
812 DEB(printk("NCR53c406a: reset intr received\n"));
813 current_SC
->SCp
.phase
= idle
;
814 current_SC
->result
= DID_RESET
<< 16;
815 current_SC
->scsi_done(current_SC
);
820 if(pio_status
& 0x80) {
821 printk("NCR53C406A: Warning: PIO error!\n");
822 current_SC
->SCp
.phase
= idle
;
823 current_SC
->result
= DID_ERROR
<< 16;
824 current_SC
->scsi_done(current_SC
);
829 if(status
& 0x20) { /* Parity error */
830 printk("NCR53c406a: Warning: parity error!\n");
831 current_SC
->SCp
.phase
= idle
;
832 current_SC
->result
= DID_PARITY
<< 16;
833 current_SC
->scsi_done(current_SC
);
837 if(status
& 0x40) { /* Gross error */
838 printk("NCR53c406a: Warning: gross error!\n");
839 current_SC
->SCp
.phase
= idle
;
840 current_SC
->result
= DID_ERROR
<< 16;
841 current_SC
->scsi_done(current_SC
);
845 if(int_reg
& 0x20){ /* Disconnect */
846 DEB(printk("NCR53c406a: disconnect intr received\n"));
847 if(current_SC
->SCp
.phase
!= message_in
){ /* Unexpected disconnect */
848 current_SC
->result
= DID_NO_CONNECT
<< 16;
850 else{ /* Command complete, return status and message */
851 current_SC
->result
= (current_SC
->SCp
.Status
& 0xff)
852 | ((current_SC
->SCp
.Message
& 0xff) << 8) | (DID_OK
<< 16);
856 current_SC
->SCp
.phase
= idle
;
857 current_SC
->scsi_done( current_SC
);
861 switch(status
& 0x07){ /* scsi phase */
862 case 0x00: /* DATA-OUT */
863 if(int_reg
& 0x10){ /* Target requesting info transfer */
865 current_SC
->SCp
.phase
= data_out
;
866 VDEB(printk("NCR53c406a: Data-Out phase\n"));
867 outb(FLUSH_FIFO
, CMD_REG
);
868 LOAD_DMA_COUNT(current_SC
->request_bufflen
); /* Max transfer size */
869 #if USE_DMA /* No s/g support for DMA */
870 NCR53c406a_dma_write(current_SC
->request_buffer
,
871 current_SC
->request_bufflen
);
873 outb(TRANSFER_INFO
| DMA_OP
, CMD_REG
);
875 if (!current_SC
->use_sg
) /* Don't use scatter-gather */
876 NCR53c406a_pio_write(current_SC
->request_buffer
,
877 current_SC
->request_bufflen
);
878 else { /* use scatter-gather */
879 sgcount
= current_SC
->use_sg
;
880 sglist
= current_SC
->request_buffer
;
882 NCR53c406a_pio_write(sglist
->address
, sglist
->length
);
891 case 0x01: /* DATA-IN */
892 if(int_reg
& 0x10){ /* Target requesting info transfer */
894 current_SC
->SCp
.phase
= data_in
;
895 VDEB(printk("NCR53c406a: Data-In phase\n"));
896 outb(FLUSH_FIFO
, CMD_REG
);
897 LOAD_DMA_COUNT(current_SC
->request_bufflen
); /* Max transfer size */
898 #if USE_DMA /* No s/g support for DMA */
899 NCR53c406a_dma_read(current_SC
->request_buffer
,
900 current_SC
->request_bufflen
);
902 outb(TRANSFER_INFO
| DMA_OP
, CMD_REG
);
904 if (!current_SC
->use_sg
) /* Don't use scatter-gather */
905 NCR53c406a_pio_read(current_SC
->request_buffer
,
906 current_SC
->request_bufflen
);
907 else { /* Use scatter-gather */
908 sgcount
= current_SC
->use_sg
;
909 sglist
= current_SC
->request_buffer
;
911 NCR53c406a_pio_read(sglist
->address
, sglist
->length
);
920 case 0x02: /* COMMAND */
921 current_SC
->SCp
.phase
= command_ph
;
922 printk("NCR53c406a: Warning: Unknown interrupt occurred in command phase!\n");
925 case 0x03: /* STATUS */
927 current_SC
->SCp
.phase
= status_ph
;
928 VDEB(printk("NCR53c406a: Status phase\n"));
929 outb(FLUSH_FIFO
, CMD_REG
);
930 outb(INIT_CMD_COMPLETE
, CMD_REG
);
933 case 0x04: /* Reserved */
934 case 0x05: /* Reserved */
935 printk("NCR53c406a: WARNING: Reserved phase!!!\n");
938 case 0x06: /* MESSAGE-OUT */
939 DEB(printk("NCR53c406a: Message-Out phase\n"));
940 current_SC
->SCp
.phase
= message_out
;
941 outb(SET_ATN
, CMD_REG
); /* Reject the message */
942 outb(MSG_ACCEPT
, CMD_REG
);
945 case 0x07: /* MESSAGE-IN */
947 VDEB(printk("NCR53c406a: Message-In phase\n"));
948 current_SC
->SCp
.phase
= message_in
;
950 current_SC
->SCp
.Status
= inb(SCSI_FIFO
);
951 current_SC
->SCp
.Message
= inb(SCSI_FIFO
);
953 VDEB(printk("SCSI FIFO size=%d\n", inb(FIFO_FLAGS
) & 0x1f));
954 DEB(printk("Status = %02x Message = %02x\n",
955 current_SC
->SCp
.Status
, current_SC
->SCp
.Message
));
957 if(current_SC
->SCp
.Message
== SAVE_POINTERS
||
958 current_SC
->SCp
.Message
== DISCONNECT
) {
959 outb(SET_ATN
, CMD_REG
); /* Reject message */
960 DEB(printk("Discarding SAVE_POINTERS message\n"));
962 outb(MSG_ACCEPT
, CMD_REG
);
968 static int irq_probe()
973 inb(INT_REG
); /* clear the interrupt register */
974 irqs
= probe_irq_on();
976 /* Invalid command will cause an interrupt */
980 /* Wait for the interrupt to occur */
981 i
= jiffies
+ WATCHDOG
;
982 while(time_after(i
, jiffies
) && !(inb(STAT_REG
) & 0x80))
984 if (time_before_eq(i
, jiffies
)) { /* Timed out, must be hardware trouble */
989 irq
= probe_irq_off(irqs
);
992 outb(CHIP_RESET
, CMD_REG
);
993 outb(SCSI_NOP
, CMD_REG
);
1000 static void chip_init()
1004 outb(0x00, PIO_STATUS
);
1006 outb(0x01, PIO_STATUS
);
1008 outb(0x00, PIO_FLAG
);
1010 outb(C4_IMG
, CONFIG4
); /* REG0; */
1011 outb(C3_IMG
, CONFIG3
);
1012 outb(C2_IMG
, CONFIG2
);
1013 outb(C1_IMG
, CONFIG1
);
1015 outb(0x05, CLKCONV
); /* clock conversion factor */
1016 outb(0x9C, SRTIMOUT
); /* Selection timeout */
1017 outb(0x05, SYNCPRD
); /* Synchronous transfer period */
1018 outb(SYNC_MODE
, SYNCOFF
); /* synchronous mode */
1021 void __init
calc_port_addr(void)
1023 /* Control Register Set 0 */
1024 TC_LSB
= (port_base
+0x00);
1025 TC_MSB
= (port_base
+0x01);
1026 SCSI_FIFO
= (port_base
+0x02);
1027 CMD_REG
= (port_base
+0x03);
1028 STAT_REG
= (port_base
+0x04);
1029 DEST_ID
= (port_base
+0x04);
1030 INT_REG
= (port_base
+0x05);
1031 SRTIMOUT
= (port_base
+0x05);
1032 SEQ_REG
= (port_base
+0x06);
1033 SYNCPRD
= (port_base
+0x06);
1034 FIFO_FLAGS
= (port_base
+0x07);
1035 SYNCOFF
= (port_base
+0x07);
1036 CONFIG1
= (port_base
+0x08);
1037 CLKCONV
= (port_base
+0x09);
1038 /* TESTREG = (port_base+0x0A); */
1039 CONFIG2
= (port_base
+0x0B);
1040 CONFIG3
= (port_base
+0x0C);
1041 CONFIG4
= (port_base
+0x0D);
1042 TC_HIGH
= (port_base
+0x0E);
1043 /* FIFO_BOTTOM = (port_base+0x0F); */
1045 /* Control Register Set 1 */
1046 /* JUMPER_SENSE = (port_base+0x00);*/
1047 /* SRAM_PTR = (port_base+0x01);*/
1048 /* SRAM_DATA = (port_base+0x02);*/
1049 PIO_FIFO
= (port_base
+0x04);
1050 /* PIO_FIFO1 = (port_base+0x05);*/
1051 /* PIO_FIFO2 = (port_base+0x06);*/
1052 /* PIO_FIFO3 = (port_base+0x07);*/
1053 PIO_STATUS
= (port_base
+0x08);
1054 /* ATA_CMD = (port_base+0x09);*/
1055 /* ATA_ERR = (port_base+0x0A);*/
1056 PIO_FLAG
= (port_base
+0x0B);
1057 CONFIG5
= (port_base
+0x0D);
1058 /* SIGNATURE = (port_base+0x0E);*/
1059 /* CONFIG6 = (port_base+0x0F);*/
1062 /* Eventually this will go into an include file, but this will be later */
1063 static Scsi_Host_Template driver_template
= NCR53c406a
;
1065 #include "scsi_module.c"
1068 * Overrides for Emacs so that we get a uniform tabbing style.
1069 * Emacs will notice this stuff at the end of the file and automatically
1070 * adjust the settings for this buffer only. This must remain at the end
1072 * ---------------------------------------------------------------------------
1075 * c-brace-imaginary-offset: 0
1076 * c-brace-offset: -4
1077 * c-argdecl-indent: 4
1078 * c-label-offset: -4
1079 * c-continued-statement-offset: 4
1080 * c-continued-brace-offset: 0
1081 * indent-tabs-mode: nil