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
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);
127 #define MATCH_MASK(match) (EFX_MASK32(match) << EFX_LOW_BIT(match))
128 EFX_STATIC_ASSERT(EFX_FILTER_MATCH_REM_HOST ==
129 MATCH_MASK(MC_CMD_FILTER_OP_IN_MATCH_SRC_IP));
130 EFX_STATIC_ASSERT(EFX_FILTER_MATCH_LOC_HOST ==
131 MATCH_MASK(MC_CMD_FILTER_OP_IN_MATCH_DST_IP));
132 EFX_STATIC_ASSERT(EFX_FILTER_MATCH_REM_MAC ==
133 MATCH_MASK(MC_CMD_FILTER_OP_IN_MATCH_SRC_MAC));
134 EFX_STATIC_ASSERT(EFX_FILTER_MATCH_REM_PORT ==
135 MATCH_MASK(MC_CMD_FILTER_OP_IN_MATCH_SRC_PORT));
136 EFX_STATIC_ASSERT(EFX_FILTER_MATCH_LOC_MAC ==
137 MATCH_MASK(MC_CMD_FILTER_OP_IN_MATCH_DST_MAC));
138 EFX_STATIC_ASSERT(EFX_FILTER_MATCH_LOC_PORT ==
139 MATCH_MASK(MC_CMD_FILTER_OP_IN_MATCH_DST_PORT));
140 EFX_STATIC_ASSERT(EFX_FILTER_MATCH_ETHER_TYPE ==
141 MATCH_MASK(MC_CMD_FILTER_OP_IN_MATCH_ETHER_TYPE));
142 EFX_STATIC_ASSERT(EFX_FILTER_MATCH_INNER_VID ==
143 MATCH_MASK(MC_CMD_FILTER_OP_IN_MATCH_INNER_VLAN));
144 EFX_STATIC_ASSERT(EFX_FILTER_MATCH_OUTER_VID ==
145 MATCH_MASK(MC_CMD_FILTER_OP_IN_MATCH_OUTER_VLAN));
146 EFX_STATIC_ASSERT(EFX_FILTER_MATCH_IP_PROTO ==
147 MATCH_MASK(MC_CMD_FILTER_OP_IN_MATCH_IP_PROTO));
150 EFSYS_KMEM_ALLOC(enp->en_esip, sizeof (ef10_filter_table_t), eftp);
157 enp->en_filter.ef_ef10_filter_table = eftp;
162 EFSYS_PROBE1(fail1, efx_rc_t, rc);
171 EFSYS_ASSERT(enp->en_family == EFX_FAMILY_HUNTINGTON ||
172 enp->en_family == EFX_FAMILY_MEDFORD);
174 if (enp->en_filter.ef_ef10_filter_table != NULL) {
175 EFSYS_KMEM_FREE(enp->en_esip, sizeof (ef10_filter_table_t),
176 enp->en_filter.ef_ef10_filter_table);
180 static __checkReturn efx_rc_t
181 efx_mcdi_filter_op_add(
183 __in efx_filter_spec_t *spec,
184 __in unsigned int filter_op,
185 __inout ef10_filter_handle_t *handle)
188 uint8_t payload[MAX(MC_CMD_FILTER_OP_IN_LEN,
189 MC_CMD_FILTER_OP_OUT_LEN)];
190 uint32_t match_fields = 0;
193 memset(payload, 0, sizeof (payload));
194 req.emr_cmd = MC_CMD_FILTER_OP;
195 req.emr_in_buf = payload;
196 req.emr_in_length = MC_CMD_FILTER_OP_IN_LEN;
197 req.emr_out_buf = payload;
198 req.emr_out_length = MC_CMD_FILTER_OP_OUT_LEN;
201 case MC_CMD_FILTER_OP_IN_OP_REPLACE:
202 MCDI_IN_SET_DWORD(req, FILTER_OP_IN_HANDLE_LO,
204 MCDI_IN_SET_DWORD(req, FILTER_OP_IN_HANDLE_HI,
207 case MC_CMD_FILTER_OP_IN_OP_INSERT:
208 case MC_CMD_FILTER_OP_IN_OP_SUBSCRIBE:
209 MCDI_IN_SET_DWORD(req, FILTER_OP_IN_OP, filter_op);
217 if (spec->efs_match_flags & EFX_FILTER_MATCH_LOC_MAC_IG) {
219 * The LOC_MAC_IG match flag can represent unknown unicast
220 * or multicast filters - use the MAC address to distinguish
223 if (EFX_MAC_ADDR_IS_MULTICAST(spec->efs_loc_mac))
224 match_fields |= 1U <<
225 MC_CMD_FILTER_OP_IN_MATCH_UNKNOWN_MCAST_DST_LBN;
227 match_fields |= 1U <<
228 MC_CMD_FILTER_OP_IN_MATCH_UNKNOWN_UCAST_DST_LBN;
231 match_fields |= spec->efs_match_flags & (~EFX_FILTER_MATCH_LOC_MAC_IG);
233 MCDI_IN_SET_DWORD(req, FILTER_OP_IN_PORT_ID,
234 EVB_PORT_ID_ASSIGNED);
235 MCDI_IN_SET_DWORD(req, FILTER_OP_IN_MATCH_FIELDS,
237 MCDI_IN_SET_DWORD(req, FILTER_OP_IN_RX_DEST,
238 MC_CMD_FILTER_OP_IN_RX_DEST_HOST);
239 MCDI_IN_SET_DWORD(req, FILTER_OP_IN_RX_QUEUE,
241 if (spec->efs_flags & EFX_FILTER_FLAG_RX_RSS) {
242 MCDI_IN_SET_DWORD(req, FILTER_OP_IN_RX_CONTEXT,
243 spec->efs_rss_context);
245 MCDI_IN_SET_DWORD(req, FILTER_OP_IN_RX_MODE,
246 spec->efs_flags & EFX_FILTER_FLAG_RX_RSS ?
247 MC_CMD_FILTER_OP_IN_RX_MODE_RSS :
248 MC_CMD_FILTER_OP_IN_RX_MODE_SIMPLE);
249 MCDI_IN_SET_DWORD(req, FILTER_OP_IN_TX_DEST,
250 MC_CMD_FILTER_OP_IN_TX_DEST_DEFAULT);
252 if (filter_op != MC_CMD_FILTER_OP_IN_OP_REPLACE) {
254 * NOTE: Unlike most MCDI requests, the filter fields
255 * are presented in network (big endian) byte order.
257 memcpy(MCDI_IN2(req, uint8_t, FILTER_OP_IN_SRC_MAC),
258 spec->efs_rem_mac, EFX_MAC_ADDR_LEN);
259 memcpy(MCDI_IN2(req, uint8_t, FILTER_OP_IN_DST_MAC),
260 spec->efs_loc_mac, EFX_MAC_ADDR_LEN);
262 MCDI_IN_SET_WORD(req, FILTER_OP_IN_SRC_PORT,
263 __CPU_TO_BE_16(spec->efs_rem_port));
264 MCDI_IN_SET_WORD(req, FILTER_OP_IN_DST_PORT,
265 __CPU_TO_BE_16(spec->efs_loc_port));
267 MCDI_IN_SET_WORD(req, FILTER_OP_IN_ETHER_TYPE,
268 __CPU_TO_BE_16(spec->efs_ether_type));
270 MCDI_IN_SET_WORD(req, FILTER_OP_IN_INNER_VLAN,
271 __CPU_TO_BE_16(spec->efs_inner_vid));
272 MCDI_IN_SET_WORD(req, FILTER_OP_IN_OUTER_VLAN,
273 __CPU_TO_BE_16(spec->efs_outer_vid));
275 /* IP protocol (in low byte, high byte is zero) */
276 MCDI_IN_SET_BYTE(req, FILTER_OP_IN_IP_PROTO,
279 EFX_STATIC_ASSERT(sizeof (spec->efs_rem_host) ==
280 MC_CMD_FILTER_OP_IN_SRC_IP_LEN);
281 EFX_STATIC_ASSERT(sizeof (spec->efs_loc_host) ==
282 MC_CMD_FILTER_OP_IN_DST_IP_LEN);
284 memcpy(MCDI_IN2(req, uint8_t, FILTER_OP_IN_SRC_IP),
285 &spec->efs_rem_host.eo_byte[0],
286 MC_CMD_FILTER_OP_IN_SRC_IP_LEN);
287 memcpy(MCDI_IN2(req, uint8_t, FILTER_OP_IN_DST_IP),
288 &spec->efs_loc_host.eo_byte[0],
289 MC_CMD_FILTER_OP_IN_DST_IP_LEN);
292 efx_mcdi_execute(enp, &req);
294 if (req.emr_rc != 0) {
299 if (req.emr_out_length_used < MC_CMD_FILTER_OP_OUT_LEN) {
304 handle->efh_lo = MCDI_OUT_DWORD(req, FILTER_OP_OUT_HANDLE_LO);
305 handle->efh_hi = MCDI_OUT_DWORD(req, FILTER_OP_OUT_HANDLE_HI);
314 EFSYS_PROBE1(fail1, efx_rc_t, rc);
320 static __checkReturn efx_rc_t
321 efx_mcdi_filter_op_delete(
323 __in unsigned int filter_op,
324 __inout ef10_filter_handle_t *handle)
327 uint8_t payload[MAX(MC_CMD_FILTER_OP_IN_LEN,
328 MC_CMD_FILTER_OP_OUT_LEN)];
331 memset(payload, 0, sizeof (payload));
332 req.emr_cmd = MC_CMD_FILTER_OP;
333 req.emr_in_buf = payload;
334 req.emr_in_length = MC_CMD_FILTER_OP_IN_LEN;
335 req.emr_out_buf = payload;
336 req.emr_out_length = MC_CMD_FILTER_OP_OUT_LEN;
339 case MC_CMD_FILTER_OP_IN_OP_REMOVE:
340 MCDI_IN_SET_DWORD(req, FILTER_OP_IN_OP,
341 MC_CMD_FILTER_OP_IN_OP_REMOVE);
343 case MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE:
344 MCDI_IN_SET_DWORD(req, FILTER_OP_IN_OP,
345 MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE);
353 MCDI_IN_SET_DWORD(req, FILTER_OP_IN_HANDLE_LO, handle->efh_lo);
354 MCDI_IN_SET_DWORD(req, FILTER_OP_IN_HANDLE_HI, handle->efh_hi);
356 efx_mcdi_execute_quiet(enp, &req);
358 if (req.emr_rc != 0) {
363 if (req.emr_out_length_used < MC_CMD_FILTER_OP_OUT_LEN) {
376 EFSYS_PROBE1(fail1, efx_rc_t, rc);
381 static __checkReturn boolean_t
383 __in const efx_filter_spec_t *left,
384 __in const efx_filter_spec_t *right)
386 /* FIXME: Consider rx vs tx filters (look at efs_flags) */
387 if (left->efs_match_flags != right->efs_match_flags)
389 if (!EFX_OWORD_IS_EQUAL(left->efs_rem_host, right->efs_rem_host))
391 if (!EFX_OWORD_IS_EQUAL(left->efs_loc_host, right->efs_loc_host))
393 if (memcmp(left->efs_rem_mac, right->efs_rem_mac, EFX_MAC_ADDR_LEN))
395 if (memcmp(left->efs_loc_mac, right->efs_loc_mac, EFX_MAC_ADDR_LEN))
397 if (left->efs_rem_port != right->efs_rem_port)
399 if (left->efs_loc_port != right->efs_loc_port)
401 if (left->efs_inner_vid != right->efs_inner_vid)
403 if (left->efs_outer_vid != right->efs_outer_vid)
405 if (left->efs_ether_type != right->efs_ether_type)
407 if (left->efs_ip_proto != right->efs_ip_proto)
414 static __checkReturn boolean_t
415 ef10_filter_same_dest(
416 __in const efx_filter_spec_t *left,
417 __in const efx_filter_spec_t *right)
419 if ((left->efs_flags & EFX_FILTER_FLAG_RX_RSS) &&
420 (right->efs_flags & EFX_FILTER_FLAG_RX_RSS)) {
421 if (left->efs_rss_context == right->efs_rss_context)
423 } else if ((~(left->efs_flags) & EFX_FILTER_FLAG_RX_RSS) &&
424 (~(right->efs_flags) & EFX_FILTER_FLAG_RX_RSS)) {
425 if (left->efs_dmaq_id == right->efs_dmaq_id)
431 static __checkReturn uint32_t
433 __in efx_filter_spec_t *spec)
435 EFX_STATIC_ASSERT((sizeof (efx_filter_spec_t) % sizeof (uint32_t))
437 EFX_STATIC_ASSERT((EFX_FIELD_OFFSET(efx_filter_spec_t, efs_outer_vid) %
438 sizeof (uint32_t)) == 0);
441 * As the area of the efx_filter_spec_t we need to hash is DWORD
442 * aligned and an exact number of DWORDs in size we can use the
443 * optimised efx_hash_dwords() rather than efx_hash_bytes()
445 return (efx_hash_dwords((const uint32_t *)&spec->efs_outer_vid,
446 (sizeof (efx_filter_spec_t) -
447 EFX_FIELD_OFFSET(efx_filter_spec_t, efs_outer_vid)) /
448 sizeof (uint32_t), 0));
452 * Decide whether a filter should be exclusive or else should allow
453 * delivery to additional recipients. Currently we decide that
454 * filters for specific local unicast MAC and IP addresses are
457 static __checkReturn boolean_t
458 ef10_filter_is_exclusive(
459 __in efx_filter_spec_t *spec)
461 if ((spec->efs_match_flags & EFX_FILTER_MATCH_LOC_MAC) &&
462 !EFX_MAC_ADDR_IS_MULTICAST(spec->efs_loc_mac))
465 if ((spec->efs_match_flags &
466 (EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_LOC_HOST)) ==
467 (EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_LOC_HOST)) {
468 if ((spec->efs_ether_type == EFX_ETHER_TYPE_IPV4) &&
469 ((spec->efs_loc_host.eo_u8[0] & 0xf) != 0xe))
471 if ((spec->efs_ether_type == EFX_ETHER_TYPE_IPV6) &&
472 (spec->efs_loc_host.eo_u8[0] != 0xff))
479 __checkReturn efx_rc_t
484 efx_filter_spec_t *spec;
485 ef10_filter_table_t *eftp = enp->en_filter.ef_ef10_filter_table;
490 EFSYS_ASSERT(enp->en_family == EFX_FAMILY_HUNTINGTON ||
491 enp->en_family == EFX_FAMILY_MEDFORD);
493 for (tbl_id = 0; tbl_id < EFX_EF10_FILTER_TBL_ROWS; tbl_id++) {
495 EFSYS_LOCK(enp->en_eslp, state);
497 spec = ef10_filter_entry_spec(eftp, tbl_id);
500 } else if (ef10_filter_entry_is_busy(eftp, tbl_id)) {
501 /* Ignore busy entries. */
504 ef10_filter_set_entry_busy(eftp, tbl_id);
508 EFSYS_UNLOCK(enp->en_eslp, state);
510 if (restoring == B_FALSE)
513 if (ef10_filter_is_exclusive(spec)) {
514 rc = efx_mcdi_filter_op_add(enp, spec,
515 MC_CMD_FILTER_OP_IN_OP_INSERT,
516 &eftp->eft_entry[tbl_id].efe_handle);
518 rc = efx_mcdi_filter_op_add(enp, spec,
519 MC_CMD_FILTER_OP_IN_OP_SUBSCRIBE,
520 &eftp->eft_entry[tbl_id].efe_handle);
526 EFSYS_LOCK(enp->en_eslp, state);
528 ef10_filter_set_entry_not_busy(eftp, tbl_id);
530 EFSYS_UNLOCK(enp->en_eslp, state);
536 EFSYS_PROBE1(fail1, efx_rc_t, rc);
542 * An arbitrary search limit for the software hash table. As per the linux net
545 #define EF10_FILTER_SEARCH_LIMIT 200
547 static __checkReturn efx_rc_t
548 ef10_filter_add_internal(
550 __inout efx_filter_spec_t *spec,
551 __in boolean_t may_replace,
552 __out_opt uint32_t *filter_id)
555 ef10_filter_table_t *eftp = enp->en_filter.ef_ef10_filter_table;
556 efx_filter_spec_t *saved_spec;
560 boolean_t replacing = B_FALSE;
563 boolean_t locked = B_FALSE;
565 EFSYS_ASSERT(enp->en_family == EFX_FAMILY_HUNTINGTON ||
566 enp->en_family == EFX_FAMILY_MEDFORD);
568 #if EFSYS_OPT_RX_SCALE
569 spec->efs_rss_context = enp->en_rss_context;
572 hash = ef10_filter_hash(spec);
575 * FIXME: Add support for inserting filters of different priorities
576 * and removing lower priority multicast filters (bug 42378)
580 * Find any existing filters with the same match tuple or
581 * else a free slot to insert at. If any of them are busy,
582 * we have to wait and retry.
587 EFSYS_LOCK(enp->en_eslp, state);
591 i = (hash + depth) & (EFX_EF10_FILTER_TBL_ROWS - 1);
592 saved_spec = ef10_filter_entry_spec(eftp, i);
598 } else if (ef10_filter_equal(spec, saved_spec)) {
599 if (ef10_filter_entry_is_busy(eftp, i))
601 if (saved_spec->efs_priority
602 == EFX_FILTER_PRI_AUTO) {
605 } else if (ef10_filter_is_exclusive(spec)) {
619 * Once we reach the maximum search depth, use
620 * the first suitable slot or return EBUSY if
623 if (depth == EF10_FILTER_SEARCH_LIMIT) {
632 EFSYS_UNLOCK(enp->en_eslp, state);
638 * Create a software table entry if necessary, and mark it
639 * busy. We might yet fail to insert, but any attempt to
640 * insert a conflicting filter while we're waiting for the
641 * firmware must find the busy entry.
643 saved_spec = ef10_filter_entry_spec(eftp, ins_index);
645 if (saved_spec->efs_priority == EFX_FILTER_PRI_AUTO) {
646 /* This is a filter we are refreshing */
647 ef10_filter_set_entry_not_auto_old(eftp, ins_index);
653 EFSYS_KMEM_ALLOC(enp->en_esip, sizeof (*spec), saved_spec);
659 ef10_filter_set_entry(eftp, ins_index, saved_spec);
661 ef10_filter_set_entry_busy(eftp, ins_index);
663 EFSYS_UNLOCK(enp->en_eslp, state);
667 * On replacing the filter handle may change after after a successful
671 rc = efx_mcdi_filter_op_add(enp, spec,
672 MC_CMD_FILTER_OP_IN_OP_REPLACE,
673 &eftp->eft_entry[ins_index].efe_handle);
674 } else if (ef10_filter_is_exclusive(spec)) {
675 rc = efx_mcdi_filter_op_add(enp, spec,
676 MC_CMD_FILTER_OP_IN_OP_INSERT,
677 &eftp->eft_entry[ins_index].efe_handle);
679 rc = efx_mcdi_filter_op_add(enp, spec,
680 MC_CMD_FILTER_OP_IN_OP_SUBSCRIBE,
681 &eftp->eft_entry[ins_index].efe_handle);
687 EFSYS_LOCK(enp->en_eslp, state);
691 /* Update the fields that may differ */
692 saved_spec->efs_priority = spec->efs_priority;
693 saved_spec->efs_flags = spec->efs_flags;
694 saved_spec->efs_rss_context = spec->efs_rss_context;
695 saved_spec->efs_dmaq_id = spec->efs_dmaq_id;
698 ef10_filter_set_entry_not_busy(eftp, ins_index);
702 EFSYS_UNLOCK(enp->en_eslp, state);
706 *filter_id = ins_index;
714 EFSYS_KMEM_FREE(enp->en_esip, sizeof (*spec), saved_spec);
717 ef10_filter_set_entry_not_busy(eftp, ins_index);
718 ef10_filter_set_entry(eftp, ins_index, NULL);
727 EFSYS_PROBE1(fail1, efx_rc_t, rc);
730 EFSYS_UNLOCK(enp->en_eslp, state);
735 __checkReturn efx_rc_t
738 __inout efx_filter_spec_t *spec,
739 __in boolean_t may_replace)
743 rc = ef10_filter_add_internal(enp, spec, may_replace, NULL);
750 EFSYS_PROBE1(fail1, efx_rc_t, rc);
756 static __checkReturn efx_rc_t
757 ef10_filter_delete_internal(
759 __in uint32_t filter_id)
762 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
763 efx_filter_spec_t *spec;
765 uint32_t filter_idx = filter_id % EFX_EF10_FILTER_TBL_ROWS;
768 * Find the software table entry and mark it busy. Don't
769 * remove it yet; any attempt to update while we're waiting
770 * for the firmware must find the busy entry.
772 * FIXME: What if the busy flag is never cleared?
774 EFSYS_LOCK(enp->en_eslp, state);
775 while (ef10_filter_entry_is_busy(table, filter_idx)) {
776 EFSYS_UNLOCK(enp->en_eslp, state);
778 EFSYS_LOCK(enp->en_eslp, state);
780 if ((spec = ef10_filter_entry_spec(table, filter_idx)) != NULL) {
781 ef10_filter_set_entry_busy(table, filter_idx);
783 EFSYS_UNLOCK(enp->en_eslp, state);
791 * Try to remove the hardware filter. This may fail if the MC has
792 * rebooted (which frees all hardware filter resources).
794 if (ef10_filter_is_exclusive(spec)) {
795 rc = efx_mcdi_filter_op_delete(enp,
796 MC_CMD_FILTER_OP_IN_OP_REMOVE,
797 &table->eft_entry[filter_idx].efe_handle);
799 rc = efx_mcdi_filter_op_delete(enp,
800 MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE,
801 &table->eft_entry[filter_idx].efe_handle);
804 /* Free the software table entry */
805 EFSYS_LOCK(enp->en_eslp, state);
806 ef10_filter_set_entry_not_busy(table, filter_idx);
807 ef10_filter_set_entry(table, filter_idx, NULL);
808 EFSYS_UNLOCK(enp->en_eslp, state);
810 EFSYS_KMEM_FREE(enp->en_esip, sizeof (*spec), spec);
812 /* Check result of hardware filter removal */
822 EFSYS_PROBE1(fail1, efx_rc_t, rc);
827 __checkReturn efx_rc_t
830 __inout efx_filter_spec_t *spec)
833 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
834 efx_filter_spec_t *saved_spec;
839 boolean_t locked = B_FALSE;
841 EFSYS_ASSERT(enp->en_family == EFX_FAMILY_HUNTINGTON ||
842 enp->en_family == EFX_FAMILY_MEDFORD);
844 hash = ef10_filter_hash(spec);
846 EFSYS_LOCK(enp->en_eslp, state);
851 i = (hash + depth) & (EFX_EF10_FILTER_TBL_ROWS - 1);
852 saved_spec = ef10_filter_entry_spec(table, i);
853 if (saved_spec && ef10_filter_equal(spec, saved_spec) &&
854 ef10_filter_same_dest(spec, saved_spec)) {
857 if (depth == EF10_FILTER_SEARCH_LIMIT) {
864 EFSYS_UNLOCK(enp->en_eslp, state);
867 rc = ef10_filter_delete_internal(enp, i);
877 EFSYS_PROBE1(fail1, efx_rc_t, rc);
880 EFSYS_UNLOCK(enp->en_eslp, state);
885 static __checkReturn efx_rc_t
886 efx_mcdi_get_parser_disp_info(
888 __out uint32_t *list,
889 __out size_t *length)
892 uint8_t payload[MAX(MC_CMD_GET_PARSER_DISP_INFO_IN_LEN,
893 MC_CMD_GET_PARSER_DISP_INFO_OUT_LENMAX)];
896 boolean_t support_unknown_ucast = B_FALSE;
897 boolean_t support_unknown_mcast = B_FALSE;
899 (void) memset(payload, 0, sizeof (payload));
900 req.emr_cmd = MC_CMD_GET_PARSER_DISP_INFO;
901 req.emr_in_buf = payload;
902 req.emr_in_length = MC_CMD_GET_PARSER_DISP_INFO_IN_LEN;
903 req.emr_out_buf = payload;
904 req.emr_out_length = MC_CMD_GET_PARSER_DISP_INFO_OUT_LENMAX;
906 MCDI_IN_SET_DWORD(req, GET_PARSER_DISP_INFO_OUT_OP,
907 MC_CMD_GET_PARSER_DISP_INFO_IN_OP_GET_SUPPORTED_RX_MATCHES);
909 efx_mcdi_execute(enp, &req);
911 if (req.emr_rc != 0) {
916 *length = MCDI_OUT_DWORD(req,
917 GET_PARSER_DISP_INFO_OUT_NUM_SUPPORTED_MATCHES);
919 if (req.emr_out_length_used <
920 MC_CMD_GET_PARSER_DISP_INFO_OUT_LEN(*length)) {
928 GET_PARSER_DISP_INFO_OUT_SUPPORTED_MATCHES),
929 (*length) * sizeof (uint32_t));
930 EFX_STATIC_ASSERT(sizeof (uint32_t) ==
931 MC_CMD_GET_PARSER_DISP_INFO_OUT_SUPPORTED_MATCHES_LEN);
934 * Remove UNKNOWN UCAST and MCAST flags, and if both are present, change
935 * the lower priority one to LOC_MAC_IG.
937 for (i = 0; i < *length; i++) {
938 if (list[i] & MC_CMD_FILTER_OP_IN_MATCH_UNKNOWN_UCAST_DST_LBN) {
940 (~MC_CMD_FILTER_OP_IN_MATCH_UNKNOWN_UCAST_DST_LBN);
941 support_unknown_ucast = B_TRUE;
943 if (list[i] & MC_CMD_FILTER_OP_IN_MATCH_UNKNOWN_MCAST_DST_LBN) {
945 (~MC_CMD_FILTER_OP_IN_MATCH_UNKNOWN_MCAST_DST_LBN);
946 support_unknown_mcast = B_TRUE;
949 if (support_unknown_ucast && support_unknown_mcast) {
950 list[i] &= EFX_FILTER_MATCH_LOC_MAC_IG;
960 EFSYS_PROBE1(fail1, efx_rc_t, rc);
965 __checkReturn efx_rc_t
966 ef10_filter_supported_filters(
968 __out uint32_t *list,
969 __out size_t *length)
973 if ((rc = efx_mcdi_get_parser_disp_info(enp, list, length)) != 0)
979 EFSYS_PROBE1(fail1, efx_rc_t, rc);
984 static __checkReturn efx_rc_t
985 ef10_filter_insert_unicast(
987 __in_ecount(6) uint8_t const *addr,
988 __in efx_filter_flag_t filter_flags)
990 ef10_filter_table_t *eftp = enp->en_filter.ef_ef10_filter_table;
991 efx_filter_spec_t spec;
994 /* Insert the filter for the local station address */
995 efx_filter_spec_init_rx(&spec, EFX_FILTER_PRI_AUTO,
997 eftp->eft_default_rxq);
998 efx_filter_spec_set_eth_local(&spec, EFX_FILTER_SPEC_VID_UNSPEC, addr);
1000 rc = ef10_filter_add_internal(enp, &spec, B_TRUE,
1001 &eftp->eft_unicst_filter_indexes[eftp->eft_unicst_filter_count]);
1005 eftp->eft_unicst_filter_count++;
1006 EFSYS_ASSERT(eftp->eft_unicst_filter_count <=
1007 EFX_EF10_FILTER_UNICAST_FILTERS_MAX);
1012 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1016 static __checkReturn efx_rc_t
1017 ef10_filter_insert_all_unicast(
1018 __in efx_nic_t *enp,
1019 __in efx_filter_flag_t filter_flags)
1021 ef10_filter_table_t *eftp = enp->en_filter.ef_ef10_filter_table;
1022 efx_filter_spec_t spec;
1025 /* Insert the unknown unicast filter */
1026 efx_filter_spec_init_rx(&spec, EFX_FILTER_PRI_AUTO,
1028 eftp->eft_default_rxq);
1029 efx_filter_spec_set_uc_def(&spec);
1030 rc = ef10_filter_add_internal(enp, &spec, B_TRUE,
1031 &eftp->eft_unicst_filter_indexes[eftp->eft_unicst_filter_count]);
1035 eftp->eft_unicst_filter_count++;
1036 EFSYS_ASSERT(eftp->eft_unicst_filter_count <=
1037 EFX_EF10_FILTER_UNICAST_FILTERS_MAX);
1042 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1046 static __checkReturn efx_rc_t
1047 ef10_filter_insert_multicast_list(
1048 __in efx_nic_t *enp,
1049 __in boolean_t mulcst,
1050 __in boolean_t brdcst,
1051 __in_ecount(6*count) uint8_t const *addrs,
1052 __in uint32_t count,
1053 __in efx_filter_flag_t filter_flags,
1054 __in boolean_t rollback)
1056 ef10_filter_table_t *eftp = enp->en_filter.ef_ef10_filter_table;
1057 efx_filter_spec_t spec;
1060 uint32_t filter_index;
1061 uint32_t filter_count;
1064 if (mulcst == B_FALSE)
1067 if (count + (brdcst ? 1 : 0) >
1068 EFX_ARRAY_SIZE(eftp->eft_mulcst_filter_indexes)) {
1069 /* Too many MAC addresses */
1074 /* Insert/renew multicast address list filters */
1076 for (i = 0; i < count; i++) {
1077 efx_filter_spec_init_rx(&spec,
1078 EFX_FILTER_PRI_AUTO,
1080 eftp->eft_default_rxq);
1082 efx_filter_spec_set_eth_local(&spec,
1083 EFX_FILTER_SPEC_VID_UNSPEC,
1084 &addrs[i * EFX_MAC_ADDR_LEN]);
1086 rc = ef10_filter_add_internal(enp, &spec, B_TRUE,
1090 eftp->eft_mulcst_filter_indexes[filter_count] =
1093 } else if (rollback == B_TRUE) {
1094 /* Only stop upon failure if told to rollback */
1100 if (brdcst == B_TRUE) {
1101 /* Insert/renew broadcast address filter */
1102 efx_filter_spec_init_rx(&spec, EFX_FILTER_PRI_AUTO,
1104 eftp->eft_default_rxq);
1106 EFX_MAC_BROADCAST_ADDR_SET(addr);
1107 efx_filter_spec_set_eth_local(&spec, EFX_FILTER_SPEC_VID_UNSPEC,
1110 rc = ef10_filter_add_internal(enp, &spec, B_TRUE,
1114 eftp->eft_mulcst_filter_indexes[filter_count] =
1117 } else if (rollback == B_TRUE) {
1118 /* Only stop upon failure if told to rollback */
1123 eftp->eft_mulcst_filter_count = filter_count;
1124 eftp->eft_using_all_mulcst = B_FALSE;
1129 /* Remove any filters we have inserted */
1132 (void) ef10_filter_delete_internal(enp,
1133 eftp->eft_mulcst_filter_indexes[i]);
1135 eftp->eft_mulcst_filter_count = 0;
1138 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1143 static __checkReturn efx_rc_t
1144 ef10_filter_insert_all_multicast(
1145 __in efx_nic_t *enp,
1146 __in efx_filter_flag_t filter_flags)
1148 ef10_filter_table_t *eftp = enp->en_filter.ef_ef10_filter_table;
1149 efx_filter_spec_t spec;
1152 /* Insert the unknown multicast filter */
1153 efx_filter_spec_init_rx(&spec, EFX_FILTER_PRI_AUTO,
1155 eftp->eft_default_rxq);
1156 efx_filter_spec_set_mc_def(&spec);
1158 rc = ef10_filter_add_internal(enp, &spec, B_TRUE,
1159 &eftp->eft_mulcst_filter_indexes[0]);
1163 eftp->eft_mulcst_filter_count = 1;
1164 eftp->eft_using_all_mulcst = B_TRUE;
1167 * FIXME: If brdcst == B_FALSE, add a filter to drop broadcast traffic.
1173 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1179 ef10_filter_remove_old(
1180 __in efx_nic_t *enp)
1182 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
1185 for (i = 0; i < EFX_ARRAY_SIZE(table->eft_entry); i++) {
1186 if (ef10_filter_entry_is_auto_old(table, i)) {
1187 (void) ef10_filter_delete_internal(enp, i);
1193 static __checkReturn efx_rc_t
1194 ef10_filter_get_workarounds(
1195 __in efx_nic_t *enp)
1197 efx_nic_cfg_t *encp = &enp->en_nic_cfg;
1198 uint32_t implemented = 0;
1199 uint32_t enabled = 0;
1202 rc = efx_mcdi_get_workarounds(enp, &implemented, &enabled);
1204 /* Check if chained multicast filter support is enabled */
1205 if (implemented & enabled & MC_CMD_GET_WORKAROUNDS_OUT_BUG26807)
1206 encp->enc_bug26807_workaround = B_TRUE;
1208 encp->enc_bug26807_workaround = B_FALSE;
1209 } else if (rc == ENOTSUP) {
1211 * Firmware is too old to support GET_WORKAROUNDS, and support
1212 * for this workaround was implemented later.
1214 encp->enc_bug26807_workaround = B_FALSE;
1222 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1230 * Reconfigure all filters.
1231 * If all_unicst and/or all mulcst filters cannot be applied then
1232 * return ENOTSUP (Note the filters for the specified addresses are
1233 * still applied in this case).
1235 __checkReturn efx_rc_t
1236 ef10_filter_reconfigure(
1237 __in efx_nic_t *enp,
1238 __in_ecount(6) uint8_t const *mac_addr,
1239 __in boolean_t all_unicst,
1240 __in boolean_t mulcst,
1241 __in boolean_t all_mulcst,
1242 __in boolean_t brdcst,
1243 __in_ecount(6*count) uint8_t const *addrs,
1244 __in uint32_t count)
1246 efx_nic_cfg_t *encp = &enp->en_nic_cfg;
1247 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
1248 efx_filter_flag_t filter_flags;
1250 efx_rc_t all_unicst_rc = 0;
1251 efx_rc_t all_mulcst_rc = 0;
1254 if (table->eft_default_rxq == NULL) {
1256 * Filters direct traffic to the default RXQ, and so cannot be
1257 * inserted until it is available. Any currently configured
1258 * filters must be removed (ignore errors in case the MC
1259 * has rebooted, which removes hardware filters).
1261 for (i = 0; i < table->eft_unicst_filter_count; i++) {
1262 (void) ef10_filter_delete_internal(enp,
1263 table->eft_unicst_filter_indexes[i]);
1265 table->eft_unicst_filter_count = 0;
1267 for (i = 0; i < table->eft_mulcst_filter_count; i++) {
1268 (void) ef10_filter_delete_internal(enp,
1269 table->eft_mulcst_filter_indexes[i]);
1271 table->eft_mulcst_filter_count = 0;
1276 if (table->eft_using_rss)
1277 filter_flags = EFX_FILTER_FLAG_RX_RSS;
1281 /* Mark old filters which may need to be removed */
1282 for (i = 0; i < table->eft_unicst_filter_count; i++) {
1283 ef10_filter_set_entry_auto_old(table,
1284 table->eft_unicst_filter_indexes[i]);
1286 for (i = 0; i < table->eft_mulcst_filter_count; i++) {
1287 ef10_filter_set_entry_auto_old(table,
1288 table->eft_mulcst_filter_indexes[i]);
1292 * Insert or renew unicast filters.
1294 * Frimware does not perform chaining on unicast filters. As traffic is
1295 * therefore only delivered to the first matching filter, we should
1296 * always insert the specific filter for our MAC address, to try and
1297 * ensure we get that traffic.
1299 * (If the filter for our MAC address has already been inserted by
1300 * another function, we won't receive traffic sent to us, even if we
1301 * insert a unicast mismatch filter. To prevent traffic stealing, this
1302 * therefore relies on the privilege model only allowing functions to
1303 * insert filters for their own MAC address unless explicitly given
1304 * additional privileges by the user. This also means that, even on a
1305 * priviliged function, inserting a unicast mismatch filter may not
1306 * catch all traffic in multi PCI function scenarios.)
1308 table->eft_unicst_filter_count = 0;
1309 rc = ef10_filter_insert_unicast(enp, mac_addr, filter_flags);
1310 if (all_unicst || (rc != 0)) {
1311 all_unicst_rc = ef10_filter_insert_all_unicast(enp,
1313 if ((rc != 0) && (all_unicst_rc != 0))
1318 * WORKAROUND_BUG26807 controls firmware support for chained multicast
1319 * filters, and can only be enabled or disabled when the hardware filter
1322 * Chained multicast filters require support from the datapath firmware,
1323 * and may not be available (e.g. low-latency variants or old Huntington
1326 * Firmware will reset (FLR) functions which have inserted filters in
1327 * the hardware filter table when the workaround is enabled/disabled.
1328 * Functions without any hardware filters are not reset.
1330 * Re-check if the workaround is enabled after adding unicast hardware
1331 * filters. This ensures that encp->enc_bug26807_workaround matches the
1332 * firmware state, and that later changes to enable/disable the
1333 * workaround will result in this function seeing a reset (FLR).
1335 * In common-code drivers, we only support multiple PCI function
1336 * scenarios with firmware that supports multicast chaining, so we can
1337 * assume it is enabled for such cases and hence simplify the filter
1338 * insertion logic. Firmware that does not support multicast chaining
1339 * does not support multiple PCI function configurations either, so
1340 * filter insertion is much simpler and the same strategies can still be
1343 if ((rc = ef10_filter_get_workarounds(enp)) != 0)
1346 if ((table->eft_using_all_mulcst != all_mulcst) &&
1347 (encp->enc_bug26807_workaround == B_TRUE)) {
1349 * Multicast filter chaining is enabled, so traffic that matches
1350 * more than one multicast filter will be replicated and
1351 * delivered to multiple recipients. To avoid this duplicate
1352 * delivery, remove old multicast filters before inserting new
1353 * multicast filters.
1355 ef10_filter_remove_old(enp);
1358 /* Insert or renew multicast filters */
1359 if (all_mulcst == B_TRUE) {
1361 * Insert the all multicast filter. If that fails, try to insert
1362 * all of our multicast filters (but without rollback on
1365 all_mulcst_rc = ef10_filter_insert_all_multicast(enp,
1367 if (all_mulcst_rc != 0) {
1368 rc = ef10_filter_insert_multicast_list(enp, B_TRUE,
1369 brdcst, addrs, count, filter_flags, B_FALSE);
1375 * Insert filters for multicast addresses.
1376 * If any insertion fails, then rollback and try to insert the
1377 * all multicast filter instead.
1378 * If that also fails, try to insert all of the multicast
1379 * filters (but without rollback on failure).
1381 rc = ef10_filter_insert_multicast_list(enp, mulcst, brdcst,
1382 addrs, count, filter_flags, B_TRUE);
1384 if ((table->eft_using_all_mulcst == B_FALSE) &&
1385 (encp->enc_bug26807_workaround == B_TRUE)) {
1387 * Multicast filter chaining is on, so remove
1388 * old filters before inserting the multicast
1389 * all filter to avoid duplicate delivery caused
1390 * by packets matching multiple filters.
1392 ef10_filter_remove_old(enp);
1395 rc = ef10_filter_insert_all_multicast(enp,
1398 rc = ef10_filter_insert_multicast_list(enp,
1400 addrs, count, filter_flags, B_FALSE);
1407 /* Remove old filters which were not renewed */
1408 ef10_filter_remove_old(enp);
1410 /* report if any optional flags were rejected */
1411 if (((all_unicst != B_FALSE) && (all_unicst_rc != 0)) ||
1412 ((all_mulcst != B_FALSE) && (all_mulcst_rc != 0))) {
1425 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1427 /* Clear auto old flags */
1428 for (i = 0; i < EFX_ARRAY_SIZE(table->eft_entry); i++) {
1429 if (ef10_filter_entry_is_auto_old(table, i)) {
1430 ef10_filter_set_entry_not_auto_old(table, i);
1438 ef10_filter_get_default_rxq(
1439 __in efx_nic_t *enp,
1440 __out efx_rxq_t **erpp,
1441 __out boolean_t *using_rss)
1443 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
1445 *erpp = table->eft_default_rxq;
1446 *using_rss = table->eft_using_rss;
1451 ef10_filter_default_rxq_set(
1452 __in efx_nic_t *enp,
1453 __in efx_rxq_t *erp,
1454 __in boolean_t using_rss)
1456 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
1458 #if EFSYS_OPT_RX_SCALE
1459 EFSYS_ASSERT((using_rss == B_FALSE) ||
1460 (enp->en_rss_context != EF10_RSS_CONTEXT_INVALID));
1461 table->eft_using_rss = using_rss;
1463 EFSYS_ASSERT(using_rss == B_FALSE);
1464 table->eft_using_rss = B_FALSE;
1466 table->eft_default_rxq = erp;
1470 ef10_filter_default_rxq_clear(
1471 __in efx_nic_t *enp)
1473 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
1475 table->eft_default_rxq = NULL;
1476 table->eft_using_rss = B_FALSE;
1480 #endif /* EFSYS_OPT_FILTER */
1482 #endif /* EFSYS_OPT_HUNTINGTON || EFSYS_OPT_MEDFORD */