* [PATCH net-next] hv_netvsc: add ethtool support for set and get of settings
@ 2016-02-25 23:24 Simon Xiao
2016-02-29 22:09 ` David Miller
0 siblings, 1 reply; 5+ messages in thread
From: Simon Xiao @ 2016-02-25 23:24 UTC (permalink / raw)
To: kys, haiyangz, devel, netdev, linux-kernel; +Cc: Simon Xiao
This patch allows the user to set and retrieve speed and duplex of the
hv_netvsc device via ethtool.
Example:
$ ethtool eth0
Settings for eth0:
...
Speed: Unknown!
Duplex: Unknown! (255)
...
$ ethtool -s eth0 speed 1000 duplex full
$ ethtool eth0
Settings for eth0:
...
Speed: 1000Mb/s
Duplex: Full
...
This is based on patches by Roopa Prabhu and Nikolay Aleksandrov.
Signed-off-by: Simon Xiao <sixiao@microsoft.com>
---
drivers/net/hyperv/hyperv_net.h | 4 +++
drivers/net/hyperv/netvsc_drv.c | 56 +++++++++++++++++++++++++++++++++++++++++
2 files changed, 60 insertions(+)
diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
index fcb92c0..b4c6878 100644
--- a/drivers/net/hyperv/hyperv_net.h
+++ b/drivers/net/hyperv/hyperv_net.h
@@ -658,6 +658,10 @@ struct net_device_context {
struct netvsc_stats __percpu *tx_stats;
struct netvsc_stats __percpu *rx_stats;
+
+ /* Ethtool settings */
+ u8 duplex;
+ u32 speed;
};
/* Per netvsc device */
diff --git a/drivers/net/hyperv/netvsc_drv.c b/drivers/net/hyperv/netvsc_drv.c
index 202e2b1..e703b9a 100644
--- a/drivers/net/hyperv/netvsc_drv.c
+++ b/drivers/net/hyperv/netvsc_drv.c
@@ -799,6 +799,58 @@ static int netvsc_set_channels(struct net_device *net,
goto do_set;
}
+static bool netvsc_validate_ethtool_ss_cmd(const struct ethtool_cmd *cmd)
+{
+ struct ethtool_cmd diff1 = *cmd;
+ struct ethtool_cmd diff2 = {};
+
+ ethtool_cmd_speed_set(&diff1, 0);
+ diff1.duplex = 0;
+ /* advertising and cmd are usually set */
+ diff1.advertising = 0;
+ diff1.cmd = 0;
+ /* We set port to PORT_OTHER */
+ diff2.port = PORT_OTHER;
+
+ return !memcmp(&diff1, &diff2, sizeof(diff1));
+}
+
+static void netvsc_init_settings(struct net_device *dev)
+{
+ struct net_device_context *ndc = netdev_priv(dev);
+
+ ndc->speed = SPEED_UNKNOWN;
+ ndc->duplex = DUPLEX_UNKNOWN;
+}
+
+static int netvsc_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
+{
+ struct net_device_context *ndc = netdev_priv(dev);
+
+ ethtool_cmd_speed_set(cmd, ndc->speed);
+ cmd->duplex = ndc->duplex;
+ cmd->port = PORT_OTHER;
+
+ return 0;
+}
+
+static int netvsc_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
+{
+ struct net_device_context *ndc = netdev_priv(dev);
+ u32 speed;
+
+ speed = ethtool_cmd_speed(cmd);
+ if (!ethtool_validate_speed(speed) ||
+ !ethtool_validate_duplex(cmd->duplex) ||
+ !netvsc_validate_ethtool_ss_cmd(cmd))
+ return -EINVAL;
+
+ ndc->speed = speed;
+ ndc->duplex = cmd->duplex;
+
+ return 0;
+}
+
static int netvsc_change_mtu(struct net_device *ndev, int mtu)
{
struct net_device_context *ndevctx = netdev_priv(ndev);
@@ -923,6 +975,8 @@ static const struct ethtool_ops ethtool_ops = {
.get_channels = netvsc_get_channels,
.set_channels = netvsc_set_channels,
.get_ts_info = ethtool_op_get_ts_info,
+ .get_settings = netvsc_get_settings,
+ .set_settings = netvsc_set_settings,
};
static const struct net_device_ops device_ops = {
@@ -1112,6 +1166,8 @@ static int netvsc_probe(struct hv_device *dev,
netif_set_real_num_tx_queues(net, nvdev->num_chn);
netif_set_real_num_rx_queues(net, nvdev->num_chn);
+ netvsc_init_settings(net);
+
ret = register_netdev(net);
if (ret != 0) {
pr_err("Unable to register netdev.\n");
--
2.5.0
^ permalink raw reply related [flat|nested] 5+ messages in thread* Re: [PATCH net-next] hv_netvsc: add ethtool support for set and get of settings
2016-02-25 23:24 [PATCH net-next] hv_netvsc: add ethtool support for set and get of settings Simon Xiao
@ 2016-02-29 22:09 ` David Miller
2016-02-29 22:34 ` Ben Hutchings
0 siblings, 1 reply; 5+ messages in thread
From: David Miller @ 2016-02-29 22:09 UTC (permalink / raw)
To: sixiao; +Cc: devel, haiyangz, linux-kernel, netdev
From: Simon Xiao <sixiao@microsoft.com>
Date: Thu, 25 Feb 2016 15:24:08 -0800
> This patch allows the user to set and retrieve speed and duplex of the
> hv_netvsc device via ethtool.
>
> Example:
> $ ethtool eth0
> Settings for eth0:
> ...
> Speed: Unknown!
> Duplex: Unknown! (255)
> ...
> $ ethtool -s eth0 speed 1000 duplex full
> $ ethtool eth0
> Settings for eth0:
> ...
> Speed: 1000Mb/s
> Duplex: Full
> ...
>
> This is based on patches by Roopa Prabhu and Nikolay Aleksandrov.
>
> Signed-off-by: Simon Xiao <sixiao@microsoft.com>
Applied, thanks.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH net-next] hv_netvsc: add ethtool support for set and get of settings
2016-02-29 22:09 ` David Miller
@ 2016-02-29 22:34 ` Ben Hutchings
2016-02-29 22:50 ` David Miller
0 siblings, 1 reply; 5+ messages in thread
From: Ben Hutchings @ 2016-02-29 22:34 UTC (permalink / raw)
To: David Miller, sixiao; +Cc: devel, haiyangz, linux-kernel, netdev
[-- Attachment #1.1: Type: text/plain, Size: 1178 bytes --]
On Mon, 2016-02-29 at 17:09 -0500, David Miller wrote:
> From: Simon Xiao <sixiao@microsoft.com>
> Date: Thu, 25 Feb 2016 15:24:08 -0800
>
> > This patch allows the user to set and retrieve speed and duplex of the
> > hv_netvsc device via ethtool.
> >
> > Example:
> > $ ethtool eth0
> > Settings for eth0:
> > ...
> > Speed: Unknown!
> > Duplex: Unknown! (255)
> > ...
> > $ ethtool -s eth0 speed 1000 duplex full
> > $ ethtool eth0
> > Settings for eth0:
> > ...
> > Speed: 1000Mb/s
> > Duplex: Full
> > ...
> >
> > This is based on patches by Roopa Prabhu and Nikolay Aleksandrov.
> >
> > Signed-off-by: Simon Xiao <sixiao@microsoft.com>
>
> Applied, thanks.
I missed this due to flu, but now I look at it - I don't see the point.
Link speed isn't meaingful for a memory-based transport, so "unknown"
is correct. The link is effectively full duplex though.
If the issue is that ethtool is a bit shouty about unknowns, let's
consider changing that in ethtool, not teaching drivers to lie.
Ben.
--
Ben Hutchings
If God had intended Man to program,
we'd have been born with serial I/O ports.
[-- Attachment #1.2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 811 bytes --]
[-- Attachment #2: Type: text/plain, Size: 169 bytes --]
_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH net-next] hv_netvsc: add ethtool support for set and get of settings
2016-02-29 22:34 ` Ben Hutchings
@ 2016-02-29 22:50 ` David Miller
2016-03-01 15:31 ` Ben Hutchings
0 siblings, 1 reply; 5+ messages in thread
From: David Miller @ 2016-02-29 22:50 UTC (permalink / raw)
To: ben; +Cc: sixiao, kys, haiyangz, devel, netdev, linux-kernel
From: Ben Hutchings <ben@decadent.org.uk>
Date: Mon, 29 Feb 2016 22:34:38 +0000
> On Mon, 2016-02-29 at 17:09 -0500, David Miller wrote:
>> From: Simon Xiao <sixiao@microsoft.com>
>> Date: Thu, 25 Feb 2016 15:24:08 -0800
>>
>> > This patch allows the user to set and retrieve speed and duplex of the
>> > hv_netvsc device via ethtool.
>> >
>> > Example:
>> > $ ethtool eth0
>> > Settings for eth0:
>> > ...
>> > Speed: Unknown!
>> > Duplex: Unknown! (255)
>> > ...
>> > $ ethtool -s eth0 speed 1000 duplex full
>> > $ ethtool eth0
>> > Settings for eth0:
>> > ...
>> > Speed: 1000Mb/s
>> > Duplex: Full
>> > ...
>> >
>> > This is based on patches by Roopa Prabhu and Nikolay Aleksandrov.
>> >
>> > Signed-off-by: Simon Xiao <sixiao@microsoft.com>
>>
>> Applied, thanks.
>
> I missed this due to flu, but now I look at it - I don't see the point.
> Link speed isn't meaingful for a memory-based transport, so "unknown"
> is correct. The link is effectively full duplex though.
>
> If the issue is that ethtool is a bit shouty about unknowns, let's
> consider changing that in ethtool, not teaching drivers to lie.
The issue is that certain bonding modes do not work properly without
a speed being reported by a device.
We're doing this for other "virtual" devices already thanks to changes
that went in last week, so there is precedence.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH net-next] hv_netvsc: add ethtool support for set and get of settings
2016-02-29 22:50 ` David Miller
@ 2016-03-01 15:31 ` Ben Hutchings
0 siblings, 0 replies; 5+ messages in thread
From: Ben Hutchings @ 2016-03-01 15:31 UTC (permalink / raw)
To: David Miller; +Cc: sixiao, kys, haiyangz, devel, netdev, linux-kernel
[-- Attachment #1: Type: text/plain, Size: 1756 bytes --]
On Mon, 2016-02-29 at 17:50 -0500, David Miller wrote:
> From: Ben Hutchings <ben@decadent.org.uk>
> Date: Mon, 29 Feb 2016 22:34:38 +0000
>
> > On Mon, 2016-02-29 at 17:09 -0500, David Miller wrote:
> >> From: Simon Xiao <sixiao@microsoft.com>
> >> Date: Thu, 25 Feb 2016 15:24:08 -0800
> >>
> >> > This patch allows the user to set and retrieve speed and duplex of the
> >> > hv_netvsc device via ethtool.
> >> >
> >> > Example:
> >> > $ ethtool eth0
> >> > Settings for eth0:
> >> > ...
> >> > Speed: Unknown!
> >> > Duplex: Unknown! (255)
> >> > ...
> >> > $ ethtool -s eth0 speed 1000 duplex full
> >> > $ ethtool eth0
> >> > Settings for eth0:
> >> > ...
> >> > Speed: 1000Mb/s
> >> > Duplex: Full
> >> > ...
> >> >
> >> > This is based on patches by Roopa Prabhu and Nikolay Aleksandrov.
> >> >
> >> > Signed-off-by: Simon Xiao <sixiao@microsoft.com>
> >>
> >> Applied, thanks.
> >
> > I missed this due to flu, but now I look at it - I don't see the point.
> > Link speed isn't meaingful for a memory-based transport, so "unknown"
> > is correct. The link is effectively full duplex though.
> >
> > If the issue is that ethtool is a bit shouty about unknowns, let's
> > consider changing that in ethtool, not teaching drivers to lie.
>
> The issue is that certain bonding modes do not work properly without
> a speed being reported by a device.
Ah, of course.
> We're doing this for other "virtual" devices already thanks to changes
> that went in last week, so there is precedence.
I know, just wasn't convinced it was a good precedent.
Ben.
--
Ben Hutchings
If God had intended Man to program,
we'd have been born with serial I/O ports.
[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 811 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2016-03-01 15:31 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-02-25 23:24 [PATCH net-next] hv_netvsc: add ethtool support for set and get of settings Simon Xiao
2016-02-29 22:09 ` David Miller
2016-02-29 22:34 ` Ben Hutchings
2016-02-29 22:50 ` David Miller
2016-03-01 15:31 ` Ben Hutchings
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).