Skip to contentSkip to conversation

net: phy: add phy_ethtool_{get|set}_link_ksettings

PATCH In review Philippe Reynes 3 participants 6 messages May 9, 2016 – May 10, 2016

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

v3 cover net: phy: add phy_ethtool_{get|set}_link_ksettings

Ethtool callbacks {get|set}_link_ksettings may be the same for many drivers. So we add two generics callbacks phy_ethtool_{get|set}_link_ksettings.

To use those generics callbacks, the ethernet driver must use the pointer phydev contained in struct net_device, and not use a private structure to store this pointer.

Changelog:
v3:
- rename function to phy_ethtool_{get|set}_link_ksettings
- move code to net/phy/phy.c
This feedback were provided by David Decotigny
v2:
- use generic function instead of macro
- ethernet driver use the pointer phydev provided by struct net_device Those idea were provided by Ben Hutchings,
and Florian Fainelli acknowledge them.

Philippe Reynes (3):
net: phy: add phy_ethtool_{get|set}_link_ksettings
net: ethernet: fec: use phydev from struct net_device
net: ethernet: fec: use phy_ethtool_{get|set}_link_ksettings

 drivers/net/ethernet/freescale/fec.h      |    1 -
 drivers/net/ethernet/freescale/fec_main.c |   71 +++++++++--------------------
 drivers/net/phy/phy.c                     |   24 ++++++++++
 include/linux/phy.h                       |    4 ++
 4 files changed, 49 insertions(+), 51 deletions(-)
Signature · 1 line
1.7.4.4
#1 lore raw

PATCH v3 1/3 net: phy: add phy_ethtool_{get|set}_link_ksettings

Ethtool callbacks {get|set}_link_ksettings are often the same, so we add two generics functions phy_ethtool_{get|set}_link_ksettings to avoid writing severals times the same function.

---
 drivers/net/phy/phy.c |   24 ++++++++++++++++++++++++
 include/linux/phy.h   |    4 ++++
 2 files changed, 28 insertions(+), 0 deletions(-)
drivers/net/phy/phy.c +24 -0
index 6f221c8..603e8db 100644
@@ -1347,3 +1347,27 @@ void phy_ethtool_get_wol(struct phy_device *phydev, struct ethtool_wolinfo *wol)
 		phydev->drv->get_wol(phydev, wol);
 }
 EXPORT_SYMBOL(phy_ethtool_get_wol);
+
+int phy_ethtool_get_link_ksettings(struct net_device *ndev,
+				   struct ethtool_link_ksettings *cmd)
+{
+	struct phy_device *phydev = ndev->phydev;
+
+	if (!phydev)
+		return -ENODEV;
+
+	return phy_ethtool_ksettings_get(phydev, cmd);
+}
+EXPORT_SYMBOL(phy_ethtool_get_link_ksettings);
+
+int phy_ethtool_set_link_ksettings(struct net_device *ndev,
+				   const struct ethtool_link_ksettings *cmd)
+{
+	struct phy_device *phydev = ndev->phydev;
+
+	if (!phydev)
+		return -ENODEV;
+
+	return phy_ethtool_ksettings_set(phydev, cmd);
+}
+EXPORT_SYMBOL(phy_ethtool_set_link_ksettings);
include/linux/phy.h +4 -0
index be3f83b..2d24b28 100644
@@ -829,6 +829,10 @@ int phy_ethtool_get_eee(struct phy_device *phydev, struct ethtool_eee *data);
 int phy_ethtool_set_wol(struct phy_device *phydev, struct ethtool_wolinfo *wol);
 void phy_ethtool_get_wol(struct phy_device *phydev,
 			 struct ethtool_wolinfo *wol);
+int phy_ethtool_get_link_ksettings(struct net_device *ndev,
+				   struct ethtool_link_ksettings *cmd);
+int phy_ethtool_set_link_ksettings(struct net_device *ndev,
+				   const struct ethtool_link_ksettings *cmd);
 
 int __init mdio_bus_init(void);
 void mdio_bus_exit(void);
Signature · 1 line
1.7.4.4
Acked-by on v3 1/3
#2 lore raw
Quoted 58 lines · Philippe Reynes

Ethtool callbacks {get|set}_link_ksettings are often the same, so we add two generics functions phy_ethtool_{get|set}_link_ksettings to avoid writing severals times the same function.

---
 drivers/net/phy/phy.c |   24 ++++++++++++++++++++++++
 include/linux/phy.h   |    4 ++++
 2 files changed, 28 insertions(+), 0 deletions(-)
drivers/net/phy/phy.c +24 -0
index 6f221c8..603e8db 100644
@@ -1347,3 +1347,27 @@ void phy_ethtool_get_wol(struct phy_device *phydev, struct ethtool_wolinfo *wol)
                phydev->drv->get_wol(phydev, wol);
 }
 EXPORT_SYMBOL(phy_ethtool_get_wol);
