2 * Copyright (c) 2017 Solarflare Communications Inc.
5 * This software was jointly developed between OKTET Labs (under contract
6 * for Solarflare) and Solarflare Communications, Inc.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are met:
11 * 1. Redistributions of source code must retain the above copyright notice,
12 * this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright notice,
14 * this list of conditions and the following disclaimer in the documentation
15 * and/or other materials provided with the distribution.
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
19 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
21 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
24 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
26 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
27 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 #include <rte_common.h>
38 sfc_filter_is_match_supported(struct sfc_adapter *sa, uint32_t match)
40 struct sfc_filter *filter = &sa->filter;
43 for (i = 0; i < filter->supported_match_num; ++i) {
44 if (match == filter->supported_match[i])
52 sfc_filter_cache_match_supported(struct sfc_adapter *sa)
54 struct sfc_filter *filter = &sa->filter;
55 size_t num = filter->supported_match_num;
56 uint32_t *buf = filter->supported_match;
60 /* Just a guess of possibly sufficient entries */
64 for (retry = 0; retry < 2; ++retry) {
65 if (num != filter->supported_match_num) {
67 buf = rte_realloc(buf, num * sizeof(*buf), 0);
72 rc = efx_filter_supported_filters(sa->nic, buf, num, &num);
74 filter->supported_match_num = num;
75 filter->supported_match = buf;
78 } else if (rc != ENOSPC) {
79 goto fail_efx_filter_supported_filters;
83 SFC_ASSERT(rc == ENOSPC);
85 fail_efx_filter_supported_filters:
87 /* Original pointer is not freed by rte_realloc() on failure */
89 filter->supported_match = NULL;
90 filter->supported_match_num = 0;
95 sfc_filter_attach(struct sfc_adapter *sa)
99 sfc_log_init(sa, "entry");
101 rc = efx_filter_init(sa->nic);
103 goto fail_filter_init;
105 rc = sfc_filter_cache_match_supported(sa);
107 goto fail_cache_match_supported;
109 efx_filter_fini(sa->nic);
111 sfc_log_init(sa, "done");
115 fail_cache_match_supported:
116 efx_filter_fini(sa->nic);
119 sfc_log_init(sa, "failed %d", rc);
124 sfc_filter_detach(struct sfc_adapter *sa)
126 struct sfc_filter *filter = &sa->filter;
128 sfc_log_init(sa, "entry");
130 rte_free(filter->supported_match);
131 filter->supported_match = NULL;
132 filter->supported_match_num = 0;
134 sfc_log_init(sa, "done");