Skip to contentSkip to conversation

net: ethtool: add ethtool_op_{get|set}_link_ksettings

PATCH In review Philippe Reynes 4 participants 9 messages May 8, 2016 – May 9, 2016

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

v2 cover net: ethtool: add ethtool_op_{get|set}_link_ksettings

Ethtool callbacks {get|set}_link_ksettings may be the same for many drivers. So we add two generics callbacks ethtool_op_{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:
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: core: ethtool: add ethtool_op_{get|set}_link_ksettings
net: ethernet: fec: use phydev from struct net_device
net: ethernet: fec: use ethtool_op_{get|set}_link_ksettings

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

PATCH v2 1/3 net: core: ethtool: add ethtool_op_{get|set}_link_ksettings

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

---
 include/linux/ethtool.h |    5 +++++
 net/core/ethtool.c      |   24 ++++++++++++++++++++++++
 2 files changed, 29 insertions(+), 0 deletions(-)
include/linux/ethtool.h +5 -0
index 9ded8c6..9a55836 100644
@@ -157,6 +157,11 @@ void ethtool_convert_legacy_u32_to_link_mode(unsigned long *dst,
 bool ethtool_convert_link_mode_to_legacy_u32(u32 *legacy_u32,
 				     const unsigned long *src);
 
+int ethtool_op_get_link_ksettings(struct net_device *ndev,
+				  struct ethtool_link_ksettings *cmd);
+int ethtool_op_set_link_ksettings(struct net_device *ndev,
+				  const struct ethtool_link_ksettings *cmd);
+
 /**
  * struct ethtool_ops - optional netdev operations
  * @get_settings: DEPRECATED, use %get_link_ksettings/%set_link_ksettings
net/core/ethtool.c +24 -0
index bdb4013..b605fb1 100644
@@ -852,6 +852,30 @@ static int ethtool_set_settings(struct net_device *dev, void __user *useraddr)
 	return dev->ethtool_ops->set_settings(dev, &cmd);
 }
 
+int ethtool_op_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(ethtool_op_get_link_ksettings);
+
+int ethtool_op_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(ethtool_op_set_link_ksettings);
+
 static noinline_for_stack int ethtool_get_drvinfo(struct net_device *dev,
 						  void __user *useraddr)
 {
Signature · 1 line
1.7.4.4
#3 lore raw

PATCH v2 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
#7 lore raw

PATCH v2 3/3 net: ethernet: fec: use ethtool_op_{get|set}_link_ksettings

In reply to Philippe Reynes

There are two generics functions ethtool_op_{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 e1d24ff..f2dae6c 100644
@@ -2055,28 +2055,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)
 {
@@ -2575,8 +2553,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	= ethtool_op_get_link_ksettings,
+	.set_link_ksettings	= ethtool_op_set_link_ksettings,
 };
 
 static int fec_enet_ioctl(struct net_device *ndev, struct ifreq *rq, int cmd)
Signature · 1 line
1.7.4.4
#4 lore raw

Re: [PATCH v2 2/3] net: ethernet: fec: use phydev from struct net_device

In reply to Philippe Reynes
Quoted 4 lines · 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.

But there is no central code that updates the pointer, so:

[...]

drivers/net/ethernet/freescale/fec_main.c static int fec_enet_mii_probe(struct net_device *ndev) · line 1931

Quoted 5 lines
(quoted diff) +0 -0
@@ -1928,7 +1926,6 @@ static int fec_enet_mii_probe(struct net_device *ndev)


  phy_dev->advertising = phy_dev->supported;

drivers/net/ethernet/freescale/fec_main.c +0 -1
-	fep->phy_dev = phy_dev;

you need to assign ndev->phydev here

[...]

drivers/net/ethernet/freescale/fec_main.c fec_enet_close(struct net_device *ndev) · line 2872

Quoted 7 lines
(quoted diff) +0 -0
@@ -2875,8 +2869,7 @@ fec_enet_close(struct net_device *ndev)
  		fec_stop(ndev);
  	}

drivers/net/ethernet/freescale/fec_main.c +1 -2
-	phy_disconnect(fep->phy_dev);
-	fep->phy_dev = NULL;
+	phy_disconnect(ndev->phydev);

[...]

and you need to set it to NULL here.

Ben.

Signature · 2 lines
Ben Hutchings
I haven't lost my mind; it's backed up on tape somewhere.
#5 lore raw

Re: [PATCH v2 2/3] net: ethernet: fec: use phydev from struct net_device

Quoted 7 lines · Ben Hutchings
Quoted 4 lines · 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.

But there is no central code that updates the pointer, so:

The function phy_attach_direct and phy_detach update the pointer phydev in the struct net_device.

Quoted 9 lines

[...]

drivers/net/ethernet/freescale/fec_main.c static int fec_enet_mii_probe(struct net_device *ndev) · line 1931

Quoted 5 lines
drivers/net/ethernet/freescale/fec_main.c +0 -1
@@ -1928,7 +1926,6 @@ static int fec_enet_mii_probe(struct net_device *ndev)
 
  	phy_dev->advertising = phy_dev->supported;
 
-	fep->phy_dev = phy_dev;

you need to assign ndev->phydev here

The function fec_enet_mii_probe call of_phy_connect, which call phy_connect_direct, which call phy_attach_direct. This last function update the pointer phydev of struct net_device.

Quoted 11 lines

[...]

drivers/net/ethernet/freescale/fec_main.c fec_enet_close(struct net_device *ndev) · line 2872

Quoted 7 lines
drivers/net/ethernet/freescale/fec_main.c +1 -2
@@ -2875,8 +2869,7 @@ fec_enet_close(struct net_device *ndev)
  		fec_stop(ndev);
  	}
 
-	phy_disconnect(fep->phy_dev);
-	fep->phy_dev = NULL;
+	phy_disconnect(ndev->phydev);

[...]

and you need to set it to NULL here.

The function fec_enet_close call phy_disconnect, which call phy_detach. This last function set the pointer phydev in the struct net_device to NULL.

So from my understanding, those two lines aren't usefull. May you confirm that I'm on the right way please ?

Quoted 2 lines

Ben.

Philippe

#6 lore raw

Re: [PATCH v2 2/3] net: ethernet: fec: use phydev from struct net_device

Quoted 11 lines · Philippe Reynes
Quoted 8 lines · Ben Hutchings
Quoted 5 lines · 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.

But there is no central code that updates the pointer, so:

The function phy_attach_direct and phy_detach update the pointer phydev in the struct net_device.

[...]

Quoted 2 lines

So from my understanding, those two lines aren't usefull. May you confirm that I'm on the right way please ?

Sorry, you're right.

Ben.

Signature · 2 lines
Ben Hutchings
I haven't lost my mind; it's backed up on tape somewhere.
Acked-by on the v2 series
#8 lore raw
In reply to Philippe Reynes

Fom: Philippe Reynes <[email protected]> Sent: Monday, May 09, 2016 5:45 AM

Quoted 27 lines

To: Fugang Duan <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; Philippe Reynes <[email protected]>
Subject: [PATCH v2 0/3] net: ethtool: add ethtool_op_{get|set}_link_ksettings

Ethtool callbacks {get|set}_link_ksettings may be the same for many drivers. So we add two generics callbacks ethtool_op_{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:
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: core: ethtool: add ethtool_op_{get|set}_link_ksettings
net: ethernet: fec: use phydev from struct net_device
net: ethernet: fec: use ethtool_op_{get|set}_link_ksettings

Quoted 8 lines
 drivers/net/ethernet/freescale/fec.h      |    1 -
 drivers/net/ethernet/freescale/fec_main.c |   71 +++++++++--------------------
 include/linux/ethtool.h                   |    5 ++
 net/core/ethtool.c                        |   24 ++++++++++
 4 files changed, 50 insertions(+), 51 deletions(-)

--
1.7.4.4

#2 lore raw

Re: [PATCH v2 1/3] net: core: ethtool: add ethtool_op_{get|set}_link_ksettings

In reply to Philippe Reynes

Are you sure this belongs to ethtool.h? For one, I believe you need an #include phy.h somewhere. I would suggest instead to keep this in phy.h, presumably with a more explicit name suggesting that phydev is involved.

Quoted 64 lines · Philippe Reynes

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

---
 include/linux/ethtool.h |    5 +++++
 net/core/ethtool.c      |   24 ++++++++++++++++++++++++
 2 files changed, 29 insertions(+), 0 deletions(-)
include/linux/ethtool.h +5 -0
index 9ded8c6..9a55836 100644
@@ -157,6 +157,11 @@ void ethtool_convert_legacy_u32_to_link_mode(unsigned long *dst,
 bool ethtool_convert_link_mode_to_legacy_u32(u32 *legacy_u32,
                                     const unsigned long *src);
 
+int ethtool_op_get_link_ksettings(struct net_device *ndev,
+                                 struct ethtool_link_ksettings *cmd);
+int ethtool_op_set_link_ksettings(struct net_device *ndev,
+                                 const struct ethtool_link_ksettings *cmd);
+
 /**
  * struct ethtool_ops - optional netdev operations
  * @get_settings: DEPRECATED, use %get_link_ksettings/%set_link_ksettings
net/core/ethtool.c +24 -1
index bdb4013..b605fb1 100644
@@ -852,6 +852,30 @@ static int ethtool_set_settings(struct net_device *dev, void __user *useraddr)
        return dev->ethtool_ops->set_settings(dev, &cmd);
 }
 
+int ethtool_op_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(ethtool_op_get_link_ksettings);
+
+int ethtool_op_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(ethtool_op_set_link_ksettings);
+
 static noinline_for_stack int ethtool_get_drvinfo(struct net_device *dev,
                                                  void __user *useraddr)
 {
--

1.7.4.4