xref: /freebsd/sys/dev/sfxge/common/efx_mcdi.h (revision e8e8c939350bdf3c228a411caa9660c607c27a11)
1 /*-
2  * Copyright (c) 2009-2015 Solarflare Communications Inc.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright notice,
9  *    this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright notice,
11  *    this list of conditions and the following disclaimer in the documentation
12  *    and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
16  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
18  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
21  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
22  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
24  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25  *
26  * The views and conclusions contained in the software and documentation are
27  * those of the authors and should not be interpreted as representing official
28  * policies, either expressed or implied, of the FreeBSD Project.
29  *
30  * $FreeBSD$
31  */
32 
33 #ifndef _SYS_EFX_MCDI_H
34 #define	_SYS_EFX_MCDI_H
35 
36 #include "efx.h"
37 #include "efx_regs.h"
38 #include "efx_regs_mcdi.h"
39 
40 #ifdef	__cplusplus
41 extern "C" {
42 #endif
43 
44 /*
45  * A reboot/assertion causes the MCDI status word to be set after the
46  * command word is set or a REBOOT event is sent. If we notice a reboot
47  * via these mechanisms then wait 10ms for the status word to be set.
48  */
49 #define	EFX_MCDI_STATUS_SLEEP_US	10000
50 
51 struct efx_mcdi_req_s {
52 	boolean_t	emr_quiet;
53 	/* Inputs: Command #, input buffer and length */
54 	unsigned int	emr_cmd;
55 	uint8_t		*emr_in_buf;
56 	size_t		emr_in_length;
57 	/* Outputs: retcode, buffer, length, and length used*/
58 	int		emr_rc;
59 	uint8_t		*emr_out_buf;
60 	size_t		emr_out_length;
61 	size_t		emr_out_length_used;
62 };
63 
64 typedef struct efx_mcdi_iface_s {
65 	unsigned int		emi_port;
66 	unsigned int		emi_seq;
67 	efx_mcdi_req_t		*emi_pending_req;
68 	boolean_t		emi_ev_cpl;
69 	boolean_t		emi_new_epoch;
70 	int			emi_aborted;
71 	uint32_t		emi_poll_cnt;
72 	uint32_t		emi_mc_reboot_status;
73 } efx_mcdi_iface_t;
74 
75 extern			void
76 efx_mcdi_execute(
77 	__in		efx_nic_t *enp,
78 	__inout		efx_mcdi_req_t *emrp);
79 
80 extern			void
81 efx_mcdi_execute_quiet(
82 	__in		efx_nic_t *enp,
83 	__inout		efx_mcdi_req_t *emrp);
84 
85 extern			void
86 efx_mcdi_ev_cpl(
87 	__in		efx_nic_t *enp,
88 	__in		unsigned int seq,
89 	__in		unsigned int outlen,
90 	__in		int errcode);
91 
92 extern			void
93 efx_mcdi_ev_death(
94 	__in		efx_nic_t *enp,
95 	__in		int rc);
96 
97 extern	__checkReturn	int
98 efx_mcdi_request_errcode(
99 	__in		unsigned int err);
100 
101 extern			void
102 efx_mcdi_raise_exception(
103 	__in		efx_nic_t *enp,
104 	__in_opt	efx_mcdi_req_t *emrp,
105 	__in		int rc);
106 
107 typedef enum efx_mcdi_boot_e {
108 	EFX_MCDI_BOOT_PRIMARY,
109 	EFX_MCDI_BOOT_SECONDARY,
110 	EFX_MCDI_BOOT_ROM,
111 } efx_mcdi_boot_t;
112 
113 extern	__checkReturn		int
114 efx_mcdi_version(
115 	__in			efx_nic_t *enp,
116 	__out_ecount_opt(4)	uint16_t versionp[4],
117 	__out_opt		uint32_t *buildp,
118 	__out_opt		efx_mcdi_boot_t *statusp);
119 
120 extern	__checkReturn		int
121 efx_mcdi_read_assertion(
122 	__in			efx_nic_t *enp);
123 
124 extern	__checkReturn		int
125 efx_mcdi_exit_assertion_handler(
126 	__in			efx_nic_t *enp);
127 
128 extern	__checkReturn		int
129 efx_mcdi_drv_attach(
130 	__in			efx_nic_t *enp,
131 	__in			boolean_t attach);
132 
133 extern	__checkReturn		int
134 efx_mcdi_get_board_cfg(
135 	__in			efx_nic_t *enp,
136 	__out_opt		uint32_t *board_typep,
137 	__out_opt		efx_dword_t *capabilitiesp,
138 	__out_ecount_opt(6)	uint8_t mac_addrp[6]);
139 
140 extern	__checkReturn		int
141 efx_mcdi_get_phy_cfg(
142 	__in			efx_nic_t *enp);
143 
144 extern	__checkReturn		int
145 efx_mcdi_firmware_update_supported(
146 	__in			efx_nic_t *enp,
147 	__out			boolean_t *supportedp);
148 
149 extern	__checkReturn		int
150 efx_mcdi_macaddr_change_supported(
151 	__in			efx_nic_t *enp,
152 	__out			boolean_t *supportedp);
153 
154 #if EFSYS_OPT_BIST
155 #if EFSYS_OPT_HUNTINGTON
156 extern	__checkReturn		int
157 efx_mcdi_bist_enable_offline(
158 	__in			efx_nic_t *enp);
159 #endif /* EFSYS_OPT_HUNTINGTON */
160 extern	__checkReturn		int
161 efx_mcdi_bist_start(
162 	__in			efx_nic_t *enp,
163 	__in			efx_bist_type_t type);
164 #endif /* EFSYS_OPT_BIST */
165 
166 extern	__checkReturn		int
167 efx_mcdi_get_resource_limits(
168 	__in			efx_nic_t *enp,
169 	__out_opt		uint32_t *nevqp,
170 	__out_opt		uint32_t *nrxqp,
171 	__out_opt		uint32_t *ntxqp);
172 
173 extern	__checkReturn	int
174 efx_mcdi_log_ctrl(
175 	__in		efx_nic_t *enp);
176 
177 extern	__checkReturn	int
178 efx_mcdi_mac_stats_clear(
179 	__in		efx_nic_t *enp);
180 
181 extern	__checkReturn	int
182 efx_mcdi_mac_stats_upload(
183 	__in		efx_nic_t *enp,
184 	__in		efsys_mem_t *esmp);
185 
186 extern	__checkReturn	int
187 efx_mcdi_mac_stats_periodic(
188 	__in		efx_nic_t *enp,
189 	__in		efsys_mem_t *esmp,
190 	__in		uint16_t period,
191 	__in		boolean_t events);
192 
193 
194 #if EFSYS_OPT_LOOPBACK
195 extern	__checkReturn	int
196 efx_mcdi_get_loopback_modes(
197 	__in		efx_nic_t *enp);
198 #endif /* EFSYS_OPT_LOOPBACK */
199 
200 #define	MCDI_IN(_emr, _type, _ofst)					\
201 	((_type *)((_emr).emr_in_buf + (_ofst)))
202 
203 #define	MCDI_IN2(_emr, _type, _ofst)					\
204 	MCDI_IN(_emr, _type, MC_CMD_ ## _ofst ## _OFST)
205 
206 #define	MCDI_IN_SET_BYTE(_emr, _ofst, _value)				\
207 	EFX_POPULATE_BYTE_1(*MCDI_IN2(_emr, efx_byte_t, _ofst),		\
208 		EFX_BYTE_0, _value)
209 
210 #define	MCDI_IN_SET_WORD(_emr, _ofst, _value)				\
211 	EFX_POPULATE_WORD_1(*MCDI_IN2(_emr, efx_word_t, _ofst),		\
212 		EFX_WORD_0, _value)
213 
214 #define	MCDI_IN_SET_DWORD(_emr, _ofst, _value)				\
215 	EFX_POPULATE_DWORD_1(*MCDI_IN2(_emr, efx_dword_t, _ofst),	\
216 		EFX_DWORD_0, _value)
217 
218 #define	MCDI_IN_SET_DWORD_FIELD(_emr, _ofst, _field, _value)		\
219 	EFX_SET_DWORD_FIELD(*MCDI_IN2(_emr, efx_dword_t, _ofst),	\
220 		MC_CMD_ ## _field, _value)
221 
222 #define	MCDI_IN_POPULATE_DWORD_1(_emr, _ofst, _field1, _value1)		\
223 	EFX_POPULATE_DWORD_1(*MCDI_IN2(_emr, efx_dword_t, _ofst),	\
224 		MC_CMD_ ## _field1, _value1)
225 
226 #define	MCDI_IN_POPULATE_DWORD_2(_emr, _ofst, _field1, _value1,		\
227 		_field2, _value2)					\
228 	EFX_POPULATE_DWORD_2(*MCDI_IN2(_emr, efx_dword_t, _ofst),	\
229 		MC_CMD_ ## _field1, _value1,				\
230 		MC_CMD_ ## _field2, _value2)
231 
232 #define	MCDI_IN_POPULATE_DWORD_3(_emr, _ofst, _field1, _value1,		\
233 		_field2, _value2, _field3, _value3)			\
234 	EFX_POPULATE_DWORD_3(*MCDI_IN2(_emr, efx_dword_t, _ofst),	\
235 		MC_CMD_ ## _field1, _value1,				\
236 		MC_CMD_ ## _field2, _value2,				\
237 		MC_CMD_ ## _field3, _value3)
238 
239 #define	MCDI_IN_POPULATE_DWORD_4(_emr, _ofst, _field1, _value1,		\
240 		_field2, _value2, _field3, _value3, _field4, _value4)	\
241 	EFX_POPULATE_DWORD_4(*MCDI_IN2(_emr, efx_dword_t, _ofst),	\
242 		MC_CMD_ ## _field1, _value1,				\
243 		MC_CMD_ ## _field2, _value2,				\
244 		MC_CMD_ ## _field3, _value3,				\
245 		MC_CMD_ ## _field4, _value4)
246 
247 #define	MCDI_IN_POPULATE_DWORD_5(_emr, _ofst, _field1, _value1,		\
248 		_field2, _value2, _field3, _value3, _field4, _value4,	\
249 		_field5, _value5)					\
250 	EFX_POPULATE_DWORD_5(*MCDI_IN2(_emr, efx_dword_t, _ofst),	\
251 		MC_CMD_ ## _field1, _value1,				\
252 		MC_CMD_ ## _field2, _value2,				\
253 		MC_CMD_ ## _field3, _value3,				\
254 		MC_CMD_ ## _field4, _value4,				\
255 		MC_CMD_ ## _field5, _value5)
256 
257 #define	MCDI_IN_POPULATE_DWORD_6(_emr, _ofst, _field1, _value1,		\
258 		_field2, _value2, _field3, _value3, _field4, _value4,	\
259 		_field5, _value5, _field6, _value6)			\
260 	EFX_POPULATE_DWORD_6(*MCDI_IN2(_emr, efx_dword_t, _ofst),	\
261 		MC_CMD_ ## _field1, _value1,				\
262 		MC_CMD_ ## _field2, _value2,				\
263 		MC_CMD_ ## _field3, _value3,				\
264 		MC_CMD_ ## _field4, _value4,				\
265 		MC_CMD_ ## _field5, _value5,				\
266 		MC_CMD_ ## _field6, _value6)
267 
268 #define	MCDI_IN_POPULATE_DWORD_7(_emr, _ofst, _field1, _value1,		\
269 		_field2, _value2, _field3, _value3, _field4, _value4,	\
270 		_field5, _value5, _field6, _value6, _field7, _value7)	\
271 	EFX_POPULATE_DWORD_7(*MCDI_IN2(_emr, efx_dword_t, _ofst),	\
272 		MC_CMD_ ## _field1, _value1,				\
273 		MC_CMD_ ## _field2, _value2,				\
274 		MC_CMD_ ## _field3, _value3,				\
275 		MC_CMD_ ## _field4, _value4,				\
276 		MC_CMD_ ## _field5, _value5,				\
277 		MC_CMD_ ## _field6, _value6,				\
278 		MC_CMD_ ## _field7, _value7)
279 
280 #define	MCDI_IN_POPULATE_DWORD_8(_emr, _ofst, _field1, _value1,		\
281 		_field2, _value2, _field3, _value3, _field4, _value4,	\
282 		_field5, _value5, _field6, _value6, _field7, _value7,	\
283 		_field8, _value8)					\
284 	EFX_POPULATE_DWORD_8(*MCDI_IN2(_emr, efx_dword_t, _ofst),	\
285 		MC_CMD_ ## _field1, _value1,				\
286 		MC_CMD_ ## _field2, _value2,				\
287 		MC_CMD_ ## _field3, _value3,				\
288 		MC_CMD_ ## _field4, _value4,				\
289 		MC_CMD_ ## _field5, _value5,				\
290 		MC_CMD_ ## _field6, _value6,				\
291 		MC_CMD_ ## _field7, _value7,				\
292 		MC_CMD_ ## _field8, _value8)
293 
294 #define	MCDI_IN_POPULATE_DWORD_9(_emr, _ofst, _field1, _value1,		\
295 		_field2, _value2, _field3, _value3, _field4, _value4,	\
296 		_field5, _value5, _field6, _value6, _field7, _value7,	\
297 		_field8, _value8, _field9, _value9)			\
298 	EFX_POPULATE_DWORD_9(*MCDI_IN2(_emr, efx_dword_t, _ofst),	\
299 		MC_CMD_ ## _field1, _value1,				\
300 		MC_CMD_ ## _field2, _value2,				\
301 		MC_CMD_ ## _field3, _value3,				\
302 		MC_CMD_ ## _field4, _value4,				\
303 		MC_CMD_ ## _field5, _value5,				\
304 		MC_CMD_ ## _field6, _value6,				\
305 		MC_CMD_ ## _field7, _value7,				\
306 		MC_CMD_ ## _field8, _value8,				\
307 		MC_CMD_ ## _field9, _value9)
308 
309 #define	MCDI_IN_POPULATE_DWORD_10(_emr, _ofst, _field1, _value1,	\
310 		_field2, _value2, _field3, _value3, _field4, _value4,	\
311 		_field5, _value5, _field6, _value6, _field7, _value7,	\
312 		_field8, _value8, _field9, _value9, _field10, _value10)	\
313 	EFX_POPULATE_DWORD_10(*MCDI_IN2(_emr, efx_dword_t, _ofst),	\
314 		MC_CMD_ ## _field1, _value1,				\
315 		MC_CMD_ ## _field2, _value2,				\
316 		MC_CMD_ ## _field3, _value3,				\
317 		MC_CMD_ ## _field4, _value4,				\
318 		MC_CMD_ ## _field5, _value5,				\
319 		MC_CMD_ ## _field6, _value6,				\
320 		MC_CMD_ ## _field7, _value7,				\
321 		MC_CMD_ ## _field8, _value8,				\
322 		MC_CMD_ ## _field9, _value9,				\
323 		MC_CMD_ ## _field10, _value10)
324 
325 #define	MCDI_OUT(_emr, _type, _ofst)					\
326 	((_type *)((_emr).emr_out_buf + (_ofst)))
327 
328 #define	MCDI_OUT2(_emr, _type, _ofst)					\
329 	MCDI_OUT(_emr, _type, MC_CMD_ ## _ofst ## _OFST)
330 
331 #define	MCDI_OUT_BYTE(_emr, _ofst)					\
332 	EFX_BYTE_FIELD(*MCDI_OUT2(_emr, efx_byte_t, _ofst),		\
333 		    EFX_BYTE_0)
334 
335 #define	MCDI_OUT_WORD(_emr, _ofst)					\
336 	EFX_WORD_FIELD(*MCDI_OUT2(_emr, efx_word_t, _ofst),		\
337 		    EFX_WORD_0)
338 
339 #define	MCDI_OUT_DWORD(_emr, _ofst)					\
340 	EFX_DWORD_FIELD(*MCDI_OUT2(_emr, efx_dword_t, _ofst),		\
341 			EFX_DWORD_0)
342 
343 #define	MCDI_OUT_DWORD_FIELD(_emr, _ofst, _field)			\
344 	EFX_DWORD_FIELD(*MCDI_OUT2(_emr, efx_dword_t, _ofst),		\
345 			MC_CMD_ ## _field)
346 
347 #define	MCDI_EV_FIELD(_eqp, _field)					\
348 	EFX_QWORD_FIELD(*_eqp, MCDI_EVENT_ ## _field)
349 
350 #define	MCDI_CMD_DWORD_FIELD(_edp, _field)				\
351 	EFX_DWORD_FIELD(*_edp, MC_CMD_ ## _field)
352 
353 #ifdef	__cplusplus
354 }
355 #endif
356 
357 #endif	/* _SYS_EFX_MCDI_H */
358