Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp2064237pxb; Mon, 18 Jan 2021 07:21:21 -0800 (PST) X-Google-Smtp-Source: ABdhPJw+5o4H+H3uztZ1aUVYMB2v6pswDlaj0P8IU9LUd4mmMeFFnPBBoNU3OXzkR0FDKazBuo/w X-Received: by 2002:a17:906:e48:: with SMTP id q8mr137500eji.478.1610983281109; Mon, 18 Jan 2021 07:21:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610983281; cv=none; d=google.com; s=arc-20160816; b=OM7D5vsXEA1wKBObDmYpuZekBwOC5G61TYkSsqOtW/I2Sz3QNON0qvD6fHWNXw7to3 8yKWoczUo/ST1eM7mIVylP5EqGPH5Y7T/j2uiHuPxeXnXVkNCzDU1bye/48gD45CsBH+ sPvgxxCztheuN4Az/6m2cUvx1p6z4dHsfaEXbrt1goHbdHl94J6Z3tbXNntnnhYEQqjI tAdLtqPO+NI5sT2CWKTlAIUUBlY01oNlfooUsXMGgh3U/C9awXY7uSjZHw1p3ytYOJ1l DJrvqWC/sK8azQu8I/7PFkA59UXHyxF5Nw2KP88k7rN7xwi+9kGna0N5Cg0V1GiY1xnE uS5w== 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=LcFAvKUqSCPpp9+FHhQenrfNTPD7MgLNMUBI+nXF1qs=; b=aRji506fdOcfxzc9Xp2YEhiJo9/CxXAPnzlYCImM2o3kUdDRCytd+vxBYfIsh+mCqv QXrz6qokuS9OoJhBp0sEOPcgkn4P94j8WsCWXJckGsF/c9aRnYW4WdDFTiEiAsp8OhtB urAcF64lKaibt2m3me2oRTr+zHCcBfLSq9hO4pU7Edut84C9/39jQ7hv+Io+6k8xQu1H 18/1dfi3lAOzOw6JTnRR7+VL9oupj13a5dA+gWdDC7uCsvn0us87U9bUREhhFbU952n8 x5WNv8eZ4chlG6k1Egn1J+pCxUapka1peX7MrZp7kjSaiWOcLcZD6HS7SPaxURHKdNil IXpw== 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 b1si7590475ejb.401.2021.01.18.07.20.56; Mon, 18 Jan 2021 07:21:21 -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 S2404996AbhARPSe (ORCPT + 99 others); Mon, 18 Jan 2021 10:18:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34338 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2405414AbhARPJm (ORCPT ); Mon, 18 Jan 2021 10:09:42 -0500 Received: from laurent.telenet-ops.be (laurent.telenet-ops.be [IPv6:2a02:1800:110:4::f00:19]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 599E2C061574 for ; Mon, 18 Jan 2021 07:09:01 -0800 (PST) Received: from ramsan.of.borg ([84.195.186.194]) by laurent.telenet-ops.be with bizsmtp id JF8z2400T4C55Sk01F8zQZ; Mon, 18 Jan 2021 16:08:59 +0100 Received: from rox.of.borg ([192.168.97.57]) by ramsan.of.borg with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1l1W9L-004cql-1j; Mon, 18 Jan 2021 16:08:59 +0100 Received: from geert by rox.of.borg with local (Exim 4.93) (envelope-from ) id 1l1W9K-003LKg-LI; Mon, 18 Jan 2021 16:08:58 +0100 From: Geert Uytterhoeven To: Steve Glendinning , "David S . Miller" , Jakub Kicinski Cc: netdev@vger.kernel.org, linux-renesas-soc@vger.kernel.org, linux-kernel@vger.kernel.org, Geert Uytterhoeven Subject: [PATCH] net: smsc911x: Make Runtime PM handling more fine-grained Date: Mon, 18 Jan 2021 16:08:57 +0100 Message-Id: <20210118150857.796943-1-geert+renesas@glider.be> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Currently the smsc911x driver has mininal power management: during driver probe, the device is powered up, and during driver remove, it is powered down. Improve power management by making it more fine-grained: 1. Power the device down when driver probe is finished, 2. Power the device (down) when it is opened (closed), 3. Make sure the device is powered during PHY access. Signed-off-by: Geert Uytterhoeven --- Tested on r8a73a4/ape6evm, where the LAN9220 is connected to a power-managed bus, and any attempt to access a device register while the device is suspended will trigger an asynchronous external abort. --- drivers/net/ethernet/smsc/smsc911x.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/smsc/smsc911x.c b/drivers/net/ethernet/smsc/smsc911x.c index 823d9a7184fe6aa1..606c79de93a68146 100644 --- a/drivers/net/ethernet/smsc/smsc911x.c +++ b/drivers/net/ethernet/smsc/smsc911x.c @@ -557,6 +557,7 @@ static int smsc911x_mii_read(struct mii_bus *bus, int phyaddr, int regidx) unsigned int addr; int i, reg; + pm_runtime_get_sync(bus->parent); spin_lock_irqsave(&pdata->mac_lock, flags); /* Confirm MII not busy */ @@ -582,6 +583,7 @@ static int smsc911x_mii_read(struct mii_bus *bus, int phyaddr, int regidx) out: spin_unlock_irqrestore(&pdata->mac_lock, flags); + pm_runtime_put(bus->parent); return reg; } @@ -594,6 +596,7 @@ static int smsc911x_mii_write(struct mii_bus *bus, int phyaddr, int regidx, unsigned int addr; int i, reg; + pm_runtime_get_sync(bus->parent); spin_lock_irqsave(&pdata->mac_lock, flags); /* Confirm MII not busy */ @@ -623,6 +626,7 @@ static int smsc911x_mii_write(struct mii_bus *bus, int phyaddr, int regidx, out: spin_unlock_irqrestore(&pdata->mac_lock, flags); + pm_runtime_put(bus->parent); return reg; } @@ -1589,6 +1593,8 @@ static int smsc911x_open(struct net_device *dev) int retval; int irq_flags; + pm_runtime_get_sync(dev->dev.parent); + /* find and start the given phy */ if (!dev->phydev) { retval = smsc911x_mii_probe(dev); @@ -1735,6 +1741,7 @@ static int smsc911x_open(struct net_device *dev) phy_disconnect(dev->phydev); dev->phydev = NULL; out: + pm_runtime_put(dev->dev.parent); return retval; } @@ -1766,6 +1773,7 @@ static int smsc911x_stop(struct net_device *dev) dev->phydev = NULL; } netif_carrier_off(dev); + pm_runtime_put(dev->dev.parent); SMSC_TRACE(pdata, ifdown, "Interface stopped"); return 0; @@ -2334,7 +2342,6 @@ static int smsc911x_drv_remove(struct platform_device *pdev) free_netdev(dev); - pm_runtime_put(&pdev->dev); pm_runtime_disable(&pdev->dev); return 0; @@ -2540,6 +2547,7 @@ static int smsc911x_drv_probe(struct platform_device *pdev) } spin_unlock_irq(&pdata->mac_lock); + pm_runtime_put(&pdev->dev); netdev_info(dev, "MAC Address: %pM\n", dev->dev_addr); -- 2.25.1