question about drivers/net/dsa/sja1105/sja1105_main.c
Subsystems (2)
Hello,
The function sja1105_static_config_reload in sja1105_main.c contains the code:
if (!an_enabled) {
int speed = SPEED_UNKNOWN;
if (bmcr & BMCR_SPEED1000)
speed = SPEED_1000;
else if (bmcr & BMCR_SPEED100)
speed = SPEED_100;
else if (bmcr & BMCR_SPEED10)
speed = SPEED_10;
sja1105_sgmii_pcs_force_speed(priv, speed);
}The last test bmcr & BMCR_SPEED10 does not look correct, because according to include/uapi/linux/mii.h, BMCR_SPEED10 is 0. What should be done instead?
thanks,
julia
Hi Julia,
Quoted 19 lines · Julia Lawall
Hello,
The function
sja1105_static_config_reloadinsja1105_main.ccontains the code:if (!an_enabled) { int speed = SPEED_UNKNOWN; if (bmcr & BMCR_SPEED1000) speed = SPEED_1000; else if (bmcr & BMCR_SPEED100) speed = SPEED_100; else if (bmcr & BMCR_SPEED10) speed = SPEED_10; sja1105_sgmii_pcs_force_speed(priv, speed); }
Quoted 6 lines
The last test bmcr &
BMCR_SPEED10does not look correct, because according toinclude/uapi/linux/mii.h,BMCR_SPEED10is 0. What should be done instead?thanks,
julia
Thanks for pointing out, you raise a good point.
Correct usage would be:
include/uapi/linux/mii.h:
#define BMCR_SPEED_MASK 0x2040
drivers/net/dsa/sja1105/sja1105_main.c:
int speed = SPEED_UNKNOWN;
if (bmcr & BMCR_SPEED_MASK == BMCR_SPEED1000)
speed = SPEED_1000;
else if (bmcr & BMCR_SPEED_MASK == BMCR_SPEED100)
speed = SPEED_100;
else if (bmcr & BMCR_SPEED_MASK == BMCR_SPEED10)
speed = SPEED_10;but the BMCR_SPEED_MASK doesn't exist, it looks like. I believe that is because drivers (or the PHY library) don't typically need to read the speed from the MII_BMCR register, they just need to write it. If the PHY library maintainers think there is any value in defining BMCR_SPEED_MASK as part of the UAPI, we can do that. Otherwise, the definition can be restricted to drivers/net/dsa/sja1105/sja1105.h.
Thanks,
-Vladimir
Quoted 26 lines · Vladimir Oltean
Hi Julia,
Quoted 23 lines · Julia Lawall
Hello,
The function
sja1105_static_config_reloadinsja1105_main.ccontains the code:if (!an_enabled) { int speed = SPEED_UNKNOWN; if (bmcr & BMCR_SPEED1000) speed = SPEED_1000; else if (bmcr & BMCR_SPEED100) speed = SPEED_100; else if (bmcr & BMCR_SPEED10) speed = SPEED_10; sja1105_sgmii_pcs_force_speed(priv, speed); }The last test bmcr &
BMCR_SPEED10does not look correct, because according toinclude/uapi/linux/mii.h,BMCR_SPEED10is 0. What should be done instead?
It's right that this is not correct. You can check genphy_read_status_fixed() for how it's done there.
Quoted 29 lines
Quoted 2 lines
thanks,
juliaThanks for pointing out, you raise a good point.
Correct usage would be:
include/uapi/linux/mii.h:
#defineBMCR_SPEED_MASK0x2040
drivers/net/dsa/sja1105/sja1105_main.c:int speed = SPEED_UNKNOWN; if (bmcr & BMCR_SPEED_MASK == BMCR_SPEED1000) speed = SPEED_1000; else if (bmcr & BMCR_SPEED_MASK == BMCR_SPEED100) speed = SPEED_100; else if (bmcr & BMCR_SPEED_MASK == BMCR_SPEED10) speed = SPEED_10;but the
BMCR_SPEED_MASKdoesn't exist, it looks like. I believe that is because drivers (or the PHY library) don't typically need to read the speed from theMII_BMCRregister, they just need to write it. If the PHY library maintainers think there is any value in definingBMCR_SPEED_MASKas part of the UAPI, we can do that. Otherwise, the definition can be restricted todrivers/net/dsa/sja1105/sja1105.h.Thanks,
-Vladimir
Quoted 2 lines · Heiner Kallweit
It's right that this is not correct. You can check
genphy_read_status_fixed()for how it's done there.
There is no SPEED_UNKNOWN in that function.
Quoted 8 lines · Joe Perches
Quoted 2 lines · Heiner Kallweit
It's right that this is not correct. You can check
genphy_read_status_fixed()for how it's done there.There is no
SPEED_UNKNOWNin that function.
Correct, there isn't.
The bitwise value of the 2 speed bits from MII_BMCR is:
Bits [6,13]:
1 1 = Reserved
1 0 = 1000 Mbps
0 1 = 100 Mbps
0 0 = 10 Mbps
So basically the PHY library assumes that no piece of hardware will ever set the speed bits to 11, as that would invalidate the spec.
-Vladimir