[RFC,net-next,02/11] net: dsa: microchip: lan937x: update SMI index
Commit Message
Current DSA driver register mdio interface for a port in the
format of SMI-switch_index:port_number, switch_index is derived
using variable ds->index. For a single switch ds->index will be
always zero, and for cascaded switch, ds->index should be one.
But it is found that ds->index is getting updated only after
mdio_register stage. Update mdio_register to use variable directly
from device tree using "dsa,member" identifier.
Signed-off-by: Rakesh Sankaranarayanan <rakesh.sankaranarayanan@microchip.com>
---
drivers/net/dsa/microchip/ksz_common.c | 6 +++++-
drivers/net/dsa/microchip/ksz_common.h | 1 +
2 files changed, 6 insertions(+), 1 deletion(-)
Comments
On Thu, Feb 02, 2023 at 06:29:21PM +0530, Rakesh Sankaranarayanan wrote:
> Current DSA driver register mdio interface for a port in the
> format of SMI-switch_index:port_number, switch_index is derived
> using variable ds->index. For a single switch ds->index will be
> always zero, and for cascaded switch, ds->index should be one.
> But it is found that ds->index is getting updated only after
> mdio_register stage. Update mdio_register to use variable directly
> from device tree using "dsa,member" identifier.
>
> Signed-off-by: Rakesh Sankaranarayanan <rakesh.sankaranarayanan@microchip.com>
> ---
Impossible, check again.
The call path is:
ksz_switch_register()
-> dsa_register_switch()
-> dsa_switch_probe()
-> dsa_switch_parse_of()
-> dsa_switch_parse_member_of()
-> sets ds->index
-> dsa_tree_setup()
-> dsa_tree_setup_switches()
-> dsa_switch_setup()
-> ksz_setup()
-> ksz_mdio_register()
-> you claim ds->index isn't set
You don't even need to be an expert on the code path, you can grep for
"ds->index = ", put a dump_stack() where it's set and one where you need
it, and compare in the stack trace which functions are common and where
they diverge.
@@ -1882,7 +1882,7 @@ static int ksz_mdio_register(struct ksz_device *dev)
bus->read = ksz_sw_mdio_read;
bus->write = ksz_sw_mdio_write;
bus->name = "ksz slave smi";
- snprintf(bus->id, MII_BUS_ID_SIZE, "SMI-%d", ds->index);
+ snprintf(bus->id, MII_BUS_ID_SIZE, "SMI-%d", dev->smi_index);
bus->parent = ds->dev;
bus->phy_mask = ~ds->phys_mii_mask;
@@ -3136,6 +3136,7 @@ struct ksz_device *ksz_switch_alloc(struct device *base, void *priv)
{
struct dsa_switch *ds;
struct ksz_device *swdev;
+ u32 sw_idx[2];
ds = devm_kzalloc(base, sizeof(*ds), GFP_KERNEL);
if (!ds)
@@ -3155,6 +3156,9 @@ struct ksz_device *ksz_switch_alloc(struct device *base, void *priv)
swdev->ds = ds;
swdev->priv = priv;
+ of_property_read_variable_u32_array(base->of_node, "dsa,member", sw_idx, 2, 2);
+ swdev->smi_index = sw_idx[1];
+
return swdev;
}
EXPORT_SYMBOL(ksz_switch_alloc);
@@ -147,6 +147,7 @@ struct ksz_device {
u32 chip_id;
u8 chip_rev;
int cpu_port; /* port connected to CPU */
+ u32 smi_index;
int phy_port_cnt;
phy_interface_t compat_interface;
bool synclko_125;