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 EFX_MCDI_DECLARE_BUF(payload, MC_CMD_FILTER_OP_V3_IN_LEN,
176 MC_CMD_FILTER_OP_EXT_OUT_LEN);
177 efx_filter_match_flags_t match_flags;
180 req.emr_cmd = MC_CMD_FILTER_OP;
181 req.emr_in_buf = payload;
182 req.emr_in_length = MC_CMD_FILTER_OP_V3_IN_LEN;
183 req.emr_out_buf = payload;
184 req.emr_out_length = MC_CMD_FILTER_OP_EXT_OUT_LEN;
187 * Remove match flag for encapsulated filters that does not correspond
188 * to the MCDI match flags
190 match_flags = spec->efs_match_flags & ~EFX_FILTER_MATCH_ENCAP_TYPE;
193 case MC_CMD_FILTER_OP_IN_OP_REPLACE:
194 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_HANDLE_LO,
196 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_HANDLE_HI,
199 case MC_CMD_FILTER_OP_IN_OP_INSERT:
200 case MC_CMD_FILTER_OP_IN_OP_SUBSCRIBE:
201 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_OP, filter_op);
209 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_PORT_ID,
210 EVB_PORT_ID_ASSIGNED);
211 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_MATCH_FIELDS,
213 if (spec->efs_dmaq_id == EFX_FILTER_SPEC_RX_DMAQ_ID_DROP) {
214 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_RX_DEST,
215 MC_CMD_FILTER_OP_EXT_IN_RX_DEST_DROP);
217 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_RX_DEST,
218 MC_CMD_FILTER_OP_EXT_IN_RX_DEST_HOST);
219 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_RX_QUEUE,
223 #if EFSYS_OPT_RX_SCALE
224 if (spec->efs_flags & EFX_FILTER_FLAG_RX_RSS) {
225 uint32_t rss_context;
227 if (spec->efs_rss_context == EFX_RSS_CONTEXT_DEFAULT)
228 rss_context = enp->en_rss_context;
230 rss_context = spec->efs_rss_context;
231 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_RX_CONTEXT,
236 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_RX_MODE,
237 spec->efs_flags & EFX_FILTER_FLAG_RX_RSS ?
238 MC_CMD_FILTER_OP_EXT_IN_RX_MODE_RSS :
239 MC_CMD_FILTER_OP_EXT_IN_RX_MODE_SIMPLE);
240 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_TX_DEST,
241 MC_CMD_FILTER_OP_EXT_IN_TX_DEST_DEFAULT);
243 if (filter_op != MC_CMD_FILTER_OP_IN_OP_REPLACE) {
245 * NOTE: Unlike most MCDI requests, the filter fields
246 * are presented in network (big endian) byte order.
248 memcpy(MCDI_IN2(req, uint8_t, FILTER_OP_EXT_IN_SRC_MAC),
249 spec->efs_rem_mac, EFX_MAC_ADDR_LEN);
250 memcpy(MCDI_IN2(req, uint8_t, FILTER_OP_EXT_IN_DST_MAC),
251 spec->efs_loc_mac, EFX_MAC_ADDR_LEN);
253 MCDI_IN_SET_WORD(req, FILTER_OP_EXT_IN_SRC_PORT,
254 __CPU_TO_BE_16(spec->efs_rem_port));
255 MCDI_IN_SET_WORD(req, FILTER_OP_EXT_IN_DST_PORT,
256 __CPU_TO_BE_16(spec->efs_loc_port));
258 MCDI_IN_SET_WORD(req, FILTER_OP_EXT_IN_ETHER_TYPE,
259 __CPU_TO_BE_16(spec->efs_ether_type));
261 MCDI_IN_SET_WORD(req, FILTER_OP_EXT_IN_INNER_VLAN,
262 __CPU_TO_BE_16(spec->efs_inner_vid));
263 MCDI_IN_SET_WORD(req, FILTER_OP_EXT_IN_OUTER_VLAN,
264 __CPU_TO_BE_16(spec->efs_outer_vid));
266 /* IP protocol (in low byte, high byte is zero) */
267 MCDI_IN_SET_BYTE(req, FILTER_OP_EXT_IN_IP_PROTO,
270 EFX_STATIC_ASSERT(sizeof (spec->efs_rem_host) ==
271 MC_CMD_FILTER_OP_EXT_IN_SRC_IP_LEN);
272 EFX_STATIC_ASSERT(sizeof (spec->efs_loc_host) ==
273 MC_CMD_FILTER_OP_EXT_IN_DST_IP_LEN);
275 memcpy(MCDI_IN2(req, uint8_t, FILTER_OP_EXT_IN_SRC_IP),
276 &spec->efs_rem_host.eo_byte[0],
277 MC_CMD_FILTER_OP_EXT_IN_SRC_IP_LEN);
278 memcpy(MCDI_IN2(req, uint8_t, FILTER_OP_EXT_IN_DST_IP),
279 &spec->efs_loc_host.eo_byte[0],
280 MC_CMD_FILTER_OP_EXT_IN_DST_IP_LEN);
283 * On Medford, filters for encapsulated packets match based on
284 * the ether type and IP protocol in the outer frame. In
285 * addition we need to fill in the VNI or VSID type field.
287 switch (spec->efs_encap_type) {
288 case EFX_TUNNEL_PROTOCOL_NONE:
290 case EFX_TUNNEL_PROTOCOL_VXLAN:
291 case EFX_TUNNEL_PROTOCOL_GENEVE:
292 MCDI_IN_POPULATE_DWORD_1(req,
293 FILTER_OP_EXT_IN_VNI_OR_VSID,
294 FILTER_OP_EXT_IN_VNI_TYPE,
295 spec->efs_encap_type == EFX_TUNNEL_PROTOCOL_VXLAN ?
296 MC_CMD_FILTER_OP_EXT_IN_VNI_TYPE_VXLAN :
297 MC_CMD_FILTER_OP_EXT_IN_VNI_TYPE_GENEVE);
299 case EFX_TUNNEL_PROTOCOL_NVGRE:
300 MCDI_IN_POPULATE_DWORD_1(req,
301 FILTER_OP_EXT_IN_VNI_OR_VSID,
302 FILTER_OP_EXT_IN_VSID_TYPE,
303 MC_CMD_FILTER_OP_EXT_IN_VSID_TYPE_NVGRE);
311 memcpy(MCDI_IN2(req, uint8_t, FILTER_OP_EXT_IN_VNI_OR_VSID),
312 spec->efs_vni_or_vsid, EFX_VNI_OR_VSID_LEN);
314 memcpy(MCDI_IN2(req, uint8_t, FILTER_OP_EXT_IN_IFRM_DST_MAC),
315 spec->efs_ifrm_loc_mac, EFX_MAC_ADDR_LEN);
319 * Set the "MARK" or "FLAG" action for all packets matching this filter
320 * if necessary (only useful with equal stride packed stream Rx mode
321 * which provide the information in pseudo-header).
322 * These actions require MC_CMD_FILTER_OP_V3_IN msgrequest.
324 if ((spec->efs_flags & EFX_FILTER_FLAG_ACTION_MARK) &&
325 (spec->efs_flags & EFX_FILTER_FLAG_ACTION_FLAG)) {
329 if (spec->efs_flags & EFX_FILTER_FLAG_ACTION_MARK) {
330 MCDI_IN_SET_DWORD(req, FILTER_OP_V3_IN_MATCH_ACTION,
331 MC_CMD_FILTER_OP_V3_IN_MATCH_ACTION_MARK);
332 MCDI_IN_SET_DWORD(req, FILTER_OP_V3_IN_MATCH_MARK_VALUE,
334 } else if (spec->efs_flags & EFX_FILTER_FLAG_ACTION_FLAG) {
335 MCDI_IN_SET_DWORD(req, FILTER_OP_V3_IN_MATCH_ACTION,
336 MC_CMD_FILTER_OP_V3_IN_MATCH_ACTION_FLAG);
339 efx_mcdi_execute(enp, &req);
341 if (req.emr_rc != 0) {
346 if (req.emr_out_length_used < MC_CMD_FILTER_OP_EXT_OUT_LEN) {
351 handle->efh_lo = MCDI_OUT_DWORD(req, FILTER_OP_EXT_OUT_HANDLE_LO);
352 handle->efh_hi = MCDI_OUT_DWORD(req, FILTER_OP_EXT_OUT_HANDLE_HI);
365 EFSYS_PROBE1(fail1, efx_rc_t, rc);
371 static __checkReturn efx_rc_t
372 efx_mcdi_filter_op_delete(
374 __in unsigned int filter_op,
375 __inout ef10_filter_handle_t *handle)
378 EFX_MCDI_DECLARE_BUF(payload, MC_CMD_FILTER_OP_EXT_IN_LEN,
379 MC_CMD_FILTER_OP_EXT_OUT_LEN);
382 req.emr_cmd = MC_CMD_FILTER_OP;
383 req.emr_in_buf = payload;
384 req.emr_in_length = MC_CMD_FILTER_OP_EXT_IN_LEN;
385 req.emr_out_buf = payload;
386 req.emr_out_length = MC_CMD_FILTER_OP_EXT_OUT_LEN;
389 case MC_CMD_FILTER_OP_IN_OP_REMOVE:
390 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_OP,
391 MC_CMD_FILTER_OP_IN_OP_REMOVE);
393 case MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE:
394 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_OP,
395 MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE);
403 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_HANDLE_LO, handle->efh_lo);
404 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_HANDLE_HI, handle->efh_hi);
406 efx_mcdi_execute_quiet(enp, &req);
408 if (req.emr_rc != 0) {
413 if (req.emr_out_length_used < MC_CMD_FILTER_OP_EXT_OUT_LEN) {
426 EFSYS_PROBE1(fail1, efx_rc_t, rc);
431 static __checkReturn boolean_t
433 __in const efx_filter_spec_t *left,
434 __in const efx_filter_spec_t *right)
436 /* FIXME: Consider rx vs tx filters (look at efs_flags) */
437 if (left->efs_match_flags != right->efs_match_flags)
439 if (!EFX_OWORD_IS_EQUAL(left->efs_rem_host, right->efs_rem_host))
441 if (!EFX_OWORD_IS_EQUAL(left->efs_loc_host, right->efs_loc_host))
443 if (memcmp(left->efs_rem_mac, right->efs_rem_mac, EFX_MAC_ADDR_LEN))
445 if (memcmp(left->efs_loc_mac, right->efs_loc_mac, EFX_MAC_ADDR_LEN))
447 if (left->efs_rem_port != right->efs_rem_port)
449 if (left->efs_loc_port != right->efs_loc_port)
451 if (left->efs_inner_vid != right->efs_inner_vid)
453 if (left->efs_outer_vid != right->efs_outer_vid)
455 if (left->efs_ether_type != right->efs_ether_type)
457 if (left->efs_ip_proto != right->efs_ip_proto)
459 if (left->efs_encap_type != right->efs_encap_type)
461 if (memcmp(left->efs_vni_or_vsid, right->efs_vni_or_vsid,
462 EFX_VNI_OR_VSID_LEN))
464 if (memcmp(left->efs_ifrm_loc_mac, right->efs_ifrm_loc_mac,
472 static __checkReturn boolean_t
473 ef10_filter_same_dest(
474 __in const efx_filter_spec_t *left,
475 __in const efx_filter_spec_t *right)
477 if ((left->efs_flags & EFX_FILTER_FLAG_RX_RSS) &&
478 (right->efs_flags & EFX_FILTER_FLAG_RX_RSS)) {
479 if (left->efs_rss_context == right->efs_rss_context)
481 } else if ((~(left->efs_flags) & EFX_FILTER_FLAG_RX_RSS) &&
482 (~(right->efs_flags) & EFX_FILTER_FLAG_RX_RSS)) {
483 if (left->efs_dmaq_id == right->efs_dmaq_id)
489 static __checkReturn uint32_t
491 __in efx_filter_spec_t *spec)
493 EFX_STATIC_ASSERT((sizeof (efx_filter_spec_t) % sizeof (uint32_t))
495 EFX_STATIC_ASSERT((EFX_FIELD_OFFSET(efx_filter_spec_t, efs_outer_vid) %
496 sizeof (uint32_t)) == 0);
499 * As the area of the efx_filter_spec_t we need to hash is DWORD
500 * aligned and an exact number of DWORDs in size we can use the
501 * optimised efx_hash_dwords() rather than efx_hash_bytes()
503 return (efx_hash_dwords((const uint32_t *)&spec->efs_outer_vid,
504 (sizeof (efx_filter_spec_t) -
505 EFX_FIELD_OFFSET(efx_filter_spec_t, efs_outer_vid)) /
506 sizeof (uint32_t), 0));
510 * Decide whether a filter should be exclusive or else should allow
511 * delivery to additional recipients. Currently we decide that
512 * filters for specific local unicast MAC and IP addresses are
515 static __checkReturn boolean_t
516 ef10_filter_is_exclusive(
517 __in efx_filter_spec_t *spec)
519 if ((spec->efs_match_flags & EFX_FILTER_MATCH_LOC_MAC) &&
520 !EFX_MAC_ADDR_IS_MULTICAST(spec->efs_loc_mac))
523 if ((spec->efs_match_flags &
524 (EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_LOC_HOST)) ==
525 (EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_LOC_HOST)) {
526 if ((spec->efs_ether_type == EFX_ETHER_TYPE_IPV4) &&
527 ((spec->efs_loc_host.eo_u8[0] & 0xf) != 0xe))
529 if ((spec->efs_ether_type == EFX_ETHER_TYPE_IPV6) &&
530 (spec->efs_loc_host.eo_u8[0] != 0xff))
537 __checkReturn efx_rc_t
542 efx_filter_spec_t *spec;
543 ef10_filter_table_t *eftp = enp->en_filter.ef_ef10_filter_table;
545 efsys_lock_state_t state;
548 EFSYS_ASSERT(enp->en_family == EFX_FAMILY_HUNTINGTON ||
549 enp->en_family == EFX_FAMILY_MEDFORD ||
550 enp->en_family == EFX_FAMILY_MEDFORD2);
552 for (tbl_id = 0; tbl_id < EFX_EF10_FILTER_TBL_ROWS; tbl_id++) {
554 EFSYS_LOCK(enp->en_eslp, state);
556 spec = ef10_filter_entry_spec(eftp, tbl_id);
559 } else if (ef10_filter_entry_is_busy(eftp, tbl_id)) {
560 /* Ignore busy entries. */
563 ef10_filter_set_entry_busy(eftp, tbl_id);
567 EFSYS_UNLOCK(enp->en_eslp, state);
569 if (restoring == B_FALSE)
572 if (ef10_filter_is_exclusive(spec)) {
573 rc = efx_mcdi_filter_op_add(enp, spec,
574 MC_CMD_FILTER_OP_IN_OP_INSERT,
575 &eftp->eft_entry[tbl_id].efe_handle);
577 rc = efx_mcdi_filter_op_add(enp, spec,
578 MC_CMD_FILTER_OP_IN_OP_SUBSCRIBE,
579 &eftp->eft_entry[tbl_id].efe_handle);
585 EFSYS_LOCK(enp->en_eslp, state);
587 ef10_filter_set_entry_not_busy(eftp, tbl_id);
589 EFSYS_UNLOCK(enp->en_eslp, state);
595 EFSYS_PROBE1(fail1, efx_rc_t, rc);
601 * An arbitrary search limit for the software hash table. As per the linux net
604 #define EF10_FILTER_SEARCH_LIMIT 200
606 static __checkReturn efx_rc_t
607 ef10_filter_add_internal(
609 __inout efx_filter_spec_t *spec,
610 __in boolean_t may_replace,
611 __out_opt uint32_t *filter_id)
614 ef10_filter_table_t *eftp = enp->en_filter.ef_ef10_filter_table;
615 efx_filter_spec_t *saved_spec;
619 boolean_t replacing = B_FALSE;
621 efsys_lock_state_t state;
622 boolean_t locked = B_FALSE;
624 EFSYS_ASSERT(enp->en_family == EFX_FAMILY_HUNTINGTON ||
625 enp->en_family == EFX_FAMILY_MEDFORD ||
626 enp->en_family == EFX_FAMILY_MEDFORD2);
628 hash = ef10_filter_hash(spec);
631 * FIXME: Add support for inserting filters of different priorities
632 * and removing lower priority multicast filters (bug 42378)
636 * Find any existing filters with the same match tuple or
637 * else a free slot to insert at. If any of them are busy,
638 * we have to wait and retry.
643 EFSYS_LOCK(enp->en_eslp, state);
647 i = (hash + depth) & (EFX_EF10_FILTER_TBL_ROWS - 1);
648 saved_spec = ef10_filter_entry_spec(eftp, i);
654 } else if (ef10_filter_equal(spec, saved_spec)) {
655 if (ef10_filter_entry_is_busy(eftp, i))
657 if (saved_spec->efs_priority
658 == EFX_FILTER_PRI_AUTO) {
661 } else if (ef10_filter_is_exclusive(spec)) {
675 * Once we reach the maximum search depth, use
676 * the first suitable slot or return EBUSY if
679 if (depth == EF10_FILTER_SEARCH_LIMIT) {
688 EFSYS_UNLOCK(enp->en_eslp, state);
694 * Create a software table entry if necessary, and mark it
695 * busy. We might yet fail to insert, but any attempt to
696 * insert a conflicting filter while we're waiting for the
697 * firmware must find the busy entry.
699 saved_spec = ef10_filter_entry_spec(eftp, ins_index);
701 if (saved_spec->efs_priority == EFX_FILTER_PRI_AUTO) {
702 /* This is a filter we are refreshing */
703 ef10_filter_set_entry_not_auto_old(eftp, ins_index);
709 EFSYS_KMEM_ALLOC(enp->en_esip, sizeof (*spec), saved_spec);
715 ef10_filter_set_entry(eftp, ins_index, saved_spec);
717 ef10_filter_set_entry_busy(eftp, ins_index);
719 EFSYS_UNLOCK(enp->en_eslp, state);
723 * On replacing the filter handle may change after after a successful
727 rc = efx_mcdi_filter_op_add(enp, spec,
728 MC_CMD_FILTER_OP_IN_OP_REPLACE,
729 &eftp->eft_entry[ins_index].efe_handle);
730 } else if (ef10_filter_is_exclusive(spec)) {
731 rc = efx_mcdi_filter_op_add(enp, spec,
732 MC_CMD_FILTER_OP_IN_OP_INSERT,
733 &eftp->eft_entry[ins_index].efe_handle);
735 rc = efx_mcdi_filter_op_add(enp, spec,
736 MC_CMD_FILTER_OP_IN_OP_SUBSCRIBE,
737 &eftp->eft_entry[ins_index].efe_handle);
743 EFSYS_LOCK(enp->en_eslp, state);
747 /* Update the fields that may differ */
748 saved_spec->efs_priority = spec->efs_priority;
749 saved_spec->efs_flags = spec->efs_flags;
750 saved_spec->efs_rss_context = spec->efs_rss_context;
751 saved_spec->efs_dmaq_id = spec->efs_dmaq_id;
754 ef10_filter_set_entry_not_busy(eftp, ins_index);
758 EFSYS_UNLOCK(enp->en_eslp, state);
762 *filter_id = ins_index;
770 EFSYS_KMEM_FREE(enp->en_esip, sizeof (*spec), saved_spec);
773 ef10_filter_set_entry_not_busy(eftp, ins_index);
774 ef10_filter_set_entry(eftp, ins_index, NULL);
783 EFSYS_PROBE1(fail1, efx_rc_t, rc);
786 EFSYS_UNLOCK(enp->en_eslp, state);
791 __checkReturn efx_rc_t
794 __inout efx_filter_spec_t *spec,
795 __in boolean_t may_replace)
799 rc = ef10_filter_add_internal(enp, spec, may_replace, NULL);
806 EFSYS_PROBE1(fail1, efx_rc_t, rc);
812 static __checkReturn efx_rc_t
813 ef10_filter_delete_internal(
815 __in uint32_t filter_id)
818 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
819 efx_filter_spec_t *spec;
820 efsys_lock_state_t state;
821 uint32_t filter_idx = filter_id % EFX_EF10_FILTER_TBL_ROWS;
824 * Find the software table entry and mark it busy. Don't
825 * remove it yet; any attempt to update while we're waiting
826 * for the firmware must find the busy entry.
828 * FIXME: What if the busy flag is never cleared?
830 EFSYS_LOCK(enp->en_eslp, state);
831 while (ef10_filter_entry_is_busy(table, filter_idx)) {
832 EFSYS_UNLOCK(enp->en_eslp, state);
834 EFSYS_LOCK(enp->en_eslp, state);
836 if ((spec = ef10_filter_entry_spec(table, filter_idx)) != NULL) {
837 ef10_filter_set_entry_busy(table, filter_idx);
839 EFSYS_UNLOCK(enp->en_eslp, state);
847 * Try to remove the hardware filter. This may fail if the MC has
848 * rebooted (which frees all hardware filter resources).
850 if (ef10_filter_is_exclusive(spec)) {
851 rc = efx_mcdi_filter_op_delete(enp,
852 MC_CMD_FILTER_OP_IN_OP_REMOVE,
853 &table->eft_entry[filter_idx].efe_handle);
855 rc = efx_mcdi_filter_op_delete(enp,
856 MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE,
857 &table->eft_entry[filter_idx].efe_handle);
860 /* Free the software table entry */
861 EFSYS_LOCK(enp->en_eslp, state);
862 ef10_filter_set_entry_not_busy(table, filter_idx);
863 ef10_filter_set_entry(table, filter_idx, NULL);
864 EFSYS_UNLOCK(enp->en_eslp, state);
866 EFSYS_KMEM_FREE(enp->en_esip, sizeof (*spec), spec);
868 /* Check result of hardware filter removal */
878 EFSYS_PROBE1(fail1, efx_rc_t, rc);
883 __checkReturn efx_rc_t
886 __inout efx_filter_spec_t *spec)
889 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
890 efx_filter_spec_t *saved_spec;
894 efsys_lock_state_t state;
895 boolean_t locked = B_FALSE;
897 EFSYS_ASSERT(enp->en_family == EFX_FAMILY_HUNTINGTON ||
898 enp->en_family == EFX_FAMILY_MEDFORD ||
899 enp->en_family == EFX_FAMILY_MEDFORD2);
901 hash = ef10_filter_hash(spec);
903 EFSYS_LOCK(enp->en_eslp, state);
908 i = (hash + depth) & (EFX_EF10_FILTER_TBL_ROWS - 1);
909 saved_spec = ef10_filter_entry_spec(table, i);
910 if (saved_spec && ef10_filter_equal(spec, saved_spec) &&
911 ef10_filter_same_dest(spec, saved_spec)) {
914 if (depth == EF10_FILTER_SEARCH_LIMIT) {
921 EFSYS_UNLOCK(enp->en_eslp, state);
924 rc = ef10_filter_delete_internal(enp, i);
934 EFSYS_PROBE1(fail1, efx_rc_t, rc);
937 EFSYS_UNLOCK(enp->en_eslp, state);
942 static __checkReturn efx_rc_t
943 efx_mcdi_get_parser_disp_info(
945 __out_ecount(buffer_length) uint32_t *buffer,
946 __in size_t buffer_length,
947 __in boolean_t encap,
948 __out size_t *list_lengthp)
951 EFX_MCDI_DECLARE_BUF(payload, MC_CMD_GET_PARSER_DISP_INFO_IN_LEN,
952 MC_CMD_GET_PARSER_DISP_INFO_OUT_LENMAX);
953 size_t matches_count;
957 req.emr_cmd = MC_CMD_GET_PARSER_DISP_INFO;
958 req.emr_in_buf = payload;
959 req.emr_in_length = MC_CMD_GET_PARSER_DISP_INFO_IN_LEN;
960 req.emr_out_buf = payload;
961 req.emr_out_length = MC_CMD_GET_PARSER_DISP_INFO_OUT_LENMAX;
963 MCDI_IN_SET_DWORD(req, GET_PARSER_DISP_INFO_OUT_OP, encap ?
964 MC_CMD_GET_PARSER_DISP_INFO_IN_OP_GET_SUPPORTED_ENCAP_RX_MATCHES :
965 MC_CMD_GET_PARSER_DISP_INFO_IN_OP_GET_SUPPORTED_RX_MATCHES);
967 efx_mcdi_execute(enp, &req);
969 if (req.emr_rc != 0) {
974 matches_count = MCDI_OUT_DWORD(req,
975 GET_PARSER_DISP_INFO_OUT_NUM_SUPPORTED_MATCHES);
977 if (req.emr_out_length_used <
978 MC_CMD_GET_PARSER_DISP_INFO_OUT_LEN(matches_count)) {
983 *list_lengthp = matches_count;
985 if (buffer_length < matches_count) {
991 * Check that the elements in the list in the MCDI response are the size
992 * we expect, so we can just copy them directly. Any conversion of the
993 * flags is handled by the caller.
995 EFX_STATIC_ASSERT(sizeof (uint32_t) ==
996 MC_CMD_GET_PARSER_DISP_INFO_OUT_SUPPORTED_MATCHES_LEN);
998 list_size = matches_count *
999 MC_CMD_GET_PARSER_DISP_INFO_OUT_SUPPORTED_MATCHES_LEN;
1001 MCDI_OUT2(req, uint32_t,
1002 GET_PARSER_DISP_INFO_OUT_SUPPORTED_MATCHES),
1012 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1017 __checkReturn efx_rc_t
1018 ef10_filter_supported_filters(
1019 __in efx_nic_t *enp,
1020 __out_ecount(buffer_length) uint32_t *buffer,
1021 __in size_t buffer_length,
1022 __out size_t *list_lengthp)
1024 efx_nic_cfg_t *encp = &(enp->en_nic_cfg);
1025 size_t mcdi_list_length;
1026 size_t mcdi_encap_list_length;
1029 uint32_t next_buf_idx;
1030 size_t next_buf_length;
1032 boolean_t no_space = B_FALSE;
1033 efx_filter_match_flags_t all_filter_flags =
1034 (EFX_FILTER_MATCH_REM_HOST | EFX_FILTER_MATCH_LOC_HOST |
1035 EFX_FILTER_MATCH_REM_MAC | EFX_FILTER_MATCH_REM_PORT |
1036 EFX_FILTER_MATCH_LOC_MAC | EFX_FILTER_MATCH_LOC_PORT |
1037 EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_INNER_VID |
1038 EFX_FILTER_MATCH_OUTER_VID | EFX_FILTER_MATCH_IP_PROTO |
1039 EFX_FILTER_MATCH_VNI_OR_VSID |
1040 EFX_FILTER_MATCH_IFRM_LOC_MAC |
1041 EFX_FILTER_MATCH_IFRM_UNKNOWN_MCAST_DST |
1042 EFX_FILTER_MATCH_IFRM_UNKNOWN_UCAST_DST |
1043 EFX_FILTER_MATCH_ENCAP_TYPE |
1044 EFX_FILTER_MATCH_UNKNOWN_MCAST_DST |
1045 EFX_FILTER_MATCH_UNKNOWN_UCAST_DST);
1048 * Two calls to MC_CMD_GET_PARSER_DISP_INFO are needed: one to get the
1049 * list of supported filters for ordinary packets, and then another to
1050 * get the list of supported filters for encapsulated packets. To
1051 * distinguish the second list from the first, the
1052 * EFX_FILTER_MATCH_ENCAP_TYPE flag is added to each filter for
1053 * encapsulated packets.
1055 rc = efx_mcdi_get_parser_disp_info(enp, buffer, buffer_length, B_FALSE,
1066 next_buf_length = 0;
1068 EFSYS_ASSERT(mcdi_list_length <= buffer_length);
1069 next_buf_idx = mcdi_list_length;
1070 next_buf_length = buffer_length - mcdi_list_length;
1073 if (encp->enc_tunnel_encapsulations_supported != 0) {
1074 rc = efx_mcdi_get_parser_disp_info(enp, &buffer[next_buf_idx],
1075 next_buf_length, B_TRUE, &mcdi_encap_list_length);
1082 for (i = next_buf_idx;
1083 i < next_buf_idx + mcdi_encap_list_length; i++)
1084 buffer[i] |= EFX_FILTER_MATCH_ENCAP_TYPE;
1087 mcdi_encap_list_length = 0;
1091 *list_lengthp = mcdi_list_length + mcdi_encap_list_length;
1097 * The static assertions in ef10_filter_init() ensure that the values of
1098 * the EFX_FILTER_MATCH flags match those used by MCDI, so they don't
1099 * need to be converted.
1101 * In case support is added to MCDI for additional flags, remove any
1102 * matches from the list which include flags we don't support. The order
1103 * of the matches is preserved as they are ordered from highest to
1106 EFSYS_ASSERT(mcdi_list_length + mcdi_encap_list_length <=
1109 for (i = 0; i < mcdi_list_length + mcdi_encap_list_length; i++) {
1110 if ((buffer[i] & ~all_filter_flags) == 0) {
1111 buffer[list_length] = buffer[i];
1116 *list_lengthp = list_length;
1125 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1130 static __checkReturn efx_rc_t
1131 ef10_filter_insert_unicast(
1132 __in efx_nic_t *enp,
1133 __in_ecount(6) uint8_t const *addr,
1134 __in efx_filter_flags_t filter_flags)
1136 ef10_filter_table_t *eftp = enp->en_filter.ef_ef10_filter_table;
1137 efx_filter_spec_t spec;
1140 /* Insert the filter for the local station address */
1141 efx_filter_spec_init_rx(&spec, EFX_FILTER_PRI_AUTO,
1143 eftp->eft_default_rxq);
1144 rc = efx_filter_spec_set_eth_local(&spec, EFX_FILTER_SPEC_VID_UNSPEC,
1149 rc = ef10_filter_add_internal(enp, &spec, B_TRUE,
1150 &eftp->eft_unicst_filter_indexes[eftp->eft_unicst_filter_count]);
1154 eftp->eft_unicst_filter_count++;
1155 EFSYS_ASSERT(eftp->eft_unicst_filter_count <=
1156 EFX_EF10_FILTER_UNICAST_FILTERS_MAX);
1163 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1167 static __checkReturn efx_rc_t
1168 ef10_filter_insert_all_unicast(
1169 __in efx_nic_t *enp,
1170 __in efx_filter_flags_t filter_flags)
1172 ef10_filter_table_t *eftp = enp->en_filter.ef_ef10_filter_table;
1173 efx_filter_spec_t spec;
1176 /* Insert the unknown unicast filter */
1177 efx_filter_spec_init_rx(&spec, EFX_FILTER_PRI_AUTO,
1179 eftp->eft_default_rxq);
1180 rc = efx_filter_spec_set_uc_def(&spec);
1183 rc = ef10_filter_add_internal(enp, &spec, B_TRUE,
1184 &eftp->eft_unicst_filter_indexes[eftp->eft_unicst_filter_count]);
1188 eftp->eft_unicst_filter_count++;
1189 EFSYS_ASSERT(eftp->eft_unicst_filter_count <=
1190 EFX_EF10_FILTER_UNICAST_FILTERS_MAX);
1197 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1201 static __checkReturn efx_rc_t
1202 ef10_filter_insert_multicast_list(
1203 __in efx_nic_t *enp,
1204 __in boolean_t mulcst,
1205 __in boolean_t brdcst,
1206 __in_ecount(6*count) uint8_t const *addrs,
1207 __in uint32_t count,
1208 __in efx_filter_flags_t filter_flags,
1209 __in boolean_t rollback)
1211 ef10_filter_table_t *eftp = enp->en_filter.ef_ef10_filter_table;
1212 efx_filter_spec_t spec;
1215 uint32_t filter_index;
1216 uint32_t filter_count;
1219 if (mulcst == B_FALSE)
1222 if (count + (brdcst ? 1 : 0) >
1223 EFX_ARRAY_SIZE(eftp->eft_mulcst_filter_indexes)) {
1224 /* Too many MAC addresses */
1229 /* Insert/renew multicast address list filters */
1231 for (i = 0; i < count; i++) {
1232 efx_filter_spec_init_rx(&spec,
1233 EFX_FILTER_PRI_AUTO,
1235 eftp->eft_default_rxq);
1237 rc = efx_filter_spec_set_eth_local(&spec,
1238 EFX_FILTER_SPEC_VID_UNSPEC,
1239 &addrs[i * EFX_MAC_ADDR_LEN]);
1241 if (rollback == B_TRUE) {
1242 /* Only stop upon failure if told to rollback */
1246 * Don't try to add a filter with a corrupt
1253 rc = ef10_filter_add_internal(enp, &spec, B_TRUE,
1257 eftp->eft_mulcst_filter_indexes[filter_count] =
1260 } else if (rollback == B_TRUE) {
1261 /* Only stop upon failure if told to rollback */
1267 if (brdcst == B_TRUE) {
1268 /* Insert/renew broadcast address filter */
1269 efx_filter_spec_init_rx(&spec, EFX_FILTER_PRI_AUTO,
1271 eftp->eft_default_rxq);
1273 EFX_MAC_BROADCAST_ADDR_SET(addr);
1274 rc = efx_filter_spec_set_eth_local(&spec,
1275 EFX_FILTER_SPEC_VID_UNSPEC, addr);
1276 if ((rc != 0) && (rollback == B_TRUE)) {
1277 /* Only stop upon failure if told to rollback */
1281 rc = ef10_filter_add_internal(enp, &spec, B_TRUE,
1285 eftp->eft_mulcst_filter_indexes[filter_count] =
1288 } else if (rollback == B_TRUE) {
1289 /* Only stop upon failure if told to rollback */
1294 eftp->eft_mulcst_filter_count = filter_count;
1295 eftp->eft_using_all_mulcst = B_FALSE;
1300 /* Remove any filters we have inserted */
1303 (void) ef10_filter_delete_internal(enp,
1304 eftp->eft_mulcst_filter_indexes[i]);
1306 eftp->eft_mulcst_filter_count = 0;
1309 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1314 static __checkReturn efx_rc_t
1315 ef10_filter_insert_all_multicast(
1316 __in efx_nic_t *enp,
1317 __in efx_filter_flags_t filter_flags)
1319 ef10_filter_table_t *eftp = enp->en_filter.ef_ef10_filter_table;
1320 efx_filter_spec_t spec;
1323 /* Insert the unknown multicast filter */
1324 efx_filter_spec_init_rx(&spec, EFX_FILTER_PRI_AUTO,
1326 eftp->eft_default_rxq);
1327 rc = efx_filter_spec_set_mc_def(&spec);
1331 rc = ef10_filter_add_internal(enp, &spec, B_TRUE,
1332 &eftp->eft_mulcst_filter_indexes[0]);
1336 eftp->eft_mulcst_filter_count = 1;
1337 eftp->eft_using_all_mulcst = B_TRUE;
1340 * FIXME: If brdcst == B_FALSE, add a filter to drop broadcast traffic.
1348 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1353 typedef struct ef10_filter_encap_entry_s {
1354 uint16_t ether_type;
1355 efx_tunnel_protocol_t encap_type;
1356 uint32_t inner_frame_match;
1357 } ef10_filter_encap_entry_t;
1359 #define EF10_ENCAP_FILTER_ENTRY(ipv, encap_type, inner_frame_match) \
1360 { EFX_ETHER_TYPE_##ipv, EFX_TUNNEL_PROTOCOL_##encap_type, \
1361 EFX_FILTER_INNER_FRAME_MATCH_UNKNOWN_##inner_frame_match }
1363 static ef10_filter_encap_entry_t ef10_filter_encap_list[] = {
1364 EF10_ENCAP_FILTER_ENTRY(IPV4, VXLAN, UCAST_DST),
1365 EF10_ENCAP_FILTER_ENTRY(IPV4, VXLAN, MCAST_DST),
1366 EF10_ENCAP_FILTER_ENTRY(IPV6, VXLAN, UCAST_DST),
1367 EF10_ENCAP_FILTER_ENTRY(IPV6, VXLAN, MCAST_DST),
1369 EF10_ENCAP_FILTER_ENTRY(IPV4, GENEVE, UCAST_DST),
1370 EF10_ENCAP_FILTER_ENTRY(IPV4, GENEVE, MCAST_DST),
1371 EF10_ENCAP_FILTER_ENTRY(IPV6, GENEVE, UCAST_DST),
1372 EF10_ENCAP_FILTER_ENTRY(IPV6, GENEVE, MCAST_DST),
1374 EF10_ENCAP_FILTER_ENTRY(IPV4, NVGRE, UCAST_DST),
1375 EF10_ENCAP_FILTER_ENTRY(IPV4, NVGRE, MCAST_DST),
1376 EF10_ENCAP_FILTER_ENTRY(IPV6, NVGRE, UCAST_DST),
1377 EF10_ENCAP_FILTER_ENTRY(IPV6, NVGRE, MCAST_DST),
1380 #undef EF10_ENCAP_FILTER_ENTRY
1382 static __checkReturn efx_rc_t
1383 ef10_filter_insert_encap_filters(
1384 __in efx_nic_t *enp,
1385 __in boolean_t mulcst,
1386 __in efx_filter_flags_t filter_flags)
1388 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
1392 EFX_STATIC_ASSERT(EFX_ARRAY_SIZE(ef10_filter_encap_list) <=
1393 EFX_ARRAY_SIZE(table->eft_encap_filter_indexes));
1396 * On Medford, full-featured firmware can identify packets as being
1397 * tunnel encapsulated, even if no encapsulated packet offloads are in
1398 * use. When packets are identified as such, ordinary filters are not
1399 * applied, only ones specific to encapsulated packets. Hence we need to
1400 * insert filters for encapsulated packets in order to receive them.
1402 * Separate filters need to be inserted for each ether type,
1403 * encapsulation type, and inner frame type (unicast or multicast). To
1404 * keep things simple and reduce the number of filters needed, catch-all
1405 * filters for all combinations of types are inserted, even if
1406 * all_unicst or all_mulcst have not been set. (These catch-all filters
1407 * may well, however, fail to insert on unprivileged functions.)
1409 table->eft_encap_filter_count = 0;
1410 for (i = 0; i < EFX_ARRAY_SIZE(ef10_filter_encap_list); i++) {
1411 efx_filter_spec_t spec;
1412 ef10_filter_encap_entry_t *encap_filter =
1413 &ef10_filter_encap_list[i];
1416 * Skip multicast filters if we've not been asked for
1417 * any multicast traffic.
1419 if ((mulcst == B_FALSE) &&
1420 (encap_filter->inner_frame_match ==
1421 EFX_FILTER_INNER_FRAME_MATCH_UNKNOWN_MCAST_DST))
1424 efx_filter_spec_init_rx(&spec, EFX_FILTER_PRI_AUTO,
1426 table->eft_default_rxq);
1427 efx_filter_spec_set_ether_type(&spec, encap_filter->ether_type);
1428 rc = efx_filter_spec_set_encap_type(&spec,
1429 encap_filter->encap_type,
1430 encap_filter->inner_frame_match);
1434 rc = ef10_filter_add_internal(enp, &spec, B_TRUE,
1435 &table->eft_encap_filter_indexes[
1436 table->eft_encap_filter_count]);
1441 table->eft_encap_filter_count++;
1450 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1456 ef10_filter_remove_old(
1457 __in efx_nic_t *enp)
1459 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
1462 for (i = 0; i < EFX_ARRAY_SIZE(table->eft_entry); i++) {
1463 if (ef10_filter_entry_is_auto_old(table, i)) {
1464 (void) ef10_filter_delete_internal(enp, i);
1470 static __checkReturn efx_rc_t
1471 ef10_filter_get_workarounds(
1472 __in efx_nic_t *enp)
1474 efx_nic_cfg_t *encp = &enp->en_nic_cfg;
1475 uint32_t implemented = 0;
1476 uint32_t enabled = 0;
1479 rc = efx_mcdi_get_workarounds(enp, &implemented, &enabled);
1481 /* Check if chained multicast filter support is enabled */
1482 if (implemented & enabled & MC_CMD_GET_WORKAROUNDS_OUT_BUG26807)
1483 encp->enc_bug26807_workaround = B_TRUE;
1485 encp->enc_bug26807_workaround = B_FALSE;
1486 } else if (rc == ENOTSUP) {
1488 * Firmware is too old to support GET_WORKAROUNDS, and support
1489 * for this workaround was implemented later.
1491 encp->enc_bug26807_workaround = B_FALSE;
1499 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1507 * Reconfigure all filters.
1508 * If all_unicst and/or all mulcst filters cannot be applied then
1509 * return ENOTSUP (Note the filters for the specified addresses are
1510 * still applied in this case).
1512 __checkReturn efx_rc_t
1513 ef10_filter_reconfigure(
1514 __in efx_nic_t *enp,
1515 __in_ecount(6) uint8_t const *mac_addr,
1516 __in boolean_t all_unicst,
1517 __in boolean_t mulcst,
1518 __in boolean_t all_mulcst,
1519 __in boolean_t brdcst,
1520 __in_ecount(6*count) uint8_t const *addrs,
1521 __in uint32_t count)
1523 efx_nic_cfg_t *encp = &enp->en_nic_cfg;
1524 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
1525 efx_filter_flags_t filter_flags;
1527 efx_rc_t all_unicst_rc = 0;
1528 efx_rc_t all_mulcst_rc = 0;
1531 if (table->eft_default_rxq == NULL) {
1533 * Filters direct traffic to the default RXQ, and so cannot be
1534 * inserted until it is available. Any currently configured
1535 * filters must be removed (ignore errors in case the MC
1536 * has rebooted, which removes hardware filters).
1538 for (i = 0; i < table->eft_unicst_filter_count; i++) {
1539 (void) ef10_filter_delete_internal(enp,
1540 table->eft_unicst_filter_indexes[i]);
1542 table->eft_unicst_filter_count = 0;
1544 for (i = 0; i < table->eft_mulcst_filter_count; i++) {
1545 (void) ef10_filter_delete_internal(enp,
1546 table->eft_mulcst_filter_indexes[i]);
1548 table->eft_mulcst_filter_count = 0;
1550 for (i = 0; i < table->eft_encap_filter_count; i++) {
1551 (void) ef10_filter_delete_internal(enp,
1552 table->eft_encap_filter_indexes[i]);
1554 table->eft_encap_filter_count = 0;
1559 if (table->eft_using_rss)
1560 filter_flags = EFX_FILTER_FLAG_RX_RSS;
1564 /* Mark old filters which may need to be removed */
1565 for (i = 0; i < table->eft_unicst_filter_count; i++) {
1566 ef10_filter_set_entry_auto_old(table,
1567 table->eft_unicst_filter_indexes[i]);
1569 for (i = 0; i < table->eft_mulcst_filter_count; i++) {
1570 ef10_filter_set_entry_auto_old(table,
1571 table->eft_mulcst_filter_indexes[i]);
1573 for (i = 0; i < table->eft_encap_filter_count; i++) {
1574 ef10_filter_set_entry_auto_old(table,
1575 table->eft_encap_filter_indexes[i]);
1579 * Insert or renew unicast filters.
1581 * Firmware does not perform chaining on unicast filters. As traffic is
1582 * therefore only delivered to the first matching filter, we should
1583 * always insert the specific filter for our MAC address, to try and
1584 * ensure we get that traffic.
1586 * (If the filter for our MAC address has already been inserted by
1587 * another function, we won't receive traffic sent to us, even if we
1588 * insert a unicast mismatch filter. To prevent traffic stealing, this
1589 * therefore relies on the privilege model only allowing functions to
1590 * insert filters for their own MAC address unless explicitly given
1591 * additional privileges by the user. This also means that, even on a
1592 * priviliged function, inserting a unicast mismatch filter may not
1593 * catch all traffic in multi PCI function scenarios.)
1595 table->eft_unicst_filter_count = 0;
1596 rc = ef10_filter_insert_unicast(enp, mac_addr, filter_flags);
1597 if (all_unicst || (rc != 0)) {
1598 all_unicst_rc = ef10_filter_insert_all_unicast(enp,
1600 if ((rc != 0) && (all_unicst_rc != 0))
1605 * WORKAROUND_BUG26807 controls firmware support for chained multicast
1606 * filters, and can only be enabled or disabled when the hardware filter
1609 * Chained multicast filters require support from the datapath firmware,
1610 * and may not be available (e.g. low-latency variants or old Huntington
1613 * Firmware will reset (FLR) functions which have inserted filters in
1614 * the hardware filter table when the workaround is enabled/disabled.
1615 * Functions without any hardware filters are not reset.
1617 * Re-check if the workaround is enabled after adding unicast hardware
1618 * filters. This ensures that encp->enc_bug26807_workaround matches the
1619 * firmware state, and that later changes to enable/disable the
1620 * workaround will result in this function seeing a reset (FLR).
1622 * In common-code drivers, we only support multiple PCI function
1623 * scenarios with firmware that supports multicast chaining, so we can
1624 * assume it is enabled for such cases and hence simplify the filter
1625 * insertion logic. Firmware that does not support multicast chaining
1626 * does not support multiple PCI function configurations either, so
1627 * filter insertion is much simpler and the same strategies can still be
1630 if ((rc = ef10_filter_get_workarounds(enp)) != 0)
1633 if ((table->eft_using_all_mulcst != all_mulcst) &&
1634 (encp->enc_bug26807_workaround == B_TRUE)) {
1636 * Multicast filter chaining is enabled, so traffic that matches
1637 * more than one multicast filter will be replicated and
1638 * delivered to multiple recipients. To avoid this duplicate
1639 * delivery, remove old multicast filters before inserting new
1640 * multicast filters.
1642 ef10_filter_remove_old(enp);
1645 /* Insert or renew multicast filters */
1646 if (all_mulcst == B_TRUE) {
1648 * Insert the all multicast filter. If that fails, try to insert
1649 * all of our multicast filters (but without rollback on
1652 all_mulcst_rc = ef10_filter_insert_all_multicast(enp,
1654 if (all_mulcst_rc != 0) {
1655 rc = ef10_filter_insert_multicast_list(enp, B_TRUE,
1656 brdcst, addrs, count, filter_flags, B_FALSE);
1662 * Insert filters for multicast addresses.
1663 * If any insertion fails, then rollback and try to insert the
1664 * all multicast filter instead.
1665 * If that also fails, try to insert all of the multicast
1666 * filters (but without rollback on failure).
1668 rc = ef10_filter_insert_multicast_list(enp, mulcst, brdcst,
1669 addrs, count, filter_flags, B_TRUE);
1671 if ((table->eft_using_all_mulcst == B_FALSE) &&
1672 (encp->enc_bug26807_workaround == B_TRUE)) {
1674 * Multicast filter chaining is on, so remove
1675 * old filters before inserting the multicast
1676 * all filter to avoid duplicate delivery caused
1677 * by packets matching multiple filters.
1679 ef10_filter_remove_old(enp);
1682 rc = ef10_filter_insert_all_multicast(enp,
1685 rc = ef10_filter_insert_multicast_list(enp,
1687 addrs, count, filter_flags, B_FALSE);
1694 if (encp->enc_tunnel_encapsulations_supported != 0) {
1695 /* Try to insert filters for encapsulated packets. */
1696 (void) ef10_filter_insert_encap_filters(enp,
1697 mulcst || all_mulcst || brdcst,
1701 /* Remove old filters which were not renewed */
1702 ef10_filter_remove_old(enp);
1704 /* report if any optional flags were rejected */
1705 if (((all_unicst != B_FALSE) && (all_unicst_rc != 0)) ||
1706 ((all_mulcst != B_FALSE) && (all_mulcst_rc != 0))) {
1719 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1721 /* Clear auto old flags */
1722 for (i = 0; i < EFX_ARRAY_SIZE(table->eft_entry); i++) {
1723 if (ef10_filter_entry_is_auto_old(table, i)) {
1724 ef10_filter_set_entry_not_auto_old(table, i);
1732 ef10_filter_get_default_rxq(
1733 __in efx_nic_t *enp,
1734 __out efx_rxq_t **erpp,
1735 __out boolean_t *using_rss)
1737 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
1739 *erpp = table->eft_default_rxq;
1740 *using_rss = table->eft_using_rss;
1745 ef10_filter_default_rxq_set(
1746 __in efx_nic_t *enp,
1747 __in efx_rxq_t *erp,
1748 __in boolean_t using_rss)
1750 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
1752 #if EFSYS_OPT_RX_SCALE
1753 EFSYS_ASSERT((using_rss == B_FALSE) ||
1754 (enp->en_rss_context != EF10_RSS_CONTEXT_INVALID));
1755 table->eft_using_rss = using_rss;
1757 EFSYS_ASSERT(using_rss == B_FALSE);
1758 table->eft_using_rss = B_FALSE;
1760 table->eft_default_rxq = erp;
1764 ef10_filter_default_rxq_clear(
1765 __in efx_nic_t *enp)
1767 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
1769 table->eft_default_rxq = NULL;
1770 table->eft_using_rss = B_FALSE;
1774 #endif /* EFSYS_OPT_FILTER */
1776 #endif /* EFSYS_OPT_HUNTINGTON || EFSYS_OPT_MEDFORD || EFSYS_OPT_MEDFORD2 */