2021-01-13 12:58:40

by Gilles Doffe

[permalink] [raw]
Subject: [PATCH net 2/6] net: dsa: ksz: move tag/untag action

Move tag/untag action at the end of the function to avoid
tagging or untagging traffic if only vlan 0 is handled.

Signed-off-by: Gilles DOFFE <[email protected]>
---
drivers/net/dsa/microchip/ksz8795.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/net/dsa/microchip/ksz8795.c b/drivers/net/dsa/microchip/ksz8795.c
index 6962ba4ee125..4b060503b2e8 100644
--- a/drivers/net/dsa/microchip/ksz8795.c
+++ b/drivers/net/dsa/microchip/ksz8795.c
@@ -840,8 +840,6 @@ static void ksz8795_port_vlan_add(struct dsa_switch *ds, int port,
u8 fid, member, valid;
int ret;

- ksz_port_cfg(dev, port, P_TAG_CTRL, PORT_REMOVE_TAG, untagged);
-
for (vid = vlan->vid_begin; vid <= vlan->vid_end; vid++) {
if (vid == 0)
continue;
@@ -874,6 +872,8 @@ static void ksz8795_port_vlan_add(struct dsa_switch *ds, int port,
vid |= new_pvid;
ksz_pwrite16(dev, port, REG_PORT_CTRL_VID, vid);
}
+
+ ksz_port_cfg(dev, port, P_TAG_CTRL, PORT_REMOVE_TAG, untagged);
}

static int ksz8795_port_vlan_del(struct dsa_switch *ds, int port,
--
2.25.1


2021-01-14 01:54:57

by Vladimir Oltean

[permalink] [raw]
Subject: Re: [PATCH net 2/6] net: dsa: ksz: move tag/untag action

On Wed, Jan 13, 2021 at 01:45:18PM +0100, Gilles DOFFE wrote:
> Move tag/untag action at the end of the function to avoid
> tagging or untagging traffic if only vlan 0 is handled.
>
> Signed-off-by: Gilles DOFFE <[email protected]>
> ---

No matter how much you move the assignment around, there's no escaping
the truth that the Tag Removal bit in the Port Registers affects all
VLANs that egress a port, whereas the BRIDGE_VLAN_INFO_UNTAGGED flag
controls egress VLAN stripping per VLAN. Sorry, if you work with broken
hardware, you might as well treat it accordingly too.

And as to why the moving around would make any difference in the first
place, you need to do a better job explaining that. There is nothing
that prevents PORT_REMOVE_TAG from being written to the port, regardless
of the order of operations. Unless the order matters?

2021-01-14 01:57:14

by Florian Fainelli

[permalink] [raw]
Subject: Re: [PATCH net 2/6] net: dsa: ksz: move tag/untag action

On 1/13/21 4:45 AM, Gilles DOFFE wrote:
> Move tag/untag action at the end of the function to avoid
> tagging or untagging traffic if only vlan 0 is handled.
>
> Signed-off-by: Gilles DOFFE <[email protected]>
> ---
> drivers/net/dsa/microchip/ksz8795.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/net/dsa/microchip/ksz8795.c b/drivers/net/dsa/microchip/ksz8795.c
> index 6962ba4ee125..4b060503b2e8 100644
> --- a/drivers/net/dsa/microchip/ksz8795.c
> +++ b/drivers/net/dsa/microchip/ksz8795.c
> @@ -840,8 +840,6 @@ static void ksz8795_port_vlan_add(struct dsa_switch *ds, int port,
> u8 fid, member, valid;
> int ret;
>
> - ksz_port_cfg(dev, port, P_TAG_CTRL, PORT_REMOVE_TAG, untagged);
> -
> for (vid = vlan->vid_begin; vid <= vlan->vid_end; vid++) {
> if (vid == 0)
> continue;
> @@ -874,6 +872,8 @@ static void ksz8795_port_vlan_add(struct dsa_switch *ds, int port,
> vid |= new_pvid;
> ksz_pwrite16(dev, port, REG_PORT_CTRL_VID, vid);
> }
> +
> + ksz_port_cfg(dev, port, P_TAG_CTRL, PORT_REMOVE_TAG, untagged);

You should be giving an example how this fails, because it is not
immediately obvious why this fixes a problem and how it does fix it,
especially for VID == 0 given that the loop would be skipped over.
--
Florian