linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Huazhong Tan <tanhuazhong@huawei.com>
To: <davem@davemloft.net>
Cc: <netdev@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
	<salil.mehta@huawei.com>, <yisen.zhuang@huawei.com>,
	<linuxarm@huawei.com>, Jian Shen <shenjian15@huawei.com>,
	Huazhong Tan <tanhuazhong@huawei.com>
Subject: [PATCH net-next 02/12] net: hns3: fix VLAN offload handle for VLAN inserted by port
Date: Thu, 11 Apr 2019 20:25:21 +0800	[thread overview]
Message-ID: <1554985531-1827-3-git-send-email-tanhuazhong@huawei.com> (raw)
In-Reply-To: <1554985531-1827-1-git-send-email-tanhuazhong@huawei.com>

From: Jian Shen <shenjian15@huawei.com>

When port based VLAN enabled, hardware will insert VLAN automatically
when send packets, driver needs to fill the VLAN from skb or from
port to different areas in TX BD. For RX packets, hardware can
strip two VLAN headers, and fill them into RX BD, driver needs
to identify which one should be send to skb, and drop the port
based VLAN id.

Signed-off-by: Jian Shen <shenjian15@huawei.com>
Signed-off-by: Huazhong Tan <tanhuazhong@huawei.com>
---
 drivers/net/ethernet/hisilicon/hns3/hnae3.h        |  2 +
 drivers/net/ethernet/hisilicon/hns3/hns3_enet.c    | 54 +++++++++++++++++++---
 .../ethernet/hisilicon/hns3/hns3pf/hclge_main.c    | 10 +++-
 3 files changed, 58 insertions(+), 8 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hnae3.h b/drivers/net/ethernet/hisilicon/hns3/hnae3.h
