2 * Copyright (c) 2012-2016 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.
34 #if EFSYS_OPT_SIENA && EFSYS_OPT_MCDI
36 #define SIENA_MCDI_PDU(_emip) \
37 (((emip)->emi_port == 1) \
38 ? MC_SMEM_P0_PDU_OFST >> 2 \
39 : MC_SMEM_P1_PDU_OFST >> 2)
41 #define SIENA_MCDI_DOORBELL(_emip) \
42 (((emip)->emi_port == 1) \
43 ? MC_SMEM_P0_DOORBELL_OFST >> 2 \
44 : MC_SMEM_P1_DOORBELL_OFST >> 2)
46 #define SIENA_MCDI_STATUS(_emip) \
47 (((emip)->emi_port == 1) \
48 ? MC_SMEM_P0_STATUS_OFST >> 2 \
49 : MC_SMEM_P1_STATUS_OFST >> 2)
53 siena_mcdi_send_request(
55 __in_bcount(hdr_len) void *hdrp,
57 __in_bcount(sdu_len) void *sdup,
60 efx_mcdi_iface_t *emip = &(enp->en_mcdi.em_emip);
66 EFSYS_ASSERT(enp->en_family == EFX_FAMILY_SIENA);
68 EFSYS_ASSERT(emip->emi_port == 1 || emip->emi_port == 2);
69 pdur = SIENA_MCDI_PDU(emip);
70 dbr = SIENA_MCDI_DOORBELL(emip);
72 /* Write the header */
73 EFSYS_ASSERT3U(hdr_len, ==, sizeof (efx_dword_t));
74 dword = *(efx_dword_t *)hdrp;
75 EFX_BAR_TBL_WRITED(enp, FR_CZ_MC_TREG_SMEM, pdur, &dword, B_TRUE);
77 /* Write the payload */
78 for (pos = 0; pos < sdu_len; pos += sizeof (efx_dword_t)) {
79 dword = *(efx_dword_t *)((uint8_t *)sdup + pos);
80 EFX_BAR_TBL_WRITED(enp, FR_CZ_MC_TREG_SMEM,
81 pdur + 1 + (pos >> 2), &dword, B_FALSE);
84 /* Ring the doorbell */
85 EFX_POPULATE_DWORD_1(dword, EFX_DWORD_0, 0xd004be11);
86 EFX_BAR_TBL_WRITED(enp, FR_CZ_MC_TREG_SMEM, dbr, &dword, B_FALSE);
90 siena_mcdi_poll_reboot(
95 * XXX Bug 25922, bug 26099: This function is not being used
96 * properly. Until its callers are fixed, it should always
102 efx_mcdi_iface_t *emip = &(enp->en_mcdi.em_emip);
103 unsigned int rebootr;
107 EFSYS_ASSERT(enp->en_family == EFX_FAMILY_SIENA);
108 EFSYS_ASSERT(emip->emi_port == 1 || emip->emi_port == 2);
109 rebootr = SIENA_MCDI_STATUS(emip);
111 EFX_BAR_TBL_READD(enp, FR_CZ_MC_TREG_SMEM, rebootr, &dword, B_FALSE);
112 value = EFX_DWORD_FIELD(dword, EFX_DWORD_0);
117 EFX_ZERO_DWORD(dword);
118 EFX_BAR_TBL_WRITED(enp, FR_CZ_MC_TREG_SMEM, rebootr, &dword, B_FALSE);
120 if (value == MC_STATUS_DWORD_ASSERT)
127 extern __checkReturn boolean_t
128 siena_mcdi_poll_response(
131 efx_mcdi_iface_t *emip = &(enp->en_mcdi.em_emip);
135 EFSYS_ASSERT(emip->emi_port == 1 || emip->emi_port == 2);
136 pdur = SIENA_MCDI_PDU(emip);
138 EFX_BAR_TBL_READD(enp, FR_CZ_MC_TREG_SMEM, pdur, &hdr, B_FALSE);
139 return (EFX_DWORD_FIELD(hdr, MCDI_HEADER_RESPONSE) ? B_TRUE : B_FALSE);
143 siena_mcdi_read_response(
145 __out_bcount(length) void *bufferp,
149 efx_mcdi_iface_t *emip = &(enp->en_mcdi.em_emip);
154 EFSYS_ASSERT(emip->emi_port == 1 || emip->emi_port == 2);
155 pdur = SIENA_MCDI_PDU(emip);
157 for (pos = 0; pos < length; pos += sizeof (efx_dword_t)) {
158 EFX_BAR_TBL_READD(enp, FR_CZ_MC_TREG_SMEM,
159 pdur + ((offset + pos) >> 2), &data, B_FALSE);
160 memcpy((uint8_t *)bufferp + pos, &data,
161 MIN(sizeof (data), length - pos));
165 __checkReturn efx_rc_t
168 __in const efx_mcdi_transport_t *mtp)
170 efx_mcdi_iface_t *emip = &(enp->en_mcdi.em_emip);
172 unsigned int portnum;
175 _NOTE(ARGUNUSED(mtp))
177 EFSYS_ASSERT(enp->en_family == EFX_FAMILY_SIENA);
179 /* Determine the port number to use for MCDI */
180 EFX_BAR_READO(enp, FR_AZ_CS_DEBUG_REG, &oword);
181 portnum = EFX_OWORD_FIELD(oword, FRF_CZ_CS_PORT_NUM);
184 /* Presumably booted from ROM; only MCDI port 1 will work */
186 } else if (portnum <= 2) {
187 emip->emi_port = portnum;
193 /* Siena BootROM and firmware only support MCDIv1 */
194 emip->emi_max_version = 1;
197 * Wipe the atomic reboot status so subsequent MCDI requests succeed.
198 * BOOT_STATUS is preserved so eno_nic_probe() can boot out of the
201 (void) siena_mcdi_poll_reboot(enp);
206 EFSYS_PROBE1(fail1, efx_rc_t, rc);
215 _NOTE(ARGUNUSED(enp))
218 __checkReturn efx_rc_t
219 siena_mcdi_feature_supported(
221 __in efx_mcdi_feature_id_t id,
222 __out boolean_t *supportedp)
226 EFSYS_ASSERT3U(enp->en_family, ==, EFX_FAMILY_SIENA);
229 case EFX_MCDI_FEATURE_FW_UPDATE:
230 case EFX_MCDI_FEATURE_LINK_CONTROL:
231 case EFX_MCDI_FEATURE_MACADDR_CHANGE:
232 case EFX_MCDI_FEATURE_MAC_SPOOFING:
233 *supportedp = B_TRUE;
243 EFSYS_PROBE1(fail1, efx_rc_t, rc);
248 /* Default timeout for MCDI command processing. */
249 #define SIENA_MCDI_CMD_TIMEOUT_US (10 * 1000 * 1000)
252 siena_mcdi_get_timeout(
254 __in efx_mcdi_req_t *emrp,
255 __out uint32_t *timeoutp)
257 _NOTE(ARGUNUSED(enp, emrp))
259 *timeoutp = SIENA_MCDI_CMD_TIMEOUT_US;
263 #endif /* EFSYS_OPT_SIENA && EFSYS_OPT_MCDI */