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;
76 max_filters = bp->max_l2_ctx;
77 STAILQ_INIT(&bp->free_filter_list);
78 for (i = 0; i < max_filters; i++) {
79 filter = &bp->filter_info[i];
80 filter->fw_l2_filter_id = -1;
81 STAILQ_INSERT_TAIL(&bp->free_filter_list, filter, next);
85 void bnxt_free_all_filters(struct bnxt *bp)
87 struct bnxt_vnic_info *vnic;
88 struct bnxt_filter_info *filter, *temp_filter;
91 for (i = 0; i < MAX_FF_POOLS; i++) {
92 STAILQ_FOREACH(vnic, &bp->ff_pool[i], next) {
93 filter = STAILQ_FIRST(&vnic->filter);
95 temp_filter = STAILQ_NEXT(filter, next);
96 STAILQ_REMOVE(&vnic->filter, filter,
97 bnxt_filter_info, next);
98 STAILQ_INSERT_TAIL(&bp->free_filter_list,
100 filter = temp_filter;
102 STAILQ_INIT(&vnic->filter);
107 void bnxt_free_filter_mem(struct bnxt *bp)
109 struct bnxt_filter_info *filter;
110 uint16_t max_filters, i;
113 if (bp->filter_info == NULL)
116 /* Ensure that all filters are freed */
117 max_filters = bp->max_l2_ctx;
118 for (i = 0; i < max_filters; i++) {
119 filter = &bp->filter_info[i];
120 if (filter->fw_l2_filter_id != ((uint64_t)-1)) {
121 RTE_LOG(ERR, PMD, "HWRM filter is not freed??\n");
122 /* Call HWRM to try to free filter again */
123 rc = bnxt_hwrm_clear_filter(bp, filter);
126 "HWRM filter cannot be freed rc = %d\n",
129 filter->fw_l2_filter_id = UINT64_MAX;
131 STAILQ_INIT(&bp->free_filter_list);
133 rte_free(bp->filter_info);
134 bp->filter_info = NULL;
137 int bnxt_alloc_filter_mem(struct bnxt *bp)
139 struct bnxt_filter_info *filter_mem;
140 uint16_t max_filters;
142 max_filters = bp->max_l2_ctx;
143 /* Allocate memory for VNIC pool and filter pool */
144 filter_mem = rte_zmalloc("bnxt_filter_info",
145 max_filters * sizeof(struct bnxt_filter_info),
147 if (filter_mem == NULL) {
148 RTE_LOG(ERR, PMD, "Failed to alloc memory for %d filters",
152 bp->filter_info = filter_mem;