2023-02-22 05:51:04

by Oleksij Rempel

[permalink] [raw]
Subject: [PATCH net v333 0/4] net: phy: EEE fixes

changes v3:
- add kernel test robot tags to commit log
- reword comment for genphy_c45_an_config_eee_aneg() function

changes v2:
- restore previous ethtool set logic for the case where advertisements
are not provided by user space.
- use ethtool_convert_legacy_u32_to_link_mode() where possible
- genphy_c45_an_config_eee_aneg(): move adv initialization in to the if
scope.

Different EEE related fixes.

Oleksij Rempel (4):
net: phy: c45: use "supported_eee" instead of supported for access
validation
net: phy: c45: add genphy_c45_an_config_eee_aneg() function
net: phy: do not force EEE support
net: phy: c45: genphy_c45_ethtool_set_eee: validate EEE link modes

drivers/net/phy/phy-c45.c | 54 ++++++++++++++++++++++++++++--------
drivers/net/phy/phy_device.c | 21 +++++++++++++-
include/linux/phy.h | 6 ++++
3 files changed, 68 insertions(+), 13 deletions(-)

--
2.30.2



2023-02-22 05:51:07

by Oleksij Rempel

[permalink] [raw]
Subject: [PATCH net v3 2/4] net: phy: c45: add genphy_c45_an_config_eee_aneg() function

Add new genphy_c45_an_config_eee_aneg() function and replace some of
genphy_c45_write_eee_adv() calls. This will be needed by the next patch.

Signed-off-by: Oleksij Rempel <[email protected]>
Reviewed-by: Russell King (Oracle) <[email protected]>
---
drivers/net/phy/phy-c45.c | 11 ++++++++++-
drivers/net/phy/phy_device.c | 2 +-
include/linux/phy.h | 1 +
3 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/drivers/net/phy/phy-c45.c b/drivers/net/phy/phy-c45.c
index f23cce2c5199..784868e818a7 100644
--- a/drivers/net/phy/phy-c45.c
+++ b/drivers/net/phy/phy-c45.c
@@ -262,7 +262,7 @@ int genphy_c45_an_config_aneg(struct phy_device *phydev)
linkmode_and(phydev->advertising, phydev->advertising,
phydev->supported);

- ret = genphy_c45_write_eee_adv(phydev, phydev->supported_eee);
+ ret = genphy_c45_an_config_eee_aneg(phydev);
if (ret < 0)
return ret;
else if (ret)
@@ -858,6 +858,15 @@ int genphy_c45_read_eee_abilities(struct phy_device *phydev)
}
EXPORT_SYMBOL_GPL(genphy_c45_read_eee_abilities);

+/**
+ * genphy_c45_an_config_eee_aneg - configure EEE advertisement
+ * @phydev: target phy_device struct
+ */
+int genphy_c45_an_config_eee_aneg(struct phy_device *phydev)
+{
+ return genphy_c45_write_eee_adv(phydev, phydev->supported_eee);
+}
+
/**
* genphy_c45_pma_read_abilities - read supported link modes from PMA
* @phydev: target phy_device struct
diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
index 71becceb8764..570a5803f9c2 100644
--- a/drivers/net/phy/phy_device.c
+++ b/drivers/net/phy/phy_device.c
@@ -2231,7 +2231,7 @@ int __genphy_config_aneg(struct phy_device *phydev, bool changed)
{
int err;

- err = genphy_c45_write_eee_adv(phydev, phydev->supported_eee);
+ err = genphy_c45_an_config_eee_aneg(phydev);
if (err < 0)
return err;
else if (err)
diff --git a/include/linux/phy.h b/include/linux/phy.h
index 727bff531a14..19d83e112beb 100644
--- a/include/linux/phy.h
+++ b/include/linux/phy.h
@@ -1765,6 +1765,7 @@ int genphy_c45_ethtool_get_eee(struct phy_device *phydev,
int genphy_c45_ethtool_set_eee(struct phy_device *phydev,
struct ethtool_eee *data);
int genphy_c45_write_eee_adv(struct phy_device *phydev, unsigned long *adv);
+int genphy_c45_an_config_eee_aneg(struct phy_device *phydev);

/* Generic C45 PHY driver */
extern struct phy_driver genphy_c45_driver;
--
2.30.2


2023-02-22 05:51:10

by Oleksij Rempel

[permalink] [raw]
Subject: [PATCH net v3 3/4] net: phy: do not force EEE support

With following patches:
commit 9b01c885be36 ("net: phy: c22: migrate to genphy_c45_write_eee_adv()")
commit 5827b168125d ("net: phy: c45: migrate to genphy_c45_write_eee_adv()")

we set the advertisement to potentially supported values. This behavior
may introduce new regressions on systems where EEE was disabled by
default (BIOS or boot loader configuration or by other ways.)

