diff mbox series

[net-next,1/4] net: Wrap ndo_do_ioctl() to prepare for DSA stacked ops

Message ID 20200718030533.171556-2-f.fainelli@gmail.com
State Changes Requested
Delegated to: David Miller
Headers show
Series net: dsa: Setup dsa_netdev_ops | expand

Commit Message

Florian Fainelli July 18, 2020, 3:05 a.m. UTC
In preparation for adding another layer of call into a DSA stacked ops
singleton, wrap the ndo_do_ioctl() call into dev_do_ioctl().

Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
---
 net/core/dev_ioctl.c | 24 +++++++++++++++++-------
 1 file changed, 17 insertions(+), 7 deletions(-)

Comments

Vladimir Oltean July 18, 2020, 8:30 p.m. UTC | #1
Hi Florian,

On Fri, Jul 17, 2020 at 08:05:30PM -0700, Florian Fainelli wrote:
> In preparation for adding another layer of call into a DSA stacked ops
> singleton, wrap the ndo_do_ioctl() call into dev_do_ioctl().
> 
> Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
> ---

I missed most of the context, but this looks interesting. Am I correct
in saying that this could save us from having to manually pass
phy_mii_ioctl() and that it could be generically handled here?

>  net/core/dev_ioctl.c | 24 +++++++++++++++++-------
>  1 file changed, 17 insertions(+), 7 deletions(-)
> 
> diff --git a/net/core/dev_ioctl.c b/net/core/dev_ioctl.c
> index 547b587c1950..a213c703c90a 100644
> --- a/net/core/dev_ioctl.c
> +++ b/net/core/dev_ioctl.c
> @@ -225,6 +225,22 @@ static int net_hwtstamp_validate(struct ifreq *ifr)
>  	return 0;
>  }
>  
> +static int dev_do_ioctl(struct net_device *dev,
> +			struct ifreq *ifr, unsigned int cmd)
> +{
> +	const struct net_device_ops *ops = dev->netdev_ops;
> +	int err = -EOPNOTSUPP;
> +
> +	if (ops->ndo_do_ioctl) {
> +		if (netif_device_present(dev))
> +			err = ops->ndo_do_ioctl(dev, ifr, cmd);
> +		else
> +			err = -ENODEV;
> +	}
> +
> +	return err;
> +}
> +
>  /*
>   *	Perform the SIOCxIFxxx calls, inside rtnl_lock()
>   */
> @@ -323,13 +339,7 @@ static int dev_ifsioc(struct net *net, struct ifreq *ifr, unsigned int cmd)
>  		    cmd == SIOCSHWTSTAMP ||
>  		    cmd == SIOCGHWTSTAMP ||
>  		    cmd == SIOCWANDEV) {
> -			err = -EOPNOTSUPP;
> -			if (ops->ndo_do_ioctl) {
> -				if (netif_device_present(dev))
> -					err = ops->ndo_do_ioctl(dev, ifr, cmd);
> -				else
> -					err = -ENODEV;
> -			}
> +			err = dev_do_ioctl(dev, ifr, cmd);
>  		} else
>  			err = -EINVAL;
>  
> -- 
> 2.25.1
>
Florian Fainelli July 18, 2020, 8:36 p.m. UTC | #2
On 7/18/2020 1:30 PM, Vladimir Oltean wrote:
> Hi Florian,
> 
> On Fri, Jul 17, 2020 at 08:05:30PM -0700, Florian Fainelli wrote:
>> In preparation for adding another layer of call into a DSA stacked ops
>> singleton, wrap the ndo_do_ioctl() call into dev_do_ioctl().
>>
>> Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
>> ---
> 
> I missed most of the context, but this looks interesting. Am I correct
> in saying that this could save us from having to manually pass
> phy_mii_ioctl() and that it could be generically handled here?

