Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp611115ybl; Fri, 24 Jan 2020 06:24:50 -0800 (PST) X-Google-Smtp-Source: APXvYqydpeUIP4jvLHT0Kn2U2OEblEMNI9ACe8fGBGJehWBGDj8QrmeYfq2e7JQZtGRHdzYEg30O X-Received: by 2002:a05:6830:148a:: with SMTP id s10mr2082042otq.239.1579875889763; Fri, 24 Jan 2020 06:24:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579875889; cv=none; d=google.com; s=arc-20160816; b=kuBmMOnUgNzORkwJUxnV8c6/SfWTB8lXxvx99UVJZLGrL49PMoRR1x4ileTAAqKtRq B6jE0cSbaeQe7tCTJbmQwykeMshs2VNkMWbhefbLCIhJnu3EaqMjhBlUMqAHE5oAYHfa RKaG6pOAqU02JZr4mB5VRJSeVQLopRw7rtKZUpf3/NsYQBdCSdNfYCGruVOEiyV6dljo 57UI3NbtZDwP7MLjTkDtidVfj5Lorct6obVLTbcYO4Je2RIlmwAT/X0TIIWpN/+3irvI yGWfoJP+nTYIPJILI47reybr2xswmIh+UK+q5y+o3AY2Y0jpTbfMGOJUX6gsq8OSqP8E sWRg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=JDDji/XjrQttQ1i0UKZKg/jqfrp5u1l8ooMEERWARjo=; b=lLFK+DNDlrOUH4KnWudSKS+tSMoF/w6+bHO3u8ZyARoPX2KPUoyw4630Qyzm2Epcr7 ut+bEGV+9EbQHHCGnCy8sBIYB/U4L/RWkHUcgSuSQVXXSuGTzrf01Gdh9aC9vXgxpTCy r478tmEnZ0GO0QbXLjzGGHb4pCHUeMwo9E05On+VL5Vc/2en6ZJ7JbeyKoqWlP7wzuw0 KYnJEGyMDxXZBp4bTmuOQ0ssEJqLebpoT1C/g3VjA1beSod/PO05ZIWL1935+QQiGOkz lJTDTox3OzlMO1QYAHGzkUWY+2mqgnPMc67JL5+tFf/4GereJwA5LHidZYvk4o7SYi5f pIPg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Sj0WcHDd; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h9si2429459oie.74.2020.01.24.06.24.37; Fri, 24 Jan 2020 06:24:49 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Sj0WcHDd; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389821AbgAXLKI (ORCPT + 99 others); Fri, 24 Jan 2020 06:10:08 -0500 Received: from mail.kernel.org ([198.145.29.99]:45830 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730170AbgAXLKG (ORCPT ); Fri, 24 Jan 2020 06:10:06 -0500 Received: from localhost (ip-213-127-102-57.ip.prioritytelecom.net [213.127.102.57]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id CD67720663; Fri, 24 Jan 2020 11:10:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1579864205; bh=JIkjs8C9QE1u8UoMgAl79rNB1yLw+RBxDt3+1CJ6u1o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Sj0WcHDd95hQglwoH6z2mCJv4bC04e5tjh9Ex6bWobeDi7KIChm/0YinzwxPKHkPE 9h2dhy4KRT8wzWhYognhxyTCEJf8dbsSxJBOfWajNixGrQa/ru+lE2rjZis3EUnI38 WfYpNipdW+2CFqFKINsXYxeSPZnHEOMLzMg82duw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Florian Fainelli , "David S. Miller" , Sasha Levin Subject: [PATCH 4.19 201/639] net: dsa: b53: Properly account for VLAN filtering Date: Fri, 24 Jan 2020 10:26:11 +0100 Message-Id: <20200124093112.222982098@linuxfoundation.org> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200124093047.008739095@linuxfoundation.org> References: <20200124093047.008739095@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Florian Fainelli [ Upstream commit dad8d7c6452b5b9f9828c9e2c7ca143205fd40c7 ] VLAN filtering can be built into the kernel, and also dynamically turned on/off through the bridge master device. Allow re-configuring the switch appropriately to account for that by deciding whether VLAN table (v_table) misses should lead to a drop or forward. Fixes: a2482d2ce349 ("net: dsa: b53: Plug in VLAN support") Signed-off-by: Florian Fainelli Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- drivers/net/dsa/b53/b53_common.c | 59 +++++++++++++++++++++++++++++--- drivers/net/dsa/b53/b53_priv.h | 3 ++ 2 files changed, 57 insertions(+), 5 deletions(-) diff --git a/drivers/net/dsa/b53/b53_common.c b/drivers/net/dsa/b53/b53_common.c index bceda1e884426..426ec1c05799a 100644 --- a/drivers/net/dsa/b53/b53_common.c +++ b/drivers/net/dsa/b53/b53_common.c @@ -343,7 +343,8 @@ static void b53_set_forwarding(struct b53_device *dev, int enable) b53_write8(dev, B53_CTRL_PAGE, B53_SWITCH_CTRL, mgmt); } -static void b53_enable_vlan(struct b53_device *dev, bool enable) +static void b53_enable_vlan(struct b53_device *dev, bool enable, + bool enable_filtering) { u8 mgmt, vc0, vc1, vc4 = 0, vc5; @@ -368,8 +369,13 @@ static void b53_enable_vlan(struct b53_device *dev, bool enable) vc0 |= VC0_VLAN_EN | VC0_VID_CHK_EN | VC0_VID_HASH_VID; vc1 |= VC1_RX_MCST_UNTAG_EN | VC1_RX_MCST_FWD_EN; vc4 &= ~VC4_ING_VID_CHECK_MASK; - vc4 |= VC4_ING_VID_VIO_DROP << VC4_ING_VID_CHECK_S; - vc5 |= VC5_DROP_VTABLE_MISS; + if (enable_filtering) { + vc4 |= VC4_ING_VID_VIO_DROP << VC4_ING_VID_CHECK_S; + vc5 |= VC5_DROP_VTABLE_MISS; + } else { + vc4 |= VC4_ING_VID_VIO_FWD << VC4_ING_VID_CHECK_S; + vc5 &= ~VC5_DROP_VTABLE_MISS; + } if (is5325(dev)) vc0 &= ~VC0_RESERVED_1; @@ -419,6 +425,9 @@ static void b53_enable_vlan(struct b53_device *dev, bool enable) } b53_write8(dev, B53_CTRL_PAGE, B53_SWITCH_MODE, mgmt); + + dev->vlan_enabled = enable; + dev->vlan_filtering_enabled = enable_filtering; } static int b53_set_jumbo(struct b53_device *dev, bool enable, bool allow_10_100) @@ -646,7 +655,7 @@ int b53_configure_vlan(struct dsa_switch *ds) b53_do_vlan_op(dev, VTA_CMD_CLEAR); } - b53_enable_vlan(dev, false); + b53_enable_vlan(dev, false, dev->vlan_filtering_enabled); b53_for_each_port(dev, i) b53_write16(dev, B53_VLAN_PAGE, @@ -1081,6 +1090,46 @@ static void b53_adjust_link(struct dsa_switch *ds, int port, int b53_vlan_filtering(struct dsa_switch *ds, int port, bool vlan_filtering) { + struct b53_device *dev = ds->priv; + struct net_device *bridge_dev; + unsigned int i; + u16 pvid, new_pvid; + + /* Handle the case were multiple bridges span the same switch device + * and one of them has a different setting than what is being requested + * which would be breaking filtering semantics for any of the other + * bridge devices. + */ + b53_for_each_port(dev, i) { + bridge_dev = dsa_to_port(ds, i)->bridge_dev; + if (bridge_dev && + bridge_dev != dsa_to_port(ds, port)->bridge_dev && + br_vlan_enabled(bridge_dev) != vlan_filtering) { + netdev_err(bridge_dev, + "VLAN filtering is global to the switch!\n"); + return -EINVAL; + } + } + + b53_read16(dev, B53_VLAN_PAGE, B53_VLAN_PORT_DEF_TAG(port), &pvid); + new_pvid = pvid; + if (dev->vlan_filtering_enabled && !vlan_filtering) { + /* Filtering is currently enabled, use the default PVID since + * the bridge does not expect tagging anymore + */ + dev->ports[port].pvid = pvid; + new_pvid = b53_default_pvid(dev); + } else if (!dev->vlan_filtering_enabled && vlan_filtering) { + /* Filtering is currently disabled, restore the previous PVID */ + new_pvid = dev->ports[port].pvid; + } + + if (pvid != new_pvid) + b53_write16(dev, B53_VLAN_PAGE, B53_VLAN_PORT_DEF_TAG(port), + new_pvid); + + b53_enable_vlan(dev, dev->vlan_enabled, vlan_filtering); + return 0; } EXPORT_SYMBOL(b53_vlan_filtering); @@ -1096,7 +1145,7 @@ int b53_vlan_prepare(struct dsa_switch *ds, int port, if (vlan->vid_end > dev->num_vlans) return -ERANGE; - b53_enable_vlan(dev, true); + b53_enable_vlan(dev, true, dev->vlan_filtering_enabled); return 0; } diff --git a/drivers/net/dsa/b53/b53_priv.h b/drivers/net/dsa/b53/b53_priv.h index df149756c2820..e87af5db0d6d8 100644 --- a/drivers/net/dsa/b53/b53_priv.h +++ b/drivers/net/dsa/b53/b53_priv.h @@ -73,6 +73,7 @@ enum { struct b53_port { u16 vlan_ctl_mask; struct ethtool_eee eee; + u16 pvid; }; struct b53_vlan { @@ -118,6 +119,8 @@ struct b53_device { unsigned int num_vlans; struct b53_vlan *vlans; + bool vlan_enabled; + bool vlan_filtering_enabled; unsigned int num_ports; struct b53_port *ports; }; -- 2.20.1