2 * Copyright (c) 2007-2015 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
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(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_unicast_refresh(
987 __in_ecount(6) uint8_t const *addr,
988 __in boolean_t all_unicst,
989 __in efx_filter_flag_t filter_flags)
991 ef10_filter_table_t *eftp = enp->en_filter.ef_ef10_filter_table;
992 efx_filter_spec_t spec;
995 if (all_unicst == B_TRUE)
998 /* Insert the filter for the local station address */
999 efx_filter_spec_init_rx(&spec, EFX_FILTER_PRI_AUTO,
1001 eftp->eft_default_rxq);
1002 efx_filter_spec_set_eth_local(&spec, EFX_FILTER_SPEC_VID_UNSPEC, addr);
1004 rc = ef10_filter_add_internal(enp, &spec, B_TRUE,
1005 &eftp->eft_unicst_filter_index);
1008 * Fall back to an unknown filter. We may be able to subscribe
1009 * to it even if we couldn't insert the unicast filter.
1013 eftp->eft_unicst_filter_set = B_TRUE;
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_index);
1028 eftp->eft_unicst_filter_set = B_TRUE;
1033 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1035 if (eftp->eft_unicst_filter_set != B_FALSE) {
1036 (void) ef10_filter_delete_internal(enp,
1037 eftp->eft_unicst_filter_index);
1039 eftp->eft_unicst_filter_set = B_FALSE;
1045 static __checkReturn efx_rc_t
1046 ef10_filter_multicast_refresh(
1047 __in efx_nic_t *enp,
1048 __in boolean_t mulcst,
1049 __in boolean_t all_mulcst,
1050 __in boolean_t brdcst,
1051 __in_ecount(6*count) uint8_t const *addrs,
1053 __in efx_filter_flag_t filter_flags)
1055 ef10_filter_table_t *eftp = enp->en_filter.ef_ef10_filter_table;
1056 efx_filter_spec_t spec;
1061 if (all_mulcst == B_TRUE)
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; use unknown multicast filter */
1073 /* Insert/renew multicast address list filters */
1074 eftp->eft_mulcst_filter_count = count;
1075 for (i = 0; i < eftp->eft_mulcst_filter_count; i++) {
1076 efx_filter_spec_init_rx(&spec,
1077 EFX_FILTER_PRI_AUTO,
1079 eftp->eft_default_rxq);
1081 efx_filter_spec_set_eth_local(&spec,
1082 EFX_FILTER_SPEC_VID_UNSPEC,
1083 &addrs[i * EFX_MAC_ADDR_LEN]);
1085 rc = ef10_filter_add_internal(enp, &spec, B_TRUE,
1086 &eftp->eft_mulcst_filter_indexes[i]);
1088 /* Rollback, then use unknown multicast filter */
1093 if (brdcst == B_TRUE) {
1094 /* Insert/renew broadcast address filter */
1095 eftp->eft_mulcst_filter_count++;
1096 efx_filter_spec_init_rx(&spec, EFX_FILTER_PRI_AUTO,
1098 eftp->eft_default_rxq);
1100 EFX_MAC_BROADCAST_ADDR_SET(addr);
1101 efx_filter_spec_set_eth_local(&spec, EFX_FILTER_SPEC_VID_UNSPEC,
1104 rc = ef10_filter_add_internal(enp, &spec, B_TRUE,
1105 &eftp->eft_mulcst_filter_indexes[
1106 eftp->eft_mulcst_filter_count - 1]);
1108 /* Rollback, then use unknown multicast filter */
1117 * Rollback by removing any filters we have inserted
1118 * before inserting the unknown multicast filter.
1121 (void) ef10_filter_delete_internal(enp,
1122 eftp->eft_mulcst_filter_indexes[i]);
1124 eftp->eft_mulcst_filter_count = 0;
1127 /* Insert the unknown multicast filter */
1128 efx_filter_spec_init_rx(&spec, EFX_FILTER_PRI_AUTO,
1130 eftp->eft_default_rxq);
1131 efx_filter_spec_set_mc_def(&spec);
1133 rc = ef10_filter_add_internal(enp, &spec, B_TRUE,
1134 &eftp->eft_mulcst_filter_indexes[0]);
1138 eftp->eft_mulcst_filter_count = 1;
1141 * FIXME: If brdcst == B_FALSE, add a filter to drop broadcast traffic.
1147 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1154 static __checkReturn efx_rc_t
1155 hunt_filter_get_workarounds(
1156 __in efx_nic_t *enp)
1158 efx_nic_cfg_t *encp = &enp->en_nic_cfg;
1159 uint32_t implemented = 0;
1160 uint32_t enabled = 0;
1163 rc = efx_mcdi_get_workarounds(enp, &implemented, &enabled);
1165 /* Check if chained multicast filter support is enabled */
1166 if (implemented & enabled & MC_CMD_GET_WORKAROUNDS_OUT_BUG26807)
1167 encp->enc_bug26807_workaround = B_TRUE;
1169 encp->enc_bug26807_workaround = B_FALSE;
1170 } else if (rc == ENOTSUP) {
1172 * Firmware is too old to support GET_WORKAROUNDS, and support
1173 * for this workaround was implemented later.
1175 encp->enc_bug26807_workaround = B_FALSE;
1183 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1191 * Reconfigure all filters.
1192 * If all_unicst and/or all mulcst filters cannot be applied then
1193 * return ENOTSUP (Note the filters for the specified addresses are
1194 * still applied in this case).
1196 __checkReturn efx_rc_t
1197 ef10_filter_reconfigure(
1198 __in efx_nic_t *enp,
1199 __in_ecount(6) uint8_t const *mac_addr,
1200 __in boolean_t all_unicst,
1201 __in boolean_t mulcst,
1202 __in boolean_t all_mulcst,
1203 __in boolean_t brdcst,
1204 __in_ecount(6*count) uint8_t const *addrs,
1207 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
1208 efx_filter_flag_t filter_flags;
1214 if (table->eft_default_rxq == NULL) {
1216 * Filters direct traffic to the default RXQ, and so cannot be
1217 * inserted until it is available. Any currently configured
1218 * filters must be removed (ignore errors in case the MC
1219 * has rebooted, which removes hardware filters).
1221 if (table->eft_unicst_filter_set != B_FALSE) {
1222 (void) ef10_filter_delete_internal(enp,
1223 table->eft_unicst_filter_index);
1224 table->eft_unicst_filter_set = B_FALSE;
1226 for (i = 0; i < table->eft_mulcst_filter_count; i++) {
1227 (void) ef10_filter_delete_internal(enp,
1228 table->eft_mulcst_filter_indexes[i]);
1230 table->eft_mulcst_filter_count = 0;
1235 if (table->eft_using_rss)
1236 filter_flags = EFX_FILTER_FLAG_RX_RSS;
1240 /* Mark old filters which may need to be removed */
1241 if (table->eft_unicst_filter_set != B_FALSE) {
1242 ef10_filter_set_entry_auto_old(table,
1243 table->eft_unicst_filter_index);
1245 for (i = 0; i < table->eft_mulcst_filter_count; i++) {
1246 ef10_filter_set_entry_auto_old(table,
1247 table->eft_mulcst_filter_indexes[i]);
1250 /* Insert or renew unicast filters */
1251 if ((all_unicst_rc = ef10_filter_unicast_refresh(enp, mac_addr,
1252 all_unicst, filter_flags)) != 0) {
1253 if (all_unicst == B_FALSE) {
1257 /* Retry without all_unicast flag */
1258 rc = ef10_filter_unicast_refresh(enp, mac_addr,
1259 B_FALSE, filter_flags);
1265 * WORKAROUND_BUG26807 controls firmware support for chained multicast
1266 * filters, and can only be enabled or disabled when the hardware filter
1269 * Firmware will reset (FLR) functions which have inserted filters in
1270 * the hardware filter table when the workaround is enabled/disabled.
1271 * Functions without any hardware filters are not reset.
1273 * Re-check if the workaround is enabled after adding unicast hardware
1274 * filters. This ensures that encp->enc_workaround_bug26807 matches the
1275 * firmware state, and that later changes to enable/disable the
1276 * workaround will result in this function seeing a reset (FLR).
1278 * FIXME: On Medford mulicast chaining should always be on.
1280 if ((rc = hunt_filter_get_workarounds(enp)) != 0)
1283 /* Insert or renew multicast filters */
1284 if ((all_mulcst_rc = ef10_filter_multicast_refresh(enp, mulcst,
1286 addrs, count, filter_flags)) != 0) {
1287 if (all_mulcst == B_FALSE) {
1291 /* Retry without all_mulcast flag */
1292 rc = ef10_filter_multicast_refresh(enp, mulcst,
1294 addrs, count, filter_flags);
1299 /* Remove old filters which were not renewed */
1300 for (i = 0; i < EFX_ARRAY_SIZE(table->eft_entry); i++) {
1301 if (ef10_filter_entry_is_auto_old(table, i)) {
1302 (void) ef10_filter_delete_internal(enp, i);
1306 /* report if any optional flags were rejected */
1307 if (((all_unicst != B_FALSE) && (all_unicst_rc != 0)) ||
1308 ((all_mulcst != B_FALSE) && (all_mulcst_rc != 0))) {
1323 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1325 /* Clear auto old flags */
1326 for (i = 0; i < EFX_ARRAY_SIZE(table->eft_entry); i++) {
1327 if (ef10_filter_entry_is_auto_old(table, i)) {
1328 ef10_filter_set_entry_not_auto_old(table, i);
1336 ef10_filter_get_default_rxq(
1337 __in efx_nic_t *enp,
1338 __out efx_rxq_t **erpp,
1339 __out boolean_t *using_rss)
1341 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
1343 *erpp = table->eft_default_rxq;
1344 *using_rss = table->eft_using_rss;
1349 ef10_filter_default_rxq_set(
1350 __in efx_nic_t *enp,
1351 __in efx_rxq_t *erp,
1352 __in boolean_t using_rss)
1354 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
1356 #if EFSYS_OPT_RX_SCALE
1357 EFSYS_ASSERT((using_rss == B_FALSE) ||
1358 (enp->en_rss_context != EF10_RSS_CONTEXT_INVALID));
1359 table->eft_using_rss = using_rss;
1361 EFSYS_ASSERT(using_rss == B_FALSE);
1362 table->eft_using_rss = B_FALSE;
1364 table->eft_default_rxq = erp;
1368 ef10_filter_default_rxq_clear(
1369 __in efx_nic_t *enp)
1371 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
1373 table->eft_default_rxq = NULL;
1374 table->eft_using_rss = B_FALSE;
1378 #endif /* EFSYS_OPT_FILTER */
1380 #endif /* EFSYS_OPT_HUNTINGTON */