From f42a338de65dc32684d26cca106853eb3e888fde Mon Sep 17 00:00:00 2001
From: John Crispin <john@phrozen.org>
Date: Thu, 8 Apr 2021 10:46:29 +0200
Subject: [PATCH 52/83] Revert "ipq40xx: revert usage of VLAN S-TAG"

This reverts commit cdc8d4b46f0811292fffc6094acd81e854b5f4a5.

Signed-off-by: John Crispin <john@phrozen.org>
---
 .../net/ethernet/qualcomm/essedma/edma_axi.c  | 19 +++++++++----
 .../ipq40xx/files/drivers/net/phy/ar40xx.c    | 27 ++++++++++++++++---
 2 files changed, 37 insertions(+), 9 deletions(-)

diff --git a/target/linux/ipq40xx/files/drivers/net/ethernet/qualcomm/essedma/edma_axi.c b/target/linux/ipq40xx/files/drivers/net/ethernet/qualcomm/essedma/edma_axi.c
index af55ee4dd5..9dc38bcfcc 100644
--- a/target/linux/ipq40xx/files/drivers/net/ethernet/qualcomm/essedma/edma_axi.c
+++ b/target/linux/ipq40xx/files/drivers/net/ethernet/qualcomm/essedma/edma_axi.c
@@ -952,7 +952,7 @@ static int edma_axi_probe(struct platform_device *pdev)
 		edma_netdev[i]->max_mtu = 9000;
 		edma_netdev[i]->features = NETIF_F_HW_CSUM | NETIF_F_RXCSUM
 				      | NETIF_F_HW_VLAN_CTAG_RX | NETIF_F_SG |
-				      NETIF_F_TSO | NETIF_F_GRO | NETIF_F_HW_VLAN_CTAG_TX;
+				      NETIF_F_TSO | NETIF_F_GRO;
 		edma_netdev[i]->hw_features = NETIF_F_HW_CSUM | NETIF_F_RXCSUM |
 				NETIF_F_HW_VLAN_CTAG_RX
 				| NETIF_F_SG | NETIF_F_TSO | NETIF_F_GRO;
@@ -961,11 +961,20 @@ static int edma_axi_probe(struct platform_device *pdev)
 		edma_netdev[i]->wanted_features = NETIF_F_HW_CSUM | NETIF_F_SG |
 					     NETIF_F_TSO | NETIF_F_GRO;
 
+		if (of_property_read_bool(np, "qcom,single-phy") && edma_cinfo->num_gmac == 1)
+			edma_netdev[i]->features |= NETIF_F_HW_VLAN_CTAG_TX;
+
 #ifdef CONFIG_RFS_ACCEL
-		edma_netdev[i]->features |=  NETIF_F_NTUPLE | NETIF_F_RXHASH;
-		edma_netdev[i]->hw_features |=  NETIF_F_NTUPLE | NETIF_F_RXHASH;
-		edma_netdev[i]->vlan_features |= NETIF_F_NTUPLE | NETIF_F_RXHASH;
-		edma_netdev[i]->wanted_features |= NETIF_F_NTUPLE | NETIF_F_RXHASH;
+		edma_netdev[i]->features |=  NETIF_F_NTUPLE;
+		edma_netdev[i]->hw_features |=  NETIF_F_NTUPLE;
+		edma_netdev[i]->vlan_features |= NETIF_F_NTUPLE;
+		edma_netdev[i]->wanted_features |= NETIF_F_NTUPLE;
+		if (of_property_read_bool(np, "qcom,single-phy") && edma_cinfo->num_gmac == 1) {
+			edma_netdev[i]->features |= NETIF_F_RXHASH;
+			edma_netdev[i]->hw_features |= NETIF_F_RXHASH;
+			edma_netdev[i]->vlan_features |= NETIF_F_RXHASH;
+			edma_netdev[i]->wanted_features |= NETIF_F_RXHASH;
+		}
 #endif
 		edma_set_ethtool_ops(edma_netdev[i]);
 
diff --git a/target/linux/ipq40xx/files/drivers/net/phy/ar40xx.c b/target/linux/ipq40xx/files/drivers/net/phy/ar40xx.c
index ca7f0ca350..8b3ae53bd9 100644
--- a/target/linux/ipq40xx/files/drivers/net/phy/ar40xx.c
+++ b/target/linux/ipq40xx/files/drivers/net/phy/ar40xx.c
@@ -1200,7 +1200,11 @@ ar40xx_init_port(struct ar40xx_priv *priv, int port)
 
 	ar40xx_write(priv, AR40XX_REG_PORT_STATUS(port), 0);
 
-	ar40xx_write(priv, AR40XX_REG_PORT_HEADER(port), 0);
+	/* CPU port is setting headers to limit output ports */
+	if (port == 0)
+		ar40xx_write(priv, AR40XX_REG_PORT_HEADER(port), 0x8);
+	else
+		ar40xx_write(priv, AR40XX_REG_PORT_HEADER(port), 0);
 
 	ar40xx_write(priv, AR40XX_REG_PORT_VLAN0(port), 0);
 
@@ -1243,6 +1247,10 @@ ar40xx_init_globals(struct ar40xx_priv *priv)
 	t = (AR40XX_PORT0_FC_THRESH_ON_DFLT << 16) |
 	      AR40XX_PORT0_FC_THRESH_OFF_DFLT;
 	ar40xx_write(priv, AR40XX_REG_PORT_FLOWCTRL_THRESH(0), t);
+
+	/* set service tag to 802.1q */
+	t = ETH_P_8021Q | AR40XX_ESS_SERVICE_TAG_STAG;
+	ar40xx_write(priv, AR40XX_ESS_SERVICE_TAG, t);
 }
 
 static int
@@ -1530,7 +1538,10 @@ ar40xx_setup_port(struct ar40xx_priv *priv, int port, u32 members)
 	u32 pvid = priv->vlan_id[priv->pvid[port]];
 
 	if (priv->vlan) {
-		egress = AR40XX_PORT_VLAN1_OUT_MODE_UNMOD;
+		if (priv->vlan_tagged & BIT(port))
+			egress = AR40XX_PORT_VLAN1_OUT_MODE_TAG;
+		else
+			egress = AR40XX_PORT_VLAN1_OUT_MODE_UNMOD;
 
 		ingress = AR40XX_IN_SECURE;
 	} else {
@@ -1542,8 +1553,16 @@ ar40xx_setup_port(struct ar40xx_priv *priv, int port, u32 members)
 	t |= pvid << AR40XX_PORT_VLAN0_DEF_CVID_S;
 	ar40xx_write(priv, AR40XX_REG_PORT_VLAN0(port), t);
 
-	t = AR40XX_PORT_VLAN1_PORT_VLAN_PROP;
-	t |= egress << AR40XX_PORT_VLAN1_OUT_MODE_S;
+	t = egress << AR40XX_PORT_VLAN1_OUT_MODE_S;
+
+	/* set CPU port to core port */
+	if (port == 0)
+		t |= AR40XX_PORT_VLAN1_CORE_PORT;
+
+	if (priv->vlan_tagged & BIT(port))
+		t |= AR40XX_PORT_VLAN1_PORT_VLAN_PROP;
+	else
+		t |= AR40XX_PORT_VLAN1_PORT_TLS_MODE;
 
 	ar40xx_write(priv, AR40XX_REG_PORT_VLAN1(port), t);
 
-- 
2.25.1

