xref: /freebsd/sys/dev/sfxge/common/efx_mac.c (revision ec831f7f)
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
403c838a9fSAndrew Rybchenko falconsiena_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 	NULL,					/* emo_reset */
48e948693eSPhilip Paeps 	siena_mac_poll,				/* emo_poll */
49e948693eSPhilip Paeps 	siena_mac_up,				/* emo_up */
503c838a9fSAndrew Rybchenko 	siena_mac_reconfigure,			/* emo_addr_set */
5108c5af79SAndrew Rybchenko 	siena_mac_reconfigure,			/* emo_pdu_set */
52e948693eSPhilip Paeps 	siena_mac_reconfigure,			/* emo_reconfigure */
533c838a9fSAndrew Rybchenko 	falconsiena_mac_multicast_list_set,	/* emo_multicast_list_set */
543c838a9fSAndrew Rybchenko 	NULL,					/* emo_filter_set_default_rxq */
553c838a9fSAndrew Rybchenko 	NULL,				/* emo_filter_default_rxq_clear */
56e948693eSPhilip Paeps #if EFSYS_OPT_LOOPBACK
57e948693eSPhilip Paeps 	siena_mac_loopback_set,			/* emo_loopback_set */
58e948693eSPhilip Paeps #endif	/* EFSYS_OPT_LOOPBACK */
59e948693eSPhilip Paeps #if EFSYS_OPT_MAC_STATS
603c838a9fSAndrew Rybchenko 	efx_mcdi_mac_stats_upload,		/* emo_stats_upload */
613c838a9fSAndrew Rybchenko 	efx_mcdi_mac_stats_periodic,		/* emo_stats_periodic */
62e948693eSPhilip Paeps 	siena_mac_stats_update			/* emo_stats_update */
63e948693eSPhilip Paeps #endif	/* EFSYS_OPT_MAC_STATS */
64e948693eSPhilip Paeps };
65e948693eSPhilip Paeps #endif	/* EFSYS_OPT_SIENA */
66e948693eSPhilip Paeps 
67c15d6d21SAndrew Rybchenko #if EFSYS_OPT_HUNTINGTON || EFSYS_OPT_MEDFORD
68ec831f7fSAndrew Rybchenko static const efx_mac_ops_t	__efx_ef10_mac_ops = {
693c838a9fSAndrew Rybchenko 	NULL,					/* emo_reset */
70c15d6d21SAndrew Rybchenko 	ef10_mac_poll,				/* emo_poll */
71c15d6d21SAndrew Rybchenko 	ef10_mac_up,				/* emo_up */
72c15d6d21SAndrew Rybchenko 	ef10_mac_addr_set,			/* emo_addr_set */
7308c5af79SAndrew Rybchenko 	ef10_mac_pdu_set,			/* emo_pdu_set */
74c15d6d21SAndrew Rybchenko 	ef10_mac_reconfigure,			/* emo_reconfigure */
75c15d6d21SAndrew Rybchenko 	ef10_mac_multicast_list_set,		/* emo_multicast_list_set */
76c15d6d21SAndrew Rybchenko 	ef10_mac_filter_default_rxq_set,	/* emo_filter_default_rxq_set */
77c15d6d21SAndrew Rybchenko 	ef10_mac_filter_default_rxq_clear,
783c838a9fSAndrew Rybchenko 					/* emo_filter_default_rxq_clear */
793c838a9fSAndrew Rybchenko #if EFSYS_OPT_LOOPBACK
80c15d6d21SAndrew Rybchenko 	ef10_mac_loopback_set,			/* emo_loopback_set */
813c838a9fSAndrew Rybchenko #endif	/* EFSYS_OPT_LOOPBACK */
823c838a9fSAndrew Rybchenko #if EFSYS_OPT_MAC_STATS
833c838a9fSAndrew Rybchenko 	efx_mcdi_mac_stats_upload,		/* emo_stats_upload */
843c838a9fSAndrew Rybchenko 	efx_mcdi_mac_stats_periodic,		/* emo_stats_periodic */
85c15d6d21SAndrew Rybchenko 	ef10_mac_stats_update			/* emo_stats_update */
863c838a9fSAndrew Rybchenko #endif	/* EFSYS_OPT_MAC_STATS */
873c838a9fSAndrew Rybchenko };
88c15d6d21SAndrew Rybchenko #endif	/* EFSYS_OPT_HUNTINGTON || EFSYS_OPT_MEDFORD */
893c838a9fSAndrew Rybchenko 
90e948693eSPhilip Paeps 
91460cb568SAndrew Rybchenko 	__checkReturn			efx_rc_t
92e948693eSPhilip Paeps efx_mac_pdu_set(
93e948693eSPhilip Paeps 	__in				efx_nic_t *enp,
94e948693eSPhilip Paeps 	__in				size_t pdu)
95e948693eSPhilip Paeps {
96e948693eSPhilip Paeps 	efx_port_t *epp = &(enp->en_port);
97ec831f7fSAndrew Rybchenko 	const efx_mac_ops_t *emop = epp->ep_emop;
98e948693eSPhilip Paeps 	uint32_t old_pdu;
99460cb568SAndrew Rybchenko 	efx_rc_t rc;
100e948693eSPhilip Paeps 
101e948693eSPhilip Paeps 	EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
102e948693eSPhilip Paeps 	EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_PORT);
103e948693eSPhilip Paeps 	EFSYS_ASSERT(emop != NULL);
104e948693eSPhilip Paeps 
105e948693eSPhilip Paeps 	if (pdu < EFX_MAC_PDU_MIN) {
106e948693eSPhilip Paeps 		rc = EINVAL;
107e948693eSPhilip Paeps 		goto fail1;
108e948693eSPhilip Paeps 	}
109e948693eSPhilip Paeps 
110e948693eSPhilip Paeps 	if (pdu > EFX_MAC_PDU_MAX) {
111e948693eSPhilip Paeps 		rc = EINVAL;
112e948693eSPhilip Paeps 		goto fail2;
113e948693eSPhilip Paeps 	}
114e948693eSPhilip Paeps 
115e948693eSPhilip Paeps 	old_pdu = epp->ep_mac_pdu;
116e948693eSPhilip Paeps 	epp->ep_mac_pdu = (uint32_t)pdu;
11708c5af79SAndrew Rybchenko 	if ((rc = emop->emo_pdu_set(enp)) != 0)
118e948693eSPhilip Paeps 		goto fail3;
119e948693eSPhilip Paeps 
120e948693eSPhilip Paeps 	return (0);
121e948693eSPhilip Paeps 
122e948693eSPhilip Paeps fail3:
123e948693eSPhilip Paeps 	EFSYS_PROBE(fail3);
124e948693eSPhilip Paeps 
125e948693eSPhilip Paeps 	epp->ep_mac_pdu = old_pdu;
126e948693eSPhilip Paeps 
127e948693eSPhilip Paeps fail2:
128e948693eSPhilip Paeps 	EFSYS_PROBE(fail2);
129e948693eSPhilip Paeps fail1:
130460cb568SAndrew Rybchenko 	EFSYS_PROBE1(fail1, efx_rc_t, rc);
131e948693eSPhilip Paeps 
132e948693eSPhilip Paeps 	return (rc);
133e948693eSPhilip Paeps }
134e948693eSPhilip Paeps 
135460cb568SAndrew Rybchenko 	__checkReturn			efx_rc_t
136e948693eSPhilip Paeps efx_mac_addr_set(
137e948693eSPhilip Paeps 	__in				efx_nic_t *enp,
138e948693eSPhilip Paeps 	__in				uint8_t *addr)
139e948693eSPhilip Paeps {
140e948693eSPhilip Paeps 	efx_port_t *epp = &(enp->en_port);
141ec831f7fSAndrew Rybchenko 	const efx_mac_ops_t *emop = epp->ep_emop;
142e948693eSPhilip Paeps 	uint8_t old_addr[6];
143e948693eSPhilip Paeps 	uint32_t oui;
144460cb568SAndrew Rybchenko 	efx_rc_t rc;
145e948693eSPhilip Paeps 
146e948693eSPhilip Paeps 	EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
147e948693eSPhilip Paeps 	EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_PORT);
148e948693eSPhilip Paeps 
1493c838a9fSAndrew Rybchenko 	if (EFX_MAC_ADDR_IS_MULTICAST(addr)) {
150e948693eSPhilip Paeps 		rc = EINVAL;
151e948693eSPhilip Paeps 		goto fail1;
152e948693eSPhilip Paeps 	}
153e948693eSPhilip Paeps 
154e948693eSPhilip Paeps 	oui = addr[0] << 16 | addr[1] << 8 | addr[2];
155e948693eSPhilip Paeps 	if (oui == 0x000000) {
156e948693eSPhilip Paeps 		rc = EINVAL;
157e948693eSPhilip Paeps 		goto fail2;
158e948693eSPhilip Paeps 	}
159e948693eSPhilip Paeps 
160e948693eSPhilip Paeps 	EFX_MAC_ADDR_COPY(old_addr, epp->ep_mac_addr);
161e948693eSPhilip Paeps 	EFX_MAC_ADDR_COPY(epp->ep_mac_addr, addr);
1623c838a9fSAndrew Rybchenko 	if ((rc = emop->emo_addr_set(enp)) != 0)
163e948693eSPhilip Paeps 		goto fail3;
164e948693eSPhilip Paeps 
165e948693eSPhilip Paeps 	return (0);
166e948693eSPhilip Paeps 
167e948693eSPhilip Paeps fail3:
168e948693eSPhilip Paeps 	EFSYS_PROBE(fail3);
169e948693eSPhilip Paeps 
170e948693eSPhilip Paeps 	EFX_MAC_ADDR_COPY(epp->ep_mac_addr, old_addr);
171e948693eSPhilip Paeps 
172e948693eSPhilip Paeps fail2:
173e948693eSPhilip Paeps 	EFSYS_PROBE(fail2);
174e948693eSPhilip Paeps fail1:
175460cb568SAndrew Rybchenko 	EFSYS_PROBE1(fail1, efx_rc_t, rc);
176e948693eSPhilip Paeps 
177e948693eSPhilip Paeps 	return (rc);
178e948693eSPhilip Paeps }
179e948693eSPhilip Paeps 
180460cb568SAndrew Rybchenko 	__checkReturn			efx_rc_t
181e948693eSPhilip Paeps efx_mac_filter_set(
182e948693eSPhilip Paeps 	__in				efx_nic_t *enp,
1833c838a9fSAndrew Rybchenko 	__in				boolean_t all_unicst,
1843c838a9fSAndrew Rybchenko 	__in				boolean_t mulcst,
1853c838a9fSAndrew Rybchenko 	__in				boolean_t all_mulcst,
186e948693eSPhilip Paeps 	__in				boolean_t brdcst)
187e948693eSPhilip Paeps {
188e948693eSPhilip Paeps 	efx_port_t *epp = &(enp->en_port);
189ec831f7fSAndrew Rybchenko 	const efx_mac_ops_t *emop = epp->ep_emop;
1903c838a9fSAndrew Rybchenko 	boolean_t old_all_unicst;
1913c838a9fSAndrew Rybchenko 	boolean_t old_mulcst;
1923c838a9fSAndrew Rybchenko 	boolean_t old_all_mulcst;
193e948693eSPhilip Paeps 	boolean_t old_brdcst;
194460cb568SAndrew Rybchenko 	efx_rc_t rc;
195e948693eSPhilip Paeps 
196e948693eSPhilip Paeps 	EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
197e948693eSPhilip Paeps 	EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_PORT);
198e948693eSPhilip Paeps 
1993c838a9fSAndrew Rybchenko 	old_all_unicst = epp->ep_all_unicst;
2003c838a9fSAndrew Rybchenko 	old_mulcst = epp->ep_mulcst;
2013c838a9fSAndrew Rybchenko 	old_all_mulcst = epp->ep_all_mulcst;
2023c838a9fSAndrew Rybchenko 	old_brdcst = epp->ep_brdcst;
203e948693eSPhilip Paeps 
2043c838a9fSAndrew Rybchenko 	epp->ep_all_unicst = all_unicst;
2053c838a9fSAndrew Rybchenko 	epp->ep_mulcst = mulcst;
2063c838a9fSAndrew Rybchenko 	epp->ep_all_mulcst = all_mulcst;
207e948693eSPhilip Paeps 	epp->ep_brdcst = brdcst;
208e948693eSPhilip Paeps 
209e948693eSPhilip Paeps 	if ((rc = emop->emo_reconfigure(enp)) != 0)
210e948693eSPhilip Paeps 		goto fail1;
211e948693eSPhilip Paeps 
212e948693eSPhilip Paeps 	return (0);
213e948693eSPhilip Paeps 
214e948693eSPhilip Paeps fail1:
215460cb568SAndrew Rybchenko 	EFSYS_PROBE1(fail1, efx_rc_t, rc);
216e948693eSPhilip Paeps 
2173c838a9fSAndrew Rybchenko 	epp->ep_all_unicst = old_all_unicst;
2183c838a9fSAndrew Rybchenko 	epp->ep_mulcst = old_mulcst;
2193c838a9fSAndrew Rybchenko 	epp->ep_all_mulcst = old_all_mulcst;
220e948693eSPhilip Paeps 	epp->ep_brdcst = old_brdcst;
221e948693eSPhilip Paeps 
222e948693eSPhilip Paeps 	return (rc);
223e948693eSPhilip Paeps }
224e948693eSPhilip Paeps 
225460cb568SAndrew Rybchenko 	__checkReturn			efx_rc_t
226e948693eSPhilip Paeps efx_mac_drain(
227e948693eSPhilip Paeps 	__in				efx_nic_t *enp,
228e948693eSPhilip Paeps 	__in				boolean_t enabled)
229e948693eSPhilip Paeps {
230e948693eSPhilip Paeps 	efx_port_t *epp = &(enp->en_port);
231ec831f7fSAndrew Rybchenko 	const efx_mac_ops_t *emop = epp->ep_emop;
232460cb568SAndrew Rybchenko 	efx_rc_t rc;
233e948693eSPhilip Paeps 
234e948693eSPhilip Paeps 	EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
235e948693eSPhilip Paeps 	EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_PORT);
236e948693eSPhilip Paeps 	EFSYS_ASSERT(emop != NULL);
237e948693eSPhilip Paeps 
238e948693eSPhilip Paeps 	if (epp->ep_mac_drain == enabled)
239e948693eSPhilip Paeps 		return (0);
240e948693eSPhilip Paeps 
241e948693eSPhilip Paeps 	epp->ep_mac_drain = enabled;
242e948693eSPhilip Paeps 
243e948693eSPhilip Paeps 	if (enabled && emop->emo_reset != NULL) {
244e948693eSPhilip Paeps 		if ((rc = emop->emo_reset(enp)) != 0)
245e948693eSPhilip Paeps 			goto fail1;
246e948693eSPhilip Paeps 
247e948693eSPhilip Paeps 		EFSYS_ASSERT(enp->en_reset_flags & EFX_RESET_MAC);
248e948693eSPhilip Paeps 		enp->en_reset_flags &= ~EFX_RESET_PHY;
249e948693eSPhilip Paeps 	}
250e948693eSPhilip Paeps 
251e948693eSPhilip Paeps 	if ((rc = emop->emo_reconfigure(enp)) != 0)
252e948693eSPhilip Paeps 		goto fail2;
253e948693eSPhilip Paeps 
254e948693eSPhilip Paeps 	return (0);
255e948693eSPhilip Paeps 
256e948693eSPhilip Paeps fail2:
257e948693eSPhilip Paeps 	EFSYS_PROBE(fail2);
258e948693eSPhilip Paeps fail1:
259460cb568SAndrew Rybchenko 	EFSYS_PROBE1(fail1, efx_rc_t, rc);
260e948693eSPhilip Paeps 
261e948693eSPhilip Paeps 	return (rc);
262e948693eSPhilip Paeps }
263e948693eSPhilip Paeps 
264460cb568SAndrew Rybchenko 	__checkReturn	efx_rc_t
265e948693eSPhilip Paeps efx_mac_up(
266e948693eSPhilip Paeps 	__in		efx_nic_t *enp,
267e948693eSPhilip Paeps 	__out		boolean_t *mac_upp)
268e948693eSPhilip Paeps {
269e948693eSPhilip Paeps 	efx_port_t *epp = &(enp->en_port);
270ec831f7fSAndrew Rybchenko 	const efx_mac_ops_t *emop = epp->ep_emop;
271460cb568SAndrew Rybchenko 	efx_rc_t rc;
272e948693eSPhilip Paeps 
273e948693eSPhilip Paeps 	EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
274e948693eSPhilip Paeps 	EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_PORT);
275e948693eSPhilip Paeps 
276e948693eSPhilip Paeps 	if ((rc = emop->emo_up(enp, mac_upp)) != 0)
277e948693eSPhilip Paeps 		goto fail1;
278e948693eSPhilip Paeps 
279e948693eSPhilip Paeps 	return (0);
280e948693eSPhilip Paeps 
281e948693eSPhilip Paeps fail1:
282460cb568SAndrew Rybchenko 	EFSYS_PROBE1(fail1, efx_rc_t, rc);
283e948693eSPhilip Paeps 
284e948693eSPhilip Paeps 	return (rc);
285e948693eSPhilip Paeps }
286e948693eSPhilip Paeps 
287460cb568SAndrew Rybchenko 	__checkReturn			efx_rc_t
288e948693eSPhilip Paeps efx_mac_fcntl_set(
289e948693eSPhilip Paeps 	__in				efx_nic_t *enp,
290e948693eSPhilip Paeps 	__in				unsigned int fcntl,
291e948693eSPhilip Paeps 	__in				boolean_t autoneg)
292e948693eSPhilip Paeps {
293e948693eSPhilip Paeps 	efx_port_t *epp = &(enp->en_port);
294ec831f7fSAndrew Rybchenko 	const efx_mac_ops_t *emop = epp->ep_emop;
295ec831f7fSAndrew Rybchenko 	const efx_phy_ops_t *epop = epp->ep_epop;
296e948693eSPhilip Paeps 	unsigned int old_fcntl;
297e948693eSPhilip Paeps 	boolean_t old_autoneg;
298e948693eSPhilip Paeps 	unsigned int old_adv_cap;
299460cb568SAndrew Rybchenko 	efx_rc_t rc;
300e948693eSPhilip Paeps 
301e948693eSPhilip Paeps 	EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
302e948693eSPhilip Paeps 	EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_PORT);
303e948693eSPhilip Paeps 
304e948693eSPhilip Paeps 	if ((fcntl & ~(EFX_FCNTL_RESPOND | EFX_FCNTL_GENERATE)) != 0) {
305e948693eSPhilip Paeps 		rc = EINVAL;
306e948693eSPhilip Paeps 		goto fail1;
307e948693eSPhilip Paeps 	}
308e948693eSPhilip Paeps 
309e948693eSPhilip Paeps 	/*
3103c838a9fSAndrew Rybchenko 	 * Ignore a request to set flow control auto-negotiation
311e948693eSPhilip Paeps 	 * if the PHY doesn't support it.
312e948693eSPhilip Paeps 	 */
313e948693eSPhilip Paeps 	if (~epp->ep_phy_cap_mask & (1 << EFX_PHY_CAP_AN))
314e948693eSPhilip Paeps 		autoneg = B_FALSE;
315e948693eSPhilip Paeps 
316e948693eSPhilip Paeps 	old_fcntl = epp->ep_fcntl;
3173c838a9fSAndrew Rybchenko 	old_autoneg = epp->ep_fcntl_autoneg;
318e948693eSPhilip Paeps 	old_adv_cap = epp->ep_adv_cap_mask;
319e948693eSPhilip Paeps 
320e948693eSPhilip Paeps 	epp->ep_fcntl = fcntl;
321e948693eSPhilip Paeps 	epp->ep_fcntl_autoneg = autoneg;
322e948693eSPhilip Paeps 
323e948693eSPhilip Paeps 	/*
3243c838a9fSAndrew Rybchenko 	 * Always encode the flow control settings in the advertised
3253c838a9fSAndrew Rybchenko 	 * capabilities even if we are not trying to auto-negotiate
3263c838a9fSAndrew Rybchenko 	 * them and reconfigure both the PHY and the MAC.
327e948693eSPhilip Paeps 	 */
328e948693eSPhilip Paeps 	if (fcntl & EFX_FCNTL_RESPOND)
329e948693eSPhilip Paeps 		epp->ep_adv_cap_mask |=    (1 << EFX_PHY_CAP_PAUSE |
330e948693eSPhilip Paeps 					    1 << EFX_PHY_CAP_ASYM);
331e948693eSPhilip Paeps 	else
332e948693eSPhilip Paeps 		epp->ep_adv_cap_mask &=   ~(1 << EFX_PHY_CAP_PAUSE |
333e948693eSPhilip Paeps 					    1 << EFX_PHY_CAP_ASYM);
334e948693eSPhilip Paeps 
335e948693eSPhilip Paeps 	if (fcntl & EFX_FCNTL_GENERATE)
336e948693eSPhilip Paeps 		epp->ep_adv_cap_mask ^= (1 << EFX_PHY_CAP_ASYM);
337e948693eSPhilip Paeps 
338e948693eSPhilip Paeps 	if ((rc = epop->epo_reconfigure(enp)) != 0)
339e948693eSPhilip Paeps 		goto fail2;
340e948693eSPhilip Paeps 
341e948693eSPhilip Paeps 	if ((rc = emop->emo_reconfigure(enp)) != 0)
3423c838a9fSAndrew Rybchenko 		goto fail3;
343e948693eSPhilip Paeps 
344e948693eSPhilip Paeps 	return (0);
345e948693eSPhilip Paeps 
3463c838a9fSAndrew Rybchenko fail3:
3473c838a9fSAndrew Rybchenko 	EFSYS_PROBE(fail3);
3483c838a9fSAndrew Rybchenko 
349e948693eSPhilip Paeps fail2:
350e948693eSPhilip Paeps 	EFSYS_PROBE(fail2);
351e948693eSPhilip Paeps 
352e948693eSPhilip Paeps 	epp->ep_fcntl = old_fcntl;
353e948693eSPhilip Paeps 	epp->ep_fcntl_autoneg = old_autoneg;
354e948693eSPhilip Paeps 	epp->ep_adv_cap_mask = old_adv_cap;
355e948693eSPhilip Paeps 
356e948693eSPhilip Paeps fail1:
357460cb568SAndrew Rybchenko 	EFSYS_PROBE1(fail1, efx_rc_t, rc);
358e948693eSPhilip Paeps 
359e948693eSPhilip Paeps 	return (rc);
360e948693eSPhilip Paeps }
361e948693eSPhilip Paeps 
362e948693eSPhilip Paeps 			void
363e948693eSPhilip Paeps efx_mac_fcntl_get(
364e948693eSPhilip Paeps 	__in		efx_nic_t *enp,
365e948693eSPhilip Paeps 	__out		unsigned int *fcntl_wantedp,
366e948693eSPhilip Paeps 	__out		unsigned int *fcntl_linkp)
367e948693eSPhilip Paeps {
368e948693eSPhilip Paeps 	efx_port_t *epp = &(enp->en_port);
3693c838a9fSAndrew Rybchenko 	unsigned int wanted = 0;
370e948693eSPhilip Paeps 
371e948693eSPhilip Paeps 	EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
372e948693eSPhilip Paeps 	EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_PORT);
373e948693eSPhilip Paeps 
374e948693eSPhilip Paeps 	/*
3753c838a9fSAndrew Rybchenko 	 * Decode the requested flow control settings from the PHY
3763c838a9fSAndrew Rybchenko 	 * advertised capabilities.
377e948693eSPhilip Paeps 	 */
378e948693eSPhilip Paeps 	if (epp->ep_adv_cap_mask & (1 << EFX_PHY_CAP_PAUSE))
379e948693eSPhilip Paeps 		wanted = EFX_FCNTL_RESPOND | EFX_FCNTL_GENERATE;
380e948693eSPhilip Paeps 	if (epp->ep_adv_cap_mask & (1 << EFX_PHY_CAP_ASYM))
381e948693eSPhilip Paeps 		wanted ^= EFX_FCNTL_GENERATE;
382e948693eSPhilip Paeps 
383e948693eSPhilip Paeps 	*fcntl_linkp = epp->ep_fcntl;
384e948693eSPhilip Paeps 	*fcntl_wantedp = wanted;
385e948693eSPhilip Paeps }
386e948693eSPhilip Paeps 
387460cb568SAndrew Rybchenko 	__checkReturn	efx_rc_t
3883c838a9fSAndrew Rybchenko efx_mac_multicast_list_set(
3893c838a9fSAndrew Rybchenko 	__in				efx_nic_t *enp,
3903c838a9fSAndrew Rybchenko 	__in_ecount(6*count)		uint8_t const *addrs,
3913c838a9fSAndrew Rybchenko 	__in				int count)
3923c838a9fSAndrew Rybchenko {
3933c838a9fSAndrew Rybchenko 	efx_port_t *epp = &(enp->en_port);
394ec831f7fSAndrew Rybchenko 	const efx_mac_ops_t *emop = epp->ep_emop;
3953c838a9fSAndrew Rybchenko 	uint8_t	*old_mulcst_addr_list = NULL;
3963c838a9fSAndrew Rybchenko 	uint32_t old_mulcst_addr_count;
397460cb568SAndrew Rybchenko 	efx_rc_t rc;
3983c838a9fSAndrew Rybchenko 
3993c838a9fSAndrew Rybchenko 	EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
4003c838a9fSAndrew Rybchenko 	EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_PORT);
4013c838a9fSAndrew Rybchenko 
4023c838a9fSAndrew Rybchenko 	if (count > EFX_MAC_MULTICAST_LIST_MAX) {
4033c838a9fSAndrew Rybchenko 		rc = EINVAL;
4043c838a9fSAndrew Rybchenko 		goto fail1;
4053c838a9fSAndrew Rybchenko 	}
4063c838a9fSAndrew Rybchenko 
4073c838a9fSAndrew Rybchenko 	old_mulcst_addr_count = epp->ep_mulcst_addr_count;
4083c838a9fSAndrew Rybchenko 	if (old_mulcst_addr_count > 0) {
4093c838a9fSAndrew Rybchenko 		/* Allocate memory to store old list (instead of using stack) */
4103c838a9fSAndrew Rybchenko 		EFSYS_KMEM_ALLOC(enp->en_esip,
4113c838a9fSAndrew Rybchenko 				old_mulcst_addr_count * EFX_MAC_ADDR_LEN,
4123c838a9fSAndrew Rybchenko 				old_mulcst_addr_list);
4133c838a9fSAndrew Rybchenko 		if (old_mulcst_addr_list == NULL) {
4143c838a9fSAndrew Rybchenko 			rc = ENOMEM;
4153c838a9fSAndrew Rybchenko 			goto fail2;
4163c838a9fSAndrew Rybchenko 		}
4173c838a9fSAndrew Rybchenko 
4183c838a9fSAndrew Rybchenko 		/* Save the old list in case we need to rollback */
4193c838a9fSAndrew Rybchenko 		memcpy(old_mulcst_addr_list, epp->ep_mulcst_addr_list,
4203c838a9fSAndrew Rybchenko 			old_mulcst_addr_count * EFX_MAC_ADDR_LEN);
4213c838a9fSAndrew Rybchenko 	}
4223c838a9fSAndrew Rybchenko 
4233c838a9fSAndrew Rybchenko 	/* Store the new list */
4243c838a9fSAndrew Rybchenko 	memcpy(epp->ep_mulcst_addr_list, addrs,
4253c838a9fSAndrew Rybchenko 		count * EFX_MAC_ADDR_LEN);
4263c838a9fSAndrew Rybchenko 	epp->ep_mulcst_addr_count = count;
4273c838a9fSAndrew Rybchenko 
4283c838a9fSAndrew Rybchenko 	if ((rc = emop->emo_multicast_list_set(enp)) != 0)
4293c838a9fSAndrew Rybchenko 		goto fail3;
4303c838a9fSAndrew Rybchenko 
4313c838a9fSAndrew Rybchenko 	if (old_mulcst_addr_count > 0) {
4323c838a9fSAndrew Rybchenko 		EFSYS_KMEM_FREE(enp->en_esip,
4333c838a9fSAndrew Rybchenko 				old_mulcst_addr_count * EFX_MAC_ADDR_LEN,
4343c838a9fSAndrew Rybchenko 				old_mulcst_addr_list);
4353c838a9fSAndrew Rybchenko 	}
4363c838a9fSAndrew Rybchenko 
4373c838a9fSAndrew Rybchenko 	return (0);
4383c838a9fSAndrew Rybchenko 
4393c838a9fSAndrew Rybchenko fail3:
4403c838a9fSAndrew Rybchenko 	EFSYS_PROBE(fail3);
4413c838a9fSAndrew Rybchenko 
4423c838a9fSAndrew Rybchenko 	/* Restore original list on failure */
4433c838a9fSAndrew Rybchenko 	epp->ep_mulcst_addr_count = old_mulcst_addr_count;
4443c838a9fSAndrew Rybchenko 	if (old_mulcst_addr_count > 0) {
4453c838a9fSAndrew Rybchenko 		memcpy(epp->ep_mulcst_addr_list, old_mulcst_addr_list,
4463c838a9fSAndrew Rybchenko 			old_mulcst_addr_count * EFX_MAC_ADDR_LEN);
4473c838a9fSAndrew Rybchenko 
4483c838a9fSAndrew Rybchenko 		EFSYS_KMEM_FREE(enp->en_esip,
4493c838a9fSAndrew Rybchenko 				old_mulcst_addr_count * EFX_MAC_ADDR_LEN,
4503c838a9fSAndrew Rybchenko 				old_mulcst_addr_list);
4513c838a9fSAndrew Rybchenko 	}
4523c838a9fSAndrew Rybchenko 
4533c838a9fSAndrew Rybchenko fail2:
4543c838a9fSAndrew Rybchenko 	EFSYS_PROBE(fail2);
4553c838a9fSAndrew Rybchenko 
4563c838a9fSAndrew Rybchenko fail1:
457460cb568SAndrew Rybchenko 	EFSYS_PROBE1(fail1, efx_rc_t, rc);
4583c838a9fSAndrew Rybchenko 
4593c838a9fSAndrew Rybchenko 	return (rc);
4603c838a9fSAndrew Rybchenko 
4613c838a9fSAndrew Rybchenko }
4623c838a9fSAndrew Rybchenko 
463460cb568SAndrew Rybchenko 	__checkReturn	efx_rc_t
4643c838a9fSAndrew Rybchenko efx_mac_filter_default_rxq_set(
4653c838a9fSAndrew Rybchenko 	__in		efx_nic_t *enp,
4663c838a9fSAndrew Rybchenko 	__in		efx_rxq_t *erp,
4673c838a9fSAndrew Rybchenko 	__in		boolean_t using_rss)
4683c838a9fSAndrew Rybchenko {
4693c838a9fSAndrew Rybchenko 	efx_port_t *epp = &(enp->en_port);
470ec831f7fSAndrew Rybchenko 	const efx_mac_ops_t *emop = epp->ep_emop;
471460cb568SAndrew Rybchenko 	efx_rc_t rc;
4723c838a9fSAndrew Rybchenko 
4733c838a9fSAndrew Rybchenko 	EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
4743c838a9fSAndrew Rybchenko 	EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_PORT);
4753c838a9fSAndrew Rybchenko 
4763c838a9fSAndrew Rybchenko 	if (emop->emo_filter_default_rxq_set != NULL) {
4773c838a9fSAndrew Rybchenko 		rc = emop->emo_filter_default_rxq_set(enp, erp, using_rss);
4783c838a9fSAndrew Rybchenko 		if (rc != 0)
4793c838a9fSAndrew Rybchenko 			goto fail1;
4803c838a9fSAndrew Rybchenko 	}
4813c838a9fSAndrew Rybchenko 
4823c838a9fSAndrew Rybchenko 	return (0);
4833c838a9fSAndrew Rybchenko 
4843c838a9fSAndrew Rybchenko fail1:
485460cb568SAndrew Rybchenko 	EFSYS_PROBE1(fail1, efx_rc_t, rc);
4863c838a9fSAndrew Rybchenko 
4873c838a9fSAndrew Rybchenko 	return (rc);
4883c838a9fSAndrew Rybchenko }
4893c838a9fSAndrew Rybchenko 
4903c838a9fSAndrew Rybchenko 			void
4913c838a9fSAndrew Rybchenko efx_mac_filter_default_rxq_clear(
4923c838a9fSAndrew Rybchenko 	__in		efx_nic_t *enp)
4933c838a9fSAndrew Rybchenko {
4943c838a9fSAndrew Rybchenko 	efx_port_t *epp = &(enp->en_port);
495ec831f7fSAndrew Rybchenko 	const efx_mac_ops_t *emop = epp->ep_emop;
4963c838a9fSAndrew Rybchenko 
4973c838a9fSAndrew Rybchenko 	EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
4983c838a9fSAndrew Rybchenko 	EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_PORT);
4993c838a9fSAndrew Rybchenko 
5003c838a9fSAndrew Rybchenko 	if (emop->emo_filter_default_rxq_clear != NULL)
5013c838a9fSAndrew Rybchenko 		emop->emo_filter_default_rxq_clear(enp);
5023c838a9fSAndrew Rybchenko }
5033c838a9fSAndrew Rybchenko 
5043c838a9fSAndrew Rybchenko 
505e948693eSPhilip Paeps #if EFSYS_OPT_MAC_STATS
506e948693eSPhilip Paeps 
507e948693eSPhilip Paeps #if EFSYS_OPT_NAMES
508e948693eSPhilip Paeps 
5093c838a9fSAndrew Rybchenko /* START MKCONFIG GENERATED EfxMacStatNamesBlock 054d43a31d2d7a45 */
5103c838a9fSAndrew Rybchenko static const char 	*__efx_mac_stat_name[] = {
511e948693eSPhilip Paeps 	"rx_octets",
512e948693eSPhilip Paeps 	"rx_pkts",
513e948693eSPhilip Paeps 	"rx_unicst_pkts",
514e948693eSPhilip Paeps 	"rx_multicst_pkts",
515e948693eSPhilip Paeps 	"rx_brdcst_pkts",
516e948693eSPhilip Paeps 	"rx_pause_pkts",
517e948693eSPhilip Paeps 	"rx_le_64_pkts",
518e948693eSPhilip Paeps 	"rx_65_to_127_pkts",
519e948693eSPhilip Paeps 	"rx_128_to_255_pkts",
520e948693eSPhilip Paeps 	"rx_256_to_511_pkts",
521e948693eSPhilip Paeps 	"rx_512_to_1023_pkts",
522e948693eSPhilip Paeps 	"rx_1024_to_15xx_pkts",
523e948693eSPhilip Paeps 	"rx_ge_15xx_pkts",
524e948693eSPhilip Paeps 	"rx_errors",
525e948693eSPhilip Paeps 	"rx_fcs_errors",
526e948693eSPhilip Paeps 	"rx_drop_events",
527e948693eSPhilip Paeps 	"rx_false_carrier_errors",
528e948693eSPhilip Paeps 	"rx_symbol_errors",
529e948693eSPhilip Paeps 	"rx_align_errors",
530e948693eSPhilip Paeps 	"rx_internal_errors",
531e948693eSPhilip Paeps 	"rx_jabber_pkts",
532e948693eSPhilip Paeps 	"rx_lane0_char_err",
533e948693eSPhilip Paeps 	"rx_lane1_char_err",
534e948693eSPhilip Paeps 	"rx_lane2_char_err",
535e948693eSPhilip Paeps 	"rx_lane3_char_err",
536e948693eSPhilip Paeps 	"rx_lane0_disp_err",
537e948693eSPhilip Paeps 	"rx_lane1_disp_err",
538e948693eSPhilip Paeps 	"rx_lane2_disp_err",
539e948693eSPhilip Paeps 	"rx_lane3_disp_err",
540e948693eSPhilip Paeps 	"rx_match_fault",
541e948693eSPhilip Paeps 	"rx_nodesc_drop_cnt",
542e948693eSPhilip Paeps 	"tx_octets",
543e948693eSPhilip Paeps 	"tx_pkts",
544e948693eSPhilip Paeps 	"tx_unicst_pkts",
545e948693eSPhilip Paeps 	"tx_multicst_pkts",
546e948693eSPhilip Paeps 	"tx_brdcst_pkts",
547e948693eSPhilip Paeps 	"tx_pause_pkts",
548e948693eSPhilip Paeps 	"tx_le_64_pkts",
549e948693eSPhilip Paeps 	"tx_65_to_127_pkts",
550e948693eSPhilip Paeps 	"tx_128_to_255_pkts",
551e948693eSPhilip Paeps 	"tx_256_to_511_pkts",
552e948693eSPhilip Paeps 	"tx_512_to_1023_pkts",
553e948693eSPhilip Paeps 	"tx_1024_to_15xx_pkts",
554e948693eSPhilip Paeps 	"tx_ge_15xx_pkts",
555e948693eSPhilip Paeps 	"tx_errors",
556e948693eSPhilip Paeps 	"tx_sgl_col_pkts",
557e948693eSPhilip Paeps 	"tx_mult_col_pkts",
558e948693eSPhilip Paeps 	"tx_ex_col_pkts",
559e948693eSPhilip Paeps 	"tx_late_col_pkts",
560e948693eSPhilip Paeps 	"tx_def_pkts",
561e948693eSPhilip Paeps 	"tx_ex_def_pkts",
5623c838a9fSAndrew Rybchenko 	"pm_trunc_bb_overflow",
5633c838a9fSAndrew Rybchenko 	"pm_discard_bb_overflow",
5643c838a9fSAndrew Rybchenko 	"pm_trunc_vfifo_full",
5653c838a9fSAndrew Rybchenko 	"pm_discard_vfifo_full",
5663c838a9fSAndrew Rybchenko 	"pm_trunc_qbb",
5673c838a9fSAndrew Rybchenko 	"pm_discard_qbb",
5683c838a9fSAndrew Rybchenko 	"pm_discard_mapping",
5693c838a9fSAndrew Rybchenko 	"rxdp_q_disabled_pkts",
5703c838a9fSAndrew Rybchenko 	"rxdp_di_dropped_pkts",
5713c838a9fSAndrew Rybchenko 	"rxdp_streaming_pkts",
5723c838a9fSAndrew Rybchenko 	"rxdp_hlb_fetch",
5733c838a9fSAndrew Rybchenko 	"rxdp_hlb_wait",
5743c838a9fSAndrew Rybchenko 	"vadapter_rx_unicast_packets",
5753c838a9fSAndrew Rybchenko 	"vadapter_rx_unicast_bytes",
5763c838a9fSAndrew Rybchenko 	"vadapter_rx_multicast_packets",
5773c838a9fSAndrew Rybchenko 	"vadapter_rx_multicast_bytes",
5783c838a9fSAndrew Rybchenko 	"vadapter_rx_broadcast_packets",
5793c838a9fSAndrew Rybchenko 	"vadapter_rx_broadcast_bytes",
5803c838a9fSAndrew Rybchenko 	"vadapter_rx_bad_packets",
5813c838a9fSAndrew Rybchenko 	"vadapter_rx_bad_bytes",
5823c838a9fSAndrew Rybchenko 	"vadapter_rx_overflow",
5833c838a9fSAndrew Rybchenko 	"vadapter_tx_unicast_packets",
5843c838a9fSAndrew Rybchenko 	"vadapter_tx_unicast_bytes",
5853c838a9fSAndrew Rybchenko 	"vadapter_tx_multicast_packets",
5863c838a9fSAndrew Rybchenko 	"vadapter_tx_multicast_bytes",
5873c838a9fSAndrew Rybchenko 	"vadapter_tx_broadcast_packets",
5883c838a9fSAndrew Rybchenko 	"vadapter_tx_broadcast_bytes",
5893c838a9fSAndrew Rybchenko 	"vadapter_tx_bad_packets",
5903c838a9fSAndrew Rybchenko 	"vadapter_tx_bad_bytes",
5913c838a9fSAndrew Rybchenko 	"vadapter_tx_overflow",
592e948693eSPhilip Paeps };
593e948693eSPhilip Paeps /* END MKCONFIG GENERATED EfxMacStatNamesBlock */
594e948693eSPhilip Paeps 
5953c838a9fSAndrew Rybchenko 	__checkReturn			const char *
596e948693eSPhilip Paeps efx_mac_stat_name(
597e948693eSPhilip Paeps 	__in				efx_nic_t *enp,
598e948693eSPhilip Paeps 	__in				unsigned int id)
599e948693eSPhilip Paeps {
600e948693eSPhilip Paeps 	_NOTE(ARGUNUSED(enp))
601e948693eSPhilip Paeps 	EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
602e948693eSPhilip Paeps 
603e948693eSPhilip Paeps 	EFSYS_ASSERT3U(id, <, EFX_MAC_NSTATS);
604e948693eSPhilip Paeps 	return (__efx_mac_stat_name[id]);
605e948693eSPhilip Paeps }
606e948693eSPhilip Paeps 
6073c838a9fSAndrew Rybchenko #endif	/* EFSYS_OPT_NAMES */
608e948693eSPhilip Paeps 
609460cb568SAndrew Rybchenko 	__checkReturn			efx_rc_t
610e948693eSPhilip Paeps efx_mac_stats_upload(
611e948693eSPhilip Paeps 	__in				efx_nic_t *enp,
612e948693eSPhilip Paeps 	__in				efsys_mem_t *esmp)
613e948693eSPhilip Paeps {
614e948693eSPhilip Paeps 	efx_port_t *epp = &(enp->en_port);
615ec831f7fSAndrew Rybchenko 	const efx_mac_ops_t *emop = epp->ep_emop;
616460cb568SAndrew Rybchenko 	efx_rc_t rc;
617e948693eSPhilip Paeps 
618e948693eSPhilip Paeps 	EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
619e948693eSPhilip Paeps 	EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_PORT);
620e948693eSPhilip Paeps 	EFSYS_ASSERT(emop != NULL);
621e948693eSPhilip Paeps 
622e948693eSPhilip Paeps 	/*
623e948693eSPhilip Paeps 	 * Don't assert !ep_mac_stats_pending, because the client might
624e948693eSPhilip Paeps 	 * have failed to finalise statistics when previously stopping
625e948693eSPhilip Paeps 	 * the port.
626e948693eSPhilip Paeps 	 */
627e948693eSPhilip Paeps 	if ((rc = emop->emo_stats_upload(enp, esmp)) != 0)
628e948693eSPhilip Paeps 		goto fail1;
629e948693eSPhilip Paeps 
630e948693eSPhilip Paeps 	epp->ep_mac_stats_pending = B_TRUE;
631e948693eSPhilip Paeps 
632e948693eSPhilip Paeps 	return (0);
633e948693eSPhilip Paeps 
634e948693eSPhilip Paeps fail1:
635460cb568SAndrew Rybchenko 	EFSYS_PROBE1(fail1, efx_rc_t, rc);
636e948693eSPhilip Paeps 
637e948693eSPhilip Paeps 	return (rc);
638e948693eSPhilip Paeps }
639e948693eSPhilip Paeps 
640460cb568SAndrew Rybchenko 	__checkReturn			efx_rc_t
641e948693eSPhilip Paeps efx_mac_stats_periodic(
642e948693eSPhilip Paeps 	__in				efx_nic_t *enp,
643e948693eSPhilip Paeps 	__in				efsys_mem_t *esmp,
644e948693eSPhilip Paeps 	__in				uint16_t period_ms,
645e948693eSPhilip Paeps 	__in				boolean_t events)
646e948693eSPhilip Paeps {
647e948693eSPhilip Paeps 	efx_port_t *epp = &(enp->en_port);
648ec831f7fSAndrew Rybchenko 	const efx_mac_ops_t *emop = epp->ep_emop;
649460cb568SAndrew Rybchenko 	efx_rc_t rc;
650e948693eSPhilip Paeps 
651e948693eSPhilip Paeps 	EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
652e948693eSPhilip Paeps 	EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_PORT);
653e948693eSPhilip Paeps 
654e948693eSPhilip Paeps 	EFSYS_ASSERT(emop != NULL);
655e948693eSPhilip Paeps 
656e948693eSPhilip Paeps 	if (emop->emo_stats_periodic == NULL) {
657e948693eSPhilip Paeps 		rc = EINVAL;
658e948693eSPhilip Paeps 		goto fail1;
659e948693eSPhilip Paeps 	}
660e948693eSPhilip Paeps 
661e948693eSPhilip Paeps 	if ((rc = emop->emo_stats_periodic(enp, esmp, period_ms, events)) != 0)
662e948693eSPhilip Paeps 		goto fail2;
663e948693eSPhilip Paeps 
664e948693eSPhilip Paeps 	return (0);
665e948693eSPhilip Paeps 
666e948693eSPhilip Paeps fail2:
667e948693eSPhilip Paeps 	EFSYS_PROBE(fail2);
668e948693eSPhilip Paeps fail1:
669460cb568SAndrew Rybchenko 	EFSYS_PROBE1(fail1, efx_rc_t, rc);
670e948693eSPhilip Paeps 
671e948693eSPhilip Paeps 	return (rc);
672e948693eSPhilip Paeps }
673e948693eSPhilip Paeps 
674e948693eSPhilip Paeps 
675460cb568SAndrew Rybchenko 	__checkReturn			efx_rc_t
676e948693eSPhilip Paeps efx_mac_stats_update(
677e948693eSPhilip Paeps 	__in				efx_nic_t *enp,
678e948693eSPhilip Paeps 	__in				efsys_mem_t *esmp,
679e948693eSPhilip Paeps 	__inout_ecount(EFX_MAC_NSTATS)	efsys_stat_t *essp,
68014c3e490SAndrew Rybchenko 	__inout_opt			uint32_t *generationp)
681e948693eSPhilip Paeps {
682e948693eSPhilip Paeps 	efx_port_t *epp = &(enp->en_port);
683ec831f7fSAndrew Rybchenko 	const efx_mac_ops_t *emop = epp->ep_emop;
684460cb568SAndrew Rybchenko 	efx_rc_t rc;
685e948693eSPhilip Paeps 
686e948693eSPhilip Paeps 	EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
687e948693eSPhilip Paeps 	EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_PORT);
688e948693eSPhilip Paeps 	EFSYS_ASSERT(emop != NULL);
689e948693eSPhilip Paeps 
690e948693eSPhilip Paeps 	rc = emop->emo_stats_update(enp, esmp, essp, generationp);
691e948693eSPhilip Paeps 	if (rc == 0)
692e948693eSPhilip Paeps 		epp->ep_mac_stats_pending = B_FALSE;
693e948693eSPhilip Paeps 
694e948693eSPhilip Paeps 	return (rc);
695e948693eSPhilip Paeps }
696e948693eSPhilip Paeps 
697e948693eSPhilip Paeps #endif	/* EFSYS_OPT_MAC_STATS */
698e948693eSPhilip Paeps 
699460cb568SAndrew Rybchenko 	__checkReturn			efx_rc_t
700e948693eSPhilip Paeps efx_mac_select(
701e948693eSPhilip Paeps 	__in				efx_nic_t *enp)
702e948693eSPhilip Paeps {
703e948693eSPhilip Paeps 	efx_port_t *epp = &(enp->en_port);
704e948693eSPhilip Paeps 	efx_mac_type_t type = EFX_MAC_INVALID;
705ec831f7fSAndrew Rybchenko 	const efx_mac_ops_t *emop;
706e948693eSPhilip Paeps 	int rc = EINVAL;
707e948693eSPhilip Paeps 
70895812f27SAndrew Rybchenko 	switch (enp->en_family) {
709c15d6d21SAndrew Rybchenko #if EFSYS_OPT_SIENA
71095812f27SAndrew Rybchenko 	case EFX_FAMILY_SIENA:
71195812f27SAndrew Rybchenko 		emop = &__efx_siena_mac_ops;
712c15d6d21SAndrew Rybchenko 		type = EFX_MAC_SIENA;
71395812f27SAndrew Rybchenko 		break;
71495812f27SAndrew Rybchenko #endif /* EFSYS_OPT_SIENA */
715c15d6d21SAndrew Rybchenko 
7163c838a9fSAndrew Rybchenko #if EFSYS_OPT_HUNTINGTON
71795812f27SAndrew Rybchenko 	case EFX_FAMILY_HUNTINGTON:
71895812f27SAndrew Rybchenko 		emop = &__efx_ef10_mac_ops;
7193c838a9fSAndrew Rybchenko 		type = EFX_MAC_HUNTINGTON;
72095812f27SAndrew Rybchenko 		break;
72195812f27SAndrew Rybchenko #endif /* EFSYS_OPT_HUNTINGTON */
7223c838a9fSAndrew Rybchenko 
723c15d6d21SAndrew Rybchenko #if EFSYS_OPT_MEDFORD
72495812f27SAndrew Rybchenko 	case EFX_FAMILY_MEDFORD:
72595812f27SAndrew Rybchenko 		emop = &__efx_ef10_mac_ops;
726c15d6d21SAndrew Rybchenko 		type = EFX_MAC_MEDFORD;
72795812f27SAndrew Rybchenko 		break;
72895812f27SAndrew Rybchenko #endif /* EFSYS_OPT_MEDFORD */
729e948693eSPhilip Paeps 
73095812f27SAndrew Rybchenko 	default:
73195812f27SAndrew Rybchenko 		rc = EINVAL;
73295812f27SAndrew Rybchenko 		goto fail1;
73395812f27SAndrew Rybchenko 	}
73495812f27SAndrew Rybchenko 
735e948693eSPhilip Paeps 	EFSYS_ASSERT(type != EFX_MAC_INVALID);
736e948693eSPhilip Paeps 	EFSYS_ASSERT3U(type, <, EFX_MAC_NTYPES);
737e948693eSPhilip Paeps 	EFSYS_ASSERT(emop != NULL);
738e948693eSPhilip Paeps 
73995812f27SAndrew Rybchenko 	epp->ep_emop = emop;
740e948693eSPhilip Paeps 	epp->ep_mac_type = type;
741e948693eSPhilip Paeps 
742e948693eSPhilip Paeps 	if (emop->emo_reset != NULL) {
743e948693eSPhilip Paeps 		if ((rc = emop->emo_reset(enp)) != 0)
74495812f27SAndrew Rybchenko 			goto fail2;
745e948693eSPhilip Paeps 
746e948693eSPhilip Paeps 		EFSYS_ASSERT(enp->en_reset_flags & EFX_RESET_MAC);
747e948693eSPhilip Paeps 		enp->en_reset_flags &= ~EFX_RESET_MAC;
748e948693eSPhilip Paeps 	}
749e948693eSPhilip Paeps 
750e948693eSPhilip Paeps 	return (0);
751e948693eSPhilip Paeps 
75295812f27SAndrew Rybchenko fail2:
75395812f27SAndrew Rybchenko 	EFSYS_PROBE(fail2);
754e948693eSPhilip Paeps fail1:
755460cb568SAndrew Rybchenko 	EFSYS_PROBE1(fail1, efx_rc_t, rc);
756e948693eSPhilip Paeps 
757e948693eSPhilip Paeps 	return (rc);
758e948693eSPhilip Paeps }
7593c838a9fSAndrew Rybchenko 
7603c838a9fSAndrew Rybchenko 
761e75412c9SAndrew Rybchenko #if EFSYS_OPT_SIENA
7623c838a9fSAndrew Rybchenko 
76374bb0ed8SAndrew Rybchenko #define	EFX_MAC_HASH_BITS	(1 << 8)
76474bb0ed8SAndrew Rybchenko 
7653c838a9fSAndrew Rybchenko /* Compute the multicast hash as used on Falcon and Siena. */
7663c838a9fSAndrew Rybchenko static	void
7673c838a9fSAndrew Rybchenko falconsiena_mac_multicast_hash_compute(
7683c838a9fSAndrew Rybchenko 	__in_ecount(6*count)		uint8_t const *addrs,
7693c838a9fSAndrew Rybchenko 	__in				int count,
7703c838a9fSAndrew Rybchenko 	__out				efx_oword_t *hash_low,
7713c838a9fSAndrew Rybchenko 	__out				efx_oword_t *hash_high)
7723c838a9fSAndrew Rybchenko {
7733c838a9fSAndrew Rybchenko 	uint32_t crc, index;
7743c838a9fSAndrew Rybchenko 	int i;
7753c838a9fSAndrew Rybchenko 
7763c838a9fSAndrew Rybchenko 	EFSYS_ASSERT(hash_low != NULL);
7773c838a9fSAndrew Rybchenko 	EFSYS_ASSERT(hash_high != NULL);
7783c838a9fSAndrew Rybchenko 
7793c838a9fSAndrew Rybchenko 	EFX_ZERO_OWORD(*hash_low);
7803c838a9fSAndrew Rybchenko 	EFX_ZERO_OWORD(*hash_high);
7813c838a9fSAndrew Rybchenko 
7823c838a9fSAndrew Rybchenko 	for (i = 0; i < count; i++) {
7833c838a9fSAndrew Rybchenko 		/* Calculate hash bucket (IEEE 802.3 CRC32 of the MAC addr) */
7843c838a9fSAndrew Rybchenko 		crc = efx_crc32_calculate(0xffffffff, addrs, EFX_MAC_ADDR_LEN);
7853c838a9fSAndrew Rybchenko 		index = crc % EFX_MAC_HASH_BITS;
7863c838a9fSAndrew Rybchenko 		if (index < 128) {
7873c838a9fSAndrew Rybchenko 			EFX_SET_OWORD_BIT(*hash_low, index);
7883c838a9fSAndrew Rybchenko 		} else {
7893c838a9fSAndrew Rybchenko 			EFX_SET_OWORD_BIT(*hash_high, index - 128);
7903c838a9fSAndrew Rybchenko 		}
7913c838a9fSAndrew Rybchenko 
7923c838a9fSAndrew Rybchenko 		addrs += EFX_MAC_ADDR_LEN;
7933c838a9fSAndrew Rybchenko 	}
7943c838a9fSAndrew Rybchenko }
7953c838a9fSAndrew Rybchenko 
796460cb568SAndrew Rybchenko static	__checkReturn	efx_rc_t
7973c838a9fSAndrew Rybchenko falconsiena_mac_multicast_list_set(
7983c838a9fSAndrew Rybchenko 	__in		efx_nic_t *enp)
7993c838a9fSAndrew Rybchenko {
8003c838a9fSAndrew Rybchenko 	efx_port_t *epp = &(enp->en_port);
801ec831f7fSAndrew Rybchenko 	const efx_mac_ops_t *emop = epp->ep_emop;
8023c838a9fSAndrew Rybchenko 	efx_oword_t old_hash[2];
803460cb568SAndrew Rybchenko 	efx_rc_t rc;
8043c838a9fSAndrew Rybchenko 
8053c838a9fSAndrew Rybchenko 	EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
8063c838a9fSAndrew Rybchenko 	EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_PORT);
8073c838a9fSAndrew Rybchenko 
8083c838a9fSAndrew Rybchenko 	memcpy(old_hash, epp->ep_multicst_hash, sizeof (old_hash));
8093c838a9fSAndrew Rybchenko 
8103c838a9fSAndrew Rybchenko 	falconsiena_mac_multicast_hash_compute(epp->ep_mulcst_addr_list,
8113c838a9fSAndrew Rybchenko 				epp->ep_mulcst_addr_count,
8123c838a9fSAndrew Rybchenko 				&epp->ep_multicst_hash[0],
8133c838a9fSAndrew Rybchenko 				&epp->ep_multicst_hash[1]);
8143c838a9fSAndrew Rybchenko 
8153c838a9fSAndrew Rybchenko 	if ((rc = emop->emo_reconfigure(enp)) != 0)
8163c838a9fSAndrew Rybchenko 		goto fail1;
8173c838a9fSAndrew Rybchenko 
8183c838a9fSAndrew Rybchenko 	return (0);
8193c838a9fSAndrew Rybchenko 
8203c838a9fSAndrew Rybchenko fail1:
821460cb568SAndrew Rybchenko 	EFSYS_PROBE1(fail1, efx_rc_t, rc);
8223c838a9fSAndrew Rybchenko 
8233c838a9fSAndrew Rybchenko 	memcpy(epp->ep_multicst_hash, old_hash, sizeof (old_hash));
8243c838a9fSAndrew Rybchenko 
8253c838a9fSAndrew Rybchenko 	return (rc);
8263c838a9fSAndrew Rybchenko }
8273c838a9fSAndrew Rybchenko 
828e75412c9SAndrew Rybchenko #endif /* EFSYS_OPT_SIENA */
829