xref: /OK3568_Linux_fs/kernel/drivers/scsi/53c700.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0 */
2*4882a593Smuzhiyun /* -*- mode: c; c-basic-offset: 8 -*- */
3*4882a593Smuzhiyun 
4*4882a593Smuzhiyun /* Driver for 53c700 and 53c700-66 chips from NCR and Symbios
5*4882a593Smuzhiyun  *
6*4882a593Smuzhiyun  * Copyright (C) 2001 by James.Bottomley@HansenPartnership.com
7*4882a593Smuzhiyun  */
8*4882a593Smuzhiyun 
9*4882a593Smuzhiyun #ifndef _53C700_H
10*4882a593Smuzhiyun #define _53C700_H
11*4882a593Smuzhiyun 
12*4882a593Smuzhiyun #include <linux/interrupt.h>
13*4882a593Smuzhiyun #include <asm/io.h>
14*4882a593Smuzhiyun 
15*4882a593Smuzhiyun #include <scsi/scsi_device.h>
16*4882a593Smuzhiyun #include <scsi/scsi_cmnd.h>
17*4882a593Smuzhiyun 
18*4882a593Smuzhiyun /* Turn on for general debugging---too verbose for normal use */
19*4882a593Smuzhiyun #undef	NCR_700_DEBUG
20*4882a593Smuzhiyun /* Debug the tag queues, checking hash queue allocation and deallocation
21*4882a593Smuzhiyun  * and search for duplicate tags */
22*4882a593Smuzhiyun #undef NCR_700_TAG_DEBUG
23*4882a593Smuzhiyun 
24*4882a593Smuzhiyun #ifdef NCR_700_DEBUG
25*4882a593Smuzhiyun #define DEBUG(x)	printk x
26*4882a593Smuzhiyun #define DDEBUG(prefix, sdev, fmt, a...) \
27*4882a593Smuzhiyun 	sdev_printk(prefix, sdev, fmt, ##a)
28*4882a593Smuzhiyun #define CDEBUG(prefix, scmd, fmt, a...) \
29*4882a593Smuzhiyun 	scmd_printk(prefix, scmd, fmt, ##a)
30*4882a593Smuzhiyun #else
31*4882a593Smuzhiyun #define DEBUG(x)	do {} while (0)
32*4882a593Smuzhiyun #define DDEBUG(prefix, scmd, fmt, a...) do {} while (0)
33*4882a593Smuzhiyun #define CDEBUG(prefix, scmd, fmt, a...) do {} while (0)
34*4882a593Smuzhiyun #endif
35*4882a593Smuzhiyun 
36*4882a593Smuzhiyun /* The number of available command slots */
37*4882a593Smuzhiyun #define NCR_700_COMMAND_SLOTS_PER_HOST	64
38*4882a593Smuzhiyun /* The maximum number of Scatter Gathers we allow */
39*4882a593Smuzhiyun #define NCR_700_SG_SEGMENTS		32
40*4882a593Smuzhiyun /* The maximum number of luns (make this of the form 2^n) */
41*4882a593Smuzhiyun #define NCR_700_MAX_LUNS		32
42*4882a593Smuzhiyun #define NCR_700_LUN_MASK		(NCR_700_MAX_LUNS - 1)
43*4882a593Smuzhiyun /* Maximum number of tags the driver ever allows per device */
44*4882a593Smuzhiyun #define NCR_700_MAX_TAGS		16
45*4882a593Smuzhiyun /* Tag depth the driver starts out with (can be altered in sysfs) */
46*4882a593Smuzhiyun #define NCR_700_DEFAULT_TAGS		4
47*4882a593Smuzhiyun /* This is the default number of commands per LUN in the untagged case.
48*4882a593Smuzhiyun  * two is a good value because it means we can have one command active and
49*4882a593Smuzhiyun  * one command fully prepared and waiting
50*4882a593Smuzhiyun  */
51*4882a593Smuzhiyun #define NCR_700_CMD_PER_LUN		2
52*4882a593Smuzhiyun /* magic byte identifying an internally generated REQUEST_SENSE command */
53*4882a593Smuzhiyun #define NCR_700_INTERNAL_SENSE_MAGIC	0x42
54*4882a593Smuzhiyun 
55*4882a593Smuzhiyun struct NCR_700_Host_Parameters;
56*4882a593Smuzhiyun 
57*4882a593Smuzhiyun /* These are the externally used routines */
58*4882a593Smuzhiyun struct Scsi_Host *NCR_700_detect(struct scsi_host_template *,
59*4882a593Smuzhiyun 		struct NCR_700_Host_Parameters *, struct device *);
60*4882a593Smuzhiyun int NCR_700_release(struct Scsi_Host *host);
61*4882a593Smuzhiyun irqreturn_t NCR_700_intr(int, void *);
62*4882a593Smuzhiyun 
63*4882a593Smuzhiyun 
64*4882a593Smuzhiyun enum NCR_700_Host_State {
65*4882a593Smuzhiyun 	NCR_700_HOST_BUSY,
66*4882a593Smuzhiyun 	NCR_700_HOST_FREE,
67*4882a593Smuzhiyun };
68*4882a593Smuzhiyun 
69*4882a593Smuzhiyun struct NCR_700_SG_List {
70*4882a593Smuzhiyun 	/* The following is a script fragment to move the buffer onto the
71*4882a593Smuzhiyun 	 * bus and then link the next fragment or return */
72*4882a593Smuzhiyun 	#define	SCRIPT_MOVE_DATA_IN		0x09000000
73*4882a593Smuzhiyun 	#define	SCRIPT_MOVE_DATA_OUT		0x08000000
74*4882a593Smuzhiyun 	__u32	ins;
75*4882a593Smuzhiyun 	__u32	pAddr;
76*4882a593Smuzhiyun 	#define	SCRIPT_NOP			0x80000000
77*4882a593Smuzhiyun 	#define	SCRIPT_RETURN			0x90080000
78*4882a593Smuzhiyun };
79*4882a593Smuzhiyun 
80*4882a593Smuzhiyun struct NCR_700_Device_Parameters {
81*4882a593Smuzhiyun 	/* space for creating a request sense command. Really, except
82*4882a593Smuzhiyun 	 * for the annoying SCSI-2 requirement for LUN information in
83*4882a593Smuzhiyun 	 * cmnd[1], this could be in static storage */
84*4882a593Smuzhiyun 	unsigned char cmnd[MAX_COMMAND_SIZE];
85*4882a593Smuzhiyun 	__u8	depth;
86*4882a593Smuzhiyun 	struct scsi_cmnd *current_cmnd;	/* currently active command */
87*4882a593Smuzhiyun };
88*4882a593Smuzhiyun 
89*4882a593Smuzhiyun 
90*4882a593Smuzhiyun /* The SYNC negotiation sequence looks like:
91*4882a593Smuzhiyun  *
92*4882a593Smuzhiyun  * If DEV_NEGOTIATED_SYNC not set, tack and SDTR message on to the
93*4882a593Smuzhiyun  * initial identify for the device and set DEV_BEGIN_SYNC_NEGOTIATION
94*4882a593Smuzhiyun  * If we get an SDTR reply, work out the SXFER parameters, squirrel
95*4882a593Smuzhiyun  * them away here, clear DEV_BEGIN_SYNC_NEGOTIATION and set
96*4882a593Smuzhiyun  * DEV_NEGOTIATED_SYNC.  If we get a REJECT msg, squirrel
97*4882a593Smuzhiyun  *
98*4882a593Smuzhiyun  *
99*4882a593Smuzhiyun  * 0:7	SXFER_REG negotiated value for this device
100*4882a593Smuzhiyun  * 8:15 Current queue depth
101*4882a593Smuzhiyun  * 16	negotiated SYNC flag
102*4882a593Smuzhiyun  * 17 begin SYNC negotiation flag
103*4882a593Smuzhiyun  * 18 device supports tag queueing */
104*4882a593Smuzhiyun #define NCR_700_DEV_NEGOTIATED_SYNC	(1<<16)
105*4882a593Smuzhiyun #define NCR_700_DEV_BEGIN_SYNC_NEGOTIATION	(1<<17)
106*4882a593Smuzhiyun #define NCR_700_DEV_PRINT_SYNC_NEGOTIATION (1<<19)
107*4882a593Smuzhiyun 
NCR_700_get_sense_cmnd(struct scsi_device * SDp)108*4882a593Smuzhiyun static inline char *NCR_700_get_sense_cmnd(struct scsi_device *SDp)
109*4882a593Smuzhiyun {
110*4882a593Smuzhiyun 	struct NCR_700_Device_Parameters *hostdata = SDp->hostdata;
111*4882a593Smuzhiyun 
112*4882a593Smuzhiyun 	return hostdata->cmnd;
113*4882a593Smuzhiyun }
114*4882a593Smuzhiyun 
115*4882a593Smuzhiyun static inline void
NCR_700_set_depth(struct scsi_device * SDp,__u8 depth)116*4882a593Smuzhiyun NCR_700_set_depth(struct scsi_device *SDp, __u8 depth)
117*4882a593Smuzhiyun {
118*4882a593Smuzhiyun 	struct NCR_700_Device_Parameters *hostdata = SDp->hostdata;
119*4882a593Smuzhiyun 
120*4882a593Smuzhiyun 	hostdata->depth = depth;
121*4882a593Smuzhiyun }
122*4882a593Smuzhiyun static inline __u8
NCR_700_get_depth(struct scsi_device * SDp)123*4882a593Smuzhiyun NCR_700_get_depth(struct scsi_device *SDp)
124*4882a593Smuzhiyun {
125*4882a593Smuzhiyun 	struct NCR_700_Device_Parameters *hostdata = SDp->hostdata;
126*4882a593Smuzhiyun 
127*4882a593Smuzhiyun 	return hostdata->depth;
128*4882a593Smuzhiyun }
129*4882a593Smuzhiyun static inline int
NCR_700_is_flag_set(struct scsi_device * SDp,__u32 flag)130*4882a593Smuzhiyun NCR_700_is_flag_set(struct scsi_device *SDp, __u32 flag)
131*4882a593Smuzhiyun {
132*4882a593Smuzhiyun 	return (spi_flags(SDp->sdev_target) & flag) == flag;
133*4882a593Smuzhiyun }
134*4882a593Smuzhiyun static inline int
NCR_700_is_flag_clear(struct scsi_device * SDp,__u32 flag)135*4882a593Smuzhiyun NCR_700_is_flag_clear(struct scsi_device *SDp, __u32 flag)
136*4882a593Smuzhiyun {
137*4882a593Smuzhiyun 	return (spi_flags(SDp->sdev_target) & flag) == 0;
138*4882a593Smuzhiyun }
139*4882a593Smuzhiyun static inline void
NCR_700_set_flag(struct scsi_device * SDp,__u32 flag)140*4882a593Smuzhiyun NCR_700_set_flag(struct scsi_device *SDp, __u32 flag)
141*4882a593Smuzhiyun {
142*4882a593Smuzhiyun 	spi_flags(SDp->sdev_target) |= flag;
143*4882a593Smuzhiyun }
144*4882a593Smuzhiyun static inline void
NCR_700_clear_flag(struct scsi_device * SDp,__u32 flag)145*4882a593Smuzhiyun NCR_700_clear_flag(struct scsi_device *SDp, __u32 flag)
146*4882a593Smuzhiyun {
147*4882a593Smuzhiyun 	spi_flags(SDp->sdev_target) &= ~flag;
148*4882a593Smuzhiyun }
149*4882a593Smuzhiyun 
150*4882a593Smuzhiyun enum NCR_700_tag_neg_state {
151*4882a593Smuzhiyun 	NCR_700_START_TAG_NEGOTIATION = 0,
152*4882a593Smuzhiyun 	NCR_700_DURING_TAG_NEGOTIATION = 1,
153*4882a593Smuzhiyun 	NCR_700_FINISHED_TAG_NEGOTIATION = 2,
154*4882a593Smuzhiyun };
155*4882a593Smuzhiyun 
156*4882a593Smuzhiyun static inline enum NCR_700_tag_neg_state
NCR_700_get_tag_neg_state(struct scsi_device * SDp)157*4882a593Smuzhiyun NCR_700_get_tag_neg_state(struct scsi_device *SDp)
158*4882a593Smuzhiyun {
159*4882a593Smuzhiyun 	return (enum NCR_700_tag_neg_state)((spi_flags(SDp->sdev_target)>>20) & 0x3);
160*4882a593Smuzhiyun }
161*4882a593Smuzhiyun 
162*4882a593Smuzhiyun static inline void
NCR_700_set_tag_neg_state(struct scsi_device * SDp,enum NCR_700_tag_neg_state state)163*4882a593Smuzhiyun NCR_700_set_tag_neg_state(struct scsi_device *SDp,
164*4882a593Smuzhiyun 			  enum NCR_700_tag_neg_state state)
165*4882a593Smuzhiyun {
166*4882a593Smuzhiyun 	/* clear the slot */
167*4882a593Smuzhiyun 	spi_flags(SDp->sdev_target) &= ~(0x3 << 20);
168*4882a593Smuzhiyun 	spi_flags(SDp->sdev_target) |= ((__u32)state) << 20;
169*4882a593Smuzhiyun }
170*4882a593Smuzhiyun 
171*4882a593Smuzhiyun struct NCR_700_command_slot {
172*4882a593Smuzhiyun 	struct NCR_700_SG_List	SG[NCR_700_SG_SEGMENTS+1];
173*4882a593Smuzhiyun 	struct NCR_700_SG_List	*pSG;
174*4882a593Smuzhiyun 	#define NCR_700_SLOT_MASK 0xFC
175*4882a593Smuzhiyun 	#define NCR_700_SLOT_MAGIC 0xb8
176*4882a593Smuzhiyun 	#define	NCR_700_SLOT_FREE (0|NCR_700_SLOT_MAGIC) /* slot may be used */
177*4882a593Smuzhiyun 	#define NCR_700_SLOT_BUSY (1|NCR_700_SLOT_MAGIC) /* slot has command active on HA */
178*4882a593Smuzhiyun 	#define NCR_700_SLOT_QUEUED (2|NCR_700_SLOT_MAGIC) /* slot has command to be made active on HA */
179*4882a593Smuzhiyun 	__u8	state;
180*4882a593Smuzhiyun 	#define NCR_700_FLAG_AUTOSENSE	0x01
181*4882a593Smuzhiyun 	__u8	flags;
182*4882a593Smuzhiyun 	__u8	pad1[2];	/* Needed for m68k where min alignment is 2 bytes */
183*4882a593Smuzhiyun 	int	tag;
184*4882a593Smuzhiyun 	__u32	resume_offset;
185*4882a593Smuzhiyun 	struct scsi_cmnd *cmnd;
186*4882a593Smuzhiyun 	/* The pci_mapped address of the actual command in cmnd */
187*4882a593Smuzhiyun 	dma_addr_t	pCmd;
188*4882a593Smuzhiyun 	__u32		temp;
189*4882a593Smuzhiyun 	/* if this command is a pci_single mapping, holds the dma address
190*4882a593Smuzhiyun 	 * for later unmapping in the done routine */
191*4882a593Smuzhiyun 	dma_addr_t	dma_handle;
192*4882a593Smuzhiyun 	/* historical remnant, now used to link free commands */
193*4882a593Smuzhiyun 	struct NCR_700_command_slot *ITL_forw;
194*4882a593Smuzhiyun };
195*4882a593Smuzhiyun 
196*4882a593Smuzhiyun struct NCR_700_Host_Parameters {
197*4882a593Smuzhiyun 	/* These must be filled in by the calling driver */
198*4882a593Smuzhiyun 	int	clock;			/* board clock speed in MHz */
199*4882a593Smuzhiyun 	void __iomem	*base;		/* the base for the port (copied to host) */
200*4882a593Smuzhiyun 	struct device	*dev;
201*4882a593Smuzhiyun 	__u32	dmode_extra;	/* adjustable bus settings */
202*4882a593Smuzhiyun 	__u32	dcntl_extra;	/* adjustable bus settings */
203*4882a593Smuzhiyun 	__u32	ctest7_extra;	/* adjustable bus settings */
204*4882a593Smuzhiyun 	__u32	differential:1;	/* if we are differential */
205*4882a593Smuzhiyun #ifdef CONFIG_53C700_LE_ON_BE
206*4882a593Smuzhiyun 	/* This option is for HP only.  Set it if your chip is wired for
207*4882a593Smuzhiyun 	 * little endian on this platform (which is big endian) */
208*4882a593Smuzhiyun 	__u32	force_le_on_be:1;
209*4882a593Smuzhiyun #endif
210*4882a593Smuzhiyun 	__u32	chip710:1;	/* set if really a 710 not 700 */
211*4882a593Smuzhiyun 	__u32	burst_length:4;	/* set to 0 to disable 710 bursting */
212*4882a593Smuzhiyun 	__u32	noncoherent:1;	/* needs to use non-coherent DMA */
213*4882a593Smuzhiyun 
214*4882a593Smuzhiyun 	/* NOTHING BELOW HERE NEEDS ALTERING */
215*4882a593Smuzhiyun 	__u32	fast:1;		/* if we can alter the SCSI bus clock
216*4882a593Smuzhiyun                                    speed (so can negiotiate sync) */
217*4882a593Smuzhiyun 	int	sync_clock;	/* The speed of the SYNC core */
218*4882a593Smuzhiyun 
219*4882a593Smuzhiyun 	__u32	*script;		/* pointer to script location */
220*4882a593Smuzhiyun 	__u32	pScript;		/* physical mem addr of script */
221*4882a593Smuzhiyun 
222*4882a593Smuzhiyun 	enum NCR_700_Host_State state; /* protected by state lock */
223*4882a593Smuzhiyun 	struct scsi_cmnd *cmd;
224*4882a593Smuzhiyun 	/* Note: pScript contains the single consistent block of
225*4882a593Smuzhiyun 	 * memory.  All the msgin, msgout and status are allocated in
226*4882a593Smuzhiyun 	 * this memory too (at separate cache lines).  TOTAL_MEM_SIZE
227*4882a593Smuzhiyun 	 * represents the total size of this area */
228*4882a593Smuzhiyun #define	MSG_ARRAY_SIZE	8
229*4882a593Smuzhiyun #define	MSGOUT_OFFSET	(L1_CACHE_ALIGN(sizeof(SCRIPT)))
230*4882a593Smuzhiyun 	__u8	*msgout;
231*4882a593Smuzhiyun #define MSGIN_OFFSET	(MSGOUT_OFFSET + L1_CACHE_ALIGN(MSG_ARRAY_SIZE))
232*4882a593Smuzhiyun 	__u8	*msgin;
233*4882a593Smuzhiyun #define STATUS_OFFSET	(MSGIN_OFFSET + L1_CACHE_ALIGN(MSG_ARRAY_SIZE))
234*4882a593Smuzhiyun 	__u8	*status;
235*4882a593Smuzhiyun #define SLOTS_OFFSET	(STATUS_OFFSET + L1_CACHE_ALIGN(MSG_ARRAY_SIZE))
236*4882a593Smuzhiyun 	struct NCR_700_command_slot	*slots;
237*4882a593Smuzhiyun #define	TOTAL_MEM_SIZE	(SLOTS_OFFSET + L1_CACHE_ALIGN(sizeof(struct NCR_700_command_slot) * NCR_700_COMMAND_SLOTS_PER_HOST))
238*4882a593Smuzhiyun 	int	saved_slot_position;
239*4882a593Smuzhiyun 	int	command_slot_count; /* protected by state lock */
240*4882a593Smuzhiyun 	__u8	tag_negotiated;
241*4882a593Smuzhiyun 	__u8	rev;
242*4882a593Smuzhiyun 	__u8	reselection_id;
243*4882a593Smuzhiyun 	__u8	min_period;
244*4882a593Smuzhiyun 
245*4882a593Smuzhiyun 	/* Free list, singly linked by ITL_forw elements */
246*4882a593Smuzhiyun 	struct NCR_700_command_slot *free_list;
247*4882a593Smuzhiyun 	/* Completion for waited for ops, like reset, abort or
248*4882a593Smuzhiyun 	 * device reset.
249*4882a593Smuzhiyun 	 *
250*4882a593Smuzhiyun 	 * NOTE: relies on single threading in the error handler to
251*4882a593Smuzhiyun 	 * have only one outstanding at once */
252*4882a593Smuzhiyun 	struct completion *eh_complete;
253*4882a593Smuzhiyun };
254*4882a593Smuzhiyun 
255*4882a593Smuzhiyun /*
256*4882a593Smuzhiyun  *	53C700 Register Interface - the offset from the Selected base
257*4882a593Smuzhiyun  *	I/O address */
258*4882a593Smuzhiyun #ifdef CONFIG_53C700_LE_ON_BE
259*4882a593Smuzhiyun #define bE	(hostdata->force_le_on_be ? 0 : 3)
260*4882a593Smuzhiyun #define	bSWAP	(hostdata->force_le_on_be)
261*4882a593Smuzhiyun #define bEBus	(!hostdata->force_le_on_be)
262*4882a593Smuzhiyun #elif defined(__BIG_ENDIAN)
263*4882a593Smuzhiyun #define bE	3
264*4882a593Smuzhiyun #define bSWAP	0
265*4882a593Smuzhiyun #elif defined(__LITTLE_ENDIAN)
266*4882a593Smuzhiyun #define bE	0
267*4882a593Smuzhiyun #define bSWAP	0
268*4882a593Smuzhiyun #else
269*4882a593Smuzhiyun #error "__BIG_ENDIAN or __LITTLE_ENDIAN must be defined, did you include byteorder.h?"
270*4882a593Smuzhiyun #endif
271*4882a593Smuzhiyun #ifndef bEBus
272*4882a593Smuzhiyun #ifdef CONFIG_53C700_BE_BUS
273*4882a593Smuzhiyun #define bEBus	1
274*4882a593Smuzhiyun #else
275*4882a593Smuzhiyun #define bEBus	0
276*4882a593Smuzhiyun #endif
277*4882a593Smuzhiyun #endif
278*4882a593Smuzhiyun #define bS_to_cpu(x)	(bSWAP ? le32_to_cpu(x) : (x))
279*4882a593Smuzhiyun #define bS_to_host(x)	(bSWAP ? cpu_to_le32(x) : (x))
280*4882a593Smuzhiyun 
281*4882a593Smuzhiyun /* NOTE: These registers are in the LE register space only, the required byte
282*4882a593Smuzhiyun  * swapping is done by the NCR_700_{read|write}[b] functions */
283*4882a593Smuzhiyun #define	SCNTL0_REG			0x00
284*4882a593Smuzhiyun #define		FULL_ARBITRATION	0xc0
285*4882a593Smuzhiyun #define 	PARITY			0x08
286*4882a593Smuzhiyun #define		ENABLE_PARITY		0x04
287*4882a593Smuzhiyun #define 	AUTO_ATN		0x02
288*4882a593Smuzhiyun #define	SCNTL1_REG			0x01
289*4882a593Smuzhiyun #define 	SLOW_BUS		0x80
290*4882a593Smuzhiyun #define		ENABLE_SELECT		0x20
291*4882a593Smuzhiyun #define		ASSERT_RST		0x08
292*4882a593Smuzhiyun #define		ASSERT_EVEN_PARITY	0x04
293*4882a593Smuzhiyun #define	SDID_REG			0x02
294*4882a593Smuzhiyun #define	SIEN_REG			0x03
295*4882a593Smuzhiyun #define 	PHASE_MM_INT		0x80
296*4882a593Smuzhiyun #define 	FUNC_COMP_INT		0x40
297*4882a593Smuzhiyun #define 	SEL_TIMEOUT_INT		0x20
298*4882a593Smuzhiyun #define 	SELECT_INT		0x10
299*4882a593Smuzhiyun #define 	GROSS_ERR_INT		0x08
300*4882a593Smuzhiyun #define 	UX_DISC_INT		0x04
301*4882a593Smuzhiyun #define 	RST_INT			0x02
302*4882a593Smuzhiyun #define 	PAR_ERR_INT		0x01
303*4882a593Smuzhiyun #define	SCID_REG			0x04
304*4882a593Smuzhiyun #define SXFER_REG			0x05
305*4882a593Smuzhiyun #define		ASYNC_OPERATION		0x00
306*4882a593Smuzhiyun #define SODL_REG                        0x06
307*4882a593Smuzhiyun #define	SOCL_REG			0x07
308*4882a593Smuzhiyun #define	SFBR_REG			0x08
309*4882a593Smuzhiyun #define	SIDL_REG			0x09
310*4882a593Smuzhiyun #define	SBDL_REG			0x0A
311*4882a593Smuzhiyun #define	SBCL_REG			0x0B
312*4882a593Smuzhiyun /* read bits */
313*4882a593Smuzhiyun #define		SBCL_IO			0x01
314*4882a593Smuzhiyun /*write bits */
315*4882a593Smuzhiyun #define		SYNC_DIV_AS_ASYNC	0x00
316*4882a593Smuzhiyun #define		SYNC_DIV_1_0		0x01
317*4882a593Smuzhiyun #define		SYNC_DIV_1_5		0x02
318*4882a593Smuzhiyun #define		SYNC_DIV_2_0		0x03
319*4882a593Smuzhiyun #define	DSTAT_REG			0x0C
320*4882a593Smuzhiyun #define		ILGL_INST_DETECTED	0x01
321*4882a593Smuzhiyun #define		WATCH_DOG_INTERRUPT	0x02
322*4882a593Smuzhiyun #define		SCRIPT_INT_RECEIVED	0x04
323*4882a593Smuzhiyun #define		ABORTED			0x10
324*4882a593Smuzhiyun #define	SSTAT0_REG			0x0D
325*4882a593Smuzhiyun #define		PARITY_ERROR		0x01
326*4882a593Smuzhiyun #define		SCSI_RESET_DETECTED	0x02
327*4882a593Smuzhiyun #define		UNEXPECTED_DISCONNECT	0x04
328*4882a593Smuzhiyun #define		SCSI_GROSS_ERROR	0x08
329*4882a593Smuzhiyun #define		SELECTED		0x10
330*4882a593Smuzhiyun #define		SELECTION_TIMEOUT	0x20
331*4882a593Smuzhiyun #define		FUNCTION_COMPLETE	0x40
332*4882a593Smuzhiyun #define		PHASE_MISMATCH 		0x80
333*4882a593Smuzhiyun #define	SSTAT1_REG			0x0E
334*4882a593Smuzhiyun #define		SIDL_REG_FULL		0x80
335*4882a593Smuzhiyun #define		SODR_REG_FULL		0x40
336*4882a593Smuzhiyun #define		SODL_REG_FULL		0x20
337*4882a593Smuzhiyun #define SSTAT2_REG                      0x0F
338*4882a593Smuzhiyun #define CTEST0_REG                      0x14
339*4882a593Smuzhiyun #define		BTB_TIMER_DISABLE	0x40
340*4882a593Smuzhiyun #define CTEST1_REG                      0x15
341*4882a593Smuzhiyun #define CTEST2_REG                      0x16
342*4882a593Smuzhiyun #define CTEST3_REG                      0x17
343*4882a593Smuzhiyun #define CTEST4_REG                      0x18
344*4882a593Smuzhiyun #define         DISABLE_FIFO            0x00
345*4882a593Smuzhiyun #define         SLBE                    0x10
346*4882a593Smuzhiyun #define         SFWR                    0x08
347*4882a593Smuzhiyun #define         BYTE_LANE0              0x04
348*4882a593Smuzhiyun #define         BYTE_LANE1              0x05
349*4882a593Smuzhiyun #define         BYTE_LANE2              0x06
350*4882a593Smuzhiyun #define         BYTE_LANE3              0x07
351*4882a593Smuzhiyun #define         SCSI_ZMODE              0x20
352*4882a593Smuzhiyun #define         ZMODE                   0x40
353*4882a593Smuzhiyun #define CTEST5_REG                      0x19
354*4882a593Smuzhiyun #define         MASTER_CONTROL          0x10
355*4882a593Smuzhiyun #define         DMA_DIRECTION           0x08
356*4882a593Smuzhiyun #define CTEST7_REG                      0x1B
357*4882a593Smuzhiyun #define		BURST_DISABLE		0x80 /* 710 only */
358*4882a593Smuzhiyun #define		SEL_TIMEOUT_DISABLE	0x10 /* 710 only */
359*4882a593Smuzhiyun #define         DFP                     0x08
360*4882a593Smuzhiyun #define         EVP                     0x04
361*4882a593Smuzhiyun #define         CTEST7_TT1              0x02
362*4882a593Smuzhiyun #define		DIFF			0x01
363*4882a593Smuzhiyun #define CTEST6_REG                      0x1A
364*4882a593Smuzhiyun #define	TEMP_REG			0x1C
365*4882a593Smuzhiyun #define	DFIFO_REG			0x20
366*4882a593Smuzhiyun #define		FLUSH_DMA_FIFO		0x80
367*4882a593Smuzhiyun #define		CLR_FIFO		0x40
368*4882a593Smuzhiyun #define	ISTAT_REG			0x21
369*4882a593Smuzhiyun #define		ABORT_OPERATION		0x80
370*4882a593Smuzhiyun #define		SOFTWARE_RESET_710	0x40
371*4882a593Smuzhiyun #define		DMA_INT_PENDING		0x01
372*4882a593Smuzhiyun #define		SCSI_INT_PENDING	0x02
373*4882a593Smuzhiyun #define		CONNECTED		0x08
374*4882a593Smuzhiyun #define CTEST8_REG                      0x22
375*4882a593Smuzhiyun #define         LAST_DIS_ENBL           0x01
376*4882a593Smuzhiyun #define		SHORTEN_FILTERING	0x04
377*4882a593Smuzhiyun #define		ENABLE_ACTIVE_NEGATION	0x10
378*4882a593Smuzhiyun #define		GENERATE_RECEIVE_PARITY	0x20
379*4882a593Smuzhiyun #define		CLR_FIFO_710		0x04
380*4882a593Smuzhiyun #define		FLUSH_DMA_FIFO_710	0x08
381*4882a593Smuzhiyun #define CTEST9_REG                      0x23
382*4882a593Smuzhiyun #define	DBC_REG				0x24
383*4882a593Smuzhiyun #define	DCMD_REG			0x27
384*4882a593Smuzhiyun #define	DNAD_REG			0x28
385*4882a593Smuzhiyun #define	DIEN_REG			0x39
386*4882a593Smuzhiyun #define		BUS_FAULT		0x20
387*4882a593Smuzhiyun #define 	ABORT_INT		0x10
388*4882a593Smuzhiyun #define 	INT_INST_INT		0x04
389*4882a593Smuzhiyun #define 	WD_INT			0x02
390*4882a593Smuzhiyun #define 	ILGL_INST_INT		0x01
391*4882a593Smuzhiyun #define	DCNTL_REG			0x3B
392*4882a593Smuzhiyun #define		SOFTWARE_RESET		0x01
393*4882a593Smuzhiyun #define		COMPAT_700_MODE		0x01
394*4882a593Smuzhiyun #define 	SCRPTS_16BITS		0x20
395*4882a593Smuzhiyun #define		EA_710			0x20
396*4882a593Smuzhiyun #define		ASYNC_DIV_2_0		0x00
397*4882a593Smuzhiyun #define		ASYNC_DIV_1_5		0x40
398*4882a593Smuzhiyun #define		ASYNC_DIV_1_0		0x80
399*4882a593Smuzhiyun #define		ASYNC_DIV_3_0		0xc0
400*4882a593Smuzhiyun #define DMODE_710_REG			0x38
401*4882a593Smuzhiyun #define	DMODE_700_REG			0x34
402*4882a593Smuzhiyun #define		BURST_LENGTH_1		0x00
403*4882a593Smuzhiyun #define		BURST_LENGTH_2		0x40
404*4882a593Smuzhiyun #define		BURST_LENGTH_4		0x80
405*4882a593Smuzhiyun #define		BURST_LENGTH_8		0xC0
406*4882a593Smuzhiyun #define		DMODE_FC1		0x10
407*4882a593Smuzhiyun #define		DMODE_FC2		0x20
408*4882a593Smuzhiyun #define 	BW16			32
409*4882a593Smuzhiyun #define 	MODE_286		16
410*4882a593Smuzhiyun #define 	IO_XFER			8
411*4882a593Smuzhiyun #define 	FIXED_ADDR		4
412*4882a593Smuzhiyun 
413*4882a593Smuzhiyun #define DSP_REG                         0x2C
414*4882a593Smuzhiyun #define DSPS_REG                        0x30
415*4882a593Smuzhiyun 
416*4882a593Smuzhiyun /* Parameters to begin SDTR negotiations.  Empirically, I find that
417*4882a593Smuzhiyun  * the 53c700-66 cannot handle an offset >8, so don't change this  */
418*4882a593Smuzhiyun #define NCR_700_MAX_OFFSET	8
419*4882a593Smuzhiyun /* Was hoping the max offset would be greater for the 710, but
420*4882a593Smuzhiyun  * empirically it seems to be 8 also */
421*4882a593Smuzhiyun #define NCR_710_MAX_OFFSET	8
422*4882a593Smuzhiyun #define NCR_700_MIN_XFERP	1
423*4882a593Smuzhiyun #define NCR_710_MIN_XFERP	0
424*4882a593Smuzhiyun #define NCR_700_MIN_PERIOD	25 /* for SDTR message, 100ns */
425*4882a593Smuzhiyun 
426*4882a593Smuzhiyun #define script_patch_32(h, script, symbol, value) \
427*4882a593Smuzhiyun { \
428*4882a593Smuzhiyun 	int i; \
429*4882a593Smuzhiyun 	dma_addr_t da = value; \
430*4882a593Smuzhiyun 	for(i=0; i< (sizeof(A_##symbol##_used) / sizeof(__u32)); i++) { \
431*4882a593Smuzhiyun 		__u32 val = bS_to_cpu((script)[A_##symbol##_used[i]]) + da; \
432*4882a593Smuzhiyun 		(script)[A_##symbol##_used[i]] = bS_to_host(val); \
433*4882a593Smuzhiyun 		dma_sync_to_dev((h), &(script)[A_##symbol##_used[i]], 4); \
434*4882a593Smuzhiyun 		DEBUG((" script, patching %s at %d to %pad\n", \
435*4882a593Smuzhiyun 		       #symbol, A_##symbol##_used[i], &da)); \
436*4882a593Smuzhiyun 	} \
437*4882a593Smuzhiyun }
438*4882a593Smuzhiyun 
439*4882a593Smuzhiyun #define script_patch_32_abs(h, script, symbol, value) \
440*4882a593Smuzhiyun { \
441*4882a593Smuzhiyun 	int i; \
442*4882a593Smuzhiyun 	dma_addr_t da = value; \
443*4882a593Smuzhiyun 	for(i=0; i< (sizeof(A_##symbol##_used) / sizeof(__u32)); i++) { \
444*4882a593Smuzhiyun 		(script)[A_##symbol##_used[i]] = bS_to_host(da); \
445*4882a593Smuzhiyun 		dma_sync_to_dev((h), &(script)[A_##symbol##_used[i]], 4); \
446*4882a593Smuzhiyun 		DEBUG((" script, patching %s at %d to %pad\n", \
447*4882a593Smuzhiyun 		       #symbol, A_##symbol##_used[i], &da)); \
448*4882a593Smuzhiyun 	} \
449*4882a593Smuzhiyun }
450*4882a593Smuzhiyun 
451*4882a593Smuzhiyun /* Used for patching the SCSI ID in the SELECT instruction */
452*4882a593Smuzhiyun #define script_patch_ID(h, script, symbol, value) \
453*4882a593Smuzhiyun { \
454*4882a593Smuzhiyun 	int i; \
455*4882a593Smuzhiyun 	for(i=0; i< (sizeof(A_##symbol##_used) / sizeof(__u32)); i++) { \
456*4882a593Smuzhiyun 		__u32 val = bS_to_cpu((script)[A_##symbol##_used[i]]); \
457*4882a593Smuzhiyun 		val &= 0xff00ffff; \
458*4882a593Smuzhiyun 		val |= ((value) & 0xff) << 16; \
459*4882a593Smuzhiyun 		(script)[A_##symbol##_used[i]] = bS_to_host(val); \
460*4882a593Smuzhiyun 		dma_sync_to_dev((h), &(script)[A_##symbol##_used[i]], 4); \
461*4882a593Smuzhiyun 		DEBUG((" script, patching ID field %s at %d to 0x%x\n", \
462*4882a593Smuzhiyun 		       #symbol, A_##symbol##_used[i], val)); \
463*4882a593Smuzhiyun 	} \
464*4882a593Smuzhiyun }
465*4882a593Smuzhiyun 
466*4882a593Smuzhiyun #define script_patch_16(h, script, symbol, value) \
467*4882a593Smuzhiyun { \
468*4882a593Smuzhiyun 	int i; \
469*4882a593Smuzhiyun 	for(i=0; i< (sizeof(A_##symbol##_used) / sizeof(__u32)); i++) { \
470*4882a593Smuzhiyun 		__u32 val = bS_to_cpu((script)[A_##symbol##_used[i]]); \
471*4882a593Smuzhiyun 		val &= 0xffff0000; \
472*4882a593Smuzhiyun 		val |= ((value) & 0xffff); \
473*4882a593Smuzhiyun 		(script)[A_##symbol##_used[i]] = bS_to_host(val); \
474*4882a593Smuzhiyun 		dma_sync_to_dev((h), &(script)[A_##symbol##_used[i]], 4); \
475*4882a593Smuzhiyun 		DEBUG((" script, patching short field %s at %d to 0x%x\n", \
476*4882a593Smuzhiyun 		       #symbol, A_##symbol##_used[i], val)); \
477*4882a593Smuzhiyun 	} \
478*4882a593Smuzhiyun }
479*4882a593Smuzhiyun 
480*4882a593Smuzhiyun 
481*4882a593Smuzhiyun static inline __u8
NCR_700_readb(struct Scsi_Host * host,__u32 reg)482*4882a593Smuzhiyun NCR_700_readb(struct Scsi_Host *host, __u32 reg)
483*4882a593Smuzhiyun {
484*4882a593Smuzhiyun 	const struct NCR_700_Host_Parameters *hostdata
485*4882a593Smuzhiyun 		= (struct NCR_700_Host_Parameters *)host->hostdata[0];
486*4882a593Smuzhiyun 
487*4882a593Smuzhiyun 	return ioread8(hostdata->base + (reg^bE));
488*4882a593Smuzhiyun }
489*4882a593Smuzhiyun 
490*4882a593Smuzhiyun static inline __u32
NCR_700_readl(struct Scsi_Host * host,__u32 reg)491*4882a593Smuzhiyun NCR_700_readl(struct Scsi_Host *host, __u32 reg)
492*4882a593Smuzhiyun {
493*4882a593Smuzhiyun 	const struct NCR_700_Host_Parameters *hostdata
494*4882a593Smuzhiyun 		= (struct NCR_700_Host_Parameters *)host->hostdata[0];
495*4882a593Smuzhiyun 	__u32 value = bEBus ? ioread32be(hostdata->base + reg) :
496*4882a593Smuzhiyun 		ioread32(hostdata->base + reg);
497*4882a593Smuzhiyun #if 1
498*4882a593Smuzhiyun 	/* sanity check the register */
499*4882a593Smuzhiyun 	BUG_ON((reg & 0x3) != 0);
500*4882a593Smuzhiyun #endif
501*4882a593Smuzhiyun 
502*4882a593Smuzhiyun 	return value;
503*4882a593Smuzhiyun }
504*4882a593Smuzhiyun 
505*4882a593Smuzhiyun static inline void
NCR_700_writeb(__u8 value,struct Scsi_Host * host,__u32 reg)506*4882a593Smuzhiyun NCR_700_writeb(__u8 value, struct Scsi_Host *host, __u32 reg)
507*4882a593Smuzhiyun {
508*4882a593Smuzhiyun 	const struct NCR_700_Host_Parameters *hostdata
509*4882a593Smuzhiyun 		= (struct NCR_700_Host_Parameters *)host->hostdata[0];
510*4882a593Smuzhiyun 
511*4882a593Smuzhiyun 	iowrite8(value, hostdata->base + (reg^bE));
512*4882a593Smuzhiyun }
513*4882a593Smuzhiyun 
514*4882a593Smuzhiyun static inline void
NCR_700_writel(__u32 value,struct Scsi_Host * host,__u32 reg)515*4882a593Smuzhiyun NCR_700_writel(__u32 value, struct Scsi_Host *host, __u32 reg)
516*4882a593Smuzhiyun {
517*4882a593Smuzhiyun 	const struct NCR_700_Host_Parameters *hostdata
518*4882a593Smuzhiyun 		= (struct NCR_700_Host_Parameters *)host->hostdata[0];
519*4882a593Smuzhiyun 
520*4882a593Smuzhiyun #if 1
521*4882a593Smuzhiyun 	/* sanity check the register */
522*4882a593Smuzhiyun 	BUG_ON((reg & 0x3) != 0);
523*4882a593Smuzhiyun #endif
524*4882a593Smuzhiyun 
525*4882a593Smuzhiyun 	bEBus ? iowrite32be(value, hostdata->base + reg):
526*4882a593Smuzhiyun 		iowrite32(value, hostdata->base + reg);
527*4882a593Smuzhiyun }
528*4882a593Smuzhiyun 
529*4882a593Smuzhiyun #endif
530