Received: by 2002:a05:7412:98c1:b0:fa:551:50a7 with SMTP id kc1csp10540rdb; Fri, 5 Jan 2024 00:30:37 -0800 (PST) X-Google-Smtp-Source: AGHT+IFEWFP0aaNSDZ062FNy5XV2BjTUE8zQKYzm7vpx1ll4rA1c4VBIlNJmhoW0zEMacW1grhS9 X-Received: by 2002:a17:907:268a:b0:a28:d287:90a8 with SMTP id bn10-20020a170907268a00b00a28d28790a8mr1144982ejc.50.1704443436960; Fri, 05 Jan 2024 00:30:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704443436; cv=none; d=google.com; s=arc-20160816; b=QB0F3h71UOBDatI4V+Ms9ogXqZnwWvpr69fPOGKYDsSiTZW/fBiRD1i9YGa49owA6V JrHAR5KgseG2FU+8AOdTSOe1Vc2fxTsi0XlNHz1a28guYh+au1oP/zFa5MLM1HjQNewH F3OOZKzgqYe+Nhbza/+NXTOqqth6dNV0E12lywsnunVunbFN0RAmX6w4Xv/+Ng9FP95Y vQ6GJES5Ek6zqndIivo0FRKwWbV5Koqlxu+hzGNose92AonBWWagMt5JmzB/YZfzWLR5 900VvumH1aEva/Gqv5FwcCNl4RiU/NQpc4bh0M7Ne9tUSdUkEPfAZVt3QhpZpZlfTy7p XwxA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=D52HtaDyG1yQmVNxfMf3+ZvDLZVTUO44eFJ4THAqFfQ=; fh=qryrdWWtksp4Ojh0keXejXriHeHARah4mOGZkuZ1jnk=; b=ElL8fMrPYosTZlnBFB/QMcvwzu+fBeDP7pEOzu973EDgo8Lm+xRfssiy9xucGOeHi/ ew8EVfNdtuwpiHLjM2tNgT2Yd16PTdWnH7iGmrIjGTFiSmh4gENv96w5N2qCT+wLh2Cc 2n7JWJgpPzlw3pGNlQGvNUDeGoljQt/MyFrZABL4sNu2rzM/h8kk9cSiYSUWFYFV8Zog jzilF78T13CuHWw2wmFihmU4xXITNyx8cRum6Eutb1SddxiWKi7zCT3UXNOQgAWnvPVd E2feWIXAEnuMlb2GpjMUKWY3U23rzhgzHs9RdtaTGw7llSg4OEpgEAvmWYBeiJqM7ufd AuTg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@tuxon.dev header.s=google header.b=lfFQt1IV; spf=pass (google.com: domain of linux-kernel+bounces-17598-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-17598-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id gh6-20020a1709073c0600b00a234530a56csi394048ejc.393.2024.01.05.00.30.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Jan 2024 00:30:36 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-17598-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@tuxon.dev header.s=google header.b=lfFQt1IV; spf=pass (google.com: domain of linux-kernel+bounces-17598-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-17598-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 7F8EE1F23BCD for ; Fri, 5 Jan 2024 08:30:36 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AB5FB31755; Fri, 5 Jan 2024 08:25:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=tuxon.dev header.i=@tuxon.dev header.b="lfFQt1IV" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-ej1-f41.google.com (mail-ej1-f41.google.com [209.85.218.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 502C331734 for ; Fri, 5 Jan 2024 08:25:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=tuxon.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=tuxon.dev Received: by mail-ej1-f41.google.com with SMTP id a640c23a62f3a-a28ac851523so155006866b.0 for ; Fri, 05 Jan 2024 00:25:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tuxon.dev; s=google; t=1704443129; x=1705047929; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=D52HtaDyG1yQmVNxfMf3+ZvDLZVTUO44eFJ4THAqFfQ=; b=lfFQt1IVBbUjxJzX7wU88vnF+faewzzYXcdtenrNORr6NHzk1P5lLd6wYrwnA25cwc hAS7yxXkaNpXDxEuyZIuSmAmIXWixm1QBXYi9q1Y7saCa7FAm50EWKvNc35AXEwTk20N 78XDUUjysSz76c0JSCef8DMznILqaciOV3aHub5YYts3Yjxe39+rKdyLRBr+dcWhO0I3 VQFL9HAt+AyFmiLafdXtaoKMYtsL9J/rK9xDPDstfGfMSdbEKCcpJFHTTYUwSDOJGRry G32qO9mbPQcirQY9h1GmavC8rLU49GZWlk2ByRKEghpMAgtbz9axtRqdrCx4XhYypJex oGfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704443129; x=1705047929; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=D52HtaDyG1yQmVNxfMf3+ZvDLZVTUO44eFJ4THAqFfQ=; b=kIlX8+NCfB9ykk8J/Tuo+kTgFdZYepbzKo2MA2L/RJzG8noEoaO+rOHVWGWqd6zHVc EWL/O2P8zq5JEkV30h2nX3L72d6U7z7EBVqnlC1kfs/aIHZErH64MGJ2Q7prCkBCfyCf 7BDI8Sj1il3LZE89kc8vPPLNgVqRWeemixxuxM0RXkr7RDioRX011OCJvJWE+XK5k5HC qKRWMPRCoT1Xjb2hpFp2+mGI9z1Ucpq+JaS6lQy6AGdscrArHWut5c2AARxjz534jxfe jRHzdcxDwCAB3gI7MJK8CHWGmTqv03A29Ev5+Xc5nLIk3qaNKp3m5VheVmE6QydvB5H7 4vug== X-Gm-Message-State: AOJu0Yz6/R+B9E4pCVn3E1jt7GSSadJoA7b2Q54YOg0CQmseu/06LWAZ S1ltYxb/PTbDj/aYbt44aiR/aHIl4sy77w== X-Received: by 2002:a17:906:4554:b0:a28:b6a5:a26b with SMTP id s20-20020a170906455400b00a28b6a5a26bmr1003355ejq.141.1704443129678; Fri, 05 Jan 2024 00:25:29 -0800 (PST) Received: from claudiu-X670E-Pro-RS.. ([82.78.167.5]) by smtp.gmail.com with ESMTPSA id j15-20020a1709064b4f00b00a28e759a447sm596198ejv.213.2024.01.05.00.25.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Jan 2024 00:25:29 -0800 (PST) From: Claudiu X-Google-Original-From: Claudiu To: s.shtylyov@omp.ru, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, richardcochran@gmail.com, p.zabel@pengutronix.de, yoshihiro.shimoda.uh@renesas.com, wsa+renesas@sang-engineering.com Cc: netdev@vger.kernel.org, linux-renesas-soc@vger.kernel.org, linux-kernel@vger.kernel.org, claudiu.beznea@tuxon.dev, geert+renesas@glider.be, Claudiu Beznea Subject: [PATCH net-next v3 19/19] net: ravb: Add runtime PM support Date: Fri, 5 Jan 2024 10:23:39 +0200 Message-Id: <20240105082339.1468817-20-claudiu.beznea.uj@bp.renesas.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240105082339.1468817-1-claudiu.beznea.uj@bp.renesas.com> References: <20240105082339.1468817-1-claudiu.beznea.uj@bp.renesas.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Claudiu Beznea Add runtime PM support for the ravb driver. As the driver is used by different IP variants, with different behaviors, to be able to have the runtime PM support available for all devices, the preparatory commits moved all the resources parsing and allocations in the driver's probe function and kept the settings for ravb_open(). This is due to the fact that on some IP variants-platforms tuples disabling/enabling the clocks will switch the IP to the reset operation mode where registers' content is lost and reconfiguration needs to be done. For this the rabv_open() function enables the clocks, switches the IP to configuration mode, applies all the registers settings and switches the IP to the operational mode. At the end of ravb_open() IP is ready to send/receive data. In ravb_close() necessary reverts are done (compared with ravb_open()), the IP is switched to reset mode and clocks are disabled. The ethtool APIs or IOCTLs that might execute while the interface is down are either cached (and applied in ravb_open()) or rejected (as at that time the IP is in reset mode). Keeping the IP in the reset mode also increases the power saved (according to the hardware manual). Reviewed-by: Sergey Shtylyov Signed-off-by: Claudiu Beznea --- Changes in v3: - this was patch 21/21 in v2 - collected tags - fixed typos in patch description Changes in v2: - keep RPM support for all platforms drivers/net/ethernet/renesas/ravb_main.c | 54 ++++++++++++++++++++++-- 1 file changed, 50 insertions(+), 4 deletions(-) diff --git a/drivers/net/ethernet/renesas/ravb_main.c b/drivers/net/ethernet/renesas/ravb_main.c index e909960fbc30..e99351fe8d7f 100644 --- a/drivers/net/ethernet/renesas/ravb_main.c +++ b/drivers/net/ethernet/renesas/ravb_main.c @@ -1840,16 +1840,21 @@ static int ravb_open(struct net_device *ndev) { struct ravb_private *priv = netdev_priv(ndev); const struct ravb_hw_info *info = priv->info; + struct device *dev = &priv->pdev->dev; int error; napi_enable(&priv->napi[RAVB_BE]); if (info->nc_queues) napi_enable(&priv->napi[RAVB_NC]); + error = pm_runtime_resume_and_get(dev); + if (error < 0) + goto out_napi_off; + /* Set AVB config mode */ error = ravb_set_config_mode(ndev); if (error) - goto out_napi_off; + goto out_rpm_put; ravb_set_delay_mode(ndev); ravb_write(ndev, priv->desc_bat_dma, DBAT); @@ -1883,6 +1888,9 @@ static int ravb_open(struct net_device *ndev) ravb_stop_dma(ndev); out_set_reset: ravb_set_opmode(ndev, CCC_OPC_RESET); +out_rpm_put: + pm_runtime_mark_last_busy(dev); + pm_runtime_put_autosuspend(dev); out_napi_off: if (info->nc_queues) napi_disable(&priv->napi[RAVB_NC]); @@ -2184,6 +2192,8 @@ static int ravb_close(struct net_device *ndev) struct ravb_private *priv = netdev_priv(ndev); const struct ravb_hw_info *info = priv->info; struct ravb_tstamp_skb *ts_skb, *ts_skb2; + struct device *dev = &priv->pdev->dev; + int error; netif_tx_stop_all_queues(ndev); @@ -2233,7 +2243,14 @@ static int ravb_close(struct net_device *ndev) ravb_get_stats(ndev); /* Set reset mode. */ - return ravb_set_opmode(ndev, CCC_OPC_RESET); + error = ravb_set_opmode(ndev, CCC_OPC_RESET); + if (error) + return error; + + pm_runtime_mark_last_busy(dev); + pm_runtime_put_autosuspend(dev); + + return 0; } static int ravb_hwtstamp_get(struct net_device *ndev, struct ifreq *req) @@ -2725,6 +2742,8 @@ static int ravb_probe(struct platform_device *pdev) clk_prepare(priv->refclk); platform_set_drvdata(pdev, ndev); + pm_runtime_set_autosuspend_delay(&pdev->dev, 100); + pm_runtime_use_autosuspend(&pdev->dev); pm_runtime_enable(&pdev->dev); error = pm_runtime_resume_and_get(&pdev->dev); if (error < 0) @@ -2830,6 +2849,9 @@ static int ravb_probe(struct platform_device *pdev) netdev_info(ndev, "Base address at %#x, %pM, IRQ %d.\n", (u32)ndev->base_addr, ndev->dev_addr, ndev->irq); + pm_runtime_mark_last_busy(&pdev->dev); + pm_runtime_put_autosuspend(&pdev->dev); + return 0; out_napi_del: @@ -2847,6 +2869,7 @@ static int ravb_probe(struct platform_device *pdev) pm_runtime_put(&pdev->dev); out_rpm_disable: pm_runtime_disable(&pdev->dev); + pm_runtime_dont_use_autosuspend(&pdev->dev); clk_unprepare(priv->refclk); out_reset_assert: reset_control_assert(rstc); @@ -2860,6 +2883,12 @@ static void ravb_remove(struct platform_device *pdev) struct net_device *ndev = platform_get_drvdata(pdev); struct ravb_private *priv = netdev_priv(ndev); const struct ravb_hw_info *info = priv->info; + struct device *dev = &priv->pdev->dev; + int error; + + error = pm_runtime_resume_and_get(dev); + if (error < 0) + return; unregister_netdev(ndev); if (info->nc_queues) @@ -2871,8 +2900,9 @@ static void ravb_remove(struct platform_device *pdev) dma_free_coherent(ndev->dev.parent, priv->desc_bat_size, priv->desc_bat, priv->desc_bat_dma); - pm_runtime_put_sync(&pdev->dev); + pm_runtime_put_sync_suspend(&pdev->dev); pm_runtime_disable(&pdev->dev); + pm_runtime_dont_use_autosuspend(dev); clk_unprepare(priv->refclk); reset_control_assert(priv->rstc); free_netdev(ndev); @@ -2954,6 +2984,10 @@ static int ravb_suspend(struct device *dev) if (ret) return ret; + ret = pm_runtime_force_suspend(&priv->pdev->dev); + if (ret) + return ret; + reset_assert: return reset_control_assert(priv->rstc); } @@ -2976,16 +3010,28 @@ static int ravb_resume(struct device *dev) ret = ravb_wol_restore(ndev); if (ret) return ret; + } else { + ret = pm_runtime_force_resume(dev); + if (ret) + return ret; } /* Reopening the interface will restore the device to the working state. */ ret = ravb_open(ndev); if (ret < 0) - return ret; + goto out_rpm_put; ravb_set_rx_mode(ndev); netif_device_attach(ndev); + return 0; + +out_rpm_put: + if (!priv->wol_enabled) { + pm_runtime_mark_last_busy(dev); + pm_runtime_put_autosuspend(dev); + } + return ret; } -- 2.39.2