DPDK patches and discussions
 help / color / mirror / Atom feed
From: "Wei Hu (Xavier)" <huwei013@chinasoftinc.com>
To: <dev@dpdk.org>
Cc: <xavier.huwei@huawei.com>
Subject: [dpdk-dev] [PATCH v2 02/17] net/hns3: fix default VLAN won't be deleted when set PF PVID
Date: Tue, 22 Sep 2020 20:03:14 +0800	[thread overview]
Message-ID: <20200922120329.21185-3-huwei013@chinasoftinc.com> (raw)
In-Reply-To: <20200922120329.21185-1-huwei013@chinasoftinc.com>

From: Chengchang Tang <tangchengchang@huawei.com>

Currently, the default VLAN (vlan id 0) will never be deleted from the
hardware VLAN table based on hns3 PF device. As a result, even a non-zero
PVID is set by calling rte_eth_dev_set_vlan_pvid based on hns3 PF device,
packets with VLAN 0 and without VLAN are still received by PF driver in Rx
direction.

This patch deletes the restriction that VLAN 0 cannot be removed in PVID
configuration to ensure packets without PVID will be filtered when PVID
is set. And the patch adds VLAN 0 to the soft list when initing vlan
configuration to ensure that VLAN 0 will be deleted from the hardware VLAN
table when device is closed.

Fixes: 411d23b9eafb ("net/hns3: support VLAN")
Cc: stable@dpdk.org

Signed-off-by: Chengchang Tang <tangchengchang@huawei.com>
Signed-off-by: Wei Hu (Xavier) <xavier.huwei@huawei.com>
---
v1 -> v2:
	 fix TYPO_SPELLING with INVALID.
---
 drivers/net/hns3/hns3_ethdev.c | 105 +++++++++++++++++++----------------------
 1 file changed, 48 insertions(+), 57 deletions(-)

diff --git a/drivers/net/hns3/hns3_ethdev.c b/drivers/net/hns3/hns3_ethdev.c
index 3e98df3..abc1742 100644
--- a/drivers/net/hns3/hns3_ethdev.c
+++ b/drivers/net/hns3/hns3_ethdev.c
@@ -35,7 +35,7 @@
 #define HNS3_DEFAULT_PORT_CONF_QUEUES_NUM	1
 
 #define HNS3_SERVICE_INTERVAL		1000000 /* us */
-#define HNS3_INVLID_PVID		0xFFFF
+#define HNS3_INVALID_PVID		0xFFFF
 
 #define HNS3_FILTER_TYPE_VF		0
 #define HNS3_FILTER_TYPE_PORT		1
@@ -346,8 +346,9 @@ hns3_vlan_filter_configure(struct hns3_adapter *hns, uint16_t vlan_id, int on)
 	int ret = 0;
 
 	/*
-	 * When vlan filter is enabled, hardware regards vlan id 0 as the entry
-	 * for normal packet, deleting vlan id 0 is not allowed.
+	 * When vlan filter is enabled, hardware regards packets without vlan
+	 * as packets with vlan 0. So, to receive packets without vlan, vlan id
+	 * 0 is not allowed to be removed by rte_eth_dev_vlan_filter.
 	 */
 	if (on == 0 && vlan_id == 0)
 		return 0;
@@ -364,7 +365,7 @@ hns3_vlan_filter_configure(struct hns3_adapter *hns, uint16_t vlan_id, int on)
 		writen_to_tbl = true;
 	}
 
