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.
34 #if EFSYS_OPT_HUNTINGTON || EFSYS_OPT_MEDFORD
38 #define EFE_SPEC(eftp, index) ((eftp)->eft_entry[(index)].efe_spec)
40 static efx_filter_spec_t *
41 ef10_filter_entry_spec(
42 __in const ef10_filter_table_t *eftp,
43 __in unsigned int index)
45 return ((efx_filter_spec_t *)(EFE_SPEC(eftp, index) &
46 ~(uintptr_t)EFX_EF10_FILTER_FLAGS));
50 ef10_filter_entry_is_busy(
51 __in const ef10_filter_table_t *eftp,
52 __in unsigned int index)
54 if (EFE_SPEC(eftp, index) & EFX_EF10_FILTER_FLAG_BUSY)
61 ef10_filter_entry_is_auto_old(
62 __in const ef10_filter_table_t *eftp,
63 __in unsigned int index)
65 if (EFE_SPEC(eftp, index) & EFX_EF10_FILTER_FLAG_AUTO_OLD)
72 ef10_filter_set_entry(
73 __inout ef10_filter_table_t *eftp,
74 __in unsigned int index,
75 __in_opt const efx_filter_spec_t *efsp)
77 EFE_SPEC(eftp, index) = (uintptr_t)efsp;
81 ef10_filter_set_entry_busy(
82 __inout ef10_filter_table_t *eftp,
83 __in unsigned int index)
85 EFE_SPEC(eftp, index) |= (uintptr_t)EFX_EF10_FILTER_FLAG_BUSY;
89 ef10_filter_set_entry_not_busy(
90 __inout ef10_filter_table_t *eftp,
91 __in unsigned int index)
93 EFE_SPEC(eftp, index) &= ~(uintptr_t)EFX_EF10_FILTER_FLAG_BUSY;
97 ef10_filter_set_entry_auto_old(
98 __inout ef10_filter_table_t *eftp,
99 __in unsigned int index)
101 EFSYS_ASSERT(ef10_filter_entry_spec(eftp, index) != NULL);
102 EFE_SPEC(eftp, index) |= (uintptr_t)EFX_EF10_FILTER_FLAG_AUTO_OLD;
106 ef10_filter_set_entry_not_auto_old(
107 __inout ef10_filter_table_t *eftp,
108 __in unsigned int index)
110 EFE_SPEC(eftp, index) &= ~(uintptr_t)EFX_EF10_FILTER_FLAG_AUTO_OLD;
111 EFSYS_ASSERT(ef10_filter_entry_spec(eftp, index) != NULL);
114 __checkReturn efx_rc_t
119 ef10_filter_table_t *eftp;
121 EFSYS_ASSERT(enp->en_family == EFX_FAMILY_HUNTINGTON ||
122 enp->en_family == EFX_FAMILY_MEDFORD);
124 #define MATCH_MASK(match) (EFX_MASK32(match) << EFX_LOW_BIT(match))
125 EFX_STATIC_ASSERT(EFX_FILTER_MATCH_REM_HOST ==
126 MATCH_MASK(MC_CMD_FILTER_OP_IN_MATCH_SRC_IP));
127 EFX_STATIC_ASSERT(EFX_FILTER_MATCH_LOC_HOST ==
128 MATCH_MASK(MC_CMD_FILTER_OP_IN_MATCH_DST_IP));
129 EFX_STATIC_ASSERT(EFX_FILTER_MATCH_REM_MAC ==
130 MATCH_MASK(MC_CMD_FILTER_OP_IN_MATCH_SRC_MAC));
131 EFX_STATIC_ASSERT(EFX_FILTER_MATCH_REM_PORT ==
132 MATCH_MASK(MC_CMD_FILTER_OP_IN_MATCH_SRC_PORT));
133 EFX_STATIC_ASSERT(EFX_FILTER_MATCH_LOC_MAC ==
134 MATCH_MASK(MC_CMD_FILTER_OP_IN_MATCH_DST_MAC));
135 EFX_STATIC_ASSERT(EFX_FILTER_MATCH_LOC_PORT ==
136 MATCH_MASK(MC_CMD_FILTER_OP_IN_MATCH_DST_PORT));
137 EFX_STATIC_ASSERT(EFX_FILTER_MATCH_ETHER_TYPE ==
138 MATCH_MASK(MC_CMD_FILTER_OP_IN_MATCH_ETHER_TYPE));
139 EFX_STATIC_ASSERT(EFX_FILTER_MATCH_INNER_VID ==
140 MATCH_MASK(MC_CMD_FILTER_OP_IN_MATCH_INNER_VLAN));
141 EFX_STATIC_ASSERT(EFX_FILTER_MATCH_OUTER_VID ==
142 MATCH_MASK(MC_CMD_FILTER_OP_IN_MATCH_OUTER_VLAN));
143 EFX_STATIC_ASSERT(EFX_FILTER_MATCH_IP_PROTO ==
144 MATCH_MASK(MC_CMD_FILTER_OP_IN_MATCH_IP_PROTO));
147 EFSYS_KMEM_ALLOC(enp->en_esip, sizeof (ef10_filter_table_t), eftp);
154 enp->en_filter.ef_ef10_filter_table = eftp;
159 EFSYS_PROBE1(fail1, efx_rc_t, rc);
168 EFSYS_ASSERT(enp->en_family == EFX_FAMILY_HUNTINGTON ||
169 enp->en_family == EFX_FAMILY_MEDFORD);
171 if (enp->en_filter.ef_ef10_filter_table != NULL) {
172 EFSYS_KMEM_FREE(enp->en_esip, sizeof (ef10_filter_table_t),
173 enp->en_filter.ef_ef10_filter_table);
177 static __checkReturn efx_rc_t
178 efx_mcdi_filter_op_add(
180 __in efx_filter_spec_t *spec,
181 __in unsigned int filter_op,
182 __inout ef10_filter_handle_t *handle)
185 uint8_t payload[MAX(MC_CMD_FILTER_OP_IN_LEN,
186 MC_CMD_FILTER_OP_OUT_LEN)];
187 uint32_t match_fields = 0;
190 memset(payload, 0, sizeof (payload));
191 req.emr_cmd = MC_CMD_FILTER_OP;
192 req.emr_in_buf = payload;
193 req.emr_in_length = MC_CMD_FILTER_OP_IN_LEN;
194 req.emr_out_buf = payload;
195 req.emr_out_length = MC_CMD_FILTER_OP_OUT_LEN;
198 case MC_CMD_FILTER_OP_IN_OP_REPLACE:
199 MCDI_IN_SET_DWORD(req, FILTER_OP_IN_HANDLE_LO,
201 MCDI_IN_SET_DWORD(req, FILTER_OP_IN_HANDLE_HI,
204 case MC_CMD_FILTER_OP_IN_OP_INSERT:
205 case MC_CMD_FILTER_OP_IN_OP_SUBSCRIBE:
206 MCDI_IN_SET_DWORD(req, FILTER_OP_IN_OP, filter_op);
214 if (spec->efs_match_flags & EFX_FILTER_MATCH_LOC_MAC_IG) {
216 * The LOC_MAC_IG match flag can represent unknown unicast
217 * or multicast filters - use the MAC address to distinguish
220 if (EFX_MAC_ADDR_IS_MULTICAST(spec->efs_loc_mac))
221 match_fields |= 1U <<
222 MC_CMD_FILTER_OP_IN_MATCH_UNKNOWN_MCAST_DST_LBN;
224 match_fields |= 1U <<
225 MC_CMD_FILTER_OP_IN_MATCH_UNKNOWN_UCAST_DST_LBN;
228 match_fields |= spec->efs_match_flags & (~EFX_FILTER_MATCH_LOC_MAC_IG);
230 MCDI_IN_SET_DWORD(req, FILTER_OP_IN_PORT_ID,
231 EVB_PORT_ID_ASSIGNED);
232 MCDI_IN_SET_DWORD(req, FILTER_OP_IN_MATCH_FIELDS,
234 MCDI_IN_SET_DWORD(req, FILTER_OP_IN_RX_DEST,
235 MC_CMD_FILTER_OP_IN_RX_DEST_HOST);
236 MCDI_IN_SET_DWORD(req, FILTER_OP_IN_RX_QUEUE,
238 if (spec->efs_flags & EFX_FILTER_FLAG_RX_RSS) {
239 MCDI_IN_SET_DWORD(req, FILTER_OP_IN_RX_CONTEXT,
240 spec->efs_rss_context);
242 MCDI_IN_SET_DWORD(req, FILTER_OP_IN_RX_MODE,
243 spec->efs_flags & EFX_FILTER_FLAG_RX_RSS ?
244 MC_CMD_FILTER_OP_IN_RX_MODE_RSS :
245 MC_CMD_FILTER_OP_IN_RX_MODE_SIMPLE);
246 MCDI_IN_SET_DWORD(req, FILTER_OP_IN_TX_DEST,
247 MC_CMD_FILTER_OP_IN_TX_DEST_DEFAULT);
249 if (filter_op != MC_CMD_FILTER_OP_IN_OP_REPLACE) {
251 * NOTE: Unlike most MCDI requests, the filter fields
252 * are presented in network (big endian) byte order.
254 memcpy(MCDI_IN2(req, uint8_t, FILTER_OP_IN_SRC_MAC),
255 spec->efs_rem_mac, EFX_MAC_ADDR_LEN);
256 memcpy(MCDI_IN2(req, uint8_t, FILTER_OP_IN_DST_MAC),
257 spec->efs_loc_mac, EFX_MAC_ADDR_LEN);
259 MCDI_IN_SET_WORD(req, FILTER_OP_IN_SRC_PORT,
260 __CPU_TO_BE_16(spec->efs_rem_port));
261 MCDI_IN_SET_WORD(req, FILTER_OP_IN_DST_PORT,
262 __CPU_TO_BE_16(spec->efs_loc_port));
264 MCDI_IN_SET_WORD(req, FILTER_OP_IN_ETHER_TYPE,
265 __CPU_TO_BE_16(spec->efs_ether_type));
267 MCDI_IN_SET_WORD(req, FILTER_OP_IN_INNER_VLAN,
268 __CPU_TO_BE_16(spec->efs_inner_vid));
269 MCDI_IN_SET_WORD(req, FILTER_OP_IN_OUTER_VLAN,
270 __CPU_TO_BE_16(spec->efs_outer_vid));
272 /* IP protocol (in low byte, high byte is zero) */
273 MCDI_IN_SET_BYTE(req, FILTER_OP_IN_IP_PROTO,
276 EFX_STATIC_ASSERT(sizeof (spec->efs_rem_host) ==
277 MC_CMD_FILTER_OP_IN_SRC_IP_LEN);
278 EFX_STATIC_ASSERT(sizeof (spec->efs_loc_host) ==
279 MC_CMD_FILTER_OP_IN_DST_IP_LEN);
281 memcpy(MCDI_IN2(req, uint8_t, FILTER_OP_IN_SRC_IP),
282 &spec->efs_rem_host.eo_byte[0],
283 MC_CMD_FILTER_OP_IN_SRC_IP_LEN);
284 memcpy(MCDI_IN2(req, uint8_t, FILTER_OP_IN_DST_IP),
285 &spec->efs_loc_host.eo_byte[0],
286 MC_CMD_FILTER_OP_IN_DST_IP_LEN);
289 efx_mcdi_execute(enp, &req);
291 if (req.emr_rc != 0) {
296 if (req.emr_out_length_used < MC_CMD_FILTER_OP_OUT_LEN) {
301 handle->efh_lo = MCDI_OUT_DWORD(req, FILTER_OP_OUT_HANDLE_LO);
302 handle->efh_hi = MCDI_OUT_DWORD(req, FILTER_OP_OUT_HANDLE_HI);
311 EFSYS_PROBE1(fail1, efx_rc_t, rc);
317 static __checkReturn efx_rc_t
318 efx_mcdi_filter_op_delete(
320 __in unsigned int filter_op,
321 __inout ef10_filter_handle_t *handle)
324 uint8_t payload[MAX(MC_CMD_FILTER_OP_IN_LEN,
325 MC_CMD_FILTER_OP_OUT_LEN)];
328 memset(payload, 0, sizeof (payload));
329 req.emr_cmd = MC_CMD_FILTER_OP;
330 req.emr_in_buf = payload;
331 req.emr_in_length = MC_CMD_FILTER_OP_IN_LEN;
332 req.emr_out_buf = payload;
333 req.emr_out_length = MC_CMD_FILTER_OP_OUT_LEN;
336 case MC_CMD_FILTER_OP_IN_OP_REMOVE:
337 MCDI_IN_SET_DWORD(req, FILTER_OP_IN_OP,
338 MC_CMD_FILTER_OP_IN_OP_REMOVE);
340 case MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE:
341 MCDI_IN_SET_DWORD(req, FILTER_OP_IN_OP,
342 MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE);
350 MCDI_IN_SET_DWORD(req, FILTER_OP_IN_HANDLE_LO, handle->efh_lo);
351 MCDI_IN_SET_DWORD(req, FILTER_OP_IN_HANDLE_HI, handle->efh_hi);
353 efx_mcdi_execute_quiet(enp, &req);
355 if (req.emr_rc != 0) {
360 if (req.emr_out_length_used < MC_CMD_FILTER_OP_OUT_LEN) {
373 EFSYS_PROBE1(fail1, efx_rc_t, rc);
378 static __checkReturn boolean_t
380 __in const efx_filter_spec_t *left,
381 __in const efx_filter_spec_t *right)
383 /* FIXME: Consider rx vs tx filters (look at efs_flags) */
384 if (left->efs_match_flags != right->efs_match_flags)
386 if (!EFX_OWORD_IS_EQUAL(left->efs_rem_host, right->efs_rem_host))
388 if (!EFX_OWORD_IS_EQUAL(left->efs_loc_host, right->efs_loc_host))
390 if (memcmp(left->efs_rem_mac, right->efs_rem_mac, EFX_MAC_ADDR_LEN))
392 if (memcmp(left->efs_loc_mac, right->efs_loc_mac, EFX_MAC_ADDR_LEN))
394 if (left->efs_rem_port != right->efs_rem_port)
396 if (left->efs_loc_port != right->efs_loc_port)
398 if (left->efs_inner_vid != right->efs_inner_vid)
400 if (left->efs_outer_vid != right->efs_outer_vid)
402 if (left->efs_ether_type != right->efs_ether_type)
404 if (left->efs_ip_proto != right->efs_ip_proto)
411 static __checkReturn boolean_t
412 ef10_filter_same_dest(
413 __in const efx_filter_spec_t *left,
414 __in const efx_filter_spec_t *right)
416 if ((left->efs_flags & EFX_FILTER_FLAG_RX_RSS) &&
417 (right->efs_flags & EFX_FILTER_FLAG_RX_RSS)) {
418 if (left->efs_rss_context == right->efs_rss_context)
420 } else if ((~(left->efs_flags) & EFX_FILTER_FLAG_RX_RSS) &&
421 (~(right->efs_flags) & EFX_FILTER_FLAG_RX_RSS)) {
422 if (left->efs_dmaq_id == right->efs_dmaq_id)
428 static __checkReturn uint32_t
430 __in efx_filter_spec_t *spec)
432 EFX_STATIC_ASSERT((sizeof (efx_filter_spec_t) % sizeof (uint32_t))
434 EFX_STATIC_ASSERT((EFX_FIELD_OFFSET(efx_filter_spec_t, efs_outer_vid) %
435 sizeof (uint32_t)) == 0);
438 * As the area of the efx_filter_spec_t we need to hash is DWORD
439 * aligned and an exact number of DWORDs in size we can use the
440 * optimised efx_hash_dwords() rather than efx_hash_bytes()
442 return (efx_hash_dwords((const uint32_t *)&spec->efs_outer_vid,
443 (sizeof (efx_filter_spec_t) -
444 EFX_FIELD_OFFSET(efx_filter_spec_t, efs_outer_vid)) /
445 sizeof (uint32_t), 0));
449 * Decide whether a filter should be exclusive or else should allow
450 * delivery to additional recipients. Currently we decide that
451 * filters for specific local unicast MAC and IP addresses are
454 static __checkReturn boolean_t
455 ef10_filter_is_exclusive(
456 __in efx_filter_spec_t *spec)
458 if ((spec->efs_match_flags & EFX_FILTER_MATCH_LOC_MAC) &&
459 !EFX_MAC_ADDR_IS_MULTICAST(spec->efs_loc_mac))
462 if ((spec->efs_match_flags &
463 (EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_LOC_HOST)) ==
464 (EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_LOC_HOST)) {
465 if ((spec->efs_ether_type == EFX_ETHER_TYPE_IPV4) &&
466 ((spec->efs_loc_host.eo_u8[0] & 0xf) != 0xe))
468 if ((spec->efs_ether_type == EFX_ETHER_TYPE_IPV6) &&
469 (spec->efs_loc_host.eo_u8[0] != 0xff))
476 __checkReturn efx_rc_t
481 efx_filter_spec_t *spec;
482 ef10_filter_table_t *eftp = enp->en_filter.ef_ef10_filter_table;
484 efsys_lock_state_t state;
487 EFSYS_ASSERT(enp->en_family == EFX_FAMILY_HUNTINGTON ||
488 enp->en_family == EFX_FAMILY_MEDFORD);
490 for (tbl_id = 0; tbl_id < EFX_EF10_FILTER_TBL_ROWS; tbl_id++) {
492 EFSYS_LOCK(enp->en_eslp, state);
494 spec = ef10_filter_entry_spec(eftp, tbl_id);
497 } else if (ef10_filter_entry_is_busy(eftp, tbl_id)) {
498 /* Ignore busy entries. */
501 ef10_filter_set_entry_busy(eftp, tbl_id);
505 EFSYS_UNLOCK(enp->en_eslp, state);
507 if (restoring == B_FALSE)
510 if (ef10_filter_is_exclusive(spec)) {
511 rc = efx_mcdi_filter_op_add(enp, spec,
512 MC_CMD_FILTER_OP_IN_OP_INSERT,
513 &eftp->eft_entry[tbl_id].efe_handle);
515 rc = efx_mcdi_filter_op_add(enp, spec,
516 MC_CMD_FILTER_OP_IN_OP_SUBSCRIBE,
517 &eftp->eft_entry[tbl_id].efe_handle);
523 EFSYS_LOCK(enp->en_eslp, state);
525 ef10_filter_set_entry_not_busy(eftp, tbl_id);
527 EFSYS_UNLOCK(enp->en_eslp, state);
533 EFSYS_PROBE1(fail1, efx_rc_t, rc);
539 * An arbitrary search limit for the software hash table. As per the linux net
542 #define EF10_FILTER_SEARCH_LIMIT 200
544 static __checkReturn efx_rc_t
545 ef10_filter_add_internal(
547 __inout efx_filter_spec_t *spec,
548 __in boolean_t may_replace,
549 __out_opt uint32_t *filter_id)
552 ef10_filter_table_t *eftp = enp->en_filter.ef_ef10_filter_table;
553 efx_filter_spec_t *saved_spec;
557 boolean_t replacing = B_FALSE;
559 efsys_lock_state_t state;
560 boolean_t locked = B_FALSE;
562 EFSYS_ASSERT(enp->en_family == EFX_FAMILY_HUNTINGTON ||
563 enp->en_family == EFX_FAMILY_MEDFORD);
565 hash = ef10_filter_hash(spec);
568 * FIXME: Add support for inserting filters of different priorities
569 * and removing lower priority multicast filters (bug 42378)
573 * Find any existing filters with the same match tuple or
574 * else a free slot to insert at. If any of them are busy,
575 * we have to wait and retry.
580 EFSYS_LOCK(enp->en_eslp, state);
584 i = (hash + depth) & (EFX_EF10_FILTER_TBL_ROWS - 1);
585 saved_spec = ef10_filter_entry_spec(eftp, i);
591 } else if (ef10_filter_equal(spec, saved_spec)) {
592 if (ef10_filter_entry_is_busy(eftp, i))
594 if (saved_spec->efs_priority
595 == EFX_FILTER_PRI_AUTO) {
598 } else if (ef10_filter_is_exclusive(spec)) {
612 * Once we reach the maximum search depth, use
613 * the first suitable slot or return EBUSY if
616 if (depth == EF10_FILTER_SEARCH_LIMIT) {
625 EFSYS_UNLOCK(enp->en_eslp, state);
631 * Create a software table entry if necessary, and mark it
632 * busy. We might yet fail to insert, but any attempt to
633 * insert a conflicting filter while we're waiting for the
634 * firmware must find the busy entry.
636 saved_spec = ef10_filter_entry_spec(eftp, ins_index);
638 if (saved_spec->efs_priority == EFX_FILTER_PRI_AUTO) {
639 /* This is a filter we are refreshing */
640 ef10_filter_set_entry_not_auto_old(eftp, ins_index);
646 EFSYS_KMEM_ALLOC(enp->en_esip, sizeof (*spec), saved_spec);
652 ef10_filter_set_entry(eftp, ins_index, saved_spec);
654 ef10_filter_set_entry_busy(eftp, ins_index);
656 EFSYS_UNLOCK(enp->en_eslp, state);
660 * On replacing the filter handle may change after after a successful
664 rc = efx_mcdi_filter_op_add(enp, spec,
665 MC_CMD_FILTER_OP_IN_OP_REPLACE,
666 &eftp->eft_entry[ins_index].efe_handle);
667 } else if (ef10_filter_is_exclusive(spec)) {
668 rc = efx_mcdi_filter_op_add(enp, spec,
669 MC_CMD_FILTER_OP_IN_OP_INSERT,
670 &eftp->eft_entry[ins_index].efe_handle);
672 rc = efx_mcdi_filter_op_add(enp, spec,
673 MC_CMD_FILTER_OP_IN_OP_SUBSCRIBE,
674 &eftp->eft_entry[ins_index].efe_handle);
680 EFSYS_LOCK(enp->en_eslp, state);
684 /* Update the fields that may differ */
685 saved_spec->efs_priority = spec->efs_priority;
686 saved_spec->efs_flags = spec->efs_flags;
687 saved_spec->efs_rss_context = spec->efs_rss_context;
688 saved_spec->efs_dmaq_id = spec->efs_dmaq_id;
691 ef10_filter_set_entry_not_busy(eftp, ins_index);
695 EFSYS_UNLOCK(enp->en_eslp, state);
699 *filter_id = ins_index;
707 EFSYS_KMEM_FREE(enp->en_esip, sizeof (*spec), saved_spec);
710 ef10_filter_set_entry_not_busy(eftp, ins_index);
711 ef10_filter_set_entry(eftp, ins_index, NULL);
720 EFSYS_PROBE1(fail1, efx_rc_t, rc);
723 EFSYS_UNLOCK(enp->en_eslp, state);
728 __checkReturn efx_rc_t
731 __inout efx_filter_spec_t *spec,
732 __in boolean_t may_replace)
736 rc = ef10_filter_add_internal(enp, spec, may_replace, NULL);
743 EFSYS_PROBE1(fail1, efx_rc_t, rc);
749 static __checkReturn efx_rc_t
750 ef10_filter_delete_internal(
752 __in uint32_t filter_id)
755 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
756 efx_filter_spec_t *spec;
757 efsys_lock_state_t state;
758 uint32_t filter_idx = filter_id % EFX_EF10_FILTER_TBL_ROWS;
761 * Find the software table entry and mark it busy. Don't
762 * remove it yet; any attempt to update while we're waiting
763 * for the firmware must find the busy entry.
765 * FIXME: What if the busy flag is never cleared?
767 EFSYS_LOCK(enp->en_eslp, state);
768 while (ef10_filter_entry_is_busy(table, filter_idx)) {
769 EFSYS_UNLOCK(enp->en_eslp, state);
771 EFSYS_LOCK(enp->en_eslp, state);
773 if ((spec = ef10_filter_entry_spec(table, filter_idx)) != NULL) {
774 ef10_filter_set_entry_busy(table, filter_idx);
776 EFSYS_UNLOCK(enp->en_eslp, state);
784 * Try to remove the hardware filter. This may fail if the MC has
785 * rebooted (which frees all hardware filter resources).
787 if (ef10_filter_is_exclusive(spec)) {
788 rc = efx_mcdi_filter_op_delete(enp,
789 MC_CMD_FILTER_OP_IN_OP_REMOVE,
790 &table->eft_entry[filter_idx].efe_handle);
792 rc = efx_mcdi_filter_op_delete(enp,
793 MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE,
794 &table->eft_entry[filter_idx].efe_handle);
797 /* Free the software table entry */
798 EFSYS_LOCK(enp->en_eslp, state);
799 ef10_filter_set_entry_not_busy(table, filter_idx);
800 ef10_filter_set_entry(table, filter_idx, NULL);
801 EFSYS_UNLOCK(enp->en_eslp, state);
803 EFSYS_KMEM_FREE(enp->en_esip, sizeof (*spec), spec);
805 /* Check result of hardware filter removal */
815 EFSYS_PROBE1(fail1, efx_rc_t, rc);
820 __checkReturn efx_rc_t
823 __inout efx_filter_spec_t *spec)
826 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
827 efx_filter_spec_t *saved_spec;
831 efsys_lock_state_t state;
832 boolean_t locked = B_FALSE;
834 EFSYS_ASSERT(enp->en_family == EFX_FAMILY_HUNTINGTON ||
835 enp->en_family == EFX_FAMILY_MEDFORD);
837 hash = ef10_filter_hash(spec);
839 EFSYS_LOCK(enp->en_eslp, state);
844 i = (hash + depth) & (EFX_EF10_FILTER_TBL_ROWS - 1);
845 saved_spec = ef10_filter_entry_spec(table, i);
846 if (saved_spec && ef10_filter_equal(spec, saved_spec) &&
847 ef10_filter_same_dest(spec, saved_spec)) {
850 if (depth == EF10_FILTER_SEARCH_LIMIT) {
857 EFSYS_UNLOCK(enp->en_eslp, state);
860 rc = ef10_filter_delete_internal(enp, i);
870 EFSYS_PROBE1(fail1, efx_rc_t, rc);
873 EFSYS_UNLOCK(enp->en_eslp, state);
878 static __checkReturn efx_rc_t
879 efx_mcdi_get_parser_disp_info(
881 __out uint32_t *list,
882 __out size_t *length)
885 uint8_t payload[MAX(MC_CMD_GET_PARSER_DISP_INFO_IN_LEN,
886 MC_CMD_GET_PARSER_DISP_INFO_OUT_LENMAX)];
889 boolean_t support_unknown_ucast = B_FALSE;
890 boolean_t support_unknown_mcast = B_FALSE;
892 (void) memset(payload, 0, sizeof (payload));
893 req.emr_cmd = MC_CMD_GET_PARSER_DISP_INFO;
894 req.emr_in_buf = payload;
895 req.emr_in_length = MC_CMD_GET_PARSER_DISP_INFO_IN_LEN;
896 req.emr_out_buf = payload;
897 req.emr_out_length = MC_CMD_GET_PARSER_DISP_INFO_OUT_LENMAX;
899 MCDI_IN_SET_DWORD(req, GET_PARSER_DISP_INFO_OUT_OP,
900 MC_CMD_GET_PARSER_DISP_INFO_IN_OP_GET_SUPPORTED_RX_MATCHES);
902 efx_mcdi_execute(enp, &req);
904 if (req.emr_rc != 0) {
909 *length = MCDI_OUT_DWORD(req,
910 GET_PARSER_DISP_INFO_OUT_NUM_SUPPORTED_MATCHES);
912 if (req.emr_out_length_used <
913 MC_CMD_GET_PARSER_DISP_INFO_OUT_LEN(*length)) {
921 GET_PARSER_DISP_INFO_OUT_SUPPORTED_MATCHES),
922 (*length) * sizeof (uint32_t));
923 EFX_STATIC_ASSERT(sizeof (uint32_t) ==
924 MC_CMD_GET_PARSER_DISP_INFO_OUT_SUPPORTED_MATCHES_LEN);
927 * Remove UNKNOWN UCAST and MCAST flags, and if both are present, change
928 * the lower priority one to LOC_MAC_IG.
930 for (i = 0; i < *length; i++) {
931 if (list[i] & MC_CMD_FILTER_OP_IN_MATCH_UNKNOWN_UCAST_DST_LBN) {
933 (~MC_CMD_FILTER_OP_IN_MATCH_UNKNOWN_UCAST_DST_LBN);
934 support_unknown_ucast = B_TRUE;
936 if (list[i] & MC_CMD_FILTER_OP_IN_MATCH_UNKNOWN_MCAST_DST_LBN) {
938 (~MC_CMD_FILTER_OP_IN_MATCH_UNKNOWN_MCAST_DST_LBN);
939 support_unknown_mcast = B_TRUE;
942 if (support_unknown_ucast && support_unknown_mcast) {
943 list[i] &= EFX_FILTER_MATCH_LOC_MAC_IG;
953 EFSYS_PROBE1(fail1, efx_rc_t, rc);
958 __checkReturn efx_rc_t
959 ef10_filter_supported_filters(
961 __out uint32_t *list,
962 __out size_t *length)
966 if ((rc = efx_mcdi_get_parser_disp_info(enp, list, length)) != 0)
972 EFSYS_PROBE1(fail1, efx_rc_t, rc);
977 static __checkReturn efx_rc_t
978 ef10_filter_insert_unicast(
980 __in_ecount(6) uint8_t const *addr,
981 __in efx_filter_flags_t filter_flags)
983 ef10_filter_table_t *eftp = enp->en_filter.ef_ef10_filter_table;
984 efx_filter_spec_t spec;
987 /* Insert the filter for the local station address */
988 efx_filter_spec_init_rx(&spec, EFX_FILTER_PRI_AUTO,
990 eftp->eft_default_rxq);
991 efx_filter_spec_set_eth_local(&spec, EFX_FILTER_SPEC_VID_UNSPEC, addr);
993 rc = ef10_filter_add_internal(enp, &spec, B_TRUE,
994 &eftp->eft_unicst_filter_indexes[eftp->eft_unicst_filter_count]);
998 eftp->eft_unicst_filter_count++;
999 EFSYS_ASSERT(eftp->eft_unicst_filter_count <=
1000 EFX_EF10_FILTER_UNICAST_FILTERS_MAX);
1005 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1009 static __checkReturn efx_rc_t
1010 ef10_filter_insert_all_unicast(
1011 __in efx_nic_t *enp,
1012 __in efx_filter_flags_t filter_flags)
1014 ef10_filter_table_t *eftp = enp->en_filter.ef_ef10_filter_table;
1015 efx_filter_spec_t spec;
1018 /* Insert the unknown unicast filter */
1019 efx_filter_spec_init_rx(&spec, EFX_FILTER_PRI_AUTO,
1021 eftp->eft_default_rxq);
1022 efx_filter_spec_set_uc_def(&spec);
1023 rc = ef10_filter_add_internal(enp, &spec, B_TRUE,
1024 &eftp->eft_unicst_filter_indexes[eftp->eft_unicst_filter_count]);
1028 eftp->eft_unicst_filter_count++;
1029 EFSYS_ASSERT(eftp->eft_unicst_filter_count <=
1030 EFX_EF10_FILTER_UNICAST_FILTERS_MAX);
1035 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1039 static __checkReturn efx_rc_t
1040 ef10_filter_insert_multicast_list(
1041 __in efx_nic_t *enp,
1042 __in boolean_t mulcst,
1043 __in boolean_t brdcst,
1044 __in_ecount(6*count) uint8_t const *addrs,
1045 __in uint32_t count,
1046 __in efx_filter_flags_t filter_flags,
1047 __in boolean_t rollback)
1049 ef10_filter_table_t *eftp = enp->en_filter.ef_ef10_filter_table;
1050 efx_filter_spec_t spec;
1053 uint32_t filter_index;
1054 uint32_t filter_count;
1057 if (mulcst == B_FALSE)
1060 if (count + (brdcst ? 1 : 0) >
1061 EFX_ARRAY_SIZE(eftp->eft_mulcst_filter_indexes)) {
1062 /* Too many MAC addresses */
1067 /* Insert/renew multicast address list filters */
1069 for (i = 0; i < count; i++) {
1070 efx_filter_spec_init_rx(&spec,
1071 EFX_FILTER_PRI_AUTO,
1073 eftp->eft_default_rxq);
1075 efx_filter_spec_set_eth_local(&spec,
1076 EFX_FILTER_SPEC_VID_UNSPEC,
1077 &addrs[i * EFX_MAC_ADDR_LEN]);
1079 rc = ef10_filter_add_internal(enp, &spec, B_TRUE,
1083 eftp->eft_mulcst_filter_indexes[filter_count] =
1086 } else if (rollback == B_TRUE) {
1087 /* Only stop upon failure if told to rollback */
1093 if (brdcst == B_TRUE) {
1094 /* Insert/renew broadcast address filter */
1095 efx_filter_spec_init_rx(&spec, EFX_FILTER_PRI_AUTO,
1097 eftp->eft_default_rxq);
1099 EFX_MAC_BROADCAST_ADDR_SET(addr);
1100 efx_filter_spec_set_eth_local(&spec, EFX_FILTER_SPEC_VID_UNSPEC,
1103 rc = ef10_filter_add_internal(enp, &spec, B_TRUE,
1107 eftp->eft_mulcst_filter_indexes[filter_count] =
1110 } else if (rollback == B_TRUE) {
1111 /* Only stop upon failure if told to rollback */
1116 eftp->eft_mulcst_filter_count = filter_count;
1117 eftp->eft_using_all_mulcst = B_FALSE;
1122 /* Remove any filters we have inserted */
1125 (void) ef10_filter_delete_internal(enp,
1126 eftp->eft_mulcst_filter_indexes[i]);
1128 eftp->eft_mulcst_filter_count = 0;
1131 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1136 static __checkReturn efx_rc_t
1137 ef10_filter_insert_all_multicast(
1138 __in efx_nic_t *enp,
1139 __in efx_filter_flags_t filter_flags)
1141 ef10_filter_table_t *eftp = enp->en_filter.ef_ef10_filter_table;
1142 efx_filter_spec_t spec;
1145 /* Insert the unknown multicast filter */
1146 efx_filter_spec_init_rx(&spec, EFX_FILTER_PRI_AUTO,
1148 eftp->eft_default_rxq);
1149 efx_filter_spec_set_mc_def(&spec);
1151 rc = ef10_filter_add_internal(enp, &spec, B_TRUE,
1152 &eftp->eft_mulcst_filter_indexes[0]);
1156 eftp->eft_mulcst_filter_count = 1;
1157 eftp->eft_using_all_mulcst = B_TRUE;
1160 * FIXME: If brdcst == B_FALSE, add a filter to drop broadcast traffic.
1166 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1172 ef10_filter_remove_old(
1173 __in efx_nic_t *enp)
1175 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
1178 for (i = 0; i < EFX_ARRAY_SIZE(table->eft_entry); i++) {
1179 if (ef10_filter_entry_is_auto_old(table, i)) {
1180 (void) ef10_filter_delete_internal(enp, i);
1186 static __checkReturn efx_rc_t
1187 ef10_filter_get_workarounds(
1188 __in efx_nic_t *enp)
1190 efx_nic_cfg_t *encp = &enp->en_nic_cfg;
1191 uint32_t implemented = 0;
1192 uint32_t enabled = 0;
1195 rc = efx_mcdi_get_workarounds(enp, &implemented, &enabled);
1197 /* Check if chained multicast filter support is enabled */
1198 if (implemented & enabled & MC_CMD_GET_WORKAROUNDS_OUT_BUG26807)
1199 encp->enc_bug26807_workaround = B_TRUE;
1201 encp->enc_bug26807_workaround = B_FALSE;
1202 } else if (rc == ENOTSUP) {
1204 * Firmware is too old to support GET_WORKAROUNDS, and support
1205 * for this workaround was implemented later.
1207 encp->enc_bug26807_workaround = B_FALSE;
1215 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1223 * Reconfigure all filters.
1224 * If all_unicst and/or all mulcst filters cannot be applied then
1225 * return ENOTSUP (Note the filters for the specified addresses are
1226 * still applied in this case).
1228 __checkReturn efx_rc_t
1229 ef10_filter_reconfigure(
1230 __in efx_nic_t *enp,
1231 __in_ecount(6) uint8_t const *mac_addr,
1232 __in boolean_t all_unicst,
1233 __in boolean_t mulcst,
1234 __in boolean_t all_mulcst,
1235 __in boolean_t brdcst,
1236 __in_ecount(6*count) uint8_t const *addrs,
1237 __in uint32_t count)
1239 efx_nic_cfg_t *encp = &enp->en_nic_cfg;
1240 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
1241 efx_filter_flags_t filter_flags;
1243 efx_rc_t all_unicst_rc = 0;
1244 efx_rc_t all_mulcst_rc = 0;
1247 if (table->eft_default_rxq == NULL) {
1249 * Filters direct traffic to the default RXQ, and so cannot be
1250 * inserted until it is available. Any currently configured
1251 * filters must be removed (ignore errors in case the MC
1252 * has rebooted, which removes hardware filters).
1254 for (i = 0; i < table->eft_unicst_filter_count; i++) {
1255 (void) ef10_filter_delete_internal(enp,
1256 table->eft_unicst_filter_indexes[i]);
1258 table->eft_unicst_filter_count = 0;
1260 for (i = 0; i < table->eft_mulcst_filter_count; i++) {
1261 (void) ef10_filter_delete_internal(enp,
1262 table->eft_mulcst_filter_indexes[i]);
1264 table->eft_mulcst_filter_count = 0;
1269 if (table->eft_using_rss)
1270 filter_flags = EFX_FILTER_FLAG_RX_RSS;
1274 /* Mark old filters which may need to be removed */
1275 for (i = 0; i < table->eft_unicst_filter_count; i++) {
1276 ef10_filter_set_entry_auto_old(table,
1277 table->eft_unicst_filter_indexes[i]);
1279 for (i = 0; i < table->eft_mulcst_filter_count; i++) {
1280 ef10_filter_set_entry_auto_old(table,
1281 table->eft_mulcst_filter_indexes[i]);
1285 * Insert or renew unicast filters.
1287 * Frimware does not perform chaining on unicast filters. As traffic is
1288 * therefore only delivered to the first matching filter, we should
1289 * always insert the specific filter for our MAC address, to try and
1290 * ensure we get that traffic.
1292 * (If the filter for our MAC address has already been inserted by
1293 * another function, we won't receive traffic sent to us, even if we
1294 * insert a unicast mismatch filter. To prevent traffic stealing, this
1295 * therefore relies on the privilege model only allowing functions to
1296 * insert filters for their own MAC address unless explicitly given
1297 * additional privileges by the user. This also means that, even on a
1298 * priviliged function, inserting a unicast mismatch filter may not
1299 * catch all traffic in multi PCI function scenarios.)
1301 table->eft_unicst_filter_count = 0;
1302 rc = ef10_filter_insert_unicast(enp, mac_addr, filter_flags);
1303 if (all_unicst || (rc != 0)) {
1304 all_unicst_rc = ef10_filter_insert_all_unicast(enp,
1306 if ((rc != 0) && (all_unicst_rc != 0))
1311 * WORKAROUND_BUG26807 controls firmware support for chained multicast
1312 * filters, and can only be enabled or disabled when the hardware filter
1315 * Chained multicast filters require support from the datapath firmware,
1316 * and may not be available (e.g. low-latency variants or old Huntington
1319 * Firmware will reset (FLR) functions which have inserted filters in
1320 * the hardware filter table when the workaround is enabled/disabled.
1321 * Functions without any hardware filters are not reset.
1323 * Re-check if the workaround is enabled after adding unicast hardware
1324 * filters. This ensures that encp->enc_bug26807_workaround matches the
1325 * firmware state, and that later changes to enable/disable the
1326 * workaround will result in this function seeing a reset (FLR).
1328 * In common-code drivers, we only support multiple PCI function
1329 * scenarios with firmware that supports multicast chaining, so we can
1330 * assume it is enabled for such cases and hence simplify the filter
1331 * insertion logic. Firmware that does not support multicast chaining
1332 * does not support multiple PCI function configurations either, so
1333 * filter insertion is much simpler and the same strategies can still be
1336 if ((rc = ef10_filter_get_workarounds(enp)) != 0)
1339 if ((table->eft_using_all_mulcst != all_mulcst) &&
1340 (encp->enc_bug26807_workaround == B_TRUE)) {
1342 * Multicast filter chaining is enabled, so traffic that matches
1343 * more than one multicast filter will be replicated and
1344 * delivered to multiple recipients. To avoid this duplicate
1345 * delivery, remove old multicast filters before inserting new
1346 * multicast filters.
1348 ef10_filter_remove_old(enp);
1351 /* Insert or renew multicast filters */
1352 if (all_mulcst == B_TRUE) {
1354 * Insert the all multicast filter. If that fails, try to insert
1355 * all of our multicast filters (but without rollback on
1358 all_mulcst_rc = ef10_filter_insert_all_multicast(enp,
1360 if (all_mulcst_rc != 0) {
1361 rc = ef10_filter_insert_multicast_list(enp, B_TRUE,
1362 brdcst, addrs, count, filter_flags, B_FALSE);
1368 * Insert filters for multicast addresses.
1369 * If any insertion fails, then rollback and try to insert the
1370 * all multicast filter instead.
1371 * If that also fails, try to insert all of the multicast
1372 * filters (but without rollback on failure).
1374 rc = ef10_filter_insert_multicast_list(enp, mulcst, brdcst,
1375 addrs, count, filter_flags, B_TRUE);
1377 if ((table->eft_using_all_mulcst == B_FALSE) &&
1378 (encp->enc_bug26807_workaround == B_TRUE)) {
1380 * Multicast filter chaining is on, so remove
1381 * old filters before inserting the multicast
1382 * all filter to avoid duplicate delivery caused
1383 * by packets matching multiple filters.
1385 ef10_filter_remove_old(enp);
1388 rc = ef10_filter_insert_all_multicast(enp,
1391 rc = ef10_filter_insert_multicast_list(enp,
1393 addrs, count, filter_flags, B_FALSE);
1400 /* Remove old filters which were not renewed */
1401 ef10_filter_remove_old(enp);
1403 /* report if any optional flags were rejected */
1404 if (((all_unicst != B_FALSE) && (all_unicst_rc != 0)) ||
1405 ((all_mulcst != B_FALSE) && (all_mulcst_rc != 0))) {
1418 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1420 /* Clear auto old flags */
1421 for (i = 0; i < EFX_ARRAY_SIZE(table->eft_entry); i++) {
1422 if (ef10_filter_entry_is_auto_old(table, i)) {
1423 ef10_filter_set_entry_not_auto_old(table, i);
1431 ef10_filter_get_default_rxq(
1432 __in efx_nic_t *enp,
1433 __out efx_rxq_t **erpp,
1434 __out boolean_t *using_rss)
1436 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
1438 *erpp = table->eft_default_rxq;
1439 *using_rss = table->eft_using_rss;
1444 ef10_filter_default_rxq_set(
1445 __in efx_nic_t *enp,
1446 __in efx_rxq_t *erp,
1447 __in boolean_t using_rss)
1449 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
1451 EFSYS_ASSERT(using_rss == B_FALSE);
1452 table->eft_using_rss = B_FALSE;
1453 table->eft_default_rxq = erp;
1457 ef10_filter_default_rxq_clear(
1458 __in efx_nic_t *enp)
1460 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
1462 table->eft_default_rxq = NULL;
1463 table->eft_using_rss = B_FALSE;
1467 #endif /* EFSYS_OPT_FILTER */
1469 #endif /* EFSYS_OPT_HUNTINGTON || EFSYS_OPT_MEDFORD */