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 EFX_MCDI_DECLARE_BUF(payload, MC_CMD_FILTER_OP_EXT_IN_LEN,
194 MC_CMD_FILTER_OP_EXT_OUT_LEN);
197 req.emr_cmd = MC_CMD_FILTER_OP;
198 req.emr_in_buf = payload;
199 req.emr_in_length = MC_CMD_FILTER_OP_EXT_IN_LEN;
200 req.emr_out_buf = payload;
201 req.emr_out_length = MC_CMD_FILTER_OP_EXT_OUT_LEN;
204 case MC_CMD_FILTER_OP_IN_OP_REPLACE:
205 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_HANDLE_LO,
207 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_HANDLE_HI,
210 case MC_CMD_FILTER_OP_IN_OP_INSERT:
211 case MC_CMD_FILTER_OP_IN_OP_SUBSCRIBE:
212 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_OP, filter_op);
220 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_PORT_ID,
221 EVB_PORT_ID_ASSIGNED);
222 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_MATCH_FIELDS,
223 spec->efs_match_flags);
224 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_RX_DEST,
225 MC_CMD_FILTER_OP_EXT_IN_RX_DEST_HOST);
226 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_RX_QUEUE,
229 #if EFSYS_OPT_RX_SCALE
230 if (spec->efs_flags & EFX_FILTER_FLAG_RX_RSS) {
231 uint32_t rss_context;
233 if (spec->efs_rss_context == EFX_RSS_CONTEXT_DEFAULT)
234 rss_context = enp->en_rss_context;
236 rss_context = spec->efs_rss_context;
237 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_RX_CONTEXT,
242 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_RX_MODE,
243 spec->efs_flags & EFX_FILTER_FLAG_RX_RSS ?
244 MC_CMD_FILTER_OP_EXT_IN_RX_MODE_RSS :
245 MC_CMD_FILTER_OP_EXT_IN_RX_MODE_SIMPLE);
246 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_TX_DEST,
247 MC_CMD_FILTER_OP_EXT_IN_TX_DEST_DEFAULT);
249 if (filter_op != MC_CMD_FILTER_OP_IN_OP_REPLACE) {
251 * NOTE: Unlike most MCDI requests, the filter fields
252 * are presented in network (big endian) byte order.
254 memcpy(MCDI_IN2(req, uint8_t, FILTER_OP_EXT_IN_SRC_MAC),
255 spec->efs_rem_mac, EFX_MAC_ADDR_LEN);
256 memcpy(MCDI_IN2(req, uint8_t, FILTER_OP_EXT_IN_DST_MAC),
257 spec->efs_loc_mac, EFX_MAC_ADDR_LEN);
259 MCDI_IN_SET_WORD(req, FILTER_OP_EXT_IN_SRC_PORT,
260 __CPU_TO_BE_16(spec->efs_rem_port));
261 MCDI_IN_SET_WORD(req, FILTER_OP_EXT_IN_DST_PORT,
262 __CPU_TO_BE_16(spec->efs_loc_port));
264 MCDI_IN_SET_WORD(req, FILTER_OP_EXT_IN_ETHER_TYPE,
265 __CPU_TO_BE_16(spec->efs_ether_type));
267 MCDI_IN_SET_WORD(req, FILTER_OP_EXT_IN_INNER_VLAN,
268 __CPU_TO_BE_16(spec->efs_inner_vid));
269 MCDI_IN_SET_WORD(req, FILTER_OP_EXT_IN_OUTER_VLAN,
270 __CPU_TO_BE_16(spec->efs_outer_vid));
272 /* IP protocol (in low byte, high byte is zero) */
273 MCDI_IN_SET_BYTE(req, FILTER_OP_EXT_IN_IP_PROTO,
276 EFX_STATIC_ASSERT(sizeof (spec->efs_rem_host) ==
277 MC_CMD_FILTER_OP_EXT_IN_SRC_IP_LEN);
278 EFX_STATIC_ASSERT(sizeof (spec->efs_loc_host) ==
279 MC_CMD_FILTER_OP_EXT_IN_DST_IP_LEN);
281 memcpy(MCDI_IN2(req, uint8_t, FILTER_OP_EXT_IN_SRC_IP),
282 &spec->efs_rem_host.eo_byte[0],
283 MC_CMD_FILTER_OP_EXT_IN_SRC_IP_LEN);
284 memcpy(MCDI_IN2(req, uint8_t, FILTER_OP_EXT_IN_DST_IP),
285 &spec->efs_loc_host.eo_byte[0],
286 MC_CMD_FILTER_OP_EXT_IN_DST_IP_LEN);
289 * On Medford, filters for encapsulated packets match based on
290 * the ether type and IP protocol in the outer frame. In
291 * addition we need to fill in the VNI or VSID type field.
293 switch (spec->efs_encap_type) {
294 case EFX_TUNNEL_PROTOCOL_NONE:
296 case EFX_TUNNEL_PROTOCOL_VXLAN:
297 case EFX_TUNNEL_PROTOCOL_GENEVE:
298 MCDI_IN_POPULATE_DWORD_1(req,
299 FILTER_OP_EXT_IN_VNI_OR_VSID,
300 FILTER_OP_EXT_IN_VNI_TYPE,
301 spec->efs_encap_type == EFX_TUNNEL_PROTOCOL_VXLAN ?
302 MC_CMD_FILTER_OP_EXT_IN_VNI_TYPE_VXLAN :
303 MC_CMD_FILTER_OP_EXT_IN_VNI_TYPE_GENEVE);
305 case EFX_TUNNEL_PROTOCOL_NVGRE:
306 MCDI_IN_POPULATE_DWORD_1(req,
307 FILTER_OP_EXT_IN_VNI_OR_VSID,
308 FILTER_OP_EXT_IN_VSID_TYPE,
309 MC_CMD_FILTER_OP_EXT_IN_VSID_TYPE_NVGRE);
318 efx_mcdi_execute(enp, &req);
320 if (req.emr_rc != 0) {
325 if (req.emr_out_length_used < MC_CMD_FILTER_OP_EXT_OUT_LEN) {
330 handle->efh_lo = MCDI_OUT_DWORD(req, FILTER_OP_EXT_OUT_HANDLE_LO);
331 handle->efh_hi = MCDI_OUT_DWORD(req, FILTER_OP_EXT_OUT_HANDLE_HI);
342 EFSYS_PROBE1(fail1, efx_rc_t, rc);
348 static __checkReturn efx_rc_t
349 efx_mcdi_filter_op_delete(
351 __in unsigned int filter_op,
352 __inout ef10_filter_handle_t *handle)
355 EFX_MCDI_DECLARE_BUF(payload, MC_CMD_FILTER_OP_EXT_IN_LEN,
356 MC_CMD_FILTER_OP_EXT_OUT_LEN);
359 req.emr_cmd = MC_CMD_FILTER_OP;
360 req.emr_in_buf = payload;
361 req.emr_in_length = MC_CMD_FILTER_OP_EXT_IN_LEN;
362 req.emr_out_buf = payload;
363 req.emr_out_length = MC_CMD_FILTER_OP_EXT_OUT_LEN;
366 case MC_CMD_FILTER_OP_IN_OP_REMOVE:
367 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_OP,
368 MC_CMD_FILTER_OP_IN_OP_REMOVE);
370 case MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE:
371 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_OP,
372 MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE);
380 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_HANDLE_LO, handle->efh_lo);
381 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_HANDLE_HI, handle->efh_hi);
383 efx_mcdi_execute_quiet(enp, &req);
385 if (req.emr_rc != 0) {
390 if (req.emr_out_length_used < MC_CMD_FILTER_OP_EXT_OUT_LEN) {
403 EFSYS_PROBE1(fail1, efx_rc_t, rc);
408 static __checkReturn boolean_t
410 __in const efx_filter_spec_t *left,
411 __in const efx_filter_spec_t *right)
413 /* FIXME: Consider rx vs tx filters (look at efs_flags) */
414 if (left->efs_match_flags != right->efs_match_flags)
416 if (!EFX_OWORD_IS_EQUAL(left->efs_rem_host, right->efs_rem_host))
418 if (!EFX_OWORD_IS_EQUAL(left->efs_loc_host, right->efs_loc_host))
420 if (memcmp(left->efs_rem_mac, right->efs_rem_mac, EFX_MAC_ADDR_LEN))
422 if (memcmp(left->efs_loc_mac, right->efs_loc_mac, EFX_MAC_ADDR_LEN))
424 if (left->efs_rem_port != right->efs_rem_port)
426 if (left->efs_loc_port != right->efs_loc_port)
428 if (left->efs_inner_vid != right->efs_inner_vid)
430 if (left->efs_outer_vid != right->efs_outer_vid)
432 if (left->efs_ether_type != right->efs_ether_type)
434 if (left->efs_ip_proto != right->efs_ip_proto)
436 if (left->efs_encap_type != right->efs_encap_type)
443 static __checkReturn boolean_t
444 ef10_filter_same_dest(
445 __in const efx_filter_spec_t *left,
446 __in const efx_filter_spec_t *right)
448 if ((left->efs_flags & EFX_FILTER_FLAG_RX_RSS) &&
449 (right->efs_flags & EFX_FILTER_FLAG_RX_RSS)) {
450 if (left->efs_rss_context == right->efs_rss_context)
452 } else if ((~(left->efs_flags) & EFX_FILTER_FLAG_RX_RSS) &&
453 (~(right->efs_flags) & EFX_FILTER_FLAG_RX_RSS)) {
454 if (left->efs_dmaq_id == right->efs_dmaq_id)
460 static __checkReturn uint32_t
462 __in efx_filter_spec_t *spec)
464 EFX_STATIC_ASSERT((sizeof (efx_filter_spec_t) % sizeof (uint32_t))
466 EFX_STATIC_ASSERT((EFX_FIELD_OFFSET(efx_filter_spec_t, efs_outer_vid) %
467 sizeof (uint32_t)) == 0);
470 * As the area of the efx_filter_spec_t we need to hash is DWORD
471 * aligned and an exact number of DWORDs in size we can use the
472 * optimised efx_hash_dwords() rather than efx_hash_bytes()
474 return (efx_hash_dwords((const uint32_t *)&spec->efs_outer_vid,
475 (sizeof (efx_filter_spec_t) -
476 EFX_FIELD_OFFSET(efx_filter_spec_t, efs_outer_vid)) /
477 sizeof (uint32_t), 0));
481 * Decide whether a filter should be exclusive or else should allow
482 * delivery to additional recipients. Currently we decide that
483 * filters for specific local unicast MAC and IP addresses are
486 static __checkReturn boolean_t
487 ef10_filter_is_exclusive(
488 __in efx_filter_spec_t *spec)
490 if ((spec->efs_match_flags & EFX_FILTER_MATCH_LOC_MAC) &&
491 !EFX_MAC_ADDR_IS_MULTICAST(spec->efs_loc_mac))
494 if ((spec->efs_match_flags &
495 (EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_LOC_HOST)) ==
496 (EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_LOC_HOST)) {
497 if ((spec->efs_ether_type == EFX_ETHER_TYPE_IPV4) &&
498 ((spec->efs_loc_host.eo_u8[0] & 0xf) != 0xe))
500 if ((spec->efs_ether_type == EFX_ETHER_TYPE_IPV6) &&
501 (spec->efs_loc_host.eo_u8[0] != 0xff))
508 __checkReturn efx_rc_t
513 efx_filter_spec_t *spec;
514 ef10_filter_table_t *eftp = enp->en_filter.ef_ef10_filter_table;
516 efsys_lock_state_t state;
519 EFSYS_ASSERT(enp->en_family == EFX_FAMILY_HUNTINGTON ||
520 enp->en_family == EFX_FAMILY_MEDFORD);
522 for (tbl_id = 0; tbl_id < EFX_EF10_FILTER_TBL_ROWS; tbl_id++) {
524 EFSYS_LOCK(enp->en_eslp, state);
526 spec = ef10_filter_entry_spec(eftp, tbl_id);
529 } else if (ef10_filter_entry_is_busy(eftp, tbl_id)) {
530 /* Ignore busy entries. */
533 ef10_filter_set_entry_busy(eftp, tbl_id);
537 EFSYS_UNLOCK(enp->en_eslp, state);
539 if (restoring == B_FALSE)
542 if (ef10_filter_is_exclusive(spec)) {
543 rc = efx_mcdi_filter_op_add(enp, spec,
544 MC_CMD_FILTER_OP_IN_OP_INSERT,
545 &eftp->eft_entry[tbl_id].efe_handle);
547 rc = efx_mcdi_filter_op_add(enp, spec,
548 MC_CMD_FILTER_OP_IN_OP_SUBSCRIBE,
549 &eftp->eft_entry[tbl_id].efe_handle);
555 EFSYS_LOCK(enp->en_eslp, state);
557 ef10_filter_set_entry_not_busy(eftp, tbl_id);
559 EFSYS_UNLOCK(enp->en_eslp, state);
565 EFSYS_PROBE1(fail1, efx_rc_t, rc);
571 * An arbitrary search limit for the software hash table. As per the linux net
574 #define EF10_FILTER_SEARCH_LIMIT 200
576 static __checkReturn efx_rc_t
577 ef10_filter_add_internal(
579 __inout efx_filter_spec_t *spec,
580 __in boolean_t may_replace,
581 __out_opt uint32_t *filter_id)
584 ef10_filter_table_t *eftp = enp->en_filter.ef_ef10_filter_table;
585 efx_filter_spec_t *saved_spec;
589 boolean_t replacing = B_FALSE;
591 efsys_lock_state_t state;
592 boolean_t locked = B_FALSE;
594 EFSYS_ASSERT(enp->en_family == EFX_FAMILY_HUNTINGTON ||
595 enp->en_family == EFX_FAMILY_MEDFORD);
597 hash = ef10_filter_hash(spec);
600 * FIXME: Add support for inserting filters of different priorities
601 * and removing lower priority multicast filters (bug 42378)
605 * Find any existing filters with the same match tuple or
606 * else a free slot to insert at. If any of them are busy,
607 * we have to wait and retry.
612 EFSYS_LOCK(enp->en_eslp, state);
616 i = (hash + depth) & (EFX_EF10_FILTER_TBL_ROWS - 1);
617 saved_spec = ef10_filter_entry_spec(eftp, i);
623 } else if (ef10_filter_equal(spec, saved_spec)) {
624 if (ef10_filter_entry_is_busy(eftp, i))
626 if (saved_spec->efs_priority
627 == EFX_FILTER_PRI_AUTO) {
630 } else if (ef10_filter_is_exclusive(spec)) {
644 * Once we reach the maximum search depth, use
645 * the first suitable slot or return EBUSY if
648 if (depth == EF10_FILTER_SEARCH_LIMIT) {
657 EFSYS_UNLOCK(enp->en_eslp, state);
663 * Create a software table entry if necessary, and mark it
664 * busy. We might yet fail to insert, but any attempt to
665 * insert a conflicting filter while we're waiting for the
666 * firmware must find the busy entry.
668 saved_spec = ef10_filter_entry_spec(eftp, ins_index);
670 if (saved_spec->efs_priority == EFX_FILTER_PRI_AUTO) {
671 /* This is a filter we are refreshing */
672 ef10_filter_set_entry_not_auto_old(eftp, ins_index);
678 EFSYS_KMEM_ALLOC(enp->en_esip, sizeof (*spec), saved_spec);
684 ef10_filter_set_entry(eftp, ins_index, saved_spec);
686 ef10_filter_set_entry_busy(eftp, ins_index);
688 EFSYS_UNLOCK(enp->en_eslp, state);
692 * On replacing the filter handle may change after after a successful
696 rc = efx_mcdi_filter_op_add(enp, spec,
697 MC_CMD_FILTER_OP_IN_OP_REPLACE,
698 &eftp->eft_entry[ins_index].efe_handle);
699 } else if (ef10_filter_is_exclusive(spec)) {
700 rc = efx_mcdi_filter_op_add(enp, spec,
701 MC_CMD_FILTER_OP_IN_OP_INSERT,
702 &eftp->eft_entry[ins_index].efe_handle);
704 rc = efx_mcdi_filter_op_add(enp, spec,
705 MC_CMD_FILTER_OP_IN_OP_SUBSCRIBE,
706 &eftp->eft_entry[ins_index].efe_handle);
712 EFSYS_LOCK(enp->en_eslp, state);
716 /* Update the fields that may differ */
717 saved_spec->efs_priority = spec->efs_priority;
718 saved_spec->efs_flags = spec->efs_flags;
719 saved_spec->efs_rss_context = spec->efs_rss_context;
720 saved_spec->efs_dmaq_id = spec->efs_dmaq_id;
723 ef10_filter_set_entry_not_busy(eftp, ins_index);
727 EFSYS_UNLOCK(enp->en_eslp, state);
731 *filter_id = ins_index;
739 EFSYS_KMEM_FREE(enp->en_esip, sizeof (*spec), saved_spec);
742 ef10_filter_set_entry_not_busy(eftp, ins_index);
743 ef10_filter_set_entry(eftp, ins_index, NULL);
752 EFSYS_PROBE1(fail1, efx_rc_t, rc);
755 EFSYS_UNLOCK(enp->en_eslp, state);
760 __checkReturn efx_rc_t
763 __inout efx_filter_spec_t *spec,
764 __in boolean_t may_replace)
768 rc = ef10_filter_add_internal(enp, spec, may_replace, NULL);
775 EFSYS_PROBE1(fail1, efx_rc_t, rc);
781 static __checkReturn efx_rc_t
782 ef10_filter_delete_internal(
784 __in uint32_t filter_id)
787 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
788 efx_filter_spec_t *spec;
789 efsys_lock_state_t state;
790 uint32_t filter_idx = filter_id % EFX_EF10_FILTER_TBL_ROWS;
793 * Find the software table entry and mark it busy. Don't
794 * remove it yet; any attempt to update while we're waiting
795 * for the firmware must find the busy entry.
797 * FIXME: What if the busy flag is never cleared?
799 EFSYS_LOCK(enp->en_eslp, state);
800 while (ef10_filter_entry_is_busy(table, filter_idx)) {
801 EFSYS_UNLOCK(enp->en_eslp, state);
803 EFSYS_LOCK(enp->en_eslp, state);
805 if ((spec = ef10_filter_entry_spec(table, filter_idx)) != NULL) {
806 ef10_filter_set_entry_busy(table, filter_idx);
808 EFSYS_UNLOCK(enp->en_eslp, state);
816 * Try to remove the hardware filter. This may fail if the MC has
817 * rebooted (which frees all hardware filter resources).
819 if (ef10_filter_is_exclusive(spec)) {
820 rc = efx_mcdi_filter_op_delete(enp,
821 MC_CMD_FILTER_OP_IN_OP_REMOVE,
822 &table->eft_entry[filter_idx].efe_handle);
824 rc = efx_mcdi_filter_op_delete(enp,
825 MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE,
826 &table->eft_entry[filter_idx].efe_handle);
829 /* Free the software table entry */
830 EFSYS_LOCK(enp->en_eslp, state);
831 ef10_filter_set_entry_not_busy(table, filter_idx);
832 ef10_filter_set_entry(table, filter_idx, NULL);
833 EFSYS_UNLOCK(enp->en_eslp, state);
835 EFSYS_KMEM_FREE(enp->en_esip, sizeof (*spec), spec);
837 /* Check result of hardware filter removal */
847 EFSYS_PROBE1(fail1, efx_rc_t, rc);
852 __checkReturn efx_rc_t
855 __inout efx_filter_spec_t *spec)
858 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
859 efx_filter_spec_t *saved_spec;
863 efsys_lock_state_t state;
864 boolean_t locked = B_FALSE;
866 EFSYS_ASSERT(enp->en_family == EFX_FAMILY_HUNTINGTON ||
867 enp->en_family == EFX_FAMILY_MEDFORD);
869 hash = ef10_filter_hash(spec);
871 EFSYS_LOCK(enp->en_eslp, state);
876 i = (hash + depth) & (EFX_EF10_FILTER_TBL_ROWS - 1);
877 saved_spec = ef10_filter_entry_spec(table, i);
878 if (saved_spec && ef10_filter_equal(spec, saved_spec) &&
879 ef10_filter_same_dest(spec, saved_spec)) {
882 if (depth == EF10_FILTER_SEARCH_LIMIT) {
889 EFSYS_UNLOCK(enp->en_eslp, state);
892 rc = ef10_filter_delete_internal(enp, i);
902 EFSYS_PROBE1(fail1, efx_rc_t, rc);
905 EFSYS_UNLOCK(enp->en_eslp, state);
910 static __checkReturn efx_rc_t
911 efx_mcdi_get_parser_disp_info(
913 __out_ecount(buffer_length) uint32_t *buffer,
914 __in size_t buffer_length,
915 __out size_t *list_lengthp)
918 EFX_MCDI_DECLARE_BUF(payload, MC_CMD_GET_PARSER_DISP_INFO_IN_LEN,
919 MC_CMD_GET_PARSER_DISP_INFO_OUT_LENMAX);
920 size_t matches_count;
924 req.emr_cmd = MC_CMD_GET_PARSER_DISP_INFO;
925 req.emr_in_buf = payload;
926 req.emr_in_length = MC_CMD_GET_PARSER_DISP_INFO_IN_LEN;
927 req.emr_out_buf = payload;
928 req.emr_out_length = MC_CMD_GET_PARSER_DISP_INFO_OUT_LENMAX;
930 MCDI_IN_SET_DWORD(req, GET_PARSER_DISP_INFO_OUT_OP,
931 MC_CMD_GET_PARSER_DISP_INFO_IN_OP_GET_SUPPORTED_RX_MATCHES);
933 efx_mcdi_execute(enp, &req);
935 if (req.emr_rc != 0) {
940 matches_count = MCDI_OUT_DWORD(req,
941 GET_PARSER_DISP_INFO_OUT_NUM_SUPPORTED_MATCHES);
943 if (req.emr_out_length_used <
944 MC_CMD_GET_PARSER_DISP_INFO_OUT_LEN(matches_count)) {
949 *list_lengthp = matches_count;
951 if (buffer_length < matches_count) {
957 * Check that the elements in the list in the MCDI response are the size
958 * we expect, so we can just copy them directly. Any conversion of the
959 * flags is handled by the caller.
961 EFX_STATIC_ASSERT(sizeof (uint32_t) ==
962 MC_CMD_GET_PARSER_DISP_INFO_OUT_SUPPORTED_MATCHES_LEN);
964 list_size = matches_count *
965 MC_CMD_GET_PARSER_DISP_INFO_OUT_SUPPORTED_MATCHES_LEN;
967 MCDI_OUT2(req, uint32_t,
968 GET_PARSER_DISP_INFO_OUT_SUPPORTED_MATCHES),
978 EFSYS_PROBE1(fail1, efx_rc_t, rc);
983 __checkReturn efx_rc_t
984 ef10_filter_supported_filters(
986 __out_ecount(buffer_length) uint32_t *buffer,
987 __in size_t buffer_length,
988 __out size_t *list_lengthp)
991 size_t mcdi_list_length;
995 uint32_t all_filter_flags =
996 (EFX_FILTER_MATCH_REM_HOST | EFX_FILTER_MATCH_LOC_HOST |
997 EFX_FILTER_MATCH_REM_MAC | EFX_FILTER_MATCH_REM_PORT |
998 EFX_FILTER_MATCH_LOC_MAC | EFX_FILTER_MATCH_LOC_PORT |
999 EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_INNER_VID |
1000 EFX_FILTER_MATCH_OUTER_VID | EFX_FILTER_MATCH_IP_PROTO |
1001 EFX_FILTER_MATCH_UNKNOWN_MCAST_DST |
1002 EFX_FILTER_MATCH_UNKNOWN_UCAST_DST);
1004 rc = efx_mcdi_get_parser_disp_info(enp, buffer, buffer_length,
1008 /* Pass through mcdi_list_length for the list length */
1009 *list_lengthp = mcdi_list_length;
1015 * The static assertions in ef10_filter_init() ensure that the values of
1016 * the EFX_FILTER_MATCH flags match those used by MCDI, so they don't
1017 * need to be converted.
1019 * In case support is added to MCDI for additional flags, remove any
1020 * matches from the list which include flags we don't support. The order
1021 * of the matches is preserved as they are ordered from highest to
1024 EFSYS_ASSERT(mcdi_list_length <= buffer_length);
1026 for (i = 0; i < mcdi_list_length; i++) {
1027 if ((buffer[i] & ~all_filter_flags) == 0) {
1028 buffer[list_length] = buffer[i];
1033 *list_lengthp = list_length;
1038 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1043 static __checkReturn efx_rc_t
1044 ef10_filter_insert_unicast(
1045 __in efx_nic_t *enp,
1046 __in_ecount(6) uint8_t const *addr,
1047 __in efx_filter_flags_t filter_flags)
1049 ef10_filter_table_t *eftp = enp->en_filter.ef_ef10_filter_table;
1050 efx_filter_spec_t spec;
1053 /* Insert the filter for the local station address */
1054 efx_filter_spec_init_rx(&spec, EFX_FILTER_PRI_AUTO,
1056 eftp->eft_default_rxq);
1057 rc = efx_filter_spec_set_eth_local(&spec, EFX_FILTER_SPEC_VID_UNSPEC,
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);
1076 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1080 static __checkReturn efx_rc_t
1081 ef10_filter_insert_all_unicast(
1082 __in efx_nic_t *enp,
1083 __in efx_filter_flags_t filter_flags)
1085 ef10_filter_table_t *eftp = enp->en_filter.ef_ef10_filter_table;
1086 efx_filter_spec_t spec;
1089 /* Insert the unknown unicast filter */
1090 efx_filter_spec_init_rx(&spec, EFX_FILTER_PRI_AUTO,
1092 eftp->eft_default_rxq);
1093 rc = efx_filter_spec_set_uc_def(&spec);
1096 rc = ef10_filter_add_internal(enp, &spec, B_TRUE,
1097 &eftp->eft_unicst_filter_indexes[eftp->eft_unicst_filter_count]);
1101 eftp->eft_unicst_filter_count++;
1102 EFSYS_ASSERT(eftp->eft_unicst_filter_count <=
1103 EFX_EF10_FILTER_UNICAST_FILTERS_MAX);
1110 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1114 static __checkReturn efx_rc_t
1115 ef10_filter_insert_multicast_list(
1116 __in efx_nic_t *enp,
1117 __in boolean_t mulcst,
1118 __in boolean_t brdcst,
1119 __in_ecount(6*count) uint8_t const *addrs,
1120 __in uint32_t count,
1121 __in efx_filter_flags_t filter_flags,
1122 __in boolean_t rollback)
1124 ef10_filter_table_t *eftp = enp->en_filter.ef_ef10_filter_table;
1125 efx_filter_spec_t spec;
1128 uint32_t filter_index;
1129 uint32_t filter_count;
1132 if (mulcst == B_FALSE)
1135 if (count + (brdcst ? 1 : 0) >
1136 EFX_ARRAY_SIZE(eftp->eft_mulcst_filter_indexes)) {
1137 /* Too many MAC addresses */
1142 /* Insert/renew multicast address list filters */
1144 for (i = 0; i < count; i++) {
1145 efx_filter_spec_init_rx(&spec,
1146 EFX_FILTER_PRI_AUTO,
1148 eftp->eft_default_rxq);
1150 rc = efx_filter_spec_set_eth_local(&spec,
1151 EFX_FILTER_SPEC_VID_UNSPEC,
1152 &addrs[i * EFX_MAC_ADDR_LEN]);
1154 if (rollback == B_TRUE) {
1155 /* Only stop upon failure if told to rollback */
1159 * Don't try to add a filter with a corrupt
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 */
1180 if (brdcst == B_TRUE) {
1181 /* Insert/renew broadcast address filter */
1182 efx_filter_spec_init_rx(&spec, EFX_FILTER_PRI_AUTO,
1184 eftp->eft_default_rxq);
1186 EFX_MAC_BROADCAST_ADDR_SET(addr);
1187 rc = efx_filter_spec_set_eth_local(&spec,
1188 EFX_FILTER_SPEC_VID_UNSPEC, addr);
1189 if ((rc != 0) && (rollback == B_TRUE)) {
1190 /* Only stop upon failure if told to rollback */
1194 rc = ef10_filter_add_internal(enp, &spec, B_TRUE,
1198 eftp->eft_mulcst_filter_indexes[filter_count] =
1201 } else if (rollback == B_TRUE) {
1202 /* Only stop upon failure if told to rollback */
1207 eftp->eft_mulcst_filter_count = filter_count;
1208 eftp->eft_using_all_mulcst = B_FALSE;
1213 /* Remove any filters we have inserted */
1216 (void) ef10_filter_delete_internal(enp,
1217 eftp->eft_mulcst_filter_indexes[i]);
1219 eftp->eft_mulcst_filter_count = 0;
1222 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1227 static __checkReturn efx_rc_t
1228 ef10_filter_insert_all_multicast(
1229 __in efx_nic_t *enp,
1230 __in efx_filter_flags_t filter_flags)
1232 ef10_filter_table_t *eftp = enp->en_filter.ef_ef10_filter_table;
1233 efx_filter_spec_t spec;
1236 /* Insert the unknown multicast filter */
1237 efx_filter_spec_init_rx(&spec, EFX_FILTER_PRI_AUTO,
1239 eftp->eft_default_rxq);
1240 rc = efx_filter_spec_set_mc_def(&spec);
1244 rc = ef10_filter_add_internal(enp, &spec, B_TRUE,
1245 &eftp->eft_mulcst_filter_indexes[0]);
1249 eftp->eft_mulcst_filter_count = 1;
1250 eftp->eft_using_all_mulcst = B_TRUE;
1253 * FIXME: If brdcst == B_FALSE, add a filter to drop broadcast traffic.
1261 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1266 typedef struct ef10_filter_encap_entry_s {
1267 uint16_t ether_type;
1268 efx_tunnel_protocol_t encap_type;
1269 uint32_t inner_frame_match;
1270 } ef10_filter_encap_entry_t;
1272 #define EF10_ENCAP_FILTER_ENTRY(ipv, encap_type, inner_frame_match) \
1273 { EFX_ETHER_TYPE_##ipv, EFX_TUNNEL_PROTOCOL_##encap_type, \
1274 EFX_FILTER_INNER_FRAME_MATCH_UNKNOWN_##inner_frame_match }
1276 static ef10_filter_encap_entry_t ef10_filter_encap_list[] = {
1277 EF10_ENCAP_FILTER_ENTRY(IPV4, VXLAN, UCAST_DST),
1278 EF10_ENCAP_FILTER_ENTRY(IPV4, VXLAN, MCAST_DST),
1279 EF10_ENCAP_FILTER_ENTRY(IPV6, VXLAN, UCAST_DST),
1280 EF10_ENCAP_FILTER_ENTRY(IPV6, VXLAN, MCAST_DST),
1282 EF10_ENCAP_FILTER_ENTRY(IPV4, GENEVE, UCAST_DST),
1283 EF10_ENCAP_FILTER_ENTRY(IPV4, GENEVE, MCAST_DST),
1284 EF10_ENCAP_FILTER_ENTRY(IPV6, GENEVE, UCAST_DST),
1285 EF10_ENCAP_FILTER_ENTRY(IPV6, GENEVE, MCAST_DST),
1287 EF10_ENCAP_FILTER_ENTRY(IPV4, NVGRE, UCAST_DST),
1288 EF10_ENCAP_FILTER_ENTRY(IPV4, NVGRE, MCAST_DST),
1289 EF10_ENCAP_FILTER_ENTRY(IPV6, NVGRE, UCAST_DST),
1290 EF10_ENCAP_FILTER_ENTRY(IPV6, NVGRE, MCAST_DST),
1293 #undef EF10_ENCAP_FILTER_ENTRY
1295 static __checkReturn efx_rc_t
1296 ef10_filter_insert_encap_filters(
1297 __in efx_nic_t *enp,
1298 __in boolean_t mulcst,
1299 __in efx_filter_flags_t filter_flags)
1301 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
1305 EFX_STATIC_ASSERT(EFX_ARRAY_SIZE(ef10_filter_encap_list) <=
1306 EFX_ARRAY_SIZE(table->eft_encap_filter_indexes));
1309 * On Medford, full-featured firmware can identify packets as being
1310 * tunnel encapsulated, even if no encapsulated packet offloads are in
1311 * use. When packets are identified as such, ordinary filters are not
1312 * applied, only ones specific to encapsulated packets. Hence we need to
1313 * insert filters for encapsulated packets in order to receive them.
1315 * Separate filters need to be inserted for each ether type,
1316 * encapsulation type, and inner frame type (unicast or multicast). To
1317 * keep things simple and reduce the number of filters needed, catch-all
1318 * filters for all combinations of types are inserted, even if
1319 * all_unicst or all_mulcst have not been set. (These catch-all filters
1320 * may well, however, fail to insert on unprivileged functions.)
1322 table->eft_encap_filter_count = 0;
1323 for (i = 0; i < EFX_ARRAY_SIZE(ef10_filter_encap_list); i++) {
1324 efx_filter_spec_t spec;
1325 ef10_filter_encap_entry_t *encap_filter =
1326 &ef10_filter_encap_list[i];
1329 * Skip multicast filters if we've not been asked for
1330 * any multicast traffic.
1332 if ((mulcst == B_FALSE) &&
1333 (encap_filter->inner_frame_match ==
1334 EFX_FILTER_INNER_FRAME_MATCH_UNKNOWN_MCAST_DST))
1337 efx_filter_spec_init_rx(&spec, EFX_FILTER_PRI_AUTO,
1339 table->eft_default_rxq);
1340 efx_filter_spec_set_ether_type(&spec, encap_filter->ether_type);
1341 rc = efx_filter_spec_set_encap_type(&spec,
1342 encap_filter->encap_type,
1343 encap_filter->inner_frame_match);
1347 rc = ef10_filter_add_internal(enp, &spec, B_TRUE,
1348 &table->eft_encap_filter_indexes[
1349 table->eft_encap_filter_count]);
1354 table->eft_encap_filter_count++;
1363 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1369 ef10_filter_remove_old(
1370 __in efx_nic_t *enp)
1372 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
1375 for (i = 0; i < EFX_ARRAY_SIZE(table->eft_entry); i++) {
1376 if (ef10_filter_entry_is_auto_old(table, i)) {
1377 (void) ef10_filter_delete_internal(enp, i);
1383 static __checkReturn efx_rc_t
1384 ef10_filter_get_workarounds(
1385 __in efx_nic_t *enp)
1387 efx_nic_cfg_t *encp = &enp->en_nic_cfg;
1388 uint32_t implemented = 0;
1389 uint32_t enabled = 0;
1392 rc = efx_mcdi_get_workarounds(enp, &implemented, &enabled);
1394 /* Check if chained multicast filter support is enabled */
1395 if (implemented & enabled & MC_CMD_GET_WORKAROUNDS_OUT_BUG26807)
1396 encp->enc_bug26807_workaround = B_TRUE;
1398 encp->enc_bug26807_workaround = B_FALSE;
1399 } else if (rc == ENOTSUP) {
1401 * Firmware is too old to support GET_WORKAROUNDS, and support
1402 * for this workaround was implemented later.
1404 encp->enc_bug26807_workaround = B_FALSE;
1412 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1420 * Reconfigure all filters.
1421 * If all_unicst and/or all mulcst filters cannot be applied then
1422 * return ENOTSUP (Note the filters for the specified addresses are
1423 * still applied in this case).
1425 __checkReturn efx_rc_t
1426 ef10_filter_reconfigure(
1427 __in efx_nic_t *enp,
1428 __in_ecount(6) uint8_t const *mac_addr,
1429 __in boolean_t all_unicst,
1430 __in boolean_t mulcst,
1431 __in boolean_t all_mulcst,
1432 __in boolean_t brdcst,
1433 __in_ecount(6*count) uint8_t const *addrs,
1434 __in uint32_t count)
1436 efx_nic_cfg_t *encp = &enp->en_nic_cfg;
1437 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
1438 efx_filter_flags_t filter_flags;
1440 efx_rc_t all_unicst_rc = 0;
1441 efx_rc_t all_mulcst_rc = 0;
1444 if (table->eft_default_rxq == NULL) {
1446 * Filters direct traffic to the default RXQ, and so cannot be
1447 * inserted until it is available. Any currently configured
1448 * filters must be removed (ignore errors in case the MC
1449 * has rebooted, which removes hardware filters).
1451 for (i = 0; i < table->eft_unicst_filter_count; i++) {
1452 (void) ef10_filter_delete_internal(enp,
1453 table->eft_unicst_filter_indexes[i]);
1455 table->eft_unicst_filter_count = 0;
1457 for (i = 0; i < table->eft_mulcst_filter_count; i++) {
1458 (void) ef10_filter_delete_internal(enp,
1459 table->eft_mulcst_filter_indexes[i]);
1461 table->eft_mulcst_filter_count = 0;
1463 for (i = 0; i < table->eft_encap_filter_count; i++) {
1464 (void) ef10_filter_delete_internal(enp,
1465 table->eft_encap_filter_indexes[i]);
1467 table->eft_encap_filter_count = 0;
1472 if (table->eft_using_rss)
1473 filter_flags = EFX_FILTER_FLAG_RX_RSS;
1477 /* Mark old filters which may need to be removed */
1478 for (i = 0; i < table->eft_unicst_filter_count; i++) {
1479 ef10_filter_set_entry_auto_old(table,
1480 table->eft_unicst_filter_indexes[i]);
1482 for (i = 0; i < table->eft_mulcst_filter_count; i++) {
1483 ef10_filter_set_entry_auto_old(table,
1484 table->eft_mulcst_filter_indexes[i]);
1486 for (i = 0; i < table->eft_encap_filter_count; i++) {
1487 ef10_filter_set_entry_auto_old(table,
1488 table->eft_encap_filter_indexes[i]);
1492 * Insert or renew unicast filters.
1494 * Firmware does not perform chaining on unicast filters. As traffic is
1495 * therefore only delivered to the first matching filter, we should
1496 * always insert the specific filter for our MAC address, to try and
1497 * ensure we get that traffic.
1499 * (If the filter for our MAC address has already been inserted by
1500 * another function, we won't receive traffic sent to us, even if we
1501 * insert a unicast mismatch filter. To prevent traffic stealing, this
1502 * therefore relies on the privilege model only allowing functions to
1503 * insert filters for their own MAC address unless explicitly given
1504 * additional privileges by the user. This also means that, even on a
1505 * priviliged function, inserting a unicast mismatch filter may not
1506 * catch all traffic in multi PCI function scenarios.)
1508 table->eft_unicst_filter_count = 0;
1509 rc = ef10_filter_insert_unicast(enp, mac_addr, filter_flags);
1510 if (all_unicst || (rc != 0)) {
1511 all_unicst_rc = ef10_filter_insert_all_unicast(enp,
1513 if ((rc != 0) && (all_unicst_rc != 0))
1518 * WORKAROUND_BUG26807 controls firmware support for chained multicast
1519 * filters, and can only be enabled or disabled when the hardware filter
1522 * Chained multicast filters require support from the datapath firmware,
1523 * and may not be available (e.g. low-latency variants or old Huntington
1526 * Firmware will reset (FLR) functions which have inserted filters in
1527 * the hardware filter table when the workaround is enabled/disabled.
1528 * Functions without any hardware filters are not reset.
1530 * Re-check if the workaround is enabled after adding unicast hardware
1531 * filters. This ensures that encp->enc_bug26807_workaround matches the
1532 * firmware state, and that later changes to enable/disable the
1533 * workaround will result in this function seeing a reset (FLR).
1535 * In common-code drivers, we only support multiple PCI function
1536 * scenarios with firmware that supports multicast chaining, so we can
1537 * assume it is enabled for such cases and hence simplify the filter
1538 * insertion logic. Firmware that does not support multicast chaining
1539 * does not support multiple PCI function configurations either, so
1540 * filter insertion is much simpler and the same strategies can still be
1543 if ((rc = ef10_filter_get_workarounds(enp)) != 0)
1546 if ((table->eft_using_all_mulcst != all_mulcst) &&
1547 (encp->enc_bug26807_workaround == B_TRUE)) {
1549 * Multicast filter chaining is enabled, so traffic that matches
1550 * more than one multicast filter will be replicated and
1551 * delivered to multiple recipients. To avoid this duplicate
1552 * delivery, remove old multicast filters before inserting new
1553 * multicast filters.
1555 ef10_filter_remove_old(enp);
1558 /* Insert or renew multicast filters */
1559 if (all_mulcst == B_TRUE) {
1561 * Insert the all multicast filter. If that fails, try to insert
1562 * all of our multicast filters (but without rollback on
1565 all_mulcst_rc = ef10_filter_insert_all_multicast(enp,
1567 if (all_mulcst_rc != 0) {
1568 rc = ef10_filter_insert_multicast_list(enp, B_TRUE,
1569 brdcst, addrs, count, filter_flags, B_FALSE);
1575 * Insert filters for multicast addresses.
1576 * If any insertion fails, then rollback and try to insert the
1577 * all multicast filter instead.
1578 * If that also fails, try to insert all of the multicast
1579 * filters (but without rollback on failure).
1581 rc = ef10_filter_insert_multicast_list(enp, mulcst, brdcst,
1582 addrs, count, filter_flags, B_TRUE);
1584 if ((table->eft_using_all_mulcst == B_FALSE) &&
1585 (encp->enc_bug26807_workaround == B_TRUE)) {
1587 * Multicast filter chaining is on, so remove
1588 * old filters before inserting the multicast
1589 * all filter to avoid duplicate delivery caused
1590 * by packets matching multiple filters.
1592 ef10_filter_remove_old(enp);
1595 rc = ef10_filter_insert_all_multicast(enp,
1598 rc = ef10_filter_insert_multicast_list(enp,
1600 addrs, count, filter_flags, B_FALSE);
1607 if (encp->enc_tunnel_encapsulations_supported != 0) {
1608 /* Try to insert filters for encapsulated packets. */
1609 (void) ef10_filter_insert_encap_filters(enp,
1610 mulcst || all_mulcst || brdcst,
1614 /* Remove old filters which were not renewed */
1615 ef10_filter_remove_old(enp);
1617 /* report if any optional flags were rejected */
1618 if (((all_unicst != B_FALSE) && (all_unicst_rc != 0)) ||
1619 ((all_mulcst != B_FALSE) && (all_mulcst_rc != 0))) {
1632 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1634 /* Clear auto old flags */
1635 for (i = 0; i < EFX_ARRAY_SIZE(table->eft_entry); i++) {
1636 if (ef10_filter_entry_is_auto_old(table, i)) {
1637 ef10_filter_set_entry_not_auto_old(table, i);
1645 ef10_filter_get_default_rxq(
1646 __in efx_nic_t *enp,
1647 __out efx_rxq_t **erpp,
1648 __out boolean_t *using_rss)
1650 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
1652 *erpp = table->eft_default_rxq;
1653 *using_rss = table->eft_using_rss;
1658 ef10_filter_default_rxq_set(
1659 __in efx_nic_t *enp,
1660 __in efx_rxq_t *erp,
1661 __in boolean_t using_rss)
1663 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
1665 #if EFSYS_OPT_RX_SCALE
1666 EFSYS_ASSERT((using_rss == B_FALSE) ||
1667 (enp->en_rss_context != EF10_RSS_CONTEXT_INVALID));
1668 table->eft_using_rss = using_rss;
1670 EFSYS_ASSERT(using_rss == B_FALSE);
1671 table->eft_using_rss = B_FALSE;
1673 table->eft_default_rxq = erp;
1677 ef10_filter_default_rxq_clear(
1678 __in efx_nic_t *enp)
1680 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
1682 table->eft_default_rxq = NULL;
1683 table->eft_using_rss = B_FALSE;
1687 #endif /* EFSYS_OPT_FILTER */
1689 #endif /* EFSYS_OPT_HUNTINGTON || EFSYS_OPT_MEDFORD */