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