xref: /freebsd/sys/dev/sfxge/common/efx_mac.c (revision 0c909247)
1e948693eSPhilip Paeps /*-
23c838a9fSAndrew Rybchenko  * Copyright (c) 2007-2015 Solarflare Communications Inc.
33c838a9fSAndrew Rybchenko  * All rights reserved.
4e948693eSPhilip Paeps  *
5e948693eSPhilip Paeps  * Redistribution and use in source and binary forms, with or without
63c838a9fSAndrew Rybchenko  * modification, are permitted provided that the following conditions are met:
7e948693eSPhilip Paeps  *
83c838a9fSAndrew Rybchenko  * 1. Redistributions of source code must retain the above copyright notice,
93c838a9fSAndrew Rybchenko  *    this list of conditions and the following disclaimer.
103c838a9fSAndrew Rybchenko  * 2. Redistributions in binary form must reproduce the above copyright notice,
113c838a9fSAndrew Rybchenko  *    this list of conditions and the following disclaimer in the documentation
123c838a9fSAndrew Rybchenko  *    and/or other materials provided with the distribution.
133c838a9fSAndrew Rybchenko  *
143c838a9fSAndrew Rybchenko  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
153c838a9fSAndrew Rybchenko  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
163c838a9fSAndrew Rybchenko  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
173c838a9fSAndrew Rybchenko  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
183c838a9fSAndrew Rybchenko  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
193c838a9fSAndrew Rybchenko  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
203c838a9fSAndrew Rybchenko  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
213c838a9fSAndrew Rybchenko  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
223c838a9fSAndrew Rybchenko  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
233c838a9fSAndrew Rybchenko  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
243c838a9fSAndrew Rybchenko  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
253c838a9fSAndrew Rybchenko  *
263c838a9fSAndrew Rybchenko  * The views and conclusions contained in the software and documentation are
273c838a9fSAndrew Rybchenko  * those of the authors and should not be interpreted as representing official
283c838a9fSAndrew Rybchenko  * policies, either expressed or implied, of the FreeBSD Project.
29e948693eSPhilip Paeps  */
30e948693eSPhilip Paeps 
315dee87d7SPhilip Paeps #include <sys/cdefs.h>
325dee87d7SPhilip Paeps __FBSDID("$FreeBSD$");
335dee87d7SPhilip Paeps 
34e948693eSPhilip Paeps #include "efx.h"
35e948693eSPhilip Paeps #include "efx_impl.h"
36e948693eSPhilip Paeps 
37e75412c9SAndrew Rybchenko #if EFSYS_OPT_SIENA
383c838a9fSAndrew Rybchenko 
39460cb568SAndrew Rybchenko static	__checkReturn	efx_rc_t
405cab4fc7SAndrew Rybchenko siena_mac_multicast_list_set(
413c838a9fSAndrew Rybchenko 	__in		efx_nic_t *enp);
423c838a9fSAndrew Rybchenko 
43e75412c9SAndrew Rybchenko #endif /* EFSYS_OPT_SIENA */
443c838a9fSAndrew Rybchenko 
45e948693eSPhilip Paeps #if EFSYS_OPT_SIENA
46ec831f7fSAndrew Rybchenko static const efx_mac_ops_t	__efx_siena_mac_ops = {
47e948693eSPhilip Paeps 	siena_mac_poll,				/* emo_poll */
48e948693eSPhilip Paeps 	siena_mac_up,				/* emo_up */
493c838a9fSAndrew Rybchenko 	siena_mac_reconfigure,			/* emo_addr_set */
5008c5af79SAndrew Rybchenko 	siena_mac_reconfigure,			/* emo_pdu_set */
51e948693eSPhilip Paeps 	siena_mac_reconfigure,			/* emo_reconfigure */
525cab4fc7SAndrew Rybchenko 	siena_mac_multicast_list_set,		/* emo_multicast_list_set */
533c838a9fSAndrew Rybchenko 	NULL,					/* emo_filter_set_default_rxq */
543c838a9fSAndrew Rybchenko 	NULL,				/* emo_filter_default_rxq_clear */
55e948693eSPhilip Paeps #if EFSYS_OPT_LOOPBACK
56e948693eSPhilip Paeps 	siena_mac_loopback_set,			/* emo_loopback_set */
57e948693eSPhilip Paeps #endif	/* EFSYS_OPT_LOOPBACK */
58e948693eSPhilip Paeps #if EFSYS_OPT_MAC_STATS
593c838a9fSAndrew Rybchenko 	efx_mcdi_mac_stats_upload,		/* emo_stats_upload */
603c838a9fSAndrew Rybchenko 	efx_mcdi_mac_stats_periodic,		/* emo_stats_periodic */
61e948693eSPhilip Paeps 	siena_mac_stats_update			/* emo_stats_update */
62e948693eSPhilip Paeps #endif	/* EFSYS_OPT_MAC_STATS */
63e948693eSPhilip Paeps };
64e948693eSPhilip Paeps #endif	/* EFSYS_OPT_SIENA */
65e948693eSPhilip Paeps 
66c15d6d21SAndrew Rybchenko #if EFSYS_OPT_HUNTINGTON || EFSYS_OPT_MEDFORD
67ec831f7fSAndrew Rybchenko static const efx_mac_ops_t	__efx_ef10_mac_ops = {
68c15d6d21SAndrew Rybchenko 	ef10_mac_poll,				/* emo_poll */
69c15d6d21SAndrew Rybchenko 	ef10_mac_up,				/* emo_up */
70c15d6d21SAndrew Rybchenko 	ef10_mac_addr_set,			/* emo_addr_set */
7108c5af79SAndrew Rybchenko 	ef10_mac_pdu_set,			/* emo_pdu_set */
72c15d6d21SAndrew Rybchenko 	ef10_mac_reconfigure,			/* emo_reconfigure */
73c15d6d21SAndrew Rybchenko 	ef10_mac_multicast_list_set,		/* emo_multicast_list_set */
74c15d6d21SAndrew Rybchenko 	ef10_mac_filter_default_rxq_set,	/* emo_filter_default_rxq_set */
75c15d6d21SAndrew Rybchenko 	ef10_mac_filter_default_rxq_clear,
763c838a9fSAndrew Rybchenko 					/* emo_filter_default_rxq_clear */
773c838a9fSAndrew Rybchenko #if EFSYS_OPT_LOOPBACK
78c15d6d21SAndrew Rybchenko 	ef10_mac_loopback_set,			/* emo_loopback_set */
793c838a9fSAndrew Rybchenko #endif	/* EFSYS_OPT_LOOPBACK */
803c838a9fSAndrew Rybchenko #if EFSYS_OPT_MAC_STATS
813c838a9fSAndrew Rybchenko 	efx_mcdi_mac_stats_upload,		/* emo_stats_upload */
823c838a9fSAndrew Rybchenko 	efx_mcdi_mac_stats_periodic,		/* emo_stats_periodic */
83c15d6d21SAndrew Rybchenko 	ef10_mac_stats_update			/* emo_stats_update */
843c838a9fSAndrew Rybchenko #endif	/* EFSYS_OPT_MAC_STATS */
853c838a9fSAndrew Rybchenko };
86c15d6d21SAndrew Rybchenko #endif	/* EFSYS_OPT_HUNTINGTON || EFSYS_OPT_MEDFORD */
873c838a9fSAndrew Rybchenko 
88e948693eSPhilip Paeps 
89460cb568SAndrew Rybchenko 	__checkReturn			efx_rc_t
90e948693eSPhilip Paeps efx_mac_pdu_set(
91e948693eSPhilip Paeps 	__in				efx_nic_t *enp,
92e948693eSPhilip Paeps 	__in				size_t pdu)
93e948693eSPhilip Paeps {
94e948693eSPhilip Paeps 	efx_port_t *epp = &(enp->en_port);
95ec831f7fSAndrew Rybchenko 	const efx_mac_ops_t *emop = epp->ep_emop;
96e948693eSPhilip Paeps 	uint32_t old_pdu;
97460cb568SAndrew Rybchenko 	efx_rc_t rc;
98e948693eSPhilip Paeps 
99e948693eSPhilip Paeps 	EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
100e948693eSPhilip Paeps 	EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_PORT);
101e948693eSPhilip Paeps 	EFSYS_ASSERT(emop != NULL);
102e948693eSPhilip Paeps 
103e948693eSPhilip Paeps 	if (pdu < EFX_MAC_PDU_MIN) {
104e948693eSPhilip Paeps 		rc = EINVAL;
105e948693eSPhilip Paeps 		goto fail1;
106e948693eSPhilip Paeps 	}
107e948693eSPhilip Paeps 
108e948693eSPhilip Paeps 	if (pdu > EFX_MAC_PDU_MAX) {
109e948693eSPhilip Paeps 		rc = EINVAL;
110e948693eSPhilip Paeps 		goto fail2;
111e948693eSPhilip Paeps 	}
112e948693eSPhilip Paeps 
113e948693eSPhilip Paeps 	old_pdu = epp->ep_mac_pdu;
114e948693eSPhilip Paeps 	epp->ep_mac_pdu = (uint32_t)pdu;
11508c5af79SAndrew Rybchenko 	if ((rc = emop->emo_pdu_set(enp)) != 0)
116e948693eSPhilip Paeps 		goto fail3;
117e948693eSPhilip Paeps 
118e948693eSPhilip Paeps 	return (0);
119e948693eSPhilip Paeps 
120e948693eSPhilip Paeps fail3:
121e948693eSPhilip Paeps 	EFSYS_PROBE(fail3);
122e948693eSPhilip Paeps 
123e948693eSPhilip Paeps 	epp->ep_mac_pdu = old_pdu;
124e948693eSPhilip Paeps 
125e948693eSPhilip Paeps fail2:
126e948693eSPhilip Paeps 	EFSYS_PROBE(fail2);
127e948693eSPhilip Paeps fail1:
128460cb568SAndrew Rybchenko 	EFSYS_PROBE1(fail1, efx_rc_t, rc);
129e948693eSPhilip Paeps 
130e948693eSPhilip Paeps 	return (rc);
131e948693eSPhilip Paeps }
132e948693eSPhilip Paeps 
133460cb568SAndrew Rybchenko 	__checkReturn			efx_rc_t
134e948693eSPhilip Paeps efx_mac_addr_set(
135e948693eSPhilip Paeps 	__in				efx_nic_t *enp,
136e948693eSPhilip Paeps 	__in				uint8_t *addr)
137e948693eSPhilip Paeps {
138e948693eSPhilip Paeps 	efx_port_t *epp = &(enp->en_port);
139ec831f7fSAndrew Rybchenko 	const efx_mac_ops_t *emop = epp->ep_emop;
140e948693eSPhilip Paeps 	uint8_t old_addr[6];
141e948693eSPhilip Paeps 	uint32_t oui;
142460cb568SAndrew Rybchenko 	efx_rc_t rc;
143e948693eSPhilip Paeps 
144e948693eSPhilip Paeps 	EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
145e948693eSPhilip Paeps 	EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_PORT);
146e948693eSPhilip Paeps 
1473c838a9fSAndrew Rybchenko 	if (EFX_MAC_ADDR_IS_MULTICAST(addr)) {
148e948693eSPhilip Paeps 		rc = EINVAL;
149e948693eSPhilip Paeps 		goto fail1;
150e948693eSPhilip Paeps 	}
151e948693eSPhilip Paeps 
152e948693eSPhilip Paeps 	oui = addr[0] << 16 | addr[1] << 8 | addr[2];
153e948693eSPhilip Paeps 	if (oui == 0x000000) {
154e948693eSPhilip Paeps 		rc = EINVAL;
155e948693eSPhilip Paeps 		goto fail2;
156e948693eSPhilip Paeps 	}
157e948693eSPhilip Paeps 
158e948693eSPhilip Paeps 	EFX_MAC_ADDR_COPY(old_addr, epp->ep_mac_addr);
159e948693eSPhilip Paeps 	EFX_MAC_ADDR_COPY(epp->ep_mac_addr, addr);
1603c838a9fSAndrew Rybchenko 	if ((rc = emop->emo_addr_set(enp)) != 0)
161e948693eSPhilip Paeps 		goto fail3;
162e948693eSPhilip Paeps 
163e948693eSPhilip Paeps 	return (0);
164e948693eSPhilip Paeps 
165e948693eSPhilip Paeps fail3:
166e948693eSPhilip Paeps 	EFSYS_PROBE(fail3);
167e948693eSPhilip Paeps 
168e948693eSPhilip Paeps 	EFX_MAC_ADDR_COPY(epp->ep_mac_addr, old_addr);
169e948693eSPhilip Paeps 
170e948693eSPhilip Paeps fail2:
171e948693eSPhilip Paeps 	EFSYS_PROBE(fail2);
172e948693eSPhilip Paeps fail1:
173460cb568SAndrew Rybchenko 	EFSYS_PROBE1(fail1, efx_rc_t, rc);
174e948693eSPhilip Paeps 
175e948693eSPhilip Paeps 	return (rc);
176e948693eSPhilip Paeps }
177e948693eSPhilip Paeps 
178460cb568SAndrew Rybchenko 	__checkReturn			efx_rc_t
179e948693eSPhilip Paeps efx_mac_filter_set(
180e948693eSPhilip Paeps 	__in				efx_nic_t *enp,
1813c838a9fSAndrew Rybchenko 	__in				boolean_t all_unicst,
1823c838a9fSAndrew Rybchenko 	__in				boolean_t mulcst,
1833c838a9fSAndrew Rybchenko 	__in				boolean_t all_mulcst,
184e948693eSPhilip Paeps 	__in				boolean_t brdcst)
185e948693eSPhilip Paeps {
186e948693eSPhilip Paeps 	efx_port_t *epp = &(enp->en_port);
187ec831f7fSAndrew Rybchenko 	const efx_mac_ops_t *emop = epp->ep_emop;
1883c838a9fSAndrew Rybchenko 	boolean_t old_all_unicst;
1893c838a9fSAndrew Rybchenko 	boolean_t old_mulcst;
1903c838a9fSAndrew Rybchenko 	boolean_t old_all_mulcst;
191e948693eSPhilip Paeps 	boolean_t old_brdcst;
192460cb568SAndrew Rybchenko 	efx_rc_t rc;
193e948693eSPhilip Paeps 
194e948693eSPhilip Paeps 	EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
195e948693eSPhilip Paeps 	EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_PORT);
196e948693eSPhilip Paeps 
1973c838a9fSAndrew Rybchenko 	old_all_unicst = epp->ep_all_unicst;
1983c838a9fSAndrew Rybchenko 	old_mulcst = epp->ep_mulcst;
1993c838a9fSAndrew Rybchenko 	old_all_mulcst = epp->ep_all_mulcst;
2003c838a9fSAndrew Rybchenko 	old_brdcst = epp->ep_brdcst;
201e948693eSPhilip Paeps 
2023c838a9fSAndrew Rybchenko 	epp->ep_all_unicst = all_unicst;
2033c838a9fSAndrew Rybchenko 	epp->ep_mulcst = mulcst;
2043c838a9fSAndrew Rybchenko 	epp->ep_all_mulcst = all_mulcst;
205e948693eSPhilip Paeps 	epp->ep_brdcst = brdcst;
206e948693eSPhilip Paeps 
207e948693eSPhilip Paeps 	if ((rc = emop->emo_reconfigure(enp)) != 0)
208e948693eSPhilip Paeps 		goto fail1;
209e948693eSPhilip Paeps 
210e948693eSPhilip Paeps 	return (0);
211e948693eSPhilip Paeps 
212e948693eSPhilip Paeps fail1:
213460cb568SAndrew Rybchenko 	EFSYS_PROBE1(fail1, efx_rc_t, rc);
214e948693eSPhilip Paeps 
2153c838a9fSAndrew Rybchenko 	epp->ep_all_unicst = old_all_unicst;
2163c838a9fSAndrew Rybchenko 	epp->ep_mulcst = old_mulcst;
2173c838a9fSAndrew Rybchenko 	epp->ep_all_mulcst = old_all_mulcst;
218e948693eSPhilip Paeps 	epp->ep_brdcst = old_brdcst;
219e948693eSPhilip Paeps 
220e948693eSPhilip Paeps 	return (rc);
221e948693eSPhilip Paeps }
222e948693eSPhilip Paeps 
223460cb568SAndrew Rybchenko 	__checkReturn			efx_rc_t
224e948693eSPhilip Paeps efx_mac_drain(
225e948693eSPhilip Paeps 	__in				efx_nic_t *enp,
226e948693eSPhilip Paeps 	__in				boolean_t enabled)
227e948693eSPhilip Paeps {
228e948693eSPhilip Paeps 	efx_port_t *epp = &(enp->en_port);
229ec831f7fSAndrew Rybchenko 	const efx_mac_ops_t *emop = epp->ep_emop;
230460cb568SAndrew Rybchenko 	efx_rc_t rc;
231e948693eSPhilip Paeps 
232e948693eSPhilip Paeps 	EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
233e948693eSPhilip Paeps 	EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_PORT);
234e948693eSPhilip Paeps 	EFSYS_ASSERT(emop != NULL);
235e948693eSPhilip Paeps 
236e948693eSPhilip Paeps 	if (epp->ep_mac_drain == enabled)
237e948693eSPhilip Paeps 		return (0);
238e948693eSPhilip Paeps 
239e948693eSPhilip Paeps 	epp->ep_mac_drain = enabled;
240e948693eSPhilip Paeps 
241e948693eSPhilip Paeps 	if ((rc = emop->emo_reconfigure(enp)) != 0)
2420c909247SAndrew Rybchenko 		goto fail1;
243e948693eSPhilip Paeps 
244e948693eSPhilip Paeps 	return (0);
245e948693eSPhilip Paeps 
246e948693eSPhilip Paeps fail1:
247460cb568SAndrew Rybchenko 	EFSYS_PROBE1(fail1, efx_rc_t, rc);
248e948693eSPhilip Paeps 
249e948693eSPhilip Paeps 	return (rc);
250e948693eSPhilip Paeps }
251e948693eSPhilip Paeps 
252460cb568SAndrew Rybchenko 	__checkReturn	efx_rc_t
253e948693eSPhilip Paeps efx_mac_up(
254e948693eSPhilip Paeps 	__in		efx_nic_t *enp,
255e948693eSPhilip Paeps 	__out		boolean_t *mac_upp)
256e948693eSPhilip Paeps {
257e948693eSPhilip Paeps 	efx_port_t *epp = &(enp->en_port);
258ec831f7fSAndrew Rybchenko 	const efx_mac_ops_t *emop = epp->ep_emop;
259460cb568SAndrew Rybchenko 	efx_rc_t rc;
260e948693eSPhilip Paeps 
261e948693eSPhilip Paeps 	EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
262e948693eSPhilip Paeps 	EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_PORT);
263e948693eSPhilip Paeps 
264e948693eSPhilip Paeps 	if ((rc = emop->emo_up(enp, mac_upp)) != 0)
265e948693eSPhilip Paeps 		goto fail1;
266e948693eSPhilip Paeps 
267e948693eSPhilip Paeps 	return (0);
268e948693eSPhilip Paeps 
269e948693eSPhilip Paeps fail1:
270460cb568SAndrew Rybchenko 	EFSYS_PROBE1(fail1, efx_rc_t, rc);
271e948693eSPhilip Paeps 
272e948693eSPhilip Paeps 	return (rc);
273e948693eSPhilip Paeps }
274e948693eSPhilip Paeps 
275460cb568SAndrew Rybchenko 	__checkReturn			efx_rc_t
276e948693eSPhilip Paeps efx_mac_fcntl_set(
277e948693eSPhilip Paeps 	__in				efx_nic_t *enp,
278e948693eSPhilip Paeps 	__in				unsigned int fcntl,
279e948693eSPhilip Paeps 	__in				boolean_t autoneg)
280e948693eSPhilip Paeps {
281e948693eSPhilip Paeps 	efx_port_t *epp = &(enp->en_port);
282ec831f7fSAndrew Rybchenko 	const efx_mac_ops_t *emop = epp->ep_emop;
283ec831f7fSAndrew Rybchenko 	const efx_phy_ops_t *epop = epp->ep_epop;
284e948693eSPhilip Paeps 	unsigned int old_fcntl;
285e948693eSPhilip Paeps 	boolean_t old_autoneg;
286e948693eSPhilip Paeps 	unsigned int old_adv_cap;
287460cb568SAndrew Rybchenko 	efx_rc_t rc;
288e948693eSPhilip Paeps 
289e948693eSPhilip Paeps 	EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
290e948693eSPhilip Paeps 	EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_PORT);
291e948693eSPhilip Paeps 
292e948693eSPhilip Paeps 	if ((fcntl & ~(EFX_FCNTL_RESPOND | EFX_FCNTL_GENERATE)) != 0) {
293e948693eSPhilip Paeps 		rc = EINVAL;
294e948693eSPhilip Paeps 		goto fail1;
295e948693eSPhilip Paeps 	}
296e948693eSPhilip Paeps 
297e948693eSPhilip Paeps 	/*
2983c838a9fSAndrew Rybchenko 	 * Ignore a request to set flow control auto-negotiation
299e948693eSPhilip Paeps 	 * if the PHY doesn't support it.
300e948693eSPhilip Paeps 	 */
301e948693eSPhilip Paeps 	if (~epp->ep_phy_cap_mask & (1 << EFX_PHY_CAP_AN))
302e948693eSPhilip Paeps 		autoneg = B_FALSE;
303e948693eSPhilip Paeps 
304e948693eSPhilip Paeps 	old_fcntl = epp->ep_fcntl;
3053c838a9fSAndrew Rybchenko 	old_autoneg = epp->ep_fcntl_autoneg;
306e948693eSPhilip Paeps 	old_adv_cap = epp->ep_adv_cap_mask;
307e948693eSPhilip Paeps 
308e948693eSPhilip Paeps 	epp->ep_fcntl = fcntl;
309e948693eSPhilip Paeps 	epp->ep_fcntl_autoneg = autoneg;
310e948693eSPhilip Paeps 
311e948693eSPhilip Paeps 	/*
3123c838a9fSAndrew Rybchenko 	 * Always encode the flow control settings in the advertised
3133c838a9fSAndrew Rybchenko 	 * capabilities even if we are not trying to auto-negotiate
3143c838a9fSAndrew Rybchenko 	 * them and reconfigure both the PHY and the MAC.
315e948693eSPhilip Paeps 	 */
316e948693eSPhilip Paeps 	if (fcntl & EFX_FCNTL_RESPOND)
317e948693eSPhilip Paeps 		epp->ep_adv_cap_mask |=    (1 << EFX_PHY_CAP_PAUSE |
318e948693eSPhilip Paeps 					    1 << EFX_PHY_CAP_ASYM);
319e948693eSPhilip Paeps 	else
320e948693eSPhilip Paeps 		epp->ep_adv_cap_mask &=   ~(1 << EFX_PHY_CAP_PAUSE |
321e948693eSPhilip Paeps 					    1 << EFX_PHY_CAP_ASYM);
322e948693eSPhilip Paeps 
323e948693eSPhilip Paeps 	if (fcntl & EFX_FCNTL_GENERATE)
324e948693eSPhilip Paeps 		epp->ep_adv_cap_mask ^= (1 << EFX_PHY_CAP_ASYM);
325e948693eSPhilip Paeps 
326e948693eSPhilip Paeps 	if ((rc = epop->epo_reconfigure(enp)) != 0)
327e948693eSPhilip Paeps 		goto fail2;
328e948693eSPhilip Paeps 
329e948693eSPhilip Paeps 	if ((rc = emop->emo_reconfigure(enp)) != 0)
3303c838a9fSAndrew Rybchenko 		goto fail3;
331e948693eSPhilip Paeps 
332e948693eSPhilip Paeps 	return (0);
333e948693eSPhilip Paeps 
3343c838a9fSAndrew Rybchenko fail3:
3353c838a9fSAndrew Rybchenko 	EFSYS_PROBE(fail3);
3363c838a9fSAndrew Rybchenko 
337e948693eSPhilip Paeps fail2:
338e948693eSPhilip Paeps 	EFSYS_PROBE(fail2);
339e948693eSPhilip Paeps 
340e948693eSPhilip Paeps 	epp->ep_fcntl = old_fcntl;
341e948693eSPhilip Paeps 	epp->ep_fcntl_autoneg = old_autoneg;
342e948693eSPhilip Paeps 	epp->ep_adv_cap_mask = old_adv_cap;
343e948693eSPhilip Paeps 
344e948693eSPhilip Paeps fail1:
345460cb568SAndrew Rybchenko 	EFSYS_PROBE1(fail1, efx_rc_t, rc);
346e948693eSPhilip Paeps 
347e948693eSPhilip Paeps 	return (rc);
348e948693eSPhilip Paeps }
349e948693eSPhilip Paeps 
350e948693eSPhilip Paeps 			void
351e948693eSPhilip Paeps efx_mac_fcntl_get(
352e948693eSPhilip Paeps 	__in		efx_nic_t *enp,
353e948693eSPhilip Paeps 	__out		unsigned int *fcntl_wantedp,
354e948693eSPhilip Paeps 	__out		unsigned int *fcntl_linkp)
355e948693eSPhilip Paeps {
356e948693eSPhilip Paeps 	efx_port_t *epp = &(enp->en_port);
3573c838a9fSAndrew Rybchenko 	unsigned int wanted = 0;
358e948693eSPhilip Paeps 
359e948693eSPhilip Paeps 	EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
360e948693eSPhilip Paeps 	EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_PORT);
361e948693eSPhilip Paeps 
362e948693eSPhilip Paeps 	/*
3633c838a9fSAndrew Rybchenko 	 * Decode the requested flow control settings from the PHY
3643c838a9fSAndrew Rybchenko 	 * advertised capabilities.
365e948693eSPhilip Paeps 	 */
366e948693eSPhilip Paeps 	if (epp->ep_adv_cap_mask & (1 << EFX_PHY_CAP_PAUSE))
367e948693eSPhilip Paeps 		wanted = EFX_FCNTL_RESPOND | EFX_FCNTL_GENERATE;
368e948693eSPhilip Paeps 	if (epp->ep_adv_cap_mask & (1 << EFX_PHY_CAP_ASYM))
369e948693eSPhilip Paeps 		wanted ^= EFX_FCNTL_GENERATE;
370e948693eSPhilip Paeps 
371e948693eSPhilip Paeps 	*fcntl_linkp = epp->ep_fcntl;
372e948693eSPhilip Paeps 	*fcntl_wantedp = wanted;
373e948693eSPhilip Paeps }
374e948693eSPhilip Paeps 
375460cb568SAndrew Rybchenko 	__checkReturn	efx_rc_t
3763c838a9fSAndrew Rybchenko efx_mac_multicast_list_set(
3773c838a9fSAndrew Rybchenko 	__in				efx_nic_t *enp,
3783c838a9fSAndrew Rybchenko 	__in_ecount(6*count)		uint8_t const *addrs,
3793c838a9fSAndrew Rybchenko 	__in				int count)
3803c838a9fSAndrew Rybchenko {
3813c838a9fSAndrew Rybchenko 	efx_port_t *epp = &(enp->en_port);
382ec831f7fSAndrew Rybchenko 	const efx_mac_ops_t *emop = epp->ep_emop;
3833c838a9fSAndrew Rybchenko 	uint8_t	*old_mulcst_addr_list = NULL;
3843c838a9fSAndrew Rybchenko 	uint32_t old_mulcst_addr_count;
385460cb568SAndrew Rybchenko 	efx_rc_t rc;
3863c838a9fSAndrew Rybchenko 
3873c838a9fSAndrew Rybchenko 	EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
3883c838a9fSAndrew Rybchenko 	EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_PORT);
3893c838a9fSAndrew Rybchenko 
3903c838a9fSAndrew Rybchenko 	if (count > EFX_MAC_MULTICAST_LIST_MAX) {
3913c838a9fSAndrew Rybchenko 		rc = EINVAL;
3923c838a9fSAndrew Rybchenko 		goto fail1;
3933c838a9fSAndrew Rybchenko 	}
3943c838a9fSAndrew Rybchenko 
3953c838a9fSAndrew Rybchenko 	old_mulcst_addr_count = epp->ep_mulcst_addr_count;
3963c838a9fSAndrew Rybchenko 	if (old_mulcst_addr_count > 0) {
3973c838a9fSAndrew Rybchenko 		/* Allocate memory to store old list (instead of using stack) */
3983c838a9fSAndrew Rybchenko 		EFSYS_KMEM_ALLOC(enp->en_esip,
3993c838a9fSAndrew Rybchenko 				old_mulcst_addr_count * EFX_MAC_ADDR_LEN,
4003c838a9fSAndrew Rybchenko 				old_mulcst_addr_list);
4013c838a9fSAndrew Rybchenko 		if (old_mulcst_addr_list == NULL) {
4023c838a9fSAndrew Rybchenko 			rc = ENOMEM;
4033c838a9fSAndrew Rybchenko 			goto fail2;
4043c838a9fSAndrew Rybchenko 		}
4053c838a9fSAndrew Rybchenko 
4063c838a9fSAndrew Rybchenko 		/* Save the old list in case we need to rollback */
4073c838a9fSAndrew Rybchenko 		memcpy(old_mulcst_addr_list, epp->ep_mulcst_addr_list,
4083c838a9fSAndrew Rybchenko 			old_mulcst_addr_count * EFX_MAC_ADDR_LEN);
4093c838a9fSAndrew Rybchenko 	}
4103c838a9fSAndrew Rybchenko 
4113c838a9fSAndrew Rybchenko 	/* Store the new list */
4123c838a9fSAndrew Rybchenko 	memcpy(epp->ep_mulcst_addr_list, addrs,
4133c838a9fSAndrew Rybchenko 		count * EFX_MAC_ADDR_LEN);
4143c838a9fSAndrew Rybchenko 	epp->ep_mulcst_addr_count = count;
4153c838a9fSAndrew Rybchenko 
4163c838a9fSAndrew Rybchenko 	if ((rc = emop->emo_multicast_list_set(enp)) != 0)
4173c838a9fSAndrew Rybchenko 		goto fail3;
4183c838a9fSAndrew Rybchenko 
4193c838a9fSAndrew Rybchenko 	if (old_mulcst_addr_count > 0) {
4203c838a9fSAndrew Rybchenko 		EFSYS_KMEM_FREE(enp->en_esip,
4213c838a9fSAndrew Rybchenko 				old_mulcst_addr_count * EFX_MAC_ADDR_LEN,
4223c838a9fSAndrew Rybchenko 				old_mulcst_addr_list);
4233c838a9fSAndrew Rybchenko 	}
4243c838a9fSAndrew Rybchenko 
4253c838a9fSAndrew Rybchenko 	return (0);
4263c838a9fSAndrew Rybchenko 
4273c838a9fSAndrew Rybchenko fail3:
4283c838a9fSAndrew Rybchenko 	EFSYS_PROBE(fail3);
4293c838a9fSAndrew Rybchenko 
4303c838a9fSAndrew Rybchenko 	/* Restore original list on failure */
4313c838a9fSAndrew Rybchenko 	epp->ep_mulcst_addr_count = old_mulcst_addr_count;
4323c838a9fSAndrew Rybchenko 	if (old_mulcst_addr_count > 0) {
4333c838a9fSAndrew Rybchenko 		memcpy(epp->ep_mulcst_addr_list, old_mulcst_addr_list,
4343c838a9fSAndrew Rybchenko 			old_mulcst_addr_count * EFX_MAC_ADDR_LEN);
4353c838a9fSAndrew Rybchenko 
4363c838a9fSAndrew Rybchenko 		EFSYS_KMEM_FREE(enp->en_esip,
4373c838a9fSAndrew Rybchenko 				old_mulcst_addr_count * EFX_MAC_ADDR_LEN,
4383c838a9fSAndrew Rybchenko 				old_mulcst_addr_list);
4393c838a9fSAndrew Rybchenko 	}
4403c838a9fSAndrew Rybchenko 
4413c838a9fSAndrew Rybchenko fail2:
4423c838a9fSAndrew Rybchenko 	EFSYS_PROBE(fail2);
4433c838a9fSAndrew Rybchenko 
4443c838a9fSAndrew Rybchenko fail1:
445460cb568SAndrew Rybchenko 	EFSYS_PROBE1(fail1, efx_rc_t, rc);
4463c838a9fSAndrew Rybchenko 
4473c838a9fSAndrew Rybchenko 	return (rc);
4483c838a9fSAndrew Rybchenko 
4493c838a9fSAndrew Rybchenko }
4503c838a9fSAndrew Rybchenko 
451460cb568SAndrew Rybchenko 	__checkReturn	efx_rc_t
4523c838a9fSAndrew Rybchenko efx_mac_filter_default_rxq_set(
4533c838a9fSAndrew Rybchenko 	__in		efx_nic_t *enp,
4543c838a9fSAndrew Rybchenko 	__in		efx_rxq_t *erp,
4553c838a9fSAndrew Rybchenko 	__in		boolean_t using_rss)
4563c838a9fSAndrew Rybchenko {
4573c838a9fSAndrew Rybchenko 	efx_port_t *epp = &(enp->en_port);
458ec831f7fSAndrew Rybchenko 	const efx_mac_ops_t *emop = epp->ep_emop;
459460cb568SAndrew Rybchenko 	efx_rc_t rc;
4603c838a9fSAndrew Rybchenko 
4613c838a9fSAndrew Rybchenko 	EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
4623c838a9fSAndrew Rybchenko 	EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_PORT);
4633c838a9fSAndrew Rybchenko 
4643c838a9fSAndrew Rybchenko 	if (emop->emo_filter_default_rxq_set != NULL) {
4653c838a9fSAndrew Rybchenko 		rc = emop->emo_filter_default_rxq_set(enp, erp, using_rss);
4663c838a9fSAndrew Rybchenko 		if (rc != 0)
4673c838a9fSAndrew Rybchenko 			goto fail1;
4683c838a9fSAndrew Rybchenko 	}
4693c838a9fSAndrew Rybchenko 
4703c838a9fSAndrew Rybchenko 	return (0);
4713c838a9fSAndrew Rybchenko 
4723c838a9fSAndrew Rybchenko fail1:
473460cb568SAndrew Rybchenko 	EFSYS_PROBE1(fail1, efx_rc_t, rc);
4743c838a9fSAndrew Rybchenko 
4753c838a9fSAndrew Rybchenko 	return (rc);
4763c838a9fSAndrew Rybchenko }
4773c838a9fSAndrew Rybchenko 
4783c838a9fSAndrew Rybchenko 			void
4793c838a9fSAndrew Rybchenko efx_mac_filter_default_rxq_clear(
4803c838a9fSAndrew Rybchenko 	__in		efx_nic_t *enp)
4813c838a9fSAndrew Rybchenko {
4823c838a9fSAndrew Rybchenko 	efx_port_t *epp = &(enp->en_port);
483ec831f7fSAndrew Rybchenko 	const efx_mac_ops_t *emop = epp->ep_emop;
4843c838a9fSAndrew Rybchenko 
4853c838a9fSAndrew Rybchenko 	EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
4863c838a9fSAndrew Rybchenko 	EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_PORT);
4873c838a9fSAndrew Rybchenko 
4883c838a9fSAndrew Rybchenko 	if (emop->emo_filter_default_rxq_clear != NULL)
4893c838a9fSAndrew Rybchenko 		emop->emo_filter_default_rxq_clear(enp);
4903c838a9fSAndrew Rybchenko }
4913c838a9fSAndrew Rybchenko 
4923c838a9fSAndrew Rybchenko 
493e948693eSPhilip Paeps #if EFSYS_OPT_MAC_STATS
494e948693eSPhilip Paeps 
495e948693eSPhilip Paeps #if EFSYS_OPT_NAMES
496e948693eSPhilip Paeps 
4973c838a9fSAndrew Rybchenko /* START MKCONFIG GENERATED EfxMacStatNamesBlock 054d43a31d2d7a45 */
4983c838a9fSAndrew Rybchenko static const char 	*__efx_mac_stat_name[] = {
499e948693eSPhilip Paeps 	"rx_octets",
500e948693eSPhilip Paeps 	"rx_pkts",
501e948693eSPhilip Paeps 	"rx_unicst_pkts",
502e948693eSPhilip Paeps 	"rx_multicst_pkts",
503e948693eSPhilip Paeps 	"rx_brdcst_pkts",
504e948693eSPhilip Paeps 	"rx_pause_pkts",
505e948693eSPhilip Paeps 	"rx_le_64_pkts",
506e948693eSPhilip Paeps 	"rx_65_to_127_pkts",
507e948693eSPhilip Paeps 	"rx_128_to_255_pkts",
508e948693eSPhilip Paeps 	"rx_256_to_511_pkts",
509e948693eSPhilip Paeps 	"rx_512_to_1023_pkts",
510e948693eSPhilip Paeps 	"rx_1024_to_15xx_pkts",
511e948693eSPhilip Paeps 	"rx_ge_15xx_pkts",
512e948693eSPhilip Paeps 	"rx_errors",
513e948693eSPhilip Paeps 	"rx_fcs_errors",
514e948693eSPhilip Paeps 	"rx_drop_events",
515e948693eSPhilip Paeps 	"rx_false_carrier_errors",
516e948693eSPhilip Paeps 	"rx_symbol_errors",
517e948693eSPhilip Paeps 	"rx_align_errors",
518e948693eSPhilip Paeps 	"rx_internal_errors",
519e948693eSPhilip Paeps 	"rx_jabber_pkts",
520e948693eSPhilip Paeps 	"rx_lane0_char_err",
521e948693eSPhilip Paeps 	"rx_lane1_char_err",
522e948693eSPhilip Paeps 	"rx_lane2_char_err",
523e948693eSPhilip Paeps 	"rx_lane3_char_err",
524e948693eSPhilip Paeps 	"rx_lane0_disp_err",
525e948693eSPhilip Paeps 	"rx_lane1_disp_err",
526e948693eSPhilip Paeps 	"rx_lane2_disp_err",
527e948693eSPhilip Paeps 	"rx_lane3_disp_err",
528e948693eSPhilip Paeps 	"rx_match_fault",
529e948693eSPhilip Paeps 	"rx_nodesc_drop_cnt",
530e948693eSPhilip Paeps 	"tx_octets",
531e948693eSPhilip Paeps 	"tx_pkts",
532e948693eSPhilip Paeps 	"tx_unicst_pkts",
533e948693eSPhilip Paeps 	"tx_multicst_pkts",
534e948693eSPhilip Paeps 	"tx_brdcst_pkts",
535e948693eSPhilip Paeps 	"tx_pause_pkts",
536e948693eSPhilip Paeps 	"tx_le_64_pkts",
537e948693eSPhilip Paeps 	"tx_65_to_127_pkts",
538e948693eSPhilip Paeps 	"tx_128_to_255_pkts",
539e948693eSPhilip Paeps 	"tx_256_to_511_pkts",
540e948693eSPhilip Paeps 	"tx_512_to_1023_pkts",
541e948693eSPhilip Paeps 	"tx_1024_to_15xx_pkts",
542e948693eSPhilip Paeps 	"tx_ge_15xx_pkts",
543e948693eSPhilip Paeps 	"tx_errors",
544e948693eSPhilip Paeps 	"tx_sgl_col_pkts",
545e948693eSPhilip Paeps 	"tx_mult_col_pkts",
546e948693eSPhilip Paeps 	"tx_ex_col_pkts",
547e948693eSPhilip Paeps 	"tx_late_col_pkts",
548e948693eSPhilip Paeps 	"tx_def_pkts",
549e948693eSPhilip Paeps 	"tx_ex_def_pkts",
5503c838a9fSAndrew Rybchenko 	"pm_trunc_bb_overflow",
5513c838a9fSAndrew Rybchenko 	"pm_discard_bb_overflow",
5523c838a9fSAndrew Rybchenko 	"pm_trunc_vfifo_full",
5533c838a9fSAndrew Rybchenko 	"pm_discard_vfifo_full",
5543c838a9fSAndrew Rybchenko 	"pm_trunc_qbb",
5553c838a9fSAndrew Rybchenko 	"pm_discard_qbb",
5563c838a9fSAndrew Rybchenko 	"pm_discard_mapping",
5573c838a9fSAndrew Rybchenko 	"rxdp_q_disabled_pkts",
5583c838a9fSAndrew Rybchenko 	"rxdp_di_dropped_pkts",
5593c838a9fSAndrew Rybchenko 	"rxdp_streaming_pkts",
5603c838a9fSAndrew Rybchenko 	"rxdp_hlb_fetch",
5613c838a9fSAndrew Rybchenko 	"rxdp_hlb_wait",
5623c838a9fSAndrew Rybchenko 	"vadapter_rx_unicast_packets",
5633c838a9fSAndrew Rybchenko 	"vadapter_rx_unicast_bytes",
5643c838a9fSAndrew Rybchenko 	"vadapter_rx_multicast_packets",
5653c838a9fSAndrew Rybchenko 	"vadapter_rx_multicast_bytes",
5663c838a9fSAndrew Rybchenko 	"vadapter_rx_broadcast_packets",
5673c838a9fSAndrew Rybchenko 	"vadapter_rx_broadcast_bytes",
5683c838a9fSAndrew Rybchenko 	"vadapter_rx_bad_packets",
5693c838a9fSAndrew Rybchenko 	"vadapter_rx_bad_bytes",
5703c838a9fSAndrew Rybchenko 	"vadapter_rx_overflow",
5713c838a9fSAndrew Rybchenko 	"vadapter_tx_unicast_packets",
5723c838a9fSAndrew Rybchenko 	"vadapter_tx_unicast_bytes",
5733c838a9fSAndrew Rybchenko 	"vadapter_tx_multicast_packets",
5743c838a9fSAndrew Rybchenko 	"vadapter_tx_multicast_bytes",
5753c838a9fSAndrew Rybchenko 	"vadapter_tx_broadcast_packets",
5763c838a9fSAndrew Rybchenko 	"vadapter_tx_broadcast_bytes",
5773c838a9fSAndrew Rybchenko 	"vadapter_tx_bad_packets",
5783c838a9fSAndrew Rybchenko 	"vadapter_tx_bad_bytes",
5793c838a9fSAndrew Rybchenko 	"vadapter_tx_overflow",
580e948693eSPhilip Paeps };
581e948693eSPhilip Paeps /* END MKCONFIG GENERATED EfxMacStatNamesBlock */
582e948693eSPhilip Paeps 
5833c838a9fSAndrew Rybchenko 	__checkReturn			const char *
584e948693eSPhilip Paeps efx_mac_stat_name(
585e948693eSPhilip Paeps 	__in				efx_nic_t *enp,
586e948693eSPhilip Paeps 	__in				unsigned int id)
587e948693eSPhilip Paeps {
588e948693eSPhilip Paeps 	_NOTE(ARGUNUSED(enp))
589e948693eSPhilip Paeps 	EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
590e948693eSPhilip Paeps 
591e948693eSPhilip Paeps 	EFSYS_ASSERT3U(id, <, EFX_MAC_NSTATS);
592e948693eSPhilip Paeps 	return (__efx_mac_stat_name[id]);
593e948693eSPhilip Paeps }
594e948693eSPhilip Paeps 
5953c838a9fSAndrew Rybchenko #endif	/* EFSYS_OPT_NAMES */
596e948693eSPhilip Paeps 
597460cb568SAndrew Rybchenko 	__checkReturn			efx_rc_t
598e948693eSPhilip Paeps efx_mac_stats_upload(
599e948693eSPhilip Paeps 	__in				efx_nic_t *enp,
600e948693eSPhilip Paeps 	__in				efsys_mem_t *esmp)
601e948693eSPhilip Paeps {
602e948693eSPhilip Paeps 	efx_port_t *epp = &(enp->en_port);
603ec831f7fSAndrew Rybchenko 	const efx_mac_ops_t *emop = epp->ep_emop;
604460cb568SAndrew Rybchenko 	efx_rc_t rc;
605e948693eSPhilip Paeps 
606e948693eSPhilip Paeps 	EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
607e948693eSPhilip Paeps 	EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_PORT);
608e948693eSPhilip Paeps 	EFSYS_ASSERT(emop != NULL);
609e948693eSPhilip Paeps 
610e948693eSPhilip Paeps 	/*
611e948693eSPhilip Paeps 	 * Don't assert !ep_mac_stats_pending, because the client might
612e948693eSPhilip Paeps 	 * have failed to finalise statistics when previously stopping
613e948693eSPhilip Paeps 	 * the port.
614e948693eSPhilip Paeps 	 */
615e948693eSPhilip Paeps 	if ((rc = emop->emo_stats_upload(enp, esmp)) != 0)
616e948693eSPhilip Paeps 		goto fail1;
617e948693eSPhilip Paeps 
618e948693eSPhilip Paeps 	epp->ep_mac_stats_pending = B_TRUE;
619e948693eSPhilip Paeps 
620e948693eSPhilip Paeps 	return (0);
621e948693eSPhilip Paeps 
622e948693eSPhilip Paeps fail1:
623460cb568SAndrew Rybchenko 	EFSYS_PROBE1(fail1, efx_rc_t, rc);
624e948693eSPhilip Paeps 
625e948693eSPhilip Paeps 	return (rc);
626e948693eSPhilip Paeps }
627e948693eSPhilip Paeps 
628460cb568SAndrew Rybchenko 	__checkReturn			efx_rc_t
629e948693eSPhilip Paeps efx_mac_stats_periodic(
630e948693eSPhilip Paeps 	__in				efx_nic_t *enp,
631e948693eSPhilip Paeps 	__in				efsys_mem_t *esmp,
632e948693eSPhilip Paeps 	__in				uint16_t period_ms,
633e948693eSPhilip Paeps 	__in				boolean_t events)
634e948693eSPhilip Paeps {
635e948693eSPhilip Paeps 	efx_port_t *epp = &(enp->en_port);
636ec831f7fSAndrew Rybchenko 	const efx_mac_ops_t *emop = epp->ep_emop;
637460cb568SAndrew Rybchenko 	efx_rc_t rc;
638e948693eSPhilip Paeps 
639e948693eSPhilip Paeps 	EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
640e948693eSPhilip Paeps 	EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_PORT);
641e948693eSPhilip Paeps 
642e948693eSPhilip Paeps 	EFSYS_ASSERT(emop != NULL);
643e948693eSPhilip Paeps 
644e948693eSPhilip Paeps 	if (emop->emo_stats_periodic == NULL) {
645e948693eSPhilip Paeps 		rc = EINVAL;
646e948693eSPhilip Paeps 		goto fail1;
647e948693eSPhilip Paeps 	}
648e948693eSPhilip Paeps 
649e948693eSPhilip Paeps 	if ((rc = emop->emo_stats_periodic(enp, esmp, period_ms, events)) != 0)
650e948693eSPhilip Paeps 		goto fail2;
651e948693eSPhilip Paeps 
652e948693eSPhilip Paeps 	return (0);
653e948693eSPhilip Paeps 
654e948693eSPhilip Paeps fail2:
655e948693eSPhilip Paeps 	EFSYS_PROBE(fail2);
656e948693eSPhilip Paeps fail1:
657460cb568SAndrew Rybchenko 	EFSYS_PROBE1(fail1, efx_rc_t, rc);
658e948693eSPhilip Paeps 
659e948693eSPhilip Paeps 	return (rc);
660e948693eSPhilip Paeps }
661e948693eSPhilip Paeps 
662e948693eSPhilip Paeps 
663460cb568SAndrew Rybchenko 	__checkReturn			efx_rc_t
664e948693eSPhilip Paeps efx_mac_stats_update(
665e948693eSPhilip Paeps 	__in				efx_nic_t *enp,
666e948693eSPhilip Paeps 	__in				efsys_mem_t *esmp,
667e948693eSPhilip Paeps 	__inout_ecount(EFX_MAC_NSTATS)	efsys_stat_t *essp,
66814c3e490SAndrew Rybchenko 	__inout_opt			uint32_t *generationp)
669e948693eSPhilip Paeps {
670e948693eSPhilip Paeps 	efx_port_t *epp = &(enp->en_port);
671ec831f7fSAndrew Rybchenko 	const efx_mac_ops_t *emop = epp->ep_emop;
672460cb568SAndrew Rybchenko 	efx_rc_t rc;
673e948693eSPhilip Paeps 
674e948693eSPhilip Paeps 	EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
675e948693eSPhilip Paeps 	EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_PORT);
676e948693eSPhilip Paeps 	EFSYS_ASSERT(emop != NULL);
677e948693eSPhilip Paeps 
678e948693eSPhilip Paeps 	rc = emop->emo_stats_update(enp, esmp, essp, generationp);
679e948693eSPhilip Paeps 	if (rc == 0)
680e948693eSPhilip Paeps 		epp->ep_mac_stats_pending = B_FALSE;
681e948693eSPhilip Paeps 
682e948693eSPhilip Paeps 	return (rc);
683e948693eSPhilip Paeps }
684e948693eSPhilip Paeps 
685e948693eSPhilip Paeps #endif	/* EFSYS_OPT_MAC_STATS */
686e948693eSPhilip Paeps 
687460cb568SAndrew Rybchenko 	__checkReturn			efx_rc_t
688e948693eSPhilip Paeps efx_mac_select(
689e948693eSPhilip Paeps 	__in				efx_nic_t *enp)
690e948693eSPhilip Paeps {
691e948693eSPhilip Paeps 	efx_port_t *epp = &(enp->en_port);
692e948693eSPhilip Paeps 	efx_mac_type_t type = EFX_MAC_INVALID;
693ec831f7fSAndrew Rybchenko 	const efx_mac_ops_t *emop;
694e948693eSPhilip Paeps 	int rc = EINVAL;
695e948693eSPhilip Paeps 
69695812f27SAndrew Rybchenko 	switch (enp->en_family) {
697c15d6d21SAndrew Rybchenko #if EFSYS_OPT_SIENA
69895812f27SAndrew Rybchenko 	case EFX_FAMILY_SIENA:
69995812f27SAndrew Rybchenko 		emop = &__efx_siena_mac_ops;
700c15d6d21SAndrew Rybchenko 		type = EFX_MAC_SIENA;
70195812f27SAndrew Rybchenko 		break;
70295812f27SAndrew Rybchenko #endif /* EFSYS_OPT_SIENA */
703c15d6d21SAndrew Rybchenko 
7043c838a9fSAndrew Rybchenko #if EFSYS_OPT_HUNTINGTON
70595812f27SAndrew Rybchenko 	case EFX_FAMILY_HUNTINGTON:
70695812f27SAndrew Rybchenko 		emop = &__efx_ef10_mac_ops;
7073c838a9fSAndrew Rybchenko 		type = EFX_MAC_HUNTINGTON;
70895812f27SAndrew Rybchenko 		break;
70995812f27SAndrew Rybchenko #endif /* EFSYS_OPT_HUNTINGTON */
7103c838a9fSAndrew Rybchenko 
711c15d6d21SAndrew Rybchenko #if EFSYS_OPT_MEDFORD
71295812f27SAndrew Rybchenko 	case EFX_FAMILY_MEDFORD:
71395812f27SAndrew Rybchenko 		emop = &__efx_ef10_mac_ops;
714c15d6d21SAndrew Rybchenko 		type = EFX_MAC_MEDFORD;
71595812f27SAndrew Rybchenko 		break;
71695812f27SAndrew Rybchenko #endif /* EFSYS_OPT_MEDFORD */
717e948693eSPhilip Paeps 
71895812f27SAndrew Rybchenko 	default:
71995812f27SAndrew Rybchenko 		rc = EINVAL;
72095812f27SAndrew Rybchenko 		goto fail1;
72195812f27SAndrew Rybchenko 	}
72295812f27SAndrew Rybchenko 
723e948693eSPhilip Paeps 	EFSYS_ASSERT(type != EFX_MAC_INVALID);
724e948693eSPhilip Paeps 	EFSYS_ASSERT3U(type, <, EFX_MAC_NTYPES);
725e948693eSPhilip Paeps 	EFSYS_ASSERT(emop != NULL);
726e948693eSPhilip Paeps 
72795812f27SAndrew Rybchenko 	epp->ep_emop = emop;
728e948693eSPhilip Paeps 	epp->ep_mac_type = type;
729e948693eSPhilip Paeps 
730e948693eSPhilip Paeps 	return (0);
731e948693eSPhilip Paeps 
732e948693eSPhilip Paeps fail1:
733460cb568SAndrew Rybchenko 	EFSYS_PROBE1(fail1, efx_rc_t, rc);
734e948693eSPhilip Paeps 
735e948693eSPhilip Paeps 	return (rc);
736e948693eSPhilip Paeps }
7373c838a9fSAndrew Rybchenko 
7383c838a9fSAndrew Rybchenko 
739e75412c9SAndrew Rybchenko #if EFSYS_OPT_SIENA
7403c838a9fSAndrew Rybchenko 
74174bb0ed8SAndrew Rybchenko #define	EFX_MAC_HASH_BITS	(1 << 8)
74274bb0ed8SAndrew Rybchenko 
7433c838a9fSAndrew Rybchenko /* Compute the multicast hash as used on Falcon and Siena. */
7443c838a9fSAndrew Rybchenko static	void
7455cab4fc7SAndrew Rybchenko siena_mac_multicast_hash_compute(
7463c838a9fSAndrew Rybchenko 	__in_ecount(6*count)		uint8_t const *addrs,
7473c838a9fSAndrew Rybchenko 	__in				int count,
7483c838a9fSAndrew Rybchenko 	__out				efx_oword_t *hash_low,
7493c838a9fSAndrew Rybchenko 	__out				efx_oword_t *hash_high)
7503c838a9fSAndrew Rybchenko {
7513c838a9fSAndrew Rybchenko 	uint32_t crc, index;
7523c838a9fSAndrew Rybchenko 	int i;
7533c838a9fSAndrew Rybchenko 
7543c838a9fSAndrew Rybchenko 	EFSYS_ASSERT(hash_low != NULL);
7553c838a9fSAndrew Rybchenko 	EFSYS_ASSERT(hash_high != NULL);
7563c838a9fSAndrew Rybchenko 
7573c838a9fSAndrew Rybchenko 	EFX_ZERO_OWORD(*hash_low);
7583c838a9fSAndrew Rybchenko 	EFX_ZERO_OWORD(*hash_high);
7593c838a9fSAndrew Rybchenko 
7603c838a9fSAndrew Rybchenko 	for (i = 0; i < count; i++) {
7613c838a9fSAndrew Rybchenko 		/* Calculate hash bucket (IEEE 802.3 CRC32 of the MAC addr) */
7623c838a9fSAndrew Rybchenko 		crc = efx_crc32_calculate(0xffffffff, addrs, EFX_MAC_ADDR_LEN);
7633c838a9fSAndrew Rybchenko 		index = crc % EFX_MAC_HASH_BITS;
7643c838a9fSAndrew Rybchenko 		if (index < 128) {
7653c838a9fSAndrew Rybchenko 			EFX_SET_OWORD_BIT(*hash_low, index);
7663c838a9fSAndrew Rybchenko 		} else {
7673c838a9fSAndrew Rybchenko 			EFX_SET_OWORD_BIT(*hash_high, index - 128);
7683c838a9fSAndrew Rybchenko 		}
7693c838a9fSAndrew Rybchenko 
7703c838a9fSAndrew Rybchenko 		addrs += EFX_MAC_ADDR_LEN;
7713c838a9fSAndrew Rybchenko 	}
7723c838a9fSAndrew Rybchenko }
7733c838a9fSAndrew Rybchenko 
774460cb568SAndrew Rybchenko static	__checkReturn	efx_rc_t
7755cab4fc7SAndrew Rybchenko siena_mac_multicast_list_set(
7763c838a9fSAndrew Rybchenko 	__in		efx_nic_t *enp)
7773c838a9fSAndrew Rybchenko {
7783c838a9fSAndrew Rybchenko 	efx_port_t *epp = &(enp->en_port);
779ec831f7fSAndrew Rybchenko 	const efx_mac_ops_t *emop = epp->ep_emop;
7803c838a9fSAndrew Rybchenko 	efx_oword_t old_hash[2];
781460cb568SAndrew Rybchenko 	efx_rc_t rc;
7823c838a9fSAndrew Rybchenko 
7833c838a9fSAndrew Rybchenko 	EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
7843c838a9fSAndrew Rybchenko 	EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_PORT);
7853c838a9fSAndrew Rybchenko 
7863c838a9fSAndrew Rybchenko 	memcpy(old_hash, epp->ep_multicst_hash, sizeof (old_hash));
7873c838a9fSAndrew Rybchenko 
7885cab4fc7SAndrew Rybchenko 	siena_mac_multicast_hash_compute(
7895cab4fc7SAndrew Rybchenko 	    epp->ep_mulcst_addr_list,
7903c838a9fSAndrew Rybchenko 	    epp->ep_mulcst_addr_count,
7913c838a9fSAndrew Rybchenko 	    &epp->ep_multicst_hash[0],
7923c838a9fSAndrew Rybchenko 	    &epp->ep_multicst_hash[1]);
7933c838a9fSAndrew Rybchenko 
7943c838a9fSAndrew Rybchenko 	if ((rc = emop->emo_reconfigure(enp)) != 0)
7953c838a9fSAndrew Rybchenko 		goto fail1;
7963c838a9fSAndrew Rybchenko 
7973c838a9fSAndrew Rybchenko 	return (0);
7983c838a9fSAndrew Rybchenko 
7993c838a9fSAndrew Rybchenko fail1:
800460cb568SAndrew Rybchenko 	EFSYS_PROBE1(fail1, efx_rc_t, rc);
8013c838a9fSAndrew Rybchenko 
8023c838a9fSAndrew Rybchenko 	memcpy(epp->ep_multicst_hash, old_hash, sizeof (old_hash));
8033c838a9fSAndrew Rybchenko 
8043c838a9fSAndrew Rybchenko 	return (rc);
8053c838a9fSAndrew Rybchenko }
8063c838a9fSAndrew Rybchenko 
807e75412c9SAndrew Rybchenko #endif /* EFSYS_OPT_SIENA */
808