1 /*
2  * Device driver for the SYMBIOS/LSILOGIC 53C8XX and 53C1010 family
3  * of PCI-SCSI IO processors.
4  *
5  * Copyright (C) 1999-2001  Gerard Roudier <groudier@free.fr>
6  *
7  * This driver is derived from the Linux sym53c8xx driver.
8  * Copyright (C) 1998-2000  Gerard Roudier
9  *
10  * The sym53c8xx driver is derived from the ncr53c8xx driver that had been
11  * a port of the FreeBSD ncr driver to Linux-1.2.13.
12  *
13  * The original ncr driver has been written for 386bsd and FreeBSD by
14  *         Wolfgang Stanglmeier        <wolf@cologne.de>
15  *         Stefan Esser                <se@mi.Uni-Koeln.de>
16  * Copyright (C) 1994  Wolfgang Stanglmeier
17  *
18  * Other major contributions:
19  *
20  * NVRAM detection and reading.
21  * Copyright (C) 1997 Richard Waltham <dormouse@farsrobt.demon.co.uk>
22  *
23  *-----------------------------------------------------------------------------
24  *
25  * Redistribution and use in source and binary forms, with or without
26  * modification, are permitted provided that the following conditions
27  * are met:
28  * 1. Redistributions of source code must retain the above copyright
29  *    notice, this list of conditions and the following disclaimer.
30  * 2. The name of the author may not be used to endorse or promote products
31  *    derived from this software without specific prior written permission.
32  *
33  * Where this Software is combined with software released under the terms of
34  * the GNU Public License ("GPL") and the terms of the GPL would require the
35  * combined work to also be released under the terms of the GPL, the terms
36  * and conditions of this License will apply in addition to those of the
37  * GPL with the exception of any terms or conditions of this License that
38  * conflict with, or are expressly prohibited by, the GPL.
39  *
40  * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
41  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
42  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
43  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
44  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
45  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
46  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
48  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
49  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
50  * SUCH DAMAGE.
51  */
52 
53 #ifndef SYM53C8XX_H
54 #define SYM53C8XX_H
55 
56 #if !defined(LINUX_VERSION_CODE)
57 #include <linux/version.h>
58 #endif
59 #include <linux/config.h>
60 
61 /*
62  *  Compatibility with ncr53c8xx and sym53c8xx configuration options.
63  */
64 #ifndef	CONFIG_SCSI_SYM53C8XX_IOMAPPED
65 #ifdef	CONFIG_SCSI_NCR53C8XX_IOMAPPED
66 #define	CONFIG_SCSI_SYM53C8XX_IOMAPPED		CONFIG_SCSI_NCR53C8XX_IOMAPPED
67 #endif
68 #endif
69 
70 #ifndef	CONFIG_SCSI_SYM53C8XX_DEFAULT_TAGS
71 #ifdef	CONFIG_SCSI_NCR53C8XX_DEFAULT_TAGS
72 #define	CONFIG_SCSI_SYM53C8XX_DEFAULT_TAGS	CONFIG_SCSI_NCR53C8XX_DEFAULT_TAGS
73 #endif
74 #endif
75 
76 #ifndef	CONFIG_SCSI_SYM53C8XX_MAX_TAGS
77 #ifdef	CONFIG_SCSI_NCR53C8XX_MAX_TAGS
78 #define	CONFIG_SCSI_SYM53C8XX_MAX_TAGS		CONFIG_SCSI_NCR53C8XX_MAX_TAGS
79 #endif
80 #endif
81 
82 int sym53c8xx_detect(Scsi_Host_Template *tpnt);
83 const char *sym53c8xx_info(struct Scsi_Host *host);
84 
85 int sym53c8xx_queue_command(Scsi_Cmnd *, void (*done)(Scsi_Cmnd *));
86 
87 int sym53c8xx_eh_abort_handler(Scsi_Cmnd *);
88 int sym53c8xx_eh_device_reset_handler(Scsi_Cmnd *);
89 int sym53c8xx_eh_bus_reset_handler(Scsi_Cmnd *);
90 int sym53c8xx_eh_host_reset_handler(Scsi_Cmnd *);
91 
92 #ifdef MODULE
93 int sym53c8xx_release(struct Scsi_Host *);
94 #else
95 #define sym53c8xx_release NULL
96 #endif
97 
98 
99 /*
100  *  Host template defintion
101  */
102 #if (LINUX_VERSION_CODE >= 0x020400) || defined(HOSTS_C) || defined(MODULE)
103 
104 #include <scsi/scsicam.h>
105 
106 #define SYM53C8XX {							\
107 	name:			"sym53c8xx",				\
108 	detect:			sym53c8xx_detect,			\
109 	release:		sym53c8xx_release,			\
110 	info:			sym53c8xx_info, 			\
111 	queuecommand:		sym53c8xx_queue_command,		\
112 	use_new_eh_code:	1,					\
113 	eh_abort_handler:	sym53c8xx_eh_abort_handler,		\
114 	eh_device_reset_handler:sym53c8xx_eh_device_reset_handler,	\
115 	eh_bus_reset_handler:	sym53c8xx_eh_bus_reset_handler,		\
116 	eh_host_reset_handler:	sym53c8xx_eh_host_reset_handler,	\
117 	bios_param:		scsicam_bios_param,			\
118 	can_queue:		0,					\
119 	this_id:		7,					\
120 	sg_tablesize:		0,					\
121 	cmd_per_lun:		0,					\
122 	use_clustering:		DISABLE_CLUSTERING,			\
123 	highmem_io:		1}
124 
125 #endif /* defined(HOSTS_C) || defined(MODULE) */
126 
127 /*
128  *  Translate kernel configuration parameters
129  *  into corresponding driver parameters.
130  */
131 #if !defined(HOSTS_C)
132 
133 /*
134  *  Use normal IO if configured.
135  *  Normal IO forced for alpha.
136  *  Forced to MMIO for sparc.
137  */
138 #if defined(__alpha__)
139 #define	SYM_CONF_IOMAPPED
140 #elif defined(__sparc__)
141 #undef SYM_CONF_IOMAPPED
142 /* #elif defined(__powerpc__) */
143 /* #define	SYM_CONF_IOMAPPED */
144 /* #define SYM_OPT_NO_BUS_MEMORY_MAPPING */
145 #elif defined(CONFIG_SCSI_SYM53C8XX_IOMAPPED)
146 #define	SYM_CONF_IOMAPPED
147 #endif
148 
149 /*
150  *  DMA addressing mode.
151  *
152  *  0 : 32 bit addressing for all chips.
153  *  1 : 40 bit addressing when supported by chip.
154  *  2 : 64 bit addressing when supported by chip,
155  *      limited to 16 segments of 4 GB -> 64 GB max.
156  */
157 #ifdef	CONFIG_SCSI_SYM53C8XX_DMA_ADDRESSING_MODE
158 #define	SYM_CONF_DMA_ADDRESSING_MODE CONFIG_SCSI_SYM53C8XX_DMA_ADDRESSING_MODE
159 #endif
160 
161 /*
162  *  NCR PQS/PDS special device support.
163  */
164 #if 1
165 #define SYM_CONF_PQS_PDS_SUPPORT
166 #endif
167 
168 /*
169  *  NVRAM support.
170  */
171 #if 1
172 #define SYM_CONF_NVRAM_SUPPORT		(1)
173 #define SYM_SETUP_SYMBIOS_NVRAM		(1)
174 #define SYM_SETUP_TEKRAM_NVRAM		(1)
175 #endif
176 
177 /*
178  *  These options are not tunable from 'make config'
179  */
180 #if 1
181 #define	SYM_LINUX_PROC_INFO_SUPPORT
182 #define SYM_LINUX_BOOT_COMMAND_LINE_SUPPORT
183 #define SYM_LINUX_USER_COMMAND_SUPPORT
184 #define SYM_LINUX_USER_INFO_SUPPORT
185 #define SYM_LINUX_DEBUG_CONTROL_SUPPORT
186 #endif
187 
188 /*
189  *  Also handle old NCR chips if not (0).
190  */
191 #define SYM_CONF_GENERIC_SUPPORT	(1)
192 
193 /*
194  *  Allow tags from 2 to 256, default 8
195  */
196 #ifndef CONFIG_SCSI_SYM53C8XX_MAX_TAGS
197 #define CONFIG_SCSI_SYM53C8XX_MAX_TAGS	(8)
198 #endif
199 
200 #if	CONFIG_SCSI_SYM53C8XX_MAX_TAGS < 2
201 #define SYM_CONF_MAX_TAG	(2)
202 #elif	CONFIG_SCSI_SYM53C8XX_MAX_TAGS > 256
203 #define SYM_CONF_MAX_TAG	(256)
204 #else
205 #define	SYM_CONF_MAX_TAG	CONFIG_SCSI_SYM53C8XX_MAX_TAGS
206 #endif
207 
208 #ifndef	CONFIG_SCSI_SYM53C8XX_DEFAULT_TAGS
209 #define	CONFIG_SCSI_SYM53C8XX_DEFAULT_TAGS	SYM_CONF_MAX_TAG
210 #endif
211 
212 /*
213  *  Anyway, we configure the driver for at least 64 tags per LUN. :)
214  */
215 #if	SYM_CONF_MAX_TAG <= 64
216 #define SYM_CONF_MAX_TAG_ORDER	(6)
217 #elif	SYM_CONF_MAX_TAG <= 128
218 #define SYM_CONF_MAX_TAG_ORDER	(7)
219 #else
220 #define SYM_CONF_MAX_TAG_ORDER	(8)
221 #endif
222 
223 /*
224  *  Sync transfer frequency at startup.
225  *  Allow up to ULTRA-160. The driver will scale the value
226  *  according to controller capabilities.
227  */
228 #define	CONFIG_SCSI_SYM53C8XX_DEFAULT_SYNC (9)
229 
230 /*
231  *  Max number of SG entries.
232  */
233 #define SYM_CONF_MAX_SG		(96)
234 
235 /*
236  *  Max number of LUNs per target.
237  */
238 #if 1 /* defined CONFIG_SCSI_MULTI_LUN */
239 #define	CONFIG_SCSI_SYM53C8XX_MAX_LUN	(16)
240 #else
241 #define	CONFIG_SCSI_SYM53C8XX_MAX_LUN	(1)
242 #endif
243 
244 /*
245  *  Driver setup structure.
246  *
247  *  This structure is initialized from linux config options.
248  *  It can be overridden at boot-up by the boot command line.
249  */
250 struct sym_driver_setup {
251 	u_char	pci_parity;
252 	u_char	scsi_parity;
253 	u_short	max_tag;
254 	u_char	min_sync;
255 	u_char	burst_order;
256 	u_char	scsi_led;
257 	u_char	max_wide;
258 	u_char	scsi_diff;
259 	u_char	irq_mode;
260 	u_char	scsi_bus_check;
261 	u_char	host_id;
262 	u_char	max_offs;
263 	u_char	max_lun;
264 	u_char	pci_fix_up;
265 
266 	u_char	reverse_probe;
267 	u_char	verbose;
268 	u_short	debug;
269 	u_char	settle_delay;
270 	u_char	use_nvram;
271 	u_long	excludes[8];
272 	char	tag_ctrl[100];
273 };
274 
275 #define SYM_SETUP_PCI_PARITY		sym_driver_setup.pci_parity
276 #define SYM_SETUP_SCSI_PARITY		sym_driver_setup.scsi_parity
277 #define SYM_SETUP_MAX_TAG		sym_driver_setup.max_tag
278 #define SYM_SETUP_MIN_SYNC		sym_driver_setup.min_sync
279 #define SYM_SETUP_BURST_ORDER		sym_driver_setup.burst_order
280 #define SYM_SETUP_SCSI_LED		sym_driver_setup.scsi_led
281 #define SYM_SETUP_MAX_WIDE		sym_driver_setup.max_wide
282 #define SYM_SETUP_SCSI_DIFF		sym_driver_setup.scsi_diff
283 #define SYM_SETUP_IRQ_MODE		sym_driver_setup.irq_mode
284 #define SYM_SETUP_SCSI_BUS_CHECK	sym_driver_setup.scsi_bus_check
285 #define SYM_SETUP_HOST_ID		sym_driver_setup.host_id
286 #define SYM_SETUP_MAX_OFFS		sym_driver_setup.max_offs
287 #define SYM_SETUP_MAX_LUN		sym_driver_setup.max_lun
288 #define SYM_SETUP_PCI_FIX_UP		sym_driver_setup.pci_fix_up
289 
290 /*
291  *  Initial setup.
292  *
293  *  Can be overriden at startup by a command line.
294  */
295 #define SYM_LINUX_DRIVER_SETUP			\
296 {						\
297 	1,	/* pci_parity */		\
298 	1,	/* scsi_parity */		\
299 	CONFIG_SCSI_SYM53C8XX_DEFAULT_TAGS,	\
300 	CONFIG_SCSI_SYM53C8XX_DEFAULT_SYNC,	\
301 	7,	/* burst_order */		\
302 	1,	/* scsi_led */			\
303 	1,	/* max_wide */			\
304 	1,	/* scsi_diff */			\
305 	0,	/* irq_mode */			\
306 	1,	/* scsi_bus_check */		\
307 	7,	/* host_id */			\
308 	62,	/* max_offs */			\
309 	CONFIG_SCSI_SYM53C8XX_MAX_LUN,		\
310 	3,	/* pci_fix_up */		\
311 	0,	/* reverse_probe */		\
312 	0,	/* verbose */			\
313 	0,	/* debug */			\
314 	3,	/* settle_delay */		\
315 	1,	/* use_nvram */			\
316 }
317 
318 /*
319  *  Boot fail safe setup.
320  *
321  *  Override initial setup from boot command line:
322  *    sym53c8xx=safe:y
323  */
324 #define SYM_LINUX_DRIVER_SAFE_SETUP		\
325 {						\
326 	0,	/* pci_parity */		\
327 	0,	/* scsi_parity */		\
328 	0,	/* max_tag */			\
329 	50,	/* min_sync */			\
330 	0,	/* burst_order */		\
331 	0,	/* scsi_led */			\
332 	1,	/* max_wide */			\
333 	1,	/* scsi_diff */			\
334 	0,	/* irq_mode */			\
335 	2,	/* scsi_bus_check */		\
336 	7,	/* host_id */			\
337 	15,	/* max_offs */			\
338 	1,	/* max_lun */			\
339 	0,	/* pci_fix_up */		\
340 	0,	/* reverse_probe */		\
341 	2,	/* verbose */			\
342 	0,	/* debug */			\
343 	10,	/* settle_delay */		\
344 	1,	/* use_nvram */			\
345 }
346 
347 /*
348  *  This structure is initialized from linux config options.
349  *  It can be overridden at boot-up by the boot command line.
350  */
351 #ifdef SYM_GLUE_C
352 struct sym_driver_setup
353 	sym_driver_setup = SYM_LINUX_DRIVER_SETUP;
354 #ifdef SYM_LINUX_DEBUG_CONTROL_SUPPORT
355 u_int	sym_debug_flags = 0;
356 #endif
357 #else
358 extern struct sym_driver_setup sym_driver_setup;
359 #ifdef SYM_LINUX_DEBUG_CONTROL_SUPPORT
360 extern u_int sym_debug_flags;
361 #endif
362 #endif /* SYM_GLUE_C */
363 
364 #ifdef SYM_LINUX_DEBUG_CONTROL_SUPPORT
365 #define DEBUG_FLAGS	sym_debug_flags
366 #endif
367 #define boot_verbose	sym_driver_setup.verbose
368 
369 #endif /* !defined(HOSTS_C) */
370 
371 #endif /* SYM53C8XX_H */
372