DPDK patches and discussions
 help / color / mirror / Atom feed
From: beilei.xing@intel.com
To: jingjing.wu@intel.com, qi.z.zhang@intel.com
Cc: dev@dpdk.org, Beilei Xing <beilei.xing@intel.com>
Subject: [PATCH 07/15] common/idpf: add irq map/unmap
Date: Thu,  8 Dec 2022 07:53:01 +0000	[thread overview]
Message-ID: <20221208075309.37852-8-beilei.xing@intel.com> (raw)
In-Reply-To: <20221208075309.37852-1-beilei.xing@intel.com>

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

Add irq map/unmap functions in common module.

Signed-off-by: Beilei Xing <beilei.xing@intel.com>
---
 drivers/common/idpf/idpf_common_device.c   | 110 +++++++++++++++++++++
 drivers/common/idpf/idpf_common_device.h   |   6 ++
 drivers/common/idpf/idpf_common_virtchnl.c |   8 --
 drivers/common/idpf/idpf_common_virtchnl.h |   5 +-
 drivers/common/idpf/version.map            |   3 +-
 drivers/net/idpf/idpf_ethdev.c             |  90 +----------------
 drivers/net/idpf/idpf_ethdev.h             |   1 -
 7 files changed, 124 insertions(+), 99 deletions(-)

diff --git a/drivers/common/idpf/idpf_common_device.c b/drivers/common/idpf/idpf_common_device.c
index 19d638824d..58a7f4cee3 100644
--- a/drivers/common/idpf/idpf_common_device.c
+++ b/drivers/common/idpf/idpf_common_device.c
@@ -254,8 +254,21 @@ idpf_vport_init(struct idpf_vport *vport,
 		goto err_rss_lut;
 	}
 
+	/* recv_vectors is used for VIRTCHNL2_OP_ALLOC_VECTORS response,
+	 * reserve maximum size for it now, may need optimization in future.
+	 */
+	vport->recv_vectors = rte_zmalloc("recv_vectors", IDPF_DFLT_MBX_BUF_SIZE, 0);
+	if (vport->recv_vectors == NULL) {
+		DRV_LOG(ERR, "Failed to allocate ecv_vectors");
+		ret = -ENOMEM;
+		goto err_recv_vec;
+	}
+
 	return 0;
 
+err_recv_vec:
+	rte_free(vport->rss_lut);
+	vport->rss_lut = NULL;
 err_rss_lut:
 	vport->dev_data = NULL;
 	rte_free(vport->rss_key);
