netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jie Wang <wangjie125@huawei.com>
To: <mkubecek@suse.cz>, <davem@davemloft.net>, <kuba@kernel.org>,
	<wangjie125@huawei.com>
Cc: <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: [RFC net-next 2/2] net: hns3: add ethtool set/get device features support for hns3 driver
Date: Tue, 15 Mar 2022 11:21:08 +0800	[thread overview]
Message-ID: <20220315032108.57228-3-wangjie125@huawei.com> (raw)
In-Reply-To: <20220315032108.57228-1-wangjie125@huawei.com>

This patch implements hns3 set_devfeatures/get_devfeatures hooks defined
in struct ethtool_ops.

Signed-off-by: Jie Wang <wangjie125@huawei.com>
---
 drivers/net/ethernet/hisilicon/hns3/hnae3.h   |  1 +
 .../ethernet/hisilicon/hns3/hns3_ethtool.c    | 77 +++++++++++++++++++
 2 files changed, 78 insertions(+)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hnae3.h b/drivers/net/ethernet/hisilicon/hns3/hnae3.h
index 9298fbecb31a..9ae5b3318dc4 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hnae3.h
+++ b/drivers/net/ethernet/hisilicon/hns3/hnae3.h
@@ -817,6 +817,7 @@ struct hnae3_roce_private_info {
 
 enum hnae3_pflag {
 	HNAE3_PFLAG_LIMIT_PROMISC,
+	HNAE3_PFLAG_PUSH_ENABLE,
 	HNAE3_PFLAG_MAX
 };
 
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c b/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c
index c06c39ece80d..7ad141aed3aa 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c
@@ -1925,6 +1925,79 @@ static int hns3_get_link_ext_state(struct net_device *netdev,
 	return -ENODATA;
 }
 
+static int hns3_set_tx_push(struct net_device *netdev,
+			    struct ethtool_dev_features *dev_feat)
+{
+	struct hns3_nic_priv *priv = netdev_priv(netdev);
+	struct hnae3_handle *h = hns3_get_handle(netdev);
+	struct hnae3_ae_dev *ae_dev = pci_get_drvdata(h->pdev);
+
+	if (!test_bit(HNAE3_DEV_SUPPORT_TX_PUSH_B, ae_dev->caps))
+		return -EOPNOTSUPP;
+
+	if (dev_feat->data)
+		set_bit(HNAE3_PFLAG_PUSH_ENABLE, &priv->state);
+	else
+		clear_bit(HNAE3_PFLAG_PUSH_ENABLE, &priv->state);
+
+	return 0;
+}
+
+static int hns3_set_devfeatures(struct net_device *netdev,
+				struct ethtool_dev_features *dev_feat)
+{
+	struct set_proto {
+		u64 type;
+		int (*set_func)(struct net_device *dev,
+				struct ethtool_dev_features *feat);
+	} set_arr[] = {
+		{ ETHTOOL_DEV_TX_PUSH, hns3_set_tx_push },
+	};
+	unsigned int i;
+
+	for (i = 0; i < ARRAY_SIZE(set_arr); ++i) {
+		if (set_arr[i].type == dev_feat->type && set_arr[i].set_func)
+			return set_arr[i].set_func(netdev, dev_feat);
+	}
+
+	return -EINVAL;
+}
+
+static int hns3_get_tx_push(struct net_device *netdev,
+			    struct ethtool_dev_features *dev_feat)
+{
+	struct hns3_nic_priv *priv = netdev_priv(netdev);
+	struct hnae3_handle *h = hns3_get_handle(netdev);
+	struct hnae3_ae_dev *ae_dev = pci_get_drvdata(h->pdev);
+
+	if (!test_bit(HNAE3_DEV_SUPPORT_TX_PUSH_B, ae_dev->caps))
+		return -EOPNOTSUPP;
+
+	dev_feat->data = test_bit(HNAE3_PFLAG_PUSH_ENABLE, &priv->state);
+
+	return 0;
+}
+
+static int hns3_get_devfeatures(struct net_device *netdev,
+				struct ethtool_dev_features *dev_feat)
+{
+	struct get_proto {
+		u32 type;
+		int (*get_func)(struct net_device *netdev,
+				struct ethtool_dev_features *feat);
+	} get_arr[] = {
+		{ ETHTOOL_DEV_TX_PUSH, hns3_get_tx_push },
+	};
+	unsigned int i;
+
+	for (i = 0; i < ARRAY_SIZE(get_arr); ++i) {
+		if (get_arr[i].type == dev_feat->type && get_arr[i].get_func)
+			return get_arr[i].get_func(netdev, dev_feat);
+	}
+
+	return -EINVAL;
+}
+
 static const struct ethtool_ops hns3vf_ethtool_ops = {
 	.supported_coalesce_params = HNS3_ETHTOOL_COALESCE,
 	.supported_ring_params = HNS3_ETHTOOL_RING,
@@ -1955,6 +2028,8 @@ static const struct ethtool_ops hns3vf_ethtool_ops = {
 	.get_tunable = hns3_get_tunable,
 	.set_tunable = hns3_set_tunable,
 	.reset = hns3_set_reset,
+	.get_devfeatures = hns3_get_devfeatures,
+	.set_devfeatures = hns3_set_devfeatures,
 };
 
 static const struct ethtool_ops hns3_ethtool_ops = {
@@ -1999,6 +2074,8 @@ static const struct ethtool_ops hns3_ethtool_ops = {
 	.set_tunable = hns3_set_tunable,
 	.reset = hns3_set_reset,
 	.get_link_ext_state = hns3_get_link_ext_state,
+	.get_devfeatures = hns3_get_devfeatures,
+	.set_devfeatures = hns3_set_devfeatures,
 };
 
 void hns3_ethtool_set_ops(struct net_device *netdev)
-- 
2.33.0


      parent reply	other threads:[~2022-03-15  3:27 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
2022-03-18  6:28     ` wangjie (L)
2022-03-15  3:21 ` Jie Wang [this message]

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=20220315032108.57228-3-wangjie125@huawei.com \
    --to=wangjie125@huawei.com \
    --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=mkubecek@suse.cz \
    --cc=moyufeng@huawei.com \
    --cc=netdev@vger.kernel.org \
    --cc=salil.mehta@huawei.com \
    --cc=shenjian15@huawei.com \
    --cc=tanhuazhong@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).