net: phy: add ethtool_phy_{get|set}_link_ksettings
Subsystems (4)
PATCH 1/2 net: phy: add ethtool_phy_{get|set}_link_ksettings
The callback {get|set}_link_ksettings are often defined in a very close way. There are mainly two differences in those callback:
- the name of the netdev private structure
- the name of the struct phydev in the private structure
We add two defines ethtool_phy_{get|set}_link_ksettings to avoid writing severals times almost the same function.
--- include/linux/phy.h | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 46 insertions(+), 0 deletions(-)
include/linux/phy.h +46 -0
@@ -830,6 +830,52 @@ 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); +/** +* ethtool_phy_get_link_ksettings() - Helper macro for get_link_ksettings +* @name: name of the driver +* @private: name of the private structure in the net device +* @phy: name of the phydev variable in the private structure +* +* Helper macro for the callback get_link_ksettings which +* simply call phy_ethtool_ksettings_get. +*/ +#define ethtool_phy_get_link_ksettings (name, private, phy) \ + static int \ + name##_get_link_ksettings(struct net_device *ndev, \ + struct ethtool_link_ksettings *cmd) \ + { \ + struct private *priv = netdev_priv(ndev); \ + struct phy_device *phydev = priv->phy; \ + \ + if (!phydev) \ + return -ENODEV; \ + \ + return phy_ethtool_ksettings_get(phydev, cmd); \ + } + +/** +* ethtool_phy_set_link_ksettings() - Helper macro for set_link_ksettings +* @name: name of the driver +* @private: name of the private structure in the net device +* @phy: name of the phydev variable in the private structure +* +* Helper macro for the callback set_link_ksettings which +* simply call phy_ethtool_ksettings_set. +*/ +#define ethtool_phy_set_link_ksettings (name, private, phy) \ + static int \ + name##_set_link_ksettings(struct net_device *ndev, \ + const struct ethtool_link_ksettings *cmd) \ + { \ + struct private *priv = netdev_priv(ndev); \ + struct phy_device *phydev = priv->phy; \ + \ + if (!phydev) \ + return -ENODEV; \ + \ + return phy_ethtool_ksettings_set(phydev, cmd); \ + } +int __init mdio_bus_init (void );void mdio_bus_exit (void );
Signature · 1 line
1.7.4.4
PATCH 2/2 net: ethernet: fec: use ethtool_phy_{get|set}_link_ksettings
Use the generic ethtool_phy_{get|set}_link_ksettings to generate the callback for {get|set}_link_ksettings.
--- drivers/net/ethernet/freescale/fec_main.c | 25 ++----------------------- 1 files changed, 2 insertions(+), 23 deletions(-)
drivers/net/ethernet/freescale/fec_main.c +2 -23
@@ -2058,29 +2058,8 @@ 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 fec_enet_private *fep =netdev_priv (ndev); -struct phy_device *phydev = fep->phy_dev; - -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 fec_enet_private *fep =netdev_priv (ndev); -struct phy_device *phydev = fep->phy_dev; - -if (!phydev) -return -ENODEV ; - -return phy_ethtool_ksettings_set (phydev, cmd); -} +ethtool_phy_get_link_ksettings (fec_enet, fec_enet_private, phy_dev); +ethtool_phy_set_link_ksettings (fec_enet, fec_enet_private, phy_dev);static void fec_enet_get_drvinfo (struct net_device *ndev,struct ethtool_drvinfo *info)
Signature · 1 line
1.7.4.4
Quoted 8 lines · Philippe Reynes
The callback {get|set}_link_ksettings are often defined in a very close way. There are mainly two differences in those callback:
- the name of the netdev private structure
- the name of the struct phydev in the private structureWe add two defines ethtool_phy_{get|set}_link_ksettings to avoid writing severals times almost the same function.
This looks fine in principle, but then there is a whole ton of code that could become like that in the kernel, I do not have any strong opinion either way...
Signature · 1 line
Florian
Quoted 8 lines · Philippe Reynes
The callback {get|set}_link_ksettings are often defined in a very close way. There are mainly two differences in those callback:
- the name of the netdev private structure
- the name of the struct phydev in the private structureWe add two defines ethtool_phy_{get|set}_link_ksettings to avoid writing severals times almost the same function.
[...]
I don't think there's no need to access a private structure, as there's a phydev pointer in struct net_device. If some drivers don't maintain that pointer, they should be changed to do so. Then they can use generic implementations of {get,set}_link_ksettings provided by phylib.
Ben.
Signature · 3 lines
Ben Hutchings Editing code like this is akin to sticking plasters on the bleeding stump of a severed limb. - me, 29 June 1999
Quoted 9 lines · Ben Hutchings
Quoted 8 lines · Philippe Reynes
The callback {get|set}_link_ksettings are often defined in a very close way. There are mainly two differences in those callback:
- the name of the netdev private structure
- the name of the struct phydev in the private structureWe add two defines ethtool_phy_{get|set}_link_ksettings to avoid writing severals times almost the same function.
Quoted 7 lines
[...]
I don't think there's no need to access a private structure, as there's a phydev pointer in struct
net_device. If some drivers don't maintain that pointer, they should be changed to do so. Then they can use generic implementations of {get,set}_link_ksettings provided by phylib.
If we could use the phydev in the struct net_device, we could write a generic function for {get|set}_link_ksettings. It's a good idea.
But I've quickly looked and a lot of ethernet driver use the private structure to store the phydev. If the ethernet driver may use the struct net_device for phydev, do you know why so many drivers use the private structure ?
If everybody agree, I can send a new version with a generic {get|set}_link_ksettings and a update of fec to use the phydev store in the structure net_device.
Philippe
Quoted 19 lines · Philippe Reynes
Quoted 11 lines · Ben Hutchings
Quoted 9 lines · Philippe Reynes
The callback {get|set}_link_ksettings are often defined in a very close way. There are mainly two differences in those callback:
- the name of the netdev private structure
- the name of the struct phydev in the private structureWe add two defines ethtool_phy_{get|set}_link_ksettings to avoid writing severals times almost the same function.
Quoted 7 lines
[...]
I don't think there's no need to access a private structure, as there's a phydev pointer in struct net_device. If some drivers don't maintain that pointer, they should be changed to do so. Then they can use generic implementations of {get,set}_link_ksettings provided by phylib.
Quoted 7 lines
If we could use the phydev in the struct
net_device, we could write a generic function for {get|set}_link_ksettings. It's a good idea.But I've quickly looked and a lot of ethernet driver use the private structure to store the phydev. If the ethernet driver may use the struct
net_devicefor phydev, do you know why so many drivers use the private structure ?
Maybe just because no-one bothered to update them after it was added to net_device.
Ben.
Quoted 2 lines
If everybody agree, I can send a new version with a generic {get|set}_link_ksettings and a update of fec to use the phydev store in the structure
net_device.
--
Ben Hutchings
I haven't lost my mind; it's backed up on tape somewhere.
Quoted 20 lines · Philippe Reynes
Quoted 7 lines · Ben Hutchings
Quoted 6 lines · Philippe Reynes
The callback {get|set}_link_ksettings are often defined in a very close way. There are mainly two differences in those callback:
- the name of the netdev private structure
- the name of the struct phydev in the private structureQuoted 5 lines
Quoted 2 lines
We add two defines ethtool_phy_{get|set}_link_ksettings to avoid writing severals times almost the same function.
[...]
I don't think there's no need to access a private structure, as
there's
Quoted 1 line
a phydev pointer in struct
net_device. If some drivers don'tmaintain
Quoted 3 lines
that pointer, they should be changed to do so. Then they can use generic implementations of {get,set}_link_ksettings provided by phylib.
Quoted 7 lines
If we could use the phydev in the struct
net_device, we could write a generic function for {get|set}_link_ksettings. It's a good idea.But I've quickly looked and a lot of ethernet driver use the private structure to store the phydev. If the ethernet driver may use the struct
net_devicefor phydev, do you know why so many drivers use the private structure ?
The introduction of a phy_device pointer in net_device came much later than the introduction and use of PHYLIB by most drivers so it is probably just an oversight.
Quoted 5 lines
If everybody agree, I can send a new version with a generic {get|set}_link_ksettings
and a update of fec to use the phydev store in the structurenet_device.
Yes, that sounds very reasonable. It might be possible to cook a coccinelle patch which replaces the use of a private phy_device pointer and utilize the one from net_device.
Signature · 1 line
Florian