1*49ef7e06SGarrett D'Amore /*
2*49ef7e06SGarrett D'Amore  * Copyright (c) 2008-2015 Solarflare Communications Inc.
3*49ef7e06SGarrett D'Amore  * All rights reserved.
4*49ef7e06SGarrett D'Amore  *
5*49ef7e06SGarrett D'Amore  * Redistribution and use in source and binary forms, with or without
6*49ef7e06SGarrett D'Amore  * modification, are permitted provided that the following conditions are met:
7*49ef7e06SGarrett D'Amore  *
8*49ef7e06SGarrett D'Amore  * 1. Redistributions of source code must retain the above copyright notice,
9*49ef7e06SGarrett D'Amore  *    this list of conditions and the following disclaimer.
10*49ef7e06SGarrett D'Amore  * 2. Redistributions in binary form must reproduce the above copyright notice,
11*49ef7e06SGarrett D'Amore  *    this list of conditions and the following disclaimer in the documentation
12*49ef7e06SGarrett D'Amore  *    and/or other materials provided with the distribution.
13*49ef7e06SGarrett D'Amore  *
14*49ef7e06SGarrett D'Amore  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15*49ef7e06SGarrett D'Amore  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
16*49ef7e06SGarrett D'Amore  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17*49ef7e06SGarrett D'Amore  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
18*49ef7e06SGarrett D'Amore  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19*49ef7e06SGarrett D'Amore  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20*49ef7e06SGarrett D'Amore  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
21*49ef7e06SGarrett D'Amore  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
22*49ef7e06SGarrett D'Amore  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23*49ef7e06SGarrett D'Amore  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
24*49ef7e06SGarrett D'Amore  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25*49ef7e06SGarrett D'Amore  *
26*49ef7e06SGarrett D'Amore  * The views and conclusions contained in the software and documentation are
27*49ef7e06SGarrett D'Amore  * those of the authors and should not be interpreted as representing official
28*49ef7e06SGarrett D'Amore  * policies, either expressed or implied, of the FreeBSD Project.
29*49ef7e06SGarrett D'Amore  */
30*49ef7e06SGarrett D'Amore 
31*49ef7e06SGarrett D'Amore #include "efx.h"
32*49ef7e06SGarrett D'Amore #include "efx_impl.h"
33*49ef7e06SGarrett D'Amore 
34*49ef7e06SGarrett D'Amore #if EFSYS_OPT_MCDI
35*49ef7e06SGarrett D'Amore 
36*49ef7e06SGarrett D'Amore /*
37*49ef7e06SGarrett D'Amore  * There are three versions of the MCDI interface:
38*49ef7e06SGarrett D'Amore  *  - MCDIv0: Siena BootROM. Transport uses MCDIv1 headers.
39*49ef7e06SGarrett D'Amore  *  - MCDIv1: Siena firmware and Huntington BootROM.
40*49ef7e06SGarrett D'Amore  *  - MCDIv2: EF10 firmware (Huntington/Medford) and Medford BootROM.
41*49ef7e06SGarrett D'Amore  *            Transport uses MCDIv2 headers.
42*49ef7e06SGarrett D'Amore  *
43*49ef7e06SGarrett D'Amore  * MCDIv2 Header NOT_EPOCH flag
44*49ef7e06SGarrett D'Amore  * ----------------------------
45*49ef7e06SGarrett D'Amore  * A new epoch begins at initial startup or after an MC reboot, and defines when
46*49ef7e06SGarrett D'Amore  * the MC should reject stale MCDI requests.
47*49ef7e06SGarrett D'Amore  *
48*49ef7e06SGarrett D'Amore  * The first MCDI request sent by the host should contain NOT_EPOCH=0, and all
49*49ef7e06SGarrett D'Amore  * subsequent requests (until the next MC reboot) should contain NOT_EPOCH=1.
50*49ef7e06SGarrett D'Amore  *
51*49ef7e06SGarrett D'Amore  * After rebooting the MC will fail all requests with NOT_EPOCH=1 by writing a
52*49ef7e06SGarrett D'Amore  * response with ERROR=1 and DATALEN=0 until a request is seen with NOT_EPOCH=0.
53*49ef7e06SGarrett D'Amore  */
54*49ef7e06SGarrett D'Amore 
55*49ef7e06SGarrett D'Amore 
56*49ef7e06SGarrett D'Amore 
57*49ef7e06SGarrett D'Amore #if EFSYS_OPT_SIENA
58*49ef7e06SGarrett D'Amore 
59*49ef7e06SGarrett D'Amore static const efx_mcdi_ops_t	__efx_mcdi_siena_ops = {
60*49ef7e06SGarrett D'Amore 	siena_mcdi_init,		/* emco_init */
61*49ef7e06SGarrett D'Amore 	siena_mcdi_send_request,	/* emco_send_request */
62*49ef7e06SGarrett D'Amore 	siena_mcdi_poll_reboot,		/* emco_poll_reboot */
63*49ef7e06SGarrett D'Amore 	siena_mcdi_poll_response,	/* emco_poll_response */
64*49ef7e06SGarrett D'Amore 	siena_mcdi_read_response,	/* emco_read_response */
65*49ef7e06SGarrett D'Amore 	siena_mcdi_fini,		/* emco_fini */
66*49ef7e06SGarrett D'Amore 	siena_mcdi_feature_supported,	/* emco_feature_supported */
67*49ef7e06SGarrett D'Amore };
68*49ef7e06SGarrett D'Amore 
69*49ef7e06SGarrett D'Amore #endif	/* EFSYS_OPT_SIENA */
70*49ef7e06SGarrett D'Amore 
71*49ef7e06SGarrett D'Amore #if EFSYS_OPT_HUNTINGTON || EFSYS_OPT_MEDFORD
72*49ef7e06SGarrett D'Amore 
73*49ef7e06SGarrett D'Amore static const efx_mcdi_ops_t	__efx_mcdi_ef10_ops = {
74*49ef7e06SGarrett D'Amore 	ef10_mcdi_init,			/* emco_init */
75*49ef7e06SGarrett D'Amore 	ef10_mcdi_send_request,		/* emco_send_request */
76*49ef7e06SGarrett D'Amore 	ef10_mcdi_poll_reboot,		/* emco_poll_reboot */
77*49ef7e06SGarrett D'Amore 	ef10_mcdi_poll_response,	/* emco_poll_response */
78*49ef7e06SGarrett D'Amore 	ef10_mcdi_read_response,	/* emco_read_response */
79*49ef7e06SGarrett D'Amore 	ef10_mcdi_fini,			/* emco_fini */
80*49ef7e06SGarrett D'Amore 	ef10_mcdi_feature_supported,	/* emco_feature_supported */
81*49ef7e06SGarrett D'Amore };
82*49ef7e06SGarrett D'Amore 
83*49ef7e06SGarrett D'Amore #endif	/* EFSYS_OPT_HUNTINGTON || EFSYS_OPT_MEDFORD */
84*49ef7e06SGarrett D'Amore 
85*49ef7e06SGarrett D'Amore 
86*49ef7e06SGarrett D'Amore 
87*49ef7e06SGarrett D'Amore 	__checkReturn	efx_rc_t
efx_mcdi_init(__in efx_nic_t * enp,__in const efx_mcdi_transport_t * emtp)88*49ef7e06SGarrett D'Amore efx_mcdi_init(
89*49ef7e06SGarrett D'Amore 	__in		efx_nic_t *enp,
90*49ef7e06SGarrett D'Amore 	__in		const efx_mcdi_transport_t *emtp)
91*49ef7e06SGarrett D'Amore {
92*49ef7e06SGarrett D'Amore 	const efx_mcdi_ops_t *emcop;
93*49ef7e06SGarrett D'Amore 	efx_rc_t rc;
94*49ef7e06SGarrett D'Amore 
95*49ef7e06SGarrett D'Amore 	EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
96*49ef7e06SGarrett D'Amore 	EFSYS_ASSERT3U(enp->en_mod_flags, ==, 0);
97*49ef7e06SGarrett D'Amore 
98*49ef7e06SGarrett D'Amore 	switch (enp->en_family) {
99*49ef7e06SGarrett D'Amore #if EFSYS_OPT_SIENA
100*49ef7e06SGarrett D'Amore 	case EFX_FAMILY_SIENA:
101*49ef7e06SGarrett D'Amore 		emcop = &__efx_mcdi_siena_ops;
102*49ef7e06SGarrett D'Amore 		break;
103*49ef7e06SGarrett D'Amore #endif	/* EFSYS_OPT_SIENA */
104*49ef7e06SGarrett D'Amore 
105*49ef7e06SGarrett D'Amore #if EFSYS_OPT_HUNTINGTON
106*49ef7e06SGarrett D'Amore 	case EFX_FAMILY_HUNTINGTON:
107*49ef7e06SGarrett D'Amore 		emcop = &__efx_mcdi_ef10_ops;
108*49ef7e06SGarrett D'Amore 		break;
109*49ef7e06SGarrett D'Amore #endif	/* EFSYS_OPT_HUNTINGTON */
110*49ef7e06SGarrett D'Amore 
111*49ef7e06SGarrett D'Amore #if EFSYS_OPT_MEDFORD
112*49ef7e06SGarrett D'Amore 	case EFX_FAMILY_MEDFORD:
113*49ef7e06SGarrett D'Amore 		emcop = &__efx_mcdi_ef10_ops;
114*49ef7e06SGarrett D'Amore 		break;
115*49ef7e06SGarrett D'Amore #endif	/* EFSYS_OPT_MEDFORD */
116*49ef7e06SGarrett D'Amore 
117*49ef7e06SGarrett D'Amore 	default:
118*49ef7e06SGarrett D'Amore 		EFSYS_ASSERT(0);
119*49ef7e06SGarrett D'Amore 		rc = ENOTSUP;
120*49ef7e06SGarrett D'Amore 		goto fail1;
121*49ef7e06SGarrett D'Amore 	}
122*49ef7e06SGarrett D'Amore 
123*49ef7e06SGarrett D'Amore 	if (enp->en_features & EFX_FEATURE_MCDI_DMA) {
124*49ef7e06SGarrett D'Amore 		/* MCDI requires a DMA buffer in host memory */
125*49ef7e06SGarrett D'Amore 		if ((emtp == NULL) || (emtp->emt_dma_mem) == NULL) {
126*49ef7e06SGarrett D'Amore 			rc = EINVAL;
127*49ef7e06SGarrett D'Amore 			goto fail2;
128*49ef7e06SGarrett D'Amore 		}
129*49ef7e06SGarrett D'Amore 	}
130*49ef7e06SGarrett D'Amore 	enp->en_mcdi.em_emtp = emtp;
131*49ef7e06SGarrett D'Amore 
132*49ef7e06SGarrett D'Amore 	if (emcop != NULL && emcop->emco_init != NULL) {
133*49ef7e06SGarrett D'Amore 		if ((rc = emcop->emco_init(enp, emtp)) != 0)
134*49ef7e06SGarrett D'Amore 			goto fail3;
135*49ef7e06SGarrett D'Amore 	}
136*49ef7e06SGarrett D'Amore 
137*49ef7e06SGarrett D'Amore 	enp->en_mcdi.em_emcop = emcop;
138*49ef7e06SGarrett D'Amore 	enp->en_mod_flags |= EFX_MOD_MCDI;
139*49ef7e06SGarrett D'Amore 
140*49ef7e06SGarrett D'Amore 	return (0);
141*49ef7e06SGarrett D'Amore 
142*49ef7e06SGarrett D'Amore fail3:
143*49ef7e06SGarrett D'Amore 	EFSYS_PROBE(fail3);
144*49ef7e06SGarrett D'Amore fail2:
145*49ef7e06SGarrett D'Amore 	EFSYS_PROBE(fail2);
146*49ef7e06SGarrett D'Amore fail1:
147*49ef7e06SGarrett D'Amore 	EFSYS_PROBE1(fail1, efx_rc_t, rc);
148*49ef7e06SGarrett D'Amore 
149*49ef7e06SGarrett D'Amore 	enp->en_mcdi.em_emcop = NULL;
150*49ef7e06SGarrett D'Amore 	enp->en_mcdi.em_emtp = NULL;
151*49ef7e06SGarrett D'Amore 	enp->en_mod_flags &= ~EFX_MOD_MCDI;
152*49ef7e06SGarrett D'Amore 
153*49ef7e06SGarrett D'Amore 	return (rc);
154*49ef7e06SGarrett D'Amore }
155*49ef7e06SGarrett D'Amore 
156*49ef7e06SGarrett D'Amore 			void
efx_mcdi_fini(__in efx_nic_t * enp)157*49ef7e06SGarrett D'Amore efx_mcdi_fini(
158*49ef7e06SGarrett D'Amore 	__in		efx_nic_t *enp)
159*49ef7e06SGarrett D'Amore {
160*49ef7e06SGarrett D'Amore 	efx_mcdi_iface_t *emip = &(enp->en_mcdi.em_emip);
161*49ef7e06SGarrett D'Amore 	const efx_mcdi_ops_t *emcop = enp->en_mcdi.em_emcop;
162*49ef7e06SGarrett D'Amore 
163*49ef7e06SGarrett D'Amore 	EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
164*49ef7e06SGarrett D'Amore 	EFSYS_ASSERT3U(enp->en_mod_flags, ==, EFX_MOD_MCDI);
165*49ef7e06SGarrett D'Amore 
166*49ef7e06SGarrett D'Amore 	if (emcop != NULL && emcop->emco_fini != NULL)
167*49ef7e06SGarrett D'Amore 		emcop->emco_fini(enp);
168*49ef7e06SGarrett D'Amore 
169*49ef7e06SGarrett D'Amore 	emip->emi_port = 0;
170*49ef7e06SGarrett D'Amore 	emip->emi_aborted = 0;
171*49ef7e06SGarrett D'Amore 
172*49ef7e06SGarrett D'Amore 	enp->en_mcdi.em_emcop = NULL;
173*49ef7e06SGarrett D'Amore 	enp->en_mod_flags &= ~EFX_MOD_MCDI;
174*49ef7e06SGarrett D'Amore }
175*49ef7e06SGarrett D'Amore 
176*49ef7e06SGarrett D'Amore 			void
efx_mcdi_new_epoch(__in efx_nic_t * enp)177*49ef7e06SGarrett D'Amore efx_mcdi_new_epoch(
178*49ef7e06SGarrett D'Amore 	__in		efx_nic_t *enp)
179*49ef7e06SGarrett D'Amore {
180*49ef7e06SGarrett D'Amore 	efx_mcdi_iface_t *emip = &(enp->en_mcdi.em_emip);
181*49ef7e06SGarrett D'Amore 	int state;
182*49ef7e06SGarrett D'Amore 
183*49ef7e06SGarrett D'Amore 	/* Start a new epoch (allow fresh MCDI requests to succeed) */
184*49ef7e06SGarrett D'Amore 	EFSYS_LOCK(enp->en_eslp, state);
185*49ef7e06SGarrett D'Amore 	emip->emi_new_epoch = B_TRUE;
186*49ef7e06SGarrett D'Amore 	EFSYS_UNLOCK(enp->en_eslp, state);
187*49ef7e06SGarrett D'Amore }
188*49ef7e06SGarrett D'Amore 
189*49ef7e06SGarrett D'Amore static			void
efx_mcdi_send_request(__in efx_nic_t * enp,__in void * hdrp,__in size_t hdr_len,__in void * sdup,__in size_t sdu_len)190*49ef7e06SGarrett D'Amore efx_mcdi_send_request(
191*49ef7e06SGarrett D'Amore 	__in		efx_nic_t *enp,
192*49ef7e06SGarrett D'Amore 	__in		void *hdrp,
193*49ef7e06SGarrett D'Amore 	__in		size_t hdr_len,
194*49ef7e06SGarrett D'Amore 	__in		void *sdup,
195*49ef7e06SGarrett D'Amore 	__in		size_t sdu_len)
196*49ef7e06SGarrett D'Amore {
197*49ef7e06SGarrett D'Amore 	const efx_mcdi_ops_t *emcop = enp->en_mcdi.em_emcop;
198*49ef7e06SGarrett D'Amore 
199*49ef7e06SGarrett D'Amore 	emcop->emco_send_request(enp, hdrp, hdr_len, sdup, sdu_len);
200*49ef7e06SGarrett D'Amore }
201*49ef7e06SGarrett D'Amore 
202*49ef7e06SGarrett D'Amore static			efx_rc_t
efx_mcdi_poll_reboot(__in efx_nic_t * enp)203*49ef7e06SGarrett D'Amore efx_mcdi_poll_reboot(
204*49ef7e06SGarrett D'Amore 	__in		efx_nic_t *enp)
205*49ef7e06SGarrett D'Amore {
206*49ef7e06SGarrett D'Amore 	const efx_mcdi_ops_t *emcop = enp->en_mcdi.em_emcop;
207*49ef7e06SGarrett D'Amore 	efx_rc_t rc;
208*49ef7e06SGarrett D'Amore 
209*49ef7e06SGarrett D'Amore 	rc = emcop->emco_poll_reboot(enp);
210*49ef7e06SGarrett D'Amore 	return (rc);
211*49ef7e06SGarrett D'Amore }
212*49ef7e06SGarrett D'Amore 
213*49ef7e06SGarrett D'Amore static			boolean_t
efx_mcdi_poll_response(__in efx_nic_t * enp)214*49ef7e06SGarrett D'Amore efx_mcdi_poll_response(
215*49ef7e06SGarrett D'Amore 	__in		efx_nic_t *enp)
216*49ef7e06SGarrett D'Amore {
217*49ef7e06SGarrett D'Amore 	const efx_mcdi_ops_t *emcop = enp->en_mcdi.em_emcop;
218*49ef7e06SGarrett D'Amore 	boolean_t available;
219*49ef7e06SGarrett D'Amore 
220*49ef7e06SGarrett D'Amore 	available = emcop->emco_poll_response(enp);
221*49ef7e06SGarrett D'Amore 	return (available);
222*49ef7e06SGarrett D'Amore }
223*49ef7e06SGarrett D'Amore 
224*49ef7e06SGarrett D'Amore static			void
efx_mcdi_read_response(__in efx_nic_t * enp,__out void * bufferp,__in size_t offset,__in size_t length)225*49ef7e06SGarrett D'Amore efx_mcdi_read_response(
226*49ef7e06SGarrett D'Amore 	__in		efx_nic_t *enp,
227*49ef7e06SGarrett D'Amore 	__out		void *bufferp,
228*49ef7e06SGarrett D'Amore 	__in		size_t offset,
229*49ef7e06SGarrett D'Amore 	__in		size_t length)
230*49ef7e06SGarrett D'Amore {
231*49ef7e06SGarrett D'Amore 	const efx_mcdi_ops_t *emcop = enp->en_mcdi.em_emcop;
232*49ef7e06SGarrett D'Amore 
233*49ef7e06SGarrett D'Amore 	emcop->emco_read_response(enp, bufferp, offset, length);
234*49ef7e06SGarrett D'Amore }
235*49ef7e06SGarrett D'Amore 
236*49ef7e06SGarrett D'Amore 			void
efx_mcdi_request_start(__in efx_nic_t * enp,__in efx_mcdi_req_t * emrp,__in boolean_t ev_cpl)237*49ef7e06SGarrett D'Amore efx_mcdi_request_start(
238*49ef7e06SGarrett D'Amore 	__in		efx_nic_t *enp,
239*49ef7e06SGarrett D'Amore 	__in		efx_mcdi_req_t *emrp,
240*49ef7e06SGarrett D'Amore 	__in		boolean_t ev_cpl)
241*49ef7e06SGarrett D'Amore {
242*49ef7e06SGarrett D'Amore #if EFSYS_OPT_MCDI_LOGGING
243*49ef7e06SGarrett D'Amore 	const efx_mcdi_transport_t *emtp = enp->en_mcdi.em_emtp;
244*49ef7e06SGarrett D'Amore #endif
245*49ef7e06SGarrett D'Amore 	efx_mcdi_iface_t *emip = &(enp->en_mcdi.em_emip);
246*49ef7e06SGarrett D'Amore 	efx_dword_t hdr[2];
247*49ef7e06SGarrett D'Amore 	size_t hdr_len;
248*49ef7e06SGarrett D'Amore 	unsigned int max_version;
249*49ef7e06SGarrett D'Amore 	unsigned int seq;
250*49ef7e06SGarrett D'Amore 	unsigned int xflags;
251*49ef7e06SGarrett D'Amore 	boolean_t new_epoch;
252*49ef7e06SGarrett D'Amore 	int state;
253*49ef7e06SGarrett D'Amore 
254*49ef7e06SGarrett D'Amore 	EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
255*49ef7e06SGarrett D'Amore 	EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_MCDI);
256*49ef7e06SGarrett D'Amore 	EFSYS_ASSERT3U(enp->en_features, &, EFX_FEATURE_MCDI);
257*49ef7e06SGarrett D'Amore 
258*49ef7e06SGarrett D'Amore 	/*
259*49ef7e06SGarrett D'Amore 	 * efx_mcdi_request_start() is naturally serialised against both
260*49ef7e06SGarrett D'Amore 	 * efx_mcdi_request_poll() and efx_mcdi_ev_cpl()/efx_mcdi_ev_death(),
261*49ef7e06SGarrett D'Amore 	 * by virtue of there only being one outstanding MCDI request.
262*49ef7e06SGarrett D'Amore 	 * Unfortunately, upper layers may also call efx_mcdi_request_abort()
263*49ef7e06SGarrett D'Amore 	 * at any time, to timeout a pending mcdi request, That request may
264*49ef7e06SGarrett D'Amore 	 * then subsequently complete, meaning efx_mcdi_ev_cpl() or
265*49ef7e06SGarrett D'Amore 	 * efx_mcdi_ev_death() may end up running in parallel with
266*49ef7e06SGarrett D'Amore 	 * efx_mcdi_request_start(). This race is handled by ensuring that
267*49ef7e06SGarrett D'Amore 	 * %emi_pending_req, %emi_ev_cpl and %emi_seq are protected by the
268*49ef7e06SGarrett D'Amore 	 * en_eslp lock.
269*49ef7e06SGarrett D'Amore 	 */
270*49ef7e06SGarrett D'Amore 	EFSYS_LOCK(enp->en_eslp, state);
271*49ef7e06SGarrett D'Amore 	EFSYS_ASSERT(emip->emi_pending_req == NULL);
272*49ef7e06SGarrett D'Amore 	emip->emi_pending_req = emrp;
273*49ef7e06SGarrett D'Amore 	emip->emi_ev_cpl = ev_cpl;
274*49ef7e06SGarrett D'Amore 	emip->emi_poll_cnt = 0;
275*49ef7e06SGarrett D'Amore 	seq = emip->emi_seq++ & EFX_MASK32(MCDI_HEADER_SEQ);
276*49ef7e06SGarrett D'Amore 	new_epoch = emip->emi_new_epoch;
277*49ef7e06SGarrett D'Amore 	max_version = emip->emi_max_version;
278*49ef7e06SGarrett D'Amore 	EFSYS_UNLOCK(enp->en_eslp, state);
279*49ef7e06SGarrett D'Amore 
280*49ef7e06SGarrett D'Amore 	xflags = 0;
281*49ef7e06SGarrett D'Amore 	if (ev_cpl)
282*49ef7e06SGarrett D'Amore 		xflags |= MCDI_HEADER_XFLAGS_EVREQ;
283*49ef7e06SGarrett D'Amore 
284*49ef7e06SGarrett D'Amore 	/*
285*49ef7e06SGarrett D'Amore 	 * Huntington firmware supports MCDIv2, but the Huntington BootROM only
286*49ef7e06SGarrett D'Amore 	 * supports MCDIv1. Use MCDIv1 headers for MCDIv1 commands where
287*49ef7e06SGarrett D'Amore 	 * possible to support this.
288*49ef7e06SGarrett D'Amore 	 */
289*49ef7e06SGarrett D'Amore 	if ((max_version >= 2) &&
290*49ef7e06SGarrett D'Amore 	    ((emrp->emr_cmd > MC_CMD_CMD_SPACE_ESCAPE_7) ||
291*49ef7e06SGarrett D'Amore 	    (emrp->emr_in_length > MCDI_CTL_SDU_LEN_MAX_V1))) {
292*49ef7e06SGarrett D'Amore 		/* Construct MCDI v2 header */
293*49ef7e06SGarrett D'Amore 		hdr_len = sizeof (hdr);
294*49ef7e06SGarrett D'Amore 		EFX_POPULATE_DWORD_8(hdr[0],
295*49ef7e06SGarrett D'Amore 		    MCDI_HEADER_CODE, MC_CMD_V2_EXTN,
296*49ef7e06SGarrett D'Amore 		    MCDI_HEADER_RESYNC, 1,
297*49ef7e06SGarrett D'Amore 		    MCDI_HEADER_DATALEN, 0,
298*49ef7e06SGarrett D'Amore 		    MCDI_HEADER_SEQ, seq,
299*49ef7e06SGarrett D'Amore 		    MCDI_HEADER_NOT_EPOCH, new_epoch ? 0 : 1,
300*49ef7e06SGarrett D'Amore 		    MCDI_HEADER_ERROR, 0,
301*49ef7e06SGarrett D'Amore 		    MCDI_HEADER_RESPONSE, 0,
302*49ef7e06SGarrett D'Amore 		    MCDI_HEADER_XFLAGS, xflags);
303*49ef7e06SGarrett D'Amore 
304*49ef7e06SGarrett D'Amore 		EFX_POPULATE_DWORD_2(hdr[1],
305*49ef7e06SGarrett D'Amore 		    MC_CMD_V2_EXTN_IN_EXTENDED_CMD, emrp->emr_cmd,
306*49ef7e06SGarrett D'Amore 		    MC_CMD_V2_EXTN_IN_ACTUAL_LEN, emrp->emr_in_length);
307*49ef7e06SGarrett D'Amore 	} else {
308*49ef7e06SGarrett D'Amore 		/* Construct MCDI v1 header */
309*49ef7e06SGarrett D'Amore 		hdr_len = sizeof (hdr[0]);
310*49ef7e06SGarrett D'Amore 		EFX_POPULATE_DWORD_8(hdr[0],
311*49ef7e06SGarrett D'Amore 		    MCDI_HEADER_CODE, emrp->emr_cmd,
312*49ef7e06SGarrett D'Amore 		    MCDI_HEADER_RESYNC, 1,
313*49ef7e06SGarrett D'Amore 		    MCDI_HEADER_DATALEN, emrp->emr_in_length,
314*49ef7e06SGarrett D'Amore 		    MCDI_HEADER_SEQ, seq,
315*49ef7e06SGarrett D'Amore 		    MCDI_HEADER_NOT_EPOCH, new_epoch ? 0 : 1,
316*49ef7e06SGarrett D'Amore 		    MCDI_HEADER_ERROR, 0,
317*49ef7e06SGarrett D'Amore 		    MCDI_HEADER_RESPONSE, 0,
318*49ef7e06SGarrett D'Amore 		    MCDI_HEADER_XFLAGS, xflags);
319*49ef7e06SGarrett D'Amore 	}
320*49ef7e06SGarrett D'Amore 
321*49ef7e06SGarrett D'Amore #if EFSYS_OPT_MCDI_LOGGING
322*49ef7e06SGarrett D'Amore 	if (emtp->emt_logger != NULL) {
323*49ef7e06SGarrett D'Amore 		emtp->emt_logger(emtp->emt_context, EFX_LOG_MCDI_REQUEST,
324*49ef7e06SGarrett D'Amore 		    &hdr[0], hdr_len,
325*49ef7e06SGarrett D'Amore 		    emrp->emr_in_buf, emrp->emr_in_length);
326*49ef7e06SGarrett D'Amore 	}
327*49ef7e06SGarrett D'Amore #endif /* EFSYS_OPT_MCDI_LOGGING */
328*49ef7e06SGarrett D'Amore 
329*49ef7e06SGarrett D'Amore 	efx_mcdi_send_request(enp, &hdr[0], hdr_len,
330*49ef7e06SGarrett D'Amore 	    emrp->emr_in_buf, emrp->emr_in_length);
331*49ef7e06SGarrett D'Amore }
332*49ef7e06SGarrett D'Amore 
333*49ef7e06SGarrett D'Amore 
334*49ef7e06SGarrett D'Amore static			void
efx_mcdi_read_response_header(__in efx_nic_t * enp,__inout efx_mcdi_req_t * emrp)335*49ef7e06SGarrett D'Amore efx_mcdi_read_response_header(
336*49ef7e06SGarrett D'Amore 	__in		efx_nic_t *enp,
337*49ef7e06SGarrett D'Amore 	__inout		efx_mcdi_req_t *emrp)
338*49ef7e06SGarrett D'Amore {
339*49ef7e06SGarrett D'Amore #if EFSYS_OPT_MCDI_LOGGING
340*49ef7e06SGarrett D'Amore 	const efx_mcdi_transport_t *emtp = enp->en_mcdi.em_emtp;
341*49ef7e06SGarrett D'Amore #endif /* EFSYS_OPT_MCDI_LOGGING */
342*49ef7e06SGarrett D'Amore 	efx_mcdi_iface_t *emip = &(enp->en_mcdi.em_emip);
343*49ef7e06SGarrett D'Amore 	efx_dword_t hdr[2];
344*49ef7e06SGarrett D'Amore 	unsigned int hdr_len;
345*49ef7e06SGarrett D'Amore 	unsigned int data_len;
346*49ef7e06SGarrett D'Amore 	unsigned int seq;
347*49ef7e06SGarrett D'Amore 	unsigned int cmd;
348*49ef7e06SGarrett D'Amore 	unsigned int error;
349*49ef7e06SGarrett D'Amore 	efx_rc_t rc;
350*49ef7e06SGarrett D'Amore 
351*49ef7e06SGarrett D'Amore 	EFSYS_ASSERT(emrp != NULL);
352*49ef7e06SGarrett D'Amore 
353*49ef7e06SGarrett D'Amore 	efx_mcdi_read_response(enp, &hdr[0], 0, sizeof (hdr[0]));
354*49ef7e06SGarrett D'Amore 	hdr_len = sizeof (hdr[0]);
355*49ef7e06SGarrett D'Amore 
356*49ef7e06SGarrett D'Amore 	cmd = EFX_DWORD_FIELD(hdr[0], MCDI_HEADER_CODE);
357*49ef7e06SGarrett D'Amore 	seq = EFX_DWORD_FIELD(hdr[0], MCDI_HEADER_SEQ);
358*49ef7e06SGarrett D'Amore 	error = EFX_DWORD_FIELD(hdr[0], MCDI_HEADER_ERROR);
359*49ef7e06SGarrett D'Amore 
360*49ef7e06SGarrett D'Amore 	if (cmd != MC_CMD_V2_EXTN) {
361*49ef7e06SGarrett D'Amore 		data_len = EFX_DWORD_FIELD(hdr[0], MCDI_HEADER_DATALEN);
362*49ef7e06SGarrett D'Amore 	} else {
363*49ef7e06SGarrett D'Amore 		efx_mcdi_read_response(enp, &hdr[1], hdr_len, sizeof (hdr[1]));
364*49ef7e06SGarrett D'Amore 		hdr_len += sizeof (hdr[1]);
365*49ef7e06SGarrett D'Amore 
366*49ef7e06SGarrett D'Amore 		cmd = EFX_DWORD_FIELD(hdr[1], MC_CMD_V2_EXTN_IN_EXTENDED_CMD);
367*49ef7e06SGarrett D'Amore 		data_len =
368*49ef7e06SGarrett D'Amore 		    EFX_DWORD_FIELD(hdr[1], MC_CMD_V2_EXTN_IN_ACTUAL_LEN);
369*49ef7e06SGarrett D'Amore 	}
370*49ef7e06SGarrett D'Amore 
371*49ef7e06SGarrett D'Amore 	if (error && (data_len == 0)) {
372*49ef7e06SGarrett D'Amore 		/* The MC has rebooted since the request was sent. */
373*49ef7e06SGarrett D'Amore 		EFSYS_SPIN(EFX_MCDI_STATUS_SLEEP_US);
374*49ef7e06SGarrett D'Amore 		(void) efx_mcdi_poll_reboot(enp);
375*49ef7e06SGarrett D'Amore 		rc = EIO;
376*49ef7e06SGarrett D'Amore 		goto fail1;
377*49ef7e06SGarrett D'Amore 	}
378*49ef7e06SGarrett D'Amore 	if ((cmd != emrp->emr_cmd) ||
379*49ef7e06SGarrett D'Amore 	    (seq != ((emip->emi_seq - 1) & EFX_MASK32(MCDI_HEADER_SEQ)))) {
380*49ef7e06SGarrett D'Amore 		/* Response is for a different request */
381*49ef7e06SGarrett D'Amore 		rc = EIO;
382*49ef7e06SGarrett D'Amore 		goto fail2;
383*49ef7e06SGarrett D'Amore 	}
384*49ef7e06SGarrett D'Amore 	if (error) {
385*49ef7e06SGarrett D'Amore 		efx_dword_t err[2];
386*49ef7e06SGarrett D'Amore 		unsigned int err_len = MIN(data_len, sizeof (err));
387*49ef7e06SGarrett D'Amore 		int err_code = MC_CMD_ERR_EPROTO;
388*49ef7e06SGarrett D'Amore 		int err_arg = 0;
389*49ef7e06SGarrett D'Amore 
390*49ef7e06SGarrett D'Amore 		/* Read error code (and arg num for MCDI v2 commands) */
391*49ef7e06SGarrett D'Amore 		efx_mcdi_read_response(enp, &err, hdr_len, err_len);
392*49ef7e06SGarrett D'Amore 
393*49ef7e06SGarrett D'Amore 		if (err_len >= (MC_CMD_ERR_CODE_OFST + sizeof (efx_dword_t)))
394*49ef7e06SGarrett D'Amore 			err_code = EFX_DWORD_FIELD(err[0], EFX_DWORD_0);
395*49ef7e06SGarrett D'Amore #ifdef WITH_MCDI_V2
396*49ef7e06SGarrett D'Amore 		if (err_len >= (MC_CMD_ERR_ARG_OFST + sizeof (efx_dword_t)))
397*49ef7e06SGarrett D'Amore 			err_arg = EFX_DWORD_FIELD(err[1], EFX_DWORD_0);
398*49ef7e06SGarrett D'Amore #endif
399*49ef7e06SGarrett D'Amore 		emrp->emr_err_code = err_code;
400*49ef7e06SGarrett D'Amore 		emrp->emr_err_arg = err_arg;
401*49ef7e06SGarrett D'Amore 
402*49ef7e06SGarrett D'Amore #if EFSYS_OPT_MCDI_PROXY_AUTH
403*49ef7e06SGarrett D'Amore 		if ((err_code == MC_CMD_ERR_PROXY_PENDING) &&
404*49ef7e06SGarrett D'Amore 		    (err_len == sizeof (err))) {
405*49ef7e06SGarrett D'Amore 			/*
406*49ef7e06SGarrett D'Amore 			 * The MCDI request would normally fail with EPERM, but
407*49ef7e06SGarrett D'Amore 			 * firmware has forwarded it to an authorization agent
408*49ef7e06SGarrett D'Amore 			 * attached to a privileged PF.
409*49ef7e06SGarrett D'Amore 			 *
410*49ef7e06SGarrett D'Amore 			 * Save the authorization request handle. The client
411*49ef7e06SGarrett D'Amore 			 * must wait for a PROXY_RESPONSE event, or timeout.
412*49ef7e06SGarrett D'Amore 			 */
413*49ef7e06SGarrett D'Amore 			emrp->emr_proxy_handle = err_arg;
414*49ef7e06SGarrett D'Amore 		}
415*49ef7e06SGarrett D'Amore #endif /* EFSYS_OPT_MCDI_PROXY_AUTH */
416*49ef7e06SGarrett D'Amore 
417*49ef7e06SGarrett D'Amore #if EFSYS_OPT_MCDI_LOGGING
418*49ef7e06SGarrett D'Amore 		if (emtp->emt_logger != NULL) {
419*49ef7e06SGarrett D'Amore 			emtp->emt_logger(emtp->emt_context,
420*49ef7e06SGarrett D'Amore 			    EFX_LOG_MCDI_RESPONSE,
421*49ef7e06SGarrett D'Amore 			    &hdr[0], hdr_len,
422*49ef7e06SGarrett D'Amore 			    &err[0], err_len);
423*49ef7e06SGarrett D'Amore 		}
424*49ef7e06SGarrett D'Amore #endif /* EFSYS_OPT_MCDI_LOGGING */
425*49ef7e06SGarrett D'Amore 
426*49ef7e06SGarrett D'Amore 		if (!emrp->emr_quiet) {
427*49ef7e06SGarrett D'Amore 			EFSYS_PROBE3(mcdi_err_arg, int, emrp->emr_cmd,
428*49ef7e06SGarrett D'Amore 			    int, err_code, int, err_arg);
429*49ef7e06SGarrett D'Amore 		}
430*49ef7e06SGarrett D'Amore 
431*49ef7e06SGarrett D'Amore 		rc = efx_mcdi_request_errcode(err_code);
432*49ef7e06SGarrett D'Amore 		goto fail3;
433*49ef7e06SGarrett D'Amore 	}
434*49ef7e06SGarrett D'Amore 
435*49ef7e06SGarrett D'Amore 	emrp->emr_rc = 0;
436*49ef7e06SGarrett D'Amore 	emrp->emr_out_length_used = data_len;
437*49ef7e06SGarrett D'Amore #if EFSYS_OPT_MCDI_PROXY_AUTH
438*49ef7e06SGarrett D'Amore 	emrp->emr_proxy_handle = 0;
439*49ef7e06SGarrett D'Amore #endif /* EFSYS_OPT_MCDI_PROXY_AUTH */
440*49ef7e06SGarrett D'Amore 	return;
441*49ef7e06SGarrett D'Amore 
442*49ef7e06SGarrett D'Amore fail3:
443*49ef7e06SGarrett D'Amore fail2:
444*49ef7e06SGarrett D'Amore fail1:
445*49ef7e06SGarrett D'Amore 	emrp->emr_rc = rc;
446*49ef7e06SGarrett D'Amore 	emrp->emr_out_length_used = 0;
447*49ef7e06SGarrett D'Amore }
448*49ef7e06SGarrett D'Amore 
449*49ef7e06SGarrett D'Amore static			void
efx_mcdi_finish_response(__in efx_nic_t * enp,__in efx_mcdi_req_t * emrp)450*49ef7e06SGarrett D'Amore efx_mcdi_finish_response(
451*49ef7e06SGarrett D'Amore 	__in		efx_nic_t *enp,
452*49ef7e06SGarrett D'Amore 	__in		efx_mcdi_req_t *emrp)
453*49ef7e06SGarrett D'Amore {
454*49ef7e06SGarrett D'Amore #if EFSYS_OPT_MCDI_LOGGING
455*49ef7e06SGarrett D'Amore 	const efx_mcdi_transport_t *emtp = enp->en_mcdi.em_emtp;
456*49ef7e06SGarrett D'Amore #endif /* EFSYS_OPT_MCDI_LOGGING */
457*49ef7e06SGarrett D'Amore 	efx_dword_t hdr[2];
458*49ef7e06SGarrett D'Amore 	unsigned int hdr_len;
459*49ef7e06SGarrett D'Amore 	size_t bytes;
460*49ef7e06SGarrett D'Amore 
461*49ef7e06SGarrett D'Amore 	if (emrp->emr_out_buf == NULL)
462*49ef7e06SGarrett D'Amore 		return;
463*49ef7e06SGarrett D'Amore 
464*49ef7e06SGarrett D'Amore 	/* Read the command header to detect MCDI response format */
465*49ef7e06SGarrett D'Amore 	hdr_len = sizeof (hdr[0]);
466*49ef7e06SGarrett D'Amore 	efx_mcdi_read_response(enp, &hdr[0], 0, hdr_len);
467*49ef7e06SGarrett D'Amore 	if (EFX_DWORD_FIELD(hdr[0], MCDI_HEADER_CODE) == MC_CMD_V2_EXTN) {
468*49ef7e06SGarrett D'Amore 		/*
469*49ef7e06SGarrett D'Amore 		 * Read the actual payload length. The length given in the event
470*49ef7e06SGarrett D'Amore 		 * is only correct for responses with the V1 format.
471*49ef7e06SGarrett D'Amore 		 */
472*49ef7e06SGarrett D'Amore 		efx_mcdi_read_response(enp, &hdr[1], hdr_len, sizeof (hdr[1]));
473*49ef7e06SGarrett D'Amore 		hdr_len += sizeof (hdr[1]);
474*49ef7e06SGarrett D'Amore 
475*49ef7e06SGarrett D'Amore 		emrp->emr_out_length_used = EFX_DWORD_FIELD(hdr[1],
476*49ef7e06SGarrett D'Amore 					    MC_CMD_V2_EXTN_IN_ACTUAL_LEN);
477*49ef7e06SGarrett D'Amore 	}
478*49ef7e06SGarrett D'Amore 
479*49ef7e06SGarrett D'Amore 	/* Copy payload out into caller supplied buffer */
480*49ef7e06SGarrett D'Amore 	bytes = MIN(emrp->emr_out_length_used, emrp->emr_out_length);
481*49ef7e06SGarrett D'Amore 	efx_mcdi_read_response(enp, emrp->emr_out_buf, hdr_len, bytes);
482*49ef7e06SGarrett D'Amore 
483*49ef7e06SGarrett D'Amore #if EFSYS_OPT_MCDI_LOGGING
484*49ef7e06SGarrett D'Amore 	if (emtp->emt_logger != NULL) {
485*49ef7e06SGarrett D'Amore 		emtp->emt_logger(emtp->emt_context,
486*49ef7e06SGarrett D'Amore 		    EFX_LOG_MCDI_RESPONSE,
487*49ef7e06SGarrett D'Amore 		    &hdr[0], hdr_len,
488*49ef7e06SGarrett D'Amore 		    emrp->emr_out_buf, bytes);
489*49ef7e06SGarrett D'Amore 	}
490*49ef7e06SGarrett D'Amore #endif /* EFSYS_OPT_MCDI_LOGGING */
491*49ef7e06SGarrett D'Amore }
492*49ef7e06SGarrett D'Amore 
493*49ef7e06SGarrett D'Amore 
494*49ef7e06SGarrett D'Amore 	__checkReturn	boolean_t
efx_mcdi_request_poll(__in efx_nic_t * enp)495*49ef7e06SGarrett D'Amore efx_mcdi_request_poll(
496*49ef7e06SGarrett D'Amore 	__in		efx_nic_t *enp)
497*49ef7e06SGarrett D'Amore {
498*49ef7e06SGarrett D'Amore 	efx_mcdi_iface_t *emip = &(enp->en_mcdi.em_emip);
499*49ef7e06SGarrett D'Amore 	efx_mcdi_req_t *emrp;
500*49ef7e06SGarrett D'Amore 	int state;
501*49ef7e06SGarrett D'Amore 	efx_rc_t rc;
502*49ef7e06SGarrett D'Amore 
503*49ef7e06SGarrett D'Amore 	EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
504*49ef7e06SGarrett D'Amore 	EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_MCDI);
505*49ef7e06SGarrett D'Amore 	EFSYS_ASSERT3U(enp->en_features, &, EFX_FEATURE_MCDI);
506*49ef7e06SGarrett D'Amore 
507*49ef7e06SGarrett D'Amore 	/* Serialise against post-watchdog efx_mcdi_ev* */
508*49ef7e06SGarrett D'Amore 	EFSYS_LOCK(enp->en_eslp, state);
509*49ef7e06SGarrett D'Amore 
510*49ef7e06SGarrett D'Amore 	EFSYS_ASSERT(emip->emi_pending_req != NULL);
511*49ef7e06SGarrett D'Amore 	EFSYS_ASSERT(!emip->emi_ev_cpl);
512*49ef7e06SGarrett D'Amore 	emrp = emip->emi_pending_req;
513*49ef7e06SGarrett D'Amore 
514*49ef7e06SGarrett D'Amore 	/* Check for reboot atomically w.r.t efx_mcdi_request_start */
515*49ef7e06SGarrett D'Amore 	if (emip->emi_poll_cnt++ == 0) {
516*49ef7e06SGarrett D'Amore 		if ((rc = efx_mcdi_poll_reboot(enp)) != 0) {
517*49ef7e06SGarrett D'Amore 			emip->emi_pending_req = NULL;
518*49ef7e06SGarrett D'Amore 			EFSYS_UNLOCK(enp->en_eslp, state);
519*49ef7e06SGarrett D'Amore 			goto fail1;
520*49ef7e06SGarrett D'Amore 		}
521*49ef7e06SGarrett D'Amore 	}
522*49ef7e06SGarrett D'Amore 
523*49ef7e06SGarrett D'Amore 	/* Check if a response is available */
524*49ef7e06SGarrett D'Amore 	if (efx_mcdi_poll_response(enp) == B_FALSE) {
525*49ef7e06SGarrett D'Amore 		EFSYS_UNLOCK(enp->en_eslp, state);
526*49ef7e06SGarrett D'Amore 		return (B_FALSE);
527*49ef7e06SGarrett D'Amore 	}
528*49ef7e06SGarrett D'Amore 
529*49ef7e06SGarrett D'Amore 	/* Read the response header */
530*49ef7e06SGarrett D'Amore 	efx_mcdi_read_response_header(enp, emrp);
531*49ef7e06SGarrett D'Amore 
532*49ef7e06SGarrett D'Amore 	/* Request complete */
533*49ef7e06SGarrett D'Amore 	emip->emi_pending_req = NULL;
534*49ef7e06SGarrett D'Amore 
535*49ef7e06SGarrett D'Amore 	EFSYS_UNLOCK(enp->en_eslp, state);
536*49ef7e06SGarrett D'Amore 
537*49ef7e06SGarrett D'Amore 	if ((rc = emrp->emr_rc) != 0)
538*49ef7e06SGarrett D'Amore 		goto fail2;
539*49ef7e06SGarrett D'Amore 
540*49ef7e06SGarrett D'Amore 	efx_mcdi_finish_response(enp, emrp);
541*49ef7e06SGarrett D'Amore 	return (B_TRUE);
542*49ef7e06SGarrett D'Amore 
543*49ef7e06SGarrett D'Amore fail2:
544*49ef7e06SGarrett D'Amore 	if (!emrp->emr_quiet)
545*49ef7e06SGarrett D'Amore 		EFSYS_PROBE(fail2);
546*49ef7e06SGarrett D'Amore fail1:
547*49ef7e06SGarrett D'Amore 	if (!emrp->emr_quiet)
548*49ef7e06SGarrett D'Amore 		EFSYS_PROBE1(fail1, efx_rc_t, rc);
549*49ef7e06SGarrett D'Amore 
550*49ef7e06SGarrett D'Amore 	/* Reboot/Assertion */
551*49ef7e06SGarrett D'Amore 	if (rc == EIO || rc == EINTR)
552*49ef7e06SGarrett D'Amore 		efx_mcdi_raise_exception(enp, emrp, rc);
553*49ef7e06SGarrett D'Amore 
554*49ef7e06SGarrett D'Amore 	return (B_TRUE);
555*49ef7e06SGarrett D'Amore }
556*49ef7e06SGarrett D'Amore 
557*49ef7e06SGarrett D'Amore 	__checkReturn	boolean_t
efx_mcdi_request_abort(__in efx_nic_t * enp)558*49ef7e06SGarrett D'Amore efx_mcdi_request_abort(
559*49ef7e06SGarrett D'Amore 	__in		efx_nic_t *enp)
560*49ef7e06SGarrett D'Amore {
561*49ef7e06SGarrett D'Amore 	efx_mcdi_iface_t *emip = &(enp->en_mcdi.em_emip);
562*49ef7e06SGarrett D'Amore 	efx_mcdi_req_t *emrp;
563*49ef7e06SGarrett D'Amore 	boolean_t aborted;
564*49ef7e06SGarrett D'Amore 	int state;
565*49ef7e06SGarrett D'Amore 
566*49ef7e06SGarrett D'Amore 	EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
567*49ef7e06SGarrett D'Amore 	EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_MCDI);
568*49ef7e06SGarrett D'Amore 	EFSYS_ASSERT3U(enp->en_features, &, EFX_FEATURE_MCDI);
569*49ef7e06SGarrett D'Amore 
570*49ef7e06SGarrett D'Amore 	/*
571*49ef7e06SGarrett D'Amore 	 * efx_mcdi_ev_* may have already completed this event, and be
572*49ef7e06SGarrett D'Amore 	 * spinning/blocked on the upper layer lock. So it *is* legitimate
573*49ef7e06SGarrett D'Amore 	 * to for emi_pending_req to be NULL. If there is a pending event
574*49ef7e06SGarrett D'Amore 	 * completed request, then provide a "credit" to allow
575*49ef7e06SGarrett D'Amore 	 * efx_mcdi_ev_cpl() to accept a single spurious completion.
576*49ef7e06SGarrett D'Amore 	 */
577*49ef7e06SGarrett D'Amore 	EFSYS_LOCK(enp->en_eslp, state);
578*49ef7e06SGarrett D'Amore 	emrp = emip->emi_pending_req;
579*49ef7e06SGarrett D'Amore 	aborted = (emrp != NULL);
580*49ef7e06SGarrett D'Amore 	if (aborted) {
581*49ef7e06SGarrett D'Amore 		emip->emi_pending_req = NULL;
582*49ef7e06SGarrett D'Amore 
583*49ef7e06SGarrett D'Amore 		/* Error the request */
584*49ef7e06SGarrett D'Amore 		emrp->emr_out_length_used = 0;
585*49ef7e06SGarrett D'Amore 		emrp->emr_rc = ETIMEDOUT;
586*49ef7e06SGarrett D'Amore 
587*49ef7e06SGarrett D'Amore 		/* Provide a credit for seqno/emr_pending_req mismatches */
588*49ef7e06SGarrett D'Amore 		if (emip->emi_ev_cpl)
589*49ef7e06SGarrett D'Amore 			++emip->emi_aborted;
590*49ef7e06SGarrett D'Amore 
591*49ef7e06SGarrett D'Amore 		/*
592*49ef7e06SGarrett D'Amore 		 * The upper layer has called us, so we don't
593*49ef7e06SGarrett D'Amore 		 * need to complete the request.
594*49ef7e06SGarrett D'Amore 		 */
595*49ef7e06SGarrett D'Amore 	}
596*49ef7e06SGarrett D'Amore 	EFSYS_UNLOCK(enp->en_eslp, state);
597*49ef7e06SGarrett D'Amore 
598*49ef7e06SGarrett D'Amore 	return (aborted);
599*49ef7e06SGarrett D'Amore }
600*49ef7e06SGarrett D'Amore 
601*49ef7e06SGarrett D'Amore 	__checkReturn	efx_rc_t
efx_mcdi_request_errcode(__in unsigned int err)602*49ef7e06SGarrett D'Amore efx_mcdi_request_errcode(
603*49ef7e06SGarrett D'Amore 	__in		unsigned int err)
604*49ef7e06SGarrett D'Amore {
605*49ef7e06SGarrett D'Amore 
606*49ef7e06SGarrett D'Amore 	switch (err) {
607*49ef7e06SGarrett D'Amore 		/* MCDI v1 */
608*49ef7e06SGarrett D'Amore 	case MC_CMD_ERR_EPERM:
609*49ef7e06SGarrett D'Amore 		return (EACCES);
610*49ef7e06SGarrett D'Amore 	case MC_CMD_ERR_ENOENT:
611*49ef7e06SGarrett D'Amore 		return (ENOENT);
612*49ef7e06SGarrett D'Amore 	case MC_CMD_ERR_EINTR:
613*49ef7e06SGarrett D'Amore 		return (EINTR);
614*49ef7e06SGarrett D'Amore 	case MC_CMD_ERR_EACCES:
615*49ef7e06SGarrett D'Amore 		return (EACCES);
616*49ef7e06SGarrett D'Amore 	case MC_CMD_ERR_EBUSY:
617*49ef7e06SGarrett D'Amore 		return (EBUSY);
618*49ef7e06SGarrett D'Amore 	case MC_CMD_ERR_EINVAL:
619*49ef7e06SGarrett D'Amore 		return (EINVAL);
620*49ef7e06SGarrett D'Amore 	case MC_CMD_ERR_EDEADLK:
621*49ef7e06SGarrett D'Amore 		return (EDEADLK);
622*49ef7e06SGarrett D'Amore 	case MC_CMD_ERR_ENOSYS:
623*49ef7e06SGarrett D'Amore 		return (ENOTSUP);
624*49ef7e06SGarrett D'Amore 	case MC_CMD_ERR_ETIME:
625*49ef7e06SGarrett D'Amore 		return (ETIMEDOUT);
626*49ef7e06SGarrett D'Amore 	case MC_CMD_ERR_ENOTSUP:
627*49ef7e06SGarrett D'Amore 		return (ENOTSUP);
628*49ef7e06SGarrett D'Amore 	case MC_CMD_ERR_EALREADY:
629*49ef7e06SGarrett D'Amore 		return (EALREADY);
630*49ef7e06SGarrett D'Amore 
631*49ef7e06SGarrett D'Amore 		/* MCDI v2 */
632*49ef7e06SGarrett D'Amore #ifdef MC_CMD_ERR_EAGAIN
633*49ef7e06SGarrett D'Amore 	case MC_CMD_ERR_EAGAIN:
634*49ef7e06SGarrett D'Amore 		return (EAGAIN);
635*49ef7e06SGarrett D'Amore #endif
636*49ef7e06SGarrett D'Amore #ifdef MC_CMD_ERR_ENOSPC
637*49ef7e06SGarrett D'Amore 	case MC_CMD_ERR_ENOSPC:
638*49ef7e06SGarrett D'Amore 		return (ENOSPC);
639*49ef7e06SGarrett D'Amore #endif
640*49ef7e06SGarrett D'Amore 
641*49ef7e06SGarrett D'Amore 	case MC_CMD_ERR_ALLOC_FAIL:
642*49ef7e06SGarrett D'Amore 		return (ENOMEM);
643*49ef7e06SGarrett D'Amore 	case MC_CMD_ERR_NO_VADAPTOR:
644*49ef7e06SGarrett D'Amore 		return (ENOENT);
645*49ef7e06SGarrett D'Amore 	case MC_CMD_ERR_NO_EVB_PORT:
646*49ef7e06SGarrett D'Amore 		return (ENOENT);
647*49ef7e06SGarrett D'Amore 	case MC_CMD_ERR_NO_VSWITCH:
648*49ef7e06SGarrett D'Amore 		return (ENODEV);
649*49ef7e06SGarrett D'Amore 	case MC_CMD_ERR_VLAN_LIMIT:
650*49ef7e06SGarrett D'Amore 		return (EINVAL);
651*49ef7e06SGarrett D'Amore 	case MC_CMD_ERR_BAD_PCI_FUNC:
652*49ef7e06SGarrett D'Amore 		return (ENODEV);
653*49ef7e06SGarrett D'Amore 	case MC_CMD_ERR_BAD_VLAN_MODE:
654*49ef7e06SGarrett D'Amore 		return (EINVAL);
655*49ef7e06SGarrett D'Amore 	case MC_CMD_ERR_BAD_VSWITCH_TYPE:
656*49ef7e06SGarrett D'Amore 		return (EINVAL);
657*49ef7e06SGarrett D'Amore 	case MC_CMD_ERR_BAD_VPORT_TYPE:
658*49ef7e06SGarrett D'Amore 		return (EINVAL);
659*49ef7e06SGarrett D'Amore 	case MC_CMD_ERR_MAC_EXIST:
660*49ef7e06SGarrett D'Amore 		return (EEXIST);
661*49ef7e06SGarrett D'Amore 
662*49ef7e06SGarrett D'Amore 	case MC_CMD_ERR_PROXY_PENDING:
663*49ef7e06SGarrett D'Amore 		return (EAGAIN);
664*49ef7e06SGarrett D'Amore 
665*49ef7e06SGarrett D'Amore 	default:
666*49ef7e06SGarrett D'Amore 		EFSYS_PROBE1(mc_pcol_error, int, err);
667*49ef7e06SGarrett D'Amore 		return (EIO);
668*49ef7e06SGarrett D'Amore 	}
669*49ef7e06SGarrett D'Amore }
670*49ef7e06SGarrett D'Amore 
671*49ef7e06SGarrett D'Amore 			void
efx_mcdi_raise_exception(__in efx_nic_t * enp,__in_opt efx_mcdi_req_t * emrp,__in int rc)672*49ef7e06SGarrett D'Amore efx_mcdi_raise_exception(
673*49ef7e06SGarrett D'Amore 	__in		efx_nic_t *enp,
674*49ef7e06SGarrett D'Amore 	__in_opt	efx_mcdi_req_t *emrp,
675*49ef7e06SGarrett D'Amore 	__in		int rc)
676*49ef7e06SGarrett D'Amore {
677*49ef7e06SGarrett D'Amore 	const efx_mcdi_transport_t *emtp = enp->en_mcdi.em_emtp;
678*49ef7e06SGarrett D'Amore 	efx_mcdi_exception_t exception;
679*49ef7e06SGarrett D'Amore 
680*49ef7e06SGarrett D'Amore 	/* Reboot or Assertion failure only */
681*49ef7e06SGarrett D'Amore 	EFSYS_ASSERT(rc == EIO || rc == EINTR);
682*49ef7e06SGarrett D'Amore 
683*49ef7e06SGarrett D'Amore 	/*
684*49ef7e06SGarrett D'Amore 	 * If MC_CMD_REBOOT causes a reboot (dependent on parameters),
685*49ef7e06SGarrett D'Amore 	 * then the EIO is not worthy of an exception.
686*49ef7e06SGarrett D'Amore 	 */
687*49ef7e06SGarrett D'Amore 	if (emrp != NULL && emrp->emr_cmd == MC_CMD_REBOOT && rc == EIO)
688*49ef7e06SGarrett D'Amore 		return;
689*49ef7e06SGarrett D'Amore 
690*49ef7e06SGarrett D'Amore 	exception = (rc == EIO)
691*49ef7e06SGarrett D'Amore 		? EFX_MCDI_EXCEPTION_MC_REBOOT
692*49ef7e06SGarrett D'Amore 		: EFX_MCDI_EXCEPTION_MC_BADASSERT;
693*49ef7e06SGarrett D'Amore 
694*49ef7e06SGarrett D'Amore 	emtp->emt_exception(emtp->emt_context, exception);
695*49ef7e06SGarrett D'Amore }
696*49ef7e06SGarrett D'Amore 
697*49ef7e06SGarrett D'Amore 			void
efx_mcdi_execute(__in efx_nic_t * enp,__inout efx_mcdi_req_t * emrp)698*49ef7e06SGarrett D'Amore efx_mcdi_execute(
699*49ef7e06SGarrett D'Amore 	__in		efx_nic_t *enp,
700*49ef7e06SGarrett D'Amore 	__inout		efx_mcdi_req_t *emrp)
701*49ef7e06SGarrett D'Amore {
702*49ef7e06SGarrett D'Amore 	const efx_mcdi_transport_t *emtp = enp->en_mcdi.em_emtp;
703*49ef7e06SGarrett D'Amore 
704*49ef7e06SGarrett D'Amore 	EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_MCDI);
705*49ef7e06SGarrett D'Amore 	EFSYS_ASSERT3U(enp->en_features, &, EFX_FEATURE_MCDI);
706*49ef7e06SGarrett D'Amore 
707*49ef7e06SGarrett D'Amore 	emrp->emr_quiet = B_FALSE;
708*49ef7e06SGarrett D'Amore 	emtp->emt_execute(emtp->emt_context, emrp);
709*49ef7e06SGarrett D'Amore }
710*49ef7e06SGarrett D'Amore 
711*49ef7e06SGarrett D'Amore 			void
efx_mcdi_execute_quiet(__in efx_nic_t * enp,__inout efx_mcdi_req_t * emrp)712*49ef7e06SGarrett D'Amore efx_mcdi_execute_quiet(
713*49ef7e06SGarrett D'Amore 	__in		efx_nic_t *enp,
714*49ef7e06SGarrett D'Amore 	__inout		efx_mcdi_req_t *emrp)
715*49ef7e06SGarrett D'Amore {
716*49ef7e06SGarrett D'Amore 	const efx_mcdi_transport_t *emtp = enp->en_mcdi.em_emtp;
717*49ef7e06SGarrett D'Amore 
718*49ef7e06SGarrett D'Amore 	EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_MCDI);
719*49ef7e06SGarrett D'Amore 	EFSYS_ASSERT3U(enp->en_features, &, EFX_FEATURE_MCDI);
720*49ef7e06SGarrett D'Amore 
721*49ef7e06SGarrett D'Amore 	emrp->emr_quiet = B_TRUE;
722*49ef7e06SGarrett D'Amore 	emtp->emt_execute(emtp->emt_context, emrp);
723*49ef7e06SGarrett D'Amore }
724*49ef7e06SGarrett D'Amore 
725*49ef7e06SGarrett D'Amore 			void
efx_mcdi_ev_cpl(__in efx_nic_t * enp,__in unsigned int seq,__in unsigned int outlen,__in int errcode)726*49ef7e06SGarrett D'Amore efx_mcdi_ev_cpl(
727*49ef7e06SGarrett D'Amore 	__in		efx_nic_t *enp,
728*49ef7e06SGarrett D'Amore 	__in		unsigned int seq,
729*49ef7e06SGarrett D'Amore 	__in		unsigned int outlen,
730*49ef7e06SGarrett D'Amore 	__in		int errcode)
731*49ef7e06SGarrett D'Amore {
732*49ef7e06SGarrett D'Amore 	efx_mcdi_iface_t *emip = &(enp->en_mcdi.em_emip);
733*49ef7e06SGarrett D'Amore 	const efx_mcdi_transport_t *emtp = enp->en_mcdi.em_emtp;
734*49ef7e06SGarrett D'Amore 	efx_mcdi_req_t *emrp;
735*49ef7e06SGarrett D'Amore 	int state;
736*49ef7e06SGarrett D'Amore 
737*49ef7e06SGarrett D'Amore 	EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_MCDI);
738*49ef7e06SGarrett D'Amore 	EFSYS_ASSERT3U(enp->en_features, &, EFX_FEATURE_MCDI);
739*49ef7e06SGarrett D'Amore 
740*49ef7e06SGarrett D'Amore 	/*
741*49ef7e06SGarrett D'Amore 	 * Serialise against efx_mcdi_request_poll()/efx_mcdi_request_start()
742*49ef7e06SGarrett D'Amore 	 * when we're completing an aborted request.
743*49ef7e06SGarrett D'Amore 	 */
744*49ef7e06SGarrett D'Amore 	EFSYS_LOCK(enp->en_eslp, state);
745*49ef7e06SGarrett D'Amore 	if (emip->emi_pending_req == NULL || !emip->emi_ev_cpl ||
746*49ef7e06SGarrett D'Amore 	    (seq != ((emip->emi_seq - 1) & EFX_MASK32(MCDI_HEADER_SEQ)))) {
747*49ef7e06SGarrett D'Amore 		EFSYS_ASSERT(emip->emi_aborted > 0);
748*49ef7e06SGarrett D'Amore 		if (emip->emi_aborted > 0)
749*49ef7e06SGarrett D'Amore 			--emip->emi_aborted;
750*49ef7e06SGarrett D'Amore 		EFSYS_UNLOCK(enp->en_eslp, state);
751*49ef7e06SGarrett D'Amore 		return;
752*49ef7e06SGarrett D'Amore 	}
753*49ef7e06SGarrett D'Amore 
754*49ef7e06SGarrett D'Amore 	emrp = emip->emi_pending_req;
755*49ef7e06SGarrett D'Amore 	emip->emi_pending_req = NULL;
756*49ef7e06SGarrett D'Amore 	EFSYS_UNLOCK(enp->en_eslp, state);
757*49ef7e06SGarrett D'Amore 
758*49ef7e06SGarrett D'Amore 	if (emip->emi_max_version >= 2) {
759*49ef7e06SGarrett D'Amore 		/* MCDIv2 response details do not fit into an event. */
760*49ef7e06SGarrett D'Amore 		efx_mcdi_read_response_header(enp, emrp);
761*49ef7e06SGarrett D'Amore 	} else {
762*49ef7e06SGarrett D'Amore 		if (errcode != 0) {
763*49ef7e06SGarrett D'Amore 			if (!emrp->emr_quiet) {
764*49ef7e06SGarrett D'Amore 				EFSYS_PROBE2(mcdi_err, int, emrp->emr_cmd,
765*49ef7e06SGarrett D'Amore 				    int, errcode);
766*49ef7e06SGarrett D'Amore 			}
767*49ef7e06SGarrett D'Amore 			emrp->emr_out_length_used = 0;
768*49ef7e06SGarrett D'Amore 			emrp->emr_rc = efx_mcdi_request_errcode(errcode);
769*49ef7e06SGarrett D'Amore 		} else {
770*49ef7e06SGarrett D'Amore 			emrp->emr_out_length_used = outlen;
771*49ef7e06SGarrett D'Amore 			emrp->emr_rc = 0;
772*49ef7e06SGarrett D'Amore 		}
773*49ef7e06SGarrett D'Amore 	}
774*49ef7e06SGarrett D'Amore 	if (errcode == 0) {
775*49ef7e06SGarrett D'Amore 		efx_mcdi_finish_response(enp, emrp);
776*49ef7e06SGarrett D'Amore 	}
777*49ef7e06SGarrett D'Amore 
778*49ef7e06SGarrett D'Amore 	emtp->emt_ev_cpl(emtp->emt_context);
779*49ef7e06SGarrett D'Amore }
780*49ef7e06SGarrett D'Amore 
781*49ef7e06SGarrett D'Amore #if EFSYS_OPT_MCDI_PROXY_AUTH
782*49ef7e06SGarrett D'Amore 
783*49ef7e06SGarrett D'Amore 	__checkReturn	efx_rc_t
efx_mcdi_get_proxy_handle(__in efx_nic_t * enp,__in efx_mcdi_req_t * emrp,__out uint32_t * handlep)784*49ef7e06SGarrett D'Amore efx_mcdi_get_proxy_handle(
785*49ef7e06SGarrett D'Amore 	__in		efx_nic_t *enp,
786*49ef7e06SGarrett D'Amore 	__in		efx_mcdi_req_t *emrp,
787*49ef7e06SGarrett D'Amore 	__out		uint32_t *handlep)
788*49ef7e06SGarrett D'Amore {
789*49ef7e06SGarrett D'Amore 	efx_mcdi_iface_t *emip = &(enp->en_mcdi.em_emip);
790*49ef7e06SGarrett D'Amore 	efx_rc_t rc;
791*49ef7e06SGarrett D'Amore 
792*49ef7e06SGarrett D'Amore 	/*
793*49ef7e06SGarrett D'Amore 	 * Return proxy handle from MCDI request that returned with error
794*49ef7e06SGarrett D'Amore 	 * MC_MCD_ERR_PROXY_PENDING. This handle is used to wait for a matching
795*49ef7e06SGarrett D'Amore 	 * PROXY_RESPONSE event.
796*49ef7e06SGarrett D'Amore 	 */
797*49ef7e06SGarrett D'Amore 	if ((emrp == NULL) || (handlep == NULL)) {
798*49ef7e06SGarrett D'Amore 		rc = EINVAL;
799*49ef7e06SGarrett D'Amore 		goto fail1;
800*49ef7e06SGarrett D'Amore 	}
801*49ef7e06SGarrett D'Amore 	if ((emrp->emr_rc != 0) &&
802*49ef7e06SGarrett D'Amore 	    (emrp->emr_err_code == MC_CMD_ERR_PROXY_PENDING)) {
803*49ef7e06SGarrett D'Amore 		*handlep = emrp->emr_proxy_handle;
804*49ef7e06SGarrett D'Amore 		rc = 0;
805*49ef7e06SGarrett D'Amore 	} else {
806*49ef7e06SGarrett D'Amore 		*handlep = 0;
807*49ef7e06SGarrett D'Amore 		rc = ENOENT;
808*49ef7e06SGarrett D'Amore 	}
809*49ef7e06SGarrett D'Amore 	return (rc);
810*49ef7e06SGarrett D'Amore 
811*49ef7e06SGarrett D'Amore fail1:
812*49ef7e06SGarrett D'Amore 	EFSYS_PROBE1(fail1, efx_rc_t, rc);
813*49ef7e06SGarrett D'Amore 	return (rc);
814*49ef7e06SGarrett D'Amore }
815*49ef7e06SGarrett D'Amore 
816*49ef7e06SGarrett D'Amore 			void
efx_mcdi_ev_proxy_response(__in efx_nic_t * enp,__in unsigned int handle,__in unsigned int status)817*49ef7e06SGarrett D'Amore efx_mcdi_ev_proxy_response(
818*49ef7e06SGarrett D'Amore 	__in		efx_nic_t *enp,
819*49ef7e06SGarrett D'Amore 	__in		unsigned int handle,
820*49ef7e06SGarrett D'Amore 	__in		unsigned int status)
821*49ef7e06SGarrett D'Amore {
822*49ef7e06SGarrett D'Amore 	const efx_mcdi_transport_t *emtp = enp->en_mcdi.em_emtp;
823*49ef7e06SGarrett D'Amore 	efx_rc_t rc;
824*49ef7e06SGarrett D'Amore 
825*49ef7e06SGarrett D'Amore 	/*
826*49ef7e06SGarrett D'Amore 	 * Handle results of an authorization request for a privileged MCDI
827*49ef7e06SGarrett D'Amore 	 * command. If authorization was granted then we must re-issue the
828*49ef7e06SGarrett D'Amore 	 * original MCDI request. If authorization failed or timed out,
829*49ef7e06SGarrett D'Amore 	 * then the original MCDI request should be completed with the
830*49ef7e06SGarrett D'Amore 	 * result code from this event.
831*49ef7e06SGarrett D'Amore 	 */
832*49ef7e06SGarrett D'Amore 	rc = (status == 0) ? 0 : efx_mcdi_request_errcode(status);
833*49ef7e06SGarrett D'Amore 
834*49ef7e06SGarrett D'Amore 	emtp->emt_ev_proxy_response(emtp->emt_context, handle, rc);
835*49ef7e06SGarrett D'Amore }
836*49ef7e06SGarrett D'Amore #endif /* EFSYS_OPT_MCDI_PROXY_AUTH */
837*49ef7e06SGarrett D'Amore 
838*49ef7e06SGarrett D'Amore 			void
efx_mcdi_ev_death(__in efx_nic_t * enp,__in int rc)839*49ef7e06SGarrett D'Amore efx_mcdi_ev_death(
840*49ef7e06SGarrett D'Amore 	__in		efx_nic_t *enp,
841*49ef7e06SGarrett D'Amore 	__in		int rc)
842*49ef7e06SGarrett D'Amore {
843*49ef7e06SGarrett D'Amore 	efx_mcdi_iface_t *emip = &(enp->en_mcdi.em_emip);
844*49ef7e06SGarrett D'Amore 	const efx_mcdi_transport_t *emtp = enp->en_mcdi.em_emtp;
845*49ef7e06SGarrett D'Amore 	efx_mcdi_req_t *emrp = NULL;
846*49ef7e06SGarrett D'Amore 	boolean_t ev_cpl;
847*49ef7e06SGarrett D'Amore 	int state;
848*49ef7e06SGarrett D'Amore 
849*49ef7e06SGarrett D'Amore 	/*
850*49ef7e06SGarrett D'Amore 	 * The MCDI request (if there is one) has been terminated, either
851*49ef7e06SGarrett D'Amore 	 * by a BADASSERT or REBOOT event.
852*49ef7e06SGarrett D'Amore 	 *
853*49ef7e06SGarrett D'Amore 	 * If there is an outstanding event-completed MCDI operation, then we
854*49ef7e06SGarrett D'Amore 	 * will never receive the completion event (because both MCDI
855*49ef7e06SGarrett D'Amore 	 * completions and BADASSERT events are sent to the same evq). So
856*49ef7e06SGarrett D'Amore 	 * complete this MCDI op.
857*49ef7e06SGarrett D'Amore 	 *
858*49ef7e06SGarrett D'Amore 	 * This function might run in parallel with efx_mcdi_request_poll()
859*49ef7e06SGarrett D'Amore 	 * for poll completed mcdi requests, and also with
860*49ef7e06SGarrett D'Amore 	 * efx_mcdi_request_start() for post-watchdog completions.
861*49ef7e06SGarrett D'Amore 	 */
862*49ef7e06SGarrett D'Amore 	EFSYS_LOCK(enp->en_eslp, state);
863*49ef7e06SGarrett D'Amore 	emrp = emip->emi_pending_req;
864*49ef7e06SGarrett D'Amore 	ev_cpl = emip->emi_ev_cpl;
865*49ef7e06SGarrett D'Amore 	if (emrp != NULL && emip->emi_ev_cpl) {
866*49ef7e06SGarrett D'Amore 		emip->emi_pending_req = NULL;
867*49ef7e06SGarrett D'Amore 
868*49ef7e06SGarrett D'Amore 		emrp->emr_out_length_used = 0;
869*49ef7e06SGarrett D'Amore 		emrp->emr_rc = rc;
870*49ef7e06SGarrett D'Amore 		++emip->emi_aborted;
871*49ef7e06SGarrett D'Amore 	}
872*49ef7e06SGarrett D'Amore 
873*49ef7e06SGarrett D'Amore 	/*
874*49ef7e06SGarrett D'Amore 	 * Since we're running in parallel with a request, consume the
875*49ef7e06SGarrett D'Amore 	 * status word before dropping the lock.
876*49ef7e06SGarrett D'Amore 	 */
877*49ef7e06SGarrett D'Amore 	if (rc == EIO || rc == EINTR) {
878*49ef7e06SGarrett D'Amore 		EFSYS_SPIN(EFX_MCDI_STATUS_SLEEP_US);
879*49ef7e06SGarrett D'Amore 		(void) efx_mcdi_poll_reboot(enp);
880*49ef7e06SGarrett D'Amore 		emip->emi_new_epoch = B_TRUE;
881*49ef7e06SGarrett D'Amore 	}
882*49ef7e06SGarrett D'Amore 
883*49ef7e06SGarrett D'Amore 	EFSYS_UNLOCK(enp->en_eslp, state);
884*49ef7e06SGarrett D'Amore 
885*49ef7e06SGarrett D'Amore 	efx_mcdi_raise_exception(enp, emrp, rc);
886*49ef7e06SGarrett D'Amore 
887*49ef7e06SGarrett D'Amore 	if (emrp != NULL && ev_cpl)
888*49ef7e06SGarrett D'Amore 		emtp->emt_ev_cpl(emtp->emt_context);
889*49ef7e06SGarrett D'Amore }
890*49ef7e06SGarrett D'Amore 
891*49ef7e06SGarrett D'Amore 	__checkReturn		efx_rc_t
892*49ef7e06SGarrett D'Amore efx_mcdi_version(
893*49ef7e06SGarrett D'Amore 	__in			efx_nic_t *enp,
894*49ef7e06SGarrett D'Amore 	__out_ecount_opt(4)	uint16_t versionp[4],
895*49ef7e06SGarrett D'Amore 	__out_opt		uint32_t *buildp,
896*49ef7e06SGarrett D'Amore 	__out_opt		efx_mcdi_boot_t *statusp)
897*49ef7e06SGarrett D'Amore {
898*49ef7e06SGarrett D'Amore 	efx_mcdi_req_t req;
899*49ef7e06SGarrett D'Amore 	uint8_t payload[MAX(MAX(MC_CMD_GET_VERSION_IN_LEN,
900*49ef7e06SGarrett D'Amore 				MC_CMD_GET_VERSION_OUT_LEN),
901*49ef7e06SGarrett D'Amore 			    MAX(MC_CMD_GET_BOOT_STATUS_IN_LEN,
902*49ef7e06SGarrett D'Amore 				MC_CMD_GET_BOOT_STATUS_OUT_LEN))];
903*49ef7e06SGarrett D'Amore 	efx_word_t *ver_words;
904*49ef7e06SGarrett D'Amore 	uint16_t version[4];
905*49ef7e06SGarrett D'Amore 	uint32_t build;
906*49ef7e06SGarrett D'Amore 	efx_mcdi_boot_t status;
907*49ef7e06SGarrett D'Amore 	efx_rc_t rc;
908*49ef7e06SGarrett D'Amore 
909*49ef7e06SGarrett D'Amore 	EFSYS_ASSERT3U(enp->en_features, &, EFX_FEATURE_MCDI);
910*49ef7e06SGarrett D'Amore 
911*49ef7e06SGarrett D'Amore 	(void) memset(payload, 0, sizeof (payload));
912*49ef7e06SGarrett D'Amore 	req.emr_cmd = MC_CMD_GET_VERSION;
913*49ef7e06SGarrett D'Amore 	req.emr_in_buf = payload;
914*49ef7e06SGarrett D'Amore 	req.emr_in_length = MC_CMD_GET_VERSION_IN_LEN;
915*49ef7e06SGarrett D'Amore 	req.emr_out_buf = payload;
916*49ef7e06SGarrett D'Amore 	req.emr_out_length = MC_CMD_GET_VERSION_OUT_LEN;
917*49ef7e06SGarrett D'Amore 
918*49ef7e06SGarrett D'Amore 	efx_mcdi_execute(enp, &req);
919*49ef7e06SGarrett D'Amore 
920*49ef7e06SGarrett D'Amore 	if (req.emr_rc != 0) {
921*49ef7e06SGarrett D'Amore 		rc = req.emr_rc;
922*49ef7e06SGarrett D'Amore 		goto fail1;
923*49ef7e06SGarrett D'Amore 	}
924*49ef7e06SGarrett D'Amore 
925*49ef7e06SGarrett D'Amore 	/* bootrom support */
926*49ef7e06SGarrett D'Amore 	if (req.emr_out_length_used == MC_CMD_GET_VERSION_V0_OUT_LEN) {
927*49ef7e06SGarrett D'Amore 		version[0] = version[1] = version[2] = version[3] = 0;
928*49ef7e06SGarrett D'Amore 		build = MCDI_OUT_DWORD(req, GET_VERSION_OUT_FIRMWARE);
929*49ef7e06SGarrett D'Amore 
930*49ef7e06SGarrett D'Amore 		goto version;
931*49ef7e06SGarrett D'Amore 	}
932*49ef7e06SGarrett D'Amore 
933*49ef7e06SGarrett D'Amore 	if (req.emr_out_length_used < MC_CMD_GET_VERSION_OUT_LEN) {
934*49ef7e06SGarrett D'Amore 		rc = EMSGSIZE;
935*49ef7e06SGarrett D'Amore 		goto fail2;
936*49ef7e06SGarrett D'Amore 	}
937*49ef7e06SGarrett D'Amore 
938*49ef7e06SGarrett D'Amore 	ver_words = MCDI_OUT2(req, efx_word_t, GET_VERSION_OUT_VERSION);
939*49ef7e06SGarrett D'Amore 	version[0] = EFX_WORD_FIELD(ver_words[0], EFX_WORD_0);
940*49ef7e06SGarrett D'Amore 	version[1] = EFX_WORD_FIELD(ver_words[1], EFX_WORD_0);
941*49ef7e06SGarrett D'Amore 	version[2] = EFX_WORD_FIELD(ver_words[2], EFX_WORD_0);
942*49ef7e06SGarrett D'Amore 	version[3] = EFX_WORD_FIELD(ver_words[3], EFX_WORD_0);
943*49ef7e06SGarrett D'Amore 	build = MCDI_OUT_DWORD(req, GET_VERSION_OUT_FIRMWARE);
944*49ef7e06SGarrett D'Amore 
945*49ef7e06SGarrett D'Amore version:
946*49ef7e06SGarrett D'Amore 	/* The bootrom doesn't understand BOOT_STATUS */
947*49ef7e06SGarrett D'Amore 	if (MC_FW_VERSION_IS_BOOTLOADER(build)) {
948*49ef7e06SGarrett D'Amore 		status = EFX_MCDI_BOOT_ROM;
949*49ef7e06SGarrett D'Amore 		goto out;
950*49ef7e06SGarrett D'Amore 	}
951*49ef7e06SGarrett D'Amore 
952*49ef7e06SGarrett D'Amore 	(void) memset(payload, 0, sizeof (payload));
953*49ef7e06SGarrett D'Amore 	req.emr_cmd = MC_CMD_GET_BOOT_STATUS;
954*49ef7e06SGarrett D'Amore 	req.emr_in_buf = payload;
955*49ef7e06SGarrett D'Amore 	req.emr_in_length = MC_CMD_GET_BOOT_STATUS_IN_LEN;
956*49ef7e06SGarrett D'Amore 	req.emr_out_buf = payload;
957*49ef7e06SGarrett D'Amore 	req.emr_out_length = MC_CMD_GET_BOOT_STATUS_OUT_LEN;
958*49ef7e06SGarrett D'Amore 
959*49ef7e06SGarrett D'Amore 	efx_mcdi_execute_quiet(enp, &req);
960*49ef7e06SGarrett D'Amore 
961*49ef7e06SGarrett D'Amore 	if (req.emr_rc == EACCES) {
962*49ef7e06SGarrett D'Amore 		/* Unprivileged functions cannot access BOOT_STATUS */
963*49ef7e06SGarrett D'Amore 		status = EFX_MCDI_BOOT_PRIMARY;
964*49ef7e06SGarrett D'Amore 		version[0] = version[1] = version[2] = version[3] = 0;
965*49ef7e06SGarrett D'Amore 		build = 0;
966*49ef7e06SGarrett D'Amore 		goto out;
967*49ef7e06SGarrett D'Amore 	}
968*49ef7e06SGarrett D'Amore 
969*49ef7e06SGarrett D'Amore 	if (req.emr_rc != 0) {
970*49ef7e06SGarrett D'Amore 		rc = req.emr_rc;
971*49ef7e06SGarrett D'Amore 		goto fail3;
972*49ef7e06SGarrett D'Amore 	}
973*49ef7e06SGarrett D'Amore 
974*49ef7e06SGarrett D'Amore 	if (req.emr_out_length_used < MC_CMD_GET_BOOT_STATUS_OUT_LEN) {
975*49ef7e06SGarrett D'Amore 		rc = EMSGSIZE;
976*49ef7e06SGarrett D'Amore 		goto fail4;
977*49ef7e06SGarrett D'Amore 	}
978*49ef7e06SGarrett D'Amore 
979*49ef7e06SGarrett D'Amore 	if (MCDI_OUT_DWORD_FIELD(req, GET_BOOT_STATUS_OUT_FLAGS,
980*49ef7e06SGarrett D'Amore 	    GET_BOOT_STATUS_OUT_FLAGS_PRIMARY))
981*49ef7e06SGarrett D'Amore 		status = EFX_MCDI_BOOT_PRIMARY;
982*49ef7e06SGarrett D'Amore 	else
983*49ef7e06SGarrett D'Amore 		status = EFX_MCDI_BOOT_SECONDARY;
984*49ef7e06SGarrett D'Amore 
985*49ef7e06SGarrett D'Amore out:
986*49ef7e06SGarrett D'Amore 	if (versionp != NULL)
987*49ef7e06SGarrett D'Amore 		(void) memcpy(versionp, version, sizeof (version));
988*49ef7e06SGarrett D'Amore 	if (buildp != NULL)
989*49ef7e06SGarrett D'Amore 		*buildp = build;
990*49ef7e06SGarrett D'Amore 	if (statusp != NULL)
991*49ef7e06SGarrett D'Amore 		*statusp = status;
992*49ef7e06SGarrett D'Amore 
993*49ef7e06SGarrett D'Amore 	return (0);
994*49ef7e06SGarrett D'Amore 
995*49ef7e06SGarrett D'Amore fail4:
996*49ef7e06SGarrett D'Amore 	EFSYS_PROBE(fail4);
997*49ef7e06SGarrett D'Amore fail3:
998*49ef7e06SGarrett D'Amore 	EFSYS_PROBE(fail3);
999*49ef7e06SGarrett D'Amore fail2:
1000*49ef7e06SGarrett D'Amore 	EFSYS_PROBE(fail2);
1001*49ef7e06SGarrett D'Amore fail1:
1002*49ef7e06SGarrett D'Amore 	EFSYS_PROBE1(fail1, efx_rc_t, rc);
1003*49ef7e06SGarrett D'Amore 
1004*49ef7e06SGarrett D'Amore 	return (rc);
1005*49ef7e06SGarrett D'Amore }
1006*49ef7e06SGarrett D'Amore 
1007*49ef7e06SGarrett D'Amore static	__checkReturn	efx_rc_t
efx_mcdi_do_reboot(__in efx_nic_t * enp,__in boolean_t after_assertion)1008*49ef7e06SGarrett D'Amore efx_mcdi_do_reboot(
1009*49ef7e06SGarrett D'Amore 	__in		efx_nic_t *enp,
1010*49ef7e06SGarrett D'Amore 	__in		boolean_t after_assertion)
1011*49ef7e06SGarrett D'Amore {
1012*49ef7e06SGarrett D'Amore 	uint8_t payload[MAX(MC_CMD_REBOOT_IN_LEN, MC_CMD_REBOOT_OUT_LEN)];
1013*49ef7e06SGarrett D'Amore 	efx_mcdi_req_t req;
1014*49ef7e06SGarrett D'Amore 	efx_rc_t rc;
1015*49ef7e06SGarrett D'Amore 
1016*49ef7e06SGarrett D'Amore 	/*
1017*49ef7e06SGarrett D'Amore 	 * We could require the caller to have caused en_mod_flags=0 to
1018*49ef7e06SGarrett D'Amore 	 * call this function. This doesn't help the other port though,
1019*49ef7e06SGarrett D'Amore 	 * who's about to get the MC ripped out from underneath them.
1020*49ef7e06SGarrett D'Amore 	 * Since they have to cope with the subsequent fallout of MCDI
1021*49ef7e06SGarrett D'Amore 	 * failures, we should as well.
1022*49ef7e06SGarrett D'Amore 	 */
1023*49ef7e06SGarrett D'Amore 	EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
1024*49ef7e06SGarrett D'Amore 
1025*49ef7e06SGarrett D'Amore 	(void) memset(payload, 0, sizeof (payload));
1026*49ef7e06SGarrett D'Amore 	req.emr_cmd = MC_CMD_REBOOT;
1027*49ef7e06SGarrett D'Amore 	req.emr_in_buf = payload;
1028*49ef7e06SGarrett D'Amore 	req.emr_in_length = MC_CMD_REBOOT_IN_LEN;
1029*49ef7e06SGarrett D'Amore 	req.emr_out_buf = payload;
1030*49ef7e06SGarrett D'Amore 	req.emr_out_length = MC_CMD_REBOOT_OUT_LEN;
1031*49ef7e06SGarrett D'Amore 
1032*49ef7e06SGarrett D'Amore 	MCDI_IN_SET_DWORD(req, REBOOT_IN_FLAGS,
1033*49ef7e06SGarrett D'Amore 	    (after_assertion ? MC_CMD_REBOOT_FLAGS_AFTER_ASSERTION : 0));
1034*49ef7e06SGarrett D'Amore 
1035*49ef7e06SGarrett D'Amore 	efx_mcdi_execute_quiet(enp, &req);
1036*49ef7e06SGarrett D'Amore 
1037*49ef7e06SGarrett D'Amore 	if (req.emr_rc == EACCES) {
1038*49ef7e06SGarrett D'Amore 		/* Unprivileged functions cannot reboot the MC. */
1039*49ef7e06SGarrett D'Amore 		goto out;
1040*49ef7e06SGarrett D'Amore 	}
1041*49ef7e06SGarrett D'Amore 
1042*49ef7e06SGarrett D'Amore 	/* A successful reboot request returns EIO. */
1043*49ef7e06SGarrett D'Amore 	if (req.emr_rc != 0 && req.emr_rc != EIO) {
1044*49ef7e06SGarrett D'Amore 		rc = req.emr_rc;
1045*49ef7e06SGarrett D'Amore 		goto fail1;
1046*49ef7e06SGarrett D'Amore 	}
1047*49ef7e06SGarrett D'Amore 
1048*49ef7e06SGarrett D'Amore out:
1049*49ef7e06SGarrett D'Amore 	return (0);
1050*49ef7e06SGarrett D'Amore 
1051*49ef7e06SGarrett D'Amore fail1:
1052*49ef7e06SGarrett D'Amore 	EFSYS_PROBE1(fail1, efx_rc_t, rc);
1053*49ef7e06SGarrett D'Amore 
1054*49ef7e06SGarrett D'Amore 	return (rc);
1055*49ef7e06SGarrett D'Amore }
1056*49ef7e06SGarrett D'Amore 
1057*49ef7e06SGarrett D'Amore 	__checkReturn	efx_rc_t
efx_mcdi_reboot(__in efx_nic_t * enp)1058*49ef7e06SGarrett D'Amore efx_mcdi_reboot(
1059*49ef7e06SGarrett D'Amore 	__in		efx_nic_t *enp)
1060*49ef7e06SGarrett D'Amore {
1061*49ef7e06SGarrett D'Amore 	return (efx_mcdi_do_reboot(enp, B_FALSE));
1062*49ef7e06SGarrett D'Amore }
1063*49ef7e06SGarrett D'Amore 
1064*49ef7e06SGarrett D'Amore 	__checkReturn	efx_rc_t
efx_mcdi_exit_assertion_handler(__in efx_nic_t * enp)1065*49ef7e06SGarrett D'Amore efx_mcdi_exit_assertion_handler(
1066*49ef7e06SGarrett D'Amore 	__in		efx_nic_t *enp)
1067*49ef7e06SGarrett D'Amore {
1068*49ef7e06SGarrett D'Amore 	return (efx_mcdi_do_reboot(enp, B_TRUE));
1069*49ef7e06SGarrett D'Amore }
1070*49ef7e06SGarrett D'Amore 
1071*49ef7e06SGarrett D'Amore 	__checkReturn	efx_rc_t
efx_mcdi_read_assertion(__in efx_nic_t * enp)1072*49ef7e06SGarrett D'Amore efx_mcdi_read_assertion(
1073*49ef7e06SGarrett D'Amore 	__in		efx_nic_t *enp)
1074*49ef7e06SGarrett D'Amore {
1075*49ef7e06SGarrett D'Amore 	efx_mcdi_req_t req;
1076*49ef7e06SGarrett D'Amore 	uint8_t payload[MAX(MC_CMD_GET_ASSERTS_IN_LEN,
1077*49ef7e06SGarrett D'Amore 			    MC_CMD_GET_ASSERTS_OUT_LEN)];
1078*49ef7e06SGarrett D'Amore 	const char *reason;
1079*49ef7e06SGarrett D'Amore 	unsigned int flags;
1080*49ef7e06SGarrett D'Amore 	unsigned int index;
1081*49ef7e06SGarrett D'Amore 	unsigned int ofst;
1082*49ef7e06SGarrett D'Amore 	int retry;
1083*49ef7e06SGarrett D'Amore 	efx_rc_t rc;
1084*49ef7e06SGarrett D'Amore 
1085*49ef7e06SGarrett D'Amore 	/*
1086*49ef7e06SGarrett D'Amore 	 * Before we attempt to chat to the MC, we should verify that the MC
1087*49ef7e06SGarrett D'Amore 	 * isn't in it's assertion handler, either due to a previous reboot,
1088*49ef7e06SGarrett D'Amore 	 * or because we're reinitializing due to an eec_exception().
1089*49ef7e06SGarrett D'Amore 	 *
1090*49ef7e06SGarrett D'Amore 	 * Use GET_ASSERTS to read any assertion state that may be present.
1091*49ef7e06SGarrett D'Amore 	 * Retry this command twice. Once because a boot-time assertion failure
1092*49ef7e06SGarrett D'Amore 	 * might cause the 1st MCDI request to fail. And once again because
1093*49ef7e06SGarrett D'Amore 	 * we might race with efx_mcdi_exit_assertion_handler() running on
1094*49ef7e06SGarrett D'Amore 	 * partner port(s) on the same NIC.
1095*49ef7e06SGarrett D'Amore 	 */
1096*49ef7e06SGarrett D'Amore 	retry = 2;
1097*49ef7e06SGarrett D'Amore 	do {
1098*49ef7e06SGarrett D'Amore 		(void) memset(payload, 0, sizeof (payload));
1099*49ef7e06SGarrett D'Amore 		req.emr_cmd = MC_CMD_GET_ASSERTS;
1100*49ef7e06SGarrett D'Amore 		req.emr_in_buf = payload;
1101*49ef7e06SGarrett D'Amore 		req.emr_in_length = MC_CMD_GET_ASSERTS_IN_LEN;
1102*49ef7e06SGarrett D'Amore 		req.emr_out_buf = payload;
1103*49ef7e06SGarrett D'Amore 		req.emr_out_length = MC_CMD_GET_ASSERTS_OUT_LEN;
1104*49ef7e06SGarrett D'Amore 
1105*49ef7e06SGarrett D'Amore 		MCDI_IN_SET_DWORD(req, GET_ASSERTS_IN_CLEAR, 1);
1106*49ef7e06SGarrett D'Amore 		efx_mcdi_execute_quiet(enp, &req);
1107*49ef7e06SGarrett D'Amore 
1108*49ef7e06SGarrett D'Amore 	} while ((req.emr_rc == EINTR || req.emr_rc == EIO) && retry-- > 0);
1109*49ef7e06SGarrett D'Amore 
1110*49ef7e06SGarrett D'Amore 	if (req.emr_rc != 0) {
1111*49ef7e06SGarrett D'Amore 		if (req.emr_rc == EACCES) {
1112*49ef7e06SGarrett D'Amore 			/* Unprivileged functions cannot clear assertions. */
1113*49ef7e06SGarrett D'Amore 			goto out;
1114*49ef7e06SGarrett D'Amore 		}
1115*49ef7e06SGarrett D'Amore 		rc = req.emr_rc;
1116*49ef7e06SGarrett D'Amore 		goto fail1;
1117*49ef7e06SGarrett D'Amore 	}
1118*49ef7e06SGarrett D'Amore 
1119*49ef7e06SGarrett D'Amore 	if (req.emr_out_length_used < MC_CMD_GET_ASSERTS_OUT_LEN) {
1120*49ef7e06SGarrett D'Amore 		rc = EMSGSIZE;
1121*49ef7e06SGarrett D'Amore 		goto fail2;
1122*49ef7e06SGarrett D'Amore 	}
1123*49ef7e06SGarrett D'Amore 
1124*49ef7e06SGarrett D'Amore 	/* Print out any assertion state recorded */
1125*49ef7e06SGarrett D'Amore 	flags = MCDI_OUT_DWORD(req, GET_ASSERTS_OUT_GLOBAL_FLAGS);
1126*49ef7e06SGarrett D'Amore 	if (flags == MC_CMD_GET_ASSERTS_FLAGS_NO_FAILS)
1127*49ef7e06SGarrett D'Amore 		return (0);
1128*49ef7e06SGarrett D'Amore 
1129*49ef7e06SGarrett D'Amore 	reason = (flags == MC_CMD_GET_ASSERTS_FLAGS_SYS_FAIL)
1130*49ef7e06SGarrett D'Amore 		? "system-level assertion"
1131*49ef7e06SGarrett D'Amore 		: (flags == MC_CMD_GET_ASSERTS_FLAGS_THR_FAIL)
1132*49ef7e06SGarrett D'Amore 		? "thread-level assertion"
1133*49ef7e06SGarrett D'Amore 		: (flags == MC_CMD_GET_ASSERTS_FLAGS_WDOG_FIRED)
1134*49ef7e06SGarrett D'Amore 		? "watchdog reset"
1135*49ef7e06SGarrett D'Amore 		: (flags == MC_CMD_GET_ASSERTS_FLAGS_ADDR_TRAP)
1136*49ef7e06SGarrett D'Amore 		? "illegal address trap"
1137*49ef7e06SGarrett D'Amore 		: "unknown assertion";
1138*49ef7e06SGarrett D'Amore 	EFSYS_PROBE3(mcpu_assertion,
1139*49ef7e06SGarrett D'Amore 	    const char *, reason, unsigned int,
1140*49ef7e06SGarrett D'Amore 	    MCDI_OUT_DWORD(req, GET_ASSERTS_OUT_SAVED_PC_OFFS),
1141*49ef7e06SGarrett D'Amore 	    unsigned int,
1142*49ef7e06SGarrett D'Amore 	    MCDI_OUT_DWORD(req, GET_ASSERTS_OUT_THREAD_OFFS));
1143*49ef7e06SGarrett D'Amore 
1144*49ef7e06SGarrett D'Amore 	/* Print out the registers (r1 ... r31) */
1145*49ef7e06SGarrett D'Amore 	ofst = MC_CMD_GET_ASSERTS_OUT_GP_REGS_OFFS_OFST;
1146*49ef7e06SGarrett D'Amore 	for (index = 1;
1147*49ef7e06SGarrett D'Amore 		index < 1 + MC_CMD_GET_ASSERTS_OUT_GP_REGS_OFFS_NUM;
1148*49ef7e06SGarrett D'Amore 		index++) {
1149*49ef7e06SGarrett D'Amore 		EFSYS_PROBE2(mcpu_register, unsigned int, index, unsigned int,
1150*49ef7e06SGarrett D'Amore 			    EFX_DWORD_FIELD(*MCDI_OUT(req, efx_dword_t, ofst),
1151*49ef7e06SGarrett D'Amore 					    EFX_DWORD_0));
1152*49ef7e06SGarrett D'Amore 		ofst += sizeof (efx_dword_t);
1153*49ef7e06SGarrett D'Amore 	}
1154*49ef7e06SGarrett D'Amore 	EFSYS_ASSERT(ofst <= MC_CMD_GET_ASSERTS_OUT_LEN);
1155*49ef7e06SGarrett D'Amore 
1156*49ef7e06SGarrett D'Amore out:
1157*49ef7e06SGarrett D'Amore 	return (0);
1158*49ef7e06SGarrett D'Amore 
1159*49ef7e06SGarrett D'Amore fail2:
1160*49ef7e06SGarrett D'Amore 	EFSYS_PROBE(fail2);
1161*49ef7e06SGarrett D'Amore fail1:
1162*49ef7e06SGarrett D'Amore 	EFSYS_PROBE1(fail1, efx_rc_t, rc);
1163*49ef7e06SGarrett D'Amore 
1164*49ef7e06SGarrett D'Amore 	return (rc);
1165*49ef7e06SGarrett D'Amore }
1166*49ef7e06SGarrett D'Amore 
1167*49ef7e06SGarrett D'Amore 
1168*49ef7e06SGarrett D'Amore /*
1169*49ef7e06SGarrett D'Amore  * Internal routines for for specific MCDI requests.
1170*49ef7e06SGarrett D'Amore  */
1171*49ef7e06SGarrett D'Amore 
1172*49ef7e06SGarrett D'Amore 	__checkReturn	efx_rc_t
efx_mcdi_drv_attach(__in efx_nic_t * enp,__in boolean_t attach)1173*49ef7e06SGarrett D'Amore efx_mcdi_drv_attach(
1174*49ef7e06SGarrett D'Amore 	__in		efx_nic_t *enp,
1175*49ef7e06SGarrett D'Amore 	__in		boolean_t attach)
1176*49ef7e06SGarrett D'Amore {
1177*49ef7e06SGarrett D'Amore 	efx_nic_cfg_t *encp = &(enp->en_nic_cfg);
1178*49ef7e06SGarrett D'Amore 	efx_mcdi_req_t req;
1179*49ef7e06SGarrett D'Amore 	uint8_t payload[MAX(MC_CMD_DRV_ATTACH_IN_LEN,
1180*49ef7e06SGarrett D'Amore 			    MC_CMD_DRV_ATTACH_EXT_OUT_LEN)];
1181*49ef7e06SGarrett D'Amore 	uint32_t flags;
1182*49ef7e06SGarrett D'Amore 	efx_rc_t rc;
1183*49ef7e06SGarrett D'Amore 
1184*49ef7e06SGarrett D'Amore 	(void) memset(payload, 0, sizeof (payload));
1185*49ef7e06SGarrett D'Amore 	req.emr_cmd = MC_CMD_DRV_ATTACH;
1186*49ef7e06SGarrett D'Amore 	req.emr_in_buf = payload;
1187*49ef7e06SGarrett D'Amore 	req.emr_in_length = MC_CMD_DRV_ATTACH_IN_LEN;
1188*49ef7e06SGarrett D'Amore 	req.emr_out_buf = payload;
1189*49ef7e06SGarrett D'Amore 	req.emr_out_length = MC_CMD_DRV_ATTACH_EXT_OUT_LEN;
1190*49ef7e06SGarrett D'Amore 
1191*49ef7e06SGarrett D'Amore 	/*
1192*49ef7e06SGarrett D'Amore 	 * Use DONT_CARE for the datapath firmware type to ensure that the
1193*49ef7e06SGarrett D'Amore 	 * driver can attach to an unprivileged function. The datapath firmware
1194*49ef7e06SGarrett D'Amore 	 * type to use is controlled by the 'sfboot' utility.
1195*49ef7e06SGarrett D'Amore 	 */
1196*49ef7e06SGarrett D'Amore 	MCDI_IN_SET_DWORD(req, DRV_ATTACH_IN_NEW_STATE, attach ? 1 : 0);
1197*49ef7e06SGarrett D'Amore 	MCDI_IN_SET_DWORD(req, DRV_ATTACH_IN_UPDATE, 1);
1198*49ef7e06SGarrett D'Amore 	MCDI_IN_SET_DWORD(req, DRV_ATTACH_IN_FIRMWARE_ID, MC_CMD_FW_DONT_CARE);
1199*49ef7e06SGarrett D'Amore 
1200*49ef7e06SGarrett D'Amore 	efx_mcdi_execute(enp, &req);
1201*49ef7e06SGarrett D'Amore 
1202*49ef7e06SGarrett D'Amore 	if (req.emr_rc != 0) {
1203*49ef7e06SGarrett D'Amore 		rc = req.emr_rc;
1204*49ef7e06SGarrett D'Amore 		goto fail1;
1205*49ef7e06SGarrett D'Amore 	}
1206*49ef7e06SGarrett D'Amore 
1207*49ef7e06SGarrett D'Amore 	if (req.emr_out_length_used < MC_CMD_DRV_ATTACH_OUT_LEN) {
1208*49ef7e06SGarrett D'Amore 		rc = EMSGSIZE;
1209*49ef7e06SGarrett D'Amore 		goto fail2;
1210*49ef7e06SGarrett D'Amore 	}
1211*49ef7e06SGarrett D'Amore 
1212*49ef7e06SGarrett D'Amore 	if (attach == B_FALSE) {
1213*49ef7e06SGarrett D'Amore 		flags = 0;
1214*49ef7e06SGarrett D'Amore 	} else if (enp->en_family == EFX_FAMILY_SIENA) {
1215*49ef7e06SGarrett D'Amore 		efx_mcdi_iface_t *emip = &(enp->en_mcdi.em_emip);
1216*49ef7e06SGarrett D'Amore 
1217*49ef7e06SGarrett D'Amore 		/* Create synthetic privileges for Siena functions */
1218*49ef7e06SGarrett D'Amore 		flags = EFX_NIC_FUNC_LINKCTRL | EFX_NIC_FUNC_TRUSTED;
1219*49ef7e06SGarrett D'Amore 		if (emip->emi_port == 1)
1220*49ef7e06SGarrett D'Amore 			flags |= EFX_NIC_FUNC_PRIMARY;
1221*49ef7e06SGarrett D'Amore 	} else {
1222*49ef7e06SGarrett D'Amore 		EFX_STATIC_ASSERT(EFX_NIC_FUNC_PRIMARY ==
1223*49ef7e06SGarrett D'Amore 		    (1u << MC_CMD_DRV_ATTACH_EXT_OUT_FLAG_PRIMARY));
1224*49ef7e06SGarrett D'Amore 		EFX_STATIC_ASSERT(EFX_NIC_FUNC_LINKCTRL ==
1225*49ef7e06SGarrett D'Amore 		    (1u << MC_CMD_DRV_ATTACH_EXT_OUT_FLAG_LINKCTRL));
1226*49ef7e06SGarrett D'Amore 		EFX_STATIC_ASSERT(EFX_NIC_FUNC_TRUSTED ==
1227*49ef7e06SGarrett D'Amore 		    (1u << MC_CMD_DRV_ATTACH_EXT_OUT_FLAG_TRUSTED));
1228*49ef7e06SGarrett D'Amore 
1229*49ef7e06SGarrett D'Amore 		/* Save function privilege flags (EF10 and later) */
1230*49ef7e06SGarrett D'Amore 		if (req.emr_out_length_used < MC_CMD_DRV_ATTACH_EXT_OUT_LEN) {
1231*49ef7e06SGarrett D'Amore 			rc = EMSGSIZE;
1232*49ef7e06SGarrett D'Amore 			goto fail3;
1233*49ef7e06SGarrett D'Amore 		}
1234*49ef7e06SGarrett D'Amore 		flags = MCDI_OUT_DWORD(req, DRV_ATTACH_EXT_OUT_FUNC_FLAGS);
1235*49ef7e06SGarrett D'Amore 	}
1236*49ef7e06SGarrett D'Amore 	encp->enc_func_flags = flags;
1237*49ef7e06SGarrett D'Amore 
1238*49ef7e06SGarrett D'Amore 	return (0);
1239*49ef7e06SGarrett D'Amore 
1240*49ef7e06SGarrett D'Amore fail3:
1241*49ef7e06SGarrett D'Amore 	EFSYS_PROBE(fail3);
1242*49ef7e06SGarrett D'Amore fail2:
1243*49ef7e06SGarrett D'Amore 	EFSYS_PROBE(fail2);
1244*49ef7e06SGarrett D'Amore fail1:
1245*49ef7e06SGarrett D'Amore 	EFSYS_PROBE1(fail1, efx_rc_t, rc);
1246*49ef7e06SGarrett D'Amore 
1247*49ef7e06SGarrett D'Amore 	return (rc);
1248*49ef7e06SGarrett D'Amore }
1249*49ef7e06SGarrett D'Amore 
1250*49ef7e06SGarrett D'Amore 	__checkReturn		efx_rc_t
1251*49ef7e06SGarrett D'Amore efx_mcdi_get_board_cfg(
1252*49ef7e06SGarrett D'Amore 	__in			efx_nic_t *enp,
1253*49ef7e06SGarrett D'Amore 	__out_opt		uint32_t *board_typep,
1254*49ef7e06SGarrett D'Amore 	__out_opt		efx_dword_t *capabilitiesp,
1255*49ef7e06SGarrett D'Amore 	__out_ecount_opt(6)	uint8_t mac_addrp[6])
1256*49ef7e06SGarrett D'Amore {
1257*49ef7e06SGarrett D'Amore 	efx_mcdi_iface_t *emip = &(enp->en_mcdi.em_emip);
1258*49ef7e06SGarrett D'Amore 	efx_mcdi_req_t req;
1259*49ef7e06SGarrett D'Amore 	uint8_t payload[MAX(MC_CMD_GET_BOARD_CFG_IN_LEN,
1260*49ef7e06SGarrett D'Amore 			    MC_CMD_GET_BOARD_CFG_OUT_LENMIN)];
1261*49ef7e06SGarrett D'Amore 	efx_rc_t rc;
1262*49ef7e06SGarrett D'Amore 
1263*49ef7e06SGarrett D'Amore 	(void) memset(payload, 0, sizeof (payload));
1264*49ef7e06SGarrett D'Amore 	req.emr_cmd = MC_CMD_GET_BOARD_CFG;
1265*49ef7e06SGarrett D'Amore 	req.emr_in_buf = payload;
1266*49ef7e06SGarrett D'Amore 	req.emr_in_length = MC_CMD_GET_BOARD_CFG_IN_LEN;
1267*49ef7e06SGarrett D'Amore 	req.emr_out_buf = payload;
1268*49ef7e06SGarrett D'Amore 	req.emr_out_length = MC_CMD_GET_BOARD_CFG_OUT_LENMIN;
1269*49ef7e06SGarrett D'Amore 
1270*49ef7e06SGarrett D'Amore 	efx_mcdi_execute(enp, &req);
1271*49ef7e06SGarrett D'Amore 
1272*49ef7e06SGarrett D'Amore 	if (req.emr_rc != 0) {
1273*49ef7e06SGarrett D'Amore 		rc = req.emr_rc;
1274*49ef7e06SGarrett D'Amore 		goto fail1;
1275*49ef7e06SGarrett D'Amore 	}
1276*49ef7e06SGarrett D'Amore 
1277*49ef7e06SGarrett D'Amore 	if (req.emr_out_length_used < MC_CMD_GET_BOARD_CFG_OUT_LENMIN) {
1278*49ef7e06SGarrett D'Amore 		rc = EMSGSIZE;
1279*49ef7e06SGarrett D'Amore 		goto fail2;
1280*49ef7e06SGarrett D'Amore 	}
1281*49ef7e06SGarrett D'Amore 
1282*49ef7e06SGarrett D'Amore 	if (mac_addrp != NULL) {
1283*49ef7e06SGarrett D'Amore 		uint8_t *addrp;
1284*49ef7e06SGarrett D'Amore 
1285*49ef7e06SGarrett D'Amore 		if (emip->emi_port == 1) {
1286*49ef7e06SGarrett D'Amore 			addrp = MCDI_OUT2(req, uint8_t,
1287*49ef7e06SGarrett D'Amore 			    GET_BOARD_CFG_OUT_MAC_ADDR_BASE_PORT0);
1288*49ef7e06SGarrett D'Amore 		} else if (emip->emi_port == 2) {
1289*49ef7e06SGarrett D'Amore 			addrp = MCDI_OUT2(req, uint8_t,
1290*49ef7e06SGarrett D'Amore 			    GET_BOARD_CFG_OUT_MAC_ADDR_BASE_PORT1);
1291*49ef7e06SGarrett D'Amore 		} else {
1292*49ef7e06SGarrett D'Amore 			rc = EINVAL;
1293*49ef7e06SGarrett D'Amore 			goto fail3;
1294*49ef7e06SGarrett D'Amore 		}
1295*49ef7e06SGarrett D'Amore 
1296*49ef7e06SGarrett D'Amore 		EFX_MAC_ADDR_COPY(mac_addrp, addrp);
1297*49ef7e06SGarrett D'Amore 	}
1298*49ef7e06SGarrett D'Amore 
1299*49ef7e06SGarrett D'Amore 	if (capabilitiesp != NULL) {
1300*49ef7e06SGarrett D'Amore 		if (emip->emi_port == 1) {
1301*49ef7e06SGarrett D'Amore 			*capabilitiesp = *MCDI_OUT2(req, efx_dword_t,
1302*49ef7e06SGarrett D'Amore 			    GET_BOARD_CFG_OUT_CAPABILITIES_PORT0);
1303*49ef7e06SGarrett D'Amore 		} else if (emip->emi_port == 2) {
1304*49ef7e06SGarrett D'Amore 			*capabilitiesp = *MCDI_OUT2(req, efx_dword_t,
1305*49ef7e06SGarrett D'Amore 			    GET_BOARD_CFG_OUT_CAPABILITIES_PORT1);
1306*49ef7e06SGarrett D'Amore 		} else {
1307*49ef7e06SGarrett D'Amore 			rc = EINVAL;
1308*49ef7e06SGarrett D'Amore 			goto fail4;
1309*49ef7e06SGarrett D'Amore 		}
1310*49ef7e06SGarrett D'Amore 	}
1311*49ef7e06SGarrett D'Amore 
1312*49ef7e06SGarrett D'Amore 	if (board_typep != NULL) {
1313*49ef7e06SGarrett D'Amore 		*board_typep = MCDI_OUT_DWORD(req,
1314*49ef7e06SGarrett D'Amore 		    GET_BOARD_CFG_OUT_BOARD_TYPE);
1315*49ef7e06SGarrett D'Amore 	}
1316*49ef7e06SGarrett D'Amore 
1317*49ef7e06SGarrett D'Amore 	return (0);
1318*49ef7e06SGarrett D'Amore 
1319*49ef7e06SGarrett D'Amore fail4:
1320*49ef7e06SGarrett D'Amore 	EFSYS_PROBE(fail4);
1321*49ef7e06SGarrett D'Amore fail3:
1322*49ef7e06SGarrett D'Amore 	EFSYS_PROBE(fail3);
1323*49ef7e06SGarrett D'Amore fail2:
1324*49ef7e06SGarrett D'Amore 	EFSYS_PROBE(fail2);
1325*49ef7e06SGarrett D'Amore fail1:
1326*49ef7e06SGarrett D'Amore 	EFSYS_PROBE1(fail1, efx_rc_t, rc);
1327*49ef7e06SGarrett D'Amore 
1328*49ef7e06SGarrett D'Amore 	return (rc);
1329*49ef7e06SGarrett D'Amore }
1330*49ef7e06SGarrett D'Amore 
1331*49ef7e06SGarrett D'Amore 	__checkReturn	efx_rc_t
efx_mcdi_get_resource_limits(__in efx_nic_t * enp,__out_opt uint32_t * nevqp,__out_opt uint32_t * nrxqp,__out_opt uint32_t * ntxqp)1332*49ef7e06SGarrett D'Amore efx_mcdi_get_resource_limits(
1333*49ef7e06SGarrett D'Amore 	__in		efx_nic_t *enp,
1334*49ef7e06SGarrett D'Amore 	__out_opt	uint32_t *nevqp,
1335*49ef7e06SGarrett D'Amore 	__out_opt	uint32_t *nrxqp,
1336*49ef7e06SGarrett D'Amore 	__out_opt	uint32_t *ntxqp)
1337*49ef7e06SGarrett D'Amore {
1338*49ef7e06SGarrett D'Amore 	efx_mcdi_req_t req;
1339*49ef7e06SGarrett D'Amore 	uint8_t payload[MAX(MC_CMD_GET_RESOURCE_LIMITS_IN_LEN,
1340*49ef7e06SGarrett D'Amore 			    MC_CMD_GET_RESOURCE_LIMITS_OUT_LEN)];
1341*49ef7e06SGarrett D'Amore 	efx_rc_t rc;
1342*49ef7e06SGarrett D'Amore 
1343*49ef7e06SGarrett D'Amore 	(void) memset(payload, 0, sizeof (payload));
1344*49ef7e06SGarrett D'Amore 	req.emr_cmd = MC_CMD_GET_RESOURCE_LIMITS;
1345*49ef7e06SGarrett D'Amore 	req.emr_in_buf = payload;
1346*49ef7e06SGarrett D'Amore 	req.emr_in_length = MC_CMD_GET_RESOURCE_LIMITS_IN_LEN;
1347*49ef7e06SGarrett D'Amore 	req.emr_out_buf = payload;
1348*49ef7e06SGarrett D'Amore 	req.emr_out_length = MC_CMD_GET_RESOURCE_LIMITS_OUT_LEN;
1349*49ef7e06SGarrett D'Amore 
1350*49ef7e06SGarrett D'Amore 	efx_mcdi_execute(enp, &req);
1351*49ef7e06SGarrett D'Amore 
1352*49ef7e06SGarrett D'Amore 	if (req.emr_rc != 0) {
1353*49ef7e06SGarrett D'Amore 		rc = req.emr_rc;
1354*49ef7e06SGarrett D'Amore 		goto fail1;
1355*49ef7e06SGarrett D'Amore 	}
1356*49ef7e06SGarrett D'Amore 
1357*49ef7e06SGarrett D'Amore 	if (req.emr_out_length_used < MC_CMD_GET_RESOURCE_LIMITS_OUT_LEN) {
1358*49ef7e06SGarrett D'Amore 		rc = EMSGSIZE;
1359*49ef7e06SGarrett D'Amore 		goto fail2;
1360*49ef7e06SGarrett D'Amore 	}
1361*49ef7e06SGarrett D'Amore 
1362*49ef7e06SGarrett D'Amore 	if (nevqp != NULL)
1363*49ef7e06SGarrett D'Amore 		*nevqp = MCDI_OUT_DWORD(req, GET_RESOURCE_LIMITS_OUT_EVQ);
1364*49ef7e06SGarrett D'Amore 	if (nrxqp != NULL)
1365*49ef7e06SGarrett D'Amore 		*nrxqp = MCDI_OUT_DWORD(req, GET_RESOURCE_LIMITS_OUT_RXQ);
1366*49ef7e06SGarrett D'Amore 	if (ntxqp != NULL)
1367*49ef7e06SGarrett D'Amore 		*ntxqp = MCDI_OUT_DWORD(req, GET_RESOURCE_LIMITS_OUT_TXQ);
1368*49ef7e06SGarrett D'Amore 
1369*49ef7e06SGarrett D'Amore 	return (0);
1370*49ef7e06SGarrett D'Amore 
1371*49ef7e06SGarrett D'Amore fail2:
1372*49ef7e06SGarrett D'Amore 	EFSYS_PROBE(fail2);
1373*49ef7e06SGarrett D'Amore fail1:
1374*49ef7e06SGarrett D'Amore 	EFSYS_PROBE1(fail1, efx_rc_t, rc);
1375*49ef7e06SGarrett D'Amore 
1376*49ef7e06SGarrett D'Amore 	return (rc);
1377*49ef7e06SGarrett D'Amore }
1378*49ef7e06SGarrett D'Amore 
1379*49ef7e06SGarrett D'Amore 	__checkReturn	efx_rc_t
efx_mcdi_get_phy_cfg(__in efx_nic_t * enp)1380*49ef7e06SGarrett D'Amore efx_mcdi_get_phy_cfg(
1381*49ef7e06SGarrett D'Amore 	__in		efx_nic_t *enp)
1382*49ef7e06SGarrett D'Amore {
1383*49ef7e06SGarrett D'Amore 	efx_port_t *epp = &(enp->en_port);
1384*49ef7e06SGarrett D'Amore 	efx_nic_cfg_t *encp = &(enp->en_nic_cfg);
1385*49ef7e06SGarrett D'Amore 	efx_mcdi_req_t req;
1386*49ef7e06SGarrett D'Amore 	uint8_t payload[MAX(MC_CMD_GET_PHY_CFG_IN_LEN,
1387*49ef7e06SGarrett D'Amore 			    MC_CMD_GET_PHY_CFG_OUT_LEN)];
1388*49ef7e06SGarrett D'Amore 	efx_rc_t rc;
1389*49ef7e06SGarrett D'Amore 
1390*49ef7e06SGarrett D'Amore 	(void) memset(payload, 0, sizeof (payload));
1391*49ef7e06SGarrett D'Amore 	req.emr_cmd = MC_CMD_GET_PHY_CFG;
1392*49ef7e06SGarrett D'Amore 	req.emr_in_buf = payload;
1393*49ef7e06SGarrett D'Amore 	req.emr_in_length = MC_CMD_GET_PHY_CFG_IN_LEN;
1394*49ef7e06SGarrett D'Amore 	req.emr_out_buf = payload;
1395*49ef7e06SGarrett D'Amore 	req.emr_out_length = MC_CMD_GET_PHY_CFG_OUT_LEN;
1396*49ef7e06SGarrett D'Amore 
1397*49ef7e06SGarrett D'Amore 	efx_mcdi_execute(enp, &req);
1398*49ef7e06SGarrett D'Amore 
1399*49ef7e06SGarrett D'Amore 	if (req.emr_rc != 0) {
1400*49ef7e06SGarrett D'Amore 		rc = req.emr_rc;
1401*49ef7e06SGarrett D'Amore 		goto fail1;
1402*49ef7e06SGarrett D'Amore 	}
1403*49ef7e06SGarrett D'Amore 
1404*49ef7e06SGarrett D'Amore 	if (req.emr_out_length_used < MC_CMD_GET_PHY_CFG_OUT_LEN) {
1405*49ef7e06SGarrett D'Amore 		rc = EMSGSIZE;
1406*49ef7e06SGarrett D'Amore 		goto fail2;
1407*49ef7e06SGarrett D'Amore 	}
1408*49ef7e06SGarrett D'Amore 
1409*49ef7e06SGarrett D'Amore 	encp->enc_phy_type = MCDI_OUT_DWORD(req, GET_PHY_CFG_OUT_TYPE);
1410*49ef7e06SGarrett D'Amore #if EFSYS_OPT_NAMES
1411*49ef7e06SGarrett D'Amore 	(void) strncpy(encp->enc_phy_name,
1412*49ef7e06SGarrett D'Amore 		MCDI_OUT2(req, char, GET_PHY_CFG_OUT_NAME),
1413*49ef7e06SGarrett D'Amore 		MIN(sizeof (encp->enc_phy_name) - 1,
1414*49ef7e06SGarrett D'Amore 		    MC_CMD_GET_PHY_CFG_OUT_NAME_LEN));
1415*49ef7e06SGarrett D'Amore #endif	/* EFSYS_OPT_NAMES */
1416*49ef7e06SGarrett D'Amore 	(void) memset(encp->enc_phy_revision, 0,
1417*49ef7e06SGarrett D'Amore 	    sizeof (encp->enc_phy_revision));
1418*49ef7e06SGarrett D'Amore 	(void) memcpy(encp->enc_phy_revision,
1419*49ef7e06SGarrett D'Amore 		MCDI_OUT2(req, char, GET_PHY_CFG_OUT_REVISION),
1420*49ef7e06SGarrett D'Amore 		MIN(sizeof (encp->enc_phy_revision) - 1,
1421*49ef7e06SGarrett D'Amore 		    MC_CMD_GET_PHY_CFG_OUT_REVISION_LEN));
1422*49ef7e06SGarrett D'Amore #if EFSYS_OPT_PHY_LED_CONTROL
1423*49ef7e06SGarrett D'Amore 	encp->enc_led_mask = ((1 << EFX_PHY_LED_DEFAULT) |
1424*49ef7e06SGarrett D'Amore 			    (1 << EFX_PHY_LED_OFF) |
1425*49ef7e06SGarrett D'Amore 			    (1 << EFX_PHY_LED_ON));
1426*49ef7e06SGarrett D'Amore #endif	/* EFSYS_OPT_PHY_LED_CONTROL */
1427*49ef7e06SGarrett D'Amore 
1428*49ef7e06SGarrett D'Amore 	/* Get the media type of the fixed port, if recognised. */
1429*49ef7e06SGarrett D'Amore 	EFX_STATIC_ASSERT(MC_CMD_MEDIA_XAUI == EFX_PHY_MEDIA_XAUI);
1430*49ef7e06SGarrett D'Amore 	EFX_STATIC_ASSERT(MC_CMD_MEDIA_CX4 == EFX_PHY_MEDIA_CX4);
1431*49ef7e06SGarrett D'Amore 	EFX_STATIC_ASSERT(MC_CMD_MEDIA_KX4 == EFX_PHY_MEDIA_KX4);
1432*49ef7e06SGarrett D'Amore 	EFX_STATIC_ASSERT(MC_CMD_MEDIA_XFP == EFX_PHY_MEDIA_XFP);
1433*49ef7e06SGarrett D'Amore 	EFX_STATIC_ASSERT(MC_CMD_MEDIA_SFP_PLUS == EFX_PHY_MEDIA_SFP_PLUS);
1434*49ef7e06SGarrett D'Amore 	EFX_STATIC_ASSERT(MC_CMD_MEDIA_BASE_T == EFX_PHY_MEDIA_BASE_T);
1435*49ef7e06SGarrett D'Amore 	EFX_STATIC_ASSERT(MC_CMD_MEDIA_QSFP_PLUS == EFX_PHY_MEDIA_QSFP_PLUS);
1436*49ef7e06SGarrett D'Amore 	epp->ep_fixed_port_type =
1437*49ef7e06SGarrett D'Amore 		MCDI_OUT_DWORD(req, GET_PHY_CFG_OUT_MEDIA_TYPE);
1438*49ef7e06SGarrett D'Amore 	if (epp->ep_fixed_port_type >= EFX_PHY_MEDIA_NTYPES)
1439*49ef7e06SGarrett D'Amore 		epp->ep_fixed_port_type = EFX_PHY_MEDIA_INVALID;
1440*49ef7e06SGarrett D'Amore 
1441*49ef7e06SGarrett D'Amore 	epp->ep_phy_cap_mask =
1442*49ef7e06SGarrett D'Amore 		MCDI_OUT_DWORD(req, GET_PHY_CFG_OUT_SUPPORTED_CAP);
1443*49ef7e06SGarrett D'Amore #if EFSYS_OPT_PHY_FLAGS
1444*49ef7e06SGarrett D'Amore 	encp->enc_phy_flags_mask = MCDI_OUT_DWORD(req, GET_PHY_CFG_OUT_FLAGS);
1445*49ef7e06SGarrett D'Amore #endif	/* EFSYS_OPT_PHY_FLAGS */
1446*49ef7e06SGarrett D'Amore 
1447*49ef7e06SGarrett D'Amore 	encp->enc_port = (uint8_t)MCDI_OUT_DWORD(req, GET_PHY_CFG_OUT_PRT);
1448*49ef7e06SGarrett D'Amore 
1449*49ef7e06SGarrett D'Amore 	/* Populate internal state */
1450*49ef7e06SGarrett D'Amore 	encp->enc_mcdi_mdio_channel =
1451*49ef7e06SGarrett D'Amore 		(uint8_t)MCDI_OUT_DWORD(req, GET_PHY_CFG_OUT_CHANNEL);
1452*49ef7e06SGarrett D'Amore 
1453*49ef7e06SGarrett D'Amore #if EFSYS_OPT_PHY_STATS
1454*49ef7e06SGarrett D'Amore 	encp->enc_mcdi_phy_stat_mask =
1455*49ef7e06SGarrett D'Amore 		MCDI_OUT_DWORD(req, GET_PHY_CFG_OUT_STATS_MASK);
1456*49ef7e06SGarrett D'Amore #endif	/* EFSYS_OPT_PHY_STATS */
1457*49ef7e06SGarrett D'Amore 
1458*49ef7e06SGarrett D'Amore #if EFSYS_OPT_BIST
1459*49ef7e06SGarrett D'Amore 	encp->enc_bist_mask = 0;
1460*49ef7e06SGarrett D'Amore 	if (MCDI_OUT_DWORD_FIELD(req, GET_PHY_CFG_OUT_FLAGS,
1461*49ef7e06SGarrett D'Amore 	    GET_PHY_CFG_OUT_BIST_CABLE_SHORT))
1462*49ef7e06SGarrett D'Amore 		encp->enc_bist_mask |= (1 << EFX_BIST_TYPE_PHY_CABLE_SHORT);
1463*49ef7e06SGarrett D'Amore 	if (MCDI_OUT_DWORD_FIELD(req, GET_PHY_CFG_OUT_FLAGS,
1464*49ef7e06SGarrett D'Amore 	    GET_PHY_CFG_OUT_BIST_CABLE_LONG))
1465*49ef7e06SGarrett D'Amore 		encp->enc_bist_mask |= (1 << EFX_BIST_TYPE_PHY_CABLE_LONG);
1466*49ef7e06SGarrett D'Amore 	if (MCDI_OUT_DWORD_FIELD(req, GET_PHY_CFG_OUT_FLAGS,
1467*49ef7e06SGarrett D'Amore 	    GET_PHY_CFG_OUT_BIST))
1468*49ef7e06SGarrett D'Amore 		encp->enc_bist_mask |= (1 << EFX_BIST_TYPE_PHY_NORMAL);
1469*49ef7e06SGarrett D'Amore #endif  /* EFSYS_OPT_BIST */
1470*49ef7e06SGarrett D'Amore 
1471*49ef7e06SGarrett D'Amore 	return (0);
1472*49ef7e06SGarrett D'Amore 
1473*49ef7e06SGarrett D'Amore fail2:
1474*49ef7e06SGarrett D'Amore 	EFSYS_PROBE(fail2);
1475*49ef7e06SGarrett D'Amore fail1:
1476*49ef7e06SGarrett D'Amore 	EFSYS_PROBE1(fail1, efx_rc_t, rc);
1477*49ef7e06SGarrett D'Amore 
1478*49ef7e06SGarrett D'Amore 	return (rc);
1479*49ef7e06SGarrett D'Amore }
1480*49ef7e06SGarrett D'Amore 
1481*49ef7e06SGarrett D'Amore 	__checkReturn		efx_rc_t
efx_mcdi_firmware_update_supported(__in efx_nic_t * enp,__out boolean_t * supportedp)1482*49ef7e06SGarrett D'Amore efx_mcdi_firmware_update_supported(
1483*49ef7e06SGarrett D'Amore 	__in			efx_nic_t *enp,
1484*49ef7e06SGarrett D'Amore 	__out			boolean_t *supportedp)
1485*49ef7e06SGarrett D'Amore {
1486*49ef7e06SGarrett D'Amore 	const efx_mcdi_ops_t *emcop = enp->en_mcdi.em_emcop;
1487*49ef7e06SGarrett D'Amore 	efx_rc_t rc;
1488*49ef7e06SGarrett D'Amore 
1489*49ef7e06SGarrett D'Amore 	if (emcop != NULL) {
1490*49ef7e06SGarrett D'Amore 		if ((rc = emcop->emco_feature_supported(enp,
1491*49ef7e06SGarrett D'Amore 			    EFX_MCDI_FEATURE_FW_UPDATE, supportedp)) != 0)
1492*49ef7e06SGarrett D'Amore 			goto fail1;
1493*49ef7e06SGarrett D'Amore 	} else {
1494*49ef7e06SGarrett D'Amore 		/* Earlier devices always supported updates */
1495*49ef7e06SGarrett D'Amore 		*supportedp = B_TRUE;
1496*49ef7e06SGarrett D'Amore 	}
1497*49ef7e06SGarrett D'Amore 
1498*49ef7e06SGarrett D'Amore 	return (0);
1499*49ef7e06SGarrett D'Amore 
1500*49ef7e06SGarrett D'Amore fail1:
1501*49ef7e06SGarrett D'Amore 	EFSYS_PROBE1(fail1, efx_rc_t, rc);
1502*49ef7e06SGarrett D'Amore 
1503*49ef7e06SGarrett D'Amore 	return (rc);
1504*49ef7e06SGarrett D'Amore }
1505*49ef7e06SGarrett D'Amore 
1506*49ef7e06SGarrett D'Amore 	__checkReturn		efx_rc_t
efx_mcdi_macaddr_change_supported(__in efx_nic_t * enp,__out boolean_t * supportedp)1507*49ef7e06SGarrett D'Amore efx_mcdi_macaddr_change_supported(
1508*49ef7e06SGarrett D'Amore 	__in			efx_nic_t *enp,
1509*49ef7e06SGarrett D'Amore 	__out			boolean_t *supportedp)
1510*49ef7e06SGarrett D'Amore {
1511*49ef7e06SGarrett D'Amore 	const efx_mcdi_ops_t *emcop = enp->en_mcdi.em_emcop;
1512*49ef7e06SGarrett D'Amore 	efx_rc_t rc;
1513*49ef7e06SGarrett D'Amore 
1514*49ef7e06SGarrett D'Amore 	if (emcop != NULL) {
1515*49ef7e06SGarrett D'Amore 		if ((rc = emcop->emco_feature_supported(enp,
1516*49ef7e06SGarrett D'Amore 			    EFX_MCDI_FEATURE_MACADDR_CHANGE, supportedp)) != 0)
1517*49ef7e06SGarrett D'Amore 			goto fail1;
1518*49ef7e06SGarrett D'Amore 	} else {
1519*49ef7e06SGarrett D'Amore 		/* Earlier devices always supported MAC changes */
1520*49ef7e06SGarrett D'Amore 		*supportedp = B_TRUE;
1521*49ef7e06SGarrett D'Amore 	}
1522*49ef7e06SGarrett D'Amore 
1523*49ef7e06SGarrett D'Amore 	return (0);
1524*49ef7e06SGarrett D'Amore 
1525*49ef7e06SGarrett D'Amore fail1:
1526*49ef7e06SGarrett D'Amore 	EFSYS_PROBE1(fail1, efx_rc_t, rc);
1527*49ef7e06SGarrett D'Amore 
1528*49ef7e06SGarrett D'Amore 	return (rc);
1529*49ef7e06SGarrett D'Amore }
1530*49ef7e06SGarrett D'Amore 
1531*49ef7e06SGarrett D'Amore 	__checkReturn		efx_rc_t
efx_mcdi_link_control_supported(__in efx_nic_t * enp,__out boolean_t * supportedp)1532*49ef7e06SGarrett D'Amore efx_mcdi_link_control_supported(
1533*49ef7e06SGarrett D'Amore 	__in			efx_nic_t *enp,
1534*49ef7e06SGarrett D'Amore 	__out			boolean_t *supportedp)
1535*49ef7e06SGarrett D'Amore {
1536*49ef7e06SGarrett D'Amore 	const efx_mcdi_ops_t *emcop = enp->en_mcdi.em_emcop;
1537*49ef7e06SGarrett D'Amore 	efx_rc_t rc;
1538*49ef7e06SGarrett D'Amore 
1539*49ef7e06SGarrett D'Amore 	if (emcop != NULL) {
1540*49ef7e06SGarrett D'Amore 		if ((rc = emcop->emco_feature_supported(enp,
1541*49ef7e06SGarrett D'Amore 			    EFX_MCDI_FEATURE_LINK_CONTROL, supportedp)) != 0)
1542*49ef7e06SGarrett D'Amore 			goto fail1;
1543*49ef7e06SGarrett D'Amore 	} else {
1544*49ef7e06SGarrett D'Amore 		/* Earlier devices always supported link control */
1545*49ef7e06SGarrett D'Amore 		*supportedp = B_TRUE;
1546*49ef7e06SGarrett D'Amore 	}
1547*49ef7e06SGarrett D'Amore 
1548*49ef7e06SGarrett D'Amore 	return (0);
1549*49ef7e06SGarrett D'Amore 
1550*49ef7e06SGarrett D'Amore fail1:
1551*49ef7e06SGarrett D'Amore 	EFSYS_PROBE1(fail1, efx_rc_t, rc);
1552*49ef7e06SGarrett D'Amore 
1553*49ef7e06SGarrett D'Amore 	return (rc);
1554*49ef7e06SGarrett D'Amore }
1555*49ef7e06SGarrett D'Amore 
1556*49ef7e06SGarrett D'Amore 	__checkReturn		efx_rc_t
efx_mcdi_mac_spoofing_supported(__in efx_nic_t * enp,__out boolean_t * supportedp)1557*49ef7e06SGarrett D'Amore efx_mcdi_mac_spoofing_supported(
1558*49ef7e06SGarrett D'Amore 	__in			efx_nic_t *enp,
1559*49ef7e06SGarrett D'Amore 	__out			boolean_t *supportedp)
1560*49ef7e06SGarrett D'Amore {
1561*49ef7e06SGarrett D'Amore 	const efx_mcdi_ops_t *emcop = enp->en_mcdi.em_emcop;
1562*49ef7e06SGarrett D'Amore 	efx_rc_t rc;
1563*49ef7e06SGarrett D'Amore 
1564*49ef7e06SGarrett D'Amore 	if (emcop != NULL) {
1565*49ef7e06SGarrett D'Amore 		if ((rc = emcop->emco_feature_supported(enp,
1566*49ef7e06SGarrett D'Amore 			    EFX_MCDI_FEATURE_MAC_SPOOFING, supportedp)) != 0)
1567*49ef7e06SGarrett D'Amore 			goto fail1;
1568*49ef7e06SGarrett D'Amore 	} else {
1569*49ef7e06SGarrett D'Amore 		/* Earlier devices always supported MAC spoofing */
1570*49ef7e06SGarrett D'Amore 		*supportedp = B_TRUE;
1571*49ef7e06SGarrett D'Amore 	}
1572*49ef7e06SGarrett D'Amore 
1573*49ef7e06SGarrett D'Amore 	return (0);
1574*49ef7e06SGarrett D'Amore 
1575*49ef7e06SGarrett D'Amore fail1:
1576*49ef7e06SGarrett D'Amore 	EFSYS_PROBE1(fail1, efx_rc_t, rc);
1577*49ef7e06SGarrett D'Amore 
1578*49ef7e06SGarrett D'Amore 	return (rc);
1579*49ef7e06SGarrett D'Amore }
1580*49ef7e06SGarrett D'Amore 
1581*49ef7e06SGarrett D'Amore #if EFSYS_OPT_BIST
1582*49ef7e06SGarrett D'Amore 
1583*49ef7e06SGarrett D'Amore #if EFSYS_OPT_HUNTINGTON || EFSYS_OPT_MEDFORD
1584*49ef7e06SGarrett D'Amore /*
1585*49ef7e06SGarrett D'Amore  * Enter bist offline mode. This is a fw mode which puts the NIC into a state
1586*49ef7e06SGarrett D'Amore  * where memory BIST tests can be run and not much else can interfere or happen.
1587*49ef7e06SGarrett D'Amore  * A reboot is required to exit this mode.
1588*49ef7e06SGarrett D'Amore  */
1589*49ef7e06SGarrett D'Amore 	__checkReturn		efx_rc_t
efx_mcdi_bist_enable_offline(__in efx_nic_t * enp)1590*49ef7e06SGarrett D'Amore efx_mcdi_bist_enable_offline(
1591*49ef7e06SGarrett D'Amore 	__in			efx_nic_t *enp)
1592*49ef7e06SGarrett D'Amore {
1593*49ef7e06SGarrett D'Amore 	efx_mcdi_req_t req;
1594*49ef7e06SGarrett D'Amore 	efx_rc_t rc;
1595*49ef7e06SGarrett D'Amore 
1596*49ef7e06SGarrett D'Amore 	EFX_STATIC_ASSERT(MC_CMD_ENABLE_OFFLINE_BIST_IN_LEN == 0);
1597*49ef7e06SGarrett D'Amore 	EFX_STATIC_ASSERT(MC_CMD_ENABLE_OFFLINE_BIST_OUT_LEN == 0);
1598*49ef7e06SGarrett D'Amore 
1599*49ef7e06SGarrett D'Amore 	req.emr_cmd = MC_CMD_ENABLE_OFFLINE_BIST;
1600*49ef7e06SGarrett D'Amore 	req.emr_in_buf = NULL;
1601*49ef7e06SGarrett D'Amore 	req.emr_in_length = 0;
1602*49ef7e06SGarrett D'Amore 	req.emr_out_buf = NULL;
1603*49ef7e06SGarrett D'Amore 	req.emr_out_length = 0;
1604*49ef7e06SGarrett D'Amore 
1605*49ef7e06SGarrett D'Amore 	efx_mcdi_execute(enp, &req);
1606*49ef7e06SGarrett D'Amore 
1607*49ef7e06SGarrett D'Amore 	if (req.emr_rc != 0) {
1608*49ef7e06SGarrett D'Amore 		rc = req.emr_rc;
1609*49ef7e06SGarrett D'Amore 		goto fail1;
1610*49ef7e06SGarrett D'Amore 	}
1611*49ef7e06SGarrett D'Amore 
1612*49ef7e06SGarrett D'Amore 	return (0);
1613*49ef7e06SGarrett D'Amore 
1614*49ef7e06SGarrett D'Amore fail1:
1615*49ef7e06SGarrett D'Amore 	EFSYS_PROBE1(fail1, efx_rc_t, rc);
1616*49ef7e06SGarrett D'Amore 
1617*49ef7e06SGarrett D'Amore 	return (rc);
1618*49ef7e06SGarrett D'Amore }
1619*49ef7e06SGarrett D'Amore #endif /* EFSYS_OPT_HUNTINGTON || EFSYS_OPT_MEDFORD */
1620*49ef7e06SGarrett D'Amore 
1621*49ef7e06SGarrett D'Amore 	__checkReturn		efx_rc_t
efx_mcdi_bist_start(__in efx_nic_t * enp,__in efx_bist_type_t type)1622*49ef7e06SGarrett D'Amore efx_mcdi_bist_start(
1623*49ef7e06SGarrett D'Amore 	__in			efx_nic_t *enp,
1624*49ef7e06SGarrett D'Amore 	__in			efx_bist_type_t type)
1625*49ef7e06SGarrett D'Amore {
1626*49ef7e06SGarrett D'Amore 	efx_mcdi_req_t req;
1627*49ef7e06SGarrett D'Amore 	uint8_t payload[MAX(MC_CMD_START_BIST_IN_LEN,
1628*49ef7e06SGarrett D'Amore 			    MC_CMD_START_BIST_OUT_LEN)];
1629*49ef7e06SGarrett D'Amore 	efx_rc_t rc;
1630*49ef7e06SGarrett D'Amore 
1631*49ef7e06SGarrett D'Amore 	(void) memset(payload, 0, sizeof (payload));
1632*49ef7e06SGarrett D'Amore 	req.emr_cmd = MC_CMD_START_BIST;
1633*49ef7e06SGarrett D'Amore 	req.emr_in_buf = payload;
1634*49ef7e06SGarrett D'Amore 	req.emr_in_length = MC_CMD_START_BIST_IN_LEN;
1635*49ef7e06SGarrett D'Amore 	req.emr_out_buf = payload;
1636*49ef7e06SGarrett D'Amore 	req.emr_out_length = MC_CMD_START_BIST_OUT_LEN;
1637*49ef7e06SGarrett D'Amore 
1638*49ef7e06SGarrett D'Amore 	switch (type) {
1639*49ef7e06SGarrett D'Amore 	case EFX_BIST_TYPE_PHY_NORMAL:
1640*49ef7e06SGarrett D'Amore 		MCDI_IN_SET_DWORD(req, START_BIST_IN_TYPE, MC_CMD_PHY_BIST);
1641*49ef7e06SGarrett D'Amore 		break;
1642*49ef7e06SGarrett D'Amore 	case EFX_BIST_TYPE_PHY_CABLE_SHORT:
1643*49ef7e06SGarrett D'Amore 		MCDI_IN_SET_DWORD(req, START_BIST_IN_TYPE,
1644*49ef7e06SGarrett D'Amore 		    MC_CMD_PHY_BIST_CABLE_SHORT);
1645*49ef7e06SGarrett D'Amore 		break;
1646*49ef7e06SGarrett D'Amore 	case EFX_BIST_TYPE_PHY_CABLE_LONG:
1647*49ef7e06SGarrett D'Amore 		MCDI_IN_SET_DWORD(req, START_BIST_IN_TYPE,
1648*49ef7e06SGarrett D'Amore 		    MC_CMD_PHY_BIST_CABLE_LONG);
1649*49ef7e06SGarrett D'Amore 		break;
1650*49ef7e06SGarrett D'Amore 	case EFX_BIST_TYPE_MC_MEM:
1651*49ef7e06SGarrett D'Amore 		MCDI_IN_SET_DWORD(req, START_BIST_IN_TYPE,
1652*49ef7e06SGarrett D'Amore 		    MC_CMD_MC_MEM_BIST);
1653*49ef7e06SGarrett D'Amore 		break;
1654*49ef7e06SGarrett D'Amore 	case EFX_BIST_TYPE_SAT_MEM:
1655*49ef7e06SGarrett D'Amore 		MCDI_IN_SET_DWORD(req, START_BIST_IN_TYPE,
1656*49ef7e06SGarrett D'Amore 		    MC_CMD_PORT_MEM_BIST);
1657*49ef7e06SGarrett D'Amore 		break;
1658*49ef7e06SGarrett D'Amore 	case EFX_BIST_TYPE_REG:
1659*49ef7e06SGarrett D'Amore 		MCDI_IN_SET_DWORD(req, START_BIST_IN_TYPE,
1660*49ef7e06SGarrett D'Amore 		    MC_CMD_REG_BIST);
1661*49ef7e06SGarrett D'Amore 		break;
1662*49ef7e06SGarrett D'Amore 	default:
1663*49ef7e06SGarrett D'Amore 		EFSYS_ASSERT(0);
1664*49ef7e06SGarrett D'Amore 	}
1665*49ef7e06SGarrett D'Amore 
1666*49ef7e06SGarrett D'Amore 	efx_mcdi_execute(enp, &req);
1667*49ef7e06SGarrett D'Amore 
1668*49ef7e06SGarrett D'Amore 	if (req.emr_rc != 0) {
1669*49ef7e06SGarrett D'Amore 		rc = req.emr_rc;
1670*49ef7e06SGarrett D'Amore 		goto fail1;
1671*49ef7e06SGarrett D'Amore 	}
1672*49ef7e06SGarrett D'Amore 
1673*49ef7e06SGarrett D'Amore 	return (0);
1674*49ef7e06SGarrett D'Amore 
1675*49ef7e06SGarrett D'Amore fail1:
1676*49ef7e06SGarrett D'Amore 	EFSYS_PROBE1(fail1, efx_rc_t, rc);
1677*49ef7e06SGarrett D'Amore 
1678*49ef7e06SGarrett D'Amore 	return (rc);
1679*49ef7e06SGarrett D'Amore }
1680*49ef7e06SGarrett D'Amore 
1681*49ef7e06SGarrett D'Amore #endif /* EFSYS_OPT_BIST */
1682*49ef7e06SGarrett D'Amore 
1683*49ef7e06SGarrett D'Amore 
1684*49ef7e06SGarrett D'Amore /* Enable logging of some events (e.g. link state changes) */
1685*49ef7e06SGarrett D'Amore 	__checkReturn	efx_rc_t
efx_mcdi_log_ctrl(__in efx_nic_t * enp)1686*49ef7e06SGarrett D'Amore efx_mcdi_log_ctrl(
1687*49ef7e06SGarrett D'Amore 	__in		efx_nic_t *enp)
1688*49ef7e06SGarrett D'Amore {
1689*49ef7e06SGarrett D'Amore 	efx_mcdi_req_t req;
1690*49ef7e06SGarrett D'Amore 	uint8_t payload[MAX(MC_CMD_LOG_CTRL_IN_LEN,
1691*49ef7e06SGarrett D'Amore 			    MC_CMD_LOG_CTRL_OUT_LEN)];
1692*49ef7e06SGarrett D'Amore 	efx_rc_t rc;
1693*49ef7e06SGarrett D'Amore 
1694*49ef7e06SGarrett D'Amore 	(void) memset(payload, 0, sizeof (payload));
1695*49ef7e06SGarrett D'Amore 	req.emr_cmd = MC_CMD_LOG_CTRL;
1696*49ef7e06SGarrett D'Amore 	req.emr_in_buf = payload;
1697*49ef7e06SGarrett D'Amore 	req.emr_in_length = MC_CMD_LOG_CTRL_IN_LEN;
1698*49ef7e06SGarrett D'Amore 	req.emr_out_buf = payload;
1699*49ef7e06SGarrett D'Amore 	req.emr_out_length = MC_CMD_LOG_CTRL_OUT_LEN;
1700*49ef7e06SGarrett D'Amore 
1701*49ef7e06SGarrett D'Amore 	MCDI_IN_SET_DWORD(req, LOG_CTRL_IN_LOG_DEST,
1702*49ef7e06SGarrett D'Amore 		    MC_CMD_LOG_CTRL_IN_LOG_DEST_EVQ);
1703*49ef7e06SGarrett D'Amore 	MCDI_IN_SET_DWORD(req, LOG_CTRL_IN_LOG_DEST_EVQ, 0);
1704*49ef7e06SGarrett D'Amore 
1705*49ef7e06SGarrett D'Amore 	efx_mcdi_execute(enp, &req);
1706*49ef7e06SGarrett D'Amore 
1707*49ef7e06SGarrett D'Amore 	if (req.emr_rc != 0) {
1708*49ef7e06SGarrett D'Amore 		rc = req.emr_rc;
1709*49ef7e06SGarrett D'Amore 		goto fail1;
1710*49ef7e06SGarrett D'Amore 	}
1711*49ef7e06SGarrett D'Amore 
1712*49ef7e06SGarrett D'Amore 	return (0);
1713*49ef7e06SGarrett D'Amore 
1714*49ef7e06SGarrett D'Amore fail1:
1715*49ef7e06SGarrett D'Amore 	EFSYS_PROBE1(fail1, efx_rc_t, rc);
1716*49ef7e06SGarrett D'Amore 
1717*49ef7e06SGarrett D'Amore 	return (rc);
1718*49ef7e06SGarrett D'Amore }
1719*49ef7e06SGarrett D'Amore 
1720*49ef7e06SGarrett D'Amore 
1721*49ef7e06SGarrett D'Amore #if EFSYS_OPT_MAC_STATS
1722*49ef7e06SGarrett D'Amore 
1723*49ef7e06SGarrett D'Amore typedef enum efx_stats_action_e
1724*49ef7e06SGarrett D'Amore {
1725*49ef7e06SGarrett D'Amore 	EFX_STATS_CLEAR,
1726*49ef7e06SGarrett D'Amore 	EFX_STATS_UPLOAD,
1727*49ef7e06SGarrett D'Amore 	EFX_STATS_ENABLE_NOEVENTS,
1728*49ef7e06SGarrett D'Amore 	EFX_STATS_ENABLE_EVENTS,
1729*49ef7e06SGarrett D'Amore 	EFX_STATS_DISABLE,
1730*49ef7e06SGarrett D'Amore } efx_stats_action_t;
1731*49ef7e06SGarrett D'Amore 
1732*49ef7e06SGarrett D'Amore static	__checkReturn	efx_rc_t
efx_mcdi_mac_stats(__in efx_nic_t * enp,__in_opt efsys_mem_t * esmp,__in efx_stats_action_t action)1733*49ef7e06SGarrett D'Amore efx_mcdi_mac_stats(
1734*49ef7e06SGarrett D'Amore 	__in		efx_nic_t *enp,
1735*49ef7e06SGarrett D'Amore 	__in_opt	efsys_mem_t *esmp,
1736*49ef7e06SGarrett D'Amore 	__in		efx_stats_action_t action)
1737*49ef7e06SGarrett D'Amore {
1738*49ef7e06SGarrett D'Amore 	efx_mcdi_req_t req;
1739*49ef7e06SGarrett D'Amore 	uint8_t payload[MAX(MC_CMD_MAC_STATS_IN_LEN,
1740*49ef7e06SGarrett D'Amore 			    MC_CMD_MAC_STATS_OUT_DMA_LEN)];
1741*49ef7e06SGarrett D'Amore 	int clear = (action == EFX_STATS_CLEAR);
1742*49ef7e06SGarrett D'Amore 	int upload = (action == EFX_STATS_UPLOAD);
1743*49ef7e06SGarrett D'Amore 	int enable = (action == EFX_STATS_ENABLE_NOEVENTS);
1744*49ef7e06SGarrett D'Amore 	int events = (action == EFX_STATS_ENABLE_EVENTS);
1745*49ef7e06SGarrett D'Amore 	int disable = (action == EFX_STATS_DISABLE);
1746*49ef7e06SGarrett D'Amore 	efx_rc_t rc;
1747*49ef7e06SGarrett D'Amore 
1748*49ef7e06SGarrett D'Amore 	(void) memset(payload, 0, sizeof (payload));
1749*49ef7e06SGarrett D'Amore 	req.emr_cmd = MC_CMD_MAC_STATS;
1750*49ef7e06SGarrett D'Amore 	req.emr_in_buf = payload;
1751*49ef7e06SGarrett D'Amore 	req.emr_in_length = MC_CMD_MAC_STATS_IN_LEN;
1752*49ef7e06SGarrett D'Amore 	req.emr_out_buf = payload;
1753*49ef7e06SGarrett D'Amore 	req.emr_out_length = MC_CMD_MAC_STATS_OUT_DMA_LEN;
1754*49ef7e06SGarrett D'Amore 
1755*49ef7e06SGarrett D'Amore 	MCDI_IN_POPULATE_DWORD_6(req, MAC_STATS_IN_CMD,
1756*49ef7e06SGarrett D'Amore 	    MAC_STATS_IN_DMA, upload,
1757*49ef7e06SGarrett D'Amore 	    MAC_STATS_IN_CLEAR, clear,
1758*49ef7e06SGarrett D'Amore 	    MAC_STATS_IN_PERIODIC_CHANGE, enable | events | disable,
1759*49ef7e06SGarrett D'Amore 	    MAC_STATS_IN_PERIODIC_ENABLE, enable | events,
1760*49ef7e06SGarrett D'Amore 	    MAC_STATS_IN_PERIODIC_NOEVENT, !events,
1761*49ef7e06SGarrett D'Amore 	    MAC_STATS_IN_PERIOD_MS, (enable | events) ? 1000: 0);
1762*49ef7e06SGarrett D'Amore 
1763*49ef7e06SGarrett D'Amore 	if (esmp != NULL) {
1764*49ef7e06SGarrett D'Amore 		int bytes = MC_CMD_MAC_NSTATS * sizeof (uint64_t);
1765*49ef7e06SGarrett D'Amore 
1766*49ef7e06SGarrett D'Amore 		EFX_STATIC_ASSERT(MC_CMD_MAC_NSTATS * sizeof (uint64_t) <=
1767*49ef7e06SGarrett D'Amore 		    EFX_MAC_STATS_SIZE);
1768*49ef7e06SGarrett D'Amore 
1769*49ef7e06SGarrett D'Amore 		MCDI_IN_SET_DWORD(req, MAC_STATS_IN_DMA_ADDR_LO,
1770*49ef7e06SGarrett D'Amore 			    EFSYS_MEM_ADDR(esmp) & 0xffffffff);
1771*49ef7e06SGarrett D'Amore 		MCDI_IN_SET_DWORD(req, MAC_STATS_IN_DMA_ADDR_HI,
1772*49ef7e06SGarrett D'Amore 			    EFSYS_MEM_ADDR(esmp) >> 32);
1773*49ef7e06SGarrett D'Amore 		MCDI_IN_SET_DWORD(req, MAC_STATS_IN_DMA_LEN, bytes);
1774*49ef7e06SGarrett D'Amore 	} else {
1775*49ef7e06SGarrett D'Amore 		EFSYS_ASSERT(!upload && !enable && !events);
1776*49ef7e06SGarrett D'Amore 	}
1777*49ef7e06SGarrett D'Amore 
1778*49ef7e06SGarrett D'Amore 	/*
1779*49ef7e06SGarrett D'Amore 	 * NOTE: Do not use EVB_PORT_ID_ASSIGNED when disabling periodic stats,
1780*49ef7e06SGarrett D'Amore 	 *	 as this may fail (and leave periodic DMA enabled) if the
1781*49ef7e06SGarrett D'Amore 	 *	 vadapter has already been deleted.
1782*49ef7e06SGarrett D'Amore 	 */
1783*49ef7e06SGarrett D'Amore 	MCDI_IN_SET_DWORD(req, MAC_STATS_IN_PORT_ID,
1784*49ef7e06SGarrett D'Amore 	    (disable ? EVB_PORT_ID_NULL : enp->en_vport_id));
1785*49ef7e06SGarrett D'Amore 
1786*49ef7e06SGarrett D'Amore 	efx_mcdi_execute(enp, &req);
1787*49ef7e06SGarrett D'Amore 
1788*49ef7e06SGarrett D'Amore 	if (req.emr_rc != 0) {
1789*49ef7e06SGarrett D'Amore 		/* EF10: Expect ENOENT if no DMA queues are initialised */
1790*49ef7e06SGarrett D'Amore 		if ((req.emr_rc != ENOENT) ||
1791*49ef7e06SGarrett D'Amore 		    (enp->en_rx_qcount + enp->en_tx_qcount != 0)) {
1792*49ef7e06SGarrett D'Amore 			rc = req.emr_rc;
1793*49ef7e06SGarrett D'Amore 			goto fail1;
1794*49ef7e06SGarrett D'Amore 		}
1795*49ef7e06SGarrett D'Amore 	}
1796*49ef7e06SGarrett D'Amore 
1797*49ef7e06SGarrett D'Amore 	return (0);
1798*49ef7e06SGarrett D'Amore 
1799*49ef7e06SGarrett D'Amore fail1:
1800*49ef7e06SGarrett D'Amore 	EFSYS_PROBE1(fail1, efx_rc_t, rc);
1801*49ef7e06SGarrett D'Amore 
1802*49ef7e06SGarrett D'Amore 	return (rc);
1803*49ef7e06SGarrett D'Amore }
1804*49ef7e06SGarrett D'Amore 
1805*49ef7e06SGarrett D'Amore 	__checkReturn	efx_rc_t
efx_mcdi_mac_stats_clear(__in efx_nic_t * enp)1806*49ef7e06SGarrett D'Amore efx_mcdi_mac_stats_clear(
1807*49ef7e06SGarrett D'Amore 	__in		efx_nic_t *enp)
1808*49ef7e06SGarrett D'Amore {
1809*49ef7e06SGarrett D'Amore 	efx_rc_t rc;
1810*49ef7e06SGarrett D'Amore 
1811*49ef7e06SGarrett D'Amore 	if ((rc = efx_mcdi_mac_stats(enp, NULL, EFX_STATS_CLEAR)) != 0)
1812*49ef7e06SGarrett D'Amore 		goto fail1;
1813*49ef7e06SGarrett D'Amore 
1814*49ef7e06SGarrett D'Amore 	return (0);
1815*49ef7e06SGarrett D'Amore 
1816*49ef7e06SGarrett D'Amore fail1:
1817*49ef7e06SGarrett D'Amore 	EFSYS_PROBE1(fail1, efx_rc_t, rc);
1818*49ef7e06SGarrett D'Amore 
1819*49ef7e06SGarrett D'Amore 	return (rc);
1820*49ef7e06SGarrett D'Amore }
1821*49ef7e06SGarrett D'Amore 
1822*49ef7e06SGarrett D'Amore 	__checkReturn	efx_rc_t
efx_mcdi_mac_stats_upload(__in efx_nic_t * enp,__in efsys_mem_t * esmp)1823*49ef7e06SGarrett D'Amore efx_mcdi_mac_stats_upload(
1824*49ef7e06SGarrett D'Amore 	__in		efx_nic_t *enp,
1825*49ef7e06SGarrett D'Amore 	__in		efsys_mem_t *esmp)
1826*49ef7e06SGarrett D'Amore {
1827*49ef7e06SGarrett D'Amore 	efx_rc_t rc;
1828*49ef7e06SGarrett D'Amore 
1829*49ef7e06SGarrett D'Amore 	/*
1830*49ef7e06SGarrett D'Amore 	 * The MC DMAs aggregate statistics for our convenience, so we can
1831*49ef7e06SGarrett D'Amore 	 * avoid having to pull the statistics buffer into the cache to
1832*49ef7e06SGarrett D'Amore 	 * maintain cumulative statistics.
1833*49ef7e06SGarrett D'Amore 	 */
1834*49ef7e06SGarrett D'Amore 	if ((rc = efx_mcdi_mac_stats(enp, esmp, EFX_STATS_UPLOAD)) != 0)
1835*49ef7e06SGarrett D'Amore 		goto fail1;
1836*49ef7e06SGarrett D'Amore 
1837*49ef7e06SGarrett D'Amore 	return (0);
1838*49ef7e06SGarrett D'Amore 
1839*49ef7e06SGarrett D'Amore fail1:
1840*49ef7e06SGarrett D'Amore 	EFSYS_PROBE1(fail1, efx_rc_t, rc);
1841*49ef7e06SGarrett D'Amore 
1842*49ef7e06SGarrett D'Amore 	return (rc);
1843*49ef7e06SGarrett D'Amore }
1844*49ef7e06SGarrett D'Amore 
1845*49ef7e06SGarrett D'Amore 	__checkReturn	efx_rc_t
efx_mcdi_mac_stats_periodic(__in efx_nic_t * enp,__in efsys_mem_t * esmp,__in uint16_t period,__in boolean_t events)1846*49ef7e06SGarrett D'Amore efx_mcdi_mac_stats_periodic(
1847*49ef7e06SGarrett D'Amore 	__in		efx_nic_t *enp,
1848*49ef7e06SGarrett D'Amore 	__in		efsys_mem_t *esmp,
1849*49ef7e06SGarrett D'Amore 	__in		uint16_t period,
1850*49ef7e06SGarrett D'Amore 	__in		boolean_t events)
1851*49ef7e06SGarrett D'Amore {
1852*49ef7e06SGarrett D'Amore 	efx_rc_t rc;
1853*49ef7e06SGarrett D'Amore 
1854*49ef7e06SGarrett D'Amore 	/*
1855*49ef7e06SGarrett D'Amore 	 * The MC DMAs aggregate statistics for our convenience, so we can
1856*49ef7e06SGarrett D'Amore 	 * avoid having to pull the statistics buffer into the cache to
1857*49ef7e06SGarrett D'Amore 	 * maintain cumulative statistics.
1858*49ef7e06SGarrett D'Amore 	 * Huntington uses a fixed 1sec period, so use that on Siena too.
1859*49ef7e06SGarrett D'Amore 	 */
1860*49ef7e06SGarrett D'Amore 	if (period == 0)
1861*49ef7e06SGarrett D'Amore 		rc = efx_mcdi_mac_stats(enp, NULL, EFX_STATS_DISABLE);
1862*49ef7e06SGarrett D'Amore 	else if (events)
1863*49ef7e06SGarrett D'Amore 		rc = efx_mcdi_mac_stats(enp, esmp, EFX_STATS_ENABLE_EVENTS);
1864*49ef7e06SGarrett D'Amore 	else
1865*49ef7e06SGarrett D'Amore 		rc = efx_mcdi_mac_stats(enp, esmp, EFX_STATS_ENABLE_NOEVENTS);
1866*49ef7e06SGarrett D'Amore 
1867*49ef7e06SGarrett D'Amore 	if (rc != 0)
1868*49ef7e06SGarrett D'Amore 		goto fail1;
1869*49ef7e06SGarrett D'Amore 
1870*49ef7e06SGarrett D'Amore 	return (0);
1871*49ef7e06SGarrett D'Amore 
1872*49ef7e06SGarrett D'Amore fail1:
1873*49ef7e06SGarrett D'Amore 	EFSYS_PROBE1(fail1, efx_rc_t, rc);
1874*49ef7e06SGarrett D'Amore 
1875*49ef7e06SGarrett D'Amore 	return (rc);
1876*49ef7e06SGarrett D'Amore }
1877*49ef7e06SGarrett D'Amore 
1878*49ef7e06SGarrett D'Amore #endif	/* EFSYS_OPT_MAC_STATS */
1879*49ef7e06SGarrett D'Amore 
1880*49ef7e06SGarrett D'Amore #if EFSYS_OPT_HUNTINGTON || EFSYS_OPT_MEDFORD
1881*49ef7e06SGarrett D'Amore 
1882*49ef7e06SGarrett D'Amore /*
1883*49ef7e06SGarrett D'Amore  * This function returns the pf and vf number of a function.  If it is a pf the
1884*49ef7e06SGarrett D'Amore  * vf number is 0xffff.  The vf number is the index of the vf on that
1885*49ef7e06SGarrett D'Amore  * function. So if you have 3 vfs on pf 0 the 3 vfs will return (pf=0,vf=0),
1886*49ef7e06SGarrett D'Amore  * (pf=0,vf=1), (pf=0,vf=2) aand the pf will return (pf=0, vf=0xffff).
1887*49ef7e06SGarrett D'Amore  */
1888*49ef7e06SGarrett D'Amore 	__checkReturn		efx_rc_t
efx_mcdi_get_function_info(__in efx_nic_t * enp,__out uint32_t * pfp,__out_opt uint32_t * vfp)1889*49ef7e06SGarrett D'Amore efx_mcdi_get_function_info(
1890*49ef7e06SGarrett D'Amore 	__in			efx_nic_t *enp,
1891*49ef7e06SGarrett D'Amore 	__out			uint32_t *pfp,
1892*49ef7e06SGarrett D'Amore 	__out_opt		uint32_t *vfp)
1893*49ef7e06SGarrett D'Amore {
1894*49ef7e06SGarrett D'Amore 	efx_mcdi_req_t req;
1895*49ef7e06SGarrett D'Amore 	uint8_t payload[MAX(MC_CMD_GET_FUNCTION_INFO_IN_LEN,
1896*49ef7e06SGarrett D'Amore 			    MC_CMD_GET_FUNCTION_INFO_OUT_LEN)];
1897*49ef7e06SGarrett D'Amore 	efx_rc_t rc;
1898*49ef7e06SGarrett D'Amore 
1899*49ef7e06SGarrett D'Amore 	(void) memset(payload, 0, sizeof (payload));
1900*49ef7e06SGarrett D'Amore 	req.emr_cmd = MC_CMD_GET_FUNCTION_INFO;
1901*49ef7e06SGarrett D'Amore 	req.emr_in_buf = payload;
1902*49ef7e06SGarrett D'Amore 	req.emr_in_length = MC_CMD_GET_FUNCTION_INFO_IN_LEN;
1903*49ef7e06SGarrett D'Amore 	req.emr_out_buf = payload;
1904*49ef7e06SGarrett D'Amore 	req.emr_out_length = MC_CMD_GET_FUNCTION_INFO_OUT_LEN;
1905*49ef7e06SGarrett D'Amore 
1906*49ef7e06SGarrett D'Amore 	efx_mcdi_execute(enp, &req);
1907*49ef7e06SGarrett D'Amore 
1908*49ef7e06SGarrett D'Amore 	if (req.emr_rc != 0) {
1909*49ef7e06SGarrett D'Amore 		rc = req.emr_rc;
1910*49ef7e06SGarrett D'Amore 		goto fail1;
1911*49ef7e06SGarrett D'Amore 	}
1912*49ef7e06SGarrett D'Amore 
1913*49ef7e06SGarrett D'Amore 	if (req.emr_out_length_used < MC_CMD_GET_FUNCTION_INFO_OUT_LEN) {
1914*49ef7e06SGarrett D'Amore 		rc = EMSGSIZE;
1915*49ef7e06SGarrett D'Amore 		goto fail2;
1916*49ef7e06SGarrett D'Amore 	}
1917*49ef7e06SGarrett D'Amore 
1918*49ef7e06SGarrett D'Amore 	*pfp = MCDI_OUT_DWORD(req, GET_FUNCTION_INFO_OUT_PF);
1919*49ef7e06SGarrett D'Amore 	if (vfp != NULL)
1920*49ef7e06SGarrett D'Amore 		*vfp = MCDI_OUT_DWORD(req, GET_FUNCTION_INFO_OUT_VF);
1921*49ef7e06SGarrett D'Amore 
1922*49ef7e06SGarrett D'Amore 	return (0);
1923*49ef7e06SGarrett D'Amore 
1924*49ef7e06SGarrett D'Amore fail2:
1925*49ef7e06SGarrett D'Amore 	EFSYS_PROBE(fail2);
1926*49ef7e06SGarrett D'Amore fail1:
1927*49ef7e06SGarrett D'Amore 	EFSYS_PROBE1(fail1, efx_rc_t, rc);
1928*49ef7e06SGarrett D'Amore 
1929*49ef7e06SGarrett D'Amore 	return (rc);
1930*49ef7e06SGarrett D'Amore }
1931*49ef7e06SGarrett D'Amore 
1932*49ef7e06SGarrett D'Amore 	__checkReturn		efx_rc_t
efx_mcdi_privilege_mask(__in efx_nic_t * enp,__in uint32_t pf,__in uint32_t vf,__out uint32_t * maskp)1933*49ef7e06SGarrett D'Amore efx_mcdi_privilege_mask(
1934*49ef7e06SGarrett D'Amore 	__in			efx_nic_t *enp,
1935*49ef7e06SGarrett D'Amore 	__in			uint32_t pf,
1936*49ef7e06SGarrett D'Amore 	__in			uint32_t vf,
1937*49ef7e06SGarrett D'Amore 	__out			uint32_t *maskp)
1938*49ef7e06SGarrett D'Amore {
1939*49ef7e06SGarrett D'Amore 	efx_mcdi_req_t req;
1940*49ef7e06SGarrett D'Amore 	uint8_t payload[MAX(MC_CMD_PRIVILEGE_MASK_IN_LEN,
1941*49ef7e06SGarrett D'Amore 			    MC_CMD_PRIVILEGE_MASK_OUT_LEN)];
1942*49ef7e06SGarrett D'Amore 	efx_rc_t rc;
1943*49ef7e06SGarrett D'Amore 
1944*49ef7e06SGarrett D'Amore 	(void) memset(payload, 0, sizeof (payload));
1945*49ef7e06SGarrett D'Amore 	req.emr_cmd = MC_CMD_PRIVILEGE_MASK;
1946*49ef7e06SGarrett D'Amore 	req.emr_in_buf = payload;
1947*49ef7e06SGarrett D'Amore 	req.emr_in_length = MC_CMD_PRIVILEGE_MASK_IN_LEN;
1948*49ef7e06SGarrett D'Amore 	req.emr_out_buf = payload;
1949*49ef7e06SGarrett D'Amore 	req.emr_out_length = MC_CMD_PRIVILEGE_MASK_OUT_LEN;
1950*49ef7e06SGarrett D'Amore 
1951*49ef7e06SGarrett D'Amore 	MCDI_IN_POPULATE_DWORD_2(req, PRIVILEGE_MASK_IN_FUNCTION,
1952*49ef7e06SGarrett D'Amore 	    PRIVILEGE_MASK_IN_FUNCTION_PF, pf,
1953*49ef7e06SGarrett D'Amore 	    PRIVILEGE_MASK_IN_FUNCTION_VF, vf);
1954*49ef7e06SGarrett D'Amore 
1955*49ef7e06SGarrett D'Amore 	efx_mcdi_execute(enp, &req);
1956*49ef7e06SGarrett D'Amore 
1957*49ef7e06SGarrett D'Amore 	if (req.emr_rc != 0) {
1958*49ef7e06SGarrett D'Amore 		rc = req.emr_rc;
1959*49ef7e06SGarrett D'Amore 		goto fail1;
1960*49ef7e06SGarrett D'Amore 	}
1961*49ef7e06SGarrett D'Amore 
1962*49ef7e06SGarrett D'Amore 	if (req.emr_out_length_used < MC_CMD_PRIVILEGE_MASK_OUT_LEN) {
1963*49ef7e06SGarrett D'Amore 		rc = EMSGSIZE;
1964*49ef7e06SGarrett D'Amore 		goto fail2;
1965*49ef7e06SGarrett D'Amore 	}
1966*49ef7e06SGarrett D'Amore 
1967*49ef7e06SGarrett D'Amore 	*maskp = MCDI_OUT_DWORD(req, PRIVILEGE_MASK_OUT_OLD_MASK);
1968*49ef7e06SGarrett D'Amore 
1969*49ef7e06SGarrett D'Amore 	return (0);
1970*49ef7e06SGarrett D'Amore 
1971*49ef7e06SGarrett D'Amore fail2:
1972*49ef7e06SGarrett D'Amore 	EFSYS_PROBE(fail2);
1973*49ef7e06SGarrett D'Amore fail1:
1974*49ef7e06SGarrett D'Amore 	EFSYS_PROBE1(fail1, efx_rc_t, rc);
1975*49ef7e06SGarrett D'Amore 
1976*49ef7e06SGarrett D'Amore 	return (rc);
1977*49ef7e06SGarrett D'Amore }
1978*49ef7e06SGarrett D'Amore 
1979*49ef7e06SGarrett D'Amore #endif /* EFSYS_OPT_HUNTINGTON || EFSYS_OPT_MEDFORD */
1980*49ef7e06SGarrett D'Amore 
1981*49ef7e06SGarrett D'Amore 	__checkReturn		efx_rc_t
efx_mcdi_set_workaround(__in efx_nic_t * enp,__in uint32_t type,__in boolean_t enabled,__out_opt uint32_t * flagsp)1982*49ef7e06SGarrett D'Amore efx_mcdi_set_workaround(
1983*49ef7e06SGarrett D'Amore 	__in			efx_nic_t *enp,
1984*49ef7e06SGarrett D'Amore 	__in			uint32_t type,
1985*49ef7e06SGarrett D'Amore 	__in			boolean_t enabled,
1986*49ef7e06SGarrett D'Amore 	__out_opt		uint32_t *flagsp)
1987*49ef7e06SGarrett D'Amore {
1988*49ef7e06SGarrett D'Amore 	efx_mcdi_req_t req;
1989*49ef7e06SGarrett D'Amore 	uint8_t payload[MAX(MC_CMD_WORKAROUND_IN_LEN,
1990*49ef7e06SGarrett D'Amore 			    MC_CMD_WORKAROUND_EXT_OUT_LEN)];
1991*49ef7e06SGarrett D'Amore 	efx_rc_t rc;
1992*49ef7e06SGarrett D'Amore 
1993*49ef7e06SGarrett D'Amore 	(void) memset(payload, 0, sizeof (payload));
1994*49ef7e06SGarrett D'Amore 	req.emr_cmd = MC_CMD_WORKAROUND;
1995*49ef7e06SGarrett D'Amore 	req.emr_in_buf = payload;
1996*49ef7e06SGarrett D'Amore 	req.emr_in_length = MC_CMD_WORKAROUND_IN_LEN;
1997*49ef7e06SGarrett D'Amore 	req.emr_out_buf = payload;
1998*49ef7e06SGarrett D'Amore 	req.emr_out_length = MC_CMD_WORKAROUND_OUT_LEN;
1999*49ef7e06SGarrett D'Amore 
2000*49ef7e06SGarrett D'Amore 	MCDI_IN_SET_DWORD(req, WORKAROUND_IN_TYPE, type);
2001*49ef7e06SGarrett D'Amore 	MCDI_IN_SET_DWORD(req, WORKAROUND_IN_ENABLED, enabled ? 1 : 0);
2002*49ef7e06SGarrett D'Amore 
2003*49ef7e06SGarrett D'Amore 	efx_mcdi_execute_quiet(enp, &req);
2004*49ef7e06SGarrett D'Amore 
2005*49ef7e06SGarrett D'Amore 	if (req.emr_rc != 0) {
2006*49ef7e06SGarrett D'Amore 		rc = req.emr_rc;
2007*49ef7e06SGarrett D'Amore 		goto fail1;
2008*49ef7e06SGarrett D'Amore 	}
2009*49ef7e06SGarrett D'Amore 
2010*49ef7e06SGarrett D'Amore 	if (flagsp != NULL) {
2011*49ef7e06SGarrett D'Amore 		if (req.emr_out_length_used >= MC_CMD_WORKAROUND_EXT_OUT_LEN)
2012*49ef7e06SGarrett D'Amore 			*flagsp = MCDI_OUT_DWORD(req, WORKAROUND_EXT_OUT_FLAGS);
2013*49ef7e06SGarrett D'Amore 		else
2014*49ef7e06SGarrett D'Amore 			*flagsp = 0;
2015*49ef7e06SGarrett D'Amore 	}
2016*49ef7e06SGarrett D'Amore 
2017*49ef7e06SGarrett D'Amore 	return (0);
2018*49ef7e06SGarrett D'Amore 
2019*49ef7e06SGarrett D'Amore fail1:
2020*49ef7e06SGarrett D'Amore 	EFSYS_PROBE1(fail1, efx_rc_t, rc);
2021*49ef7e06SGarrett D'Amore 
2022*49ef7e06SGarrett D'Amore 	return (rc);
2023*49ef7e06SGarrett D'Amore }
2024*49ef7e06SGarrett D'Amore 
2025*49ef7e06SGarrett D'Amore 
2026*49ef7e06SGarrett D'Amore 	__checkReturn		efx_rc_t
efx_mcdi_get_workarounds(__in efx_nic_t * enp,__out_opt uint32_t * implementedp,__out_opt uint32_t * enabledp)2027*49ef7e06SGarrett D'Amore efx_mcdi_get_workarounds(
2028*49ef7e06SGarrett D'Amore 	__in			efx_nic_t *enp,
2029*49ef7e06SGarrett D'Amore 	__out_opt		uint32_t *implementedp,
2030*49ef7e06SGarrett D'Amore 	__out_opt		uint32_t *enabledp)
2031*49ef7e06SGarrett D'Amore {
2032*49ef7e06SGarrett D'Amore 	efx_mcdi_req_t req;
2033*49ef7e06SGarrett D'Amore 	uint8_t payload[MC_CMD_GET_WORKAROUNDS_OUT_LEN];
2034*49ef7e06SGarrett D'Amore 	efx_rc_t rc;
2035*49ef7e06SGarrett D'Amore 
2036*49ef7e06SGarrett D'Amore 	(void) memset(payload, 0, sizeof (payload));
2037*49ef7e06SGarrett D'Amore 	req.emr_cmd = MC_CMD_GET_WORKAROUNDS;
2038*49ef7e06SGarrett D'Amore 	req.emr_in_buf = NULL;
2039*49ef7e06SGarrett D'Amore 	req.emr_in_length = 0;
2040*49ef7e06SGarrett D'Amore 	req.emr_out_buf = payload;
2041*49ef7e06SGarrett D'Amore 	req.emr_out_length = MC_CMD_GET_WORKAROUNDS_OUT_LEN;
2042*49ef7e06SGarrett D'Amore 
2043*49ef7e06SGarrett D'Amore 	efx_mcdi_execute(enp, &req);
2044*49ef7e06SGarrett D'Amore 
2045*49ef7e06SGarrett D'Amore 	if (req.emr_rc != 0) {
2046*49ef7e06SGarrett D'Amore 		rc = req.emr_rc;
2047*49ef7e06SGarrett D'Amore 		goto fail1;
2048*49ef7e06SGarrett D'Amore 	}
2049*49ef7e06SGarrett D'Amore 
2050*49ef7e06SGarrett D'Amore 	if (implementedp != NULL) {
2051*49ef7e06SGarrett D'Amore 		*implementedp =
2052*49ef7e06SGarrett D'Amore 		    MCDI_OUT_DWORD(req, GET_WORKAROUNDS_OUT_IMPLEMENTED);
2053*49ef7e06SGarrett D'Amore 	}
2054*49ef7e06SGarrett D'Amore 
2055*49ef7e06SGarrett D'Amore 	if (enabledp != NULL) {
2056*49ef7e06SGarrett D'Amore 		*enabledp = MCDI_OUT_DWORD(req, GET_WORKAROUNDS_OUT_ENABLED);
2057*49ef7e06SGarrett D'Amore 	}
2058*49ef7e06SGarrett D'Amore 
2059*49ef7e06SGarrett D'Amore 	return (0);
2060*49ef7e06SGarrett D'Amore 
2061*49ef7e06SGarrett D'Amore fail1:
2062*49ef7e06SGarrett D'Amore 	EFSYS_PROBE1(fail1, efx_rc_t, rc);
2063*49ef7e06SGarrett D'Amore 
2064*49ef7e06SGarrett D'Amore 	return (rc);
2065*49ef7e06SGarrett D'Amore }
2066*49ef7e06SGarrett D'Amore 
2067*49ef7e06SGarrett D'Amore /*
2068*49ef7e06SGarrett D'Amore  * Size of media information page in accordance with SFF-8472 and SFF-8436.
2069*49ef7e06SGarrett D'Amore  * It is used in MCDI interface as well.
2070*49ef7e06SGarrett D'Amore  */
2071*49ef7e06SGarrett D'Amore #define	EFX_PHY_MEDIA_INFO_PAGE_SIZE		0x80
2072*49ef7e06SGarrett D'Amore 
2073*49ef7e06SGarrett D'Amore static	__checkReturn		efx_rc_t
efx_mcdi_get_phy_media_info(__in efx_nic_t * enp,__in uint32_t mcdi_page,__in uint8_t offset,__in uint8_t len,__out_bcount (len)uint8_t * data)2074*49ef7e06SGarrett D'Amore efx_mcdi_get_phy_media_info(
2075*49ef7e06SGarrett D'Amore 	__in			efx_nic_t *enp,
2076*49ef7e06SGarrett D'Amore 	__in			uint32_t mcdi_page,
2077*49ef7e06SGarrett D'Amore 	__in			uint8_t offset,
2078*49ef7e06SGarrett D'Amore 	__in			uint8_t len,
2079*49ef7e06SGarrett D'Amore 	__out_bcount(len)	uint8_t *data)
2080*49ef7e06SGarrett D'Amore {
2081*49ef7e06SGarrett D'Amore 	efx_mcdi_req_t req;
2082*49ef7e06SGarrett D'Amore 	uint8_t payload[MAX(MC_CMD_GET_PHY_MEDIA_INFO_IN_LEN,
2083*49ef7e06SGarrett D'Amore 			    MC_CMD_GET_PHY_MEDIA_INFO_OUT_LEN(
2084*49ef7e06SGarrett D'Amore 				EFX_PHY_MEDIA_INFO_PAGE_SIZE))];
2085*49ef7e06SGarrett D'Amore 	efx_rc_t rc;
2086*49ef7e06SGarrett D'Amore 
2087*49ef7e06SGarrett D'Amore 	EFSYS_ASSERT((uint32_t)offset + len <= EFX_PHY_MEDIA_INFO_PAGE_SIZE);
2088*49ef7e06SGarrett D'Amore 
2089*49ef7e06SGarrett D'Amore 	(void) memset(payload, 0, sizeof (payload));
2090*49ef7e06SGarrett D'Amore 	req.emr_cmd = MC_CMD_GET_PHY_MEDIA_INFO;
2091*49ef7e06SGarrett D'Amore 	req.emr_in_buf = payload;
2092*49ef7e06SGarrett D'Amore 	req.emr_in_length = MC_CMD_GET_PHY_MEDIA_INFO_IN_LEN;
2093*49ef7e06SGarrett D'Amore 	req.emr_out_buf = payload;
2094*49ef7e06SGarrett D'Amore 	req.emr_out_length =
2095*49ef7e06SGarrett D'Amore 	    MC_CMD_GET_PHY_MEDIA_INFO_OUT_LEN(EFX_PHY_MEDIA_INFO_PAGE_SIZE);
2096*49ef7e06SGarrett D'Amore 
2097*49ef7e06SGarrett D'Amore 	MCDI_IN_SET_DWORD(req, GET_PHY_MEDIA_INFO_IN_PAGE, mcdi_page);
2098*49ef7e06SGarrett D'Amore 
2099*49ef7e06SGarrett D'Amore 	efx_mcdi_execute(enp, &req);
2100*49ef7e06SGarrett D'Amore 
2101*49ef7e06SGarrett D'Amore 	if (req.emr_rc != 0) {
2102*49ef7e06SGarrett D'Amore 		rc = req.emr_rc;
2103*49ef7e06SGarrett D'Amore 		goto fail1;
2104*49ef7e06SGarrett D'Amore 	}
2105*49ef7e06SGarrett D'Amore 
2106*49ef7e06SGarrett D'Amore 	if (req.emr_out_length_used !=
2107*49ef7e06SGarrett D'Amore 	    MC_CMD_GET_PHY_MEDIA_INFO_OUT_LEN(EFX_PHY_MEDIA_INFO_PAGE_SIZE)) {
2108*49ef7e06SGarrett D'Amore 		rc = EMSGSIZE;
2109*49ef7e06SGarrett D'Amore 		goto fail2;
2110*49ef7e06SGarrett D'Amore 	}
2111*49ef7e06SGarrett D'Amore 
2112*49ef7e06SGarrett D'Amore 	if (MCDI_OUT_DWORD(req, GET_PHY_MEDIA_INFO_OUT_DATALEN) !=
2113*49ef7e06SGarrett D'Amore 	    EFX_PHY_MEDIA_INFO_PAGE_SIZE) {
2114*49ef7e06SGarrett D'Amore 		rc = EIO;
2115*49ef7e06SGarrett D'Amore 		goto fail3;
2116*49ef7e06SGarrett D'Amore 	}
2117*49ef7e06SGarrett D'Amore 
2118*49ef7e06SGarrett D'Amore 	(void) memcpy(data,
2119*49ef7e06SGarrett D'Amore 	    MCDI_OUT2(req, uint8_t, GET_PHY_MEDIA_INFO_OUT_DATA) + offset,
2120*49ef7e06SGarrett D'Amore 	    len);
2121*49ef7e06SGarrett D'Amore 
2122*49ef7e06SGarrett D'Amore 	return (0);
2123*49ef7e06SGarrett D'Amore 
2124*49ef7e06SGarrett D'Amore fail3:
2125*49ef7e06SGarrett D'Amore 	EFSYS_PROBE(fail3);
2126*49ef7e06SGarrett D'Amore fail2:
2127*49ef7e06SGarrett D'Amore 	EFSYS_PROBE(fail2);
2128*49ef7e06SGarrett D'Amore fail1:
2129*49ef7e06SGarrett D'Amore 	EFSYS_PROBE1(fail1, efx_rc_t, rc);
2130*49ef7e06SGarrett D'Amore 
2131*49ef7e06SGarrett D'Amore 	return (rc);
2132*49ef7e06SGarrett D'Amore }
2133*49ef7e06SGarrett D'Amore 
2134*49ef7e06SGarrett D'Amore /*
2135*49ef7e06SGarrett D'Amore  * 2-wire device address of the base information in accordance with SFF-8472
2136*49ef7e06SGarrett D'Amore  * Diagnostic Monitoring Interface for Optical Transceivers section
2137*49ef7e06SGarrett D'Amore  * 4 Memory Organization.
2138*49ef7e06SGarrett D'Amore  */
2139*49ef7e06SGarrett D'Amore #define	EFX_PHY_MEDIA_INFO_DEV_ADDR_SFP_BASE	0xA0
2140*49ef7e06SGarrett D'Amore 
2141*49ef7e06SGarrett D'Amore /*
2142*49ef7e06SGarrett D'Amore  * 2-wire device address of the digital diagnostics monitoring interface
2143*49ef7e06SGarrett D'Amore  * in accordance with SFF-8472 Diagnostic Monitoring Interface for Optical
2144*49ef7e06SGarrett D'Amore  * Transceivers section 4 Memory Organization.
2145*49ef7e06SGarrett D'Amore  */
2146*49ef7e06SGarrett D'Amore #define	EFX_PHY_MEDIA_INFO_DEV_ADDR_SFP_DDM	0xA2
2147*49ef7e06SGarrett D'Amore 
2148*49ef7e06SGarrett D'Amore /*
2149*49ef7e06SGarrett D'Amore  * Hard wired 2-wire device address for QSFP+ in accordance with SFF-8436
2150*49ef7e06SGarrett D'Amore  * QSFP+ 10 Gbs 4X PLUGGABLE TRANSCEIVER section 7.4 Device Addressing and
2151*49ef7e06SGarrett D'Amore  * Operation.
2152*49ef7e06SGarrett D'Amore  */
2153*49ef7e06SGarrett D'Amore #define	EFX_PHY_MEDIA_INFO_DEV_ADDR_QSFP	0xA0
2154*49ef7e06SGarrett D'Amore 
2155*49ef7e06SGarrett D'Amore 	__checkReturn		efx_rc_t
efx_mcdi_phy_module_get_info(__in efx_nic_t * enp,__in uint8_t dev_addr,__in uint8_t offset,__in uint8_t len,__out_bcount (len)uint8_t * data)2156*49ef7e06SGarrett D'Amore efx_mcdi_phy_module_get_info(
2157*49ef7e06SGarrett D'Amore 	__in			efx_nic_t *enp,
2158*49ef7e06SGarrett D'Amore 	__in			uint8_t dev_addr,
2159*49ef7e06SGarrett D'Amore 	__in			uint8_t offset,
2160*49ef7e06SGarrett D'Amore 	__in			uint8_t len,
2161*49ef7e06SGarrett D'Amore 	__out_bcount(len)	uint8_t *data)
2162*49ef7e06SGarrett D'Amore {
2163*49ef7e06SGarrett D'Amore 	efx_port_t *epp = &(enp->en_port);
2164*49ef7e06SGarrett D'Amore 	efx_rc_t rc;
2165*49ef7e06SGarrett D'Amore 	uint32_t mcdi_lower_page;
2166*49ef7e06SGarrett D'Amore 	uint32_t mcdi_upper_page;
2167*49ef7e06SGarrett D'Amore 
2168*49ef7e06SGarrett D'Amore 	EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_PROBE);
2169*49ef7e06SGarrett D'Amore 
2170*49ef7e06SGarrett D'Amore 	/*
2171*49ef7e06SGarrett D'Amore 	 * Map device address to MC_CMD_GET_PHY_MEDIA_INFO pages.
2172*49ef7e06SGarrett D'Amore 	 * Offset plus length interface allows to access page 0 only.
2173*49ef7e06SGarrett D'Amore 	 * I.e. non-zero upper pages are not accessible.
2174*49ef7e06SGarrett D'Amore 	 * See SFF-8472 section 4 Memory Organization and SFF-8436 section 7.6
2175*49ef7e06SGarrett D'Amore 	 * QSFP+ Memory Map for details on how information is structured
2176*49ef7e06SGarrett D'Amore 	 * and accessible.
2177*49ef7e06SGarrett D'Amore 	 */
2178*49ef7e06SGarrett D'Amore 	switch (epp->ep_fixed_port_type) {
2179*49ef7e06SGarrett D'Amore 	case EFX_PHY_MEDIA_SFP_PLUS:
2180*49ef7e06SGarrett D'Amore 		/*
2181*49ef7e06SGarrett D'Amore 		 * In accordance with SFF-8472 Diagnostic Monitoring
2182*49ef7e06SGarrett D'Amore 		 * Interface for Optical Transceivers section 4 Memory
2183*49ef7e06SGarrett D'Amore 		 * Organization two 2-wire addresses are defined.
2184*49ef7e06SGarrett D'Amore 		 */
2185*49ef7e06SGarrett D'Amore 		switch (dev_addr) {
2186*49ef7e06SGarrett D'Amore 		/* Base information */
2187*49ef7e06SGarrett D'Amore 		case EFX_PHY_MEDIA_INFO_DEV_ADDR_SFP_BASE:
2188*49ef7e06SGarrett D'Amore 			/*
2189*49ef7e06SGarrett D'Amore 			 * MCDI page 0 should be used to access lower
2190*49ef7e06SGarrett D'Amore 			 * page 0 (0x00 - 0x7f) at the device address 0xA0.
2191*49ef7e06SGarrett D'Amore 			 */
2192*49ef7e06SGarrett D'Amore 			mcdi_lower_page = 0;
2193*49ef7e06SGarrett D'Amore 			/*
2194*49ef7e06SGarrett D'Amore 			 * MCDI page 1 should be used to access  upper
2195*49ef7e06SGarrett D'Amore 			 * page 0 (0x80 - 0xff) at the device address 0xA0.
2196*49ef7e06SGarrett D'Amore 			 */
2197*49ef7e06SGarrett D'Amore 			mcdi_upper_page = 1;
2198*49ef7e06SGarrett D'Amore 			break;
2199*49ef7e06SGarrett D'Amore 		/* Diagnostics */
2200*49ef7e06SGarrett D'Amore 		case EFX_PHY_MEDIA_INFO_DEV_ADDR_SFP_DDM:
2201*49ef7e06SGarrett D'Amore 			/*
2202*49ef7e06SGarrett D'Amore 			 * MCDI page 2 should be used to access lower
2203*49ef7e06SGarrett D'Amore 			 * page 0 (0x00 - 0x7f) at the device address 0xA2.
2204*49ef7e06SGarrett D'Amore 			 */
2205*49ef7e06SGarrett D'Amore 			mcdi_lower_page = 2;
2206*49ef7e06SGarrett D'Amore 			/*
2207*49ef7e06SGarrett D'Amore 			 * MCDI page 3 should be used to access upper
2208*49ef7e06SGarrett D'Amore 			 * page 0 (0x80 - 0xff) at the device address 0xA2.
2209*49ef7e06SGarrett D'Amore 			 */
2210*49ef7e06SGarrett D'Amore 			mcdi_upper_page = 3;
2211*49ef7e06SGarrett D'Amore 			break;
2212*49ef7e06SGarrett D'Amore 		default:
2213*49ef7e06SGarrett D'Amore 			rc = ENOTSUP;
2214*49ef7e06SGarrett D'Amore 			goto fail1;
2215*49ef7e06SGarrett D'Amore 		}
2216*49ef7e06SGarrett D'Amore 		break;
2217*49ef7e06SGarrett D'Amore 	case EFX_PHY_MEDIA_QSFP_PLUS:
2218*49ef7e06SGarrett D'Amore 		switch (dev_addr) {
2219*49ef7e06SGarrett D'Amore 		case EFX_PHY_MEDIA_INFO_DEV_ADDR_QSFP:
2220*49ef7e06SGarrett D'Amore 			/*
2221*49ef7e06SGarrett D'Amore 			 * MCDI page -1 should be used to access lower page 0
2222*49ef7e06SGarrett D'Amore 			 * (0x00 - 0x7f).
2223*49ef7e06SGarrett D'Amore 			 */
2224*49ef7e06SGarrett D'Amore 			mcdi_lower_page = (uint32_t)-1;
2225*49ef7e06SGarrett D'Amore 			/*
2226*49ef7e06SGarrett D'Amore 			 * MCDI page 0 should be used to access upper page 0
2227*49ef7e06SGarrett D'Amore 			 * (0x80h - 0xff).
2228*49ef7e06SGarrett D'Amore 			 */
2229*49ef7e06SGarrett D'Amore 			mcdi_upper_page = 0;
2230*49ef7e06SGarrett D'Amore 			break;
2231*49ef7e06SGarrett D'Amore 		default:
2232*49ef7e06SGarrett D'Amore 			rc = ENOTSUP;
2233*49ef7e06SGarrett D'Amore 			goto fail1;
2234*49ef7e06SGarrett D'Amore 		}
2235*49ef7e06SGarrett D'Amore 		break;
2236*49ef7e06SGarrett D'Amore 	default:
2237*49ef7e06SGarrett D'Amore 		rc = ENOTSUP;
2238*49ef7e06SGarrett D'Amore 		goto fail1;
2239*49ef7e06SGarrett D'Amore 	}
2240*49ef7e06SGarrett D'Amore 
2241*49ef7e06SGarrett D'Amore 	if (offset < EFX_PHY_MEDIA_INFO_PAGE_SIZE) {
2242*49ef7e06SGarrett D'Amore 		uint8_t read_len =
2243*49ef7e06SGarrett D'Amore 		    MIN(len, EFX_PHY_MEDIA_INFO_PAGE_SIZE - offset);
2244*49ef7e06SGarrett D'Amore 
2245*49ef7e06SGarrett D'Amore 		rc = efx_mcdi_get_phy_media_info(enp,
2246*49ef7e06SGarrett D'Amore 		    mcdi_lower_page, offset, read_len, data);
2247*49ef7e06SGarrett D'Amore 		if (rc != 0)
2248*49ef7e06SGarrett D'Amore 			goto fail2;
2249*49ef7e06SGarrett D'Amore 
2250*49ef7e06SGarrett D'Amore 		data += read_len;
2251*49ef7e06SGarrett D'Amore 		len -= read_len;
2252*49ef7e06SGarrett D'Amore 
2253*49ef7e06SGarrett D'Amore 		offset = 0;
2254*49ef7e06SGarrett D'Amore 	} else {
2255*49ef7e06SGarrett D'Amore 		offset -= EFX_PHY_MEDIA_INFO_PAGE_SIZE;
2256*49ef7e06SGarrett D'Amore 	}
2257*49ef7e06SGarrett D'Amore 
2258*49ef7e06SGarrett D'Amore 	if (len > 0) {
2259*49ef7e06SGarrett D'Amore 		EFSYS_ASSERT3U(len, <=, EFX_PHY_MEDIA_INFO_PAGE_SIZE);
2260*49ef7e06SGarrett D'Amore 		EFSYS_ASSERT3U(offset, <, EFX_PHY_MEDIA_INFO_PAGE_SIZE);
2261*49ef7e06SGarrett D'Amore 
2262*49ef7e06SGarrett D'Amore 		rc = efx_mcdi_get_phy_media_info(enp,
2263*49ef7e06SGarrett D'Amore 		    mcdi_upper_page, offset, len, data);
2264*49ef7e06SGarrett D'Amore 		if (rc != 0)
2265*49ef7e06SGarrett D'Amore 			goto fail3;
2266*49ef7e06SGarrett D'Amore 	}
2267*49ef7e06SGarrett D'Amore 
2268*49ef7e06SGarrett D'Amore 	return (0);
2269*49ef7e06SGarrett D'Amore 
2270*49ef7e06SGarrett D'Amore fail3:
2271*49ef7e06SGarrett D'Amore 	EFSYS_PROBE(fail3);
2272*49ef7e06SGarrett D'Amore fail2:
2273*49ef7e06SGarrett D'Amore 	EFSYS_PROBE(fail2);
2274*49ef7e06SGarrett D'Amore fail1:
2275*49ef7e06SGarrett D'Amore 	EFSYS_PROBE1(fail1, efx_rc_t, rc);
2276*49ef7e06SGarrett D'Amore 
2277*49ef7e06SGarrett D'Amore 	return (rc);
2278*49ef7e06SGarrett D'Amore }
2279*49ef7e06SGarrett D'Amore 
2280*49ef7e06SGarrett D'Amore #endif	/* EFSYS_OPT_MCDI */
2281