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 filter->flags |= HWRM_CFA_L2_FILTER_ALLOC_INPUT_FLAGS_OUTERMOST;
68 STAILQ_INSERT_TAIL(&vnic->filter, filter, next);
72 /* Multi-queue mode */
73 if (dev_conf->rxmode.mq_mode & ETH_MQ_RX_VMDQ_DCB_RSS) {
74 /* VMDq ONLY, VMDq+RSS, VMDq+DCB, VMDq+DCB+RSS */
76 switch (dev_conf->rxmode.mq_mode) {
77 case ETH_MQ_RX_VMDQ_RSS:
78 case ETH_MQ_RX_VMDQ_ONLY:
79 case ETH_MQ_RX_VMDQ_DCB_RSS:
82 pools = conf->nb_queue_pools;
83 /* For each pool, allocate MACVLAN CFA rule & VNIC */
84 max_pools = RTE_MIN(bp->max_vnics,
85 RTE_MIN(bp->max_l2_ctx,
86 RTE_MIN(bp->max_rsscos_ctx,
89 "pools = %u max_pools = %u\n",
91 if (pools > max_pools)
95 pools = bp->rx_cosq_cnt ? bp->rx_cosq_cnt : 1;
98 PMD_DRV_LOG(ERR, "Unsupported mq_mod %d\n",
99 dev_conf->rxmode.mq_mode);
104 nb_q_per_grp = bp->rx_cp_nr_rings / pools;
105 bp->rx_num_qs_per_vnic = nb_q_per_grp;
106 PMD_DRV_LOG(DEBUG, "pools = %u nb_q_per_grp = %u\n",
107 pools, nb_q_per_grp);
109 end_grp_id = nb_q_per_grp;
111 for (i = 0; i < pools; i++) {
112 vnic = &bp->vnic_info[i];
114 PMD_DRV_LOG(ERR, "VNIC alloc failed\n");
118 vnic->flags |= BNXT_VNIC_INFO_BCAST;
121 for (j = 0; j < nb_q_per_grp; j++, ring_idx++) {
122 rxq = bp->eth_dev->data->rx_queues[ring_idx];
125 "rxq[%d] = %p vnic[%d] = %p\n",
126 ring_idx, rxq, i, vnic);
129 if (dev_conf->rxmode.mq_mode & ETH_MQ_RX_VMDQ_DCB) {
130 bp->eth_dev->data->promiscuous = 1;
131 vnic->flags |= BNXT_VNIC_INFO_PROMISC;
133 vnic->func_default = true;
135 vnic->start_grp_id = start_grp_id;
136 vnic->end_grp_id = end_grp_id;
139 if (dev_conf->rxmode.mq_mode & ETH_MQ_RX_VMDQ_DCB ||
140 !(dev_conf->rxmode.mq_mode & ETH_MQ_RX_RSS))
141 vnic->rss_dflt_cr = true;
142 goto skip_filter_allocation;
144 filter = bnxt_alloc_filter(bp);
146 PMD_DRV_LOG(ERR, "L2 filter alloc failed\n");
150 filter->flags |= HWRM_CFA_L2_FILTER_ALLOC_INPUT_FLAGS_OUTERMOST;
152 * TODO: Configure & associate CFA rule for
153 * each VNIC for each VMDq with MACVLAN, MACVLAN+TC
155 STAILQ_INSERT_TAIL(&vnic->filter, filter, next);
157 skip_filter_allocation:
158 start_grp_id = end_grp_id;
159 end_grp_id += nb_q_per_grp;
163 if (dev_conf->rxmode.mq_mode & ETH_MQ_RX_RSS_FLAG) {
164 struct rte_eth_rss_conf *rss = &dev_conf->rx_adv_conf.rss_conf;
166 if (bp->flags & BNXT_FLAG_UPDATE_HASH) {
168 bp->flags &= ~BNXT_FLAG_UPDATE_HASH;
171 for (i = 0; i < bp->nr_vnics; i++) {
172 vnic = &bp->vnic_info[i];
174 bnxt_rte_to_hwrm_hash_types(rss->rss_hf);
177 * Use the supplied key if the key length is
178 * acceptable and the rss_key is not NULL
181 rss->rss_key_len <= HW_HASH_KEY_SIZE)
182 memcpy(vnic->rss_hash_key,
183 rss->rss_key, rss->rss_key_len);
190 /* Free allocated vnic/filters */
195 void bnxt_rx_queue_release_mbufs(struct bnxt_rx_queue *rxq)
197 struct bnxt_sw_rx_bd *sw_ring;
198 struct bnxt_tpa_info *tpa_info;
204 rte_spinlock_lock(&rxq->lock);
206 sw_ring = rxq->rx_ring->rx_buf_ring;
209 i < rxq->rx_ring->rx_ring_struct->ring_size; i++) {
210 if (sw_ring[i].mbuf) {
211 rte_pktmbuf_free_seg(sw_ring[i].mbuf);
212 sw_ring[i].mbuf = NULL;
216 /* Free up mbufs in Agg ring */
217 sw_ring = rxq->rx_ring->ag_buf_ring;
220 i < rxq->rx_ring->ag_ring_struct->ring_size; i++) {
221 if (sw_ring[i].mbuf) {
222 rte_pktmbuf_free_seg(sw_ring[i].mbuf);
223 sw_ring[i].mbuf = NULL;
228 /* Free up mbufs in TPA */
229 tpa_info = rxq->rx_ring->tpa_info;
231 int max_aggs = BNXT_TPA_MAX_AGGS(rxq->bp);
233 for (i = 0; i < max_aggs; i++) {
234 if (tpa_info[i].mbuf) {
235 rte_pktmbuf_free_seg(tpa_info[i].mbuf);
236 tpa_info[i].mbuf = NULL;
241 rte_spinlock_unlock(&rxq->lock);
244 void bnxt_free_rx_mbufs(struct bnxt *bp)
246 struct bnxt_rx_queue *rxq;
249 for (i = 0; i < (int)bp->rx_nr_rings; i++) {
250 rxq = bp->rx_queues[i];
251 bnxt_rx_queue_release_mbufs(rxq);
255 void bnxt_rx_queue_release_op(void *rx_queue)
257 struct bnxt_rx_queue *rxq = (struct bnxt_rx_queue *)rx_queue;
260 if (is_bnxt_in_error(rxq->bp))
263 bnxt_rx_queue_release_mbufs(rxq);
265 /* Free RX ring hardware descriptors */
266 bnxt_free_ring(rxq->rx_ring->rx_ring_struct);
267 /* Free RX Agg ring hardware descriptors */
268 bnxt_free_ring(rxq->rx_ring->ag_ring_struct);
270 /* Free RX completion ring hardware descriptors */
271 bnxt_free_ring(rxq->cp_ring->cp_ring_struct);
273 bnxt_free_rxq_stats(rxq);
274 rte_memzone_free(rxq->mz);
281 int bnxt_rx_queue_setup_op(struct rte_eth_dev *eth_dev,
284 unsigned int socket_id,
285 const struct rte_eth_rxconf *rx_conf,
286 struct rte_mempool *mp)
288 struct bnxt *bp = eth_dev->data->dev_private;
289 uint64_t rx_offloads = eth_dev->data->dev_conf.rxmode.offloads;
290 struct bnxt_rx_queue *rxq;
294 rc = is_bnxt_in_error(bp);
298 if (queue_idx >= bp->max_rx_rings) {
300 "Cannot create Rx ring %d. Only %d rings available\n",
301 queue_idx, bp->max_rx_rings);
305 if (!nb_desc || nb_desc > MAX_RX_DESC_CNT) {
306 PMD_DRV_LOG(ERR, "nb_desc %d is invalid\n", nb_desc);
311 if (eth_dev->data->rx_queues) {
312 rxq = eth_dev->data->rx_queues[queue_idx];
314 bnxt_rx_queue_release_op(rxq);
316 rxq = rte_zmalloc_socket("bnxt_rx_queue", sizeof(struct bnxt_rx_queue),
317 RTE_CACHE_LINE_SIZE, socket_id);
319 PMD_DRV_LOG(ERR, "bnxt_rx_queue allocation failed!\n");
325 rxq->nb_rx_desc = nb_desc;
326 rxq->rx_free_thresh = rx_conf->rx_free_thresh;
328 PMD_DRV_LOG(DEBUG, "RX Buf MTU %d\n", eth_dev->data->mtu);
330 rc = bnxt_init_rx_ring_struct(rxq, socket_id);
334 PMD_DRV_LOG(DEBUG, "RX Buf size is %d\n", rxq->rx_buf_size);
335 rxq->queue_id = queue_idx;
336 rxq->port_id = eth_dev->data->port_id;
337 if (rx_offloads & DEV_RX_OFFLOAD_KEEP_CRC)
338 rxq->crc_len = RTE_ETHER_CRC_LEN;
342 eth_dev->data->rx_queues[queue_idx] = rxq;
343 /* Allocate RX ring hardware descriptors */
344 if (bnxt_alloc_rings(bp, queue_idx, NULL, rxq, rxq->cp_ring, NULL,
347 "ring_dma_zone_reserve for rx_ring failed!\n");
348 bnxt_rx_queue_release_op(rxq);
352 rte_atomic64_init(&rxq->rx_mbuf_alloc_fail);
354 /* rxq 0 must not be stopped when used as async CPR */
355 if (!BNXT_NUM_ASYNC_CPR(bp) && queue_idx == 0)
356 rxq->rx_deferred_start = false;
358 rxq->rx_deferred_start = rx_conf->rx_deferred_start;
360 if (rxq->rx_deferred_start) {
361 queue_state = RTE_ETH_QUEUE_STATE_STOPPED;
362 rxq->rx_started = false;
364 queue_state = RTE_ETH_QUEUE_STATE_STARTED;
365 rxq->rx_started = true;
367 eth_dev->data->rx_queue_state[queue_idx] = queue_state;
368 rte_spinlock_init(&rxq->lock);
375 bnxt_rx_queue_intr_enable_op(struct rte_eth_dev *eth_dev, uint16_t queue_id)
377 struct bnxt *bp = eth_dev->data->dev_private;
378 struct bnxt_rx_queue *rxq;
379 struct bnxt_cp_ring_info *cpr;
382 rc = is_bnxt_in_error(bp);
386 if (eth_dev->data->rx_queues) {
387 rxq = eth_dev->data->rx_queues[queue_id];
393 B_CP_DB_REARM(cpr, cpr->cp_raw_cons);
399 bnxt_rx_queue_intr_disable_op(struct rte_eth_dev *eth_dev, uint16_t queue_id)
401 struct bnxt *bp = eth_dev->data->dev_private;
402 struct bnxt_rx_queue *rxq;
403 struct bnxt_cp_ring_info *cpr;
406 rc = is_bnxt_in_error(bp);
410 if (eth_dev->data->rx_queues) {
411 rxq = eth_dev->data->rx_queues[queue_id];
422 int bnxt_rx_queue_start(struct rte_eth_dev *dev, uint16_t rx_queue_id)
424 struct bnxt *bp = dev->data->dev_private;
425 struct rte_eth_conf *dev_conf = &bp->eth_dev->data->dev_conf;
426 struct bnxt_rx_queue *rxq = bp->rx_queues[rx_queue_id];
427 struct bnxt_vnic_info *vnic = NULL;
430 rc = is_bnxt_in_error(bp);
435 PMD_DRV_LOG(ERR, "Invalid Rx queue %d\n", rx_queue_id);
439 /* Set the queue state to started here.
440 * We check the status of the queue while posting buffer.
441 * If queue is it started, we do not post buffers for Rx.
443 rxq->rx_started = true;
444 bnxt_free_hwrm_rx_ring(bp, rx_queue_id);
445 rc = bnxt_alloc_hwrm_rx_ring(bp, rx_queue_id);
449 PMD_DRV_LOG(INFO, "Rx queue started %d\n", rx_queue_id);
451 if (dev_conf->rxmode.mq_mode & ETH_MQ_RX_RSS_FLAG) {
454 if (BNXT_HAS_RING_GRPS(bp)) {
455 if (vnic->fw_grp_ids[rx_queue_id] != INVALID_HW_RING_ID)
458 vnic->fw_grp_ids[rx_queue_id] =
459 bp->grp_info[rx_queue_id].fw_grp_id;
461 "vnic = %p fw_grp_id = %d\n",
462 vnic, bp->grp_info[rx_queue_id].fw_grp_id);
465 PMD_DRV_LOG(DEBUG, "Rx Queue Count %d\n", vnic->rx_queue_cnt);
466 if (vnic->rx_queue_cnt > 1)
467 rc = bnxt_vnic_rss_configure(bp, vnic);
471 dev->data->rx_queue_state[rx_queue_id] =
472 RTE_ETH_QUEUE_STATE_STARTED;
474 rxq->rx_started = false;
477 "queue %d, rx_deferred_start %d, state %d!\n",
478 rx_queue_id, rxq->rx_deferred_start,
479 bp->eth_dev->data->rx_queue_state[rx_queue_id]);
484 int bnxt_rx_queue_stop(struct rte_eth_dev *dev, uint16_t rx_queue_id)
486 struct bnxt *bp = dev->data->dev_private;
487 struct rte_eth_conf *dev_conf = &bp->eth_dev->data->dev_conf;
488 struct bnxt_vnic_info *vnic = NULL;
489 struct bnxt_rx_queue *rxq = NULL;
492 rc = is_bnxt_in_error(bp);
496 /* For the stingray platform and other platforms needing tighter
497 * control of resource utilization, Rx CQ 0 also works as
498 * Default CQ for async notifications
500 if (!BNXT_NUM_ASYNC_CPR(bp) && !rx_queue_id) {
501 PMD_DRV_LOG(ERR, "Cannot stop Rx queue id %d\n", rx_queue_id);
505 rxq = bp->rx_queues[rx_queue_id];
508 PMD_DRV_LOG(ERR, "Invalid Rx queue %d\n", rx_queue_id);
512 dev->data->rx_queue_state[rx_queue_id] = RTE_ETH_QUEUE_STATE_STOPPED;
513 rxq->rx_started = false;
514 PMD_DRV_LOG(DEBUG, "Rx queue stopped\n");
516 if (dev_conf->rxmode.mq_mode & ETH_MQ_RX_RSS_FLAG) {
518 if (BNXT_HAS_RING_GRPS(bp))
519 vnic->fw_grp_ids[rx_queue_id] = INVALID_HW_RING_ID;
521 PMD_DRV_LOG(DEBUG, "Rx Queue Count %d\n", vnic->rx_queue_cnt);
522 if (vnic->rx_queue_cnt > 1)
523 rc = bnxt_vnic_rss_configure(bp, vnic);
527 bnxt_rx_queue_release_mbufs(rxq);