4ad3bf698ace8dc1a2047a517abb644c4890c46a
[oweals/openwrt.git] /
1 From ce825df56e0480a2cbb296e38976babafb57e503 Mon Sep 17 00:00:00 2001
2 From: Andrew Lunn <andrew@lunn.ch>
3 Date: Wed, 12 Sep 2018 01:53:17 +0200
4 Subject: [PATCH 601/660] net: ethernet: Add helper for set_pauseparam for Asym
5  Pause
6
7 ethtool can be used to enable/disable pause. Add a helper to configure
8 the PHY when asym pause is supported.
9
10 Signed-off-by: Andrew Lunn <andrew@lunn.ch>
11 Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
12 Signed-off-by: David S. Miller <davem@davemloft.net>
13 ---
14  drivers/net/phy/phy_device.c | 30 ++++++++++++++++++++++++++++++
15  include/linux/phy.h          |  1 +
16  2 files changed, 31 insertions(+)
17
18 --- a/drivers/net/phy/phy_device.c
19 +++ b/drivers/net/phy/phy_device.c
20 @@ -1790,6 +1790,36 @@ void phy_support_asym_pause(struct phy_d
21  }
22  EXPORT_SYMBOL(phy_support_asym_pause);
23  
24 +/**
25 + * phy_set_asym_pause - Configure Pause and Asym Pause
26 + * @phydev: target phy_device struct
27 + * @rx: Receiver Pause is supported
28 + * @tx: Transmit Pause is supported
29 + *
30 + * Description: Configure advertised Pause support depending on if
31 + * transmit and receiver pause is supported. If there has been a
32 + * change in adverting, trigger a new autoneg. Generally called from
33 + * the set_pauseparam .ndo.
34 + */
35 +void phy_set_asym_pause(struct phy_device *phydev, bool rx, bool tx)
36 +{
37 +       u16 oldadv = phydev->advertising;
38 +       u16 newadv = oldadv &= ~(SUPPORTED_Pause | SUPPORTED_Asym_Pause);
39 +
40 +       if (rx)
41 +               newadv |= SUPPORTED_Pause | SUPPORTED_Asym_Pause;
42 +       if (tx)
43 +               newadv ^= SUPPORTED_Asym_Pause;
44 +
45 +       if (oldadv != newadv) {
46 +               phydev->advertising = newadv;
47 +
48 +               if (phydev->autoneg)
49 +                       phy_start_aneg(phydev);
50 +       }
51 +}
52 +EXPORT_SYMBOL(phy_set_asym_pause);
53 +
54  static void of_set_phy_supported(struct phy_device *phydev)
55  {
56         struct device_node *node = phydev->mdio.dev.of_node;
57 --- a/include/linux/phy.h
58 +++ b/include/linux/phy.h
59 @@ -1050,6 +1050,7 @@ int phy_start_interrupts(struct phy_devi
60  void phy_print_status(struct phy_device *phydev);
61  int phy_set_max_speed(struct phy_device *phydev, u32 max_speed);
62  void phy_support_asym_pause(struct phy_device *phydev);
63 +void phy_set_asym_pause(struct phy_device *phydev, bool rx, bool tx);
64  
65  int phy_register_fixup(const char *bus_id, u32 phy_uid, u32 phy_uid_mask,
66                        int (*run)(struct phy_device *));