netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Michal Kubecek <mkubecek@suse.cz>
To: Jie Wang <wangjie125@huawei.com>
Cc: davem@davemloft.net, kuba@kernel.org, netdev@vger.kernel.org,
	huangguangbin2@huawei.com, lipeng321@huawei.com,
	shenjian15@huawei.com, moyufeng@huawei.com,
	linyunsheng@huawei.com, tanhuazhong@huawei.com,
	salil.mehta@huawei.com, chenhao288@hisilicon.com
Subject: Re: [RFC net-next 1/2] net: ethtool: add ethtool ability to set/get fresh device features
Date: Tue, 15 Mar 2022 20:18:23 +0100	[thread overview]
Message-ID: <20220315191823.h3edooqrfevkxfuz@lion.mk-sys.cz> (raw)
In-Reply-To: <20220315032108.57228-2-wangjie125@huawei.com>

[-- Attachment #1: Type: text/plain, Size: 5588 bytes --]

On Tue, Mar 15, 2022 at 11:21:07AM +0800, Jie Wang wrote:
> As tx push is a standard feature for NICs, but netdev_feature which is
> controlled by ethtool -K has reached the maximum specification.
> 
> so this patch adds a pair of new ethtool messages:'ETHTOOL_GDEVFEAT' and
> 'ETHTOOL_SDEVFEAT' to be used to set/get features contained entirely to
> drivers. The message processing functions and function hooks in struct
> ethtool_ops are also added.
> 
> set-devfeatures/show-devfeatures option(s) are designed to provide set
> and get function.
> set cmd:
> root@wj: ethtool --set-devfeatures eth4 tx-push [on | off]
> get cmd:
> root@wj: ethtool --show-devfeatures eth4
> 
> Signed-off-by: Jie Wang <wangjie125@huawei.com>

The consensus is that no new commands should be added to the ioctl
interface. Please implement this via netlink.

Michal

> ---
>  include/linux/ethtool.h      |  4 ++++
>  include/uapi/linux/ethtool.h | 27 ++++++++++++++++++++++
>  net/ethtool/ioctl.c          | 43 ++++++++++++++++++++++++++++++++++++
>  3 files changed, 74 insertions(+)
> 
> diff --git a/include/linux/ethtool.h b/include/linux/ethtool.h
> index 11efc45de66a..1a34bb074720 100644
> --- a/include/linux/ethtool.h
> +++ b/include/linux/ethtool.h
> @@ -750,6 +750,10 @@ struct ethtool_ops {
>  	int	(*set_module_power_mode)(struct net_device *dev,
>  					 const struct ethtool_module_power_mode_params *params,
>  					 struct netlink_ext_ack *extack);
> +	int	(*get_devfeatures)(struct net_device *dev,
> +				   struct ethtool_dev_features *dev_feat);
> +	int	(*set_devfeatures)(struct net_device *dev,
> +				   struct ethtool_dev_features *dev_feat);
>  };
>  
>  int ethtool_check_ops(const struct ethtool_ops *ops);
> diff --git a/include/uapi/linux/ethtool.h b/include/uapi/linux/ethtool.h
> index 7bc4b8def12c..319d7b2c6acb 100644
> --- a/include/uapi/linux/ethtool.h
> +++ b/include/uapi/linux/ethtool.h
> @@ -1490,6 +1490,31 @@ enum ethtool_fec_config_bits {
>  #define ETHTOOL_FEC_BASER		(1 << ETHTOOL_FEC_BASER_BIT)
>  #define ETHTOOL_FEC_LLRS		(1 << ETHTOOL_FEC_LLRS_BIT)
>  
> +/**
> + * struct ethtool_dev_features - device feature configurations
> + * @cmd: Command number = %ETHTOOL_GDEVFEAT or %ETHTOOL_SDEVFEAT
> + * @type: feature configuration type.
> + * @data: feature configuration value.
> + */
> +struct ethtool_dev_features {
> +	__u32 cmd;
> +	__u32 type;
> +	__u32 data;
> +};
> +
> +/**
> + * enum ethtool_dev_features_type - flags definition of ethtool_dev_features
> + * @ETHTOOL_DEV_TX_PUSH: nic tx push mode set bit.
> + */
> +enum ethtool_dev_features_type {
> +	ETHTOOL_DEV_TX_PUSH,
> +	/*
> +	 * Add your fresh feature type above and remember to update
> +	 * feat_line[] in ethtool.c
> +	 */
> +	ETHTOOL_DEV_FEATURE_COUNT,
> +};
> +
>  /* CMDs currently supported */
>  #define ETHTOOL_GSET		0x00000001 /* DEPRECATED, Get settings.
>  					    * Please use ETHTOOL_GLINKSETTINGS
> @@ -1584,6 +1609,8 @@ enum ethtool_fec_config_bits {
>  #define ETHTOOL_PHY_STUNABLE	0x0000004f /* Set PHY tunable configuration */
>  #define ETHTOOL_GFECPARAM	0x00000050 /* Get FEC settings */
>  #define ETHTOOL_SFECPARAM	0x00000051 /* Set FEC settings */
> +#define ETHTOOL_GDEVFEAT	0x00000052 /* Get device features */
> +#define ETHTOOL_SDEVFEAT	0x00000053 /* Set device features */
>  
>  /* compatibility with older code */
>  #define SPARC_ETH_GSET		ETHTOOL_GSET
> diff --git a/net/ethtool/ioctl.c b/net/ethtool/ioctl.c
> index 326e14ee05db..efac23352eb9 100644
> --- a/net/ethtool/ioctl.c
> +++ b/net/ethtool/ioctl.c
> @@ -2722,6 +2722,42 @@ static int ethtool_set_fecparam(struct net_device *dev, void __user *useraddr)
>  	return dev->ethtool_ops->set_fecparam(dev, &fecparam);
>  }
>  
> +static int ethtool_get_devfeatures(struct net_device *dev,
> +				   void __user *useraddr)
> +{
> +	struct ethtool_dev_features dev_feat;
> +	int ret;
> +
> +	if (!dev->ethtool_ops->get_devfeatures)
> +		return -EOPNOTSUPP;
> +
> +	if (copy_from_user(&dev_feat, useraddr, sizeof(dev_feat)))
> +		return -EFAULT;
> +
> +	ret = dev->ethtool_ops->get_devfeatures(dev, &dev_feat);
> +	if (ret)
> +		return ret;
> +
> +	if (copy_to_user(useraddr, &dev_feat, sizeof(dev_feat)))
> +		return -EFAULT;
> +
> +	return 0;
> +}
> +
> +static int ethtool_set_devfeatures(struct net_device *dev,
> +				   void __user *useraddr)
> +{
> +	struct ethtool_dev_features dev_feat;
> +
> +	if (!dev->ethtool_ops->set_devfeatures)
> +		return -EOPNOTSUPP;
> +
> +	if (copy_from_user(&dev_feat, useraddr, sizeof(dev_feat)))
> +		return -EFAULT;
> +
> +	return dev->ethtool_ops->set_devfeatures(dev, &dev_feat);
> +}
> +
>  /* The main entry point in this file.  Called from net/core/dev_ioctl.c */
>  
>  static int
> @@ -2781,6 +2817,7 @@ __dev_ethtool(struct net *net, struct ifreq *ifr, void __user *useraddr,
>  	case ETHTOOL_PHY_GTUNABLE:
>  	case ETHTOOL_GLINKSETTINGS:
>  	case ETHTOOL_GFECPARAM:
> +	case ETHTOOL_GDEVFEAT:
>  		break;
>  	default:
>  		if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
> @@ -3008,6 +3045,12 @@ __dev_ethtool(struct net *net, struct ifreq *ifr, void __user *useraddr,
>  	case ETHTOOL_SFECPARAM:
>  		rc = ethtool_set_fecparam(dev, useraddr);
>  		break;
> +	case ETHTOOL_GDEVFEAT:
> +		rc = ethtool_get_devfeatures(dev, useraddr);
> +		break;
> +	case ETHTOOL_SDEVFEAT:
> +		rc = ethtool_set_devfeatures(dev, useraddr);
> +		break;
>  	default:
>  		rc = -EOPNOTSUPP;
>  	}
> -- 
> 2.33.0
> 

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

  parent reply	other threads:[~2022-03-15 19:18 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-15  3:21 [RFC net-next 0/2] add ethtool ops support for fresh device features Jie Wang
2022-03-15  3:21 ` [RFC net-next 1/2] net: ethtool: add ethtool ability to set/get " Jie Wang
2022-03-15 19:15   ` Jakub Kicinski
2022-03-15 19:56     ` Michal Kubecek
2022-03-16  1:45       ` Jakub Kicinski
2022-03-21  6:17         ` wangjie (L)
2022-03-21 18:20           ` Jakub Kicinski
2022-03-15 20:03     ` Roopa Prabhu
2022-03-16  1:40       ` Jakub Kicinski
2022-03-15 19:18   ` Michal Kubecek [this message]
2022-03-18  6:28     ` wangjie (L)
2022-03-15  3:21 ` [RFC net-next 2/2] net: hns3: add ethtool set/get device features support for hns3 driver Jie Wang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220315191823.h3edooqrfevkxfuz@lion.mk-sys.cz \
    --to=mkubecek@suse.cz \
    --cc=chenhao288@hisilicon.com \
    --cc=davem@davemloft.net \
    --cc=huangguangbin2@huawei.com \
    --cc=kuba@kernel.org \
    --cc=linyunsheng@huawei.com \
    --cc=lipeng321@huawei.com \
    --cc=moyufeng@huawei.com \
    --cc=netdev@vger.kernel.org \
    --cc=salil.mehta@huawei.com \
    --cc=shenjian15@huawei.com \
    --cc=tanhuazhong@huawei.com \
    --cc=wangjie125@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).