kernel: bump 4.9 to 4.9.77
[oweals/openwrt.git] / target / linux / generic / pending-4.9 / 701-phy_extension.patch
1 From: John Crispin <john@phrozen.org>
2 Subject: net: phy: add phy_ethtool_ioctl()
3
4 Signed-off-by: John Crispin <john@phrozen.org>
5 ---
6  drivers/net/phy/phy.c | 44 ++++++++++++++++++++++++++++++++++++++++++++
7  include/linux/phy.h   |  1 +
8  2 files changed, 45 insertions(+)
9
10 --- a/drivers/net/phy/phy.c
11 +++ b/drivers/net/phy/phy.c
12 @@ -466,6 +466,50 @@ int phy_ethtool_ksettings_get(struct phy
13  }
14  EXPORT_SYMBOL(phy_ethtool_ksettings_get);
15  
16 +int phy_ethtool_ioctl(struct phy_device *phydev, void *useraddr)
17 +{
18 +       u32 cmd;
19 +       int tmp;
20 +       struct ethtool_cmd ecmd = { ETHTOOL_GSET };
21 +       struct ethtool_value edata = { ETHTOOL_GLINK };
22 +
23 +       if (get_user(cmd, (u32 *) useraddr))
24 +               return -EFAULT;
25 +
26 +       switch (cmd) {
27 +       case ETHTOOL_GSET:
28 +               phy_ethtool_gset(phydev, &ecmd);
29 +               if (copy_to_user(useraddr, &ecmd, sizeof(ecmd)))
30 +                       return -EFAULT;
31 +               return 0;
32 +
33 +       case ETHTOOL_SSET:
34 +               if (copy_from_user(&ecmd, useraddr, sizeof(ecmd)))
35 +                       return -EFAULT;
36 +               return phy_ethtool_sset(phydev, &ecmd);
37 +
38 +       case ETHTOOL_NWAY_RST:
39 +               /* if autoneg is off, it's an error */
40 +               tmp = phy_read(phydev, MII_BMCR);
41 +               if (tmp & BMCR_ANENABLE) {
42 +                       tmp |= (BMCR_ANRESTART);
43 +                       phy_write(phydev, MII_BMCR, tmp);
44 +                       return 0;
45 +               }
46 +               return -EINVAL;
47 +
48 +       case ETHTOOL_GLINK:
49 +               edata.data = (phy_read(phydev,
50 +                               MII_BMSR) & BMSR_LSTATUS) ? 1 : 0;
51 +               if (copy_to_user(useraddr, &edata, sizeof(edata)))
52 +                       return -EFAULT;
53 +               return 0;
54 +       }
55 +
56 +       return -EOPNOTSUPP;
57 +}
58 +EXPORT_SYMBOL(phy_ethtool_ioctl);
59 +
60  /**
61   * phy_mii_ioctl - generic PHY MII ioctl interface
62   * @phydev: the phy_device struct
63 --- a/include/linux/phy.h
64 +++ b/include/linux/phy.h
65 @@ -827,6 +827,7 @@ int phy_ethtool_ksettings_get(struct phy
66                               struct ethtool_link_ksettings *cmd);
67  int phy_ethtool_ksettings_set(struct phy_device *phydev,
68                               const struct ethtool_link_ksettings *cmd);
69 +int phy_ethtool_ioctl(struct phy_device *phydev, void *useraddr);
70  int phy_mii_ioctl(struct phy_device *phydev, struct ifreq *ifr, int cmd);
71  int phy_start_interrupts(struct phy_device *phydev);
72  void phy_print_status(struct phy_device *phydev);