ethdev: add namespace
[dpdk.git] / drivers / net / bnxt / bnxt_reps.c
index 74a76fc..1c07db3 100644 (file)
@@ -1,5 +1,5 @@
 /* SPDX-License-Identifier: BSD-3-Clause
- * Copyright(c) 2014-2020 Broadcom
+ * Copyright(c) 2014-2021 Broadcom
  * All rights reserved.
  */
 
@@ -29,7 +29,7 @@ static const struct eth_dev_ops bnxt_rep_dev_ops = {
        .dev_stop = bnxt_rep_dev_stop_op,
        .stats_get = bnxt_rep_stats_get_op,
        .stats_reset = bnxt_rep_stats_reset_op,
-       .filter_ctrl = bnxt_filter_ctrl_op
+       .flow_ops_get = bnxt_flow_ops_get_op
 };
 
 uint16_t
@@ -55,17 +55,17 @@ bnxt_vfr_recv(uint16_t port_id, uint16_t queue_id, struct rte_mbuf *mbuf)
        mask = rep_rxr->rx_ring_struct->ring_mask;
 
        /* Put this mbuf on the RxQ of the Representor */
-       prod_rx_buf = &rep_rxr->rx_buf_ring[rep_rxr->rx_prod & mask];
-       if (!*prod_rx_buf) {
+       prod_rx_buf = &rep_rxr->rx_buf_ring[rep_rxr->rx_raw_prod & mask];
+       if (*prod_rx_buf == NULL) {
                *prod_rx_buf = mbuf;
                vfr_bp->rx_bytes[que] += mbuf->pkt_len;
                vfr_bp->rx_pkts[que]++;
-               rep_rxr->rx_prod++;
+               rep_rxr->rx_raw_prod++;
        } else {
                /* Representor Rx ring full, drop pkt */
                vfr_bp->rx_drop_bytes[que] += mbuf->pkt_len;
                vfr_bp->rx_drop_pkts[que]++;
-               rte_pktmbuf_free(mbuf);
+               rte_mbuf_raw_free(mbuf);
        }
 
        return 0;
@@ -104,7 +104,7 @@ bnxt_rep_rx_burst(void *rx_queue,
 static uint16_t
 bnxt_rep_tx_burst(void *tx_queue,
                     struct rte_mbuf **tx_pkts,
-                    __rte_unused uint16_t nb_pkts)
+                    uint16_t nb_pkts)
 {
        struct bnxt_vf_rep_tx_queue *vfr_txq = tx_queue;
        struct bnxt_tx_queue *ptxq;
@@ -184,8 +184,10 @@ int bnxt_representor_init(struct rte_eth_dev *eth_dev, void *params)
        vf_rep_bp->rep_fc_r2f = rep_params->rep_fc_r2f;
        vf_rep_bp->rep_fc_f2r = rep_params->rep_fc_f2r;
 
-       eth_dev->data->dev_flags |= RTE_ETH_DEV_REPRESENTOR;
+       eth_dev->data->dev_flags |= RTE_ETH_DEV_REPRESENTOR |
+                                       RTE_ETH_DEV_AUTOFILL_QUEUE_XSTATS;
        eth_dev->data->representor_id = rep_params->vf_id;
+       eth_dev->data->backer_port_id = rep_params->parent_dev->data->port_id;
 
        rte_eth_random_addr(vf_rep_bp->dflt_mac_addr);
        memcpy(vf_rep_bp->mac_addr, vf_rep_bp->dflt_mac_addr,
@@ -215,8 +217,9 @@ int bnxt_representor_init(struct rte_eth_dev *eth_dev, void *params)
                    "Switch domain id %d: Representor Device %d init done\n",
                    vf_rep_bp->switch_domain_id, vf_rep_bp->vf_id);
 
-       if (vf_rep_bp->rep_based_pf) {
+       if (BNXT_REP_BASED_PF(vf_rep_bp)) {
                vf_rep_bp->fw_fid = vf_rep_bp->rep_based_pf + 1;
+               vf_rep_bp->parent_pf_idx = vf_rep_bp->rep_based_pf;
                if (!(BNXT_REP_PF(vf_rep_bp))) {
                        /* VF representor for the remote PF,get first_vf_id */
                        rc = bnxt_hwrm_first_vf_id_query(parent_bp,
@@ -236,6 +239,10 @@ int bnxt_representor_init(struct rte_eth_dev *eth_dev, void *params)
                }
        }  else {
                vf_rep_bp->fw_fid = rep_params->vf_id + parent_bp->first_vf_id;
+               if (BNXT_VF_IS_TRUSTED(parent_bp))
+                       vf_rep_bp->parent_pf_idx = parent_bp->parent->fid - 1;
+               else
+                       vf_rep_bp->parent_pf_idx = parent_bp->fw_fid - 1;
        }
 
        PMD_DRV_LOG(INFO, "vf_rep->fw_fid = %d\n", vf_rep_bp->fw_fid);
@@ -255,7 +262,6 @@ int bnxt_representor_uninit(struct rte_eth_dev *eth_dev)
 
        PMD_DRV_LOG(DEBUG, "BNXT Port:%d VFR uninit\n", eth_dev->data->port_id);
        eth_dev->data->mac_addrs = NULL;
-       eth_dev->dev_ops = NULL;
 
        parent_bp = rep->parent_dev->data->dev_private;
        if (!parent_bp) {
@@ -329,11 +335,7 @@ static int bnxt_tf_vfr_alloc(struct rte_eth_dev *vfr_ethdev)
        /* update the port id so you can backtrack to ethdev */
        vfr->dpdk_port_id = vfr_ethdev->data->port_id;
 
-       if (BNXT_STINGRAY(parent_bp)) {
-               rc = bnxt_hwrm_cfa_pair_alloc(parent_bp, vfr);
-       } else {
-               rc = bnxt_hwrm_cfa_vfr_alloc(parent_bp, vfr->vf_id);
-       }
+       rc = bnxt_hwrm_cfa_pair_alloc(parent_bp, vfr);
        if (rc) {
                BNXT_TF_DBG(ERR, "Failed in hwrm vfr alloc vfr:%u rc=%d\n",
                            vfr->vf_id, rc);
@@ -468,15 +470,12 @@ static int bnxt_vfr_free(struct bnxt_representor *vfr)
                    vfr->vf_id);
        vfr->vfr_tx_cfa_action = 0;
 
-       if (BNXT_STINGRAY(parent_bp))
-               rc = bnxt_hwrm_cfa_pair_free(parent_bp, vfr);
-       else
-               rc = bnxt_hwrm_cfa_vfr_free(parent_bp, vfr->vf_id);
+       rc = bnxt_hwrm_cfa_pair_free(parent_bp, vfr);
 
        return rc;
 }
 
-void bnxt_rep_dev_stop_op(struct rte_eth_dev *eth_dev)
+int bnxt_rep_dev_stop_op(struct rte_eth_dev *eth_dev)
 {
        struct bnxt_representor *vfr_bp = eth_dev->data->dev_private;
 
@@ -492,6 +491,8 @@ void bnxt_rep_dev_stop_op(struct rte_eth_dev *eth_dev)
                eth_dev->data->dev_link.link_status = 0;
 
        bnxt_rep_free_rx_mbufs(vfr_bp);
+
+       return 0;
 }
 
 int bnxt_rep_dev_close_op(struct rte_eth_dev *eth_dev)
@@ -536,7 +537,7 @@ int bnxt_rep_dev_info_get_op(struct rte_eth_dev *eth_dev,
 
        dev_info->rx_offload_capa = BNXT_DEV_RX_OFFLOAD_SUPPORT;
        if (parent_bp->flags & BNXT_FLAG_PTP_SUPPORTED)
-               dev_info->rx_offload_capa |= DEV_RX_OFFLOAD_TIMESTAMP;
+               dev_info->rx_offload_capa |= RTE_ETH_RX_OFFLOAD_TIMESTAMP;
        dev_info->tx_offload_capa = BNXT_DEV_TX_OFFLOAD_SUPPORT;
        dev_info->flow_type_rss_offloads = BNXT_ETH_RSS_SUPPORT;
 
@@ -548,7 +549,7 @@ int bnxt_rep_dev_info_get_op(struct rte_eth_dev *eth_dev,
        return 0;
 }
 
-int bnxt_rep_dev_configure_op(__rte_unused struct rte_eth_dev *eth_dev)
+int bnxt_rep_dev_configure_op(struct rte_eth_dev *eth_dev)
 {
        struct bnxt_representor *rep_bp = eth_dev->data->dev_private;
 
@@ -630,7 +631,7 @@ int bnxt_rep_rx_queue_setup_op(struct rte_eth_dev *eth_dev,
        if (eth_dev->data->rx_queues) {
                rxq = eth_dev->data->rx_queues[queue_idx];
                if (rxq)
-                       bnxt_rx_queue_release_op(rxq);
+                       bnxt_rx_queue_release_op(eth_dev, queue_idx);
        }
 
        rxq = rte_zmalloc_socket("bnxt_vfr_rx_queue",
@@ -641,6 +642,8 @@ int bnxt_rep_rx_queue_setup_op(struct rte_eth_dev *eth_dev,
                return -ENOMEM;
        }
 
+       eth_dev->data->rx_queues[queue_idx] = rxq;
+
        rxq->nb_rx_desc = nb_desc;
 
        rc = bnxt_init_rep_rx_ring(rxq, socket_id);
@@ -660,20 +663,19 @@ int bnxt_rep_rx_queue_setup_op(struct rte_eth_dev *eth_dev,
        rxq->rx_ring->rx_buf_ring = buf_ring;
        rxq->queue_id = queue_idx;
        rxq->port_id = eth_dev->data->port_id;
-       eth_dev->data->rx_queues[queue_idx] = rxq;
 
        return 0;
 
 out:
        if (rxq)
-               bnxt_rep_rx_queue_release_op(rxq);
+               bnxt_rep_rx_queue_release_op(eth_dev, queue_idx);
 
        return rc;
 }
 
-void bnxt_rep_rx_queue_release_op(void *rx_queue)
+void bnxt_rep_rx_queue_release_op(struct rte_eth_dev *dev, uint16_t queue_idx)
 {
-       struct bnxt_rx_queue *rxq = (struct bnxt_rx_queue *)rx_queue;
+       struct bnxt_rx_queue *rxq = dev->data->rx_queues[queue_idx];
 
        if (!rxq)
                return;
@@ -728,8 +730,8 @@ int bnxt_rep_tx_queue_setup_op(struct rte_eth_dev *eth_dev,
 
        if (eth_dev->data->tx_queues) {
                vfr_txq = eth_dev->data->tx_queues[queue_idx];
-               bnxt_rep_tx_queue_release_op(vfr_txq);
-               vfr_txq = NULL;
+               if (vfr_txq != NULL)
+                       bnxt_rep_tx_queue_release_op(eth_dev, queue_idx);
        }
 
        vfr_txq = rte_zmalloc_socket("bnxt_vfr_tx_queue",
@@ -758,15 +760,16 @@ int bnxt_rep_tx_queue_setup_op(struct rte_eth_dev *eth_dev,
        return 0;
 }
 
-void bnxt_rep_tx_queue_release_op(void *tx_queue)
+void bnxt_rep_tx_queue_release_op(struct rte_eth_dev *dev, uint16_t queue_idx)
 {
-       struct bnxt_vf_rep_tx_queue *vfr_txq = tx_queue;
+       struct bnxt_vf_rep_tx_queue *vfr_txq = dev->data->tx_queues[queue_idx];
 
        if (!vfr_txq)
                return;
 
        rte_free(vfr_txq->txq);
        rte_free(vfr_txq);
+       dev->data->tx_queues[queue_idx] = NULL;
 }
 
 int bnxt_rep_stats_get_op(struct rte_eth_dev *eth_dev,
@@ -808,19 +811,24 @@ int bnxt_rep_stats_reset_op(struct rte_eth_dev *eth_dev)
        return 0;
 }
 
-void bnxt_rep_stop_all(struct bnxt *bp)
+int bnxt_rep_stop_all(struct bnxt *bp)
 {
        uint16_t vf_id;
        struct rte_eth_dev *rep_eth_dev;
+       int ret;
 
        /* No vfrep ports just exit */
        if (!bp->rep_info)
-               return;
+               return 0;
 
        for (vf_id = 0; vf_id < BNXT_MAX_VF_REPS; vf_id++) {
                rep_eth_dev = bp->rep_info[vf_id].vfr_eth_dev;
                if (!rep_eth_dev)
                        continue;
-               bnxt_rep_dev_stop_op(rep_eth_dev);
+               ret = bnxt_rep_dev_stop_op(rep_eth_dev);
+               if (ret != 0)
+                       return ret;
        }
+
+       return 0;
 }