kernel: backport phylink changes from mainline Linux
[openwrt/staging/stintel.git] / target / linux / generic / backport-6.1 / 715-23-v6.4-net-phylink-actually-fix-ksettings_set-ethtool-call.patch
1 From 11933aa76865621d8e82553c8f3bc07796a5aaa2 Mon Sep 17 00:00:00 2001
2 From: "Russell King (Oracle)" <rmk+kernel@armlinux.org.uk>
3 Date: Thu, 1 Jun 2023 10:12:06 +0100
4 Subject: [PATCH 20/21] net: phylink: actually fix ksettings_set() ethtool call
5
6 Raju Lakkaraju reported that the below commit caused a regression
7 with Lan743x drivers and a 2.5G SFP. Sadly, this is because the commit
8 was utterly wrong. Let's fix this properly by not moving the
9 linkmode_and(), but instead copying the link ksettings and then
10 modifying the advertising mask before passing the modified link
11 ksettings to phylib.
12
13 Fixes: df0acdc59b09 ("net: phylink: fix ksettings_set() ethtool call")
14 Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
15 Link: https://lore.kernel.org/r/E1q4eLm-00Ayxk-GZ@rmk-PC.armlinux.org.uk
16 Signed-off-by: Jakub Kicinski <kuba@kernel.org>
17 ---
18 drivers/net/phy/phylink.c | 15 ++++++++++-----
19 1 file changed, 10 insertions(+), 5 deletions(-)
20
21 --- a/drivers/net/phy/phylink.c
22 +++ b/drivers/net/phy/phylink.c
23 @@ -2259,11 +2259,13 @@ int phylink_ethtool_ksettings_set(struct
24
25 ASSERT_RTNL();
26
27 - /* Mask out unsupported advertisements */
28 - linkmode_and(config.advertising, kset->link_modes.advertising,
29 - pl->supported);
30 -
31 if (pl->phydev) {
32 + struct ethtool_link_ksettings phy_kset = *kset;
33 +
34 + linkmode_and(phy_kset.link_modes.advertising,
35 + phy_kset.link_modes.advertising,
36 + pl->supported);
37 +
38 /* We can rely on phylib for this update; we also do not need
39 * to update the pl->link_config settings:
40 * - the configuration returned via ksettings_get() will come
41 @@ -2282,10 +2284,13 @@ int phylink_ethtool_ksettings_set(struct
42 * the presence of a PHY, this should not be changed as that
43 * should be determined from the media side advertisement.
44 */
45 - return phy_ethtool_ksettings_set(pl->phydev, kset);
46 + return phy_ethtool_ksettings_set(pl->phydev, &phy_kset);
47 }
48
49 config = pl->link_config;
50 + /* Mask out unsupported advertisements */
51 + linkmode_and(config.advertising, kset->link_modes.advertising,
52 + pl->supported);
53
54 /* FIXME: should we reject autoneg if phy/mac does not support it? */
55 switch (kset->base.autoneg) {