At same time, with this patches, we would overwrite EEE advertisement
configuration made over ethtool.

To avoid this issues, we need to cache initial and ethtool advertisement
configuration and store it for later use.

Fixes: 9b01c885be36 ("net: phy: c22: migrate to genphy_c45_write_eee_adv()")
Fixes: 5827b168125d ("net: phy: c45: migrate to genphy_c45_write_eee_adv()")
Fixes: 022c3f87f88e ("net: phy: add genphy_c45_ethtool_get/set_eee() support")
Signed-off-by: Oleksij Rempel <[email protected]>
---
drivers/net/phy/phy-c45.c | 24 +++++++++++++++++-------
drivers/net/phy/phy_device.c | 19 +++++++++++++++++++
include/linux/phy.h | 5 +++++
3 files changed, 41 insertions(+), 7 deletions(-)

diff --git a/drivers/net/phy/phy-c45.c b/drivers/net/phy/phy-c45.c
index 784868e818a7..8717c122e2f3 100644
--- a/drivers/net/phy/phy-c45.c
+++ b/drivers/net/phy/phy-c45.c
@@ -721,8 +721,7 @@ int genphy_c45_write_eee_adv(struct phy_device *phydev, unsigned long *adv)
* @phydev: target phy_device struct
* @adv: the linkmode advertisement status
*/
-static int genphy_c45_read_eee_adv(struct phy_device *phydev,
- unsigned long *adv)
+int genphy_c45_read_eee_adv(struct phy_device *phydev, unsigned long *adv)
{
int val;

@@ -864,7 +863,13 @@ EXPORT_SYMBOL_GPL(genphy_c45_read_eee_abilities);
*/
int genphy_c45_an_config_eee_aneg(struct phy_device *phydev)
{
- return genphy_c45_write_eee_adv(phydev, phydev->supported_eee);
+ if (!phydev->eee_enabled) {
+ __ETHTOOL_DECLARE_LINK_MODE_MASK(adv) = {};
+
+ return genphy_c45_write_eee_adv(phydev, adv);
+ }
+
+ return genphy_c45_write_eee_adv(phydev, phydev->advertising_eee);
}

/**
@@ -1430,17 +1435,22 @@ EXPORT_SYMBOL(genphy_c45_ethtool_get_eee);
int genphy_c45_ethtool_set_eee(struct phy_device *phydev,
struct ethtool_eee *data)
{
- __ETHTOOL_DECLARE_LINK_MODE_MASK(adv) = {};
int ret;

if (data->eee_enabled) {
if (data->advertised)
- adv[0] = data->advertised;
+ ethtool_convert_legacy_u32_to_link_mode(phydev->advertising_eee,
+ data->advertised);
else
- linkmode_copy(adv, phydev->supported_eee);
+ linkmode_copy(phydev->advertising_eee,
+ phydev->supported_eee);
+
+ phydev->eee_enabled = true;
+ } else {
+ phydev->eee_enabled = false;
}

- ret = genphy_c45_write_eee_adv(phydev, adv);
+ ret = genphy_c45_an_config_eee_aneg(phydev);
if (ret < 0)
return ret;
if (ret > 0)
diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
index 570a5803f9c2..3f8a64fb9d71 100644
--- a/drivers/net/phy/phy_device.c
+++ b/drivers/net/phy/phy_device.c
@@ -3141,6 +3141,25 @@ static int phy_probe(struct device *dev)
of_set_phy_supported(phydev);
phy_advertise_supported(phydev);

+ /* Get PHY default EEE advertising modes and handle them as potentially
+ * safe initial configuration.
+ */
+ err = genphy_c45_read_eee_adv(phydev, phydev->advertising_eee);
+ if (err)
+ return err;
+
+ /* There is no "enabled" flag. If PHY is advertising, assume it is
+ * kind of enabled.
+ */
+ phydev->eee_enabled = !linkmode_empty(phydev->advertising_eee);
+
+ /* Some PHYs may advertise, by default, not support EEE modes. So,
+ * we need to clean them.
+ */
+ if (phydev->eee_enabled)
+ linkmode_and(phydev->advertising_eee, phydev->supported_eee,
+ phydev->advertising_eee);
+
/* Get the EEE modes we want to prohibit. We will ask
* the PHY stop advertising these mode later on
*/
diff --git a/include/linux/phy.h b/include/linux/phy.h
index 19d83e112beb..36bf0bbc8efa 100644
--- a/include/linux/phy.h
+++ b/include/linux/phy.h
@@ -575,6 +575,8 @@ struct macsec_ops;
* @advertising: Currently advertised linkmodes
* @adv_old: Saved advertised while power saving for WoL
* @supported_eee: supported PHY EEE linkmodes
+ * @advertising_eee: Currently advertised EEE linkmodes
+ * @eee_enabled: Flag indicating whether the EEE feature is enabled
* @lp_advertising: Current link partner advertised linkmodes
* @host_interfaces: PHY interface modes supported by host
* @eee_broken_modes: Energy efficient ethernet modes which should be prohibited
@@ -681,6 +683,8 @@ struct phy_device {
__ETHTOOL_DECLARE_LINK_MODE_MASK(adv_old);
/* used for eee validation */
__ETHTOOL_DECLARE_LINK_MODE_MASK(supported_eee);
+ __ETHTOOL_DECLARE_LINK_MODE_MASK(advertising_eee);
+ bool eee_enabled;

/* Host supported PHY interface types. Should be ignored if empty. */
DECLARE_PHY_INTERFACE_MASK(host_interfaces);
@@ -1766,6 +1770,7 @@ int genphy_c45_ethtool_set_eee(struct phy_device *phydev,
struct ethtool_eee *data);
int genphy_c45_write_eee_adv(struct phy_device *phydev, unsigned long *adv);
int genphy_c45_an_config_eee_aneg(struct phy_device *phydev);
+int genphy_c45_read_eee_adv(struct phy_device *phydev, unsigned long *adv);

/* Generic C45 PHY driver */
extern struct phy_driver genphy_c45_driver;
--
2.30.2


2023-02-22 05:51:12

by Oleksij Rempel

[permalink] [raw]
Subject: [PATCH net v3 1/4] net: phy: c45: use "supported_eee" instead of supported for access validation

Make sure we use proper variable to validate access to potentially not
supported registers. Otherwise we will get false read/write errors.

Reported-by: kernel test robot <[email protected]>
Link: https://lore.kernel.org/oe-lkp/[email protected]
Fixes: 022c3f87f88e ("net: phy: add genphy_c45_ethtool_get/set_eee() support")
Signed-off-by: Oleksij Rempel <[email protected]>
Reviewed-by: Russell King (Oracle) <[email protected]>
---
drivers/net/phy/phy-c45.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/net/phy/phy-c45.c b/drivers/net/phy/phy-c45.c
index f9b128cecc3f..f23cce2c5199 100644
--- a/drivers/net/phy/phy-c45.c
+++ b/drivers/net/phy/phy-c45.c
@@ -674,7 +674,7 @@ int genphy_c45_write_eee_adv(struct phy_device *phydev, unsigned long *adv)
{
int val, changed;

- if (linkmode_intersects(phydev->supported, PHY_EEE_CAP1_FEATURES)) {
+ if (linkmode_intersects(phydev->supported_eee, PHY_EEE_CAP1_FEATURES)) {
val = linkmode_to_mii_eee_cap1_t(adv);

/* In eee_broken_modes are stored MDIO_AN_EEE_ADV specific raw
@@ -726,7 +726,7 @@ static int genphy_c45_read_eee_adv(struct phy_device *phydev,
{
int val;

- if (linkmode_intersects(phydev->supported, PHY_EEE_CAP1_FEATURES)) {
+ if (linkmode_intersects(phydev->supported_eee, PHY_EEE_CAP1_FEATURES)) {
/* IEEE 802.3-2018 45.2.7.13 EEE advertisement 1
* (Register 7.60)
*/
@@ -762,7 +762,7 @@ static int genphy_c45_read_eee_lpa(struct phy_device *phydev,
{
int val;

- if (linkmode_intersects(phydev->supported, PHY_EEE_CAP1_FEATURES)) {
+ if (linkmode_intersects(phydev->supported_eee, PHY_EEE_CAP1_FEATURES)) {
/* IEEE 802.3-2018 45.2.7.14 EEE link partner ability 1
* (Register 7.61)
*/
--
2.30.2


2023-02-23 09:24:16

by Paolo Abeni

[permalink] [raw]
Subject: Re: [PATCH net v333 0/4] net: phy: EEE fixes

Hi,

On Wed, 2023-02-22 at 06:50 +0100, Oleksij Rempel wrote:
> changes v3:
> - add kernel test robot tags to commit log
> - reword comment for genphy_c45_an_config_eee_aneg() function
>
> changes v2:
> - restore previous ethtool set logic for the case where advertisements
> are not provided by user space.
> - use ethtool_convert_legacy_u32_to_link_mode() where possible
> - genphy_c45_an_config_eee_aneg(): move adv initialization in to the if
> scope.
>
> Different EEE related fixes.
>
> Oleksij Rempel (4):
> net: phy: c45: use "supported_eee" instead of supported for access
> validation
> net: phy: c45: add genphy_c45_an_config_eee_aneg() function
> net: phy: do not force EEE support
> net: phy: c45: genphy_c45_ethtool_set_eee: validate EEE link modes
>
> drivers/net/phy/phy-c45.c | 54 ++++++++++++++++++++++++++++--------
> drivers/net/phy/phy_device.c | 21 +++++++++++++-
> include/linux/phy.h | 6 ++++
> 3 files changed, 68 insertions(+), 13 deletions(-)
>
@Russel: I read your last reply to the v2 series as an ack here, am I
correct?

Thanks!

Paolo


2023-02-23 09:55:45

by Russell King (Oracle)

[permalink] [raw]
Subject: Re: [PATCH net v3 3/4] net: phy: do not force EEE support

On Wed, Feb 22, 2023 at 06:50:42AM +0100, Oleksij Rempel wrote:
> With following patches:
> commit 9b01c885be36 ("net: phy: c22: migrate to genphy_c45_write_eee_adv()")
> commit 5827b168125d ("net: phy: c45: migrate to genphy_c45_write_eee_adv()")
>
> we set the advertisement to potentially supported values. This behavior
> may introduce new regressions on systems where EEE was disabled by
> default (BIOS or boot loader configuration or by other ways.)
>
> At same time, with this patches, we would overwrite EEE advertisement
> configuration made over ethtool.
>
> To avoid this issues, we need to cache initial and ethtool advertisement
> configuration and store it for later use.
>
> Fixes: 9b01c885be36 ("net: phy: c22: migrate to genphy_c45_write_eee_adv()")
> Fixes: 5827b168125d ("net: phy: c45: migrate to genphy_c45_write_eee_adv()")
> Fixes: 022c3f87f88e ("net: phy: add genphy_c45_ethtool_get/set_eee() support")
> Signed-off-by: Oleksij Rempel <[email protected]>

Reviewed-by: Russell King (Oracle) <[email protected]>

Thanks!

--
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 40Mbps down 10Mbps up. Decent connectivity at last!

2023-02-23 09:56:57

by Russell King (Oracle)

[permalink] [raw]
Subject: Re: [PATCH net v333 0/4] net: phy: EEE fixes

On Thu, Feb 23, 2023 at 10:23:20AM +0100, Paolo Abeni wrote:
> Hi,
>
> On Wed, 2023-02-22 at 06:50 +0100, Oleksij Rempel wrote:
> > changes v3:
> > - add kernel test robot tags to commit log
> > - reword comment for genphy_c45_an_config_eee_aneg() function
> >
> > changes v2:
> > - restore previous ethtool set logic for the case where advertisements
> > are not provided by user space.
> > - use ethtool_convert_legacy_u32_to_link_mode() where possible
> > - genphy_c45_an_config_eee_aneg(): move adv initialization in to the if
> > scope.
> >
> > Different EEE related fixes.
> >
> > Oleksij Rempel (4):
> > net: phy: c45: use "supported_eee" instead of supported for access
> > validation
> > net: phy: c45: add genphy_c45_an_config_eee_aneg() function
> > net: phy: do not force EEE support
> > net: phy: c45: genphy_c45_ethtool_set_eee: validate EEE link modes
> >
> > drivers/net/phy/phy-c45.c | 54 ++++++++++++++++++++++++++++--------
> > drivers/net/phy/phy_device.c | 21 +++++++++++++-
> > include/linux/phy.h | 6 ++++
> > 3 files changed, 68 insertions(+), 13 deletions(-)
> >
> @Russel: I read your last reply to the v2 series as an ack here, am I
> correct?

Yes - I've just given two r-b's as well for the last two patches.
Thanks.

--
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 40Mbps down 10Mbps up. Decent connectivity at last!

2023-02-23 12:50:48

by patchwork-bot+netdevbpf

[permalink] [raw]
Subject: Re: [PATCH net v333 0/4] net: phy: EEE fixes

Hello:

This series was applied to netdev/net.git (master)
by Paolo Abeni <[email protected]>:

On Wed, 22 Feb 2023 06:50:39 +0100 you wrote:
> changes v3:
> - add kernel test robot tags to commit log
> - reword comment for genphy_c45_an_config_eee_aneg() function
>
> changes v2:
> - restore previous ethtool set logic for the case where advertisements
> are not provided by user space.
> - use ethtool_convert_legacy_u32_to_link_mode() where possible
> - genphy_c45_an_config_eee_aneg(): move adv initialization in to the if
> scope.
>
> [...]

Here is the summary with links:
- [net,v3,1/4] net: phy: c45: use "supported_eee" instead of supported for access validation
https://git.kernel.org/netdev/net/c/e209519b6233
- [net,v3,2/4] net: phy: c45: add genphy_c45_an_config_eee_aneg() function
https://git.kernel.org/netdev/net/c/b6478b8c9330
- [net,v3,3/4] net: phy: do not force EEE support
https://git.kernel.org/netdev/net/c/3eeca4e199ce
- [net,v3,4/4] net: phy: c45: genphy_c45_ethtool_set_eee: validate EEE link modes
https://git.kernel.org/netdev/net/c/186b1da76b72

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html