New upstream version 18.08
[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         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         efx_filter_spec_set_eth_local(&spec, EFX_FILTER_SPEC_VID_UNSPEC, addr);
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 fail1;
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 fail1:
1161         EFSYS_PROBE1(fail1, efx_rc_t, rc);
1162         return (rc);
1163 }
1164
1165 static  __checkReturn   efx_rc_t
1166 ef10_filter_insert_all_unicast(
1167         __in                            efx_nic_t *enp,
1168         __in                            efx_filter_flags_t filter_flags)
1169 {
1170         ef10_filter_table_t *eftp = enp->en_filter.ef_ef10_filter_table;
1171         efx_filter_spec_t spec;
1172         efx_rc_t rc;
1173
1174         /* Insert the unknown unicast filter */
1175         efx_filter_spec_init_rx(&spec, EFX_FILTER_PRI_AUTO,
1176             filter_flags,
1177             eftp->eft_default_rxq);
1178         efx_filter_spec_set_uc_def(&spec);
1179         rc = ef10_filter_add_internal(enp, &spec, B_TRUE,
1180             &eftp->eft_unicst_filter_indexes[eftp->eft_unicst_filter_count]);
1181         if (rc != 0)
1182                 goto fail1;
1183
1184         eftp->eft_unicst_filter_count++;
1185         EFSYS_ASSERT(eftp->eft_unicst_filter_count <=
1186                     EFX_EF10_FILTER_UNICAST_FILTERS_MAX);
1187
1188         return (0);
1189
1190 fail1:
1191         EFSYS_PROBE1(fail1, efx_rc_t, rc);
1192         return (rc);
1193 }
1194
1195 static  __checkReturn   efx_rc_t
1196 ef10_filter_insert_multicast_list(
1197         __in                            efx_nic_t *enp,
1198         __in                            boolean_t mulcst,
1199         __in                            boolean_t brdcst,
1200         __in_ecount(6*count)            uint8_t const *addrs,
1201         __in                            uint32_t count,
1202         __in                            efx_filter_flags_t filter_flags,
1203         __in                            boolean_t rollback)
1204 {
1205         ef10_filter_table_t *eftp = enp->en_filter.ef_ef10_filter_table;
1206         efx_filter_spec_t spec;
1207         uint8_t addr[6];
1208         uint32_t i;
1209         uint32_t filter_index;
1210         uint32_t filter_count;
1211         efx_rc_t rc;
1212
1213         if (mulcst == B_FALSE)
1214                 count = 0;
1215
1216         if (count + (brdcst ? 1 : 0) >
1217             EFX_ARRAY_SIZE(eftp->eft_mulcst_filter_indexes)) {
1218                 /* Too many MAC addresses */
1219                 rc = EINVAL;
1220                 goto fail1;
1221         }
1222
1223         /* Insert/renew multicast address list filters */
1224         filter_count = 0;
1225         for (i = 0; i < count; i++) {
1226                 efx_filter_spec_init_rx(&spec,
1227                     EFX_FILTER_PRI_AUTO,
1228                     filter_flags,
1229                     eftp->eft_default_rxq);
1230
1231                 efx_filter_spec_set_eth_local(&spec,
1232                     EFX_FILTER_SPEC_VID_UNSPEC,
1233                     &addrs[i * EFX_MAC_ADDR_LEN]);
1234
1235                 rc = ef10_filter_add_internal(enp, &spec, B_TRUE,
1236                                             &filter_index);
1237
1238                 if (rc == 0) {
1239                         eftp->eft_mulcst_filter_indexes[filter_count] =
1240                                 filter_index;
1241                         filter_count++;
1242                 } else if (rollback == B_TRUE) {
1243                         /* Only stop upon failure if told to rollback */
1244                         goto rollback;
1245                 }
1246
1247         }
1248
1249         if (brdcst == B_TRUE) {
1250                 /* Insert/renew broadcast address filter */
1251                 efx_filter_spec_init_rx(&spec, EFX_FILTER_PRI_AUTO,
1252                     filter_flags,
1253                     eftp->eft_default_rxq);
1254
1255                 EFX_MAC_BROADCAST_ADDR_SET(addr);
1256                 efx_filter_spec_set_eth_local(&spec, EFX_FILTER_SPEC_VID_UNSPEC,
1257                     addr);
1258
1259                 rc = ef10_filter_add_internal(enp, &spec, B_TRUE,
1260                                             &filter_index);
1261
1262                 if (rc == 0) {
1263                         eftp->eft_mulcst_filter_indexes[filter_count] =
1264                                 filter_index;
1265                         filter_count++;
1266                 } else if (rollback == B_TRUE) {
1267                         /* Only stop upon failure if told to rollback */
1268                         goto rollback;
1269                 }
1270         }
1271
1272         eftp->eft_mulcst_filter_count = filter_count;
1273         eftp->eft_using_all_mulcst = B_FALSE;
1274
1275         return (0);
1276
1277 rollback:
1278         /* Remove any filters we have inserted */
1279         i = filter_count;
1280         while (i--) {
1281                 (void) ef10_filter_delete_internal(enp,
1282                     eftp->eft_mulcst_filter_indexes[i]);
1283         }
1284         eftp->eft_mulcst_filter_count = 0;
1285
1286 fail1:
1287         EFSYS_PROBE1(fail1, efx_rc_t, rc);
1288
1289         return (rc);
1290 }
1291
1292 static  __checkReturn   efx_rc_t
1293 ef10_filter_insert_all_multicast(
1294         __in                            efx_nic_t *enp,
1295         __in                            efx_filter_flags_t filter_flags)
1296 {
1297         ef10_filter_table_t *eftp = enp->en_filter.ef_ef10_filter_table;
1298         efx_filter_spec_t spec;
1299         efx_rc_t rc;
1300
1301         /* Insert the unknown multicast filter */
1302         efx_filter_spec_init_rx(&spec, EFX_FILTER_PRI_AUTO,
1303             filter_flags,
1304             eftp->eft_default_rxq);
1305         efx_filter_spec_set_mc_def(&spec);
1306
1307         rc = ef10_filter_add_internal(enp, &spec, B_TRUE,
1308             &eftp->eft_mulcst_filter_indexes[0]);
1309         if (rc != 0)
1310                 goto fail1;
1311
1312         eftp->eft_mulcst_filter_count = 1;
1313         eftp->eft_using_all_mulcst = B_TRUE;
1314
1315         /*
1316          * FIXME: If brdcst == B_FALSE, add a filter to drop broadcast traffic.
1317          */
1318
1319         return (0);
1320
1321 fail1:
1322         EFSYS_PROBE1(fail1, efx_rc_t, rc);
1323
1324         return (rc);
1325 }
1326
1327 typedef struct ef10_filter_encap_entry_s {
1328         uint16_t                ether_type;
1329         efx_tunnel_protocol_t   encap_type;
1330         uint32_t                inner_frame_match;
1331 } ef10_filter_encap_entry_t;
1332
1333 #define EF10_ENCAP_FILTER_ENTRY(ipv, encap_type, inner_frame_match)     \
1334         { EFX_ETHER_TYPE_##ipv, EFX_TUNNEL_PROTOCOL_##encap_type,       \
1335             EFX_FILTER_INNER_FRAME_MATCH_UNKNOWN_##inner_frame_match }
1336
1337 static ef10_filter_encap_entry_t ef10_filter_encap_list[] = {
1338         EF10_ENCAP_FILTER_ENTRY(IPV4, VXLAN, UCAST_DST),
1339         EF10_ENCAP_FILTER_ENTRY(IPV4, VXLAN, MCAST_DST),
1340         EF10_ENCAP_FILTER_ENTRY(IPV6, VXLAN, UCAST_DST),
1341         EF10_ENCAP_FILTER_ENTRY(IPV6, VXLAN, MCAST_DST),
1342
1343         EF10_ENCAP_FILTER_ENTRY(IPV4, GENEVE, UCAST_DST),
1344         EF10_ENCAP_FILTER_ENTRY(IPV4, GENEVE, MCAST_DST),
1345         EF10_ENCAP_FILTER_ENTRY(IPV6, GENEVE, UCAST_DST),
1346         EF10_ENCAP_FILTER_ENTRY(IPV6, GENEVE, MCAST_DST),
1347
1348         EF10_ENCAP_FILTER_ENTRY(IPV4, NVGRE, UCAST_DST),
1349         EF10_ENCAP_FILTER_ENTRY(IPV4, NVGRE, MCAST_DST),
1350         EF10_ENCAP_FILTER_ENTRY(IPV6, NVGRE, UCAST_DST),
1351         EF10_ENCAP_FILTER_ENTRY(IPV6, NVGRE, MCAST_DST),
1352 };
1353
1354 #undef EF10_ENCAP_FILTER_ENTRY
1355
1356 static  __checkReturn   efx_rc_t
1357 ef10_filter_insert_encap_filters(
1358         __in            efx_nic_t *enp,
1359         __in            boolean_t mulcst,
1360         __in            efx_filter_flags_t filter_flags)
1361 {
1362         ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
1363         uint32_t i;
1364         efx_rc_t rc;
1365
1366         EFX_STATIC_ASSERT(EFX_ARRAY_SIZE(ef10_filter_encap_list) <=
1367                             EFX_ARRAY_SIZE(table->eft_encap_filter_indexes));
1368
1369         /*
1370          * On Medford, full-featured firmware can identify packets as being
1371          * tunnel encapsulated, even if no encapsulated packet offloads are in
1372          * use. When packets are identified as such, ordinary filters are not
1373          * applied, only ones specific to encapsulated packets. Hence we need to
1374          * insert filters for encapsulated packets in order to receive them.
1375          *
1376          * Separate filters need to be inserted for each ether type,
1377          * encapsulation type, and inner frame type (unicast or multicast). To
1378          * keep things simple and reduce the number of filters needed, catch-all
1379          * filters for all combinations of types are inserted, even if
1380          * all_unicst or all_mulcst have not been set. (These catch-all filters
1381          * may well, however, fail to insert on unprivileged functions.)
1382          */
1383         table->eft_encap_filter_count = 0;
1384         for (i = 0; i < EFX_ARRAY_SIZE(ef10_filter_encap_list); i++) {
1385                 efx_filter_spec_t spec;
1386                 ef10_filter_encap_entry_t *encap_filter =
1387                         &ef10_filter_encap_list[i];
1388
1389                 /*
1390                  * Skip multicast filters if we've not been asked for
1391                  * any multicast traffic.
1392                  */
1393                 if ((mulcst == B_FALSE) &&
1394                     (encap_filter->inner_frame_match ==
1395                     EFX_FILTER_INNER_FRAME_MATCH_UNKNOWN_MCAST_DST))
1396                         continue;
1397
1398                 efx_filter_spec_init_rx(&spec, EFX_FILTER_PRI_AUTO,
1399                                         filter_flags,
1400                                         table->eft_default_rxq);
1401                 efx_filter_spec_set_ether_type(&spec, encap_filter->ether_type);
1402                 rc = efx_filter_spec_set_encap_type(&spec,
1403                                             encap_filter->encap_type,
1404                                             encap_filter->inner_frame_match);
1405                 if (rc != 0)
1406                         goto fail1;
1407
1408                 rc = ef10_filter_add_internal(enp, &spec, B_TRUE,
1409                             &table->eft_encap_filter_indexes[
1410                                     table->eft_encap_filter_count]);
1411                 if (rc != 0) {
1412                         if (rc != EACCES)
1413                                 goto fail2;
1414                 } else {
1415                         table->eft_encap_filter_count++;
1416                 }
1417         }
1418
1419         return (0);
1420
1421 fail2:
1422         EFSYS_PROBE(fail2);
1423 fail1:
1424         EFSYS_PROBE1(fail1, efx_rc_t, rc);
1425
1426         return (rc);
1427 }
1428
1429 static                  void
1430 ef10_filter_remove_old(
1431         __in            efx_nic_t *enp)
1432 {
1433         ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
1434         uint32_t i;
1435
1436         for (i = 0; i < EFX_ARRAY_SIZE(table->eft_entry); i++) {
1437                 if (ef10_filter_entry_is_auto_old(table, i)) {
1438                         (void) ef10_filter_delete_internal(enp, i);
1439                 }
1440         }
1441 }
1442
1443
1444 static  __checkReturn   efx_rc_t
1445 ef10_filter_get_workarounds(
1446         __in                            efx_nic_t *enp)
1447 {
1448         efx_nic_cfg_t *encp = &enp->en_nic_cfg;
1449         uint32_t implemented = 0;
1450         uint32_t enabled = 0;
1451         efx_rc_t rc;
1452
1453         rc = efx_mcdi_get_workarounds(enp, &implemented, &enabled);
1454         if (rc == 0) {
1455                 /* Check if chained multicast filter support is enabled */
1456                 if (implemented & enabled & MC_CMD_GET_WORKAROUNDS_OUT_BUG26807)
1457                         encp->enc_bug26807_workaround = B_TRUE;
1458                 else
1459                         encp->enc_bug26807_workaround = B_FALSE;
1460         } else if (rc == ENOTSUP) {
1461                 /*
1462                  * Firmware is too old to support GET_WORKAROUNDS, and support
1463                  * for this workaround was implemented later.
1464                  */
1465                 encp->enc_bug26807_workaround = B_FALSE;
1466         } else {
1467                 goto fail1;
1468         }
1469
1470         return (0);
1471
1472 fail1:
1473         EFSYS_PROBE1(fail1, efx_rc_t, rc);
1474
1475         return (rc);
1476
1477 }
1478
1479
1480 /*
1481  * Reconfigure all filters.
1482  * If all_unicst and/or all mulcst filters cannot be applied then
1483  * return ENOTSUP (Note the filters for the specified addresses are
1484  * still applied in this case).
1485  */
1486         __checkReturn   efx_rc_t
1487 ef10_filter_reconfigure(
1488         __in                            efx_nic_t *enp,
1489         __in_ecount(6)                  uint8_t const *mac_addr,
1490         __in                            boolean_t all_unicst,
1491         __in                            boolean_t mulcst,
1492         __in                            boolean_t all_mulcst,
1493         __in                            boolean_t brdcst,
1494         __in_ecount(6*count)            uint8_t const *addrs,
1495         __in                            uint32_t count)
1496 {
1497         efx_nic_cfg_t *encp = &enp->en_nic_cfg;
1498         ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
1499         efx_filter_flags_t filter_flags;
1500         unsigned int i;
1501         efx_rc_t all_unicst_rc = 0;
1502         efx_rc_t all_mulcst_rc = 0;
1503         efx_rc_t rc;
1504
1505         if (table->eft_default_rxq == NULL) {
1506                 /*
1507                  * Filters direct traffic to the default RXQ, and so cannot be
1508                  * inserted until it is available. Any currently configured
1509                  * filters must be removed (ignore errors in case the MC
1510                  * has rebooted, which removes hardware filters).
1511                  */
1512                 for (i = 0; i < table->eft_unicst_filter_count; i++) {
1513                         (void) ef10_filter_delete_internal(enp,
1514                                         table->eft_unicst_filter_indexes[i]);
1515                 }
1516                 table->eft_unicst_filter_count = 0;
1517
1518                 for (i = 0; i < table->eft_mulcst_filter_count; i++) {
1519                         (void) ef10_filter_delete_internal(enp,
1520                                         table->eft_mulcst_filter_indexes[i]);
1521                 }
1522                 table->eft_mulcst_filter_count = 0;
1523
1524                 for (i = 0; i < table->eft_encap_filter_count; i++) {
1525                         (void) ef10_filter_delete_internal(enp,
1526                                         table->eft_encap_filter_indexes[i]);
1527                 }
1528                 table->eft_encap_filter_count = 0;
1529
1530                 return (0);
1531         }
1532
1533         if (table->eft_using_rss)
1534                 filter_flags = EFX_FILTER_FLAG_RX_RSS;
1535         else
1536                 filter_flags = 0;
1537
1538         /* Mark old filters which may need to be removed */
1539         for (i = 0; i < table->eft_unicst_filter_count; i++) {
1540                 ef10_filter_set_entry_auto_old(table,
1541                                         table->eft_unicst_filter_indexes[i]);
1542         }
1543         for (i = 0; i < table->eft_mulcst_filter_count; i++) {
1544                 ef10_filter_set_entry_auto_old(table,
1545                                         table->eft_mulcst_filter_indexes[i]);
1546         }
1547         for (i = 0; i < table->eft_encap_filter_count; i++) {
1548                 ef10_filter_set_entry_auto_old(table,
1549                                         table->eft_encap_filter_indexes[i]);
1550         }
1551
1552         /*
1553          * Insert or renew unicast filters.
1554          *
1555          * Frimware does not perform chaining on unicast filters. As traffic is
1556          * therefore only delivered to the first matching filter, we should
1557          * always insert the specific filter for our MAC address, to try and
1558          * ensure we get that traffic.
1559          *
1560          * (If the filter for our MAC address has already been inserted by
1561          * another function, we won't receive traffic sent to us, even if we
1562          * insert a unicast mismatch filter. To prevent traffic stealing, this
1563          * therefore relies on the privilege model only allowing functions to
1564          * insert filters for their own MAC address unless explicitly given
1565          * additional privileges by the user. This also means that, even on a
1566          * priviliged function, inserting a unicast mismatch filter may not
1567          * catch all traffic in multi PCI function scenarios.)
1568          */
1569         table->eft_unicst_filter_count = 0;
1570         rc = ef10_filter_insert_unicast(enp, mac_addr, filter_flags);
1571         if (all_unicst || (rc != 0)) {
1572                 all_unicst_rc = ef10_filter_insert_all_unicast(enp,
1573                                                     filter_flags);
1574                 if ((rc != 0) && (all_unicst_rc != 0))
1575                         goto fail1;
1576         }
1577
1578         /*
1579          * WORKAROUND_BUG26807 controls firmware support for chained multicast
1580          * filters, and can only be enabled or disabled when the hardware filter
1581          * table is empty.
1582          *
1583          * Chained multicast filters require support from the datapath firmware,
1584          * and may not be available (e.g. low-latency variants or old Huntington
1585          * firmware).
1586          *
1587          * Firmware will reset (FLR) functions which have inserted filters in
1588          * the hardware filter table when the workaround is enabled/disabled.
1589          * Functions without any hardware filters are not reset.
1590          *
1591          * Re-check if the workaround is enabled after adding unicast hardware
1592          * filters. This ensures that encp->enc_bug26807_workaround matches the
1593          * firmware state, and that later changes to enable/disable the
1594          * workaround will result in this function seeing a reset (FLR).
1595          *
1596          * In common-code drivers, we only support multiple PCI function
1597          * scenarios with firmware that supports multicast chaining, so we can
1598          * assume it is enabled for such cases and hence simplify the filter
1599          * insertion logic. Firmware that does not support multicast chaining
1600          * does not support multiple PCI function configurations either, so
1601          * filter insertion is much simpler and the same strategies can still be
1602          * used.
1603          */
1604         if ((rc = ef10_filter_get_workarounds(enp)) != 0)
1605                 goto fail2;
1606
1607         if ((table->eft_using_all_mulcst != all_mulcst) &&
1608             (encp->enc_bug26807_workaround == B_TRUE)) {
1609                 /*
1610                  * Multicast filter chaining is enabled, so traffic that matches
1611                  * more than one multicast filter will be replicated and
1612                  * delivered to multiple recipients.  To avoid this duplicate
1613                  * delivery, remove old multicast filters before inserting new
1614                  * multicast filters.
1615                  */
1616                 ef10_filter_remove_old(enp);
1617         }
1618
1619         /* Insert or renew multicast filters */
1620         if (all_mulcst == B_TRUE) {
1621                 /*
1622                  * Insert the all multicast filter. If that fails, try to insert
1623                  * all of our multicast filters (but without rollback on
1624                  * failure).
1625                  */
1626                 all_mulcst_rc = ef10_filter_insert_all_multicast(enp,
1627                                                             filter_flags);
1628                 if (all_mulcst_rc != 0) {
1629                         rc = ef10_filter_insert_multicast_list(enp, B_TRUE,
1630                             brdcst, addrs, count, filter_flags, B_FALSE);
1631                         if (rc != 0)
1632                                 goto fail3;
1633                 }
1634         } else {
1635                 /*
1636                  * Insert filters for multicast addresses.
1637                  * If any insertion fails, then rollback and try to insert the
1638                  * all multicast filter instead.
1639                  * If that also fails, try to insert all of the multicast
1640                  * filters (but without rollback on failure).
1641                  */
1642                 rc = ef10_filter_insert_multicast_list(enp, mulcst, brdcst,
1643                             addrs, count, filter_flags, B_TRUE);
1644                 if (rc != 0) {
1645                         if ((table->eft_using_all_mulcst == B_FALSE) &&
1646                             (encp->enc_bug26807_workaround == B_TRUE)) {
1647                                 /*
1648                                  * Multicast filter chaining is on, so remove
1649                                  * old filters before inserting the multicast
1650                                  * all filter to avoid duplicate delivery caused
1651                                  * by packets matching multiple filters.
1652                                  */
1653                                 ef10_filter_remove_old(enp);
1654                         }
1655
1656                         rc = ef10_filter_insert_all_multicast(enp,
1657                                                             filter_flags);
1658                         if (rc != 0) {
1659                                 rc = ef10_filter_insert_multicast_list(enp,
1660                                     mulcst, brdcst,
1661                                     addrs, count, filter_flags, B_FALSE);
1662                                 if (rc != 0)
1663                                         goto fail4;
1664                         }
1665                 }
1666         }
1667
1668         if (encp->enc_tunnel_encapsulations_supported != 0) {
1669                 /* Try to insert filters for encapsulated packets. */
1670                 (void) ef10_filter_insert_encap_filters(enp,
1671                                             mulcst || all_mulcst || brdcst,
1672                                             filter_flags);
1673         }
1674
1675         /* Remove old filters which were not renewed */
1676         ef10_filter_remove_old(enp);
1677
1678         /* report if any optional flags were rejected */
1679         if (((all_unicst != B_FALSE) && (all_unicst_rc != 0)) ||
1680             ((all_mulcst != B_FALSE) && (all_mulcst_rc != 0))) {
1681                 rc = ENOTSUP;
1682         }
1683
1684         return (rc);
1685
1686 fail4:
1687         EFSYS_PROBE(fail4);
1688 fail3:
1689         EFSYS_PROBE(fail3);
1690 fail2:
1691         EFSYS_PROBE(fail2);
1692 fail1:
1693         EFSYS_PROBE1(fail1, efx_rc_t, rc);
1694
1695         /* Clear auto old flags */
1696         for (i = 0; i < EFX_ARRAY_SIZE(table->eft_entry); i++) {
1697                 if (ef10_filter_entry_is_auto_old(table, i)) {
1698                         ef10_filter_set_entry_not_auto_old(table, i);
1699                 }
1700         }
1701
1702         return (rc);
1703 }
1704
1705                 void
1706 ef10_filter_get_default_rxq(
1707         __in            efx_nic_t *enp,
1708         __out           efx_rxq_t **erpp,
1709         __out           boolean_t *using_rss)
1710 {
1711         ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
1712
1713         *erpp = table->eft_default_rxq;
1714         *using_rss = table->eft_using_rss;
1715 }
1716
1717
1718                 void
1719 ef10_filter_default_rxq_set(
1720         __in            efx_nic_t *enp,
1721         __in            efx_rxq_t *erp,
1722         __in            boolean_t using_rss)
1723 {
1724         ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
1725
1726 #if EFSYS_OPT_RX_SCALE
1727         EFSYS_ASSERT((using_rss == B_FALSE) ||
1728             (enp->en_rss_context != EF10_RSS_CONTEXT_INVALID));
1729         table->eft_using_rss = using_rss;
1730 #else
1731         EFSYS_ASSERT(using_rss == B_FALSE);
1732         table->eft_using_rss = B_FALSE;
1733 #endif
1734         table->eft_default_rxq = erp;
1735 }
1736
1737                 void
1738 ef10_filter_default_rxq_clear(
1739         __in            efx_nic_t *enp)
1740 {
1741         ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
1742
1743         table->eft_default_rxq = NULL;
1744         table->eft_using_rss = B_FALSE;
1745 }
1746
1747
1748 #endif /* EFSYS_OPT_FILTER */
1749
1750 #endif /* EFSYS_OPT_HUNTINGTON || EFSYS_OPT_MEDFORD || EFSYS_OPT_MEDFORD2 */