1*49ef7e06SGarrett D'Amore /*
2*49ef7e06SGarrett D'Amore  * Copyright (c) 2012-2015 Solarflare Communications Inc.
3*49ef7e06SGarrett D'Amore  * All rights reserved.
4*49ef7e06SGarrett D'Amore  *
5*49ef7e06SGarrett D'Amore  * Redistribution and use in source and binary forms, with or without
6*49ef7e06SGarrett D'Amore  * modification, are permitted provided that the following conditions are met:
7*49ef7e06SGarrett D'Amore  *
8*49ef7e06SGarrett D'Amore  * 1. Redistributions of source code must retain the above copyright notice,
9*49ef7e06SGarrett D'Amore  *    this list of conditions and the following disclaimer.
10*49ef7e06SGarrett D'Amore  * 2. Redistributions in binary form must reproduce the above copyright notice,
11*49ef7e06SGarrett D'Amore  *    this list of conditions and the following disclaimer in the documentation
12*49ef7e06SGarrett D'Amore  *    and/or other materials provided with the distribution.
13*49ef7e06SGarrett D'Amore  *
14*49ef7e06SGarrett D'Amore  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15*49ef7e06SGarrett D'Amore  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
16*49ef7e06SGarrett D'Amore  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17*49ef7e06SGarrett D'Amore  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
18*49ef7e06SGarrett D'Amore  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19*49ef7e06SGarrett D'Amore  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20*49ef7e06SGarrett D'Amore  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
21*49ef7e06SGarrett D'Amore  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
22*49ef7e06SGarrett D'Amore  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23*49ef7e06SGarrett D'Amore  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
24*49ef7e06SGarrett D'Amore  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25*49ef7e06SGarrett D'Amore  *
26*49ef7e06SGarrett D'Amore  * The views and conclusions contained in the software and documentation are
27*49ef7e06SGarrett D'Amore  * those of the authors and should not be interpreted as representing official
28*49ef7e06SGarrett D'Amore  * policies, either expressed or implied, of the FreeBSD Project.
29*49ef7e06SGarrett D'Amore  */
30*49ef7e06SGarrett D'Amore 
31*49ef7e06SGarrett D'Amore #include "efx.h"
32*49ef7e06SGarrett D'Amore #include "efx_impl.h"
33*49ef7e06SGarrett D'Amore 
34*49ef7e06SGarrett D'Amore 
35*49ef7e06SGarrett D'Amore #if EFSYS_OPT_HUNTINGTON || EFSYS_OPT_MEDFORD
36*49ef7e06SGarrett D'Amore 
37*49ef7e06SGarrett D'Amore 	__checkReturn	efx_rc_t
ef10_mac_poll(__in efx_nic_t * enp,__out efx_link_mode_t * link_modep)38*49ef7e06SGarrett D'Amore ef10_mac_poll(
39*49ef7e06SGarrett D'Amore 	__in		efx_nic_t *enp,
40*49ef7e06SGarrett D'Amore 	__out		efx_link_mode_t *link_modep)
41*49ef7e06SGarrett D'Amore {
42*49ef7e06SGarrett D'Amore 	efx_port_t *epp = &(enp->en_port);
43*49ef7e06SGarrett D'Amore 	ef10_link_state_t els;
44*49ef7e06SGarrett D'Amore 	efx_rc_t rc;
45*49ef7e06SGarrett D'Amore 
46*49ef7e06SGarrett D'Amore 	if ((rc = ef10_phy_get_link(enp, &els)) != 0)
47*49ef7e06SGarrett D'Amore 		goto fail1;
48*49ef7e06SGarrett D'Amore 
49*49ef7e06SGarrett D'Amore 	epp->ep_adv_cap_mask = els.els_adv_cap_mask;
50*49ef7e06SGarrett D'Amore 	epp->ep_fcntl = els.els_fcntl;
51*49ef7e06SGarrett D'Amore 
52*49ef7e06SGarrett D'Amore 	*link_modep = els.els_link_mode;
53*49ef7e06SGarrett D'Amore 
54*49ef7e06SGarrett D'Amore 	return (0);
55*49ef7e06SGarrett D'Amore 
56*49ef7e06SGarrett D'Amore fail1:
57*49ef7e06SGarrett D'Amore 	EFSYS_PROBE1(fail1, efx_rc_t, rc);
58*49ef7e06SGarrett D'Amore 
59*49ef7e06SGarrett D'Amore 	*link_modep = EFX_LINK_UNKNOWN;
60*49ef7e06SGarrett D'Amore 
61*49ef7e06SGarrett D'Amore 	return (rc);
62*49ef7e06SGarrett D'Amore }
63*49ef7e06SGarrett D'Amore 
64*49ef7e06SGarrett D'Amore 	__checkReturn	efx_rc_t
ef10_mac_up(__in efx_nic_t * enp,__out boolean_t * mac_upp)65*49ef7e06SGarrett D'Amore ef10_mac_up(
66*49ef7e06SGarrett D'Amore 	__in		efx_nic_t *enp,
67*49ef7e06SGarrett D'Amore 	__out		boolean_t *mac_upp)
68*49ef7e06SGarrett D'Amore {
69*49ef7e06SGarrett D'Amore 	ef10_link_state_t els;
70*49ef7e06SGarrett D'Amore 	efx_rc_t rc;
71*49ef7e06SGarrett D'Amore 
72*49ef7e06SGarrett D'Amore 	/*
73*49ef7e06SGarrett D'Amore 	 * Because EF10 doesn't *require* polling, we can't rely on
74*49ef7e06SGarrett D'Amore 	 * ef10_mac_poll() being executed to populate epp->ep_mac_up.
75*49ef7e06SGarrett D'Amore 	 */
76*49ef7e06SGarrett D'Amore 	if ((rc = ef10_phy_get_link(enp, &els)) != 0)
77*49ef7e06SGarrett D'Amore 		goto fail1;
78*49ef7e06SGarrett D'Amore 
79*49ef7e06SGarrett D'Amore 	*mac_upp = els.els_mac_up;
80*49ef7e06SGarrett D'Amore 
81*49ef7e06SGarrett D'Amore 	return (0);
82*49ef7e06SGarrett D'Amore 
83*49ef7e06SGarrett D'Amore fail1:
84*49ef7e06SGarrett D'Amore 	EFSYS_PROBE1(fail1, efx_rc_t, rc);
85*49ef7e06SGarrett D'Amore 
86*49ef7e06SGarrett D'Amore 	return (rc);
87*49ef7e06SGarrett D'Amore }
88*49ef7e06SGarrett D'Amore 
89*49ef7e06SGarrett D'Amore /*
90*49ef7e06SGarrett D'Amore  * EF10 adapters use MC_CMD_VADAPTOR_SET_MAC to set the
91*49ef7e06SGarrett D'Amore  * MAC address; the address field in MC_CMD_SET_MAC has no
92*49ef7e06SGarrett D'Amore  * effect.
93*49ef7e06SGarrett D'Amore  * MC_CMD_VADAPTOR_SET_MAC requires mac-spoofing privilege and
94*49ef7e06SGarrett D'Amore  * the port to have no filters or queues active.
95*49ef7e06SGarrett D'Amore  */
96*49ef7e06SGarrett D'Amore static	__checkReturn	efx_rc_t
efx_mcdi_vadapter_set_mac(__in efx_nic_t * enp)97*49ef7e06SGarrett D'Amore efx_mcdi_vadapter_set_mac(
98*49ef7e06SGarrett D'Amore 	__in		efx_nic_t *enp)
99*49ef7e06SGarrett D'Amore {
100*49ef7e06SGarrett D'Amore 	efx_port_t *epp = &(enp->en_port);
101*49ef7e06SGarrett D'Amore 	efx_mcdi_req_t req;
102*49ef7e06SGarrett D'Amore 	uint8_t payload[MAX(MC_CMD_VADAPTOR_SET_MAC_IN_LEN,
103*49ef7e06SGarrett D'Amore 			    MC_CMD_VADAPTOR_SET_MAC_OUT_LEN)];
104*49ef7e06SGarrett D'Amore 	efx_rc_t rc;
105*49ef7e06SGarrett D'Amore 
106*49ef7e06SGarrett D'Amore 	(void) memset(payload, 0, sizeof (payload));
107*49ef7e06SGarrett D'Amore 	req.emr_cmd = MC_CMD_VADAPTOR_SET_MAC;
108*49ef7e06SGarrett D'Amore 	req.emr_in_buf = payload;
109*49ef7e06SGarrett D'Amore 	req.emr_in_length = MC_CMD_VADAPTOR_SET_MAC_IN_LEN;
110*49ef7e06SGarrett D'Amore 	req.emr_out_buf = payload;
111*49ef7e06SGarrett D'Amore 	req.emr_out_length = MC_CMD_VADAPTOR_SET_MAC_OUT_LEN;
112*49ef7e06SGarrett D'Amore 
113*49ef7e06SGarrett D'Amore 	MCDI_IN_SET_DWORD(req, VADAPTOR_SET_MAC_IN_UPSTREAM_PORT_ID,
114*49ef7e06SGarrett D'Amore 	    enp->en_vport_id);
115*49ef7e06SGarrett D'Amore 	EFX_MAC_ADDR_COPY(MCDI_IN2(req, uint8_t, VADAPTOR_SET_MAC_IN_MACADDR),
116*49ef7e06SGarrett D'Amore 	    epp->ep_mac_addr);
117*49ef7e06SGarrett D'Amore 
118*49ef7e06SGarrett D'Amore 	efx_mcdi_execute(enp, &req);
119*49ef7e06SGarrett D'Amore 
120*49ef7e06SGarrett D'Amore 	if (req.emr_rc != 0) {
121*49ef7e06SGarrett D'Amore 		rc = req.emr_rc;
122*49ef7e06SGarrett D'Amore 		goto fail1;
123*49ef7e06SGarrett D'Amore 	}
124*49ef7e06SGarrett D'Amore 
125*49ef7e06SGarrett D'Amore 	return (0);
126*49ef7e06SGarrett D'Amore 
127*49ef7e06SGarrett D'Amore fail1:
128*49ef7e06SGarrett D'Amore 	EFSYS_PROBE1(fail1, efx_rc_t, rc);
129*49ef7e06SGarrett D'Amore 
130*49ef7e06SGarrett D'Amore 	return (rc);
131*49ef7e06SGarrett D'Amore }
132*49ef7e06SGarrett D'Amore 
133*49ef7e06SGarrett D'Amore 	__checkReturn	efx_rc_t
ef10_mac_addr_set(__in efx_nic_t * enp)134*49ef7e06SGarrett D'Amore ef10_mac_addr_set(
135*49ef7e06SGarrett D'Amore 	__in		efx_nic_t *enp)
136*49ef7e06SGarrett D'Amore {
137*49ef7e06SGarrett D'Amore 	efx_rc_t rc;
138*49ef7e06SGarrett D'Amore 
139*49ef7e06SGarrett D'Amore 	if ((rc = efx_mcdi_vadapter_set_mac(enp)) != 0) {
140*49ef7e06SGarrett D'Amore 		if (rc != ENOTSUP)
141*49ef7e06SGarrett D'Amore 			goto fail1;
142*49ef7e06SGarrett D'Amore 
143*49ef7e06SGarrett D'Amore 		/*
144*49ef7e06SGarrett D'Amore 		 * Fallback for older Huntington firmware without Vadapter
145*49ef7e06SGarrett D'Amore 		 * support.
146*49ef7e06SGarrett D'Amore 		 */
147*49ef7e06SGarrett D'Amore 		if ((rc = ef10_mac_reconfigure(enp)) != 0)
148*49ef7e06SGarrett D'Amore 			goto fail2;
149*49ef7e06SGarrett D'Amore 	}
150*49ef7e06SGarrett D'Amore 
151*49ef7e06SGarrett D'Amore 	return (0);
152*49ef7e06SGarrett D'Amore 
153*49ef7e06SGarrett D'Amore fail2:
154*49ef7e06SGarrett D'Amore 	EFSYS_PROBE(fail2);
155*49ef7e06SGarrett D'Amore 
156*49ef7e06SGarrett D'Amore fail1:
157*49ef7e06SGarrett D'Amore 	EFSYS_PROBE1(fail1, efx_rc_t, rc);
158*49ef7e06SGarrett D'Amore 
159*49ef7e06SGarrett D'Amore 	return (rc);
160*49ef7e06SGarrett D'Amore }
161*49ef7e06SGarrett D'Amore 
162*49ef7e06SGarrett D'Amore static	__checkReturn	efx_rc_t
efx_mcdi_mtu_set(__in efx_nic_t * enp,__in uint32_t mtu)163*49ef7e06SGarrett D'Amore efx_mcdi_mtu_set(
164*49ef7e06SGarrett D'Amore 	__in		efx_nic_t *enp,
165*49ef7e06SGarrett D'Amore 	__in		uint32_t mtu)
166*49ef7e06SGarrett D'Amore {
167*49ef7e06SGarrett D'Amore 	efx_mcdi_req_t req;
168*49ef7e06SGarrett D'Amore 	uint8_t payload[MAX(MC_CMD_SET_MAC_EXT_IN_LEN,
169*49ef7e06SGarrett D'Amore 			    MC_CMD_SET_MAC_OUT_LEN)];
170*49ef7e06SGarrett D'Amore 	efx_rc_t rc;
171*49ef7e06SGarrett D'Amore 
172*49ef7e06SGarrett D'Amore 	(void) memset(payload, 0, sizeof (payload));
173*49ef7e06SGarrett D'Amore 	req.emr_cmd = MC_CMD_SET_MAC;
174*49ef7e06SGarrett D'Amore 	req.emr_in_buf = payload;
175*49ef7e06SGarrett D'Amore 	req.emr_in_length = MC_CMD_SET_MAC_EXT_IN_LEN;
176*49ef7e06SGarrett D'Amore 	req.emr_out_buf = payload;
177*49ef7e06SGarrett D'Amore 	req.emr_out_length = MC_CMD_SET_MAC_OUT_LEN;
178*49ef7e06SGarrett D'Amore 
179*49ef7e06SGarrett D'Amore 	/* Only configure the MTU in this call to MC_CMD_SET_MAC */
180*49ef7e06SGarrett D'Amore 	MCDI_IN_SET_DWORD(req, SET_MAC_EXT_IN_MTU, mtu);
181*49ef7e06SGarrett D'Amore 	MCDI_IN_POPULATE_DWORD_1(req, SET_MAC_EXT_IN_CONTROL,
182*49ef7e06SGarrett D'Amore 			    SET_MAC_EXT_IN_CFG_MTU, 1);
183*49ef7e06SGarrett D'Amore 
184*49ef7e06SGarrett D'Amore 	efx_mcdi_execute(enp, &req);
185*49ef7e06SGarrett D'Amore 
186*49ef7e06SGarrett D'Amore 	if (req.emr_rc != 0) {
187*49ef7e06SGarrett D'Amore 		rc = req.emr_rc;
188*49ef7e06SGarrett D'Amore 		goto fail1;
189*49ef7e06SGarrett D'Amore 	}
190*49ef7e06SGarrett D'Amore 
191*49ef7e06SGarrett D'Amore 	return (0);
192*49ef7e06SGarrett D'Amore 
193*49ef7e06SGarrett D'Amore fail1:
194*49ef7e06SGarrett D'Amore 	EFSYS_PROBE1(fail1, efx_rc_t, rc);
195*49ef7e06SGarrett D'Amore 
196*49ef7e06SGarrett D'Amore 	return (rc);
197*49ef7e06SGarrett D'Amore }
198*49ef7e06SGarrett D'Amore 
199*49ef7e06SGarrett D'Amore 	__checkReturn	efx_rc_t
ef10_mac_pdu_set(__in efx_nic_t * enp)200*49ef7e06SGarrett D'Amore ef10_mac_pdu_set(
201*49ef7e06SGarrett D'Amore 	__in		efx_nic_t *enp)
202*49ef7e06SGarrett D'Amore {
203*49ef7e06SGarrett D'Amore 	efx_port_t *epp = &(enp->en_port);
204*49ef7e06SGarrett D'Amore 	efx_nic_cfg_t *encp = &(enp->en_nic_cfg);
205*49ef7e06SGarrett D'Amore 	efx_rc_t rc;
206*49ef7e06SGarrett D'Amore 
207*49ef7e06SGarrett D'Amore 	if (encp->enc_enhanced_set_mac_supported) {
208*49ef7e06SGarrett D'Amore 		if ((rc = efx_mcdi_mtu_set(enp, epp->ep_mac_pdu)) != 0)
209*49ef7e06SGarrett D'Amore 			goto fail1;
210*49ef7e06SGarrett D'Amore 	} else {
211*49ef7e06SGarrett D'Amore 		/*
212*49ef7e06SGarrett D'Amore 		 * Fallback for older Huntington firmware, which always
213*49ef7e06SGarrett D'Amore 		 * configure all of the parameters to MC_CMD_SET_MAC. This isn't
214*49ef7e06SGarrett D'Amore 		 * suitable for setting the MTU on unpriviliged functions.
215*49ef7e06SGarrett D'Amore 		 */
216*49ef7e06SGarrett D'Amore 		if ((rc = ef10_mac_reconfigure(enp)) != 0)
217*49ef7e06SGarrett D'Amore 			goto fail2;
218*49ef7e06SGarrett D'Amore 	}
219*49ef7e06SGarrett D'Amore 
220*49ef7e06SGarrett D'Amore 	return (0);
221*49ef7e06SGarrett D'Amore 
222*49ef7e06SGarrett D'Amore fail2:
223*49ef7e06SGarrett D'Amore 	EFSYS_PROBE(fail2);
224*49ef7e06SGarrett D'Amore fail1:
225*49ef7e06SGarrett D'Amore 	EFSYS_PROBE1(fail1, efx_rc_t, rc);
226*49ef7e06SGarrett D'Amore 
227*49ef7e06SGarrett D'Amore 	return (rc);
228*49ef7e06SGarrett D'Amore }
229*49ef7e06SGarrett D'Amore 
230*49ef7e06SGarrett D'Amore __checkReturn	efx_rc_t
ef10_mac_reconfigure(__in efx_nic_t * enp)231*49ef7e06SGarrett D'Amore ef10_mac_reconfigure(
232*49ef7e06SGarrett D'Amore 	__in		efx_nic_t *enp)
233*49ef7e06SGarrett D'Amore {
234*49ef7e06SGarrett D'Amore 	efx_port_t *epp = &(enp->en_port);
235*49ef7e06SGarrett D'Amore 	efx_mcdi_req_t req;
236*49ef7e06SGarrett D'Amore 	uint8_t payload[MAX(MC_CMD_SET_MAC_IN_LEN,
237*49ef7e06SGarrett D'Amore 			    MC_CMD_SET_MAC_OUT_LEN)];
238*49ef7e06SGarrett D'Amore 	efx_rc_t rc;
239*49ef7e06SGarrett D'Amore 
240*49ef7e06SGarrett D'Amore 	(void) memset(payload, 0, sizeof (payload));
241*49ef7e06SGarrett D'Amore 	req.emr_cmd = MC_CMD_SET_MAC;
242*49ef7e06SGarrett D'Amore 	req.emr_in_buf = payload;
243*49ef7e06SGarrett D'Amore 	req.emr_in_length = MC_CMD_SET_MAC_IN_LEN;
244*49ef7e06SGarrett D'Amore 	req.emr_out_buf = payload;
245*49ef7e06SGarrett D'Amore 	req.emr_out_length = MC_CMD_SET_MAC_OUT_LEN;
246*49ef7e06SGarrett D'Amore 
247*49ef7e06SGarrett D'Amore 	MCDI_IN_SET_DWORD(req, SET_MAC_IN_MTU, epp->ep_mac_pdu);
248*49ef7e06SGarrett D'Amore 	MCDI_IN_SET_DWORD(req, SET_MAC_IN_DRAIN, epp->ep_mac_drain ? 1 : 0);
249*49ef7e06SGarrett D'Amore 	EFX_MAC_ADDR_COPY(MCDI_IN2(req, uint8_t, SET_MAC_IN_ADDR),
250*49ef7e06SGarrett D'Amore 			    epp->ep_mac_addr);
251*49ef7e06SGarrett D'Amore 
252*49ef7e06SGarrett D'Amore 	/*
253*49ef7e06SGarrett D'Amore 	 * Note: The Huntington MAC does not support REJECT_BRDCST.
254*49ef7e06SGarrett D'Amore 	 * The REJECT_UNCST flag will also prevent multicast traffic
255*49ef7e06SGarrett D'Amore 	 * from reaching the filters. As Huntington filters drop any
256*49ef7e06SGarrett D'Amore 	 * traffic that does not match a filter it is ok to leave the
257*49ef7e06SGarrett D'Amore 	 * MAC running in promiscuous mode. See bug41141.
258*49ef7e06SGarrett D'Amore 	 *
259*49ef7e06SGarrett D'Amore 	 * FIXME: Does REJECT_UNCST behave the same way on Medford?
260*49ef7e06SGarrett D'Amore 	 */
261*49ef7e06SGarrett D'Amore 	MCDI_IN_POPULATE_DWORD_2(req, SET_MAC_IN_REJECT,
262*49ef7e06SGarrett D'Amore 				    SET_MAC_IN_REJECT_UNCST, 0,
263*49ef7e06SGarrett D'Amore 				    SET_MAC_IN_REJECT_BRDCST, 0);
264*49ef7e06SGarrett D'Amore 
265*49ef7e06SGarrett D'Amore 	/*
266*49ef7e06SGarrett D'Amore 	 * Flow control, whether it is auto-negotiated or not,
267*49ef7e06SGarrett D'Amore 	 * is set via the PHY advertised capabilities.  When set to
268*49ef7e06SGarrett D'Amore 	 * automatic the MAC will use the PHY settings to determine
269*49ef7e06SGarrett D'Amore 	 * the flow control settings.
270*49ef7e06SGarrett D'Amore 	 */
271*49ef7e06SGarrett D'Amore 	MCDI_IN_SET_DWORD(req, SET_MAC_IN_FCNTL, MC_CMD_FCNTL_AUTO);
272*49ef7e06SGarrett D'Amore 
273*49ef7e06SGarrett D'Amore 	/* Do not include the Ethernet frame checksum in RX packets */
274*49ef7e06SGarrett D'Amore 	MCDI_IN_POPULATE_DWORD_1(req, SET_MAC_IN_FLAGS,
275*49ef7e06SGarrett D'Amore 				    SET_MAC_IN_FLAG_INCLUDE_FCS, 0);
276*49ef7e06SGarrett D'Amore 
277*49ef7e06SGarrett D'Amore 	efx_mcdi_execute_quiet(enp, &req);
278*49ef7e06SGarrett D'Amore 
279*49ef7e06SGarrett D'Amore 	if (req.emr_rc != 0) {
280*49ef7e06SGarrett D'Amore 		/*
281*49ef7e06SGarrett D'Amore 		 * Unprivileged functions cannot control link state,
282*49ef7e06SGarrett D'Amore 		 * but still need to configure filters.
283*49ef7e06SGarrett D'Amore 		 */
284*49ef7e06SGarrett D'Amore 		if (req.emr_rc != EACCES) {
285*49ef7e06SGarrett D'Amore 			rc = req.emr_rc;
286*49ef7e06SGarrett D'Amore 			goto fail1;
287*49ef7e06SGarrett D'Amore 		}
288*49ef7e06SGarrett D'Amore 	}
289*49ef7e06SGarrett D'Amore 
290*49ef7e06SGarrett D'Amore 	/*
291*49ef7e06SGarrett D'Amore 	 * Apply the filters for the MAC configuration.
292*49ef7e06SGarrett D'Amore 	 * If the NIC isn't ready to accept filters this may
293*49ef7e06SGarrett D'Amore 	 * return success without setting anything.
294*49ef7e06SGarrett D'Amore 	 */
295*49ef7e06SGarrett D'Amore 	(void) efx_filter_reconfigure(enp, epp->ep_mac_addr,
296*49ef7e06SGarrett D'Amore 				    epp->ep_all_unicst, epp->ep_mulcst,
297*49ef7e06SGarrett D'Amore 				    epp->ep_all_mulcst, epp->ep_brdcst,
298*49ef7e06SGarrett D'Amore 				    epp->ep_mulcst_addr_list,
299*49ef7e06SGarrett D'Amore 				    epp->ep_mulcst_addr_count);
300*49ef7e06SGarrett D'Amore 
301*49ef7e06SGarrett D'Amore 	return (0);
302*49ef7e06SGarrett D'Amore 
303*49ef7e06SGarrett D'Amore fail1:
304*49ef7e06SGarrett D'Amore 	EFSYS_PROBE1(fail1, efx_rc_t, rc);
305*49ef7e06SGarrett D'Amore 
306*49ef7e06SGarrett D'Amore 	return (rc);
307*49ef7e06SGarrett D'Amore }
308*49ef7e06SGarrett D'Amore 
309*49ef7e06SGarrett D'Amore 	__checkReturn			efx_rc_t
ef10_mac_multicast_list_set(__in efx_nic_t * enp)310*49ef7e06SGarrett D'Amore ef10_mac_multicast_list_set(
311*49ef7e06SGarrett D'Amore 	__in				efx_nic_t *enp)
312*49ef7e06SGarrett D'Amore {
313*49ef7e06SGarrett D'Amore 	efx_port_t *epp = &(enp->en_port);
314*49ef7e06SGarrett D'Amore 	const efx_mac_ops_t *emop = epp->ep_emop;
315*49ef7e06SGarrett D'Amore 	efx_rc_t rc;
316*49ef7e06SGarrett D'Amore 
317*49ef7e06SGarrett D'Amore 	EFSYS_ASSERT(enp->en_family == EFX_FAMILY_HUNTINGTON ||
318*49ef7e06SGarrett D'Amore 		    enp->en_family == EFX_FAMILY_MEDFORD);
319*49ef7e06SGarrett D'Amore 
320*49ef7e06SGarrett D'Amore 	if ((rc = emop->emo_reconfigure(enp)) != 0)
321*49ef7e06SGarrett D'Amore 		goto fail1;
322*49ef7e06SGarrett D'Amore 
323*49ef7e06SGarrett D'Amore 	return (0);
324*49ef7e06SGarrett D'Amore 
325*49ef7e06SGarrett D'Amore fail1:
326*49ef7e06SGarrett D'Amore 	EFSYS_PROBE1(fail1, efx_rc_t, rc);
327*49ef7e06SGarrett D'Amore 
328*49ef7e06SGarrett D'Amore 	return (rc);
329*49ef7e06SGarrett D'Amore }
330*49ef7e06SGarrett D'Amore 
331*49ef7e06SGarrett D'Amore 	__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)332*49ef7e06SGarrett D'Amore ef10_mac_filter_default_rxq_set(
333*49ef7e06SGarrett D'Amore 	__in		efx_nic_t *enp,
334*49ef7e06SGarrett D'Amore 	__in		efx_rxq_t *erp,
335*49ef7e06SGarrett D'Amore 	__in		boolean_t using_rss)
336*49ef7e06SGarrett D'Amore {
337*49ef7e06SGarrett D'Amore 	efx_port_t *epp = &(enp->en_port);
338*49ef7e06SGarrett D'Amore 	efx_rxq_t *old_rxq;
339*49ef7e06SGarrett D'Amore 	boolean_t old_using_rss;
340*49ef7e06SGarrett D'Amore 	efx_rc_t rc;
341*49ef7e06SGarrett D'Amore 
342*49ef7e06SGarrett D'Amore 	ef10_filter_get_default_rxq(enp, &old_rxq, &old_using_rss);
343*49ef7e06SGarrett D'Amore 
344*49ef7e06SGarrett D'Amore 	ef10_filter_default_rxq_set(enp, erp, using_rss);
345*49ef7e06SGarrett D'Amore 
346*49ef7e06SGarrett D'Amore 	rc = efx_filter_reconfigure(enp, epp->ep_mac_addr,
347*49ef7e06SGarrett D'Amore 				    epp->ep_all_unicst, epp->ep_mulcst,
348*49ef7e06SGarrett D'Amore 				    epp->ep_all_mulcst, epp->ep_brdcst,
349*49ef7e06SGarrett D'Amore 				    epp->ep_mulcst_addr_list,
350*49ef7e06SGarrett D'Amore 				    epp->ep_mulcst_addr_count);
351*49ef7e06SGarrett D'Amore 
352*49ef7e06SGarrett D'Amore 	if (rc != 0)
353*49ef7e06SGarrett D'Amore 		goto fail1;
354*49ef7e06SGarrett D'Amore 
355*49ef7e06SGarrett D'Amore 	return (0);
356*49ef7e06SGarrett D'Amore 
357*49ef7e06SGarrett D'Amore fail1:
358*49ef7e06SGarrett D'Amore 	EFSYS_PROBE1(fail1, efx_rc_t, rc);
359*49ef7e06SGarrett D'Amore 
360*49ef7e06SGarrett D'Amore 	ef10_filter_default_rxq_set(enp, old_rxq, old_using_rss);
361*49ef7e06SGarrett D'Amore 
362*49ef7e06SGarrett D'Amore 	return (rc);
363*49ef7e06SGarrett D'Amore }
364*49ef7e06SGarrett D'Amore 
365*49ef7e06SGarrett D'Amore 			void
ef10_mac_filter_default_rxq_clear(__in efx_nic_t * enp)366*49ef7e06SGarrett D'Amore ef10_mac_filter_default_rxq_clear(
367*49ef7e06SGarrett D'Amore 	__in		efx_nic_t *enp)
368*49ef7e06SGarrett D'Amore {
369*49ef7e06SGarrett D'Amore 	efx_port_t *epp = &(enp->en_port);
370*49ef7e06SGarrett D'Amore 
371*49ef7e06SGarrett D'Amore 	ef10_filter_default_rxq_clear(enp);
372*49ef7e06SGarrett D'Amore 
373*49ef7e06SGarrett D'Amore 	(void) efx_filter_reconfigure(enp, epp->ep_mac_addr,
374*49ef7e06SGarrett D'Amore 				    epp->ep_all_unicst, epp->ep_mulcst,
375*49ef7e06SGarrett D'Amore 				    epp->ep_all_mulcst, epp->ep_brdcst,
376*49ef7e06SGarrett D'Amore 				    epp->ep_mulcst_addr_list,
377*49ef7e06SGarrett D'Amore 				    epp->ep_mulcst_addr_count);
378*49ef7e06SGarrett D'Amore }
379*49ef7e06SGarrett D'Amore 
380*49ef7e06SGarrett D'Amore 
381*49ef7e06SGarrett D'Amore #if EFSYS_OPT_LOOPBACK
382*49ef7e06SGarrett D'Amore 
383*49ef7e06SGarrett D'Amore 	__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)384*49ef7e06SGarrett D'Amore ef10_mac_loopback_set(
385*49ef7e06SGarrett D'Amore 	__in		efx_nic_t *enp,
386*49ef7e06SGarrett D'Amore 	__in		efx_link_mode_t link_mode,
387*49ef7e06SGarrett D'Amore 	__in		efx_loopback_type_t loopback_type)
388*49ef7e06SGarrett D'Amore {
389*49ef7e06SGarrett D'Amore 	efx_port_t *epp = &(enp->en_port);
390*49ef7e06SGarrett D'Amore 	const efx_phy_ops_t *epop = epp->ep_epop;
391*49ef7e06SGarrett D'Amore 	efx_loopback_type_t old_loopback_type;
392*49ef7e06SGarrett D'Amore 	efx_link_mode_t old_loopback_link_mode;
393*49ef7e06SGarrett D'Amore 	efx_rc_t rc;
394*49ef7e06SGarrett D'Amore 
395*49ef7e06SGarrett D'Amore 	/* The PHY object handles this on EF10 */
396*49ef7e06SGarrett D'Amore 	old_loopback_type = epp->ep_loopback_type;
397*49ef7e06SGarrett D'Amore 	old_loopback_link_mode = epp->ep_loopback_link_mode;
398*49ef7e06SGarrett D'Amore 	epp->ep_loopback_type = loopback_type;
399*49ef7e06SGarrett D'Amore 	epp->ep_loopback_link_mode = link_mode;
400*49ef7e06SGarrett D'Amore 
401*49ef7e06SGarrett D'Amore 	if ((rc = epop->epo_reconfigure(enp)) != 0)
402*49ef7e06SGarrett D'Amore 		goto fail1;
403*49ef7e06SGarrett D'Amore 
404*49ef7e06SGarrett D'Amore 	return (0);
405*49ef7e06SGarrett D'Amore 
406*49ef7e06SGarrett D'Amore fail1:
407*49ef7e06SGarrett D'Amore 	EFSYS_PROBE1(fail1, efx_rc_t, rc);
408*49ef7e06SGarrett D'Amore 
409*49ef7e06SGarrett D'Amore 	epp->ep_loopback_type = old_loopback_type;
410*49ef7e06SGarrett D'Amore 	epp->ep_loopback_link_mode = old_loopback_link_mode;
411*49ef7e06SGarrett D'Amore 
412*49ef7e06SGarrett D'Amore 	return (rc);
413*49ef7e06SGarrett D'Amore }
414*49ef7e06SGarrett D'Amore 
415*49ef7e06SGarrett D'Amore #endif	/* EFSYS_OPT_LOOPBACK */
416*49ef7e06SGarrett D'Amore 
417*49ef7e06SGarrett D'Amore #if EFSYS_OPT_MAC_STATS
418*49ef7e06SGarrett D'Amore 
419*49ef7e06SGarrett D'Amore #define	EF10_MAC_STAT_READ(_esmp, _field, _eqp)			\
420*49ef7e06SGarrett D'Amore 	EFSYS_MEM_READQ((_esmp), (_field) * sizeof (efx_qword_t), _eqp)
421*49ef7e06SGarrett D'Amore 
422*49ef7e06SGarrett D'Amore 
423*49ef7e06SGarrett D'Amore 	__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)424*49ef7e06SGarrett D'Amore ef10_mac_stats_update(
425*49ef7e06SGarrett D'Amore 	__in				efx_nic_t *enp,
426*49ef7e06SGarrett D'Amore 	__in				efsys_mem_t *esmp,
427*49ef7e06SGarrett D'Amore 	__inout_ecount(EFX_MAC_NSTATS)	efsys_stat_t *stat,
428*49ef7e06SGarrett D'Amore 	__inout_opt			uint32_t *generationp)
429*49ef7e06SGarrett D'Amore {
430*49ef7e06SGarrett D'Amore 	efx_qword_t value;
431*49ef7e06SGarrett D'Amore 	efx_qword_t generation_start;
432*49ef7e06SGarrett D'Amore 	efx_qword_t generation_end;
433*49ef7e06SGarrett D'Amore 
434*49ef7e06SGarrett D'Amore 	_NOTE(ARGUNUSED(enp))
435*49ef7e06SGarrett D'Amore 
436*49ef7e06SGarrett D'Amore 	/* Read END first so we don't race with the MC */
437*49ef7e06SGarrett D'Amore 	EFSYS_DMA_SYNC_FOR_KERNEL(esmp, 0, EFX_MAC_STATS_SIZE);
438*49ef7e06SGarrett D'Amore 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_GENERATION_END,
439*49ef7e06SGarrett D'Amore 			    &generation_end);
440*49ef7e06SGarrett D'Amore 	EFSYS_MEM_READ_BARRIER();
441*49ef7e06SGarrett D'Amore 
442*49ef7e06SGarrett D'Amore 	/* TX */
443*49ef7e06SGarrett D'Amore 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_TX_PKTS, &value);
444*49ef7e06SGarrett D'Amore 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_TX_PKTS]), &value);
445*49ef7e06SGarrett D'Amore 
446*49ef7e06SGarrett D'Amore 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_TX_CONTROL_PKTS, &value);
447*49ef7e06SGarrett D'Amore 	EFSYS_STAT_SUBR_QWORD(&(stat[EFX_MAC_TX_PKTS]), &value);
448*49ef7e06SGarrett D'Amore 
449*49ef7e06SGarrett D'Amore 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_TX_PAUSE_PKTS, &value);
450*49ef7e06SGarrett D'Amore 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_TX_PAUSE_PKTS]), &value);
451*49ef7e06SGarrett D'Amore 
452*49ef7e06SGarrett D'Amore 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_TX_UNICAST_PKTS, &value);
453*49ef7e06SGarrett D'Amore 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_TX_UNICST_PKTS]), &value);
454*49ef7e06SGarrett D'Amore 
455*49ef7e06SGarrett D'Amore 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_TX_MULTICAST_PKTS, &value);
456*49ef7e06SGarrett D'Amore 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_TX_MULTICST_PKTS]), &value);
457*49ef7e06SGarrett D'Amore 
458*49ef7e06SGarrett D'Amore 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_TX_BROADCAST_PKTS, &value);
459*49ef7e06SGarrett D'Amore 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_TX_BRDCST_PKTS]), &value);
460*49ef7e06SGarrett D'Amore 
461*49ef7e06SGarrett D'Amore 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_TX_BYTES, &value);
462*49ef7e06SGarrett D'Amore 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_TX_OCTETS]), &value);
463*49ef7e06SGarrett D'Amore 
464*49ef7e06SGarrett D'Amore 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_TX_LT64_PKTS, &value);
465*49ef7e06SGarrett D'Amore 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_TX_LE_64_PKTS]), &value);
466*49ef7e06SGarrett D'Amore 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_TX_64_PKTS, &value);
467*49ef7e06SGarrett D'Amore 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_TX_LE_64_PKTS]), &value);
468*49ef7e06SGarrett D'Amore 
469*49ef7e06SGarrett D'Amore 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_TX_65_TO_127_PKTS, &value);
470*49ef7e06SGarrett D'Amore 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_TX_65_TO_127_PKTS]), &value);
471*49ef7e06SGarrett D'Amore 
472*49ef7e06SGarrett D'Amore 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_TX_128_TO_255_PKTS, &value);
473*49ef7e06SGarrett D'Amore 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_TX_128_TO_255_PKTS]), &value);
474*49ef7e06SGarrett D'Amore 
475*49ef7e06SGarrett D'Amore 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_TX_256_TO_511_PKTS, &value);
476*49ef7e06SGarrett D'Amore 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_TX_256_TO_511_PKTS]), &value);
477*49ef7e06SGarrett D'Amore 
478*49ef7e06SGarrett D'Amore 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_TX_512_TO_1023_PKTS, &value);
479*49ef7e06SGarrett D'Amore 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_TX_512_TO_1023_PKTS]), &value);
480*49ef7e06SGarrett D'Amore 
481*49ef7e06SGarrett D'Amore 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_TX_1024_TO_15XX_PKTS, &value);
482*49ef7e06SGarrett D'Amore 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_TX_1024_TO_15XX_PKTS]), &value);
483*49ef7e06SGarrett D'Amore 
484*49ef7e06SGarrett D'Amore 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_TX_15XX_TO_JUMBO_PKTS, &value);
485*49ef7e06SGarrett D'Amore 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_TX_GE_15XX_PKTS]), &value);
486*49ef7e06SGarrett D'Amore 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_TX_GTJUMBO_PKTS, &value);
487*49ef7e06SGarrett D'Amore 	EFSYS_STAT_INCR_QWORD(&(stat[EFX_MAC_TX_GE_15XX_PKTS]), &value);
488*49ef7e06SGarrett D'Amore 
489*49ef7e06SGarrett D'Amore 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_TX_BAD_FCS_PKTS, &value);
490*49ef7e06SGarrett D'Amore 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_TX_ERRORS]), &value);
491*49ef7e06SGarrett D'Amore 
492*49ef7e06SGarrett D'Amore 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_TX_SINGLE_COLLISION_PKTS, &value);
493*49ef7e06SGarrett D'Amore 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_TX_SGL_COL_PKTS]), &value);
494*49ef7e06SGarrett D'Amore 
495*49ef7e06SGarrett D'Amore 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_TX_MULTIPLE_COLLISION_PKTS,
496*49ef7e06SGarrett D'Amore 			    &value);
497*49ef7e06SGarrett D'Amore 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_TX_MULT_COL_PKTS]), &value);
498*49ef7e06SGarrett D'Amore 
499*49ef7e06SGarrett D'Amore 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_TX_EXCESSIVE_COLLISION_PKTS,
500*49ef7e06SGarrett D'Amore 			    &value);
501*49ef7e06SGarrett D'Amore 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_TX_EX_COL_PKTS]), &value);
502*49ef7e06SGarrett D'Amore 
503*49ef7e06SGarrett D'Amore 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_TX_LATE_COLLISION_PKTS, &value);
504*49ef7e06SGarrett D'Amore 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_TX_LATE_COL_PKTS]), &value);
505*49ef7e06SGarrett D'Amore 
506*49ef7e06SGarrett D'Amore 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_TX_DEFERRED_PKTS, &value);
507*49ef7e06SGarrett D'Amore 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_TX_DEF_PKTS]), &value);
508*49ef7e06SGarrett D'Amore 
509*49ef7e06SGarrett D'Amore 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_TX_EXCESSIVE_DEFERRED_PKTS,
510*49ef7e06SGarrett D'Amore 	    &value);
511*49ef7e06SGarrett D'Amore 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_TX_EX_DEF_PKTS]), &value);
512*49ef7e06SGarrett D'Amore 
513*49ef7e06SGarrett D'Amore 	/* RX */
514*49ef7e06SGarrett D'Amore 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_RX_BYTES, &value);
515*49ef7e06SGarrett D'Amore 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_RX_OCTETS]), &value);
516*49ef7e06SGarrett D'Amore 
517*49ef7e06SGarrett D'Amore 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_RX_PKTS, &value);
518*49ef7e06SGarrett D'Amore 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_RX_PKTS]), &value);
519*49ef7e06SGarrett D'Amore 
520*49ef7e06SGarrett D'Amore 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_RX_UNICAST_PKTS, &value);
521*49ef7e06SGarrett D'Amore 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_RX_UNICST_PKTS]), &value);
522*49ef7e06SGarrett D'Amore 
523*49ef7e06SGarrett D'Amore 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_RX_MULTICAST_PKTS, &value);
524*49ef7e06SGarrett D'Amore 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_RX_MULTICST_PKTS]), &value);
525*49ef7e06SGarrett D'Amore 
526*49ef7e06SGarrett D'Amore 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_RX_BROADCAST_PKTS, &value);
527*49ef7e06SGarrett D'Amore 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_RX_BRDCST_PKTS]), &value);
528*49ef7e06SGarrett D'Amore 
529*49ef7e06SGarrett D'Amore 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_RX_PAUSE_PKTS, &value);
530*49ef7e06SGarrett D'Amore 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_RX_PAUSE_PKTS]), &value);
531*49ef7e06SGarrett D'Amore 
532*49ef7e06SGarrett D'Amore 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_RX_UNDERSIZE_PKTS, &value);
533*49ef7e06SGarrett D'Amore 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_RX_LE_64_PKTS]), &value);
534*49ef7e06SGarrett D'Amore 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_RX_64_PKTS, &value);
535*49ef7e06SGarrett D'Amore 	EFSYS_STAT_INCR_QWORD(&(stat[EFX_MAC_RX_LE_64_PKTS]), &value);
536*49ef7e06SGarrett D'Amore 
537*49ef7e06SGarrett D'Amore 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_RX_65_TO_127_PKTS, &value);
538*49ef7e06SGarrett D'Amore 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_RX_65_TO_127_PKTS]), &value);
539*49ef7e06SGarrett D'Amore 
540*49ef7e06SGarrett D'Amore 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_RX_128_TO_255_PKTS, &value);
541*49ef7e06SGarrett D'Amore 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_RX_128_TO_255_PKTS]), &value);
542*49ef7e06SGarrett D'Amore 
543*49ef7e06SGarrett D'Amore 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_RX_256_TO_511_PKTS, &value);
544*49ef7e06SGarrett D'Amore 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_RX_256_TO_511_PKTS]), &value);
545*49ef7e06SGarrett D'Amore 
546*49ef7e06SGarrett D'Amore 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_RX_512_TO_1023_PKTS, &value);
547*49ef7e06SGarrett D'Amore 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_RX_512_TO_1023_PKTS]), &value);
548*49ef7e06SGarrett D'Amore 
549*49ef7e06SGarrett D'Amore 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_RX_1024_TO_15XX_PKTS, &value);
550*49ef7e06SGarrett D'Amore 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_RX_1024_TO_15XX_PKTS]), &value);
551*49ef7e06SGarrett D'Amore 
552*49ef7e06SGarrett D'Amore 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_RX_15XX_TO_JUMBO_PKTS, &value);
553*49ef7e06SGarrett D'Amore 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_RX_GE_15XX_PKTS]), &value);
554*49ef7e06SGarrett D'Amore 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_RX_GTJUMBO_PKTS, &value);
555*49ef7e06SGarrett D'Amore 	EFSYS_STAT_INCR_QWORD(&(stat[EFX_MAC_RX_GE_15XX_PKTS]), &value);
556*49ef7e06SGarrett D'Amore 
557*49ef7e06SGarrett D'Amore 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_RX_BAD_FCS_PKTS, &value);
558*49ef7e06SGarrett D'Amore 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_RX_FCS_ERRORS]), &value);
559*49ef7e06SGarrett D'Amore 
560*49ef7e06SGarrett D'Amore 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_RX_OVERFLOW_PKTS, &value);
561*49ef7e06SGarrett D'Amore 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_RX_DROP_EVENTS]), &value);
562*49ef7e06SGarrett D'Amore 
563*49ef7e06SGarrett D'Amore 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_RX_FALSE_CARRIER_PKTS, &value);
564*49ef7e06SGarrett D'Amore 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_RX_FALSE_CARRIER_ERRORS]), &value);
565*49ef7e06SGarrett D'Amore 
566*49ef7e06SGarrett D'Amore 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_RX_SYMBOL_ERROR_PKTS, &value);
567*49ef7e06SGarrett D'Amore 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_RX_SYMBOL_ERRORS]), &value);
568*49ef7e06SGarrett D'Amore 
569*49ef7e06SGarrett D'Amore 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_RX_ALIGN_ERROR_PKTS, &value);
570*49ef7e06SGarrett D'Amore 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_RX_ALIGN_ERRORS]), &value);
571*49ef7e06SGarrett D'Amore 
572*49ef7e06SGarrett D'Amore 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_RX_INTERNAL_ERROR_PKTS, &value);
573*49ef7e06SGarrett D'Amore 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_RX_INTERNAL_ERRORS]), &value);
574*49ef7e06SGarrett D'Amore 
575*49ef7e06SGarrett D'Amore 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_RX_JABBER_PKTS, &value);
576*49ef7e06SGarrett D'Amore 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_RX_JABBER_PKTS]), &value);
577*49ef7e06SGarrett D'Amore 
578*49ef7e06SGarrett D'Amore 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_RX_LANES01_CHAR_ERR, &value);
579*49ef7e06SGarrett D'Amore 	EFSYS_STAT_SET_DWORD(&(stat[EFX_MAC_RX_LANE0_CHAR_ERR]),
580*49ef7e06SGarrett D'Amore 			    &(value.eq_dword[0]));
581*49ef7e06SGarrett D'Amore 	EFSYS_STAT_SET_DWORD(&(stat[EFX_MAC_RX_LANE1_CHAR_ERR]),
582*49ef7e06SGarrett D'Amore 			    &(value.eq_dword[1]));
583*49ef7e06SGarrett D'Amore 
584*49ef7e06SGarrett D'Amore 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_RX_LANES23_CHAR_ERR, &value);
585*49ef7e06SGarrett D'Amore 	EFSYS_STAT_SET_DWORD(&(stat[EFX_MAC_RX_LANE2_CHAR_ERR]),
586*49ef7e06SGarrett D'Amore 			    &(value.eq_dword[0]));
587*49ef7e06SGarrett D'Amore 	EFSYS_STAT_SET_DWORD(&(stat[EFX_MAC_RX_LANE3_CHAR_ERR]),
588*49ef7e06SGarrett D'Amore 			    &(value.eq_dword[1]));
589*49ef7e06SGarrett D'Amore 
590*49ef7e06SGarrett D'Amore 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_RX_LANES01_DISP_ERR, &value);
591*49ef7e06SGarrett D'Amore 	EFSYS_STAT_SET_DWORD(&(stat[EFX_MAC_RX_LANE0_DISP_ERR]),
592*49ef7e06SGarrett D'Amore 			    &(value.eq_dword[0]));
593*49ef7e06SGarrett D'Amore 	EFSYS_STAT_SET_DWORD(&(stat[EFX_MAC_RX_LANE1_DISP_ERR]),
594*49ef7e06SGarrett D'Amore 			    &(value.eq_dword[1]));
595*49ef7e06SGarrett D'Amore 
596*49ef7e06SGarrett D'Amore 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_RX_LANES23_DISP_ERR, &value);
597*49ef7e06SGarrett D'Amore 	EFSYS_STAT_SET_DWORD(&(stat[EFX_MAC_RX_LANE2_DISP_ERR]),
598*49ef7e06SGarrett D'Amore 			    &(value.eq_dword[0]));
599*49ef7e06SGarrett D'Amore 	EFSYS_STAT_SET_DWORD(&(stat[EFX_MAC_RX_LANE3_DISP_ERR]),
600*49ef7e06SGarrett D'Amore 			    &(value.eq_dword[1]));
601*49ef7e06SGarrett D'Amore 
602*49ef7e06SGarrett D'Amore 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_RX_MATCH_FAULT, &value);
603*49ef7e06SGarrett D'Amore 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_RX_MATCH_FAULT]), &value);
604*49ef7e06SGarrett D'Amore 
605*49ef7e06SGarrett D'Amore 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_RX_NODESC_DROPS, &value);
606*49ef7e06SGarrett D'Amore 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_RX_NODESC_DROP_CNT]), &value);
607*49ef7e06SGarrett D'Amore 
608*49ef7e06SGarrett D'Amore 	/* Packet memory (EF10 only) */
609*49ef7e06SGarrett D'Amore 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_PM_TRUNC_BB_OVERFLOW, &value);
610*49ef7e06SGarrett D'Amore 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_PM_TRUNC_BB_OVERFLOW]), &value);
611*49ef7e06SGarrett D'Amore 
612*49ef7e06SGarrett D'Amore 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_PM_DISCARD_BB_OVERFLOW, &value);
613*49ef7e06SGarrett D'Amore 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_PM_DISCARD_BB_OVERFLOW]), &value);
614*49ef7e06SGarrett D'Amore 
615*49ef7e06SGarrett D'Amore 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_PM_TRUNC_VFIFO_FULL, &value);
616*49ef7e06SGarrett D'Amore 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_PM_TRUNC_VFIFO_FULL]), &value);
617*49ef7e06SGarrett D'Amore 
618*49ef7e06SGarrett D'Amore 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_PM_DISCARD_VFIFO_FULL, &value);
619*49ef7e06SGarrett D'Amore 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_PM_DISCARD_VFIFO_FULL]), &value);
620*49ef7e06SGarrett D'Amore 
621*49ef7e06SGarrett D'Amore 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_PM_TRUNC_QBB, &value);
622*49ef7e06SGarrett D'Amore 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_PM_TRUNC_QBB]), &value);
623*49ef7e06SGarrett D'Amore 
624*49ef7e06SGarrett D'Amore 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_PM_DISCARD_QBB, &value);
625*49ef7e06SGarrett D'Amore 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_PM_DISCARD_QBB]), &value);
626*49ef7e06SGarrett D'Amore 
627*49ef7e06SGarrett D'Amore 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_PM_DISCARD_MAPPING, &value);
628*49ef7e06SGarrett D'Amore 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_PM_DISCARD_MAPPING]), &value);
629*49ef7e06SGarrett D'Amore 
630*49ef7e06SGarrett D'Amore 	/* RX datapath */
631*49ef7e06SGarrett D'Amore 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_RXDP_Q_DISABLED_PKTS, &value);
632*49ef7e06SGarrett D'Amore 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_RXDP_Q_DISABLED_PKTS]), &value);
633*49ef7e06SGarrett D'Amore 
634*49ef7e06SGarrett D'Amore 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_RXDP_DI_DROPPED_PKTS, &value);
635*49ef7e06SGarrett D'Amore 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_RXDP_DI_DROPPED_PKTS]), &value);
636*49ef7e06SGarrett D'Amore 
637*49ef7e06SGarrett D'Amore 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_RXDP_STREAMING_PKTS, &value);
638*49ef7e06SGarrett D'Amore 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_RXDP_STREAMING_PKTS]), &value);
639*49ef7e06SGarrett D'Amore 
640*49ef7e06SGarrett D'Amore 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_RXDP_HLB_FETCH_CONDITIONS, &value);
641*49ef7e06SGarrett D'Amore 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_RXDP_HLB_FETCH]), &value);
642*49ef7e06SGarrett D'Amore 
643*49ef7e06SGarrett D'Amore 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_RXDP_HLB_WAIT_CONDITIONS, &value);
644*49ef7e06SGarrett D'Amore 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_RXDP_HLB_WAIT]), &value);
645*49ef7e06SGarrett D'Amore 
646*49ef7e06SGarrett D'Amore 
647*49ef7e06SGarrett D'Amore 	/* VADAPTER RX */
648*49ef7e06SGarrett D'Amore 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_VADAPTER_RX_UNICAST_PACKETS,
649*49ef7e06SGarrett D'Amore 	    &value);
650*49ef7e06SGarrett D'Amore 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_VADAPTER_RX_UNICAST_PACKETS]),
651*49ef7e06SGarrett D'Amore 	    &value);
652*49ef7e06SGarrett D'Amore 
653*49ef7e06SGarrett D'Amore 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_VADAPTER_RX_UNICAST_BYTES,
654*49ef7e06SGarrett D'Amore 	    &value);
655*49ef7e06SGarrett D'Amore 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_VADAPTER_RX_UNICAST_BYTES]),
656*49ef7e06SGarrett D'Amore 	    &value);
657*49ef7e06SGarrett D'Amore 
658*49ef7e06SGarrett D'Amore 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_VADAPTER_RX_MULTICAST_PACKETS,
659*49ef7e06SGarrett D'Amore 	    &value);
660*49ef7e06SGarrett D'Amore 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_VADAPTER_RX_MULTICAST_PACKETS]),
661*49ef7e06SGarrett D'Amore 	    &value);
662*49ef7e06SGarrett D'Amore 
663*49ef7e06SGarrett D'Amore 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_VADAPTER_RX_MULTICAST_BYTES,
664*49ef7e06SGarrett D'Amore 	    &value);
665*49ef7e06SGarrett D'Amore 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_VADAPTER_RX_MULTICAST_BYTES]),
666*49ef7e06SGarrett D'Amore 	    &value);
667*49ef7e06SGarrett D'Amore 
668*49ef7e06SGarrett D'Amore 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_VADAPTER_RX_BROADCAST_PACKETS,
669*49ef7e06SGarrett D'Amore 	    &value);
670*49ef7e06SGarrett D'Amore 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_VADAPTER_RX_BROADCAST_PACKETS]),
671*49ef7e06SGarrett D'Amore 	    &value);
672*49ef7e06SGarrett D'Amore 
673*49ef7e06SGarrett D'Amore 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_VADAPTER_RX_BROADCAST_BYTES,
674*49ef7e06SGarrett D'Amore 	    &value);
675*49ef7e06SGarrett D'Amore 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_VADAPTER_RX_BROADCAST_BYTES]),
676*49ef7e06SGarrett D'Amore 	    &value);
677*49ef7e06SGarrett D'Amore 
678*49ef7e06SGarrett D'Amore 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_VADAPTER_RX_BAD_PACKETS,
679*49ef7e06SGarrett D'Amore 	    &value);
680*49ef7e06SGarrett D'Amore 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_VADAPTER_RX_BAD_PACKETS]),
681*49ef7e06SGarrett D'Amore 	    &value);
682*49ef7e06SGarrett D'Amore 
683*49ef7e06SGarrett D'Amore 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_VADAPTER_RX_BAD_BYTES, &value);
684*49ef7e06SGarrett D'Amore 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_VADAPTER_RX_BAD_BYTES]), &value);
685*49ef7e06SGarrett D'Amore 
686*49ef7e06SGarrett D'Amore 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_VADAPTER_RX_OVERFLOW, &value);
687*49ef7e06SGarrett D'Amore 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_VADAPTER_RX_OVERFLOW]), &value);
688*49ef7e06SGarrett D'Amore 
689*49ef7e06SGarrett D'Amore 	/* VADAPTER TX */
690*49ef7e06SGarrett D'Amore 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_VADAPTER_TX_UNICAST_PACKETS,
691*49ef7e06SGarrett D'Amore 	    &value);
692*49ef7e06SGarrett D'Amore 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_VADAPTER_TX_UNICAST_PACKETS]),
693*49ef7e06SGarrett D'Amore 	    &value);
694*49ef7e06SGarrett D'Amore 
695*49ef7e06SGarrett D'Amore 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_VADAPTER_TX_UNICAST_BYTES,
696*49ef7e06SGarrett D'Amore 	    &value);
697*49ef7e06SGarrett D'Amore 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_VADAPTER_TX_UNICAST_BYTES]),
698*49ef7e06SGarrett D'Amore 	    &value);
699*49ef7e06SGarrett D'Amore 
700*49ef7e06SGarrett D'Amore 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_VADAPTER_TX_MULTICAST_PACKETS,
701*49ef7e06SGarrett D'Amore 	    &value);
702*49ef7e06SGarrett D'Amore 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_VADAPTER_TX_MULTICAST_PACKETS]),
703*49ef7e06SGarrett D'Amore 	    &value);
704*49ef7e06SGarrett D'Amore 
705*49ef7e06SGarrett D'Amore 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_VADAPTER_TX_MULTICAST_BYTES,
706*49ef7e06SGarrett D'Amore 	    &value);
707*49ef7e06SGarrett D'Amore 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_VADAPTER_TX_MULTICAST_BYTES]),
708*49ef7e06SGarrett D'Amore 	    &value);
709*49ef7e06SGarrett D'Amore 
710*49ef7e06SGarrett D'Amore 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_VADAPTER_TX_BROADCAST_PACKETS,
711*49ef7e06SGarrett D'Amore 	    &value);
712*49ef7e06SGarrett D'Amore 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_VADAPTER_TX_BROADCAST_PACKETS]),
713*49ef7e06SGarrett D'Amore 	    &value);
714*49ef7e06SGarrett D'Amore 
715*49ef7e06SGarrett D'Amore 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_VADAPTER_TX_BROADCAST_BYTES,
716*49ef7e06SGarrett D'Amore 	    &value);
717*49ef7e06SGarrett D'Amore 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_VADAPTER_TX_BROADCAST_BYTES]),
718*49ef7e06SGarrett D'Amore 	    &value);
719*49ef7e06SGarrett D'Amore 
720*49ef7e06SGarrett D'Amore 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_VADAPTER_TX_BAD_PACKETS, &value);
721*49ef7e06SGarrett D'Amore 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_VADAPTER_TX_BAD_PACKETS]), &value);
722*49ef7e06SGarrett D'Amore 
723*49ef7e06SGarrett D'Amore 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_VADAPTER_TX_BAD_BYTES, &value);
724*49ef7e06SGarrett D'Amore 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_VADAPTER_TX_BAD_BYTES]), &value);
725*49ef7e06SGarrett D'Amore 
726*49ef7e06SGarrett D'Amore 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_VADAPTER_TX_OVERFLOW, &value);
727*49ef7e06SGarrett D'Amore 	EFSYS_STAT_SET_QWORD(&(stat[EFX_MAC_VADAPTER_TX_OVERFLOW]), &value);
728*49ef7e06SGarrett D'Amore 
729*49ef7e06SGarrett D'Amore 
730*49ef7e06SGarrett D'Amore 	EFSYS_DMA_SYNC_FOR_KERNEL(esmp, 0, EFX_MAC_STATS_SIZE);
731*49ef7e06SGarrett D'Amore 	EFSYS_MEM_READ_BARRIER();
732*49ef7e06SGarrett D'Amore 	EF10_MAC_STAT_READ(esmp, MC_CMD_MAC_GENERATION_START,
733*49ef7e06SGarrett D'Amore 			    &generation_start);
734*49ef7e06SGarrett D'Amore 
735*49ef7e06SGarrett D'Amore 	/* Check that we didn't read the stats in the middle of a DMA */
736*49ef7e06SGarrett D'Amore 	/* Not a good enough check ? */
737*49ef7e06SGarrett D'Amore 	if (memcmp(&generation_start, &generation_end,
738*49ef7e06SGarrett D'Amore 	    sizeof (generation_start)))
739*49ef7e06SGarrett D'Amore 		return (EAGAIN);
740*49ef7e06SGarrett D'Amore 
741*49ef7e06SGarrett D'Amore 	if (generationp)
742*49ef7e06SGarrett D'Amore 		*generationp = EFX_QWORD_FIELD(generation_start, EFX_DWORD_0);
743*49ef7e06SGarrett D'Amore 
744*49ef7e06SGarrett D'Amore 	return (0);
745*49ef7e06SGarrett D'Amore }
746*49ef7e06SGarrett D'Amore 
747*49ef7e06SGarrett D'Amore #endif	/* EFSYS_OPT_MAC_STATS */
748*49ef7e06SGarrett D'Amore 
749*49ef7e06SGarrett D'Amore #endif	/* EFSYS_OPT_HUNTINGTON || EFSYS_OPT_MEDFORD */
750