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 16/23] net/nfp: support configuration of VF numbers
Date: Wed, 19 Jun 2024 17:58:23 +0800	[thread overview]
Message-ID: <20240619095830.3479757-17-chaoyong.he@corigine.com> (raw)
In-Reply-To: <20240619095830.3479757-1-chaoyong.he@corigine.com>

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

The firmware uses the VF split capacity to identify the
feature of PF can has different number of VFs.
Add the logic to write the VF count and the first VF ID
into firmware, so that the firmware can initialize and
allocate relevant resource accordingly.

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>
---
 drivers/common/nfp/nfp_common_ctrl.h |  11 +++
 drivers/net/nfp/flower/nfp_flower.c  |   6 ++
 drivers/net/nfp/nfp_ethdev.c         |   8 ++
 drivers/net/nfp/nfp_net_common.c     | 125 +++++++++++++++++++++++++++
 drivers/net/nfp/nfp_net_common.h     |   2 +
 5 files changed, 152 insertions(+)

diff --git a/drivers/common/nfp/nfp_common_ctrl.h b/drivers/common/nfp/nfp_common_ctrl.h
index e108720ff6..a52c33508e 100644
--- a/drivers/common/nfp/nfp_common_ctrl.h
+++ b/drivers/common/nfp/nfp_common_ctrl.h
@@ -21,6 +21,16 @@
 #define NFP_NET_VF_CFG_SZ               16
 #define NFP_NET_VF_CFG_MB_SZ            16
 
+/* VF config mailbox */
+#define NFP_NET_VF_CFG_MB               0x0
+#define NFP_NET_VF_CFG_MB_CAP           0x0
+#define   NFP_NET_VF_CFG_MB_CAP_SPLIT             (0x1 << 8)
+#define NFP_NET_VF_CFG_MB_RET           0x2
+#define NFP_NET_VF_CFG_MB_UPD           0x4
+#define   NFP_NET_VF_CFG_MB_UPD_SPLIT             (0x1 << 8)
+#define NFP_NET_VF_CFG_MB_VF_CNT        0x6
+#define NFP_NET_VF_CFG_MB_VF_NUM        0x7
+
 /*
  * @NFP_NET_TXR_MAX:         Maximum number of TX rings
  * @NFP_NET_TXR_MASK:        Mask for TX rings
@@ -89,6 +99,7 @@
 #define   NFP_NET_CFG_UPDATE_VXLAN        (0x1 <<  9) /* VXLAN port change */
 #define   NFP_NET_CFG_UPDATE_MACADDR      (0x1 << 11) /* MAC address change */
 #define   NFP_NET_CFG_UPDATE_MBOX         (0x1 << 12) /* Mailbox update */
+#define   NFP_NET_CFG_UPDATE_VF           (0x1 << 13) /* VF settings change */
 #define   NFP_NET_CFG_UPDATE_ERR          (0x1U << 31) /* A error occurred */
 #define NFP_NET_CFG_TXRS_ENABLE         0x0008
 #define NFP_NET_CFG_RXRS_ENABLE         0x0010
diff --git a/drivers/net/nfp/flower/nfp_flower.c b/drivers/net/nfp/flower/nfp_flower.c
index 602f45d1dd..fa272790bc 100644
--- a/drivers/net/nfp/flower/nfp_flower.c
+++ b/drivers/net/nfp/flower/nfp_flower.c
@@ -724,6 +724,12 @@ nfp_init_app_fw_flower(struct nfp_net_hw_priv *hw_priv)
 		goto pf_cpp_area_cleanup;
 	}
 
+	ret = nfp_net_vf_config_app_init(pf_hw, pf_dev);
+	if (ret != 0) {
+		PMD_INIT_LOG(ERR, "Failed to init sriov module");
+		goto pf_cpp_area_cleanup;
+	}
+
 	nfp_flower_nfd_func_register(app_fw_flower);
 
 	/* The ctrl vNIC struct comes directly after the PF one */
