kernel: split patches folder up into backport, pending and hack folders
[openwrt/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 diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
11 index a9be26f1f677..d0a5ac1d6445 100644
12 --- a/drivers/net/phy/phy.c
13 +++ b/drivers/net/phy/phy.c
14 @@ -466,6 +466,50 @@ int phy_ethtool_ksettings_get(struct phy_device *phydev,
15 }
16 EXPORT_SYMBOL(phy_ethtool_ksettings_get);
17
18 +int phy_ethtool_ioctl(struct phy_device *phydev, void *useraddr)
19 +{
20 + u32 cmd;
21 + int tmp;
22 + struct ethtool_cmd ecmd = { ETHTOOL_GSET };
23 + struct ethtool_value edata = { ETHTOOL_GLINK };
24 +
25 + if (get_user(cmd, (u32 *) useraddr))
26 + return -EFAULT;
27 +
28 + switch (cmd) {
29 + case ETHTOOL_GSET:
30 + phy_ethtool_gset(phydev, &ecmd);
31 + if (copy_to_user(useraddr, &ecmd, sizeof(ecmd)))
32 + return -EFAULT;
33 + return 0;
34 +
35 + case ETHTOOL_SSET:
36 + if (copy_from_user(&ecmd, useraddr, sizeof(ecmd)))
37 + return -EFAULT;
38 + return phy_ethtool_sset(phydev, &ecmd);
39 +
40 + case ETHTOOL_NWAY_RST:
41 + /* if autoneg is off, it's an error */
42 + tmp = phy_read(phydev, MII_BMCR);
43 + if (tmp & BMCR_ANENABLE) {
44 + tmp |= (BMCR_ANRESTART);
45 + phy_write(phydev, MII_BMCR, tmp);
46 + return 0;
47 + }
48 + return -EINVAL;
49 +
50 + case ETHTOOL_GLINK:
51 + edata.data = (phy_read(phydev,
52 + MII_BMSR) & BMSR_LSTATUS) ? 1 : 0;
53 + if (copy_to_user(useraddr, &edata, sizeof(edata)))
54 + return -EFAULT;
55 + return 0;
56 + }
57 +
58 + return -EOPNOTSUPP;
59 +}
60 +EXPORT_SYMBOL(phy_ethtool_ioctl);
61 +
62 /**
63 * phy_mii_ioctl - generic PHY MII ioctl interface
64 * @phydev: the phy_device struct
65 diff --git a/include/linux/phy.h b/include/linux/phy.h
66 index bd22670e2182..93c1e74afc44 100644
67 --- a/include/linux/phy.h
68 +++ b/include/linux/phy.h
69 @@ -813,6 +813,7 @@ int phy_ethtool_ksettings_get(struct phy_device *phydev,
70 struct ethtool_link_ksettings *cmd);
71 int phy_ethtool_ksettings_set(struct phy_device *phydev,
72 const struct ethtool_link_ksettings *cmd);
73 +int phy_ethtool_ioctl(struct phy_device *phydev, void *useraddr);
74 int phy_mii_ioctl(struct phy_device *phydev, struct ifreq *ifr, int cmd);
75 int phy_start_interrupts(struct phy_device *phydev);
76 void phy_print_status(struct phy_device *phydev);
77 --
78 2.11.0
79