DPDK patches and discussions
 help / color / mirror / Atom feed
From: Dongdong Liu <liudongdong3@huawei.com>
To: <dev@dpdk.org>, <ferruh.yigit@amd.com>, <thomas@monjalon.net>,
	<andrew.rybchenko@oktetlabs.ru>
Cc: <stable@dpdk.org>, <yisen.zhuang@huawei.com>,
	<liudongdong3@huawei.com>, <lihuisong@huawei.com>
Subject: [PATCH 02/10] net/hns3: extract common API to query device
Date: Sun, 29 Jan 2023 18:51:32 +0800	[thread overview]
Message-ID: <20230129105140.29921-3-liudongdong3@huawei.com> (raw)
In-Reply-To: <20230129105140.29921-1-liudongdong3@huawei.com>

From: Huisong Li <lihuisong@huawei.com>

Extract common function to query device specifications.

Fixes: 9c740336f024 ("net/hns3: get device specifications from firmware")
Cc: stable@dpdk.org

Signed-off-by: Huisong Li <lihuisong@huawei.com>
Signed-off-by: Dongdong Liu <liudongdong3@huawei.com>
---
 drivers/net/hns3/hns3_common.c    | 75 +++++++++++++++++++++++++++++++
 drivers/net/hns3/hns3_common.h    |  2 +
 drivers/net/hns3/hns3_ethdev.c    | 63 --------------------------
 drivers/net/hns3/hns3_ethdev_vf.c | 65 +--------------------------
 4 files changed, 79 insertions(+), 126 deletions(-)

diff --git a/drivers/net/hns3/hns3_common.c b/drivers/net/hns3/hns3_common.c
index 7adc6a4972..b0c7f8d62c 100644
--- a/drivers/net/hns3/hns3_common.c
+++ b/drivers/net/hns3/hns3_common.c
@@ -10,6 +10,7 @@
 #include "hns3_logs.h"
 #include "hns3_regs.h"
 #include "hns3_rxtx.h"
+#include "hns3_dcb.h"
 #include "hns3_common.h"
 
 int
@@ -845,3 +846,77 @@ hns3_get_pci_revision_id(struct hns3_hw *hw, uint8_t *revision_id)
 
 	return 0;
 }
