Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp1809500pxb; Fri, 6 Nov 2020 22:36:18 -0800 (PST) X-Google-Smtp-Source: ABdhPJz5hbOb1gYWAlF08XGn7ptAcukrHZPaPB5obAt4XvU7YScZyWNKWwXDCMMxv1xlU3e3wUuN X-Received: by 2002:a17:906:a856:: with SMTP id dx22mr5940621ejb.134.1604730977779; Fri, 06 Nov 2020 22:36:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604730977; cv=none; d=google.com; s=arc-20160816; b=faLrSu/0SJ6NHcmpZ6HgfC7Sr2VyPggkWsqJnCG+Fkaw8MPbygXcJP9hA72Ca9PhYT QwISGVdfl/tKCawG2ad88GA3Kq14HqGvFuNdxQBEtWHJpia1DQrPQM3zzvjgoVExcRyg CQj2A9TAaekOEkQCYxEVzT+K/r5yG5Ket20UacsiYvdWQyaWY6w2s9LntFHXMu5Y8h3J pZ8L8aZPxgmMGimk1rmT2HhYyl0or2uLnqIxzv9GtwQ9iF9/wrvpXEUcw6vcC/Y2gq5N wltgBEtv3njzfrrrCz0CSgDfYCFpfueGu1IsBhllSuPIxjOmiMgwqlOq88XhYQFoiQV8 SRCQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from; bh=xXQYARqSU4hgo/jJqr+witSxje1WiIeqBKowussym88=; b=vHDlNQ37fEdUhqETVUImhbt7GcVOzzwcXUy/N6l04hgLaqKT0bnIKWCldi6aIEoeFj E0ArE3JM1jd6JFQSqQcuhnQPhiXJAd/nnJbeXweUwlTZFUgybXR9xpQAx33qChyPqy9J njLre1S6fquxxd4V5qm07WpoeHYg9xswQ1DC0ntqQNNSAERq9QBtJUAzl9tSAI73W4p5 BCEk7Zwjtbt8nXcdtZ6YpbVInwAI/0RXMqLIgDrfh8yz+0lAMqVx0uDE+36+CUUYvmsq ImJ1oxg9gviDeq08uPnBpPVu9gZWflwXaFyArUMmBjVcPeqWVgNG+Zekal/PuFwAyau4 UiMQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dn22si2964504edb.239.2020.11.06.22.35.55; Fri, 06 Nov 2020 22:36:17 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728264AbgKGGbx (ORCPT + 99 others); Sat, 7 Nov 2020 01:31:53 -0500 Received: from szxga04-in.huawei.com ([45.249.212.190]:6756 "EHLO szxga04-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727931AbgKGGbM (ORCPT ); Sat, 7 Nov 2020 01:31:12 -0500 Received: from DGGEMS410-HUB.china.huawei.com (unknown [172.30.72.58]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4CSnT14ff2zkd9t; Sat, 7 Nov 2020 14:31:01 +0800 (CST) Received: from localhost.localdomain (10.69.192.56) by DGGEMS410-HUB.china.huawei.com (10.3.19.210) with Microsoft SMTP Server id 14.3.487.0; Sat, 7 Nov 2020 14:30:59 +0800 From: Huazhong Tan To: CC: , , , , , , Huazhong Tan Subject: [PATCH net-next 08/11] net: hns3: add a check for ethtool priv-flag interface Date: Sat, 7 Nov 2020 14:31:18 +0800 Message-ID: <1604730681-32559-9-git-send-email-tanhuazhong@huawei.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1604730681-32559-1-git-send-email-tanhuazhong@huawei.com> References: <1604730681-32559-1-git-send-email-tanhuazhong@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.69.192.56] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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