1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2014-2021 Broadcom
13 #include "bnxt_hwrm.h"
14 #include "hsi_struct_def_dpdk.h"
15 #include "bnxt_tf_common.h"
16 #include "ulp_port_db.h"
17 #include "ulp_flow_db.h"
19 static const struct eth_dev_ops bnxt_rep_dev_ops = {
20 .dev_infos_get = bnxt_rep_dev_info_get_op,
21 .dev_configure = bnxt_rep_dev_configure_op,
22 .dev_start = bnxt_rep_dev_start_op,
23 .rx_queue_setup = bnxt_rep_rx_queue_setup_op,
24 .rx_queue_release = bnxt_rep_rx_queue_release_op,
25 .tx_queue_setup = bnxt_rep_tx_queue_setup_op,
26 .tx_queue_release = bnxt_rep_tx_queue_release_op,
27 .link_update = bnxt_rep_link_update_op,
28 .dev_close = bnxt_rep_dev_close_op,
29 .dev_stop = bnxt_rep_dev_stop_op,
30 .stats_get = bnxt_rep_stats_get_op,
31 .stats_reset = bnxt_rep_stats_reset_op,
32 .flow_ops_get = bnxt_flow_ops_get_op
36 bnxt_vfr_recv(uint16_t port_id, uint16_t queue_id, struct rte_mbuf *mbuf)
38 struct bnxt_representor *vfr_bp = NULL;
39 struct bnxt_rx_ring_info *rep_rxr;
40 struct rte_eth_dev *vfr_eth_dev;
41 struct rte_mbuf **prod_rx_buf;
42 struct bnxt_rx_queue *rep_rxq;
46 vfr_eth_dev = &rte_eth_devices[port_id];
47 vfr_bp = vfr_eth_dev ? vfr_eth_dev->data->dev_private : NULL;
49 if (unlikely(vfr_bp == NULL))
52 /* If rxq_id happens to be > nr_rings, use ring 0 */
53 que = queue_id < vfr_bp->rx_nr_rings ? queue_id : 0;
54 rep_rxq = vfr_bp->rx_queues[que];
55 /* Ideally should not happen now, paranoid check */
58 rep_rxr = rep_rxq->rx_ring;
59 mask = rep_rxr->rx_ring_struct->ring_mask;
61 /* Put this mbuf on the RxQ of the Representor */
62 prod_rx_buf = &rep_rxr->rx_buf_ring[rep_rxr->rx_raw_prod & mask];
63 if (*prod_rx_buf == NULL) {
65 vfr_bp->rx_bytes[que] += mbuf->pkt_len;
66 vfr_bp->rx_pkts[que]++;
67 rep_rxr->rx_raw_prod++;
69 /* Representor Rx ring full, drop pkt */
70 vfr_bp->rx_drop_bytes[que] += mbuf->pkt_len;
71 vfr_bp->rx_drop_pkts[que]++;
72 rte_mbuf_raw_free(mbuf);
79 bnxt_rep_rx_burst(void *rx_queue,
80 struct rte_mbuf **rx_pkts,
83 struct bnxt_rx_queue *rxq = rx_queue;
84 struct rte_mbuf **cons_rx_buf;
85 struct bnxt_rx_ring_info *rxr;
86 uint16_t nb_rx_pkts = 0;
93 mask = rxr->rx_ring_struct->ring_mask;
94 for (i = 0; i < nb_pkts; i++) {
95 cons_rx_buf = &rxr->rx_buf_ring[rxr->rx_cons & mask];
96 if (*cons_rx_buf == NULL)
98 rx_pkts[nb_rx_pkts] = *cons_rx_buf;
99 rx_pkts[nb_rx_pkts]->port = rxq->port_id;
109 bnxt_rep_tx_burst(void *tx_queue,
110 struct rte_mbuf **tx_pkts,
113 struct bnxt_vf_rep_tx_queue *vfr_txq = tx_queue;
114 struct bnxt_tx_queue *ptxq;
116 struct bnxt_representor *vf_rep_bp;
124 qid = vfr_txq->txq->queue_id;
125 vf_rep_bp = vfr_txq->bp;
126 parent = vf_rep_bp->parent_dev->data->dev_private;
127 pthread_mutex_lock(&parent->rep_info->vfr_lock);
128 ptxq = parent->tx_queues[qid];
130 ptxq->vfr_tx_cfa_action = vf_rep_bp->vfr_tx_cfa_action;
132 for (i = 0; i < nb_pkts; i++) {
133 vf_rep_bp->tx_bytes[qid] += tx_pkts[i]->pkt_len;
134 vf_rep_bp->tx_pkts[qid]++;
137 rc = bnxt_xmit_pkts(ptxq, tx_pkts, nb_pkts);
138 ptxq->vfr_tx_cfa_action = 0;
139 pthread_mutex_unlock(&parent->rep_info->vfr_lock);
145 bnxt_get_dflt_vnic_svif(struct bnxt *bp, struct bnxt_representor *vf_rep_bp)
147 struct bnxt_rep_info *rep_info;
150 rc = bnxt_hwrm_get_dflt_vnic_svif(bp, vf_rep_bp->fw_fid,
151 &vf_rep_bp->dflt_vnic_id,
154 PMD_DRV_LOG(ERR, "Failed to get default vnic id of VF\n");
155 vf_rep_bp->dflt_vnic_id = BNXT_DFLT_VNIC_ID_INVALID;
156 vf_rep_bp->svif = BNXT_SVIF_INVALID;
158 PMD_DRV_LOG(INFO, "vf_rep->dflt_vnic_id = %d\n",
159 vf_rep_bp->dflt_vnic_id);
161 if (vf_rep_bp->dflt_vnic_id != BNXT_DFLT_VNIC_ID_INVALID &&
162 vf_rep_bp->svif != BNXT_SVIF_INVALID) {
163 rep_info = &bp->rep_info[vf_rep_bp->vf_id];
164 rep_info->conduit_valid = true;
170 int bnxt_representor_init(struct rte_eth_dev *eth_dev, void *params)
172 struct bnxt_representor *vf_rep_bp = eth_dev->data->dev_private;
173 struct bnxt_representor *rep_params =
174 (struct bnxt_representor *)params;
175 struct rte_eth_link *link;
176 struct bnxt *parent_bp;
177 uint16_t first_vf_id;
180 PMD_DRV_LOG(DEBUG, "BNXT Port:%d VFR init\n", eth_dev->data->port_id);
181 vf_rep_bp->vf_id = rep_params->vf_id;
182 vf_rep_bp->switch_domain_id = rep_params->switch_domain_id;
183 vf_rep_bp->parent_dev = rep_params->parent_dev;
184 vf_rep_bp->rep_based_pf = rep_params->rep_based_pf;
185 vf_rep_bp->flags = rep_params->flags;
186 vf_rep_bp->rep_q_r2f = rep_params->rep_q_r2f;
187 vf_rep_bp->rep_q_f2r = rep_params->rep_q_f2r;
188 vf_rep_bp->rep_fc_r2f = rep_params->rep_fc_r2f;
189 vf_rep_bp->rep_fc_f2r = rep_params->rep_fc_f2r;
191 eth_dev->data->dev_flags |= RTE_ETH_DEV_REPRESENTOR |
192 RTE_ETH_DEV_AUTOFILL_QUEUE_XSTATS;
193 eth_dev->data->representor_id = rep_params->vf_id;
194 eth_dev->data->backer_port_id = rep_params->parent_dev->data->port_id;
196 rte_eth_random_addr(vf_rep_bp->dflt_mac_addr);
197 memcpy(vf_rep_bp->mac_addr, vf_rep_bp->dflt_mac_addr,
198 sizeof(vf_rep_bp->mac_addr));
199 eth_dev->data->mac_addrs =
200 (struct rte_ether_addr *)&vf_rep_bp->mac_addr;
201 eth_dev->dev_ops = &bnxt_rep_dev_ops;
203 /* No data-path, but need stub Rx/Tx functions to avoid crash
204 * when testing with ovs-dpdk
206 eth_dev->rx_pkt_burst = bnxt_rep_rx_burst;
207 eth_dev->tx_pkt_burst = bnxt_rep_tx_burst;
208 /* Link state. Inherited from PF or trusted VF */
209 parent_bp = vf_rep_bp->parent_dev->data->dev_private;
210 link = &parent_bp->eth_dev->data->dev_link;
212 eth_dev->data->dev_link.link_speed = link->link_speed;
213 eth_dev->data->dev_link.link_duplex = link->link_duplex;
214 eth_dev->data->dev_link.link_status = link->link_status;
215 eth_dev->data->dev_link.link_autoneg = link->link_autoneg;
217 bnxt_print_link_info(eth_dev);
220 "Switch domain id %d: Representor Device %d init done\n",
221 vf_rep_bp->switch_domain_id, vf_rep_bp->vf_id);
223 if (BNXT_REP_BASED_PF(vf_rep_bp)) {
224 vf_rep_bp->fw_fid = vf_rep_bp->rep_based_pf + 1;
225 vf_rep_bp->parent_pf_idx = vf_rep_bp->rep_based_pf;
226 if (!(BNXT_REP_PF(vf_rep_bp))) {
227 /* VF representor for the remote PF,get first_vf_id */
228 rc = bnxt_hwrm_first_vf_id_query(parent_bp,
233 if (first_vf_id == 0xffff) {
235 "Invalid first_vf_id fid:%x\n",
239 PMD_DRV_LOG(INFO, "first_vf_id = %x parent_fid:%x\n",
240 first_vf_id, vf_rep_bp->fw_fid);
241 vf_rep_bp->fw_fid = rep_params->vf_id + first_vf_id;
244 vf_rep_bp->fw_fid = rep_params->vf_id + parent_bp->first_vf_id;
245 if (BNXT_VF_IS_TRUSTED(parent_bp))
246 vf_rep_bp->parent_pf_idx = parent_bp->parent->fid - 1;
248 vf_rep_bp->parent_pf_idx = parent_bp->fw_fid - 1;
251 PMD_DRV_LOG(INFO, "vf_rep->fw_fid = %d\n", vf_rep_bp->fw_fid);
256 int bnxt_representor_uninit(struct rte_eth_dev *eth_dev)
258 struct bnxt *parent_bp;
259 struct bnxt_representor *rep =
260 (struct bnxt_representor *)eth_dev->data->dev_private;
263 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
266 PMD_DRV_LOG(DEBUG, "BNXT Port:%d VFR uninit\n", eth_dev->data->port_id);
267 eth_dev->data->mac_addrs = NULL;
269 parent_bp = rep->parent_dev->data->dev_private;
271 PMD_DRV_LOG(DEBUG, "BNXT Port:%d already freed\n",
272 eth_dev->data->port_id);
276 parent_bp->num_reps--;
278 if (parent_bp->rep_info)
279 memset(&parent_bp->rep_info[vf_id], 0,
280 sizeof(parent_bp->rep_info[vf_id]));
281 /* mark that this representor has been freed */
285 int bnxt_rep_link_update_op(struct rte_eth_dev *eth_dev, int wait_to_compl)
287 struct bnxt *parent_bp;
288 struct bnxt_representor *rep =
289 (struct bnxt_representor *)eth_dev->data->dev_private;
290 struct rte_eth_link *link;
293 parent_bp = rep->parent_dev->data->dev_private;
297 rc = bnxt_link_update_op(parent_bp->eth_dev, wait_to_compl);
299 /* Link state. Inherited from PF or trusted VF */
300 link = &parent_bp->eth_dev->data->dev_link;
302 eth_dev->data->dev_link.link_speed = link->link_speed;
303 eth_dev->data->dev_link.link_duplex = link->link_duplex;
304 eth_dev->data->dev_link.link_status = link->link_status;
305 eth_dev->data->dev_link.link_autoneg = link->link_autoneg;
306 bnxt_print_link_info(eth_dev);
311 static int bnxt_tf_vfr_alloc(struct rte_eth_dev *vfr_ethdev)
314 struct bnxt_representor *vfr = vfr_ethdev->data->dev_private;
315 struct rte_eth_dev *parent_dev = vfr->parent_dev;
316 struct bnxt *parent_bp = parent_dev->data->dev_private;
318 if (!parent_bp || !parent_bp->ulp_ctx) {
319 BNXT_TF_DBG(ERR, "Invalid arguments\n");
322 /* update the port id so you can backtrack to ethdev */
323 vfr->dpdk_port_id = vfr_ethdev->data->port_id;
325 /* If pair is present, then delete the pair */
326 if (bnxt_hwrm_cfa_pair_exists(parent_bp, vfr))
327 (void)bnxt_hwrm_cfa_pair_free(parent_bp, vfr);
329 /* Update the ULP portdata base with the new VFR interface */
330 rc = ulp_port_db_dev_port_intf_update(parent_bp->ulp_ctx, vfr_ethdev);
332 BNXT_TF_DBG(ERR, "Failed to update ulp port details vfr:%u\n",
337 /* Create the default rules for the VFR */
338 rc = bnxt_ulp_create_vfr_default_rules(vfr_ethdev);
340 BNXT_TF_DBG(ERR, "Failed to create VFR default rules vfr:%u\n",
344 /* update the port id so you can backtrack to ethdev */
345 vfr->dpdk_port_id = vfr_ethdev->data->port_id;
347 rc = bnxt_hwrm_cfa_pair_alloc(parent_bp, vfr);
349 BNXT_TF_DBG(ERR, "Failed in hwrm vfr alloc vfr:%u rc=%d\n",
351 (void)bnxt_ulp_delete_vfr_default_rules(vfr);
353 BNXT_TF_DBG(DEBUG, "BNXT Port:%d VFR created and initialized\n",
358 static int bnxt_vfr_alloc(struct rte_eth_dev *vfr_ethdev)
361 struct bnxt_representor *vfr = vfr_ethdev->data->dev_private;
362 struct bnxt *parent_bp;
364 if (!vfr || !vfr->parent_dev) {
366 "No memory allocated for representor\n");
370 parent_bp = vfr->parent_dev->data->dev_private;
371 if (parent_bp && !parent_bp->ulp_ctx) {
373 "ulp context not allocated for parent\n");
377 /* Check if representor has been already allocated in FW */
378 if (vfr->vfr_tx_cfa_action)
382 * Alloc VF rep rules in CFA after default VNIC is created.
383 * Otherwise the FW will create the VF-rep rules with
384 * default drop action.
386 rc = bnxt_tf_vfr_alloc(vfr_ethdev);
388 PMD_DRV_LOG(DEBUG, "allocated representor %d in FW\n",
392 "Failed to alloc representor %d in FW\n",
398 static void bnxt_vfr_rx_queue_release_mbufs(struct bnxt_rx_queue *rxq)
400 struct rte_mbuf **sw_ring;
403 if (!rxq || !rxq->rx_ring)
406 sw_ring = rxq->rx_ring->rx_buf_ring;
408 for (i = 0; i < rxq->rx_ring->rx_ring_struct->ring_size; i++) {
410 if (sw_ring[i] != &rxq->fake_mbuf)
411 rte_pktmbuf_free_seg(sw_ring[i]);
418 static void bnxt_rep_free_rx_mbufs(struct bnxt_representor *rep_bp)
420 struct bnxt_rx_queue *rxq;
423 for (i = 0; i < rep_bp->rx_nr_rings; i++) {
424 rxq = rep_bp->rx_queues[i];
425 bnxt_vfr_rx_queue_release_mbufs(rxq);
429 int bnxt_rep_dev_start_op(struct rte_eth_dev *eth_dev)
431 struct bnxt_representor *rep_bp = eth_dev->data->dev_private;
432 struct bnxt_rep_info *rep_info;
433 struct bnxt *parent_bp;
436 parent_bp = rep_bp->parent_dev->data->dev_private;
437 rep_info = &parent_bp->rep_info[rep_bp->vf_id];
439 BNXT_TF_DBG(DEBUG, "BNXT Port:%d VFR start\n", eth_dev->data->port_id);
440 pthread_mutex_lock(&rep_info->vfr_start_lock);
441 if (!rep_info->conduit_valid) {
442 rc = bnxt_get_dflt_vnic_svif(parent_bp, rep_bp);
443 if (rc || !rep_info->conduit_valid) {
444 pthread_mutex_unlock(&rep_info->vfr_start_lock);
448 pthread_mutex_unlock(&rep_info->vfr_start_lock);
450 rc = bnxt_vfr_alloc(eth_dev);
452 eth_dev->data->dev_link.link_status = 0;
453 bnxt_rep_free_rx_mbufs(rep_bp);
456 eth_dev->rx_pkt_burst = &bnxt_rep_rx_burst;
457 eth_dev->tx_pkt_burst = &bnxt_rep_tx_burst;
458 bnxt_rep_link_update_op(eth_dev, 1);
463 static int bnxt_tf_vfr_free(struct bnxt_representor *vfr)
465 BNXT_TF_DBG(DEBUG, "BNXT Port:%d VFR ulp free\n", vfr->dpdk_port_id);
466 return bnxt_ulp_delete_vfr_default_rules(vfr);
469 static int bnxt_vfr_free(struct bnxt_representor *vfr)
472 struct bnxt *parent_bp;
474 if (!vfr || !vfr->parent_dev) {
476 "No memory allocated for representor\n");
480 parent_bp = vfr->parent_dev->data->dev_private;
482 PMD_DRV_LOG(DEBUG, "BNXT Port:%d VFR already freed\n",
487 /* Check if representor has been already freed in FW */
488 if (!vfr->vfr_tx_cfa_action)
491 rc = bnxt_tf_vfr_free(vfr);
494 "Failed to free representor %d in FW\n",
498 PMD_DRV_LOG(DEBUG, "freed representor %d in FW\n",
500 vfr->vfr_tx_cfa_action = 0;
502 rc = bnxt_hwrm_cfa_pair_free(parent_bp, vfr);
507 int bnxt_rep_dev_stop_op(struct rte_eth_dev *eth_dev)
509 struct bnxt_representor *vfr_bp = eth_dev->data->dev_private;
511 /* Avoid crashes as we are about to free queues */
512 bnxt_stop_rxtx(eth_dev);
514 BNXT_TF_DBG(DEBUG, "BNXT Port:%d VFR stop\n", eth_dev->data->port_id);
516 bnxt_vfr_free(vfr_bp);
518 if (eth_dev->data->dev_started)
519 eth_dev->data->dev_link.link_status = 0;
521 bnxt_rep_free_rx_mbufs(vfr_bp);
526 int bnxt_rep_dev_close_op(struct rte_eth_dev *eth_dev)
528 BNXT_TF_DBG(DEBUG, "BNXT Port:%d VFR close\n", eth_dev->data->port_id);
529 bnxt_representor_uninit(eth_dev);
533 int bnxt_rep_dev_info_get_op(struct rte_eth_dev *eth_dev,
534 struct rte_eth_dev_info *dev_info)
536 struct bnxt_representor *rep_bp = eth_dev->data->dev_private;
537 struct bnxt *parent_bp;
538 unsigned int max_rx_rings;
542 parent_bp = rep_bp->parent_dev->data->dev_private;
544 PMD_DRV_LOG(ERR, "Rep parent NULL!\n");
547 PMD_DRV_LOG(DEBUG, "Representor dev_info_get_op\n");
548 dev_info->max_mac_addrs = parent_bp->max_l2_ctx;
549 dev_info->max_hash_mac_addrs = 0;
551 max_rx_rings = BNXT_MAX_VF_REP_RINGS;
552 /* For the sake of symmetry, max_rx_queues = max_tx_queues */
553 dev_info->max_rx_queues = max_rx_rings;
554 dev_info->max_tx_queues = max_rx_rings;
555 dev_info->reta_size = bnxt_rss_hash_tbl_size(parent_bp);
556 dev_info->hash_key_size = 40;
557 dev_info->dev_capa &= ~RTE_ETH_DEV_CAPA_FLOW_RULE_KEEP;
560 dev_info->min_mtu = RTE_ETHER_MIN_MTU;
561 dev_info->max_mtu = BNXT_MAX_MTU;
563 /* Fast path specifics */
564 dev_info->min_rx_bufsize = 1;
565 dev_info->max_rx_pktlen = BNXT_MAX_PKT_LEN;
567 dev_info->rx_offload_capa = BNXT_DEV_RX_OFFLOAD_SUPPORT;
568 if (parent_bp->flags & BNXT_FLAG_PTP_SUPPORTED)
569 dev_info->rx_offload_capa |= RTE_ETH_RX_OFFLOAD_TIMESTAMP;
570 dev_info->tx_offload_capa = BNXT_DEV_TX_OFFLOAD_SUPPORT;
571 dev_info->flow_type_rss_offloads = BNXT_ETH_RSS_SUPPORT;
573 dev_info->switch_info.name = eth_dev->device->name;
574 dev_info->switch_info.domain_id = rep_bp->switch_domain_id;
575 dev_info->switch_info.port_id =
576 rep_bp->vf_id & BNXT_SWITCH_PORT_ID_VF_MASK;
581 int bnxt_rep_dev_configure_op(struct rte_eth_dev *eth_dev)
583 struct bnxt_representor *rep_bp = eth_dev->data->dev_private;
585 PMD_DRV_LOG(DEBUG, "Representor dev_configure_op\n");
586 rep_bp->rx_queues = (void *)eth_dev->data->rx_queues;
587 rep_bp->tx_nr_rings = eth_dev->data->nb_tx_queues;
588 rep_bp->rx_nr_rings = eth_dev->data->nb_rx_queues;
593 static int bnxt_init_rep_rx_ring(struct bnxt_rx_queue *rxq,
594 unsigned int socket_id)
596 struct bnxt_rx_ring_info *rxr;
597 struct bnxt_ring *ring;
599 rxr = rte_zmalloc_socket("bnxt_rep_rx_ring",
600 sizeof(struct bnxt_rx_ring_info),
601 RTE_CACHE_LINE_SIZE, socket_id);
606 ring = rte_zmalloc_socket("bnxt_rep_rx_ring_struct",
607 sizeof(struct bnxt_ring),
608 RTE_CACHE_LINE_SIZE, socket_id);
611 rxr->rx_ring_struct = ring;
612 ring->ring_size = rte_align32pow2(rxq->nb_rx_desc);
613 ring->ring_mask = ring->ring_size - 1;
618 int bnxt_rep_rx_queue_setup_op(struct rte_eth_dev *eth_dev,
621 unsigned int socket_id,
622 __rte_unused const struct rte_eth_rxconf *rx_conf,
623 __rte_unused struct rte_mempool *mp)
625 struct bnxt_representor *rep_bp = eth_dev->data->dev_private;
626 struct bnxt *parent_bp = rep_bp->parent_dev->data->dev_private;
627 struct bnxt_rx_queue *parent_rxq;
628 struct bnxt_rx_queue *rxq;
629 struct rte_mbuf **buf_ring;
632 if (queue_idx >= BNXT_MAX_VF_REP_RINGS) {
634 "Cannot create Rx ring %d. %d rings available\n",
635 queue_idx, BNXT_MAX_VF_REP_RINGS);
639 if (!nb_desc || nb_desc > MAX_RX_DESC_CNT) {
640 PMD_DRV_LOG(ERR, "nb_desc %d is invalid\n", nb_desc);
644 if (!parent_bp->rx_queues) {
645 PMD_DRV_LOG(ERR, "Parent Rx qs not configured yet\n");
649 parent_rxq = parent_bp->rx_queues[queue_idx];
651 PMD_DRV_LOG(ERR, "Parent RxQ has not been configured yet\n");
655 if (nb_desc != parent_rxq->nb_rx_desc) {
656 PMD_DRV_LOG(ERR, "nb_desc %d do not match parent rxq", nb_desc);
660 if (eth_dev->data->rx_queues) {
661 rxq = eth_dev->data->rx_queues[queue_idx];
663 bnxt_rx_queue_release_op(eth_dev, queue_idx);
666 rxq = rte_zmalloc_socket("bnxt_vfr_rx_queue",
667 sizeof(struct bnxt_rx_queue),
668 RTE_CACHE_LINE_SIZE, socket_id);
670 PMD_DRV_LOG(ERR, "bnxt_vfr_rx_queue allocation failed!\n");
674 eth_dev->data->rx_queues[queue_idx] = rxq;
676 rxq->nb_rx_desc = nb_desc;
678 rc = bnxt_init_rep_rx_ring(rxq, socket_id);
682 buf_ring = rte_zmalloc_socket("bnxt_rx_vfr_buf_ring",
683 sizeof(struct rte_mbuf *) *
684 rxq->rx_ring->rx_ring_struct->ring_size,
685 RTE_CACHE_LINE_SIZE, socket_id);
687 PMD_DRV_LOG(ERR, "bnxt_rx_vfr_buf_ring allocation failed!\n");
692 rxq->rx_ring->rx_buf_ring = buf_ring;
693 rxq->queue_id = queue_idx;
694 rxq->port_id = eth_dev->data->port_id;
700 bnxt_rep_rx_queue_release_op(eth_dev, queue_idx);
705 void bnxt_rep_rx_queue_release_op(struct rte_eth_dev *dev, uint16_t queue_idx)
707 struct bnxt_rx_queue *rxq = dev->data->rx_queues[queue_idx];
712 bnxt_rx_queue_release_mbufs(rxq);
714 bnxt_free_ring(rxq->rx_ring->rx_ring_struct);
715 rte_free(rxq->rx_ring->rx_ring_struct);
716 rte_free(rxq->rx_ring);
721 int bnxt_rep_tx_queue_setup_op(struct rte_eth_dev *eth_dev,
724 unsigned int socket_id,
725 __rte_unused const struct rte_eth_txconf *tx_conf)
727 struct bnxt_representor *rep_bp = eth_dev->data->dev_private;
728 struct bnxt *parent_bp = rep_bp->parent_dev->data->dev_private;
729 struct bnxt_tx_queue *parent_txq, *txq;
730 struct bnxt_vf_rep_tx_queue *vfr_txq;
732 if (queue_idx >= BNXT_MAX_VF_REP_RINGS) {
734 "Cannot create Tx rings %d. %d rings available\n",
735 queue_idx, BNXT_MAX_VF_REP_RINGS);
739 if (!nb_desc || nb_desc > MAX_TX_DESC_CNT) {
740 PMD_DRV_LOG(ERR, "nb_desc %d is invalid", nb_desc);
744 if (!parent_bp->tx_queues) {
745 PMD_DRV_LOG(ERR, "Parent Tx qs not configured yet\n");
749 parent_txq = parent_bp->tx_queues[queue_idx];
751 PMD_DRV_LOG(ERR, "Parent TxQ has not been configured yet\n");
755 if (nb_desc != parent_txq->nb_tx_desc) {
756 PMD_DRV_LOG(ERR, "nb_desc %d do not match parent txq", nb_desc);
760 if (eth_dev->data->tx_queues) {
761 vfr_txq = eth_dev->data->tx_queues[queue_idx];
763 bnxt_rep_tx_queue_release_op(eth_dev, queue_idx);
766 vfr_txq = rte_zmalloc_socket("bnxt_vfr_tx_queue",
767 sizeof(struct bnxt_vf_rep_tx_queue),
768 RTE_CACHE_LINE_SIZE, socket_id);
770 PMD_DRV_LOG(ERR, "bnxt_vfr_tx_queue allocation failed!");
773 txq = rte_zmalloc_socket("bnxt_tx_queue",
774 sizeof(struct bnxt_tx_queue),
775 RTE_CACHE_LINE_SIZE, socket_id);
777 PMD_DRV_LOG(ERR, "bnxt_tx_queue allocation failed!");
782 txq->nb_tx_desc = nb_desc;
783 txq->queue_id = queue_idx;
784 txq->port_id = eth_dev->data->port_id;
786 vfr_txq->bp = rep_bp;
787 eth_dev->data->tx_queues[queue_idx] = vfr_txq;
792 void bnxt_rep_tx_queue_release_op(struct rte_eth_dev *dev, uint16_t queue_idx)
794 struct bnxt_vf_rep_tx_queue *vfr_txq = dev->data->tx_queues[queue_idx];
799 rte_free(vfr_txq->txq);
801 dev->data->tx_queues[queue_idx] = NULL;
804 int bnxt_rep_stats_get_op(struct rte_eth_dev *eth_dev,
805 struct rte_eth_stats *stats)
807 struct bnxt_representor *rep_bp = eth_dev->data->dev_private;
810 memset(stats, 0, sizeof(*stats));
811 for (i = 0; i < BNXT_MAX_VF_REP_RINGS; i++) {
812 stats->obytes += rep_bp->tx_bytes[i];
813 stats->opackets += rep_bp->tx_pkts[i];
814 stats->ibytes += rep_bp->rx_bytes[i];
815 stats->ipackets += rep_bp->rx_pkts[i];
816 stats->imissed += rep_bp->rx_drop_pkts[i];
818 stats->q_ipackets[i] = rep_bp->rx_pkts[i];
819 stats->q_ibytes[i] = rep_bp->rx_bytes[i];
820 stats->q_opackets[i] = rep_bp->tx_pkts[i];
821 stats->q_obytes[i] = rep_bp->tx_bytes[i];
822 stats->q_errors[i] = rep_bp->rx_drop_pkts[i];
828 int bnxt_rep_stats_reset_op(struct rte_eth_dev *eth_dev)
830 struct bnxt_representor *rep_bp = eth_dev->data->dev_private;
833 for (i = 0; i < BNXT_MAX_VF_REP_RINGS; i++) {
834 rep_bp->tx_pkts[i] = 0;
835 rep_bp->tx_bytes[i] = 0;
836 rep_bp->rx_pkts[i] = 0;
837 rep_bp->rx_bytes[i] = 0;
838 rep_bp->rx_drop_pkts[i] = 0;
843 int bnxt_rep_stop_all(struct bnxt *bp)
846 struct rte_eth_dev *rep_eth_dev;
849 /* No vfrep ports just exit */
853 for (vf_id = 0; vf_id < BNXT_MAX_VF_REPS(bp); vf_id++) {
854 rep_eth_dev = bp->rep_info[vf_id].vfr_eth_dev;
857 ret = bnxt_rep_dev_stop_op(rep_eth_dev);