From patchwork Thu Apr 30 20:25:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 1280903 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=juS4uTFo; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 49Cn2S6xqhz9sSX for ; Fri, 1 May 2020 06:25:52 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727827AbgD3UZu (ORCPT ); Thu, 30 Apr 2020 16:25:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60684 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726817AbgD3UZt (ORCPT ); Thu, 30 Apr 2020 16:25:49 -0400 Received: from mail-wm1-x342.google.com (mail-wm1-x342.google.com [IPv6:2a00:1450:4864:20::342]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 17D42C035494 for ; Thu, 30 Apr 2020 13:25:49 -0700 (PDT) Received: by mail-wm1-x342.google.com with SMTP id k12so3508119wmj.3 for ; Thu, 30 Apr 2020 13:25:49 -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=LR9SrrMw6aPuTNSYfC5PebQZxaOrhCyGQQUG01toL4Q=; b=juS4uTFouq7hWbzK53I0mtL6omR/h0+xktB+wR1NcyoSDpJ9IU+qr4Z8Ec/eNINe36 etDwbmqWnMtViH1OIIGCmn3zUAAgiZ8Qcu0AOLRIrZOnxRIoGzbEBhq+YCs4TEmQRLsx 3035rieLMSHVFZVY8hDXMu3uKU8qNuEQEmq0n4X5NmUfvumQjzSvmBGaWrgBhjXQJmPj X2LlQ2gIvCJQdex0uFXziREfXmrwZi0+7gW5VXvBOzFyOhM0PL8FSKcUrnnVvbetYNJH +thf/W1Rtt6Zli/PSmtRmkkvDFpEb0H5ftyKG9aR882CbgYAc86n9dhHbBCcmWtNZj16 mjSw== 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=LR9SrrMw6aPuTNSYfC5PebQZxaOrhCyGQQUG01toL4Q=; b=ZTztvoX2jH55hsjA664P0114VBRVVfHGhxhMazqCWikau/D7xbugnJPAxHUfga8Kk/ DOPZLLhHuxGQuTQX0AwAwhcHWwvSpEbwoc3PSULGAMhiqom9eDK6ZbV0tQT2RSgBybPq eJaFxGZHAiVLwYpWHwNH2tsHTeeLUnmK0nD+mpMyUltAnScWv8i9TcXxAxsR0W6PgVk2 oOn46gkvI0YC6JD4aWXpGgLdXyMtdnp7jQYE77s0Qk12P16tzN35Tv6V+Sf78uo+pA69 r0ikdpn67vFXl2/btWxdjzSPBHS+vIwMX8W91g+YpydJ8aXKT3g/xS08yDhgHCe5jzca FIwQ== X-Gm-Message-State: AGi0PuZGMffPgTXsQVgvAqc+x0wTbsLAmwrBjP3YIRo3MCsZMtcF9dyL tbdtKdTLIbfXFOJv6dFiT0s= X-Google-Smtp-Source: APiQypJhV8MGcGpv4/P0jtqY66rCQHegWfaunlf/Y6SwOIT6qpM0bxSUY539vmtUz9PYEOjP0cv0Wg== X-Received: by 2002:a7b:c1da:: with SMTP id a26mr317667wmj.125.1588278347715; Thu, 30 Apr 2020 13:25:47 -0700 (PDT) Received: from localhost.localdomain ([86.121.118.29]) by smtp.gmail.com with ESMTPSA id f8sm1188462wrm.14.2020.04.30.13.25.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Apr 2020 13:25:47 -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, roopa@cumulusnetworks.com Subject: [PATCH v2 net-next 1/4] net: bridge: allow enslaving some DSA master network devices Date: Thu, 30 Apr 2020 23:25:39 +0300 Message-Id: <20200430202542.11797-2-olteanv@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200430202542.11797-1-olteanv@gmail.com> References: <20200430202542.11797-1-olteanv@gmail.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Vladimir Oltean 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. Instead of the regular br_handle_frame(), install a new function br_handle_frame_dummy() on these DSA masters, which returns RX_HANDLER_PASS in order to call into the DSA specific tagging protocol handlers, and lift the restriction from br_add_if. Suggested-by: Nikolay Aleksandrov Suggested-by: Florian Fainelli Signed-off-by: Vladimir Oltean Acked-by: Nikolay Aleksandrov --- Changes in v2: * Removed the hotpath netdev_uses_dsa check and installed a dummy rx_handler for such net devices. * Improved the check of which DSA master net devices are able to be bridged and which aren't. * At this stage, the patch is different enough from where I took it from (aka https://github.com/ffainelli/linux/commit/75618cea75ada8d9eef7936c002b5ec3dd3e4eac) that I just added my authorship to it). include/net/dsa.h | 2 +- net/bridge/br_if.c | 32 +++++++++++++++++++++++--------- net/bridge/br_input.c | 23 ++++++++++++++++++++++- net/bridge/br_private.h | 6 +++--- 4 files changed, 49 insertions(+), 14 deletions(-) diff --git a/include/net/dsa.h b/include/net/dsa.h index fb3f9222f2a1..3c0ae84156c8 100644 --- a/include/net/dsa.h +++ b/include/net/dsa.h @@ -650,7 +650,7 @@ struct dsa_switch_driver { struct net_device *dsa_dev_to_net_device(struct device *dev); /* Keep inline for faster access in hot path */ -static inline bool netdev_uses_dsa(struct net_device *dev) +static inline bool netdev_uses_dsa(const struct net_device *dev) { #if IS_ENABLED(CONFIG_NET_DSA) return dev->dsa_ptr && dev->dsa_ptr->rcv; diff --git a/net/bridge/br_if.c b/net/bridge/br_if.c index ca685c0cdf95..a0e9a7937412 100644 --- a/net/bridge/br_if.c +++ b/net/bridge/br_if.c @@ -563,18 +563,32 @@ int br_add_if(struct net_bridge *br, struct net_device *dev, unsigned br_hr, dev_hr; bool changed_addr; - /* Don't allow bridging non-ethernet like devices, or DSA-enabled - * master network devices since the bridge layer rx_handler prevents - * the DSA fake ethertype handler to be invoked, so we do not strip off - * the DSA switch tag protocol header and the bridge layer just return - * RX_HANDLER_CONSUMED, stopping RX processing for these frames. - */ + /* Don't allow bridging non-ethernet like devices. */ 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; + /* Also don't allow bridging of net devices that are DSA masters, since + * the bridge layer rx_handler prevents the DSA fake ethertype handler + * to be invoked, so we don't get the chance to strip off and parse the + * DSA switch tag protocol header (the bridge layer just returns + * RX_HANDLER_CONSUMED, stopping RX processing for these frames). + * The only case where that would not be an issue is when bridging can + * already be offloaded, such as when the DSA master is itself a DSA + * or plain switchdev port, and is bridged only with other ports from + * the same hardware device. + */ + if (netdev_uses_dsa(dev)) { + list_for_each_entry(p, &br->port_list, list) { + if (!netdev_port_same_parent_id(dev, p->dev)) { + NL_SET_ERR_MSG(extack, + "Cannot do software bridging with a DSA master"); + return -EINVAL; + } + } + } + /* No bridging of bridges */ if (dev->netdev_ops->ndo_start_xmit == br_dev_xmit) { NL_SET_ERR_MSG(extack, @@ -618,7 +632,7 @@ int br_add_if(struct net_bridge *br, struct net_device *dev, if (err) goto err3; - err = netdev_rx_handler_register(dev, br_handle_frame, p); + err = netdev_rx_handler_register(dev, br_get_rx_handler(dev), p); if (err) goto err4; diff --git a/net/bridge/br_input.c b/net/bridge/br_input.c index d5c34f36f0f4..59a318b9f646 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" @@ -257,7 +258,7 @@ static int nf_hook_bridge_pre(struct sk_buff *skb, struct sk_buff **pskb) * Return NULL if skb is handled * note: already called with rcu_read_lock */ -rx_handler_result_t br_handle_frame(struct sk_buff **pskb) +static rx_handler_result_t br_handle_frame(struct sk_buff **pskb) { struct net_bridge_port *p; struct sk_buff *skb = *pskb; @@ -359,3 +360,23 @@ rx_handler_result_t br_handle_frame(struct sk_buff **pskb) } return RX_HANDLER_CONSUMED; } + +/* This function has no purpose other than to appease the br_port_get_rcu/rtnl + * helpers which identify bridged ports according to the rx_handler installed + * on them (so there _needs_ to be a bridge rx_handler even if we don't need it + * to do anything useful). This bridge won't support traffic to/from the stack, + * but only hardware bridging. So return RX_HANDLER_PASS so we don't steal + * frames from the ETH_P_XDSA packet_type handler. + */ +static rx_handler_result_t br_handle_frame_dummy(struct sk_buff **pskb) +{ + return RX_HANDLER_PASS; +} + +rx_handler_func_t *br_get_rx_handler(const struct net_device *dev) +{ + if (netdev_uses_dsa(dev)) + return br_handle_frame_dummy; + + return br_handle_frame; +} diff --git a/net/bridge/br_private.h b/net/bridge/br_private.h index c35647cb138a..0defc2ff365f 100644 --- a/net/bridge/br_private.h +++ b/net/bridge/br_private.h @@ -705,16 +705,16 @@ int nbp_backup_change(struct net_bridge_port *p, struct net_device *backup_dev); /* br_input.c */ int br_handle_frame_finish(struct net *net, struct sock *sk, struct sk_buff *skb); -rx_handler_result_t br_handle_frame(struct sk_buff **pskb); +rx_handler_func_t *br_get_rx_handler(const struct net_device *dev); static inline bool br_rx_handler_check_rcu(const struct net_device *dev) { - return rcu_dereference(dev->rx_handler) == br_handle_frame; + return rcu_dereference(dev->rx_handler) == br_get_rx_handler(dev); } static inline bool br_rx_handler_check_rtnl(const struct net_device *dev) { - return rcu_dereference_rtnl(dev->rx_handler) == br_handle_frame; + return rcu_dereference_rtnl(dev->rx_handler) == br_get_rx_handler(dev); } static inline struct net_bridge_port *br_port_get_check_rcu(const struct net_device *dev) From patchwork Thu Apr 30 20:25:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 1280904 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=WsCTqsGj; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 49Cn2T3NjXz9sSK for ; Fri, 1 May 2020 06:25:53 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727834AbgD3UZw (ORCPT ); Thu, 30 Apr 2020 16:25:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60688 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726817AbgD3UZu (ORCPT ); Thu, 30 Apr 2020 16:25:50 -0400 Received: from mail-wr1-x441.google.com (mail-wr1-x441.google.com [IPv6:2a00:1450:4864:20::441]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 40376C035494 for ; Thu, 30 Apr 2020 13:25:50 -0700 (PDT) Received: by mail-wr1-x441.google.com with SMTP id i10so8800781wrv.10 for ; Thu, 30 Apr 2020 13:25:50 -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=dpXI1V5ghMRhSJL8SIXWkXSPLtONjElZBTYDshyr6ZM=; b=WsCTqsGjLYccKUjY2fb9LWpK8fpE+bTSz0p48q1AQR5R1/WmMuxxxTbuVdk5ph/r2o wErZsvfegW7vP3SUEYXTqTyoxi6Dpau0ItJFUkkmWWP/9p+kKLtWbtil2unKIzjM2ApY 1cWB5JYbZaEJjgV+O/gAo6401bZsFsfWVFx6ifDSZql40M6j9K/zFMMv1PheZmqFefuA qh/wAsi4kOcp3J5geRs9ij9hw4wfaBHuDcjhTzalo4mBc/AC11RvEQgm5NrD2vT8o10I 0WOP3O3EJMLRDp9IXBaLTKTkDVRWUzVefwbdcza3egpwc0ts/4w+dO3yZ78sJCu/yecm +f+w== 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=dpXI1V5ghMRhSJL8SIXWkXSPLtONjElZBTYDshyr6ZM=; b=icYvcPDfdJZtw9x6Bt2uKm32V6gNHxx6hv/KDdBF7iPMuDLuJJnrGOq9rCQ1GyUqNG Fp3+TNa8ZMkptCgLf8GkKRPv2G/BOokWtKMm429VkpPtJ91j5hHv6MxmrNC0J1+BjSNA 0/Pzvg4WDGEAT1etX1oYYQNMEcc3MwYdUnMv05Q1DnD/lJUq7/dmBPo78gPrm0cLtwK5 k8fXxlFpipNpe7SiCL60vEln7V5rzlRjQdMlrhYz7cSwaQPFvFtk89eRy4iE9szNneXM Xntl3W2SUTJPFe92XsfQxQWj9kMneCFuMU3f6Xo2TqUD4So/7ZpaFw/bwHOt2cd/KRPg CNgA== X-Gm-Message-State: AGi0PuaLAzQTbFqOLS7xJy+C9qE6vp7AFZ6QTc6vdB2b4G7suG1aziOf QUK7AHjyeY69/XNHAwI0RMs= X-Google-Smtp-Source: APiQypLPqqJsOdu05oQ/k6/tewSiLIB1LwDkEhaDfn7giqBX3lwp3800LmW+gX5cf65uqR1suwJPAw== X-Received: by 2002:adf:f844:: with SMTP id d4mr343325wrq.362.1588278348913; Thu, 30 Apr 2020 13:25:48 -0700 (PDT) Received: from localhost.localdomain ([86.121.118.29]) by smtp.gmail.com with ESMTPSA id f8sm1188462wrm.14.2020.04.30.13.25.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Apr 2020 13:25:48 -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, roopa@cumulusnetworks.com Subject: [PATCH v2 net-next 2/4] net: dsa: permit cross-chip bridging between all trees in the system Date: Thu, 30 Apr 2020 23:25:40 +0300 Message-Id: <20200430202542.11797-3-olteanv@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200430202542.11797-1-olteanv@gmail.com> References: <20200430202542.11797-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 --- Changes in v2: None. 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 3c0ae84156c8..bd5561dacb13 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 Thu Apr 30 20:25:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 1280905 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=YWC+O+Ld; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 49Cn2V1mN0z9sSM for ; Fri, 1 May 2020 06:25:54 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727842AbgD3UZx (ORCPT ); Thu, 30 Apr 2020 16:25:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60692 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727832AbgD3UZw (ORCPT ); Thu, 30 Apr 2020 16:25:52 -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 4C187C035494 for ; Thu, 30 Apr 2020 13:25:51 -0700 (PDT) Received: by mail-wr1-x443.google.com with SMTP id d17so8792458wrg.11 for ; Thu, 30 Apr 2020 13:25:51 -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=ApjSk/50jRjyhk0cZtIwoXWTq09wjHoGSh17ig0ay5c=; b=YWC+O+LdWhsqzyspxUM7YjSVEcHKKIWGhyKRmoxLF3TIJV8c4MeMhbtYGLomwahSjF lZazMZBGKto/+A7rheZZ50HmYYRGMhg188zw1hZozb1rzn9WZ7dcHUC1NaY2VDBSWEHt XsiMDwqK5boYRZOyJprKdUOGNlL79MXfTGcDP5wrlXryzQLxEzi05nDqgn67MB6LzQAD nWHn8V7hDrH++5+QVQeABmtdSJGl2zw4H3t7mno+JTcoN0oR2ZPgZwKo65nIkQuICOuP LDxeXPix5MN6up5RjLmn/8E2wWwoMF+MZsUPZMijtJu/mlBrBeyklce/rGUO4kjFNXI3 YTaQ== 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=ApjSk/50jRjyhk0cZtIwoXWTq09wjHoGSh17ig0ay5c=; b=KpAJADNWRxIv32/0nhPJEyHI97vbW/LSdmhSAv45lWtcrIcB4PukPpxDpyOunu+nny eYNBg/Yhxc4b2tzF5pCsfCEvuFC7SPgnaMKLoHrldKUKmMe5MUBsc9dM5TjTY+CeVKlZ BR0B4zdnjMhGCU2v0cFs540hwMD2Eyv8DsO7PZy75nGmp1PMqYHUSR0foVzfE+RapOeT 1hiJIOVyqtnUMAW68EApY+WKbE2pFu1ifYRd+jgPPT6E8UUPjzdFNrFX7W/3Rq8OQD4H KAVRuIgY2alPu4bsAafxIa3AVsW/wstZb9kso0HK+fQp9/JXFy464QljaP+IqoFl+raX gHow== X-Gm-Message-State: AGi0PuZyvtUTVP2TDxu19WKf8/8S6fLzYx2ys92e6oUREF7KSvXANVuT e7qo/HNMoYg5mGNIST8Fz88= X-Google-Smtp-Source: APiQypJYeGGDytoOIHHatQgRUjsXh4dq/L9xSXlHWi6l0xWP4C+vhz5rYdk9/jd4jU0KqeEPXjcWnQ== X-Received: by 2002:adf:dcca:: with SMTP id x10mr361797wrm.212.1588278350080; Thu, 30 Apr 2020 13:25:50 -0700 (PDT) Received: from localhost.localdomain ([86.121.118.29]) by smtp.gmail.com with ESMTPSA id f8sm1188462wrm.14.2020.04.30.13.25.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Apr 2020 13:25:49 -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, roopa@cumulusnetworks.com Subject: [PATCH v2 net-next 3/4] net: dsa: introduce a dsa_switch_find function Date: Thu, 30 Apr 2020 23:25:41 +0300 Message-Id: <20200430202542.11797-4-olteanv@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200430202542.11797-1-olteanv@gmail.com> References: <20200430202542.11797-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 --- Changes in v2: None. 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 bd5561dacb13..c5e2530f54c9 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 Thu Apr 30 20:25:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 1280906 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=G4A6D1/w; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 49Cn2X3skNz9sSK for ; Fri, 1 May 2020 06:25:56 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727855AbgD3UZz (ORCPT ); Thu, 30 Apr 2020 16:25:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60698 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727835AbgD3UZx (ORCPT ); Thu, 30 Apr 2020 16:25:53 -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 AA54BC035495 for ; Thu, 30 Apr 2020 13:25:52 -0700 (PDT) Received: by mail-wm1-x341.google.com with SMTP id u127so3720214wmg.1 for ; Thu, 30 Apr 2020 13:25:52 -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=f4SwCAXCxrU0cnOC51WJEylW3Rjq5yh0DKQxZ3Li9+k=; b=G4A6D1/wAh19XGjVWZTNvpsF/Atyib7JT+qk5J2tEG1YMB70rQnz76E0zfx5aPgvq/ 7P8pLAZ9YCbgWLTk3ltsPkyerq3vhExyF3/pPwWHtPVLcB08EH/l9E578oBaTNtRkoK8 QNPX0s6o4nW0DPC0+u29DwXR1cwLE+/3v3SMqsWlu2BA+0oag7cg3LGWUwJLo/3RkTJf FKUQizuGDeLiAb4q2T31azjAqtVDu45RSeQTn/hgDIASkaAoxWT7tVrRPqewXXxzEgoA Uek/hHIqeCkhE/uBrubVqb+L9Yhz5T7eyh3rpp/3KEiHz3Kxg5oH6GwFrDvyyevGvYZM +5/Q== 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=f4SwCAXCxrU0cnOC51WJEylW3Rjq5yh0DKQxZ3Li9+k=; b=DNpWf2wt6TWnZ+Sq1ngys0EfnYijkyZXHIL70WL3GibqPWmZtruCCp/SHWYD+mul+P qPy9qvI3ZjIpqRR38pHudPHa1m0g6yhd5wlB09AT6G2s3x4cN5MhR1Ii97yCVpvn5hq5 kxyOaGmnOQn7Z6Y5MkaDjxr3/rYaUjfUHkN02qc03fWkbUZPvQVupoU/CtdHjJzW85XS r6pdO9FQNdy+saM/JvOCLoV6vzs7XQu/Gv2UgJhM/9KAtLeDph9pdyAa/Wndk1MqODmK FzncA6iiaUD8fDc6Auq3qoEaAUmI2/5EaqfaCsl5UPL23hOxp2tF5wdRzG0PMJ9IEDiK ZiTQ== X-Gm-Message-State: AGi0PubpiGdr954ar0RU7sJCaTi+pkrn2ivD6dkTVdevtACyPgjxNY4x U+3fY3r8GohMXVvrBtJWGac= X-Google-Smtp-Source: APiQypKOTdhmGRAWB/nTe9Hbv7SAOGHR8pW9ECZJGIFE6ih4e1J80/bhOPHDyoHjc38haIDYfQocBQ== X-Received: by 2002:a7b:c755:: with SMTP id w21mr370228wmk.120.1588278351220; Thu, 30 Apr 2020 13:25:51 -0700 (PDT) Received: from localhost.localdomain ([86.121.118.29]) by smtp.gmail.com with ESMTPSA id f8sm1188462wrm.14.2020.04.30.13.25.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Apr 2020 13:25:50 -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, roopa@cumulusnetworks.com Subject: [PATCH v2 net-next 4/4] net: dsa: sja1105: implement cross-chip bridging operations Date: Thu, 30 Apr 2020 23:25:42 +0300 Message-Id: <20200430202542.11797-5-olteanv@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200430202542.11797-1-olteanv@gmail.com> References: <20200430202542.11797-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 --- Changes in v2: Now replaying the crosschip operations when toggling the VLAN filtering state (aka when we need to hide the dsa_8021q VLANs, as the VLAN filtering table becomes visible to the user so it needs to be cleared - and perhaps restored afterwards). drivers/net/dsa/sja1105/sja1105.h | 9 ++ drivers/net/dsa/sja1105/sja1105_main.c | 183 +++++++++++++++++++++++++ 2 files changed, 192 insertions(+) diff --git a/drivers/net/dsa/sja1105/sja1105.h b/drivers/net/dsa/sja1105/sja1105.h index 2f62942692ec..6b4fad1216bb 100644 --- a/drivers/net/dsa/sja1105/sja1105.h +++ b/drivers/net/dsa/sja1105/sja1105.h @@ -127,6 +127,14 @@ struct sja1105_flow_block { bool l2_policer_used[SJA1105_NUM_L2_POLICERS]; }; +struct sja1105_crosschip_info { + struct list_head list; + int tree_index; + int sw_index; + int other_port; + struct net_device *br; +}; + struct sja1105_private { struct sja1105_static_config static_config; bool rgmii_rx_delay[SJA1105_NUM_PORTS]; @@ -135,6 +143,7 @@ struct sja1105_private { struct gpio_desc *reset_gpio; struct spi_device *spidev; struct dsa_switch *ds; + struct list_head crosschip_ports; struct sja1105_flow_block flow_block; struct sja1105_port ports[SJA1105_NUM_PORTS]; /* Serializes transmission of management frames so that diff --git a/drivers/net/dsa/sja1105/sja1105_main.c b/drivers/net/dsa/sja1105/sja1105_main.c index 472f4eb20c49..95e00e03d05b 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) { @@ -1790,6 +1792,176 @@ static int sja1105_vlan_apply(struct sja1105_private *priv, int port, u16 vid, 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) +{ + struct sja1105_private *priv = ds->priv; + struct sja1105_crosschip_info *c; + int rc; + + if (!br_vlan_enabled(br)) { + rc = sja1105_crosschip_bridge_member(ds, tree_index, sw_index, + other_port, br, true); + if (rc) + return rc; + } + + c = kzalloc(sizeof(*c), GFP_KERNEL); + if (!c) + return -ENOMEM; + + c->tree_index = tree_index; + c->sw_index = sw_index; + c->other_port = other_port; + c->br = br; + + list_add(&c->list, &priv->crosschip_ports); + + return 0; +} + +static void sja1105_crosschip_bridge_leave(struct dsa_switch *ds, + int tree_index, int sw_index, + int other_port, + struct net_device *br) +{ + struct sja1105_private *priv = ds->priv; + struct sja1105_crosschip_info *c, *n; + + if (!br_vlan_enabled(br)) + sja1105_crosschip_bridge_member(ds, tree_index, sw_index, + other_port, br, false); + + list_for_each_entry_safe(c, n, &priv->crosschip_ports, list) { + if (c->tree_index == tree_index && c->sw_index == sw_index && + c->other_port == other_port && c->br == br) { + list_del(&c->list); + kfree(c); + break; + } + } +} + +static int sja1105_apply_crosschip_vlans(struct dsa_switch *ds, bool enabled) +{ + struct sja1105_private *priv = ds->priv; + struct sja1105_crosschip_info *c; + int rc; + + list_for_each_entry(c, &priv->crosschip_ports, list) { + rc = sja1105_crosschip_bridge_member(ds, c->tree_index, + c->sw_index, + c->other_port, c->br, + enabled); + if (rc) + break; + } + + return rc; +} + static int sja1105_setup_8021q_tagging(struct dsa_switch *ds, bool enabled) { int rc, i; @@ -1802,6 +1974,13 @@ static int sja1105_setup_8021q_tagging(struct dsa_switch *ds, bool enabled) return rc; } } + /* Replay the crosschip operations whenever we need to enable or + * disable DSA tagging. + */ + rc = sja1105_apply_crosschip_vlans(ds, enabled); + if (rc) + return rc; + dev_info(ds->dev, "%s switch tagging\n", enabled ? "Enabled" : "Disabled"); return 0; @@ -2359,6 +2538,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) @@ -2461,6 +2642,8 @@ static int sja1105_probe(struct spi_device *spi) mutex_init(&priv->ptp_data.lock); mutex_init(&priv->mgmt_lock); + INIT_LIST_HEAD(&priv->crosschip_ports); + sja1105_tas_setup(ds); sja1105_flower_setup(ds);