e4f8de51c046388bbb4ebb2c7e9e9151a7166b48
[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         for (;;) {
632                 ins_index = -1;
633                 depth = 1;
634                 EFSYS_LOCK(enp->en_eslp, state);
635                 locked = B_TRUE;
636
637                 for (;;) {
638                         i = (hash + depth) & (EFX_EF10_FILTER_TBL_ROWS - 1);
639                         saved_spec = ef10_filter_entry_spec(eftp, i);
640
641                         if (!saved_spec) {
642                                 if (ins_index < 0) {
643                                         ins_index = i;
644                                 }
645                         } else if (ef10_filter_equal(spec, saved_spec)) {
646                                 if (ef10_filter_entry_is_busy(eftp, i))
647                                         break;
648                                 if (saved_spec->efs_priority
649                                             == EFX_FILTER_PRI_AUTO) {
650                                         ins_index = i;
651                                         goto found;
652                                 } else if (ef10_filter_is_exclusive(spec)) {
653                                         if (may_replace) {
654                                                 ins_index = i;
655                                                 goto found;
656                                         } else {
657                                                 rc = EEXIST;
658                                                 goto fail1;
659                                         }
660                                 }
661
662                                 /* Leave existing */
663                         }
664
665                         /*
666                          * Once we reach the maximum search depth, use
667                          * the first suitable slot or return EBUSY if
668                          * there was none.
669                          */
670                         if (depth == EF10_FILTER_SEARCH_LIMIT) {
671                                 if (ins_index < 0) {
672                                         rc = EBUSY;
673                                         goto fail2;
674                                 }
675                                 goto found;
676                         }
677                         depth++;
678                 }
679                 EFSYS_UNLOCK(enp->en_eslp, state);
680                 locked = B_FALSE;
681         }
682
683 found:
684         /*
685          * Create a software table entry if necessary, and mark it
686          * busy.  We might yet fail to insert, but any attempt to
687          * insert a conflicting filter while we're waiting for the
688          * firmware must find the busy entry.
689          */
690         saved_spec = ef10_filter_entry_spec(eftp, ins_index);
691         if (saved_spec) {
692                 if (saved_spec->efs_priority == EFX_FILTER_PRI_AUTO) {
693                         /* This is a filter we are refreshing */
694                         ef10_filter_set_entry_not_auto_old(eftp, ins_index);
695                         goto out_unlock;
696
697                 }
698                 replacing = B_TRUE;
699         } else {
700                 EFSYS_KMEM_ALLOC(enp->en_esip, sizeof (*spec), saved_spec);
701                 if (!saved_spec) {
702                         rc = ENOMEM;
703                         goto fail3;
704                 }
705                 *saved_spec = *spec;
706                 ef10_filter_set_entry(eftp, ins_index, saved_spec);
707         }
708         ef10_filter_set_entry_busy(eftp, ins_index);
709
710         EFSYS_UNLOCK(enp->en_eslp, state);
711         locked = B_FALSE;
712
713         /*
714          * On replacing the filter handle may change after after a successful
715          * replace operation.
716          */
717         if (replacing) {
718                 rc = efx_mcdi_filter_op_add(enp, spec,
719                     MC_CMD_FILTER_OP_IN_OP_REPLACE,
720                     &eftp->eft_entry[ins_index].efe_handle);
721         } else if (ef10_filter_is_exclusive(spec)) {
722                 rc = efx_mcdi_filter_op_add(enp, spec,
723                     MC_CMD_FILTER_OP_IN_OP_INSERT,
724                     &eftp->eft_entry[ins_index].efe_handle);
725         } else {
726                 rc = efx_mcdi_filter_op_add(enp, spec,
727                     MC_CMD_FILTER_OP_IN_OP_SUBSCRIBE,
728                     &eftp->eft_entry[ins_index].efe_handle);
729         }
730
731         if (rc != 0)
732                 goto fail4;
733
734         EFSYS_LOCK(enp->en_eslp, state);
735         locked = B_TRUE;
736
737         if (replacing) {
738                 /* Update the fields that may differ */
739                 saved_spec->efs_priority = spec->efs_priority;
740                 saved_spec->efs_flags = spec->efs_flags;
741                 saved_spec->efs_rss_context = spec->efs_rss_context;
742                 saved_spec->efs_dmaq_id = spec->efs_dmaq_id;
743         }
744
745         ef10_filter_set_entry_not_busy(eftp, ins_index);
746
747 out_unlock:
748
749         EFSYS_UNLOCK(enp->en_eslp, state);
750         locked = B_FALSE;
751
752         if (filter_id)
753                 *filter_id = ins_index;
754
755         return (0);
756
757 fail4:
758         EFSYS_PROBE(fail4);
759
760         if (!replacing) {
761                 EFSYS_KMEM_FREE(enp->en_esip, sizeof (*spec), saved_spec);
762                 saved_spec = NULL;
763         }
764         ef10_filter_set_entry_not_busy(eftp, ins_index);
765         ef10_filter_set_entry(eftp, ins_index, NULL);
766
767 fail3:
768         EFSYS_PROBE(fail3);
769
770 fail2:
771         EFSYS_PROBE(fail2);
772
773 fail1:
774         EFSYS_PROBE1(fail1, efx_rc_t, rc);
775
776         if (locked)
777                 EFSYS_UNLOCK(enp->en_eslp, state);
778
779         return (rc);
780 }
781
782         __checkReturn   efx_rc_t
783 ef10_filter_add(
784         __in            efx_nic_t *enp,
785         __inout         efx_filter_spec_t *spec,
786         __in            boolean_t may_replace)
787 {
788         efx_rc_t rc;
789
790         rc = ef10_filter_add_internal(enp, spec, may_replace, NULL);
791         if (rc != 0)
792                 goto fail1;
793
794         return (0);
795
796 fail1:
797         EFSYS_PROBE1(fail1, efx_rc_t, rc);
798
799         return (rc);
800 }
801
802
803 static  __checkReturn   efx_rc_t
804 ef10_filter_delete_internal(
805         __in            efx_nic_t *enp,
806         __in            uint32_t filter_id)
807 {
808         efx_rc_t rc;
809         ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
810         efx_filter_spec_t *spec;
811         efsys_lock_state_t state;
812         uint32_t filter_idx = filter_id % EFX_EF10_FILTER_TBL_ROWS;
813
814         /*
815          * Find the software table entry and mark it busy.  Don't
816          * remove it yet; any attempt to update while we're waiting
817          * for the firmware must find the busy entry.
818          *
819          * FIXME: What if the busy flag is never cleared?
820          */
821         EFSYS_LOCK(enp->en_eslp, state);
822         while (ef10_filter_entry_is_busy(table, filter_idx)) {
823                 EFSYS_UNLOCK(enp->en_eslp, state);
824                 EFSYS_SPIN(1);
825                 EFSYS_LOCK(enp->en_eslp, state);
826         }
827         if ((spec = ef10_filter_entry_spec(table, filter_idx)) != NULL) {
828                 ef10_filter_set_entry_busy(table, filter_idx);
829         }
830         EFSYS_UNLOCK(enp->en_eslp, state);
831
832         if (spec == NULL) {
833                 rc = ENOENT;
834                 goto fail1;
835         }
836
837         /*
838          * Try to remove the hardware filter. This may fail if the MC has
839          * rebooted (which frees all hardware filter resources).
840          */
841         if (ef10_filter_is_exclusive(spec)) {
842                 rc = efx_mcdi_filter_op_delete(enp,
843                     MC_CMD_FILTER_OP_IN_OP_REMOVE,
844                     &table->eft_entry[filter_idx].efe_handle);
845         } else {
846                 rc = efx_mcdi_filter_op_delete(enp,
847                     MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE,
848                     &table->eft_entry[filter_idx].efe_handle);
849         }
850
851         /* Free the software table entry */
852         EFSYS_LOCK(enp->en_eslp, state);
853         ef10_filter_set_entry_not_busy(table, filter_idx);
854         ef10_filter_set_entry(table, filter_idx, NULL);
855         EFSYS_UNLOCK(enp->en_eslp, state);
856
857         EFSYS_KMEM_FREE(enp->en_esip, sizeof (*spec), spec);
858
859         /* Check result of hardware filter removal */
860         if (rc != 0)
861                 goto fail2;
862
863         return (0);
864
865 fail2:
866         EFSYS_PROBE(fail2);
867
868 fail1:
869         EFSYS_PROBE1(fail1, efx_rc_t, rc);
870
871         return (rc);
872 }
873
874         __checkReturn   efx_rc_t
875 ef10_filter_delete(
876         __in            efx_nic_t *enp,
877         __inout         efx_filter_spec_t *spec)
878 {
879         efx_rc_t rc;
880         ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
881         efx_filter_spec_t *saved_spec;
882         unsigned int hash;
883         unsigned int depth;
884         unsigned int i;
885         efsys_lock_state_t state;
886         boolean_t locked = B_FALSE;
887
888         EFSYS_ASSERT(EFX_FAMILY_IS_EF10(enp));
889
890         hash = ef10_filter_hash(spec);
891
892         EFSYS_LOCK(enp->en_eslp, state);
893         locked = B_TRUE;
894
895         depth = 1;
896         for (;;) {
897                 i = (hash + depth) & (EFX_EF10_FILTER_TBL_ROWS - 1);
898                 saved_spec = ef10_filter_entry_spec(table, i);
899                 if (saved_spec && ef10_filter_equal(spec, saved_spec) &&
900                     ef10_filter_same_dest(spec, saved_spec)) {
901                         break;
902                 }
903                 if (depth == EF10_FILTER_SEARCH_LIMIT) {
904                         rc = ENOENT;
905                         goto fail1;
906                 }
907                 depth++;
908         }
909
910         EFSYS_UNLOCK(enp->en_eslp, state);
911         locked = B_FALSE;
912
913         rc = ef10_filter_delete_internal(enp, i);
914         if (rc != 0)
915                 goto fail2;
916
917         return (0);
918
919 fail2:
920         EFSYS_PROBE(fail2);
921
922 fail1:
923         EFSYS_PROBE1(fail1, efx_rc_t, rc);
924
925         if (locked)
926                 EFSYS_UNLOCK(enp->en_eslp, state);
927
928         return (rc);
929 }
930
931 static  __checkReturn   efx_rc_t
932 efx_mcdi_get_parser_disp_info(
933         __in                            efx_nic_t *enp,
934         __out_ecount(buffer_length)     uint32_t *buffer,
935         __in                            size_t buffer_length,
936         __in                            boolean_t encap,
937         __out                           size_t *list_lengthp)
938 {
939         efx_mcdi_req_t req;
940         EFX_MCDI_DECLARE_BUF(payload, MC_CMD_GET_PARSER_DISP_INFO_IN_LEN,
941                 MC_CMD_GET_PARSER_DISP_INFO_OUT_LENMAX);
942         size_t matches_count;
943         size_t list_size;
944         efx_rc_t rc;
945
946         req.emr_cmd = MC_CMD_GET_PARSER_DISP_INFO;
947         req.emr_in_buf = payload;
948         req.emr_in_length = MC_CMD_GET_PARSER_DISP_INFO_IN_LEN;
949         req.emr_out_buf = payload;
950         req.emr_out_length = MC_CMD_GET_PARSER_DISP_INFO_OUT_LENMAX;
951
952         MCDI_IN_SET_DWORD(req, GET_PARSER_DISP_INFO_OUT_OP, encap ?
953             MC_CMD_GET_PARSER_DISP_INFO_IN_OP_GET_SUPPORTED_ENCAP_RX_MATCHES :
954             MC_CMD_GET_PARSER_DISP_INFO_IN_OP_GET_SUPPORTED_RX_MATCHES);
955
956         efx_mcdi_execute(enp, &req);
957
958         if (req.emr_rc != 0) {
959                 rc = req.emr_rc;
960                 goto fail1;
961         }
962
963         matches_count = MCDI_OUT_DWORD(req,
964             GET_PARSER_DISP_INFO_OUT_NUM_SUPPORTED_MATCHES);
965
966         if (req.emr_out_length_used <
967             MC_CMD_GET_PARSER_DISP_INFO_OUT_LEN(matches_count)) {
968                 rc = EMSGSIZE;
969                 goto fail2;
970         }
971
972         *list_lengthp = matches_count;
973
974         if (buffer_length < matches_count) {
975                 rc = ENOSPC;
976                 goto fail3;
977         }
978
979         /*
980          * Check that the elements in the list in the MCDI response are the size
981          * we expect, so we can just copy them directly. Any conversion of the
982          * flags is handled by the caller.
983          */
984         EFX_STATIC_ASSERT(sizeof (uint32_t) ==
985             MC_CMD_GET_PARSER_DISP_INFO_OUT_SUPPORTED_MATCHES_LEN);
986
987         list_size = matches_count *
988                 MC_CMD_GET_PARSER_DISP_INFO_OUT_SUPPORTED_MATCHES_LEN;
989         memcpy(buffer,
990             MCDI_OUT2(req, uint32_t,
991                     GET_PARSER_DISP_INFO_OUT_SUPPORTED_MATCHES),
992             list_size);
993
994         return (0);
995
996 fail3:
997         EFSYS_PROBE(fail3);
998 fail2:
999         EFSYS_PROBE(fail2);
1000 fail1:
1001         EFSYS_PROBE1(fail1, efx_rc_t, rc);
1002
1003         return (rc);
1004 }
1005
1006         __checkReturn   efx_rc_t
1007 ef10_filter_supported_filters(
1008         __in                            efx_nic_t *enp,
1009         __out_ecount(buffer_length)     uint32_t *buffer,
1010         __in                            size_t buffer_length,
1011         __out                           size_t *list_lengthp)
1012 {
1013         efx_nic_cfg_t *encp = &(enp->en_nic_cfg);
1014         size_t mcdi_list_length;
1015         size_t mcdi_encap_list_length;
1016         size_t list_length;
1017         uint32_t i;
1018         uint32_t next_buf_idx;
1019         size_t next_buf_length;
1020         efx_rc_t rc;
1021         boolean_t no_space = B_FALSE;
1022         efx_filter_match_flags_t all_filter_flags =
1023             (EFX_FILTER_MATCH_REM_HOST | EFX_FILTER_MATCH_LOC_HOST |
1024             EFX_FILTER_MATCH_REM_MAC | EFX_FILTER_MATCH_REM_PORT |
1025             EFX_FILTER_MATCH_LOC_MAC | EFX_FILTER_MATCH_LOC_PORT |
1026             EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_INNER_VID |
1027             EFX_FILTER_MATCH_OUTER_VID | EFX_FILTER_MATCH_IP_PROTO |
1028             EFX_FILTER_MATCH_VNI_OR_VSID |
1029             EFX_FILTER_MATCH_IFRM_LOC_MAC |
1030             EFX_FILTER_MATCH_IFRM_UNKNOWN_MCAST_DST |
1031             EFX_FILTER_MATCH_IFRM_UNKNOWN_UCAST_DST |
1032             EFX_FILTER_MATCH_ENCAP_TYPE |
1033             EFX_FILTER_MATCH_UNKNOWN_MCAST_DST |
1034             EFX_FILTER_MATCH_UNKNOWN_UCAST_DST);
1035
1036         /*
1037          * Two calls to MC_CMD_GET_PARSER_DISP_INFO are needed: one to get the
1038          * list of supported filters for ordinary packets, and then another to
1039          * get the list of supported filters for encapsulated packets. To
1040          * distinguish the second list from the first, the
1041          * EFX_FILTER_MATCH_ENCAP_TYPE flag is added to each filter for
1042          * encapsulated packets.
1043          */
1044         rc = efx_mcdi_get_parser_disp_info(enp, buffer, buffer_length, B_FALSE,
1045             &mcdi_list_length);
1046         if (rc != 0) {
1047                 if (rc == ENOSPC)
1048                         no_space = B_TRUE;
1049                 else
1050                         goto fail1;
1051         }
1052
1053         if (no_space) {
1054                 next_buf_idx = 0;
1055                 next_buf_length = 0;
1056         } else {
1057                 EFSYS_ASSERT(mcdi_list_length <= buffer_length);
1058                 next_buf_idx = mcdi_list_length;
1059                 next_buf_length = buffer_length - mcdi_list_length;
1060         }
1061
1062         if (encp->enc_tunnel_encapsulations_supported != 0) {
1063                 rc = efx_mcdi_get_parser_disp_info(enp, &buffer[next_buf_idx],
1064                     next_buf_length, B_TRUE, &mcdi_encap_list_length);
1065                 if (rc != 0) {
1066                         if (rc == ENOSPC)
1067                                 no_space = B_TRUE;
1068                         else
1069                                 goto fail2;
1070                 } else {
1071                         for (i = next_buf_idx;
1072                             i < next_buf_idx + mcdi_encap_list_length; i++)
1073                                 buffer[i] |= EFX_FILTER_MATCH_ENCAP_TYPE;
1074                 }
1075         } else {
1076                 mcdi_encap_list_length = 0;
1077         }
1078
1079         if (no_space) {
1080                 *list_lengthp = mcdi_list_length + mcdi_encap_list_length;
1081                 rc = ENOSPC;
1082                 goto fail3;
1083         }
1084
1085         /*
1086          * The static assertions in ef10_filter_init() ensure that the values of
1087          * the EFX_FILTER_MATCH flags match those used by MCDI, so they don't
1088          * need to be converted.
1089          *
1090          * In case support is added to MCDI for additional flags, remove any
1091          * matches from the list which include flags we don't support. The order
1092          * of the matches is preserved as they are ordered from highest to
1093          * lowest priority.
1094          */
1095         EFSYS_ASSERT(mcdi_list_length + mcdi_encap_list_length <=
1096             buffer_length);
1097         list_length = 0;
1098         for (i = 0; i < mcdi_list_length + mcdi_encap_list_length; i++) {
1099                 if ((buffer[i] & ~all_filter_flags) == 0) {
1100                         buffer[list_length] = buffer[i];
1101                         list_length++;
1102                 }
1103         }
1104
1105         *list_lengthp = list_length;
1106
1107         return (0);
1108
1109 fail3:
1110         EFSYS_PROBE(fail3);
1111 fail2:
1112         EFSYS_PROBE(fail2);
1113 fail1:
1114         EFSYS_PROBE1(fail1, efx_rc_t, rc);
1115
1116         return (rc);
1117 }
1118
1119 static  __checkReturn   efx_rc_t
1120 ef10_filter_insert_unicast(
1121         __in                            efx_nic_t *enp,
1122         __in_ecount(6)                  uint8_t const *addr,
1123         __in                            efx_filter_flags_t filter_flags)
1124 {
1125         ef10_filter_table_t *eftp = enp->en_filter.ef_ef10_filter_table;
1126         efx_filter_spec_t spec;
1127         efx_rc_t rc;
1128
1129         /* Insert the filter for the local station address */
1130         efx_filter_spec_init_rx(&spec, EFX_FILTER_PRI_AUTO,
1131             filter_flags,
1132             eftp->eft_default_rxq);
1133         rc = efx_filter_spec_set_eth_local(&spec, EFX_FILTER_SPEC_VID_UNSPEC,
1134             addr);
1135         if (rc != 0)
1136                 goto fail1;
1137
1138         rc = ef10_filter_add_internal(enp, &spec, B_TRUE,
1139             &eftp->eft_unicst_filter_indexes[eftp->eft_unicst_filter_count]);
1140         if (rc != 0)
1141                 goto fail2;
1142
1143         eftp->eft_unicst_filter_count++;
1144         EFSYS_ASSERT(eftp->eft_unicst_filter_count <=
1145                     EFX_EF10_FILTER_UNICAST_FILTERS_MAX);
1146
1147         return (0);
1148
1149 fail2:
1150         EFSYS_PROBE(fail2);
1151 fail1:
1152         EFSYS_PROBE1(fail1, efx_rc_t, rc);
1153         return (rc);
1154 }
1155
1156 static  __checkReturn   efx_rc_t
1157 ef10_filter_insert_all_unicast(
1158         __in                            efx_nic_t *enp,
1159         __in                            efx_filter_flags_t filter_flags)
1160 {
1161         ef10_filter_table_t *eftp = enp->en_filter.ef_ef10_filter_table;
1162         efx_filter_spec_t spec;
1163         efx_rc_t rc;
1164
1165         /* Insert the unknown unicast filter */
1166         efx_filter_spec_init_rx(&spec, EFX_FILTER_PRI_AUTO,
1167             filter_flags,
1168             eftp->eft_default_rxq);
1169         rc = efx_filter_spec_set_uc_def(&spec);
1170         if (rc != 0)
1171                 goto fail1;
1172         rc = ef10_filter_add_internal(enp, &spec, B_TRUE,
1173             &eftp->eft_unicst_filter_indexes[eftp->eft_unicst_filter_count]);
1174         if (rc != 0)
1175                 goto fail2;
1176
1177         eftp->eft_unicst_filter_count++;
1178         EFSYS_ASSERT(eftp->eft_unicst_filter_count <=
1179                     EFX_EF10_FILTER_UNICAST_FILTERS_MAX);
1180
1181         return (0);
1182
1183 fail2:
1184         EFSYS_PROBE(fail2);
1185 fail1:
1186         EFSYS_PROBE1(fail1, efx_rc_t, rc);
1187         return (rc);
1188 }
1189
1190 static  __checkReturn   efx_rc_t
1191 ef10_filter_insert_multicast_list(
1192         __in                            efx_nic_t *enp,
1193         __in                            boolean_t mulcst,
1194         __in                            boolean_t brdcst,
1195         __in_ecount(6*count)            uint8_t const *addrs,
1196         __in                            uint32_t count,
1197         __in                            efx_filter_flags_t filter_flags,
1198         __in                            boolean_t rollback)
1199 {
1200         ef10_filter_table_t *eftp = enp->en_filter.ef_ef10_filter_table;
1201         efx_filter_spec_t spec;
1202         uint8_t addr[6];
1203         uint32_t i;
1204         uint32_t filter_index;
1205         uint32_t filter_count;
1206         efx_rc_t rc;
1207
1208         if (mulcst == B_FALSE)
1209                 count = 0;
1210
1211         if (count + (brdcst ? 1 : 0) >
1212             EFX_ARRAY_SIZE(eftp->eft_mulcst_filter_indexes)) {
1213                 /* Too many MAC addresses */
1214                 rc = EINVAL;
1215                 goto fail1;
1216         }
1217
1218         /* Insert/renew multicast address list filters */
1219         filter_count = 0;
1220         for (i = 0; i < count; i++) {
1221                 efx_filter_spec_init_rx(&spec,
1222                     EFX_FILTER_PRI_AUTO,
1223                     filter_flags,
1224                     eftp->eft_default_rxq);
1225
1226                 rc = efx_filter_spec_set_eth_local(&spec,
1227                     EFX_FILTER_SPEC_VID_UNSPEC,
1228                     &addrs[i * EFX_MAC_ADDR_LEN]);
1229                 if (rc != 0) {
1230                         if (rollback == B_TRUE) {
1231                                 /* Only stop upon failure if told to rollback */
1232                                 goto rollback;
1233                         } else {
1234                                 /*
1235                                  * Don't try to add a filter with a corrupt
1236                                  * specification.
1237                                  */
1238                                 continue;
1239                         }
1240                 }
1241
1242                 rc = ef10_filter_add_internal(enp, &spec, B_TRUE,
1243                                             &filter_index);
1244
1245                 if (rc == 0) {
1246                         eftp->eft_mulcst_filter_indexes[filter_count] =
1247                                 filter_index;
1248                         filter_count++;
1249                 } else if (rollback == B_TRUE) {
1250                         /* Only stop upon failure if told to rollback */
1251                         goto rollback;
1252                 }
1253
1254         }
1255
1256         if (brdcst == B_TRUE) {
1257                 /* Insert/renew broadcast address filter */
1258                 efx_filter_spec_init_rx(&spec, EFX_FILTER_PRI_AUTO,
1259                     filter_flags,
1260                     eftp->eft_default_rxq);
1261
1262                 EFX_MAC_BROADCAST_ADDR_SET(addr);
1263                 rc = efx_filter_spec_set_eth_local(&spec,
1264                     EFX_FILTER_SPEC_VID_UNSPEC, addr);
1265                 if ((rc != 0) && (rollback == B_TRUE)) {
1266                         /* Only stop upon failure if told to rollback */
1267                         goto rollback;
1268                 }
1269
1270                 rc = ef10_filter_add_internal(enp, &spec, B_TRUE,
1271                                             &filter_index);
1272
1273                 if (rc == 0) {
1274                         eftp->eft_mulcst_filter_indexes[filter_count] =
1275                                 filter_index;
1276                         filter_count++;
1277                 } else if (rollback == B_TRUE) {
1278                         /* Only stop upon failure if told to rollback */
1279                         goto rollback;
1280                 }
1281         }
1282
1283         eftp->eft_mulcst_filter_count = filter_count;
1284         eftp->eft_using_all_mulcst = B_FALSE;
1285
1286         return (0);
1287
1288 rollback:
1289         /* Remove any filters we have inserted */
1290         i = filter_count;
1291         while (i--) {
1292                 (void) ef10_filter_delete_internal(enp,
1293                     eftp->eft_mulcst_filter_indexes[i]);
1294         }
1295         eftp->eft_mulcst_filter_count = 0;
1296
1297 fail1:
1298         EFSYS_PROBE1(fail1, efx_rc_t, rc);
1299
1300         return (rc);
1301 }
1302
1303 static  __checkReturn   efx_rc_t
1304 ef10_filter_insert_all_multicast(
1305         __in                            efx_nic_t *enp,
1306         __in                            efx_filter_flags_t filter_flags)
1307 {
1308         ef10_filter_table_t *eftp = enp->en_filter.ef_ef10_filter_table;
1309         efx_filter_spec_t spec;
1310         efx_rc_t rc;
1311
1312         /* Insert the unknown multicast filter */
1313         efx_filter_spec_init_rx(&spec, EFX_FILTER_PRI_AUTO,
1314             filter_flags,
1315             eftp->eft_default_rxq);
1316         rc = efx_filter_spec_set_mc_def(&spec);
1317         if (rc != 0)
1318                 goto fail1;
1319
1320         rc = ef10_filter_add_internal(enp, &spec, B_TRUE,
1321             &eftp->eft_mulcst_filter_indexes[0]);
1322         if (rc != 0)
1323                 goto fail2;
1324
1325         eftp->eft_mulcst_filter_count = 1;
1326         eftp->eft_using_all_mulcst = B_TRUE;
1327
1328         /*
1329          * FIXME: If brdcst == B_FALSE, add a filter to drop broadcast traffic.
1330          */
1331
1332         return (0);
1333
1334 fail2:
1335         EFSYS_PROBE(fail2);
1336 fail1:
1337         EFSYS_PROBE1(fail1, efx_rc_t, rc);
1338
1339         return (rc);
1340 }
1341
1342 typedef struct ef10_filter_encap_entry_s {
1343         uint16_t                ether_type;
1344         efx_tunnel_protocol_t   encap_type;
1345         uint32_t                inner_frame_match;
1346 } ef10_filter_encap_entry_t;
1347
1348 #define EF10_ENCAP_FILTER_ENTRY(ipv, encap_type, inner_frame_match)     \
1349         { EFX_ETHER_TYPE_##ipv, EFX_TUNNEL_PROTOCOL_##encap_type,       \
1350             EFX_FILTER_INNER_FRAME_MATCH_UNKNOWN_##inner_frame_match }
1351
1352 static ef10_filter_encap_entry_t ef10_filter_encap_list[] = {
1353         EF10_ENCAP_FILTER_ENTRY(IPV4, VXLAN, UCAST_DST),
1354         EF10_ENCAP_FILTER_ENTRY(IPV4, VXLAN, MCAST_DST),
1355         EF10_ENCAP_FILTER_ENTRY(IPV6, VXLAN, UCAST_DST),
1356         EF10_ENCAP_FILTER_ENTRY(IPV6, VXLAN, MCAST_DST),
1357
1358         EF10_ENCAP_FILTER_ENTRY(IPV4, GENEVE, UCAST_DST),
1359         EF10_ENCAP_FILTER_ENTRY(IPV4, GENEVE, MCAST_DST),
1360         EF10_ENCAP_FILTER_ENTRY(IPV6, GENEVE, UCAST_DST),
1361         EF10_ENCAP_FILTER_ENTRY(IPV6, GENEVE, MCAST_DST),
1362
1363         EF10_ENCAP_FILTER_ENTRY(IPV4, NVGRE, UCAST_DST),
1364         EF10_ENCAP_FILTER_ENTRY(IPV4, NVGRE, MCAST_DST),
1365         EF10_ENCAP_FILTER_ENTRY(IPV6, NVGRE, UCAST_DST),
1366         EF10_ENCAP_FILTER_ENTRY(IPV6, NVGRE, MCAST_DST),
1367 };
1368
1369 #undef EF10_ENCAP_FILTER_ENTRY
1370
1371 static  __checkReturn   efx_rc_t
1372 ef10_filter_insert_encap_filters(
1373         __in            efx_nic_t *enp,
1374         __in            boolean_t mulcst,
1375         __in            efx_filter_flags_t filter_flags)
1376 {
1377         ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
1378         uint32_t i;
1379         efx_rc_t rc;
1380
1381         EFX_STATIC_ASSERT(EFX_ARRAY_SIZE(ef10_filter_encap_list) <=
1382                             EFX_ARRAY_SIZE(table->eft_encap_filter_indexes));
1383
1384         /*
1385          * On Medford, full-featured firmware can identify packets as being
1386          * tunnel encapsulated, even if no encapsulated packet offloads are in
1387          * use. When packets are identified as such, ordinary filters are not
1388          * applied, only ones specific to encapsulated packets. Hence we need to
1389          * insert filters for encapsulated packets in order to receive them.
1390          *
1391          * Separate filters need to be inserted for each ether type,
1392          * encapsulation type, and inner frame type (unicast or multicast). To
1393          * keep things simple and reduce the number of filters needed, catch-all
1394          * filters for all combinations of types are inserted, even if
1395          * all_unicst or all_mulcst have not been set. (These catch-all filters
1396          * may well, however, fail to insert on unprivileged functions.)
1397          */
1398         table->eft_encap_filter_count = 0;
1399         for (i = 0; i < EFX_ARRAY_SIZE(ef10_filter_encap_list); i++) {
1400                 efx_filter_spec_t spec;
1401                 ef10_filter_encap_entry_t *encap_filter =
1402                         &ef10_filter_encap_list[i];
1403
1404                 /*
1405                  * Skip multicast filters if we've not been asked for
1406                  * any multicast traffic.
1407                  */
1408                 if ((mulcst == B_FALSE) &&
1409                     (encap_filter->inner_frame_match ==
1410                     EFX_FILTER_INNER_FRAME_MATCH_UNKNOWN_MCAST_DST))
1411                         continue;
1412
1413                 efx_filter_spec_init_rx(&spec, EFX_FILTER_PRI_AUTO,
1414                                         filter_flags,
1415                                         table->eft_default_rxq);
1416                 efx_filter_spec_set_ether_type(&spec, encap_filter->ether_type);
1417                 rc = efx_filter_spec_set_encap_type(&spec,
1418                                             encap_filter->encap_type,
1419                                             encap_filter->inner_frame_match);
1420                 if (rc != 0)
1421                         goto fail1;
1422
1423                 rc = ef10_filter_add_internal(enp, &spec, B_TRUE,
1424                             &table->eft_encap_filter_indexes[
1425                                     table->eft_encap_filter_count]);
1426                 if (rc != 0) {
1427                         if (rc != EACCES)
1428                                 goto fail2;
1429                 } else {
1430                         table->eft_encap_filter_count++;
1431                 }
1432         }
1433
1434         return (0);
1435
1436 fail2:
1437         EFSYS_PROBE(fail2);
1438 fail1:
1439         EFSYS_PROBE1(fail1, efx_rc_t, rc);
1440
1441         return (rc);
1442 }
1443
1444 static                  void
1445 ef10_filter_remove_old(
1446         __in            efx_nic_t *enp)
1447 {
1448         ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
1449         uint32_t i;
1450
1451         for (i = 0; i < EFX_ARRAY_SIZE(table->eft_entry); i++) {
1452                 if (ef10_filter_entry_is_auto_old(table, i)) {
1453                         (void) ef10_filter_delete_internal(enp, i);
1454                 }
1455         }
1456 }
1457
1458
1459 static  __checkReturn   efx_rc_t
1460 ef10_filter_get_workarounds(
1461         __in                            efx_nic_t *enp)
1462 {
1463         efx_nic_cfg_t *encp = &enp->en_nic_cfg;
1464         uint32_t implemented = 0;
1465         uint32_t enabled = 0;
1466         efx_rc_t rc;
1467
1468         rc = efx_mcdi_get_workarounds(enp, &implemented, &enabled);
1469         if (rc == 0) {
1470                 /* Check if chained multicast filter support is enabled */
1471                 if (implemented & enabled & MC_CMD_GET_WORKAROUNDS_OUT_BUG26807)
1472                         encp->enc_bug26807_workaround = B_TRUE;
1473                 else
1474                         encp->enc_bug26807_workaround = B_FALSE;
1475         } else if (rc == ENOTSUP) {
1476                 /*
1477                  * Firmware is too old to support GET_WORKAROUNDS, and support
1478                  * for this workaround was implemented later.
1479                  */
1480                 encp->enc_bug26807_workaround = B_FALSE;
1481         } else {
1482                 goto fail1;
1483         }
1484
1485         return (0);
1486
1487 fail1:
1488         EFSYS_PROBE1(fail1, efx_rc_t, rc);
1489
1490         return (rc);
1491
1492 }
1493
1494
1495 /*
1496  * Reconfigure all filters.
1497  * If all_unicst and/or all mulcst filters cannot be applied then
1498  * return ENOTSUP (Note the filters for the specified addresses are
1499  * still applied in this case).
1500  */
1501         __checkReturn   efx_rc_t
1502 ef10_filter_reconfigure(
1503         __in                            efx_nic_t *enp,
1504         __in_ecount(6)                  uint8_t const *mac_addr,
1505         __in                            boolean_t all_unicst,
1506         __in                            boolean_t mulcst,
1507         __in                            boolean_t all_mulcst,
1508         __in                            boolean_t brdcst,
1509         __in_ecount(6*count)            uint8_t const *addrs,
1510         __in                            uint32_t count)
1511 {
1512         efx_nic_cfg_t *encp = &enp->en_nic_cfg;
1513         ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
1514         efx_filter_flags_t filter_flags;
1515         unsigned int i;
1516         efx_rc_t all_unicst_rc = 0;
1517         efx_rc_t all_mulcst_rc = 0;
1518         efx_rc_t rc;
1519
1520         if (table->eft_default_rxq == NULL) {
1521                 /*
1522                  * Filters direct traffic to the default RXQ, and so cannot be
1523                  * inserted until it is available. Any currently configured
1524                  * filters must be removed (ignore errors in case the MC
1525                  * has rebooted, which removes hardware filters).
1526                  */
1527                 for (i = 0; i < table->eft_unicst_filter_count; i++) {
1528                         (void) ef10_filter_delete_internal(enp,
1529                                         table->eft_unicst_filter_indexes[i]);
1530                 }
1531                 table->eft_unicst_filter_count = 0;
1532
1533                 for (i = 0; i < table->eft_mulcst_filter_count; i++) {
1534                         (void) ef10_filter_delete_internal(enp,
1535                                         table->eft_mulcst_filter_indexes[i]);
1536                 }
1537                 table->eft_mulcst_filter_count = 0;
1538
1539                 for (i = 0; i < table->eft_encap_filter_count; i++) {
1540                         (void) ef10_filter_delete_internal(enp,
1541                                         table->eft_encap_filter_indexes[i]);
1542                 }
1543                 table->eft_encap_filter_count = 0;
1544
1545                 return (0);
1546         }
1547
1548         if (table->eft_using_rss)
1549                 filter_flags = EFX_FILTER_FLAG_RX_RSS;
1550         else
1551                 filter_flags = 0;
1552
1553         /* Mark old filters which may need to be removed */
1554         for (i = 0; i < table->eft_unicst_filter_count; i++) {
1555                 ef10_filter_set_entry_auto_old(table,
1556                                         table->eft_unicst_filter_indexes[i]);
1557         }
1558         for (i = 0; i < table->eft_mulcst_filter_count; i++) {
1559                 ef10_filter_set_entry_auto_old(table,
1560                                         table->eft_mulcst_filter_indexes[i]);
1561         }
1562         for (i = 0; i < table->eft_encap_filter_count; i++) {
1563                 ef10_filter_set_entry_auto_old(table,
1564                                         table->eft_encap_filter_indexes[i]);
1565         }
1566
1567         /*
1568          * Insert or renew unicast filters.
1569          *
1570          * Firmware does not perform chaining on unicast filters. As traffic is
1571          * therefore only delivered to the first matching filter, we should
1572          * always insert the specific filter for our MAC address, to try and
1573          * ensure we get that traffic.
1574          *
1575          * (If the filter for our MAC address has already been inserted by
1576          * another function, we won't receive traffic sent to us, even if we
1577          * insert a unicast mismatch filter. To prevent traffic stealing, this
1578          * therefore relies on the privilege model only allowing functions to
1579          * insert filters for their own MAC address unless explicitly given
1580          * additional privileges by the user. This also means that, even on a
1581          * priviliged function, inserting a unicast mismatch filter may not
1582          * catch all traffic in multi PCI function scenarios.)
1583          */
1584         table->eft_unicst_filter_count = 0;
1585         rc = ef10_filter_insert_unicast(enp, mac_addr, filter_flags);
1586         if (all_unicst || (rc != 0)) {
1587                 all_unicst_rc = ef10_filter_insert_all_unicast(enp,
1588                                                     filter_flags);
1589                 if ((rc != 0) && (all_unicst_rc != 0))
1590                         goto fail1;
1591         }
1592
1593         /*
1594          * WORKAROUND_BUG26807 controls firmware support for chained multicast
1595          * filters, and can only be enabled or disabled when the hardware filter
1596          * table is empty.
1597          *
1598          * Chained multicast filters require support from the datapath firmware,
1599          * and may not be available (e.g. low-latency variants or old Huntington
1600          * firmware).
1601          *
1602          * Firmware will reset (FLR) functions which have inserted filters in
1603          * the hardware filter table when the workaround is enabled/disabled.
1604          * Functions without any hardware filters are not reset.
1605          *
1606          * Re-check if the workaround is enabled after adding unicast hardware
1607          * filters. This ensures that encp->enc_bug26807_workaround matches the
1608          * firmware state, and that later changes to enable/disable the
1609          * workaround will result in this function seeing a reset (FLR).
1610          *
1611          * In common-code drivers, we only support multiple PCI function
1612          * scenarios with firmware that supports multicast chaining, so we can
1613          * assume it is enabled for such cases and hence simplify the filter
1614          * insertion logic. Firmware that does not support multicast chaining
1615          * does not support multiple PCI function configurations either, so
1616          * filter insertion is much simpler and the same strategies can still be
1617          * used.
1618          */
1619         if ((rc = ef10_filter_get_workarounds(enp)) != 0)
1620                 goto fail2;
1621
1622         if ((table->eft_using_all_mulcst != all_mulcst) &&
1623             (encp->enc_bug26807_workaround == B_TRUE)) {
1624                 /*
1625                  * Multicast filter chaining is enabled, so traffic that matches
1626                  * more than one multicast filter will be replicated and
1627                  * delivered to multiple recipients.  To avoid this duplicate
1628                  * delivery, remove old multicast filters before inserting new
1629                  * multicast filters.
1630                  */
1631                 ef10_filter_remove_old(enp);
1632         }
1633
1634         /* Insert or renew multicast filters */
1635         if (all_mulcst == B_TRUE) {
1636                 /*
1637                  * Insert the all multicast filter. If that fails, try to insert
1638                  * all of our multicast filters (but without rollback on
1639                  * failure).
1640                  */
1641                 all_mulcst_rc = ef10_filter_insert_all_multicast(enp,
1642                                                             filter_flags);
1643                 if (all_mulcst_rc != 0) {
1644                         rc = ef10_filter_insert_multicast_list(enp, B_TRUE,
1645                             brdcst, addrs, count, filter_flags, B_FALSE);
1646                         if (rc != 0)
1647                                 goto fail3;
1648                 }
1649         } else {
1650                 /*
1651                  * Insert filters for multicast addresses.
1652                  * If any insertion fails, then rollback and try to insert the
1653                  * all multicast filter instead.
1654                  * If that also fails, try to insert all of the multicast
1655                  * filters (but without rollback on failure).
1656                  */
1657                 rc = ef10_filter_insert_multicast_list(enp, mulcst, brdcst,
1658                             addrs, count, filter_flags, B_TRUE);
1659                 if (rc != 0) {
1660                         if ((table->eft_using_all_mulcst == B_FALSE) &&
1661                             (encp->enc_bug26807_workaround == B_TRUE)) {
1662                                 /*
1663                                  * Multicast filter chaining is on, so remove
1664                                  * old filters before inserting the multicast
1665                                  * all filter to avoid duplicate delivery caused
1666                                  * by packets matching multiple filters.
1667                                  */
1668                                 ef10_filter_remove_old(enp);
1669                         }
1670
1671                         rc = ef10_filter_insert_all_multicast(enp,
1672                                                             filter_flags);
1673                         if (rc != 0) {
1674                                 rc = ef10_filter_insert_multicast_list(enp,
1675                                     mulcst, brdcst,
1676                                     addrs, count, filter_flags, B_FALSE);
1677                                 if (rc != 0)
1678                                         goto fail4;
1679                         }
1680                 }
1681         }
1682
1683         if (encp->enc_tunnel_encapsulations_supported != 0) {
1684                 /* Try to insert filters for encapsulated packets. */
1685                 (void) ef10_filter_insert_encap_filters(enp,
1686                                             mulcst || all_mulcst || brdcst,
1687                                             filter_flags);
1688         }
1689
1690         /* Remove old filters which were not renewed */
1691         ef10_filter_remove_old(enp);
1692
1693         /* report if any optional flags were rejected */
1694         if (((all_unicst != B_FALSE) && (all_unicst_rc != 0)) ||
1695             ((all_mulcst != B_FALSE) && (all_mulcst_rc != 0))) {
1696                 rc = ENOTSUP;
1697         }
1698
1699         return (rc);
1700
1701 fail4:
1702         EFSYS_PROBE(fail4);
1703 fail3:
1704         EFSYS_PROBE(fail3);
1705 fail2:
1706         EFSYS_PROBE(fail2);
1707 fail1:
1708         EFSYS_PROBE1(fail1, efx_rc_t, rc);
1709
1710         /* Clear auto old flags */
1711         for (i = 0; i < EFX_ARRAY_SIZE(table->eft_entry); i++) {
1712                 if (ef10_filter_entry_is_auto_old(table, i)) {
1713                         ef10_filter_set_entry_not_auto_old(table, i);
1714                 }
1715         }
1716
1717         return (rc);
1718 }
1719
1720                 void
1721 ef10_filter_get_default_rxq(
1722         __in            efx_nic_t *enp,
1723         __out           efx_rxq_t **erpp,
1724         __out           boolean_t *using_rss)
1725 {
1726         ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
1727
1728         *erpp = table->eft_default_rxq;
1729         *using_rss = table->eft_using_rss;
1730 }
1731
1732
1733                 void
1734 ef10_filter_default_rxq_set(
1735         __in            efx_nic_t *enp,
1736         __in            efx_rxq_t *erp,
1737         __in            boolean_t using_rss)
1738 {
1739         ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
1740
1741 #if EFSYS_OPT_RX_SCALE
1742         EFSYS_ASSERT((using_rss == B_FALSE) ||
1743             (enp->en_rss_context != EF10_RSS_CONTEXT_INVALID));
1744         table->eft_using_rss = using_rss;
1745 #else
1746         EFSYS_ASSERT(using_rss == B_FALSE);
1747         table->eft_using_rss = B_FALSE;
1748 #endif
1749         table->eft_default_rxq = erp;
1750 }
1751
1752                 void
1753 ef10_filter_default_rxq_clear(
1754         __in            efx_nic_t *enp)
1755 {
1756         ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
1757
1758         table->eft_default_rxq = NULL;
1759         table->eft_using_rss = B_FALSE;
1760 }
1761
1762
1763 #endif /* EFSYS_OPT_FILTER */
1764
1765 #endif /* EFX_OPTS_EF10() */