Re: [RFC PATCH net-next 06/11] net: dsa: microchip: lan937x: get cascade tag protocol

From: Vladimir Oltean
Date: Fri Feb 03 2023 - 18:31:06 EST


On Thu, Feb 02, 2023 at 06:29:25PM +0530, Rakesh Sankaranarayanan wrote:
> Update ksz_get_tag_protocol to return separate tag protocol if
> switch is connected in cascade mode. Variable ds->dst->last_switch
> will contain total number of switches registered. For cascaded
> connection alone, this will be more than zero.

Nope, last_switch does not contain the total number of switches
registered, but the index of the last switch in this tree. DSA does not
assume that the indices are consecutive.

If you make any assumption in the driver regarding switch numbering in a
cascade setup, it is an assumption that a device tree writer who is not
you needs to know about. So you must document it in
Documentation/devicetree/bindings/net/dsa/microchip,lan937x.yaml.

>
> Signed-off-by: Rakesh Sankaranarayanan <rakesh.sankaranarayanan@xxxxxxxxxxxxx>
> ---
> drivers/net/dsa/microchip/ksz_common.c | 6 +++++-
> 1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/net/dsa/microchip/ksz_common.c b/drivers/net/dsa/microchip/ksz_common.c
> index adf8391dd29f..2160a3e61a5a 100644
> --- a/drivers/net/dsa/microchip/ksz_common.c
> +++ b/drivers/net/dsa/microchip/ksz_common.c
> @@ -2567,9 +2567,13 @@ static enum dsa_tag_protocol ksz_get_tag_protocol(struct dsa_switch *ds,
> dev->chip_id == KSZ9567_CHIP_ID)
> proto = DSA_TAG_PROTO_KSZ9477;
>
> - if (is_lan937x(dev))
> + if (is_lan937x(dev)) {
> proto = DSA_TAG_PROTO_LAN937X_VALUE;
>
> + if (ds->dst->last_switch)
> + proto = DSA_TAG_PROTO_LAN937X_CASCADE_VALUE;
> + }

Also nope, see the comment on patch 1.

> +
> return proto;
> }
>
> --
> 2.34.1
>