diff mbox series

[RESUBMIT,net-next] r8169: simplify EEE handling

Message ID 27c336a8-ea47-483d-815b-02c45ae41da2@gmail.com (mailing list archive)
State Accepted
Commit f5d59230ec26aa5e8b59e9f4a4d288703a737479
Delegated to: Netdev Maintainers
Headers show
Series [RESUBMIT,net-next] r8169: simplify EEE handling | expand

Checks

Context Check Description
netdev/series_format success Single patches do not need cover letters
netdev/tree_selection success Clearly marked for net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 1048 this patch: 1048
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers success CCed 0 of 0 maintainers
netdev/build_clang success Errors and warnings before: 1065 this patch: 1065
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 1065 this patch: 1065
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 72 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/contest success net-next-2024-02-02--15-00 (tests: 720)

Commit Message

Heiner Kallweit Jan. 31, 2024, 8:31 p.m. UTC
We don't have to store the EEE modes to be advertised in the driver,
phylib does this for us and stores it in phydev->advertising_eee.
phylib also takes care of properly handling the EEE advertisement.

Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
---
 drivers/net/ethernet/realtek/r8169_main.c | 32 +++--------------------
 1 file changed, 4 insertions(+), 28 deletions(-)

Comments

Andrew Lunn Feb. 2, 2024, 12:16 a.m. UTC | #1
> @@ -5058,7 +5033,9 @@ static int r8169_mdio_register(struct rtl8169_private *tp)
>  	}
>  
>  	tp->phydev->mac_managed_pm = true;
> -
> +	if (rtl_supports_eee(tp))
> +		linkmode_copy(tp->phydev->advertising_eee,
> +			      tp->phydev->supported_eee);

This looks odd. Does it mean something is missing on phylib?

	Andrew
Heiner Kallweit Feb. 2, 2024, 6:55 a.m. UTC | #2
On 02.02.2024 01:16, Andrew Lunn wrote:
>> @@ -5058,7 +5033,9 @@ static int r8169_mdio_register(struct rtl8169_private *tp)
>>  	}
>>  
>>  	tp->phydev->mac_managed_pm = true;
>> -
>> +	if (rtl_supports_eee(tp))
>> +		linkmode_copy(tp->phydev->advertising_eee,
>> +			      tp->phydev->supported_eee);
> 
> This looks odd. Does it mean something is missing on phylib?
> 
Reason is that we treat "normal" advertising and EEE advertising differently
in phylib. See this code snippet from phy_probe().

        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);

For EEE we don't change the initial advertising to what's supported,
but preserve the EEE advertising at the time of phy probing.
So if I want to mimic the behavior of phy_advertise_supported() for EEE,
I have to populate advertising_eee in the driver.

Alternative would be to change phy_advertise_supported(), but this may
impact systems with PHY's with EEE flaws.

> 	Andrew
Heiner
Andrew Lunn Feb. 2, 2024, 1:12 p.m. UTC | #3
On Fri, Feb 02, 2024 at 07:55:38AM +0100, Heiner Kallweit wrote:
> On 02.02.2024 01:16, Andrew Lunn wrote:
> >> @@ -5058,7 +5033,9 @@ static int r8169_mdio_register(struct rtl8169_private *tp)
> >>  	}
> >>  
> >>  	tp->phydev->mac_managed_pm = true;
> >> -
> >> +	if (rtl_supports_eee(tp))
> >> +		linkmode_copy(tp->phydev->advertising_eee,
> >> +			      tp->phydev->supported_eee);
> > 
> > This looks odd. Does it mean something is missing on phylib?
> > 
> Reason is that we treat "normal" advertising and EEE advertising differently
> in phylib. See this code snippet from phy_probe().
> 
>         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);
> 
> For EEE we don't change the initial advertising to what's supported,
> but preserve the EEE advertising at the time of phy probing.
> So if I want to mimic the behavior of phy_advertise_supported() for EEE,
> I have to populate advertising_eee in the driver.

So the device you are using is advertising less than what it supports?

> Alternative would be to change phy_advertise_supported(), but this may
> impact systems with PHY's with EEE flaws.

If i remember correctly, there was some worry enabling EEE by default
could upset some low latency use cases, PTP accuracy etc. So lets
leave it as it is. Maybe a helper would be useful
phy_advertise_eee_all() with a comment about why it could be used.

	Andrew
