1 /* SPDX-License-Identifier: BSD-3-Clause
3 * Copyright (c) 2007-2018 Solarflare Communications Inc.
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(EFX_FAMILY_IS_EF10(enp));
99 #define MATCH_MASK(match) (EFX_MASK32(match) << EFX_LOW_BIT(match))
100 EFX_STATIC_ASSERT(EFX_FILTER_MATCH_REM_HOST ==
101 MATCH_MASK(MC_CMD_FILTER_OP_EXT_IN_MATCH_SRC_IP));
102 EFX_STATIC_ASSERT(EFX_FILTER_MATCH_LOC_HOST ==
103 MATCH_MASK(MC_CMD_FILTER_OP_EXT_IN_MATCH_DST_IP));
104 EFX_STATIC_ASSERT(EFX_FILTER_MATCH_REM_MAC ==
105 MATCH_MASK(MC_CMD_FILTER_OP_EXT_IN_MATCH_SRC_MAC));
106 EFX_STATIC_ASSERT(EFX_FILTER_MATCH_REM_PORT ==
107 MATCH_MASK(MC_CMD_FILTER_OP_EXT_IN_MATCH_SRC_PORT));
108 EFX_STATIC_ASSERT(EFX_FILTER_MATCH_LOC_MAC ==
109 MATCH_MASK(MC_CMD_FILTER_OP_EXT_IN_MATCH_DST_MAC));
110 EFX_STATIC_ASSERT(EFX_FILTER_MATCH_LOC_PORT ==
111 MATCH_MASK(MC_CMD_FILTER_OP_EXT_IN_MATCH_DST_PORT));
112 EFX_STATIC_ASSERT(EFX_FILTER_MATCH_ETHER_TYPE ==
113 MATCH_MASK(MC_CMD_FILTER_OP_EXT_IN_MATCH_ETHER_TYPE));
114 EFX_STATIC_ASSERT(EFX_FILTER_MATCH_INNER_VID ==
115 MATCH_MASK(MC_CMD_FILTER_OP_EXT_IN_MATCH_INNER_VLAN));
116 EFX_STATIC_ASSERT(EFX_FILTER_MATCH_OUTER_VID ==
117 MATCH_MASK(MC_CMD_FILTER_OP_EXT_IN_MATCH_OUTER_VLAN));
118 EFX_STATIC_ASSERT(EFX_FILTER_MATCH_IP_PROTO ==
119 MATCH_MASK(MC_CMD_FILTER_OP_EXT_IN_MATCH_IP_PROTO));
120 EFX_STATIC_ASSERT(EFX_FILTER_MATCH_VNI_OR_VSID ==
121 MATCH_MASK(MC_CMD_FILTER_OP_EXT_IN_MATCH_VNI_OR_VSID));
122 EFX_STATIC_ASSERT(EFX_FILTER_MATCH_IFRM_LOC_MAC ==
123 MATCH_MASK(MC_CMD_FILTER_OP_EXT_IN_MATCH_IFRM_DST_MAC));
124 EFX_STATIC_ASSERT(EFX_FILTER_MATCH_IFRM_UNKNOWN_MCAST_DST ==
125 MATCH_MASK(MC_CMD_FILTER_OP_EXT_IN_MATCH_IFRM_UNKNOWN_MCAST_DST));
126 EFX_STATIC_ASSERT(EFX_FILTER_MATCH_IFRM_UNKNOWN_UCAST_DST ==
127 MATCH_MASK(MC_CMD_FILTER_OP_EXT_IN_MATCH_IFRM_UNKNOWN_UCAST_DST));
128 EFX_STATIC_ASSERT(EFX_FILTER_MATCH_UNKNOWN_MCAST_DST ==
129 MATCH_MASK(MC_CMD_FILTER_OP_EXT_IN_MATCH_UNKNOWN_MCAST_DST));
130 EFX_STATIC_ASSERT((uint32_t)EFX_FILTER_MATCH_UNKNOWN_UCAST_DST ==
131 MATCH_MASK(MC_CMD_FILTER_OP_EXT_IN_MATCH_UNKNOWN_UCAST_DST));
134 EFSYS_KMEM_ALLOC(enp->en_esip, sizeof (ef10_filter_table_t), eftp);
141 enp->en_filter.ef_ef10_filter_table = eftp;
146 EFSYS_PROBE1(fail1, efx_rc_t, rc);
155 EFSYS_ASSERT(EFX_FAMILY_IS_EF10(enp));
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 EFX_MCDI_DECLARE_BUF(payload, MC_CMD_FILTER_OP_V3_IN_LEN,
172 MC_CMD_FILTER_OP_EXT_OUT_LEN);
173 efx_filter_match_flags_t match_flags;
176 req.emr_cmd = MC_CMD_FILTER_OP;
177 req.emr_in_buf = payload;
178 req.emr_in_length = MC_CMD_FILTER_OP_V3_IN_LEN;
179 req.emr_out_buf = payload;
180 req.emr_out_length = MC_CMD_FILTER_OP_EXT_OUT_LEN;
183 * Remove match flag for encapsulated filters that does not correspond
184 * to the MCDI match flags
186 match_flags = spec->efs_match_flags & ~EFX_FILTER_MATCH_ENCAP_TYPE;
189 case MC_CMD_FILTER_OP_IN_OP_REPLACE:
190 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_HANDLE_LO,
192 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_HANDLE_HI,
195 case MC_CMD_FILTER_OP_IN_OP_INSERT:
196 case MC_CMD_FILTER_OP_IN_OP_SUBSCRIBE:
197 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_OP, filter_op);
205 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_PORT_ID, enp->en_vport_id);
206 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_MATCH_FIELDS,
208 if (spec->efs_dmaq_id == EFX_FILTER_SPEC_RX_DMAQ_ID_DROP) {
209 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_RX_DEST,
210 MC_CMD_FILTER_OP_EXT_IN_RX_DEST_DROP);
212 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_RX_DEST,
213 MC_CMD_FILTER_OP_EXT_IN_RX_DEST_HOST);
214 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_RX_QUEUE,
218 #if EFSYS_OPT_RX_SCALE
219 if (spec->efs_flags & EFX_FILTER_FLAG_RX_RSS) {
220 uint32_t rss_context;
222 if (spec->efs_rss_context == EFX_RSS_CONTEXT_DEFAULT)
223 rss_context = enp->en_rss_context;
225 rss_context = spec->efs_rss_context;
226 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_RX_CONTEXT,
231 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_RX_MODE,
232 spec->efs_flags & EFX_FILTER_FLAG_RX_RSS ?
233 MC_CMD_FILTER_OP_EXT_IN_RX_MODE_RSS :
234 MC_CMD_FILTER_OP_EXT_IN_RX_MODE_SIMPLE);
235 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_TX_DEST,
236 MC_CMD_FILTER_OP_EXT_IN_TX_DEST_DEFAULT);
238 if (filter_op != MC_CMD_FILTER_OP_IN_OP_REPLACE) {
240 * NOTE: Unlike most MCDI requests, the filter fields
241 * are presented in network (big endian) byte order.
243 memcpy(MCDI_IN2(req, uint8_t, FILTER_OP_EXT_IN_SRC_MAC),
244 spec->efs_rem_mac, EFX_MAC_ADDR_LEN);
245 memcpy(MCDI_IN2(req, uint8_t, FILTER_OP_EXT_IN_DST_MAC),
246 spec->efs_loc_mac, EFX_MAC_ADDR_LEN);
248 MCDI_IN_SET_WORD(req, FILTER_OP_EXT_IN_SRC_PORT,
249 __CPU_TO_BE_16(spec->efs_rem_port));
250 MCDI_IN_SET_WORD(req, FILTER_OP_EXT_IN_DST_PORT,
251 __CPU_TO_BE_16(spec->efs_loc_port));
253 MCDI_IN_SET_WORD(req, FILTER_OP_EXT_IN_ETHER_TYPE,
254 __CPU_TO_BE_16(spec->efs_ether_type));
256 MCDI_IN_SET_WORD(req, FILTER_OP_EXT_IN_INNER_VLAN,
257 __CPU_TO_BE_16(spec->efs_inner_vid));
258 MCDI_IN_SET_WORD(req, FILTER_OP_EXT_IN_OUTER_VLAN,
259 __CPU_TO_BE_16(spec->efs_outer_vid));
261 /* IP protocol (in low byte, high byte is zero) */
262 MCDI_IN_SET_BYTE(req, FILTER_OP_EXT_IN_IP_PROTO,
265 EFX_STATIC_ASSERT(sizeof (spec->efs_rem_host) ==
266 MC_CMD_FILTER_OP_EXT_IN_SRC_IP_LEN);
267 EFX_STATIC_ASSERT(sizeof (spec->efs_loc_host) ==
268 MC_CMD_FILTER_OP_EXT_IN_DST_IP_LEN);
270 memcpy(MCDI_IN2(req, uint8_t, FILTER_OP_EXT_IN_SRC_IP),
271 &spec->efs_rem_host.eo_byte[0],
272 MC_CMD_FILTER_OP_EXT_IN_SRC_IP_LEN);
273 memcpy(MCDI_IN2(req, uint8_t, FILTER_OP_EXT_IN_DST_IP),
274 &spec->efs_loc_host.eo_byte[0],
275 MC_CMD_FILTER_OP_EXT_IN_DST_IP_LEN);
278 * On Medford, filters for encapsulated packets match based on
279 * the ether type and IP protocol in the outer frame. In
280 * addition we need to fill in the VNI or VSID type field.
282 switch (spec->efs_encap_type) {
283 case EFX_TUNNEL_PROTOCOL_NONE:
285 case EFX_TUNNEL_PROTOCOL_VXLAN:
286 case EFX_TUNNEL_PROTOCOL_GENEVE:
287 MCDI_IN_POPULATE_DWORD_1(req,
288 FILTER_OP_EXT_IN_VNI_OR_VSID,
289 FILTER_OP_EXT_IN_VNI_TYPE,
290 spec->efs_encap_type == EFX_TUNNEL_PROTOCOL_VXLAN ?
291 MC_CMD_FILTER_OP_EXT_IN_VNI_TYPE_VXLAN :
292 MC_CMD_FILTER_OP_EXT_IN_VNI_TYPE_GENEVE);
294 case EFX_TUNNEL_PROTOCOL_NVGRE:
295 MCDI_IN_POPULATE_DWORD_1(req,
296 FILTER_OP_EXT_IN_VNI_OR_VSID,
297 FILTER_OP_EXT_IN_VSID_TYPE,
298 MC_CMD_FILTER_OP_EXT_IN_VSID_TYPE_NVGRE);
306 memcpy(MCDI_IN2(req, uint8_t, FILTER_OP_EXT_IN_VNI_OR_VSID),
307 spec->efs_vni_or_vsid, EFX_VNI_OR_VSID_LEN);
309 memcpy(MCDI_IN2(req, uint8_t, FILTER_OP_EXT_IN_IFRM_DST_MAC),
310 spec->efs_ifrm_loc_mac, EFX_MAC_ADDR_LEN);
314 * Set the "MARK" or "FLAG" action for all packets matching this filter
315 * if necessary (only useful with equal stride packed stream Rx mode
316 * which provide the information in pseudo-header).
317 * These actions require MC_CMD_FILTER_OP_V3_IN msgrequest.
319 if ((spec->efs_flags & EFX_FILTER_FLAG_ACTION_MARK) &&
320 (spec->efs_flags & EFX_FILTER_FLAG_ACTION_FLAG)) {
324 if (spec->efs_flags & EFX_FILTER_FLAG_ACTION_MARK) {
325 MCDI_IN_SET_DWORD(req, FILTER_OP_V3_IN_MATCH_ACTION,
326 MC_CMD_FILTER_OP_V3_IN_MATCH_ACTION_MARK);
327 MCDI_IN_SET_DWORD(req, FILTER_OP_V3_IN_MATCH_MARK_VALUE,
329 } else if (spec->efs_flags & EFX_FILTER_FLAG_ACTION_FLAG) {
330 MCDI_IN_SET_DWORD(req, FILTER_OP_V3_IN_MATCH_ACTION,
331 MC_CMD_FILTER_OP_V3_IN_MATCH_ACTION_FLAG);
334 efx_mcdi_execute(enp, &req);
336 if (req.emr_rc != 0) {
341 if (req.emr_out_length_used < MC_CMD_FILTER_OP_EXT_OUT_LEN) {
346 handle->efh_lo = MCDI_OUT_DWORD(req, FILTER_OP_EXT_OUT_HANDLE_LO);
347 handle->efh_hi = MCDI_OUT_DWORD(req, FILTER_OP_EXT_OUT_HANDLE_HI);
360 EFSYS_PROBE1(fail1, efx_rc_t, rc);
366 static __checkReturn efx_rc_t
367 efx_mcdi_filter_op_delete(
369 __in unsigned int filter_op,
370 __inout ef10_filter_handle_t *handle)
373 EFX_MCDI_DECLARE_BUF(payload, MC_CMD_FILTER_OP_EXT_IN_LEN,
374 MC_CMD_FILTER_OP_EXT_OUT_LEN);
377 req.emr_cmd = MC_CMD_FILTER_OP;
378 req.emr_in_buf = payload;
379 req.emr_in_length = MC_CMD_FILTER_OP_EXT_IN_LEN;
380 req.emr_out_buf = payload;
381 req.emr_out_length = MC_CMD_FILTER_OP_EXT_OUT_LEN;
384 case MC_CMD_FILTER_OP_IN_OP_REMOVE:
385 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_OP,
386 MC_CMD_FILTER_OP_IN_OP_REMOVE);
388 case MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE:
389 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_OP,
390 MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE);
398 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_HANDLE_LO, handle->efh_lo);
399 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_HANDLE_HI, handle->efh_hi);
401 efx_mcdi_execute_quiet(enp, &req);
403 if (req.emr_rc != 0) {
408 if (req.emr_out_length_used < MC_CMD_FILTER_OP_EXT_OUT_LEN) {
421 EFSYS_PROBE1(fail1, efx_rc_t, rc);
426 static __checkReturn boolean_t
428 __in const efx_filter_spec_t *left,
429 __in const efx_filter_spec_t *right)
431 /* FIXME: Consider rx vs tx filters (look at efs_flags) */
432 if (left->efs_match_flags != right->efs_match_flags)
434 if (!EFX_OWORD_IS_EQUAL(left->efs_rem_host, right->efs_rem_host))
436 if (!EFX_OWORD_IS_EQUAL(left->efs_loc_host, right->efs_loc_host))
438 if (memcmp(left->efs_rem_mac, right->efs_rem_mac, EFX_MAC_ADDR_LEN))
440 if (memcmp(left->efs_loc_mac, right->efs_loc_mac, EFX_MAC_ADDR_LEN))
442 if (left->efs_rem_port != right->efs_rem_port)
444 if (left->efs_loc_port != right->efs_loc_port)
446 if (left->efs_inner_vid != right->efs_inner_vid)
448 if (left->efs_outer_vid != right->efs_outer_vid)
450 if (left->efs_ether_type != right->efs_ether_type)
452 if (left->efs_ip_proto != right->efs_ip_proto)
454 if (left->efs_encap_type != right->efs_encap_type)
456 if (memcmp(left->efs_vni_or_vsid, right->efs_vni_or_vsid,
457 EFX_VNI_OR_VSID_LEN))
459 if (memcmp(left->efs_ifrm_loc_mac, right->efs_ifrm_loc_mac,
467 static __checkReturn boolean_t
468 ef10_filter_same_dest(
469 __in const efx_filter_spec_t *left,
470 __in const efx_filter_spec_t *right)
472 if ((left->efs_flags & EFX_FILTER_FLAG_RX_RSS) &&
473 (right->efs_flags & EFX_FILTER_FLAG_RX_RSS)) {
474 if (left->efs_rss_context == right->efs_rss_context)
476 } else if ((~(left->efs_flags) & EFX_FILTER_FLAG_RX_RSS) &&
477 (~(right->efs_flags) & EFX_FILTER_FLAG_RX_RSS)) {
478 if (left->efs_dmaq_id == right->efs_dmaq_id)
484 static __checkReturn uint32_t
486 __in efx_filter_spec_t *spec)
488 EFX_STATIC_ASSERT((sizeof (efx_filter_spec_t) % sizeof (uint32_t))
490 EFX_STATIC_ASSERT((EFX_FIELD_OFFSET(efx_filter_spec_t, efs_outer_vid) %
491 sizeof (uint32_t)) == 0);
494 * As the area of the efx_filter_spec_t we need to hash is DWORD
495 * aligned and an exact number of DWORDs in size we can use the
496 * optimised efx_hash_dwords() rather than efx_hash_bytes()
498 return (efx_hash_dwords((const uint32_t *)&spec->efs_outer_vid,
499 (sizeof (efx_filter_spec_t) -
500 EFX_FIELD_OFFSET(efx_filter_spec_t, efs_outer_vid)) /
501 sizeof (uint32_t), 0));
505 * Decide whether a filter should be exclusive or else should allow
506 * delivery to additional recipients. Currently we decide that
507 * filters for specific local unicast MAC and IP addresses are
510 static __checkReturn boolean_t
511 ef10_filter_is_exclusive(
512 __in efx_filter_spec_t *spec)
514 if ((spec->efs_match_flags & EFX_FILTER_MATCH_LOC_MAC) &&
515 !EFX_MAC_ADDR_IS_MULTICAST(spec->efs_loc_mac))
518 if ((spec->efs_match_flags &
519 (EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_LOC_HOST)) ==
520 (EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_LOC_HOST)) {
521 if ((spec->efs_ether_type == EFX_ETHER_TYPE_IPV4) &&
522 ((spec->efs_loc_host.eo_u8[0] & 0xf) != 0xe))
524 if ((spec->efs_ether_type == EFX_ETHER_TYPE_IPV6) &&
525 (spec->efs_loc_host.eo_u8[0] != 0xff))
532 __checkReturn efx_rc_t
537 efx_filter_spec_t *spec;
538 ef10_filter_table_t *eftp = enp->en_filter.ef_ef10_filter_table;
540 efsys_lock_state_t state;
543 EFSYS_ASSERT(EFX_FAMILY_IS_EF10(enp));
545 for (tbl_id = 0; tbl_id < EFX_EF10_FILTER_TBL_ROWS; tbl_id++) {
547 EFSYS_LOCK(enp->en_eslp, state);
549 spec = ef10_filter_entry_spec(eftp, tbl_id);
552 } else if (ef10_filter_entry_is_busy(eftp, tbl_id)) {
553 /* Ignore busy entries. */
556 ef10_filter_set_entry_busy(eftp, tbl_id);
560 EFSYS_UNLOCK(enp->en_eslp, state);
562 if (restoring == B_FALSE)
565 if (ef10_filter_is_exclusive(spec)) {
566 rc = efx_mcdi_filter_op_add(enp, spec,
567 MC_CMD_FILTER_OP_IN_OP_INSERT,
568 &eftp->eft_entry[tbl_id].efe_handle);
570 rc = efx_mcdi_filter_op_add(enp, spec,
571 MC_CMD_FILTER_OP_IN_OP_SUBSCRIBE,
572 &eftp->eft_entry[tbl_id].efe_handle);
578 EFSYS_LOCK(enp->en_eslp, state);
580 ef10_filter_set_entry_not_busy(eftp, tbl_id);
582 EFSYS_UNLOCK(enp->en_eslp, state);
588 EFSYS_PROBE1(fail1, efx_rc_t, rc);
594 * An arbitrary search limit for the software hash table. As per the linux net
597 #define EF10_FILTER_SEARCH_LIMIT 200
599 static __checkReturn efx_rc_t
600 ef10_filter_add_internal(
602 __inout efx_filter_spec_t *spec,
603 __in boolean_t may_replace,
604 __out_opt uint32_t *filter_id)
607 ef10_filter_table_t *eftp = enp->en_filter.ef_ef10_filter_table;
608 efx_filter_spec_t *saved_spec;
612 boolean_t replacing = B_FALSE;
614 efsys_lock_state_t state;
615 boolean_t locked = B_FALSE;
617 EFSYS_ASSERT(EFX_FAMILY_IS_EF10(enp));
619 hash = ef10_filter_hash(spec);
622 * FIXME: Add support for inserting filters of different priorities
623 * and removing lower priority multicast filters (bug 42378)
627 * Find any existing filters with the same match tuple or
628 * else a free slot to insert at. If any of them are busy,
629 * we have to wait and retry.
632 EFSYS_LOCK(enp->en_eslp, state);
637 for (depth = 1; depth <= EF10_FILTER_SEARCH_LIMIT; depth++) {
638 i = (hash + depth) & (EFX_EF10_FILTER_TBL_ROWS - 1);
639 saved_spec = ef10_filter_entry_spec(eftp, i);
641 if (saved_spec == NULL) {
644 } else if (ef10_filter_equal(spec, saved_spec)) {
645 if (ef10_filter_entry_is_busy(eftp, i)) {
646 EFSYS_UNLOCK(enp->en_eslp, state);
651 if (saved_spec->efs_priority == EFX_FILTER_PRI_AUTO) {
656 if (ef10_filter_is_exclusive(spec)) {
671 * Once we reach the maximum search depth, use the first suitable slot
672 * or return EBUSY if there was none.
681 * Create a software table entry if necessary, and mark it
682 * busy. We might yet fail to insert, but any attempt to
683 * insert a conflicting filter while we're waiting for the
684 * firmware must find the busy entry.
686 saved_spec = ef10_filter_entry_spec(eftp, ins_index);
688 if (saved_spec->efs_priority == EFX_FILTER_PRI_AUTO) {
689 /* This is a filter we are refreshing */
690 ef10_filter_set_entry_not_auto_old(eftp, ins_index);
696 EFSYS_KMEM_ALLOC(enp->en_esip, sizeof (*spec), saved_spec);
702 ef10_filter_set_entry(eftp, ins_index, saved_spec);
704 ef10_filter_set_entry_busy(eftp, ins_index);
706 EFSYS_UNLOCK(enp->en_eslp, state);
710 * On replacing the filter handle may change after after a successful
714 rc = efx_mcdi_filter_op_add(enp, spec,
715 MC_CMD_FILTER_OP_IN_OP_REPLACE,
716 &eftp->eft_entry[ins_index].efe_handle);
717 } else if (ef10_filter_is_exclusive(spec)) {
718 rc = efx_mcdi_filter_op_add(enp, spec,
719 MC_CMD_FILTER_OP_IN_OP_INSERT,
720 &eftp->eft_entry[ins_index].efe_handle);
722 rc = efx_mcdi_filter_op_add(enp, spec,
723 MC_CMD_FILTER_OP_IN_OP_SUBSCRIBE,
724 &eftp->eft_entry[ins_index].efe_handle);
730 EFSYS_LOCK(enp->en_eslp, state);
734 /* Update the fields that may differ */
735 saved_spec->efs_priority = spec->efs_priority;
736 saved_spec->efs_flags = spec->efs_flags;
737 saved_spec->efs_rss_context = spec->efs_rss_context;
738 saved_spec->efs_dmaq_id = spec->efs_dmaq_id;
741 ef10_filter_set_entry_not_busy(eftp, ins_index);
745 EFSYS_UNLOCK(enp->en_eslp, state);
749 *filter_id = ins_index;
757 EFSYS_KMEM_FREE(enp->en_esip, sizeof (*spec), saved_spec);
760 ef10_filter_set_entry_not_busy(eftp, ins_index);
761 ef10_filter_set_entry(eftp, ins_index, NULL);
770 EFSYS_PROBE1(fail1, efx_rc_t, rc);
773 EFSYS_UNLOCK(enp->en_eslp, state);
778 __checkReturn efx_rc_t
781 __inout efx_filter_spec_t *spec,
782 __in boolean_t may_replace)
786 rc = ef10_filter_add_internal(enp, spec, may_replace, NULL);
793 EFSYS_PROBE1(fail1, efx_rc_t, rc);
799 static __checkReturn efx_rc_t
800 ef10_filter_delete_internal(
802 __in uint32_t filter_id)
805 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
806 efx_filter_spec_t *spec;
807 efsys_lock_state_t state;
808 uint32_t filter_idx = filter_id % EFX_EF10_FILTER_TBL_ROWS;
811 * Find the software table entry and mark it busy. Don't
812 * remove it yet; any attempt to update while we're waiting
813 * for the firmware must find the busy entry.
815 * FIXME: What if the busy flag is never cleared?
817 EFSYS_LOCK(enp->en_eslp, state);
818 while (ef10_filter_entry_is_busy(table, filter_idx)) {
819 EFSYS_UNLOCK(enp->en_eslp, state);
821 EFSYS_LOCK(enp->en_eslp, state);
823 if ((spec = ef10_filter_entry_spec(table, filter_idx)) != NULL) {
824 ef10_filter_set_entry_busy(table, filter_idx);
826 EFSYS_UNLOCK(enp->en_eslp, state);
834 * Try to remove the hardware filter. This may fail if the MC has
835 * rebooted (which frees all hardware filter resources).
837 if (ef10_filter_is_exclusive(spec)) {
838 rc = efx_mcdi_filter_op_delete(enp,
839 MC_CMD_FILTER_OP_IN_OP_REMOVE,
840 &table->eft_entry[filter_idx].efe_handle);
842 rc = efx_mcdi_filter_op_delete(enp,
843 MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE,
844 &table->eft_entry[filter_idx].efe_handle);
847 /* Free the software table entry */
848 EFSYS_LOCK(enp->en_eslp, state);
849 ef10_filter_set_entry_not_busy(table, filter_idx);
850 ef10_filter_set_entry(table, filter_idx, NULL);
851 EFSYS_UNLOCK(enp->en_eslp, state);
853 EFSYS_KMEM_FREE(enp->en_esip, sizeof (*spec), spec);
855 /* Check result of hardware filter removal */
865 EFSYS_PROBE1(fail1, efx_rc_t, rc);
870 __checkReturn efx_rc_t
873 __inout efx_filter_spec_t *spec)
876 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
877 efx_filter_spec_t *saved_spec;
881 efsys_lock_state_t state;
882 boolean_t locked = B_FALSE;
884 EFSYS_ASSERT(EFX_FAMILY_IS_EF10(enp));
886 hash = ef10_filter_hash(spec);
888 EFSYS_LOCK(enp->en_eslp, state);
893 i = (hash + depth) & (EFX_EF10_FILTER_TBL_ROWS - 1);
894 saved_spec = ef10_filter_entry_spec(table, i);
895 if (saved_spec && ef10_filter_equal(spec, saved_spec) &&
896 ef10_filter_same_dest(spec, saved_spec)) {
899 if (depth == EF10_FILTER_SEARCH_LIMIT) {
906 EFSYS_UNLOCK(enp->en_eslp, state);
909 rc = ef10_filter_delete_internal(enp, i);
919 EFSYS_PROBE1(fail1, efx_rc_t, rc);
922 EFSYS_UNLOCK(enp->en_eslp, state);
927 static __checkReturn efx_rc_t
928 efx_mcdi_get_parser_disp_info(
930 __out_ecount(buffer_length) uint32_t *buffer,
931 __in size_t buffer_length,
932 __in boolean_t encap,
933 __out size_t *list_lengthp)
936 EFX_MCDI_DECLARE_BUF(payload, MC_CMD_GET_PARSER_DISP_INFO_IN_LEN,
937 MC_CMD_GET_PARSER_DISP_INFO_OUT_LENMAX);
938 size_t matches_count;
942 req.emr_cmd = MC_CMD_GET_PARSER_DISP_INFO;
943 req.emr_in_buf = payload;
944 req.emr_in_length = MC_CMD_GET_PARSER_DISP_INFO_IN_LEN;
945 req.emr_out_buf = payload;
946 req.emr_out_length = MC_CMD_GET_PARSER_DISP_INFO_OUT_LENMAX;
948 MCDI_IN_SET_DWORD(req, GET_PARSER_DISP_INFO_OUT_OP, encap ?
949 MC_CMD_GET_PARSER_DISP_INFO_IN_OP_GET_SUPPORTED_ENCAP_RX_MATCHES :
950 MC_CMD_GET_PARSER_DISP_INFO_IN_OP_GET_SUPPORTED_RX_MATCHES);
952 efx_mcdi_execute(enp, &req);
954 if (req.emr_rc != 0) {
959 matches_count = MCDI_OUT_DWORD(req,
960 GET_PARSER_DISP_INFO_OUT_NUM_SUPPORTED_MATCHES);
962 if (req.emr_out_length_used <
963 MC_CMD_GET_PARSER_DISP_INFO_OUT_LEN(matches_count)) {
968 *list_lengthp = matches_count;
970 if (buffer_length < matches_count) {
976 * Check that the elements in the list in the MCDI response are the size
977 * we expect, so we can just copy them directly. Any conversion of the
978 * flags is handled by the caller.
980 EFX_STATIC_ASSERT(sizeof (uint32_t) ==
981 MC_CMD_GET_PARSER_DISP_INFO_OUT_SUPPORTED_MATCHES_LEN);
983 list_size = matches_count *
984 MC_CMD_GET_PARSER_DISP_INFO_OUT_SUPPORTED_MATCHES_LEN;
986 MCDI_OUT2(req, uint32_t,
987 GET_PARSER_DISP_INFO_OUT_SUPPORTED_MATCHES),
997 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1002 __checkReturn efx_rc_t
1003 ef10_filter_supported_filters(
1004 __in efx_nic_t *enp,
1005 __out_ecount(buffer_length) uint32_t *buffer,
1006 __in size_t buffer_length,
1007 __out size_t *list_lengthp)
1009 efx_nic_cfg_t *encp = &(enp->en_nic_cfg);
1010 size_t mcdi_list_length;
1011 size_t mcdi_encap_list_length;
1014 uint32_t next_buf_idx;
1015 size_t next_buf_length;
1017 boolean_t no_space = B_FALSE;
1018 efx_filter_match_flags_t all_filter_flags =
1019 (EFX_FILTER_MATCH_REM_HOST | EFX_FILTER_MATCH_LOC_HOST |
1020 EFX_FILTER_MATCH_REM_MAC | EFX_FILTER_MATCH_REM_PORT |
1021 EFX_FILTER_MATCH_LOC_MAC | EFX_FILTER_MATCH_LOC_PORT |
1022 EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_INNER_VID |
1023 EFX_FILTER_MATCH_OUTER_VID | EFX_FILTER_MATCH_IP_PROTO |
1024 EFX_FILTER_MATCH_VNI_OR_VSID |
1025 EFX_FILTER_MATCH_IFRM_LOC_MAC |
1026 EFX_FILTER_MATCH_IFRM_UNKNOWN_MCAST_DST |
1027 EFX_FILTER_MATCH_IFRM_UNKNOWN_UCAST_DST |
1028 EFX_FILTER_MATCH_ENCAP_TYPE |
1029 EFX_FILTER_MATCH_UNKNOWN_MCAST_DST |
1030 EFX_FILTER_MATCH_UNKNOWN_UCAST_DST);
1033 * Two calls to MC_CMD_GET_PARSER_DISP_INFO are needed: one to get the
1034 * list of supported filters for ordinary packets, and then another to
1035 * get the list of supported filters for encapsulated packets. To
1036 * distinguish the second list from the first, the
1037 * EFX_FILTER_MATCH_ENCAP_TYPE flag is added to each filter for
1038 * encapsulated packets.
1040 rc = efx_mcdi_get_parser_disp_info(enp, buffer, buffer_length, B_FALSE,
1051 next_buf_length = 0;
1053 EFSYS_ASSERT(mcdi_list_length <= buffer_length);
1054 next_buf_idx = mcdi_list_length;
1055 next_buf_length = buffer_length - mcdi_list_length;
1058 if (encp->enc_tunnel_encapsulations_supported != 0) {
1059 rc = efx_mcdi_get_parser_disp_info(enp, &buffer[next_buf_idx],
1060 next_buf_length, B_TRUE, &mcdi_encap_list_length);
1067 for (i = next_buf_idx;
1068 i < next_buf_idx + mcdi_encap_list_length; i++)
1069 buffer[i] |= EFX_FILTER_MATCH_ENCAP_TYPE;
1072 mcdi_encap_list_length = 0;
1076 *list_lengthp = mcdi_list_length + mcdi_encap_list_length;
1082 * The static assertions in ef10_filter_init() ensure that the values of
1083 * the EFX_FILTER_MATCH flags match those used by MCDI, so they don't
1084 * need to be converted.
1086 * In case support is added to MCDI for additional flags, remove any
1087 * matches from the list which include flags we don't support. The order
1088 * of the matches is preserved as they are ordered from highest to
1091 EFSYS_ASSERT(mcdi_list_length + mcdi_encap_list_length <=
1094 for (i = 0; i < mcdi_list_length + mcdi_encap_list_length; i++) {
1095 if ((buffer[i] & ~all_filter_flags) == 0) {
1096 buffer[list_length] = buffer[i];
1101 *list_lengthp = list_length;
1110 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1115 static __checkReturn efx_rc_t
1116 ef10_filter_insert_unicast(
1117 __in efx_nic_t *enp,
1118 __in_ecount(6) uint8_t const *addr,
1119 __in efx_filter_flags_t filter_flags)
1121 ef10_filter_table_t *eftp = enp->en_filter.ef_ef10_filter_table;
1122 efx_filter_spec_t spec;
1125 /* Insert the filter for the local station address */
1126 efx_filter_spec_init_rx(&spec, EFX_FILTER_PRI_AUTO,
1128 eftp->eft_default_rxq);
1129 rc = efx_filter_spec_set_eth_local(&spec, EFX_FILTER_SPEC_VID_UNSPEC,
1134 rc = ef10_filter_add_internal(enp, &spec, B_TRUE,
1135 &eftp->eft_unicst_filter_indexes[eftp->eft_unicst_filter_count]);
1139 eftp->eft_unicst_filter_count++;
1140 EFSYS_ASSERT(eftp->eft_unicst_filter_count <=
1141 EFX_EF10_FILTER_UNICAST_FILTERS_MAX);
1148 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1152 static __checkReturn efx_rc_t
1153 ef10_filter_insert_all_unicast(
1154 __in efx_nic_t *enp,
1155 __in efx_filter_flags_t filter_flags)
1157 ef10_filter_table_t *eftp = enp->en_filter.ef_ef10_filter_table;
1158 efx_filter_spec_t spec;
1161 /* Insert the unknown unicast filter */
1162 efx_filter_spec_init_rx(&spec, EFX_FILTER_PRI_AUTO,
1164 eftp->eft_default_rxq);
1165 rc = efx_filter_spec_set_uc_def(&spec);
1168 rc = ef10_filter_add_internal(enp, &spec, B_TRUE,
1169 &eftp->eft_unicst_filter_indexes[eftp->eft_unicst_filter_count]);
1173 eftp->eft_unicst_filter_count++;
1174 EFSYS_ASSERT(eftp->eft_unicst_filter_count <=
1175 EFX_EF10_FILTER_UNICAST_FILTERS_MAX);
1182 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1186 static __checkReturn efx_rc_t
1187 ef10_filter_insert_multicast_list(
1188 __in efx_nic_t *enp,
1189 __in boolean_t mulcst,
1190 __in boolean_t brdcst,
1191 __in_ecount(6*count) uint8_t const *addrs,
1192 __in uint32_t count,
1193 __in efx_filter_flags_t filter_flags,
1194 __in boolean_t rollback)
1196 ef10_filter_table_t *eftp = enp->en_filter.ef_ef10_filter_table;
1197 efx_filter_spec_t spec;
1200 uint32_t filter_index;
1201 uint32_t filter_count;
1204 if (mulcst == B_FALSE)
1207 if (count + (brdcst ? 1 : 0) >
1208 EFX_ARRAY_SIZE(eftp->eft_mulcst_filter_indexes)) {
1209 /* Too many MAC addresses */
1214 /* Insert/renew multicast address list filters */
1216 for (i = 0; i < count; i++) {
1217 efx_filter_spec_init_rx(&spec,
1218 EFX_FILTER_PRI_AUTO,
1220 eftp->eft_default_rxq);
1222 rc = efx_filter_spec_set_eth_local(&spec,
1223 EFX_FILTER_SPEC_VID_UNSPEC,
1224 &addrs[i * EFX_MAC_ADDR_LEN]);
1226 if (rollback == B_TRUE) {
1227 /* Only stop upon failure if told to rollback */
1231 * Don't try to add a filter with a corrupt
1238 rc = ef10_filter_add_internal(enp, &spec, B_TRUE,
1242 eftp->eft_mulcst_filter_indexes[filter_count] =
1245 } else if (rollback == B_TRUE) {
1246 /* Only stop upon failure if told to rollback */
1252 if (brdcst == B_TRUE) {
1253 /* Insert/renew broadcast address filter */
1254 efx_filter_spec_init_rx(&spec, EFX_FILTER_PRI_AUTO,
1256 eftp->eft_default_rxq);
1258 EFX_MAC_BROADCAST_ADDR_SET(addr);
1259 rc = efx_filter_spec_set_eth_local(&spec,
1260 EFX_FILTER_SPEC_VID_UNSPEC, addr);
1261 if ((rc != 0) && (rollback == B_TRUE)) {
1262 /* Only stop upon failure if told to rollback */
1266 rc = ef10_filter_add_internal(enp, &spec, B_TRUE,
1270 eftp->eft_mulcst_filter_indexes[filter_count] =
1273 } else if (rollback == B_TRUE) {
1274 /* Only stop upon failure if told to rollback */
1279 eftp->eft_mulcst_filter_count = filter_count;
1280 eftp->eft_using_all_mulcst = B_FALSE;
1285 /* Remove any filters we have inserted */
1288 (void) ef10_filter_delete_internal(enp,
1289 eftp->eft_mulcst_filter_indexes[i]);
1291 eftp->eft_mulcst_filter_count = 0;
1294 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1299 static __checkReturn efx_rc_t
1300 ef10_filter_insert_all_multicast(
1301 __in efx_nic_t *enp,
1302 __in efx_filter_flags_t filter_flags)
1304 ef10_filter_table_t *eftp = enp->en_filter.ef_ef10_filter_table;
1305 efx_filter_spec_t spec;
1308 /* Insert the unknown multicast filter */
1309 efx_filter_spec_init_rx(&spec, EFX_FILTER_PRI_AUTO,
1311 eftp->eft_default_rxq);
1312 rc = efx_filter_spec_set_mc_def(&spec);
1316 rc = ef10_filter_add_internal(enp, &spec, B_TRUE,
1317 &eftp->eft_mulcst_filter_indexes[0]);
1321 eftp->eft_mulcst_filter_count = 1;
1322 eftp->eft_using_all_mulcst = B_TRUE;
1325 * FIXME: If brdcst == B_FALSE, add a filter to drop broadcast traffic.
1333 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1338 typedef struct ef10_filter_encap_entry_s {
1339 uint16_t ether_type;
1340 efx_tunnel_protocol_t encap_type;
1341 uint32_t inner_frame_match;
1342 } ef10_filter_encap_entry_t;
1344 #define EF10_ENCAP_FILTER_ENTRY(ipv, encap_type, inner_frame_match) \
1345 { EFX_ETHER_TYPE_##ipv, EFX_TUNNEL_PROTOCOL_##encap_type, \
1346 EFX_FILTER_INNER_FRAME_MATCH_UNKNOWN_##inner_frame_match }
1348 static ef10_filter_encap_entry_t ef10_filter_encap_list[] = {
1349 EF10_ENCAP_FILTER_ENTRY(IPV4, VXLAN, UCAST_DST),
1350 EF10_ENCAP_FILTER_ENTRY(IPV4, VXLAN, MCAST_DST),
1351 EF10_ENCAP_FILTER_ENTRY(IPV6, VXLAN, UCAST_DST),
1352 EF10_ENCAP_FILTER_ENTRY(IPV6, VXLAN, MCAST_DST),
1354 EF10_ENCAP_FILTER_ENTRY(IPV4, GENEVE, UCAST_DST),
1355 EF10_ENCAP_FILTER_ENTRY(IPV4, GENEVE, MCAST_DST),
1356 EF10_ENCAP_FILTER_ENTRY(IPV6, GENEVE, UCAST_DST),
1357 EF10_ENCAP_FILTER_ENTRY(IPV6, GENEVE, MCAST_DST),
1359 EF10_ENCAP_FILTER_ENTRY(IPV4, NVGRE, UCAST_DST),
1360 EF10_ENCAP_FILTER_ENTRY(IPV4, NVGRE, MCAST_DST),
1361 EF10_ENCAP_FILTER_ENTRY(IPV6, NVGRE, UCAST_DST),
1362 EF10_ENCAP_FILTER_ENTRY(IPV6, NVGRE, MCAST_DST),
1365 #undef EF10_ENCAP_FILTER_ENTRY
1367 static __checkReturn efx_rc_t
1368 ef10_filter_insert_encap_filters(
1369 __in efx_nic_t *enp,
1370 __in boolean_t mulcst,
1371 __in efx_filter_flags_t filter_flags)
1373 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
1377 EFX_STATIC_ASSERT(EFX_ARRAY_SIZE(ef10_filter_encap_list) <=
1378 EFX_ARRAY_SIZE(table->eft_encap_filter_indexes));
1381 * On Medford, full-featured firmware can identify packets as being
1382 * tunnel encapsulated, even if no encapsulated packet offloads are in
1383 * use. When packets are identified as such, ordinary filters are not
1384 * applied, only ones specific to encapsulated packets. Hence we need to
1385 * insert filters for encapsulated packets in order to receive them.
1387 * Separate filters need to be inserted for each ether type,
1388 * encapsulation type, and inner frame type (unicast or multicast). To
1389 * keep things simple and reduce the number of filters needed, catch-all
1390 * filters for all combinations of types are inserted, even if
1391 * all_unicst or all_mulcst have not been set. (These catch-all filters
1392 * may well, however, fail to insert on unprivileged functions.)
1394 table->eft_encap_filter_count = 0;
1395 for (i = 0; i < EFX_ARRAY_SIZE(ef10_filter_encap_list); i++) {
1396 efx_filter_spec_t spec;
1397 ef10_filter_encap_entry_t *encap_filter =
1398 &ef10_filter_encap_list[i];
1401 * Skip multicast filters if we've not been asked for
1402 * any multicast traffic.
1404 if ((mulcst == B_FALSE) &&
1405 (encap_filter->inner_frame_match ==
1406 EFX_FILTER_INNER_FRAME_MATCH_UNKNOWN_MCAST_DST))
1409 efx_filter_spec_init_rx(&spec, EFX_FILTER_PRI_AUTO,
1411 table->eft_default_rxq);
1412 efx_filter_spec_set_ether_type(&spec, encap_filter->ether_type);
1413 rc = efx_filter_spec_set_encap_type(&spec,
1414 encap_filter->encap_type,
1415 encap_filter->inner_frame_match);
1419 rc = ef10_filter_add_internal(enp, &spec, B_TRUE,
1420 &table->eft_encap_filter_indexes[
1421 table->eft_encap_filter_count]);
1426 table->eft_encap_filter_count++;
1435 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1441 ef10_filter_remove_old(
1442 __in efx_nic_t *enp)
1444 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
1447 for (i = 0; i < EFX_ARRAY_SIZE(table->eft_entry); i++) {
1448 if (ef10_filter_entry_is_auto_old(table, i)) {
1449 (void) ef10_filter_delete_internal(enp, i);
1455 static __checkReturn efx_rc_t
1456 ef10_filter_get_workarounds(
1457 __in efx_nic_t *enp)
1459 efx_nic_cfg_t *encp = &enp->en_nic_cfg;
1460 uint32_t implemented = 0;
1461 uint32_t enabled = 0;
1464 rc = efx_mcdi_get_workarounds(enp, &implemented, &enabled);
1466 /* Check if chained multicast filter support is enabled */
1467 if (implemented & enabled & MC_CMD_GET_WORKAROUNDS_OUT_BUG26807)
1468 encp->enc_bug26807_workaround = B_TRUE;
1470 encp->enc_bug26807_workaround = B_FALSE;
1471 } else if (rc == ENOTSUP) {
1473 * Firmware is too old to support GET_WORKAROUNDS, and support
1474 * for this workaround was implemented later.
1476 encp->enc_bug26807_workaround = B_FALSE;
1484 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1492 * Reconfigure all filters.
1493 * If all_unicst and/or all mulcst filters cannot be applied then
1494 * return ENOTSUP (Note the filters for the specified addresses are
1495 * still applied in this case).
1497 __checkReturn efx_rc_t
1498 ef10_filter_reconfigure(
1499 __in efx_nic_t *enp,
1500 __in_ecount(6) uint8_t const *mac_addr,
1501 __in boolean_t all_unicst,
1502 __in boolean_t mulcst,
1503 __in boolean_t all_mulcst,
1504 __in boolean_t brdcst,
1505 __in_ecount(6*count) uint8_t const *addrs,
1506 __in uint32_t count)
1508 efx_nic_cfg_t *encp = &enp->en_nic_cfg;
1509 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
1510 efx_filter_flags_t filter_flags;
1512 efx_rc_t all_unicst_rc = 0;
1513 efx_rc_t all_mulcst_rc = 0;
1516 if (table->eft_default_rxq == NULL) {
1518 * Filters direct traffic to the default RXQ, and so cannot be
1519 * inserted until it is available. Any currently configured
1520 * filters must be removed (ignore errors in case the MC
1521 * has rebooted, which removes hardware filters).
1523 for (i = 0; i < table->eft_unicst_filter_count; i++) {
1524 (void) ef10_filter_delete_internal(enp,
1525 table->eft_unicst_filter_indexes[i]);
1527 table->eft_unicst_filter_count = 0;
1529 for (i = 0; i < table->eft_mulcst_filter_count; i++) {
1530 (void) ef10_filter_delete_internal(enp,
1531 table->eft_mulcst_filter_indexes[i]);
1533 table->eft_mulcst_filter_count = 0;
1535 for (i = 0; i < table->eft_encap_filter_count; i++) {
1536 (void) ef10_filter_delete_internal(enp,
1537 table->eft_encap_filter_indexes[i]);
1539 table->eft_encap_filter_count = 0;
1544 if (table->eft_using_rss)
1545 filter_flags = EFX_FILTER_FLAG_RX_RSS;
1549 /* Mark old filters which may need to be removed */
1550 for (i = 0; i < table->eft_unicst_filter_count; i++) {
1551 ef10_filter_set_entry_auto_old(table,
1552 table->eft_unicst_filter_indexes[i]);
1554 for (i = 0; i < table->eft_mulcst_filter_count; i++) {
1555 ef10_filter_set_entry_auto_old(table,
1556 table->eft_mulcst_filter_indexes[i]);
1558 for (i = 0; i < table->eft_encap_filter_count; i++) {
1559 ef10_filter_set_entry_auto_old(table,
1560 table->eft_encap_filter_indexes[i]);
1564 * Insert or renew unicast filters.
1566 * Firmware does not perform chaining on unicast filters. As traffic is
1567 * therefore only delivered to the first matching filter, we should
1568 * always insert the specific filter for our MAC address, to try and
1569 * ensure we get that traffic.
1571 * (If the filter for our MAC address has already been inserted by
1572 * another function, we won't receive traffic sent to us, even if we
1573 * insert a unicast mismatch filter. To prevent traffic stealing, this
1574 * therefore relies on the privilege model only allowing functions to
1575 * insert filters for their own MAC address unless explicitly given
1576 * additional privileges by the user. This also means that, even on a
1577 * priviliged function, inserting a unicast mismatch filter may not
1578 * catch all traffic in multi PCI function scenarios.)
1580 table->eft_unicst_filter_count = 0;
1581 rc = ef10_filter_insert_unicast(enp, mac_addr, filter_flags);
1582 if (all_unicst || (rc != 0)) {
1583 all_unicst_rc = ef10_filter_insert_all_unicast(enp,
1585 if ((rc != 0) && (all_unicst_rc != 0))
1590 * WORKAROUND_BUG26807 controls firmware support for chained multicast
1591 * filters, and can only be enabled or disabled when the hardware filter
1594 * Chained multicast filters require support from the datapath firmware,
1595 * and may not be available (e.g. low-latency variants or old Huntington
1598 * Firmware will reset (FLR) functions which have inserted filters in
1599 * the hardware filter table when the workaround is enabled/disabled.
1600 * Functions without any hardware filters are not reset.
1602 * Re-check if the workaround is enabled after adding unicast hardware
1603 * filters. This ensures that encp->enc_bug26807_workaround matches the
1604 * firmware state, and that later changes to enable/disable the
1605 * workaround will result in this function seeing a reset (FLR).
1607 * In common-code drivers, we only support multiple PCI function
1608 * scenarios with firmware that supports multicast chaining, so we can
1609 * assume it is enabled for such cases and hence simplify the filter
1610 * insertion logic. Firmware that does not support multicast chaining
1611 * does not support multiple PCI function configurations either, so
1612 * filter insertion is much simpler and the same strategies can still be
1615 if ((rc = ef10_filter_get_workarounds(enp)) != 0)
1618 if ((table->eft_using_all_mulcst != all_mulcst) &&
1619 (encp->enc_bug26807_workaround == B_TRUE)) {
1621 * Multicast filter chaining is enabled, so traffic that matches
1622 * more than one multicast filter will be replicated and
1623 * delivered to multiple recipients. To avoid this duplicate
1624 * delivery, remove old multicast filters before inserting new
1625 * multicast filters.
1627 ef10_filter_remove_old(enp);
1630 /* Insert or renew multicast filters */
1631 if (all_mulcst == B_TRUE) {
1633 * Insert the all multicast filter. If that fails, try to insert
1634 * all of our multicast filters (but without rollback on
1637 all_mulcst_rc = ef10_filter_insert_all_multicast(enp,
1639 if (all_mulcst_rc != 0) {
1640 rc = ef10_filter_insert_multicast_list(enp, B_TRUE,
1641 brdcst, addrs, count, filter_flags, B_FALSE);
1647 * Insert filters for multicast addresses.
1648 * If any insertion fails, then rollback and try to insert the
1649 * all multicast filter instead.
1650 * If that also fails, try to insert all of the multicast
1651 * filters (but without rollback on failure).
1653 rc = ef10_filter_insert_multicast_list(enp, mulcst, brdcst,
1654 addrs, count, filter_flags, B_TRUE);
1656 if ((table->eft_using_all_mulcst == B_FALSE) &&
1657 (encp->enc_bug26807_workaround == B_TRUE)) {
1659 * Multicast filter chaining is on, so remove
1660 * old filters before inserting the multicast
1661 * all filter to avoid duplicate delivery caused
1662 * by packets matching multiple filters.
1664 ef10_filter_remove_old(enp);
1667 rc = ef10_filter_insert_all_multicast(enp,
1670 rc = ef10_filter_insert_multicast_list(enp,
1672 addrs, count, filter_flags, B_FALSE);
1679 if (encp->enc_tunnel_encapsulations_supported != 0) {
1680 /* Try to insert filters for encapsulated packets. */
1681 (void) ef10_filter_insert_encap_filters(enp,
1682 mulcst || all_mulcst || brdcst,
1686 /* Remove old filters which were not renewed */
1687 ef10_filter_remove_old(enp);
1689 /* report if any optional flags were rejected */
1690 if (((all_unicst != B_FALSE) && (all_unicst_rc != 0)) ||
1691 ((all_mulcst != B_FALSE) && (all_mulcst_rc != 0))) {
1704 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1706 /* Clear auto old flags */
1707 for (i = 0; i < EFX_ARRAY_SIZE(table->eft_entry); i++) {
1708 if (ef10_filter_entry_is_auto_old(table, i)) {
1709 ef10_filter_set_entry_not_auto_old(table, i);
1717 ef10_filter_get_default_rxq(
1718 __in efx_nic_t *enp,
1719 __out efx_rxq_t **erpp,
1720 __out boolean_t *using_rss)
1722 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
1724 *erpp = table->eft_default_rxq;
1725 *using_rss = table->eft_using_rss;
1730 ef10_filter_default_rxq_set(
1731 __in efx_nic_t *enp,
1732 __in efx_rxq_t *erp,
1733 __in boolean_t using_rss)
1735 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
1737 #if EFSYS_OPT_RX_SCALE
1738 EFSYS_ASSERT((using_rss == B_FALSE) ||
1739 (enp->en_rss_context != EF10_RSS_CONTEXT_INVALID));
1740 table->eft_using_rss = using_rss;
1742 EFSYS_ASSERT(using_rss == B_FALSE);
1743 table->eft_using_rss = B_FALSE;
1745 table->eft_default_rxq = erp;
1749 ef10_filter_default_rxq_clear(
1750 __in efx_nic_t *enp)
1752 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
1754 table->eft_default_rxq = NULL;
1755 table->eft_using_rss = B_FALSE;
1759 #endif /* EFSYS_OPT_FILTER */
1761 #endif /* EFX_OPTS_EF10() */