1 /* SPDX-License-Identifier: BSD-3-Clause
3 * Copyright (c) 2007-2018 Solarflare Communications Inc.
10 #if EFSYS_OPT_HUNTINGTON || EFSYS_OPT_MEDFORD || EFSYS_OPT_MEDFORD2
14 #define EFE_SPEC(eftp, index) ((eftp)->eft_entry[(index)].efe_spec)
16 static efx_filter_spec_t *
17 ef10_filter_entry_spec(
18 __in const ef10_filter_table_t *eftp,
19 __in unsigned int index)
21 return ((efx_filter_spec_t *)(EFE_SPEC(eftp, index) &
22 ~(uintptr_t)EFX_EF10_FILTER_FLAGS));
26 ef10_filter_entry_is_busy(
27 __in const ef10_filter_table_t *eftp,
28 __in unsigned int index)
30 if (EFE_SPEC(eftp, index) & EFX_EF10_FILTER_FLAG_BUSY)
37 ef10_filter_entry_is_auto_old(
38 __in const ef10_filter_table_t *eftp,
39 __in unsigned int index)
41 if (EFE_SPEC(eftp, index) & EFX_EF10_FILTER_FLAG_AUTO_OLD)
48 ef10_filter_set_entry(
49 __inout ef10_filter_table_t *eftp,
50 __in unsigned int index,
51 __in_opt const efx_filter_spec_t *efsp)
53 EFE_SPEC(eftp, index) = (uintptr_t)efsp;
57 ef10_filter_set_entry_busy(
58 __inout ef10_filter_table_t *eftp,
59 __in unsigned int index)
61 EFE_SPEC(eftp, index) |= (uintptr_t)EFX_EF10_FILTER_FLAG_BUSY;
65 ef10_filter_set_entry_not_busy(
66 __inout ef10_filter_table_t *eftp,
67 __in unsigned int index)
69 EFE_SPEC(eftp, index) &= ~(uintptr_t)EFX_EF10_FILTER_FLAG_BUSY;
73 ef10_filter_set_entry_auto_old(
74 __inout ef10_filter_table_t *eftp,
75 __in unsigned int index)
77 EFSYS_ASSERT(ef10_filter_entry_spec(eftp, index) != NULL);
78 EFE_SPEC(eftp, index) |= (uintptr_t)EFX_EF10_FILTER_FLAG_AUTO_OLD;
82 ef10_filter_set_entry_not_auto_old(
83 __inout ef10_filter_table_t *eftp,
84 __in unsigned int index)
86 EFE_SPEC(eftp, index) &= ~(uintptr_t)EFX_EF10_FILTER_FLAG_AUTO_OLD;
87 EFSYS_ASSERT(ef10_filter_entry_spec(eftp, index) != NULL);
90 __checkReturn efx_rc_t
95 ef10_filter_table_t *eftp;
97 EFSYS_ASSERT(enp->en_family == EFX_FAMILY_HUNTINGTON ||
98 enp->en_family == EFX_FAMILY_MEDFORD ||
99 enp->en_family == EFX_FAMILY_MEDFORD2);
101 #define MATCH_MASK(match) (EFX_MASK32(match) << EFX_LOW_BIT(match))
102 EFX_STATIC_ASSERT(EFX_FILTER_MATCH_REM_HOST ==
103 MATCH_MASK(MC_CMD_FILTER_OP_EXT_IN_MATCH_SRC_IP));
104 EFX_STATIC_ASSERT(EFX_FILTER_MATCH_LOC_HOST ==
105 MATCH_MASK(MC_CMD_FILTER_OP_EXT_IN_MATCH_DST_IP));
106 EFX_STATIC_ASSERT(EFX_FILTER_MATCH_REM_MAC ==
107 MATCH_MASK(MC_CMD_FILTER_OP_EXT_IN_MATCH_SRC_MAC));
108 EFX_STATIC_ASSERT(EFX_FILTER_MATCH_REM_PORT ==
109 MATCH_MASK(MC_CMD_FILTER_OP_EXT_IN_MATCH_SRC_PORT));
110 EFX_STATIC_ASSERT(EFX_FILTER_MATCH_LOC_MAC ==
111 MATCH_MASK(MC_CMD_FILTER_OP_EXT_IN_MATCH_DST_MAC));
112 EFX_STATIC_ASSERT(EFX_FILTER_MATCH_LOC_PORT ==
113 MATCH_MASK(MC_CMD_FILTER_OP_EXT_IN_MATCH_DST_PORT));
114 EFX_STATIC_ASSERT(EFX_FILTER_MATCH_ETHER_TYPE ==
115 MATCH_MASK(MC_CMD_FILTER_OP_EXT_IN_MATCH_ETHER_TYPE));
116 EFX_STATIC_ASSERT(EFX_FILTER_MATCH_INNER_VID ==
117 MATCH_MASK(MC_CMD_FILTER_OP_EXT_IN_MATCH_INNER_VLAN));
118 EFX_STATIC_ASSERT(EFX_FILTER_MATCH_OUTER_VID ==
119 MATCH_MASK(MC_CMD_FILTER_OP_EXT_IN_MATCH_OUTER_VLAN));
120 EFX_STATIC_ASSERT(EFX_FILTER_MATCH_IP_PROTO ==
121 MATCH_MASK(MC_CMD_FILTER_OP_EXT_IN_MATCH_IP_PROTO));
122 EFX_STATIC_ASSERT(EFX_FILTER_MATCH_VNI_OR_VSID ==
123 MATCH_MASK(MC_CMD_FILTER_OP_EXT_IN_MATCH_VNI_OR_VSID));
124 EFX_STATIC_ASSERT(EFX_FILTER_MATCH_IFRM_LOC_MAC ==
125 MATCH_MASK(MC_CMD_FILTER_OP_EXT_IN_MATCH_IFRM_DST_MAC));
126 EFX_STATIC_ASSERT(EFX_FILTER_MATCH_IFRM_UNKNOWN_MCAST_DST ==
127 MATCH_MASK(MC_CMD_FILTER_OP_EXT_IN_MATCH_IFRM_UNKNOWN_MCAST_DST));
128 EFX_STATIC_ASSERT(EFX_FILTER_MATCH_IFRM_UNKNOWN_UCAST_DST ==
129 MATCH_MASK(MC_CMD_FILTER_OP_EXT_IN_MATCH_IFRM_UNKNOWN_UCAST_DST));
130 EFX_STATIC_ASSERT(EFX_FILTER_MATCH_UNKNOWN_MCAST_DST ==
131 MATCH_MASK(MC_CMD_FILTER_OP_EXT_IN_MATCH_UNKNOWN_MCAST_DST));
132 EFX_STATIC_ASSERT((uint32_t)EFX_FILTER_MATCH_UNKNOWN_UCAST_DST ==
133 MATCH_MASK(MC_CMD_FILTER_OP_EXT_IN_MATCH_UNKNOWN_UCAST_DST));
136 EFSYS_KMEM_ALLOC(enp->en_esip, sizeof (ef10_filter_table_t), eftp);
143 enp->en_filter.ef_ef10_filter_table = eftp;
148 EFSYS_PROBE1(fail1, efx_rc_t, rc);
157 EFSYS_ASSERT(enp->en_family == EFX_FAMILY_HUNTINGTON ||
158 enp->en_family == EFX_FAMILY_MEDFORD ||
159 enp->en_family == EFX_FAMILY_MEDFORD2);
161 if (enp->en_filter.ef_ef10_filter_table != NULL) {
162 EFSYS_KMEM_FREE(enp->en_esip, sizeof (ef10_filter_table_t),
163 enp->en_filter.ef_ef10_filter_table);
167 static __checkReturn efx_rc_t
168 efx_mcdi_filter_op_add(
170 __in efx_filter_spec_t *spec,
171 __in unsigned int filter_op,
172 __inout ef10_filter_handle_t *handle)
175 uint8_t payload[MAX(MC_CMD_FILTER_OP_EXT_IN_LEN,
176 MC_CMD_FILTER_OP_EXT_OUT_LEN)];
179 memset(payload, 0, sizeof (payload));
180 req.emr_cmd = MC_CMD_FILTER_OP;
181 req.emr_in_buf = payload;
182 req.emr_in_length = MC_CMD_FILTER_OP_EXT_IN_LEN;
183 req.emr_out_buf = payload;
184 req.emr_out_length = MC_CMD_FILTER_OP_EXT_OUT_LEN;
187 case MC_CMD_FILTER_OP_IN_OP_REPLACE:
188 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_HANDLE_LO,
190 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_HANDLE_HI,
193 case MC_CMD_FILTER_OP_IN_OP_INSERT:
194 case MC_CMD_FILTER_OP_IN_OP_SUBSCRIBE:
195 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_OP, filter_op);
203 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_PORT_ID,
204 EVB_PORT_ID_ASSIGNED);
205 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_MATCH_FIELDS,
206 spec->efs_match_flags);
207 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_RX_DEST,
208 MC_CMD_FILTER_OP_EXT_IN_RX_DEST_HOST);
209 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_RX_QUEUE,
212 #if EFSYS_OPT_RX_SCALE
213 if (spec->efs_flags & EFX_FILTER_FLAG_RX_RSS) {
214 uint32_t rss_context;
216 if (spec->efs_rss_context == EFX_RSS_CONTEXT_DEFAULT)
217 rss_context = enp->en_rss_context;
219 rss_context = spec->efs_rss_context;
220 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_RX_CONTEXT,
225 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_RX_MODE,
226 spec->efs_flags & EFX_FILTER_FLAG_RX_RSS ?
227 MC_CMD_FILTER_OP_EXT_IN_RX_MODE_RSS :
228 MC_CMD_FILTER_OP_EXT_IN_RX_MODE_SIMPLE);
229 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_TX_DEST,
230 MC_CMD_FILTER_OP_EXT_IN_TX_DEST_DEFAULT);
232 if (filter_op != MC_CMD_FILTER_OP_IN_OP_REPLACE) {
234 * NOTE: Unlike most MCDI requests, the filter fields
235 * are presented in network (big endian) byte order.
237 memcpy(MCDI_IN2(req, uint8_t, FILTER_OP_EXT_IN_SRC_MAC),
238 spec->efs_rem_mac, EFX_MAC_ADDR_LEN);
239 memcpy(MCDI_IN2(req, uint8_t, FILTER_OP_EXT_IN_DST_MAC),
240 spec->efs_loc_mac, EFX_MAC_ADDR_LEN);
242 MCDI_IN_SET_WORD(req, FILTER_OP_EXT_IN_SRC_PORT,
243 __CPU_TO_BE_16(spec->efs_rem_port));
244 MCDI_IN_SET_WORD(req, FILTER_OP_EXT_IN_DST_PORT,
245 __CPU_TO_BE_16(spec->efs_loc_port));
247 MCDI_IN_SET_WORD(req, FILTER_OP_EXT_IN_ETHER_TYPE,
248 __CPU_TO_BE_16(spec->efs_ether_type));
250 MCDI_IN_SET_WORD(req, FILTER_OP_EXT_IN_INNER_VLAN,
251 __CPU_TO_BE_16(spec->efs_inner_vid));
252 MCDI_IN_SET_WORD(req, FILTER_OP_EXT_IN_OUTER_VLAN,
253 __CPU_TO_BE_16(spec->efs_outer_vid));
255 /* IP protocol (in low byte, high byte is zero) */
256 MCDI_IN_SET_BYTE(req, FILTER_OP_EXT_IN_IP_PROTO,
259 EFX_STATIC_ASSERT(sizeof (spec->efs_rem_host) ==
260 MC_CMD_FILTER_OP_EXT_IN_SRC_IP_LEN);
261 EFX_STATIC_ASSERT(sizeof (spec->efs_loc_host) ==
262 MC_CMD_FILTER_OP_EXT_IN_DST_IP_LEN);
264 memcpy(MCDI_IN2(req, uint8_t, FILTER_OP_EXT_IN_SRC_IP),
265 &spec->efs_rem_host.eo_byte[0],
266 MC_CMD_FILTER_OP_EXT_IN_SRC_IP_LEN);
267 memcpy(MCDI_IN2(req, uint8_t, FILTER_OP_EXT_IN_DST_IP),
268 &spec->efs_loc_host.eo_byte[0],
269 MC_CMD_FILTER_OP_EXT_IN_DST_IP_LEN);
272 * On Medford, filters for encapsulated packets match based on
273 * the ether type and IP protocol in the outer frame. In
274 * addition we need to fill in the VNI or VSID type field.
276 switch (spec->efs_encap_type) {
277 case EFX_TUNNEL_PROTOCOL_NONE:
279 case EFX_TUNNEL_PROTOCOL_VXLAN:
280 case EFX_TUNNEL_PROTOCOL_GENEVE:
281 MCDI_IN_POPULATE_DWORD_1(req,
282 FILTER_OP_EXT_IN_VNI_OR_VSID,
283 FILTER_OP_EXT_IN_VNI_TYPE,
284 spec->efs_encap_type == EFX_TUNNEL_PROTOCOL_VXLAN ?
285 MC_CMD_FILTER_OP_EXT_IN_VNI_TYPE_VXLAN :
286 MC_CMD_FILTER_OP_EXT_IN_VNI_TYPE_GENEVE);
288 case EFX_TUNNEL_PROTOCOL_NVGRE:
289 MCDI_IN_POPULATE_DWORD_1(req,
290 FILTER_OP_EXT_IN_VNI_OR_VSID,
291 FILTER_OP_EXT_IN_VSID_TYPE,
292 MC_CMD_FILTER_OP_EXT_IN_VSID_TYPE_NVGRE);
300 memcpy(MCDI_IN2(req, uint8_t, FILTER_OP_EXT_IN_VNI_OR_VSID),
301 spec->efs_vni_or_vsid, EFX_VNI_OR_VSID_LEN);
303 memcpy(MCDI_IN2(req, uint8_t, FILTER_OP_EXT_IN_IFRM_DST_MAC),
304 spec->efs_ifrm_loc_mac, EFX_MAC_ADDR_LEN);
307 efx_mcdi_execute(enp, &req);
309 if (req.emr_rc != 0) {
314 if (req.emr_out_length_used < MC_CMD_FILTER_OP_EXT_OUT_LEN) {
319 handle->efh_lo = MCDI_OUT_DWORD(req, FILTER_OP_EXT_OUT_HANDLE_LO);
320 handle->efh_hi = MCDI_OUT_DWORD(req, FILTER_OP_EXT_OUT_HANDLE_HI);
331 EFSYS_PROBE1(fail1, efx_rc_t, rc);
337 static __checkReturn efx_rc_t
338 efx_mcdi_filter_op_delete(
340 __in unsigned int filter_op,
341 __inout ef10_filter_handle_t *handle)
344 uint8_t payload[MAX(MC_CMD_FILTER_OP_EXT_IN_LEN,
345 MC_CMD_FILTER_OP_EXT_OUT_LEN)];
348 memset(payload, 0, sizeof (payload));
349 req.emr_cmd = MC_CMD_FILTER_OP;
350 req.emr_in_buf = payload;
351 req.emr_in_length = MC_CMD_FILTER_OP_EXT_IN_LEN;
352 req.emr_out_buf = payload;
353 req.emr_out_length = MC_CMD_FILTER_OP_EXT_OUT_LEN;
356 case MC_CMD_FILTER_OP_IN_OP_REMOVE:
357 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_OP,
358 MC_CMD_FILTER_OP_IN_OP_REMOVE);
360 case MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE:
361 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_OP,
362 MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE);
370 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_HANDLE_LO, handle->efh_lo);
371 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_HANDLE_HI, handle->efh_hi);
373 efx_mcdi_execute_quiet(enp, &req);
375 if (req.emr_rc != 0) {
380 if (req.emr_out_length_used < MC_CMD_FILTER_OP_EXT_OUT_LEN) {
393 EFSYS_PROBE1(fail1, efx_rc_t, rc);
398 static __checkReturn boolean_t
400 __in const efx_filter_spec_t *left,
401 __in const efx_filter_spec_t *right)
403 /* FIXME: Consider rx vs tx filters (look at efs_flags) */
404 if (left->efs_match_flags != right->efs_match_flags)
406 if (!EFX_OWORD_IS_EQUAL(left->efs_rem_host, right->efs_rem_host))
408 if (!EFX_OWORD_IS_EQUAL(left->efs_loc_host, right->efs_loc_host))
410 if (memcmp(left->efs_rem_mac, right->efs_rem_mac, EFX_MAC_ADDR_LEN))
412 if (memcmp(left->efs_loc_mac, right->efs_loc_mac, EFX_MAC_ADDR_LEN))
414 if (left->efs_rem_port != right->efs_rem_port)
416 if (left->efs_loc_port != right->efs_loc_port)
418 if (left->efs_inner_vid != right->efs_inner_vid)
420 if (left->efs_outer_vid != right->efs_outer_vid)
422 if (left->efs_ether_type != right->efs_ether_type)
424 if (left->efs_ip_proto != right->efs_ip_proto)
426 if (left->efs_encap_type != right->efs_encap_type)
428 if (memcmp(left->efs_vni_or_vsid, right->efs_vni_or_vsid,
429 EFX_VNI_OR_VSID_LEN))
431 if (memcmp(left->efs_ifrm_loc_mac, right->efs_ifrm_loc_mac,
439 static __checkReturn boolean_t
440 ef10_filter_same_dest(
441 __in const efx_filter_spec_t *left,
442 __in const efx_filter_spec_t *right)
444 if ((left->efs_flags & EFX_FILTER_FLAG_RX_RSS) &&
445 (right->efs_flags & EFX_FILTER_FLAG_RX_RSS)) {
446 if (left->efs_rss_context == right->efs_rss_context)
448 } else if ((~(left->efs_flags) & EFX_FILTER_FLAG_RX_RSS) &&
449 (~(right->efs_flags) & EFX_FILTER_FLAG_RX_RSS)) {
450 if (left->efs_dmaq_id == right->efs_dmaq_id)
456 static __checkReturn uint32_t
458 __in efx_filter_spec_t *spec)
460 EFX_STATIC_ASSERT((sizeof (efx_filter_spec_t) % sizeof (uint32_t))
462 EFX_STATIC_ASSERT((EFX_FIELD_OFFSET(efx_filter_spec_t, efs_outer_vid) %
463 sizeof (uint32_t)) == 0);
466 * As the area of the efx_filter_spec_t we need to hash is DWORD
467 * aligned and an exact number of DWORDs in size we can use the
468 * optimised efx_hash_dwords() rather than efx_hash_bytes()
470 return (efx_hash_dwords((const uint32_t *)&spec->efs_outer_vid,
471 (sizeof (efx_filter_spec_t) -
472 EFX_FIELD_OFFSET(efx_filter_spec_t, efs_outer_vid)) /
473 sizeof (uint32_t), 0));
477 * Decide whether a filter should be exclusive or else should allow
478 * delivery to additional recipients. Currently we decide that
479 * filters for specific local unicast MAC and IP addresses are
482 static __checkReturn boolean_t
483 ef10_filter_is_exclusive(
484 __in efx_filter_spec_t *spec)
486 if ((spec->efs_match_flags & EFX_FILTER_MATCH_LOC_MAC) &&
487 !EFX_MAC_ADDR_IS_MULTICAST(spec->efs_loc_mac))
490 if ((spec->efs_match_flags &
491 (EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_LOC_HOST)) ==
492 (EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_LOC_HOST)) {
493 if ((spec->efs_ether_type == EFX_ETHER_TYPE_IPV4) &&
494 ((spec->efs_loc_host.eo_u8[0] & 0xf) != 0xe))
496 if ((spec->efs_ether_type == EFX_ETHER_TYPE_IPV6) &&
497 (spec->efs_loc_host.eo_u8[0] != 0xff))
504 __checkReturn efx_rc_t
509 efx_filter_spec_t *spec;
510 ef10_filter_table_t *eftp = enp->en_filter.ef_ef10_filter_table;
512 efsys_lock_state_t state;
515 EFSYS_ASSERT(enp->en_family == EFX_FAMILY_HUNTINGTON ||
516 enp->en_family == EFX_FAMILY_MEDFORD ||
517 enp->en_family == EFX_FAMILY_MEDFORD2);
519 for (tbl_id = 0; tbl_id < EFX_EF10_FILTER_TBL_ROWS; tbl_id++) {
521 EFSYS_LOCK(enp->en_eslp, state);
523 spec = ef10_filter_entry_spec(eftp, tbl_id);
526 } else if (ef10_filter_entry_is_busy(eftp, tbl_id)) {
527 /* Ignore busy entries. */
530 ef10_filter_set_entry_busy(eftp, tbl_id);
534 EFSYS_UNLOCK(enp->en_eslp, state);
536 if (restoring == B_FALSE)
539 if (ef10_filter_is_exclusive(spec)) {
540 rc = efx_mcdi_filter_op_add(enp, spec,
541 MC_CMD_FILTER_OP_IN_OP_INSERT,
542 &eftp->eft_entry[tbl_id].efe_handle);
544 rc = efx_mcdi_filter_op_add(enp, spec,
545 MC_CMD_FILTER_OP_IN_OP_SUBSCRIBE,
546 &eftp->eft_entry[tbl_id].efe_handle);
552 EFSYS_LOCK(enp->en_eslp, state);
554 ef10_filter_set_entry_not_busy(eftp, tbl_id);
556 EFSYS_UNLOCK(enp->en_eslp, state);
562 EFSYS_PROBE1(fail1, efx_rc_t, rc);
568 * An arbitrary search limit for the software hash table. As per the linux net
571 #define EF10_FILTER_SEARCH_LIMIT 200
573 static __checkReturn efx_rc_t
574 ef10_filter_add_internal(
576 __inout efx_filter_spec_t *spec,
577 __in boolean_t may_replace,
578 __out_opt uint32_t *filter_id)
581 ef10_filter_table_t *eftp = enp->en_filter.ef_ef10_filter_table;
582 efx_filter_spec_t *saved_spec;
586 boolean_t replacing = B_FALSE;
588 efsys_lock_state_t state;
589 boolean_t locked = B_FALSE;
591 EFSYS_ASSERT(enp->en_family == EFX_FAMILY_HUNTINGTON ||
592 enp->en_family == EFX_FAMILY_MEDFORD ||
593 enp->en_family == EFX_FAMILY_MEDFORD2);
595 hash = ef10_filter_hash(spec);
598 * FIXME: Add support for inserting filters of different priorities
599 * and removing lower priority multicast filters (bug 42378)
603 * Find any existing filters with the same match tuple or
604 * else a free slot to insert at. If any of them are busy,
605 * we have to wait and retry.
610 EFSYS_LOCK(enp->en_eslp, state);
614 i = (hash + depth) & (EFX_EF10_FILTER_TBL_ROWS - 1);
615 saved_spec = ef10_filter_entry_spec(eftp, i);
621 } else if (ef10_filter_equal(spec, saved_spec)) {
622 if (ef10_filter_entry_is_busy(eftp, i))
624 if (saved_spec->efs_priority
625 == EFX_FILTER_PRI_AUTO) {
628 } else if (ef10_filter_is_exclusive(spec)) {
642 * Once we reach the maximum search depth, use
643 * the first suitable slot or return EBUSY if
646 if (depth == EF10_FILTER_SEARCH_LIMIT) {
655 EFSYS_UNLOCK(enp->en_eslp, state);
661 * Create a software table entry if necessary, and mark it
662 * busy. We might yet fail to insert, but any attempt to
663 * insert a conflicting filter while we're waiting for the
664 * firmware must find the busy entry.
666 saved_spec = ef10_filter_entry_spec(eftp, ins_index);
668 if (saved_spec->efs_priority == EFX_FILTER_PRI_AUTO) {
669 /* This is a filter we are refreshing */
670 ef10_filter_set_entry_not_auto_old(eftp, ins_index);
676 EFSYS_KMEM_ALLOC(enp->en_esip, sizeof (*spec), saved_spec);
682 ef10_filter_set_entry(eftp, ins_index, saved_spec);
684 ef10_filter_set_entry_busy(eftp, ins_index);
686 EFSYS_UNLOCK(enp->en_eslp, state);
690 * On replacing the filter handle may change after after a successful
694 rc = efx_mcdi_filter_op_add(enp, spec,
695 MC_CMD_FILTER_OP_IN_OP_REPLACE,
696 &eftp->eft_entry[ins_index].efe_handle);
697 } else if (ef10_filter_is_exclusive(spec)) {
698 rc = efx_mcdi_filter_op_add(enp, spec,
699 MC_CMD_FILTER_OP_IN_OP_INSERT,
700 &eftp->eft_entry[ins_index].efe_handle);
702 rc = efx_mcdi_filter_op_add(enp, spec,
703 MC_CMD_FILTER_OP_IN_OP_SUBSCRIBE,
704 &eftp->eft_entry[ins_index].efe_handle);
710 EFSYS_LOCK(enp->en_eslp, state);
714 /* Update the fields that may differ */
715 saved_spec->efs_priority = spec->efs_priority;
716 saved_spec->efs_flags = spec->efs_flags;
717 saved_spec->efs_rss_context = spec->efs_rss_context;
718 saved_spec->efs_dmaq_id = spec->efs_dmaq_id;
721 ef10_filter_set_entry_not_busy(eftp, ins_index);
725 EFSYS_UNLOCK(enp->en_eslp, state);
729 *filter_id = ins_index;
737 EFSYS_KMEM_FREE(enp->en_esip, sizeof (*spec), saved_spec);
740 ef10_filter_set_entry_not_busy(eftp, ins_index);
741 ef10_filter_set_entry(eftp, ins_index, NULL);
750 EFSYS_PROBE1(fail1, efx_rc_t, rc);
753 EFSYS_UNLOCK(enp->en_eslp, state);
758 __checkReturn efx_rc_t
761 __inout efx_filter_spec_t *spec,
762 __in boolean_t may_replace)
766 rc = ef10_filter_add_internal(enp, spec, may_replace, NULL);
773 EFSYS_PROBE1(fail1, efx_rc_t, rc);
779 static __checkReturn efx_rc_t
780 ef10_filter_delete_internal(
782 __in uint32_t filter_id)
785 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
786 efx_filter_spec_t *spec;
787 efsys_lock_state_t state;
788 uint32_t filter_idx = filter_id % EFX_EF10_FILTER_TBL_ROWS;
791 * Find the software table entry and mark it busy. Don't
792 * remove it yet; any attempt to update while we're waiting
793 * for the firmware must find the busy entry.
795 * FIXME: What if the busy flag is never cleared?
797 EFSYS_LOCK(enp->en_eslp, state);
798 while (ef10_filter_entry_is_busy(table, filter_idx)) {
799 EFSYS_UNLOCK(enp->en_eslp, state);
801 EFSYS_LOCK(enp->en_eslp, state);
803 if ((spec = ef10_filter_entry_spec(table, filter_idx)) != NULL) {
804 ef10_filter_set_entry_busy(table, filter_idx);
806 EFSYS_UNLOCK(enp->en_eslp, state);
814 * Try to remove the hardware filter. This may fail if the MC has
815 * rebooted (which frees all hardware filter resources).
817 if (ef10_filter_is_exclusive(spec)) {
818 rc = efx_mcdi_filter_op_delete(enp,
819 MC_CMD_FILTER_OP_IN_OP_REMOVE,
820 &table->eft_entry[filter_idx].efe_handle);
822 rc = efx_mcdi_filter_op_delete(enp,
823 MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE,
824 &table->eft_entry[filter_idx].efe_handle);
827 /* Free the software table entry */
828 EFSYS_LOCK(enp->en_eslp, state);
829 ef10_filter_set_entry_not_busy(table, filter_idx);
830 ef10_filter_set_entry(table, filter_idx, NULL);
831 EFSYS_UNLOCK(enp->en_eslp, state);
833 EFSYS_KMEM_FREE(enp->en_esip, sizeof (*spec), spec);
835 /* Check result of hardware filter removal */
845 EFSYS_PROBE1(fail1, efx_rc_t, rc);
850 __checkReturn efx_rc_t
853 __inout efx_filter_spec_t *spec)
856 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
857 efx_filter_spec_t *saved_spec;
861 efsys_lock_state_t state;
862 boolean_t locked = B_FALSE;
864 EFSYS_ASSERT(enp->en_family == EFX_FAMILY_HUNTINGTON ||
865 enp->en_family == EFX_FAMILY_MEDFORD ||
866 enp->en_family == EFX_FAMILY_MEDFORD2);
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 __in boolean_t encap,
915 __out size_t *list_lengthp)
918 uint8_t payload[MAX(MC_CMD_GET_PARSER_DISP_INFO_IN_LEN,
919 MC_CMD_GET_PARSER_DISP_INFO_OUT_LENMAX)];
920 size_t matches_count;
924 (void) memset(payload, 0, sizeof (payload));
925 req.emr_cmd = MC_CMD_GET_PARSER_DISP_INFO;
926 req.emr_in_buf = payload;
927 req.emr_in_length = MC_CMD_GET_PARSER_DISP_INFO_IN_LEN;
928 req.emr_out_buf = payload;
929 req.emr_out_length = MC_CMD_GET_PARSER_DISP_INFO_OUT_LENMAX;
931 MCDI_IN_SET_DWORD(req, GET_PARSER_DISP_INFO_OUT_OP, encap ?
932 MC_CMD_GET_PARSER_DISP_INFO_IN_OP_GET_SUPPORTED_ENCAP_RX_MATCHES :
933 MC_CMD_GET_PARSER_DISP_INFO_IN_OP_GET_SUPPORTED_RX_MATCHES);
935 efx_mcdi_execute(enp, &req);
937 if (req.emr_rc != 0) {
942 matches_count = MCDI_OUT_DWORD(req,
943 GET_PARSER_DISP_INFO_OUT_NUM_SUPPORTED_MATCHES);
945 if (req.emr_out_length_used <
946 MC_CMD_GET_PARSER_DISP_INFO_OUT_LEN(matches_count)) {
951 *list_lengthp = matches_count;
953 if (buffer_length < matches_count) {
959 * Check that the elements in the list in the MCDI response are the size
960 * we expect, so we can just copy them directly. Any conversion of the
961 * flags is handled by the caller.
963 EFX_STATIC_ASSERT(sizeof (uint32_t) ==
964 MC_CMD_GET_PARSER_DISP_INFO_OUT_SUPPORTED_MATCHES_LEN);
966 list_size = matches_count *
967 MC_CMD_GET_PARSER_DISP_INFO_OUT_SUPPORTED_MATCHES_LEN;
969 MCDI_OUT2(req, uint32_t,
970 GET_PARSER_DISP_INFO_OUT_SUPPORTED_MATCHES),
980 EFSYS_PROBE1(fail1, efx_rc_t, rc);
985 __checkReturn efx_rc_t
986 ef10_filter_supported_filters(
988 __out_ecount(buffer_length) uint32_t *buffer,
989 __in size_t buffer_length,
990 __out size_t *list_lengthp)
992 efx_nic_cfg_t *encp = &(enp->en_nic_cfg);
993 size_t mcdi_list_length;
994 size_t mcdi_encap_list_length;
997 uint32_t next_buf_idx;
998 size_t next_buf_length;
1000 boolean_t no_space = B_FALSE;
1001 efx_filter_match_flags_t all_filter_flags =
1002 (EFX_FILTER_MATCH_REM_HOST | EFX_FILTER_MATCH_LOC_HOST |
1003 EFX_FILTER_MATCH_REM_MAC | EFX_FILTER_MATCH_REM_PORT |
1004 EFX_FILTER_MATCH_LOC_MAC | EFX_FILTER_MATCH_LOC_PORT |
1005 EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_INNER_VID |
1006 EFX_FILTER_MATCH_OUTER_VID | EFX_FILTER_MATCH_IP_PROTO |
1007 EFX_FILTER_MATCH_VNI_OR_VSID |
1008 EFX_FILTER_MATCH_IFRM_LOC_MAC |
1009 EFX_FILTER_MATCH_IFRM_UNKNOWN_MCAST_DST |
1010 EFX_FILTER_MATCH_IFRM_UNKNOWN_UCAST_DST |
1011 EFX_FILTER_MATCH_UNKNOWN_MCAST_DST |
1012 EFX_FILTER_MATCH_UNKNOWN_UCAST_DST);
1015 * Two calls to MC_CMD_GET_PARSER_DISP_INFO are needed: one to get the
1016 * list of supported filters for ordinary packets, and then another to
1017 * get the list of supported filters for encapsulated packets.
1019 rc = efx_mcdi_get_parser_disp_info(enp, buffer, buffer_length, B_FALSE,
1030 next_buf_length = 0;
1032 EFSYS_ASSERT(mcdi_list_length <= buffer_length);
1033 next_buf_idx = mcdi_list_length;
1034 next_buf_length = buffer_length - mcdi_list_length;
1037 if (encp->enc_tunnel_encapsulations_supported != 0) {
1038 rc = efx_mcdi_get_parser_disp_info(enp, &buffer[next_buf_idx],
1039 next_buf_length, B_TRUE, &mcdi_encap_list_length);
1047 mcdi_encap_list_length = 0;
1051 *list_lengthp = mcdi_list_length + mcdi_encap_list_length;
1057 * The static assertions in ef10_filter_init() ensure that the values of
1058 * the EFX_FILTER_MATCH flags match those used by MCDI, so they don't
1059 * need to be converted.
1061 * In case support is added to MCDI for additional flags, remove any
1062 * matches from the list which include flags we don't support. The order
1063 * of the matches is preserved as they are ordered from highest to
1066 EFSYS_ASSERT(mcdi_list_length + mcdi_encap_list_length <=
1069 for (i = 0; i < mcdi_list_length + mcdi_encap_list_length; i++) {
1070 if ((buffer[i] & ~all_filter_flags) == 0) {
1071 buffer[list_length] = buffer[i];
1076 *list_lengthp = list_length;
1085 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1090 static __checkReturn efx_rc_t
1091 ef10_filter_insert_unicast(
1092 __in efx_nic_t *enp,
1093 __in_ecount(6) uint8_t const *addr,
1094 __in efx_filter_flags_t filter_flags)
1096 ef10_filter_table_t *eftp = enp->en_filter.ef_ef10_filter_table;
1097 efx_filter_spec_t spec;
1100 /* Insert the filter for the local station address */
1101 efx_filter_spec_init_rx(&spec, EFX_FILTER_PRI_AUTO,
1103 eftp->eft_default_rxq);
1104 efx_filter_spec_set_eth_local(&spec, EFX_FILTER_SPEC_VID_UNSPEC, addr);
1106 rc = ef10_filter_add_internal(enp, &spec, B_TRUE,
1107 &eftp->eft_unicst_filter_indexes[eftp->eft_unicst_filter_count]);
1111 eftp->eft_unicst_filter_count++;
1112 EFSYS_ASSERT(eftp->eft_unicst_filter_count <=
1113 EFX_EF10_FILTER_UNICAST_FILTERS_MAX);
1118 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1122 static __checkReturn efx_rc_t
1123 ef10_filter_insert_all_unicast(
1124 __in efx_nic_t *enp,
1125 __in efx_filter_flags_t filter_flags)
1127 ef10_filter_table_t *eftp = enp->en_filter.ef_ef10_filter_table;
1128 efx_filter_spec_t spec;
1131 /* Insert the unknown unicast filter */
1132 efx_filter_spec_init_rx(&spec, EFX_FILTER_PRI_AUTO,
1134 eftp->eft_default_rxq);
1135 efx_filter_spec_set_uc_def(&spec);
1136 rc = ef10_filter_add_internal(enp, &spec, B_TRUE,
1137 &eftp->eft_unicst_filter_indexes[eftp->eft_unicst_filter_count]);
1141 eftp->eft_unicst_filter_count++;
1142 EFSYS_ASSERT(eftp->eft_unicst_filter_count <=
1143 EFX_EF10_FILTER_UNICAST_FILTERS_MAX);
1148 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1152 static __checkReturn efx_rc_t
1153 ef10_filter_insert_multicast_list(
1154 __in efx_nic_t *enp,
1155 __in boolean_t mulcst,
1156 __in boolean_t brdcst,
1157 __in_ecount(6*count) uint8_t const *addrs,
1158 __in uint32_t count,
1159 __in efx_filter_flags_t filter_flags,
1160 __in boolean_t rollback)
1162 ef10_filter_table_t *eftp = enp->en_filter.ef_ef10_filter_table;
1163 efx_filter_spec_t spec;
1166 uint32_t filter_index;
1167 uint32_t filter_count;
1170 if (mulcst == B_FALSE)
1173 if (count + (brdcst ? 1 : 0) >
1174 EFX_ARRAY_SIZE(eftp->eft_mulcst_filter_indexes)) {
1175 /* Too many MAC addresses */
1180 /* Insert/renew multicast address list filters */
1182 for (i = 0; i < count; i++) {
1183 efx_filter_spec_init_rx(&spec,
1184 EFX_FILTER_PRI_AUTO,
1186 eftp->eft_default_rxq);
1188 efx_filter_spec_set_eth_local(&spec,
1189 EFX_FILTER_SPEC_VID_UNSPEC,
1190 &addrs[i * EFX_MAC_ADDR_LEN]);
1192 rc = ef10_filter_add_internal(enp, &spec, B_TRUE,
1196 eftp->eft_mulcst_filter_indexes[filter_count] =
1199 } else if (rollback == B_TRUE) {
1200 /* Only stop upon failure if told to rollback */
1206 if (brdcst == B_TRUE) {
1207 /* Insert/renew broadcast address filter */
1208 efx_filter_spec_init_rx(&spec, EFX_FILTER_PRI_AUTO,
1210 eftp->eft_default_rxq);
1212 EFX_MAC_BROADCAST_ADDR_SET(addr);
1213 efx_filter_spec_set_eth_local(&spec, EFX_FILTER_SPEC_VID_UNSPEC,
1216 rc = ef10_filter_add_internal(enp, &spec, B_TRUE,
1220 eftp->eft_mulcst_filter_indexes[filter_count] =
1223 } else if (rollback == B_TRUE) {
1224 /* Only stop upon failure if told to rollback */
1229 eftp->eft_mulcst_filter_count = filter_count;
1230 eftp->eft_using_all_mulcst = B_FALSE;
1235 /* Remove any filters we have inserted */
1238 (void) ef10_filter_delete_internal(enp,
1239 eftp->eft_mulcst_filter_indexes[i]);
1241 eftp->eft_mulcst_filter_count = 0;
1244 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1249 static __checkReturn efx_rc_t
1250 ef10_filter_insert_all_multicast(
1251 __in efx_nic_t *enp,
1252 __in efx_filter_flags_t filter_flags)
1254 ef10_filter_table_t *eftp = enp->en_filter.ef_ef10_filter_table;
1255 efx_filter_spec_t spec;
1258 /* Insert the unknown multicast filter */
1259 efx_filter_spec_init_rx(&spec, EFX_FILTER_PRI_AUTO,
1261 eftp->eft_default_rxq);
1262 efx_filter_spec_set_mc_def(&spec);
1264 rc = ef10_filter_add_internal(enp, &spec, B_TRUE,
1265 &eftp->eft_mulcst_filter_indexes[0]);
1269 eftp->eft_mulcst_filter_count = 1;
1270 eftp->eft_using_all_mulcst = B_TRUE;
1273 * FIXME: If brdcst == B_FALSE, add a filter to drop broadcast traffic.
1279 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1284 typedef struct ef10_filter_encap_entry_s {
1285 uint16_t ether_type;
1286 efx_tunnel_protocol_t encap_type;
1287 uint32_t inner_frame_match;
1288 } ef10_filter_encap_entry_t;
1290 #define EF10_ENCAP_FILTER_ENTRY(ipv, encap_type, inner_frame_match) \
1291 { EFX_ETHER_TYPE_##ipv, EFX_TUNNEL_PROTOCOL_##encap_type, \
1292 EFX_FILTER_INNER_FRAME_MATCH_UNKNOWN_##inner_frame_match }
1294 static ef10_filter_encap_entry_t ef10_filter_encap_list[] = {
1295 EF10_ENCAP_FILTER_ENTRY(IPV4, VXLAN, UCAST_DST),
1296 EF10_ENCAP_FILTER_ENTRY(IPV4, VXLAN, MCAST_DST),
1297 EF10_ENCAP_FILTER_ENTRY(IPV6, VXLAN, UCAST_DST),
1298 EF10_ENCAP_FILTER_ENTRY(IPV6, VXLAN, MCAST_DST),
1300 EF10_ENCAP_FILTER_ENTRY(IPV4, GENEVE, UCAST_DST),
1301 EF10_ENCAP_FILTER_ENTRY(IPV4, GENEVE, MCAST_DST),
1302 EF10_ENCAP_FILTER_ENTRY(IPV6, GENEVE, UCAST_DST),
1303 EF10_ENCAP_FILTER_ENTRY(IPV6, GENEVE, MCAST_DST),
1305 EF10_ENCAP_FILTER_ENTRY(IPV4, NVGRE, UCAST_DST),
1306 EF10_ENCAP_FILTER_ENTRY(IPV4, NVGRE, MCAST_DST),
1307 EF10_ENCAP_FILTER_ENTRY(IPV6, NVGRE, UCAST_DST),
1308 EF10_ENCAP_FILTER_ENTRY(IPV6, NVGRE, MCAST_DST),
1311 #undef EF10_ENCAP_FILTER_ENTRY
1313 static __checkReturn efx_rc_t
1314 ef10_filter_insert_encap_filters(
1315 __in efx_nic_t *enp,
1316 __in boolean_t mulcst,
1317 __in efx_filter_flags_t filter_flags)
1319 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
1323 EFX_STATIC_ASSERT(EFX_ARRAY_SIZE(ef10_filter_encap_list) <=
1324 EFX_ARRAY_SIZE(table->eft_encap_filter_indexes));
1327 * On Medford, full-featured firmware can identify packets as being
1328 * tunnel encapsulated, even if no encapsulated packet offloads are in
1329 * use. When packets are identified as such, ordinary filters are not
1330 * applied, only ones specific to encapsulated packets. Hence we need to
1331 * insert filters for encapsulated packets in order to receive them.
1333 * Separate filters need to be inserted for each ether type,
1334 * encapsulation type, and inner frame type (unicast or multicast). To
1335 * keep things simple and reduce the number of filters needed, catch-all
1336 * filters for all combinations of types are inserted, even if
1337 * all_unicst or all_mulcst have not been set. (These catch-all filters
1338 * may well, however, fail to insert on unprivileged functions.)
1340 table->eft_encap_filter_count = 0;
1341 for (i = 0; i < EFX_ARRAY_SIZE(ef10_filter_encap_list); i++) {
1342 efx_filter_spec_t spec;
1343 ef10_filter_encap_entry_t *encap_filter =
1344 &ef10_filter_encap_list[i];
1347 * Skip multicast filters if we've not been asked for
1348 * any multicast traffic.
1350 if ((mulcst == B_FALSE) &&
1351 (encap_filter->inner_frame_match ==
1352 EFX_FILTER_INNER_FRAME_MATCH_UNKNOWN_MCAST_DST))
1355 efx_filter_spec_init_rx(&spec, EFX_FILTER_PRI_AUTO,
1357 table->eft_default_rxq);
1358 efx_filter_spec_set_ether_type(&spec, encap_filter->ether_type);
1359 rc = efx_filter_spec_set_encap_type(&spec,
1360 encap_filter->encap_type,
1361 encap_filter->inner_frame_match);
1365 rc = ef10_filter_add_internal(enp, &spec, B_TRUE,
1366 &table->eft_encap_filter_indexes[
1367 table->eft_encap_filter_count]);
1372 table->eft_encap_filter_count++;
1381 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1387 ef10_filter_remove_old(
1388 __in efx_nic_t *enp)
1390 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
1393 for (i = 0; i < EFX_ARRAY_SIZE(table->eft_entry); i++) {
1394 if (ef10_filter_entry_is_auto_old(table, i)) {
1395 (void) ef10_filter_delete_internal(enp, i);
1401 static __checkReturn efx_rc_t
1402 ef10_filter_get_workarounds(
1403 __in efx_nic_t *enp)
1405 efx_nic_cfg_t *encp = &enp->en_nic_cfg;
1406 uint32_t implemented = 0;
1407 uint32_t enabled = 0;
1410 rc = efx_mcdi_get_workarounds(enp, &implemented, &enabled);
1412 /* Check if chained multicast filter support is enabled */
1413 if (implemented & enabled & MC_CMD_GET_WORKAROUNDS_OUT_BUG26807)
1414 encp->enc_bug26807_workaround = B_TRUE;
1416 encp->enc_bug26807_workaround = B_FALSE;
1417 } else if (rc == ENOTSUP) {
1419 * Firmware is too old to support GET_WORKAROUNDS, and support
1420 * for this workaround was implemented later.
1422 encp->enc_bug26807_workaround = B_FALSE;
1430 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1438 * Reconfigure all filters.
1439 * If all_unicst and/or all mulcst filters cannot be applied then
1440 * return ENOTSUP (Note the filters for the specified addresses are
1441 * still applied in this case).
1443 __checkReturn efx_rc_t
1444 ef10_filter_reconfigure(
1445 __in efx_nic_t *enp,
1446 __in_ecount(6) uint8_t const *mac_addr,
1447 __in boolean_t all_unicst,
1448 __in boolean_t mulcst,
1449 __in boolean_t all_mulcst,
1450 __in boolean_t brdcst,
1451 __in_ecount(6*count) uint8_t const *addrs,
1452 __in uint32_t count)
1454 efx_nic_cfg_t *encp = &enp->en_nic_cfg;
1455 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
1456 efx_filter_flags_t filter_flags;
1458 efx_rc_t all_unicst_rc = 0;
1459 efx_rc_t all_mulcst_rc = 0;
1462 if (table->eft_default_rxq == NULL) {
1464 * Filters direct traffic to the default RXQ, and so cannot be
1465 * inserted until it is available. Any currently configured
1466 * filters must be removed (ignore errors in case the MC
1467 * has rebooted, which removes hardware filters).
1469 for (i = 0; i < table->eft_unicst_filter_count; i++) {
1470 (void) ef10_filter_delete_internal(enp,
1471 table->eft_unicst_filter_indexes[i]);
1473 table->eft_unicst_filter_count = 0;
1475 for (i = 0; i < table->eft_mulcst_filter_count; i++) {
1476 (void) ef10_filter_delete_internal(enp,
1477 table->eft_mulcst_filter_indexes[i]);
1479 table->eft_mulcst_filter_count = 0;
1481 for (i = 0; i < table->eft_encap_filter_count; i++) {
1482 (void) ef10_filter_delete_internal(enp,
1483 table->eft_encap_filter_indexes[i]);
1485 table->eft_encap_filter_count = 0;
1490 if (table->eft_using_rss)
1491 filter_flags = EFX_FILTER_FLAG_RX_RSS;
1495 /* Mark old filters which may need to be removed */
1496 for (i = 0; i < table->eft_unicst_filter_count; i++) {
1497 ef10_filter_set_entry_auto_old(table,
1498 table->eft_unicst_filter_indexes[i]);
1500 for (i = 0; i < table->eft_mulcst_filter_count; i++) {
1501 ef10_filter_set_entry_auto_old(table,
1502 table->eft_mulcst_filter_indexes[i]);
1504 for (i = 0; i < table->eft_encap_filter_count; i++) {
1505 ef10_filter_set_entry_auto_old(table,
1506 table->eft_encap_filter_indexes[i]);
1510 * Insert or renew unicast filters.
1512 * Frimware does not perform chaining on unicast filters. As traffic is
1513 * therefore only delivered to the first matching filter, we should
1514 * always insert the specific filter for our MAC address, to try and
1515 * ensure we get that traffic.
1517 * (If the filter for our MAC address has already been inserted by
1518 * another function, we won't receive traffic sent to us, even if we
1519 * insert a unicast mismatch filter. To prevent traffic stealing, this
1520 * therefore relies on the privilege model only allowing functions to
1521 * insert filters for their own MAC address unless explicitly given
1522 * additional privileges by the user. This also means that, even on a
1523 * priviliged function, inserting a unicast mismatch filter may not
1524 * catch all traffic in multi PCI function scenarios.)
1526 table->eft_unicst_filter_count = 0;
1527 rc = ef10_filter_insert_unicast(enp, mac_addr, filter_flags);
1528 if (all_unicst || (rc != 0)) {
1529 all_unicst_rc = ef10_filter_insert_all_unicast(enp,
1531 if ((rc != 0) && (all_unicst_rc != 0))
1536 * WORKAROUND_BUG26807 controls firmware support for chained multicast
1537 * filters, and can only be enabled or disabled when the hardware filter
1540 * Chained multicast filters require support from the datapath firmware,
1541 * and may not be available (e.g. low-latency variants or old Huntington
1544 * Firmware will reset (FLR) functions which have inserted filters in
1545 * the hardware filter table when the workaround is enabled/disabled.
1546 * Functions without any hardware filters are not reset.
1548 * Re-check if the workaround is enabled after adding unicast hardware
1549 * filters. This ensures that encp->enc_bug26807_workaround matches the
1550 * firmware state, and that later changes to enable/disable the
1551 * workaround will result in this function seeing a reset (FLR).
1553 * In common-code drivers, we only support multiple PCI function
1554 * scenarios with firmware that supports multicast chaining, so we can
1555 * assume it is enabled for such cases and hence simplify the filter
1556 * insertion logic. Firmware that does not support multicast chaining
1557 * does not support multiple PCI function configurations either, so
1558 * filter insertion is much simpler and the same strategies can still be
1561 if ((rc = ef10_filter_get_workarounds(enp)) != 0)
1564 if ((table->eft_using_all_mulcst != all_mulcst) &&
1565 (encp->enc_bug26807_workaround == B_TRUE)) {
1567 * Multicast filter chaining is enabled, so traffic that matches
1568 * more than one multicast filter will be replicated and
1569 * delivered to multiple recipients. To avoid this duplicate
1570 * delivery, remove old multicast filters before inserting new
1571 * multicast filters.
1573 ef10_filter_remove_old(enp);
1576 /* Insert or renew multicast filters */
1577 if (all_mulcst == B_TRUE) {
1579 * Insert the all multicast filter. If that fails, try to insert
1580 * all of our multicast filters (but without rollback on
1583 all_mulcst_rc = ef10_filter_insert_all_multicast(enp,
1585 if (all_mulcst_rc != 0) {
1586 rc = ef10_filter_insert_multicast_list(enp, B_TRUE,
1587 brdcst, addrs, count, filter_flags, B_FALSE);
1593 * Insert filters for multicast addresses.
1594 * If any insertion fails, then rollback and try to insert the
1595 * all multicast filter instead.
1596 * If that also fails, try to insert all of the multicast
1597 * filters (but without rollback on failure).
1599 rc = ef10_filter_insert_multicast_list(enp, mulcst, brdcst,
1600 addrs, count, filter_flags, B_TRUE);
1602 if ((table->eft_using_all_mulcst == B_FALSE) &&
1603 (encp->enc_bug26807_workaround == B_TRUE)) {
1605 * Multicast filter chaining is on, so remove
1606 * old filters before inserting the multicast
1607 * all filter to avoid duplicate delivery caused
1608 * by packets matching multiple filters.
1610 ef10_filter_remove_old(enp);
1613 rc = ef10_filter_insert_all_multicast(enp,
1616 rc = ef10_filter_insert_multicast_list(enp,
1618 addrs, count, filter_flags, B_FALSE);
1625 if (encp->enc_tunnel_encapsulations_supported != 0) {
1626 /* Try to insert filters for encapsulated packets. */
1627 (void) ef10_filter_insert_encap_filters(enp,
1628 mulcst || all_mulcst || brdcst,
1632 /* Remove old filters which were not renewed */
1633 ef10_filter_remove_old(enp);
1635 /* report if any optional flags were rejected */
1636 if (((all_unicst != B_FALSE) && (all_unicst_rc != 0)) ||
1637 ((all_mulcst != B_FALSE) && (all_mulcst_rc != 0))) {
1650 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1652 /* Clear auto old flags */
1653 for (i = 0; i < EFX_ARRAY_SIZE(table->eft_entry); i++) {
1654 if (ef10_filter_entry_is_auto_old(table, i)) {
1655 ef10_filter_set_entry_not_auto_old(table, i);
1663 ef10_filter_get_default_rxq(
1664 __in efx_nic_t *enp,
1665 __out efx_rxq_t **erpp,
1666 __out boolean_t *using_rss)
1668 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
1670 *erpp = table->eft_default_rxq;
1671 *using_rss = table->eft_using_rss;
1676 ef10_filter_default_rxq_set(
1677 __in efx_nic_t *enp,
1678 __in efx_rxq_t *erp,
1679 __in boolean_t using_rss)
1681 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
1683 #if EFSYS_OPT_RX_SCALE
1684 EFSYS_ASSERT((using_rss == B_FALSE) ||
1685 (enp->en_rss_context != EF10_RSS_CONTEXT_INVALID));
1686 table->eft_using_rss = using_rss;
1688 EFSYS_ASSERT(using_rss == B_FALSE);
1689 table->eft_using_rss = B_FALSE;
1691 table->eft_default_rxq = erp;
1695 ef10_filter_default_rxq_clear(
1696 __in efx_nic_t *enp)
1698 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
1700 table->eft_default_rxq = NULL;
1701 table->eft_using_rss = B_FALSE;
1705 #endif /* EFSYS_OPT_FILTER */
1707 #endif /* EFSYS_OPT_HUNTINGTON || EFSYS_OPT_MEDFORD || EFSYS_OPT_MEDFORD2 */