1 /* SPDX-License-Identifier: BSD-3-Clause
3 * Copyright(c) 2019-2020 Xilinx, Inc.
4 * Copyright(c) 2007-2019 Solarflare Communications Inc.
10 #if EFSYS_OPT_RIVERHEAD || EFX_OPTS_EF10()
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_EF100(enp) || 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_EF100(enp) || 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_EF100(enp) || 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);
593 enum ef10_filter_add_action_e {
594 /* Insert a new filter */
597 * Replace old filter with a new, overriding the old one
598 * if it has lower priority.
600 EF10_FILTER_ADD_REPLACE,
601 /* Store new, lower priority filter as overridden by old filter */
602 EF10_FILTER_ADD_STORE,
603 /* Special case for AUTO filters, remove AUTO_OLD flag */
604 EF10_FILTER_ADD_REFRESH,
607 static __checkReturn efx_rc_t
608 ef10_filter_add_lookup_equal_spec(
609 __in efx_filter_spec_t *spec,
610 __in efx_filter_spec_t *probe_spec,
611 __in efx_filter_replacement_policy_t policy,
612 __out boolean_t *found)
616 /* Refreshing AUTO filter */
617 if (spec->efs_priority == EFX_FILTER_PRI_AUTO &&
618 probe_spec->efs_priority == EFX_FILTER_PRI_AUTO) {
624 * With exclusive filters, higher priority ones
625 * override lower priority ones, and lower priority
626 * ones are stored in case the higher priority one
629 if (ef10_filter_is_exclusive(spec)) {
631 case EFX_FILTER_REPLACEMENT_HIGHER_OR_EQUAL_PRIORITY:
632 if (spec->efs_priority == probe_spec->efs_priority) {
637 case EFX_FILTER_REPLACEMENT_HIGHER_PRIORITY:
638 if (spec->efs_priority > probe_spec->efs_priority) {
643 case EFX_FILTER_REPLACEMENT_NEVER:
645 * Lower priority filter needs to be
646 * stored. It does *not* replace the
647 * old one. That is why EEXIST is not
648 * returned in that case.
650 if (spec->efs_priority < probe_spec->efs_priority) {
672 EFSYS_PROBE1(fail1, efx_rc_t, rc);
679 ef10_filter_add_select_action(
680 __in efx_filter_spec_t *saved_spec,
681 __in efx_filter_spec_t *spec,
682 __out enum ef10_filter_add_action_e *action,
683 __out efx_filter_spec_t **overridden_spec)
685 efx_filter_spec_t *overridden = NULL;
687 if (saved_spec == NULL) {
688 *action = EF10_FILTER_ADD_NEW;
689 } else if (ef10_filter_is_exclusive(spec) == B_FALSE) {
691 * Non-exclusive filters are always stored in separate entries
692 * in the table. The only case involving a saved spec is
693 * refreshing an AUTO filter.
695 EFSYS_ASSERT(saved_spec->efs_overridden_spec == NULL);
696 EFSYS_ASSERT(spec->efs_priority == EFX_FILTER_PRI_AUTO);
697 EFSYS_ASSERT(saved_spec->efs_priority == EFX_FILTER_PRI_AUTO);
698 *action = EF10_FILTER_ADD_REFRESH;
700 /* Exclusive filters stored in the same entry */
701 if (spec->efs_priority > saved_spec->efs_priority) {
703 * Insert a high priority filter over a lower priority
704 * one. Only two priority levels are implemented, so
705 * there must not already be an overridden filter.
707 EFX_STATIC_ASSERT(EFX_FILTER_NPRI == 2);
708 EFSYS_ASSERT(saved_spec->efs_overridden_spec == NULL);
709 overridden = saved_spec;
710 *action = EF10_FILTER_ADD_REPLACE;
711 } else if (spec->efs_priority == saved_spec->efs_priority) {
712 /* Replace in-place or refresh an existing filter */
713 if (spec->efs_priority == EFX_FILTER_PRI_AUTO)
714 *action = EF10_FILTER_ADD_REFRESH;
716 *action = EF10_FILTER_ADD_REPLACE;
719 * Insert a lower priority filter, storing it in case
720 * the higher priority filter is removed.
722 * Currently there are only two priority levels, so this
723 * must be an AUTO filter.
725 EFX_STATIC_ASSERT(EFX_FILTER_NPRI == 2);
726 EFSYS_ASSERT(spec->efs_priority == EFX_FILTER_PRI_AUTO);
727 if (saved_spec->efs_overridden_spec != NULL) {
728 *action = EF10_FILTER_ADD_REFRESH;
731 *action = EF10_FILTER_ADD_STORE;
736 *overridden_spec = overridden;
739 static __checkReturn efx_rc_t
740 ef10_filter_add_execute_action(
742 __in efx_filter_spec_t *saved_spec,
743 __in efx_filter_spec_t *spec,
744 __in efx_filter_spec_t *overridden_spec,
745 __in enum ef10_filter_add_action_e action,
748 ef10_filter_table_t *eftp = enp->en_filter.ef_ef10_filter_table;
749 efsys_lock_state_t state;
752 EFSYS_LOCK(enp->en_eslp, state);
754 if (action == EF10_FILTER_ADD_REFRESH) {
755 ef10_filter_set_entry_not_auto_old(eftp, ins_index);
757 } else if (action == EF10_FILTER_ADD_STORE) {
758 EFSYS_ASSERT(overridden_spec != NULL);
759 saved_spec->efs_overridden_spec = overridden_spec;
763 EFSYS_UNLOCK(enp->en_eslp, state);
766 case EF10_FILTER_ADD_REPLACE:
768 * On replacing the filter handle may change after a
769 * successful replace operation.
771 rc = efx_mcdi_filter_op_add(enp, spec,
772 MC_CMD_FILTER_OP_IN_OP_REPLACE,
773 &eftp->eft_entry[ins_index].efe_handle);
775 case EF10_FILTER_ADD_NEW:
776 if (ef10_filter_is_exclusive(spec)) {
777 rc = efx_mcdi_filter_op_add(enp, spec,
778 MC_CMD_FILTER_OP_IN_OP_INSERT,
779 &eftp->eft_entry[ins_index].efe_handle);
781 rc = efx_mcdi_filter_op_add(enp, spec,
782 MC_CMD_FILTER_OP_IN_OP_SUBSCRIBE,
783 &eftp->eft_entry[ins_index].efe_handle);
794 EFSYS_LOCK(enp->en_eslp, state);
796 if (action == EF10_FILTER_ADD_REPLACE) {
797 /* Update the fields that may differ */
798 saved_spec->efs_priority = spec->efs_priority;
799 saved_spec->efs_flags = spec->efs_flags;
800 saved_spec->efs_rss_context = spec->efs_rss_context;
801 saved_spec->efs_dmaq_id = spec->efs_dmaq_id;
803 if (overridden_spec != NULL)
804 saved_spec->efs_overridden_spec = overridden_spec;
808 EFSYS_UNLOCK(enp->en_eslp, state);
813 EFSYS_PROBE1(fail1, efx_rc_t, rc);
819 * An arbitrary search limit for the software hash table. As per the linux net
822 #define EF10_FILTER_SEARCH_LIMIT 200
824 static __checkReturn efx_rc_t
825 ef10_filter_add_internal(
827 __inout efx_filter_spec_t *spec,
828 __in efx_filter_replacement_policy_t policy,
829 __out_opt uint32_t *filter_id)
832 ef10_filter_table_t *eftp = enp->en_filter.ef_ef10_filter_table;
833 enum ef10_filter_add_action_e action;
834 efx_filter_spec_t *overridden_spec = NULL;
835 efx_filter_spec_t *saved_spec;
839 efsys_lock_state_t state;
840 boolean_t locked = B_FALSE;
842 EFSYS_ASSERT(EFX_FAMILY_IS_EF100(enp) || EFX_FAMILY_IS_EF10(enp));
844 EFSYS_ASSERT(spec->efs_overridden_spec == NULL);
846 hash = ef10_filter_hash(spec);
849 * FIXME: Add support for inserting filters of different priorities
850 * and removing lower priority multicast filters (bug 42378)
854 * Find any existing filters with the same match tuple or
855 * else a free slot to insert at. If any of them are busy,
856 * we have to wait and retry.
859 EFSYS_LOCK(enp->en_eslp, state);
864 for (depth = 1; depth <= EF10_FILTER_SEARCH_LIMIT; depth++) {
865 unsigned int probe_index;
866 efx_filter_spec_t *probe_spec;
868 probe_index = (hash + depth) & (EFX_EF10_FILTER_TBL_ROWS - 1);
869 probe_spec = ef10_filter_entry_spec(eftp, probe_index);
871 if (probe_spec == NULL) {
873 ins_index = probe_index;
874 } else if (ef10_filter_equal(spec, probe_spec)) {
877 if (ef10_filter_entry_is_busy(eftp, probe_index)) {
878 EFSYS_UNLOCK(enp->en_eslp, state);
883 rc = ef10_filter_add_lookup_equal_spec(spec,
884 probe_spec, policy, &found);
888 if (found != B_FALSE) {
889 ins_index = probe_index;
896 * Once we reach the maximum search depth, use the first suitable slot
897 * or return EBUSY if there was none.
905 * Mark software table entry busy. We might yet fail to insert,
906 * but any attempt to insert a conflicting filter while we're
907 * waiting for the firmware must find the busy entry.
909 ef10_filter_set_entry_busy(eftp, ins_index);
911 saved_spec = ef10_filter_entry_spec(eftp, ins_index);
912 ef10_filter_add_select_action(saved_spec, spec, &action,
916 * Allocate a new filter if found entry is empty or
917 * a filter should be overridden.
919 if (overridden_spec != NULL || saved_spec == NULL) {
920 efx_filter_spec_t *new_spec;
922 EFSYS_UNLOCK(enp->en_eslp, state);
925 EFSYS_KMEM_ALLOC(enp->en_esip, sizeof (*new_spec), new_spec);
926 if (new_spec == NULL) {
928 overridden_spec = NULL;
932 EFSYS_LOCK(enp->en_eslp, state);
935 if (saved_spec == NULL) {
937 ef10_filter_set_entry(eftp, ins_index, new_spec);
939 *new_spec = *overridden_spec;
940 overridden_spec = new_spec;
944 EFSYS_UNLOCK(enp->en_eslp, state);
947 rc = ef10_filter_add_execute_action(enp, saved_spec, spec,
948 overridden_spec, action, ins_index);
953 *filter_id = ins_index;
955 EFSYS_LOCK(enp->en_eslp, state);
956 ef10_filter_set_entry_not_busy(eftp, ins_index);
957 EFSYS_UNLOCK(enp->en_eslp, state);
964 EFSYS_ASSERT(locked == B_FALSE);
965 EFSYS_LOCK(enp->en_eslp, state);
967 if (action == EF10_FILTER_ADD_NEW) {
968 EFSYS_KMEM_FREE(enp->en_esip, sizeof (*spec),
969 ef10_filter_entry_spec(eftp, ins_index));
970 ef10_filter_set_entry(eftp, ins_index, NULL);
973 EFSYS_UNLOCK(enp->en_eslp, state);
975 if (overridden_spec != NULL)
976 EFSYS_KMEM_FREE(enp->en_esip, sizeof (*spec), overridden_spec);
981 EFSYS_ASSERT(locked == B_FALSE);
982 EFSYS_LOCK(enp->en_eslp, state);
984 ef10_filter_set_entry_not_busy(eftp, ins_index);
986 EFSYS_UNLOCK(enp->en_eslp, state);
992 EFSYS_PROBE1(fail1, efx_rc_t, rc);
995 EFSYS_UNLOCK(enp->en_eslp, state);
1000 __checkReturn efx_rc_t
1002 __in efx_nic_t *enp,
1003 __inout efx_filter_spec_t *spec,
1004 __in enum efx_filter_replacement_policy_e policy)
1008 rc = ef10_filter_add_internal(enp, spec, policy, NULL);
1015 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1021 * Delete a filter by index from the filter table with priority
1022 * that is not higher than specified.
1024 static __checkReturn efx_rc_t
1025 ef10_filter_delete_internal(
1026 __in efx_nic_t *enp,
1027 __in uint32_t filter_id,
1028 __in efx_filter_priority_t priority)
1031 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
1032 efx_filter_spec_t *spec;
1033 efsys_lock_state_t state;
1034 uint32_t filter_idx = filter_id % EFX_EF10_FILTER_TBL_ROWS;
1037 * Find the software table entry and mark it busy. Don't
1038 * remove it yet; any attempt to update while we're waiting
1039 * for the firmware must find the busy entry.
1041 * FIXME: What if the busy flag is never cleared?
1043 EFSYS_LOCK(enp->en_eslp, state);
1044 while (ef10_filter_entry_is_busy(table, filter_idx)) {
1045 EFSYS_UNLOCK(enp->en_eslp, state);
1047 EFSYS_LOCK(enp->en_eslp, state);
1049 if ((spec = ef10_filter_entry_spec(table, filter_idx)) != NULL) {
1050 if (spec->efs_priority <= priority)
1051 ef10_filter_set_entry_busy(table, filter_idx);
1053 EFSYS_UNLOCK(enp->en_eslp, state);
1060 if (spec->efs_priority > priority) {
1062 * Applied filter stays, but overridden filter is removed since
1063 * next user request to delete the applied filter should not
1064 * restore outdated filter.
1066 if (spec->efs_overridden_spec != NULL) {
1067 EFSYS_ASSERT(spec->efs_overridden_spec->efs_overridden_spec ==
1069 EFSYS_KMEM_FREE(enp->en_esip, sizeof (*spec),
1070 spec->efs_overridden_spec);
1071 spec->efs_overridden_spec = NULL;
1075 * Try to remove the hardware filter or replace it with the
1076 * saved automatic filter. This may fail if the MC has
1077 * rebooted (which frees all hardware filter resources).
1079 if (spec->efs_overridden_spec != NULL) {
1080 rc = efx_mcdi_filter_op_add(enp,
1081 spec->efs_overridden_spec,
1082 MC_CMD_FILTER_OP_IN_OP_REPLACE,
1083 &table->eft_entry[filter_idx].efe_handle);
1084 } else if (ef10_filter_is_exclusive(spec)) {
1085 rc = efx_mcdi_filter_op_delete(enp,
1086 MC_CMD_FILTER_OP_IN_OP_REMOVE,
1087 &table->eft_entry[filter_idx].efe_handle);
1089 rc = efx_mcdi_filter_op_delete(enp,
1090 MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE,
1091 &table->eft_entry[filter_idx].efe_handle);
1094 /* Free the software table entry */
1095 EFSYS_LOCK(enp->en_eslp, state);
1096 ef10_filter_set_entry_not_busy(table, filter_idx);
1097 ef10_filter_set_entry(table, filter_idx,
1098 spec->efs_overridden_spec);
1099 EFSYS_UNLOCK(enp->en_eslp, state);
1101 EFSYS_KMEM_FREE(enp->en_esip, sizeof (*spec), spec);
1103 /* Check result of hardware filter removal */
1114 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1120 ef10_filter_delete_auto(
1121 __in efx_nic_t *enp,
1122 __in uint32_t filter_id)
1124 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
1125 uint32_t filter_idx = filter_id % EFX_EF10_FILTER_TBL_ROWS;
1128 * AUTO_OLD flag is cleared since the auto filter that is to be removed
1129 * may not be the filter at the specified index itself, but the filter
1130 * that is overridden by it.
1132 ef10_filter_set_entry_not_auto_old(table, filter_idx);
1134 (void) ef10_filter_delete_internal(enp, filter_idx,
1135 EFX_FILTER_PRI_AUTO);
1138 __checkReturn efx_rc_t
1140 __in efx_nic_t *enp,
1141 __inout efx_filter_spec_t *spec)
1144 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
1145 efx_filter_spec_t *saved_spec;
1149 efsys_lock_state_t state;
1150 boolean_t locked = B_FALSE;
1152 EFSYS_ASSERT(EFX_FAMILY_IS_EF100(enp) || EFX_FAMILY_IS_EF10(enp));
1154 hash = ef10_filter_hash(spec);
1156 EFSYS_LOCK(enp->en_eslp, state);
1161 i = (hash + depth) & (EFX_EF10_FILTER_TBL_ROWS - 1);
1162 saved_spec = ef10_filter_entry_spec(table, i);
1163 if (saved_spec && ef10_filter_equal(spec, saved_spec) &&
1164 ef10_filter_same_dest(spec, saved_spec) &&
1165 saved_spec->efs_priority == EFX_FILTER_PRI_MANUAL) {
1168 if (depth == EF10_FILTER_SEARCH_LIMIT) {
1175 EFSYS_UNLOCK(enp->en_eslp, state);
1178 rc = ef10_filter_delete_internal(enp, i, EFX_FILTER_PRI_MANUAL);
1188 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1191 EFSYS_UNLOCK(enp->en_eslp, state);
1196 static __checkReturn efx_rc_t
1197 efx_mcdi_get_parser_disp_info(
1198 __in efx_nic_t *enp,
1199 __out_ecount(buffer_length) uint32_t *buffer,
1200 __in size_t buffer_length,
1201 __in boolean_t encap,
1202 __out size_t *list_lengthp)
1205 EFX_MCDI_DECLARE_BUF(payload, MC_CMD_GET_PARSER_DISP_INFO_IN_LEN,
1206 MC_CMD_GET_PARSER_DISP_INFO_OUT_LENMAX);
1207 size_t matches_count;
1211 req.emr_cmd = MC_CMD_GET_PARSER_DISP_INFO;
1212 req.emr_in_buf = payload;
1213 req.emr_in_length = MC_CMD_GET_PARSER_DISP_INFO_IN_LEN;
1214 req.emr_out_buf = payload;
1215 req.emr_out_length = MC_CMD_GET_PARSER_DISP_INFO_OUT_LENMAX;
1217 MCDI_IN_SET_DWORD(req, GET_PARSER_DISP_INFO_OUT_OP, encap ?
1218 MC_CMD_GET_PARSER_DISP_INFO_IN_OP_GET_SUPPORTED_ENCAP_RX_MATCHES :
1219 MC_CMD_GET_PARSER_DISP_INFO_IN_OP_GET_SUPPORTED_RX_MATCHES);
1221 efx_mcdi_execute(enp, &req);
1223 if (req.emr_rc != 0) {
1228 matches_count = MCDI_OUT_DWORD(req,
1229 GET_PARSER_DISP_INFO_OUT_NUM_SUPPORTED_MATCHES);
1231 if (req.emr_out_length_used <
1232 MC_CMD_GET_PARSER_DISP_INFO_OUT_LEN(matches_count)) {
1237 *list_lengthp = matches_count;
1239 if (buffer_length < matches_count) {
1245 * Check that the elements in the list in the MCDI response are the size
1246 * we expect, so we can just copy them directly. Any conversion of the
1247 * flags is handled by the caller.
1249 EFX_STATIC_ASSERT(sizeof (uint32_t) ==
1250 MC_CMD_GET_PARSER_DISP_INFO_OUT_SUPPORTED_MATCHES_LEN);
1252 list_size = matches_count *
1253 MC_CMD_GET_PARSER_DISP_INFO_OUT_SUPPORTED_MATCHES_LEN;
1255 MCDI_OUT2(req, uint32_t,
1256 GET_PARSER_DISP_INFO_OUT_SUPPORTED_MATCHES),
1266 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1271 __checkReturn efx_rc_t
1272 ef10_filter_supported_filters(
1273 __in efx_nic_t *enp,
1274 __out_ecount(buffer_length) uint32_t *buffer,
1275 __in size_t buffer_length,
1276 __out size_t *list_lengthp)
1278 efx_nic_cfg_t *encp = &(enp->en_nic_cfg);
1279 size_t mcdi_list_length;
1280 size_t mcdi_encap_list_length;
1283 uint32_t next_buf_idx;
1284 size_t next_buf_length;
1286 boolean_t no_space = B_FALSE;
1287 efx_filter_match_flags_t all_filter_flags =
1288 (EFX_FILTER_MATCH_REM_HOST | EFX_FILTER_MATCH_LOC_HOST |
1289 EFX_FILTER_MATCH_REM_MAC | EFX_FILTER_MATCH_REM_PORT |
1290 EFX_FILTER_MATCH_LOC_MAC | EFX_FILTER_MATCH_LOC_PORT |
1291 EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_INNER_VID |
1292 EFX_FILTER_MATCH_OUTER_VID | EFX_FILTER_MATCH_IP_PROTO |
1293 EFX_FILTER_MATCH_VNI_OR_VSID |
1294 EFX_FILTER_MATCH_IFRM_LOC_MAC |
1295 EFX_FILTER_MATCH_IFRM_UNKNOWN_MCAST_DST |
1296 EFX_FILTER_MATCH_IFRM_UNKNOWN_UCAST_DST |
1297 EFX_FILTER_MATCH_ENCAP_TYPE |
1298 EFX_FILTER_MATCH_UNKNOWN_MCAST_DST |
1299 EFX_FILTER_MATCH_UNKNOWN_UCAST_DST);
1302 * Two calls to MC_CMD_GET_PARSER_DISP_INFO are needed: one to get the
1303 * list of supported filters for ordinary packets, and then another to
1304 * get the list of supported filters for encapsulated packets. To
1305 * distinguish the second list from the first, the
1306 * EFX_FILTER_MATCH_ENCAP_TYPE flag is added to each filter for
1307 * encapsulated packets.
1309 rc = efx_mcdi_get_parser_disp_info(enp, buffer, buffer_length, B_FALSE,
1320 next_buf_length = 0;
1322 EFSYS_ASSERT(mcdi_list_length <= buffer_length);
1323 next_buf_idx = mcdi_list_length;
1324 next_buf_length = buffer_length - mcdi_list_length;
1327 if (encp->enc_tunnel_encapsulations_supported != 0) {
1328 rc = efx_mcdi_get_parser_disp_info(enp, &buffer[next_buf_idx],
1329 next_buf_length, B_TRUE, &mcdi_encap_list_length);
1336 for (i = next_buf_idx;
1337 i < next_buf_idx + mcdi_encap_list_length; i++)
1338 buffer[i] |= EFX_FILTER_MATCH_ENCAP_TYPE;
1341 mcdi_encap_list_length = 0;
1345 *list_lengthp = mcdi_list_length + mcdi_encap_list_length;
1351 * The static assertions in ef10_filter_init() ensure that the values of
1352 * the EFX_FILTER_MATCH flags match those used by MCDI, so they don't
1353 * need to be converted.
1355 * In case support is added to MCDI for additional flags, remove any
1356 * matches from the list which include flags we don't support. The order
1357 * of the matches is preserved as they are ordered from highest to
1360 EFSYS_ASSERT(mcdi_list_length + mcdi_encap_list_length <=
1363 for (i = 0; i < mcdi_list_length + mcdi_encap_list_length; i++) {
1364 if ((buffer[i] & ~all_filter_flags) == 0) {
1365 buffer[list_length] = buffer[i];
1370 *list_lengthp = list_length;
1379 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1384 static __checkReturn efx_rc_t
1385 ef10_filter_insert_unicast(
1386 __in efx_nic_t *enp,
1387 __in_ecount(6) uint8_t const *addr,
1388 __in efx_filter_flags_t filter_flags)
1390 ef10_filter_table_t *eftp = enp->en_filter.ef_ef10_filter_table;
1391 efx_filter_spec_t spec;
1394 /* Insert the filter for the local station address */
1395 efx_filter_spec_init_rx(&spec, EFX_FILTER_PRI_AUTO,
1397 eftp->eft_default_rxq);
1398 rc = efx_filter_spec_set_eth_local(&spec, EFX_FILTER_SPEC_VID_UNSPEC,
1403 rc = ef10_filter_add_internal(enp, &spec, EFX_FILTER_REPLACEMENT_NEVER,
1404 &eftp->eft_unicst_filter_indexes[eftp->eft_unicst_filter_count]);
1408 eftp->eft_unicst_filter_count++;
1409 EFSYS_ASSERT(eftp->eft_unicst_filter_count <=
1410 EFX_EF10_FILTER_UNICAST_FILTERS_MAX);
1417 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1421 static __checkReturn efx_rc_t
1422 ef10_filter_insert_all_unicast(
1423 __in efx_nic_t *enp,
1424 __in efx_filter_flags_t filter_flags)
1426 ef10_filter_table_t *eftp = enp->en_filter.ef_ef10_filter_table;
1427 efx_filter_spec_t spec;
1430 /* Insert the unknown unicast filter */
1431 efx_filter_spec_init_rx(&spec, EFX_FILTER_PRI_AUTO,
1433 eftp->eft_default_rxq);
1434 rc = efx_filter_spec_set_uc_def(&spec);
1437 rc = ef10_filter_add_internal(enp, &spec, EFX_FILTER_REPLACEMENT_NEVER,
1438 &eftp->eft_unicst_filter_indexes[eftp->eft_unicst_filter_count]);
1442 eftp->eft_unicst_filter_count++;
1443 EFSYS_ASSERT(eftp->eft_unicst_filter_count <=
1444 EFX_EF10_FILTER_UNICAST_FILTERS_MAX);
1451 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1455 static __checkReturn efx_rc_t
1456 ef10_filter_insert_multicast_list(
1457 __in efx_nic_t *enp,
1458 __in boolean_t mulcst,
1459 __in boolean_t brdcst,
1460 __in_ecount(6*count) uint8_t const *addrs,
1461 __in uint32_t count,
1462 __in efx_filter_flags_t filter_flags,
1463 __in boolean_t rollback)
1465 ef10_filter_table_t *eftp = enp->en_filter.ef_ef10_filter_table;
1466 efx_filter_spec_t spec;
1469 uint32_t filter_index;
1470 uint32_t filter_count;
1473 if (mulcst == B_FALSE)
1476 if (count + (brdcst ? 1 : 0) >
1477 EFX_ARRAY_SIZE(eftp->eft_mulcst_filter_indexes)) {
1478 /* Too many MAC addresses */
1483 /* Insert/renew multicast address list filters */
1485 for (i = 0; i < count; i++) {
1486 efx_filter_spec_init_rx(&spec,
1487 EFX_FILTER_PRI_AUTO,
1489 eftp->eft_default_rxq);
1491 rc = efx_filter_spec_set_eth_local(&spec,
1492 EFX_FILTER_SPEC_VID_UNSPEC,
1493 &addrs[i * EFX_MAC_ADDR_LEN]);
1495 if (rollback == B_TRUE) {
1496 /* Only stop upon failure if told to rollback */
1500 * Don't try to add a filter with a corrupt
1507 rc = ef10_filter_add_internal(enp, &spec,
1508 EFX_FILTER_REPLACEMENT_NEVER, &filter_index);
1511 eftp->eft_mulcst_filter_indexes[filter_count] =
1514 } else if (rollback == B_TRUE) {
1515 /* Only stop upon failure if told to rollback */
1521 if (brdcst == B_TRUE) {
1522 /* Insert/renew broadcast address filter */
1523 efx_filter_spec_init_rx(&spec, EFX_FILTER_PRI_AUTO,
1525 eftp->eft_default_rxq);
1527 EFX_MAC_BROADCAST_ADDR_SET(addr);
1528 rc = efx_filter_spec_set_eth_local(&spec,
1529 EFX_FILTER_SPEC_VID_UNSPEC, addr);
1530 if ((rc != 0) && (rollback == B_TRUE)) {
1531 /* Only stop upon failure if told to rollback */
1535 rc = ef10_filter_add_internal(enp, &spec,
1536 EFX_FILTER_REPLACEMENT_NEVER, &filter_index);
1539 eftp->eft_mulcst_filter_indexes[filter_count] =
1542 } else if (rollback == B_TRUE) {
1543 /* Only stop upon failure if told to rollback */
1548 eftp->eft_mulcst_filter_count = filter_count;
1549 eftp->eft_using_all_mulcst = B_FALSE;
1554 /* Remove any filters we have inserted */
1557 ef10_filter_delete_auto(enp,
1558 eftp->eft_mulcst_filter_indexes[i]);
1560 eftp->eft_mulcst_filter_count = 0;
1563 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1568 static __checkReturn efx_rc_t
1569 ef10_filter_insert_all_multicast(
1570 __in efx_nic_t *enp,
1571 __in efx_filter_flags_t filter_flags)
1573 ef10_filter_table_t *eftp = enp->en_filter.ef_ef10_filter_table;
1574 efx_filter_spec_t spec;
1577 /* Insert the unknown multicast filter */
1578 efx_filter_spec_init_rx(&spec, EFX_FILTER_PRI_AUTO,
1580 eftp->eft_default_rxq);
1581 rc = efx_filter_spec_set_mc_def(&spec);
1585 rc = ef10_filter_add_internal(enp, &spec, EFX_FILTER_REPLACEMENT_NEVER,
1586 &eftp->eft_mulcst_filter_indexes[0]);
1590 eftp->eft_mulcst_filter_count = 1;
1591 eftp->eft_using_all_mulcst = B_TRUE;
1594 * FIXME: If brdcst == B_FALSE, add a filter to drop broadcast traffic.
1602 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1607 typedef struct ef10_filter_encap_entry_s {
1608 uint16_t ether_type;
1609 efx_tunnel_protocol_t encap_type;
1610 uint32_t inner_frame_match;
1611 } ef10_filter_encap_entry_t;
1613 #define EF10_ENCAP_FILTER_ENTRY(ipv, encap_type, inner_frame_match) \
1614 { EFX_ETHER_TYPE_##ipv, EFX_TUNNEL_PROTOCOL_##encap_type, \
1615 EFX_FILTER_INNER_FRAME_MATCH_UNKNOWN_##inner_frame_match }
1617 static ef10_filter_encap_entry_t ef10_filter_encap_list[] = {
1618 EF10_ENCAP_FILTER_ENTRY(IPV4, VXLAN, UCAST_DST),
1619 EF10_ENCAP_FILTER_ENTRY(IPV4, VXLAN, MCAST_DST),
1620 EF10_ENCAP_FILTER_ENTRY(IPV6, VXLAN, UCAST_DST),
1621 EF10_ENCAP_FILTER_ENTRY(IPV6, VXLAN, MCAST_DST),
1623 EF10_ENCAP_FILTER_ENTRY(IPV4, GENEVE, UCAST_DST),
1624 EF10_ENCAP_FILTER_ENTRY(IPV4, GENEVE, MCAST_DST),
1625 EF10_ENCAP_FILTER_ENTRY(IPV6, GENEVE, UCAST_DST),
1626 EF10_ENCAP_FILTER_ENTRY(IPV6, GENEVE, MCAST_DST),
1628 EF10_ENCAP_FILTER_ENTRY(IPV4, NVGRE, UCAST_DST),
1629 EF10_ENCAP_FILTER_ENTRY(IPV4, NVGRE, MCAST_DST),
1630 EF10_ENCAP_FILTER_ENTRY(IPV6, NVGRE, UCAST_DST),
1631 EF10_ENCAP_FILTER_ENTRY(IPV6, NVGRE, MCAST_DST),
1634 #undef EF10_ENCAP_FILTER_ENTRY
1636 static __checkReturn efx_rc_t
1637 ef10_filter_insert_encap_filters(
1638 __in efx_nic_t *enp,
1639 __in boolean_t mulcst,
1640 __in efx_filter_flags_t filter_flags)
1642 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
1646 EFX_STATIC_ASSERT(EFX_ARRAY_SIZE(ef10_filter_encap_list) <=
1647 EFX_ARRAY_SIZE(table->eft_encap_filter_indexes));
1650 * On Medford, full-featured firmware can identify packets as being
1651 * tunnel encapsulated, even if no encapsulated packet offloads are in
1652 * use. When packets are identified as such, ordinary filters are not
1653 * applied, only ones specific to encapsulated packets. Hence we need to
1654 * insert filters for encapsulated packets in order to receive them.
1656 * Separate filters need to be inserted for each ether type,
1657 * encapsulation type, and inner frame type (unicast or multicast). To
1658 * keep things simple and reduce the number of filters needed, catch-all
1659 * filters for all combinations of types are inserted, even if
1660 * all_unicst or all_mulcst have not been set. (These catch-all filters
1661 * may well, however, fail to insert on unprivileged functions.)
1663 table->eft_encap_filter_count = 0;
1664 for (i = 0; i < EFX_ARRAY_SIZE(ef10_filter_encap_list); i++) {
1665 efx_filter_spec_t spec;
1666 ef10_filter_encap_entry_t *encap_filter =
1667 &ef10_filter_encap_list[i];
1670 * Skip multicast filters if we've not been asked for
1671 * any multicast traffic.
1673 if ((mulcst == B_FALSE) &&
1674 (encap_filter->inner_frame_match ==
1675 EFX_FILTER_INNER_FRAME_MATCH_UNKNOWN_MCAST_DST))
1678 efx_filter_spec_init_rx(&spec, EFX_FILTER_PRI_AUTO,
1680 table->eft_default_rxq);
1681 efx_filter_spec_set_ether_type(&spec, encap_filter->ether_type);
1682 rc = efx_filter_spec_set_encap_type(&spec,
1683 encap_filter->encap_type,
1684 encap_filter->inner_frame_match);
1688 rc = ef10_filter_add_internal(enp, &spec,
1689 EFX_FILTER_REPLACEMENT_NEVER,
1690 &table->eft_encap_filter_indexes[
1691 table->eft_encap_filter_count]);
1696 table->eft_encap_filter_count++;
1705 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1711 ef10_filter_remove_old(
1712 __in efx_nic_t *enp)
1714 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
1717 for (i = 0; i < EFX_ARRAY_SIZE(table->eft_entry); i++) {
1718 if (ef10_filter_entry_is_auto_old(table, i)) {
1719 ef10_filter_delete_auto(enp, i);
1725 static __checkReturn efx_rc_t
1726 ef10_filter_get_workarounds(
1727 __in efx_nic_t *enp)
1729 efx_nic_cfg_t *encp = &enp->en_nic_cfg;
1730 uint32_t implemented = 0;
1731 uint32_t enabled = 0;
1734 rc = efx_mcdi_get_workarounds(enp, &implemented, &enabled);
1736 /* Check if chained multicast filter support is enabled */
1737 if (implemented & enabled & MC_CMD_GET_WORKAROUNDS_OUT_BUG26807)
1738 encp->enc_bug26807_workaround = B_TRUE;
1740 encp->enc_bug26807_workaround = B_FALSE;
1741 } else if (rc == ENOTSUP) {
1743 * Firmware is too old to support GET_WORKAROUNDS, and support
1744 * for this workaround was implemented later.
1746 encp->enc_bug26807_workaround = B_FALSE;
1754 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1761 ef10_filter_remove_all_existing_filters(
1762 __in efx_nic_t *enp)
1764 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
1765 efx_port_t *epp = &(enp->en_port);
1768 for (i = 0; i < table->eft_unicst_filter_count; i++) {
1769 ef10_filter_delete_auto(enp,
1770 table->eft_unicst_filter_indexes[i]);
1772 table->eft_unicst_filter_count = 0;
1774 for (i = 0; i < table->eft_mulcst_filter_count; i++) {
1775 ef10_filter_delete_auto(enp,
1776 table->eft_mulcst_filter_indexes[i]);
1778 table->eft_mulcst_filter_count = 0;
1780 for (i = 0; i < table->eft_encap_filter_count; i++) {
1781 ef10_filter_delete_auto(enp,
1782 table->eft_encap_filter_indexes[i]);
1784 table->eft_encap_filter_count = 0;
1786 epp->ep_all_unicst_inserted = B_FALSE;
1787 epp->ep_all_mulcst_inserted = B_FALSE;
1791 ef10_filter_mark_old_filters(
1792 __in efx_nic_t *enp)
1794 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
1797 for (i = 0; i < table->eft_unicst_filter_count; i++) {
1798 ef10_filter_set_entry_auto_old(table,
1799 table->eft_unicst_filter_indexes[i]);
1801 for (i = 0; i < table->eft_mulcst_filter_count; i++) {
1802 ef10_filter_set_entry_auto_old(table,
1803 table->eft_mulcst_filter_indexes[i]);
1805 for (i = 0; i < table->eft_encap_filter_count; i++) {
1806 ef10_filter_set_entry_auto_old(table,
1807 table->eft_encap_filter_indexes[i]);
1811 static __checkReturn efx_rc_t
1812 ef10_filter_insert_renew_unicst_filters(
1813 __in efx_nic_t *enp,
1814 __in_ecount(6) uint8_t const *mac_addr,
1815 __in boolean_t all_unicst,
1816 __in efx_filter_flags_t filter_flags,
1817 __out boolean_t *all_unicst_inserted)
1819 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
1820 efx_port_t *epp = &(enp->en_port);
1824 * Firmware does not perform chaining on unicast filters. As traffic is
1825 * therefore only delivered to the first matching filter, we should
1826 * always insert the specific filter for our MAC address, to try and
1827 * ensure we get that traffic.
1829 * (If the filter for our MAC address has already been inserted by
1830 * another function, we won't receive traffic sent to us, even if we
1831 * insert a unicast mismatch filter. To prevent traffic stealing, this
1832 * therefore relies on the privilege model only allowing functions to
1833 * insert filters for their own MAC address unless explicitly given
1834 * additional privileges by the user. This also means that, even on a
1835 * privileged function, inserting a unicast mismatch filter may not
1836 * catch all traffic in multi PCI function scenarios.)
1838 table->eft_unicst_filter_count = 0;
1839 rc = ef10_filter_insert_unicast(enp, mac_addr, filter_flags);
1840 *all_unicst_inserted = B_FALSE;
1841 if (all_unicst || (rc != 0)) {
1842 efx_rc_t all_unicst_rc;
1844 all_unicst_rc = ef10_filter_insert_all_unicast(enp,
1846 if (all_unicst_rc == 0) {
1847 *all_unicst_inserted = B_TRUE;
1848 epp->ep_all_unicst_inserted = B_TRUE;
1856 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1861 static __checkReturn efx_rc_t
1862 ef10_filter_insert_renew_mulcst_filters(
1863 __in efx_nic_t *enp,
1864 __in boolean_t mulcst,
1865 __in boolean_t all_mulcst,
1866 __in boolean_t brdcst,
1867 __in_ecount(6*count) uint8_t const *addrs,
1868 __in uint32_t count,
1869 __in efx_filter_flags_t filter_flags,
1870 __in boolean_t all_unicst_inserted,
1871 __out boolean_t *all_mulcst_inserted)
1873 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
1874 efx_nic_cfg_t *encp = &enp->en_nic_cfg;
1875 efx_port_t *epp = &(enp->en_port);
1878 *all_mulcst_inserted = B_FALSE;
1880 if (all_mulcst == B_TRUE) {
1881 efx_rc_t all_mulcst_rc;
1884 * Insert the all multicast filter. If that fails, try to insert
1885 * all of our multicast filters (but without rollback on
1888 all_mulcst_rc = ef10_filter_insert_all_multicast(enp,
1890 if (all_mulcst_rc == 0) {
1891 epp->ep_all_mulcst_inserted = B_TRUE;
1892 *all_mulcst_inserted = B_TRUE;
1894 rc = ef10_filter_insert_multicast_list(enp, B_TRUE,
1895 brdcst, addrs, count, filter_flags, B_FALSE);
1901 * Insert filters for multicast addresses.
1902 * If any insertion fails, then rollback and try to insert the
1903 * all multicast filter instead.
1904 * If that also fails, try to insert all of the multicast
1905 * filters (but without rollback on failure).
1907 rc = ef10_filter_insert_multicast_list(enp, mulcst, brdcst,
1908 addrs, count, filter_flags, B_TRUE);
1910 if ((table->eft_using_all_mulcst == B_FALSE) &&
1911 (encp->enc_bug26807_workaround == B_TRUE)) {
1913 * Multicast filter chaining is on, so remove
1914 * old filters before inserting the multicast
1915 * all filter to avoid duplicate delivery caused
1916 * by packets matching multiple filters.
1918 ef10_filter_remove_old(enp);
1919 if (all_unicst_inserted == B_FALSE)
1920 epp->ep_all_unicst_inserted = B_FALSE;
1921 if (*all_mulcst_inserted == B_FALSE)
1922 epp->ep_all_mulcst_inserted = B_FALSE;
1925 rc = ef10_filter_insert_all_multicast(enp,
1928 epp->ep_all_mulcst_inserted = B_TRUE;
1929 *all_mulcst_inserted = B_TRUE;
1931 rc = ef10_filter_insert_multicast_list(enp,
1933 addrs, count, filter_flags, B_FALSE);
1943 EFSYS_PROBE1(fail2, efx_rc_t, rc);
1946 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1952 * Reconfigure all filters.
1953 * If all_unicst and/or all mulcst filters cannot be applied then
1954 * return ENOTSUP (Note the filters for the specified addresses are
1955 * still applied in this case).
1957 __checkReturn efx_rc_t
1958 ef10_filter_reconfigure(
1959 __in efx_nic_t *enp,
1960 __in_ecount(6) uint8_t const *mac_addr,
1961 __in boolean_t all_unicst,
1962 __in boolean_t mulcst,
1963 __in boolean_t all_mulcst,
1964 __in boolean_t brdcst,
1965 __in_ecount(6*count) uint8_t const *addrs,
1966 __in uint32_t count)
1968 efx_nic_cfg_t *encp = &enp->en_nic_cfg;
1969 efx_port_t *epp = &(enp->en_port);
1970 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
1971 efx_filter_flags_t filter_flags;
1973 boolean_t all_unicst_inserted = B_FALSE;
1974 boolean_t all_mulcst_inserted = B_FALSE;
1977 if (table->eft_default_rxq == NULL) {
1979 * Filters direct traffic to the default RXQ, and so cannot be
1980 * inserted until it is available. Any currently configured
1981 * filters must be removed (ignore errors in case the MC
1982 * has rebooted, which removes hardware filters).
1984 ef10_filter_remove_all_existing_filters(enp);
1988 if (table->eft_using_rss)
1989 filter_flags = EFX_FILTER_FLAG_RX_RSS;
1993 /* Mark old filters which may need to be removed */
1994 ef10_filter_mark_old_filters(enp);
1996 /* Insert or renew unicast filters */
1997 rc = ef10_filter_insert_renew_unicst_filters(enp, mac_addr, all_unicst,
1999 &all_unicst_inserted);
2004 * WORKAROUND_BUG26807 controls firmware support for chained multicast
2005 * filters, and can only be enabled or disabled when the hardware filter
2008 * Chained multicast filters require support from the datapath firmware,
2009 * and may not be available (e.g. low-latency variants or old Huntington
2012 * Firmware will reset (FLR) functions which have inserted filters in
2013 * the hardware filter table when the workaround is enabled/disabled.
2014 * Functions without any hardware filters are not reset.
2016 * Re-check if the workaround is enabled after adding unicast hardware
2017 * filters. This ensures that encp->enc_bug26807_workaround matches the
2018 * firmware state, and that later changes to enable/disable the
2019 * workaround will result in this function seeing a reset (FLR).
2021 * In common-code drivers, we only support multiple PCI function
2022 * scenarios with firmware that supports multicast chaining, so we can
2023 * assume it is enabled for such cases and hence simplify the filter
2024 * insertion logic. Firmware that does not support multicast chaining
2025 * does not support multiple PCI function configurations either, so
2026 * filter insertion is much simpler and the same strategies can still be
2029 if ((rc = ef10_filter_get_workarounds(enp)) != 0)
2032 if ((table->eft_using_all_mulcst != all_mulcst) &&
2033 (encp->enc_bug26807_workaround == B_TRUE)) {
2035 * Multicast filter chaining is enabled, so traffic that matches
2036 * more than one multicast filter will be replicated and
2037 * delivered to multiple recipients. To avoid this duplicate
2038 * delivery, remove old multicast filters before inserting new
2039 * multicast filters.
2041 ef10_filter_remove_old(enp);
2042 if (all_unicst_inserted == B_FALSE)
2043 epp->ep_all_unicst_inserted = B_FALSE;
2045 epp->ep_all_mulcst_inserted = B_FALSE;
2048 /* Insert or renew multicast filters */
2049 rc = ef10_filter_insert_renew_mulcst_filters(enp, mulcst, all_mulcst,
2050 brdcst, addrs, count,
2052 all_unicst_inserted,
2053 &all_mulcst_inserted);
2057 if (encp->enc_tunnel_encapsulations_supported != 0) {
2058 /* Try to insert filters for encapsulated packets. */
2059 (void) ef10_filter_insert_encap_filters(enp,
2060 mulcst || all_mulcst || brdcst,
2064 /* Remove old filters which were not renewed */
2065 ef10_filter_remove_old(enp);
2066 if (all_unicst_inserted == B_FALSE)
2067 epp->ep_all_unicst_inserted = B_FALSE;
2068 if (all_mulcst_inserted == B_FALSE)
2069 epp->ep_all_mulcst_inserted = B_FALSE;
2071 /* report if any optional flags were rejected */
2072 if (((all_unicst != B_FALSE) && (all_unicst_inserted == B_FALSE)) ||
2073 ((all_mulcst != B_FALSE) && (all_mulcst_inserted == B_FALSE))) {
2084 EFSYS_PROBE1(fail1, efx_rc_t, rc);
2086 /* Clear auto old flags */
2087 for (i = 0; i < EFX_ARRAY_SIZE(table->eft_entry); i++) {
2088 if (ef10_filter_entry_is_auto_old(table, i)) {
2089 ef10_filter_set_entry_not_auto_old(table, i);
2097 ef10_filter_get_default_rxq(
2098 __in efx_nic_t *enp,
2099 __out efx_rxq_t **erpp,
2100 __out boolean_t *using_rss)
2102 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
2104 *erpp = table->eft_default_rxq;
2105 *using_rss = table->eft_using_rss;
2110 ef10_filter_default_rxq_set(
2111 __in efx_nic_t *enp,
2112 __in efx_rxq_t *erp,
2113 __in boolean_t using_rss)
2115 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
2117 #if EFSYS_OPT_RX_SCALE
2118 EFSYS_ASSERT((using_rss == B_FALSE) ||
2119 (enp->en_rss_context != EF10_RSS_CONTEXT_INVALID));
2120 table->eft_using_rss = using_rss;
2122 EFSYS_ASSERT(using_rss == B_FALSE);
2123 table->eft_using_rss = B_FALSE;
2125 table->eft_default_rxq = erp;
2129 ef10_filter_default_rxq_clear(
2130 __in efx_nic_t *enp)
2132 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
2134 table->eft_default_rxq = NULL;
2135 table->eft_using_rss = B_FALSE;
2139 #endif /* EFSYS_OPT_FILTER */
2141 #endif /* EFSYS_OPT_RIVERHEAD || EFX_OPTS_EF10() */