Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp5312047pxv; Wed, 21 Jul 2021 02:22:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyfOIRU9WZLrI6b9YPTF00BVknRIzJ2sddQ09Uh3+bI+BZgeKNmyTxXXAzObl3xLxxPX9RV X-Received: by 2002:a6b:b883:: with SMTP id i125mr26630520iof.104.1626859366938; Wed, 21 Jul 2021 02:22:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626859366; cv=none; d=google.com; s=arc-20160816; b=s6fU8S7JlGoZhiDA/ZVWxIN0kVaObHZuUuVyMtuXwl+SUb3eStaQaIPUl49Zpu1LVB msM7ZScPJcrK15x2tEMZN+I5IfkrPIPZ0OvNCNAO6wGtc+HZMaoICUvCnISKF2ihza36 3Mmp9JCNVZN807/di6XCQuXAQMe4743wqkBhbPKCyWHTNAcIGOgx8rRe17R3t8KDeOUg Ku0XFY67hzEODcBHVSWB/k3RC3RQOCuf4/twlm7c9J6cvyph36imq30+ncUKruNDvZO4 Kqw7bBrAp3YwM6GCRhYOu60KBs2PE1wPr75TF/rvY0tKIfHrFNdhnEv/HJk58did5r+y 1k+g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=3tLrXGVtqSGB66n7TTgK+8G814NK5VZ5XrNu0eRoh5U=; b=B+P7BWSKrgDaANM+EzcgkEwNlzdajpRaWW28GBhmKnuhWyIs+2bKnjTNz+h2vylMu7 SlCFVDxj0a7ED4SmxOJK08qbE/8VqQCaji/7J1VQS3ygbpRMFn61LOcUUaZjuy+k0YvD jRwxV4vTzI1v6uBA1lhIzmD5hpMlnaf2qfBz6nt5b/QcaveJSLGNHVXk4dK+uB56JeFs Y5SoRexfQ+Wnow9GS35bVggVhnoYWow6Sfwb78lJ396/DgSafJ3bXq5xK8q7gMWRNieq VrBSesfRBVXTD6Je0J4lC0+mwVvXLRbQizHisnOccH/q8qXiS0Aud9nl9q6Bf4Hv9pJ6 2Mhw== 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 k25si15968254jan.106.2021.07.21.02.22.35; Wed, 21 Jul 2021 02:22:46 -0700 (PDT) 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 S237992AbhGUIjh (ORCPT + 99 others); Wed, 21 Jul 2021 04:39:37 -0400 Received: from lucky1.263xmail.com ([211.157.147.133]:51090 "EHLO lucky1.263xmail.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236744AbhGUI1z (ORCPT ); Wed, 21 Jul 2021 04:27:55 -0400 Received: from localhost (unknown [192.168.167.70]) by lucky1.263xmail.com (Postfix) with ESMTP id AA31CD604A; Wed, 21 Jul 2021 17:07:58 +0800 (CST) X-MAIL-GRAY: 0 X-MAIL-DELIVERY: 1 X-ADDR-CHECKED4: 1 X-SKE-CHECKED: 1 X-ANTISPAM-LEVEL: 2 Received: from localhost.localdomain (unknown [113.57.152.160]) by smtp.263.net (postfix) whith ESMTP id P13644T140561998673664S1626858476493763_; Wed, 21 Jul 2021 17:07:57 +0800 (CST) X-IP-DOMAINF: 1 X-UNIQUE-TAG: <677266e43cc6ebe63ae9c4eeb930a4f8> X-RL-SENDER: chenhaoa@uniontech.com X-SENDER: chenhaoa@uniontech.com X-LOGIN-NAME: chenhaoa@uniontech.com X-FST-TO: peppe.cavallaro@st.com X-RCPT-COUNT: 12 X-SENDER-IP: 113.57.152.160 X-ATTACHMENT-NUM: 0 X-System-Flag: 0 From: Hao Chen To: peppe.cavallaro@st.com Cc: alexandre.torgue@foss.st.com, joabreu@synopsys.com, davem@davemloft.net, kuba@kernel.org, mcoquelin.stm32@gmail.com, linux@armlinux.org.uk, netdev@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-kernel@vger.kernel.org, qiangqing.zhang@nxp.com, Hao Chen Subject: [net,v6] net: stmmac: fix 'ethtool -P' return -EBUSY Date: Wed, 21 Jul 2021 17:07:14 +0800 Message-Id: <20210721090714.17416-1-chenhaoa@uniontech.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org I want to get permanent MAC address when the card is down. And I think it is more convenient to get statistics in the down state by 'ethtool -S'. But current all of the ethool command return -EBUSY. I don't think we should detect that the network card is up in '. Begin', which will cause that all the ethtool commands can't be used when the network card is down. If some ethtool commands can only be used in the up state, check it in the corresponding ethool OPS function is better. This is too rude and unreasonable. I have checked the '. Begin' implementation of other drivers, most of which support the submission of NIC driver for the first time. They are too old to know why '. Begin' is implemented. I suspect that they have not noticed the usage of '. Begin'. Fixes: 47dd7a540b8a ("net: add support for STMicroelectronics Ethernet controllers.") Compile-tested on arm64. Tested on an arm64 system with an on-board STMMAC chip. Changes v5 ... v6: - The 4.19.90 kernel not support pm_runtime, so implemente '.begin' and '.complete' again. Add return value check of pm_runtime function. Changes v4 ... v5: - test the '.begin' will return -13 error on my machine based on 4.19.90 kernel. The platform driver does not supported pm_runtime. So remove the implementation of '.begin' and '.complete'. Changes v3 ... v4: - implement '.complete' ethtool OPS. Changes v2 ... v3: - add linux/pm_runtime.h head file. Changes v1 ... v2: - fix spell error of dev. Signed-off-by: Hao Chen --- .../ethernet/stmicro/stmmac/stmmac_ethtool.c | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c index d0ce608b81c3..e969bde36507 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c @@ -12,8 +12,9 @@ #include #include #include -#include #include +#include +#include #include #include "stmmac.h" @@ -410,11 +411,18 @@ static void stmmac_ethtool_setmsglevel(struct net_device *dev, u32 level) } -static int stmmac_check_if_running(struct net_device *dev) +static int stmmac_ethtool_begin(struct net_device *dev) { - if (!netif_running(dev)) - return -EBUSY; - return 0; + struct stmmac_priv *priv = netdev_priv(dev); + + return pm_runtime_resume_and_get(dev); +} + +static void stmmac_ethtool_complete(struct net_device *dev) +{ + struct stmmac_priv *priv = netdev_priv(dev); + + pm_runtime_put(priv->device); } static int stmmac_ethtool_get_regs_len(struct net_device *dev) @@ -1073,7 +1081,8 @@ static int stmmac_set_tunable(struct net_device *dev, static const struct ethtool_ops stmmac_ethtool_ops = { .supported_coalesce_params = ETHTOOL_COALESCE_USECS | ETHTOOL_COALESCE_MAX_FRAMES, - .begin = stmmac_check_if_running, + .begin = stmmac_ethtool_begin, + .complete = stmmac_ethtool_complete, .get_drvinfo = stmmac_ethtool_getdrvinfo, .get_msglevel = stmmac_ethtool_getmsglevel, .set_msglevel = stmmac_ethtool_setmsglevel, -- 2.20.1