Received: by 2002:a05:7412:8d23:b0:f7:29d7:fb05 with SMTP id bj35csp151151rdb; Sat, 16 Dec 2023 03:50:33 -0800 (PST) X-Google-Smtp-Source: AGHT+IG1RMsMjYaV/dMp3x+pvLz/goewDQPB+wX03V3K9wLCWArZzyMqD7gvEo/+H0zTtjlCI6Aa X-Received: by 2002:a05:6e02:1b8a:b0:35f:859c:d420 with SMTP id h10-20020a056e021b8a00b0035f859cd420mr5057038ili.41.1702727432867; Sat, 16 Dec 2023 03:50:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702727432; cv=none; d=google.com; s=arc-20160816; b=XX8DTqj6KS9iAv+c8NUbN0t8YuPc0Rt2DBpvh+IFAYIj2czD/jcM4A7G8e0Es+GJBH cVUe5+JfJyRWiSxpU9p+nEC7gYbdDDFn5plzjdhvgHs4XcL6DT9tzm/PD4DhToORjG3y Pczy321EFDAI7pXRWQ62J1bdohe6FgqfxQpkrjhitenSwDlrS8cNzk75/BlSOo4MxltB wjFoHpRUVL2r2NqUxpOMhL3q8horIlJxmb+6eWctYX9AKx6jrpjjpER1CoAEAVK9RF8q ZWDoJhD2TwmUZ+f7NSk04ayMOs/ib7WREcSSr3JsJRYi5Qn6+LKOeDFzOgU5lWuMoWfv +g3w== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=AHdjbrsgC9c7zj7iW7XF4dehsvpJIxxX32noXPZIWvM=; fh=JRNH3R6BkbckLgmyv72Fq6g69IcAiTiL2Sp+o8fsz+8=; b=WHmTvIM0NXBSxkZbFwc+gETtZZSb2+jZ6jvwI/cF/oRP0fSD6Da7dKR2lyoAguUb1u lkRCro62hmnZ4RNN8zv/uciP3Z5+dPnHA08wpjnirsA0LeiJeRT4B+5X0galWPI1viFA 7/mM/43cPEF+GeU65KbvEOYlXatjGwvtTvFm1of+PEc1P51opJe6qei5awhRXVWyWh08 ta2WBHb+3SKCDMvNZxir+YvqIC8R5/PGin041D0IMSAeamDbF/Rl3Ssr6+wqfefl7nJk oUxMFofPX+84jZDnUBFimCIQicE7BHiCl94l4QWcFPFlrYpXDNfvvPh7JFQ+VHQ47BNb sLNg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@tuxon.dev header.s=google header.b=VH2cq5w1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id q10-20020a170902edca00b001d04cb0d6e2si14395667plk.520.2023.12.16.03.50.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 16 Dec 2023 03:50:32 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass header.i=@tuxon.dev header.s=google header.b=VH2cq5w1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 26B03810836D; Thu, 14 Dec 2023 03:48:36 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1572880AbjLNLsG (ORCPT + 99 others); Thu, 14 Dec 2023 06:48:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56050 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1444214AbjLNLrc (ORCPT ); Thu, 14 Dec 2023 06:47:32 -0500 Received: from mail-ej1-x62b.google.com (mail-ej1-x62b.google.com [IPv6:2a00:1450:4864:20::62b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A1EB51718 for ; Thu, 14 Dec 2023 03:46:54 -0800 (PST) Received: by mail-ej1-x62b.google.com with SMTP id a640c23a62f3a-a1e35c2807fso1058967166b.3 for ; Thu, 14 Dec 2023 03:46:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tuxon.dev; s=google; t=1702554413; x=1703159213; 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=AHdjbrsgC9c7zj7iW7XF4dehsvpJIxxX32noXPZIWvM=; b=VH2cq5w1BQ0Zbv/cNEd4CUZaRS8dyZjc4zE+W1wM4RqrCRVoR5xKR4uoz7hWqSGsHA DbhoR7p5hQ4v/uDaj0XiLwEjCI+im9ODDaJ9CSsxSGirOfFQ0IAYjV3OL3ZY1Xjv+W9V oM3GbU3NOcLAWVjdwTVD0bcLROXGqW4Ke5UpA5y5vTzeJR6EHc/tZ/kLz5yPMtPA+gP8 xmpv68vR2iJzUeXGGwRKynq1mn12XMVc3AAV2jA2BomxyfhUwe0LvvQYK+Ex311ELynx mErJJPbFEnscJrKgnWeDBblsz8C0BxMsYZj+M0bB8BsT4G8swO/IuypMyKS6H4pgQlD+ DtvQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702554413; x=1703159213; 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=AHdjbrsgC9c7zj7iW7XF4dehsvpJIxxX32noXPZIWvM=; b=m92vDiKgIVBSynMCmOO2u0FtmGkF86MYYeInKBJHBvk+yQ0MSjheZm60OQDWtD2ccI DnJYVo7ZXZiQ9tuti2Q3msJvM8FLzsw5Qsmaox7sT6AS4lRS12NWR8m69NmcRBAeKgq7 0Fp28vidB7go8sLi9q3mWIP0PvFj4voCnTA/O3xpFzs8odkARDbwekVe96QQWXUYqPg6 J85VFNGbjcsYHHuIRrZf1IpR9uOI1NixBaKAnY/vuCx5ULbNVNZsRVg0n50g7vu7Of1t uSeoeDmWV3P7UjvUCt7XcFdf/GzOHv2CPacDzl6fWUfyMNzbDoEROVEeb4SuUa98PQQL hH6g== X-Gm-Message-State: AOJu0Yxcnov3hXFR3AgmRHNi8zFZ4dyHgaBWKjEebV+ydRofh9i/CTD8 OM7Aug6yeulWT45sT6fiObbgPg== X-Received: by 2002:a17:906:284:b0:a19:940f:b9d3 with SMTP id 4-20020a170906028400b00a19940fb9d3mr4327540ejf.25.1702554413073; Thu, 14 Dec 2023 03:46:53 -0800 (PST) Received: from claudiu-X670E-Pro-RS.. ([82.78.167.103]) by smtp.gmail.com with ESMTPSA id ll9-20020a170907190900b00a1da2f7c1d8sm9240877ejc.77.2023.12.14.03.46.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Dec 2023 03:46:52 -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, geert+renesas@glider.be Cc: netdev@vger.kernel.org, linux-renesas-soc@vger.kernel.org, linux-kernel@vger.kernel.org, Claudiu Beznea Subject: [PATCH net-next v2 21/21] net: ravb: Add runtime PM support Date: Thu, 14 Dec 2023 13:46:00 +0200 Message-Id: <20231214114600.2451162-22-claudiu.beznea.uj@bp.renesas.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231214114600.2451162-1-claudiu.beznea.uj@bp.renesas.com> References: <20231214114600.2451162-1-claudiu.beznea.uj@bp.renesas.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Thu, 14 Dec 2023 03:48:36 -0800 (PST) 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). Signed-off-by: Claudiu Beznea --- Changes in v2: - keep RPM support for all platforms drivers/net/ethernet/renesas/ravb_main.c | 47 ++++++++++++++++++++++-- 1 file changed, 44 insertions(+), 3 deletions(-) diff --git a/drivers/net/ethernet/renesas/ravb_main.c b/drivers/net/ethernet/renesas/ravb_main.c index 9ff943dff522..0733b63ff910 100644 --- a/drivers/net/ethernet/renesas/ravb_main.c +++ b/drivers/net/ethernet/renesas/ravb_main.c @@ -1839,16 +1839,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); @@ -1894,6 +1899,9 @@ static int ravb_open(struct net_device *ndev) ravb_stop_dma(ndev); out_set_reset: ravb_set_reset_mode(ndev); +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]); @@ -2189,6 +2197,7 @@ 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; netif_tx_stop_all_queues(ndev); @@ -2237,6 +2246,9 @@ static int ravb_close(struct net_device *ndev) /* Set reset mode. */ ravb_set_reset_mode(ndev); + pm_runtime_mark_last_busy(dev); + pm_runtime_put_autosuspend(dev); + return 0; } @@ -2808,6 +2820,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) @@ -2916,6 +2930,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_netdev_unregister: @@ -2934,6 +2951,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); @@ -2947,6 +2965,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) @@ -2958,8 +2982,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); @@ -3041,6 +3066,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); } @@ -3063,16 +3092,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