net/mvpp2: remove resources when port is closed

Message ID 1565000216-9465-1-git-send-email-lironh@marvell.com (mailing list archive)
State Accepted, archived
Delegated to: Jerin Jacob
Headers
Series net/mvpp2: remove resources when port is closed |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/iol-Compile-Testing success Compile Testing PASS
ci/intel-Performance-Testing success Performance Testing PASS
ci/Intel-compilation success Compilation OK
ci/mellanox-Performance-Testing success Performance Testing PASS

Commit Message

Liron Himi Aug. 5, 2019, 10:16 a.m. UTC
  From: Liron Himi <lironh@marvell.com>

Since 18.11, it is suggested that driver should release all its private
resources at the dev_close routine. So all resources previously released
in remove routine are now released at the dev_close routine, and the
dev_close routine will be called in driver remove routine in order to
support removing a device without closing its ports.

Above behavior changes are supported by setting RTE_ETH_DEV_CLOSE_REMOVE
flag during probe stage.

Signed-off-by: Liron Himi <lironh@marvell.com>
Reviewed-by: Yuri Chipchev <yuric@marvell.com>
---
 drivers/net/mvpp2/mrvl_ethdev.c | 79 +++++++++++++++--------------------------
 1 file changed, 29 insertions(+), 50 deletions(-)
  

Comments

Jerin Jacob Kollanukkaran Aug. 5, 2019, 5:28 p.m. UTC | #1
> -----Original Message-----
> From: lironh@marvell.com <lironh@marvell.com>
> Sent: Monday, August 5, 2019 3:47 PM
> To: Jerin Jacob Kollanukkaran <jerinj@marvell.com>
> Cc: dev@dpdk.org; Liron Himi <lironh@marvell.com>
> Subject: [PATCH] net/mvpp2: remove resources when port is closed
> 
> From: Liron Himi <lironh@marvell.com>
> 
> Since 18.11, it is suggested that driver should release all its private resources
> at the dev_close routine. So all resources previously released in remove
> routine are now released at the dev_close routine, and the dev_close
> routine will be called in driver remove routine in order to support removing a
> device without closing its ports.
> 
> Above behavior changes are supported by setting
> RTE_ETH_DEV_CLOSE_REMOVE flag during probe stage.
> 
> Signed-off-by: Liron Himi <lironh@marvell.com>
> Reviewed-by: Yuri Chipchev <yuric@marvell.com>

Applied to dpdk-next-net-mrvl/master. Thanks
  

Patch

diff --git a/drivers/net/mvpp2/mrvl_ethdev.c b/drivers/net/mvpp2/mrvl_ethdev.c
index d1d0d41..810a703 100644
--- a/drivers/net/mvpp2/mrvl_ethdev.c
+++ b/drivers/net/mvpp2/mrvl_ethdev.c
@@ -144,6 +144,9 @@  static uint16_t mrvl_tx_pkt_burst(void *txq, struct rte_mbuf **tx_pkts,
 				  uint16_t nb_pkts);
 static uint16_t mrvl_tx_sg_pkt_burst(void *txq,	struct rte_mbuf **tx_pkts,
 				     uint16_t nb_pkts);
+static int rte_pmd_mrvl_remove(struct rte_vdev_device *vdev);
+static void mrvl_deinit_pp2(void);
+static void mrvl_deinit_hifs(void);
 
 
 #define MRVL_XSTATS_TBL_ENTRY(name) { \
@@ -898,6 +901,22 @@  mrvl_dev_close(struct rte_eth_dev *dev)
 		pp2_cls_plcr_deinit(priv->default_policer);
 		priv->default_policer = NULL;
 	}
