1*49ef7e06SGarrett D'Amore /*
2*49ef7e06SGarrett D'Amore  * Copyright (c) 2012-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_HUNTINGTON || EFSYS_OPT_MEDFORD
35*49ef7e06SGarrett D'Amore 
36*49ef7e06SGarrett D'Amore static			void
mcdi_phy_decode_cap(__in uint32_t mcdi_cap,__out uint32_t * maskp)37*49ef7e06SGarrett D'Amore mcdi_phy_decode_cap(
38*49ef7e06SGarrett D'Amore 	__in		uint32_t mcdi_cap,
39*49ef7e06SGarrett D'Amore 	__out		uint32_t *maskp)
40*49ef7e06SGarrett D'Amore {
41*49ef7e06SGarrett D'Amore 	uint32_t mask;
42*49ef7e06SGarrett D'Amore 
43*49ef7e06SGarrett D'Amore 	mask = 0;
44*49ef7e06SGarrett D'Amore 	if (mcdi_cap & (1 << MC_CMD_PHY_CAP_10HDX_LBN))
45*49ef7e06SGarrett D'Amore 		mask |= (1 << EFX_PHY_CAP_10HDX);
46*49ef7e06SGarrett D'Amore 	if (mcdi_cap & (1 << MC_CMD_PHY_CAP_10FDX_LBN))
47*49ef7e06SGarrett D'Amore 		mask |= (1 << EFX_PHY_CAP_10FDX);
48*49ef7e06SGarrett D'Amore 	if (mcdi_cap & (1 << MC_CMD_PHY_CAP_100HDX_LBN))
49*49ef7e06SGarrett D'Amore 		mask |= (1 << EFX_PHY_CAP_100HDX);
50*49ef7e06SGarrett D'Amore 	if (mcdi_cap & (1 << MC_CMD_PHY_CAP_100FDX_LBN))
51*49ef7e06SGarrett D'Amore 		mask |= (1 << EFX_PHY_CAP_100FDX);
52*49ef7e06SGarrett D'Amore 	if (mcdi_cap & (1 << MC_CMD_PHY_CAP_1000HDX_LBN))
53*49ef7e06SGarrett D'Amore 		mask |= (1 << EFX_PHY_CAP_1000HDX);
54*49ef7e06SGarrett D'Amore 	if (mcdi_cap & (1 << MC_CMD_PHY_CAP_1000FDX_LBN))
55*49ef7e06SGarrett D'Amore 		mask |= (1 << EFX_PHY_CAP_1000FDX);
56*49ef7e06SGarrett D'Amore 	if (mcdi_cap & (1 << MC_CMD_PHY_CAP_10000FDX_LBN))
57*49ef7e06SGarrett D'Amore 		mask |= (1 << EFX_PHY_CAP_10000FDX);
58*49ef7e06SGarrett D'Amore 	if (mcdi_cap & (1 << MC_CMD_PHY_CAP_40000FDX_LBN))
59*49ef7e06SGarrett D'Amore 		mask |= (1 << EFX_PHY_CAP_40000FDX);
60*49ef7e06SGarrett D'Amore 	if (mcdi_cap & (1 << MC_CMD_PHY_CAP_PAUSE_LBN))
61*49ef7e06SGarrett D'Amore 		mask |= (1 << EFX_PHY_CAP_PAUSE);
62*49ef7e06SGarrett D'Amore 	if (mcdi_cap & (1 << MC_CMD_PHY_CAP_ASYM_LBN))
63*49ef7e06SGarrett D'Amore 		mask |= (1 << EFX_PHY_CAP_ASYM);
64*49ef7e06SGarrett D'Amore 	if (mcdi_cap & (1 << MC_CMD_PHY_CAP_AN_LBN))
65*49ef7e06SGarrett D'Amore 		mask |= (1 << EFX_PHY_CAP_AN);
66*49ef7e06SGarrett D'Amore 
67*49ef7e06SGarrett D'Amore 	*maskp = mask;
68*49ef7e06SGarrett D'Amore }
69*49ef7e06SGarrett D'Amore 
70*49ef7e06SGarrett D'Amore static			void
mcdi_phy_decode_link_mode(__in efx_nic_t * enp,__in uint32_t link_flags,__in unsigned int speed,__in unsigned int fcntl,__out efx_link_mode_t * link_modep,__out unsigned int * fcntlp)71*49ef7e06SGarrett D'Amore mcdi_phy_decode_link_mode(
72*49ef7e06SGarrett D'Amore 	__in		efx_nic_t *enp,
73*49ef7e06SGarrett D'Amore 	__in		uint32_t link_flags,
74*49ef7e06SGarrett D'Amore 	__in		unsigned int speed,
75*49ef7e06SGarrett D'Amore 	__in		unsigned int fcntl,
76*49ef7e06SGarrett D'Amore 	__out		efx_link_mode_t *link_modep,
77*49ef7e06SGarrett D'Amore 	__out		unsigned int *fcntlp)
78*49ef7e06SGarrett D'Amore {
79*49ef7e06SGarrett D'Amore 	boolean_t fd = !!(link_flags &
80*49ef7e06SGarrett D'Amore 		    (1 << MC_CMD_GET_LINK_OUT_FULL_DUPLEX_LBN));
81*49ef7e06SGarrett D'Amore 	boolean_t up = !!(link_flags &
82*49ef7e06SGarrett D'Amore 		    (1 << MC_CMD_GET_LINK_OUT_LINK_UP_LBN));
83*49ef7e06SGarrett D'Amore 
84*49ef7e06SGarrett D'Amore 	_NOTE(ARGUNUSED(enp))
85*49ef7e06SGarrett D'Amore 
86*49ef7e06SGarrett D'Amore 	if (!up)
87*49ef7e06SGarrett D'Amore 		*link_modep = EFX_LINK_DOWN;
88*49ef7e06SGarrett D'Amore 	else if (speed == 40000 && fd)
89*49ef7e06SGarrett D'Amore 		*link_modep = EFX_LINK_40000FDX;
90*49ef7e06SGarrett D'Amore 	else if (speed == 10000 && fd)
91*49ef7e06SGarrett D'Amore 		*link_modep = EFX_LINK_10000FDX;
92*49ef7e06SGarrett D'Amore 	else if (speed == 1000)
93*49ef7e06SGarrett D'Amore 		*link_modep = fd ? EFX_LINK_1000FDX : EFX_LINK_1000HDX;
94*49ef7e06SGarrett D'Amore 	else if (speed == 100)
95*49ef7e06SGarrett D'Amore 		*link_modep = fd ? EFX_LINK_100FDX : EFX_LINK_100HDX;
96*49ef7e06SGarrett D'Amore 	else if (speed == 10)
97*49ef7e06SGarrett D'Amore 		*link_modep = fd ? EFX_LINK_10FDX : EFX_LINK_10HDX;
98*49ef7e06SGarrett D'Amore 	else
99*49ef7e06SGarrett D'Amore 		*link_modep = EFX_LINK_UNKNOWN;
100*49ef7e06SGarrett D'Amore 
101*49ef7e06SGarrett D'Amore 	if (fcntl == MC_CMD_FCNTL_OFF)
102*49ef7e06SGarrett D'Amore 		*fcntlp = 0;
103*49ef7e06SGarrett D'Amore 	else if (fcntl == MC_CMD_FCNTL_RESPOND)
104*49ef7e06SGarrett D'Amore 		*fcntlp = EFX_FCNTL_RESPOND;
105*49ef7e06SGarrett D'Amore 	else if (fcntl == MC_CMD_FCNTL_GENERATE)
106*49ef7e06SGarrett D'Amore 		*fcntlp = EFX_FCNTL_GENERATE;
107*49ef7e06SGarrett D'Amore 	else if (fcntl == MC_CMD_FCNTL_BIDIR)
108*49ef7e06SGarrett D'Amore 		*fcntlp = EFX_FCNTL_RESPOND | EFX_FCNTL_GENERATE;
109*49ef7e06SGarrett D'Amore 	else {
110*49ef7e06SGarrett D'Amore 		EFSYS_PROBE1(mc_pcol_error, int, fcntl);
111*49ef7e06SGarrett D'Amore 		*fcntlp = 0;
112*49ef7e06SGarrett D'Amore 	}
113*49ef7e06SGarrett D'Amore }
114*49ef7e06SGarrett D'Amore 
115*49ef7e06SGarrett D'Amore 
116*49ef7e06SGarrett D'Amore 			void
ef10_phy_link_ev(__in efx_nic_t * enp,__in efx_qword_t * eqp,__out efx_link_mode_t * link_modep)117*49ef7e06SGarrett D'Amore ef10_phy_link_ev(
118*49ef7e06SGarrett D'Amore 	__in		efx_nic_t *enp,
119*49ef7e06SGarrett D'Amore 	__in		efx_qword_t *eqp,
120*49ef7e06SGarrett D'Amore 	__out		efx_link_mode_t *link_modep)
121*49ef7e06SGarrett D'Amore {
122*49ef7e06SGarrett D'Amore 	efx_port_t *epp = &(enp->en_port);
123*49ef7e06SGarrett D'Amore 	unsigned int link_flags;
124*49ef7e06SGarrett D'Amore 	unsigned int speed;
125*49ef7e06SGarrett D'Amore 	unsigned int fcntl;
126*49ef7e06SGarrett D'Amore 	efx_link_mode_t link_mode;
127*49ef7e06SGarrett D'Amore 	uint32_t lp_cap_mask;
128*49ef7e06SGarrett D'Amore 
129*49ef7e06SGarrett D'Amore 	/*
130*49ef7e06SGarrett D'Amore 	 * Convert the LINKCHANGE speed enumeration into mbit/s, in the
131*49ef7e06SGarrett D'Amore 	 * same way as GET_LINK encodes the speed
132*49ef7e06SGarrett D'Amore 	 */
133*49ef7e06SGarrett D'Amore 	switch (MCDI_EV_FIELD(eqp, LINKCHANGE_SPEED)) {
134*49ef7e06SGarrett D'Amore 	case MCDI_EVENT_LINKCHANGE_SPEED_100M:
135*49ef7e06SGarrett D'Amore 		speed = 100;
136*49ef7e06SGarrett D'Amore 		break;
137*49ef7e06SGarrett D'Amore 	case MCDI_EVENT_LINKCHANGE_SPEED_1G:
138*49ef7e06SGarrett D'Amore 		speed = 1000;
139*49ef7e06SGarrett D'Amore 		break;
140*49ef7e06SGarrett D'Amore 	case MCDI_EVENT_LINKCHANGE_SPEED_10G:
141*49ef7e06SGarrett D'Amore 		speed = 10000;
142*49ef7e06SGarrett D'Amore 		break;
143*49ef7e06SGarrett D'Amore 	case MCDI_EVENT_LINKCHANGE_SPEED_40G:
144*49ef7e06SGarrett D'Amore 		speed = 40000;
145*49ef7e06SGarrett D'Amore 		break;
146*49ef7e06SGarrett D'Amore 	default:
147*49ef7e06SGarrett D'Amore 		speed = 0;
148*49ef7e06SGarrett D'Amore 		break;
149*49ef7e06SGarrett D'Amore 	}
150*49ef7e06SGarrett D'Amore 
151*49ef7e06SGarrett D'Amore 	link_flags = MCDI_EV_FIELD(eqp, LINKCHANGE_LINK_FLAGS);
152*49ef7e06SGarrett D'Amore 	mcdi_phy_decode_link_mode(enp, link_flags, speed,
153*49ef7e06SGarrett D'Amore 				    MCDI_EV_FIELD(eqp, LINKCHANGE_FCNTL),
154*49ef7e06SGarrett D'Amore 				    &link_mode, &fcntl);
155*49ef7e06SGarrett D'Amore 	mcdi_phy_decode_cap(MCDI_EV_FIELD(eqp, LINKCHANGE_LP_CAP),
156*49ef7e06SGarrett D'Amore 			    &lp_cap_mask);
157*49ef7e06SGarrett D'Amore 
158*49ef7e06SGarrett D'Amore 	/*
159*49ef7e06SGarrett D'Amore 	 * It's safe to update ep_lp_cap_mask without the driver's port lock
160*49ef7e06SGarrett D'Amore 	 * because presumably any concurrently running efx_port_poll() is
161*49ef7e06SGarrett D'Amore 	 * only going to arrive at the same value.
162*49ef7e06SGarrett D'Amore 	 *
163*49ef7e06SGarrett D'Amore 	 * ep_fcntl has two meanings. It's either the link common fcntl
164*49ef7e06SGarrett D'Amore 	 * (if the PHY supports AN), or it's the forced link state. If
165*49ef7e06SGarrett D'Amore 	 * the former, it's safe to update the value for the same reason as
166*49ef7e06SGarrett D'Amore 	 * for ep_lp_cap_mask. If the latter, then just ignore the value,
167*49ef7e06SGarrett D'Amore 	 * because we can race with efx_mac_fcntl_set().
168*49ef7e06SGarrett D'Amore 	 */
169*49ef7e06SGarrett D'Amore 	epp->ep_lp_cap_mask = lp_cap_mask;
170*49ef7e06SGarrett D'Amore 	epp->ep_fcntl = fcntl;
171*49ef7e06SGarrett D'Amore 
172*49ef7e06SGarrett D'Amore 	*link_modep = link_mode;
173*49ef7e06SGarrett D'Amore }
174*49ef7e06SGarrett D'Amore 
175*49ef7e06SGarrett D'Amore 	__checkReturn	efx_rc_t
ef10_phy_power(__in efx_nic_t * enp,__in boolean_t power)176*49ef7e06SGarrett D'Amore ef10_phy_power(
177*49ef7e06SGarrett D'Amore 	__in		efx_nic_t *enp,
178*49ef7e06SGarrett D'Amore 	__in		boolean_t power)
179*49ef7e06SGarrett D'Amore {
180*49ef7e06SGarrett D'Amore 	efx_rc_t rc;
181*49ef7e06SGarrett D'Amore 
182*49ef7e06SGarrett D'Amore 	if (!power)
183*49ef7e06SGarrett D'Amore 		return (0);
184*49ef7e06SGarrett D'Amore 
185*49ef7e06SGarrett D'Amore 	/* Check if the PHY is a zombie */
186*49ef7e06SGarrett D'Amore 	if ((rc = ef10_phy_verify(enp)) != 0)
187*49ef7e06SGarrett D'Amore 		goto fail1;
188*49ef7e06SGarrett D'Amore 
189*49ef7e06SGarrett D'Amore 	enp->en_reset_flags |= EFX_RESET_PHY;
190*49ef7e06SGarrett D'Amore 
191*49ef7e06SGarrett D'Amore 	return (0);
192*49ef7e06SGarrett D'Amore 
193*49ef7e06SGarrett D'Amore fail1:
194*49ef7e06SGarrett D'Amore 	EFSYS_PROBE1(fail1, efx_rc_t, rc);
195*49ef7e06SGarrett D'Amore 
196*49ef7e06SGarrett D'Amore 	return (rc);
197*49ef7e06SGarrett D'Amore }
198*49ef7e06SGarrett D'Amore 
199*49ef7e06SGarrett D'Amore 	__checkReturn	efx_rc_t
ef10_phy_get_link(__in efx_nic_t * enp,__out ef10_link_state_t * elsp)200*49ef7e06SGarrett D'Amore ef10_phy_get_link(
201*49ef7e06SGarrett D'Amore 	__in		efx_nic_t *enp,
202*49ef7e06SGarrett D'Amore 	__out		ef10_link_state_t *elsp)
203*49ef7e06SGarrett D'Amore {
204*49ef7e06SGarrett D'Amore 	efx_mcdi_req_t req;
205*49ef7e06SGarrett D'Amore 	uint8_t payload[MAX(MC_CMD_GET_LINK_IN_LEN,
206*49ef7e06SGarrett D'Amore 			    MC_CMD_GET_LINK_OUT_LEN)];
207*49ef7e06SGarrett D'Amore 	efx_rc_t rc;
208*49ef7e06SGarrett D'Amore 
209*49ef7e06SGarrett D'Amore 	(void) memset(payload, 0, sizeof (payload));
210*49ef7e06SGarrett D'Amore 	req.emr_cmd = MC_CMD_GET_LINK;
211*49ef7e06SGarrett D'Amore 	req.emr_in_buf = payload;
212*49ef7e06SGarrett D'Amore 	req.emr_in_length = MC_CMD_GET_LINK_IN_LEN;
213*49ef7e06SGarrett D'Amore 	req.emr_out_buf = payload;
214*49ef7e06SGarrett D'Amore 	req.emr_out_length = MC_CMD_GET_LINK_OUT_LEN;
215*49ef7e06SGarrett D'Amore 
216*49ef7e06SGarrett D'Amore 	efx_mcdi_execute(enp, &req);
217*49ef7e06SGarrett D'Amore 
218*49ef7e06SGarrett D'Amore 	if (req.emr_rc != 0) {
219*49ef7e06SGarrett D'Amore 		rc = req.emr_rc;
220*49ef7e06SGarrett D'Amore 		goto fail1;
221*49ef7e06SGarrett D'Amore 	}
222*49ef7e06SGarrett D'Amore 
223*49ef7e06SGarrett D'Amore 	if (req.emr_out_length_used < MC_CMD_GET_LINK_OUT_LEN) {
224*49ef7e06SGarrett D'Amore 		rc = EMSGSIZE;
225*49ef7e06SGarrett D'Amore 		goto fail2;
226*49ef7e06SGarrett D'Amore 	}
227*49ef7e06SGarrett D'Amore 
228*49ef7e06SGarrett D'Amore 	mcdi_phy_decode_cap(MCDI_OUT_DWORD(req, GET_LINK_OUT_CAP),
229*49ef7e06SGarrett D'Amore 			    &elsp->els_adv_cap_mask);
230*49ef7e06SGarrett D'Amore 	mcdi_phy_decode_cap(MCDI_OUT_DWORD(req, GET_LINK_OUT_LP_CAP),
231*49ef7e06SGarrett D'Amore 			    &elsp->els_lp_cap_mask);
232*49ef7e06SGarrett D'Amore 
233*49ef7e06SGarrett D'Amore 	mcdi_phy_decode_link_mode(enp, MCDI_OUT_DWORD(req, GET_LINK_OUT_FLAGS),
234*49ef7e06SGarrett D'Amore 			    MCDI_OUT_DWORD(req, GET_LINK_OUT_LINK_SPEED),
235*49ef7e06SGarrett D'Amore 			    MCDI_OUT_DWORD(req, GET_LINK_OUT_FCNTL),
236*49ef7e06SGarrett D'Amore 			    &elsp->els_link_mode, &elsp->els_fcntl);
237*49ef7e06SGarrett D'Amore 
238*49ef7e06SGarrett D'Amore #if EFSYS_OPT_LOOPBACK
239*49ef7e06SGarrett D'Amore 	/* Assert the MC_CMD_LOOPBACK and EFX_LOOPBACK namespace agree */
240*49ef7e06SGarrett D'Amore 	EFX_STATIC_ASSERT(MC_CMD_LOOPBACK_NONE == EFX_LOOPBACK_OFF);
241*49ef7e06SGarrett D'Amore 	EFX_STATIC_ASSERT(MC_CMD_LOOPBACK_DATA == EFX_LOOPBACK_DATA);
242*49ef7e06SGarrett D'Amore 	EFX_STATIC_ASSERT(MC_CMD_LOOPBACK_GMAC == EFX_LOOPBACK_GMAC);
243*49ef7e06SGarrett D'Amore 	EFX_STATIC_ASSERT(MC_CMD_LOOPBACK_XGMII == EFX_LOOPBACK_XGMII);
244*49ef7e06SGarrett D'Amore 	EFX_STATIC_ASSERT(MC_CMD_LOOPBACK_XGXS == EFX_LOOPBACK_XGXS);
245*49ef7e06SGarrett D'Amore 	EFX_STATIC_ASSERT(MC_CMD_LOOPBACK_XAUI == EFX_LOOPBACK_XAUI);
246*49ef7e06SGarrett D'Amore 	EFX_STATIC_ASSERT(MC_CMD_LOOPBACK_GMII == EFX_LOOPBACK_GMII);
247*49ef7e06SGarrett D'Amore 	EFX_STATIC_ASSERT(MC_CMD_LOOPBACK_SGMII == EFX_LOOPBACK_SGMII);
248*49ef7e06SGarrett D'Amore 	EFX_STATIC_ASSERT(MC_CMD_LOOPBACK_XGBR == EFX_LOOPBACK_XGBR);
249*49ef7e06SGarrett D'Amore 	EFX_STATIC_ASSERT(MC_CMD_LOOPBACK_XFI == EFX_LOOPBACK_XFI);
250*49ef7e06SGarrett D'Amore 	EFX_STATIC_ASSERT(MC_CMD_LOOPBACK_XAUI_FAR == EFX_LOOPBACK_XAUI_FAR);
251*49ef7e06SGarrett D'Amore 	EFX_STATIC_ASSERT(MC_CMD_LOOPBACK_GMII_FAR == EFX_LOOPBACK_GMII_FAR);
252*49ef7e06SGarrett D'Amore 	EFX_STATIC_ASSERT(MC_CMD_LOOPBACK_SGMII_FAR == EFX_LOOPBACK_SGMII_FAR);
253*49ef7e06SGarrett D'Amore 	EFX_STATIC_ASSERT(MC_CMD_LOOPBACK_XFI_FAR == EFX_LOOPBACK_XFI_FAR);
254*49ef7e06SGarrett D'Amore 	EFX_STATIC_ASSERT(MC_CMD_LOOPBACK_GPHY == EFX_LOOPBACK_GPHY);
255*49ef7e06SGarrett D'Amore 	EFX_STATIC_ASSERT(MC_CMD_LOOPBACK_PHYXS == EFX_LOOPBACK_PHY_XS);
256*49ef7e06SGarrett D'Amore 	EFX_STATIC_ASSERT(MC_CMD_LOOPBACK_PCS == EFX_LOOPBACK_PCS);
257*49ef7e06SGarrett D'Amore 	EFX_STATIC_ASSERT(MC_CMD_LOOPBACK_PMAPMD == EFX_LOOPBACK_PMA_PMD);
258*49ef7e06SGarrett D'Amore 
259*49ef7e06SGarrett D'Amore 	elsp->els_loopback = MCDI_OUT_DWORD(req, GET_LINK_OUT_LOOPBACK_MODE);
260*49ef7e06SGarrett D'Amore #endif	/* EFSYS_OPT_LOOPBACK */
261*49ef7e06SGarrett D'Amore 
262*49ef7e06SGarrett D'Amore 	elsp->els_mac_up = MCDI_OUT_DWORD(req, GET_LINK_OUT_MAC_FAULT) == 0;
263*49ef7e06SGarrett D'Amore 
264*49ef7e06SGarrett D'Amore 	return (0);
265*49ef7e06SGarrett D'Amore 
266*49ef7e06SGarrett D'Amore fail2:
267*49ef7e06SGarrett D'Amore 	EFSYS_PROBE(fail2);
268*49ef7e06SGarrett D'Amore fail1:
269*49ef7e06SGarrett D'Amore 	EFSYS_PROBE1(fail1, efx_rc_t, rc);
270*49ef7e06SGarrett D'Amore 
271*49ef7e06SGarrett D'Amore 	return (rc);
272*49ef7e06SGarrett D'Amore }
273*49ef7e06SGarrett D'Amore 
274*49ef7e06SGarrett D'Amore 	__checkReturn	efx_rc_t
ef10_phy_reconfigure(__in efx_nic_t * enp)275*49ef7e06SGarrett D'Amore ef10_phy_reconfigure(
276*49ef7e06SGarrett D'Amore 	__in		efx_nic_t *enp)
277*49ef7e06SGarrett D'Amore {
278*49ef7e06SGarrett D'Amore 	efx_nic_cfg_t *encp = &(enp->en_nic_cfg);
279*49ef7e06SGarrett D'Amore 	efx_port_t *epp = &(enp->en_port);
280*49ef7e06SGarrett D'Amore 	efx_mcdi_req_t req;
281*49ef7e06SGarrett D'Amore 	uint8_t payload[MAX(MC_CMD_SET_LINK_IN_LEN,
282*49ef7e06SGarrett D'Amore 			    MC_CMD_SET_LINK_OUT_LEN)];
283*49ef7e06SGarrett D'Amore 	uint32_t cap_mask;
284*49ef7e06SGarrett D'Amore 	unsigned int led_mode;
285*49ef7e06SGarrett D'Amore 	unsigned int speed;
286*49ef7e06SGarrett D'Amore 	efx_rc_t rc;
287*49ef7e06SGarrett D'Amore 
288*49ef7e06SGarrett D'Amore 	if (~encp->enc_func_flags & EFX_NIC_FUNC_LINKCTRL)
289*49ef7e06SGarrett D'Amore 		goto out;
290*49ef7e06SGarrett D'Amore 
291*49ef7e06SGarrett D'Amore 	(void) memset(payload, 0, sizeof (payload));
292*49ef7e06SGarrett D'Amore 	req.emr_cmd = MC_CMD_SET_LINK;
293*49ef7e06SGarrett D'Amore 	req.emr_in_buf = payload;
294*49ef7e06SGarrett D'Amore 	req.emr_in_length = MC_CMD_SET_LINK_IN_LEN;
295*49ef7e06SGarrett D'Amore 	req.emr_out_buf = payload;
296*49ef7e06SGarrett D'Amore 	req.emr_out_length = MC_CMD_SET_LINK_OUT_LEN;
297*49ef7e06SGarrett D'Amore 
298*49ef7e06SGarrett D'Amore 	cap_mask = epp->ep_adv_cap_mask;
299*49ef7e06SGarrett D'Amore 	MCDI_IN_POPULATE_DWORD_10(req, SET_LINK_IN_CAP,
300*49ef7e06SGarrett D'Amore 		PHY_CAP_10HDX, (cap_mask >> EFX_PHY_CAP_10HDX) & 0x1,
301*49ef7e06SGarrett D'Amore 		PHY_CAP_10FDX, (cap_mask >> EFX_PHY_CAP_10FDX) & 0x1,
302*49ef7e06SGarrett D'Amore 		PHY_CAP_100HDX, (cap_mask >> EFX_PHY_CAP_100HDX) & 0x1,
303*49ef7e06SGarrett D'Amore 		PHY_CAP_100FDX, (cap_mask >> EFX_PHY_CAP_100FDX) & 0x1,
304*49ef7e06SGarrett D'Amore 		PHY_CAP_1000HDX, (cap_mask >> EFX_PHY_CAP_1000HDX) & 0x1,
305*49ef7e06SGarrett D'Amore 		PHY_CAP_1000FDX, (cap_mask >> EFX_PHY_CAP_1000FDX) & 0x1,
306*49ef7e06SGarrett D'Amore 		PHY_CAP_10000FDX, (cap_mask >> EFX_PHY_CAP_10000FDX) & 0x1,
307*49ef7e06SGarrett D'Amore 		PHY_CAP_PAUSE, (cap_mask >> EFX_PHY_CAP_PAUSE) & 0x1,
308*49ef7e06SGarrett D'Amore 		PHY_CAP_ASYM, (cap_mask >> EFX_PHY_CAP_ASYM) & 0x1,
309*49ef7e06SGarrett D'Amore 		PHY_CAP_AN, (cap_mask >> EFX_PHY_CAP_AN) & 0x1);
310*49ef7e06SGarrett D'Amore 	/* Too many fields for for POPULATE macros, so insert this afterwards */
311*49ef7e06SGarrett D'Amore 	MCDI_IN_SET_DWORD_FIELD(req, SET_LINK_IN_CAP,
312*49ef7e06SGarrett D'Amore 	    PHY_CAP_40000FDX, (cap_mask >> EFX_PHY_CAP_40000FDX) & 0x1);
313*49ef7e06SGarrett D'Amore 
314*49ef7e06SGarrett D'Amore #if EFSYS_OPT_LOOPBACK
315*49ef7e06SGarrett D'Amore 	MCDI_IN_SET_DWORD(req, SET_LINK_IN_LOOPBACK_MODE,
316*49ef7e06SGarrett D'Amore 		    epp->ep_loopback_type);
317*49ef7e06SGarrett D'Amore 	switch (epp->ep_loopback_link_mode) {
318*49ef7e06SGarrett D'Amore 	case EFX_LINK_100FDX:
319*49ef7e06SGarrett D'Amore 		speed = 100;
320*49ef7e06SGarrett D'Amore 		break;
321*49ef7e06SGarrett D'Amore 	case EFX_LINK_1000FDX:
322*49ef7e06SGarrett D'Amore 		speed = 1000;
323*49ef7e06SGarrett D'Amore 		break;
324*49ef7e06SGarrett D'Amore 	case EFX_LINK_10000FDX:
325*49ef7e06SGarrett D'Amore 		speed = 10000;
326*49ef7e06SGarrett D'Amore 		break;
327*49ef7e06SGarrett D'Amore 	case EFX_LINK_40000FDX:
328*49ef7e06SGarrett D'Amore 		speed = 40000;
329*49ef7e06SGarrett D'Amore 		break;
330*49ef7e06SGarrett D'Amore 	default:
331*49ef7e06SGarrett D'Amore 		speed = 0;
332*49ef7e06SGarrett D'Amore 	}
333*49ef7e06SGarrett D'Amore #else
334*49ef7e06SGarrett D'Amore 	MCDI_IN_SET_DWORD(req, SET_LINK_IN_LOOPBACK_MODE, MC_CMD_LOOPBACK_NONE);
335*49ef7e06SGarrett D'Amore 	speed = 0;
336*49ef7e06SGarrett D'Amore #endif	/* EFSYS_OPT_LOOPBACK */
337*49ef7e06SGarrett D'Amore 	MCDI_IN_SET_DWORD(req, SET_LINK_IN_LOOPBACK_SPEED, speed);
338*49ef7e06SGarrett D'Amore 
339*49ef7e06SGarrett D'Amore #if EFSYS_OPT_PHY_FLAGS
340*49ef7e06SGarrett D'Amore 	MCDI_IN_SET_DWORD(req, SET_LINK_IN_FLAGS, epp->ep_phy_flags);
341*49ef7e06SGarrett D'Amore #else
342*49ef7e06SGarrett D'Amore 	MCDI_IN_SET_DWORD(req, SET_LINK_IN_FLAGS, 0);
343*49ef7e06SGarrett D'Amore #endif	/* EFSYS_OPT_PHY_FLAGS */
344*49ef7e06SGarrett D'Amore 
345*49ef7e06SGarrett D'Amore 	efx_mcdi_execute(enp, &req);
346*49ef7e06SGarrett D'Amore 
347*49ef7e06SGarrett D'Amore 	if (req.emr_rc != 0) {
348*49ef7e06SGarrett D'Amore 		rc = req.emr_rc;
349*49ef7e06SGarrett D'Amore 		goto fail1;
350*49ef7e06SGarrett D'Amore 	}
351*49ef7e06SGarrett D'Amore 
352*49ef7e06SGarrett D'Amore 	/* And set the blink mode */
353*49ef7e06SGarrett D'Amore 	(void) memset(payload, 0, sizeof (payload));
354*49ef7e06SGarrett D'Amore 	req.emr_cmd = MC_CMD_SET_ID_LED;
355*49ef7e06SGarrett D'Amore 	req.emr_in_buf = payload;
356*49ef7e06SGarrett D'Amore 	req.emr_in_length = MC_CMD_SET_ID_LED_IN_LEN;
357*49ef7e06SGarrett D'Amore 	req.emr_out_buf = payload;
358*49ef7e06SGarrett D'Amore 	req.emr_out_length = MC_CMD_SET_ID_LED_OUT_LEN;
359*49ef7e06SGarrett D'Amore 
360*49ef7e06SGarrett D'Amore #if EFSYS_OPT_PHY_LED_CONTROL
361*49ef7e06SGarrett D'Amore 	switch (epp->ep_phy_led_mode) {
362*49ef7e06SGarrett D'Amore 	case EFX_PHY_LED_DEFAULT:
363*49ef7e06SGarrett D'Amore 		led_mode = MC_CMD_LED_DEFAULT;
364*49ef7e06SGarrett D'Amore 		break;
365*49ef7e06SGarrett D'Amore 	case EFX_PHY_LED_OFF:
366*49ef7e06SGarrett D'Amore 		led_mode = MC_CMD_LED_OFF;
367*49ef7e06SGarrett D'Amore 		break;
368*49ef7e06SGarrett D'Amore 	case EFX_PHY_LED_ON:
369*49ef7e06SGarrett D'Amore 		led_mode = MC_CMD_LED_ON;
370*49ef7e06SGarrett D'Amore 		break;
371*49ef7e06SGarrett D'Amore 	default:
372*49ef7e06SGarrett D'Amore 		EFSYS_ASSERT(0);
373*49ef7e06SGarrett D'Amore 		led_mode = MC_CMD_LED_DEFAULT;
374*49ef7e06SGarrett D'Amore 	}
375*49ef7e06SGarrett D'Amore 
376*49ef7e06SGarrett D'Amore 	MCDI_IN_SET_DWORD(req, SET_ID_LED_IN_STATE, led_mode);
377*49ef7e06SGarrett D'Amore #else
378*49ef7e06SGarrett D'Amore 	MCDI_IN_SET_DWORD(req, SET_ID_LED_IN_STATE, MC_CMD_LED_DEFAULT);
379*49ef7e06SGarrett D'Amore #endif	/* EFSYS_OPT_PHY_LED_CONTROL */
380*49ef7e06SGarrett D'Amore 
381*49ef7e06SGarrett D'Amore 	efx_mcdi_execute(enp, &req);
382*49ef7e06SGarrett D'Amore 
383*49ef7e06SGarrett D'Amore 	if (req.emr_rc != 0) {
384*49ef7e06SGarrett D'Amore 		rc = req.emr_rc;
385*49ef7e06SGarrett D'Amore 		goto fail2;
386*49ef7e06SGarrett D'Amore 	}
387*49ef7e06SGarrett D'Amore out:
388*49ef7e06SGarrett D'Amore 	return (0);
389*49ef7e06SGarrett D'Amore 
390*49ef7e06SGarrett D'Amore fail2:
391*49ef7e06SGarrett D'Amore 	EFSYS_PROBE(fail2);
392*49ef7e06SGarrett D'Amore fail1:
393*49ef7e06SGarrett D'Amore 	EFSYS_PROBE1(fail1, efx_rc_t, rc);
394*49ef7e06SGarrett D'Amore 
395*49ef7e06SGarrett D'Amore 	return (rc);
396*49ef7e06SGarrett D'Amore }
397*49ef7e06SGarrett D'Amore 
398*49ef7e06SGarrett D'Amore 	__checkReturn	efx_rc_t
ef10_phy_verify(__in efx_nic_t * enp)399*49ef7e06SGarrett D'Amore ef10_phy_verify(
400*49ef7e06SGarrett D'Amore 	__in		efx_nic_t *enp)
401*49ef7e06SGarrett D'Amore {
402*49ef7e06SGarrett D'Amore 	efx_mcdi_req_t req;
403*49ef7e06SGarrett D'Amore 	uint8_t payload[MAX(MC_CMD_GET_PHY_STATE_IN_LEN,
404*49ef7e06SGarrett D'Amore 			    MC_CMD_GET_PHY_STATE_OUT_LEN)];
405*49ef7e06SGarrett D'Amore 	uint32_t state;
406*49ef7e06SGarrett D'Amore 	efx_rc_t rc;
407*49ef7e06SGarrett D'Amore 
408*49ef7e06SGarrett D'Amore 	(void) memset(payload, 0, sizeof (payload));
409*49ef7e06SGarrett D'Amore 	req.emr_cmd = MC_CMD_GET_PHY_STATE;
410*49ef7e06SGarrett D'Amore 	req.emr_in_buf = payload;
411*49ef7e06SGarrett D'Amore 	req.emr_in_length = MC_CMD_GET_PHY_STATE_IN_LEN;
412*49ef7e06SGarrett D'Amore 	req.emr_out_buf = payload;
413*49ef7e06SGarrett D'Amore 	req.emr_out_length = MC_CMD_GET_PHY_STATE_OUT_LEN;
414*49ef7e06SGarrett D'Amore 
415*49ef7e06SGarrett D'Amore 	efx_mcdi_execute(enp, &req);
416*49ef7e06SGarrett D'Amore 
417*49ef7e06SGarrett D'Amore 	if (req.emr_rc != 0) {
418*49ef7e06SGarrett D'Amore 		rc = req.emr_rc;
419*49ef7e06SGarrett D'Amore 		goto fail1;
420*49ef7e06SGarrett D'Amore 	}
421*49ef7e06SGarrett D'Amore 
422*49ef7e06SGarrett D'Amore 	if (req.emr_out_length_used < MC_CMD_GET_PHY_STATE_OUT_LEN) {
423*49ef7e06SGarrett D'Amore 		rc = EMSGSIZE;
424*49ef7e06SGarrett D'Amore 		goto fail2;
425*49ef7e06SGarrett D'Amore 	}
426*49ef7e06SGarrett D'Amore 
427*49ef7e06SGarrett D'Amore 	state = MCDI_OUT_DWORD(req, GET_PHY_STATE_OUT_STATE);
428*49ef7e06SGarrett D'Amore 	if (state != MC_CMD_PHY_STATE_OK) {
429*49ef7e06SGarrett D'Amore 		if (state != MC_CMD_PHY_STATE_ZOMBIE)
430*49ef7e06SGarrett D'Amore 			EFSYS_PROBE1(mc_pcol_error, int, state);
431*49ef7e06SGarrett D'Amore 		rc = ENOTACTIVE;
432*49ef7e06SGarrett D'Amore 		goto fail3;
433*49ef7e06SGarrett D'Amore 	}
434*49ef7e06SGarrett D'Amore 
435*49ef7e06SGarrett D'Amore 	return (0);
436*49ef7e06SGarrett D'Amore 
437*49ef7e06SGarrett D'Amore fail3:
438*49ef7e06SGarrett D'Amore 	EFSYS_PROBE(fail3);
439*49ef7e06SGarrett D'Amore fail2:
440*49ef7e06SGarrett D'Amore 	EFSYS_PROBE(fail2);
441*49ef7e06SGarrett D'Amore fail1:
442*49ef7e06SGarrett D'Amore 	EFSYS_PROBE1(fail1, efx_rc_t, rc);
443*49ef7e06SGarrett D'Amore 
444*49ef7e06SGarrett D'Amore 	return (rc);
445*49ef7e06SGarrett D'Amore }
446*49ef7e06SGarrett D'Amore 
447*49ef7e06SGarrett D'Amore 	__checkReturn	efx_rc_t
ef10_phy_oui_get(__in efx_nic_t * enp,__out uint32_t * ouip)448*49ef7e06SGarrett D'Amore ef10_phy_oui_get(
449*49ef7e06SGarrett D'Amore 	__in		efx_nic_t *enp,
450*49ef7e06SGarrett D'Amore 	__out		uint32_t *ouip)
451*49ef7e06SGarrett D'Amore {
452*49ef7e06SGarrett D'Amore 	_NOTE(ARGUNUSED(enp, ouip))
453*49ef7e06SGarrett D'Amore 
454*49ef7e06SGarrett D'Amore 	return (ENOTSUP);
455*49ef7e06SGarrett D'Amore }
456*49ef7e06SGarrett D'Amore 
457*49ef7e06SGarrett D'Amore #if EFSYS_OPT_PHY_STATS
458*49ef7e06SGarrett D'Amore 
459*49ef7e06SGarrett D'Amore 	__checkReturn				efx_rc_t
ef10_phy_stats_update(__in efx_nic_t * enp,__in efsys_mem_t * esmp,__inout_ecount (EFX_PHY_NSTATS)uint32_t * stat)460*49ef7e06SGarrett D'Amore ef10_phy_stats_update(
461*49ef7e06SGarrett D'Amore 	__in					efx_nic_t *enp,
462*49ef7e06SGarrett D'Amore 	__in					efsys_mem_t *esmp,
463*49ef7e06SGarrett D'Amore 	__inout_ecount(EFX_PHY_NSTATS)		uint32_t *stat)
464*49ef7e06SGarrett D'Amore {
465*49ef7e06SGarrett D'Amore 	/* TBD: no stats support in firmware yet */
466*49ef7e06SGarrett D'Amore 	_NOTE(ARGUNUSED(enp, esmp))
467*49ef7e06SGarrett D'Amore 	(void) memset(stat, 0, EFX_PHY_NSTATS * sizeof (*stat));
468*49ef7e06SGarrett D'Amore 
469*49ef7e06SGarrett D'Amore 	return (0);
470*49ef7e06SGarrett D'Amore }
471*49ef7e06SGarrett D'Amore 
472*49ef7e06SGarrett D'Amore #endif	/* EFSYS_OPT_PHY_STATS */
473*49ef7e06SGarrett D'Amore 
474*49ef7e06SGarrett D'Amore #endif	/* EFSYS_OPT_HUNTINGTON || EFSYS_OPT_MEDFORD */
475