Subject: Re: [PATCH 1/1] tun: change speed from 10M to dynamically configured

From: Sergei Shtylyov <[email-masked]>
Date: Thu, 12 Feb 2015 16:52:49 +0300

Hello.

On 2/12/2015 8:35 AM, Zhu Yanjun wrote:

> From: Zhu Yanjun <[email-masked]>

> 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 <[email-masked]>
> CC: Jason Wang <[email-masked]>
> CC: Al Viro <[email-masked]>
> Signed-off-by: Zhu Yanjun <[email-masked]>
> Signed-off-by: Zhu Yanjun <[email-masked]>
> ---
>   drivers/net/tun.c           | 36 +++++++++++++++++++++++++++++++++++-
>   include/uapi/linux/if_tun.h |  5 +++++
>   2 files changed, 40 insertions(+), 1 deletion(-)

> diff --git a/drivers/net/tun.c b/drivers/net/tun.c
> index 8c8dc16..64f4dcc 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*/

    Please add spaces after /* and before */.

[...]
> @@ -2287,6 +2299,27 @@ 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);
> +
> +	if (10 == speed) {
> +		tun->flags &= ~TUN_CTRL_SPD_100;
> +		tun->flags &= ~TUN_CTRL_SPD_1000;

   Can't you clear both bits at once?

> +		tun->flags |= TUN_CTRL_SPD_10;
> +	} else if (100 == speed) {
> +		tun->flags &= ~TUN_CTRL_SPD_10;
> +		tun->flags &= ~TUN_CTRL_SPD_1000;
> +		tun->flags |= TUN_CTRL_SPD_100;
> +	} else {
> +		tun->flags &= ~TUN_CTRL_SPD_10;
> +		tun->flags &= ~TUN_CTRL_SPD_100;
> +		tun->flags |= TUN_CTRL_SPD_1000;
> +	}

    This is asking to be a *switch* statement.

[...]
> 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*/

    Same remark about the comment style as above.

[...]

WBR, Sergei