DPDK patches and discussions
 help / color / mirror / Atom feed
From: beilei.xing@intel.com
To: jingjing.wu@intel.com
Cc: dev@dpdk.org, Beilei Xing <beilei.xing@intel.com>
Subject: [PATCH v2] common/idpf: move PF specific functions from common init
Date: Tue, 21 Mar 2023 07:07:03 +0000	[thread overview]
Message-ID: <20230321070703.80689-1-beilei.xing@intel.com> (raw)
In-Reply-To: <20230321065316.79549-1-beilei.xing@intel.com>

From: Beilei Xing <beilei.xing@intel.com>

Move PF reset and PF mailbox initialization functions from
idpf_adapter_init function to xxxx_adapter_ext_init function,
since they're different between PF and VF support.

Signed-off-by: Beilei Xing <beilei.xing@intel.com>
---
v2 change:
 - fix typo.

 drivers/common/idpf/idpf_common_device.c | 72 +++++-------------------
 drivers/common/idpf/idpf_common_device.h | 13 +++++
 drivers/common/idpf/version.map          |  5 ++
 drivers/net/cpfl/cpfl_ethdev.c           | 18 ++++++
 drivers/net/idpf/idpf_ethdev.c           | 51 +++++++++++++++++
 5 files changed, 100 insertions(+), 59 deletions(-)

diff --git a/drivers/common/idpf/idpf_common_device.c b/drivers/common/idpf/idpf_common_device.c
index c5e7bbf66c..3b58bdd41e 100644
--- a/drivers/common/idpf/idpf_common_device.c
+++ b/drivers/common/idpf/idpf_common_device.c
@@ -6,8 +6,8 @@
 #include <idpf_common_device.h>
 #include <idpf_common_virtchnl.h>
 
-static void
-idpf_reset_pf(struct idpf_hw *hw)
+void
+idpf_hw_pf_reset(struct idpf_hw *hw)
 {
 	uint32_t reg;
 
@@ -15,9 +15,8 @@ idpf_reset_pf(struct idpf_hw *hw)
 	IDPF_WRITE_REG(hw, PFGEN_CTRL, (reg | PFGEN_CTRL_PFSWR));
 }
 
-#define IDPF_RESET_WAIT_CNT 100
-static int
-idpf_check_pf_reset_done(struct idpf_hw *hw)
+int
+idpf_hw_pf_reset_check(struct idpf_hw *hw)
 {
 	uint32_t reg;
 	int i;
@@ -33,48 +32,13 @@ idpf_check_pf_reset_done(struct idpf_hw *hw)
 	return -EBUSY;
 }
 
-#define CTLQ_NUM 2
-static int
-idpf_init_mbx(struct idpf_hw *hw)
+int
+idpf_hw_mbx_init(struct idpf_hw *hw, struct idpf_ctlq_create_info *ctlq_info)
 {
-	struct idpf_ctlq_create_info ctlq_info[CTLQ_NUM] = {
-		{
-			.type = IDPF_CTLQ_TYPE_MAILBOX_TX,
-			.id = IDPF_CTLQ_ID,
-			.len = IDPF_CTLQ_LEN,
-			.buf_size = IDPF_DFLT_MBX_BUF_SIZE,
-			.reg = {
-				.head = PF_FW_ATQH,
-				.tail = PF_FW_ATQT,
-				.len = PF_FW_ATQLEN,
-				.bah = PF_FW_ATQBAH,
-				.bal = PF_FW_ATQBAL,
-				.len_mask = PF_FW_ATQLEN_ATQLEN_M,
-				.len_ena_mask = PF_FW_ATQLEN_ATQENABLE_M,
-				.head_mask = PF_FW_ATQH_ATQH_M,
-			}
-		},
-		{
-			.type = IDPF_CTLQ_TYPE_MAILBOX_RX,
-			.id = IDPF_CTLQ_ID,
-			.len = IDPF_CTLQ_LEN,
-			.buf_size = IDPF_DFLT_MBX_BUF_SIZE,
-			.reg = {
-				.head = PF_FW_ARQH,
-				.tail = PF_FW_ARQT,
-				.len = PF_FW_ARQLEN,
-				.bah = PF_FW_ARQBAH,
-				.bal = PF_FW_ARQBAL,
-				.len_mask = PF_FW_ARQLEN_ARQLEN_M,
-				.len_ena_mask = PF_FW_ARQLEN_ARQENABLE_M,
-				.head_mask = PF_FW_ARQH_ARQH_M,
-			}
-		}
-	};
 	struct idpf_ctlq_info *ctlq;
 	int ret;
 
-	ret = idpf_ctlq_init(hw, CTLQ_NUM, ctlq_info);
+	ret = idpf_ctlq_init(hw, IDPF_CTLQ_NUM, ctlq_info);
 	if (ret != 0)
 		return ret;
 
@@ -96,6 +60,12 @@ idpf_init_mbx(struct idpf_hw *hw)
 	return ret;
 }
 
