[PATCH v2 0/4]
Subsystems (3)
v2 cover [PATCH v2 0/4]
Hello David, Ben, Florian, Chris and everybody,
this series improves ethoc behavior in gigabit environment:
- first patch introduces two phylib setters for 'advertising' and 'supported' fields of struct phy_device;
- second patch disables gigabit advertisement in the attached PHY making possible to use gigabit link without any additional setup;
- third patch adds support to set up MII management bus frequency, adding new fields to platform data and to OF bindings;
- fourth patch adds basic ethtool support to ethoc driver.
These changes allow to use KC-705 board with 50MHz xtensa core and OpenCores 10/100 Mbps MAC connected to gigabit network without any additional setup.
Changes v1->v2:
- new patch "phy: provide accessors for 'advertising' and 'supported' fields";
- disable both gigabit advertisement and support;
- drop MDIO bus frequency configurability, always configure for standard 2.5MHz;
- allow using common clock framework to provide ethoc clock;
- new patch: "net: ethoc: implement ethtool operations";
- drop device tree bindings documentation patch until common bindings format for network drivers is decided.
Max Filippov (4):
phy: provide accessors for 'advertising' and 'supported' fields
net: ethoc: don't advertise gigabit speed on attached PHY
net: ethoc: set up MII management bus clock
net: ethoc: implement ethtool operations
drivers/net/ethernet/ethoc.c | 130 ++++++++++++++++++++++++++++++++++++++++++- include/linux/phy.h | 12 ++++ include/net/ethoc.h | 1 + 3 files changed, 141 insertions(+), 2 deletions(-)
Signature · 1 line
1.8.1.4
PATCH v2 1/4 phy: provide accessors for 'advertising' and 'supported' fields
Many network drivers directly modify phy_device::advertising and phy_device::supported. Provide accessors to these fields to better isolate phylib from its users.
---
Changes v1->v2:
- new patch
include/linux/phy.h | 12 ++++++++++++ 1 file changed, 12 insertions(+)
include/linux/phy.h +12 -0
@@ -559,6 +559,18 @@ static inline int phy_read_status(struct phy_device *phydev) {return phydev->drv->read_status (phydev); } +static inline void phy_update_advert (struct phy_device *phydev,u32 clear, +u32 set) +{ + phydev->advertising = (phydev->advertising & ~clear) | set; +} + +static inline void phy_update_supported (struct phy_device *phydev,u32 clear, +u32 set) +{ + phydev->supported = (phydev->supported & ~clear) | set; +} +int genphy_setup_forced (struct phy_device *phydev);int genphy_restart_aneg (struct phy_device *phydev);int genphy_config_aneg (struct phy_device *phydev);
Signature · 1 line
1.8.1.4
Re: [PATCH v2 1/4] phy: provide accessors for 'advertising' and 'supported' fields
2014-01-28 Max Filippov <[email protected]>:
Quoted 6 lines
Many network drivers directly modify
phy_device::advertisingandphy_device::supported. Provide accessors to these fields to better isolate phylib from its users.Suggested-by Ben Hutchings <[email protected]>Signed-off-by Max Filippov <[email protected]>
After giving some more thought to this patch, I am not sure this really adds anything, struct phy_device is already exposed to drivers, and those drivers have been able to modify phydev->supported and phydev->advertising to suit their needs.
Quoted 33 lines
---
Changesv1->v2:
- new patchinclude/linux/phy.h | 12 ++++++++++++ 1 file changed, 12 insertions(+)include/linux/phy.h +12
-1@@ -559,6 +559,18 @@ static inline int phy_read_status(struct phy_device *phydev) {return phydev->drv->read_status (phydev); } +static inline void phy_update_advert (struct phy_device *phydev,u32 clear, +u32 set) +{ + phydev->advertising = (phydev->advertising & ~clear) | set; +} + +static inline void phy_update_supported (struct phy_device *phydev,u32 clear, +u32 set) +{ + phydev->supported = (phydev->supported & ~clear) | set; +} +int genphy_setup_forced (struct phy_device *phydev);int genphy_restart_aneg (struct phy_device *phydev);int genphy_config_aneg (struct phy_device *phydev); --1.8.1.4
Signature · 1 line
Florian
PATCH v2 2/4 net: ethoc: don't advertise gigabit speed on attached PHY
In reply to Max FilippovOpenCores 10/100 Mbps MAC does not support speeds above 100 Mbps, but does not disable advertisement when PHY supports them. This results in non-functioning network when the MAC is connected to a gigabit PHY connected to a gigabit switch.
The fix is to disable gigabit speed advertisement on attached PHY unconditionally.
---
Changes v1->v2:
- disable both gigabit advertisement and support.
drivers/net/ethernet/ethoc.c | 8 ++++++++ 1 file changed, 8 insertions(+)
drivers/net/ethernet/ethoc.c +8 -0
@@ -688,6 +688,14 @@ static int ethoc_mdio_probe(struct net_device *dev) } priv->phy = phy; +phy_update_advert (phy, + ADVERTISED_1000baseT_Full | + ADVERTISED_1000baseT_Half,0 ); +phy_start_aneg (phy); +phy_update_supported (phy, + SUPPORTED_1000baseT_Full | + SUPPORTED_1000baseT_Half,0 ); +return 0 ; }
Signature · 1 line
1.8.1.4
Re: [PATCH v2 2/4] net: ethoc: don't advertise gigabit speed on attached PHY
Hi Max,
Quoted 21 lines · Max Filippov
OpenCores 10/100 Mbps MAC does not support speeds above 100 Mbps, but does not disable advertisement when PHY supports them. This results in non-functioning network when the MAC is connected to a gigabit PHY connected to a gigabit switch.
The fix is to disable gigabit speed advertisement on attached PHY unconditionally.
Signed-off-by Max Filippov <[email protected]>---
Changesv1->v2:
- disable both gigabit advertisement and support.drivers/net/ethernet/ethoc.c | 8 ++++++++ 1 file changed, 8 insertions(+)drivers/net/ethernet/ethoc.c +0
-0
drivers/net/ethernet/ethoc.c static int ethoc_mdio_probe(struct net_device *dev) · line 694
Quoted 7 lines
drivers/net/ethernet/ethoc.c +4
-0@@ -688,6 +688,14 @@ static int ethoc_mdio_probe(struct net_device *dev) } priv->phy = phy; +phy_update_advert (phy, + ADVERTISED_1000baseT_Full | + ADVERTISED_1000baseT_Half,0 ); +phy_start_aneg (phy);
This does not look necessary, you should not have to call phy_start_aneg() because the PHY state machine is not yet started, at best this calls does nothing.
Quoted 8 lines
drivers/net/ethernet/ethoc.c +4
-0+phy_update_supported (phy, + SUPPORTED_1000baseT_Full | + SUPPORTED_1000baseT_Half,0 ); +return 0 ; }
Re: [PATCH v2 2/4] net: ethoc: don't advertise gigabit speed on attached PHY
Quoted 28 lines · Florian Fainelli
Hi Max,
Quoted 24 lines · Max Filippov
OpenCores 10/100 Mbps MAC does not support speeds above 100 Mbps, but does not disable advertisement when PHY supports them. This results in non-functioning network when the MAC is connected to a gigabit PHY connected
to a gigabit switch.The fix is to disable gigabit speed advertisement on attached PHY unconditionally.
Signed-off-by Max Filippov <[email protected]>---
Changesv1->v2:
- disable both gigabit advertisement and support.drivers/net/ethernet/ethoc.c | 8 ++++++++ 1 file changed, 8 insertions(+)drivers/net/ethernet/ethoc.c +0
-0@@ -688,6 +688,14 @@ static int ethoc_mdio_probe(struct net_device *dev) }
Quoted 10 lines
drivers/net/ethernet/ethoc.c static int ethoc_mdio_probe(struct net_device *dev) · line 694
Quoted 5 lines
drivers/net/ethernet/ethoc.c +4
-0priv->phy = phy; +phy_update_advert (phy, + ADVERTISED_1000baseT_Full | + ADVERTISED_1000baseT_Half,0 ); +phy_start_aneg (phy);This does not look necessary, you should not have to call
phy_start_aneg()because the PHY state machine is not yet started, at best this calls does nothing.
This call actually makes the whole thing work, because otherwise once gigabit support is cleared from the supported mask genphy_config_advert does not update gigabit advertisement register, leaving it enabled.
Quoted 9 lines
Quoted 8 lines
drivers/net/ethernet/ethoc.c +4
-0+phy_update_supported (phy, + SUPPORTED_1000baseT_Full | + SUPPORTED_1000baseT_Half,0 ); +return 0 ; }
Signature · 2 lines
Thanks. -- Max
A message that is not in the archive (sent off-list or not yet received): CAGVrzcboHp8-qHZseGOVm14u1-cTcOjRZGExFxNu_nbK__XCSA@mail.gmail.com
Re: [PATCH v2 2/4] net: ethoc: don't advertise gigabit speed on attached PHY
Quoted 48 lines · Florian Fainelli
Quoted 47 lines · Max Filippov
Quoted 43 lines · Florian Fainelli
Hi Max,
Quoted 24 lines · Max Filippov
OpenCores 10/100 Mbps MAC does not support speeds above 100 Mbps, but does
not disable advertisement when PHY supports them. This results in non-functioning network when the MAC is connected to a gigabit PHY connected
to a gigabit switch.The fix is to disable gigabit speed advertisement on attached PHY unconditionally.
Signed-off-by Max Filippov <[email protected]>---
Changesv1->v2:
- disable both gigabit advertisement and support.drivers/net/ethernet/ethoc.c | 8 ++++++++ 1 file changed, 8 insertions(+)drivers/net/ethernet/ethoc.c +0
-0drivers/net/ethernet/ethoc.c static int ethoc_mdio_probe(struct net_device · line 695
Quoted 8 lines
drivers/net/ethernet/ethoc.c +4
-0@@ -688,6 +688,14 @@ static int ethoc_mdio_probe(struct net_device *dev) } priv->phy = phy; +phy_update_advert (phy, + ADVERTISED_1000baseT_Full | + ADVERTISED_1000baseT_Half,0 ); +phy_start_aneg (phy);This does not look necessary, you should not have to call
phy_start_aneg()
because the PHY state machine is not yet started, at best this calls does
nothing.
Quoted 7 lines
Quoted 4 lines
This call actually makes the whole thing work, because otherwise once gigabit
support is cleared from the supported maskgenphy_config_advertdoes not update gigabit advertisement register, leaving it enabled.OK, then we need to figure out what is wrong with ethoc since this is unusual.
Maybe they boot up with gigabit advertisement disabled in their PHY and thus they don't see the problem?
Quoted 9 lines
Other drivers do the following:
- connect to the PHY
-phydev->supported=PHY_BASIC_FEATURES
-phydev->advertising&=phydev->supported
- start the PHY state machineAnd they work just fine. Is the PHY driver you are bound to the "Generic PHY" or something else which does something funky in
config_aneg()?
It's marvell 88E1111 from the KC-705 board, but the behaviour doesn't change if I disable it and the generic phy is used.
Signature · 2 lines
Thanks. -- Max
Re: [PATCH v2 2/4] net: ethoc: don't advertise gigabit speed on attached PHY
Quoted 67 lines · Max Filippov
Quoted 48 lines · Florian Fainelli
Quoted 47 lines · Max Filippov
Quoted 43 lines · Florian Fainelli
Hi Max,
Quoted 24 lines · Max Filippov
OpenCores 10/100 Mbps MAC does not support speeds above 100 Mbps, but does
not disable advertisement when PHY supports them. This results in non-functioning network when the MAC is connected to a gigabit PHY connected
to a gigabit switch.The fix is to disable gigabit speed advertisement on attached PHY unconditionally.
Signed-off-by Max Filippov <[email protected]>---
Changesv1->v2:
- disable both gigabit advertisement and support.drivers/net/ethernet/ethoc.c | 8 ++++++++ 1 file changed, 8 insertions(+)drivers/net/ethernet/ethoc.c +0
-0drivers/net/ethernet/ethoc.c static int ethoc_mdio_probe(struct net_device · line 695
Quoted 8 lines
drivers/net/ethernet/ethoc.c +4
-0@@ -688,6 +688,14 @@ static int ethoc_mdio_probe(struct net_device *dev) } priv->phy = phy; +phy_update_advert (phy, + ADVERTISED_1000baseT_Full | + ADVERTISED_1000baseT_Half,0 ); +phy_start_aneg (phy);This does not look necessary, you should not have to call
phy_start_aneg()
because the PHY state machine is not yet started, at best this calls does
nothing.Quoted 7 lines
Quoted 4 lines
This call actually makes the whole thing work, because otherwise once gigabit
support is cleared from the supported maskgenphy_config_advertdoes not update gigabit advertisement register, leaving it enabled.OK, then we need to figure out what is wrong with ethoc since this is unusual.
Maybe they boot up with gigabit advertisement disabled in their PHY and thus they don't see the problem?
Quoted 7 lines
Other drivers do the following:
- connect to the PHY
-phydev->supported=PHY_BASIC_FEATURES
-phydev->advertising&=phydev->supported
- start the PHY state machine
Quoted 5 lines
Quoted 2 lines
And they work just fine. Is the PHY driver you are bound to the "Generic PHY" or something else which does something funky in
config_aneg()?It's marvell 88E1111 from the KC-705 board, but the behaviour doesn't change if I disable it and the generic phy is used.
Florian,
I don't see how the generic genphy_config_advert can ever change gigabit advertisement if phydev->supported has gigabit speeds masked off. So I'm pretty sure that other 10/100 cards would exhibit the same issue if their PHY started with gigabit advertisement enabled. Maybe we need to fix those other drivers? Or maybe we need to track what PHY really supports vs. what we report it supports, so that gigabit advertisement could be changed even when the PHY no longer appears to support gigabit?
Signature · 2 lines
Thanks. -- Max
Re: [PATCH v2 2/4] net: ethoc: don't advertise gigabit speed on attached PHY
2014-01-30 Max Filippov <[email protected]>:
Quoted 71 lines · Max Filippov
Quoted 70 lines · Florian Fainelli
Quoted 48 lines · Max Filippov
Quoted 47 lines
Quoted 43 lines · Florian Fainelli
Hi Max,
Quoted 24 lines · Max Filippov
OpenCores 10/100 Mbps MAC does not support speeds above 100 Mbps, but does
not disable advertisement when PHY supports them. This results in non-functioning network when the MAC is connected to a gigabit PHY connected
to a gigabit switch.The fix is to disable gigabit speed advertisement on attached PHY unconditionally.
Signed-off-by Max Filippov <[email protected]>---
Changesv1->v2:
- disable both gigabit advertisement and support.drivers/net/ethernet/ethoc.c | 8 ++++++++ 1 file changed, 8 insertions(+)drivers/net/ethernet/ethoc.c +0
-0drivers/net/ethernet/ethoc.c static int ethoc_mdio_probe(struct net_device · line 695
Quoted 8 lines
drivers/net/ethernet/ethoc.c +4
-0@@ -688,6 +688,14 @@ static int ethoc_mdio_probe(struct net_device *dev) } priv->phy = phy; +phy_update_advert (phy, + ADVERTISED_1000baseT_Full | + ADVERTISED_1000baseT_Half,0 ); +phy_start_aneg (phy);This does not look necessary, you should not have to call
phy_start_aneg()
because the PHY state machine is not yet started, at best this calls does
nothing.Quoted 7 lines
Quoted 4 lines
This call actually makes the whole thing work, because otherwise once gigabit
support is cleared from the supported maskgenphy_config_advertdoes not update gigabit advertisement register, leaving it enabled.OK, then we need to figure out what is wrong with ethoc since this is unusual.
Maybe they boot up with gigabit advertisement disabled in their PHY and thus they don't see the problem?
Quoted 9 lines
Other drivers do the following:
- connect to the PHY
-phydev->supported=PHY_BASIC_FEATURES
-phydev->advertising&=phydev->supported
- start the PHY state machineAnd they work just fine. Is the PHY driver you are bound to the "Generic PHY" or something else which does something funky in
config_aneg()?
Quoted 8 lines
Quoted 2 lines
It's marvell 88E1111 from the KC-705 board, but the behaviour doesn't change if I disable it and the generic phy is used.
Florian,
I don't see how the generic
genphy_config_advertcan ever change gigabit advertisement ifphydev->supportedhas gigabit speeds masked off.
It does not, but it makes sure that phydev->advertising gets masked with phydev->supported. So, prior to starting your PHY state machine, if you do:
phydev->supported &= PHY_BASIC_FEATURES;phydev->advertising = phydev->supported;
you should get the expected results. Just make sure that phydev->autoneg is not set to AUTONEG_DISABLE, otherwise phy_start_aneg() will not call phy_sanitize_settings(), and this might be the problem.
Quoted 2 lines
So I'm pretty sure that other 10/100 cards would exhibit the same issue if their PHY started with gigabit advertisement enabled.
If the speed is not restricted, yes that will be the case, but most drivers seem to correctly set both phydev->supported and phydev->advertising.
Quoted 5 lines
Maybe
we need to fix those other drivers? Or maybe we need to track what PHY really supports vs. what we report it supports, so that gigabit advertisement could be changed even when the PHY no longer appears to support gigabit?
This is supposedly already taken care of provided that you correctly restrict the PHY supported/advertising bits with respect to what the HW really supports.
Signature · 1 line
Florian
Re: [PATCH v2 2/4] net: ethoc: don't advertise gigabit speed on attached PHY
2014-01-31 Florian Fainelli <[email protected]>:
Quoted 22 lines
Quoted 13 lines
Quoted 13 lines
Maybe they boot up with gigabit advertisement disabled in their PHY and thus they don't see the problem?
Quoted 9 lines
Other drivers do the following:
- connect to the PHY
-phydev->supported=PHY_BASIC_FEATURES
-phydev->advertising&=phydev->supported
- start the PHY state machineAnd they work just fine. Is the PHY driver you are bound to the "Generic PHY" or something else which does something funky in
config_aneg()?Quoted 8 lines
Quoted 2 lines
It's marvell 88E1111 from the KC-705 board, but the behaviour doesn't change if I disable it and the generic phy is used.
Florian,
I don't see how the generic
genphy_config_advertcan ever change gigabit advertisement ifphydev->supportedhas gigabit speeds masked off.
Quoted 6 lines
It does not, but it makes sure that
phydev->advertisinggets masked withphydev->supported. So, prior to starting your PHY state machine, if you do:
phydev->supported&=PHY_BASIC_FEATURES;phydev->advertising=phydev->supported;
It looks like there might be one problem however, if we have the following:
- phydev->supported masks off the Gigabit features
- PHY device comes out of reset/default with Gigabit features set in MII_CTRL1000
Could you try the following patch:
drivers/net/phy/phy_device.c +12 -13
@@ -749,25 +749,24 @@ static int genphy_config_advert(struct phy_device *phydev) }/* Configure gigabit if it's supported */ + adv =phy_read (phydev,MII_CTRL1000 ); +if (adv <0 ) +return adv; + + oldadv = adv; + adv &= ~(ADVERTISE_1000FULL |ADVERTISE_1000HALF ); +if (phydev->supported & (SUPPORTED_1000baseT_Half | SUPPORTED_1000baseT_Full)) { - adv =phy_read (phydev,MII_CTRL1000 ); -if (adv <0 ) -return adv; - - oldadv = adv; - adv &= ~(ADVERTISE_1000FULL |ADVERTISE_1000HALF ); adv |=ethtool_adv_to_mii_ctrl1000_t (advertise); - -if (adv != oldadv) { - err =phy_write (phydev,MII_CTRL1000 , adv); - -if (err <0 ) -return err; +if (adv != oldadv) changed =1 ; - } } + err =phy_write (phydev,MII_CTRL1000 , adv); +if (err <0 ) +return err; +return changed; }
Signature · 1 line
Florian
Re: [PATCH v2 2/4] net: ethoc: don't advertise gigabit speed on attached PHY
Quoted 27 lines · Florian Fainelli
2014-01-31 Florian Fainelli <[email protected]>:
Quoted 26 lines
Quoted 13 lines
Quoted 13 lines
Maybe they boot up with gigabit advertisement disabled in their PHY and thus they don't see the problem?
Quoted 9 lines
Other drivers do the following:
- connect to the PHY
-phydev->supported=PHY_BASIC_FEATURES
-phydev->advertising&=phydev->supported
- start the PHY state machineAnd they work just fine. Is the PHY driver you are bound to the "Generic PHY" or something else which does something funky in
config_aneg()?Quoted 8 lines
Quoted 2 lines
It's marvell 88E1111 from the KC-705 board, but the behaviour doesn't change if I disable it and the generic phy is used.
Florian,
I don't see how the generic
genphy_config_advertcan ever change gigabit advertisement ifphydev->supportedhas gigabit speeds masked off.It does not, but it makes sure that
phydev->advertisinggets masked withphydev->supported. So, prior to starting your PHY state machine, if you do:
Quoted 8 lines
Quoted 2 lines
phydev->supported&=PHY_BASIC_FEATURES;phydev->advertising=phydev->supported;It looks like there might be one problem however, if we have the following:
-
phydev->supportedmasks off the Gigabit features
- PHY device comes out of reset/default with Gigabit features set inMII_CTRL1000
That's exactly my case.
Quoted 28 lines
Could you try the following patch:
drivers/net/phy/phy_device.c +7
-8@@ -749,25 +749,24 @@ static int genphy_config_advert(struct phy_device *phydev) }/* Configure gigabit if it's supported */ + adv =phy_read (phydev,MII_CTRL1000 ); +if (adv <0 ) +return adv; + + oldadv = adv; + adv &= ~(ADVERTISE_1000FULL |ADVERTISE_1000HALF ); +if (phydev->supported & (SUPPORTED_1000baseT_Half | SUPPORTED_1000baseT_Full)) { - adv =phy_read (phydev,MII_CTRL1000 ); -if (adv <0 ) -return adv; - - oldadv = adv; - adv &= ~(ADVERTISE_1000FULL |ADVERTISE_1000HALF ); adv |=ethtool_adv_to_mii_ctrl1000_t (advertise); - -if (adv != oldadv) {
drivers/net/phy/phy_device.c static int genphy_config_advert(struct phy_device *phydev) · line 766
Quoted 10 lines
drivers/net/phy/phy_device.c +2
-5- err =phy_write (phydev,MII_CTRL1000 , adv); - -if (err <0 ) -return err; +if (adv != oldadv) changed =1 ; - } } + err =phy_write (phydev,MII_CTRL1000 , adv);
I don't think this is correct: MII_CTRL1000 is reserved for 10/100 PHYs, we probably need to read/write it conditionally, depending on MII_BMSR BMSR_ESTATEN bit.
Otherwise yes, it works for me too.
Quoted 5 lines
drivers/net/phy/phy_device.c +3
-0+if (err <0 ) +return err; +return changed; }
Signature · 2 lines
Thanks. -- Max
Re: [PATCH v2 2/4] net: ethoc: don't advertise gigabit speed on attached PHY
2014-01-31 Max Filippov <[email protected]>:
Quoted 76 lines · Florian Fainelli
Quoted 27 lines
2014-01-31 Florian Fainelli <[email protected]>:
Quoted 26 lines
Quoted 13 lines
Quoted 13 lines
Maybe they boot up with gigabit advertisement disabled in their PHY and thus they don't see the problem?
Quoted 9 lines
Other drivers do the following:
- connect to the PHY
-phydev->supported=PHY_BASIC_FEATURES
-phydev->advertising&=phydev->supported
- start the PHY state machineAnd they work just fine. Is the PHY driver you are bound to the "Generic PHY" or something else which does something funky in
config_aneg()?Quoted 8 lines
Quoted 2 lines
It's marvell 88E1111 from the KC-705 board, but the behaviour doesn't change if I disable it and the generic phy is used.
Florian,
I don't see how the generic
genphy_config_advertcan ever change gigabit advertisement ifphydev->supportedhas gigabit speeds masked off.It does not, but it makes sure that
phydev->advertisinggets masked withphydev->supported. So, prior to starting your PHY state machine, if you do:Quoted 8 lines
Quoted 2 lines
phydev->supported&=PHY_BASIC_FEATURES;phydev->advertising=phydev->supported;It looks like there might be one problem however, if we have the following:
-
phydev->supportedmasks off the Gigabit features
- PHY device comes out of reset/default with Gigabit features set inMII_CTRL1000That's exactly my case.
Quoted 37 lines
Could you try the following patch:
drivers/net/phy/phy_device.c +8
-13@@ -749,25 +749,24 @@ static int genphy_config_advert(struct phy_device *phydev) }/* Configure gigabit if it's supported */ + adv =phy_read (phydev,MII_CTRL1000 ); +if (adv <0 ) +return adv; + + oldadv = adv; + adv &= ~(ADVERTISE_1000FULL |ADVERTISE_1000HALF ); +if (phydev->supported & (SUPPORTED_1000baseT_Half | SUPPORTED_1000baseT_Full)) { - adv =phy_read (phydev,MII_CTRL1000 ); -if (adv <0 ) -return adv; - - oldadv = adv; - adv &= ~(ADVERTISE_1000FULL |ADVERTISE_1000HALF ); adv |=ethtool_adv_to_mii_ctrl1000_t (advertise); - -if (adv != oldadv) { - err =phy_write (phydev,MII_CTRL1000 , adv); - -if (err <0 ) -return err; +if (adv != oldadv) changed =1 ; - } }
Quoted 7 lines
drivers/net/phy/phy_device.c static int genphy_config_advert(struct phy_device *phydev) · line 766
Quoted 1 line
drivers/net/phy/phy_device.c +1
-0+ err =phy_write (phydev,MII_CTRL1000 , adv);I don't think this is correct:
MII_CTRL1000is reserved for 10/100 PHYs, we probably need to read/write it conditionally, depending onMII_BMSRBMSR_ESTATENbit.
Otherwise yes, it works for me too.
You are right, that needs to be made conditional. I will give this patch some more proper testing on a truly non-gigabit PHY. Thanks!
Signature · 1 line
Florian
PATCH v2 3/4 net: ethoc: set up MII management bus clock
In reply to Max FilippovMII management bus clock is derived from the MAC clock by dividing it by MIIMODER register CLKDIV field value. This value may need to be set up in case it is undefined or its default value is too high (and communication with PHY is too slow) or too low (and communication with PHY is impossible). The value of CLKDIV is not specified directly, but is derived from the MAC clock for the default MII management bus frequency of 2.5MHz. The MAC clock may be specified in the platform data, or as either 'clock-frequency' or 'clocks' device tree attribute.
---
Changes v1->v2:
- drop MDIO bus frequency configurability, always configure for standard 2.5MHz;
- allow using common clock framework to provide ethoc clock.
drivers/net/ethernet/ethoc.c | 37 +++++++++++++++++++++++++++++++++++-- include/net/ethoc.h | 1 + 2 files changed, 36 insertions(+), 2 deletions(-)
drivers/net/ethernet/ethoc.c +35 -2
@@ -13,6 +13,7 @@#include <linux/dma-mapping.h> #include <linux/etherdevice.h> +#include <linux/clk.h> #include <linux/crc32.h> #include <linux/interrupt.h> #include <linux/io.h>
@@ -216,6 +217,7 @@ struct ethoc {struct phy_device *phy;struct mii_bus *mdio; +struct clk *clk;s8 phy_id; };
@@ -925,6 +927,8 @@ static int ethoc_probe(struct platform_device *pdev)int num_bd;int ret =0 ;bool random_mac = false; +u32 eth_clkfreq =0 ; +struct ethoc_platform_data *pdata =dev_get_platdata (&pdev->dev);/* allocate networking device */ netdev =alloc_etherdev (sizeof (struct ethoc ));
@@ -1038,8 +1042,7 @@ static int ethoc_probe(struct platform_device *pdev) }/* Allow the platform setup code to pass in a MAC address. */ -if (dev_get_platdata (&pdev->dev)) { -struct ethoc_platform_data *pdata =dev_get_platdata (&pdev->dev); +if (pdata) {memcpy (netdev->dev_addr, pdata->hwaddr,IFHWADDRLEN ); priv->phy_id = pdata->phy_id; }else {
@@ -1077,6 +1080,32 @@ static int ethoc_probe(struct platform_device *pdev)if (random_mac) netdev->addr_assign_type =NET_ADDR_RANDOM ; +/* Allow the platform setup code to adjust MII management bus clock. */ +if (pdata) + eth_clkfreq = pdata->eth_clkfreq; +else +of_property_read_u32 (pdev->dev.of_node, +"clock-frequency" , ð_clkfreq); +if (!eth_clkfreq) { +struct clk *clk =clk_get (&pdev->dev,NULL ); + +if (!IS_ERR (clk)) { + priv->clk = clk; +clk_prepare_enable (clk); + eth_clkfreq =clk_get_rate (clk); + } + } +if (eth_clkfreq) { +u32 clkdiv =MIIMODER_CLKDIV (eth_clkfreq /2500000 +1 ); + +if (!clkdiv) + clkdiv =2 ; +dev_dbg (&pdev->dev,"setting MII clkdiv to %u\n" , clkdiv); +ethoc_write (priv,MIIMODER , + (ethoc_read (priv,MIIMODER ) &MIIMODER_NOPRE ) | + clkdiv); + } +/* register MII bus */ priv->mdio =mdiobus_alloc ();if (!priv->mdio) {
@@ -1141,6 +1170,8 @@ free_mdio:kfree (priv->mdio->irq);mdiobus_free (priv->mdio); free: +if (priv->clk) +clk_disable_unprepare (priv->clk);free_netdev (netdev); out:return ret;
@@ -1165,6 +1196,8 @@ static int ethoc_remove(struct platform_device *pdev)kfree (priv->mdio->irq);mdiobus_free (priv->mdio); } +if (priv->clk) +clk_disable_unprepare (priv->clk);unregister_netdev (netdev);free_netdev (netdev); }
include/net/ethoc.h +1 -0
@@ -16,6 +16,7 @@struct ethoc_platform_data {u8 hwaddr[IFHWADDRLEN ];s8 phy_id; +u32 eth_clkfreq; };#endif /* !LINUX_NET_ETHOC_H */
Signature · 1 line
1.8.1.4
Re: [PATCH v2 3/4] net: ethoc: set up MII management bus clock
Quoted 60 lines · Max Filippov
MII management bus clock is derived from the MAC clock by dividing it by MIIMODER register CLKDIV field value. This value may need to be set up in case it is undefined or its default value is too high (and communication with PHY is too slow) or too low (and communication with PHY is impossible). The value of CLKDIV is not specified directly, but is derived from the MAC clock for the default MII management bus frequency of 2.5MHz. The MAC clock may be specified in the platform data, or as either 'clock-frequency' or 'clocks' device tree attribute.
Signed-off-by Max Filippov <[email protected]>---
Changesv1->v2:
- drop MDIO bus frequency configurability, always configure for standard 2.5MHz;
- allow using common clock framework to provide ethoc clock.drivers/net/ethernet/ethoc.c | 37 +++++++++++++++++++++++++++++++++++-- include/net/ethoc.h | 1 + 2 files changed, 36 insertions(+), 2 deletions(-)drivers/net/ethernet/ethoc.c +5
-2@@ -13,6 +13,7 @@#include <linux/dma-mapping.h> #include <linux/etherdevice.h> +#include <linux/clk.h> #include <linux/crc32.h> #include <linux/interrupt.h> #include <linux/io.h> @@ -216,6 +217,7 @@ struct ethoc {struct phy_device *phy;struct mii_bus *mdio; +struct clk *clk;s8 phy_id; };@@ -925,6 +927,8 @@ static int ethoc_probe(struct platform_device *pdev)int num_bd;int ret =0 ;bool random_mac = false; +u32 eth_clkfreq =0 ; +struct ethoc_platform_data *pdata =dev_get_platdata (&pdev->dev);/* allocate networking device */ netdev =alloc_etherdev (sizeof (struct ethoc ));@@ -1038,8 +1042,7 @@ static int ethoc_probe(struct platform_device *pdev) }/* Allow the platform setup code to pass in a MAC address. */ -if (dev_get_platdata (&pdev->dev)) { -struct ethoc_platform_data *pdata =dev_get_platdata (&pdev->dev); +if (pdata) {memcpy (netdev->dev_addr, pdata->hwaddr,IFHWADDRLEN ); priv->phy_id = pdata->phy_id; }else {
drivers/net/ethernet/ethoc.c static int ethoc_probe(struct platform_device *pdev) · line 1085
Quoted 6 lines
drivers/net/ethernet/ethoc.c +3
-0@@ -1077,6 +1080,32 @@ static int ethoc_probe(struct platform_device *pdev)if (random_mac) netdev->addr_assign_type =NET_ADDR_RANDOM ; +/* Allow the platform setup code to adjust MII management bus clock. */ +if (pdata) + eth_clkfreq = pdata->eth_clkfreq;
Since this is a new member, why not make it a struct clk pointer directly so you could simplify the code path?
Quoted 12 lines
drivers/net/ethernet/ethoc.c +12
-0+else +of_property_read_u32 (pdev->dev.of_node, +"clock-frequency" , ð_clkfreq); +if (!eth_clkfreq) { +struct clk *clk =clk_get (&pdev->dev,NULL ); + +if (!IS_ERR (clk)) { + priv->clk = clk; +clk_prepare_enable (clk); + eth_clkfreq =clk_get_rate (clk); + } + }
drivers/net/ethernet/ethoc.c static int ethoc_probe(struct platform_device *pdev) · line 1107
Quoted 10 lines
drivers/net/ethernet/ethoc.c +10
-0+if (eth_clkfreq) { +u32 clkdiv =MIIMODER_CLKDIV (eth_clkfreq /2500000 +1 ); + +if (!clkdiv) + clkdiv =2 ; +dev_dbg (&pdev->dev,"setting MII clkdiv to %u\n" , clkdiv); +ethoc_write (priv,MIIMODER , + (ethoc_read (priv,MIIMODER ) &MIIMODER_NOPRE ) | + clkdiv); + }
This does look a bit convoluted, and it looks like the clk_get() or getting the clock-frequency property should boil down to being the same thing with of_clk_get() as it should resolve all clocks phandles and fetch their frequencies appropriately.
drivers/net/ethernet/ethoc.c free_mdio: · line 1174
Quoted 10 lines
drivers/net/ethernet/ethoc.c +3
-0+/* register MII bus */ priv->mdio =mdiobus_alloc ();if (!priv->mdio) {@@ -1141,6 +1170,8 @@ free_mdio:kfree (priv->mdio->irq);mdiobus_free (priv->mdio); free: +if (priv->clk) +clk_disable_unprepare (priv->clk);
This should probbaly be if (!IS_ERR(priv-clk)).
drivers/net/ethernet/ethoc.c static int ethoc_remove(struct platform_device *pdev) · line 1200
Quoted 9 lines
drivers/net/ethernet/ethoc.c +2
-0free_netdev (netdev); out:return ret;@@ -1165,6 +1196,8 @@ static int ethoc_remove(struct platform_device *pdev)kfree (priv->mdio->irq);mdiobus_free (priv->mdio); } +if (priv->clk) +clk_disable_unprepare (priv->clk);
Same here
Quoted 16 lines
drivers/net/ethernet/ethoc.c +0
-0unregister_netdev (netdev);free_netdev (netdev); }include/net/ethoc.h +1
-0@@ -16,6 +16,7 @@struct ethoc_platform_data {u8 hwaddr[IFHWADDRLEN ];s8 phy_id; +u32 eth_clkfreq; };#endif /* !LINUX_NET_ETHOC_H */
Re: [PATCH v2 3/4] net: ethoc: set up MII management bus clock
Quoted 67 lines · Florian Fainelli
Quoted 65 lines · Max Filippov
MII management bus clock is derived from the MAC clock by dividing it by MIIMODER register CLKDIV field value. This value may need to be set up in case it is undefined or its default value is too high (and communication with PHY is too slow) or too low (and communication with PHY is impossible). The value of CLKDIV is not specified directly, but is derived from the MAC clock for the default MII management bus frequency of 2.5MHz. The MAC clock may be specified in the platform data, or as either 'clock-frequency' or 'clocks' device tree attribute.
Signed-off-by Max Filippov <[email protected]>---
Changesv1->v2:
- drop MDIO bus frequency configurability, always configure for standard 2.5MHz;
- allow using common clock framework to provide ethoc clock.drivers/net/ethernet/ethoc.c | 37 +++++++++++++++++++++++++++++++++++-- include/net/ethoc.h | 1 + 2 files changed, 36 insertions(+), 2 deletions(-)drivers/net/ethernet/ethoc.c +5
-2@@ -13,6 +13,7 @@#include <linux/dma-mapping.h> #include <linux/etherdevice.h> +#include <linux/clk.h> #include <linux/crc32.h> #include <linux/interrupt.h> #include <linux/io.h> @@ -216,6 +217,7 @@ struct ethoc {struct phy_device *phy;struct mii_bus *mdio; +struct clk *clk;s8 phy_id; };@@ -925,6 +927,8 @@ static int ethoc_probe(struct platform_device *pdev)int num_bd;int ret =0 ;bool random_mac = false; +u32 eth_clkfreq =0 ; +struct ethoc_platform_data *pdata =dev_get_platdata (&pdev->dev);/* allocate networking device */ netdev =alloc_etherdev (sizeof (struct ethoc ));@@ -1038,8 +1042,7 @@ static int ethoc_probe(struct platform_device *pdev) }/* Allow the platform setup code to pass in a MAC address. */ -if (dev_get_platdata (&pdev->dev)) { -struct ethoc_platform_data *pdata =dev_get_platdata (&pdev->dev); +if (pdata) {memcpy (netdev->dev_addr, pdata->hwaddr,IFHWADDRLEN ); priv->phy_id = pdata->phy_id;} else {drivers/net/ethernet/ethoc.c +0
-0@@ -1077,6 +1080,32 @@ static int ethoc_probe(struct platform_device *pdev)if (random_mac) netdev->addr_assign_type =NET_ADDR_RANDOM ;
Quoted 7 lines
drivers/net/ethernet/ethoc.c static int ethoc_probe(struct platform_device *pdev) · line 1085
Quoted 4 lines
drivers/net/ethernet/ethoc.c +1
-0+/* Allow the platform setup code to adjust MII management bus clock. */
drivers/net/ethernet/ethoc.c +2
-0+if (pdata) + eth_clkfreq = pdata->eth_clkfreq;Since this is a new member, why not make it a struct clk pointer directly so you could simplify the code path?
Basically this is to provide flexibility for the user: it may be more appropriate to
specify frequency if it's known and fixed, otherwise clk_get below would find the
clock registered for this device/generic clock.
Quoted 5 lines
drivers/net/ethernet/ethoc.c static int ethoc_probe(struct platform_device *pdev) · line 1090
Quoted 5 lines
drivers/net/ethernet/ethoc.c +5
-0+else +of_property_read_u32 (pdev->dev.of_node, +"clock-frequency" , ð_clkfreq); +if (!eth_clkfreq) { +struct clk *clk =clk_get (&pdev->dev,NULL );
This should have been devm_clk_get.
Quoted 16 lines
Quoted 16 lines
drivers/net/ethernet/ethoc.c +15
-0+ +if (!IS_ERR (clk)) { + priv->clk = clk; +clk_prepare_enable (clk); + eth_clkfreq =clk_get_rate (clk); + } + } +if (eth_clkfreq) { +u32 clkdiv =MIIMODER_CLKDIV (eth_clkfreq /2500000 +1 ); + +if (!clkdiv) + clkdiv =2 ; +dev_dbg (&pdev->dev,"setting MII clkdiv to %u\n" , clkdiv); +ethoc_write (priv,MIIMODER , + (ethoc_read(priv, MIIMODER) & MIIMODER_NOPRE)|
Quoted 8 lines
drivers/net/ethernet/ethoc.c static int ethoc_probe(struct platform_device *pdev) · line 1107
Quoted 2 lines
drivers/net/ethernet/ethoc.c +2
-0+ clkdiv); + }This does look a bit convoluted, and it looks like the
clk_get()or getting the clock-frequency property should boil down to being the same thing withof_clk_get()as it should resolve all clocks phandles and fetch their frequencies appropriately.
I can drop clock-frequency property checking to encourage usage of common clock framework. I don't quite understand the rest of the objection, could you please rephrase it? clk_get calls of_clk_get internally.
Quoted 5 lines
Quoted 5 lines
drivers/net/ethernet/ethoc.c +1
-0+/* register MII bus */ priv->mdio =mdiobus_alloc ();if (!priv->mdio) {@@ -1141,6 +1170,8 @@ free_mdio:
Quoted 8 lines
drivers/net/ethernet/ethoc.c free_mdio: · line 1174
Quoted 5 lines
drivers/net/ethernet/ethoc.c +2
-0kfree (priv->mdio->irq);mdiobus_free (priv->mdio); free: +if (priv->clk) +clk_disable_unprepare (priv->clk);This should probbaly be if (!IS_ERR(priv-clk)).
No, I haven't changed priv->clk when get_clk returned error.
Quoted 5 lines
Quoted 5 lines
drivers/net/ethernet/ethoc.c +0
-0free_netdev (netdev); out:return ret;@@ -1165,6 +1196,8 @@ static int ethoc_remove(struct platform_device *pdev)
Quoted 8 lines
drivers/net/ethernet/ethoc.c static int ethoc_remove(struct platform_device *pdev) · line 1200
Quoted 5 lines
drivers/net/ethernet/ethoc.c +2
-0kfree (priv->mdio->irq);mdiobus_free (priv->mdio); } +if (priv->clk) +clk_disable_unprepare (priv->clk);Same here
Ditto.
Quoted 16 lines
Quoted 16 lines
drivers/net/ethernet/ethoc.c +0
-0unregister_netdev (netdev);free_netdev (netdev);}include/net/ethoc.h +1
-0@@ -16,6 +16,7 @@struct ethoc_platform_data {u8 hwaddr[IFHWADDRLEN ];s8 phy_id; +u32 eth_clkfreq; };#endif /* !LINUX_NET_ETHOC_H */
Signature · 2 lines
Thanks. -- Max
PATCH v2 4/4 net: ethoc: implement ethtool operations
In reply to Max FilippovThe following methods are implemented:
- get/set settings;
- get registers length/registers;
- get link state (standard implementation);
- get/set ring parameters;
- get timestamping info (standard implementation).
---
Changes v1->v2:
- new patch.
drivers/net/ethernet/ethoc.c | 85 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+)
drivers/net/ethernet/ethoc.c +85 -0
@@ -52,6 +52,7 @@ MODULE_PARM_DESC(buffer_size, "DMA buffer allocation size");#define ETH_HASH0 0x48#define ETH_HASH1 0x4c#define ETH_TXCTRL 0x50 +#define ETH_END 0x54/* mode register */ #define MODER_RXEN (1 << 0)/* receive enable */
@@ -180,6 +181,7 @@ MODULE_PARM_DESC(buffer_size, "DMA buffer allocation size");* @membase: pointer to buffer memory region * @dma_alloc: dma allocated buffer size * @io_region_size: I/O memory region size +* @num_bd: number of buffer descriptors * @num_tx: number of send buffers * @cur_tx: last send buffer written * @dty_tx: last buffer actually sent
@@ -200,6 +202,7 @@ struct ethoc {int dma_alloc;resource_size_t io_region_size; +unsigned int num_bd;unsigned int num_tx;unsigned int cur_tx;unsigned int dty_tx;
@@ -900,6 +903,86 @@ out:return NETDEV_TX_OK ; } +static int ethoc_get_settings (struct net_device *dev,struct ethtool_cmd *cmd) +{ +struct ethoc *priv =netdev_priv (dev); +struct phy_device *phydev = priv->phy; + +if (!phydev) +return -ENODEV ; + +return phy_ethtool_gset (phydev, cmd); +} + +static int ethoc_set_settings (struct net_device *dev,struct ethtool_cmd *cmd) +{ +struct ethoc *priv =netdev_priv (dev); +struct phy_device *phydev = priv->phy; + +if (!phydev) +return -ENODEV ; + +return phy_ethtool_sset (phydev, cmd); +} + +static int ethoc_get_regs_len (struct net_device *netdev) +{ +return ETH_END ; +} + +static void ethoc_get_regs (struct net_device *dev,struct ethtool_regs *regs, +void *p) +{ +struct ethoc *priv =netdev_priv (dev); +u32 *regs_buff = p; +unsigned i; + + regs->version =0 ; +for (i =0 ; i <ETH_END /sizeof (u32); ++i) + regs_buff[i] =ethoc_read (priv, i *sizeof (u32)); +} + +static void ethoc_get_ringparam (struct net_device *dev, +struct ethtool_ringparam *ring) +{ +struct ethoc *priv =netdev_priv (dev); + + ring->rx_max_pending = priv->num_bd; + ring->rx_mini_max_pending =0 ; + ring->rx_jumbo_max_pending =0 ; + ring->tx_max_pending = priv->num_bd; + + ring->rx_pending = priv->num_rx; + ring->rx_mini_pending =0 ; + ring->rx_jumbo_pending =0 ; + ring->tx_pending = priv->num_tx; +} + +static int ethoc_set_ringparam (struct net_device *dev, +struct ethtool_ringparam *ring) +{ +struct ethoc *priv =netdev_priv (dev); + +if (netif_running (dev)) +return -EBUSY ; + priv->num_tx =rounddown_pow_of_two (ring->tx_pending); + priv->num_rx = priv->num_bd - priv->num_tx; +if (priv->num_rx > ring->rx_pending) + priv->num_rx = ring->rx_pending; +return 0 ; +} + +const struct ethtool_ops ethoc_ethtool_ops = { + .get_settings = ethoc_get_settings, + .set_settings = ethoc_set_settings, + .get_regs_len = ethoc_get_regs_len, + .get_regs = ethoc_get_regs, + .get_link = ethtool_op_get_link, + .get_ringparam = ethoc_get_ringparam, + .set_ringparam = ethoc_set_ringparam, + .get_ts_info = ethtool_op_get_ts_info, +}; +static const struct net_device_ops ethoc_netdev_ops = { .ndo_open = ethoc_open, .ndo_stop = ethoc_stop,
@@ -1028,6 +1111,7 @@ static int ethoc_probe(struct platform_device *pdev) ret = -ENODEV ; goto error; } + priv->num_bd = num_bd;/* num_tx must be a power of two */ priv->num_tx =rounddown_pow_of_two (num_bd >>1 ); priv->num_rx = num_bd - priv->num_tx;
@@ -1148,6 +1232,7 @@ static int ethoc_probe(struct platform_device *pdev) netdev->netdev_ops = ðoc_netdev_ops; netdev->watchdog_timeo =ETHOC_TIMEOUT ; netdev->features |=0 ; + netdev->ethtool_ops = ðoc_ethtool_ops;/* setup NAPI */ netif_napi_add (netdev, &priv->napi, ethoc_poll,64 );
Signature · 1 line
1.8.1.4
Re: [PATCH v2 4/4] net: ethoc: implement ethtool operations
Quoted 6 lines · Max Filippov
The following methods are implemented:
- get/set settings;
- get registers length/registers;
- get link state (standard implementation);
- get/set ring parameters;
- get timestamping info (standard implementation).
Ideally you should have one patch per ethtool callback that you implement just in case something happens to break, only the specific patch can reverted/referenced.
Quoted 141 lines
Signed-off-by Max Filippov <[email protected]>---
Changesv1->v2:
- new patch.drivers/net/ethernet/ethoc.c | 85 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+)drivers/net/ethernet/ethoc.c +85
-0@@ -52,6 +52,7 @@ MODULE_PARM_DESC(buffer_size, "DMA buffer allocation size");#define ETH_HASH0 0x48#define ETH_HASH1 0x4c#define ETH_TXCTRL 0x50 +#define ETH_END 0x54/* mode register */ #define MODER_RXEN (1 << 0)/* receive enable */ @@ -180,6 +181,7 @@ MODULE_PARM_DESC(buffer_size, "DMA buffer allocation size");* @membase: pointer to buffer memory region * @dma_alloc: dma allocated buffer size * @io_region_size: I/O memory region size +* @num_bd: number of buffer descriptors * @num_tx: number of send buffers * @cur_tx: last send buffer written * @dty_tx: last buffer actually sent @@ -200,6 +202,7 @@ struct ethoc {int dma_alloc;resource_size_t io_region_size; +unsigned int num_bd;unsigned int num_tx;unsigned int cur_tx;unsigned int dty_tx;@@ -900,6 +903,86 @@ out:return NETDEV_TX_OK ; } +static int ethoc_get_settings (struct net_device *dev,struct ethtool_cmd *cmd) +{ +struct ethoc *priv =netdev_priv (dev); +struct phy_device *phydev = priv->phy; + +if (!phydev) +return -ENODEV ; + +return phy_ethtool_gset (phydev, cmd); +} + +static int ethoc_set_settings (struct net_device *dev,struct ethtool_cmd *cmd) +{ +struct ethoc *priv =netdev_priv (dev); +struct phy_device *phydev = priv->phy; + +if (!phydev) +return -ENODEV ; + +return phy_ethtool_sset (phydev, cmd); +} + +static int ethoc_get_regs_len (struct net_device *netdev) +{ +return ETH_END ; +} + +static void ethoc_get_regs (struct net_device *dev,struct ethtool_regs *regs, +void *p) +{ +struct ethoc *priv =netdev_priv (dev); +u32 *regs_buff = p; +unsigned i; + + regs->version =0 ; +for (i =0 ; i <ETH_END /sizeof (u32); ++i) + regs_buff[i] =ethoc_read (priv, i *sizeof (u32)); +} + +static void ethoc_get_ringparam (struct net_device *dev, +struct ethtool_ringparam *ring) +{ +struct ethoc *priv =netdev_priv (dev); + + ring->rx_max_pending = priv->num_bd; + ring->rx_mini_max_pending =0 ; + ring->rx_jumbo_max_pending =0 ; + ring->tx_max_pending = priv->num_bd; + + ring->rx_pending = priv->num_rx; + ring->rx_mini_pending =0 ; + ring->rx_jumbo_pending =0 ; + ring->tx_pending = priv->num_tx; +} + +static int ethoc_set_ringparam (struct net_device *dev, +struct ethtool_ringparam *ring) +{ +struct ethoc *priv =netdev_priv (dev); + +if (netif_running (dev)) +return -EBUSY ; + priv->num_tx =rounddown_pow_of_two (ring->tx_pending); + priv->num_rx = priv->num_bd - priv->num_tx; +if (priv->num_rx > ring->rx_pending) + priv->num_rx = ring->rx_pending; +return 0 ; +} + +const struct ethtool_ops ethoc_ethtool_ops = { + .get_settings = ethoc_get_settings, + .set_settings = ethoc_set_settings, + .get_regs_len = ethoc_get_regs_len, + .get_regs = ethoc_get_regs, + .get_link = ethtool_op_get_link, + .get_ringparam = ethoc_get_ringparam, + .set_ringparam = ethoc_set_ringparam, + .get_ts_info = ethtool_op_get_ts_info, +}; +static const struct net_device_ops ethoc_netdev_ops = { .ndo_open = ethoc_open, .ndo_stop = ethoc_stop,@@ -1028,6 +1111,7 @@ static int ethoc_probe(struct platform_device *pdev) ret = -ENODEV ; goto error; } + priv->num_bd = num_bd;/* num_tx must be a power of two */ priv->num_tx =rounddown_pow_of_two (num_bd >>1 ); priv->num_rx = num_bd - priv->num_tx;@@ -1148,6 +1232,7 @@ static int ethoc_probe(struct platform_device *pdev) netdev->netdev_ops = ðoc_netdev_ops; netdev->watchdog_timeo =ETHOC_TIMEOUT ; netdev->features |=0 ; + netdev->ethtool_ops = ðoc_ethtool_ops;/* setup NAPI */ netif_napi_add (netdev, &priv->napi, ethoc_poll,64 );
Re: [PATCH v2 4/4] net: ethoc: implement ethtool operations
In reply to Max FilippovQuoted 6 lines · Max Filippov
The following methods are implemented:
- get/set settings;
- get registers length/registers;
- get link state (standard implementation);
- get/set ring parameters;
- get timestamping info (standard implementation).
[...]
Quoted 14 lines
drivers/net/ethernet/ethoc.c +11
-0+static int ethoc_get_settings (struct net_device *dev,struct ethtool_cmd *cmd) +{ +struct ethoc *priv =netdev_priv (dev); +struct phy_device *phydev = priv->phy; + +if (!phydev) +return -ENODEV ; + +return phy_ethtool_gset (phydev, cmd); +} +
drivers/net/ethernet/ethoc.c out: · line 926
Quoted 10 lines
drivers/net/ethernet/ethoc.c +10
-0+static int ethoc_set_settings (struct net_device *dev,struct ethtool_cmd *cmd) +{ +struct ethoc *priv =netdev_priv (dev); +struct phy_device *phydev = priv->phy; + +if (!phydev) +return -ENODEV ; + +return phy_ethtool_sset (phydev, cmd); +}
I think these should return -EOPNOTSUPP in the PHY-less case, just as if the set_settings pointer was not set.
[...]
Quoted 13 lines
drivers/net/ethernet/ethoc.c +13
-0+static void ethoc_get_ringparam (struct net_device *dev, +struct ethtool_ringparam *ring) +{ +struct ethoc *priv =netdev_priv (dev); + + ring->rx_max_pending = priv->num_bd; + ring->rx_mini_max_pending =0 ; + ring->rx_jumbo_max_pending =0 ; + ring->tx_max_pending = priv->num_bd; + + ring->rx_pending = priv->num_rx; + ring->rx_mini_pending =0 ; + ring->rx_jumbo_pending =0 ;
drivers/net/ethernet/ethoc.c out: · line 967
Quoted 10 lines
drivers/net/ethernet/ethoc.c +10
-0+ ring->tx_pending = priv->num_tx; +} + +static int ethoc_set_ringparam (struct net_device *dev, +struct ethtool_ringparam *ring) +{ +struct ethoc *priv =netdev_priv (dev); + +if (netif_running (dev)) +return -EBUSY ;
This is unhelpful. Most implementations of this operation will restart the interface if it's running.
drivers/net/ethernet/ethoc.c out: · line 968
Quoted 1 line
drivers/net/ethernet/ethoc.c +1
-0+ priv->num_tx =rounddown_pow_of_two (ring->tx_pending);
Range check?
drivers/net/ethernet/ethoc.c out: · line 971
Quoted 3 lines
drivers/net/ethernet/ethoc.c +3
-0+ priv->num_rx = priv->num_bd - priv->num_tx; +if (priv->num_rx > ring->rx_pending) + priv->num_rx = ring->rx_pending;
So the RX ring may only ever be shrunk?! Did you mean to compare with priv->num_bd instead?
drivers/net/ethernet/ethoc.c out: · line 975
Quoted 4 lines
drivers/net/ethernet/ethoc.c +4
-0+return 0 ; +} + +const struct ethtool_ops ethoc_ethtool_ops = {
static
Quoted 9 lines
drivers/net/ethernet/ethoc.c +9
-0+ .get_settings = ethoc_get_settings, + .set_settings = ethoc_set_settings, + .get_regs_len = ethoc_get_regs_len, + .get_regs = ethoc_get_regs, + .get_link = ethtool_op_get_link, + .get_ringparam = ethoc_get_ringparam, + .set_ringparam = ethoc_set_ringparam, + .get_ts_info = ethtool_op_get_ts_info, +};
[...]
Signature · 2 lines
Ben Hutchings It is a miracle that curiosity survives formal education. - Albert Einstein
Re: [PATCH v2 4/4] net: ethoc: implement ethtool operations
Quoted 27 lines · Ben Hutchings
Quoted 6 lines · Max Filippov
The following methods are implemented:
- get/set settings;
- get registers length/registers;
- get link state (standard implementation);
- get/set ring parameters;
- get timestamping info (standard implementation).[...]
Quoted 19 lines
drivers/net/ethernet/ethoc.c +16
-0+static int ethoc_get_settings (struct net_device *dev,struct ethtool_cmd *cmd) +{ +struct ethoc *priv =netdev_priv (dev); +struct phy_device *phydev = priv->phy; + +if (!phydev) +return -ENODEV ; + +return phy_ethtool_gset (phydev, cmd); +} + +static int ethoc_set_settings (struct net_device *dev,struct ethtool_cmd *cmd) +{ +struct ethoc *priv =netdev_priv (dev); +struct phy_device *phydev = priv->phy; +
Quoted 8 lines
drivers/net/ethernet/ethoc.c out: · line 926
Quoted 5 lines
drivers/net/ethernet/ethoc.c +5
-0+if (!phydev) +return -ENODEV ; + +return phy_ethtool_sset (phydev, cmd); +}I think these should return
-EOPNOTSUPPin the PHY-less case, just as if theset_settingspointer was not set.
Ok
Quoted 19 lines
[...]
Quoted 18 lines
drivers/net/ethernet/ethoc.c +18
-0+static void ethoc_get_ringparam (struct net_device *dev, +struct ethtool_ringparam *ring) +{ +struct ethoc *priv =netdev_priv (dev); + + ring->rx_max_pending = priv->num_bd; + ring->rx_mini_max_pending =0 ; + ring->rx_jumbo_max_pending =0 ; + ring->tx_max_pending = priv->num_bd; + + ring->rx_pending = priv->num_rx; + ring->rx_mini_pending =0 ; + ring->rx_jumbo_pending =0 ; + ring->tx_pending = priv->num_tx; +} + +static int ethoc_set_ringparam (struct net_device *dev, +struct ethtool_ringparam *ring)
Quoted 8 lines
drivers/net/ethernet/ethoc.c out: · line 967
Quoted 5 lines
drivers/net/ethernet/ethoc.c +5
-0+{ +struct ethoc *priv =netdev_priv (dev); + +if (netif_running (dev)) +return -EBUSY ;This is unhelpful. Most implementations of this operation will restart the interface if it's running.
Ok
Quoted 3 lines
Quoted 1 line
+
priv->num_tx=rounddown_pow_of_two(ring->tx_pending);Range check?
May there be requested more than ring->tx_max_pending that we indicated in the get_ringparam?
Quoted 6 lines
drivers/net/ethernet/ethoc.c out: · line 971
Quoted 3 lines
drivers/net/ethernet/ethoc.c +3
-0+ priv->num_rx = priv->num_bd - priv->num_tx; +if (priv->num_rx > ring->rx_pending) + priv->num_rx = ring->rx_pending;So the RX ring may only ever be shrunk?! Did you mean to compare with
priv->num_bdinstead?
First all non-TX descriptors are made RX, and if that's more than user requested I trim it.
Quoted 6 lines
drivers/net/ethernet/ethoc.c out: · line 975
Quoted 4 lines
drivers/net/ethernet/ethoc.c +4
-0+return 0 ; +} + +const struct ethtool_ops ethoc_ethtool_ops = {static
Ok
Signature · 2 lines
Thanks. -- Max
Re: [PATCH v2 4/4] net: ethoc: implement ethtool operations
Quoted 2 lines · Max Filippov
Quoted 1 line · Ben Hutchings
On Wed, 2014-01-29 at 10:00 +0400, Max Filippov wrote:
[...]
Quoted 6 lines
Quoted 3 lines
Quoted 1 line
+
priv->num_tx=rounddown_pow_of_two(ring->tx_pending);Range check?
May there be requested more than
ring->tx_max_pendingthat we indicated in theget_ringparam?
Yes, the ethtool core doesn't check that for you.
Quoted 9 lines
Quoted 6 lines
drivers/net/ethernet/ethoc.c out: · line 971
Quoted 3 lines
drivers/net/ethernet/ethoc.c +3
-0+ priv->num_rx = priv->num_bd - priv->num_tx; +if (priv->num_rx > ring->rx_pending) + priv->num_rx = ring->rx_pending;So the RX ring may only ever be shrunk?! Did you mean to compare with
priv->num_bdinstead?First all non-TX descriptors are made RX, and if that's more than user requested I trim it.
[...]
OK, I get it. But it would be clearer if you used min().
Ben.
Signature · 2 lines
Ben Hutchings It is a miracle that curiosity survives formal education. - Albert Einstein