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 4/9] net/nfp: extract the function to allocate the VF
Date: Mon, 21 Oct 2024 14:32:56 +0800	[thread overview]
Message-ID: <20241021063301.4146214-5-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 allocate the VF representor ports.

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   | 85 +++++++++++--------
 1 file changed, 49 insertions(+), 36 deletions(-)

diff --git a/drivers/net/nfp/flower/nfp_flower_representor.c b/drivers/net/nfp/flower/nfp_flower_representor.c
index 2045076b4b..d49f02fc75 100644
--- a/drivers/net/nfp/flower/nfp_flower_representor.c
+++ b/drivers/net/nfp/flower/nfp_flower_representor.c
@@ -873,6 +873,49 @@ nfp_flower_phy_repr_alloc(struct nfp_net_hw_priv *hw_priv,
 	return 0;
 }
 
+static int
+nfp_flower_vf_repr_alloc(struct nfp_net_hw_priv *hw_priv,
+		struct nfp_flower_representor *flower_repr,
+		const char *pci_name)
+{
+	int i;
+	int ret;
+	struct nfp_pf_dev *pf_dev;
+	struct nfp_repr_init repr_init;
+	struct nfp_app_fw_flower *app_fw_flower;
+
+	pf_dev = hw_priv->pf_dev;
+	repr_init.hw_priv = hw_priv;
+	app_fw_flower = flower_repr->app_fw_flower;
+	for (i = 0; i < app_fw_flower->num_vf_reprs; i++) {
+		flower_repr->repr_type = NFP_REPR_TYPE_VF;
+		flower_repr->port_id = nfp_get_pcie_port_id(pf_dev->cpp,
+				NFP_FLOWER_CMSG_PORT_VNIC_TYPE_VF, i + pf_dev->vf_base_id, 0);
+		flower_repr->nfp_idx = 0;
+		flower_repr->vf_id = i;
+
+		/* VF reprs get a random MAC address */
+		rte_eth_random_addr(flower_repr->mac_addr.addr_bytes);
+		snprintf(flower_repr->name, sizeof(flower_repr->name),
+				"%s_repr_vf%d", pci_name, i);
+
+		repr_init.flower_repr = flower_repr;
+		/* This will also allocate private memory for the device */
+		ret = rte_eth_dev_create(&pf_dev->pci_dev->device, flower_repr->name,
+				sizeof(struct nfp_flower_representor),
+				NULL, NULL, nfp_flower_repr_init, &repr_init);
+		if (ret != 0) {
+			PMD_INIT_LOG(ERR, "Could not create eth_dev for repr.");
+			break;
+		}
+	}
+
+	if (i < app_fw_flower->num_vf_reprs)
+		return -EIO;
+
+	return 0;
+}
+
 static int
 nfp_flower_pf_repr_alloc(struct nfp_net_hw_priv *hw_priv,
 		struct nfp_flower_representor *flower_repr,
@@ -912,30 +955,21 @@ static int
 nfp_flower_repr_alloc(struct nfp_app_fw_flower *app_fw_flower,
 		struct nfp_net_hw_priv *hw_priv)
 {
-	int i;
 	int ret;
 	const char *pci_name;
-	struct nfp_pf_dev *pf_dev;
-	struct rte_pci_device *pci_dev;
-	struct nfp_repr_init repr_init;
 	struct nfp_flower_representor flower_repr = {
 		.switch_domain_id = app_fw_flower->switch_domain_id,
 		.app_fw_flower    = app_fw_flower,
 	};
 
-	pf_dev = hw_priv->pf_dev;
-	repr_init.hw_priv = hw_priv;
-
 	/* Send a NFP_FLOWER_CMSG_TYPE_MAC_REPR cmsg to hardware */
-	ret = nfp_flower_cmsg_mac_repr(app_fw_flower, pf_dev);
+	ret = nfp_flower_cmsg_mac_repr(app_fw_flower, hw_priv->pf_dev);
 	if (ret != 0) {
 		PMD_INIT_LOG(ERR, "Could not send mac repr cmsgs.");
 		return ret;
 	}
 
-	pci_dev = pf_dev->pci_dev;
-
-	pci_name = strchr(pci_dev->name, ':') + 1;
+	pci_name = strchr(hw_priv->pf_dev->pci_dev->name, ':') + 1;
 
 	ret = nfp_flower_pf_repr_alloc(hw_priv, &flower_repr, pci_name);
 	if (ret != 0) {
@@ -954,32 +988,11 @@ nfp_flower_repr_alloc(struct nfp_app_fw_flower *app_fw_flower,
 	 * Now allocate eth_dev's for VF representors.
 	 * Also send reify messages.
 	 */
-	for (i = 0; i < app_fw_flower->num_vf_reprs; i++) {
-		flower_repr.repr_type = NFP_REPR_TYPE_VF;
-		flower_repr.port_id = nfp_get_pcie_port_id(pf_dev->cpp,
-				NFP_FLOWER_CMSG_PORT_VNIC_TYPE_VF, i + pf_dev->vf_base_id, 0);
-		flower_repr.nfp_idx = 0;
-		flower_repr.vf_id = i;
-		flower_repr.idx = 0;
-
-		/* VF reprs get a random MAC address */
-		rte_eth_random_addr(flower_repr.mac_addr.addr_bytes);
-		snprintf(flower_repr.name, sizeof(flower_repr.name),
-				"%s_repr_vf%d", pci_name, i);
-
-		repr_init.flower_repr = &flower_repr;
-		/* This will also allocate private memory for the device */
-		ret = rte_eth_dev_create(&pci_dev->device, flower_repr.name,
-				sizeof(struct nfp_flower_representor),
-				NULL, NULL, nfp_flower_repr_init, &repr_init);
-		if (ret != 0) {
-			PMD_INIT_LOG(ERR, "Could not create eth_dev for repr.");
-			break;
-		}
-	}
-
-	if (i < app_fw_flower->num_vf_reprs)
+	ret = nfp_flower_vf_repr_alloc(hw_priv, &flower_repr, pci_name);
+	if (ret != 0) {
+		PMD_INIT_LOG(ERR, "Failed to init the vf repr.");
 		goto repr_free;
+	}
 
 	nfp_flower_repr_priv_init(app_fw_flower, hw_priv);
 
-- 
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 ` [PATCH 2/9] net/nfp: extract the function to initialize the PF Chaoyong He
2024-10-21  6:32 ` [PATCH 3/9] net/nfp: extract the function to allocate PF Chaoyong He
2024-10-21  6:32 ` Chaoyong He [this message]
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-5-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).