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));
147 EFSYS_KMEM_ALLOC(enp->en_esip, sizeof (ef10_filter_table_t), eftp);
154 enp->en_filter.ef_ef10_filter_table = eftp;
159 EFSYS_PROBE1(fail1, efx_rc_t, rc);
168 EFSYS_ASSERT(enp->en_family == EFX_FAMILY_HUNTINGTON ||
169 enp->en_family == EFX_FAMILY_MEDFORD);
171 if (enp->en_filter.ef_ef10_filter_table != NULL) {
172 EFSYS_KMEM_FREE(enp->en_esip, sizeof (ef10_filter_table_t),
173 enp->en_filter.ef_ef10_filter_table);
177 static __checkReturn efx_rc_t
178 efx_mcdi_filter_op_add(
180 __in efx_filter_spec_t *spec,
181 __in unsigned int filter_op,
182 __inout ef10_filter_handle_t *handle)
185 uint8_t payload[MAX(MC_CMD_FILTER_OP_IN_LEN,
186 MC_CMD_FILTER_OP_OUT_LEN)];
187 uint32_t match_fields = 0;
190 memset(payload, 0, sizeof (payload));
191 req.emr_cmd = MC_CMD_FILTER_OP;
192 req.emr_in_buf = payload;
193 req.emr_in_length = MC_CMD_FILTER_OP_IN_LEN;
194 req.emr_out_buf = payload;
195 req.emr_out_length = MC_CMD_FILTER_OP_OUT_LEN;
198 case MC_CMD_FILTER_OP_IN_OP_REPLACE:
199 MCDI_IN_SET_DWORD(req, FILTER_OP_IN_HANDLE_LO,
201 MCDI_IN_SET_DWORD(req, FILTER_OP_IN_HANDLE_HI,
204 case MC_CMD_FILTER_OP_IN_OP_INSERT:
205 case MC_CMD_FILTER_OP_IN_OP_SUBSCRIBE:
206 MCDI_IN_SET_DWORD(req, FILTER_OP_IN_OP, filter_op);
214 if (spec->efs_match_flags & EFX_FILTER_MATCH_LOC_MAC_IG) {
216 * The LOC_MAC_IG match flag can represent unknown unicast
217 * or multicast filters - use the MAC address to distinguish
220 if (EFX_MAC_ADDR_IS_MULTICAST(spec->efs_loc_mac))
221 match_fields |= 1U <<
222 MC_CMD_FILTER_OP_IN_MATCH_UNKNOWN_MCAST_DST_LBN;
224 match_fields |= 1U <<
225 MC_CMD_FILTER_OP_IN_MATCH_UNKNOWN_UCAST_DST_LBN;
228 match_fields |= spec->efs_match_flags & (~EFX_FILTER_MATCH_LOC_MAC_IG);
230 MCDI_IN_SET_DWORD(req, FILTER_OP_IN_PORT_ID,
231 EVB_PORT_ID_ASSIGNED);
232 MCDI_IN_SET_DWORD(req, FILTER_OP_IN_MATCH_FIELDS,
234 MCDI_IN_SET_DWORD(req, FILTER_OP_IN_RX_DEST,
235 MC_CMD_FILTER_OP_IN_RX_DEST_HOST);
236 MCDI_IN_SET_DWORD(req, FILTER_OP_IN_RX_QUEUE,
238 if (spec->efs_flags & EFX_FILTER_FLAG_RX_RSS) {
239 MCDI_IN_SET_DWORD(req, FILTER_OP_IN_RX_CONTEXT,
240 spec->efs_rss_context);
242 MCDI_IN_SET_DWORD(req, FILTER_OP_IN_RX_MODE,
243 spec->efs_flags & EFX_FILTER_FLAG_RX_RSS ?
244 MC_CMD_FILTER_OP_IN_RX_MODE_RSS :
245 MC_CMD_FILTER_OP_IN_RX_MODE_SIMPLE);
246 MCDI_IN_SET_DWORD(req, FILTER_OP_IN_TX_DEST,
247 MC_CMD_FILTER_OP_IN_TX_DEST_DEFAULT);
249 if (filter_op != MC_CMD_FILTER_OP_IN_OP_REPLACE) {
251 * NOTE: Unlike most MCDI requests, the filter fields
252 * are presented in network (big endian) byte order.
254 memcpy(MCDI_IN2(req, uint8_t, FILTER_OP_IN_SRC_MAC),
255 spec->efs_rem_mac, EFX_MAC_ADDR_LEN);
256 memcpy(MCDI_IN2(req, uint8_t, FILTER_OP_IN_DST_MAC),
257 spec->efs_loc_mac, EFX_MAC_ADDR_LEN);
259 MCDI_IN_SET_WORD(req, FILTER_OP_IN_SRC_PORT,
260 __CPU_TO_BE_16(spec->efs_rem_port));
261 MCDI_IN_SET_WORD(req, FILTER_OP_IN_DST_PORT,
262 __CPU_TO_BE_16(spec->efs_loc_port));
264 MCDI_IN_SET_WORD(req, FILTER_OP_IN_ETHER_TYPE,
265 __CPU_TO_BE_16(spec->efs_ether_type));
267 MCDI_IN_SET_WORD(req, FILTER_OP_IN_INNER_VLAN,
268 __CPU_TO_BE_16(spec->efs_inner_vid));
269 MCDI_IN_SET_WORD(req, FILTER_OP_IN_OUTER_VLAN,
270 __CPU_TO_BE_16(spec->efs_outer_vid));
272 /* IP protocol (in low byte, high byte is zero) */
273 MCDI_IN_SET_BYTE(req, FILTER_OP_IN_IP_PROTO,
276 EFX_STATIC_ASSERT(sizeof (spec->efs_rem_host) ==
277 MC_CMD_FILTER_OP_IN_SRC_IP_LEN);
278 EFX_STATIC_ASSERT(sizeof (spec->efs_loc_host) ==
279 MC_CMD_FILTER_OP_IN_DST_IP_LEN);
281 memcpy(MCDI_IN2(req, uint8_t, FILTER_OP_IN_SRC_IP),
282 &spec->efs_rem_host.eo_byte[0],
283 MC_CMD_FILTER_OP_IN_SRC_IP_LEN);
284 memcpy(MCDI_IN2(req, uint8_t, FILTER_OP_IN_DST_IP),
285 &spec->efs_loc_host.eo_byte[0],
286 MC_CMD_FILTER_OP_IN_DST_IP_LEN);
289 efx_mcdi_execute(enp, &req);
291 if (req.emr_rc != 0) {
296 if (req.emr_out_length_used < MC_CMD_FILTER_OP_OUT_LEN) {
301 handle->efh_lo = MCDI_OUT_DWORD(req, FILTER_OP_OUT_HANDLE_LO);
302 handle->efh_hi = MCDI_OUT_DWORD(req, FILTER_OP_OUT_HANDLE_HI);
311 EFSYS_PROBE1(fail1, efx_rc_t, rc);
317 static __checkReturn efx_rc_t
318 efx_mcdi_filter_op_delete(
320 __in unsigned int filter_op,
321 __inout ef10_filter_handle_t *handle)
324 uint8_t payload[MAX(MC_CMD_FILTER_OP_IN_LEN,
325 MC_CMD_FILTER_OP_OUT_LEN)];
328 memset(payload, 0, sizeof (payload));
329 req.emr_cmd = MC_CMD_FILTER_OP;
330 req.emr_in_buf = payload;
331 req.emr_in_length = MC_CMD_FILTER_OP_IN_LEN;
332 req.emr_out_buf = payload;
333 req.emr_out_length = MC_CMD_FILTER_OP_OUT_LEN;
336 case MC_CMD_FILTER_OP_IN_OP_REMOVE:
337 MCDI_IN_SET_DWORD(req, FILTER_OP_IN_OP,
338 MC_CMD_FILTER_OP_IN_OP_REMOVE);
340 case MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE:
341 MCDI_IN_SET_DWORD(req, FILTER_OP_IN_OP,
342 MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE);
350 MCDI_IN_SET_DWORD(req, FILTER_OP_IN_HANDLE_LO, handle->efh_lo);
351 MCDI_IN_SET_DWORD(req, FILTER_OP_IN_HANDLE_HI, handle->efh_hi);
353 efx_mcdi_execute_quiet(enp, &req);
355 if (req.emr_rc != 0) {
360 if (req.emr_out_length_used < MC_CMD_FILTER_OP_OUT_LEN) {
373 EFSYS_PROBE1(fail1, efx_rc_t, rc);
378 static __checkReturn boolean_t
380 __in const efx_filter_spec_t *left,
381 __in const efx_filter_spec_t *right)
383 /* FIXME: Consider rx vs tx filters (look at efs_flags) */
384 if (left->efs_match_flags != right->efs_match_flags)
386 if (!EFX_OWORD_IS_EQUAL(left->efs_rem_host, right->efs_rem_host))
388 if (!EFX_OWORD_IS_EQUAL(left->efs_loc_host, right->efs_loc_host))
390 if (memcmp(left->efs_rem_mac, right->efs_rem_mac, EFX_MAC_ADDR_LEN))
392 if (memcmp(left->efs_loc_mac, right->efs_loc_mac, EFX_MAC_ADDR_LEN))
394 if (left->efs_rem_port != right->efs_rem_port)
396 if (left->efs_loc_port != right->efs_loc_port)
398 if (left->efs_inner_vid != right->efs_inner_vid)
400 if (left->efs_outer_vid != right->efs_outer_vid)
402 if (left->efs_ether_type != right->efs_ether_type)
404 if (left->efs_ip_proto != right->efs_ip_proto)
411 static __checkReturn boolean_t
412 ef10_filter_same_dest(
413 __in const efx_filter_spec_t *left,
414 __in const efx_filter_spec_t *right)
416 if ((left->efs_flags & EFX_FILTER_FLAG_RX_RSS) &&
417 (right->efs_flags & EFX_FILTER_FLAG_RX_RSS)) {
418 if (left->efs_rss_context == right->efs_rss_context)
420 } else if ((~(left->efs_flags) & EFX_FILTER_FLAG_RX_RSS) &&
421 (~(right->efs_flags) & EFX_FILTER_FLAG_RX_RSS)) {
422 if (left->efs_dmaq_id == right->efs_dmaq_id)
428 static __checkReturn uint32_t
430 __in efx_filter_spec_t *spec)
432 EFX_STATIC_ASSERT((sizeof (efx_filter_spec_t) % sizeof (uint32_t))
434 EFX_STATIC_ASSERT((EFX_FIELD_OFFSET(efx_filter_spec_t, efs_outer_vid) %
435 sizeof (uint32_t)) == 0);
438 * As the area of the efx_filter_spec_t we need to hash is DWORD
439 * aligned and an exact number of DWORDs in size we can use the
440 * optimised efx_hash_dwords() rather than efx_hash_bytes()
442 return (efx_hash_dwords((const uint32_t *)&spec->efs_outer_vid,
443 (sizeof (efx_filter_spec_t) -
444 EFX_FIELD_OFFSET(efx_filter_spec_t, efs_outer_vid)) /
445 sizeof (uint32_t), 0));
449 * Decide whether a filter should be exclusive or else should allow
450 * delivery to additional recipients. Currently we decide that
451 * filters for specific local unicast MAC and IP addresses are
454 static __checkReturn boolean_t
455 ef10_filter_is_exclusive(
456 __in efx_filter_spec_t *spec)
458 if ((spec->efs_match_flags & EFX_FILTER_MATCH_LOC_MAC) &&
459 !EFX_MAC_ADDR_IS_MULTICAST(spec->efs_loc_mac))
462 if ((spec->efs_match_flags &
463 (EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_LOC_HOST)) ==
464 (EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_LOC_HOST)) {
465 if ((spec->efs_ether_type == EFX_ETHER_TYPE_IPV4) &&
466 ((spec->efs_loc_host.eo_u8[0] & 0xf) != 0xe))
468 if ((spec->efs_ether_type == EFX_ETHER_TYPE_IPV6) &&
469 (spec->efs_loc_host.eo_u8[0] != 0xff))
476 __checkReturn efx_rc_t
481 efx_filter_spec_t *spec;
482 ef10_filter_table_t *eftp = enp->en_filter.ef_ef10_filter_table;
484 efsys_lock_state_t state;
487 EFSYS_ASSERT(enp->en_family == EFX_FAMILY_HUNTINGTON ||
488 enp->en_family == EFX_FAMILY_MEDFORD);
490 for (tbl_id = 0; tbl_id < EFX_EF10_FILTER_TBL_ROWS; tbl_id++) {
492 EFSYS_LOCK(enp->en_eslp, state);
494 spec = ef10_filter_entry_spec(eftp, tbl_id);
497 } else if (ef10_filter_entry_is_busy(eftp, tbl_id)) {
498 /* Ignore busy entries. */
501 ef10_filter_set_entry_busy(eftp, tbl_id);
505 EFSYS_UNLOCK(enp->en_eslp, state);
507 if (restoring == B_FALSE)
510 if (ef10_filter_is_exclusive(spec)) {
511 rc = efx_mcdi_filter_op_add(enp, spec,
512 MC_CMD_FILTER_OP_IN_OP_INSERT,
513 &eftp->eft_entry[tbl_id].efe_handle);
515 rc = efx_mcdi_filter_op_add(enp, spec,
516 MC_CMD_FILTER_OP_IN_OP_SUBSCRIBE,
517 &eftp->eft_entry[tbl_id].efe_handle);
523 EFSYS_LOCK(enp->en_eslp, state);
525 ef10_filter_set_entry_not_busy(eftp, tbl_id);
527 EFSYS_UNLOCK(enp->en_eslp, state);
533 EFSYS_PROBE1(fail1, efx_rc_t, rc);
539 * An arbitrary search limit for the software hash table. As per the linux net
542 #define EF10_FILTER_SEARCH_LIMIT 200
544 static __checkReturn efx_rc_t
545 ef10_filter_add_internal(
547 __inout efx_filter_spec_t *spec,
548 __in boolean_t may_replace,
549 __out_opt uint32_t *filter_id)
552 ef10_filter_table_t *eftp = enp->en_filter.ef_ef10_filter_table;
553 efx_filter_spec_t *saved_spec;
557 boolean_t replacing = B_FALSE;
559 efsys_lock_state_t state;
560 boolean_t locked = B_FALSE;
562 EFSYS_ASSERT(enp->en_family == EFX_FAMILY_HUNTINGTON ||
563 enp->en_family == EFX_FAMILY_MEDFORD);
565 #if EFSYS_OPT_RX_SCALE
566 spec->efs_rss_context = enp->en_rss_context;
569 hash = ef10_filter_hash(spec);
572 * FIXME: Add support for inserting filters of different priorities
573 * and removing lower priority multicast filters (bug 42378)
577 * Find any existing filters with the same match tuple or
578 * else a free slot to insert at. If any of them are busy,
579 * we have to wait and retry.
584 EFSYS_LOCK(enp->en_eslp, state);
588 i = (hash + depth) & (EFX_EF10_FILTER_TBL_ROWS - 1);
589 saved_spec = ef10_filter_entry_spec(eftp, i);
595 } else if (ef10_filter_equal(spec, saved_spec)) {
596 if (ef10_filter_entry_is_busy(eftp, i))
598 if (saved_spec->efs_priority
599 == EFX_FILTER_PRI_AUTO) {
602 } else if (ef10_filter_is_exclusive(spec)) {
616 * Once we reach the maximum search depth, use
617 * the first suitable slot or return EBUSY if
620 if (depth == EF10_FILTER_SEARCH_LIMIT) {
629 EFSYS_UNLOCK(enp->en_eslp, state);
635 * Create a software table entry if necessary, and mark it
636 * busy. We might yet fail to insert, but any attempt to
637 * insert a conflicting filter while we're waiting for the
638 * firmware must find the busy entry.
640 saved_spec = ef10_filter_entry_spec(eftp, ins_index);
642 if (saved_spec->efs_priority == EFX_FILTER_PRI_AUTO) {
643 /* This is a filter we are refreshing */
644 ef10_filter_set_entry_not_auto_old(eftp, ins_index);
650 EFSYS_KMEM_ALLOC(enp->en_esip, sizeof (*spec), saved_spec);
656 ef10_filter_set_entry(eftp, ins_index, saved_spec);
658 ef10_filter_set_entry_busy(eftp, ins_index);
660 EFSYS_UNLOCK(enp->en_eslp, state);
664 * On replacing the filter handle may change after after a successful
668 rc = efx_mcdi_filter_op_add(enp, spec,
669 MC_CMD_FILTER_OP_IN_OP_REPLACE,
670 &eftp->eft_entry[ins_index].efe_handle);
671 } else if (ef10_filter_is_exclusive(spec)) {
672 rc = efx_mcdi_filter_op_add(enp, spec,
673 MC_CMD_FILTER_OP_IN_OP_INSERT,
674 &eftp->eft_entry[ins_index].efe_handle);
676 rc = efx_mcdi_filter_op_add(enp, spec,
677 MC_CMD_FILTER_OP_IN_OP_SUBSCRIBE,
678 &eftp->eft_entry[ins_index].efe_handle);
684 EFSYS_LOCK(enp->en_eslp, state);
688 /* Update the fields that may differ */
689 saved_spec->efs_priority = spec->efs_priority;
690 saved_spec->efs_flags = spec->efs_flags;
691 saved_spec->efs_rss_context = spec->efs_rss_context;
692 saved_spec->efs_dmaq_id = spec->efs_dmaq_id;
695 ef10_filter_set_entry_not_busy(eftp, ins_index);
699 EFSYS_UNLOCK(enp->en_eslp, state);
703 *filter_id = ins_index;
711 EFSYS_KMEM_FREE(enp->en_esip, sizeof (*spec), saved_spec);
714 ef10_filter_set_entry_not_busy(eftp, ins_index);
715 ef10_filter_set_entry(eftp, ins_index, NULL);
724 EFSYS_PROBE1(fail1, efx_rc_t, rc);
727 EFSYS_UNLOCK(enp->en_eslp, state);
732 __checkReturn efx_rc_t
735 __inout efx_filter_spec_t *spec,
736 __in boolean_t may_replace)
740 rc = ef10_filter_add_internal(enp, spec, may_replace, NULL);
747 EFSYS_PROBE1(fail1, efx_rc_t, rc);
753 static __checkReturn efx_rc_t
754 ef10_filter_delete_internal(
756 __in uint32_t filter_id)
759 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
760 efx_filter_spec_t *spec;
761 efsys_lock_state_t state;
762 uint32_t filter_idx = filter_id % EFX_EF10_FILTER_TBL_ROWS;
765 * Find the software table entry and mark it busy. Don't
766 * remove it yet; any attempt to update while we're waiting
767 * for the firmware must find the busy entry.
769 * FIXME: What if the busy flag is never cleared?
771 EFSYS_LOCK(enp->en_eslp, state);
772 while (ef10_filter_entry_is_busy(table, filter_idx)) {
773 EFSYS_UNLOCK(enp->en_eslp, state);
775 EFSYS_LOCK(enp->en_eslp, state);
777 if ((spec = ef10_filter_entry_spec(table, filter_idx)) != NULL) {
778 ef10_filter_set_entry_busy(table, filter_idx);
780 EFSYS_UNLOCK(enp->en_eslp, state);
788 * Try to remove the hardware filter. This may fail if the MC has
789 * rebooted (which frees all hardware filter resources).
791 if (ef10_filter_is_exclusive(spec)) {
792 rc = efx_mcdi_filter_op_delete(enp,
793 MC_CMD_FILTER_OP_IN_OP_REMOVE,
794 &table->eft_entry[filter_idx].efe_handle);
796 rc = efx_mcdi_filter_op_delete(enp,
797 MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE,
798 &table->eft_entry[filter_idx].efe_handle);
801 /* Free the software table entry */
802 EFSYS_LOCK(enp->en_eslp, state);
803 ef10_filter_set_entry_not_busy(table, filter_idx);
804 ef10_filter_set_entry(table, filter_idx, NULL);
805 EFSYS_UNLOCK(enp->en_eslp, state);
807 EFSYS_KMEM_FREE(enp->en_esip, sizeof (*spec), spec);
809 /* Check result of hardware filter removal */
819 EFSYS_PROBE1(fail1, efx_rc_t, rc);
824 __checkReturn efx_rc_t
827 __inout efx_filter_spec_t *spec)
830 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
831 efx_filter_spec_t *saved_spec;
835 efsys_lock_state_t state;
836 boolean_t locked = B_FALSE;
838 EFSYS_ASSERT(enp->en_family == EFX_FAMILY_HUNTINGTON ||
839 enp->en_family == EFX_FAMILY_MEDFORD);
841 hash = ef10_filter_hash(spec);
843 EFSYS_LOCK(enp->en_eslp, state);
848 i = (hash + depth) & (EFX_EF10_FILTER_TBL_ROWS - 1);
849 saved_spec = ef10_filter_entry_spec(table, i);
850 if (saved_spec && ef10_filter_equal(spec, saved_spec) &&
851 ef10_filter_same_dest(spec, saved_spec)) {
854 if (depth == EF10_FILTER_SEARCH_LIMIT) {
861 EFSYS_UNLOCK(enp->en_eslp, state);
864 rc = ef10_filter_delete_internal(enp, i);
874 EFSYS_PROBE1(fail1, efx_rc_t, rc);
877 EFSYS_UNLOCK(enp->en_eslp, state);
882 static __checkReturn efx_rc_t
883 efx_mcdi_get_parser_disp_info(
885 __out uint32_t *list,
886 __out size_t *length)
889 uint8_t payload[MAX(MC_CMD_GET_PARSER_DISP_INFO_IN_LEN,
890 MC_CMD_GET_PARSER_DISP_INFO_OUT_LENMAX)];
893 boolean_t support_unknown_ucast = B_FALSE;
894 boolean_t support_unknown_mcast = B_FALSE;
896 (void) memset(payload, 0, sizeof (payload));
897 req.emr_cmd = MC_CMD_GET_PARSER_DISP_INFO;
898 req.emr_in_buf = payload;
899 req.emr_in_length = MC_CMD_GET_PARSER_DISP_INFO_IN_LEN;
900 req.emr_out_buf = payload;
901 req.emr_out_length = MC_CMD_GET_PARSER_DISP_INFO_OUT_LENMAX;
903 MCDI_IN_SET_DWORD(req, GET_PARSER_DISP_INFO_OUT_OP,
904 MC_CMD_GET_PARSER_DISP_INFO_IN_OP_GET_SUPPORTED_RX_MATCHES);
906 efx_mcdi_execute(enp, &req);
908 if (req.emr_rc != 0) {
913 *length = MCDI_OUT_DWORD(req,
914 GET_PARSER_DISP_INFO_OUT_NUM_SUPPORTED_MATCHES);
916 if (req.emr_out_length_used <
917 MC_CMD_GET_PARSER_DISP_INFO_OUT_LEN(*length)) {
925 GET_PARSER_DISP_INFO_OUT_SUPPORTED_MATCHES),
926 (*length) * sizeof (uint32_t));
927 EFX_STATIC_ASSERT(sizeof (uint32_t) ==
928 MC_CMD_GET_PARSER_DISP_INFO_OUT_SUPPORTED_MATCHES_LEN);
931 * Remove UNKNOWN UCAST and MCAST flags, and if both are present, change
932 * the lower priority one to LOC_MAC_IG.
934 for (i = 0; i < *length; i++) {
935 if (list[i] & MC_CMD_FILTER_OP_IN_MATCH_UNKNOWN_UCAST_DST_LBN) {
937 (~MC_CMD_FILTER_OP_IN_MATCH_UNKNOWN_UCAST_DST_LBN);
938 support_unknown_ucast = B_TRUE;
940 if (list[i] & MC_CMD_FILTER_OP_IN_MATCH_UNKNOWN_MCAST_DST_LBN) {
942 (~MC_CMD_FILTER_OP_IN_MATCH_UNKNOWN_MCAST_DST_LBN);
943 support_unknown_mcast = B_TRUE;
946 if (support_unknown_ucast && support_unknown_mcast) {
947 list[i] &= EFX_FILTER_MATCH_LOC_MAC_IG;
957 EFSYS_PROBE1(fail1, efx_rc_t, rc);
962 __checkReturn efx_rc_t
963 ef10_filter_supported_filters(
965 __out uint32_t *list,
966 __out size_t *length)
970 if ((rc = efx_mcdi_get_parser_disp_info(enp, list, length)) != 0)
976 EFSYS_PROBE1(fail1, efx_rc_t, rc);
981 static __checkReturn efx_rc_t
982 ef10_filter_insert_unicast(
984 __in_ecount(6) uint8_t const *addr,
985 __in efx_filter_flags_t filter_flags)
987 ef10_filter_table_t *eftp = enp->en_filter.ef_ef10_filter_table;
988 efx_filter_spec_t spec;
991 /* Insert the filter for the local station address */
992 efx_filter_spec_init_rx(&spec, EFX_FILTER_PRI_AUTO,
994 eftp->eft_default_rxq);
995 efx_filter_spec_set_eth_local(&spec, EFX_FILTER_SPEC_VID_UNSPEC, addr);
997 rc = ef10_filter_add_internal(enp, &spec, B_TRUE,
998 &eftp->eft_unicst_filter_indexes[eftp->eft_unicst_filter_count]);
1002 eftp->eft_unicst_filter_count++;
1003 EFSYS_ASSERT(eftp->eft_unicst_filter_count <=
1004 EFX_EF10_FILTER_UNICAST_FILTERS_MAX);
1009 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1013 static __checkReturn efx_rc_t
1014 ef10_filter_insert_all_unicast(
1015 __in efx_nic_t *enp,
1016 __in efx_filter_flags_t filter_flags)
1018 ef10_filter_table_t *eftp = enp->en_filter.ef_ef10_filter_table;
1019 efx_filter_spec_t spec;
1022 /* Insert the unknown unicast filter */
1023 efx_filter_spec_init_rx(&spec, EFX_FILTER_PRI_AUTO,
1025 eftp->eft_default_rxq);
1026 efx_filter_spec_set_uc_def(&spec);
1027 rc = ef10_filter_add_internal(enp, &spec, B_TRUE,
1028 &eftp->eft_unicst_filter_indexes[eftp->eft_unicst_filter_count]);
1032 eftp->eft_unicst_filter_count++;
1033 EFSYS_ASSERT(eftp->eft_unicst_filter_count <=
1034 EFX_EF10_FILTER_UNICAST_FILTERS_MAX);
1039 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1043 static __checkReturn efx_rc_t
1044 ef10_filter_insert_multicast_list(
1045 __in efx_nic_t *enp,
1046 __in boolean_t mulcst,
1047 __in boolean_t brdcst,
1048 __in_ecount(6*count) uint8_t const *addrs,
1049 __in uint32_t count,
1050 __in efx_filter_flags_t filter_flags,
1051 __in boolean_t rollback)
1053 ef10_filter_table_t *eftp = enp->en_filter.ef_ef10_filter_table;
1054 efx_filter_spec_t spec;
1057 uint32_t filter_index;
1058 uint32_t filter_count;
1061 if (mulcst == B_FALSE)
1064 if (count + (brdcst ? 1 : 0) >
1065 EFX_ARRAY_SIZE(eftp->eft_mulcst_filter_indexes)) {
1066 /* Too many MAC addresses */
1071 /* Insert/renew multicast address list filters */
1073 for (i = 0; i < count; i++) {
1074 efx_filter_spec_init_rx(&spec,
1075 EFX_FILTER_PRI_AUTO,
1077 eftp->eft_default_rxq);
1079 efx_filter_spec_set_eth_local(&spec,
1080 EFX_FILTER_SPEC_VID_UNSPEC,
1081 &addrs[i * EFX_MAC_ADDR_LEN]);
1083 rc = ef10_filter_add_internal(enp, &spec, B_TRUE,
1087 eftp->eft_mulcst_filter_indexes[filter_count] =
1090 } else if (rollback == B_TRUE) {
1091 /* Only stop upon failure if told to rollback */
1097 if (brdcst == B_TRUE) {
1098 /* Insert/renew broadcast address filter */
1099 efx_filter_spec_init_rx(&spec, EFX_FILTER_PRI_AUTO,
1101 eftp->eft_default_rxq);
1103 EFX_MAC_BROADCAST_ADDR_SET(addr);
1104 efx_filter_spec_set_eth_local(&spec, EFX_FILTER_SPEC_VID_UNSPEC,
1107 rc = ef10_filter_add_internal(enp, &spec, B_TRUE,
1111 eftp->eft_mulcst_filter_indexes[filter_count] =
1114 } else if (rollback == B_TRUE) {
1115 /* Only stop upon failure if told to rollback */
1120 eftp->eft_mulcst_filter_count = filter_count;
1121 eftp->eft_using_all_mulcst = B_FALSE;
1126 /* Remove any filters we have inserted */
1129 (void) ef10_filter_delete_internal(enp,
1130 eftp->eft_mulcst_filter_indexes[i]);
1132 eftp->eft_mulcst_filter_count = 0;
1135 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1140 static __checkReturn efx_rc_t
1141 ef10_filter_insert_all_multicast(
1142 __in efx_nic_t *enp,
1143 __in efx_filter_flags_t filter_flags)
1145 ef10_filter_table_t *eftp = enp->en_filter.ef_ef10_filter_table;
1146 efx_filter_spec_t spec;
1149 /* Insert the unknown multicast filter */
1150 efx_filter_spec_init_rx(&spec, EFX_FILTER_PRI_AUTO,
1152 eftp->eft_default_rxq);
1153 efx_filter_spec_set_mc_def(&spec);
1155 rc = ef10_filter_add_internal(enp, &spec, B_TRUE,
1156 &eftp->eft_mulcst_filter_indexes[0]);
1160 eftp->eft_mulcst_filter_count = 1;
1161 eftp->eft_using_all_mulcst = B_TRUE;
1164 * FIXME: If brdcst == B_FALSE, add a filter to drop broadcast traffic.
1170 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1176 ef10_filter_remove_old(
1177 __in efx_nic_t *enp)
1179 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
1182 for (i = 0; i < EFX_ARRAY_SIZE(table->eft_entry); i++) {
1183 if (ef10_filter_entry_is_auto_old(table, i)) {
1184 (void) ef10_filter_delete_internal(enp, i);
1190 static __checkReturn efx_rc_t
1191 ef10_filter_get_workarounds(
1192 __in efx_nic_t *enp)
1194 efx_nic_cfg_t *encp = &enp->en_nic_cfg;
1195 uint32_t implemented = 0;
1196 uint32_t enabled = 0;
1199 rc = efx_mcdi_get_workarounds(enp, &implemented, &enabled);
1201 /* Check if chained multicast filter support is enabled */
1202 if (implemented & enabled & MC_CMD_GET_WORKAROUNDS_OUT_BUG26807)
1203 encp->enc_bug26807_workaround = B_TRUE;
1205 encp->enc_bug26807_workaround = B_FALSE;
1206 } else if (rc == ENOTSUP) {
1208 * Firmware is too old to support GET_WORKAROUNDS, and support
1209 * for this workaround was implemented later.
1211 encp->enc_bug26807_workaround = B_FALSE;
1219 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1227 * Reconfigure all filters.
1228 * If all_unicst and/or all mulcst filters cannot be applied then
1229 * return ENOTSUP (Note the filters for the specified addresses are
1230 * still applied in this case).
1232 __checkReturn efx_rc_t
1233 ef10_filter_reconfigure(
1234 __in efx_nic_t *enp,
1235 __in_ecount(6) uint8_t const *mac_addr,
1236 __in boolean_t all_unicst,
1237 __in boolean_t mulcst,
1238 __in boolean_t all_mulcst,
1239 __in boolean_t brdcst,
1240 __in_ecount(6*count) uint8_t const *addrs,
1241 __in uint32_t count)
1243 efx_nic_cfg_t *encp = &enp->en_nic_cfg;
1244 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
1245 efx_filter_flags_t filter_flags;
1247 efx_rc_t all_unicst_rc = 0;
1248 efx_rc_t all_mulcst_rc = 0;
1251 if (table->eft_default_rxq == NULL) {
1253 * Filters direct traffic to the default RXQ, and so cannot be
1254 * inserted until it is available. Any currently configured
1255 * filters must be removed (ignore errors in case the MC
1256 * has rebooted, which removes hardware filters).
1258 for (i = 0; i < table->eft_unicst_filter_count; i++) {
1259 (void) ef10_filter_delete_internal(enp,
1260 table->eft_unicst_filter_indexes[i]);
1262 table->eft_unicst_filter_count = 0;
1264 for (i = 0; i < table->eft_mulcst_filter_count; i++) {
1265 (void) ef10_filter_delete_internal(enp,
1266 table->eft_mulcst_filter_indexes[i]);
1268 table->eft_mulcst_filter_count = 0;
1273 if (table->eft_using_rss)
1274 filter_flags = EFX_FILTER_FLAG_RX_RSS;
1278 /* Mark old filters which may need to be removed */
1279 for (i = 0; i < table->eft_unicst_filter_count; i++) {
1280 ef10_filter_set_entry_auto_old(table,
1281 table->eft_unicst_filter_indexes[i]);
1283 for (i = 0; i < table->eft_mulcst_filter_count; i++) {
1284 ef10_filter_set_entry_auto_old(table,
1285 table->eft_mulcst_filter_indexes[i]);
1289 * Insert or renew unicast filters.
1291 * Frimware does not perform chaining on unicast filters. As traffic is
1292 * therefore only delivered to the first matching filter, we should
1293 * always insert the specific filter for our MAC address, to try and
1294 * ensure we get that traffic.
1296 * (If the filter for our MAC address has already been inserted by
1297 * another function, we won't receive traffic sent to us, even if we
1298 * insert a unicast mismatch filter. To prevent traffic stealing, this
1299 * therefore relies on the privilege model only allowing functions to
1300 * insert filters for their own MAC address unless explicitly given
1301 * additional privileges by the user. This also means that, even on a
1302 * priviliged function, inserting a unicast mismatch filter may not
1303 * catch all traffic in multi PCI function scenarios.)
1305 table->eft_unicst_filter_count = 0;
1306 rc = ef10_filter_insert_unicast(enp, mac_addr, filter_flags);
1307 if (all_unicst || (rc != 0)) {
1308 all_unicst_rc = ef10_filter_insert_all_unicast(enp,
1310 if ((rc != 0) && (all_unicst_rc != 0))
1315 * WORKAROUND_BUG26807 controls firmware support for chained multicast
1316 * filters, and can only be enabled or disabled when the hardware filter
1319 * Chained multicast filters require support from the datapath firmware,
1320 * and may not be available (e.g. low-latency variants or old Huntington
1323 * Firmware will reset (FLR) functions which have inserted filters in
1324 * the hardware filter table when the workaround is enabled/disabled.
1325 * Functions without any hardware filters are not reset.
1327 * Re-check if the workaround is enabled after adding unicast hardware
1328 * filters. This ensures that encp->enc_bug26807_workaround matches the
1329 * firmware state, and that later changes to enable/disable the
1330 * workaround will result in this function seeing a reset (FLR).
1332 * In common-code drivers, we only support multiple PCI function
1333 * scenarios with firmware that supports multicast chaining, so we can
1334 * assume it is enabled for such cases and hence simplify the filter
1335 * insertion logic. Firmware that does not support multicast chaining
1336 * does not support multiple PCI function configurations either, so
1337 * filter insertion is much simpler and the same strategies can still be
1340 if ((rc = ef10_filter_get_workarounds(enp)) != 0)
1343 if ((table->eft_using_all_mulcst != all_mulcst) &&
1344 (encp->enc_bug26807_workaround == B_TRUE)) {
1346 * Multicast filter chaining is enabled, so traffic that matches
1347 * more than one multicast filter will be replicated and
1348 * delivered to multiple recipients. To avoid this duplicate
1349 * delivery, remove old multicast filters before inserting new
1350 * multicast filters.
1352 ef10_filter_remove_old(enp);
1355 /* Insert or renew multicast filters */
1356 if (all_mulcst == B_TRUE) {
1358 * Insert the all multicast filter. If that fails, try to insert
1359 * all of our multicast filters (but without rollback on
1362 all_mulcst_rc = ef10_filter_insert_all_multicast(enp,
1364 if (all_mulcst_rc != 0) {
1365 rc = ef10_filter_insert_multicast_list(enp, B_TRUE,
1366 brdcst, addrs, count, filter_flags, B_FALSE);
1372 * Insert filters for multicast addresses.
1373 * If any insertion fails, then rollback and try to insert the
1374 * all multicast filter instead.
1375 * If that also fails, try to insert all of the multicast
1376 * filters (but without rollback on failure).
1378 rc = ef10_filter_insert_multicast_list(enp, mulcst, brdcst,
1379 addrs, count, filter_flags, B_TRUE);
1381 if ((table->eft_using_all_mulcst == B_FALSE) &&
1382 (encp->enc_bug26807_workaround == B_TRUE)) {
1384 * Multicast filter chaining is on, so remove
1385 * old filters before inserting the multicast
1386 * all filter to avoid duplicate delivery caused
1387 * by packets matching multiple filters.
1389 ef10_filter_remove_old(enp);
1392 rc = ef10_filter_insert_all_multicast(enp,
1395 rc = ef10_filter_insert_multicast_list(enp,
1397 addrs, count, filter_flags, B_FALSE);
1404 /* Remove old filters which were not renewed */
1405 ef10_filter_remove_old(enp);
1407 /* report if any optional flags were rejected */
1408 if (((all_unicst != B_FALSE) && (all_unicst_rc != 0)) ||
1409 ((all_mulcst != B_FALSE) && (all_mulcst_rc != 0))) {
1422 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1424 /* Clear auto old flags */
1425 for (i = 0; i < EFX_ARRAY_SIZE(table->eft_entry); i++) {
1426 if (ef10_filter_entry_is_auto_old(table, i)) {
1427 ef10_filter_set_entry_not_auto_old(table, i);
1435 ef10_filter_get_default_rxq(
1436 __in efx_nic_t *enp,
1437 __out efx_rxq_t **erpp,
1438 __out boolean_t *using_rss)
1440 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
1442 *erpp = table->eft_default_rxq;
1443 *using_rss = table->eft_using_rss;
1448 ef10_filter_default_rxq_set(
1449 __in efx_nic_t *enp,
1450 __in efx_rxq_t *erp,
1451 __in boolean_t using_rss)
1453 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
1455 #if EFSYS_OPT_RX_SCALE
1456 EFSYS_ASSERT((using_rss == B_FALSE) ||
1457 (enp->en_rss_context != EF10_RSS_CONTEXT_INVALID));
1458 table->eft_using_rss = using_rss;
1460 EFSYS_ASSERT(using_rss == B_FALSE);
1461 table->eft_using_rss = B_FALSE;
1463 table->eft_default_rxq = erp;
1467 ef10_filter_default_rxq_clear(
1468 __in efx_nic_t *enp)
1470 ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
1472 table->eft_default_rxq = NULL;
1473 table->eft_using_rss = B_FALSE;
1477 #endif /* EFSYS_OPT_FILTER */
1479 #endif /* EFSYS_OPT_HUNTINGTON || EFSYS_OPT_MEDFORD */