2024-03-20 18:57:31

by Andrew Lunn

[permalink] [raw]
Subject: Re: [PATCH] net: dsa: mv88e6xxx: add warning for truncated mdio bus id

> With separators ('!') we have:
> cp0!config-space@f2000000!mdio@12a200!ethernet-switch@4!mdio
> cp0!config-space@f2000000!mdio@12a200!ethernet-switch@4!mdio-external
> Truncated to MII_BUS_ID_SIZE:
> cp0!config-space@f2000000!mdio@12a200!ethernet-switch@4!mdi
> cp0!config-space@f2000000!mdio@12a200!ethernet-switch@4!mdi

This has been made worse by the DT maintainers wanting
ethernet-switch@4, not switch@4. And i guess config-space was also
something shorter in the past.

I think your idea of cropping from the beginning, not the end, is in
general a good solution. However, is there any danger of

cp0!config-space@f2000000!mdio@12a200!ethernet-switch@4!mdio-external

and

cp1!config-space@f2000000!mdio@12a200!ethernet-switch@4!mdio-external

I assume the two instances of cp have the same peripherals, at the
same address?

Another option would be if the name needs to be truncated, use the
fallback as if there was no np:

bus->name = "mv88e6xxx SMI";
snprintf(bus->id, MII_BUS_ID_SIZE, "mv88e6xxx-%d", index++);

That at least gives you unique names.

Andrew


2024-03-21 10:27:13

by Josua Mayer

[permalink] [raw]
Subject: Re: [PATCH] net: dsa: mv88e6xxx: add warning for truncated mdio bus id

Am 20.03.24 um 19:57 schrieb Andrew Lunn:
>> With separators ('!') we have:
>> cp0!config-space@f2000000!mdio@12a200!ethernet-switch@4!mdio
>> cp0!config-space@f2000000!mdio@12a200!ethernet-switch@4!mdio-external
>> Truncated to MII_BUS_ID_SIZE:
>> cp0!config-space@f2000000!mdio@12a200!ethernet-switch@4!mdi
>> cp0!config-space@f2000000!mdio@12a200!ethernet-switch@4!mdi
> This has been made worse by the DT maintainers wanting
> ethernet-switch@4, not switch@4. And i guess config-space was also
> something shorter in the past.
>
> I think your idea of cropping from the beginning, not the end, is in
> general a good solution. However, is there any danger of
>
> cp0!config-space@f2000000!mdio@12a200!ethernet-switch@4!mdio-external
>
> and
>
> cp1!config-space@f2000000!mdio@12a200!ethernet-switch@4!mdio-external
Since these will appear as links in /sys/bus/mdio_bus/devices,
this danger exists.
If the prefix is too similar, we can run into duplicates also when
cropping from the front.

So we could crop at the front and reduce likelihood of this situation,
but (imo) should still print a warning since it is not working as intended.

>
> I assume the two instances of cp have the same peripherals, at the
> same address?
In this particular platform the config-space layer uses the actual base address for each cp:
cp0!config-space@f2000000
cp1!config-space@f4000000
cp2!config-space@f6000000
>
> Another option would be if the name needs to be truncated, use the
> fallback as if there was no np:
>
> bus->name = "mv88e6xxx SMI";
> snprintf(bus->id, MII_BUS_ID_SIZE, "mv88e6xxx-%d", index++);
>
> That at least gives you unique names.
This ensures a unique suffix within a branch of device-tree.
It could still collide with same structure on a cp1 or cp2.


The platform where this is triggered does not (currently) require declaring
external mdio bus (because hardware bug renders that bus useless).
For now my priority is helping future developers running into this.