From patchwork Wed Apr 29 16:19:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 1279504 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=DcoEu8Tw; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 49C3dM4bFyz9sSM for ; Thu, 30 Apr 2020 02:20:07 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726864AbgD2QUB (ORCPT ); Wed, 29 Apr 2020 12:20:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50484 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1726423AbgD2QT7 (ORCPT ); Wed, 29 Apr 2020 12:19:59 -0400 Received: from mail-wm1-x341.google.com (mail-wm1-x341.google.com [IPv6:2a00:1450:4864:20::341]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 75236C03C1AD for ; Wed, 29 Apr 2020 09:19:59 -0700 (PDT) Received: by mail-wm1-x341.google.com with SMTP id v8so5329678wma.0 for ; Wed, 29 Apr 2020 09:19:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=sslderKR2VnBe3vbWtKjxt2i8MRgj916M4Mgvk8OZR0=; b=DcoEu8TwsirMmJY1ujDyd/YDbLX3E35lTqumTv3D1wU5xQRTGw54MEIDx6xwud7JGr f/vbErxiE/8r2Rmbj/K9x6tZp9p2EUWR6eT/Avis6iFNQXfgT9T0oQHKG7de7jxQT9Kj KoW/0333jIvdmDYCy5RPfvPwlzsGD+9EVKhu9XAKJpe1W/RWmeajAXaO9c3wX5K+PPsx YZnAG92ErIWWgt+yrncTkvV92OFQ8Wmm9xuIiAnrtAqqDw/imj9lQTSWnH9SoTpVGiTZ WfBayjCQ3xvXoft8U8B5p+4NZOcVHCqQIso7flwUIy9q32o+7FiJ9GPjt8bPSdbXmXd3 b/WA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=sslderKR2VnBe3vbWtKjxt2i8MRgj916M4Mgvk8OZR0=; b=j3GBvJHizNK7msyo7H/Kuyxbbziz1eqla1c6vwrjsonvxp8zMqaxzWo8OHnu9uVNBF JVbI5Geh8MPSnfcskUzNCsBSNHem5KC57De5My4cw783cxNemr7OYWfbd89xslbXvdui nDqr+T5CynpGlTZdmW0tekJ4zbMXPJYn8XB8YkQ/ORZBtx93ueTx4gcc84yopd84xAWx S0QlKBFy1mPwEwEOzamqCoK2LzmNS7Oht8Sb7qVNxDRULaOZQTHJjN/xI4g8KtkhZJjn HQII1SvX6WvQHiwE6oxzZ2HR+Ef0sr2RgozqYDLNvWB++BPrMCpWR8dSfyv++VgObzWr sWMg== X-Gm-Message-State: AGi0PuY2HX5yRUTE4vUPlUFCNosh8cJbfdjBaIDJYIC5JAyXw4LfTFB0 4C7ku3owJ93yJmqhWqWsEx4= X-Google-Smtp-Source: APiQypJJuUY/UEoG2j7KslBLNLCUWab8feTEw73uVtckG+jifWULQYVDGuH1I5gXP5qH19gDW6Vu9g== X-Received: by 2002:a1c:c302:: with SMTP id t2mr4225330wmf.85.1588177198160; Wed, 29 Apr 2020 09:19:58 -0700 (PDT) Received: from localhost.localdomain ([86.121.118.29]) by smtp.gmail.com with ESMTPSA id r18sm28132609wrj.70.2020.04.29.09.19.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Apr 2020 09:19:57 -0700 (PDT) From: Vladimir Oltean To: andrew@lunn.ch, f.fainelli@gmail.com, vivien.didelot@gmail.com, davem@davemloft.net Cc: jiri@resnulli.us, idosch@idosch.org, kuba@kernel.org, netdev@vger.kernel.org, leoyang.li@nxp.com, nikolay@cumulusnetworks.com Subject: [PATCH net-next 1/4] bridge: Allow enslaving DSA master network devices Date: Wed, 29 Apr 2020 19:19:49 +0300 Message-Id: <20200429161952.17769-2-olteanv@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200429161952.17769-1-olteanv@gmail.com> References: <20200429161952.17769-1-olteanv@gmail.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Florian Fainelli Commit 8db0a2ee2c63 ("net: bridge: reject DSA-enabled master netdevices as bridge members") added a special check in br_if.c in order to check for a DSA master network device with a tagging protocol configured. This was done because back then, such devices, once enslaved in a bridge would become inoperative and would not pass DSA tagged traffic anymore due to br_handle_frame returning RX_HANDLER_CONSUMED. But right now we have valid use cases which do require bridging of DSA masters. One such example is when the DSA master ports are DSA switch ports themselves (in a disjoint tree setup). This should be completely equivalent, functionally speaking, from having multiple DSA switches hanging off of the ports of a switchdev driver. So we should allow the enslaving of DSA tagged master network devices. Make br_handle_frame() return RX_HANDLER_PASS in order to call into the DSA specific tagging protocol handlers, and lift the restriction from br_add_if. Signed-off-by: Florian Fainelli Signed-off-by: Vladimir Oltean --- net/bridge/br_if.c | 4 +--- net/bridge/br_input.c | 4 +++- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/net/bridge/br_if.c b/net/bridge/br_if.c index ca685c0cdf95..e0fbdb855664 100644 --- a/net/bridge/br_if.c +++ b/net/bridge/br_if.c @@ -18,7 +18,6 @@ #include #include #include -#include #include #include #include @@ -571,8 +570,7 @@ int br_add_if(struct net_bridge *br, struct net_device *dev, */ if ((dev->flags & IFF_LOOPBACK) || dev->type != ARPHRD_ETHER || dev->addr_len != ETH_ALEN || - !is_valid_ether_addr(dev->dev_addr) || - netdev_uses_dsa(dev)) + !is_valid_ether_addr(dev->dev_addr)) return -EINVAL; /* No bridging of bridges */ diff --git a/net/bridge/br_input.c b/net/bridge/br_input.c index d5c34f36f0f4..396bc0c18cb5 100644 --- a/net/bridge/br_input.c +++ b/net/bridge/br_input.c @@ -17,6 +17,7 @@ #endif #include #include +#include #include #include #include "br_private.h" @@ -263,7 +264,8 @@ rx_handler_result_t br_handle_frame(struct sk_buff **pskb) struct sk_buff *skb = *pskb; const unsigned char *dest = eth_hdr(skb)->h_dest; - if (unlikely(skb->pkt_type == PACKET_LOOPBACK)) + if (unlikely(skb->pkt_type == PACKET_LOOPBACK) || + netdev_uses_dsa(skb->dev)) return RX_HANDLER_PASS; if (!is_valid_ether_addr(eth_hdr(skb)->h_source)) From patchwork Wed Apr 29 16:19:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 1279506 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=mQRKG9gj; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 49C3dN6Zg8z9sSX for ; Thu, 30 Apr 2020 02:20:08 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726882AbgD2QUD (ORCPT ); Wed, 29 Apr 2020 12:20:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50490 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1726423AbgD2QUB (ORCPT ); Wed, 29 Apr 2020 12:20:01 -0400 Received: from mail-wm1-x341.google.com (mail-wm1-x341.google.com [IPv6:2a00:1450:4864:20::341]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C6F54C03C1AD for ; Wed, 29 Apr 2020 09:20:00 -0700 (PDT) Received: by mail-wm1-x341.google.com with SMTP id u127so2691595wmg.1 for ; Wed, 29 Apr 2020 09:20:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=9aqcV/gxEnfMu5dKf+1cH+sRHfjU+MHHhNV07UBF/dY=; b=mQRKG9gjPkjNk4d/uL398koTg2R8SyYcE6IuAdTS4e+AXC0xK36QKwT210ixtty5J9 5Dl2Wt3ea2sgyYEr3zJvIv1EbgFWP4HK5nxtB8R9hLKVVyIzJ6S+rFXhU/MDl8ssjZro kUQkD+2D54KksNgyVk2ACG112TA75Y53kUnPyII+H/97VmPONN757YEXvWFrTMqDMFY5 p8Lib98neAOr+2nCGUMWjCzoX4X6nt2dytRoegf95fLZ4H6mQbB9XEzdTrpu071yXDxU nETB3/hwZNuCmbZUImA4Gvh01y/YSX4IPmsD1d4fUEFj4dr1w55XwmO0lbxN7gwObnOy KwjA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=9aqcV/gxEnfMu5dKf+1cH+sRHfjU+MHHhNV07UBF/dY=; b=dzS2yslRl+8qQN4jA/BvfJ3qyBOKa4cbGxEcnh01whQknzx2/7yPVTNCSiFmSx+7cG 0b8hFuUQ4cnRRmNx+n7xBIYFSKCBhdqrxEddcF4Pl8lIgWMVltT8cAliU0x2mqzxImlS 5WeZgT9K1BMIU6G6UZ4qcsUCLvip2X8KM73moqUnOGMY0ayMcvbsKkt7qDLG3ecByMAb blGPJsUav+M9zfsKoNKeTRBHEp1pVYPG4/5sgE+z6iR84drpTa0CE0ngUR5N2I+PtO0B 9sadJ/Jcsi3axMtLWEqfXtWf4/wMWED983Gy+FTKwtweF/+mPWYpDCtaQOhbV+Je+WBT BwSg== X-Gm-Message-State: AGi0PubjB7mvESG7mpZw0zKu+1CiWJ2x8F5OHBLhJAMVwtbqJUZcgffP 4xhyvj7/0ZzaQ9fWloaC5ZE= X-Google-Smtp-Source: APiQypIxQTO4QIsAhHcXma2usCG3cyWQjufFG7xdP9oJiQfBNTtlz3M+4e7Ub/XLnWhFYDbbhtR4mA== X-Received: by 2002:a1c:59c3:: with SMTP id n186mr4017915wmb.24.1588177199367; Wed, 29 Apr 2020 09:19:59 -0700 (PDT) Received: from localhost.localdomain ([86.121.118.29]) by smtp.gmail.com with ESMTPSA id r18sm28132609wrj.70.2020.04.29.09.19.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Apr 2020 09:19:58 -0700 (PDT) From: Vladimir Oltean To: andrew@lunn.ch, f.fainelli@gmail.com, vivien.didelot@gmail.com, davem@davemloft.net Cc: jiri@resnulli.us, idosch@idosch.org, kuba@kernel.org, netdev@vger.kernel.org, leoyang.li@nxp.com, nikolay@cumulusnetworks.com Subject: [PATCH net-next 2/4] net: dsa: permit cross-chip bridging between all trees in the system Date: Wed, 29 Apr 2020 19:19:50 +0300 Message-Id: <20200429161952.17769-3-olteanv@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200429161952.17769-1-olteanv@gmail.com> References: <20200429161952.17769-1-olteanv@gmail.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Vladimir Oltean One way of utilizing DSA is by cascading switches which do not all have compatible taggers. Consider the following real-life topology: +---------------------------------------------------------------+ | LS1028A | | +------------------------------+ | | | DSA master for Felix | | | |(internal ENETC port 2: eno2))| | | +------------+------------------------------+-------------+ | | | Felix embedded L2 switch | | | | | | | | +--------------+ +--------------+ +--------------+ | | | | |DSA master for| |DSA master for| |DSA master for| | | | | | SJA1105 1 | | SJA1105 2 | | SJA1105 3 | | | | | |(Felix port 1)| |(Felix port 2)| |(Felix port 3)| | | +--+-+--------------+---+--------------+---+--------------+--+--+ +-----------------------+ +-----------------------+ +-----------------------+ | SJA1105 switch 1 | | SJA1105 switch 2 | | SJA1105 switch 3 | +-----+-----+-----+-----+ +-----+-----+-----+-----+ +-----+-----+-----+-----+ |sw1p0|sw1p1|sw1p2|sw1p3| |sw2p0|sw2p1|sw2p2|sw2p3| |sw3p0|sw3p1|sw3p2|sw3p3| +-----+-----+-----+-----+ +-----+-----+-----+-----+ +-----+-----+-----+-----+ The above can be described in the device tree as follows (obviously not complete): mscc_felix { dsa,member = <0 0>; ports { port@4 { ethernet = <&enetc_port2>; }; }; }; sja1105_switch1 { dsa,member = <1 1>; ports { port@4 { ethernet = <&mscc_felix_port1>; }; }; }; sja1105_switch2 { dsa,member = <2 2>; ports { port@4 { ethernet = <&mscc_felix_port2>; }; }; }; sja1105_switch3 { dsa,member = <3 3>; ports { port@4 { ethernet = <&mscc_felix_port3>; }; }; }; Basically we instantiate one DSA switch tree for every hardware switch in the system, but we still give them globally unique switch IDs (will come back to that later). Having 3 disjoint switch trees makes the tagger drivers "just work", because net devices are registered for the 3 Felix DSA master ports, and they are also DSA slave ports to the ENETC port. So packets received on the ENETC port are stripped of their stacked DSA tags one by one. Currently, hardware bridging between ports on the same sja1105 chip is possible, but switching between sja1105 ports on different chips is handled by the software bridge. This is fine, but we can do better. In fact, the dsa_8021q tag used by sja1105 is compatible with cascading. In other words, a sja1105 switch can correctly parse and route a packet containing a dsa_8021q tag. So if we could enable hardware bridging on the Felix DSA master ports, cross-chip bridging could be completely offloaded. Such as system would be used as follows: ip link add dev br0 type bridge && ip link set dev br0 up for port in sw0p0 sw0p1 sw0p2 sw0p3 \ sw1p0 sw1p1 sw1p2 sw1p3 \ sw2p0 sw2p1 sw2p2 sw2p3; do ip link set dev $port master br0 done The above makes switching between ports on the same row be performed in hardware, and between ports on different rows in software. Now assume the Felix switch ports are called swp0, swp1, swp2. By running the following extra commands: ip link add dev br1 type bridge && ip link set dev br1 up for port in swp0 swp1 swp2; do ip link set dev $port master br1 done the CPU no longer sees packets which traverse sja1105 switch boundaries and can be forwarded directly by Felix. The br1 bridge would not be used for any sort of traffic termination. For this to work, we need to give drivers an opportunity to listen for bridging events on DSA trees other than their own, and pass that other tree index as argument. I have made the assumption, for the moment, that the other existing DSA notifiers don't need to be broadcast to other trees. That assumption might turn out to be incorrect. But in the meantime, introduce a dsa_broadcast function, similar in purpose to dsa_port_notify, which is used only by the bridging notifiers. Signed-off-by: Vladimir Oltean --- drivers/net/dsa/mv88e6xxx/chip.c | 16 ++++++++++++---- include/net/dsa.h | 10 ++++++---- net/dsa/dsa_priv.h | 1 + net/dsa/port.c | 23 +++++++++++++++++++++-- net/dsa/switch.c | 21 +++++++++++++++------ 5 files changed, 55 insertions(+), 16 deletions(-) diff --git a/drivers/net/dsa/mv88e6xxx/chip.c b/drivers/net/dsa/mv88e6xxx/chip.c index dd8a5666a584..9ecfbe0c4f6c 100644 --- a/drivers/net/dsa/mv88e6xxx/chip.c +++ b/drivers/net/dsa/mv88e6xxx/chip.c @@ -2233,26 +2233,34 @@ static void mv88e6xxx_port_bridge_leave(struct dsa_switch *ds, int port, mv88e6xxx_reg_unlock(chip); } -static int mv88e6xxx_crosschip_bridge_join(struct dsa_switch *ds, int dev, +static int mv88e6xxx_crosschip_bridge_join(struct dsa_switch *ds, + int tree_index, int sw_index, int port, struct net_device *br) { struct mv88e6xxx_chip *chip = ds->priv; int err; + if (tree_index != ds->dst->index) + return 0; + mv88e6xxx_reg_lock(chip); - err = mv88e6xxx_pvt_map(chip, dev, port); + err = mv88e6xxx_pvt_map(chip, sw_index, port); mv88e6xxx_reg_unlock(chip); return err; } -static void mv88e6xxx_crosschip_bridge_leave(struct dsa_switch *ds, int dev, +static void mv88e6xxx_crosschip_bridge_leave(struct dsa_switch *ds, + int tree_index, int sw_index, int port, struct net_device *br) { struct mv88e6xxx_chip *chip = ds->priv; + if (tree_index != ds->dst->index) + return; + mv88e6xxx_reg_lock(chip); - if (mv88e6xxx_pvt_map(chip, dev, port)) + if (mv88e6xxx_pvt_map(chip, sw_index, port)) dev_err(ds->dev, "failed to remap cross-chip Port VLAN\n"); mv88e6xxx_reg_unlock(chip); } diff --git a/include/net/dsa.h b/include/net/dsa.h index fb3f9222f2a1..b2111924c7ef 100644 --- a/include/net/dsa.h +++ b/include/net/dsa.h @@ -574,10 +574,12 @@ struct dsa_switch_ops { /* * Cross-chip operations */ - int (*crosschip_bridge_join)(struct dsa_switch *ds, int sw_index, - int port, struct net_device *br); - void (*crosschip_bridge_leave)(struct dsa_switch *ds, int sw_index, - int port, struct net_device *br); + int (*crosschip_bridge_join)(struct dsa_switch *ds, int tree_index, + int sw_index, int port, + struct net_device *br); + void (*crosschip_bridge_leave)(struct dsa_switch *ds, int tree_index, + int sw_index, int port, + struct net_device *br); /* * PTP functionality diff --git a/net/dsa/dsa_priv.h b/net/dsa/dsa_priv.h index 6d9a1ef65fa0..a1a0ae242012 100644 --- a/net/dsa/dsa_priv.h +++ b/net/dsa/dsa_priv.h @@ -35,6 +35,7 @@ struct dsa_notifier_ageing_time_info { /* DSA_NOTIFIER_BRIDGE_* */ struct dsa_notifier_bridge_info { struct net_device *br; + int tree_index; int sw_index; int port; }; diff --git a/net/dsa/port.c b/net/dsa/port.c index a58fdd362574..ebc8d6cbd1d4 100644 --- a/net/dsa/port.c +++ b/net/dsa/port.c @@ -13,6 +13,23 @@ #include "dsa_priv.h" +static int dsa_broadcast(unsigned long e, void *v) +{ + struct dsa_switch_tree *dst; + int err = 0; + + list_for_each_entry(dst, &dsa_tree_list, list) { + struct raw_notifier_head *nh = &dst->nh; + + err = raw_notifier_call_chain(nh, e, v); + err = notifier_to_errno(err); + if (err) + break; + } + + return err; +} + static int dsa_port_notify(const struct dsa_port *dp, unsigned long e, void *v) { struct raw_notifier_head *nh = &dp->ds->dst->nh; @@ -120,6 +137,7 @@ void dsa_port_disable(struct dsa_port *dp) int dsa_port_bridge_join(struct dsa_port *dp, struct net_device *br) { struct dsa_notifier_bridge_info info = { + .tree_index = dp->ds->dst->index, .sw_index = dp->ds->index, .port = dp->index, .br = br, @@ -136,7 +154,7 @@ int dsa_port_bridge_join(struct dsa_port *dp, struct net_device *br) */ dp->bridge_dev = br; - err = dsa_port_notify(dp, DSA_NOTIFIER_BRIDGE_JOIN, &info); + err = dsa_broadcast(DSA_NOTIFIER_BRIDGE_JOIN, &info); /* The bridging is rolled back on error */ if (err) { @@ -150,6 +168,7 @@ int dsa_port_bridge_join(struct dsa_port *dp, struct net_device *br) void dsa_port_bridge_leave(struct dsa_port *dp, struct net_device *br) { struct dsa_notifier_bridge_info info = { + .tree_index = dp->ds->dst->index, .sw_index = dp->ds->index, .port = dp->index, .br = br, @@ -161,7 +180,7 @@ void dsa_port_bridge_leave(struct dsa_port *dp, struct net_device *br) */ dp->bridge_dev = NULL; - err = dsa_port_notify(dp, DSA_NOTIFIER_BRIDGE_LEAVE, &info); + err = dsa_broadcast(DSA_NOTIFIER_BRIDGE_LEAVE, &info); if (err) pr_err("DSA: failed to notify DSA_NOTIFIER_BRIDGE_LEAVE\n"); diff --git a/net/dsa/switch.c b/net/dsa/switch.c index f3c32ff552b3..86c8dc5c32a0 100644 --- a/net/dsa/switch.c +++ b/net/dsa/switch.c @@ -89,11 +89,16 @@ static int dsa_switch_mtu(struct dsa_switch *ds, static int dsa_switch_bridge_join(struct dsa_switch *ds, struct dsa_notifier_bridge_info *info) { - if (ds->index == info->sw_index && ds->ops->port_bridge_join) + struct dsa_switch_tree *dst = ds->dst; + + if (dst->index == info->tree_index && ds->index == info->sw_index && + ds->ops->port_bridge_join) return ds->ops->port_bridge_join(ds, info->port, info->br); - if (ds->index != info->sw_index && ds->ops->crosschip_bridge_join) - return ds->ops->crosschip_bridge_join(ds, info->sw_index, + if ((dst->index != info->tree_index || ds->index != info->sw_index) && + ds->ops->crosschip_bridge_join) + return ds->ops->crosschip_bridge_join(ds, info->tree_index, + info->sw_index, info->port, info->br); return 0; @@ -103,13 +108,17 @@ static int dsa_switch_bridge_leave(struct dsa_switch *ds, struct dsa_notifier_bridge_info *info) { bool unset_vlan_filtering = br_vlan_enabled(info->br); + struct dsa_switch_tree *dst = ds->dst; int err, i; - if (ds->index == info->sw_index && ds->ops->port_bridge_leave) + if (dst->index == info->tree_index && ds->index == info->sw_index && + ds->ops->port_bridge_join) ds->ops->port_bridge_leave(ds, info->port, info->br); - if (ds->index != info->sw_index && ds->ops->crosschip_bridge_leave) - ds->ops->crosschip_bridge_leave(ds, info->sw_index, info->port, + if ((dst->index != info->tree_index || ds->index != info->sw_index) && + ds->ops->crosschip_bridge_join) + ds->ops->crosschip_bridge_leave(ds, info->tree_index, + info->sw_index, info->port, info->br); /* If the bridge was vlan_filtering, the bridge core doesn't trigger an From patchwork Wed Apr 29 16:19:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 1279507 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=XHexUZNE; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 49C3dP5JJkz9sSb for ; Thu, 30 Apr 2020 02:20:09 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726741AbgD2QUE (ORCPT ); Wed, 29 Apr 2020 12:20:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50492 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1726871AbgD2QUC (ORCPT ); Wed, 29 Apr 2020 12:20:02 -0400 Received: from mail-wr1-x444.google.com (mail-wr1-x444.google.com [IPv6:2a00:1450:4864:20::444]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E88D4C03C1AE for ; Wed, 29 Apr 2020 09:20:01 -0700 (PDT) Received: by mail-wr1-x444.google.com with SMTP id x18so3280441wrq.2 for ; Wed, 29 Apr 2020 09:20:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=zSQUFcTA5EZEGaPUB16rfmy3e7ibN/rhh32ryX4vK0A=; b=XHexUZNEEoPLgiKSW3tiPQbAg+klMt2VeEbN69JwmzWCJG75SktlhyIrXnnKMcrWFb faPL6lRlvCoROh4BQDqXo4Fur++S1Aw0eMONGRp1z6cBtWKZygoOp8RZSMKdebTs9mFz bj777HQcJFKwiY61tb0pqDFa4QfAQUcn0bmPfZdpBejIcR7XZR2u5Unz2zxhH6Ru9I2O z6Vb6wCcl2rMWzyjdsT3RsuIUThGYnRsdIFXHhSlCQXc4ZxGAL63IzL+gHCvfUxGK1CU ASXC8FoDYmAjwIPj1x5vLiSZaNDhuv8IPHxONseP+/VS2w2jRvmQHtampEaK4fFqXcyx 47sA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=zSQUFcTA5EZEGaPUB16rfmy3e7ibN/rhh32ryX4vK0A=; b=kNxJdYrn2W3+FsiLRPAMLUr6IAt1U52Av3eztO5oybu69p0FhYWFoSAkT/XCaSovxz vmXT78wmWiz/pjXG40DPB5bb7VxkaQVymJS7e1jJhOcw8JiSbSKKvjX8arGnSQ/9armJ fU9YeWiaNntmDuk2g+wMiz6EmcKTII/Y6WdxaOFNsu7kWOONuJUkqg56bTqwhZA8qpMp FREwyiZI0LpbAL+LcNMx4lJzFqJDBvuyTmFxqyrnq4My5HDbv5IwcESLJ3yvKOtDOSq3 7zUOEy8JERVs1+CCGh185Z92bHCSkWyXJFd7EVULm7Mc8fykNmOzUbQ9kiz12kXGD/dK ABpQ== X-Gm-Message-State: AGi0PuYztSDMZlGNX4x+atWxBVoMZ7WClNxqM3XHqUKCE+Q/ngyZbCCp K8KmO+U54Uh0vkxphnttP00= X-Google-Smtp-Source: APiQypLnRMNWj+gSL1nJEaYPI0cQv/guQjjTgnbCwZ0+y9mH8/h91MOFUuEH32wYsuPb23Cxzhzccw== X-Received: by 2002:a5d:4042:: with SMTP id w2mr37340690wrp.195.1588177200611; Wed, 29 Apr 2020 09:20:00 -0700 (PDT) Received: from localhost.localdomain ([86.121.118.29]) by smtp.gmail.com with ESMTPSA id r18sm28132609wrj.70.2020.04.29.09.19.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Apr 2020 09:20:00 -0700 (PDT) From: Vladimir Oltean To: andrew@lunn.ch, f.fainelli@gmail.com, vivien.didelot@gmail.com, davem@davemloft.net Cc: jiri@resnulli.us, idosch@idosch.org, kuba@kernel.org, netdev@vger.kernel.org, leoyang.li@nxp.com, nikolay@cumulusnetworks.com Subject: [PATCH net-next 3/4] net: dsa: introduce a dsa_switch_find function Date: Wed, 29 Apr 2020 19:19:51 +0300 Message-Id: <20200429161952.17769-4-olteanv@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200429161952.17769-1-olteanv@gmail.com> References: <20200429161952.17769-1-olteanv@gmail.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Vladimir Oltean Somewhat similar to dsa_tree_find, dsa_switch_find returns a dsa_switch structure pointer by searching for its tree index and switch index (the parameters from dsa,member). To be used, for example, by drivers who implement .crosschip_bridge_join and need a reference to the other switch indicated to by the tree_index and sw_index arguments. Signed-off-by: Vladimir Oltean --- include/net/dsa.h | 1 + net/dsa/dsa2.c | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/include/net/dsa.h b/include/net/dsa.h index b2111924c7ef..8a337387565a 100644 --- a/include/net/dsa.h +++ b/include/net/dsa.h @@ -671,6 +671,7 @@ static inline bool dsa_can_decode(const struct sk_buff *skb, void dsa_unregister_switch(struct dsa_switch *ds); int dsa_register_switch(struct dsa_switch *ds); +struct dsa_switch *dsa_switch_find(int tree_index, int sw_index); #ifdef CONFIG_PM_SLEEP int dsa_switch_suspend(struct dsa_switch *ds); int dsa_switch_resume(struct dsa_switch *ds); diff --git a/net/dsa/dsa2.c b/net/dsa/dsa2.c index 9a271a58a41d..07e01b195975 100644 --- a/net/dsa/dsa2.c +++ b/net/dsa/dsa2.c @@ -24,6 +24,27 @@ LIST_HEAD(dsa_tree_list); static const struct devlink_ops dsa_devlink_ops = { }; +struct dsa_switch *dsa_switch_find(int tree_index, int sw_index) +{ + struct dsa_switch_tree *dst; + struct dsa_port *dp; + + list_for_each_entry(dst, &dsa_tree_list, list) { + if (dst->index != tree_index) + continue; + + list_for_each_entry(dp, &dst->ports, list) { + if (dp->ds->index != sw_index) + continue; + + return dp->ds; + } + } + + return NULL; +} +EXPORT_SYMBOL_GPL(dsa_switch_find); + static struct dsa_switch_tree *dsa_tree_find(int index) { struct dsa_switch_tree *dst; From patchwork Wed Apr 29 16:19:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 1279508 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=bXPGBL4X; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 49C3dQ2Hs2z9sPF for ; Thu, 30 Apr 2020 02:20:10 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726885AbgD2QUH (ORCPT ); Wed, 29 Apr 2020 12:20:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50500 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1726539AbgD2QUE (ORCPT ); Wed, 29 Apr 2020 12:20:04 -0400 Received: from mail-wr1-x443.google.com (mail-wr1-x443.google.com [IPv6:2a00:1450:4864:20::443]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 57E24C03C1AD for ; Wed, 29 Apr 2020 09:20:03 -0700 (PDT) Received: by mail-wr1-x443.google.com with SMTP id k1so3275794wrx.4 for ; Wed, 29 Apr 2020 09:20:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=VQJTGM6oDsDIGZQkRdaVeFHVl+u9VslqlGtVawflCTU=; b=bXPGBL4XhxN22Hdi3Nj2+VNEDwsg7ShF3vE0qQFjrbOQQvGFj6vYU61BM7QiYAIBaB rfN6cxfR1sPYEG6fCoZbg1hbC48SLK1BapKshrG4Cxj225JD3V5YXVWCGwGTCfPBBdl0 usoaPTE7HcpVknMFOxSxPZhBy28dUct78E1LxfJEZdWjUqf8jxSJYZxGt+TbJT08Dy5c RF947Y0IIiGpf0OOEJopTTYy9fscHJRzKUm+aBooovRNKOjkFf0TRr92gXbaVjETIgEJ CtXwnDzOxGseGb15eT0Y8p89z5AYz+5i5uCkTWqdXd9xMcD2Q2kWL4zAkI5XUmdAYdR3 K0mA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=VQJTGM6oDsDIGZQkRdaVeFHVl+u9VslqlGtVawflCTU=; b=F/kyebHrmqmISsSxcUwFet0cyvTwSrbwTHwJNNSAYuWRN/RAk0g54BAYu+m/CZmhE6 kmMP8LBNdHGdyoWUz1t/QBUjE0mHT0MJDVyTfvS5uQgJDUWZd4V1/JCnlIB9yL+lSo2C DTboHLJuu8NkE0YkAQAUl4nfnSv+s2qYG153U3Jm7z2BiHZDWtvc2KhYHR/Gtbt1q4MN Bu5MDknP/2AfUvAlJvJ62oOkbpjpXDjYaVm+LBWhIsk05PsDiB7SJVQkEtiuK0AMUgoK XxPYhwl4AUylxW9v1DuEQGcTAW4aoxeW7jS7LgWcjPvdyRQ03ScC3FrJJdaLMZyOcVHB luag== X-Gm-Message-State: AGi0PuY6TUItaa09QHp+9uHOgOrL8tmNaiz+OaW981ZkJpxPdXjf3zLO lN/+9pDXsKr+GGLXtHuAJtg= X-Google-Smtp-Source: APiQypLPyUDvbdOuUapmmgSoAfwWV/Tauz10VJLSdDJbFd1Oz8+JhdWSKxqZwZX/CjqKwtslR6epHQ== X-Received: by 2002:adf:cc81:: with SMTP id p1mr42743680wrj.372.1588177201861; Wed, 29 Apr 2020 09:20:01 -0700 (PDT) Received: from localhost.localdomain ([86.121.118.29]) by smtp.gmail.com with ESMTPSA id r18sm28132609wrj.70.2020.04.29.09.20.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Apr 2020 09:20:01 -0700 (PDT) From: Vladimir Oltean To: andrew@lunn.ch, f.fainelli@gmail.com, vivien.didelot@gmail.com, davem@davemloft.net Cc: jiri@resnulli.us, idosch@idosch.org, kuba@kernel.org, netdev@vger.kernel.org, leoyang.li@nxp.com, nikolay@cumulusnetworks.com Subject: [PATCH net-next 4/4] net: dsa: sja1105: implement cross-chip bridging operations Date: Wed, 29 Apr 2020 19:19:52 +0300 Message-Id: <20200429161952.17769-5-olteanv@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200429161952.17769-1-olteanv@gmail.com> References: <20200429161952.17769-1-olteanv@gmail.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Vladimir Oltean sja1105 uses dsa_8021q for DSA tagging, a format which is VLAN at heart and which is compatible with cascading. A complete description of this tagging format is in net/dsa/tag_8021q.c, but a quick summary is that each external-facing port tags incoming frames with a unique pvid, and this special VLAN is transmitted as tagged towards the inside of the system, and as untagged towards the exterior. The tag encodes the switch id and the source port index. This means that cross-chip bridging for dsa_8021q only entails adding the dsa_8021q pvids of one switch to the RX filter of the other switches. Everything else falls naturally into place, as long as the bottom-end of ports (the leaves in the tree) is comprised exclusively of dsa_8021q-compatible (i.e. sja1105 switches). Otherwise, there would be a chance that a front-panel switch transmits a packet tagged with a dsa_8021q header, header which it wouldn't be able to remove, and which would hence "leak" out. The only use case I tested (due to lack of board availability) was when the sja1105 switches are part of disjoint trees (however, this doesn't change the fact that multiple sja1105 switches still need unique switch identifiers in such a system). But in principle, even "true" single-tree setups (with DSA links) should work just as fine, except for a small change which I can't test: dsa_towards_port should be used instead of dsa_upstream_port (I made the assumption that the routing port that any sja1105 should use towards its neighbours is the CPU port. That might not hold true in other setups). Signed-off-by: Vladimir Oltean --- drivers/net/dsa/sja1105/sja1105_main.c | 122 +++++++++++++++++++++++++ 1 file changed, 122 insertions(+) diff --git a/drivers/net/dsa/sja1105/sja1105_main.c b/drivers/net/dsa/sja1105/sja1105_main.c index 472f4eb20c49..32a05a2424a3 100644 --- a/drivers/net/dsa/sja1105/sja1105_main.c +++ b/drivers/net/dsa/sja1105/sja1105_main.c @@ -25,6 +25,8 @@ #include "sja1105_sgmii.h" #include "sja1105_tas.h" +static const struct dsa_switch_ops sja1105_switch_ops; + static void sja1105_hw_reset(struct gpio_desc *gpio, unsigned int pulse_len, unsigned int startup_delay) { @@ -1934,6 +1936,124 @@ static int sja1105_vlan_del(struct dsa_switch *ds, int port, return 0; } +static int sja1105_crosschip_bridge_member(struct dsa_switch *ds, + int tree_index, int sw_index, + int other_port, + struct net_device *br, bool enabled) +{ + struct dsa_switch *other_ds = dsa_switch_find(tree_index, sw_index); + struct sja1105_private *priv = ds->priv; + struct sja1105_private *other_priv; + u16 rx_vid, other_rx_vid; + int cpu = -1, other_cpu; + int port, rc; + + if (other_ds->ops != &sja1105_switch_ops) + return 0; + + other_cpu = dsa_upstream_port(other_ds, other_port); + other_priv = other_ds->priv; + + /* Make traffic from all local ports enslaved to @br be received + * by @other_ds. This means that our @rx_vid needs to be installed + * on @other_ds's CPU port and user ports. The user ports should be + * egress-untagged so that the can pop the dsa_8021q VLAN. But the + * @other_cpu can be either egress-tagged or untagged: it doesn't + * matter, since it should never egress a frame having our @rx_vid. + */ + for (port = 0; port < SJA1105_NUM_PORTS; port++) { + if (!dsa_is_user_port(ds, port)) + continue; + if (dsa_to_port(ds, port)->bridge_dev != br) + continue; + + cpu = dsa_upstream_port(ds, port); + + rx_vid = dsa_8021q_rx_vid(ds, port); + + /* The VLANs on @other_cpu port should be refcounted, because + * we don't want to remove our @rx_vid just yet when a single + * remote port leaves. But that's tricky to implement, so just + * keep it simple and leave the VLANs installed on the CPU + * ports when leaving. Forwarding will still be denied, as it + * should be, because the @rx_vid has been removed from the + * remote switch's external port. + */ + if (enabled) { + /* @rx_vid of local @ds port @port goes to @other_cpu + * of @other_ds + */ + rc = sja1105_vlan_apply(other_priv, other_cpu, rx_vid, + enabled, false); + if (rc < 0) + return rc; + } + + /* @rx_vid of local @ds port @port goes to @other_port of + * @other_ds + */ + rc = sja1105_vlan_apply(other_priv, other_port, + rx_vid, enabled, true); + if (rc < 0) + return rc; + } + + /* Shorthand way of saying that we had no ports enslaved to @br. Also a + * convenient way of getting a reference to the CPU port via + * dsa_upstream_port(), which needs a valid user port as argument. + */ + if (cpu == -1) + return 0; + + /* Make traffic from the remote @other_ds switch's @other_port be + * accepted by the local @ds. This means that its @rx_vid needs to be + * installed on our local CPU port as well as local ports that are + * members of @br. + */ + other_rx_vid = dsa_8021q_rx_vid(other_ds, other_port); + + for (port = 0; port < SJA1105_NUM_PORTS; port++) { + if (!dsa_is_user_port(ds, port)) + continue; + if (dsa_to_port(ds, port)->bridge_dev != br) + continue; + + /* @other_rx_vid of @other_ds port @other_port goes to port + * @port of local @ds. + */ + rc = sja1105_vlan_apply(priv, port, other_rx_vid, enabled, + true); + if (rc < 0) + return rc; + } + + /* The comment above regarding VLAN refcounting applies here too */ + if (!enabled) + return 0; + + /* @other_rx_vid of @other_ds port @other_port goes to port @cpu of + * local @ds + */ + return sja1105_vlan_apply(priv, cpu, other_rx_vid, enabled, false); +} + +static int sja1105_crosschip_bridge_join(struct dsa_switch *ds, + int tree_index, int sw_index, + int other_port, struct net_device *br) +{ + return sja1105_crosschip_bridge_member(ds, tree_index, sw_index, + other_port, br, true); +} + +static void sja1105_crosschip_bridge_leave(struct dsa_switch *ds, + int tree_index, int sw_index, + int other_port, + struct net_device *br) +{ + sja1105_crosschip_bridge_member(ds, tree_index, sw_index, other_port, + br, false); +} + /* The programming model for the SJA1105 switch is "all-at-once" via static * configuration tables. Some of these can be dynamically modified at runtime, * but not the xMII mode parameters table. @@ -2359,6 +2479,8 @@ static const struct dsa_switch_ops sja1105_switch_ops = { .port_policer_del = sja1105_port_policer_del, .cls_flower_add = sja1105_cls_flower_add, .cls_flower_del = sja1105_cls_flower_del, + .crosschip_bridge_join = sja1105_crosschip_bridge_join, + .crosschip_bridge_leave = sja1105_crosschip_bridge_leave, }; static int sja1105_check_device_id(struct sja1105_private *priv)