xref: /freebsd/sys/dev/sym/sym_fw.h (revision 71625ec9ad2a9bc8c09784fbd23b759830e0ee5f)
1 /*-
2  * SPDX-License-Identifier: BSD-3-Clause
3  *
4  *  Device driver optimized for the Symbios/LSI 53C896/53C895A/53C1010
5  *  PCI-SCSI controllers.
6  *
7  *  Copyright (C) 1999-2001  Gerard Roudier <groudier@free.fr>
8  *
9  *  This driver also supports the following Symbios/LSI PCI-SCSI chips:
10  *	53C810A, 53C825A, 53C860, 53C875, 53C876, 53C885, 53C895,
11  *	53C810,  53C815,  53C825 and the 53C1510D is 53C8XX mode.
12  *
13  *
14  *  This driver for FreeBSD-CAM is derived from the Linux sym53c8xx driver.
15  *  Copyright (C) 1998-1999  Gerard Roudier
16  *
17  *  The sym53c8xx driver is derived from the ncr53c8xx driver that had been
18  *  a port of the FreeBSD ncr driver to Linux-1.2.13.
19  *
20  *  The original ncr driver has been written for 386bsd and FreeBSD by
21  *          Wolfgang Stanglmeier        <wolf@cologne.de>
22  *          Stefan Esser                <se@mi.Uni-Koeln.de>
23  *  Copyright (C) 1994  Wolfgang Stanglmeier
24  *
25  *  The initialisation code, and part of the code that addresses
26  *  FreeBSD-CAM services is based on the aic7xxx driver for FreeBSD-CAM
27  *  written by Justin T. Gibbs.
28  *
29  *  Other major contributions:
30  *
31  *  NVRAM detection and reading.
32  *  Copyright (C) 1997 Richard Waltham <dormouse@farsrobt.demon.co.uk>
33  *
34  *-----------------------------------------------------------------------------
35  *
36  * Redistribution and use in source and binary forms, with or without
37  * modification, are permitted provided that the following conditions
38  * are met:
39  * 1. Redistributions of source code must retain the above copyright
40  *    notice, this list of conditions and the following disclaimer.
41  * 2. Redistributions in binary form must reproduce the above copyright
42  *    notice, this list of conditions and the following disclaimer in the
43  *    documentation and/or other materials provided with the distribution.
44  * 3. The name of the author may not be used to endorse or promote products
45  *    derived from this software without specific prior written permission.
46  *
47  * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
48  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
49  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
50  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
51  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
52  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
53  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
54  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
55  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
56  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
57  * SUCH DAMAGE.
58  */
59 
60 
61 #ifndef	SYM_FW_H
62 #define	SYM_FW_H
63 /*
64  *  Macro used to generate interfaces for script A.
65  */
66 #define SYM_GEN_FW_A(s)							\
67 	SYM_GEN_A(s, start)		SYM_GEN_A(s, getjob_begin)	\
68 	SYM_GEN_A(s, getjob_end)					\
69 	SYM_GEN_A(s, select)		SYM_GEN_A(s, wf_sel_done)	\
70 	SYM_GEN_A(s, send_ident)					\
71 	SYM_GEN_A(s, dispatch)		SYM_GEN_A(s, init)		\
72 	SYM_GEN_A(s, clrack)		SYM_GEN_A(s, complete_error)	\
73 	SYM_GEN_A(s, done)		SYM_GEN_A(s, done_end)		\
74 	SYM_GEN_A(s, idle)		SYM_GEN_A(s, ungetjob)		\
75 	SYM_GEN_A(s, reselect)						\
76 	SYM_GEN_A(s, resel_tag)		SYM_GEN_A(s, resel_dsa)		\
77 	SYM_GEN_A(s, resel_no_tag)					\
78 	SYM_GEN_A(s, data_in)		SYM_GEN_A(s, data_in2)		\
79 	SYM_GEN_A(s, data_out)		SYM_GEN_A(s, data_out2)		\
80 	SYM_GEN_A(s, pm0_data)		SYM_GEN_A(s, pm1_data)
81 
82 /*
83  *  Macro used to generate interfaces for script B.
84  */
85 #define SYM_GEN_FW_B(s)							\
86 	SYM_GEN_B(s, no_data)						\
87 	SYM_GEN_B(s, sel_for_abort)	SYM_GEN_B(s, sel_for_abort_1)	\
88 	SYM_GEN_B(s, msg_bad)		SYM_GEN_B(s, msg_weird)		\
89 	SYM_GEN_B(s, wdtr_resp)		SYM_GEN_B(s, send_wdtr)		\
90 	SYM_GEN_B(s, sdtr_resp)		SYM_GEN_B(s, send_sdtr)		\
91 	SYM_GEN_B(s, ppr_resp)		SYM_GEN_B(s, send_ppr)		\
92 	SYM_GEN_B(s, nego_bad_phase)					\
93 	SYM_GEN_B(s, ident_break) 	SYM_GEN_B(s, ident_break_atn)	\
94 	SYM_GEN_B(s, sdata_in)		SYM_GEN_B(s, resel_bad_lun)	\
95 	SYM_GEN_B(s, bad_i_t_l)		SYM_GEN_B(s, bad_i_t_l_q)	\
96 	SYM_GEN_B(s, wsr_ma_helper)					\
97 	SYM_GEN_B(s, snooptest)		SYM_GEN_B(s, snoopend)
98 
99 /*
100  *  Generates structure interface that contains
101  *  offsets within script A and script B.
102  */
103 #define	SYM_GEN_A(s, label)	s label;
104 #define	SYM_GEN_B(s, label)	s label;
105 struct sym_fwa_ofs {
106 	SYM_GEN_FW_A(u_short)
107 };
108 struct sym_fwb_ofs {
109 	SYM_GEN_FW_B(u_short)
110 	SYM_GEN_B(u_short, start64)
111 	SYM_GEN_B(u_short, pm_handle)
112 };
113 
114 /*
115  *  Generates structure interface that contains
116  *  bus addresses within script A and script B.
117  */
118 struct sym_fwa_ba {
119 	SYM_GEN_FW_A(u32)
120 };
121 struct sym_fwb_ba {
122 	SYM_GEN_FW_B(u32)
123 	SYM_GEN_B(u32, start64)
124 	SYM_GEN_B(u32, pm_handle)
125 };
126 #undef	SYM_GEN_A
127 #undef	SYM_GEN_B
128 
129 /*
130  *  Let cc know about the name of the controller data structure.
131  *  We need this for function prototype declarations just below.
132  */
133 struct sym_hcb;
134 
135 /*
136  *  Generic structure that defines a firmware.
137  */
138 struct sym_fw {
139 	const char	*name;	/* Name we want to print out	*/
140 	const u32	*a_base;/* Pointer to script A template	*/
141 	int	a_size;		/* Size of script A		*/
142 	const struct	sym_fwa_ofs
143 		*a_ofs;		/* Useful offsets in script A	*/
144 	const u32	*b_base;/* Pointer to script B template	*/
145 	int	b_size;		/* Size of script B		*/
146 	const struct	sym_fwb_ofs
147 		*b_ofs;		/* Useful offsets in script B	*/
148 	/* Setup and patch methods for this firmware */
149 	void	(*setup)(struct sym_hcb *, const struct sym_fw *);
150 	void	(*patch)(struct sym_hcb *);
151 };
152 
153 /*
154  *  Macro used to declare a firmware.
155  */
156 #define SYM_FW_ENTRY(fw, name)					\
157 {								\
158 	name,							\
159 	(const u32 *) &fw##a_scr, sizeof(fw##a_scr), &fw##a_ofs,\
160 	(const u32 *) &fw##b_scr, sizeof(fw##b_scr), &fw##b_ofs,\
161 	fw##_setup, fw##_patch					\
162 }
163 
164 /*
165  *  Macros used from the C code to get useful
166  *  SCRIPTS bus addresses.
167  */
168 #define SCRIPTA_BA(np, label)	(np->fwa_bas.label)
169 #define SCRIPTB_BA(np, label)	(np->fwb_bas.label)
170 #define SCRIPTB0_BA(np,label)	\
171 	(np->scriptb0_ba + (np->fwb_bas.label - np->scriptb_ba))
172 
173 /*
174  *  Macros used by scripts definitions.
175  *
176  *  HADDR_1 generates a reference to a field of the controller data.
177  *  HADDR_2 generates a reference to a field of the controller data
178  *          with offset.
179  *  RADDR_1 generates a reference to a script processor register.
180  *  RADDR_2 generates a reference to a script processor register
181  *          with offset.
182  *  PADDR_A generates a reference to another part of script A.
183  *  PADDR_B generates a reference to another part of script B.
184  *
185  *  SYM_GEN_PADDR_A and SYM_GEN_PADDR_B are used to define respectively
186  *  the PADDR_A and PADDR_B macros for each firmware by setting argument
187  *  `s' to the name of the corresponding structure.
188  *
189  *  SCR_DATA_ZERO is used to allocate a DWORD of data in scripts areas.
190  */
191 
192 #define	RELOC_SOFTC	0x40000000
193 #define	RELOC_LABEL_A	0x50000000
194 #define	RELOC_REGISTER	0x60000000
195 #define	RELOC_LABEL_B	0x80000000
196 #define	RELOC_MASK	0xf0000000
197 
198 #define	HADDR_1(label)	   (RELOC_SOFTC    | offsetof(struct sym_hcb, label))
199 #define	HADDR_2(label,ofs) (RELOC_SOFTC    | \
200 				(offsetof(struct sym_hcb, label)+(ofs)))
201 #define	RADDR_1(label)	   (RELOC_REGISTER | REG(label))
202 #define	RADDR_2(label,ofs) (RELOC_REGISTER | ((REG(label))+(ofs)))
203 
204 #define SYM_GEN_PADDR_A(s, label) (RELOC_LABEL_A  | offsetof(s, label))
205 #define SYM_GEN_PADDR_B(s, label) (RELOC_LABEL_B  | offsetof(s, label))
206 
207 #define SCR_DATA_ZERO	0xf00ff00f
208 
209 #endif	/* SYM_FW_H */
210