2 * Copyright (c) 2007-2016 Solarflare Communications Inc.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
16 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
18 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
21 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
22 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
24 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 * The views and conclusions contained in the software and documentation are
27 * those of the authors and should not be interpreted as representing official
28 * policies, either expressed or implied, of the FreeBSD Project.
31 #include <sys/cdefs.h>
32 __FBSDID("$FreeBSD$");
37 #if EFSYS_OPT_HUNTINGTON || EFSYS_OPT_MEDFORD || EFSYS_OPT_MEDFORD2
41 #define EFE_SPEC(eftp, index) ((eftp)->eft_entry[(index)].efe_spec)
43 static efx_filter_spec_t *
44 ef10_filter_entry_spec(
45 __in const ef10_filter_table_t *eftp,
46 __in unsigned int index)
48 return ((efx_filter_spec_t *)(EFE_SPEC(eftp, index) &
49 ~(uintptr_t)EFX_EF10_FILTER_FLAGS));
53 ef10_filter_entry_is_busy(
54 __in const ef10_filter_table_t *eftp,
55 __in unsigned int index)
57 if (EFE_SPEC(eftp, index) & EFX_EF10_FILTER_FLAG_BUSY)
64 ef10_filter_entry_is_auto_old(
65 __in const ef10_filter_table_t *eftp,
66 __in unsigned int index)
68 if (EFE_SPEC(eftp, index) & EFX_EF10_FILTER_FLAG_AUTO_OLD)
75 ef10_filter_set_entry(
76 __inout ef10_filter_table_t *eftp,
77 __in unsigned int index,
78 __in_opt const efx_filter_spec_t *efsp)
80 EFE_SPEC(eftp, index) = (uintptr_t)efsp;
84 ef10_filter_set_entry_busy(
85 __inout ef10_filter_table_t *eftp,
86 __in unsigned int index)
88 EFE_SPEC(eftp, index) |= (uintptr_t)EFX_EF10_FILTER_FLAG_BUSY;
92 ef10_filter_set_entry_not_busy(
93 __inout ef10_filter_table_t *eftp,
94 __in unsigned int index)
96 EFE_SPEC(eftp, index) &= ~(uintptr_t)EFX_EF10_FILTER_FLAG_BUSY;
100 ef10_filter_set_entry_auto_old(
101 __inout ef10_filter_table_t *eftp,
102 __in unsigned int index)
104 EFSYS_ASSERT(ef10_filter_entry_spec(eftp, index) != NULL);
105 EFE_SPEC(eftp, index) |= (uintptr_t)EFX_EF10_FILTER_FLAG_AUTO_OLD;
109 ef10_filter_set_entry_not_auto_old(
110 __inout ef10_filter_table_t *eftp,
111 __in unsigned int index)
113 EFE_SPEC(eftp, index) &= ~(uintptr_t)EFX_EF10_FILTER_FLAG_AUTO_OLD;
114 EFSYS_ASSERT(ef10_filter_entry_spec(eftp, index) != NULL);
117 __checkReturn efx_rc_t
122 ef10_filter_table_t *eftp;
124 EFSYS_ASSERT(enp->en_family == EFX_FAMILY_HUNTINGTON ||
125 enp->en_family == EFX_FAMILY_MEDFORD ||
126 enp->en_family == EFX_FAMILY_MEDFORD2);
128 #define MATCH_MASK(match) (EFX_MASK32(match) << EFX_LOW_BIT(match))
129 EFX_STATIC_ASSERT(EFX_FILTER_MATCH_REM_HOST ==
130 MATCH_MASK(MC_CMD_FILTER_OP_EXT_IN_MATCH_SRC_IP));
131 EFX_STATIC_ASSERT(EFX_FILTER_MATCH_LOC_HOST ==
132 MATCH_MASK(MC_CMD_FILTER_OP_EXT_IN_MATCH_DST_IP));
133 EFX_STATIC_ASSERT(EFX_FILTER_MATCH_REM_MAC ==
134 MATCH_MASK(MC_CMD_FILTER_OP_EXT_IN_MATCH_SRC_MAC));
135 EFX_STATIC_ASSERT(EFX_FILTER_MATCH_REM_PORT ==
136 MATCH_MASK(MC_CMD_FILTER_OP_EXT_IN_MATCH_SRC_PORT));
137 EFX_STATIC_ASSERT(EFX_FILTER_MATCH_LOC_MAC ==
138 MATCH_MASK(MC_CMD_FILTER_OP_EXT_IN_MATCH_DST_MAC));
139 EFX_STATIC_ASSERT(EFX_FILTER_MATCH_LOC_PORT ==
140 MATCH_MASK(MC_CMD_FILTER_OP_EXT_IN_MATCH_DST_PORT));
141 EFX_STATIC_ASSERT(EFX_FILTER_MATCH_ETHER_TYPE ==
142 MATCH_MASK(MC_CMD_FILTER_OP_EXT_IN_MATCH_ETHER_TYPE));
143 EFX_STATIC_ASSERT(EFX_FILTER_MATCH_INNER_VID ==
144 MATCH_MASK(MC_CMD_FILTER_OP_EXT_IN_MATCH_INNER_VLAN));
145 EFX_STATIC_ASSERT(EFX_FILTER_MATCH_OUTER_VID ==
146 MATCH_MASK(MC_CMD_FILTER_OP_EXT_IN_MATCH_OUTER_VLAN));
147 EFX_STATIC_ASSERT(EFX_FILTER_MATCH_IP_PROTO ==
148 MATCH_MASK(MC_CMD_FILTER_OP_EXT_IN_MATCH_IP_PROTO));
149 EFX_STATIC_ASSERT(EFX_FILTER_MATCH_IFRM_UNKNOWN_MCAST_DST ==
150 MATCH_MASK(MC_CMD_FILTER_OP_EXT_IN_MATCH_IFRM_UNKNOWN_MCAST_DST));
151 EFX_STATIC_ASSERT(EFX_FILTER_MATCH_IFRM_UNKNOWN_UCAST_DST ==
152 MATCH_MASK(MC_CMD_FILTER_OP_EXT_IN_MATCH_IFRM_UNKNOWN_UCAST_DST));
153 EFX_STATIC_ASSERT(EFX_FILTER_MATCH_UNKNOWN_MCAST_DST ==
154 MATCH_MASK(MC_CMD_FILTER_OP_EXT_IN_MATCH_UNKNOWN_MCAST_DST));
155 EFX_STATIC_ASSERT((uint32_t)EFX_FILTER_MATCH_UNKNOWN_UCAST_DST ==
156 MATCH_MASK(MC_CMD_FILTER_OP_EXT_IN_MATCH_UNKNOWN_UCAST_DST));
159 EFSYS_KMEM_ALLOC(enp->en_esip, sizeof (ef10_filter_table_t), eftp);
166 enp->en_filter.ef_ef10_filter_table = eftp;
171 EFSYS_PROBE1(fail1, efx_rc_t, rc);
180 EFSYS_ASSERT(enp->en_family == EFX_FAMILY_HUNTINGTON ||
181 enp->en_family == EFX_FAMILY_MEDFORD ||
182 enp->en_family == EFX_FAMILY_MEDFORD2);
184 if (enp->en_filter.ef_ef10_filter_table != NULL) {
185 EFSYS_KMEM_FREE(enp->en_esip, sizeof (ef10_filter_table_t),
186 enp->en_filter.ef_ef10_filter_table);
190 static __checkReturn efx_rc_t
191 efx_mcdi_filter_op_add(
193 __in efx_filter_spec_t *spec,
194 __in unsigned int filter_op,
195 __inout ef10_filter_handle_t *handle)
198 uint8_t payload[MAX(MC_CMD_FILTER_OP_EXT_IN_LEN,
199 MC_CMD_FILTER_OP_EXT_OUT_LEN)];
202 memset(payload, 0, sizeof (payload));
203 req.emr_cmd = MC_CMD_FILTER_OP;
204 req.emr_in_buf = payload;
205 req.emr_in_length = MC_CMD_FILTER_OP_EXT_IN_LEN;
206 req.emr_out_buf = payload;
207 req.emr_out_length = MC_CMD_FILTER_OP_EXT_OUT_LEN;
210 case MC_CMD_FILTER_OP_IN_OP_REPLACE:
211 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_HANDLE_LO,
213 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_HANDLE_HI,
216 case MC_CMD_FILTER_OP_IN_OP_INSERT:
217 case MC_CMD_FILTER_OP_IN_OP_SUBSCRIBE:
218 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_OP, filter_op);
226 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_PORT_ID,
227 EVB_PORT_ID_ASSIGNED);
228 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_MATCH_FIELDS,
229 spec->efs_match_flags);
230 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_RX_DEST,
231 MC_CMD_FILTER_OP_EXT_IN_RX_DEST_HOST);
232 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_RX_QUEUE,
235 #if EFSYS_OPT_RX_SCALE
236 if (spec->efs_flags & EFX_FILTER_FLAG_RX_RSS) {
237 uint32_t rss_context;
239 if (spec->efs_rss_context == EFX_RSS_CONTEXT_DEFAULT)
240 rss_context = enp->en_rss_context;
242 rss_context = spec->efs_rss_context;
243 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_RX_CONTEXT,
248 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_RX_MODE,
249 spec->efs_flags & EFX_FILTER_FLAG_RX_RSS ?
250 MC_CMD_FILTER_OP_EXT_IN_RX_MODE_RSS :
251 MC_CMD_FILTER_OP_EXT_IN_RX_MODE_SIMPLE);
252 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_TX_DEST,
253 MC_CMD_FILTER_OP_EXT_IN_TX_DEST_DEFAULT);
255 if (filter_op != MC_CMD_FILTER_OP_IN_OP_REPLACE) {
257 * NOTE: Unlike most MCDI requests, the filter fields
258 * are presented in network (big endian) byte order.
260 memcpy(MCDI_IN2(req, uint8_t, FILTER_OP_EXT_IN_SRC_MAC),
261 spec->efs_rem_mac, EFX_MAC_ADDR_LEN);
262 memcpy(MCDI_IN2(req, uint8_t, FILTER_OP_EXT_IN_DST_MAC),
263 spec->efs_loc_mac, EFX_MAC_ADDR_LEN);
265 MCDI_IN_SET_WORD(req, FILTER_OP_EXT_IN_SRC_PORT,
266 __CPU_TO_BE_16(spec->efs_rem_port));
267 MCDI_IN_SET_WORD(req, FILTER_OP_EXT_IN_DST_PORT,
268 __CPU_TO_BE_16(spec->efs_loc_port));
270 MCDI_IN_SET_WORD(req, FILTER_OP_EXT_IN_ETHER_TYPE,
271 __CPU_TO_BE_16(spec->efs_ether_type));
273 MCDI_IN_SET_WORD(req, FILTER_OP_EXT_IN_INNER_VLAN,
274 __CPU_TO_BE_16(spec->efs_inner_vid));
275 MCDI_IN_SET_WORD(req, FILTER_OP_EXT_IN_OUTER_VLAN,
276 __CPU_TO_BE_16(spec->efs_outer_vid));
278 /* IP protocol (in low byte, high byte is zero) */
279 MCDI_IN_SET_BYTE(req, FILTER_OP_EXT_IN_IP_PROTO,
282 EFX_STATIC_ASSERT(sizeof (spec->efs_rem_host) ==
283 MC_CMD_FILTER_OP_EXT_IN_SRC_IP_LEN);
284 EFX_STATIC_ASSERT(sizeof (spec->efs_loc_host) ==
285 MC_CMD_FILTER_OP_EXT_IN_DST_IP_LEN);
287 memcpy(MCDI_IN2(req, uint8_t, FILTER_OP_EXT_IN_SRC_IP),
288 &spec->efs_rem_host.eo_byte[0],
289 MC_CMD_FILTER_OP_EXT_IN_SRC_IP_LEN);
290 memcpy(MCDI_IN2(req, uint8_t, FILTER_OP_EXT_IN_DST_IP),
291 &spec->efs_loc_host.eo_byte[0],
292 MC_CMD_FILTER_OP_EXT_IN_DST_IP_LEN);
295 * On Medford, filters for encapsulated packets match based on
296 * the ether type and IP protocol in the outer frame. In
297 * addition we need to fill in the VNI or VSID type field.
299 switch (spec->efs_encap_type) {
300 case EFX_TUNNEL_PROTOCOL_NONE:
302 case EFX_TUNNEL_PROTOCOL_VXLAN:
303 case EFX_TUNNEL_PROTOCOL_GENEVE:
304 MCDI_IN_POPULATE_DWORD_1(req,
305 FILTER_OP_EXT_IN_VNI_OR_VSID,
306 FILTER_OP_EXT_IN_VNI_TYPE,
307 spec->efs_encap_type == EFX_TUNNEL_PROTOCOL_VXLAN ?
308 MC_CMD_FILTER_OP_EXT_IN_VNI_TYPE_VXLAN :
309 MC_CMD_FILTER_OP_EXT_IN_VNI_TYPE_GENEVE);
311 case EFX_TUNNEL_PROTOCOL_NVGRE:
312 MCDI_IN_POPULATE_DWORD_1(req,
313 FILTER_OP_EXT_IN_VNI_OR_VSID,
314 FILTER_OP_EXT_IN_VSID_TYPE,
315 MC_CMD_FILTER_OP_EXT_IN_VSID_TYPE_NVGRE);
324 efx_mcdi_execute(enp, &req);
326 if (req.emr_rc != 0) {
331 if (req.emr_out_length_used < MC_CMD_FILTER_OP_EXT_OUT_LEN) {
336 handle->efh_lo = MCDI_OUT_DWORD(req, FILTER_OP_EXT_OUT_HANDLE_LO);
337 handle->efh_hi = MCDI_OUT_DWORD(req, FILTER_OP_EXT_OUT_HANDLE_HI);
348 EFSYS_PROBE1(fail1, efx_rc_t, rc);
354 static __checkReturn efx_rc_t
355 efx_mcdi_filter_op_delete(
357 __in unsigned int filter_op,
358 __inout ef10_filter_handle_t *handle)
361 uint8_t payload[MAX(MC_CMD_FILTER_OP_EXT_IN_LEN,
362 MC_CMD_FILTER_OP_EXT_OUT_LEN)];
365 memset(payload, 0, sizeof (payload));
366 req.emr_cmd = MC_CMD_FILTER_OP;
367 req.emr_in_buf = payload;
368 req.emr_in_length = MC_CMD_FILTER_OP_EXT_IN_LEN;
369 req.emr_out_buf = payload;
370 req.emr_out_length = MC_CMD_FILTER_OP_EXT_OUT_LEN;
373 case MC_CMD_FILTER_OP_IN_OP_REMOVE:
374 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_OP,
375 MC_CMD_FILTER_OP_IN_OP_REMOVE);
377 case MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE:
378 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_OP,
379 MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE);
387 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_HANDLE_LO, handle->efh_lo);
388 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_HANDLE_HI, handle->efh_hi);
390 efx_mcdi_execute_quiet(enp, &req);
392 if (req.emr_rc != 0) {
397 if (req.emr_out_length_used < MC_CMD_FILTER_OP_EXT_OUT_LEN) {
410 EFSYS_PROBE1(fail1, efx_rc_t, rc);
415 static __checkReturn boolean_t
417 __in const efx_filter_spec_t *left,
418 __in const efx_filter_spec_t *right)
420 /* FIXME: Consider rx vs tx filters (look at efs_flags) */
421 if (left->efs_match_flags != right->efs_match_flags)
423 if (!EFX_OWORD_IS_EQUAL(left->efs_rem_host, right->efs_rem_host))
425 if (!EFX_OWORD_IS_EQUAL(left->efs_loc_host, right->efs_loc_host))
427 if (memcmp(left->efs_rem_mac, right->efs_rem_mac, EFX_MAC_ADDR_LEN))
429 if (memcmp(left->efs_loc_mac, right->efs_loc_mac, EFX_MAC_ADDR_LEN))
431 if (left->efs_rem_port != right->efs_rem_port)
433 if (left->efs_loc_port != right->efs_loc_port)
435 if (left->efs_inner_vid != right->efs_inner_vid)
437 if (left->efs_outer_vid != right->efs_outer_vid)
439 if (left->efs_ether_type != right->efs_ether_type)
441 if (left->efs_ip_proto != right->efs_ip_proto)
443 if (left->efs_encap_type != right->efs_encap_type)
450 static __checkReturn boolean_t
451 ef10_filter_same_dest(
452 __in const efx_filter_spec_t *left,
453 __in const efx_filter_spec_t *right)
455 if ((left->efs_flags & EFX_FILTER_FLAG_RX_RSS) &&
456 (right->efs_flags & EFX_FILTER_FLAG_RX_RSS)) {
457 if (left->efs_rss_context == right->efs_rss_context)
459 } else if ((~(left->efs_flags) & EFX_FILTER_FLAG_RX_RSS) &&
460 (~(right->efs_flags) & EFX_FILTER_FLAG_RX_RSS)) {
461 if (left->efs_dmaq_id == right->efs_dmaq_id)
467 static __checkReturn uint32_t
469 __in efx_filter_spec_t *spec)
471 EFX_STATIC_ASSERT((sizeof (efx_filter_spec_t) % sizeof (uint32_t))
473 EFX_STATIC_ASSERT((EFX_FIELD_OFFSET(efx_filter_spec_t, efs_outer_vid) %
474 sizeof (uint32_t)) == 0);
477 * As the area of the efx_filter_spec_t we need to hash is DWORD
478 * aligned and an exact number of DWORDs in size we can use the
479 * optimised efx_hash_dwords() rather than efx_hash_bytes()
481 return (efx_hash_dwords((const uint32_t *)&spec->efs_outer_vid,
482 (sizeof (efx_filter_spec_t) -
483 EFX_FIELD_OFFSET(efx_filter_spec_t, efs_outer_vid)) /
484 sizeof (uint32_t), 0));
488 * Decide whether a filter should be exclusive or else should allow
489 * delivery to additional recipients. Currently we decide that
490 * filters for specific local unicast MAC and IP addresses are
493 static __checkReturn boolean_t
494 ef10_filter_is_exclusive(
495 __in efx_filter_spec_t *spec)
497 if ((spec->efs_match_flags & EFX_FILTER_MATCH_LOC_MAC) &&
498 !EFX_MAC_ADDR_IS_MULTICAST(spec->efs_loc_mac))
501 if ((spec->efs_match_flags &
502 (EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_LOC_HOST)) ==
503 (EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_LOC_HOST)) {
504 if ((spec->efs_ether_type == EFX_ETHER_TYPE_IPV4) &&
505 ((spec->efs_loc_host.eo_u8[0] & 0xf) != 0xe))
507 if ((spec->efs_ether_type == EFX_ETHER_TYPE_IPV6) &&
508 (spec->efs_loc_host.eo_u8[0] != 0xff))
515 __checkReturn efx_rc_t
520 efx_filter_spec_t *spec;
521 ef10_filter_table_t *eftp = enp->en_filter.ef_ef10_filter_table;
523 efsys_lock_state_t state;
526 EFSYS_ASSERT(enp->en_family == EFX_FAMILY_HUNTINGTON ||
527 enp->en_family == EFX_FAMILY_MEDFORD ||
528 enp->en_family == EFX_FAMILY_MEDFORD2);
530 for (tbl_id = 0; tbl_id < EFX_EF10_FILTER_TBL_ROWS; tbl_id++) {
532 EFSYS_LOCK(enp->en_eslp, state);
534 spec = ef10_filter_entry_spec(eftp, tbl_id);
537 } else if (ef10_filter_entry_is_busy(eftp, tbl_id)) {
538 /* Ignore busy entries. */
541 ef10_filter_set_entry_busy(eftp, tbl_id);
545 EFSYS_UNLOCK(enp->en_eslp, state);
547 if (restoring == B_FALSE)
550 if (ef10_filter_is_exclusive(spec)) {
551 rc = efx_mcdi_filter_op_add(enp, spec,
552 MC_CMD_FILTER_OP_IN_OP_INSERT,
553 &eftp->eft_entry[tbl_id].efe_handle);
555 rc = efx_mcdi_filter_op_add(enp, spec,
556 MC_CMD_FILTER_OP_IN_OP_SUBSCRIBE,
557 &eftp->eft_entry[tbl_id].efe_handle);
563 EFSYS_LOCK(enp->en_eslp, state);
565 ef10_filter_set_entry_not_busy(eftp, tbl_id);
567 EFSYS_UNLOCK(enp->en_eslp, state);
573 EFSYS_PROBE1(fail1, efx_rc_t, rc);
579 * An arbitrary search limit for the software hash table. As per the linux net
582 #define EF10_FILTER_SEARCH_LIMIT 200
584 static __checkReturn efx_rc_t
585 ef10_filter_add_internal(
587 __inout efx_filter_spec_t *spec,
588 __in boolean_t may_replace,
589 __out_opt uint32_t *filter_id)
592 ef10_filter_table_t *eftp = enp->en_filter.ef_ef10_filter_table;
593 efx_filter_spec_t *saved_spec;
597 boolean_t replacing = B_FALSE;
599 efsys_lock_state_t state;
600 boolean_t locked = B_FALSE;
602 EFSYS_ASSERT(enp->en_family == EFX_FAMILY_HUNTINGTON ||
603 enp->en_family == EFX_FAMILY_MEDFORD ||
604 enp->en_family == EFX_FAMILY_MEDFORD2);
606 hash = ef10_filter_hash(spec);
609 * FIXME: Add support for inserting filters of different priorities
610 * and removing lower priority multicast filters (bug 42378)
614 * Find any existing filters with the same match tuple or
615 * else a free slot to insert at. If any of them are busy,
616 * we have to wait and retry.
621 EFSYS_LOCK(enp->en_eslp, state);
625 i = (hash + depth) & (EFX_EF10_FILTER_TBL_ROWS - 1);
626 saved_spec = ef10_filter_entry_spec(eftp, i);
632 } else if (ef10_filter_equal(spec, saved_spec)) {
633 if (ef10_filter_entry_is_busy(eftp, i))
635 if (saved_spec->efs_priority
636 == EFX_FILTER_PRI_AUTO) {
639 } else if (ef10_filter_is_exclusive(spec)) {
653 * Once we reach the maximum search depth, use
654 * the first suitable slot or return EBUSY if
657 if (depth == EF10_FILTER_SEARCH_LIMIT) {
666 EFSYS_UNLOCK(enp->en_eslp, state);
672 * Create a software table entry if necessary, and mark it
673 * busy. We might yet fail to insert, but any attempt to
674 * insert a conflicting filter while we're waiting for the
675 * firmware must find the busy entry.
677 saved_spec = ef10_filter_entry_spec(eftp, ins_index);
679 if (saved_spec->efs_priority == EFX_FILTER_PRI_AUTO) {
680 /* This is a filter we are refreshing */
681 ef10_filter_set_entry_not_auto_old(eftp, ins_index);
687 EFSYS_KMEM_ALLOC(enp->en_esip, sizeof (*spec), saved_spec);
693 ef10_filter_set_entry(eftp, ins_index, saved_spec);
695 ef10_filter_set_entry_busy(eftp, ins_index);
697 EFSYS_UNLOCK(enp->en_eslp, state);
701 * On replacing the filter handle may change after after a successful
705 rc = efx_mcdi_filter_op_add(enp, spec,
706 MC_CMD_FILTER_OP_IN_OP_REPLACE,
707 &eftp->eft_entry[ins_index].efe_handle);
708 } else if (ef10_filter_is_exclusive(spec)) {
709 rc = efx_mcdi_filter_op_add(enp, spec,
710 MC_CMD_FILTER_OP_IN_OP_INSERT,
711 &eftp->eft_entry[ins_index].efe_handle);
713 rc = efx_mcdi_filter_op_add(enp, spec,
714 MC_CMD_FILTER_OP_IN_OP_SUBSCRIBE,
715 &eftp->eft_entry[ins_index].efe_handle);
721 EFSYS_LOCK(enp->en_eslp, state);
725 /* Update the fields that may differ */
726 saved_spec->efs_priority = spec->efs_priority;
727 saved_spec->efs_flags = spec->efs_flags;
728 saved_spec->efs_rss_context = spec->efs_rss_context;
729 saved_spec->efs_dmaq_id = spec->efs_dmaq_id;
732 ef10_filter_set_entry_not_busy(eftp, ins_index);
736 EFSYS_UNLOCK(enp->en_eslp, state);
740 *filter_id = ins_index;
748 EFSYS_KMEM_FREE(enp->en_esip, sizeof (*spec), saved_spec);
751 ef10_filter_set_entry_not_busy(eftp, ins_index);
752 ef10_filter_set_entry(eftp, ins_index, NULL);
761 EFSYS_PROBE1(fail1, efx_rc_t, rc);
764 EFSYS_UNLOCK(enp->en_eslp, state);
769 __checkReturn efx_rc_t
772 __inout efx_filter_spec_t *spec,
773 __in boolean_t may_replace)
777 rc = ef10_filter_add_internal(enp, spec, may_replace, NULL);
784 EFSYS_PROBE1(fail1, efx_rc_t, rc);
790 static __checkReturn efx_rc_t
791 ef10_filter_delete_internal(
793 __in uint32_t filter_id)
796 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
797 efx_filter_spec_t *spec;
798 efsys_lock_state_t state;
799 uint32_t filter_idx = filter_id % EFX_EF10_FILTER_TBL_ROWS;
802 * Find the software table entry and mark it busy. Don't
803 * remove it yet; any attempt to update while we're waiting
804 * for the firmware must find the busy entry.
806 * FIXME: What if the busy flag is never cleared?
808 EFSYS_LOCK(enp->en_eslp, state);
809 while (ef10_filter_entry_is_busy(table, filter_idx)) {
810 EFSYS_UNLOCK(enp->en_eslp, state);
812 EFSYS_LOCK(enp->en_eslp, state);
814 if ((spec = ef10_filter_entry_spec(table, filter_idx)) != NULL) {
815 ef10_filter_set_entry_busy(table, filter_idx);
817 EFSYS_UNLOCK(enp->en_eslp, state);
825 * Try to remove the hardware filter. This may fail if the MC has
826 * rebooted (which frees all hardware filter resources).
828 if (ef10_filter_is_exclusive(spec)) {
829 rc = efx_mcdi_filter_op_delete(enp,
830 MC_CMD_FILTER_OP_IN_OP_REMOVE,
831 &table->eft_entry[filter_idx].efe_handle);
833 rc = efx_mcdi_filter_op_delete(enp,
834 MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE,
835 &table->eft_entry[filter_idx].efe_handle);
838 /* Free the software table entry */
839 EFSYS_LOCK(enp->en_eslp, state);
840 ef10_filter_set_entry_not_busy(table, filter_idx);
841 ef10_filter_set_entry(table, filter_idx, NULL);
842 EFSYS_UNLOCK(enp->en_eslp, state);
844 EFSYS_KMEM_FREE(enp->en_esip, sizeof (*spec), spec);
846 /* Check result of hardware filter removal */
856 EFSYS_PROBE1(fail1, efx_rc_t, rc);
861 __checkReturn efx_rc_t
864 __inout efx_filter_spec_t *spec)
867 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
868 efx_filter_spec_t *saved_spec;
872 efsys_lock_state_t state;
873 boolean_t locked = B_FALSE;
875 EFSYS_ASSERT(enp->en_family == EFX_FAMILY_HUNTINGTON ||
876 enp->en_family == EFX_FAMILY_MEDFORD ||
877 enp->en_family == EFX_FAMILY_MEDFORD2);
879 hash = ef10_filter_hash(spec);
881 EFSYS_LOCK(enp->en_eslp, state);
886 i = (hash + depth) & (EFX_EF10_FILTER_TBL_ROWS - 1);
887 saved_spec = ef10_filter_entry_spec(table, i);
888 if (saved_spec && ef10_filter_equal(spec, saved_spec) &&
889 ef10_filter_same_dest(spec, saved_spec)) {
892 if (depth == EF10_FILTER_SEARCH_LIMIT) {
899 EFSYS_UNLOCK(enp->en_eslp, state);
902 rc = ef10_filter_delete_internal(enp, i);
912 EFSYS_PROBE1(fail1, efx_rc_t, rc);
915 EFSYS_UNLOCK(enp->en_eslp, state);
920 static __checkReturn efx_rc_t
921 efx_mcdi_get_parser_disp_info(
923 __out_ecount(buffer_length) uint32_t *buffer,
924 __in size_t buffer_length,
925 __out size_t *list_lengthp)
928 uint8_t payload[MAX(MC_CMD_GET_PARSER_DISP_INFO_IN_LEN,
929 MC_CMD_GET_PARSER_DISP_INFO_OUT_LENMAX)];
930 size_t matches_count;
934 (void) memset(payload, 0, sizeof (payload));
935 req.emr_cmd = MC_CMD_GET_PARSER_DISP_INFO;
936 req.emr_in_buf = payload;
937 req.emr_in_length = MC_CMD_GET_PARSER_DISP_INFO_IN_LEN;
938 req.emr_out_buf = payload;
939 req.emr_out_length = MC_CMD_GET_PARSER_DISP_INFO_OUT_LENMAX;
941 MCDI_IN_SET_DWORD(req, GET_PARSER_DISP_INFO_OUT_OP,
942 MC_CMD_GET_PARSER_DISP_INFO_IN_OP_GET_SUPPORTED_RX_MATCHES);
944 efx_mcdi_execute(enp, &req);
946 if (req.emr_rc != 0) {
951 matches_count = MCDI_OUT_DWORD(req,
952 GET_PARSER_DISP_INFO_OUT_NUM_SUPPORTED_MATCHES);
954 if (req.emr_out_length_used <
955 MC_CMD_GET_PARSER_DISP_INFO_OUT_LEN(matches_count)) {
960 *list_lengthp = matches_count;
962 if (buffer_length < matches_count) {
968 * Check that the elements in the list in the MCDI response are the size
969 * we expect, so we can just copy them directly. Any conversion of the
970 * flags is handled by the caller.
972 EFX_STATIC_ASSERT(sizeof (uint32_t) ==
973 MC_CMD_GET_PARSER_DISP_INFO_OUT_SUPPORTED_MATCHES_LEN);
975 list_size = matches_count *
976 MC_CMD_GET_PARSER_DISP_INFO_OUT_SUPPORTED_MATCHES_LEN;
978 MCDI_OUT2(req, uint32_t,
979 GET_PARSER_DISP_INFO_OUT_SUPPORTED_MATCHES),
989 EFSYS_PROBE1(fail1, efx_rc_t, rc);
994 __checkReturn efx_rc_t
995 ef10_filter_supported_filters(
997 __out_ecount(buffer_length) uint32_t *buffer,
998 __in size_t buffer_length,
999 __out size_t *list_lengthp)
1002 size_t mcdi_list_length;
1006 efx_filter_match_flags_t all_filter_flags =
1007 (EFX_FILTER_MATCH_REM_HOST | EFX_FILTER_MATCH_LOC_HOST |
1008 EFX_FILTER_MATCH_REM_MAC | EFX_FILTER_MATCH_REM_PORT |
1009 EFX_FILTER_MATCH_LOC_MAC | EFX_FILTER_MATCH_LOC_PORT |
1010 EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_INNER_VID |
1011 EFX_FILTER_MATCH_OUTER_VID | EFX_FILTER_MATCH_IP_PROTO |
1012 EFX_FILTER_MATCH_UNKNOWN_MCAST_DST |
1013 EFX_FILTER_MATCH_UNKNOWN_UCAST_DST);
1015 rc = efx_mcdi_get_parser_disp_info(enp, buffer, buffer_length,
1019 /* Pass through mcdi_list_length for the list length */
1020 *list_lengthp = mcdi_list_length;
1026 * The static assertions in ef10_filter_init() ensure that the values of
1027 * the EFX_FILTER_MATCH flags match those used by MCDI, so they don't
1028 * need to be converted.
1030 * In case support is added to MCDI for additional flags, remove any
1031 * matches from the list which include flags we don't support. The order
1032 * of the matches is preserved as they are ordered from highest to
1035 EFSYS_ASSERT(mcdi_list_length <= buffer_length);
1037 for (i = 0; i < mcdi_list_length; i++) {
1038 if ((buffer[i] & ~all_filter_flags) == 0) {
1039 buffer[list_length] = buffer[i];
1044 *list_lengthp = list_length;
1049 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1054 static __checkReturn efx_rc_t
1055 ef10_filter_insert_unicast(
1056 __in efx_nic_t *enp,
1057 __in_ecount(6) uint8_t const *addr,
1058 __in efx_filter_flags_t filter_flags)
1060 ef10_filter_table_t *eftp = enp->en_filter.ef_ef10_filter_table;
1061 efx_filter_spec_t spec;
1064 /* Insert the filter for the local station address */
1065 efx_filter_spec_init_rx(&spec, EFX_FILTER_PRI_AUTO,
1067 eftp->eft_default_rxq);
1068 efx_filter_spec_set_eth_local(&spec, EFX_FILTER_SPEC_VID_UNSPEC, addr);
1070 rc = ef10_filter_add_internal(enp, &spec, B_TRUE,
1071 &eftp->eft_unicst_filter_indexes[eftp->eft_unicst_filter_count]);
1075 eftp->eft_unicst_filter_count++;
1076 EFSYS_ASSERT(eftp->eft_unicst_filter_count <=
1077 EFX_EF10_FILTER_UNICAST_FILTERS_MAX);
1082 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1086 static __checkReturn efx_rc_t
1087 ef10_filter_insert_all_unicast(
1088 __in efx_nic_t *enp,
1089 __in efx_filter_flags_t filter_flags)
1091 ef10_filter_table_t *eftp = enp->en_filter.ef_ef10_filter_table;
1092 efx_filter_spec_t spec;
1095 /* Insert the unknown unicast filter */
1096 efx_filter_spec_init_rx(&spec, EFX_FILTER_PRI_AUTO,
1098 eftp->eft_default_rxq);
1099 efx_filter_spec_set_uc_def(&spec);
1100 rc = ef10_filter_add_internal(enp, &spec, B_TRUE,
1101 &eftp->eft_unicst_filter_indexes[eftp->eft_unicst_filter_count]);
1105 eftp->eft_unicst_filter_count++;
1106 EFSYS_ASSERT(eftp->eft_unicst_filter_count <=
1107 EFX_EF10_FILTER_UNICAST_FILTERS_MAX);
1112 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1116 static __checkReturn efx_rc_t
1117 ef10_filter_insert_multicast_list(
1118 __in efx_nic_t *enp,
1119 __in boolean_t mulcst,
1120 __in boolean_t brdcst,
1121 __in_ecount(6*count) uint8_t const *addrs,
1122 __in uint32_t count,
1123 __in efx_filter_flags_t filter_flags,
1124 __in boolean_t rollback)
1126 ef10_filter_table_t *eftp = enp->en_filter.ef_ef10_filter_table;
1127 efx_filter_spec_t spec;
1130 uint32_t filter_index;
1131 uint32_t filter_count;
1134 if (mulcst == B_FALSE)
1137 if (count + (brdcst ? 1 : 0) >
1138 EFX_ARRAY_SIZE(eftp->eft_mulcst_filter_indexes)) {
1139 /* Too many MAC addresses */
1144 /* Insert/renew multicast address list filters */
1146 for (i = 0; i < count; i++) {
1147 efx_filter_spec_init_rx(&spec,
1148 EFX_FILTER_PRI_AUTO,
1150 eftp->eft_default_rxq);
1152 efx_filter_spec_set_eth_local(&spec,
1153 EFX_FILTER_SPEC_VID_UNSPEC,
1154 &addrs[i * EFX_MAC_ADDR_LEN]);
1156 rc = ef10_filter_add_internal(enp, &spec, B_TRUE,
1160 eftp->eft_mulcst_filter_indexes[filter_count] =
1163 } else if (rollback == B_TRUE) {
1164 /* Only stop upon failure if told to rollback */
1170 if (brdcst == B_TRUE) {
1171 /* Insert/renew broadcast address filter */
1172 efx_filter_spec_init_rx(&spec, EFX_FILTER_PRI_AUTO,
1174 eftp->eft_default_rxq);
1176 EFX_MAC_BROADCAST_ADDR_SET(addr);
1177 efx_filter_spec_set_eth_local(&spec, EFX_FILTER_SPEC_VID_UNSPEC,
1180 rc = ef10_filter_add_internal(enp, &spec, B_TRUE,
1184 eftp->eft_mulcst_filter_indexes[filter_count] =
1187 } else if (rollback == B_TRUE) {
1188 /* Only stop upon failure if told to rollback */
1193 eftp->eft_mulcst_filter_count = filter_count;
1194 eftp->eft_using_all_mulcst = B_FALSE;
1199 /* Remove any filters we have inserted */
1202 (void) ef10_filter_delete_internal(enp,
1203 eftp->eft_mulcst_filter_indexes[i]);
1205 eftp->eft_mulcst_filter_count = 0;
1208 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1213 static __checkReturn efx_rc_t
1214 ef10_filter_insert_all_multicast(
1215 __in efx_nic_t *enp,
1216 __in efx_filter_flags_t filter_flags)
1218 ef10_filter_table_t *eftp = enp->en_filter.ef_ef10_filter_table;
1219 efx_filter_spec_t spec;
1222 /* Insert the unknown multicast filter */
1223 efx_filter_spec_init_rx(&spec, EFX_FILTER_PRI_AUTO,
1225 eftp->eft_default_rxq);
1226 efx_filter_spec_set_mc_def(&spec);
1228 rc = ef10_filter_add_internal(enp, &spec, B_TRUE,
1229 &eftp->eft_mulcst_filter_indexes[0]);
1233 eftp->eft_mulcst_filter_count = 1;
1234 eftp->eft_using_all_mulcst = B_TRUE;
1237 * FIXME: If brdcst == B_FALSE, add a filter to drop broadcast traffic.
1243 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1248 typedef struct ef10_filter_encap_entry_s {
1249 uint16_t ether_type;
1250 efx_tunnel_protocol_t encap_type;
1251 uint32_t inner_frame_match;
1252 } ef10_filter_encap_entry_t;
1254 #define EF10_ENCAP_FILTER_ENTRY(ipv, encap_type, inner_frame_match) \
1255 { EFX_ETHER_TYPE_##ipv, EFX_TUNNEL_PROTOCOL_##encap_type, \
1256 EFX_FILTER_INNER_FRAME_MATCH_UNKNOWN_##inner_frame_match }
1258 static ef10_filter_encap_entry_t ef10_filter_encap_list[] = {
1259 EF10_ENCAP_FILTER_ENTRY(IPV4, VXLAN, UCAST_DST),
1260 EF10_ENCAP_FILTER_ENTRY(IPV4, VXLAN, MCAST_DST),
1261 EF10_ENCAP_FILTER_ENTRY(IPV6, VXLAN, UCAST_DST),
1262 EF10_ENCAP_FILTER_ENTRY(IPV6, VXLAN, MCAST_DST),
1264 EF10_ENCAP_FILTER_ENTRY(IPV4, GENEVE, UCAST_DST),
1265 EF10_ENCAP_FILTER_ENTRY(IPV4, GENEVE, MCAST_DST),
1266 EF10_ENCAP_FILTER_ENTRY(IPV6, GENEVE, UCAST_DST),
1267 EF10_ENCAP_FILTER_ENTRY(IPV6, GENEVE, MCAST_DST),
1269 EF10_ENCAP_FILTER_ENTRY(IPV4, NVGRE, UCAST_DST),
1270 EF10_ENCAP_FILTER_ENTRY(IPV4, NVGRE, MCAST_DST),
1271 EF10_ENCAP_FILTER_ENTRY(IPV6, NVGRE, UCAST_DST),
1272 EF10_ENCAP_FILTER_ENTRY(IPV6, NVGRE, MCAST_DST),
1275 #undef EF10_ENCAP_FILTER_ENTRY
1277 static __checkReturn efx_rc_t
1278 ef10_filter_insert_encap_filters(
1279 __in efx_nic_t *enp,
1280 __in boolean_t mulcst,
1281 __in efx_filter_flags_t filter_flags)
1283 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
1287 EFX_STATIC_ASSERT(EFX_ARRAY_SIZE(ef10_filter_encap_list) <=
1288 EFX_ARRAY_SIZE(table->eft_encap_filter_indexes));
1291 * On Medford, full-featured firmware can identify packets as being
1292 * tunnel encapsulated, even if no encapsulated packet offloads are in
1293 * use. When packets are identified as such, ordinary filters are not
1294 * applied, only ones specific to encapsulated packets. Hence we need to
1295 * insert filters for encapsulated packets in order to receive them.
1297 * Separate filters need to be inserted for each ether type,
1298 * encapsulation type, and inner frame type (unicast or multicast). To
1299 * keep things simple and reduce the number of filters needed, catch-all
1300 * filters for all combinations of types are inserted, even if
1301 * all_unicst or all_mulcst have not been set. (These catch-all filters
1302 * may well, however, fail to insert on unprivileged functions.)
1304 table->eft_encap_filter_count = 0;
1305 for (i = 0; i < EFX_ARRAY_SIZE(ef10_filter_encap_list); i++) {
1306 efx_filter_spec_t spec;
1307 ef10_filter_encap_entry_t *encap_filter =
1308 &ef10_filter_encap_list[i];
1311 * Skip multicast filters if we've not been asked for
1312 * any multicast traffic.
1314 if ((mulcst == B_FALSE) &&
1315 (encap_filter->inner_frame_match ==
1316 EFX_FILTER_INNER_FRAME_MATCH_UNKNOWN_MCAST_DST))
1319 efx_filter_spec_init_rx(&spec, EFX_FILTER_PRI_AUTO,
1321 table->eft_default_rxq);
1322 efx_filter_spec_set_ether_type(&spec, encap_filter->ether_type);
1323 rc = efx_filter_spec_set_encap_type(&spec,
1324 encap_filter->encap_type,
1325 encap_filter->inner_frame_match);
1329 rc = ef10_filter_add_internal(enp, &spec, B_TRUE,
1330 &table->eft_encap_filter_indexes[
1331 table->eft_encap_filter_count]);
1336 table->eft_encap_filter_count++;
1345 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1351 ef10_filter_remove_old(
1352 __in efx_nic_t *enp)
1354 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
1357 for (i = 0; i < EFX_ARRAY_SIZE(table->eft_entry); i++) {
1358 if (ef10_filter_entry_is_auto_old(table, i)) {
1359 (void) ef10_filter_delete_internal(enp, i);
1365 static __checkReturn efx_rc_t
1366 ef10_filter_get_workarounds(
1367 __in efx_nic_t *enp)
1369 efx_nic_cfg_t *encp = &enp->en_nic_cfg;
1370 uint32_t implemented = 0;
1371 uint32_t enabled = 0;
1374 rc = efx_mcdi_get_workarounds(enp, &implemented, &enabled);
1376 /* Check if chained multicast filter support is enabled */
1377 if (implemented & enabled & MC_CMD_GET_WORKAROUNDS_OUT_BUG26807)
1378 encp->enc_bug26807_workaround = B_TRUE;
1380 encp->enc_bug26807_workaround = B_FALSE;
1381 } else if (rc == ENOTSUP) {
1383 * Firmware is too old to support GET_WORKAROUNDS, and support
1384 * for this workaround was implemented later.
1386 encp->enc_bug26807_workaround = B_FALSE;
1394 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1402 * Reconfigure all filters.
1403 * If all_unicst and/or all mulcst filters cannot be applied then
1404 * return ENOTSUP (Note the filters for the specified addresses are
1405 * still applied in this case).
1407 __checkReturn efx_rc_t
1408 ef10_filter_reconfigure(
1409 __in efx_nic_t *enp,
1410 __in_ecount(6) uint8_t const *mac_addr,
1411 __in boolean_t all_unicst,
1412 __in boolean_t mulcst,
1413 __in boolean_t all_mulcst,
1414 __in boolean_t brdcst,
1415 __in_ecount(6*count) uint8_t const *addrs,
1416 __in uint32_t count)
1418 efx_nic_cfg_t *encp = &enp->en_nic_cfg;
1419 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
1420 efx_filter_flags_t filter_flags;
1422 efx_rc_t all_unicst_rc = 0;
1423 efx_rc_t all_mulcst_rc = 0;
1426 if (table->eft_default_rxq == NULL) {
1428 * Filters direct traffic to the default RXQ, and so cannot be
1429 * inserted until it is available. Any currently configured
1430 * filters must be removed (ignore errors in case the MC
1431 * has rebooted, which removes hardware filters).
1433 for (i = 0; i < table->eft_unicst_filter_count; i++) {
1434 (void) ef10_filter_delete_internal(enp,
1435 table->eft_unicst_filter_indexes[i]);
1437 table->eft_unicst_filter_count = 0;
1439 for (i = 0; i < table->eft_mulcst_filter_count; i++) {
1440 (void) ef10_filter_delete_internal(enp,
1441 table->eft_mulcst_filter_indexes[i]);
1443 table->eft_mulcst_filter_count = 0;
1445 for (i = 0; i < table->eft_encap_filter_count; i++) {
1446 (void) ef10_filter_delete_internal(enp,
1447 table->eft_encap_filter_indexes[i]);
1449 table->eft_encap_filter_count = 0;
1454 if (table->eft_using_rss)
1455 filter_flags = EFX_FILTER_FLAG_RX_RSS;
1459 /* Mark old filters which may need to be removed */
1460 for (i = 0; i < table->eft_unicst_filter_count; i++) {
1461 ef10_filter_set_entry_auto_old(table,
1462 table->eft_unicst_filter_indexes[i]);
1464 for (i = 0; i < table->eft_mulcst_filter_count; i++) {
1465 ef10_filter_set_entry_auto_old(table,
1466 table->eft_mulcst_filter_indexes[i]);
1468 for (i = 0; i < table->eft_encap_filter_count; i++) {
1469 ef10_filter_set_entry_auto_old(table,
1470 table->eft_encap_filter_indexes[i]);
1474 * Insert or renew unicast filters.
1476 * Frimware does not perform chaining on unicast filters. As traffic is
1477 * therefore only delivered to the first matching filter, we should
1478 * always insert the specific filter for our MAC address, to try and
1479 * ensure we get that traffic.
1481 * (If the filter for our MAC address has already been inserted by
1482 * another function, we won't receive traffic sent to us, even if we
1483 * insert a unicast mismatch filter. To prevent traffic stealing, this
1484 * therefore relies on the privilege model only allowing functions to
1485 * insert filters for their own MAC address unless explicitly given
1486 * additional privileges by the user. This also means that, even on a
1487 * priviliged function, inserting a unicast mismatch filter may not
1488 * catch all traffic in multi PCI function scenarios.)
1490 table->eft_unicst_filter_count = 0;
1491 rc = ef10_filter_insert_unicast(enp, mac_addr, filter_flags);
1492 if (all_unicst || (rc != 0)) {
1493 all_unicst_rc = ef10_filter_insert_all_unicast(enp,
1495 if ((rc != 0) && (all_unicst_rc != 0))
1500 * WORKAROUND_BUG26807 controls firmware support for chained multicast
1501 * filters, and can only be enabled or disabled when the hardware filter
1504 * Chained multicast filters require support from the datapath firmware,
1505 * and may not be available (e.g. low-latency variants or old Huntington
1508 * Firmware will reset (FLR) functions which have inserted filters in
1509 * the hardware filter table when the workaround is enabled/disabled.
1510 * Functions without any hardware filters are not reset.
1512 * Re-check if the workaround is enabled after adding unicast hardware
1513 * filters. This ensures that encp->enc_bug26807_workaround matches the
1514 * firmware state, and that later changes to enable/disable the
1515 * workaround will result in this function seeing a reset (FLR).
1517 * In common-code drivers, we only support multiple PCI function
1518 * scenarios with firmware that supports multicast chaining, so we can
1519 * assume it is enabled for such cases and hence simplify the filter
1520 * insertion logic. Firmware that does not support multicast chaining
1521 * does not support multiple PCI function configurations either, so
1522 * filter insertion is much simpler and the same strategies can still be
1525 if ((rc = ef10_filter_get_workarounds(enp)) != 0)
1528 if ((table->eft_using_all_mulcst != all_mulcst) &&
1529 (encp->enc_bug26807_workaround == B_TRUE)) {
1531 * Multicast filter chaining is enabled, so traffic that matches
1532 * more than one multicast filter will be replicated and
1533 * delivered to multiple recipients. To avoid this duplicate
1534 * delivery, remove old multicast filters before inserting new
1535 * multicast filters.
1537 ef10_filter_remove_old(enp);
1540 /* Insert or renew multicast filters */
1541 if (all_mulcst == B_TRUE) {
1543 * Insert the all multicast filter. If that fails, try to insert
1544 * all of our multicast filters (but without rollback on
1547 all_mulcst_rc = ef10_filter_insert_all_multicast(enp,
1549 if (all_mulcst_rc != 0) {
1550 rc = ef10_filter_insert_multicast_list(enp, B_TRUE,
1551 brdcst, addrs, count, filter_flags, B_FALSE);
1557 * Insert filters for multicast addresses.
1558 * If any insertion fails, then rollback and try to insert the
1559 * all multicast filter instead.
1560 * If that also fails, try to insert all of the multicast
1561 * filters (but without rollback on failure).
1563 rc = ef10_filter_insert_multicast_list(enp, mulcst, brdcst,
1564 addrs, count, filter_flags, B_TRUE);
1566 if ((table->eft_using_all_mulcst == B_FALSE) &&
1567 (encp->enc_bug26807_workaround == B_TRUE)) {
1569 * Multicast filter chaining is on, so remove
1570 * old filters before inserting the multicast
1571 * all filter to avoid duplicate delivery caused
1572 * by packets matching multiple filters.
1574 ef10_filter_remove_old(enp);
1577 rc = ef10_filter_insert_all_multicast(enp,
1580 rc = ef10_filter_insert_multicast_list(enp,
1582 addrs, count, filter_flags, B_FALSE);
1589 if (encp->enc_tunnel_encapsulations_supported != 0) {
1590 /* Try to insert filters for encapsulated packets. */
1591 (void) ef10_filter_insert_encap_filters(enp,
1592 mulcst || all_mulcst || brdcst,
1596 /* Remove old filters which were not renewed */
1597 ef10_filter_remove_old(enp);
1599 /* report if any optional flags were rejected */
1600 if (((all_unicst != B_FALSE) && (all_unicst_rc != 0)) ||
1601 ((all_mulcst != B_FALSE) && (all_mulcst_rc != 0))) {
1614 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1616 /* Clear auto old flags */
1617 for (i = 0; i < EFX_ARRAY_SIZE(table->eft_entry); i++) {
1618 if (ef10_filter_entry_is_auto_old(table, i)) {
1619 ef10_filter_set_entry_not_auto_old(table, i);
1627 ef10_filter_get_default_rxq(
1628 __in efx_nic_t *enp,
1629 __out efx_rxq_t **erpp,
1630 __out boolean_t *using_rss)
1632 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
1634 *erpp = table->eft_default_rxq;
1635 *using_rss = table->eft_using_rss;
1640 ef10_filter_default_rxq_set(
1641 __in efx_nic_t *enp,
1642 __in efx_rxq_t *erp,
1643 __in boolean_t using_rss)
1645 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
1647 #if EFSYS_OPT_RX_SCALE
1648 EFSYS_ASSERT((using_rss == B_FALSE) ||
1649 (enp->en_rss_context != EF10_RSS_CONTEXT_INVALID));
1650 table->eft_using_rss = using_rss;
1652 EFSYS_ASSERT(using_rss == B_FALSE);
1653 table->eft_using_rss = B_FALSE;
1655 table->eft_default_rxq = erp;
1659 ef10_filter_default_rxq_clear(
1660 __in efx_nic_t *enp)
1662 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
1664 table->eft_default_rxq = NULL;
1665 table->eft_using_rss = B_FALSE;
1669 #endif /* EFSYS_OPT_FILTER */
1671 #endif /* EFSYS_OPT_HUNTINGTON || EFSYS_OPT_MEDFORD || EFSYS_OPT_MEDFORD2 */