mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Huazhong Tan <tanhuazhong@huawei.com>
To: <davem@davemloft.net>
Cc: <netdev@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
	<salil.mehta@huawei.com>, <yisen.zhuang@huawei.com>,
	<linuxarm@huawei.com>, <kuba@kernel.org>,
	Huazhong Tan <tanhuazhong@huawei.com>
Subject: [PATCH V2 net-next 08/11] net: hns3: add a check for ethtool priv-flag interface
Date: Mon, 9 Nov 2020 11:22:36 +0800	[thread overview]
Message-ID: <1604892159-19990-9-git-send-email-tanhuazhong@huawei.com> (raw)
In-Reply-To: <1604892159-19990-1-git-send-email-tanhuazhong@huawei.com>

Add a check for hns3_set_priv_flags() since if the capability
is unsupported its private flags should not be modified as well.

Signed-off-by: Huazhong Tan <tanhuazhong@huawei.com>
---
 drivers/net/ethernet/hisilicon/hns3/hnae3.h        |  1 +
 drivers/net/ethernet/hisilicon/hns3/hns3_enet.c    |  1 +
 drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c | 19 +++++++++++++++++++
 3 files changed, 21 insertions(+)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hnae3.h b/drivers/net/ethernet/hisilicon/hns3/hnae3.h
index 18b3e43..3642740 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hnae3.h
+++ b/drivers/net/ethernet/hisilicon/hns3/hnae3.h
@@ -744,6 +744,7 @@ struct hnae3_handle {
 	/* Network interface message level enabled bits */
 	u32 msg_enable;
 
+	unsigned long supported_pflags;
 	unsigned long priv_flags;
 };
 
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
index f686723..c30cf9e 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
@@ -4152,6 +4152,7 @@ static void hns3_state_init(struct hnae3_handle *handle)
 	set_bit(HNS3_NIC_STATE_INITED, &priv->state);
 	set_bit(HNS3_NIC_STATE_DIM_ENABLE, &priv->state);
 	handle->priv_flags |= BIT(HNAE3_PFLAG_DIM_ENABLE);
+	set_bit(HNAE3_PFLAG_DIM_ENABLE, &handle->supported_pflags);
 }
 
 static int hns3_client_init(struct hnae3_handle *handle)
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c b/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c
index 427b72c..6904c0a 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c
@@ -1561,12 +1561,31 @@ static u32 hns3_get_priv_flags(struct net_device *netdev)
 	return handle->priv_flags;
 }
 
+static int hns3_check_priv_flags(struct hnae3_handle *h, u32 changed)
+{
+	u32 i;
+
+	for (i = 0; i < HNAE3_PFLAG_MAX; i++)
+		if ((changed & BIT(i)) && !test_bit(i, &h->supported_pflags)) {
+			netdev_err(h->netdev, "%s is unsupported\n",
+				   hns3_priv_flags[i].name);
+			return -EOPNOTSUPP;
+		}
+
+	return 0;
+}
+
 static int hns3_set_priv_flags(struct net_device *netdev, u32 pflags)
 {
 	struct hnae3_handle *handle = hns3_get_handle(netdev);
 	u32 changed = pflags ^ handle->priv_flags;
+	int ret;
 	u32 i;
 
+	ret = hns3_check_priv_flags(handle, changed);
+	if (ret)
+		return ret;
+
 	for (i = 0; i < HNAE3_PFLAG_MAX; i++) {
 		if (changed & BIT(i)) {
 			bool enable = !(handle->priv_flags & BIT(i));
-- 
2.7.4


  parent reply	other threads:[~2020-11-09  3:23 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-09  3:22 [PATCH V2 net-next 00/11] net: hns3: updates for -next Huazhong Tan
2020-11-09  3:22 ` [PATCH V2 net-next 01/11] net: hns3: add support for configuring interrupt quantity limiting Huazhong Tan
2020-11-11  1:13   ` Jakub Kicinski
2020-11-11  1:15     ` tanhuazhong
2020-11-09  3:22 ` [PATCH V2 net-next 02/11] net: hns3: add support for querying maximum value of GL Huazhong Tan
2020-11-09  3:22 ` [PATCH V2 net-next 03/11] net: hns3: add support for 1us unit GL configuration Huazhong Tan
2020-11-09  3:22 ` [PATCH V2 net-next 04/11] net: hns3: rename gl_adapt_enable in struct hns3_enet_coalesce Huazhong Tan
2020-11-09  3:22 ` [PATCH V2 net-next 05/11] net: hns3: add support for dynamic interrupt moderation Huazhong Tan
2020-11-11  1:20   ` Jakub Kicinski
2020-11-11  2:31     ` tanhuazhong
2020-11-09  3:22 ` [PATCH V2 net-next 06/11] net: hns3: add ethtool priv-flag for DIM Huazhong Tan
2020-11-09  3:22 ` [PATCH V2 net-next 07/11] net: hns3: add hns3_state_init() to do state initialization Huazhong Tan
2020-11-09  3:22 ` Huazhong Tan [this message]
2020-11-09  3:22 ` [PATCH V2 net-next 09/11] net: hns3: add support for EQ/CQ mode configuration Huazhong Tan
2020-11-11  1:25   ` Jakub Kicinski
2020-11-11  3:03     ` tanhuazhong
2020-11-09  3:22 ` [PATCH V2 net-next 10/11] net: hns3: add ethtool priv-flag for EQ/CQ Huazhong Tan
2020-11-09  3:22 ` [PATCH V2 net-next 11/11] net: hns3: add debugfs support for interrupt coalesce Huazhong Tan
2020-11-11  1:28   ` Jakub Kicinski
2020-11-11  3:16     ` tanhuazhong
2020-11-11 16:15       ` Jakub Kicinski
2020-11-12  0:48         ` tanhuazhong

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=1604892159-19990-9-git-send-email-tanhuazhong@huawei.com \
    --to=tanhuazhong@huawei.com \
    --cc=davem@davemloft.net \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linuxarm@huawei.com \
    --cc=netdev@vger.kernel.org \
    --cc=salil.mehta@huawei.com \
    --cc=yisen.zhuang@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

all inboxes | Powered by JetHome®