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_ecount(buffer_length) uint32_t *buffer,
873 __in size_t buffer_length,
874 __out size_t *list_lengthp)
877 uint8_t payload[MAX(MC_CMD_GET_PARSER_DISP_INFO_IN_LEN,
878 MC_CMD_GET_PARSER_DISP_INFO_OUT_LENMAX)];
879 size_t matches_count;
883 (void) memset(payload, 0, sizeof (payload));
884 req.emr_cmd = MC_CMD_GET_PARSER_DISP_INFO;
885 req.emr_in_buf = payload;
886 req.emr_in_length = MC_CMD_GET_PARSER_DISP_INFO_IN_LEN;
887 req.emr_out_buf = payload;
888 req.emr_out_length = MC_CMD_GET_PARSER_DISP_INFO_OUT_LENMAX;
890 MCDI_IN_SET_DWORD(req, GET_PARSER_DISP_INFO_OUT_OP,
891 MC_CMD_GET_PARSER_DISP_INFO_IN_OP_GET_SUPPORTED_RX_MATCHES);
893 efx_mcdi_execute(enp, &req);
895 if (req.emr_rc != 0) {
900 matches_count = MCDI_OUT_DWORD(req,
901 GET_PARSER_DISP_INFO_OUT_NUM_SUPPORTED_MATCHES);
903 if (req.emr_out_length_used <
904 MC_CMD_GET_PARSER_DISP_INFO_OUT_LEN(matches_count)) {
909 *list_lengthp = matches_count;
911 if (buffer_length < matches_count) {
917 * Check that the elements in the list in the MCDI response are the size
918 * we expect, so we can just copy them directly. Any conversion of the
919 * flags is handled by the caller.
921 EFX_STATIC_ASSERT(sizeof (uint32_t) ==
922 MC_CMD_GET_PARSER_DISP_INFO_OUT_SUPPORTED_MATCHES_LEN);
924 list_size = matches_count *
925 MC_CMD_GET_PARSER_DISP_INFO_OUT_SUPPORTED_MATCHES_LEN;
927 MCDI_OUT2(req, uint32_t,
928 GET_PARSER_DISP_INFO_OUT_SUPPORTED_MATCHES),
938 EFSYS_PROBE1(fail1, efx_rc_t, rc);
943 __checkReturn efx_rc_t
944 ef10_filter_supported_filters(
946 __out_ecount(buffer_length) uint32_t *buffer,
947 __in size_t buffer_length,
948 __out size_t *list_lengthp)
951 size_t mcdi_list_length;
955 uint32_t all_filter_flags =
956 (EFX_FILTER_MATCH_REM_HOST | EFX_FILTER_MATCH_LOC_HOST |
957 EFX_FILTER_MATCH_REM_MAC | EFX_FILTER_MATCH_REM_PORT |
958 EFX_FILTER_MATCH_LOC_MAC | EFX_FILTER_MATCH_LOC_PORT |
959 EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_INNER_VID |
960 EFX_FILTER_MATCH_OUTER_VID | EFX_FILTER_MATCH_IP_PROTO |
961 EFX_FILTER_MATCH_UNKNOWN_MCAST_DST |
962 EFX_FILTER_MATCH_UNKNOWN_UCAST_DST);
964 rc = efx_mcdi_get_parser_disp_info(enp, buffer, buffer_length,
968 /* Pass through mcdi_list_length for the list length */
969 *list_lengthp = mcdi_list_length;
975 * The static assertions in ef10_filter_init() ensure that the values of
976 * the EFX_FILTER_MATCH flags match those used by MCDI, so they don't
977 * need to be converted.
979 * In case support is added to MCDI for additional flags, remove any
980 * matches from the list which include flags we don't support. The order
981 * of the matches is preserved as they are ordered from highest to
984 EFSYS_ASSERT(mcdi_list_length <= buffer_length);
986 for (i = 0; i < mcdi_list_length; i++) {
987 if ((buffer[i] & ~all_filter_flags) == 0) {
988 buffer[list_length] = buffer[i];
993 *list_lengthp = list_length;
998 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1003 static __checkReturn efx_rc_t
1004 ef10_filter_insert_unicast(
1005 __in efx_nic_t *enp,
1006 __in_ecount(6) uint8_t const *addr,
1007 __in efx_filter_flags_t filter_flags)
1009 ef10_filter_table_t *eftp = enp->en_filter.ef_ef10_filter_table;
1010 efx_filter_spec_t spec;
1013 /* Insert the filter for the local station address */
1014 efx_filter_spec_init_rx(&spec, EFX_FILTER_PRI_AUTO,
1016 eftp->eft_default_rxq);
1017 efx_filter_spec_set_eth_local(&spec, EFX_FILTER_SPEC_VID_UNSPEC, addr);
1019 rc = ef10_filter_add_internal(enp, &spec, B_TRUE,
1020 &eftp->eft_unicst_filter_indexes[eftp->eft_unicst_filter_count]);
1024 eftp->eft_unicst_filter_count++;
1025 EFSYS_ASSERT(eftp->eft_unicst_filter_count <=
1026 EFX_EF10_FILTER_UNICAST_FILTERS_MAX);
1031 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1035 static __checkReturn efx_rc_t
1036 ef10_filter_insert_all_unicast(
1037 __in efx_nic_t *enp,
1038 __in efx_filter_flags_t filter_flags)
1040 ef10_filter_table_t *eftp = enp->en_filter.ef_ef10_filter_table;
1041 efx_filter_spec_t spec;
1044 /* Insert the unknown unicast filter */
1045 efx_filter_spec_init_rx(&spec, EFX_FILTER_PRI_AUTO,
1047 eftp->eft_default_rxq);
1048 efx_filter_spec_set_uc_def(&spec);
1049 rc = ef10_filter_add_internal(enp, &spec, B_TRUE,
1050 &eftp->eft_unicst_filter_indexes[eftp->eft_unicst_filter_count]);
1054 eftp->eft_unicst_filter_count++;
1055 EFSYS_ASSERT(eftp->eft_unicst_filter_count <=
1056 EFX_EF10_FILTER_UNICAST_FILTERS_MAX);
1061 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1065 static __checkReturn efx_rc_t
1066 ef10_filter_insert_multicast_list(
1067 __in efx_nic_t *enp,
1068 __in boolean_t mulcst,
1069 __in boolean_t brdcst,
1070 __in_ecount(6*count) uint8_t const *addrs,
1071 __in uint32_t count,
1072 __in efx_filter_flags_t filter_flags,
1073 __in boolean_t rollback)
1075 ef10_filter_table_t *eftp = enp->en_filter.ef_ef10_filter_table;
1076 efx_filter_spec_t spec;
1079 uint32_t filter_index;
1080 uint32_t filter_count;
1083 if (mulcst == B_FALSE)
1086 if (count + (brdcst ? 1 : 0) >
1087 EFX_ARRAY_SIZE(eftp->eft_mulcst_filter_indexes)) {
1088 /* Too many MAC addresses */
1093 /* Insert/renew multicast address list filters */
1095 for (i = 0; i < count; i++) {
1096 efx_filter_spec_init_rx(&spec,
1097 EFX_FILTER_PRI_AUTO,
1099 eftp->eft_default_rxq);
1101 efx_filter_spec_set_eth_local(&spec,
1102 EFX_FILTER_SPEC_VID_UNSPEC,
1103 &addrs[i * EFX_MAC_ADDR_LEN]);
1105 rc = ef10_filter_add_internal(enp, &spec, B_TRUE,
1109 eftp->eft_mulcst_filter_indexes[filter_count] =
1112 } else if (rollback == B_TRUE) {
1113 /* Only stop upon failure if told to rollback */
1119 if (brdcst == B_TRUE) {
1120 /* Insert/renew broadcast address filter */
1121 efx_filter_spec_init_rx(&spec, EFX_FILTER_PRI_AUTO,
1123 eftp->eft_default_rxq);
1125 EFX_MAC_BROADCAST_ADDR_SET(addr);
1126 efx_filter_spec_set_eth_local(&spec, EFX_FILTER_SPEC_VID_UNSPEC,
1129 rc = ef10_filter_add_internal(enp, &spec, B_TRUE,
1133 eftp->eft_mulcst_filter_indexes[filter_count] =
1136 } else if (rollback == B_TRUE) {
1137 /* Only stop upon failure if told to rollback */
1142 eftp->eft_mulcst_filter_count = filter_count;
1143 eftp->eft_using_all_mulcst = B_FALSE;
1148 /* Remove any filters we have inserted */
1151 (void) ef10_filter_delete_internal(enp,
1152 eftp->eft_mulcst_filter_indexes[i]);
1154 eftp->eft_mulcst_filter_count = 0;
1157 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1162 static __checkReturn efx_rc_t
1163 ef10_filter_insert_all_multicast(
1164 __in efx_nic_t *enp,
1165 __in efx_filter_flags_t filter_flags)
1167 ef10_filter_table_t *eftp = enp->en_filter.ef_ef10_filter_table;
1168 efx_filter_spec_t spec;
1171 /* Insert the unknown multicast filter */
1172 efx_filter_spec_init_rx(&spec, EFX_FILTER_PRI_AUTO,
1174 eftp->eft_default_rxq);
1175 efx_filter_spec_set_mc_def(&spec);
1177 rc = ef10_filter_add_internal(enp, &spec, B_TRUE,
1178 &eftp->eft_mulcst_filter_indexes[0]);
1182 eftp->eft_mulcst_filter_count = 1;
1183 eftp->eft_using_all_mulcst = B_TRUE;
1186 * FIXME: If brdcst == B_FALSE, add a filter to drop broadcast traffic.
1192 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1198 ef10_filter_remove_old(
1199 __in efx_nic_t *enp)
1201 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
1204 for (i = 0; i < EFX_ARRAY_SIZE(table->eft_entry); i++) {
1205 if (ef10_filter_entry_is_auto_old(table, i)) {
1206 (void) ef10_filter_delete_internal(enp, i);
1212 static __checkReturn efx_rc_t
1213 ef10_filter_get_workarounds(
1214 __in efx_nic_t *enp)
1216 efx_nic_cfg_t *encp = &enp->en_nic_cfg;
1217 uint32_t implemented = 0;
1218 uint32_t enabled = 0;
1221 rc = efx_mcdi_get_workarounds(enp, &implemented, &enabled);
1223 /* Check if chained multicast filter support is enabled */
1224 if (implemented & enabled & MC_CMD_GET_WORKAROUNDS_OUT_BUG26807)
1225 encp->enc_bug26807_workaround = B_TRUE;
1227 encp->enc_bug26807_workaround = B_FALSE;
1228 } else if (rc == ENOTSUP) {
1230 * Firmware is too old to support GET_WORKAROUNDS, and support
1231 * for this workaround was implemented later.
1233 encp->enc_bug26807_workaround = B_FALSE;
1241 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1249 * Reconfigure all filters.
1250 * If all_unicst and/or all mulcst filters cannot be applied then
1251 * return ENOTSUP (Note the filters for the specified addresses are
1252 * still applied in this case).
1254 __checkReturn efx_rc_t
1255 ef10_filter_reconfigure(
1256 __in efx_nic_t *enp,
1257 __in_ecount(6) uint8_t const *mac_addr,
1258 __in boolean_t all_unicst,
1259 __in boolean_t mulcst,
1260 __in boolean_t all_mulcst,
1261 __in boolean_t brdcst,
1262 __in_ecount(6*count) uint8_t const *addrs,
1263 __in uint32_t count)
1265 efx_nic_cfg_t *encp = &enp->en_nic_cfg;
1266 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
1267 efx_filter_flags_t filter_flags;
1269 efx_rc_t all_unicst_rc = 0;
1270 efx_rc_t all_mulcst_rc = 0;
1273 if (table->eft_default_rxq == NULL) {
1275 * Filters direct traffic to the default RXQ, and so cannot be
1276 * inserted until it is available. Any currently configured
1277 * filters must be removed (ignore errors in case the MC
1278 * has rebooted, which removes hardware filters).
1280 for (i = 0; i < table->eft_unicst_filter_count; i++) {
1281 (void) ef10_filter_delete_internal(enp,
1282 table->eft_unicst_filter_indexes[i]);
1284 table->eft_unicst_filter_count = 0;
1286 for (i = 0; i < table->eft_mulcst_filter_count; i++) {
1287 (void) ef10_filter_delete_internal(enp,
1288 table->eft_mulcst_filter_indexes[i]);
1290 table->eft_mulcst_filter_count = 0;
1295 if (table->eft_using_rss)
1296 filter_flags = EFX_FILTER_FLAG_RX_RSS;
1300 /* Mark old filters which may need to be removed */
1301 for (i = 0; i < table->eft_unicst_filter_count; i++) {
1302 ef10_filter_set_entry_auto_old(table,
1303 table->eft_unicst_filter_indexes[i]);
1305 for (i = 0; i < table->eft_mulcst_filter_count; i++) {
1306 ef10_filter_set_entry_auto_old(table,
1307 table->eft_mulcst_filter_indexes[i]);
1311 * Insert or renew unicast filters.
1313 * Frimware does not perform chaining on unicast filters. As traffic is
1314 * therefore only delivered to the first matching filter, we should
1315 * always insert the specific filter for our MAC address, to try and
1316 * ensure we get that traffic.
1318 * (If the filter for our MAC address has already been inserted by
1319 * another function, we won't receive traffic sent to us, even if we
1320 * insert a unicast mismatch filter. To prevent traffic stealing, this
1321 * therefore relies on the privilege model only allowing functions to
1322 * insert filters for their own MAC address unless explicitly given
1323 * additional privileges by the user. This also means that, even on a
1324 * priviliged function, inserting a unicast mismatch filter may not
1325 * catch all traffic in multi PCI function scenarios.)
1327 table->eft_unicst_filter_count = 0;
1328 rc = ef10_filter_insert_unicast(enp, mac_addr, filter_flags);
1329 if (all_unicst || (rc != 0)) {
1330 all_unicst_rc = ef10_filter_insert_all_unicast(enp,
1332 if ((rc != 0) && (all_unicst_rc != 0))
1337 * WORKAROUND_BUG26807 controls firmware support for chained multicast
1338 * filters, and can only be enabled or disabled when the hardware filter
1341 * Chained multicast filters require support from the datapath firmware,
1342 * and may not be available (e.g. low-latency variants or old Huntington
1345 * Firmware will reset (FLR) functions which have inserted filters in
1346 * the hardware filter table when the workaround is enabled/disabled.
1347 * Functions without any hardware filters are not reset.
1349 * Re-check if the workaround is enabled after adding unicast hardware
1350 * filters. This ensures that encp->enc_bug26807_workaround matches the
1351 * firmware state, and that later changes to enable/disable the
1352 * workaround will result in this function seeing a reset (FLR).
1354 * In common-code drivers, we only support multiple PCI function
1355 * scenarios with firmware that supports multicast chaining, so we can
1356 * assume it is enabled for such cases and hence simplify the filter
1357 * insertion logic. Firmware that does not support multicast chaining
1358 * does not support multiple PCI function configurations either, so
1359 * filter insertion is much simpler and the same strategies can still be
1362 if ((rc = ef10_filter_get_workarounds(enp)) != 0)
1365 if ((table->eft_using_all_mulcst != all_mulcst) &&
1366 (encp->enc_bug26807_workaround == B_TRUE)) {
1368 * Multicast filter chaining is enabled, so traffic that matches
1369 * more than one multicast filter will be replicated and
1370 * delivered to multiple recipients. To avoid this duplicate
1371 * delivery, remove old multicast filters before inserting new
1372 * multicast filters.
1374 ef10_filter_remove_old(enp);
1377 /* Insert or renew multicast filters */
1378 if (all_mulcst == B_TRUE) {
1380 * Insert the all multicast filter. If that fails, try to insert
1381 * all of our multicast filters (but without rollback on
1384 all_mulcst_rc = ef10_filter_insert_all_multicast(enp,
1386 if (all_mulcst_rc != 0) {
1387 rc = ef10_filter_insert_multicast_list(enp, B_TRUE,
1388 brdcst, addrs, count, filter_flags, B_FALSE);
1394 * Insert filters for multicast addresses.
1395 * If any insertion fails, then rollback and try to insert the
1396 * all multicast filter instead.
1397 * If that also fails, try to insert all of the multicast
1398 * filters (but without rollback on failure).
1400 rc = ef10_filter_insert_multicast_list(enp, mulcst, brdcst,
1401 addrs, count, filter_flags, B_TRUE);
1403 if ((table->eft_using_all_mulcst == B_FALSE) &&
1404 (encp->enc_bug26807_workaround == B_TRUE)) {
1406 * Multicast filter chaining is on, so remove
1407 * old filters before inserting the multicast
1408 * all filter to avoid duplicate delivery caused
1409 * by packets matching multiple filters.
1411 ef10_filter_remove_old(enp);
1414 rc = ef10_filter_insert_all_multicast(enp,
1417 rc = ef10_filter_insert_multicast_list(enp,
1419 addrs, count, filter_flags, B_FALSE);
1426 /* Remove old filters which were not renewed */
1427 ef10_filter_remove_old(enp);
1429 /* report if any optional flags were rejected */
1430 if (((all_unicst != B_FALSE) && (all_unicst_rc != 0)) ||
1431 ((all_mulcst != B_FALSE) && (all_mulcst_rc != 0))) {
1444 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1446 /* Clear auto old flags */
1447 for (i = 0; i < EFX_ARRAY_SIZE(table->eft_entry); i++) {
1448 if (ef10_filter_entry_is_auto_old(table, i)) {
1449 ef10_filter_set_entry_not_auto_old(table, i);
1457 ef10_filter_get_default_rxq(
1458 __in efx_nic_t *enp,
1459 __out efx_rxq_t **erpp,
1460 __out boolean_t *using_rss)
1462 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
1464 *erpp = table->eft_default_rxq;
1465 *using_rss = table->eft_using_rss;
1470 ef10_filter_default_rxq_set(
1471 __in efx_nic_t *enp,
1472 __in efx_rxq_t *erp,
1473 __in boolean_t using_rss)
1475 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
1477 #if EFSYS_OPT_RX_SCALE
1478 EFSYS_ASSERT((using_rss == B_FALSE) ||
1479 (enp->en_rss_context != EF10_RSS_CONTEXT_INVALID));
1480 table->eft_using_rss = using_rss;
1482 EFSYS_ASSERT(using_rss == B_FALSE);
1483 table->eft_using_rss = B_FALSE;
1485 table->eft_default_rxq = erp;
1489 ef10_filter_default_rxq_clear(
1490 __in efx_nic_t *enp)
1492 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
1494 table->eft_default_rxq = NULL;
1495 table->eft_using_rss = B_FALSE;
1499 #endif /* EFSYS_OPT_FILTER */
1501 #endif /* EFSYS_OPT_HUNTINGTON || EFSYS_OPT_MEDFORD */