DPDK patches and discussions
 help / color / mirror / Atom feed
From: Dengdui Huang <huangdengdui@huawei.com>
To: <dev@dpdk.org>
Cc: <stephen@networkplumber.org>, <lihuisong@huawei.com>,
	<fengchengwen@huawei.com>, <liuyonglong@huawei.com>
Subject: [PATCH 2/6] net/hns3: remove duplicate struct field
Date: Wed, 11 Jun 2025 16:18:56 +0800	[thread overview]
Message-ID: <20250611081900.3658421-3-huangdengdui@huawei.com> (raw)
In-Reply-To: <20250611081900.3658421-1-huangdengdui@huawei.com>

From: Chengwen Feng <fengchengwen@huawei.com>

The struct hns3_hw and hns3_hw.dcb_info both has num_tc field, their
meanings are the same, to ensure code readability, remove the num_tc
field of struct hns3_hw.

Signed-off-by: Chengwen Feng <fengchengwen@huawei.com>
Signed-off-by: Dengdui Huang <huangdengdui@huawei.com>
---
 drivers/net/hns3/hns3_dcb.c       | 44 ++++++++++++-------------------
 drivers/net/hns3/hns3_dump.c      |  2 +-
 drivers/net/hns3/hns3_ethdev.c    |  4 +--
 drivers/net/hns3/hns3_ethdev.h    |  3 +--
 drivers/net/hns3/hns3_ethdev_vf.c |  2 +-
 drivers/net/hns3/hns3_tm.c        |  6 ++---
 6 files changed, 25 insertions(+), 36 deletions(-)

diff --git a/drivers/net/hns3/hns3_dcb.c b/drivers/net/hns3/hns3_dcb.c
index 2f917fef9e..88c6242d66 100644
--- a/drivers/net/hns3/hns3_dcb.c
+++ b/drivers/net/hns3/hns3_dcb.c
@@ -623,7 +623,7 @@ hns3_set_rss_size(struct hns3_hw *hw, uint16_t nb_rx_q)
 	uint16_t used_rx_queues;
 	uint16_t i;
 
-	rx_qnum_per_tc = nb_rx_q / hw->num_tc;
+	rx_qnum_per_tc = nb_rx_q / hw->dcb_info.num_tc;
 	if (rx_qnum_per_tc > hw->rss_size_max) {
 		hns3_err(hw, "rx queue number of per tc (%u) is greater than "
 			 "value (%u) hardware supported.",
@@ -631,11 +631,11 @@ hns3_set_rss_size(struct hns3_hw *hw, uint16_t nb_rx_q)
 		return -EINVAL;
 	}
 
-	used_rx_queues = hw->num_tc * rx_qnum_per_tc;
+	used_rx_queues = hw->dcb_info.num_tc * rx_qnum_per_tc;
 	if (used_rx_queues != nb_rx_q) {
 		hns3_err(hw, "rx queue number (%u) configured must be an "
 			 "integral multiple of valid tc number (%u).",
-			 nb_rx_q, hw->num_tc);
+			 nb_rx_q, hw->dcb_info.num_tc);
 		return -EINVAL;
 	}
 	hw->alloc_rss_size = rx_qnum_per_tc;
@@ -665,12 +665,12 @@ hns3_tc_queue_mapping_cfg(struct hns3_hw *hw, uint16_t nb_tx_q)
 	uint16_t tx_qnum_per_tc;
 	uint8_t i;
 
-	tx_qnum_per_tc = nb_tx_q / hw->num_tc;
-	used_tx_queues = hw->num_tc * tx_qnum_per_tc;
+	tx_qnum_per_tc = nb_tx_q / hw->dcb_info.num_tc;
+	used_tx_queues = hw->dcb_info.num_tc * tx_qnum_per_tc;
 	if (used_tx_queues != nb_tx_q) {
 		hns3_err(hw, "tx queue number (%u) configured must be an "
 			 "integral multiple of valid tc number (%u).",
-			 nb_tx_q, hw->num_tc);
+			 nb_tx_q, hw->dcb_info.num_tc);
 		return -EINVAL;
 	}
 
