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$");
38 #if EFSYS_OPT_HUNTINGTON || EFSYS_OPT_MEDFORD
43 #error "WITH_MCDI_V2 required for EF10 MCDIv2 commands."
47 __checkReturn efx_rc_t
50 __in const efx_mcdi_transport_t *emtp)
52 efx_mcdi_iface_t *emip = &(enp->en_mcdi.em_emip);
53 efsys_mem_t *esmp = emtp->emt_dma_mem;
57 EFSYS_ASSERT(enp->en_family == EFX_FAMILY_HUNTINGTON ||
58 enp->en_family == EFX_FAMILY_MEDFORD);
59 EFSYS_ASSERT(enp->en_features & EFX_FEATURE_MCDI_DMA);
62 * All EF10 firmware supports MCDIv2 and MCDIv1.
63 * Medford BootROM supports MCDIv2 and MCDIv1.
64 * Huntington BootROM supports MCDIv1 only.
66 emip->emi_max_version = 2;
68 /* A host DMA buffer is required for EF10 MCDI */
75 * Ensure that the MC doorbell is in a known state before issuing MCDI
76 * commands. The recovery algorithm requires that the MC command buffer
77 * must be 256 byte aligned. See bug24769.
79 if ((EFSYS_MEM_ADDR(esmp) & 0xFF) != 0) {
83 EFX_POPULATE_DWORD_1(dword, EFX_DWORD_0, 1);
84 EFX_BAR_WRITED(enp, ER_DZ_MC_DB_HWRD_REG, &dword, B_FALSE);
86 /* Save initial MC reboot status */
87 (void) ef10_mcdi_poll_reboot(enp);
89 /* Start a new epoch (allow fresh MCDI requests to succeed) */
90 efx_mcdi_new_epoch(enp);
97 EFSYS_PROBE1(fail1, efx_rc_t, rc);
106 efx_mcdi_iface_t *emip = &(enp->en_mcdi.em_emip);
108 emip->emi_new_epoch = B_FALSE;
112 ef10_mcdi_send_request(
119 const efx_mcdi_transport_t *emtp = enp->en_mcdi.em_emtp;
120 efsys_mem_t *esmp = emtp->emt_dma_mem;
124 EFSYS_ASSERT(enp->en_family == EFX_FAMILY_HUNTINGTON ||
125 enp->en_family == EFX_FAMILY_MEDFORD);
127 /* Write the header */
128 for (pos = 0; pos < hdr_len; pos += sizeof (efx_dword_t)) {
129 dword = *(efx_dword_t *)((uint8_t *)hdrp + pos);
130 EFSYS_MEM_WRITED(esmp, pos, &dword);
133 /* Write the payload */
134 for (pos = 0; pos < sdu_len; pos += sizeof (efx_dword_t)) {
135 dword = *(efx_dword_t *)((uint8_t *)sdup + pos);
136 EFSYS_MEM_WRITED(esmp, hdr_len + pos, &dword);
139 /* Guarantee ordering of memory (MCDI request) and PIO (MC doorbell) */
140 EFSYS_DMA_SYNC_FOR_DEVICE(esmp, 0, hdr_len + sdu_len);
141 EFSYS_PIO_WRITE_BARRIER();
143 /* Ring the doorbell to post the command DMA address to the MC */
144 EFX_POPULATE_DWORD_1(dword, EFX_DWORD_0,
145 EFSYS_MEM_ADDR(esmp) >> 32);
146 EFX_BAR_WRITED(enp, ER_DZ_MC_DB_LWRD_REG, &dword, B_FALSE);
148 EFX_POPULATE_DWORD_1(dword, EFX_DWORD_0,
149 EFSYS_MEM_ADDR(esmp) & 0xffffffff);
150 EFX_BAR_WRITED(enp, ER_DZ_MC_DB_HWRD_REG, &dword, B_FALSE);
153 __checkReturn boolean_t
154 ef10_mcdi_poll_response(
157 const efx_mcdi_transport_t *emtp = enp->en_mcdi.em_emtp;
158 efsys_mem_t *esmp = emtp->emt_dma_mem;
161 EFSYS_MEM_READD(esmp, 0, &hdr);
162 return (EFX_DWORD_FIELD(hdr, MCDI_HEADER_RESPONSE) ? B_TRUE : B_FALSE);
166 ef10_mcdi_read_response(
168 __out_bcount(length) void *bufferp,
172 const efx_mcdi_transport_t *emtp = enp->en_mcdi.em_emtp;
173 efsys_mem_t *esmp = emtp->emt_dma_mem;
177 for (pos = 0; pos < length; pos += sizeof (efx_dword_t)) {
178 EFSYS_MEM_READD(esmp, offset + pos, &data);
179 memcpy((uint8_t *)bufferp + pos, &data,
180 MIN(sizeof (data), length - pos));
185 ef10_mcdi_poll_reboot(
188 efx_mcdi_iface_t *emip = &(enp->en_mcdi.em_emip);
194 old_status = emip->emi_mc_reboot_status;
196 /* Update MC reboot status word */
197 EFX_BAR_TBL_READD(enp, ER_DZ_BIU_MC_SFT_STATUS_REG, 0, &dword, B_FALSE);
198 new_status = dword.ed_u32[0];
200 /* MC has rebooted if the value has changed */
201 if (new_status != old_status) {
202 emip->emi_mc_reboot_status = new_status;
205 * FIXME: Ignore detected MC REBOOT for now.
207 * The Siena support for checking for MC reboot from status
208 * flags is broken - see comments in siena_mcdi_poll_reboot().
209 * As the generic MCDI code is shared the EF10 reboot
210 * detection suffers similar problems.
212 * Do not report an error when the boot status changes until
213 * this can be handled by common code drivers (and reworked to
214 * support Siena too).
225 EFSYS_PROBE1(fail1, efx_rc_t, rc);
230 __checkReturn efx_rc_t
231 ef10_mcdi_feature_supported(
233 __in efx_mcdi_feature_id_t id,
234 __out boolean_t *supportedp)
236 efx_nic_cfg_t *encp = &(enp->en_nic_cfg);
237 uint32_t privilege_mask = encp->enc_privilege_mask;
240 EFSYS_ASSERT(enp->en_family == EFX_FAMILY_HUNTINGTON ||
241 enp->en_family == EFX_FAMILY_MEDFORD);
244 * Use privilege mask state at MCDI attach.
248 case EFX_MCDI_FEATURE_FW_UPDATE:
250 * Admin privilege must be used prior to introduction of
254 EFX_MCDI_HAVE_PRIVILEGE(privilege_mask, ADMIN);
256 case EFX_MCDI_FEATURE_LINK_CONTROL:
258 * Admin privilege used prior to introduction of
262 EFX_MCDI_HAVE_PRIVILEGE(privilege_mask, LINK) ||
263 EFX_MCDI_HAVE_PRIVILEGE(privilege_mask, ADMIN);
265 case EFX_MCDI_FEATURE_MACADDR_CHANGE:
267 * Admin privilege must be used prior to introduction of
268 * mac spoofing privilege (at v4.6), which is used up to
269 * introduction of change mac spoofing privilege (at v4.7)
272 EFX_MCDI_HAVE_PRIVILEGE(privilege_mask, CHANGE_MAC) ||
273 EFX_MCDI_HAVE_PRIVILEGE(privilege_mask, MAC_SPOOFING) ||
274 EFX_MCDI_HAVE_PRIVILEGE(privilege_mask, ADMIN);
276 case EFX_MCDI_FEATURE_MAC_SPOOFING:
278 * Admin privilege must be used prior to introduction of
279 * mac spoofing privilege (at v4.6), which is used up to
280 * introduction of mac spoofing TX privilege (at v4.7)
283 EFX_MCDI_HAVE_PRIVILEGE(privilege_mask, MAC_SPOOFING_TX) ||
284 EFX_MCDI_HAVE_PRIVILEGE(privilege_mask, MAC_SPOOFING) ||
285 EFX_MCDI_HAVE_PRIVILEGE(privilege_mask, ADMIN);
296 EFSYS_PROBE1(fail1, efx_rc_t, rc);
301 #endif /* EFSYS_OPT_MCDI */
303 #endif /* EFSYS_OPT_HUNTINGTON || EFSYS_OPT_MEDFORD */