1 /* SPDX-License-Identifier: BSD-3-Clause
3 * Copyright (c) 2017-2018 Solarflare Communications Inc.
6 * This software was jointly developed between OKTET Labs (under contract
7 * for Solarflare) and Solarflare Communications, Inc.
10 #include <rte_common.h>
18 sfc_filter_is_match_supported(struct sfc_adapter *sa, uint32_t match)
20 struct sfc_filter *filter = &sa->filter;
23 for (i = 0; i < filter->supported_match_num; ++i) {
24 if (match == filter->supported_match[i])
32 sfc_filter_cache_match_supported(struct sfc_adapter *sa)
34 struct sfc_filter *filter = &sa->filter;
35 size_t num = filter->supported_match_num;
36 uint32_t *buf = filter->supported_match;
40 /* Just a guess of possibly sufficient entries */
44 for (retry = 0; retry < 2; ++retry) {
45 if (num != filter->supported_match_num) {
47 buf = rte_realloc(buf, num * sizeof(*buf), 0);
52 rc = efx_filter_supported_filters(sa->nic, buf, num, &num);
54 filter->supported_match_num = num;
55 filter->supported_match = buf;
58 } else if (rc != ENOSPC) {
59 goto fail_efx_filter_supported_filters;
63 SFC_ASSERT(rc == ENOSPC);
65 fail_efx_filter_supported_filters:
67 /* Original pointer is not freed by rte_realloc() on failure */
69 filter->supported_match = NULL;
70 filter->supported_match_num = 0;
75 sfc_filter_attach(struct sfc_adapter *sa)
80 sfc_log_init(sa, "entry");
82 rc = efx_filter_init(sa->nic);
84 goto fail_filter_init;
86 rc = sfc_filter_cache_match_supported(sa);
88 goto fail_cache_match_supported;
90 efx_filter_fini(sa->nic);
92 sa->filter.supports_ip_proto_or_addr_filter = B_FALSE;
93 sa->filter.supports_rem_or_local_port_filter = B_FALSE;
94 for (i = 0; i < sa->filter.supported_match_num; ++i) {
95 if (sa->filter.supported_match[i] &
96 (EFX_FILTER_MATCH_IP_PROTO | EFX_FILTER_MATCH_LOC_HOST |
97 EFX_FILTER_MATCH_REM_HOST))
98 sa->filter.supports_ip_proto_or_addr_filter = B_TRUE;
100 if (sa->filter.supported_match[i] &
101 (EFX_FILTER_MATCH_LOC_PORT | EFX_FILTER_MATCH_REM_PORT))
102 sa->filter.supports_rem_or_local_port_filter = B_TRUE;
105 sfc_log_init(sa, "done");
109 fail_cache_match_supported:
110 efx_filter_fini(sa->nic);
113 sfc_log_init(sa, "failed %d", rc);
118 sfc_filter_detach(struct sfc_adapter *sa)
120 struct sfc_filter *filter = &sa->filter;
122 sfc_log_init(sa, "entry");
124 rte_free(filter->supported_match);
125 filter->supported_match = NULL;
126 filter->supported_match_num = 0;
128 sfc_log_init(sa, "done");