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