2 * Copyright (c) 2007-2016 Solarflare Communications Inc.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
16 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
18 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
21 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
22 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
24 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 * The views and conclusions contained in the software and documentation are
27 * those of the authors and should not be interpreted as representing official
28 * policies, either expressed or implied, of the FreeBSD Project.
31 #include <sys/cdefs.h>
32 __FBSDID("$FreeBSD$");
37 #if EFSYS_OPT_HUNTINGTON || EFSYS_OPT_MEDFORD || EFSYS_OPT_MEDFORD2
41 #define EFE_SPEC(eftp, index) ((eftp)->eft_entry[(index)].efe_spec)
43 static efx_filter_spec_t *
44 ef10_filter_entry_spec(
45 __in const ef10_filter_table_t *eftp,
46 __in unsigned int index)
48 return ((efx_filter_spec_t *)(EFE_SPEC(eftp, index) &
49 ~(uintptr_t)EFX_EF10_FILTER_FLAGS));
53 ef10_filter_entry_is_busy(
54 __in const ef10_filter_table_t *eftp,
55 __in unsigned int index)
57 if (EFE_SPEC(eftp, index) & EFX_EF10_FILTER_FLAG_BUSY)
64 ef10_filter_entry_is_auto_old(
65 __in const ef10_filter_table_t *eftp,
66 __in unsigned int index)
68 if (EFE_SPEC(eftp, index) & EFX_EF10_FILTER_FLAG_AUTO_OLD)
75 ef10_filter_set_entry(
76 __inout ef10_filter_table_t *eftp,
77 __in unsigned int index,
78 __in_opt const efx_filter_spec_t *efsp)
80 EFE_SPEC(eftp, index) = (uintptr_t)efsp;
84 ef10_filter_set_entry_busy(
85 __inout ef10_filter_table_t *eftp,
86 __in unsigned int index)
88 EFE_SPEC(eftp, index) |= (uintptr_t)EFX_EF10_FILTER_FLAG_BUSY;
92 ef10_filter_set_entry_not_busy(
93 __inout ef10_filter_table_t *eftp,
94 __in unsigned int index)
96 EFE_SPEC(eftp, index) &= ~(uintptr_t)EFX_EF10_FILTER_FLAG_BUSY;
100 ef10_filter_set_entry_auto_old(
101 __inout ef10_filter_table_t *eftp,
102 __in unsigned int index)
104 EFSYS_ASSERT(ef10_filter_entry_spec(eftp, index) != NULL);
105 EFE_SPEC(eftp, index) |= (uintptr_t)EFX_EF10_FILTER_FLAG_AUTO_OLD;
109 ef10_filter_set_entry_not_auto_old(
110 __inout ef10_filter_table_t *eftp,
111 __in unsigned int index)
113 EFE_SPEC(eftp, index) &= ~(uintptr_t)EFX_EF10_FILTER_FLAG_AUTO_OLD;
114 EFSYS_ASSERT(ef10_filter_entry_spec(eftp, index) != NULL);
117 __checkReturn efx_rc_t
122 ef10_filter_table_t *eftp;
124 EFSYS_ASSERT(enp->en_family == EFX_FAMILY_HUNTINGTON ||
125 enp->en_family == EFX_FAMILY_MEDFORD ||
126 enp->en_family == EFX_FAMILY_MEDFORD2);
128 #define MATCH_MASK(match) (EFX_MASK32(match) << EFX_LOW_BIT(match))
129 EFX_STATIC_ASSERT(EFX_FILTER_MATCH_REM_HOST ==
130 MATCH_MASK(MC_CMD_FILTER_OP_EXT_IN_MATCH_SRC_IP));
131 EFX_STATIC_ASSERT(EFX_FILTER_MATCH_LOC_HOST ==
132 MATCH_MASK(MC_CMD_FILTER_OP_EXT_IN_MATCH_DST_IP));
133 EFX_STATIC_ASSERT(EFX_FILTER_MATCH_REM_MAC ==
134 MATCH_MASK(MC_CMD_FILTER_OP_EXT_IN_MATCH_SRC_MAC));
135 EFX_STATIC_ASSERT(EFX_FILTER_MATCH_REM_PORT ==
136 MATCH_MASK(MC_CMD_FILTER_OP_EXT_IN_MATCH_SRC_PORT));
137 EFX_STATIC_ASSERT(EFX_FILTER_MATCH_LOC_MAC ==
138 MATCH_MASK(MC_CMD_FILTER_OP_EXT_IN_MATCH_DST_MAC));
139 EFX_STATIC_ASSERT(EFX_FILTER_MATCH_LOC_PORT ==
140 MATCH_MASK(MC_CMD_FILTER_OP_EXT_IN_MATCH_DST_PORT));
141 EFX_STATIC_ASSERT(EFX_FILTER_MATCH_ETHER_TYPE ==
142 MATCH_MASK(MC_CMD_FILTER_OP_EXT_IN_MATCH_ETHER_TYPE));
143 EFX_STATIC_ASSERT(EFX_FILTER_MATCH_INNER_VID ==
144 MATCH_MASK(MC_CMD_FILTER_OP_EXT_IN_MATCH_INNER_VLAN));
145 EFX_STATIC_ASSERT(EFX_FILTER_MATCH_OUTER_VID ==
146 MATCH_MASK(MC_CMD_FILTER_OP_EXT_IN_MATCH_OUTER_VLAN));
147 EFX_STATIC_ASSERT(EFX_FILTER_MATCH_IP_PROTO ==
148 MATCH_MASK(MC_CMD_FILTER_OP_EXT_IN_MATCH_IP_PROTO));
149 EFX_STATIC_ASSERT(EFX_FILTER_MATCH_VNI_OR_VSID ==
150 MATCH_MASK(MC_CMD_FILTER_OP_EXT_IN_MATCH_VNI_OR_VSID));
151 EFX_STATIC_ASSERT(EFX_FILTER_MATCH_IFRM_LOC_MAC ==
152 MATCH_MASK(MC_CMD_FILTER_OP_EXT_IN_MATCH_IFRM_DST_MAC));
153 EFX_STATIC_ASSERT(EFX_FILTER_MATCH_IFRM_UNKNOWN_MCAST_DST ==
154 MATCH_MASK(MC_CMD_FILTER_OP_EXT_IN_MATCH_IFRM_UNKNOWN_MCAST_DST));
155 EFX_STATIC_ASSERT(EFX_FILTER_MATCH_IFRM_UNKNOWN_UCAST_DST ==
156 MATCH_MASK(MC_CMD_FILTER_OP_EXT_IN_MATCH_IFRM_UNKNOWN_UCAST_DST));
157 EFX_STATIC_ASSERT(EFX_FILTER_MATCH_UNKNOWN_MCAST_DST ==
158 MATCH_MASK(MC_CMD_FILTER_OP_EXT_IN_MATCH_UNKNOWN_MCAST_DST));
159 EFX_STATIC_ASSERT((uint32_t)EFX_FILTER_MATCH_UNKNOWN_UCAST_DST ==
160 MATCH_MASK(MC_CMD_FILTER_OP_EXT_IN_MATCH_UNKNOWN_UCAST_DST));
163 EFSYS_KMEM_ALLOC(enp->en_esip, sizeof (ef10_filter_table_t), eftp);
170 enp->en_filter.ef_ef10_filter_table = eftp;
175 EFSYS_PROBE1(fail1, efx_rc_t, rc);
184 EFSYS_ASSERT(enp->en_family == EFX_FAMILY_HUNTINGTON ||
185 enp->en_family == EFX_FAMILY_MEDFORD ||
186 enp->en_family == EFX_FAMILY_MEDFORD2);
188 if (enp->en_filter.ef_ef10_filter_table != NULL) {
189 EFSYS_KMEM_FREE(enp->en_esip, sizeof (ef10_filter_table_t),
190 enp->en_filter.ef_ef10_filter_table);
194 static __checkReturn efx_rc_t
195 efx_mcdi_filter_op_add(
197 __in efx_filter_spec_t *spec,
198 __in unsigned int filter_op,
199 __inout ef10_filter_handle_t *handle)
202 EFX_MCDI_DECLARE_BUF(payload, MC_CMD_FILTER_OP_V3_IN_LEN,
203 MC_CMD_FILTER_OP_EXT_OUT_LEN);
204 efx_filter_match_flags_t match_flags;
207 req.emr_cmd = MC_CMD_FILTER_OP;
208 req.emr_in_buf = payload;
209 req.emr_in_length = MC_CMD_FILTER_OP_V3_IN_LEN;
210 req.emr_out_buf = payload;
211 req.emr_out_length = MC_CMD_FILTER_OP_EXT_OUT_LEN;
214 * Remove match flag for encapsulated filters that does not correspond
215 * to the MCDI match flags
217 match_flags = spec->efs_match_flags & ~EFX_FILTER_MATCH_ENCAP_TYPE;
220 case MC_CMD_FILTER_OP_IN_OP_REPLACE:
221 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_HANDLE_LO,
223 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_HANDLE_HI,
226 case MC_CMD_FILTER_OP_IN_OP_INSERT:
227 case MC_CMD_FILTER_OP_IN_OP_SUBSCRIBE:
228 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_OP, filter_op);
236 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_PORT_ID,
237 EVB_PORT_ID_ASSIGNED);
238 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_MATCH_FIELDS,
240 if (spec->efs_dmaq_id == EFX_FILTER_SPEC_RX_DMAQ_ID_DROP) {
241 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_RX_DEST,
242 MC_CMD_FILTER_OP_EXT_IN_RX_DEST_DROP);
244 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_RX_DEST,
245 MC_CMD_FILTER_OP_EXT_IN_RX_DEST_HOST);
246 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_RX_QUEUE,
250 #if EFSYS_OPT_RX_SCALE
251 if (spec->efs_flags & EFX_FILTER_FLAG_RX_RSS) {
252 uint32_t rss_context;
254 if (spec->efs_rss_context == EFX_RSS_CONTEXT_DEFAULT)
255 rss_context = enp->en_rss_context;
257 rss_context = spec->efs_rss_context;
258 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_RX_CONTEXT,
263 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_RX_MODE,
264 spec->efs_flags & EFX_FILTER_FLAG_RX_RSS ?
265 MC_CMD_FILTER_OP_EXT_IN_RX_MODE_RSS :
266 MC_CMD_FILTER_OP_EXT_IN_RX_MODE_SIMPLE);
267 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_TX_DEST,
268 MC_CMD_FILTER_OP_EXT_IN_TX_DEST_DEFAULT);
270 if (filter_op != MC_CMD_FILTER_OP_IN_OP_REPLACE) {
272 * NOTE: Unlike most MCDI requests, the filter fields
273 * are presented in network (big endian) byte order.
275 memcpy(MCDI_IN2(req, uint8_t, FILTER_OP_EXT_IN_SRC_MAC),
276 spec->efs_rem_mac, EFX_MAC_ADDR_LEN);
277 memcpy(MCDI_IN2(req, uint8_t, FILTER_OP_EXT_IN_DST_MAC),
278 spec->efs_loc_mac, EFX_MAC_ADDR_LEN);
280 MCDI_IN_SET_WORD(req, FILTER_OP_EXT_IN_SRC_PORT,
281 __CPU_TO_BE_16(spec->efs_rem_port));
282 MCDI_IN_SET_WORD(req, FILTER_OP_EXT_IN_DST_PORT,
283 __CPU_TO_BE_16(spec->efs_loc_port));
285 MCDI_IN_SET_WORD(req, FILTER_OP_EXT_IN_ETHER_TYPE,
286 __CPU_TO_BE_16(spec->efs_ether_type));
288 MCDI_IN_SET_WORD(req, FILTER_OP_EXT_IN_INNER_VLAN,
289 __CPU_TO_BE_16(spec->efs_inner_vid));
290 MCDI_IN_SET_WORD(req, FILTER_OP_EXT_IN_OUTER_VLAN,
291 __CPU_TO_BE_16(spec->efs_outer_vid));
293 /* IP protocol (in low byte, high byte is zero) */
294 MCDI_IN_SET_BYTE(req, FILTER_OP_EXT_IN_IP_PROTO,
297 EFX_STATIC_ASSERT(sizeof (spec->efs_rem_host) ==
298 MC_CMD_FILTER_OP_EXT_IN_SRC_IP_LEN);
299 EFX_STATIC_ASSERT(sizeof (spec->efs_loc_host) ==
300 MC_CMD_FILTER_OP_EXT_IN_DST_IP_LEN);
302 memcpy(MCDI_IN2(req, uint8_t, FILTER_OP_EXT_IN_SRC_IP),
303 &spec->efs_rem_host.eo_byte[0],
304 MC_CMD_FILTER_OP_EXT_IN_SRC_IP_LEN);
305 memcpy(MCDI_IN2(req, uint8_t, FILTER_OP_EXT_IN_DST_IP),
306 &spec->efs_loc_host.eo_byte[0],
307 MC_CMD_FILTER_OP_EXT_IN_DST_IP_LEN);
310 * On Medford, filters for encapsulated packets match based on
311 * the ether type and IP protocol in the outer frame. In
312 * addition we need to fill in the VNI or VSID type field.
314 switch (spec->efs_encap_type) {
315 case EFX_TUNNEL_PROTOCOL_NONE:
317 case EFX_TUNNEL_PROTOCOL_VXLAN:
318 case EFX_TUNNEL_PROTOCOL_GENEVE:
319 MCDI_IN_POPULATE_DWORD_1(req,
320 FILTER_OP_EXT_IN_VNI_OR_VSID,
321 FILTER_OP_EXT_IN_VNI_TYPE,
322 spec->efs_encap_type == EFX_TUNNEL_PROTOCOL_VXLAN ?
323 MC_CMD_FILTER_OP_EXT_IN_VNI_TYPE_VXLAN :
324 MC_CMD_FILTER_OP_EXT_IN_VNI_TYPE_GENEVE);
326 case EFX_TUNNEL_PROTOCOL_NVGRE:
327 MCDI_IN_POPULATE_DWORD_1(req,
328 FILTER_OP_EXT_IN_VNI_OR_VSID,
329 FILTER_OP_EXT_IN_VSID_TYPE,
330 MC_CMD_FILTER_OP_EXT_IN_VSID_TYPE_NVGRE);
338 memcpy(MCDI_IN2(req, uint8_t, FILTER_OP_EXT_IN_VNI_OR_VSID),
339 spec->efs_vni_or_vsid, EFX_VNI_OR_VSID_LEN);
341 memcpy(MCDI_IN2(req, uint8_t, FILTER_OP_EXT_IN_IFRM_DST_MAC),
342 spec->efs_ifrm_loc_mac, EFX_MAC_ADDR_LEN);
346 * Set the "MARK" or "FLAG" action for all packets matching this filter
347 * if necessary (only useful with equal stride packed stream Rx mode
348 * which provide the information in pseudo-header).
349 * These actions require MC_CMD_FILTER_OP_V3_IN msgrequest.
351 if ((spec->efs_flags & EFX_FILTER_FLAG_ACTION_MARK) &&
352 (spec->efs_flags & EFX_FILTER_FLAG_ACTION_FLAG)) {
356 if (spec->efs_flags & EFX_FILTER_FLAG_ACTION_MARK) {
357 MCDI_IN_SET_DWORD(req, FILTER_OP_V3_IN_MATCH_ACTION,
358 MC_CMD_FILTER_OP_V3_IN_MATCH_ACTION_MARK);
359 MCDI_IN_SET_DWORD(req, FILTER_OP_V3_IN_MATCH_MARK_VALUE,
361 } else if (spec->efs_flags & EFX_FILTER_FLAG_ACTION_FLAG) {
362 MCDI_IN_SET_DWORD(req, FILTER_OP_V3_IN_MATCH_ACTION,
363 MC_CMD_FILTER_OP_V3_IN_MATCH_ACTION_FLAG);
366 efx_mcdi_execute(enp, &req);
368 if (req.emr_rc != 0) {
373 if (req.emr_out_length_used < MC_CMD_FILTER_OP_EXT_OUT_LEN) {
378 handle->efh_lo = MCDI_OUT_DWORD(req, FILTER_OP_EXT_OUT_HANDLE_LO);
379 handle->efh_hi = MCDI_OUT_DWORD(req, FILTER_OP_EXT_OUT_HANDLE_HI);
392 EFSYS_PROBE1(fail1, efx_rc_t, rc);
398 static __checkReturn efx_rc_t
399 efx_mcdi_filter_op_delete(
401 __in unsigned int filter_op,
402 __inout ef10_filter_handle_t *handle)
405 EFX_MCDI_DECLARE_BUF(payload, MC_CMD_FILTER_OP_EXT_IN_LEN,
406 MC_CMD_FILTER_OP_EXT_OUT_LEN);
409 req.emr_cmd = MC_CMD_FILTER_OP;
410 req.emr_in_buf = payload;
411 req.emr_in_length = MC_CMD_FILTER_OP_EXT_IN_LEN;
412 req.emr_out_buf = payload;
413 req.emr_out_length = MC_CMD_FILTER_OP_EXT_OUT_LEN;
416 case MC_CMD_FILTER_OP_IN_OP_REMOVE:
417 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_OP,
418 MC_CMD_FILTER_OP_IN_OP_REMOVE);
420 case MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE:
421 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_OP,
422 MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE);
430 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_HANDLE_LO, handle->efh_lo);
431 MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_HANDLE_HI, handle->efh_hi);
433 efx_mcdi_execute_quiet(enp, &req);
435 if (req.emr_rc != 0) {
440 if (req.emr_out_length_used < MC_CMD_FILTER_OP_EXT_OUT_LEN) {
453 EFSYS_PROBE1(fail1, efx_rc_t, rc);
458 static __checkReturn boolean_t
460 __in const efx_filter_spec_t *left,
461 __in const efx_filter_spec_t *right)
463 /* FIXME: Consider rx vs tx filters (look at efs_flags) */
464 if (left->efs_match_flags != right->efs_match_flags)
466 if (!EFX_OWORD_IS_EQUAL(left->efs_rem_host, right->efs_rem_host))
468 if (!EFX_OWORD_IS_EQUAL(left->efs_loc_host, right->efs_loc_host))
470 if (memcmp(left->efs_rem_mac, right->efs_rem_mac, EFX_MAC_ADDR_LEN))
472 if (memcmp(left->efs_loc_mac, right->efs_loc_mac, EFX_MAC_ADDR_LEN))
474 if (left->efs_rem_port != right->efs_rem_port)
476 if (left->efs_loc_port != right->efs_loc_port)
478 if (left->efs_inner_vid != right->efs_inner_vid)
480 if (left->efs_outer_vid != right->efs_outer_vid)
482 if (left->efs_ether_type != right->efs_ether_type)
484 if (left->efs_ip_proto != right->efs_ip_proto)
486 if (left->efs_encap_type != right->efs_encap_type)
488 if (memcmp(left->efs_vni_or_vsid, right->efs_vni_or_vsid,
489 EFX_VNI_OR_VSID_LEN))
491 if (memcmp(left->efs_ifrm_loc_mac, right->efs_ifrm_loc_mac,
499 static __checkReturn boolean_t
500 ef10_filter_same_dest(
501 __in const efx_filter_spec_t *left,
502 __in const efx_filter_spec_t *right)
504 if ((left->efs_flags & EFX_FILTER_FLAG_RX_RSS) &&
505 (right->efs_flags & EFX_FILTER_FLAG_RX_RSS)) {
506 if (left->efs_rss_context == right->efs_rss_context)
508 } else if ((~(left->efs_flags) & EFX_FILTER_FLAG_RX_RSS) &&
509 (~(right->efs_flags) & EFX_FILTER_FLAG_RX_RSS)) {
510 if (left->efs_dmaq_id == right->efs_dmaq_id)
516 static __checkReturn uint32_t
518 __in efx_filter_spec_t *spec)
520 EFX_STATIC_ASSERT((sizeof (efx_filter_spec_t) % sizeof (uint32_t))
522 EFX_STATIC_ASSERT((EFX_FIELD_OFFSET(efx_filter_spec_t, efs_outer_vid) %
523 sizeof (uint32_t)) == 0);
526 * As the area of the efx_filter_spec_t we need to hash is DWORD
527 * aligned and an exact number of DWORDs in size we can use the
528 * optimised efx_hash_dwords() rather than efx_hash_bytes()
530 return (efx_hash_dwords((const uint32_t *)&spec->efs_outer_vid,
531 (sizeof (efx_filter_spec_t) -
532 EFX_FIELD_OFFSET(efx_filter_spec_t, efs_outer_vid)) /
533 sizeof (uint32_t), 0));
537 * Decide whether a filter should be exclusive or else should allow
538 * delivery to additional recipients. Currently we decide that
539 * filters for specific local unicast MAC and IP addresses are
542 static __checkReturn boolean_t
543 ef10_filter_is_exclusive(
544 __in efx_filter_spec_t *spec)
546 if ((spec->efs_match_flags & EFX_FILTER_MATCH_LOC_MAC) &&
547 !EFX_MAC_ADDR_IS_MULTICAST(spec->efs_loc_mac))
550 if ((spec->efs_match_flags &
551 (EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_LOC_HOST)) ==
552 (EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_LOC_HOST)) {
553 if ((spec->efs_ether_type == EFX_ETHER_TYPE_IPV4) &&
554 ((spec->efs_loc_host.eo_u8[0] & 0xf) != 0xe))
556 if ((spec->efs_ether_type == EFX_ETHER_TYPE_IPV6) &&
557 (spec->efs_loc_host.eo_u8[0] != 0xff))
564 __checkReturn efx_rc_t
569 efx_filter_spec_t *spec;
570 ef10_filter_table_t *eftp = enp->en_filter.ef_ef10_filter_table;
572 efsys_lock_state_t state;
575 EFSYS_ASSERT(enp->en_family == EFX_FAMILY_HUNTINGTON ||
576 enp->en_family == EFX_FAMILY_MEDFORD ||
577 enp->en_family == EFX_FAMILY_MEDFORD2);
579 for (tbl_id = 0; tbl_id < EFX_EF10_FILTER_TBL_ROWS; tbl_id++) {
581 EFSYS_LOCK(enp->en_eslp, state);
583 spec = ef10_filter_entry_spec(eftp, tbl_id);
586 } else if (ef10_filter_entry_is_busy(eftp, tbl_id)) {
587 /* Ignore busy entries. */
590 ef10_filter_set_entry_busy(eftp, tbl_id);
594 EFSYS_UNLOCK(enp->en_eslp, state);
596 if (restoring == B_FALSE)
599 if (ef10_filter_is_exclusive(spec)) {
600 rc = efx_mcdi_filter_op_add(enp, spec,
601 MC_CMD_FILTER_OP_IN_OP_INSERT,
602 &eftp->eft_entry[tbl_id].efe_handle);
604 rc = efx_mcdi_filter_op_add(enp, spec,
605 MC_CMD_FILTER_OP_IN_OP_SUBSCRIBE,
606 &eftp->eft_entry[tbl_id].efe_handle);
612 EFSYS_LOCK(enp->en_eslp, state);
614 ef10_filter_set_entry_not_busy(eftp, tbl_id);
616 EFSYS_UNLOCK(enp->en_eslp, state);
622 EFSYS_PROBE1(fail1, efx_rc_t, rc);
628 * An arbitrary search limit for the software hash table. As per the linux net
631 #define EF10_FILTER_SEARCH_LIMIT 200
633 static __checkReturn efx_rc_t
634 ef10_filter_add_internal(
636 __inout efx_filter_spec_t *spec,
637 __in boolean_t may_replace,
638 __out_opt uint32_t *filter_id)
641 ef10_filter_table_t *eftp = enp->en_filter.ef_ef10_filter_table;
642 efx_filter_spec_t *saved_spec;
646 boolean_t replacing = B_FALSE;
648 efsys_lock_state_t state;
649 boolean_t locked = B_FALSE;
651 EFSYS_ASSERT(enp->en_family == EFX_FAMILY_HUNTINGTON ||
652 enp->en_family == EFX_FAMILY_MEDFORD ||
653 enp->en_family == EFX_FAMILY_MEDFORD2);
655 hash = ef10_filter_hash(spec);
658 * FIXME: Add support for inserting filters of different priorities
659 * and removing lower priority multicast filters (bug 42378)
663 * Find any existing filters with the same match tuple or
664 * else a free slot to insert at. If any of them are busy,
665 * we have to wait and retry.
670 EFSYS_LOCK(enp->en_eslp, state);
674 i = (hash + depth) & (EFX_EF10_FILTER_TBL_ROWS - 1);
675 saved_spec = ef10_filter_entry_spec(eftp, i);
681 } else if (ef10_filter_equal(spec, saved_spec)) {
682 if (ef10_filter_entry_is_busy(eftp, i))
684 if (saved_spec->efs_priority
685 == EFX_FILTER_PRI_AUTO) {
688 } else if (ef10_filter_is_exclusive(spec)) {
702 * Once we reach the maximum search depth, use
703 * the first suitable slot or return EBUSY if
706 if (depth == EF10_FILTER_SEARCH_LIMIT) {
715 EFSYS_UNLOCK(enp->en_eslp, state);
721 * Create a software table entry if necessary, and mark it
722 * busy. We might yet fail to insert, but any attempt to
723 * insert a conflicting filter while we're waiting for the
724 * firmware must find the busy entry.
726 saved_spec = ef10_filter_entry_spec(eftp, ins_index);
728 if (saved_spec->efs_priority == EFX_FILTER_PRI_AUTO) {
729 /* This is a filter we are refreshing */
730 ef10_filter_set_entry_not_auto_old(eftp, ins_index);
736 EFSYS_KMEM_ALLOC(enp->en_esip, sizeof (*spec), saved_spec);
742 ef10_filter_set_entry(eftp, ins_index, saved_spec);
744 ef10_filter_set_entry_busy(eftp, ins_index);
746 EFSYS_UNLOCK(enp->en_eslp, state);
750 * On replacing the filter handle may change after after a successful
754 rc = efx_mcdi_filter_op_add(enp, spec,
755 MC_CMD_FILTER_OP_IN_OP_REPLACE,
756 &eftp->eft_entry[ins_index].efe_handle);
757 } else if (ef10_filter_is_exclusive(spec)) {
758 rc = efx_mcdi_filter_op_add(enp, spec,
759 MC_CMD_FILTER_OP_IN_OP_INSERT,
760 &eftp->eft_entry[ins_index].efe_handle);
762 rc = efx_mcdi_filter_op_add(enp, spec,
763 MC_CMD_FILTER_OP_IN_OP_SUBSCRIBE,
764 &eftp->eft_entry[ins_index].efe_handle);
770 EFSYS_LOCK(enp->en_eslp, state);
774 /* Update the fields that may differ */
775 saved_spec->efs_priority = spec->efs_priority;
776 saved_spec->efs_flags = spec->efs_flags;
777 saved_spec->efs_rss_context = spec->efs_rss_context;
778 saved_spec->efs_dmaq_id = spec->efs_dmaq_id;
781 ef10_filter_set_entry_not_busy(eftp, ins_index);
785 EFSYS_UNLOCK(enp->en_eslp, state);
789 *filter_id = ins_index;
797 EFSYS_KMEM_FREE(enp->en_esip, sizeof (*spec), saved_spec);
800 ef10_filter_set_entry_not_busy(eftp, ins_index);
801 ef10_filter_set_entry(eftp, ins_index, NULL);
810 EFSYS_PROBE1(fail1, efx_rc_t, rc);
813 EFSYS_UNLOCK(enp->en_eslp, state);
818 __checkReturn efx_rc_t
821 __inout efx_filter_spec_t *spec,
822 __in boolean_t may_replace)
826 rc = ef10_filter_add_internal(enp, spec, may_replace, NULL);
833 EFSYS_PROBE1(fail1, efx_rc_t, rc);
839 static __checkReturn efx_rc_t
840 ef10_filter_delete_internal(
842 __in uint32_t filter_id)
845 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
846 efx_filter_spec_t *spec;
847 efsys_lock_state_t state;
848 uint32_t filter_idx = filter_id % EFX_EF10_FILTER_TBL_ROWS;
851 * Find the software table entry and mark it busy. Don't
852 * remove it yet; any attempt to update while we're waiting
853 * for the firmware must find the busy entry.
855 * FIXME: What if the busy flag is never cleared?
857 EFSYS_LOCK(enp->en_eslp, state);
858 while (ef10_filter_entry_is_busy(table, filter_idx)) {
859 EFSYS_UNLOCK(enp->en_eslp, state);
861 EFSYS_LOCK(enp->en_eslp, state);
863 if ((spec = ef10_filter_entry_spec(table, filter_idx)) != NULL) {
864 ef10_filter_set_entry_busy(table, filter_idx);
866 EFSYS_UNLOCK(enp->en_eslp, state);
874 * Try to remove the hardware filter. This may fail if the MC has
875 * rebooted (which frees all hardware filter resources).
877 if (ef10_filter_is_exclusive(spec)) {
878 rc = efx_mcdi_filter_op_delete(enp,
879 MC_CMD_FILTER_OP_IN_OP_REMOVE,
880 &table->eft_entry[filter_idx].efe_handle);
882 rc = efx_mcdi_filter_op_delete(enp,
883 MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE,
884 &table->eft_entry[filter_idx].efe_handle);
887 /* Free the software table entry */
888 EFSYS_LOCK(enp->en_eslp, state);
889 ef10_filter_set_entry_not_busy(table, filter_idx);
890 ef10_filter_set_entry(table, filter_idx, NULL);
891 EFSYS_UNLOCK(enp->en_eslp, state);
893 EFSYS_KMEM_FREE(enp->en_esip, sizeof (*spec), spec);
895 /* Check result of hardware filter removal */
905 EFSYS_PROBE1(fail1, efx_rc_t, rc);
910 __checkReturn efx_rc_t
913 __inout efx_filter_spec_t *spec)
916 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
917 efx_filter_spec_t *saved_spec;
921 efsys_lock_state_t state;
922 boolean_t locked = B_FALSE;
924 EFSYS_ASSERT(enp->en_family == EFX_FAMILY_HUNTINGTON ||
925 enp->en_family == EFX_FAMILY_MEDFORD ||
926 enp->en_family == EFX_FAMILY_MEDFORD2);
928 hash = ef10_filter_hash(spec);
930 EFSYS_LOCK(enp->en_eslp, state);
935 i = (hash + depth) & (EFX_EF10_FILTER_TBL_ROWS - 1);
936 saved_spec = ef10_filter_entry_spec(table, i);
937 if (saved_spec && ef10_filter_equal(spec, saved_spec) &&
938 ef10_filter_same_dest(spec, saved_spec)) {
941 if (depth == EF10_FILTER_SEARCH_LIMIT) {
948 EFSYS_UNLOCK(enp->en_eslp, state);
951 rc = ef10_filter_delete_internal(enp, i);
961 EFSYS_PROBE1(fail1, efx_rc_t, rc);
964 EFSYS_UNLOCK(enp->en_eslp, state);
969 static __checkReturn efx_rc_t
970 efx_mcdi_get_parser_disp_info(
972 __out_ecount(buffer_length) uint32_t *buffer,
973 __in size_t buffer_length,
974 __in boolean_t encap,
975 __out size_t *list_lengthp)
978 EFX_MCDI_DECLARE_BUF(payload, MC_CMD_GET_PARSER_DISP_INFO_IN_LEN,
979 MC_CMD_GET_PARSER_DISP_INFO_OUT_LENMAX);
980 size_t matches_count;
984 req.emr_cmd = MC_CMD_GET_PARSER_DISP_INFO;
985 req.emr_in_buf = payload;
986 req.emr_in_length = MC_CMD_GET_PARSER_DISP_INFO_IN_LEN;
987 req.emr_out_buf = payload;
988 req.emr_out_length = MC_CMD_GET_PARSER_DISP_INFO_OUT_LENMAX;
990 MCDI_IN_SET_DWORD(req, GET_PARSER_DISP_INFO_OUT_OP, encap ?
991 MC_CMD_GET_PARSER_DISP_INFO_IN_OP_GET_SUPPORTED_ENCAP_RX_MATCHES :
992 MC_CMD_GET_PARSER_DISP_INFO_IN_OP_GET_SUPPORTED_RX_MATCHES);
994 efx_mcdi_execute(enp, &req);
996 if (req.emr_rc != 0) {
1001 matches_count = MCDI_OUT_DWORD(req,
1002 GET_PARSER_DISP_INFO_OUT_NUM_SUPPORTED_MATCHES);
1004 if (req.emr_out_length_used <
1005 MC_CMD_GET_PARSER_DISP_INFO_OUT_LEN(matches_count)) {
1010 *list_lengthp = matches_count;
1012 if (buffer_length < matches_count) {
1018 * Check that the elements in the list in the MCDI response are the size
1019 * we expect, so we can just copy them directly. Any conversion of the
1020 * flags is handled by the caller.
1022 EFX_STATIC_ASSERT(sizeof (uint32_t) ==
1023 MC_CMD_GET_PARSER_DISP_INFO_OUT_SUPPORTED_MATCHES_LEN);
1025 list_size = matches_count *
1026 MC_CMD_GET_PARSER_DISP_INFO_OUT_SUPPORTED_MATCHES_LEN;
1028 MCDI_OUT2(req, uint32_t,
1029 GET_PARSER_DISP_INFO_OUT_SUPPORTED_MATCHES),
1039 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1044 __checkReturn efx_rc_t
1045 ef10_filter_supported_filters(
1046 __in efx_nic_t *enp,
1047 __out_ecount(buffer_length) uint32_t *buffer,
1048 __in size_t buffer_length,
1049 __out size_t *list_lengthp)
1051 efx_nic_cfg_t *encp = &(enp->en_nic_cfg);
1052 size_t mcdi_list_length;
1053 size_t mcdi_encap_list_length;
1056 uint32_t next_buf_idx;
1057 size_t next_buf_length;
1059 boolean_t no_space = B_FALSE;
1060 efx_filter_match_flags_t all_filter_flags =
1061 (EFX_FILTER_MATCH_REM_HOST | EFX_FILTER_MATCH_LOC_HOST |
1062 EFX_FILTER_MATCH_REM_MAC | EFX_FILTER_MATCH_REM_PORT |
1063 EFX_FILTER_MATCH_LOC_MAC | EFX_FILTER_MATCH_LOC_PORT |
1064 EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_INNER_VID |
1065 EFX_FILTER_MATCH_OUTER_VID | EFX_FILTER_MATCH_IP_PROTO |
1066 EFX_FILTER_MATCH_VNI_OR_VSID |
1067 EFX_FILTER_MATCH_IFRM_LOC_MAC |
1068 EFX_FILTER_MATCH_IFRM_UNKNOWN_MCAST_DST |
1069 EFX_FILTER_MATCH_IFRM_UNKNOWN_UCAST_DST |
1070 EFX_FILTER_MATCH_ENCAP_TYPE |
1071 EFX_FILTER_MATCH_UNKNOWN_MCAST_DST |
1072 EFX_FILTER_MATCH_UNKNOWN_UCAST_DST);
1075 * Two calls to MC_CMD_GET_PARSER_DISP_INFO are needed: one to get the
1076 * list of supported filters for ordinary packets, and then another to
1077 * get the list of supported filters for encapsulated packets. To
1078 * distinguish the second list from the first, the
1079 * EFX_FILTER_MATCH_ENCAP_TYPE flag is added to each filter for
1080 * encapsulated packets.
1082 rc = efx_mcdi_get_parser_disp_info(enp, buffer, buffer_length, B_FALSE,
1093 next_buf_length = 0;
1095 EFSYS_ASSERT(mcdi_list_length <= buffer_length);
1096 next_buf_idx = mcdi_list_length;
1097 next_buf_length = buffer_length - mcdi_list_length;
1100 if (encp->enc_tunnel_encapsulations_supported != 0) {
1101 rc = efx_mcdi_get_parser_disp_info(enp, &buffer[next_buf_idx],
1102 next_buf_length, B_TRUE, &mcdi_encap_list_length);
1109 for (i = next_buf_idx;
1110 i < next_buf_idx + mcdi_encap_list_length; i++)
1111 buffer[i] |= EFX_FILTER_MATCH_ENCAP_TYPE;
1114 mcdi_encap_list_length = 0;
1118 *list_lengthp = mcdi_list_length + mcdi_encap_list_length;
1124 * The static assertions in ef10_filter_init() ensure that the values of
1125 * the EFX_FILTER_MATCH flags match those used by MCDI, so they don't
1126 * need to be converted.
1128 * In case support is added to MCDI for additional flags, remove any
1129 * matches from the list which include flags we don't support. The order
1130 * of the matches is preserved as they are ordered from highest to
1133 EFSYS_ASSERT(mcdi_list_length + mcdi_encap_list_length <=
1136 for (i = 0; i < mcdi_list_length + mcdi_encap_list_length; i++) {
1137 if ((buffer[i] & ~all_filter_flags) == 0) {
1138 buffer[list_length] = buffer[i];
1143 *list_lengthp = list_length;
1152 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1157 static __checkReturn efx_rc_t
1158 ef10_filter_insert_unicast(
1159 __in efx_nic_t *enp,
1160 __in_ecount(6) uint8_t const *addr,
1161 __in efx_filter_flags_t filter_flags)
1163 ef10_filter_table_t *eftp = enp->en_filter.ef_ef10_filter_table;
1164 efx_filter_spec_t spec;
1167 /* Insert the filter for the local station address */
1168 efx_filter_spec_init_rx(&spec, EFX_FILTER_PRI_AUTO,
1170 eftp->eft_default_rxq);
1171 rc = efx_filter_spec_set_eth_local(&spec, EFX_FILTER_SPEC_VID_UNSPEC,
1176 rc = ef10_filter_add_internal(enp, &spec, B_TRUE,
1177 &eftp->eft_unicst_filter_indexes[eftp->eft_unicst_filter_count]);
1181 eftp->eft_unicst_filter_count++;
1182 EFSYS_ASSERT(eftp->eft_unicst_filter_count <=
1183 EFX_EF10_FILTER_UNICAST_FILTERS_MAX);
1190 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1194 static __checkReturn efx_rc_t
1195 ef10_filter_insert_all_unicast(
1196 __in efx_nic_t *enp,
1197 __in efx_filter_flags_t filter_flags)
1199 ef10_filter_table_t *eftp = enp->en_filter.ef_ef10_filter_table;
1200 efx_filter_spec_t spec;
1203 /* Insert the unknown unicast filter */
1204 efx_filter_spec_init_rx(&spec, EFX_FILTER_PRI_AUTO,
1206 eftp->eft_default_rxq);
1207 rc = efx_filter_spec_set_uc_def(&spec);
1210 rc = ef10_filter_add_internal(enp, &spec, B_TRUE,
1211 &eftp->eft_unicst_filter_indexes[eftp->eft_unicst_filter_count]);
1215 eftp->eft_unicst_filter_count++;
1216 EFSYS_ASSERT(eftp->eft_unicst_filter_count <=
1217 EFX_EF10_FILTER_UNICAST_FILTERS_MAX);
1224 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1228 static __checkReturn efx_rc_t
1229 ef10_filter_insert_multicast_list(
1230 __in efx_nic_t *enp,
1231 __in boolean_t mulcst,
1232 __in boolean_t brdcst,
1233 __in_ecount(6*count) uint8_t const *addrs,
1234 __in uint32_t count,
1235 __in efx_filter_flags_t filter_flags,
1236 __in boolean_t rollback)
1238 ef10_filter_table_t *eftp = enp->en_filter.ef_ef10_filter_table;
1239 efx_filter_spec_t spec;
1242 uint32_t filter_index;
1243 uint32_t filter_count;
1246 if (mulcst == B_FALSE)
1249 if (count + (brdcst ? 1 : 0) >
1250 EFX_ARRAY_SIZE(eftp->eft_mulcst_filter_indexes)) {
1251 /* Too many MAC addresses */
1256 /* Insert/renew multicast address list filters */
1258 for (i = 0; i < count; i++) {
1259 efx_filter_spec_init_rx(&spec,
1260 EFX_FILTER_PRI_AUTO,
1262 eftp->eft_default_rxq);
1264 rc = efx_filter_spec_set_eth_local(&spec,
1265 EFX_FILTER_SPEC_VID_UNSPEC,
1266 &addrs[i * EFX_MAC_ADDR_LEN]);
1268 if (rollback == B_TRUE) {
1269 /* Only stop upon failure if told to rollback */
1273 * Don't try to add a filter with a corrupt
1280 rc = ef10_filter_add_internal(enp, &spec, B_TRUE,
1284 eftp->eft_mulcst_filter_indexes[filter_count] =
1287 } else if (rollback == B_TRUE) {
1288 /* Only stop upon failure if told to rollback */
1294 if (brdcst == B_TRUE) {
1295 /* Insert/renew broadcast address filter */
1296 efx_filter_spec_init_rx(&spec, EFX_FILTER_PRI_AUTO,
1298 eftp->eft_default_rxq);
1300 EFX_MAC_BROADCAST_ADDR_SET(addr);
1301 rc = efx_filter_spec_set_eth_local(&spec,
1302 EFX_FILTER_SPEC_VID_UNSPEC, addr);
1303 if ((rc != 0) && (rollback == B_TRUE)) {
1304 /* Only stop upon failure if told to rollback */
1308 rc = ef10_filter_add_internal(enp, &spec, B_TRUE,
1312 eftp->eft_mulcst_filter_indexes[filter_count] =
1315 } else if (rollback == B_TRUE) {
1316 /* Only stop upon failure if told to rollback */
1321 eftp->eft_mulcst_filter_count = filter_count;
1322 eftp->eft_using_all_mulcst = B_FALSE;
1327 /* Remove any filters we have inserted */
1330 (void) ef10_filter_delete_internal(enp,
1331 eftp->eft_mulcst_filter_indexes[i]);
1333 eftp->eft_mulcst_filter_count = 0;
1336 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1341 static __checkReturn efx_rc_t
1342 ef10_filter_insert_all_multicast(
1343 __in efx_nic_t *enp,
1344 __in efx_filter_flags_t filter_flags)
1346 ef10_filter_table_t *eftp = enp->en_filter.ef_ef10_filter_table;
1347 efx_filter_spec_t spec;
1350 /* Insert the unknown multicast filter */
1351 efx_filter_spec_init_rx(&spec, EFX_FILTER_PRI_AUTO,
1353 eftp->eft_default_rxq);
1354 rc = efx_filter_spec_set_mc_def(&spec);
1358 rc = ef10_filter_add_internal(enp, &spec, B_TRUE,
1359 &eftp->eft_mulcst_filter_indexes[0]);
1363 eftp->eft_mulcst_filter_count = 1;
1364 eftp->eft_using_all_mulcst = B_TRUE;
1367 * FIXME: If brdcst == B_FALSE, add a filter to drop broadcast traffic.
1375 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1380 typedef struct ef10_filter_encap_entry_s {
1381 uint16_t ether_type;
1382 efx_tunnel_protocol_t encap_type;
1383 uint32_t inner_frame_match;
1384 } ef10_filter_encap_entry_t;
1386 #define EF10_ENCAP_FILTER_ENTRY(ipv, encap_type, inner_frame_match) \
1387 { EFX_ETHER_TYPE_##ipv, EFX_TUNNEL_PROTOCOL_##encap_type, \
1388 EFX_FILTER_INNER_FRAME_MATCH_UNKNOWN_##inner_frame_match }
1390 static ef10_filter_encap_entry_t ef10_filter_encap_list[] = {
1391 EF10_ENCAP_FILTER_ENTRY(IPV4, VXLAN, UCAST_DST),
1392 EF10_ENCAP_FILTER_ENTRY(IPV4, VXLAN, MCAST_DST),
1393 EF10_ENCAP_FILTER_ENTRY(IPV6, VXLAN, UCAST_DST),
1394 EF10_ENCAP_FILTER_ENTRY(IPV6, VXLAN, MCAST_DST),
1396 EF10_ENCAP_FILTER_ENTRY(IPV4, GENEVE, UCAST_DST),
1397 EF10_ENCAP_FILTER_ENTRY(IPV4, GENEVE, MCAST_DST),
1398 EF10_ENCAP_FILTER_ENTRY(IPV6, GENEVE, UCAST_DST),
1399 EF10_ENCAP_FILTER_ENTRY(IPV6, GENEVE, MCAST_DST),
1401 EF10_ENCAP_FILTER_ENTRY(IPV4, NVGRE, UCAST_DST),
1402 EF10_ENCAP_FILTER_ENTRY(IPV4, NVGRE, MCAST_DST),
1403 EF10_ENCAP_FILTER_ENTRY(IPV6, NVGRE, UCAST_DST),
1404 EF10_ENCAP_FILTER_ENTRY(IPV6, NVGRE, MCAST_DST),
1407 #undef EF10_ENCAP_FILTER_ENTRY
1409 static __checkReturn efx_rc_t
1410 ef10_filter_insert_encap_filters(
1411 __in efx_nic_t *enp,
1412 __in boolean_t mulcst,
1413 __in efx_filter_flags_t filter_flags)
1415 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
1419 EFX_STATIC_ASSERT(EFX_ARRAY_SIZE(ef10_filter_encap_list) <=
1420 EFX_ARRAY_SIZE(table->eft_encap_filter_indexes));
1423 * On Medford, full-featured firmware can identify packets as being
1424 * tunnel encapsulated, even if no encapsulated packet offloads are in
1425 * use. When packets are identified as such, ordinary filters are not
1426 * applied, only ones specific to encapsulated packets. Hence we need to
1427 * insert filters for encapsulated packets in order to receive them.
1429 * Separate filters need to be inserted for each ether type,
1430 * encapsulation type, and inner frame type (unicast or multicast). To
1431 * keep things simple and reduce the number of filters needed, catch-all
1432 * filters for all combinations of types are inserted, even if
1433 * all_unicst or all_mulcst have not been set. (These catch-all filters
1434 * may well, however, fail to insert on unprivileged functions.)
1436 table->eft_encap_filter_count = 0;
1437 for (i = 0; i < EFX_ARRAY_SIZE(ef10_filter_encap_list); i++) {
1438 efx_filter_spec_t spec;
1439 ef10_filter_encap_entry_t *encap_filter =
1440 &ef10_filter_encap_list[i];
1443 * Skip multicast filters if we've not been asked for
1444 * any multicast traffic.
1446 if ((mulcst == B_FALSE) &&
1447 (encap_filter->inner_frame_match ==
1448 EFX_FILTER_INNER_FRAME_MATCH_UNKNOWN_MCAST_DST))
1451 efx_filter_spec_init_rx(&spec, EFX_FILTER_PRI_AUTO,
1453 table->eft_default_rxq);
1454 efx_filter_spec_set_ether_type(&spec, encap_filter->ether_type);
1455 rc = efx_filter_spec_set_encap_type(&spec,
1456 encap_filter->encap_type,
1457 encap_filter->inner_frame_match);
1461 rc = ef10_filter_add_internal(enp, &spec, B_TRUE,
1462 &table->eft_encap_filter_indexes[
1463 table->eft_encap_filter_count]);
1468 table->eft_encap_filter_count++;
1477 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1483 ef10_filter_remove_old(
1484 __in efx_nic_t *enp)
1486 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
1489 for (i = 0; i < EFX_ARRAY_SIZE(table->eft_entry); i++) {
1490 if (ef10_filter_entry_is_auto_old(table, i)) {
1491 (void) ef10_filter_delete_internal(enp, i);
1497 static __checkReturn efx_rc_t
1498 ef10_filter_get_workarounds(
1499 __in efx_nic_t *enp)
1501 efx_nic_cfg_t *encp = &enp->en_nic_cfg;
1502 uint32_t implemented = 0;
1503 uint32_t enabled = 0;
1506 rc = efx_mcdi_get_workarounds(enp, &implemented, &enabled);
1508 /* Check if chained multicast filter support is enabled */
1509 if (implemented & enabled & MC_CMD_GET_WORKAROUNDS_OUT_BUG26807)
1510 encp->enc_bug26807_workaround = B_TRUE;
1512 encp->enc_bug26807_workaround = B_FALSE;
1513 } else if (rc == ENOTSUP) {
1515 * Firmware is too old to support GET_WORKAROUNDS, and support
1516 * for this workaround was implemented later.
1518 encp->enc_bug26807_workaround = B_FALSE;
1526 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1534 * Reconfigure all filters.
1535 * If all_unicst and/or all mulcst filters cannot be applied then
1536 * return ENOTSUP (Note the filters for the specified addresses are
1537 * still applied in this case).
1539 __checkReturn efx_rc_t
1540 ef10_filter_reconfigure(
1541 __in efx_nic_t *enp,
1542 __in_ecount(6) uint8_t const *mac_addr,
1543 __in boolean_t all_unicst,
1544 __in boolean_t mulcst,
1545 __in boolean_t all_mulcst,
1546 __in boolean_t brdcst,
1547 __in_ecount(6*count) uint8_t const *addrs,
1548 __in uint32_t count)
1550 efx_nic_cfg_t *encp = &enp->en_nic_cfg;
1551 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
1552 efx_filter_flags_t filter_flags;
1554 efx_rc_t all_unicst_rc = 0;
1555 efx_rc_t all_mulcst_rc = 0;
1558 if (table->eft_default_rxq == NULL) {
1560 * Filters direct traffic to the default RXQ, and so cannot be
1561 * inserted until it is available. Any currently configured
1562 * filters must be removed (ignore errors in case the MC
1563 * has rebooted, which removes hardware filters).
1565 for (i = 0; i < table->eft_unicst_filter_count; i++) {
1566 (void) ef10_filter_delete_internal(enp,
1567 table->eft_unicst_filter_indexes[i]);
1569 table->eft_unicst_filter_count = 0;
1571 for (i = 0; i < table->eft_mulcst_filter_count; i++) {
1572 (void) ef10_filter_delete_internal(enp,
1573 table->eft_mulcst_filter_indexes[i]);
1575 table->eft_mulcst_filter_count = 0;
1577 for (i = 0; i < table->eft_encap_filter_count; i++) {
1578 (void) ef10_filter_delete_internal(enp,
1579 table->eft_encap_filter_indexes[i]);
1581 table->eft_encap_filter_count = 0;
1586 if (table->eft_using_rss)
1587 filter_flags = EFX_FILTER_FLAG_RX_RSS;
1591 /* Mark old filters which may need to be removed */
1592 for (i = 0; i < table->eft_unicst_filter_count; i++) {
1593 ef10_filter_set_entry_auto_old(table,
1594 table->eft_unicst_filter_indexes[i]);
1596 for (i = 0; i < table->eft_mulcst_filter_count; i++) {
1597 ef10_filter_set_entry_auto_old(table,
1598 table->eft_mulcst_filter_indexes[i]);
1600 for (i = 0; i < table->eft_encap_filter_count; i++) {
1601 ef10_filter_set_entry_auto_old(table,
1602 table->eft_encap_filter_indexes[i]);
1606 * Insert or renew unicast filters.
1608 * Firmware does not perform chaining on unicast filters. As traffic is
1609 * therefore only delivered to the first matching filter, we should
1610 * always insert the specific filter for our MAC address, to try and
1611 * ensure we get that traffic.
1613 * (If the filter for our MAC address has already been inserted by
1614 * another function, we won't receive traffic sent to us, even if we
1615 * insert a unicast mismatch filter. To prevent traffic stealing, this
1616 * therefore relies on the privilege model only allowing functions to
1617 * insert filters for their own MAC address unless explicitly given
1618 * additional privileges by the user. This also means that, even on a
1619 * priviliged function, inserting a unicast mismatch filter may not
1620 * catch all traffic in multi PCI function scenarios.)
1622 table->eft_unicst_filter_count = 0;
1623 rc = ef10_filter_insert_unicast(enp, mac_addr, filter_flags);
1624 if (all_unicst || (rc != 0)) {
1625 all_unicst_rc = ef10_filter_insert_all_unicast(enp,
1627 if ((rc != 0) && (all_unicst_rc != 0))
1632 * WORKAROUND_BUG26807 controls firmware support for chained multicast
1633 * filters, and can only be enabled or disabled when the hardware filter
1636 * Chained multicast filters require support from the datapath firmware,
1637 * and may not be available (e.g. low-latency variants or old Huntington
1640 * Firmware will reset (FLR) functions which have inserted filters in
1641 * the hardware filter table when the workaround is enabled/disabled.
1642 * Functions without any hardware filters are not reset.
1644 * Re-check if the workaround is enabled after adding unicast hardware
1645 * filters. This ensures that encp->enc_bug26807_workaround matches the
1646 * firmware state, and that later changes to enable/disable the
1647 * workaround will result in this function seeing a reset (FLR).
1649 * In common-code drivers, we only support multiple PCI function
1650 * scenarios with firmware that supports multicast chaining, so we can
1651 * assume it is enabled for such cases and hence simplify the filter
1652 * insertion logic. Firmware that does not support multicast chaining
1653 * does not support multiple PCI function configurations either, so
1654 * filter insertion is much simpler and the same strategies can still be
1657 if ((rc = ef10_filter_get_workarounds(enp)) != 0)
1660 if ((table->eft_using_all_mulcst != all_mulcst) &&
1661 (encp->enc_bug26807_workaround == B_TRUE)) {
1663 * Multicast filter chaining is enabled, so traffic that matches
1664 * more than one multicast filter will be replicated and
1665 * delivered to multiple recipients. To avoid this duplicate
1666 * delivery, remove old multicast filters before inserting new
1667 * multicast filters.
1669 ef10_filter_remove_old(enp);
1672 /* Insert or renew multicast filters */
1673 if (all_mulcst == B_TRUE) {
1675 * Insert the all multicast filter. If that fails, try to insert
1676 * all of our multicast filters (but without rollback on
1679 all_mulcst_rc = ef10_filter_insert_all_multicast(enp,
1681 if (all_mulcst_rc != 0) {
1682 rc = ef10_filter_insert_multicast_list(enp, B_TRUE,
1683 brdcst, addrs, count, filter_flags, B_FALSE);
1689 * Insert filters for multicast addresses.
1690 * If any insertion fails, then rollback and try to insert the
1691 * all multicast filter instead.
1692 * If that also fails, try to insert all of the multicast
1693 * filters (but without rollback on failure).
1695 rc = ef10_filter_insert_multicast_list(enp, mulcst, brdcst,
1696 addrs, count, filter_flags, B_TRUE);
1698 if ((table->eft_using_all_mulcst == B_FALSE) &&
1699 (encp->enc_bug26807_workaround == B_TRUE)) {
1701 * Multicast filter chaining is on, so remove
1702 * old filters before inserting the multicast
1703 * all filter to avoid duplicate delivery caused
1704 * by packets matching multiple filters.
1706 ef10_filter_remove_old(enp);
1709 rc = ef10_filter_insert_all_multicast(enp,
1712 rc = ef10_filter_insert_multicast_list(enp,
1714 addrs, count, filter_flags, B_FALSE);
1721 if (encp->enc_tunnel_encapsulations_supported != 0) {
1722 /* Try to insert filters for encapsulated packets. */
1723 (void) ef10_filter_insert_encap_filters(enp,
1724 mulcst || all_mulcst || brdcst,
1728 /* Remove old filters which were not renewed */
1729 ef10_filter_remove_old(enp);
1731 /* report if any optional flags were rejected */
1732 if (((all_unicst != B_FALSE) && (all_unicst_rc != 0)) ||
1733 ((all_mulcst != B_FALSE) && (all_mulcst_rc != 0))) {
1746 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1748 /* Clear auto old flags */
1749 for (i = 0; i < EFX_ARRAY_SIZE(table->eft_entry); i++) {
1750 if (ef10_filter_entry_is_auto_old(table, i)) {
1751 ef10_filter_set_entry_not_auto_old(table, i);
1759 ef10_filter_get_default_rxq(
1760 __in efx_nic_t *enp,
1761 __out efx_rxq_t **erpp,
1762 __out boolean_t *using_rss)
1764 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
1766 *erpp = table->eft_default_rxq;
1767 *using_rss = table->eft_using_rss;
1772 ef10_filter_default_rxq_set(
1773 __in efx_nic_t *enp,
1774 __in efx_rxq_t *erp,
1775 __in boolean_t using_rss)
1777 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
1779 #if EFSYS_OPT_RX_SCALE
1780 EFSYS_ASSERT((using_rss == B_FALSE) ||
1781 (enp->en_rss_context != EF10_RSS_CONTEXT_INVALID));
1782 table->eft_using_rss = using_rss;
1784 EFSYS_ASSERT(using_rss == B_FALSE);
1785 table->eft_using_rss = B_FALSE;
1787 table->eft_default_rxq = erp;
1791 ef10_filter_default_rxq_clear(
1792 __in efx_nic_t *enp)
1794 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
1796 table->eft_default_rxq = NULL;
1797 table->eft_using_rss = B_FALSE;
1801 #endif /* EFSYS_OPT_FILTER */
1803 #endif /* EFSYS_OPT_HUNTINGTON || EFSYS_OPT_MEDFORD || EFSYS_OPT_MEDFORD2 */