+void
+idpf_hw_mbx_deinit(struct idpf_hw *hw)
+{
+	idpf_ctlq_deinit(hw);
+}
+
 static int
 idpf_get_pkt_type(struct idpf_adapter *adapter)
 {
@@ -312,19 +282,6 @@ idpf_adapter_init(struct idpf_adapter *adapter)
 	struct idpf_hw *hw = &adapter->hw;
 	int ret;
 
-	idpf_reset_pf(hw);
-	ret = idpf_check_pf_reset_done(hw);
-	if (ret != 0) {
-		DRV_LOG(ERR, "IDPF is still resetting");
-		goto err_check_reset;
-	}
-
-	ret = idpf_init_mbx(hw);
-	if (ret != 0) {
-		DRV_LOG(ERR, "Failed to init mailbox");
-		goto err_check_reset;
-	}
-
 	adapter->mbx_resp = rte_zmalloc("idpf_adapter_mbx_resp",
 					IDPF_DFLT_MBX_BUF_SIZE, 0);
 	if (adapter->mbx_resp == NULL) {
@@ -357,8 +314,6 @@ idpf_adapter_init(struct idpf_adapter *adapter)
 	rte_free(adapter->mbx_resp);
 	adapter->mbx_resp = NULL;
 err_mbx_resp:
-	idpf_ctlq_deinit(hw);
-err_check_reset:
 	return ret;
 }
 
@@ -367,7 +322,6 @@ idpf_adapter_deinit(struct idpf_adapter *adapter)
 {
 	struct idpf_hw *hw = &adapter->hw;
 
-	idpf_ctlq_deinit(hw);
 	rte_free(adapter->mbx_resp);
 	adapter->mbx_resp = NULL;
 
diff --git a/drivers/common/idpf/idpf_common_device.h b/drivers/common/idpf/idpf_common_device.h
index c2dc2f16b9..ac4afd5ab9 100644
--- a/drivers/common/idpf/idpf_common_device.h
+++ b/drivers/common/idpf/idpf_common_device.h
@@ -10,8 +10,11 @@
 #include <base/virtchnl2.h>
 #include <idpf_common_logs.h>
 
+#define IDPF_RESET_WAIT_CNT	100
+
 #define IDPF_RSS_KEY_LEN	52
 
+#define IDPF_CTLQ_NUM		2
 #define IDPF_CTLQ_ID		-1
 #define IDPF_CTLQ_LEN		64
 #define IDPF_DFLT_MBX_BUF_SIZE	4096
@@ -142,6 +145,8 @@ struct idpf_cmd_info {
 	uint32_t out_size;      /* buffer size for response */
 };
 
+struct idpf_ctlq_create_info ctlq_info[IDPF_CTLQ_NUM];
+
 /* notify current command done. Only call in case execute
  * _atomic_set_cmd successfully.
  */
@@ -180,6 +185,14 @@ atomic_set_cmd(struct idpf_adapter *adapter, uint32_t ops)
 	return !ret;
 }
 
+__rte_internal
+void idpf_hw_pf_reset(struct idpf_hw *hw);
+__rte_internal
+int idpf_hw_pf_reset_check(struct idpf_hw *hw);
+__rte_internal
+int idpf_hw_mbx_init(struct idpf_hw *hw, struct idpf_ctlq_create_info *ctlq_info);
+__rte_internal
+void idpf_hw_mbx_deinit(struct idpf_hw *hw);
 __rte_internal
 int idpf_adapter_init(struct idpf_adapter *adapter);
 __rte_internal
diff --git a/drivers/common/idpf/version.map b/drivers/common/idpf/version.map
index 70334a1b03..7076759024 100644
--- a/drivers/common/idpf/version.map
+++ b/drivers/common/idpf/version.map
@@ -15,6 +15,11 @@ INTERNAL {
 	idpf_dp_splitq_xmit_pkts;
 	idpf_dp_splitq_xmit_pkts_avx512;
 
+	idpf_hw_mbx_deinit;
+	idpf_hw_mbx_init;
+	idpf_hw_pf_reset;
+	idpf_hw_pf_reset_check;
+
 	idpf_qc_rx_thresh_check;
 	idpf_qc_rx_queue_release;
 	idpf_qc_rxq_mbufs_release;
diff --git a/drivers/net/cpfl/cpfl_ethdev.c b/drivers/net/cpfl/cpfl_ethdev.c
index ede730fd50..21505b86f2 100644
--- a/drivers/net/cpfl/cpfl_ethdev.c
+++ b/drivers/net/cpfl/cpfl_ethdev.c
@@ -1165,6 +1165,8 @@ cpfl_dev_alarm_handler(void *param)
 	rte_eal_alarm_set(CPFL_ALARM_INTERVAL, cpfl_dev_alarm_handler, adapter);
 }
 
+extern struct idpf_ctlq_create_info ctlq_info[IDPF_CTLQ_NUM];
+
 static int
 cpfl_adapter_ext_init(struct rte_pci_device *pci_dev, struct cpfl_adapter_ext *adapter)
 {
@@ -1181,6 +1183,19 @@ cpfl_adapter_ext_init(struct rte_pci_device *pci_dev, struct cpfl_adapter_ext *a
 
 	strncpy(adapter->name, pci_dev->device.name, PCI_PRI_STR_SIZE);
 
+	idpf_hw_pf_reset(hw);
+	ret = idpf_hw_pf_reset_check(hw);
+	if (ret != 0) {
+		PMD_INIT_LOG(ERR, "PF is still resetting");
+		goto err_reset_check;
+	}
+
+	ret = idpf_hw_mbx_init(hw, ctlq_info);
+	if (ret != 0) {
+		PMD_INIT_LOG(ERR, "Failed to init mailbox");
+		goto err_reset_check;
+	}
+
 	ret = idpf_adapter_init(base);
 	if (ret != 0) {
 		PMD_INIT_LOG(ERR, "Failed to init adapter");
@@ -1213,6 +1228,8 @@ cpfl_adapter_ext_init(struct rte_pci_device *pci_dev, struct cpfl_adapter_ext *a
 	rte_eal_alarm_cancel(cpfl_dev_alarm_handler, adapter);
 	idpf_adapter_deinit(base);
 err_adapter_init:
+	idpf_hw_mbx_deinit(hw);
+err_reset_check:
 	return ret;
 }
 
@@ -1323,6 +1340,7 @@ cpfl_adapter_ext_deinit(struct cpfl_adapter_ext *adapter)
 {
 	rte_eal_alarm_cancel(cpfl_dev_alarm_handler, adapter);
 	idpf_adapter_deinit(&adapter->base);
+	idpf_hw_mbx_deinit(&adapter->base.hw);
 
 	rte_free(adapter->vports);
 	adapter->vports = NULL;
diff --git a/drivers/net/idpf/idpf_ethdev.c b/drivers/net/idpf/idpf_ethdev.c
index e02ec2ec5a..c23623c5fc 100644
--- a/drivers/net/idpf/idpf_ethdev.c
+++ b/drivers/net/idpf/idpf_ethdev.c
@@ -1128,6 +1128,41 @@ idpf_dev_alarm_handler(void *param)
 	rte_eal_alarm_set(IDPF_ALARM_INTERVAL, idpf_dev_alarm_handler, adapter);
 }
 
+struct idpf_ctlq_create_info ctlq_info[IDPF_CTLQ_NUM] = {
+	{
+		.type = IDPF_CTLQ_TYPE_MAILBOX_TX,
+		.id = IDPF_CTLQ_ID,
+		.len = IDPF_CTLQ_LEN,
+		.buf_size = IDPF_DFLT_MBX_BUF_SIZE,
+		.reg = {
+			.head = PF_FW_ATQH,
+			.tail = PF_FW_ATQT,
+			.len = PF_FW_ATQLEN,
+			.bah = PF_FW_ATQBAH,
+			.bal = PF_FW_ATQBAL,
+			.len_mask = PF_FW_ATQLEN_ATQLEN_M,
+			.len_ena_mask = PF_FW_ATQLEN_ATQENABLE_M,
+			.head_mask = PF_FW_ATQH_ATQH_M,
+		}
+	},
+	{
+		.type = IDPF_CTLQ_TYPE_MAILBOX_RX,
+		.id = IDPF_CTLQ_ID,
+		.len = IDPF_CTLQ_LEN,
+		.buf_size = IDPF_DFLT_MBX_BUF_SIZE,
+		.reg = {
+			.head = PF_FW_ARQH,
+			.tail = PF_FW_ARQT,
+			.len = PF_FW_ARQLEN,
+			.bah = PF_FW_ARQBAH,
+			.bal = PF_FW_ARQBAL,
+			.len_mask = PF_FW_ARQLEN_ARQLEN_M,
+			.len_ena_mask = PF_FW_ARQLEN_ARQENABLE_M,
+			.head_mask = PF_FW_ARQH_ARQH_M,
+		}
+	}
+};
+
 static int
 idpf_adapter_ext_init(struct rte_pci_device *pci_dev, struct idpf_adapter_ext *adapter)
 {
@@ -1144,6 +1179,19 @@ idpf_adapter_ext_init(struct rte_pci_device *pci_dev, struct idpf_adapter_ext *a
 
 	strncpy(adapter->name, pci_dev->device.name, PCI_PRI_STR_SIZE);
 
+	idpf_hw_pf_reset(hw);
+	ret = idpf_hw_pf_reset_check(hw);
+	if (ret != 0) {
+		PMD_INIT_LOG(ERR, "PF is still resetting");
+		goto err_reset_check;
+	}
+
+	ret = idpf_hw_mbx_init(hw, ctlq_info);
+	if (ret != 0) {
+		PMD_INIT_LOG(ERR, "Failed to init mailbox");
+		goto err_reset_check;
+	}
+
 	ret = idpf_adapter_init(base);
 	if (ret != 0) {
 		PMD_INIT_LOG(ERR, "Failed to init adapter");
@@ -1175,6 +1223,8 @@ idpf_adapter_ext_init(struct rte_pci_device *pci_dev, struct idpf_adapter_ext *a
 	rte_eal_alarm_cancel(idpf_dev_alarm_handler, adapter);
 	idpf_adapter_deinit(base);
 err_adapter_init:
+	idpf_hw_mbx_deinit(hw);
+err_reset_check:
 	return ret;
 }
 
@@ -1311,6 +1361,7 @@ idpf_adapter_ext_deinit(struct idpf_adapter_ext *adapter)
 {
 	rte_eal_alarm_cancel(idpf_dev_alarm_handler, adapter);
 	idpf_adapter_deinit(&adapter->base);
+	idpf_hw_mbx_deinit(&adapter->base.hw);
 
 	rte_free(adapter->vports);
 	adapter->vports = NULL;
-- 
2.26.2


  reply	other threads:[~2023-03-21  7:39 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-21  6:53 [PATCH] " beilei.xing
2023-03-21  7:07 ` beilei.xing [this message]
2023-04-04 12:41   ` [PATCH v3 0/2] refine common module beilei.xing
2023-04-04 12:41     ` [PATCH v3 1/2] common/idpf: move PF specific functions from common init beilei.xing
2023-04-04 12:41     ` [PATCH v3 2/2] common/idpf: refine capability get beilei.xing
2023-04-06  7:42     ` [PATCH v4 0/2] refine common module beilei.xing
2023-04-06  7:42       ` [PATCH v4 1/2] common/idpf: move PF specific functions from common init beilei.xing
2023-04-23  8:25         ` Wu, Jingjing
2023-04-06  7:42       ` [PATCH v4 2/2] common/idpf: refine capability get beilei.xing
2023-04-24  8:08       ` [PATCH v5] " beilei.xing
2023-04-26  5:17         ` Wu, Jingjing
2023-04-26  8:11           ` Zhang, Qi Z

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=20230321070703.80689-1-beilei.xing@intel.com \
    --to=beilei.xing@intel.com \
    --cc=dev@dpdk.org \
    --cc=jingjing.wu@intel.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).