2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) 2009-2016 Solarflare Communications Inc.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are met:
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.
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.
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.
35 #ifndef _SYS_EFX_MCDI_H
36 #define _SYS_EFX_MCDI_H
39 #include "efx_regs_mcdi.h"
42 #include "efx_regs_mcdi_strs.h"
43 #endif /* EFSYS_OPT_NAMES */
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.
54 #define EFX_MCDI_STATUS_SLEEP_US 10000
56 struct efx_mcdi_req_s {
58 /* Inputs: Command #, input buffer and length */
62 /* Outputs: retcode, buffer, length, and length used */
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;
75 typedef struct efx_mcdi_iface_s {
76 unsigned int emi_port;
77 unsigned int emi_max_version;
79 efx_mcdi_req_t *emi_pending_req;
81 boolean_t emi_new_epoch;
83 uint32_t emi_poll_cnt;
84 uint32_t emi_mc_reboot_status;
90 __inout efx_mcdi_req_t *emrp);
93 efx_mcdi_execute_quiet(
95 __inout efx_mcdi_req_t *emrp);
100 __in unsigned int seq,
101 __in unsigned int outlen,
104 #if EFSYS_OPT_MCDI_PROXY_AUTH
105 extern __checkReturn efx_rc_t
106 efx_mcdi_get_proxy_handle(
108 __in efx_mcdi_req_t *emrp,
109 __out uint32_t *handlep);
112 efx_mcdi_ev_proxy_response(
114 __in unsigned int handle,
115 __in unsigned int status);
123 extern __checkReturn efx_rc_t
124 efx_mcdi_request_errcode(
125 __in unsigned int err);
128 efx_mcdi_raise_exception(
130 __in_opt efx_mcdi_req_t *emrp,
133 typedef enum efx_mcdi_boot_e {
134 EFX_MCDI_BOOT_PRIMARY,
135 EFX_MCDI_BOOT_SECONDARY,
139 extern __checkReturn efx_rc_t
142 __out_ecount_opt(4) uint16_t versionp[4],
143 __out_opt uint32_t *buildp,
144 __out_opt efx_mcdi_boot_t *statusp);
146 extern __checkReturn efx_rc_t
147 efx_mcdi_get_capabilities(
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);
155 extern __checkReturn efx_rc_t
156 efx_mcdi_read_assertion(
157 __in efx_nic_t *enp);
159 extern __checkReturn efx_rc_t
160 efx_mcdi_exit_assertion_handler(
161 __in efx_nic_t *enp);
163 extern __checkReturn efx_rc_t
166 __in boolean_t attach);
168 extern __checkReturn efx_rc_t
169 efx_mcdi_get_board_cfg(
171 __out_opt uint32_t *board_typep,
172 __out_opt efx_dword_t *capabilitiesp,
173 __out_ecount_opt(6) uint8_t mac_addrp[6]);
175 extern __checkReturn efx_rc_t
176 efx_mcdi_get_phy_cfg(
177 __in efx_nic_t *enp);
179 extern __checkReturn efx_rc_t
180 efx_mcdi_firmware_update_supported(
182 __out boolean_t *supportedp);
184 extern __checkReturn efx_rc_t
185 efx_mcdi_macaddr_change_supported(
187 __out boolean_t *supportedp);
189 extern __checkReturn efx_rc_t
190 efx_mcdi_link_control_supported(
192 __out boolean_t *supportedp);
194 extern __checkReturn efx_rc_t
195 efx_mcdi_mac_spoofing_supported(
197 __out boolean_t *supportedp);
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
209 __in efx_bist_type_t type);
210 #endif /* EFSYS_OPT_BIST */
212 extern __checkReturn efx_rc_t
213 efx_mcdi_get_resource_limits(
215 __out_opt uint32_t *nevqp,
216 __out_opt uint32_t *nrxqp,
217 __out_opt uint32_t *ntxqp);
219 extern __checkReturn efx_rc_t
221 __in efx_nic_t *enp);
223 extern __checkReturn efx_rc_t
224 efx_mcdi_mac_stats_clear(
225 __in efx_nic_t *enp);
227 extern __checkReturn efx_rc_t
228 efx_mcdi_mac_stats_upload(
230 __in efsys_mem_t *esmp);
232 extern __checkReturn efx_rc_t
233 efx_mcdi_mac_stats_periodic(
235 __in efsys_mem_t *esmp,
236 __in uint16_t period_ms,
237 __in boolean_t events);
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 */
246 extern __checkReturn efx_rc_t
247 efx_mcdi_phy_module_get_info(
249 __in uint8_t dev_addr,
252 __out_bcount(len) uint8_t *data);
254 #define MCDI_IN(_emr, _type, _ofst) \
255 ((_type *)((_emr).emr_in_buf + (_ofst)))
257 #define MCDI_IN2(_emr, _type, _ofst) \
258 MCDI_IN(_emr, _type, MC_CMD_ ## _ofst ## _OFST)
260 #define MCDI_IN_SET_BYTE(_emr, _ofst, _value) \
261 EFX_POPULATE_BYTE_1(*MCDI_IN2(_emr, efx_byte_t, _ofst), \
264 #define MCDI_IN_SET_WORD(_emr, _ofst, _value) \
265 EFX_POPULATE_WORD_1(*MCDI_IN2(_emr, efx_word_t, _ofst), \
268 #define MCDI_IN_SET_DWORD(_emr, _ofst, _value) \
269 EFX_POPULATE_DWORD_1(*MCDI_IN2(_emr, efx_dword_t, _ofst), \
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)
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)
280 #define MCDI_IN_POPULATE_DWORD_2(_emr, _ofst, _field1, _value1, \
282 EFX_POPULATE_DWORD_2(*MCDI_IN2(_emr, efx_dword_t, _ofst), \
283 MC_CMD_ ## _field1, _value1, \
284 MC_CMD_ ## _field2, _value2)
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)
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)
301 #define MCDI_IN_POPULATE_DWORD_5(_emr, _ofst, _field1, _value1, \
302 _field2, _value2, _field3, _value3, _field4, _value4, \
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)
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)
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)
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, \
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)
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)
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)
379 #define MCDI_OUT(_emr, _type, _ofst) \
380 ((_type *)((_emr).emr_out_buf + (_ofst)))
382 #define MCDI_OUT2(_emr, _type, _ofst) \
383 MCDI_OUT(_emr, _type, MC_CMD_ ## _ofst ## _OFST)
385 #define MCDI_OUT_BYTE(_emr, _ofst) \
386 EFX_BYTE_FIELD(*MCDI_OUT2(_emr, efx_byte_t, _ofst), \
389 #define MCDI_OUT_WORD(_emr, _ofst) \
390 EFX_WORD_FIELD(*MCDI_OUT2(_emr, efx_word_t, _ofst), \
393 #define MCDI_OUT_WORD_FIELD(_emr, _ofst, _field) \
394 EFX_WORD_FIELD(*MCDI_OUT2(_emr, efx_word_t, _ofst), \
397 #define MCDI_OUT_DWORD(_emr, _ofst) \
398 EFX_DWORD_FIELD(*MCDI_OUT2(_emr, efx_dword_t, _ofst), \
401 #define MCDI_OUT_DWORD_FIELD(_emr, _ofst, _field) \
402 EFX_DWORD_FIELD(*MCDI_OUT2(_emr, efx_dword_t, _ofst), \
405 #define MCDI_EV_FIELD(_eqp, _field) \
406 EFX_QWORD_FIELD(*_eqp, MCDI_EVENT_ ## _field)
408 #define MCDI_CMD_DWORD_FIELD(_edp, _field) \
409 EFX_DWORD_FIELD(*_edp, MC_CMD_ ## _field)
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))
416 * The buffer size must be a multiple of dword to ensure that MCDI works
417 * properly with Siena based boards (which use on-chip buffer). Also, it
418 * should be at minimum the size of two dwords to allow space for extended
419 * error responses if the request/response buffer sizes are smaller.
421 #define EFX_MCDI_DECLARE_BUF(_name, _in_len, _out_len) \
422 uint8_t _name[P2ROUNDUP(MAX(MAX(_in_len, _out_len), \
423 (2 * sizeof (efx_dword_t))), \
424 sizeof (efx_dword_t))] = {0}
426 typedef enum efx_mcdi_feature_id_e {
427 EFX_MCDI_FEATURE_FW_UPDATE = 0,
428 EFX_MCDI_FEATURE_LINK_CONTROL,
429 EFX_MCDI_FEATURE_MACADDR_CHANGE,
430 EFX_MCDI_FEATURE_MAC_SPOOFING,
431 EFX_MCDI_FEATURE_NIDS
432 } efx_mcdi_feature_id_t;
438 #endif /* _SYS_EFX_MCDI_H */