diff --git a/drivers/net/nfp/nfp_ethdev.c b/drivers/net/nfp/nfp_ethdev.c
index dc3890ef53..f9f0884c88 100644
--- a/drivers/net/nfp/nfp_ethdev.c
+++ b/drivers/net/nfp/nfp_ethdev.c
@@ -1030,6 +1030,14 @@ nfp_net_init(struct rte_eth_dev *eth_dev,
 	/* Initializing spinlock for reconfigs */
 	rte_spinlock_init(&hw->reconfig_lock);
 
+	if ((port == 0 || pf_dev->multi_pf.enabled)) {
+		err = nfp_net_vf_config_app_init(net_hw, pf_dev);
+		if (err != 0) {
+			PMD_INIT_LOG(ERR, "Failed to init sriov module");
+			goto xstats_free;
+		}
+	}
+
 	/* 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) {
diff --git a/drivers/net/nfp/nfp_net_common.c b/drivers/net/nfp/nfp_net_common.c
index 0bfe7a514c..e1cae983b2 100644
--- a/drivers/net/nfp/nfp_net_common.c
+++ b/drivers/net/nfp/nfp_net_common.c
@@ -196,6 +196,54 @@ nfp_net_notify_port_speed(struct nfp_net_hw *hw,
 /* The length of firmware version string */
 #define FW_VER_LEN        32
 
+/**
+ * Reconfigure the firmware of VF configure
+ *
+ * @param net_hw
+ *   Device to reconfigure
+ * @param pf_dev
+ *   Get the Device info
+ * @param update
+ *   The value for the mailbox VF command
+ * @param value
+ *   The value of update
+ * @param offset
+ *   The offset in the VF configure table
+ *
+ * @return
+ *   - (0) if OK to reconfigure vf configure.
+ *   - (-EIO) if I/O err and fail to configure the vf configure
+ */
+static int
+nfp_net_vf_reconfig(struct nfp_net_hw *net_hw,
+		struct nfp_pf_dev *pf_dev,
+		uint16_t update,
+		uint8_t value,
+		uint32_t offset)
+{
+	int ret;
+	struct nfp_hw *hw;
+
+	hw = &net_hw->super;
+	rte_spinlock_lock(&hw->reconfig_lock);
+
+	/* Write update info to mailbox in VF config symbol */
+	nn_writeb(value, pf_dev->vf_cfg_tbl_bar + offset);
+	nn_writew(update, pf_dev->vf_cfg_tbl_bar + NFP_NET_VF_CFG_MB_UPD);
+	nn_cfg_writel(hw, NFP_NET_CFG_UPDATE, NFP_NET_CFG_UPDATE_VF);
+
+	rte_wmb();
+
+	ret = nfp_reconfig_real(hw, NFP_NET_CFG_UPDATE_VF);
+
+	rte_spinlock_unlock(&hw->reconfig_lock);
+
+	if (ret != 0)
+		return -EIO;
+
+	return nn_readw(pf_dev->vf_cfg_tbl_bar + NFP_NET_VF_CFG_MB_RET);
+}
+
 /**
  * Reconfigure the firmware via the mailbox
  *
@@ -2574,3 +2622,80 @@ nfp_function_id_get(const struct nfp_pf_dev *pf_dev,
 
 	return port_id;
 }
+
+static int
+nfp_net_sriov_check(struct nfp_pf_dev *pf_dev,
+		uint16_t cap)
+{
+	uint16_t cap_vf;
+
+	cap_vf = nn_readw(pf_dev->vf_cfg_tbl_bar + NFP_NET_VF_CFG_MB_CAP);
+	if ((cap_vf & cap) != cap)
+		return -ENOTSUP;
+
+	return 0;
+}
+
+static int
+nfp_net_sriov_update(struct nfp_net_hw *net_hw,
+		struct nfp_pf_dev *pf_dev,
+		uint16_t update)
+{
+	int ret;
+
+	/* Reuse NFP_NET_VF_CFG_MB_VF_NUM to pass vf_base_id to FW. */
+	ret = nfp_net_vf_reconfig(net_hw, pf_dev, update, pf_dev->vf_base_id,
+			NFP_NET_VF_CFG_MB_VF_NUM);
+	if (ret != 0) {
+		PMD_INIT_LOG(ERR, "Error nfp VF reconfig");
+		return ret;
+	}
+
+	return 0;
+}
+
+static int
+nfp_net_sriov_init(struct nfp_net_hw *net_hw,
+		struct nfp_pf_dev *pf_dev)
+{
+	int ret;
+
+	ret = nfp_net_sriov_check(pf_dev, NFP_NET_VF_CFG_MB_CAP_SPLIT);
+	if (ret != 0) {
+		if (ret == -ENOTSUP) {
+			PMD_INIT_LOG(WARNING, "Set VF split not supported");
+			return 0;
+		}
+
+		PMD_INIT_LOG(ERR, "Set VF split failed");
+		return ret;
+	}
+
+	nn_writeb(pf_dev->sriov_vf, pf_dev->vf_cfg_tbl_bar + NFP_NET_VF_CFG_MB_VF_CNT);
+
+	ret = nfp_net_sriov_update(net_hw, pf_dev, NFP_NET_VF_CFG_MB_UPD_SPLIT);
+	if (ret != 0) {
+		PMD_INIT_LOG(ERR, "The nfp sriov update spilt failed");
+		return ret;
+	}
+
+	return 0;
+}
+
+int
+nfp_net_vf_config_app_init(struct nfp_net_hw *net_hw,
+		struct nfp_pf_dev *pf_dev)
+{
+	int ret;
+
+	if (pf_dev->sriov_vf == 0)
+		return 0;
+
+	ret = nfp_net_sriov_init(net_hw, pf_dev);
+	if (ret != 0) {
+		PMD_INIT_LOG(ERR, "Failed to init sriov module");
+		return ret;
+	}
+
+	return 0;
+}
diff --git a/drivers/net/nfp/nfp_net_common.h b/drivers/net/nfp/nfp_net_common.h
index c4d469599f..4b5029f3f4 100644
--- a/drivers/net/nfp/nfp_net_common.h
+++ b/drivers/net/nfp/nfp_net_common.h
@@ -347,6 +347,8 @@ uint32_t nfp_net_get_port_num(struct nfp_pf_dev *pf_dev,
 		struct nfp_eth_table *nfp_eth_table);
 uint8_t nfp_function_id_get(const struct nfp_pf_dev *pf_dev,
 		uint8_t port_id);
