From nobody Sat Feb 7 19:04:11 2026 Received: from mail-ed1-f53.google.com (mail-ed1-f53.google.com [209.85.208.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8372E14532B; Fri, 23 Feb 2024 21:01:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708722106; cv=none; b=gR8oVuJ/AgiDfjPI+1wFUlT2oV5clhsQJ560hdm6il2/lJIkRUm8a6tGXf7jGC7Ccs8/oXepHeDrHwIAKil93AhM9d4u1GKIX2kfUl3mhF0MCR4Ro5LLL0qRP01s5FGQFd6VRAzoXsoXHJ1eP+uFUKGvqyY5zvhHKnJlk9OrdXg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708722106; c=relaxed/simple; bh=9fsXlW8k/82RP59Hyg0tIsH191jUNaBCZk2e6c+plbE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=PX8LtAUZn6gYgbcOF0ryYnW1LRuqL4ulkQ1g7MD2WWivqmTaeibriv+ED3RW8E+x6N+1HTViYLaFYEWXCKykinzTa7DsMMXE4PhR6jpvUDJzts23Dn6tAMnUSAIraA3SleKCBVfSrH5aUrfGDInX+uvgQFLhbzHAeCWn7L5qBk4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=LZkQfmV9; arc=none smtp.client-ip=209.85.208.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="LZkQfmV9" Received: by mail-ed1-f53.google.com with SMTP id 4fb4d7f45d1cf-564d9b0e96dso1033848a12.2; Fri, 23 Feb 2024 13:01:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708722102; x=1709326902; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=QouBmNwC5Mz1DDSViLi9LfWxt2YyADxYyZ8tYZSUz6c=; b=LZkQfmV9jkh4J2cPZVvJLYkwY5hwpptqTF3SFuVaCbyvEFxy1rAEottee777Xgl7Wn s8AzwKc3y0d5wVUh8XBW/R8N3by6xFfzO2Md5pTschuTKITSAQ5zBlRjn774fIaVkzTl kRlnVYYnl0w9vI69ZZ+AX1GQ0+vKh5rtN6YUVKKDDCixiorQRE77W3gsPn1y2iHz5/jK oAfYDyM8nrmFKKCiQdk2KaMS++OLsUzMiLo0mBEr5JWqUiueedYIrTT7aTpU2X2W7Z3+ KYsB9x/fVDoefu4Fnb70qyZ0BbY2ocRgFjhAb017l72RonQ/N19t0FG6b+V445kyLauL 2g+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708722102; x=1709326902; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=QouBmNwC5Mz1DDSViLi9LfWxt2YyADxYyZ8tYZSUz6c=; b=FSVVeuc5vk3+ARBTqVmHz5ZimWTxk//jOk4lZAMcgijjbaoS3enVDoxLRqIL2/TOB/ kW/aKx2PaRdiPmZIu8YfYn8U6srlA/aeKimgJg+dcKzn7QPaMwPi4DDr0ziCbC7RyEwi HGuGxxkw2jP5KnRChYGoHBjKiUQnl4cCWT8f/O6w1WvJhnBdxuTcgN/Gg75F+S7AYIyo 43H5dJg0ynvgFhTznok1CARjiq2JNrgQKkCA1TT0K/64hnJqvwGw2BLw1cQyAE/TsvUr QRVrwcb8apEZu24wYfheU+rD16tsUkmhOMItzTrZlPr7N4KQGLbqX8+n3gTHTPU+ULVE dwgA== X-Forwarded-Encrypted: i=1; AJvYcCVHl8xljZCDROysb9ST7Tl8ZF0Nr9U+72XuiJpJ1njnHcNX3PsnlhcZUyk2OBfIZp5mBbN2JC/T6y8s5yHjzYtMy/JGmtPCI/YER12u X-Gm-Message-State: AOJu0YwWJEmQpjgBmpuIpIDnKeU/cQOOd3xknuPIzMNGUYdvW0w7UY1P iOqNjDArbAD4YFZezAMoVi6DxG4z6w67U/W1dntnTRnLxVoGnjhqjtx4IRuv3ZQ= X-Google-Smtp-Source: AGHT+IE+PDfUSbpkJadKxGFZIZzUyuC/W/FK5GgZQlcn7ptjpfuXp14gxEB//j6Z9tG2+jLFaqhIAg== X-Received: by 2002:a17:906:7c55:b0:a3e:6501:339d with SMTP id g21-20020a1709067c5500b00a3e6501339dmr666452ejp.61.1708722102190; Fri, 23 Feb 2024 13:01:42 -0800 (PST) Received: from WBEC325.dom.lan ([185.188.71.122]) by smtp.gmail.com with ESMTPSA id st11-20020a170907c08b00b00a3e559aaff9sm6185424ejc.29.2024.02.23.13.01.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Feb 2024 13:01:41 -0800 (PST) From: Pawel Dembicki To: netdev@vger.kernel.org Cc: linus.walleij@linaro.org, Pawel Dembicki , Russell King , Andrew Lunn , Florian Fainelli , Florian Fainelli , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Claudiu Manoil , Alexandre Belloni , UNGLinuxDriver@microchip.com, linux-kernel@vger.kernel.org Subject: [PATCH net-next v5 01/16] net: dsa: vsc73xx: use read_poll_timeout instead delay loop Date: Fri, 23 Feb 2024 22:00:31 +0100 Message-Id: <20240223210049.3197486-2-paweldembicki@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240223210049.3197486-1-paweldembicki@gmail.com> References: <20240223210049.3197486-1-paweldembicki@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Switch the delay loop during the Arbiter empty check from vsc73xx_adjust_link() to use read_poll_timeout(). Functionally, one msleep() call is eliminated at the end of the loop in the timeout case. As Russell King suggested: "This [change] avoids the issue that on the last iteration, the code reads the register, tests it, finds the condition that's being waiting for is false, _then_ waits and end up printing the error message - that last wait is rather useless, and as the arbiter state isn't checked after waiting, it could be that we had success during the last wait." Suggested-by: Russell King Reviewed-by: Andrew Lunn Reviewed-by: Linus Walleij Reviewed-by: Florian Fainelli Signed-off-by: Pawel Dembicki --- v5: - improved commit description - added two defines instead magic numbers - added include with iopoll.h v4: - resend patch v3: - added "Reviewed-by" to commit message only v2: - introduced patch drivers/net/dsa/vitesse-vsc73xx-core.c | 30 ++++++++++++++------------ 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/drivers/net/dsa/vitesse-vsc73xx-core.c b/drivers/net/dsa/vites= se-vsc73xx-core.c index ae70eac3be28..ab5771d4d828 100644 --- a/drivers/net/dsa/vitesse-vsc73xx-core.c +++ b/drivers/net/dsa/vitesse-vsc73xx-core.c @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -268,6 +269,9 @@ #define IS_7398(a) ((a)->chipid =3D=3D VSC73XX_CHIPID_ID_7398) #define IS_739X(a) (IS_7395(a) || IS_7398(a)) =20 +#define VSC73XX_POLL_SLEEP_US 1000 +#define VSC73XX_POLL_TIMEOUT_US 10000 + struct vsc73xx_counter { u8 counter; const char *name; @@ -779,7 +783,7 @@ static void vsc73xx_adjust_link(struct dsa_switch *ds, = int port, * after a PHY or the CPU port comes up or down. */ if (!phydev->link) { - int maxloop =3D 10; + int ret, err; =20 dev_dbg(vsc->dev, "port %d: went down\n", port); @@ -794,19 +798,17 @@ static void vsc73xx_adjust_link(struct dsa_switch *ds= , int port, VSC73XX_ARBDISC, BIT(port), BIT(port)); =20 /* Wait until queue is empty */ - vsc73xx_read(vsc, VSC73XX_BLOCK_ARBITER, 0, - VSC73XX_ARBEMPTY, &val); - while (!(val & BIT(port))) { - msleep(1); - vsc73xx_read(vsc, VSC73XX_BLOCK_ARBITER, 0, - VSC73XX_ARBEMPTY, &val); - if (--maxloop =3D=3D 0) { - dev_err(vsc->dev, - "timeout waiting for block arbiter\n"); - /* Continue anyway */ - break; - } - } + ret =3D read_poll_timeout(vsc73xx_read, err, + err < 0 || (val & BIT(port)), + VSC73XX_POLL_SLEEP_US, + VSC73XX_POLL_TIMEOUT_US, false, + vsc, VSC73XX_BLOCK_ARBITER, 0, + VSC73XX_ARBEMPTY, &val); + if (ret) + dev_err(vsc->dev, + "timeout waiting for block arbiter\n"); + else if (err < 0) + dev_err(vsc->dev, "error reading arbiter\n"); =20 /* Put this port into reset */ vsc73xx_write(vsc, VSC73XX_BLOCK_MAC, port, VSC73XX_MAC_CFG, --=20 2.34.1 From nobody Sat Feb 7 19:04:11 2026 Received: from mail-ed1-f45.google.com (mail-ed1-f45.google.com [209.85.208.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A4F12146E8C; Fri, 23 Feb 2024 21:01:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708722114; cv=none; b=Tt0XwH4fo8qyUkNJEw0J1MrMhs/lz4rv2Yjq3BBlDErhQVE6AxgZQPaX907hRpoT8eermMXIfubXxMSx6eKy3Ezh8b26VyNS5HIVEyjhceYjkjUXQukqucDwmqmh6tVEJfRyb9rNb1QN1ipcFAN3FwR8pBPWAIchCc2/i9gnFyQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708722114; c=relaxed/simple; bh=2IGaelDIgCYR4RgiqKcmwo0tHaiSsj2BS1E8ORjmnkw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Zn+O5rAXQibYBDLqzu+jSPdX1jyTSegFPp0/6jplq2P/5/u00bmOuvl/GxGRtdp+YLuPxmgm9/TNHM2IlHSwx6Pe3QBGutG91o54Gg3Rq1U30tsQAn2foyHg6D5Rtazrf1cO38dRQ7PZwJiZNddFEKEW4ldysQver+agUgp/1oA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=MImA3q6T; arc=none smtp.client-ip=209.85.208.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="MImA3q6T" Received: by mail-ed1-f45.google.com with SMTP id 4fb4d7f45d1cf-564647bcdbfso1238403a12.2; Fri, 23 Feb 2024 13:01:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708722110; x=1709326910; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=5w6OYQ2wklfdPvhp1HMp63z3R/jBQE2KyU5Swu+vJNw=; b=MImA3q6TALZmrX0v1mirw1ApSJGvXp3R6WWAIun9+Rx7VKwrWHZnfW6PZ81AY3yyGF L0Mhvy/4axHD4BTTXkQ0cJIYuDvrPjHCb/0Ali0S4rk9L9CBZyUh0qa/S5Q0cr42pb4l J91KTzipckIv5mvjUHcTk6jEivp1Ebd5HI2bju+HLuOTdeN/A1FDEGiIsfEX+WjnL+OI UHvHmtquvb2cUf9SrH49y3j3hWGYT6WEdJMWk9ul4qhV7uvnmw6UOEjHCE+cm48uVWSc nPQovRZBhHftTLj0PKRiSmnLFHVzDtPMglR21l4INXZi31Iqw8Tyw0/oC0LL65CE0MFJ fIWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708722110; x=1709326910; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=5w6OYQ2wklfdPvhp1HMp63z3R/jBQE2KyU5Swu+vJNw=; b=puXZEhU7FoTfkbQ+D6RZkgj0K77weaYcQw6Vb0/1wPVPmKtNCHtiQW8qelafR3Ad0l q8DDtq8NnMmtS8IOQ4E4IXhWIlpNPdeu3FvPc8TkWoFVvlN7ErYqJ6sMbPf390ECDrZA B+PDZYErpICXNUyIyEJssTPQLM0rcy2KklWu6Ggwt4R0gvfB66KGVJGf/O5CaCPhgXdM 4qi+TNfmffUH/MzHBlPJgFBVzFgLGIuJAEnqHVdkgc2+D4rKS5QdBxruRH4VTmJqG3nI Ghs9sP/nh+/Hg6RsD8XwmvX9u/vq+kn1LnFZMteqMGbSgV4UO8asuBDaxFoVozPjAKxc FnNQ== X-Forwarded-Encrypted: i=1; AJvYcCUEr7j5r8Rd7Zw03vrB1MzVIEOi/SZKMSvIX/XJ8Rj/huhAl+cH/qH4VpI/btd0dMWUmbn6JclKjmjv8PAOmoFfndu6yl6ONy2ZdZqM X-Gm-Message-State: AOJu0Yx6VMYcdUvxOxSDBysTdG3gqZqurU/flWVprQv7OOClq5VqLFKd e/nl14wKGftzJcHzI6k9hdXjCMbjdvHlY/9AJbsmPE8XhMnY5G80/jXMF2pA7OU= X-Google-Smtp-Source: AGHT+IEtd+hfrVnCC4fnjGCN3lhF25TkchqQ/1pf/DH4YLm5ynXY0A0tYCFO6rDOjh4Qy6H+6jrvQA== X-Received: by 2002:a17:906:d04e:b0:a3e:63bd:3ae1 with SMTP id bo14-20020a170906d04e00b00a3e63bd3ae1mr547419ejb.9.1708722110351; Fri, 23 Feb 2024 13:01:50 -0800 (PST) Received: from WBEC325.dom.lan ([185.188.71.122]) by smtp.gmail.com with ESMTPSA id st11-20020a170907c08b00b00a3e559aaff9sm6185424ejc.29.2024.02.23.13.01.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Feb 2024 13:01:49 -0800 (PST) From: Pawel Dembicki To: netdev@vger.kernel.org Cc: linus.walleij@linaro.org, Pawel Dembicki , Andrew Lunn , Florian Fainelli , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Claudiu Manoil , Alexandre Belloni , UNGLinuxDriver@microchip.com, Russell King , linux-kernel@vger.kernel.org Subject: [PATCH net-next v5 02/16] net: dsa: vsc73xx: convert to PHYLINK Date: Fri, 23 Feb 2024 22:00:32 +0100 Message-Id: <20240223210049.3197486-3-paweldembicki@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240223210049.3197486-1-paweldembicki@gmail.com> References: <20240223210049.3197486-1-paweldembicki@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This patch replaces the adjust_link api with the phylink apis that provide equivalent functionality. The remaining functionality from the adjust_link is now covered in the phylink_mac_link_* and phylink_mac_config. Removes: .adjust_link Adds: .phylink_mac_config .phylink_mac_link_up .phylink_mac_link_down Signed-off-by: Pawel Dembicki --- v5: - introduce MAC reset function with procedure described in datasheet - reorganise routines - move 'Accept packets again' routine to 'phylink_mac_link_up' - fix one FIXME v4: - update commit descripion - remove phylink_get_caps after rebase to current net-next/main v3: - remove legacy_pre_march2020 after rebase v2: - replace switch to if and get rid of macros in vsc73xx_phylink_mac_link_up function drivers/net/dsa/vitesse-vsc73xx-core.c | 235 ++++++++++++------------- 1 file changed, 109 insertions(+), 126 deletions(-) diff --git a/drivers/net/dsa/vitesse-vsc73xx-core.c b/drivers/net/dsa/vites= se-vsc73xx-core.c index ab5771d4d828..cb2e7e256279 100644 --- a/drivers/net/dsa/vitesse-vsc73xx-core.c +++ b/drivers/net/dsa/vitesse-vsc73xx-core.c @@ -717,52 +717,43 @@ static void vsc73xx_init_port(struct vsc73xx *vsc, in= t port) port, VSC73XX_C_RX0, 0); } =20 -static void vsc73xx_adjust_enable_port(struct vsc73xx *vsc, - int port, struct phy_device *phydev, - u32 initval) +static void vsc73xx_reset_port(struct vsc73xx *vsc, int port, u32 initval) { - u32 val =3D initval; - u8 seed; - - /* Reset this port FIXME: break out subroutine */ - val |=3D VSC73XX_MAC_CFG_RESET; - vsc73xx_write(vsc, VSC73XX_BLOCK_MAC, port, VSC73XX_MAC_CFG, val); - - /* Seed the port randomness with randomness */ - get_random_bytes(&seed, 1); - val |=3D seed << VSC73XX_MAC_CFG_SEED_OFFSET; - val |=3D VSC73XX_MAC_CFG_SEED_LOAD; - val |=3D VSC73XX_MAC_CFG_WEXC_DIS; - vsc73xx_write(vsc, VSC73XX_BLOCK_MAC, port, VSC73XX_MAC_CFG, val); + int ret, err; + u32 val; =20 - /* Flow control for the PHY facing ports: - * Use a zero delay pause frame when pause condition is left - * Obey pause control frames - * When generating pause frames, use 0xff as pause value - */ - vsc73xx_write(vsc, VSC73XX_BLOCK_MAC, port, VSC73XX_FCCONF, - VSC73XX_FCCONF_ZERO_PAUSE_EN | - VSC73XX_FCCONF_FLOW_CTRL_OBEY | - 0xff); + /* Disable RX on this port */ + vsc73xx_update_bits(vsc, VSC73XX_BLOCK_MAC, port, + VSC73XX_MAC_CFG, + VSC73XX_MAC_CFG_RX_EN, 0); =20 - /* Disallow backward dropping of frames from this port */ + /* Discard packets */ vsc73xx_update_bits(vsc, VSC73XX_BLOCK_ARBITER, 0, - VSC73XX_SBACKWDROP, BIT(port), 0); + VSC73XX_ARBDISC, BIT(port), BIT(port)); + + /* Wait until queue is empty */ + ret =3D read_poll_timeout(vsc73xx_read, err, + err < 0 || (val & BIT(port)), + VSC73XX_POLL_SLEEP_US, + VSC73XX_POLL_TIMEOUT_US, false, + vsc, VSC73XX_BLOCK_ARBITER, 0, + VSC73XX_ARBEMPTY, &val); + if (ret) + dev_err(vsc->dev, + "timeout waiting for block arbiter\n"); + else if (err < 0) + dev_err(vsc->dev, "error reading arbiter\n"); =20 - /* Enable TX, RX, deassert reset, stop loading seed */ - vsc73xx_update_bits(vsc, VSC73XX_BLOCK_MAC, port, - VSC73XX_MAC_CFG, - VSC73XX_MAC_CFG_RESET | VSC73XX_MAC_CFG_SEED_LOAD | - VSC73XX_MAC_CFG_TX_EN | VSC73XX_MAC_CFG_RX_EN, - VSC73XX_MAC_CFG_TX_EN | VSC73XX_MAC_CFG_RX_EN); + /* Put this port into reset */ + vsc73xx_write(vsc, VSC73XX_BLOCK_MAC, port, VSC73XX_MAC_CFG, + VSC73XX_MAC_CFG_RESET | initval); } =20 -static void vsc73xx_adjust_link(struct dsa_switch *ds, int port, - struct phy_device *phydev) +static void vsc73xx_phylink_mac_config(struct dsa_switch *ds, int port, + unsigned int mode, + const struct phylink_link_state *state) { struct vsc73xx *vsc =3D ds->priv; - u32 val; - /* Special handling of the CPU-facing port */ if (port =3D=3D CPU_PORT) { /* Other ports are already initialized but not this one */ @@ -778,102 +769,92 @@ static void vsc73xx_adjust_link(struct dsa_switch *d= s, int port, VSC73XX_ADVPORTM_ENA_GTX | VSC73XX_ADVPORTM_DDR_MODE); } +} + +static void vsc73xx_phylink_mac_link_down(struct dsa_switch *ds, int port, + unsigned int mode, + phy_interface_t interface) +{ + struct vsc73xx *vsc =3D ds->priv; =20 - /* This is the MAC confiuration that always need to happen - * after a PHY or the CPU port comes up or down. + /* This routine is described in the datasheet (below ARBDISC register + * description) */ - if (!phydev->link) { - int ret, err; - - dev_dbg(vsc->dev, "port %d: went down\n", - port); - - /* Disable RX on this port */ - vsc73xx_update_bits(vsc, VSC73XX_BLOCK_MAC, port, - VSC73XX_MAC_CFG, - VSC73XX_MAC_CFG_RX_EN, 0); - - /* Discard packets */ - vsc73xx_update_bits(vsc, VSC73XX_BLOCK_ARBITER, 0, - VSC73XX_ARBDISC, BIT(port), BIT(port)); - - /* Wait until queue is empty */ - ret =3D read_poll_timeout(vsc73xx_read, err, - err < 0 || (val & BIT(port)), - VSC73XX_POLL_SLEEP_US, - VSC73XX_POLL_TIMEOUT_US, false, - vsc, VSC73XX_BLOCK_ARBITER, 0, - VSC73XX_ARBEMPTY, &val); - if (ret) - dev_err(vsc->dev, - "timeout waiting for block arbiter\n"); - else if (err < 0) - dev_err(vsc->dev, "error reading arbiter\n"); - - /* Put this port into reset */ - vsc73xx_write(vsc, VSC73XX_BLOCK_MAC, port, VSC73XX_MAC_CFG, - VSC73XX_MAC_CFG_RESET); - - /* Accept packets again */ - vsc73xx_update_bits(vsc, VSC73XX_BLOCK_ARBITER, 0, - VSC73XX_ARBDISC, BIT(port), 0); - - /* Allow backward dropping of frames from this port */ - vsc73xx_update_bits(vsc, VSC73XX_BLOCK_ARBITER, 0, - VSC73XX_SBACKWDROP, BIT(port), BIT(port)); - - /* Receive mask (disable forwarding) */ - vsc73xx_update_bits(vsc, VSC73XX_BLOCK_ANALYZER, 0, - VSC73XX_RECVMASK, BIT(port), 0); + vsc73xx_reset_port(vsc, port, 0); =20 - return; - } + /* Allow backward dropping of frames from this port */ + vsc73xx_update_bits(vsc, VSC73XX_BLOCK_ARBITER, 0, + VSC73XX_SBACKWDROP, BIT(port), BIT(port)); =20 - /* Figure out what speed was negotiated */ - if (phydev->speed =3D=3D SPEED_1000) { - dev_dbg(vsc->dev, "port %d: 1000 Mbit mode full duplex\n", - port); - - /* Set up default for internal port or external RGMII */ - if (phydev->interface =3D=3D PHY_INTERFACE_MODE_RGMII) - val =3D VSC73XX_MAC_CFG_1000M_F_RGMII; - else - val =3D VSC73XX_MAC_CFG_1000M_F_PHY; - vsc73xx_adjust_enable_port(vsc, port, phydev, val); - } else if (phydev->speed =3D=3D SPEED_100) { - if (phydev->duplex =3D=3D DUPLEX_FULL) { - val =3D VSC73XX_MAC_CFG_100_10M_F_PHY; - dev_dbg(vsc->dev, - "port %d: 100 Mbit full duplex mode\n", - port); - } else { - val =3D VSC73XX_MAC_CFG_100_10M_H_PHY; - dev_dbg(vsc->dev, - "port %d: 100 Mbit half duplex mode\n", - port); - } - vsc73xx_adjust_enable_port(vsc, port, phydev, val); - } else if (phydev->speed =3D=3D SPEED_10) { - if (phydev->duplex =3D=3D DUPLEX_FULL) { - val =3D VSC73XX_MAC_CFG_100_10M_F_PHY; - dev_dbg(vsc->dev, - "port %d: 10 Mbit full duplex mode\n", - port); - } else { - val =3D VSC73XX_MAC_CFG_100_10M_H_PHY; - dev_dbg(vsc->dev, - "port %d: 10 Mbit half duplex mode\n", - port); - } - vsc73xx_adjust_enable_port(vsc, port, phydev, val); - } else { - dev_err(vsc->dev, - "could not adjust link: unknown speed\n"); - } + /* Receive mask (disable forwarding) */ + vsc73xx_update_bits(vsc, VSC73XX_BLOCK_ANALYZER, 0, + VSC73XX_RECVMASK, BIT(port), 0); +} + +static void vsc73xx_phylink_mac_link_up(struct dsa_switch *ds, int port, + unsigned int mode, + phy_interface_t interface, + struct phy_device *phydev, + int speed, int duplex, + bool tx_pause, bool rx_pause) +{ + struct vsc73xx *vsc =3D ds->priv; + u32 val; + u8 seed; + + if (speed =3D=3D SPEED_1000) + val =3D VSC73XX_MAC_CFG_GIGA_MODE | VSC73XX_MAC_CFG_TX_IPG_1000M; + else + val =3D VSC73XX_MAC_CFG_TX_IPG_100_10M; + + if (interface =3D=3D PHY_INTERFACE_MODE_RGMII) + val |=3D VSC73XX_MAC_CFG_CLK_SEL_1000M; + else + val |=3D VSC73XX_MAC_CFG_CLK_SEL_EXT; + + if (duplex =3D=3D DUPLEX_FULL) + val |=3D VSC73XX_MAC_CFG_FDX; + + /* This routine is described in the datasheet (below ARBDISC register + * description) + */ + vsc73xx_reset_port(vsc, port, val); + + /* Seed the port randomness with randomness */ + get_random_bytes(&seed, 1); + val |=3D seed << VSC73XX_MAC_CFG_SEED_OFFSET; + val |=3D VSC73XX_MAC_CFG_SEED_LOAD; + val |=3D VSC73XX_MAC_CFG_WEXC_DIS; + vsc73xx_write(vsc, VSC73XX_BLOCK_MAC, port, VSC73XX_MAC_CFG, val); + + /* Flow control for the PHY facing ports: + * Use a zero delay pause frame when pause condition is left + * Obey pause control frames + * When generating pause frames, use 0xff as pause value + */ + vsc73xx_write(vsc, VSC73XX_BLOCK_MAC, port, VSC73XX_FCCONF, + VSC73XX_FCCONF_ZERO_PAUSE_EN | + VSC73XX_FCCONF_FLOW_CTRL_OBEY | + 0xff); + + /* Accept packets again */ + vsc73xx_update_bits(vsc, VSC73XX_BLOCK_ARBITER, 0, + VSC73XX_ARBDISC, BIT(port), 0); =20 /* Enable port (forwarding) in the receieve mask */ vsc73xx_update_bits(vsc, VSC73XX_BLOCK_ANALYZER, 0, VSC73XX_RECVMASK, BIT(port), BIT(port)); + + /* Disallow backward dropping of frames from this port */ + vsc73xx_update_bits(vsc, VSC73XX_BLOCK_ARBITER, 0, + VSC73XX_SBACKWDROP, BIT(port), 0); + + /* Enable TX, RX, deassert reset, stop loading seed */ + vsc73xx_update_bits(vsc, VSC73XX_BLOCK_MAC, port, + VSC73XX_MAC_CFG, + VSC73XX_MAC_CFG_RESET | VSC73XX_MAC_CFG_SEED_LOAD | + VSC73XX_MAC_CFG_TX_EN | VSC73XX_MAC_CFG_RX_EN, + VSC73XX_MAC_CFG_TX_EN | VSC73XX_MAC_CFG_RX_EN); } =20 static int vsc73xx_port_enable(struct dsa_switch *ds, int port, @@ -1060,7 +1041,9 @@ static const struct dsa_switch_ops vsc73xx_ds_ops =3D= { .setup =3D vsc73xx_setup, .phy_read =3D vsc73xx_phy_read, .phy_write =3D vsc73xx_phy_write, - .adjust_link =3D vsc73xx_adjust_link, + .phylink_mac_config =3D vsc73xx_phylink_mac_config, + .phylink_mac_link_down =3D vsc73xx_phylink_mac_link_down, + .phylink_mac_link_up =3D vsc73xx_phylink_mac_link_up, .get_strings =3D vsc73xx_get_strings, .get_ethtool_stats =3D vsc73xx_get_ethtool_stats, .get_sset_count =3D vsc73xx_get_sset_count, --=20 2.34.1 From nobody Sat Feb 7 19:04:11 2026 Received: from mail-lf1-f42.google.com (mail-lf1-f42.google.com [209.85.167.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E2EFE149396; Fri, 23 Feb 2024 21:01:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708722119; cv=none; b=K49Z3bt9RhlsoHXTMrka4dDGufLseT3wLxwUL02m/ELYsXBYdKHwe1nlV9SBgDF5P9fkKf2iUWCmbi8EWJ5YGzuD5JL5rYEHsZjj0LdgM11xF6MY1OcmheanIE+++sAoSasXUUkOaUPEAjg4B+H3XVX/M1Ac2CUQP/z+Xw3YGug= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708722119; c=relaxed/simple; bh=YzSS2jEc2yrsg0NpWculskSZdP/jfRB/wDseRYqsnQY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=LzASsB/+gTtupduUxA99jpfZ8tL7r20lJwmLbNgu9okV9pU24w2kA2fXnLuF7yyvr/zbRfK8YRM3igKXWY6pm4Op/Agvigufzl39HaGKrKIC2dDkje0O92CBwZrRcKUk6TfDl62nu6NVfpzliDOgK/ztEhF3hzcg8ZKmkUXc+TM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=KfKZKgPN; arc=none smtp.client-ip=209.85.167.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="KfKZKgPN" Received: by mail-lf1-f42.google.com with SMTP id 2adb3069b0e04-512c2e8c6cfso1563064e87.1; Fri, 23 Feb 2024 13:01:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708722116; x=1709326916; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=kegIZxvQ3V5ErtuAqBTi6g+zqDh2Ar8Wl8I510MU1cI=; b=KfKZKgPNVQpc5bk9gznxBwZ8RuF9ki4tAzdxZW5js68e+FQ9dqr87CyrEjovVW3XbV mkjQcVZaXQhDpfXgRQ+a0vsXY2zAum1Ozgl5pRhrMu7cHYkmU+i/bKnVbnvbJatY8rfp pEq2i9npa4p37gz43fgm5Fbt/P+dQ0KlR4TaAv0r7tNuLMShv7ofRRz7ktzmFPhSXGXV 0HRTcB5x5boFkWN2nS9FYfxumU+f2ORGJjmEbHtibIIvZRByeh7RXwtfS4H33/EX1Yj4 VNcXYoNgDfMurN+w0jmePHS2omrM+m3UTPwGniPwlbsnRRh36wekkyxSR+KJekJW4HeR DAPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708722116; x=1709326916; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=kegIZxvQ3V5ErtuAqBTi6g+zqDh2Ar8Wl8I510MU1cI=; b=nHXXWZc7z2TuHaeRQ5hI/eyguZIALPDPVujGIha5sWDkJr9hEncAnTGX0yXNT+EOb9 NSP4TuiS57kIYJPwYDAOB+OJW35XFQtTHQM5GPlny9GeEm1r0X11XVdFBTu3G82V1JEj VzVjcVsZjZ6RGfV7nWiqDCD2k3ErKuC9PhWWxaz1ek3IFED8Iy8LxT+JJ9rp5awcoN1q A7JgXmqPDpJVnLGNFfUPJ2kc0kjGbcYoQj7HPMJXn0puJnR5j2f3h+0LocdM65sXz/jv 44BTV5YRqZYjNZY+nkvDdNKwVrHTSajB7w0mqxtL8QuGO/dqH488N6MZ8onbxogMaR9G 8vag== X-Forwarded-Encrypted: i=1; AJvYcCXub1jtOL5w9oeJ0sHO8JGWQVRernOuDTg+VEIVlXBFe3qZyYg2EKBt2uRcgHwgAjrEVSJKdzQ5iY7l+fvqoawYDZJZ/yKQgjhMJQ74 X-Gm-Message-State: AOJu0Yxj2qSSxvEqMsm4WbckrHaUprIUWxfS4sbHb+72Wzy2NyAMv/nH l42iOCkVp5exa3B6H6PK6cTgA13W+yjF3gAc5Z67JUJsvuh2ylNw+yhio9WKpbw= X-Google-Smtp-Source: AGHT+IGgyEg0sSyltk8/UVl/EpN6TNnB0v97hxaR/op/E1C/vNMfbMqSHl94BzUKMKWTJmd/taf2NQ== X-Received: by 2002:a05:6512:242:b0:512:b935:c542 with SMTP id b2-20020a056512024200b00512b935c542mr634057lfo.59.1708722115443; Fri, 23 Feb 2024 13:01:55 -0800 (PST) Received: from WBEC325.dom.lan ([185.188.71.122]) by smtp.gmail.com with ESMTPSA id st11-20020a170907c08b00b00a3e559aaff9sm6185424ejc.29.2024.02.23.13.01.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Feb 2024 13:01:55 -0800 (PST) From: Pawel Dembicki To: netdev@vger.kernel.org Cc: linus.walleij@linaro.org, Pawel Dembicki , Russell King , Florian Fainelli , Vladimir Oltean , Andrew Lunn , Florian Fainelli , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Claudiu Manoil , Alexandre Belloni , UNGLinuxDriver@microchip.com, linux-kernel@vger.kernel.org Subject: [PATCH net-next v5 03/16] net: dsa: vsc73xx: use macros for rgmii recognition Date: Fri, 23 Feb 2024 22:00:33 +0100 Message-Id: <20240223210049.3197486-4-paweldembicki@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240223210049.3197486-1-paweldembicki@gmail.com> References: <20240223210049.3197486-1-paweldembicki@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" It's preparation for future use. At this moment, the RGMII port is used only for a connection to the MAC interface, but in the future, someone could connect a PHY to it. Using the "phy_interface_mode_is_rgmii" macro allows for the proper recognition of all RGMII modes. Suggested-by: Russell King Signed-off-by: Pawel Dembicki Reviewed-by: Linus Walleij Reviewed-by: Florian Fainelli Reviewed-by: Vladimir Oltean --- v5: - added 'Reviewed-by' only v4: - introduced patch drivers/net/dsa/vitesse-vsc73xx-core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/dsa/vitesse-vsc73xx-core.c b/drivers/net/dsa/vites= se-vsc73xx-core.c index cb2e7e256279..8ed8fc997d6d 100644 --- a/drivers/net/dsa/vitesse-vsc73xx-core.c +++ b/drivers/net/dsa/vitesse-vsc73xx-core.c @@ -807,7 +807,7 @@ static void vsc73xx_phylink_mac_link_up(struct dsa_swit= ch *ds, int port, else val =3D VSC73XX_MAC_CFG_TX_IPG_100_10M; =20 - if (interface =3D=3D PHY_INTERFACE_MODE_RGMII) + if (phy_interface_mode_is_rgmii(interface)) val |=3D VSC73XX_MAC_CFG_CLK_SEL_1000M; else val |=3D VSC73XX_MAC_CFG_CLK_SEL_EXT; --=20 2.34.1 From nobody Sat Feb 7 19:04:11 2026 Received: from mail-lf1-f43.google.com (mail-lf1-f43.google.com [209.85.167.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E15E8149386; Fri, 23 Feb 2024 21:02:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708722125; cv=none; b=ro1cRrMgKqXGwJ8BFmuv5+pmC06r/NtBKpT9o/qpzTqzlmagrVOT1JI10A+1rlizxTcn7zrsRI/b1mluxlrQp61zsnBuOPZYwAlvJbl1uAJ69KeNzisqRVLrr+urxF4EfwA/InSSLKPm7WEekvY768g8tU/AsFJcVqh/LTOfFUU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708722125; c=relaxed/simple; bh=jMIi9XpyjMKrSso2kjpj8ETvk29CWpBo/T3bKFftHjE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=sT38ZTgwnnzSFgYt2U3cc+L/lct19dcfuSyrxXINcJWPBDVzz3ivQvsaeNp0PcK95+F1LxTwWaH870Y8erV2pnjaUCfaM/Gikt5xRwzsAhpig00DjM6qxVxVqbZDgeyXOtXK8ffsqAvO38kc+x9IrPhR077Jcy2FCPA11QXsAgs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=FAG8jUKd; arc=none smtp.client-ip=209.85.167.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="FAG8jUKd" Received: by mail-lf1-f43.google.com with SMTP id 2adb3069b0e04-512e01b3da3so1658866e87.3; Fri, 23 Feb 2024 13:02:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708722122; x=1709326922; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=DPX4Iuw96szPAD6qjCqbSaeFiBzpVrcX4bId7fchfRc=; b=FAG8jUKd0oEmwhnH1Zr+LBWbrrqciEKLybwCgIoEy6VUIREIOEapvSAdNmHNcPYqg5 p0bY6PPa/NrPOSVLv1ILFh/TSIXxAyAqe18NoifOG9aa9xR9vK/GjS8/jdLruGrrkZW7 yZBY/LEXupyzUbZGTkgb+6gzoqUVIhjJsjVU2aKpf2rRPiRft7kwKGuhACsmgKc1wZ5w vWbkGJrsfA87f2itnUCrq8vZZVp9p+z4Fdom9tubh8HoXvsfDHXmGmnJ/pm4eF6wFcP6 WNyS0LdjMqjPUBXi8HTz/7hWhcz7x1rXnEufS03smDt96ag6dnH0lvwS22JpEabQEwSt gYnQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708722122; x=1709326922; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=DPX4Iuw96szPAD6qjCqbSaeFiBzpVrcX4bId7fchfRc=; b=AtT0EN5+Gw+2ei0Jn9KUKpRAnipQypGW/rbT6//RgTVx7mgGKIdOBNxEmQhS7d9uGZ +FpYkYDoSxr/wrqRGOKxZRFmlAh6395g2Vi7LnDY0k5OBJ3Hc4BjGq287HZgIW1pulkK MXcZHX4LxU8qZHcOEyJKdDysmYqXChgN1M7HevNA/tgT2b1IxekXCl/MKbTh/bqWdWjX 6AKHokHLt1o/VyYektzTNkkigmC1QSmaTh8DRw+PLQviGJUIZnOSwhPH7lJI2vdmKaFB cIBQuFz6dB6rUjMZJ9V0JF4FE8e/w6i4xj1DMwFp5ey2w1ESfkrSogbYTm/YBImV/Gid nApA== X-Forwarded-Encrypted: i=1; AJvYcCW9YipJc95KPKzBisogpf01dZUbIpNch6E0dBLmd+SiflkaVj/2TKe4i8G3IHIWaBuxSYeCfoK1ae1tSp9PZR/Wdj6cAQoNii2KjTVx X-Gm-Message-State: AOJu0YxbD/QMd2O2+q0Bl4JGneys7+kO0RdQn0gJPvhj66oY7SZcSeih XivjP7TBPKs23Sk11iiMXixhCYNfWxXPGsXN2lh0rZVjd0Z1CoKE9ehURavLhLs= X-Google-Smtp-Source: AGHT+IEf3ZAws7M3wsQDv5v3oNMNgbSGTUF8TvKm7R9dAeuRwtY34qePH44k/hRqjBLRuJuZUTZ9Jw== X-Received: by 2002:ac2:483a:0:b0:512:e711:d46a with SMTP id 26-20020ac2483a000000b00512e711d46amr542056lft.24.1708722121826; Fri, 23 Feb 2024 13:02:01 -0800 (PST) Received: from WBEC325.dom.lan ([185.188.71.122]) by smtp.gmail.com with ESMTPSA id st11-20020a170907c08b00b00a3e559aaff9sm6185424ejc.29.2024.02.23.13.02.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Feb 2024 13:02:01 -0800 (PST) From: Pawel Dembicki To: netdev@vger.kernel.org Cc: linus.walleij@linaro.org, Pawel Dembicki , Vladimir Oltean , Andrew Lunn , Florian Fainelli , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Claudiu Manoil , Alexandre Belloni , UNGLinuxDriver@microchip.com, Russell King , linux-kernel@vger.kernel.org Subject: [PATCH net-next v5 04/16] net: dsa: vsc73xx: Add define for max num of ports Date: Fri, 23 Feb 2024 22:00:34 +0100 Message-Id: <20240223210049.3197486-5-paweldembicki@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240223210049.3197486-1-paweldembicki@gmail.com> References: <20240223210049.3197486-1-paweldembicki@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This patch introduces a new define: VSC73XX_MAX_NUM_PORTS, which can be used in the future instead of a hardcoded value. Currently, the only hardcoded value is vsc->ds->num_ports. It is being replaced with the new define. Suggested-by: Vladimir Oltean Signed-off-by: Pawel Dembicki Reviewed-by: Vladimir Oltean Reviewed-by: Linus Walleij --- v5: - added 'Reviewed-by' only v4: - Resend patch v3: - Introduce patch drivers/net/dsa/vitesse-vsc73xx-core.c | 13 +------------ drivers/net/dsa/vitesse-vsc73xx.h | 11 +++++++++++ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/drivers/net/dsa/vitesse-vsc73xx-core.c b/drivers/net/dsa/vites= se-vsc73xx-core.c index 8ed8fc997d6d..425999d7bf41 100644 --- a/drivers/net/dsa/vitesse-vsc73xx-core.c +++ b/drivers/net/dsa/vitesse-vsc73xx-core.c @@ -1180,23 +1180,12 @@ int vsc73xx_probe(struct vsc73xx *vsc) vsc->addr[0], vsc->addr[1], vsc->addr[2], vsc->addr[3], vsc->addr[4], vsc->addr[5]); =20 - /* The VSC7395 switch chips have 5+1 ports which means 5 - * ordinary ports and a sixth CPU port facing the processor - * with an RGMII interface. These ports are numbered 0..4 - * and 6, so they leave a "hole" in the port map for port 5, - * which is invalid. - * - * The VSC7398 has 8 ports, port 7 is again the CPU port. - * - * We allocate 8 ports and avoid access to the nonexistant - * ports. - */ vsc->ds =3D devm_kzalloc(dev, sizeof(*vsc->ds), GFP_KERNEL); if (!vsc->ds) return -ENOMEM; =20 vsc->ds->dev =3D dev; - vsc->ds->num_ports =3D 8; + vsc->ds->num_ports =3D VSC73XX_MAX_NUM_PORTS; vsc->ds->priv =3D vsc; =20 vsc->ds->ops =3D &vsc73xx_ds_ops; diff --git a/drivers/net/dsa/vitesse-vsc73xx.h b/drivers/net/dsa/vitesse-vs= c73xx.h index 30b1f0a36566..fee1378508b5 100644 --- a/drivers/net/dsa/vitesse-vsc73xx.h +++ b/drivers/net/dsa/vitesse-vsc73xx.h @@ -3,6 +3,17 @@ #include #include =20 +/* The VSC7395 switch chips have 5+1 ports which means 5 ordinary ports and + * a sixth CPU port facing the processor with an RGMII interface. These po= rts + * are numbered 0..4 and 6, so they leave a "hole" in the port map for por= t 5, + * which is invalid. + * + * The VSC7398 has 8 ports, port 7 is again the CPU port. + * + * We allocate 8 ports and avoid access to the nonexistent ports. + */ +#define VSC73XX_MAX_NUM_PORTS 8 + /** * struct vsc73xx - VSC73xx state container */ --=20 2.34.1 From nobody Sat Feb 7 19:04:11 2026 Received: from mail-ej1-f43.google.com (mail-ej1-f43.google.com [209.85.218.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 45EF4146E71; Fri, 23 Feb 2024 21:02:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708722131; cv=none; b=qg2ddBM+X2KE1GhlceHpLWk5cUfuaAURoIQzloVJvQxet52Rabwb8Q95/iC/Oz3IpqWPIuNu1w5GYXKBiSTFHyfF37ziINsvLW0psMhue3If9ZjnbRoEAZitCdU5SE2G7crUfpWd/JACxpptjpS8iMQMPELLoTL9r8khr1Vf4Nw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708722131; c=relaxed/simple; bh=jDveqTSmY5Obwiw3CEMCB1M279nvlZqw4xJmx+i2XN8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Z9aC5PG2GDY8jHx40OG7Wdxdq8/FP7qR5alTz5Pja4UvUDoZp3+tD0gU811pbH5Mq0v8OGlPS+Q9YmLUAodSvzoMZHJuZmcPjMhYNVic0ezEtqwZ7cyWvibvhTEBF0XEW1bLifv2w+42CkHO81K9mL4MyUKseDzqLvWpnTc/z6o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=kZekfT0l; arc=none smtp.client-ip=209.85.218.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="kZekfT0l" Received: by mail-ej1-f43.google.com with SMTP id a640c23a62f3a-a3122b70439so118108466b.3; Fri, 23 Feb 2024 13:02:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708722127; x=1709326927; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=08NWjQnKcjY+6Ilk3BwFDKrpVp02goqIQe5ciPfYtik=; b=kZekfT0lNa7Csz+tGqbI+ABXCIpW9ZemNHrtbC/QYfisFAvftUC9gQXpUbGPxnSY1G JT3qZ1NRL7x+qYAN4Wu08hAzVxIs3lQnQdo3T2bqY4SKjmskjAtrzA8ri4OmZ3e9QgJS 1mRlSFxX3CX9K3qEubIQXK/Ihh8pSjp/7EirWQS+5Dc4xMD2kBO9FWnOfJGmi/4XZzoA aWd3Gk5lHroN/73+OnlxMmvL9yWG34ZKZC2FT/R3EnIPB+d2UOJkXHvlh8RgsgNYXE9B v8ehK1VgotTk+BeH/214goQyCj/yiMIuFQP9MzzVhXEJUXCYkvKzx0xYqyTwor8XfUGG Qgpg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708722127; x=1709326927; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=08NWjQnKcjY+6Ilk3BwFDKrpVp02goqIQe5ciPfYtik=; b=OWWoCW9QlY0h9sHIw9ftJpfum4sQ41nm118NfPEEcqtuJvF2+CQI/T8DUn7lPXq05s GBFHA3QGoEgmZFSFFy1SgoDLvX30j4OIIstGgQa7P2KYilLViFqirdMiXBFIG4B6v8iz x+04MA0VfvZFe47eeWPrdOwZFc4JNUELbIm/Szd+xmyQgHngbtdFNncVb94HR26LDSs8 lHBoblei6Qolz0FpjbNBqKvURTSSq3FgMjJ8szR7wC+Xx7Lfanf0KSDXbB2+cupv8OYL Tws5SEJxP0Caxf/5CwelVMe4rfxlK3yiMVfRRMIR+n6nZRWlWXeBN2Q9IgPgizUz0YR9 yxmA== X-Forwarded-Encrypted: i=1; AJvYcCVBBb87hPv78OfIMyTKwTqKA858nvuhkovvT3Q4XbdmocnWi0BCWV/Tu/oBRcd/Ns+3HdgY8LZtSm+czppXo01gR8eM1643ti6Zc55Y X-Gm-Message-State: AOJu0YwE+Z1hjbS/XCAk2N/nlfevnEKlaDRQjPWQRc8APKjX4zCsogAj syC8fTy+8Kwkic5TDJmnJyL9r4UJ7q82Wy7woXUjTfY2aOawXysbnZ6YT4lFY8s= X-Google-Smtp-Source: AGHT+IGxIjNBhbVfPoTgLrTPefWGVY5hhMv8ribdIlbIMAZVU43JII72udqKYtJcRSOqc+p9tlHQTw== X-Received: by 2002:a17:906:688a:b0:a3e:4093:89df with SMTP id n10-20020a170906688a00b00a3e409389dfmr675430ejr.74.1708722127288; Fri, 23 Feb 2024 13:02:07 -0800 (PST) Received: from WBEC325.dom.lan ([185.188.71.122]) by smtp.gmail.com with ESMTPSA id st11-20020a170907c08b00b00a3e559aaff9sm6185424ejc.29.2024.02.23.13.02.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Feb 2024 13:02:06 -0800 (PST) From: Pawel Dembicki To: netdev@vger.kernel.org Cc: linus.walleij@linaro.org, Pawel Dembicki , Florian Fainelli , Andrew Lunn , Florian Fainelli , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Claudiu Manoil , Alexandre Belloni , UNGLinuxDriver@microchip.com, Russell King , linux-kernel@vger.kernel.org Subject: [PATCH net-next v5 05/16] net: dsa: vsc73xx: add structure descriptions Date: Fri, 23 Feb 2024 22:00:35 +0100 Message-Id: <20240223210049.3197486-6-paweldembicki@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240223210049.3197486-1-paweldembicki@gmail.com> References: <20240223210049.3197486-1-paweldembicki@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This commit adds updates to the documentation describing the structures used in vsc73xx. This will help prevent kdoc-related issues in the future. Reviewed-by: Linus Walleij Reviewed-by: Florian Fainelli Signed-off-by: Pawel Dembicki --- v5: - improved description and stick to 80 characters per line v4: - introduced patch drivers/net/dsa/vitesse-vsc73xx.h | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/drivers/net/dsa/vitesse-vsc73xx.h b/drivers/net/dsa/vitesse-vs= c73xx.h index fee1378508b5..e7b08599a625 100644 --- a/drivers/net/dsa/vitesse-vsc73xx.h +++ b/drivers/net/dsa/vitesse-vsc73xx.h @@ -15,7 +15,16 @@ #define VSC73XX_MAX_NUM_PORTS 8 =20 /** - * struct vsc73xx - VSC73xx state container + * struct vsc73xx - VSC73xx state container: main data structure + * @dev: The device pointer + * @reset: The descriptor for the GPIO line tied to the reset pin + * @ds: Pointer to the DSA core structure + * @gc: Main structure of the GPIO controller + * @chipid: Storage for the Chip ID value read from the CHIPID register of= the + * sswitch + * @addr: MAC address used in flow control frames + * @ops: Structure with hardware-dependent operations + * @priv: Pointer to the configuration interface structure */ struct vsc73xx { struct device *dev; @@ -28,6 +37,11 @@ struct vsc73xx { void *priv; }; =20 +/** + * struct vsc73xx_ops - VSC73xx methods container + * @read: Method for register reading over the hardware-dependent interface + * @write: Method for register writing over the hardware-dependent interfa= ce + */ struct vsc73xx_ops { int (*read)(struct vsc73xx *vsc, u8 block, u8 subblock, u8 reg, u32 *val); --=20 2.34.1 From nobody Sat Feb 7 19:04:11 2026 Received: from mail-lf1-f43.google.com (mail-lf1-f43.google.com [209.85.167.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 819F8146E71; Fri, 23 Feb 2024 21:02:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708722138; cv=none; b=kk94k0a/AgQgCL3NytM9xkBtoAFymr82BT6f4qXG12/9I89+5B7dTc7V32690OA8YEq7VGl2FFEnsbQ0zCxxY7hNvAWGRD4vclpOF2SEjDBVy2URS9DmQpKFIYntP3owaooL+TiIHLXkzRIUExr6v6ub/jxGVB7gQkiuhJGUZRM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708722138; c=relaxed/simple; bh=IUnbtBh/jU7L8ituS+NKI77KKtYzeb3KBPhVBtjGX9M=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=V1pr4di+LxFxMAYXUF3J2Qf3sYihw/DZROHh1nidcUwurLhyUZ7nENTzZKIVAhfRkvSF/5/kEvgenuOp6Mp8ofEN2ql5t7gpBX2Alh2jAkTUa8zPlp2zDfHhv5y14OQ/fH9NJ8zFF4lDuGIIBFQP1OtVmviJmjTlfgxd0p3/9+0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=CjJfLlRb; arc=none smtp.client-ip=209.85.167.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="CjJfLlRb" Received: by mail-lf1-f43.google.com with SMTP id 2adb3069b0e04-512c2e8c6cfso1563422e87.1; Fri, 23 Feb 2024 13:02:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708722134; x=1709326934; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=NmSDk0c3liZ0FTN/I0gFbiEYHUdcrbT6AD0dmbXbwOI=; b=CjJfLlRb4i63vq+cXiiB8rKMfEm5wsbSGDJeWcVAbNBJMW8j4WblNnHVid4yN9W9le hwD20dthzP4pWDq6paB05Yt70dmizotE2J5NACsUVZgCb0rF2Q+whOxsm2ZIs0PkfxyY L3RYun7HFWjYGCdB4hcjC6ycRRLS7Rk3sO+4HFaT5twKEqGSleRSFFWF6PULHs2vFADE zDi8fYToAGKJVx072BjJC9sWZzDt3TUkO61r+kioEKYegp8FBktjH1OWxzOlV5KY2/V8 Gr1z1lmYYWieSs4GwabVT64VTDWHxRn984/6Ic+MXs4QCGYhcJ7jhHEiYENFZmNWStBh Nybw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708722134; x=1709326934; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=NmSDk0c3liZ0FTN/I0gFbiEYHUdcrbT6AD0dmbXbwOI=; b=opCKGBvaip6N8VGKB/clpnR0jfBMuYmKHPkoehfU9hIn3sOPOFDvdBZp+GHTL0fCMV nFq2UyUQS+XLYRtpwG4QQtzoaorVG+fXfWSivxpjZ7iTAgSNuAltQKIEIpmIt4XP12pk bvCnIPQpS1ONuFOFWTM97I6Py1ABoEKVWNGKh1uLxCIt//cCs9/hUQjB/ZEbs1ejGMjU IArgoXlzGRTcyfIn5dVRV4N3jHHJcn14pb6ENTQ/4NylTOMzkNHM+DzJgp2uPsCk1a5U bL4XZuJEzrYXiwdsmnHzJBG5LUFDYScVrjhFzdJLo3R/qrWfCMlM9IL9cN6NKC46NoPw 3qTg== X-Forwarded-Encrypted: i=1; AJvYcCWRwO45njiqgTD6oIvqqB1t2kCiXF4V7uWItqZLVQynaKYKPuH3O0HYVsHUYdsAGDiNGorwbQYzRnaH2A2071Z19BQgxeikRMcnGnku X-Gm-Message-State: AOJu0Yw3/FF0fmfWZ1cQqGKLSAdZk5VGXQ8ge1If5GE8DFDHYjMwaclP ft8dnWSuC/M7N70oNjYIctIBu9XX0VjIP1t/ywsCpfhMx4bxOk3izaWH+vrPTuc= X-Google-Smtp-Source: AGHT+IFbDZzCgqCG02LpbKUr8+Lywgq+0F3Ytefd8LyP+AzgpNCX1OPXjxUU97zY2c/MQyK5Jvrb3g== X-Received: by 2002:ac2:5970:0:b0:512:b362:e790 with SMTP id h16-20020ac25970000000b00512b362e790mr546591lfp.34.1708722134333; Fri, 23 Feb 2024 13:02:14 -0800 (PST) Received: from WBEC325.dom.lan ([185.188.71.122]) by smtp.gmail.com with ESMTPSA id st11-20020a170907c08b00b00a3e559aaff9sm6185424ejc.29.2024.02.23.13.02.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Feb 2024 13:02:13 -0800 (PST) From: Pawel Dembicki To: netdev@vger.kernel.org Cc: linus.walleij@linaro.org, Pawel Dembicki , Andrew Lunn , Florian Fainelli , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Claudiu Manoil , Alexandre Belloni , UNGLinuxDriver@microchip.com, Russell King , linux-kernel@vger.kernel.org Subject: [PATCH net-next v5 06/16] net: dsa: vsc73xx: add port_stp_state_set function Date: Fri, 23 Feb 2024 22:00:36 +0100 Message-Id: <20240223210049.3197486-7-paweldembicki@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240223210049.3197486-1-paweldembicki@gmail.com> References: <20240223210049.3197486-1-paweldembicki@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This isn't a fully functional implementation of 802.1D, but port_stp_state_set is required for a future tag8021q operations. This implementation handles properly all states, but vsc73xx doesn't forward STP packets. Signed-off-by: Pawel Dembicki --- v5: - remove unneeded 'RECVMASK' operations - reorganise vsc73xx_refresh_fwd_map function v4: - fully reworked port_stp_state_set v3: - use 'VSC73XX_MAX_NUM_PORTS' define - add 'state =3D=3D BR_STATE_DISABLED' condition - fix style issues v2: - fix kdoc drivers/net/dsa/vitesse-vsc73xx-core.c | 99 +++++++++++++++++++++++--- 1 file changed, 88 insertions(+), 11 deletions(-) diff --git a/drivers/net/dsa/vitesse-vsc73xx-core.c b/drivers/net/dsa/vites= se-vsc73xx-core.c index 425999d7bf41..c3ef4c22f687 100644 --- a/drivers/net/dsa/vitesse-vsc73xx-core.c +++ b/drivers/net/dsa/vitesse-vsc73xx-core.c @@ -164,6 +164,10 @@ #define VSC73XX_AGENCTRL 0xf0 #define VSC73XX_CAPRST 0xff =20 +#define VSC73XX_SRCMASKS_CPU_COPY BIT(27) +#define VSC73XX_SRCMASKS_MIRROR BIT(26) +#define VSC73XX_SRCMASKS_PORTS_MASK GENMASK(7, 0) + #define VSC73XX_MACACCESS_CPU_COPY BIT(14) #define VSC73XX_MACACCESS_FWD_KILL BIT(13) #define VSC73XX_MACACCESS_IGNORE_VLAN BIT(12) @@ -623,9 +627,6 @@ static int vsc73xx_setup(struct dsa_switch *ds) vsc73xx_write(vsc, VSC73XX_BLOCK_SYSTEM, 0, VSC73XX_GMIIDELAY, VSC73XX_GMIIDELAY_GMII0_GTXDELAY_2_0_NS | VSC73XX_GMIIDELAY_GMII0_RXDELAY_2_0_NS); - /* Enable reception of frames on all ports */ - vsc73xx_write(vsc, VSC73XX_BLOCK_ANALYZER, 0, VSC73XX_RECVMASK, - 0x5f); /* IP multicast flood mask (table 144) */ vsc73xx_write(vsc, VSC73XX_BLOCK_ANALYZER, 0, VSC73XX_IFLODMSK, 0xff); @@ -785,10 +786,6 @@ static void vsc73xx_phylink_mac_link_down(struct dsa_s= witch *ds, int port, /* Allow backward dropping of frames from this port */ vsc73xx_update_bits(vsc, VSC73XX_BLOCK_ARBITER, 0, VSC73XX_SBACKWDROP, BIT(port), BIT(port)); - - /* Receive mask (disable forwarding) */ - vsc73xx_update_bits(vsc, VSC73XX_BLOCK_ANALYZER, 0, - VSC73XX_RECVMASK, BIT(port), 0); } =20 static void vsc73xx_phylink_mac_link_up(struct dsa_switch *ds, int port, @@ -841,10 +838,6 @@ static void vsc73xx_phylink_mac_link_up(struct dsa_swi= tch *ds, int port, vsc73xx_update_bits(vsc, VSC73XX_BLOCK_ARBITER, 0, VSC73XX_ARBDISC, BIT(port), 0); =20 - /* Enable port (forwarding) in the receieve mask */ - vsc73xx_update_bits(vsc, VSC73XX_BLOCK_ANALYZER, 0, - VSC73XX_RECVMASK, BIT(port), BIT(port)); - /* Disallow backward dropping of frames from this port */ vsc73xx_update_bits(vsc, VSC73XX_BLOCK_ARBITER, 0, VSC73XX_SBACKWDROP, BIT(port), 0); @@ -1036,6 +1029,89 @@ static void vsc73xx_phylink_get_caps(struct dsa_swit= ch *dsa, int port, config->mac_capabilities =3D MAC_SYM_PAUSE | MAC_10 | MAC_100 | MAC_1000; } =20 +static void vsc73xx_refresh_fwd_map(struct dsa_switch *ds, int port, u8 st= ate) +{ + struct dsa_port *other_dp, *dp =3D dsa_to_port(ds, port); + struct vsc73xx *vsc =3D ds->priv; + u16 mask; + + if (state !=3D BR_STATE_FORWARDING) { + /* Ports that aren't in the forwarding state must not + * forward packets anywhere. + */ + vsc73xx_update_bits(vsc, VSC73XX_BLOCK_ANALYZER, 0, + VSC73XX_SRCMASKS + port, + VSC73XX_SRCMASKS_PORTS_MASK, 0); + + dsa_switch_for_each_available_port(other_dp, ds) { + if (other_dp =3D=3D dp) + continue; + vsc73xx_update_bits(vsc, VSC73XX_BLOCK_ANALYZER, 0, + VSC73XX_SRCMASKS + other_dp->index, + BIT(port), 0); + } + + return; + } + + /* Forwarding ports must forward to the CPU and to other ports + * in the same bridge + */ + vsc73xx_update_bits(vsc, VSC73XX_BLOCK_ANALYZER, 0, + VSC73XX_SRCMASKS + CPU_PORT, BIT(port), BIT(port)); + + mask =3D BIT(CPU_PORT); + + if (dp->bridge) { + dsa_switch_for_each_user_port(other_dp, ds) { + if (other_dp->bridge =3D=3D dp->bridge && + other_dp->index !=3D port && + other_dp->stp_state =3D=3D BR_STATE_FORWARDING) { + int other_port =3D other_dp->index; + + mask |=3D BIT(other_port); + vsc73xx_update_bits(vsc, VSC73XX_BLOCK_ANALYZER, + 0, + VSC73XX_SRCMASKS + + other_port, + BIT(port), BIT(port)); + } + } + } + + vsc73xx_update_bits(vsc, VSC73XX_BLOCK_ANALYZER, 0, + VSC73XX_SRCMASKS + port, + VSC73XX_SRCMASKS_PORTS_MASK, mask); +} + +/* FIXME: STP frames aren't forwarded at this moment. BPDU frames are + * forwarded only from and to PI/SI interface. For more info see chapter + * 2.7.1 (CPU Forwarding) in datasheet. + * This function is required for tag_8021q operations. + */ +static void vsc73xx_port_stp_state_set(struct dsa_switch *ds, int port, + u8 state) +{ + struct vsc73xx *vsc =3D ds->priv; + u32 val; + + val =3D (state =3D=3D BR_STATE_BLOCKING || state =3D=3D BR_STATE_DISABLED= ) ? + 0 : BIT(port); + vsc73xx_update_bits(vsc, VSC73XX_BLOCK_ANALYZER, 0, + VSC73XX_RECVMASK, BIT(port), val); + + val =3D (state =3D=3D BR_STATE_LEARNING || state =3D=3D BR_STATE_FORWARDI= NG) ? + BIT(port) : 0; + vsc73xx_update_bits(vsc, VSC73XX_BLOCK_ANALYZER, 0, + VSC73XX_LEARNMASK, BIT(port), val); + + /* CPU Port should always forward packets when user ports are forwarding + * so let's configure it from other ports only. + */ + if (port !=3D CPU_PORT) + vsc73xx_refresh_fwd_map(ds, port, state); +} + static const struct dsa_switch_ops vsc73xx_ds_ops =3D { .get_tag_protocol =3D vsc73xx_get_tag_protocol, .setup =3D vsc73xx_setup, @@ -1051,6 +1127,7 @@ static const struct dsa_switch_ops vsc73xx_ds_ops =3D= { .port_disable =3D vsc73xx_port_disable, .port_change_mtu =3D vsc73xx_change_mtu, .port_max_mtu =3D vsc73xx_get_max_mtu, + .port_stp_state_set =3D vsc73xx_port_stp_state_set, .phylink_get_caps =3D vsc73xx_phylink_get_caps, }; =20 --=20 2.34.1 From nobody Sat Feb 7 19:04:11 2026 Received: from mail-ej1-f51.google.com (mail-ej1-f51.google.com [209.85.218.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6E5A2146E71; Fri, 23 Feb 2024 21:02:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708722146; cv=none; b=kXYxmRzQVUT4Hb/A/CtT6Q9qT3weOa/jS93wQdODPSiErYlqLmOTH0H1u4q5moQs6eNOocy9MxfI2g8RiYIbUDnG1eQ9yxjholLPqmKp4SALxv4Aw6R06alO9jrHZDty+202Y9Kz8pfJbTdbOaQXQkfJqW7Neqwyb0Yzq18UUwI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708722146; c=relaxed/simple; bh=1FS1ymrskWa5czitCxLd7qTbgAeF7WMP47xFmyGFtZw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ZBeKRKpxAKU/M3p46F+ZCcZ07oxv96uLn+x+8OM+Pk13zWxCNelowsyEz/joyd+UxABpqc1RIMWbuZqgFSCsNYuUk0owIIU8MiEYqz4QQffvQGRboC8xUsNIQ3uX4TPQu4ygRgq8I9uH8GU91CDwqHZWtlqHItWHx+4CfcSL8go= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=SnEy/YDP; arc=none smtp.client-ip=209.85.218.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="SnEy/YDP" Received: by mail-ej1-f51.google.com with SMTP id a640c23a62f3a-a3f48422fb6so191517466b.3; Fri, 23 Feb 2024 13:02:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708722141; x=1709326941; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=mhgF0KndogaQ4hiNACt7+FiqREIf4PihWNEH6HY1lds=; b=SnEy/YDPlKJmc99tEQ3xP3R347x7phk1lz8H/w0hs8+3fUaFG3BT9fHaTw7wbQCAXN phq6wXwc5QVVB1Iw7K2ayv5XA9mMsE6Z8AjYGOUT8unfxhMHvngnaM3+7PNkNLgF+q2a 35hmhn8p3xFPgEjPebW/+uzVF/+al7QyI7Nel4ss7JUwsnolryBQmG/ePJlDtUZq/c2D Daf7yvZYf/FZdsJudgw+1JSQKSjbI/BS9dE/fpac7fB1OVRgZRw7IaFlmx/jy5+HenCz ANa5nggjwUG/e/mK4KJbeiavBOJXHRbHZQbPWkwcNksHar92es6TWBLBYWlBzEp7zB1a dkcg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708722141; x=1709326941; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=mhgF0KndogaQ4hiNACt7+FiqREIf4PihWNEH6HY1lds=; b=Bs+mT6llj2fOIkUCbxv/+UmUMhz0ct1C9f4VL+Lv7OTD7kHJ4BP93Fhjy60cGJq9jc qlGpagrp5g8H4+1VMsLi6FfzqSNmGFXsfoMmgDLRZj879b9s1a5qe1gUUC1d6V2kXjwV cz9+NdPQG2/V3jXE13WcBgduUuamdhkQkY9dX7Prho7vWCyNWcwToqXD9cKmVJWGqpmO nP/ku7MTvEVFhdwF2vBYwXC0HHl7Wp61BEnFFEyrRrEEZcmZwwUP9n1MMO+6AVywzJBI bDMNHNgqLmMr+Yq8tR41ZyXFqH0mkhRToJ93m7HTiL3+YQw85uAP68TJ4z4/3khrQ0S9 jO9g== X-Forwarded-Encrypted: i=1; AJvYcCV89xcFQ18opsEdg2NRx2B+ckCxKl0wnagZUGxEnBC+vrk5ugxFr2AfoxyM18MXZt/Hqy3lwtSGd8qAEwzBHcoTfg7Czod7OOX4AU+4 X-Gm-Message-State: AOJu0Yx+Mgk+8q9blPVUq17HFZQScbbdNqVNdyqlM0cnr612udc4fJ+8 dnDIAQ9sXwavbOJEU5Bl1sEEyuwK4IxO4/4TpFIKTkRS5hDxfw7GK7YTlKyZ5qM= X-Google-Smtp-Source: AGHT+IF3RhM7TbNf1aQB1m/C4OSlO3hX/Dcvkm6TCPRoAju58Z9KBRmh+VgOixuz97RguTQPJqai0w== X-Received: by 2002:a17:906:bc8c:b0:a3f:50ad:fd71 with SMTP id lv12-20020a170906bc8c00b00a3f50adfd71mr615710ejb.19.1708722141366; Fri, 23 Feb 2024 13:02:21 -0800 (PST) Received: from WBEC325.dom.lan ([185.188.71.122]) by smtp.gmail.com with ESMTPSA id st11-20020a170907c08b00b00a3e559aaff9sm6185424ejc.29.2024.02.23.13.02.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Feb 2024 13:02:21 -0800 (PST) From: Pawel Dembicki To: netdev@vger.kernel.org Cc: linus.walleij@linaro.org, Pawel Dembicki , Andrew Lunn , Florian Fainelli , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Claudiu Manoil , Alexandre Belloni , UNGLinuxDriver@microchip.com, Russell King , linux-kernel@vger.kernel.org Subject: [PATCH net-next v5 07/16] net: dsa: vsc73xx: Add vlan filtering Date: Fri, 23 Feb 2024 22:00:37 +0100 Message-Id: <20240223210049.3197486-8-paweldembicki@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240223210049.3197486-1-paweldembicki@gmail.com> References: <20240223210049.3197486-1-paweldembicki@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This patch implements VLAN filtering for the vsc73xx driver. After starting VLAN filtering, the switch is reconfigured from QinQ to a simple VLAN aware mode. This is required because VSC73XX chips do not support inner VLAN tag filtering. Signed-off-by: Pawel Dembicki --- v5: - fix possible leak in 'vsc73xx_port_vlan_add' - use proper variable in statement from 'vsc73xx_port_vlan_filtering' - change 'vlan_no' name to 'vid' - codding style improvements - comment improvements - handle return of 'vsc73xx_update_bits' - reduce I/O operations - use 'size_t' for counting variables v4: - reworked most of conditional register configs - simplified port_vlan function - move vlan table clearing from port_setup to setup - pvid configuration simplified (now kernel take care about no of pvids per port) - port vlans are stored in list now - introduce implementation of all untagged vlans state - many minor changes v3: - reworked all vlan commits - added storage variables for pvid and untagged vlans - move length extender settings to port setup - remove vlan table cleaning in wrong places v2: - no changes done drivers/net/dsa/vitesse-vsc73xx-core.c | 570 ++++++++++++++++++++++++- drivers/net/dsa/vitesse-vsc73xx.h | 29 ++ 2 files changed, 597 insertions(+), 2 deletions(-) diff --git a/drivers/net/dsa/vitesse-vsc73xx-core.c b/drivers/net/dsa/vites= se-vsc73xx-core.c index c3ef4c22f687..87ad8b78f141 100644 --- a/drivers/net/dsa/vitesse-vsc73xx-core.c +++ b/drivers/net/dsa/vitesse-vsc73xx-core.c @@ -22,9 +22,11 @@ #include #include #include +#include #include #include #include +#include #include #include =20 @@ -62,6 +64,8 @@ #define VSC73XX_CAT_DROP 0x6e #define VSC73XX_CAT_PR_MISC_L2 0x6f #define VSC73XX_CAT_PR_USR_PRIO 0x75 +#define VSC73XX_CAT_VLAN_MISC 0x79 +#define VSC73XX_CAT_PORT_VLAN 0x7a #define VSC73XX_Q_MISC_CONF 0xdf =20 /* MAC_CFG register bits */ @@ -122,6 +126,17 @@ #define VSC73XX_ADVPORTM_IO_LOOPBACK BIT(1) #define VSC73XX_ADVPORTM_HOST_LOOPBACK BIT(0) =20 +/* TXUPDCFG transmit modify setup bits */ +#define VSC73XX_TXUPDCFG_DSCP_REWR_MODE GENMASK(20, 19) +#define VSC73XX_TXUPDCFG_DSCP_REWR_ENA BIT(18) +#define VSC73XX_TXUPDCFG_TX_INT_TO_USRPRIO_ENA BIT(17) +#define VSC73XX_TXUPDCFG_TX_UNTAGGED_VID GENMASK(15, 4) +#define VSC73XX_TXUPDCFG_TX_UNTAGGED_VID_ENA BIT(3) +#define VSC73XX_TXUPDCFG_TX_UPDATE_CRC_CPU_ENA BIT(1) +#define VSC73XX_TXUPDCFG_TX_INSERT_TAG BIT(0) + +#define VSC73XX_TXUPDCFG_TX_UNTAGGED_VID_SHIFT 4 + /* CAT_DROP categorizer frame dropping register bits */ #define VSC73XX_CAT_DROP_DROP_MC_SMAC_ENA BIT(6) #define VSC73XX_CAT_DROP_FWD_CTRL_ENA BIT(4) @@ -135,6 +150,15 @@ #define VSC73XX_Q_MISC_CONF_EARLY_TX_512 (1 << 1) #define VSC73XX_Q_MISC_CONF_MAC_PAUSE_MODE BIT(0) =20 +/* CAT_VLAN_MISC categorizer VLAN miscellaneous bits */ +#define VSC73XX_CAT_VLAN_MISC_VLAN_TCI_IGNORE_ENA BIT(8) +#define VSC73XX_CAT_VLAN_MISC_VLAN_KEEP_TAG_ENA BIT(7) + +/* CAT_PORT_VLAN categorizer port VLAN */ +#define VSC73XX_CAT_PORT_VLAN_VLAN_CFI BIT(15) +#define VSC73XX_CAT_PORT_VLAN_VLAN_USR_PRIO GENMASK(14, 12) +#define VSC73XX_CAT_PORT_VLAN_VLAN_VID GENMASK(11, 0) + /* Frame analyzer block 2 registers */ #define VSC73XX_STORMLIMIT 0x02 #define VSC73XX_ADVLEARN 0x03 @@ -189,7 +213,8 @@ #define VSC73XX_VLANACCESS_VLAN_MIRROR BIT(29) #define VSC73XX_VLANACCESS_VLAN_SRC_CHECK BIT(28) #define VSC73XX_VLANACCESS_VLAN_PORT_MASK GENMASK(9, 2) -#define VSC73XX_VLANACCESS_VLAN_TBL_CMD_MASK GENMASK(2, 0) +#define VSC73XX_VLANACCESS_VLAN_PORT_MASK_SHIFT 2 +#define VSC73XX_VLANACCESS_VLAN_TBL_CMD_MASK GENMASK(1, 0) #define VSC73XX_VLANACCESS_VLAN_TBL_CMD_IDLE 0 #define VSC73XX_VLANACCESS_VLAN_TBL_CMD_READ_ENTRY 1 #define VSC73XX_VLANACCESS_VLAN_TBL_CMD_WRITE_ENTRY 2 @@ -347,6 +372,12 @@ static const struct vsc73xx_counter vsc73xx_tx_counter= s[] =3D { { 29, "TxQoSClass3" }, /* non-standard counter */ }; =20 +enum vsc73xx_port_vlan_conf { + VSC73XX_VLAN_FILTER, + VSC73XX_VLAN_FILTER_UNTAG_ALL, + VSC73XX_VLAN_IGNORE, +}; + int vsc73xx_is_addr_valid(u8 block, u8 subblock) { switch (block) { @@ -564,6 +595,91 @@ static enum dsa_tag_protocol vsc73xx_get_tag_protocol(= struct dsa_switch *ds, return DSA_TAG_PROTO_NONE; } =20 +static int vsc73xx_wait_for_vlan_table_cmd(struct vsc73xx *vsc) +{ + int ret, err; + u32 val; + + ret =3D read_poll_timeout(vsc73xx_read, err, + err < 0 || + ((val & VSC73XX_VLANACCESS_VLAN_TBL_CMD_MASK) =3D=3D + VSC73XX_VLANACCESS_VLAN_TBL_CMD_IDLE), + VSC73XX_POLL_SLEEP_US, VSC73XX_POLL_TIMEOUT_US, + false, vsc, VSC73XX_BLOCK_ANALYZER, + 0, VSC73XX_VLANACCESS, &val); + if (ret) + return ret; + return err; +} + +static int +vsc73xx_read_vlan_table_entry(struct vsc73xx *vsc, u16 vid, u8 *portmap) +{ + u32 val; + int ret; + + vsc73xx_write(vsc, VSC73XX_BLOCK_ANALYZER, 0, VSC73XX_VLANTIDX, vid); + + ret =3D vsc73xx_wait_for_vlan_table_cmd(vsc); + if (ret) + return ret; + + vsc73xx_update_bits(vsc, VSC73XX_BLOCK_ANALYZER, 0, VSC73XX_VLANACCESS, + VSC73XX_VLANACCESS_VLAN_TBL_CMD_MASK, + VSC73XX_VLANACCESS_VLAN_TBL_CMD_READ_ENTRY); + + ret =3D vsc73xx_wait_for_vlan_table_cmd(vsc); + if (ret) + return ret; + + vsc73xx_read(vsc, VSC73XX_BLOCK_ANALYZER, 0, VSC73XX_VLANACCESS, &val); + *portmap =3D (val & VSC73XX_VLANACCESS_VLAN_PORT_MASK) >> + VSC73XX_VLANACCESS_VLAN_PORT_MASK_SHIFT; + + return 0; +} + +static int +vsc73xx_write_vlan_table_entry(struct vsc73xx *vsc, u16 vid, u8 portmap) +{ + int ret; + + vsc73xx_write(vsc, VSC73XX_BLOCK_ANALYZER, 0, VSC73XX_VLANTIDX, vid); + + ret =3D vsc73xx_wait_for_vlan_table_cmd(vsc); + if (ret) + return ret; + + vsc73xx_update_bits(vsc, VSC73XX_BLOCK_ANALYZER, 0, VSC73XX_VLANACCESS, + VSC73XX_VLANACCESS_VLAN_TBL_CMD_MASK | + VSC73XX_VLANACCESS_VLAN_SRC_CHECK | + VSC73XX_VLANACCESS_VLAN_PORT_MASK, + VSC73XX_VLANACCESS_VLAN_TBL_CMD_WRITE_ENTRY | + VSC73XX_VLANACCESS_VLAN_SRC_CHECK | + (portmap << VSC73XX_VLANACCESS_VLAN_PORT_MASK_SHIFT) + ); + + return vsc73xx_wait_for_vlan_table_cmd(vsc); +} + +static int +vsc73xx_update_vlan_table(struct vsc73xx *vsc, int port, u16 vid, bool set) +{ + u8 portmap; + int ret; + + ret =3D vsc73xx_read_vlan_table_entry(vsc, vid, &portmap); + if (ret) + return ret; + + if (set) + portmap |=3D BIT(port); + else + portmap &=3D ~BIT(port); + + return vsc73xx_write_vlan_table_entry(vsc, vid, portmap); +} + static int vsc73xx_setup(struct dsa_switch *ds) { struct vsc73xx *vsc =3D ds->priv; @@ -598,7 +714,7 @@ static int vsc73xx_setup(struct dsa_switch *ds) VSC73XX_MACACCESS, VSC73XX_MACACCESS_CMD_CLEAR_TABLE); =20 - /* Clear VLAN table */ + /* Set VLAN table to default values */ vsc73xx_write(vsc, VSC73XX_BLOCK_ANALYZER, 0, VSC73XX_VLANACCESS, VSC73XX_VLANACCESS_VLAN_TBL_CMD_CLEAR_TABLE); @@ -627,6 +743,9 @@ static int vsc73xx_setup(struct dsa_switch *ds) vsc73xx_write(vsc, VSC73XX_BLOCK_SYSTEM, 0, VSC73XX_GMIIDELAY, VSC73XX_GMIIDELAY_GMII0_GTXDELAY_2_0_NS | VSC73XX_GMIIDELAY_GMII0_RXDELAY_2_0_NS); + /* Ingess VLAN reception mask (table 145) */ + vsc73xx_write(vsc, VSC73XX_BLOCK_ANALYZER, 0, VSC73XX_VLANMASK, + 0x5f); /* IP multicast flood mask (table 144) */ vsc73xx_write(vsc, VSC73XX_BLOCK_ANALYZER, 0, VSC73XX_IFLODMSK, 0xff); @@ -639,6 +758,12 @@ static int vsc73xx_setup(struct dsa_switch *ds) =20 udelay(4); =20 + /* Clear VLAN table */ + for (i =3D 0; i < VLAN_N_VID; i++) + vsc73xx_write_vlan_table_entry(vsc, i, 0); + + INIT_LIST_HEAD(&vsc->vlans); + return 0; } =20 @@ -1029,6 +1154,443 @@ static void vsc73xx_phylink_get_caps(struct dsa_swi= tch *dsa, int port, config->mac_capabilities =3D MAC_SYM_PAUSE | MAC_10 | MAC_100 | MAC_1000; } =20 +static void +vsc73xx_set_vlan_conf(struct vsc73xx *vsc, int port, + enum vsc73xx_port_vlan_conf port_vlan_conf) +{ + u32 val =3D 0; + + if (port_vlan_conf =3D=3D VSC73XX_VLAN_IGNORE) + val =3D VSC73XX_CAT_VLAN_MISC_VLAN_TCI_IGNORE_ENA | + VSC73XX_CAT_VLAN_MISC_VLAN_KEEP_TAG_ENA; + + vsc73xx_update_bits(vsc, VSC73XX_BLOCK_MAC, port, VSC73XX_CAT_VLAN_MISC, + VSC73XX_CAT_VLAN_MISC_VLAN_TCI_IGNORE_ENA | + VSC73XX_CAT_VLAN_MISC_VLAN_KEEP_TAG_ENA, val); + + val =3D (port_vlan_conf =3D=3D VSC73XX_VLAN_FILTER) ? + VSC73XX_TXUPDCFG_TX_INSERT_TAG : 0; + vsc73xx_update_bits(vsc, VSC73XX_BLOCK_MAC, port, VSC73XX_TXUPDCFG, + VSC73XX_TXUPDCFG_TX_INSERT_TAG, val); +} + +static int +vsc73xx_vlan_change_untagged(struct vsc73xx *vsc, int port, u16 vid, bool = set, + bool operate_on_storage) +{ + u32 val =3D 0; + + if (operate_on_storage) { + vsc->untagged_storage[port] =3D set ? vid : VLAN_N_VID; + return 0; + } + + if (set) + val =3D VSC73XX_TXUPDCFG_TX_UNTAGGED_VID_ENA | + ((vid << VSC73XX_TXUPDCFG_TX_UNTAGGED_VID_SHIFT) & + VSC73XX_TXUPDCFG_TX_UNTAGGED_VID); + + return vsc73xx_update_bits(vsc, VSC73XX_BLOCK_MAC, port, + VSC73XX_TXUPDCFG, + VSC73XX_TXUPDCFG_TX_UNTAGGED_VID_ENA | + VSC73XX_TXUPDCFG_TX_UNTAGGED_VID, val); +} + +static int vsc73xx_vlan_change_pvid(struct vsc73xx *vsc, int port, u16 vid, + bool set, bool operate_on_storage) +{ + int ret; + u32 val; + + if (operate_on_storage) { + vsc->pvid_storage[port] =3D set ? vid : VLAN_N_VID; + return 0; + } + + val =3D set ? 0 : VSC73XX_CAT_DROP_UNTAGGED_ENA; + vid =3D set ? vid : 0; + + ret =3D vsc73xx_update_bits(vsc, VSC73XX_BLOCK_MAC, port, + VSC73XX_CAT_DROP, + VSC73XX_CAT_DROP_UNTAGGED_ENA, val); + if (ret) + return ret; + + return vsc73xx_update_bits(vsc, VSC73XX_BLOCK_MAC, port, + VSC73XX_CAT_PORT_VLAN, + VSC73XX_CAT_PORT_VLAN_VLAN_VID, + vid & VSC73XX_CAT_PORT_VLAN_VLAN_VID); +} + +static bool vsc73xx_port_get_pvid(struct vsc73xx *vsc, int port, u16 *vid, + bool operate_on_storage) +{ + u32 val; + + if (operate_on_storage) { + if (vsc->pvid_storage[port] < VLAN_N_VID) { + *vid =3D vsc->pvid_storage[port]; + return true; + } + return false; + } + + vsc73xx_read(vsc, VSC73XX_BLOCK_MAC, port, VSC73XX_CAT_DROP, &val); + if (val & VSC73XX_CAT_DROP_UNTAGGED_ENA) + return false; + + vsc73xx_read(vsc, VSC73XX_BLOCK_MAC, port, VSC73XX_CAT_PORT_VLAN, &val); + *vid =3D val & VSC73XX_CAT_PORT_VLAN_VLAN_VID; + + return true; +} + +static bool vsc73xx_tag_8021q_active(struct dsa_port *dp) +{ + return !dsa_port_is_vlan_filtering(dp); +} + +static bool vsc73xx_port_get_untagged(struct vsc73xx *vsc, int port, u16 *= vid, + bool operate_on_storage) +{ + u32 val; + + if (operate_on_storage) { + if (vsc->untagged_storage[port] < VLAN_N_VID) { + *vid =3D vsc->untagged_storage[port]; + return true; + } + return false; + } + + vsc73xx_read(vsc, VSC73XX_BLOCK_MAC, port, VSC73XX_TXUPDCFG, &val); + if (!(val & VSC73XX_TXUPDCFG_TX_UNTAGGED_VID_ENA)) + return false; + + *vid =3D (val & VSC73XX_TXUPDCFG_TX_UNTAGGED_VID) >> + VSC73XX_TXUPDCFG_TX_UNTAGGED_VID_SHIFT; + + return true; +} + +static struct vsc73xx_bridge_vlan * +vsc73xx_bridge_vlan_find(struct vsc73xx *vsc, u16 vid) +{ + struct vsc73xx_bridge_vlan *vlan; + + list_for_each_entry(vlan, &vsc->vlans, list) + if (vlan->vid =3D=3D vid) + return vlan; + + return NULL; +} + +static size_t +vsc73xx_bridge_vlan_num_tagged(struct vsc73xx *vsc, int port, u16 ignored_= vid) +{ + struct vsc73xx_bridge_vlan *vlan; + size_t num_tagged =3D 0; + + list_for_each_entry(vlan, &vsc->vlans, list) + if ((vlan->portmask & BIT(port)) && + !(vlan->untagged & BIT(port)) && + vlan->vid !=3D ignored_vid) + num_tagged++; + + return num_tagged; +} + +static size_t +vsc73xx_bridge_vlan_num_untagged(struct vsc73xx *vsc, int port, u16 ignore= d_vid) +{ + struct vsc73xx_bridge_vlan *vlan; + size_t num_untagged =3D 0; + + list_for_each_entry(vlan, &vsc->vlans, list) + if ((vlan->portmask & BIT(port)) && + (vlan->untagged & BIT(port)) && + vlan->vid !=3D ignored_vid) + num_untagged++; + + return num_untagged; +} + +static u16 vsc73xx_find_first_vlan_untagged(struct vsc73xx *vsc, int port) +{ + struct vsc73xx_bridge_vlan *vlan; + + list_for_each_entry(vlan, &vsc->vlans, list) + if ((vlan->portmask & BIT(port)) && + (vlan->untagged & BIT(port))) + return vlan->vid; + + return VLAN_N_VID; +} + +static int +vsc73xx_port_vlan_filtering(struct dsa_switch *ds, int port, + bool vlan_filtering, struct netlink_ext_ack *extack) +{ + enum vsc73xx_port_vlan_conf port_vlan_conf =3D VSC73XX_VLAN_IGNORE; + struct vsc73xx *vsc =3D ds->priv; + bool store_untagged =3D false; + bool store_pvid =3D false; + u16 vid, vlan_untagged; + + /* The swap processed below is required because vsc73xx is using + * tag_8021q. When vlan_filtering is disabled, tag_8021q uses + * pvid/untagged vlans for port recognition. The values configured for + * vlans < 3072 are stored in storage table. When vlan_filtering is + * enabled, we need to restore pvid/untagged from storage and keep + * values used for tag_8021q. + */ + if (vlan_filtering) { + /* Use VLAN_N_VID to count all vlans */ + size_t num_untagged =3D + vsc73xx_bridge_vlan_num_untagged(vsc, port, VLAN_N_VID); + + port_vlan_conf =3D (num_untagged > 1) ? + VSC73XX_VLAN_FILTER_UNTAG_ALL : + VSC73XX_VLAN_FILTER; + + vlan_untagged =3D vsc73xx_find_first_vlan_untagged(vsc, port); + if (vlan_untagged < VLAN_N_VID) { + store_untagged =3D vsc73xx_port_get_untagged(vsc, port, + &vid, + false); + vsc73xx_vlan_change_untagged(vsc, port, vlan_untagged, + true, false); + vsc->untagged_storage[port] =3D store_untagged ? + vid : VLAN_N_VID; + } + } else { + vsc73xx_vlan_change_untagged(vsc, port, + vsc->untagged_storage[port], + vsc->untagged_storage[port] < + VLAN_N_VID, false); + } + + vsc73xx_set_vlan_conf(vsc, port, port_vlan_conf); + + store_pvid =3D vsc73xx_port_get_pvid(vsc, port, &vid, false); + vsc73xx_vlan_change_pvid(vsc, port, vsc->pvid_storage[port], + vsc->pvid_storage[port] < VLAN_N_VID, false); + vsc->pvid_storage[port] =3D store_pvid ? vid : VLAN_N_VID; + + return 0; +} + +static int vsc73xx_port_vlan_add(struct dsa_switch *ds, int port, + const struct switchdev_obj_port_vlan *vlan, + struct netlink_ext_ack *extack) +{ + bool untagged =3D vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED; + bool pvid =3D vlan->flags & BRIDGE_VLAN_INFO_PVID; + struct dsa_port *dp =3D dsa_to_port(ds, port); + struct vsc73xx_bridge_vlan *vsc73xx_vlan; + size_t num_tagged, num_untagged; + struct vsc73xx *vsc =3D ds->priv; + int ret; + u16 vid; + + /* Be sure to deny alterations to the configuration done by tag_8021q. + */ + if (vid_is_dsa_8021q(vlan->vid)) { + NL_SET_ERR_MSG_MOD(extack, + "Range 3072-4095 reserved for dsa_8021q operation"); + return -EBUSY; + } + + /* The processed vlan->vid is excluded from the search because the VLAN + * can be re-added with a different set of flags, so it's easiest to + * ignore its old flags from the VLAN database software copy. + */ + num_tagged =3D vsc73xx_bridge_vlan_num_tagged(vsc, port, vlan->vid); + num_untagged =3D vsc73xx_bridge_vlan_num_untagged(vsc, port, vlan->vid); + + /* VSC73XX allow only three untagged states: none, one or all */ + if ((untagged && num_tagged > 0 && num_untagged > 0) || + (!untagged && num_untagged > 1)) { + NL_SET_ERR_MSG_MOD(extack, + "Port can have only none, one or all untagged vlan"); + return -EBUSY; + } + + vsc73xx_vlan =3D vsc73xx_bridge_vlan_find(vsc, vlan->vid); + + if (!vsc73xx_vlan) { + vsc73xx_vlan =3D kzalloc(sizeof(*vsc73xx_vlan), GFP_KERNEL); + if (!vsc73xx_vlan) + return -ENOMEM; + + vsc73xx_vlan->vid =3D vlan->vid; + vsc73xx_vlan->portmask =3D BIT(port); + vsc73xx_vlan->untagged =3D untagged ? BIT(port) : 0; + + INIT_LIST_HEAD(&vsc73xx_vlan->list); + list_add_tail(&vsc73xx_vlan->list, &vsc->vlans); + } else { + vsc73xx_vlan->portmask |=3D BIT(port); + + if (untagged) + vsc73xx_vlan->untagged |=3D BIT(port); + else + vsc73xx_vlan->untagged &=3D ~BIT(port); + } + + /* CPU port must be always tagged because port separation is based on + * tag_8021q. + */ + if (port !=3D CPU_PORT) { + bool operate_on_storage =3D vsc73xx_tag_8021q_active(dp); + + if (!operate_on_storage) { + enum vsc73xx_port_vlan_conf port_vlan_conf =3D + VSC73XX_VLAN_FILTER; + + if (num_tagged =3D=3D 0 && untagged) + port_vlan_conf =3D VSC73XX_VLAN_FILTER_UNTAG_ALL; + vsc73xx_set_vlan_conf(vsc, port, port_vlan_conf); + + if (port_vlan_conf =3D=3D VSC73XX_VLAN_FILTER) { + if (untagged) { + ret =3D vsc73xx_vlan_change_untagged(vsc, + port, + vlan->vid, + true, + false); + if (ret) + goto err; + } else if (num_untagged =3D=3D 1) { + vid =3D vsc73xx_find_first_vlan_untagged(vsc, + port); + ret =3D vsc73xx_vlan_change_untagged(vsc, + port, + vid, + true, + false); + if (ret) + goto err; + } + } + } + + if (pvid) { + ret =3D vsc73xx_vlan_change_pvid(vsc, port, vlan->vid, + true, + operate_on_storage); + if (ret) + goto err; + } else if (vsc73xx_port_get_pvid(vsc, port, &vid, false) && + vid =3D=3D vlan->vid) { + vsc73xx_vlan_change_pvid(vsc, port, 0, false, false); + } else if (vsc->pvid_storage[port] =3D=3D vlan->vid) { + vsc73xx_vlan_change_pvid(vsc, port, 0, false, true); + } + } + + ret =3D vsc73xx_update_vlan_table(vsc, port, vlan->vid, true); + if (!ret) + return 0; +err: + list_del(&vsc73xx_vlan->list); + kfree(vsc73xx_vlan); + return ret; +} + +static int vsc73xx_port_vlan_del(struct dsa_switch *ds, int port, + const struct switchdev_obj_port_vlan *vlan) +{ + struct vsc73xx_bridge_vlan *vsc73xx_vlan; + size_t num_tagged, num_untagged; + struct vsc73xx *vsc =3D ds->priv; + bool operate_on_storage; + int ret; + u16 vid; + + num_tagged =3D vsc73xx_bridge_vlan_num_tagged(vsc, port, vlan->vid); + num_untagged =3D vsc73xx_bridge_vlan_num_untagged(vsc, port, vlan->vid); + + ret =3D vsc73xx_update_vlan_table(vsc, port, vlan->vid, false); + if (ret) + return ret; + + operate_on_storage =3D vsc73xx_tag_8021q_active(dsa_to_port(ds, port)); + + if (!operate_on_storage) { + enum vsc73xx_port_vlan_conf port_vlan_conf =3D + VSC73XX_VLAN_FILTER; + + if (num_tagged =3D=3D 0) + port_vlan_conf =3D VSC73XX_VLAN_FILTER_UNTAG_ALL; + vsc73xx_set_vlan_conf(vsc, port, port_vlan_conf); + + if (num_untagged <=3D 1) { + vid =3D vsc73xx_find_first_vlan_untagged(vsc, port); + vsc73xx_vlan_change_untagged(vsc, port, vid, + num_untagged, false); + } + } else if (vsc->untagged_storage[port] =3D=3D vlan->vid) { + vsc73xx_vlan_change_untagged(vsc, port, 0, false, true); + } + + if (vsc73xx_port_get_pvid(vsc, port, &vid, false) && vid =3D=3D vlan->vid) + vsc73xx_vlan_change_pvid(vsc, port, 0, false, false); + else if (vsc->pvid_storage[port] =3D=3D vlan->vid) + vsc73xx_vlan_change_pvid(vsc, port, 0, false, true); + + vsc73xx_vlan =3D vsc73xx_bridge_vlan_find(vsc, vlan->vid); + + if (vsc73xx_vlan) { + vsc73xx_vlan->portmask &=3D ~BIT(port); + + if (vsc73xx_vlan->portmask) + return 0; + + list_del(&vsc73xx_vlan->list); + kfree(vsc73xx_vlan); + } + + return 0; +} + +static int vsc73xx_port_setup(struct dsa_switch *ds, int port) +{ + struct vsc73xx *vsc =3D ds->priv; + + /* Those bits are responsible for MTU only. Kernel take care about MTU, + * let's enable +8 bytes frame length unconditionally. + */ + vsc73xx_update_bits(vsc, VSC73XX_BLOCK_MAC, port, VSC73XX_MAC_CFG, + VSC73XX_MAC_CFG_VLAN_AWR | + VSC73XX_MAC_CFG_VLAN_DBLAWR, + VSC73XX_MAC_CFG_VLAN_AWR | + VSC73XX_MAC_CFG_VLAN_DBLAWR); + + vsc73xx_update_bits(vsc, VSC73XX_BLOCK_MAC, port, VSC73XX_CAT_DROP, + VSC73XX_CAT_DROP_TAGGED_ENA | + VSC73XX_CAT_DROP_UNTAGGED_ENA, + VSC73XX_CAT_DROP_UNTAGGED_ENA); + vsc73xx_update_bits(vsc, VSC73XX_BLOCK_MAC, port, VSC73XX_TXUPDCFG, + VSC73XX_TXUPDCFG_TX_UNTAGGED_VID_ENA | + VSC73XX_TXUPDCFG_TX_UNTAGGED_VID, 0); + vsc73xx_update_bits(vsc, VSC73XX_BLOCK_MAC, port, VSC73XX_CAT_PORT_VLAN, + VSC73XX_CAT_PORT_VLAN_VLAN_VID, 0); + + if (port =3D=3D CPU_PORT) + vsc73xx_set_vlan_conf(vsc, port, VSC73XX_VLAN_FILTER); + else + vsc73xx_set_vlan_conf(vsc, port, VSC73XX_VLAN_IGNORE); + + /* Initially, there is no backup VLAN configuration to keep track of, so + * configure the storage values out of range + */ + vsc->pvid_storage[port] =3D VLAN_N_VID; + vsc->untagged_storage[port] =3D VLAN_N_VID; + + return 0; +} + static void vsc73xx_refresh_fwd_map(struct dsa_switch *ds, int port, u8 st= ate) { struct dsa_port *other_dp, *dp =3D dsa_to_port(ds, port); @@ -1123,11 +1685,15 @@ static const struct dsa_switch_ops vsc73xx_ds_ops = =3D { .get_strings =3D vsc73xx_get_strings, .get_ethtool_stats =3D vsc73xx_get_ethtool_stats, .get_sset_count =3D vsc73xx_get_sset_count, + .port_setup =3D vsc73xx_port_setup, .port_enable =3D vsc73xx_port_enable, .port_disable =3D vsc73xx_port_disable, .port_change_mtu =3D vsc73xx_change_mtu, .port_max_mtu =3D vsc73xx_get_max_mtu, .port_stp_state_set =3D vsc73xx_port_stp_state_set, + .port_vlan_filtering =3D vsc73xx_port_vlan_filtering, + .port_vlan_add =3D vsc73xx_port_vlan_add, + .port_vlan_del =3D vsc73xx_port_vlan_del, .phylink_get_caps =3D vsc73xx_phylink_get_caps, }; =20 diff --git a/drivers/net/dsa/vitesse-vsc73xx.h b/drivers/net/dsa/vitesse-vs= c73xx.h index e7b08599a625..facc50f1e320 100644 --- a/drivers/net/dsa/vitesse-vsc73xx.h +++ b/drivers/net/dsa/vitesse-vsc73xx.h @@ -25,6 +25,17 @@ * @addr: MAC address used in flow control frames * @ops: Structure with hardware-dependent operations * @priv: Pointer to the configuration interface structure + * @pvid_storage: Storage table with PVID configured for other state of + * vlan_filtering. It has two alternating roles: it stores the PVID when + * configured by the bridge but VLAN filtering is off, and it stores the + * PVID necessary for tag_8021q operation when bridge VLAN filtering is + * enabled. + * @untagged_storage: Storage table with eggres untagged VLAN configured f= or + * other state of vlan_filtering.Keep VID necessary for tag8021q operations + * when vlan filtering is enabled. + * @vlans: List of configured vlans. Contains port mask and untagged statu= s of + * every vlan configured in port vlan operation. It doesn't cover tag_8021q + * vlans. */ struct vsc73xx { struct device *dev; @@ -35,6 +46,9 @@ struct vsc73xx { u8 addr[ETH_ALEN]; const struct vsc73xx_ops *ops; void *priv; + u16 pvid_storage[VSC73XX_MAX_NUM_PORTS]; + u16 untagged_storage[VSC73XX_MAX_NUM_PORTS]; + struct list_head vlans; }; =20 /** @@ -49,6 +63,21 @@ struct vsc73xx_ops { u32 val); }; =20 +/** + * struct vsc73xx_bridge_vlan - VSC73xx driver structure which keeps vlan + * database copy + * @vid: VLAN number + * @portmask: each bit represends one port + * @untagged: each bit represends one port configured with @vid untagged + * @list: list structure + */ +struct vsc73xx_bridge_vlan { + u16 vid; + u8 portmask; + u8 untagged; + struct list_head list; +}; + int vsc73xx_is_addr_valid(u8 block, u8 subblock); int vsc73xx_probe(struct vsc73xx *vsc); void vsc73xx_remove(struct vsc73xx *vsc); --=20 2.34.1 From nobody Sat Feb 7 19:04:11 2026 Received: from mail-ed1-f41.google.com (mail-ed1-f41.google.com [209.85.208.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1561D1493B6; Fri, 23 Feb 2024 21:02:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708722150; cv=none; b=bNZLYJwncN/IzW8U9iokhI7AQUzjwy1evsXJ2rNg3lkFfJTNW3HoVaieUj+6+T6ErgLHAuc17SKY8a3n/S3SS+MKGp7a0T265soJjCIkSlnZuSvcAELIxq58R2mKe/GDmV6zuQAvaUlo8qFruNLu2JRWf89RqO272Srm9Rs/bgU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708722150; c=relaxed/simple; bh=Ge4QXGCmrLjaNvVszjPRi3oZ/cuOJtfxYaMZ7XeCdNo=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=FZAWxVHH/sC7fgFBD4zmgk6KyAXpOmGBTwZmHJG1VvSBAZUPtu0MhP0fqfEY7DPBcZYKrCgd7gIoP4dt9sbRX2AJpi5S7wNz0l86NP7L+B+/d5UGRHuNkwJ460sI7vo6oDQ848njh6X7yl2K4rWRpEo+aGocBauVzq5ZW0KxbbQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=VJZHHeJQ; arc=none smtp.client-ip=209.85.208.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="VJZHHeJQ" Received: by mail-ed1-f41.google.com with SMTP id 4fb4d7f45d1cf-5640fef9fa6so1649096a12.0; Fri, 23 Feb 2024 13:02:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708722147; x=1709326947; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=vcBeMQ6U+yvrfqhVopecDLTi+IwDrZJeE1wPHz5lZzs=; b=VJZHHeJQgnY00gZsXrt9NurbfQnBScobSmvrwzmB8oIk7CKqFmjqHwbDKytFZyJR+v GbgVp6OeAJeLLWcyvH4Ls0OL/k5OqVDQUbtrtscBWpz/3EbqqRc34jH69EQOvOF1IwuU 4PalivfV/o+Zx3p91iabLU7wYa6t+/tUwlbPqjPF54OAUSrulDmWmzTi9bgOsKGv7XFn Tec0aNEzkSp8zbTAu2vUPIs9bRLND07mwC2Z/xYTaRfG6/WE7MpFa3xEUPDhIk+vtF6w Ok338ND+H8ZNnRSHMczlc1zocEVzwyAyFBd1HsN+yyj5U1DSc4+cqCKdGDk0+1ihmgzP LdRg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708722147; x=1709326947; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=vcBeMQ6U+yvrfqhVopecDLTi+IwDrZJeE1wPHz5lZzs=; b=lqUMdGoROvE7gvYWX1fczW/k+gyYVAnly3S2Z3sSOI05dkSTolar/PcOPCavhKkN8X 2Ywz6llG8mqDRDd7Kg9/mdZqHRpjgRr8i4IBR8nm+k2gc00QDW/7WwoYnUq74D05uL+8 E+TrYW+TtavSWTI+OrUyrX0LaQKz/WxemJfDbFrzCDZvnvxweE/WOup4RVZk0JgWxSwL 19ErH6l3zjNIberJldrsMgspUc5FNsjbjvIkeaPRS/S0HipUSKAt2KIDARIv8PpKyH62 eN2pURF939NHGnxn3fHzZOBJu8/ws9q+zscplCloLnnS/Aw1Dt8Kd5T/lapKRBreDVJ6 afhw== X-Forwarded-Encrypted: i=1; AJvYcCXYUu1yzd2GRW/oKkf3c4DARNZfoJMFvJ+yQNJ0u47DqxCHZ8iWgj3Ny0vJihLKhfIKl8NL0V84Wo91gXOzh+CV54bPCta8dCL0GOPu X-Gm-Message-State: AOJu0YylRS+GC78AgVOBWeLfabd5KJTMN6yfQJwUsewzdXjnafGI8I+a G6+FSyUfmfH7PH0TyMv15TwPVHiZc4/zA3tzjAVYZytTC2/LbKi8kvdV2y9318g= X-Google-Smtp-Source: AGHT+IHwBAMoti2alBUocy9BwyUKIE2FZEzonj/kFxEGgnpORtjpx5CsCoE5zkrsRA2A2uSe/j0qiQ== X-Received: by 2002:a17:906:a40f:b0:a3e:8300:7647 with SMTP id l15-20020a170906a40f00b00a3e83007647mr663043ejz.63.1708722147035; Fri, 23 Feb 2024 13:02:27 -0800 (PST) Received: from WBEC325.dom.lan ([185.188.71.122]) by smtp.gmail.com with ESMTPSA id st11-20020a170907c08b00b00a3e559aaff9sm6185424ejc.29.2024.02.23.13.02.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Feb 2024 13:02:26 -0800 (PST) From: Pawel Dembicki To: netdev@vger.kernel.org Cc: linus.walleij@linaro.org, Vladimir Oltean , Pawel Dembicki , Andrew Lunn , Florian Fainelli , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Claudiu Manoil , Alexandre Belloni , UNGLinuxDriver@microchip.com, Russell King , linux-kernel@vger.kernel.org Subject: [PATCH net-next v5 08/16] net: dsa: tag_sja1105: absorb logic for not overwriting precise info into dsa_8021q_rcv() Date: Fri, 23 Feb 2024 22:00:38 +0100 Message-Id: <20240223210049.3197486-9-paweldembicki@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240223210049.3197486-1-paweldembicki@gmail.com> References: <20240223210049.3197486-1-paweldembicki@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Vladimir Oltean In both sja1105_rcv() and sja1110_rcv(), we may have precise source port information coming from parallel hardware mechanisms, in addition to the tag_8021q header. Only sja1105_rcv() has extra logic to not overwrite that precise info with what's present in the VLAN tag. This is because sja1110_rcv() gets by, by having a reversed set of checks when assigning skb->dev. When the source port is imprecise (vbid >=3D1), source_port and switch_id will be set to zeroes by dsa_8021q_rcv(), which might be problematic. But by checking for vbid >=3D 1 first, sja1110_rcv() fends that off. We would like to make more code common between sja1105_rcv() and sja1110_rcv(), and for that, we need to make sure that sja1110_rcv() also goes through the precise source port preservation logic. Signed-off-by: Vladimir Oltean Signed-off-by: Pawel Dembicki --- v5: - add missing SoB v4: - introduced patch net/dsa/tag_8021q.c | 32 +++++++++++++++++++++++++++++--- net/dsa/tag_sja1105.c | 23 +++-------------------- 2 files changed, 32 insertions(+), 23 deletions(-) diff --git a/net/dsa/tag_8021q.c b/net/dsa/tag_8021q.c index 71b26ae6db39..3cb0293793a5 100644 --- a/net/dsa/tag_8021q.c +++ b/net/dsa/tag_8021q.c @@ -497,9 +497,21 @@ struct net_device *dsa_tag_8021q_find_port_by_vbid(str= uct net_device *conduit, } EXPORT_SYMBOL_GPL(dsa_tag_8021q_find_port_by_vbid); =20 +/** + * dsa_8021q_rcv - Decode source information from tag_8021q header + * @skb: RX socket buffer + * @source_port: pointer to storage for precise source port information. + * If this is known already from outside tag_8021q, the pre-initialized + * value is preserved. If not known, pass -1. + * @switch_id: similar to source_port. + * @vbid: pointer to storage for imprecise bridge ID. Must be pre-initiali= zed + * with -1. If a positive value is returned, the source_port and switch_id + * are invalid. + */ void dsa_8021q_rcv(struct sk_buff *skb, int *source_port, int *switch_id, int *vbid) { + int tmp_source_port, tmp_switch_id, tmp_vbid; u16 vid, tci; =20 if (skb_vlan_tag_present(skb)) { @@ -513,11 +525,25 @@ void dsa_8021q_rcv(struct sk_buff *skb, int *source_p= ort, int *switch_id, =20 vid =3D tci & VLAN_VID_MASK; =20 - *source_port =3D dsa_8021q_rx_source_port(vid); - *switch_id =3D dsa_8021q_rx_switch_id(vid); + tmp_source_port =3D dsa_8021q_rx_source_port(vid); + tmp_switch_id =3D dsa_8021q_rx_switch_id(vid); + tmp_vbid =3D dsa_tag_8021q_rx_vbid(vid); + + /* Precise source port information is unknown when receiving from a + * VLAN-unaware bridging domain, and tmp_source_port and tmp_switch_id + * are zeroes in this case. + * + * Preserve the source information from hardware-specific mechanisms, + * if available. This allows us to not overwrite a valid source port + * and switch ID with less precise values. + */ + if (tmp_vbid =3D=3D 0 && *source_port =3D=3D -1) + *source_port =3D tmp_source_port; + if (tmp_vbid =3D=3D 0 && *switch_id =3D=3D -1) + *switch_id =3D tmp_switch_id; =20 if (vbid) - *vbid =3D dsa_tag_8021q_rx_vbid(vid); + *vbid =3D tmp_vbid; =20 skb->priority =3D (tci & VLAN_PRIO_MASK) >> VLAN_PRIO_SHIFT; } diff --git a/net/dsa/tag_sja1105.c b/net/dsa/tag_sja1105.c index 1aba1d05c27a..48886d4b7e3e 100644 --- a/net/dsa/tag_sja1105.c +++ b/net/dsa/tag_sja1105.c @@ -524,30 +524,13 @@ static struct sk_buff *sja1105_rcv(struct sk_buff *sk= b, /* Normal data plane traffic and link-local frames are tagged with * a tag_8021q VLAN which we have to strip */ - if (sja1105_skb_has_tag_8021q(skb)) { - int tmp_source_port =3D -1, tmp_switch_id =3D -1; - - sja1105_vlan_rcv(skb, &tmp_source_port, &tmp_switch_id, &vbid, - &vid); - /* Preserve the source information from the INCL_SRCPT option, - * if available. This allows us to not overwrite a valid source - * port and switch ID with zeroes when receiving link-local - * frames from a VLAN-unaware bridged port (non-zero vbid) or a - * VLAN-aware bridged port (non-zero vid). Furthermore, the - * tag_8021q source port information is only of trust when the - * vbid is 0 (precise port). Otherwise, tmp_source_port and - * tmp_switch_id will be zeroes. - */ - if (vbid =3D=3D 0 && source_port =3D=3D -1) - source_port =3D tmp_source_port; - if (vbid =3D=3D 0 && switch_id =3D=3D -1) - switch_id =3D tmp_switch_id; - } else if (source_port =3D=3D -1 && switch_id =3D=3D -1) { + if (sja1105_skb_has_tag_8021q(skb)) + sja1105_vlan_rcv(skb, &source_port, &switch_id, &vbid, &vid); + else if (source_port =3D=3D -1 && switch_id =3D=3D -1) /* Packets with no source information have no chance of * getting accepted, drop them straight away. */ return NULL; - } =20 if (source_port !=3D -1 && switch_id !=3D -1) skb->dev =3D dsa_conduit_find_user(netdev, switch_id, source_port); --=20 2.34.1 From nobody Sat Feb 7 19:04:11 2026 Received: from mail-ej1-f54.google.com (mail-ej1-f54.google.com [209.85.218.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B7D5614A4EB; Fri, 23 Feb 2024 21:02:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708722156; cv=none; b=E19i2/O454JYTUljRHpGVHGYZLS6qvX2DqlZVz2eCnBh5TZYO4KjkbI8KQXQKCjzq/FnT7Tx+7Ou7Lhi4xZUmgCfIMWuYlRefP+XuGsDoHufYZmmJlR+DPtSN4Ui3AACM5awuFPwn//rnIQNDsb0iVh8EhINSWHyutLQATgXdLA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708722156; c=relaxed/simple; bh=dD5FfujAc94OXdU0UClPUt602iyIqBlyvP8ocvrvfVs=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=tgGbpnNBu822PdZyA8IVHb6wu67JpaI4EnJpEcvreXtD6n/iF6unapkK1QbWiBOJcG3eg2tvaiPXjN16zVO+HeMnpmlJlTFCXD7WvL6K5h+mgtlofI1eCFWa7P466ByjpqSOqJkkzmIcnQ7LyDdEafAqoqozaOtUF9raIKGqIDY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=E83Bieqn; arc=none smtp.client-ip=209.85.218.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="E83Bieqn" Received: by mail-ej1-f54.google.com with SMTP id a640c23a62f3a-a3ddc13bbb3so128070966b.0; Fri, 23 Feb 2024 13:02:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708722153; x=1709326953; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=X+4J3DQCVz1HXUjDsjFpN8O2XmJVUHvuuUmsIb+sDcU=; b=E83Bieqn6IiesVir9ilLbVu+91AkXUw67lP21vjZ+Ea2YSBbnQm03OZwHg/36jLW9H NtjDNanHht88EuKIWBuC7AfSzDCXKK38xIPKwIcQ79nNMhZt9eyNuR9qcebQhyo0bfEw c1mjWDBw3z3NXnPG3/HEcUZf3wyXxW4UxLeFEtWGoyoFhLV6lN1d8hBYAmVYtz9EisTg Kvkk26exLCs2Q2VZyYXodwmtbAsRqgZUnL3/oljbmperkcAA0CwRue3+1mqfR/Z0ST7v NHFIb6QagK7+XRmOGwaNI5+B6PucCJ9v/FFFjTMCshUgiAOr594drZSOCsnYkppZxIKU tgKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708722153; x=1709326953; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=X+4J3DQCVz1HXUjDsjFpN8O2XmJVUHvuuUmsIb+sDcU=; b=naNqMz2hy4WvjPO+8b+V7gx7szsXrOZgTwUcbQ8ZmFAM/TfzRAprSQjAVbZpKVngld 1xsHsC1pxawWQ7NGtx7l2TsPG6AfRBZ74uKWdXGlM+aDOD8KDGylSVVswuytASqLsxm1 QBky2mwJdZ7Y8QIa6kooZm5WuIvqhJV8YYjxB/aNFL0oU88QU3aHjD4INTfNoTcIU1Dn KP6O6OebS86k6EXG8SVtgqlEVuNPrWHasfahKuyXCVOaunbwO5hFtkEiNRu+VwhaE/8Q vpy77cpI7a/OG3/DDPp/hC/YyNv9BPm3JXDWPJL6BIoEjeck8tGQLTLY8kDHK8vph6vv BQsw== X-Forwarded-Encrypted: i=1; AJvYcCXNVIMqBWJZ4MUoZKEHM+fwfBiw6ENctnj58O1nsQUGv6MhuAbOt4XGtRPvrJ1cWKPT7cDOR8Ssjamym4kifTxQs6fLrTlOwBEXWqAf X-Gm-Message-State: AOJu0YzjMV/bVfysDlxWOk9SjXipu8+bqV6jq5GLwg4azIEVoqurcd9e WExR5jLOCopB/8bkXHexTiR9gznfPNXhg5YlmDEOG6XY+7euseojFpC+ucoAl8Q= X-Google-Smtp-Source: AGHT+IGSSogorGvYlhayIwMoENUQ9CaXYWb1KW09w49EFKsdj7EqhxE6w0cptI38FBNNTiwE6FacKw== X-Received: by 2002:a17:906:b2d9:b0:a3f:b4f0:6206 with SMTP id cf25-20020a170906b2d900b00a3fb4f06206mr907432ejb.7.1708722152628; Fri, 23 Feb 2024 13:02:32 -0800 (PST) Received: from WBEC325.dom.lan ([185.188.71.122]) by smtp.gmail.com with ESMTPSA id st11-20020a170907c08b00b00a3e559aaff9sm6185424ejc.29.2024.02.23.13.02.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Feb 2024 13:02:32 -0800 (PST) From: Pawel Dembicki To: netdev@vger.kernel.org Cc: linus.walleij@linaro.org, Vladimir Oltean , Pawel Dembicki , Andrew Lunn , Florian Fainelli , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Claudiu Manoil , Alexandre Belloni , UNGLinuxDriver@microchip.com, Russell King , linux-kernel@vger.kernel.org Subject: [PATCH net-next v5 09/16] net: dsa: tag_sja1105: absorb entire sja1105_vlan_rcv() into dsa_8021q_rcv() Date: Fri, 23 Feb 2024 22:00:39 +0100 Message-Id: <20240223210049.3197486-10-paweldembicki@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240223210049.3197486-1-paweldembicki@gmail.com> References: <20240223210049.3197486-1-paweldembicki@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Vladimir Oltean tag_sja1105 has a wrapper over dsa_8021q_rcv(): sja1105_vlan_rcv(), which determines whether the packet came from a bridge with vlan_filtering=3D1 (the case resolved via dsa_find_designated_bridge_port_by_vid()), or if it contains a tag_8021q header. Looking at a new tagger implementation for vsc73xx, based also on tag_8021q, it is becoming clear that the logic is needed there as well. So instead of forcing each tagger to wrap around dsa_8021q_rcv(), let's merge the logic into the core. Signed-off-by: Vladimir Oltean Signed-off-by: Pawel Dembicki --- v5: - add missing SoB v4: - introduced patch net/dsa/tag_8021q.c | 34 ++++++++++++++++++++++++++++------ net/dsa/tag_8021q.h | 2 +- net/dsa/tag_ocelot_8021q.c | 2 +- net/dsa/tag_sja1105.c | 32 ++++---------------------------- 4 files changed, 34 insertions(+), 36 deletions(-) diff --git a/net/dsa/tag_8021q.c b/net/dsa/tag_8021q.c index 3cb0293793a5..332b0ae02645 100644 --- a/net/dsa/tag_8021q.c +++ b/net/dsa/tag_8021q.c @@ -507,27 +507,39 @@ EXPORT_SYMBOL_GPL(dsa_tag_8021q_find_port_by_vbid); * @vbid: pointer to storage for imprecise bridge ID. Must be pre-initiali= zed * with -1. If a positive value is returned, the source_port and switch_id * are invalid. + * @vid: pointer to storage for original VID, in case tag_8021q decoding f= ailed. + * + * If the packet has a tag_8021q header, decode it and set @source_port, + * @switch_id and @vbid, and strip the header. Otherwise set @vid and keep= the + * header in the hwaccel area of the packet. */ void dsa_8021q_rcv(struct sk_buff *skb, int *source_port, int *switch_id, - int *vbid) + int *vbid, int *vid) { int tmp_source_port, tmp_switch_id, tmp_vbid; - u16 vid, tci; + __be16 vlan_proto; + u16 tmp_vid, tci; =20 if (skb_vlan_tag_present(skb)) { + vlan_proto =3D skb->vlan_proto; tci =3D skb_vlan_tag_get(skb); __vlan_hwaccel_clear_tag(skb); } else { + struct vlan_ethhdr *hdr =3D vlan_eth_hdr(skb); + + vlan_proto =3D hdr->h_vlan_proto; skb_push_rcsum(skb, ETH_HLEN); __skb_vlan_pop(skb, &tci); skb_pull_rcsum(skb, ETH_HLEN); } =20 - vid =3D tci & VLAN_VID_MASK; + tmp_vid =3D tci & VLAN_VID_MASK; + if (!vid_is_dsa_8021q(tmp_vid)) + goto not_tag_8021q; =20 - tmp_source_port =3D dsa_8021q_rx_source_port(vid); - tmp_switch_id =3D dsa_8021q_rx_switch_id(vid); - tmp_vbid =3D dsa_tag_8021q_rx_vbid(vid); + tmp_source_port =3D dsa_8021q_rx_source_port(tmp_vid); + tmp_switch_id =3D dsa_8021q_rx_switch_id(tmp_vid); + tmp_vbid =3D dsa_tag_8021q_rx_vbid(tmp_vid); =20 /* Precise source port information is unknown when receiving from a * VLAN-unaware bridging domain, and tmp_source_port and tmp_switch_id @@ -546,5 +558,15 @@ void dsa_8021q_rcv(struct sk_buff *skb, int *source_po= rt, int *switch_id, *vbid =3D tmp_vbid; =20 skb->priority =3D (tci & VLAN_PRIO_MASK) >> VLAN_PRIO_SHIFT; + return; + +not_tag_8021q: + if (vid) + *vid =3D tmp_vid; + if (vbid) + *vbid =3D -1; + + /* Put the tag back */ + __vlan_hwaccel_put_tag(skb, vlan_proto, tci); } EXPORT_SYMBOL_GPL(dsa_8021q_rcv); diff --git a/net/dsa/tag_8021q.h b/net/dsa/tag_8021q.h index 41f7167ac520..0c6671d7c1c2 100644 --- a/net/dsa/tag_8021q.h +++ b/net/dsa/tag_8021q.h @@ -14,7 +14,7 @@ struct sk_buff *dsa_8021q_xmit(struct sk_buff *skb, struc= t net_device *netdev, u16 tpid, u16 tci); =20 void dsa_8021q_rcv(struct sk_buff *skb, int *source_port, int *switch_id, - int *vbid); + int *vbid, int *vid); =20 struct net_device *dsa_tag_8021q_find_port_by_vbid(struct net_device *cond= uit, int vbid); diff --git a/net/dsa/tag_ocelot_8021q.c b/net/dsa/tag_ocelot_8021q.c index b059381310fe..8e8b1bef6af6 100644 --- a/net/dsa/tag_ocelot_8021q.c +++ b/net/dsa/tag_ocelot_8021q.c @@ -81,7 +81,7 @@ static struct sk_buff *ocelot_rcv(struct sk_buff *skb, { int src_port, switch_id; =20 - dsa_8021q_rcv(skb, &src_port, &switch_id, NULL); + dsa_8021q_rcv(skb, &src_port, &switch_id, NULL, NULL); =20 skb->dev =3D dsa_conduit_find_user(netdev, switch_id, src_port); if (!skb->dev) diff --git a/net/dsa/tag_sja1105.c b/net/dsa/tag_sja1105.c index 48886d4b7e3e..7639ccb94d35 100644 --- a/net/dsa/tag_sja1105.c +++ b/net/dsa/tag_sja1105.c @@ -472,37 +472,14 @@ static bool sja1110_skb_has_inband_control_extension(= const struct sk_buff *skb) return ntohs(eth_hdr(skb)->h_proto) =3D=3D ETH_P_SJA1110; } =20 -/* If the VLAN in the packet is a tag_8021q one, set @source_port and - * @switch_id and strip the header. Otherwise set @vid and keep it in the - * packet. - */ -static void sja1105_vlan_rcv(struct sk_buff *skb, int *source_port, - int *switch_id, int *vbid, u16 *vid) -{ - struct vlan_ethhdr *hdr =3D vlan_eth_hdr(skb); - u16 vlan_tci; - - if (skb_vlan_tag_present(skb)) - vlan_tci =3D skb_vlan_tag_get(skb); - else - vlan_tci =3D ntohs(hdr->h_vlan_TCI); - - if (vid_is_dsa_8021q(vlan_tci & VLAN_VID_MASK)) - return dsa_8021q_rcv(skb, source_port, switch_id, vbid); - - /* Try our best with imprecise RX */ - *vid =3D vlan_tci & VLAN_VID_MASK; -} - static struct sk_buff *sja1105_rcv(struct sk_buff *skb, struct net_device *netdev) { - int source_port =3D -1, switch_id =3D -1, vbid =3D -1; + int source_port =3D -1, switch_id =3D -1, vbid =3D -1, vid =3D -1; struct sja1105_meta meta =3D {0}; struct ethhdr *hdr; bool is_link_local; bool is_meta; - u16 vid; =20 hdr =3D eth_hdr(skb); is_link_local =3D sja1105_is_link_local(skb); @@ -525,7 +502,7 @@ static struct sk_buff *sja1105_rcv(struct sk_buff *skb, * a tag_8021q VLAN which we have to strip */ if (sja1105_skb_has_tag_8021q(skb)) - sja1105_vlan_rcv(skb, &source_port, &switch_id, &vbid, &vid); + dsa_8021q_rcv(skb, &source_port, &switch_id, &vbid, &vid); else if (source_port =3D=3D -1 && switch_id =3D=3D -1) /* Packets with no source information have no chance of * getting accepted, drop them straight away. @@ -660,9 +637,8 @@ static struct sk_buff *sja1110_rcv_inband_control_exten= sion(struct sk_buff *skb, static struct sk_buff *sja1110_rcv(struct sk_buff *skb, struct net_device *netdev) { - int source_port =3D -1, switch_id =3D -1, vbid =3D -1; + int source_port =3D -1, switch_id =3D -1, vbid =3D -1, vid =3D -1; bool host_only =3D false; - u16 vid =3D 0; =20 if (sja1110_skb_has_inband_control_extension(skb)) { skb =3D sja1110_rcv_inband_control_extension(skb, &source_port, @@ -674,7 +650,7 @@ static struct sk_buff *sja1110_rcv(struct sk_buff *skb, =20 /* Packets with in-band control extensions might still have RX VLANs */ if (likely(sja1105_skb_has_tag_8021q(skb))) - sja1105_vlan_rcv(skb, &source_port, &switch_id, &vbid, &vid); + dsa_8021q_rcv(skb, &source_port, &switch_id, &vbid, &vid); =20 if (vbid >=3D 1) skb->dev =3D dsa_tag_8021q_find_port_by_vbid(netdev, vbid); --=20 2.34.1 From nobody Sat Feb 7 19:04:11 2026 Received: from mail-ej1-f54.google.com (mail-ej1-f54.google.com [209.85.218.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0CD5514EFC5; Fri, 23 Feb 2024 21:02:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708722161; cv=none; b=lWc+bv5RFngLWJ7C+Cseifwwzr56hVQdDoDL+gNRGoKXFh+JHZNDbzEGkGtCv1Mb45DlqNzxOvN4fIi9wEo/0tZkUkHK6fwTkWGDn0lEj7cistqOB4Kxw5uuOae7YKQh39AMWNbbVss9XR67aP82AYFYkA1eHov5Ozk++hRB+dE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708722161; c=relaxed/simple; bh=2iUVpsRP+GziJHbqwVWUqIeakMzbVBwpep9BwrCTVN0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Xt0vyel0C9vsK/EA8XXa7GfpbtxHFtzf8q4MN0bQrPkhxaC8XeKhaYL4uqO/8svKr0qdKImHaCP0f0qTcbGTpbtLdK8aUQPDaj2gL+Lm1V5Ir/ToOPZd4YSPgTCA0jGTdhOV++ZyjddHfCl8UmqQUIcKoJ+7RxNmClpZaQ3yRK8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=PNXStYk7; arc=none smtp.client-ip=209.85.218.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="PNXStYk7" Received: by mail-ej1-f54.google.com with SMTP id a640c23a62f3a-a3e8c1e4aa7so127023266b.2; Fri, 23 Feb 2024 13:02:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708722158; x=1709326958; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=0NLCOmx0IepUq3FGeXL96wdgQ4A1ty/0t9iA55p68ic=; b=PNXStYk70Er1WvWKORv5EiLjIBatBy+v3gb8FvENboTSbZLSAYa7gRjOHXA2QlAZt0 3lFg/56GI1UNw7Hty4SLOkkrquZuJuVbbWon/MKe1FNiBVEewnNiDigce7MoIEJTq1bQ Ab7Xw26lQXet+Xs3TZHSA7jikc+sHFTK/5BzxFiScz2zwNFF70cifDvJ/ISRc6f7Crc3 5JGkQ7np69Sy9cNuPT4YfrtDxKh5MW+ukMBzzS7RwFmd0IoLlvAFdxjDT4R46Ng3+TJp BrsDSBh44PRDZbwhllQR0HvrcbKy4BycHumplud4+d/LezoxRa239cAngC0rPRE0ADrA /ulQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708722158; x=1709326958; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=0NLCOmx0IepUq3FGeXL96wdgQ4A1ty/0t9iA55p68ic=; b=j47woY2c7M5wCt9bK8U5iXWEsVLGzOJoUuRWBx/ARplVGJX72WwsJbxTZ4eseVvXcQ Tbz1TyFzh8LEWlpu1zXCpSZII2hGFKAyczuAUC4I5F/rcH2lxEu5LTGPAL1rHDZS0orw MXDRr2Q0c4wDzVBlwA8RUAKNaK8KsO+fEzJ3+VsaXlen3WAm7IrJmwjjrWO7yRwsfT/F P7IPRppcBMuA3rLHpMuup/KDhVkW8I3nKtcgyI5m19Q2CTzVUlGeG9IXZknz9VP1Pg9W x/w4nKGfVNHI1OaI9Mta9eax+iKram+O29ptj1LslKXVrBhJXF9sbq4UDFldE2ZpjH7P B/eQ== X-Forwarded-Encrypted: i=1; AJvYcCXpLM5ocNDNRjzWfMq0bQEJuVNWZa0klKCdITOGDMa2cOBFbmNVQ+QHwYFJh/J/+lFskkmCTOZQ0RVjJi/REYBdMNjE4zkSK6pYNqVQ X-Gm-Message-State: AOJu0YyKGt4WPTsedDrfZ6WQknnIVY2licYi/x+MpLk7lCRjgz/YPh3m i61PcU8SXufRH9EyFaD16K7YRyMHZNJhD05/TsZfG974hLbaSMfn9Jl1H6hajGk= X-Google-Smtp-Source: AGHT+IEaotSAMr41DL2euvzOhXf8mHXbPlfAdMNEbBS8HQCPP3PttQDXaZseZ2s663P/pjs0m077Lw== X-Received: by 2002:a17:906:d20e:b0:a3f:9f38:ded with SMTP id w14-20020a170906d20e00b00a3f9f380dedmr584159ejz.69.1708722157949; Fri, 23 Feb 2024 13:02:37 -0800 (PST) Received: from WBEC325.dom.lan ([185.188.71.122]) by smtp.gmail.com with ESMTPSA id st11-20020a170907c08b00b00a3e559aaff9sm6185424ejc.29.2024.02.23.13.02.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Feb 2024 13:02:37 -0800 (PST) From: Pawel Dembicki To: netdev@vger.kernel.org Cc: linus.walleij@linaro.org, Vladimir Oltean , Pawel Dembicki , Andrew Lunn , Florian Fainelli , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Claudiu Manoil , Alexandre Belloni , UNGLinuxDriver@microchip.com, Russell King , linux-kernel@vger.kernel.org Subject: [PATCH net-next v5 10/16] net: dsa: tag_sja1105: prefer precise source port info on SJA1110 too Date: Fri, 23 Feb 2024 22:00:40 +0100 Message-Id: <20240223210049.3197486-11-paweldembicki@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240223210049.3197486-1-paweldembicki@gmail.com> References: <20240223210049.3197486-1-paweldembicki@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Vladimir Oltean Now that dsa_8021q_rcv() handles better the case where we don't overwrite the precise source information if it comes from an external (non-tag_8021q) source, we can now unify the call sequence between sja1105_rcv() and sja1110_rcv(). This is a preparatory change for creating a higher-level wrapper for the entire sequence which will live in tag_8021q. Signed-off-by: Vladimir Oltean Signed-off-by: Pawel Dembicki --- v5: - resend only v4: - introduce patch and replace 'slave' with 'conduit' after rebase net/dsa/tag_sja1105.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/net/dsa/tag_sja1105.c b/net/dsa/tag_sja1105.c index 7639ccb94d35..35a6346549f2 100644 --- a/net/dsa/tag_sja1105.c +++ b/net/dsa/tag_sja1105.c @@ -652,12 +652,12 @@ static struct sk_buff *sja1110_rcv(struct sk_buff *sk= b, if (likely(sja1105_skb_has_tag_8021q(skb))) dsa_8021q_rcv(skb, &source_port, &switch_id, &vbid, &vid); =20 - if (vbid >=3D 1) + if (source_port !=3D -1 && switch_id !=3D -1) + skb->dev =3D dsa_conduit_find_user(netdev, switch_id, source_port); + else if (vbid >=3D 1) skb->dev =3D dsa_tag_8021q_find_port_by_vbid(netdev, vbid); - else if (source_port =3D=3D -1 || switch_id =3D=3D -1) - skb->dev =3D dsa_find_designated_bridge_port_by_vid(netdev, vid); else - skb->dev =3D dsa_conduit_find_user(netdev, switch_id, source_port); + skb->dev =3D dsa_find_designated_bridge_port_by_vid(netdev, vid); if (!skb->dev) { netdev_warn(netdev, "Couldn't decode source port\n"); return NULL; --=20 2.34.1 From nobody Sat Feb 7 19:04:11 2026 Received: from mail-ej1-f42.google.com (mail-ej1-f42.google.com [209.85.218.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3BD9114F96B; Fri, 23 Feb 2024 21:02:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708722167; cv=none; b=aQiFxH8EYVmfyYUrvsk3+YMzV89mUfIFjT8+YVFqsHBERd3OWqTyIIRdfTYfT456mZb0fQixBBHgMt2wOnBiy9zT83Ybrk7OiX117KxXb4wzyswu0kQIsmWUl+1bCTdGCIav6vwKD/Pd7H+2YWB0OT442eoCWLQTBbvoDlzd1zE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708722167; c=relaxed/simple; bh=cg5+yosR/5Tn9ofG8K0XW7tcyBhYZ/r6xGlE4FO9pW0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=idVkAplsDEDSkx3xP9XECGJ+C1dSppHIvo1+4ci6MUnV9vNu0iZ0OwYpTuS0hyfC8/RSl1ETSm3J7CPtoGMzkWjtayYbGroxXwUCIcYY1ZbkdaNjyMzvLu1fKyF7jL+DZNcv8mDCtcfsrcBwTEhr3t73fMa4/+mGWeXGMB0IvnA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=PygFljCI; arc=none smtp.client-ip=209.85.218.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="PygFljCI" Received: by mail-ej1-f42.google.com with SMTP id a640c23a62f3a-a3ddc13bbb3so128093566b.0; Fri, 23 Feb 2024 13:02:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708722163; x=1709326963; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=C/esy7XtdM/Uq4jCB2UtvNoZm2r9dK5BL2ynsWoKYNM=; b=PygFljCIAIdWBWqEIo5BN83pbMUdhlZ/MrtC9VPicDsoUscmN1qeDI60KUllufCY52 XxVk20c4YETwwOFXbT69FjOeWSsU2BVHxmwnIU8Oi4j4nL1yl2LV7PZpXM85+P4ZPGTh La0kRxlHtLdxym82lGYC9FOz24yWRmk9uhk69W1YikubkyywUjY1ztAqaAMdYFAVJPwg IM0QOtG1KxsgDXA/sFPwjD94/ru5MH3SDwQgZZrmStHmsVtX0TA3Yb3PNS1SehKZos1l WzzgviUTg2BPg2xZxHJWrLvfAKiK1DeUmzSXiaiojOVPtclrVTLt/ACJQ477YZYcn3ez wpgQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708722163; x=1709326963; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=C/esy7XtdM/Uq4jCB2UtvNoZm2r9dK5BL2ynsWoKYNM=; b=u2n6M7AfoWad8fD8h1iFgK5yR57TbfEiAMLjDOM6a94FLm5VfP/uGJ6FFA1lasRH39 UbQ0jwrAEt5t4DuCuEcuZa4zSkpmOBH6ggRIkwbKSpY3nTzzuBYqYkg7ErdjRX6NAapu oeDCJP20lzHAbUozAG8mNYxBSqWzqp+inSB5D7kPq5x+v9c7oNgvQuUg2myid1xCxry4 ApXpMnbiFZB1HeGo+Fm02f/k7/XhG7EAlkhJqU8J1tpBuF6GFyS5w5crs5Kb95WJVeTw hv8iI2fei10M1t5ZYfWPHLYoIuVd7w4YR0uF5i+f8tnppbOGfHlvQ6iOLvLAAJH9kPB4 i7zQ== X-Forwarded-Encrypted: i=1; AJvYcCUq5QJM8CtJ1kj9C9hlGusLX7K0jhxHW7Sb6/WhBWR1ahZgTiRNoZH8KRTAo4qfzqIhvOHkDeDJJBhWgXxFxcCBzCxQFRIY7GrJCaPr X-Gm-Message-State: AOJu0YwX7B9gKObAzHJDuvlXLrP6A3GgARX6zWAGRwYxpEJVsNhJRWcf rY14HV+mpx001lWiAeZNX4WjngxqE3WNpEorthwKrK3vhmKAAWZJXImLCPL45EI= X-Google-Smtp-Source: AGHT+IFBtOxqmrdsOvpFjK/lg5qcySCITo83aNfkf6FHl35CkKdpH88lxioDimb1quBf9cil/U7iaA== X-Received: by 2002:a17:906:338b:b0:a41:36d2:f342 with SMTP id v11-20020a170906338b00b00a4136d2f342mr789187eja.31.1708722163059; Fri, 23 Feb 2024 13:02:43 -0800 (PST) Received: from WBEC325.dom.lan ([185.188.71.122]) by smtp.gmail.com with ESMTPSA id st11-20020a170907c08b00b00a3e559aaff9sm6185424ejc.29.2024.02.23.13.02.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Feb 2024 13:02:42 -0800 (PST) From: Pawel Dembicki To: netdev@vger.kernel.org Cc: linus.walleij@linaro.org, Vladimir Oltean , Pawel Dembicki , Andrew Lunn , Florian Fainelli , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Claudiu Manoil , Alexandre Belloni , UNGLinuxDriver@microchip.com, Russell King , linux-kernel@vger.kernel.org Subject: [PATCH net-next v5 11/16] net: dsa: tag_sja1105: refactor skb->dev assignment to dsa_tag_8021q_find_user() Date: Fri, 23 Feb 2024 22:00:41 +0100 Message-Id: <20240223210049.3197486-12-paweldembicki@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240223210049.3197486-1-paweldembicki@gmail.com> References: <20240223210049.3197486-1-paweldembicki@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Vladimir Oltean A new tagging protocol implementation based on tag_8021q is on the horizon, and it appears that it also has to open-code the complicated logic of finding a source port based on a VLAN header. Create a single dsa_tag_8021q_find_user() and make sja1105 call it. Signed-off-by: Vladimir Oltean Signed-off-by: Pawel Dembicki --- v5: - resend only v4: - introduce patch and change from master to conduit and slave to user net/dsa/tag_8021q.c | 19 ++++++++++++++++--- net/dsa/tag_8021q.h | 5 +++-- net/dsa/tag_sja1105.c | 17 +++++------------ 3 files changed, 24 insertions(+), 17 deletions(-) diff --git a/net/dsa/tag_8021q.c b/net/dsa/tag_8021q.c index 332b0ae02645..454d36c84671 100644 --- a/net/dsa/tag_8021q.c +++ b/net/dsa/tag_8021q.c @@ -468,8 +468,8 @@ struct sk_buff *dsa_8021q_xmit(struct sk_buff *skb, str= uct net_device *netdev, } EXPORT_SYMBOL_GPL(dsa_8021q_xmit); =20 -struct net_device *dsa_tag_8021q_find_port_by_vbid(struct net_device *cond= uit, - int vbid) +static struct net_device * +dsa_tag_8021q_find_port_by_vbid(struct net_device *conduit, int vbid) { struct dsa_port *cpu_dp =3D conduit->dsa_ptr; struct dsa_switch_tree *dst =3D cpu_dp->dst; @@ -495,7 +495,20 @@ struct net_device *dsa_tag_8021q_find_port_by_vbid(str= uct net_device *conduit, =20 return NULL; } -EXPORT_SYMBOL_GPL(dsa_tag_8021q_find_port_by_vbid); + +struct net_device *dsa_tag_8021q_find_user(struct net_device *conduit, + int source_port, int switch_id, + int vid, int vbid) +{ + /* Always prefer precise source port information, if available */ + if (source_port !=3D -1 && switch_id !=3D -1) + return dsa_conduit_find_user(conduit, switch_id, source_port); + else if (vbid >=3D 1) + return dsa_tag_8021q_find_port_by_vbid(conduit, vbid); + + return dsa_find_designated_bridge_port_by_vid(conduit, vid); +} +EXPORT_SYMBOL_GPL(dsa_tag_8021q_find_user); =20 /** * dsa_8021q_rcv - Decode source information from tag_8021q header diff --git a/net/dsa/tag_8021q.h b/net/dsa/tag_8021q.h index 0c6671d7c1c2..27b8906f99ec 100644 --- a/net/dsa/tag_8021q.h +++ b/net/dsa/tag_8021q.h @@ -16,8 +16,9 @@ struct sk_buff *dsa_8021q_xmit(struct sk_buff *skb, struc= t net_device *netdev, void dsa_8021q_rcv(struct sk_buff *skb, int *source_port, int *switch_id, int *vbid, int *vid); =20 -struct net_device *dsa_tag_8021q_find_port_by_vbid(struct net_device *cond= uit, - int vbid); +struct net_device *dsa_tag_8021q_find_user(struct net_device *conduit, + int source_port, int switch_id, + int vid, int vbid); =20 int dsa_switch_tag_8021q_vlan_add(struct dsa_switch *ds, struct dsa_notifier_tag_8021q_vlan_info *info); diff --git a/net/dsa/tag_sja1105.c b/net/dsa/tag_sja1105.c index 35a6346549f2..3e902af7eea6 100644 --- a/net/dsa/tag_sja1105.c +++ b/net/dsa/tag_sja1105.c @@ -509,12 +509,8 @@ static struct sk_buff *sja1105_rcv(struct sk_buff *skb, */ return NULL; =20 - if (source_port !=3D -1 && switch_id !=3D -1) - skb->dev =3D dsa_conduit_find_user(netdev, switch_id, source_port); - else if (vbid >=3D 1) - skb->dev =3D dsa_tag_8021q_find_port_by_vbid(netdev, vbid); - else - skb->dev =3D dsa_find_designated_bridge_port_by_vid(netdev, vid); + skb->dev =3D dsa_tag_8021q_find_user(netdev, source_port, switch_id, + vid, vbid); if (!skb->dev) { netdev_warn(netdev, "Couldn't decode source port\n"); return NULL; @@ -652,12 +648,9 @@ static struct sk_buff *sja1110_rcv(struct sk_buff *skb, if (likely(sja1105_skb_has_tag_8021q(skb))) dsa_8021q_rcv(skb, &source_port, &switch_id, &vbid, &vid); =20 - if (source_port !=3D -1 && switch_id !=3D -1) - skb->dev =3D dsa_conduit_find_user(netdev, switch_id, source_port); - else if (vbid >=3D 1) - skb->dev =3D dsa_tag_8021q_find_port_by_vbid(netdev, vbid); - else - skb->dev =3D dsa_find_designated_bridge_port_by_vid(netdev, vid); + skb->dev =3D dsa_tag_8021q_find_user(netdev, source_port, switch_id, + vid, vbid); + if (!skb->dev) { netdev_warn(netdev, "Couldn't decode source port\n"); return NULL; --=20 2.34.1 From nobody Sat Feb 7 19:04:11 2026 Received: from mail-ej1-f53.google.com (mail-ej1-f53.google.com [209.85.218.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0249D14F97D; Fri, 23 Feb 2024 21:02:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708722171; cv=none; b=kAMvTK8VMcM+lN42E1PS5uH+WHsDIwjyt6iquTogq/CTEtEyZBgoBLR6LZd0hcYdKsYCQBOVl0u5/pwko2gb/hdUT12cL0iGlH26p7FFsouEEjgS86v5dTd8D9Wi9Q41giiiOYLqnogOJhoEqfHOmFzRrml67G5oWGAMrNE6bnY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708722171; c=relaxed/simple; bh=8uvTSaExNf5N7PUZxerkiyfetwuQs19cLIADLSML+BY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=eSjr/no+rRDrdzGUzkmI0q5746Wl0u6B4jPHZkGheA41SkfEB39VAH+5dp+93TNBcSNz+V8BnWlmrn0L4ppDrc7ouwShPB3e8HiWEKfXIGiZsK61BLIhuNhX52dX9IwozHA1kSJnl971vjNdkx/ckciDgInWJ2yTzQ9qr84u/PU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=iAdqjQr7; arc=none smtp.client-ip=209.85.218.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="iAdqjQr7" Received: by mail-ej1-f53.google.com with SMTP id a640c23a62f3a-a26fa294e56so213728066b.0; Fri, 23 Feb 2024 13:02:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708722168; x=1709326968; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=CS69myIkjHM/Z9zwIn1rxkv4VNTb80UGHf3LfnDuhFs=; b=iAdqjQr7QixbARClfSI9xuqFvxlbMTxFojdvK70s9BdsEX1rYdr6cbSd5PGjn1XkPr jEBjf33/Bp/kWDoaLyisjWaiYBe+9DQFKg+WLSo8uyftYoOs8aQfS2/wZc1kpjggwckM pZwkUiEzcp7jYX/di9EcdropASCs9YrG3qf8/bZ+MDKzzVeJZjlRlFB5T9WLiR63eH63 in6q4bVndCijabFWdGW6Sl7LRHTcLEnrx7aCW6pe0nwgTCs2VYnVkwQt1eeLKgNpVsFP 9iHnrgfx/BFpw8gwpCo7MXJ+CVeE+lLH8zGIUrnWCatbmmZeaAYQgHTYmED7+xO+FJzD KPpA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708722168; x=1709326968; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=CS69myIkjHM/Z9zwIn1rxkv4VNTb80UGHf3LfnDuhFs=; b=NvLC05v8PGIn51MKcreYum2L1r6mx5PhESisPYYNNQqy2OTYH9nD0CfijCnFiIJBwc AJLkssDmbTNH/B3chmQBRjzWvnC6uUI97BxNChryflU2uu9MkgLGoKzHACn1tvYMx8VE oss4P0WxvScH1oeX3lFeNph82KVppj4GBjj6GVSTt7GbcTEKX3mrioSkHcITol2Iy3+Q Fma/JmOkzBJ4903jUx6IQ1+PRwf/m9IJZgmzwVK80SvE8hXP782lL7A93OpRYdKewUoa 3cPWlqgIdWJ4tmjOuAn4RSBpUcwkFTtCBg5AOtrWcZwXF645WU9qlOsT0+OHlkTBR+9N 35qg== X-Forwarded-Encrypted: i=1; AJvYcCX0ml8QEdRDYwMOGKBCVvcoLgHZIWfP8xxyp/lHNCyO2v9U41LIrmHLQ7/+Te0twpdZRM1hMJJfl5JTarkCG3nM9S18uw5vwWKQRDMv X-Gm-Message-State: AOJu0YyNL4FyIFFRG994iTdJ3IYVHxZZVI5IpOGs0RRnIew7tNZXlqug iSzBzJLm+apLRch/sNIzGrOmud6mgTmNKLSTHIAlyH5N3kY4IWQ0nO4tRIfWSvQ= X-Google-Smtp-Source: AGHT+IENP38wU4sFXdwDYIYmN+0anXzNC7F15y0nlkEiyfksPp8Rr5iOYV9+NfCBn2jssyTlbhyrrg== X-Received: by 2002:a17:906:a850:b0:a3e:980c:699d with SMTP id dx16-20020a170906a85000b00a3e980c699dmr631390ejb.57.1708722168076; Fri, 23 Feb 2024 13:02:48 -0800 (PST) Received: from WBEC325.dom.lan ([185.188.71.122]) by smtp.gmail.com with ESMTPSA id st11-20020a170907c08b00b00a3e559aaff9sm6185424ejc.29.2024.02.23.13.02.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Feb 2024 13:02:47 -0800 (PST) From: Pawel Dembicki To: netdev@vger.kernel.org Cc: linus.walleij@linaro.org, Pawel Dembicki , Andrew Lunn , Florian Fainelli , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Claudiu Manoil , Alexandre Belloni , UNGLinuxDriver@microchip.com, Russell King , linux-kernel@vger.kernel.org Subject: [PATCH net-next v5 12/16] net: dsa: vsc73xx: introduce tag 8021q for vsc73xx Date: Fri, 23 Feb 2024 22:00:42 +0100 Message-Id: <20240223210049.3197486-13-paweldembicki@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240223210049.3197486-1-paweldembicki@gmail.com> References: <20240223210049.3197486-1-paweldembicki@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This commit introduces a new tagger based on 802.1q tagging. It's designed for the vsc73xx driver. The VSC73xx family doesn't have any tag support for the RGMII port, but it could be based on VLANs. Signed-off-by: Pawel Dembicki --- v5: - removed skb_vlan_tag_present(skb) checking - use 80 characters per line limit v4: - rebase to net-next/main v3: - Introduce a patch after the tagging patch split include/net/dsa.h | 2 ++ net/dsa/Kconfig | 6 ++++ net/dsa/Makefile | 1 + net/dsa/tag_vsc73xx_8021q.c | 66 +++++++++++++++++++++++++++++++++++++ 4 files changed, 75 insertions(+) create mode 100644 net/dsa/tag_vsc73xx_8021q.c diff --git a/include/net/dsa.h b/include/net/dsa.h index 7c0da9effe4e..b79e136e4c41 100644 --- a/include/net/dsa.h +++ b/include/net/dsa.h @@ -56,6 +56,7 @@ struct phylink_link_state; #define DSA_TAG_PROTO_RTL8_4T_VALUE 25 #define DSA_TAG_PROTO_RZN1_A5PSW_VALUE 26 #define DSA_TAG_PROTO_LAN937X_VALUE 27 +#define DSA_TAG_PROTO_VSC73XX_8021Q_VALUE 28 =20 enum dsa_tag_protocol { DSA_TAG_PROTO_NONE =3D DSA_TAG_PROTO_NONE_VALUE, @@ -86,6 +87,7 @@ enum dsa_tag_protocol { DSA_TAG_PROTO_RTL8_4T =3D DSA_TAG_PROTO_RTL8_4T_VALUE, DSA_TAG_PROTO_RZN1_A5PSW =3D DSA_TAG_PROTO_RZN1_A5PSW_VALUE, DSA_TAG_PROTO_LAN937X =3D DSA_TAG_PROTO_LAN937X_VALUE, + DSA_TAG_PROTO_VSC73XX_8021Q =3D DSA_TAG_PROTO_VSC73XX_8021Q_VALUE, }; =20 struct dsa_switch; diff --git a/net/dsa/Kconfig b/net/dsa/Kconfig index 8e698bea99a3..e59360071c67 100644 --- a/net/dsa/Kconfig +++ b/net/dsa/Kconfig @@ -166,6 +166,12 @@ config NET_DSA_TAG_TRAILER Say Y or M if you want to enable support for tagging frames at with a trailed. e.g. Marvell 88E6060. =20 +config NET_DSA_TAG_VSC73XX_8021Q + tristate "Tag driver for Microchip/Vitesse VSC73xx family of switches, us= ing VLAN" + help + Say Y or M if you want to enable support for tagging frames with a + custom VLAN-based header. + config NET_DSA_TAG_XRS700X tristate "Tag driver for XRS700x switches" help diff --git a/net/dsa/Makefile b/net/dsa/Makefile index 8a1894a42552..555c07cfeb71 100644 --- a/net/dsa/Makefile +++ b/net/dsa/Makefile @@ -37,6 +37,7 @@ obj-$(CONFIG_NET_DSA_TAG_RTL8_4) +=3D tag_rtl8_4.o obj-$(CONFIG_NET_DSA_TAG_RZN1_A5PSW) +=3D tag_rzn1_a5psw.o obj-$(CONFIG_NET_DSA_TAG_SJA1105) +=3D tag_sja1105.o obj-$(CONFIG_NET_DSA_TAG_TRAILER) +=3D tag_trailer.o +obj-$(CONFIG_NET_DSA_TAG_VSC73XX_8021Q) +=3D tag_vsc73xx_8021q.o obj-$(CONFIG_NET_DSA_TAG_XRS700X) +=3D tag_xrs700x.o =20 # for tracing framework to find trace.h diff --git a/net/dsa/tag_vsc73xx_8021q.c b/net/dsa/tag_vsc73xx_8021q.c new file mode 100644 index 000000000000..3197c2f0d472 --- /dev/null +++ b/net/dsa/tag_vsc73xx_8021q.c @@ -0,0 +1,66 @@ +// SPDX-License-Identifier: GPL-2.0 OR MIT +/* Copyright (C) 2024 Pawel Dembicki + */ +#include + +#include "tag.h" +#include "tag_8021q.h" + +#define VSC73XX_8021Q_NAME "vsc73xx-8021q" + +static struct sk_buff * +vsc73xx_xmit(struct sk_buff *skb, struct net_device *netdev) +{ + struct dsa_port *dp =3D dsa_user_to_port(netdev); + u16 queue_mapping =3D skb_get_queue_mapping(skb); + u16 tx_vid =3D dsa_tag_8021q_standalone_vid(dp); + u8 pcp; + + if (skb->offload_fwd_mark) { + unsigned int bridge_num =3D dsa_port_bridge_num_get(dp); + struct net_device *br =3D dsa_port_bridge_dev_get(dp); + + if (br_vlan_enabled(br)) + return skb; + + tx_vid =3D dsa_tag_8021q_bridge_vid(bridge_num); + } + + pcp =3D netdev_txq_to_tc(netdev, queue_mapping); + + return dsa_8021q_xmit(skb, netdev, ETH_P_8021Q, + ((pcp << VLAN_PRIO_SHIFT) | tx_vid)); +} + +static struct sk_buff * +vsc73xx_rcv(struct sk_buff *skb, struct net_device *netdev) +{ + int src_port =3D -1, switch_id =3D -1, vbid =3D -1, vid =3D -1; + + dsa_8021q_rcv(skb, &src_port, &switch_id, &vbid, &vid); + + skb->dev =3D dsa_tag_8021q_find_user(netdev, src_port, switch_id, + vid, vbid); + if (!skb->dev) { + netdev_warn(netdev, "Couldn't decode source port\n"); + return NULL; + } + + dsa_default_offload_fwd_mark(skb); + + return skb; +} + +static const struct dsa_device_ops vsc73xx_8021q_netdev_ops =3D { + .name =3D VSC73XX_8021Q_NAME, + .proto =3D DSA_TAG_PROTO_VSC73XX_8021Q, + .xmit =3D vsc73xx_xmit, + .rcv =3D vsc73xx_rcv, + .needed_headroom =3D VLAN_HLEN, + .promisc_on_conduit =3D true, +}; + +MODULE_LICENSE("GPL"); +MODULE_ALIAS_DSA_TAG_DRIVER(DSA_TAG_PROTO_VSC73XX_8021Q, VSC73XX_8021Q_NAM= E); + +module_dsa_tag_driver(vsc73xx_8021q_netdev_ops); --=20 2.34.1 From nobody Sat Feb 7 19:04:11 2026 Received: from mail-ed1-f53.google.com (mail-ed1-f53.google.com [209.85.208.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7B3F714F99E; Fri, 23 Feb 2024 21:02:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708722177; cv=none; b=WQmKl6QAitV1aUolPnRsMSUoAAbIcdH5+PsevGKSGVGd3XTmbglK0ktjuNbQOlJGf3kRSiX4UwHWNMQlRdkqVXbBsWLkAhCV+2hJOBkqiacBJbXUhaK0WO2h0qpiiOkal076TwioMeiqtQhP0050NiiwwUNYuFdgcMkyLwwdpa0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708722177; c=relaxed/simple; bh=wqknE9u4+0m61qZz7WSBRU/y1adl1GpWbvzVjWqRpQs=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=R+uFE5njIAdNINaKhDHZglK+bvDyfG/+bXIauPVJ8ER8eifXDdzA0BQaNVo0Pbbte5sPj6xGv6XUP4bLj0vIE/cbiNI/flgodlrAUHiDFVuWsJNzsMEi2Fpx754IB7/9vqnDLW3YEI9glcLWhTFy/RgxzEnIHtelmurs0yh3mE4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=c0l1tv5b; arc=none smtp.client-ip=209.85.208.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="c0l1tv5b" Received: by mail-ed1-f53.google.com with SMTP id 4fb4d7f45d1cf-564e4df00f3so1563852a12.3; Fri, 23 Feb 2024 13:02:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708722173; x=1709326973; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=nFS2hcwK9/ZRU15faSWV/LrndwlGzgKuFOE0N4Cou2w=; b=c0l1tv5bp6t0Mlqw6p2pCwUVvnCvmZAhdpDM3SAc0/EHlGac/1GOOEpVgZevB1JCke oadC0TY1zhV19uq2/bXLeNdmHuO3W+32RygkzaZtIyzLbhSKHhPujz8K+9PbeVLaKSFE jpquO3ijaysec/dJb0SKR4TsQ6rzCEPSE0Uing/gtNMlo6RRj5lEDjE4hlnDMFw1/gmy JEoXRSvZaj1azb9i/hhqzqh90B/eVYgguVuKDPNkJd1c4gh7sE0aRpnO8tIa7HlN/+Ft wdXFTltT+Li9c6S7uNMlGyGaZ6OA7egDcCRLJ4NSjJ7x40kpWNkplcy9ngw+EVWObku7 DxsQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708722173; x=1709326973; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=nFS2hcwK9/ZRU15faSWV/LrndwlGzgKuFOE0N4Cou2w=; b=onfer8bLbFpIlZzajkZYbPiZ6WalFeMBrWNJDz7n76WfVtvgU/+8zqLYKCVcn+MoZF JQse+BnaL+ftTwPDWmIJKYQq9jcqepFDbF56EDerg+i3VIXr2uzBaJpwJ3HSzRulYKZT CRPDCLol/HhPMniv6mXPyZz48u/iZjbOnoVMoqyxX4wqhzXSTOdgMzclqXeO/V4uUA9b /QIdNlZYOqIhfNlglrG5hwUBU7+lF2X6LOoTfbU//t8efuYIxvJLQF88A1SKjTtopfqy oLhv0GjsZ9D+5z9bKhrUqjNgeGyIWdqlTlZgLMRWbaTnqNXsyp0D/bdmUE3bimwjQdXQ zttA== X-Forwarded-Encrypted: i=1; AJvYcCXxNxiFs8B13lfbboBrv7jGF4HKRuyFG767uq404ssSIyiQAd5WZ1ZMGgLwhr3UTF2TG4v6V2wHhXNrcDIutE3z+hW0aFquTUAmGyBW X-Gm-Message-State: AOJu0YyChmwwwMbUnUXsBBymisveoRQ8gkXA7fFgruTpguhqUkr0WXYs eHgQOZqEP+bIqflYBnmIr+ykOfUaBAOpPEv1MHb+uWhwJKRFacVnXL5762FMQ58= X-Google-Smtp-Source: AGHT+IHMhYGIk6DrqgXSN3qd7Sh734TzrVvLXgke5AtfBUeAKqPwKkpdJeiFOE+sVDDKyd3xIX4tcg== X-Received: by 2002:a17:906:6855:b0:a42:1347:17c0 with SMTP id a21-20020a170906685500b00a42134717c0mr376499ejs.50.1708722173289; Fri, 23 Feb 2024 13:02:53 -0800 (PST) Received: from WBEC325.dom.lan ([185.188.71.122]) by smtp.gmail.com with ESMTPSA id st11-20020a170907c08b00b00a3e559aaff9sm6185424ejc.29.2024.02.23.13.02.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Feb 2024 13:02:53 -0800 (PST) From: Pawel Dembicki To: netdev@vger.kernel.org Cc: linus.walleij@linaro.org, Pawel Dembicki , Andrew Lunn , Florian Fainelli , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Claudiu Manoil , Alexandre Belloni , UNGLinuxDriver@microchip.com, Russell King , linux-kernel@vger.kernel.org Subject: [PATCH net-next v5 13/16] net: dsa: vsc73xx: Implement the tag_8021q VLAN operations Date: Fri, 23 Feb 2024 22:00:43 +0100 Message-Id: <20240223210049.3197486-14-paweldembicki@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240223210049.3197486-1-paweldembicki@gmail.com> References: <20240223210049.3197486-1-paweldembicki@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This patch is a simple implementation of 802.1q tagging in the vsc73xx driver. Currently, devices with DSA_TAG_PROTO_NONE are not functional. The VSC73XX family doesn't provide any tag support for external Ethernet ports. The only option available is VLAN-based tagging, which requires constant hardware VLAN filtering. While the VSC73XX family supports provider bridging, it only supports QinQ without full implementation of 802.1AD. This means it only allows the doubled 0x8100 TPID. In the simple port mode, QinQ is enabled to preserve forwarding of VLAN-tagged frames. Signed-off-by: Pawel Dembicki --- v5: - improve commit message v4: - adjust tag8021q implementation for changed untagged vlan storage - minor fixes v3: - Split tagger and tag implementation into separate commits drivers/net/dsa/Kconfig | 2 +- drivers/net/dsa/vitesse-vsc73xx-core.c | 39 ++++++++++++++++++++++++-- 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/drivers/net/dsa/Kconfig b/drivers/net/dsa/Kconfig index 3092b391031a..22a04636d09e 100644 --- a/drivers/net/dsa/Kconfig +++ b/drivers/net/dsa/Kconfig @@ -126,7 +126,7 @@ config NET_DSA_SMSC_LAN9303_MDIO =20 config NET_DSA_VITESSE_VSC73XX tristate - select NET_DSA_TAG_NONE + select NET_DSA_TAG_VSC73XX_8021Q select FIXED_PHY select VITESSE_PHY select GPIOLIB diff --git a/drivers/net/dsa/vitesse-vsc73xx-core.c b/drivers/net/dsa/vites= se-vsc73xx-core.c index 87ad8b78f141..1132a86538a3 100644 --- a/drivers/net/dsa/vitesse-vsc73xx-core.c +++ b/drivers/net/dsa/vitesse-vsc73xx-core.c @@ -592,7 +592,7 @@ static enum dsa_tag_protocol vsc73xx_get_tag_protocol(s= truct dsa_switch *ds, * cannot access the tag. (See "Internal frame header" section * 3.9.1 in the manual.) */ - return DSA_TAG_PROTO_NONE; + return DSA_TAG_PROTO_VSC73XX_8021Q; } =20 static int vsc73xx_wait_for_vlan_table_cmd(struct vsc73xx *vsc) @@ -683,7 +683,7 @@ vsc73xx_update_vlan_table(struct vsc73xx *vsc, int port= , u16 vid, bool set) static int vsc73xx_setup(struct dsa_switch *ds) { struct vsc73xx *vsc =3D ds->priv; - int i; + int i, ret; =20 dev_info(vsc->dev, "set up the switch\n"); =20 @@ -752,6 +752,12 @@ static int vsc73xx_setup(struct dsa_switch *ds) =20 mdelay(50); =20 + rtnl_lock(); + ret =3D dsa_tag_8021q_register(ds, htons(ETH_P_8021Q)); + rtnl_unlock(); + if (ret) + return ret; + /* Release reset from the internal PHYs */ vsc73xx_write(vsc, VSC73XX_BLOCK_SYSTEM, 0, VSC73XX_GLORESET, VSC73XX_GLORESET_PHY_RESET); @@ -1554,6 +1560,33 @@ static int vsc73xx_port_vlan_del(struct dsa_switch *= ds, int port, return 0; } =20 +static int vsc73xx_tag_8021q_vlan_add(struct dsa_switch *ds, int port, u16= vid, + u16 flags) +{ + bool untagged =3D flags & BRIDGE_VLAN_INFO_UNTAGGED; + bool pvid =3D flags & BRIDGE_VLAN_INFO_PVID; + struct vsc73xx *vsc =3D ds->priv; + bool operate_on_storage; + + operate_on_storage =3D !vsc73xx_tag_8021q_active(dsa_to_port(ds, port)); + + if (untagged) + vsc73xx_vlan_change_untagged(vsc, port, vid, true, + operate_on_storage); + if (pvid) + vsc73xx_vlan_change_pvid(vsc, port, vid, true, + operate_on_storage); + + return vsc73xx_update_vlan_table(vsc, port, vid, true); +} + +static int vsc73xx_tag_8021q_vlan_del(struct dsa_switch *ds, int port, u16= vid) +{ + struct vsc73xx *vsc =3D ds->priv; + + return vsc73xx_update_vlan_table(vsc, port, vid, false); +} + static int vsc73xx_port_setup(struct dsa_switch *ds, int port) { struct vsc73xx *vsc =3D ds->priv; @@ -1695,6 +1728,8 @@ static const struct dsa_switch_ops vsc73xx_ds_ops =3D= { .port_vlan_add =3D vsc73xx_port_vlan_add, .port_vlan_del =3D vsc73xx_port_vlan_del, .phylink_get_caps =3D vsc73xx_phylink_get_caps, + .tag_8021q_vlan_add =3D vsc73xx_tag_8021q_vlan_add, + .tag_8021q_vlan_del =3D vsc73xx_tag_8021q_vlan_del, }; =20 static int vsc73xx_gpio_get(struct gpio_chip *chip, unsigned int offset) --=20 2.34.1 From nobody Sat Feb 7 19:04:11 2026 Received: from mail-ej1-f48.google.com (mail-ej1-f48.google.com [209.85.218.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5F111152DE9; Fri, 23 Feb 2024 21:03:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708722182; cv=none; b=Fsw7kWamShKZgg14CWaRpxRnK5RksncYAaiJDHz5F6jh6FKX+1AVal5RFjBhnvcsxetrXah59KTM5AGJ4y64+txRnaCZJXV59mzFWyxRsEBIl0XC+V+p2MfLxmR+h1wDxJXsvs2riHx8CBDSEllo2lQkzsEY1IcVCq1b6553TjY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708722182; c=relaxed/simple; bh=NbST3xiq/8f/mXsRyb+dmsw+eV52rzAmQa09GQXYbtQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=rFshRgLy63wq5ZsqpP8xgC/w7Jae7oTZgW/MPEpHD8jP8M7Iu1SG86OZDZz36fBwcL0dT6Lx6pVjpkb7PDc4+G8hkgN5DBj4RniHIsqONXX1PwDLQS5Bzbe9Pj/Dcq2KZWewYUlTN+KimvqL0HPJQBba0mCCw1UJIC4669MQY+M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=G0uYtcE7; arc=none smtp.client-ip=209.85.218.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="G0uYtcE7" Received: by mail-ej1-f48.google.com with SMTP id a640c23a62f3a-a2f22bfb4e6so126469666b.0; Fri, 23 Feb 2024 13:03:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708722178; x=1709326978; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=tztr1+TqGO5v+hvzGEs9lKsceCvS2t24CDtG8/HmH0c=; b=G0uYtcE7St9lo9QEdODm242GVehp9ba4gi5Zb8XNTXlyiD3/CYIheGkA3uCU5vX/xU tnGGWxB+uHj/f0JOQX5zfFdEjmX63MrnTFue23HzvrREsFjPTWDQCZ9+vEd/EASixfzM AcCdtZoIACuMGQvlXHRjk6BJpcTd/jolEXQ/m7JAJ7SlCXWj6sdqaG0IIt6gZ+2FGTJw 8klSFDfb74a5OSCaeUVuUr+GxC/SnPIns7Myi1lnteOcZKrymbWqWknxCyvmqQCNj8y8 kWYoxv5b4rX09CxU4BsYCc3OjanZgfOk3qua0UPWCBZnx4+0F2NSz/1rFBVhdsks31G/ a+fw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708722178; x=1709326978; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=tztr1+TqGO5v+hvzGEs9lKsceCvS2t24CDtG8/HmH0c=; b=WCnSHEeVRaEJl8uWPyUq16PkL1LsYHebnPAsX6OTfHu6C0aAzbVdZ0G/iTrfPX9Scr qR841/Rd4lGbPW0hZdcOT2YGO2+2PUxVd8H7apgWObztCcssB1kMM5hQAqEPU44VApPp R7pBSE8pvKvwq+4nH3HT8mDAyIFID3LGZ3YO9sTvq2DmEH2Sj74emYvgo9ORrgw8OCDQ AGdEn01y+I+JMyydF9MSj/rNbkH2q5DSOlqZOwlXx6g52IjPRQsrMSRLPevRZMJhAoFu 5osk3br//i+FMHbgjbPeg/MCngAEhW3r0fQYLnEv+huA+onVoDXYDeTG3HKO0SbjkizZ ZdYQ== X-Forwarded-Encrypted: i=1; AJvYcCVaJy6kWwYzN2uTiyAJVtbN8PENs9qGkCwFtqLOSVIciRVFLJWSTU4zLIf26MMkeOtDRIDrMfpJT4dNKUH+d/hfJBOcrRfZunJRKRca X-Gm-Message-State: AOJu0Yw7hK0daIDejxgqgyT7iHOG5KqXHxOhzuU9RYF1bBlVbJg5N49/ h92BvlbnUu0zoOlJKsQxQv36kvoN3mZMKXpLSWz7bslDOJ+1etksyOZFq0HLOiI= X-Google-Smtp-Source: AGHT+IHpO8gJUSAkISZp8PUFUv/4uG9dMlgn15urd9qo/QSRVfaKl9cd4f9RvZEAkkYgq9pKXkpfrg== X-Received: by 2002:a17:907:20b9:b0:a3e:6aae:d342 with SMTP id pw25-20020a17090720b900b00a3e6aaed342mr641518ejb.47.1708722178402; Fri, 23 Feb 2024 13:02:58 -0800 (PST) Received: from WBEC325.dom.lan ([185.188.71.122]) by smtp.gmail.com with ESMTPSA id st11-20020a170907c08b00b00a3e559aaff9sm6185424ejc.29.2024.02.23.13.02.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Feb 2024 13:02:58 -0800 (PST) From: Pawel Dembicki To: netdev@vger.kernel.org Cc: linus.walleij@linaro.org, Pawel Dembicki , Vladimir Oltean , Florian Fainelli , Andrew Lunn , Florian Fainelli , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Claudiu Manoil , Alexandre Belloni , UNGLinuxDriver@microchip.com, Russell King , linux-kernel@vger.kernel.org Subject: [PATCH net-next v5 14/16] net: dsa: Define max num of bridges in tag8021q implementation Date: Fri, 23 Feb 2024 22:00:44 +0100 Message-Id: <20240223210049.3197486-15-paweldembicki@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240223210049.3197486-1-paweldembicki@gmail.com> References: <20240223210049.3197486-1-paweldembicki@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Max number of bridges in tag8021q implementation is strictly limited by VBID size: 3 bits. But zero is reserved and only 7 values can be used. This patch adds define which describe maximum possible value. Suggested-by: Vladimir Oltean Signed-off-by: Pawel Dembicki Reviewed-by: Florian Fainelli --- v5: - added 'Reviewed-by' only v4: - introduce patch drivers/net/dsa/sja1105/sja1105_main.c | 3 +-- include/linux/dsa/8021q.h | 5 +++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/net/dsa/sja1105/sja1105_main.c b/drivers/net/dsa/sja11= 05/sja1105_main.c index 6646f7fb0f90..6e22d7a6bfa3 100644 --- a/drivers/net/dsa/sja1105/sja1105_main.c +++ b/drivers/net/dsa/sja1105/sja1105_main.c @@ -3156,8 +3156,7 @@ static int sja1105_setup(struct dsa_switch *ds) ds->vlan_filtering_is_global =3D true; ds->untag_bridge_pvid =3D true; ds->fdb_isolation =3D true; - /* tag_8021q has 3 bits for the VBID, and the value 0 is reserved */ - ds->max_num_bridges =3D 7; + ds->max_num_bridges =3D DSA_TAG_8021Q_MAX_NUM_BRIDGES; =20 /* Advertise the 8 egress queues */ ds->num_tx_queues =3D SJA1105_NUM_TC; diff --git a/include/linux/dsa/8021q.h b/include/linux/dsa/8021q.h index f3664ee12170..1dda2a13b832 100644 --- a/include/linux/dsa/8021q.h +++ b/include/linux/dsa/8021q.h @@ -8,6 +8,11 @@ #include #include =20 +/* VBID is limited to three bits only and zero is reserved. + * Only 7 bridges can be enumerated. + */ +#define DSA_TAG_8021Q_MAX_NUM_BRIDGES 7 + int dsa_tag_8021q_register(struct dsa_switch *ds, __be16 proto); =20 void dsa_tag_8021q_unregister(struct dsa_switch *ds); --=20 2.34.1 From nobody Sat Feb 7 19:04:11 2026 Received: from mail-lf1-f41.google.com (mail-lf1-f41.google.com [209.85.167.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B859514939E; Fri, 23 Feb 2024 21:03:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708722188; cv=none; b=P447Cq64vuYL2agoJSGtqL9C/2485/Krv5qCUSTO22JnJSesHksusPQXGYmgd/PgY43OakvU62kXUxAPJId5ZeHxlLBDM3pJMjhbA+uSAWIfn56rL+aZ2rVfVq4ZJDDpEcr1X28UWripa3NhL0NahOwtI0UN2D0y8DLatlb+5RQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708722188; c=relaxed/simple; bh=zxFuSdqwAGFS78xhXJ+6ExlfTO7DkUchW5bvMLNLJ+E=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=RktHnUm2BH6hG8WasWpWJC1RA9DGzDOqlxaAdeLYsPil+Mm4bCbIPUbW0/E+5amRzEpjgaYD52P2I70iZMBCByphTf+PczoPPAUoa49VWSBeq5C9ctKZ501sVTPXKopp1Ax5nxPCkUef7Os/l0k5Np04nT5XX3VxVPAitn9ttV8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=g4DjGv+m; arc=none smtp.client-ip=209.85.167.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="g4DjGv+m" Received: by mail-lf1-f41.google.com with SMTP id 2adb3069b0e04-512ab55fde6so1070090e87.2; Fri, 23 Feb 2024 13:03:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708722185; x=1709326985; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=CsgqUU+5bw6FiOn7ZlwWk12GQwooTmRMzEUA6afssIg=; b=g4DjGv+mj114mgehuOiE327nRVIHyPZD12UNw5jv5s0l8nzPFfFmn71gceighoIMg8 gJbTdUdzdLLMx7B9CQq0ZK8gU7rxVyqSybThf1d4yDPPiXzHTOSGSkfAFT2XPuZMPuR5 xE1xlQMaM183O4O5c9c8hL7UjLOdUWCR0owKIR/RIXkUG1v33LaOmLlMHVPqVN+7iVOA UP1ngFKBjbvttHgiX/8NAevP4kmn+YcZc2OP3RwYd2zrD6regxutCZ5ABkA/aagtg3P9 AsA2pBksVUEbSvv0etBjU74xui56BM1sIKP+4UTsXIi0WjI3//HA+Ac4R/s9aZlDxeJF WUnQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708722185; x=1709326985; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=CsgqUU+5bw6FiOn7ZlwWk12GQwooTmRMzEUA6afssIg=; b=SxHUkwVW9wUmsGubEd0xvEs5QX8dqf81apxcATpjtAm0s8p73bwI8+wca8+o22dYMV UdTyLIGtj1XAicUCBjm2PCp5bTmiXK9ziuGaG+V2wbZza3G8qwMWgwDtlFTNgMU8+wyx +Rm4UjpyhmiQrsyKi+yVTxEwwFc3nTbAXP9GYu70S+xyogoE72ka5cJaXAoeQ4oz1DRX dE9MceneSJ95ado1nO269I4WJZCKNRdQrQH53vgqeYopx7avTmtQYFvRaH6SYsmScINQ dhrE9I73Bfc+bdNZETnm5gYKCavRxNrwkymoCDd2aX2K9ErEv3Qjr0x9Ucz921Mrw01R OPBA== X-Forwarded-Encrypted: i=1; AJvYcCVfYY+ZbX5vVc0iSibu/WFE82dJ4Uqrb7DD478Nnyqwm3GTvWTHIGoe/qC5Fn6TSRara5SoEsYKytVOdtvglZIXPj2OOwrD8E5IQI2B X-Gm-Message-State: AOJu0Yx47WW5Dl/hALRZp69MQEToaw+oHjANbjPKS4oZnBb2NMOSrPfc c4V4V16EvIH86KjkUBL4ql5PT1mTwcGdKXwiFD3+sAx1fOrcHOtzBB2bCFr8x4w= X-Google-Smtp-Source: AGHT+IHciUWkHuvKW6gqvHMyFt/BsBIpY8aPjK1rxBoMC8W8hzqSZGelz2JEyAK26UPhWhfOyhW4qQ== X-Received: by 2002:a05:6512:324a:b0:512:d689:51cb with SMTP id c10-20020a056512324a00b00512d68951cbmr499841lfr.26.1708722184723; Fri, 23 Feb 2024 13:03:04 -0800 (PST) Received: from WBEC325.dom.lan ([185.188.71.122]) by smtp.gmail.com with ESMTPSA id st11-20020a170907c08b00b00a3e559aaff9sm6185424ejc.29.2024.02.23.13.03.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Feb 2024 13:03:04 -0800 (PST) From: Pawel Dembicki To: netdev@vger.kernel.org Cc: linus.walleij@linaro.org, Pawel Dembicki , Vladimir Oltean , Andrew Lunn , Florian Fainelli , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Claudiu Manoil , Alexandre Belloni , UNGLinuxDriver@microchip.com, Russell King , linux-kernel@vger.kernel.org Subject: [PATCH net-next v5 15/16] net: dsa: vsc73xx: Add bridge support Date: Fri, 23 Feb 2024 22:00:45 +0100 Message-Id: <20240223210049.3197486-16-paweldembicki@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240223210049.3197486-1-paweldembicki@gmail.com> References: <20240223210049.3197486-1-paweldembicki@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This patch adds bridge support for vsc73xx driver. It introduce two functions for port_bridge_join and vsc73xx_port_bridge_leave handling. Those functions implement forwarding adjust and use dsa_tag_8021q_bridge_* api for adjust VLAN configuration. Reviewed-by: Linus Walleij Signed-off-by: Pawel Dembicki Reviewed-by: Vladimir Oltean --- v5: - added 'Reviewed-by' only v4: - remove forward configuration after stp patch refactoring - implement new define with max num of bridges for tag8021q devices v3: - All vlan commits was reworked - move VLAN_AWR and VLAN_DBLAWR to port setup in other commit - drop vlan table upgrade v2: - no changes done drivers/net/dsa/vitesse-vsc73xx-core.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/drivers/net/dsa/vitesse-vsc73xx-core.c b/drivers/net/dsa/vites= se-vsc73xx-core.c index 1132a86538a3..8dc366461b9c 100644 --- a/drivers/net/dsa/vitesse-vsc73xx-core.c +++ b/drivers/net/dsa/vitesse-vsc73xx-core.c @@ -687,6 +687,9 @@ static int vsc73xx_setup(struct dsa_switch *ds) =20 dev_info(vsc->dev, "set up the switch\n"); =20 + ds->untag_bridge_pvid =3D true; + ds->max_num_bridges =3D DSA_TAG_8021Q_MAX_NUM_BRIDGES; + /* Issue RESET */ vsc73xx_write(vsc, VSC73XX_BLOCK_SYSTEM, 0, VSC73XX_GLORESET, VSC73XX_GLORESET_MASTER_RESET); @@ -1587,6 +1590,22 @@ static int vsc73xx_tag_8021q_vlan_del(struct dsa_swi= tch *ds, int port, u16 vid) return vsc73xx_update_vlan_table(vsc, port, vid, false); } =20 +static int vsc73xx_port_bridge_join(struct dsa_switch *ds, int port, + struct dsa_bridge bridge, + bool *tx_fwd_offload, + struct netlink_ext_ack *extack) +{ + *tx_fwd_offload =3D true; + + return dsa_tag_8021q_bridge_join(ds, port, bridge); +} + +static void vsc73xx_port_bridge_leave(struct dsa_switch *ds, int port, + struct dsa_bridge bridge) +{ + dsa_tag_8021q_bridge_leave(ds, port, bridge); +} + static int vsc73xx_port_setup(struct dsa_switch *ds, int port) { struct vsc73xx *vsc =3D ds->priv; @@ -1721,6 +1740,8 @@ static const struct dsa_switch_ops vsc73xx_ds_ops =3D= { .port_setup =3D vsc73xx_port_setup, .port_enable =3D vsc73xx_port_enable, .port_disable =3D vsc73xx_port_disable, + .port_bridge_join =3D vsc73xx_port_bridge_join, + .port_bridge_leave =3D vsc73xx_port_bridge_leave, .port_change_mtu =3D vsc73xx_change_mtu, .port_max_mtu =3D vsc73xx_get_max_mtu, .port_stp_state_set =3D vsc73xx_port_stp_state_set, --=20 2.34.1 From nobody Sat Feb 7 19:04:11 2026 Received: from mail-lj1-f174.google.com (mail-lj1-f174.google.com [209.85.208.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5243214939E; Fri, 23 Feb 2024 21:03:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708722194; cv=none; b=FtmqE+iUXbNRbzlSk5Dx3WGvVvgbJhOth0G6fUjptWNTgBYtqtPtPUunpcGsl1udmLrGDEhWsD2Cnzp7RR07ogBXd1Dldpi9SCetEXNo4X4hei+NPEE/MkoBjdveTuFi0qiPsGpaWpTI+WqXzKyu1atox+Vb2bumpkDPHfNzvss= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708722194; c=relaxed/simple; bh=wAzmO2nV/mts0uRLd+SnpnPKDzjDEHTguc73SCAqHIo=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=qdP4PndMQzEhSesHL8pYbPsV16oLry2U6IcOxR+iRKUlQfkwn4pGFd1+/TsRKxD4Q8xBqAw4SsCy+2BLLNmGM+br45h7lE7vgiuyT+EsciRnH5DjVFOooGhQwHMXwBZ6cuP2pQYGvtU7gs7b+CSdTi2NRnxhv8eDOjH7bzx82gU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=OiiuDVRq; arc=none smtp.client-ip=209.85.208.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="OiiuDVRq" Received: by mail-lj1-f174.google.com with SMTP id 38308e7fff4ca-2d22fa5c822so17331721fa.2; Fri, 23 Feb 2024 13:03:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708722190; x=1709326990; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=u3iU9R8t6ng+bkzwOIZP0nM+fEY42hDYQ8lo7syRMXk=; b=OiiuDVRqfO3+yqYy5fGX1OE6y7aqrCPXKTOsbFUfM7Zg6OgJ2HzIlGtvcEhqyxmLEk ji4AgD77As+wvhpzBDvEydgJ55IINmmkUyqgeVGUX2G9dl+6h/J6CFtRMdoOX5+IOVBx 60o1au/kTQdKWvPJ3cyt5jz+VlSTQ2ew1qhkD+5SoD3lZfJOrSOg7daRpdp0wypCfuzq uaq4UE68wKTj60Sk4F45yBku+fS/1TnnvqI9ESc9qQ2215wPZX/VF6gi6n1x7FBxr541 aSxJcyNrg6fpHBy7sxv+oZX0r95C6WVxEtae5dWjHKNCk5sOQOp0Zq/cOJkaIpPaT5sf pMww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708722190; x=1709326990; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=u3iU9R8t6ng+bkzwOIZP0nM+fEY42hDYQ8lo7syRMXk=; b=IoEDsKps5+lnhtekXJR04UdZjCnW5QicYtPM5vQtScRgBciP/pa84XE4cl9QaghvSS uVdA/oBX/eS8t7lNai/5vpHQsFlXiRC19V6FJjv25zceEKygQT0n7lEwBG8zTMTswizB 2etHNuIC/EqlwzI5H8e43iN4hnMtt9F7WAFyOcav5+n2mBs1jE4VhUwjY2WxLp04hAA/ PndF+q2vTV02zuOsvnIH9rz0SITr34qfzL1RaM8c9PvH/IUqvb0ph59tqF5hLkEBTPGa Bytk4+xashHKjzhiKaOQ8Dj2fyHkZX9ulwQ+xE9+CSlAnjlBlwmgWpIGWTkQyYv+HcbE 2Rbg== X-Forwarded-Encrypted: i=1; AJvYcCWfN+XOMtCnEWMD7JeNgvGB5Jhau88l1UTbtmagNzqLjBZmL0ih+aXXgjz7t/tdxzwdz5B750YZMNcK59mq1YLgu9vL7Ex8ZQHMaude X-Gm-Message-State: AOJu0YxvKO1zdmKmsmYcCCOf8e8vW3Quf0+Ozl62Yjry3Yrq3rnsg4Yd 0Bv+Zh0zCpBUSv3CQj+dQxpcS5DTYgg6VKf5HFxXOGkXngy5Xj/LDOwz93H9CjM= X-Google-Smtp-Source: AGHT+IHVV2y64jRVCacDLEUV+u1xPRhTkyOMvdB8LkVI3WkOF0Ffmnp1ZpGOuI3DJBOG4YKt6gV4gw== X-Received: by 2002:ac2:5fef:0:b0:512:99c2:dfa with SMTP id s15-20020ac25fef000000b0051299c20dfamr552215lfg.42.1708722189978; Fri, 23 Feb 2024 13:03:09 -0800 (PST) Received: from WBEC325.dom.lan ([185.188.71.122]) by smtp.gmail.com with ESMTPSA id st11-20020a170907c08b00b00a3e559aaff9sm6185424ejc.29.2024.02.23.13.03.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Feb 2024 13:03:09 -0800 (PST) From: Pawel Dembicki To: netdev@vger.kernel.org Cc: linus.walleij@linaro.org, Pawel Dembicki , Andrew Lunn , Florian Fainelli , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Claudiu Manoil , Alexandre Belloni , UNGLinuxDriver@microchip.com, Russell King , linux-kernel@vger.kernel.org Subject: [PATCH net-next v5 16/16] net: dsa: vsc73xx: start treating the BR_LEARNING flag Date: Fri, 23 Feb 2024 22:00:46 +0100 Message-Id: <20240223210049.3197486-17-paweldembicki@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240223210049.3197486-1-paweldembicki@gmail.com> References: <20240223210049.3197486-1-paweldembicki@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This patch implements .port_pre_bridge_flags() and .port_bridge_flags(), which are required for properly treating the BR_LEARNING flag. Also, .port_stp_state_set() is tweaked and now disables learning for standalone ports. Disabling learning for standalone ports is required to avoid situations where one port sees traffic originating from another, which could cause invalid operations. Signed-off-by: Pawel Dembicki --- v5: - introduce patch drivers/net/dsa/vitesse-vsc73xx-core.c | 41 ++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 6 deletions(-) diff --git a/drivers/net/dsa/vitesse-vsc73xx-core.c b/drivers/net/dsa/vites= se-vsc73xx-core.c index 8dc366461b9c..3b312799cf66 100644 --- a/drivers/net/dsa/vitesse-vsc73xx-core.c +++ b/drivers/net/dsa/vitesse-vsc73xx-core.c @@ -1590,6 +1590,31 @@ static int vsc73xx_tag_8021q_vlan_del(struct dsa_swi= tch *ds, int port, u16 vid) return vsc73xx_update_vlan_table(vsc, port, vid, false); } =20 +static int vsc73xx_port_pre_bridge_flags(struct dsa_switch *ds, int port, + struct switchdev_brport_flags flags, + struct netlink_ext_ack *extack) +{ + if (flags.mask & ~BR_LEARNING) + return -EINVAL; + + return 0; +} + +static int vsc73xx_port_bridge_flags(struct dsa_switch *ds, int port, + struct switchdev_brport_flags flags, + struct netlink_ext_ack *extack) +{ + if (flags.mask & BR_LEARNING) { + struct vsc73xx *vsc =3D ds->priv; + u32 val =3D flags.val & BR_LEARNING ? BIT(port) : 0; + + return vsc73xx_update_bits(vsc, VSC73XX_BLOCK_ANALYZER, 0, + VSC73XX_LEARNMASK, BIT(port), val); + } + + return 0; +} + static int vsc73xx_port_bridge_join(struct dsa_switch *ds, int port, struct dsa_bridge bridge, bool *tx_fwd_offload, @@ -1706,19 +1731,21 @@ static void vsc73xx_refresh_fwd_map(struct dsa_swit= ch *ds, int port, u8 state) static void vsc73xx_port_stp_state_set(struct dsa_switch *ds, int port, u8 state) { + struct dsa_port *dp =3D dsa_to_port(ds, port); struct vsc73xx *vsc =3D ds->priv; - u32 val; + u32 val =3D 0; + + if (state =3D=3D BR_STATE_LEARNING || state =3D=3D BR_STATE_FORWARDING) + val =3D dp->learning ? BIT(port) : 0; + + vsc73xx_update_bits(vsc, VSC73XX_BLOCK_ANALYZER, 0, + VSC73XX_LEARNMASK, BIT(port), val); =20 val =3D (state =3D=3D BR_STATE_BLOCKING || state =3D=3D BR_STATE_DISABLED= ) ? 0 : BIT(port); vsc73xx_update_bits(vsc, VSC73XX_BLOCK_ANALYZER, 0, VSC73XX_RECVMASK, BIT(port), val); =20 - val =3D (state =3D=3D BR_STATE_LEARNING || state =3D=3D BR_STATE_FORWARDI= NG) ? - BIT(port) : 0; - vsc73xx_update_bits(vsc, VSC73XX_BLOCK_ANALYZER, 0, - VSC73XX_LEARNMASK, BIT(port), val); - /* CPU Port should always forward packets when user ports are forwarding * so let's configure it from other ports only. */ @@ -1740,6 +1767,8 @@ static const struct dsa_switch_ops vsc73xx_ds_ops =3D= { .port_setup =3D vsc73xx_port_setup, .port_enable =3D vsc73xx_port_enable, .port_disable =3D vsc73xx_port_disable, + .port_pre_bridge_flags =3D vsc73xx_port_pre_bridge_flags, + .port_bridge_flags =3D vsc73xx_port_bridge_flags, .port_bridge_join =3D vsc73xx_port_bridge_join, .port_bridge_leave =3D vsc73xx_port_bridge_leave, .port_change_mtu =3D vsc73xx_change_mtu, --=20 2.34.1