xref: /freebsd/sys/dev/sfxge/common/efx_mcdi.h (revision dd41de95a84d979615a2ef11df6850622bf6184e)
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 #if EFSYS_OPT_BIST
200 #if EFSYS_OPT_HUNTINGTON || EFSYS_OPT_MEDFORD || EFSYS_OPT_MEDFORD2
201 extern	__checkReturn		efx_rc_t
202 efx_mcdi_bist_enable_offline(
203 	__in			efx_nic_t *enp);
204 #endif /* EFSYS_OPT_HUNTINGTON || EFSYS_OPT_MEDFORD || EFSYS_OPT_MEDFORD2 */
205 extern	__checkReturn		efx_rc_t
206 efx_mcdi_bist_start(
207 	__in			efx_nic_t *enp,
208 	__in			efx_bist_type_t type);
209 #endif /* EFSYS_OPT_BIST */
210 
211 extern	__checkReturn		efx_rc_t
212 efx_mcdi_get_resource_limits(
213 	__in			efx_nic_t *enp,
214 	__out_opt		uint32_t *nevqp,
215 	__out_opt		uint32_t *nrxqp,
216 	__out_opt		uint32_t *ntxqp);
217 
218 extern	__checkReturn	efx_rc_t
219 efx_mcdi_log_ctrl(
220 	__in		efx_nic_t *enp);
221 
222 extern	__checkReturn	efx_rc_t
223 efx_mcdi_mac_stats_clear(
224 	__in		efx_nic_t *enp);
225 
226 extern	__checkReturn	efx_rc_t
227 efx_mcdi_mac_stats_upload(
228 	__in		efx_nic_t *enp,
229 	__in		efsys_mem_t *esmp);
230 
231 extern	__checkReturn	efx_rc_t
232 efx_mcdi_mac_stats_periodic(
233 	__in		efx_nic_t *enp,
234 	__in		efsys_mem_t *esmp,
235 	__in		uint16_t period_ms,
236 	__in		boolean_t events);
237 
238 #if EFSYS_OPT_LOOPBACK
239 extern	__checkReturn	efx_rc_t
240 efx_mcdi_get_loopback_modes(
241 	__in		efx_nic_t *enp);
242 #endif /* EFSYS_OPT_LOOPBACK */
243 
244 extern	__checkReturn	efx_rc_t
245 efx_mcdi_phy_module_get_info(
246 	__in			efx_nic_t *enp,
247 	__in			uint8_t dev_addr,
248 	__in			size_t offset,
249 	__in			size_t len,
250 	__out_bcount(len)	uint8_t *data);
251 
252 #define	MCDI_IN(_emr, _type, _ofst)					\
253 	((_type *)((_emr).emr_in_buf + (_ofst)))
254 
255 #define	MCDI_IN2(_emr, _type, _ofst)					\
256 	MCDI_IN(_emr, _type, MC_CMD_ ## _ofst ## _OFST)
257 
258 #define	MCDI_IN_SET_BYTE(_emr, _ofst, _value)				\
259 	EFX_POPULATE_BYTE_1(*MCDI_IN2(_emr, efx_byte_t, _ofst),		\
260 		EFX_BYTE_0, _value)
261 
262 #define	MCDI_IN_SET_WORD(_emr, _ofst, _value)				\
263 	EFX_POPULATE_WORD_1(*MCDI_IN2(_emr, efx_word_t, _ofst),		\
264 		EFX_WORD_0, _value)
265 
266 #define	MCDI_IN_SET_DWORD(_emr, _ofst, _value)				\
267 	EFX_POPULATE_DWORD_1(*MCDI_IN2(_emr, efx_dword_t, _ofst),	\
268 		EFX_DWORD_0, _value)
269 
270 #define	MCDI_IN_SET_DWORD_FIELD(_emr, _ofst, _field, _value)		\
271 	EFX_SET_DWORD_FIELD(*MCDI_IN2(_emr, efx_dword_t, _ofst),	\
272 		MC_CMD_ ## _field, _value)
273 
274 #define	MCDI_IN_POPULATE_DWORD_1(_emr, _ofst, _field1, _value1)		\
275 	EFX_POPULATE_DWORD_1(*MCDI_IN2(_emr, efx_dword_t, _ofst),	\
276 		MC_CMD_ ## _field1, _value1)
277 
278 #define	MCDI_IN_POPULATE_DWORD_2(_emr, _ofst, _field1, _value1,		\
279 		_field2, _value2)					\
280 	EFX_POPULATE_DWORD_2(*MCDI_IN2(_emr, efx_dword_t, _ofst),	\
281 		MC_CMD_ ## _field1, _value1,				\
282 		MC_CMD_ ## _field2, _value2)
283 
284 #define	MCDI_IN_POPULATE_DWORD_3(_emr, _ofst, _field1, _value1,		\
285 		_field2, _value2, _field3, _value3)			\
286 	EFX_POPULATE_DWORD_3(*MCDI_IN2(_emr, efx_dword_t, _ofst),	\
287 		MC_CMD_ ## _field1, _value1,				\
288 		MC_CMD_ ## _field2, _value2,				\
289 		MC_CMD_ ## _field3, _value3)
290 
291 #define	MCDI_IN_POPULATE_DWORD_4(_emr, _ofst, _field1, _value1,		\
292 		_field2, _value2, _field3, _value3, _field4, _value4)	\
293 	EFX_POPULATE_DWORD_4(*MCDI_IN2(_emr, efx_dword_t, _ofst),	\
294 		MC_CMD_ ## _field1, _value1,				\
295 		MC_CMD_ ## _field2, _value2,				\
296 		MC_CMD_ ## _field3, _value3,				\
297 		MC_CMD_ ## _field4, _value4)
298 
299 #define	MCDI_IN_POPULATE_DWORD_5(_emr, _ofst, _field1, _value1,		\
300 		_field2, _value2, _field3, _value3, _field4, _value4,	\
301 		_field5, _value5)					\
302 	EFX_POPULATE_DWORD_5(*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 
309 #define	MCDI_IN_POPULATE_DWORD_6(_emr, _ofst, _field1, _value1,		\
310 		_field2, _value2, _field3, _value3, _field4, _value4,	\
311 		_field5, _value5, _field6, _value6)			\
312 	EFX_POPULATE_DWORD_6(*MCDI_IN2(_emr, efx_dword_t, _ofst),	\
313 		MC_CMD_ ## _field1, _value1,				\
314 		MC_CMD_ ## _field2, _value2,				\
315 		MC_CMD_ ## _field3, _value3,				\
316 		MC_CMD_ ## _field4, _value4,				\
317 		MC_CMD_ ## _field5, _value5,				\
318 		MC_CMD_ ## _field6, _value6)
319 
320 #define	MCDI_IN_POPULATE_DWORD_7(_emr, _ofst, _field1, _value1,		\
321 		_field2, _value2, _field3, _value3, _field4, _value4,	\
322 		_field5, _value5, _field6, _value6, _field7, _value7)	\
323 	EFX_POPULATE_DWORD_7(*MCDI_IN2(_emr, efx_dword_t, _ofst),	\
324 		MC_CMD_ ## _field1, _value1,				\
325 		MC_CMD_ ## _field2, _value2,				\
326 		MC_CMD_ ## _field3, _value3,				\
327 		MC_CMD_ ## _field4, _value4,				\
328 		MC_CMD_ ## _field5, _value5,				\
329 		MC_CMD_ ## _field6, _value6,				\
330 		MC_CMD_ ## _field7, _value7)
331 
332 #define	MCDI_IN_POPULATE_DWORD_8(_emr, _ofst, _field1, _value1,		\
333 		_field2, _value2, _field3, _value3, _field4, _value4,	\
334 		_field5, _value5, _field6, _value6, _field7, _value7,	\
335 		_field8, _value8)					\
336 	EFX_POPULATE_DWORD_8(*MCDI_IN2(_emr, efx_dword_t, _ofst),	\
337 		MC_CMD_ ## _field1, _value1,				\
338 		MC_CMD_ ## _field2, _value2,				\
339 		MC_CMD_ ## _field3, _value3,				\
340 		MC_CMD_ ## _field4, _value4,				\
341 		MC_CMD_ ## _field5, _value5,				\
342 		MC_CMD_ ## _field6, _value6,				\
343 		MC_CMD_ ## _field7, _value7,				\
344 		MC_CMD_ ## _field8, _value8)
345 
346 #define	MCDI_IN_POPULATE_DWORD_9(_emr, _ofst, _field1, _value1,		\
347 		_field2, _value2, _field3, _value3, _field4, _value4,	\
348 		_field5, _value5, _field6, _value6, _field7, _value7,	\
349 		_field8, _value8, _field9, _value9)			\
350 	EFX_POPULATE_DWORD_9(*MCDI_IN2(_emr, efx_dword_t, _ofst),	\
351 		MC_CMD_ ## _field1, _value1,				\
352 		MC_CMD_ ## _field2, _value2,				\
353 		MC_CMD_ ## _field3, _value3,				\
354 		MC_CMD_ ## _field4, _value4,				\
355 		MC_CMD_ ## _field5, _value5,				\
356 		MC_CMD_ ## _field6, _value6,				\
357 		MC_CMD_ ## _field7, _value7,				\
358 		MC_CMD_ ## _field8, _value8,				\
359 		MC_CMD_ ## _field9, _value9)
360 
361 #define	MCDI_IN_POPULATE_DWORD_10(_emr, _ofst, _field1, _value1,	\
362 		_field2, _value2, _field3, _value3, _field4, _value4,	\
363 		_field5, _value5, _field6, _value6, _field7, _value7,	\
364 		_field8, _value8, _field9, _value9, _field10, _value10)	\
365 	EFX_POPULATE_DWORD_10(*MCDI_IN2(_emr, efx_dword_t, _ofst),	\
366 		MC_CMD_ ## _field1, _value1,				\
367 		MC_CMD_ ## _field2, _value2,				\
368 		MC_CMD_ ## _field3, _value3,				\
369 		MC_CMD_ ## _field4, _value4,				\
370 		MC_CMD_ ## _field5, _value5,				\
371 		MC_CMD_ ## _field6, _value6,				\
372 		MC_CMD_ ## _field7, _value7,				\
373 		MC_CMD_ ## _field8, _value8,				\
374 		MC_CMD_ ## _field9, _value9,				\
375 		MC_CMD_ ## _field10, _value10)
376 
377 #define	MCDI_OUT(_emr, _type, _ofst)					\
378 	((_type *)((_emr).emr_out_buf + (_ofst)))
379 
380 #define	MCDI_OUT2(_emr, _type, _ofst)					\
381 	MCDI_OUT(_emr, _type, MC_CMD_ ## _ofst ## _OFST)
382 
383 #define	MCDI_OUT_BYTE(_emr, _ofst)					\
384 	EFX_BYTE_FIELD(*MCDI_OUT2(_emr, efx_byte_t, _ofst),		\
385 		    EFX_BYTE_0)
386 
387 #define	MCDI_OUT_WORD(_emr, _ofst)					\
388 	EFX_WORD_FIELD(*MCDI_OUT2(_emr, efx_word_t, _ofst),		\
389 		    EFX_WORD_0)
390 
391 #define	MCDI_OUT_WORD_FIELD(_emr, _ofst, _field)			\
392 	EFX_WORD_FIELD(*MCDI_OUT2(_emr, efx_word_t, _ofst),		\
393 		       MC_CMD_ ## _field)
394 
395 #define	MCDI_OUT_DWORD(_emr, _ofst)					\
396 	EFX_DWORD_FIELD(*MCDI_OUT2(_emr, efx_dword_t, _ofst),		\
397 			EFX_DWORD_0)
398 
399 #define	MCDI_OUT_DWORD_FIELD(_emr, _ofst, _field)			\
400 	EFX_DWORD_FIELD(*MCDI_OUT2(_emr, efx_dword_t, _ofst),		\
401 			MC_CMD_ ## _field)
402 
403 #define	MCDI_EV_FIELD(_eqp, _field)					\
404 	EFX_QWORD_FIELD(*_eqp, MCDI_EVENT_ ## _field)
405 
406 #define	MCDI_CMD_DWORD_FIELD(_edp, _field)				\
407 	EFX_DWORD_FIELD(*_edp, MC_CMD_ ## _field)
408 
409 #define	EFX_MCDI_HAVE_PRIVILEGE(mask, priv)				\
410 	(((mask) & (MC_CMD_PRIVILEGE_MASK_IN_GRP_ ## priv)) ==		\
411 	(MC_CMD_PRIVILEGE_MASK_IN_GRP_ ## priv))
412 
413 #define	EFX_MCDI_BUF_SIZE(_in_len, _out_len)				\
414 	EFX_P2ROUNDUP(size_t,						\
415 		MAX(MAX(_in_len, _out_len), (2 * sizeof (efx_dword_t))),\
416 		sizeof (efx_dword_t))
417 
418 /*
419  * The buffer size must be a multiple of dword to ensure that MCDI works
420  * properly with Siena based boards (which use on-chip buffer). Also, it
421  * should be at minimum the size of two dwords to allow space for extended
422  * error responses if the request/response buffer sizes are smaller.
423  */
424 #define EFX_MCDI_DECLARE_BUF(_name, _in_len, _out_len)			\
425 	uint8_t _name[EFX_MCDI_BUF_SIZE(_in_len, _out_len)] = {0}
426 
427 typedef enum efx_mcdi_feature_id_e {
428 	EFX_MCDI_FEATURE_FW_UPDATE = 0,
429 	EFX_MCDI_FEATURE_LINK_CONTROL,
430 	EFX_MCDI_FEATURE_MACADDR_CHANGE,
431 	EFX_MCDI_FEATURE_MAC_SPOOFING,
432 	EFX_MCDI_FEATURE_NIDS
433 } efx_mcdi_feature_id_t;
434 
435 #ifdef	__cplusplus
436 }
437 #endif
438 
439 #endif	/* _SYS_EFX_MCDI_H */
440