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,
229 if (spec->efs_flags & EFX_FILTER_FLAG_RX_RSS) {
230 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_RX_CONTEXT,
231 spec->efs_rss_context);
233 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_RX_MODE,
234 spec->efs_flags & EFX_FILTER_FLAG_RX_RSS ?
235 MC_CMD_FILTER_OP_EXT_IN_RX_MODE_RSS :
236 MC_CMD_FILTER_OP_EXT_IN_RX_MODE_SIMPLE);
237 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_TX_DEST,
238 MC_CMD_FILTER_OP_EXT_IN_TX_DEST_DEFAULT);
240 if (filter_op != MC_CMD_FILTER_OP_IN_OP_REPLACE) {
242 * NOTE: Unlike most MCDI requests, the filter fields
243 * are presented in network (big endian) byte order.
245 memcpy(MCDI_IN2(req, uint8_t, FILTER_OP_EXT_IN_SRC_MAC),
246 spec->efs_rem_mac, EFX_MAC_ADDR_LEN);
247 memcpy(MCDI_IN2(req, uint8_t, FILTER_OP_EXT_IN_DST_MAC),
248 spec->efs_loc_mac, EFX_MAC_ADDR_LEN);
250 MCDI_IN_SET_WORD(req, FILTER_OP_EXT_IN_SRC_PORT,
251 __CPU_TO_BE_16(spec->efs_rem_port));
252 MCDI_IN_SET_WORD(req, FILTER_OP_EXT_IN_DST_PORT,
253 __CPU_TO_BE_16(spec->efs_loc_port));
255 MCDI_IN_SET_WORD(req, FILTER_OP_EXT_IN_ETHER_TYPE,
256 __CPU_TO_BE_16(spec->efs_ether_type));
258 MCDI_IN_SET_WORD(req, FILTER_OP_EXT_IN_INNER_VLAN,
259 __CPU_TO_BE_16(spec->efs_inner_vid));
260 MCDI_IN_SET_WORD(req, FILTER_OP_EXT_IN_OUTER_VLAN,
261 __CPU_TO_BE_16(spec->efs_outer_vid));
263 /* IP protocol (in low byte, high byte is zero) */
264 MCDI_IN_SET_BYTE(req, FILTER_OP_EXT_IN_IP_PROTO,
267 EFX_STATIC_ASSERT(sizeof (spec->efs_rem_host) ==
268 MC_CMD_FILTER_OP_EXT_IN_SRC_IP_LEN);
269 EFX_STATIC_ASSERT(sizeof (spec->efs_loc_host) ==
270 MC_CMD_FILTER_OP_EXT_IN_DST_IP_LEN);
272 memcpy(MCDI_IN2(req, uint8_t, FILTER_OP_EXT_IN_SRC_IP),
273 &spec->efs_rem_host.eo_byte[0],
274 MC_CMD_FILTER_OP_EXT_IN_SRC_IP_LEN);
275 memcpy(MCDI_IN2(req, uint8_t, FILTER_OP_EXT_IN_DST_IP),
276 &spec->efs_loc_host.eo_byte[0],
277 MC_CMD_FILTER_OP_EXT_IN_DST_IP_LEN);
280 * On Medford, filters for encapsulated packets match based on
281 * the ether type and IP protocol in the outer frame. In
282 * addition we need to fill in the VNI or VSID type field.
284 switch (spec->efs_encap_type) {
285 case EFX_TUNNEL_PROTOCOL_NONE:
287 case EFX_TUNNEL_PROTOCOL_VXLAN:
288 case EFX_TUNNEL_PROTOCOL_GENEVE:
289 MCDI_IN_POPULATE_DWORD_1(req,
290 FILTER_OP_EXT_IN_VNI_OR_VSID,
291 FILTER_OP_EXT_IN_VNI_TYPE,
292 spec->efs_encap_type == EFX_TUNNEL_PROTOCOL_VXLAN ?
293 MC_CMD_FILTER_OP_EXT_IN_VNI_TYPE_VXLAN :
294 MC_CMD_FILTER_OP_EXT_IN_VNI_TYPE_GENEVE);
296 case EFX_TUNNEL_PROTOCOL_NVGRE:
297 MCDI_IN_POPULATE_DWORD_1(req,
298 FILTER_OP_EXT_IN_VNI_OR_VSID,
299 FILTER_OP_EXT_IN_VSID_TYPE,
300 MC_CMD_FILTER_OP_EXT_IN_VSID_TYPE_NVGRE);
309 efx_mcdi_execute(enp, &req);
311 if (req.emr_rc != 0) {
316 if (req.emr_out_length_used < MC_CMD_FILTER_OP_EXT_OUT_LEN) {
321 handle->efh_lo = MCDI_OUT_DWORD(req, FILTER_OP_EXT_OUT_HANDLE_LO);
322 handle->efh_hi = MCDI_OUT_DWORD(req, FILTER_OP_EXT_OUT_HANDLE_HI);
333 EFSYS_PROBE1(fail1, efx_rc_t, rc);
339 static __checkReturn efx_rc_t
340 efx_mcdi_filter_op_delete(
342 __in unsigned int filter_op,
343 __inout ef10_filter_handle_t *handle)
346 uint8_t payload[MAX(MC_CMD_FILTER_OP_EXT_IN_LEN,
347 MC_CMD_FILTER_OP_EXT_OUT_LEN)];
350 memset(payload, 0, sizeof (payload));
351 req.emr_cmd = MC_CMD_FILTER_OP;
352 req.emr_in_buf = payload;
353 req.emr_in_length = MC_CMD_FILTER_OP_EXT_IN_LEN;
354 req.emr_out_buf = payload;
355 req.emr_out_length = MC_CMD_FILTER_OP_EXT_OUT_LEN;
358 case MC_CMD_FILTER_OP_IN_OP_REMOVE:
359 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_OP,
360 MC_CMD_FILTER_OP_IN_OP_REMOVE);
362 case MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE:
363 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_OP,
364 MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE);
372 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_HANDLE_LO, handle->efh_lo);
373 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_HANDLE_HI, handle->efh_hi);
375 efx_mcdi_execute_quiet(enp, &req);
377 if (req.emr_rc != 0) {
382 if (req.emr_out_length_used < MC_CMD_FILTER_OP_EXT_OUT_LEN) {
395 EFSYS_PROBE1(fail1, efx_rc_t, rc);
400 static __checkReturn boolean_t
402 __in const efx_filter_spec_t *left,
403 __in const efx_filter_spec_t *right)
405 /* FIXME: Consider rx vs tx filters (look at efs_flags) */
406 if (left->efs_match_flags != right->efs_match_flags)
408 if (!EFX_OWORD_IS_EQUAL(left->efs_rem_host, right->efs_rem_host))
410 if (!EFX_OWORD_IS_EQUAL(left->efs_loc_host, right->efs_loc_host))
412 if (memcmp(left->efs_rem_mac, right->efs_rem_mac, EFX_MAC_ADDR_LEN))
414 if (memcmp(left->efs_loc_mac, right->efs_loc_mac, EFX_MAC_ADDR_LEN))
416 if (left->efs_rem_port != right->efs_rem_port)
418 if (left->efs_loc_port != right->efs_loc_port)
420 if (left->efs_inner_vid != right->efs_inner_vid)
422 if (left->efs_outer_vid != right->efs_outer_vid)
424 if (left->efs_ether_type != right->efs_ether_type)
426 if (left->efs_ip_proto != right->efs_ip_proto)
428 if (left->efs_encap_type != right->efs_encap_type)
435 static __checkReturn boolean_t
436 ef10_filter_same_dest(
437 __in const efx_filter_spec_t *left,
438 __in const efx_filter_spec_t *right)
440 if ((left->efs_flags & EFX_FILTER_FLAG_RX_RSS) &&
441 (right->efs_flags & EFX_FILTER_FLAG_RX_RSS)) {
442 if (left->efs_rss_context == right->efs_rss_context)
444 } else if ((~(left->efs_flags) & EFX_FILTER_FLAG_RX_RSS) &&
445 (~(right->efs_flags) & EFX_FILTER_FLAG_RX_RSS)) {
446 if (left->efs_dmaq_id == right->efs_dmaq_id)
452 static __checkReturn uint32_t
454 __in efx_filter_spec_t *spec)
456 EFX_STATIC_ASSERT((sizeof (efx_filter_spec_t) % sizeof (uint32_t))
458 EFX_STATIC_ASSERT((EFX_FIELD_OFFSET(efx_filter_spec_t, efs_outer_vid) %
459 sizeof (uint32_t)) == 0);
462 * As the area of the efx_filter_spec_t we need to hash is DWORD
463 * aligned and an exact number of DWORDs in size we can use the
464 * optimised efx_hash_dwords() rather than efx_hash_bytes()
466 return (efx_hash_dwords((const uint32_t *)&spec->efs_outer_vid,
467 (sizeof (efx_filter_spec_t) -
468 EFX_FIELD_OFFSET(efx_filter_spec_t, efs_outer_vid)) /
469 sizeof (uint32_t), 0));
473 * Decide whether a filter should be exclusive or else should allow
474 * delivery to additional recipients. Currently we decide that
475 * filters for specific local unicast MAC and IP addresses are
478 static __checkReturn boolean_t
479 ef10_filter_is_exclusive(
480 __in efx_filter_spec_t *spec)
482 if ((spec->efs_match_flags & EFX_FILTER_MATCH_LOC_MAC) &&
483 !EFX_MAC_ADDR_IS_MULTICAST(spec->efs_loc_mac))
486 if ((spec->efs_match_flags &
487 (EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_LOC_HOST)) ==
488 (EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_LOC_HOST)) {
489 if ((spec->efs_ether_type == EFX_ETHER_TYPE_IPV4) &&
490 ((spec->efs_loc_host.eo_u8[0] & 0xf) != 0xe))
492 if ((spec->efs_ether_type == EFX_ETHER_TYPE_IPV6) &&
493 (spec->efs_loc_host.eo_u8[0] != 0xff))
500 __checkReturn efx_rc_t
505 efx_filter_spec_t *spec;
506 ef10_filter_table_t *eftp = enp->en_filter.ef_ef10_filter_table;
508 efsys_lock_state_t state;
511 EFSYS_ASSERT(enp->en_family == EFX_FAMILY_HUNTINGTON ||
512 enp->en_family == EFX_FAMILY_MEDFORD);
514 for (tbl_id = 0; tbl_id < EFX_EF10_FILTER_TBL_ROWS; tbl_id++) {
516 EFSYS_LOCK(enp->en_eslp, state);
518 spec = ef10_filter_entry_spec(eftp, tbl_id);
521 } else if (ef10_filter_entry_is_busy(eftp, tbl_id)) {
522 /* Ignore busy entries. */
525 ef10_filter_set_entry_busy(eftp, tbl_id);
529 EFSYS_UNLOCK(enp->en_eslp, state);
531 if (restoring == B_FALSE)
534 if (ef10_filter_is_exclusive(spec)) {
535 rc = efx_mcdi_filter_op_add(enp, spec,
536 MC_CMD_FILTER_OP_IN_OP_INSERT,
537 &eftp->eft_entry[tbl_id].efe_handle);
539 rc = efx_mcdi_filter_op_add(enp, spec,
540 MC_CMD_FILTER_OP_IN_OP_SUBSCRIBE,
541 &eftp->eft_entry[tbl_id].efe_handle);
547 EFSYS_LOCK(enp->en_eslp, state);
549 ef10_filter_set_entry_not_busy(eftp, tbl_id);
551 EFSYS_UNLOCK(enp->en_eslp, state);
557 EFSYS_PROBE1(fail1, efx_rc_t, rc);
563 * An arbitrary search limit for the software hash table. As per the linux net
566 #define EF10_FILTER_SEARCH_LIMIT 200
568 static __checkReturn efx_rc_t
569 ef10_filter_add_internal(
571 __inout efx_filter_spec_t *spec,
572 __in boolean_t may_replace,
573 __out_opt uint32_t *filter_id)
576 ef10_filter_table_t *eftp = enp->en_filter.ef_ef10_filter_table;
577 efx_filter_spec_t *saved_spec;
581 boolean_t replacing = B_FALSE;
583 efsys_lock_state_t state;
584 boolean_t locked = B_FALSE;
586 EFSYS_ASSERT(enp->en_family == EFX_FAMILY_HUNTINGTON ||
587 enp->en_family == EFX_FAMILY_MEDFORD);
589 #if EFSYS_OPT_RX_SCALE
590 spec->efs_rss_context = enp->en_rss_context;
593 hash = ef10_filter_hash(spec);
596 * FIXME: Add support for inserting filters of different priorities
597 * and removing lower priority multicast filters (bug 42378)
601 * Find any existing filters with the same match tuple or
602 * else a free slot to insert at. If any of them are busy,
603 * we have to wait and retry.
608 EFSYS_LOCK(enp->en_eslp, state);
612 i = (hash + depth) & (EFX_EF10_FILTER_TBL_ROWS - 1);
613 saved_spec = ef10_filter_entry_spec(eftp, i);
619 } else if (ef10_filter_equal(spec, saved_spec)) {
620 if (ef10_filter_entry_is_busy(eftp, i))
622 if (saved_spec->efs_priority
623 == EFX_FILTER_PRI_AUTO) {
626 } else if (ef10_filter_is_exclusive(spec)) {
640 * Once we reach the maximum search depth, use
641 * the first suitable slot or return EBUSY if
644 if (depth == EF10_FILTER_SEARCH_LIMIT) {
653 EFSYS_UNLOCK(enp->en_eslp, state);
659 * Create a software table entry if necessary, and mark it
660 * busy. We might yet fail to insert, but any attempt to
661 * insert a conflicting filter while we're waiting for the
662 * firmware must find the busy entry.
664 saved_spec = ef10_filter_entry_spec(eftp, ins_index);
666 if (saved_spec->efs_priority == EFX_FILTER_PRI_AUTO) {
667 /* This is a filter we are refreshing */
668 ef10_filter_set_entry_not_auto_old(eftp, ins_index);
674 EFSYS_KMEM_ALLOC(enp->en_esip, sizeof (*spec), saved_spec);
680 ef10_filter_set_entry(eftp, ins_index, saved_spec);
682 ef10_filter_set_entry_busy(eftp, ins_index);
684 EFSYS_UNLOCK(enp->en_eslp, state);
688 * On replacing the filter handle may change after after a successful
692 rc = efx_mcdi_filter_op_add(enp, spec,
693 MC_CMD_FILTER_OP_IN_OP_REPLACE,
694 &eftp->eft_entry[ins_index].efe_handle);
695 } else if (ef10_filter_is_exclusive(spec)) {
696 rc = efx_mcdi_filter_op_add(enp, spec,
697 MC_CMD_FILTER_OP_IN_OP_INSERT,
698 &eftp->eft_entry[ins_index].efe_handle);
700 rc = efx_mcdi_filter_op_add(enp, spec,
701 MC_CMD_FILTER_OP_IN_OP_SUBSCRIBE,
702 &eftp->eft_entry[ins_index].efe_handle);
708 EFSYS_LOCK(enp->en_eslp, state);
712 /* Update the fields that may differ */
713 saved_spec->efs_priority = spec->efs_priority;
714 saved_spec->efs_flags = spec->efs_flags;
715 saved_spec->efs_rss_context = spec->efs_rss_context;
716 saved_spec->efs_dmaq_id = spec->efs_dmaq_id;
719 ef10_filter_set_entry_not_busy(eftp, ins_index);
723 EFSYS_UNLOCK(enp->en_eslp, state);
727 *filter_id = ins_index;
735 EFSYS_KMEM_FREE(enp->en_esip, sizeof (*spec), saved_spec);
738 ef10_filter_set_entry_not_busy(eftp, ins_index);
739 ef10_filter_set_entry(eftp, ins_index, NULL);
748 EFSYS_PROBE1(fail1, efx_rc_t, rc);
751 EFSYS_UNLOCK(enp->en_eslp, state);
756 __checkReturn efx_rc_t
759 __inout efx_filter_spec_t *spec,
760 __in boolean_t may_replace)
764 rc = ef10_filter_add_internal(enp, spec, may_replace, NULL);
771 EFSYS_PROBE1(fail1, efx_rc_t, rc);
777 static __checkReturn efx_rc_t
778 ef10_filter_delete_internal(
780 __in uint32_t filter_id)
783 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
784 efx_filter_spec_t *spec;
785 efsys_lock_state_t state;
786 uint32_t filter_idx = filter_id % EFX_EF10_FILTER_TBL_ROWS;
789 * Find the software table entry and mark it busy. Don't
790 * remove it yet; any attempt to update while we're waiting
791 * for the firmware must find the busy entry.
793 * FIXME: What if the busy flag is never cleared?
795 EFSYS_LOCK(enp->en_eslp, state);
796 while (ef10_filter_entry_is_busy(table, filter_idx)) {
797 EFSYS_UNLOCK(enp->en_eslp, state);
799 EFSYS_LOCK(enp->en_eslp, state);
801 if ((spec = ef10_filter_entry_spec(table, filter_idx)) != NULL) {
802 ef10_filter_set_entry_busy(table, filter_idx);
804 EFSYS_UNLOCK(enp->en_eslp, state);
812 * Try to remove the hardware filter. This may fail if the MC has
813 * rebooted (which frees all hardware filter resources).
815 if (ef10_filter_is_exclusive(spec)) {
816 rc = efx_mcdi_filter_op_delete(enp,
817 MC_CMD_FILTER_OP_IN_OP_REMOVE,
818 &table->eft_entry[filter_idx].efe_handle);
820 rc = efx_mcdi_filter_op_delete(enp,
821 MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE,
822 &table->eft_entry[filter_idx].efe_handle);
825 /* Free the software table entry */
826 EFSYS_LOCK(enp->en_eslp, state);
827 ef10_filter_set_entry_not_busy(table, filter_idx);
828 ef10_filter_set_entry(table, filter_idx, NULL);
829 EFSYS_UNLOCK(enp->en_eslp, state);
831 EFSYS_KMEM_FREE(enp->en_esip, sizeof (*spec), spec);
833 /* Check result of hardware filter removal */
843 EFSYS_PROBE1(fail1, efx_rc_t, rc);
848 __checkReturn efx_rc_t
851 __inout efx_filter_spec_t *spec)
854 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
855 efx_filter_spec_t *saved_spec;
859 efsys_lock_state_t state;
860 boolean_t locked = B_FALSE;
862 EFSYS_ASSERT(enp->en_family == EFX_FAMILY_HUNTINGTON ||
863 enp->en_family == EFX_FAMILY_MEDFORD);
865 hash = ef10_filter_hash(spec);
867 EFSYS_LOCK(enp->en_eslp, state);
872 i = (hash + depth) & (EFX_EF10_FILTER_TBL_ROWS - 1);
873 saved_spec = ef10_filter_entry_spec(table, i);
874 if (saved_spec && ef10_filter_equal(spec, saved_spec) &&
875 ef10_filter_same_dest(spec, saved_spec)) {
878 if (depth == EF10_FILTER_SEARCH_LIMIT) {
885 EFSYS_UNLOCK(enp->en_eslp, state);
888 rc = ef10_filter_delete_internal(enp, i);
898 EFSYS_PROBE1(fail1, efx_rc_t, rc);
901 EFSYS_UNLOCK(enp->en_eslp, state);
906 static __checkReturn efx_rc_t
907 efx_mcdi_get_parser_disp_info(
909 __out_ecount(buffer_length) uint32_t *buffer,
910 __in size_t buffer_length,
911 __out size_t *list_lengthp)
914 uint8_t payload[MAX(MC_CMD_GET_PARSER_DISP_INFO_IN_LEN,
915 MC_CMD_GET_PARSER_DISP_INFO_OUT_LENMAX)];
916 size_t matches_count;
920 (void) memset(payload, 0, sizeof (payload));
921 req.emr_cmd = MC_CMD_GET_PARSER_DISP_INFO;
922 req.emr_in_buf = payload;
923 req.emr_in_length = MC_CMD_GET_PARSER_DISP_INFO_IN_LEN;
924 req.emr_out_buf = payload;
925 req.emr_out_length = MC_CMD_GET_PARSER_DISP_INFO_OUT_LENMAX;
927 MCDI_IN_SET_DWORD(req, GET_PARSER_DISP_INFO_OUT_OP,
928 MC_CMD_GET_PARSER_DISP_INFO_IN_OP_GET_SUPPORTED_RX_MATCHES);
930 efx_mcdi_execute(enp, &req);
932 if (req.emr_rc != 0) {
937 matches_count = MCDI_OUT_DWORD(req,
938 GET_PARSER_DISP_INFO_OUT_NUM_SUPPORTED_MATCHES);
940 if (req.emr_out_length_used <
941 MC_CMD_GET_PARSER_DISP_INFO_OUT_LEN(matches_count)) {
946 *list_lengthp = matches_count;
948 if (buffer_length < matches_count) {
954 * Check that the elements in the list in the MCDI response are the size
955 * we expect, so we can just copy them directly. Any conversion of the
956 * flags is handled by the caller.
958 EFX_STATIC_ASSERT(sizeof (uint32_t) ==
959 MC_CMD_GET_PARSER_DISP_INFO_OUT_SUPPORTED_MATCHES_LEN);
961 list_size = matches_count *
962 MC_CMD_GET_PARSER_DISP_INFO_OUT_SUPPORTED_MATCHES_LEN;
964 MCDI_OUT2(req, uint32_t,
965 GET_PARSER_DISP_INFO_OUT_SUPPORTED_MATCHES),
975 EFSYS_PROBE1(fail1, efx_rc_t, rc);
980 __checkReturn efx_rc_t
981 ef10_filter_supported_filters(
983 __out_ecount(buffer_length) uint32_t *buffer,
984 __in size_t buffer_length,
985 __out size_t *list_lengthp)
988 size_t mcdi_list_length;
992 uint32_t all_filter_flags =
993 (EFX_FILTER_MATCH_REM_HOST | EFX_FILTER_MATCH_LOC_HOST |
994 EFX_FILTER_MATCH_REM_MAC | EFX_FILTER_MATCH_REM_PORT |
995 EFX_FILTER_MATCH_LOC_MAC | EFX_FILTER_MATCH_LOC_PORT |
996 EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_INNER_VID |
997 EFX_FILTER_MATCH_OUTER_VID | EFX_FILTER_MATCH_IP_PROTO |
998 EFX_FILTER_MATCH_UNKNOWN_MCAST_DST |
999 EFX_FILTER_MATCH_UNKNOWN_UCAST_DST);
1001 rc = efx_mcdi_get_parser_disp_info(enp, buffer, buffer_length,
1005 /* Pass through mcdi_list_length for the list length */
1006 *list_lengthp = mcdi_list_length;
1012 * The static assertions in ef10_filter_init() ensure that the values of
1013 * the EFX_FILTER_MATCH flags match those used by MCDI, so they don't
1014 * need to be converted.
1016 * In case support is added to MCDI for additional flags, remove any
1017 * matches from the list which include flags we don't support. The order
1018 * of the matches is preserved as they are ordered from highest to
1021 EFSYS_ASSERT(mcdi_list_length <= buffer_length);
1023 for (i = 0; i < mcdi_list_length; i++) {
1024 if ((buffer[i] & ~all_filter_flags) == 0) {
1025 buffer[list_length] = buffer[i];
1030 *list_lengthp = list_length;
1035 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1040 static __checkReturn efx_rc_t
1041 ef10_filter_insert_unicast(
1042 __in efx_nic_t *enp,
1043 __in_ecount(6) uint8_t const *addr,
1044 __in efx_filter_flags_t filter_flags)
1046 ef10_filter_table_t *eftp = enp->en_filter.ef_ef10_filter_table;
1047 efx_filter_spec_t spec;
1050 /* Insert the filter for the local station address */
1051 efx_filter_spec_init_rx(&spec, EFX_FILTER_PRI_AUTO,
1053 eftp->eft_default_rxq);
1054 efx_filter_spec_set_eth_local(&spec, EFX_FILTER_SPEC_VID_UNSPEC, addr);
1056 rc = ef10_filter_add_internal(enp, &spec, B_TRUE,
1057 &eftp->eft_unicst_filter_indexes[eftp->eft_unicst_filter_count]);
1061 eftp->eft_unicst_filter_count++;
1062 EFSYS_ASSERT(eftp->eft_unicst_filter_count <=
1063 EFX_EF10_FILTER_UNICAST_FILTERS_MAX);
1068 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1072 static __checkReturn efx_rc_t
1073 ef10_filter_insert_all_unicast(
1074 __in efx_nic_t *enp,
1075 __in efx_filter_flags_t filter_flags)
1077 ef10_filter_table_t *eftp = enp->en_filter.ef_ef10_filter_table;
1078 efx_filter_spec_t spec;
1081 /* Insert the unknown unicast filter */
1082 efx_filter_spec_init_rx(&spec, EFX_FILTER_PRI_AUTO,
1084 eftp->eft_default_rxq);
1085 efx_filter_spec_set_uc_def(&spec);
1086 rc = ef10_filter_add_internal(enp, &spec, B_TRUE,
1087 &eftp->eft_unicst_filter_indexes[eftp->eft_unicst_filter_count]);
1091 eftp->eft_unicst_filter_count++;
1092 EFSYS_ASSERT(eftp->eft_unicst_filter_count <=
1093 EFX_EF10_FILTER_UNICAST_FILTERS_MAX);
1098 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1102 static __checkReturn efx_rc_t
1103 ef10_filter_insert_multicast_list(
1104 __in efx_nic_t *enp,
1105 __in boolean_t mulcst,
1106 __in boolean_t brdcst,
1107 __in_ecount(6*count) uint8_t const *addrs,
1108 __in uint32_t count,
1109 __in efx_filter_flags_t filter_flags,
1110 __in boolean_t rollback)
1112 ef10_filter_table_t *eftp = enp->en_filter.ef_ef10_filter_table;
1113 efx_filter_spec_t spec;
1116 uint32_t filter_index;
1117 uint32_t filter_count;
1120 if (mulcst == B_FALSE)
1123 if (count + (brdcst ? 1 : 0) >
1124 EFX_ARRAY_SIZE(eftp->eft_mulcst_filter_indexes)) {
1125 /* Too many MAC addresses */
1130 /* Insert/renew multicast address list filters */
1132 for (i = 0; i < count; i++) {
1133 efx_filter_spec_init_rx(&spec,
1134 EFX_FILTER_PRI_AUTO,
1136 eftp->eft_default_rxq);
1138 efx_filter_spec_set_eth_local(&spec,
1139 EFX_FILTER_SPEC_VID_UNSPEC,
1140 &addrs[i * EFX_MAC_ADDR_LEN]);
1142 rc = ef10_filter_add_internal(enp, &spec, B_TRUE,
1146 eftp->eft_mulcst_filter_indexes[filter_count] =
1149 } else if (rollback == B_TRUE) {
1150 /* Only stop upon failure if told to rollback */
1156 if (brdcst == B_TRUE) {
1157 /* Insert/renew broadcast address filter */
1158 efx_filter_spec_init_rx(&spec, EFX_FILTER_PRI_AUTO,
1160 eftp->eft_default_rxq);
1162 EFX_MAC_BROADCAST_ADDR_SET(addr);
1163 efx_filter_spec_set_eth_local(&spec, EFX_FILTER_SPEC_VID_UNSPEC,
1166 rc = ef10_filter_add_internal(enp, &spec, B_TRUE,
1170 eftp->eft_mulcst_filter_indexes[filter_count] =
1173 } else if (rollback == B_TRUE) {
1174 /* Only stop upon failure if told to rollback */
1179 eftp->eft_mulcst_filter_count = filter_count;
1180 eftp->eft_using_all_mulcst = B_FALSE;
1185 /* Remove any filters we have inserted */
1188 (void) ef10_filter_delete_internal(enp,
1189 eftp->eft_mulcst_filter_indexes[i]);
1191 eftp->eft_mulcst_filter_count = 0;
1194 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1199 static __checkReturn efx_rc_t
1200 ef10_filter_insert_all_multicast(
1201 __in efx_nic_t *enp,
1202 __in efx_filter_flags_t filter_flags)
1204 ef10_filter_table_t *eftp = enp->en_filter.ef_ef10_filter_table;
1205 efx_filter_spec_t spec;
1208 /* Insert the unknown multicast filter */
1209 efx_filter_spec_init_rx(&spec, EFX_FILTER_PRI_AUTO,
1211 eftp->eft_default_rxq);
1212 efx_filter_spec_set_mc_def(&spec);
1214 rc = ef10_filter_add_internal(enp, &spec, B_TRUE,
1215 &eftp->eft_mulcst_filter_indexes[0]);
1219 eftp->eft_mulcst_filter_count = 1;
1220 eftp->eft_using_all_mulcst = B_TRUE;
1223 * FIXME: If brdcst == B_FALSE, add a filter to drop broadcast traffic.
1229 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1234 typedef struct ef10_filter_encap_entry_s {
1235 uint16_t ether_type;
1236 efx_tunnel_protocol_t encap_type;
1237 uint32_t inner_frame_match;
1238 } ef10_filter_encap_entry_t;
1240 #define EF10_ENCAP_FILTER_ENTRY(ipv, encap_type, inner_frame_match) \
1241 { EFX_ETHER_TYPE_##ipv, EFX_TUNNEL_PROTOCOL_##encap_type, \
1242 EFX_FILTER_INNER_FRAME_MATCH_UNKNOWN_##inner_frame_match }
1244 static ef10_filter_encap_entry_t ef10_filter_encap_list[] = {
1245 EF10_ENCAP_FILTER_ENTRY(IPV4, VXLAN, UCAST_DST),
1246 EF10_ENCAP_FILTER_ENTRY(IPV4, VXLAN, MCAST_DST),
1247 EF10_ENCAP_FILTER_ENTRY(IPV6, VXLAN, UCAST_DST),
1248 EF10_ENCAP_FILTER_ENTRY(IPV6, VXLAN, MCAST_DST),
1250 EF10_ENCAP_FILTER_ENTRY(IPV4, GENEVE, UCAST_DST),
1251 EF10_ENCAP_FILTER_ENTRY(IPV4, GENEVE, MCAST_DST),
1252 EF10_ENCAP_FILTER_ENTRY(IPV6, GENEVE, UCAST_DST),
1253 EF10_ENCAP_FILTER_ENTRY(IPV6, GENEVE, MCAST_DST),
1255 EF10_ENCAP_FILTER_ENTRY(IPV4, NVGRE, UCAST_DST),
1256 EF10_ENCAP_FILTER_ENTRY(IPV4, NVGRE, MCAST_DST),
1257 EF10_ENCAP_FILTER_ENTRY(IPV6, NVGRE, UCAST_DST),
1258 EF10_ENCAP_FILTER_ENTRY(IPV6, NVGRE, MCAST_DST),
1261 #undef EF10_ENCAP_FILTER_ENTRY
1263 static __checkReturn efx_rc_t
1264 ef10_filter_insert_encap_filters(
1265 __in efx_nic_t *enp,
1266 __in boolean_t mulcst,
1267 __in efx_filter_flags_t filter_flags)
1269 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
1273 EFX_STATIC_ASSERT(EFX_ARRAY_SIZE(ef10_filter_encap_list) <=
1274 EFX_ARRAY_SIZE(table->eft_encap_filter_indexes));
1277 * On Medford, full-featured firmware can identify packets as being
1278 * tunnel encapsulated, even if no encapsulated packet offloads are in
1279 * use. When packets are identified as such, ordinary filters are not
1280 * applied, only ones specific to encapsulated packets. Hence we need to
1281 * insert filters for encapsulated packets in order to receive them.
1283 * Separate filters need to be inserted for each ether type,
1284 * encapsulation type, and inner frame type (unicast or multicast). To
1285 * keep things simple and reduce the number of filters needed, catch-all
1286 * filters for all combinations of types are inserted, even if
1287 * all_unicst or all_mulcst have not been set. (These catch-all filters
1288 * may well, however, fail to insert on unprivileged functions.)
1290 table->eft_encap_filter_count = 0;
1291 for (i = 0; i < EFX_ARRAY_SIZE(ef10_filter_encap_list); i++) {
1292 efx_filter_spec_t spec;
1293 ef10_filter_encap_entry_t *encap_filter =
1294 &ef10_filter_encap_list[i];
1297 * Skip multicast filters if we've not been asked for
1298 * any multicast traffic.
1300 if ((mulcst == B_FALSE) &&
1301 (encap_filter->inner_frame_match ==
1302 EFX_FILTER_INNER_FRAME_MATCH_UNKNOWN_MCAST_DST))
1305 efx_filter_spec_init_rx(&spec, EFX_FILTER_PRI_AUTO,
1307 table->eft_default_rxq);
1308 efx_filter_spec_set_ether_type(&spec, encap_filter->ether_type);
1309 rc = efx_filter_spec_set_encap_type(&spec,
1310 encap_filter->encap_type,
1311 encap_filter->inner_frame_match);
1315 rc = ef10_filter_add_internal(enp, &spec, B_TRUE,
1316 &table->eft_encap_filter_indexes[
1317 table->eft_encap_filter_count]);
1322 table->eft_encap_filter_count++;
1331 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1337 ef10_filter_remove_old(
1338 __in efx_nic_t *enp)
1340 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
1343 for (i = 0; i < EFX_ARRAY_SIZE(table->eft_entry); i++) {
1344 if (ef10_filter_entry_is_auto_old(table, i)) {
1345 (void) ef10_filter_delete_internal(enp, i);
1351 static __checkReturn efx_rc_t
1352 ef10_filter_get_workarounds(
1353 __in efx_nic_t *enp)
1355 efx_nic_cfg_t *encp = &enp->en_nic_cfg;
1356 uint32_t implemented = 0;
1357 uint32_t enabled = 0;
1360 rc = efx_mcdi_get_workarounds(enp, &implemented, &enabled);
1362 /* Check if chained multicast filter support is enabled */
1363 if (implemented & enabled & MC_CMD_GET_WORKAROUNDS_OUT_BUG26807)
1364 encp->enc_bug26807_workaround = B_TRUE;
1366 encp->enc_bug26807_workaround = B_FALSE;
1367 } else if (rc == ENOTSUP) {
1369 * Firmware is too old to support GET_WORKAROUNDS, and support
1370 * for this workaround was implemented later.
1372 encp->enc_bug26807_workaround = B_FALSE;
1380 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1388 * Reconfigure all filters.
1389 * If all_unicst and/or all mulcst filters cannot be applied then
1390 * return ENOTSUP (Note the filters for the specified addresses are
1391 * still applied in this case).
1393 __checkReturn efx_rc_t
1394 ef10_filter_reconfigure(
1395 __in efx_nic_t *enp,
1396 __in_ecount(6) uint8_t const *mac_addr,
1397 __in boolean_t all_unicst,
1398 __in boolean_t mulcst,
1399 __in boolean_t all_mulcst,
1400 __in boolean_t brdcst,
1401 __in_ecount(6*count) uint8_t const *addrs,
1402 __in uint32_t count)
1404 efx_nic_cfg_t *encp = &enp->en_nic_cfg;
1405 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
1406 efx_filter_flags_t filter_flags;
1408 efx_rc_t all_unicst_rc = 0;
1409 efx_rc_t all_mulcst_rc = 0;
1412 if (table->eft_default_rxq == NULL) {
1414 * Filters direct traffic to the default RXQ, and so cannot be
1415 * inserted until it is available. Any currently configured
1416 * filters must be removed (ignore errors in case the MC
1417 * has rebooted, which removes hardware filters).
1419 for (i = 0; i < table->eft_unicst_filter_count; i++) {
1420 (void) ef10_filter_delete_internal(enp,
1421 table->eft_unicst_filter_indexes[i]);
1423 table->eft_unicst_filter_count = 0;
1425 for (i = 0; i < table->eft_mulcst_filter_count; i++) {
1426 (void) ef10_filter_delete_internal(enp,
1427 table->eft_mulcst_filter_indexes[i]);
1429 table->eft_mulcst_filter_count = 0;
1431 for (i = 0; i < table->eft_encap_filter_count; i++) {
1432 (void) ef10_filter_delete_internal(enp,
1433 table->eft_encap_filter_indexes[i]);
1435 table->eft_encap_filter_count = 0;
1440 if (table->eft_using_rss)
1441 filter_flags = EFX_FILTER_FLAG_RX_RSS;
1445 /* Mark old filters which may need to be removed */
1446 for (i = 0; i < table->eft_unicst_filter_count; i++) {
1447 ef10_filter_set_entry_auto_old(table,
1448 table->eft_unicst_filter_indexes[i]);
1450 for (i = 0; i < table->eft_mulcst_filter_count; i++) {
1451 ef10_filter_set_entry_auto_old(table,
1452 table->eft_mulcst_filter_indexes[i]);
1454 for (i = 0; i < table->eft_encap_filter_count; i++) {
1455 ef10_filter_set_entry_auto_old(table,
1456 table->eft_encap_filter_indexes[i]);
1460 * Insert or renew unicast filters.
1462 * Frimware does not perform chaining on unicast filters. As traffic is
1463 * therefore only delivered to the first matching filter, we should
1464 * always insert the specific filter for our MAC address, to try and
1465 * ensure we get that traffic.
1467 * (If the filter for our MAC address has already been inserted by
1468 * another function, we won't receive traffic sent to us, even if we
1469 * insert a unicast mismatch filter. To prevent traffic stealing, this
1470 * therefore relies on the privilege model only allowing functions to
1471 * insert filters for their own MAC address unless explicitly given
1472 * additional privileges by the user. This also means that, even on a
1473 * priviliged function, inserting a unicast mismatch filter may not
1474 * catch all traffic in multi PCI function scenarios.)
1476 table->eft_unicst_filter_count = 0;
1477 rc = ef10_filter_insert_unicast(enp, mac_addr, filter_flags);
1478 if (all_unicst || (rc != 0)) {
1479 all_unicst_rc = ef10_filter_insert_all_unicast(enp,
1481 if ((rc != 0) && (all_unicst_rc != 0))
1486 * WORKAROUND_BUG26807 controls firmware support for chained multicast
1487 * filters, and can only be enabled or disabled when the hardware filter
1490 * Chained multicast filters require support from the datapath firmware,
1491 * and may not be available (e.g. low-latency variants or old Huntington
1494 * Firmware will reset (FLR) functions which have inserted filters in
1495 * the hardware filter table when the workaround is enabled/disabled.
1496 * Functions without any hardware filters are not reset.
1498 * Re-check if the workaround is enabled after adding unicast hardware
1499 * filters. This ensures that encp->enc_bug26807_workaround matches the
1500 * firmware state, and that later changes to enable/disable the
1501 * workaround will result in this function seeing a reset (FLR).
1503 * In common-code drivers, we only support multiple PCI function
1504 * scenarios with firmware that supports multicast chaining, so we can
1505 * assume it is enabled for such cases and hence simplify the filter
1506 * insertion logic. Firmware that does not support multicast chaining
1507 * does not support multiple PCI function configurations either, so
1508 * filter insertion is much simpler and the same strategies can still be
1511 if ((rc = ef10_filter_get_workarounds(enp)) != 0)
1514 if ((table->eft_using_all_mulcst != all_mulcst) &&
1515 (encp->enc_bug26807_workaround == B_TRUE)) {
1517 * Multicast filter chaining is enabled, so traffic that matches
1518 * more than one multicast filter will be replicated and
1519 * delivered to multiple recipients. To avoid this duplicate
1520 * delivery, remove old multicast filters before inserting new
1521 * multicast filters.
1523 ef10_filter_remove_old(enp);
1526 /* Insert or renew multicast filters */
1527 if (all_mulcst == B_TRUE) {
1529 * Insert the all multicast filter. If that fails, try to insert
1530 * all of our multicast filters (but without rollback on
1533 all_mulcst_rc = ef10_filter_insert_all_multicast(enp,
1535 if (all_mulcst_rc != 0) {
1536 rc = ef10_filter_insert_multicast_list(enp, B_TRUE,
1537 brdcst, addrs, count, filter_flags, B_FALSE);
1543 * Insert filters for multicast addresses.
1544 * If any insertion fails, then rollback and try to insert the
1545 * all multicast filter instead.
1546 * If that also fails, try to insert all of the multicast
1547 * filters (but without rollback on failure).
1549 rc = ef10_filter_insert_multicast_list(enp, mulcst, brdcst,
1550 addrs, count, filter_flags, B_TRUE);
1552 if ((table->eft_using_all_mulcst == B_FALSE) &&
1553 (encp->enc_bug26807_workaround == B_TRUE)) {
1555 * Multicast filter chaining is on, so remove
1556 * old filters before inserting the multicast
1557 * all filter to avoid duplicate delivery caused
1558 * by packets matching multiple filters.
1560 ef10_filter_remove_old(enp);
1563 rc = ef10_filter_insert_all_multicast(enp,
1566 rc = ef10_filter_insert_multicast_list(enp,
1568 addrs, count, filter_flags, B_FALSE);
1575 if (encp->enc_tunnel_encapsulations_supported != 0) {
1576 /* Try to insert filters for encapsulated packets. */
1577 (void) ef10_filter_insert_encap_filters(enp,
1578 mulcst || all_mulcst || brdcst,
1582 /* Remove old filters which were not renewed */
1583 ef10_filter_remove_old(enp);
1585 /* report if any optional flags were rejected */
1586 if (((all_unicst != B_FALSE) && (all_unicst_rc != 0)) ||
1587 ((all_mulcst != B_FALSE) && (all_mulcst_rc != 0))) {
1600 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1602 /* Clear auto old flags */
1603 for (i = 0; i < EFX_ARRAY_SIZE(table->eft_entry); i++) {
1604 if (ef10_filter_entry_is_auto_old(table, i)) {
1605 ef10_filter_set_entry_not_auto_old(table, i);
1613 ef10_filter_get_default_rxq(
1614 __in efx_nic_t *enp,
1615 __out efx_rxq_t **erpp,
1616 __out boolean_t *using_rss)
1618 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
1620 *erpp = table->eft_default_rxq;
1621 *using_rss = table->eft_using_rss;
1626 ef10_filter_default_rxq_set(
1627 __in efx_nic_t *enp,
1628 __in efx_rxq_t *erp,
1629 __in boolean_t using_rss)
1631 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
1633 #if EFSYS_OPT_RX_SCALE
1634 EFSYS_ASSERT((using_rss == B_FALSE) ||
1635 (enp->en_rss_context != EF10_RSS_CONTEXT_INVALID));
1636 table->eft_using_rss = using_rss;
1638 EFSYS_ASSERT(using_rss == B_FALSE);
1639 table->eft_using_rss = B_FALSE;
1641 table->eft_default_rxq = erp;
1645 ef10_filter_default_rxq_clear(
1646 __in efx_nic_t *enp)
1648 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
1650 table->eft_default_rxq = NULL;
1651 table->eft_using_rss = B_FALSE;
1655 #endif /* EFSYS_OPT_FILTER */
1657 #endif /* EFSYS_OPT_HUNTINGTON || EFSYS_OPT_MEDFORD */