2 * Copyright (c) 2007-2015 Solarflare Communications Inc.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
16 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
18 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
21 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
22 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
24 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 * The views and conclusions contained in the software and documentation are
27 * those of the authors and should not be interpreted as representing official
28 * policies, either expressed or implied, of the FreeBSD Project.
31 #include <sys/cdefs.h>
32 __FBSDID("$FreeBSD$");
36 #include "efx_types.h"
37 #include "efx_regs_mcdi.h"
40 #if EFSYS_OPT_HUNTINGTON
44 #define HFE_SPEC(hftp, index) ((hftp)->hft_entry[(index)].hfe_spec)
46 static efx_filter_spec_t *
47 hunt_filter_entry_spec(
48 __in const hunt_filter_table_t *hftp,
49 __in unsigned int index)
51 return ((efx_filter_spec_t *)(HFE_SPEC(hftp, index) &
52 ~(uintptr_t)EFX_HUNT_FILTER_FLAGS));
56 hunt_filter_entry_is_busy(
57 __in const hunt_filter_table_t *hftp,
58 __in unsigned int index)
60 if (HFE_SPEC(hftp, index) & EFX_HUNT_FILTER_FLAG_BUSY)
67 hunt_filter_entry_is_auto_old(
68 __in const hunt_filter_table_t *hftp,
69 __in unsigned int index)
71 if (HFE_SPEC(hftp, index) & EFX_HUNT_FILTER_FLAG_AUTO_OLD)
78 hunt_filter_set_entry(
79 __inout hunt_filter_table_t *hftp,
80 __in unsigned int index,
81 __in_opt const efx_filter_spec_t *efsp)
83 HFE_SPEC(hftp, index) = (uintptr_t)efsp;
87 hunt_filter_set_entry_busy(
88 __inout hunt_filter_table_t *hftp,
89 __in unsigned int index)
91 HFE_SPEC(hftp, index) |= (uintptr_t)EFX_HUNT_FILTER_FLAG_BUSY;
95 hunt_filter_set_entry_not_busy(
96 __inout hunt_filter_table_t *hftp,
97 __in unsigned int index)
99 HFE_SPEC(hftp, index) &= ~(uintptr_t)EFX_HUNT_FILTER_FLAG_BUSY;
103 hunt_filter_set_entry_auto_old(
104 __inout hunt_filter_table_t *hftp,
105 __in unsigned int index)
107 EFSYS_ASSERT(hunt_filter_entry_spec(hftp, index) != NULL);
108 HFE_SPEC(hftp, index) |= (uintptr_t)EFX_HUNT_FILTER_FLAG_AUTO_OLD;
112 hunt_filter_set_entry_not_auto_old(
113 __inout hunt_filter_table_t *hftp,
114 __in unsigned int index)
116 HFE_SPEC(hftp, index) &= ~(uintptr_t)EFX_HUNT_FILTER_FLAG_AUTO_OLD;
117 EFSYS_ASSERT(hunt_filter_entry_spec(hftp, index) != NULL);
125 hunt_filter_table_t *hftp;
127 EFSYS_ASSERT(enp->en_family == EFX_FAMILY_HUNTINGTON);
129 #define MATCH_MASK(match) (EFX_MASK32(match) << EFX_LOW_BIT(match))
130 EFX_STATIC_ASSERT(EFX_FILTER_MATCH_REM_HOST ==
131 MATCH_MASK(MC_CMD_FILTER_OP_IN_MATCH_SRC_IP));
132 EFX_STATIC_ASSERT(EFX_FILTER_MATCH_LOC_HOST ==
133 MATCH_MASK(MC_CMD_FILTER_OP_IN_MATCH_DST_IP));
134 EFX_STATIC_ASSERT(EFX_FILTER_MATCH_REM_MAC ==
135 MATCH_MASK(MC_CMD_FILTER_OP_IN_MATCH_SRC_MAC));
136 EFX_STATIC_ASSERT(EFX_FILTER_MATCH_REM_PORT ==
137 MATCH_MASK(MC_CMD_FILTER_OP_IN_MATCH_SRC_PORT));
138 EFX_STATIC_ASSERT(EFX_FILTER_MATCH_LOC_MAC ==
139 MATCH_MASK(MC_CMD_FILTER_OP_IN_MATCH_DST_MAC));
140 EFX_STATIC_ASSERT(EFX_FILTER_MATCH_LOC_PORT ==
141 MATCH_MASK(MC_CMD_FILTER_OP_IN_MATCH_DST_PORT));
142 EFX_STATIC_ASSERT(EFX_FILTER_MATCH_ETHER_TYPE ==
143 MATCH_MASK(MC_CMD_FILTER_OP_IN_MATCH_ETHER_TYPE));
144 EFX_STATIC_ASSERT(EFX_FILTER_MATCH_INNER_VID ==
145 MATCH_MASK(MC_CMD_FILTER_OP_IN_MATCH_INNER_VLAN));
146 EFX_STATIC_ASSERT(EFX_FILTER_MATCH_OUTER_VID ==
147 MATCH_MASK(MC_CMD_FILTER_OP_IN_MATCH_OUTER_VLAN));
148 EFX_STATIC_ASSERT(EFX_FILTER_MATCH_IP_PROTO ==
149 MATCH_MASK(MC_CMD_FILTER_OP_IN_MATCH_IP_PROTO));
152 EFSYS_KMEM_ALLOC(enp->en_esip, sizeof (hunt_filter_table_t), hftp);
159 enp->en_filter.ef_hunt_filter_table = hftp;
164 EFSYS_PROBE1(fail1, int, rc);
173 EFSYS_ASSERT(enp->en_family == EFX_FAMILY_HUNTINGTON);
175 if (enp->en_filter.ef_hunt_filter_table != NULL) {
176 EFSYS_KMEM_FREE(enp->en_esip, sizeof (hunt_filter_table_t),
177 enp->en_filter.ef_hunt_filter_table);
181 static __checkReturn int
182 efx_mcdi_filter_op_add(
184 __in efx_filter_spec_t *spec,
185 __in unsigned int filter_op,
186 __inout hunt_filter_handle_t *handle)
189 uint8_t payload[MAX(MC_CMD_FILTER_OP_IN_LEN,
190 MC_CMD_FILTER_OP_OUT_LEN)];
191 uint32_t match_fields = 0;
194 memset(payload, 0, sizeof (payload));
195 req.emr_cmd = MC_CMD_FILTER_OP;
196 req.emr_in_buf = payload;
197 req.emr_in_length = MC_CMD_FILTER_OP_IN_LEN;
198 req.emr_out_buf = payload;
199 req.emr_out_length = MC_CMD_FILTER_OP_OUT_LEN;
202 case MC_CMD_FILTER_OP_IN_OP_REPLACE:
203 MCDI_IN_SET_DWORD(req, FILTER_OP_IN_HANDLE_LO,
205 MCDI_IN_SET_DWORD(req, FILTER_OP_IN_HANDLE_HI,
208 case MC_CMD_FILTER_OP_IN_OP_INSERT:
209 case MC_CMD_FILTER_OP_IN_OP_SUBSCRIBE:
210 MCDI_IN_SET_DWORD(req, FILTER_OP_IN_OP, filter_op);
218 if (spec->efs_match_flags & EFX_FILTER_MATCH_LOC_MAC_IG) {
220 * The LOC_MAC_IG match flag can represent unknown unicast
221 * or multicast filters - use the MAC address to distinguish
224 if (EFX_MAC_ADDR_IS_MULTICAST(spec->efs_loc_mac))
225 match_fields |= 1U <<
226 MC_CMD_FILTER_OP_IN_MATCH_UNKNOWN_MCAST_DST_LBN;
228 match_fields |= 1U <<
229 MC_CMD_FILTER_OP_IN_MATCH_UNKNOWN_UCAST_DST_LBN;
232 match_fields |= spec->efs_match_flags & (~EFX_FILTER_MATCH_LOC_MAC_IG);
234 MCDI_IN_SET_DWORD(req, FILTER_OP_IN_PORT_ID,
235 EVB_PORT_ID_ASSIGNED);
236 MCDI_IN_SET_DWORD(req, FILTER_OP_IN_MATCH_FIELDS,
238 MCDI_IN_SET_DWORD(req, FILTER_OP_IN_RX_DEST,
239 MC_CMD_FILTER_OP_IN_RX_DEST_HOST);
240 MCDI_IN_SET_DWORD(req, FILTER_OP_IN_RX_QUEUE,
242 if (spec->efs_flags & EFX_FILTER_FLAG_RX_RSS) {
243 MCDI_IN_SET_DWORD(req, FILTER_OP_IN_RX_CONTEXT,
244 spec->efs_rss_context);
246 MCDI_IN_SET_DWORD(req, FILTER_OP_IN_RX_MODE,
247 spec->efs_flags & EFX_FILTER_FLAG_RX_RSS ?
248 MC_CMD_FILTER_OP_IN_RX_MODE_RSS :
249 MC_CMD_FILTER_OP_IN_RX_MODE_SIMPLE);
250 MCDI_IN_SET_DWORD(req, FILTER_OP_IN_TX_DEST,
251 MC_CMD_FILTER_OP_IN_TX_DEST_DEFAULT);
253 if (filter_op != MC_CMD_FILTER_OP_IN_OP_REPLACE) {
255 * NOTE: Unlike most MCDI requests, the filter fields
256 * are presented in network (big endian) byte order.
258 memcpy(MCDI_IN2(req, uint8_t, FILTER_OP_IN_SRC_MAC),
259 spec->efs_rem_mac, EFX_MAC_ADDR_LEN);
260 memcpy(MCDI_IN2(req, uint8_t, FILTER_OP_IN_DST_MAC),
261 spec->efs_loc_mac, EFX_MAC_ADDR_LEN);
263 MCDI_IN_SET_WORD(req, FILTER_OP_IN_SRC_PORT,
264 __CPU_TO_BE_16(spec->efs_rem_port));
265 MCDI_IN_SET_WORD(req, FILTER_OP_IN_DST_PORT,
266 __CPU_TO_BE_16(spec->efs_loc_port));
268 MCDI_IN_SET_WORD(req, FILTER_OP_IN_ETHER_TYPE,
269 __CPU_TO_BE_16(spec->efs_ether_type));
271 MCDI_IN_SET_WORD(req, FILTER_OP_IN_INNER_VLAN,
272 __CPU_TO_BE_16(spec->efs_inner_vid));
273 MCDI_IN_SET_WORD(req, FILTER_OP_IN_OUTER_VLAN,
274 __CPU_TO_BE_16(spec->efs_outer_vid));
276 /* IP protocol (in low byte, high byte is zero) */
277 MCDI_IN_SET_BYTE(req, FILTER_OP_IN_IP_PROTO,
280 EFX_STATIC_ASSERT(sizeof (spec->efs_rem_host) ==
281 MC_CMD_FILTER_OP_IN_SRC_IP_LEN);
282 EFX_STATIC_ASSERT(sizeof (spec->efs_loc_host) ==
283 MC_CMD_FILTER_OP_IN_DST_IP_LEN);
285 memcpy(MCDI_IN2(req, uint8_t, FILTER_OP_IN_SRC_IP),
286 &spec->efs_rem_host.eo_byte[0],
287 MC_CMD_FILTER_OP_IN_SRC_IP_LEN);
288 memcpy(MCDI_IN2(req, uint8_t, FILTER_OP_IN_DST_IP),
289 &spec->efs_loc_host.eo_byte[0],
290 MC_CMD_FILTER_OP_IN_DST_IP_LEN);
293 efx_mcdi_execute(enp, &req);
295 if (req.emr_rc != 0) {
300 if (req.emr_out_length_used < MC_CMD_FILTER_OP_OUT_LEN) {
305 handle->hfh_lo = MCDI_OUT_DWORD(req, FILTER_OP_OUT_HANDLE_LO);
306 handle->hfh_hi = MCDI_OUT_DWORD(req, FILTER_OP_OUT_HANDLE_HI);
315 EFSYS_PROBE1(fail1, int, rc);
321 static __checkReturn int
322 efx_mcdi_filter_op_delete(
324 __in unsigned int filter_op,
325 __inout hunt_filter_handle_t *handle)
328 uint8_t payload[MAX(MC_CMD_FILTER_OP_IN_LEN,
329 MC_CMD_FILTER_OP_OUT_LEN)];
332 memset(payload, 0, sizeof (payload));
333 req.emr_cmd = MC_CMD_FILTER_OP;
334 req.emr_in_buf = payload;
335 req.emr_in_length = MC_CMD_FILTER_OP_IN_LEN;
336 req.emr_out_buf = payload;
337 req.emr_out_length = MC_CMD_FILTER_OP_OUT_LEN;
340 case MC_CMD_FILTER_OP_IN_OP_REMOVE:
341 MCDI_IN_SET_DWORD(req, FILTER_OP_IN_OP,
342 MC_CMD_FILTER_OP_IN_OP_REMOVE);
344 case MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE:
345 MCDI_IN_SET_DWORD(req, FILTER_OP_IN_OP,
346 MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE);
354 MCDI_IN_SET_DWORD(req, FILTER_OP_IN_HANDLE_LO, handle->hfh_lo);
355 MCDI_IN_SET_DWORD(req, FILTER_OP_IN_HANDLE_HI, handle->hfh_hi);
357 efx_mcdi_execute(enp, &req);
359 if (req.emr_rc != 0) {
364 if (req.emr_out_length_used < MC_CMD_FILTER_OP_OUT_LEN) {
377 EFSYS_PROBE1(fail1, int, rc);
382 static __checkReturn boolean_t
384 __in const efx_filter_spec_t *left,
385 __in const efx_filter_spec_t *right)
387 /* FIXME: Consider rx vs tx filters (look at efs_flags) */
388 if (left->efs_match_flags != right->efs_match_flags)
390 if (!EFX_OWORD_IS_EQUAL(left->efs_rem_host, right->efs_rem_host))
392 if (!EFX_OWORD_IS_EQUAL(left->efs_loc_host, right->efs_loc_host))
394 if (memcmp(left->efs_rem_mac, right->efs_rem_mac, EFX_MAC_ADDR_LEN))
396 if (memcmp(left->efs_loc_mac, right->efs_loc_mac, EFX_MAC_ADDR_LEN))
398 if (left->efs_rem_port != right->efs_rem_port)
400 if (left->efs_loc_port != right->efs_loc_port)
402 if (left->efs_inner_vid != right->efs_inner_vid)
404 if (left->efs_outer_vid != right->efs_outer_vid)
406 if (left->efs_ether_type != right->efs_ether_type)
408 if (left->efs_ip_proto != right->efs_ip_proto)
415 static __checkReturn boolean_t
416 hunt_filter_same_dest(
417 __in const efx_filter_spec_t *left,
418 __in const efx_filter_spec_t *right)
420 if ((left->efs_flags & EFX_FILTER_FLAG_RX_RSS) &&
421 (right->efs_flags & EFX_FILTER_FLAG_RX_RSS)) {
422 if (left->efs_rss_context == right->efs_rss_context)
424 } else if ((~(left->efs_flags) & EFX_FILTER_FLAG_RX_RSS) &&
425 (~(right->efs_flags) & EFX_FILTER_FLAG_RX_RSS)) {
426 if (left->efs_dmaq_id == right->efs_dmaq_id)
432 static __checkReturn uint32_t
434 __in efx_filter_spec_t *spec)
436 EFX_STATIC_ASSERT((sizeof (efx_filter_spec_t) % sizeof (uint32_t))
438 EFX_STATIC_ASSERT((EFX_FIELD_OFFSET(efx_filter_spec_t, efs_outer_vid) %
439 sizeof (uint32_t)) == 0);
442 * As the area of the efx_filter_spec_t we need to hash is DWORD
443 * aligned and an exact number of DWORDs in size we can use the
444 * optimised efx_hash_dwords() rather than efx_hash_bytes()
446 return (efx_hash_dwords((const uint32_t *)&spec->efs_outer_vid,
447 (sizeof (efx_filter_spec_t) -
448 EFX_FIELD_OFFSET(efx_filter_spec_t, efs_outer_vid)) /
449 sizeof (uint32_t), 0));
453 * Decide whether a filter should be exclusive or else should allow
454 * delivery to additional recipients. Currently we decide that
455 * filters for specific local unicast MAC and IP addresses are
458 static __checkReturn boolean_t
459 hunt_filter_is_exclusive(
460 __in efx_filter_spec_t *spec)
462 if ((spec->efs_match_flags & EFX_FILTER_MATCH_LOC_MAC) &&
463 !EFX_MAC_ADDR_IS_MULTICAST(spec->efs_loc_mac))
466 if ((spec->efs_match_flags &
467 (EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_LOC_HOST)) ==
468 (EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_LOC_HOST)) {
469 if ((spec->efs_ether_type == EFX_ETHER_TYPE_IPV4) &&
470 ((spec->efs_loc_host.eo_u8[0] & 0xf) != 0xe))
472 if ((spec->efs_ether_type == EFX_ETHER_TYPE_IPV6) &&
473 (spec->efs_loc_host.eo_u8[0] != 0xff))
485 efx_filter_spec_t *spec;
486 hunt_filter_table_t *hftp = enp->en_filter.ef_hunt_filter_table;
491 EFSYS_ASSERT(enp->en_family == EFX_FAMILY_HUNTINGTON);
493 for (tbl_id = 0; tbl_id < EFX_HUNT_FILTER_TBL_ROWS; tbl_id++) {
495 EFSYS_LOCK(enp->en_eslp, state);
497 spec = hunt_filter_entry_spec(hftp, tbl_id);
500 } else if (hunt_filter_entry_is_busy(hftp, tbl_id)) {
501 /* Ignore busy entries. */
504 hunt_filter_set_entry_busy(hftp, tbl_id);
508 EFSYS_UNLOCK(enp->en_eslp, state);
510 if (restoring == B_FALSE)
513 if (hunt_filter_is_exclusive(spec)) {
514 rc = efx_mcdi_filter_op_add(enp, spec,
515 MC_CMD_FILTER_OP_IN_OP_INSERT,
516 &hftp->hft_entry[tbl_id].hfe_handle);
518 rc = efx_mcdi_filter_op_add(enp, spec,
519 MC_CMD_FILTER_OP_IN_OP_SUBSCRIBE,
520 &hftp->hft_entry[tbl_id].hfe_handle);
526 EFSYS_LOCK(enp->en_eslp, state);
528 hunt_filter_set_entry_not_busy(hftp, tbl_id);
530 EFSYS_UNLOCK(enp->en_eslp, state);
536 EFSYS_PROBE1(fail1, int, rc);
542 * An arbitrary search limit for the software hash table. As per the linux net
545 #define EFX_HUNT_FILTER_SEARCH_LIMIT 200
547 static __checkReturn int
548 hunt_filter_add_internal(
550 __inout efx_filter_spec_t *spec,
551 __in boolean_t may_replace,
552 __out_opt uint32_t *filter_id)
555 hunt_filter_table_t *hftp = enp->en_filter.ef_hunt_filter_table;
556 efx_filter_spec_t *saved_spec;
560 boolean_t replacing = B_FALSE;
563 boolean_t locked = B_FALSE;
565 EFSYS_ASSERT(enp->en_family == EFX_FAMILY_HUNTINGTON);
567 #if EFSYS_OPT_RX_SCALE
568 spec->efs_rss_context = enp->en_rss_context;
571 hash = hunt_filter_hash(spec);
574 * FIXME: Add support for inserting filters of different priorities
575 * and removing lower priority multicast filters (bug 42378)
579 * Find any existing filters with the same match tuple or
580 * else a free slot to insert at. If any of them are busy,
581 * we have to wait and retry.
586 EFSYS_LOCK(enp->en_eslp, state);
590 i = (hash + depth) & (EFX_HUNT_FILTER_TBL_ROWS - 1);
591 saved_spec = hunt_filter_entry_spec(hftp, i);
597 } else if (hunt_filter_equal(spec, saved_spec)) {
598 if (hunt_filter_entry_is_busy(hftp, i))
600 if (saved_spec->efs_priority
601 == EFX_FILTER_PRI_AUTO) {
604 } else if (hunt_filter_is_exclusive(spec)) {
618 * Once we reach the maximum search depth, use
619 * the first suitable slot or return EBUSY if
622 if (depth == EFX_HUNT_FILTER_SEARCH_LIMIT) {
631 EFSYS_UNLOCK(enp->en_eslp, state);
637 * Create a software table entry if necessary, and mark it
638 * busy. We might yet fail to insert, but any attempt to
639 * insert a conflicting filter while we're waiting for the
640 * firmware must find the busy entry.
642 saved_spec = hunt_filter_entry_spec(hftp, ins_index);
644 if (saved_spec->efs_priority == EFX_FILTER_PRI_AUTO) {
645 /* This is a filter we are refreshing */
646 hunt_filter_set_entry_not_auto_old(hftp, ins_index);
652 EFSYS_KMEM_ALLOC(enp->en_esip, sizeof (*spec), saved_spec);
658 hunt_filter_set_entry(hftp, ins_index, saved_spec);
660 hunt_filter_set_entry_busy(hftp, ins_index);
662 EFSYS_UNLOCK(enp->en_eslp, state);
666 * On replacing the filter handle may change after after a successful
670 rc = efx_mcdi_filter_op_add(enp, spec,
671 MC_CMD_FILTER_OP_IN_OP_REPLACE,
672 &hftp->hft_entry[ins_index].hfe_handle);
673 } else if (hunt_filter_is_exclusive(spec)) {
674 rc = efx_mcdi_filter_op_add(enp, spec,
675 MC_CMD_FILTER_OP_IN_OP_INSERT,
676 &hftp->hft_entry[ins_index].hfe_handle);
678 rc = efx_mcdi_filter_op_add(enp, spec,
679 MC_CMD_FILTER_OP_IN_OP_SUBSCRIBE,
680 &hftp->hft_entry[ins_index].hfe_handle);
686 EFSYS_LOCK(enp->en_eslp, state);
690 /* Update the fields that may differ */
691 saved_spec->efs_priority = spec->efs_priority;
692 saved_spec->efs_flags = spec->efs_flags;
693 saved_spec->efs_rss_context = spec->efs_rss_context;
694 saved_spec->efs_dmaq_id = spec->efs_dmaq_id;
697 hunt_filter_set_entry_not_busy(hftp, ins_index);
701 EFSYS_UNLOCK(enp->en_eslp, state);
705 *filter_id = ins_index;
713 EFSYS_KMEM_FREE(enp->en_esip, sizeof (*spec), saved_spec);
716 hunt_filter_set_entry_not_busy(hftp, ins_index);
717 hunt_filter_set_entry(hftp, ins_index, NULL);
726 EFSYS_PROBE1(fail1, int, rc);
729 EFSYS_UNLOCK(enp->en_eslp, state);
737 __inout efx_filter_spec_t *spec,
738 __in boolean_t may_replace)
742 rc = hunt_filter_add_internal(enp, spec, may_replace, NULL);
749 EFSYS_PROBE1(fail1, int, rc);
755 static __checkReturn int
756 hunt_filter_delete_internal(
758 __in uint32_t filter_id)
761 hunt_filter_table_t *table = enp->en_filter.ef_hunt_filter_table;
762 efx_filter_spec_t *spec;
764 uint32_t filter_idx = filter_id % EFX_HUNT_FILTER_TBL_ROWS;
767 * Find the software table entry and mark it busy. Don't
768 * remove it yet; any attempt to update while we're waiting
769 * for the firmware must find the busy entry.
771 * FIXME: What if the busy flag is never cleared?
773 EFSYS_LOCK(enp->en_eslp, state);
774 while (hunt_filter_entry_is_busy(table, filter_idx)) {
775 EFSYS_UNLOCK(enp->en_eslp, state);
777 EFSYS_LOCK(enp->en_eslp, state);
779 if ((spec = hunt_filter_entry_spec(table, filter_idx)) != NULL) {
780 hunt_filter_set_entry_busy(table, filter_idx);
782 EFSYS_UNLOCK(enp->en_eslp, state);
790 * Try to remove the hardware filter. This may fail if the MC has
791 * rebooted (which frees all hardware filter resources).
793 if (hunt_filter_is_exclusive(spec)) {
794 rc = efx_mcdi_filter_op_delete(enp,
795 MC_CMD_FILTER_OP_IN_OP_REMOVE,
796 &table->hft_entry[filter_idx].hfe_handle);
798 rc = efx_mcdi_filter_op_delete(enp,
799 MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE,
800 &table->hft_entry[filter_idx].hfe_handle);
803 /* Free the software table entry */
804 EFSYS_LOCK(enp->en_eslp, state);
805 hunt_filter_set_entry_not_busy(table, filter_idx);
806 hunt_filter_set_entry(table, filter_idx, NULL);
807 EFSYS_UNLOCK(enp->en_eslp, state);
809 EFSYS_KMEM_FREE(enp->en_esip, sizeof (*spec), spec);
811 /* Check result of hardware filter removal */
821 EFSYS_PROBE1(fail1, int, rc);
829 __inout efx_filter_spec_t *spec)
832 hunt_filter_table_t *table = enp->en_filter.ef_hunt_filter_table;
833 efx_filter_spec_t *saved_spec;
838 boolean_t locked = B_FALSE;
840 EFSYS_ASSERT(enp->en_family == EFX_FAMILY_HUNTINGTON);
842 hash = hunt_filter_hash(spec);
844 EFSYS_LOCK(enp->en_eslp, state);
849 i = (hash + depth) & (EFX_HUNT_FILTER_TBL_ROWS - 1);
850 saved_spec = hunt_filter_entry_spec(table, i);
851 if (saved_spec && hunt_filter_equal(spec, saved_spec) &&
852 hunt_filter_same_dest(spec, saved_spec)) {
855 if (depth == EFX_HUNT_FILTER_SEARCH_LIMIT) {
862 EFSYS_UNLOCK(enp->en_eslp, state);
865 rc = hunt_filter_delete_internal(enp, i);
875 EFSYS_PROBE1(fail1, int, rc);
878 EFSYS_UNLOCK(enp->en_eslp, state);
883 static __checkReturn int
884 efx_mcdi_get_parser_disp_info(
886 __out uint32_t *list,
887 __out size_t *length)
890 uint8_t payload[MAX(MC_CMD_GET_PARSER_DISP_INFO_IN_LEN,
891 MC_CMD_GET_PARSER_DISP_INFO_OUT_LENMAX)];
894 boolean_t support_unknown_ucast = B_FALSE;
895 boolean_t support_unknown_mcast = B_FALSE;
897 (void) memset(payload, 0, sizeof (payload));
898 req.emr_cmd = MC_CMD_GET_PARSER_DISP_INFO;
899 req.emr_in_buf = payload;
900 req.emr_in_length = MC_CMD_GET_PARSER_DISP_INFO_IN_LEN;
901 req.emr_out_buf = payload;
902 req.emr_out_length = MC_CMD_GET_PARSER_DISP_INFO_OUT_LENMAX;
904 MCDI_IN_SET_DWORD(req, GET_PARSER_DISP_INFO_OUT_OP,
905 MC_CMD_GET_PARSER_DISP_INFO_IN_OP_GET_SUPPORTED_RX_MATCHES);
907 efx_mcdi_execute(enp, &req);
909 if (req.emr_rc != 0) {
914 *length = MCDI_OUT_DWORD(req,
915 GET_PARSER_DISP_INFO_OUT_NUM_SUPPORTED_MATCHES);
917 if (req.emr_out_length_used <
918 MC_CMD_GET_PARSER_DISP_INFO_OUT_LEN(*length)) {
926 GET_PARSER_DISP_INFO_OUT_SUPPORTED_MATCHES),
927 (*length) * sizeof (uint32_t));
928 EFX_STATIC_ASSERT(sizeof (uint32_t) ==
929 MC_CMD_GET_PARSER_DISP_INFO_OUT_SUPPORTED_MATCHES_LEN);
932 * Remove UNKNOWN UCAST and MCAST flags, and if both are present, change
933 * the lower priority one to LOC_MAC_IG.
935 for (i = 0; i < *length; i++) {
936 if (list[i] & MC_CMD_FILTER_OP_IN_MATCH_UNKNOWN_UCAST_DST_LBN) {
938 (~MC_CMD_FILTER_OP_IN_MATCH_UNKNOWN_UCAST_DST_LBN);
939 support_unknown_ucast = B_TRUE;
941 if (list[i] & MC_CMD_FILTER_OP_IN_MATCH_UNKNOWN_MCAST_DST_LBN) {
943 (~MC_CMD_FILTER_OP_IN_MATCH_UNKNOWN_MCAST_DST_LBN);
944 support_unknown_mcast = B_TRUE;
947 if (support_unknown_ucast && support_unknown_mcast) {
948 list[i] &= EFX_FILTER_MATCH_LOC_MAC_IG;
958 EFSYS_PROBE1(fail1, int, rc);
964 hunt_filter_supported_filters(
966 __out uint32_t *list,
967 __out size_t *length)
971 if ((rc = efx_mcdi_get_parser_disp_info(enp, list, length) != 0))
977 EFSYS_PROBE1(fail1, int, rc);
982 static __checkReturn int
983 hunt_filter_unicast_refresh(
985 __in_ecount(6) uint8_t const *addr,
986 __in boolean_t all_unicst,
987 __in efx_filter_flag_t filter_flags)
989 hunt_filter_table_t *hftp = enp->en_filter.ef_hunt_filter_table;
990 efx_filter_spec_t spec;
993 if (all_unicst == B_TRUE)
996 /* Insert the filter for the local station address */
997 efx_filter_spec_init_rx(&spec, EFX_FILTER_PRI_AUTO,
999 hftp->hft_default_rxq);
1000 efx_filter_spec_set_eth_local(&spec, EFX_FILTER_SPEC_VID_UNSPEC, addr);
1002 rc = hunt_filter_add_internal(enp, &spec, B_TRUE,
1003 &hftp->hft_unicst_filter_index);
1006 * Fall back to an unknown filter. We may be able to subscribe
1007 * to it even if we couldn't insert the unicast filter.
1011 hftp->hft_unicst_filter_set = B_TRUE;
1016 /* Insert the unknown unicast filter */
1017 efx_filter_spec_init_rx(&spec, EFX_FILTER_PRI_AUTO,
1019 hftp->hft_default_rxq);
1020 efx_filter_spec_set_uc_def(&spec);
1021 rc = hunt_filter_add_internal(enp, &spec, B_TRUE,
1022 &hftp->hft_unicst_filter_index);
1026 hftp->hft_unicst_filter_set = B_TRUE;
1031 EFSYS_PROBE1(fail1, int, rc);
1033 if (hftp->hft_unicst_filter_set != B_FALSE) {
1034 (void) hunt_filter_delete_internal(enp,
1035 hftp->hft_unicst_filter_index);
1037 hftp->hft_unicst_filter_set = B_FALSE;
1043 static __checkReturn int
1044 hunt_filter_multicast_refresh(
1045 __in efx_nic_t *enp,
1046 __in boolean_t mulcst,
1047 __in boolean_t all_mulcst,
1048 __in boolean_t brdcst,
1049 __in_ecount(6*count) uint8_t const *addrs,
1051 __in efx_filter_flag_t filter_flags)
1053 hunt_filter_table_t *hftp = enp->en_filter.ef_hunt_filter_table;
1054 efx_filter_spec_t spec;
1059 if (all_mulcst == B_TRUE)
1062 if (mulcst == B_FALSE)
1065 if (count + (brdcst ? 1 : 0) >
1066 EFX_ARRAY_SIZE(hftp->hft_mulcst_filter_indexes)) {
1067 /* Too many MAC addresses; use unknown multicast filter */
1071 /* Insert/renew multicast address list filters */
1072 hftp->hft_mulcst_filter_count = count;
1073 for (i = 0; i < hftp->hft_mulcst_filter_count; i++) {
1074 efx_filter_spec_init_rx(&spec,
1075 EFX_FILTER_PRI_AUTO,
1077 hftp->hft_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 = hunt_filter_add_internal(enp, &spec, B_TRUE,
1084 &hftp->hft_mulcst_filter_indexes[i]);
1086 /* Rollback, then use unknown multicast filter */
1091 if (brdcst == B_TRUE) {
1092 /* Insert/renew broadcast address filter */
1093 hftp->hft_mulcst_filter_count++;
1094 efx_filter_spec_init_rx(&spec, EFX_FILTER_PRI_AUTO,
1096 hftp->hft_default_rxq);
1098 EFX_MAC_BROADCAST_ADDR_SET(addr);
1099 efx_filter_spec_set_eth_local(&spec, EFX_FILTER_SPEC_VID_UNSPEC,
1102 rc = hunt_filter_add_internal(enp, &spec, B_TRUE,
1103 &hftp->hft_mulcst_filter_indexes[
1104 hftp->hft_mulcst_filter_count - 1]);
1106 /* Rollback, then use unknown multicast filter */
1115 * Rollback by removing any filters we have inserted
1116 * before inserting the unknown multicast filter.
1119 (void) hunt_filter_delete_internal(enp,
1120 hftp->hft_mulcst_filter_indexes[i]);
1122 hftp->hft_mulcst_filter_count = 0;
1125 /* Insert the unknown multicast filter */
1126 efx_filter_spec_init_rx(&spec, EFX_FILTER_PRI_AUTO,
1128 hftp->hft_default_rxq);
1129 efx_filter_spec_set_mc_def(&spec);
1131 rc = hunt_filter_add_internal(enp, &spec, B_TRUE,
1132 &hftp->hft_mulcst_filter_indexes[0]);
1136 hftp->hft_mulcst_filter_count = 1;
1139 * FIXME: If brdcst == B_FALSE, add a filter to drop broadcast traffic.
1145 EFSYS_PROBE1(fail1, int, rc);
1152 static __checkReturn int
1153 hunt_filter_get_workarounds(
1154 __in efx_nic_t *enp)
1156 efx_nic_cfg_t *encp = &enp->en_nic_cfg;
1157 uint32_t implemented = 0;
1158 uint32_t enabled = 0;
1161 rc = efx_mcdi_get_workarounds(enp, &implemented, &enabled);
1163 /* Check if chained multicast filter support is enabled */
1164 if (implemented & enabled & MC_CMD_GET_WORKAROUNDS_OUT_BUG26807)
1165 encp->enc_bug26807_workaround = B_TRUE;
1167 encp->enc_bug26807_workaround = B_FALSE;
1168 } else if (rc == ENOTSUP) {
1170 * Firmware is too old to support GET_WORKAROUNDS, and support
1171 * for this workaround was implemented later.
1173 encp->enc_bug26807_workaround = B_FALSE;
1181 EFSYS_PROBE1(fail1, int, rc);
1189 * Reconfigure all filters.
1190 * If all_unicst and/or all mulcst filters cannot be applied then
1191 * return ENOTSUP (Note the filters for the specified addresses are
1192 * still applied in this case).
1195 hunt_filter_reconfigure(
1196 __in efx_nic_t *enp,
1197 __in_ecount(6) uint8_t const *mac_addr,
1198 __in boolean_t all_unicst,
1199 __in boolean_t mulcst,
1200 __in boolean_t all_mulcst,
1201 __in boolean_t brdcst,
1202 __in_ecount(6*count) uint8_t const *addrs,
1205 hunt_filter_table_t *table = enp->en_filter.ef_hunt_filter_table;
1206 efx_filter_flag_t filter_flags;
1212 if (table->hft_default_rxq == NULL) {
1214 * Filters direct traffic to the default RXQ, and so cannot be
1215 * inserted until it is available. Any currently configured
1216 * filters must be removed (ignore errors in case the MC
1217 * has rebooted, which removes hardware filters).
1219 if (table->hft_unicst_filter_set != B_FALSE) {
1220 (void) hunt_filter_delete_internal(enp,
1221 table->hft_unicst_filter_index);
1222 table->hft_unicst_filter_set = B_FALSE;
1224 for (i = 0; i < table->hft_mulcst_filter_count; i++) {
1225 (void) hunt_filter_delete_internal(enp,
1226 table->hft_mulcst_filter_indexes[i]);
1228 table->hft_mulcst_filter_count = 0;
1233 if (table->hft_using_rss)
1234 filter_flags = EFX_FILTER_FLAG_RX_RSS;
1238 /* Mark old filters which may need to be removed */
1239 if (table->hft_unicst_filter_set != B_FALSE) {
1240 hunt_filter_set_entry_auto_old(table,
1241 table->hft_unicst_filter_index);
1243 for (i = 0; i < table->hft_mulcst_filter_count; i++) {
1244 hunt_filter_set_entry_auto_old(table,
1245 table->hft_mulcst_filter_indexes[i]);
1248 /* Insert or renew unicast filters */
1249 if ((all_unicst_rc = hunt_filter_unicast_refresh(enp, mac_addr,
1250 all_unicst, filter_flags)) != 0) {
1251 if (all_unicst == B_FALSE) {
1255 /* Retry without all_unicast flag */
1256 rc = hunt_filter_unicast_refresh(enp, mac_addr,
1257 B_FALSE, filter_flags);
1263 * WORKAROUND_BUG26807 controls firmware support for chained multicast
1264 * filters, and can only be enabled or disabled when the hardware filter
1267 * Firmware will reset (FLR) functions which have inserted filters in
1268 * the hardware filter table when the workaround is enabled/disabled.
1269 * Functions without any hardware filters are not reset.
1271 * Re-check if the workaround is enabled after adding unicast hardware
1272 * filters. This ensures that encp->enc_workaround_bug26807 matches the
1273 * firmware state, and that later changes to enable/disable the
1274 * workaround will result in this function seeing a reset (FLR).
1276 if ((rc = hunt_filter_get_workarounds(enp)) != 0)
1279 /* Insert or renew multicast filters */
1280 if ((all_mulcst_rc = hunt_filter_multicast_refresh(enp, mulcst,
1282 addrs, count, filter_flags)) != 0) {
1283 if (all_mulcst == B_FALSE) {
1287 /* Retry without all_mulcast flag */
1288 rc = hunt_filter_multicast_refresh(enp, mulcst,
1290 addrs, count, filter_flags);
1295 /* Remove old filters which were not renewed */
1296 for (i = 0; i < EFX_ARRAY_SIZE(table->hft_entry); i++) {
1297 if (hunt_filter_entry_is_auto_old(table, i)) {
1298 (void) hunt_filter_delete_internal(enp, i);
1302 /* report if any optional flags were rejected */
1303 if (((all_unicst != B_FALSE) && (all_unicst_rc != 0)) ||
1304 ((all_mulcst != B_FALSE) && (all_mulcst_rc != 0))) {
1319 EFSYS_PROBE1(fail1, int, rc);
1321 /* Clear auto old flags */
1322 for (i = 0; i < EFX_ARRAY_SIZE(table->hft_entry); i++) {
1323 if (hunt_filter_entry_is_auto_old(table, i)) {
1324 hunt_filter_set_entry_not_auto_old(table, i);
1332 hunt_filter_get_default_rxq(
1333 __in efx_nic_t *enp,
1334 __out efx_rxq_t **erpp,
1335 __out boolean_t *using_rss)
1337 hunt_filter_table_t *table = enp->en_filter.ef_hunt_filter_table;
1339 *erpp = table->hft_default_rxq;
1340 *using_rss = table->hft_using_rss;
1345 hunt_filter_default_rxq_set(
1346 __in efx_nic_t *enp,
1347 __in efx_rxq_t *erp,
1348 __in boolean_t using_rss)
1350 hunt_filter_table_t *table = enp->en_filter.ef_hunt_filter_table;
1352 #if EFSYS_OPT_RX_SCALE
1353 EFSYS_ASSERT((using_rss == B_FALSE) ||
1354 (enp->en_rss_context != HUNTINGTON_RSS_CONTEXT_INVALID));
1355 table->hft_using_rss = using_rss;
1357 EFSYS_ASSERT(using_rss == B_FALSE);
1358 table->hft_using_rss = B_FALSE;
1360 table->hft_default_rxq = erp;
1364 hunt_filter_default_rxq_clear(
1365 __in efx_nic_t *enp)
1367 hunt_filter_table_t *table = enp->en_filter.ef_hunt_filter_table;
1369 table->hft_default_rxq = NULL;
1370 table->hft_using_rss = B_FALSE;
1374 #endif /* EFSYS_OPT_FILTER */
1376 #endif /* EFSYS_OPT_HUNTINGTON */