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 void bnxt_init_filters(struct bnxt *bp)
73 struct bnxt_filter_info *filter;
77 struct bnxt_pf_info *pf = &bp->pf;
79 max_filters = pf->max_l2_ctx;
81 struct bnxt_vf_info *vf = &bp->vf;
83 max_filters = vf->max_l2_ctx;
85 STAILQ_INIT(&bp->free_filter_list);
86 for (i = 0; i < max_filters; i++) {
87 filter = &bp->filter_info[i];
88 filter->fw_l2_filter_id = -1;
89 STAILQ_INSERT_TAIL(&bp->free_filter_list, filter, next);
93 void bnxt_free_all_filters(struct bnxt *bp)
95 struct bnxt_vnic_info *vnic;
96 struct bnxt_filter_info *filter, *temp_filter;
99 for (i = 0; i < MAX_FF_POOLS; i++) {
100 STAILQ_FOREACH(vnic, &bp->ff_pool[i], next) {
101 filter = STAILQ_FIRST(&vnic->filter);
103 temp_filter = STAILQ_NEXT(filter, next);
104 STAILQ_REMOVE(&vnic->filter, filter,
105 bnxt_filter_info, next);
106 STAILQ_INSERT_TAIL(&bp->free_filter_list,
108 filter = temp_filter;
110 STAILQ_INIT(&vnic->filter);
115 void bnxt_free_filter_mem(struct bnxt *bp)
117 struct bnxt_filter_info *filter;
118 uint16_t max_filters, i;
121 if (bp->filter_info == NULL)
124 /* Ensure that all filters are freed */
126 struct bnxt_pf_info *pf = &bp->pf;
128 max_filters = pf->max_l2_ctx;
130 struct bnxt_vf_info *vf = &bp->vf;
132 max_filters = vf->max_l2_ctx;
134 for (i = 0; i < max_filters; i++) {
135 filter = &bp->filter_info[i];
136 if (filter->fw_l2_filter_id != ((uint64_t)-1)) {
137 RTE_LOG(ERR, PMD, "HWRM filter is not freed??\n");
138 /* Call HWRM to try to free filter again */
139 rc = bnxt_hwrm_clear_filter(bp, filter);
142 "HWRM filter cannot be freed rc = %d\n",
145 filter->fw_l2_filter_id = -1;
147 STAILQ_INIT(&bp->free_filter_list);
149 rte_free(bp->filter_info);
150 bp->filter_info = NULL;
153 int bnxt_alloc_filter_mem(struct bnxt *bp)
155 struct bnxt_filter_info *filter_mem;
156 uint16_t max_filters;
159 struct bnxt_pf_info *pf = &bp->pf;
161 max_filters = pf->max_l2_ctx;
163 struct bnxt_vf_info *vf = &bp->vf;
165 max_filters = vf->max_l2_ctx;
167 /* Allocate memory for VNIC pool and filter pool */
168 filter_mem = rte_zmalloc("bnxt_filter_info",
169 max_filters * sizeof(struct bnxt_filter_info),
171 if (filter_mem == NULL) {
172 RTE_LOG(ERR, PMD, "Failed to alloc memory for %d filters",
176 bp->filter_info = filter_mem;