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)];
177 efx_filter_match_flags_t match_flags;
180 memset(payload, 0, sizeof (payload));
181 req.emr_cmd = MC_CMD_FILTER_OP;
182 req.emr_in_buf = payload;
183 req.emr_in_length = MC_CMD_FILTER_OP_EXT_IN_LEN;
184 req.emr_out_buf = payload;
185 req.emr_out_length = MC_CMD_FILTER_OP_EXT_OUT_LEN;
188 * Remove match flag for encapsulated filters that does not correspond
189 * to the MCDI match flags
191 match_flags = spec->efs_match_flags & ~EFX_FILTER_MATCH_ENCAP_TYPE;
194 case MC_CMD_FILTER_OP_IN_OP_REPLACE:
195 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_HANDLE_LO,
197 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_HANDLE_HI,
200 case MC_CMD_FILTER_OP_IN_OP_INSERT:
201 case MC_CMD_FILTER_OP_IN_OP_SUBSCRIBE:
202 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_OP, filter_op);
210 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_PORT_ID,
211 EVB_PORT_ID_ASSIGNED);
212 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_MATCH_FIELDS,
214 if (spec->efs_dmaq_id == EFX_FILTER_SPEC_RX_DMAQ_ID_DROP) {
215 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_RX_DEST,
216 MC_CMD_FILTER_OP_EXT_IN_RX_DEST_DROP);
218 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_RX_DEST,
219 MC_CMD_FILTER_OP_EXT_IN_RX_DEST_HOST);
220 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_RX_QUEUE,
224 #if EFSYS_OPT_RX_SCALE
225 if (spec->efs_flags & EFX_FILTER_FLAG_RX_RSS) {
226 uint32_t rss_context;
228 if (spec->efs_rss_context == EFX_RSS_CONTEXT_DEFAULT)
229 rss_context = enp->en_rss_context;
231 rss_context = spec->efs_rss_context;
232 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_RX_CONTEXT,
237 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_RX_MODE,
238 spec->efs_flags & EFX_FILTER_FLAG_RX_RSS ?
239 MC_CMD_FILTER_OP_EXT_IN_RX_MODE_RSS :
240 MC_CMD_FILTER_OP_EXT_IN_RX_MODE_SIMPLE);
241 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_TX_DEST,
242 MC_CMD_FILTER_OP_EXT_IN_TX_DEST_DEFAULT);
244 if (filter_op != MC_CMD_FILTER_OP_IN_OP_REPLACE) {
246 * NOTE: Unlike most MCDI requests, the filter fields
247 * are presented in network (big endian) byte order.
249 memcpy(MCDI_IN2(req, uint8_t, FILTER_OP_EXT_IN_SRC_MAC),
250 spec->efs_rem_mac, EFX_MAC_ADDR_LEN);
251 memcpy(MCDI_IN2(req, uint8_t, FILTER_OP_EXT_IN_DST_MAC),
252 spec->efs_loc_mac, EFX_MAC_ADDR_LEN);
254 MCDI_IN_SET_WORD(req, FILTER_OP_EXT_IN_SRC_PORT,
255 __CPU_TO_BE_16(spec->efs_rem_port));
256 MCDI_IN_SET_WORD(req, FILTER_OP_EXT_IN_DST_PORT,
257 __CPU_TO_BE_16(spec->efs_loc_port));
259 MCDI_IN_SET_WORD(req, FILTER_OP_EXT_IN_ETHER_TYPE,
260 __CPU_TO_BE_16(spec->efs_ether_type));
262 MCDI_IN_SET_WORD(req, FILTER_OP_EXT_IN_INNER_VLAN,
263 __CPU_TO_BE_16(spec->efs_inner_vid));
264 MCDI_IN_SET_WORD(req, FILTER_OP_EXT_IN_OUTER_VLAN,
265 __CPU_TO_BE_16(spec->efs_outer_vid));
267 /* IP protocol (in low byte, high byte is zero) */
268 MCDI_IN_SET_BYTE(req, FILTER_OP_EXT_IN_IP_PROTO,
271 EFX_STATIC_ASSERT(sizeof (spec->efs_rem_host) ==
272 MC_CMD_FILTER_OP_EXT_IN_SRC_IP_LEN);
273 EFX_STATIC_ASSERT(sizeof (spec->efs_loc_host) ==
274 MC_CMD_FILTER_OP_EXT_IN_DST_IP_LEN);
276 memcpy(MCDI_IN2(req, uint8_t, FILTER_OP_EXT_IN_SRC_IP),
277 &spec->efs_rem_host.eo_byte[0],
278 MC_CMD_FILTER_OP_EXT_IN_SRC_IP_LEN);
279 memcpy(MCDI_IN2(req, uint8_t, FILTER_OP_EXT_IN_DST_IP),
280 &spec->efs_loc_host.eo_byte[0],
281 MC_CMD_FILTER_OP_EXT_IN_DST_IP_LEN);
284 * On Medford, filters for encapsulated packets match based on
285 * the ether type and IP protocol in the outer frame. In
286 * addition we need to fill in the VNI or VSID type field.
288 switch (spec->efs_encap_type) {
289 case EFX_TUNNEL_PROTOCOL_NONE:
291 case EFX_TUNNEL_PROTOCOL_VXLAN:
292 case EFX_TUNNEL_PROTOCOL_GENEVE:
293 MCDI_IN_POPULATE_DWORD_1(req,
294 FILTER_OP_EXT_IN_VNI_OR_VSID,
295 FILTER_OP_EXT_IN_VNI_TYPE,
296 spec->efs_encap_type == EFX_TUNNEL_PROTOCOL_VXLAN ?
297 MC_CMD_FILTER_OP_EXT_IN_VNI_TYPE_VXLAN :
298 MC_CMD_FILTER_OP_EXT_IN_VNI_TYPE_GENEVE);
300 case EFX_TUNNEL_PROTOCOL_NVGRE:
301 MCDI_IN_POPULATE_DWORD_1(req,
302 FILTER_OP_EXT_IN_VNI_OR_VSID,
303 FILTER_OP_EXT_IN_VSID_TYPE,
304 MC_CMD_FILTER_OP_EXT_IN_VSID_TYPE_NVGRE);
312 memcpy(MCDI_IN2(req, uint8_t, FILTER_OP_EXT_IN_VNI_OR_VSID),
313 spec->efs_vni_or_vsid, EFX_VNI_OR_VSID_LEN);
315 memcpy(MCDI_IN2(req, uint8_t, FILTER_OP_EXT_IN_IFRM_DST_MAC),
316 spec->efs_ifrm_loc_mac, EFX_MAC_ADDR_LEN);
319 efx_mcdi_execute(enp, &req);
321 if (req.emr_rc != 0) {
326 if (req.emr_out_length_used < MC_CMD_FILTER_OP_EXT_OUT_LEN) {
331 handle->efh_lo = MCDI_OUT_DWORD(req, FILTER_OP_EXT_OUT_HANDLE_LO);
332 handle->efh_hi = MCDI_OUT_DWORD(req, FILTER_OP_EXT_OUT_HANDLE_HI);
343 EFSYS_PROBE1(fail1, efx_rc_t, rc);
349 static __checkReturn efx_rc_t
350 efx_mcdi_filter_op_delete(
352 __in unsigned int filter_op,
353 __inout ef10_filter_handle_t *handle)
356 uint8_t payload[MAX(MC_CMD_FILTER_OP_EXT_IN_LEN,
357 MC_CMD_FILTER_OP_EXT_OUT_LEN)];
360 memset(payload, 0, sizeof (payload));
361 req.emr_cmd = MC_CMD_FILTER_OP;
362 req.emr_in_buf = payload;
363 req.emr_in_length = MC_CMD_FILTER_OP_EXT_IN_LEN;
364 req.emr_out_buf = payload;
365 req.emr_out_length = MC_CMD_FILTER_OP_EXT_OUT_LEN;
368 case MC_CMD_FILTER_OP_IN_OP_REMOVE:
369 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_OP,
370 MC_CMD_FILTER_OP_IN_OP_REMOVE);
372 case MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE:
373 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_OP,
374 MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE);
382 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_HANDLE_LO, handle->efh_lo);
383 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_HANDLE_HI, handle->efh_hi);
385 efx_mcdi_execute_quiet(enp, &req);
387 if (req.emr_rc != 0) {
392 if (req.emr_out_length_used < MC_CMD_FILTER_OP_EXT_OUT_LEN) {
405 EFSYS_PROBE1(fail1, efx_rc_t, rc);
410 static __checkReturn boolean_t
412 __in const efx_filter_spec_t *left,
413 __in const efx_filter_spec_t *right)
415 /* FIXME: Consider rx vs tx filters (look at efs_flags) */
416 if (left->efs_match_flags != right->efs_match_flags)
418 if (!EFX_OWORD_IS_EQUAL(left->efs_rem_host, right->efs_rem_host))
420 if (!EFX_OWORD_IS_EQUAL(left->efs_loc_host, right->efs_loc_host))
422 if (memcmp(left->efs_rem_mac, right->efs_rem_mac, EFX_MAC_ADDR_LEN))
424 if (memcmp(left->efs_loc_mac, right->efs_loc_mac, EFX_MAC_ADDR_LEN))
426 if (left->efs_rem_port != right->efs_rem_port)
428 if (left->efs_loc_port != right->efs_loc_port)
430 if (left->efs_inner_vid != right->efs_inner_vid)
432 if (left->efs_outer_vid != right->efs_outer_vid)
434 if (left->efs_ether_type != right->efs_ether_type)
436 if (left->efs_ip_proto != right->efs_ip_proto)
438 if (left->efs_encap_type != right->efs_encap_type)
440 if (memcmp(left->efs_vni_or_vsid, right->efs_vni_or_vsid,
441 EFX_VNI_OR_VSID_LEN))
443 if (memcmp(left->efs_ifrm_loc_mac, right->efs_ifrm_loc_mac,
451 static __checkReturn boolean_t
452 ef10_filter_same_dest(
453 __in const efx_filter_spec_t *left,
454 __in const efx_filter_spec_t *right)
456 if ((left->efs_flags & EFX_FILTER_FLAG_RX_RSS) &&
457 (right->efs_flags & EFX_FILTER_FLAG_RX_RSS)) {
458 if (left->efs_rss_context == right->efs_rss_context)
460 } else if ((~(left->efs_flags) & EFX_FILTER_FLAG_RX_RSS) &&
461 (~(right->efs_flags) & EFX_FILTER_FLAG_RX_RSS)) {
462 if (left->efs_dmaq_id == right->efs_dmaq_id)
468 static __checkReturn uint32_t
470 __in efx_filter_spec_t *spec)
472 EFX_STATIC_ASSERT((sizeof (efx_filter_spec_t) % sizeof (uint32_t))
474 EFX_STATIC_ASSERT((EFX_FIELD_OFFSET(efx_filter_spec_t, efs_outer_vid) %
475 sizeof (uint32_t)) == 0);
478 * As the area of the efx_filter_spec_t we need to hash is DWORD
479 * aligned and an exact number of DWORDs in size we can use the
480 * optimised efx_hash_dwords() rather than efx_hash_bytes()
482 return (efx_hash_dwords((const uint32_t *)&spec->efs_outer_vid,
483 (sizeof (efx_filter_spec_t) -
484 EFX_FIELD_OFFSET(efx_filter_spec_t, efs_outer_vid)) /
485 sizeof (uint32_t), 0));
489 * Decide whether a filter should be exclusive or else should allow
490 * delivery to additional recipients. Currently we decide that
491 * filters for specific local unicast MAC and IP addresses are
494 static __checkReturn boolean_t
495 ef10_filter_is_exclusive(
496 __in efx_filter_spec_t *spec)
498 if ((spec->efs_match_flags & EFX_FILTER_MATCH_LOC_MAC) &&
499 !EFX_MAC_ADDR_IS_MULTICAST(spec->efs_loc_mac))
502 if ((spec->efs_match_flags &
503 (EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_LOC_HOST)) ==
504 (EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_LOC_HOST)) {
505 if ((spec->efs_ether_type == EFX_ETHER_TYPE_IPV4) &&
506 ((spec->efs_loc_host.eo_u8[0] & 0xf) != 0xe))
508 if ((spec->efs_ether_type == EFX_ETHER_TYPE_IPV6) &&
509 (spec->efs_loc_host.eo_u8[0] != 0xff))
516 __checkReturn efx_rc_t
521 efx_filter_spec_t *spec;
522 ef10_filter_table_t *eftp = enp->en_filter.ef_ef10_filter_table;
524 efsys_lock_state_t state;
527 EFSYS_ASSERT(enp->en_family == EFX_FAMILY_HUNTINGTON ||
528 enp->en_family == EFX_FAMILY_MEDFORD ||
529 enp->en_family == EFX_FAMILY_MEDFORD2);
531 for (tbl_id = 0; tbl_id < EFX_EF10_FILTER_TBL_ROWS; tbl_id++) {
533 EFSYS_LOCK(enp->en_eslp, state);
535 spec = ef10_filter_entry_spec(eftp, tbl_id);
538 } else if (ef10_filter_entry_is_busy(eftp, tbl_id)) {
539 /* Ignore busy entries. */
542 ef10_filter_set_entry_busy(eftp, tbl_id);
546 EFSYS_UNLOCK(enp->en_eslp, state);
548 if (restoring == B_FALSE)
551 if (ef10_filter_is_exclusive(spec)) {
552 rc = efx_mcdi_filter_op_add(enp, spec,
553 MC_CMD_FILTER_OP_IN_OP_INSERT,
554 &eftp->eft_entry[tbl_id].efe_handle);
556 rc = efx_mcdi_filter_op_add(enp, spec,
557 MC_CMD_FILTER_OP_IN_OP_SUBSCRIBE,
558 &eftp->eft_entry[tbl_id].efe_handle);
564 EFSYS_LOCK(enp->en_eslp, state);
566 ef10_filter_set_entry_not_busy(eftp, tbl_id);
568 EFSYS_UNLOCK(enp->en_eslp, state);
574 EFSYS_PROBE1(fail1, efx_rc_t, rc);
580 * An arbitrary search limit for the software hash table. As per the linux net
583 #define EF10_FILTER_SEARCH_LIMIT 200
585 static __checkReturn efx_rc_t
586 ef10_filter_add_internal(
588 __inout efx_filter_spec_t *spec,
589 __in boolean_t may_replace,
590 __out_opt uint32_t *filter_id)
593 ef10_filter_table_t *eftp = enp->en_filter.ef_ef10_filter_table;
594 efx_filter_spec_t *saved_spec;
598 boolean_t replacing = B_FALSE;
600 efsys_lock_state_t state;
601 boolean_t locked = B_FALSE;
603 EFSYS_ASSERT(enp->en_family == EFX_FAMILY_HUNTINGTON ||
604 enp->en_family == EFX_FAMILY_MEDFORD ||
605 enp->en_family == EFX_FAMILY_MEDFORD2);
607 hash = ef10_filter_hash(spec);
610 * FIXME: Add support for inserting filters of different priorities
611 * and removing lower priority multicast filters (bug 42378)
615 * Find any existing filters with the same match tuple or
616 * else a free slot to insert at. If any of them are busy,
617 * we have to wait and retry.
622 EFSYS_LOCK(enp->en_eslp, state);
626 i = (hash + depth) & (EFX_EF10_FILTER_TBL_ROWS - 1);
627 saved_spec = ef10_filter_entry_spec(eftp, i);
633 } else if (ef10_filter_equal(spec, saved_spec)) {
634 if (ef10_filter_entry_is_busy(eftp, i))
636 if (saved_spec->efs_priority
637 == EFX_FILTER_PRI_AUTO) {
640 } else if (ef10_filter_is_exclusive(spec)) {
654 * Once we reach the maximum search depth, use
655 * the first suitable slot or return EBUSY if
658 if (depth == EF10_FILTER_SEARCH_LIMIT) {
667 EFSYS_UNLOCK(enp->en_eslp, state);
673 * Create a software table entry if necessary, and mark it
674 * busy. We might yet fail to insert, but any attempt to
675 * insert a conflicting filter while we're waiting for the
676 * firmware must find the busy entry.
678 saved_spec = ef10_filter_entry_spec(eftp, ins_index);
680 if (saved_spec->efs_priority == EFX_FILTER_PRI_AUTO) {
681 /* This is a filter we are refreshing */
682 ef10_filter_set_entry_not_auto_old(eftp, ins_index);
688 EFSYS_KMEM_ALLOC(enp->en_esip, sizeof (*spec), saved_spec);
694 ef10_filter_set_entry(eftp, ins_index, saved_spec);
696 ef10_filter_set_entry_busy(eftp, ins_index);
698 EFSYS_UNLOCK(enp->en_eslp, state);
702 * On replacing the filter handle may change after after a successful
706 rc = efx_mcdi_filter_op_add(enp, spec,
707 MC_CMD_FILTER_OP_IN_OP_REPLACE,
708 &eftp->eft_entry[ins_index].efe_handle);
709 } else if (ef10_filter_is_exclusive(spec)) {
710 rc = efx_mcdi_filter_op_add(enp, spec,
711 MC_CMD_FILTER_OP_IN_OP_INSERT,
712 &eftp->eft_entry[ins_index].efe_handle);
714 rc = efx_mcdi_filter_op_add(enp, spec,
715 MC_CMD_FILTER_OP_IN_OP_SUBSCRIBE,
716 &eftp->eft_entry[ins_index].efe_handle);
722 EFSYS_LOCK(enp->en_eslp, state);
726 /* Update the fields that may differ */
727 saved_spec->efs_priority = spec->efs_priority;
728 saved_spec->efs_flags = spec->efs_flags;
729 saved_spec->efs_rss_context = spec->efs_rss_context;
730 saved_spec->efs_dmaq_id = spec->efs_dmaq_id;
733 ef10_filter_set_entry_not_busy(eftp, ins_index);
737 EFSYS_UNLOCK(enp->en_eslp, state);
741 *filter_id = ins_index;
749 EFSYS_KMEM_FREE(enp->en_esip, sizeof (*spec), saved_spec);
752 ef10_filter_set_entry_not_busy(eftp, ins_index);
753 ef10_filter_set_entry(eftp, ins_index, NULL);
762 EFSYS_PROBE1(fail1, efx_rc_t, rc);
765 EFSYS_UNLOCK(enp->en_eslp, state);
770 __checkReturn efx_rc_t
773 __inout efx_filter_spec_t *spec,
774 __in boolean_t may_replace)
778 rc = ef10_filter_add_internal(enp, spec, may_replace, NULL);
785 EFSYS_PROBE1(fail1, efx_rc_t, rc);
791 static __checkReturn efx_rc_t
792 ef10_filter_delete_internal(
794 __in uint32_t filter_id)
797 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
798 efx_filter_spec_t *spec;
799 efsys_lock_state_t state;
800 uint32_t filter_idx = filter_id % EFX_EF10_FILTER_TBL_ROWS;
803 * Find the software table entry and mark it busy. Don't
804 * remove it yet; any attempt to update while we're waiting
805 * for the firmware must find the busy entry.
807 * FIXME: What if the busy flag is never cleared?
809 EFSYS_LOCK(enp->en_eslp, state);
810 while (ef10_filter_entry_is_busy(table, filter_idx)) {
811 EFSYS_UNLOCK(enp->en_eslp, state);
813 EFSYS_LOCK(enp->en_eslp, state);
815 if ((spec = ef10_filter_entry_spec(table, filter_idx)) != NULL) {
816 ef10_filter_set_entry_busy(table, filter_idx);
818 EFSYS_UNLOCK(enp->en_eslp, state);
826 * Try to remove the hardware filter. This may fail if the MC has
827 * rebooted (which frees all hardware filter resources).
829 if (ef10_filter_is_exclusive(spec)) {
830 rc = efx_mcdi_filter_op_delete(enp,
831 MC_CMD_FILTER_OP_IN_OP_REMOVE,
832 &table->eft_entry[filter_idx].efe_handle);
834 rc = efx_mcdi_filter_op_delete(enp,
835 MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE,
836 &table->eft_entry[filter_idx].efe_handle);
839 /* Free the software table entry */
840 EFSYS_LOCK(enp->en_eslp, state);
841 ef10_filter_set_entry_not_busy(table, filter_idx);
842 ef10_filter_set_entry(table, filter_idx, NULL);
843 EFSYS_UNLOCK(enp->en_eslp, state);
845 EFSYS_KMEM_FREE(enp->en_esip, sizeof (*spec), spec);
847 /* Check result of hardware filter removal */
857 EFSYS_PROBE1(fail1, efx_rc_t, rc);
862 __checkReturn efx_rc_t
865 __inout efx_filter_spec_t *spec)
868 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
869 efx_filter_spec_t *saved_spec;
873 efsys_lock_state_t state;
874 boolean_t locked = B_FALSE;
876 EFSYS_ASSERT(enp->en_family == EFX_FAMILY_HUNTINGTON ||
877 enp->en_family == EFX_FAMILY_MEDFORD ||
878 enp->en_family == EFX_FAMILY_MEDFORD2);
880 hash = ef10_filter_hash(spec);
882 EFSYS_LOCK(enp->en_eslp, state);
887 i = (hash + depth) & (EFX_EF10_FILTER_TBL_ROWS - 1);
888 saved_spec = ef10_filter_entry_spec(table, i);
889 if (saved_spec && ef10_filter_equal(spec, saved_spec) &&
890 ef10_filter_same_dest(spec, saved_spec)) {
893 if (depth == EF10_FILTER_SEARCH_LIMIT) {
900 EFSYS_UNLOCK(enp->en_eslp, state);
903 rc = ef10_filter_delete_internal(enp, i);
913 EFSYS_PROBE1(fail1, efx_rc_t, rc);
916 EFSYS_UNLOCK(enp->en_eslp, state);
921 static __checkReturn efx_rc_t
922 efx_mcdi_get_parser_disp_info(
924 __out_ecount(buffer_length) uint32_t *buffer,
925 __in size_t buffer_length,
926 __in boolean_t encap,
927 __out size_t *list_lengthp)
930 uint8_t payload[MAX(MC_CMD_GET_PARSER_DISP_INFO_IN_LEN,
931 MC_CMD_GET_PARSER_DISP_INFO_OUT_LENMAX)];
932 size_t matches_count;
936 (void) memset(payload, 0, sizeof (payload));
937 req.emr_cmd = MC_CMD_GET_PARSER_DISP_INFO;
938 req.emr_in_buf = payload;
939 req.emr_in_length = MC_CMD_GET_PARSER_DISP_INFO_IN_LEN;
940 req.emr_out_buf = payload;
941 req.emr_out_length = MC_CMD_GET_PARSER_DISP_INFO_OUT_LENMAX;
943 MCDI_IN_SET_DWORD(req, GET_PARSER_DISP_INFO_OUT_OP, encap ?
944 MC_CMD_GET_PARSER_DISP_INFO_IN_OP_GET_SUPPORTED_ENCAP_RX_MATCHES :
945 MC_CMD_GET_PARSER_DISP_INFO_IN_OP_GET_SUPPORTED_RX_MATCHES);
947 efx_mcdi_execute(enp, &req);
949 if (req.emr_rc != 0) {
954 matches_count = MCDI_OUT_DWORD(req,
955 GET_PARSER_DISP_INFO_OUT_NUM_SUPPORTED_MATCHES);
957 if (req.emr_out_length_used <
958 MC_CMD_GET_PARSER_DISP_INFO_OUT_LEN(matches_count)) {
963 *list_lengthp = matches_count;
965 if (buffer_length < matches_count) {
971 * Check that the elements in the list in the MCDI response are the size
972 * we expect, so we can just copy them directly. Any conversion of the
973 * flags is handled by the caller.
975 EFX_STATIC_ASSERT(sizeof (uint32_t) ==
976 MC_CMD_GET_PARSER_DISP_INFO_OUT_SUPPORTED_MATCHES_LEN);
978 list_size = matches_count *
979 MC_CMD_GET_PARSER_DISP_INFO_OUT_SUPPORTED_MATCHES_LEN;
981 MCDI_OUT2(req, uint32_t,
982 GET_PARSER_DISP_INFO_OUT_SUPPORTED_MATCHES),
992 EFSYS_PROBE1(fail1, efx_rc_t, rc);
997 __checkReturn efx_rc_t
998 ef10_filter_supported_filters(
1000 __out_ecount(buffer_length) uint32_t *buffer,
1001 __in size_t buffer_length,
1002 __out size_t *list_lengthp)
1004 efx_nic_cfg_t *encp = &(enp->en_nic_cfg);
1005 size_t mcdi_list_length;
1006 size_t mcdi_encap_list_length;
1009 uint32_t next_buf_idx;
1010 size_t next_buf_length;
1012 boolean_t no_space = B_FALSE;
1013 efx_filter_match_flags_t all_filter_flags =
1014 (EFX_FILTER_MATCH_REM_HOST | EFX_FILTER_MATCH_LOC_HOST |
1015 EFX_FILTER_MATCH_REM_MAC | EFX_FILTER_MATCH_REM_PORT |
1016 EFX_FILTER_MATCH_LOC_MAC | EFX_FILTER_MATCH_LOC_PORT |
1017 EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_INNER_VID |
1018 EFX_FILTER_MATCH_OUTER_VID | EFX_FILTER_MATCH_IP_PROTO |
1019 EFX_FILTER_MATCH_VNI_OR_VSID |
1020 EFX_FILTER_MATCH_IFRM_LOC_MAC |
1021 EFX_FILTER_MATCH_IFRM_UNKNOWN_MCAST_DST |
1022 EFX_FILTER_MATCH_IFRM_UNKNOWN_UCAST_DST |
1023 EFX_FILTER_MATCH_ENCAP_TYPE |
1024 EFX_FILTER_MATCH_UNKNOWN_MCAST_DST |
1025 EFX_FILTER_MATCH_UNKNOWN_UCAST_DST);
1028 * Two calls to MC_CMD_GET_PARSER_DISP_INFO are needed: one to get the
1029 * list of supported filters for ordinary packets, and then another to
1030 * get the list of supported filters for encapsulated packets. To
1031 * distinguish the second list from the first, the
1032 * EFX_FILTER_MATCH_ENCAP_TYPE flag is added to each filter for
1033 * encapsulated packets.
1035 rc = efx_mcdi_get_parser_disp_info(enp, buffer, buffer_length, B_FALSE,
1046 next_buf_length = 0;
1048 EFSYS_ASSERT(mcdi_list_length <= buffer_length);
1049 next_buf_idx = mcdi_list_length;
1050 next_buf_length = buffer_length - mcdi_list_length;
1053 if (encp->enc_tunnel_encapsulations_supported != 0) {
1054 rc = efx_mcdi_get_parser_disp_info(enp, &buffer[next_buf_idx],
1055 next_buf_length, B_TRUE, &mcdi_encap_list_length);
1062 for (i = next_buf_idx;
1063 i < next_buf_idx + mcdi_encap_list_length; i++)
1064 buffer[i] |= EFX_FILTER_MATCH_ENCAP_TYPE;
1067 mcdi_encap_list_length = 0;
1071 *list_lengthp = mcdi_list_length + mcdi_encap_list_length;
1077 * The static assertions in ef10_filter_init() ensure that the values of
1078 * the EFX_FILTER_MATCH flags match those used by MCDI, so they don't
1079 * need to be converted.
1081 * In case support is added to MCDI for additional flags, remove any
1082 * matches from the list which include flags we don't support. The order
1083 * of the matches is preserved as they are ordered from highest to
1086 EFSYS_ASSERT(mcdi_list_length + mcdi_encap_list_length <=
1089 for (i = 0; i < mcdi_list_length + mcdi_encap_list_length; i++) {
1090 if ((buffer[i] & ~all_filter_flags) == 0) {
1091 buffer[list_length] = buffer[i];
1096 *list_lengthp = list_length;
1105 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1110 static __checkReturn efx_rc_t
1111 ef10_filter_insert_unicast(
1112 __in efx_nic_t *enp,
1113 __in_ecount(6) uint8_t const *addr,
1114 __in efx_filter_flags_t filter_flags)
1116 ef10_filter_table_t *eftp = enp->en_filter.ef_ef10_filter_table;
1117 efx_filter_spec_t spec;
1120 /* Insert the filter for the local station address */
1121 efx_filter_spec_init_rx(&spec, EFX_FILTER_PRI_AUTO,
1123 eftp->eft_default_rxq);
1124 efx_filter_spec_set_eth_local(&spec, EFX_FILTER_SPEC_VID_UNSPEC, addr);
1126 rc = ef10_filter_add_internal(enp, &spec, B_TRUE,
1127 &eftp->eft_unicst_filter_indexes[eftp->eft_unicst_filter_count]);
1131 eftp->eft_unicst_filter_count++;
1132 EFSYS_ASSERT(eftp->eft_unicst_filter_count <=
1133 EFX_EF10_FILTER_UNICAST_FILTERS_MAX);
1138 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1142 static __checkReturn efx_rc_t
1143 ef10_filter_insert_all_unicast(
1144 __in efx_nic_t *enp,
1145 __in efx_filter_flags_t filter_flags)
1147 ef10_filter_table_t *eftp = enp->en_filter.ef_ef10_filter_table;
1148 efx_filter_spec_t spec;
1151 /* Insert the unknown unicast filter */
1152 efx_filter_spec_init_rx(&spec, EFX_FILTER_PRI_AUTO,
1154 eftp->eft_default_rxq);
1155 efx_filter_spec_set_uc_def(&spec);
1156 rc = ef10_filter_add_internal(enp, &spec, B_TRUE,
1157 &eftp->eft_unicst_filter_indexes[eftp->eft_unicst_filter_count]);
1161 eftp->eft_unicst_filter_count++;
1162 EFSYS_ASSERT(eftp->eft_unicst_filter_count <=
1163 EFX_EF10_FILTER_UNICAST_FILTERS_MAX);
1168 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1172 static __checkReturn efx_rc_t
1173 ef10_filter_insert_multicast_list(
1174 __in efx_nic_t *enp,
1175 __in boolean_t mulcst,
1176 __in boolean_t brdcst,
1177 __in_ecount(6*count) uint8_t const *addrs,
1178 __in uint32_t count,
1179 __in efx_filter_flags_t filter_flags,
1180 __in boolean_t rollback)
1182 ef10_filter_table_t *eftp = enp->en_filter.ef_ef10_filter_table;
1183 efx_filter_spec_t spec;
1186 uint32_t filter_index;
1187 uint32_t filter_count;
1190 if (mulcst == B_FALSE)
1193 if (count + (brdcst ? 1 : 0) >
1194 EFX_ARRAY_SIZE(eftp->eft_mulcst_filter_indexes)) {
1195 /* Too many MAC addresses */
1200 /* Insert/renew multicast address list filters */
1202 for (i = 0; i < count; i++) {
1203 efx_filter_spec_init_rx(&spec,
1204 EFX_FILTER_PRI_AUTO,
1206 eftp->eft_default_rxq);
1208 efx_filter_spec_set_eth_local(&spec,
1209 EFX_FILTER_SPEC_VID_UNSPEC,
1210 &addrs[i * EFX_MAC_ADDR_LEN]);
1212 rc = ef10_filter_add_internal(enp, &spec, B_TRUE,
1216 eftp->eft_mulcst_filter_indexes[filter_count] =
1219 } else if (rollback == B_TRUE) {
1220 /* Only stop upon failure if told to rollback */
1226 if (brdcst == B_TRUE) {
1227 /* Insert/renew broadcast address filter */
1228 efx_filter_spec_init_rx(&spec, EFX_FILTER_PRI_AUTO,
1230 eftp->eft_default_rxq);
1232 EFX_MAC_BROADCAST_ADDR_SET(addr);
1233 efx_filter_spec_set_eth_local(&spec, EFX_FILTER_SPEC_VID_UNSPEC,
1236 rc = ef10_filter_add_internal(enp, &spec, B_TRUE,
1240 eftp->eft_mulcst_filter_indexes[filter_count] =
1243 } else if (rollback == B_TRUE) {
1244 /* Only stop upon failure if told to rollback */
1249 eftp->eft_mulcst_filter_count = filter_count;
1250 eftp->eft_using_all_mulcst = B_FALSE;
1255 /* Remove any filters we have inserted */
1258 (void) ef10_filter_delete_internal(enp,
1259 eftp->eft_mulcst_filter_indexes[i]);
1261 eftp->eft_mulcst_filter_count = 0;
1264 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1269 static __checkReturn efx_rc_t
1270 ef10_filter_insert_all_multicast(
1271 __in efx_nic_t *enp,
1272 __in efx_filter_flags_t filter_flags)
1274 ef10_filter_table_t *eftp = enp->en_filter.ef_ef10_filter_table;
1275 efx_filter_spec_t spec;
1278 /* Insert the unknown multicast filter */
1279 efx_filter_spec_init_rx(&spec, EFX_FILTER_PRI_AUTO,
1281 eftp->eft_default_rxq);
1282 efx_filter_spec_set_mc_def(&spec);
1284 rc = ef10_filter_add_internal(enp, &spec, B_TRUE,
1285 &eftp->eft_mulcst_filter_indexes[0]);
1289 eftp->eft_mulcst_filter_count = 1;
1290 eftp->eft_using_all_mulcst = B_TRUE;
1293 * FIXME: If brdcst == B_FALSE, add a filter to drop broadcast traffic.
1299 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1304 typedef struct ef10_filter_encap_entry_s {
1305 uint16_t ether_type;
1306 efx_tunnel_protocol_t encap_type;
1307 uint32_t inner_frame_match;
1308 } ef10_filter_encap_entry_t;
1310 #define EF10_ENCAP_FILTER_ENTRY(ipv, encap_type, inner_frame_match) \
1311 { EFX_ETHER_TYPE_##ipv, EFX_TUNNEL_PROTOCOL_##encap_type, \
1312 EFX_FILTER_INNER_FRAME_MATCH_UNKNOWN_##inner_frame_match }
1314 static ef10_filter_encap_entry_t ef10_filter_encap_list[] = {
1315 EF10_ENCAP_FILTER_ENTRY(IPV4, VXLAN, UCAST_DST),
1316 EF10_ENCAP_FILTER_ENTRY(IPV4, VXLAN, MCAST_DST),
1317 EF10_ENCAP_FILTER_ENTRY(IPV6, VXLAN, UCAST_DST),
1318 EF10_ENCAP_FILTER_ENTRY(IPV6, VXLAN, MCAST_DST),
1320 EF10_ENCAP_FILTER_ENTRY(IPV4, GENEVE, UCAST_DST),
1321 EF10_ENCAP_FILTER_ENTRY(IPV4, GENEVE, MCAST_DST),
1322 EF10_ENCAP_FILTER_ENTRY(IPV6, GENEVE, UCAST_DST),
1323 EF10_ENCAP_FILTER_ENTRY(IPV6, GENEVE, MCAST_DST),
1325 EF10_ENCAP_FILTER_ENTRY(IPV4, NVGRE, UCAST_DST),
1326 EF10_ENCAP_FILTER_ENTRY(IPV4, NVGRE, MCAST_DST),
1327 EF10_ENCAP_FILTER_ENTRY(IPV6, NVGRE, UCAST_DST),
1328 EF10_ENCAP_FILTER_ENTRY(IPV6, NVGRE, MCAST_DST),
1331 #undef EF10_ENCAP_FILTER_ENTRY
1333 static __checkReturn efx_rc_t
1334 ef10_filter_insert_encap_filters(
1335 __in efx_nic_t *enp,
1336 __in boolean_t mulcst,
1337 __in efx_filter_flags_t filter_flags)
1339 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
1343 EFX_STATIC_ASSERT(EFX_ARRAY_SIZE(ef10_filter_encap_list) <=
1344 EFX_ARRAY_SIZE(table->eft_encap_filter_indexes));
1347 * On Medford, full-featured firmware can identify packets as being
1348 * tunnel encapsulated, even if no encapsulated packet offloads are in
1349 * use. When packets are identified as such, ordinary filters are not
1350 * applied, only ones specific to encapsulated packets. Hence we need to
1351 * insert filters for encapsulated packets in order to receive them.
1353 * Separate filters need to be inserted for each ether type,
1354 * encapsulation type, and inner frame type (unicast or multicast). To
1355 * keep things simple and reduce the number of filters needed, catch-all
1356 * filters for all combinations of types are inserted, even if
1357 * all_unicst or all_mulcst have not been set. (These catch-all filters
1358 * may well, however, fail to insert on unprivileged functions.)
1360 table->eft_encap_filter_count = 0;
1361 for (i = 0; i < EFX_ARRAY_SIZE(ef10_filter_encap_list); i++) {
1362 efx_filter_spec_t spec;
1363 ef10_filter_encap_entry_t *encap_filter =
1364 &ef10_filter_encap_list[i];
1367 * Skip multicast filters if we've not been asked for
1368 * any multicast traffic.
1370 if ((mulcst == B_FALSE) &&
1371 (encap_filter->inner_frame_match ==
1372 EFX_FILTER_INNER_FRAME_MATCH_UNKNOWN_MCAST_DST))
1375 efx_filter_spec_init_rx(&spec, EFX_FILTER_PRI_AUTO,
1377 table->eft_default_rxq);
1378 efx_filter_spec_set_ether_type(&spec, encap_filter->ether_type);
1379 rc = efx_filter_spec_set_encap_type(&spec,
1380 encap_filter->encap_type,
1381 encap_filter->inner_frame_match);
1385 rc = ef10_filter_add_internal(enp, &spec, B_TRUE,
1386 &table->eft_encap_filter_indexes[
1387 table->eft_encap_filter_count]);
1392 table->eft_encap_filter_count++;
1401 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1407 ef10_filter_remove_old(
1408 __in efx_nic_t *enp)
1410 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
1413 for (i = 0; i < EFX_ARRAY_SIZE(table->eft_entry); i++) {
1414 if (ef10_filter_entry_is_auto_old(table, i)) {
1415 (void) ef10_filter_delete_internal(enp, i);
1421 static __checkReturn efx_rc_t
1422 ef10_filter_get_workarounds(
1423 __in efx_nic_t *enp)
1425 efx_nic_cfg_t *encp = &enp->en_nic_cfg;
1426 uint32_t implemented = 0;
1427 uint32_t enabled = 0;
1430 rc = efx_mcdi_get_workarounds(enp, &implemented, &enabled);
1432 /* Check if chained multicast filter support is enabled */
1433 if (implemented & enabled & MC_CMD_GET_WORKAROUNDS_OUT_BUG26807)
1434 encp->enc_bug26807_workaround = B_TRUE;
1436 encp->enc_bug26807_workaround = B_FALSE;
1437 } else if (rc == ENOTSUP) {
1439 * Firmware is too old to support GET_WORKAROUNDS, and support
1440 * for this workaround was implemented later.
1442 encp->enc_bug26807_workaround = B_FALSE;
1450 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1458 * Reconfigure all filters.
1459 * If all_unicst and/or all mulcst filters cannot be applied then
1460 * return ENOTSUP (Note the filters for the specified addresses are
1461 * still applied in this case).
1463 __checkReturn efx_rc_t
1464 ef10_filter_reconfigure(
1465 __in efx_nic_t *enp,
1466 __in_ecount(6) uint8_t const *mac_addr,
1467 __in boolean_t all_unicst,
1468 __in boolean_t mulcst,
1469 __in boolean_t all_mulcst,
1470 __in boolean_t brdcst,
1471 __in_ecount(6*count) uint8_t const *addrs,
1472 __in uint32_t count)
1474 efx_nic_cfg_t *encp = &enp->en_nic_cfg;
1475 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
1476 efx_filter_flags_t filter_flags;
1478 efx_rc_t all_unicst_rc = 0;
1479 efx_rc_t all_mulcst_rc = 0;
1482 if (table->eft_default_rxq == NULL) {
1484 * Filters direct traffic to the default RXQ, and so cannot be
1485 * inserted until it is available. Any currently configured
1486 * filters must be removed (ignore errors in case the MC
1487 * has rebooted, which removes hardware filters).
1489 for (i = 0; i < table->eft_unicst_filter_count; i++) {
1490 (void) ef10_filter_delete_internal(enp,
1491 table->eft_unicst_filter_indexes[i]);
1493 table->eft_unicst_filter_count = 0;
1495 for (i = 0; i < table->eft_mulcst_filter_count; i++) {
1496 (void) ef10_filter_delete_internal(enp,
1497 table->eft_mulcst_filter_indexes[i]);
1499 table->eft_mulcst_filter_count = 0;
1501 for (i = 0; i < table->eft_encap_filter_count; i++) {
1502 (void) ef10_filter_delete_internal(enp,
1503 table->eft_encap_filter_indexes[i]);
1505 table->eft_encap_filter_count = 0;
1510 if (table->eft_using_rss)
1511 filter_flags = EFX_FILTER_FLAG_RX_RSS;
1515 /* Mark old filters which may need to be removed */
1516 for (i = 0; i < table->eft_unicst_filter_count; i++) {
1517 ef10_filter_set_entry_auto_old(table,
1518 table->eft_unicst_filter_indexes[i]);
1520 for (i = 0; i < table->eft_mulcst_filter_count; i++) {
1521 ef10_filter_set_entry_auto_old(table,
1522 table->eft_mulcst_filter_indexes[i]);
1524 for (i = 0; i < table->eft_encap_filter_count; i++) {
1525 ef10_filter_set_entry_auto_old(table,
1526 table->eft_encap_filter_indexes[i]);
1530 * Insert or renew unicast filters.
1532 * Frimware does not perform chaining on unicast filters. As traffic is
1533 * therefore only delivered to the first matching filter, we should
1534 * always insert the specific filter for our MAC address, to try and
1535 * ensure we get that traffic.
1537 * (If the filter for our MAC address has already been inserted by
1538 * another function, we won't receive traffic sent to us, even if we
1539 * insert a unicast mismatch filter. To prevent traffic stealing, this
1540 * therefore relies on the privilege model only allowing functions to
1541 * insert filters for their own MAC address unless explicitly given
1542 * additional privileges by the user. This also means that, even on a
1543 * priviliged function, inserting a unicast mismatch filter may not
1544 * catch all traffic in multi PCI function scenarios.)
1546 table->eft_unicst_filter_count = 0;
1547 rc = ef10_filter_insert_unicast(enp, mac_addr, filter_flags);
1548 if (all_unicst || (rc != 0)) {
1549 all_unicst_rc = ef10_filter_insert_all_unicast(enp,
1551 if ((rc != 0) && (all_unicst_rc != 0))
1556 * WORKAROUND_BUG26807 controls firmware support for chained multicast
1557 * filters, and can only be enabled or disabled when the hardware filter
1560 * Chained multicast filters require support from the datapath firmware,
1561 * and may not be available (e.g. low-latency variants or old Huntington
1564 * Firmware will reset (FLR) functions which have inserted filters in
1565 * the hardware filter table when the workaround is enabled/disabled.
1566 * Functions without any hardware filters are not reset.
1568 * Re-check if the workaround is enabled after adding unicast hardware
1569 * filters. This ensures that encp->enc_bug26807_workaround matches the
1570 * firmware state, and that later changes to enable/disable the
1571 * workaround will result in this function seeing a reset (FLR).
1573 * In common-code drivers, we only support multiple PCI function
1574 * scenarios with firmware that supports multicast chaining, so we can
1575 * assume it is enabled for such cases and hence simplify the filter
1576 * insertion logic. Firmware that does not support multicast chaining
1577 * does not support multiple PCI function configurations either, so
1578 * filter insertion is much simpler and the same strategies can still be
1581 if ((rc = ef10_filter_get_workarounds(enp)) != 0)
1584 if ((table->eft_using_all_mulcst != all_mulcst) &&
1585 (encp->enc_bug26807_workaround == B_TRUE)) {
1587 * Multicast filter chaining is enabled, so traffic that matches
1588 * more than one multicast filter will be replicated and
1589 * delivered to multiple recipients. To avoid this duplicate
1590 * delivery, remove old multicast filters before inserting new
1591 * multicast filters.
1593 ef10_filter_remove_old(enp);
1596 /* Insert or renew multicast filters */
1597 if (all_mulcst == B_TRUE) {
1599 * Insert the all multicast filter. If that fails, try to insert
1600 * all of our multicast filters (but without rollback on
1603 all_mulcst_rc = ef10_filter_insert_all_multicast(enp,
1605 if (all_mulcst_rc != 0) {
1606 rc = ef10_filter_insert_multicast_list(enp, B_TRUE,
1607 brdcst, addrs, count, filter_flags, B_FALSE);
1613 * Insert filters for multicast addresses.
1614 * If any insertion fails, then rollback and try to insert the
1615 * all multicast filter instead.
1616 * If that also fails, try to insert all of the multicast
1617 * filters (but without rollback on failure).
1619 rc = ef10_filter_insert_multicast_list(enp, mulcst, brdcst,
1620 addrs, count, filter_flags, B_TRUE);
1622 if ((table->eft_using_all_mulcst == B_FALSE) &&
1623 (encp->enc_bug26807_workaround == B_TRUE)) {
1625 * Multicast filter chaining is on, so remove
1626 * old filters before inserting the multicast
1627 * all filter to avoid duplicate delivery caused
1628 * by packets matching multiple filters.
1630 ef10_filter_remove_old(enp);
1633 rc = ef10_filter_insert_all_multicast(enp,
1636 rc = ef10_filter_insert_multicast_list(enp,
1638 addrs, count, filter_flags, B_FALSE);
1645 if (encp->enc_tunnel_encapsulations_supported != 0) {
1646 /* Try to insert filters for encapsulated packets. */
1647 (void) ef10_filter_insert_encap_filters(enp,
1648 mulcst || all_mulcst || brdcst,
1652 /* Remove old filters which were not renewed */
1653 ef10_filter_remove_old(enp);
1655 /* report if any optional flags were rejected */
1656 if (((all_unicst != B_FALSE) && (all_unicst_rc != 0)) ||
1657 ((all_mulcst != B_FALSE) && (all_mulcst_rc != 0))) {
1670 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1672 /* Clear auto old flags */
1673 for (i = 0; i < EFX_ARRAY_SIZE(table->eft_entry); i++) {
1674 if (ef10_filter_entry_is_auto_old(table, i)) {
1675 ef10_filter_set_entry_not_auto_old(table, i);
1683 ef10_filter_get_default_rxq(
1684 __in efx_nic_t *enp,
1685 __out efx_rxq_t **erpp,
1686 __out boolean_t *using_rss)
1688 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
1690 *erpp = table->eft_default_rxq;
1691 *using_rss = table->eft_using_rss;
1696 ef10_filter_default_rxq_set(
1697 __in efx_nic_t *enp,
1698 __in efx_rxq_t *erp,
1699 __in boolean_t using_rss)
1701 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
1703 #if EFSYS_OPT_RX_SCALE
1704 EFSYS_ASSERT((using_rss == B_FALSE) ||
1705 (enp->en_rss_context != EF10_RSS_CONTEXT_INVALID));
1706 table->eft_using_rss = using_rss;
1708 EFSYS_ASSERT(using_rss == B_FALSE);
1709 table->eft_using_rss = B_FALSE;
1711 table->eft_default_rxq = erp;
1715 ef10_filter_default_rxq_clear(
1716 __in efx_nic_t *enp)
1718 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
1720 table->eft_default_rxq = NULL;
1721 table->eft_using_rss = B_FALSE;
1725 #endif /* EFSYS_OPT_FILTER */
1727 #endif /* EFSYS_OPT_HUNTINGTON || EFSYS_OPT_MEDFORD || EFSYS_OPT_MEDFORD2 */