xref: /freebsd/sys/dev/sfxge/common/efx_mcdi.h (revision 49b49cda41feabe3439f7318e8bf40e3896c7bf4)
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_mcdi.h"
38 
39 #ifdef	__cplusplus
40 extern "C" {
41 #endif
42 
43 /*
44  * A reboot/assertion causes the MCDI status word to be set after the
45  * command word is set or a REBOOT event is sent. If we notice a reboot
46  * via these mechanisms then wait 10ms for the status word to be set.
47  */
48 #define	EFX_MCDI_STATUS_SLEEP_US	10000
49 
50 struct efx_mcdi_req_s {
51 	boolean_t	emr_quiet;
52 	/* Inputs: Command #, input buffer and length */
53 	unsigned int	emr_cmd;
54 	uint8_t		*emr_in_buf;
55 	size_t		emr_in_length;
56 	/* Outputs: retcode, buffer, length, and length used*/
57 	efx_rc_t	emr_rc;
58 	uint8_t		*emr_out_buf;
59 	size_t		emr_out_length;
60 	size_t		emr_out_length_used;
61 	/* Internals: low level transport details */
62 	unsigned int	emr_err_code;
63 	unsigned int	emr_err_arg;
64 #if EFSYS_OPT_MCDI_PROXY_AUTH
65 	uint32_t	emr_proxy_handle;
66 #endif
67 };
68 
69 typedef struct efx_mcdi_iface_s {
70 	unsigned int		emi_port;
71 	unsigned int		emi_max_version;
72 	unsigned int		emi_seq;
73 	efx_mcdi_req_t		*emi_pending_req;
74 	boolean_t		emi_ev_cpl;
75 	boolean_t		emi_new_epoch;
76 	int			emi_aborted;
77 	uint32_t		emi_poll_cnt;
78 	uint32_t		emi_mc_reboot_status;
79 } efx_mcdi_iface_t;
80 
81 extern			void
82 efx_mcdi_execute(
83 	__in		efx_nic_t *enp,
84 	__inout		efx_mcdi_req_t *emrp);
85 
86 extern			void
87 efx_mcdi_execute_quiet(
88 	__in		efx_nic_t *enp,
89 	__inout		efx_mcdi_req_t *emrp);
90 
91 extern			void
92 efx_mcdi_ev_cpl(
93 	__in		efx_nic_t *enp,
94 	__in		unsigned int seq,
95 	__in		unsigned int outlen,
96 	__in		int errcode);
97 
98 #if EFSYS_OPT_MCDI_PROXY_AUTH
99 extern	__checkReturn	efx_rc_t
100 efx_mcdi_get_proxy_handle(
101 	__in		efx_nic_t *enp,
102 	__in		efx_mcdi_req_t *emrp,
103 	__out		uint32_t *handlep);
104 
105 extern			void
106 efx_mcdi_ev_proxy_response(
107 	__in		efx_nic_t *enp,
108 	__in		unsigned int handle,
109 	__in		unsigned int status);
110 #endif
111 
112 extern			void
113 efx_mcdi_ev_death(
114 	__in		efx_nic_t *enp,
115 	__in		int rc);
116 
117 extern	__checkReturn	efx_rc_t
118 efx_mcdi_request_errcode(
119 	__in		unsigned int err);
120 
121 extern			void
122 efx_mcdi_raise_exception(
123 	__in		efx_nic_t *enp,
124 	__in_opt	efx_mcdi_req_t *emrp,
125 	__in		int rc);
126 
127 typedef enum efx_mcdi_boot_e {
128 	EFX_MCDI_BOOT_PRIMARY,
129 	EFX_MCDI_BOOT_SECONDARY,
130 	EFX_MCDI_BOOT_ROM,
131 } efx_mcdi_boot_t;
132 
133 extern	__checkReturn		efx_rc_t
134 efx_mcdi_version(
135 	__in			efx_nic_t *enp,
136 	__out_ecount_opt(4)	uint16_t versionp[4],
137 	__out_opt		uint32_t *buildp,
138 	__out_opt		efx_mcdi_boot_t *statusp);
139 
140 extern	__checkReturn		efx_rc_t
141 efx_mcdi_read_assertion(
142 	__in			efx_nic_t *enp);
143 
144 extern	__checkReturn		efx_rc_t
145 efx_mcdi_exit_assertion_handler(
146 	__in			efx_nic_t *enp);
147 
148 extern	__checkReturn		efx_rc_t
149 efx_mcdi_drv_attach(
150 	__in			efx_nic_t *enp,
151 	__in			boolean_t attach);
152 
153 extern	__checkReturn		efx_rc_t
154 efx_mcdi_get_board_cfg(
155 	__in			efx_nic_t *enp,
156 	__out_opt		uint32_t *board_typep,
157 	__out_opt		efx_dword_t *capabilitiesp,
158 	__out_ecount_opt(6)	uint8_t mac_addrp[6]);
159 
160 extern	__checkReturn		efx_rc_t
161 efx_mcdi_get_phy_cfg(
162 	__in			efx_nic_t *enp);
163 
164 extern	__checkReturn		efx_rc_t
165 efx_mcdi_firmware_update_supported(
166 	__in			efx_nic_t *enp,
167 	__out			boolean_t *supportedp);
168 
169 extern	__checkReturn		efx_rc_t
170 efx_mcdi_macaddr_change_supported(
171 	__in			efx_nic_t *enp,
172 	__out			boolean_t *supportedp);
173 
174 extern	__checkReturn		efx_rc_t
175 efx_mcdi_link_control_supported(
176 	__in			efx_nic_t *enp,
177 	__out			boolean_t *supportedp);
178 
179 extern	__checkReturn		efx_rc_t
180 efx_mcdi_mac_spoofing_supported(
181 	__in			efx_nic_t *enp,
182 	__out			boolean_t *supportedp);
183 
184 
185 #if EFSYS_OPT_BIST
186 #if EFSYS_OPT_HUNTINGTON || EFSYS_OPT_MEDFORD
187 extern	__checkReturn		efx_rc_t
188 efx_mcdi_bist_enable_offline(
189 	__in			efx_nic_t *enp);
190 #endif /* EFSYS_OPT_HUNTINGTON || EFSYS_OPT_MEDFORD */
191 extern	__checkReturn		efx_rc_t
192 efx_mcdi_bist_start(
193 	__in			efx_nic_t *enp,
194 	__in			efx_bist_type_t type);
195 #endif /* EFSYS_OPT_BIST */
196 
197 extern	__checkReturn		efx_rc_t
198 efx_mcdi_get_resource_limits(
199 	__in			efx_nic_t *enp,
200 	__out_opt		uint32_t *nevqp,
201 	__out_opt		uint32_t *nrxqp,
202 	__out_opt		uint32_t *ntxqp);
203 
204 extern	__checkReturn	efx_rc_t
205 efx_mcdi_log_ctrl(
206 	__in		efx_nic_t *enp);
207 
208 extern	__checkReturn	efx_rc_t
209 efx_mcdi_mac_stats_clear(
210 	__in		efx_nic_t *enp);
211 
212 extern	__checkReturn	efx_rc_t
213 efx_mcdi_mac_stats_upload(
214 	__in		efx_nic_t *enp,
215 	__in		efsys_mem_t *esmp);
216 
217 extern	__checkReturn	efx_rc_t
218 efx_mcdi_mac_stats_periodic(
219 	__in		efx_nic_t *enp,
220 	__in		efsys_mem_t *esmp,
221 	__in		uint16_t period,
222 	__in		boolean_t events);
223 
224 
225 #if EFSYS_OPT_LOOPBACK
226 extern	__checkReturn	efx_rc_t
227 efx_mcdi_get_loopback_modes(
228 	__in		efx_nic_t *enp);
229 #endif /* EFSYS_OPT_LOOPBACK */
230 
231 #define	MCDI_IN(_emr, _type, _ofst)					\
232 	((_type *)((_emr).emr_in_buf + (_ofst)))
233 
234 #define	MCDI_IN2(_emr, _type, _ofst)					\
235 	MCDI_IN(_emr, _type, MC_CMD_ ## _ofst ## _OFST)
236 
237 #define	MCDI_IN_SET_BYTE(_emr, _ofst, _value)				\
238 	EFX_POPULATE_BYTE_1(*MCDI_IN2(_emr, efx_byte_t, _ofst),		\
239 		EFX_BYTE_0, _value)
240 
241 #define	MCDI_IN_SET_WORD(_emr, _ofst, _value)				\
242 	EFX_POPULATE_WORD_1(*MCDI_IN2(_emr, efx_word_t, _ofst),		\
243 		EFX_WORD_0, _value)
244 
245 #define	MCDI_IN_SET_DWORD(_emr, _ofst, _value)				\
246 	EFX_POPULATE_DWORD_1(*MCDI_IN2(_emr, efx_dword_t, _ofst),	\
247 		EFX_DWORD_0, _value)
248 
249 #define	MCDI_IN_SET_DWORD_FIELD(_emr, _ofst, _field, _value)		\
250 	EFX_SET_DWORD_FIELD(*MCDI_IN2(_emr, efx_dword_t, _ofst),	\
251 		MC_CMD_ ## _field, _value)
252 
253 #define	MCDI_IN_POPULATE_DWORD_1(_emr, _ofst, _field1, _value1)		\
254 	EFX_POPULATE_DWORD_1(*MCDI_IN2(_emr, efx_dword_t, _ofst),	\
255 		MC_CMD_ ## _field1, _value1)
256 
257 #define	MCDI_IN_POPULATE_DWORD_2(_emr, _ofst, _field1, _value1,		\
258 		_field2, _value2)					\
259 	EFX_POPULATE_DWORD_2(*MCDI_IN2(_emr, efx_dword_t, _ofst),	\
260 		MC_CMD_ ## _field1, _value1,				\
261 		MC_CMD_ ## _field2, _value2)
262 
263 #define	MCDI_IN_POPULATE_DWORD_3(_emr, _ofst, _field1, _value1,		\
264 		_field2, _value2, _field3, _value3)			\
265 	EFX_POPULATE_DWORD_3(*MCDI_IN2(_emr, efx_dword_t, _ofst),	\
266 		MC_CMD_ ## _field1, _value1,				\
267 		MC_CMD_ ## _field2, _value2,				\
268 		MC_CMD_ ## _field3, _value3)
269 
270 #define	MCDI_IN_POPULATE_DWORD_4(_emr, _ofst, _field1, _value1,		\
271 		_field2, _value2, _field3, _value3, _field4, _value4)	\
272 	EFX_POPULATE_DWORD_4(*MCDI_IN2(_emr, efx_dword_t, _ofst),	\
273 		MC_CMD_ ## _field1, _value1,				\
274 		MC_CMD_ ## _field2, _value2,				\
275 		MC_CMD_ ## _field3, _value3,				\
276 		MC_CMD_ ## _field4, _value4)
277 
278 #define	MCDI_IN_POPULATE_DWORD_5(_emr, _ofst, _field1, _value1,		\
279 		_field2, _value2, _field3, _value3, _field4, _value4,	\
280 		_field5, _value5)					\
281 	EFX_POPULATE_DWORD_5(*MCDI_IN2(_emr, efx_dword_t, _ofst),	\
282 		MC_CMD_ ## _field1, _value1,				\
283 		MC_CMD_ ## _field2, _value2,				\
284 		MC_CMD_ ## _field3, _value3,				\
285 		MC_CMD_ ## _field4, _value4,				\
286 		MC_CMD_ ## _field5, _value5)
287 
288 #define	MCDI_IN_POPULATE_DWORD_6(_emr, _ofst, _field1, _value1,		\
289 		_field2, _value2, _field3, _value3, _field4, _value4,	\
290 		_field5, _value5, _field6, _value6)			\
291 	EFX_POPULATE_DWORD_6(*MCDI_IN2(_emr, efx_dword_t, _ofst),	\
292 		MC_CMD_ ## _field1, _value1,				\
293 		MC_CMD_ ## _field2, _value2,				\
294 		MC_CMD_ ## _field3, _value3,				\
295 		MC_CMD_ ## _field4, _value4,				\
296 		MC_CMD_ ## _field5, _value5,				\
297 		MC_CMD_ ## _field6, _value6)
298 
299 #define	MCDI_IN_POPULATE_DWORD_7(_emr, _ofst, _field1, _value1,		\
300 		_field2, _value2, _field3, _value3, _field4, _value4,	\
301 		_field5, _value5, _field6, _value6, _field7, _value7)	\
302 	EFX_POPULATE_DWORD_7(*MCDI_IN2(_emr, efx_dword_t, _ofst),	\
303 		MC_CMD_ ## _field1, _value1,				\
304 		MC_CMD_ ## _field2, _value2,				\
305 		MC_CMD_ ## _field3, _value3,				\
306 		MC_CMD_ ## _field4, _value4,				\
307 		MC_CMD_ ## _field5, _value5,				\
308 		MC_CMD_ ## _field6, _value6,				\
309 		MC_CMD_ ## _field7, _value7)
310 
311 #define	MCDI_IN_POPULATE_DWORD_8(_emr, _ofst, _field1, _value1,		\
312 		_field2, _value2, _field3, _value3, _field4, _value4,	\
313 		_field5, _value5, _field6, _value6, _field7, _value7,	\
314 		_field8, _value8)					\
315 	EFX_POPULATE_DWORD_8(*MCDI_IN2(_emr, efx_dword_t, _ofst),	\
316 		MC_CMD_ ## _field1, _value1,				\
317 		MC_CMD_ ## _field2, _value2,				\
318 		MC_CMD_ ## _field3, _value3,				\
319 		MC_CMD_ ## _field4, _value4,				\
320 		MC_CMD_ ## _field5, _value5,				\
321 		MC_CMD_ ## _field6, _value6,				\
322 		MC_CMD_ ## _field7, _value7,				\
323 		MC_CMD_ ## _field8, _value8)
324 
325 #define	MCDI_IN_POPULATE_DWORD_9(_emr, _ofst, _field1, _value1,		\
326 		_field2, _value2, _field3, _value3, _field4, _value4,	\
327 		_field5, _value5, _field6, _value6, _field7, _value7,	\
328 		_field8, _value8, _field9, _value9)			\
329 	EFX_POPULATE_DWORD_9(*MCDI_IN2(_emr, efx_dword_t, _ofst),	\
330 		MC_CMD_ ## _field1, _value1,				\
331 		MC_CMD_ ## _field2, _value2,				\
332 		MC_CMD_ ## _field3, _value3,				\
333 		MC_CMD_ ## _field4, _value4,				\
334 		MC_CMD_ ## _field5, _value5,				\
335 		MC_CMD_ ## _field6, _value6,				\
336 		MC_CMD_ ## _field7, _value7,				\
337 		MC_CMD_ ## _field8, _value8,				\
338 		MC_CMD_ ## _field9, _value9)
339 
340 #define	MCDI_IN_POPULATE_DWORD_10(_emr, _ofst, _field1, _value1,	\
341 		_field2, _value2, _field3, _value3, _field4, _value4,	\
342 		_field5, _value5, _field6, _value6, _field7, _value7,	\
343 		_field8, _value8, _field9, _value9, _field10, _value10)	\
344 	EFX_POPULATE_DWORD_10(*MCDI_IN2(_emr, efx_dword_t, _ofst),	\
345 		MC_CMD_ ## _field1, _value1,				\
346 		MC_CMD_ ## _field2, _value2,				\
347 		MC_CMD_ ## _field3, _value3,				\
348 		MC_CMD_ ## _field4, _value4,				\
349 		MC_CMD_ ## _field5, _value5,				\
350 		MC_CMD_ ## _field6, _value6,				\
351 		MC_CMD_ ## _field7, _value7,				\
352 		MC_CMD_ ## _field8, _value8,				\
353 		MC_CMD_ ## _field9, _value9,				\
354 		MC_CMD_ ## _field10, _value10)
355 
356 #define	MCDI_OUT(_emr, _type, _ofst)					\
357 	((_type *)((_emr).emr_out_buf + (_ofst)))
358 
359 #define	MCDI_OUT2(_emr, _type, _ofst)					\
360 	MCDI_OUT(_emr, _type, MC_CMD_ ## _ofst ## _OFST)
361 
362 #define	MCDI_OUT_BYTE(_emr, _ofst)					\
363 	EFX_BYTE_FIELD(*MCDI_OUT2(_emr, efx_byte_t, _ofst),		\
364 		    EFX_BYTE_0)
365 
366 #define	MCDI_OUT_WORD(_emr, _ofst)					\
367 	EFX_WORD_FIELD(*MCDI_OUT2(_emr, efx_word_t, _ofst),		\
368 		    EFX_WORD_0)
369 
370 #define	MCDI_OUT_DWORD(_emr, _ofst)					\
371 	EFX_DWORD_FIELD(*MCDI_OUT2(_emr, efx_dword_t, _ofst),		\
372 			EFX_DWORD_0)
373 
374 #define	MCDI_OUT_DWORD_FIELD(_emr, _ofst, _field)			\
375 	EFX_DWORD_FIELD(*MCDI_OUT2(_emr, efx_dword_t, _ofst),		\
376 			MC_CMD_ ## _field)
377 
378 #define	MCDI_EV_FIELD(_eqp, _field)					\
379 	EFX_QWORD_FIELD(*_eqp, MCDI_EVENT_ ## _field)
380 
381 #define	MCDI_CMD_DWORD_FIELD(_edp, _field)				\
382 	EFX_DWORD_FIELD(*_edp, MC_CMD_ ## _field)
383 
384 #define	EFX_MCDI_HAVE_PRIVILEGE(mask, priv)				\
385 	(((mask) & (MC_CMD_PRIVILEGE_MASK_IN_GRP_ ## priv)) ==		\
386 	(MC_CMD_PRIVILEGE_MASK_IN_GRP_ ## priv))
387 
388 typedef enum efx_mcdi_feature_id_e {
389 	EFX_MCDI_FEATURE_FW_UPDATE = 0,
390 	EFX_MCDI_FEATURE_LINK_CONTROL,
391 	EFX_MCDI_FEATURE_MACADDR_CHANGE,
392 	EFX_MCDI_FEATURE_MAC_SPOOFING,
393 	EFX_MCDI_FEATURE_NIDS
394 } efx_mcdi_feature_id_t;
395 
396 #ifdef	__cplusplus
397 }
398 #endif
399 
400 #endif	/* _SYS_EFX_MCDI_H */
401