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 if (rxq && rxq->cp_ring && rxq->cp_ring->hw_stats)
27 rxq->cp_ring->hw_stats = NULL;
30 int bnxt_mq_rx_configure(struct bnxt *bp)
32 struct rte_eth_conf *dev_conf = &bp->eth_dev->data->dev_conf;
33 const struct rte_eth_vmdq_rx_conf *conf =
34 &dev_conf->rx_adv_conf.vmdq_rx_conf;
35 unsigned int i, j, nb_q_per_grp = 1, ring_idx = 0;
36 int start_grp_id, end_grp_id = 1, rc = 0;
37 struct bnxt_vnic_info *vnic;
38 struct bnxt_filter_info *filter;
39 enum rte_eth_nb_pools pools = bp->rx_cp_nr_rings, max_pools = 0;
40 struct bnxt_rx_queue *rxq;
44 /* Single queue mode */
45 if (bp->rx_cp_nr_rings < 2) {
46 vnic = &bp->vnic_info[0];
48 PMD_DRV_LOG(ERR, "VNIC alloc failed\n");
52 vnic->flags |= BNXT_VNIC_INFO_BCAST;
55 rxq = bp->eth_dev->data->rx_queues[0];
58 vnic->func_default = true;
59 vnic->start_grp_id = 0;
60 vnic->end_grp_id = vnic->start_grp_id;
61 filter = bnxt_alloc_filter(bp);
63 PMD_DRV_LOG(ERR, "L2 filter alloc failed\n");
67 STAILQ_INSERT_TAIL(&vnic->filter, filter, next);
71 /* Multi-queue mode */
72 if (dev_conf->rxmode.mq_mode & ETH_MQ_RX_VMDQ_DCB_RSS) {
73 /* VMDq ONLY, VMDq+RSS, VMDq+DCB, VMDq+DCB+RSS */
75 switch (dev_conf->rxmode.mq_mode) {
76 case ETH_MQ_RX_VMDQ_RSS:
77 case ETH_MQ_RX_VMDQ_ONLY:
80 pools = conf->nb_queue_pools;
81 /* For each pool, allocate MACVLAN CFA rule & VNIC */
82 max_pools = RTE_MIN(bp->max_vnics,
83 RTE_MIN(bp->max_l2_ctx,
84 RTE_MIN(bp->max_rsscos_ctx,
87 "pools = %u max_pools = %u\n",
89 if (pools > max_pools)
96 PMD_DRV_LOG(ERR, "Unsupported mq_mod %d\n",
97 dev_conf->rxmode.mq_mode);
102 nb_q_per_grp = bp->rx_cp_nr_rings / pools;
103 PMD_DRV_LOG(DEBUG, "pools = %u nb_q_per_grp = %u\n",
104 pools, nb_q_per_grp);
106 end_grp_id = nb_q_per_grp;
108 for (i = 0; i < pools; i++) {
109 vnic = &bp->vnic_info[i];
111 PMD_DRV_LOG(ERR, "VNIC alloc failed\n");
115 vnic->flags |= BNXT_VNIC_INFO_BCAST;
118 for (j = 0; j < nb_q_per_grp; j++, ring_idx++) {
119 rxq = bp->eth_dev->data->rx_queues[ring_idx];
122 "rxq[%d] = %p vnic[%d] = %p\n",
123 ring_idx, rxq, i, vnic);
126 if (dev_conf->rxmode.mq_mode & ETH_MQ_RX_VMDQ_DCB) {
127 bp->eth_dev->data->promiscuous = 1;
128 vnic->flags |= BNXT_VNIC_INFO_PROMISC;
130 vnic->func_default = true;
132 vnic->start_grp_id = start_grp_id;
133 vnic->end_grp_id = end_grp_id;
136 if (dev_conf->rxmode.mq_mode & ETH_MQ_RX_VMDQ_DCB ||
137 !(dev_conf->rxmode.mq_mode & ETH_MQ_RX_RSS))
138 vnic->rss_dflt_cr = true;
139 goto skip_filter_allocation;
141 filter = bnxt_alloc_filter(bp);
143 PMD_DRV_LOG(ERR, "L2 filter alloc failed\n");
148 * TODO: Configure & associate CFA rule for
149 * each VNIC for each VMDq with MACVLAN, MACVLAN+TC
151 STAILQ_INSERT_TAIL(&vnic->filter, filter, next);
153 skip_filter_allocation:
154 start_grp_id = end_grp_id;
155 end_grp_id += nb_q_per_grp;
159 if (dev_conf->rxmode.mq_mode & ETH_MQ_RX_RSS_FLAG) {
160 struct rte_eth_rss_conf *rss = &dev_conf->rx_adv_conf.rss_conf;
161 uint16_t hash_type = 0;
163 if (bp->flags & BNXT_FLAG_UPDATE_HASH) {
165 bp->flags &= ~BNXT_FLAG_UPDATE_HASH;
168 if (rss->rss_hf & ETH_RSS_IPV4)
169 hash_type |= HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_IPV4;
170 if (rss->rss_hf & ETH_RSS_NONFRAG_IPV4_TCP)
171 hash_type |= HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_TCP_IPV4;
172 if (rss->rss_hf & ETH_RSS_NONFRAG_IPV4_UDP)
173 hash_type |= HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_UDP_IPV4;
174 if (rss->rss_hf & ETH_RSS_IPV6)
175 hash_type |= HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_IPV6;
176 if (rss->rss_hf & ETH_RSS_NONFRAG_IPV6_TCP)
177 hash_type |= HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_TCP_IPV6;
178 if (rss->rss_hf & ETH_RSS_NONFRAG_IPV6_UDP)
179 hash_type |= HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_UDP_IPV6;
181 for (i = 0; i < bp->nr_vnics; i++) {
182 vnic = &bp->vnic_info[i];
183 vnic->hash_type = hash_type;
186 * Use the supplied key if the key length is
187 * acceptable and the rss_key is not NULL
190 rss->rss_key_len <= HW_HASH_KEY_SIZE)
191 memcpy(vnic->rss_hash_key,
192 rss->rss_key, rss->rss_key_len);
199 /* Free allocated vnic/filters */
204 void bnxt_rx_queue_release_mbufs(struct bnxt_rx_queue *rxq)
206 struct bnxt_sw_rx_bd *sw_ring;
207 struct bnxt_tpa_info *tpa_info;
213 rte_spinlock_lock(&rxq->lock);
215 sw_ring = rxq->rx_ring->rx_buf_ring;
218 i < rxq->rx_ring->rx_ring_struct->ring_size; i++) {
219 if (sw_ring[i].mbuf) {
220 rte_pktmbuf_free_seg(sw_ring[i].mbuf);
221 sw_ring[i].mbuf = NULL;
225 /* Free up mbufs in Agg ring */
226 sw_ring = rxq->rx_ring->ag_buf_ring;
229 i < rxq->rx_ring->ag_ring_struct->ring_size; i++) {
230 if (sw_ring[i].mbuf) {
231 rte_pktmbuf_free_seg(sw_ring[i].mbuf);
232 sw_ring[i].mbuf = NULL;
237 /* Free up mbufs in TPA */
238 tpa_info = rxq->rx_ring->tpa_info;
240 for (i = 0; i < BNXT_TPA_MAX; i++) {
241 if (tpa_info[i].mbuf) {
242 rte_pktmbuf_free_seg(tpa_info[i].mbuf);
243 tpa_info[i].mbuf = NULL;
248 rte_spinlock_unlock(&rxq->lock);
251 void bnxt_free_rx_mbufs(struct bnxt *bp)
253 struct bnxt_rx_queue *rxq;
256 for (i = 0; i < (int)bp->rx_nr_rings; i++) {
257 rxq = bp->rx_queues[i];
258 bnxt_rx_queue_release_mbufs(rxq);
262 void bnxt_rx_queue_release_op(void *rx_queue)
264 struct bnxt_rx_queue *rxq = (struct bnxt_rx_queue *)rx_queue;
267 if (is_bnxt_in_error(rxq->bp))
270 bnxt_rx_queue_release_mbufs(rxq);
272 /* Free RX ring hardware descriptors */
273 bnxt_free_ring(rxq->rx_ring->rx_ring_struct);
274 /* Free RX Agg ring hardware descriptors */
275 bnxt_free_ring(rxq->rx_ring->ag_ring_struct);
277 /* Free RX completion ring hardware descriptors */
278 bnxt_free_ring(rxq->cp_ring->cp_ring_struct);
280 bnxt_free_rxq_stats(rxq);
281 rte_memzone_free(rxq->mz);
288 int bnxt_rx_queue_setup_op(struct rte_eth_dev *eth_dev,
291 unsigned int socket_id,
292 const struct rte_eth_rxconf *rx_conf,
293 struct rte_mempool *mp)
295 struct bnxt *bp = eth_dev->data->dev_private;
296 uint64_t rx_offloads = eth_dev->data->dev_conf.rxmode.offloads;
297 struct bnxt_rx_queue *rxq;
301 rc = is_bnxt_in_error(bp);
305 if (queue_idx >= bp->max_rx_rings) {
307 "Cannot create Rx ring %d. Only %d rings available\n",
308 queue_idx, bp->max_rx_rings);
312 if (!nb_desc || nb_desc > MAX_RX_DESC_CNT) {
313 PMD_DRV_LOG(ERR, "nb_desc %d is invalid\n", nb_desc);
318 if (eth_dev->data->rx_queues) {
319 rxq = eth_dev->data->rx_queues[queue_idx];
321 bnxt_rx_queue_release_op(rxq);
323 rxq = rte_zmalloc_socket("bnxt_rx_queue", sizeof(struct bnxt_rx_queue),
324 RTE_CACHE_LINE_SIZE, socket_id);
326 PMD_DRV_LOG(ERR, "bnxt_rx_queue allocation failed!\n");
332 rxq->nb_rx_desc = nb_desc;
333 rxq->rx_free_thresh = rx_conf->rx_free_thresh;
335 PMD_DRV_LOG(DEBUG, "RX Buf MTU %d\n", eth_dev->data->mtu);
337 rc = bnxt_init_rx_ring_struct(rxq, socket_id);
341 PMD_DRV_LOG(DEBUG, "RX Buf size is %d\n", rxq->rx_buf_size);
342 rxq->queue_id = queue_idx;
343 rxq->port_id = eth_dev->data->port_id;
344 if (rx_offloads & DEV_RX_OFFLOAD_KEEP_CRC)
345 rxq->crc_len = RTE_ETHER_CRC_LEN;
349 eth_dev->data->rx_queues[queue_idx] = rxq;
350 /* Allocate RX ring hardware descriptors */
351 if (bnxt_alloc_rings(bp, queue_idx, NULL, rxq, rxq->cp_ring,
352 rxq->nq_ring, "rxr")) {
354 "ring_dma_zone_reserve for rx_ring failed!\n");
355 bnxt_rx_queue_release_op(rxq);
359 rte_atomic64_init(&rxq->rx_mbuf_alloc_fail);
361 /* rxq 0 must not be stopped when used as async CPR */
362 if (!BNXT_NUM_ASYNC_CPR(bp) && queue_idx == 0)
363 rxq->rx_deferred_start = false;
365 rxq->rx_deferred_start = rx_conf->rx_deferred_start;
367 if (rxq->rx_deferred_start) {
368 queue_state = RTE_ETH_QUEUE_STATE_STOPPED;
369 rxq->rx_started = false;
371 queue_state = RTE_ETH_QUEUE_STATE_STARTED;
372 rxq->rx_started = true;
374 eth_dev->data->rx_queue_state[queue_idx] = queue_state;
375 rte_spinlock_init(&rxq->lock);
382 bnxt_rx_queue_intr_enable_op(struct rte_eth_dev *eth_dev, uint16_t queue_id)
384 struct bnxt *bp = eth_dev->data->dev_private;
385 struct bnxt_rx_queue *rxq;
386 struct bnxt_cp_ring_info *cpr;
389 rc = is_bnxt_in_error(bp);
393 if (eth_dev->data->rx_queues) {
394 rxq = eth_dev->data->rx_queues[queue_id];
400 B_CP_DB_REARM(cpr, cpr->cp_raw_cons);
406 bnxt_rx_queue_intr_disable_op(struct rte_eth_dev *eth_dev, uint16_t queue_id)
408 struct bnxt *bp = eth_dev->data->dev_private;
409 struct bnxt_rx_queue *rxq;
410 struct bnxt_cp_ring_info *cpr;
413 rc = is_bnxt_in_error(bp);
417 if (eth_dev->data->rx_queues) {
418 rxq = eth_dev->data->rx_queues[queue_id];
429 int bnxt_rx_queue_start(struct rte_eth_dev *dev, uint16_t rx_queue_id)
431 struct bnxt *bp = dev->data->dev_private;
432 struct rte_eth_conf *dev_conf = &bp->eth_dev->data->dev_conf;
433 struct bnxt_rx_queue *rxq = bp->rx_queues[rx_queue_id];
434 struct bnxt_vnic_info *vnic = NULL;
437 rc = is_bnxt_in_error(bp);
442 PMD_DRV_LOG(ERR, "Invalid Rx queue %d\n", rx_queue_id);
446 /* Set the queue state to started here.
447 * We check the status of the queue while posting buffer.
448 * If queue is it started, we do not post buffers for Rx.
450 rxq->rx_started = true;
451 bnxt_free_hwrm_rx_ring(bp, rx_queue_id);
452 rc = bnxt_alloc_hwrm_rx_ring(bp, rx_queue_id);
456 PMD_DRV_LOG(INFO, "Rx queue started %d\n", rx_queue_id);
458 if (dev_conf->rxmode.mq_mode & ETH_MQ_RX_RSS_FLAG) {
461 if (BNXT_HAS_RING_GRPS(bp)) {
462 if (vnic->fw_grp_ids[rx_queue_id] != INVALID_HW_RING_ID)
465 vnic->fw_grp_ids[rx_queue_id] =
466 bp->grp_info[rx_queue_id].fw_grp_id;
468 "vnic = %p fw_grp_id = %d\n",
469 vnic, bp->grp_info[rx_queue_id].fw_grp_id);
472 rc = bnxt_vnic_rss_configure(bp, vnic);
476 dev->data->rx_queue_state[rx_queue_id] =
477 RTE_ETH_QUEUE_STATE_STARTED;
479 rxq->rx_started = false;
482 "queue %d, rx_deferred_start %d, state %d!\n",
483 rx_queue_id, rxq->rx_deferred_start,
484 bp->eth_dev->data->rx_queue_state[rx_queue_id]);
489 int bnxt_rx_queue_stop(struct rte_eth_dev *dev, uint16_t rx_queue_id)
491 struct bnxt *bp = dev->data->dev_private;
492 struct rte_eth_conf *dev_conf = &bp->eth_dev->data->dev_conf;
493 struct bnxt_vnic_info *vnic = NULL;
494 struct bnxt_rx_queue *rxq = NULL;
497 rc = is_bnxt_in_error(bp);
501 /* For the stingray platform and other platforms needing tighter
502 * control of resource utilization, Rx CQ 0 also works as
503 * Default CQ for async notifications
505 if (!BNXT_NUM_ASYNC_CPR(bp) && !rx_queue_id) {
506 PMD_DRV_LOG(ERR, "Cannot stop Rx queue id %d\n", rx_queue_id);
510 rxq = bp->rx_queues[rx_queue_id];
513 PMD_DRV_LOG(ERR, "Invalid Rx queue %d\n", rx_queue_id);
517 dev->data->rx_queue_state[rx_queue_id] = RTE_ETH_QUEUE_STATE_STOPPED;
518 rxq->rx_started = false;
519 PMD_DRV_LOG(DEBUG, "Rx queue stopped\n");
521 if (dev_conf->rxmode.mq_mode & ETH_MQ_RX_RSS_FLAG) {
523 if (BNXT_HAS_RING_GRPS(bp))
524 vnic->fw_grp_ids[rx_queue_id] = INVALID_HW_RING_ID;
525 rc = bnxt_vnic_rss_configure(bp, vnic);
529 bnxt_rx_queue_release_mbufs(rxq);