Heiner Kallweit Feb. 2, 2024, 4:06 p.m. UTC | #4
On 02.02.2024 14:12, Andrew Lunn wrote:
> On Fri, Feb 02, 2024 at 07:55:38AM +0100, Heiner Kallweit wrote:
>> On 02.02.2024 01:16, Andrew Lunn wrote:
>>>> @@ -5058,7 +5033,9 @@ static int r8169_mdio_register(struct rtl8169_private *tp)
>>>>  	}
>>>>  
>>>>  	tp->phydev->mac_managed_pm = true;
>>>> -
>>>> +	if (rtl_supports_eee(tp))
>>>> +		linkmode_copy(tp->phydev->advertising_eee,
>>>> +			      tp->phydev->supported_eee);
>>>
>>> This looks odd. Does it mean something is missing on phylib?
>>>
>> Reason is that we treat "normal" advertising and EEE advertising differently
>> in phylib. See this code snippet from phy_probe().
>>
>>         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);
>>
>> For EEE we don't change the initial advertising to what's supported,
>> but preserve the EEE advertising at the time of phy probing.
>> So if I want to mimic the behavior of phy_advertise_supported() for EEE,
>> I have to populate advertising_eee in the driver.
> 
> So the device you are using is advertising less than what it supports?
> 
It may. If on a board with this chip version the BIOS for whatever reason
disabled EEE advertising, then users may complain that their system consumes
more power with r8169 than with r8125. Typical users don't necessarily
know that EEE exists and what it is, and how to enable it with ethtool.
Therefore I'd like to ensure that the supported EEE modes are also advertised.

>> Alternative would be to change phy_advertise_supported(), but this may
>> impact systems with PHY's with EEE flaws.
> 
> If i remember correctly, there was some worry enabling EEE by default
> could upset some low latency use cases, PTP accuracy etc. So lets
> leave it as it is. Maybe a helper would be useful
> phy_advertise_eee_all() with a comment about why it could be used.
> 
Yes, I think that's the way to go.
To minimize efforts I'd like to keep this patch here as it is, then I'll
add the helper and change this place in r8169 to use the new helper.

> 	Andrew
Heiner
Jakub Kicinski Feb. 2, 2024, 4:15 p.m. UTC | #5
On Fri, 2 Feb 2024 17:06:10 +0100 Heiner Kallweit wrote:
> >> Alternative would be to change phy_advertise_supported(), but this may
> >> impact systems with PHY's with EEE flaws.  
> > 
> > If i remember correctly, there was some worry enabling EEE by default
> > could upset some low latency use cases, PTP accuracy etc. So lets
> > leave it as it is. Maybe a helper would be useful
> > phy_advertise_eee_all() with a comment about why it could be used.
> >   
> Yes, I think that's the way to go.
> To minimize efforts I'd like to keep this patch here as it is, then I'll
> add the helper and change this place in r8169 to use the new helper.

Sorry for being slow - on top or as v2? :)
Heiner Kallweit Feb. 2, 2024, 8:36 p.m. UTC | #6
On 02.02.2024 17:15, Jakub Kicinski wrote:
> On Fri, 2 Feb 2024 17:06:10 +0100 Heiner Kallweit wrote:
>>>> Alternative would be to change phy_advertise_supported(), but this may
>>>> impact systems with PHY's with EEE flaws.  
>>>
>>> If i remember correctly, there was some worry enabling EEE by default
>>> could upset some low latency use cases, PTP accuracy etc. So lets
>>> leave it as it is. Maybe a helper would be useful
>>> phy_advertise_eee_all() with a comment about why it could be used.
>>>   
>> Yes, I think that's the way to go.
>> To minimize efforts I'd like to keep this patch here as it is, then I'll
>> add the helper and change this place in r8169 to use the new helper.
> 
> Sorry for being slow - on top or as v2? :)

I'll do it on top.
patchwork-bot+netdevbpf@kernel.org Feb. 3, 2024, 5:10 a.m. UTC | #7
Hello:

This patch was applied to netdev/net-next.git (main)
by Jakub Kicinski <kuba@kernel.org>:

