* [PATCH V2 0/1] tun: dynamically set speed of tun @ 2015-02-13 3:35 Zhu Yanjun 2015-02-13 3:35 ` [PATCH V2 1/1] tun: change speed from 10M to dynamically configured Zhu Yanjun 0 siblings, 1 reply; 7+ messages in thread From: Zhu Yanjun @ 2015-02-13 3:35 UTC (permalink / raw) To: netdev, mst, jasowang, viro, davem, sergei.shtylyov V2: Follow the advice from Sergei, a new patch is made. V1: The default speed of tun is 10M while the normal nic speed is 1000M. When the speed of tun is accessed by the userspace application, the default 10M is not proper. In this case, the default tun speed is changed to 1000M. And this speed can be dynamically configured by the command "ethtool -s tunX speed 10/100/1000". Zhu Yanjun (1): tun: change speed from 10M to dynamically configured drivers/net/tun.c | 42 +++++++++++++++++++++++++++++++++++++++++- include/uapi/linux/if_tun.h | 5 +++++ 2 files changed, 46 insertions(+), 1 deletion(-) -- 1.9.1 ^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH V2 1/1] tun: change speed from 10M to dynamically configured 2015-02-13 3:35 [PATCH V2 0/1] tun: dynamically set speed of tun Zhu Yanjun @ 2015-02-13 3:35 ` Zhu Yanjun 2015-02-13 3:44 ` Jonathon Reinhart 2015-02-13 10:37 ` Sergei Shtylyov 0 siblings, 2 replies; 7+ messages in thread From: Zhu Yanjun @ 2015-02-13 3:35 UTC (permalink / raw) To: netdev, mst, jasowang, viro, davem, sergei.shtylyov The default speed of normal nic is 1000M while the default speed of tun is 10M. Now the default speed of tun is changed to 1000M. And there are 3 options: 10M, 100M and 1000M to the speed of tun. The command "ethtool -s tun0 speed 10/100/1000" can configure the speed of tun dynamically. CC: Michael S. Tsirkin <mst@redhat.com> CC: Jason Wang <jasowang@redhat.com> CC: Al Viro <viro@zeniv.linux.org.uk> Reviewed-by: Sergei Shtylyov <sergei.shtylyov@cogentembedded.com> Signed-off-by: Zhu Yanjun <Yanjun.Zhu@windriver.com> --- drivers/net/tun.c | 42 +++++++++++++++++++++++++++++++++++++++++- include/uapi/linux/if_tun.h | 5 +++++ 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/drivers/net/tun.c b/drivers/net/tun.c index 8c8dc16..0ee36f1 100644 --- a/drivers/net/tun.c +++ b/drivers/net/tun.c @@ -950,6 +950,9 @@ static void tun_net_init(struct net_device *dev) dev->addr_len = 0; dev->mtu = 1500; + /* Set default speed 1000M */ + tun->flags |= TUN_CTRL_SPD_1000; + /* Zero header length */ dev->type = ARPHRD_NONE; dev->flags = IFF_POINTOPOINT | IFF_NOARP | IFF_MULTICAST; @@ -2257,9 +2260,18 @@ static struct miscdevice tun_miscdev = { static int tun_get_settings(struct net_device *dev, struct ethtool_cmd *cmd) { + struct tun_struct *tun = netdev_priv(dev); + + /* Get the speed of tun */ + if (tun->flags & TUN_CTRL_SPD_1000) { + ethtool_cmd_speed_set(cmd, SPEED_1000); + } else if (tun->flags & TUN_CTRL_SPD_100) { + ethtool_cmd_speed_set(cmd, SPEED_100); + } else + ethtool_cmd_speed_set(cmd, SPEED_10); + cmd->supported = 0; cmd->advertising = 0; - ethtool_cmd_speed_set(cmd, SPEED_10); cmd->duplex = DUPLEX_FULL; cmd->port = PORT_TP; cmd->phy_address = 0; @@ -2287,6 +2299,33 @@ static void tun_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info } } +static int tun_set_settings(struct net_device *dev, struct ethtool_cmd *cmd) +{ + struct tun_struct *tun = netdev_priv(dev); + u32 speed = ethtool_cmd_speed(cmd); + + /* Clear speed flag */ + tun->flags &= ~(TUN_CTRL_SPD_10 | TUN_CTRL_SPD_100 | + TUN_CTRL_SPD_1000); + + /* Set speed flag */ + switch (speed) { + case 10: + tun->flags |= TUN_CTRL_SPD_10; + break; + case 100: + tun->flags |= TUN_CTRL_SPD_100; + break; + case 1000: + tun->flags |= TUN_CTRL_SPD_1000; + break; + default: + tun_debug(KERN_INFO, tun, "wrong speed!\n"); + } + + return 0; +} + static u32 tun_get_msglevel(struct net_device *dev) { #ifdef TUN_DEBUG @@ -2307,6 +2346,7 @@ static void tun_set_msglevel(struct net_device *dev, u32 value) static const struct ethtool_ops tun_ethtool_ops = { .get_settings = tun_get_settings, + .set_settings = tun_set_settings, .get_drvinfo = tun_get_drvinfo, .get_msglevel = tun_get_msglevel, .set_msglevel = tun_set_msglevel, diff --git a/include/uapi/linux/if_tun.h b/include/uapi/linux/if_tun.h index 50ae243..78a09a7 100644 --- a/include/uapi/linux/if_tun.h +++ b/include/uapi/linux/if_tun.h @@ -66,6 +66,11 @@ #define IFF_PERSIST 0x0800 #define IFF_NOFILTER 0x1000 +/*add speed control, default 1000M*/ +#define TUN_CTRL_SPD_10 0x0020 +#define TUN_CTRL_SPD_100 0x0040 +#define TUN_CTRL_SPD_1000 0x0080 + /* Socket options */ #define TUN_TX_TIMESTAMP 1 -- 1.9.1 ^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH V2 1/1] tun: change speed from 10M to dynamically configured 2015-02-13 3:35 ` [PATCH V2 1/1] tun: change speed from 10M to dynamically configured Zhu Yanjun @ 2015-02-13 3:44 ` Jonathon Reinhart 2015-02-13 5:31 ` yzhu1 2015-02-13 10:37 ` Sergei Shtylyov 1 sibling, 1 reply; 7+ messages in thread From: Jonathon Reinhart @ 2015-02-13 3:44 UTC (permalink / raw) To: Zhu Yanjun; +Cc: netdev, mst, jasowang, viro, davem, sergei.shtylyov Shouldn't the default case of tun_set_settings() return -EINVAL instead of zero? On Thu, Feb 12, 2015 at 10:35 PM, Zhu Yanjun <Yanjun.Zhu@windriver.com> wrote: > > The default speed of normal nic is 1000M while the default speed > of tun is 10M. Now the default speed of tun is changed to 1000M. > And there are 3 options: 10M, 100M and 1000M to the speed of tun. > The command "ethtool -s tun0 speed 10/100/1000" can configure the > speed of tun dynamically. > > CC: Michael S. Tsirkin <mst@redhat.com> > CC: Jason Wang <jasowang@redhat.com> > CC: Al Viro <viro@zeniv.linux.org.uk> > Reviewed-by: Sergei Shtylyov <sergei.shtylyov@cogentembedded.com> > Signed-off-by: Zhu Yanjun <Yanjun.Zhu@windriver.com> > --- > drivers/net/tun.c | 42 +++++++++++++++++++++++++++++++++++++++++- > include/uapi/linux/if_tun.h | 5 +++++ > 2 files changed, 46 insertions(+), 1 deletion(-) > > diff --git a/drivers/net/tun.c b/drivers/net/tun.c > index 8c8dc16..0ee36f1 100644 > --- a/drivers/net/tun.c > +++ b/drivers/net/tun.c > @@ -950,6 +950,9 @@ static void tun_net_init(struct net_device *dev) > dev->addr_len = 0; > dev->mtu = 1500; > > + /* Set default speed 1000M */ > + tun->flags |= TUN_CTRL_SPD_1000; > + > /* Zero header length */ > dev->type = ARPHRD_NONE; > dev->flags = IFF_POINTOPOINT | IFF_NOARP | IFF_MULTICAST; > @@ -2257,9 +2260,18 @@ static struct miscdevice tun_miscdev = { > > static int tun_get_settings(struct net_device *dev, struct ethtool_cmd *cmd) > { > + struct tun_struct *tun = netdev_priv(dev); > + > + /* Get the speed of tun */ > + if (tun->flags & TUN_CTRL_SPD_1000) { > + ethtool_cmd_speed_set(cmd, SPEED_1000); > + } else if (tun->flags & TUN_CTRL_SPD_100) { > + ethtool_cmd_speed_set(cmd, SPEED_100); > + } else > + ethtool_cmd_speed_set(cmd, SPEED_10); > + > cmd->supported = 0; > cmd->advertising = 0; > - ethtool_cmd_speed_set(cmd, SPEED_10); > cmd->duplex = DUPLEX_FULL; > cmd->port = PORT_TP; > cmd->phy_address = 0; > @@ -2287,6 +2299,33 @@ static void tun_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info > } > } > > +static int tun_set_settings(struct net_device *dev, struct ethtool_cmd *cmd) > +{ > + struct tun_struct *tun = netdev_priv(dev); > + u32 speed = ethtool_cmd_speed(cmd); > + > + /* Clear speed flag */ > + tun->flags &= ~(TUN_CTRL_SPD_10 | TUN_CTRL_SPD_100 | > + TUN_CTRL_SPD_1000); > + > + /* Set speed flag */ > + switch (speed) { > + case 10: > + tun->flags |= TUN_CTRL_SPD_10; > + break; > + case 100: > + tun->flags |= TUN_CTRL_SPD_100; > + break; > + case 1000: > + tun->flags |= TUN_CTRL_SPD_1000; > + break; > + default: > + tun_debug(KERN_INFO, tun, "wrong speed!\n"); > + } > + > + return 0; > +} > + > static u32 tun_get_msglevel(struct net_device *dev) > { > #ifdef TUN_DEBUG > @@ -2307,6 +2346,7 @@ static void tun_set_msglevel(struct net_device *dev, u32 value) > > static const struct ethtool_ops tun_ethtool_ops = { > .get_settings = tun_get_settings, > + .set_settings = tun_set_settings, > .get_drvinfo = tun_get_drvinfo, > .get_msglevel = tun_get_msglevel, > .set_msglevel = tun_set_msglevel, > diff --git a/include/uapi/linux/if_tun.h b/include/uapi/linux/if_tun.h > index 50ae243..78a09a7 100644 > --- a/include/uapi/linux/if_tun.h > +++ b/include/uapi/linux/if_tun.h > @@ -66,6 +66,11 @@ > #define IFF_PERSIST 0x0800 > #define IFF_NOFILTER 0x1000 > > +/*add speed control, default 1000M*/ > +#define TUN_CTRL_SPD_10 0x0020 > +#define TUN_CTRL_SPD_100 0x0040 > +#define TUN_CTRL_SPD_1000 0x0080 > + > /* Socket options */ > #define TUN_TX_TIMESTAMP 1 > > -- > 1.9.1 > > -- > To unsubscribe from this list: send the line "unsubscribe netdev" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html -- Computers are incredibly fast, accurate and stupid. Human beings are incredibly slow, inaccurate and brilliant. Together they are powerful beyond imagination. A. Einstein ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH V2 1/1] tun: change speed from 10M to dynamically configured 2015-02-13 3:44 ` Jonathon Reinhart @ 2015-02-13 5:31 ` yzhu1 2015-02-13 5:42 ` Jonathon Reinhart 0 siblings, 1 reply; 7+ messages in thread From: yzhu1 @ 2015-02-13 5:31 UTC (permalink / raw) To: Jonathon Reinhart; +Cc: netdev, mst, jasowang, viro, davem, sergei.shtylyov On 02/13/2015 11:44 AM, Jonathon Reinhart wrote: > Shouldn't the default case of tun_set_settings() return -EINVAL instead of zero? I agree with you. Zhu Yanjun > > On Thu, Feb 12, 2015 at 10:35 PM, Zhu Yanjun <Yanjun.Zhu@windriver.com> wrote: >> The default speed of normal nic is 1000M while the default speed >> of tun is 10M. Now the default speed of tun is changed to 1000M. >> And there are 3 options: 10M, 100M and 1000M to the speed of tun. >> The command "ethtool -s tun0 speed 10/100/1000" can configure the >> speed of tun dynamically. >> >> CC: Michael S. Tsirkin <mst@redhat.com> >> CC: Jason Wang <jasowang@redhat.com> >> CC: Al Viro <viro@zeniv.linux.org.uk> >> Reviewed-by: Sergei Shtylyov <sergei.shtylyov@cogentembedded.com> >> Signed-off-by: Zhu Yanjun <Yanjun.Zhu@windriver.com> >> --- >> drivers/net/tun.c | 42 +++++++++++++++++++++++++++++++++++++++++- >> include/uapi/linux/if_tun.h | 5 +++++ >> 2 files changed, 46 insertions(+), 1 deletion(-) >> >> diff --git a/drivers/net/tun.c b/drivers/net/tun.c >> index 8c8dc16..0ee36f1 100644 >> --- a/drivers/net/tun.c >> +++ b/drivers/net/tun.c >> @@ -950,6 +950,9 @@ static void tun_net_init(struct net_device *dev) >> dev->addr_len = 0; >> dev->mtu = 1500; >> >> + /* Set default speed 1000M */ >> + tun->flags |= TUN_CTRL_SPD_1000; >> + >> /* Zero header length */ >> dev->type = ARPHRD_NONE; >> dev->flags = IFF_POINTOPOINT | IFF_NOARP | IFF_MULTICAST; >> @@ -2257,9 +2260,18 @@ static struct miscdevice tun_miscdev = { >> >> static int tun_get_settings(struct net_device *dev, struct ethtool_cmd *cmd) >> { >> + struct tun_struct *tun = netdev_priv(dev); >> + >> + /* Get the speed of tun */ >> + if (tun->flags & TUN_CTRL_SPD_1000) { >> + ethtool_cmd_speed_set(cmd, SPEED_1000); >> + } else if (tun->flags & TUN_CTRL_SPD_100) { >> + ethtool_cmd_speed_set(cmd, SPEED_100); >> + } else >> + ethtool_cmd_speed_set(cmd, SPEED_10); >> + >> cmd->supported = 0; >> cmd->advertising = 0; >> - ethtool_cmd_speed_set(cmd, SPEED_10); >> cmd->duplex = DUPLEX_FULL; >> cmd->port = PORT_TP; >> cmd->phy_address = 0; >> @@ -2287,6 +2299,33 @@ static void tun_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info >> } >> } >> >> +static int tun_set_settings(struct net_device *dev, struct ethtool_cmd *cmd) >> +{ >> + struct tun_struct *tun = netdev_priv(dev); >> + u32 speed = ethtool_cmd_speed(cmd); >> + >> + /* Clear speed flag */ >> + tun->flags &= ~(TUN_CTRL_SPD_10 | TUN_CTRL_SPD_100 | >> + TUN_CTRL_SPD_1000); >> + >> + /* Set speed flag */ >> + switch (speed) { >> + case 10: >> + tun->flags |= TUN_CTRL_SPD_10; >> + break; >> + case 100: >> + tun->flags |= TUN_CTRL_SPD_100; >> + break; >> + case 1000: >> + tun->flags |= TUN_CTRL_SPD_1000; >> + break; >> + default: >> + tun_debug(KERN_INFO, tun, "wrong speed!\n"); >> + } >> + >> + return 0; >> +} >> + >> static u32 tun_get_msglevel(struct net_device *dev) >> { >> #ifdef TUN_DEBUG >> @@ -2307,6 +2346,7 @@ static void tun_set_msglevel(struct net_device *dev, u32 value) >> >> static const struct ethtool_ops tun_ethtool_ops = { >> .get_settings = tun_get_settings, >> + .set_settings = tun_set_settings, >> .get_drvinfo = tun_get_drvinfo, >> .get_msglevel = tun_get_msglevel, >> .set_msglevel = tun_set_msglevel, >> diff --git a/include/uapi/linux/if_tun.h b/include/uapi/linux/if_tun.h >> index 50ae243..78a09a7 100644 >> --- a/include/uapi/linux/if_tun.h >> +++ b/include/uapi/linux/if_tun.h >> @@ -66,6 +66,11 @@ >> #define IFF_PERSIST 0x0800 >> #define IFF_NOFILTER 0x1000 >> >> +/*add speed control, default 1000M*/ >> +#define TUN_CTRL_SPD_10 0x0020 >> +#define TUN_CTRL_SPD_100 0x0040 >> +#define TUN_CTRL_SPD_1000 0x0080 >> + >> /* Socket options */ >> #define TUN_TX_TIMESTAMP 1 >> >> -- >> 1.9.1 >> >> -- >> To unsubscribe from this list: send the line "unsubscribe netdev" in >> the body of a message to majordomo@vger.kernel.org >> More majordomo info at http://vger.kernel.org/majordomo-info.html > > > ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH V2 1/1] tun: change speed from 10M to dynamically configured 2015-02-13 5:31 ` yzhu1 @ 2015-02-13 5:42 ` Jonathon Reinhart 2015-02-13 5:56 ` yzhu1 0 siblings, 1 reply; 7+ messages in thread From: Jonathon Reinhart @ 2015-02-13 5:42 UTC (permalink / raw) To: yzhu1; +Cc: netdev, mst, jasowang, viro, davem, sergei.shtylyov Also in the default case, you've already cleared the existing TUN_CTRL_SPD flags, which probably isn't what a user would expect if he passed an invalid value. On Fri, Feb 13, 2015 at 12:31 AM, yzhu1 <Yanjun.Zhu@windriver.com> wrote: > On 02/13/2015 11:44 AM, Jonathon Reinhart wrote: >> >> Shouldn't the default case of tun_set_settings() return -EINVAL instead of >> zero? > > I agree with you. > > Zhu Yanjun > > >> >> On Thu, Feb 12, 2015 at 10:35 PM, Zhu Yanjun <Yanjun.Zhu@windriver.com> >> wrote: >>> >>> The default speed of normal nic is 1000M while the default speed >>> of tun is 10M. Now the default speed of tun is changed to 1000M. >>> And there are 3 options: 10M, 100M and 1000M to the speed of tun. >>> The command "ethtool -s tun0 speed 10/100/1000" can configure the >>> speed of tun dynamically. >>> >>> CC: Michael S. Tsirkin <mst@redhat.com> >>> CC: Jason Wang <jasowang@redhat.com> >>> CC: Al Viro <viro@zeniv.linux.org.uk> >>> Reviewed-by: Sergei Shtylyov <sergei.shtylyov@cogentembedded.com> >>> Signed-off-by: Zhu Yanjun <Yanjun.Zhu@windriver.com> >>> --- >>> drivers/net/tun.c | 42 >>> +++++++++++++++++++++++++++++++++++++++++- >>> include/uapi/linux/if_tun.h | 5 +++++ >>> 2 files changed, 46 insertions(+), 1 deletion(-) >>> >>> diff --git a/drivers/net/tun.c b/drivers/net/tun.c >>> index 8c8dc16..0ee36f1 100644 >>> --- a/drivers/net/tun.c >>> +++ b/drivers/net/tun.c >>> @@ -950,6 +950,9 @@ static void tun_net_init(struct net_device *dev) >>> dev->addr_len = 0; >>> dev->mtu = 1500; >>> >>> + /* Set default speed 1000M */ >>> + tun->flags |= TUN_CTRL_SPD_1000; >>> + >>> /* Zero header length */ >>> dev->type = ARPHRD_NONE; >>> dev->flags = IFF_POINTOPOINT | IFF_NOARP | >>> IFF_MULTICAST; >>> @@ -2257,9 +2260,18 @@ static struct miscdevice tun_miscdev = { >>> >>> static int tun_get_settings(struct net_device *dev, struct ethtool_cmd >>> *cmd) >>> { >>> + struct tun_struct *tun = netdev_priv(dev); >>> + >>> + /* Get the speed of tun */ >>> + if (tun->flags & TUN_CTRL_SPD_1000) { >>> + ethtool_cmd_speed_set(cmd, SPEED_1000); >>> + } else if (tun->flags & TUN_CTRL_SPD_100) { >>> + ethtool_cmd_speed_set(cmd, SPEED_100); >>> + } else >>> + ethtool_cmd_speed_set(cmd, SPEED_10); >>> + >>> cmd->supported = 0; >>> cmd->advertising = 0; >>> - ethtool_cmd_speed_set(cmd, SPEED_10); >>> cmd->duplex = DUPLEX_FULL; >>> cmd->port = PORT_TP; >>> cmd->phy_address = 0; >>> @@ -2287,6 +2299,33 @@ static void tun_get_drvinfo(struct net_device >>> *dev, struct ethtool_drvinfo *info >>> } >>> } >>> >>> +static int tun_set_settings(struct net_device *dev, struct ethtool_cmd >>> *cmd) >>> +{ >>> + struct tun_struct *tun = netdev_priv(dev); >>> + u32 speed = ethtool_cmd_speed(cmd); >>> + >>> + /* Clear speed flag */ >>> + tun->flags &= ~(TUN_CTRL_SPD_10 | TUN_CTRL_SPD_100 | >>> + TUN_CTRL_SPD_1000); >>> + >>> + /* Set speed flag */ >>> + switch (speed) { >>> + case 10: >>> + tun->flags |= TUN_CTRL_SPD_10; >>> + break; >>> + case 100: >>> + tun->flags |= TUN_CTRL_SPD_100; >>> + break; >>> + case 1000: >>> + tun->flags |= TUN_CTRL_SPD_1000; >>> + break; >>> + default: >>> + tun_debug(KERN_INFO, tun, "wrong speed!\n"); >>> + } >>> + >>> + return 0; >>> +} >>> + >>> static u32 tun_get_msglevel(struct net_device *dev) >>> { >>> #ifdef TUN_DEBUG >>> @@ -2307,6 +2346,7 @@ static void tun_set_msglevel(struct net_device >>> *dev, u32 value) >>> >>> static const struct ethtool_ops tun_ethtool_ops = { >>> .get_settings = tun_get_settings, >>> + .set_settings = tun_set_settings, >>> .get_drvinfo = tun_get_drvinfo, >>> .get_msglevel = tun_get_msglevel, >>> .set_msglevel = tun_set_msglevel, >>> diff --git a/include/uapi/linux/if_tun.h b/include/uapi/linux/if_tun.h >>> index 50ae243..78a09a7 100644 >>> --- a/include/uapi/linux/if_tun.h >>> +++ b/include/uapi/linux/if_tun.h >>> @@ -66,6 +66,11 @@ >>> #define IFF_PERSIST 0x0800 >>> #define IFF_NOFILTER 0x1000 >>> >>> +/*add speed control, default 1000M*/ >>> +#define TUN_CTRL_SPD_10 0x0020 >>> +#define TUN_CTRL_SPD_100 0x0040 >>> +#define TUN_CTRL_SPD_1000 0x0080 >>> + >>> /* Socket options */ >>> #define TUN_TX_TIMESTAMP 1 >>> >>> -- >>> 1.9.1 >>> >>> -- >>> To unsubscribe from this list: send the line "unsubscribe netdev" in >>> the body of a message to majordomo@vger.kernel.org >>> More majordomo info at http://vger.kernel.org/majordomo-info.html >> >> >> >> > ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH V2 1/1] tun: change speed from 10M to dynamically configured 2015-02-13 5:42 ` Jonathon Reinhart @ 2015-02-13 5:56 ` yzhu1 0 siblings, 0 replies; 7+ messages in thread From: yzhu1 @ 2015-02-13 5:56 UTC (permalink / raw) To: Jonathon Reinhart; +Cc: netdev, mst, jasowang, viro, davem, sergei.shtylyov Yeah. my fault. I will correct it. On 02/13/2015 01:42 PM, Jonathon Reinhart wrote: > Also in the default case, you've already cleared the existing > TUN_CTRL_SPD flags, > which probably isn't what a user would expect if he passed an invalid value. > > On Fri, Feb 13, 2015 at 12:31 AM, yzhu1 <Yanjun.Zhu@windriver.com> wrote: >> On 02/13/2015 11:44 AM, Jonathon Reinhart wrote: >>> Shouldn't the default case of tun_set_settings() return -EINVAL instead of >>> zero? >> I agree with you. >> >> Zhu Yanjun >> >> >>> On Thu, Feb 12, 2015 at 10:35 PM, Zhu Yanjun <Yanjun.Zhu@windriver.com> >>> wrote: >>>> The default speed of normal nic is 1000M while the default speed >>>> of tun is 10M. Now the default speed of tun is changed to 1000M. >>>> And there are 3 options: 10M, 100M and 1000M to the speed of tun. >>>> The command "ethtool -s tun0 speed 10/100/1000" can configure the >>>> speed of tun dynamically. >>>> >>>> CC: Michael S. Tsirkin <mst@redhat.com> >>>> CC: Jason Wang <jasowang@redhat.com> >>>> CC: Al Viro <viro@zeniv.linux.org.uk> >>>> Reviewed-by: Sergei Shtylyov <sergei.shtylyov@cogentembedded.com> >>>> Signed-off-by: Zhu Yanjun <Yanjun.Zhu@windriver.com> >>>> --- >>>> drivers/net/tun.c | 42 >>>> +++++++++++++++++++++++++++++++++++++++++- >>>> include/uapi/linux/if_tun.h | 5 +++++ >>>> 2 files changed, 46 insertions(+), 1 deletion(-) >>>> >>>> diff --git a/drivers/net/tun.c b/drivers/net/tun.c >>>> index 8c8dc16..0ee36f1 100644 >>>> --- a/drivers/net/tun.c >>>> +++ b/drivers/net/tun.c >>>> @@ -950,6 +950,9 @@ static void tun_net_init(struct net_device *dev) >>>> dev->addr_len = 0; >>>> dev->mtu = 1500; >>>> >>>> + /* Set default speed 1000M */ >>>> + tun->flags |= TUN_CTRL_SPD_1000; >>>> + >>>> /* Zero header length */ >>>> dev->type = ARPHRD_NONE; >>>> dev->flags = IFF_POINTOPOINT | IFF_NOARP | >>>> IFF_MULTICAST; >>>> @@ -2257,9 +2260,18 @@ static struct miscdevice tun_miscdev = { >>>> >>>> static int tun_get_settings(struct net_device *dev, struct ethtool_cmd >>>> *cmd) >>>> { >>>> + struct tun_struct *tun = netdev_priv(dev); >>>> + >>>> + /* Get the speed of tun */ >>>> + if (tun->flags & TUN_CTRL_SPD_1000) { >>>> + ethtool_cmd_speed_set(cmd, SPEED_1000); >>>> + } else if (tun->flags & TUN_CTRL_SPD_100) { >>>> + ethtool_cmd_speed_set(cmd, SPEED_100); >>>> + } else >>>> + ethtool_cmd_speed_set(cmd, SPEED_10); >>>> + >>>> cmd->supported = 0; >>>> cmd->advertising = 0; >>>> - ethtool_cmd_speed_set(cmd, SPEED_10); >>>> cmd->duplex = DUPLEX_FULL; >>>> cmd->port = PORT_TP; >>>> cmd->phy_address = 0; >>>> @@ -2287,6 +2299,33 @@ static void tun_get_drvinfo(struct net_device >>>> *dev, struct ethtool_drvinfo *info >>>> } >>>> } >>>> >>>> +static int tun_set_settings(struct net_device *dev, struct ethtool_cmd >>>> *cmd) >>>> +{ >>>> + struct tun_struct *tun = netdev_priv(dev); >>>> + u32 speed = ethtool_cmd_speed(cmd); >>>> + >>>> + /* Clear speed flag */ >>>> + tun->flags &= ~(TUN_CTRL_SPD_10 | TUN_CTRL_SPD_100 | >>>> + TUN_CTRL_SPD_1000); >>>> + >>>> + /* Set speed flag */ >>>> + switch (speed) { >>>> + case 10: >>>> + tun->flags |= TUN_CTRL_SPD_10; >>>> + break; >>>> + case 100: >>>> + tun->flags |= TUN_CTRL_SPD_100; >>>> + break; >>>> + case 1000: >>>> + tun->flags |= TUN_CTRL_SPD_1000; >>>> + break; >>>> + default: >>>> + tun_debug(KERN_INFO, tun, "wrong speed!\n"); >>>> + } >>>> + >>>> + return 0; >>>> +} >>>> + >>>> static u32 tun_get_msglevel(struct net_device *dev) >>>> { >>>> #ifdef TUN_DEBUG >>>> @@ -2307,6 +2346,7 @@ static void tun_set_msglevel(struct net_device >>>> *dev, u32 value) >>>> >>>> static const struct ethtool_ops tun_ethtool_ops = { >>>> .get_settings = tun_get_settings, >>>> + .set_settings = tun_set_settings, >>>> .get_drvinfo = tun_get_drvinfo, >>>> .get_msglevel = tun_get_msglevel, >>>> .set_msglevel = tun_set_msglevel, >>>> diff --git a/include/uapi/linux/if_tun.h b/include/uapi/linux/if_tun.h >>>> index 50ae243..78a09a7 100644 >>>> --- a/include/uapi/linux/if_tun.h >>>> +++ b/include/uapi/linux/if_tun.h >>>> @@ -66,6 +66,11 @@ >>>> #define IFF_PERSIST 0x0800 >>>> #define IFF_NOFILTER 0x1000 >>>> >>>> +/*add speed control, default 1000M*/ >>>> +#define TUN_CTRL_SPD_10 0x0020 >>>> +#define TUN_CTRL_SPD_100 0x0040 >>>> +#define TUN_CTRL_SPD_1000 0x0080 >>>> + >>>> /* Socket options */ >>>> #define TUN_TX_TIMESTAMP 1 >>>> >>>> -- >>>> 1.9.1 >>>> >>>> -- >>>> To unsubscribe from this list: send the line "unsubscribe netdev" in >>>> the body of a message to majordomo@vger.kernel.org >>>> More majordomo info at http://vger.kernel.org/majordomo-info.html >>> >>> >>> > ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH V2 1/1] tun: change speed from 10M to dynamically configured 2015-02-13 3:35 ` [PATCH V2 1/1] tun: change speed from 10M to dynamically configured Zhu Yanjun 2015-02-13 3:44 ` Jonathon Reinhart @ 2015-02-13 10:37 ` Sergei Shtylyov 1 sibling, 0 replies; 7+ messages in thread From: Sergei Shtylyov @ 2015-02-13 10:37 UTC (permalink / raw) To: Zhu Yanjun, netdev, mst, jasowang, viro, davem Hello. On 2/13/2015 6:35 AM, Zhu Yanjun wrote: > The default speed of normal nic is 1000M while the default speed > of tun is 10M. Now the default speed of tun is changed to 1000M. > And there are 3 options: 10M, 100M and 1000M to the speed of tun. > The command "ethtool -s tun0 speed 10/100/1000" can configure the > speed of tun dynamically. > CC: Michael S. Tsirkin <mst@redhat.com> > CC: Jason Wang <jasowang@redhat.com> > CC: Al Viro <viro@zeniv.linux.org.uk> > Reviewed-by: Sergei Shtylyov <sergei.shtylyov@cogentembedded.com> > Signed-off-by: Zhu Yanjun <Yanjun.Zhu@windriver.com> > --- > drivers/net/tun.c | 42 +++++++++++++++++++++++++++++++++++++++++- > include/uapi/linux/if_tun.h | 5 +++++ > 2 files changed, 46 insertions(+), 1 deletion(-) > diff --git a/drivers/net/tun.c b/drivers/net/tun.c > index 8c8dc16..0ee36f1 100644 > --- a/drivers/net/tun.c > +++ b/drivers/net/tun.c [...] > @@ -2257,9 +2260,18 @@ static struct miscdevice tun_miscdev = { > > static int tun_get_settings(struct net_device *dev, struct ethtool_cmd *cmd) > { > + struct tun_struct *tun = netdev_priv(dev); > + > + /* Get the speed of tun */ > + if (tun->flags & TUN_CTRL_SPD_1000) { > + ethtool_cmd_speed_set(cmd, SPEED_1000); > + } else if (tun->flags & TUN_CTRL_SPD_100) { > + ethtool_cmd_speed_set(cmd, SPEED_100); > + } else > + ethtool_cmd_speed_set(cmd, SPEED_10); I probably missed it in the previous version: {} not needed here at all. Please remove to comply with Documentation/CodingStyle. [...] WBR, Sergei ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2015-02-13 10:38 UTC | newest] Thread overview: 7+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2015-02-13 3:35 [PATCH V2 0/1] tun: dynamically set speed of tun Zhu Yanjun 2015-02-13 3:35 ` [PATCH V2 1/1] tun: change speed from 10M to dynamically configured Zhu Yanjun 2015-02-13 3:44 ` Jonathon Reinhart 2015-02-13 5:31 ` yzhu1 2015-02-13 5:42 ` Jonathon Reinhart 2015-02-13 5:56 ` yzhu1 2015-02-13 10:37 ` Sergei Shtylyov
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).