1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2014-2018 Broadcom
8 #include <rte_malloc.h>
11 #include "bnxt_filter.h"
12 #include "bnxt_hwrm.h"
13 #include "bnxt_ring.h"
16 #include "bnxt_vnic.h"
17 #include "hsi_struct_def_dpdk.h"
23 void bnxt_free_rxq_stats(struct bnxt_rx_queue *rxq)
25 if (rxq && rxq->cp_ring && rxq->cp_ring->hw_stats)
26 rxq->cp_ring->hw_stats = NULL;
29 int bnxt_mq_rx_configure(struct bnxt *bp)
31 struct rte_eth_conf *dev_conf = &bp->eth_dev->data->dev_conf;
32 const struct rte_eth_vmdq_rx_conf *conf =
33 &dev_conf->rx_adv_conf.vmdq_rx_conf;
34 unsigned int i, j, nb_q_per_grp = 1, ring_idx = 0;
35 int start_grp_id, end_grp_id = 1, rc = 0;
36 struct bnxt_vnic_info *vnic;
37 struct bnxt_filter_info *filter;
38 enum rte_eth_nb_pools pools = bp->rx_cp_nr_rings, max_pools = 0;
39 struct bnxt_rx_queue *rxq;
43 /* Single queue mode */
44 if (bp->rx_cp_nr_rings < 2) {
45 vnic = &bp->vnic_info[0];
47 PMD_DRV_LOG(ERR, "VNIC alloc failed\n");
51 vnic->flags |= BNXT_VNIC_INFO_BCAST;
54 rxq = bp->eth_dev->data->rx_queues[0];
57 vnic->func_default = true;
58 vnic->start_grp_id = 0;
59 vnic->end_grp_id = vnic->start_grp_id;
60 filter = bnxt_alloc_filter(bp);
62 PMD_DRV_LOG(ERR, "L2 filter alloc failed\n");
66 filter->flags |= HWRM_CFA_L2_FILTER_ALLOC_INPUT_FLAGS_OUTERMOST;
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:
78 case ETH_MQ_RX_VMDQ_DCB_RSS:
81 pools = conf->nb_queue_pools;
82 /* For each pool, allocate MACVLAN CFA rule & VNIC */
83 max_pools = RTE_MIN(bp->max_vnics,
84 RTE_MIN(bp->max_l2_ctx,
85 RTE_MIN(bp->max_rsscos_ctx,
88 "pools = %u max_pools = %u\n",
90 if (pools > max_pools)
94 pools = bp->rx_cosq_cnt ? bp->rx_cosq_cnt : 1;
97 PMD_DRV_LOG(ERR, "Unsupported mq_mod %d\n",
98 dev_conf->rxmode.mq_mode);
103 nb_q_per_grp = bp->rx_cp_nr_rings / pools;
104 bp->rx_num_qs_per_vnic = nb_q_per_grp;
105 PMD_DRV_LOG(DEBUG, "pools = %u nb_q_per_grp = %u\n",
106 pools, nb_q_per_grp);
108 end_grp_id = nb_q_per_grp;
110 for (i = 0; i < pools; i++) {
111 vnic = &bp->vnic_info[i];
113 PMD_DRV_LOG(ERR, "VNIC alloc failed\n");
117 vnic->flags |= BNXT_VNIC_INFO_BCAST;
120 for (j = 0; j < nb_q_per_grp; j++, ring_idx++) {
121 rxq = bp->eth_dev->data->rx_queues[ring_idx];
124 "rxq[%d] = %p vnic[%d] = %p\n",
125 ring_idx, rxq, i, vnic);
128 if (dev_conf->rxmode.mq_mode & ETH_MQ_RX_VMDQ_DCB) {
129 bp->eth_dev->data->promiscuous = 1;
130 vnic->flags |= BNXT_VNIC_INFO_PROMISC;
132 vnic->func_default = true;
134 vnic->start_grp_id = start_grp_id;
135 vnic->end_grp_id = end_grp_id;
138 if (dev_conf->rxmode.mq_mode & ETH_MQ_RX_VMDQ_DCB ||
139 !(dev_conf->rxmode.mq_mode & ETH_MQ_RX_RSS))
140 vnic->rss_dflt_cr = true;
141 goto skip_filter_allocation;
143 filter = bnxt_alloc_filter(bp);
145 PMD_DRV_LOG(ERR, "L2 filter alloc failed\n");
149 filter->flags |= HWRM_CFA_L2_FILTER_ALLOC_INPUT_FLAGS_OUTERMOST;
151 * TODO: Configure & associate CFA rule for
152 * each VNIC for each VMDq with MACVLAN, MACVLAN+TC
154 STAILQ_INSERT_TAIL(&vnic->filter, filter, next);
156 skip_filter_allocation:
157 start_grp_id = end_grp_id;
158 end_grp_id += nb_q_per_grp;
162 if (dev_conf->rxmode.mq_mode & ETH_MQ_RX_RSS_FLAG) {
163 struct rte_eth_rss_conf *rss = &dev_conf->rx_adv_conf.rss_conf;
165 if (bp->flags & BNXT_FLAG_UPDATE_HASH) {
167 bp->flags &= ~BNXT_FLAG_UPDATE_HASH;
170 for (i = 0; i < bp->nr_vnics; i++) {
171 vnic = &bp->vnic_info[i];
173 bnxt_rte_to_hwrm_hash_types(rss->rss_hf);
176 * Use the supplied key if the key length is
177 * acceptable and the rss_key is not NULL
180 rss->rss_key_len <= HW_HASH_KEY_SIZE)
181 memcpy(vnic->rss_hash_key,
182 rss->rss_key, rss->rss_key_len);
189 /* Free allocated vnic/filters */
194 void bnxt_rx_queue_release_mbufs(struct bnxt_rx_queue *rxq)
196 struct bnxt_sw_rx_bd *sw_ring;
197 struct bnxt_tpa_info *tpa_info;
203 rte_spinlock_lock(&rxq->lock);
205 sw_ring = rxq->rx_ring->rx_buf_ring;
208 i < rxq->rx_ring->rx_ring_struct->ring_size; i++) {
209 if (sw_ring[i].mbuf) {
210 rte_pktmbuf_free_seg(sw_ring[i].mbuf);
211 sw_ring[i].mbuf = NULL;
215 /* Free up mbufs in Agg ring */
216 sw_ring = rxq->rx_ring->ag_buf_ring;
219 i < rxq->rx_ring->ag_ring_struct->ring_size; i++) {
220 if (sw_ring[i].mbuf) {
221 rte_pktmbuf_free_seg(sw_ring[i].mbuf);
222 sw_ring[i].mbuf = NULL;
227 /* Free up mbufs in TPA */
228 tpa_info = rxq->rx_ring->tpa_info;
230 int max_aggs = BNXT_TPA_MAX_AGGS(rxq->bp);
232 for (i = 0; i < max_aggs; i++) {
233 if (tpa_info[i].mbuf) {
234 rte_pktmbuf_free_seg(tpa_info[i].mbuf);
235 tpa_info[i].mbuf = NULL;
240 rte_spinlock_unlock(&rxq->lock);
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 if (is_bnxt_in_error(rxq->bp))
262 bnxt_rx_queue_release_mbufs(rxq);
264 /* Free RX ring hardware descriptors */
265 bnxt_free_ring(rxq->rx_ring->rx_ring_struct);
266 /* Free RX Agg ring hardware descriptors */
267 bnxt_free_ring(rxq->rx_ring->ag_ring_struct);
269 /* Free RX completion ring hardware descriptors */
270 bnxt_free_ring(rxq->cp_ring->cp_ring_struct);
272 bnxt_free_rxq_stats(rxq);
273 rte_memzone_free(rxq->mz);
280 int bnxt_rx_queue_setup_op(struct rte_eth_dev *eth_dev,
283 unsigned int socket_id,
284 const struct rte_eth_rxconf *rx_conf,
285 struct rte_mempool *mp)
287 struct bnxt *bp = eth_dev->data->dev_private;
288 uint64_t rx_offloads = eth_dev->data->dev_conf.rxmode.offloads;
289 struct bnxt_rx_queue *rxq;
293 rc = is_bnxt_in_error(bp);
297 if (queue_idx >= bp->max_rx_rings) {
299 "Cannot create Rx ring %d. Only %d rings available\n",
300 queue_idx, bp->max_rx_rings);
304 if (!nb_desc || nb_desc > MAX_RX_DESC_CNT) {
305 PMD_DRV_LOG(ERR, "nb_desc %d is invalid\n", nb_desc);
310 if (eth_dev->data->rx_queues) {
311 rxq = eth_dev->data->rx_queues[queue_idx];
313 bnxt_rx_queue_release_op(rxq);
315 rxq = rte_zmalloc_socket("bnxt_rx_queue", sizeof(struct bnxt_rx_queue),
316 RTE_CACHE_LINE_SIZE, socket_id);
318 PMD_DRV_LOG(ERR, "bnxt_rx_queue allocation failed!\n");
324 rxq->nb_rx_desc = nb_desc;
325 rxq->rx_free_thresh = rx_conf->rx_free_thresh;
327 PMD_DRV_LOG(DEBUG, "RX Buf MTU %d\n", eth_dev->data->mtu);
329 rc = bnxt_init_rx_ring_struct(rxq, socket_id);
333 PMD_DRV_LOG(DEBUG, "RX Buf size is %d\n", rxq->rx_buf_size);
334 rxq->queue_id = queue_idx;
335 rxq->port_id = eth_dev->data->port_id;
336 if (rx_offloads & DEV_RX_OFFLOAD_KEEP_CRC)
337 rxq->crc_len = RTE_ETHER_CRC_LEN;
341 eth_dev->data->rx_queues[queue_idx] = rxq;
342 /* Allocate RX ring hardware descriptors */
343 if (bnxt_alloc_rings(bp, queue_idx, NULL, rxq, rxq->cp_ring, NULL,
346 "ring_dma_zone_reserve for rx_ring failed!\n");
347 bnxt_rx_queue_release_op(rxq);
351 rte_atomic64_init(&rxq->rx_mbuf_alloc_fail);
353 /* rxq 0 must not be stopped when used as async CPR */
354 if (!BNXT_NUM_ASYNC_CPR(bp) && queue_idx == 0)
355 rxq->rx_deferred_start = false;
357 rxq->rx_deferred_start = rx_conf->rx_deferred_start;
359 if (rxq->rx_deferred_start) {
360 queue_state = RTE_ETH_QUEUE_STATE_STOPPED;
361 rxq->rx_started = false;
363 queue_state = RTE_ETH_QUEUE_STATE_STARTED;
364 rxq->rx_started = true;
366 eth_dev->data->rx_queue_state[queue_idx] = queue_state;
367 rte_spinlock_init(&rxq->lock);
369 /* Configure mtu if it is different from what was configured before */
371 bnxt_mtu_set_op(eth_dev, eth_dev->data->mtu);
378 bnxt_rx_queue_intr_enable_op(struct rte_eth_dev *eth_dev, uint16_t queue_id)
380 struct bnxt *bp = eth_dev->data->dev_private;
381 struct bnxt_rx_queue *rxq;
382 struct bnxt_cp_ring_info *cpr;
385 rc = is_bnxt_in_error(bp);
389 if (eth_dev->data->rx_queues) {
390 rxq = eth_dev->data->rx_queues[queue_id];
395 B_CP_DB_REARM(cpr, cpr->cp_raw_cons);
401 bnxt_rx_queue_intr_disable_op(struct rte_eth_dev *eth_dev, uint16_t queue_id)
403 struct bnxt *bp = eth_dev->data->dev_private;
404 struct bnxt_rx_queue *rxq;
405 struct bnxt_cp_ring_info *cpr;
408 rc = is_bnxt_in_error(bp);
412 if (eth_dev->data->rx_queues) {
413 rxq = eth_dev->data->rx_queues[queue_id];
423 int bnxt_rx_queue_start(struct rte_eth_dev *dev, uint16_t rx_queue_id)
425 struct bnxt *bp = dev->data->dev_private;
426 struct rte_eth_conf *dev_conf = &bp->eth_dev->data->dev_conf;
427 struct bnxt_rx_queue *rxq = bp->rx_queues[rx_queue_id];
428 struct bnxt_vnic_info *vnic = NULL;
431 rc = is_bnxt_in_error(bp);
436 PMD_DRV_LOG(ERR, "Invalid Rx queue %d\n", rx_queue_id);
440 /* Set the queue state to started here.
441 * We check the status of the queue while posting buffer.
442 * If queue is it started, we do not post buffers for Rx.
444 rxq->rx_started = true;
445 bnxt_free_hwrm_rx_ring(bp, rx_queue_id);
446 rc = bnxt_alloc_hwrm_rx_ring(bp, rx_queue_id);
450 PMD_DRV_LOG(INFO, "Rx queue started %d\n", rx_queue_id);
452 if (dev_conf->rxmode.mq_mode & ETH_MQ_RX_RSS_FLAG) {
455 if (BNXT_HAS_RING_GRPS(bp)) {
456 if (vnic->fw_grp_ids[rx_queue_id] != INVALID_HW_RING_ID)
459 vnic->fw_grp_ids[rx_queue_id] =
460 bp->grp_info[rx_queue_id].fw_grp_id;
462 "vnic = %p fw_grp_id = %d\n",
463 vnic, bp->grp_info[rx_queue_id].fw_grp_id);
466 PMD_DRV_LOG(DEBUG, "Rx Queue Count %d\n", vnic->rx_queue_cnt);
467 if (vnic->rx_queue_cnt > 1)
468 rc = bnxt_vnic_rss_configure(bp, vnic);
472 dev->data->rx_queue_state[rx_queue_id] =
473 RTE_ETH_QUEUE_STATE_STARTED;
475 rxq->rx_started = false;
478 "queue %d, rx_deferred_start %d, state %d!\n",
479 rx_queue_id, rxq->rx_deferred_start,
480 bp->eth_dev->data->rx_queue_state[rx_queue_id]);
485 int bnxt_rx_queue_stop(struct rte_eth_dev *dev, uint16_t rx_queue_id)
487 struct bnxt *bp = dev->data->dev_private;
488 struct rte_eth_conf *dev_conf = &bp->eth_dev->data->dev_conf;
489 struct bnxt_vnic_info *vnic = NULL;
490 struct bnxt_rx_queue *rxq = NULL;
493 rc = is_bnxt_in_error(bp);
497 /* For the stingray platform and other platforms needing tighter
498 * control of resource utilization, Rx CQ 0 also works as
499 * Default CQ for async notifications
501 if (!BNXT_NUM_ASYNC_CPR(bp) && !rx_queue_id) {
502 PMD_DRV_LOG(ERR, "Cannot stop Rx queue id %d\n", rx_queue_id);
506 rxq = bp->rx_queues[rx_queue_id];
509 PMD_DRV_LOG(ERR, "Invalid Rx queue %d\n", rx_queue_id);
513 dev->data->rx_queue_state[rx_queue_id] = RTE_ETH_QUEUE_STATE_STOPPED;
514 rxq->rx_started = false;
515 PMD_DRV_LOG(DEBUG, "Rx queue stopped\n");
517 if (dev_conf->rxmode.mq_mode & ETH_MQ_RX_RSS_FLAG) {
519 if (BNXT_HAS_RING_GRPS(bp))
520 vnic->fw_grp_ids[rx_queue_id] = INVALID_HW_RING_ID;
522 PMD_DRV_LOG(DEBUG, "Rx Queue Count %d\n", vnic->rx_queue_cnt);
523 if (vnic->rx_queue_cnt > 1)
524 rc = bnxt_vnic_rss_configure(bp, vnic);
528 bnxt_rx_queue_release_mbufs(rxq);