1*49ef7e06SGarrett D'Amore /*
2*49ef7e06SGarrett D'Amore  * Copyright (c) 2007-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 
35*49ef7e06SGarrett D'Amore #if EFSYS_OPT_SIENA
36*49ef7e06SGarrett D'Amore static const efx_phy_ops_t	__efx_phy_siena_ops = {
37*49ef7e06SGarrett D'Amore 	siena_phy_power,		/* epo_power */
38*49ef7e06SGarrett D'Amore 	NULL,				/* epo_reset */
39*49ef7e06SGarrett D'Amore 	siena_phy_reconfigure,		/* epo_reconfigure */
40*49ef7e06SGarrett D'Amore 	siena_phy_verify,		/* epo_verify */
41*49ef7e06SGarrett D'Amore 	siena_phy_oui_get,		/* epo_oui_get */
42*49ef7e06SGarrett D'Amore #if EFSYS_OPT_PHY_STATS
43*49ef7e06SGarrett D'Amore 	siena_phy_stats_update,		/* epo_stats_update */
44*49ef7e06SGarrett D'Amore #endif	/* EFSYS_OPT_PHY_STATS */
45*49ef7e06SGarrett D'Amore #if EFSYS_OPT_BIST
46*49ef7e06SGarrett D'Amore 	NULL,				/* epo_bist_enable_offline */
47*49ef7e06SGarrett D'Amore 	siena_phy_bist_start, 		/* epo_bist_start */
48*49ef7e06SGarrett D'Amore 	siena_phy_bist_poll,		/* epo_bist_poll */
49*49ef7e06SGarrett D'Amore 	siena_phy_bist_stop,		/* epo_bist_stop */
50*49ef7e06SGarrett D'Amore #endif	/* EFSYS_OPT_BIST */
51*49ef7e06SGarrett D'Amore };
52*49ef7e06SGarrett D'Amore #endif	/* EFSYS_OPT_SIENA */
53*49ef7e06SGarrett D'Amore 
54*49ef7e06SGarrett D'Amore #if EFSYS_OPT_HUNTINGTON || EFSYS_OPT_MEDFORD
55*49ef7e06SGarrett D'Amore static const efx_phy_ops_t	__efx_phy_ef10_ops = {
56*49ef7e06SGarrett D'Amore 	ef10_phy_power,			/* epo_power */
57*49ef7e06SGarrett D'Amore 	NULL,				/* epo_reset */
58*49ef7e06SGarrett D'Amore 	ef10_phy_reconfigure,		/* epo_reconfigure */
59*49ef7e06SGarrett D'Amore 	ef10_phy_verify,		/* epo_verify */
60*49ef7e06SGarrett D'Amore 	ef10_phy_oui_get,		/* epo_oui_get */
61*49ef7e06SGarrett D'Amore #if EFSYS_OPT_PHY_STATS
62*49ef7e06SGarrett D'Amore 	ef10_phy_stats_update,		/* epo_stats_update */
63*49ef7e06SGarrett D'Amore #endif	/* EFSYS_OPT_PHY_STATS */
64*49ef7e06SGarrett D'Amore #if EFSYS_OPT_BIST
65*49ef7e06SGarrett D'Amore 	/* FIXME: Are these BIST methods appropriate for Medford? */
66*49ef7e06SGarrett D'Amore 	hunt_bist_enable_offline,	/* epo_bist_enable_offline */
67*49ef7e06SGarrett D'Amore 	hunt_bist_start,		/* epo_bist_start */
68*49ef7e06SGarrett D'Amore 	hunt_bist_poll,			/* epo_bist_poll */
69*49ef7e06SGarrett D'Amore 	hunt_bist_stop,			/* epo_bist_stop */
70*49ef7e06SGarrett D'Amore #endif	/* EFSYS_OPT_BIST */
71*49ef7e06SGarrett D'Amore };
72*49ef7e06SGarrett D'Amore #endif	/* EFSYS_OPT_HUNTINGTON || EFSYS_OPT_MEDFORD */
73*49ef7e06SGarrett D'Amore 
74*49ef7e06SGarrett D'Amore 	__checkReturn	efx_rc_t
efx_phy_probe(__in efx_nic_t * enp)75*49ef7e06SGarrett D'Amore efx_phy_probe(
76*49ef7e06SGarrett D'Amore 	__in		efx_nic_t *enp)
77*49ef7e06SGarrett D'Amore {
78*49ef7e06SGarrett D'Amore 	efx_port_t *epp = &(enp->en_port);
79*49ef7e06SGarrett D'Amore 	efx_nic_cfg_t *encp = &(enp->en_nic_cfg);
80*49ef7e06SGarrett D'Amore 	const efx_phy_ops_t *epop;
81*49ef7e06SGarrett D'Amore 	efx_rc_t rc;
82*49ef7e06SGarrett D'Amore 
83*49ef7e06SGarrett D'Amore 	EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
84*49ef7e06SGarrett D'Amore 
85*49ef7e06SGarrett D'Amore 	epp->ep_port = encp->enc_port;
86*49ef7e06SGarrett D'Amore 	epp->ep_phy_type = encp->enc_phy_type;
87*49ef7e06SGarrett D'Amore 
88*49ef7e06SGarrett D'Amore 	/* Hook in operations structure */
89*49ef7e06SGarrett D'Amore 	switch (enp->en_family) {
90*49ef7e06SGarrett D'Amore #if EFSYS_OPT_SIENA
91*49ef7e06SGarrett D'Amore 	case EFX_FAMILY_SIENA:
92*49ef7e06SGarrett D'Amore 		epop = &__efx_phy_siena_ops;
93*49ef7e06SGarrett D'Amore 		break;
94*49ef7e06SGarrett D'Amore #endif	/* EFSYS_OPT_SIENA */
95*49ef7e06SGarrett D'Amore #if EFSYS_OPT_HUNTINGTON
96*49ef7e06SGarrett D'Amore 	case EFX_FAMILY_HUNTINGTON:
97*49ef7e06SGarrett D'Amore 		epop = &__efx_phy_ef10_ops;
98*49ef7e06SGarrett D'Amore 		break;
99*49ef7e06SGarrett D'Amore #endif	/* EFSYS_OPT_HUNTINGTON */
100*49ef7e06SGarrett D'Amore #if EFSYS_OPT_MEDFORD
101*49ef7e06SGarrett D'Amore 	case EFX_FAMILY_MEDFORD:
102*49ef7e06SGarrett D'Amore 		epop = &__efx_phy_ef10_ops;
103*49ef7e06SGarrett D'Amore 		break;
104*49ef7e06SGarrett D'Amore #endif	/* EFSYS_OPT_MEDFORD */
105*49ef7e06SGarrett D'Amore 	default:
106*49ef7e06SGarrett D'Amore 		rc = ENOTSUP;
107*49ef7e06SGarrett D'Amore 		goto fail1;
108*49ef7e06SGarrett D'Amore 	}
109*49ef7e06SGarrett D'Amore 
110*49ef7e06SGarrett D'Amore 	epp->ep_epop = epop;
111*49ef7e06SGarrett D'Amore 
112*49ef7e06SGarrett D'Amore 	return (0);
113*49ef7e06SGarrett D'Amore 
114*49ef7e06SGarrett D'Amore fail1:
115*49ef7e06SGarrett D'Amore 	EFSYS_PROBE1(fail1, efx_rc_t, rc);
116*49ef7e06SGarrett D'Amore 
117*49ef7e06SGarrett D'Amore 	epp->ep_port = 0;
118*49ef7e06SGarrett D'Amore 	epp->ep_phy_type = 0;
119*49ef7e06SGarrett D'Amore 
120*49ef7e06SGarrett D'Amore 	return (rc);
121*49ef7e06SGarrett D'Amore }
122*49ef7e06SGarrett D'Amore 
123*49ef7e06SGarrett D'Amore 	__checkReturn	efx_rc_t
efx_phy_verify(__in efx_nic_t * enp)124*49ef7e06SGarrett D'Amore efx_phy_verify(
125*49ef7e06SGarrett D'Amore 	__in		efx_nic_t *enp)
126*49ef7e06SGarrett D'Amore {
127*49ef7e06SGarrett D'Amore 	efx_port_t *epp = &(enp->en_port);
128*49ef7e06SGarrett D'Amore 	const efx_phy_ops_t *epop = epp->ep_epop;
129*49ef7e06SGarrett D'Amore 
130*49ef7e06SGarrett D'Amore 	EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
131*49ef7e06SGarrett D'Amore 	EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_PORT);
132*49ef7e06SGarrett D'Amore 
133*49ef7e06SGarrett D'Amore 	return (epop->epo_verify(enp));
134*49ef7e06SGarrett D'Amore }
135*49ef7e06SGarrett D'Amore 
136*49ef7e06SGarrett D'Amore #if EFSYS_OPT_PHY_LED_CONTROL
137*49ef7e06SGarrett D'Amore 
138*49ef7e06SGarrett D'Amore 	__checkReturn	efx_rc_t
efx_phy_led_set(__in efx_nic_t * enp,__in efx_phy_led_mode_t mode)139*49ef7e06SGarrett D'Amore efx_phy_led_set(
140*49ef7e06SGarrett D'Amore 	__in		efx_nic_t *enp,
141*49ef7e06SGarrett D'Amore 	__in		efx_phy_led_mode_t mode)
142*49ef7e06SGarrett D'Amore {
143*49ef7e06SGarrett D'Amore 	efx_nic_cfg_t *encp = (&enp->en_nic_cfg);
144*49ef7e06SGarrett D'Amore 	efx_port_t *epp = &(enp->en_port);
145*49ef7e06SGarrett D'Amore 	const efx_phy_ops_t *epop = epp->ep_epop;
146*49ef7e06SGarrett D'Amore 	uint32_t mask;
147*49ef7e06SGarrett D'Amore 	efx_rc_t rc;
148*49ef7e06SGarrett D'Amore 
149*49ef7e06SGarrett D'Amore 	EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
150*49ef7e06SGarrett D'Amore 	EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_PORT);
151*49ef7e06SGarrett D'Amore 
152*49ef7e06SGarrett D'Amore 	if (epp->ep_phy_led_mode == mode)
153*49ef7e06SGarrett D'Amore 		goto done;
154*49ef7e06SGarrett D'Amore 
155*49ef7e06SGarrett D'Amore 	mask = (1 << EFX_PHY_LED_DEFAULT);
156*49ef7e06SGarrett D'Amore 	mask |= encp->enc_led_mask;
157*49ef7e06SGarrett D'Amore 
158*49ef7e06SGarrett D'Amore 	if (!((1 << mode) & mask)) {
159*49ef7e06SGarrett D'Amore 		rc = ENOTSUP;
160*49ef7e06SGarrett D'Amore 		goto fail1;
161*49ef7e06SGarrett D'Amore 	}
162*49ef7e06SGarrett D'Amore 
163*49ef7e06SGarrett D'Amore 	EFSYS_ASSERT3U(mode, <, EFX_PHY_LED_NMODES);
164*49ef7e06SGarrett D'Amore 	epp->ep_phy_led_mode = mode;
165*49ef7e06SGarrett D'Amore 
166*49ef7e06SGarrett D'Amore 	if ((rc = epop->epo_reconfigure(enp)) != 0)
167*49ef7e06SGarrett D'Amore 		goto fail2;
168*49ef7e06SGarrett D'Amore 
169*49ef7e06SGarrett D'Amore done:
170*49ef7e06SGarrett D'Amore 	return (0);
171*49ef7e06SGarrett D'Amore 
172*49ef7e06SGarrett D'Amore fail2:
173*49ef7e06SGarrett D'Amore 	EFSYS_PROBE(fail2);
174*49ef7e06SGarrett D'Amore fail1:
175*49ef7e06SGarrett D'Amore 	EFSYS_PROBE1(fail1, efx_rc_t, rc);
176*49ef7e06SGarrett D'Amore 
177*49ef7e06SGarrett D'Amore 	return (rc);
178*49ef7e06SGarrett D'Amore }
179*49ef7e06SGarrett D'Amore #endif	/* EFSYS_OPT_PHY_LED_CONTROL */
180*49ef7e06SGarrett D'Amore 
181*49ef7e06SGarrett D'Amore 			void
efx_phy_adv_cap_get(__in efx_nic_t * enp,__in uint32_t flag,__out uint32_t * maskp)182*49ef7e06SGarrett D'Amore efx_phy_adv_cap_get(
183*49ef7e06SGarrett D'Amore 	__in		efx_nic_t *enp,
184*49ef7e06SGarrett D'Amore 	__in		uint32_t flag,
185*49ef7e06SGarrett D'Amore 	__out		uint32_t *maskp)
186*49ef7e06SGarrett D'Amore {
187*49ef7e06SGarrett D'Amore 	efx_port_t *epp = &(enp->en_port);
188*49ef7e06SGarrett D'Amore 
189*49ef7e06SGarrett D'Amore 	EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
190*49ef7e06SGarrett D'Amore 	EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_PROBE);
191*49ef7e06SGarrett D'Amore 
192*49ef7e06SGarrett D'Amore 	switch (flag) {
193*49ef7e06SGarrett D'Amore 	case EFX_PHY_CAP_CURRENT:
194*49ef7e06SGarrett D'Amore 		*maskp = epp->ep_adv_cap_mask;
195*49ef7e06SGarrett D'Amore 		break;
196*49ef7e06SGarrett D'Amore 	case EFX_PHY_CAP_DEFAULT:
197*49ef7e06SGarrett D'Amore 		*maskp = epp->ep_default_adv_cap_mask;
198*49ef7e06SGarrett D'Amore 		break;
199*49ef7e06SGarrett D'Amore 	case EFX_PHY_CAP_PERM:
200*49ef7e06SGarrett D'Amore 		*maskp = epp->ep_phy_cap_mask;
201*49ef7e06SGarrett D'Amore 		break;
202*49ef7e06SGarrett D'Amore 	default:
203*49ef7e06SGarrett D'Amore 		EFSYS_ASSERT(B_FALSE);
204*49ef7e06SGarrett D'Amore 		break;
205*49ef7e06SGarrett D'Amore 	}
206*49ef7e06SGarrett D'Amore }
207*49ef7e06SGarrett D'Amore 
208*49ef7e06SGarrett D'Amore 	__checkReturn	efx_rc_t
efx_phy_adv_cap_set(__in efx_nic_t * enp,__in uint32_t mask)209*49ef7e06SGarrett D'Amore efx_phy_adv_cap_set(
210*49ef7e06SGarrett D'Amore 	__in		efx_nic_t *enp,
211*49ef7e06SGarrett D'Amore 	__in		uint32_t mask)
212*49ef7e06SGarrett D'Amore {
213*49ef7e06SGarrett D'Amore 	efx_port_t *epp = &(enp->en_port);
214*49ef7e06SGarrett D'Amore 	const efx_phy_ops_t *epop = epp->ep_epop;
215*49ef7e06SGarrett D'Amore 	uint32_t old_mask;
216*49ef7e06SGarrett D'Amore 	efx_rc_t rc;
217*49ef7e06SGarrett D'Amore 
218*49ef7e06SGarrett D'Amore 	EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
219*49ef7e06SGarrett D'Amore 	EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_PORT);
220*49ef7e06SGarrett D'Amore 
221*49ef7e06SGarrett D'Amore 	if ((mask & ~epp->ep_phy_cap_mask) != 0) {
222*49ef7e06SGarrett D'Amore 		rc = ENOTSUP;
223*49ef7e06SGarrett D'Amore 		goto fail1;
224*49ef7e06SGarrett D'Amore 	}
225*49ef7e06SGarrett D'Amore 
226*49ef7e06SGarrett D'Amore 	if (epp->ep_adv_cap_mask == mask)
227*49ef7e06SGarrett D'Amore 		goto done;
228*49ef7e06SGarrett D'Amore 
229*49ef7e06SGarrett D'Amore 	old_mask = epp->ep_adv_cap_mask;
230*49ef7e06SGarrett D'Amore 	epp->ep_adv_cap_mask = mask;
231*49ef7e06SGarrett D'Amore 
232*49ef7e06SGarrett D'Amore 	if ((rc = epop->epo_reconfigure(enp)) != 0)
233*49ef7e06SGarrett D'Amore 		goto fail2;
234*49ef7e06SGarrett D'Amore 
235*49ef7e06SGarrett D'Amore done:
236*49ef7e06SGarrett D'Amore 	return (0);
237*49ef7e06SGarrett D'Amore 
238*49ef7e06SGarrett D'Amore fail2:
239*49ef7e06SGarrett D'Amore 	EFSYS_PROBE(fail2);
240*49ef7e06SGarrett D'Amore 
241*49ef7e06SGarrett D'Amore 	epp->ep_adv_cap_mask = old_mask;
242*49ef7e06SGarrett D'Amore 	/* Reconfigure for robustness */
243*49ef7e06SGarrett D'Amore 	if (epop->epo_reconfigure(enp) != 0) {
244*49ef7e06SGarrett D'Amore 		/*
245*49ef7e06SGarrett D'Amore 		 * We may have an inconsistent view of our advertised speed
246*49ef7e06SGarrett D'Amore 		 * capabilities.
247*49ef7e06SGarrett D'Amore 		 */
248*49ef7e06SGarrett D'Amore 		EFSYS_ASSERT(0);
249*49ef7e06SGarrett D'Amore 	}
250*49ef7e06SGarrett D'Amore 
251*49ef7e06SGarrett D'Amore fail1:
252*49ef7e06SGarrett D'Amore 	EFSYS_PROBE1(fail1, efx_rc_t, rc);
253*49ef7e06SGarrett D'Amore 
254*49ef7e06SGarrett D'Amore 	return (rc);
255*49ef7e06SGarrett D'Amore }
256*49ef7e06SGarrett D'Amore 
257*49ef7e06SGarrett D'Amore 	void
efx_phy_lp_cap_get(__in efx_nic_t * enp,__out uint32_t * maskp)258*49ef7e06SGarrett D'Amore efx_phy_lp_cap_get(
259*49ef7e06SGarrett D'Amore 	__in		efx_nic_t *enp,
260*49ef7e06SGarrett D'Amore 	__out		uint32_t *maskp)
261*49ef7e06SGarrett D'Amore {
262*49ef7e06SGarrett D'Amore 	efx_port_t *epp = &(enp->en_port);
263*49ef7e06SGarrett D'Amore 
264*49ef7e06SGarrett D'Amore 	EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
265*49ef7e06SGarrett D'Amore 	EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_PORT);
266*49ef7e06SGarrett D'Amore 
267*49ef7e06SGarrett D'Amore 	*maskp = epp->ep_lp_cap_mask;
268*49ef7e06SGarrett D'Amore }
269*49ef7e06SGarrett D'Amore 
270*49ef7e06SGarrett D'Amore 	__checkReturn	efx_rc_t
efx_phy_oui_get(__in efx_nic_t * enp,__out uint32_t * ouip)271*49ef7e06SGarrett D'Amore efx_phy_oui_get(
272*49ef7e06SGarrett D'Amore 	__in		efx_nic_t *enp,
273*49ef7e06SGarrett D'Amore 	__out		uint32_t *ouip)
274*49ef7e06SGarrett D'Amore {
275*49ef7e06SGarrett D'Amore 	efx_port_t *epp = &(enp->en_port);
276*49ef7e06SGarrett D'Amore 	const efx_phy_ops_t *epop = epp->ep_epop;
277*49ef7e06SGarrett D'Amore 
278*49ef7e06SGarrett D'Amore 	EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
279*49ef7e06SGarrett D'Amore 	EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_PORT);
280*49ef7e06SGarrett D'Amore 
281*49ef7e06SGarrett D'Amore 	return (epop->epo_oui_get(enp, ouip));
282*49ef7e06SGarrett D'Amore }
283*49ef7e06SGarrett D'Amore 
284*49ef7e06SGarrett D'Amore 			void
efx_phy_media_type_get(__in efx_nic_t * enp,__out efx_phy_media_type_t * typep)285*49ef7e06SGarrett D'Amore efx_phy_media_type_get(
286*49ef7e06SGarrett D'Amore 	__in		efx_nic_t *enp,
287*49ef7e06SGarrett D'Amore 	__out		efx_phy_media_type_t *typep)
288*49ef7e06SGarrett D'Amore {
289*49ef7e06SGarrett D'Amore 	efx_port_t *epp = &(enp->en_port);
290*49ef7e06SGarrett D'Amore 
291*49ef7e06SGarrett D'Amore 	EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
292*49ef7e06SGarrett D'Amore 	EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_PORT);
293*49ef7e06SGarrett D'Amore 
294*49ef7e06SGarrett D'Amore 	if (epp->ep_module_type != EFX_PHY_MEDIA_INVALID)
295*49ef7e06SGarrett D'Amore 		*typep = epp->ep_module_type;
296*49ef7e06SGarrett D'Amore 	else
297*49ef7e06SGarrett D'Amore 		*typep = epp->ep_fixed_port_type;
298*49ef7e06SGarrett D'Amore }
299*49ef7e06SGarrett D'Amore 
300*49ef7e06SGarrett D'Amore 	__checkReturn	efx_rc_t
efx_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)301*49ef7e06SGarrett D'Amore efx_phy_module_get_info(
302*49ef7e06SGarrett D'Amore 	__in			efx_nic_t *enp,
303*49ef7e06SGarrett D'Amore 	__in			uint8_t dev_addr,
304*49ef7e06SGarrett D'Amore 	__in			uint8_t offset,
305*49ef7e06SGarrett D'Amore 	__in			uint8_t len,
306*49ef7e06SGarrett D'Amore 	__out_bcount(len)	uint8_t *data)
307*49ef7e06SGarrett D'Amore {
308*49ef7e06SGarrett D'Amore 	efx_rc_t rc;
309*49ef7e06SGarrett D'Amore 
310*49ef7e06SGarrett D'Amore 	EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
311*49ef7e06SGarrett D'Amore 	EFSYS_ASSERT(data != NULL);
312*49ef7e06SGarrett D'Amore 
313*49ef7e06SGarrett D'Amore 	if ((uint32_t)offset + len > 0xff) {
314*49ef7e06SGarrett D'Amore 		rc = EINVAL;
315*49ef7e06SGarrett D'Amore 		goto fail1;
316*49ef7e06SGarrett D'Amore 	}
317*49ef7e06SGarrett D'Amore 
318*49ef7e06SGarrett D'Amore 	if ((rc = efx_mcdi_phy_module_get_info(enp, dev_addr,
319*49ef7e06SGarrett D'Amore 	    offset, len, data)) != 0)
320*49ef7e06SGarrett D'Amore 		goto fail2;
321*49ef7e06SGarrett D'Amore 
322*49ef7e06SGarrett D'Amore 	return (0);
323*49ef7e06SGarrett D'Amore 
324*49ef7e06SGarrett D'Amore fail2:
325*49ef7e06SGarrett D'Amore 	EFSYS_PROBE(fail2);
326*49ef7e06SGarrett D'Amore fail1:
327*49ef7e06SGarrett D'Amore 	EFSYS_PROBE1(fail1, efx_rc_t, rc);
328*49ef7e06SGarrett D'Amore 
329*49ef7e06SGarrett D'Amore 	return (rc);
330*49ef7e06SGarrett D'Amore }
331*49ef7e06SGarrett D'Amore 
332*49ef7e06SGarrett D'Amore #if EFSYS_OPT_PHY_STATS
333*49ef7e06SGarrett D'Amore 
334*49ef7e06SGarrett D'Amore #if EFSYS_OPT_NAMES
335*49ef7e06SGarrett D'Amore 
336*49ef7e06SGarrett D'Amore /* START MKCONFIG GENERATED PhyStatNamesBlock d5f79b4bc2c050fe */
337*49ef7e06SGarrett D'Amore static const char 	*__efx_phy_stat_name[] = {
338*49ef7e06SGarrett D'Amore 	"oui",
339*49ef7e06SGarrett D'Amore 	"pma_pmd_link_up",
340*49ef7e06SGarrett D'Amore 	"pma_pmd_rx_fault",
341*49ef7e06SGarrett D'Amore 	"pma_pmd_tx_fault",
342*49ef7e06SGarrett D'Amore 	"pma_pmd_rev_a",
343*49ef7e06SGarrett D'Amore 	"pma_pmd_rev_b",
344*49ef7e06SGarrett D'Amore 	"pma_pmd_rev_c",
345*49ef7e06SGarrett D'Amore 	"pma_pmd_rev_d",
346*49ef7e06SGarrett D'Amore 	"pcs_link_up",
347*49ef7e06SGarrett D'Amore 	"pcs_rx_fault",
348*49ef7e06SGarrett D'Amore 	"pcs_tx_fault",
349*49ef7e06SGarrett D'Amore 	"pcs_ber",
350*49ef7e06SGarrett D'Amore 	"pcs_block_errors",
351*49ef7e06SGarrett D'Amore 	"phy_xs_link_up",
352*49ef7e06SGarrett D'Amore 	"phy_xs_rx_fault",
353*49ef7e06SGarrett D'Amore 	"phy_xs_tx_fault",
354*49ef7e06SGarrett D'Amore 	"phy_xs_align",
355*49ef7e06SGarrett D'Amore 	"phy_xs_sync_a",
356*49ef7e06SGarrett D'Amore 	"phy_xs_sync_b",
357*49ef7e06SGarrett D'Amore 	"phy_xs_sync_c",
358*49ef7e06SGarrett D'Amore 	"phy_xs_sync_d",
359*49ef7e06SGarrett D'Amore 	"an_link_up",
360*49ef7e06SGarrett D'Amore 	"an_master",
361*49ef7e06SGarrett D'Amore 	"an_local_rx_ok",
362*49ef7e06SGarrett D'Amore 	"an_remote_rx_ok",
363*49ef7e06SGarrett D'Amore 	"cl22ext_link_up",
364*49ef7e06SGarrett D'Amore 	"snr_a",
365*49ef7e06SGarrett D'Amore 	"snr_b",
366*49ef7e06SGarrett D'Amore 	"snr_c",
367*49ef7e06SGarrett D'Amore 	"snr_d",
368*49ef7e06SGarrett D'Amore 	"pma_pmd_signal_a",
369*49ef7e06SGarrett D'Amore 	"pma_pmd_signal_b",
370*49ef7e06SGarrett D'Amore 	"pma_pmd_signal_c",
371*49ef7e06SGarrett D'Amore 	"pma_pmd_signal_d",
372*49ef7e06SGarrett D'Amore 	"an_complete",
373*49ef7e06SGarrett D'Amore 	"pma_pmd_rev_major",
374*49ef7e06SGarrett D'Amore 	"pma_pmd_rev_minor",
375*49ef7e06SGarrett D'Amore 	"pma_pmd_rev_micro",
376*49ef7e06SGarrett D'Amore 	"pcs_fw_version_0",
377*49ef7e06SGarrett D'Amore 	"pcs_fw_version_1",
378*49ef7e06SGarrett D'Amore 	"pcs_fw_version_2",
379*49ef7e06SGarrett D'Amore 	"pcs_fw_version_3",
380*49ef7e06SGarrett D'Amore 	"pcs_fw_build_yy",
381*49ef7e06SGarrett D'Amore 	"pcs_fw_build_mm",
382*49ef7e06SGarrett D'Amore 	"pcs_fw_build_dd",
383*49ef7e06SGarrett D'Amore 	"pcs_op_mode",
384*49ef7e06SGarrett D'Amore };
385*49ef7e06SGarrett D'Amore 
386*49ef7e06SGarrett D'Amore /* END MKCONFIG GENERATED PhyStatNamesBlock */
387*49ef7e06SGarrett D'Amore 
388*49ef7e06SGarrett D'Amore 					const char *
efx_phy_stat_name(__in efx_nic_t * enp,__in efx_phy_stat_t type)389*49ef7e06SGarrett D'Amore efx_phy_stat_name(
390*49ef7e06SGarrett D'Amore 	__in				efx_nic_t *enp,
391*49ef7e06SGarrett D'Amore 	__in				efx_phy_stat_t type)
392*49ef7e06SGarrett D'Amore {
393*49ef7e06SGarrett D'Amore 	_NOTE(ARGUNUSED(enp))
394*49ef7e06SGarrett D'Amore 	EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
395*49ef7e06SGarrett D'Amore 	EFSYS_ASSERT3U(type, <, EFX_PHY_NSTATS);
396*49ef7e06SGarrett D'Amore 
397*49ef7e06SGarrett D'Amore 	return (__efx_phy_stat_name[type]);
398*49ef7e06SGarrett D'Amore }
399*49ef7e06SGarrett D'Amore 
400*49ef7e06SGarrett D'Amore #endif	/* EFSYS_OPT_NAMES */
401*49ef7e06SGarrett D'Amore 
402*49ef7e06SGarrett D'Amore 	__checkReturn			efx_rc_t
efx_phy_stats_update(__in efx_nic_t * enp,__in efsys_mem_t * esmp,__inout_ecount (EFX_PHY_NSTATS)uint32_t * stat)403*49ef7e06SGarrett D'Amore efx_phy_stats_update(
404*49ef7e06SGarrett D'Amore 	__in				efx_nic_t *enp,
405*49ef7e06SGarrett D'Amore 	__in				efsys_mem_t *esmp,
406*49ef7e06SGarrett D'Amore 	__inout_ecount(EFX_PHY_NSTATS)	uint32_t *stat)
407*49ef7e06SGarrett D'Amore {
408*49ef7e06SGarrett D'Amore 	efx_port_t *epp = &(enp->en_port);
409*49ef7e06SGarrett D'Amore 	const efx_phy_ops_t *epop = epp->ep_epop;
410*49ef7e06SGarrett D'Amore 
411*49ef7e06SGarrett D'Amore 	EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
412*49ef7e06SGarrett D'Amore 	EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_PORT);
413*49ef7e06SGarrett D'Amore 
414*49ef7e06SGarrett D'Amore 	return (epop->epo_stats_update(enp, esmp, stat));
415*49ef7e06SGarrett D'Amore }
416*49ef7e06SGarrett D'Amore 
417*49ef7e06SGarrett D'Amore #endif	/* EFSYS_OPT_PHY_STATS */
418*49ef7e06SGarrett D'Amore 
419*49ef7e06SGarrett D'Amore 
420*49ef7e06SGarrett D'Amore #if EFSYS_OPT_BIST
421*49ef7e06SGarrett D'Amore 
422*49ef7e06SGarrett D'Amore 	__checkReturn		efx_rc_t
efx_bist_enable_offline(__in efx_nic_t * enp)423*49ef7e06SGarrett D'Amore efx_bist_enable_offline(
424*49ef7e06SGarrett D'Amore 	__in			efx_nic_t *enp)
425*49ef7e06SGarrett D'Amore {
426*49ef7e06SGarrett D'Amore 	efx_port_t *epp = &(enp->en_port);
427*49ef7e06SGarrett D'Amore 	const efx_phy_ops_t *epop = epp->ep_epop;
428*49ef7e06SGarrett D'Amore 	efx_rc_t rc;
429*49ef7e06SGarrett D'Amore 
430*49ef7e06SGarrett D'Amore 	EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
431*49ef7e06SGarrett D'Amore 
432*49ef7e06SGarrett D'Amore 	if (epop->epo_bist_enable_offline == NULL) {
433*49ef7e06SGarrett D'Amore 		rc = ENOTSUP;
434*49ef7e06SGarrett D'Amore 		goto fail1;
435*49ef7e06SGarrett D'Amore 	}
436*49ef7e06SGarrett D'Amore 
437*49ef7e06SGarrett D'Amore 	if ((rc = epop->epo_bist_enable_offline(enp)) != 0)
438*49ef7e06SGarrett D'Amore 		goto fail2;
439*49ef7e06SGarrett D'Amore 
440*49ef7e06SGarrett D'Amore 	return (0);
441*49ef7e06SGarrett D'Amore 
442*49ef7e06SGarrett D'Amore fail2:
443*49ef7e06SGarrett D'Amore 	EFSYS_PROBE(fail2);
444*49ef7e06SGarrett D'Amore fail1:
445*49ef7e06SGarrett D'Amore 	EFSYS_PROBE1(fail1, efx_rc_t, rc);
446*49ef7e06SGarrett D'Amore 
447*49ef7e06SGarrett D'Amore 	return (rc);
448*49ef7e06SGarrett D'Amore 
449*49ef7e06SGarrett D'Amore }
450*49ef7e06SGarrett D'Amore 
451*49ef7e06SGarrett D'Amore 	__checkReturn		efx_rc_t
efx_bist_start(__in efx_nic_t * enp,__in efx_bist_type_t type)452*49ef7e06SGarrett D'Amore efx_bist_start(
453*49ef7e06SGarrett D'Amore 	__in			efx_nic_t *enp,
454*49ef7e06SGarrett D'Amore 	__in			efx_bist_type_t type)
455*49ef7e06SGarrett D'Amore {
456*49ef7e06SGarrett D'Amore 	efx_port_t *epp = &(enp->en_port);
457*49ef7e06SGarrett D'Amore 	const efx_phy_ops_t *epop = epp->ep_epop;
458*49ef7e06SGarrett D'Amore 	efx_rc_t rc;
459*49ef7e06SGarrett D'Amore 
460*49ef7e06SGarrett D'Amore 	EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
461*49ef7e06SGarrett D'Amore 
462*49ef7e06SGarrett D'Amore 	EFSYS_ASSERT3U(type, !=, EFX_BIST_TYPE_UNKNOWN);
463*49ef7e06SGarrett D'Amore 	EFSYS_ASSERT3U(type, <, EFX_BIST_TYPE_NTYPES);
464*49ef7e06SGarrett D'Amore 	EFSYS_ASSERT3U(epp->ep_current_bist, ==, EFX_BIST_TYPE_UNKNOWN);
465*49ef7e06SGarrett D'Amore 
466*49ef7e06SGarrett D'Amore 	if (epop->epo_bist_start == NULL) {
467*49ef7e06SGarrett D'Amore 		rc = ENOTSUP;
468*49ef7e06SGarrett D'Amore 		goto fail1;
469*49ef7e06SGarrett D'Amore 	}
470*49ef7e06SGarrett D'Amore 
471*49ef7e06SGarrett D'Amore 	if ((rc = epop->epo_bist_start(enp, type)) != 0)
472*49ef7e06SGarrett D'Amore 		goto fail2;
473*49ef7e06SGarrett D'Amore 
474*49ef7e06SGarrett D'Amore 	epp->ep_current_bist = type;
475*49ef7e06SGarrett D'Amore 
476*49ef7e06SGarrett D'Amore 	return (0);
477*49ef7e06SGarrett D'Amore 
478*49ef7e06SGarrett D'Amore fail2:
479*49ef7e06SGarrett D'Amore 	EFSYS_PROBE(fail2);
480*49ef7e06SGarrett D'Amore fail1:
481*49ef7e06SGarrett D'Amore 	EFSYS_PROBE1(fail1, efx_rc_t, rc);
482*49ef7e06SGarrett D'Amore 
483*49ef7e06SGarrett D'Amore 	return (rc);
484*49ef7e06SGarrett D'Amore }
485*49ef7e06SGarrett D'Amore 
486*49ef7e06SGarrett D'Amore 	__checkReturn		efx_rc_t
efx_bist_poll(__in efx_nic_t * enp,__in efx_bist_type_t type,__out efx_bist_result_t * resultp,__out_opt uint32_t * value_maskp,__out_ecount_opt (count)unsigned long * valuesp,__in size_t count)487*49ef7e06SGarrett D'Amore efx_bist_poll(
488*49ef7e06SGarrett D'Amore 	__in			efx_nic_t *enp,
489*49ef7e06SGarrett D'Amore 	__in			efx_bist_type_t type,
490*49ef7e06SGarrett D'Amore 	__out			efx_bist_result_t *resultp,
491*49ef7e06SGarrett D'Amore 	__out_opt		uint32_t *value_maskp,
492*49ef7e06SGarrett D'Amore 	__out_ecount_opt(count)	unsigned long *valuesp,
493*49ef7e06SGarrett D'Amore 	__in			size_t count)
494*49ef7e06SGarrett D'Amore {
495*49ef7e06SGarrett D'Amore 	efx_port_t *epp = &(enp->en_port);
496*49ef7e06SGarrett D'Amore 	const efx_phy_ops_t *epop = epp->ep_epop;
497*49ef7e06SGarrett D'Amore 	efx_rc_t rc;
498*49ef7e06SGarrett D'Amore 
499*49ef7e06SGarrett D'Amore 	EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
500*49ef7e06SGarrett D'Amore 
501*49ef7e06SGarrett D'Amore 	EFSYS_ASSERT3U(type, !=, EFX_BIST_TYPE_UNKNOWN);
502*49ef7e06SGarrett D'Amore 	EFSYS_ASSERT3U(type, <, EFX_BIST_TYPE_NTYPES);
503*49ef7e06SGarrett D'Amore 	EFSYS_ASSERT3U(epp->ep_current_bist, ==, type);
504*49ef7e06SGarrett D'Amore 
505*49ef7e06SGarrett D'Amore 	EFSYS_ASSERT(epop->epo_bist_poll != NULL);
506*49ef7e06SGarrett D'Amore 	if (epop->epo_bist_poll == NULL) {
507*49ef7e06SGarrett D'Amore 		rc = ENOTSUP;
508*49ef7e06SGarrett D'Amore 		goto fail1;
509*49ef7e06SGarrett D'Amore 	}
510*49ef7e06SGarrett D'Amore 
511*49ef7e06SGarrett D'Amore 	if ((rc = epop->epo_bist_poll(enp, type, resultp, value_maskp,
512*49ef7e06SGarrett D'Amore 	    valuesp, count)) != 0)
513*49ef7e06SGarrett D'Amore 		goto fail2;
514*49ef7e06SGarrett D'Amore 
515*49ef7e06SGarrett D'Amore 	return (0);
516*49ef7e06SGarrett D'Amore 
517*49ef7e06SGarrett D'Amore fail2:
518*49ef7e06SGarrett D'Amore 	EFSYS_PROBE(fail2);
519*49ef7e06SGarrett D'Amore fail1:
520*49ef7e06SGarrett D'Amore 	EFSYS_PROBE1(fail1, efx_rc_t, rc);
521*49ef7e06SGarrett D'Amore 
522*49ef7e06SGarrett D'Amore 	return (rc);
523*49ef7e06SGarrett D'Amore }
524*49ef7e06SGarrett D'Amore 
525*49ef7e06SGarrett D'Amore 			void
efx_bist_stop(__in efx_nic_t * enp,__in efx_bist_type_t type)526*49ef7e06SGarrett D'Amore efx_bist_stop(
527*49ef7e06SGarrett D'Amore 	__in		efx_nic_t *enp,
528*49ef7e06SGarrett D'Amore 	__in		efx_bist_type_t type)
529*49ef7e06SGarrett D'Amore {
530*49ef7e06SGarrett D'Amore 	efx_port_t *epp = &(enp->en_port);
531*49ef7e06SGarrett D'Amore 	const efx_phy_ops_t *epop = epp->ep_epop;
532*49ef7e06SGarrett D'Amore 
533*49ef7e06SGarrett D'Amore 	EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
534*49ef7e06SGarrett D'Amore 
535*49ef7e06SGarrett D'Amore 	EFSYS_ASSERT3U(type, !=, EFX_BIST_TYPE_UNKNOWN);
536*49ef7e06SGarrett D'Amore 	EFSYS_ASSERT3U(type, <, EFX_BIST_TYPE_NTYPES);
537*49ef7e06SGarrett D'Amore 	EFSYS_ASSERT3U(epp->ep_current_bist, ==, type);
538*49ef7e06SGarrett D'Amore 
539*49ef7e06SGarrett D'Amore 	EFSYS_ASSERT(epop->epo_bist_stop != NULL);
540*49ef7e06SGarrett D'Amore 
541*49ef7e06SGarrett D'Amore 	if (epop->epo_bist_stop != NULL)
542*49ef7e06SGarrett D'Amore 		epop->epo_bist_stop(enp, type);
543*49ef7e06SGarrett D'Amore 
544*49ef7e06SGarrett D'Amore 	epp->ep_current_bist = EFX_BIST_TYPE_UNKNOWN;
545*49ef7e06SGarrett D'Amore }
546*49ef7e06SGarrett D'Amore 
547*49ef7e06SGarrett D'Amore #endif	/* EFSYS_OPT_BIST */
548*49ef7e06SGarrett D'Amore 			void
efx_phy_unprobe(__in efx_nic_t * enp)549*49ef7e06SGarrett D'Amore efx_phy_unprobe(
550*49ef7e06SGarrett D'Amore 	__in	efx_nic_t *enp)
551*49ef7e06SGarrett D'Amore {
552*49ef7e06SGarrett D'Amore 	efx_port_t *epp = &(enp->en_port);
553*49ef7e06SGarrett D'Amore 
554*49ef7e06SGarrett D'Amore 	EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
555*49ef7e06SGarrett D'Amore 
556*49ef7e06SGarrett D'Amore 	epp->ep_epop = NULL;
557*49ef7e06SGarrett D'Amore 
558*49ef7e06SGarrett D'Amore 	epp->ep_adv_cap_mask = 0;
559*49ef7e06SGarrett D'Amore 
560*49ef7e06SGarrett D'Amore 	epp->ep_port = 0;
561*49ef7e06SGarrett D'Amore 	epp->ep_phy_type = 0;
562*49ef7e06SGarrett D'Amore }
563