2 * Copyright (c) 2007-2016 Solarflare Communications Inc.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
16 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
18 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
21 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
22 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
24 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 * The views and conclusions contained in the software and documentation are
27 * those of the authors and should not be interpreted as representing official
28 * policies, either expressed or implied, of the FreeBSD Project.
31 #include <sys/cdefs.h>
32 __FBSDID("$FreeBSD$");
37 #if EFSYS_OPT_HUNTINGTON || EFSYS_OPT_MEDFORD
41 #define EFE_SPEC(eftp, index) ((eftp)->eft_entry[(index)].efe_spec)
43 static efx_filter_spec_t *
44 ef10_filter_entry_spec(
45 __in const ef10_filter_table_t *eftp,
46 __in unsigned int index)
48 return ((efx_filter_spec_t *)(EFE_SPEC(eftp, index) &
49 ~(uintptr_t)EFX_EF10_FILTER_FLAGS));
53 ef10_filter_entry_is_busy(
54 __in const ef10_filter_table_t *eftp,
55 __in unsigned int index)
57 if (EFE_SPEC(eftp, index) & EFX_EF10_FILTER_FLAG_BUSY)
64 ef10_filter_entry_is_auto_old(
65 __in const ef10_filter_table_t *eftp,
66 __in unsigned int index)
68 if (EFE_SPEC(eftp, index) & EFX_EF10_FILTER_FLAG_AUTO_OLD)
75 ef10_filter_set_entry(
76 __inout ef10_filter_table_t *eftp,
77 __in unsigned int index,
78 __in_opt const efx_filter_spec_t *efsp)
80 EFE_SPEC(eftp, index) = (uintptr_t)efsp;
84 ef10_filter_set_entry_busy(
85 __inout ef10_filter_table_t *eftp,
86 __in unsigned int index)
88 EFE_SPEC(eftp, index) |= (uintptr_t)EFX_EF10_FILTER_FLAG_BUSY;
92 ef10_filter_set_entry_not_busy(
93 __inout ef10_filter_table_t *eftp,
94 __in unsigned int index)
96 EFE_SPEC(eftp, index) &= ~(uintptr_t)EFX_EF10_FILTER_FLAG_BUSY;
100 ef10_filter_set_entry_auto_old(
101 __inout ef10_filter_table_t *eftp,
102 __in unsigned int index)
104 EFSYS_ASSERT(ef10_filter_entry_spec(eftp, index) != NULL);
105 EFE_SPEC(eftp, index) |= (uintptr_t)EFX_EF10_FILTER_FLAG_AUTO_OLD;
109 ef10_filter_set_entry_not_auto_old(
110 __inout ef10_filter_table_t *eftp,
111 __in unsigned int index)
113 EFE_SPEC(eftp, index) &= ~(uintptr_t)EFX_EF10_FILTER_FLAG_AUTO_OLD;
114 EFSYS_ASSERT(ef10_filter_entry_spec(eftp, index) != NULL);
117 __checkReturn efx_rc_t
122 ef10_filter_table_t *eftp;
124 EFSYS_ASSERT(enp->en_family == EFX_FAMILY_HUNTINGTON ||
125 enp->en_family == EFX_FAMILY_MEDFORD);
127 #define MATCH_MASK(match) (EFX_MASK32(match) << EFX_LOW_BIT(match))
128 EFX_STATIC_ASSERT(EFX_FILTER_MATCH_REM_HOST ==
129 MATCH_MASK(MC_CMD_FILTER_OP_EXT_IN_MATCH_SRC_IP));
130 EFX_STATIC_ASSERT(EFX_FILTER_MATCH_LOC_HOST ==
131 MATCH_MASK(MC_CMD_FILTER_OP_EXT_IN_MATCH_DST_IP));
132 EFX_STATIC_ASSERT(EFX_FILTER_MATCH_REM_MAC ==
133 MATCH_MASK(MC_CMD_FILTER_OP_EXT_IN_MATCH_SRC_MAC));
134 EFX_STATIC_ASSERT(EFX_FILTER_MATCH_REM_PORT ==
135 MATCH_MASK(MC_CMD_FILTER_OP_EXT_IN_MATCH_SRC_PORT));
136 EFX_STATIC_ASSERT(EFX_FILTER_MATCH_LOC_MAC ==
137 MATCH_MASK(MC_CMD_FILTER_OP_EXT_IN_MATCH_DST_MAC));
138 EFX_STATIC_ASSERT(EFX_FILTER_MATCH_LOC_PORT ==
139 MATCH_MASK(MC_CMD_FILTER_OP_EXT_IN_MATCH_DST_PORT));
140 EFX_STATIC_ASSERT(EFX_FILTER_MATCH_ETHER_TYPE ==
141 MATCH_MASK(MC_CMD_FILTER_OP_EXT_IN_MATCH_ETHER_TYPE));
142 EFX_STATIC_ASSERT(EFX_FILTER_MATCH_INNER_VID ==
143 MATCH_MASK(MC_CMD_FILTER_OP_EXT_IN_MATCH_INNER_VLAN));
144 EFX_STATIC_ASSERT(EFX_FILTER_MATCH_OUTER_VID ==
145 MATCH_MASK(MC_CMD_FILTER_OP_EXT_IN_MATCH_OUTER_VLAN));
146 EFX_STATIC_ASSERT(EFX_FILTER_MATCH_IP_PROTO ==
147 MATCH_MASK(MC_CMD_FILTER_OP_EXT_IN_MATCH_IP_PROTO));
148 EFX_STATIC_ASSERT(EFX_FILTER_MATCH_IFRM_UNKNOWN_MCAST_DST ==
149 MATCH_MASK(MC_CMD_FILTER_OP_EXT_IN_MATCH_IFRM_UNKNOWN_MCAST_DST));
150 EFX_STATIC_ASSERT(EFX_FILTER_MATCH_IFRM_UNKNOWN_UCAST_DST ==
151 MATCH_MASK(MC_CMD_FILTER_OP_EXT_IN_MATCH_IFRM_UNKNOWN_UCAST_DST));
152 EFX_STATIC_ASSERT(EFX_FILTER_MATCH_UNKNOWN_MCAST_DST ==
153 MATCH_MASK(MC_CMD_FILTER_OP_EXT_IN_MATCH_UNKNOWN_MCAST_DST));
154 EFX_STATIC_ASSERT((uint32_t)EFX_FILTER_MATCH_UNKNOWN_UCAST_DST ==
155 MATCH_MASK(MC_CMD_FILTER_OP_EXT_IN_MATCH_UNKNOWN_UCAST_DST));
158 EFSYS_KMEM_ALLOC(enp->en_esip, sizeof (ef10_filter_table_t), eftp);
165 enp->en_filter.ef_ef10_filter_table = eftp;
170 EFSYS_PROBE1(fail1, efx_rc_t, rc);
179 EFSYS_ASSERT(enp->en_family == EFX_FAMILY_HUNTINGTON ||
180 enp->en_family == EFX_FAMILY_MEDFORD);
182 if (enp->en_filter.ef_ef10_filter_table != NULL) {
183 EFSYS_KMEM_FREE(enp->en_esip, sizeof (ef10_filter_table_t),
184 enp->en_filter.ef_ef10_filter_table);
188 static __checkReturn efx_rc_t
189 efx_mcdi_filter_op_add(
191 __in efx_filter_spec_t *spec,
192 __in unsigned int filter_op,
193 __inout ef10_filter_handle_t *handle)
196 uint8_t payload[MAX(MC_CMD_FILTER_OP_EXT_IN_LEN,
197 MC_CMD_FILTER_OP_EXT_OUT_LEN)];
200 memset(payload, 0, sizeof (payload));
201 req.emr_cmd = MC_CMD_FILTER_OP;
202 req.emr_in_buf = payload;
203 req.emr_in_length = MC_CMD_FILTER_OP_EXT_IN_LEN;
204 req.emr_out_buf = payload;
205 req.emr_out_length = MC_CMD_FILTER_OP_EXT_OUT_LEN;
208 case MC_CMD_FILTER_OP_IN_OP_REPLACE:
209 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_HANDLE_LO,
211 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_HANDLE_HI,
214 case MC_CMD_FILTER_OP_IN_OP_INSERT:
215 case MC_CMD_FILTER_OP_IN_OP_SUBSCRIBE:
216 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_OP, filter_op);
224 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_PORT_ID,
225 EVB_PORT_ID_ASSIGNED);
226 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_MATCH_FIELDS,
227 spec->efs_match_flags);
228 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_RX_DEST,
229 MC_CMD_FILTER_OP_EXT_IN_RX_DEST_HOST);
230 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_RX_QUEUE,
232 if (spec->efs_flags & EFX_FILTER_FLAG_RX_RSS) {
233 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_RX_CONTEXT,
234 spec->efs_rss_context);
236 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_RX_MODE,
237 spec->efs_flags & EFX_FILTER_FLAG_RX_RSS ?
238 MC_CMD_FILTER_OP_EXT_IN_RX_MODE_RSS :
239 MC_CMD_FILTER_OP_EXT_IN_RX_MODE_SIMPLE);
240 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_TX_DEST,
241 MC_CMD_FILTER_OP_EXT_IN_TX_DEST_DEFAULT);
243 if (filter_op != MC_CMD_FILTER_OP_IN_OP_REPLACE) {
245 * NOTE: Unlike most MCDI requests, the filter fields
246 * are presented in network (big endian) byte order.
248 memcpy(MCDI_IN2(req, uint8_t, FILTER_OP_EXT_IN_SRC_MAC),
249 spec->efs_rem_mac, EFX_MAC_ADDR_LEN);
250 memcpy(MCDI_IN2(req, uint8_t, FILTER_OP_EXT_IN_DST_MAC),
251 spec->efs_loc_mac, EFX_MAC_ADDR_LEN);
253 MCDI_IN_SET_WORD(req, FILTER_OP_EXT_IN_SRC_PORT,
254 __CPU_TO_BE_16(spec->efs_rem_port));
255 MCDI_IN_SET_WORD(req, FILTER_OP_EXT_IN_DST_PORT,
256 __CPU_TO_BE_16(spec->efs_loc_port));
258 MCDI_IN_SET_WORD(req, FILTER_OP_EXT_IN_ETHER_TYPE,
259 __CPU_TO_BE_16(spec->efs_ether_type));
261 MCDI_IN_SET_WORD(req, FILTER_OP_EXT_IN_INNER_VLAN,
262 __CPU_TO_BE_16(spec->efs_inner_vid));
263 MCDI_IN_SET_WORD(req, FILTER_OP_EXT_IN_OUTER_VLAN,
264 __CPU_TO_BE_16(spec->efs_outer_vid));
266 /* IP protocol (in low byte, high byte is zero) */
267 MCDI_IN_SET_BYTE(req, FILTER_OP_EXT_IN_IP_PROTO,
270 EFX_STATIC_ASSERT(sizeof (spec->efs_rem_host) ==
271 MC_CMD_FILTER_OP_EXT_IN_SRC_IP_LEN);
272 EFX_STATIC_ASSERT(sizeof (spec->efs_loc_host) ==
273 MC_CMD_FILTER_OP_EXT_IN_DST_IP_LEN);
275 memcpy(MCDI_IN2(req, uint8_t, FILTER_OP_EXT_IN_SRC_IP),
276 &spec->efs_rem_host.eo_byte[0],
277 MC_CMD_FILTER_OP_EXT_IN_SRC_IP_LEN);
278 memcpy(MCDI_IN2(req, uint8_t, FILTER_OP_EXT_IN_DST_IP),
279 &spec->efs_loc_host.eo_byte[0],
280 MC_CMD_FILTER_OP_EXT_IN_DST_IP_LEN);
283 * On Medford, filters for encapsulated packets match based on
284 * the ether type and IP protocol in the outer frame. In
285 * addition we need to fill in the VNI or VSID type field.
287 switch (spec->efs_encap_type) {
288 case EFX_TUNNEL_PROTOCOL_NONE:
290 case EFX_TUNNEL_PROTOCOL_VXLAN:
291 case EFX_TUNNEL_PROTOCOL_GENEVE:
292 MCDI_IN_POPULATE_DWORD_1(req,
293 FILTER_OP_EXT_IN_VNI_OR_VSID,
294 FILTER_OP_EXT_IN_VNI_TYPE,
295 spec->efs_encap_type == EFX_TUNNEL_PROTOCOL_VXLAN ?
296 MC_CMD_FILTER_OP_EXT_IN_VNI_TYPE_VXLAN :
297 MC_CMD_FILTER_OP_EXT_IN_VNI_TYPE_GENEVE);
299 case EFX_TUNNEL_PROTOCOL_NVGRE:
300 MCDI_IN_POPULATE_DWORD_1(req,
301 FILTER_OP_EXT_IN_VNI_OR_VSID,
302 FILTER_OP_EXT_IN_VSID_TYPE,
303 MC_CMD_FILTER_OP_EXT_IN_VSID_TYPE_NVGRE);
312 efx_mcdi_execute(enp, &req);
314 if (req.emr_rc != 0) {
319 if (req.emr_out_length_used < MC_CMD_FILTER_OP_EXT_OUT_LEN) {
324 handle->efh_lo = MCDI_OUT_DWORD(req, FILTER_OP_EXT_OUT_HANDLE_LO);
325 handle->efh_hi = MCDI_OUT_DWORD(req, FILTER_OP_EXT_OUT_HANDLE_HI);
336 EFSYS_PROBE1(fail1, efx_rc_t, rc);
342 static __checkReturn efx_rc_t
343 efx_mcdi_filter_op_delete(
345 __in unsigned int filter_op,
346 __inout ef10_filter_handle_t *handle)
349 uint8_t payload[MAX(MC_CMD_FILTER_OP_EXT_IN_LEN,
350 MC_CMD_FILTER_OP_EXT_OUT_LEN)];
353 memset(payload, 0, sizeof (payload));
354 req.emr_cmd = MC_CMD_FILTER_OP;
355 req.emr_in_buf = payload;
356 req.emr_in_length = MC_CMD_FILTER_OP_EXT_IN_LEN;
357 req.emr_out_buf = payload;
358 req.emr_out_length = MC_CMD_FILTER_OP_EXT_OUT_LEN;
361 case MC_CMD_FILTER_OP_IN_OP_REMOVE:
362 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_OP,
363 MC_CMD_FILTER_OP_IN_OP_REMOVE);
365 case MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE:
366 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_OP,
367 MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE);
375 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_HANDLE_LO, handle->efh_lo);
376 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_HANDLE_HI, handle->efh_hi);
378 efx_mcdi_execute_quiet(enp, &req);
380 if (req.emr_rc != 0) {
385 if (req.emr_out_length_used < MC_CMD_FILTER_OP_EXT_OUT_LEN) {
398 EFSYS_PROBE1(fail1, efx_rc_t, rc);
403 static __checkReturn boolean_t
405 __in const efx_filter_spec_t *left,
406 __in const efx_filter_spec_t *right)
408 /* FIXME: Consider rx vs tx filters (look at efs_flags) */
409 if (left->efs_match_flags != right->efs_match_flags)
411 if (!EFX_OWORD_IS_EQUAL(left->efs_rem_host, right->efs_rem_host))
413 if (!EFX_OWORD_IS_EQUAL(left->efs_loc_host, right->efs_loc_host))
415 if (memcmp(left->efs_rem_mac, right->efs_rem_mac, EFX_MAC_ADDR_LEN))
417 if (memcmp(left->efs_loc_mac, right->efs_loc_mac, EFX_MAC_ADDR_LEN))
419 if (left->efs_rem_port != right->efs_rem_port)
421 if (left->efs_loc_port != right->efs_loc_port)
423 if (left->efs_inner_vid != right->efs_inner_vid)
425 if (left->efs_outer_vid != right->efs_outer_vid)
427 if (left->efs_ether_type != right->efs_ether_type)
429 if (left->efs_ip_proto != right->efs_ip_proto)
431 if (left->efs_encap_type != right->efs_encap_type)
438 static __checkReturn boolean_t
439 ef10_filter_same_dest(
440 __in const efx_filter_spec_t *left,
441 __in const efx_filter_spec_t *right)
443 if ((left->efs_flags & EFX_FILTER_FLAG_RX_RSS) &&
444 (right->efs_flags & EFX_FILTER_FLAG_RX_RSS)) {
445 if (left->efs_rss_context == right->efs_rss_context)
447 } else if ((~(left->efs_flags) & EFX_FILTER_FLAG_RX_RSS) &&
448 (~(right->efs_flags) & EFX_FILTER_FLAG_RX_RSS)) {
449 if (left->efs_dmaq_id == right->efs_dmaq_id)
455 static __checkReturn uint32_t
457 __in efx_filter_spec_t *spec)
459 EFX_STATIC_ASSERT((sizeof (efx_filter_spec_t) % sizeof (uint32_t))
461 EFX_STATIC_ASSERT((EFX_FIELD_OFFSET(efx_filter_spec_t, efs_outer_vid) %
462 sizeof (uint32_t)) == 0);
465 * As the area of the efx_filter_spec_t we need to hash is DWORD
466 * aligned and an exact number of DWORDs in size we can use the
467 * optimised efx_hash_dwords() rather than efx_hash_bytes()
469 return (efx_hash_dwords((const uint32_t *)&spec->efs_outer_vid,
470 (sizeof (efx_filter_spec_t) -
471 EFX_FIELD_OFFSET(efx_filter_spec_t, efs_outer_vid)) /
472 sizeof (uint32_t), 0));
476 * Decide whether a filter should be exclusive or else should allow
477 * delivery to additional recipients. Currently we decide that
478 * filters for specific local unicast MAC and IP addresses are
481 static __checkReturn boolean_t
482 ef10_filter_is_exclusive(
483 __in efx_filter_spec_t *spec)
485 if ((spec->efs_match_flags & EFX_FILTER_MATCH_LOC_MAC) &&
486 !EFX_MAC_ADDR_IS_MULTICAST(spec->efs_loc_mac))
489 if ((spec->efs_match_flags &
490 (EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_LOC_HOST)) ==
491 (EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_LOC_HOST)) {
492 if ((spec->efs_ether_type == EFX_ETHER_TYPE_IPV4) &&
493 ((spec->efs_loc_host.eo_u8[0] & 0xf) != 0xe))
495 if ((spec->efs_ether_type == EFX_ETHER_TYPE_IPV6) &&
496 (spec->efs_loc_host.eo_u8[0] != 0xff))
503 __checkReturn efx_rc_t
508 efx_filter_spec_t *spec;
509 ef10_filter_table_t *eftp = enp->en_filter.ef_ef10_filter_table;
511 efsys_lock_state_t state;
514 EFSYS_ASSERT(enp->en_family == EFX_FAMILY_HUNTINGTON ||
515 enp->en_family == EFX_FAMILY_MEDFORD);
517 for (tbl_id = 0; tbl_id < EFX_EF10_FILTER_TBL_ROWS; tbl_id++) {
519 EFSYS_LOCK(enp->en_eslp, state);
521 spec = ef10_filter_entry_spec(eftp, tbl_id);
524 } else if (ef10_filter_entry_is_busy(eftp, tbl_id)) {
525 /* Ignore busy entries. */
528 ef10_filter_set_entry_busy(eftp, tbl_id);
532 EFSYS_UNLOCK(enp->en_eslp, state);
534 if (restoring == B_FALSE)
537 if (ef10_filter_is_exclusive(spec)) {
538 rc = efx_mcdi_filter_op_add(enp, spec,
539 MC_CMD_FILTER_OP_IN_OP_INSERT,
540 &eftp->eft_entry[tbl_id].efe_handle);
542 rc = efx_mcdi_filter_op_add(enp, spec,
543 MC_CMD_FILTER_OP_IN_OP_SUBSCRIBE,
544 &eftp->eft_entry[tbl_id].efe_handle);
550 EFSYS_LOCK(enp->en_eslp, state);
552 ef10_filter_set_entry_not_busy(eftp, tbl_id);
554 EFSYS_UNLOCK(enp->en_eslp, state);
560 EFSYS_PROBE1(fail1, efx_rc_t, rc);
566 * An arbitrary search limit for the software hash table. As per the linux net
569 #define EF10_FILTER_SEARCH_LIMIT 200
571 static __checkReturn efx_rc_t
572 ef10_filter_add_internal(
574 __inout efx_filter_spec_t *spec,
575 __in boolean_t may_replace,
576 __out_opt uint32_t *filter_id)
579 ef10_filter_table_t *eftp = enp->en_filter.ef_ef10_filter_table;
580 efx_filter_spec_t *saved_spec;
584 boolean_t replacing = B_FALSE;
586 efsys_lock_state_t state;
587 boolean_t locked = B_FALSE;
589 EFSYS_ASSERT(enp->en_family == EFX_FAMILY_HUNTINGTON ||
590 enp->en_family == EFX_FAMILY_MEDFORD);
592 #if EFSYS_OPT_RX_SCALE
593 spec->efs_rss_context = enp->en_rss_context;
596 hash = ef10_filter_hash(spec);
599 * FIXME: Add support for inserting filters of different priorities
600 * and removing lower priority multicast filters (bug 42378)
604 * Find any existing filters with the same match tuple or
605 * else a free slot to insert at. If any of them are busy,
606 * we have to wait and retry.
611 EFSYS_LOCK(enp->en_eslp, state);
615 i = (hash + depth) & (EFX_EF10_FILTER_TBL_ROWS - 1);
616 saved_spec = ef10_filter_entry_spec(eftp, i);
622 } else if (ef10_filter_equal(spec, saved_spec)) {
623 if (ef10_filter_entry_is_busy(eftp, i))
625 if (saved_spec->efs_priority
626 == EFX_FILTER_PRI_AUTO) {
629 } else if (ef10_filter_is_exclusive(spec)) {
643 * Once we reach the maximum search depth, use
644 * the first suitable slot or return EBUSY if
647 if (depth == EF10_FILTER_SEARCH_LIMIT) {
656 EFSYS_UNLOCK(enp->en_eslp, state);
662 * Create a software table entry if necessary, and mark it
663 * busy. We might yet fail to insert, but any attempt to
664 * insert a conflicting filter while we're waiting for the
665 * firmware must find the busy entry.
667 saved_spec = ef10_filter_entry_spec(eftp, ins_index);
669 if (saved_spec->efs_priority == EFX_FILTER_PRI_AUTO) {
670 /* This is a filter we are refreshing */
671 ef10_filter_set_entry_not_auto_old(eftp, ins_index);
677 EFSYS_KMEM_ALLOC(enp->en_esip, sizeof (*spec), saved_spec);
683 ef10_filter_set_entry(eftp, ins_index, saved_spec);
685 ef10_filter_set_entry_busy(eftp, ins_index);
687 EFSYS_UNLOCK(enp->en_eslp, state);
691 * On replacing the filter handle may change after after a successful
695 rc = efx_mcdi_filter_op_add(enp, spec,
696 MC_CMD_FILTER_OP_IN_OP_REPLACE,
697 &eftp->eft_entry[ins_index].efe_handle);
698 } else if (ef10_filter_is_exclusive(spec)) {
699 rc = efx_mcdi_filter_op_add(enp, spec,
700 MC_CMD_FILTER_OP_IN_OP_INSERT,
701 &eftp->eft_entry[ins_index].efe_handle);
703 rc = efx_mcdi_filter_op_add(enp, spec,
704 MC_CMD_FILTER_OP_IN_OP_SUBSCRIBE,
705 &eftp->eft_entry[ins_index].efe_handle);
711 EFSYS_LOCK(enp->en_eslp, state);
715 /* Update the fields that may differ */
716 saved_spec->efs_priority = spec->efs_priority;
717 saved_spec->efs_flags = spec->efs_flags;
718 saved_spec->efs_rss_context = spec->efs_rss_context;
719 saved_spec->efs_dmaq_id = spec->efs_dmaq_id;
722 ef10_filter_set_entry_not_busy(eftp, ins_index);
726 EFSYS_UNLOCK(enp->en_eslp, state);
730 *filter_id = ins_index;
738 EFSYS_KMEM_FREE(enp->en_esip, sizeof (*spec), saved_spec);
741 ef10_filter_set_entry_not_busy(eftp, ins_index);
742 ef10_filter_set_entry(eftp, ins_index, NULL);
751 EFSYS_PROBE1(fail1, efx_rc_t, rc);
754 EFSYS_UNLOCK(enp->en_eslp, state);
759 __checkReturn efx_rc_t
762 __inout efx_filter_spec_t *spec,
763 __in boolean_t may_replace)
767 rc = ef10_filter_add_internal(enp, spec, may_replace, NULL);
774 EFSYS_PROBE1(fail1, efx_rc_t, rc);
780 static __checkReturn efx_rc_t
781 ef10_filter_delete_internal(
783 __in uint32_t filter_id)
786 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
787 efx_filter_spec_t *spec;
788 efsys_lock_state_t state;
789 uint32_t filter_idx = filter_id % EFX_EF10_FILTER_TBL_ROWS;
792 * Find the software table entry and mark it busy. Don't
793 * remove it yet; any attempt to update while we're waiting
794 * for the firmware must find the busy entry.
796 * FIXME: What if the busy flag is never cleared?
798 EFSYS_LOCK(enp->en_eslp, state);
799 while (ef10_filter_entry_is_busy(table, filter_idx)) {
800 EFSYS_UNLOCK(enp->en_eslp, state);
802 EFSYS_LOCK(enp->en_eslp, state);
804 if ((spec = ef10_filter_entry_spec(table, filter_idx)) != NULL) {
805 ef10_filter_set_entry_busy(table, filter_idx);
807 EFSYS_UNLOCK(enp->en_eslp, state);
815 * Try to remove the hardware filter. This may fail if the MC has
816 * rebooted (which frees all hardware filter resources).
818 if (ef10_filter_is_exclusive(spec)) {
819 rc = efx_mcdi_filter_op_delete(enp,
820 MC_CMD_FILTER_OP_IN_OP_REMOVE,
821 &table->eft_entry[filter_idx].efe_handle);
823 rc = efx_mcdi_filter_op_delete(enp,
824 MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE,
825 &table->eft_entry[filter_idx].efe_handle);
828 /* Free the software table entry */
829 EFSYS_LOCK(enp->en_eslp, state);
830 ef10_filter_set_entry_not_busy(table, filter_idx);
831 ef10_filter_set_entry(table, filter_idx, NULL);
832 EFSYS_UNLOCK(enp->en_eslp, state);
834 EFSYS_KMEM_FREE(enp->en_esip, sizeof (*spec), spec);
836 /* Check result of hardware filter removal */
846 EFSYS_PROBE1(fail1, efx_rc_t, rc);
851 __checkReturn efx_rc_t
854 __inout efx_filter_spec_t *spec)
857 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
858 efx_filter_spec_t *saved_spec;
862 efsys_lock_state_t state;
863 boolean_t locked = B_FALSE;
865 EFSYS_ASSERT(enp->en_family == EFX_FAMILY_HUNTINGTON ||
866 enp->en_family == EFX_FAMILY_MEDFORD);
868 hash = ef10_filter_hash(spec);
870 EFSYS_LOCK(enp->en_eslp, state);
875 i = (hash + depth) & (EFX_EF10_FILTER_TBL_ROWS - 1);
876 saved_spec = ef10_filter_entry_spec(table, i);
877 if (saved_spec && ef10_filter_equal(spec, saved_spec) &&
878 ef10_filter_same_dest(spec, saved_spec)) {
881 if (depth == EF10_FILTER_SEARCH_LIMIT) {
888 EFSYS_UNLOCK(enp->en_eslp, state);
891 rc = ef10_filter_delete_internal(enp, i);
901 EFSYS_PROBE1(fail1, efx_rc_t, rc);
904 EFSYS_UNLOCK(enp->en_eslp, state);
909 static __checkReturn efx_rc_t
910 efx_mcdi_get_parser_disp_info(
912 __out_ecount(buffer_length) uint32_t *buffer,
913 __in size_t buffer_length,
914 __out size_t *list_lengthp)
917 uint8_t payload[MAX(MC_CMD_GET_PARSER_DISP_INFO_IN_LEN,
918 MC_CMD_GET_PARSER_DISP_INFO_OUT_LENMAX)];
919 size_t matches_count;
923 (void) memset(payload, 0, sizeof (payload));
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 efx_filter_match_flags_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 * Frimware 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 */