+int nfp_net_vf_config_app_init(struct nfp_net_hw *net_hw,
+		struct nfp_pf_dev *pf_dev);
 
 #define NFP_PRIV_TO_APP_FW_NIC(app_fw_priv)\
 	((struct nfp_app_fw_nic *)app_fw_priv)
-- 
2.39.1


  parent reply	other threads:[~2024-06-19 10:01 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-19  9:58 [PATCH 00/23] support flower firmware with multiple PF Chaoyong He
2024-06-19  9:58 ` [PATCH 01/23] net/nfp: fix dereference of null pointer Chaoyong He
2024-07-07 18:56   ` Ferruh Yigit
2024-07-08  1:35     ` Chaoyong He
2024-06-19  9:58 ` [PATCH 02/23] net/nfp: disable ctrl VNIC queues Chaoyong He
2024-06-19  9:58 ` [PATCH 03/23] net/nfp: fix dereference of null pointer Chaoyong He
2024-06-19  9:58 ` [PATCH 04/23] net/nfp: fix repeat disable the port Chaoyong He
2024-06-19  9:58 ` [PATCH 05/23] net/nfp: fix repeat set the speed configure Chaoyong He
2024-06-19  9:58 ` [PATCH 06/23] net/nfp: make the logic simpler by adding local variable Chaoyong He
2024-06-19  9:58 ` [PATCH 07/23] net/nfp: rename the variable name Chaoyong He
2024-06-19  9:58 ` [PATCH 08/23] net/nfp: export function ID get interface Chaoyong He
2024-06-19  9:58 ` [PATCH 09/23] net/nfp: extract total phyports Chaoyong He
2024-06-19  9:58 ` [PATCH 10/23] net/nfp: extract the initialize helper function Chaoyong He
2024-06-19  9:58 ` [PATCH 11/23] net/nfp: get the VF configuration Chaoyong He
2024-06-19  9:58 ` [PATCH 12/23] net/nfp: refactor the logic of flower service Chaoyong He
2024-06-19  9:58 ` [PATCH 13/23] net/nfp: get the first VF ID of the PF Chaoyong He
2024-06-19  9:58 ` [PATCH 14/23] net/nfp: add the helper function to map rtsym with offset Chaoyong He
2024-06-19  9:58 ` [PATCH 15/23] net/nfp: add the VF table to record the VF information Chaoyong He
2024-06-19  9:58 ` Chaoyong He [this message]
2024-06-19  9:58 ` [PATCH 17/23] net/nfp: configure the VF queue Chaoyong He
2024-06-19  9:58 ` [PATCH 18/23] net/nfp: add check for numbers of VF representor port Chaoyong He
2024-06-19  9:58 ` [PATCH 19/23] net/nfp: add support of ring pop and push Chaoyong He
2024-06-19  9:58 ` [PATCH 20/23] net/nfp: add resource share mode of host context Chaoyong He
2024-06-19  9:58 ` [PATCH 21/23] net/nfp: add resource share mode of mask ID Chaoyong He
2024-06-19  9:58 ` [PATCH 22/23] net/nfp: add device active command for nsp service Chaoyong He
2024-06-19  9:58 ` [PATCH 23/23] net/nfp: add support of flower firmware with multiple PF Chaoyong He
2024-07-07 18:56 ` [PATCH 00/23] support " Ferruh Yigit

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=20240619095830.3479757-17-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).