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_SIENA && EFSYS_OPT_MCDI
40 #define SIENA_MCDI_PDU(_emip) \
41 (((emip)->emi_port == 1) \
42 ? MC_SMEM_P0_PDU_OFST >> 2 \
43 : MC_SMEM_P1_PDU_OFST >> 2)
45 #define SIENA_MCDI_DOORBELL(_emip) \
46 (((emip)->emi_port == 1) \
47 ? MC_SMEM_P0_DOORBELL_OFST >> 2 \
48 : MC_SMEM_P1_DOORBELL_OFST >> 2)
50 #define SIENA_MCDI_STATUS(_emip) \
51 (((emip)->emi_port == 1) \
52 ? MC_SMEM_P0_STATUS_OFST >> 2 \
53 : MC_SMEM_P1_STATUS_OFST >> 2)
57 siena_mcdi_request_copyin(
59 __in efx_mcdi_req_t *emrp,
60 __in unsigned int seq,
61 __in boolean_t ev_cpl,
62 __in boolean_t new_epoch)
64 efx_mcdi_iface_t *emip = &(enp->en_mcdi.em_emip);
71 EFSYS_ASSERT(enp->en_family == EFX_FAMILY_SIENA);
72 _NOTE(ARGUNUSED(new_epoch))
74 EFSYS_ASSERT(emip->emi_port == 1 || emip->emi_port == 2);
75 pdur = SIENA_MCDI_PDU(emip);
76 dbr = SIENA_MCDI_DOORBELL(emip);
80 xflags |= MCDI_HEADER_XFLAGS_EVREQ;
82 /* Construct the header in shared memory */
83 EFX_POPULATE_DWORD_6(dword,
84 MCDI_HEADER_CODE, emrp->emr_cmd,
85 MCDI_HEADER_RESYNC, 1,
86 MCDI_HEADER_DATALEN, emrp->emr_in_length,
88 MCDI_HEADER_RESPONSE, 0,
89 MCDI_HEADER_XFLAGS, xflags);
90 EFX_BAR_TBL_WRITED(enp, FR_CZ_MC_TREG_SMEM, pdur, &dword, B_TRUE);
92 for (pos = 0; pos < emrp->emr_in_length; pos += sizeof (efx_dword_t)) {
93 memcpy(&dword, MCDI_IN(*emrp, efx_dword_t, pos),
94 MIN(sizeof (dword), emrp->emr_in_length - pos));
95 EFX_BAR_TBL_WRITED(enp, FR_CZ_MC_TREG_SMEM,
96 pdur + 1 + (pos >> 2), &dword, B_FALSE);
99 /* Ring the doorbell */
100 EFX_POPULATE_DWORD_1(dword, EFX_DWORD_0, 0xd004be11);
101 EFX_BAR_TBL_WRITED(enp, FR_CZ_MC_TREG_SMEM, dbr, &dword, B_FALSE);
105 siena_mcdi_request_copyout(
107 __in efx_mcdi_req_t *emrp)
109 efx_mcdi_iface_t *emip = &(enp->en_mcdi.em_emip);
114 pdur = SIENA_MCDI_PDU(emip);
116 /* Copy payload out if caller supplied buffer */
117 if (emrp->emr_out_buf != NULL) {
118 size_t bytes = MIN(emrp->emr_out_length_used,
119 emrp->emr_out_length);
120 for (pos = 0; pos < bytes; pos += sizeof (efx_dword_t)) {
121 EFX_BAR_TBL_READD(enp, FR_CZ_MC_TREG_SMEM,
122 pdur + 1 + (pos >> 2), &data, B_FALSE);
123 memcpy(MCDI_OUT(*emrp, efx_dword_t, pos), &data,
124 MIN(sizeof (data), bytes - pos));
130 siena_mcdi_poll_reboot(
133 #ifndef EFX_GRACEFUL_MC_REBOOT
135 * This function is not being used properly.
136 * Until its callers are fixed, it should always return 0.
138 _NOTE(ARGUNUSED(enp))
141 efx_mcdi_iface_t *emip = &(enp->en_mcdi.em_emip);
142 unsigned int rebootr;
146 EFSYS_ASSERT(enp->en_family == EFX_FAMILY_SIENA);
147 EFSYS_ASSERT(emip->emi_port == 1 || emip->emi_port == 2);
148 rebootr = SIENA_MCDI_STATUS(emip);
150 EFX_BAR_TBL_READD(enp, FR_CZ_MC_TREG_SMEM, rebootr, &dword, B_FALSE);
151 value = EFX_DWORD_FIELD(dword, EFX_DWORD_0);
156 EFX_ZERO_DWORD(dword);
157 EFX_BAR_TBL_WRITED(enp, FR_CZ_MC_TREG_SMEM, rebootr, &dword, B_FALSE);
159 if (value == MC_STATUS_DWORD_ASSERT)
166 __checkReturn boolean_t
167 siena_mcdi_request_poll(
170 efx_mcdi_iface_t *emip = &(enp->en_mcdi.em_emip);
171 efx_mcdi_req_t *emrp;
179 EFSYS_ASSERT3U(enp->en_family, ==, EFX_FAMILY_SIENA);
181 /* Serialise against post-watchdog efx_mcdi_ev* */
182 EFSYS_LOCK(enp->en_eslp, state);
184 EFSYS_ASSERT(emip->emi_pending_req != NULL);
185 EFSYS_ASSERT(!emip->emi_ev_cpl);
186 emrp = emip->emi_pending_req;
188 /* Check for reboot atomically w.r.t efx_mcdi_request_start */
189 if (emip->emi_poll_cnt++ == 0) {
190 if ((rc = siena_mcdi_poll_reboot(enp)) != 0) {
191 emip->emi_pending_req = NULL;
192 EFSYS_UNLOCK(enp->en_eslp, state);
198 EFSYS_ASSERT(emip->emi_port == 1 || emip->emi_port == 2);
199 pdur = SIENA_MCDI_PDU(emip);
201 /* Read the command header */
202 EFX_BAR_TBL_READD(enp, FR_CZ_MC_TREG_SMEM, pdur, &dword, B_FALSE);
203 if (EFX_DWORD_FIELD(dword, MCDI_HEADER_RESPONSE) == 0) {
204 EFSYS_UNLOCK(enp->en_eslp, state);
208 /* Request complete */
209 emip->emi_pending_req = NULL;
210 seq = (emip->emi_seq - 1) & EFX_MASK32(MCDI_HEADER_SEQ);
212 /* Check for synchronous reboot */
213 if (EFX_DWORD_FIELD(dword, MCDI_HEADER_ERROR) != 0 &&
214 EFX_DWORD_FIELD(dword, MCDI_HEADER_DATALEN) == 0) {
215 /* Consume status word */
216 EFSYS_SPIN(EFX_MCDI_STATUS_SLEEP_US);
217 siena_mcdi_poll_reboot(enp);
218 EFSYS_UNLOCK(enp->en_eslp, state);
223 EFSYS_UNLOCK(enp->en_eslp, state);
225 /* Check that the returned data is consistent */
226 if (EFX_DWORD_FIELD(dword, MCDI_HEADER_CODE) != emrp->emr_cmd ||
227 EFX_DWORD_FIELD(dword, MCDI_HEADER_SEQ) != seq) {
228 /* Response is for a different request */
233 length = EFX_DWORD_FIELD(dword, MCDI_HEADER_DATALEN);
234 if (EFX_DWORD_FIELD(dword, MCDI_HEADER_ERROR)) {
235 efx_dword_t errdword;
238 EFSYS_ASSERT3U(length, ==, 4);
239 EFX_BAR_TBL_READD(enp, FR_CZ_MC_TREG_SMEM,
240 pdur + 1 + (MC_CMD_ERR_CODE_OFST >> 2),
242 errcode = EFX_DWORD_FIELD(errdword, EFX_DWORD_0);
243 rc = efx_mcdi_request_errcode(errcode);
244 if (!emrp->emr_quiet) {
245 EFSYS_PROBE2(mcdi_err, int, emrp->emr_cmd,
251 emrp->emr_out_length_used = length;
253 siena_mcdi_request_copyout(enp, emrp);
259 if (!emrp->emr_quiet)
262 if (!emrp->emr_quiet)
265 if (!emrp->emr_quiet)
268 if (!emrp->emr_quiet)
269 EFSYS_PROBE1(fail1, int, rc);
271 /* Fill out error state */
273 emrp->emr_out_length_used = 0;
275 /* Reboot/Assertion */
276 if (rc == EIO || rc == EINTR)
277 efx_mcdi_raise_exception(enp, emrp, rc);
286 __in const efx_mcdi_transport_t *mtp)
288 efx_mcdi_iface_t *emip = &(enp->en_mcdi.em_emip);
290 unsigned int portnum;
293 EFSYS_ASSERT(enp->en_family == EFX_FAMILY_SIENA);
295 /* Determine the port number to use for MCDI */
296 EFX_BAR_READO(enp, FR_AZ_CS_DEBUG_REG, &oword);
297 portnum = EFX_OWORD_FIELD(oword, FRF_CZ_CS_PORT_NUM);
300 /* Presumably booted from ROM; only MCDI port 1 will work */
302 } else if (portnum <= 2) {
303 emip->emi_port = portnum;
310 * Wipe the atomic reboot status so subsequent MCDI requests succeed.
311 * BOOT_STATUS is preserved so eno_nic_probe() can boot out of the
314 (void) siena_mcdi_poll_reboot(enp);
319 EFSYS_PROBE1(fail1, int, rc);
331 siena_mcdi_fw_update_supported(
333 __out boolean_t *supportedp)
335 EFSYS_ASSERT3U(enp->en_family, ==, EFX_FAMILY_SIENA);
337 *supportedp = B_TRUE;
343 siena_mcdi_macaddr_change_supported(
345 __out boolean_t *supportedp)
347 EFSYS_ASSERT3U(enp->en_family, ==, EFX_FAMILY_SIENA);
349 *supportedp = B_TRUE;
354 #endif /* EFSYS_OPT_SIENA && EFSYS_OPT_MCDI */