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_V3_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_V3_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);
320 * Set the "MARK" or "FLAG" action for all packets matching this filter
321 * if necessary (only useful with equal stride packed stream Rx mode
322 * which provide the information in pseudo-header).
323 * These actions require MC_CMD_FILTER_OP_V3_IN msgrequest.
325 if ((spec->efs_flags & EFX_FILTER_FLAG_ACTION_MARK) &&
326 (spec->efs_flags & EFX_FILTER_FLAG_ACTION_FLAG)) {
330 if (spec->efs_flags & EFX_FILTER_FLAG_ACTION_MARK) {
331 MCDI_IN_SET_DWORD(req, FILTER_OP_V3_IN_MATCH_ACTION,
332 MC_CMD_FILTER_OP_V3_IN_MATCH_ACTION_MARK);
333 MCDI_IN_SET_DWORD(req, FILTER_OP_V3_IN_MATCH_MARK_VALUE,
335 } else if (spec->efs_flags & EFX_FILTER_FLAG_ACTION_FLAG) {
336 MCDI_IN_SET_DWORD(req, FILTER_OP_V3_IN_MATCH_ACTION,
337 MC_CMD_FILTER_OP_V3_IN_MATCH_ACTION_FLAG);
340 efx_mcdi_execute(enp, &req);
342 if (req.emr_rc != 0) {
347 if (req.emr_out_length_used < MC_CMD_FILTER_OP_EXT_OUT_LEN) {
352 handle->efh_lo = MCDI_OUT_DWORD(req, FILTER_OP_EXT_OUT_HANDLE_LO);
353 handle->efh_hi = MCDI_OUT_DWORD(req, FILTER_OP_EXT_OUT_HANDLE_HI);
366 EFSYS_PROBE1(fail1, efx_rc_t, rc);
372 static __checkReturn efx_rc_t
373 efx_mcdi_filter_op_delete(
375 __in unsigned int filter_op,
376 __inout ef10_filter_handle_t *handle)
379 uint8_t payload[MAX(MC_CMD_FILTER_OP_EXT_IN_LEN,
380 MC_CMD_FILTER_OP_EXT_OUT_LEN)];
383 memset(payload, 0, sizeof (payload));
384 req.emr_cmd = MC_CMD_FILTER_OP;
385 req.emr_in_buf = payload;
386 req.emr_in_length = MC_CMD_FILTER_OP_EXT_IN_LEN;
387 req.emr_out_buf = payload;
388 req.emr_out_length = MC_CMD_FILTER_OP_EXT_OUT_LEN;
391 case MC_CMD_FILTER_OP_IN_OP_REMOVE:
392 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_OP,
393 MC_CMD_FILTER_OP_IN_OP_REMOVE);
395 case MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE:
396 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_OP,
397 MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE);
405 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_HANDLE_LO, handle->efh_lo);
406 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_HANDLE_HI, handle->efh_hi);
408 efx_mcdi_execute_quiet(enp, &req);
410 if (req.emr_rc != 0) {
415 if (req.emr_out_length_used < MC_CMD_FILTER_OP_EXT_OUT_LEN) {
428 EFSYS_PROBE1(fail1, efx_rc_t, rc);
433 static __checkReturn boolean_t
435 __in const efx_filter_spec_t *left,
436 __in const efx_filter_spec_t *right)
438 /* FIXME: Consider rx vs tx filters (look at efs_flags) */
439 if (left->efs_match_flags != right->efs_match_flags)
441 if (!EFX_OWORD_IS_EQUAL(left->efs_rem_host, right->efs_rem_host))
443 if (!EFX_OWORD_IS_EQUAL(left->efs_loc_host, right->efs_loc_host))
445 if (memcmp(left->efs_rem_mac, right->efs_rem_mac, EFX_MAC_ADDR_LEN))
447 if (memcmp(left->efs_loc_mac, right->efs_loc_mac, EFX_MAC_ADDR_LEN))
449 if (left->efs_rem_port != right->efs_rem_port)
451 if (left->efs_loc_port != right->efs_loc_port)
453 if (left->efs_inner_vid != right->efs_inner_vid)
455 if (left->efs_outer_vid != right->efs_outer_vid)
457 if (left->efs_ether_type != right->efs_ether_type)
459 if (left->efs_ip_proto != right->efs_ip_proto)
461 if (left->efs_encap_type != right->efs_encap_type)
463 if (memcmp(left->efs_vni_or_vsid, right->efs_vni_or_vsid,
464 EFX_VNI_OR_VSID_LEN))
466 if (memcmp(left->efs_ifrm_loc_mac, right->efs_ifrm_loc_mac,
474 static __checkReturn boolean_t
475 ef10_filter_same_dest(
476 __in const efx_filter_spec_t *left,
477 __in const efx_filter_spec_t *right)
479 if ((left->efs_flags & EFX_FILTER_FLAG_RX_RSS) &&
480 (right->efs_flags & EFX_FILTER_FLAG_RX_RSS)) {
481 if (left->efs_rss_context == right->efs_rss_context)
483 } else if ((~(left->efs_flags) & EFX_FILTER_FLAG_RX_RSS) &&
484 (~(right->efs_flags) & EFX_FILTER_FLAG_RX_RSS)) {
485 if (left->efs_dmaq_id == right->efs_dmaq_id)
491 static __checkReturn uint32_t
493 __in efx_filter_spec_t *spec)
495 EFX_STATIC_ASSERT((sizeof (efx_filter_spec_t) % sizeof (uint32_t))
497 EFX_STATIC_ASSERT((EFX_FIELD_OFFSET(efx_filter_spec_t, efs_outer_vid) %
498 sizeof (uint32_t)) == 0);
501 * As the area of the efx_filter_spec_t we need to hash is DWORD
502 * aligned and an exact number of DWORDs in size we can use the
503 * optimised efx_hash_dwords() rather than efx_hash_bytes()
505 return (efx_hash_dwords((const uint32_t *)&spec->efs_outer_vid,
506 (sizeof (efx_filter_spec_t) -
507 EFX_FIELD_OFFSET(efx_filter_spec_t, efs_outer_vid)) /
508 sizeof (uint32_t), 0));
512 * Decide whether a filter should be exclusive or else should allow
513 * delivery to additional recipients. Currently we decide that
514 * filters for specific local unicast MAC and IP addresses are
517 static __checkReturn boolean_t
518 ef10_filter_is_exclusive(
519 __in efx_filter_spec_t *spec)
521 if ((spec->efs_match_flags & EFX_FILTER_MATCH_LOC_MAC) &&
522 !EFX_MAC_ADDR_IS_MULTICAST(spec->efs_loc_mac))
525 if ((spec->efs_match_flags &
526 (EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_LOC_HOST)) ==
527 (EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_LOC_HOST)) {
528 if ((spec->efs_ether_type == EFX_ETHER_TYPE_IPV4) &&
529 ((spec->efs_loc_host.eo_u8[0] & 0xf) != 0xe))
531 if ((spec->efs_ether_type == EFX_ETHER_TYPE_IPV6) &&
532 (spec->efs_loc_host.eo_u8[0] != 0xff))
539 __checkReturn efx_rc_t
544 efx_filter_spec_t *spec;
545 ef10_filter_table_t *eftp = enp->en_filter.ef_ef10_filter_table;
547 efsys_lock_state_t state;
550 EFSYS_ASSERT(enp->en_family == EFX_FAMILY_HUNTINGTON ||
551 enp->en_family == EFX_FAMILY_MEDFORD ||
552 enp->en_family == EFX_FAMILY_MEDFORD2);
554 for (tbl_id = 0; tbl_id < EFX_EF10_FILTER_TBL_ROWS; tbl_id++) {
556 EFSYS_LOCK(enp->en_eslp, state);
558 spec = ef10_filter_entry_spec(eftp, tbl_id);
561 } else if (ef10_filter_entry_is_busy(eftp, tbl_id)) {
562 /* Ignore busy entries. */
565 ef10_filter_set_entry_busy(eftp, tbl_id);
569 EFSYS_UNLOCK(enp->en_eslp, state);
571 if (restoring == B_FALSE)
574 if (ef10_filter_is_exclusive(spec)) {
575 rc = efx_mcdi_filter_op_add(enp, spec,
576 MC_CMD_FILTER_OP_IN_OP_INSERT,
577 &eftp->eft_entry[tbl_id].efe_handle);
579 rc = efx_mcdi_filter_op_add(enp, spec,
580 MC_CMD_FILTER_OP_IN_OP_SUBSCRIBE,
581 &eftp->eft_entry[tbl_id].efe_handle);
587 EFSYS_LOCK(enp->en_eslp, state);
589 ef10_filter_set_entry_not_busy(eftp, tbl_id);
591 EFSYS_UNLOCK(enp->en_eslp, state);
597 EFSYS_PROBE1(fail1, efx_rc_t, rc);
603 * An arbitrary search limit for the software hash table. As per the linux net
606 #define EF10_FILTER_SEARCH_LIMIT 200
608 static __checkReturn efx_rc_t
609 ef10_filter_add_internal(
611 __inout efx_filter_spec_t *spec,
612 __in boolean_t may_replace,
613 __out_opt uint32_t *filter_id)
616 ef10_filter_table_t *eftp = enp->en_filter.ef_ef10_filter_table;
617 efx_filter_spec_t *saved_spec;
621 boolean_t replacing = B_FALSE;
623 efsys_lock_state_t state;
624 boolean_t locked = B_FALSE;
626 EFSYS_ASSERT(enp->en_family == EFX_FAMILY_HUNTINGTON ||
627 enp->en_family == EFX_FAMILY_MEDFORD ||
628 enp->en_family == EFX_FAMILY_MEDFORD2);
630 hash = ef10_filter_hash(spec);
633 * FIXME: Add support for inserting filters of different priorities
634 * and removing lower priority multicast filters (bug 42378)
638 * Find any existing filters with the same match tuple or
639 * else a free slot to insert at. If any of them are busy,
640 * we have to wait and retry.
645 EFSYS_LOCK(enp->en_eslp, state);
649 i = (hash + depth) & (EFX_EF10_FILTER_TBL_ROWS - 1);
650 saved_spec = ef10_filter_entry_spec(eftp, i);
656 } else if (ef10_filter_equal(spec, saved_spec)) {
657 if (ef10_filter_entry_is_busy(eftp, i))
659 if (saved_spec->efs_priority
660 == EFX_FILTER_PRI_AUTO) {
663 } else if (ef10_filter_is_exclusive(spec)) {
677 * Once we reach the maximum search depth, use
678 * the first suitable slot or return EBUSY if
681 if (depth == EF10_FILTER_SEARCH_LIMIT) {
690 EFSYS_UNLOCK(enp->en_eslp, state);
696 * Create a software table entry if necessary, and mark it
697 * busy. We might yet fail to insert, but any attempt to
698 * insert a conflicting filter while we're waiting for the
699 * firmware must find the busy entry.
701 saved_spec = ef10_filter_entry_spec(eftp, ins_index);
703 if (saved_spec->efs_priority == EFX_FILTER_PRI_AUTO) {
704 /* This is a filter we are refreshing */
705 ef10_filter_set_entry_not_auto_old(eftp, ins_index);
711 EFSYS_KMEM_ALLOC(enp->en_esip, sizeof (*spec), saved_spec);
717 ef10_filter_set_entry(eftp, ins_index, saved_spec);
719 ef10_filter_set_entry_busy(eftp, ins_index);
721 EFSYS_UNLOCK(enp->en_eslp, state);
725 * On replacing the filter handle may change after after a successful
729 rc = efx_mcdi_filter_op_add(enp, spec,
730 MC_CMD_FILTER_OP_IN_OP_REPLACE,
731 &eftp->eft_entry[ins_index].efe_handle);
732 } else if (ef10_filter_is_exclusive(spec)) {
733 rc = efx_mcdi_filter_op_add(enp, spec,
734 MC_CMD_FILTER_OP_IN_OP_INSERT,
735 &eftp->eft_entry[ins_index].efe_handle);
737 rc = efx_mcdi_filter_op_add(enp, spec,
738 MC_CMD_FILTER_OP_IN_OP_SUBSCRIBE,
739 &eftp->eft_entry[ins_index].efe_handle);
745 EFSYS_LOCK(enp->en_eslp, state);
749 /* Update the fields that may differ */
750 saved_spec->efs_priority = spec->efs_priority;
751 saved_spec->efs_flags = spec->efs_flags;
752 saved_spec->efs_rss_context = spec->efs_rss_context;
753 saved_spec->efs_dmaq_id = spec->efs_dmaq_id;
756 ef10_filter_set_entry_not_busy(eftp, ins_index);
760 EFSYS_UNLOCK(enp->en_eslp, state);
764 *filter_id = ins_index;
772 EFSYS_KMEM_FREE(enp->en_esip, sizeof (*spec), saved_spec);
775 ef10_filter_set_entry_not_busy(eftp, ins_index);
776 ef10_filter_set_entry(eftp, ins_index, NULL);
785 EFSYS_PROBE1(fail1, efx_rc_t, rc);
788 EFSYS_UNLOCK(enp->en_eslp, state);
793 __checkReturn efx_rc_t
796 __inout efx_filter_spec_t *spec,
797 __in boolean_t may_replace)
801 rc = ef10_filter_add_internal(enp, spec, may_replace, NULL);
808 EFSYS_PROBE1(fail1, efx_rc_t, rc);
814 static __checkReturn efx_rc_t
815 ef10_filter_delete_internal(
817 __in uint32_t filter_id)
820 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
821 efx_filter_spec_t *spec;
822 efsys_lock_state_t state;
823 uint32_t filter_idx = filter_id % EFX_EF10_FILTER_TBL_ROWS;
826 * Find the software table entry and mark it busy. Don't
827 * remove it yet; any attempt to update while we're waiting
828 * for the firmware must find the busy entry.
830 * FIXME: What if the busy flag is never cleared?
832 EFSYS_LOCK(enp->en_eslp, state);
833 while (ef10_filter_entry_is_busy(table, filter_idx)) {
834 EFSYS_UNLOCK(enp->en_eslp, state);
836 EFSYS_LOCK(enp->en_eslp, state);
838 if ((spec = ef10_filter_entry_spec(table, filter_idx)) != NULL) {
839 ef10_filter_set_entry_busy(table, filter_idx);
841 EFSYS_UNLOCK(enp->en_eslp, state);
849 * Try to remove the hardware filter. This may fail if the MC has
850 * rebooted (which frees all hardware filter resources).
852 if (ef10_filter_is_exclusive(spec)) {
853 rc = efx_mcdi_filter_op_delete(enp,
854 MC_CMD_FILTER_OP_IN_OP_REMOVE,
855 &table->eft_entry[filter_idx].efe_handle);
857 rc = efx_mcdi_filter_op_delete(enp,
858 MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE,
859 &table->eft_entry[filter_idx].efe_handle);
862 /* Free the software table entry */
863 EFSYS_LOCK(enp->en_eslp, state);
864 ef10_filter_set_entry_not_busy(table, filter_idx);
865 ef10_filter_set_entry(table, filter_idx, NULL);
866 EFSYS_UNLOCK(enp->en_eslp, state);
868 EFSYS_KMEM_FREE(enp->en_esip, sizeof (*spec), spec);
870 /* Check result of hardware filter removal */
880 EFSYS_PROBE1(fail1, efx_rc_t, rc);
885 __checkReturn efx_rc_t
888 __inout efx_filter_spec_t *spec)
891 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
892 efx_filter_spec_t *saved_spec;
896 efsys_lock_state_t state;
897 boolean_t locked = B_FALSE;
899 EFSYS_ASSERT(enp->en_family == EFX_FAMILY_HUNTINGTON ||
900 enp->en_family == EFX_FAMILY_MEDFORD ||
901 enp->en_family == EFX_FAMILY_MEDFORD2);
903 hash = ef10_filter_hash(spec);
905 EFSYS_LOCK(enp->en_eslp, state);
910 i = (hash + depth) & (EFX_EF10_FILTER_TBL_ROWS - 1);
911 saved_spec = ef10_filter_entry_spec(table, i);
912 if (saved_spec && ef10_filter_equal(spec, saved_spec) &&
913 ef10_filter_same_dest(spec, saved_spec)) {
916 if (depth == EF10_FILTER_SEARCH_LIMIT) {
923 EFSYS_UNLOCK(enp->en_eslp, state);
926 rc = ef10_filter_delete_internal(enp, i);
936 EFSYS_PROBE1(fail1, efx_rc_t, rc);
939 EFSYS_UNLOCK(enp->en_eslp, state);
944 static __checkReturn efx_rc_t
945 efx_mcdi_get_parser_disp_info(
947 __out_ecount(buffer_length) uint32_t *buffer,
948 __in size_t buffer_length,
949 __in boolean_t encap,
950 __out size_t *list_lengthp)
953 uint8_t payload[MAX(MC_CMD_GET_PARSER_DISP_INFO_IN_LEN,
954 MC_CMD_GET_PARSER_DISP_INFO_OUT_LENMAX)];
955 size_t matches_count;
959 (void) memset(payload, 0, sizeof (payload));
960 req.emr_cmd = MC_CMD_GET_PARSER_DISP_INFO;
961 req.emr_in_buf = payload;
962 req.emr_in_length = MC_CMD_GET_PARSER_DISP_INFO_IN_LEN;
963 req.emr_out_buf = payload;
964 req.emr_out_length = MC_CMD_GET_PARSER_DISP_INFO_OUT_LENMAX;
966 MCDI_IN_SET_DWORD(req, GET_PARSER_DISP_INFO_OUT_OP, encap ?
967 MC_CMD_GET_PARSER_DISP_INFO_IN_OP_GET_SUPPORTED_ENCAP_RX_MATCHES :
968 MC_CMD_GET_PARSER_DISP_INFO_IN_OP_GET_SUPPORTED_RX_MATCHES);
970 efx_mcdi_execute(enp, &req);
972 if (req.emr_rc != 0) {
977 matches_count = MCDI_OUT_DWORD(req,
978 GET_PARSER_DISP_INFO_OUT_NUM_SUPPORTED_MATCHES);
980 if (req.emr_out_length_used <
981 MC_CMD_GET_PARSER_DISP_INFO_OUT_LEN(matches_count)) {
986 *list_lengthp = matches_count;
988 if (buffer_length < matches_count) {
994 * Check that the elements in the list in the MCDI response are the size
995 * we expect, so we can just copy them directly. Any conversion of the
996 * flags is handled by the caller.
998 EFX_STATIC_ASSERT(sizeof (uint32_t) ==
999 MC_CMD_GET_PARSER_DISP_INFO_OUT_SUPPORTED_MATCHES_LEN);
1001 list_size = matches_count *
1002 MC_CMD_GET_PARSER_DISP_INFO_OUT_SUPPORTED_MATCHES_LEN;
1004 MCDI_OUT2(req, uint32_t,
1005 GET_PARSER_DISP_INFO_OUT_SUPPORTED_MATCHES),
1015 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1020 __checkReturn efx_rc_t
1021 ef10_filter_supported_filters(
1022 __in efx_nic_t *enp,
1023 __out_ecount(buffer_length) uint32_t *buffer,
1024 __in size_t buffer_length,
1025 __out size_t *list_lengthp)
1027 efx_nic_cfg_t *encp = &(enp->en_nic_cfg);
1028 size_t mcdi_list_length;
1029 size_t mcdi_encap_list_length;
1032 uint32_t next_buf_idx;
1033 size_t next_buf_length;
1035 boolean_t no_space = B_FALSE;
1036 efx_filter_match_flags_t all_filter_flags =
1037 (EFX_FILTER_MATCH_REM_HOST | EFX_FILTER_MATCH_LOC_HOST |
1038 EFX_FILTER_MATCH_REM_MAC | EFX_FILTER_MATCH_REM_PORT |
1039 EFX_FILTER_MATCH_LOC_MAC | EFX_FILTER_MATCH_LOC_PORT |
1040 EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_INNER_VID |
1041 EFX_FILTER_MATCH_OUTER_VID | EFX_FILTER_MATCH_IP_PROTO |
1042 EFX_FILTER_MATCH_VNI_OR_VSID |
1043 EFX_FILTER_MATCH_IFRM_LOC_MAC |
1044 EFX_FILTER_MATCH_IFRM_UNKNOWN_MCAST_DST |
1045 EFX_FILTER_MATCH_IFRM_UNKNOWN_UCAST_DST |
1046 EFX_FILTER_MATCH_ENCAP_TYPE |
1047 EFX_FILTER_MATCH_UNKNOWN_MCAST_DST |
1048 EFX_FILTER_MATCH_UNKNOWN_UCAST_DST);
1051 * Two calls to MC_CMD_GET_PARSER_DISP_INFO are needed: one to get the
1052 * list of supported filters for ordinary packets, and then another to
1053 * get the list of supported filters for encapsulated packets. To
1054 * distinguish the second list from the first, the
1055 * EFX_FILTER_MATCH_ENCAP_TYPE flag is added to each filter for
1056 * encapsulated packets.
1058 rc = efx_mcdi_get_parser_disp_info(enp, buffer, buffer_length, B_FALSE,
1069 next_buf_length = 0;
1071 EFSYS_ASSERT(mcdi_list_length <= buffer_length);
1072 next_buf_idx = mcdi_list_length;
1073 next_buf_length = buffer_length - mcdi_list_length;
1076 if (encp->enc_tunnel_encapsulations_supported != 0) {
1077 rc = efx_mcdi_get_parser_disp_info(enp, &buffer[next_buf_idx],
1078 next_buf_length, B_TRUE, &mcdi_encap_list_length);
1085 for (i = next_buf_idx;
1086 i < next_buf_idx + mcdi_encap_list_length; i++)
1087 buffer[i] |= EFX_FILTER_MATCH_ENCAP_TYPE;
1090 mcdi_encap_list_length = 0;
1094 *list_lengthp = mcdi_list_length + mcdi_encap_list_length;
1100 * The static assertions in ef10_filter_init() ensure that the values of
1101 * the EFX_FILTER_MATCH flags match those used by MCDI, so they don't
1102 * need to be converted.
1104 * In case support is added to MCDI for additional flags, remove any
1105 * matches from the list which include flags we don't support. The order
1106 * of the matches is preserved as they are ordered from highest to
1109 EFSYS_ASSERT(mcdi_list_length + mcdi_encap_list_length <=
1112 for (i = 0; i < mcdi_list_length + mcdi_encap_list_length; i++) {
1113 if ((buffer[i] & ~all_filter_flags) == 0) {
1114 buffer[list_length] = buffer[i];
1119 *list_lengthp = list_length;
1128 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1133 static __checkReturn efx_rc_t
1134 ef10_filter_insert_unicast(
1135 __in efx_nic_t *enp,
1136 __in_ecount(6) uint8_t const *addr,
1137 __in efx_filter_flags_t filter_flags)
1139 ef10_filter_table_t *eftp = enp->en_filter.ef_ef10_filter_table;
1140 efx_filter_spec_t spec;
1143 /* Insert the filter for the local station address */
1144 efx_filter_spec_init_rx(&spec, EFX_FILTER_PRI_AUTO,
1146 eftp->eft_default_rxq);
1147 rc = efx_filter_spec_set_eth_local(&spec, EFX_FILTER_SPEC_VID_UNSPEC,
1152 rc = ef10_filter_add_internal(enp, &spec, B_TRUE,
1153 &eftp->eft_unicst_filter_indexes[eftp->eft_unicst_filter_count]);
1157 eftp->eft_unicst_filter_count++;
1158 EFSYS_ASSERT(eftp->eft_unicst_filter_count <=
1159 EFX_EF10_FILTER_UNICAST_FILTERS_MAX);
1166 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1170 static __checkReturn efx_rc_t
1171 ef10_filter_insert_all_unicast(
1172 __in efx_nic_t *enp,
1173 __in efx_filter_flags_t filter_flags)
1175 ef10_filter_table_t *eftp = enp->en_filter.ef_ef10_filter_table;
1176 efx_filter_spec_t spec;
1179 /* Insert the unknown unicast filter */
1180 efx_filter_spec_init_rx(&spec, EFX_FILTER_PRI_AUTO,
1182 eftp->eft_default_rxq);
1183 rc = efx_filter_spec_set_uc_def(&spec);
1186 rc = ef10_filter_add_internal(enp, &spec, B_TRUE,
1187 &eftp->eft_unicst_filter_indexes[eftp->eft_unicst_filter_count]);
1191 eftp->eft_unicst_filter_count++;
1192 EFSYS_ASSERT(eftp->eft_unicst_filter_count <=
1193 EFX_EF10_FILTER_UNICAST_FILTERS_MAX);
1200 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1204 static __checkReturn efx_rc_t
1205 ef10_filter_insert_multicast_list(
1206 __in efx_nic_t *enp,
1207 __in boolean_t mulcst,
1208 __in boolean_t brdcst,
1209 __in_ecount(6*count) uint8_t const *addrs,
1210 __in uint32_t count,
1211 __in efx_filter_flags_t filter_flags,
1212 __in boolean_t rollback)
1214 ef10_filter_table_t *eftp = enp->en_filter.ef_ef10_filter_table;
1215 efx_filter_spec_t spec;
1218 uint32_t filter_index;
1219 uint32_t filter_count;
1222 if (mulcst == B_FALSE)
1225 if (count + (brdcst ? 1 : 0) >
1226 EFX_ARRAY_SIZE(eftp->eft_mulcst_filter_indexes)) {
1227 /* Too many MAC addresses */
1232 /* Insert/renew multicast address list filters */
1234 for (i = 0; i < count; i++) {
1235 efx_filter_spec_init_rx(&spec,
1236 EFX_FILTER_PRI_AUTO,
1238 eftp->eft_default_rxq);
1240 rc = efx_filter_spec_set_eth_local(&spec,
1241 EFX_FILTER_SPEC_VID_UNSPEC,
1242 &addrs[i * EFX_MAC_ADDR_LEN]);
1244 if (rollback == B_TRUE) {
1245 /* Only stop upon failure if told to rollback */
1249 * Don't try to add a filter with a corrupt
1256 rc = ef10_filter_add_internal(enp, &spec, B_TRUE,
1260 eftp->eft_mulcst_filter_indexes[filter_count] =
1263 } else if (rollback == B_TRUE) {
1264 /* Only stop upon failure if told to rollback */
1270 if (brdcst == B_TRUE) {
1271 /* Insert/renew broadcast address filter */
1272 efx_filter_spec_init_rx(&spec, EFX_FILTER_PRI_AUTO,
1274 eftp->eft_default_rxq);
1276 EFX_MAC_BROADCAST_ADDR_SET(addr);
1277 rc = efx_filter_spec_set_eth_local(&spec,
1278 EFX_FILTER_SPEC_VID_UNSPEC, addr);
1279 if ((rc != 0) && (rollback == B_TRUE)) {
1280 /* Only stop upon failure if told to rollback */
1284 rc = ef10_filter_add_internal(enp, &spec, B_TRUE,
1288 eftp->eft_mulcst_filter_indexes[filter_count] =
1291 } else if (rollback == B_TRUE) {
1292 /* Only stop upon failure if told to rollback */
1297 eftp->eft_mulcst_filter_count = filter_count;
1298 eftp->eft_using_all_mulcst = B_FALSE;
1303 /* Remove any filters we have inserted */
1306 (void) ef10_filter_delete_internal(enp,
1307 eftp->eft_mulcst_filter_indexes[i]);
1309 eftp->eft_mulcst_filter_count = 0;
1312 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1317 static __checkReturn efx_rc_t
1318 ef10_filter_insert_all_multicast(
1319 __in efx_nic_t *enp,
1320 __in efx_filter_flags_t filter_flags)
1322 ef10_filter_table_t *eftp = enp->en_filter.ef_ef10_filter_table;
1323 efx_filter_spec_t spec;
1326 /* Insert the unknown multicast filter */
1327 efx_filter_spec_init_rx(&spec, EFX_FILTER_PRI_AUTO,
1329 eftp->eft_default_rxq);
1330 rc = efx_filter_spec_set_mc_def(&spec);
1334 rc = ef10_filter_add_internal(enp, &spec, B_TRUE,
1335 &eftp->eft_mulcst_filter_indexes[0]);
1339 eftp->eft_mulcst_filter_count = 1;
1340 eftp->eft_using_all_mulcst = B_TRUE;
1343 * FIXME: If brdcst == B_FALSE, add a filter to drop broadcast traffic.
1351 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1356 typedef struct ef10_filter_encap_entry_s {
1357 uint16_t ether_type;
1358 efx_tunnel_protocol_t encap_type;
1359 uint32_t inner_frame_match;
1360 } ef10_filter_encap_entry_t;
1362 #define EF10_ENCAP_FILTER_ENTRY(ipv, encap_type, inner_frame_match) \
1363 { EFX_ETHER_TYPE_##ipv, EFX_TUNNEL_PROTOCOL_##encap_type, \
1364 EFX_FILTER_INNER_FRAME_MATCH_UNKNOWN_##inner_frame_match }
1366 static ef10_filter_encap_entry_t ef10_filter_encap_list[] = {
1367 EF10_ENCAP_FILTER_ENTRY(IPV4, VXLAN, UCAST_DST),
1368 EF10_ENCAP_FILTER_ENTRY(IPV4, VXLAN, MCAST_DST),
1369 EF10_ENCAP_FILTER_ENTRY(IPV6, VXLAN, UCAST_DST),
1370 EF10_ENCAP_FILTER_ENTRY(IPV6, VXLAN, MCAST_DST),
1372 EF10_ENCAP_FILTER_ENTRY(IPV4, GENEVE, UCAST_DST),
1373 EF10_ENCAP_FILTER_ENTRY(IPV4, GENEVE, MCAST_DST),
1374 EF10_ENCAP_FILTER_ENTRY(IPV6, GENEVE, UCAST_DST),
1375 EF10_ENCAP_FILTER_ENTRY(IPV6, GENEVE, MCAST_DST),
1377 EF10_ENCAP_FILTER_ENTRY(IPV4, NVGRE, UCAST_DST),
1378 EF10_ENCAP_FILTER_ENTRY(IPV4, NVGRE, MCAST_DST),
1379 EF10_ENCAP_FILTER_ENTRY(IPV6, NVGRE, UCAST_DST),
1380 EF10_ENCAP_FILTER_ENTRY(IPV6, NVGRE, MCAST_DST),
1383 #undef EF10_ENCAP_FILTER_ENTRY
1385 static __checkReturn efx_rc_t
1386 ef10_filter_insert_encap_filters(
1387 __in efx_nic_t *enp,
1388 __in boolean_t mulcst,
1389 __in efx_filter_flags_t filter_flags)
1391 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
1395 EFX_STATIC_ASSERT(EFX_ARRAY_SIZE(ef10_filter_encap_list) <=
1396 EFX_ARRAY_SIZE(table->eft_encap_filter_indexes));
1399 * On Medford, full-featured firmware can identify packets as being
1400 * tunnel encapsulated, even if no encapsulated packet offloads are in
1401 * use. When packets are identified as such, ordinary filters are not
1402 * applied, only ones specific to encapsulated packets. Hence we need to
1403 * insert filters for encapsulated packets in order to receive them.
1405 * Separate filters need to be inserted for each ether type,
1406 * encapsulation type, and inner frame type (unicast or multicast). To
1407 * keep things simple and reduce the number of filters needed, catch-all
1408 * filters for all combinations of types are inserted, even if
1409 * all_unicst or all_mulcst have not been set. (These catch-all filters
1410 * may well, however, fail to insert on unprivileged functions.)
1412 table->eft_encap_filter_count = 0;
1413 for (i = 0; i < EFX_ARRAY_SIZE(ef10_filter_encap_list); i++) {
1414 efx_filter_spec_t spec;
1415 ef10_filter_encap_entry_t *encap_filter =
1416 &ef10_filter_encap_list[i];
1419 * Skip multicast filters if we've not been asked for
1420 * any multicast traffic.
1422 if ((mulcst == B_FALSE) &&
1423 (encap_filter->inner_frame_match ==
1424 EFX_FILTER_INNER_FRAME_MATCH_UNKNOWN_MCAST_DST))
1427 efx_filter_spec_init_rx(&spec, EFX_FILTER_PRI_AUTO,
1429 table->eft_default_rxq);
1430 efx_filter_spec_set_ether_type(&spec, encap_filter->ether_type);
1431 rc = efx_filter_spec_set_encap_type(&spec,
1432 encap_filter->encap_type,
1433 encap_filter->inner_frame_match);
1437 rc = ef10_filter_add_internal(enp, &spec, B_TRUE,
1438 &table->eft_encap_filter_indexes[
1439 table->eft_encap_filter_count]);
1444 table->eft_encap_filter_count++;
1453 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1459 ef10_filter_remove_old(
1460 __in efx_nic_t *enp)
1462 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
1465 for (i = 0; i < EFX_ARRAY_SIZE(table->eft_entry); i++) {
1466 if (ef10_filter_entry_is_auto_old(table, i)) {
1467 (void) ef10_filter_delete_internal(enp, i);
1473 static __checkReturn efx_rc_t
1474 ef10_filter_get_workarounds(
1475 __in efx_nic_t *enp)
1477 efx_nic_cfg_t *encp = &enp->en_nic_cfg;
1478 uint32_t implemented = 0;
1479 uint32_t enabled = 0;
1482 rc = efx_mcdi_get_workarounds(enp, &implemented, &enabled);
1484 /* Check if chained multicast filter support is enabled */
1485 if (implemented & enabled & MC_CMD_GET_WORKAROUNDS_OUT_BUG26807)
1486 encp->enc_bug26807_workaround = B_TRUE;
1488 encp->enc_bug26807_workaround = B_FALSE;
1489 } else if (rc == ENOTSUP) {
1491 * Firmware is too old to support GET_WORKAROUNDS, and support
1492 * for this workaround was implemented later.
1494 encp->enc_bug26807_workaround = B_FALSE;
1502 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1510 * Reconfigure all filters.
1511 * If all_unicst and/or all mulcst filters cannot be applied then
1512 * return ENOTSUP (Note the filters for the specified addresses are
1513 * still applied in this case).
1515 __checkReturn efx_rc_t
1516 ef10_filter_reconfigure(
1517 __in efx_nic_t *enp,
1518 __in_ecount(6) uint8_t const *mac_addr,
1519 __in boolean_t all_unicst,
1520 __in boolean_t mulcst,
1521 __in boolean_t all_mulcst,
1522 __in boolean_t brdcst,
1523 __in_ecount(6*count) uint8_t const *addrs,
1524 __in uint32_t count)
1526 efx_nic_cfg_t *encp = &enp->en_nic_cfg;
1527 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
1528 efx_filter_flags_t filter_flags;
1530 efx_rc_t all_unicst_rc = 0;
1531 efx_rc_t all_mulcst_rc = 0;
1534 if (table->eft_default_rxq == NULL) {
1536 * Filters direct traffic to the default RXQ, and so cannot be
1537 * inserted until it is available. Any currently configured
1538 * filters must be removed (ignore errors in case the MC
1539 * has rebooted, which removes hardware filters).
1541 for (i = 0; i < table->eft_unicst_filter_count; i++) {
1542 (void) ef10_filter_delete_internal(enp,
1543 table->eft_unicst_filter_indexes[i]);
1545 table->eft_unicst_filter_count = 0;
1547 for (i = 0; i < table->eft_mulcst_filter_count; i++) {
1548 (void) ef10_filter_delete_internal(enp,
1549 table->eft_mulcst_filter_indexes[i]);
1551 table->eft_mulcst_filter_count = 0;
1553 for (i = 0; i < table->eft_encap_filter_count; i++) {
1554 (void) ef10_filter_delete_internal(enp,
1555 table->eft_encap_filter_indexes[i]);
1557 table->eft_encap_filter_count = 0;
1562 if (table->eft_using_rss)
1563 filter_flags = EFX_FILTER_FLAG_RX_RSS;
1567 /* Mark old filters which may need to be removed */
1568 for (i = 0; i < table->eft_unicst_filter_count; i++) {
1569 ef10_filter_set_entry_auto_old(table,
1570 table->eft_unicst_filter_indexes[i]);
1572 for (i = 0; i < table->eft_mulcst_filter_count; i++) {
1573 ef10_filter_set_entry_auto_old(table,
1574 table->eft_mulcst_filter_indexes[i]);
1576 for (i = 0; i < table->eft_encap_filter_count; i++) {
1577 ef10_filter_set_entry_auto_old(table,
1578 table->eft_encap_filter_indexes[i]);
1582 * Insert or renew unicast filters.
1584 * Frimware does not perform chaining on unicast filters. As traffic is
1585 * therefore only delivered to the first matching filter, we should
1586 * always insert the specific filter for our MAC address, to try and
1587 * ensure we get that traffic.
1589 * (If the filter for our MAC address has already been inserted by
1590 * another function, we won't receive traffic sent to us, even if we
1591 * insert a unicast mismatch filter. To prevent traffic stealing, this
1592 * therefore relies on the privilege model only allowing functions to
1593 * insert filters for their own MAC address unless explicitly given
1594 * additional privileges by the user. This also means that, even on a
1595 * priviliged function, inserting a unicast mismatch filter may not
1596 * catch all traffic in multi PCI function scenarios.)
1598 table->eft_unicst_filter_count = 0;
1599 rc = ef10_filter_insert_unicast(enp, mac_addr, filter_flags);
1600 if (all_unicst || (rc != 0)) {
1601 all_unicst_rc = ef10_filter_insert_all_unicast(enp,
1603 if ((rc != 0) && (all_unicst_rc != 0))
1608 * WORKAROUND_BUG26807 controls firmware support for chained multicast
1609 * filters, and can only be enabled or disabled when the hardware filter
1612 * Chained multicast filters require support from the datapath firmware,
1613 * and may not be available (e.g. low-latency variants or old Huntington
1616 * Firmware will reset (FLR) functions which have inserted filters in
1617 * the hardware filter table when the workaround is enabled/disabled.
1618 * Functions without any hardware filters are not reset.
1620 * Re-check if the workaround is enabled after adding unicast hardware
1621 * filters. This ensures that encp->enc_bug26807_workaround matches the
1622 * firmware state, and that later changes to enable/disable the
1623 * workaround will result in this function seeing a reset (FLR).
1625 * In common-code drivers, we only support multiple PCI function
1626 * scenarios with firmware that supports multicast chaining, so we can
1627 * assume it is enabled for such cases and hence simplify the filter
1628 * insertion logic. Firmware that does not support multicast chaining
1629 * does not support multiple PCI function configurations either, so
1630 * filter insertion is much simpler and the same strategies can still be
1633 if ((rc = ef10_filter_get_workarounds(enp)) != 0)
1636 if ((table->eft_using_all_mulcst != all_mulcst) &&
1637 (encp->enc_bug26807_workaround == B_TRUE)) {
1639 * Multicast filter chaining is enabled, so traffic that matches
1640 * more than one multicast filter will be replicated and
1641 * delivered to multiple recipients. To avoid this duplicate
1642 * delivery, remove old multicast filters before inserting new
1643 * multicast filters.
1645 ef10_filter_remove_old(enp);
1648 /* Insert or renew multicast filters */
1649 if (all_mulcst == B_TRUE) {
1651 * Insert the all multicast filter. If that fails, try to insert
1652 * all of our multicast filters (but without rollback on
1655 all_mulcst_rc = ef10_filter_insert_all_multicast(enp,
1657 if (all_mulcst_rc != 0) {
1658 rc = ef10_filter_insert_multicast_list(enp, B_TRUE,
1659 brdcst, addrs, count, filter_flags, B_FALSE);
1665 * Insert filters for multicast addresses.
1666 * If any insertion fails, then rollback and try to insert the
1667 * all multicast filter instead.
1668 * If that also fails, try to insert all of the multicast
1669 * filters (but without rollback on failure).
1671 rc = ef10_filter_insert_multicast_list(enp, mulcst, brdcst,
1672 addrs, count, filter_flags, B_TRUE);
1674 if ((table->eft_using_all_mulcst == B_FALSE) &&
1675 (encp->enc_bug26807_workaround == B_TRUE)) {
1677 * Multicast filter chaining is on, so remove
1678 * old filters before inserting the multicast
1679 * all filter to avoid duplicate delivery caused
1680 * by packets matching multiple filters.
1682 ef10_filter_remove_old(enp);
1685 rc = ef10_filter_insert_all_multicast(enp,
1688 rc = ef10_filter_insert_multicast_list(enp,
1690 addrs, count, filter_flags, B_FALSE);
1697 if (encp->enc_tunnel_encapsulations_supported != 0) {
1698 /* Try to insert filters for encapsulated packets. */
1699 (void) ef10_filter_insert_encap_filters(enp,
1700 mulcst || all_mulcst || brdcst,
1704 /* Remove old filters which were not renewed */
1705 ef10_filter_remove_old(enp);
1707 /* report if any optional flags were rejected */
1708 if (((all_unicst != B_FALSE) && (all_unicst_rc != 0)) ||
1709 ((all_mulcst != B_FALSE) && (all_mulcst_rc != 0))) {
1722 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1724 /* Clear auto old flags */
1725 for (i = 0; i < EFX_ARRAY_SIZE(table->eft_entry); i++) {
1726 if (ef10_filter_entry_is_auto_old(table, i)) {
1727 ef10_filter_set_entry_not_auto_old(table, i);
1735 ef10_filter_get_default_rxq(
1736 __in efx_nic_t *enp,
1737 __out efx_rxq_t **erpp,
1738 __out boolean_t *using_rss)
1740 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
1742 *erpp = table->eft_default_rxq;
1743 *using_rss = table->eft_using_rss;
1748 ef10_filter_default_rxq_set(
1749 __in efx_nic_t *enp,
1750 __in efx_rxq_t *erp,
1751 __in boolean_t using_rss)
1753 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
1755 #if EFSYS_OPT_RX_SCALE
1756 EFSYS_ASSERT((using_rss == B_FALSE) ||
1757 (enp->en_rss_context != EF10_RSS_CONTEXT_INVALID));
1758 table->eft_using_rss = using_rss;
1760 EFSYS_ASSERT(using_rss == B_FALSE);
1761 table->eft_using_rss = B_FALSE;
1763 table->eft_default_rxq = erp;
1767 ef10_filter_default_rxq_clear(
1768 __in efx_nic_t *enp)
1770 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
1772 table->eft_default_rxq = NULL;
1773 table->eft_using_rss = B_FALSE;
1777 #endif /* EFSYS_OPT_FILTER */
1779 #endif /* EFSYS_OPT_HUNTINGTON || EFSYS_OPT_MEDFORD || EFSYS_OPT_MEDFORD2 */