+
+void
+hns3_set_default_dev_specifications(struct hns3_hw *hw)
+{
+	struct hns3_adapter *hns = HNS3_DEV_HW_TO_ADAPTER(hw);
+
+	hw->max_non_tso_bd_num = HNS3_MAX_NON_TSO_BD_PER_PKT;
+	hw->rss_ind_tbl_size = HNS3_RSS_IND_TBL_SIZE;
+	hw->rss_key_size = HNS3_RSS_KEY_SIZE;
+	hw->intr.int_ql_max = HNS3_INTR_QL_NONE;
+
+	if (hns->is_vf)
+		return;
+
+	hw->max_tm_rate = HNS3_ETHER_MAX_RATE;
+}
+
+static void
+hns3_parse_dev_specifications(struct hns3_hw *hw, struct hns3_cmd_desc *desc)
+{
+	struct hns3_adapter *hns = HNS3_DEV_HW_TO_ADAPTER(hw);
+	struct hns3_dev_specs_0_cmd *req0;
+	struct hns3_dev_specs_1_cmd *req1;
+
+	req0 = (struct hns3_dev_specs_0_cmd *)desc[0].data;
+	req1 = (struct hns3_dev_specs_1_cmd *)desc[1].data;
+
+	hw->max_non_tso_bd_num = req0->max_non_tso_bd_num;
+	hw->rss_ind_tbl_size = rte_le_to_cpu_16(req0->rss_ind_tbl_size);
+	hw->rss_key_size = rte_le_to_cpu_16(req0->rss_key_size);
+	hw->intr.int_ql_max = rte_le_to_cpu_16(req0->intr_ql_max);
+	hw->min_tx_pkt_len = req1->min_tx_pkt_len;
+
+	if (hns->is_vf)
+		return;
+
+	hw->max_tm_rate = rte_le_to_cpu_32(req0->max_tm_rate);
+}
+
+static int
+hns3_check_dev_specifications(struct hns3_hw *hw)
+{
+	if (hw->rss_ind_tbl_size == 0 ||
+	    hw->rss_ind_tbl_size > HNS3_RSS_IND_TBL_SIZE_MAX) {
+		hns3_err(hw, "the indirection table size obtained (%u) is invalid, and should not be zero or exceed the maximum(%u)",
+			 hw->rss_ind_tbl_size, HNS3_RSS_IND_TBL_SIZE_MAX);
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
+int
+hns3_query_dev_specifications(struct hns3_hw *hw)
+{
+	struct hns3_cmd_desc desc[HNS3_QUERY_DEV_SPECS_BD_NUM];
+	int ret;
+	int i;
+
+	for (i = 0; i < HNS3_QUERY_DEV_SPECS_BD_NUM - 1; i++) {
+		hns3_cmd_setup_basic_desc(&desc[i], HNS3_OPC_QUERY_DEV_SPECS,
+					  true);
+		desc[i].flag |= rte_cpu_to_le_16(HNS3_CMD_FLAG_NEXT);
+	}
+	hns3_cmd_setup_basic_desc(&desc[i], HNS3_OPC_QUERY_DEV_SPECS, true);
+
+	ret = hns3_cmd_send(hw, desc, HNS3_QUERY_DEV_SPECS_BD_NUM);
+	if (ret)
+		return ret;
+
+	hns3_parse_dev_specifications(hw, desc);
+
+	return hns3_check_dev_specifications(hw);
+}
diff --git a/drivers/net/hns3/hns3_common.h b/drivers/net/hns3/hns3_common.h
index 5aa001f0cc..8eaeda26e7 100644
--- a/drivers/net/hns3/hns3_common.h
+++ b/drivers/net/hns3/hns3_common.h
@@ -60,5 +60,7 @@ void hns3_unmap_rx_interrupt(struct rte_eth_dev *dev);
 int hns3_restore_rx_interrupt(struct hns3_hw *hw);
 
 int hns3_get_pci_revision_id(struct hns3_hw *hw, uint8_t *revision_id);
+void hns3_set_default_dev_specifications(struct hns3_hw *hw);
+int hns3_query_dev_specifications(struct hns3_hw *hw);
 
 #endif /* HNS3_COMMON_H */
diff --git a/drivers/net/hns3/hns3_ethdev.c b/drivers/net/hns3/hns3_ethdev.c
index eb809cd8c9..ab565ce128 100644
--- a/drivers/net/hns3/hns3_ethdev.c
+++ b/drivers/net/hns3/hns3_ethdev.c
@@ -2647,69 +2647,6 @@ hns3_parse_speed(int speed_cmd, uint32_t *speed)
 	return 0;
 }
 
-static void
-hns3_set_default_dev_specifications(struct hns3_hw *hw)
-{
-	hw->max_non_tso_bd_num = HNS3_MAX_NON_TSO_BD_PER_PKT;
-	hw->rss_ind_tbl_size = HNS3_RSS_IND_TBL_SIZE;
-	hw->rss_key_size = HNS3_RSS_KEY_SIZE;
-	hw->max_tm_rate = HNS3_ETHER_MAX_RATE;
-	hw->intr.int_ql_max = HNS3_INTR_QL_NONE;
-}
-
-static void
-hns3_parse_dev_specifications(struct hns3_hw *hw, struct hns3_cmd_desc *desc)
-{
-	struct hns3_dev_specs_0_cmd *req0;
-	struct hns3_dev_specs_1_cmd *req1;
-
-	req0 = (struct hns3_dev_specs_0_cmd *)desc[0].data;
-	req1 = (struct hns3_dev_specs_1_cmd *)desc[1].data;
-
-	hw->max_non_tso_bd_num = req0->max_non_tso_bd_num;
-	hw->rss_ind_tbl_size = rte_le_to_cpu_16(req0->rss_ind_tbl_size);
-	hw->rss_key_size = rte_le_to_cpu_16(req0->rss_key_size);
-	hw->max_tm_rate = rte_le_to_cpu_32(req0->max_tm_rate);
-	hw->intr.int_ql_max = rte_le_to_cpu_16(req0->intr_ql_max);
-	hw->min_tx_pkt_len = req1->min_tx_pkt_len;
-}
-
-static int
-hns3_check_dev_specifications(struct hns3_hw *hw)
-{
-	if (hw->rss_ind_tbl_size == 0 ||
-	    hw->rss_ind_tbl_size > HNS3_RSS_IND_TBL_SIZE_MAX) {
-		hns3_err(hw, "the indirection table size obtained (%u) is invalid, and should not be zero or exceed the maximum(%u)",
-			 hw->rss_ind_tbl_size, HNS3_RSS_IND_TBL_SIZE_MAX);
-		return -EINVAL;
-	}
-
-	return 0;
-}
-
-static int
-hns3_query_dev_specifications(struct hns3_hw *hw)
-{
-	struct hns3_cmd_desc desc[HNS3_QUERY_DEV_SPECS_BD_NUM];
-	int ret;
-	int i;
-
-	for (i = 0; i < HNS3_QUERY_DEV_SPECS_BD_NUM - 1; i++) {
-		hns3_cmd_setup_basic_desc(&desc[i], HNS3_OPC_QUERY_DEV_SPECS,
-					  true);
-		desc[i].flag |= rte_cpu_to_le_16(HNS3_CMD_FLAG_NEXT);
-	}
-	hns3_cmd_setup_basic_desc(&desc[i], HNS3_OPC_QUERY_DEV_SPECS, true);
-
-	ret = hns3_cmd_send(hw, desc, HNS3_QUERY_DEV_SPECS_BD_NUM);
-	if (ret)
-		return ret;
-
-	hns3_parse_dev_specifications(hw, desc);
-
-	return hns3_check_dev_specifications(hw);
-}
-
 static int
 hns3_get_capability(struct hns3_hw *hw)
 {
diff --git a/drivers/net/hns3/hns3_ethdev_vf.c b/drivers/net/hns3/hns3_ethdev_vf.c
index e43815607a..d3c1bdf2c5 100644
--- a/drivers/net/hns3/hns3_ethdev_vf.c
+++ b/drivers/net/hns3/hns3_ethdev_vf.c
@@ -688,67 +688,6 @@ hns3vf_interrupt_handler(void *param)
 	hns3vf_enable_irq0(hw);
 }
 
-static void
-hns3vf_set_default_dev_specifications(struct hns3_hw *hw)
-{
-	hw->max_non_tso_bd_num = HNS3_MAX_NON_TSO_BD_PER_PKT;
-	hw->rss_ind_tbl_size = HNS3_RSS_IND_TBL_SIZE;
-	hw->rss_key_size = HNS3_RSS_KEY_SIZE;
-	hw->intr.int_ql_max = HNS3_INTR_QL_NONE;
-}
-
-static void
-hns3vf_parse_dev_specifications(struct hns3_hw *hw, struct hns3_cmd_desc *desc)
-{
-	struct hns3_dev_specs_0_cmd *req0;
-	struct hns3_dev_specs_1_cmd *req1;
-
-	req0 = (struct hns3_dev_specs_0_cmd *)desc[0].data;
-	req1 = (struct hns3_dev_specs_1_cmd *)desc[1].data;
-
-	hw->max_non_tso_bd_num = req0->max_non_tso_bd_num;
-	hw->rss_ind_tbl_size = rte_le_to_cpu_16(req0->rss_ind_tbl_size);
-	hw->rss_key_size = rte_le_to_cpu_16(req0->rss_key_size);
-	hw->intr.int_ql_max = rte_le_to_cpu_16(req0->intr_ql_max);
-	hw->min_tx_pkt_len = req1->min_tx_pkt_len;
-}
-
-static int
-hns3vf_check_dev_specifications(struct hns3_hw *hw)
-{
-	if (hw->rss_ind_tbl_size == 0 ||
-	    hw->rss_ind_tbl_size > HNS3_RSS_IND_TBL_SIZE_MAX) {
-		hns3_err(hw, "the indirection table size obtained (%u) is invalid, and should not be zero or exceed the maximum(%u)",
-			 hw->rss_ind_tbl_size, HNS3_RSS_IND_TBL_SIZE_MAX);
-		return -EINVAL;
-	}
-
-	return 0;
-}
-
-static int
-hns3vf_query_dev_specifications(struct hns3_hw *hw)
-{
-	struct hns3_cmd_desc desc[HNS3_QUERY_DEV_SPECS_BD_NUM];
-	int ret;
-	int i;
-
-	for (i = 0; i < HNS3_QUERY_DEV_SPECS_BD_NUM - 1; i++) {
-		hns3_cmd_setup_basic_desc(&desc[i], HNS3_OPC_QUERY_DEV_SPECS,
-					  true);
-		desc[i].flag |= rte_cpu_to_le_16(HNS3_CMD_FLAG_NEXT);
-	}
-	hns3_cmd_setup_basic_desc(&desc[i], HNS3_OPC_QUERY_DEV_SPECS, true);
-
-	ret = hns3_cmd_send(hw, desc, HNS3_QUERY_DEV_SPECS_BD_NUM);
-	if (ret)
-		return ret;
-
-	hns3vf_parse_dev_specifications(hw, desc);
-
-	return hns3vf_check_dev_specifications(hw);
-}
-
 void
 hns3vf_update_push_lsc_cap(struct hns3_hw *hw, bool supported)
 {
@@ -826,7 +765,7 @@ hns3vf_get_capability(struct hns3_hw *hw)
 		return ret;
 
 	if (hw->revision < PCI_REVISION_ID_HIP09_A) {
-		hns3vf_set_default_dev_specifications(hw);
+		hns3_set_default_dev_specifications(hw);
 		hw->intr.mapping_mode = HNS3_INTR_MAPPING_VEC_RSV_ONE;
 		hw->intr.gl_unit = HNS3_INTR_COALESCE_GL_UINT_2US;
 		hw->tso_mode = HNS3_TSO_SW_CAL_PSEUDO_H_CSUM;
@@ -837,7 +776,7 @@ hns3vf_get_capability(struct hns3_hw *hw)
 		return 0;
 	}
 
-	ret = hns3vf_query_dev_specifications(hw);
+	ret = hns3_query_dev_specifications(hw);
 	if (ret) {
 		PMD_INIT_LOG(ERR,
 			     "failed to query dev specifications, ret = %d",
-- 
2.22.0


  parent reply	other threads:[~2023-01-29 10:52 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-29 10:51 [PATCH 00/10] net/hns3: some bugfixes for rss Dongdong Liu
2023-01-29 10:51 ` [PATCH 01/10] net/hns3: fix error log about indirection table size Dongdong Liu
2023-01-29 10:51 ` Dongdong Liu [this message]
2023-01-29 10:51 ` [PATCH 03/10] net/hns3: refactor set RSS hash algorithm and key interface Dongdong Liu
2023-01-29 10:51 ` [PATCH 04/10] net/hns3: fix fixed RSS key size to be more compatibility Dongdong Liu
2023-01-29 10:51 ` [PATCH 05/10] net/hns3: fix misclearing RSS configuration Dongdong Liu
2023-01-29 10:51 ` [PATCH 06/10] net/hns3: using RSS filter list to check duplicated rule Dongdong Liu
2023-01-29 10:51 ` [PATCH 07/10] net/hns3: remove useless code when destroy valid RSS rule Dongdong Liu
2023-01-29 10:51 ` [PATCH 08/10] net/hns3: fix useless warning when flush or destroy rule Dongdong Liu
2023-01-29 10:51 ` [PATCH 09/10] net/hns3: fix bad memory structure conversion Dongdong Liu
2023-01-29 10:51 ` [PATCH 10/10] net/hns3: fix incorrect check for duplicate RSS rule Dongdong Liu
2023-01-30  9:31 ` [PATCH V2 00/10] net/hns3: some bugfixes for rss Dongdong Liu
2023-01-30  9:31   ` [PATCH V2 01/10] net/hns3: fix error log about indirection table size Dongdong Liu
2023-01-30  9:31   ` [PATCH V2 02/10] net/hns3: extract common API to query device Dongdong Liu
2023-01-30  9:31   ` [PATCH V2 03/10] net/hns3: refactor set RSS hash algorithm and key interface Dongdong Liu
2023-01-30  9:31   ` [PATCH V2 04/10] net/hns3: fix fixed RSS key size to be more compatibility Dongdong Liu
2023-01-30  9:31   ` [PATCH V2 05/10] net/hns3: fix misclearing RSS configuration Dongdong Liu
2023-01-30  9:31   ` [PATCH V2 06/10] net/hns3: using RSS filter list to check duplicated rule Dongdong Liu
2023-01-30  9:31   ` [PATCH V2 07/10] net/hns3: remove useless code when destroy valid RSS rule Dongdong Liu
2023-01-30  9:31   ` [PATCH V2 08/10] net/hns3: fix useless warning when flush or destroy rule Dongdong Liu
2023-01-30  9:31   ` [PATCH V2 09/10] net/hns3: fix bad memory structure conversion Dongdong Liu
2023-01-31  9:34     ` Dongdong Liu
2023-01-30  9:31   ` [PATCH V2 10/10] net/hns3: fix incorrect check for duplicate RSS rule Dongdong Liu
2023-01-31 13:02 ` [PATCH V3 00/10] net/hns3: some bugfixes for rss Dongdong Liu
2023-01-31 13:02   ` [PATCH V3 01/10] net/hns3: fix error log about indirection table size Dongdong Liu
2023-01-31 13:02   ` [PATCH V3 02/10] net/hns3: extract common API to query device Dongdong Liu
2023-01-31 13:02   ` [PATCH V3 03/10] net/hns3: refactor set RSS hash algorithm and key interface Dongdong Liu
2023-01-31 13:02   ` [PATCH V3 04/10] net/hns3: fix fixed RSS key size to be more compatibility Dongdong Liu
2023-01-31 13:02   ` [PATCH V3 05/10] net/hns3: fix misclearing RSS configuration Dongdong Liu
2023-01-31 13:02   ` [PATCH V3 06/10] net/hns3: using RSS filter list to check duplicated rule Dongdong Liu
2023-01-31 13:02   ` [PATCH V3 07/10] net/hns3: remove useless code when destroy valid RSS rule Dongdong Liu
2023-01-31 13:02   ` [PATCH V3 08/10] net/hns3: fix useless warning when flush or destroy rule Dongdong Liu
2023-01-31 13:02   ` [PATCH V3 09/10] net/hns3: fix bad memory structure conversion Dongdong Liu
2023-01-31 13:03   ` [PATCH V3 10/10] net/hns3: fix incorrect check for duplicate RSS rule Dongdong Liu
2023-02-08 17:46   ` [PATCH V3 00/10] net/hns3: some bugfixes for rss 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=20230129105140.29921-3-liudongdong3@huawei.com \
    --to=liudongdong3@huawei.com \
    --cc=andrew.rybchenko@oktetlabs.ru \
    --cc=dev@dpdk.org \
    --cc=ferruh.yigit@amd.com \
    --cc=lihuisong@huawei.com \
    --cc=stable@dpdk.org \
    --cc=thomas@monjalon.net \
    --cc=yisen.zhuang@huawei.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).