phylib consolidation
Subsystems (3)
Russell King - ARM Linux admin
reviewercover phylib consolidation
Hi,
Over the last few releases, there has been a push to clean up and consolidate the phylib code. Some cases have been missed, and this series catches those cases.
1. Remove redundant .aneg_done initialisers; calling genphy_aneg_done() for clause 22 PHYs is the default when .aneg_done is not set.
2. Some PHY drivers manually set phydev->pause and phydev->asym_pause, but we have a helper for this - phy_resolve_aneg_pause(), introduced in 2d880b8709c0 ("net: phy: extract pause mode"). Use this in the lxt, marvell and uPD60620 drivers.
Incidentally, this brings up the question whether marvell fiber mode is correctly interpreting and advertising the pause parameters.
3. Add a genphy_check_and_restart_aneg() helper, which complements the clause 45 version of this. This will be useful for PHY drivers that open code this logic (e.g. marvell.c)
4. Add a genphy_read_status_fixed() helper to read the fixed-mode status from a clause 22 PHY. lxt and marvell both contain copies of this code, so convert them over.
5. Arrange marvell driver to use genphy_read_lpa() for copper mode. This needs some rearrangement of the code in marvell_read_status_page_an(), but preserves using the PHY specific status register to derive the current negotiation results.
6. Simplify the marvell driver so we can use the genphy_read_status_fixed() helper directly rather than marvell_read_status_page_fixed().
7. Use positive logic in the marvell driver to determine the link state, and get rid of the REGISTER_LINK_STATUS definition; we already have a definition for this.
8. The marvell driver reads the PHY specific status register multiple times when determining the status: once in marvell_update_link() and again in marvell_read_status_page_an(). This is a waste; rearrange to read the status register once, and pass its value into marvell_read_status_page_an(). We preserve using genphy_update_link() for the copper side.
9. The marvell driver was using private clause 37 definitions, but we have clause 37 definitions in uapi/linux/mii.h. Use the generic definitions.
10. Switch the marvell driver to use phy_modify_changed() to modify the fiber advertisement.
11. Switch the marvell driver to use genphy_check_and_restart_aneg() introduced above rather than open-coding this functionality.
drivers/net/phy/lxt.c | 24 +---- drivers/net/phy/marvell.c | 209 ++++++++++++------------------------------- drivers/net/phy/mscc.c | 6 -- drivers/net/phy/phy_device.c | 98 +++++++++++++------- drivers/net/phy/uPD60620.c | 7 +- include/linux/phy.h | 2 + 6 files changed, 129 insertions(+), 217 deletions(-)
Signature · 3 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTC broadband for 0.8mile line in suburbia: sync at 12.1Mbps down 622kbps up According to speedtest.net: 11.9Mbps down 500kbps up
PATCH 1/11 net: phy: remove redundant .aneg_done initialisers
Remove initialisers that set .aneg_done to genphy_aneg_done - this is the default for clause 22 PHYs, so the initialiser is redundant.
--- drivers/net/phy/mscc.c | 6 ------ drivers/net/phy/phy_device.c | 1 - 2 files changed, 7 deletions(-)
drivers/net/phy/mscc.c +0 -6
@@ -2352,7 +2352,6 @@ static struct phy_driver vsc85xx_driver[] = { .soft_reset = &genphy_soft_reset, .config_init = &vsc85xx_config_init, .config_aneg = &vsc85xx_config_aneg, - .aneg_done = &genphy_aneg_done, .read_status = &vsc85xx_read_status, .ack_interrupt = &vsc85xx_ack_interrupt, .config_intr = &vsc85xx_config_intr,
@@ -2377,7 +2376,6 @@ static struct phy_driver vsc85xx_driver[] = { .soft_reset = &genphy_soft_reset, .config_init = &vsc85xx_config_init, .config_aneg = &vsc85xx_config_aneg, - .aneg_done = &genphy_aneg_done, .read_status = &vsc85xx_read_status, .ack_interrupt = &vsc85xx_ack_interrupt, .config_intr = &vsc85xx_config_intr,
@@ -2402,7 +2400,6 @@ static struct phy_driver vsc85xx_driver[] = { .soft_reset = &genphy_soft_reset, .config_init = &vsc85xx_config_init, .config_aneg = &vsc85xx_config_aneg, - .aneg_done = &genphy_aneg_done, .read_status = &vsc85xx_read_status, .ack_interrupt = &vsc85xx_ack_interrupt, .config_intr = &vsc85xx_config_intr,
@@ -2427,7 +2424,6 @@ static struct phy_driver vsc85xx_driver[] = { .soft_reset = &genphy_soft_reset, .config_init = &vsc85xx_config_init, .config_aneg = &vsc85xx_config_aneg, - .aneg_done = &genphy_aneg_done, .read_status = &vsc85xx_read_status, .ack_interrupt = &vsc85xx_ack_interrupt, .config_intr = &vsc85xx_config_intr,
@@ -2452,7 +2448,6 @@ static struct phy_driver vsc85xx_driver[] = { .soft_reset = &genphy_soft_reset, .config_init = &vsc8584_config_init, .config_aneg = &vsc85xx_config_aneg, - .aneg_done = &genphy_aneg_done, .read_status = &vsc85xx_read_status, .ack_interrupt = &vsc85xx_ack_interrupt, .config_intr = &vsc85xx_config_intr,
@@ -2478,7 +2473,6 @@ static struct phy_driver vsc85xx_driver[] = { .soft_reset = &genphy_soft_reset, .config_init = &vsc8584_config_init, .config_aneg = &vsc85xx_config_aneg, - .aneg_done = &genphy_aneg_done, .read_status = &vsc85xx_read_status, .ack_interrupt = &vsc85xx_ack_interrupt, .config_intr = &vsc85xx_config_intr,
drivers/net/phy/phy_device.c +0 -1
@@ -2452,7 +2452,6 @@ static struct phy_driver genphy_driver = { .name = "Generic PHY", .soft_reset = genphy_no_soft_reset, .get_features = genphy_read_abilities, - .aneg_done = genphy_aneg_done, .suspend = genphy_suspend, .resume = genphy_resume, .set_loopback = genphy_loopback,
Signature · 1 line
2.20.1
Re: [PATCH net-next 01/11] net: phy: remove redundant .aneg_done initialisers
Quoted 4 lines · Russell King
Remove initialisers that set .aneg_done to
genphy_aneg_done- this is the default for clause 22 PHYs, so the initialiser is redundant.Signed-off-by Russell King <[email protected]>
Andrew
Re: [PATCH net-next 01/11] net: phy: remove redundant .aneg_done initialisers
In reply to Russell KingQuoted 4 lines · Russell King
Remove initialisers that set .aneg_done to
genphy_aneg_done- this is the default for clause 22 PHYs, so the initialiser is redundant.Signed-off-by Russell King <[email protected]>
Signature · 1 line
Florian
PATCH 2/11 net: phy: use phy_resolve_aneg_pause()
In reply to Russell King - ARM Linux adminSeveral drivers code their own version of this, working from the LPA register, after setting the ethtool link partner advertisement bitmask. Use the generic function instead.
--- drivers/net/phy/lxt.c | 5 +---- drivers/net/phy/marvell.c | 5 +---- drivers/net/phy/uPD60620.c | 7 +------ 3 files changed, 3 insertions(+), 14 deletions(-)
drivers/net/phy/lxt.c +1 -4
@@ -190,10 +190,7 @@ static int lxt973a2_read_status(struct phy_device *phydev) phydev->duplex =DUPLEX_FULL ; } -if (phydev->duplex ==DUPLEX_FULL ) { - phydev->pause = lpa &LPA_PAUSE_CAP ?1 :0 ; - phydev->asym_pause = lpa &LPA_PAUSE_ASYM ?1 :0 ; - } +phy_resolve_aneg_pause (phydev); }else {int bmcr =phy_read (phydev,MII_BMCR );
drivers/net/phy/marvell.c +1 -4
@@ -1260,10 +1260,7 @@ static int marvell_read_status_page_an(struct phy_device *phydev,mii_lpa_to_linkmode_lpa_t (phydev->lp_advertising, lpa);mii_stat1000_mod_linkmode_lpa_t (phydev->lp_advertising, lpagb); -if (phydev->duplex ==DUPLEX_FULL ) { - phydev->pause = lpa &LPA_PAUSE_CAP ?1 :0 ; - phydev->asym_pause = lpa &LPA_PAUSE_ASYM ?1 :0 ; - } +phy_resolve_aneg_pause (phydev); }else {/* The fiber link is only 1000M capable */ fiber_lpa_mod_linkmode_lpa_t (phydev->lp_advertising, lpa);
drivers/net/phy/uPD60620.c +1 -6
@@ -68,12 +68,7 @@ static int upd60620_read_status(struct phy_device *phydev)mii_lpa_to_linkmode_lpa_t (phydev->lp_advertising, phy_state); -if (phydev->duplex ==DUPLEX_FULL ) { -if (phy_state &LPA_PAUSE_CAP ) - phydev->pause =1 ; -if (phy_state &LPA_PAUSE_ASYM ) - phydev->asym_pause =1 ; - } +phy_resolve_aneg_pause (phydev); } }return 0 ;
Signature · 1 line
2.20.1
Re: [PATCH net-next 02/11] net: phy: use phy_resolve_aneg_pause()
Quoted 5 lines · Russell King
Several drivers code their own version of this, working from the LPA register, after setting the ethtool link partner advertisement bitmask. Use the generic function instead.
Signed-off-by Russell King <[email protected]>
Andrew
Re: [PATCH net-next 02/11] net: phy: use phy_resolve_aneg_pause()
In reply to Russell KingQuoted 5 lines · Russell King
Several drivers code their own version of this, working from the LPA register, after setting the ethtool link partner advertisement bitmask. Use the generic function instead.
Signed-off-by Russell King <[email protected]>
Signature · 1 line
Florian
PATCH 3/11 net: phy: add genphy_check_and_restart_aneg()
In reply to Russell King - ARM Linux adminAdd a helper for restarting autonegotiation(), similar to the clause 45 variant. Use it in __genphy_config_aneg()
--- drivers/net/phy/phy_device.c | 48 +++++++++++++++++++++++------------- include/linux/phy.h | 1 + 2 files changed, 32 insertions(+), 17 deletions(-)
drivers/net/phy/phy_device.c +31 -17
@@ -1736,6 +1736,36 @@ int genphy_restart_aneg(struct phy_device *phydev) }EXPORT_SYMBOL (genphy_restart_aneg); +/** +* genphy_check_and_restart_aneg - Enable and restart auto-negotiation +* @phydev: target phy_device struct +* @restart: whether aneg restart is requested +* +* Check, and restart auto-negotiation if needed. +*/ +int genphy_check_and_restart_aneg (struct phy_device *phydev,bool restart) +{ +int ret =0 ; + +if (!restart) { +/* Advertisement hasn't changed, but maybe aneg was never on to +* begin with? Or maybe phy was isolated? +*/ + ret =phy_read (phydev,MII_BMCR ); +if (ret <0 ) +return ret; + +if (!(ret &BMCR_ANENABLE ) || (ret &BMCR_ISOLATE )) + restart = true; + } + +if (restart) + ret =genphy_restart_aneg (phydev); + +return ret; +} +EXPORT_SYMBOL (genphy_check_and_restart_aneg); +/** * __genphy_config_aneg - restart auto-negotiation or write BMCR * @phydev: target phy_device struct
@@ -1761,23 +1791,7 @@ int __genphy_config_aneg(struct phy_device *phydev, bool changed)else if (err) changed = true; -if (!changed) { -/* Advertisement hasn't changed, but maybe aneg was never on to -* begin with? Or maybe phy was isolated? -*/ -int ctl =phy_read (phydev,MII_BMCR ); - -if (ctl <0 ) -return ctl; - -if (!(ctl &BMCR_ANENABLE ) || (ctl &BMCR_ISOLATE )) - changed = true;/* do restart aneg */ - } - -/* Only restart aneg if we are advertising something different -* than we were before. -*/ -return changed ?genphy_restart_aneg (phydev) :0 ; +return genphy_check_and_restart_aneg (phydev, changed); }EXPORT_SYMBOL (__genphy_config_aneg);
include/linux/phy.h +1 -0
@@ -1095,6 +1095,7 @@ void phy_attached_info(struct phy_device *phydev);int genphy_read_abilities (struct phy_device *phydev);int genphy_setup_forced (struct phy_device *phydev);int genphy_restart_aneg (struct phy_device *phydev); +int genphy_check_and_restart_aneg (struct phy_device *phydev,bool restart);int genphy_config_eee_advert (struct phy_device *phydev);int __genphy_config_aneg (struct phy_device *phydev,bool changed);int genphy_aneg_done (struct phy_device *phydev);
Signature · 1 line
2.20.1
Re: [PATCH net-next 03/11] net: phy: add genphy_check_and_restart_aneg()
Quoted 4 lines · Russell King
Add a helper for restarting
autonegotiation(), similar to the clause 45 variant. Use it in__genphy_config_aneg()Signed-off-by Russell King <[email protected]>
Andrew
Re: [PATCH net-next 03/11] net: phy: add genphy_check_and_restart_aneg()
In reply to Russell KingQuoted 4 lines · Russell King
Add a helper for restarting
autonegotiation(), similar to the clause 45 variant. Use it in__genphy_config_aneg()Signed-off-by Russell King <[email protected]>
Signature · 1 line
Florian
PATCH 4/11 net: phy: provide and use genphy_read_status_fixed()
In reply to Russell King - ARM Linux adminThere are two drivers and generic code which contain exactly the same code to read the status of a PHY operating without autonegotiation enabled. Rather than duplicate this code, provide a helper to read this information.
--- drivers/net/phy/lxt.c | 19 +++----------- drivers/net/phy/marvell.c | 19 +++----------- drivers/net/phy/phy_device.c | 49 ++++++++++++++++++++++++------------ include/linux/phy.h | 1 + 4 files changed, 41 insertions(+), 47 deletions(-)
drivers/net/phy/lxt.c +3 -16
@@ -192,22 +192,9 @@ static int lxt973a2_read_status(struct phy_device *phydev)phy_resolve_aneg_pause (phydev); }else { -int bmcr =phy_read (phydev,MII_BMCR ); - -if (bmcr <0 ) -return bmcr; - -if (bmcr &BMCR_FULLDPLX ) - phydev->duplex =DUPLEX_FULL ; -else - phydev->duplex =DUPLEX_HALF ; - -if (bmcr &BMCR_SPEED1000 ) - phydev->speed =SPEED_1000 ; -else if (bmcr &BMCR_SPEED100 ) - phydev->speed =SPEED_100 ; -else - phydev->speed =SPEED_10 ; + err =genphy_read_status_fixed (phydev); +if (err <0 ) +return err; phydev->pause = phydev->asym_pause =0 ;linkmode_zero (phydev->lp_advertising);
drivers/net/phy/marvell.c +4 -15
@@ -1283,22 +1283,11 @@ static int marvell_read_status_page_an(struct phy_device *phydev,static int marvell_read_status_page_fixed (struct phy_device *phydev) { -int bmcr =phy_read (phydev,MII_BMCR ); - -if (bmcr <0 ) -return bmcr; - -if (bmcr &BMCR_FULLDPLX ) - phydev->duplex =DUPLEX_FULL ; -else - phydev->duplex =DUPLEX_HALF ; +int err; -if (bmcr &BMCR_SPEED1000 ) - phydev->speed =SPEED_1000 ; -else if (bmcr &BMCR_SPEED100 ) - phydev->speed =SPEED_100 ; -else - phydev->speed =SPEED_10 ; + err =genphy_read_status_fixed (phydev); +if (err <0 ) +return err; phydev->pause =0 ; phydev->asym_pause =0 ;
drivers/net/phy/phy_device.c +33 -16
61 lines not on this page · raw message
include/linux/phy.h +1 -0
@@ -1101,6 +1101,7 @@ int __genphy_config_aneg(struct phy_device *phydev, bool changed);int genphy_aneg_done (struct phy_device *phydev);int genphy_update_link (struct phy_device *phydev);int genphy_read_lpa (struct phy_device *phydev); +int genphy_read_status_fixed (struct phy_device *phydev);int genphy_read_status (struct phy_device *phydev);int genphy_suspend (struct phy_device *phydev);int genphy_resume (struct phy_device *phydev);
Signature · 1 line
2.20.1
Re: [PATCH net-next 04/11] net: phy: provide and use genphy_read_status_fixed()
Quoted 6 lines · Russell King
There are two drivers and generic code which contain exactly the same code to read the status of a PHY operating without autonegotiation enabled. Rather than duplicate this code, provide a helper to read this information.
Signed-off-by Russell King <[email protected]>
Andrew
Re: [PATCH net-next 04/11] net: phy: provide and use genphy_read_status_fixed()
In reply to Russell KingQuoted 6 lines · Russell King
There are two drivers and generic code which contain exactly the same code to read the status of a PHY operating without autonegotiation enabled. Rather than duplicate this code, provide a helper to read this information.
Signed-off-by Russell King <[email protected]>
Signature · 1 line
Florian
PATCH 5/11 net: phy: marvell: rearrange to use genphy_read_lpa()
In reply to Russell King - ARM Linux adminRearrange the Marvell PHY driver to use genphy_read_lpa() rather than open-coding this functionality.
--- drivers/net/phy/marvell.c | 66 +++++++++++++++++++-------------------- 1 file changed, 32 insertions(+), 34 deletions(-)
drivers/net/phy/marvell.c +32 -34
@@ -1219,52 +1219,30 @@ static int marvell_read_status_page_an(struct phy_device *phydev, {int status;int lpa; -int lpagb; +int err; status =phy_read (phydev,MII_M1011_PHY_STATUS );if (status <0 )return status; - lpa =phy_read (phydev,MII_LPA ); -if (lpa <0 ) -return lpa; - - lpagb =phy_read (phydev,MII_STAT1000 ); -if (lpagb <0 ) -return lpagb; - -if (status &MII_M1011_PHY_STATUS_FULLDUPLEX ) - phydev->duplex =DUPLEX_FULL ; -else - phydev->duplex =DUPLEX_HALF ; - - status = status &MII_M1011_PHY_STATUS_SPD_MASK ; - phydev->pause =0 ; - phydev->asym_pause =0 ; - -switch (status) { -case MII_M1011_PHY_STATUS_1000 : - phydev->speed =SPEED_1000 ; -break ; - -case MII_M1011_PHY_STATUS_100 : - phydev->speed =SPEED_100 ; -break ; - -default : - phydev->speed =SPEED_10 ; -break ; - } -if (!fiber) { -mii_lpa_to_linkmode_lpa_t (phydev->lp_advertising, lpa); -mii_stat1000_mod_linkmode_lpa_t (phydev->lp_advertising, lpagb); + err =genphy_read_lpa (phydev); +if (err <0 ) +return err; + phydev->pause =0 ; + phydev->asym_pause =0 ;phy_resolve_aneg_pause (phydev); }else { + lpa =phy_read (phydev,MII_LPA ); +if (lpa <0 ) +return lpa; +/* The fiber link is only 1000M capable */ fiber_lpa_mod_linkmode_lpa_t (phydev->lp_advertising, lpa); + phydev->pause =0 ; + phydev->asym_pause =0 ;if (phydev->duplex ==DUPLEX_FULL ) {if (!(lpa &LPA_PAUSE_FIBER )) { phydev->pause =0 ;
@@ -1278,6 +1256,26 @@ static int marvell_read_status_page_an(struct phy_device *phydev, } } } + +if (status &MII_M1011_PHY_STATUS_FULLDUPLEX ) + phydev->duplex =DUPLEX_FULL ; +else + phydev->duplex =DUPLEX_HALF ; + +switch (status &MII_M1011_PHY_STATUS_SPD_MASK ) { +case MII_M1011_PHY_STATUS_1000 : + phydev->speed =SPEED_1000 ; +break ; + +case MII_M1011_PHY_STATUS_100 : + phydev->speed =SPEED_100 ; +break ; + +default : + phydev->speed =SPEED_10 ; +break ; + } +return 0 ; }
Signature · 1 line
2.20.1
Re: [PATCH net-next 05/11] net: phy: marvell: rearrange to use genphy_read_lpa()
Quoted 4 lines · Russell King
Rearrange the Marvell PHY driver to use
genphy_read_lpa()rather than open-coding this functionality.Signed-off-by Russell King <[email protected]>
Andrew
Re: [PATCH net-next 05/11] net: phy: marvell: rearrange to use genphy_read_lpa()
In reply to Russell KingQuoted 4 lines · Russell King
Rearrange the Marvell PHY driver to use
genphy_read_lpa()rather than open-coding this functionality.Signed-off-by Russell King <[email protected]>
Signature · 1 line
Florian
PATCH 6/11 net: phy: marvell: initialise link partner state earlier
In reply to Russell King - ARM Linux adminMove the initialisation of the link partner state earlier, inside marvell_read_status_page(), so we don't have the same initialisation scattered amongst the other files. This is in a similar place to the genphy implementation, so would result in the same behaviour if a PHY read error occurs.
This allows us to get rid of marvell_read_status_page_fixed(), which became a pointless wrapper around genphy_read_status_fixed().
--- drivers/net/phy/marvell.c | 25 +++++-------------------- 1 file changed, 5 insertions(+), 20 deletions(-)
drivers/net/phy/marvell.c +5 -20
@@ -1230,8 +1230,6 @@ static int marvell_read_status_page_an(struct phy_device *phydev,if (err <0 )return err; - phydev->pause =0 ; - phydev->asym_pause =0 ;phy_resolve_aneg_pause (phydev); }else { lpa =phy_read (phydev,MII_LPA );
@@ -1241,8 +1239,6 @@ static int marvell_read_status_page_an(struct phy_device *phydev,/* The fiber link is only 1000M capable */ fiber_lpa_mod_linkmode_lpa_t (phydev->lp_advertising, lpa); - phydev->pause =0 ; - phydev->asym_pause =0 ;if (phydev->duplex ==DUPLEX_FULL ) {if (!(lpa &LPA_PAUSE_FIBER )) { phydev->pause =0 ;
@@ -1279,21 +1275,6 @@ static int marvell_read_status_page_an(struct phy_device *phydev,return 0 ; } -static int marvell_read_status_page_fixed (struct phy_device *phydev) -{ -int err; - - err =genphy_read_status_fixed (phydev); -if (err <0 ) -return err; - - phydev->pause =0 ; - phydev->asym_pause =0 ; -linkmode_zero (phydev->lp_advertising); - -return 0 ; -} -/* marvell_read_status_page * * Description:
@@ -1319,10 +1300,14 @@ static int marvell_read_status_page(struct phy_device *phydev, int page)if (err)return err; +linkmode_zero (phydev->lp_advertising); + phydev->pause =0 ; + phydev->asym_pause =0 ; +if (phydev->autoneg ==AUTONEG_ENABLE ) err =marvell_read_status_page_an (phydev, fiber);else - err =marvell_read_status_page_fixed (phydev); + err =genphy_read_status_fixed (phydev);return err; }
Signature · 1 line
2.20.1
Re: [PATCH net-next 06/11] net: phy: marvell: initialise link partner state earlier
Quoted 10 lines · Russell King
Move the initialisation of the link partner state earlier, inside
marvell_read_status_page(), so we don't have the same initialisation scattered amongst the other files. This is in a similar place to the genphy implementation, so would result in the same behaviour if a PHY read error occurs.This allows us to get rid of
marvell_read_status_page_fixed(), which became a pointless wrapper aroundgenphy_read_status_fixed().Signed-off-by Russell King <[email protected]>
Andrew
Re: [PATCH net-next 06/11] net: phy: marvell: initialise link partner state earlier
In reply to Russell KingQuoted 10 lines · Russell King
Move the initialisation of the link partner state earlier, inside
marvell_read_status_page(), so we don't have the same initialisation scattered amongst the other files. This is in a similar place to the genphy implementation, so would result in the same behaviour if a PHY read error occurs.This allows us to get rid of
marvell_read_status_page_fixed(), which became a pointless wrapper aroundgenphy_read_status_fixed().Signed-off-by Russell King <[email protected]>
Signature · 1 line
Florian
PATCH 7/11 net: phy: marvell: use positive logic for link state
In reply to Russell King - ARM Linux adminRather than using negative logic:
if (there is no link)
set link = 0
else
set link = 1
use the more natural positive logic:
if (there is link)
set link = 1
else
set link = 0
--- drivers/net/phy/marvell.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/net/phy/marvell.c +3 -4
@@ -168,7 +168,6 @@#define ADVERTISE_PAUSE_FIBER 0x180#define ADVERTISE_PAUSE_ASYM_FIBER 0x100 -#define REGISTER_LINK_STATUS 0x400#define NB_FIBER_STATS 1MODULE_DESCRIPTION ("Marvell PHY driver" );
@@ -1203,10 +1202,10 @@ static int marvell_update_link(struct phy_device *phydev, int fiber)if (status <0 )return status; -if ((status ®ISTER_LINK_STATUS ) ==0 ) - phydev->link =0 ; -else +if (status &MII_M1011_PHY_STATUS_LINK ) phydev->link =1 ; +else + phydev->link =0 ; }else {return genphy_update_link (phydev); }
Signature · 1 line
2.20.1
Re: [PATCH net-next 07/11] net: phy: marvell: use positive logic for link state
Quoted 7 lines · Russell King
Rather than using negative logic:
if (there is no link)
set link = 0
else
set link = 1
Quoted 8 lines
use the more natural positive logic:
if (there is link)
set link = 1
else
set link = 0Signed-off-by Russell King <[email protected]>
Andrew
Re: [PATCH net-next 07/11] net: phy: marvell: use positive logic for link state
In reply to Russell KingQuoted 7 lines · Russell King
Rather than using negative logic:
if (there is no link)
set link = 0
else
set link = 1
Quoted 8 lines
use the more natural positive logic:
if (there is link)
set link = 1
else
set link = 0Signed-off-by Russell King <[email protected]>
Signature · 1 line
Florian
PATCH 8/11 net: phy: marvell: consolidate phy status reading
In reply to Russell King - ARM Linux adminmarvell_read_status_page_an() always reads the PHY status register, but marvell_update_link() has already done this. Rather than wastefully reading the register twice in quick succession, read it once in marvell_read_status_page() and use the result for both.
This makes marvell_update_link() rather pointless, so move it into marvell_read_status_page().
--- drivers/net/phy/marvell.c | 60 +++++++++++---------------------------- 1 file changed, 17 insertions(+), 43 deletions(-)
drivers/net/phy/marvell.c +17 -43
@@ -1183,47 +1183,12 @@ static void fiber_lpa_mod_linkmode_lpa_t(unsigned long *advertising, u32 lpa) advertising, lpa & LPA_FIBER_1000FULL); } -/** -* marvell_update_link - update link status in real time in @phydev -* @phydev: target phy_device struct -* -* Description: Update the value in phydev->link to reflect the -* current link value. -*/ -static int marvell_update_link (struct phy_device *phydev,int fiber) -{ -int status; - -/* Use the generic register for copper link, or specific -* register for fiber case -*/ -if (fiber) { - status =phy_read (phydev,MII_M1011_PHY_STATUS ); -if (status <0 ) -return status; - -if (status &MII_M1011_PHY_STATUS_LINK ) - phydev->link =1 ; -else - phydev->link =0 ; - }else { -return genphy_update_link (phydev); - } - -return 0 ; -} -static int marvell_read_status_page_an (struct phy_device *phydev, -int fiber) +int fiber,int status) { -int status;int lpa;int err; - status =phy_read (phydev,MII_M1011_PHY_STATUS ); -if (status <0 ) -return status; -if (!fiber) { err =genphy_read_lpa (phydev);if (err <0 )
@@ -1284,27 +1249,36 @@ static int marvell_read_status_page_an(struct phy_device *phydev,*/ static int marvell_read_status_page (struct phy_device *phydev,int page) { +int status;int fiber;int err; -/* Detect and update the link, but return if there -* was an error + status =phy_read (phydev,MII_M1011_PHY_STATUS ); +if (status <0 ) +return status; + +/* Use the generic register for copper link status, +* and the PHY status register for fiber link status. */ +if (page ==MII_MARVELL_FIBER_PAGE ) { + phydev->link = !!(status &MII_M1011_PHY_STATUS_LINK ); + }else { + err =genphy_update_link (phydev); +if (err) +return err; + } +if (page ==MII_MARVELL_FIBER_PAGE ) fiber =1 ;else fiber =0 ; - err =marvell_update_link (phydev, fiber); -if (err) -return err; -linkmode_zero (phydev->lp_advertising); phydev->pause =0 ; phydev->asym_pause =0 ;if (phydev->autoneg ==AUTONEG_ENABLE ) - err =marvell_read_status_page_an (phydev, fiber); + err =marvell_read_status_page_an (phydev, fiber, status);else err =genphy_read_status_fixed (phydev);
Signature · 1 line
2.20.1
PATCH 9/11 net: phy: marvell: use existing clause 37 definitions
In reply to Russell King - ARM Linux adminUse existing clause 37 advertising/link partner definitions rather than private ones for the advertisement registers.
--- drivers/net/phy/marvell.c | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-)
drivers/net/phy/marvell.c +8 -18
@@ -156,18 +156,9 @@#define MII_88E1510_GEN_CTRL_REG_1_MODE_SGMII 0x1/* SGMII to copper */ #define MII_88E1510_GEN_CTRL_REG_1_RESET 0x8000/* Soft reset */ -#define LPA_FIBER_1000HALF 0x40 -#define LPA_FIBER_1000FULL 0x20 -#define LPA_PAUSE_FIBER 0x180#define LPA_PAUSE_ASYM_FIBER 0x100 -#define ADVERTISE_FIBER_1000HALF 0x40 -#define ADVERTISE_FIBER_1000FULL 0x20 - -#define ADVERTISE_PAUSE_FIBER 0x180 -#define ADVERTISE_PAUSE_ASYM_FIBER 0x100 -#define NB_FIBER_STATS 1MODULE_DESCRIPTION ("Marvell PHY driver" );
@@ -507,16 +498,15 @@ static inline u32 linkmode_adv_to_fiber_adv_t(unsigned long *advertise)u32 result =0 ;if (linkmode_test_bit (ETHTOOL_LINK_MODE_1000baseT_Half_BIT, advertise)) - result |=ADVERTISE_FIBER_1000HALF ; + result |=ADVERTISE_1000XHALF ;if (linkmode_test_bit (ETHTOOL_LINK_MODE_1000baseT_Full_BIT, advertise)) - result |=ADVERTISE_FIBER_1000FULL ; + result |=ADVERTISE_1000XFULL ;if (linkmode_test_bit (ETHTOOL_LINK_MODE_Asym_Pause_BIT, advertise) &&linkmode_test_bit (ETHTOOL_LINK_MODE_Pause_BIT, advertise)) - result |=LPA_PAUSE_ASYM_FIBER ; + result |=ADVERTISE_1000XPSE_ASYM ;else if (linkmode_test_bit (ETHTOOL_LINK_MODE_Pause_BIT, advertise)) - result |= (ADVERTISE_PAUSE_FIBER - & (~ADVERTISE_PAUSE_ASYM_FIBER )); + result |=ADVERTISE_1000XPAUSE ;return result; }
@@ -549,8 +539,8 @@ static int marvell_config_aneg_fiber(struct phy_device *phydev)return adv; oldadv = adv; - adv &= ~(ADVERTISE_FIBER_1000HALF |ADVERTISE_FIBER_1000FULL - |LPA_PAUSE_FIBER ); + adv &= ~(ADVERTISE_1000XHALF |ADVERTISE_1000XFULL | +ADVERTISE_1000XPAUSE |ADVERTISE_1000XPSE_ASYM ); adv |=linkmode_adv_to_fiber_adv_t (phydev->advertising);if (adv != oldadv) {
@@ -1177,10 +1167,10 @@ static int m88e6390_config_aneg(struct phy_device *phydev)static void fiber_lpa_mod_linkmode_lpa_t (unsigned long *advertising,u32 lpa) {linkmode_mod_bit (ETHTOOL_LINK_MODE_1000baseT_Half_BIT, - advertising, lpa &LPA_FIBER_1000HALF ); + advertising, lpa &LPA_1000XHALF );linkmode_mod_bit (ETHTOOL_LINK_MODE_1000baseT_Full_BIT, - advertising, lpa &LPA_FIBER_1000FULL ); + advertising, lpa &LPA_1000XFULL ); } static int marvell_read_status_page_an(struct phy_device *phydev,
Signature · 1 line
2.20.1
Re: [PATCH net-next 09/11] net: phy: marvell: use existing clause 37 definitions
Quoted 4 lines · Russell King
Use existing clause 37 advertising/link partner definitions rather than private ones for the advertisement registers.
Signed-off-by Russell King <[email protected]>
Andrew
Re: [PATCH net-next 09/11] net: phy: marvell: use existing clause 37 definitions
In reply to Russell KingQuoted 4 lines · Russell King
Use existing clause 37 advertising/link partner definitions rather than private ones for the advertisement registers.
Signed-off-by Russell King <[email protected]>
Signature · 1 line
Florian
PATCH 10/11 net: phy: marvell: use phy_modify_changed()
In reply to Russell King - ARM Linux adminUse phy_modify_changed() to change the fiber advertisement register rather than open coding this functionality.
--- drivers/net/phy/marvell.c | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-)
drivers/net/phy/marvell.c +10 -16
@@ -524,7 +524,7 @@ static int marvell_config_aneg_fiber(struct phy_device *phydev) {int changed =0 ;int err; -int adv, oldadv; +u16 adv;if (phydev->autoneg !=AUTONEG_ENABLE )return genphy_setup_forced (phydev);
@@ -533,23 +533,17 @@ static int marvell_config_aneg_fiber(struct phy_device *phydev)linkmode_and (phydev->advertising, phydev->advertising, phydev->supported); -/* Setup fiber advertisement */ - adv =phy_read (phydev,MII_ADVERTISE ); -if (adv <0 ) -return adv; - - oldadv = adv; - adv &= ~(ADVERTISE_1000XHALF |ADVERTISE_1000XFULL | -ADVERTISE_1000XPAUSE |ADVERTISE_1000XPSE_ASYM ); - adv |=linkmode_adv_to_fiber_adv_t (phydev->advertising); - -if (adv != oldadv) { - err =phy_write (phydev,MII_ADVERTISE , adv); -if (err <0 ) -return err; + adv =linkmode_adv_to_fiber_adv_t (phydev->advertising); +/* Setup fiber advertisement */ + err =phy_modify_changed (phydev,MII_ADVERTISE , +ADVERTISE_1000XHALF |ADVERTISE_1000XFULL | +ADVERTISE_1000XPAUSE |ADVERTISE_1000XPSE_ASYM , + adv); +if (err <0 ) +return err; +if (err >0 ) changed =1 ; - }if (changed ==0 ) {/* Advertisement hasn't changed, but maybe aneg was never on to
Signature · 1 line
2.20.1
Re: [PATCH net-next 10/11] net: phy: marvell: use phy_modify_changed()
Quoted 4 lines · Russell King
Use
phy_modify_changed()to change the fiber advertisement register rather than open coding this functionality.Signed-off-by Russell King <[email protected]>
Andrew
Re: [PATCH net-next 10/11] net: phy: marvell: use phy_modify_changed()
In reply to Russell KingQuoted 4 lines · Russell King
Use
phy_modify_changed()to change the fiber advertisement register rather than open coding this functionality.Signed-off-by Russell King <[email protected]>
Signature · 1 line
Florian
PATCH 11/11 net: phy: marvell: use genphy_check_and_restart_aneg()
In reply to Russell King - ARM Linux adminUse the helper to check and restart autonegotiation for the marvell fiber page negotiation setting.
--- drivers/net/phy/marvell.c | 21 +-------------------- 1 file changed, 1 insertion(+), 20 deletions(-)
drivers/net/phy/marvell.c +1 -20
@@ -545,26 +545,7 @@ static int marvell_config_aneg_fiber(struct phy_device *phydev)if (err >0 ) changed =1 ; -if (changed ==0 ) { -/* Advertisement hasn't changed, but maybe aneg was never on to -* begin with? Or maybe phy was isolated? -*/ -int ctl =phy_read (phydev,MII_BMCR ); - -if (ctl <0 ) -return ctl; - -if (!(ctl &BMCR_ANENABLE ) || (ctl &BMCR_ISOLATE )) - changed =1 ;/* do restart aneg */ - } - -/* Only restart aneg if we are advertising something different -* than we were before. -*/ -if (changed >0 ) - changed =genphy_restart_aneg (phydev); - -return changed; +return genphy_check_and_restart_aneg (phydev, changed); }static int m88e1510_config_aneg (struct phy_device *phydev)
Signature · 1 line
2.20.1
Re: [PATCH net-next 11/11] net: phy: marvell: use genphy_check_and_restart_aneg()
Quoted 4 lines · Russell King
Use the helper to check and restart autonegotiation for the marvell fiber page negotiation setting.
Signed-off-by Russell King <[email protected]>
Andrew
Re: [PATCH net-next 11/11] net: phy: marvell: use genphy_check_and_restart_aneg()
In reply to Russell KingQuoted 4 lines · Russell King
Use the helper to check and restart autonegotiation for the marvell fiber page negotiation setting.
Signed-off-by Russell King <[email protected]>
Signature · 1 line
Florian
David Miller
maintainerFrom: Russell King - ARM Linux admin <[email protected]>
Date: Tue, 17 Dec 2019 13:38:27 +0000
Quoted 3 lines
Over the last few releases, there has been a push to clean up and consolidate the phylib code. Some cases have been missed, and this series catches those cases.
...
Series applied, thanks Russell.