+
+int phy_ethtool_get_link_ksettings(struct net_device *ndev,
+                                  struct ethtool_link_ksettings *cmd)
+{
+       struct phy_device *phydev = ndev->phydev;
+
+       if (!phydev)
+               return -ENODEV;
+
+       return phy_ethtool_ksettings_get(phydev, cmd);
+}
+EXPORT_SYMBOL(phy_ethtool_get_link_ksettings);
+
+int phy_ethtool_set_link_ksettings(struct net_device *ndev,
+                                  const struct ethtool_link_ksettings *cmd)
+{
+       struct phy_device *phydev = ndev->phydev;
+
+       if (!phydev)
+               return -ENODEV;
+
+       return phy_ethtool_ksettings_set(phydev, cmd);
+}
+EXPORT_SYMBOL(phy_ethtool_set_link_ksettings);
include/linux/phy.h +4 -1
index be3f83b..2d24b28 100644
@@ -829,6 +829,10 @@ int phy_ethtool_get_eee(struct phy_device *phydev, struct ethtool_eee *data);
 int phy_ethtool_set_wol(struct phy_device *phydev, struct ethtool_wolinfo *wol);
 void phy_ethtool_get_wol(struct phy_device *phydev,
                         struct ethtool_wolinfo *wol);
+int phy_ethtool_get_link_ksettings(struct net_device *ndev,
+                                  struct ethtool_link_ksettings *cmd);
+int phy_ethtool_set_link_ksettings(struct net_device *ndev,
+                                  const struct ethtool_link_ksettings *cmd);
 
 int __init mdio_bus_init(void);
 void mdio_bus_exit(void);
--
Quoted 2 lines

1.7.4.4

#3 lore raw

PATCH v3 2/3 net: ethernet: fec: use phydev from struct net_device

In reply to Philippe Reynes

The private structure contain a pointer to phydev, but the structure net_device already contain such pointer. So we can remove the pointer phydev in the private structure, and update the driver to use the one contained in struct net_device.

---
 drivers/net/ethernet/freescale/fec.h      |    1 -
 drivers/net/ethernet/freescale/fec_main.c |   49 ++++++++++++----------------
 2 files changed, 21 insertions(+), 29 deletions(-)
drivers/net/ethernet/freescale/fec.h +0 -1
index 195122e..f58f9ea 100644
@@ -517,7 +517,6 @@ struct fec_enet_private {
 
 	/* Phylib and MDIO interface */
 	struct	mii_bus *mii_bus;
-	struct	phy_device *phy_dev;
 	int	mii_timeout;
 	uint	phy_speed;
 	phy_interface_t	phy_interface;
drivers/net/ethernet/freescale/fec_main.c +21 -28

158 lines not on this page · raw message

Signature · 1 line
1.7.4.4
#4 lore raw

PATCH v3 3/3 net: ethernet: fec: use phy_ethtool_{get|set}_link_ksettings

In reply to Philippe Reynes

There are two generics functions phy_ethtool_{get|set}_link_ksettings, so we can use them instead of defining the same code in the driver.

---
 drivers/net/ethernet/freescale/fec_main.c |   26 ++------------------------
 1 files changed, 2 insertions(+), 24 deletions(-)
drivers/net/ethernet/freescale/fec_main.c +2 -24
index 9d6e35c..ca2cccc 100644
@@ -2061,28 +2061,6 @@ static void fec_enet_mii_remove(struct fec_enet_private *fep)
 	}
 }
 
-static int fec_enet_get_link_ksettings(struct net_device *ndev,
-				       struct ethtool_link_ksettings *cmd)
-{
-	struct phy_device *phydev = ndev->phydev;
-
-	if (!phydev)
-		return -ENODEV;
-
-	return phy_ethtool_ksettings_get(phydev, cmd);
-}
-
-static int fec_enet_set_link_ksettings(struct net_device *ndev,
-				       const struct ethtool_link_ksettings *cmd)
-{
-	struct phy_device *phydev = ndev->phydev;
-
-	if (!phydev)
-		return -ENODEV;
-
-	return phy_ethtool_ksettings_set(phydev, cmd);
-}
-
 static void fec_enet_get_drvinfo(struct net_device *ndev,
 				 struct ethtool_drvinfo *info)
 {
@@ -2581,8 +2559,8 @@ static const struct ethtool_ops fec_enet_ethtool_ops = {
 	.set_tunable		= fec_enet_set_tunable,
 	.get_wol		= fec_enet_get_wol,
 	.set_wol		= fec_enet_set_wol,
-	.get_link_ksettings	= fec_enet_get_link_ksettings,
-	.set_link_ksettings	= fec_enet_set_link_ksettings,
+	.get_link_ksettings	= phy_ethtool_get_link_ksettings,
+	.set_link_ksettings	= phy_ethtool_set_link_ksettings,
 };
 
 static int fec_enet_ioctl(struct net_device *ndev, struct ifreq *rq, int cmd)
Signature · 1 line
1.7.4.4
maintainer
#5 lore raw
In reply to Philippe Reynes

From: Philippe Reynes <[email protected]>
Date: Tue, 10 May 2016 00:19:40 +0200

Quoted 7 lines

Ethtool callbacks {get|set}_link_ksettings may be the same for many drivers. So we add two generics callbacks phy_ethtool_{get|set}_link_ksettings.

To use those generics callbacks, the ethernet driver must use the pointer phydev contained in struct net_device, and not use a private structure to store this pointer.

Series applied, thanks.