DPDK patches and discussions
 help / color / mirror / Atom feed
From: Chaoyong He <chaoyong.he@corigine.com>
To: dev@dpdk.org
Cc: oss-drivers@corigine.com, Peng Zhang <peng.zhang@corigine.com>,
	Chaoyong He <chaoyong.he@corigine.com>,
	Long Wu <long.wu@corigine.com>
Subject: [PATCH 2/9] net/nfp: extract the function to initialize the PF
Date: Mon, 21 Oct 2024 14:32:54 +0800	[thread overview]
Message-ID: <20241021063301.4146214-3-chaoyong.he@corigine.com> (raw)
In-Reply-To: <20241021063301.4146214-1-chaoyong.he@corigine.com>

From: Peng Zhang <peng.zhang@corigine.com>

Extract the helper function to initialize the basic information
 of the PF representor port.
The logic of check VF is updated because of changing the order
of some logics in the initialization function.

Signed-off-by: Peng Zhang <peng.zhang@corigine.com>
Reviewed-by: Chaoyong He <chaoyong.he@corigine.com>
Reviewed-by: Long Wu <long.wu@corigine.com>
---
 .../net/nfp/flower/nfp_flower_representor.c   | 114 +++++++++++-------
 drivers/net/nfp/nfp_net_common.c              |   2 +-
 2 files changed, 71 insertions(+), 45 deletions(-)

diff --git a/drivers/net/nfp/flower/nfp_flower_representor.c b/drivers/net/nfp/flower/nfp_flower_representor.c
index af5f7fa4af..f76e780840 100644
--- a/drivers/net/nfp/flower/nfp_flower_representor.c
+++ b/drivers/net/nfp/flower/nfp_flower_representor.c
@@ -389,6 +389,12 @@ nfp_flower_repr_close_queue(struct rte_eth_dev *eth_dev,
 	}
 }
 
