6d47fa9634375da7d86ae10772d37d768985eea1
[openwrt/openwrt.git] / target / linux / generic / backport-5.4 / 707-v5.1-net-phy-add-genphy_c45_check_and_restart_aneg.patch
1 From 2c3db705737cf52d7d24c993f0889b25b956c718 Mon Sep 17 00:00:00 2001
2 From: Heiner Kallweit <hkallweit1@gmail.com>
3 Date: Mon, 18 Feb 2019 21:27:18 +0100
4 Subject: [PATCH 605/660] net: phy: add genphy_c45_check_and_restart_aneg
5
6 This function will be used by config_aneg callback implementations of
7 PHY drivers and allows to reduce boilerplate code.
8
9 Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
10 Signed-off-by: David S. Miller <davem@davemloft.net>
11 ---
12 drivers/net/phy/phy-c45.c | 30 ++++++++++++++++++++++++++++++
13 include/linux/phy.h | 1 +
14 2 files changed, 31 insertions(+)
15
16 --- a/drivers/net/phy/phy-c45.c
17 +++ b/drivers/net/phy/phy-c45.c
18 @@ -110,6 +110,36 @@ int genphy_c45_restart_aneg(struct phy_d
19 EXPORT_SYMBOL_GPL(genphy_c45_restart_aneg);
20
21 /**
22 + * genphy_c45_check_and_restart_aneg - Enable and restart auto-negotiation
23 + * @phydev: target phy_device struct
24 + * @restart: whether aneg restart is requested
25 + *
26 + * This assumes that the auto-negotiation MMD is present.
27 + *
28 + * Check, and restart auto-negotiation if needed.
29 + */
30 +int genphy_c45_check_and_restart_aneg(struct phy_device *phydev, bool restart)
31 +{
32 + int ret = 0;
33 +
34 + if (!restart) {
35 + /* Configure and restart aneg if it wasn't set before */
36 + ret = phy_read_mmd(phydev, MDIO_MMD_AN, MDIO_CTRL1);
37 + if (ret < 0)
38 + return ret;
39 +
40 + if (!(ret & MDIO_AN_CTRL1_ENABLE))
41 + restart = true;
42 + }
43 +
44 + if (restart)
45 + ret = genphy_c45_restart_aneg(phydev);
46 +
47 + return ret;
48 +}
49 +EXPORT_SYMBOL_GPL(genphy_c45_check_and_restart_aneg);
50 +
51 +/**
52 * genphy_c45_aneg_done - return auto-negotiation complete status
53 * @phydev: target phy_device struct
54 *
55 --- a/include/linux/phy.h
56 +++ b/include/linux/phy.h
57 @@ -1098,6 +1098,7 @@ int genphy_write_mmd_unsupported(struct
58
59 /* Clause 45 PHY */
60 int genphy_c45_restart_aneg(struct phy_device *phydev);
61 +int genphy_c45_check_and_restart_aneg(struct phy_device *phydev, bool restart);
62 int genphy_c45_aneg_done(struct phy_device *phydev);
63 int genphy_c45_read_link(struct phy_device *phydev, u32 mmd_mask);
64 int genphy_c45_read_lpa(struct phy_device *phydev);