On Wed, 31 Jan 2024 21:31:01 +0100 you wrote:
> We don't have to store the EEE modes to be advertised in the driver,
> phylib does this for us and stores it in phydev->advertising_eee.
> phylib also takes care of properly handling the EEE advertisement.
> 
> Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
> ---
>  drivers/net/ethernet/realtek/r8169_main.c | 32 +++--------------------
>  1 file changed, 4 insertions(+), 28 deletions(-)

Here is the summary with links:
  - [RESUBMIT,net-next] r8169: simplify EEE handling
    https://git.kernel.org/netdev/net-next/c/f5d59230ec26

You are awesome, thank you!
diff mbox series

Patch

diff --git a/drivers/net/ethernet/realtek/r8169_main.c b/drivers/net/ethernet/realtek/r8169_main.c
index 3d30d4499..e0abdbcfa 100644
--- a/drivers/net/ethernet/realtek/r8169_main.c
+++ b/drivers/net/ethernet/realtek/r8169_main.c
@@ -629,7 +629,6 @@  struct rtl8169_private {
 	struct rtl8169_counters *counters;
 	struct rtl8169_tc_offsets tc_offset;
 	u32 saved_wolopts;
-	int eee_adv;
 
 	const char *fw_name;
 	struct rtl_fw *rtl_fw;
@@ -1987,17 +1986,11 @@  static int rtl8169_get_eee(struct net_device *dev, struct ethtool_keee *data)
 static int rtl8169_set_eee(struct net_device *dev, struct ethtool_keee *data)
 {
 	struct rtl8169_private *tp = netdev_priv(dev);
-	int ret;
 
 	if (!rtl_supports_eee(tp))
 		return -EOPNOTSUPP;
 
-	ret = phy_ethtool_set_eee(tp->phydev, data);
-
-	if (!ret)
-		tp->eee_adv = phy_read_mmd(dev->phydev, MDIO_MMD_AN,
-					   MDIO_AN_EEE_ADV);
-	return ret;
+	return phy_ethtool_set_eee(tp->phydev, data);
 }
 
 static void rtl8169_get_ringparam(struct net_device *dev,
@@ -2062,21 +2055,6 @@  static const struct ethtool_ops rtl8169_ethtool_ops = {
 	.set_pauseparam		= rtl8169_set_pauseparam,
 };
 
-static void rtl_enable_eee(struct rtl8169_private *tp)
-{
-	struct phy_device *phydev = tp->phydev;
-	int adv;
-
-	/* respect EEE advertisement the user may have set */
-	if (tp->eee_adv >= 0)
-		adv = tp->eee_adv;
-	else
-		adv = phy_read_mmd(phydev, MDIO_MMD_PCS, MDIO_PCS_EEE_ABLE);
-
-	if (adv >= 0)
-		phy_write_mmd(phydev, MDIO_MMD_AN, MDIO_AN_EEE_ADV, adv);
-}
-
 static enum mac_version rtl8169_get_mac_version(u16 xid, bool gmii)
 {
 	/*
@@ -2313,9 +2291,6 @@  static void rtl8169_init_phy(struct rtl8169_private *tp)
 	/* We may have called phy_speed_down before */
 	phy_speed_up(tp->phydev);
 
-	if (rtl_supports_eee(tp))
-		rtl_enable_eee(tp);
-
 	genphy_soft_reset(tp->phydev);
 }
 
@@ -5058,7 +5033,9 @@  static int r8169_mdio_register(struct rtl8169_private *tp)
 	}
 
 	tp->phydev->mac_managed_pm = true;
-
+	if (rtl_supports_eee(tp))
+		linkmode_copy(tp->phydev->advertising_eee,
+			      tp->phydev->supported_eee);
 	phy_support_asym_pause(tp->phydev);
 
 	/* PHY will be woken up in rtl_open() */
@@ -5193,7 +5170,6 @@  static int rtl_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 	tp->dev = dev;
 	tp->pci_dev = pdev;
 	tp->supports_gmii = ent->driver_data == RTL_CFG_NO_GBIT ? 0 : 1;
-	tp->eee_adv = -1;
 	tp->ocp_base = OCP_STD_PHY_BASE;
 
 	raw_spin_lock_init(&tp->cfg9346_usage_lock);