1 /* SPDX-License-Identifier: BSD-3-Clause
3 * Copyright(c) 2019-2020 Xilinx, Inc.
4 * Copyright(c) 2012-2019 Solarflare Communications Inc.
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(EFX_FAMILY_IS_EF10(enp
));
31 EFSYS_ASSERT(enp
->en_features
& EFX_FEATURE_MCDI_DMA
);
34 * All EF10 firmware supports MCDIv2 and MCDIv1.
35 * Medford BootROM supports MCDIv2 and MCDIv1.
36 * Huntington BootROM supports MCDIv1 only.
38 emip
->emi_max_version
= 2;
40 /* A host DMA buffer is required for EF10 MCDI */
47 * Ensure that the MC doorbell is in a known state before issuing MCDI
48 * commands. The recovery algorithm requires that the MC command buffer
49 * must be 256 byte aligned. See bug24769.
51 if ((EFSYS_MEM_ADDR(esmp
) & 0xFF) != 0) {
55 EFX_POPULATE_DWORD_1(dword
, EFX_DWORD_0
, 1);
56 EFX_BAR_WRITED(enp
, ER_DZ_MC_DB_HWRD_REG
, &dword
, B_FALSE
);
58 /* Save initial MC reboot status */
59 (void) ef10_mcdi_poll_reboot(enp
);
61 /* Start a new epoch (allow fresh MCDI requests to succeed) */
62 efx_mcdi_new_epoch(enp
);
69 EFSYS_PROBE1(fail1
, efx_rc_t
, rc
);
78 efx_mcdi_iface_t
*emip
= &(enp
->en_mcdi
.em_emip
);
80 emip
->emi_new_epoch
= B_FALSE
;
84 * In older firmware all commands are processed in a single thread, so a long
85 * running command for one PCIe function can block processing for another
86 * function (see bug 61269).
88 * In newer firmware that supports multithreaded MCDI processing, we can extend
89 * the timeout for long-running requests which we know firmware may choose to
90 * process in a background thread.
92 #define EF10_MCDI_CMD_TIMEOUT_US (10 * 1000 * 1000)
93 #define EF10_MCDI_CMD_LONG_TIMEOUT_US (60 * 1000 * 1000)
96 ef10_mcdi_get_timeout(
98 __in efx_mcdi_req_t
*emrp
,
99 __out
uint32_t *timeoutp
)
101 efx_nic_cfg_t
*encp
= &(enp
->en_nic_cfg
);
103 switch (emrp
->emr_cmd
) {
104 case MC_CMD_POLL_BIST
:
105 case MC_CMD_NVRAM_ERASE
:
106 case MC_CMD_LICENSING_V3
:
107 case MC_CMD_NVRAM_UPDATE_FINISH
:
108 if (encp
->enc_nvram_update_verify_result_supported
!= B_FALSE
) {
110 * Potentially longer running commands, which firmware
111 * may choose to process in a background thread.
113 *timeoutp
= EF10_MCDI_CMD_LONG_TIMEOUT_US
;
118 *timeoutp
= EF10_MCDI_CMD_TIMEOUT_US
;
124 ef10_mcdi_send_request(
126 __in_bcount(hdr_len
) void *hdrp
,
128 __in_bcount(sdu_len
) void *sdup
,
131 const efx_mcdi_transport_t
*emtp
= enp
->en_mcdi
.em_emtp
;
132 efsys_mem_t
*esmp
= emtp
->emt_dma_mem
;
136 EFSYS_ASSERT(EFX_FAMILY_IS_EF10(enp
));
138 /* Write the header */
139 for (pos
= 0; pos
< hdr_len
; pos
+= sizeof (efx_dword_t
)) {
140 dword
= *(efx_dword_t
*)((uint8_t *)hdrp
+ pos
);
141 EFSYS_MEM_WRITED(esmp
, pos
, &dword
);
144 /* Write the payload */
145 for (pos
= 0; pos
< sdu_len
; pos
+= sizeof (efx_dword_t
)) {
146 dword
= *(efx_dword_t
*)((uint8_t *)sdup
+ pos
);
147 EFSYS_MEM_WRITED(esmp
, hdr_len
+ pos
, &dword
);
150 /* Guarantee ordering of memory (MCDI request) and PIO (MC doorbell) */
151 EFSYS_DMA_SYNC_FOR_DEVICE(esmp
, 0, hdr_len
+ sdu_len
);
152 EFSYS_PIO_WRITE_BARRIER();
154 /* Ring the doorbell to post the command DMA address to the MC */
155 EFX_POPULATE_DWORD_1(dword
, EFX_DWORD_0
,
156 EFSYS_MEM_ADDR(esmp
) >> 32);
157 EFX_BAR_WRITED(enp
, ER_DZ_MC_DB_LWRD_REG
, &dword
, B_FALSE
);
159 EFX_POPULATE_DWORD_1(dword
, EFX_DWORD_0
,
160 EFSYS_MEM_ADDR(esmp
) & 0xffffffff);
161 EFX_BAR_WRITED(enp
, ER_DZ_MC_DB_HWRD_REG
, &dword
, B_FALSE
);
164 __checkReturn boolean_t
165 ef10_mcdi_poll_response(
168 const efx_mcdi_transport_t
*emtp
= enp
->en_mcdi
.em_emtp
;
169 efsys_mem_t
*esmp
= emtp
->emt_dma_mem
;
172 EFSYS_MEM_READD(esmp
, 0, &hdr
);
173 EFSYS_MEM_READ_BARRIER();
175 return (EFX_DWORD_FIELD(hdr
, MCDI_HEADER_RESPONSE
) ? B_TRUE
: B_FALSE
);
179 ef10_mcdi_read_response(
181 __out_bcount(length
) void *bufferp
,
185 const efx_mcdi_transport_t
*emtp
= enp
->en_mcdi
.em_emtp
;
186 efsys_mem_t
*esmp
= emtp
->emt_dma_mem
;
187 unsigned int pos
= 0;
189 size_t remaining
= length
;
191 while (remaining
> 0) {
192 size_t chunk
= MIN(remaining
, sizeof (data
));
194 EFSYS_MEM_READD(esmp
, offset
+ pos
, &data
);
195 memcpy((uint8_t *)bufferp
+ pos
, &data
, chunk
);
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(EFX_FAMILY_IS_EF10(enp
));
261 * Use privilege mask state at MCDI attach.
265 case EFX_MCDI_FEATURE_FW_UPDATE
:
267 * Admin privilege must be used prior to introduction of
271 EFX_MCDI_HAVE_PRIVILEGE(privilege_mask
, ADMIN
);
273 case EFX_MCDI_FEATURE_LINK_CONTROL
:
275 * Admin privilege used prior to introduction of
279 EFX_MCDI_HAVE_PRIVILEGE(privilege_mask
, LINK
) ||
280 EFX_MCDI_HAVE_PRIVILEGE(privilege_mask
, ADMIN
);
282 case EFX_MCDI_FEATURE_MACADDR_CHANGE
:
284 * Admin privilege must be used prior to introduction of
285 * mac spoofing privilege (at v4.6), which is used up to
286 * introduction of change mac spoofing privilege (at v4.7)
289 EFX_MCDI_HAVE_PRIVILEGE(privilege_mask
, CHANGE_MAC
) ||
290 EFX_MCDI_HAVE_PRIVILEGE(privilege_mask
, MAC_SPOOFING
) ||
291 EFX_MCDI_HAVE_PRIVILEGE(privilege_mask
, ADMIN
);
293 case EFX_MCDI_FEATURE_MAC_SPOOFING
:
295 * Admin privilege must be used prior to introduction of
296 * mac spoofing privilege (at v4.6), which is used up to
297 * introduction of mac spoofing TX privilege (at v4.7)
300 EFX_MCDI_HAVE_PRIVILEGE(privilege_mask
, MAC_SPOOFING_TX
) ||
301 EFX_MCDI_HAVE_PRIVILEGE(privilege_mask
, MAC_SPOOFING
) ||
302 EFX_MCDI_HAVE_PRIVILEGE(privilege_mask
, ADMIN
);
312 EFSYS_PROBE1(fail1
, efx_rc_t
, rc
);
317 #endif /* EFSYS_OPT_MCDI */
319 #endif /* EFX_OPTS_EF10() */