Skip to content

Commit 0005b2d

Browse files
ceggers-arrikuba-moo
authored andcommitted
dsa: lan9303: Fix mapping between DSA port number and PHY address
The 'phy' parameter supplied to lan9303_phy_read/_write was sometimes a DSA port number and sometimes a PHY address. This isn't a problem as long as they are equal. But if the external phy_addr_sel_strap pin is wired to 'high', the PHY addresses change from 0-1-2 to 1-2-3 (CPU, slave0, slave1). In this case, lan9303_phy_read/_write must translate between DSA port numbers and the corresponding PHY address. Fixes: a129259 ("net: dsa: add new DSA switch driver for the SMSC-LAN9303") Signed-off-by: Christian Eggers <[email protected]> Reviewed-by: Michal Kubiak <[email protected]> Reviewed-by: Florian Fainelli <[email protected]> Reviewed-by: Vladimir Oltean <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 033771c commit 0005b2d

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

drivers/net/dsa/lan9303-core.c

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1047,31 +1047,31 @@ static int lan9303_get_sset_count(struct dsa_switch *ds, int port, int sset)
10471047
return ARRAY_SIZE(lan9303_mib);
10481048
}
10491049

1050-
static int lan9303_phy_read(struct dsa_switch *ds, int phy, int regnum)
1050+
static int lan9303_phy_read(struct dsa_switch *ds, int port, int regnum)
10511051
{
10521052
struct lan9303 *chip = ds->priv;
10531053
int phy_base = chip->phy_addr_base;
10541054

1055-
if (phy == phy_base)
1055+
if (port == 0)
10561056
return lan9303_virt_phy_reg_read(chip, regnum);
1057-
if (phy > phy_base + 2)
1057+
if (port > 2)
10581058
return -ENODEV;
10591059

1060-
return chip->ops->phy_read(chip, phy, regnum);
1060+
return chip->ops->phy_read(chip, phy_base + port, regnum);
10611061
}
10621062

1063-
static int lan9303_phy_write(struct dsa_switch *ds, int phy, int regnum,
1063+
static int lan9303_phy_write(struct dsa_switch *ds, int port, int regnum,
10641064
u16 val)
10651065
{
10661066
struct lan9303 *chip = ds->priv;
10671067
int phy_base = chip->phy_addr_base;
10681068

1069-
if (phy == phy_base)
1069+
if (port == 0)
10701070
return lan9303_virt_phy_reg_write(chip, regnum, val);
1071-
if (phy > phy_base + 2)
1071+
if (port > 2)
10721072
return -ENODEV;
10731073

1074-
return chip->ops->phy_write(chip, phy, regnum, val);
1074+
return chip->ops->phy_write(chip, phy_base + port, regnum, val);
10751075
}
10761076

10771077
static int lan9303_port_enable(struct dsa_switch *ds, int port,
@@ -1099,7 +1099,7 @@ static void lan9303_port_disable(struct dsa_switch *ds, int port)
10991099
vlan_vid_del(dsa_port_to_conduit(dp), htons(ETH_P_8021Q), port);
11001100

11011101
lan9303_disable_processing_port(chip, port);
1102-
lan9303_phy_write(ds, chip->phy_addr_base + port, MII_BMCR, BMCR_PDOWN);
1102+
lan9303_phy_write(ds, port, MII_BMCR, BMCR_PDOWN);
11031103
}
11041104

11051105
static int lan9303_port_bridge_join(struct dsa_switch *ds, int port,
@@ -1374,8 +1374,6 @@ static const struct dsa_switch_ops lan9303_switch_ops = {
13741374

13751375
static int lan9303_register_switch(struct lan9303 *chip)
13761376
{
1377-
int base;
1378-
13791377
chip->ds = devm_kzalloc(chip->dev, sizeof(*chip->ds), GFP_KERNEL);
13801378
if (!chip->ds)
13811379
return -ENOMEM;
@@ -1385,8 +1383,7 @@ static int lan9303_register_switch(struct lan9303 *chip)
13851383
chip->ds->priv = chip;
13861384
chip->ds->ops = &lan9303_switch_ops;
13871385
chip->ds->phylink_mac_ops = &lan9303_phylink_mac_ops;
1388-
base = chip->phy_addr_base;
1389-
chip->ds->phys_mii_mask = GENMASK(LAN9303_NUM_PORTS - 1 + base, base);
1386+
chip->ds->phys_mii_mask = GENMASK(LAN9303_NUM_PORTS - 1, 0);
13901387

13911388
return dsa_register_switch(chip->ds);
13921389
}

0 commit comments

Comments
 (0)