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	SYM_FW_H
54 #define	SYM_FW_H
55 /*
56  *  Macro used to generate interfaces for script A.
57  */
58 #define SYM_GEN_FW_A(s)							\
59 	SYM_GEN_A(s, start)		SYM_GEN_A(s, getjob_begin)	\
60 	SYM_GEN_A(s, getjob_end)					\
61 	SYM_GEN_A(s, select)		SYM_GEN_A(s, wf_sel_done)	\
62 	SYM_GEN_A(s, send_ident)					\
63 	SYM_GEN_A(s, dispatch)		SYM_GEN_A(s, init)		\
64 	SYM_GEN_A(s, clrack)		SYM_GEN_A(s, complete_error)	\
65 	SYM_GEN_A(s, done)		SYM_GEN_A(s, done_end)		\
66 	SYM_GEN_A(s, idle)		SYM_GEN_A(s, ungetjob)		\
67 	SYM_GEN_A(s, reselect)						\
68 	SYM_GEN_A(s, resel_tag)		SYM_GEN_A(s, resel_dsa)		\
69 	SYM_GEN_A(s, resel_no_tag)					\
70 	SYM_GEN_A(s, data_in)		SYM_GEN_A(s, data_in2)		\
71 	SYM_GEN_A(s, data_out)		SYM_GEN_A(s, data_out2)		\
72 	SYM_GEN_A(s, pm0_data)		SYM_GEN_A(s, pm1_data)
73 
74 /*
75  *  Macro used to generate interfaces for script B.
76  */
77 #define SYM_GEN_FW_B(s)							\
78 	SYM_GEN_B(s, no_data)						\
79 	SYM_GEN_B(s, sel_for_abort)	SYM_GEN_B(s, sel_for_abort_1)	\
80 	SYM_GEN_B(s, msg_bad)		SYM_GEN_B(s, msg_weird)		\
81 	SYM_GEN_B(s, wdtr_resp)		SYM_GEN_B(s, send_wdtr)		\
82 	SYM_GEN_B(s, sdtr_resp)		SYM_GEN_B(s, send_sdtr)		\
83 	SYM_GEN_B(s, ppr_resp)		SYM_GEN_B(s, send_ppr)		\
84 	SYM_GEN_B(s, nego_bad_phase)					\
85 	SYM_GEN_B(s, ident_break) 	SYM_GEN_B(s, ident_break_atn)	\
86 	SYM_GEN_B(s, sdata_in)		SYM_GEN_B(s, resel_bad_lun)	\
87 	SYM_GEN_B(s, bad_i_t_l)		SYM_GEN_B(s, bad_i_t_l_q)	\
88 	SYM_GEN_B(s, wsr_ma_helper)
89 
90 /*
91  *  Macro used to generate interfaces for script Z.
92  */
93 #define SYM_GEN_FW_Z(s)							\
94 	SYM_GEN_Z(s, snooptest)		SYM_GEN_Z(s, snoopend)
95 
96 /*
97  *  Generates structure interface that contains
98  *  offsets within script A, B and Z.
99  */
100 #define	SYM_GEN_A(s, label)	s label;
101 #define	SYM_GEN_B(s, label)	s label;
102 #define	SYM_GEN_Z(s, label)	s label;
103 struct sym_fwa_ofs {
104 	SYM_GEN_FW_A(u_short)
105 };
106 struct sym_fwb_ofs {
107 	SYM_GEN_FW_B(u_short)
108 #ifdef SYM_OPT_HANDLE_DIR_UNKNOWN
109 	SYM_GEN_B(u_short, data_io)
110 #endif
111 	SYM_GEN_B(u_short, start64)
112 	SYM_GEN_B(u_short, pm_handle)
113 };
114 struct sym_fwz_ofs {
115 	SYM_GEN_FW_Z(u_short)
116 #ifdef SYM_OPT_NO_BUS_MEMORY_MAPPING
117 	SYM_GEN_Z(u_short, start_ram)
118 	SYM_GEN_Z(u_short, start_ram64)
119 #endif
120 };
121 
122 /*
123  *  Generates structure interface that contains
124  *  bus addresses within script A, B and Z.
125  */
126 struct sym_fwa_ba {
127 	SYM_GEN_FW_A(u32)
128 };
129 struct sym_fwb_ba {
130 	SYM_GEN_FW_B(u32)
131 #ifdef SYM_OPT_HANDLE_DIR_UNKNOWN
132 	SYM_GEN_B(u32, data_io)
133 #endif
134 	SYM_GEN_B(u32, start64);
135 	SYM_GEN_B(u32, pm_handle);
136 };
137 struct sym_fwz_ba {
138 	SYM_GEN_FW_Z(u32)
139 #ifdef SYM_OPT_NO_BUS_MEMORY_MAPPING
140 	SYM_GEN_Z(u32, start_ram)
141 	SYM_GEN_Z(u32, start_ram64)
142 #endif
143 };
144 #undef	SYM_GEN_A
145 #undef	SYM_GEN_B
146 #undef	SYM_GEN_Z
147 
148 /*
149  *  Let cc know about the name of the controller data structure.
150  *  We need this for function prototype declarations just below.
151  */
152 struct sym_hcb;
153 
154 /*
155  *  Generic structure that defines a firmware.
156  */
157 struct sym_fw {
158 	char	*name;		/* Name we want to print out	*/
159 	u32	*a_base;	/* Pointer to script A template	*/
160 	int	a_size;		/* Size of script A		*/
161 	struct	sym_fwa_ofs
162 		*a_ofs;		/* Useful offsets in script A	*/
163 	u32	*b_base;	/* Pointer to script B template	*/
164 	int	b_size;		/* Size of script B		*/
165 	struct	sym_fwb_ofs
166 		*b_ofs;		/* Useful offsets in script B	*/
167 	u32	*z_base;	/* Pointer to script Z template	*/
168 	int	z_size;		/* Size of script Z		*/
169 	struct	sym_fwz_ofs
170 		*z_ofs;		/* Useful offsets in script Z	*/
171 	/* Setup and patch methods for this firmware */
172 	void	(*setup)(struct sym_hcb *, struct sym_fw *);
173 	void	(*patch)(struct sym_hcb *);
174 };
175 
176 /*
177  *  Macro used to declare a firmware.
178  */
179 #define SYM_FW_ENTRY(fw, name)					\
180 {								\
181 	name,							\
182 	(u32 *) &fw##a_scr, sizeof(fw##a_scr), &fw##a_ofs,	\
183 	(u32 *) &fw##b_scr, sizeof(fw##b_scr), &fw##b_ofs,	\
184 	(u32 *) &fw##z_scr, sizeof(fw##z_scr), &fw##z_ofs,	\
185 	fw##_setup, fw##_patch					\
186 }
187 
188 /*
189  *  Macros used from the C code to get useful
190  *  SCRIPTS bus addresses.
191  */
192 #define SCRIPTA_BA(np, label)	(np->fwa_bas.label)
193 #define SCRIPTB_BA(np, label)	(np->fwb_bas.label)
194 #define SCRIPTZ_BA(np, label)	(np->fwz_bas.label)
195 
196 /*
197  *  Macros used by scripts definitions.
198  *
199  *  HADDR_1 generates a reference to a field of the controller data.
200  *  HADDR_2 generates a reference to a field of the controller data
201  *          with offset.
202  *  RADDR_1 generates a reference to a script processor register.
203  *  RADDR_2 generates a reference to a script processor register
204  *          with offset.
205  *  PADDR_A generates a reference to another part of script A.
206  *  PADDR_B generates a reference to another part of script B.
207  *
208  *  SYM_GEN_PADDR_A and SYM_GEN_PADDR_B are used to define respectively
209  *  the PADDR_A and PADDR_B macros for each firmware by setting argument
210  *  `s' to the name of the corresponding structure.
211  *
212  *  SCR_DATA_ZERO is used to allocate a DWORD of data in scripts areas.
213  */
214 
215 #define	RELOC_SOFTC	0x40000000
216 #define	RELOC_LABEL_A	0x50000000
217 #define	RELOC_REGISTER	0x60000000
218 #define	RELOC_LABEL_B	0x80000000
219 #define	RELOC_MASK	0xf0000000
220 
221 #define	HADDR_1(label)	   (RELOC_SOFTC    | offsetof(struct sym_hcb, label))
222 #define	HADDR_2(label,ofs) (RELOC_SOFTC    | \
223 				(offsetof(struct sym_hcb, label)+(ofs)))
224 #define	RADDR_1(label)	   (RELOC_REGISTER | REG(label))
225 #define	RADDR_2(label,ofs) (RELOC_REGISTER | ((REG(label))+(ofs)))
226 
227 #define SYM_GEN_PADDR_A(s, label) (RELOC_LABEL_A  | offsetof(s, label))
228 #define SYM_GEN_PADDR_B(s, label) (RELOC_LABEL_B  | offsetof(s, label))
229 
230 #define SCR_DATA_ZERO	0xf00ff00f
231 
232 #endif	/* SYM_FW_H */
233