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 = bnxt_alloc_vnic(bp);
48 PMD_DRV_LOG(ERR, "VNIC alloc failed\n");
52 vnic->flags |= BNXT_VNIC_INFO_BCAST;
53 STAILQ_INSERT_TAIL(&bp->ff_pool[0], vnic, next);
56 rxq = bp->eth_dev->data->rx_queues[0];
59 vnic->func_default = true;
60 vnic->ff_pool_idx = 0;
61 vnic->start_grp_id = 0;
62 vnic->end_grp_id = vnic->start_grp_id;
63 filter = bnxt_alloc_filter(bp);
65 PMD_DRV_LOG(ERR, "L2 filter alloc failed\n");
69 STAILQ_INSERT_TAIL(&vnic->filter, filter, next);
73 /* Multi-queue mode */
74 if (dev_conf->rxmode.mq_mode & ETH_MQ_RX_VMDQ_DCB_RSS) {
75 /* VMDq ONLY, VMDq+RSS, VMDq+DCB, VMDq+DCB+RSS */
77 switch (dev_conf->rxmode.mq_mode) {
78 case ETH_MQ_RX_VMDQ_RSS:
79 case ETH_MQ_RX_VMDQ_ONLY:
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,
88 if (pools > max_pools)
95 PMD_DRV_LOG(ERR, "Unsupported mq_mod %d\n",
96 dev_conf->rxmode.mq_mode);
102 nb_q_per_grp = bp->rx_cp_nr_rings / pools;
104 end_grp_id = nb_q_per_grp;
106 for (i = 0; i < pools; i++) {
107 vnic = bnxt_alloc_vnic(bp);
109 PMD_DRV_LOG(ERR, "VNIC alloc failed\n");
113 vnic->flags |= BNXT_VNIC_INFO_BCAST;
114 STAILQ_INSERT_TAIL(&bp->ff_pool[i], vnic, next);
117 for (j = 0; j < nb_q_per_grp; j++, ring_idx++) {
118 rxq = bp->eth_dev->data->rx_queues[ring_idx];
122 if (dev_conf->rxmode.mq_mode & ETH_MQ_RX_VMDQ_DCB) {
123 bp->eth_dev->data->promiscuous = 1;
124 vnic->flags |= BNXT_VNIC_INFO_PROMISC;
126 vnic->func_default = true;
128 vnic->ff_pool_idx = i;
129 vnic->start_grp_id = start_grp_id;
130 vnic->end_grp_id = end_grp_id;
133 if (dev_conf->rxmode.mq_mode & ETH_MQ_RX_VMDQ_DCB ||
134 !(dev_conf->rxmode.mq_mode & ETH_MQ_RX_RSS))
135 vnic->rss_dflt_cr = true;
136 goto skip_filter_allocation;
138 filter = bnxt_alloc_filter(bp);
140 PMD_DRV_LOG(ERR, "L2 filter alloc failed\n");
145 * TODO: Configure & associate CFA rule for
146 * each VNIC for each VMDq with MACVLAN, MACVLAN+TC
148 STAILQ_INSERT_TAIL(&vnic->filter, filter, next);
150 skip_filter_allocation:
151 start_grp_id = end_grp_id;
152 end_grp_id += nb_q_per_grp;
156 if (dev_conf->rxmode.mq_mode & ETH_MQ_RX_RSS_FLAG) {
157 struct rte_eth_rss_conf *rss = &dev_conf->rx_adv_conf.rss_conf;
158 uint16_t hash_type = 0;
160 if (bp->flags & BNXT_FLAG_UPDATE_HASH) {
162 bp->flags &= ~BNXT_FLAG_UPDATE_HASH;
165 if (rss->rss_hf & ETH_RSS_IPV4)
166 hash_type |= HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_IPV4;
167 if (rss->rss_hf & ETH_RSS_NONFRAG_IPV4_TCP)
168 hash_type |= HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_TCP_IPV4;
169 if (rss->rss_hf & ETH_RSS_NONFRAG_IPV4_UDP)
170 hash_type |= HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_UDP_IPV4;
171 if (rss->rss_hf & ETH_RSS_IPV6)
172 hash_type |= HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_IPV6;
173 if (rss->rss_hf & ETH_RSS_NONFRAG_IPV6_TCP)
174 hash_type |= HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_TCP_IPV6;
175 if (rss->rss_hf & ETH_RSS_NONFRAG_IPV6_UDP)
176 hash_type |= HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_UDP_IPV6;
178 for (i = 0; i < bp->nr_vnics; i++) {
179 STAILQ_FOREACH(vnic, &bp->ff_pool[i], next) {
180 vnic->hash_type = hash_type;
183 * Use the supplied key if the key length is
184 * acceptable and the rss_key is not NULL
187 rss->rss_key_len <= HW_HASH_KEY_SIZE)
188 memcpy(vnic->rss_hash_key,
189 rss->rss_key, rss->rss_key_len);
197 /* Free allocated vnic/filters */
202 void bnxt_rx_queue_release_mbufs(struct bnxt_rx_queue *rxq)
204 struct bnxt_sw_rx_bd *sw_ring;
205 struct bnxt_tpa_info *tpa_info;
208 rte_spinlock_lock(&rxq->lock);
211 sw_ring = rxq->rx_ring->rx_buf_ring;
214 i < rxq->rx_ring->rx_ring_struct->ring_size; i++) {
215 if (sw_ring[i].mbuf) {
216 rte_pktmbuf_free_seg(sw_ring[i].mbuf);
217 sw_ring[i].mbuf = NULL;
221 /* Free up mbufs in Agg ring */
222 sw_ring = rxq->rx_ring->ag_buf_ring;
225 i < rxq->rx_ring->ag_ring_struct->ring_size; i++) {
226 if (sw_ring[i].mbuf) {
227 rte_pktmbuf_free_seg(sw_ring[i].mbuf);
228 sw_ring[i].mbuf = NULL;
233 /* Free up mbufs in TPA */
234 tpa_info = rxq->rx_ring->tpa_info;
236 for (i = 0; i < BNXT_TPA_MAX; i++) {
237 if (tpa_info[i].mbuf) {
238 rte_pktmbuf_free_seg(tpa_info[i].mbuf);
239 tpa_info[i].mbuf = NULL;
245 rte_spinlock_unlock(&rxq->lock);
248 void bnxt_free_rx_mbufs(struct bnxt *bp)
250 struct bnxt_rx_queue *rxq;
253 for (i = 0; i < (int)bp->rx_nr_rings; i++) {
254 rxq = bp->rx_queues[i];
255 bnxt_rx_queue_release_mbufs(rxq);
259 void bnxt_rx_queue_release_op(void *rx_queue)
261 struct bnxt_rx_queue *rxq = (struct bnxt_rx_queue *)rx_queue;
264 bnxt_rx_queue_release_mbufs(rxq);
266 /* Free RX ring hardware descriptors */
267 bnxt_free_ring(rxq->rx_ring->rx_ring_struct);
268 /* Free RX Agg ring hardware descriptors */
269 bnxt_free_ring(rxq->rx_ring->ag_ring_struct);
271 /* Free RX completion ring hardware descriptors */
272 bnxt_free_ring(rxq->cp_ring->cp_ring_struct);
274 bnxt_free_rxq_stats(rxq);
275 rte_memzone_free(rxq->mz);
282 int bnxt_rx_queue_setup_op(struct rte_eth_dev *eth_dev,
285 unsigned int socket_id,
286 const struct rte_eth_rxconf *rx_conf,
287 struct rte_mempool *mp)
289 struct bnxt *bp = (struct bnxt *)eth_dev->data->dev_private;
290 uint64_t rx_offloads = eth_dev->data->dev_conf.rxmode.offloads;
291 struct bnxt_rx_queue *rxq;
295 if (queue_idx >= bp->max_rx_rings) {
297 "Cannot create Rx ring %d. Only %d rings available\n",
298 queue_idx, bp->max_rx_rings);
302 if (!nb_desc || nb_desc > MAX_RX_DESC_CNT) {
303 PMD_DRV_LOG(ERR, "nb_desc %d is invalid\n", nb_desc);
308 if (eth_dev->data->rx_queues) {
309 rxq = eth_dev->data->rx_queues[queue_idx];
311 bnxt_rx_queue_release_op(rxq);
313 rxq = rte_zmalloc_socket("bnxt_rx_queue", sizeof(struct bnxt_rx_queue),
314 RTE_CACHE_LINE_SIZE, socket_id);
316 PMD_DRV_LOG(ERR, "bnxt_rx_queue allocation failed!\n");
322 rxq->nb_rx_desc = nb_desc;
323 rxq->rx_free_thresh = rx_conf->rx_free_thresh;
325 PMD_DRV_LOG(DEBUG, "RX Buf size is %d\n", rxq->rx_buf_use_size);
326 PMD_DRV_LOG(DEBUG, "RX Buf MTU %d\n", eth_dev->data->mtu);
328 rc = bnxt_init_rx_ring_struct(rxq, socket_id);
332 rxq->queue_id = queue_idx;
333 rxq->port_id = eth_dev->data->port_id;
334 rxq->crc_len = rte_eth_dev_must_keep_crc(rx_offloads) ?
337 eth_dev->data->rx_queues[queue_idx] = rxq;
338 /* Allocate RX ring hardware descriptors */
339 if (bnxt_alloc_rings(bp, queue_idx, NULL, rxq, rxq->cp_ring,
342 "ring_dma_zone_reserve for rx_ring failed!\n");
343 bnxt_rx_queue_release_op(rxq);
347 rte_atomic64_init(&rxq->rx_mbuf_alloc_fail);
349 rxq->rx_deferred_start = rx_conf->rx_deferred_start;
350 queue_state = rxq->rx_deferred_start ? RTE_ETH_QUEUE_STATE_STOPPED :
351 RTE_ETH_QUEUE_STATE_STARTED;
352 eth_dev->data->rx_queue_state[queue_idx] = queue_state;
353 rte_spinlock_init(&rxq->lock);
359 bnxt_rx_queue_intr_enable_op(struct rte_eth_dev *eth_dev, uint16_t queue_id)
361 struct bnxt_rx_queue *rxq;
362 struct bnxt_cp_ring_info *cpr;
365 if (eth_dev->data->rx_queues) {
366 rxq = eth_dev->data->rx_queues[queue_id];
378 bnxt_rx_queue_intr_disable_op(struct rte_eth_dev *eth_dev, uint16_t queue_id)
380 struct bnxt_rx_queue *rxq;
381 struct bnxt_cp_ring_info *cpr;
384 if (eth_dev->data->rx_queues) {
385 rxq = eth_dev->data->rx_queues[queue_id];
396 int bnxt_rx_queue_start(struct rte_eth_dev *dev, uint16_t rx_queue_id)
398 struct bnxt *bp = (struct bnxt *)dev->data->dev_private;
399 struct rte_eth_conf *dev_conf = &bp->eth_dev->data->dev_conf;
400 struct bnxt_rx_queue *rxq = bp->rx_queues[rx_queue_id];
401 struct bnxt_vnic_info *vnic = NULL;
405 PMD_DRV_LOG(ERR, "Invalid Rx queue %d\n", rx_queue_id);
409 dev->data->rx_queue_state[rx_queue_id] = RTE_ETH_QUEUE_STATE_STARTED;
411 bnxt_free_hwrm_rx_ring(bp, rx_queue_id);
412 bnxt_alloc_hwrm_rx_ring(bp, rx_queue_id);
413 PMD_DRV_LOG(INFO, "Rx queue started %d\n", rx_queue_id);
415 if (dev_conf->rxmode.mq_mode & ETH_MQ_RX_RSS_FLAG) {
418 if (vnic->fw_grp_ids[rx_queue_id] != INVALID_HW_RING_ID)
422 "vnic = %p fw_grp_id = %d\n",
423 vnic, bp->grp_info[rx_queue_id].fw_grp_id);
425 vnic->fw_grp_ids[rx_queue_id] =
426 bp->grp_info[rx_queue_id].fw_grp_id;
427 rc = bnxt_vnic_rss_configure(bp, vnic);
431 rxq->rx_deferred_start = false;
436 int bnxt_rx_queue_stop(struct rte_eth_dev *dev, uint16_t rx_queue_id)
438 struct bnxt *bp = (struct bnxt *)dev->data->dev_private;
439 struct rte_eth_conf *dev_conf = &bp->eth_dev->data->dev_conf;
440 struct bnxt_vnic_info *vnic = NULL;
441 struct bnxt_rx_queue *rxq = NULL;
444 /* Rx CQ 0 also works as Default CQ for async notifications */
446 PMD_DRV_LOG(ERR, "Cannot stop Rx queue id %d\n", rx_queue_id);
450 rxq = bp->rx_queues[rx_queue_id];
453 PMD_DRV_LOG(ERR, "Invalid Rx queue %d\n", rx_queue_id);
457 dev->data->rx_queue_state[rx_queue_id] = RTE_ETH_QUEUE_STATE_STOPPED;
458 rxq->rx_deferred_start = true;
459 PMD_DRV_LOG(DEBUG, "Rx queue stopped\n");
461 if (dev_conf->rxmode.mq_mode & ETH_MQ_RX_RSS_FLAG) {
463 vnic->fw_grp_ids[rx_queue_id] = INVALID_HW_RING_ID;
464 rc = bnxt_vnic_rss_configure(bp, vnic);
468 bnxt_rx_queue_release_mbufs(rxq);