1 /* SPDX-License-Identifier: BSD-3-Clause
3 * Copyright (c) 2012-2018 Solarflare Communications Inc.
11 #if EFSYS_OPT_HUNTINGTON || EFSYS_OPT_MEDFORD || EFSYS_OPT_MEDFORD2
16 #error "WITH_MCDI_V2 required for EF10 MCDIv2 commands."
20 __checkReturn efx_rc_t
23 __in const efx_mcdi_transport_t *emtp)
25 efx_mcdi_iface_t *emip = &(enp->en_mcdi.em_emip);
26 efsys_mem_t *esmp = emtp->emt_dma_mem;
30 EFSYS_ASSERT(enp->en_family == EFX_FAMILY_HUNTINGTON ||
31 enp->en_family == EFX_FAMILY_MEDFORD ||
32 enp->en_family == EFX_FAMILY_MEDFORD2);
33 EFSYS_ASSERT(enp->en_features & EFX_FEATURE_MCDI_DMA);
36 * All EF10 firmware supports MCDIv2 and MCDIv1.
37 * Medford BootROM supports MCDIv2 and MCDIv1.
38 * Huntington BootROM supports MCDIv1 only.
40 emip->emi_max_version = 2;
42 /* A host DMA buffer is required for EF10 MCDI */
49 * Ensure that the MC doorbell is in a known state before issuing MCDI
50 * commands. The recovery algorithm requires that the MC command buffer
51 * must be 256 byte aligned. See bug24769.
53 if ((EFSYS_MEM_ADDR(esmp) & 0xFF) != 0) {
57 EFX_POPULATE_DWORD_1(dword, EFX_DWORD_0, 1);
58 EFX_BAR_WRITED(enp, ER_DZ_MC_DB_HWRD_REG, &dword, B_FALSE);
60 /* Save initial MC reboot status */
61 (void) ef10_mcdi_poll_reboot(enp);
63 /* Start a new epoch (allow fresh MCDI requests to succeed) */
64 efx_mcdi_new_epoch(enp);
71 EFSYS_PROBE1(fail1, efx_rc_t, rc);
80 efx_mcdi_iface_t *emip = &(enp->en_mcdi.em_emip);
82 emip->emi_new_epoch = B_FALSE;
86 * In older firmware all commands are processed in a single thread, so a long
87 * running command for one PCIe function can block processing for another
88 * function (see bug 61269).
90 * In newer firmware that supports multithreaded MCDI processing, we can extend
91 * the timeout for long-running requests which we know firmware may choose to
92 * process in a background thread.
94 #define EF10_MCDI_CMD_TIMEOUT_US (10 * 1000 * 1000)
95 #define EF10_MCDI_CMD_LONG_TIMEOUT_US (60 * 1000 * 1000)
98 ef10_mcdi_get_timeout(
100 __in efx_mcdi_req_t *emrp,
101 __out uint32_t *timeoutp)
103 efx_nic_cfg_t *encp = &(enp->en_nic_cfg);
105 switch (emrp->emr_cmd) {
106 case MC_CMD_POLL_BIST:
107 case MC_CMD_NVRAM_ERASE:
108 case MC_CMD_LICENSING_V3:
109 case MC_CMD_NVRAM_UPDATE_FINISH:
110 if (encp->enc_nvram_update_verify_result_supported != B_FALSE) {
112 * Potentially longer running commands, which firmware
113 * may choose to process in a background thread.
115 *timeoutp = EF10_MCDI_CMD_LONG_TIMEOUT_US;
120 *timeoutp = EF10_MCDI_CMD_TIMEOUT_US;
126 ef10_mcdi_send_request(
128 __in_bcount(hdr_len) void *hdrp,
130 __in_bcount(sdu_len) void *sdup,
133 const efx_mcdi_transport_t *emtp = enp->en_mcdi.em_emtp;
134 efsys_mem_t *esmp = emtp->emt_dma_mem;
138 EFSYS_ASSERT(enp->en_family == EFX_FAMILY_HUNTINGTON ||
139 enp->en_family == EFX_FAMILY_MEDFORD ||
140 enp->en_family == EFX_FAMILY_MEDFORD2);
142 /* Write the header */
143 for (pos = 0; pos < hdr_len; pos += sizeof (efx_dword_t)) {
144 dword = *(efx_dword_t *)((uint8_t *)hdrp + pos);
145 EFSYS_MEM_WRITED(esmp, pos, &dword);
148 /* Write the payload */
149 for (pos = 0; pos < sdu_len; pos += sizeof (efx_dword_t)) {
150 dword = *(efx_dword_t *)((uint8_t *)sdup + pos);
151 EFSYS_MEM_WRITED(esmp, hdr_len + pos, &dword);
154 /* Guarantee ordering of memory (MCDI request) and PIO (MC doorbell) */
155 EFSYS_DMA_SYNC_FOR_DEVICE(esmp, 0, hdr_len + sdu_len);
156 EFSYS_PIO_WRITE_BARRIER();
158 /* Ring the doorbell to post the command DMA address to the MC */
159 EFX_POPULATE_DWORD_1(dword, EFX_DWORD_0,
160 EFSYS_MEM_ADDR(esmp) >> 32);
161 EFX_BAR_WRITED(enp, ER_DZ_MC_DB_LWRD_REG, &dword, B_FALSE);
163 EFX_POPULATE_DWORD_1(dword, EFX_DWORD_0,
164 EFSYS_MEM_ADDR(esmp) & 0xffffffff);
165 EFX_BAR_WRITED(enp, ER_DZ_MC_DB_HWRD_REG, &dword, B_FALSE);
168 __checkReturn boolean_t
169 ef10_mcdi_poll_response(
172 const efx_mcdi_transport_t *emtp = enp->en_mcdi.em_emtp;
173 efsys_mem_t *esmp = emtp->emt_dma_mem;
176 EFSYS_MEM_READD(esmp, 0, &hdr);
177 EFSYS_MEM_READ_BARRIER();
179 return (EFX_DWORD_FIELD(hdr, MCDI_HEADER_RESPONSE) ? B_TRUE : B_FALSE);
183 ef10_mcdi_read_response(
185 __out_bcount(length) void *bufferp,
189 const efx_mcdi_transport_t *emtp = enp->en_mcdi.em_emtp;
190 efsys_mem_t *esmp = emtp->emt_dma_mem;
194 for (pos = 0; pos < length; pos += sizeof (efx_dword_t)) {
195 EFSYS_MEM_READD(esmp, offset + pos, &data);
196 memcpy((uint8_t *)bufferp + pos, &data,
197 MIN(sizeof (data), length - pos));
202 ef10_mcdi_poll_reboot(
205 efx_mcdi_iface_t *emip = &(enp->en_mcdi.em_emip);
211 old_status = emip->emi_mc_reboot_status;
213 /* Update MC reboot status word */
214 EFX_BAR_TBL_READD(enp, ER_DZ_BIU_MC_SFT_STATUS_REG, 0, &dword, B_FALSE);
215 new_status = dword.ed_u32[0];
217 /* MC has rebooted if the value has changed */
218 if (new_status != old_status) {
219 emip->emi_mc_reboot_status = new_status;
222 * FIXME: Ignore detected MC REBOOT for now.
224 * The Siena support for checking for MC reboot from status
225 * flags is broken - see comments in siena_mcdi_poll_reboot().
226 * As the generic MCDI code is shared the EF10 reboot
227 * detection suffers similar problems.
229 * Do not report an error when the boot status changes until
230 * this can be handled by common code drivers (and reworked to
231 * support Siena too).
233 _NOTE(CONSTANTCONDITION)
243 EFSYS_PROBE1(fail1, efx_rc_t, rc);
248 __checkReturn efx_rc_t
249 ef10_mcdi_feature_supported(
251 __in efx_mcdi_feature_id_t id,
252 __out boolean_t *supportedp)
254 efx_nic_cfg_t *encp = &(enp->en_nic_cfg);
255 uint32_t privilege_mask = encp->enc_privilege_mask;
258 EFSYS_ASSERT(enp->en_family == EFX_FAMILY_HUNTINGTON ||
259 enp->en_family == EFX_FAMILY_MEDFORD ||
260 enp->en_family == EFX_FAMILY_MEDFORD2);
263 * Use privilege mask state at MCDI attach.
267 case EFX_MCDI_FEATURE_FW_UPDATE:
269 * Admin privilege must be used prior to introduction of
273 EFX_MCDI_HAVE_PRIVILEGE(privilege_mask, ADMIN);
275 case EFX_MCDI_FEATURE_LINK_CONTROL:
277 * Admin privilege used prior to introduction of
281 EFX_MCDI_HAVE_PRIVILEGE(privilege_mask, LINK) ||
282 EFX_MCDI_HAVE_PRIVILEGE(privilege_mask, ADMIN);
284 case EFX_MCDI_FEATURE_MACADDR_CHANGE:
286 * Admin privilege must be used prior to introduction of
287 * mac spoofing privilege (at v4.6), which is used up to
288 * introduction of change mac spoofing privilege (at v4.7)
291 EFX_MCDI_HAVE_PRIVILEGE(privilege_mask, CHANGE_MAC) ||
292 EFX_MCDI_HAVE_PRIVILEGE(privilege_mask, MAC_SPOOFING) ||
293 EFX_MCDI_HAVE_PRIVILEGE(privilege_mask, ADMIN);
295 case EFX_MCDI_FEATURE_MAC_SPOOFING:
297 * Admin privilege must be used prior to introduction of
298 * mac spoofing privilege (at v4.6), which is used up to
299 * introduction of mac spoofing TX privilege (at v4.7)
302 EFX_MCDI_HAVE_PRIVILEGE(privilege_mask, MAC_SPOOFING_TX) ||
303 EFX_MCDI_HAVE_PRIVILEGE(privilege_mask, MAC_SPOOFING) ||
304 EFX_MCDI_HAVE_PRIVILEGE(privilege_mask, ADMIN);
314 EFSYS_PROBE1(fail1, efx_rc_t, rc);
319 #endif /* EFSYS_OPT_MCDI */
321 #endif /* EFSYS_OPT_HUNTINGTON || EFSYS_OPT_MEDFORD || EFSYS_OPT_MEDFORD2 */