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 efx_filter_spec_set_eth_local(&spec, EFX_FILTER_SPEC_VID_UNSPEC, addr);
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);
1161 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1165 static __checkReturn efx_rc_t
1166 ef10_filter_insert_all_unicast(
1167 __in efx_nic_t *enp,
1168 __in efx_filter_flags_t filter_flags)
1170 ef10_filter_table_t *eftp = enp->en_filter.ef_ef10_filter_table;
1171 efx_filter_spec_t spec;
1174 /* Insert the unknown unicast filter */
1175 efx_filter_spec_init_rx(&spec, EFX_FILTER_PRI_AUTO,
1177 eftp->eft_default_rxq);
1178 efx_filter_spec_set_uc_def(&spec);
1179 rc = ef10_filter_add_internal(enp, &spec, B_TRUE,
1180 &eftp->eft_unicst_filter_indexes[eftp->eft_unicst_filter_count]);
1184 eftp->eft_unicst_filter_count++;
1185 EFSYS_ASSERT(eftp->eft_unicst_filter_count <=
1186 EFX_EF10_FILTER_UNICAST_FILTERS_MAX);
1191 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1195 static __checkReturn efx_rc_t
1196 ef10_filter_insert_multicast_list(
1197 __in efx_nic_t *enp,
1198 __in boolean_t mulcst,
1199 __in boolean_t brdcst,
1200 __in_ecount(6*count) uint8_t const *addrs,
1201 __in uint32_t count,
1202 __in efx_filter_flags_t filter_flags,
1203 __in boolean_t rollback)
1205 ef10_filter_table_t *eftp = enp->en_filter.ef_ef10_filter_table;
1206 efx_filter_spec_t spec;
1209 uint32_t filter_index;
1210 uint32_t filter_count;
1213 if (mulcst == B_FALSE)
1216 if (count + (brdcst ? 1 : 0) >
1217 EFX_ARRAY_SIZE(eftp->eft_mulcst_filter_indexes)) {
1218 /* Too many MAC addresses */
1223 /* Insert/renew multicast address list filters */
1225 for (i = 0; i < count; i++) {
1226 efx_filter_spec_init_rx(&spec,
1227 EFX_FILTER_PRI_AUTO,
1229 eftp->eft_default_rxq);
1231 efx_filter_spec_set_eth_local(&spec,
1232 EFX_FILTER_SPEC_VID_UNSPEC,
1233 &addrs[i * EFX_MAC_ADDR_LEN]);
1235 rc = ef10_filter_add_internal(enp, &spec, B_TRUE,
1239 eftp->eft_mulcst_filter_indexes[filter_count] =
1242 } else if (rollback == B_TRUE) {
1243 /* Only stop upon failure if told to rollback */
1249 if (brdcst == B_TRUE) {
1250 /* Insert/renew broadcast address filter */
1251 efx_filter_spec_init_rx(&spec, EFX_FILTER_PRI_AUTO,
1253 eftp->eft_default_rxq);
1255 EFX_MAC_BROADCAST_ADDR_SET(addr);
1256 efx_filter_spec_set_eth_local(&spec, EFX_FILTER_SPEC_VID_UNSPEC,
1259 rc = ef10_filter_add_internal(enp, &spec, B_TRUE,
1263 eftp->eft_mulcst_filter_indexes[filter_count] =
1266 } else if (rollback == B_TRUE) {
1267 /* Only stop upon failure if told to rollback */
1272 eftp->eft_mulcst_filter_count = filter_count;
1273 eftp->eft_using_all_mulcst = B_FALSE;
1278 /* Remove any filters we have inserted */
1281 (void) ef10_filter_delete_internal(enp,
1282 eftp->eft_mulcst_filter_indexes[i]);
1284 eftp->eft_mulcst_filter_count = 0;
1287 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1292 static __checkReturn efx_rc_t
1293 ef10_filter_insert_all_multicast(
1294 __in efx_nic_t *enp,
1295 __in efx_filter_flags_t filter_flags)
1297 ef10_filter_table_t *eftp = enp->en_filter.ef_ef10_filter_table;
1298 efx_filter_spec_t spec;
1301 /* Insert the unknown multicast filter */
1302 efx_filter_spec_init_rx(&spec, EFX_FILTER_PRI_AUTO,
1304 eftp->eft_default_rxq);
1305 efx_filter_spec_set_mc_def(&spec);
1307 rc = ef10_filter_add_internal(enp, &spec, B_TRUE,
1308 &eftp->eft_mulcst_filter_indexes[0]);
1312 eftp->eft_mulcst_filter_count = 1;
1313 eftp->eft_using_all_mulcst = B_TRUE;
1316 * FIXME: If brdcst == B_FALSE, add a filter to drop broadcast traffic.
1322 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1327 typedef struct ef10_filter_encap_entry_s {
1328 uint16_t ether_type;
1329 efx_tunnel_protocol_t encap_type;
1330 uint32_t inner_frame_match;
1331 } ef10_filter_encap_entry_t;
1333 #define EF10_ENCAP_FILTER_ENTRY(ipv, encap_type, inner_frame_match) \
1334 { EFX_ETHER_TYPE_##ipv, EFX_TUNNEL_PROTOCOL_##encap_type, \
1335 EFX_FILTER_INNER_FRAME_MATCH_UNKNOWN_##inner_frame_match }
1337 static ef10_filter_encap_entry_t ef10_filter_encap_list[] = {
1338 EF10_ENCAP_FILTER_ENTRY(IPV4, VXLAN, UCAST_DST),
1339 EF10_ENCAP_FILTER_ENTRY(IPV4, VXLAN, MCAST_DST),
1340 EF10_ENCAP_FILTER_ENTRY(IPV6, VXLAN, UCAST_DST),
1341 EF10_ENCAP_FILTER_ENTRY(IPV6, VXLAN, MCAST_DST),
1343 EF10_ENCAP_FILTER_ENTRY(IPV4, GENEVE, UCAST_DST),
1344 EF10_ENCAP_FILTER_ENTRY(IPV4, GENEVE, MCAST_DST),
1345 EF10_ENCAP_FILTER_ENTRY(IPV6, GENEVE, UCAST_DST),
1346 EF10_ENCAP_FILTER_ENTRY(IPV6, GENEVE, MCAST_DST),
1348 EF10_ENCAP_FILTER_ENTRY(IPV4, NVGRE, UCAST_DST),
1349 EF10_ENCAP_FILTER_ENTRY(IPV4, NVGRE, MCAST_DST),
1350 EF10_ENCAP_FILTER_ENTRY(IPV6, NVGRE, UCAST_DST),
1351 EF10_ENCAP_FILTER_ENTRY(IPV6, NVGRE, MCAST_DST),
1354 #undef EF10_ENCAP_FILTER_ENTRY
1356 static __checkReturn efx_rc_t
1357 ef10_filter_insert_encap_filters(
1358 __in efx_nic_t *enp,
1359 __in boolean_t mulcst,
1360 __in efx_filter_flags_t filter_flags)
1362 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
1366 EFX_STATIC_ASSERT(EFX_ARRAY_SIZE(ef10_filter_encap_list) <=
1367 EFX_ARRAY_SIZE(table->eft_encap_filter_indexes));
1370 * On Medford, full-featured firmware can identify packets as being
1371 * tunnel encapsulated, even if no encapsulated packet offloads are in
1372 * use. When packets are identified as such, ordinary filters are not
1373 * applied, only ones specific to encapsulated packets. Hence we need to
1374 * insert filters for encapsulated packets in order to receive them.
1376 * Separate filters need to be inserted for each ether type,
1377 * encapsulation type, and inner frame type (unicast or multicast). To
1378 * keep things simple and reduce the number of filters needed, catch-all
1379 * filters for all combinations of types are inserted, even if
1380 * all_unicst or all_mulcst have not been set. (These catch-all filters
1381 * may well, however, fail to insert on unprivileged functions.)
1383 table->eft_encap_filter_count = 0;
1384 for (i = 0; i < EFX_ARRAY_SIZE(ef10_filter_encap_list); i++) {
1385 efx_filter_spec_t spec;
1386 ef10_filter_encap_entry_t *encap_filter =
1387 &ef10_filter_encap_list[i];
1390 * Skip multicast filters if we've not been asked for
1391 * any multicast traffic.
1393 if ((mulcst == B_FALSE) &&
1394 (encap_filter->inner_frame_match ==
1395 EFX_FILTER_INNER_FRAME_MATCH_UNKNOWN_MCAST_DST))
1398 efx_filter_spec_init_rx(&spec, EFX_FILTER_PRI_AUTO,
1400 table->eft_default_rxq);
1401 efx_filter_spec_set_ether_type(&spec, encap_filter->ether_type);
1402 rc = efx_filter_spec_set_encap_type(&spec,
1403 encap_filter->encap_type,
1404 encap_filter->inner_frame_match);
1408 rc = ef10_filter_add_internal(enp, &spec, B_TRUE,
1409 &table->eft_encap_filter_indexes[
1410 table->eft_encap_filter_count]);
1415 table->eft_encap_filter_count++;
1424 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1430 ef10_filter_remove_old(
1431 __in efx_nic_t *enp)
1433 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
1436 for (i = 0; i < EFX_ARRAY_SIZE(table->eft_entry); i++) {
1437 if (ef10_filter_entry_is_auto_old(table, i)) {
1438 (void) ef10_filter_delete_internal(enp, i);
1444 static __checkReturn efx_rc_t
1445 ef10_filter_get_workarounds(
1446 __in efx_nic_t *enp)
1448 efx_nic_cfg_t *encp = &enp->en_nic_cfg;
1449 uint32_t implemented = 0;
1450 uint32_t enabled = 0;
1453 rc = efx_mcdi_get_workarounds(enp, &implemented, &enabled);
1455 /* Check if chained multicast filter support is enabled */
1456 if (implemented & enabled & MC_CMD_GET_WORKAROUNDS_OUT_BUG26807)
1457 encp->enc_bug26807_workaround = B_TRUE;
1459 encp->enc_bug26807_workaround = B_FALSE;
1460 } else if (rc == ENOTSUP) {
1462 * Firmware is too old to support GET_WORKAROUNDS, and support
1463 * for this workaround was implemented later.
1465 encp->enc_bug26807_workaround = B_FALSE;
1473 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1481 * Reconfigure all filters.
1482 * If all_unicst and/or all mulcst filters cannot be applied then
1483 * return ENOTSUP (Note the filters for the specified addresses are
1484 * still applied in this case).
1486 __checkReturn efx_rc_t
1487 ef10_filter_reconfigure(
1488 __in efx_nic_t *enp,
1489 __in_ecount(6) uint8_t const *mac_addr,
1490 __in boolean_t all_unicst,
1491 __in boolean_t mulcst,
1492 __in boolean_t all_mulcst,
1493 __in boolean_t brdcst,
1494 __in_ecount(6*count) uint8_t const *addrs,
1495 __in uint32_t count)
1497 efx_nic_cfg_t *encp = &enp->en_nic_cfg;
1498 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
1499 efx_filter_flags_t filter_flags;
1501 efx_rc_t all_unicst_rc = 0;
1502 efx_rc_t all_mulcst_rc = 0;
1505 if (table->eft_default_rxq == NULL) {
1507 * Filters direct traffic to the default RXQ, and so cannot be
1508 * inserted until it is available. Any currently configured
1509 * filters must be removed (ignore errors in case the MC
1510 * has rebooted, which removes hardware filters).
1512 for (i = 0; i < table->eft_unicst_filter_count; i++) {
1513 (void) ef10_filter_delete_internal(enp,
1514 table->eft_unicst_filter_indexes[i]);
1516 table->eft_unicst_filter_count = 0;
1518 for (i = 0; i < table->eft_mulcst_filter_count; i++) {
1519 (void) ef10_filter_delete_internal(enp,
1520 table->eft_mulcst_filter_indexes[i]);
1522 table->eft_mulcst_filter_count = 0;
1524 for (i = 0; i < table->eft_encap_filter_count; i++) {
1525 (void) ef10_filter_delete_internal(enp,
1526 table->eft_encap_filter_indexes[i]);
1528 table->eft_encap_filter_count = 0;
1533 if (table->eft_using_rss)
1534 filter_flags = EFX_FILTER_FLAG_RX_RSS;
1538 /* Mark old filters which may need to be removed */
1539 for (i = 0; i < table->eft_unicst_filter_count; i++) {
1540 ef10_filter_set_entry_auto_old(table,
1541 table->eft_unicst_filter_indexes[i]);
1543 for (i = 0; i < table->eft_mulcst_filter_count; i++) {
1544 ef10_filter_set_entry_auto_old(table,
1545 table->eft_mulcst_filter_indexes[i]);
1547 for (i = 0; i < table->eft_encap_filter_count; i++) {
1548 ef10_filter_set_entry_auto_old(table,
1549 table->eft_encap_filter_indexes[i]);
1553 * Insert or renew unicast filters.
1555 * Frimware does not perform chaining on unicast filters. As traffic is
1556 * therefore only delivered to the first matching filter, we should
1557 * always insert the specific filter for our MAC address, to try and
1558 * ensure we get that traffic.
1560 * (If the filter for our MAC address has already been inserted by
1561 * another function, we won't receive traffic sent to us, even if we
1562 * insert a unicast mismatch filter. To prevent traffic stealing, this
1563 * therefore relies on the privilege model only allowing functions to
1564 * insert filters for their own MAC address unless explicitly given
1565 * additional privileges by the user. This also means that, even on a
1566 * priviliged function, inserting a unicast mismatch filter may not
1567 * catch all traffic in multi PCI function scenarios.)
1569 table->eft_unicst_filter_count = 0;
1570 rc = ef10_filter_insert_unicast(enp, mac_addr, filter_flags);
1571 if (all_unicst || (rc != 0)) {
1572 all_unicst_rc = ef10_filter_insert_all_unicast(enp,
1574 if ((rc != 0) && (all_unicst_rc != 0))
1579 * WORKAROUND_BUG26807 controls firmware support for chained multicast
1580 * filters, and can only be enabled or disabled when the hardware filter
1583 * Chained multicast filters require support from the datapath firmware,
1584 * and may not be available (e.g. low-latency variants or old Huntington
1587 * Firmware will reset (FLR) functions which have inserted filters in
1588 * the hardware filter table when the workaround is enabled/disabled.
1589 * Functions without any hardware filters are not reset.
1591 * Re-check if the workaround is enabled after adding unicast hardware
1592 * filters. This ensures that encp->enc_bug26807_workaround matches the
1593 * firmware state, and that later changes to enable/disable the
1594 * workaround will result in this function seeing a reset (FLR).
1596 * In common-code drivers, we only support multiple PCI function
1597 * scenarios with firmware that supports multicast chaining, so we can
1598 * assume it is enabled for such cases and hence simplify the filter
1599 * insertion logic. Firmware that does not support multicast chaining
1600 * does not support multiple PCI function configurations either, so
1601 * filter insertion is much simpler and the same strategies can still be
1604 if ((rc = ef10_filter_get_workarounds(enp)) != 0)
1607 if ((table->eft_using_all_mulcst != all_mulcst) &&
1608 (encp->enc_bug26807_workaround == B_TRUE)) {
1610 * Multicast filter chaining is enabled, so traffic that matches
1611 * more than one multicast filter will be replicated and
1612 * delivered to multiple recipients. To avoid this duplicate
1613 * delivery, remove old multicast filters before inserting new
1614 * multicast filters.
1616 ef10_filter_remove_old(enp);
1619 /* Insert or renew multicast filters */
1620 if (all_mulcst == B_TRUE) {
1622 * Insert the all multicast filter. If that fails, try to insert
1623 * all of our multicast filters (but without rollback on
1626 all_mulcst_rc = ef10_filter_insert_all_multicast(enp,
1628 if (all_mulcst_rc != 0) {
1629 rc = ef10_filter_insert_multicast_list(enp, B_TRUE,
1630 brdcst, addrs, count, filter_flags, B_FALSE);
1636 * Insert filters for multicast addresses.
1637 * If any insertion fails, then rollback and try to insert the
1638 * all multicast filter instead.
1639 * If that also fails, try to insert all of the multicast
1640 * filters (but without rollback on failure).
1642 rc = ef10_filter_insert_multicast_list(enp, mulcst, brdcst,
1643 addrs, count, filter_flags, B_TRUE);
1645 if ((table->eft_using_all_mulcst == B_FALSE) &&
1646 (encp->enc_bug26807_workaround == B_TRUE)) {
1648 * Multicast filter chaining is on, so remove
1649 * old filters before inserting the multicast
1650 * all filter to avoid duplicate delivery caused
1651 * by packets matching multiple filters.
1653 ef10_filter_remove_old(enp);
1656 rc = ef10_filter_insert_all_multicast(enp,
1659 rc = ef10_filter_insert_multicast_list(enp,
1661 addrs, count, filter_flags, B_FALSE);
1668 if (encp->enc_tunnel_encapsulations_supported != 0) {
1669 /* Try to insert filters for encapsulated packets. */
1670 (void) ef10_filter_insert_encap_filters(enp,
1671 mulcst || all_mulcst || brdcst,
1675 /* Remove old filters which were not renewed */
1676 ef10_filter_remove_old(enp);
1678 /* report if any optional flags were rejected */
1679 if (((all_unicst != B_FALSE) && (all_unicst_rc != 0)) ||
1680 ((all_mulcst != B_FALSE) && (all_mulcst_rc != 0))) {
1693 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1695 /* Clear auto old flags */
1696 for (i = 0; i < EFX_ARRAY_SIZE(table->eft_entry); i++) {
1697 if (ef10_filter_entry_is_auto_old(table, i)) {
1698 ef10_filter_set_entry_not_auto_old(table, i);
1706 ef10_filter_get_default_rxq(
1707 __in efx_nic_t *enp,
1708 __out efx_rxq_t **erpp,
1709 __out boolean_t *using_rss)
1711 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
1713 *erpp = table->eft_default_rxq;
1714 *using_rss = table->eft_using_rss;
1719 ef10_filter_default_rxq_set(
1720 __in efx_nic_t *enp,
1721 __in efx_rxq_t *erp,
1722 __in boolean_t using_rss)
1724 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
1726 #if EFSYS_OPT_RX_SCALE
1727 EFSYS_ASSERT((using_rss == B_FALSE) ||
1728 (enp->en_rss_context != EF10_RSS_CONTEXT_INVALID));
1729 table->eft_using_rss = using_rss;
1731 EFSYS_ASSERT(using_rss == B_FALSE);
1732 table->eft_using_rss = B_FALSE;
1734 table->eft_default_rxq = erp;
1738 ef10_filter_default_rxq_clear(
1739 __in efx_nic_t *enp)
1741 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
1743 table->eft_default_rxq = NULL;
1744 table->eft_using_rss = B_FALSE;
1748 #endif /* EFSYS_OPT_FILTER */
1750 #endif /* EFSYS_OPT_HUNTINGTON || EFSYS_OPT_MEDFORD || EFSYS_OPT_MEDFORD2 */