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.
36 #include <rte_malloc.h>
40 #include "bnxt_filter.h"
41 #include "bnxt_hwrm.h"
42 #include "bnxt_ring.h"
44 #include "bnxt_vnic.h"
45 #include "hsi_struct_def_dpdk.h"
51 void bnxt_free_rxq_stats(struct bnxt_rx_queue *rxq)
53 struct bnxt_cp_ring_info *cpr = rxq->cp_ring;
55 /* 'Unreserve' rte_memzone */
61 int bnxt_mq_rx_configure(struct bnxt *bp)
63 struct rte_eth_conf *dev_conf = &bp->eth_dev->data->dev_conf;
64 unsigned int i, j, nb_q_per_grp, ring_idx;
65 int start_grp_id, end_grp_id, rc = 0;
66 struct bnxt_vnic_info *vnic;
67 struct bnxt_filter_info *filter;
68 struct bnxt_rx_queue *rxq;
72 /* Single queue mode */
73 if (bp->rx_cp_nr_rings < 2) {
74 vnic = bnxt_alloc_vnic(bp);
76 RTE_LOG(ERR, PMD, "VNIC alloc failed\n");
80 STAILQ_INSERT_TAIL(&bp->ff_pool[0], vnic, next);
83 rxq = bp->eth_dev->data->rx_queues[0];
86 vnic->func_default = true;
87 vnic->ff_pool_idx = 0;
88 vnic->start_grp_id = 1;
89 vnic->end_grp_id = vnic->start_grp_id +
90 bp->rx_cp_nr_rings - 1;
91 filter = bnxt_alloc_filter(bp);
93 RTE_LOG(ERR, PMD, "L2 filter alloc failed\n");
97 STAILQ_INSERT_TAIL(&vnic->filter, filter, next);
101 /* Multi-queue mode */
102 if (dev_conf->rxmode.mq_mode & ETH_MQ_RX_VMDQ_FLAG) {
103 /* VMDq ONLY, VMDq+RSS, VMDq+DCB, VMDq+DCB+RSS */
104 enum rte_eth_nb_pools pools;
106 switch (dev_conf->rxmode.mq_mode) {
107 case ETH_MQ_RX_VMDQ_RSS:
108 case ETH_MQ_RX_VMDQ_ONLY:
110 const struct rte_eth_vmdq_rx_conf *conf =
111 &dev_conf->rx_adv_conf.vmdq_rx_conf;
114 pools = conf->nb_queue_pools;
118 RTE_LOG(ERR, PMD, "Unsupported mq_mod %d\n",
119 dev_conf->rxmode.mq_mode);
123 /* For each pool, allocate MACVLAN CFA rule & VNIC */
126 "VMDq pool not set, defaulted to 64\n");
127 pools = ETH_64_POOLS;
129 nb_q_per_grp = bp->rx_cp_nr_rings / pools;
131 end_grp_id = start_grp_id + nb_q_per_grp - 1;
134 for (i = 0; i < pools; i++) {
135 vnic = bnxt_alloc_vnic(bp);
138 "VNIC alloc failed\n");
142 STAILQ_INSERT_TAIL(&bp->ff_pool[i], vnic, next);
145 for (j = 0; j < nb_q_per_grp; j++, ring_idx++) {
146 rxq = bp->eth_dev->data->rx_queues[ring_idx];
150 vnic->func_default = true;
151 vnic->ff_pool_idx = i;
152 vnic->start_grp_id = start_grp_id;
153 vnic->end_grp_id = end_grp_id;
155 filter = bnxt_alloc_filter(bp);
158 "L2 filter alloc failed\n");
163 * TODO: Configure & associate CFA rule for
164 * each VNIC for each VMDq with MACVLAN, MACVLAN+TC
166 STAILQ_INSERT_TAIL(&vnic->filter, filter, next);
168 start_grp_id = end_grp_id + 1;
169 end_grp_id += nb_q_per_grp;
174 /* Non-VMDq mode - RSS, DCB, RSS+DCB */
175 /* Init default VNIC for RSS or DCB only */
176 vnic = bnxt_alloc_vnic(bp);
178 RTE_LOG(ERR, PMD, "VNIC alloc failed\n");
182 /* Partition the rx queues for the single pool */
183 for (i = 0; i < bp->rx_cp_nr_rings; i++) {
184 rxq = bp->eth_dev->data->rx_queues[i];
187 STAILQ_INSERT_TAIL(&bp->ff_pool[0], vnic, next);
190 vnic->func_default = true;
191 vnic->ff_pool_idx = 0;
192 vnic->start_grp_id = 1;
193 vnic->end_grp_id = vnic->start_grp_id +
194 bp->rx_cp_nr_rings - 1;
195 filter = bnxt_alloc_filter(bp);
197 RTE_LOG(ERR, PMD, "L2 filter alloc failed\n");
201 STAILQ_INSERT_TAIL(&vnic->filter, filter, next);
203 if (dev_conf->rxmode.mq_mode & ETH_MQ_RX_RSS_FLAG)
205 HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_IPV4 |
206 HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_IPV6;
212 /* Free allocated vnic/filters */
217 static void bnxt_rx_queue_release_mbufs(struct bnxt_rx_queue *rxq __rte_unused)
219 /* TODO: Requires interaction with TX ring */
222 void bnxt_free_rx_mbufs(struct bnxt *bp)
224 struct bnxt_rx_queue *rxq;
227 for (i = 0; i < (int)bp->rx_nr_rings; i++) {
228 rxq = bp->rx_queues[i];
229 bnxt_rx_queue_release_mbufs(rxq);
233 void bnxt_rx_queue_release_op(void *rx_queue)
235 struct bnxt_rx_queue *rxq = (struct bnxt_rx_queue *)rx_queue;
238 bnxt_rx_queue_release_mbufs(rxq);
240 /* TODO: Free ring and stats here */
246 int bnxt_rx_queue_setup_op(struct rte_eth_dev *eth_dev,
249 unsigned int socket_id,
250 const struct rte_eth_rxconf *rx_conf,
251 struct rte_mempool *mp)
253 struct bnxt *bp = (struct bnxt *)eth_dev->data->dev_private;
254 struct bnxt_rx_queue *rxq;
256 if (!nb_desc || nb_desc > MAX_RX_DESC_CNT) {
257 RTE_LOG(ERR, PMD, "nb_desc %d is invalid", nb_desc);
261 if (eth_dev->data->rx_queues) {
262 rxq = eth_dev->data->rx_queues[queue_idx];
264 bnxt_rx_queue_release_op(rxq);
266 rxq = rte_zmalloc_socket("bnxt_rx_queue", sizeof(struct bnxt_rx_queue),
267 RTE_CACHE_LINE_SIZE, socket_id);
269 RTE_LOG(ERR, PMD, "bnxt_rx_queue allocation failed!");
274 rxq->nb_rx_desc = nb_desc;
275 rxq->rx_free_thresh = rx_conf->rx_free_thresh;
277 /* TODO: Initialize ring structure */
279 rxq->queue_id = queue_idx;
280 rxq->port_id = eth_dev->data->port_id;
281 rxq->crc_len = (uint8_t)((eth_dev->data->dev_conf.rxmode.hw_strip_crc) ?
284 eth_dev->data->rx_queues[queue_idx] = rxq;
285 /* TODO: Allocate RX ring hardware descriptors */