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_IFRM_UNKNOWN_MCAST_DST ==
123 MATCH_MASK(MC_CMD_FILTER_OP_EXT_IN_MATCH_IFRM_UNKNOWN_MCAST_DST));
124 EFX_STATIC_ASSERT(EFX_FILTER_MATCH_IFRM_UNKNOWN_UCAST_DST ==
125 MATCH_MASK(MC_CMD_FILTER_OP_EXT_IN_MATCH_IFRM_UNKNOWN_UCAST_DST));
126 EFX_STATIC_ASSERT(EFX_FILTER_MATCH_UNKNOWN_MCAST_DST ==
127 MATCH_MASK(MC_CMD_FILTER_OP_EXT_IN_MATCH_UNKNOWN_MCAST_DST));
128 EFX_STATIC_ASSERT((uint32_t)EFX_FILTER_MATCH_UNKNOWN_UCAST_DST ==
129 MATCH_MASK(MC_CMD_FILTER_OP_EXT_IN_MATCH_UNKNOWN_UCAST_DST));
132 EFSYS_KMEM_ALLOC(enp->en_esip, sizeof (ef10_filter_table_t), eftp);
139 enp->en_filter.ef_ef10_filter_table = eftp;
144 EFSYS_PROBE1(fail1, efx_rc_t, rc);
153 EFSYS_ASSERT(enp->en_family == EFX_FAMILY_HUNTINGTON ||
154 enp->en_family == EFX_FAMILY_MEDFORD ||
155 enp->en_family == EFX_FAMILY_MEDFORD2);
157 if (enp->en_filter.ef_ef10_filter_table != NULL) {
158 EFSYS_KMEM_FREE(enp->en_esip, sizeof (ef10_filter_table_t),
159 enp->en_filter.ef_ef10_filter_table);
163 static __checkReturn efx_rc_t
164 efx_mcdi_filter_op_add(
166 __in efx_filter_spec_t *spec,
167 __in unsigned int filter_op,
168 __inout ef10_filter_handle_t *handle)
171 uint8_t payload[MAX(MC_CMD_FILTER_OP_EXT_IN_LEN,
172 MC_CMD_FILTER_OP_EXT_OUT_LEN)];
175 memset(payload, 0, sizeof (payload));
176 req.emr_cmd = MC_CMD_FILTER_OP;
177 req.emr_in_buf = payload;
178 req.emr_in_length = MC_CMD_FILTER_OP_EXT_IN_LEN;
179 req.emr_out_buf = payload;
180 req.emr_out_length = MC_CMD_FILTER_OP_EXT_OUT_LEN;
183 case MC_CMD_FILTER_OP_IN_OP_REPLACE:
184 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_HANDLE_LO,
186 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_HANDLE_HI,
189 case MC_CMD_FILTER_OP_IN_OP_INSERT:
190 case MC_CMD_FILTER_OP_IN_OP_SUBSCRIBE:
191 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_OP, filter_op);
199 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_PORT_ID,
200 EVB_PORT_ID_ASSIGNED);
201 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_MATCH_FIELDS,
202 spec->efs_match_flags);
203 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_RX_DEST,
204 MC_CMD_FILTER_OP_EXT_IN_RX_DEST_HOST);
205 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_RX_QUEUE,
208 #if EFSYS_OPT_RX_SCALE
209 if (spec->efs_flags & EFX_FILTER_FLAG_RX_RSS) {
210 uint32_t rss_context;
212 if (spec->efs_rss_context == EFX_RSS_CONTEXT_DEFAULT)
213 rss_context = enp->en_rss_context;
215 rss_context = spec->efs_rss_context;
216 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_RX_CONTEXT,
221 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_RX_MODE,
222 spec->efs_flags & EFX_FILTER_FLAG_RX_RSS ?
223 MC_CMD_FILTER_OP_EXT_IN_RX_MODE_RSS :
224 MC_CMD_FILTER_OP_EXT_IN_RX_MODE_SIMPLE);
225 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_TX_DEST,
226 MC_CMD_FILTER_OP_EXT_IN_TX_DEST_DEFAULT);
228 if (filter_op != MC_CMD_FILTER_OP_IN_OP_REPLACE) {
230 * NOTE: Unlike most MCDI requests, the filter fields
231 * are presented in network (big endian) byte order.
233 memcpy(MCDI_IN2(req, uint8_t, FILTER_OP_EXT_IN_SRC_MAC),
234 spec->efs_rem_mac, EFX_MAC_ADDR_LEN);
235 memcpy(MCDI_IN2(req, uint8_t, FILTER_OP_EXT_IN_DST_MAC),
236 spec->efs_loc_mac, EFX_MAC_ADDR_LEN);
238 MCDI_IN_SET_WORD(req, FILTER_OP_EXT_IN_SRC_PORT,
239 __CPU_TO_BE_16(spec->efs_rem_port));
240 MCDI_IN_SET_WORD(req, FILTER_OP_EXT_IN_DST_PORT,
241 __CPU_TO_BE_16(spec->efs_loc_port));
243 MCDI_IN_SET_WORD(req, FILTER_OP_EXT_IN_ETHER_TYPE,
244 __CPU_TO_BE_16(spec->efs_ether_type));
246 MCDI_IN_SET_WORD(req, FILTER_OP_EXT_IN_INNER_VLAN,
247 __CPU_TO_BE_16(spec->efs_inner_vid));
248 MCDI_IN_SET_WORD(req, FILTER_OP_EXT_IN_OUTER_VLAN,
249 __CPU_TO_BE_16(spec->efs_outer_vid));
251 /* IP protocol (in low byte, high byte is zero) */
252 MCDI_IN_SET_BYTE(req, FILTER_OP_EXT_IN_IP_PROTO,
255 EFX_STATIC_ASSERT(sizeof (spec->efs_rem_host) ==
256 MC_CMD_FILTER_OP_EXT_IN_SRC_IP_LEN);
257 EFX_STATIC_ASSERT(sizeof (spec->efs_loc_host) ==
258 MC_CMD_FILTER_OP_EXT_IN_DST_IP_LEN);
260 memcpy(MCDI_IN2(req, uint8_t, FILTER_OP_EXT_IN_SRC_IP),
261 &spec->efs_rem_host.eo_byte[0],
262 MC_CMD_FILTER_OP_EXT_IN_SRC_IP_LEN);
263 memcpy(MCDI_IN2(req, uint8_t, FILTER_OP_EXT_IN_DST_IP),
264 &spec->efs_loc_host.eo_byte[0],
265 MC_CMD_FILTER_OP_EXT_IN_DST_IP_LEN);
268 * On Medford, filters for encapsulated packets match based on
269 * the ether type and IP protocol in the outer frame. In
270 * addition we need to fill in the VNI or VSID type field.
272 switch (spec->efs_encap_type) {
273 case EFX_TUNNEL_PROTOCOL_NONE:
275 case EFX_TUNNEL_PROTOCOL_VXLAN:
276 case EFX_TUNNEL_PROTOCOL_GENEVE:
277 MCDI_IN_POPULATE_DWORD_1(req,
278 FILTER_OP_EXT_IN_VNI_OR_VSID,
279 FILTER_OP_EXT_IN_VNI_TYPE,
280 spec->efs_encap_type == EFX_TUNNEL_PROTOCOL_VXLAN ?
281 MC_CMD_FILTER_OP_EXT_IN_VNI_TYPE_VXLAN :
282 MC_CMD_FILTER_OP_EXT_IN_VNI_TYPE_GENEVE);
284 case EFX_TUNNEL_PROTOCOL_NVGRE:
285 MCDI_IN_POPULATE_DWORD_1(req,
286 FILTER_OP_EXT_IN_VNI_OR_VSID,
287 FILTER_OP_EXT_IN_VSID_TYPE,
288 MC_CMD_FILTER_OP_EXT_IN_VSID_TYPE_NVGRE);
297 efx_mcdi_execute(enp, &req);
299 if (req.emr_rc != 0) {
304 if (req.emr_out_length_used < MC_CMD_FILTER_OP_EXT_OUT_LEN) {
309 handle->efh_lo = MCDI_OUT_DWORD(req, FILTER_OP_EXT_OUT_HANDLE_LO);
310 handle->efh_hi = MCDI_OUT_DWORD(req, FILTER_OP_EXT_OUT_HANDLE_HI);
321 EFSYS_PROBE1(fail1, efx_rc_t, rc);
327 static __checkReturn efx_rc_t
328 efx_mcdi_filter_op_delete(
330 __in unsigned int filter_op,
331 __inout ef10_filter_handle_t *handle)
334 uint8_t payload[MAX(MC_CMD_FILTER_OP_EXT_IN_LEN,
335 MC_CMD_FILTER_OP_EXT_OUT_LEN)];
338 memset(payload, 0, sizeof (payload));
339 req.emr_cmd = MC_CMD_FILTER_OP;
340 req.emr_in_buf = payload;
341 req.emr_in_length = MC_CMD_FILTER_OP_EXT_IN_LEN;
342 req.emr_out_buf = payload;
343 req.emr_out_length = MC_CMD_FILTER_OP_EXT_OUT_LEN;
346 case MC_CMD_FILTER_OP_IN_OP_REMOVE:
347 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_OP,
348 MC_CMD_FILTER_OP_IN_OP_REMOVE);
350 case MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE:
351 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_OP,
352 MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE);
360 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_HANDLE_LO, handle->efh_lo);
361 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_HANDLE_HI, handle->efh_hi);
363 efx_mcdi_execute_quiet(enp, &req);
365 if (req.emr_rc != 0) {
370 if (req.emr_out_length_used < MC_CMD_FILTER_OP_EXT_OUT_LEN) {
383 EFSYS_PROBE1(fail1, efx_rc_t, rc);
388 static __checkReturn boolean_t
390 __in const efx_filter_spec_t *left,
391 __in const efx_filter_spec_t *right)
393 /* FIXME: Consider rx vs tx filters (look at efs_flags) */
394 if (left->efs_match_flags != right->efs_match_flags)
396 if (!EFX_OWORD_IS_EQUAL(left->efs_rem_host, right->efs_rem_host))
398 if (!EFX_OWORD_IS_EQUAL(left->efs_loc_host, right->efs_loc_host))
400 if (memcmp(left->efs_rem_mac, right->efs_rem_mac, EFX_MAC_ADDR_LEN))
402 if (memcmp(left->efs_loc_mac, right->efs_loc_mac, EFX_MAC_ADDR_LEN))
404 if (left->efs_rem_port != right->efs_rem_port)
406 if (left->efs_loc_port != right->efs_loc_port)
408 if (left->efs_inner_vid != right->efs_inner_vid)
410 if (left->efs_outer_vid != right->efs_outer_vid)
412 if (left->efs_ether_type != right->efs_ether_type)
414 if (left->efs_ip_proto != right->efs_ip_proto)
416 if (left->efs_encap_type != right->efs_encap_type)
423 static __checkReturn boolean_t
424 ef10_filter_same_dest(
425 __in const efx_filter_spec_t *left,
426 __in const efx_filter_spec_t *right)
428 if ((left->efs_flags & EFX_FILTER_FLAG_RX_RSS) &&
429 (right->efs_flags & EFX_FILTER_FLAG_RX_RSS)) {
430 if (left->efs_rss_context == right->efs_rss_context)
432 } else if ((~(left->efs_flags) & EFX_FILTER_FLAG_RX_RSS) &&
433 (~(right->efs_flags) & EFX_FILTER_FLAG_RX_RSS)) {
434 if (left->efs_dmaq_id == right->efs_dmaq_id)
440 static __checkReturn uint32_t
442 __in efx_filter_spec_t *spec)
444 EFX_STATIC_ASSERT((sizeof (efx_filter_spec_t) % sizeof (uint32_t))
446 EFX_STATIC_ASSERT((EFX_FIELD_OFFSET(efx_filter_spec_t, efs_outer_vid) %
447 sizeof (uint32_t)) == 0);
450 * As the area of the efx_filter_spec_t we need to hash is DWORD
451 * aligned and an exact number of DWORDs in size we can use the
452 * optimised efx_hash_dwords() rather than efx_hash_bytes()
454 return (efx_hash_dwords((const uint32_t *)&spec->efs_outer_vid,
455 (sizeof (efx_filter_spec_t) -
456 EFX_FIELD_OFFSET(efx_filter_spec_t, efs_outer_vid)) /
457 sizeof (uint32_t), 0));
461 * Decide whether a filter should be exclusive or else should allow
462 * delivery to additional recipients. Currently we decide that
463 * filters for specific local unicast MAC and IP addresses are
466 static __checkReturn boolean_t
467 ef10_filter_is_exclusive(
468 __in efx_filter_spec_t *spec)
470 if ((spec->efs_match_flags & EFX_FILTER_MATCH_LOC_MAC) &&
471 !EFX_MAC_ADDR_IS_MULTICAST(spec->efs_loc_mac))
474 if ((spec->efs_match_flags &
475 (EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_LOC_HOST)) ==
476 (EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_LOC_HOST)) {
477 if ((spec->efs_ether_type == EFX_ETHER_TYPE_IPV4) &&
478 ((spec->efs_loc_host.eo_u8[0] & 0xf) != 0xe))
480 if ((spec->efs_ether_type == EFX_ETHER_TYPE_IPV6) &&
481 (spec->efs_loc_host.eo_u8[0] != 0xff))
488 __checkReturn efx_rc_t
493 efx_filter_spec_t *spec;
494 ef10_filter_table_t *eftp = enp->en_filter.ef_ef10_filter_table;
496 efsys_lock_state_t state;
499 EFSYS_ASSERT(enp->en_family == EFX_FAMILY_HUNTINGTON ||
500 enp->en_family == EFX_FAMILY_MEDFORD ||
501 enp->en_family == EFX_FAMILY_MEDFORD2);
503 for (tbl_id = 0; tbl_id < EFX_EF10_FILTER_TBL_ROWS; tbl_id++) {
505 EFSYS_LOCK(enp->en_eslp, state);
507 spec = ef10_filter_entry_spec(eftp, tbl_id);
510 } else if (ef10_filter_entry_is_busy(eftp, tbl_id)) {
511 /* Ignore busy entries. */
514 ef10_filter_set_entry_busy(eftp, tbl_id);
518 EFSYS_UNLOCK(enp->en_eslp, state);
520 if (restoring == B_FALSE)
523 if (ef10_filter_is_exclusive(spec)) {
524 rc = efx_mcdi_filter_op_add(enp, spec,
525 MC_CMD_FILTER_OP_IN_OP_INSERT,
526 &eftp->eft_entry[tbl_id].efe_handle);
528 rc = efx_mcdi_filter_op_add(enp, spec,
529 MC_CMD_FILTER_OP_IN_OP_SUBSCRIBE,
530 &eftp->eft_entry[tbl_id].efe_handle);
536 EFSYS_LOCK(enp->en_eslp, state);
538 ef10_filter_set_entry_not_busy(eftp, tbl_id);
540 EFSYS_UNLOCK(enp->en_eslp, state);
546 EFSYS_PROBE1(fail1, efx_rc_t, rc);
552 * An arbitrary search limit for the software hash table. As per the linux net
555 #define EF10_FILTER_SEARCH_LIMIT 200
557 static __checkReturn efx_rc_t
558 ef10_filter_add_internal(
560 __inout efx_filter_spec_t *spec,
561 __in boolean_t may_replace,
562 __out_opt uint32_t *filter_id)
565 ef10_filter_table_t *eftp = enp->en_filter.ef_ef10_filter_table;
566 efx_filter_spec_t *saved_spec;
570 boolean_t replacing = B_FALSE;
572 efsys_lock_state_t state;
573 boolean_t locked = B_FALSE;
575 EFSYS_ASSERT(enp->en_family == EFX_FAMILY_HUNTINGTON ||
576 enp->en_family == EFX_FAMILY_MEDFORD ||
577 enp->en_family == EFX_FAMILY_MEDFORD2);
579 hash = ef10_filter_hash(spec);
582 * FIXME: Add support for inserting filters of different priorities
583 * and removing lower priority multicast filters (bug 42378)
587 * Find any existing filters with the same match tuple or
588 * else a free slot to insert at. If any of them are busy,
589 * we have to wait and retry.
594 EFSYS_LOCK(enp->en_eslp, state);
598 i = (hash + depth) & (EFX_EF10_FILTER_TBL_ROWS - 1);
599 saved_spec = ef10_filter_entry_spec(eftp, i);
605 } else if (ef10_filter_equal(spec, saved_spec)) {
606 if (ef10_filter_entry_is_busy(eftp, i))
608 if (saved_spec->efs_priority
609 == EFX_FILTER_PRI_AUTO) {
612 } else if (ef10_filter_is_exclusive(spec)) {
626 * Once we reach the maximum search depth, use
627 * the first suitable slot or return EBUSY if
630 if (depth == EF10_FILTER_SEARCH_LIMIT) {
639 EFSYS_UNLOCK(enp->en_eslp, state);
645 * Create a software table entry if necessary, and mark it
646 * busy. We might yet fail to insert, but any attempt to
647 * insert a conflicting filter while we're waiting for the
648 * firmware must find the busy entry.
650 saved_spec = ef10_filter_entry_spec(eftp, ins_index);
652 if (saved_spec->efs_priority == EFX_FILTER_PRI_AUTO) {
653 /* This is a filter we are refreshing */
654 ef10_filter_set_entry_not_auto_old(eftp, ins_index);
660 EFSYS_KMEM_ALLOC(enp->en_esip, sizeof (*spec), saved_spec);
666 ef10_filter_set_entry(eftp, ins_index, saved_spec);
668 ef10_filter_set_entry_busy(eftp, ins_index);
670 EFSYS_UNLOCK(enp->en_eslp, state);
674 * On replacing the filter handle may change after after a successful
678 rc = efx_mcdi_filter_op_add(enp, spec,
679 MC_CMD_FILTER_OP_IN_OP_REPLACE,
680 &eftp->eft_entry[ins_index].efe_handle);
681 } else if (ef10_filter_is_exclusive(spec)) {
682 rc = efx_mcdi_filter_op_add(enp, spec,
683 MC_CMD_FILTER_OP_IN_OP_INSERT,
684 &eftp->eft_entry[ins_index].efe_handle);
686 rc = efx_mcdi_filter_op_add(enp, spec,
687 MC_CMD_FILTER_OP_IN_OP_SUBSCRIBE,
688 &eftp->eft_entry[ins_index].efe_handle);
694 EFSYS_LOCK(enp->en_eslp, state);
698 /* Update the fields that may differ */
699 saved_spec->efs_priority = spec->efs_priority;
700 saved_spec->efs_flags = spec->efs_flags;
701 saved_spec->efs_rss_context = spec->efs_rss_context;
702 saved_spec->efs_dmaq_id = spec->efs_dmaq_id;
705 ef10_filter_set_entry_not_busy(eftp, ins_index);
709 EFSYS_UNLOCK(enp->en_eslp, state);
713 *filter_id = ins_index;
721 EFSYS_KMEM_FREE(enp->en_esip, sizeof (*spec), saved_spec);
724 ef10_filter_set_entry_not_busy(eftp, ins_index);
725 ef10_filter_set_entry(eftp, ins_index, NULL);
734 EFSYS_PROBE1(fail1, efx_rc_t, rc);
737 EFSYS_UNLOCK(enp->en_eslp, state);
742 __checkReturn efx_rc_t
745 __inout efx_filter_spec_t *spec,
746 __in boolean_t may_replace)
750 rc = ef10_filter_add_internal(enp, spec, may_replace, NULL);
757 EFSYS_PROBE1(fail1, efx_rc_t, rc);
763 static __checkReturn efx_rc_t
764 ef10_filter_delete_internal(
766 __in uint32_t filter_id)
769 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
770 efx_filter_spec_t *spec;
771 efsys_lock_state_t state;
772 uint32_t filter_idx = filter_id % EFX_EF10_FILTER_TBL_ROWS;
775 * Find the software table entry and mark it busy. Don't
776 * remove it yet; any attempt to update while we're waiting
777 * for the firmware must find the busy entry.
779 * FIXME: What if the busy flag is never cleared?
781 EFSYS_LOCK(enp->en_eslp, state);
782 while (ef10_filter_entry_is_busy(table, filter_idx)) {
783 EFSYS_UNLOCK(enp->en_eslp, state);
785 EFSYS_LOCK(enp->en_eslp, state);
787 if ((spec = ef10_filter_entry_spec(table, filter_idx)) != NULL) {
788 ef10_filter_set_entry_busy(table, filter_idx);
790 EFSYS_UNLOCK(enp->en_eslp, state);
798 * Try to remove the hardware filter. This may fail if the MC has
799 * rebooted (which frees all hardware filter resources).
801 if (ef10_filter_is_exclusive(spec)) {
802 rc = efx_mcdi_filter_op_delete(enp,
803 MC_CMD_FILTER_OP_IN_OP_REMOVE,
804 &table->eft_entry[filter_idx].efe_handle);
806 rc = efx_mcdi_filter_op_delete(enp,
807 MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE,
808 &table->eft_entry[filter_idx].efe_handle);
811 /* Free the software table entry */
812 EFSYS_LOCK(enp->en_eslp, state);
813 ef10_filter_set_entry_not_busy(table, filter_idx);
814 ef10_filter_set_entry(table, filter_idx, NULL);
815 EFSYS_UNLOCK(enp->en_eslp, state);
817 EFSYS_KMEM_FREE(enp->en_esip, sizeof (*spec), spec);
819 /* Check result of hardware filter removal */
829 EFSYS_PROBE1(fail1, efx_rc_t, rc);
834 __checkReturn efx_rc_t
837 __inout efx_filter_spec_t *spec)
840 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
841 efx_filter_spec_t *saved_spec;
845 efsys_lock_state_t state;
846 boolean_t locked = B_FALSE;
848 EFSYS_ASSERT(enp->en_family == EFX_FAMILY_HUNTINGTON ||
849 enp->en_family == EFX_FAMILY_MEDFORD ||
850 enp->en_family == EFX_FAMILY_MEDFORD2);
852 hash = ef10_filter_hash(spec);
854 EFSYS_LOCK(enp->en_eslp, state);
859 i = (hash + depth) & (EFX_EF10_FILTER_TBL_ROWS - 1);
860 saved_spec = ef10_filter_entry_spec(table, i);
861 if (saved_spec && ef10_filter_equal(spec, saved_spec) &&
862 ef10_filter_same_dest(spec, saved_spec)) {
865 if (depth == EF10_FILTER_SEARCH_LIMIT) {
872 EFSYS_UNLOCK(enp->en_eslp, state);
875 rc = ef10_filter_delete_internal(enp, i);
885 EFSYS_PROBE1(fail1, efx_rc_t, rc);
888 EFSYS_UNLOCK(enp->en_eslp, state);
893 static __checkReturn efx_rc_t
894 efx_mcdi_get_parser_disp_info(
896 __out_ecount(buffer_length) uint32_t *buffer,
897 __in size_t buffer_length,
898 __in boolean_t encap,
899 __out size_t *list_lengthp)
902 uint8_t payload[MAX(MC_CMD_GET_PARSER_DISP_INFO_IN_LEN,
903 MC_CMD_GET_PARSER_DISP_INFO_OUT_LENMAX)];
904 size_t matches_count;
908 (void) memset(payload, 0, sizeof (payload));
909 req.emr_cmd = MC_CMD_GET_PARSER_DISP_INFO;
910 req.emr_in_buf = payload;
911 req.emr_in_length = MC_CMD_GET_PARSER_DISP_INFO_IN_LEN;
912 req.emr_out_buf = payload;
913 req.emr_out_length = MC_CMD_GET_PARSER_DISP_INFO_OUT_LENMAX;
915 MCDI_IN_SET_DWORD(req, GET_PARSER_DISP_INFO_OUT_OP, encap ?
916 MC_CMD_GET_PARSER_DISP_INFO_IN_OP_GET_SUPPORTED_ENCAP_RX_MATCHES :
917 MC_CMD_GET_PARSER_DISP_INFO_IN_OP_GET_SUPPORTED_RX_MATCHES);
919 efx_mcdi_execute(enp, &req);
921 if (req.emr_rc != 0) {
926 matches_count = MCDI_OUT_DWORD(req,
927 GET_PARSER_DISP_INFO_OUT_NUM_SUPPORTED_MATCHES);
929 if (req.emr_out_length_used <
930 MC_CMD_GET_PARSER_DISP_INFO_OUT_LEN(matches_count)) {
935 *list_lengthp = matches_count;
937 if (buffer_length < matches_count) {
943 * Check that the elements in the list in the MCDI response are the size
944 * we expect, so we can just copy them directly. Any conversion of the
945 * flags is handled by the caller.
947 EFX_STATIC_ASSERT(sizeof (uint32_t) ==
948 MC_CMD_GET_PARSER_DISP_INFO_OUT_SUPPORTED_MATCHES_LEN);
950 list_size = matches_count *
951 MC_CMD_GET_PARSER_DISP_INFO_OUT_SUPPORTED_MATCHES_LEN;
953 MCDI_OUT2(req, uint32_t,
954 GET_PARSER_DISP_INFO_OUT_SUPPORTED_MATCHES),
964 EFSYS_PROBE1(fail1, efx_rc_t, rc);
969 __checkReturn efx_rc_t
970 ef10_filter_supported_filters(
972 __out_ecount(buffer_length) uint32_t *buffer,
973 __in size_t buffer_length,
974 __out size_t *list_lengthp)
976 efx_nic_cfg_t *encp = &(enp->en_nic_cfg);
977 size_t mcdi_list_length;
978 size_t mcdi_encap_list_length;
981 uint32_t next_buf_idx;
982 size_t next_buf_length;
984 boolean_t no_space = B_FALSE;
985 efx_filter_match_flags_t all_filter_flags =
986 (EFX_FILTER_MATCH_REM_HOST | EFX_FILTER_MATCH_LOC_HOST |
987 EFX_FILTER_MATCH_REM_MAC | EFX_FILTER_MATCH_REM_PORT |
988 EFX_FILTER_MATCH_LOC_MAC | EFX_FILTER_MATCH_LOC_PORT |
989 EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_INNER_VID |
990 EFX_FILTER_MATCH_OUTER_VID | EFX_FILTER_MATCH_IP_PROTO |
991 EFX_FILTER_MATCH_IFRM_UNKNOWN_MCAST_DST |
992 EFX_FILTER_MATCH_IFRM_UNKNOWN_UCAST_DST |
993 EFX_FILTER_MATCH_UNKNOWN_MCAST_DST |
994 EFX_FILTER_MATCH_UNKNOWN_UCAST_DST);
997 * Two calls to MC_CMD_GET_PARSER_DISP_INFO are needed: one to get the
998 * list of supported filters for ordinary packets, and then another to
999 * get the list of supported filters for encapsulated packets.
1001 rc = efx_mcdi_get_parser_disp_info(enp, buffer, buffer_length, B_FALSE,
1012 next_buf_length = 0;
1014 EFSYS_ASSERT(mcdi_list_length <= buffer_length);
1015 next_buf_idx = mcdi_list_length;
1016 next_buf_length = buffer_length - mcdi_list_length;
1019 if (encp->enc_tunnel_encapsulations_supported != 0) {
1020 rc = efx_mcdi_get_parser_disp_info(enp, &buffer[next_buf_idx],
1021 next_buf_length, B_TRUE, &mcdi_encap_list_length);
1029 mcdi_encap_list_length = 0;
1033 *list_lengthp = mcdi_list_length + mcdi_encap_list_length;
1039 * The static assertions in ef10_filter_init() ensure that the values of
1040 * the EFX_FILTER_MATCH flags match those used by MCDI, so they don't
1041 * need to be converted.
1043 * In case support is added to MCDI for additional flags, remove any
1044 * matches from the list which include flags we don't support. The order
1045 * of the matches is preserved as they are ordered from highest to
1048 EFSYS_ASSERT(mcdi_list_length + mcdi_encap_list_length <=
1051 for (i = 0; i < mcdi_list_length + mcdi_encap_list_length; i++) {
1052 if ((buffer[i] & ~all_filter_flags) == 0) {
1053 buffer[list_length] = buffer[i];
1058 *list_lengthp = list_length;
1067 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1072 static __checkReturn efx_rc_t
1073 ef10_filter_insert_unicast(
1074 __in efx_nic_t *enp,
1075 __in_ecount(6) uint8_t const *addr,
1076 __in efx_filter_flags_t filter_flags)
1078 ef10_filter_table_t *eftp = enp->en_filter.ef_ef10_filter_table;
1079 efx_filter_spec_t spec;
1082 /* Insert the filter for the local station address */
1083 efx_filter_spec_init_rx(&spec, EFX_FILTER_PRI_AUTO,
1085 eftp->eft_default_rxq);
1086 efx_filter_spec_set_eth_local(&spec, EFX_FILTER_SPEC_VID_UNSPEC, addr);
1088 rc = ef10_filter_add_internal(enp, &spec, B_TRUE,
1089 &eftp->eft_unicst_filter_indexes[eftp->eft_unicst_filter_count]);
1093 eftp->eft_unicst_filter_count++;
1094 EFSYS_ASSERT(eftp->eft_unicst_filter_count <=
1095 EFX_EF10_FILTER_UNICAST_FILTERS_MAX);
1100 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1104 static __checkReturn efx_rc_t
1105 ef10_filter_insert_all_unicast(
1106 __in efx_nic_t *enp,
1107 __in efx_filter_flags_t filter_flags)
1109 ef10_filter_table_t *eftp = enp->en_filter.ef_ef10_filter_table;
1110 efx_filter_spec_t spec;
1113 /* Insert the unknown unicast filter */
1114 efx_filter_spec_init_rx(&spec, EFX_FILTER_PRI_AUTO,
1116 eftp->eft_default_rxq);
1117 efx_filter_spec_set_uc_def(&spec);
1118 rc = ef10_filter_add_internal(enp, &spec, B_TRUE,
1119 &eftp->eft_unicst_filter_indexes[eftp->eft_unicst_filter_count]);
1123 eftp->eft_unicst_filter_count++;
1124 EFSYS_ASSERT(eftp->eft_unicst_filter_count <=
1125 EFX_EF10_FILTER_UNICAST_FILTERS_MAX);
1130 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1134 static __checkReturn efx_rc_t
1135 ef10_filter_insert_multicast_list(
1136 __in efx_nic_t *enp,
1137 __in boolean_t mulcst,
1138 __in boolean_t brdcst,
1139 __in_ecount(6*count) uint8_t const *addrs,
1140 __in uint32_t count,
1141 __in efx_filter_flags_t filter_flags,
1142 __in boolean_t rollback)
1144 ef10_filter_table_t *eftp = enp->en_filter.ef_ef10_filter_table;
1145 efx_filter_spec_t spec;
1148 uint32_t filter_index;
1149 uint32_t filter_count;
1152 if (mulcst == B_FALSE)
1155 if (count + (brdcst ? 1 : 0) >
1156 EFX_ARRAY_SIZE(eftp->eft_mulcst_filter_indexes)) {
1157 /* Too many MAC addresses */
1162 /* Insert/renew multicast address list filters */
1164 for (i = 0; i < count; i++) {
1165 efx_filter_spec_init_rx(&spec,
1166 EFX_FILTER_PRI_AUTO,
1168 eftp->eft_default_rxq);
1170 efx_filter_spec_set_eth_local(&spec,
1171 EFX_FILTER_SPEC_VID_UNSPEC,
1172 &addrs[i * EFX_MAC_ADDR_LEN]);
1174 rc = ef10_filter_add_internal(enp, &spec, B_TRUE,
1178 eftp->eft_mulcst_filter_indexes[filter_count] =
1181 } else if (rollback == B_TRUE) {
1182 /* Only stop upon failure if told to rollback */
1188 if (brdcst == B_TRUE) {
1189 /* Insert/renew broadcast address filter */
1190 efx_filter_spec_init_rx(&spec, EFX_FILTER_PRI_AUTO,
1192 eftp->eft_default_rxq);
1194 EFX_MAC_BROADCAST_ADDR_SET(addr);
1195 efx_filter_spec_set_eth_local(&spec, EFX_FILTER_SPEC_VID_UNSPEC,
1198 rc = ef10_filter_add_internal(enp, &spec, B_TRUE,
1202 eftp->eft_mulcst_filter_indexes[filter_count] =
1205 } else if (rollback == B_TRUE) {
1206 /* Only stop upon failure if told to rollback */
1211 eftp->eft_mulcst_filter_count = filter_count;
1212 eftp->eft_using_all_mulcst = B_FALSE;
1217 /* Remove any filters we have inserted */
1220 (void) ef10_filter_delete_internal(enp,
1221 eftp->eft_mulcst_filter_indexes[i]);
1223 eftp->eft_mulcst_filter_count = 0;
1226 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1231 static __checkReturn efx_rc_t
1232 ef10_filter_insert_all_multicast(
1233 __in efx_nic_t *enp,
1234 __in efx_filter_flags_t filter_flags)
1236 ef10_filter_table_t *eftp = enp->en_filter.ef_ef10_filter_table;
1237 efx_filter_spec_t spec;
1240 /* Insert the unknown multicast filter */
1241 efx_filter_spec_init_rx(&spec, EFX_FILTER_PRI_AUTO,
1243 eftp->eft_default_rxq);
1244 efx_filter_spec_set_mc_def(&spec);
1246 rc = ef10_filter_add_internal(enp, &spec, B_TRUE,
1247 &eftp->eft_mulcst_filter_indexes[0]);
1251 eftp->eft_mulcst_filter_count = 1;
1252 eftp->eft_using_all_mulcst = B_TRUE;
1255 * FIXME: If brdcst == B_FALSE, add a filter to drop broadcast traffic.
1261 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1266 typedef struct ef10_filter_encap_entry_s {
1267 uint16_t ether_type;
1268 efx_tunnel_protocol_t encap_type;
1269 uint32_t inner_frame_match;
1270 } ef10_filter_encap_entry_t;
1272 #define EF10_ENCAP_FILTER_ENTRY(ipv, encap_type, inner_frame_match) \
1273 { EFX_ETHER_TYPE_##ipv, EFX_TUNNEL_PROTOCOL_##encap_type, \
1274 EFX_FILTER_INNER_FRAME_MATCH_UNKNOWN_##inner_frame_match }
1276 static ef10_filter_encap_entry_t ef10_filter_encap_list[] = {
1277 EF10_ENCAP_FILTER_ENTRY(IPV4, VXLAN, UCAST_DST),
1278 EF10_ENCAP_FILTER_ENTRY(IPV4, VXLAN, MCAST_DST),
1279 EF10_ENCAP_FILTER_ENTRY(IPV6, VXLAN, UCAST_DST),
1280 EF10_ENCAP_FILTER_ENTRY(IPV6, VXLAN, MCAST_DST),
1282 EF10_ENCAP_FILTER_ENTRY(IPV4, GENEVE, UCAST_DST),
1283 EF10_ENCAP_FILTER_ENTRY(IPV4, GENEVE, MCAST_DST),
1284 EF10_ENCAP_FILTER_ENTRY(IPV6, GENEVE, UCAST_DST),
1285 EF10_ENCAP_FILTER_ENTRY(IPV6, GENEVE, MCAST_DST),
1287 EF10_ENCAP_FILTER_ENTRY(IPV4, NVGRE, UCAST_DST),
1288 EF10_ENCAP_FILTER_ENTRY(IPV4, NVGRE, MCAST_DST),
1289 EF10_ENCAP_FILTER_ENTRY(IPV6, NVGRE, UCAST_DST),
1290 EF10_ENCAP_FILTER_ENTRY(IPV6, NVGRE, MCAST_DST),
1293 #undef EF10_ENCAP_FILTER_ENTRY
1295 static __checkReturn efx_rc_t
1296 ef10_filter_insert_encap_filters(
1297 __in efx_nic_t *enp,
1298 __in boolean_t mulcst,
1299 __in efx_filter_flags_t filter_flags)
1301 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
1305 EFX_STATIC_ASSERT(EFX_ARRAY_SIZE(ef10_filter_encap_list) <=
1306 EFX_ARRAY_SIZE(table->eft_encap_filter_indexes));
1309 * On Medford, full-featured firmware can identify packets as being
1310 * tunnel encapsulated, even if no encapsulated packet offloads are in
1311 * use. When packets are identified as such, ordinary filters are not
1312 * applied, only ones specific to encapsulated packets. Hence we need to
1313 * insert filters for encapsulated packets in order to receive them.
1315 * Separate filters need to be inserted for each ether type,
1316 * encapsulation type, and inner frame type (unicast or multicast). To
1317 * keep things simple and reduce the number of filters needed, catch-all
1318 * filters for all combinations of types are inserted, even if
1319 * all_unicst or all_mulcst have not been set. (These catch-all filters
1320 * may well, however, fail to insert on unprivileged functions.)
1322 table->eft_encap_filter_count = 0;
1323 for (i = 0; i < EFX_ARRAY_SIZE(ef10_filter_encap_list); i++) {
1324 efx_filter_spec_t spec;
1325 ef10_filter_encap_entry_t *encap_filter =
1326 &ef10_filter_encap_list[i];
1329 * Skip multicast filters if we've not been asked for
1330 * any multicast traffic.
1332 if ((mulcst == B_FALSE) &&
1333 (encap_filter->inner_frame_match ==
1334 EFX_FILTER_INNER_FRAME_MATCH_UNKNOWN_MCAST_DST))
1337 efx_filter_spec_init_rx(&spec, EFX_FILTER_PRI_AUTO,
1339 table->eft_default_rxq);
1340 efx_filter_spec_set_ether_type(&spec, encap_filter->ether_type);
1341 rc = efx_filter_spec_set_encap_type(&spec,
1342 encap_filter->encap_type,
1343 encap_filter->inner_frame_match);
1347 rc = ef10_filter_add_internal(enp, &spec, B_TRUE,
1348 &table->eft_encap_filter_indexes[
1349 table->eft_encap_filter_count]);
1354 table->eft_encap_filter_count++;
1363 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1369 ef10_filter_remove_old(
1370 __in efx_nic_t *enp)
1372 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
1375 for (i = 0; i < EFX_ARRAY_SIZE(table->eft_entry); i++) {
1376 if (ef10_filter_entry_is_auto_old(table, i)) {
1377 (void) ef10_filter_delete_internal(enp, i);
1383 static __checkReturn efx_rc_t
1384 ef10_filter_get_workarounds(
1385 __in efx_nic_t *enp)
1387 efx_nic_cfg_t *encp = &enp->en_nic_cfg;
1388 uint32_t implemented = 0;
1389 uint32_t enabled = 0;
1392 rc = efx_mcdi_get_workarounds(enp, &implemented, &enabled);
1394 /* Check if chained multicast filter support is enabled */
1395 if (implemented & enabled & MC_CMD_GET_WORKAROUNDS_OUT_BUG26807)
1396 encp->enc_bug26807_workaround = B_TRUE;
1398 encp->enc_bug26807_workaround = B_FALSE;
1399 } else if (rc == ENOTSUP) {
1401 * Firmware is too old to support GET_WORKAROUNDS, and support
1402 * for this workaround was implemented later.
1404 encp->enc_bug26807_workaround = B_FALSE;
1412 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1420 * Reconfigure all filters.
1421 * If all_unicst and/or all mulcst filters cannot be applied then
1422 * return ENOTSUP (Note the filters for the specified addresses are
1423 * still applied in this case).
1425 __checkReturn efx_rc_t
1426 ef10_filter_reconfigure(
1427 __in efx_nic_t *enp,
1428 __in_ecount(6) uint8_t const *mac_addr,
1429 __in boolean_t all_unicst,
1430 __in boolean_t mulcst,
1431 __in boolean_t all_mulcst,
1432 __in boolean_t brdcst,
1433 __in_ecount(6*count) uint8_t const *addrs,
1434 __in uint32_t count)
1436 efx_nic_cfg_t *encp = &enp->en_nic_cfg;
1437 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
1438 efx_filter_flags_t filter_flags;
1440 efx_rc_t all_unicst_rc = 0;
1441 efx_rc_t all_mulcst_rc = 0;
1444 if (table->eft_default_rxq == NULL) {
1446 * Filters direct traffic to the default RXQ, and so cannot be
1447 * inserted until it is available. Any currently configured
1448 * filters must be removed (ignore errors in case the MC
1449 * has rebooted, which removes hardware filters).
1451 for (i = 0; i < table->eft_unicst_filter_count; i++) {
1452 (void) ef10_filter_delete_internal(enp,
1453 table->eft_unicst_filter_indexes[i]);
1455 table->eft_unicst_filter_count = 0;
1457 for (i = 0; i < table->eft_mulcst_filter_count; i++) {
1458 (void) ef10_filter_delete_internal(enp,
1459 table->eft_mulcst_filter_indexes[i]);
1461 table->eft_mulcst_filter_count = 0;
1463 for (i = 0; i < table->eft_encap_filter_count; i++) {
1464 (void) ef10_filter_delete_internal(enp,
1465 table->eft_encap_filter_indexes[i]);
1467 table->eft_encap_filter_count = 0;
1472 if (table->eft_using_rss)
1473 filter_flags = EFX_FILTER_FLAG_RX_RSS;
1477 /* Mark old filters which may need to be removed */
1478 for (i = 0; i < table->eft_unicst_filter_count; i++) {
1479 ef10_filter_set_entry_auto_old(table,
1480 table->eft_unicst_filter_indexes[i]);
1482 for (i = 0; i < table->eft_mulcst_filter_count; i++) {
1483 ef10_filter_set_entry_auto_old(table,
1484 table->eft_mulcst_filter_indexes[i]);
1486 for (i = 0; i < table->eft_encap_filter_count; i++) {
1487 ef10_filter_set_entry_auto_old(table,
1488 table->eft_encap_filter_indexes[i]);
1492 * Insert or renew unicast filters.
1494 * Frimware does not perform chaining on unicast filters. As traffic is
1495 * therefore only delivered to the first matching filter, we should
1496 * always insert the specific filter for our MAC address, to try and
1497 * ensure we get that traffic.
1499 * (If the filter for our MAC address has already been inserted by
1500 * another function, we won't receive traffic sent to us, even if we
1501 * insert a unicast mismatch filter. To prevent traffic stealing, this
1502 * therefore relies on the privilege model only allowing functions to
1503 * insert filters for their own MAC address unless explicitly given
1504 * additional privileges by the user. This also means that, even on a
1505 * priviliged function, inserting a unicast mismatch filter may not
1506 * catch all traffic in multi PCI function scenarios.)
1508 table->eft_unicst_filter_count = 0;
1509 rc = ef10_filter_insert_unicast(enp, mac_addr, filter_flags);
1510 if (all_unicst || (rc != 0)) {
1511 all_unicst_rc = ef10_filter_insert_all_unicast(enp,
1513 if ((rc != 0) && (all_unicst_rc != 0))
1518 * WORKAROUND_BUG26807 controls firmware support for chained multicast
1519 * filters, and can only be enabled or disabled when the hardware filter
1522 * Chained multicast filters require support from the datapath firmware,
1523 * and may not be available (e.g. low-latency variants or old Huntington
1526 * Firmware will reset (FLR) functions which have inserted filters in
1527 * the hardware filter table when the workaround is enabled/disabled.
1528 * Functions without any hardware filters are not reset.
1530 * Re-check if the workaround is enabled after adding unicast hardware
1531 * filters. This ensures that encp->enc_bug26807_workaround matches the
1532 * firmware state, and that later changes to enable/disable the
1533 * workaround will result in this function seeing a reset (FLR).
1535 * In common-code drivers, we only support multiple PCI function
1536 * scenarios with firmware that supports multicast chaining, so we can
1537 * assume it is enabled for such cases and hence simplify the filter
1538 * insertion logic. Firmware that does not support multicast chaining
1539 * does not support multiple PCI function configurations either, so
1540 * filter insertion is much simpler and the same strategies can still be
1543 if ((rc = ef10_filter_get_workarounds(enp)) != 0)
1546 if ((table->eft_using_all_mulcst != all_mulcst) &&
1547 (encp->enc_bug26807_workaround == B_TRUE)) {
1549 * Multicast filter chaining is enabled, so traffic that matches
1550 * more than one multicast filter will be replicated and
1551 * delivered to multiple recipients. To avoid this duplicate
1552 * delivery, remove old multicast filters before inserting new
1553 * multicast filters.
1555 ef10_filter_remove_old(enp);
1558 /* Insert or renew multicast filters */
1559 if (all_mulcst == B_TRUE) {
1561 * Insert the all multicast filter. If that fails, try to insert
1562 * all of our multicast filters (but without rollback on
1565 all_mulcst_rc = ef10_filter_insert_all_multicast(enp,
1567 if (all_mulcst_rc != 0) {
1568 rc = ef10_filter_insert_multicast_list(enp, B_TRUE,
1569 brdcst, addrs, count, filter_flags, B_FALSE);
1575 * Insert filters for multicast addresses.
1576 * If any insertion fails, then rollback and try to insert the
1577 * all multicast filter instead.
1578 * If that also fails, try to insert all of the multicast
1579 * filters (but without rollback on failure).
1581 rc = ef10_filter_insert_multicast_list(enp, mulcst, brdcst,
1582 addrs, count, filter_flags, B_TRUE);
1584 if ((table->eft_using_all_mulcst == B_FALSE) &&
1585 (encp->enc_bug26807_workaround == B_TRUE)) {
1587 * Multicast filter chaining is on, so remove
1588 * old filters before inserting the multicast
1589 * all filter to avoid duplicate delivery caused
1590 * by packets matching multiple filters.
1592 ef10_filter_remove_old(enp);
1595 rc = ef10_filter_insert_all_multicast(enp,
1598 rc = ef10_filter_insert_multicast_list(enp,
1600 addrs, count, filter_flags, B_FALSE);
1607 if (encp->enc_tunnel_encapsulations_supported != 0) {
1608 /* Try to insert filters for encapsulated packets. */
1609 (void) ef10_filter_insert_encap_filters(enp,
1610 mulcst || all_mulcst || brdcst,
1614 /* Remove old filters which were not renewed */
1615 ef10_filter_remove_old(enp);
1617 /* report if any optional flags were rejected */
1618 if (((all_unicst != B_FALSE) && (all_unicst_rc != 0)) ||
1619 ((all_mulcst != B_FALSE) && (all_mulcst_rc != 0))) {
1632 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1634 /* Clear auto old flags */
1635 for (i = 0; i < EFX_ARRAY_SIZE(table->eft_entry); i++) {
1636 if (ef10_filter_entry_is_auto_old(table, i)) {
1637 ef10_filter_set_entry_not_auto_old(table, i);
1645 ef10_filter_get_default_rxq(
1646 __in efx_nic_t *enp,
1647 __out efx_rxq_t **erpp,
1648 __out boolean_t *using_rss)
1650 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
1652 *erpp = table->eft_default_rxq;
1653 *using_rss = table->eft_using_rss;
1658 ef10_filter_default_rxq_set(
1659 __in efx_nic_t *enp,
1660 __in efx_rxq_t *erp,
1661 __in boolean_t using_rss)
1663 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
1665 #if EFSYS_OPT_RX_SCALE
1666 EFSYS_ASSERT((using_rss == B_FALSE) ||
1667 (enp->en_rss_context != EF10_RSS_CONTEXT_INVALID));
1668 table->eft_using_rss = using_rss;
1670 EFSYS_ASSERT(using_rss == B_FALSE);
1671 table->eft_using_rss = B_FALSE;
1673 table->eft_default_rxq = erp;
1677 ef10_filter_default_rxq_clear(
1678 __in efx_nic_t *enp)
1680 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
1682 table->eft_default_rxq = NULL;
1683 table->eft_using_rss = B_FALSE;
1687 #endif /* EFSYS_OPT_FILTER */
1689 #endif /* EFSYS_OPT_HUNTINGTON || EFSYS_OPT_MEDFORD || EFSYS_OPT_MEDFORD2 */