net/sfc/base: refactor filter lookup loop in EF10
[dpdk.git] / drivers / net / sfc / base / ef10_filter.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  *
3  * Copyright (c) 2007-2018 Solarflare Communications Inc.
4  * All rights reserved.
5  */
6
7 #include "efx.h"
8 #include "efx_impl.h"
9
10 #if EFX_OPTS_EF10()
11
12 #if EFSYS_OPT_FILTER
13
14 #define EFE_SPEC(eftp, index)   ((eftp)->eft_entry[(index)].efe_spec)
15
16 static                  efx_filter_spec_t *
17 ef10_filter_entry_spec(
18         __in            const ef10_filter_table_t *eftp,
19         __in            unsigned int index)
20 {
21         return ((efx_filter_spec_t *)(EFE_SPEC(eftp, index) &
22                 ~(uintptr_t)EFX_EF10_FILTER_FLAGS));
23 }
24
25 static                  boolean_t
26 ef10_filter_entry_is_busy(
27         __in            const ef10_filter_table_t *eftp,
28         __in            unsigned int index)
29 {
30         if (EFE_SPEC(eftp, index) & EFX_EF10_FILTER_FLAG_BUSY)
31                 return (B_TRUE);
32         else
33                 return (B_FALSE);
34 }
35
36 static                  boolean_t
37 ef10_filter_entry_is_auto_old(
38         __in            const ef10_filter_table_t *eftp,
39         __in            unsigned int index)
40 {
41         if (EFE_SPEC(eftp, index) & EFX_EF10_FILTER_FLAG_AUTO_OLD)
42                 return (B_TRUE);
43         else
44                 return (B_FALSE);
45 }
46
47 static                  void
48 ef10_filter_set_entry(
49         __inout         ef10_filter_table_t *eftp,
50         __in            unsigned int index,
51         __in_opt        const efx_filter_spec_t *efsp)
52 {
53         EFE_SPEC(eftp, index) = (uintptr_t)efsp;
54 }
55
56 static                  void
57 ef10_filter_set_entry_busy(
58         __inout         ef10_filter_table_t *eftp,
59         __in            unsigned int index)
60 {
61         EFE_SPEC(eftp, index) |= (uintptr_t)EFX_EF10_FILTER_FLAG_BUSY;
62 }
63
64 static                  void
65 ef10_filter_set_entry_not_busy(
66         __inout         ef10_filter_table_t *eftp,
67         __in            unsigned int index)
68 {
69         EFE_SPEC(eftp, index) &= ~(uintptr_t)EFX_EF10_FILTER_FLAG_BUSY;
70 }
71
72 static                  void
73 ef10_filter_set_entry_auto_old(
74         __inout         ef10_filter_table_t *eftp,
75         __in            unsigned int index)
76 {
77         EFSYS_ASSERT(ef10_filter_entry_spec(eftp, index) != NULL);
78         EFE_SPEC(eftp, index) |= (uintptr_t)EFX_EF10_FILTER_FLAG_AUTO_OLD;
79 }
80
81 static                  void
82 ef10_filter_set_entry_not_auto_old(
83         __inout         ef10_filter_table_t *eftp,
84         __in            unsigned int index)
85 {
86         EFE_SPEC(eftp, index) &= ~(uintptr_t)EFX_EF10_FILTER_FLAG_AUTO_OLD;
87         EFSYS_ASSERT(ef10_filter_entry_spec(eftp, index) != NULL);
88 }
89
90         __checkReturn   efx_rc_t
91 ef10_filter_init(
92         __in            efx_nic_t *enp)
93 {
94         efx_rc_t rc;
95         ef10_filter_table_t *eftp;
96
97         EFSYS_ASSERT(EFX_FAMILY_IS_EF10(enp));
98
99 #define MATCH_MASK(match) (EFX_MASK32(match) << EFX_LOW_BIT(match))
100         EFX_STATIC_ASSERT(EFX_FILTER_MATCH_REM_HOST ==
101             MATCH_MASK(MC_CMD_FILTER_OP_EXT_IN_MATCH_SRC_IP));
102         EFX_STATIC_ASSERT(EFX_FILTER_MATCH_LOC_HOST ==
103             MATCH_MASK(MC_CMD_FILTER_OP_EXT_IN_MATCH_DST_IP));
104         EFX_STATIC_ASSERT(EFX_FILTER_MATCH_REM_MAC ==
105             MATCH_MASK(MC_CMD_FILTER_OP_EXT_IN_MATCH_SRC_MAC));
106         EFX_STATIC_ASSERT(EFX_FILTER_MATCH_REM_PORT ==
107             MATCH_MASK(MC_CMD_FILTER_OP_EXT_IN_MATCH_SRC_PORT));
108         EFX_STATIC_ASSERT(EFX_FILTER_MATCH_LOC_MAC ==
109             MATCH_MASK(MC_CMD_FILTER_OP_EXT_IN_MATCH_DST_MAC));
110         EFX_STATIC_ASSERT(EFX_FILTER_MATCH_LOC_PORT ==
111             MATCH_MASK(MC_CMD_FILTER_OP_EXT_IN_MATCH_DST_PORT));
112         EFX_STATIC_ASSERT(EFX_FILTER_MATCH_ETHER_TYPE ==
113             MATCH_MASK(MC_CMD_FILTER_OP_EXT_IN_MATCH_ETHER_TYPE));
114         EFX_STATIC_ASSERT(EFX_FILTER_MATCH_INNER_VID ==
115             MATCH_MASK(MC_CMD_FILTER_OP_EXT_IN_MATCH_INNER_VLAN));
116         EFX_STATIC_ASSERT(EFX_FILTER_MATCH_OUTER_VID ==
117             MATCH_MASK(MC_CMD_FILTER_OP_EXT_IN_MATCH_OUTER_VLAN));
118         EFX_STATIC_ASSERT(EFX_FILTER_MATCH_IP_PROTO ==
119             MATCH_MASK(MC_CMD_FILTER_OP_EXT_IN_MATCH_IP_PROTO));
120         EFX_STATIC_ASSERT(EFX_FILTER_MATCH_VNI_OR_VSID ==
121             MATCH_MASK(MC_CMD_FILTER_OP_EXT_IN_MATCH_VNI_OR_VSID));
122         EFX_STATIC_ASSERT(EFX_FILTER_MATCH_IFRM_LOC_MAC ==
123             MATCH_MASK(MC_CMD_FILTER_OP_EXT_IN_MATCH_IFRM_DST_MAC));
124         EFX_STATIC_ASSERT(EFX_FILTER_MATCH_IFRM_UNKNOWN_MCAST_DST ==
125             MATCH_MASK(MC_CMD_FILTER_OP_EXT_IN_MATCH_IFRM_UNKNOWN_MCAST_DST));
126         EFX_STATIC_ASSERT(EFX_FILTER_MATCH_IFRM_UNKNOWN_UCAST_DST ==
127             MATCH_MASK(MC_CMD_FILTER_OP_EXT_IN_MATCH_IFRM_UNKNOWN_UCAST_DST));
128         EFX_STATIC_ASSERT(EFX_FILTER_MATCH_UNKNOWN_MCAST_DST ==
129             MATCH_MASK(MC_CMD_FILTER_OP_EXT_IN_MATCH_UNKNOWN_MCAST_DST));
130         EFX_STATIC_ASSERT((uint32_t)EFX_FILTER_MATCH_UNKNOWN_UCAST_DST ==
131             MATCH_MASK(MC_CMD_FILTER_OP_EXT_IN_MATCH_UNKNOWN_UCAST_DST));
132 #undef MATCH_MASK
133
134         EFSYS_KMEM_ALLOC(enp->en_esip, sizeof (ef10_filter_table_t), eftp);
135
136         if (!eftp) {
137                 rc = ENOMEM;
138                 goto fail1;
139         }
140
141         enp->en_filter.ef_ef10_filter_table = eftp;
142
143         return (0);
144
145 fail1:
146         EFSYS_PROBE1(fail1, efx_rc_t, rc);
147
148         return (rc);
149 }
150
151                         void
152 ef10_filter_fini(
153         __in            efx_nic_t *enp)
154 {
155         EFSYS_ASSERT(EFX_FAMILY_IS_EF10(enp));
156
157         if (enp->en_filter.ef_ef10_filter_table != NULL) {
158                 EFSYS_KMEM_FREE(enp->en_esip, sizeof (ef10_filter_table_t),
159                     enp->en_filter.ef_ef10_filter_table);
160         }
161 }
162
163 static  __checkReturn   efx_rc_t
164 efx_mcdi_filter_op_add(
165         __in            efx_nic_t *enp,
166         __in            efx_filter_spec_t *spec,
167         __in            unsigned int filter_op,
168         __inout         ef10_filter_handle_t *handle)
169 {
170         efx_mcdi_req_t req;
171         EFX_MCDI_DECLARE_BUF(payload, MC_CMD_FILTER_OP_V3_IN_LEN,
172                 MC_CMD_FILTER_OP_EXT_OUT_LEN);
173         efx_filter_match_flags_t match_flags;
174         efx_rc_t rc;
175
176         req.emr_cmd = MC_CMD_FILTER_OP;
177         req.emr_in_buf = payload;
178         req.emr_in_length = MC_CMD_FILTER_OP_V3_IN_LEN;
179         req.emr_out_buf = payload;
180         req.emr_out_length = MC_CMD_FILTER_OP_EXT_OUT_LEN;
181
182         /*
183          * Remove match flag for encapsulated filters that does not correspond
184          * to the MCDI match flags
185          */
186         match_flags = spec->efs_match_flags & ~EFX_FILTER_MATCH_ENCAP_TYPE;
187
188         switch (filter_op) {
189         case MC_CMD_FILTER_OP_IN_OP_REPLACE:
190                 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_HANDLE_LO,
191                     handle->efh_lo);
192                 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_HANDLE_HI,
193                     handle->efh_hi);
194                 /* Fall through */
195         case MC_CMD_FILTER_OP_IN_OP_INSERT:
196         case MC_CMD_FILTER_OP_IN_OP_SUBSCRIBE:
197                 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_OP, filter_op);
198                 break;
199         default:
200                 EFSYS_ASSERT(0);
201                 rc = EINVAL;
202                 goto fail1;
203         }
204
205         MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_PORT_ID, enp->en_vport_id);
206         MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_MATCH_FIELDS,
207             match_flags);
208         if (spec->efs_dmaq_id == EFX_FILTER_SPEC_RX_DMAQ_ID_DROP) {
209                 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_RX_DEST,
210                     MC_CMD_FILTER_OP_EXT_IN_RX_DEST_DROP);
211         } else {
212                 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_RX_DEST,
213                     MC_CMD_FILTER_OP_EXT_IN_RX_DEST_HOST);
214                 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_RX_QUEUE,
215                     spec->efs_dmaq_id);
216         }
217
218 #if EFSYS_OPT_RX_SCALE
219         if (spec->efs_flags & EFX_FILTER_FLAG_RX_RSS) {
220                 uint32_t rss_context;
221
222                 if (spec->efs_rss_context == EFX_RSS_CONTEXT_DEFAULT)
223                         rss_context = enp->en_rss_context;
224                 else
225                         rss_context = spec->efs_rss_context;
226                 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_RX_CONTEXT,
227                     rss_context);
228         }
229 #endif
230
231         MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_RX_MODE,
232             spec->efs_flags & EFX_FILTER_FLAG_RX_RSS ?
233             MC_CMD_FILTER_OP_EXT_IN_RX_MODE_RSS :
234             MC_CMD_FILTER_OP_EXT_IN_RX_MODE_SIMPLE);
235         MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_TX_DEST,
236             MC_CMD_FILTER_OP_EXT_IN_TX_DEST_DEFAULT);
237
238         if (filter_op != MC_CMD_FILTER_OP_IN_OP_REPLACE) {
239                 /*
240                  * NOTE: Unlike most MCDI requests, the filter fields
241                  * are presented in network (big endian) byte order.
242                  */
243                 memcpy(MCDI_IN2(req, uint8_t, FILTER_OP_EXT_IN_SRC_MAC),
244                     spec->efs_rem_mac, EFX_MAC_ADDR_LEN);
245                 memcpy(MCDI_IN2(req, uint8_t, FILTER_OP_EXT_IN_DST_MAC),
246                     spec->efs_loc_mac, EFX_MAC_ADDR_LEN);
247
248                 MCDI_IN_SET_WORD(req, FILTER_OP_EXT_IN_SRC_PORT,
249                     __CPU_TO_BE_16(spec->efs_rem_port));
250                 MCDI_IN_SET_WORD(req, FILTER_OP_EXT_IN_DST_PORT,
251                     __CPU_TO_BE_16(spec->efs_loc_port));
252
253                 MCDI_IN_SET_WORD(req, FILTER_OP_EXT_IN_ETHER_TYPE,
254                     __CPU_TO_BE_16(spec->efs_ether_type));
255
256                 MCDI_IN_SET_WORD(req, FILTER_OP_EXT_IN_INNER_VLAN,
257                     __CPU_TO_BE_16(spec->efs_inner_vid));
258                 MCDI_IN_SET_WORD(req, FILTER_OP_EXT_IN_OUTER_VLAN,
259                     __CPU_TO_BE_16(spec->efs_outer_vid));
260
261                 /* IP protocol (in low byte, high byte is zero) */
262                 MCDI_IN_SET_BYTE(req, FILTER_OP_EXT_IN_IP_PROTO,
263                     spec->efs_ip_proto);
264
265                 EFX_STATIC_ASSERT(sizeof (spec->efs_rem_host) ==
266                     MC_CMD_FILTER_OP_EXT_IN_SRC_IP_LEN);
267                 EFX_STATIC_ASSERT(sizeof (spec->efs_loc_host) ==
268                     MC_CMD_FILTER_OP_EXT_IN_DST_IP_LEN);
269
270                 memcpy(MCDI_IN2(req, uint8_t, FILTER_OP_EXT_IN_SRC_IP),
271                     &spec->efs_rem_host.eo_byte[0],
272                     MC_CMD_FILTER_OP_EXT_IN_SRC_IP_LEN);
273                 memcpy(MCDI_IN2(req, uint8_t, FILTER_OP_EXT_IN_DST_IP),
274                     &spec->efs_loc_host.eo_byte[0],
275                     MC_CMD_FILTER_OP_EXT_IN_DST_IP_LEN);
276
277                 /*
278                  * On Medford, filters for encapsulated packets match based on
279                  * the ether type and IP protocol in the outer frame.  In
280                  * addition we need to fill in the VNI or VSID type field.
281                  */
282                 switch (spec->efs_encap_type) {
283                 case EFX_TUNNEL_PROTOCOL_NONE:
284                         break;
285                 case EFX_TUNNEL_PROTOCOL_VXLAN:
286                 case EFX_TUNNEL_PROTOCOL_GENEVE:
287                         MCDI_IN_POPULATE_DWORD_1(req,
288                             FILTER_OP_EXT_IN_VNI_OR_VSID,
289                             FILTER_OP_EXT_IN_VNI_TYPE,
290                             spec->efs_encap_type == EFX_TUNNEL_PROTOCOL_VXLAN ?
291                                     MC_CMD_FILTER_OP_EXT_IN_VNI_TYPE_VXLAN :
292                                     MC_CMD_FILTER_OP_EXT_IN_VNI_TYPE_GENEVE);
293                         break;
294                 case EFX_TUNNEL_PROTOCOL_NVGRE:
295                         MCDI_IN_POPULATE_DWORD_1(req,
296                             FILTER_OP_EXT_IN_VNI_OR_VSID,
297                             FILTER_OP_EXT_IN_VSID_TYPE,
298                             MC_CMD_FILTER_OP_EXT_IN_VSID_TYPE_NVGRE);
299                         break;
300                 default:
301                         EFSYS_ASSERT(0);
302                         rc = EINVAL;
303                         goto fail2;
304                 }
305
306                 memcpy(MCDI_IN2(req, uint8_t, FILTER_OP_EXT_IN_VNI_OR_VSID),
307                     spec->efs_vni_or_vsid, EFX_VNI_OR_VSID_LEN);
308
309                 memcpy(MCDI_IN2(req, uint8_t, FILTER_OP_EXT_IN_IFRM_DST_MAC),
310                     spec->efs_ifrm_loc_mac, EFX_MAC_ADDR_LEN);
311         }
312
313         /*
314          * Set the "MARK" or "FLAG" action for all packets matching this filter
315          * if necessary (only useful with equal stride packed stream Rx mode
316          * which provide the information in pseudo-header).
317          * These actions require MC_CMD_FILTER_OP_V3_IN msgrequest.
318          */
319         if ((spec->efs_flags & EFX_FILTER_FLAG_ACTION_MARK) &&
320             (spec->efs_flags & EFX_FILTER_FLAG_ACTION_FLAG)) {
321                 rc = EINVAL;
322                 goto fail3;
323         }
324         if (spec->efs_flags & EFX_FILTER_FLAG_ACTION_MARK) {
325                 MCDI_IN_SET_DWORD(req, FILTER_OP_V3_IN_MATCH_ACTION,
326                     MC_CMD_FILTER_OP_V3_IN_MATCH_ACTION_MARK);
327                 MCDI_IN_SET_DWORD(req, FILTER_OP_V3_IN_MATCH_MARK_VALUE,
328                     spec->efs_mark);
329         } else if (spec->efs_flags & EFX_FILTER_FLAG_ACTION_FLAG) {
330                 MCDI_IN_SET_DWORD(req, FILTER_OP_V3_IN_MATCH_ACTION,
331                     MC_CMD_FILTER_OP_V3_IN_MATCH_ACTION_FLAG);
332         }
333
334         efx_mcdi_execute(enp, &req);
335
336         if (req.emr_rc != 0) {
337                 rc = req.emr_rc;
338                 goto fail4;
339         }
340
341         if (req.emr_out_length_used < MC_CMD_FILTER_OP_EXT_OUT_LEN) {
342                 rc = EMSGSIZE;
343                 goto fail5;
344         }
345
346         handle->efh_lo = MCDI_OUT_DWORD(req, FILTER_OP_EXT_OUT_HANDLE_LO);
347         handle->efh_hi = MCDI_OUT_DWORD(req, FILTER_OP_EXT_OUT_HANDLE_HI);
348
349         return (0);
350
351 fail5:
352         EFSYS_PROBE(fail5);
353 fail4:
354         EFSYS_PROBE(fail4);
355 fail3:
356         EFSYS_PROBE(fail3);
357 fail2:
358         EFSYS_PROBE(fail2);
359 fail1:
360         EFSYS_PROBE1(fail1, efx_rc_t, rc);
361
362         return (rc);
363
364 }
365
366 static  __checkReturn   efx_rc_t
367 efx_mcdi_filter_op_delete(
368         __in            efx_nic_t *enp,
369         __in            unsigned int filter_op,
370         __inout         ef10_filter_handle_t *handle)
371 {
372         efx_mcdi_req_t req;
373         EFX_MCDI_DECLARE_BUF(payload, MC_CMD_FILTER_OP_EXT_IN_LEN,
374                 MC_CMD_FILTER_OP_EXT_OUT_LEN);
375         efx_rc_t rc;
376
377         req.emr_cmd = MC_CMD_FILTER_OP;
378         req.emr_in_buf = payload;
379         req.emr_in_length = MC_CMD_FILTER_OP_EXT_IN_LEN;
380         req.emr_out_buf = payload;
381         req.emr_out_length = MC_CMD_FILTER_OP_EXT_OUT_LEN;
382
383         switch (filter_op) {
384         case MC_CMD_FILTER_OP_IN_OP_REMOVE:
385                 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_OP,
386                     MC_CMD_FILTER_OP_IN_OP_REMOVE);
387                 break;
388         case MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE:
389                 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_OP,
390                     MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE);
391                 break;
392         default:
393                 EFSYS_ASSERT(0);
394                 rc = EINVAL;
395                 goto fail1;
396         }
397
398         MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_HANDLE_LO, handle->efh_lo);
399         MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_HANDLE_HI, handle->efh_hi);
400
401         efx_mcdi_execute_quiet(enp, &req);
402
403         if (req.emr_rc != 0) {
404                 rc = req.emr_rc;
405                 goto fail2;
406         }
407
408         if (req.emr_out_length_used < MC_CMD_FILTER_OP_EXT_OUT_LEN) {
409                 rc = EMSGSIZE;
410                 goto fail3;
411         }
412
413         return (0);
414
415 fail3:
416         EFSYS_PROBE(fail3);
417
418 fail2:
419         EFSYS_PROBE(fail2);
420 fail1:
421         EFSYS_PROBE1(fail1, efx_rc_t, rc);
422
423         return (rc);
424 }
425
426 static  __checkReturn   boolean_t
427 ef10_filter_equal(
428         __in            const efx_filter_spec_t *left,
429         __in            const efx_filter_spec_t *right)
430 {
431         /* FIXME: Consider rx vs tx filters (look at efs_flags) */
432         if (left->efs_match_flags != right->efs_match_flags)
433                 return (B_FALSE);
434         if (!EFX_OWORD_IS_EQUAL(left->efs_rem_host, right->efs_rem_host))
435                 return (B_FALSE);
436         if (!EFX_OWORD_IS_EQUAL(left->efs_loc_host, right->efs_loc_host))
437                 return (B_FALSE);
438         if (memcmp(left->efs_rem_mac, right->efs_rem_mac, EFX_MAC_ADDR_LEN))
439                 return (B_FALSE);
440         if (memcmp(left->efs_loc_mac, right->efs_loc_mac, EFX_MAC_ADDR_LEN))
441                 return (B_FALSE);
442         if (left->efs_rem_port != right->efs_rem_port)
443                 return (B_FALSE);
444         if (left->efs_loc_port != right->efs_loc_port)
445                 return (B_FALSE);
446         if (left->efs_inner_vid != right->efs_inner_vid)
447                 return (B_FALSE);
448         if (left->efs_outer_vid != right->efs_outer_vid)
449                 return (B_FALSE);
450         if (left->efs_ether_type != right->efs_ether_type)
451                 return (B_FALSE);
452         if (left->efs_ip_proto != right->efs_ip_proto)
453                 return (B_FALSE);
454         if (left->efs_encap_type != right->efs_encap_type)
455                 return (B_FALSE);
456         if (memcmp(left->efs_vni_or_vsid, right->efs_vni_or_vsid,
457             EFX_VNI_OR_VSID_LEN))
458                 return (B_FALSE);
459         if (memcmp(left->efs_ifrm_loc_mac, right->efs_ifrm_loc_mac,
460             EFX_MAC_ADDR_LEN))
461                 return (B_FALSE);
462
463         return (B_TRUE);
464
465 }
466
467 static  __checkReturn   boolean_t
468 ef10_filter_same_dest(
469         __in            const efx_filter_spec_t *left,
470         __in            const efx_filter_spec_t *right)
471 {
472         if ((left->efs_flags & EFX_FILTER_FLAG_RX_RSS) &&
473             (right->efs_flags & EFX_FILTER_FLAG_RX_RSS)) {
474                 if (left->efs_rss_context == right->efs_rss_context)
475                         return (B_TRUE);
476         } else if ((~(left->efs_flags) & EFX_FILTER_FLAG_RX_RSS) &&
477             (~(right->efs_flags) & EFX_FILTER_FLAG_RX_RSS)) {
478                 if (left->efs_dmaq_id == right->efs_dmaq_id)
479                         return (B_TRUE);
480         }
481         return (B_FALSE);
482 }
483
484 static  __checkReturn   uint32_t
485 ef10_filter_hash(
486         __in            efx_filter_spec_t *spec)
487 {
488         EFX_STATIC_ASSERT((sizeof (efx_filter_spec_t) % sizeof (uint32_t))
489                             == 0);
490         EFX_STATIC_ASSERT((EFX_FIELD_OFFSET(efx_filter_spec_t, efs_outer_vid) %
491                             sizeof (uint32_t)) == 0);
492
493         /*
494          * As the area of the efx_filter_spec_t we need to hash is DWORD
495          * aligned and an exact number of DWORDs in size we can use the
496          * optimised efx_hash_dwords() rather than efx_hash_bytes()
497          */
498         return (efx_hash_dwords((const uint32_t *)&spec->efs_outer_vid,
499                         (sizeof (efx_filter_spec_t) -
500                         EFX_FIELD_OFFSET(efx_filter_spec_t, efs_outer_vid)) /
501                         sizeof (uint32_t), 0));
502 }
503
504 /*
505  * Decide whether a filter should be exclusive or else should allow
506  * delivery to additional recipients.  Currently we decide that
507  * filters for specific local unicast MAC and IP addresses are
508  * exclusive.
509  */
510 static  __checkReturn   boolean_t
511 ef10_filter_is_exclusive(
512         __in            efx_filter_spec_t *spec)
513 {
514         if ((spec->efs_match_flags & EFX_FILTER_MATCH_LOC_MAC) &&
515             !EFX_MAC_ADDR_IS_MULTICAST(spec->efs_loc_mac))
516                 return (B_TRUE);
517
518         if ((spec->efs_match_flags &
519                 (EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_LOC_HOST)) ==
520             (EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_LOC_HOST)) {
521                 if ((spec->efs_ether_type == EFX_ETHER_TYPE_IPV4) &&
522                     ((spec->efs_loc_host.eo_u8[0] & 0xf) != 0xe))
523                         return (B_TRUE);
524                 if ((spec->efs_ether_type == EFX_ETHER_TYPE_IPV6) &&
525                     (spec->efs_loc_host.eo_u8[0] != 0xff))
526                         return (B_TRUE);
527         }
528
529         return (B_FALSE);
530 }
531
532         __checkReturn   efx_rc_t
533 ef10_filter_restore(
534         __in            efx_nic_t *enp)
535 {
536         int tbl_id;
537         efx_filter_spec_t *spec;
538         ef10_filter_table_t *eftp = enp->en_filter.ef_ef10_filter_table;
539         boolean_t restoring;
540         efsys_lock_state_t state;
541         efx_rc_t rc;
542
543         EFSYS_ASSERT(EFX_FAMILY_IS_EF10(enp));
544
545         for (tbl_id = 0; tbl_id < EFX_EF10_FILTER_TBL_ROWS; tbl_id++) {
546
547                 EFSYS_LOCK(enp->en_eslp, state);
548
549                 spec = ef10_filter_entry_spec(eftp, tbl_id);
550                 if (spec == NULL) {
551                         restoring = B_FALSE;
552                 } else if (ef10_filter_entry_is_busy(eftp, tbl_id)) {
553                         /* Ignore busy entries. */
554                         restoring = B_FALSE;
555                 } else {
556                         ef10_filter_set_entry_busy(eftp, tbl_id);
557                         restoring = B_TRUE;
558                 }
559
560                 EFSYS_UNLOCK(enp->en_eslp, state);
561
562                 if (restoring == B_FALSE)
563                         continue;
564
565                 if (ef10_filter_is_exclusive(spec)) {
566                         rc = efx_mcdi_filter_op_add(enp, spec,
567                             MC_CMD_FILTER_OP_IN_OP_INSERT,
568                             &eftp->eft_entry[tbl_id].efe_handle);
569                 } else {
570                         rc = efx_mcdi_filter_op_add(enp, spec,
571                             MC_CMD_FILTER_OP_IN_OP_SUBSCRIBE,
572                             &eftp->eft_entry[tbl_id].efe_handle);
573                 }
574
575                 if (rc != 0)
576                         goto fail1;
577
578                 EFSYS_LOCK(enp->en_eslp, state);
579
580                 ef10_filter_set_entry_not_busy(eftp, tbl_id);
581
582                 EFSYS_UNLOCK(enp->en_eslp, state);
583         }
584
585         return (0);
586
587 fail1:
588         EFSYS_PROBE1(fail1, efx_rc_t, rc);
589
590         return (rc);
591 }
592
593 /*
594  * An arbitrary search limit for the software hash table. As per the linux net
595  * driver.
596  */
597 #define EF10_FILTER_SEARCH_LIMIT 200
598
599 static  __checkReturn   efx_rc_t
600 ef10_filter_add_internal(
601         __in            efx_nic_t *enp,
602         __inout         efx_filter_spec_t *spec,
603         __in            boolean_t may_replace,
604         __out_opt       uint32_t *filter_id)
605 {
606         efx_rc_t rc;
607         ef10_filter_table_t *eftp = enp->en_filter.ef_ef10_filter_table;
608         efx_filter_spec_t *saved_spec;
609         uint32_t hash;
610         unsigned int depth;
611         int ins_index;
612         boolean_t replacing = B_FALSE;
613         unsigned int i;
614         efsys_lock_state_t state;
615         boolean_t locked = B_FALSE;
616
617         EFSYS_ASSERT(EFX_FAMILY_IS_EF10(enp));
618
619         hash = ef10_filter_hash(spec);
620
621         /*
622          * FIXME: Add support for inserting filters of different priorities
623          * and removing lower priority multicast filters (bug 42378)
624          */
625
626         /*
627          * Find any existing filters with the same match tuple or
628          * else a free slot to insert at.  If any of them are busy,
629          * we have to wait and retry.
630          */
631 retry:
632         EFSYS_LOCK(enp->en_eslp, state);
633         locked = B_TRUE;
634
635         ins_index = -1;
636
637         for (depth = 1; depth <= EF10_FILTER_SEARCH_LIMIT; depth++) {
638                 i = (hash + depth) & (EFX_EF10_FILTER_TBL_ROWS - 1);
639                 saved_spec = ef10_filter_entry_spec(eftp, i);
640
641                 if (saved_spec == NULL) {
642                         if (ins_index < 0)
643                                 ins_index = i;
644                 } else if (ef10_filter_equal(spec, saved_spec)) {
645                         if (ef10_filter_entry_is_busy(eftp, i)) {
646                                 EFSYS_UNLOCK(enp->en_eslp, state);
647                                 locked = B_FALSE;
648                                 goto retry;
649                         }
650
651                         if (saved_spec->efs_priority == EFX_FILTER_PRI_AUTO) {
652                                 ins_index = i;
653                                 goto found;
654                         }
655
656                         if (ef10_filter_is_exclusive(spec)) {
657                                 if (may_replace) {
658                                         ins_index = i;
659                                         goto found;
660                                 } else {
661                                         rc = EEXIST;
662                                         goto fail1;
663                                 }
664                         }
665
666                         /* Leave existing */
667                 }
668         }
669
670         /*
671          * Once we reach the maximum search depth, use the first suitable slot
672          * or return EBUSY if there was none.
673          */
674         if (ins_index < 0) {
675                 rc = EBUSY;
676                 goto fail2;
677         }
678
679 found:
680         /*
681          * Create a software table entry if necessary, and mark it
682          * busy.  We might yet fail to insert, but any attempt to
683          * insert a conflicting filter while we're waiting for the
684          * firmware must find the busy entry.
685          */
686         saved_spec = ef10_filter_entry_spec(eftp, ins_index);
687         if (saved_spec) {
688                 if (saved_spec->efs_priority == EFX_FILTER_PRI_AUTO) {
689                         /* This is a filter we are refreshing */
690                         ef10_filter_set_entry_not_auto_old(eftp, ins_index);
691                         goto out_unlock;
692
693                 }
694                 replacing = B_TRUE;
695         } else {
696                 EFSYS_KMEM_ALLOC(enp->en_esip, sizeof (*spec), saved_spec);
697                 if (!saved_spec) {
698                         rc = ENOMEM;
699                         goto fail3;
700                 }
701                 *saved_spec = *spec;
702                 ef10_filter_set_entry(eftp, ins_index, saved_spec);
703         }
704         ef10_filter_set_entry_busy(eftp, ins_index);
705
706         EFSYS_UNLOCK(enp->en_eslp, state);
707         locked = B_FALSE;
708
709         /*
710          * On replacing the filter handle may change after after a successful
711          * replace operation.
712          */
713         if (replacing) {
714                 rc = efx_mcdi_filter_op_add(enp, spec,
715                     MC_CMD_FILTER_OP_IN_OP_REPLACE,
716                     &eftp->eft_entry[ins_index].efe_handle);
717         } else if (ef10_filter_is_exclusive(spec)) {
718                 rc = efx_mcdi_filter_op_add(enp, spec,
719                     MC_CMD_FILTER_OP_IN_OP_INSERT,
720                     &eftp->eft_entry[ins_index].efe_handle);
721         } else {
722                 rc = efx_mcdi_filter_op_add(enp, spec,
723                     MC_CMD_FILTER_OP_IN_OP_SUBSCRIBE,
724                     &eftp->eft_entry[ins_index].efe_handle);
725         }
726
727         if (rc != 0)
728                 goto fail4;
729
730         EFSYS_LOCK(enp->en_eslp, state);
731         locked = B_TRUE;
732
733         if (replacing) {
734                 /* Update the fields that may differ */
735                 saved_spec->efs_priority = spec->efs_priority;
736                 saved_spec->efs_flags = spec->efs_flags;
737                 saved_spec->efs_rss_context = spec->efs_rss_context;
738                 saved_spec->efs_dmaq_id = spec->efs_dmaq_id;
739         }
740
741         ef10_filter_set_entry_not_busy(eftp, ins_index);
742
743 out_unlock:
744
745         EFSYS_UNLOCK(enp->en_eslp, state);
746         locked = B_FALSE;
747
748         if (filter_id)
749                 *filter_id = ins_index;
750
751         return (0);
752
753 fail4:
754         EFSYS_PROBE(fail4);
755
756         if (!replacing) {
757                 EFSYS_KMEM_FREE(enp->en_esip, sizeof (*spec), saved_spec);
758                 saved_spec = NULL;
759         }
760         ef10_filter_set_entry_not_busy(eftp, ins_index);
761         ef10_filter_set_entry(eftp, ins_index, NULL);
762
763 fail3:
764         EFSYS_PROBE(fail3);
765
766 fail2:
767         EFSYS_PROBE(fail2);
768
769 fail1:
770         EFSYS_PROBE1(fail1, efx_rc_t, rc);
771
772         if (locked)
773                 EFSYS_UNLOCK(enp->en_eslp, state);
774
775         return (rc);
776 }
777
778         __checkReturn   efx_rc_t
779 ef10_filter_add(
780         __in            efx_nic_t *enp,
781         __inout         efx_filter_spec_t *spec,
782         __in            boolean_t may_replace)
783 {
784         efx_rc_t rc;
785
786         rc = ef10_filter_add_internal(enp, spec, may_replace, NULL);
787         if (rc != 0)
788                 goto fail1;
789
790         return (0);
791
792 fail1:
793         EFSYS_PROBE1(fail1, efx_rc_t, rc);
794
795         return (rc);
796 }
797
798
799 static  __checkReturn   efx_rc_t
800 ef10_filter_delete_internal(
801         __in            efx_nic_t *enp,
802         __in            uint32_t filter_id)
803 {
804         efx_rc_t rc;
805         ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
806         efx_filter_spec_t *spec;
807         efsys_lock_state_t state;
808         uint32_t filter_idx = filter_id % EFX_EF10_FILTER_TBL_ROWS;
809
810         /*
811          * Find the software table entry and mark it busy.  Don't
812          * remove it yet; any attempt to update while we're waiting
813          * for the firmware must find the busy entry.
814          *
815          * FIXME: What if the busy flag is never cleared?
816          */
817         EFSYS_LOCK(enp->en_eslp, state);
818         while (ef10_filter_entry_is_busy(table, filter_idx)) {
819                 EFSYS_UNLOCK(enp->en_eslp, state);
820                 EFSYS_SPIN(1);
821                 EFSYS_LOCK(enp->en_eslp, state);
822         }
823         if ((spec = ef10_filter_entry_spec(table, filter_idx)) != NULL) {
824                 ef10_filter_set_entry_busy(table, filter_idx);
825         }
826         EFSYS_UNLOCK(enp->en_eslp, state);
827
828         if (spec == NULL) {
829                 rc = ENOENT;
830                 goto fail1;
831         }
832
833         /*
834          * Try to remove the hardware filter. This may fail if the MC has
835          * rebooted (which frees all hardware filter resources).
836          */
837         if (ef10_filter_is_exclusive(spec)) {
838                 rc = efx_mcdi_filter_op_delete(enp,
839                     MC_CMD_FILTER_OP_IN_OP_REMOVE,
840                     &table->eft_entry[filter_idx].efe_handle);
841         } else {
842                 rc = efx_mcdi_filter_op_delete(enp,
843                     MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE,
844                     &table->eft_entry[filter_idx].efe_handle);
845         }
846
847         /* Free the software table entry */
848         EFSYS_LOCK(enp->en_eslp, state);
849         ef10_filter_set_entry_not_busy(table, filter_idx);
850         ef10_filter_set_entry(table, filter_idx, NULL);
851         EFSYS_UNLOCK(enp->en_eslp, state);
852
853         EFSYS_KMEM_FREE(enp->en_esip, sizeof (*spec), spec);
854
855         /* Check result of hardware filter removal */
856         if (rc != 0)
857                 goto fail2;
858
859         return (0);
860
861 fail2:
862         EFSYS_PROBE(fail2);
863
864 fail1:
865         EFSYS_PROBE1(fail1, efx_rc_t, rc);
866
867         return (rc);
868 }
869
870         __checkReturn   efx_rc_t
871 ef10_filter_delete(
872         __in            efx_nic_t *enp,
873         __inout         efx_filter_spec_t *spec)
874 {
875         efx_rc_t rc;
876         ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
877         efx_filter_spec_t *saved_spec;
878         unsigned int hash;
879         unsigned int depth;
880         unsigned int i;
881         efsys_lock_state_t state;
882         boolean_t locked = B_FALSE;
883
884         EFSYS_ASSERT(EFX_FAMILY_IS_EF10(enp));
885
886         hash = ef10_filter_hash(spec);
887
888         EFSYS_LOCK(enp->en_eslp, state);
889         locked = B_TRUE;
890
891         depth = 1;
892         for (;;) {
893                 i = (hash + depth) & (EFX_EF10_FILTER_TBL_ROWS - 1);
894                 saved_spec = ef10_filter_entry_spec(table, i);
895                 if (saved_spec && ef10_filter_equal(spec, saved_spec) &&
896                     ef10_filter_same_dest(spec, saved_spec)) {
897                         break;
898                 }
899                 if (depth == EF10_FILTER_SEARCH_LIMIT) {
900                         rc = ENOENT;
901                         goto fail1;
902                 }
903                 depth++;
904         }
905
906         EFSYS_UNLOCK(enp->en_eslp, state);
907         locked = B_FALSE;
908
909         rc = ef10_filter_delete_internal(enp, i);
910         if (rc != 0)
911                 goto fail2;
912
913         return (0);
914
915 fail2:
916         EFSYS_PROBE(fail2);
917
918 fail1:
919         EFSYS_PROBE1(fail1, efx_rc_t, rc);
920
921         if (locked)
922                 EFSYS_UNLOCK(enp->en_eslp, state);
923
924         return (rc);
925 }
926
927 static  __checkReturn   efx_rc_t
928 efx_mcdi_get_parser_disp_info(
929         __in                            efx_nic_t *enp,
930         __out_ecount(buffer_length)     uint32_t *buffer,
931         __in                            size_t buffer_length,
932         __in                            boolean_t encap,
933         __out                           size_t *list_lengthp)
934 {
935         efx_mcdi_req_t req;
936         EFX_MCDI_DECLARE_BUF(payload, MC_CMD_GET_PARSER_DISP_INFO_IN_LEN,
937                 MC_CMD_GET_PARSER_DISP_INFO_OUT_LENMAX);
938         size_t matches_count;
939         size_t list_size;
940         efx_rc_t rc;
941
942         req.emr_cmd = MC_CMD_GET_PARSER_DISP_INFO;
943         req.emr_in_buf = payload;
944         req.emr_in_length = MC_CMD_GET_PARSER_DISP_INFO_IN_LEN;
945         req.emr_out_buf = payload;
946         req.emr_out_length = MC_CMD_GET_PARSER_DISP_INFO_OUT_LENMAX;
947
948         MCDI_IN_SET_DWORD(req, GET_PARSER_DISP_INFO_OUT_OP, encap ?
949             MC_CMD_GET_PARSER_DISP_INFO_IN_OP_GET_SUPPORTED_ENCAP_RX_MATCHES :
950             MC_CMD_GET_PARSER_DISP_INFO_IN_OP_GET_SUPPORTED_RX_MATCHES);
951
952         efx_mcdi_execute(enp, &req);
953
954         if (req.emr_rc != 0) {
955                 rc = req.emr_rc;
956                 goto fail1;
957         }
958
959         matches_count = MCDI_OUT_DWORD(req,
960             GET_PARSER_DISP_INFO_OUT_NUM_SUPPORTED_MATCHES);
961
962         if (req.emr_out_length_used <
963             MC_CMD_GET_PARSER_DISP_INFO_OUT_LEN(matches_count)) {
964                 rc = EMSGSIZE;
965                 goto fail2;
966         }
967
968         *list_lengthp = matches_count;
969
970         if (buffer_length < matches_count) {
971                 rc = ENOSPC;
972                 goto fail3;
973         }
974
975         /*
976          * Check that the elements in the list in the MCDI response are the size
977          * we expect, so we can just copy them directly. Any conversion of the
978          * flags is handled by the caller.
979          */
980         EFX_STATIC_ASSERT(sizeof (uint32_t) ==
981             MC_CMD_GET_PARSER_DISP_INFO_OUT_SUPPORTED_MATCHES_LEN);
982
983         list_size = matches_count *
984                 MC_CMD_GET_PARSER_DISP_INFO_OUT_SUPPORTED_MATCHES_LEN;
985         memcpy(buffer,
986             MCDI_OUT2(req, uint32_t,
987                     GET_PARSER_DISP_INFO_OUT_SUPPORTED_MATCHES),
988             list_size);
989
990         return (0);
991
992 fail3:
993         EFSYS_PROBE(fail3);
994 fail2:
995         EFSYS_PROBE(fail2);
996 fail1:
997         EFSYS_PROBE1(fail1, efx_rc_t, rc);
998
999         return (rc);
1000 }
1001
1002         __checkReturn   efx_rc_t
1003 ef10_filter_supported_filters(
1004         __in                            efx_nic_t *enp,
1005         __out_ecount(buffer_length)     uint32_t *buffer,
1006         __in                            size_t buffer_length,
1007         __out                           size_t *list_lengthp)
1008 {
1009         efx_nic_cfg_t *encp = &(enp->en_nic_cfg);
1010         size_t mcdi_list_length;
1011         size_t mcdi_encap_list_length;
1012         size_t list_length;
1013         uint32_t i;
1014         uint32_t next_buf_idx;
1015         size_t next_buf_length;
1016         efx_rc_t rc;
1017         boolean_t no_space = B_FALSE;
1018         efx_filter_match_flags_t all_filter_flags =
1019             (EFX_FILTER_MATCH_REM_HOST | EFX_FILTER_MATCH_LOC_HOST |
1020             EFX_FILTER_MATCH_REM_MAC | EFX_FILTER_MATCH_REM_PORT |
1021             EFX_FILTER_MATCH_LOC_MAC | EFX_FILTER_MATCH_LOC_PORT |
1022             EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_INNER_VID |
1023             EFX_FILTER_MATCH_OUTER_VID | EFX_FILTER_MATCH_IP_PROTO |
1024             EFX_FILTER_MATCH_VNI_OR_VSID |
1025             EFX_FILTER_MATCH_IFRM_LOC_MAC |
1026             EFX_FILTER_MATCH_IFRM_UNKNOWN_MCAST_DST |
1027             EFX_FILTER_MATCH_IFRM_UNKNOWN_UCAST_DST |
1028             EFX_FILTER_MATCH_ENCAP_TYPE |
1029             EFX_FILTER_MATCH_UNKNOWN_MCAST_DST |
1030             EFX_FILTER_MATCH_UNKNOWN_UCAST_DST);
1031
1032         /*
1033          * Two calls to MC_CMD_GET_PARSER_DISP_INFO are needed: one to get the
1034          * list of supported filters for ordinary packets, and then another to
1035          * get the list of supported filters for encapsulated packets. To
1036          * distinguish the second list from the first, the
1037          * EFX_FILTER_MATCH_ENCAP_TYPE flag is added to each filter for
1038          * encapsulated packets.
1039          */
1040         rc = efx_mcdi_get_parser_disp_info(enp, buffer, buffer_length, B_FALSE,
1041             &mcdi_list_length);
1042         if (rc != 0) {
1043                 if (rc == ENOSPC)
1044                         no_space = B_TRUE;
1045                 else
1046                         goto fail1;
1047         }
1048
1049         if (no_space) {
1050                 next_buf_idx = 0;
1051                 next_buf_length = 0;
1052         } else {
1053                 EFSYS_ASSERT(mcdi_list_length <= buffer_length);
1054                 next_buf_idx = mcdi_list_length;
1055                 next_buf_length = buffer_length - mcdi_list_length;
1056         }
1057
1058         if (encp->enc_tunnel_encapsulations_supported != 0) {
1059                 rc = efx_mcdi_get_parser_disp_info(enp, &buffer[next_buf_idx],
1060                     next_buf_length, B_TRUE, &mcdi_encap_list_length);
1061                 if (rc != 0) {
1062                         if (rc == ENOSPC)
1063                                 no_space = B_TRUE;
1064                         else
1065                                 goto fail2;
1066                 } else {
1067                         for (i = next_buf_idx;
1068                             i < next_buf_idx + mcdi_encap_list_length; i++)
1069                                 buffer[i] |= EFX_FILTER_MATCH_ENCAP_TYPE;
1070                 }
1071         } else {
1072                 mcdi_encap_list_length = 0;
1073         }
1074
1075         if (no_space) {
1076                 *list_lengthp = mcdi_list_length + mcdi_encap_list_length;
1077                 rc = ENOSPC;
1078                 goto fail3;
1079         }
1080
1081         /*
1082          * The static assertions in ef10_filter_init() ensure that the values of
1083          * the EFX_FILTER_MATCH flags match those used by MCDI, so they don't
1084          * need to be converted.
1085          *
1086          * In case support is added to MCDI for additional flags, remove any
1087          * matches from the list which include flags we don't support. The order
1088          * of the matches is preserved as they are ordered from highest to
1089          * lowest priority.
1090          */
1091         EFSYS_ASSERT(mcdi_list_length + mcdi_encap_list_length <=
1092             buffer_length);
1093         list_length = 0;
1094         for (i = 0; i < mcdi_list_length + mcdi_encap_list_length; i++) {
1095                 if ((buffer[i] & ~all_filter_flags) == 0) {
1096                         buffer[list_length] = buffer[i];
1097                         list_length++;
1098                 }
1099         }
1100
1101         *list_lengthp = list_length;
1102
1103         return (0);
1104
1105 fail3:
1106         EFSYS_PROBE(fail3);
1107 fail2:
1108         EFSYS_PROBE(fail2);
1109 fail1:
1110         EFSYS_PROBE1(fail1, efx_rc_t, rc);
1111
1112         return (rc);
1113 }
1114
1115 static  __checkReturn   efx_rc_t
1116 ef10_filter_insert_unicast(
1117         __in                            efx_nic_t *enp,
1118         __in_ecount(6)                  uint8_t const *addr,
1119         __in                            efx_filter_flags_t filter_flags)
1120 {
1121         ef10_filter_table_t *eftp = enp->en_filter.ef_ef10_filter_table;
1122         efx_filter_spec_t spec;
1123         efx_rc_t rc;
1124
1125         /* Insert the filter for the local station address */
1126         efx_filter_spec_init_rx(&spec, EFX_FILTER_PRI_AUTO,
1127             filter_flags,
1128             eftp->eft_default_rxq);
1129         rc = efx_filter_spec_set_eth_local(&spec, EFX_FILTER_SPEC_VID_UNSPEC,
1130             addr);
1131         if (rc != 0)
1132                 goto fail1;
1133
1134         rc = ef10_filter_add_internal(enp, &spec, B_TRUE,
1135             &eftp->eft_unicst_filter_indexes[eftp->eft_unicst_filter_count]);
1136         if (rc != 0)
1137                 goto fail2;
1138
1139         eftp->eft_unicst_filter_count++;
1140         EFSYS_ASSERT(eftp->eft_unicst_filter_count <=
1141                     EFX_EF10_FILTER_UNICAST_FILTERS_MAX);
1142
1143         return (0);
1144
1145 fail2:
1146         EFSYS_PROBE(fail2);
1147 fail1:
1148         EFSYS_PROBE1(fail1, efx_rc_t, rc);
1149         return (rc);
1150 }
1151
1152 static  __checkReturn   efx_rc_t
1153 ef10_filter_insert_all_unicast(
1154         __in                            efx_nic_t *enp,
1155         __in                            efx_filter_flags_t filter_flags)
1156 {
1157         ef10_filter_table_t *eftp = enp->en_filter.ef_ef10_filter_table;
1158         efx_filter_spec_t spec;
1159         efx_rc_t rc;
1160
1161         /* Insert the unknown unicast filter */
1162         efx_filter_spec_init_rx(&spec, EFX_FILTER_PRI_AUTO,
1163             filter_flags,
1164             eftp->eft_default_rxq);
1165         rc = efx_filter_spec_set_uc_def(&spec);
1166         if (rc != 0)
1167                 goto fail1;
1168         rc = ef10_filter_add_internal(enp, &spec, B_TRUE,
1169             &eftp->eft_unicst_filter_indexes[eftp->eft_unicst_filter_count]);
1170         if (rc != 0)
1171                 goto fail2;
1172
1173         eftp->eft_unicst_filter_count++;
1174         EFSYS_ASSERT(eftp->eft_unicst_filter_count <=
1175                     EFX_EF10_FILTER_UNICAST_FILTERS_MAX);
1176
1177         return (0);
1178
1179 fail2:
1180         EFSYS_PROBE(fail2);
1181 fail1:
1182         EFSYS_PROBE1(fail1, efx_rc_t, rc);
1183         return (rc);
1184 }
1185
1186 static  __checkReturn   efx_rc_t
1187 ef10_filter_insert_multicast_list(
1188         __in                            efx_nic_t *enp,
1189         __in                            boolean_t mulcst,
1190         __in                            boolean_t brdcst,
1191         __in_ecount(6*count)            uint8_t const *addrs,
1192         __in                            uint32_t count,
1193         __in                            efx_filter_flags_t filter_flags,
1194         __in                            boolean_t rollback)
1195 {
1196         ef10_filter_table_t *eftp = enp->en_filter.ef_ef10_filter_table;
1197         efx_filter_spec_t spec;
1198         uint8_t addr[6];
1199         uint32_t i;
1200         uint32_t filter_index;
1201         uint32_t filter_count;
1202         efx_rc_t rc;
1203
1204         if (mulcst == B_FALSE)
1205                 count = 0;
1206
1207         if (count + (brdcst ? 1 : 0) >
1208             EFX_ARRAY_SIZE(eftp->eft_mulcst_filter_indexes)) {
1209                 /* Too many MAC addresses */
1210                 rc = EINVAL;
1211                 goto fail1;
1212         }
1213
1214         /* Insert/renew multicast address list filters */
1215         filter_count = 0;
1216         for (i = 0; i < count; i++) {
1217                 efx_filter_spec_init_rx(&spec,
1218                     EFX_FILTER_PRI_AUTO,
1219                     filter_flags,
1220                     eftp->eft_default_rxq);
1221
1222                 rc = efx_filter_spec_set_eth_local(&spec,
1223                     EFX_FILTER_SPEC_VID_UNSPEC,
1224                     &addrs[i * EFX_MAC_ADDR_LEN]);
1225                 if (rc != 0) {
1226                         if (rollback == B_TRUE) {
1227                                 /* Only stop upon failure if told to rollback */
1228                                 goto rollback;
1229                         } else {
1230                                 /*
1231                                  * Don't try to add a filter with a corrupt
1232                                  * specification.
1233                                  */
1234                                 continue;
1235                         }
1236                 }
1237
1238                 rc = ef10_filter_add_internal(enp, &spec, B_TRUE,
1239                                             &filter_index);
1240
1241                 if (rc == 0) {
1242                         eftp->eft_mulcst_filter_indexes[filter_count] =
1243                                 filter_index;
1244                         filter_count++;
1245                 } else if (rollback == B_TRUE) {
1246                         /* Only stop upon failure if told to rollback */
1247                         goto rollback;
1248                 }
1249
1250         }
1251
1252         if (brdcst == B_TRUE) {
1253                 /* Insert/renew broadcast address filter */
1254                 efx_filter_spec_init_rx(&spec, EFX_FILTER_PRI_AUTO,
1255                     filter_flags,
1256                     eftp->eft_default_rxq);
1257
1258                 EFX_MAC_BROADCAST_ADDR_SET(addr);
1259                 rc = efx_filter_spec_set_eth_local(&spec,
1260                     EFX_FILTER_SPEC_VID_UNSPEC, addr);
1261                 if ((rc != 0) && (rollback == B_TRUE)) {
1262                         /* Only stop upon failure if told to rollback */
1263                         goto rollback;
1264                 }
1265
1266                 rc = ef10_filter_add_internal(enp, &spec, B_TRUE,
1267                                             &filter_index);
1268
1269                 if (rc == 0) {
1270                         eftp->eft_mulcst_filter_indexes[filter_count] =
1271                                 filter_index;
1272                         filter_count++;
1273                 } else if (rollback == B_TRUE) {
1274                         /* Only stop upon failure if told to rollback */
1275                         goto rollback;
1276                 }
1277         }
1278
1279         eftp->eft_mulcst_filter_count = filter_count;
1280         eftp->eft_using_all_mulcst = B_FALSE;
1281
1282         return (0);
1283
1284 rollback:
1285         /* Remove any filters we have inserted */
1286         i = filter_count;
1287         while (i--) {
1288                 (void) ef10_filter_delete_internal(enp,
1289                     eftp->eft_mulcst_filter_indexes[i]);
1290         }
1291         eftp->eft_mulcst_filter_count = 0;
1292
1293 fail1:
1294         EFSYS_PROBE1(fail1, efx_rc_t, rc);
1295
1296         return (rc);
1297 }
1298
1299 static  __checkReturn   efx_rc_t
1300 ef10_filter_insert_all_multicast(
1301         __in                            efx_nic_t *enp,
1302         __in                            efx_filter_flags_t filter_flags)
1303 {
1304         ef10_filter_table_t *eftp = enp->en_filter.ef_ef10_filter_table;
1305         efx_filter_spec_t spec;
1306         efx_rc_t rc;
1307
1308         /* Insert the unknown multicast filter */
1309         efx_filter_spec_init_rx(&spec, EFX_FILTER_PRI_AUTO,
1310             filter_flags,
1311             eftp->eft_default_rxq);
1312         rc = efx_filter_spec_set_mc_def(&spec);
1313         if (rc != 0)
1314                 goto fail1;
1315
1316         rc = ef10_filter_add_internal(enp, &spec, B_TRUE,
1317             &eftp->eft_mulcst_filter_indexes[0]);
1318         if (rc != 0)
1319                 goto fail2;
1320
1321         eftp->eft_mulcst_filter_count = 1;
1322         eftp->eft_using_all_mulcst = B_TRUE;
1323
1324         /*
1325          * FIXME: If brdcst == B_FALSE, add a filter to drop broadcast traffic.
1326          */
1327
1328         return (0);
1329
1330 fail2:
1331         EFSYS_PROBE(fail2);
1332 fail1:
1333         EFSYS_PROBE1(fail1, efx_rc_t, rc);
1334
1335         return (rc);
1336 }
1337
1338 typedef struct ef10_filter_encap_entry_s {
1339         uint16_t                ether_type;
1340         efx_tunnel_protocol_t   encap_type;
1341         uint32_t                inner_frame_match;
1342 } ef10_filter_encap_entry_t;
1343
1344 #define EF10_ENCAP_FILTER_ENTRY(ipv, encap_type, inner_frame_match)     \
1345         { EFX_ETHER_TYPE_##ipv, EFX_TUNNEL_PROTOCOL_##encap_type,       \
1346             EFX_FILTER_INNER_FRAME_MATCH_UNKNOWN_##inner_frame_match }
1347
1348 static ef10_filter_encap_entry_t ef10_filter_encap_list[] = {
1349         EF10_ENCAP_FILTER_ENTRY(IPV4, VXLAN, UCAST_DST),
1350         EF10_ENCAP_FILTER_ENTRY(IPV4, VXLAN, MCAST_DST),
1351         EF10_ENCAP_FILTER_ENTRY(IPV6, VXLAN, UCAST_DST),
1352         EF10_ENCAP_FILTER_ENTRY(IPV6, VXLAN, MCAST_DST),
1353
1354         EF10_ENCAP_FILTER_ENTRY(IPV4, GENEVE, UCAST_DST),
1355         EF10_ENCAP_FILTER_ENTRY(IPV4, GENEVE, MCAST_DST),
1356         EF10_ENCAP_FILTER_ENTRY(IPV6, GENEVE, UCAST_DST),
1357         EF10_ENCAP_FILTER_ENTRY(IPV6, GENEVE, MCAST_DST),
1358
1359         EF10_ENCAP_FILTER_ENTRY(IPV4, NVGRE, UCAST_DST),
1360         EF10_ENCAP_FILTER_ENTRY(IPV4, NVGRE, MCAST_DST),
1361         EF10_ENCAP_FILTER_ENTRY(IPV6, NVGRE, UCAST_DST),
1362         EF10_ENCAP_FILTER_ENTRY(IPV6, NVGRE, MCAST_DST),
1363 };
1364
1365 #undef EF10_ENCAP_FILTER_ENTRY
1366
1367 static  __checkReturn   efx_rc_t
1368 ef10_filter_insert_encap_filters(
1369         __in            efx_nic_t *enp,
1370         __in            boolean_t mulcst,
1371         __in            efx_filter_flags_t filter_flags)
1372 {
1373         ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
1374         uint32_t i;
1375         efx_rc_t rc;
1376
1377         EFX_STATIC_ASSERT(EFX_ARRAY_SIZE(ef10_filter_encap_list) <=
1378                             EFX_ARRAY_SIZE(table->eft_encap_filter_indexes));
1379
1380         /*
1381          * On Medford, full-featured firmware can identify packets as being
1382          * tunnel encapsulated, even if no encapsulated packet offloads are in
1383          * use. When packets are identified as such, ordinary filters are not
1384          * applied, only ones specific to encapsulated packets. Hence we need to
1385          * insert filters for encapsulated packets in order to receive them.
1386          *
1387          * Separate filters need to be inserted for each ether type,
1388          * encapsulation type, and inner frame type (unicast or multicast). To
1389          * keep things simple and reduce the number of filters needed, catch-all
1390          * filters for all combinations of types are inserted, even if
1391          * all_unicst or all_mulcst have not been set. (These catch-all filters
1392          * may well, however, fail to insert on unprivileged functions.)
1393          */
1394         table->eft_encap_filter_count = 0;
1395         for (i = 0; i < EFX_ARRAY_SIZE(ef10_filter_encap_list); i++) {
1396                 efx_filter_spec_t spec;
1397                 ef10_filter_encap_entry_t *encap_filter =
1398                         &ef10_filter_encap_list[i];
1399
1400                 /*
1401                  * Skip multicast filters if we've not been asked for
1402                  * any multicast traffic.
1403                  */
1404                 if ((mulcst == B_FALSE) &&
1405                     (encap_filter->inner_frame_match ==
1406                     EFX_FILTER_INNER_FRAME_MATCH_UNKNOWN_MCAST_DST))
1407                         continue;
1408
1409                 efx_filter_spec_init_rx(&spec, EFX_FILTER_PRI_AUTO,
1410                                         filter_flags,
1411                                         table->eft_default_rxq);
1412                 efx_filter_spec_set_ether_type(&spec, encap_filter->ether_type);
1413                 rc = efx_filter_spec_set_encap_type(&spec,
1414                                             encap_filter->encap_type,
1415                                             encap_filter->inner_frame_match);
1416                 if (rc != 0)
1417                         goto fail1;
1418
1419                 rc = ef10_filter_add_internal(enp, &spec, B_TRUE,
1420                             &table->eft_encap_filter_indexes[
1421                                     table->eft_encap_filter_count]);
1422                 if (rc != 0) {
1423                         if (rc != EACCES)
1424                                 goto fail2;
1425                 } else {
1426                         table->eft_encap_filter_count++;
1427                 }
1428         }
1429
1430         return (0);
1431
1432 fail2:
1433         EFSYS_PROBE(fail2);
1434 fail1:
1435         EFSYS_PROBE1(fail1, efx_rc_t, rc);
1436
1437         return (rc);
1438 }
1439
1440 static                  void
1441 ef10_filter_remove_old(
1442         __in            efx_nic_t *enp)
1443 {
1444         ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
1445         uint32_t i;
1446
1447         for (i = 0; i < EFX_ARRAY_SIZE(table->eft_entry); i++) {
1448                 if (ef10_filter_entry_is_auto_old(table, i)) {
1449                         (void) ef10_filter_delete_internal(enp, i);
1450                 }
1451         }
1452 }
1453
1454
1455 static  __checkReturn   efx_rc_t
1456 ef10_filter_get_workarounds(
1457         __in                            efx_nic_t *enp)
1458 {
1459         efx_nic_cfg_t *encp = &enp->en_nic_cfg;
1460         uint32_t implemented = 0;
1461         uint32_t enabled = 0;
1462         efx_rc_t rc;
1463
1464         rc = efx_mcdi_get_workarounds(enp, &implemented, &enabled);
1465         if (rc == 0) {
1466                 /* Check if chained multicast filter support is enabled */
1467                 if (implemented & enabled & MC_CMD_GET_WORKAROUNDS_OUT_BUG26807)
1468                         encp->enc_bug26807_workaround = B_TRUE;
1469                 else
1470                         encp->enc_bug26807_workaround = B_FALSE;
1471         } else if (rc == ENOTSUP) {
1472                 /*
1473                  * Firmware is too old to support GET_WORKAROUNDS, and support
1474                  * for this workaround was implemented later.
1475                  */
1476                 encp->enc_bug26807_workaround = B_FALSE;
1477         } else {
1478                 goto fail1;
1479         }
1480
1481         return (0);
1482
1483 fail1:
1484         EFSYS_PROBE1(fail1, efx_rc_t, rc);
1485
1486         return (rc);
1487
1488 }
1489
1490
1491 /*
1492  * Reconfigure all filters.
1493  * If all_unicst and/or all mulcst filters cannot be applied then
1494  * return ENOTSUP (Note the filters for the specified addresses are
1495  * still applied in this case).
1496  */
1497         __checkReturn   efx_rc_t
1498 ef10_filter_reconfigure(
1499         __in                            efx_nic_t *enp,
1500         __in_ecount(6)                  uint8_t const *mac_addr,
1501         __in                            boolean_t all_unicst,
1502         __in                            boolean_t mulcst,
1503         __in                            boolean_t all_mulcst,
1504         __in                            boolean_t brdcst,
1505         __in_ecount(6*count)            uint8_t const *addrs,
1506         __in                            uint32_t count)
1507 {
1508         efx_nic_cfg_t *encp = &enp->en_nic_cfg;
1509         ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
1510         efx_filter_flags_t filter_flags;
1511         unsigned int i;
1512         efx_rc_t all_unicst_rc = 0;
1513         efx_rc_t all_mulcst_rc = 0;
1514         efx_rc_t rc;
1515
1516         if (table->eft_default_rxq == NULL) {
1517                 /*
1518                  * Filters direct traffic to the default RXQ, and so cannot be
1519                  * inserted until it is available. Any currently configured
1520                  * filters must be removed (ignore errors in case the MC
1521                  * has rebooted, which removes hardware filters).
1522                  */
1523                 for (i = 0; i < table->eft_unicst_filter_count; i++) {
1524                         (void) ef10_filter_delete_internal(enp,
1525                                         table->eft_unicst_filter_indexes[i]);
1526                 }
1527                 table->eft_unicst_filter_count = 0;
1528
1529                 for (i = 0; i < table->eft_mulcst_filter_count; i++) {
1530                         (void) ef10_filter_delete_internal(enp,
1531                                         table->eft_mulcst_filter_indexes[i]);
1532                 }
1533                 table->eft_mulcst_filter_count = 0;
1534
1535                 for (i = 0; i < table->eft_encap_filter_count; i++) {
1536                         (void) ef10_filter_delete_internal(enp,
1537                                         table->eft_encap_filter_indexes[i]);
1538                 }
1539                 table->eft_encap_filter_count = 0;
1540
1541                 return (0);
1542         }
1543
1544         if (table->eft_using_rss)
1545                 filter_flags = EFX_FILTER_FLAG_RX_RSS;
1546         else
1547                 filter_flags = 0;
1548
1549         /* Mark old filters which may need to be removed */
1550         for (i = 0; i < table->eft_unicst_filter_count; i++) {
1551                 ef10_filter_set_entry_auto_old(table,
1552                                         table->eft_unicst_filter_indexes[i]);
1553         }
1554         for (i = 0; i < table->eft_mulcst_filter_count; i++) {
1555                 ef10_filter_set_entry_auto_old(table,
1556                                         table->eft_mulcst_filter_indexes[i]);
1557         }
1558         for (i = 0; i < table->eft_encap_filter_count; i++) {
1559                 ef10_filter_set_entry_auto_old(table,
1560                                         table->eft_encap_filter_indexes[i]);
1561         }
1562
1563         /*
1564          * Insert or renew unicast filters.
1565          *
1566          * Firmware does not perform chaining on unicast filters. As traffic is
1567          * therefore only delivered to the first matching filter, we should
1568          * always insert the specific filter for our MAC address, to try and
1569          * ensure we get that traffic.
1570          *
1571          * (If the filter for our MAC address has already been inserted by
1572          * another function, we won't receive traffic sent to us, even if we
1573          * insert a unicast mismatch filter. To prevent traffic stealing, this
1574          * therefore relies on the privilege model only allowing functions to
1575          * insert filters for their own MAC address unless explicitly given
1576          * additional privileges by the user. This also means that, even on a
1577          * priviliged function, inserting a unicast mismatch filter may not
1578          * catch all traffic in multi PCI function scenarios.)
1579          */
1580         table->eft_unicst_filter_count = 0;
1581         rc = ef10_filter_insert_unicast(enp, mac_addr, filter_flags);
1582         if (all_unicst || (rc != 0)) {
1583                 all_unicst_rc = ef10_filter_insert_all_unicast(enp,
1584                                                     filter_flags);
1585                 if ((rc != 0) && (all_unicst_rc != 0))
1586                         goto fail1;
1587         }
1588
1589         /*
1590          * WORKAROUND_BUG26807 controls firmware support for chained multicast
1591          * filters, and can only be enabled or disabled when the hardware filter
1592          * table is empty.
1593          *
1594          * Chained multicast filters require support from the datapath firmware,
1595          * and may not be available (e.g. low-latency variants or old Huntington
1596          * firmware).
1597          *
1598          * Firmware will reset (FLR) functions which have inserted filters in
1599          * the hardware filter table when the workaround is enabled/disabled.
1600          * Functions without any hardware filters are not reset.
1601          *
1602          * Re-check if the workaround is enabled after adding unicast hardware
1603          * filters. This ensures that encp->enc_bug26807_workaround matches the
1604          * firmware state, and that later changes to enable/disable the
1605          * workaround will result in this function seeing a reset (FLR).
1606          *
1607          * In common-code drivers, we only support multiple PCI function
1608          * scenarios with firmware that supports multicast chaining, so we can
1609          * assume it is enabled for such cases and hence simplify the filter
1610          * insertion logic. Firmware that does not support multicast chaining
1611          * does not support multiple PCI function configurations either, so
1612          * filter insertion is much simpler and the same strategies can still be
1613          * used.
1614          */
1615         if ((rc = ef10_filter_get_workarounds(enp)) != 0)
1616                 goto fail2;
1617
1618         if ((table->eft_using_all_mulcst != all_mulcst) &&
1619             (encp->enc_bug26807_workaround == B_TRUE)) {
1620                 /*
1621                  * Multicast filter chaining is enabled, so traffic that matches
1622                  * more than one multicast filter will be replicated and
1623                  * delivered to multiple recipients.  To avoid this duplicate
1624                  * delivery, remove old multicast filters before inserting new
1625                  * multicast filters.
1626                  */
1627                 ef10_filter_remove_old(enp);
1628         }
1629
1630         /* Insert or renew multicast filters */
1631         if (all_mulcst == B_TRUE) {
1632                 /*
1633                  * Insert the all multicast filter. If that fails, try to insert
1634                  * all of our multicast filters (but without rollback on
1635                  * failure).
1636                  */
1637                 all_mulcst_rc = ef10_filter_insert_all_multicast(enp,
1638                                                             filter_flags);
1639                 if (all_mulcst_rc != 0) {
1640                         rc = ef10_filter_insert_multicast_list(enp, B_TRUE,
1641                             brdcst, addrs, count, filter_flags, B_FALSE);
1642                         if (rc != 0)
1643                                 goto fail3;
1644                 }
1645         } else {
1646                 /*
1647                  * Insert filters for multicast addresses.
1648                  * If any insertion fails, then rollback and try to insert the
1649                  * all multicast filter instead.
1650                  * If that also fails, try to insert all of the multicast
1651                  * filters (but without rollback on failure).
1652                  */
1653                 rc = ef10_filter_insert_multicast_list(enp, mulcst, brdcst,
1654                             addrs, count, filter_flags, B_TRUE);
1655                 if (rc != 0) {
1656                         if ((table->eft_using_all_mulcst == B_FALSE) &&
1657                             (encp->enc_bug26807_workaround == B_TRUE)) {
1658                                 /*
1659                                  * Multicast filter chaining is on, so remove
1660                                  * old filters before inserting the multicast
1661                                  * all filter to avoid duplicate delivery caused
1662                                  * by packets matching multiple filters.
1663                                  */
1664                                 ef10_filter_remove_old(enp);
1665                         }
1666
1667                         rc = ef10_filter_insert_all_multicast(enp,
1668                                                             filter_flags);
1669                         if (rc != 0) {
1670                                 rc = ef10_filter_insert_multicast_list(enp,
1671                                     mulcst, brdcst,
1672                                     addrs, count, filter_flags, B_FALSE);
1673                                 if (rc != 0)
1674                                         goto fail4;
1675                         }
1676                 }
1677         }
1678
1679         if (encp->enc_tunnel_encapsulations_supported != 0) {
1680                 /* Try to insert filters for encapsulated packets. */
1681                 (void) ef10_filter_insert_encap_filters(enp,
1682                                             mulcst || all_mulcst || brdcst,
1683                                             filter_flags);
1684         }
1685
1686         /* Remove old filters which were not renewed */
1687         ef10_filter_remove_old(enp);
1688
1689         /* report if any optional flags were rejected */
1690         if (((all_unicst != B_FALSE) && (all_unicst_rc != 0)) ||
1691             ((all_mulcst != B_FALSE) && (all_mulcst_rc != 0))) {
1692                 rc = ENOTSUP;
1693         }
1694
1695         return (rc);
1696
1697 fail4:
1698         EFSYS_PROBE(fail4);
1699 fail3:
1700         EFSYS_PROBE(fail3);
1701 fail2:
1702         EFSYS_PROBE(fail2);
1703 fail1:
1704         EFSYS_PROBE1(fail1, efx_rc_t, rc);
1705
1706         /* Clear auto old flags */
1707         for (i = 0; i < EFX_ARRAY_SIZE(table->eft_entry); i++) {
1708                 if (ef10_filter_entry_is_auto_old(table, i)) {
1709                         ef10_filter_set_entry_not_auto_old(table, i);
1710                 }
1711         }
1712
1713         return (rc);
1714 }
1715
1716                 void
1717 ef10_filter_get_default_rxq(
1718         __in            efx_nic_t *enp,
1719         __out           efx_rxq_t **erpp,
1720         __out           boolean_t *using_rss)
1721 {
1722         ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
1723
1724         *erpp = table->eft_default_rxq;
1725         *using_rss = table->eft_using_rss;
1726 }
1727
1728
1729                 void
1730 ef10_filter_default_rxq_set(
1731         __in            efx_nic_t *enp,
1732         __in            efx_rxq_t *erp,
1733         __in            boolean_t using_rss)
1734 {
1735         ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
1736
1737 #if EFSYS_OPT_RX_SCALE
1738         EFSYS_ASSERT((using_rss == B_FALSE) ||
1739             (enp->en_rss_context != EF10_RSS_CONTEXT_INVALID));
1740         table->eft_using_rss = using_rss;
1741 #else
1742         EFSYS_ASSERT(using_rss == B_FALSE);
1743         table->eft_using_rss = B_FALSE;
1744 #endif
1745         table->eft_default_rxq = erp;
1746 }
1747
1748                 void
1749 ef10_filter_default_rxq_clear(
1750         __in            efx_nic_t *enp)
1751 {
1752         ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
1753
1754         table->eft_default_rxq = NULL;
1755         table->eft_using_rss = B_FALSE;
1756 }
1757
1758
1759 #endif /* EFSYS_OPT_FILTER */
1760
1761 #endif /* EFX_OPTS_EF10() */