* [PATCH 1/2] net: phy: add ethtool_phy_{get|set}_link_ksettings
@ 2016-05-06 23:18 Philippe Reynes
2016-05-06 23:18 ` [PATCH 2/2] net: ethernet: fec: use ethtool_phy_{get|set}_link_ksettings Philippe Reynes
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: Philippe Reynes @ 2016-05-06 23:18 UTC (permalink / raw)
To: f.fainelli, fugang.duan, davem; +Cc: netdev, linux-kernel, 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 structure
We add two defines ethtool_phy_{get|set}_link_ksettings
to avoid writing severals times almost the same function.
Signed-off-by: Philippe Reynes <tremyfr@gmail.com>
---
include/linux/phy.h | 46 ++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 46 insertions(+), 0 deletions(-)
diff --git a/include/linux/phy.h b/include/linux/phy.h
index be3f83b..e4a79fa 100644
--- a/include/linux/phy.h
+++ b/include/linux/phy.h
@@ -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);
--
1.7.4.4
^ permalink raw reply related [flat|nested] 7+ messages in thread* [PATCH 2/2] net: ethernet: fec: use ethtool_phy_{get|set}_link_ksettings
2016-05-06 23:18 [PATCH 1/2] net: phy: add ethtool_phy_{get|set}_link_ksettings Philippe Reynes
@ 2016-05-06 23:18 ` Philippe Reynes
2016-05-06 23:41 ` [PATCH 1/2] net: phy: add ethtool_phy_{get|set}_link_ksettings Florian Fainelli
2016-05-07 11:59 ` Ben Hutchings
2 siblings, 0 replies; 7+ messages in thread
From: Philippe Reynes @ 2016-05-06 23:18 UTC (permalink / raw)
To: f.fainelli, fugang.duan, davem; +Cc: netdev, linux-kernel, Philippe Reynes
Use the generic ethtool_phy_{get|set}_link_ksettings to
generate the callback for {get|set}_link_ksettings.
Signed-off-by: Philippe Reynes <tremyfr@gmail.com>
---
drivers/net/ethernet/freescale/fec_main.c | 25 ++-----------------------
1 files changed, 2 insertions(+), 23 deletions(-)
diff --git a/drivers/net/ethernet/freescale/fec_main.c b/drivers/net/ethernet/freescale/fec_main.c
index bfa10c3..00339d0 100644
--- a/drivers/net/ethernet/freescale/fec_main.c
+++ b/drivers/net/ethernet/freescale/fec_main.c
@@ -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)
--
1.7.4.4
^ permalink raw reply related [flat|nested] 7+ messages in thread* Re: [PATCH 1/2] net: phy: add ethtool_phy_{get|set}_link_ksettings
2016-05-06 23:18 [PATCH 1/2] net: phy: add ethtool_phy_{get|set}_link_ksettings Philippe Reynes
2016-05-06 23:18 ` [PATCH 2/2] net: ethernet: fec: use ethtool_phy_{get|set}_link_ksettings Philippe Reynes
@ 2016-05-06 23:41 ` Florian Fainelli
2016-05-07 11:59 ` Ben Hutchings
2 siblings, 0 replies; 7+ messages in thread
From: Florian Fainelli @ 2016-05-06 23:41 UTC (permalink / raw)
To: Philippe Reynes, fugang.duan, davem; +Cc: netdev, linux-kernel
On 06/05/16 16:18, Philippe Reynes wrote:
> 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.
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...
--
Florian
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH 1/2] net: phy: add ethtool_phy_{get|set}_link_ksettings
2016-05-06 23:18 [PATCH 1/2] net: phy: add ethtool_phy_{get|set}_link_ksettings Philippe Reynes
2016-05-06 23:18 ` [PATCH 2/2] net: ethernet: fec: use ethtool_phy_{get|set}_link_ksettings Philippe Reynes
2016-05-06 23:41 ` [PATCH 1/2] net: phy: add ethtool_phy_{get|set}_link_ksettings Florian Fainelli
@ 2016-05-07 11:59 ` Ben Hutchings
2016-05-07 22:56 ` Philippe Reynes
2 siblings, 1 reply; 7+ messages in thread
From: Ben Hutchings @ 2016-05-07 11:59 UTC (permalink / raw)
To: Philippe Reynes, f.fainelli, fugang.duan, davem; +Cc: netdev, linux-kernel
[-- Attachment #1: Type: text/plain, Size: 867 bytes --]
On Sat, 2016-05-07 at 01:18 +0200, Philippe Reynes wrote:
> 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.
[...]
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.
--
Ben Hutchings
Editing code like this is akin to sticking plasters on the bleeding stump
of a severed limb. - me, 29 June 1999
[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 819 bytes --]
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH 1/2] net: phy: add ethtool_phy_{get|set}_link_ksettings
2016-05-07 11:59 ` Ben Hutchings
@ 2016-05-07 22:56 ` Philippe Reynes
2016-05-08 0:13 ` Ben Hutchings
2016-05-08 18:19 ` Florian Fainelli
0 siblings, 2 replies; 7+ messages in thread
From: Philippe Reynes @ 2016-05-07 22:56 UTC (permalink / raw)
To: Ben Hutchings; +Cc: f.fainelli, fugang.duan, davem, netdev, linux-kernel
On 07/05/16 13:59, Ben Hutchings wrote:
> On Sat, 2016-05-07 at 01:18 +0200, Philippe Reynes wrote:
>> 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.
> [...]
>
> 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
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH 1/2] net: phy: add ethtool_phy_{get|set}_link_ksettings
2016-05-07 22:56 ` Philippe Reynes
@ 2016-05-08 0:13 ` Ben Hutchings
2016-05-08 18:19 ` Florian Fainelli
1 sibling, 0 replies; 7+ messages in thread
From: Ben Hutchings @ 2016-05-08 0:13 UTC (permalink / raw)
To: Philippe Reynes; +Cc: f.fainelli, fugang.duan, davem, netdev, linux-kernel
[-- Attachment #1: Type: text/plain, Size: 1630 bytes --]
On Sun, 2016-05-08 at 00:56 +0200, Philippe Reynes wrote:
> On 07/05/16 13:59, Ben Hutchings wrote:
> >
> > On Sat, 2016-05-07 at 01:18 +0200, Philippe Reynes wrote:
> > >
> > > 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.
> > [...]
> >
> > 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 ?
Maybe just because no-one bothered to update them after it was added to
net_device.
Ben.
> 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.
[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 819 bytes --]
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH 1/2] net: phy: add ethtool_phy_{get|set}_link_ksettings
2016-05-07 22:56 ` Philippe Reynes
2016-05-08 0:13 ` Ben Hutchings
@ 2016-05-08 18:19 ` Florian Fainelli
1 sibling, 0 replies; 7+ messages in thread
From: Florian Fainelli @ 2016-05-08 18:19 UTC (permalink / raw)
To: Philippe Reynes, Ben Hutchings; +Cc: fugang.duan, davem, netdev, linux-kernel
On May 7, 2016 3:56:34 PM PDT, Philippe Reynes <tremyfr@gmail.com> wrote:
>On 07/05/16 13:59, Ben Hutchings wrote:
>> On Sat, 2016-05-07 at 01:18 +0200, Philippe Reynes wrote:
>>> 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.
>> [...]
>>
>> 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 ?
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.
>
>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.
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.
--
Florian
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2016-05-08 18:19 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-05-06 23:18 [PATCH 1/2] net: phy: add ethtool_phy_{get|set}_link_ksettings Philippe Reynes
2016-05-06 23:18 ` [PATCH 2/2] net: ethernet: fec: use ethtool_phy_{get|set}_link_ksettings Philippe Reynes
2016-05-06 23:41 ` [PATCH 1/2] net: phy: add ethtool_phy_{get|set}_link_ksettings Florian Fainelli
2016-05-07 11:59 ` Ben Hutchings
2016-05-07 22:56 ` Philippe Reynes
2016-05-08 0:13 ` Ben Hutchings
2016-05-08 18:19 ` Florian Fainelli
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).