2 * Copyright (c) 2012-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.
31 #include <sys/cdefs.h>
32 __FBSDID("$FreeBSD$");
39 #if EFSYS_OPT_HUNTINGTON || EFSYS_OPT_MEDFORD
44 #error "WITH_MCDI_V2 required for EF10 MCDIv2 commands."
47 typedef enum efx_mcdi_header_type_e {
48 EFX_MCDI_HEADER_TYPE_V1, /* MCDIv0 (BootROM), MCDIv1 commands */
49 EFX_MCDI_HEADER_TYPE_V2, /* MCDIv2 commands */
50 } efx_mcdi_header_type_t;
53 * Return the header format to use for sending an MCDI request.
55 * An MCDIv1 (Siena compatible) command should use MCDIv2 encapsulation if the
56 * request input buffer or response output buffer are too large for the MCDIv1
57 * format. An MCDIv2 command must always be sent using MCDIv2 encapsulation.
59 #define EFX_MCDI_HEADER_TYPE(_cmd, _length) \
60 ((((_cmd) & ~EFX_MASK32(MCDI_HEADER_CODE)) || \
61 ((_length) & ~EFX_MASK32(MCDI_HEADER_DATALEN))) ? \
62 EFX_MCDI_HEADER_TYPE_V2 : EFX_MCDI_HEADER_TYPE_V1)
66 * MCDI Header NOT_EPOCH flag
67 * ==========================
68 * A new epoch begins at initial startup or after an MC reboot, and defines when
69 * the MC should reject stale MCDI requests.
71 * The first MCDI request sent by the host should contain NOT_EPOCH=0, and all
72 * subsequent requests (until the next MC reboot) should contain NOT_EPOCH=1.
74 * After rebooting the MC will fail all requests with NOT_EPOCH=1 by writing a
75 * response with ERROR=1 and DATALEN=0 until a request is seen with NOT_EPOCH=0.
79 __checkReturn efx_rc_t
82 __in const efx_mcdi_transport_t *emtp)
84 efx_mcdi_iface_t *emip = &(enp->en_mcdi.em_emip);
85 efsys_mem_t *esmp = emtp->emt_dma_mem;
89 EFSYS_ASSERT(enp->en_family == EFX_FAMILY_HUNTINGTON ||
90 enp->en_family == EFX_FAMILY_MEDFORD);
91 EFSYS_ASSERT(enp->en_features & EFX_FEATURE_MCDI_DMA);
94 * All EF10 firmware supports MCDIv2 and MCDIv1.
95 * Medford BootROM supports MCDIv2 and MCDIv1.
96 * Huntington BootROM supports MCDIv1 only.
98 emip->emi_max_version = 2;
100 /* A host DMA buffer is required for EF10 MCDI */
107 * Ensure that the MC doorbell is in a known state before issuing MCDI
108 * commands. The recovery algorithm requires that the MC command buffer
109 * must be 256 byte aligned. See bug24769.
111 if ((EFSYS_MEM_ADDR(esmp) & 0xFF) != 0) {
115 EFX_POPULATE_DWORD_1(dword, EFX_DWORD_0, 1);
116 EFX_BAR_WRITED(enp, ER_DZ_MC_DB_HWRD_REG, &dword, B_FALSE);
118 /* Save initial MC reboot status */
119 (void) ef10_mcdi_poll_reboot(enp);
121 /* Start a new epoch (allow fresh MCDI requests to succeed) */
122 efx_mcdi_new_epoch(enp);
129 EFSYS_PROBE1(fail1, efx_rc_t, rc);
138 efx_mcdi_iface_t *emip = &(enp->en_mcdi.em_emip);
140 emip->emi_new_epoch = B_FALSE;
144 ef10_mcdi_request_copyin(
146 __in efx_mcdi_req_t *emrp,
147 __in unsigned int seq,
148 __in boolean_t ev_cpl,
149 __in boolean_t new_epoch)
151 const efx_mcdi_transport_t *emtp = enp->en_mcdi.em_emtp;
152 efsys_mem_t *esmp = emtp->emt_dma_mem;
153 efx_mcdi_header_type_t hdr_type;
160 EFSYS_ASSERT(enp->en_family == EFX_FAMILY_HUNTINGTON ||
161 enp->en_family == EFX_FAMILY_MEDFORD);
165 xflags |= MCDI_HEADER_XFLAGS_EVREQ;
169 hdr_type = EFX_MCDI_HEADER_TYPE(emrp->emr_cmd,
170 MAX(emrp->emr_in_length, emrp->emr_out_length));
172 if (hdr_type == EFX_MCDI_HEADER_TYPE_V2) {
173 /* Construct MCDI v2 header */
174 EFX_POPULATE_DWORD_8(hdr[0],
175 MCDI_HEADER_CODE, MC_CMD_V2_EXTN,
176 MCDI_HEADER_RESYNC, 1,
177 MCDI_HEADER_DATALEN, 0,
178 MCDI_HEADER_SEQ, seq,
179 MCDI_HEADER_NOT_EPOCH, new_epoch ? 0 : 1,
180 MCDI_HEADER_ERROR, 0,
181 MCDI_HEADER_RESPONSE, 0,
182 MCDI_HEADER_XFLAGS, xflags);
183 EFSYS_MEM_WRITED(esmp, offset, &hdr[0]);
184 offset += sizeof (efx_dword_t);
186 EFX_POPULATE_DWORD_2(hdr[1],
187 MC_CMD_V2_EXTN_IN_EXTENDED_CMD, emrp->emr_cmd,
188 MC_CMD_V2_EXTN_IN_ACTUAL_LEN, emrp->emr_in_length);
189 EFSYS_MEM_WRITED(esmp, offset, &hdr[1]);
190 offset += sizeof (efx_dword_t);
192 /* Construct MCDI v1 header */
193 EFX_POPULATE_DWORD_8(hdr[0],
194 MCDI_HEADER_CODE, emrp->emr_cmd,
195 MCDI_HEADER_RESYNC, 1,
196 MCDI_HEADER_DATALEN, emrp->emr_in_length,
197 MCDI_HEADER_SEQ, seq,
198 MCDI_HEADER_NOT_EPOCH, new_epoch ? 0 : 1,
199 MCDI_HEADER_ERROR, 0,
200 MCDI_HEADER_RESPONSE, 0,
201 MCDI_HEADER_XFLAGS, xflags);
202 EFSYS_MEM_WRITED(esmp, 0, &hdr[0]);
203 offset += sizeof (efx_dword_t);
206 #if EFSYS_OPT_MCDI_LOGGING
207 if (emtp->emt_logger != NULL) {
208 emtp->emt_logger(emtp->emt_context, EFX_LOG_MCDI_REQUEST,
210 emrp->emr_in_buf, emrp->emr_in_length);
212 #endif /* EFSYS_OPT_MCDI_LOGGING */
214 /* Construct the payload */
215 for (pos = 0; pos < emrp->emr_in_length; pos += sizeof (efx_dword_t)) {
216 memcpy(&dword, MCDI_IN(*emrp, efx_dword_t, pos),
217 MIN(sizeof (dword), emrp->emr_in_length - pos));
218 EFSYS_MEM_WRITED(esmp, offset + pos, &dword);
221 /* Ring the doorbell to post the command DMA address to the MC */
222 EFSYS_ASSERT((EFSYS_MEM_ADDR(esmp) & 0xFF) == 0);
224 /* Guarantee ordering of memory (MCDI request) and PIO (MC doorbell) */
225 EFSYS_DMA_SYNC_FOR_DEVICE(esmp, 0, offset + emrp->emr_in_length);
226 EFSYS_PIO_WRITE_BARRIER();
228 EFX_POPULATE_DWORD_1(dword,
229 EFX_DWORD_0, EFSYS_MEM_ADDR(esmp) >> 32);
230 EFX_BAR_WRITED(enp, ER_DZ_MC_DB_LWRD_REG, &dword, B_FALSE);
232 EFX_POPULATE_DWORD_1(dword,
233 EFX_DWORD_0, EFSYS_MEM_ADDR(esmp) & 0xffffffff);
234 EFX_BAR_WRITED(enp, ER_DZ_MC_DB_HWRD_REG, &dword, B_FALSE);
238 ef10_mcdi_request_copyout(
240 __in efx_mcdi_req_t *emrp)
242 #if EFSYS_OPT_MCDI_LOGGING
243 const efx_mcdi_transport_t *emtp = enp->en_mcdi.em_emtp;
244 #endif /* EFSYS_OPT_MCDI_LOGGING */
246 unsigned int hdr_len;
249 if (emrp->emr_out_buf == NULL)
252 /* Read the command header to detect MCDI response format */
253 hdr_len = sizeof (hdr[0]);
254 ef10_mcdi_read_response(enp, &hdr[0], 0, hdr_len);
255 if (EFX_DWORD_FIELD(hdr[0], MCDI_HEADER_CODE) == MC_CMD_V2_EXTN) {
257 * Read the actual payload length. The length given in the event
258 * is only correct for responses with the V1 format.
260 ef10_mcdi_read_response(enp, &hdr[1], hdr_len, sizeof (hdr[1]));
261 hdr_len += sizeof (hdr[1]);
263 emrp->emr_out_length_used = EFX_DWORD_FIELD(hdr[1],
264 MC_CMD_V2_EXTN_IN_ACTUAL_LEN);
267 /* Copy payload out into caller supplied buffer */
268 bytes = MIN(emrp->emr_out_length_used, emrp->emr_out_length);
269 ef10_mcdi_read_response(enp, emrp->emr_out_buf, hdr_len, bytes);
271 #if EFSYS_OPT_MCDI_LOGGING
272 if (emtp->emt_logger != NULL) {
273 emtp->emt_logger(emtp->emt_context,
274 EFX_LOG_MCDI_RESPONSE,
276 emrp->emr_out_buf, bytes);
278 #endif /* EFSYS_OPT_MCDI_LOGGING */
281 __checkReturn boolean_t
282 ef10_mcdi_poll_response(
285 const efx_mcdi_transport_t *emtp = enp->en_mcdi.em_emtp;
286 efsys_mem_t *esmp = emtp->emt_dma_mem;
289 EFSYS_MEM_READD(esmp, 0, &hdr);
290 return (EFX_DWORD_FIELD(hdr, MCDI_HEADER_RESPONSE) ? B_TRUE : B_FALSE);
294 ef10_mcdi_read_response(
300 const efx_mcdi_transport_t *emtp = enp->en_mcdi.em_emtp;
301 efsys_mem_t *esmp = emtp->emt_dma_mem;
305 for (pos = 0; pos < length; pos += sizeof (efx_dword_t)) {
306 EFSYS_MEM_READD(esmp, offset + pos, &data);
307 memcpy((uint8_t *)bufferp + pos, &data,
308 MIN(sizeof (data), length - pos));
313 ef10_mcdi_poll_reboot(
316 efx_mcdi_iface_t *emip = &(enp->en_mcdi.em_emip);
322 old_status = emip->emi_mc_reboot_status;
324 /* Update MC reboot status word */
325 EFX_BAR_TBL_READD(enp, ER_DZ_BIU_MC_SFT_STATUS_REG, 0, &dword, B_FALSE);
326 new_status = dword.ed_u32[0];
328 /* MC has rebooted if the value has changed */
329 if (new_status != old_status) {
330 emip->emi_mc_reboot_status = new_status;
333 * FIXME: Ignore detected MC REBOOT for now.
335 * The Siena support for checking for MC reboot from status
336 * flags is broken - see comments in siena_mcdi_poll_reboot().
337 * As the generic MCDI code is shared the EF10 reboot
338 * detection suffers similar problems.
340 * Do not report an error when the boot status changes until
341 * this can be handled by common code drivers (and reworked to
342 * support Siena too).
353 EFSYS_PROBE1(fail1, efx_rc_t, rc);
358 __checkReturn efx_rc_t
359 ef10_mcdi_feature_supported(
361 __in efx_mcdi_feature_id_t id,
362 __out boolean_t *supportedp)
364 efx_nic_cfg_t *encp = &(enp->en_nic_cfg);
365 uint32_t privilege_mask = encp->enc_privilege_mask;
368 EFSYS_ASSERT(enp->en_family == EFX_FAMILY_HUNTINGTON ||
369 enp->en_family == EFX_FAMILY_MEDFORD);
372 * Use privilege mask state at MCDI attach.
376 case EFX_MCDI_FEATURE_FW_UPDATE:
378 * Admin privilege must be used prior to introduction of
382 EFX_MCDI_HAVE_PRIVILEGE(privilege_mask, ADMIN);
384 case EFX_MCDI_FEATURE_LINK_CONTROL:
386 * Admin privilege used prior to introduction of
390 EFX_MCDI_HAVE_PRIVILEGE(privilege_mask, LINK) ||
391 EFX_MCDI_HAVE_PRIVILEGE(privilege_mask, ADMIN);
393 case EFX_MCDI_FEATURE_MACADDR_CHANGE:
395 * Admin privilege must be used prior to introduction of
396 * mac spoofing privilege (at v4.6), which is used up to
397 * introduction of change mac spoofing privilege (at v4.7)
400 EFX_MCDI_HAVE_PRIVILEGE(privilege_mask, CHANGE_MAC) ||
401 EFX_MCDI_HAVE_PRIVILEGE(privilege_mask, MAC_SPOOFING) ||
402 EFX_MCDI_HAVE_PRIVILEGE(privilege_mask, ADMIN);
404 case EFX_MCDI_FEATURE_MAC_SPOOFING:
406 * Admin privilege must be used prior to introduction of
407 * mac spoofing privilege (at v4.6), which is used up to
408 * introduction of mac spoofing TX privilege (at v4.7)
411 EFX_MCDI_HAVE_PRIVILEGE(privilege_mask, MAC_SPOOFING_TX) ||
412 EFX_MCDI_HAVE_PRIVILEGE(privilege_mask, MAC_SPOOFING) ||
413 EFX_MCDI_HAVE_PRIVILEGE(privilege_mask, ADMIN);
424 EFSYS_PROBE1(fail1, efx_rc_t, rc);
429 #endif /* EFSYS_OPT_MCDI */
431 #endif /* EFSYS_OPT_HUNTINGTON || EFSYS_OPT_MEDFORD */