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