DPDK patches and discussions
 help / color / mirror / Atom feed
From: beilei.xing@intel.com
To: jingjing.wu@intel.com
Cc: dev@dpdk.org, qi.z.zhang@intel.com,
	Beilei Xing <beilei.xing@intel.com>,
	Wenjun Wu <wenjun1.wu@intel.com>
Subject: [PATCH v3 04/15] common/idpf: introduce adapter init and deinit
Date: Tue, 17 Jan 2023 07:26:12 +0000	[thread overview]
Message-ID: <20230117072626.93796-6-beilei.xing@intel.com> (raw)
In-Reply-To: <20230117072626.93796-1-beilei.xing@intel.com>

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

Introduce idpf_adapter_init and idpf_adapter_deinit
functions in common module.
And also introduce idpf_adapter_ext_init and
idpf_adapter_ext_deinit functions.

Signed-off-by: Wenjun Wu <wenjun1.wu@intel.com>
Signed-off-by: Beilei Xing <beilei.xing@intel.com>
---
 drivers/common/idpf/idpf_common_device.c | 153 ++++++++++++++++++++++
 drivers/common/idpf/idpf_common_device.h |   6 +
 drivers/common/idpf/version.map          |   2 +
 drivers/net/idpf/idpf_ethdev.c           | 158 +++--------------------
 drivers/net/idpf/idpf_ethdev.h           |   2 -
 5 files changed, 178 insertions(+), 143 deletions(-)

diff --git a/drivers/common/idpf/idpf_common_device.c b/drivers/common/idpf/idpf_common_device.c
index 5062780362..b2b42443e4 100644
--- a/drivers/common/idpf/idpf_common_device.c
+++ b/drivers/common/idpf/idpf_common_device.c
@@ -4,5 +4,158 @@
 
 #include <rte_log.h>
 #include <idpf_common_device.h>
+#include <idpf_common_virtchnl.h>
+
+static void
+idpf_reset_pf(struct idpf_hw *hw)
+{
+	uint32_t reg;
+
+	reg = IDPF_READ_REG(hw, PFGEN_CTRL);
+	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)
+{
+	uint32_t reg;
+	int i;
+
+	for (i = 0; i < IDPF_RESET_WAIT_CNT; i++) {
+		reg = IDPF_READ_REG(hw, PFGEN_RSTAT);
+		if (reg != 0xFFFFFFFF && (reg & PFGEN_RSTAT_PFR_STATE_M))
+			return 0;
+		rte_delay_ms(1000);
+	}
+
+	DRV_LOG(ERR, "IDPF reset timeout");
+	return -EBUSY;
+}
+
+#define CTLQ_NUM 2
+static int
+idpf_init_mbx(struct idpf_hw *hw)
+{
+	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);
+	if (ret != 0)
+		return ret;
+
+	LIST_FOR_EACH_ENTRY_SAFE(ctlq, NULL, &hw->cq_list_head,
+				 struct idpf_ctlq_info, cq_list) {
+		if (ctlq->q_id == IDPF_CTLQ_ID &&
+		    ctlq->cq_type == IDPF_CTLQ_TYPE_MAILBOX_TX)
+			hw->asq = ctlq;
+		if (ctlq->q_id == IDPF_CTLQ_ID &&
+		    ctlq->cq_type == IDPF_CTLQ_TYPE_MAILBOX_RX)
+			hw->arq = ctlq;
+	}
+
+	if (hw->asq == NULL || hw->arq == NULL) {
+		idpf_ctlq_deinit(hw);
+		ret = -ENOENT;
+	}
+
+	return ret;
+}
+
+int
+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) {
+		DRV_LOG(ERR, "Failed to allocate idpf_adapter_mbx_resp memory");
+		ret = -ENOMEM;
+		goto err_mbx_resp;
+	}
+
+	ret = idpf_vc_check_api_version(adapter);
+	if (ret != 0) {
+		DRV_LOG(ERR, "Failed to check api version");
+		goto err_check_api;
+	}
+
+	ret = idpf_vc_get_caps(adapter);
+	if (ret != 0) {
+		DRV_LOG(ERR, "Failed to get capabilities");
+		goto err_check_api;
+	}
+
+	return 0;
+
+err_check_api:
+	rte_free(adapter->mbx_resp);
+	adapter->mbx_resp = NULL;
+err_mbx_resp:
+	idpf_ctlq_deinit(hw);
+err_check_reset:
+	return ret;
+}
+
+int
+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;
+
+	return 0;
+}
 
 RTE_LOG_REGISTER_SUFFIX(idpf_common_logtype, common, NOTICE);
