1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2014-2018 Broadcom
8 #include <rte_malloc.h>
12 #include "bnxt_filter.h"
13 #include "bnxt_hwrm.h"
14 #include "bnxt_ring.h"
17 #include "bnxt_vnic.h"
18 #include "hsi_struct_def_dpdk.h"
24 void bnxt_free_rxq_stats(struct bnxt_rx_queue *rxq)
26 struct bnxt_cp_ring_info *cpr = rxq->cp_ring;
32 int bnxt_mq_rx_configure(struct bnxt *bp)
34 struct rte_eth_conf *dev_conf = &bp->eth_dev->data->dev_conf;
35 const struct rte_eth_vmdq_rx_conf *conf =
36 &dev_conf->rx_adv_conf.vmdq_rx_conf;
37 unsigned int i, j, nb_q_per_grp = 1, ring_idx = 0;
38 int start_grp_id, end_grp_id = 1, rc = 0;
39 struct bnxt_vnic_info *vnic;
40 struct bnxt_filter_info *filter;
41 enum rte_eth_nb_pools pools = bp->rx_cp_nr_rings, max_pools = 0;
42 struct bnxt_rx_queue *rxq;
46 /* Single queue mode */
47 if (bp->rx_cp_nr_rings < 2) {
48 vnic = bnxt_alloc_vnic(bp);
50 PMD_DRV_LOG(ERR, "VNIC alloc failed\n");
54 vnic->flags |= BNXT_VNIC_INFO_BCAST;
55 STAILQ_INSERT_TAIL(&bp->ff_pool[0], vnic, next);
58 rxq = bp->eth_dev->data->rx_queues[0];
61 vnic->func_default = true;
62 vnic->ff_pool_idx = 0;
63 vnic->start_grp_id = 0;
64 vnic->end_grp_id = vnic->start_grp_id;
65 filter = bnxt_alloc_filter(bp);
67 PMD_DRV_LOG(ERR, "L2 filter alloc failed\n");
71 STAILQ_INSERT_TAIL(&vnic->filter, filter, next);
75 /* Multi-queue mode */
76 if (dev_conf->rxmode.mq_mode & ETH_MQ_RX_VMDQ_DCB_RSS) {
77 /* VMDq ONLY, VMDq+RSS, VMDq+DCB, VMDq+DCB+RSS */
79 switch (dev_conf->rxmode.mq_mode) {
80 case ETH_MQ_RX_VMDQ_RSS:
81 case ETH_MQ_RX_VMDQ_ONLY:
83 pools = conf->nb_queue_pools;
84 /* For each pool, allocate MACVLAN CFA rule & VNIC */
85 max_pools = RTE_MIN(bp->max_vnics,
86 RTE_MIN(bp->max_l2_ctx,
87 RTE_MIN(bp->max_rsscos_ctx,
89 if (pools > max_pools)
96 PMD_DRV_LOG(ERR, "Unsupported mq_mod %d\n",
97 dev_conf->rxmode.mq_mode);
103 nb_q_per_grp = bp->rx_cp_nr_rings / pools;
105 end_grp_id = nb_q_per_grp;
107 for (i = 0; i < pools; i++) {
108 vnic = bnxt_alloc_vnic(bp);
110 PMD_DRV_LOG(ERR, "VNIC alloc failed\n");
114 vnic->flags |= BNXT_VNIC_INFO_BCAST;
115 STAILQ_INSERT_TAIL(&bp->ff_pool[i], vnic, next);
118 for (j = 0; j < nb_q_per_grp; j++, ring_idx++) {
119 rxq = bp->eth_dev->data->rx_queues[ring_idx];
123 if (dev_conf->rxmode.mq_mode & ETH_MQ_RX_VMDQ_DCB) {
124 bp->eth_dev->data->promiscuous = 1;
125 vnic->flags |= BNXT_VNIC_INFO_PROMISC;
127 vnic->func_default = true;
129 vnic->ff_pool_idx = i;
130 vnic->start_grp_id = start_grp_id;
131 vnic->end_grp_id = end_grp_id;
134 if (dev_conf->rxmode.mq_mode & ETH_MQ_RX_VMDQ_DCB ||
135 !(dev_conf->rxmode.mq_mode & ETH_MQ_RX_RSS))
136 vnic->rss_dflt_cr = true;
137 goto skip_filter_allocation;
139 filter = bnxt_alloc_filter(bp);
141 PMD_DRV_LOG(ERR, "L2 filter alloc failed\n");
146 * TODO: Configure & associate CFA rule for
147 * each VNIC for each VMDq with MACVLAN, MACVLAN+TC
149 STAILQ_INSERT_TAIL(&vnic->filter, filter, next);
151 skip_filter_allocation:
152 start_grp_id = end_grp_id;
153 end_grp_id += nb_q_per_grp;
157 if (dev_conf->rxmode.mq_mode & ETH_MQ_RX_RSS_FLAG) {
158 struct rte_eth_rss_conf *rss = &dev_conf->rx_adv_conf.rss_conf;
159 uint16_t hash_type = 0;
161 if (bp->flags & BNXT_FLAG_UPDATE_HASH) {
163 bp->flags &= ~BNXT_FLAG_UPDATE_HASH;
166 if (rss->rss_hf & ETH_RSS_IPV4)
167 hash_type |= HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_IPV4;
168 if (rss->rss_hf & ETH_RSS_NONFRAG_IPV4_TCP)
169 hash_type |= HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_TCP_IPV4;
170 if (rss->rss_hf & ETH_RSS_NONFRAG_IPV4_UDP)
171 hash_type |= HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_UDP_IPV4;
172 if (rss->rss_hf & ETH_RSS_IPV6)
173 hash_type |= HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_IPV6;
174 if (rss->rss_hf & ETH_RSS_NONFRAG_IPV6_TCP)
175 hash_type |= HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_TCP_IPV6;
176 if (rss->rss_hf & ETH_RSS_NONFRAG_IPV6_UDP)
177 hash_type |= HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_UDP_IPV6;
179 for (i = 0; i < bp->nr_vnics; i++) {
180 STAILQ_FOREACH(vnic, &bp->ff_pool[i], next) {
181 vnic->hash_type = hash_type;
184 * Use the supplied key if the key length is
185 * acceptable and the rss_key is not NULL
188 rss->rss_key_len <= HW_HASH_KEY_SIZE)
189 memcpy(vnic->rss_hash_key,
190 rss->rss_key, rss->rss_key_len);
198 /* Free allocated vnic/filters */
203 static void bnxt_rx_queue_release_mbufs(struct bnxt_rx_queue *rxq)
205 struct bnxt_sw_rx_bd *sw_ring;
206 struct bnxt_tpa_info *tpa_info;
210 sw_ring = rxq->rx_ring->rx_buf_ring;
212 for (i = 0; i < rxq->nb_rx_desc; i++) {
213 if (sw_ring[i].mbuf) {
214 rte_pktmbuf_free_seg(sw_ring[i].mbuf);
215 sw_ring[i].mbuf = NULL;
219 /* Free up mbufs in Agg ring */
220 sw_ring = rxq->rx_ring->ag_buf_ring;
222 for (i = 0; i < rxq->nb_rx_desc; i++) {
223 if (sw_ring[i].mbuf) {
224 rte_pktmbuf_free_seg(sw_ring[i].mbuf);
225 sw_ring[i].mbuf = NULL;
230 /* Free up mbufs in TPA */
231 tpa_info = rxq->rx_ring->tpa_info;
233 for (i = 0; i < BNXT_TPA_MAX; i++) {
234 if (tpa_info[i].mbuf) {
235 rte_pktmbuf_free_seg(tpa_info[i].mbuf);
236 tpa_info[i].mbuf = NULL;
243 void bnxt_free_rx_mbufs(struct bnxt *bp)
245 struct bnxt_rx_queue *rxq;
248 for (i = 0; i < (int)bp->rx_nr_rings; i++) {
249 rxq = bp->rx_queues[i];
250 bnxt_rx_queue_release_mbufs(rxq);
254 void bnxt_rx_queue_release_op(void *rx_queue)
256 struct bnxt_rx_queue *rxq = (struct bnxt_rx_queue *)rx_queue;
259 bnxt_rx_queue_release_mbufs(rxq);
261 /* Free RX ring hardware descriptors */
262 bnxt_free_ring(rxq->rx_ring->rx_ring_struct);
263 /* Free RX Agg ring hardware descriptors */
264 bnxt_free_ring(rxq->rx_ring->ag_ring_struct);
266 /* Free RX completion ring hardware descriptors */
267 bnxt_free_ring(rxq->cp_ring->cp_ring_struct);
269 bnxt_free_rxq_stats(rxq);
275 int bnxt_rx_queue_setup_op(struct rte_eth_dev *eth_dev,
278 unsigned int socket_id,
279 const struct rte_eth_rxconf *rx_conf,
280 struct rte_mempool *mp)
282 struct bnxt *bp = (struct bnxt *)eth_dev->data->dev_private;
283 struct bnxt_rx_queue *rxq;
286 if (queue_idx >= bp->max_rx_rings) {
288 "Cannot create Rx ring %d. Only %d rings available\n",
289 queue_idx, bp->max_rx_rings);
293 if (!nb_desc || nb_desc > MAX_RX_DESC_CNT) {
294 PMD_DRV_LOG(ERR, "nb_desc %d is invalid\n", nb_desc);
299 if (eth_dev->data->rx_queues) {
300 rxq = eth_dev->data->rx_queues[queue_idx];
302 bnxt_rx_queue_release_op(rxq);
304 rxq = rte_zmalloc_socket("bnxt_rx_queue", sizeof(struct bnxt_rx_queue),
305 RTE_CACHE_LINE_SIZE, socket_id);
307 PMD_DRV_LOG(ERR, "bnxt_rx_queue allocation failed!\n");
313 rxq->nb_rx_desc = nb_desc;
314 rxq->rx_free_thresh = rx_conf->rx_free_thresh;
316 PMD_DRV_LOG(DEBUG, "RX Buf size is %d\n", rxq->rx_buf_use_size);
317 PMD_DRV_LOG(DEBUG, "RX Buf MTU %d\n", eth_dev->data->mtu);
319 rc = bnxt_init_rx_ring_struct(rxq, socket_id);
323 rxq->queue_id = queue_idx;
324 rxq->port_id = eth_dev->data->port_id;
325 rxq->crc_len = (uint8_t)((eth_dev->data->dev_conf.rxmode.hw_strip_crc) ?
328 eth_dev->data->rx_queues[queue_idx] = rxq;
329 /* Allocate RX ring hardware descriptors */
330 if (bnxt_alloc_rings(bp, queue_idx, NULL, rxq->rx_ring, rxq->cp_ring,
333 "ring_dma_zone_reserve for rx_ring failed!\n");
334 bnxt_rx_queue_release_op(rxq);
344 bnxt_rx_queue_intr_enable_op(struct rte_eth_dev *eth_dev, uint16_t queue_id)
346 struct bnxt_rx_queue *rxq;
347 struct bnxt_cp_ring_info *cpr;
350 if (eth_dev->data->rx_queues) {
351 rxq = eth_dev->data->rx_queues[queue_id];
363 bnxt_rx_queue_intr_disable_op(struct rte_eth_dev *eth_dev, uint16_t queue_id)
365 struct bnxt_rx_queue *rxq;
366 struct bnxt_cp_ring_info *cpr;
369 if (eth_dev->data->rx_queues) {
370 rxq = eth_dev->data->rx_queues[queue_id];
381 int bnxt_rx_queue_start(struct rte_eth_dev *dev, uint16_t rx_queue_id)
383 struct bnxt *bp = (struct bnxt *)dev->data->dev_private;
384 struct rte_eth_conf *dev_conf = &bp->eth_dev->data->dev_conf;
385 struct bnxt_rx_queue *rxq = bp->rx_queues[rx_queue_id];
386 struct bnxt_vnic_info *vnic = NULL;
389 PMD_DRV_LOG(ERR, "Invalid Rx queue %d\n", rx_queue_id);
393 dev->data->rx_queue_state[rx_queue_id] = RTE_ETH_QUEUE_STATE_STARTED;
394 rxq->rx_deferred_start = false;
395 PMD_DRV_LOG(INFO, "Rx queue started %d\n", rx_queue_id);
396 if (dev_conf->rxmode.mq_mode & ETH_MQ_RX_RSS_FLAG) {
398 if (vnic->fw_grp_ids[rx_queue_id] != INVALID_HW_RING_ID)
400 PMD_DRV_LOG(DEBUG, "vnic = %p fw_grp_id = %d\n",
401 vnic, bp->grp_info[rx_queue_id + 1].fw_grp_id);
402 vnic->fw_grp_ids[rx_queue_id] =
403 bp->grp_info[rx_queue_id + 1].fw_grp_id;
404 return bnxt_vnic_rss_configure(bp, vnic);
410 int bnxt_rx_queue_stop(struct rte_eth_dev *dev, uint16_t rx_queue_id)
412 struct bnxt *bp = (struct bnxt *)dev->data->dev_private;
413 struct rte_eth_conf *dev_conf = &bp->eth_dev->data->dev_conf;
414 struct bnxt_rx_queue *rxq = bp->rx_queues[rx_queue_id];
415 struct bnxt_vnic_info *vnic = NULL;
418 PMD_DRV_LOG(ERR, "Invalid Rx queue %d\n", rx_queue_id);
422 dev->data->rx_queue_state[rx_queue_id] = RTE_ETH_QUEUE_STATE_STOPPED;
423 rxq->rx_deferred_start = true;
424 PMD_DRV_LOG(DEBUG, "Rx queue stopped\n");
426 if (dev_conf->rxmode.mq_mode & ETH_MQ_RX_RSS_FLAG) {
428 vnic->fw_grp_ids[rx_queue_id] = INVALID_HW_RING_ID;
429 return bnxt_vnic_rss_configure(bp, vnic);