xref: /openbmc/linux/drivers/scsi/NCR5380.h (revision ef1081cbf05b22d3d0e05b267a5559a8cd8e8d4a)
11da177e4SLinus Torvalds /*
21da177e4SLinus Torvalds  * NCR 5380 defines
31da177e4SLinus Torvalds  *
41da177e4SLinus Torvalds  * Copyright 1993, Drew Eckhardt
51da177e4SLinus Torvalds  *	Visionary Computing
61da177e4SLinus Torvalds  *	(Unix consulting and custom programming)
71da177e4SLinus Torvalds  * 	drew@colorado.edu
81da177e4SLinus Torvalds  *      +1 (303) 666-5836
91da177e4SLinus Torvalds  *
101da177e4SLinus Torvalds  * For more information, please consult
111da177e4SLinus Torvalds  *
121da177e4SLinus Torvalds  * NCR 5380 Family
131da177e4SLinus Torvalds  * SCSI Protocol Controller
141da177e4SLinus Torvalds  * Databook
151da177e4SLinus Torvalds  * NCR Microelectronics
161da177e4SLinus Torvalds  * 1635 Aeroplaza Drive
171da177e4SLinus Torvalds  * Colorado Springs, CO 80916
181da177e4SLinus Torvalds  * 1+ (719) 578-3400
191da177e4SLinus Torvalds  * 1+ (800) 334-5454
201da177e4SLinus Torvalds  */
211da177e4SLinus Torvalds 
221da177e4SLinus Torvalds #ifndef NCR5380_H
231da177e4SLinus Torvalds #define NCR5380_H
241da177e4SLinus Torvalds 
251da177e4SLinus Torvalds #include <linux/interrupt.h>
2628424d3aSBoaz Harrosh #include <scsi/scsi_eh.h>
2728424d3aSBoaz Harrosh 
281da177e4SLinus Torvalds #define NDEBUG_ARBITRATION	0x1
291da177e4SLinus Torvalds #define NDEBUG_AUTOSENSE	0x2
301da177e4SLinus Torvalds #define NDEBUG_DMA		0x4
311da177e4SLinus Torvalds #define NDEBUG_HANDSHAKE	0x8
321da177e4SLinus Torvalds #define NDEBUG_INFORMATION	0x10
331da177e4SLinus Torvalds #define NDEBUG_INIT		0x20
341da177e4SLinus Torvalds #define NDEBUG_INTR		0x40
351da177e4SLinus Torvalds #define NDEBUG_LINKED		0x80
361da177e4SLinus Torvalds #define NDEBUG_MAIN		0x100
371da177e4SLinus Torvalds #define NDEBUG_NO_DATAOUT	0x200
381da177e4SLinus Torvalds #define NDEBUG_NO_WRITE		0x400
391da177e4SLinus Torvalds #define NDEBUG_PIO		0x800
401da177e4SLinus Torvalds #define NDEBUG_PSEUDO_DMA	0x1000
411da177e4SLinus Torvalds #define NDEBUG_QUEUES		0x2000
421da177e4SLinus Torvalds #define NDEBUG_RESELECTION	0x4000
431da177e4SLinus Torvalds #define NDEBUG_SELECTION	0x8000
441da177e4SLinus Torvalds #define NDEBUG_USLEEP		0x10000
451da177e4SLinus Torvalds #define NDEBUG_LAST_BYTE_SENT	0x20000
461da177e4SLinus Torvalds #define NDEBUG_RESTART_SELECT	0x40000
471da177e4SLinus Torvalds #define NDEBUG_EXTENDED		0x80000
481da177e4SLinus Torvalds #define NDEBUG_C400_PREAD	0x100000
491da177e4SLinus Torvalds #define NDEBUG_C400_PWRITE	0x200000
501da177e4SLinus Torvalds #define NDEBUG_LISTS		0x400000
519829e528SFinn Thain #define NDEBUG_ABORT		0x800000
529829e528SFinn Thain #define NDEBUG_TAGS		0x1000000
539829e528SFinn Thain #define NDEBUG_MERGING		0x2000000
541da177e4SLinus Torvalds 
551da177e4SLinus Torvalds #define NDEBUG_ANY		0xFFFFFFFFUL
561da177e4SLinus Torvalds 
571da177e4SLinus Torvalds /*
581da177e4SLinus Torvalds  * The contents of the OUTPUT DATA register are asserted on the bus when
591da177e4SLinus Torvalds  * either arbitration is occurring or the phase-indicating signals (
601da177e4SLinus Torvalds  * IO, CD, MSG) in the TARGET COMMAND register and the ASSERT DATA
611da177e4SLinus Torvalds  * bit in the INITIATOR COMMAND register is set.
621da177e4SLinus Torvalds  */
631da177e4SLinus Torvalds 
641da177e4SLinus Torvalds #define OUTPUT_DATA_REG         0	/* wo DATA lines on SCSI bus */
651da177e4SLinus Torvalds #define CURRENT_SCSI_DATA_REG   0	/* ro same */
661da177e4SLinus Torvalds 
671da177e4SLinus Torvalds #define INITIATOR_COMMAND_REG	1	/* rw */
681da177e4SLinus Torvalds #define ICR_ASSERT_RST		0x80	/* rw Set to assert RST  */
691da177e4SLinus Torvalds #define ICR_ARBITRATION_PROGRESS 0x40	/* ro Indicates arbitration complete */
701da177e4SLinus Torvalds #define ICR_TRI_STATE		0x40	/* wo Set to tri-state drivers */
711da177e4SLinus Torvalds #define ICR_ARBITRATION_LOST	0x20	/* ro Indicates arbitration lost */
721da177e4SLinus Torvalds #define ICR_DIFF_ENABLE		0x20	/* wo Set to enable diff. drivers */
731da177e4SLinus Torvalds #define ICR_ASSERT_ACK		0x10	/* rw ini Set to assert ACK */
741da177e4SLinus Torvalds #define ICR_ASSERT_BSY		0x08	/* rw Set to assert BSY */
751da177e4SLinus Torvalds #define ICR_ASSERT_SEL 		0x04	/* rw Set to assert SEL */
761da177e4SLinus Torvalds #define ICR_ASSERT_ATN		0x02	/* rw Set to assert ATN */
771da177e4SLinus Torvalds #define ICR_ASSERT_DATA		0x01	/* rw SCSI_DATA_REG is asserted */
781da177e4SLinus Torvalds 
791da177e4SLinus Torvalds #ifdef DIFFERENTIAL
801da177e4SLinus Torvalds #define ICR_BASE		ICR_DIFF_ENABLE
811da177e4SLinus Torvalds #else
821da177e4SLinus Torvalds #define ICR_BASE		0
831da177e4SLinus Torvalds #endif
841da177e4SLinus Torvalds 
851da177e4SLinus Torvalds #define MODE_REG		2
861da177e4SLinus Torvalds /*
871da177e4SLinus Torvalds  * Note : BLOCK_DMA code will keep DRQ asserted for the duration of the
881da177e4SLinus Torvalds  * transfer, causing the chip to hog the bus.  You probably don't want
891da177e4SLinus Torvalds  * this.
901da177e4SLinus Torvalds  */
911da177e4SLinus Torvalds #define MR_BLOCK_DMA_MODE	0x80	/* rw block mode DMA */
921da177e4SLinus Torvalds #define MR_TARGET		0x40	/* rw target mode */
931da177e4SLinus Torvalds #define MR_ENABLE_PAR_CHECK	0x20	/* rw enable parity checking */
941da177e4SLinus Torvalds #define MR_ENABLE_PAR_INTR	0x10	/* rw enable bad parity interrupt */
951da177e4SLinus Torvalds #define MR_ENABLE_EOP_INTR	0x08	/* rw enable eop interrupt */
961da177e4SLinus Torvalds #define MR_MONITOR_BSY		0x04	/* rw enable int on unexpected bsy fail */
971da177e4SLinus Torvalds #define MR_DMA_MODE		0x02	/* rw DMA / pseudo DMA mode */
981da177e4SLinus Torvalds #define MR_ARBITRATE		0x01	/* rw start arbitration */
991da177e4SLinus Torvalds 
1001da177e4SLinus Torvalds #ifdef PARITY
1011da177e4SLinus Torvalds #define MR_BASE			MR_ENABLE_PAR_CHECK
1021da177e4SLinus Torvalds #else
1031da177e4SLinus Torvalds #define MR_BASE			0
1041da177e4SLinus Torvalds #endif
1051da177e4SLinus Torvalds 
1061da177e4SLinus Torvalds #define TARGET_COMMAND_REG	3
1071da177e4SLinus Torvalds #define TCR_LAST_BYTE_SENT	0x80	/* ro DMA done */
1081da177e4SLinus Torvalds #define TCR_ASSERT_REQ		0x08	/* tgt rw assert REQ */
1091da177e4SLinus Torvalds #define TCR_ASSERT_MSG		0x04	/* tgt rw assert MSG */
1101da177e4SLinus Torvalds #define TCR_ASSERT_CD		0x02	/* tgt rw assert CD */
1111da177e4SLinus Torvalds #define TCR_ASSERT_IO		0x01	/* tgt rw assert IO */
1121da177e4SLinus Torvalds 
1131da177e4SLinus Torvalds #define STATUS_REG		4	/* ro */
1141da177e4SLinus Torvalds /*
1151da177e4SLinus Torvalds  * Note : a set bit indicates an active signal, driven by us or another
1161da177e4SLinus Torvalds  * device.
1171da177e4SLinus Torvalds  */
1181da177e4SLinus Torvalds #define SR_RST			0x80
1191da177e4SLinus Torvalds #define SR_BSY			0x40
1201da177e4SLinus Torvalds #define SR_REQ			0x20
1211da177e4SLinus Torvalds #define SR_MSG			0x10
1221da177e4SLinus Torvalds #define SR_CD			0x08
1231da177e4SLinus Torvalds #define SR_IO			0x04
1241da177e4SLinus Torvalds #define SR_SEL			0x02
1251da177e4SLinus Torvalds #define SR_DBP			0x01
1261da177e4SLinus Torvalds 
1271da177e4SLinus Torvalds /*
1281da177e4SLinus Torvalds  * Setting a bit in this register will cause an interrupt to be generated when
1291da177e4SLinus Torvalds  * BSY is false and SEL true and this bit is asserted  on the bus.
1301da177e4SLinus Torvalds  */
1311da177e4SLinus Torvalds #define SELECT_ENABLE_REG	4	/* wo */
1321da177e4SLinus Torvalds 
1331da177e4SLinus Torvalds #define BUS_AND_STATUS_REG	5	/* ro */
1341da177e4SLinus Torvalds #define BASR_END_DMA_TRANSFER	0x80	/* ro set on end of transfer */
1351da177e4SLinus Torvalds #define BASR_DRQ		0x40	/* ro mirror of DRQ pin */
1361da177e4SLinus Torvalds #define BASR_PARITY_ERROR	0x20	/* ro parity error detected */
1371da177e4SLinus Torvalds #define BASR_IRQ		0x10	/* ro mirror of IRQ pin */
1381da177e4SLinus Torvalds #define BASR_PHASE_MATCH	0x08	/* ro Set when MSG CD IO match TCR */
1391da177e4SLinus Torvalds #define BASR_BUSY_ERROR		0x04	/* ro Unexpected change to inactive state */
1401da177e4SLinus Torvalds #define BASR_ATN 		0x02	/* ro BUS status */
1411da177e4SLinus Torvalds #define BASR_ACK		0x01	/* ro BUS status */
1421da177e4SLinus Torvalds 
1431da177e4SLinus Torvalds /* Write any value to this register to start a DMA send */
1441da177e4SLinus Torvalds #define START_DMA_SEND_REG	5	/* wo */
1451da177e4SLinus Torvalds 
1461da177e4SLinus Torvalds /*
1471da177e4SLinus Torvalds  * Used in DMA transfer mode, data is latched from the SCSI bus on
1481da177e4SLinus Torvalds  * the falling edge of REQ (ini) or ACK (tgt)
1491da177e4SLinus Torvalds  */
1501da177e4SLinus Torvalds #define INPUT_DATA_REG			6	/* ro */
1511da177e4SLinus Torvalds 
1521da177e4SLinus Torvalds /* Write any value to this register to start a DMA receive */
1531da177e4SLinus Torvalds #define START_DMA_TARGET_RECEIVE_REG	6	/* wo */
1541da177e4SLinus Torvalds 
1551da177e4SLinus Torvalds /* Read this register to clear interrupt conditions */
1561da177e4SLinus Torvalds #define RESET_PARITY_INTERRUPT_REG	7	/* ro */
1571da177e4SLinus Torvalds 
1581da177e4SLinus Torvalds /* Write any value to this register to start an ini mode DMA receive */
1591da177e4SLinus Torvalds #define START_DMA_INITIATOR_RECEIVE_REG 7	/* wo */
1601da177e4SLinus Torvalds 
1611da177e4SLinus Torvalds #define C400_CONTROL_STATUS_REG NCR53C400_register_offset-8	/* rw */
1621da177e4SLinus Torvalds 
1631da177e4SLinus Torvalds #define CSR_RESET              0x80	/* wo  Resets 53c400 */
1641da177e4SLinus Torvalds #define CSR_53C80_REG          0x80	/* ro  5380 registers busy */
1651da177e4SLinus Torvalds #define CSR_TRANS_DIR          0x40	/* rw  Data transfer direction */
1661da177e4SLinus Torvalds #define CSR_SCSI_BUFF_INTR     0x20	/* rw  Enable int on transfer ready */
1671da177e4SLinus Torvalds #define CSR_53C80_INTR         0x10	/* rw  Enable 53c80 interrupts */
1681da177e4SLinus Torvalds #define CSR_SHARED_INTR        0x08	/* rw  Interrupt sharing */
1691da177e4SLinus Torvalds #define CSR_HOST_BUF_NOT_RDY   0x04	/* ro  Is Host buffer ready */
1701da177e4SLinus Torvalds #define CSR_SCSI_BUF_RDY       0x02	/* ro  SCSI buffer read */
1711da177e4SLinus Torvalds #define CSR_GATED_53C80_IRQ    0x01	/* ro  Last block xferred */
1721da177e4SLinus Torvalds 
1731da177e4SLinus Torvalds #if 0
1741da177e4SLinus Torvalds #define CSR_BASE CSR_SCSI_BUFF_INTR | CSR_53C80_INTR
1751da177e4SLinus Torvalds #else
1761da177e4SLinus Torvalds #define CSR_BASE CSR_53C80_INTR
1771da177e4SLinus Torvalds #endif
1781da177e4SLinus Torvalds 
1791da177e4SLinus Torvalds /* Number of 128-byte blocks to be transferred */
1801da177e4SLinus Torvalds #define C400_BLOCK_COUNTER_REG   NCR53C400_register_offset-7	/* rw */
1811da177e4SLinus Torvalds 
1821da177e4SLinus Torvalds /* Resume transfer after disconnect */
1831da177e4SLinus Torvalds #define C400_RESUME_TRANSFER_REG NCR53C400_register_offset-6	/* wo */
1841da177e4SLinus Torvalds 
1851da177e4SLinus Torvalds /* Access to host buffer stack */
1861da177e4SLinus Torvalds #define C400_HOST_BUFFER         NCR53C400_register_offset-4	/* rw */
1871da177e4SLinus Torvalds 
1881da177e4SLinus Torvalds 
1891da177e4SLinus Torvalds /* Note : PHASE_* macros are based on the values of the STATUS register */
1901da177e4SLinus Torvalds #define PHASE_MASK 	(SR_MSG | SR_CD | SR_IO)
1911da177e4SLinus Torvalds 
1921da177e4SLinus Torvalds #define PHASE_DATAOUT		0
1931da177e4SLinus Torvalds #define PHASE_DATAIN		SR_IO
1941da177e4SLinus Torvalds #define PHASE_CMDOUT		SR_CD
1951da177e4SLinus Torvalds #define PHASE_STATIN		(SR_CD | SR_IO)
1961da177e4SLinus Torvalds #define PHASE_MSGOUT		(SR_MSG | SR_CD)
1971da177e4SLinus Torvalds #define PHASE_MSGIN		(SR_MSG | SR_CD | SR_IO)
1981da177e4SLinus Torvalds #define PHASE_UNKNOWN		0xff
1991da177e4SLinus Torvalds 
2001da177e4SLinus Torvalds /*
2011da177e4SLinus Torvalds  * Convert status register phase to something we can use to set phase in
2021da177e4SLinus Torvalds  * the target register so we can get phase mismatch interrupts on DMA
2031da177e4SLinus Torvalds  * transfers.
2041da177e4SLinus Torvalds  */
2051da177e4SLinus Torvalds 
2061da177e4SLinus Torvalds #define PHASE_SR_TO_TCR(phase) ((phase) >> 2)
2071da177e4SLinus Torvalds 
2081da177e4SLinus Torvalds /*
2091da177e4SLinus Torvalds  * The internal should_disconnect() function returns these based on the
2101da177e4SLinus Torvalds  * expected length of a disconnect if a device supports disconnect/
2111da177e4SLinus Torvalds  * reconnect.
2121da177e4SLinus Torvalds  */
2131da177e4SLinus Torvalds 
2141da177e4SLinus Torvalds #define DISCONNECT_NONE		0
2151da177e4SLinus Torvalds #define DISCONNECT_TIME_TO_DATA	1
2161da177e4SLinus Torvalds #define DISCONNECT_LONG		2
2171da177e4SLinus Torvalds 
2181da177e4SLinus Torvalds /*
21976f13b93SFinn Thain  * "Special" value for the (unsigned char) command tag, to indicate
22076f13b93SFinn Thain  * I_T_L nexus instead of I_T_L_Q.
2211da177e4SLinus Torvalds  */
2221da177e4SLinus Torvalds 
22376f13b93SFinn Thain #define TAG_NONE	0xff
2241da177e4SLinus Torvalds 
2251da177e4SLinus Torvalds /*
2261da177e4SLinus Torvalds  * These are "special" values for the irq and dma_channel fields of the
2271da177e4SLinus Torvalds  * Scsi_Host structure
2281da177e4SLinus Torvalds  */
2291da177e4SLinus Torvalds 
2301da177e4SLinus Torvalds #define DMA_NONE	255
2311da177e4SLinus Torvalds #define IRQ_AUTO	254
2321da177e4SLinus Torvalds #define DMA_AUTO	254
2331da177e4SLinus Torvalds #define PORT_AUTO	0xffff	/* autoprobe io port for 53c400a */
2341da177e4SLinus Torvalds 
23522f5f10dSFinn Thain #ifndef NO_IRQ
23622f5f10dSFinn Thain #define NO_IRQ		0
23722f5f10dSFinn Thain #endif
23822f5f10dSFinn Thain 
2391da177e4SLinus Torvalds #define FLAG_HAS_LAST_BYTE_SENT		1	/* NCR53c81 or better */
2401da177e4SLinus Torvalds #define FLAG_CHECK_LAST_BYTE_SENT	2	/* Only test once */
2411da177e4SLinus Torvalds #define FLAG_NCR53C400			4	/* NCR53c400 */
2421da177e4SLinus Torvalds #define FLAG_NO_PSEUDO_DMA		8	/* Inhibit DMA */
2431da177e4SLinus Torvalds #define FLAG_DTC3181E			16	/* DTC3181E */
244*ef1081cbSFinn Thain #define FLAG_LATE_DMA_SETUP		32	/* Setup NCR before DMA H/W */
2451da177e4SLinus Torvalds 
2461da177e4SLinus Torvalds #ifndef ASM
2471da177e4SLinus Torvalds struct NCR5380_hostdata {
2481da177e4SLinus Torvalds 	NCR5380_implementation_fields;		/* implementation specific */
2491da177e4SLinus Torvalds 	struct Scsi_Host *host;			/* Host backpointer */
2501da177e4SLinus Torvalds 	unsigned char id_mask, id_higher_mask;	/* 1 << id, all bits greater */
2511da177e4SLinus Torvalds 	unsigned char targets_present;		/* targets we have connected
2521da177e4SLinus Torvalds 						   to, so we can call a select
2531da177e4SLinus Torvalds 						   failure a retryable condition */
2541da177e4SLinus Torvalds 	volatile unsigned char busy[8];		/* index = target, bit = lun */
2551da177e4SLinus Torvalds #if defined(REAL_DMA) || defined(REAL_DMA_POLL)
2561da177e4SLinus Torvalds 	volatile int dma_len;			/* requested length of DMA */
2571da177e4SLinus Torvalds #endif
2581da177e4SLinus Torvalds 	volatile unsigned char last_message;	/* last message OUT */
259710ddd0dSFinn Thain 	volatile struct scsi_cmnd *connected;	/* currently connected command */
260710ddd0dSFinn Thain 	volatile struct scsi_cmnd *issue_queue;	/* waiting to be issued */
261710ddd0dSFinn Thain 	volatile struct scsi_cmnd *disconnected_queue;	/* waiting for reconnect */
2621da177e4SLinus Torvalds 	volatile int restart_select;		/* we have disconnected,
2631da177e4SLinus Torvalds 						   used to restart
2641da177e4SLinus Torvalds 						   NCR5380_select() */
2651da177e4SLinus Torvalds 	volatile unsigned aborted:1;		/* flag, says aborted */
2661da177e4SLinus Torvalds 	int flags;
2671da177e4SLinus Torvalds 	unsigned long time_expires;		/* in jiffies, set prior to sleeping */
2681da177e4SLinus Torvalds 	int select_time;			/* timer in select for target response */
269710ddd0dSFinn Thain 	volatile struct scsi_cmnd *selecting;
270c4028958SDavid Howells 	struct delayed_work coroutine;		/* our co-routine */
27128424d3aSBoaz Harrosh 	struct scsi_eh_save ses;
2728c32513bSFinn Thain 	char info[256];
273*ef1081cbSFinn Thain 	int read_overruns;                /* number of bytes to cut from a
274*ef1081cbSFinn Thain 	                                   * transfer to handle chip overruns */
275*ef1081cbSFinn Thain 	int retain_dma_intr;
276a9c2dc43SFinn Thain #ifdef PSEUDO_DMA
277a9c2dc43SFinn Thain 	unsigned spin_max_r;
278a9c2dc43SFinn Thain 	unsigned spin_max_w;
279a9c2dc43SFinn Thain #endif
2801da177e4SLinus Torvalds };
2811da177e4SLinus Torvalds 
2821da177e4SLinus Torvalds #ifdef __KERNEL__
2831da177e4SLinus Torvalds 
2849829e528SFinn Thain #ifndef NDEBUG
2859829e528SFinn Thain #define NDEBUG (0)
2869829e528SFinn Thain #endif
2879829e528SFinn Thain 
28816b9d870SFinn Thain #define dprintk(flg, fmt, ...) \
289d61c5427SFinn Thain 	do { if ((NDEBUG) & (flg)) \
290d61c5427SFinn Thain 		printk(KERN_DEBUG fmt, ## __VA_ARGS__); } while (0)
29116b9d870SFinn Thain 
2929829e528SFinn Thain #if NDEBUG
2939829e528SFinn Thain #define NCR5380_dprint(flg, arg) \
2949829e528SFinn Thain 	do { if ((NDEBUG) & (flg)) NCR5380_print(arg); } while (0)
2959829e528SFinn Thain #define NCR5380_dprint_phase(flg, arg) \
2969829e528SFinn Thain 	do { if ((NDEBUG) & (flg)) NCR5380_print_phase(arg); } while (0)
2979829e528SFinn Thain static void NCR5380_print_phase(struct Scsi_Host *instance);
2989829e528SFinn Thain static void NCR5380_print(struct Scsi_Host *instance);
2999829e528SFinn Thain #else
30052a6a1cbSFinn Thain #define NCR5380_dprint(flg, arg)       do {} while (0)
30152a6a1cbSFinn Thain #define NCR5380_dprint_phase(flg, arg) do {} while (0)
3029829e528SFinn Thain #endif
3031da177e4SLinus Torvalds 
3041da177e4SLinus Torvalds #if defined(AUTOPROBE_IRQ)
3051da177e4SLinus Torvalds static int NCR5380_probe_irq(struct Scsi_Host *instance, int possible);
3061da177e4SLinus Torvalds #endif
3071da177e4SLinus Torvalds static int NCR5380_init(struct Scsi_Host *instance, int flags);
3081da177e4SLinus Torvalds static void NCR5380_exit(struct Scsi_Host *instance);
3091da177e4SLinus Torvalds static void NCR5380_information_transfer(struct Scsi_Host *instance);
3101da177e4SLinus Torvalds #ifndef DONT_USE_INTR
3117d12e780SDavid Howells static irqreturn_t NCR5380_intr(int irq, void *dev_id);
3121da177e4SLinus Torvalds #endif
313c4028958SDavid Howells static void NCR5380_main(struct work_struct *work);
3148c32513bSFinn Thain static const char *NCR5380_info(struct Scsi_Host *instance);
3151da177e4SLinus Torvalds static void NCR5380_reselect(struct Scsi_Host *instance);
316710ddd0dSFinn Thain static int NCR5380_select(struct Scsi_Host *instance, struct scsi_cmnd *cmd);
3171da177e4SLinus Torvalds #if defined(PSEUDO_DMA) || defined(REAL_DMA) || defined(REAL_DMA_POLL)
3181da177e4SLinus Torvalds static int NCR5380_transfer_dma(struct Scsi_Host *instance, unsigned char *phase, int *count, unsigned char **data);
3191da177e4SLinus Torvalds #endif
3201da177e4SLinus Torvalds static int NCR5380_transfer_pio(struct Scsi_Host *instance, unsigned char *phase, int *count, unsigned char **data);
3211da177e4SLinus Torvalds 
3221da177e4SLinus Torvalds #if (defined(REAL_DMA) || defined(REAL_DMA_POLL))
3231da177e4SLinus Torvalds 
3241da177e4SLinus Torvalds #if defined(i386) || defined(__alpha__)
3251da177e4SLinus Torvalds 
3261da177e4SLinus Torvalds /**
3271da177e4SLinus Torvalds  *	NCR5380_pc_dma_setup		-	setup ISA DMA
3281da177e4SLinus Torvalds  *	@instance: adapter to set up
3291da177e4SLinus Torvalds  *	@ptr: block to transfer (virtual address)
3301da177e4SLinus Torvalds  *	@count: number of bytes to transfer
3311da177e4SLinus Torvalds  *	@mode: DMA controller mode to use
3321da177e4SLinus Torvalds  *
3331da177e4SLinus Torvalds  *	Program the DMA controller ready to perform an ISA DMA transfer
3341da177e4SLinus Torvalds  *	on this chip.
3351da177e4SLinus Torvalds  *
3361da177e4SLinus Torvalds  *	Locks: takes and releases the ISA DMA lock.
3371da177e4SLinus Torvalds  */
3381da177e4SLinus Torvalds 
3391da177e4SLinus Torvalds static __inline__ int NCR5380_pc_dma_setup(struct Scsi_Host *instance, unsigned char *ptr, unsigned int count, unsigned char mode)
3401da177e4SLinus Torvalds {
3411da177e4SLinus Torvalds 	unsigned limit;
3421da177e4SLinus Torvalds 	unsigned long bus_addr = virt_to_bus(ptr);
3431da177e4SLinus Torvalds 	unsigned long flags;
3441da177e4SLinus Torvalds 
3451da177e4SLinus Torvalds 	if (instance->dma_channel <= 3) {
3461da177e4SLinus Torvalds 		if (count > 65536)
3471da177e4SLinus Torvalds 			count = 65536;
3481da177e4SLinus Torvalds 		limit = 65536 - (bus_addr & 0xFFFF);
3491da177e4SLinus Torvalds 	} else {
3501da177e4SLinus Torvalds 		if (count > 65536 * 2)
3511da177e4SLinus Torvalds 			count = 65536 * 2;
3521da177e4SLinus Torvalds 		limit = 65536 * 2 - (bus_addr & 0x1FFFF);
3531da177e4SLinus Torvalds 	}
3541da177e4SLinus Torvalds 
3551da177e4SLinus Torvalds 	if (count > limit)
3561da177e4SLinus Torvalds 		count = limit;
3571da177e4SLinus Torvalds 
3581da177e4SLinus Torvalds 	if ((count & 1) || (bus_addr & 1))
3591da177e4SLinus Torvalds 		panic("scsi%d : attempted unaligned DMA transfer\n", instance->host_no);
3601da177e4SLinus Torvalds 
3611da177e4SLinus Torvalds 	flags=claim_dma_lock();
3621da177e4SLinus Torvalds 	disable_dma(instance->dma_channel);
3631da177e4SLinus Torvalds 	clear_dma_ff(instance->dma_channel);
3641da177e4SLinus Torvalds 	set_dma_addr(instance->dma_channel, bus_addr);
3651da177e4SLinus Torvalds 	set_dma_count(instance->dma_channel, count);
3661da177e4SLinus Torvalds 	set_dma_mode(instance->dma_channel, mode);
3671da177e4SLinus Torvalds 	enable_dma(instance->dma_channel);
3681da177e4SLinus Torvalds 	release_dma_lock(flags);
3691da177e4SLinus Torvalds 
3701da177e4SLinus Torvalds 	return count;
3711da177e4SLinus Torvalds }
3721da177e4SLinus Torvalds 
3731da177e4SLinus Torvalds /**
3741da177e4SLinus Torvalds  *	NCR5380_pc_dma_write_setup		-	setup ISA DMA write
3751da177e4SLinus Torvalds  *	@instance: adapter to set up
3761da177e4SLinus Torvalds  *	@ptr: block to transfer (virtual address)
3771da177e4SLinus Torvalds  *	@count: number of bytes to transfer
3781da177e4SLinus Torvalds  *
3791da177e4SLinus Torvalds  *	Program the DMA controller ready to perform an ISA DMA write to the
3801da177e4SLinus Torvalds  *	SCSI controller.
3811da177e4SLinus Torvalds  *
3821da177e4SLinus Torvalds  *	Locks: called routines take and release the ISA DMA lock.
3831da177e4SLinus Torvalds  */
3841da177e4SLinus Torvalds 
3851da177e4SLinus Torvalds static __inline__ int NCR5380_pc_dma_write_setup(struct Scsi_Host *instance, unsigned char *src, unsigned int count)
3861da177e4SLinus Torvalds {
3871da177e4SLinus Torvalds 	return NCR5380_pc_dma_setup(instance, src, count, DMA_MODE_WRITE);
3881da177e4SLinus Torvalds }
3891da177e4SLinus Torvalds 
3901da177e4SLinus Torvalds /**
3911da177e4SLinus Torvalds  *	NCR5380_pc_dma_read_setup		-	setup ISA DMA read
3921da177e4SLinus Torvalds  *	@instance: adapter to set up
3931da177e4SLinus Torvalds  *	@ptr: block to transfer (virtual address)
3941da177e4SLinus Torvalds  *	@count: number of bytes to transfer
3951da177e4SLinus Torvalds  *
3961da177e4SLinus Torvalds  *	Program the DMA controller ready to perform an ISA DMA read from the
3971da177e4SLinus Torvalds  *	SCSI controller.
3981da177e4SLinus Torvalds  *
3991da177e4SLinus Torvalds  *	Locks: called routines take and release the ISA DMA lock.
4001da177e4SLinus Torvalds  */
4011da177e4SLinus Torvalds 
4021da177e4SLinus Torvalds static __inline__ int NCR5380_pc_dma_read_setup(struct Scsi_Host *instance, unsigned char *src, unsigned int count)
4031da177e4SLinus Torvalds {
4041da177e4SLinus Torvalds 	return NCR5380_pc_dma_setup(instance, src, count, DMA_MODE_READ);
4051da177e4SLinus Torvalds }
4061da177e4SLinus Torvalds 
4071da177e4SLinus Torvalds /**
4081da177e4SLinus Torvalds  *	NCR5380_pc_dma_residual		-	return bytes left
4091da177e4SLinus Torvalds  *	@instance: adapter
4101da177e4SLinus Torvalds  *
4111da177e4SLinus Torvalds  *	Reports the number of bytes left over after the DMA was terminated.
4121da177e4SLinus Torvalds  *
4131da177e4SLinus Torvalds  *	Locks: takes and releases the ISA DMA lock.
4141da177e4SLinus Torvalds  */
4151da177e4SLinus Torvalds 
4161da177e4SLinus Torvalds static __inline__ int NCR5380_pc_dma_residual(struct Scsi_Host *instance)
4171da177e4SLinus Torvalds {
4181da177e4SLinus Torvalds 	unsigned long flags;
4191da177e4SLinus Torvalds 	int tmp;
4201da177e4SLinus Torvalds 
4211da177e4SLinus Torvalds 	flags = claim_dma_lock();
4221da177e4SLinus Torvalds 	clear_dma_ff(instance->dma_channel);
4231da177e4SLinus Torvalds 	tmp = get_dma_residue(instance->dma_channel);
4241da177e4SLinus Torvalds 	release_dma_lock(flags);
4251da177e4SLinus Torvalds 
4261da177e4SLinus Torvalds 	return tmp;
4271da177e4SLinus Torvalds }
4281da177e4SLinus Torvalds #endif				/* defined(i386) || defined(__alpha__) */
4291da177e4SLinus Torvalds #endif				/* defined(REAL_DMA)  */
4301da177e4SLinus Torvalds #endif				/* __KERNEL__ */
4311da177e4SLinus Torvalds #endif				/* ndef ASM */
4321da177e4SLinus Torvalds #endif				/* NCR5380_H */
433