xref: /freebsd/sys/dev/sfxge/common/ef10_mac.c (revision 685dc743dc3b5645e34836464128e1c0558b404b)
19573ed00SAndrew Rybchenko /*-
2929c7febSAndrew Rybchenko  * Copyright (c) 2012-2016 Solarflare Communications Inc.
39573ed00SAndrew Rybchenko  * All rights reserved.
49573ed00SAndrew Rybchenko  *
59573ed00SAndrew Rybchenko  * Redistribution and use in source and binary forms, with or without
69573ed00SAndrew Rybchenko  * modification, are permitted provided that the following conditions are met:
79573ed00SAndrew Rybchenko  *
89573ed00SAndrew Rybchenko  * 1. Redistributions of source code must retain the above copyright notice,
99573ed00SAndrew Rybchenko  *    this list of conditions and the following disclaimer.
109573ed00SAndrew Rybchenko  * 2. Redistributions in binary form must reproduce the above copyright notice,
119573ed00SAndrew Rybchenko  *    this list of conditions and the following disclaimer in the documentation
129573ed00SAndrew Rybchenko  *    and/or other materials provided with the distribution.
139573ed00SAndrew Rybchenko  *
149573ed00SAndrew Rybchenko  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
159573ed00SAndrew Rybchenko  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
169573ed00SAndrew Rybchenko  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
179573ed00SAndrew Rybchenko  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
189573ed00SAndrew Rybchenko  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
199573ed00SAndrew Rybchenko  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
209573ed00SAndrew Rybchenko  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
219573ed00SAndrew Rybchenko  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
229573ed00SAndrew Rybchenko  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
239573ed00SAndrew Rybchenko  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
249573ed00SAndrew Rybchenko  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
259573ed00SAndrew Rybchenko  *
269573ed00SAndrew Rybchenko  * The views and conclusions contained in the software and documentation are
279573ed00SAndrew Rybchenko  * those of the authors and should not be interpreted as representing official
289573ed00SAndrew Rybchenko  * policies, either expressed or implied, of the FreeBSD Project.
299573ed00SAndrew Rybchenko  */
309573ed00SAndrew Rybchenko 
319573ed00SAndrew Rybchenko #include <sys/cdefs.h>
329573ed00SAndrew Rybchenko #include "efx.h"
339573ed00SAndrew Rybchenko #include "efx_impl.h"
349573ed00SAndrew Rybchenko 
35cbc3f94fSAndrew Rybchenko #if EFSYS_OPT_HUNTINGTON || EFSYS_OPT_MEDFORD || EFSYS_OPT_MEDFORD2
369573ed00SAndrew Rybchenko 
379573ed00SAndrew Rybchenko 	__checkReturn	efx_rc_t
ef10_mac_poll(__in efx_nic_t * enp,__out efx_link_mode_t * link_modep)389573ed00SAndrew Rybchenko ef10_mac_poll(
399573ed00SAndrew Rybchenko 	__in		efx_nic_t *enp,
409573ed00SAndrew Rybchenko 	__out		efx_link_mode_t *link_modep)
419573ed00SAndrew Rybchenko {
429573ed00SAndrew Rybchenko 	efx_port_t *epp = &(enp->en_port);
439573ed00SAndrew Rybchenko 	ef10_link_state_t els;
449573ed00SAndrew Rybchenko 	efx_rc_t rc;
459573ed00SAndrew Rybchenko 
469573ed00SAndrew Rybchenko 	if ((rc = ef10_phy_get_link(enp, &els)) != 0)
479573ed00SAndrew Rybchenko 		goto fail1;
489573ed00SAndrew Rybchenko 
49*cf94ca37SAndrew Rybchenko 	epp->ep_adv_cap_mask = els.epls.epls_adv_cap_mask;
50*cf94ca37SAndrew Rybchenko 	epp->ep_fcntl = els.epls.epls_fcntl;
519573ed00SAndrew Rybchenko 
52*cf94ca37SAndrew Rybchenko 	*link_modep = els.epls.epls_link_mode;
539573ed00SAndrew Rybchenko 
549573ed00SAndrew Rybchenko 	return (0);
559573ed00SAndrew Rybchenko 
569573ed00SAndrew Rybchenko fail1:
579573ed00SAndrew Rybchenko 	EFSYS_PROBE1(fail1, efx_rc_t, rc);
589573ed00SAndrew Rybchenko 
599573ed00SAndrew Rybchenko 	*link_modep = EFX_LINK_UNKNOWN;
609573ed00SAndrew Rybchenko 
619573ed00SAndrew Rybchenko 	return (rc);
629573ed00SAndrew Rybchenko }
639573ed00SAndrew Rybchenko 
649573ed00SAndrew Rybchenko 	__checkReturn	efx_rc_t
ef10_mac_up(__in efx_nic_t * enp,__out boolean_t * mac_upp)659573ed00SAndrew Rybchenko ef10_mac_up(
669573ed00SAndrew Rybchenko 	__in		efx_nic_t *enp,
679573ed00SAndrew Rybchenko 	__out		boolean_t *mac_upp)
689573ed00SAndrew Rybchenko {
699573ed00SAndrew Rybchenko 	ef10_link_state_t els;
709573ed00SAndrew Rybchenko 	efx_rc_t rc;
719573ed00SAndrew Rybchenko 
729573ed00SAndrew Rybchenko 	/*
739573ed00SAndrew Rybchenko 	 * Because EF10 doesn't *require* polling, we can't rely on
749573ed00SAndrew Rybchenko 	 * ef10_mac_poll() being executed to populate epp->ep_mac_up.
759573ed00SAndrew Rybchenko 	 */
769573ed00SAndrew Rybchenko 	if ((rc = ef10_phy_get_link(enp, &els)) != 0)
779573ed00SAndrew Rybchenko 		goto fail1;
789573ed00SAndrew Rybchenko 
799573ed00SAndrew Rybchenko 	*mac_upp = els.els_mac_up;
809573ed00SAndrew Rybchenko 
819573ed00SAndrew Rybchenko 	return (0);
829573ed00SAndrew Rybchenko 
839573ed00SAndrew Rybchenko fail1:
849573ed00SAndrew Rybchenko 	EFSYS_PROBE1(fail1, efx_rc_t, rc);
859573ed00SAndrew Rybchenko 
869573ed00SAndrew Rybchenko 	return (rc);
879573ed00SAndrew Rybchenko }
889573ed00SAndrew Rybchenko 
899573ed00SAndrew Rybchenko /*
909573ed00SAndrew Rybchenko  * EF10 adapters use MC_CMD_VADAPTOR_SET_MAC to set the
919573ed00SAndrew Rybchenko  * MAC address; the address field in MC_CMD_SET_MAC has no
929573ed00SAndrew Rybchenko  * effect.
939573ed00SAndrew Rybchenko  * MC_CMD_VADAPTOR_SET_MAC requires mac-spoofing privilege and
949573ed00SAndrew Rybchenko  * the port to have no filters or queues active.
959573ed00SAndrew Rybchenko  */
969573ed00SAndrew Rybchenko static	__checkReturn	efx_rc_t
efx_mcdi_vadapter_set_mac(__in efx_nic_t * enp)979573ed00SAndrew Rybchenko efx_mcdi_vadapter_set_mac(
989573ed00SAndrew Rybchenko 	__in		efx_nic_t *enp)
999573ed00SAndrew Rybchenko {
1009573ed00SAndrew Rybchenko 	efx_port_t *epp = &(enp->en_port);
1019573ed00SAndrew Rybchenko 	efx_mcdi_req_t req;
102315bbbaaSAndrew Rybchenko 	EFX_MCDI_DECLARE_BUF(payload, MC_CMD_VADAPTOR_SET_MAC_IN_LEN,
103315bbbaaSAndrew Rybchenko 		MC_CMD_VADAPTOR_SET_MAC_OUT_LEN);
1049573ed00SAndrew Rybchenko 	efx_rc_t rc;
1059573ed00SAndrew Rybchenko 
1069573ed00SAndrew Rybchenko 	req.emr_cmd = MC_CMD_VADAPTOR_SET_MAC;
1079573ed00SAndrew Rybchenko 	req.emr_in_buf = payload;
1089573ed00SAndrew Rybchenko 	req.emr_in_length = MC_CMD_VADAPTOR_SET_MAC_IN_LEN;
1099573ed00SAndrew Rybchenko 	req.emr_out_buf = payload;
1109573ed00SAndrew Rybchenko 	req.emr_out_length = MC_CMD_VADAPTOR_SET_MAC_OUT_LEN;
1119573ed00SAndrew Rybchenko 
1129573ed00SAndrew Rybchenko 	MCDI_IN_SET_DWORD(req, VADAPTOR_SET_MAC_IN_UPSTREAM_PORT_ID,
1139573ed00SAndrew Rybchenko 	    enp->en_vport_id);
1149573ed00SAndrew Rybchenko 	EFX_MAC_ADDR_COPY(MCDI_IN2(req, uint8_t, VADAPTOR_SET_MAC_IN_MACADDR),
1159573ed00SAndrew Rybchenko 	    epp->ep_mac_addr);
1169573ed00SAndrew Rybchenko 
1179573ed00SAndrew Rybchenko 	efx_mcdi_execute(enp, &req);
1189573ed00SAndrew Rybchenko 
1199573ed00SAndrew Rybchenko 	if (req.emr_rc != 0) {
1209573ed00SAndrew Rybchenko 		rc = req.emr_rc;
1219573ed00SAndrew Rybchenko 		goto fail1;
1229573ed00SAndrew Rybchenko 	}
1239573ed00SAndrew Rybchenko 
1249573ed00SAndrew Rybchenko 	return (0);
1259573ed00SAndrew Rybchenko 
1269573ed00SAndrew Rybchenko fail1:
1279573ed00SAndrew Rybchenko 	EFSYS_PROBE1(fail1, efx_rc_t, rc);
1289573ed00SAndrew Rybchenko 
1299573ed00SAndrew Rybchenko 	return (rc);
1309573ed00SAndrew Rybchenko }
1319573ed00SAndrew Rybchenko 
1329573ed00SAndrew Rybchenko 	__checkReturn	efx_rc_t
ef10_mac_addr_set(__in efx_nic_t * enp)1339573ed00SAndrew Rybchenko ef10_mac_addr_set(
1349573ed00SAndrew Rybchenko 	__in		efx_nic_t *enp)
1359573ed00SAndrew Rybchenko {
1369573ed00SAndrew Rybchenko 	efx_rc_t rc;
1379573ed00SAndrew Rybchenko 
1389573ed00SAndrew Rybchenko 	if ((rc = efx_mcdi_vadapter_set_mac(enp)) != 0) {
1399573ed00SAndrew Rybchenko 		if (rc != ENOTSUP)
1409573ed00SAndrew Rybchenko 			goto fail1;
1419573ed00SAndrew Rybchenko 
1429573ed00SAndrew Rybchenko 		/*
1439573ed00SAndrew Rybchenko 		 * Fallback for older Huntington firmware without Vadapter
1449573ed00SAndrew Rybchenko 		 * support.
1459573ed00SAndrew Rybchenko 		 */
1469573ed00SAndrew Rybchenko 		if ((rc = ef10_mac_reconfigure(enp)) != 0)
1479573ed00SAndrew Rybchenko 			goto fail2;
1489573ed00SAndrew Rybchenko 	}
1499573ed00SAndrew Rybchenko 
1509573ed00SAndrew Rybchenko 	return (0);
1519573ed00SAndrew Rybchenko 
1529573ed00SAndrew Rybchenko fail2:
1539573ed00SAndrew Rybchenko 	EFSYS_PROBE(fail2);
1549573ed00SAndrew Rybchenko 
1559573ed00SAndrew Rybchenko fail1:
1569573ed00SAndrew Rybchenko 	EFSYS_PROBE1(fail1, efx_rc_t, rc);
1579573ed00SAndrew Rybchenko 
1589573ed00SAndrew Rybchenko 	return (rc);
1599573ed00SAndrew Rybchenko }
1609573ed00SAndrew Rybchenko 
1619573ed00SAndrew Rybchenko static	__checkReturn	efx_rc_t
efx_mcdi_mtu_set(__in efx_nic_t * enp,__in uint32_t mtu)1629573ed00SAndrew Rybchenko efx_mcdi_mtu_set(
1639573ed00SAndrew Rybchenko 	__in		efx_nic_t *enp,
1649573ed00SAndrew Rybchenko 	__in		uint32_t mtu)
1659573ed00SAndrew Rybchenko {
1669573ed00SAndrew Rybchenko 	efx_mcdi_req_t req;
167315bbbaaSAndrew Rybchenko 	EFX_MCDI_DECLARE_BUF(payload, MC_CMD_SET_MAC_EXT_IN_LEN,
168315bbbaaSAndrew Rybchenko 		MC_CMD_SET_MAC_OUT_LEN);
1699573ed00SAndrew Rybchenko 	efx_rc_t rc;
1709573ed00SAndrew Rybchenko 
1719573ed00SAndrew Rybchenko 	req.emr_cmd = MC_CMD_SET_MAC;
1729573ed00SAndrew Rybchenko 	req.emr_in_buf = payload;
1739573ed00SAndrew Rybchenko 	req.emr_in_length = MC_CMD_SET_MAC_EXT_IN_LEN;
1749573ed00SAndrew Rybchenko 	req.emr_out_buf = payload;
1759573ed00SAndrew Rybchenko 	req.emr_out_length = MC_CMD_SET_MAC_OUT_LEN;
1769573ed00SAndrew Rybchenko 
1779573ed00SAndrew Rybchenko 	/* Only configure the MTU in this call to MC_CMD_SET_MAC */
1789573ed00SAndrew Rybchenko 	MCDI_IN_SET_DWORD(req, SET_MAC_EXT_IN_MTU, mtu);
1799573ed00SAndrew Rybchenko 	MCDI_IN_POPULATE_DWORD_1(req, SET_MAC_EXT_IN_CONTROL,
1809573ed00SAndrew Rybchenko 			    SET_MAC_EXT_IN_CFG_MTU, 1);
1819573ed00SAndrew Rybchenko 
1829573ed00SAndrew Rybchenko 	efx_mcdi_execute(enp, &req);
1839573ed00SAndrew Rybchenko 
1849573ed00SAndrew Rybchenko 	if (req.emr_rc != 0) {
1859573ed00SAndrew Rybchenko 		rc = req.emr_rc;
1869573ed00SAndrew Rybchenko 		goto fail1;
1879573ed00SAndrew Rybchenko 	}
1889573ed00SAndrew Rybchenko 
1899573ed00SAndrew Rybchenko 	return (0);
1909573ed00SAndrew Rybchenko 
1919573ed00SAndrew Rybchenko fail1:
1929573ed00SAndrew Rybchenko 	EFSYS_PROBE1(fail1, efx_rc_t, rc);
1939573ed00SAndrew Rybchenko 
1949573ed00SAndrew Rybchenko 	return (rc);
1959573ed00SAndrew Rybchenko }
1969573ed00SAndrew Rybchenko 
197d8484af2SAndrew Rybchenko static	__checkReturn		efx_rc_t
efx_mcdi_mtu_get(__in efx_nic_t * enp,__out size_t * mtu)198d8484af2SAndrew Rybchenko efx_mcdi_mtu_get(
199d8484af2SAndrew Rybchenko 	__in		efx_nic_t *enp,
200d8484af2SAndrew Rybchenko 	__out		size_t *mtu)
201d8484af2SAndrew Rybchenko {
202d8484af2SAndrew Rybchenko 	efx_mcdi_req_t req;
203315bbbaaSAndrew Rybchenko 	EFX_MCDI_DECLARE_BUF(payload, MC_CMD_SET_MAC_EXT_IN_LEN,
204315bbbaaSAndrew Rybchenko 		MC_CMD_SET_MAC_V2_OUT_LEN);
205d8484af2SAndrew Rybchenko 	efx_rc_t rc;
206d8484af2SAndrew Rybchenko 
207d8484af2SAndrew Rybchenko 	req.emr_cmd = MC_CMD_SET_MAC;
208d8484af2SAndrew Rybchenko 	req.emr_in_buf = payload;
209d8484af2SAndrew Rybchenko 	req.emr_in_length = MC_CMD_SET_MAC_EXT_IN_LEN;
210d8484af2SAndrew Rybchenko 	req.emr_out_buf = payload;
211d8484af2SAndrew Rybchenko 	req.emr_out_length = MC_CMD_SET_MAC_V2_OUT_LEN;
212d8484af2SAndrew Rybchenko 
213d8484af2SAndrew Rybchenko 	/*
214d8484af2SAndrew Rybchenko 	 * With MC_CMD_SET_MAC_EXT_IN_CONTROL set to 0, this just queries the
215d8484af2SAndrew Rybchenko 	 * MTU.  This should always be supported on Medford, but it is not
216d8484af2SAndrew Rybchenko 	 * supported on older Huntington firmware.
217d8484af2SAndrew Rybchenko 	 */
218d8484af2SAndrew Rybchenko 	MCDI_IN_SET_DWORD(req, SET_MAC_EXT_IN_CONTROL, 0);
219d8484af2SAndrew Rybchenko 
220d8484af2SAndrew Rybchenko 	efx_mcdi_execute(enp, &req);
221d8484af2SAndrew Rybchenko 
222d8484af2SAndrew Rybchenko 	if (req.emr_rc != 0) {
223d8484af2SAndrew Rybchenko 		rc = req.emr_rc;
224d8484af2SAndrew Rybchenko 		goto fail1;
225d8484af2SAndrew Rybchenko 	}
226d8484af2SAndrew Rybchenko 	if (req.emr_out_length_used < MC_CMD_SET_MAC_V2_OUT_MTU_OFST + 4) {
227d8484af2SAndrew Rybchenko 		rc = EMSGSIZE;
228d8484af2SAndrew Rybchenko 		goto fail2;
229d8484af2SAndrew Rybchenko 	}
230d8484af2SAndrew Rybchenko 
231d8484af2SAndrew Rybchenko 	*mtu = MCDI_OUT_DWORD(req, SET_MAC_V2_OUT_MTU);
232d8484af2SAndrew Rybchenko 
233d8484af2SAndrew Rybchenko 	return (0);
234d8484af2SAndrew Rybchenko 
235d8484af2SAndrew Rybchenko fail2:
236d8484af2SAndrew Rybchenko 	EFSYS_PROBE(fail2);
237d8484af2SAndrew Rybchenko fail1:
238d8484af2SAndrew Rybchenko 	EFSYS_PROBE1(fail1, efx_rc_t, rc);
239d8484af2SAndrew Rybchenko 
240d8484af2SAndrew Rybchenko 	return (rc);
241d8484af2SAndrew Rybchenko }
242d8484af2SAndrew Rybchenko 
2439573ed00SAndrew Rybchenko 	__checkReturn	efx_rc_t
ef10_mac_pdu_set(__in efx_nic_t * enp)2449573ed00SAndrew Rybchenko ef10_mac_pdu_set(
2459573ed00SAndrew Rybchenko 	__in		efx_nic_t *enp)
2469573ed00SAndrew Rybchenko {
2479573ed00SAndrew Rybchenko 	efx_port_t *epp = &(enp->en_port);
2489573ed00SAndrew Rybchenko 	efx_nic_cfg_t *encp = &(enp->en_nic_cfg);
2499573ed00SAndrew Rybchenko 	efx_rc_t rc;
2509573ed00SAndrew Rybchenko 
2519573ed00SAndrew Rybchenko 	if (encp->enc_enhanced_set_mac_supported) {
2529573ed00SAndrew Rybchenko 		if ((rc = efx_mcdi_mtu_set(enp, epp->ep_mac_pdu)) != 0)
2539573ed00SAndrew Rybchenko 			goto fail1;
2549573ed00SAndrew Rybchenko 	} else {
2559573ed00SAndrew Rybchenko 		/*
2569573ed00SAndrew Rybchenko 		 * Fallback for older Huntington firmware, which always
2579573ed00SAndrew Rybchenko 		 * configure all of the parameters to MC_CMD_SET_MAC. This isn't
2589573ed00SAndrew Rybchenko 		 * suitable for setting the MTU on unpriviliged functions.
2599573ed00SAndrew Rybchenko 		 */
2609573ed00SAndrew Rybchenko 		if ((rc = ef10_mac_reconfigure(enp)) != 0)
2619573ed00SAndrew Rybchenko 			goto fail2;
2629573ed00SAndrew Rybchenko 	}
2639573ed00SAndrew Rybchenko 
2649573ed00SAndrew Rybchenko 	return (0);
2659573ed00SAndrew Rybchenko 
2669573ed00SAndrew Rybchenko fail2:
2679573ed00SAndrew Rybchenko 	EFSYS_PROBE(fail2);
2689573ed00SAndrew Rybchenko fail1:
2699573ed00SAndrew Rybchenko 	EFSYS_PROBE1(fail1, efx_rc_t, rc);
2709573ed00SAndrew Rybchenko 
2719573ed00SAndrew Rybchenko 	return (rc);
2729573ed00SAndrew Rybchenko }
2739573ed00SAndrew Rybchenko 
2749573ed00SAndrew Rybchenko 	__checkReturn		efx_rc_t
ef10_mac_pdu_get(__in efx_nic_t * enp,__out size_t * pdu)275d8484af2SAndrew Rybchenko ef10_mac_pdu_get(
276d8484af2SAndrew Rybchenko 	__in		efx_nic_t *enp,
277d8484af2SAndrew Rybchenko 	__out		size_t *pdu)
278d8484af2SAndrew Rybchenko {
279d8484af2SAndrew Rybchenko 	efx_rc_t rc;
280d8484af2SAndrew Rybchenko 
281d8484af2SAndrew Rybchenko 	if ((rc = efx_mcdi_mtu_get(enp, pdu)) != 0)
282d8484af2SAndrew Rybchenko 		goto fail1;
283d8484af2SAndrew Rybchenko 
284d8484af2SAndrew Rybchenko 	return (0);
285d8484af2SAndrew Rybchenko 
286d8484af2SAndrew Rybchenko fail1:
287d8484af2SAndrew Rybchenko 	EFSYS_PROBE1(fail1, efx_rc_t, rc);
288d8484af2SAndrew Rybchenko 
289d8484af2SAndrew Rybchenko 	return (rc);
290d8484af2SAndrew Rybchenko }
291d8484af2SAndrew Rybchenko 
292d8484af2SAndrew Rybchenko __checkReturn	efx_rc_t
ef10_mac_reconfigure(__in efx_nic_t * enp)2939573ed00SAndrew Rybchenko ef10_mac_reconfigure(
2949573ed00SAndrew Rybchenko 	__in		efx_nic_t *enp)
2959573ed00SAndrew Rybchenko {
2969573ed00SAndrew Rybchenko 	efx_port_t *epp = &(enp->en_port);
2979573ed00SAndrew Rybchenko 	efx_mcdi_req_t req;
298315bbbaaSAndrew Rybchenko 	EFX_MCDI_DECLARE_BUF(payload, MC_CMD_SET_MAC_IN_LEN,
299315bbbaaSAndrew Rybchenko 		MC_CMD_SET_MAC_OUT_LEN);
3009573ed00SAndrew Rybchenko 	efx_rc_t rc;
3019573ed00SAndrew Rybchenko 
3029573ed00SAndrew Rybchenko 	req.emr_cmd = MC_CMD_SET_MAC;
3039573ed00SAndrew Rybchenko 	req.emr_in_buf = payload;
3049573ed00SAndrew Rybchenko 	req.emr_in_length = MC_CMD_SET_MAC_IN_LEN;
3059573ed00SAndrew Rybchenko 	req.emr_out_buf = payload;
3069573ed00SAndrew Rybchenko 	req.emr_out_length = MC_CMD_SET_MAC_OUT_LEN;
3079573ed00SAndrew Rybchenko 
3089573ed00SAndrew Rybchenko 	MCDI_IN_SET_DWORD(req, SET_MAC_IN_MTU, epp->ep_mac_pdu);
3099573ed00SAndrew Rybchenko 	MCDI_IN_SET_DWORD(req, SET_MAC_IN_DRAIN, epp->ep_mac_drain ? 1 : 0);
3109573ed00SAndrew Rybchenko 	EFX_MAC_ADDR_COPY(MCDI_IN2(req, uint8_t, SET_MAC_IN_ADDR),
3119573ed00SAndrew Rybchenko 			    epp->ep_mac_addr);
3129573ed00SAndrew Rybchenko 
3139573ed00SAndrew Rybchenko 	/*
3149573ed00SAndrew Rybchenko 	 * Note: The Huntington MAC does not support REJECT_BRDCST.
3159573ed00SAndrew Rybchenko 	 * The REJECT_UNCST flag will also prevent multicast traffic
3169573ed00SAndrew Rybchenko 	 * from reaching the filters. As Huntington filters drop any
3179573ed00SAndrew Rybchenko 	 * traffic that does not match a filter it is ok to leave the
3189573ed00SAndrew Rybchenko 	 * MAC running in promiscuous mode. See bug41141.
3199573ed00SAndrew Rybchenko 	 *
3209573ed00SAndrew Rybchenko 	 * FIXME: Does REJECT_UNCST behave the same way on Medford?
3219573ed00SAndrew Rybchenko 	 */
3229573ed00SAndrew Rybchenko 	MCDI_IN_POPULATE_DWORD_2(req, SET_MAC_IN_REJECT,
3239573ed00SAndrew Rybchenko 				    SET_MAC_IN_REJECT_UNCST, 0,
3249573ed00SAndrew Rybchenko 				    SET_MAC_IN_REJECT_BRDCST, 0);
3259573ed00SAndrew Rybchenko 
3269573ed00SAndrew Rybchenko 	/*
3279573ed00SAndrew Rybchenko 	 * Flow control, whether it is auto-negotiated or not,
3289573ed00SAndrew Rybchenko 	 * is set via the PHY advertised capabilities.  When set to
3299573ed00SAndrew Rybchenko 	 * automatic the MAC will use the PHY settings to determine
3309573ed00SAndrew Rybchenko 	 * the flow control settings.
3319573ed00SAndrew Rybchenko 	 */
3329573ed00SAndrew Rybchenko 	MCDI_IN_SET_DWORD(req, SET_MAC_IN_FCNTL, MC_CMD_FCNTL_AUTO);
3339573ed00SAndrew Rybchenko 
3349573ed00SAndrew Rybchenko 	/* Do not include the Ethernet frame checksum in RX packets */
3359573ed00SAndrew Rybchenko 	MCDI_IN_POPULATE_DWORD_1(req, SET_MAC_IN_FLAGS,
3369573ed00SAndrew Rybchenko 				    SET_MAC_IN_FLAG_INCLUDE_FCS, 0);
3379573ed00SAndrew Rybchenko 
3389573ed00SAndrew Rybchenko 	efx_mcdi_execute_quiet(enp, &req);
3399573ed00SAndrew Rybchenko 
3409573ed00SAndrew Rybchenko 	if (req.emr_rc != 0) {
3419573ed00SAndrew Rybchenko 		/*
3429573ed00SAndrew Rybchenko 		 * Unprivileged functions cannot control link state,
3439573ed00SAndrew Rybchenko 		 * but still need to configure filters.
3449573ed00SAndrew Rybchenko 		 */
3459573ed00SAndrew Rybchenko 		if (req.emr_rc != EACCES) {
3469573ed00SAndrew Rybchenko 			rc = req.emr_rc;
3479573ed00SAndrew Rybchenko 			goto fail1;
3489573ed00SAndrew Rybchenko 		}
3499573ed00SAndrew Rybchenko 	}
3509573ed00SAndrew Rybchenko 
3519573ed00SAndrew Rybchenko 	/*
3529573ed00SAndrew Rybchenko 	 * Apply the filters for the MAC configuration.
3539573ed00SAndrew Rybchenko 	 * If the NIC isn't ready to accept filters this may
3549573ed00SAndrew Rybchenko 	 * return success without setting anything.
3559573ed00SAndrew Rybchenko 	 */
3569573ed00SAndrew Rybchenko 	rc = efx_filter_reconfigure(enp, epp->ep_mac_addr,
3579573ed00SAndrew Rybchenko 				    epp->ep_all_unicst, epp->ep_mulcst,
3589573ed00SAndrew Rybchenko 				    epp->ep_all_mulcst, epp->ep_brdcst,
3599573ed00SAndrew Rybchenko 				    epp->ep_mulcst_addr_list,
3609573ed00SAndrew Rybchenko 				    epp->ep_mulcst_addr_count);
3619573ed00SAndrew Rybchenko 
3629573ed00SAndrew Rybchenko 	return (0);
3639573ed00SAndrew Rybchenko 
3649573ed00SAndrew Rybchenko fail1:
3659573ed00SAndrew Rybchenko 	EFSYS_PROBE1(fail1, efx_rc_t, rc);
3669573ed00SAndrew Rybchenko 
3679573ed00SAndrew Rybchenko 	return (rc);
3689573ed00SAndrew Rybchenko }
3699573ed00SAndrew Rybchenko 
3709573ed00SAndrew Rybchenko 	__checkReturn			efx_rc_t
ef10_mac_multicast_list_set(__in efx_nic_t * enp)3719573ed00SAndrew Rybchenko ef10_mac_multicast_list_set(
3729573ed00SAndrew Rybchenko 	__in				efx_nic_t *enp)
3739573ed00SAndrew Rybchenko {
3749573ed00SAndrew Rybchenko 	efx_port_t *epp = &(enp->en_port);
3759573ed00SAndrew Rybchenko 	const efx_mac_ops_t *emop = epp->ep_emop;
3769573ed00SAndrew Rybchenko 	efx_rc_t rc;
3779573ed00SAndrew Rybchenko 
3789573ed00SAndrew Rybchenko 	EFSYS_ASSERT(enp->en_family == EFX_FAMILY_HUNTINGTON ||
379cbc3f94fSAndrew Rybchenko 	    enp->en_family == EFX_FAMILY_MEDFORD ||
380cbc3f94fSAndrew Rybchenko 	    enp->en_family == EFX_FAMILY_MEDFORD2);
3819573ed00SAndrew Rybchenko 
3829573ed00SAndrew Rybchenko 	if ((rc = emop->emo_reconfigure(enp)) != 0)
3839573ed00SAndrew Rybchenko 		goto fail1;
3849573ed00SAndrew Rybchenko 
3859573ed00SAndrew Rybchenko 	return (0);
3869573ed00SAndrew Rybchenko 
3879573ed00SAndrew Rybchenko fail1:
3889573ed00SAndrew Rybchenko 	EFSYS_PROBE1(fail1, efx_rc_t, rc);
3899573ed00SAndrew Rybchenko 
3909573ed00SAndrew Rybchenko 	return (rc);
3919573ed00SAndrew Rybchenko }
3929573ed00SAndrew Rybchenko 
3939573ed00SAndrew Rybchenko 	__checkReturn	efx_rc_t
ef10_mac_filter_default_rxq_set(__in efx_nic_t * enp,__in efx_rxq_t * erp,__in boolean_t using_rss)3949573ed00SAndrew Rybchenko ef10_mac_filter_default_rxq_set(
3959573ed00SAndrew Rybchenko 	__in		efx_nic_t *enp,
3969573ed00SAndrew Rybchenko 	__in		efx_rxq_t *erp,
3979573ed00SAndrew Rybchenko 	__in		boolean_t using_rss)
3989573ed00SAndrew Rybchenko {
3999573ed00SAndrew Rybchenko 	efx_port_t *epp = &(enp->en_port);
4009573ed00SAndrew Rybchenko 	efx_rxq_t *old_rxq;
4019573ed00SAndrew Rybchenko 	boolean_t old_using_rss;
4029573ed00SAndrew Rybchenko 	efx_rc_t rc;
4039573ed00SAndrew Rybchenko 
4049573ed00SAndrew Rybchenko 	ef10_filter_get_default_rxq(enp, &old_rxq, &old_using_rss);
4059573ed00SAndrew Rybchenko 
4069573ed00SAndrew Rybchenko 	ef10_filter_default_rxq_set(enp, erp, using_rss);
4079573ed00SAndrew Rybchenko 
4089573ed00SAndrew Rybchenko 	rc = efx_filter_reconfigure(enp, epp->ep_mac_addr,
4099573ed00SAndrew Rybchenko 				    epp->ep_all_unicst, epp->ep_mulcst,
4109573ed00SAndrew Rybchenko 				    epp->ep_all_mulcst, epp->ep_brdcst,
4119573ed00SAndrew Rybchenko 				    epp->ep_mulcst_addr_list,
4129573ed00SAndrew Rybchenko 				    epp->ep_mulcst_addr_count);
4139573ed00SAndrew Rybchenko 
4149573ed00SAndrew Rybchenko 	if (rc != 0)
4159573ed00SAndrew Rybchenko 		goto fail1;
4169573ed00SAndrew Rybchenko 
4179573ed00SAndrew Rybchenko 	return (0);
4189573ed00SAndrew Rybchenko 
4199573ed00SAndrew Rybchenko fail1:
4209573ed00SAndrew Rybchenko 	EFSYS_PROBE1(fail1, efx_rc_t, rc);
4219573ed00SAndrew Rybchenko 
4229573ed00SAndrew Rybchenko 	ef10_filter_default_rxq_set(enp, old_rxq, old_using_rss);
4239573ed00SAndrew Rybchenko 
4249573ed00SAndrew Rybchenko 	return (rc);
4259573ed00SAndrew Rybchenko }
4269573ed00SAndrew Rybchenko 
4279573ed00SAndrew Rybchenko 			void
ef10_mac_filter_default_rxq_clear(__in efx_nic_t * enp)4289573ed00SAndrew Rybchenko ef10_mac_filter_default_rxq_clear(
4299573ed00SAndrew Rybchenko 	__in		efx_nic_t *enp)
4309573ed00SAndrew Rybchenko {
4319573ed00SAndrew Rybchenko 	efx_port_t *epp = &(enp->en_port);
4329573ed00SAndrew Rybchenko 
4339573ed00SAndrew Rybchenko 	ef10_filter_default_rxq_clear(enp);
4349573ed00SAndrew Rybchenko 
435e4ddd4ccSAndrew Rybchenko 	(void) efx_filter_reconfigure(enp, epp->ep_mac_addr,
4369573ed00SAndrew Rybchenko 				    epp->ep_all_unicst, epp->ep_mulcst,
4379573ed00SAndrew Rybchenko 				    epp->ep_all_mulcst, epp->ep_brdcst,
4389573ed00SAndrew Rybchenko 				    epp->ep_mulcst_addr_list,
4399573ed00SAndrew Rybchenko 				    epp->ep_mulcst_addr_count);
4409573ed00SAndrew Rybchenko }
4419573ed00SAndrew Rybchenko 
4429573ed00SAndrew Rybchenko #if EFSYS_OPT_LOOPBACK
4439573ed00SAndrew Rybchenko 
4449573ed00SAndrew Rybchenko 	__checkReturn	efx_rc_t
ef10_mac_loopback_set(__in efx_nic_t * enp,__in efx_link_mode_t link_mode,__in efx_loopback_type_t loopback_type)4459573ed00SAndrew Rybchenko ef10_mac_loopback_set(
4469573ed00SAndrew Rybchenko 	__in		efx_nic_t *enp,
4479573ed00SAndrew Rybchenko 	__in		efx_link_mode_t link_mode,
4489573ed00SAndrew Rybchenko 	__in		efx_loopback_type_t loopback_type)
4499573ed00SAndrew Rybchenko {
4509573ed00SAndrew Rybchenko 	efx_port_t *epp = &(enp->en_port);
4519573ed00SAndrew Rybchenko 	const efx_phy_ops_t *epop = epp->ep_epop;
4529573ed00SAndrew Rybchenko 	efx_loopback_type_t old_loopback_type;
4539573ed00SAndrew Rybchenko 	efx_link_mode_t old_loopback_link_mode;
4549573ed00SAndrew Rybchenko 	efx_rc_t rc;
4559573ed00SAndrew Rybchenko 
4569573ed00SAndrew Rybchenko 	/* The PHY object handles this on EF10 */
4579573ed00SAndrew Rybchenko 	old_loopback_type = epp->ep_loopback_type;
4589573ed00SAndrew Rybchenko 	old_loopback_link_mode = epp->ep_loopback_link_mode;
4599573ed00SAndrew Rybchenko 	epp->ep_loopback_type = loopback_type;
4609573ed00SAndrew Rybchenko 	epp->ep_loopback_link_mode = link_mode;
4619573ed00SAndrew Rybchenko 
4629573ed00SAndrew Rybchenko 	if ((rc = epop->epo_reconfigure(enp)) != 0)
4639573ed00SAndrew Rybchenko 		goto fail1;
4649573ed00SAndrew Rybchenko 
4659573ed00SAndrew Rybchenko 	return (0);
4669573ed00SAndrew Rybchenko 
4679573ed00SAndrew Rybchenko fail1:
4689573ed00SAndrew Rybchenko 	EFSYS_PROBE1(fail1, efx_rc_t, rc);
4699573ed00SAndrew Rybchenko 
4709573ed00SAndrew Rybchenko 	epp->ep_loopback_type = old_loopback_type;
4719573ed00SAndrew Rybchenko 	epp->ep_loopback_link_mode = old_loopback_link_mode;
4729573ed00SAndrew Rybchenko 
4739573ed00SAndrew Rybchenko 	return (rc);
4749573ed00SAndrew Rybchenko }
4759573ed00SAndrew Rybchenko 
4769573ed00SAndrew Rybchenko #endif	/* EFSYS_OPT_LOOPBACK */
4779573ed00SAndrew Rybchenko 
4789573ed00SAndrew Rybchenko #if EFSYS_OPT_MAC_STATS
4799573ed00SAndrew Rybchenko 
48058a72cb2SAndrew Rybchenko 	__checkReturn			efx_rc_t
ef10_mac_stats_get_mask(__in efx_nic_t * enp,__inout_bcount (mask_size)uint32_t * maskp,__in size_t mask_size)48158a72cb2SAndrew Rybchenko ef10_mac_stats_get_mask(
48258a72cb2SAndrew Rybchenko 	__in				efx_nic_t *enp,
48358a72cb2SAndrew Rybchenko 	__inout_bcount(mask_size)	uint32_t *maskp,
48458a72cb2SAndrew Rybchenko 	__in				size_t mask_size)
48558a72cb2SAndrew Rybchenko {
48658a72cb2SAndrew Rybchenko 	const struct efx_mac_stats_range ef10_common[] = {
48758a72cb2SAndrew Rybchenko 		{ EFX_MAC_RX_OCTETS, EFX_MAC_RX_GE_15XX_PKTS },
48858a72cb2SAndrew Rybchenko 		{ EFX_MAC_RX_FCS_ERRORS, EFX_MAC_RX_DROP_EVENTS },
48958a72cb2SAndrew Rybchenko 		{ EFX_MAC_RX_JABBER_PKTS, EFX_MAC_RX_JABBER_PKTS },
49058a72cb2SAndrew Rybchenko 		{ EFX_MAC_RX_NODESC_DROP_CNT, EFX_MAC_TX_PAUSE_PKTS },
49158a72cb2SAndrew Rybchenko 	};
49258a72cb2SAndrew Rybchenko 	const struct efx_mac_stats_range ef10_tx_size_bins[] = {
49358a72cb2SAndrew Rybchenko 		{ EFX_MAC_TX_LE_64_PKTS, EFX_MAC_TX_GE_15XX_PKTS },
49458a72cb2SAndrew Rybchenko 	};
49558a72cb2SAndrew Rybchenko 	efx_nic_cfg_t *encp = &(enp->en_nic_cfg);
49658a72cb2SAndrew Rybchenko 	efx_port_t *epp = &(enp->en_port);
49758a72cb2SAndrew Rybchenko 	efx_rc_t rc;
49858a72cb2SAndrew Rybchenko 
49958a72cb2SAndrew Rybchenko 	if ((rc = efx_mac_stats_mask_add_ranges(maskp, mask_size,
50058a72cb2SAndrew Rybchenko 	    ef10_common, EFX_ARRAY_SIZE(ef10_common))) != 0)
50158a72cb2SAndrew Rybchenko 		goto fail1;
50258a72cb2SAndrew Rybchenko 
50358a72cb2SAndrew Rybchenko 	if (epp->ep_phy_cap_mask & (1 << MC_CMD_PHY_CAP_40000FDX_LBN)) {
50458a72cb2SAndrew Rybchenko 		const struct efx_mac_stats_range ef10_40g_extra[] = {
50558a72cb2SAndrew Rybchenko 			{ EFX_MAC_RX_ALIGN_ERRORS, EFX_MAC_RX_ALIGN_ERRORS },
50658a72cb2SAndrew Rybchenko 		};
50758a72cb2SAndrew Rybchenko 
50858a72cb2SAndrew Rybchenko 		if ((rc = efx_mac_stats_mask_add_ranges(maskp, mask_size,
50958a72cb2SAndrew Rybchenko 		    ef10_40g_extra, EFX_ARRAY_SIZE(ef10_40g_extra))) != 0)
51058a72cb2SAndrew Rybchenko 			goto fail2;
51158a72cb2SAndrew Rybchenko 
51258a72cb2SAndrew Rybchenko 		if (encp->enc_mac_stats_40g_tx_size_bins) {
51358a72cb2SAndrew Rybchenko 			if ((rc = efx_mac_stats_mask_add_ranges(maskp,
51458a72cb2SAndrew Rybchenko 			    mask_size, ef10_tx_size_bins,
51558a72cb2SAndrew Rybchenko 			    EFX_ARRAY_SIZE(ef10_tx_size_bins))) != 0)
51658a72cb2SAndrew Rybchenko 				goto fail3;
51758a72cb2SAndrew Rybchenko 		}
51858a72cb2SAndrew Rybchenko 	} else {
51958a72cb2SAndrew Rybchenko 		if ((rc = efx_mac_stats_mask_add_ranges(maskp, mask_size,
52058a72cb2SAndrew Rybchenko 		    ef10_tx_size_bins, EFX_ARRAY_SIZE(ef10_tx_size_bins))) != 0)
52158a72cb2SAndrew Rybchenko 			goto fail4;
52258a72cb2SAndrew Rybchenko 	}
52358a72cb2SAndrew Rybchenko 
52458a72cb2SAndrew Rybchenko 	if (encp->enc_pm_and_rxdp_counters) {
52558a72cb2SAndrew Rybchenko 		const struct efx_mac_stats_range ef10_pm_and_rxdp[] = {
52658a72cb2SAndrew Rybchenko 			{ EFX_MAC_PM_TRUNC_BB_OVERFLOW, EFX_MAC_RXDP_HLB_WAIT },
52758a72cb2SAndrew Rybchenko 		};
52858a72cb2SAndrew Rybchenko 
52958a72cb2SAndrew Rybchenko 		if ((rc = efx_mac_stats_mask_add_ranges(maskp, mask_size,
53058a72cb2SAndrew Rybchenko 		    ef10_pm_and_rxdp, EFX_ARRAY_SIZE(ef10_pm_and_rxdp))) != 0)
53158a72cb2SAndrew Rybchenko 			goto fail5;
53258a72cb2SAndrew Rybchenko 	}
53358a72cb2SAndrew Rybchenko 
53458a72cb2SAndrew Rybchenko 	if (encp->enc_datapath_cap_evb) {
53558a72cb2SAndrew Rybchenko 		const struct efx_mac_stats_range ef10_vadaptor[] = {
53658a72cb2SAndrew Rybchenko 			{ EFX_MAC_VADAPTER_RX_UNICAST_PACKETS,
53758a72cb2SAndrew Rybchenko 			    EFX_MAC_VADAPTER_TX_OVERFLOW },
53858a72cb2SAndrew Rybchenko 		};
53958a72cb2SAndrew Rybchenko 
54058a72cb2SAndrew Rybchenko 		if ((rc = efx_mac_stats_mask_add_ranges(maskp, mask_size,
54158a72cb2SAndrew Rybchenko 		    ef10_vadaptor, EFX_ARRAY_SIZE(ef10_vadaptor))) != 0)
54258a72cb2SAndrew Rybchenko 			goto fail6;
54358a72cb2SAndrew Rybchenko 	}
54458a72cb2SAndrew Rybchenko 
545747819d2SAndrew Rybchenko 	if (encp->enc_fec_counters) {
546747819d2SAndrew Rybchenko 		const struct efx_mac_stats_range ef10_fec[] = {
547747819d2SAndrew Rybchenko 			{ EFX_MAC_FEC_UNCORRECTED_ERRORS,
548747819d2SAndrew Rybchenko 			    EFX_MAC_FEC_CORRECTED_SYMBOLS_LANE3 },
549747819d2SAndrew Rybchenko 		};
550747819d2SAndrew Rybchenko 		if ((rc = efx_mac_stats_mask_add_ranges(maskp, mask_size,
551747819d2SAndrew Rybchenko 		    ef10_fec, EFX_ARRAY_SIZE(ef10_fec))) != 0)
552747819d2SAndrew Rybchenko 			goto fail7;
553747819d2SAndrew Rybchenko 	}
554747819d2SAndrew Rybchenko 
555ef8967c7SAndrew Rybchenko 	if (encp->enc_mac_stats_nstats >= MC_CMD_MAC_NSTATS_V4) {
556ef8967c7SAndrew Rybchenko 		const struct efx_mac_stats_range ef10_rxdp_sdt[] = {
557ef8967c7SAndrew Rybchenko 			{ EFX_MAC_RXDP_SCATTER_DISABLED_TRUNC,
558ef8967c7SAndrew Rybchenko 			    EFX_MAC_RXDP_SCATTER_DISABLED_TRUNC },
559ef8967c7SAndrew Rybchenko 		};
560ef8967c7SAndrew Rybchenko 
561ef8967c7SAndrew Rybchenko 		if ((rc = efx_mac_stats_mask_add_ranges(maskp, mask_size,
562ef8967c7SAndrew Rybchenko 		    ef10_rxdp_sdt, EFX_ARRAY_SIZE(ef10_rxdp_sdt))) != 0)
563ef8967c7SAndrew Rybchenko 			goto fail8;
564ef8967c7SAndrew Rybchenko 	}
565ef8967c7SAndrew Rybchenko 
566aea9d093SAndrew Rybchenko 	if (encp->enc_hlb_counters) {
567aea9d093SAndrew Rybchenko 		const struct efx_mac_stats_range ef10_hlb[] = {
568aea9d093SAndrew Rybchenko 			{ EFX_MAC_RXDP_HLB_IDLE, EFX_MAC_RXDP_HLB_TIMEOUT },
569aea9d093SAndrew Rybchenko 		};
570aea9d093SAndrew Rybchenko 		if ((rc = efx_mac_stats_mask_add_ranges(maskp, mask_size,
571aea9d093SAndrew Rybchenko 		    ef10_hlb, EFX_ARRAY_SIZE(ef10_hlb))) != 0)
572aea9d093SAndrew Rybchenko 			goto fail9;
573aea9d093SAndrew Rybchenko 	}
574aea9d093SAndrew Rybchenko 
57558a72cb2SAndrew Rybchenko 	return (0);
57658a72cb2SAndrew Rybchenko 
577aea9d093SAndrew Rybchenko fail9:
578aea9d093SAndrew Rybchenko 	EFSYS_PROBE(fail9);
579ef8967c7SAndrew Rybchenko fail8:
580ef8967c7SAndrew Rybchenko 	EFSYS_PROBE(fail8);
581747819d2SAndrew Rybchenko fail7:
582747819d2SAndrew Rybchenko 	EFSYS_PROBE(fail7);
58358a72cb2SAndrew Rybchenko fail6:
58458a72cb2SAndrew Rybchenko 	EFSYS_PROBE(fail6);
58558a72cb2SAndrew Rybchenko fail5:
58658a72cb2SAndrew Rybchenko 	EFSYS_PROBE(fail5);
58758a72cb2SAndrew Rybchenko fail4:
58858a72cb2SAndrew Rybchenko 	EFSYS_PROBE(fail4);
58958a72cb2SAndrew Rybchenko fail3:
59058a72cb2SAndrew Rybchenko 	EFSYS_PROBE(fail3);
59158a72cb2SAndrew Rybchenko fail2:
59258a72cb2SAndrew Rybchenko 	EFSYS_PROBE(fail2);
59358a72cb2SAndrew Rybchenko fail1:
59458a72cb2SAndrew Rybchenko 	EFSYS_PROBE1(fail1, efx_rc_t, rc);
59558a72cb2SAndrew Rybchenko 
59658a72cb2SAndrew Rybchenko 	return (rc);
59758a72cb2SAndrew Rybchenko }
59858a72cb2SAndrew Rybchenko 
5999573ed00SAndrew Rybchenko #define	EF10_MAC_STAT_READ(_esmp, _field, _eqp)			\
6009573ed00SAndrew Rybchenko 	EFSYS_MEM_READQ((_esmp), (_field) * sizeof (efx_qword_t), _eqp)
6019573ed00SAndrew Rybchenko 
6029573ed00SAndrew Rybchenko 	__checkReturn			efx_rc_t
ef10_mac_stats_update(__in efx_nic_t * enp,__in efsys_mem_t * esmp,__inout_ecount (EFX_MAC_NSTATS)efsys_stat_t * stat,__inout_opt uint32_t * generationp)6039573ed00SAndrew Rybchenko ef10_mac_stats_update(
6049573ed00SAndrew Rybchenko 	__in				efx_nic_t *enp,
6059573ed00SAndrew Rybchenko 	__in				efsys_mem_t *esmp,
6069573ed00SAndrew Rybchenko 	__inout_ecount(EFX_MAC_NSTATS)	efsys_stat_t *stat,
6079573ed00SAndrew Rybchenko 	__inout_opt			uint32_t *generationp)
6089573ed00SAndrew Rybchenko {
609fdfd8bfeSAndrew Rybchenko 	const efx_nic_cfg_t *encp = &enp->en_nic_cfg;
6109573ed00SAndrew Rybchenko 	efx_qword_t generation_start;
6119573ed00SAndrew Rybchenko 	efx_qword_t generation_end;
612fdfd8bfeSAndrew Rybchenko 	efx_qword_t value;
613fdfd8bfeSAndrew Rybchenko 	efx_rc_t rc;
6149573ed00SAndrew Rybchenko 
615fdfd8bfeSAndrew Rybchenko 	/*
616fdfd8bfeSAndrew Rybchenko 	 * The MAC_STATS contain start and end generation counters used to
617fdfd8bfeSAndrew Rybchenko 	 * detect when the DMA buffer has been updated during stats decode.
618fdfd8bfeSAndrew Rybchenko 	 * All stats counters are 64bit unsigned values.
619fdfd8bfeSAndrew Rybchenko 	 *
620fdfd8bfeSAndrew Rybchenko 	 * Siena-compatible MAC stats contain MC_CMD_MAC_NSTATS 64bit counters.
621fdfd8bfeSAndrew Rybchenko 	 * The generation end counter is at index MC_CMD_MAC_GENERATION_END
622fdfd8bfeSAndrew Rybchenko 	 * (same as MC_CMD_MAC_NSTATS-1).
623fdfd8bfeSAndrew Rybchenko 	 *
624fdfd8bfeSAndrew Rybchenko 	 * Medford2 and later use a larger DMA buffer: MAC_STATS_NUM_STATS from
625fdfd8bfeSAndrew Rybchenko 	 * MC_CMD_GET_CAPABILITIES_V4_OUT reports the number of 64bit counters.
626fdfd8bfeSAndrew Rybchenko 	 *
627fdfd8bfeSAndrew Rybchenko 	 * Firmware writes the generation end counter as the last counter in the
628fdfd8bfeSAndrew Rybchenko 	 * DMA buffer. Do not use MC_CMD_MAC_GENERATION_END, as that is only
629fdfd8bfeSAndrew Rybchenko 	 * correct for legacy Siena-compatible MAC stats.
630fdfd8bfeSAndrew Rybchenko 	 */
631fdfd8bfeSAndrew Rybchenko 
632fdfd8bfeSAndrew Rybchenko 	if (encp->enc_mac_stats_nstats < MC_CMD_MAC_NSTATS) {
633fdfd8bfeSAndrew Rybchenko 		/* MAC stats count too small for legacy MAC stats */
634fdfd8bfeSAndrew Rybchenko 		rc = ENOSPC;
635fdfd8bfeSAndrew Rybchenko 		goto fail1;
636fdfd8bfeSAndrew Rybchenko 	}
637fdfd8bfeSAndrew Rybchenko 	if (EFSYS_MEM_SIZE(esmp) <
638fdfd8bfeSAndrew Rybchenko 	    (encp->enc_mac_stats_nstats * sizeof (efx_qword_t))) {
639fdfd8bfeSAndrew Rybchenko 		/* DMA buffer too small */
640fdfd8bfeSAndrew Rybchenko 		rc = ENOSPC;
641fdfd8bfeSAndrew Rybchenko 		goto fail2;
642fdfd8bfeSAndrew Rybchenko 	}
6439573ed00SAndrew Rybchenko 
6449573ed00SAndrew Rybchenko 	/* Read END first so we don't race with the MC */
645fdfd8bfeSAndrew Rybchenko 	EFSYS_DMA_SYNC_FOR_KERNEL(esmp, 0, EFSYS_MEM_SIZE(esmp));
646fdfd8bfeSAndrew Rybchenko 	EF10_MAC_STAT_READ(esmp, (encp->enc_mac_stats_nstats - 1),
6479573ed00SAndrew Rybchenko 	    &generation_end);
6489573ed00SAndrew Rybchenko 	EFSYS_MEM_READ_BARRIER();
6499573ed00SAndrew Rybchenko 
6509573ed00SAndrew Rybchenko 	/* TX */
6519573ed00SAndrew Rybchenko 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_TX_PKTS, &value);
6529573ed00SAndrew Rybchenko 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_TX_PKTS]), &value);
6539573ed00SAndrew Rybchenko 
6549573ed00SAndrew Rybchenko 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_TX_CONTROL_PKTS, &value);
6559573ed00SAndrew Rybchenko 	EFSYS_STAT_SUBR_QWORD(&(stat[EFX_MAC_TX_PKTS]), &value);
6569573ed00SAndrew Rybchenko 
6579573ed00SAndrew Rybchenko 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_TX_PAUSE_PKTS, &value);
6589573ed00SAndrew Rybchenko 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_TX_PAUSE_PKTS]), &value);
6599573ed00SAndrew Rybchenko 
6609573ed00SAndrew Rybchenko 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_TX_UNICAST_PKTS, &value);
6619573ed00SAndrew Rybchenko 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_TX_UNICST_PKTS]), &value);
6629573ed00SAndrew Rybchenko 
6639573ed00SAndrew Rybchenko 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_TX_MULTICAST_PKTS, &value);
6649573ed00SAndrew Rybchenko 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_TX_MULTICST_PKTS]), &value);
6659573ed00SAndrew Rybchenko 
6669573ed00SAndrew Rybchenko 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_TX_BROADCAST_PKTS, &value);
6679573ed00SAndrew Rybchenko 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_TX_BRDCST_PKTS]), &value);
6689573ed00SAndrew Rybchenko 
6699573ed00SAndrew Rybchenko 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_TX_BYTES, &value);
6709573ed00SAndrew Rybchenko 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_TX_OCTETS]), &value);
6719573ed00SAndrew Rybchenko 
6729573ed00SAndrew Rybchenko 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_TX_LT64_PKTS, &value);
6739573ed00SAndrew Rybchenko 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_TX_LE_64_PKTS]), &value);
6749573ed00SAndrew Rybchenko 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_TX_64_PKTS, &value);
675fe094a7cSAndrew Rybchenko 	EFSYS_STAT_INCR_QWORD(&(stat[EFX_MAC_TX_LE_64_PKTS]), &value);
6769573ed00SAndrew Rybchenko 
6779573ed00SAndrew Rybchenko 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_TX_65_TO_127_PKTS, &value);
6789573ed00SAndrew Rybchenko 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_TX_65_TO_127_PKTS]), &value);
6799573ed00SAndrew Rybchenko 
6809573ed00SAndrew Rybchenko 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_TX_128_TO_255_PKTS, &value);
6819573ed00SAndrew Rybchenko 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_TX_128_TO_255_PKTS]), &value);
6829573ed00SAndrew Rybchenko 
6839573ed00SAndrew Rybchenko 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_TX_256_TO_511_PKTS, &value);
6849573ed00SAndrew Rybchenko 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_TX_256_TO_511_PKTS]), &value);
6859573ed00SAndrew Rybchenko 
6869573ed00SAndrew Rybchenko 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_TX_512_TO_1023_PKTS, &value);
6879573ed00SAndrew Rybchenko 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_TX_512_TO_1023_PKTS]), &value);
6889573ed00SAndrew Rybchenko 
6899573ed00SAndrew Rybchenko 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_TX_1024_TO_15XX_PKTS, &value);
6909573ed00SAndrew Rybchenko 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_TX_1024_TO_15XX_PKTS]), &value);
6919573ed00SAndrew Rybchenko 
6929573ed00SAndrew Rybchenko 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_TX_15XX_TO_JUMBO_PKTS, &value);
6939573ed00SAndrew Rybchenko 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_TX_GE_15XX_PKTS]), &value);
6949573ed00SAndrew Rybchenko 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_TX_GTJUMBO_PKTS, &value);
6959573ed00SAndrew Rybchenko 	EFSYS_STAT_INCR_QWORD(&(stat[EFX_MAC_TX_GE_15XX_PKTS]), &value);
6969573ed00SAndrew Rybchenko 
6979573ed00SAndrew Rybchenko 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_TX_BAD_FCS_PKTS, &value);
6989573ed00SAndrew Rybchenko 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_TX_ERRORS]), &value);
6999573ed00SAndrew Rybchenko 
7009573ed00SAndrew Rybchenko 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_TX_SINGLE_COLLISION_PKTS, &value);
7019573ed00SAndrew Rybchenko 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_TX_SGL_COL_PKTS]), &value);
7029573ed00SAndrew Rybchenko 
7039573ed00SAndrew Rybchenko 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_TX_MULTIPLE_COLLISION_PKTS,
7049573ed00SAndrew Rybchenko 			    &value);
7059573ed00SAndrew Rybchenko 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_TX_MULT_COL_PKTS]), &value);
7069573ed00SAndrew Rybchenko 
7079573ed00SAndrew Rybchenko 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_TX_EXCESSIVE_COLLISION_PKTS,
7089573ed00SAndrew Rybchenko 			    &value);
7099573ed00SAndrew Rybchenko 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_TX_EX_COL_PKTS]), &value);
7109573ed00SAndrew Rybchenko 
7119573ed00SAndrew Rybchenko 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_TX_LATE_COLLISION_PKTS, &value);
7129573ed00SAndrew Rybchenko 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_TX_LATE_COL_PKTS]), &value);
7139573ed00SAndrew Rybchenko 
7149573ed00SAndrew Rybchenko 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_TX_DEFERRED_PKTS, &value);
7159573ed00SAndrew Rybchenko 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_TX_DEF_PKTS]), &value);
7169573ed00SAndrew Rybchenko 
7179573ed00SAndrew Rybchenko 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_TX_EXCESSIVE_DEFERRED_PKTS,
7189573ed00SAndrew Rybchenko 	    &value);
7199573ed00SAndrew Rybchenko 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_TX_EX_DEF_PKTS]), &value);
7209573ed00SAndrew Rybchenko 
7219573ed00SAndrew Rybchenko 	/* RX */
7229573ed00SAndrew Rybchenko 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_RX_BYTES, &value);
7239573ed00SAndrew Rybchenko 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_RX_OCTETS]), &value);
7249573ed00SAndrew Rybchenko 
7259573ed00SAndrew Rybchenko 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_RX_PKTS, &value);
7269573ed00SAndrew Rybchenko 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_RX_PKTS]), &value);
7279573ed00SAndrew Rybchenko 
7289573ed00SAndrew Rybchenko 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_RX_UNICAST_PKTS, &value);
7299573ed00SAndrew Rybchenko 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_RX_UNICST_PKTS]), &value);
7309573ed00SAndrew Rybchenko 
7319573ed00SAndrew Rybchenko 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_RX_MULTICAST_PKTS, &value);
7329573ed00SAndrew Rybchenko 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_RX_MULTICST_PKTS]), &value);
7339573ed00SAndrew Rybchenko 
7349573ed00SAndrew Rybchenko 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_RX_BROADCAST_PKTS, &value);
7359573ed00SAndrew Rybchenko 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_RX_BRDCST_PKTS]), &value);
7369573ed00SAndrew Rybchenko 
7379573ed00SAndrew Rybchenko 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_RX_PAUSE_PKTS, &value);
7389573ed00SAndrew Rybchenko 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_RX_PAUSE_PKTS]), &value);
7399573ed00SAndrew Rybchenko 
7409573ed00SAndrew Rybchenko 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_RX_UNDERSIZE_PKTS, &value);
7419573ed00SAndrew Rybchenko 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_RX_LE_64_PKTS]), &value);
7429573ed00SAndrew Rybchenko 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_RX_64_PKTS, &value);
7439573ed00SAndrew Rybchenko 	EFSYS_STAT_INCR_QWORD(&(stat[EFX_MAC_RX_LE_64_PKTS]), &value);
7449573ed00SAndrew Rybchenko 
7459573ed00SAndrew Rybchenko 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_RX_65_TO_127_PKTS, &value);
7469573ed00SAndrew Rybchenko 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_RX_65_TO_127_PKTS]), &value);
7479573ed00SAndrew Rybchenko 
7489573ed00SAndrew Rybchenko 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_RX_128_TO_255_PKTS, &value);
7499573ed00SAndrew Rybchenko 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_RX_128_TO_255_PKTS]), &value);
7509573ed00SAndrew Rybchenko 
7519573ed00SAndrew Rybchenko 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_RX_256_TO_511_PKTS, &value);
7529573ed00SAndrew Rybchenko 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_RX_256_TO_511_PKTS]), &value);
7539573ed00SAndrew Rybchenko 
7549573ed00SAndrew Rybchenko 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_RX_512_TO_1023_PKTS, &value);
7559573ed00SAndrew Rybchenko 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_RX_512_TO_1023_PKTS]), &value);
7569573ed00SAndrew Rybchenko 
7579573ed00SAndrew Rybchenko 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_RX_1024_TO_15XX_PKTS, &value);
7589573ed00SAndrew Rybchenko 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_RX_1024_TO_15XX_PKTS]), &value);
7599573ed00SAndrew Rybchenko 
7609573ed00SAndrew Rybchenko 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_RX_15XX_TO_JUMBO_PKTS, &value);
7619573ed00SAndrew Rybchenko 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_RX_GE_15XX_PKTS]), &value);
7629573ed00SAndrew Rybchenko 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_RX_GTJUMBO_PKTS, &value);
7639573ed00SAndrew Rybchenko 	EFSYS_STAT_INCR_QWORD(&(stat[EFX_MAC_RX_GE_15XX_PKTS]), &value);
7649573ed00SAndrew Rybchenko 
7659573ed00SAndrew Rybchenko 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_RX_BAD_FCS_PKTS, &value);
7669573ed00SAndrew Rybchenko 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_RX_FCS_ERRORS]), &value);
7679573ed00SAndrew Rybchenko 
7689573ed00SAndrew Rybchenko 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_RX_OVERFLOW_PKTS, &value);
7699573ed00SAndrew Rybchenko 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_RX_DROP_EVENTS]), &value);
7709573ed00SAndrew Rybchenko 
7719573ed00SAndrew Rybchenko 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_RX_FALSE_CARRIER_PKTS, &value);
7729573ed00SAndrew Rybchenko 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_RX_FALSE_CARRIER_ERRORS]), &value);
7739573ed00SAndrew Rybchenko 
7749573ed00SAndrew Rybchenko 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_RX_SYMBOL_ERROR_PKTS, &value);
7759573ed00SAndrew Rybchenko 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_RX_SYMBOL_ERRORS]), &value);
7769573ed00SAndrew Rybchenko 
7779573ed00SAndrew Rybchenko 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_RX_ALIGN_ERROR_PKTS, &value);
7789573ed00SAndrew Rybchenko 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_RX_ALIGN_ERRORS]), &value);
7799573ed00SAndrew Rybchenko 
7809573ed00SAndrew Rybchenko 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_RX_INTERNAL_ERROR_PKTS, &value);
7819573ed00SAndrew Rybchenko 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_RX_INTERNAL_ERRORS]), &value);
7829573ed00SAndrew Rybchenko 
7839573ed00SAndrew Rybchenko 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_RX_JABBER_PKTS, &value);
7849573ed00SAndrew Rybchenko 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_RX_JABBER_PKTS]), &value);
7859573ed00SAndrew Rybchenko 
7869573ed00SAndrew Rybchenko 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_RX_LANES01_CHAR_ERR, &value);
7879573ed00SAndrew Rybchenko 	EFSYS_STAT_SET_DWORD(&(stat[EFX_MAC_RX_LANE0_CHAR_ERR]),
7889573ed00SAndrew Rybchenko 			    &(value.eq_dword[0]));
7899573ed00SAndrew Rybchenko 	EFSYS_STAT_SET_DWORD(&(stat[EFX_MAC_RX_LANE1_CHAR_ERR]),
7909573ed00SAndrew Rybchenko 			    &(value.eq_dword[1]));
7919573ed00SAndrew Rybchenko 
7929573ed00SAndrew Rybchenko 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_RX_LANES23_CHAR_ERR, &value);
7939573ed00SAndrew Rybchenko 	EFSYS_STAT_SET_DWORD(&(stat[EFX_MAC_RX_LANE2_CHAR_ERR]),
7949573ed00SAndrew Rybchenko 			    &(value.eq_dword[0]));
7959573ed00SAndrew Rybchenko 	EFSYS_STAT_SET_DWORD(&(stat[EFX_MAC_RX_LANE3_CHAR_ERR]),
7969573ed00SAndrew Rybchenko 			    &(value.eq_dword[1]));
7979573ed00SAndrew Rybchenko 
7989573ed00SAndrew Rybchenko 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_RX_LANES01_DISP_ERR, &value);
7999573ed00SAndrew Rybchenko 	EFSYS_STAT_SET_DWORD(&(stat[EFX_MAC_RX_LANE0_DISP_ERR]),
8009573ed00SAndrew Rybchenko 			    &(value.eq_dword[0]));
8019573ed00SAndrew Rybchenko 	EFSYS_STAT_SET_DWORD(&(stat[EFX_MAC_RX_LANE1_DISP_ERR]),
8029573ed00SAndrew Rybchenko 			    &(value.eq_dword[1]));
8039573ed00SAndrew Rybchenko 
8049573ed00SAndrew Rybchenko 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_RX_LANES23_DISP_ERR, &value);
8059573ed00SAndrew Rybchenko 	EFSYS_STAT_SET_DWORD(&(stat[EFX_MAC_RX_LANE2_DISP_ERR]),
8069573ed00SAndrew Rybchenko 			    &(value.eq_dword[0]));
8079573ed00SAndrew Rybchenko 	EFSYS_STAT_SET_DWORD(&(stat[EFX_MAC_RX_LANE3_DISP_ERR]),
8089573ed00SAndrew Rybchenko 			    &(value.eq_dword[1]));
8099573ed00SAndrew Rybchenko 
8109573ed00SAndrew Rybchenko 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_RX_MATCH_FAULT, &value);
8119573ed00SAndrew Rybchenko 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_RX_MATCH_FAULT]), &value);
8129573ed00SAndrew Rybchenko 
8139573ed00SAndrew Rybchenko 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_RX_NODESC_DROPS, &value);
8149573ed00SAndrew Rybchenko 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_RX_NODESC_DROP_CNT]), &value);
8159573ed00SAndrew Rybchenko 
8169573ed00SAndrew Rybchenko 	/* Packet memory (EF10 only) */
8179573ed00SAndrew Rybchenko 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_PM_TRUNC_BB_OVERFLOW, &value);
8189573ed00SAndrew Rybchenko 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_PM_TRUNC_BB_OVERFLOW]), &value);
8199573ed00SAndrew Rybchenko 
8209573ed00SAndrew Rybchenko 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_PM_DISCARD_BB_OVERFLOW, &value);
8219573ed00SAndrew Rybchenko 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_PM_DISCARD_BB_OVERFLOW]), &value);
8229573ed00SAndrew Rybchenko 
8239573ed00SAndrew Rybchenko 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_PM_TRUNC_VFIFO_FULL, &value);
8249573ed00SAndrew Rybchenko 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_PM_TRUNC_VFIFO_FULL]), &value);
8259573ed00SAndrew Rybchenko 
8269573ed00SAndrew Rybchenko 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_PM_DISCARD_VFIFO_FULL, &value);
8279573ed00SAndrew Rybchenko 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_PM_DISCARD_VFIFO_FULL]), &value);
8289573ed00SAndrew Rybchenko 
8299573ed00SAndrew Rybchenko 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_PM_TRUNC_QBB, &value);
8309573ed00SAndrew Rybchenko 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_PM_TRUNC_QBB]), &value);
8319573ed00SAndrew Rybchenko 
8329573ed00SAndrew Rybchenko 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_PM_DISCARD_QBB, &value);
8339573ed00SAndrew Rybchenko 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_PM_DISCARD_QBB]), &value);
8349573ed00SAndrew Rybchenko 
8359573ed00SAndrew Rybchenko 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_PM_DISCARD_MAPPING, &value);
8369573ed00SAndrew Rybchenko 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_PM_DISCARD_MAPPING]), &value);
8379573ed00SAndrew Rybchenko 
8389573ed00SAndrew Rybchenko 	/* RX datapath */
8399573ed00SAndrew Rybchenko 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_RXDP_Q_DISABLED_PKTS, &value);
8409573ed00SAndrew Rybchenko 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_RXDP_Q_DISABLED_PKTS]), &value);
8419573ed00SAndrew Rybchenko 
8429573ed00SAndrew Rybchenko 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_RXDP_DI_DROPPED_PKTS, &value);
8439573ed00SAndrew Rybchenko 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_RXDP_DI_DROPPED_PKTS]), &value);
8449573ed00SAndrew Rybchenko 
8459573ed00SAndrew Rybchenko 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_RXDP_STREAMING_PKTS, &value);
8469573ed00SAndrew Rybchenko 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_RXDP_STREAMING_PKTS]), &value);
8479573ed00SAndrew Rybchenko 
8489573ed00SAndrew Rybchenko 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_RXDP_HLB_FETCH_CONDITIONS, &value);
8499573ed00SAndrew Rybchenko 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_RXDP_HLB_FETCH]), &value);
8509573ed00SAndrew Rybchenko 
8519573ed00SAndrew Rybchenko 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_RXDP_HLB_WAIT_CONDITIONS, &value);
8529573ed00SAndrew Rybchenko 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_RXDP_HLB_WAIT]), &value);
8539573ed00SAndrew Rybchenko 
8549573ed00SAndrew Rybchenko 	/* VADAPTER RX */
8559573ed00SAndrew Rybchenko 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_VADAPTER_RX_UNICAST_PACKETS,
8569573ed00SAndrew Rybchenko 	    &value);
8579573ed00SAndrew Rybchenko 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_VADAPTER_RX_UNICAST_PACKETS]),
8589573ed00SAndrew Rybchenko 	    &value);
8599573ed00SAndrew Rybchenko 
8609573ed00SAndrew Rybchenko 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_VADAPTER_RX_UNICAST_BYTES,
8619573ed00SAndrew Rybchenko 	    &value);
8629573ed00SAndrew Rybchenko 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_VADAPTER_RX_UNICAST_BYTES]),
8639573ed00SAndrew Rybchenko 	    &value);
8649573ed00SAndrew Rybchenko 
8659573ed00SAndrew Rybchenko 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_VADAPTER_RX_MULTICAST_PACKETS,
8669573ed00SAndrew Rybchenko 	    &value);
8679573ed00SAndrew Rybchenko 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_VADAPTER_RX_MULTICAST_PACKETS]),
8689573ed00SAndrew Rybchenko 	    &value);
8699573ed00SAndrew Rybchenko 
8709573ed00SAndrew Rybchenko 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_VADAPTER_RX_MULTICAST_BYTES,
8719573ed00SAndrew Rybchenko 	    &value);
8729573ed00SAndrew Rybchenko 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_VADAPTER_RX_MULTICAST_BYTES]),
8739573ed00SAndrew Rybchenko 	    &value);
8749573ed00SAndrew Rybchenko 
8759573ed00SAndrew Rybchenko 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_VADAPTER_RX_BROADCAST_PACKETS,
8769573ed00SAndrew Rybchenko 	    &value);
8779573ed00SAndrew Rybchenko 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_VADAPTER_RX_BROADCAST_PACKETS]),
8789573ed00SAndrew Rybchenko 	    &value);
8799573ed00SAndrew Rybchenko 
8809573ed00SAndrew Rybchenko 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_VADAPTER_RX_BROADCAST_BYTES,
8819573ed00SAndrew Rybchenko 	    &value);
8829573ed00SAndrew Rybchenko 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_VADAPTER_RX_BROADCAST_BYTES]),
8839573ed00SAndrew Rybchenko 	    &value);
8849573ed00SAndrew Rybchenko 
8859573ed00SAndrew Rybchenko 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_VADAPTER_RX_BAD_PACKETS,
8869573ed00SAndrew Rybchenko 	    &value);
8879573ed00SAndrew Rybchenko 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_VADAPTER_RX_BAD_PACKETS]),
8889573ed00SAndrew Rybchenko 	    &value);
8899573ed00SAndrew Rybchenko 
8909573ed00SAndrew Rybchenko 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_VADAPTER_RX_BAD_BYTES, &value);
8919573ed00SAndrew Rybchenko 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_VADAPTER_RX_BAD_BYTES]), &value);
8929573ed00SAndrew Rybchenko 
8939573ed00SAndrew Rybchenko 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_VADAPTER_RX_OVERFLOW, &value);
8949573ed00SAndrew Rybchenko 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_VADAPTER_RX_OVERFLOW]), &value);
8959573ed00SAndrew Rybchenko 
8969573ed00SAndrew Rybchenko 	/* VADAPTER TX */
8979573ed00SAndrew Rybchenko 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_VADAPTER_TX_UNICAST_PACKETS,
8989573ed00SAndrew Rybchenko 	    &value);
8999573ed00SAndrew Rybchenko 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_VADAPTER_TX_UNICAST_PACKETS]),
9009573ed00SAndrew Rybchenko 	    &value);
9019573ed00SAndrew Rybchenko 
9029573ed00SAndrew Rybchenko 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_VADAPTER_TX_UNICAST_BYTES,
9039573ed00SAndrew Rybchenko 	    &value);
9049573ed00SAndrew Rybchenko 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_VADAPTER_TX_UNICAST_BYTES]),
9059573ed00SAndrew Rybchenko 	    &value);
9069573ed00SAndrew Rybchenko 
9079573ed00SAndrew Rybchenko 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_VADAPTER_TX_MULTICAST_PACKETS,
9089573ed00SAndrew Rybchenko 	    &value);
9099573ed00SAndrew Rybchenko 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_VADAPTER_TX_MULTICAST_PACKETS]),
9109573ed00SAndrew Rybchenko 	    &value);
9119573ed00SAndrew Rybchenko 
9129573ed00SAndrew Rybchenko 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_VADAPTER_TX_MULTICAST_BYTES,
9139573ed00SAndrew Rybchenko 	    &value);
9149573ed00SAndrew Rybchenko 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_VADAPTER_TX_MULTICAST_BYTES]),
9159573ed00SAndrew Rybchenko 	    &value);
9169573ed00SAndrew Rybchenko 
9179573ed00SAndrew Rybchenko 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_VADAPTER_TX_BROADCAST_PACKETS,
9189573ed00SAndrew Rybchenko 	    &value);
9199573ed00SAndrew Rybchenko 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_VADAPTER_TX_BROADCAST_PACKETS]),
9209573ed00SAndrew Rybchenko 	    &value);
9219573ed00SAndrew Rybchenko 
9229573ed00SAndrew Rybchenko 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_VADAPTER_TX_BROADCAST_BYTES,
9239573ed00SAndrew Rybchenko 	    &value);
9249573ed00SAndrew Rybchenko 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_VADAPTER_TX_BROADCAST_BYTES]),
9259573ed00SAndrew Rybchenko 	    &value);
9269573ed00SAndrew Rybchenko 
9279573ed00SAndrew Rybchenko 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_VADAPTER_TX_BAD_PACKETS, &value);
9289573ed00SAndrew Rybchenko 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_VADAPTER_TX_BAD_PACKETS]), &value);
9299573ed00SAndrew Rybchenko 
9309573ed00SAndrew Rybchenko 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_VADAPTER_TX_BAD_BYTES, &value);
9319573ed00SAndrew Rybchenko 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_VADAPTER_TX_BAD_BYTES]), &value);
9329573ed00SAndrew Rybchenko 
9339573ed00SAndrew Rybchenko 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_VADAPTER_TX_OVERFLOW, &value);
9349573ed00SAndrew Rybchenko 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_VADAPTER_TX_OVERFLOW]), &value);
9359573ed00SAndrew Rybchenko 
936747819d2SAndrew Rybchenko 	if (encp->enc_mac_stats_nstats < MC_CMD_MAC_NSTATS_V2)
937747819d2SAndrew Rybchenko 		goto done;
938747819d2SAndrew Rybchenko 
939747819d2SAndrew Rybchenko 	/* FEC */
940747819d2SAndrew Rybchenko 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_FEC_UNCORRECTED_ERRORS, &value);
941747819d2SAndrew Rybchenko 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_FEC_UNCORRECTED_ERRORS]), &value);
942747819d2SAndrew Rybchenko 
943747819d2SAndrew Rybchenko 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_FEC_CORRECTED_ERRORS, &value);
944747819d2SAndrew Rybchenko 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_FEC_CORRECTED_ERRORS]), &value);
945747819d2SAndrew Rybchenko 
946747819d2SAndrew Rybchenko 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_FEC_CORRECTED_SYMBOLS_LANE0,
947747819d2SAndrew Rybchenko 	    &value);
948747819d2SAndrew Rybchenko 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_FEC_CORRECTED_SYMBOLS_LANE0]),
949747819d2SAndrew Rybchenko 	    &value);
950747819d2SAndrew Rybchenko 
951747819d2SAndrew Rybchenko 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_FEC_CORRECTED_SYMBOLS_LANE1,
952747819d2SAndrew Rybchenko 	    &value);
953747819d2SAndrew Rybchenko 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_FEC_CORRECTED_SYMBOLS_LANE1]),
954747819d2SAndrew Rybchenko 	    &value);
955747819d2SAndrew Rybchenko 
956747819d2SAndrew Rybchenko 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_FEC_CORRECTED_SYMBOLS_LANE2,
957747819d2SAndrew Rybchenko 	    &value);
958747819d2SAndrew Rybchenko 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_FEC_CORRECTED_SYMBOLS_LANE2]),
959747819d2SAndrew Rybchenko 	    &value);
960747819d2SAndrew Rybchenko 
961747819d2SAndrew Rybchenko 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_FEC_CORRECTED_SYMBOLS_LANE3,
962747819d2SAndrew Rybchenko 	    &value);
963747819d2SAndrew Rybchenko 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_FEC_CORRECTED_SYMBOLS_LANE3]),
964747819d2SAndrew Rybchenko 	    &value);
965747819d2SAndrew Rybchenko 
96674d36c84SAndrew Rybchenko 	if (encp->enc_mac_stats_nstats < MC_CMD_MAC_NSTATS_V3)
96774d36c84SAndrew Rybchenko 		goto done;
96874d36c84SAndrew Rybchenko 
96974d36c84SAndrew Rybchenko 	/* CTPIO exceptions */
97074d36c84SAndrew Rybchenko 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_CTPIO_VI_BUSY_FALLBACK, &value);
97174d36c84SAndrew Rybchenko 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_CTPIO_VI_BUSY_FALLBACK]), &value);
97274d36c84SAndrew Rybchenko 
97374d36c84SAndrew Rybchenko 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_CTPIO_LONG_WRITE_SUCCESS, &value);
97474d36c84SAndrew Rybchenko 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_CTPIO_LONG_WRITE_SUCCESS]), &value);
97574d36c84SAndrew Rybchenko 
97674d36c84SAndrew Rybchenko 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_CTPIO_MISSING_DBELL_FAIL, &value);
97774d36c84SAndrew Rybchenko 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_CTPIO_MISSING_DBELL_FAIL]), &value);
97874d36c84SAndrew Rybchenko 
97974d36c84SAndrew Rybchenko 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_CTPIO_OVERFLOW_FAIL, &value);
98074d36c84SAndrew Rybchenko 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_CTPIO_OVERFLOW_FAIL]), &value);
98174d36c84SAndrew Rybchenko 
98274d36c84SAndrew Rybchenko 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_CTPIO_UNDERFLOW_FAIL, &value);
98374d36c84SAndrew Rybchenko 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_CTPIO_UNDERFLOW_FAIL]), &value);
98474d36c84SAndrew Rybchenko 
98574d36c84SAndrew Rybchenko 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_CTPIO_TIMEOUT_FAIL, &value);
98674d36c84SAndrew Rybchenko 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_CTPIO_TIMEOUT_FAIL]), &value);
98774d36c84SAndrew Rybchenko 
98874d36c84SAndrew Rybchenko 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_CTPIO_NONCONTIG_WR_FAIL, &value);
98974d36c84SAndrew Rybchenko 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_CTPIO_NONCONTIG_WR_FAIL]), &value);
99074d36c84SAndrew Rybchenko 
99174d36c84SAndrew Rybchenko 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_CTPIO_FRM_CLOBBER_FAIL, &value);
99274d36c84SAndrew Rybchenko 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_CTPIO_FRM_CLOBBER_FAIL]), &value);
99374d36c84SAndrew Rybchenko 
99474d36c84SAndrew Rybchenko 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_CTPIO_INVALID_WR_FAIL, &value);
99574d36c84SAndrew Rybchenko 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_CTPIO_INVALID_WR_FAIL]), &value);
99674d36c84SAndrew Rybchenko 
99774d36c84SAndrew Rybchenko 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_CTPIO_VI_CLOBBER_FALLBACK, &value);
99874d36c84SAndrew Rybchenko 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_CTPIO_VI_CLOBBER_FALLBACK]),
99974d36c84SAndrew Rybchenko 	    &value);
100074d36c84SAndrew Rybchenko 
100174d36c84SAndrew Rybchenko 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_CTPIO_UNQUALIFIED_FALLBACK, &value);
100274d36c84SAndrew Rybchenko 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_CTPIO_UNQUALIFIED_FALLBACK]),
100374d36c84SAndrew Rybchenko 	    &value);
100474d36c84SAndrew Rybchenko 
100574d36c84SAndrew Rybchenko 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_CTPIO_RUNT_FALLBACK, &value);
100674d36c84SAndrew Rybchenko 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_CTPIO_RUNT_FALLBACK]), &value);
100774d36c84SAndrew Rybchenko 
100874d36c84SAndrew Rybchenko 	/* CTPIO per-port stats */
100974d36c84SAndrew Rybchenko 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_CTPIO_SUCCESS, &value);
101074d36c84SAndrew Rybchenko 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_CTPIO_SUCCESS]), &value);
101174d36c84SAndrew Rybchenko 
101274d36c84SAndrew Rybchenko 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_CTPIO_FALLBACK, &value);
101374d36c84SAndrew Rybchenko 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_CTPIO_FALLBACK]), &value);
101474d36c84SAndrew Rybchenko 
101574d36c84SAndrew Rybchenko 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_CTPIO_POISON, &value);
101674d36c84SAndrew Rybchenko 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_CTPIO_POISON]), &value);
101774d36c84SAndrew Rybchenko 
101874d36c84SAndrew Rybchenko 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_CTPIO_ERASE, &value);
101974d36c84SAndrew Rybchenko 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_CTPIO_ERASE]), &value);
102074d36c84SAndrew Rybchenko 
1021ef8967c7SAndrew Rybchenko 	if (encp->enc_mac_stats_nstats < MC_CMD_MAC_NSTATS_V4)
1022ef8967c7SAndrew Rybchenko 		goto done;
1023ef8967c7SAndrew Rybchenko 
1024ef8967c7SAndrew Rybchenko 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_RXDP_SCATTER_DISABLED_TRUNC,
1025ef8967c7SAndrew Rybchenko 	    &value);
1026ef8967c7SAndrew Rybchenko 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_RXDP_SCATTER_DISABLED_TRUNC]),
1027ef8967c7SAndrew Rybchenko 	    &value);
1028ef8967c7SAndrew Rybchenko 
1029aea9d093SAndrew Rybchenko 	/* Head-of-line blocking */
1030aea9d093SAndrew Rybchenko 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_RXDP_HLB_IDLE, &value);
1031aea9d093SAndrew Rybchenko 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_RXDP_HLB_IDLE]), &value);
1032aea9d093SAndrew Rybchenko 
1033aea9d093SAndrew Rybchenko 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_RXDP_HLB_TIMEOUT, &value);
1034aea9d093SAndrew Rybchenko 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_RXDP_HLB_TIMEOUT]), &value);
1035aea9d093SAndrew Rybchenko 
1036747819d2SAndrew Rybchenko done:
1037fdfd8bfeSAndrew Rybchenko 	/* Read START generation counter */
1038fdfd8bfeSAndrew Rybchenko 	EFSYS_DMA_SYNC_FOR_KERNEL(esmp, 0, EFSYS_MEM_SIZE(esmp));
10399573ed00SAndrew Rybchenko 	EFSYS_MEM_READ_BARRIER();
10409573ed00SAndrew Rybchenko 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_GENERATION_START,
10419573ed00SAndrew Rybchenko 			    &generation_start);
10429573ed00SAndrew Rybchenko 
10439573ed00SAndrew Rybchenko 	/* Check that we didn't read the stats in the middle of a DMA */
10449573ed00SAndrew Rybchenko 	/* Not a good enough check ? */
10459573ed00SAndrew Rybchenko 	if (memcmp(&generation_start, &generation_end,
10469573ed00SAndrew Rybchenko 	    sizeof (generation_start)))
10479573ed00SAndrew Rybchenko 		return (EAGAIN);
10489573ed00SAndrew Rybchenko 
10499573ed00SAndrew Rybchenko 	if (generationp)
10509573ed00SAndrew Rybchenko 		*generationp = EFX_QWORD_FIELD(generation_start, EFX_DWORD_0);
10519573ed00SAndrew Rybchenko 
10529573ed00SAndrew Rybchenko 	return (0);
1053fdfd8bfeSAndrew Rybchenko 
1054fdfd8bfeSAndrew Rybchenko fail2:
1055fdfd8bfeSAndrew Rybchenko 	EFSYS_PROBE(fail2);
1056fdfd8bfeSAndrew Rybchenko fail1:
1057fdfd8bfeSAndrew Rybchenko 	EFSYS_PROBE1(fail1, efx_rc_t, rc);
1058fdfd8bfeSAndrew Rybchenko 
1059fdfd8bfeSAndrew Rybchenko 	return (rc);
10609573ed00SAndrew Rybchenko }
10619573ed00SAndrew Rybchenko 
10629573ed00SAndrew Rybchenko #endif	/* EFSYS_OPT_MAC_STATS */
10639573ed00SAndrew Rybchenko 
1064cbc3f94fSAndrew Rybchenko #endif	/* EFSYS_OPT_HUNTINGTON || EFSYS_OPT_MEDFORD || EFSYS_OPT_MEDFORD2 */
1065