+
+
+	if (priv->bpool) {
+		pp2_bpool_deinit(priv->bpool);
+		used_bpools[priv->pp_id] &= ~(1 << priv->bpool_bit);
+		priv->bpool = NULL;
+	}
+
+	mrvl_dev_num--;
+
+	if (mrvl_dev_num == 0) {
+		MRVL_LOG(INFO, "Perform MUSDK deinit");
+		mrvl_deinit_hifs();
+		mrvl_deinit_pp2();
+		rte_mvep_deinit(MVEP_MOD_T_PP2);
+	}
 }
 
 /**
@@ -2809,6 +2828,9 @@  mrvl_eth_dev_create(struct rte_vdev_device *vdev, const char *name)
 	mrvl_set_tx_function(eth_dev);
 	eth_dev->dev_ops = &mrvl_ops;
 
+	/* Flag to call rte_eth_dev_release_port() in rte_eth_dev_close(). */
+	eth_dev->data->dev_flags |= RTE_ETH_DEV_CLOSE_REMOVE;
+
 	rte_eth_dev_probing_finish(eth_dev);
 	return 0;
 out_free:
@@ -2818,28 +2840,6 @@  mrvl_eth_dev_create(struct rte_vdev_device *vdev, const char *name)
 }
 
 /**
- * Cleanup previously created device representing Ethernet port.
- *
- * @param name
- *   Pointer to the port name.
- */
-static void
-mrvl_eth_dev_destroy(const char *name)
-{
-	struct rte_eth_dev *eth_dev;
-	struct mrvl_priv *priv;
-
-	eth_dev = rte_eth_dev_allocated(name);
-	if (!eth_dev)
-		return;
-
-	priv = eth_dev->data->dev_private;
-	pp2_bpool_deinit(priv->bpool);
-	used_bpools[priv->pp_id] &= ~(1 << priv->bpool_bit);
-	rte_eth_dev_release_port(eth_dev);
-}
-
-/**
  * Callback used by rte_kvargs_process() during argument parsing.
  *
  * @param key
@@ -2959,20 +2959,15 @@  rte_pmd_mrvl_probe(struct rte_vdev_device *vdev)
 		ret = mrvl_eth_dev_create(vdev, ifnames.names[i]);
 		if (ret)
 			goto out_cleanup;
+		mrvl_dev_num++;
 	}
-	mrvl_dev_num += ifnum;
 
 	rte_kvargs_free(kvlist);
 
 	return 0;
 out_cleanup:
-	for (; i > 0; i--)
-		mrvl_eth_dev_destroy(ifnames.names[i]);
+	rte_pmd_mrvl_remove(vdev);
 
-	if (mrvl_dev_num == 0) {
-		mrvl_deinit_pp2();
-		rte_mvep_deinit(MVEP_MOD_T_PP2);
-	}
 out_free_kvlist:
 	rte_kvargs_free(kvlist);
 
@@ -2991,28 +2986,12 @@  rte_pmd_mrvl_probe(struct rte_vdev_device *vdev)
 static int
 rte_pmd_mrvl_remove(struct rte_vdev_device *vdev)
 {
-	int i;
-	const char *name;
+	uint16_t port_id;
 
-	name = rte_vdev_device_name(vdev);
-	if (!name)
-		return -EINVAL;
-
-	MRVL_LOG(INFO, "Removing %s", name);
-
-	RTE_ETH_FOREACH_DEV(i) { /* FIXME: removing all devices! */
-		char ifname[RTE_ETH_NAME_MAX_LEN];
-
-		rte_eth_dev_get_name_by_port(i, ifname);
-		mrvl_eth_dev_destroy(ifname);
-		mrvl_dev_num--;
-	}
-
-	if (mrvl_dev_num == 0) {
-		MRVL_LOG(INFO, "Perform MUSDK deinit");
-		mrvl_deinit_hifs();
-		mrvl_deinit_pp2();
-		rte_mvep_deinit(MVEP_MOD_T_PP2);
+	RTE_ETH_FOREACH_DEV(port_id) {
+		if (rte_eth_devices[port_id].device != &vdev->device)
+			continue;
+		rte_eth_dev_close(port_id);
 	}
 
 	return 0;