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)
79 sfc_log_init(sa, "entry");
81 rc = efx_filter_init(sa->nic);
83 goto fail_filter_init;
85 rc = sfc_filter_cache_match_supported(sa);
87 goto fail_cache_match_supported;
89 efx_filter_fini(sa->nic);
91 sfc_log_init(sa, "done");
95 fail_cache_match_supported:
96 efx_filter_fini(sa->nic);
99 sfc_log_init(sa, "failed %d", rc);
104 sfc_filter_detach(struct sfc_adapter *sa)
106 struct sfc_filter *filter = &sa->filter;
108 sfc_log_init(sa, "entry");
110 rte_free(filter->supported_match);
111 filter->supported_match = NULL;
112 filter->supported_match_num = 0;
114 sfc_log_init(sa, "done");