acaa4a644ee419823684c7e2e9a893e2ae045f60
[openwrt/staging/981213.git] /
1 From 9b1d5e055508393561e26bd1720f4c2639b03b1a Mon Sep 17 00:00:00 2001
2 From: Christian Marangi <ansuelsmth@gmail.com>
3 Date: Tue, 6 Feb 2024 18:31:09 +0100
4 Subject: [PATCH 06/10] net: phy: provide whether link has changed in
5 c37_read_status
6
7 Some PHY driver might require additional regs call after
8 genphy_c37_read_status() is called.
9
10 Expand genphy_c37_read_status to provide a bool wheather the link has
11 changed or not to permit PHY driver to skip additional regs call if
12 nothing has changed.
13
14 Every user of genphy_c37_read_status() is updated with the new
15 additional bool.
16
17 Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
18 Reviewed-by: Andrew Lunn <andrew@lunn.ch>
19 Signed-off-by: David S. Miller <davem@davemloft.net>
20 ---
21 drivers/net/phy/broadcom.c | 3 ++-
22 drivers/net/phy/phy_device.c | 11 +++++++++--
23 drivers/net/phy/qcom/at803x.c | 3 ++-
24 include/linux/phy.h | 2 +-
25 4 files changed, 14 insertions(+), 5 deletions(-)
26
27 --- a/drivers/net/phy/broadcom.c
28 +++ b/drivers/net/phy/broadcom.c
29 @@ -609,10 +609,11 @@ static int bcm54616s_config_aneg(struct
30 static int bcm54616s_read_status(struct phy_device *phydev)
31 {
32 struct bcm54616s_phy_priv *priv = phydev->priv;
33 + bool changed;
34 int err;
35
36 if (priv->mode_1000bx_en)
37 - err = genphy_c37_read_status(phydev);
38 + err = genphy_c37_read_status(phydev, &changed);
39 else
40 err = genphy_read_status(phydev);
41
42 --- a/drivers/net/phy/phy_device.c
43 +++ b/drivers/net/phy/phy_device.c
44 @@ -2549,12 +2549,15 @@ EXPORT_SYMBOL(genphy_read_status);
45 /**
46 * genphy_c37_read_status - check the link status and update current link state
47 * @phydev: target phy_device struct
48 + * @changed: pointer where to store if link changed
49 *
50 * Description: Check the link, then figure out the current state
51 * by comparing what we advertise with what the link partner
52 * advertises. This function is for Clause 37 1000Base-X mode.
53 + *
54 + * If link has changed, @changed is set to true, false otherwise.
55 */
56 -int genphy_c37_read_status(struct phy_device *phydev)
57 +int genphy_c37_read_status(struct phy_device *phydev, bool *changed)
58 {
59 int lpa, err, old_link = phydev->link;
60
61 @@ -2564,9 +2567,13 @@ int genphy_c37_read_status(struct phy_de
62 return err;
63
64 /* why bother the PHY if nothing can have changed */
65 - if (phydev->autoneg == AUTONEG_ENABLE && old_link && phydev->link)
66 + if (phydev->autoneg == AUTONEG_ENABLE && old_link && phydev->link) {
67 + *changed = false;
68 return 0;
69 + }
70
71 + /* Signal link has changed */
72 + *changed = true;
73 phydev->duplex = DUPLEX_UNKNOWN;
74 phydev->pause = 0;
75 phydev->asym_pause = 0;
76 --- a/drivers/net/phy/qcom/at803x.c
77 +++ b/drivers/net/phy/qcom/at803x.c
78 @@ -912,9 +912,10 @@ static int at8031_config_intr(struct phy
79 static int at8031_read_status(struct phy_device *phydev)
80 {
81 struct at803x_priv *priv = phydev->priv;
82 + bool changed;
83
84 if (priv->is_1000basex)
85 - return genphy_c37_read_status(phydev);
86 + return genphy_c37_read_status(phydev, &changed);
87
88 return at803x_read_status(phydev);
89 }
90 --- a/include/linux/phy.h
91 +++ b/include/linux/phy.h
92 @@ -1688,7 +1688,7 @@ int genphy_write_mmd_unsupported(struct
93
94 /* Clause 37 */
95 int genphy_c37_config_aneg(struct phy_device *phydev);
96 -int genphy_c37_read_status(struct phy_device *phydev);
97 +int genphy_c37_read_status(struct phy_device *phydev, bool *changed);
98
99 /* Clause 45 PHY */
100 int genphy_c45_restart_aneg(struct phy_device *phydev);