diff --git a/drivers/common/idpf/idpf_common_device.h b/drivers/common/idpf/idpf_common_device.h
index a7537281d1..e4344ea392 100644
--- a/drivers/common/idpf/idpf_common_device.h
+++ b/drivers/common/idpf/idpf_common_device.h
@@ -9,6 +9,7 @@
 #include <base/virtchnl2.h>
 #include <idpf_common_logs.h>
 
+#define IDPF_CTLQ_ID		-1
 #define IDPF_CTLQ_LEN		64
 #define IDPF_DFLT_MBX_BUF_SIZE	4096
 
@@ -137,4 +138,9 @@ atomic_set_cmd(struct idpf_adapter *adapter, uint32_t ops)
 	return !ret;
 }
 
+__rte_internal
+int idpf_adapter_init(struct idpf_adapter *adapter);
+__rte_internal
+int idpf_adapter_deinit(struct idpf_adapter *adapter);
+
 #endif /* _IDPF_COMMON_DEVICE_H_ */
diff --git a/drivers/common/idpf/version.map b/drivers/common/idpf/version.map
index a2b8780780..7259dcf8a4 100644
--- a/drivers/common/idpf/version.map
+++ b/drivers/common/idpf/version.map
@@ -1,6 +1,8 @@
 INTERNAL {
 	global:
 
+	idpf_adapter_deinit;
+	idpf_adapter_init;
 	idpf_ctlq_clean_sq;
 	idpf_ctlq_deinit;
 	idpf_ctlq_init;
diff --git a/drivers/net/idpf/idpf_ethdev.c b/drivers/net/idpf/idpf_ethdev.c
index 759fc981d7..c17c7bb472 100644
--- a/drivers/net/idpf/idpf_ethdev.c
+++ b/drivers/net/idpf/idpf_ethdev.c
@@ -786,148 +786,32 @@ idpf_parse_devargs(struct rte_pci_device *pci_dev, struct idpf_adapter_ext *adap
 	return ret;
 }
 
-static void
-idpf_reset_pf(struct idpf_hw *hw)
-{
-	uint32_t reg;
-
-	reg = IDPF_READ_REG(hw, PFGEN_CTRL);
-	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)
+idpf_adapter_ext_init(struct rte_pci_device *pci_dev, struct idpf_adapter_ext *adapter)
 {
-	uint32_t reg;
-	int i;
-
-	for (i = 0; i < IDPF_RESET_WAIT_CNT; i++) {
-		reg = IDPF_READ_REG(hw, PFGEN_RSTAT);
-		if (reg != 0xFFFFFFFF && (reg & PFGEN_RSTAT_PFR_STATE_M))
-			return 0;
-		rte_delay_ms(1000);
-	}
-
-	PMD_INIT_LOG(ERR, "IDPF reset timeout");
-	return -EBUSY;
-}
-
-#define CTLQ_NUM 2
-static int
-idpf_init_mbx(struct idpf_hw *hw)
-{
-	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);
-	if (ret != 0)
-		return ret;
-
-	LIST_FOR_EACH_ENTRY_SAFE(ctlq, NULL, &hw->cq_list_head,
-				 struct idpf_ctlq_info, cq_list) {
-		if (ctlq->q_id == IDPF_CTLQ_ID &&
-		    ctlq->cq_type == IDPF_CTLQ_TYPE_MAILBOX_TX)
-			hw->asq = ctlq;
-		if (ctlq->q_id == IDPF_CTLQ_ID &&
-		    ctlq->cq_type == IDPF_CTLQ_TYPE_MAILBOX_RX)
-			hw->arq = ctlq;
-	}
-
-	if (hw->asq == NULL || hw->arq == NULL) {
-		idpf_ctlq_deinit(hw);
-		ret = -ENOENT;
-	}
-
-	return ret;
-}
-
-static int
-idpf_adapter_init(struct rte_pci_device *pci_dev, struct idpf_adapter_ext *adapter)
-{
-	struct idpf_hw *hw = &adapter->base.hw;
+	struct idpf_adapter *base = &adapter->base;
+	struct idpf_hw *hw = &base->hw;
 	int ret = 0;
 
 	hw->hw_addr = (void *)pci_dev->mem_resource[0].addr;
 	hw->hw_addr_len = pci_dev->mem_resource[0].len;
-	hw->back = &adapter->base;
+	hw->back = base;
 	hw->vendor_id = pci_dev->id.vendor_id;
 	hw->device_id = pci_dev->id.device_id;
 	hw->subsystem_vendor_id = pci_dev->id.subsystem_vendor_id;
 
 	strncpy(adapter->name, pci_dev->device.name, PCI_PRI_STR_SIZE);
 
-	idpf_reset_pf(hw);
-	ret = idpf_check_pf_reset_done(hw);
-	if (ret != 0) {
-		PMD_INIT_LOG(ERR, "IDPF is still resetting");
-		goto err;
-	}
-
-	ret = idpf_init_mbx(hw);
-	if (ret != 0) {
-		PMD_INIT_LOG(ERR, "Failed to init mailbox");
-		goto err;
-	}
-
-	adapter->base.mbx_resp = rte_zmalloc("idpf_adapter_mbx_resp",
-					     IDPF_DFLT_MBX_BUF_SIZE, 0);
-	if (adapter->base.mbx_resp == NULL) {
-		PMD_INIT_LOG(ERR, "Failed to allocate idpf_adapter_mbx_resp memory");
-		ret = -ENOMEM;
-		goto err_mbx;
-	}
-
-	ret = idpf_vc_check_api_version(&adapter->base);
+	ret = idpf_adapter_init(base);
 	if (ret != 0) {
-		PMD_INIT_LOG(ERR, "Failed to check api version");
-		goto err_api;
+		PMD_INIT_LOG(ERR, "Failed to init adapter");
+		goto err_adapter_init;
 	}
 
 	ret = idpf_get_pkt_type(adapter);
 	if (ret != 0) {
 		PMD_INIT_LOG(ERR, "Failed to set ptype table");
-		goto err_api;
-	}
-
-	ret = idpf_vc_get_caps(&adapter->base);
-	if (ret != 0) {
-		PMD_INIT_LOG(ERR, "Failed to get capabilities");
-		goto err_api;
+		goto err_get_ptype;
 	}
 
 	adapter->max_vport_nb = adapter->base.caps.max_vports;
@@ -939,7 +823,7 @@ idpf_adapter_init(struct rte_pci_device *pci_dev, struct idpf_adapter_ext *adapt
 	if (adapter->vports == NULL) {
 		PMD_INIT_LOG(ERR, "Failed to allocate vports memory");
 		ret = -ENOMEM;
-		goto err_api;
+		goto err_get_ptype;
 	}
 
 	adapter->cur_vports = 0;
@@ -949,12 +833,9 @@ idpf_adapter_init(struct rte_pci_device *pci_dev, struct idpf_adapter_ext *adapt
 
 	return ret;
 
-err_api:
-	rte_free(adapter->base.mbx_resp);
-	adapter->base.mbx_resp = NULL;
-err_mbx:
-	idpf_ctlq_deinit(hw);
-err:
+err_get_ptype:
+	idpf_adapter_deinit(base);
+err_adapter_init:
 	return ret;
 }
 
@@ -1093,14 +974,9 @@ idpf_find_adapter_ext(struct rte_pci_device *pci_dev)
 }
 
 static void
-idpf_adapter_rel(struct idpf_adapter_ext *adapter)
+idpf_adapter_ext_deinit(struct idpf_adapter_ext *adapter)
 {
-	struct idpf_hw *hw = &adapter->base.hw;
-
-	idpf_ctlq_deinit(hw);
-
-	rte_free(adapter->base.mbx_resp);
-	adapter->base.mbx_resp = NULL;
+	idpf_adapter_deinit(&adapter->base);
 
 	rte_free(adapter->vports);
 	adapter->vports = NULL;
@@ -1133,7 +1009,7 @@ idpf_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
 			return -ENOMEM;
 		}
 
-		retval = idpf_adapter_init(pci_dev, adapter);
+		retval = idpf_adapter_ext_init(pci_dev, adapter);
 		if (retval != 0) {
 			PMD_INIT_LOG(ERR, "Failed to init adapter.");
 			return retval;
@@ -1196,7 +1072,7 @@ idpf_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
 		rte_spinlock_lock(&idpf_adapter_lock);
 		TAILQ_REMOVE(&idpf_adapter_list, adapter, next);
 		rte_spinlock_unlock(&idpf_adapter_lock);
-		idpf_adapter_rel(adapter);
+		idpf_adapter_ext_deinit(adapter);
 		rte_free(adapter);
 	}
 	return retval;
@@ -1216,7 +1092,7 @@ idpf_pci_remove(struct rte_pci_device *pci_dev)
 	rte_spinlock_lock(&idpf_adapter_lock);
 	TAILQ_REMOVE(&idpf_adapter_list, adapter, next);
 	rte_spinlock_unlock(&idpf_adapter_lock);
-	idpf_adapter_rel(adapter);
+	idpf_adapter_ext_deinit(adapter);
 	rte_free(adapter);
 
 	return 0;
diff --git a/drivers/net/idpf/idpf_ethdev.h b/drivers/net/idpf/idpf_ethdev.h
index efc540fa32..07ffe8e408 100644
--- a/drivers/net/idpf/idpf_ethdev.h
+++ b/drivers/net/idpf/idpf_ethdev.h
@@ -31,8 +31,6 @@
 #define IDPF_RXQ_PER_GRP	1
 #define IDPF_RX_BUFQ_PER_GRP	2
 
-#define IDPF_CTLQ_ID		-1
-
 #define IDPF_DFLT_Q_VEC_NUM	1
 #define IDPF_DFLT_INTERVAL	16
 
-- 
2.26.2


  parent reply	other threads:[~2023-01-17  7:51 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <https://patches.dpdk.org/project/dpdk/cover/20230106091627.13530-1-beilei.xing@intel.com/>
2023-01-17  7:26 ` [PATCH v3 00/15] net/idpf: introduce idpf common modle beilei.xing
2023-01-17  7:26   ` [PATCH v3 01/15] common/idpf: add adapter structure beilei.xing
2023-01-17  7:26   ` [PATCH v3 02/15] common/idpf: add vport structure beilei.xing
2023-01-17  7:26   ` [PATCH v3 03/15] common/idpf: add virtual channel functions beilei.xing
2023-01-17  7:26   ` [PATCH 03/15] common/idpf: move vc functions to common module beilei.xing
2023-01-17  7:26   ` beilei.xing [this message]
2023-01-17  7:26   ` [PATCH v3 05/15] common/idpf: add vport init/deinit beilei.xing
2023-01-17  7:26   ` [PATCH v3 06/15] common/idpf: add config RSS beilei.xing
2023-01-17  7:26   ` [PATCH v3 07/15] common/idpf: add irq map/unmap beilei.xing
2023-01-17  7:26   ` [PATCH 08/15] common/idpf: move ptype table to adapter structure beilei.xing
2023-01-17  7:26   ` [PATCH v3 08/15] common/idpf: support get packet type beilei.xing
2023-01-17  7:26   ` [PATCH v3 09/15] common/idpf: add vport info initialization beilei.xing
2023-01-17  7:26   ` [PATCH 09/15] common/idpf: init create vport info beilei.xing
2023-01-17  7:26   ` [PATCH v3 10/15] common/idpf: add vector flags in vport beilei.xing
2023-01-17  7:26   ` [PATCH v3 11/15] common/idpf: add rxq and txq struct beilei.xing
2023-01-17  7:26   ` [PATCH v3 12/15] common/idpf: add help functions for queue setup and release beilei.xing
2023-01-17  7:26   ` [PATCH v3 13/15] common/idpf: add Rx and Tx data path beilei.xing
2023-01-17  7:26   ` [PATCH 13/15] common/idpf: add scalar " beilei.xing
2023-01-17  7:26   ` [PATCH v3 14/15] common/idpf: add vec queue setup beilei.xing
2023-01-17  7:26   ` [PATCH v3 15/15] common/idpf: add avx512 for single queue model beilei.xing

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=20230117072626.93796-6-beilei.xing@intel.com \
    --to=beilei.xing@intel.com \
    --cc=dev@dpdk.org \
    --cc=jingjing.wu@intel.com \
    --cc=qi.z.zhang@intel.com \
    --cc=wenjun1.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).