From patchwork Tue Feb 13 22:03:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pawel Dembicki X-Patchwork-Id: 13555774 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-ej1-f45.google.com (mail-ej1-f45.google.com [209.85.218.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 10BA16217F; Tue, 13 Feb 2024 22:04:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707861902; cv=none; b=ipKMfI2ucwY7kPXyvrk1aGVt05wunZuwSHDIaXwCUJESUQqIGCpuPWW85OethdYQ1NReRdzbZEGbSAxQdN0UhiUNTetowgsNHMCk2oEniRRFSpXWuxT3IjWVbP2ZDmRyPu+5i5XeWAcEPMa3PSZ4VbuPGsnUl1nwZgNv3kR4lxg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707861902; c=relaxed/simple; bh=yNXlZ++7NAGaOX0YYjxHAN+47k2zU7Fw/VvDET7htxY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=BmgwyV5A8cCsfEge+beTXBVN8eUBDTTqIt6x3A5CGBfKuTY33WjLc1GTF8M5sLH9lc9J1h3LkScHZYbZ3umUtpxdFJuuCOHqzn7x9zhXzQLBWemBImZsIiPKFDLTyLPm1F68g+OfW6noSg988oY9HBmSwrD7VJSKopxZIyiqWJE= 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=jXwLVOO6; arc=none smtp.client-ip=209.85.218.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="jXwLVOO6" Received: by mail-ej1-f45.google.com with SMTP id a640c23a62f3a-a3c1a6c10bbso421905266b.3; Tue, 13 Feb 2024 14:04:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707861898; x=1708466698; 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=silDmACUiIN4OlWaMhBDDBG9aJpm66HeXuSytRzPWjU=; b=jXwLVOO6EOauyFKCsoWBBdPtHNxyhAYfovuE8UflP7BObmCfpNI1v7sOQAJLEPj8s9 Oba80e+noQlVz1a9oWnTOSdO+5TZJb7bUN39nFrBUtTJMk9YQTU7fMxEopEJgrO6r4f8 wbFLmWWn6lvXo1HrJisq4CfslYGqnYg2z5J0cb1EcLUDPyBr/MeA+b1EbIqHtNhnxhh+ XASmlWZazy15XVzWXdBrtX0OengYrnY9BdSs9VxFx0xUSSxTqRwqBq+KqDbsqq1TtXy3 7cbsyw2oEPfm69BSY2JQy9rGr/0gL8jKqaILwMASEOnH9q49dbY2Oc+JxtDrZQurYc7S qlzA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707861898; x=1708466698; 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=silDmACUiIN4OlWaMhBDDBG9aJpm66HeXuSytRzPWjU=; b=VejM2BBvn3mUeI7kPl/x+AmCCmOd/Pu9IU8+mzBdSkr9oPiz2Pjb4xK5gGpf2IGdM+ RvygogrHGixEKcCdy4oMqVUd/KGTPldOx/ckFy5M4vxL+auHyZE1uL2fqW6j3Zs7Dy9J 9Z/vGdJyrwBINYNd23ow7neDHJHcYGmhJpFyrtWLdw72v+KikfuMyBcvMslFHLUVSryW ErnWEum+JceEZxq6VNGwoOEETy/egPSQIbKPPYG62dTjPXmHOQu21srtofALyjORNhOQ lo6Ad1IC2LNGaQCvh1QfsQ5ZJW6eon4Os79Y5CT0Sdce+9z6Tl2pgozYI5NBqOUL8C4p ylBQ== X-Forwarded-Encrypted: i=1; AJvYcCW5ixz+1kLO/h/FD+RcMQpXSciQA8raUm3Yo9ZHLZ4ZWW8vH2ljYFqlvoynATHi5SAHv3duwoEOXl+O/7acgsRruVlet6aIFcvURotH X-Gm-Message-State: AOJu0YxSK/XlVSMyNKXjUgo8tCvWZykU6vhW3aXtCXql9GUhg8fct0ei 9Gzc5g6wxNgxK8KRhwNcECWJhDyfsbvsTHIYSL2/nAGWLQgONDPofEsh1EnnYJ4= X-Google-Smtp-Source: AGHT+IEAUz4HcNtgkz4NzDAJ0SL5yOtJ53J5yjTRwaNv+NCAJBjyyzDAgo+kvdqTr7SoncmTgvu+8g== X-Received: by 2002:a17:906:3942:b0:a39:6c07:d31c with SMTP id g2-20020a170906394200b00a396c07d31cmr421164eje.25.1707861897737; Tue, 13 Feb 2024 14:04:57 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCW2XgLzqsfLyjsePJy8TDVdmG1U/m0sZ2DzjH2daoQnPowSsVcGQ6863Gp850N7ma9gdoUnjdSurb74OPKWC+WV/3vEH5gVhcoqgKTJb4cXdn9J8VAuZNw8c4TKVbo08QGtvvRqNGyAQIPB9aXd7RGYZ/5hD1MlqnjRF90+6v3Nxo4rE+EiWw7ZlA6ZabpArjDY1G0Vo/G9lbSNZzW7M3cDPE8G3BrdJXfHDN01JWQ31UQ3+LnoSuS4yMR+Fu9l6KwB98eg4Y/VDfvfrcZ3ZdaCN+eQr4NByJAqnDk+I7SL4O+3Wk+IjgBh/rUBBV93GB3BGS1IBG/LxqbImiRXmegYczs7ZoBfFTjP2lT0n7Yd7U0c3KaCbsg7aFt7t3kMfvLxPRIU9wPKMEBszbKj0xVqThhLrn6sqHqWTsOTVsW9ErEWzkdNO2KyfXs6IQmekXXr5t/Lsvr6Dw== Received: from WBEC325.dom.lan ([185.188.71.122]) by smtp.gmail.com with ESMTPSA id p12-20020a170906b20c00b00a3bdf8ae86asm1706800ejz.10.2024.02.13.14.04.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Feb 2024 14:04:57 -0800 (PST) From: Pawel Dembicki To: netdev@vger.kernel.org Cc: linus.walleij@linaro.org, Pawel Dembicki , Russell King , Andrew Lunn , 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 v4 01/15] net: dsa: vsc73xx: use read_poll_timeout instead delay loop Date: Tue, 13 Feb 2024 23:03:14 +0100 Message-Id: <20240213220331.239031-2-paweldembicki@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240213220331.239031-1-paweldembicki@gmail.com> References: <20240213220331.239031-1-paweldembicki@gmail.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org This commit switches delay loop to read_poll_timeout macro during Arbiter empty check in adjust link function. As Russel King suggested: "This [change] avoids the issue that on the last iteration, the code reads the register, test it, find 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." It also remove one short msleep delay. Suggested-by: Russell King Signed-off-by: Pawel Dembicki Reviewed-by: Andrew Lunn Reviewed-by: Linus Walleij Reviewed-by: Florian Fainelli --- v4: - Resend patch v3: - Add "Reviewed-by" to commit message only v2: - introduced patch drivers/net/dsa/vitesse-vsc73xx-core.c | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/drivers/net/dsa/vitesse-vsc73xx-core.c b/drivers/net/dsa/vitesse-vsc73xx-core.c index ae70eac3be28..8b2219404601 100644 --- a/drivers/net/dsa/vitesse-vsc73xx-core.c +++ b/drivers/net/dsa/vitesse-vsc73xx-core.c @@ -779,7 +779,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 = 10; + int ret, err; dev_dbg(vsc->dev, "port %d: went down\n", port); @@ -794,19 +794,16 @@ static void vsc73xx_adjust_link(struct dsa_switch *ds, int port, VSC73XX_ARBDISC, BIT(port), BIT(port)); /* 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 == 0) { - dev_err(vsc->dev, - "timeout waiting for block arbiter\n"); - /* Continue anyway */ - break; - } - } + ret = read_poll_timeout(vsc73xx_read, err, + err < 0 || (val & BIT(port)), + 1000, 10000, 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, From patchwork Tue Feb 13 22:03:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pawel Dembicki X-Patchwork-Id: 13555775 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-ej1-f41.google.com (mail-ej1-f41.google.com [209.85.218.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 4433163CAE; Tue, 13 Feb 2024 22:05:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707861913; cv=none; b=A+JD9rRxdmsl6y7Hmq4QnuMGKfFUalPSTDiDLjK/K5bF4u29xDUXyQMbhEjGcl+IbtNQxbA9Htid3f1dKaZ3LZ0u3pA9mDedhrM0EvFkMPJgPUkIYdk52B03kUDfU2CC5y0KlkXFFFtXQ6nAiYWOODzk9VRC6H4/OIBbX6gZnkI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707861913; c=relaxed/simple; bh=yEjRlTeHU1w+2Rf1F1hrkdWRrgjpz55T4ZpfkZoGlaQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=jbMtCzeizoNoojH5KcKm7QNCH+oYWWwW5mTV9G8iUpGV5cUkbfAweaHVKPYgMKJv3GLG6JwX+iH3bCi4Sgz9PRVvlojhXVeCSyaIJkA+oeiCtZyBFLeF+oQL6jsuB7zNtz9vPpo3Z+2DVT1G0IXTkaonlCsqhcUAvgL5lHpZ1Ss= 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=gxdjuzuT; arc=none smtp.client-ip=209.85.218.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="gxdjuzuT" Received: by mail-ej1-f41.google.com with SMTP id a640c23a62f3a-a38271c0bd5so614416566b.0; Tue, 13 Feb 2024 14:05:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707861909; x=1708466709; 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=t+zX7GM3eAspifd077YFCj/xmWH5BRFUvp0tC1IJz9E=; b=gxdjuzuTEGGixzOeeP4oM05vDcISJb2G73eBoChC5ZmR+KT9KtKW4itpjTLKdkQvzX Cr+sgX1WMOKHhxWSS8IvqRsV0VffGSeBQBId9rgZj39ucKn8SZmpKAsE/aJTZe3PFKnP 9G/TfLUDahWPbP/x6SBGF6Gei82Epx4zCUcxJaNq/YHbHD8bk9U5AXRu627Lzvw1blvo hbhr6wFLK4QAPYmqE4PtDcOU5vI5zHxIaRjm1EEzuyyOeVDAfBP1G/+0XxpLuQQlerJ1 qdEwGW/mhsPXnZaLJ9txaBWoy1YTI45q1pt3hbAdQN8lu9FB43P0BgMoDWkfwlZ7lYFs YKBg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707861909; x=1708466709; 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=t+zX7GM3eAspifd077YFCj/xmWH5BRFUvp0tC1IJz9E=; b=iA4qcc4/iktyPOlyJZFE/XpSFD9Sk5YbTQ/Mml8u5f6HvSmwB7JprVZEHzLEYQakHV nXGMGU7EbdbFCslvenXW/ntX9t+xvUP4EZ6UFYeijuVwR6K37z8c1ER53+J0irigh9Cs FljV9MbRxEW/Tzo6k4HNiBtEISl355XtmHhjKetUUTManK6uNBq7Nm2pRp3fcpPV5QzH 2atAmb6ySL+zSs4HaPVfTf2OOgfqS29ydguHa338eRalMwvwqmjibhns5DpTKokHH+k4 3N25ggFS44VBFxhBtB6FbN+T7DSeoSg3mLybxXw/FV5fpK8h2TT7VwtJwXojpU+K3x9y 0wIg== X-Forwarded-Encrypted: i=1; AJvYcCUUCkceUVTWiRJEg/EFIVbNEB+fWMPmDg/iYIIycYwKTXfEZe0fPPSyEml0JfvNoEZMDjH78hqb9VILxrELu/xuzjyVsvJHHZgM1458 X-Gm-Message-State: AOJu0YwCneYLFqlXhrCih29Er8uHoC7nD/WIXZ1Kp7wmeAAm8f9mOJxP HuLsIcN7FLUzzw07GZ18pioKfONPDjTkaDOGco68tDPF9J3Oa1dbBPXM1ohe5vo= X-Google-Smtp-Source: AGHT+IF8YZI7u5V7pI003no9Snlwiu4mThhLeZNuC2zokJMUrHCwDJzYnA8U3Ah369MoRte/SX5eLQ== X-Received: by 2002:a17:906:b48:b0:a3c:2a66:3fdd with SMTP id v8-20020a1709060b4800b00a3c2a663fddmr468714ejg.17.1707861909047; Tue, 13 Feb 2024 14:05:09 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCVxab9q2Y7PMVWEI1uQzcxkyJ4b96TTuLVgetSUhnge+w5ZEiDsgQoHfSmgLj2EYKWIDOJIAvEMajitC16MMTuQV380mMKdQwx3Bkag3T/awAGelohkmko7dQ6FOVkQMr9RttqFcZceB9ahxnmBYXn4cPd47pGfhqX5kESV4ro1UjFkURP5ichApsexC2qbQHU6LuPViJf9Bpf9jRR4HMopG7PAwp1QrF4CemBWrWSwxOjahKAizXYaFMXZFvhkbHdP0JbRHdbSvQhNW5OB/Dve+NcMAPfUgRcTLHgsC4Hcq82ed0WNHeVcklY7HolPWri8Gl9Y46TgC08tumGuZ35CL86/yoJZxtIuSKuVJAPUC+0fi/wvCz4R3uaLK+XKSIOEcL4e6oKd8tBDHWep1HqAnHyqFFu2pqh5Qjd1wgm4gFgXtJgUMKD7TxVnY98HTRCsYUdELm+RxA== Received: from WBEC325.dom.lan ([185.188.71.122]) by smtp.gmail.com with ESMTPSA id p12-20020a170906b20c00b00a3bdf8ae86asm1706800ejz.10.2024.02.13.14.05.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Feb 2024 14:05:08 -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 v4 02/15] net: dsa: vsc73xx: convert to PHYLINK Date: Tue, 13 Feb 2024 23:03:15 +0100 Message-Id: <20240213220331.239031-3-paweldembicki@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240213220331.239031-1-paweldembicki@gmail.com> References: <20240213220331.239031-1-paweldembicki@gmail.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org 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 Reviewed-by: Linus Walleij Signed-off-by: Pawel Dembicki --- 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 | 166 +++++++++++-------------- 1 file changed, 72 insertions(+), 94 deletions(-) diff --git a/drivers/net/dsa/vitesse-vsc73xx-core.c b/drivers/net/dsa/vitesse-vsc73xx-core.c index 8b2219404601..70dd3f96dafb 100644 --- a/drivers/net/dsa/vitesse-vsc73xx-core.c +++ b/drivers/net/dsa/vitesse-vsc73xx-core.c @@ -714,8 +714,7 @@ static void vsc73xx_init_port(struct vsc73xx *vsc, int port) } static void vsc73xx_adjust_enable_port(struct vsc73xx *vsc, - int port, struct phy_device *phydev, - u32 initval) + int port, u32 initval) { u32 val = initval; u8 seed; @@ -753,12 +752,11 @@ static void vsc73xx_adjust_enable_port(struct vsc73xx *vsc, VSC73XX_MAC_CFG_TX_EN | VSC73XX_MAC_CFG_RX_EN); } -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 = ds->priv; - u32 val; - /* Special handling of the CPU-facing port */ if (port == CPU_PORT) { /* Other ports are already initialized but not this one */ @@ -774,101 +772,79 @@ static void vsc73xx_adjust_link(struct dsa_switch *ds, int port, VSC73XX_ADVPORTM_ENA_GTX | VSC73XX_ADVPORTM_DDR_MODE); } +} - /* This is the MAC confiuration that always need to happen - * after a PHY or the CPU port comes up or down. - */ - 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 = read_poll_timeout(vsc73xx_read, err, - err < 0 || (val & BIT(port)), - 1000, 10000, 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); +static void vsc73xx_phylink_mac_link_down(struct dsa_switch *ds, int port, + unsigned int mode, + phy_interface_t interface) +{ + struct vsc73xx *vsc = ds->priv; + int ret, err; + u32 val; - return; - } + /* Disable RX on this port */ + vsc73xx_update_bits(vsc, VSC73XX_BLOCK_MAC, port, + VSC73XX_MAC_CFG, + VSC73XX_MAC_CFG_RX_EN, 0); - /* Figure out what speed was negotiated */ - if (phydev->speed == 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 == PHY_INTERFACE_MODE_RGMII) - val = VSC73XX_MAC_CFG_1000M_F_RGMII; - else - val = VSC73XX_MAC_CFG_1000M_F_PHY; - vsc73xx_adjust_enable_port(vsc, port, phydev, val); - } else if (phydev->speed == SPEED_100) { - if (phydev->duplex == DUPLEX_FULL) { - val = VSC73XX_MAC_CFG_100_10M_F_PHY; - dev_dbg(vsc->dev, - "port %d: 100 Mbit full duplex mode\n", - port); - } else { - val = 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 == SPEED_10) { - if (phydev->duplex == DUPLEX_FULL) { - val = VSC73XX_MAC_CFG_100_10M_F_PHY; - dev_dbg(vsc->dev, - "port %d: 10 Mbit full duplex mode\n", - port); - } else { - val = 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 { + /* Discard packets */ + vsc73xx_update_bits(vsc, VSC73XX_BLOCK_ARBITER, 0, + VSC73XX_ARBDISC, BIT(port), BIT(port)); + + /* Wait until queue is empty */ + ret = read_poll_timeout(vsc73xx_read, err, err < 0 || (val & BIT(port)), + 1000, 10000, false, vsc, VSC73XX_BLOCK_ARBITER, + 0, VSC73XX_ARBEMPTY, &val); + if (ret) dev_err(vsc->dev, - "could not adjust link: unknown speed\n"); - } + "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); +} + +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 = ds->priv; + u32 val; + + if (speed == SPEED_1000) + val = VSC73XX_MAC_CFG_GIGA_MODE | VSC73XX_MAC_CFG_TX_IPG_1000M; + else + val = VSC73XX_MAC_CFG_TX_IPG_100_10M; + + if (interface == PHY_INTERFACE_MODE_RGMII) + val |= VSC73XX_MAC_CFG_CLK_SEL_1000M; + else + val |= VSC73XX_MAC_CFG_CLK_SEL_EXT; + + if (duplex == DUPLEX_FULL) + val |= VSC73XX_MAC_CFG_FDX; /* Enable port (forwarding) in the receieve mask */ vsc73xx_update_bits(vsc, VSC73XX_BLOCK_ANALYZER, 0, VSC73XX_RECVMASK, BIT(port), BIT(port)); + vsc73xx_adjust_enable_port(vsc, port, val); } static int vsc73xx_port_enable(struct dsa_switch *ds, int port, @@ -1055,7 +1031,9 @@ static const struct dsa_switch_ops vsc73xx_ds_ops = { .setup = vsc73xx_setup, .phy_read = vsc73xx_phy_read, .phy_write = vsc73xx_phy_write, - .adjust_link = vsc73xx_adjust_link, + .phylink_mac_config = vsc73xx_phylink_mac_config, + .phylink_mac_link_down = vsc73xx_phylink_mac_link_down, + .phylink_mac_link_up = vsc73xx_phylink_mac_link_up, .get_strings = vsc73xx_get_strings, .get_ethtool_stats = vsc73xx_get_ethtool_stats, .get_sset_count = vsc73xx_get_sset_count, From patchwork Tue Feb 13 22:03:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pawel Dembicki X-Patchwork-Id: 13555776 X-Patchwork-Delegate: kuba@kernel.org 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 0204B65BD4; Tue, 13 Feb 2024 22:05:16 +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=1707861918; cv=none; b=bJ3tIVF+fdSPVPVGnlrm4RNdMNAnGCJkx/N+dFsijnFHYoOn/eimto7vo+sNyyiBxhJu34Ni4m+/uzvBwf5n8B2wf3E+1Betr3RhRN4pra29GsPzLtQGHZXi06jEtx329NDO0+gM6ev9/9ZeQB5AqY7NzYENZvnKNAOyjKKyQwg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707861918; c=relaxed/simple; bh=FviLzxC93cNJ3wmxI/f91VZvhamslfx9I/NMWZYtlMY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=COa5Ss6g9CMuDqTkAM3wNZaAWKguJ1zPORnvN/QtA83CBR57LKzq2RWZbDobmvuVnmfRejhk30Sa3qob2ZcYgjgbg5IN+2gxEkvPzJ3/StWf9rNWLZVmhlN98Upgo1Z12uPYrjNYXtd5ihOH337oUw+S7UYERD+vPyXt/dT9oPI= 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=j23q4WKU; 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="j23q4WKU" Received: by mail-ej1-f53.google.com with SMTP id a640c23a62f3a-a26f73732c5so684193266b.3; Tue, 13 Feb 2024 14:05:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707861915; x=1708466715; 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=uozxI0Ib0yVJTDnCXOq5igCfB80aUVjda0znERTIFFE=; b=j23q4WKUwqMmPV2QUR8RXJeQsuj3NiOBfqfsBSw+xnPo2V9WolfCyN3X7RyWhCoC5o hshCUHc3GFUtrAz2Wh9KMrh4QVDBhHm9HhBt8W3bB/GLotgiz8n4lY0nsUoFUhZSgo0r 1Bgi8fy8wvHr4NQRvF6Jf2+Fx0KQHqtYt4wDbjT0riKkBut6TEM6hv6Omfs8InBmalmb m32c9rrwCmqnqmThu2c8M6DbuOAlrcvCSXb9B98/OuUeIPbczijSPK1CPxVNOlW0Cq9T 9I90z/z5P5vbdYBYxpbMKnM3Ga5Em21TJZLm4y/gxFgSjDaMBiWRN17oA1W6odOQHc6u GPVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707861915; x=1708466715; 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=uozxI0Ib0yVJTDnCXOq5igCfB80aUVjda0znERTIFFE=; b=g4LV/+W5VTIQWwRs7S2Z1hf2SO7BMXYmEnckuR74YygT4sQ7ATtiEqWTdTSkYU+ISq 6nAL9lhMlgrmK+5vInqvpz2AQYfjQF9Zg9hFzU+j5c3clohv6/Edz3KPw8KU7JXJllEO iDsKPqqAWfEC8zamTZdbTdThy9IGuVk9ixs+x1eREQeBdMO3CqxxzOTC/z2bammJSJHD +RiyaIWXKFnKcKsfdWEcfNhXet6I8TtIRbLxM+d77bNWOpzjjXWT/Dsfy1FifsMXninY bNdej02bWBFuAs6IijW7jaaZ7/2N9qQ4tRHDtxJz6FILsoNZ0oflT+auh1WRUfSn0rPD 4xiQ== X-Forwarded-Encrypted: i=1; AJvYcCVR1NzGl1ikVvhiLvsqu6VV5wBNAG1olWOF8OJLjMN7Ly1w/kxRBanMvqzrF2P8X11VrYpYAjuaqsxsADUQyysfdBJRZ2fG9c5zwcKB X-Gm-Message-State: AOJu0YxFF8YQEElb82NspRH6FWeN3CbyepNrPDPp8FcPdYEG0GFn3LrT PAkUaC87Hm8NP18ZYC9CX6AMYJ0Fd4K+IX57En+VdnajPUJaAxQQqQWzYRTRJpg= X-Google-Smtp-Source: AGHT+IEsLT5ZmumCphHvUsOMYimWlg1IWDWGmxreejX4jzAN24AE1UqfsPshz8iZ1nGpKnOMe43F6Q== X-Received: by 2002:a17:906:3c53:b0:a3d:1f59:7410 with SMTP id i19-20020a1709063c5300b00a3d1f597410mr361105ejg.22.1707861914895; Tue, 13 Feb 2024 14:05:14 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCWcCp1Wq7upm9RDN2iKLObnLHXNsKYL/nEZ/usmgnU7yyegCtOARknmFzDEK6SbUX/A2DG/aT+hY0hSHKqCk5e/ZaDm2/r4O3andE+IoxSnxgMv0bGPH+PD2qzXbYCFXt5WqM7IA1TduCqYiNiqG58yFm01mP7ROLXVfXkX8EKaXHqtcdDejp4K5nISuZAu/18yMn1KcydiQvLJ+zPkyHRYp9wmBnT0I8P2pgUicieEimz8C6oPpIXuJIiX/7vDLjF3YSgZF7at1uI0LHX5QCotjR7TH3NY6Y+ztLYdvRCyiHXHBDpptWmz8jCzg/L9tR2IGCp7EuLBRdtF6hegwQfke2+010fYHxpeZ3UAu7leN0Rb3v2R2O3L3mOZwQS+g+aIIJ3V2+6Ta8rEHOrrrZ8GpUVR97WZ0vk4mLp/fSRKqvsw7hDkTKD9QXVmBaObDcPqjl8W0EoVZA== Received: from WBEC325.dom.lan ([185.188.71.122]) by smtp.gmail.com with ESMTPSA id p12-20020a170906b20c00b00a3bdf8ae86asm1706800ejz.10.2024.02.13.14.05.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Feb 2024 14:05:14 -0800 (PST) From: Pawel Dembicki To: netdev@vger.kernel.org Cc: linus.walleij@linaro.org, Pawel Dembicki , Russell King , Andrew Lunn , 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 v4 03/15] net: dsa: vsc73xx: use macros for rgmii recognition Date: Tue, 13 Feb 2024 23:03:16 +0100 Message-Id: <20240213220331.239031-4-paweldembicki@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240213220331.239031-1-paweldembicki@gmail.com> References: <20240213220331.239031-1-paweldembicki@gmail.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org 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 --- 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/vitesse-vsc73xx-core.c index 70dd3f96dafb..5b54823b2caa 100644 --- a/drivers/net/dsa/vitesse-vsc73xx-core.c +++ b/drivers/net/dsa/vitesse-vsc73xx-core.c @@ -833,7 +833,7 @@ static void vsc73xx_phylink_mac_link_up(struct dsa_switch *ds, int port, else val = VSC73XX_MAC_CFG_TX_IPG_100_10M; - if (interface == PHY_INTERFACE_MODE_RGMII) + if (phy_interface_mode_is_rgmii(interface)) val |= VSC73XX_MAC_CFG_CLK_SEL_1000M; else val |= VSC73XX_MAC_CFG_CLK_SEL_EXT; From patchwork Tue Feb 13 22:03:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pawel Dembicki X-Patchwork-Id: 13555777 X-Patchwork-Delegate: kuba@kernel.org 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 27C9669977; Tue, 13 Feb 2024 22:05:22 +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=1707861924; cv=none; b=GjM0MMfMObdtbVf6+cBzSRWyInXwEfXn7Tu4LHEwi+SCckCCLp/qRQ9FYYdvGBmZ5lT9tUP/IVC2s+bPR1QgLkzS6aJsvwpT+Y4feofgXT8MhHr4RadtOnfK7QbDSeKIaahMZcL8uOCBj7ATOLmrs2dL21XjgiceaD5Julf/Jck= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707861924; c=relaxed/simple; bh=3t1Kl6TYhkuyHwRDe3nM2rQAkK7+PieqY3Q/E3QLm3I=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=qGyXDfC5SrOLbYbu2l73e8w5I0guI3l5KtJVDyqdA4BwiHmL+B0e9k9k1eRx8wE6GjVThPjPW4ccCflYdaOqujzG2XZ87WmlXgVOlWvdK4K3BZqFxmf6lSVlOJYHFH60rrih7iLSpZI0v06g/qEbkf0x77av8/v6yHs6uI1+wag= 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=CEwulULg; 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="CEwulULg" Received: by mail-ej1-f51.google.com with SMTP id a640c23a62f3a-a30e445602cso39427566b.0; Tue, 13 Feb 2024 14:05:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707861921; x=1708466721; 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=IvolxYsZq35+Fn0h+5+hh11SNg9vPDU7l0RYp5KmkEI=; b=CEwulULgXDZGZXyPrcWn8vs62xrrHidBLR0q3goP2XxxZGg6jUWzIkY4LH1+A20aON Gz/4/V0DUuJ7odnzvc7O+vbbukX2kfn8lcLEXvh5ftHLIyQGMCMde3HuMEsU8t4UiOpI dpQ/mIEKVM9Y6vdJIuDRxb9SBVnFY6dgiSgc+BRDygnczHGyJcPrcCUePPjUX3XHTI6Z y+Frgwsb1Pq9+BnnvMNyrItmfzetA/FBKahDuxLaiY0OSuFpLgTtgVfh7qDPagjwmlAS CDYEx+iy1bcTkF45eZIyR2GIvNTMqEk4Onv6GJ0oJzZF4VuetsRV12+jzwT5V8YwsOmE 7dew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707861921; x=1708466721; 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=IvolxYsZq35+Fn0h+5+hh11SNg9vPDU7l0RYp5KmkEI=; b=R6BYY+ThJAYrIPO70FUsnrmx+dKaf4s3+u4RMMj3jdzboLzYeieHnFEKqUT48TA4He mZE/lConWYW24iA/MrajAc6lzyoSKo7RSZdiNcToy+kuWT1/cZHm15RlUsEhysNaVBUa UvZuD5cQmDyGTEv+McC9zmsZZzEm3HCNB2e22EuOxrvhXcj8x5so+gs5Xm4zdGNwSIaX c5IOSRcWn7UlPlJRhB7VLYDll5lNIfwwVaZDyFuPYedmWSGFOXPQRS0aukEaP8R/pJPr zfYuY/Wb0IeM9OFPGDc8TRKBhU3zegG8J86ZPhFeo417d8i+x1jj2iwq1JxCcOxlP2sm u3mw== X-Forwarded-Encrypted: i=1; AJvYcCWTLiv+SKwF5JtiEJXxWw368fdUqJdrz7p2NXzBYCIt9dG2PBwo8XgLn+YhQjpW3y2sRH/2Yntt6lWjAIAVt5A/Q+/Et4VLR8jbo2IA X-Gm-Message-State: AOJu0YzEP7FBMgBZAjPFouhmtvWXSCJt2aZSDcRD/s0VveeNTJselrR6 ztkrhlMByjd6ks39B+DhcV2tBUdnEw14qdlwjMD1CI/u30hmGUjb3SiFOYPqfYs= X-Google-Smtp-Source: AGHT+IGyDOecV6Z2nG34ilSgMgSfvDEstY46UiUC2WF10L5OzK+mysKeUMQuQxzaKOxFsOnDsFoKHA== X-Received: by 2002:a17:907:b0a:b0:a3c:ce90:bf4 with SMTP id h10-20020a1709070b0a00b00a3cce900bf4mr106000ejl.14.1707861921264; Tue, 13 Feb 2024 14:05:21 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCUJ+xfKI6chSg1/+NaWuZbzmedeh2L/Nvbd4R6B/qMEO8UVHSk1VJa4HjP39iZqMZsiiOtMGwYrvy1HG05rQUnDQpSJbJpa1ckRJlEWreZlfsRRA02spfdrtR7z7YY0vEACjTUc6CCFa5QLJsPiL+1UD5ygLjwJPHvDzGmYYEcnLGoGKxfSZZ6G7pCEluO7GeJneq+rnf9ZCq2wa+QvYHwoFKLIzm/bv1k0EflEahhIQtulx9X4ADNbA0WWcRcNT/Dl0QpKw47bN4qr9S68OoZdi5M3HoKPx+fzw3qq13Ttnu5OsutomEGLJBjfxMHCfAESEdlzcvRZuXqx/pg8f/GuWcKR/wAO2krUdva3P56rrNi8s5UCEwFO44KhgLZAHyfVOijgmHM94FoPVBgUZPL/kS+WSVAJ8j/4HmaW0sXxq/EKgD63gfgrxs2T4aHEEoy/nJ0HGOQSIw== Received: from WBEC325.dom.lan ([185.188.71.122]) by smtp.gmail.com with ESMTPSA id p12-20020a170906b20c00b00a3bdf8ae86asm1706800ejz.10.2024.02.13.14.05.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Feb 2024 14:05:20 -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 v4 04/15] net: dsa: vsc73xx: Add define for max num of ports Date: Tue, 13 Feb 2024 23:03:17 +0100 Message-Id: <20240213220331.239031-5-paweldembicki@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240213220331.239031-1-paweldembicki@gmail.com> References: <20240213220331.239031-1-paweldembicki@gmail.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org 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: Linus Walleij Reviewed-by: Florian Fainelli Reviewed-by: Vladimir Oltean --- 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/vitesse-vsc73xx-core.c index 5b54823b2caa..75597daaad17 100644 --- a/drivers/net/dsa/vitesse-vsc73xx-core.c +++ b/drivers/net/dsa/vitesse-vsc73xx-core.c @@ -1170,23 +1170,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]); - /* 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 = devm_kzalloc(dev, sizeof(*vsc->ds), GFP_KERNEL); if (!vsc->ds) return -ENOMEM; vsc->ds->dev = dev; - vsc->ds->num_ports = 8; + vsc->ds->num_ports = VSC73XX_MAX_NUM_PORTS; vsc->ds->priv = vsc; vsc->ds->ops = &vsc73xx_ds_ops; diff --git a/drivers/net/dsa/vitesse-vsc73xx.h b/drivers/net/dsa/vitesse-vsc73xx.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 +/* 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 nonexistent ports. + */ +#define VSC73XX_MAX_NUM_PORTS 8 + /** * struct vsc73xx - VSC73xx state container */ From patchwork Tue Feb 13 22:03:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pawel Dembicki X-Patchwork-Id: 13555778 X-Patchwork-Delegate: kuba@kernel.org 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 3359469D1A; Tue, 13 Feb 2024 22:05:32 +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=1707861933; cv=none; b=K7AwKdrHtkqhPBdFTeC9MJ5bIStChuJAIiTFI740WHLT6tWGDeWmVGKLM+Ps53QxAy2ceGZeuEyqAEytZ2q05KX8BVK0IkpPqRcL11LFOHIcFrxhPttvDzndDIokSZJpbOpHpCN79sKOeP8EJ7LvbQnRZHCCgCA0D0m9fq4y/10= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707861933; c=relaxed/simple; bh=1fo9tqK0gVYT3dua0dTYP+mwom4X6HUKZw4ewOhVpTk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=mc0TLr1+n143WAmECUEh+BEE5HNXRBeA5rf8YoSHISiLNQW+MRtmGCzMpVWVOw1QKIRYhkKZL1W2sEfE/d8He0h2vJ7ZIESZjuzWSXX8g42Iwtn8eisYiNsTBdHspFOKrVyxE66dPUUpTpngm6IOBe8LLUvxwaYK/G5ncG8m8OY= 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=HI5B9SAR; 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="HI5B9SAR" Received: by mail-ej1-f53.google.com with SMTP id a640c23a62f3a-a3be744df3fso514014966b.0; Tue, 13 Feb 2024 14:05:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707861930; x=1708466730; 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=B9TYnreC1cjtgZPE9uArnAlQVNsjfWDdo5XqTKM9rnk=; b=HI5B9SAR3QRF52LQLQjRH9JiSAmXihtv0RB1AbEjyw+7e1eXLK4AYl3IsK+VNgELN/ DOfawtC22Va5yfqxE7K4CuZZNKnP7K0x4deh6pdCtt8rLZyI7D/tyxPiP23wGDgxMyLj dxYEesKxZ14KpYFqqoboBnCjgmkH1Kjt9mhk1Ud+dRjF70m0PO4o3AJsOros8I6hUmDj /bXJHoBQ/z01LOPSJ6kbm9iTLD7ElfGoPM7z1b5r+U9wZGXFne1kgmDM59WMcZL5cg3X 2NiB0p7ztwylJyPVUYT34T7DoaA5Ia58p2yFxoXE6ddjPUbYVTAlTsXkYhHx5+mSoT6z c2DA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707861930; x=1708466730; 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=B9TYnreC1cjtgZPE9uArnAlQVNsjfWDdo5XqTKM9rnk=; b=PGRBb15SsH7/skZOX88r2mj4oYHGjopUgxpgNqAn7FfJRB/CTeR5eFTqdfSeb14hX/ N/7az++FSmrtRKbyCDnWcT48ASSjZU6uIvq7OQTQPIm95+gy1iMWAGYPhOWeTHqMBG9Y 47bEEjcECQVnnhExCRko9R2XSamQj0nV5Xf726PzQeZ73tNLqqClYLIu4i105FScpfXH mfWyU1HX60dIG4P8mkL4W8Bv8q2yNCsIXlBkdZtoEN8jKpre6BxaiJFkF0oYESEDAfIS nfaiykg50ZjtmjslUZKkfGmnBkfvvavr3xJFjzh7tHAPCaz0AJFa2OXayVAtdH6kY1d8 tJJQ== X-Forwarded-Encrypted: i=1; AJvYcCVDIg7d/OxJA23kf85N6+/EXI3NSzpHSNPo2D0d+kYTylmIuj66nOyZd6b2gqzXNTrU8x/5Uxssk+1UVN57z4DhoiSMykGkiZZBglaj X-Gm-Message-State: AOJu0YwQSE7wDBLdsPWgRKINyIQziXqnE3lmboqI6fI78AVbzj+6Ow9/ OadlOo2RftpuaCmHj927xoW9EZzoFtLb0eAZIxXWAH36kYPKerSHcDTgNhxbtD8= X-Google-Smtp-Source: AGHT+IHij6jBh+AZ84+0Ms7NSpNfpFlAKS5ycAYemncvSKYjH7mjEEFSWBURsVKtbIB7AqlU4YXvCQ== X-Received: by 2002:a17:906:494e:b0:a3d:1378:143d with SMTP id f14-20020a170906494e00b00a3d1378143dmr480648ejt.2.1707861929878; Tue, 13 Feb 2024 14:05:29 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCVmJZuTch5bGaS2/AjO6RP2r83H/GbJkv1d4TPfzC/UylgiK7INVXoXrbajJqbVxggfp8v2F1eK5g+EPwQIye5XWWuKGvygMCdEvpS7UYMpaLWf6ymSRG8KKep389gt1E583uDchIB0MA0RRz5kqmmj1cxmIVrFRmMZbBrBHzHJU8cvXtPuqf/gQWD7AzQZGMYirWSWu5ONdndEZz+hHKin6aauxzfvQ7yFmHKygFql2UJw1/t5LmjC8IO3OAePBUupLllOc07fJzuhWXksj5BDq0pQ9eiALE3aj7ak4ATgufa9QUB1Z9XFL0WYsYi7q8A1vDdmdBd8ahls9WLsQMmh5Z+uXJA608YS50H5OH0+JdQWCQGr2ZgO3RH211pDavcCBsI0DV3SuLoTWttsMAcFbit2ekr2AUrfAXUIpBYjPECEAW7Pcry9LCrp263VLHYxUXRpy5Pzcw== Received: from WBEC325.dom.lan ([185.188.71.122]) by smtp.gmail.com with ESMTPSA id p12-20020a170906b20c00b00a3bdf8ae86asm1706800ejz.10.2024.02.13.14.05.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Feb 2024 14:05:29 -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 v4 05/15] net: dsa: vsc73xx: add structure descriptions Date: Tue, 13 Feb 2024 23:03:18 +0100 Message-Id: <20240213220331.239031-6-paweldembicki@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240213220331.239031-1-paweldembicki@gmail.com> References: <20240213220331.239031-1-paweldembicki@gmail.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org This commit adds updates to the documentation describing the structures used in vsc73xx. This will help prevent kdoc-related issues in the future. Signed-off-by: Pawel Dembicki Reviewed-by: Linus Walleij Reviewed-by: Florian Fainelli --- v4: - introduced patch drivers/net/dsa/vitesse-vsc73xx.h | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/drivers/net/dsa/vitesse-vsc73xx.h b/drivers/net/dsa/vitesse-vsc73xx.h index fee1378508b5..99c5c24ffde0 100644 --- a/drivers/net/dsa/vitesse-vsc73xx.h +++ b/drivers/net/dsa/vitesse-vsc73xx.h @@ -15,7 +15,15 @@ #define VSC73XX_MAX_NUM_PORTS 8 /** - * 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 switch + * @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 +36,11 @@ struct vsc73xx { void *priv; }; +/** + * struct vsc73xx_ops - VSC73xx methods container: pointers to hardware-dependent functions + * @read: Pointer to the read function from the hardware-dependent interface + * @write: Pointer to the write function from the hardware-dependent interface + */ struct vsc73xx_ops { int (*read)(struct vsc73xx *vsc, u8 block, u8 subblock, u8 reg, u32 *val); From patchwork Tue Feb 13 22:03:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pawel Dembicki X-Patchwork-Id: 13555779 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-ej1-f50.google.com (mail-ej1-f50.google.com [209.85.218.50]) (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 EFEA169D2E; Tue, 13 Feb 2024 22:05:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707861938; cv=none; b=A568t7clR7kiXb20Mw3TWRNBbsTZDUtVm0CpsCe/+vUwhdmigcTzUF5jg0K0CTGgO40VtBMHwUqX94hwLluyjqDcA5sDfJk4Fjbh7JB6+b207Zoam8gyQp64cTFScYmZrWyG6ZSLwWPNbRwQsxwaZog7nxpJTh6T6mD8IM9bd4s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707861938; c=relaxed/simple; bh=aSfhz/n2RCJGOr6hG14wnL3tSy0jymdagBk+PlbYLf4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=V55SxLFxsjk8Bxuhq1dzymyU0lWWx5hk46Y7ot3u4f9U5u0+qnuChg3/t9kwOQDtZK5kc+7xmZOIyYcSTGNwkoM2YmuGG3jnqNbSjOUyLRsHlUfFrubHkYeh+sWbHOV2GJ72RzYfL5uyPMCWyrDMdySBnpfqb254bCDxpzg9KfA= 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=jdFcB2/7; arc=none smtp.client-ip=209.85.218.50 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="jdFcB2/7" Received: by mail-ej1-f50.google.com with SMTP id a640c23a62f3a-a3cc2f9621aso149971666b.1; Tue, 13 Feb 2024 14:05:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707861935; x=1708466735; 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=bwJcHCbiEJFiPaixjIdrmQwiczYM9/vn6dsLmIZry58=; b=jdFcB2/7kyE5ojdvbVC1UwXcBby/bARnk2hS0R9FTrcJrKeNLT9aVEGCWjMogapC7P XvVc5MIATgBr5nblEcep1ow/X3A5MXW9HYwZcnxFmZSRLsf7pAKDvL6tCohYOOKa8PDA neiXHqMd4y5uhKiGMD05Oe8izl3Xxf8/tksNGI9ywtJP7C6hSVv5iQ9YstmcmwqIMY4+ L2A19wvAkWPxbkEDaiORtrpQbg1Z6ZeyKAEKvyB6l8Tsq3SK+5Bq6RXLDO1W1G8CGDDd OuiiBcJMvBjGQSJ90fN2UHg3upPeWsMbkMJsS9C6JMYAtZBfKRUihuh50GINFr4+A4uL 6+sg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707861935; x=1708466735; 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=bwJcHCbiEJFiPaixjIdrmQwiczYM9/vn6dsLmIZry58=; b=gS2zK8CiOfZamNPivniJGuA8+DHfbI1dm2/Bu++ZsrEdkVYdzGIZkvGYsLlYCbUTBE PBk2T9W9vDqVOo6eG+0yWHeot0NRgOf+/fhVJbuChAHe3FXiGikmbVn8IiYd4AEHQz65 Mdbn6q1Q9beJIUYtSyEF+V+PC3F7/B/kxgZlTXZ5352LofhaYaIJkimwxYcEgdcGOFT/ jPiop0GJBYomH8ZdA7N+QN/NMQQGDEiAMrZeuoK8xB147djWJe3ChvBrJHLRF2jFwAQ6 xZbBz6wbg4YK3dPdL811nBD//f4x6mgxMkmqH9vWVOe8wa37XuGnn/wLZM7JGE7Su5Bt Vuiw== X-Forwarded-Encrypted: i=1; AJvYcCXxHLj7daSQfbSfoOF7EA5QeOyNbYcbL8atW2Ktguh0X857gZRW9DZBHPpEtl4+l7oLObcW6bDqKehcMcAgWgb+aj/eY+gpfPjfPPoF X-Gm-Message-State: AOJu0YwH+fI+WOU2hMD7TwSJWxE8hMhV3C/NxKr3y92tD13yofIF8w7f /4AVqjup8zKi3a0XYXzsRENBHjxNG2k1n4Jv8THvM+6bfahnZNQdQPnp38uo4aM= X-Google-Smtp-Source: AGHT+IEkt2zrtA7tLHriJE/BgVIY098/3HhmQpSjIsl5BIiaVm3fdLYxNbLEqW3dfJpcW4nYGpIYKA== X-Received: by 2002:a17:906:5a8a:b0:a3c:f38b:ec4e with SMTP id l10-20020a1709065a8a00b00a3cf38bec4emr395277ejq.16.1707861934882; Tue, 13 Feb 2024 14:05:34 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCXswr14b8uYnfaE61bHXSkCtVnwB0LXtgndBOSCLt2TaDGAF49nsx8CXfIr/v8kfzAvmoXp2KBr2DKaMaHA0hmAK28w94XApE0yZsNFXXbfNRvZ+bDrkrG1ENfElECB5TMgwFyevBXwtmAzrGhFq79XrzsNLgANoC5QfdOFW7eV7eBhwrhYWzovo/z/Bogq9qN0eqvwaBNHB2dux1exfrxrwwvf+rfwnj8wkvQiN4EKwE5N4E2kzwEyh3fQNusDSAvpQnzfIYFSOVmYLhapX5QR0q0rPZxixdOonGRqZurZKNjq0SG1QSjGMwcoZINcsRSZE3TYA+LQdeAb4f4kYDwLmiRxru8o+BMqklCEfX5+vA30yN2Ct0l6U8wwOA4VA6NOVHXXJvxy1gMUCzFw9I5Xg0Wza4NXV0DsL0e+MohVc0JDxR/CnHs3xNPKJrWwnEWXBJmB/PJgIQ== Received: from WBEC325.dom.lan ([185.188.71.122]) by smtp.gmail.com with ESMTPSA id p12-20020a170906b20c00b00a3bdf8ae86asm1706800ejz.10.2024.02.13.14.05.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Feb 2024 14:05:34 -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 v4 06/15] net: dsa: vsc73xx: add port_stp_state_set function Date: Tue, 13 Feb 2024 23:03:19 +0100 Message-Id: <20240213220331.239031-7-paweldembicki@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240213220331.239031-1-paweldembicki@gmail.com> References: <20240213220331.239031-1-paweldembicki@gmail.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org 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. Reviewed-by: Linus Walleij Signed-off-by: Pawel Dembicki --- v4: - fully reworked port_stp_state_set v3: - use 'VSC73XX_MAX_NUM_PORTS' define - add 'state == BR_STATE_DISABLED' condition - fix style issues v2: - fix kdoc drivers/net/dsa/vitesse-vsc73xx-core.c | 83 ++++++++++++++++++++++++-- 1 file changed, 77 insertions(+), 6 deletions(-) diff --git a/drivers/net/dsa/vitesse-vsc73xx-core.c b/drivers/net/dsa/vitesse-vsc73xx-core.c index 75597daaad17..1dca3c476fac 100644 --- a/drivers/net/dsa/vitesse-vsc73xx-core.c +++ b/drivers/net/dsa/vitesse-vsc73xx-core.c @@ -163,6 +163,10 @@ #define VSC73XX_AGENCTRL 0xf0 #define VSC73XX_CAPRST 0xff +#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) @@ -619,9 +623,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); @@ -841,9 +842,6 @@ static void vsc73xx_phylink_mac_link_up(struct dsa_switch *ds, int port, if (duplex == DUPLEX_FULL) val |= VSC73XX_MAC_CFG_FDX; - /* Enable port (forwarding) in the receieve mask */ - vsc73xx_update_bits(vsc, VSC73XX_BLOCK_ANALYZER, 0, - VSC73XX_RECVMASK, BIT(port), BIT(port)); vsc73xx_adjust_enable_port(vsc, port, val); } @@ -1026,6 +1024,78 @@ static void vsc73xx_phylink_get_caps(struct dsa_switch *dsa, int port, config->mac_capabilities = MAC_SYM_PAUSE | MAC_10 | MAC_100 | MAC_1000; } +static void vsc73xx_refresh_fwd_map(struct dsa_switch *ds, int port, bool configure) +{ + struct dsa_port *dp = dsa_to_port(ds, port); + struct vsc73xx *vsc = ds->priv; + int i; + + if (configure) { + u16 mask = BIT(CPU_PORT); + + vsc73xx_update_bits(vsc, VSC73XX_BLOCK_ANALYZER, 0, + VSC73XX_SRCMASKS + CPU_PORT, BIT(port), BIT(port)); + + if (dp->bridge) { + struct dsa_port *other_dp; + + dsa_switch_for_each_user_port(other_dp, ds) { + if (other_dp->bridge == dp->bridge && + other_dp->index != port && + other_dp->stp_state == BR_STATE_FORWARDING) { + int other_port = other_dp->index; + + mask |= 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); + } else { + for (i = 0; i < vsc->ds->num_ports; i++) { + if (i == port) + vsc73xx_update_bits(vsc, VSC73XX_BLOCK_ANALYZER, 0, + VSC73XX_SRCMASKS + i, + VSC73XX_SRCMASKS_PORTS_MASK, 0); + else + vsc73xx_update_bits(vsc, VSC73XX_BLOCK_ANALYZER, 0, + VSC73XX_SRCMASKS + i, BIT(port), 0); + } + } +} + +/* 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 tag8021q operations. + */ + +static void vsc73xx_port_stp_state_set(struct dsa_switch *ds, int port, u8 state) +{ + struct vsc73xx *vsc = ds->priv; + u32 val; + + val = (state == BR_STATE_BLOCKING || state == BR_STATE_DISABLED) ? + 0 : BIT(port); + vsc73xx_update_bits(vsc, VSC73XX_BLOCK_ANALYZER, 0, + VSC73XX_RECVMASK, BIT(port), val); + + val = (state == BR_STATE_LEARNING || state == BR_STATE_FORWARDING) ? + 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 != CPU_PORT) + vsc73xx_refresh_fwd_map(ds, port, state == BR_STATE_FORWARDING); +} + static const struct dsa_switch_ops vsc73xx_ds_ops = { .get_tag_protocol = vsc73xx_get_tag_protocol, .setup = vsc73xx_setup, @@ -1041,6 +1111,7 @@ static const struct dsa_switch_ops vsc73xx_ds_ops = { .port_disable = vsc73xx_port_disable, .port_change_mtu = vsc73xx_change_mtu, .port_max_mtu = vsc73xx_get_max_mtu, + .port_stp_state_set = vsc73xx_port_stp_state_set, .phylink_get_caps = vsc73xx_phylink_get_caps, }; From patchwork Tue Feb 13 22:03:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pawel Dembicki X-Patchwork-Id: 13555780 X-Patchwork-Delegate: kuba@kernel.org 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 94B8269DE3; Tue, 13 Feb 2024 22:05:42 +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=1707861945; cv=none; b=bka2kDm8sfN3oqfQX/EXAIC6U5nB54rvYONQI95CCajMhlKAqo3EL0atgDo3XnI0BV+j/FBjfUuJWfIo+R0gx3MpZ8jhitv2ATzNq8jRkWa1hSQlBaKfnzC0evKbQ2sSYKYHTx3w6K6xRpfvUsHpnKUkNeWL0cR2dJgLY+klPi0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707861945; c=relaxed/simple; bh=lWgQKkjGAD0xvMdwkE5D2xfJl+/qgEiproz1COUTSH0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ozsj9BnF5ve8kGXCyZWO4L1rOPyN5HePfszsG8ReBlcpJqU0BlOg2mXLwPaQAx2uudrZQsM/NDaKqVuegJREQ00CFpt3uomHtSvAU14o6GWM9tc5O6VO61csRZHc6UX6zMYv9XsClXtWeK5HpA1wFYEL0QtHpDcR2uPU62BF2Mo= 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=mf+4QnTD; 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="mf+4QnTD" Received: by mail-ej1-f48.google.com with SMTP id a640c23a62f3a-a2f79e79f0cso741538966b.2; Tue, 13 Feb 2024 14:05:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707861940; x=1708466740; 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=vzi2NYSYs1dw7+WI8H7EeIeC1vmz6Hbcl0TyOSg0RA8=; b=mf+4QnTDVKVpORzxNTbI2t9j/5TyO6wgyJvHoKoFq/jVNvlOreaNyReigjMr6vFFKb yi6z+02YMYIt2wnbNOt86MD4gRDx3LKm0rrn7IT6RfMWJ0AhCg33a1pI0Kv4p/nka2wF R2vtux9PAfVaHukL4RL3ewpnP1JBYDAy0EyZ2p92Bca2ddKqrvrkzCHD13zsRf90t5ce dRfE0jQMZXjNJMMTi6SGxySTMWCcjXnUCIavLf5friwRh5fRG84kOef8d9ZXte+biOab iU/vkC4txsYouJR9SeP2dQMWNSPQkbVLp8g7CtbUwPJH0emBMaCaVfLCDV/qxKeKBreS OJiw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707861940; x=1708466740; 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=vzi2NYSYs1dw7+WI8H7EeIeC1vmz6Hbcl0TyOSg0RA8=; b=gQFfzXf3ZD8bDwJt96YPR9H067+A6DkpzFgREuAQSq9hqpo9flAMOg9dM4lUlrfqzB gd76ZhePsgY/SZYP2YxplLOX6v12A0lcCAbNrKkoxLbwPSuhDWo6wfVb52kmfPomncwf qShPJLTI1UmOTrXPjsSdSrMn9nBzm46cjV8W6hiR7Insk+TmJ5hXf1r4ku9Nw+TTEaB4 CfpZFPEv+6RcsqMKeEr8F/Z8cURm2HJMLCfNnbFF2mKXCyDZCbi5aVIv0KwJIv6ENRoa HC7E6gdJeRSNyC5ugXSZv+niwL7eqC5j8zwy0RRY53yeh4LZSVDm0k9gyY511YNFcLlI 58AQ== X-Forwarded-Encrypted: i=1; AJvYcCUbk0gjCeWa9GFfh1nX98eONma+5LtaseDfgdc7yE1ych1HtjRn1ZjhNE85Tb++G/0HNFm3m+inMizL5AMBj0hlOSNpfB9VcmO6fsZL X-Gm-Message-State: AOJu0YwCVQX2Rfyq8RLJxP8G/NXvaC0KQ+UskiKDzmyvA+4aEyuXmjs2 2oADv86zmiK7p68kM5AID3Uzph/GGWEhm1Qe7W07f6bMzTbP0sfAFi+l1lCSFgk= X-Google-Smtp-Source: AGHT+IF80JRTzC7TO+UF+a8xtuzla9nL5pr8wmQNcouJToNY45PLc3WvKo3FJS2aNsiY/2ntfJAHNg== X-Received: by 2002:a17:906:a451:b0:a3c:930b:2d14 with SMTP id cb17-20020a170906a45100b00a3c930b2d14mr451209ejb.9.1707861940108; Tue, 13 Feb 2024 14:05:40 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCUKAal6Mo6RK/gW++Aj54wuQEM03Tqmmipgrvtu3QyJnZqSQ0kV6Uz6bHPSzum5zhUjMDZtjsynzU6o/ctP/kggbc5f80kqxYhezyE01W+KIFmtUcfnfd8Iw09FmM7L13Aap7fPSjzPx2m+Rpp9BPwL4CY8tXrkBZCTmc6mX9E7zITA+G0AesR/ACNvBOSPMrUl4+D8bWmEql7jtPbXsSAwg4XiQ/itrILdyIQRHqtp5YIE8E+XtzkPz4N6uGkWxxBmDfFwSCbiYiDlLGb841GavTXr4qhV6aeOIJyZmtAtNElfVhRJhfcHbJYusHtjqqTPfQRNRWtys4YeWRtV85X4HSKSdR3nDG5HvfGftCt2rkQog7YiHL0b7/m7sBYjd2oFtc4Bs26SIzz39zsyAjdRyPu84WDkXo7aoh8xCKsaWiequyJhSVLsT5caJA6HHW33nV+8DHpXBg== Received: from WBEC325.dom.lan ([185.188.71.122]) by smtp.gmail.com with ESMTPSA id p12-20020a170906b20c00b00a3bdf8ae86asm1706800ejz.10.2024.02.13.14.05.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Feb 2024 14:05:39 -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 v4 07/15] net: dsa: vsc73xx: Add vlan filtering Date: Tue, 13 Feb 2024 23:03:20 +0100 Message-Id: <20240213220331.239031-8-paweldembicki@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240213220331.239031-1-paweldembicki@gmail.com> References: <20240213220331.239031-1-paweldembicki@gmail.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org 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 Reviewed-by: Linus Walleij --- 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 | 523 ++++++++++++++++++++++++- drivers/net/dsa/vitesse-vsc73xx.h | 25 ++ 2 files changed, 546 insertions(+), 2 deletions(-) diff --git a/drivers/net/dsa/vitesse-vsc73xx-core.c b/drivers/net/dsa/vitesse-vsc73xx-core.c index 1dca3c476fac..6c7bd1c200b4 100644 --- a/drivers/net/dsa/vitesse-vsc73xx-core.c +++ b/drivers/net/dsa/vitesse-vsc73xx-core.c @@ -21,9 +21,11 @@ #include #include #include +#include #include #include #include +#include #include #include @@ -61,6 +63,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 /* MAC_CFG register bits */ @@ -121,6 +125,17 @@ #define VSC73XX_ADVPORTM_IO_LOOPBACK BIT(1) #define VSC73XX_ADVPORTM_HOST_LOOPBACK BIT(0) +/* 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) @@ -134,6 +149,15 @@ #define VSC73XX_Q_MISC_CONF_EARLY_TX_512 (1 << 1) #define VSC73XX_Q_MISC_CONF_MAC_PAUSE_MODE BIT(0) +/* 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 @@ -188,7 +212,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 @@ -343,6 +368,12 @@ static const struct vsc73xx_counter vsc73xx_tx_counters[] = { { 29, "TxQoSClass3" }, /* non-standard counter */ }; +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) { @@ -560,6 +591,82 @@ static enum dsa_tag_protocol vsc73xx_get_tag_protocol(struct dsa_switch *ds, return DSA_TAG_PROTO_NONE; } +static int vsc73xx_wait_for_vlan_table_cmd(struct vsc73xx *vsc) +{ + int ret, err; + u32 val; + + ret = read_poll_timeout(vsc73xx_read, err, + err < 0 || ((val & VSC73XX_VLANACCESS_VLAN_TBL_CMD_MASK) == + VSC73XX_VLANACCESS_VLAN_TBL_CMD_IDLE), + 1000, 10000, 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 = 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 = vsc73xx_wait_for_vlan_table_cmd(vsc); + if (ret) + return ret; + vsc73xx_read(vsc, VSC73XX_BLOCK_ANALYZER, 0, VSC73XX_VLANACCESS, &val); + *portmap = (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 = 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 = vsc73xx_read_vlan_table_entry(vsc, vid, &portmap); + if (ret) + return ret; + + if (set) + portmap |= BIT(port); + else + portmap &= ~BIT(port); + + return vsc73xx_write_vlan_table_entry(vsc, vid, portmap); +} + static int vsc73xx_setup(struct dsa_switch *ds) { struct vsc73xx *vsc = ds->priv; @@ -594,7 +701,7 @@ static int vsc73xx_setup(struct dsa_switch *ds) VSC73XX_MACACCESS, VSC73XX_MACACCESS_CMD_CLEAR_TABLE); - /* 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); @@ -623,6 +730,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); @@ -635,6 +745,12 @@ static int vsc73xx_setup(struct dsa_switch *ds) udelay(4); + /* Clear VLAN table*/ + for (i = 0; i < VLAN_N_VID; i++) + vsc73xx_write_vlan_table_entry(vsc, i, 0); + + INIT_LIST_HEAD(&vsc->vlans); + return 0; } @@ -1024,6 +1140,405 @@ static void vsc73xx_phylink_get_caps(struct dsa_switch *dsa, int port, config->mac_capabilities = MAC_SYM_PAUSE | MAC_10 | MAC_100 | MAC_1000; } +static void +vsc73xx_set_vlan_conf(struct vsc73xx *vsc, int port, + enum vsc73xx_port_vlan_conf port_vlan_conf) +{ + u32 val = (port_vlan_conf == VSC73XX_VLAN_IGNORE) ? + VSC73XX_CAT_VLAN_MISC_VLAN_TCI_IGNORE_ENA : 0; + + vsc73xx_update_bits(vsc, VSC73XX_BLOCK_MAC, port, VSC73XX_CAT_VLAN_MISC, + VSC73XX_CAT_VLAN_MISC_VLAN_TCI_IGNORE_ENA, val); + + val = (port_vlan_conf == VSC73XX_VLAN_IGNORE) ? + VSC73XX_CAT_VLAN_MISC_VLAN_KEEP_TAG_ENA : 0; + vsc73xx_update_bits(vsc, VSC73XX_BLOCK_MAC, port, VSC73XX_CAT_VLAN_MISC, + VSC73XX_CAT_VLAN_MISC_VLAN_KEEP_TAG_ENA, val); + + val = (port_vlan_conf == 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; + + if (operate_on_storage) { + vsc->untagged_storage[port] = set ? vid : VLAN_N_VID; + return 0; + } + + val = set ? VSC73XX_TXUPDCFG_TX_UNTAGGED_VID_ENA : 0; + vid = set ? vid : 0; + + vsc73xx_update_bits(vsc, VSC73XX_BLOCK_MAC, port, VSC73XX_TXUPDCFG, + VSC73XX_TXUPDCFG_TX_UNTAGGED_VID_ENA, val); + vsc73xx_update_bits(vsc, VSC73XX_BLOCK_MAC, port, VSC73XX_TXUPDCFG, + VSC73XX_TXUPDCFG_TX_UNTAGGED_VID, + (vid << VSC73XX_TXUPDCFG_TX_UNTAGGED_VID_SHIFT) & + VSC73XX_TXUPDCFG_TX_UNTAGGED_VID); + return 0; +} + +static int +vsc73xx_vlan_change_pvid(struct vsc73xx *vsc, int port, u16 vid, bool set, bool operate_on_storage) +{ + u32 val; + + if (operate_on_storage) { + vsc->pvid_storage[port] = set ? vid : VLAN_N_VID; + return 0; + } + + val = set ? 0 : VSC73XX_CAT_DROP_UNTAGGED_ENA; + vid = set ? vid : 0; + + vsc73xx_update_bits(vsc, VSC73XX_BLOCK_MAC, port, VSC73XX_CAT_DROP, + VSC73XX_CAT_DROP_UNTAGGED_ENA, val); + + 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); + return 0; +} + +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 = 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 = 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 = 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 = (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 == vid) + return vlan; + + return NULL; +} + +static u16 vsc73xx_bridge_vlan_num_tagged(struct vsc73xx *vsc, int port, u16 ignored_vid) +{ + struct vsc73xx_bridge_vlan *vlan; + u16 num_tagged = 0; + + list_for_each_entry(vlan, &vsc->vlans, list) + if ((vlan->portmask & BIT(port)) && + !(vlan->untagged & BIT(port)) && + vlan->vid != ignored_vid) + num_tagged++; + + return num_tagged; +} + +static u16 vsc73xx_bridge_vlan_num_untagged(struct vsc73xx *vsc, int port, u16 ignored_vid) +{ + struct vsc73xx_bridge_vlan *vlan; + u16 num_untagged = 0; + + list_for_each_entry(vlan, &vsc->vlans, list) + if ((vlan->portmask & BIT(port)) && + (vlan->untagged & BIT(port)) && + vlan->vid != 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 = VSC73XX_VLAN_IGNORE; + struct vsc73xx *vsc = ds->priv; + bool store_untagged = false; + bool store_pvid = false; + u16 vlan_no, vlan_untagged; + + /* The swap processed bellow is required because vsc73xx is using tag8021q. + * When vlan_filtering is disabled, tag8021q use 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 tag8021q. + */ + + if (vlan_filtering) { + /* Use VLAN_N_VID to count all vlans */ + u16 num_untagged = vsc73xx_bridge_vlan_num_untagged(vsc, port, VLAN_N_VID); + + port_vlan_conf = (num_untagged > 1) ? + VSC73XX_VLAN_FILTER_UNTAG_ALL : VSC73XX_VLAN_FILTER; + + vlan_untagged = vsc73xx_find_first_vlan_untagged(vsc, port); + if (vlan_no < VLAN_N_VID) { + store_untagged = vsc73xx_port_get_untagged(vsc, port, &vlan_no, false); + vsc73xx_vlan_change_untagged(vsc, port, vlan_untagged, + vlan_untagged < VLAN_N_VID, false); + vsc->untagged_storage[port] = store_untagged ? vlan_no : 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 = vsc73xx_port_get_pvid(vsc, port, &vlan_no, false); + vsc73xx_vlan_change_pvid(vsc, port, vsc->pvid_storage[port], + vsc->pvid_storage[port] < VLAN_N_VID, false); + vsc->pvid_storage[port] = store_pvid ? vlan_no : 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 = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED; + bool pvid = vlan->flags & BRIDGE_VLAN_INFO_PVID; + struct vsc73xx_bridge_vlan *vsc73xx_vlan; + u16 vlan_no, num_tagged, num_untagged; + struct vsc73xx *vsc = ds->priv; + int ret; + + /* 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; + } + + num_tagged = vsc73xx_bridge_vlan_num_tagged(vsc, port, vlan->vid); + num_untagged = 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!\n"); + return -EBUSY; + } + + vsc73xx_vlan = vsc73xx_bridge_vlan_find(vsc, vlan->vid); + + if (!vsc73xx_vlan) { + vsc73xx_vlan = kzalloc(sizeof(*vsc73xx_vlan), GFP_KERNEL); + if (!vsc73xx_vlan) + return -ENOMEM; + + vsc73xx_vlan->vid = vlan->vid; + vsc73xx_vlan->portmask = BIT(port); + vsc73xx_vlan->untagged |= untagged ? BIT(port) : 0; + + INIT_LIST_HEAD(&vsc73xx_vlan->list); + list_add_tail(&vsc73xx_vlan->list, &vsc->vlans); + } else { + vsc73xx_vlan->portmask |= BIT(port); + + if (untagged) + vsc73xx_vlan->untagged |= BIT(port); + else + vsc73xx_vlan->untagged &= ~BIT(port); + } + + /* CPU port must be always tagged because port separation are based on 8021q.*/ + if (port != CPU_PORT) { + bool operate_on_storage = vsc73xx_tag_8021q_active(dsa_to_port(ds, port)); + + if (!operate_on_storage) { + enum vsc73xx_port_vlan_conf port_vlan_conf = VSC73XX_VLAN_FILTER; + + if (num_tagged == 0 && untagged) + port_vlan_conf = VSC73XX_VLAN_FILTER_UNTAG_ALL; + vsc73xx_set_vlan_conf(vsc, port, port_vlan_conf); + + if (port_vlan_conf == VSC73XX_VLAN_FILTER) { + if (untagged) { + ret = vsc73xx_vlan_change_untagged(vsc, port, vlan->vid, + true, + operate_on_storage); + if (ret) + return ret; + } else if (num_untagged == 1) { + vlan_no = vsc73xx_find_first_vlan_untagged(vsc, port); + ret = vsc73xx_vlan_change_untagged(vsc, port, vlan_no, true, + operate_on_storage); + if (ret) + return ret; + } + } + } + + if (pvid) { + ret = vsc73xx_vlan_change_pvid(vsc, port, vlan->vid, true, + operate_on_storage); + if (ret) + return ret; + } else { + if (vsc73xx_port_get_pvid(vsc, port, &vlan_no, false) && + vlan_no == vlan->vid) + vsc73xx_vlan_change_pvid(vsc, port, 0, false, false); + else if (vsc->pvid_storage[port] == vlan->vid) + vsc73xx_vlan_change_pvid(vsc, port, 0, false, true); + } + } + + return vsc73xx_update_vlan_table(vsc, port, vlan->vid, true); +} + +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; + u16 vlan_no, num_tagged, num_untagged; + struct vsc73xx *vsc = ds->priv; + bool operate_on_storage; + int ret; + + num_tagged = vsc73xx_bridge_vlan_num_tagged(vsc, port, vlan->vid); + num_untagged = vsc73xx_bridge_vlan_num_untagged(vsc, port, vlan->vid); + + ret = vsc73xx_update_vlan_table(vsc, port, vlan->vid, false); + if (ret) + return ret; + + operate_on_storage = vsc73xx_tag_8021q_active(dsa_to_port(ds, port)); + + if (!operate_on_storage) { + enum vsc73xx_port_vlan_conf port_vlan_conf = VSC73XX_VLAN_FILTER; + + if (num_tagged == 0) + port_vlan_conf = VSC73XX_VLAN_FILTER_UNTAG_ALL; + vsc73xx_set_vlan_conf(vsc, port, port_vlan_conf); + + if (num_untagged <= 1) { + vlan_no = vsc73xx_find_first_vlan_untagged(vsc, port); + vsc73xx_vlan_change_untagged(vsc, port, vlan_no, num_untagged, false); + } + } else if (vsc->untagged_storage[port] == vlan->vid) { + vsc73xx_vlan_change_untagged(vsc, port, 0, false, true); + } + + if (vsc73xx_port_get_pvid(vsc, port, &vlan_no, false) && vlan_no == vlan->vid) + vsc73xx_vlan_change_pvid(vsc, port, 0, false, false); + else if (vsc->pvid_storage[port] == vlan->vid) + vsc73xx_vlan_change_pvid(vsc, port, 0, false, true); + + vsc73xx_vlan = vsc73xx_bridge_vlan_find(vsc, vlan->vid); + + if (vsc73xx_vlan) { + vsc73xx_vlan->portmask &= ~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 = 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, 0); + vsc73xx_update_bits(vsc, VSC73XX_BLOCK_MAC, port, VSC73XX_CAT_DROP, + 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, 0); + vsc73xx_update_bits(vsc, VSC73XX_BLOCK_MAC, port, VSC73XX_TXUPDCFG, + 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 == CPU_PORT) + vsc73xx_set_vlan_conf(vsc, port, VSC73XX_VLAN_FILTER); + else + vsc73xx_set_vlan_conf(vsc, port, VSC73XX_VLAN_IGNORE); + + /* Set storage values out of range */ + vsc->pvid_storage[port] = VLAN_N_VID; + vsc->untagged_storage[port] = VLAN_N_VID; + + return 0; +} + static void vsc73xx_refresh_fwd_map(struct dsa_switch *ds, int port, bool configure) { struct dsa_port *dp = dsa_to_port(ds, port); @@ -1107,11 +1622,15 @@ static const struct dsa_switch_ops vsc73xx_ds_ops = { .get_strings = vsc73xx_get_strings, .get_ethtool_stats = vsc73xx_get_ethtool_stats, .get_sset_count = vsc73xx_get_sset_count, + .port_setup = vsc73xx_port_setup, .port_enable = vsc73xx_port_enable, .port_disable = vsc73xx_port_disable, .port_change_mtu = vsc73xx_change_mtu, .port_max_mtu = vsc73xx_get_max_mtu, .port_stp_state_set = vsc73xx_port_stp_state_set, + .port_vlan_filtering = vsc73xx_port_vlan_filtering, + .port_vlan_add = vsc73xx_port_vlan_add, + .port_vlan_del = vsc73xx_port_vlan_del, .phylink_get_caps = vsc73xx_phylink_get_caps, }; diff --git a/drivers/net/dsa/vitesse-vsc73xx.h b/drivers/net/dsa/vitesse-vsc73xx.h index 99c5c24ffde0..01eb2dd48f03 100644 --- a/drivers/net/dsa/vitesse-vsc73xx.h +++ b/drivers/net/dsa/vitesse-vsc73xx.h @@ -24,6 +24,14 @@ * @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 have two roles: Keep PVID when PVID is configured but vlan filtering is off + * and keep PVID necessary for tag8021q operations when vlan filtering is enabled. + * @untagged_storage: Storage table with eggress untagged VLAN configured for + * other state of vlan_filtering.Keep VID necessary for tag8021q operations when + * vlan filtering is enabled. + * @vlans: List of configured vlans. Contain port mask and untagged status of every + * vlan configured in port vlan operation. It doesn't cover tag8021q vlans. */ struct vsc73xx { struct device *dev; @@ -34,6 +42,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; }; /** @@ -48,6 +59,20 @@ struct vsc73xx_ops { u32 val); }; +/** + * 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); From patchwork Tue Feb 13 22:03:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pawel Dembicki X-Patchwork-Id: 13555781 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-ed1-f49.google.com (mail-ed1-f49.google.com [209.85.208.49]) (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 7714369E10; Tue, 13 Feb 2024 22:05:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707861949; cv=none; b=LwnTJMb6SZm2kySJD2nSQN6X3f6rDQxdI5ekPRTGljraEDYusV2ZJtS+fa7L40LzhwTfblhQDubYiSFxV1ieiifOpL/Je7vJsLtCmKO2Fc5FtGWsqkKTHviRdiPbIq0vB+U2PkocYLhOg86mJIoFbcCv8tH9nLIen74haMx2es0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707861949; c=relaxed/simple; bh=30wAuor8M+3rBgvHsgL+WF5JOPTFm3WXG/R2QNvezrc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=RstN8/PYxh8t3ReVU0USSMwiLE3QnMVuio6kBPWlYbiC2eTNAGESdIwDXi4dwmhApww3LObabNSheSuGX9pFA6iju8X1k0hOVsNObLXUACoHECbFe0rxLS0hBm0z10XMBhwSgJeFdnNjfqh8r/j+xZYiKlAyShWvOlhZw1e1VFk= 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=RGN2gAOO; arc=none smtp.client-ip=209.85.208.49 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="RGN2gAOO" Received: by mail-ed1-f49.google.com with SMTP id 4fb4d7f45d1cf-55c2cf644f3so6453507a12.1; Tue, 13 Feb 2024 14:05:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707861945; x=1708466745; 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=uU/EzzAZ+26p7VR+AL+8noQM2sIMSv95utTyaUMHIAk=; b=RGN2gAOOzCnhcKSSXCP1Lkq8+EYrYAwoUTqROc3YTp+Z2z0R2vjUeI4mHYd7AFISUo AKizuXy3z0pLtxqQZuB2sdGdMTfTSks/Mtv0nVdKvDM61urBKtDhwc6uGBhHuyCcdUbt 2dmICdRPHrRZkQwKKBeNhSf5PdCQ3x7cF40tJfEz1BOOa1l1i9rHiOWTf0gZuJMy4xmI RAhVRv3fjFZ2jxRZQzGlICFeAavQAxKqRnvk2dq1lRjF/n4ANjkcBnEhBlVfBrJu/wDs mf7b/B+hITEue1PjBCrEE8mL7Gg98bEuHuFZjQLfu9e6hi3yTtxMrAPav65dxl5TdjJ9 /Y/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707861945; x=1708466745; 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=uU/EzzAZ+26p7VR+AL+8noQM2sIMSv95utTyaUMHIAk=; b=dVzput3A9muX7Vy6wg3io3Y+ERjibJydqdCPLsyKQM2kFq6+poU7l/+XriVxlA+1Rl crvxlgSll1IST7SJAZUE8j46VnJubp5u+w28p6QTeR7Nj9H4AueyQ+IB1HfOvDzirO5K ED9BKlkWI28KGhgM3X0ZTE+mehQq9YmiJJIcs9YiDs62K3oChbraKqPqe6daJXJQjQlg sEXtvnVo1XyR1q70jdSSiZA114/KFzJsgK+UGYQtPZHTp8Q/hJI8Wzg8E9AghNBwJ9p9 2Jw2ke+cZBY11pMNDFcbVDczn7yRgI+X15ZtTpRaWijIFz1UHb5LfyUMpHQUHHz3KWWf XJXA== X-Forwarded-Encrypted: i=1; AJvYcCUORXMzKrUhqUMjOtDlHrMn36/zttx4WW0rSLz+XRPsgeMk8tPBYyr5neV7hQ7I2jxBCY0e8HLPBQPEXg5ERZM24QahXJ/MdzRlOhyp X-Gm-Message-State: AOJu0YxNP4qkBOzhzGeSaQR5zCOqh3+6ApfrKWX1/7OhHVmJ2qhDHGRD xXCtu9ruUc+1hFOGbUgsCsW6axoV2DuUDJnAdT5GcSMZj5Wf2hc9CgVeTBoLRs4= X-Google-Smtp-Source: AGHT+IEu2iWvEwOIyqeuEWVQnyqHB8H/uCkDsSGQZAmgVcwi5rivcl4dCuAcZl3j272XDjmrSo6/tA== X-Received: by 2002:a17:906:495:b0:a3d:1a89:7054 with SMTP id f21-20020a170906049500b00a3d1a897054mr486760eja.39.1707861945378; Tue, 13 Feb 2024 14:05:45 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCWK4qxbePgjYGlDE0gi9ls5TD1pLfnEevyvGm8A1VCaFV6ho/2jGjFgvpPKd+2PGU5YRkEjchB8OaUr08bd5O1PO+NkneZp3vx7ROmfKa7/n8pZ1qZReg14zZIcrf79o/hG5gsibENB3qqaoKdF2shbQj06+X5cgUsrhX8L3TWUWlJOEGhXa+3z9KWO3vN9GmPTDOzgMvjV03w/WtyAJdlfXl326ElGH5Usi92MTXQXbC2Yup2zbeWZWst6+Dcjz40/EUIyPk+6X1mQ24OymhtUkX1pxrrToUrccERlAJsTK3MC+FaTKHOADT5gBFl6hSQSoFkqDXJJiWWPrs1Cq/CsHI4GYsdWs37nJHB+Vmj24bb1f/ZZoNQ/OcdlxBEhGdn52tnrtuEdlwB+ddv79iYnhkUKROND07n5k3Fn5b3GcEIjJx9HkpFsX5NOC7CJkNV+EwAdAfxjkA== Received: from WBEC325.dom.lan ([185.188.71.122]) by smtp.gmail.com with ESMTPSA id p12-20020a170906b20c00b00a3bdf8ae86asm1706800ejz.10.2024.02.13.14.05.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Feb 2024 14:05:45 -0800 (PST) From: Pawel Dembicki To: netdev@vger.kernel.org Cc: linus.walleij@linaro.org, Vladimir Oltean , 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 v4 08/15] net: dsa: tag_sja1105: absorb logic for not overwriting precise info into dsa_8021q_rcv() Date: Tue, 13 Feb 2024 23:03:21 +0100 Message-Id: <20240213220331.239031-9-paweldembicki@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240213220331.239031-1-paweldembicki@gmail.com> References: <20240213220331.239031-1-paweldembicki@gmail.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org 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 >=1), source_port and switch_id will be set to zeroes by dsa_8021q_rcv(), which might be problematic. But by checking for vbid >= 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 --- 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(struct net_device *conduit, } EXPORT_SYMBOL_GPL(dsa_tag_8021q_find_port_by_vbid); +/** + * 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-initialized + * 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; if (skb_vlan_tag_present(skb)) { @@ -513,11 +525,25 @@ void dsa_8021q_rcv(struct sk_buff *skb, int *source_port, int *switch_id, vid = tci & VLAN_VID_MASK; - *source_port = dsa_8021q_rx_source_port(vid); - *switch_id = dsa_8021q_rx_switch_id(vid); + tmp_source_port = dsa_8021q_rx_source_port(vid); + tmp_switch_id = dsa_8021q_rx_switch_id(vid); + tmp_vbid = 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 == 0 && *source_port == -1) + *source_port = tmp_source_port; + if (tmp_vbid == 0 && *switch_id == -1) + *switch_id = tmp_switch_id; if (vbid) - *vbid = dsa_tag_8021q_rx_vbid(vid); + *vbid = tmp_vbid; skb->priority = (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 *skb, /* 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 = -1, tmp_switch_id = -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 == 0 && source_port == -1) - source_port = tmp_source_port; - if (vbid == 0 && switch_id == -1) - switch_id = tmp_switch_id; - } else if (source_port == -1 && switch_id == -1) { + if (sja1105_skb_has_tag_8021q(skb)) + sja1105_vlan_rcv(skb, &source_port, &switch_id, &vbid, &vid); + else if (source_port == -1 && switch_id == -1) /* Packets with no source information have no chance of * getting accepted, drop them straight away. */ return NULL; - } if (source_port != -1 && switch_id != -1) skb->dev = dsa_conduit_find_user(netdev, switch_id, source_port); From patchwork Tue Feb 13 22:03:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pawel Dembicki X-Patchwork-Id: 13555782 X-Patchwork-Delegate: kuba@kernel.org 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 3557F6FB80; Tue, 13 Feb 2024 22:05:55 +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=1707861958; cv=none; b=mvHPsEbgJYcmm8M6+SIQemMEo8KfKpy4yu3R7+yiiM6NWFdm3JdYUI0XUb841VJZBZqfKkGYsSVOfLAb1E8Nojc2AysS72c2wW9nVyynzHyd5tvLJo149A7Up1ExDDYvS69XhIKCzSBjqDEA7j2jorQ9ub+HX74vkAOrH1M1ysY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707861958; c=relaxed/simple; bh=FWHayuZw/Ot2rSgc/NXoN+gmwi8uEkTj3zeN+fbN+Uk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=FSSyIEQu3tHy4vPOzGxpVOFxCmMx0njDoPQIv5wu173hghSEeZjNuhs9wS2MLTchP4UPn3AvEYOBjYj/QptV0nc58NMbAE4AiD8A3deDgurMamO9pJdJwMks6MlpKA/N7AHU5aUtx4YZSPOET771U7Lj7kKwvWRITN8yxOomcC4= 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=D55JQG4M; 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="D55JQG4M" Received: by mail-ej1-f42.google.com with SMTP id a640c23a62f3a-a2f22bfb4e6so666336566b.0; Tue, 13 Feb 2024 14:05:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707861954; x=1708466754; 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=M+w6iJDAWTcoEwIs/CJsWDUTAWaRRDi08Wez6bn4quw=; b=D55JQG4MmeTh7P/ySczjmRM5QIhRZanRPv2PIQf1kVtwYr3URNqoAoYNPNusrNcJyj m6eTke8v9jtXjHqM+Qs9nH8TuiSeXUkEWfWNoHRK9jI0jazFMzJfAnxYhvCQCLA5tCHO //4AxA9ORo+egcV/KbvKlKk1fBMXENRbb/snCI96ZY0nXs4ICMKYStCGOQchg3rR/Y9f +EXVczLPmxmqVZ9SOUiBnlkkwzrCWNftSW3yyisKlkkzd5AdkgNVevVVMZlcO71CywWI DRUr2oge9xSmJlLuNkPE3DG2GTepJ+hh3O00eAkgRxkuwinFQIozqQA2WaWTqR2mvm8X 3UnA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707861954; x=1708466754; 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=M+w6iJDAWTcoEwIs/CJsWDUTAWaRRDi08Wez6bn4quw=; b=C5aqXJ1M0A5tkwCeoxJotUzhm3cu0dd5zD1+ekShIQU/6GY3mXRj999ChXWPSywu+D xi2HFNhrYd8oDx4x+wdARmdqWiN0ix+HkD9cRbVZt5h4Vrc4GXM5qvOYHwp8vOuYBjZ0 xSyqpvo3aHVm1Iyh6SsjR7gGlvHImHys03Z1xPeAQrB6R7uOVI3fgTdloXDYdO/EgNKF msOaXXDd/XHLpr6QL3h+UNyJtr9hrmhzr443+K7V2zO/h+W6Ezebpxb72vnPS1e85pWK YufJIgA8/dh0uRGEP2KU6bazN1Ej3jNBPcN0GeND1bmr79rBnPzrCgMe/SzoILOwAUBd Ps5Q== X-Forwarded-Encrypted: i=1; AJvYcCUXD3VS+TwzFDmcORQpuZy4znZ0eiVxREGbWQa6sMx+MqeamvzTTfT2PTDhqdZqBfZLfyXDF3EHOWMBf2d3z6wFUVVBAI9VF7eE6HlI X-Gm-Message-State: AOJu0YwEaKPTqrN68H8Oz/2c4TwYAwjMnUx7S8KAatHb69nUzxkO+SHi 0CVpwkzJjBJpeVXU1bjNBlJc8ubBRUEK1HStvmoyzu9QCVliofr3FA9WHtYPMnI= X-Google-Smtp-Source: AGHT+IEgZ4FoV4KG31cK7u3uKfC+VuGEOR3T8DLg9pKmlR4tfjYmTTai/OuO2rD97rsVe5IC0A8WTQ== X-Received: by 2002:a17:906:6812:b0:a3d:2146:5703 with SMTP id k18-20020a170906681200b00a3d21465703mr375059ejr.6.1707861953746; Tue, 13 Feb 2024 14:05:53 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCU4GyoCdSkhUePgHnQ+n+8+Ok8bk9Nqu7JX5MvMPDSEe7mBwpL+x32F+XSEnfD8JDPCSyBvF4XI0U6bZq6a+Gjm7Y4XCtwjWXh5uewMvafmJcinE1bgeoP7szDCACqbLIC63gNO5nO9sbaZTSo61k0EdPwp1z0XDuSXOhJpjSFqQa/lsosvcASD/J+c6AIsyI0ztmtftDoMtP3kCA/U5a1QQCLjmNNTHwNQNEOOgu8ULivte/bZ3XCUM2VBN1ZHe5t58kNwLpNAbO+CZ2ISpga1PUiexcYlUtiFOQ6qeVkBf5xfcIagSEGTLypU+qi3tpL/bVz9QIt6N3Dkqgnr5lVM7qmVs7M90Twl9yq492I0LFzFQKOomNLYE/mP6C5jCPxOcMXbAyezlk39SCOu2H0SYPX015HgHtHjtJLYZM/SvlN9S9WE3pTYkkekm2LsVC7hmFOXblXcKw== Received: from WBEC325.dom.lan ([185.188.71.122]) by smtp.gmail.com with ESMTPSA id p12-20020a170906b20c00b00a3bdf8ae86asm1706800ejz.10.2024.02.13.14.05.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Feb 2024 14:05:53 -0800 (PST) From: Pawel Dembicki To: netdev@vger.kernel.org Cc: linus.walleij@linaro.org, Vladimir Oltean , 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 v4 09/15] net: dsa: tag_sja1105: absorb entire sja1105_vlan_rcv() into dsa_8021q_rcv() Date: Tue, 13 Feb 2024 23:03:22 +0100 Message-Id: <20240213220331.239031-10-paweldembicki@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240213220331.239031-1-paweldembicki@gmail.com> References: <20240213220331.239031-1-paweldembicki@gmail.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org 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=1 (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 --- 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-initialized * 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 failed. + * + * 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; if (skb_vlan_tag_present(skb)) { + vlan_proto = skb->vlan_proto; tci = skb_vlan_tag_get(skb); __vlan_hwaccel_clear_tag(skb); } else { + struct vlan_ethhdr *hdr = vlan_eth_hdr(skb); + + vlan_proto = hdr->h_vlan_proto; skb_push_rcsum(skb, ETH_HLEN); __skb_vlan_pop(skb, &tci); skb_pull_rcsum(skb, ETH_HLEN); } - vid = tci & VLAN_VID_MASK; + tmp_vid = tci & VLAN_VID_MASK; + if (!vid_is_dsa_8021q(tmp_vid)) + goto not_tag_8021q; - tmp_source_port = dsa_8021q_rx_source_port(vid); - tmp_switch_id = dsa_8021q_rx_switch_id(vid); - tmp_vbid = dsa_tag_8021q_rx_vbid(vid); + tmp_source_port = dsa_8021q_rx_source_port(tmp_vid); + tmp_switch_id = dsa_8021q_rx_switch_id(tmp_vid); + tmp_vbid = dsa_tag_8021q_rx_vbid(tmp_vid); /* 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_port, int *switch_id, *vbid = tmp_vbid; skb->priority = (tci & VLAN_PRIO_MASK) >> VLAN_PRIO_SHIFT; + return; + +not_tag_8021q: + if (vid) + *vid = tmp_vid; + if (vbid) + *vbid = -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, struct net_device *netdev, u16 tpid, u16 tci); void dsa_8021q_rcv(struct sk_buff *skb, int *source_port, int *switch_id, - int *vbid); + int *vbid, int *vid); struct net_device *dsa_tag_8021q_find_port_by_vbid(struct net_device *conduit, 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; - dsa_8021q_rcv(skb, &src_port, &switch_id, NULL); + dsa_8021q_rcv(skb, &src_port, &switch_id, NULL, NULL); skb->dev = 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) == ETH_P_SJA1110; } -/* 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 = vlan_eth_hdr(skb); - u16 vlan_tci; - - if (skb_vlan_tag_present(skb)) - vlan_tci = skb_vlan_tag_get(skb); - else - vlan_tci = 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 = vlan_tci & VLAN_VID_MASK; -} - static struct sk_buff *sja1105_rcv(struct sk_buff *skb, struct net_device *netdev) { - int source_port = -1, switch_id = -1, vbid = -1; + int source_port = -1, switch_id = -1, vbid = -1, vid = -1; struct sja1105_meta meta = {0}; struct ethhdr *hdr; bool is_link_local; bool is_meta; - u16 vid; hdr = eth_hdr(skb); is_link_local = 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 == -1 && switch_id == -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_extension(struct sk_buff *skb, static struct sk_buff *sja1110_rcv(struct sk_buff *skb, struct net_device *netdev) { - int source_port = -1, switch_id = -1, vbid = -1; + int source_port = -1, switch_id = -1, vbid = -1, vid = -1; bool host_only = false; - u16 vid = 0; if (sja1110_skb_has_inband_control_extension(skb)) { skb = sja1110_rcv_inband_control_extension(skb, &source_port, @@ -674,7 +650,7 @@ static struct sk_buff *sja1110_rcv(struct sk_buff *skb, /* 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); if (vbid >= 1) skb->dev = dsa_tag_8021q_find_port_by_vbid(netdev, vbid); From patchwork Tue Feb 13 22:03:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pawel Dembicki X-Patchwork-Id: 13555783 X-Patchwork-Delegate: kuba@kernel.org 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 28E1269E10; Tue, 13 Feb 2024 22:06:00 +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=1707861963; cv=none; b=j+lcxTlj2Sxcsxwen+r5gCl3oGeOrehB1BrscmG0TOm+oSePSgJTtyyH0BJTZR7HAFuK4V+17rOV0Od79UqzMI5o+V28tBWPGjxW7kz1KM+8l8Jj+2KqP/6P7ZUxhmvWqR0qaAuANv3NXiRCKq0AgxJyj13AQgpO/TyER3Og3hA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707861963; c=relaxed/simple; bh=yMiFz9mUYxlHMRSQVDDmvaIcbWUmQQAdWdv5fkArP/o=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=nQ2jMh2N0hC2pRjZRBwbdzFW2PZEd3ekNFS8Km5BhzWnCro0hzL+hefqbVMPpkz9cbRycbsbXdJb7KRPCdh28a0h7+A8RZEeasdWQPFdJsXuE6j6vc3w+ZukuJQPdjVRH9UDT9HkpFiqryI/uDaUHfRu08Nwbbvh/4HDwrWEUOg= 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=US5syN1I; 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="US5syN1I" Received: by mail-ed1-f53.google.com with SMTP id 4fb4d7f45d1cf-561f8b8c058so394141a12.0; Tue, 13 Feb 2024 14:06:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707861959; x=1708466759; 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=Qrf9eahK2JmvAuMzFkBBc7G4ZdpSxxspNCqWeEFsoYc=; b=US5syN1IGGrUWYItoZH5riN7/gh34iaAPGU7J+odhMmwLCKLVHrMe2C9yTLofG+a2s Ux5twcZkd8NmqplaCAF1fcZEIJSQ3b0k5v2b19xH+QZhL+57sldMjZWzQTxPSs02Vo1a Db5j82n7InUSJLr9Z3D6li+HOGtoHHq32ePSQVX4NF3Yz1eGPtThzyfpfjXmmfWcoA1G DB3hpHGkxA2xwfKABbp55vfz0sBggo8r/06CfVz/j43SVXuEeXWINnINS/hrG+7n8EXY /wD3uq9R9UO6/jSizx2Ua/IgLed27aNrCfi92a1ViXKyXsOgB5xQDocuywtw4yMPIYrw Rkkg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707861959; x=1708466759; 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=Qrf9eahK2JmvAuMzFkBBc7G4ZdpSxxspNCqWeEFsoYc=; b=lvamkg9FcqvPMrprKZ3MImaFj4t9GPKbB9r1cc3uaWiNBhwvOjhrczn6thIT+WG9nA 5hY54BeynN+8w0C9kWs5tavMiFtU2T+MWU9Vs0t6ZMcCl1TTyEyiDBiYtHrM86gcVgkO 14pH69TWO5+IQtofOpduwX1tnMKKLx+S1qQkfGTP1hD3ozkykvbPUX2JAr5DNs9Kp1hW xZi3mUF8oPkCxYZrdKYa96K15MhE/rOsfVy6IGxoyp+GsjMHW1pAZc+8qN5vne7ZdPp4 /YqYB3GHkhCw1bsiV71KO5JmcGhLZiFGnuqPkY9mp53ZRFZov0ZYyWop5ExEDBBqyL9A K5UQ== X-Forwarded-Encrypted: i=1; AJvYcCXcT9OUSR+tW90+ZVId65N8POAqiCDL7WcIrQ0RXFQXqnYfmPp2KX0IluzSTgfcNpcQ40LCi6itOs2b0jpj/CfRVI3zFyoFL/Kt6vsE X-Gm-Message-State: AOJu0Yw6LclGJtrRlCM6eut6wR9pBv5GHTeUn+/q+L0AjRpGbJOHVkc2 XbNINCL5PS3vv+SWXB1IGjw9nljMtqMy77Sskxu7TqA5v5Ue6DyYj5V00gGR1no= X-Google-Smtp-Source: AGHT+IH1uQb7LXAJj3UHPqDPp0SN+HDKQSG+tGa2EU+Q/lARN/1KP8UGVGBY6usVcirqjxaswJOBlw== X-Received: by 2002:a17:907:6d0c:b0:a3d:37a4:809d with SMTP id sa12-20020a1709076d0c00b00a3d37a4809dmr150783ejc.7.1707861958861; Tue, 13 Feb 2024 14:05:58 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCXN+KHy19m3510ARFBTZmrS+SbV1BYC/xFUqolzqGzwmklav/82BcO3aNP658aWlqzsxmPL8cw8vSKdmySgJR6IRWusXfoG5RVddWeU6U1lNpJqjPcwp1tQsYO8dfGTWkPEhss15m3FR/iX7/0K2TFgWcg2e/Cop4xnfY+VByC9v2akeNsRaoWbsthAN2WY5FqGwWXuv5L+EAyh4Amy5ARgpzJ/zrB9Fojz0kypUJkYvYrbp35BSEsrfDWHZKaYPMC8YF683v/5A6J+HlJAM5hgeC985WydaZql9Vdw3I+OO/itx37lvwT/cnWY1y19UrhfQoFsEEvHZdsRQk+EMiAyoy7xWSAB056UpKDrfRIk6+MML/pq/MLjvn5BoomrFB8D6uHVFZ+6JrY4vFi/aaYe8PzzqCl3GvHodt7RqT5YIJq2VEpevvqzIWj2cZbYG+H6G91uqFTUTABTj7w18NTkitCgjOHxtcAH8+dlikPWuDA= Received: from WBEC325.dom.lan ([185.188.71.122]) by smtp.gmail.com with ESMTPSA id p12-20020a170906b20c00b00a3bdf8ae86asm1706800ejz.10.2024.02.13.14.05.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Feb 2024 14:05:58 -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 v4 10/15] net: dsa: tag_sja1105: prefer precise source port info on SJA1110 too Date: Tue, 13 Feb 2024 23:03:23 +0100 Message-Id: <20240213220331.239031-11-paweldembicki@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240213220331.239031-1-paweldembicki@gmail.com> References: <20240213220331.239031-1-paweldembicki@gmail.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org 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 --- 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 *skb, if (likely(sja1105_skb_has_tag_8021q(skb))) dsa_8021q_rcv(skb, &source_port, &switch_id, &vbid, &vid); - if (vbid >= 1) + if (source_port != -1 && switch_id != -1) + skb->dev = dsa_conduit_find_user(netdev, switch_id, source_port); + else if (vbid >= 1) skb->dev = dsa_tag_8021q_find_port_by_vbid(netdev, vbid); - else if (source_port == -1 || switch_id == -1) - skb->dev = dsa_find_designated_bridge_port_by_vid(netdev, vid); else - skb->dev = dsa_conduit_find_user(netdev, switch_id, source_port); + skb->dev = dsa_find_designated_bridge_port_by_vid(netdev, vid); if (!skb->dev) { netdev_warn(netdev, "Couldn't decode source port\n"); return NULL; From patchwork Tue Feb 13 22:03:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pawel Dembicki X-Patchwork-Id: 13555784 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-lf1-f52.google.com (mail-lf1-f52.google.com [209.85.167.52]) (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 21396768FB; Tue, 13 Feb 2024 22:06:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707861967; cv=none; b=Hm+6AX8XSoRdGEDOxDeOUWKNppgImlxxQI/BIzGhTw18FjEkQYcrtLtobaYDQTtJv6yyjc0E1VJuw9jJwrDCxej9NoVLMe/CdL+tNlIyf1RAXX5oldrrWb0Cju/TTT+mLM9Us6AQRyD1pXv3RBkbfD74zF9hPNWRPsZOT8CXJ9s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707861967; c=relaxed/simple; bh=gbxVPJ6WPRdDj/VlfQnJSPWObXat+GMFe+pa9vsdy8U=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=cfYT6BX7H6aiiV5wEWXe39cUQn6CCw/lJE28D55IzNMfkkSkE+WH9JexDMsDf6St0JHub01AO1k3GMFSFgAG7QZa20DL463lGk1VLOm+nomtIht1uqIcrpnl2mJ/RJkWwtYXsRaGwiZ630wBX7+XKNm/VeYgtYZW71BgSiA7Sow= 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=kVjMYKIR; arc=none smtp.client-ip=209.85.167.52 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="kVjMYKIR" Received: by mail-lf1-f52.google.com with SMTP id 2adb3069b0e04-51176eb6a4bso5034634e87.3; Tue, 13 Feb 2024 14:06:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707861964; x=1708466764; 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=GsV3RWi5mt3annbxTmJGAA4zUOZXwChRzqMr98hPMQE=; b=kVjMYKIRBQw1BhPhGNzwLcWenlmsxIlDH0bk7q62f9QqgCOFhiLHom0sfcqxxnDBaZ zQqZg9FCZ19q0yNv9tvrKlWnrdWdV+4EvXh8KJ3A77nQW4y5gwDV/n9hMdgx8e4XSAnX Zrq7KmG3Q4fv4fbBZaQaK8O++axGD/ew2X86QCTvSxhvIS5U83R/G+QucRTLcMViotWY TW67HrdmWXl7yF/9TUomAf2JF46jitowoKzCEdnTRekQYJx6XWyWP4Gwu0AHafqUutGd adMNkC1H37Xp8XmHJL1uziJ/lwspkRpJayShSytMwHMZ5VEEAS3EP1ZLsfi/jG3pUbRC iuqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707861964; x=1708466764; 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=GsV3RWi5mt3annbxTmJGAA4zUOZXwChRzqMr98hPMQE=; b=AJHLUYO3MSfox04FFi01bJ2OntjPuoVWV1NodDTrY8bmHb4gSH9Cew02CgcKolK8OT K0BFSCWYlfpbtQ2Yhz9VxQSdIcEgvXpQbEQ+6LXBXb/SdVPc+8D0939JEhrVyE2TmcCz EGN19MfZSifmSC7lqEE7RTjlU/mAevsFxqxX2kpkqyixsSM49FmVgN5FHO/yb65PXkrP c/nGT+2sDIl78xTElLZSvVqmrCDa2SYjcMMIrJ1pt6/txnIIR3UrXwDEo2TB18w95zUJ VSQYaenBVjNlf73169jDJLLb6tq+QiqaKy7rKn8bcA6AYO+DroawkM84m63LT2j+pEA+ +rVw== X-Forwarded-Encrypted: i=1; AJvYcCWv8UcNaa5hf/PJ2d7ew1SBRMsPTUGOo3KlX0RoW8k4Hg4XS+bRk7CulItQLOSnXh8SBFLouIJiDdZQraNRcSjYPBMrA39tz0+k13f9 X-Gm-Message-State: AOJu0YzYYeoKEmPTfDT/qPwU/5VYHx/VmGWR89dekP/xOlyFPMc83rKg 1qQKH+6XIPyDrohesgf2V3uviw8tEdTS6fE3k5w8s32/l2L2MTjpr3bFaqec10k= X-Google-Smtp-Source: AGHT+IGnLwxRXqh7Vnva/GmEq50Zj0Jzqcqk82fg01VT2b+8mhwiCg+jlDhgx1TNCTdsTAhTQiaq+w== X-Received: by 2002:ac2:4c2e:0:b0:511:48aa:d621 with SMTP id u14-20020ac24c2e000000b0051148aad621mr596887lfq.66.1707861963831; Tue, 13 Feb 2024 14:06:03 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCXiHsKUaFLJtSg26Ue6/yjHqtoSQycOdoVPF9xVAWZZ6A8ApxSlgT5sYHHdOg34B4LVHABTZJjb0fgPUXgXbCsOWt5YX3U233/9BBONll1rm05kwglv/n6TM10oBK3cUVaxALALDmILw1qHV7unWBbqsU9jzQHtnF17vHouc9faqY+bFeh6WLzvsRVPQ+RBOt91zeODGWprJkcnitiayv59Ab+XqlW7yNX5LTPB/f6WLfKl8XjRVcPZ4NUXiuZCk3M0HGZY2XK//IsCTSJcA9DMLnGduafS1loL7JGVb40QzeZXlWXW6qC/OE1FnESHi4gk5a54FttHBSO9rwTHe7UW80ljfcYlpj6jASNxqyhEOha59HgUFsxBWgAx1nk1G6hBy46mhnIOVIb7xchrz27InXRt9RWXYlKYW0+vql5hUnXlA1ilhozc5oblaJS5fj5+8DCdk3ednavarxZSkL7kahApD8QLlO0YEKvjpSDJmpI= Received: from WBEC325.dom.lan ([185.188.71.122]) by smtp.gmail.com with ESMTPSA id p12-20020a170906b20c00b00a3bdf8ae86asm1706800ejz.10.2024.02.13.14.06.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Feb 2024 14:06:03 -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 v4 11/15] net: dsa: tag_sja1105: refactor skb->dev assignment to dsa_tag_8021q_find_user() Date: Tue, 13 Feb 2024 23:03:24 +0100 Message-Id: <20240213220331.239031-12-paweldembicki@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240213220331.239031-1-paweldembicki@gmail.com> References: <20240213220331.239031-1-paweldembicki@gmail.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org 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 --- 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, struct net_device *netdev, } EXPORT_SYMBOL_GPL(dsa_8021q_xmit); -struct net_device *dsa_tag_8021q_find_port_by_vbid(struct net_device *conduit, - int vbid) +static struct net_device * +dsa_tag_8021q_find_port_by_vbid(struct net_device *conduit, int vbid) { struct dsa_port *cpu_dp = conduit->dsa_ptr; struct dsa_switch_tree *dst = cpu_dp->dst; @@ -495,7 +495,20 @@ struct net_device *dsa_tag_8021q_find_port_by_vbid(struct net_device *conduit, 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 != -1 && switch_id != -1) + return dsa_conduit_find_user(conduit, switch_id, source_port); + else if (vbid >= 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); /** * 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, struct net_device *netdev, void dsa_8021q_rcv(struct sk_buff *skb, int *source_port, int *switch_id, int *vbid, int *vid); -struct net_device *dsa_tag_8021q_find_port_by_vbid(struct net_device *conduit, - int vbid); +struct net_device *dsa_tag_8021q_find_user(struct net_device *conduit, + int source_port, int switch_id, + int vid, int vbid); 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; - if (source_port != -1 && switch_id != -1) - skb->dev = dsa_conduit_find_user(netdev, switch_id, source_port); - else if (vbid >= 1) - skb->dev = dsa_tag_8021q_find_port_by_vbid(netdev, vbid); - else - skb->dev = dsa_find_designated_bridge_port_by_vid(netdev, vid); + skb->dev = 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); - if (source_port != -1 && switch_id != -1) - skb->dev = dsa_conduit_find_user(netdev, switch_id, source_port); - else if (vbid >= 1) - skb->dev = dsa_tag_8021q_find_port_by_vbid(netdev, vbid); - else - skb->dev = dsa_find_designated_bridge_port_by_vid(netdev, vid); + skb->dev = 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; From patchwork Tue Feb 13 22:03:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pawel Dembicki X-Patchwork-Id: 13555785 X-Patchwork-Delegate: kuba@kernel.org 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 00E30768FB; Tue, 13 Feb 2024 22:06:13 +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=1707861975; cv=none; b=Dcieq+NpNxDezJK+Y71anhgt+bqTBE9reRlTKS0kO2z12e6I0+MiPduiP44jPM1aZOoI1lpTPjdL39fb3MouyGe3V9pXl1r0mPxky/ukba869O4Vsx+glvtnLN29t0m8HtlEueuKMEIIQ9MehqC7m6QSNd6NkeT1lIsvvaco/Z0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707861975; c=relaxed/simple; bh=BcCICgTKVZ2L1mhpJOxhdMkT8Ko96qUkVtelruR9JTo=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=C7Aa73XuvKvV1HCUzl49ix5sxlC+tTeyvdu3j1BOPAXXncJBCPjjN/SF0D5cedfyEVABwsnsqvZax/WInY6fGq0a3vinTIZ5hyr+QZMPoFXk/ruBSMw5VtkgXaIVMu1tp5nbrNS6yTDBOmgepMfXmFv8e9Y+SjpOMSGUx+1L2LI= 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=PB6Cvi0J; 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="PB6Cvi0J" Received: by mail-ej1-f51.google.com with SMTP id a640c23a62f3a-a3c1a6c10bbso421985766b.3; Tue, 13 Feb 2024 14:06:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707861972; x=1708466772; 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=5zhwy6nnxrLoJfssOqtXSEBpoc3WQJYfaNJ+nAZBweg=; b=PB6Cvi0JvhJWsEei7cgZ9eN0Oxjed+vO9xs0VWJ2gZVwtH/IJ8VdUHkz8wDR3pnL+K eQ0mP9T7LZ7Xq0/5a7YdmDOU839rSXnG8vSNLB1m0VKKCvzdXC82KsanF0DakZ95BnSF KDXulcX40xr8bKSyHz2Jm1NeOhFzyC7UcbfVBisi8VMoi/V+HKpcAd6MeIeFzj3DweCN fABT5RJAgCK5j2aQBA2V4q3h2oZljJc49vzcU+DEttzlunPEb0zgt0AdUMh7WFeM/P6F 0a0O9Vi8yXmPanHIATh9BFRgPsn+XYwGVOwpaMCp9PraAs+SUHpMZPE5KpjQL8Wt7AmL wRHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707861972; x=1708466772; 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=5zhwy6nnxrLoJfssOqtXSEBpoc3WQJYfaNJ+nAZBweg=; b=qpYb2G/R4l8rk1kb5fiQ67Ty5qIAHE/t9aw2yD9FhHg/FY2EFpQnt+i+pwKkfV8bLX ivMWg3JdLTuvmIBoDk7CoQ6zsIMCrUHZcxRFh8Wv2Rr5Sl21jPNRPchcZA/5NDfpm8co mZdSwSYquXhUDP4m/rOdojNtKvqc6f+RNXeEfoJKbHhSvMkqjJPaMxejTcxj1okW5SSN pq59jNZv/dMVwsu0ls3jrRpas7BfBBtUFMe+/qfhl6tBpCv1c2S8jQ4Z719/TKBikTok I+orp75IOgtLZh87v+D/TxZlOp+3AhR5CJD2rz84J3X84U2VdzRk78IJ4GVGItOyFfmI iJ7Q== X-Forwarded-Encrypted: i=1; AJvYcCVWasYGg17bnwB3Ik5uvffAtcZYYcIogwBBM98Pniczgno4E4/znlcMkOctxa16ZsKjlhSDXWK+YOG1nvmK6/SkN6EafGZB+pF3JCNB X-Gm-Message-State: AOJu0YyRGSE/l7vL+++WRQSo3JZ3e7DA7x2mHIsoojWrGcKsDWkBZdwk 5dWzOA7Q5qwb1SgpVAxCUMnZN13TMSCSGmNtuYSMgZVrkT45SQxClsRpm2q8RAU= X-Google-Smtp-Source: AGHT+IE1XY2ma3EOWQeH4tJiv0tWMUYK+zqgoJNdZT4vqJefcmDRHp7UdEF8KsK0v7dfB0oWDW7ckg== X-Received: by 2002:a17:906:5589:b0:a3c:10a4:7a91 with SMTP id y9-20020a170906558900b00a3c10a47a91mr547728ejp.13.1707861971934; Tue, 13 Feb 2024 14:06:11 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCVKRiR8sP59UO8EWHPP+/EBMRqEq6NFe3XE/hZAAghvCLSYCCtyN4lqBrrbOtkf50wGPZ4pO88D4vkD4NlLiYIZ0svDcMpWIZ7t5OtdiSV6p7X3lTWFMdLejjjme3+ux2XS/nB2M7wttJCUP387Wc77foUp5+cNyrcMAgSogTfuOq9ga44O0xGQvImvbE7t5VqJDhgUGgYeBKjKhDxUIuajWWcbFZvCBFRlyW41R/gxcuimFKgESZFwBM5dkkrm2Mm3iuXjPtXuWC4ADjXOW5pLnWf/xaIecwPlmwhp8ip2LmRo/RX87Kb/P68kcAUYfeXhXDxDH2Z2Te6ewPhmQKv6kYpQ5whrFtusL+6qYYdy6TOpGzUi2cOaTcvXnu5CLxVWiPJOAVlT7WwDDzNo5FjRzSgRZdQuOYT8aOc8DG2a/y2MIY7cMyRgXyj12Pzu0TFIsi6TW2qcZw== Received: from WBEC325.dom.lan ([185.188.71.122]) by smtp.gmail.com with ESMTPSA id p12-20020a170906b20c00b00a3bdf8ae86asm1706800ejz.10.2024.02.13.14.06.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Feb 2024 14:06:11 -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 v4 12/15] net: dsa: vsc73xx: introduce tag 8021q for vsc73xx Date: Tue, 13 Feb 2024 23:03:25 +0100 Message-Id: <20240213220331.239031-13-paweldembicki@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240213220331.239031-1-paweldembicki@gmail.com> References: <20240213220331.239031-1-paweldembicki@gmail.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org 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 --- 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 | 69 +++++++++++++++++++++++++++++++++++++ 4 files changed, 78 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 enum dsa_tag_protocol { DSA_TAG_PROTO_NONE = DSA_TAG_PROTO_NONE_VALUE, @@ -86,6 +87,7 @@ enum dsa_tag_protocol { DSA_TAG_PROTO_RTL8_4T = DSA_TAG_PROTO_RTL8_4T_VALUE, DSA_TAG_PROTO_RZN1_A5PSW = DSA_TAG_PROTO_RZN1_A5PSW_VALUE, DSA_TAG_PROTO_LAN937X = DSA_TAG_PROTO_LAN937X_VALUE, + DSA_TAG_PROTO_VSC73XX_8021Q = DSA_TAG_PROTO_VSC73XX_8021Q_VALUE, }; 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. +config NET_DSA_TAG_VSC73XX_8021Q + tristate "Tag driver for Microchip/Vitesse VSC73xx family of switches, using 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) += tag_rtl8_4.o obj-$(CONFIG_NET_DSA_TAG_RZN1_A5PSW) += tag_rzn1_a5psw.o obj-$(CONFIG_NET_DSA_TAG_SJA1105) += tag_sja1105.o obj-$(CONFIG_NET_DSA_TAG_TRAILER) += tag_trailer.o +obj-$(CONFIG_NET_DSA_TAG_VSC73XX_8021Q) += tag_vsc73xx_8021q.o obj-$(CONFIG_NET_DSA_TAG_XRS700X) += tag_xrs700x.o # 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..0bf150a10576 --- /dev/null +++ b/net/dsa/tag_vsc73xx_8021q.c @@ -0,0 +1,69 @@ +// SPDX-License-Identifier: GPL-2.0 OR MIT +/* Copyright (C) 2023 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 = dsa_user_to_port(netdev); + u16 queue_mapping = skb_get_queue_mapping(skb); + u16 tx_vid = dsa_tag_8021q_standalone_vid(dp); + u8 pcp; + + if (skb->offload_fwd_mark) { + unsigned int bridge_num = dsa_port_bridge_num_get(dp); + struct net_device *br = dsa_port_bridge_dev_get(dp); + + if (br_vlan_enabled(br)) + return skb; + + tx_vid = dsa_tag_8021q_bridge_vid(bridge_num); + } + + pcp = 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 = -1, switch_id = -1, vbid = -1, vid = -1; + + if (skb_vlan_tag_present(skb)) { + /* Normal traffic path. */ + dsa_8021q_rcv(skb, &src_port, &switch_id, &vbid, &vid); + } else { + netdev_warn(netdev, "Couldn't decode source port\n"); + return NULL; + } + + skb->dev = 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 = { + .name = VSC73XX_8021Q_NAME, + .proto = DSA_TAG_PROTO_VSC73XX_8021Q, + .xmit = vsc73xx_xmit, + .rcv = vsc73xx_rcv, + .needed_headroom = VLAN_HLEN, + .promisc_on_conduit = true, +}; + +MODULE_LICENSE("GPL"); +MODULE_ALIAS_DSA_TAG_DRIVER(DSA_TAG_PROTO_VSC73XX_8021Q, VSC73XX_8021Q_NAME); + +module_dsa_tag_driver(vsc73xx_8021q_netdev_ops); From patchwork Tue Feb 13 22:03:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pawel Dembicki X-Patchwork-Id: 13555786 X-Patchwork-Delegate: kuba@kernel.org 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 5C5C67764A; Tue, 13 Feb 2024 22:06:19 +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=1707861981; cv=none; b=S5Na0rNvXwKqUyClSPsE2kwDPjk5eL66B6lJfT3+L+dsaVHjM7Q0Y1L2xaVnwed8wtZypwahuSCnGUo1cOVgs7zsP8yF/P847AjBfOFx1jZMoR4Rx7Kniy9vlGfZjMVVQX89vAjd1ZVyC83f/pEeSYcf81tCYj39NY66HIi8Qco= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707861981; c=relaxed/simple; bh=t5Q6M/UoaVsi7X00J7NumI0UnmtqZT+dvCNVTiQagf4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=CUSPxvRt5HGTN2Twvlz5wHwnLJcdeNdm32h5/4gpSx7CA1FeZXyHgGI2WMC/rgIv8sYsr+P+ER2n/OBRisHYU7w/XW7vrt+8OnolbLtlGV5OZaT2JviCfvVOCW+PaCXVJTEOsbU7bWB6/YaaS5ypr95ag/k19fo/WQ8pBVZ0D64= 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=FO30Vd2S; 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="FO30Vd2S" Received: by mail-ed1-f53.google.com with SMTP id 4fb4d7f45d1cf-55f50cf2021so6431449a12.1; Tue, 13 Feb 2024 14:06:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707861977; x=1708466777; 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=mfZ9Os2zb9RyFiipFThksRCzRqGevVK9igii64D1Y2Q=; b=FO30Vd2S+BfeIPNTWA9vGw/ywpZ39RQp9M15jUADxrUDEmuNYfkftHhzfv6/4nxEyo 0GyYi1CNWx95GDG56yMqjxbM+IeAkSOp55J7rKYz6QTze8wV+7y46SjEJvq+pMhwcJzw +zJuM5bZNe+sKzcm5nKrj4bqYWZWJBVAC898XwG27EhtPzOHZrs83KK/p74gVCyf0E/p z9InfZL/5BJfJNZRrxYIHQrdaCKEaDmLn+VdBwjJrXUa/38ZZXi6uBdHnNyggU8hXYcZ 71FcHHBK4nBtteBuZjHYfJ9KffAckMaNANywD/tFxAMZqg9O5jBmjcdgfbPL87BmAzI6 2IUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707861977; x=1708466777; 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=mfZ9Os2zb9RyFiipFThksRCzRqGevVK9igii64D1Y2Q=; b=jyTpvhzg0J3sfjFojM1ZFGm1PHV2i8yOc7JcZjgGvo/3dl2uj+nyhNPaDZSDosn0sm f4660EHVWHON//82tFbPeEMMmFncLSNNHEdERkLAvWByYNDC8evM5VWu3fW9M1ALnDhP 1Jr6K+agE0GPvrUesqzNs0+MfkI6NhdsQWNqsxl5IoiILLwdSnr+CBsX/20KHMF+0Mfs PJi3PXWX9CV2S36lAVOV8orSUvR55K1NO64OFd+3lsG7XZUt3eTI0ER9mQX+1RanZ9QT SqifqyGx9ULUDKEtYiM+k2dOqIG1ICXFiGqoIU4iCncyGN/r8UuC90rh1vDJRFOq/T2d mhhw== X-Forwarded-Encrypted: i=1; AJvYcCWJ+vHVKPY7mvqdTmoyiYh7Ht909JkBmtE86JJTJamt2VJ0ckD5QQO81xOwRa1Jg2StK8JRySdE6D7lsb9CEW8biqtvtPz5MnnqhKO5 X-Gm-Message-State: AOJu0YwjV6r7QAmfSkKu+X/0fy6/2jzm6qGlybsNG5/xhCFDegwVDLlW tLNzDVfd8h3MbHXub+DHER7IYOONJNu4SWSPpcxoPUJa9NMrCIkd2x34hu2YCb8= X-Google-Smtp-Source: AGHT+IEwtdpk55uDslVpOwrs5rxinxSy17YGrsurMotrSsgq+pIKKHQ396gDqGUi5bi1nfHKiWFtag== X-Received: by 2002:a17:906:7199:b0:a3c:f91d:ee10 with SMTP id h25-20020a170906719900b00a3cf91dee10mr425752ejk.5.1707861977153; Tue, 13 Feb 2024 14:06:17 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCX6RqQz2uCAeYoCezfNB55B61g9qnT055Q+w6LgTYjMLmCHJDRKeqaCjh8Wks6guhNtKuKKKpwUQmp5MtFI2aV+RH8B3c4maA+Jtlu2lYtRIfsxXIjO36WXNTx1/p4a1CGo6IhOJAkCP12sKGD0SeX0AvGWwHnfzm/4yZU9SfLSXNOsDFuFO7JikvTQfIZwETRN1rF7OqK5x1ej3ZZKe4X2/ctbXMIPob8mB/O+jT7JyLwURQoLDt3KSNtJZ6eEiDYyYNuIObM8VOuoQkXGuJMLnKh3XCwKXYq7QRyzRG6MtGXIw3GIBCP0VA6tdZCvxGh7JHgx/ms9Uc/qNP3sZE64R0v9M+CywwE3Gxw8iLNKrWDsz+LJGN5tp9GMdgQPRwkeBz5rK6BHqUnvYRcwawr6x4MaOz9wfeM9vAW5NSzAXxPWdHHcniXtk/TYFX9cEBzoQOf/dksHiA== Received: from WBEC325.dom.lan ([185.188.71.122]) by smtp.gmail.com with ESMTPSA id p12-20020a170906b20c00b00a3bdf8ae86asm1706800ejz.10.2024.02.13.14.06.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Feb 2024 14:06:16 -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 v4 13/15] net: dsa: vsc73xx: Implement vsc73xx 8021q tagger Date: Tue, 13 Feb 2024 23:03:26 +0100 Message-Id: <20240213220331.239031-14-paweldembicki@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240213220331.239031-1-paweldembicki@gmail.com> References: <20240213220331.239031-1-paweldembicki@gmail.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org 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. The tag driver introduces the most basic functionality required for proper tagging support. Signed-off-by: Pawel Dembicki --- 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 | 38 ++++++++++++++++++++++++-- 2 files changed, 37 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 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/vitesse-vsc73xx-core.c index 6c7bd1c200b4..9f94ae8c763a 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 @@ -588,7 +589,7 @@ static enum dsa_tag_protocol vsc73xx_get_tag_protocol(struct 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; } static int vsc73xx_wait_for_vlan_table_cmd(struct vsc73xx *vsc) @@ -670,7 +671,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 = ds->priv; - int i; + int i, ret; dev_info(vsc->dev, "set up the switch\n"); @@ -739,6 +740,12 @@ static int vsc73xx_setup(struct dsa_switch *ds) mdelay(50); + rtnl_lock(); + ret = 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); @@ -1504,6 +1511,31 @@ static int vsc73xx_port_vlan_del(struct dsa_switch *ds, int port, return 0; } +static int vsc73xx_tag_8021q_vlan_add(struct dsa_switch *ds, int port, u16 vid, + u16 flags) +{ + bool untagged = flags & BRIDGE_VLAN_INFO_UNTAGGED; + bool pvid = flags & BRIDGE_VLAN_INFO_PVID; + struct vsc73xx *vsc = ds->priv; + bool operate_on_storage; + + operate_on_storage = !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 = 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 = ds->priv; @@ -1632,6 +1664,8 @@ static const struct dsa_switch_ops vsc73xx_ds_ops = { .port_vlan_add = vsc73xx_port_vlan_add, .port_vlan_del = vsc73xx_port_vlan_del, .phylink_get_caps = vsc73xx_phylink_get_caps, + .tag_8021q_vlan_add = vsc73xx_tag_8021q_vlan_add, + .tag_8021q_vlan_del = vsc73xx_tag_8021q_vlan_del, }; static int vsc73xx_gpio_get(struct gpio_chip *chip, unsigned int offset) From patchwork Tue Feb 13 22:03:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pawel Dembicki X-Patchwork-Id: 13555787 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-ej1-f41.google.com (mail-ej1-f41.google.com [209.85.218.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 C265A77A08; Tue, 13 Feb 2024 22:06:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707861985; cv=none; b=VtcXVl7BfyR0y1kP3do183A7sA5GXUFzA80IwPkZcEA1cYZ6+rCsJCa84V8efLYW639uXRoZQTDRgjvPc/MciVDFNviixZLTQTD787oM1X+GH7Sew/SWaXbLE5y1XaiH7Bk2emOrE6NKU1QENChObHN5QxazquPFik42LmXhYeE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707861985; c=relaxed/simple; bh=hPoqurwpt0Nzd4K48f24Meg4YCMaFciuOSzhb8zDw9M=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=GSdWRA/QsSnyJFONPbAqYCNM+lsPClcJsH9iq0zhqP6xVK28glCMPvFbMgqBza+yhvo4XRswF7XQxSQU02OZyfl2ot4fg/cxHN036Bh8pTf4TO1iA0v5TNArOgsqUUUIomhaCaSpPiymm88OZqRDFxQLTqcIyBybvHYKm4lUHUQ= 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=ft7QnrOO; arc=none smtp.client-ip=209.85.218.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="ft7QnrOO" Received: by mail-ej1-f41.google.com with SMTP id a640c23a62f3a-a3d39b2c269so14278066b.3; Tue, 13 Feb 2024 14:06:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707861982; x=1708466782; 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=5lfZKWMdVX06rkt/a2RPzvoVKkcprfsWZW9EdATKrus=; b=ft7QnrOOe5JHSaAnVzT1evB3OFB5yfsZepKX/hYRC6p9YF0MntKZX9aQGzhP6IUggK DFRmuzlfHL2rbB1vkD0n5cuD4ZuwqOYoph1sXVY/LxB74SkYiwDD38XVDUk2BmPKJlCx +HF38OKglRghokU9/1b8+8uRLPqV3zMWty1KXiOmWk14Ckut/Ra/gkvT2Z+zWkepqH+v 3m/3ZIEJYtgg7yhAekcRhGBWOuU/zQtzUeC+8tz2VLnpsOonJZ/kXwiRE/bBOa0abGN1 gb/OYoFCwTxTdFpfm3pk59RAYDYOUTSeqAvV95aeM9ZUe8WFu3FRT9N4/ZfkOo+P+Zh6 9Vgg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707861982; x=1708466782; 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=5lfZKWMdVX06rkt/a2RPzvoVKkcprfsWZW9EdATKrus=; b=fptdPLAMdjUwTEDauSuf5518CL5jbzsgJzKAMEluYdRhqe4JnTpheV73vckOZFyxRT +W82BpiuPrCknRZ1/npaoQvxGwMHYxMdTT82L8JxqqlqMIBQUo28tXBghS5+89+LTk+W ED7nS+0K3Xtnlyy8hc6t3vVxlV35mBAmswuyRoLo6cr7sSAXx14wfxpKyYkecZM15bKL XJHOiYPfgS6Jn10smboEqZlESG/30BAXKqm+uH66B9wM1YY8PMYGz4Veuil303Bm9czu kYWHInPqslU1PHpQDBF7L9DnSz89+beh2GBI9ICLBKwRmX+7kEo5bPtILnTvabqzod+M W5+A== X-Forwarded-Encrypted: i=1; AJvYcCW5U5PS9aRUoOlv2fMPzMUoguEHah7boxtxPu3airIuLQQV6DyhCiQZEXMupxNQ3TuRYijyzkHOFs86Ttu+OpdQls96rEhizURJeGzS X-Gm-Message-State: AOJu0Yz5GC2xuN/ibWsEyXbKjsAdkVNNFenI/j4BospKJ5sznFP7MGQA lVTFk33IxFo7eR7xgNDXOe6Uj4cFXV13IdG2k9/HCIU6H0ScdsG8kzTf3tNDQAs= X-Google-Smtp-Source: AGHT+IGbSm2u1unhRkzRHw0LxILh3z40D0Vc98mIpZQbe6gu8tWK35H7CtRrYmJjUWw1x5EPkB4/VA== X-Received: by 2002:a17:906:f10a:b0:a3c:fc34:d5c7 with SMTP id gv10-20020a170906f10a00b00a3cfc34d5c7mr435072ejb.61.1707861981841; Tue, 13 Feb 2024 14:06:21 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCXlF7wPfzwC0FthiObG9mNggVsgoTXaW6orPkdbuVmifEyHR9vHn1/XxFTlRk3S9x1v+rPWep99t3BhAdOJLT3qtCEjLKegPqPeQlJytzkvL2nFaY1C6oJ65cnsP6YJ+shZidDyisFRajnSReRVWkMPw9IzfdjJeSJK0QbJJWaZ3M0wXflSrF3TLrimvcggo/FfraRWS3FCuV4OuRvuRU6pJclAwWKHxi4/mIfhDeUUW/44RsLIJvgF6y2QhAkGs0WBFKQK1Z8+Dl+G0B0LdZ1OT3MUnmFOBRH8sM84PZbJMGmgKxS+cuVH2ZZdgjFOD1X7bi9jocNMZGwqFVtpA9M8Q0IygPTXaUyq1qrucZHWn82432b/v61I6prmM93L/JAf46kvb8iiGf+a/W5hBUUAem1oHjZ76AEZalmnVjaE2HAgnCltP/n+2KHKMJlMD4mJ/1Tbzt6O3A== Received: from WBEC325.dom.lan ([185.188.71.122]) by smtp.gmail.com with ESMTPSA id p12-20020a170906b20c00b00a3bdf8ae86asm1706800ejz.10.2024.02.13.14.06.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Feb 2024 14:06:21 -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 v4 14/15] net: dsa: Define max num of bridges in tag8021q implementation Date: Tue, 13 Feb 2024 23:03:27 +0100 Message-Id: <20240213220331.239031-15-paweldembicki@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240213220331.239031-1-paweldembicki@gmail.com> References: <20240213220331.239031-1-paweldembicki@gmail.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org 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 --- 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/sja1105/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 = true; ds->untag_bridge_pvid = true; ds->fdb_isolation = true; - /* tag_8021q has 3 bits for the VBID, and the value 0 is reserved */ - ds->max_num_bridges = 7; + ds->max_num_bridges = DSA_TAG_8021Q_MAX_NUM_BRIDGES; /* Advertise the 8 egress queues */ ds->num_tx_queues = 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 +/* 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); void dsa_tag_8021q_unregister(struct dsa_switch *ds); From patchwork Tue Feb 13 22:03:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pawel Dembicki X-Patchwork-Id: 13555788 X-Patchwork-Delegate: kuba@kernel.org 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 636E977F39; Tue, 13 Feb 2024 22:06:29 +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=1707861991; cv=none; b=RCiUEeGIEpb+eLZ9Q84RR/oT73xB7PKfmSOT7h4Q5qrezA1Altg8lx4j8mHb8x7VprW0owdjSDh9GO2Y1ZuvKa3OdtBf8jPrAdBDyWUQqml9pF6H+qEv3O1T6Id1vSSau7llUWwuH3s5wuhoGJcR96M9OynBLvERcUfsoFWmIAA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707861991; c=relaxed/simple; bh=tqxykmJnjc+t9OZKEIA9fiqhEZrLIlF9e6epDeBzR7U=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=QNpn6mhxGDw2J5CqZOxgYZZ1uCkdTkeFg/qmiDFEq78L1+fq9oM4w0zqnhdrvU9OkongQywk+phuXlKVCGCUpHPhanH/08nvc+DVmgw/00YXd2ickxKB6Cf9CCaTpVizEgmLSKG6pn9jfnMNuU7TBqKdbtosmJTqUxFLHzP5TqU= 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=iRCPqLSu; 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="iRCPqLSu" Received: by mail-ej1-f53.google.com with SMTP id a640c23a62f3a-a3cc2f9621aso150031066b.1; Tue, 13 Feb 2024 14:06:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707861987; x=1708466787; 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=vdHuk5ughM3e+Z5D0Z5R0C1DnmENSSx3TlDfYYFTKI0=; b=iRCPqLSuX0xy8+EDAjaF/U5QDF/XozMFI/zWd5cUbmtB0eu7KOU/4yzYyDUxyZzGJx 4wVczj1aZ9fRNNdiRjE/7IugYARioPj/6DFekiVWvRO21FpgCxxvCFK2qy3rGrRoNZXD oRFECNcvml4LjR5npIXfh9DA/bdq101mIf4YGSzOIZx9ZQYS18Il54dNkZX39YixXglX oSL0sscpOc7UVyhZyF+C562jmWGtGBo6oqBFANw5KNUAZvadgp6avOEr8k80bqBViP2v slyIbROcFRyhESTGK/hWV5EuH953SMQ/A2/F5XRsFq9RTAEqr2iO/xXIkLcXSt9rP1NK a3mg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707861987; x=1708466787; 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=vdHuk5ughM3e+Z5D0Z5R0C1DnmENSSx3TlDfYYFTKI0=; b=FeNPbkJL3MaFcP0sKXNagU4Kx+sviehGx/nPmB6lTPKnEvbR48IcoYz3TwugrW0DW8 dZ0t6RCAwTzh/CfUbb36ol70HJA0cIG5xhuAymGV727lLIUGEbYGcrnCsUpss9EuqhHy FLlq9pkgZZ+XWX3bzHGR2CgDoRLakzjLQCt2vuu808d0B8KwOqO24Ue56Ac2+WPeP1hM un0MN9YJ3nl/PskYqaFXha9VFTQFu4vd5UPNG8n841Cg0HHgMSzvClnTAw2wRuK/aC1A KKMRkrN4Gkgd/71c5vrvK/oXjWh7YIbslU9KWs/fyzeuTWGkzYVDFgPyx6iFBll2x8i6 jpEw== X-Forwarded-Encrypted: i=1; AJvYcCXPfLjeiEHt2zg+GlOFYQSV+mUWPxDShULfRl3z98aqXDztIZ2ZpLjQrxKq50dnCgMe6YqmYmHrEqX6rYZHCshURZLLFLdJ7rM9RBU4 X-Gm-Message-State: AOJu0YxEamZzaaue15j8yqufNcL8jrauKOqb5WxLpGAIU28cZJEbWt9Y FLTI3bdsV0eXDV7bge1BQW1mfCUgC2RGsjLxLGO+xm5AiN3m+tM8r3rVTYDG3AM= X-Google-Smtp-Source: AGHT+IFGujdPsKw3SRnEv1IWCGv78SR/COTAjTrsM2RTRpPIwr+ywNUzEnrCqFcwh1VGfw/CdT3xHA== X-Received: by 2002:a17:906:7c9:b0:a3c:1402:e042 with SMTP id m9-20020a17090607c900b00a3c1402e042mr388757ejc.37.1707861987378; Tue, 13 Feb 2024 14:06:27 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCWTLZa1aLuYKMp0xw8j6FTHAlWMyQ1Oc2lhyEpjW3LHjjlbWFrJdDnAVnsGJrsvYo7wHyP30IbdL2Obfx2lXqsGMVdNUBfTk5sCdsXQc2nbmpv7mdchHGxjVq63UZTjEy8k+6wx/yO/eOtYXRETJXTSvsG4S9czLiIs0yHLKgB99kJBX714Gn/gxP3KZZhUP9yRuzDBJ9rBV46NajErjjDqDYPkoq/kQQXsGMKBArWNm3rm5AeJ2QvgpleiUC0U8sgod/Vgp4nh/4v/HsSqlbwhB4Ys7JFNLpKmUzmJFFR5qWi7wqFCFrYs6wK5wVNXXSaL80piyORBQxZ11AGTOaWTc9JtOK16GOS9tQF+6SjgeYVEhOrrKexNojKTlY+y0sD7pgezqPRYF66WbiO3+Ul0HwrdCx6CEUUlbLCWkh0JuF8HB/86i3Gpwql0IBovmtDZA50suV5g5g== Received: from WBEC325.dom.lan ([185.188.71.122]) by smtp.gmail.com with ESMTPSA id p12-20020a170906b20c00b00a3bdf8ae86asm1706800ejz.10.2024.02.13.14.06.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Feb 2024 14:06:27 -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 v4 15/15] net: dsa: vsc73xx: Add bridge support Date: Tue, 13 Feb 2024 23:03:28 +0100 Message-Id: <20240213220331.239031-16-paweldembicki@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240213220331.239031-1-paweldembicki@gmail.com> References: <20240213220331.239031-1-paweldembicki@gmail.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org 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 --- 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/vitesse-vsc73xx-core.c index 9f94ae8c763a..ade90a48c53f 100644 --- a/drivers/net/dsa/vitesse-vsc73xx-core.c +++ b/drivers/net/dsa/vitesse-vsc73xx-core.c @@ -675,6 +675,9 @@ static int vsc73xx_setup(struct dsa_switch *ds) dev_info(vsc->dev, "set up the switch\n"); + ds->untag_bridge_pvid = true; + ds->max_num_bridges = DSA_TAG_8021Q_MAX_NUM_BRIDGES; + /* Issue RESET */ vsc73xx_write(vsc, VSC73XX_BLOCK_SYSTEM, 0, VSC73XX_GLORESET, VSC73XX_GLORESET_MASTER_RESET); @@ -1536,6 +1539,22 @@ static int vsc73xx_tag_8021q_vlan_del(struct dsa_switch *ds, int port, u16 vid) return vsc73xx_update_vlan_table(vsc, port, vid, false); } +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 = 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 = ds->priv; @@ -1657,6 +1676,8 @@ static const struct dsa_switch_ops vsc73xx_ds_ops = { .port_setup = vsc73xx_port_setup, .port_enable = vsc73xx_port_enable, .port_disable = vsc73xx_port_disable, + .port_bridge_join = vsc73xx_port_bridge_join, + .port_bridge_leave = vsc73xx_port_bridge_leave, .port_change_mtu = vsc73xx_change_mtu, .port_max_mtu = vsc73xx_get_max_mtu, .port_stp_state_set = vsc73xx_port_stp_state_set,