@@ -678,7 +678,7 @@ hns3_tc_queue_mapping_cfg(struct hns3_hw *hw, uint16_t nb_tx_q)
 	hw->tx_qnum_per_tc = tx_qnum_per_tc;
 	for (i = 0; i < HNS3_MAX_TC_NUM; i++) {
 		tc_queue = &hw->tc_queue[i];
-		if (hw->hw_tc_map & BIT(i) && i < hw->num_tc) {
+		if (hw->hw_tc_map & BIT(i) && i < hw->dcb_info.num_tc) {
 			tc_queue->enable = true;
 			tc_queue->tqp_offset = i * hw->tx_qnum_per_tc;
 			tc_queue->tqp_count = hw->tx_qnum_per_tc;
@@ -720,15 +720,15 @@ hns3_queue_to_tc_mapping(struct hns3_hw *hw, uint16_t nb_rx_q, uint16_t nb_tx_q)
 {
 	int ret;
 
-	if (nb_rx_q < hw->num_tc) {
+	if (nb_rx_q < hw->dcb_info.num_tc) {
 		hns3_err(hw, "number of Rx queues(%u) is less than number of TC(%u).",
-			 nb_rx_q, hw->num_tc);
+			 nb_rx_q, hw->dcb_info.num_tc);
 		return -EINVAL;
 	}
 
-	if (nb_tx_q < hw->num_tc) {
+	if (nb_tx_q < hw->dcb_info.num_tc) {
 		hns3_err(hw, "number of Tx queues(%u) is less than number of TC(%u).",
-			 nb_tx_q, hw->num_tc);
+			 nb_tx_q, hw->dcb_info.num_tc);
 		return -EINVAL;
 	}
 
@@ -739,15 +739,6 @@ hns3_queue_to_tc_mapping(struct hns3_hw *hw, uint16_t nb_rx_q, uint16_t nb_tx_q)
 	return hns3_tc_queue_mapping_cfg(hw, nb_tx_q);
 }
 
-static int
-hns3_dcb_update_tc_queue_mapping(struct hns3_hw *hw, uint16_t nb_rx_q,
-				 uint16_t nb_tx_q)
-{
-	hw->num_tc = hw->dcb_info.num_tc;
-
-	return hns3_queue_to_tc_mapping(hw, nb_rx_q, nb_tx_q);
-}
-
 int
 hns3_dcb_info_init(struct hns3_hw *hw)
 {
@@ -1028,7 +1019,7 @@ hns3_q_to_qs_map(struct hns3_hw *hw)
 	uint32_t i, j;
 	int ret;
 
-	for (i = 0; i < hw->num_tc; i++) {
+	for (i = 0; i < hw->dcb_info.num_tc; i++) {
 		tc_queue = &hw->tc_queue[i];
 		for (j = 0; j < tc_queue->tqp_count; j++) {
 			q_id = tc_queue->tqp_offset + j;
@@ -1053,7 +1044,7 @@ hns3_pri_q_qs_cfg(struct hns3_hw *hw)
 		return -EINVAL;
 
 	/* Cfg qs -> pri mapping */
-	for (i = 0; i < hw->num_tc; i++) {
+	for (i = 0; i < hw->dcb_info.num_tc; i++) {
 		ret = hns3_qs_to_pri_map_cfg(hw, i, i);
 		if (ret) {
 			hns3_err(hw, "qs_to_pri mapping fail: %d", ret);
@@ -1448,8 +1439,8 @@ hns3_dcb_info_cfg(struct hns3_adapter *hns)
 	for (i = 0; i < HNS3_MAX_USER_PRIO; i++)
 		hw->dcb_info.prio_tc[i] = dcb_rx_conf->dcb_tc[i];
 
-	ret = hns3_dcb_update_tc_queue_mapping(hw, hw->data->nb_rx_queues,
-					       hw->data->nb_tx_queues);
+	ret = hns3_queue_to_tc_mapping(hw, hw->data->nb_rx_queues,
+				       hw->data->nb_tx_queues);
 	if (ret)
 		hns3_err(hw, "update tc queue mapping failed, ret = %d.", ret);
 
@@ -1635,8 +1626,7 @@ hns3_dcb_init(struct hns3_hw *hw)
 		 */
 		default_tqp_num = RTE_MIN(hw->rss_size_max,
 					  hw->tqps_num / hw->dcb_info.num_tc);
-		ret = hns3_dcb_update_tc_queue_mapping(hw, default_tqp_num,
-						       default_tqp_num);
+		ret = hns3_queue_to_tc_mapping(hw, default_tqp_num, default_tqp_num);
 		if (ret) {
 			hns3_err(hw,
 				 "update tc queue mapping failed, ret = %d.",
@@ -1673,7 +1663,7 @@ hns3_update_queue_map_configure(struct hns3_adapter *hns)
 	if ((uint32_t)mq_mode & RTE_ETH_MQ_RX_DCB_FLAG)
 		return 0;
 
-	ret = hns3_dcb_update_tc_queue_mapping(hw, nb_rx_q, nb_tx_q);
+	ret = hns3_queue_to_tc_mapping(hw, nb_rx_q, nb_tx_q);
 	if (ret) {
 		hns3_err(hw, "failed to update tc queue mapping, ret = %d.",
 			 ret);
diff --git a/drivers/net/hns3/hns3_dump.c b/drivers/net/hns3/hns3_dump.c
index f21d32e6a2..6c43ec486e 100644
--- a/drivers/net/hns3/hns3_dump.c
+++ b/drivers/net/hns3/hns3_dump.c
@@ -914,7 +914,7 @@ hns3_is_link_fc_mode(struct hns3_adapter *hns)
 	if (hw->current_fc_status == HNS3_FC_STATUS_PFC)
 		return false;
 
-	if (hw->num_tc > 1 && !pf->support_multi_tc_pause)
+	if (hw->dcb_info.num_tc > 1 && !pf->support_multi_tc_pause)
 		return false;
 
 	return true;
diff --git a/drivers/net/hns3/hns3_ethdev.c b/drivers/net/hns3/hns3_ethdev.c
index 50c6ed0744..6b8fd3383a 100644
--- a/drivers/net/hns3/hns3_ethdev.c
+++ b/drivers/net/hns3/hns3_ethdev.c
@@ -5432,7 +5432,7 @@ hns3_flow_ctrl_set(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
 		return -EOPNOTSUPP;
 	}
 
-	if (hw->num_tc > 1 && !pf->support_multi_tc_pause) {
+	if (hw->dcb_info.num_tc > 1 && !pf->support_multi_tc_pause) {
 		hns3_err(hw, "in multi-TC scenarios, MAC pause is not supported.");
 		return -EOPNOTSUPP;
 	}
@@ -5509,7 +5509,7 @@ hns3_get_dcb_info(struct rte_eth_dev *dev, struct rte_eth_dcb_info *dcb_info)
 	for (i = 0; i < dcb_info->nb_tcs; i++)
 		dcb_info->tc_bws[i] = hw->dcb_info.pg_info[0].tc_dwrr[i];
 
-	for (i = 0; i < hw->num_tc; i++) {
+	for (i = 0; i < hw->dcb_info.num_tc; i++) {
 		dcb_info->tc_queue.tc_rxq[0][i].base = hw->alloc_rss_size * i;
 		dcb_info->tc_queue.tc_txq[0][i].base =
 						hw->tc_queue[i].tqp_offset;
diff --git a/drivers/net/hns3/hns3_ethdev.h b/drivers/net/hns3/hns3_ethdev.h
index d164b9e38c..e4160f6eae 100644
--- a/drivers/net/hns3/hns3_ethdev.h
+++ b/drivers/net/hns3/hns3_ethdev.h
@@ -130,7 +130,7 @@ struct hns3_tc_info {
 };
 
 struct hns3_dcb_info {
-	uint8_t num_tc;
+	uint8_t num_tc;     /* Total number of enabled TCs */
 	uint8_t num_pg;     /* It must be 1 if vNET-Base schd */
 	uint8_t pg_dwrr[HNS3_PG_NUM];
 	uint8_t prio_tc[HNS3_MAX_USER_PRIO];
@@ -534,7 +534,6 @@ struct hns3_hw {
 	uint16_t rss_ind_tbl_size;
 	uint16_t rss_key_size;
 
-	uint8_t num_tc;             /* Total number of enabled TCs */
 	uint8_t hw_tc_map;
 	enum hns3_fc_mode requested_fc_mode; /* FC mode requested by user */
 	struct hns3_dcb_info dcb_info;
diff --git a/drivers/net/hns3/hns3_ethdev_vf.c b/drivers/net/hns3/hns3_ethdev_vf.c
index ea9225cd26..5f4ae1d979 100644
--- a/drivers/net/hns3/hns3_ethdev_vf.c
+++ b/drivers/net/hns3/hns3_ethdev_vf.c
@@ -854,7 +854,7 @@ hns3vf_get_basic_info(struct hns3_hw *hw)
 
 	basic_info = (struct hns3_basic_info *)resp_msg;
 	hw->hw_tc_map = basic_info->hw_tc_map;
-	hw->num_tc = hns3vf_get_num_tc(hw);
+	hw->dcb_info.num_tc = hns3vf_get_num_tc(hw);
 	hw->pf_vf_if_version = basic_info->pf_vf_if_version;
 	hns3vf_update_caps(hw, basic_info->caps);
 
diff --git a/drivers/net/hns3/hns3_tm.c b/drivers/net/hns3/hns3_tm.c
index 1c2ad71133..fe97b4ab92 100644
--- a/drivers/net/hns3/hns3_tm.c
+++ b/drivers/net/hns3/hns3_tm.c
@@ -519,13 +519,13 @@ hns3_tm_tc_node_add(struct rte_eth_dev *dev, uint32_t node_id,
 
 	if (node_id >= pf->tm_conf.nb_nodes_max - 1 ||
 	    node_id < pf->tm_conf.nb_leaf_nodes_max ||
-	    hns3_tm_calc_node_tc_no(&pf->tm_conf, node_id) >= hw->num_tc) {
+	    hns3_tm_calc_node_tc_no(&pf->tm_conf, node_id) >= hw->dcb_info.num_tc) {
 		error->type = RTE_TM_ERROR_TYPE_NODE_ID;
 		error->message = "invalid tc node ID";
 		return -EINVAL;
 	}
 
-	if (pf->tm_conf.nb_tc_node >= hw->num_tc) {
+	if (pf->tm_conf.nb_tc_node >= hw->dcb_info.num_tc) {
 		error->type = RTE_TM_ERROR_TYPE_NODE_ID;
 		error->message = "too many TCs";
 		return -EINVAL;
@@ -974,7 +974,7 @@ hns3_tm_configure_check(struct hns3_hw *hw, struct rte_tm_error *error)
 		}
 
 		if (hns3_tm_calc_node_tc_no(tm_conf, tm_node->id) >=
-			hw->num_tc) {
+			hw->dcb_info.num_tc) {
 			error->type = RTE_TM_ERROR_TYPE_NODE_ID;
 			error->message = "node's TC not exist";
 			return false;
-- 
2.33.0


  parent reply	other threads:[~2025-06-11  8:19 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-11  8:18 [PATCH 0/6] net/hns3: VF support multi-TCs Dengdui Huang
2025-06-11  8:18 ` [PATCH 1/6] net/hns3: fix VF fail to config queue TC Dengdui Huang
2025-06-11  8:18 ` Dengdui Huang [this message]
2025-06-11  8:18 ` [PATCH 3/6] net/hns3: refactor DCB module code Dengdui Huang
2025-06-11  8:18 ` [PATCH 4/6] net/hns3: VF support parse max TC number Dengdui Huang
2025-06-11  8:18 ` [PATCH 5/6] net/hns3: VF support discover multi-TCs capability Dengdui Huang
2025-06-11  8:19 ` [PATCH 6/6] net/hns3: VF support multi-TCs configure Dengdui Huang

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=20250611081900.3658421-3-huangdengdui@huawei.com \
    --to=huangdengdui@huawei.com \
    --cc=dev@dpdk.org \
    --cc=fengchengwen@huawei.com \
    --cc=lihuisong@huawei.com \
    --cc=liuyonglong@huawei.com \
    --cc=stephen@networkplumber.org \
    /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).