From patchwork Mon Sep 14 17:35:37 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sven Eckelmann X-Patchwork-Id: 517509 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from arrakis.dune.hu (arrakis.dune.hu [78.24.191.176]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 7C49B14017E for ; Tue, 15 Sep 2015 03:37:36 +1000 (AEST) Received: from arrakis.dune.hu (localhost [127.0.0.1]) by arrakis.dune.hu (Postfix) with ESMTP id 149DD28BC4F; Mon, 14 Sep 2015 19:36:02 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on arrakis.dune.hu X-Spam-Level: X-Spam-Status: No, score=-1.5 required=5.0 tests=BAYES_00, T_RP_MATCHES_RCVD autolearn=unavailable version=3.3.2 Received: from arrakis.dune.hu (localhost [127.0.0.1]) by arrakis.dune.hu (Postfix) with ESMTP id 1BB33287BA5 for ; Mon, 14 Sep 2015 19:35:52 +0200 (CEST) X-policyd-weight: using cached result; rate: -7.6 Received: from v3-1039.vlinux.de (narfation.org [79.140.41.39]) by arrakis.dune.hu (Postfix) with ESMTPS for ; Mon, 14 Sep 2015 19:35:48 +0200 (CEST) Received: from sven-desktop.home.narfation.org (x4d0d52c3.dyn.telefonica.de [77.13.82.195]) by v3-1039.vlinux.de (Postfix) with ESMTPSA id 4F3071100F9; Mon, 14 Sep 2015 19:36:52 +0200 (CEST) From: Sven Eckelmann To: openwrt-devel@lists.openwrt.org Date: Mon, 14 Sep 2015 19:35:37 +0200 Message-Id: <1442252137-25108-1-git-send-email-sven@open-mesh.com> X-Mailer: git-send-email 2.5.1 Cc: Sven Eckelmann , marek@open-mesh.com Subject: [OpenWrt-Devel] [RFC] ralink: Allow to receive vlan over untag ports on MT7530 X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: OpenWrt Development List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: openwrt-devel-bounces@lists.openwrt.org Sender: "openwrt-devel" The MT7530 switch driver with enable_vlan set will automatically set all ports to the user port mode. The hardware will remove the incoming vlan tag on these ports and use it for its internal vlan. This is usually not wanted and makes it impossible to communicate via vlan over the switch in both directions. It is possible to configure a switch port to "transparent mode" when this port is only used as untag in the switch VLANs. This will disable the VLAN untagging of packets when they were received on this port. The tagging on "tag" ports based on the vlan id is still working. The transparent port mode cannot be used when a port is both used in a VLAN as "tag" and in another one as "untag" port. The problem with this approach is the limit of the MTU of 1496 bytes for the VLAN device on top of eth0.X. Larger packets can still be send but will not be received. Signed-off-by: Sven Eckelmann --- .../files/drivers/net/ethernet/ralink/mt7530.c | 36 ++++++++++++++++++++-- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/target/linux/ramips/files/drivers/net/ethernet/ralink/mt7530.c b/target/linux/ramips/files/drivers/net/ethernet/ralink/mt7530.c index 51e16f2..4e00315 100644 --- a/target/linux/ramips/files/drivers/net/ethernet/ralink/mt7530.c +++ b/target/linux/ramips/files/drivers/net/ethernet/ralink/mt7530.c @@ -484,6 +484,8 @@ mt7530_apply_config(struct switch_dev *dev) { struct mt7530_priv *priv = container_of(dev, struct mt7530_priv, swdev); int i, j; + u8 tag_ports; + u8 untag_ports; if (!priv->global_vlan_enable) { for (i = 0; i < MT7530_NUM_PORTS; i++) @@ -499,9 +501,37 @@ mt7530_apply_config(struct switch_dev *dev) for (i = 0; i < MT7530_NUM_PORTS; i++) mt7530_w32(priv, REG_ESW_PORT_PCR(i), 0x00ff0003); - /* set all ports as user port */ - for (i = 0; i < MT7530_NUM_PORTS; i++) - mt7530_w32(priv, REG_ESW_PORT_PVC(i), 0x81000000); + /* check if a port is used in tag/untag vlan egress mode */ + tag_ports = 0; + untag_ports = 0; + + for (i = 0; i < MT7530_NUM_VLANS; i++) { + u8 member = priv->vlan_entries[i].member; + u8 etags = priv->vlan_entries[i].etags; + + if (!member) + continue; + + for (j = 0; j < MT7530_NUM_PORTS; j++) { + if (!(member & BIT(j))) + continue; + + if (etags & BIT(j)) + tag_ports |= 1u << j; + else + untag_ports |= 1u << j; + } + } + + /* set all untag-only ports as transparent and the rest as user port */ + for (i = 0; i < MT7530_NUM_PORTS; i++) { + u32 pvc_mode = 0x81000000; + + if (untag_ports & BIT(i) && !(tag_ports & BIT(i))) + pvc_mode = 0x810000c0; + + mt7530_w32(priv, REG_ESW_PORT_PVC(i), pvc_mode); + } for (i = 0; i < MT7530_NUM_VLANS; i++) { u16 vid = priv->vlan_entries[i].vid;