-	if (ret == 0 && vlan_id) {
+	if (ret == 0) {
 		if (on)
 			hns3_add_dev_vlan_table(hns, vlan_id, writen_to_tbl);
 		else
@@ -743,16 +744,6 @@ hns3_vlan_txvlan_cfg(struct hns3_adapter *hns, uint16_t port_base_vlan_state,
 	return ret;
 }
 
-static void
-hns3_store_port_base_vlan_info(struct hns3_adapter *hns, uint16_t pvid, int on)
-{
-	struct hns3_hw *hw = &hns->hw;
-
-	hw->port_base_vlan_cfg.state = on ?
-	    HNS3_PORT_BASE_VLAN_ENABLE : HNS3_PORT_BASE_VLAN_DISABLE;
-
-	hw->port_base_vlan_cfg.pvid = pvid;
-}
 
 static void
 hns3_rm_all_vlan_table(struct hns3_adapter *hns, bool is_del_list)
@@ -761,10 +752,10 @@ hns3_rm_all_vlan_table(struct hns3_adapter *hns, bool is_del_list)
 	struct hns3_pf *pf = &hns->pf;
 
 	LIST_FOREACH(vlan_entry, &pf->vlan_list, next) {
-		if (vlan_entry->hd_tbl_status)
+		if (vlan_entry->hd_tbl_status) {
 			hns3_set_port_vlan_filter(hns, vlan_entry->vlan_id, 0);
-
-		vlan_entry->hd_tbl_status = false;
+			vlan_entry->hd_tbl_status = false;
+		}
 	}
 
 	if (is_del_list) {
@@ -784,10 +775,10 @@ hns3_add_all_vlan_table(struct hns3_adapter *hns)
 	struct hns3_pf *pf = &hns->pf;
 
 	LIST_FOREACH(vlan_entry, &pf->vlan_list, next) {
-		if (!vlan_entry->hd_tbl_status)
+		if (!vlan_entry->hd_tbl_status) {
 			hns3_set_port_vlan_filter(hns, vlan_entry->vlan_id, 1);
-
-		vlan_entry->hd_tbl_status = true;
+			vlan_entry->hd_tbl_status = true;
+		}
 	}
 }
 
@@ -798,7 +789,7 @@ hns3_remove_all_vlan_table(struct hns3_adapter *hns)
 	int ret;
 
 	hns3_rm_all_vlan_table(hns, true);
-	if (hw->port_base_vlan_cfg.pvid != HNS3_INVLID_PVID) {
+	if (hw->port_base_vlan_cfg.pvid != HNS3_INVALID_PVID) {
 		ret = hns3_set_port_vlan_filter(hns,
 						hw->port_base_vlan_cfg.pvid, 0);
 		if (ret) {
@@ -811,40 +802,41 @@ hns3_remove_all_vlan_table(struct hns3_adapter *hns)
 
 static int
 hns3_update_vlan_filter_entries(struct hns3_adapter *hns,
-				uint16_t port_base_vlan_state,
-				uint16_t new_pvid, uint16_t old_pvid)
+			uint16_t port_base_vlan_state, uint16_t new_pvid)
 {
 	struct hns3_hw *hw = &hns->hw;
-	int ret = 0;
+	uint16_t old_pvid;
+	int ret;
 
 	if (port_base_vlan_state == HNS3_PORT_BASE_VLAN_ENABLE) {
-		if (old_pvid != HNS3_INVLID_PVID && old_pvid != 0) {
+		old_pvid = hw->port_base_vlan_cfg.pvid;
+		if (old_pvid != HNS3_INVALID_PVID) {
 			ret = hns3_set_port_vlan_filter(hns, old_pvid, 0);
 			if (ret) {
-				hns3_err(hw,
-					 "Failed to clear clear old pvid filter, ret =%d",
-					 ret);
+				hns3_err(hw, "failed to remove old pvid %u, "
+						"ret = %d", old_pvid, ret);
 				return ret;
 			}
 		}
 
 		hns3_rm_all_vlan_table(hns, false);
-		return hns3_set_port_vlan_filter(hns, new_pvid, 1);
-	}
-
-	if (new_pvid != 0) {
+		ret = hns3_set_port_vlan_filter(hns, new_pvid, 1);
+		if (ret) {
+			hns3_err(hw, "failed to add new pvid %u, ret = %d",
+					new_pvid, ret);
+			return ret;
+		}
+	} else {
 		ret = hns3_set_port_vlan_filter(hns, new_pvid, 0);
 		if (ret) {
-			hns3_err(hw, "Failed to set port vlan filter, ret =%d",
-				 ret);
+			hns3_err(hw, "failed to remove pvid %u, ret = %d",
+					new_pvid, ret);
 			return ret;
 		}
-	}
 
-	if (new_pvid == hw->port_base_vlan_cfg.pvid)
 		hns3_add_all_vlan_table(hns);
-
-	return ret;
+	}
+	return 0;
 }
 
 static int
@@ -883,11 +875,10 @@ hns3_vlan_pvid_configure(struct hns3_adapter *hns, uint16_t pvid, int on)
 {
 	struct hns3_hw *hw = &hns->hw;
 	uint16_t port_base_vlan_state;
-	uint16_t old_pvid;
 	int ret;
 
 	if (on == 0 && pvid != hw->port_base_vlan_cfg.pvid) {
-		if (hw->port_base_vlan_cfg.pvid != HNS3_INVLID_PVID)
+		if (hw->port_base_vlan_cfg.pvid != HNS3_INVALID_PVID)
 			hns3_warn(hw, "Invalid operation! As current pvid set "
 				  "is %u, disable pvid %u is invalid",
 				  hw->port_base_vlan_cfg.pvid, pvid);
@@ -910,19 +901,18 @@ hns3_vlan_pvid_configure(struct hns3_adapter *hns, uint16_t pvid, int on)
 		return ret;
 	}
 
-	if (pvid == HNS3_INVLID_PVID)
+	if (pvid == HNS3_INVALID_PVID)
 		goto out;
-	old_pvid = hw->port_base_vlan_cfg.pvid;
-	ret = hns3_update_vlan_filter_entries(hns, port_base_vlan_state, pvid,
-					      old_pvid);
+	ret = hns3_update_vlan_filter_entries(hns, port_base_vlan_state, pvid);
 	if (ret) {
-		hns3_err(hw, "Failed to update vlan filter entries, ret =%d",
+		hns3_err(hw, "failed to update vlan filter entries, ret = %d",
 			 ret);
 		return ret;
 	}
 
 out:
-	hns3_store_port_base_vlan_info(hns, pvid, on);
+	hw->port_base_vlan_cfg.state = port_base_vlan_state;
+	hw->port_base_vlan_cfg.pvid = on ? pvid : HNS3_INVALID_PVID;
 	return ret;
 }
 
@@ -968,20 +958,19 @@ hns3_vlan_pvid_set(struct rte_eth_dev *dev, uint16_t pvid, int on)
 	return 0;
 }
 
-static void
-init_port_base_vlan_info(struct hns3_hw *hw)
-{
-	hw->port_base_vlan_cfg.state = HNS3_PORT_BASE_VLAN_DISABLE;
-	hw->port_base_vlan_cfg.pvid = HNS3_INVLID_PVID;
-}
-
 static int
 hns3_default_vlan_config(struct hns3_adapter *hns)
 {
 	struct hns3_hw *hw = &hns->hw;
 	int ret;
 
-	ret = hns3_set_port_vlan_filter(hns, 0, 1);
+	/*
+	 * When vlan filter is enabled, hardware regards packets without vlan
+	 * as packets with vlan 0. Therefore, if vlan 0 is not in the vlan
+	 * table, packets without vlan won't be received. So, add vlan 0 as
+	 * the default vlan.
+	 */
+	ret = hns3_vlan_filter_configure(hns, 0, 1);
 	if (ret)
 		hns3_err(hw, "default vlan 0 config failed, ret =%d", ret);
 	return ret;
@@ -1000,8 +989,10 @@ hns3_init_vlan_config(struct hns3_adapter *hns)
 	 * ensure that the hardware configuration remains unchanged before and
 	 * after reset.
 	 */
-	if (rte_atomic16_read(&hw->reset.resetting) == 0)
-		init_port_base_vlan_info(hw);
+	if (rte_atomic16_read(&hw->reset.resetting) == 0) {
+		hw->port_base_vlan_cfg.state = HNS3_PORT_BASE_VLAN_DISABLE;
+		hw->port_base_vlan_cfg.pvid = HNS3_INVALID_PVID;
+	}
 
 	ret = hns3_vlan_filter_init(hns);
 	if (ret) {
@@ -1023,7 +1014,7 @@ hns3_init_vlan_config(struct hns3_adapter *hns)
 	 * and hns3_restore_vlan_conf later.
 	 */
 	if (rte_atomic16_read(&hw->reset.resetting) == 0) {
-		ret = hns3_vlan_pvid_configure(hns, HNS3_INVLID_PVID, 0);
+		ret = hns3_vlan_pvid_configure(hns, HNS3_INVALID_PVID, 0);
 		if (ret) {
 			hns3_err(hw, "pvid set fail in pf, ret =%d", ret);
 			return ret;
-- 
2.9.5


  parent reply	other threads:[~2020-09-22 12:04 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-22  8:53 [dpdk-dev] [PATCH 00/17] updates for hns3 PMD driver Wei Hu (Xavier)
2020-09-22  8:53 ` [dpdk-dev] [PATCH 01/17] net/hns3: add VLAN configuration compatibility Wei Hu (Xavier)
2020-09-22  8:53 ` [dpdk-dev] [PATCH 02/17] net/hns3: fix default VLAN won't be deleted when set PF PVID Wei Hu (Xavier)
2020-09-22  8:53 ` [dpdk-dev] [PATCH 03/17] net/hns3: add default branch to switch in Rx VLAN processing Wei Hu (Xavier)
2020-09-22  8:53 ` [dpdk-dev] [PATCH 04/17] net/hns3: add max number of segs compatibility Wei Hu (Xavier)
2020-09-22  8:53 ` [dpdk-dev] [PATCH 05/17] net/hns3: add TSO pseudo header calculation compatibility Wei Hu (Xavier)
2020-09-22  8:53 ` [dpdk-dev] [PATCH 06/17] net/hns3: avoid accessing nonexistent VF reg when PF in FLR Wei Hu (Xavier)
2020-09-22  8:53 ` [dpdk-dev] [PATCH 07/17] net/hns3: add default branch to switch when parsing fd tuple Wei Hu (Xavier)
2020-09-22  8:53 ` [dpdk-dev] [PATCH 08/17] net/hns3: add break to exit loop when err stat item found Wei Hu (Xavier)
2020-09-22  8:53 ` [dpdk-dev] [PATCH 09/17] net/hns3: support flow action of queue region Wei Hu (Xavier)
2020-09-22  8:53 ` [dpdk-dev] [PATCH 10/17] net/hns3: support querying RSS flow rule Wei Hu (Xavier)
2020-09-22  8:53 ` [dpdk-dev] [PATCH 11/17] net/hns3: check input RSS type when creating flow with RSS Wei Hu (Xavier)
2020-09-22  8:53 ` [dpdk-dev] [PATCH 12/17] net/hns3: set RSS hash type input configuration Wei Hu (Xavier)
2020-09-22  8:53 ` [dpdk-dev] [PATCH 13/17] net/hns3: fix config when creating RSS rule after flush Wei Hu (Xavier)
2020-09-22  8:53 ` [dpdk-dev] [PATCH 14/17] net/hns3: fix flow RSS queue num with 0 Wei Hu (Xavier)
2020-09-22  8:53 ` [dpdk-dev] [PATCH 15/17] net/hns3: fix flushing RSS rule Wei Hu (Xavier)
2020-09-22  8:54 ` [dpdk-dev] [PATCH 16/17] net/hns3: fix configuring device with RSS is enabled Wei Hu (Xavier)
2020-09-22  8:54 ` [dpdk-dev] [PATCH 17/17] net/hns3: fix storing RSS info when creating flow action Wei Hu (Xavier)
2020-09-22 12:03 ` [dpdk-dev] [PATCH v2 00/17] updates for hns3 PMD driver Wei Hu (Xavier)
2020-09-22 12:03   ` [dpdk-dev] [PATCH v2 01/17] net/hns3: add VLAN configuration compatibility Wei Hu (Xavier)
2020-09-22 12:03   ` Wei Hu (Xavier) [this message]
2020-09-22 12:03   ` [dpdk-dev] [PATCH v2 03/17] net/hns3: add default branch to switch in Rx VLAN processing Wei Hu (Xavier)
2020-09-22 12:03   ` [dpdk-dev] [PATCH v2 04/17] net/hns3: add max number of segs compatibility Wei Hu (Xavier)
2020-09-22 12:03   ` [dpdk-dev] [PATCH v2 05/17] net/hns3: add TSO pseudo header calculation compatibility Wei Hu (Xavier)
2020-09-22 12:03   ` [dpdk-dev] [PATCH v2 06/17] net/hns3: avoid accessing nonexistent VF reg when PF in FLR Wei Hu (Xavier)
2020-09-22 12:03   ` [dpdk-dev] [PATCH v2 07/17] net/hns3: add default branch to switch when parsing fd tuple Wei Hu (Xavier)
2020-09-22 12:03   ` [dpdk-dev] [PATCH v2 08/17] net/hns3: add break to exit loop when err stat item found Wei Hu (Xavier)
2020-09-22 12:03   ` [dpdk-dev] [PATCH v2 09/17] net/hns3: support flow action of queue region Wei Hu (Xavier)
2020-09-22 12:03   ` [dpdk-dev] [PATCH v2 10/17] net/hns3: support querying RSS flow rule Wei Hu (Xavier)
2020-09-22 12:03   ` [dpdk-dev] [PATCH v2 11/17] net/hns3: check input RSS type when creating flow with RSS Wei Hu (Xavier)
2020-09-22 12:03   ` [dpdk-dev] [PATCH v2 12/17] net/hns3: set RSS hash type input configuration Wei Hu (Xavier)
2020-09-22 12:03   ` [dpdk-dev] [PATCH v2 13/17] net/hns3: fix config when creating RSS rule after flush Wei Hu (Xavier)
2020-09-22 12:03   ` [dpdk-dev] [PATCH v2 14/17] net/hns3: fix flow RSS queue num with 0 Wei Hu (Xavier)
2020-09-22 12:03   ` [dpdk-dev] [PATCH v2 15/17] net/hns3: fix flushing RSS rule Wei Hu (Xavier)
2020-09-22 12:03   ` [dpdk-dev] [PATCH v2 16/17] net/hns3: fix configuring device with RSS is enabled Wei Hu (Xavier)
2020-09-22 12:03   ` [dpdk-dev] [PATCH v2 17/17] net/hns3: fix storing RSS info when creating flow action Wei Hu (Xavier)
2020-09-28 13:29   ` [dpdk-dev] [PATCH v2 00/17] updates for hns3 PMD driver 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=20200922120329.21185-3-huwei013@chinasoftinc.com \
    --to=huwei013@chinasoftinc.com \
    --cc=dev@dpdk.org \
    --cc=xavier.huwei@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).