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));
145 EFX_STATIC_ASSERT(EFX_FILTER_MATCH_UNKNOWN_MCAST_DST ==
146 MATCH_MASK(MC_CMD_FILTER_OP_IN_MATCH_UNKNOWN_MCAST_DST));
147 EFX_STATIC_ASSERT((uint32_t)EFX_FILTER_MATCH_UNKNOWN_UCAST_DST ==
148 MATCH_MASK(MC_CMD_FILTER_OP_IN_MATCH_UNKNOWN_UCAST_DST));
151 EFSYS_KMEM_ALLOC(enp->en_esip, sizeof (ef10_filter_table_t), eftp);
158 enp->en_filter.ef_ef10_filter_table = eftp;
163 EFSYS_PROBE1(fail1, efx_rc_t, rc);
172 EFSYS_ASSERT(enp->en_family == EFX_FAMILY_HUNTINGTON ||
173 enp->en_family == EFX_FAMILY_MEDFORD);
175 if (enp->en_filter.ef_ef10_filter_table != NULL) {
176 EFSYS_KMEM_FREE(enp->en_esip, sizeof (ef10_filter_table_t),
177 enp->en_filter.ef_ef10_filter_table);
181 static __checkReturn efx_rc_t
182 efx_mcdi_filter_op_add(
184 __in efx_filter_spec_t *spec,
185 __in unsigned int filter_op,
186 __inout ef10_filter_handle_t *handle)
189 uint8_t payload[MAX(MC_CMD_FILTER_OP_IN_LEN,
190 MC_CMD_FILTER_OP_OUT_LEN)];
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 MCDI_IN_SET_DWORD(req, FILTER_OP_IN_PORT_ID,
218 EVB_PORT_ID_ASSIGNED);
219 MCDI_IN_SET_DWORD(req, FILTER_OP_IN_MATCH_FIELDS,
220 spec->efs_match_flags);
221 MCDI_IN_SET_DWORD(req, FILTER_OP_IN_RX_DEST,
222 MC_CMD_FILTER_OP_IN_RX_DEST_HOST);
223 MCDI_IN_SET_DWORD(req, FILTER_OP_IN_RX_QUEUE,
225 if (spec->efs_flags & EFX_FILTER_FLAG_RX_RSS) {
226 MCDI_IN_SET_DWORD(req, FILTER_OP_IN_RX_CONTEXT,
227 spec->efs_rss_context);
229 MCDI_IN_SET_DWORD(req, FILTER_OP_IN_RX_MODE,
230 spec->efs_flags & EFX_FILTER_FLAG_RX_RSS ?
231 MC_CMD_FILTER_OP_IN_RX_MODE_RSS :
232 MC_CMD_FILTER_OP_IN_RX_MODE_SIMPLE);
233 MCDI_IN_SET_DWORD(req, FILTER_OP_IN_TX_DEST,
234 MC_CMD_FILTER_OP_IN_TX_DEST_DEFAULT);
236 if (filter_op != MC_CMD_FILTER_OP_IN_OP_REPLACE) {
238 * NOTE: Unlike most MCDI requests, the filter fields
239 * are presented in network (big endian) byte order.
241 memcpy(MCDI_IN2(req, uint8_t, FILTER_OP_IN_SRC_MAC),
242 spec->efs_rem_mac, EFX_MAC_ADDR_LEN);
243 memcpy(MCDI_IN2(req, uint8_t, FILTER_OP_IN_DST_MAC),
244 spec->efs_loc_mac, EFX_MAC_ADDR_LEN);
246 MCDI_IN_SET_WORD(req, FILTER_OP_IN_SRC_PORT,
247 __CPU_TO_BE_16(spec->efs_rem_port));
248 MCDI_IN_SET_WORD(req, FILTER_OP_IN_DST_PORT,
249 __CPU_TO_BE_16(spec->efs_loc_port));
251 MCDI_IN_SET_WORD(req, FILTER_OP_IN_ETHER_TYPE,
252 __CPU_TO_BE_16(spec->efs_ether_type));
254 MCDI_IN_SET_WORD(req, FILTER_OP_IN_INNER_VLAN,
255 __CPU_TO_BE_16(spec->efs_inner_vid));
256 MCDI_IN_SET_WORD(req, FILTER_OP_IN_OUTER_VLAN,
257 __CPU_TO_BE_16(spec->efs_outer_vid));
259 /* IP protocol (in low byte, high byte is zero) */
260 MCDI_IN_SET_BYTE(req, FILTER_OP_IN_IP_PROTO,
263 EFX_STATIC_ASSERT(sizeof (spec->efs_rem_host) ==
264 MC_CMD_FILTER_OP_IN_SRC_IP_LEN);
265 EFX_STATIC_ASSERT(sizeof (spec->efs_loc_host) ==
266 MC_CMD_FILTER_OP_IN_DST_IP_LEN);
268 memcpy(MCDI_IN2(req, uint8_t, FILTER_OP_IN_SRC_IP),
269 &spec->efs_rem_host.eo_byte[0],
270 MC_CMD_FILTER_OP_IN_SRC_IP_LEN);
271 memcpy(MCDI_IN2(req, uint8_t, FILTER_OP_IN_DST_IP),
272 &spec->efs_loc_host.eo_byte[0],
273 MC_CMD_FILTER_OP_IN_DST_IP_LEN);
276 efx_mcdi_execute(enp, &req);
278 if (req.emr_rc != 0) {
283 if (req.emr_out_length_used < MC_CMD_FILTER_OP_OUT_LEN) {
288 handle->efh_lo = MCDI_OUT_DWORD(req, FILTER_OP_OUT_HANDLE_LO);
289 handle->efh_hi = MCDI_OUT_DWORD(req, FILTER_OP_OUT_HANDLE_HI);
298 EFSYS_PROBE1(fail1, efx_rc_t, rc);
304 static __checkReturn efx_rc_t
305 efx_mcdi_filter_op_delete(
307 __in unsigned int filter_op,
308 __inout ef10_filter_handle_t *handle)
311 uint8_t payload[MAX(MC_CMD_FILTER_OP_IN_LEN,
312 MC_CMD_FILTER_OP_OUT_LEN)];
315 memset(payload, 0, sizeof (payload));
316 req.emr_cmd = MC_CMD_FILTER_OP;
317 req.emr_in_buf = payload;
318 req.emr_in_length = MC_CMD_FILTER_OP_IN_LEN;
319 req.emr_out_buf = payload;
320 req.emr_out_length = MC_CMD_FILTER_OP_OUT_LEN;
323 case MC_CMD_FILTER_OP_IN_OP_REMOVE:
324 MCDI_IN_SET_DWORD(req, FILTER_OP_IN_OP,
325 MC_CMD_FILTER_OP_IN_OP_REMOVE);
327 case MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE:
328 MCDI_IN_SET_DWORD(req, FILTER_OP_IN_OP,
329 MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE);
337 MCDI_IN_SET_DWORD(req, FILTER_OP_IN_HANDLE_LO, handle->efh_lo);
338 MCDI_IN_SET_DWORD(req, FILTER_OP_IN_HANDLE_HI, handle->efh_hi);
340 efx_mcdi_execute_quiet(enp, &req);
342 if (req.emr_rc != 0) {
347 if (req.emr_out_length_used < MC_CMD_FILTER_OP_OUT_LEN) {
360 EFSYS_PROBE1(fail1, efx_rc_t, rc);
365 static __checkReturn boolean_t
367 __in const efx_filter_spec_t *left,
368 __in const efx_filter_spec_t *right)
370 /* FIXME: Consider rx vs tx filters (look at efs_flags) */
371 if (left->efs_match_flags != right->efs_match_flags)
373 if (!EFX_OWORD_IS_EQUAL(left->efs_rem_host, right->efs_rem_host))
375 if (!EFX_OWORD_IS_EQUAL(left->efs_loc_host, right->efs_loc_host))
377 if (memcmp(left->efs_rem_mac, right->efs_rem_mac, EFX_MAC_ADDR_LEN))
379 if (memcmp(left->efs_loc_mac, right->efs_loc_mac, EFX_MAC_ADDR_LEN))
381 if (left->efs_rem_port != right->efs_rem_port)
383 if (left->efs_loc_port != right->efs_loc_port)
385 if (left->efs_inner_vid != right->efs_inner_vid)
387 if (left->efs_outer_vid != right->efs_outer_vid)
389 if (left->efs_ether_type != right->efs_ether_type)
391 if (left->efs_ip_proto != right->efs_ip_proto)
398 static __checkReturn boolean_t
399 ef10_filter_same_dest(
400 __in const efx_filter_spec_t *left,
401 __in const efx_filter_spec_t *right)
403 if ((left->efs_flags & EFX_FILTER_FLAG_RX_RSS) &&
404 (right->efs_flags & EFX_FILTER_FLAG_RX_RSS)) {
405 if (left->efs_rss_context == right->efs_rss_context)
407 } else if ((~(left->efs_flags) & EFX_FILTER_FLAG_RX_RSS) &&
408 (~(right->efs_flags) & EFX_FILTER_FLAG_RX_RSS)) {
409 if (left->efs_dmaq_id == right->efs_dmaq_id)
415 static __checkReturn uint32_t
417 __in efx_filter_spec_t *spec)
419 EFX_STATIC_ASSERT((sizeof (efx_filter_spec_t) % sizeof (uint32_t))
421 EFX_STATIC_ASSERT((EFX_FIELD_OFFSET(efx_filter_spec_t, efs_outer_vid) %
422 sizeof (uint32_t)) == 0);
425 * As the area of the efx_filter_spec_t we need to hash is DWORD
426 * aligned and an exact number of DWORDs in size we can use the
427 * optimised efx_hash_dwords() rather than efx_hash_bytes()
429 return (efx_hash_dwords((const uint32_t *)&spec->efs_outer_vid,
430 (sizeof (efx_filter_spec_t) -
431 EFX_FIELD_OFFSET(efx_filter_spec_t, efs_outer_vid)) /
432 sizeof (uint32_t), 0));
436 * Decide whether a filter should be exclusive or else should allow
437 * delivery to additional recipients. Currently we decide that
438 * filters for specific local unicast MAC and IP addresses are
441 static __checkReturn boolean_t
442 ef10_filter_is_exclusive(
443 __in efx_filter_spec_t *spec)
445 if ((spec->efs_match_flags & EFX_FILTER_MATCH_LOC_MAC) &&
446 !EFX_MAC_ADDR_IS_MULTICAST(spec->efs_loc_mac))
449 if ((spec->efs_match_flags &
450 (EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_LOC_HOST)) ==
451 (EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_LOC_HOST)) {
452 if ((spec->efs_ether_type == EFX_ETHER_TYPE_IPV4) &&
453 ((spec->efs_loc_host.eo_u8[0] & 0xf) != 0xe))
455 if ((spec->efs_ether_type == EFX_ETHER_TYPE_IPV6) &&
456 (spec->efs_loc_host.eo_u8[0] != 0xff))
463 __checkReturn efx_rc_t
468 efx_filter_spec_t *spec;
469 ef10_filter_table_t *eftp = enp->en_filter.ef_ef10_filter_table;
471 efsys_lock_state_t state;
474 EFSYS_ASSERT(enp->en_family == EFX_FAMILY_HUNTINGTON ||
475 enp->en_family == EFX_FAMILY_MEDFORD);
477 for (tbl_id = 0; tbl_id < EFX_EF10_FILTER_TBL_ROWS; tbl_id++) {
479 EFSYS_LOCK(enp->en_eslp, state);
481 spec = ef10_filter_entry_spec(eftp, tbl_id);
484 } else if (ef10_filter_entry_is_busy(eftp, tbl_id)) {
485 /* Ignore busy entries. */
488 ef10_filter_set_entry_busy(eftp, tbl_id);
492 EFSYS_UNLOCK(enp->en_eslp, state);
494 if (restoring == B_FALSE)
497 if (ef10_filter_is_exclusive(spec)) {
498 rc = efx_mcdi_filter_op_add(enp, spec,
499 MC_CMD_FILTER_OP_IN_OP_INSERT,
500 &eftp->eft_entry[tbl_id].efe_handle);
502 rc = efx_mcdi_filter_op_add(enp, spec,
503 MC_CMD_FILTER_OP_IN_OP_SUBSCRIBE,
504 &eftp->eft_entry[tbl_id].efe_handle);
510 EFSYS_LOCK(enp->en_eslp, state);
512 ef10_filter_set_entry_not_busy(eftp, tbl_id);
514 EFSYS_UNLOCK(enp->en_eslp, state);
520 EFSYS_PROBE1(fail1, efx_rc_t, rc);
526 * An arbitrary search limit for the software hash table. As per the linux net
529 #define EF10_FILTER_SEARCH_LIMIT 200
531 static __checkReturn efx_rc_t
532 ef10_filter_add_internal(
534 __inout efx_filter_spec_t *spec,
535 __in boolean_t may_replace,
536 __out_opt uint32_t *filter_id)
539 ef10_filter_table_t *eftp = enp->en_filter.ef_ef10_filter_table;
540 efx_filter_spec_t *saved_spec;
544 boolean_t replacing = B_FALSE;
546 efsys_lock_state_t state;
547 boolean_t locked = B_FALSE;
549 EFSYS_ASSERT(enp->en_family == EFX_FAMILY_HUNTINGTON ||
550 enp->en_family == EFX_FAMILY_MEDFORD);
552 #if EFSYS_OPT_RX_SCALE
553 spec->efs_rss_context = enp->en_rss_context;
556 hash = ef10_filter_hash(spec);
559 * FIXME: Add support for inserting filters of different priorities
560 * and removing lower priority multicast filters (bug 42378)
564 * Find any existing filters with the same match tuple or
565 * else a free slot to insert at. If any of them are busy,
566 * we have to wait and retry.
571 EFSYS_LOCK(enp->en_eslp, state);
575 i = (hash + depth) & (EFX_EF10_FILTER_TBL_ROWS - 1);
576 saved_spec = ef10_filter_entry_spec(eftp, i);
582 } else if (ef10_filter_equal(spec, saved_spec)) {
583 if (ef10_filter_entry_is_busy(eftp, i))
585 if (saved_spec->efs_priority
586 == EFX_FILTER_PRI_AUTO) {
589 } else if (ef10_filter_is_exclusive(spec)) {
603 * Once we reach the maximum search depth, use
604 * the first suitable slot or return EBUSY if
607 if (depth == EF10_FILTER_SEARCH_LIMIT) {
616 EFSYS_UNLOCK(enp->en_eslp, state);
622 * Create a software table entry if necessary, and mark it
623 * busy. We might yet fail to insert, but any attempt to
624 * insert a conflicting filter while we're waiting for the
625 * firmware must find the busy entry.
627 saved_spec = ef10_filter_entry_spec(eftp, ins_index);
629 if (saved_spec->efs_priority == EFX_FILTER_PRI_AUTO) {
630 /* This is a filter we are refreshing */
631 ef10_filter_set_entry_not_auto_old(eftp, ins_index);
637 EFSYS_KMEM_ALLOC(enp->en_esip, sizeof (*spec), saved_spec);
643 ef10_filter_set_entry(eftp, ins_index, saved_spec);
645 ef10_filter_set_entry_busy(eftp, ins_index);
647 EFSYS_UNLOCK(enp->en_eslp, state);
651 * On replacing the filter handle may change after after a successful
655 rc = efx_mcdi_filter_op_add(enp, spec,
656 MC_CMD_FILTER_OP_IN_OP_REPLACE,
657 &eftp->eft_entry[ins_index].efe_handle);
658 } else if (ef10_filter_is_exclusive(spec)) {
659 rc = efx_mcdi_filter_op_add(enp, spec,
660 MC_CMD_FILTER_OP_IN_OP_INSERT,
661 &eftp->eft_entry[ins_index].efe_handle);
663 rc = efx_mcdi_filter_op_add(enp, spec,
664 MC_CMD_FILTER_OP_IN_OP_SUBSCRIBE,
665 &eftp->eft_entry[ins_index].efe_handle);
671 EFSYS_LOCK(enp->en_eslp, state);
675 /* Update the fields that may differ */
676 saved_spec->efs_priority = spec->efs_priority;
677 saved_spec->efs_flags = spec->efs_flags;
678 saved_spec->efs_rss_context = spec->efs_rss_context;
679 saved_spec->efs_dmaq_id = spec->efs_dmaq_id;
682 ef10_filter_set_entry_not_busy(eftp, ins_index);
686 EFSYS_UNLOCK(enp->en_eslp, state);
690 *filter_id = ins_index;
698 EFSYS_KMEM_FREE(enp->en_esip, sizeof (*spec), saved_spec);
701 ef10_filter_set_entry_not_busy(eftp, ins_index);
702 ef10_filter_set_entry(eftp, ins_index, NULL);
711 EFSYS_PROBE1(fail1, efx_rc_t, rc);
714 EFSYS_UNLOCK(enp->en_eslp, state);
719 __checkReturn efx_rc_t
722 __inout efx_filter_spec_t *spec,
723 __in boolean_t may_replace)
727 rc = ef10_filter_add_internal(enp, spec, may_replace, NULL);
734 EFSYS_PROBE1(fail1, efx_rc_t, rc);
740 static __checkReturn efx_rc_t
741 ef10_filter_delete_internal(
743 __in uint32_t filter_id)
746 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
747 efx_filter_spec_t *spec;
748 efsys_lock_state_t state;
749 uint32_t filter_idx = filter_id % EFX_EF10_FILTER_TBL_ROWS;
752 * Find the software table entry and mark it busy. Don't
753 * remove it yet; any attempt to update while we're waiting
754 * for the firmware must find the busy entry.
756 * FIXME: What if the busy flag is never cleared?
758 EFSYS_LOCK(enp->en_eslp, state);
759 while (ef10_filter_entry_is_busy(table, filter_idx)) {
760 EFSYS_UNLOCK(enp->en_eslp, state);
762 EFSYS_LOCK(enp->en_eslp, state);
764 if ((spec = ef10_filter_entry_spec(table, filter_idx)) != NULL) {
765 ef10_filter_set_entry_busy(table, filter_idx);
767 EFSYS_UNLOCK(enp->en_eslp, state);
775 * Try to remove the hardware filter. This may fail if the MC has
776 * rebooted (which frees all hardware filter resources).
778 if (ef10_filter_is_exclusive(spec)) {
779 rc = efx_mcdi_filter_op_delete(enp,
780 MC_CMD_FILTER_OP_IN_OP_REMOVE,
781 &table->eft_entry[filter_idx].efe_handle);
783 rc = efx_mcdi_filter_op_delete(enp,
784 MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE,
785 &table->eft_entry[filter_idx].efe_handle);
788 /* Free the software table entry */
789 EFSYS_LOCK(enp->en_eslp, state);
790 ef10_filter_set_entry_not_busy(table, filter_idx);
791 ef10_filter_set_entry(table, filter_idx, NULL);
792 EFSYS_UNLOCK(enp->en_eslp, state);
794 EFSYS_KMEM_FREE(enp->en_esip, sizeof (*spec), spec);
796 /* Check result of hardware filter removal */
806 EFSYS_PROBE1(fail1, efx_rc_t, rc);
811 __checkReturn efx_rc_t
814 __inout efx_filter_spec_t *spec)
817 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
818 efx_filter_spec_t *saved_spec;
822 efsys_lock_state_t state;
823 boolean_t locked = B_FALSE;
825 EFSYS_ASSERT(enp->en_family == EFX_FAMILY_HUNTINGTON ||
826 enp->en_family == EFX_FAMILY_MEDFORD);
828 hash = ef10_filter_hash(spec);
830 EFSYS_LOCK(enp->en_eslp, state);
835 i = (hash + depth) & (EFX_EF10_FILTER_TBL_ROWS - 1);
836 saved_spec = ef10_filter_entry_spec(table, i);
837 if (saved_spec && ef10_filter_equal(spec, saved_spec) &&
838 ef10_filter_same_dest(spec, saved_spec)) {
841 if (depth == EF10_FILTER_SEARCH_LIMIT) {
848 EFSYS_UNLOCK(enp->en_eslp, state);
851 rc = ef10_filter_delete_internal(enp, i);
861 EFSYS_PROBE1(fail1, efx_rc_t, rc);
864 EFSYS_UNLOCK(enp->en_eslp, state);
869 static __checkReturn efx_rc_t
870 efx_mcdi_get_parser_disp_info(
872 __out uint32_t *list,
873 __out size_t *length)
876 uint8_t payload[MAX(MC_CMD_GET_PARSER_DISP_INFO_IN_LEN,
877 MC_CMD_GET_PARSER_DISP_INFO_OUT_LENMAX)];
880 (void) memset(payload, 0, sizeof (payload));
881 req.emr_cmd = MC_CMD_GET_PARSER_DISP_INFO;
882 req.emr_in_buf = payload;
883 req.emr_in_length = MC_CMD_GET_PARSER_DISP_INFO_IN_LEN;
884 req.emr_out_buf = payload;
885 req.emr_out_length = MC_CMD_GET_PARSER_DISP_INFO_OUT_LENMAX;
887 MCDI_IN_SET_DWORD(req, GET_PARSER_DISP_INFO_OUT_OP,
888 MC_CMD_GET_PARSER_DISP_INFO_IN_OP_GET_SUPPORTED_RX_MATCHES);
890 efx_mcdi_execute(enp, &req);
892 if (req.emr_rc != 0) {
897 *length = MCDI_OUT_DWORD(req,
898 GET_PARSER_DISP_INFO_OUT_NUM_SUPPORTED_MATCHES);
900 if (req.emr_out_length_used <
901 MC_CMD_GET_PARSER_DISP_INFO_OUT_LEN(*length)) {
909 GET_PARSER_DISP_INFO_OUT_SUPPORTED_MATCHES),
910 (*length) * sizeof (uint32_t));
911 EFX_STATIC_ASSERT(sizeof (uint32_t) ==
912 MC_CMD_GET_PARSER_DISP_INFO_OUT_SUPPORTED_MATCHES_LEN);
919 EFSYS_PROBE1(fail1, efx_rc_t, rc);
924 __checkReturn efx_rc_t
925 ef10_filter_supported_filters(
927 __out uint32_t *list,
928 __out size_t *length)
932 if ((rc = efx_mcdi_get_parser_disp_info(enp, list, length)) != 0)
938 EFSYS_PROBE1(fail1, efx_rc_t, rc);
943 static __checkReturn efx_rc_t
944 ef10_filter_insert_unicast(
946 __in_ecount(6) uint8_t const *addr,
947 __in efx_filter_flags_t filter_flags)
949 ef10_filter_table_t *eftp = enp->en_filter.ef_ef10_filter_table;
950 efx_filter_spec_t spec;
953 /* Insert the filter for the local station address */
954 efx_filter_spec_init_rx(&spec, EFX_FILTER_PRI_AUTO,
956 eftp->eft_default_rxq);
957 efx_filter_spec_set_eth_local(&spec, EFX_FILTER_SPEC_VID_UNSPEC, addr);
959 rc = ef10_filter_add_internal(enp, &spec, B_TRUE,
960 &eftp->eft_unicst_filter_indexes[eftp->eft_unicst_filter_count]);
964 eftp->eft_unicst_filter_count++;
965 EFSYS_ASSERT(eftp->eft_unicst_filter_count <=
966 EFX_EF10_FILTER_UNICAST_FILTERS_MAX);
971 EFSYS_PROBE1(fail1, efx_rc_t, rc);
975 static __checkReturn efx_rc_t
976 ef10_filter_insert_all_unicast(
978 __in efx_filter_flags_t filter_flags)
980 ef10_filter_table_t *eftp = enp->en_filter.ef_ef10_filter_table;
981 efx_filter_spec_t spec;
984 /* Insert the unknown unicast filter */
985 efx_filter_spec_init_rx(&spec, EFX_FILTER_PRI_AUTO,
987 eftp->eft_default_rxq);
988 efx_filter_spec_set_uc_def(&spec);
989 rc = ef10_filter_add_internal(enp, &spec, B_TRUE,
990 &eftp->eft_unicst_filter_indexes[eftp->eft_unicst_filter_count]);
994 eftp->eft_unicst_filter_count++;
995 EFSYS_ASSERT(eftp->eft_unicst_filter_count <=
996 EFX_EF10_FILTER_UNICAST_FILTERS_MAX);
1001 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1005 static __checkReturn efx_rc_t
1006 ef10_filter_insert_multicast_list(
1007 __in efx_nic_t *enp,
1008 __in boolean_t mulcst,
1009 __in boolean_t brdcst,
1010 __in_ecount(6*count) uint8_t const *addrs,
1011 __in uint32_t count,
1012 __in efx_filter_flags_t filter_flags,
1013 __in boolean_t rollback)
1015 ef10_filter_table_t *eftp = enp->en_filter.ef_ef10_filter_table;
1016 efx_filter_spec_t spec;
1019 uint32_t filter_index;
1020 uint32_t filter_count;
1023 if (mulcst == B_FALSE)
1026 if (count + (brdcst ? 1 : 0) >
1027 EFX_ARRAY_SIZE(eftp->eft_mulcst_filter_indexes)) {
1028 /* Too many MAC addresses */
1033 /* Insert/renew multicast address list filters */
1035 for (i = 0; i < count; i++) {
1036 efx_filter_spec_init_rx(&spec,
1037 EFX_FILTER_PRI_AUTO,
1039 eftp->eft_default_rxq);
1041 efx_filter_spec_set_eth_local(&spec,
1042 EFX_FILTER_SPEC_VID_UNSPEC,
1043 &addrs[i * EFX_MAC_ADDR_LEN]);
1045 rc = ef10_filter_add_internal(enp, &spec, B_TRUE,
1049 eftp->eft_mulcst_filter_indexes[filter_count] =
1052 } else if (rollback == B_TRUE) {
1053 /* Only stop upon failure if told to rollback */
1059 if (brdcst == B_TRUE) {
1060 /* Insert/renew broadcast address filter */
1061 efx_filter_spec_init_rx(&spec, EFX_FILTER_PRI_AUTO,
1063 eftp->eft_default_rxq);
1065 EFX_MAC_BROADCAST_ADDR_SET(addr);
1066 efx_filter_spec_set_eth_local(&spec, EFX_FILTER_SPEC_VID_UNSPEC,
1069 rc = ef10_filter_add_internal(enp, &spec, B_TRUE,
1073 eftp->eft_mulcst_filter_indexes[filter_count] =
1076 } else if (rollback == B_TRUE) {
1077 /* Only stop upon failure if told to rollback */
1082 eftp->eft_mulcst_filter_count = filter_count;
1083 eftp->eft_using_all_mulcst = B_FALSE;
1088 /* Remove any filters we have inserted */
1091 (void) ef10_filter_delete_internal(enp,
1092 eftp->eft_mulcst_filter_indexes[i]);
1094 eftp->eft_mulcst_filter_count = 0;
1097 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1102 static __checkReturn efx_rc_t
1103 ef10_filter_insert_all_multicast(
1104 __in efx_nic_t *enp,
1105 __in efx_filter_flags_t filter_flags)
1107 ef10_filter_table_t *eftp = enp->en_filter.ef_ef10_filter_table;
1108 efx_filter_spec_t spec;
1111 /* Insert the unknown multicast filter */
1112 efx_filter_spec_init_rx(&spec, EFX_FILTER_PRI_AUTO,
1114 eftp->eft_default_rxq);
1115 efx_filter_spec_set_mc_def(&spec);
1117 rc = ef10_filter_add_internal(enp, &spec, B_TRUE,
1118 &eftp->eft_mulcst_filter_indexes[0]);
1122 eftp->eft_mulcst_filter_count = 1;
1123 eftp->eft_using_all_mulcst = B_TRUE;
1126 * FIXME: If brdcst == B_FALSE, add a filter to drop broadcast traffic.
1132 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1138 ef10_filter_remove_old(
1139 __in efx_nic_t *enp)
1141 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
1144 for (i = 0; i < EFX_ARRAY_SIZE(table->eft_entry); i++) {
1145 if (ef10_filter_entry_is_auto_old(table, i)) {
1146 (void) ef10_filter_delete_internal(enp, i);
1152 static __checkReturn efx_rc_t
1153 ef10_filter_get_workarounds(
1154 __in efx_nic_t *enp)
1156 efx_nic_cfg_t *encp = &enp->en_nic_cfg;
1157 uint32_t implemented = 0;
1158 uint32_t enabled = 0;
1161 rc = efx_mcdi_get_workarounds(enp, &implemented, &enabled);
1163 /* Check if chained multicast filter support is enabled */
1164 if (implemented & enabled & MC_CMD_GET_WORKAROUNDS_OUT_BUG26807)
1165 encp->enc_bug26807_workaround = B_TRUE;
1167 encp->enc_bug26807_workaround = B_FALSE;
1168 } else if (rc == ENOTSUP) {
1170 * Firmware is too old to support GET_WORKAROUNDS, and support
1171 * for this workaround was implemented later.
1173 encp->enc_bug26807_workaround = B_FALSE;
1181 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1189 * Reconfigure all filters.
1190 * If all_unicst and/or all mulcst filters cannot be applied then
1191 * return ENOTSUP (Note the filters for the specified addresses are
1192 * still applied in this case).
1194 __checkReturn efx_rc_t
1195 ef10_filter_reconfigure(
1196 __in efx_nic_t *enp,
1197 __in_ecount(6) uint8_t const *mac_addr,
1198 __in boolean_t all_unicst,
1199 __in boolean_t mulcst,
1200 __in boolean_t all_mulcst,
1201 __in boolean_t brdcst,
1202 __in_ecount(6*count) uint8_t const *addrs,
1203 __in uint32_t count)
1205 efx_nic_cfg_t *encp = &enp->en_nic_cfg;
1206 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
1207 efx_filter_flags_t filter_flags;
1209 efx_rc_t all_unicst_rc = 0;
1210 efx_rc_t all_mulcst_rc = 0;
1213 if (table->eft_default_rxq == NULL) {
1215 * Filters direct traffic to the default RXQ, and so cannot be
1216 * inserted until it is available. Any currently configured
1217 * filters must be removed (ignore errors in case the MC
1218 * has rebooted, which removes hardware filters).
1220 for (i = 0; i < table->eft_unicst_filter_count; i++) {
1221 (void) ef10_filter_delete_internal(enp,
1222 table->eft_unicst_filter_indexes[i]);
1224 table->eft_unicst_filter_count = 0;
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 for (i = 0; i < table->eft_unicst_filter_count; i++) {
1242 ef10_filter_set_entry_auto_old(table,
1243 table->eft_unicst_filter_indexes[i]);
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]);
1251 * Insert or renew unicast filters.
1253 * Frimware does not perform chaining on unicast filters. As traffic is
1254 * therefore only delivered to the first matching filter, we should
1255 * always insert the specific filter for our MAC address, to try and
1256 * ensure we get that traffic.
1258 * (If the filter for our MAC address has already been inserted by
1259 * another function, we won't receive traffic sent to us, even if we
1260 * insert a unicast mismatch filter. To prevent traffic stealing, this
1261 * therefore relies on the privilege model only allowing functions to
1262 * insert filters for their own MAC address unless explicitly given
1263 * additional privileges by the user. This also means that, even on a
1264 * priviliged function, inserting a unicast mismatch filter may not
1265 * catch all traffic in multi PCI function scenarios.)
1267 table->eft_unicst_filter_count = 0;
1268 rc = ef10_filter_insert_unicast(enp, mac_addr, filter_flags);
1269 if (all_unicst || (rc != 0)) {
1270 all_unicst_rc = ef10_filter_insert_all_unicast(enp,
1272 if ((rc != 0) && (all_unicst_rc != 0))
1277 * WORKAROUND_BUG26807 controls firmware support for chained multicast
1278 * filters, and can only be enabled or disabled when the hardware filter
1281 * Chained multicast filters require support from the datapath firmware,
1282 * and may not be available (e.g. low-latency variants or old Huntington
1285 * Firmware will reset (FLR) functions which have inserted filters in
1286 * the hardware filter table when the workaround is enabled/disabled.
1287 * Functions without any hardware filters are not reset.
1289 * Re-check if the workaround is enabled after adding unicast hardware
1290 * filters. This ensures that encp->enc_bug26807_workaround matches the
1291 * firmware state, and that later changes to enable/disable the
1292 * workaround will result in this function seeing a reset (FLR).
1294 * In common-code drivers, we only support multiple PCI function
1295 * scenarios with firmware that supports multicast chaining, so we can
1296 * assume it is enabled for such cases and hence simplify the filter
1297 * insertion logic. Firmware that does not support multicast chaining
1298 * does not support multiple PCI function configurations either, so
1299 * filter insertion is much simpler and the same strategies can still be
1302 if ((rc = ef10_filter_get_workarounds(enp)) != 0)
1305 if ((table->eft_using_all_mulcst != all_mulcst) &&
1306 (encp->enc_bug26807_workaround == B_TRUE)) {
1308 * Multicast filter chaining is enabled, so traffic that matches
1309 * more than one multicast filter will be replicated and
1310 * delivered to multiple recipients. To avoid this duplicate
1311 * delivery, remove old multicast filters before inserting new
1312 * multicast filters.
1314 ef10_filter_remove_old(enp);
1317 /* Insert or renew multicast filters */
1318 if (all_mulcst == B_TRUE) {
1320 * Insert the all multicast filter. If that fails, try to insert
1321 * all of our multicast filters (but without rollback on
1324 all_mulcst_rc = ef10_filter_insert_all_multicast(enp,
1326 if (all_mulcst_rc != 0) {
1327 rc = ef10_filter_insert_multicast_list(enp, B_TRUE,
1328 brdcst, addrs, count, filter_flags, B_FALSE);
1334 * Insert filters for multicast addresses.
1335 * If any insertion fails, then rollback and try to insert the
1336 * all multicast filter instead.
1337 * If that also fails, try to insert all of the multicast
1338 * filters (but without rollback on failure).
1340 rc = ef10_filter_insert_multicast_list(enp, mulcst, brdcst,
1341 addrs, count, filter_flags, B_TRUE);
1343 if ((table->eft_using_all_mulcst == B_FALSE) &&
1344 (encp->enc_bug26807_workaround == B_TRUE)) {
1346 * Multicast filter chaining is on, so remove
1347 * old filters before inserting the multicast
1348 * all filter to avoid duplicate delivery caused
1349 * by packets matching multiple filters.
1351 ef10_filter_remove_old(enp);
1354 rc = ef10_filter_insert_all_multicast(enp,
1357 rc = ef10_filter_insert_multicast_list(enp,
1359 addrs, count, filter_flags, B_FALSE);
1366 /* Remove old filters which were not renewed */
1367 ef10_filter_remove_old(enp);
1369 /* report if any optional flags were rejected */
1370 if (((all_unicst != B_FALSE) && (all_unicst_rc != 0)) ||
1371 ((all_mulcst != B_FALSE) && (all_mulcst_rc != 0))) {
1384 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1386 /* Clear auto old flags */
1387 for (i = 0; i < EFX_ARRAY_SIZE(table->eft_entry); i++) {
1388 if (ef10_filter_entry_is_auto_old(table, i)) {
1389 ef10_filter_set_entry_not_auto_old(table, i);
1397 ef10_filter_get_default_rxq(
1398 __in efx_nic_t *enp,
1399 __out efx_rxq_t **erpp,
1400 __out boolean_t *using_rss)
1402 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
1404 *erpp = table->eft_default_rxq;
1405 *using_rss = table->eft_using_rss;
1410 ef10_filter_default_rxq_set(
1411 __in efx_nic_t *enp,
1412 __in efx_rxq_t *erp,
1413 __in boolean_t using_rss)
1415 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
1417 #if EFSYS_OPT_RX_SCALE
1418 EFSYS_ASSERT((using_rss == B_FALSE) ||
1419 (enp->en_rss_context != EF10_RSS_CONTEXT_INVALID));
1420 table->eft_using_rss = using_rss;
1422 EFSYS_ASSERT(using_rss == B_FALSE);
1423 table->eft_using_rss = B_FALSE;
1425 table->eft_default_rxq = erp;
1429 ef10_filter_default_rxq_clear(
1430 __in efx_nic_t *enp)
1432 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
1434 table->eft_default_rxq = NULL;
1435 table->eft_using_rss = B_FALSE;
1439 #endif /* EFSYS_OPT_FILTER */
1441 #endif /* EFSYS_OPT_HUNTINGTON || EFSYS_OPT_MEDFORD */