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