4 * Copyright(c) Broadcom Limited.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of Broadcom Corporation nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 #include <sys/queue.h>
37 #include <rte_malloc.h>
40 #include "bnxt_filter.h"
41 #include "bnxt_hwrm.h"
42 #include "bnxt_vnic.h"
43 #include "hsi_struct_def_dpdk.h"
49 struct bnxt_filter_info *bnxt_alloc_filter(struct bnxt *bp)
51 struct bnxt_filter_info *filter;
53 /* Find the 1st unused filter from the free_filter_list pool*/
54 filter = STAILQ_FIRST(&bp->free_filter_list);
56 RTE_LOG(ERR, PMD, "No more free filter resources\n");
59 STAILQ_REMOVE_HEAD(&bp->free_filter_list, next);
61 /* Default to L2 MAC Addr filter */
62 filter->flags = HWRM_CFA_L2_FILTER_ALLOC_INPUT_FLAGS_PATH_RX;
63 filter->enables = HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_L2_ADDR |
64 HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_L2_ADDR_MASK;
65 memcpy(filter->l2_addr, bp->eth_dev->data->mac_addrs->addr_bytes,
67 memset(filter->l2_addr_mask, 0xff, ETHER_ADDR_LEN);
71 struct bnxt_filter_info *bnxt_alloc_vf_filter(struct bnxt *bp, uint16_t vf)
73 struct bnxt_filter_info *filter;
75 filter = rte_zmalloc("bnxt_vf_filter_info", sizeof(*filter), 0);
77 RTE_LOG(ERR, PMD, "Failed to alloc memory for VF %hu filters\n",
82 filter->fw_l2_filter_id = UINT64_MAX;
83 STAILQ_INSERT_TAIL(&bp->pf.vf_info[vf].filter, filter, next);
87 void bnxt_init_filters(struct bnxt *bp)
89 struct bnxt_filter_info *filter;
92 max_filters = bp->max_l2_ctx;
93 STAILQ_INIT(&bp->free_filter_list);
94 for (i = 0; i < max_filters; i++) {
95 filter = &bp->filter_info[i];
96 filter->fw_l2_filter_id = -1;
97 STAILQ_INSERT_TAIL(&bp->free_filter_list, filter, next);
101 void bnxt_free_all_filters(struct bnxt *bp)
103 struct bnxt_vnic_info *vnic;
104 struct bnxt_filter_info *filter, *temp_filter;
107 for (i = 0; i < MAX_FF_POOLS; i++) {
108 STAILQ_FOREACH(vnic, &bp->ff_pool[i], next) {
109 filter = STAILQ_FIRST(&vnic->filter);
111 temp_filter = STAILQ_NEXT(filter, next);
112 STAILQ_REMOVE(&vnic->filter, filter,
113 bnxt_filter_info, next);
114 STAILQ_INSERT_TAIL(&bp->free_filter_list,
116 filter = temp_filter;
118 STAILQ_INIT(&vnic->filter);
122 for (i = 0; i < bp->pf.max_vfs; i++) {
123 STAILQ_FOREACH(filter, &bp->pf.vf_info[i].filter, next) {
124 bnxt_hwrm_clear_filter(bp, filter);
129 void bnxt_free_filter_mem(struct bnxt *bp)
131 struct bnxt_filter_info *filter;
132 uint16_t max_filters, i;
135 if (bp->filter_info == NULL)
138 /* Ensure that all filters are freed */
139 max_filters = bp->max_l2_ctx;
140 for (i = 0; i < max_filters; i++) {
141 filter = &bp->filter_info[i];
142 if (filter->fw_l2_filter_id != ((uint64_t)-1)) {
143 RTE_LOG(ERR, PMD, "HWRM filter is not freed??\n");
144 /* Call HWRM to try to free filter again */
145 rc = bnxt_hwrm_clear_filter(bp, filter);
148 "HWRM filter cannot be freed rc = %d\n",
151 filter->fw_l2_filter_id = UINT64_MAX;
153 STAILQ_INIT(&bp->free_filter_list);
155 rte_free(bp->filter_info);
156 bp->filter_info = NULL;
159 int bnxt_alloc_filter_mem(struct bnxt *bp)
161 struct bnxt_filter_info *filter_mem;
162 uint16_t max_filters;
164 max_filters = bp->max_l2_ctx;
165 /* Allocate memory for VNIC pool and filter pool */
166 filter_mem = rte_zmalloc("bnxt_filter_info",
167 max_filters * sizeof(struct bnxt_filter_info),
169 if (filter_mem == NULL) {
170 RTE_LOG(ERR, PMD, "Failed to alloc memory for %d filters",
174 bp->filter_info = filter_mem;