2 * Copyright (c) 2007-2016 Solarflare Communications Inc.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
16 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
18 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
21 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
22 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
24 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 * The views and conclusions contained in the software and documentation are
27 * those of the authors and should not be interpreted as representing official
28 * policies, either expressed or implied, of the FreeBSD Project.
31 #include <sys/cdefs.h>
32 __FBSDID("$FreeBSD$");
37 #if EFSYS_OPT_HUNTINGTON || EFSYS_OPT_MEDFORD
41 #define EFE_SPEC(eftp, index) ((eftp)->eft_entry[(index)].efe_spec)
43 static efx_filter_spec_t *
44 ef10_filter_entry_spec(
45 __in const ef10_filter_table_t *eftp,
46 __in unsigned int index)
48 return ((efx_filter_spec_t *)(EFE_SPEC(eftp, index) &
49 ~(uintptr_t)EFX_EF10_FILTER_FLAGS));
53 ef10_filter_entry_is_busy(
54 __in const ef10_filter_table_t *eftp,
55 __in unsigned int index)
57 if (EFE_SPEC(eftp, index) & EFX_EF10_FILTER_FLAG_BUSY)
64 ef10_filter_entry_is_auto_old(
65 __in const ef10_filter_table_t *eftp,
66 __in unsigned int index)
68 if (EFE_SPEC(eftp, index) & EFX_EF10_FILTER_FLAG_AUTO_OLD)
75 ef10_filter_set_entry(
76 __inout ef10_filter_table_t *eftp,
77 __in unsigned int index,
78 __in_opt const efx_filter_spec_t *efsp)
80 EFE_SPEC(eftp, index) = (uintptr_t)efsp;
84 ef10_filter_set_entry_busy(
85 __inout ef10_filter_table_t *eftp,
86 __in unsigned int index)
88 EFE_SPEC(eftp, index) |= (uintptr_t)EFX_EF10_FILTER_FLAG_BUSY;
92 ef10_filter_set_entry_not_busy(
93 __inout ef10_filter_table_t *eftp,
94 __in unsigned int index)
96 EFE_SPEC(eftp, index) &= ~(uintptr_t)EFX_EF10_FILTER_FLAG_BUSY;
100 ef10_filter_set_entry_auto_old(
101 __inout ef10_filter_table_t *eftp,
102 __in unsigned int index)
104 EFSYS_ASSERT(ef10_filter_entry_spec(eftp, index) != NULL);
105 EFE_SPEC(eftp, index) |= (uintptr_t)EFX_EF10_FILTER_FLAG_AUTO_OLD;
109 ef10_filter_set_entry_not_auto_old(
110 __inout ef10_filter_table_t *eftp,
111 __in unsigned int index)
113 EFE_SPEC(eftp, index) &= ~(uintptr_t)EFX_EF10_FILTER_FLAG_AUTO_OLD;
114 EFSYS_ASSERT(ef10_filter_entry_spec(eftp, index) != NULL);
117 __checkReturn efx_rc_t
122 ef10_filter_table_t *eftp;
124 EFSYS_ASSERT(enp->en_family == EFX_FAMILY_HUNTINGTON ||
125 enp->en_family == EFX_FAMILY_MEDFORD);
127 #define MATCH_MASK(match) (EFX_MASK32(match) << EFX_LOW_BIT(match))
128 EFX_STATIC_ASSERT(EFX_FILTER_MATCH_REM_HOST ==
129 MATCH_MASK(MC_CMD_FILTER_OP_IN_MATCH_SRC_IP));
130 EFX_STATIC_ASSERT(EFX_FILTER_MATCH_LOC_HOST ==
131 MATCH_MASK(MC_CMD_FILTER_OP_IN_MATCH_DST_IP));
132 EFX_STATIC_ASSERT(EFX_FILTER_MATCH_REM_MAC ==
133 MATCH_MASK(MC_CMD_FILTER_OP_IN_MATCH_SRC_MAC));
134 EFX_STATIC_ASSERT(EFX_FILTER_MATCH_REM_PORT ==
135 MATCH_MASK(MC_CMD_FILTER_OP_IN_MATCH_SRC_PORT));
136 EFX_STATIC_ASSERT(EFX_FILTER_MATCH_LOC_MAC ==
137 MATCH_MASK(MC_CMD_FILTER_OP_IN_MATCH_DST_MAC));
138 EFX_STATIC_ASSERT(EFX_FILTER_MATCH_LOC_PORT ==
139 MATCH_MASK(MC_CMD_FILTER_OP_IN_MATCH_DST_PORT));
140 EFX_STATIC_ASSERT(EFX_FILTER_MATCH_ETHER_TYPE ==
141 MATCH_MASK(MC_CMD_FILTER_OP_IN_MATCH_ETHER_TYPE));
142 EFX_STATIC_ASSERT(EFX_FILTER_MATCH_INNER_VID ==
143 MATCH_MASK(MC_CMD_FILTER_OP_IN_MATCH_INNER_VLAN));
144 EFX_STATIC_ASSERT(EFX_FILTER_MATCH_OUTER_VID ==
145 MATCH_MASK(MC_CMD_FILTER_OP_IN_MATCH_OUTER_VLAN));
146 EFX_STATIC_ASSERT(EFX_FILTER_MATCH_IP_PROTO ==
147 MATCH_MASK(MC_CMD_FILTER_OP_IN_MATCH_IP_PROTO));
148 EFX_STATIC_ASSERT(EFX_FILTER_MATCH_UNKNOWN_MCAST_DST ==
149 MATCH_MASK(MC_CMD_FILTER_OP_IN_MATCH_UNKNOWN_MCAST_DST));
150 EFX_STATIC_ASSERT((uint32_t)EFX_FILTER_MATCH_UNKNOWN_UCAST_DST ==
151 MATCH_MASK(MC_CMD_FILTER_OP_IN_MATCH_UNKNOWN_UCAST_DST));
154 EFSYS_KMEM_ALLOC(enp->en_esip, sizeof (ef10_filter_table_t), eftp);
161 enp->en_filter.ef_ef10_filter_table = eftp;
166 EFSYS_PROBE1(fail1, efx_rc_t, rc);
175 EFSYS_ASSERT(enp->en_family == EFX_FAMILY_HUNTINGTON ||
176 enp->en_family == EFX_FAMILY_MEDFORD);
178 if (enp->en_filter.ef_ef10_filter_table != NULL) {
179 EFSYS_KMEM_FREE(enp->en_esip, sizeof (ef10_filter_table_t),
180 enp->en_filter.ef_ef10_filter_table);
184 static __checkReturn efx_rc_t
185 efx_mcdi_filter_op_add(
187 __in efx_filter_spec_t *spec,
188 __in unsigned int filter_op,
189 __inout ef10_filter_handle_t *handle)
192 uint8_t payload[MAX(MC_CMD_FILTER_OP_IN_LEN,
193 MC_CMD_FILTER_OP_OUT_LEN)];
196 memset(payload, 0, sizeof (payload));
197 req.emr_cmd = MC_CMD_FILTER_OP;
198 req.emr_in_buf = payload;
199 req.emr_in_length = MC_CMD_FILTER_OP_IN_LEN;
200 req.emr_out_buf = payload;
201 req.emr_out_length = MC_CMD_FILTER_OP_OUT_LEN;
204 case MC_CMD_FILTER_OP_IN_OP_REPLACE:
205 MCDI_IN_SET_DWORD(req, FILTER_OP_IN_HANDLE_LO,
207 MCDI_IN_SET_DWORD(req, FILTER_OP_IN_HANDLE_HI,
210 case MC_CMD_FILTER_OP_IN_OP_INSERT:
211 case MC_CMD_FILTER_OP_IN_OP_SUBSCRIBE:
212 MCDI_IN_SET_DWORD(req, FILTER_OP_IN_OP, filter_op);
220 MCDI_IN_SET_DWORD(req, FILTER_OP_IN_PORT_ID,
221 EVB_PORT_ID_ASSIGNED);
222 MCDI_IN_SET_DWORD(req, FILTER_OP_IN_MATCH_FIELDS,
223 spec->efs_match_flags);
224 MCDI_IN_SET_DWORD(req, FILTER_OP_IN_RX_DEST,
225 MC_CMD_FILTER_OP_IN_RX_DEST_HOST);
226 MCDI_IN_SET_DWORD(req, FILTER_OP_IN_RX_QUEUE,
228 if (spec->efs_flags & EFX_FILTER_FLAG_RX_RSS) {
229 MCDI_IN_SET_DWORD(req, FILTER_OP_IN_RX_CONTEXT,
230 spec->efs_rss_context);
232 MCDI_IN_SET_DWORD(req, FILTER_OP_IN_RX_MODE,
233 spec->efs_flags & EFX_FILTER_FLAG_RX_RSS ?
234 MC_CMD_FILTER_OP_IN_RX_MODE_RSS :
235 MC_CMD_FILTER_OP_IN_RX_MODE_SIMPLE);
236 MCDI_IN_SET_DWORD(req, FILTER_OP_IN_TX_DEST,
237 MC_CMD_FILTER_OP_IN_TX_DEST_DEFAULT);
239 if (filter_op != MC_CMD_FILTER_OP_IN_OP_REPLACE) {
241 * NOTE: Unlike most MCDI requests, the filter fields
242 * are presented in network (big endian) byte order.
244 memcpy(MCDI_IN2(req, uint8_t, FILTER_OP_IN_SRC_MAC),
245 spec->efs_rem_mac, EFX_MAC_ADDR_LEN);
246 memcpy(MCDI_IN2(req, uint8_t, FILTER_OP_IN_DST_MAC),
247 spec->efs_loc_mac, EFX_MAC_ADDR_LEN);
249 MCDI_IN_SET_WORD(req, FILTER_OP_IN_SRC_PORT,
250 __CPU_TO_BE_16(spec->efs_rem_port));
251 MCDI_IN_SET_WORD(req, FILTER_OP_IN_DST_PORT,
252 __CPU_TO_BE_16(spec->efs_loc_port));
254 MCDI_IN_SET_WORD(req, FILTER_OP_IN_ETHER_TYPE,
255 __CPU_TO_BE_16(spec->efs_ether_type));
257 MCDI_IN_SET_WORD(req, FILTER_OP_IN_INNER_VLAN,
258 __CPU_TO_BE_16(spec->efs_inner_vid));
259 MCDI_IN_SET_WORD(req, FILTER_OP_IN_OUTER_VLAN,
260 __CPU_TO_BE_16(spec->efs_outer_vid));
262 /* IP protocol (in low byte, high byte is zero) */
263 MCDI_IN_SET_BYTE(req, FILTER_OP_IN_IP_PROTO,
266 EFX_STATIC_ASSERT(sizeof (spec->efs_rem_host) ==
267 MC_CMD_FILTER_OP_IN_SRC_IP_LEN);
268 EFX_STATIC_ASSERT(sizeof (spec->efs_loc_host) ==
269 MC_CMD_FILTER_OP_IN_DST_IP_LEN);
271 memcpy(MCDI_IN2(req, uint8_t, FILTER_OP_IN_SRC_IP),
272 &spec->efs_rem_host.eo_byte[0],
273 MC_CMD_FILTER_OP_IN_SRC_IP_LEN);
274 memcpy(MCDI_IN2(req, uint8_t, FILTER_OP_IN_DST_IP),
275 &spec->efs_loc_host.eo_byte[0],
276 MC_CMD_FILTER_OP_IN_DST_IP_LEN);
279 efx_mcdi_execute(enp, &req);
281 if (req.emr_rc != 0) {
286 if (req.emr_out_length_used < MC_CMD_FILTER_OP_OUT_LEN) {
291 handle->efh_lo = MCDI_OUT_DWORD(req, FILTER_OP_OUT_HANDLE_LO);
292 handle->efh_hi = MCDI_OUT_DWORD(req, FILTER_OP_OUT_HANDLE_HI);
301 EFSYS_PROBE1(fail1, efx_rc_t, rc);
307 static __checkReturn efx_rc_t
308 efx_mcdi_filter_op_delete(
310 __in unsigned int filter_op,
311 __inout ef10_filter_handle_t *handle)
314 uint8_t payload[MAX(MC_CMD_FILTER_OP_IN_LEN,
315 MC_CMD_FILTER_OP_OUT_LEN)];
318 memset(payload, 0, sizeof (payload));
319 req.emr_cmd = MC_CMD_FILTER_OP;
320 req.emr_in_buf = payload;
321 req.emr_in_length = MC_CMD_FILTER_OP_IN_LEN;
322 req.emr_out_buf = payload;
323 req.emr_out_length = MC_CMD_FILTER_OP_OUT_LEN;
326 case MC_CMD_FILTER_OP_IN_OP_REMOVE:
327 MCDI_IN_SET_DWORD(req, FILTER_OP_IN_OP,
328 MC_CMD_FILTER_OP_IN_OP_REMOVE);
330 case MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE:
331 MCDI_IN_SET_DWORD(req, FILTER_OP_IN_OP,
332 MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE);
340 MCDI_IN_SET_DWORD(req, FILTER_OP_IN_HANDLE_LO, handle->efh_lo);
341 MCDI_IN_SET_DWORD(req, FILTER_OP_IN_HANDLE_HI, handle->efh_hi);
343 efx_mcdi_execute_quiet(enp, &req);
345 if (req.emr_rc != 0) {
350 if (req.emr_out_length_used < MC_CMD_FILTER_OP_OUT_LEN) {
363 EFSYS_PROBE1(fail1, efx_rc_t, rc);
368 static __checkReturn boolean_t
370 __in const efx_filter_spec_t *left,
371 __in const efx_filter_spec_t *right)
373 /* FIXME: Consider rx vs tx filters (look at efs_flags) */
374 if (left->efs_match_flags != right->efs_match_flags)
376 if (!EFX_OWORD_IS_EQUAL(left->efs_rem_host, right->efs_rem_host))
378 if (!EFX_OWORD_IS_EQUAL(left->efs_loc_host, right->efs_loc_host))
380 if (memcmp(left->efs_rem_mac, right->efs_rem_mac, EFX_MAC_ADDR_LEN))
382 if (memcmp(left->efs_loc_mac, right->efs_loc_mac, EFX_MAC_ADDR_LEN))
384 if (left->efs_rem_port != right->efs_rem_port)
386 if (left->efs_loc_port != right->efs_loc_port)
388 if (left->efs_inner_vid != right->efs_inner_vid)
390 if (left->efs_outer_vid != right->efs_outer_vid)
392 if (left->efs_ether_type != right->efs_ether_type)
394 if (left->efs_ip_proto != right->efs_ip_proto)
401 static __checkReturn boolean_t
402 ef10_filter_same_dest(
403 __in const efx_filter_spec_t *left,
404 __in const efx_filter_spec_t *right)
406 if ((left->efs_flags & EFX_FILTER_FLAG_RX_RSS) &&
407 (right->efs_flags & EFX_FILTER_FLAG_RX_RSS)) {
408 if (left->efs_rss_context == right->efs_rss_context)
410 } else if ((~(left->efs_flags) & EFX_FILTER_FLAG_RX_RSS) &&
411 (~(right->efs_flags) & EFX_FILTER_FLAG_RX_RSS)) {
412 if (left->efs_dmaq_id == right->efs_dmaq_id)
418 static __checkReturn uint32_t
420 __in efx_filter_spec_t *spec)
422 EFX_STATIC_ASSERT((sizeof (efx_filter_spec_t) % sizeof (uint32_t))
424 EFX_STATIC_ASSERT((EFX_FIELD_OFFSET(efx_filter_spec_t, efs_outer_vid) %
425 sizeof (uint32_t)) == 0);
428 * As the area of the efx_filter_spec_t we need to hash is DWORD
429 * aligned and an exact number of DWORDs in size we can use the
430 * optimised efx_hash_dwords() rather than efx_hash_bytes()
432 return (efx_hash_dwords((const uint32_t *)&spec->efs_outer_vid,
433 (sizeof (efx_filter_spec_t) -
434 EFX_FIELD_OFFSET(efx_filter_spec_t, efs_outer_vid)) /
435 sizeof (uint32_t), 0));
439 * Decide whether a filter should be exclusive or else should allow
440 * delivery to additional recipients. Currently we decide that
441 * filters for specific local unicast MAC and IP addresses are
444 static __checkReturn boolean_t
445 ef10_filter_is_exclusive(
446 __in efx_filter_spec_t *spec)
448 if ((spec->efs_match_flags & EFX_FILTER_MATCH_LOC_MAC) &&
449 !EFX_MAC_ADDR_IS_MULTICAST(spec->efs_loc_mac))
452 if ((spec->efs_match_flags &
453 (EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_LOC_HOST)) ==
454 (EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_LOC_HOST)) {
455 if ((spec->efs_ether_type == EFX_ETHER_TYPE_IPV4) &&
456 ((spec->efs_loc_host.eo_u8[0] & 0xf) != 0xe))
458 if ((spec->efs_ether_type == EFX_ETHER_TYPE_IPV6) &&
459 (spec->efs_loc_host.eo_u8[0] != 0xff))
466 __checkReturn efx_rc_t
471 efx_filter_spec_t *spec;
472 ef10_filter_table_t *eftp = enp->en_filter.ef_ef10_filter_table;
474 efsys_lock_state_t state;
477 EFSYS_ASSERT(enp->en_family == EFX_FAMILY_HUNTINGTON ||
478 enp->en_family == EFX_FAMILY_MEDFORD);
480 for (tbl_id = 0; tbl_id < EFX_EF10_FILTER_TBL_ROWS; tbl_id++) {
482 EFSYS_LOCK(enp->en_eslp, state);
484 spec = ef10_filter_entry_spec(eftp, tbl_id);
487 } else if (ef10_filter_entry_is_busy(eftp, tbl_id)) {
488 /* Ignore busy entries. */
491 ef10_filter_set_entry_busy(eftp, tbl_id);
495 EFSYS_UNLOCK(enp->en_eslp, state);
497 if (restoring == B_FALSE)
500 if (ef10_filter_is_exclusive(spec)) {
501 rc = efx_mcdi_filter_op_add(enp, spec,
502 MC_CMD_FILTER_OP_IN_OP_INSERT,
503 &eftp->eft_entry[tbl_id].efe_handle);
505 rc = efx_mcdi_filter_op_add(enp, spec,
506 MC_CMD_FILTER_OP_IN_OP_SUBSCRIBE,
507 &eftp->eft_entry[tbl_id].efe_handle);
513 EFSYS_LOCK(enp->en_eslp, state);
515 ef10_filter_set_entry_not_busy(eftp, tbl_id);
517 EFSYS_UNLOCK(enp->en_eslp, state);
523 EFSYS_PROBE1(fail1, efx_rc_t, rc);
529 * An arbitrary search limit for the software hash table. As per the linux net
532 #define EF10_FILTER_SEARCH_LIMIT 200
534 static __checkReturn efx_rc_t
535 ef10_filter_add_internal(
537 __inout efx_filter_spec_t *spec,
538 __in boolean_t may_replace,
539 __out_opt uint32_t *filter_id)
542 ef10_filter_table_t *eftp = enp->en_filter.ef_ef10_filter_table;
543 efx_filter_spec_t *saved_spec;
547 boolean_t replacing = B_FALSE;
549 efsys_lock_state_t state;
550 boolean_t locked = B_FALSE;
552 EFSYS_ASSERT(enp->en_family == EFX_FAMILY_HUNTINGTON ||
553 enp->en_family == EFX_FAMILY_MEDFORD);
555 #if EFSYS_OPT_RX_SCALE
556 spec->efs_rss_context = enp->en_rss_context;
559 hash = ef10_filter_hash(spec);
562 * FIXME: Add support for inserting filters of different priorities
563 * and removing lower priority multicast filters (bug 42378)
567 * Find any existing filters with the same match tuple or
568 * else a free slot to insert at. If any of them are busy,
569 * we have to wait and retry.
574 EFSYS_LOCK(enp->en_eslp, state);
578 i = (hash + depth) & (EFX_EF10_FILTER_TBL_ROWS - 1);
579 saved_spec = ef10_filter_entry_spec(eftp, i);
585 } else if (ef10_filter_equal(spec, saved_spec)) {
586 if (ef10_filter_entry_is_busy(eftp, i))
588 if (saved_spec->efs_priority
589 == EFX_FILTER_PRI_AUTO) {
592 } else if (ef10_filter_is_exclusive(spec)) {
606 * Once we reach the maximum search depth, use
607 * the first suitable slot or return EBUSY if
610 if (depth == EF10_FILTER_SEARCH_LIMIT) {
619 EFSYS_UNLOCK(enp->en_eslp, state);
625 * Create a software table entry if necessary, and mark it
626 * busy. We might yet fail to insert, but any attempt to
627 * insert a conflicting filter while we're waiting for the
628 * firmware must find the busy entry.
630 saved_spec = ef10_filter_entry_spec(eftp, ins_index);
632 if (saved_spec->efs_priority == EFX_FILTER_PRI_AUTO) {
633 /* This is a filter we are refreshing */
634 ef10_filter_set_entry_not_auto_old(eftp, ins_index);
640 EFSYS_KMEM_ALLOC(enp->en_esip, sizeof (*spec), saved_spec);
646 ef10_filter_set_entry(eftp, ins_index, saved_spec);
648 ef10_filter_set_entry_busy(eftp, ins_index);
650 EFSYS_UNLOCK(enp->en_eslp, state);
654 * On replacing the filter handle may change after after a successful
658 rc = efx_mcdi_filter_op_add(enp, spec,
659 MC_CMD_FILTER_OP_IN_OP_REPLACE,
660 &eftp->eft_entry[ins_index].efe_handle);
661 } else if (ef10_filter_is_exclusive(spec)) {
662 rc = efx_mcdi_filter_op_add(enp, spec,
663 MC_CMD_FILTER_OP_IN_OP_INSERT,
664 &eftp->eft_entry[ins_index].efe_handle);
666 rc = efx_mcdi_filter_op_add(enp, spec,
667 MC_CMD_FILTER_OP_IN_OP_SUBSCRIBE,
668 &eftp->eft_entry[ins_index].efe_handle);
674 EFSYS_LOCK(enp->en_eslp, state);
678 /* Update the fields that may differ */
679 saved_spec->efs_priority = spec->efs_priority;
680 saved_spec->efs_flags = spec->efs_flags;
681 saved_spec->efs_rss_context = spec->efs_rss_context;
682 saved_spec->efs_dmaq_id = spec->efs_dmaq_id;
685 ef10_filter_set_entry_not_busy(eftp, ins_index);
689 EFSYS_UNLOCK(enp->en_eslp, state);
693 *filter_id = ins_index;
701 EFSYS_KMEM_FREE(enp->en_esip, sizeof (*spec), saved_spec);
704 ef10_filter_set_entry_not_busy(eftp, ins_index);
705 ef10_filter_set_entry(eftp, ins_index, NULL);
714 EFSYS_PROBE1(fail1, efx_rc_t, rc);
717 EFSYS_UNLOCK(enp->en_eslp, state);
722 __checkReturn efx_rc_t
725 __inout efx_filter_spec_t *spec,
726 __in boolean_t may_replace)
730 rc = ef10_filter_add_internal(enp, spec, may_replace, NULL);
737 EFSYS_PROBE1(fail1, efx_rc_t, rc);
743 static __checkReturn efx_rc_t
744 ef10_filter_delete_internal(
746 __in uint32_t filter_id)
749 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
750 efx_filter_spec_t *spec;
751 efsys_lock_state_t state;
752 uint32_t filter_idx = filter_id % EFX_EF10_FILTER_TBL_ROWS;
755 * Find the software table entry and mark it busy. Don't
756 * remove it yet; any attempt to update while we're waiting
757 * for the firmware must find the busy entry.
759 * FIXME: What if the busy flag is never cleared?
761 EFSYS_LOCK(enp->en_eslp, state);
762 while (ef10_filter_entry_is_busy(table, filter_idx)) {
763 EFSYS_UNLOCK(enp->en_eslp, state);
765 EFSYS_LOCK(enp->en_eslp, state);
767 if ((spec = ef10_filter_entry_spec(table, filter_idx)) != NULL) {
768 ef10_filter_set_entry_busy(table, filter_idx);
770 EFSYS_UNLOCK(enp->en_eslp, state);
778 * Try to remove the hardware filter. This may fail if the MC has
779 * rebooted (which frees all hardware filter resources).
781 if (ef10_filter_is_exclusive(spec)) {
782 rc = efx_mcdi_filter_op_delete(enp,
783 MC_CMD_FILTER_OP_IN_OP_REMOVE,
784 &table->eft_entry[filter_idx].efe_handle);
786 rc = efx_mcdi_filter_op_delete(enp,
787 MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE,
788 &table->eft_entry[filter_idx].efe_handle);
791 /* Free the software table entry */
792 EFSYS_LOCK(enp->en_eslp, state);
793 ef10_filter_set_entry_not_busy(table, filter_idx);
794 ef10_filter_set_entry(table, filter_idx, NULL);
795 EFSYS_UNLOCK(enp->en_eslp, state);
797 EFSYS_KMEM_FREE(enp->en_esip, sizeof (*spec), spec);
799 /* Check result of hardware filter removal */
809 EFSYS_PROBE1(fail1, efx_rc_t, rc);
814 __checkReturn efx_rc_t
817 __inout efx_filter_spec_t *spec)
820 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
821 efx_filter_spec_t *saved_spec;
825 efsys_lock_state_t state;
826 boolean_t locked = B_FALSE;
828 EFSYS_ASSERT(enp->en_family == EFX_FAMILY_HUNTINGTON ||
829 enp->en_family == EFX_FAMILY_MEDFORD);
831 hash = ef10_filter_hash(spec);
833 EFSYS_LOCK(enp->en_eslp, state);
838 i = (hash + depth) & (EFX_EF10_FILTER_TBL_ROWS - 1);
839 saved_spec = ef10_filter_entry_spec(table, i);
840 if (saved_spec && ef10_filter_equal(spec, saved_spec) &&
841 ef10_filter_same_dest(spec, saved_spec)) {
844 if (depth == EF10_FILTER_SEARCH_LIMIT) {
851 EFSYS_UNLOCK(enp->en_eslp, state);
854 rc = ef10_filter_delete_internal(enp, i);
864 EFSYS_PROBE1(fail1, efx_rc_t, rc);
867 EFSYS_UNLOCK(enp->en_eslp, state);
872 static __checkReturn efx_rc_t
873 efx_mcdi_get_parser_disp_info(
875 __out_ecount(buffer_length) uint32_t *buffer,
876 __in size_t buffer_length,
877 __out size_t *list_lengthp)
880 uint8_t payload[MAX(MC_CMD_GET_PARSER_DISP_INFO_IN_LEN,
881 MC_CMD_GET_PARSER_DISP_INFO_OUT_LENMAX)];
882 size_t matches_count;
886 (void) memset(payload, 0, sizeof (payload));
887 req.emr_cmd = MC_CMD_GET_PARSER_DISP_INFO;
888 req.emr_in_buf = payload;
889 req.emr_in_length = MC_CMD_GET_PARSER_DISP_INFO_IN_LEN;
890 req.emr_out_buf = payload;
891 req.emr_out_length = MC_CMD_GET_PARSER_DISP_INFO_OUT_LENMAX;
893 MCDI_IN_SET_DWORD(req, GET_PARSER_DISP_INFO_OUT_OP,
894 MC_CMD_GET_PARSER_DISP_INFO_IN_OP_GET_SUPPORTED_RX_MATCHES);
896 efx_mcdi_execute(enp, &req);
898 if (req.emr_rc != 0) {
903 matches_count = MCDI_OUT_DWORD(req,
904 GET_PARSER_DISP_INFO_OUT_NUM_SUPPORTED_MATCHES);
906 if (req.emr_out_length_used <
907 MC_CMD_GET_PARSER_DISP_INFO_OUT_LEN(matches_count)) {
912 *list_lengthp = matches_count;
914 if (buffer_length < matches_count) {
920 * Check that the elements in the list in the MCDI response are the size
921 * we expect, so we can just copy them directly. Any conversion of the
922 * flags is handled by the caller.
924 EFX_STATIC_ASSERT(sizeof (uint32_t) ==
925 MC_CMD_GET_PARSER_DISP_INFO_OUT_SUPPORTED_MATCHES_LEN);
927 list_size = matches_count *
928 MC_CMD_GET_PARSER_DISP_INFO_OUT_SUPPORTED_MATCHES_LEN;
930 MCDI_OUT2(req, uint32_t,
931 GET_PARSER_DISP_INFO_OUT_SUPPORTED_MATCHES),
941 EFSYS_PROBE1(fail1, efx_rc_t, rc);
946 __checkReturn efx_rc_t
947 ef10_filter_supported_filters(
949 __out_ecount(buffer_length) uint32_t *buffer,
950 __in size_t buffer_length,
951 __out size_t *list_lengthp)
954 size_t mcdi_list_length;
958 uint32_t all_filter_flags =
959 (EFX_FILTER_MATCH_REM_HOST | EFX_FILTER_MATCH_LOC_HOST |
960 EFX_FILTER_MATCH_REM_MAC | EFX_FILTER_MATCH_REM_PORT |
961 EFX_FILTER_MATCH_LOC_MAC | EFX_FILTER_MATCH_LOC_PORT |
962 EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_INNER_VID |
963 EFX_FILTER_MATCH_OUTER_VID | EFX_FILTER_MATCH_IP_PROTO |
964 EFX_FILTER_MATCH_UNKNOWN_MCAST_DST |
965 EFX_FILTER_MATCH_UNKNOWN_UCAST_DST);
967 rc = efx_mcdi_get_parser_disp_info(enp, buffer, buffer_length,
971 /* Pass through mcdi_list_length for the list length */
972 *list_lengthp = mcdi_list_length;
978 * The static assertions in ef10_filter_init() ensure that the values of
979 * the EFX_FILTER_MATCH flags match those used by MCDI, so they don't
980 * need to be converted.
982 * In case support is added to MCDI for additional flags, remove any
983 * matches from the list which include flags we don't support. The order
984 * of the matches is preserved as they are ordered from highest to
987 EFSYS_ASSERT(mcdi_list_length <= buffer_length);
989 for (i = 0; i < mcdi_list_length; i++) {
990 if ((buffer[i] & ~all_filter_flags) == 0) {
991 buffer[list_length] = buffer[i];
996 *list_lengthp = list_length;
1001 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1006 static __checkReturn efx_rc_t
1007 ef10_filter_insert_unicast(
1008 __in efx_nic_t *enp,
1009 __in_ecount(6) uint8_t const *addr,
1010 __in efx_filter_flags_t filter_flags)
1012 ef10_filter_table_t *eftp = enp->en_filter.ef_ef10_filter_table;
1013 efx_filter_spec_t spec;
1016 /* Insert the filter for the local station address */
1017 efx_filter_spec_init_rx(&spec, EFX_FILTER_PRI_AUTO,
1019 eftp->eft_default_rxq);
1020 efx_filter_spec_set_eth_local(&spec, EFX_FILTER_SPEC_VID_UNSPEC, addr);
1022 rc = ef10_filter_add_internal(enp, &spec, B_TRUE,
1023 &eftp->eft_unicst_filter_indexes[eftp->eft_unicst_filter_count]);
1027 eftp->eft_unicst_filter_count++;
1028 EFSYS_ASSERT(eftp->eft_unicst_filter_count <=
1029 EFX_EF10_FILTER_UNICAST_FILTERS_MAX);
1034 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1038 static __checkReturn efx_rc_t
1039 ef10_filter_insert_all_unicast(
1040 __in efx_nic_t *enp,
1041 __in efx_filter_flags_t filter_flags)
1043 ef10_filter_table_t *eftp = enp->en_filter.ef_ef10_filter_table;
1044 efx_filter_spec_t spec;
1047 /* Insert the unknown unicast filter */
1048 efx_filter_spec_init_rx(&spec, EFX_FILTER_PRI_AUTO,
1050 eftp->eft_default_rxq);
1051 efx_filter_spec_set_uc_def(&spec);
1052 rc = ef10_filter_add_internal(enp, &spec, B_TRUE,
1053 &eftp->eft_unicst_filter_indexes[eftp->eft_unicst_filter_count]);
1057 eftp->eft_unicst_filter_count++;
1058 EFSYS_ASSERT(eftp->eft_unicst_filter_count <=
1059 EFX_EF10_FILTER_UNICAST_FILTERS_MAX);
1064 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1068 static __checkReturn efx_rc_t
1069 ef10_filter_insert_multicast_list(
1070 __in efx_nic_t *enp,
1071 __in boolean_t mulcst,
1072 __in boolean_t brdcst,
1073 __in_ecount(6*count) uint8_t const *addrs,
1074 __in uint32_t count,
1075 __in efx_filter_flags_t filter_flags,
1076 __in boolean_t rollback)
1078 ef10_filter_table_t *eftp = enp->en_filter.ef_ef10_filter_table;
1079 efx_filter_spec_t spec;
1082 uint32_t filter_index;
1083 uint32_t filter_count;
1086 if (mulcst == B_FALSE)
1089 if (count + (brdcst ? 1 : 0) >
1090 EFX_ARRAY_SIZE(eftp->eft_mulcst_filter_indexes)) {
1091 /* Too many MAC addresses */
1096 /* Insert/renew multicast address list filters */
1098 for (i = 0; i < count; i++) {
1099 efx_filter_spec_init_rx(&spec,
1100 EFX_FILTER_PRI_AUTO,
1102 eftp->eft_default_rxq);
1104 efx_filter_spec_set_eth_local(&spec,
1105 EFX_FILTER_SPEC_VID_UNSPEC,
1106 &addrs[i * EFX_MAC_ADDR_LEN]);
1108 rc = ef10_filter_add_internal(enp, &spec, B_TRUE,
1112 eftp->eft_mulcst_filter_indexes[filter_count] =
1115 } else if (rollback == B_TRUE) {
1116 /* Only stop upon failure if told to rollback */
1122 if (brdcst == B_TRUE) {
1123 /* Insert/renew broadcast address filter */
1124 efx_filter_spec_init_rx(&spec, EFX_FILTER_PRI_AUTO,
1126 eftp->eft_default_rxq);
1128 EFX_MAC_BROADCAST_ADDR_SET(addr);
1129 efx_filter_spec_set_eth_local(&spec, EFX_FILTER_SPEC_VID_UNSPEC,
1132 rc = ef10_filter_add_internal(enp, &spec, B_TRUE,
1136 eftp->eft_mulcst_filter_indexes[filter_count] =
1139 } else if (rollback == B_TRUE) {
1140 /* Only stop upon failure if told to rollback */
1145 eftp->eft_mulcst_filter_count = filter_count;
1146 eftp->eft_using_all_mulcst = B_FALSE;
1151 /* Remove any filters we have inserted */
1154 (void) ef10_filter_delete_internal(enp,
1155 eftp->eft_mulcst_filter_indexes[i]);
1157 eftp->eft_mulcst_filter_count = 0;
1160 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1165 static __checkReturn efx_rc_t
1166 ef10_filter_insert_all_multicast(
1167 __in efx_nic_t *enp,
1168 __in efx_filter_flags_t filter_flags)
1170 ef10_filter_table_t *eftp = enp->en_filter.ef_ef10_filter_table;
1171 efx_filter_spec_t spec;
1174 /* Insert the unknown multicast filter */
1175 efx_filter_spec_init_rx(&spec, EFX_FILTER_PRI_AUTO,
1177 eftp->eft_default_rxq);
1178 efx_filter_spec_set_mc_def(&spec);
1180 rc = ef10_filter_add_internal(enp, &spec, B_TRUE,
1181 &eftp->eft_mulcst_filter_indexes[0]);
1185 eftp->eft_mulcst_filter_count = 1;
1186 eftp->eft_using_all_mulcst = B_TRUE;
1189 * FIXME: If brdcst == B_FALSE, add a filter to drop broadcast traffic.
1195 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1201 ef10_filter_remove_old(
1202 __in efx_nic_t *enp)
1204 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
1207 for (i = 0; i < EFX_ARRAY_SIZE(table->eft_entry); i++) {
1208 if (ef10_filter_entry_is_auto_old(table, i)) {
1209 (void) ef10_filter_delete_internal(enp, i);
1215 static __checkReturn efx_rc_t
1216 ef10_filter_get_workarounds(
1217 __in efx_nic_t *enp)
1219 efx_nic_cfg_t *encp = &enp->en_nic_cfg;
1220 uint32_t implemented = 0;
1221 uint32_t enabled = 0;
1224 rc = efx_mcdi_get_workarounds(enp, &implemented, &enabled);
1226 /* Check if chained multicast filter support is enabled */
1227 if (implemented & enabled & MC_CMD_GET_WORKAROUNDS_OUT_BUG26807)
1228 encp->enc_bug26807_workaround = B_TRUE;
1230 encp->enc_bug26807_workaround = B_FALSE;
1231 } else if (rc == ENOTSUP) {
1233 * Firmware is too old to support GET_WORKAROUNDS, and support
1234 * for this workaround was implemented later.
1236 encp->enc_bug26807_workaround = B_FALSE;
1244 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1252 * Reconfigure all filters.
1253 * If all_unicst and/or all mulcst filters cannot be applied then
1254 * return ENOTSUP (Note the filters for the specified addresses are
1255 * still applied in this case).
1257 __checkReturn efx_rc_t
1258 ef10_filter_reconfigure(
1259 __in efx_nic_t *enp,
1260 __in_ecount(6) uint8_t const *mac_addr,
1261 __in boolean_t all_unicst,
1262 __in boolean_t mulcst,
1263 __in boolean_t all_mulcst,
1264 __in boolean_t brdcst,
1265 __in_ecount(6*count) uint8_t const *addrs,
1266 __in uint32_t count)
1268 efx_nic_cfg_t *encp = &enp->en_nic_cfg;
1269 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
1270 efx_filter_flags_t filter_flags;
1272 efx_rc_t all_unicst_rc = 0;
1273 efx_rc_t all_mulcst_rc = 0;
1276 if (table->eft_default_rxq == NULL) {
1278 * Filters direct traffic to the default RXQ, and so cannot be
1279 * inserted until it is available. Any currently configured
1280 * filters must be removed (ignore errors in case the MC
1281 * has rebooted, which removes hardware filters).
1283 for (i = 0; i < table->eft_unicst_filter_count; i++) {
1284 (void) ef10_filter_delete_internal(enp,
1285 table->eft_unicst_filter_indexes[i]);
1287 table->eft_unicst_filter_count = 0;
1289 for (i = 0; i < table->eft_mulcst_filter_count; i++) {
1290 (void) ef10_filter_delete_internal(enp,
1291 table->eft_mulcst_filter_indexes[i]);
1293 table->eft_mulcst_filter_count = 0;
1298 if (table->eft_using_rss)
1299 filter_flags = EFX_FILTER_FLAG_RX_RSS;
1303 /* Mark old filters which may need to be removed */
1304 for (i = 0; i < table->eft_unicst_filter_count; i++) {
1305 ef10_filter_set_entry_auto_old(table,
1306 table->eft_unicst_filter_indexes[i]);
1308 for (i = 0; i < table->eft_mulcst_filter_count; i++) {
1309 ef10_filter_set_entry_auto_old(table,
1310 table->eft_mulcst_filter_indexes[i]);
1314 * Insert or renew unicast filters.
1316 * Frimware does not perform chaining on unicast filters. As traffic is
1317 * therefore only delivered to the first matching filter, we should
1318 * always insert the specific filter for our MAC address, to try and
1319 * ensure we get that traffic.
1321 * (If the filter for our MAC address has already been inserted by
1322 * another function, we won't receive traffic sent to us, even if we
1323 * insert a unicast mismatch filter. To prevent traffic stealing, this
1324 * therefore relies on the privilege model only allowing functions to
1325 * insert filters for their own MAC address unless explicitly given
1326 * additional privileges by the user. This also means that, even on a
1327 * priviliged function, inserting a unicast mismatch filter may not
1328 * catch all traffic in multi PCI function scenarios.)
1330 table->eft_unicst_filter_count = 0;
1331 rc = ef10_filter_insert_unicast(enp, mac_addr, filter_flags);
1332 if (all_unicst || (rc != 0)) {
1333 all_unicst_rc = ef10_filter_insert_all_unicast(enp,
1335 if ((rc != 0) && (all_unicst_rc != 0))
1340 * WORKAROUND_BUG26807 controls firmware support for chained multicast
1341 * filters, and can only be enabled or disabled when the hardware filter
1344 * Chained multicast filters require support from the datapath firmware,
1345 * and may not be available (e.g. low-latency variants or old Huntington
1348 * Firmware will reset (FLR) functions which have inserted filters in
1349 * the hardware filter table when the workaround is enabled/disabled.
1350 * Functions without any hardware filters are not reset.
1352 * Re-check if the workaround is enabled after adding unicast hardware
1353 * filters. This ensures that encp->enc_bug26807_workaround matches the
1354 * firmware state, and that later changes to enable/disable the
1355 * workaround will result in this function seeing a reset (FLR).
1357 * In common-code drivers, we only support multiple PCI function
1358 * scenarios with firmware that supports multicast chaining, so we can
1359 * assume it is enabled for such cases and hence simplify the filter
1360 * insertion logic. Firmware that does not support multicast chaining
1361 * does not support multiple PCI function configurations either, so
1362 * filter insertion is much simpler and the same strategies can still be
1365 if ((rc = ef10_filter_get_workarounds(enp)) != 0)
1368 if ((table->eft_using_all_mulcst != all_mulcst) &&
1369 (encp->enc_bug26807_workaround == B_TRUE)) {
1371 * Multicast filter chaining is enabled, so traffic that matches
1372 * more than one multicast filter will be replicated and
1373 * delivered to multiple recipients. To avoid this duplicate
1374 * delivery, remove old multicast filters before inserting new
1375 * multicast filters.
1377 ef10_filter_remove_old(enp);
1380 /* Insert or renew multicast filters */
1381 if (all_mulcst == B_TRUE) {
1383 * Insert the all multicast filter. If that fails, try to insert
1384 * all of our multicast filters (but without rollback on
1387 all_mulcst_rc = ef10_filter_insert_all_multicast(enp,
1389 if (all_mulcst_rc != 0) {
1390 rc = ef10_filter_insert_multicast_list(enp, B_TRUE,
1391 brdcst, addrs, count, filter_flags, B_FALSE);
1397 * Insert filters for multicast addresses.
1398 * If any insertion fails, then rollback and try to insert the
1399 * all multicast filter instead.
1400 * If that also fails, try to insert all of the multicast
1401 * filters (but without rollback on failure).
1403 rc = ef10_filter_insert_multicast_list(enp, mulcst, brdcst,
1404 addrs, count, filter_flags, B_TRUE);
1406 if ((table->eft_using_all_mulcst == B_FALSE) &&
1407 (encp->enc_bug26807_workaround == B_TRUE)) {
1409 * Multicast filter chaining is on, so remove
1410 * old filters before inserting the multicast
1411 * all filter to avoid duplicate delivery caused
1412 * by packets matching multiple filters.
1414 ef10_filter_remove_old(enp);
1417 rc = ef10_filter_insert_all_multicast(enp,
1420 rc = ef10_filter_insert_multicast_list(enp,
1422 addrs, count, filter_flags, B_FALSE);
1429 /* Remove old filters which were not renewed */
1430 ef10_filter_remove_old(enp);
1432 /* report if any optional flags were rejected */
1433 if (((all_unicst != B_FALSE) && (all_unicst_rc != 0)) ||
1434 ((all_mulcst != B_FALSE) && (all_mulcst_rc != 0))) {
1447 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1449 /* Clear auto old flags */
1450 for (i = 0; i < EFX_ARRAY_SIZE(table->eft_entry); i++) {
1451 if (ef10_filter_entry_is_auto_old(table, i)) {
1452 ef10_filter_set_entry_not_auto_old(table, i);
1460 ef10_filter_get_default_rxq(
1461 __in efx_nic_t *enp,
1462 __out efx_rxq_t **erpp,
1463 __out boolean_t *using_rss)
1465 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
1467 *erpp = table->eft_default_rxq;
1468 *using_rss = table->eft_using_rss;
1473 ef10_filter_default_rxq_set(
1474 __in efx_nic_t *enp,
1475 __in efx_rxq_t *erp,
1476 __in boolean_t using_rss)
1478 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
1480 #if EFSYS_OPT_RX_SCALE
1481 EFSYS_ASSERT((using_rss == B_FALSE) ||
1482 (enp->en_rss_context != EF10_RSS_CONTEXT_INVALID));
1483 table->eft_using_rss = using_rss;
1485 EFSYS_ASSERT(using_rss == B_FALSE);
1486 table->eft_using_rss = B_FALSE;
1488 table->eft_default_rxq = erp;
1492 ef10_filter_default_rxq_clear(
1493 __in efx_nic_t *enp)
1495 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
1497 table->eft_default_rxq = NULL;
1498 table->eft_using_rss = B_FALSE;
1502 #endif /* EFSYS_OPT_FILTER */
1504 #endif /* EFSYS_OPT_HUNTINGTON || EFSYS_OPT_MEDFORD */