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:
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,
87 if (pools > max_pools)
94 PMD_DRV_LOG(ERR, "Unsupported mq_mod %d\n",
95 dev_conf->rxmode.mq_mode);
101 nb_q_per_grp = bp->rx_cp_nr_rings / pools;
103 end_grp_id = nb_q_per_grp;
105 for (i = 0; i < pools; i++) {
106 vnic = bnxt_alloc_vnic(bp);
108 PMD_DRV_LOG(ERR, "VNIC alloc failed\n");
112 vnic->flags |= BNXT_VNIC_INFO_BCAST;
113 STAILQ_INSERT_TAIL(&bp->ff_pool[i], vnic, next);
116 for (j = 0; j < nb_q_per_grp; j++, ring_idx++) {
117 rxq = bp->eth_dev->data->rx_queues[ring_idx];
121 if (dev_conf->rxmode.mq_mode & ETH_MQ_RX_VMDQ_DCB) {
122 bp->eth_dev->data->promiscuous = 1;
123 vnic->flags |= BNXT_VNIC_INFO_PROMISC;
125 vnic->func_default = true;
127 vnic->ff_pool_idx = i;
128 vnic->start_grp_id = start_grp_id;
129 vnic->end_grp_id = end_grp_id;
132 if (dev_conf->rxmode.mq_mode & ETH_MQ_RX_VMDQ_DCB ||
133 !(dev_conf->rxmode.mq_mode & ETH_MQ_RX_RSS))
134 vnic->rss_dflt_cr = true;
135 goto skip_filter_allocation;
137 filter = bnxt_alloc_filter(bp);
139 PMD_DRV_LOG(ERR, "L2 filter alloc failed\n");
144 * TODO: Configure & associate CFA rule for
145 * each VNIC for each VMDq with MACVLAN, MACVLAN+TC
147 STAILQ_INSERT_TAIL(&vnic->filter, filter, next);
149 skip_filter_allocation:
150 start_grp_id = end_grp_id;
151 end_grp_id += nb_q_per_grp;
155 if (dev_conf->rxmode.mq_mode & ETH_MQ_RX_RSS_FLAG) {
156 struct rte_eth_rss_conf *rss = &dev_conf->rx_adv_conf.rss_conf;
157 uint16_t hash_type = 0;
159 if (bp->flags & BNXT_FLAG_UPDATE_HASH) {
161 bp->flags &= ~BNXT_FLAG_UPDATE_HASH;
164 if (rss->rss_hf & ETH_RSS_IPV4)
165 hash_type |= HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_IPV4;
166 if (rss->rss_hf & ETH_RSS_NONFRAG_IPV4_TCP)
167 hash_type |= HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_TCP_IPV4;
168 if (rss->rss_hf & ETH_RSS_NONFRAG_IPV4_UDP)
169 hash_type |= HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_UDP_IPV4;
170 if (rss->rss_hf & ETH_RSS_IPV6)
171 hash_type |= HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_IPV6;
172 if (rss->rss_hf & ETH_RSS_NONFRAG_IPV6_TCP)
173 hash_type |= HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_TCP_IPV6;
174 if (rss->rss_hf & ETH_RSS_NONFRAG_IPV6_UDP)
175 hash_type |= HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_UDP_IPV6;
177 for (i = 0; i < bp->nr_vnics; i++) {
178 STAILQ_FOREACH(vnic, &bp->ff_pool[i], next) {
179 vnic->hash_type = hash_type;
182 * Use the supplied key if the key length is
183 * acceptable and the rss_key is not NULL
186 rss->rss_key_len <= HW_HASH_KEY_SIZE)
187 memcpy(vnic->rss_hash_key,
188 rss->rss_key, rss->rss_key_len);
196 /* Free allocated vnic/filters */
201 static void bnxt_rx_queue_release_mbufs(struct bnxt_rx_queue *rxq)
203 struct bnxt_sw_rx_bd *sw_ring;
204 struct bnxt_tpa_info *tpa_info;
208 sw_ring = rxq->rx_ring->rx_buf_ring;
211 i < rxq->rx_ring->rx_ring_struct->ring_size; i++) {
212 if (sw_ring[i].mbuf) {
213 rte_pktmbuf_free_seg(sw_ring[i].mbuf);
214 sw_ring[i].mbuf = NULL;
218 /* Free up mbufs in Agg ring */
219 sw_ring = rxq->rx_ring->ag_buf_ring;
222 i < rxq->rx_ring->ag_ring_struct->ring_size; 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);
270 rte_memzone_free(rxq->mz);
277 int bnxt_rx_queue_setup_op(struct rte_eth_dev *eth_dev,
280 unsigned int socket_id,
281 const struct rte_eth_rxconf *rx_conf,
282 struct rte_mempool *mp)
284 struct bnxt *bp = (struct bnxt *)eth_dev->data->dev_private;
285 uint64_t rx_offloads = eth_dev->data->dev_conf.rxmode.offloads;
286 struct bnxt_rx_queue *rxq;
289 if (queue_idx >= bp->max_rx_rings) {
291 "Cannot create Rx ring %d. Only %d rings available\n",
292 queue_idx, bp->max_rx_rings);
296 if (!nb_desc || nb_desc > MAX_RX_DESC_CNT) {
297 PMD_DRV_LOG(ERR, "nb_desc %d is invalid\n", nb_desc);
302 if (eth_dev->data->rx_queues) {
303 rxq = eth_dev->data->rx_queues[queue_idx];
305 bnxt_rx_queue_release_op(rxq);
307 rxq = rte_zmalloc_socket("bnxt_rx_queue", sizeof(struct bnxt_rx_queue),
308 RTE_CACHE_LINE_SIZE, socket_id);
310 PMD_DRV_LOG(ERR, "bnxt_rx_queue allocation failed!\n");
316 rxq->nb_rx_desc = nb_desc;
317 rxq->rx_free_thresh = rx_conf->rx_free_thresh;
319 PMD_DRV_LOG(DEBUG, "RX Buf size is %d\n", rxq->rx_buf_use_size);
320 PMD_DRV_LOG(DEBUG, "RX Buf MTU %d\n", eth_dev->data->mtu);
322 rc = bnxt_init_rx_ring_struct(rxq, socket_id);
326 rxq->queue_id = queue_idx;
327 rxq->port_id = eth_dev->data->port_id;
328 rxq->crc_len = rx_offloads & DEV_RX_OFFLOAD_CRC_STRIP ?
331 eth_dev->data->rx_queues[queue_idx] = rxq;
332 /* Allocate RX ring hardware descriptors */
333 if (bnxt_alloc_rings(bp, queue_idx, NULL, rxq, rxq->cp_ring,
336 "ring_dma_zone_reserve for rx_ring failed!\n");
337 bnxt_rx_queue_release_op(rxq);
341 rte_atomic64_init(&rxq->rx_mbuf_alloc_fail);
348 bnxt_rx_queue_intr_enable_op(struct rte_eth_dev *eth_dev, uint16_t queue_id)
350 struct bnxt_rx_queue *rxq;
351 struct bnxt_cp_ring_info *cpr;
354 if (eth_dev->data->rx_queues) {
355 rxq = eth_dev->data->rx_queues[queue_id];
367 bnxt_rx_queue_intr_disable_op(struct rte_eth_dev *eth_dev, uint16_t queue_id)
369 struct bnxt_rx_queue *rxq;
370 struct bnxt_cp_ring_info *cpr;
373 if (eth_dev->data->rx_queues) {
374 rxq = eth_dev->data->rx_queues[queue_id];
385 int bnxt_rx_queue_start(struct rte_eth_dev *dev, uint16_t rx_queue_id)
387 struct bnxt *bp = (struct bnxt *)dev->data->dev_private;
388 struct rte_eth_conf *dev_conf = &bp->eth_dev->data->dev_conf;
389 struct bnxt_rx_queue *rxq = bp->rx_queues[rx_queue_id];
390 struct bnxt_vnic_info *vnic = NULL;
393 PMD_DRV_LOG(ERR, "Invalid Rx queue %d\n", rx_queue_id);
397 dev->data->rx_queue_state[rx_queue_id] = RTE_ETH_QUEUE_STATE_STARTED;
398 rxq->rx_deferred_start = false;
399 PMD_DRV_LOG(INFO, "Rx queue started %d\n", rx_queue_id);
400 if (dev_conf->rxmode.mq_mode & ETH_MQ_RX_RSS_FLAG) {
402 if (vnic->fw_grp_ids[rx_queue_id] != INVALID_HW_RING_ID)
404 PMD_DRV_LOG(DEBUG, "vnic = %p fw_grp_id = %d\n",
405 vnic, bp->grp_info[rx_queue_id + 1].fw_grp_id);
406 vnic->fw_grp_ids[rx_queue_id] =
407 bp->grp_info[rx_queue_id + 1].fw_grp_id;
408 return bnxt_vnic_rss_configure(bp, vnic);
414 int bnxt_rx_queue_stop(struct rte_eth_dev *dev, uint16_t rx_queue_id)
416 struct bnxt *bp = (struct bnxt *)dev->data->dev_private;
417 struct rte_eth_conf *dev_conf = &bp->eth_dev->data->dev_conf;
418 struct bnxt_rx_queue *rxq = bp->rx_queues[rx_queue_id];
419 struct bnxt_vnic_info *vnic = NULL;
422 PMD_DRV_LOG(ERR, "Invalid Rx queue %d\n", rx_queue_id);
426 dev->data->rx_queue_state[rx_queue_id] = RTE_ETH_QUEUE_STATE_STOPPED;
427 rxq->rx_deferred_start = true;
428 PMD_DRV_LOG(DEBUG, "Rx queue stopped\n");
430 if (dev_conf->rxmode.mq_mode & ETH_MQ_RX_RSS_FLAG) {
432 vnic->fw_grp_ids[rx_queue_id] = INVALID_HW_RING_ID;
433 return bnxt_vnic_rss_configure(bp, vnic);