2 * Copyright (c) 2009-2015 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.
33 #ifndef _SYS_EFX_MCDI_H
34 #define _SYS_EFX_MCDI_H
38 #include "efx_regs_mcdi.h"
45 * A reboot/assertion causes the MCDI status word to be set after the
46 * command word is set or a REBOOT event is sent. If we notice a reboot
47 * via these mechanisms then wait 10ms for the status word to be set.
49 #define EFX_MCDI_STATUS_SLEEP_US 10000
51 struct efx_mcdi_req_s {
53 /* Inputs: Command #, input buffer and length */
57 /* Outputs: retcode, buffer, length, and length used*/
60 size_t emr_out_length;
61 size_t emr_out_length_used;
64 typedef struct efx_mcdi_iface_s {
65 unsigned int emi_port;
67 efx_mcdi_req_t *emi_pending_req;
69 boolean_t emi_new_epoch;
71 uint32_t emi_poll_cnt;
72 uint32_t emi_mc_reboot_status;
78 __inout efx_mcdi_req_t *emrp);
81 efx_mcdi_execute_quiet(
83 __inout efx_mcdi_req_t *emrp);
88 __in unsigned int seq,
89 __in unsigned int outlen,
97 extern __checkReturn int
98 efx_mcdi_request_errcode(
99 __in unsigned int err);
102 efx_mcdi_raise_exception(
104 __in_opt efx_mcdi_req_t *emrp,
107 typedef enum efx_mcdi_boot_e {
108 EFX_MCDI_BOOT_PRIMARY,
109 EFX_MCDI_BOOT_SECONDARY,
113 extern __checkReturn int
116 __out_ecount_opt(4) uint16_t versionp[4],
117 __out_opt uint32_t *buildp,
118 __out_opt efx_mcdi_boot_t *statusp);
120 extern __checkReturn int
121 efx_mcdi_read_assertion(
122 __in efx_nic_t *enp);
124 extern __checkReturn int
125 efx_mcdi_exit_assertion_handler(
126 __in efx_nic_t *enp);
128 extern __checkReturn int
131 __in boolean_t attach);
133 extern __checkReturn int
134 efx_mcdi_get_board_cfg(
136 __out_opt uint32_t *board_typep,
137 __out_opt efx_dword_t *capabilitiesp,
138 __out_ecount_opt(6) uint8_t mac_addrp[6]);
140 extern __checkReturn int
141 efx_mcdi_get_phy_cfg(
142 __in efx_nic_t *enp);
144 extern __checkReturn int
145 efx_mcdi_firmware_update_supported(
147 __out boolean_t *supportedp);
149 extern __checkReturn int
150 efx_mcdi_macaddr_change_supported(
152 __out boolean_t *supportedp);
155 #if EFSYS_OPT_HUNTINGTON
156 extern __checkReturn int
157 efx_mcdi_bist_enable_offline(
158 __in efx_nic_t *enp);
159 #endif /* EFSYS_OPT_HUNTINGTON */
160 extern __checkReturn int
163 __in efx_bist_type_t type);
164 #endif /* EFSYS_OPT_BIST */
166 extern __checkReturn int
167 efx_mcdi_get_resource_limits(
169 __out_opt uint32_t *nevqp,
170 __out_opt uint32_t *nrxqp,
171 __out_opt uint32_t *ntxqp);
173 extern __checkReturn int
175 __in efx_nic_t *enp);
177 extern __checkReturn int
178 efx_mcdi_mac_stats_clear(
179 __in efx_nic_t *enp);
181 extern __checkReturn int
182 efx_mcdi_mac_stats_upload(
184 __in efsys_mem_t *esmp);
186 extern __checkReturn int
187 efx_mcdi_mac_stats_periodic(
189 __in efsys_mem_t *esmp,
190 __in uint16_t period,
191 __in boolean_t events);
194 #if EFSYS_OPT_LOOPBACK
195 extern __checkReturn int
196 efx_mcdi_get_loopback_modes(
197 __in efx_nic_t *enp);
198 #endif /* EFSYS_OPT_LOOPBACK */
200 #define MCDI_IN(_emr, _type, _ofst) \
201 ((_type *)((_emr).emr_in_buf + (_ofst)))
203 #define MCDI_IN2(_emr, _type, _ofst) \
204 MCDI_IN(_emr, _type, MC_CMD_ ## _ofst ## _OFST)
206 #define MCDI_IN_SET_BYTE(_emr, _ofst, _value) \
207 EFX_POPULATE_BYTE_1(*MCDI_IN2(_emr, efx_byte_t, _ofst), \
210 #define MCDI_IN_SET_WORD(_emr, _ofst, _value) \
211 EFX_POPULATE_WORD_1(*MCDI_IN2(_emr, efx_word_t, _ofst), \
214 #define MCDI_IN_SET_DWORD(_emr, _ofst, _value) \
215 EFX_POPULATE_DWORD_1(*MCDI_IN2(_emr, efx_dword_t, _ofst), \
218 #define MCDI_IN_SET_DWORD_FIELD(_emr, _ofst, _field, _value) \
219 EFX_SET_DWORD_FIELD(*MCDI_IN2(_emr, efx_dword_t, _ofst), \
220 MC_CMD_ ## _field, _value)
222 #define MCDI_IN_POPULATE_DWORD_1(_emr, _ofst, _field1, _value1) \
223 EFX_POPULATE_DWORD_1(*MCDI_IN2(_emr, efx_dword_t, _ofst), \
224 MC_CMD_ ## _field1, _value1)
226 #define MCDI_IN_POPULATE_DWORD_2(_emr, _ofst, _field1, _value1, \
228 EFX_POPULATE_DWORD_2(*MCDI_IN2(_emr, efx_dword_t, _ofst), \
229 MC_CMD_ ## _field1, _value1, \
230 MC_CMD_ ## _field2, _value2)
232 #define MCDI_IN_POPULATE_DWORD_3(_emr, _ofst, _field1, _value1, \
233 _field2, _value2, _field3, _value3) \
234 EFX_POPULATE_DWORD_3(*MCDI_IN2(_emr, efx_dword_t, _ofst), \
235 MC_CMD_ ## _field1, _value1, \
236 MC_CMD_ ## _field2, _value2, \
237 MC_CMD_ ## _field3, _value3)
239 #define MCDI_IN_POPULATE_DWORD_4(_emr, _ofst, _field1, _value1, \
240 _field2, _value2, _field3, _value3, _field4, _value4) \
241 EFX_POPULATE_DWORD_4(*MCDI_IN2(_emr, efx_dword_t, _ofst), \
242 MC_CMD_ ## _field1, _value1, \
243 MC_CMD_ ## _field2, _value2, \
244 MC_CMD_ ## _field3, _value3, \
245 MC_CMD_ ## _field4, _value4)
247 #define MCDI_IN_POPULATE_DWORD_5(_emr, _ofst, _field1, _value1, \
248 _field2, _value2, _field3, _value3, _field4, _value4, \
250 EFX_POPULATE_DWORD_5(*MCDI_IN2(_emr, efx_dword_t, _ofst), \
251 MC_CMD_ ## _field1, _value1, \
252 MC_CMD_ ## _field2, _value2, \
253 MC_CMD_ ## _field3, _value3, \
254 MC_CMD_ ## _field4, _value4, \
255 MC_CMD_ ## _field5, _value5)
257 #define MCDI_IN_POPULATE_DWORD_6(_emr, _ofst, _field1, _value1, \
258 _field2, _value2, _field3, _value3, _field4, _value4, \
259 _field5, _value5, _field6, _value6) \
260 EFX_POPULATE_DWORD_6(*MCDI_IN2(_emr, efx_dword_t, _ofst), \
261 MC_CMD_ ## _field1, _value1, \
262 MC_CMD_ ## _field2, _value2, \
263 MC_CMD_ ## _field3, _value3, \
264 MC_CMD_ ## _field4, _value4, \
265 MC_CMD_ ## _field5, _value5, \
266 MC_CMD_ ## _field6, _value6)
268 #define MCDI_IN_POPULATE_DWORD_7(_emr, _ofst, _field1, _value1, \
269 _field2, _value2, _field3, _value3, _field4, _value4, \
270 _field5, _value5, _field6, _value6, _field7, _value7) \
271 EFX_POPULATE_DWORD_7(*MCDI_IN2(_emr, efx_dword_t, _ofst), \
272 MC_CMD_ ## _field1, _value1, \
273 MC_CMD_ ## _field2, _value2, \
274 MC_CMD_ ## _field3, _value3, \
275 MC_CMD_ ## _field4, _value4, \
276 MC_CMD_ ## _field5, _value5, \
277 MC_CMD_ ## _field6, _value6, \
278 MC_CMD_ ## _field7, _value7)
280 #define MCDI_IN_POPULATE_DWORD_8(_emr, _ofst, _field1, _value1, \
281 _field2, _value2, _field3, _value3, _field4, _value4, \
282 _field5, _value5, _field6, _value6, _field7, _value7, \
284 EFX_POPULATE_DWORD_8(*MCDI_IN2(_emr, efx_dword_t, _ofst), \
285 MC_CMD_ ## _field1, _value1, \
286 MC_CMD_ ## _field2, _value2, \
287 MC_CMD_ ## _field3, _value3, \
288 MC_CMD_ ## _field4, _value4, \
289 MC_CMD_ ## _field5, _value5, \
290 MC_CMD_ ## _field6, _value6, \
291 MC_CMD_ ## _field7, _value7, \
292 MC_CMD_ ## _field8, _value8)
294 #define MCDI_IN_POPULATE_DWORD_9(_emr, _ofst, _field1, _value1, \
295 _field2, _value2, _field3, _value3, _field4, _value4, \
296 _field5, _value5, _field6, _value6, _field7, _value7, \
297 _field8, _value8, _field9, _value9) \
298 EFX_POPULATE_DWORD_9(*MCDI_IN2(_emr, efx_dword_t, _ofst), \
299 MC_CMD_ ## _field1, _value1, \
300 MC_CMD_ ## _field2, _value2, \
301 MC_CMD_ ## _field3, _value3, \
302 MC_CMD_ ## _field4, _value4, \
303 MC_CMD_ ## _field5, _value5, \
304 MC_CMD_ ## _field6, _value6, \
305 MC_CMD_ ## _field7, _value7, \
306 MC_CMD_ ## _field8, _value8, \
307 MC_CMD_ ## _field9, _value9)
309 #define MCDI_IN_POPULATE_DWORD_10(_emr, _ofst, _field1, _value1, \
310 _field2, _value2, _field3, _value3, _field4, _value4, \
311 _field5, _value5, _field6, _value6, _field7, _value7, \
312 _field8, _value8, _field9, _value9, _field10, _value10) \
313 EFX_POPULATE_DWORD_10(*MCDI_IN2(_emr, efx_dword_t, _ofst), \
314 MC_CMD_ ## _field1, _value1, \
315 MC_CMD_ ## _field2, _value2, \
316 MC_CMD_ ## _field3, _value3, \
317 MC_CMD_ ## _field4, _value4, \
318 MC_CMD_ ## _field5, _value5, \
319 MC_CMD_ ## _field6, _value6, \
320 MC_CMD_ ## _field7, _value7, \
321 MC_CMD_ ## _field8, _value8, \
322 MC_CMD_ ## _field9, _value9, \
323 MC_CMD_ ## _field10, _value10)
325 #define MCDI_OUT(_emr, _type, _ofst) \
326 ((_type *)((_emr).emr_out_buf + (_ofst)))
328 #define MCDI_OUT2(_emr, _type, _ofst) \
329 MCDI_OUT(_emr, _type, MC_CMD_ ## _ofst ## _OFST)
331 #define MCDI_OUT_BYTE(_emr, _ofst) \
332 EFX_BYTE_FIELD(*MCDI_OUT2(_emr, efx_byte_t, _ofst), \
335 #define MCDI_OUT_WORD(_emr, _ofst) \
336 EFX_WORD_FIELD(*MCDI_OUT2(_emr, efx_word_t, _ofst), \
339 #define MCDI_OUT_DWORD(_emr, _ofst) \
340 EFX_DWORD_FIELD(*MCDI_OUT2(_emr, efx_dword_t, _ofst), \
343 #define MCDI_OUT_DWORD_FIELD(_emr, _ofst, _field) \
344 EFX_DWORD_FIELD(*MCDI_OUT2(_emr, efx_dword_t, _ofst), \
347 #define MCDI_EV_FIELD(_eqp, _field) \
348 EFX_QWORD_FIELD(*_eqp, MCDI_EVENT_ ## _field)
350 #define MCDI_CMD_DWORD_FIELD(_edp, _field) \
351 EFX_DWORD_FIELD(*_edp, MC_CMD_ ## _field)
357 #endif /* _SYS_EFX_MCDI_H */