index f21932c..681c175 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hnae3.h
+++ b/drivers/net/ethernet/hisilicon/hns3/hnae3.h
@@ -585,6 +585,8 @@ struct hnae3_handle {
 
 	u32 numa_node_mask;	/* for multi-chip support */
 
+	enum hnae3_port_base_vlan_state port_base_vlan_state;
+
 	u8 netdev_flags;
 	struct dentry *hnae3_dbgfs;
 };
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
index b53b091..04eca3a 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
@@ -963,6 +963,16 @@ static int hns3_fill_desc_vtags(struct sk_buff *skb,
 {
 #define HNS3_TX_VLAN_PRIO_SHIFT 13
 
+	struct hnae3_handle *handle = tx_ring->tqp->handle;
+
+	/* By hw limitation, if port base insert vlan enabled, only one vlan
+	 * header is allowed in skb; otherwise it will cause ras error.
+	 */
+	if (unlikely(skb_vlan_tagged_multi(skb) &&
+		     handle->port_base_vlan_state ==
+		     HNAE3_PORT_BASE_VLAN_ENABLE))
+		return -EINVAL;
+
 	if (skb->protocol == htons(ETH_P_8021Q) &&
 	    !(tx_ring->tqp->handle->kinfo.netdev->features &
 	    NETIF_F_HW_VLAN_CTAG_TX)) {
@@ -984,10 +994,18 @@ static int hns3_fill_desc_vtags(struct sk_buff *skb,
 		 * and use inner_vtag in one tag case.
 		 */
 		if (skb->protocol == htons(ETH_P_8021Q)) {
-			hns3_set_field(*out_vlan_flag, HNS3_TXD_OVLAN_B, 1);
-			*out_vtag = vlan_tag;
+			if (handle->port_base_vlan_state ==
+			    HNAE3_PORT_BASE_VLAN_DISABLE){
+				hnae3_set_bit(*out_vlan_flag, HNS3_TXD_OVLAN_B,
+					      1);
+				*out_vtag = vlan_tag;
+			} else {
+				hnae3_set_bit(*inner_vlan_flag, HNS3_TXD_VLAN_B,
+					      1);
+				*inner_vtag = vlan_tag;
+			}
 		} else {
-			hns3_set_field(*inner_vlan_flag, HNS3_TXD_VLAN_B, 1);
+			hnae3_set_bit(*inner_vlan_flag, HNS3_TXD_VLAN_B, 1);
 			*inner_vtag = vlan_tag;
 		}
 	} else if (skb->protocol == htons(ETH_P_8021Q)) {
@@ -2390,6 +2408,7 @@ static bool hns3_parse_vlan_tag(struct hns3_enet_ring *ring,
 				struct hns3_desc *desc, u32 l234info,
 				u16 *vlan_tag)
 {
+	struct hnae3_handle *handle = ring->tqp->handle;
 	struct pci_dev *pdev = ring->tqp->handle->pdev;
 
 	if (pdev->revision == 0x20) {
@@ -2402,14 +2421,37 @@ static bool hns3_parse_vlan_tag(struct hns3_enet_ring *ring,
 
 #define HNS3_STRP_OUTER_VLAN	0x1
 #define HNS3_STRP_INNER_VLAN	0x2
+#define HNS3_STRP_BOTH		0x3
 
+	/* Hardware always insert vlan tag into rx descriptor when
+	 * remove the tag from packet, driver needs to determin
+	 * reporting which tag to stack.
+	 */
 	switch (hnae3_get_field(l234info, HNS3_RXD_STRP_TAGP_M,
 				HNS3_RXD_STRP_TAGP_S)) {
 	case HNS3_STRP_OUTER_VLAN:
-		*vlan_tag = le16_to_cpu(desc->rx.ot_vlan_tag);
-		return true;
+		if (handle->port_base_vlan_state ==
+				HNAE3_PORT_BASE_VLAN_DISABLE) {
+			*vlan_tag = le16_to_cpu(desc->rx.ot_vlan_tag);
+			return true;
+		}
+
+		return false;
 	case HNS3_STRP_INNER_VLAN:
-		*vlan_tag = le16_to_cpu(desc->rx.vlan_tag);
+		if (handle->port_base_vlan_state ==
+				HNAE3_PORT_BASE_VLAN_DISABLE) {
+			*vlan_tag = le16_to_cpu(desc->rx.vlan_tag);
+			return true;
+		}
+
+		return false;
+	case HNS3_STRP_BOTH:
+		if (handle->port_base_vlan_state ==
+				HNAE3_PORT_BASE_VLAN_DISABLE)
+			*vlan_tag = le16_to_cpu(desc->rx.ot_vlan_tag);
+		else
+			*vlan_tag = le16_to_cpu(desc->rx.vlan_tag);
+
 		return true;
 	default:
 		return false;
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
index cd7318b..1f3c41d 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
@@ -6914,10 +6914,16 @@ int hclge_en_hw_strip_rxvtag(struct hnae3_handle *handle, bool enable)
 {
 	struct hclge_vport *vport = hclge_get_vport(handle);
 
-	vport->rxvlan_cfg.strip_tag1_en = false;
-	vport->rxvlan_cfg.strip_tag2_en = enable;
+	if (vport->port_base_vlan_cfg.state == HNAE3_PORT_BASE_VLAN_DISABLE) {
+		vport->rxvlan_cfg.strip_tag1_en = false;
+		vport->rxvlan_cfg.strip_tag2_en = enable;
+	} else {
+		vport->rxvlan_cfg.strip_tag1_en = enable;
+		vport->rxvlan_cfg.strip_tag2_en = true;
+	}
 	vport->rxvlan_cfg.vlan1_vlan_prionly = false;
 	vport->rxvlan_cfg.vlan2_vlan_prionly = false;
+	vport->rxvlan_cfg.rx_vlan_offload_en = enable;
 
 	return hclge_set_vlan_rx_offload_cfg(vport);
 }
-- 
2.7.4


  parent reply	other threads:[~2019-04-11 12:28 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-11 12:25 [PATCH net-next 00/12] code optimizations & bugfixes for HNS3 driver Huazhong Tan
2019-04-11 12:25 ` [PATCH net-next 01/12] net: hns3: fix VLAN initialization to be compatible with port base insert VLAN Huazhong Tan
2019-04-11 18:20   ` David Miller
2019-04-12  2:30     ` tanhuazhong
2019-04-12  4:26       ` David Miller
2019-04-11 12:25 ` Huazhong Tan [this message]
2019-04-11 12:25 ` [PATCH net-next 03/12] net: hns3: fix set port based VLAN for PF Huazhong Tan
2019-04-11 12:25 ` [PATCH net-next 04/12] net: hns3: fix set port based VLAN issue for VF Huazhong Tan
2019-04-11 12:25 ` [PATCH net-next 05/12] net: hns3: minor refactor for hns3_rx_checksum Huazhong Tan
2019-04-11 12:25 ` [PATCH net-next 06/12] net: hns3: add hns3_gro_complete for HW GRO process Huazhong Tan
2019-04-11 12:25 ` [PATCH net-next 07/12] net: hns3: always assume no drop TC for performance reason Huazhong Tan
2019-04-11 12:25 ` [PATCH net-next 08/12] net: hns3: divide shared buffer between TC Huazhong Tan
2019-04-11 12:25 ` [PATCH net-next 09/12] net: hns3: set dividual reset level for all RAS and MSI-X errors Huazhong Tan
2019-04-11 12:25 ` [PATCH net-next 10/12] net: hns3: do not initialize MDIO bus when PHY is inexistent Huazhong Tan
2019-04-11 12:25 ` [PATCH net-next 11/12] net: hns3: free the pending skb when clean RX ring Huazhong Tan
2019-04-11 12:25 ` [PATCH net-next 12/12] net: hns3: code optimization for command queue' spin lock Huazhong Tan

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=1554985531-1827-3-git-send-email-tanhuazhong@huawei.com \
    --to=tanhuazhong@huawei.com \
    --cc=davem@davemloft.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linuxarm@huawei.com \
    --cc=netdev@vger.kernel.org \
    --cc=salil.mehta@huawei.com \
    --cc=shenjian15@huawei.com \
    --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).