Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp21182016ybl; Sun, 5 Jan 2020 22:40:41 -0800 (PST) X-Google-Smtp-Source: APXvYqzO9MvHu91zG6ZuV21DX0hPFcniap5cB9pwS2p83cMwWC0/VpjN3mcAPrVOqurFPAHFLMRP X-Received: by 2002:a9d:21f4:: with SMTP id s107mr117165993otb.102.1578292841051; Sun, 05 Jan 2020 22:40:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578292841; cv=none; d=google.com; s=arc-20160816; b=D+ocFxXB2hrRkrj081iCUqh3O1XF/0epxwQmz7QJuGmu+z3jvepl99GtKRQbkZXkei BZyYDw1Lerthig3Un5hgms6sf3rMKhQGNvs0fLr1NJyxNYfqaqJD5ACNU1kBWhkM5hnr KOmKbNJ8Otbg1LnMM0ME/zTKDvDi1qv3LW5VkYueF/Il/NmLuGKHJNOVcLGm/wVEkECC pxHx76i7pmhtyq9Q/O2IhqNFcdL6bgy4LLWKzAN2uPWMjZL4SZOe+gHcTuAv8IwfpPrB JgH4O8iig5v9/11EZFMOTJxzGHbRqhCkOREwrNLB/0Ld5IlPNB+EZH2O16HVhwFxVwAE 9vSQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:date:cc:to:subject:from:references :in-reply-to:message-id; bh=R7HSY2DocZW7eA4h9jTBJRtXXZIlBrY+EnTJG+6VvBs=; b=Yvxo4cbHe7pjCIS5819RGg+F9hxFij9B1xkpsrvDXiXbxDenHs31w5CYElp3jKROSA HMicAOrzBFgcKm+QF5cH/Lld/xYScVhCnjmL01Wnto29d0qbenFofBKpfcnXKyXlcErI E01BOtHBosAz5oIbtTqbKeomS8YSUPpu88nC+Uw5TxO5eTePObEr57qi2OaLGzIc1j7U HTCqAHr+CI2p4c4IgfpB0iGI+BxtYILZpLCuFqswhpbqOJT+FIjYOZTK4jM5ptUVLPAB Y005HHJzTWYGCTZq2X1ONvnjqGTRY5WMuHL/ZuEE+g0jSqPSLa2J+sPDauIwOYEMjRzn 8Q1w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v28si34766917ote.55.2020.01.05.22.40.28; Sun, 05 Jan 2020 22:40:41 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727514AbgAFGjk (ORCPT + 99 others); Mon, 6 Jan 2020 01:39:40 -0500 Received: from mx2.suse.de ([195.135.220.15]:42598 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727496AbgAFGji (ORCPT ); Mon, 6 Jan 2020 01:39:38 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id CC754ADBE; Mon, 6 Jan 2020 06:39:36 +0000 (UTC) Received: by unicorn.suse.cz (Postfix, from userid 1000) id 7E191E048A; Mon, 6 Jan 2020 07:39:36 +0100 (CET) Message-Id: In-Reply-To: References: From: Michal Kubecek Subject: [PATCH net-next v2 2/3] via-velocity: allow nesting of ethtool_ops begin() and complete() To: "David S. Miller" , netdev@vger.kernel.org Cc: Maya Erez , Kalle Valo , linux-wireless@vger.kernel.org, wil6210@qti.qualcomm.com, Francois Romieu , linux-kernel@vger.kernel.org, Andrew Lunn , Florian Fainelli Date: Mon, 6 Jan 2020 07:39:36 +0100 (CET) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Unlike most networking drivers using begin() and complete() ethtool_ops callbacks to resume a device which is down and suspend it again when done, via-velocity does not use standard refcounted infrastructure but sets device sleep state directly. With the introduction of netlink ethtool interface, we may have nested begin-complete blocks so that inner complete() would put the device back to sleep for the rest of the outer block. To avoid rewriting an old and not very actively developed driver, just add a nesting counter and only perform resume and suspend on the outermost level. Signed-off-by: Michal Kubecek --- drivers/net/ethernet/via/via-velocity.c | 14 ++++++++++---- drivers/net/ethernet/via/via-velocity.h | 1 + 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/drivers/net/ethernet/via/via-velocity.c b/drivers/net/ethernet/via/via-velocity.c index 346e44115c4e..4b556b74541a 100644 --- a/drivers/net/ethernet/via/via-velocity.c +++ b/drivers/net/ethernet/via/via-velocity.c @@ -3257,12 +3257,16 @@ static struct platform_driver velocity_platform_driver = { * @dev: network device * * Called before an ethtool operation. We need to make sure the - * chip is out of D3 state before we poke at it. + * chip is out of D3 state before we poke at it. In case of ethtool + * ops nesting, only wake the device up in the outermost block. */ static int velocity_ethtool_up(struct net_device *dev) { struct velocity_info *vptr = netdev_priv(dev); - if (!netif_running(dev)) + + if (vptr->ethtool_ops_nesting == U32_MAX) + return -EBUSY; + if (!vptr->ethtool_ops_nesting++ && !netif_running(dev)) velocity_set_power_state(vptr, PCI_D0); return 0; } @@ -3272,12 +3276,14 @@ static int velocity_ethtool_up(struct net_device *dev) * @dev: network device * * Called after an ethtool operation. Restore the chip back to D3 - * state if it isn't running. + * state if it isn't running. In case of ethtool ops nesting, only + * put the device to sleep in the outermost block. */ static void velocity_ethtool_down(struct net_device *dev) { struct velocity_info *vptr = netdev_priv(dev); - if (!netif_running(dev)) + + if (!--vptr->ethtool_ops_nesting && !netif_running(dev)) velocity_set_power_state(vptr, PCI_D3hot); } diff --git a/drivers/net/ethernet/via/via-velocity.h b/drivers/net/ethernet/via/via-velocity.h index cdfe7809e3c1..f196e71d2c04 100644 --- a/drivers/net/ethernet/via/via-velocity.h +++ b/drivers/net/ethernet/via/via-velocity.h @@ -1483,6 +1483,7 @@ struct velocity_info { struct velocity_context context; u32 ticks; + u32 ethtool_ops_nesting; u8 rev_id; -- 2.24.1