The motivation for this work started with the realization while
untangling the ethtool/netlink and PHY library that tests like those:
dev->netdev_ops == &foo_ops would be defeated by the way DSA overloads
the DSA net_device operations. A better solution needed to be found.

You are correct that we could just put a call to phy_mii_ioctl() here as
well and avoid having drivers have to use phy_do_ioctl_running or roll
their own.
Vladimir Oltean July 18, 2020, 8:44 p.m. UTC | #3
On Sat, Jul 18, 2020 at 01:36:25PM -0700, Florian Fainelli wrote:
> 
> 
> On 7/18/2020 1:30 PM, Vladimir Oltean wrote:
> > Hi Florian,
> > 
> > On Fri, Jul 17, 2020 at 08:05:30PM -0700, Florian Fainelli wrote:
> >> In preparation for adding another layer of call into a DSA stacked ops
> >> singleton, wrap the ndo_do_ioctl() call into dev_do_ioctl().
> >>
> >> Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
> >> ---
> > 
> > I missed most of the context, but this looks interesting. Am I correct
> > in saying that this could save us from having to manually pass
> > phy_mii_ioctl() and that it could be generically handled here?
> 
> The motivation for this work started with the realization while
> untangling the ethtool/netlink and PHY library that tests like those:
> dev->netdev_ops == &foo_ops would be defeated by the way DSA overloads
> the DSA net_device operations. A better solution needed to be found.
> 
> You are correct that we could just put a call to phy_mii_ioctl() here as
> well and avoid having drivers have to use phy_do_ioctl_running or roll
> their own.
> -- 
> Florian

I see.
The background for my question is that we came to realize that it would
be way cleaner if an Ethernet PHY with 1588 timestamping could just
overload .ndo_do_ioctl() and the ethtool .get_ts_info() of the host
network interface, very similarly to what DSA does.
So it's very good that you started this work, it looks like it provides
a very good foundation. Thanks!

-Vladimir
Andrew Lunn July 19, 2020, 3:31 p.m. UTC | #4
On Fri, Jul 17, 2020 at 08:05:30PM -0700, Florian Fainelli wrote:
> In preparation for adding another layer of call into a DSA stacked ops
> singleton, wrap the ndo_do_ioctl() call into dev_do_ioctl().
> 
> Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>

Reviewed-by: Andrew Lunn <andrew@lunn.ch>

    Andrew
diff mbox series

Patch

diff --git a/net/core/dev_ioctl.c b/net/core/dev_ioctl.c
index 547b587c1950..a213c703c90a 100644
--- a/net/core/dev_ioctl.c
+++ b/net/core/dev_ioctl.c
@@ -225,6 +225,22 @@  static int net_hwtstamp_validate(struct ifreq *ifr)
 	return 0;
 }
 
+static int dev_do_ioctl(struct net_device *dev,
+			struct ifreq *ifr, unsigned int cmd)
+{
+	const struct net_device_ops *ops = dev->netdev_ops;
+	int err = -EOPNOTSUPP;
+
+	if (ops->ndo_do_ioctl) {
+		if (netif_device_present(dev))
+			err = ops->ndo_do_ioctl(dev, ifr, cmd);
+		else
+			err = -ENODEV;
+	}
+
+	return err;
+}
+
 /*
  *	Perform the SIOCxIFxxx calls, inside rtnl_lock()
  */
@@ -323,13 +339,7 @@  static int dev_ifsioc(struct net *net, struct ifreq *ifr, unsigned int cmd)
 		    cmd == SIOCSHWTSTAMP ||
 		    cmd == SIOCGHWTSTAMP ||
 		    cmd == SIOCWANDEV) {
-			err = -EOPNOTSUPP;
-			if (ops->ndo_do_ioctl) {
-				if (netif_device_present(dev))
-					err = ops->ndo_do_ioctl(dev, ifr, cmd);
-				else
-					err = -ENODEV;
-			}
+			err = dev_do_ioctl(dev, ifr, cmd);
 		} else
 			err = -EINVAL;