1*49ef7e06SGarrett D'Amore /*
2*49ef7e06SGarrett D'Amore  * Copyright (c) 2007-2015 Solarflare Communications Inc.
3*49ef7e06SGarrett D'Amore  * All rights reserved.
4*49ef7e06SGarrett D'Amore  *
5*49ef7e06SGarrett D'Amore  * Redistribution and use in source and binary forms, with or without
6*49ef7e06SGarrett D'Amore  * modification, are permitted provided that the following conditions are met:
7*49ef7e06SGarrett D'Amore  *
8*49ef7e06SGarrett D'Amore  * 1. Redistributions of source code must retain the above copyright notice,
9*49ef7e06SGarrett D'Amore  *    this list of conditions and the following disclaimer.
10*49ef7e06SGarrett D'Amore  * 2. Redistributions in binary form must reproduce the above copyright notice,
11*49ef7e06SGarrett D'Amore  *    this list of conditions and the following disclaimer in the documentation
12*49ef7e06SGarrett D'Amore  *    and/or other materials provided with the distribution.
13*49ef7e06SGarrett D'Amore  *
14*49ef7e06SGarrett D'Amore  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15*49ef7e06SGarrett D'Amore  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
16*49ef7e06SGarrett D'Amore  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17*49ef7e06SGarrett D'Amore  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
18*49ef7e06SGarrett D'Amore  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19*49ef7e06SGarrett D'Amore  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20*49ef7e06SGarrett D'Amore  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
21*49ef7e06SGarrett D'Amore  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
22*49ef7e06SGarrett D'Amore  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23*49ef7e06SGarrett D'Amore  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
24*49ef7e06SGarrett D'Amore  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25*49ef7e06SGarrett D'Amore  *
26*49ef7e06SGarrett D'Amore  * The views and conclusions contained in the software and documentation are
27*49ef7e06SGarrett D'Amore  * those of the authors and should not be interpreted as representing official
28*49ef7e06SGarrett D'Amore  * policies, either expressed or implied, of the FreeBSD Project.
29*49ef7e06SGarrett D'Amore  */
30*49ef7e06SGarrett D'Amore 
31*49ef7e06SGarrett D'Amore #include "efx.h"
32*49ef7e06SGarrett D'Amore #include "efx_impl.h"
33*49ef7e06SGarrett D'Amore 
34*49ef7e06SGarrett D'Amore #if EFSYS_OPT_HUNTINGTON || EFSYS_OPT_MEDFORD
35*49ef7e06SGarrett D'Amore 
36*49ef7e06SGarrett D'Amore #if EFSYS_OPT_FILTER
37*49ef7e06SGarrett D'Amore 
38*49ef7e06SGarrett D'Amore #define	EFE_SPEC(eftp, index)	((eftp)->eft_entry[(index)].efe_spec)
39*49ef7e06SGarrett D'Amore 
40*49ef7e06SGarrett D'Amore static			efx_filter_spec_t *
ef10_filter_entry_spec(__in const ef10_filter_table_t * eftp,__in unsigned int index)41*49ef7e06SGarrett D'Amore ef10_filter_entry_spec(
42*49ef7e06SGarrett D'Amore 	__in		const ef10_filter_table_t *eftp,
43*49ef7e06SGarrett D'Amore 	__in		unsigned int index)
44*49ef7e06SGarrett D'Amore {
45*49ef7e06SGarrett D'Amore 	return ((efx_filter_spec_t *)(EFE_SPEC(eftp, index) &
46*49ef7e06SGarrett D'Amore 		~(uintptr_t)EFX_EF10_FILTER_FLAGS));
47*49ef7e06SGarrett D'Amore }
48*49ef7e06SGarrett D'Amore 
49*49ef7e06SGarrett D'Amore static			boolean_t
ef10_filter_entry_is_busy(__in const ef10_filter_table_t * eftp,__in unsigned int index)50*49ef7e06SGarrett D'Amore ef10_filter_entry_is_busy(
51*49ef7e06SGarrett D'Amore 	__in		const ef10_filter_table_t *eftp,
52*49ef7e06SGarrett D'Amore 	__in		unsigned int index)
53*49ef7e06SGarrett D'Amore {
54*49ef7e06SGarrett D'Amore 	if (EFE_SPEC(eftp, index) & EFX_EF10_FILTER_FLAG_BUSY)
55*49ef7e06SGarrett D'Amore 		return (B_TRUE);
56*49ef7e06SGarrett D'Amore 	else
57*49ef7e06SGarrett D'Amore 		return (B_FALSE);
58*49ef7e06SGarrett D'Amore }
59*49ef7e06SGarrett D'Amore 
60*49ef7e06SGarrett D'Amore static			boolean_t
ef10_filter_entry_is_auto_old(__in const ef10_filter_table_t * eftp,__in unsigned int index)61*49ef7e06SGarrett D'Amore ef10_filter_entry_is_auto_old(
62*49ef7e06SGarrett D'Amore 	__in		const ef10_filter_table_t *eftp,
63*49ef7e06SGarrett D'Amore 	__in		unsigned int index)
64*49ef7e06SGarrett D'Amore {
65*49ef7e06SGarrett D'Amore 	if (EFE_SPEC(eftp, index) & EFX_EF10_FILTER_FLAG_AUTO_OLD)
66*49ef7e06SGarrett D'Amore 		return (B_TRUE);
67*49ef7e06SGarrett D'Amore 	else
68*49ef7e06SGarrett D'Amore 		return (B_FALSE);
69*49ef7e06SGarrett D'Amore }
70*49ef7e06SGarrett D'Amore 
71*49ef7e06SGarrett D'Amore static			void
ef10_filter_set_entry(__inout ef10_filter_table_t * eftp,__in unsigned int index,__in_opt const efx_filter_spec_t * efsp)72*49ef7e06SGarrett D'Amore ef10_filter_set_entry(
73*49ef7e06SGarrett D'Amore 	__inout		ef10_filter_table_t *eftp,
74*49ef7e06SGarrett D'Amore 	__in		unsigned int index,
75*49ef7e06SGarrett D'Amore 	__in_opt	const efx_filter_spec_t *efsp)
76*49ef7e06SGarrett D'Amore {
77*49ef7e06SGarrett D'Amore 	EFE_SPEC(eftp, index) = (uintptr_t)efsp;
78*49ef7e06SGarrett D'Amore }
79*49ef7e06SGarrett D'Amore 
80*49ef7e06SGarrett D'Amore static			void
ef10_filter_set_entry_busy(__inout ef10_filter_table_t * eftp,__in unsigned int index)81*49ef7e06SGarrett D'Amore ef10_filter_set_entry_busy(
82*49ef7e06SGarrett D'Amore 	__inout		ef10_filter_table_t *eftp,
83*49ef7e06SGarrett D'Amore 	__in		unsigned int index)
84*49ef7e06SGarrett D'Amore {
85*49ef7e06SGarrett D'Amore 	EFE_SPEC(eftp, index) |= (uintptr_t)EFX_EF10_FILTER_FLAG_BUSY;
86*49ef7e06SGarrett D'Amore }
87*49ef7e06SGarrett D'Amore 
88*49ef7e06SGarrett D'Amore static			void
ef10_filter_set_entry_not_busy(__inout ef10_filter_table_t * eftp,__in unsigned int index)89*49ef7e06SGarrett D'Amore ef10_filter_set_entry_not_busy(
90*49ef7e06SGarrett D'Amore 	__inout		ef10_filter_table_t *eftp,
91*49ef7e06SGarrett D'Amore 	__in		unsigned int index)
92*49ef7e06SGarrett D'Amore {
93*49ef7e06SGarrett D'Amore 	EFE_SPEC(eftp, index) &= ~(uintptr_t)EFX_EF10_FILTER_FLAG_BUSY;
94*49ef7e06SGarrett D'Amore }
95*49ef7e06SGarrett D'Amore 
96*49ef7e06SGarrett D'Amore static			void
ef10_filter_set_entry_auto_old(__inout ef10_filter_table_t * eftp,__in unsigned int index)97*49ef7e06SGarrett D'Amore ef10_filter_set_entry_auto_old(
98*49ef7e06SGarrett D'Amore 	__inout		ef10_filter_table_t *eftp,
99*49ef7e06SGarrett D'Amore 	__in		unsigned int index)
100*49ef7e06SGarrett D'Amore {
101*49ef7e06SGarrett D'Amore 	EFSYS_ASSERT(ef10_filter_entry_spec(eftp, index) != NULL);
102*49ef7e06SGarrett D'Amore 	EFE_SPEC(eftp, index) |= (uintptr_t)EFX_EF10_FILTER_FLAG_AUTO_OLD;
103*49ef7e06SGarrett D'Amore }
104*49ef7e06SGarrett D'Amore 
105*49ef7e06SGarrett D'Amore static			void
ef10_filter_set_entry_not_auto_old(__inout ef10_filter_table_t * eftp,__in unsigned int index)106*49ef7e06SGarrett D'Amore ef10_filter_set_entry_not_auto_old(
107*49ef7e06SGarrett D'Amore 	__inout		ef10_filter_table_t *eftp,
108*49ef7e06SGarrett D'Amore 	__in		unsigned int index)
109*49ef7e06SGarrett D'Amore {
110*49ef7e06SGarrett D'Amore 	EFE_SPEC(eftp, index) &= ~(uintptr_t)EFX_EF10_FILTER_FLAG_AUTO_OLD;
111*49ef7e06SGarrett D'Amore 	EFSYS_ASSERT(ef10_filter_entry_spec(eftp, index) != NULL);
112*49ef7e06SGarrett D'Amore }
113*49ef7e06SGarrett D'Amore 
114*49ef7e06SGarrett D'Amore 	__checkReturn	efx_rc_t
ef10_filter_init(__in efx_nic_t * enp)115*49ef7e06SGarrett D'Amore ef10_filter_init(
116*49ef7e06SGarrett D'Amore 	__in		efx_nic_t *enp)
117*49ef7e06SGarrett D'Amore {
118*49ef7e06SGarrett D'Amore 	efx_rc_t rc;
119*49ef7e06SGarrett D'Amore 	ef10_filter_table_t *eftp;
120*49ef7e06SGarrett D'Amore 
121*49ef7e06SGarrett D'Amore 	EFSYS_ASSERT(enp->en_family == EFX_FAMILY_HUNTINGTON ||
122*49ef7e06SGarrett D'Amore 		    enp->en_family == EFX_FAMILY_MEDFORD);
123*49ef7e06SGarrett D'Amore 
124*49ef7e06SGarrett D'Amore #define	MATCH_MASK(match) (EFX_MASK32(match) << EFX_LOW_BIT(match))
125*49ef7e06SGarrett D'Amore 	EFX_STATIC_ASSERT(EFX_FILTER_MATCH_REM_HOST ==
126*49ef7e06SGarrett D'Amore 	    MATCH_MASK(MC_CMD_FILTER_OP_IN_MATCH_SRC_IP));
127*49ef7e06SGarrett D'Amore 	EFX_STATIC_ASSERT(EFX_FILTER_MATCH_LOC_HOST ==
128*49ef7e06SGarrett D'Amore 	    MATCH_MASK(MC_CMD_FILTER_OP_IN_MATCH_DST_IP));
129*49ef7e06SGarrett D'Amore 	EFX_STATIC_ASSERT(EFX_FILTER_MATCH_REM_MAC ==
130*49ef7e06SGarrett D'Amore 	    MATCH_MASK(MC_CMD_FILTER_OP_IN_MATCH_SRC_MAC));
131*49ef7e06SGarrett D'Amore 	EFX_STATIC_ASSERT(EFX_FILTER_MATCH_REM_PORT ==
132*49ef7e06SGarrett D'Amore 	    MATCH_MASK(MC_CMD_FILTER_OP_IN_MATCH_SRC_PORT));
133*49ef7e06SGarrett D'Amore 	EFX_STATIC_ASSERT(EFX_FILTER_MATCH_LOC_MAC ==
134*49ef7e06SGarrett D'Amore 	    MATCH_MASK(MC_CMD_FILTER_OP_IN_MATCH_DST_MAC));
135*49ef7e06SGarrett D'Amore 	EFX_STATIC_ASSERT(EFX_FILTER_MATCH_LOC_PORT ==
136*49ef7e06SGarrett D'Amore 	    MATCH_MASK(MC_CMD_FILTER_OP_IN_MATCH_DST_PORT));
137*49ef7e06SGarrett D'Amore 	EFX_STATIC_ASSERT(EFX_FILTER_MATCH_ETHER_TYPE ==
138*49ef7e06SGarrett D'Amore 	    MATCH_MASK(MC_CMD_FILTER_OP_IN_MATCH_ETHER_TYPE));
139*49ef7e06SGarrett D'Amore 	EFX_STATIC_ASSERT(EFX_FILTER_MATCH_INNER_VID ==
140*49ef7e06SGarrett D'Amore 	    MATCH_MASK(MC_CMD_FILTER_OP_IN_MATCH_INNER_VLAN));
141*49ef7e06SGarrett D'Amore 	EFX_STATIC_ASSERT(EFX_FILTER_MATCH_OUTER_VID ==
142*49ef7e06SGarrett D'Amore 	    MATCH_MASK(MC_CMD_FILTER_OP_IN_MATCH_OUTER_VLAN));
143*49ef7e06SGarrett D'Amore 	EFX_STATIC_ASSERT(EFX_FILTER_MATCH_IP_PROTO ==
144*49ef7e06SGarrett D'Amore 	    MATCH_MASK(MC_CMD_FILTER_OP_IN_MATCH_IP_PROTO));
145*49ef7e06SGarrett D'Amore #undef MATCH_MASK
146*49ef7e06SGarrett D'Amore 
147*49ef7e06SGarrett D'Amore 	EFSYS_KMEM_ALLOC(enp->en_esip, sizeof (ef10_filter_table_t), eftp);
148*49ef7e06SGarrett D'Amore 
149*49ef7e06SGarrett D'Amore 	if (!eftp) {
150*49ef7e06SGarrett D'Amore 		rc = ENOMEM;
151*49ef7e06SGarrett D'Amore 		goto fail1;
152*49ef7e06SGarrett D'Amore 	}
153*49ef7e06SGarrett D'Amore 
154*49ef7e06SGarrett D'Amore 	enp->en_filter.ef_ef10_filter_table = eftp;
155*49ef7e06SGarrett D'Amore 
156*49ef7e06SGarrett D'Amore 	return (0);
157*49ef7e06SGarrett D'Amore 
158*49ef7e06SGarrett D'Amore fail1:
159*49ef7e06SGarrett D'Amore 	EFSYS_PROBE1(fail1, efx_rc_t, rc);
160*49ef7e06SGarrett D'Amore 
161*49ef7e06SGarrett D'Amore 	return (rc);
162*49ef7e06SGarrett D'Amore }
163*49ef7e06SGarrett D'Amore 
164*49ef7e06SGarrett D'Amore 			void
ef10_filter_fini(__in efx_nic_t * enp)165*49ef7e06SGarrett D'Amore ef10_filter_fini(
166*49ef7e06SGarrett D'Amore 	__in		efx_nic_t *enp)
167*49ef7e06SGarrett D'Amore {
168*49ef7e06SGarrett D'Amore 	EFSYS_ASSERT(enp->en_family == EFX_FAMILY_HUNTINGTON ||
169*49ef7e06SGarrett D'Amore 		    enp->en_family == EFX_FAMILY_MEDFORD);
170*49ef7e06SGarrett D'Amore 
171*49ef7e06SGarrett D'Amore 	if (enp->en_filter.ef_ef10_filter_table != NULL) {
172*49ef7e06SGarrett D'Amore 		EFSYS_KMEM_FREE(enp->en_esip, sizeof (ef10_filter_table_t),
173*49ef7e06SGarrett D'Amore 		    enp->en_filter.ef_ef10_filter_table);
174*49ef7e06SGarrett D'Amore 	}
175*49ef7e06SGarrett D'Amore }
176*49ef7e06SGarrett D'Amore 
177*49ef7e06SGarrett D'Amore static	__checkReturn	efx_rc_t
efx_mcdi_filter_op_add(__in efx_nic_t * enp,__in efx_filter_spec_t * spec,__in unsigned int filter_op,__inout ef10_filter_handle_t * handle)178*49ef7e06SGarrett D'Amore efx_mcdi_filter_op_add(
179*49ef7e06SGarrett D'Amore 	__in		efx_nic_t *enp,
180*49ef7e06SGarrett D'Amore 	__in		efx_filter_spec_t *spec,
181*49ef7e06SGarrett D'Amore 	__in		unsigned int filter_op,
182*49ef7e06SGarrett D'Amore 	__inout		ef10_filter_handle_t *handle)
183*49ef7e06SGarrett D'Amore {
184*49ef7e06SGarrett D'Amore 	efx_mcdi_req_t req;
185*49ef7e06SGarrett D'Amore 	uint8_t payload[MAX(MC_CMD_FILTER_OP_IN_LEN,
186*49ef7e06SGarrett D'Amore 			    MC_CMD_FILTER_OP_OUT_LEN)];
187*49ef7e06SGarrett D'Amore 	uint32_t match_fields = 0;
188*49ef7e06SGarrett D'Amore 	efx_rc_t rc;
189*49ef7e06SGarrett D'Amore 
190*49ef7e06SGarrett D'Amore 	(void) memset(payload, 0, sizeof (payload));
191*49ef7e06SGarrett D'Amore 	req.emr_cmd = MC_CMD_FILTER_OP;
192*49ef7e06SGarrett D'Amore 	req.emr_in_buf = payload;
193*49ef7e06SGarrett D'Amore 	req.emr_in_length = MC_CMD_FILTER_OP_IN_LEN;
194*49ef7e06SGarrett D'Amore 	req.emr_out_buf = payload;
195*49ef7e06SGarrett D'Amore 	req.emr_out_length = MC_CMD_FILTER_OP_OUT_LEN;
196*49ef7e06SGarrett D'Amore 
197*49ef7e06SGarrett D'Amore 	switch (filter_op) {
198*49ef7e06SGarrett D'Amore 	case MC_CMD_FILTER_OP_IN_OP_REPLACE:
199*49ef7e06SGarrett D'Amore 		MCDI_IN_SET_DWORD(req, FILTER_OP_IN_HANDLE_LO,
200*49ef7e06SGarrett D'Amore 		    handle->efh_lo);
201*49ef7e06SGarrett D'Amore 		MCDI_IN_SET_DWORD(req, FILTER_OP_IN_HANDLE_HI,
202*49ef7e06SGarrett D'Amore 		    handle->efh_hi);
203*49ef7e06SGarrett D'Amore 		/* FALLTHROUGH */
204*49ef7e06SGarrett D'Amore 	case MC_CMD_FILTER_OP_IN_OP_INSERT:
205*49ef7e06SGarrett D'Amore 	case MC_CMD_FILTER_OP_IN_OP_SUBSCRIBE:
206*49ef7e06SGarrett D'Amore 		MCDI_IN_SET_DWORD(req, FILTER_OP_IN_OP, filter_op);
207*49ef7e06SGarrett D'Amore 		break;
208*49ef7e06SGarrett D'Amore 	default:
209*49ef7e06SGarrett D'Amore 		EFSYS_ASSERT(0);
210*49ef7e06SGarrett D'Amore 		rc = EINVAL;
211*49ef7e06SGarrett D'Amore 		goto fail1;
212*49ef7e06SGarrett D'Amore 	}
213*49ef7e06SGarrett D'Amore 
214*49ef7e06SGarrett D'Amore 	if (spec->efs_match_flags & EFX_FILTER_MATCH_LOC_MAC_IG) {
215*49ef7e06SGarrett D'Amore 		/*
216*49ef7e06SGarrett D'Amore 		 * The LOC_MAC_IG match flag can represent unknown unicast
217*49ef7e06SGarrett D'Amore 		 *  or multicast filters - use the MAC address to distinguish
218*49ef7e06SGarrett D'Amore 		 *  them.
219*49ef7e06SGarrett D'Amore 		 */
220*49ef7e06SGarrett D'Amore 		if (EFX_MAC_ADDR_IS_MULTICAST(spec->efs_loc_mac))
221*49ef7e06SGarrett D'Amore 			match_fields |= 1U <<
222*49ef7e06SGarrett D'Amore 				MC_CMD_FILTER_OP_IN_MATCH_UNKNOWN_MCAST_DST_LBN;
223*49ef7e06SGarrett D'Amore 		else
224*49ef7e06SGarrett D'Amore 			match_fields |= 1U <<
225*49ef7e06SGarrett D'Amore 				MC_CMD_FILTER_OP_IN_MATCH_UNKNOWN_UCAST_DST_LBN;
226*49ef7e06SGarrett D'Amore 	}
227*49ef7e06SGarrett D'Amore 
228*49ef7e06SGarrett D'Amore 	match_fields |= spec->efs_match_flags & (~EFX_FILTER_MATCH_LOC_MAC_IG);
229*49ef7e06SGarrett D'Amore 
230*49ef7e06SGarrett D'Amore 	MCDI_IN_SET_DWORD(req, FILTER_OP_IN_PORT_ID,
231*49ef7e06SGarrett D'Amore 	    EVB_PORT_ID_ASSIGNED);
232*49ef7e06SGarrett D'Amore 	MCDI_IN_SET_DWORD(req, FILTER_OP_IN_MATCH_FIELDS,
233*49ef7e06SGarrett D'Amore 	    match_fields);
234*49ef7e06SGarrett D'Amore 	MCDI_IN_SET_DWORD(req, FILTER_OP_IN_RX_DEST,
235*49ef7e06SGarrett D'Amore 	    MC_CMD_FILTER_OP_IN_RX_DEST_HOST);
236*49ef7e06SGarrett D'Amore 	MCDI_IN_SET_DWORD(req, FILTER_OP_IN_RX_QUEUE,
237*49ef7e06SGarrett D'Amore 	    spec->efs_dmaq_id);
238*49ef7e06SGarrett D'Amore 	if (spec->efs_flags & EFX_FILTER_FLAG_RX_RSS) {
239*49ef7e06SGarrett D'Amore 		MCDI_IN_SET_DWORD(req, FILTER_OP_IN_RX_CONTEXT,
240*49ef7e06SGarrett D'Amore 		    spec->efs_rss_context);
241*49ef7e06SGarrett D'Amore 	}
242*49ef7e06SGarrett D'Amore 	MCDI_IN_SET_DWORD(req, FILTER_OP_IN_RX_MODE,
243*49ef7e06SGarrett D'Amore 	    spec->efs_flags & EFX_FILTER_FLAG_RX_RSS ?
244*49ef7e06SGarrett D'Amore 	    MC_CMD_FILTER_OP_IN_RX_MODE_RSS :
245*49ef7e06SGarrett D'Amore 	    MC_CMD_FILTER_OP_IN_RX_MODE_SIMPLE);
246*49ef7e06SGarrett D'Amore 	MCDI_IN_SET_DWORD(req, FILTER_OP_IN_TX_DEST,
247*49ef7e06SGarrett D'Amore 	    MC_CMD_FILTER_OP_IN_TX_DEST_DEFAULT);
248*49ef7e06SGarrett D'Amore 
249*49ef7e06SGarrett D'Amore 	if (filter_op != MC_CMD_FILTER_OP_IN_OP_REPLACE) {
250*49ef7e06SGarrett D'Amore 		/*
251*49ef7e06SGarrett D'Amore 		 * NOTE: Unlike most MCDI requests, the filter fields
252*49ef7e06SGarrett D'Amore 		 * are presented in network (big endian) byte order.
253*49ef7e06SGarrett D'Amore 		 */
254*49ef7e06SGarrett D'Amore 		(void) memcpy(MCDI_IN2(req, uint8_t, FILTER_OP_IN_SRC_MAC),
255*49ef7e06SGarrett D'Amore 		    spec->efs_rem_mac, EFX_MAC_ADDR_LEN);
256*49ef7e06SGarrett D'Amore 		(void) memcpy(MCDI_IN2(req, uint8_t, FILTER_OP_IN_DST_MAC),
257*49ef7e06SGarrett D'Amore 		    spec->efs_loc_mac, EFX_MAC_ADDR_LEN);
258*49ef7e06SGarrett D'Amore 
259*49ef7e06SGarrett D'Amore 		MCDI_IN_SET_WORD(req, FILTER_OP_IN_SRC_PORT,
260*49ef7e06SGarrett D'Amore 		    __CPU_TO_BE_16(spec->efs_rem_port));
261*49ef7e06SGarrett D'Amore 		MCDI_IN_SET_WORD(req, FILTER_OP_IN_DST_PORT,
262*49ef7e06SGarrett D'Amore 		    __CPU_TO_BE_16(spec->efs_loc_port));
263*49ef7e06SGarrett D'Amore 
264*49ef7e06SGarrett D'Amore 		MCDI_IN_SET_WORD(req, FILTER_OP_IN_ETHER_TYPE,
265*49ef7e06SGarrett D'Amore 		    __CPU_TO_BE_16(spec->efs_ether_type));
266*49ef7e06SGarrett D'Amore 
267*49ef7e06SGarrett D'Amore 		MCDI_IN_SET_WORD(req, FILTER_OP_IN_INNER_VLAN,
268*49ef7e06SGarrett D'Amore 		    __CPU_TO_BE_16(spec->efs_inner_vid));
269*49ef7e06SGarrett D'Amore 		MCDI_IN_SET_WORD(req, FILTER_OP_IN_OUTER_VLAN,
270*49ef7e06SGarrett D'Amore 		    __CPU_TO_BE_16(spec->efs_outer_vid));
271*49ef7e06SGarrett D'Amore 
272*49ef7e06SGarrett D'Amore 		/* IP protocol (in low byte, high byte is zero) */
273*49ef7e06SGarrett D'Amore 		MCDI_IN_SET_BYTE(req, FILTER_OP_IN_IP_PROTO,
274*49ef7e06SGarrett D'Amore 		    spec->efs_ip_proto);
275*49ef7e06SGarrett D'Amore 
276*49ef7e06SGarrett D'Amore 		EFX_STATIC_ASSERT(sizeof (spec->efs_rem_host) ==
277*49ef7e06SGarrett D'Amore 		    MC_CMD_FILTER_OP_IN_SRC_IP_LEN);
278*49ef7e06SGarrett D'Amore 		EFX_STATIC_ASSERT(sizeof (spec->efs_loc_host) ==
279*49ef7e06SGarrett D'Amore 		    MC_CMD_FILTER_OP_IN_DST_IP_LEN);
280*49ef7e06SGarrett D'Amore 
281*49ef7e06SGarrett D'Amore 		(void) memcpy(MCDI_IN2(req, uint8_t, FILTER_OP_IN_SRC_IP),
282*49ef7e06SGarrett D'Amore 		    &spec->efs_rem_host.eo_byte[0],
283*49ef7e06SGarrett D'Amore 		    MC_CMD_FILTER_OP_IN_SRC_IP_LEN);
284*49ef7e06SGarrett D'Amore 		(void) memcpy(MCDI_IN2(req, uint8_t, FILTER_OP_IN_DST_IP),
285*49ef7e06SGarrett D'Amore 		    &spec->efs_loc_host.eo_byte[0],
286*49ef7e06SGarrett D'Amore 		    MC_CMD_FILTER_OP_IN_DST_IP_LEN);
287*49ef7e06SGarrett D'Amore 	}
288*49ef7e06SGarrett D'Amore 
289*49ef7e06SGarrett D'Amore 	efx_mcdi_execute(enp, &req);
290*49ef7e06SGarrett D'Amore 
291*49ef7e06SGarrett D'Amore 	if (req.emr_rc != 0) {
292*49ef7e06SGarrett D'Amore 		rc = req.emr_rc;
293*49ef7e06SGarrett D'Amore 		goto fail2;
294*49ef7e06SGarrett D'Amore 	}
295*49ef7e06SGarrett D'Amore 
296*49ef7e06SGarrett D'Amore 	if (req.emr_out_length_used < MC_CMD_FILTER_OP_OUT_LEN) {
297*49ef7e06SGarrett D'Amore 		rc = EMSGSIZE;
298*49ef7e06SGarrett D'Amore 		goto fail3;
299*49ef7e06SGarrett D'Amore 	}
300*49ef7e06SGarrett D'Amore 
301*49ef7e06SGarrett D'Amore 	handle->efh_lo = MCDI_OUT_DWORD(req, FILTER_OP_OUT_HANDLE_LO);
302*49ef7e06SGarrett D'Amore 	handle->efh_hi = MCDI_OUT_DWORD(req, FILTER_OP_OUT_HANDLE_HI);
303*49ef7e06SGarrett D'Amore 
304*49ef7e06SGarrett D'Amore 	return (0);
305*49ef7e06SGarrett D'Amore 
306*49ef7e06SGarrett D'Amore fail3:
307*49ef7e06SGarrett D'Amore 	EFSYS_PROBE(fail3);
308*49ef7e06SGarrett D'Amore fail2:
309*49ef7e06SGarrett D'Amore 	EFSYS_PROBE(fail2);
310*49ef7e06SGarrett D'Amore fail1:
311*49ef7e06SGarrett D'Amore 	EFSYS_PROBE1(fail1, efx_rc_t, rc);
312*49ef7e06SGarrett D'Amore 
313*49ef7e06SGarrett D'Amore 	return (rc);
314*49ef7e06SGarrett D'Amore 
315*49ef7e06SGarrett D'Amore }
316*49ef7e06SGarrett D'Amore 
317*49ef7e06SGarrett D'Amore static	__checkReturn	efx_rc_t
efx_mcdi_filter_op_delete(__in efx_nic_t * enp,__in unsigned int filter_op,__inout ef10_filter_handle_t * handle)318*49ef7e06SGarrett D'Amore efx_mcdi_filter_op_delete(
319*49ef7e06SGarrett D'Amore 	__in		efx_nic_t *enp,
320*49ef7e06SGarrett D'Amore 	__in		unsigned int filter_op,
321*49ef7e06SGarrett D'Amore 	__inout		ef10_filter_handle_t *handle)
322*49ef7e06SGarrett D'Amore {
323*49ef7e06SGarrett D'Amore 	efx_mcdi_req_t req;
324*49ef7e06SGarrett D'Amore 	uint8_t payload[MAX(MC_CMD_FILTER_OP_IN_LEN,
325*49ef7e06SGarrett D'Amore 			    MC_CMD_FILTER_OP_OUT_LEN)];
326*49ef7e06SGarrett D'Amore 	efx_rc_t rc;
327*49ef7e06SGarrett D'Amore 
328*49ef7e06SGarrett D'Amore 	(void) memset(payload, 0, sizeof (payload));
329*49ef7e06SGarrett D'Amore 	req.emr_cmd = MC_CMD_FILTER_OP;
330*49ef7e06SGarrett D'Amore 	req.emr_in_buf = payload;
331*49ef7e06SGarrett D'Amore 	req.emr_in_length = MC_CMD_FILTER_OP_IN_LEN;
332*49ef7e06SGarrett D'Amore 	req.emr_out_buf = payload;
333*49ef7e06SGarrett D'Amore 	req.emr_out_length = MC_CMD_FILTER_OP_OUT_LEN;
334*49ef7e06SGarrett D'Amore 
335*49ef7e06SGarrett D'Amore 	switch (filter_op) {
336*49ef7e06SGarrett D'Amore 	case MC_CMD_FILTER_OP_IN_OP_REMOVE:
337*49ef7e06SGarrett D'Amore 		MCDI_IN_SET_DWORD(req, FILTER_OP_IN_OP,
338*49ef7e06SGarrett D'Amore 		    MC_CMD_FILTER_OP_IN_OP_REMOVE);
339*49ef7e06SGarrett D'Amore 		break;
340*49ef7e06SGarrett D'Amore 	case MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE:
341*49ef7e06SGarrett D'Amore 		MCDI_IN_SET_DWORD(req, FILTER_OP_IN_OP,
342*49ef7e06SGarrett D'Amore 		    MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE);
343*49ef7e06SGarrett D'Amore 		break;
344*49ef7e06SGarrett D'Amore 	default:
345*49ef7e06SGarrett D'Amore 		EFSYS_ASSERT(0);
346*49ef7e06SGarrett D'Amore 		rc = EINVAL;
347*49ef7e06SGarrett D'Amore 		goto fail1;
348*49ef7e06SGarrett D'Amore 	}
349*49ef7e06SGarrett D'Amore 
350*49ef7e06SGarrett D'Amore 	MCDI_IN_SET_DWORD(req, FILTER_OP_IN_HANDLE_LO, handle->efh_lo);
351*49ef7e06SGarrett D'Amore 	MCDI_IN_SET_DWORD(req, FILTER_OP_IN_HANDLE_HI, handle->efh_hi);
352*49ef7e06SGarrett D'Amore 
353*49ef7e06SGarrett D'Amore 	efx_mcdi_execute(enp, &req);
354*49ef7e06SGarrett D'Amore 
355*49ef7e06SGarrett D'Amore 	if (req.emr_rc != 0) {
356*49ef7e06SGarrett D'Amore 		rc = req.emr_rc;
357*49ef7e06SGarrett D'Amore 		goto fail2;
358*49ef7e06SGarrett D'Amore 	}
359*49ef7e06SGarrett D'Amore 
360*49ef7e06SGarrett D'Amore 	if (req.emr_out_length_used < MC_CMD_FILTER_OP_OUT_LEN) {
361*49ef7e06SGarrett D'Amore 		rc = EMSGSIZE;
362*49ef7e06SGarrett D'Amore 		goto fail3;
363*49ef7e06SGarrett D'Amore 	}
364*49ef7e06SGarrett D'Amore 
365*49ef7e06SGarrett D'Amore 	return (0);
366*49ef7e06SGarrett D'Amore 
367*49ef7e06SGarrett D'Amore fail3:
368*49ef7e06SGarrett D'Amore 	EFSYS_PROBE(fail3);
369*49ef7e06SGarrett D'Amore 
370*49ef7e06SGarrett D'Amore fail2:
371*49ef7e06SGarrett D'Amore 	EFSYS_PROBE(fail2);
372*49ef7e06SGarrett D'Amore fail1:
373*49ef7e06SGarrett D'Amore 	EFSYS_PROBE1(fail1, efx_rc_t, rc);
374*49ef7e06SGarrett D'Amore 
375*49ef7e06SGarrett D'Amore 	return (rc);
376*49ef7e06SGarrett D'Amore }
377*49ef7e06SGarrett D'Amore 
378*49ef7e06SGarrett D'Amore static	__checkReturn	boolean_t
ef10_filter_equal(__in const efx_filter_spec_t * left,__in const efx_filter_spec_t * right)379*49ef7e06SGarrett D'Amore ef10_filter_equal(
380*49ef7e06SGarrett D'Amore 	__in		const efx_filter_spec_t *left,
381*49ef7e06SGarrett D'Amore 	__in		const efx_filter_spec_t *right)
382*49ef7e06SGarrett D'Amore {
383*49ef7e06SGarrett D'Amore 	/* FIXME: Consider rx vs tx filters (look at efs_flags) */
384*49ef7e06SGarrett D'Amore 	if (left->efs_match_flags != right->efs_match_flags)
385*49ef7e06SGarrett D'Amore 		return (B_FALSE);
386*49ef7e06SGarrett D'Amore 	if (!EFX_OWORD_IS_EQUAL(left->efs_rem_host, right->efs_rem_host))
387*49ef7e06SGarrett D'Amore 		return (B_FALSE);
388*49ef7e06SGarrett D'Amore 	if (!EFX_OWORD_IS_EQUAL(left->efs_loc_host, right->efs_loc_host))
389*49ef7e06SGarrett D'Amore 		return (B_FALSE);
390*49ef7e06SGarrett D'Amore 	if (memcmp(left->efs_rem_mac, right->efs_rem_mac, EFX_MAC_ADDR_LEN))
391*49ef7e06SGarrett D'Amore 		return (B_FALSE);
392*49ef7e06SGarrett D'Amore 	if (memcmp(left->efs_loc_mac, right->efs_loc_mac, EFX_MAC_ADDR_LEN))
393*49ef7e06SGarrett D'Amore 		return (B_FALSE);
394*49ef7e06SGarrett D'Amore 	if (left->efs_rem_port != right->efs_rem_port)
395*49ef7e06SGarrett D'Amore 		return (B_FALSE);
396*49ef7e06SGarrett D'Amore 	if (left->efs_loc_port != right->efs_loc_port)
397*49ef7e06SGarrett D'Amore 		return (B_FALSE);
398*49ef7e06SGarrett D'Amore 	if (left->efs_inner_vid != right->efs_inner_vid)
399*49ef7e06SGarrett D'Amore 		return (B_FALSE);
400*49ef7e06SGarrett D'Amore 	if (left->efs_outer_vid != right->efs_outer_vid)
401*49ef7e06SGarrett D'Amore 		return (B_FALSE);
402*49ef7e06SGarrett D'Amore 	if (left->efs_ether_type != right->efs_ether_type)
403*49ef7e06SGarrett D'Amore 		return (B_FALSE);
404*49ef7e06SGarrett D'Amore 	if (left->efs_ip_proto != right->efs_ip_proto)
405*49ef7e06SGarrett D'Amore 		return (B_FALSE);
406*49ef7e06SGarrett D'Amore 
407*49ef7e06SGarrett D'Amore 	return (B_TRUE);
408*49ef7e06SGarrett D'Amore 
409*49ef7e06SGarrett D'Amore }
410*49ef7e06SGarrett D'Amore 
411*49ef7e06SGarrett D'Amore static	__checkReturn	boolean_t
ef10_filter_same_dest(__in const efx_filter_spec_t * left,__in const efx_filter_spec_t * right)412*49ef7e06SGarrett D'Amore ef10_filter_same_dest(
413*49ef7e06SGarrett D'Amore 	__in		const efx_filter_spec_t *left,
414*49ef7e06SGarrett D'Amore 	__in		const efx_filter_spec_t *right)
415*49ef7e06SGarrett D'Amore {
416*49ef7e06SGarrett D'Amore 	if ((left->efs_flags & EFX_FILTER_FLAG_RX_RSS) &&
417*49ef7e06SGarrett D'Amore 	    (right->efs_flags & EFX_FILTER_FLAG_RX_RSS)) {
418*49ef7e06SGarrett D'Amore 		if (left->efs_rss_context == right->efs_rss_context)
419*49ef7e06SGarrett D'Amore 			return (B_TRUE);
420*49ef7e06SGarrett D'Amore 	} else if ((~(left->efs_flags) & EFX_FILTER_FLAG_RX_RSS) &&
421*49ef7e06SGarrett D'Amore 	    (~(right->efs_flags) & EFX_FILTER_FLAG_RX_RSS)) {
422*49ef7e06SGarrett D'Amore 		if (left->efs_dmaq_id == right->efs_dmaq_id)
423*49ef7e06SGarrett D'Amore 			return (B_TRUE);
424*49ef7e06SGarrett D'Amore 	}
425*49ef7e06SGarrett D'Amore 	return (B_FALSE);
426*49ef7e06SGarrett D'Amore }
427*49ef7e06SGarrett D'Amore 
428*49ef7e06SGarrett D'Amore static	__checkReturn	uint32_t
ef10_filter_hash(__in efx_filter_spec_t * spec)429*49ef7e06SGarrett D'Amore ef10_filter_hash(
430*49ef7e06SGarrett D'Amore 	__in		efx_filter_spec_t *spec)
431*49ef7e06SGarrett D'Amore {
432*49ef7e06SGarrett D'Amore 	EFX_STATIC_ASSERT((sizeof (efx_filter_spec_t) % sizeof (uint32_t))
433*49ef7e06SGarrett D'Amore 			    == 0);
434*49ef7e06SGarrett D'Amore 	EFX_STATIC_ASSERT((EFX_FIELD_OFFSET(efx_filter_spec_t, efs_outer_vid) %
435*49ef7e06SGarrett D'Amore 			    sizeof (uint32_t)) == 0);
436*49ef7e06SGarrett D'Amore 
437*49ef7e06SGarrett D'Amore 	/*
438*49ef7e06SGarrett D'Amore 	 * As the area of the efx_filter_spec_t we need to hash is DWORD
439*49ef7e06SGarrett D'Amore 	 * aligned and an exact number of DWORDs in size we can use the
440*49ef7e06SGarrett D'Amore 	 * optimised efx_hash_dwords() rather than efx_hash_bytes()
441*49ef7e06SGarrett D'Amore 	 */
442*49ef7e06SGarrett D'Amore 	return (efx_hash_dwords((const void *)&spec->efs_outer_vid,
443*49ef7e06SGarrett D'Amore 			(sizeof (efx_filter_spec_t) -
444*49ef7e06SGarrett D'Amore 			EFX_FIELD_OFFSET(efx_filter_spec_t, efs_outer_vid)) /
445*49ef7e06SGarrett D'Amore 			sizeof (uint32_t), 0));
446*49ef7e06SGarrett D'Amore }
447*49ef7e06SGarrett D'Amore 
448*49ef7e06SGarrett D'Amore /*
449*49ef7e06SGarrett D'Amore  * Decide whether a filter should be exclusive or else should allow
450*49ef7e06SGarrett D'Amore  * delivery to additional recipients.  Currently we decide that
451*49ef7e06SGarrett D'Amore  * filters for specific local unicast MAC and IP addresses are
452*49ef7e06SGarrett D'Amore  * exclusive.
453*49ef7e06SGarrett D'Amore  */
454*49ef7e06SGarrett D'Amore static	__checkReturn	boolean_t
ef10_filter_is_exclusive(__in efx_filter_spec_t * spec)455*49ef7e06SGarrett D'Amore ef10_filter_is_exclusive(
456*49ef7e06SGarrett D'Amore 	__in		efx_filter_spec_t *spec)
457*49ef7e06SGarrett D'Amore {
458*49ef7e06SGarrett D'Amore 	if ((spec->efs_match_flags & EFX_FILTER_MATCH_LOC_MAC) &&
459*49ef7e06SGarrett D'Amore 	    !EFX_MAC_ADDR_IS_MULTICAST(spec->efs_loc_mac))
460*49ef7e06SGarrett D'Amore 		return (B_TRUE);
461*49ef7e06SGarrett D'Amore 
462*49ef7e06SGarrett D'Amore 	if ((spec->efs_match_flags &
463*49ef7e06SGarrett D'Amore 		(EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_LOC_HOST)) ==
464*49ef7e06SGarrett D'Amore 	    (EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_LOC_HOST)) {
465*49ef7e06SGarrett D'Amore 		if ((spec->efs_ether_type == EFX_ETHER_TYPE_IPV4) &&
466*49ef7e06SGarrett D'Amore 		    ((spec->efs_loc_host.eo_u8[0] & 0xf) != 0xe))
467*49ef7e06SGarrett D'Amore 			return (B_TRUE);
468*49ef7e06SGarrett D'Amore 		if ((spec->efs_ether_type == EFX_ETHER_TYPE_IPV6) &&
469*49ef7e06SGarrett D'Amore 		    (spec->efs_loc_host.eo_u8[0] != 0xff))
470*49ef7e06SGarrett D'Amore 			return (B_TRUE);
471*49ef7e06SGarrett D'Amore 	}
472*49ef7e06SGarrett D'Amore 
473*49ef7e06SGarrett D'Amore 	return (B_FALSE);
474*49ef7e06SGarrett D'Amore }
475*49ef7e06SGarrett D'Amore 
476*49ef7e06SGarrett D'Amore 	__checkReturn	efx_rc_t
ef10_filter_restore(__in efx_nic_t * enp)477*49ef7e06SGarrett D'Amore ef10_filter_restore(
478*49ef7e06SGarrett D'Amore 	__in		efx_nic_t *enp)
479*49ef7e06SGarrett D'Amore {
480*49ef7e06SGarrett D'Amore 	int tbl_id;
481*49ef7e06SGarrett D'Amore 	efx_filter_spec_t *spec;
482*49ef7e06SGarrett D'Amore 	ef10_filter_table_t *eftp = enp->en_filter.ef_ef10_filter_table;
483*49ef7e06SGarrett D'Amore 	boolean_t restoring;
484*49ef7e06SGarrett D'Amore 	int state;
485*49ef7e06SGarrett D'Amore 	efx_rc_t rc;
486*49ef7e06SGarrett D'Amore 
487*49ef7e06SGarrett D'Amore 	EFSYS_ASSERT(enp->en_family == EFX_FAMILY_HUNTINGTON ||
488*49ef7e06SGarrett D'Amore 		    enp->en_family == EFX_FAMILY_MEDFORD);
489*49ef7e06SGarrett D'Amore 
490*49ef7e06SGarrett D'Amore 	for (tbl_id = 0; tbl_id < EFX_EF10_FILTER_TBL_ROWS; tbl_id++) {
491*49ef7e06SGarrett D'Amore 
492*49ef7e06SGarrett D'Amore 		EFSYS_LOCK(enp->en_eslp, state);
493*49ef7e06SGarrett D'Amore 
494*49ef7e06SGarrett D'Amore 		spec = ef10_filter_entry_spec(eftp, tbl_id);
495*49ef7e06SGarrett D'Amore 		if (spec == NULL) {
496*49ef7e06SGarrett D'Amore 			restoring = B_FALSE;
497*49ef7e06SGarrett D'Amore 		} else if (ef10_filter_entry_is_busy(eftp, tbl_id)) {
498*49ef7e06SGarrett D'Amore 			/* Ignore busy entries. */
499*49ef7e06SGarrett D'Amore 			restoring = B_FALSE;
500*49ef7e06SGarrett D'Amore 		} else {
501*49ef7e06SGarrett D'Amore 			ef10_filter_set_entry_busy(eftp, tbl_id);
502*49ef7e06SGarrett D'Amore 			restoring = B_TRUE;
503*49ef7e06SGarrett D'Amore 		}
504*49ef7e06SGarrett D'Amore 
505*49ef7e06SGarrett D'Amore 		EFSYS_UNLOCK(enp->en_eslp, state);
506*49ef7e06SGarrett D'Amore 
507*49ef7e06SGarrett D'Amore 		if (restoring == B_FALSE)
508*49ef7e06SGarrett D'Amore 			continue;
509*49ef7e06SGarrett D'Amore 
510*49ef7e06SGarrett D'Amore 		if (ef10_filter_is_exclusive(spec)) {
511*49ef7e06SGarrett D'Amore 			rc = efx_mcdi_filter_op_add(enp, spec,
512*49ef7e06SGarrett D'Amore 			    MC_CMD_FILTER_OP_IN_OP_INSERT,
513*49ef7e06SGarrett D'Amore 			    &eftp->eft_entry[tbl_id].efe_handle);
514*49ef7e06SGarrett D'Amore 		} else {
515*49ef7e06SGarrett D'Amore 			rc = efx_mcdi_filter_op_add(enp, spec,
516*49ef7e06SGarrett D'Amore 			    MC_CMD_FILTER_OP_IN_OP_SUBSCRIBE,
517*49ef7e06SGarrett D'Amore 			    &eftp->eft_entry[tbl_id].efe_handle);
518*49ef7e06SGarrett D'Amore 		}
519*49ef7e06SGarrett D'Amore 
520*49ef7e06SGarrett D'Amore 		if (rc != 0)
521*49ef7e06SGarrett D'Amore 			goto fail1;
522*49ef7e06SGarrett D'Amore 
523*49ef7e06SGarrett D'Amore 		EFSYS_LOCK(enp->en_eslp, state);
524*49ef7e06SGarrett D'Amore 
525*49ef7e06SGarrett D'Amore 		ef10_filter_set_entry_not_busy(eftp, tbl_id);
526*49ef7e06SGarrett D'Amore 
527*49ef7e06SGarrett D'Amore 		EFSYS_UNLOCK(enp->en_eslp, state);
528*49ef7e06SGarrett D'Amore 	}
529*49ef7e06SGarrett D'Amore 
530*49ef7e06SGarrett D'Amore 	return (0);
531*49ef7e06SGarrett D'Amore 
532*49ef7e06SGarrett D'Amore fail1:
533*49ef7e06SGarrett D'Amore 	EFSYS_PROBE1(fail1, efx_rc_t, rc);
534*49ef7e06SGarrett D'Amore 
535*49ef7e06SGarrett D'Amore 	return (rc);
536*49ef7e06SGarrett D'Amore }
537*49ef7e06SGarrett D'Amore 
538*49ef7e06SGarrett D'Amore /*
539*49ef7e06SGarrett D'Amore  * An arbitrary search limit for the software hash table. As per the linux net
540*49ef7e06SGarrett D'Amore  * driver.
541*49ef7e06SGarrett D'Amore  */
542*49ef7e06SGarrett D'Amore #define	EF10_FILTER_SEARCH_LIMIT 200
543*49ef7e06SGarrett D'Amore 
544*49ef7e06SGarrett D'Amore static	__checkReturn	efx_rc_t
ef10_filter_add_internal(__in efx_nic_t * enp,__inout efx_filter_spec_t * spec,__in boolean_t may_replace,__out_opt uint32_t * filter_id)545*49ef7e06SGarrett D'Amore ef10_filter_add_internal(
546*49ef7e06SGarrett D'Amore 	__in		efx_nic_t *enp,
547*49ef7e06SGarrett D'Amore 	__inout		efx_filter_spec_t *spec,
548*49ef7e06SGarrett D'Amore 	__in		boolean_t may_replace,
549*49ef7e06SGarrett D'Amore 	__out_opt	uint32_t *filter_id)
550*49ef7e06SGarrett D'Amore {
551*49ef7e06SGarrett D'Amore 	efx_rc_t rc;
552*49ef7e06SGarrett D'Amore 	ef10_filter_table_t *eftp = enp->en_filter.ef_ef10_filter_table;
553*49ef7e06SGarrett D'Amore 	efx_filter_spec_t *saved_spec;
554*49ef7e06SGarrett D'Amore 	uint32_t hash;
555*49ef7e06SGarrett D'Amore 	unsigned int depth;
556*49ef7e06SGarrett D'Amore 	int ins_index;
557*49ef7e06SGarrett D'Amore 	boolean_t replacing = B_FALSE;
558*49ef7e06SGarrett D'Amore 	unsigned int i;
559*49ef7e06SGarrett D'Amore 	int state;
560*49ef7e06SGarrett D'Amore 	boolean_t locked = B_FALSE;
561*49ef7e06SGarrett D'Amore 
562*49ef7e06SGarrett D'Amore 	EFSYS_ASSERT(enp->en_family == EFX_FAMILY_HUNTINGTON ||
563*49ef7e06SGarrett D'Amore 		    enp->en_family == EFX_FAMILY_MEDFORD);
564*49ef7e06SGarrett D'Amore 
565*49ef7e06SGarrett D'Amore #if EFSYS_OPT_RX_SCALE
566*49ef7e06SGarrett D'Amore 	spec->efs_rss_context = enp->en_rss_context;
567*49ef7e06SGarrett D'Amore #endif
568*49ef7e06SGarrett D'Amore 
569*49ef7e06SGarrett D'Amore 	hash = ef10_filter_hash(spec);
570*49ef7e06SGarrett D'Amore 
571*49ef7e06SGarrett D'Amore 	/*
572*49ef7e06SGarrett D'Amore 	 * FIXME: Add support for inserting filters of different priorities
573*49ef7e06SGarrett D'Amore 	 * and removing lower priority multicast filters (bug 42378)
574*49ef7e06SGarrett D'Amore 	 */
575*49ef7e06SGarrett D'Amore 
576*49ef7e06SGarrett D'Amore 	/*
577*49ef7e06SGarrett D'Amore 	 * Find any existing filters with the same match tuple or
578*49ef7e06SGarrett D'Amore 	 * else a free slot to insert at.  If any of them are busy,
579*49ef7e06SGarrett D'Amore 	 * we have to wait and retry.
580*49ef7e06SGarrett D'Amore 	 */
581*49ef7e06SGarrett D'Amore 	for (;;) {
582*49ef7e06SGarrett D'Amore 		ins_index = -1;
583*49ef7e06SGarrett D'Amore 		depth = 1;
584*49ef7e06SGarrett D'Amore 		EFSYS_LOCK(enp->en_eslp, state);
585*49ef7e06SGarrett D'Amore 		locked = B_TRUE;
586*49ef7e06SGarrett D'Amore 
587*49ef7e06SGarrett D'Amore 		for (;;) {
588*49ef7e06SGarrett D'Amore 			i = (hash + depth) & (EFX_EF10_FILTER_TBL_ROWS - 1);
589*49ef7e06SGarrett D'Amore 			saved_spec = ef10_filter_entry_spec(eftp, i);
590*49ef7e06SGarrett D'Amore 
591*49ef7e06SGarrett D'Amore 			if (!saved_spec) {
592*49ef7e06SGarrett D'Amore 				if (ins_index < 0) {
593*49ef7e06SGarrett D'Amore 					ins_index = i;
594*49ef7e06SGarrett D'Amore 				}
595*49ef7e06SGarrett D'Amore 			} else if (ef10_filter_equal(spec, saved_spec)) {
596*49ef7e06SGarrett D'Amore 				if (ef10_filter_entry_is_busy(eftp, i))
597*49ef7e06SGarrett D'Amore 					break;
598*49ef7e06SGarrett D'Amore 				if (saved_spec->efs_priority
599*49ef7e06SGarrett D'Amore 					    == EFX_FILTER_PRI_AUTO) {
600*49ef7e06SGarrett D'Amore 					ins_index = i;
601*49ef7e06SGarrett D'Amore 					goto found;
602*49ef7e06SGarrett D'Amore 				} else if (ef10_filter_is_exclusive(spec)) {
603*49ef7e06SGarrett D'Amore 					if (may_replace) {
604*49ef7e06SGarrett D'Amore 						ins_index = i;
605*49ef7e06SGarrett D'Amore 						goto found;
606*49ef7e06SGarrett D'Amore 					} else {
607*49ef7e06SGarrett D'Amore 						rc = EEXIST;
608*49ef7e06SGarrett D'Amore 						goto fail1;
609*49ef7e06SGarrett D'Amore 					}
610*49ef7e06SGarrett D'Amore 				}
611*49ef7e06SGarrett D'Amore 
612*49ef7e06SGarrett D'Amore 				/* Leave existing */
613*49ef7e06SGarrett D'Amore 			}
614*49ef7e06SGarrett D'Amore 
615*49ef7e06SGarrett D'Amore 			/*
616*49ef7e06SGarrett D'Amore 			 * Once we reach the maximum search depth, use
617*49ef7e06SGarrett D'Amore 			 * the first suitable slot or return EBUSY if
618*49ef7e06SGarrett D'Amore 			 * there was none.
619*49ef7e06SGarrett D'Amore 			 */
620*49ef7e06SGarrett D'Amore 			if (depth == EF10_FILTER_SEARCH_LIMIT) {
621*49ef7e06SGarrett D'Amore 				if (ins_index < 0) {
622*49ef7e06SGarrett D'Amore 					rc = EBUSY;
623*49ef7e06SGarrett D'Amore 					goto fail2;
624*49ef7e06SGarrett D'Amore 				}
625*49ef7e06SGarrett D'Amore 				goto found;
626*49ef7e06SGarrett D'Amore 			}
627*49ef7e06SGarrett D'Amore 			depth++;
628*49ef7e06SGarrett D'Amore 		}
629*49ef7e06SGarrett D'Amore 		EFSYS_UNLOCK(enp->en_eslp, state);
630*49ef7e06SGarrett D'Amore 		locked = B_FALSE;
631*49ef7e06SGarrett D'Amore 	}
632*49ef7e06SGarrett D'Amore 
633*49ef7e06SGarrett D'Amore found:
634*49ef7e06SGarrett D'Amore 	/*
635*49ef7e06SGarrett D'Amore 	 * Create a software table entry if necessary, and mark it
636*49ef7e06SGarrett D'Amore 	 * busy.  We might yet fail to insert, but any attempt to
637*49ef7e06SGarrett D'Amore 	 * insert a conflicting filter while we're waiting for the
638*49ef7e06SGarrett D'Amore 	 * firmware must find the busy entry.
639*49ef7e06SGarrett D'Amore 	 */
640*49ef7e06SGarrett D'Amore 	saved_spec = ef10_filter_entry_spec(eftp, ins_index);
641*49ef7e06SGarrett D'Amore 	if (saved_spec) {
642*49ef7e06SGarrett D'Amore 		if (saved_spec->efs_priority == EFX_FILTER_PRI_AUTO) {
643*49ef7e06SGarrett D'Amore 			/* This is a filter we are refreshing */
644*49ef7e06SGarrett D'Amore 			ef10_filter_set_entry_not_auto_old(eftp, ins_index);
645*49ef7e06SGarrett D'Amore 			goto out_unlock;
646*49ef7e06SGarrett D'Amore 
647*49ef7e06SGarrett D'Amore 		}
648*49ef7e06SGarrett D'Amore 		replacing = B_TRUE;
649*49ef7e06SGarrett D'Amore 	} else {
650*49ef7e06SGarrett D'Amore 		EFSYS_KMEM_ALLOC(enp->en_esip, sizeof (*spec), saved_spec);
651*49ef7e06SGarrett D'Amore 		if (!saved_spec) {
652*49ef7e06SGarrett D'Amore 			rc = ENOMEM;
653*49ef7e06SGarrett D'Amore 			goto fail3;
654*49ef7e06SGarrett D'Amore 		}
655*49ef7e06SGarrett D'Amore 		*saved_spec = *spec;
656*49ef7e06SGarrett D'Amore 		ef10_filter_set_entry(eftp, ins_index, saved_spec);
657*49ef7e06SGarrett D'Amore 	}
658*49ef7e06SGarrett D'Amore 	ef10_filter_set_entry_busy(eftp, ins_index);
659*49ef7e06SGarrett D'Amore 
660*49ef7e06SGarrett D'Amore 	EFSYS_UNLOCK(enp->en_eslp, state);
661*49ef7e06SGarrett D'Amore 	locked = B_FALSE;
662*49ef7e06SGarrett D'Amore 
663*49ef7e06SGarrett D'Amore 	/*
664*49ef7e06SGarrett D'Amore 	 * On replacing the filter handle may change after after a successful
665*49ef7e06SGarrett D'Amore 	 * replace operation.
666*49ef7e06SGarrett D'Amore 	 */
667*49ef7e06SGarrett D'Amore 	if (replacing) {
668*49ef7e06SGarrett D'Amore 		rc = efx_mcdi_filter_op_add(enp, spec,
669*49ef7e06SGarrett D'Amore 		    MC_CMD_FILTER_OP_IN_OP_REPLACE,
670*49ef7e06SGarrett D'Amore 		    &eftp->eft_entry[ins_index].efe_handle);
671*49ef7e06SGarrett D'Amore 	} else if (ef10_filter_is_exclusive(spec)) {
672*49ef7e06SGarrett D'Amore 		rc = efx_mcdi_filter_op_add(enp, spec,
673*49ef7e06SGarrett D'Amore 		    MC_CMD_FILTER_OP_IN_OP_INSERT,
674*49ef7e06SGarrett D'Amore 		    &eftp->eft_entry[ins_index].efe_handle);
675*49ef7e06SGarrett D'Amore 	} else {
676*49ef7e06SGarrett D'Amore 		rc = efx_mcdi_filter_op_add(enp, spec,
677*49ef7e06SGarrett D'Amore 		    MC_CMD_FILTER_OP_IN_OP_SUBSCRIBE,
678*49ef7e06SGarrett D'Amore 		    &eftp->eft_entry[ins_index].efe_handle);
679*49ef7e06SGarrett D'Amore 	}
680*49ef7e06SGarrett D'Amore 
681*49ef7e06SGarrett D'Amore 	if (rc != 0)
682*49ef7e06SGarrett D'Amore 		goto fail4;
683*49ef7e06SGarrett D'Amore 
684*49ef7e06SGarrett D'Amore 	EFSYS_LOCK(enp->en_eslp, state);
685*49ef7e06SGarrett D'Amore 	locked = B_TRUE;
686*49ef7e06SGarrett D'Amore 
687*49ef7e06SGarrett D'Amore 	if (replacing) {
688*49ef7e06SGarrett D'Amore 		/* Update the fields that may differ */
689*49ef7e06SGarrett D'Amore 		saved_spec->efs_priority = spec->efs_priority;
690*49ef7e06SGarrett D'Amore 		saved_spec->efs_flags = spec->efs_flags;
691*49ef7e06SGarrett D'Amore 		saved_spec->efs_rss_context = spec->efs_rss_context;
692*49ef7e06SGarrett D'Amore 		saved_spec->efs_dmaq_id = spec->efs_dmaq_id;
693*49ef7e06SGarrett D'Amore 	}
694*49ef7e06SGarrett D'Amore 
695*49ef7e06SGarrett D'Amore 	ef10_filter_set_entry_not_busy(eftp, ins_index);
696*49ef7e06SGarrett D'Amore 
697*49ef7e06SGarrett D'Amore out_unlock:
698*49ef7e06SGarrett D'Amore 
699*49ef7e06SGarrett D'Amore 	EFSYS_UNLOCK(enp->en_eslp, state);
700*49ef7e06SGarrett D'Amore 	locked = B_FALSE;
701*49ef7e06SGarrett D'Amore 
702*49ef7e06SGarrett D'Amore 	if (filter_id)
703*49ef7e06SGarrett D'Amore 		*filter_id = ins_index;
704*49ef7e06SGarrett D'Amore 
705*49ef7e06SGarrett D'Amore 	return (0);
706*49ef7e06SGarrett D'Amore 
707*49ef7e06SGarrett D'Amore fail4:
708*49ef7e06SGarrett D'Amore 	EFSYS_PROBE(fail4);
709*49ef7e06SGarrett D'Amore 
710*49ef7e06SGarrett D'Amore 	if (!replacing) {
711*49ef7e06SGarrett D'Amore 		EFSYS_KMEM_FREE(enp->en_esip, sizeof (*spec), saved_spec);
712*49ef7e06SGarrett D'Amore 		saved_spec = NULL;
713*49ef7e06SGarrett D'Amore 	}
714*49ef7e06SGarrett D'Amore 	ef10_filter_set_entry_not_busy(eftp, ins_index);
715*49ef7e06SGarrett D'Amore 	ef10_filter_set_entry(eftp, ins_index, NULL);
716*49ef7e06SGarrett D'Amore 
717*49ef7e06SGarrett D'Amore fail3:
718*49ef7e06SGarrett D'Amore 	EFSYS_PROBE(fail3);
719*49ef7e06SGarrett D'Amore 
720*49ef7e06SGarrett D'Amore fail2:
721*49ef7e06SGarrett D'Amore 	EFSYS_PROBE(fail2);
722*49ef7e06SGarrett D'Amore 
723*49ef7e06SGarrett D'Amore fail1:
724*49ef7e06SGarrett D'Amore 	EFSYS_PROBE1(fail1, efx_rc_t, rc);
725*49ef7e06SGarrett D'Amore 
726*49ef7e06SGarrett D'Amore 	if (locked)
727*49ef7e06SGarrett D'Amore 		EFSYS_UNLOCK(enp->en_eslp, state);
728*49ef7e06SGarrett D'Amore 
729*49ef7e06SGarrett D'Amore 	return (rc);
730*49ef7e06SGarrett D'Amore }
731*49ef7e06SGarrett D'Amore 
732*49ef7e06SGarrett D'Amore 	__checkReturn	efx_rc_t
ef10_filter_add(__in efx_nic_t * enp,__inout efx_filter_spec_t * spec,__in boolean_t may_replace)733*49ef7e06SGarrett D'Amore ef10_filter_add(
734*49ef7e06SGarrett D'Amore 	__in		efx_nic_t *enp,
735*49ef7e06SGarrett D'Amore 	__inout		efx_filter_spec_t *spec,
736*49ef7e06SGarrett D'Amore 	__in		boolean_t may_replace)
737*49ef7e06SGarrett D'Amore {
738*49ef7e06SGarrett D'Amore 	efx_rc_t rc;
739*49ef7e06SGarrett D'Amore 
740*49ef7e06SGarrett D'Amore 	rc = ef10_filter_add_internal(enp, spec, may_replace, NULL);
741*49ef7e06SGarrett D'Amore 	if (rc != 0)
742*49ef7e06SGarrett D'Amore 		goto fail1;
743*49ef7e06SGarrett D'Amore 
744*49ef7e06SGarrett D'Amore 	return (0);
745*49ef7e06SGarrett D'Amore 
746*49ef7e06SGarrett D'Amore fail1:
747*49ef7e06SGarrett D'Amore 	EFSYS_PROBE1(fail1, efx_rc_t, rc);
748*49ef7e06SGarrett D'Amore 
749*49ef7e06SGarrett D'Amore 	return (rc);
750*49ef7e06SGarrett D'Amore }
751*49ef7e06SGarrett D'Amore 
752*49ef7e06SGarrett D'Amore 
753*49ef7e06SGarrett D'Amore static	__checkReturn	efx_rc_t
ef10_filter_delete_internal(__in efx_nic_t * enp,__in uint32_t filter_id)754*49ef7e06SGarrett D'Amore ef10_filter_delete_internal(
755*49ef7e06SGarrett D'Amore 	__in		efx_nic_t *enp,
756*49ef7e06SGarrett D'Amore 	__in		uint32_t filter_id)
757*49ef7e06SGarrett D'Amore {
758*49ef7e06SGarrett D'Amore 	efx_rc_t rc;
759*49ef7e06SGarrett D'Amore 	ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
760*49ef7e06SGarrett D'Amore 	efx_filter_spec_t *spec;
761*49ef7e06SGarrett D'Amore 	int state;
762*49ef7e06SGarrett D'Amore 	uint32_t filter_idx = filter_id % EFX_EF10_FILTER_TBL_ROWS;
763*49ef7e06SGarrett D'Amore 
764*49ef7e06SGarrett D'Amore 	/*
765*49ef7e06SGarrett D'Amore 	 * Find the software table entry and mark it busy.  Don't
766*49ef7e06SGarrett D'Amore 	 * remove it yet; any attempt to update while we're waiting
767*49ef7e06SGarrett D'Amore 	 * for the firmware must find the busy entry.
768*49ef7e06SGarrett D'Amore 	 *
769*49ef7e06SGarrett D'Amore 	 * FIXME: What if the busy flag is never cleared?
770*49ef7e06SGarrett D'Amore 	 */
771*49ef7e06SGarrett D'Amore 	EFSYS_LOCK(enp->en_eslp, state);
772*49ef7e06SGarrett D'Amore 	while (ef10_filter_entry_is_busy(table, filter_idx)) {
773*49ef7e06SGarrett D'Amore 		EFSYS_UNLOCK(enp->en_eslp, state);
774*49ef7e06SGarrett D'Amore 		EFSYS_SPIN(1);
775*49ef7e06SGarrett D'Amore 		EFSYS_LOCK(enp->en_eslp, state);
776*49ef7e06SGarrett D'Amore 	}
777*49ef7e06SGarrett D'Amore 	if ((spec = ef10_filter_entry_spec(table, filter_idx)) != NULL) {
778*49ef7e06SGarrett D'Amore 		ef10_filter_set_entry_busy(table, filter_idx);
779*49ef7e06SGarrett D'Amore 	}
780*49ef7e06SGarrett D'Amore 	EFSYS_UNLOCK(enp->en_eslp, state);
781*49ef7e06SGarrett D'Amore 
782*49ef7e06SGarrett D'Amore 	if (spec == NULL) {
783*49ef7e06SGarrett D'Amore 		rc = ENOENT;
784*49ef7e06SGarrett D'Amore 		goto fail1;
785*49ef7e06SGarrett D'Amore 	}
786*49ef7e06SGarrett D'Amore 
787*49ef7e06SGarrett D'Amore 	/*
788*49ef7e06SGarrett D'Amore 	 * Try to remove the hardware filter. This may fail if the MC has
789*49ef7e06SGarrett D'Amore 	 * rebooted (which frees all hardware filter resources).
790*49ef7e06SGarrett D'Amore 	 */
791*49ef7e06SGarrett D'Amore 	if (ef10_filter_is_exclusive(spec)) {
792*49ef7e06SGarrett D'Amore 		rc = efx_mcdi_filter_op_delete(enp,
793*49ef7e06SGarrett D'Amore 		    MC_CMD_FILTER_OP_IN_OP_REMOVE,
794*49ef7e06SGarrett D'Amore 		    &table->eft_entry[filter_idx].efe_handle);
795*49ef7e06SGarrett D'Amore 	} else {
796*49ef7e06SGarrett D'Amore 		rc = efx_mcdi_filter_op_delete(enp,
797*49ef7e06SGarrett D'Amore 		    MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE,
798*49ef7e06SGarrett D'Amore 		    &table->eft_entry[filter_idx].efe_handle);
799*49ef7e06SGarrett D'Amore 	}
800*49ef7e06SGarrett D'Amore 
801*49ef7e06SGarrett D'Amore 	/* Free the software table entry */
802*49ef7e06SGarrett D'Amore 	EFSYS_LOCK(enp->en_eslp, state);
803*49ef7e06SGarrett D'Amore 	ef10_filter_set_entry_not_busy(table, filter_idx);
804*49ef7e06SGarrett D'Amore 	ef10_filter_set_entry(table, filter_idx, NULL);
805*49ef7e06SGarrett D'Amore 	EFSYS_UNLOCK(enp->en_eslp, state);
806*49ef7e06SGarrett D'Amore 
807*49ef7e06SGarrett D'Amore 	EFSYS_KMEM_FREE(enp->en_esip, sizeof (*spec), spec);
808*49ef7e06SGarrett D'Amore 
809*49ef7e06SGarrett D'Amore 	/* Check result of hardware filter removal */
810*49ef7e06SGarrett D'Amore 	if (rc != 0)
811*49ef7e06SGarrett D'Amore 		goto fail2;
812*49ef7e06SGarrett D'Amore 
813*49ef7e06SGarrett D'Amore 	return (0);
814*49ef7e06SGarrett D'Amore 
815*49ef7e06SGarrett D'Amore fail2:
816*49ef7e06SGarrett D'Amore 	EFSYS_PROBE(fail2);
817*49ef7e06SGarrett D'Amore 
818*49ef7e06SGarrett D'Amore fail1:
819*49ef7e06SGarrett D'Amore 	EFSYS_PROBE1(fail1, efx_rc_t, rc);
820*49ef7e06SGarrett D'Amore 
821*49ef7e06SGarrett D'Amore 	return (rc);
822*49ef7e06SGarrett D'Amore }
823*49ef7e06SGarrett D'Amore 
824*49ef7e06SGarrett D'Amore 	__checkReturn	efx_rc_t
ef10_filter_delete(__in efx_nic_t * enp,__inout efx_filter_spec_t * spec)825*49ef7e06SGarrett D'Amore ef10_filter_delete(
826*49ef7e06SGarrett D'Amore 	__in		efx_nic_t *enp,
827*49ef7e06SGarrett D'Amore 	__inout		efx_filter_spec_t *spec)
828*49ef7e06SGarrett D'Amore {
829*49ef7e06SGarrett D'Amore 	efx_rc_t rc;
830*49ef7e06SGarrett D'Amore 	ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
831*49ef7e06SGarrett D'Amore 	efx_filter_spec_t *saved_spec;
832*49ef7e06SGarrett D'Amore 	unsigned int hash;
833*49ef7e06SGarrett D'Amore 	unsigned int depth;
834*49ef7e06SGarrett D'Amore 	unsigned int i;
835*49ef7e06SGarrett D'Amore 	int state;
836*49ef7e06SGarrett D'Amore 	boolean_t locked = B_FALSE;
837*49ef7e06SGarrett D'Amore 
838*49ef7e06SGarrett D'Amore 	EFSYS_ASSERT(enp->en_family == EFX_FAMILY_HUNTINGTON ||
839*49ef7e06SGarrett D'Amore 		    enp->en_family == EFX_FAMILY_MEDFORD);
840*49ef7e06SGarrett D'Amore 
841*49ef7e06SGarrett D'Amore 	hash = ef10_filter_hash(spec);
842*49ef7e06SGarrett D'Amore 
843*49ef7e06SGarrett D'Amore 	EFSYS_LOCK(enp->en_eslp, state);
844*49ef7e06SGarrett D'Amore 	locked = B_TRUE;
845*49ef7e06SGarrett D'Amore 
846*49ef7e06SGarrett D'Amore 	depth = 1;
847*49ef7e06SGarrett D'Amore 	for (;;) {
848*49ef7e06SGarrett D'Amore 		i = (hash + depth) & (EFX_EF10_FILTER_TBL_ROWS - 1);
849*49ef7e06SGarrett D'Amore 		saved_spec = ef10_filter_entry_spec(table, i);
850*49ef7e06SGarrett D'Amore 		if (saved_spec && ef10_filter_equal(spec, saved_spec) &&
851*49ef7e06SGarrett D'Amore 		    ef10_filter_same_dest(spec, saved_spec)) {
852*49ef7e06SGarrett D'Amore 			break;
853*49ef7e06SGarrett D'Amore 		}
854*49ef7e06SGarrett D'Amore 		if (depth == EF10_FILTER_SEARCH_LIMIT) {
855*49ef7e06SGarrett D'Amore 			rc = ENOENT;
856*49ef7e06SGarrett D'Amore 			goto fail1;
857*49ef7e06SGarrett D'Amore 		}
858*49ef7e06SGarrett D'Amore 		depth++;
859*49ef7e06SGarrett D'Amore 	}
860*49ef7e06SGarrett D'Amore 
861*49ef7e06SGarrett D'Amore 	EFSYS_UNLOCK(enp->en_eslp, state);
862*49ef7e06SGarrett D'Amore 	locked = B_FALSE;
863*49ef7e06SGarrett D'Amore 
864*49ef7e06SGarrett D'Amore 	rc = ef10_filter_delete_internal(enp, i);
865*49ef7e06SGarrett D'Amore 	if (rc != 0)
866*49ef7e06SGarrett D'Amore 		goto fail2;
867*49ef7e06SGarrett D'Amore 
868*49ef7e06SGarrett D'Amore 	return (0);
869*49ef7e06SGarrett D'Amore 
870*49ef7e06SGarrett D'Amore fail2:
871*49ef7e06SGarrett D'Amore 	EFSYS_PROBE(fail2);
872*49ef7e06SGarrett D'Amore 
873*49ef7e06SGarrett D'Amore fail1:
874*49ef7e06SGarrett D'Amore 	EFSYS_PROBE1(fail1, efx_rc_t, rc);
875*49ef7e06SGarrett D'Amore 
876*49ef7e06SGarrett D'Amore 	if (locked)
877*49ef7e06SGarrett D'Amore 		EFSYS_UNLOCK(enp->en_eslp, state);
878*49ef7e06SGarrett D'Amore 
879*49ef7e06SGarrett D'Amore 	return (rc);
880*49ef7e06SGarrett D'Amore }
881*49ef7e06SGarrett D'Amore 
882*49ef7e06SGarrett D'Amore static	__checkReturn	efx_rc_t
efx_mcdi_get_parser_disp_info(__in efx_nic_t * enp,__out uint32_t * list,__out size_t * length)883*49ef7e06SGarrett D'Amore efx_mcdi_get_parser_disp_info(
884*49ef7e06SGarrett D'Amore 	__in		efx_nic_t *enp,
885*49ef7e06SGarrett D'Amore 	__out		uint32_t *list,
886*49ef7e06SGarrett D'Amore 	__out		size_t *length)
887*49ef7e06SGarrett D'Amore {
888*49ef7e06SGarrett D'Amore 	efx_mcdi_req_t req;
889*49ef7e06SGarrett D'Amore 	uint8_t payload[MAX(MC_CMD_GET_PARSER_DISP_INFO_IN_LEN,
890*49ef7e06SGarrett D'Amore 			    MC_CMD_GET_PARSER_DISP_INFO_OUT_LENMAX)];
891*49ef7e06SGarrett D'Amore 	efx_rc_t rc;
892*49ef7e06SGarrett D'Amore 	uint32_t i;
893*49ef7e06SGarrett D'Amore 	boolean_t support_unknown_ucast = B_FALSE;
894*49ef7e06SGarrett D'Amore 	boolean_t support_unknown_mcast = B_FALSE;
895*49ef7e06SGarrett D'Amore 
896*49ef7e06SGarrett D'Amore 	(void) memset(payload, 0, sizeof (payload));
897*49ef7e06SGarrett D'Amore 	req.emr_cmd = MC_CMD_GET_PARSER_DISP_INFO;
898*49ef7e06SGarrett D'Amore 	req.emr_in_buf = payload;
899*49ef7e06SGarrett D'Amore 	req.emr_in_length = MC_CMD_GET_PARSER_DISP_INFO_IN_LEN;
900*49ef7e06SGarrett D'Amore 	req.emr_out_buf = payload;
901*49ef7e06SGarrett D'Amore 	req.emr_out_length = MC_CMD_GET_PARSER_DISP_INFO_OUT_LENMAX;
902*49ef7e06SGarrett D'Amore 
903*49ef7e06SGarrett D'Amore 	MCDI_IN_SET_DWORD(req, GET_PARSER_DISP_INFO_OUT_OP,
904*49ef7e06SGarrett D'Amore 	    MC_CMD_GET_PARSER_DISP_INFO_IN_OP_GET_SUPPORTED_RX_MATCHES);
905*49ef7e06SGarrett D'Amore 
906*49ef7e06SGarrett D'Amore 	efx_mcdi_execute(enp, &req);
907*49ef7e06SGarrett D'Amore 
908*49ef7e06SGarrett D'Amore 	if (req.emr_rc != 0) {
909*49ef7e06SGarrett D'Amore 		rc = req.emr_rc;
910*49ef7e06SGarrett D'Amore 		goto fail1;
911*49ef7e06SGarrett D'Amore 	}
912*49ef7e06SGarrett D'Amore 
913*49ef7e06SGarrett D'Amore 	*length = MCDI_OUT_DWORD(req,
914*49ef7e06SGarrett D'Amore 	    GET_PARSER_DISP_INFO_OUT_NUM_SUPPORTED_MATCHES);
915*49ef7e06SGarrett D'Amore 
916*49ef7e06SGarrett D'Amore 	if (req.emr_out_length_used <
917*49ef7e06SGarrett D'Amore 	    MC_CMD_GET_PARSER_DISP_INFO_OUT_LEN(*length)) {
918*49ef7e06SGarrett D'Amore 		rc = EMSGSIZE;
919*49ef7e06SGarrett D'Amore 		goto fail2;
920*49ef7e06SGarrett D'Amore 	}
921*49ef7e06SGarrett D'Amore 
922*49ef7e06SGarrett D'Amore 	(void) memcpy(list,
923*49ef7e06SGarrett D'Amore 	    MCDI_OUT2(req,
924*49ef7e06SGarrett D'Amore 	    void,
925*49ef7e06SGarrett D'Amore 	    GET_PARSER_DISP_INFO_OUT_SUPPORTED_MATCHES),
926*49ef7e06SGarrett D'Amore 	    (*length) * sizeof (uint32_t));
927*49ef7e06SGarrett D'Amore 	EFX_STATIC_ASSERT(sizeof (uint32_t) ==
928*49ef7e06SGarrett D'Amore 	    MC_CMD_GET_PARSER_DISP_INFO_OUT_SUPPORTED_MATCHES_LEN);
929*49ef7e06SGarrett D'Amore 
930*49ef7e06SGarrett D'Amore 	/*
931*49ef7e06SGarrett D'Amore 	 * Remove UNKNOWN UCAST and MCAST flags, and if both are present, change
932*49ef7e06SGarrett D'Amore 	 * the lower priority one to LOC_MAC_IG.
933*49ef7e06SGarrett D'Amore 	 */
934*49ef7e06SGarrett D'Amore 	for (i = 0; i < *length; i++) {
935*49ef7e06SGarrett D'Amore 		if (list[i] & MC_CMD_FILTER_OP_IN_MATCH_UNKNOWN_UCAST_DST_LBN) {
936*49ef7e06SGarrett D'Amore 			list[i] &=
937*49ef7e06SGarrett D'Amore 			(~MC_CMD_FILTER_OP_IN_MATCH_UNKNOWN_UCAST_DST_LBN);
938*49ef7e06SGarrett D'Amore 			support_unknown_ucast = B_TRUE;
939*49ef7e06SGarrett D'Amore 		}
940*49ef7e06SGarrett D'Amore 		if (list[i] & MC_CMD_FILTER_OP_IN_MATCH_UNKNOWN_MCAST_DST_LBN) {
941*49ef7e06SGarrett D'Amore 			list[i] &=
942*49ef7e06SGarrett D'Amore 			(~MC_CMD_FILTER_OP_IN_MATCH_UNKNOWN_MCAST_DST_LBN);
943*49ef7e06SGarrett D'Amore 			support_unknown_mcast = B_TRUE;
944*49ef7e06SGarrett D'Amore 		}
945*49ef7e06SGarrett D'Amore 
946*49ef7e06SGarrett D'Amore 		if (support_unknown_ucast && support_unknown_mcast) {
947*49ef7e06SGarrett D'Amore 			list[i] &= EFX_FILTER_MATCH_LOC_MAC_IG;
948*49ef7e06SGarrett D'Amore 			break;
949*49ef7e06SGarrett D'Amore 		}
950*49ef7e06SGarrett D'Amore 	}
951*49ef7e06SGarrett D'Amore 
952*49ef7e06SGarrett D'Amore 	return (0);
953*49ef7e06SGarrett D'Amore 
954*49ef7e06SGarrett D'Amore fail2:
955*49ef7e06SGarrett D'Amore 	EFSYS_PROBE(fail2);
956*49ef7e06SGarrett D'Amore fail1:
957*49ef7e06SGarrett D'Amore 	EFSYS_PROBE1(fail1, efx_rc_t, rc);
958*49ef7e06SGarrett D'Amore 
959*49ef7e06SGarrett D'Amore 	return (rc);
960*49ef7e06SGarrett D'Amore }
961*49ef7e06SGarrett D'Amore 
962*49ef7e06SGarrett D'Amore 	__checkReturn	efx_rc_t
ef10_filter_supported_filters(__in efx_nic_t * enp,__out uint32_t * list,__out size_t * length)963*49ef7e06SGarrett D'Amore ef10_filter_supported_filters(
964*49ef7e06SGarrett D'Amore 	__in		efx_nic_t *enp,
965*49ef7e06SGarrett D'Amore 	__out		uint32_t *list,
966*49ef7e06SGarrett D'Amore 	__out		size_t *length)
967*49ef7e06SGarrett D'Amore {
968*49ef7e06SGarrett D'Amore 	efx_rc_t rc;
969*49ef7e06SGarrett D'Amore 
970*49ef7e06SGarrett D'Amore 	if ((rc = efx_mcdi_get_parser_disp_info(enp, list, length)) != 0)
971*49ef7e06SGarrett D'Amore 		goto fail1;
972*49ef7e06SGarrett D'Amore 
973*49ef7e06SGarrett D'Amore 	return (0);
974*49ef7e06SGarrett D'Amore 
975*49ef7e06SGarrett D'Amore fail1:
976*49ef7e06SGarrett D'Amore 	EFSYS_PROBE1(fail1, efx_rc_t, rc);
977*49ef7e06SGarrett D'Amore 
978*49ef7e06SGarrett D'Amore 	return (rc);
979*49ef7e06SGarrett D'Amore }
980*49ef7e06SGarrett D'Amore 
981*49ef7e06SGarrett D'Amore static	__checkReturn	efx_rc_t
982*49ef7e06SGarrett D'Amore ef10_filter_insert_unicast(
983*49ef7e06SGarrett D'Amore 	__in				efx_nic_t *enp,
984*49ef7e06SGarrett D'Amore 	__in_ecount(6)			uint8_t const *addr,
985*49ef7e06SGarrett D'Amore 	__in				efx_filter_flag_t filter_flags)
986*49ef7e06SGarrett D'Amore {
987*49ef7e06SGarrett D'Amore 	ef10_filter_table_t *eftp = enp->en_filter.ef_ef10_filter_table;
988*49ef7e06SGarrett D'Amore 	efx_filter_spec_t spec;
989*49ef7e06SGarrett D'Amore 	efx_rc_t rc;
990*49ef7e06SGarrett D'Amore 
991*49ef7e06SGarrett D'Amore 	/* Insert the filter for the local station address */
992*49ef7e06SGarrett D'Amore 	efx_filter_spec_init_rx(&spec, EFX_FILTER_PRI_AUTO,
993*49ef7e06SGarrett D'Amore 	    filter_flags,
994*49ef7e06SGarrett D'Amore 	    eftp->eft_default_rxq);
995*49ef7e06SGarrett D'Amore 	(void) efx_filter_spec_set_eth_local(&spec, EFX_FILTER_SPEC_VID_UNSPEC,
996*49ef7e06SGarrett D'Amore 	    addr);
997*49ef7e06SGarrett D'Amore 
998*49ef7e06SGarrett D'Amore 	rc = ef10_filter_add_internal(enp, &spec, B_TRUE,
999*49ef7e06SGarrett D'Amore 	    &eftp->eft_unicst_filter_indexes[eftp->eft_unicst_filter_count]);
1000*49ef7e06SGarrett D'Amore 	if (rc != 0)
1001*49ef7e06SGarrett D'Amore 		goto fail1;
1002*49ef7e06SGarrett D'Amore 
1003*49ef7e06SGarrett D'Amore 	eftp->eft_unicst_filter_count++;
1004*49ef7e06SGarrett D'Amore 	EFSYS_ASSERT(eftp->eft_unicst_filter_count <=
1005*49ef7e06SGarrett D'Amore 		    EFX_EF10_FILTER_UNICAST_FILTERS_MAX);
1006*49ef7e06SGarrett D'Amore 
1007*49ef7e06SGarrett D'Amore 	return (0);
1008*49ef7e06SGarrett D'Amore 
1009*49ef7e06SGarrett D'Amore fail1:
1010*49ef7e06SGarrett D'Amore 	EFSYS_PROBE1(fail1, efx_rc_t, rc);
1011*49ef7e06SGarrett D'Amore 	return (rc);
1012*49ef7e06SGarrett D'Amore }
1013*49ef7e06SGarrett D'Amore 
1014*49ef7e06SGarrett D'Amore static	__checkReturn	efx_rc_t
ef10_filter_insert_all_unicast(__in efx_nic_t * enp,__in efx_filter_flag_t filter_flags)1015*49ef7e06SGarrett D'Amore ef10_filter_insert_all_unicast(
1016*49ef7e06SGarrett D'Amore 	__in				efx_nic_t *enp,
1017*49ef7e06SGarrett D'Amore 	__in				efx_filter_flag_t filter_flags)
1018*49ef7e06SGarrett D'Amore {
1019*49ef7e06SGarrett D'Amore 	ef10_filter_table_t *eftp = enp->en_filter.ef_ef10_filter_table;
1020*49ef7e06SGarrett D'Amore 	efx_filter_spec_t spec;
1021*49ef7e06SGarrett D'Amore 	efx_rc_t rc;
1022*49ef7e06SGarrett D'Amore 
1023*49ef7e06SGarrett D'Amore 	/* Insert the unknown unicast filter */
1024*49ef7e06SGarrett D'Amore 	efx_filter_spec_init_rx(&spec, EFX_FILTER_PRI_AUTO,
1025*49ef7e06SGarrett D'Amore 	    filter_flags,
1026*49ef7e06SGarrett D'Amore 	    eftp->eft_default_rxq);
1027*49ef7e06SGarrett D'Amore 	(void) efx_filter_spec_set_uc_def(&spec);
1028*49ef7e06SGarrett D'Amore 	rc = ef10_filter_add_internal(enp, &spec, B_TRUE,
1029*49ef7e06SGarrett D'Amore 	    &eftp->eft_unicst_filter_indexes[eftp->eft_unicst_filter_count]);
1030*49ef7e06SGarrett D'Amore 	if (rc != 0)
1031*49ef7e06SGarrett D'Amore 		goto fail1;
1032*49ef7e06SGarrett D'Amore 
1033*49ef7e06SGarrett D'Amore 	eftp->eft_unicst_filter_count++;
1034*49ef7e06SGarrett D'Amore 	EFSYS_ASSERT(eftp->eft_unicst_filter_count <=
1035*49ef7e06SGarrett D'Amore 		    EFX_EF10_FILTER_UNICAST_FILTERS_MAX);
1036*49ef7e06SGarrett D'Amore 
1037*49ef7e06SGarrett D'Amore 	return (0);
1038*49ef7e06SGarrett D'Amore 
1039*49ef7e06SGarrett D'Amore fail1:
1040*49ef7e06SGarrett D'Amore 	EFSYS_PROBE1(fail1, efx_rc_t, rc);
1041*49ef7e06SGarrett D'Amore 	return (rc);
1042*49ef7e06SGarrett D'Amore }
1043*49ef7e06SGarrett D'Amore 
1044*49ef7e06SGarrett D'Amore static	__checkReturn	efx_rc_t
1045*49ef7e06SGarrett D'Amore ef10_filter_insert_multicast_list(
1046*49ef7e06SGarrett D'Amore 	__in				efx_nic_t *enp,
1047*49ef7e06SGarrett D'Amore 	__in				boolean_t mulcst,
1048*49ef7e06SGarrett D'Amore 	__in				boolean_t brdcst,
1049*49ef7e06SGarrett D'Amore 	__in_ecount(6*count)		uint8_t const *addrs,
1050*49ef7e06SGarrett D'Amore 	__in				uint32_t count,
1051*49ef7e06SGarrett D'Amore 	__in				efx_filter_flag_t filter_flags,
1052*49ef7e06SGarrett D'Amore 	__in				boolean_t rollback)
1053*49ef7e06SGarrett D'Amore {
1054*49ef7e06SGarrett D'Amore 	ef10_filter_table_t *eftp = enp->en_filter.ef_ef10_filter_table;
1055*49ef7e06SGarrett D'Amore 	efx_filter_spec_t spec;
1056*49ef7e06SGarrett D'Amore 	uint8_t addr[6];
1057*49ef7e06SGarrett D'Amore 	uint32_t i;
1058*49ef7e06SGarrett D'Amore 	uint32_t filter_index;
1059*49ef7e06SGarrett D'Amore 	uint32_t filter_count;
1060*49ef7e06SGarrett D'Amore 	efx_rc_t rc;
1061*49ef7e06SGarrett D'Amore 
1062*49ef7e06SGarrett D'Amore 	if (mulcst == B_FALSE)
1063*49ef7e06SGarrett D'Amore 		count = 0;
1064*49ef7e06SGarrett D'Amore 
1065*49ef7e06SGarrett D'Amore 	if (count + (brdcst ? 1 : 0) >
1066*49ef7e06SGarrett D'Amore 	    EFX_ARRAY_SIZE(eftp->eft_mulcst_filter_indexes)) {
1067*49ef7e06SGarrett D'Amore 		/* Too many MAC addresses */
1068*49ef7e06SGarrett D'Amore 		rc = EINVAL;
1069*49ef7e06SGarrett D'Amore 		goto fail1;
1070*49ef7e06SGarrett D'Amore 	}
1071*49ef7e06SGarrett D'Amore 
1072*49ef7e06SGarrett D'Amore 	/* Insert/renew multicast address list filters */
1073*49ef7e06SGarrett D'Amore 	filter_count = 0;
1074*49ef7e06SGarrett D'Amore 	for (i = 0; i < count; i++) {
1075*49ef7e06SGarrett D'Amore 		efx_filter_spec_init_rx(&spec,
1076*49ef7e06SGarrett D'Amore 		    EFX_FILTER_PRI_AUTO,
1077*49ef7e06SGarrett D'Amore 		    filter_flags,
1078*49ef7e06SGarrett D'Amore 		    eftp->eft_default_rxq);
1079*49ef7e06SGarrett D'Amore 
1080*49ef7e06SGarrett D'Amore 		(void) efx_filter_spec_set_eth_local(&spec,
1081*49ef7e06SGarrett D'Amore 		    EFX_FILTER_SPEC_VID_UNSPEC,
1082*49ef7e06SGarrett D'Amore 		    &addrs[i * EFX_MAC_ADDR_LEN]);
1083*49ef7e06SGarrett D'Amore 
1084*49ef7e06SGarrett D'Amore 		rc = ef10_filter_add_internal(enp, &spec, B_TRUE,
1085*49ef7e06SGarrett D'Amore 					    &filter_index);
1086*49ef7e06SGarrett D'Amore 
1087*49ef7e06SGarrett D'Amore 		if (rc == 0) {
1088*49ef7e06SGarrett D'Amore 			eftp->eft_mulcst_filter_indexes[filter_count] =
1089*49ef7e06SGarrett D'Amore 				filter_index;
1090*49ef7e06SGarrett D'Amore 			filter_count++;
1091*49ef7e06SGarrett D'Amore 		} else if (rollback == B_TRUE) {
1092*49ef7e06SGarrett D'Amore 			/* Only stop upon failure if told to rollback */
1093*49ef7e06SGarrett D'Amore 			goto rollback;
1094*49ef7e06SGarrett D'Amore 		}
1095*49ef7e06SGarrett D'Amore 
1096*49ef7e06SGarrett D'Amore 	}
1097*49ef7e06SGarrett D'Amore 
1098*49ef7e06SGarrett D'Amore 	if (brdcst == B_TRUE) {
1099*49ef7e06SGarrett D'Amore 		/* Insert/renew broadcast address filter */
1100*49ef7e06SGarrett D'Amore 		efx_filter_spec_init_rx(&spec, EFX_FILTER_PRI_AUTO,
1101*49ef7e06SGarrett D'Amore 		    filter_flags,
1102*49ef7e06SGarrett D'Amore 		    eftp->eft_default_rxq);
1103*49ef7e06SGarrett D'Amore 
1104*49ef7e06SGarrett D'Amore 		EFX_MAC_BROADCAST_ADDR_SET(addr);
1105*49ef7e06SGarrett D'Amore 		(void) efx_filter_spec_set_eth_local(&spec,
1106*49ef7e06SGarrett D'Amore 		    EFX_FILTER_SPEC_VID_UNSPEC,
1107*49ef7e06SGarrett D'Amore 		    addr);
1108*49ef7e06SGarrett D'Amore 
1109*49ef7e06SGarrett D'Amore 		rc = ef10_filter_add_internal(enp, &spec, B_TRUE,
1110*49ef7e06SGarrett D'Amore 					    &filter_index);
1111*49ef7e06SGarrett D'Amore 
1112*49ef7e06SGarrett D'Amore 		if (rc == 0) {
1113*49ef7e06SGarrett D'Amore 			eftp->eft_mulcst_filter_indexes[filter_count] =
1114*49ef7e06SGarrett D'Amore 				filter_index;
1115*49ef7e06SGarrett D'Amore 			filter_count++;
1116*49ef7e06SGarrett D'Amore 		} else if (rollback == B_TRUE) {
1117*49ef7e06SGarrett D'Amore 			/* Only stop upon failure if told to rollback */
1118*49ef7e06SGarrett D'Amore 			goto rollback;
1119*49ef7e06SGarrett D'Amore 		}
1120*49ef7e06SGarrett D'Amore 	}
1121*49ef7e06SGarrett D'Amore 
1122*49ef7e06SGarrett D'Amore 	eftp->eft_mulcst_filter_count = filter_count;
1123*49ef7e06SGarrett D'Amore 	eftp->eft_using_all_mulcst = B_FALSE;
1124*49ef7e06SGarrett D'Amore 
1125*49ef7e06SGarrett D'Amore 	return (0);
1126*49ef7e06SGarrett D'Amore 
1127*49ef7e06SGarrett D'Amore rollback:
1128*49ef7e06SGarrett D'Amore 	/* Remove any filters we have inserted */
1129*49ef7e06SGarrett D'Amore 	i = filter_count;
1130*49ef7e06SGarrett D'Amore 	while (i--) {
1131*49ef7e06SGarrett D'Amore 		(void) ef10_filter_delete_internal(enp,
1132*49ef7e06SGarrett D'Amore 		    eftp->eft_mulcst_filter_indexes[i]);
1133*49ef7e06SGarrett D'Amore 	}
1134*49ef7e06SGarrett D'Amore 	eftp->eft_mulcst_filter_count = 0;
1135*49ef7e06SGarrett D'Amore 
1136*49ef7e06SGarrett D'Amore fail1:
1137*49ef7e06SGarrett D'Amore 	EFSYS_PROBE1(fail1, efx_rc_t, rc);
1138*49ef7e06SGarrett D'Amore 
1139*49ef7e06SGarrett D'Amore 	return (rc);
1140*49ef7e06SGarrett D'Amore }
1141*49ef7e06SGarrett D'Amore 
1142*49ef7e06SGarrett D'Amore static	__checkReturn	efx_rc_t
ef10_filter_insert_all_multicast(__in efx_nic_t * enp,__in efx_filter_flag_t filter_flags)1143*49ef7e06SGarrett D'Amore ef10_filter_insert_all_multicast(
1144*49ef7e06SGarrett D'Amore 	__in				efx_nic_t *enp,
1145*49ef7e06SGarrett D'Amore 	__in				efx_filter_flag_t filter_flags)
1146*49ef7e06SGarrett D'Amore {
1147*49ef7e06SGarrett D'Amore 	ef10_filter_table_t *eftp = enp->en_filter.ef_ef10_filter_table;
1148*49ef7e06SGarrett D'Amore 	efx_filter_spec_t spec;
1149*49ef7e06SGarrett D'Amore 	efx_rc_t rc;
1150*49ef7e06SGarrett D'Amore 
1151*49ef7e06SGarrett D'Amore 	/* Insert the unknown multicast filter */
1152*49ef7e06SGarrett D'Amore 	efx_filter_spec_init_rx(&spec, EFX_FILTER_PRI_AUTO,
1153*49ef7e06SGarrett D'Amore 	    filter_flags,
1154*49ef7e06SGarrett D'Amore 	    eftp->eft_default_rxq);
1155*49ef7e06SGarrett D'Amore 	(void) efx_filter_spec_set_mc_def(&spec);
1156*49ef7e06SGarrett D'Amore 
1157*49ef7e06SGarrett D'Amore 	rc = ef10_filter_add_internal(enp, &spec, B_TRUE,
1158*49ef7e06SGarrett D'Amore 	    &eftp->eft_mulcst_filter_indexes[0]);
1159*49ef7e06SGarrett D'Amore 	if (rc != 0)
1160*49ef7e06SGarrett D'Amore 		goto fail1;
1161*49ef7e06SGarrett D'Amore 
1162*49ef7e06SGarrett D'Amore 	eftp->eft_mulcst_filter_count = 1;
1163*49ef7e06SGarrett D'Amore 	eftp->eft_using_all_mulcst = B_TRUE;
1164*49ef7e06SGarrett D'Amore 
1165*49ef7e06SGarrett D'Amore 	/*
1166*49ef7e06SGarrett D'Amore 	 * FIXME: If brdcst == B_FALSE, add a filter to drop broadcast traffic.
1167*49ef7e06SGarrett D'Amore 	 */
1168*49ef7e06SGarrett D'Amore 
1169*49ef7e06SGarrett D'Amore 	return (0);
1170*49ef7e06SGarrett D'Amore 
1171*49ef7e06SGarrett D'Amore fail1:
1172*49ef7e06SGarrett D'Amore 	EFSYS_PROBE1(fail1, efx_rc_t, rc);
1173*49ef7e06SGarrett D'Amore 
1174*49ef7e06SGarrett D'Amore 	return (rc);
1175*49ef7e06SGarrett D'Amore }
1176*49ef7e06SGarrett D'Amore 
1177*49ef7e06SGarrett D'Amore static			void
ef10_filter_remove_old(__in efx_nic_t * enp)1178*49ef7e06SGarrett D'Amore ef10_filter_remove_old(
1179*49ef7e06SGarrett D'Amore 	__in		efx_nic_t *enp)
1180*49ef7e06SGarrett D'Amore {
1181*49ef7e06SGarrett D'Amore 	ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
1182*49ef7e06SGarrett D'Amore 	uint32_t i;
1183*49ef7e06SGarrett D'Amore 
1184*49ef7e06SGarrett D'Amore 	for (i = 0; i < EFX_ARRAY_SIZE(table->eft_entry); i++) {
1185*49ef7e06SGarrett D'Amore 		if (ef10_filter_entry_is_auto_old(table, i)) {
1186*49ef7e06SGarrett D'Amore 			(void) ef10_filter_delete_internal(enp, i);
1187*49ef7e06SGarrett D'Amore 		}
1188*49ef7e06SGarrett D'Amore 	}
1189*49ef7e06SGarrett D'Amore }
1190*49ef7e06SGarrett D'Amore 
1191*49ef7e06SGarrett D'Amore 
1192*49ef7e06SGarrett D'Amore static	__checkReturn	efx_rc_t
ef10_filter_get_workarounds(__in efx_nic_t * enp)1193*49ef7e06SGarrett D'Amore ef10_filter_get_workarounds(
1194*49ef7e06SGarrett D'Amore 	__in				efx_nic_t *enp)
1195*49ef7e06SGarrett D'Amore {
1196*49ef7e06SGarrett D'Amore 	efx_nic_cfg_t *encp = &enp->en_nic_cfg;
1197*49ef7e06SGarrett D'Amore 	uint32_t implemented = 0;
1198*49ef7e06SGarrett D'Amore 	uint32_t enabled = 0;
1199*49ef7e06SGarrett D'Amore 	efx_rc_t rc;
1200*49ef7e06SGarrett D'Amore 
1201*49ef7e06SGarrett D'Amore 	rc = efx_mcdi_get_workarounds(enp, &implemented, &enabled);
1202*49ef7e06SGarrett D'Amore 	if (rc == 0) {
1203*49ef7e06SGarrett D'Amore 		/* Check if chained multicast filter support is enabled */
1204*49ef7e06SGarrett D'Amore 		if (implemented & enabled & MC_CMD_GET_WORKAROUNDS_OUT_BUG26807)
1205*49ef7e06SGarrett D'Amore 			encp->enc_bug26807_workaround = B_TRUE;
1206*49ef7e06SGarrett D'Amore 		else
1207*49ef7e06SGarrett D'Amore 			encp->enc_bug26807_workaround = B_FALSE;
1208*49ef7e06SGarrett D'Amore 	} else if (rc == ENOTSUP) {
1209*49ef7e06SGarrett D'Amore 		/*
1210*49ef7e06SGarrett D'Amore 		 * Firmware is too old to support GET_WORKAROUNDS, and support
1211*49ef7e06SGarrett D'Amore 		 * for this workaround was implemented later.
1212*49ef7e06SGarrett D'Amore 		 */
1213*49ef7e06SGarrett D'Amore 		encp->enc_bug26807_workaround = B_FALSE;
1214*49ef7e06SGarrett D'Amore 	} else {
1215*49ef7e06SGarrett D'Amore 		goto fail1;
1216*49ef7e06SGarrett D'Amore 	}
1217*49ef7e06SGarrett D'Amore 
1218*49ef7e06SGarrett D'Amore 	return (0);
1219*49ef7e06SGarrett D'Amore 
1220*49ef7e06SGarrett D'Amore fail1:
1221*49ef7e06SGarrett D'Amore 	EFSYS_PROBE1(fail1, efx_rc_t, rc);
1222*49ef7e06SGarrett D'Amore 
1223*49ef7e06SGarrett D'Amore 	return (rc);
1224*49ef7e06SGarrett D'Amore 
1225*49ef7e06SGarrett D'Amore }
1226*49ef7e06SGarrett D'Amore 
1227*49ef7e06SGarrett D'Amore 
1228*49ef7e06SGarrett D'Amore /*
1229*49ef7e06SGarrett D'Amore  * Reconfigure all filters.
1230*49ef7e06SGarrett D'Amore  * If all_unicst and/or all mulcst filters cannot be applied then
1231*49ef7e06SGarrett D'Amore  * return ENOTSUP (Note the filters for the specified addresses are
1232*49ef7e06SGarrett D'Amore  * still applied in this case).
1233*49ef7e06SGarrett D'Amore  */
1234*49ef7e06SGarrett D'Amore 	__checkReturn	efx_rc_t
1235*49ef7e06SGarrett D'Amore ef10_filter_reconfigure(
1236*49ef7e06SGarrett D'Amore 	__in				efx_nic_t *enp,
1237*49ef7e06SGarrett D'Amore 	__in_ecount(6)			uint8_t const *mac_addr,
1238*49ef7e06SGarrett D'Amore 	__in				boolean_t all_unicst,
1239*49ef7e06SGarrett D'Amore 	__in				boolean_t mulcst,
1240*49ef7e06SGarrett D'Amore 	__in				boolean_t all_mulcst,
1241*49ef7e06SGarrett D'Amore 	__in				boolean_t brdcst,
1242*49ef7e06SGarrett D'Amore 	__in_ecount(6*count)		uint8_t const *addrs,
1243*49ef7e06SGarrett D'Amore 	__in				uint32_t count)
1244*49ef7e06SGarrett D'Amore {
1245*49ef7e06SGarrett D'Amore 	efx_nic_cfg_t *encp = &enp->en_nic_cfg;
1246*49ef7e06SGarrett D'Amore 	ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
1247*49ef7e06SGarrett D'Amore 	efx_filter_flag_t filter_flags;
1248*49ef7e06SGarrett D'Amore 	unsigned i;
1249*49ef7e06SGarrett D'Amore 	efx_rc_t all_unicst_rc = 0;
1250*49ef7e06SGarrett D'Amore 	efx_rc_t all_mulcst_rc = 0;
1251*49ef7e06SGarrett D'Amore 	efx_rc_t rc;
1252*49ef7e06SGarrett D'Amore 
1253*49ef7e06SGarrett D'Amore 	if (table->eft_default_rxq == NULL) {
1254*49ef7e06SGarrett D'Amore 		/*
1255*49ef7e06SGarrett D'Amore 		 * Filters direct traffic to the default RXQ, and so cannot be
1256*49ef7e06SGarrett D'Amore 		 * inserted until it is available. Any currently configured
1257*49ef7e06SGarrett D'Amore 		 * filters must be removed (ignore errors in case the MC
1258*49ef7e06SGarrett D'Amore 		 * has rebooted, which removes hardware filters).
1259*49ef7e06SGarrett D'Amore 		 */
1260*49ef7e06SGarrett D'Amore 		for (i = 0; i < table->eft_unicst_filter_count; i++) {
1261*49ef7e06SGarrett D'Amore 			(void) ef10_filter_delete_internal(enp,
1262*49ef7e06SGarrett D'Amore 					table->eft_unicst_filter_indexes[i]);
1263*49ef7e06SGarrett D'Amore 		}
1264*49ef7e06SGarrett D'Amore 		table->eft_unicst_filter_count = 0;
1265*49ef7e06SGarrett D'Amore 
1266*49ef7e06SGarrett D'Amore 		for (i = 0; i < table->eft_mulcst_filter_count; i++) {
1267*49ef7e06SGarrett D'Amore 			(void) ef10_filter_delete_internal(enp,
1268*49ef7e06SGarrett D'Amore 					table->eft_mulcst_filter_indexes[i]);
1269*49ef7e06SGarrett D'Amore 		}
1270*49ef7e06SGarrett D'Amore 		table->eft_mulcst_filter_count = 0;
1271*49ef7e06SGarrett D'Amore 
1272*49ef7e06SGarrett D'Amore 		return (0);
1273*49ef7e06SGarrett D'Amore 	}
1274*49ef7e06SGarrett D'Amore 
1275*49ef7e06SGarrett D'Amore 	if (table->eft_using_rss)
1276*49ef7e06SGarrett D'Amore 		filter_flags = EFX_FILTER_FLAG_RX_RSS;
1277*49ef7e06SGarrett D'Amore 	else
1278*49ef7e06SGarrett D'Amore 		filter_flags = 0;
1279*49ef7e06SGarrett D'Amore 
1280*49ef7e06SGarrett D'Amore 	/* Mark old filters which may need to be removed */
1281*49ef7e06SGarrett D'Amore 	for (i = 0; i < table->eft_unicst_filter_count; i++) {
1282*49ef7e06SGarrett D'Amore 		ef10_filter_set_entry_auto_old(table,
1283*49ef7e06SGarrett D'Amore 					table->eft_unicst_filter_indexes[i]);
1284*49ef7e06SGarrett D'Amore 	}
1285*49ef7e06SGarrett D'Amore 	for (i = 0; i < table->eft_mulcst_filter_count; i++) {
1286*49ef7e06SGarrett D'Amore 		ef10_filter_set_entry_auto_old(table,
1287*49ef7e06SGarrett D'Amore 					table->eft_mulcst_filter_indexes[i]);
1288*49ef7e06SGarrett D'Amore 	}
1289*49ef7e06SGarrett D'Amore 
1290*49ef7e06SGarrett D'Amore 	/*
1291*49ef7e06SGarrett D'Amore 	 * Insert or renew unicast filters.
1292*49ef7e06SGarrett D'Amore 	 *
1293*49ef7e06SGarrett D'Amore 	 * Frimware does not perform chaining on unicast filters. As traffic is
1294*49ef7e06SGarrett D'Amore 	 * therefore only delivered to the first matching filter, we should
1295*49ef7e06SGarrett D'Amore 	 * always insert the specific filter for our MAC address, to try and
1296*49ef7e06SGarrett D'Amore 	 * ensure we get that traffic.
1297*49ef7e06SGarrett D'Amore 	 *
1298*49ef7e06SGarrett D'Amore 	 * (If the filter for our MAC address has already been inserted by
1299*49ef7e06SGarrett D'Amore 	 * another function, we won't receive traffic sent to us, even if we
1300*49ef7e06SGarrett D'Amore 	 * insert a unicast mismatch filter. To prevent traffic stealing, this
1301*49ef7e06SGarrett D'Amore 	 * therefore relies on the privilege model only allowing functions to
1302*49ef7e06SGarrett D'Amore 	 * insert filters for their own MAC address unless explicitly given
1303*49ef7e06SGarrett D'Amore 	 * additional privileges by the user. This also means that, even on a
1304*49ef7e06SGarrett D'Amore 	 * priviliged function, inserting a unicast mismatch filter may not
1305*49ef7e06SGarrett D'Amore 	 * catch all traffic in multi PCI function scenarios.)
1306*49ef7e06SGarrett D'Amore 	 */
1307*49ef7e06SGarrett D'Amore 	table->eft_unicst_filter_count = 0;
1308*49ef7e06SGarrett D'Amore 	rc = ef10_filter_insert_unicast(enp, mac_addr, filter_flags);
1309*49ef7e06SGarrett D'Amore 	if (all_unicst || (rc != 0)) {
1310*49ef7e06SGarrett D'Amore 		all_unicst_rc = ef10_filter_insert_all_unicast(enp,
1311*49ef7e06SGarrett D'Amore 						    filter_flags);
1312*49ef7e06SGarrett D'Amore 		if ((rc != 0) && (all_unicst_rc != 0))
1313*49ef7e06SGarrett D'Amore 			goto fail1;
1314*49ef7e06SGarrett D'Amore 	}
1315*49ef7e06SGarrett D'Amore 
1316*49ef7e06SGarrett D'Amore 	/*
1317*49ef7e06SGarrett D'Amore 	 * WORKAROUND_BUG26807 controls firmware support for chained multicast
1318*49ef7e06SGarrett D'Amore 	 * filters, and can only be enabled or disabled when the hardware filter
1319*49ef7e06SGarrett D'Amore 	 * table is empty.
1320*49ef7e06SGarrett D'Amore 	 *
1321*49ef7e06SGarrett D'Amore 	 * Chained multicast filters require support from the datapath firmware,
1322*49ef7e06SGarrett D'Amore 	 * and may not be available (e.g. low-latency variants or old Huntington
1323*49ef7e06SGarrett D'Amore 	 * firmware).
1324*49ef7e06SGarrett D'Amore 	 *
1325*49ef7e06SGarrett D'Amore 	 * Firmware will reset (FLR) functions which have inserted filters in
1326*49ef7e06SGarrett D'Amore 	 * the hardware filter table when the workaround is enabled/disabled.
1327*49ef7e06SGarrett D'Amore 	 * Functions without any hardware filters are not reset.
1328*49ef7e06SGarrett D'Amore 	 *
1329*49ef7e06SGarrett D'Amore 	 * Re-check if the workaround is enabled after adding unicast hardware
1330*49ef7e06SGarrett D'Amore 	 * filters. This ensures that encp->enc_bug26807_workaround matches the
1331*49ef7e06SGarrett D'Amore 	 * firmware state, and that later changes to enable/disable the
1332*49ef7e06SGarrett D'Amore 	 * workaround will result in this function seeing a reset (FLR).
1333*49ef7e06SGarrett D'Amore 	 *
1334*49ef7e06SGarrett D'Amore 	 * In common-code drivers, we only support multiple PCI function
1335*49ef7e06SGarrett D'Amore 	 * scenarios with firmware that supports multicast chaining, so we can
1336*49ef7e06SGarrett D'Amore 	 * assume it is enabled for such cases and hence simplify the filter
1337*49ef7e06SGarrett D'Amore 	 * insertion logic. Firmware that does not support multicast chaining
1338*49ef7e06SGarrett D'Amore 	 * does not support multiple PCI function configurations either, so
1339*49ef7e06SGarrett D'Amore 	 * filter insertion is much simpler and the same strategies can still be
1340*49ef7e06SGarrett D'Amore 	 * used.
1341*49ef7e06SGarrett D'Amore 	 */
1342*49ef7e06SGarrett D'Amore 	if ((rc = ef10_filter_get_workarounds(enp)) != 0)
1343*49ef7e06SGarrett D'Amore 		goto fail2;
1344*49ef7e06SGarrett D'Amore 
1345*49ef7e06SGarrett D'Amore 	if ((table->eft_using_all_mulcst != all_mulcst) &&
1346*49ef7e06SGarrett D'Amore 	    (encp->enc_bug26807_workaround == B_TRUE)) {
1347*49ef7e06SGarrett D'Amore 		/*
1348*49ef7e06SGarrett D'Amore 		 * Multicast filter chaining is enabled, so traffic that matches
1349*49ef7e06SGarrett D'Amore 		 * more than one multicast filter will be replicated and
1350*49ef7e06SGarrett D'Amore 		 * delivered to multiple recipients.  To avoid this duplicate
1351*49ef7e06SGarrett D'Amore 		 * delivery, remove old multicast filters before inserting new
1352*49ef7e06SGarrett D'Amore 		 * multicast filters.
1353*49ef7e06SGarrett D'Amore 		 */
1354*49ef7e06SGarrett D'Amore 		ef10_filter_remove_old(enp);
1355*49ef7e06SGarrett D'Amore 	}
1356*49ef7e06SGarrett D'Amore 
1357*49ef7e06SGarrett D'Amore 	/* Insert or renew multicast filters */
1358*49ef7e06SGarrett D'Amore 	if (all_mulcst == B_TRUE) {
1359*49ef7e06SGarrett D'Amore 		/*
1360*49ef7e06SGarrett D'Amore 		 * Insert the all multicast filter. If that fails, try to insert
1361*49ef7e06SGarrett D'Amore 		 * all of our multicast filters (but without rollback on
1362*49ef7e06SGarrett D'Amore 		 * failure).
1363*49ef7e06SGarrett D'Amore 		 */
1364*49ef7e06SGarrett D'Amore 		all_mulcst_rc = ef10_filter_insert_all_multicast(enp,
1365*49ef7e06SGarrett D'Amore 							    filter_flags);
1366*49ef7e06SGarrett D'Amore 		if (all_mulcst_rc != 0) {
1367*49ef7e06SGarrett D'Amore 			rc = ef10_filter_insert_multicast_list(enp, B_TRUE,
1368*49ef7e06SGarrett D'Amore 			    brdcst, addrs, count, filter_flags, B_FALSE);
1369*49ef7e06SGarrett D'Amore 			if (rc != 0)
1370*49ef7e06SGarrett D'Amore 				goto fail3;
1371*49ef7e06SGarrett D'Amore 		}
1372*49ef7e06SGarrett D'Amore 	} else {
1373*49ef7e06SGarrett D'Amore 		/*
1374*49ef7e06SGarrett D'Amore 		 * Insert filters for multicast addresses.
1375*49ef7e06SGarrett D'Amore 		 * If any insertion fails, then rollback and try to insert the
1376*49ef7e06SGarrett D'Amore 		 * all multicast filter instead.
1377*49ef7e06SGarrett D'Amore 		 * If that also fails, try to insert all of the multicast
1378*49ef7e06SGarrett D'Amore 		 * filters (but without rollback on failure).
1379*49ef7e06SGarrett D'Amore 		 */
1380*49ef7e06SGarrett D'Amore 		rc = ef10_filter_insert_multicast_list(enp, mulcst, brdcst,
1381*49ef7e06SGarrett D'Amore 			    addrs, count, filter_flags, B_TRUE);
1382*49ef7e06SGarrett D'Amore 		if (rc != 0) {
1383*49ef7e06SGarrett D'Amore 			if ((table->eft_using_all_mulcst == B_FALSE) &&
1384*49ef7e06SGarrett D'Amore 			    (encp->enc_bug26807_workaround == B_TRUE)) {
1385*49ef7e06SGarrett D'Amore 				/*
1386*49ef7e06SGarrett D'Amore 				 * Multicast filter chaining is on, so remove
1387*49ef7e06SGarrett D'Amore 				 * old filters before inserting the multicast
1388*49ef7e06SGarrett D'Amore 				 * all filter to avoid duplicate delivery caused
1389*49ef7e06SGarrett D'Amore 				 * by packets matching multiple filters.
1390*49ef7e06SGarrett D'Amore 				 */
1391*49ef7e06SGarrett D'Amore 				ef10_filter_remove_old(enp);
1392*49ef7e06SGarrett D'Amore 			}
1393*49ef7e06SGarrett D'Amore 
1394*49ef7e06SGarrett D'Amore 			rc = ef10_filter_insert_all_multicast(enp,
1395*49ef7e06SGarrett D'Amore 							    filter_flags);
1396*49ef7e06SGarrett D'Amore 			if (rc != 0) {
1397*49ef7e06SGarrett D'Amore 				rc = ef10_filter_insert_multicast_list(enp,
1398*49ef7e06SGarrett D'Amore 				    mulcst, brdcst,
1399*49ef7e06SGarrett D'Amore 				    addrs, count, filter_flags, B_FALSE);
1400*49ef7e06SGarrett D'Amore 				if (rc != 0)
1401*49ef7e06SGarrett D'Amore 					goto fail4;
1402*49ef7e06SGarrett D'Amore 			}
1403*49ef7e06SGarrett D'Amore 		}
1404*49ef7e06SGarrett D'Amore 	}
1405*49ef7e06SGarrett D'Amore 
1406*49ef7e06SGarrett D'Amore 	/* Remove old filters which were not renewed */
1407*49ef7e06SGarrett D'Amore 	ef10_filter_remove_old(enp);
1408*49ef7e06SGarrett D'Amore 
1409*49ef7e06SGarrett D'Amore 	/* report if any optional flags were rejected */
1410*49ef7e06SGarrett D'Amore 	if (((all_unicst != B_FALSE) && (all_unicst_rc != 0)) ||
1411*49ef7e06SGarrett D'Amore 	    ((all_mulcst != B_FALSE) && (all_mulcst_rc != 0))) {
1412*49ef7e06SGarrett D'Amore 		rc = ENOTSUP;
1413*49ef7e06SGarrett D'Amore 	}
1414*49ef7e06SGarrett D'Amore 
1415*49ef7e06SGarrett D'Amore 	return (rc);
1416*49ef7e06SGarrett D'Amore 
1417*49ef7e06SGarrett D'Amore fail4:
1418*49ef7e06SGarrett D'Amore 	EFSYS_PROBE(fail4);
1419*49ef7e06SGarrett D'Amore fail3:
1420*49ef7e06SGarrett D'Amore 	EFSYS_PROBE(fail3);
1421*49ef7e06SGarrett D'Amore fail2:
1422*49ef7e06SGarrett D'Amore 	EFSYS_PROBE(fail2);
1423*49ef7e06SGarrett D'Amore fail1:
1424*49ef7e06SGarrett D'Amore 	EFSYS_PROBE1(fail1, efx_rc_t, rc);
1425*49ef7e06SGarrett D'Amore 
1426*49ef7e06SGarrett D'Amore 	/* Clear auto old flags */
1427*49ef7e06SGarrett D'Amore 	for (i = 0; i < EFX_ARRAY_SIZE(table->eft_entry); i++) {
1428*49ef7e06SGarrett D'Amore 		if (ef10_filter_entry_is_auto_old(table, i)) {
1429*49ef7e06SGarrett D'Amore 			ef10_filter_set_entry_not_auto_old(table, i);
1430*49ef7e06SGarrett D'Amore 		}
1431*49ef7e06SGarrett D'Amore 	}
1432*49ef7e06SGarrett D'Amore 
1433*49ef7e06SGarrett D'Amore 	return (rc);
1434*49ef7e06SGarrett D'Amore }
1435*49ef7e06SGarrett D'Amore 
1436*49ef7e06SGarrett D'Amore 		void
ef10_filter_get_default_rxq(__in efx_nic_t * enp,__out efx_rxq_t ** erpp,__out boolean_t * using_rss)1437*49ef7e06SGarrett D'Amore ef10_filter_get_default_rxq(
1438*49ef7e06SGarrett D'Amore 	__in		efx_nic_t *enp,
1439*49ef7e06SGarrett D'Amore 	__out		efx_rxq_t **erpp,
1440*49ef7e06SGarrett D'Amore 	__out		boolean_t *using_rss)
1441*49ef7e06SGarrett D'Amore {
1442*49ef7e06SGarrett D'Amore 	ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
1443*49ef7e06SGarrett D'Amore 
1444*49ef7e06SGarrett D'Amore 	*erpp = table->eft_default_rxq;
1445*49ef7e06SGarrett D'Amore 	*using_rss = table->eft_using_rss;
1446*49ef7e06SGarrett D'Amore }
1447*49ef7e06SGarrett D'Amore 
1448*49ef7e06SGarrett D'Amore 
1449*49ef7e06SGarrett D'Amore 		void
ef10_filter_default_rxq_set(__in efx_nic_t * enp,__in efx_rxq_t * erp,__in boolean_t using_rss)1450*49ef7e06SGarrett D'Amore ef10_filter_default_rxq_set(
1451*49ef7e06SGarrett D'Amore 	__in		efx_nic_t *enp,
1452*49ef7e06SGarrett D'Amore 	__in		efx_rxq_t *erp,
1453*49ef7e06SGarrett D'Amore 	__in		boolean_t using_rss)
1454*49ef7e06SGarrett D'Amore {
1455*49ef7e06SGarrett D'Amore 	ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
1456*49ef7e06SGarrett D'Amore 
1457*49ef7e06SGarrett D'Amore #if EFSYS_OPT_RX_SCALE
1458*49ef7e06SGarrett D'Amore 	EFSYS_ASSERT((using_rss == B_FALSE) ||
1459*49ef7e06SGarrett D'Amore 	    (enp->en_rss_context != EF10_RSS_CONTEXT_INVALID));
1460*49ef7e06SGarrett D'Amore 	table->eft_using_rss = using_rss;
1461*49ef7e06SGarrett D'Amore #else
1462*49ef7e06SGarrett D'Amore 	EFSYS_ASSERT(using_rss == B_FALSE);
1463*49ef7e06SGarrett D'Amore 	table->eft_using_rss = B_FALSE;
1464*49ef7e06SGarrett D'Amore #endif
1465*49ef7e06SGarrett D'Amore 	table->eft_default_rxq = erp;
1466*49ef7e06SGarrett D'Amore }
1467*49ef7e06SGarrett D'Amore 
1468*49ef7e06SGarrett D'Amore 		void
ef10_filter_default_rxq_clear(__in efx_nic_t * enp)1469*49ef7e06SGarrett D'Amore ef10_filter_default_rxq_clear(
1470*49ef7e06SGarrett D'Amore 	__in		efx_nic_t *enp)
1471*49ef7e06SGarrett D'Amore {
1472*49ef7e06SGarrett D'Amore 	ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
1473*49ef7e06SGarrett D'Amore 
1474*49ef7e06SGarrett D'Amore 	table->eft_default_rxq = NULL;
1475*49ef7e06SGarrett D'Amore 	table->eft_using_rss = B_FALSE;
1476*49ef7e06SGarrett D'Amore }
1477*49ef7e06SGarrett D'Amore 
1478*49ef7e06SGarrett D'Amore 
1479*49ef7e06SGarrett D'Amore #endif /* EFSYS_OPT_FILTER */
1480*49ef7e06SGarrett D'Amore 
1481*49ef7e06SGarrett D'Amore #endif /* EFSYS_OPT_HUNTINGTON || EFSYS_OPT_MEDFORD */
1482