+static void
+nfp_flower_repr_base_uninit(struct nfp_flower_representor *repr)
+{
+	rte_free(repr->repr_xstats_base);
+}
+
 static int
 nfp_flower_repr_uninit(struct rte_eth_dev *eth_dev)
 {
@@ -396,7 +402,7 @@ nfp_flower_repr_uninit(struct rte_eth_dev *eth_dev)
 	struct nfp_flower_representor *repr;
 
 	repr = eth_dev->data->dev_private;
-	rte_free(repr->repr_xstats_base);
+	nfp_flower_repr_base_uninit(repr);
 	rte_free(repr->ring);
 
 	if (repr->repr_type == NFP_REPR_TYPE_PHYS_PORT) {
@@ -616,6 +622,63 @@ nfp_flower_pf_repr_init(struct rte_eth_dev *eth_dev,
 	return 0;
 }
 
+static int
+nfp_flower_repr_base_init(struct rte_eth_dev *eth_dev,
+		struct nfp_flower_representor *repr,
+		struct nfp_repr_init *repr_init)
+{
+	int ret;
+	struct nfp_flower_representor *init_repr_data;
+
+	/* Cast the input representor data to the correct struct here */
+	init_repr_data = repr_init->flower_repr;
+
+	/* Copy data here from the input representor template */
+	repr->vf_id            = init_repr_data->vf_id;
+	repr->switch_domain_id = init_repr_data->switch_domain_id;
+	repr->port_id          = init_repr_data->port_id;
+	repr->nfp_idx          = init_repr_data->nfp_idx;
+	repr->repr_type        = init_repr_data->repr_type;
+	repr->app_fw_flower    = init_repr_data->app_fw_flower;
+
+	snprintf(repr->name, sizeof(repr->name), "%s", init_repr_data->name);
+
+	/* This backer port is that of the eth_device created for the PF vNIC */
+	eth_dev->data->backer_port_id = 0;
+
+	/* Allocating memory for mac addr */
+	eth_dev->data->mac_addrs = rte_zmalloc("mac_addr", RTE_ETHER_ADDR_LEN, 0);
+	if (eth_dev->data->mac_addrs == NULL) {
+		PMD_INIT_LOG(ERR, "Failed to allocate memory for repr MAC.");
+		return -ENOMEM;
+	}
+
+	rte_ether_addr_copy(&init_repr_data->mac_addr, &repr->mac_addr);
+	rte_ether_addr_copy(&init_repr_data->mac_addr, eth_dev->data->mac_addrs);
+
+	/* Send reify message to hardware to inform it about the new repr */
+	ret = nfp_flower_cmsg_repr_reify(init_repr_data->app_fw_flower, repr);
+	if (ret != 0) {
+		PMD_INIT_LOG(WARNING, "Failed to send repr reify message.");
+		goto mac_cleanup;
+	}
+
+	/* Allocate memory for extended statistics counters */
+	repr->repr_xstats_base = rte_zmalloc("rte_eth_xstat",
+			sizeof(struct rte_eth_xstat) * nfp_net_xstats_size(eth_dev), 0);
+	if (repr->repr_xstats_base == NULL) {
+		PMD_INIT_LOG(ERR, "No memory for xstats base on device %s!", repr->name);
+		ret = -ENOMEM;
+		goto mac_cleanup;
+	}
+
+	return 0;
+
+mac_cleanup:
+	rte_free(eth_dev->data->mac_addrs);
+	return ret;
+}
+
 static int
 nfp_flower_repr_init(struct rte_eth_dev *eth_dev,
 		void *init_params)
@@ -654,50 +717,24 @@ nfp_flower_repr_init(struct rte_eth_dev *eth_dev,
 		return -ENOMEM;
 	}
 
-	/* Copy data here from the input representor template */
-	repr->idx              = init_repr_data->idx;
-	repr->vf_id            = init_repr_data->vf_id;
-	repr->switch_domain_id = init_repr_data->switch_domain_id;
-	repr->port_id          = init_repr_data->port_id;
-	repr->nfp_idx          = init_repr_data->nfp_idx;
-	repr->repr_type        = init_repr_data->repr_type;
-	repr->app_fw_flower    = init_repr_data->app_fw_flower;
-
-	strlcpy(repr->name, init_repr_data->name, sizeof(repr->name));
-
 	eth_dev->dev_ops = &nfp_flower_repr_dev_ops;
 	eth_dev->rx_pkt_burst = nfp_flower_repr_rx_burst;
 	eth_dev->tx_pkt_burst = nfp_flower_repr_tx_burst;
 	eth_dev->data->dev_flags |= RTE_ETH_DEV_REPRESENTOR |
 			RTE_ETH_DEV_AUTOFILL_QUEUE_XSTATS;
 
+	ret = nfp_flower_repr_base_init(eth_dev, repr, repr_init);
+	if (ret != 0) {
+		PMD_DRV_LOG(ERR, "Flower repr base init failed.");
+		goto ring_cleanup;
+	}
+
 	if (repr->repr_type == NFP_REPR_TYPE_PHYS_PORT)
 		eth_dev->data->representor_id = repr->vf_id;
 	else
 		eth_dev->data->representor_id = repr->vf_id +
 				app_fw_flower->num_phyport_reprs + 1;
 
-	/* This backer port is that of the eth_device created for the PF vNIC */
-	eth_dev->data->backer_port_id = 0;
-
-	/* Allocating memory for mac addr */
-	eth_dev->data->mac_addrs = rte_zmalloc("mac_addr", RTE_ETHER_ADDR_LEN, 0);
-	if (eth_dev->data->mac_addrs == NULL) {
-		PMD_INIT_LOG(ERR, "Failed to allocate memory for repr MAC.");
-		ret = -ENOMEM;
-		goto ring_cleanup;
-	}
-
-	rte_ether_addr_copy(&init_repr_data->mac_addr, &repr->mac_addr);
-	rte_ether_addr_copy(&init_repr_data->mac_addr, eth_dev->data->mac_addrs);
-
-	/* Send reify message to hardware to inform it about the new repr */
-	ret = nfp_flower_cmsg_repr_reify(app_fw_flower, repr);
-	if (ret != 0) {
-		PMD_INIT_LOG(WARNING, "Failed to send repr reify message.");
-		goto mac_cleanup;
-	}
-
 	/* Add repr to correct array */
 	if (repr->repr_type == NFP_REPR_TYPE_PHYS_PORT) {
 		index = NFP_FLOWER_CMSG_PORT_PHYS_PORT_NUM(repr->port_id);
@@ -712,19 +749,8 @@ nfp_flower_repr_init(struct rte_eth_dev *eth_dev,
 				(repr->nfp_idx * NFP_MAC_STATS_SIZE);
 	}
 
-	/* Allocate memory for extended statistics counters */
-	repr->repr_xstats_base = rte_zmalloc("rte_eth_xstat",
-			sizeof(struct rte_eth_xstat) * nfp_net_xstats_size(eth_dev), 0);
-	if (repr->repr_xstats_base == NULL) {
-		PMD_INIT_LOG(ERR, "No memory for xstats base on device %s!", repr->name);
-		ret = -ENOMEM;
-		goto mac_cleanup;
-	}
-
 	return 0;
 
-mac_cleanup:
-	rte_free(eth_dev->data->mac_addrs);
 ring_cleanup:
 	rte_free(repr->ring);
 
diff --git a/drivers/net/nfp/nfp_net_common.c b/drivers/net/nfp/nfp_net_common.c
index 766583d597..ccfb4b39f1 100644
--- a/drivers/net/nfp/nfp_net_common.c
+++ b/drivers/net/nfp/nfp_net_common.c
@@ -1039,7 +1039,7 @@ nfp_net_xstats_size(const struct rte_eth_dev *dev)
 
 	if (rte_eth_dev_is_repr(dev)) {
 		repr = dev->data->dev_private;
-		if (repr->mac_stats == NULL)
+		if (nfp_flower_repr_is_vf(repr))
 			vf_flag = true;
 	} else {
 		hw = dev->data->dev_private;
-- 
2.39.1


  parent reply	other threads:[~2024-10-21  6:33 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-21  6:32 [PATCH 0/9] support multiple PF flower firmware Chaoyong He
2024-10-21  6:32 ` [PATCH 1/9] net/nfp: extract the function to allocate the PHY Chaoyong He
2024-10-21  6:32 ` Chaoyong He [this message]
2024-10-21  6:32 ` [PATCH 3/9] net/nfp: extract the function to allocate PF Chaoyong He
2024-10-21  6:32 ` [PATCH 4/9] net/nfp: extract the function to allocate the VF Chaoyong He
2024-10-21  6:32 ` [PATCH 5/9] net/nfp: revise the number of PF representor port Chaoyong He
2024-10-21  6:32 ` [PATCH 6/9] net/nfp: initialize the representor port of the multiple PF Chaoyong He
2024-10-21  6:32 ` [PATCH 7/9] net/nfp: ignore useless message for " Chaoyong He
2024-10-21  6:33 ` [PATCH 8/9] net/nfp: add the new operations " Chaoyong He
2024-10-21  6:33 ` [PATCH 9/9] net/nfp: update the Tx and Rx function " Chaoyong He

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20241021063301.4146214-3-chaoyong.he@corigine.com \
    --to=chaoyong.he@corigine.com \
    --cc=dev@dpdk.org \
    --cc=long.wu@corigine.com \
    --cc=oss-drivers@corigine.com \
    --cc=peng.zhang@corigine.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).