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.
34 #if EFSYS_OPT_HUNTINGTON || EFSYS_OPT_MEDFORD
38 #define EFE_SPEC(eftp, index) ((eftp)->eft_entry[(index)].efe_spec)
40 static efx_filter_spec_t *
41 ef10_filter_entry_spec(
42 __in const ef10_filter_table_t *eftp,
43 __in unsigned int index)
45 return ((efx_filter_spec_t *)(EFE_SPEC(eftp, index) &
46 ~(uintptr_t)EFX_EF10_FILTER_FLAGS));
50 ef10_filter_entry_is_busy(
51 __in const ef10_filter_table_t *eftp,
52 __in unsigned int index)
54 if (EFE_SPEC(eftp, index) & EFX_EF10_FILTER_FLAG_BUSY)
61 ef10_filter_entry_is_auto_old(
62 __in const ef10_filter_table_t *eftp,
63 __in unsigned int index)
65 if (EFE_SPEC(eftp, index) & EFX_EF10_FILTER_FLAG_AUTO_OLD)
72 ef10_filter_set_entry(
73 __inout ef10_filter_table_t *eftp,
74 __in unsigned int index,
75 __in_opt const efx_filter_spec_t *efsp)
77 EFE_SPEC(eftp, index) = (uintptr_t)efsp;
81 ef10_filter_set_entry_busy(
82 __inout ef10_filter_table_t *eftp,
83 __in unsigned int index)
85 EFE_SPEC(eftp, index) |= (uintptr_t)EFX_EF10_FILTER_FLAG_BUSY;
89 ef10_filter_set_entry_not_busy(
90 __inout ef10_filter_table_t *eftp,
91 __in unsigned int index)
93 EFE_SPEC(eftp, index) &= ~(uintptr_t)EFX_EF10_FILTER_FLAG_BUSY;
97 ef10_filter_set_entry_auto_old(
98 __inout ef10_filter_table_t *eftp,
99 __in unsigned int index)
101 EFSYS_ASSERT(ef10_filter_entry_spec(eftp, index) != NULL);
102 EFE_SPEC(eftp, index) |= (uintptr_t)EFX_EF10_FILTER_FLAG_AUTO_OLD;
106 ef10_filter_set_entry_not_auto_old(
107 __inout ef10_filter_table_t *eftp,
108 __in unsigned int index)
110 EFE_SPEC(eftp, index) &= ~(uintptr_t)EFX_EF10_FILTER_FLAG_AUTO_OLD;
111 EFSYS_ASSERT(ef10_filter_entry_spec(eftp, index) != NULL);
114 __checkReturn efx_rc_t
119 ef10_filter_table_t *eftp;
121 EFSYS_ASSERT(enp->en_family == EFX_FAMILY_HUNTINGTON ||
122 enp->en_family == EFX_FAMILY_MEDFORD);
124 #define MATCH_MASK(match) (EFX_MASK32(match) << EFX_LOW_BIT(match))
125 EFX_STATIC_ASSERT(EFX_FILTER_MATCH_REM_HOST ==
126 MATCH_MASK(MC_CMD_FILTER_OP_EXT_IN_MATCH_SRC_IP));
127 EFX_STATIC_ASSERT(EFX_FILTER_MATCH_LOC_HOST ==
128 MATCH_MASK(MC_CMD_FILTER_OP_EXT_IN_MATCH_DST_IP));
129 EFX_STATIC_ASSERT(EFX_FILTER_MATCH_REM_MAC ==
130 MATCH_MASK(MC_CMD_FILTER_OP_EXT_IN_MATCH_SRC_MAC));
131 EFX_STATIC_ASSERT(EFX_FILTER_MATCH_REM_PORT ==
132 MATCH_MASK(MC_CMD_FILTER_OP_EXT_IN_MATCH_SRC_PORT));
133 EFX_STATIC_ASSERT(EFX_FILTER_MATCH_LOC_MAC ==
134 MATCH_MASK(MC_CMD_FILTER_OP_EXT_IN_MATCH_DST_MAC));
135 EFX_STATIC_ASSERT(EFX_FILTER_MATCH_LOC_PORT ==
136 MATCH_MASK(MC_CMD_FILTER_OP_EXT_IN_MATCH_DST_PORT));
137 EFX_STATIC_ASSERT(EFX_FILTER_MATCH_ETHER_TYPE ==
138 MATCH_MASK(MC_CMD_FILTER_OP_EXT_IN_MATCH_ETHER_TYPE));
139 EFX_STATIC_ASSERT(EFX_FILTER_MATCH_INNER_VID ==
140 MATCH_MASK(MC_CMD_FILTER_OP_EXT_IN_MATCH_INNER_VLAN));
141 EFX_STATIC_ASSERT(EFX_FILTER_MATCH_OUTER_VID ==
142 MATCH_MASK(MC_CMD_FILTER_OP_EXT_IN_MATCH_OUTER_VLAN));
143 EFX_STATIC_ASSERT(EFX_FILTER_MATCH_IP_PROTO ==
144 MATCH_MASK(MC_CMD_FILTER_OP_EXT_IN_MATCH_IP_PROTO));
145 EFX_STATIC_ASSERT(EFX_FILTER_MATCH_IFRM_UNKNOWN_MCAST_DST ==
146 MATCH_MASK(MC_CMD_FILTER_OP_EXT_IN_MATCH_IFRM_UNKNOWN_MCAST_DST));
147 EFX_STATIC_ASSERT(EFX_FILTER_MATCH_IFRM_UNKNOWN_UCAST_DST ==
148 MATCH_MASK(MC_CMD_FILTER_OP_EXT_IN_MATCH_IFRM_UNKNOWN_UCAST_DST));
149 EFX_STATIC_ASSERT(EFX_FILTER_MATCH_UNKNOWN_MCAST_DST ==
150 MATCH_MASK(MC_CMD_FILTER_OP_EXT_IN_MATCH_UNKNOWN_MCAST_DST));
151 EFX_STATIC_ASSERT((uint32_t)EFX_FILTER_MATCH_UNKNOWN_UCAST_DST ==
152 MATCH_MASK(MC_CMD_FILTER_OP_EXT_IN_MATCH_UNKNOWN_UCAST_DST));
155 EFSYS_KMEM_ALLOC(enp->en_esip, sizeof (ef10_filter_table_t), eftp);
162 enp->en_filter.ef_ef10_filter_table = eftp;
167 EFSYS_PROBE1(fail1, efx_rc_t, rc);
176 EFSYS_ASSERT(enp->en_family == EFX_FAMILY_HUNTINGTON ||
177 enp->en_family == EFX_FAMILY_MEDFORD);
179 if (enp->en_filter.ef_ef10_filter_table != NULL) {
180 EFSYS_KMEM_FREE(enp->en_esip, sizeof (ef10_filter_table_t),
181 enp->en_filter.ef_ef10_filter_table);
185 static __checkReturn efx_rc_t
186 efx_mcdi_filter_op_add(
188 __in efx_filter_spec_t *spec,
189 __in unsigned int filter_op,
190 __inout ef10_filter_handle_t *handle)
193 uint8_t payload[MAX(MC_CMD_FILTER_OP_EXT_IN_LEN,
194 MC_CMD_FILTER_OP_EXT_OUT_LEN)];
197 memset(payload, 0, sizeof (payload));
198 req.emr_cmd = MC_CMD_FILTER_OP;
199 req.emr_in_buf = payload;
200 req.emr_in_length = MC_CMD_FILTER_OP_EXT_IN_LEN;
201 req.emr_out_buf = payload;
202 req.emr_out_length = MC_CMD_FILTER_OP_EXT_OUT_LEN;
205 case MC_CMD_FILTER_OP_IN_OP_REPLACE:
206 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_HANDLE_LO,
208 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_HANDLE_HI,
211 case MC_CMD_FILTER_OP_IN_OP_INSERT:
212 case MC_CMD_FILTER_OP_IN_OP_SUBSCRIBE:
213 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_OP, filter_op);
221 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_PORT_ID,
222 EVB_PORT_ID_ASSIGNED);
223 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_MATCH_FIELDS,
224 spec->efs_match_flags);
225 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_RX_DEST,
226 MC_CMD_FILTER_OP_EXT_IN_RX_DEST_HOST);
227 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_RX_QUEUE,
230 #if EFSYS_OPT_RX_SCALE
231 if (spec->efs_flags & EFX_FILTER_FLAG_RX_RSS) {
232 uint32_t rss_context;
234 if (spec->efs_rss_context == EFX_RSS_CONTEXT_DEFAULT)
235 rss_context = enp->en_rss_context;
237 rss_context = spec->efs_rss_context;
238 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_RX_CONTEXT,
243 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_RX_MODE,
244 spec->efs_flags & EFX_FILTER_FLAG_RX_RSS ?
245 MC_CMD_FILTER_OP_EXT_IN_RX_MODE_RSS :
246 MC_CMD_FILTER_OP_EXT_IN_RX_MODE_SIMPLE);
247 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_TX_DEST,
248 MC_CMD_FILTER_OP_EXT_IN_TX_DEST_DEFAULT);
250 if (filter_op != MC_CMD_FILTER_OP_IN_OP_REPLACE) {
252 * NOTE: Unlike most MCDI requests, the filter fields
253 * are presented in network (big endian) byte order.
255 memcpy(MCDI_IN2(req, uint8_t, FILTER_OP_EXT_IN_SRC_MAC),
256 spec->efs_rem_mac, EFX_MAC_ADDR_LEN);
257 memcpy(MCDI_IN2(req, uint8_t, FILTER_OP_EXT_IN_DST_MAC),
258 spec->efs_loc_mac, EFX_MAC_ADDR_LEN);
260 MCDI_IN_SET_WORD(req, FILTER_OP_EXT_IN_SRC_PORT,
261 __CPU_TO_BE_16(spec->efs_rem_port));
262 MCDI_IN_SET_WORD(req, FILTER_OP_EXT_IN_DST_PORT,
263 __CPU_TO_BE_16(spec->efs_loc_port));
265 MCDI_IN_SET_WORD(req, FILTER_OP_EXT_IN_ETHER_TYPE,
266 __CPU_TO_BE_16(spec->efs_ether_type));
268 MCDI_IN_SET_WORD(req, FILTER_OP_EXT_IN_INNER_VLAN,
269 __CPU_TO_BE_16(spec->efs_inner_vid));
270 MCDI_IN_SET_WORD(req, FILTER_OP_EXT_IN_OUTER_VLAN,
271 __CPU_TO_BE_16(spec->efs_outer_vid));
273 /* IP protocol (in low byte, high byte is zero) */
274 MCDI_IN_SET_BYTE(req, FILTER_OP_EXT_IN_IP_PROTO,
277 EFX_STATIC_ASSERT(sizeof (spec->efs_rem_host) ==
278 MC_CMD_FILTER_OP_EXT_IN_SRC_IP_LEN);
279 EFX_STATIC_ASSERT(sizeof (spec->efs_loc_host) ==
280 MC_CMD_FILTER_OP_EXT_IN_DST_IP_LEN);
282 memcpy(MCDI_IN2(req, uint8_t, FILTER_OP_EXT_IN_SRC_IP),
283 &spec->efs_rem_host.eo_byte[0],
284 MC_CMD_FILTER_OP_EXT_IN_SRC_IP_LEN);
285 memcpy(MCDI_IN2(req, uint8_t, FILTER_OP_EXT_IN_DST_IP),
286 &spec->efs_loc_host.eo_byte[0],
287 MC_CMD_FILTER_OP_EXT_IN_DST_IP_LEN);
290 * On Medford, filters for encapsulated packets match based on
291 * the ether type and IP protocol in the outer frame. In
292 * addition we need to fill in the VNI or VSID type field.
294 switch (spec->efs_encap_type) {
295 case EFX_TUNNEL_PROTOCOL_NONE:
297 case EFX_TUNNEL_PROTOCOL_VXLAN:
298 case EFX_TUNNEL_PROTOCOL_GENEVE:
299 MCDI_IN_POPULATE_DWORD_1(req,
300 FILTER_OP_EXT_IN_VNI_OR_VSID,
301 FILTER_OP_EXT_IN_VNI_TYPE,
302 spec->efs_encap_type == EFX_TUNNEL_PROTOCOL_VXLAN ?
303 MC_CMD_FILTER_OP_EXT_IN_VNI_TYPE_VXLAN :
304 MC_CMD_FILTER_OP_EXT_IN_VNI_TYPE_GENEVE);
306 case EFX_TUNNEL_PROTOCOL_NVGRE:
307 MCDI_IN_POPULATE_DWORD_1(req,
308 FILTER_OP_EXT_IN_VNI_OR_VSID,
309 FILTER_OP_EXT_IN_VSID_TYPE,
310 MC_CMD_FILTER_OP_EXT_IN_VSID_TYPE_NVGRE);
319 efx_mcdi_execute(enp, &req);
321 if (req.emr_rc != 0) {
326 if (req.emr_out_length_used < MC_CMD_FILTER_OP_EXT_OUT_LEN) {
331 handle->efh_lo = MCDI_OUT_DWORD(req, FILTER_OP_EXT_OUT_HANDLE_LO);
332 handle->efh_hi = MCDI_OUT_DWORD(req, FILTER_OP_EXT_OUT_HANDLE_HI);
343 EFSYS_PROBE1(fail1, efx_rc_t, rc);
349 static __checkReturn efx_rc_t
350 efx_mcdi_filter_op_delete(
352 __in unsigned int filter_op,
353 __inout ef10_filter_handle_t *handle)
356 uint8_t payload[MAX(MC_CMD_FILTER_OP_EXT_IN_LEN,
357 MC_CMD_FILTER_OP_EXT_OUT_LEN)];
360 memset(payload, 0, sizeof (payload));
361 req.emr_cmd = MC_CMD_FILTER_OP;
362 req.emr_in_buf = payload;
363 req.emr_in_length = MC_CMD_FILTER_OP_EXT_IN_LEN;
364 req.emr_out_buf = payload;
365 req.emr_out_length = MC_CMD_FILTER_OP_EXT_OUT_LEN;
368 case MC_CMD_FILTER_OP_IN_OP_REMOVE:
369 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_OP,
370 MC_CMD_FILTER_OP_IN_OP_REMOVE);
372 case MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE:
373 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_OP,
374 MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE);
382 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_HANDLE_LO, handle->efh_lo);
383 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_HANDLE_HI, handle->efh_hi);
385 efx_mcdi_execute_quiet(enp, &req);
387 if (req.emr_rc != 0) {
392 if (req.emr_out_length_used < MC_CMD_FILTER_OP_EXT_OUT_LEN) {
405 EFSYS_PROBE1(fail1, efx_rc_t, rc);
410 static __checkReturn boolean_t
412 __in const efx_filter_spec_t *left,
413 __in const efx_filter_spec_t *right)
415 /* FIXME: Consider rx vs tx filters (look at efs_flags) */
416 if (left->efs_match_flags != right->efs_match_flags)
418 if (!EFX_OWORD_IS_EQUAL(left->efs_rem_host, right->efs_rem_host))
420 if (!EFX_OWORD_IS_EQUAL(left->efs_loc_host, right->efs_loc_host))
422 if (memcmp(left->efs_rem_mac, right->efs_rem_mac, EFX_MAC_ADDR_LEN))
424 if (memcmp(left->efs_loc_mac, right->efs_loc_mac, EFX_MAC_ADDR_LEN))
426 if (left->efs_rem_port != right->efs_rem_port)
428 if (left->efs_loc_port != right->efs_loc_port)
430 if (left->efs_inner_vid != right->efs_inner_vid)
432 if (left->efs_outer_vid != right->efs_outer_vid)
434 if (left->efs_ether_type != right->efs_ether_type)
436 if (left->efs_ip_proto != right->efs_ip_proto)
438 if (left->efs_encap_type != right->efs_encap_type)
445 static __checkReturn boolean_t
446 ef10_filter_same_dest(
447 __in const efx_filter_spec_t *left,
448 __in const efx_filter_spec_t *right)
450 if ((left->efs_flags & EFX_FILTER_FLAG_RX_RSS) &&
451 (right->efs_flags & EFX_FILTER_FLAG_RX_RSS)) {
452 if (left->efs_rss_context == right->efs_rss_context)
454 } else if ((~(left->efs_flags) & EFX_FILTER_FLAG_RX_RSS) &&
455 (~(right->efs_flags) & EFX_FILTER_FLAG_RX_RSS)) {
456 if (left->efs_dmaq_id == right->efs_dmaq_id)
462 static __checkReturn uint32_t
464 __in efx_filter_spec_t *spec)
466 EFX_STATIC_ASSERT((sizeof (efx_filter_spec_t) % sizeof (uint32_t))
468 EFX_STATIC_ASSERT((EFX_FIELD_OFFSET(efx_filter_spec_t, efs_outer_vid) %
469 sizeof (uint32_t)) == 0);
472 * As the area of the efx_filter_spec_t we need to hash is DWORD
473 * aligned and an exact number of DWORDs in size we can use the
474 * optimised efx_hash_dwords() rather than efx_hash_bytes()
476 return (efx_hash_dwords((const uint32_t *)&spec->efs_outer_vid,
477 (sizeof (efx_filter_spec_t) -
478 EFX_FIELD_OFFSET(efx_filter_spec_t, efs_outer_vid)) /
479 sizeof (uint32_t), 0));
483 * Decide whether a filter should be exclusive or else should allow
484 * delivery to additional recipients. Currently we decide that
485 * filters for specific local unicast MAC and IP addresses are
488 static __checkReturn boolean_t
489 ef10_filter_is_exclusive(
490 __in efx_filter_spec_t *spec)
492 if ((spec->efs_match_flags & EFX_FILTER_MATCH_LOC_MAC) &&
493 !EFX_MAC_ADDR_IS_MULTICAST(spec->efs_loc_mac))
496 if ((spec->efs_match_flags &
497 (EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_LOC_HOST)) ==
498 (EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_LOC_HOST)) {
499 if ((spec->efs_ether_type == EFX_ETHER_TYPE_IPV4) &&
500 ((spec->efs_loc_host.eo_u8[0] & 0xf) != 0xe))
502 if ((spec->efs_ether_type == EFX_ETHER_TYPE_IPV6) &&
503 (spec->efs_loc_host.eo_u8[0] != 0xff))
510 __checkReturn efx_rc_t
515 efx_filter_spec_t *spec;
516 ef10_filter_table_t *eftp = enp->en_filter.ef_ef10_filter_table;
518 efsys_lock_state_t state;
521 EFSYS_ASSERT(enp->en_family == EFX_FAMILY_HUNTINGTON ||
522 enp->en_family == EFX_FAMILY_MEDFORD);
524 for (tbl_id = 0; tbl_id < EFX_EF10_FILTER_TBL_ROWS; tbl_id++) {
526 EFSYS_LOCK(enp->en_eslp, state);
528 spec = ef10_filter_entry_spec(eftp, tbl_id);
531 } else if (ef10_filter_entry_is_busy(eftp, tbl_id)) {
532 /* Ignore busy entries. */
535 ef10_filter_set_entry_busy(eftp, tbl_id);
539 EFSYS_UNLOCK(enp->en_eslp, state);
541 if (restoring == B_FALSE)
544 if (ef10_filter_is_exclusive(spec)) {
545 rc = efx_mcdi_filter_op_add(enp, spec,
546 MC_CMD_FILTER_OP_IN_OP_INSERT,
547 &eftp->eft_entry[tbl_id].efe_handle);
549 rc = efx_mcdi_filter_op_add(enp, spec,
550 MC_CMD_FILTER_OP_IN_OP_SUBSCRIBE,
551 &eftp->eft_entry[tbl_id].efe_handle);
557 EFSYS_LOCK(enp->en_eslp, state);
559 ef10_filter_set_entry_not_busy(eftp, tbl_id);
561 EFSYS_UNLOCK(enp->en_eslp, state);
567 EFSYS_PROBE1(fail1, efx_rc_t, rc);
573 * An arbitrary search limit for the software hash table. As per the linux net
576 #define EF10_FILTER_SEARCH_LIMIT 200
578 static __checkReturn efx_rc_t
579 ef10_filter_add_internal(
581 __inout efx_filter_spec_t *spec,
582 __in boolean_t may_replace,
583 __out_opt uint32_t *filter_id)
586 ef10_filter_table_t *eftp = enp->en_filter.ef_ef10_filter_table;
587 efx_filter_spec_t *saved_spec;
591 boolean_t replacing = B_FALSE;
593 efsys_lock_state_t state;
594 boolean_t locked = B_FALSE;
596 EFSYS_ASSERT(enp->en_family == EFX_FAMILY_HUNTINGTON ||
597 enp->en_family == EFX_FAMILY_MEDFORD);
599 hash = ef10_filter_hash(spec);
602 * FIXME: Add support for inserting filters of different priorities
603 * and removing lower priority multicast filters (bug 42378)
607 * Find any existing filters with the same match tuple or
608 * else a free slot to insert at. If any of them are busy,
609 * we have to wait and retry.
614 EFSYS_LOCK(enp->en_eslp, state);
618 i = (hash + depth) & (EFX_EF10_FILTER_TBL_ROWS - 1);
619 saved_spec = ef10_filter_entry_spec(eftp, i);
625 } else if (ef10_filter_equal(spec, saved_spec)) {
626 if (ef10_filter_entry_is_busy(eftp, i))
628 if (saved_spec->efs_priority
629 == EFX_FILTER_PRI_AUTO) {
632 } else if (ef10_filter_is_exclusive(spec)) {
646 * Once we reach the maximum search depth, use
647 * the first suitable slot or return EBUSY if
650 if (depth == EF10_FILTER_SEARCH_LIMIT) {
659 EFSYS_UNLOCK(enp->en_eslp, state);
665 * Create a software table entry if necessary, and mark it
666 * busy. We might yet fail to insert, but any attempt to
667 * insert a conflicting filter while we're waiting for the
668 * firmware must find the busy entry.
670 saved_spec = ef10_filter_entry_spec(eftp, ins_index);
672 if (saved_spec->efs_priority == EFX_FILTER_PRI_AUTO) {
673 /* This is a filter we are refreshing */
674 ef10_filter_set_entry_not_auto_old(eftp, ins_index);
680 EFSYS_KMEM_ALLOC(enp->en_esip, sizeof (*spec), saved_spec);
686 ef10_filter_set_entry(eftp, ins_index, saved_spec);
688 ef10_filter_set_entry_busy(eftp, ins_index);
690 EFSYS_UNLOCK(enp->en_eslp, state);
694 * On replacing the filter handle may change after after a successful
698 rc = efx_mcdi_filter_op_add(enp, spec,
699 MC_CMD_FILTER_OP_IN_OP_REPLACE,
700 &eftp->eft_entry[ins_index].efe_handle);
701 } else if (ef10_filter_is_exclusive(spec)) {
702 rc = efx_mcdi_filter_op_add(enp, spec,
703 MC_CMD_FILTER_OP_IN_OP_INSERT,
704 &eftp->eft_entry[ins_index].efe_handle);
706 rc = efx_mcdi_filter_op_add(enp, spec,
707 MC_CMD_FILTER_OP_IN_OP_SUBSCRIBE,
708 &eftp->eft_entry[ins_index].efe_handle);
714 EFSYS_LOCK(enp->en_eslp, state);
718 /* Update the fields that may differ */
719 saved_spec->efs_priority = spec->efs_priority;
720 saved_spec->efs_flags = spec->efs_flags;
721 saved_spec->efs_rss_context = spec->efs_rss_context;
722 saved_spec->efs_dmaq_id = spec->efs_dmaq_id;
725 ef10_filter_set_entry_not_busy(eftp, ins_index);
729 EFSYS_UNLOCK(enp->en_eslp, state);
733 *filter_id = ins_index;
741 EFSYS_KMEM_FREE(enp->en_esip, sizeof (*spec), saved_spec);
744 ef10_filter_set_entry_not_busy(eftp, ins_index);
745 ef10_filter_set_entry(eftp, ins_index, NULL);
754 EFSYS_PROBE1(fail1, efx_rc_t, rc);
757 EFSYS_UNLOCK(enp->en_eslp, state);
762 __checkReturn efx_rc_t
765 __inout efx_filter_spec_t *spec,
766 __in boolean_t may_replace)
770 rc = ef10_filter_add_internal(enp, spec, may_replace, NULL);
777 EFSYS_PROBE1(fail1, efx_rc_t, rc);
783 static __checkReturn efx_rc_t
784 ef10_filter_delete_internal(
786 __in uint32_t filter_id)
789 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
790 efx_filter_spec_t *spec;
791 efsys_lock_state_t state;
792 uint32_t filter_idx = filter_id % EFX_EF10_FILTER_TBL_ROWS;
795 * Find the software table entry and mark it busy. Don't
796 * remove it yet; any attempt to update while we're waiting
797 * for the firmware must find the busy entry.
799 * FIXME: What if the busy flag is never cleared?
801 EFSYS_LOCK(enp->en_eslp, state);
802 while (ef10_filter_entry_is_busy(table, filter_idx)) {
803 EFSYS_UNLOCK(enp->en_eslp, state);
805 EFSYS_LOCK(enp->en_eslp, state);
807 if ((spec = ef10_filter_entry_spec(table, filter_idx)) != NULL) {
808 ef10_filter_set_entry_busy(table, filter_idx);
810 EFSYS_UNLOCK(enp->en_eslp, state);
818 * Try to remove the hardware filter. This may fail if the MC has
819 * rebooted (which frees all hardware filter resources).
821 if (ef10_filter_is_exclusive(spec)) {
822 rc = efx_mcdi_filter_op_delete(enp,
823 MC_CMD_FILTER_OP_IN_OP_REMOVE,
824 &table->eft_entry[filter_idx].efe_handle);
826 rc = efx_mcdi_filter_op_delete(enp,
827 MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE,
828 &table->eft_entry[filter_idx].efe_handle);
831 /* Free the software table entry */
832 EFSYS_LOCK(enp->en_eslp, state);
833 ef10_filter_set_entry_not_busy(table, filter_idx);
834 ef10_filter_set_entry(table, filter_idx, NULL);
835 EFSYS_UNLOCK(enp->en_eslp, state);
837 EFSYS_KMEM_FREE(enp->en_esip, sizeof (*spec), spec);
839 /* Check result of hardware filter removal */
849 EFSYS_PROBE1(fail1, efx_rc_t, rc);
854 __checkReturn efx_rc_t
857 __inout efx_filter_spec_t *spec)
860 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
861 efx_filter_spec_t *saved_spec;
865 efsys_lock_state_t state;
866 boolean_t locked = B_FALSE;
868 EFSYS_ASSERT(enp->en_family == EFX_FAMILY_HUNTINGTON ||
869 enp->en_family == EFX_FAMILY_MEDFORD);
871 hash = ef10_filter_hash(spec);
873 EFSYS_LOCK(enp->en_eslp, state);
878 i = (hash + depth) & (EFX_EF10_FILTER_TBL_ROWS - 1);
879 saved_spec = ef10_filter_entry_spec(table, i);
880 if (saved_spec && ef10_filter_equal(spec, saved_spec) &&
881 ef10_filter_same_dest(spec, saved_spec)) {
884 if (depth == EF10_FILTER_SEARCH_LIMIT) {
891 EFSYS_UNLOCK(enp->en_eslp, state);
894 rc = ef10_filter_delete_internal(enp, i);
904 EFSYS_PROBE1(fail1, efx_rc_t, rc);
907 EFSYS_UNLOCK(enp->en_eslp, state);
912 static __checkReturn efx_rc_t
913 efx_mcdi_get_parser_disp_info(
915 __out_ecount(buffer_length) uint32_t *buffer,
916 __in size_t buffer_length,
917 __out size_t *list_lengthp)
920 uint8_t payload[MAX(MC_CMD_GET_PARSER_DISP_INFO_IN_LEN,
921 MC_CMD_GET_PARSER_DISP_INFO_OUT_LENMAX)];
922 size_t matches_count;
926 (void) memset(payload, 0, sizeof (payload));
927 req.emr_cmd = MC_CMD_GET_PARSER_DISP_INFO;
928 req.emr_in_buf = payload;
929 req.emr_in_length = MC_CMD_GET_PARSER_DISP_INFO_IN_LEN;
930 req.emr_out_buf = payload;
931 req.emr_out_length = MC_CMD_GET_PARSER_DISP_INFO_OUT_LENMAX;
933 MCDI_IN_SET_DWORD(req, GET_PARSER_DISP_INFO_OUT_OP,
934 MC_CMD_GET_PARSER_DISP_INFO_IN_OP_GET_SUPPORTED_RX_MATCHES);
936 efx_mcdi_execute(enp, &req);
938 if (req.emr_rc != 0) {
943 matches_count = MCDI_OUT_DWORD(req,
944 GET_PARSER_DISP_INFO_OUT_NUM_SUPPORTED_MATCHES);
946 if (req.emr_out_length_used <
947 MC_CMD_GET_PARSER_DISP_INFO_OUT_LEN(matches_count)) {
952 *list_lengthp = matches_count;
954 if (buffer_length < matches_count) {
960 * Check that the elements in the list in the MCDI response are the size
961 * we expect, so we can just copy them directly. Any conversion of the
962 * flags is handled by the caller.
964 EFX_STATIC_ASSERT(sizeof (uint32_t) ==
965 MC_CMD_GET_PARSER_DISP_INFO_OUT_SUPPORTED_MATCHES_LEN);
967 list_size = matches_count *
968 MC_CMD_GET_PARSER_DISP_INFO_OUT_SUPPORTED_MATCHES_LEN;
970 MCDI_OUT2(req, uint32_t,
971 GET_PARSER_DISP_INFO_OUT_SUPPORTED_MATCHES),
981 EFSYS_PROBE1(fail1, efx_rc_t, rc);
986 __checkReturn efx_rc_t
987 ef10_filter_supported_filters(
989 __out_ecount(buffer_length) uint32_t *buffer,
990 __in size_t buffer_length,
991 __out size_t *list_lengthp)
994 size_t mcdi_list_length;
998 efx_filter_match_flags_t all_filter_flags =
999 (EFX_FILTER_MATCH_REM_HOST | EFX_FILTER_MATCH_LOC_HOST |
1000 EFX_FILTER_MATCH_REM_MAC | EFX_FILTER_MATCH_REM_PORT |
1001 EFX_FILTER_MATCH_LOC_MAC | EFX_FILTER_MATCH_LOC_PORT |
1002 EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_INNER_VID |
1003 EFX_FILTER_MATCH_OUTER_VID | EFX_FILTER_MATCH_IP_PROTO |
1004 EFX_FILTER_MATCH_UNKNOWN_MCAST_DST |
1005 EFX_FILTER_MATCH_UNKNOWN_UCAST_DST);
1007 rc = efx_mcdi_get_parser_disp_info(enp, buffer, buffer_length,
1011 /* Pass through mcdi_list_length for the list length */
1012 *list_lengthp = mcdi_list_length;
1018 * The static assertions in ef10_filter_init() ensure that the values of
1019 * the EFX_FILTER_MATCH flags match those used by MCDI, so they don't
1020 * need to be converted.
1022 * In case support is added to MCDI for additional flags, remove any
1023 * matches from the list which include flags we don't support. The order
1024 * of the matches is preserved as they are ordered from highest to
1027 EFSYS_ASSERT(mcdi_list_length <= buffer_length);
1029 for (i = 0; i < mcdi_list_length; i++) {
1030 if ((buffer[i] & ~all_filter_flags) == 0) {
1031 buffer[list_length] = buffer[i];
1036 *list_lengthp = list_length;
1041 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1046 static __checkReturn efx_rc_t
1047 ef10_filter_insert_unicast(
1048 __in efx_nic_t *enp,
1049 __in_ecount(6) uint8_t const *addr,
1050 __in efx_filter_flags_t filter_flags)
1052 ef10_filter_table_t *eftp = enp->en_filter.ef_ef10_filter_table;
1053 efx_filter_spec_t spec;
1056 /* Insert the filter for the local station address */
1057 efx_filter_spec_init_rx(&spec, EFX_FILTER_PRI_AUTO,
1059 eftp->eft_default_rxq);
1060 efx_filter_spec_set_eth_local(&spec, EFX_FILTER_SPEC_VID_UNSPEC, addr);
1062 rc = ef10_filter_add_internal(enp, &spec, B_TRUE,
1063 &eftp->eft_unicst_filter_indexes[eftp->eft_unicst_filter_count]);
1067 eftp->eft_unicst_filter_count++;
1068 EFSYS_ASSERT(eftp->eft_unicst_filter_count <=
1069 EFX_EF10_FILTER_UNICAST_FILTERS_MAX);
1074 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1078 static __checkReturn efx_rc_t
1079 ef10_filter_insert_all_unicast(
1080 __in efx_nic_t *enp,
1081 __in efx_filter_flags_t filter_flags)
1083 ef10_filter_table_t *eftp = enp->en_filter.ef_ef10_filter_table;
1084 efx_filter_spec_t spec;
1087 /* Insert the unknown unicast filter */
1088 efx_filter_spec_init_rx(&spec, EFX_FILTER_PRI_AUTO,
1090 eftp->eft_default_rxq);
1091 efx_filter_spec_set_uc_def(&spec);
1092 rc = ef10_filter_add_internal(enp, &spec, B_TRUE,
1093 &eftp->eft_unicst_filter_indexes[eftp->eft_unicst_filter_count]);
1097 eftp->eft_unicst_filter_count++;
1098 EFSYS_ASSERT(eftp->eft_unicst_filter_count <=
1099 EFX_EF10_FILTER_UNICAST_FILTERS_MAX);
1104 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1108 static __checkReturn efx_rc_t
1109 ef10_filter_insert_multicast_list(
1110 __in efx_nic_t *enp,
1111 __in boolean_t mulcst,
1112 __in boolean_t brdcst,
1113 __in_ecount(6*count) uint8_t const *addrs,
1114 __in uint32_t count,
1115 __in efx_filter_flags_t filter_flags,
1116 __in boolean_t rollback)
1118 ef10_filter_table_t *eftp = enp->en_filter.ef_ef10_filter_table;
1119 efx_filter_spec_t spec;
1122 uint32_t filter_index;
1123 uint32_t filter_count;
1126 if (mulcst == B_FALSE)
1129 if (count + (brdcst ? 1 : 0) >
1130 EFX_ARRAY_SIZE(eftp->eft_mulcst_filter_indexes)) {
1131 /* Too many MAC addresses */
1136 /* Insert/renew multicast address list filters */
1138 for (i = 0; i < count; i++) {
1139 efx_filter_spec_init_rx(&spec,
1140 EFX_FILTER_PRI_AUTO,
1142 eftp->eft_default_rxq);
1144 efx_filter_spec_set_eth_local(&spec,
1145 EFX_FILTER_SPEC_VID_UNSPEC,
1146 &addrs[i * EFX_MAC_ADDR_LEN]);
1148 rc = ef10_filter_add_internal(enp, &spec, B_TRUE,
1152 eftp->eft_mulcst_filter_indexes[filter_count] =
1155 } else if (rollback == B_TRUE) {
1156 /* Only stop upon failure if told to rollback */
1162 if (brdcst == B_TRUE) {
1163 /* Insert/renew broadcast address filter */
1164 efx_filter_spec_init_rx(&spec, EFX_FILTER_PRI_AUTO,
1166 eftp->eft_default_rxq);
1168 EFX_MAC_BROADCAST_ADDR_SET(addr);
1169 efx_filter_spec_set_eth_local(&spec, EFX_FILTER_SPEC_VID_UNSPEC,
1172 rc = ef10_filter_add_internal(enp, &spec, B_TRUE,
1176 eftp->eft_mulcst_filter_indexes[filter_count] =
1179 } else if (rollback == B_TRUE) {
1180 /* Only stop upon failure if told to rollback */
1185 eftp->eft_mulcst_filter_count = filter_count;
1186 eftp->eft_using_all_mulcst = B_FALSE;
1191 /* Remove any filters we have inserted */
1194 (void) ef10_filter_delete_internal(enp,
1195 eftp->eft_mulcst_filter_indexes[i]);
1197 eftp->eft_mulcst_filter_count = 0;
1200 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1205 static __checkReturn efx_rc_t
1206 ef10_filter_insert_all_multicast(
1207 __in efx_nic_t *enp,
1208 __in efx_filter_flags_t filter_flags)
1210 ef10_filter_table_t *eftp = enp->en_filter.ef_ef10_filter_table;
1211 efx_filter_spec_t spec;
1214 /* Insert the unknown multicast filter */
1215 efx_filter_spec_init_rx(&spec, EFX_FILTER_PRI_AUTO,
1217 eftp->eft_default_rxq);
1218 efx_filter_spec_set_mc_def(&spec);
1220 rc = ef10_filter_add_internal(enp, &spec, B_TRUE,
1221 &eftp->eft_mulcst_filter_indexes[0]);
1225 eftp->eft_mulcst_filter_count = 1;
1226 eftp->eft_using_all_mulcst = B_TRUE;
1229 * FIXME: If brdcst == B_FALSE, add a filter to drop broadcast traffic.
1235 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1240 typedef struct ef10_filter_encap_entry_s {
1241 uint16_t ether_type;
1242 efx_tunnel_protocol_t encap_type;
1243 uint32_t inner_frame_match;
1244 } ef10_filter_encap_entry_t;
1246 #define EF10_ENCAP_FILTER_ENTRY(ipv, encap_type, inner_frame_match) \
1247 { EFX_ETHER_TYPE_##ipv, EFX_TUNNEL_PROTOCOL_##encap_type, \
1248 EFX_FILTER_INNER_FRAME_MATCH_UNKNOWN_##inner_frame_match }
1250 static ef10_filter_encap_entry_t ef10_filter_encap_list[] = {
1251 EF10_ENCAP_FILTER_ENTRY(IPV4, VXLAN, UCAST_DST),
1252 EF10_ENCAP_FILTER_ENTRY(IPV4, VXLAN, MCAST_DST),
1253 EF10_ENCAP_FILTER_ENTRY(IPV6, VXLAN, UCAST_DST),
1254 EF10_ENCAP_FILTER_ENTRY(IPV6, VXLAN, MCAST_DST),
1256 EF10_ENCAP_FILTER_ENTRY(IPV4, GENEVE, UCAST_DST),
1257 EF10_ENCAP_FILTER_ENTRY(IPV4, GENEVE, MCAST_DST),
1258 EF10_ENCAP_FILTER_ENTRY(IPV6, GENEVE, UCAST_DST),
1259 EF10_ENCAP_FILTER_ENTRY(IPV6, GENEVE, MCAST_DST),
1261 EF10_ENCAP_FILTER_ENTRY(IPV4, NVGRE, UCAST_DST),
1262 EF10_ENCAP_FILTER_ENTRY(IPV4, NVGRE, MCAST_DST),
1263 EF10_ENCAP_FILTER_ENTRY(IPV6, NVGRE, UCAST_DST),
1264 EF10_ENCAP_FILTER_ENTRY(IPV6, NVGRE, MCAST_DST),
1267 #undef EF10_ENCAP_FILTER_ENTRY
1269 static __checkReturn efx_rc_t
1270 ef10_filter_insert_encap_filters(
1271 __in efx_nic_t *enp,
1272 __in boolean_t mulcst,
1273 __in efx_filter_flags_t filter_flags)
1275 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
1279 EFX_STATIC_ASSERT(EFX_ARRAY_SIZE(ef10_filter_encap_list) <=
1280 EFX_ARRAY_SIZE(table->eft_encap_filter_indexes));
1283 * On Medford, full-featured firmware can identify packets as being
1284 * tunnel encapsulated, even if no encapsulated packet offloads are in
1285 * use. When packets are identified as such, ordinary filters are not
1286 * applied, only ones specific to encapsulated packets. Hence we need to
1287 * insert filters for encapsulated packets in order to receive them.
1289 * Separate filters need to be inserted for each ether type,
1290 * encapsulation type, and inner frame type (unicast or multicast). To
1291 * keep things simple and reduce the number of filters needed, catch-all
1292 * filters for all combinations of types are inserted, even if
1293 * all_unicst or all_mulcst have not been set. (These catch-all filters
1294 * may well, however, fail to insert on unprivileged functions.)
1296 table->eft_encap_filter_count = 0;
1297 for (i = 0; i < EFX_ARRAY_SIZE(ef10_filter_encap_list); i++) {
1298 efx_filter_spec_t spec;
1299 ef10_filter_encap_entry_t *encap_filter =
1300 &ef10_filter_encap_list[i];
1303 * Skip multicast filters if we've not been asked for
1304 * any multicast traffic.
1306 if ((mulcst == B_FALSE) &&
1307 (encap_filter->inner_frame_match ==
1308 EFX_FILTER_INNER_FRAME_MATCH_UNKNOWN_MCAST_DST))
1311 efx_filter_spec_init_rx(&spec, EFX_FILTER_PRI_AUTO,
1313 table->eft_default_rxq);
1314 efx_filter_spec_set_ether_type(&spec, encap_filter->ether_type);
1315 rc = efx_filter_spec_set_encap_type(&spec,
1316 encap_filter->encap_type,
1317 encap_filter->inner_frame_match);
1321 rc = ef10_filter_add_internal(enp, &spec, B_TRUE,
1322 &table->eft_encap_filter_indexes[
1323 table->eft_encap_filter_count]);
1328 table->eft_encap_filter_count++;
1337 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1343 ef10_filter_remove_old(
1344 __in efx_nic_t *enp)
1346 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
1349 for (i = 0; i < EFX_ARRAY_SIZE(table->eft_entry); i++) {
1350 if (ef10_filter_entry_is_auto_old(table, i)) {
1351 (void) ef10_filter_delete_internal(enp, i);
1357 static __checkReturn efx_rc_t
1358 ef10_filter_get_workarounds(
1359 __in efx_nic_t *enp)
1361 efx_nic_cfg_t *encp = &enp->en_nic_cfg;
1362 uint32_t implemented = 0;
1363 uint32_t enabled = 0;
1366 rc = efx_mcdi_get_workarounds(enp, &implemented, &enabled);
1368 /* Check if chained multicast filter support is enabled */
1369 if (implemented & enabled & MC_CMD_GET_WORKAROUNDS_OUT_BUG26807)
1370 encp->enc_bug26807_workaround = B_TRUE;
1372 encp->enc_bug26807_workaround = B_FALSE;
1373 } else if (rc == ENOTSUP) {
1375 * Firmware is too old to support GET_WORKAROUNDS, and support
1376 * for this workaround was implemented later.
1378 encp->enc_bug26807_workaround = B_FALSE;
1386 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1394 * Reconfigure all filters.
1395 * If all_unicst and/or all mulcst filters cannot be applied then
1396 * return ENOTSUP (Note the filters for the specified addresses are
1397 * still applied in this case).
1399 __checkReturn efx_rc_t
1400 ef10_filter_reconfigure(
1401 __in efx_nic_t *enp,
1402 __in_ecount(6) uint8_t const *mac_addr,
1403 __in boolean_t all_unicst,
1404 __in boolean_t mulcst,
1405 __in boolean_t all_mulcst,
1406 __in boolean_t brdcst,
1407 __in_ecount(6*count) uint8_t const *addrs,
1408 __in uint32_t count)
1410 efx_nic_cfg_t *encp = &enp->en_nic_cfg;
1411 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
1412 efx_filter_flags_t filter_flags;
1414 efx_rc_t all_unicst_rc = 0;
1415 efx_rc_t all_mulcst_rc = 0;
1418 if (table->eft_default_rxq == NULL) {
1420 * Filters direct traffic to the default RXQ, and so cannot be
1421 * inserted until it is available. Any currently configured
1422 * filters must be removed (ignore errors in case the MC
1423 * has rebooted, which removes hardware filters).
1425 for (i = 0; i < table->eft_unicst_filter_count; i++) {
1426 (void) ef10_filter_delete_internal(enp,
1427 table->eft_unicst_filter_indexes[i]);
1429 table->eft_unicst_filter_count = 0;
1431 for (i = 0; i < table->eft_mulcst_filter_count; i++) {
1432 (void) ef10_filter_delete_internal(enp,
1433 table->eft_mulcst_filter_indexes[i]);
1435 table->eft_mulcst_filter_count = 0;
1437 for (i = 0; i < table->eft_encap_filter_count; i++) {
1438 (void) ef10_filter_delete_internal(enp,
1439 table->eft_encap_filter_indexes[i]);
1441 table->eft_encap_filter_count = 0;
1446 if (table->eft_using_rss)
1447 filter_flags = EFX_FILTER_FLAG_RX_RSS;
1451 /* Mark old filters which may need to be removed */
1452 for (i = 0; i < table->eft_unicst_filter_count; i++) {
1453 ef10_filter_set_entry_auto_old(table,
1454 table->eft_unicst_filter_indexes[i]);
1456 for (i = 0; i < table->eft_mulcst_filter_count; i++) {
1457 ef10_filter_set_entry_auto_old(table,
1458 table->eft_mulcst_filter_indexes[i]);
1460 for (i = 0; i < table->eft_encap_filter_count; i++) {
1461 ef10_filter_set_entry_auto_old(table,
1462 table->eft_encap_filter_indexes[i]);
1466 * Insert or renew unicast filters.
1468 * Frimware does not perform chaining on unicast filters. As traffic is
1469 * therefore only delivered to the first matching filter, we should
1470 * always insert the specific filter for our MAC address, to try and
1471 * ensure we get that traffic.
1473 * (If the filter for our MAC address has already been inserted by
1474 * another function, we won't receive traffic sent to us, even if we
1475 * insert a unicast mismatch filter. To prevent traffic stealing, this
1476 * therefore relies on the privilege model only allowing functions to
1477 * insert filters for their own MAC address unless explicitly given
1478 * additional privileges by the user. This also means that, even on a
1479 * priviliged function, inserting a unicast mismatch filter may not
1480 * catch all traffic in multi PCI function scenarios.)
1482 table->eft_unicst_filter_count = 0;
1483 rc = ef10_filter_insert_unicast(enp, mac_addr, filter_flags);
1484 if (all_unicst || (rc != 0)) {
1485 all_unicst_rc = ef10_filter_insert_all_unicast(enp,
1487 if ((rc != 0) && (all_unicst_rc != 0))
1492 * WORKAROUND_BUG26807 controls firmware support for chained multicast
1493 * filters, and can only be enabled or disabled when the hardware filter
1496 * Chained multicast filters require support from the datapath firmware,
1497 * and may not be available (e.g. low-latency variants or old Huntington
1500 * Firmware will reset (FLR) functions which have inserted filters in
1501 * the hardware filter table when the workaround is enabled/disabled.
1502 * Functions without any hardware filters are not reset.
1504 * Re-check if the workaround is enabled after adding unicast hardware
1505 * filters. This ensures that encp->enc_bug26807_workaround matches the
1506 * firmware state, and that later changes to enable/disable the
1507 * workaround will result in this function seeing a reset (FLR).
1509 * In common-code drivers, we only support multiple PCI function
1510 * scenarios with firmware that supports multicast chaining, so we can
1511 * assume it is enabled for such cases and hence simplify the filter
1512 * insertion logic. Firmware that does not support multicast chaining
1513 * does not support multiple PCI function configurations either, so
1514 * filter insertion is much simpler and the same strategies can still be
1517 if ((rc = ef10_filter_get_workarounds(enp)) != 0)
1520 if ((table->eft_using_all_mulcst != all_mulcst) &&
1521 (encp->enc_bug26807_workaround == B_TRUE)) {
1523 * Multicast filter chaining is enabled, so traffic that matches
1524 * more than one multicast filter will be replicated and
1525 * delivered to multiple recipients. To avoid this duplicate
1526 * delivery, remove old multicast filters before inserting new
1527 * multicast filters.
1529 ef10_filter_remove_old(enp);
1532 /* Insert or renew multicast filters */
1533 if (all_mulcst == B_TRUE) {
1535 * Insert the all multicast filter. If that fails, try to insert
1536 * all of our multicast filters (but without rollback on
1539 all_mulcst_rc = ef10_filter_insert_all_multicast(enp,
1541 if (all_mulcst_rc != 0) {
1542 rc = ef10_filter_insert_multicast_list(enp, B_TRUE,
1543 brdcst, addrs, count, filter_flags, B_FALSE);
1549 * Insert filters for multicast addresses.
1550 * If any insertion fails, then rollback and try to insert the
1551 * all multicast filter instead.
1552 * If that also fails, try to insert all of the multicast
1553 * filters (but without rollback on failure).
1555 rc = ef10_filter_insert_multicast_list(enp, mulcst, brdcst,
1556 addrs, count, filter_flags, B_TRUE);
1558 if ((table->eft_using_all_mulcst == B_FALSE) &&
1559 (encp->enc_bug26807_workaround == B_TRUE)) {
1561 * Multicast filter chaining is on, so remove
1562 * old filters before inserting the multicast
1563 * all filter to avoid duplicate delivery caused
1564 * by packets matching multiple filters.
1566 ef10_filter_remove_old(enp);
1569 rc = ef10_filter_insert_all_multicast(enp,
1572 rc = ef10_filter_insert_multicast_list(enp,
1574 addrs, count, filter_flags, B_FALSE);
1581 if (encp->enc_tunnel_encapsulations_supported != 0) {
1582 /* Try to insert filters for encapsulated packets. */
1583 (void) ef10_filter_insert_encap_filters(enp,
1584 mulcst || all_mulcst || brdcst,
1588 /* Remove old filters which were not renewed */
1589 ef10_filter_remove_old(enp);
1591 /* report if any optional flags were rejected */
1592 if (((all_unicst != B_FALSE) && (all_unicst_rc != 0)) ||
1593 ((all_mulcst != B_FALSE) && (all_mulcst_rc != 0))) {
1606 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1608 /* Clear auto old flags */
1609 for (i = 0; i < EFX_ARRAY_SIZE(table->eft_entry); i++) {
1610 if (ef10_filter_entry_is_auto_old(table, i)) {
1611 ef10_filter_set_entry_not_auto_old(table, i);
1619 ef10_filter_get_default_rxq(
1620 __in efx_nic_t *enp,
1621 __out efx_rxq_t **erpp,
1622 __out boolean_t *using_rss)
1624 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
1626 *erpp = table->eft_default_rxq;
1627 *using_rss = table->eft_using_rss;
1632 ef10_filter_default_rxq_set(
1633 __in efx_nic_t *enp,
1634 __in efx_rxq_t *erp,
1635 __in boolean_t using_rss)
1637 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
1639 #if EFSYS_OPT_RX_SCALE
1640 EFSYS_ASSERT((using_rss == B_FALSE) ||
1641 (enp->en_rss_context != EF10_RSS_CONTEXT_INVALID));
1642 table->eft_using_rss = using_rss;
1644 EFSYS_ASSERT(using_rss == B_FALSE);
1645 table->eft_using_rss = B_FALSE;
1647 table->eft_default_rxq = erp;
1651 ef10_filter_default_rxq_clear(
1652 __in efx_nic_t *enp)
1654 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
1656 table->eft_default_rxq = NULL;
1657 table->eft_using_rss = B_FALSE;
1661 #endif /* EFSYS_OPT_FILTER */
1663 #endif /* EFSYS_OPT_HUNTINGTON || EFSYS_OPT_MEDFORD */