2 * Copyright (c) 2009-2016 Solarflare Communications Inc.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
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.
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.
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.
31 #ifndef _SYS_EFX_MCDI_H
32 #define _SYS_EFX_MCDI_H
35 #include "efx_regs_mcdi.h"
42 * A reboot/assertion causes the MCDI status word to be set after the
43 * command word is set or a REBOOT event is sent. If we notice a reboot
44 * via these mechanisms then wait 10ms for the status word to be set.
46 #define EFX_MCDI_STATUS_SLEEP_US 10000
48 struct efx_mcdi_req_s {
50 /* Inputs: Command #, input buffer and length */
54 /* Outputs: retcode, buffer, length, and length used */
57 size_t emr_out_length;
58 size_t emr_out_length_used;
59 /* Internals: low level transport details */
60 unsigned int emr_err_code;
61 unsigned int emr_err_arg;
62 #if EFSYS_OPT_MCDI_PROXY_AUTH
63 uint32_t emr_proxy_handle;
67 typedef struct efx_mcdi_iface_s {
68 unsigned int emi_port;
69 unsigned int emi_max_version;
71 efx_mcdi_req_t *emi_pending_req;
73 boolean_t emi_new_epoch;
75 uint32_t emi_poll_cnt;
76 uint32_t emi_mc_reboot_status;
82 __inout efx_mcdi_req_t *emrp);
85 efx_mcdi_execute_quiet(
87 __inout efx_mcdi_req_t *emrp);
92 __in unsigned int seq,
93 __in unsigned int outlen,
96 #if EFSYS_OPT_MCDI_PROXY_AUTH
97 extern __checkReturn efx_rc_t
98 efx_mcdi_get_proxy_handle(
100 __in efx_mcdi_req_t *emrp,
101 __out uint32_t *handlep);
104 efx_mcdi_ev_proxy_response(
106 __in unsigned int handle,
107 __in unsigned int status);
115 extern __checkReturn efx_rc_t
116 efx_mcdi_request_errcode(
117 __in unsigned int err);
120 efx_mcdi_raise_exception(
122 __in_opt efx_mcdi_req_t *emrp,
125 typedef enum efx_mcdi_boot_e {
126 EFX_MCDI_BOOT_PRIMARY,
127 EFX_MCDI_BOOT_SECONDARY,
131 extern __checkReturn efx_rc_t
134 __out_ecount_opt(4) uint16_t versionp[4],
135 __out_opt uint32_t *buildp,
136 __out_opt efx_mcdi_boot_t *statusp);
138 extern __checkReturn efx_rc_t
139 efx_mcdi_get_capabilities(
141 __out_opt uint32_t *flagsp,
142 __out_opt uint16_t *rx_dpcpu_fw_idp,
143 __out_opt uint16_t *tx_dpcpu_fw_idp,
144 __out_opt uint32_t *flags2p,
145 __out_opt uint32_t *tso2ncp);
147 extern __checkReturn efx_rc_t
148 efx_mcdi_read_assertion(
149 __in efx_nic_t *enp);
151 extern __checkReturn efx_rc_t
152 efx_mcdi_exit_assertion_handler(
153 __in efx_nic_t *enp);
155 extern __checkReturn efx_rc_t
158 __in boolean_t attach);
160 extern __checkReturn efx_rc_t
161 efx_mcdi_get_board_cfg(
163 __out_opt uint32_t *board_typep,
164 __out_opt efx_dword_t *capabilitiesp,
165 __out_ecount_opt(6) uint8_t mac_addrp[6]);
167 extern __checkReturn efx_rc_t
168 efx_mcdi_get_phy_cfg(
169 __in efx_nic_t *enp);
171 extern __checkReturn efx_rc_t
172 efx_mcdi_firmware_update_supported(
174 __out boolean_t *supportedp);
176 extern __checkReturn efx_rc_t
177 efx_mcdi_macaddr_change_supported(
179 __out boolean_t *supportedp);
181 extern __checkReturn efx_rc_t
182 efx_mcdi_link_control_supported(
184 __out boolean_t *supportedp);
186 extern __checkReturn efx_rc_t
187 efx_mcdi_mac_spoofing_supported(
189 __out boolean_t *supportedp);
193 #if EFSYS_OPT_HUNTINGTON || EFSYS_OPT_MEDFORD
194 extern __checkReturn efx_rc_t
195 efx_mcdi_bist_enable_offline(
196 __in efx_nic_t *enp);
197 #endif /* EFSYS_OPT_HUNTINGTON || EFSYS_OPT_MEDFORD */
198 extern __checkReturn efx_rc_t
201 __in efx_bist_type_t type);
202 #endif /* EFSYS_OPT_BIST */
204 extern __checkReturn efx_rc_t
205 efx_mcdi_get_resource_limits(
207 __out_opt uint32_t *nevqp,
208 __out_opt uint32_t *nrxqp,
209 __out_opt uint32_t *ntxqp);
211 extern __checkReturn efx_rc_t
213 __in efx_nic_t *enp);
215 extern __checkReturn efx_rc_t
216 efx_mcdi_mac_stats_clear(
217 __in efx_nic_t *enp);
219 extern __checkReturn efx_rc_t
220 efx_mcdi_mac_stats_upload(
222 __in efsys_mem_t *esmp);
224 extern __checkReturn efx_rc_t
225 efx_mcdi_mac_stats_periodic(
227 __in efsys_mem_t *esmp,
228 __in uint16_t period_ms,
229 __in boolean_t events);
232 #if EFSYS_OPT_LOOPBACK
233 extern __checkReturn efx_rc_t
234 efx_mcdi_get_loopback_modes(
235 __in efx_nic_t *enp);
236 #endif /* EFSYS_OPT_LOOPBACK */
238 extern __checkReturn efx_rc_t
239 efx_mcdi_phy_module_get_info(
241 __in uint8_t dev_addr,
244 __out_bcount(len) uint8_t *data);
246 #define MCDI_IN(_emr, _type, _ofst) \
247 ((_type *)((_emr).emr_in_buf + (_ofst)))
249 #define MCDI_IN2(_emr, _type, _ofst) \
250 MCDI_IN(_emr, _type, MC_CMD_ ## _ofst ## _OFST)
252 #define MCDI_IN_SET_BYTE(_emr, _ofst, _value) \
253 EFX_POPULATE_BYTE_1(*MCDI_IN2(_emr, efx_byte_t, _ofst), \
256 #define MCDI_IN_SET_WORD(_emr, _ofst, _value) \
257 EFX_POPULATE_WORD_1(*MCDI_IN2(_emr, efx_word_t, _ofst), \
260 #define MCDI_IN_SET_DWORD(_emr, _ofst, _value) \
261 EFX_POPULATE_DWORD_1(*MCDI_IN2(_emr, efx_dword_t, _ofst), \
264 #define MCDI_IN_SET_DWORD_FIELD(_emr, _ofst, _field, _value) \
265 EFX_SET_DWORD_FIELD(*MCDI_IN2(_emr, efx_dword_t, _ofst), \
266 MC_CMD_ ## _field, _value)
268 #define MCDI_IN_POPULATE_DWORD_1(_emr, _ofst, _field1, _value1) \
269 EFX_POPULATE_DWORD_1(*MCDI_IN2(_emr, efx_dword_t, _ofst), \
270 MC_CMD_ ## _field1, _value1)
272 #define MCDI_IN_POPULATE_DWORD_2(_emr, _ofst, _field1, _value1, \
274 EFX_POPULATE_DWORD_2(*MCDI_IN2(_emr, efx_dword_t, _ofst), \
275 MC_CMD_ ## _field1, _value1, \
276 MC_CMD_ ## _field2, _value2)
278 #define MCDI_IN_POPULATE_DWORD_3(_emr, _ofst, _field1, _value1, \
279 _field2, _value2, _field3, _value3) \
280 EFX_POPULATE_DWORD_3(*MCDI_IN2(_emr, efx_dword_t, _ofst), \
281 MC_CMD_ ## _field1, _value1, \
282 MC_CMD_ ## _field2, _value2, \
283 MC_CMD_ ## _field3, _value3)
285 #define MCDI_IN_POPULATE_DWORD_4(_emr, _ofst, _field1, _value1, \
286 _field2, _value2, _field3, _value3, _field4, _value4) \
287 EFX_POPULATE_DWORD_4(*MCDI_IN2(_emr, efx_dword_t, _ofst), \
288 MC_CMD_ ## _field1, _value1, \
289 MC_CMD_ ## _field2, _value2, \
290 MC_CMD_ ## _field3, _value3, \
291 MC_CMD_ ## _field4, _value4)
293 #define MCDI_IN_POPULATE_DWORD_5(_emr, _ofst, _field1, _value1, \
294 _field2, _value2, _field3, _value3, _field4, _value4, \
296 EFX_POPULATE_DWORD_5(*MCDI_IN2(_emr, efx_dword_t, _ofst), \
297 MC_CMD_ ## _field1, _value1, \
298 MC_CMD_ ## _field2, _value2, \
299 MC_CMD_ ## _field3, _value3, \
300 MC_CMD_ ## _field4, _value4, \
301 MC_CMD_ ## _field5, _value5)
303 #define MCDI_IN_POPULATE_DWORD_6(_emr, _ofst, _field1, _value1, \
304 _field2, _value2, _field3, _value3, _field4, _value4, \
305 _field5, _value5, _field6, _value6) \
306 EFX_POPULATE_DWORD_6(*MCDI_IN2(_emr, efx_dword_t, _ofst), \
307 MC_CMD_ ## _field1, _value1, \
308 MC_CMD_ ## _field2, _value2, \
309 MC_CMD_ ## _field3, _value3, \
310 MC_CMD_ ## _field4, _value4, \
311 MC_CMD_ ## _field5, _value5, \
312 MC_CMD_ ## _field6, _value6)
314 #define MCDI_IN_POPULATE_DWORD_7(_emr, _ofst, _field1, _value1, \
315 _field2, _value2, _field3, _value3, _field4, _value4, \
316 _field5, _value5, _field6, _value6, _field7, _value7) \
317 EFX_POPULATE_DWORD_7(*MCDI_IN2(_emr, efx_dword_t, _ofst), \
318 MC_CMD_ ## _field1, _value1, \
319 MC_CMD_ ## _field2, _value2, \
320 MC_CMD_ ## _field3, _value3, \
321 MC_CMD_ ## _field4, _value4, \
322 MC_CMD_ ## _field5, _value5, \
323 MC_CMD_ ## _field6, _value6, \
324 MC_CMD_ ## _field7, _value7)
326 #define MCDI_IN_POPULATE_DWORD_8(_emr, _ofst, _field1, _value1, \
327 _field2, _value2, _field3, _value3, _field4, _value4, \
328 _field5, _value5, _field6, _value6, _field7, _value7, \
330 EFX_POPULATE_DWORD_8(*MCDI_IN2(_emr, efx_dword_t, _ofst), \
331 MC_CMD_ ## _field1, _value1, \
332 MC_CMD_ ## _field2, _value2, \
333 MC_CMD_ ## _field3, _value3, \
334 MC_CMD_ ## _field4, _value4, \
335 MC_CMD_ ## _field5, _value5, \
336 MC_CMD_ ## _field6, _value6, \
337 MC_CMD_ ## _field7, _value7, \
338 MC_CMD_ ## _field8, _value8)
340 #define MCDI_IN_POPULATE_DWORD_9(_emr, _ofst, _field1, _value1, \
341 _field2, _value2, _field3, _value3, _field4, _value4, \
342 _field5, _value5, _field6, _value6, _field7, _value7, \
343 _field8, _value8, _field9, _value9) \
344 EFX_POPULATE_DWORD_9(*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)
355 #define MCDI_IN_POPULATE_DWORD_10(_emr, _ofst, _field1, _value1, \
356 _field2, _value2, _field3, _value3, _field4, _value4, \
357 _field5, _value5, _field6, _value6, _field7, _value7, \
358 _field8, _value8, _field9, _value9, _field10, _value10) \
359 EFX_POPULATE_DWORD_10(*MCDI_IN2(_emr, efx_dword_t, _ofst), \
360 MC_CMD_ ## _field1, _value1, \
361 MC_CMD_ ## _field2, _value2, \
362 MC_CMD_ ## _field3, _value3, \
363 MC_CMD_ ## _field4, _value4, \
364 MC_CMD_ ## _field5, _value5, \
365 MC_CMD_ ## _field6, _value6, \
366 MC_CMD_ ## _field7, _value7, \
367 MC_CMD_ ## _field8, _value8, \
368 MC_CMD_ ## _field9, _value9, \
369 MC_CMD_ ## _field10, _value10)
371 #define MCDI_OUT(_emr, _type, _ofst) \
372 ((_type *)((_emr).emr_out_buf + (_ofst)))
374 #define MCDI_OUT2(_emr, _type, _ofst) \
375 MCDI_OUT(_emr, _type, MC_CMD_ ## _ofst ## _OFST)
377 #define MCDI_OUT_BYTE(_emr, _ofst) \
378 EFX_BYTE_FIELD(*MCDI_OUT2(_emr, efx_byte_t, _ofst), \
381 #define MCDI_OUT_WORD(_emr, _ofst) \
382 EFX_WORD_FIELD(*MCDI_OUT2(_emr, efx_word_t, _ofst), \
385 #define MCDI_OUT_WORD_FIELD(_emr, _ofst, _field) \
386 EFX_WORD_FIELD(*MCDI_OUT2(_emr, efx_word_t, _ofst), \
389 #define MCDI_OUT_DWORD(_emr, _ofst) \
390 EFX_DWORD_FIELD(*MCDI_OUT2(_emr, efx_dword_t, _ofst), \
393 #define MCDI_OUT_DWORD_FIELD(_emr, _ofst, _field) \
394 EFX_DWORD_FIELD(*MCDI_OUT2(_emr, efx_dword_t, _ofst), \
397 #define MCDI_EV_FIELD(_eqp, _field) \
398 EFX_QWORD_FIELD(*_eqp, MCDI_EVENT_ ## _field)
400 #define MCDI_CMD_DWORD_FIELD(_edp, _field) \
401 EFX_DWORD_FIELD(*_edp, MC_CMD_ ## _field)
403 #define EFX_MCDI_HAVE_PRIVILEGE(mask, priv) \
404 (((mask) & (MC_CMD_PRIVILEGE_MASK_IN_GRP_ ## priv)) == \
405 (MC_CMD_PRIVILEGE_MASK_IN_GRP_ ## priv))
407 typedef enum efx_mcdi_feature_id_e {
408 EFX_MCDI_FEATURE_FW_UPDATE = 0,
409 EFX_MCDI_FEATURE_LINK_CONTROL,
410 EFX_MCDI_FEATURE_MACADDR_CHANGE,
411 EFX_MCDI_FEATURE_MAC_SPOOFING,
412 EFX_MCDI_FEATURE_NIDS
413 } efx_mcdi_feature_id_t;
419 #endif /* _SYS_EFX_MCDI_H */