From patchwork Fri Aug 6 03:47:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qingfang Deng X-Patchwork-Id: 12422609 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 518F6C4338F for ; Fri, 6 Aug 2021 03:47:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 21FCB61159 for ; Fri, 6 Aug 2021 03:47:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242637AbhHFDrn (ORCPT ); Thu, 5 Aug 2021 23:47:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53838 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231173AbhHFDrk (ORCPT ); Thu, 5 Aug 2021 23:47:40 -0400 Received: from mail-pj1-x1034.google.com (mail-pj1-x1034.google.com [IPv6:2607:f8b0:4864:20::1034]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9EF21C061798; Thu, 5 Aug 2021 20:47:24 -0700 (PDT) Received: by mail-pj1-x1034.google.com with SMTP id b1-20020a17090a8001b029017700de3903so11069101pjn.1; Thu, 05 Aug 2021 20:47:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=wRjfmIu1ztv3rpF9qempW092Tg0Ic9nW64q0L4U0+XM=; b=hsSIzfO4YdxtdYgjEL49PetbJFrHtI+H437tpeBWWAGaDnmpCThKq5vk4hq9Mesruq Z0s8/XY/pzTiUjnT0uuTwIeZGJfDYe3E8pBpZU4bqijj43TYGB1sriJqQHgUUqCuOpdL 3exrENopXv6xRcJ0Xm66EsjblaxR8+YwDYzvaXu6eEBNogbrV7cNC7cl2Wfl7RKHS2kc iLQ3KQh1u+CI43c65RcyMqwxyGYB2/sAW27+f8GxlBXZXlPp8118kyXpgNIHuuPuZqTJ c9Y8Sjv6nhrAOzebYAeXNpOiPQuRMc7PJ8f3Yt1iXDdGopiH+yvPZKam1FOgJEdMUp6r he8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=wRjfmIu1ztv3rpF9qempW092Tg0Ic9nW64q0L4U0+XM=; b=E7L9f62jSoyttdAXYgRLudaMRuqBA0s500iQnFwEDsZBSjo1mhUPXzUJNCJk3x7cSr eebYxn3OnX3rBNmnzFM1WPOdaECRkcB3hayjFAWo/EMWiMyNmmd3Lw9sFO54Zd0jK5LL sshpkTliCpbk8iAfrI+yvnfU5zO4et7/p5yvkc/aOLnrgNyPQWy9yWUksH7KuHGXRp/y q8GClIPUlp/9iwgppAsqNlqqObWo03ANCARCNV+w126jlWEUzVEfV1Su3sKUPm5S+iG6 yR8VIayFsNXHNiRRneRIBYUhw5pG5nIpNzJLJjGM2PN1WFYwIepdQ9aSnWv3sJKcIHXl 9DSw== X-Gm-Message-State: AOAM5302RiCKJpU3wu+DZwrqeO9R+4HSQWVxfNoERu/HUE2KLrJZ7aqR MrijN+g4WXRmL97cNkf/p+8= X-Google-Smtp-Source: ABdhPJxwv6rRE8p2TJYj8mRBp+eNNzdwKgjhixJvicNtSX0ZYgam5OoMeQFKHRT0/UIsKcYjOBN4pg== X-Received: by 2002:aa7:961d:0:b029:3bc:dbdd:7a9b with SMTP id q29-20020aa7961d0000b02903bcdbdd7a9bmr8427782pfg.32.1628221643926; Thu, 05 Aug 2021 20:47:23 -0700 (PDT) Received: from haswell-ubuntu20.lan ([138.197.212.246]) by smtp.gmail.com with ESMTPSA id y7sm7723301pfi.204.2021.08.05.20.47.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Aug 2021 20:47:23 -0700 (PDT) From: DENG Qingfang To: Sean Wang , Landen Chao , Andrew Lunn , Vivien Didelot , Florian Fainelli , Vladimir Oltean , "David S. Miller" , Jakub Kicinski , Matthias Brugger , netdev@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next v2] net: dsa: mt7530: drop untagged frames on VLAN-aware ports without PVID Date: Fri, 6 Aug 2021 11:47:11 +0800 Message-Id: <20210806034713.734853-1-dqfext@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org The driver currently still accepts untagged frames on VLAN-aware ports without PVID. Use PVC.ACC_FRM to drop untagged frames in that case. Signed-off-by: DENG Qingfang --- v1 -> v2: Avoid setting PVID to 0 on the CPU port. drivers/net/dsa/mt7530.c | 32 ++++++++++++++++++++++++++++++-- drivers/net/dsa/mt7530.h | 7 +++++++ 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/drivers/net/dsa/mt7530.c b/drivers/net/dsa/mt7530.c index 385e169080d9..07db71f129ee 100644 --- a/drivers/net/dsa/mt7530.c +++ b/drivers/net/dsa/mt7530.c @@ -1257,9 +1257,11 @@ mt7530_port_set_vlan_unaware(struct dsa_switch *ds, int port) mt7530_rmw(priv, MT7530_PCR_P(port), PCR_PORT_VLAN_MASK, MT7530_PORT_FALLBACK_MODE); - mt7530_rmw(priv, MT7530_PVC_P(port), VLAN_ATTR_MASK | PVC_EG_TAG_MASK, + mt7530_rmw(priv, MT7530_PVC_P(port), + VLAN_ATTR_MASK | PVC_EG_TAG_MASK | ACC_FRM_MASK, VLAN_ATTR(MT7530_VLAN_TRANSPARENT) | - PVC_EG_TAG(MT7530_VLAN_EG_CONSISTENT)); + PVC_EG_TAG(MT7530_VLAN_EG_CONSISTENT) | + MT7530_VLAN_ACC_ALL); /* Set PVID to 0 */ mt7530_rmw(priv, MT7530_PPBV1_P(port), G0_PORT_VID_MASK, @@ -1297,6 +1299,11 @@ mt7530_port_set_vlan_aware(struct dsa_switch *ds, int port) MT7530_PORT_SECURITY_MODE); mt7530_rmw(priv, MT7530_PPBV1_P(port), G0_PORT_VID_MASK, G0_PORT_VID(priv->ports[port].pvid)); + + /* Only accept tagged frames if PVID is not set */ + if (!priv->ports[port].pvid) + mt7530_rmw(priv, MT7530_PVC_P(port), ACC_FRM_MASK, + MT7530_VLAN_ACC_TAGGED); } /* Set the port as a user port which is to be able to recognize VID @@ -1624,11 +1631,26 @@ mt7530_port_vlan_add(struct dsa_switch *ds, int port, if (pvid) { priv->ports[port].pvid = vlan->vid; + /* Accept all frames if PVID is set */ + mt7530_rmw(priv, MT7530_PVC_P(port), ACC_FRM_MASK, + MT7530_VLAN_ACC_ALL); + /* Only configure PVID if VLAN filtering is enabled */ if (dsa_port_is_vlan_filtering(dsa_to_port(ds, port))) mt7530_rmw(priv, MT7530_PPBV1_P(port), G0_PORT_VID_MASK, G0_PORT_VID(vlan->vid)); + } else if (vlan->vid && priv->ports[port].pvid == vlan->vid) { + /* This VLAN is overwritten without PVID, so unset it */ + priv->ports[port].pvid = G0_PORT_VID_DEF; + + /* Only accept tagged frames if the port is VLAN-aware */ + if (dsa_port_is_vlan_filtering(dsa_to_port(ds, port))) + mt7530_rmw(priv, MT7530_PVC_P(port), ACC_FRM_MASK, + MT7530_VLAN_ACC_TAGGED); + + mt7530_rmw(priv, MT7530_PPBV1_P(port), G0_PORT_VID_MASK, + G0_PORT_VID_DEF); } mutex_unlock(&priv->reg_mutex); @@ -1654,6 +1676,12 @@ mt7530_port_vlan_del(struct dsa_switch *ds, int port, */ if (priv->ports[port].pvid == vlan->vid) { priv->ports[port].pvid = G0_PORT_VID_DEF; + + /* Only accept tagged frames if the port is VLAN-aware */ + if (dsa_port_is_vlan_filtering(dsa_to_port(ds, port))) + mt7530_rmw(priv, MT7530_PVC_P(port), ACC_FRM_MASK, + MT7530_VLAN_ACC_TAGGED); + mt7530_rmw(priv, MT7530_PPBV1_P(port), G0_PORT_VID_MASK, G0_PORT_VID_DEF); } diff --git a/drivers/net/dsa/mt7530.h b/drivers/net/dsa/mt7530.h index 4a91d80f51bb..fe4cd2ac26d0 100644 --- a/drivers/net/dsa/mt7530.h +++ b/drivers/net/dsa/mt7530.h @@ -238,6 +238,7 @@ enum mt7530_port_mode { #define PVC_EG_TAG_MASK PVC_EG_TAG(7) #define VLAN_ATTR(x) (((x) & 0x3) << 6) #define VLAN_ATTR_MASK VLAN_ATTR(3) +#define ACC_FRM_MASK GENMASK(1, 0) enum mt7530_vlan_port_eg_tag { MT7530_VLAN_EG_DISABLED = 0, @@ -249,6 +250,12 @@ enum mt7530_vlan_port_attr { MT7530_VLAN_TRANSPARENT = 3, }; +enum mt7530_vlan_port_acc_frm { + MT7530_VLAN_ACC_ALL = 0, + MT7530_VLAN_ACC_TAGGED = 1, + MT7530_VLAN_ACC_UNTAGGED = 2, +}; + #define STAG_VPID (((x) & 0xffff) << 16) /* Register for port port-and-protocol based vlan 1 control */