@@ -271,6 +284,8 @@ idpf_vport_init(struct idpf_vport *vport,
 int
 idpf_vport_deinit(struct idpf_vport *vport)
 {
+	rte_free(vport->recv_vectors);
+	vport->recv_vectors = NULL;
 	rte_free(vport->rss_lut);
 	vport->rss_lut = NULL;
 
@@ -311,4 +326,99 @@ idpf_config_rss(struct idpf_vport *vport)
 
 	return ret;
 }
+
+int
+idpf_config_irq_map(struct idpf_vport *vport, uint16_t nb_rx_queues)
+{
+	struct idpf_adapter *adapter = vport->adapter;
+	struct virtchnl2_queue_vector *qv_map;
+	struct idpf_hw *hw = &adapter->hw;
+	uint32_t dynctl_val, itrn_val;
+	uint32_t dynctl_reg_start;
+	uint32_t itrn_reg_start;
+	uint16_t i;
+
+	qv_map = rte_zmalloc("qv_map",
+			     nb_rx_queues *
+			     sizeof(struct virtchnl2_queue_vector), 0);
+	if (qv_map == NULL) {
+		DRV_LOG(ERR, "Failed to allocate %d queue-vector map",
+			nb_rx_queues);
+		goto qv_map_alloc_err;
+	}
+
+	/* Rx interrupt disabled, Map interrupt only for writeback */
+
+	/* The capability flags adapter->caps.other_caps should be
+	 * compared with bit VIRTCHNL2_CAP_WB_ON_ITR here. The if
+	 * condition should be updated when the FW can return the
+	 * correct flag bits.
+	 */
+	dynctl_reg_start =
+		vport->recv_vectors->vchunks.vchunks->dynctl_reg_start;
+	itrn_reg_start =
+		vport->recv_vectors->vchunks.vchunks->itrn_reg_start;
+	dynctl_val = IDPF_READ_REG(hw, dynctl_reg_start);
+	DRV_LOG(DEBUG, "Value of dynctl_reg_start is 0x%x",
+		dynctl_val);
+	itrn_val = IDPF_READ_REG(hw, itrn_reg_start);
+	DRV_LOG(DEBUG, "Value of itrn_reg_start is 0x%x", itrn_val);
+	/* Force write-backs by setting WB_ON_ITR bit in DYN_CTL
+	 * register. WB_ON_ITR and INTENA are mutually exclusive
+	 * bits. Setting WB_ON_ITR bits means TX and RX Descs
+	 * are written back based on ITR expiration irrespective
+	 * of INTENA setting.
+	 */
+	/* TBD: need to tune INTERVAL value for better performance. */
+	if (itrn_val != 0)
+		IDPF_WRITE_REG(hw,
+			       dynctl_reg_start,
+			       VIRTCHNL2_ITR_IDX_0  <<
+			       PF_GLINT_DYN_CTL_ITR_INDX_S |
+			       PF_GLINT_DYN_CTL_WB_ON_ITR_M |
+			       itrn_val <<
+			       PF_GLINT_DYN_CTL_INTERVAL_S);
+	else
+		IDPF_WRITE_REG(hw,
+			       dynctl_reg_start,
+			       VIRTCHNL2_ITR_IDX_0  <<
+			       PF_GLINT_DYN_CTL_ITR_INDX_S |
+			       PF_GLINT_DYN_CTL_WB_ON_ITR_M |
+			       IDPF_DFLT_INTERVAL <<
+			       PF_GLINT_DYN_CTL_INTERVAL_S);
+
+	for (i = 0; i < nb_rx_queues; i++) {
+		/* map all queues to the same vector */
+		qv_map[i].queue_id = vport->chunks_info.rx_start_qid + i;
+		qv_map[i].vector_id =
+			vport->recv_vectors->vchunks.vchunks->start_vector_id;
+	}
+	vport->qv_map = qv_map;
+
+	if (idpf_vc_config_irq_map_unmap(vport, nb_rx_queues, true) != 0) {
+		DRV_LOG(ERR, "config interrupt mapping failed");
+		goto config_irq_map_err;
+	}
+
+	return 0;
+
+config_irq_map_err:
+	rte_free(vport->qv_map);
+	vport->qv_map = NULL;
+
+qv_map_alloc_err:
+	return -1;
+}
+
+int
+idpf_config_irq_unmap(struct idpf_vport *vport, uint16_t nb_rx_queues)
+{
+	idpf_vc_config_irq_map_unmap(vport, nb_rx_queues, false);
+
+	rte_free(vport->qv_map);
+	vport->qv_map = 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 026d852de4..43d0380395 100644
--- a/drivers/common/idpf/idpf_common_device.h
+++ b/drivers/common/idpf/idpf_common_device.h
@@ -17,6 +17,8 @@
 
 #define IDPF_MAX_PKT_TYPE	1024
 
+#define IDPF_DFLT_INTERVAL	16
+
 struct idpf_adapter {
 	struct idpf_hw hw;
 	struct virtchnl2_version_info virtchnl_version;
@@ -152,5 +154,9 @@ __rte_internal
 int idpf_vport_deinit(struct idpf_vport *vport);
 __rte_internal
 int idpf_config_rss(struct idpf_vport *vport);
+__rte_internal
+int idpf_config_irq_map(struct idpf_vport *vport, uint16_t nb_rx_queues);
+__rte_internal
+int idpf_config_irq_unmap(struct idpf_vport *vport, uint16_t nb_rx_queues);
 
 #endif /* _IDPF_COMMON_DEVICE_H_ */
diff --git a/drivers/common/idpf/idpf_common_virtchnl.c b/drivers/common/idpf/idpf_common_virtchnl.c
index e7ba32c532..c5b68e8968 100644
--- a/drivers/common/idpf/idpf_common_virtchnl.c
+++ b/drivers/common/idpf/idpf_common_virtchnl.c
@@ -573,14 +573,6 @@ idpf_vc_alloc_vectors(struct idpf_vport *vport, uint16_t num_vectors)
 	if (err != 0)
 		DRV_LOG(ERR, "Failed to execute command VIRTCHNL2_OP_ALLOC_VECTORS");
 
-	if (vport->recv_vectors == NULL) {
-		vport->recv_vectors = rte_zmalloc("recv_vectors", len, 0);
-		if (vport->recv_vectors == NULL) {
-			rte_free(alloc_vec);
-			return -ENOMEM;
-		}
-	}
-
 	rte_memcpy(vport->recv_vectors, args.out_buffer, len);
 	rte_free(alloc_vec);
 	return err;
diff --git a/drivers/common/idpf/idpf_common_virtchnl.h b/drivers/common/idpf/idpf_common_virtchnl.h
index 182a6a4490..035be095e5 100644
--- a/drivers/common/idpf/idpf_common_virtchnl.h
+++ b/drivers/common/idpf/idpf_common_virtchnl.h
@@ -15,6 +15,8 @@ int idpf_vc_destroy_vport(struct idpf_vport *vport);
 int idpf_vc_set_rss_key(struct idpf_vport *vport);
 int idpf_vc_set_rss_lut(struct idpf_vport *vport);
 int idpf_vc_set_rss_hash(struct idpf_vport *vport);
+int idpf_vc_config_irq_map_unmap(struct idpf_vport *vport,
+				 uint16_t nb_rxq, bool map);
 __rte_internal
 int idpf_switch_queue(struct idpf_vport *vport, uint16_t qid,
 		      bool rx, bool on);
@@ -23,9 +25,6 @@ int idpf_vc_ena_dis_queues(struct idpf_vport *vport, bool enable);
 __rte_internal
 int idpf_vc_ena_dis_vport(struct idpf_vport *vport, bool enable);
 __rte_internal
-int idpf_vc_config_irq_map_unmap(struct idpf_vport *vport,
-				 uint16_t nb_rxq, bool map);
-__rte_internal
 int idpf_vc_alloc_vectors(struct idpf_vport *vport, uint16_t num_vectors);
 __rte_internal
 int idpf_vc_dealloc_vectors(struct idpf_vport *vport);
diff --git a/drivers/common/idpf/version.map b/drivers/common/idpf/version.map
index 62ea6579e3..3b3b8c2d19 100644
--- a/drivers/common/idpf/version.map
+++ b/drivers/common/idpf/version.map
@@ -10,7 +10,6 @@ INTERNAL {
 	idpf_switch_queue;
 	idpf_vc_ena_dis_queues;
 	idpf_vc_ena_dis_vport;
-	idpf_vc_config_irq_map_unmap;
 	idpf_vc_alloc_vectors;
 	idpf_vc_dealloc_vectors;
 	idpf_vc_query_ptype_info;
@@ -21,6 +20,8 @@ INTERNAL {
 	idpf_vport_init;
 	idpf_vport_deinit;
 	idpf_config_rss;
+	idpf_config_irq_map;
+	idpf_config_irq_unmap;
 
 	local: *;
 };
diff --git a/drivers/net/idpf/idpf_ethdev.c b/drivers/net/idpf/idpf_ethdev.c
index ca920bef85..15a71c6efa 100644
--- a/drivers/net/idpf/idpf_ethdev.c
+++ b/drivers/net/idpf/idpf_ethdev.c
@@ -268,84 +268,9 @@ static int
 idpf_config_rx_queues_irqs(struct rte_eth_dev *dev)
 {
 	struct idpf_vport *vport = dev->data->dev_private;
-	struct idpf_adapter *adapter = vport->adapter;
-	struct virtchnl2_queue_vector *qv_map;
-	struct idpf_hw *hw = &adapter->hw;
-	uint32_t dynctl_reg_start;
-	uint32_t itrn_reg_start;
-	uint32_t dynctl_val, itrn_val;
-	uint16_t i;
-
-	qv_map = rte_zmalloc("qv_map",
-			dev->data->nb_rx_queues *
-			sizeof(struct virtchnl2_queue_vector), 0);
-	if (qv_map == NULL) {
-		PMD_DRV_LOG(ERR, "Failed to allocate %d queue-vector map",
-			    dev->data->nb_rx_queues);
-		goto qv_map_alloc_err;
-	}
-
-	/* Rx interrupt disabled, Map interrupt only for writeback */
-
-	/* The capability flags adapter->caps.other_caps should be
-	 * compared with bit VIRTCHNL2_CAP_WB_ON_ITR here. The if
-	 * condition should be updated when the FW can return the
-	 * correct flag bits.
-	 */
-	dynctl_reg_start =
-		vport->recv_vectors->vchunks.vchunks->dynctl_reg_start;
-	itrn_reg_start =
-		vport->recv_vectors->vchunks.vchunks->itrn_reg_start;
-	dynctl_val = IDPF_READ_REG(hw, dynctl_reg_start);
-	PMD_DRV_LOG(DEBUG, "Value of dynctl_reg_start is 0x%x",
-		    dynctl_val);
-	itrn_val = IDPF_READ_REG(hw, itrn_reg_start);
-	PMD_DRV_LOG(DEBUG, "Value of itrn_reg_start is 0x%x", itrn_val);
-	/* Force write-backs by setting WB_ON_ITR bit in DYN_CTL
-	 * register. WB_ON_ITR and INTENA are mutually exclusive
-	 * bits. Setting WB_ON_ITR bits means TX and RX Descs
-	 * are written back based on ITR expiration irrespective
-	 * of INTENA setting.
-	 */
-	/* TBD: need to tune INTERVAL value for better performance. */
-	if (itrn_val != 0)
-		IDPF_WRITE_REG(hw,
-			       dynctl_reg_start,
-			       VIRTCHNL2_ITR_IDX_0  <<
-			       PF_GLINT_DYN_CTL_ITR_INDX_S |
-			       PF_GLINT_DYN_CTL_WB_ON_ITR_M |
-			       itrn_val <<
-			       PF_GLINT_DYN_CTL_INTERVAL_S);
-	else
-		IDPF_WRITE_REG(hw,
-			       dynctl_reg_start,
-			       VIRTCHNL2_ITR_IDX_0  <<
-			       PF_GLINT_DYN_CTL_ITR_INDX_S |
-			       PF_GLINT_DYN_CTL_WB_ON_ITR_M |
-			       IDPF_DFLT_INTERVAL <<
-			       PF_GLINT_DYN_CTL_INTERVAL_S);
-
-	for (i = 0; i < dev->data->nb_rx_queues; i++) {
-		/* map all queues to the same vector */
-		qv_map[i].queue_id = vport->chunks_info.rx_start_qid + i;
-		qv_map[i].vector_id =
-			vport->recv_vectors->vchunks.vchunks->start_vector_id;
-	}
-	vport->qv_map = qv_map;
+	uint16_t nb_rx_queues = dev->data->nb_rx_queues;
 
-	if (idpf_vc_config_irq_map_unmap(vport, dev->data->nb_rx_queues, true) != 0) {
-		PMD_DRV_LOG(ERR, "config interrupt mapping failed");
-		goto config_irq_map_err;
-	}
-
-	return 0;
-
-config_irq_map_err:
-	rte_free(vport->qv_map);
-	vport->qv_map = NULL;
-
-qv_map_alloc_err:
-	return -1;
+	return idpf_config_irq_map(vport, nb_rx_queues);
 }
 
 static int
@@ -457,10 +382,9 @@ idpf_dev_stop(struct rte_eth_dev *dev)
 
 	idpf_stop_queues(dev);
 
-	idpf_vc_config_irq_map_unmap(vport, dev->data->nb_rx_queues, false);
+	idpf_config_irq_unmap(vport, dev->data->nb_rx_queues);
 
-	if (vport->recv_vectors != NULL)
-		idpf_vc_dealloc_vectors(vport);
+	idpf_vc_dealloc_vectors(vport);
 
 	vport->stopped = 1;
 
@@ -477,12 +401,6 @@ idpf_dev_close(struct rte_eth_dev *dev)
 
 	idpf_vport_deinit(vport);
 
-	rte_free(vport->recv_vectors);
-	vport->recv_vectors = NULL;
-
-	rte_free(vport->qv_map);
-	vport->qv_map = NULL;
-
 	adapter->cur_vports &= ~RTE_BIT32(vport->devarg_id);
 	adapter->cur_vport_nb--;
 	dev->data->dev_private = NULL;
diff --git a/drivers/net/idpf/idpf_ethdev.h b/drivers/net/idpf/idpf_ethdev.h
index bfede6f4e3..7ee99b5585 100644
--- a/drivers/net/idpf/idpf_ethdev.h
+++ b/drivers/net/idpf/idpf_ethdev.h
@@ -32,7 +32,6 @@
 #define IDPF_RX_BUFQ_PER_GRP	2
 
 #define IDPF_DFLT_Q_VEC_NUM	1
-#define IDPF_DFLT_INTERVAL	16
 
 #define IDPF_MIN_BUF_SIZE	1024
 #define IDPF_MAX_FRAME_SIZE	9728
-- 
2.26.2


  parent reply	other threads:[~2022-12-08  7:54 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-08  7:52 [PATCH 00/15] net/idpf: refactor idpf pmd beilei.xing
2022-12-08  7:52 ` [PATCH 01/15] common/idpf: add adapter structure beilei.xing
2022-12-08  7:52 ` [PATCH 02/15] common/idpf: add vport structure beilei.xing
2022-12-08  7:52 ` [PATCH 03/15] common/idpf: move vc functions to common module beilei.xing
2022-12-08  7:52 ` [PATCH 04/15] common/idpf: introduce adapter init and deinit beilei.xing
2022-12-08  7:52 ` [PATCH 05/15] common/idpf: add vport init/deinit beilei.xing
2022-12-08  7:53 ` [PATCH 06/15] common/idpf: add config RSS beilei.xing
2022-12-08  7:53 ` beilei.xing [this message]
2022-12-08  7:53 ` [PATCH 08/15] common/idpf: move ptype table to adapter structure beilei.xing
2022-12-08  7:53 ` [PATCH 09/15] common/idpf: init create vport info beilei.xing
2022-12-08  7:53 ` [PATCH 10/15] common/idpf: add vector flags in vport beilei.xing
2022-12-08  7:53 ` [PATCH 11/15] common/idpf: add rxq and txq struct beilei.xing
2022-12-08  7:53 ` [PATCH 12/15] common/idpf: add help functions for queue setup and release beilei.xing
2022-12-08  7:53 ` [PATCH 13/15] common/idpf: add scalar data path beilei.xing
2022-12-08  7:53 ` [PATCH 14/15] common/idpf: add vec queue setup beilei.xing
2022-12-08  7:53 ` [PATCH 15/15] common/idpf: add avx512 for single queue model beilei.xing
2023-01-06  9:16 ` [PATCH v2 00/15] net/idpf: introduce idpf common modle beilei.xing
2023-01-06  9:16   ` [PATCH v2 01/15] common/idpf: add adapter structure beilei.xing
2023-01-06  9:16   ` [PATCH v2 02/15] common/idpf: add vport structure beilei.xing
2023-01-06  9:16   ` [PATCH v2 03/15] common/idpf: move vc functions to common module beilei.xing
2023-01-06  9:16   ` [PATCH v2 04/15] common/idpf: introduce adapter init and deinit beilei.xing
2023-01-06  9:16   ` [PATCH v2 05/15] common/idpf: add vport init/deinit beilei.xing
2023-01-08 12:10     ` Zhang, Qi Z
2023-01-09  1:34       ` Xing, Beilei
2023-01-06  9:16   ` [PATCH v2 06/15] common/idpf: add config RSS beilei.xing
2023-01-06  9:16   ` [PATCH v2 07/15] common/idpf: add irq map/unmap beilei.xing
2023-01-17  1:14     ` Zhang, Qi Z
2023-01-06  9:16   ` [PATCH v2 08/15] common/idpf: move ptype table to adapter structure beilei.xing
2023-01-06  9:16   ` [PATCH v2 09/15] common/idpf: init create vport info beilei.xing
2023-01-06  9:16   ` [PATCH v2 10/15] common/idpf: add vector flags in vport beilei.xing
2023-01-06  9:16   ` [PATCH v2 11/15] common/idpf: add rxq and txq struct beilei.xing
2023-01-06  9:16   ` [PATCH v2 12/15] common/idpf: add help functions for queue setup and release beilei.xing
2023-01-06  9:16   ` [PATCH v2 13/15] common/idpf: add scalar data path beilei.xing
2023-01-06  9:16   ` [PATCH v2 14/15] common/idpf: add vec queue setup beilei.xing
2023-01-06  9:16   ` [PATCH v2 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=20221208075309.37852-8-beilei.xing@intel.com \
    --to=beilei.xing@intel.com \
    --cc=dev@dpdk.org \
    --cc=jingjing.wu@intel.com \
    --cc=qi.z.zhang@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).