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