Received: by 2002:a05:6a10:c7c6:0:0:0:0 with SMTP id h6csp2093847pxy; Mon, 2 Aug 2021 19:25:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwJVHjKdZ4mi5dLe3ZLIZyHWSuN9Hu8+UvgYrdBBG4MdMbCthu1jg2zFENplZAvIdTQml9e X-Received: by 2002:a50:d749:: with SMTP id i9mr3178edj.248.1627957553033; Mon, 02 Aug 2021 19:25:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627957553; cv=none; d=google.com; s=arc-20160816; b=g3Wm6oU2mnqhNchCEZsvHzf8xXqp1Px9KUWjgd/El2ZZ+BqFMtuO9QHmz3SYYpYY1c bkrXsrYlSUVnXWLXb8iwmrJHJXD54iS1sqPurYX2gwSJ5jJqDcy/3Zp0HzlHXo+N/fD0 jFh+OdIukv7FOuuURO2X5oM/vij/Ee99UAriyltj8NxSNE8rRLTfufpzgpqRviGkQbrh UrIFPeGpB7sNrAfzxmNVapCX92u6L9UNsgztlR1NJ/o9+UJpNFHBDd5yfzdA8kM2rU71 5DzKUED6qmtL1NGZPAFFV9LnIypwVUM+9HhgxMQj/6TEjC/issGbdzNFoaGuZxieeexc Zh7Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:feedback-id:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from; bh=HvsPoYg4ExPp7Xfmcrc5iuF/YUO6ktq2mc/LsNRb1KU=; b=E/MgtwuMwlYmcKL8JRvYee2LgPYzr+7+0ojZP+KfgF5pEMi1B45sZJqWRWoK9f8Pjm 8JvRyTIqRUiO4FHjGXzK32k1lrOblkNoN1GPZabzC+JirF+leSxJvyBRdsX0kXKo4cEl ukSQ4h8AUuB+M6hKzIj6RD2nnb0tJKIxg5TPFA8f9owOE3epLCUYoWMtfxKvVlcQnvOt RBLv3GKibOfHr75gj9LKPP9Dk7zgX3MIJ81Aqcjgo7G33+qjsDPaRlCkRpGXXIr/nKrL p9c03cqdgHuZf5CT6zxi/78TR18z/pAwMOcazCfA85cz1W11Tcw03e8reqqlyJJFdwjZ +EEw== 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 c90si12068350edf.274.2021.08.02.19.25.29; Mon, 02 Aug 2021 19:25:53 -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 S233197AbhHCCYS (ORCPT + 99 others); Mon, 2 Aug 2021 22:24:18 -0400 Received: from smtpbgsg1.qq.com ([54.254.200.92]:44960 "EHLO smtpbgsg1.qq.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233619AbhHCCYQ (ORCPT ); Mon, 2 Aug 2021 22:24:16 -0400 X-QQ-mid: bizesmtp42t1627957400teqn1yb4 Received: from localhost.localdomain (unknown [113.57.152.160]) by esmtp6.qq.com (ESMTP) with id ; Tue, 03 Aug 2021 10:23:19 +0800 (CST) X-QQ-SSF: 0140000000200050B000B00A0000000 X-QQ-FEAT: Ry58bBY793vwWAmJfkkzlbE2CLg2irVtpec/fjDR8hPwID05wka8DM9dg5hOr 0zAAEZrr2zpmw0bXWXaiYMdYrRGBtwkowaeYyIPdBTSzK2BlqU+CO1SCIZIw5INnlk7wGs+ EwR2IdSuiv6H6cec7ctlYCRoZ4cJdEpyGPzccJuS6ur/WkIYR8N1gGVkj6wWuin8zxDWfsL 8DgD+AoX+XUZmYqzbfJQYObD9UMvIC9RTPNFnC+ylUmTy8nVQ3r+SOnbqtoQLzsFN+Xnaq9 F0RzcbFHG8KdOzSoE1ZN5ZypC+Qu8Fl6d6T/kvhMrS2xqj66duWPNmWzWVX12SgHz4T/cOu KQ7fa4rpHOeb72O1Kfozch2aL37+RfAGFNcnXLs+Oul4NNh3YE= X-QQ-GoodBg: 2 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, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, Hao Chen Subject: [net-next,v8] net: stmmac: optimize check in ops '.begin' Date: Tue, 3 Aug 2021 10:22:32 +0800 Message-Id: <20210803022232.23145-1-chenhaoa@uniontech.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:uniontech.com:qybgforeign:qybgforeign7 X-QQ-Bgrelay: 1 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org I want to get permanent MAC address when the interface 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 check that the network interface is up in '.begin', which will cause that all the ethtool commands can't be used when the network interface 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. Compile-tested on arm64. Tested on an arm64 system with an on-board STMMAC chip. Changes v7 ... v8: - Optimize commit description information, optimization parameters of pm_runtime function. Changes v6 ... v7: - fix arg type error of 'dev' to 'priv->device'. 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 | 17 +++++++++++------ 1 file changed, 11 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..8e2ae0ff7f8f 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,14 @@ 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; + return pm_runtime_resume_and_get(dev->dev); +} + +static void stmmac_ethtool_complete(struct net_device *dev) +{ + pm_runtime_put(dev->dev); } static int stmmac_ethtool_get_regs_len(struct net_device *dev) @@ -1073,7 +1077,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