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, Chaoyong He <chaoyong.he@corigine.com>,
	Long Wu <long.wu@corigine.com>
Subject: [PATCH 4/4] net/nfp: support different flow steering rules limit
Date: Tue,  3 Sep 2024 09:41:45 +0800	[thread overview]
Message-ID: <20240903014145.2635710-5-chaoyong.he@corigine.com> (raw)
In-Reply-To: <20240903014145.2635710-1-chaoyong.he@corigine.com>

Get the flow steering rules limit from the firmware rather than
the hard coded.

Signed-off-by: Chaoyong He <chaoyong.he@corigine.com>
Reviewed-by: Long Wu <long.wu@corigine.com>
---
 drivers/common/nfp/nfp_common_ctrl.h |  3 +-
 drivers/net/nfp/nfp_net_common.h     |  4 +--
 drivers/net/nfp/nfp_net_flow.c       | 51 ++++++++++++++++++++++++----
 3 files changed, 47 insertions(+), 11 deletions(-)

diff --git a/drivers/common/nfp/nfp_common_ctrl.h b/drivers/common/nfp/nfp_common_ctrl.h
index 711577dc76..16a18348c6 100644
--- a/drivers/common/nfp/nfp_common_ctrl.h
+++ b/drivers/common/nfp/nfp_common_ctrl.h
@@ -219,8 +219,7 @@ struct nfp_net_fw_ver {
 #define NFP_NET_CFG_CAP_WORD1           0x00a4
 
 /* 16B reserved for future use (0x00b0 - 0x00c0). */
-#define NFP_NET_CFG_RESERVED            0x00b0
-#define NFP_NET_CFG_RESERVED_SZ         0x0010
+#define NFP_NET_CFG_MAX_FS_CAP          0x00b8
 
 /*
  * RSS configuration (0x0100 - 0x01ac):
diff --git a/drivers/net/nfp/nfp_net_common.h b/drivers/net/nfp/nfp_net_common.h
index 2c54815fc9..be5705636f 100644
--- a/drivers/net/nfp/nfp_net_common.h
+++ b/drivers/net/nfp/nfp_net_common.h
@@ -186,13 +186,13 @@ struct nfp_net_flow_count {
 };
 
 #define NFP_NET_HASH_REDUNDANCE (1.2)
-#define NFP_NET_FLOW_HASH_TBALE_SIZE ((NFP_NET_FLOW_LIMIT) * (NFP_NET_HASH_REDUNDANCE))
 
 struct nfp_net_priv {
 	uint32_t hash_seed; /**< Hash seed for hash tables in this structure. */
 	struct rte_hash *flow_table; /**< Hash table to store flow rules. */
 	struct nfp_net_flow_count flow_count; /**< Flow count in hash table */
-	bool flow_position[NFP_NET_FLOW_LIMIT]; /**< Flow position array */
+	uint32_t flow_limit; /**< Flow limit of hash table */
+	bool *flow_position; /**< Flow position array */
 };
 
 struct nfp_app_fw_nic {
diff --git a/drivers/net/nfp/nfp_net_flow.c b/drivers/net/nfp/nfp_net_flow.c
index 2c7801ed41..5db4712193 100644
--- a/drivers/net/nfp/nfp_net_flow.c
+++ b/drivers/net/nfp/nfp_net_flow.c
@@ -88,9 +88,12 @@ nfp_net_flow_position_acquire(struct nfp_net_priv *priv,
 		struct rte_flow *nfp_flow)
 {
 	uint32_t i;
+	uint32_t limit;
+
+	limit = priv->flow_limit;
 
 	if (priority != 0) {
-		i = NFP_NET_FLOW_LIMIT - priority - 1;
+		i = limit - priority - 1;
 
 		if (priv->flow_position[i]) {
 			PMD_DRV_LOG(ERR, "There is already a flow rule in this place.");
@@ -102,19 +105,19 @@ nfp_net_flow_position_acquire(struct nfp_net_priv *priv,
 		return 0;
 	}
 
-	for (i = 0; i < NFP_NET_FLOW_LIMIT; i++) {
+	for (i = 0; i < limit; i++) {
 		if (!priv->flow_position[i]) {
 			priv->flow_position[i] = true;
 			break;
 		}
 	}
 
-	if (i == NFP_NET_FLOW_LIMIT) {
+	if (i == limit) {
 		PMD_DRV_LOG(ERR, "The limited flow number is reach.");
 		return -ERANGE;
 	}
 
-	nfp_flow->position = NFP_NET_FLOW_LIMIT - i - 1;
+	nfp_flow->position = limit - i - 1;
 
 	return 0;
 }
@@ -1053,11 +1056,24 @@ nfp_net_flow_ops_get(struct rte_eth_dev *dev,
 	return 0;
 }
 
+static uint32_t
+nfp_net_fs_max_entry_get(struct nfp_hw *hw)
+{
+	uint32_t cnt;
+
+	cnt = nn_cfg_readl(hw, NFP_NET_CFG_MAX_FS_CAP);
+	if (cnt != 0)
+		return cnt;
+
+	return NFP_NET_FLOW_LIMIT;
+}
+
 int
 nfp_net_flow_priv_init(struct nfp_pf_dev *pf_dev,
 		uint16_t port)
 {
 	int ret = 0;
+	struct nfp_hw *hw;
 	struct nfp_net_priv *priv;
 	char flow_name[RTE_HASH_NAMESIZE];
 	struct nfp_app_fw_nic *app_fw_nic;
@@ -1067,7 +1083,6 @@ nfp_net_flow_priv_init(struct nfp_pf_dev *pf_dev,
 
 	struct rte_hash_parameters flow_hash_params = {
 		.name       = flow_name,
-		.entries    = NFP_NET_FLOW_HASH_TBALE_SIZE,
 		.hash_func  = rte_jhash,
 		.socket_id  = rte_socket_id(),
 		.key_len    = sizeof(uint32_t),
@@ -1085,17 +1100,37 @@ nfp_net_flow_priv_init(struct nfp_pf_dev *pf_dev,
 	app_fw_nic->ports[port]->priv = priv;
 	priv->hash_seed = (uint32_t)rte_rand();
 
+	/* Flow limit */
+	hw = &app_fw_nic->ports[port]->super;
+	priv->flow_limit = nfp_net_fs_max_entry_get(hw);
+	if (priv->flow_limit == 0) {
+		PMD_INIT_LOG(ERR, "NFP app nic flow limit not right.");
+		ret = -EINVAL;
+		goto free_priv;
+	}
+
+	/* Flow position array */
+	priv->flow_position = rte_zmalloc(NULL, sizeof(bool) * priv->flow_limit, 0);
+	if (priv->flow_position == NULL) {
+		PMD_INIT_LOG(ERR, "NFP app nic flow position creation failed.");
+		ret = -ENOMEM;
+		goto free_priv;
+	}
+
 	/* Flow table */
 	flow_hash_params.hash_func_init_val = priv->hash_seed;
+	flow_hash_params.entries = priv->flow_limit * NFP_NET_HASH_REDUNDANCE;
 	priv->flow_table = rte_hash_create(&flow_hash_params);
 	if (priv->flow_table == NULL) {
 		PMD_INIT_LOG(ERR, "flow hash table creation failed");
 		ret = -ENOMEM;
-		goto free_priv;
+		goto free_flow_position;
 	}
 
 	return 0;
 
+free_flow_position:
+	rte_free(priv->flow_position);
 free_priv:
 	rte_free(priv);
 exit:
@@ -1114,8 +1149,10 @@ nfp_net_flow_priv_uninit(struct nfp_pf_dev *pf_dev,
 
 	app_fw_nic = NFP_PRIV_TO_APP_FW_NIC(pf_dev->app_fw_priv);
 	priv = app_fw_nic->ports[port]->priv;
-	if (priv != NULL)
+	if (priv != NULL) {
 		rte_hash_free(priv->flow_table);
+		rte_free(priv->flow_position);
+	}
 
 	rte_free(priv);
 }
-- 
2.39.1


  parent reply	other threads:[~2024-09-03  1:42 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-03  1:41 [PATCH 0/4] Support new card using NFP 3800 chip Chaoyong He
2024-09-03  1:41 ` [PATCH 1/4] net/nfp: add a new flag to indicate PF Chaoyong He
2024-09-03  1:41 ` [PATCH 2/4] net/nfp: refactor the firmware version logic Chaoyong He
2024-09-03  1:41 ` [PATCH 3/4] net/nfp: support different configuration BAR size Chaoyong He
2024-09-03  1:41 ` Chaoyong He [this message]
2024-10-04  4:26 ` [PATCH 0/4] Support new card using NFP 3800 chip 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=20240903014145.2635710-5-chaoyong.he@corigine.com \
    --to=chaoyong.he@corigine.com \
    --cc=dev@dpdk.org \
    --cc=long.wu@corigine.com \
    --cc=oss-drivers@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).