From patchwork Mon Dec 12 11:28:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Claudiu Beznea X-Patchwork-Id: 32335 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp2191003wrr; Mon, 12 Dec 2022 03:34:47 -0800 (PST) X-Google-Smtp-Source: AA0mqf5KHet1SEjnP4hxfJ5pYtbrx0iioo3wIsruGdqrd+SdMRlojy5n8Njs3OuZAeCQ6qM7aIV8 X-Received: by 2002:a05:6402:378c:b0:461:cdda:4004 with SMTP id et12-20020a056402378c00b00461cdda4004mr13093363edb.10.1670844887760; Mon, 12 Dec 2022 03:34:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670844887; cv=none; d=google.com; s=arc-20160816; b=Twvj3sIeKHlAWOJF6DyXe9aMWy2IsksaBwzaGtzUagz7/QRMNiGPGHOPcyrFkfIB5B PAKZO8veoDZBtNeCBnrCh8w7cqAICIdG8wiSYui7Y4V1lKVsk1JFIYP570cnns0m77Bz vjMEvcxpAgD3FDZfoNgLTcnIOy1tSYGOFwjqS2TkSILYDffmP/jrnuEenCXLwagzhEMq ToSk9VEYZWZq5GOfIfgbzQq+HYUp/P/PVik7a5GkXA+owTbkK7rm3XyubRhfIRgpq3yf y2/j92dMa+gGAABw4GFCpHZRChLt6/nSuheP25J1au1/0HhDmMQAXG+kYjBcIfmlsV7x m0Yg== 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=HkpAtFaB7Mse9vde/nAl7iN4X+aL5zOO+OIoUjczACY=; b=SpjCKqjqq0fBeNXZjMUPlCaN/WSiFpP2JAjd3HHyo+GiRICLc8xYoAjzsGVelk0bk4 3WZqIbxo6rRQkKSK9i+CsqEeGJwG3Oq4pdWzG8ABrHJ508jK7SMG2ry0mZ6siXXpEf/p CDOUs3WXu7SNDqun5zj9Oat+OfyuH8qrws8Vd68Yz+KbZHtiMQg0SzbHw4sZpizRgNFI kJJcMnOcFqVMSOSt6M1ySdMZgYiT0PoVSbYUHxX0oa4H9Ta/cNEOPmhu2amKI+907C1O vjgBM/j80W2PShttRG1eY8z6eYN8dYu4uO3Yl8T1J4N4CwZqFfiaV7MwTQNSXWIl+n6W SVVQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microchip.com header.s=mchp header.b=nxGyc62m; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=microchip.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id eb7-20020a0564020d0700b00461aa80dfa8si8464508edb.429.2022.12.12.03.34.23; Mon, 12 Dec 2022 03:34:47 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@microchip.com header.s=mchp header.b=nxGyc62m; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=microchip.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232033AbiLLLYe (ORCPT + 99 others); Mon, 12 Dec 2022 06:24:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37422 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231768AbiLLLYE (ORCPT ); Mon, 12 Dec 2022 06:24:04 -0500 Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.154.123]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 60D6DCC; Mon, 12 Dec 2022 03:23:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1670844218; x=1702380218; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=gDWgZWt68B2FUuPmIEy3AshiMsSgCuxMFYszX/kL4qo=; b=nxGyc62mBqB4PLBG3IqkKK2SAXy6UroVDVzUMEPXSY2rqPG+N7YCmznu B1Ct03zDWln6QC9znslXSMSzJbKofWdldWewHC9HgVOq7T0Foh1hfqrXY +FV1s5R0v+ldNcrd4VAcns8SMNxnVlfJfUSQKda3D9ab5Cas7CikNsvTU IlMA1Z4HE36DRaEGOq5XJfSUIZlU0YaO5XAxplZHsi1exXGI+2RR3AjVI GJoux6N77hsWnjZAkUlZV36qf2ulkD+e7hacYUXYOUIVnSVoCcm5MGej/ YvYUFui72X992QC6eJJmAGcpUFdgvSmCTzxUxyMWpSqt5IoAmCKb7dbBv w==; X-IronPort-AV: E=Sophos;i="5.96,238,1665471600"; d="scan'208";a="127662351" Received: from unknown (HELO email.microchip.com) ([170.129.1.10]) by esa6.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 12 Dec 2022 04:23:37 -0700 Received: from chn-vm-ex04.mchp-main.com (10.10.85.152) by chn-vm-ex03.mchp-main.com (10.10.85.151) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.16; Mon, 12 Dec 2022 04:23:35 -0700 Received: from localhost.localdomain (10.10.115.15) by chn-vm-ex04.mchp-main.com (10.10.85.152) with Microsoft SMTP Server id 15.1.2507.16 via Frontend Transport; Mon, 12 Dec 2022 04:23:32 -0700 From: Claudiu Beznea To: , , , , , , , CC: , , , Claudiu Beznea Subject: [PATCH v2 1/2] net: phylink: init phydev on phylink_resume() Date: Mon, 12 Dec 2022 13:28:44 +0200 Message-ID: <20221212112845.73290-2-claudiu.beznea@microchip.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20221212112845.73290-1-claudiu.beznea@microchip.com> References: <20221212112845.73290-1-claudiu.beznea@microchip.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1752007848902155769?= X-GMAIL-MSGID: =?utf-8?q?1752007848902155769?= There are scenarios where PHY power is cut off on system suspend. There are also MAC drivers which handles themselves the PHY on suspend/resume path. For such drivers the struct phy_device::mac_managed_phy is set to true and thus the mdio_bus_phy_suspend()/mdio_bus_phy_resume() wouldn't do the proper PHY suspend/resume. For such scenarios call phy_init_hw() from phylink_resume(). Suggested-by: Russell King (Oracle) Signed-off-by: Claudiu Beznea --- Hi, Russel, I let phy_init_hw() to execute for all devices. I can restrict it only for PHYs that has struct phy_device::mac_managed_phy = true. Please let me know what you think. Thank you, Claudiu Beznea drivers/net/phy/phylink.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/net/phy/phylink.c b/drivers/net/phy/phylink.c index 09cc65c0da93..6003c329638e 100644 --- a/drivers/net/phy/phylink.c +++ b/drivers/net/phy/phylink.c @@ -2031,6 +2031,12 @@ void phylink_resume(struct phylink *pl) { ASSERT_RTNL(); + if (pl->phydev) { + int ret = phy_init_hw(pl->phydev); + if (ret) + return; + } + if (test_bit(PHYLINK_DISABLE_MAC_WOL, &pl->phylink_disable_state)) { /* Wake-on-Lan enabled, MAC handling */ From patchwork Mon Dec 12 11:28:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Claudiu Beznea X-Patchwork-Id: 32334 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp2187791wrr; Mon, 12 Dec 2022 03:27:51 -0800 (PST) X-Google-Smtp-Source: AA0mqf5QlTG1SmrsLTYpsVZWn1ITeyFZ6xj/NdK+1ziCf5i4cwY9Dqe/sPzw6L2K5alCAST1MYGg X-Received: by 2002:a17:907:f8d:b0:7c0:f684:9091 with SMTP id kb13-20020a1709070f8d00b007c0f6849091mr13571920ejc.11.1670844470983; Mon, 12 Dec 2022 03:27:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670844470; cv=none; d=google.com; s=arc-20160816; b=ZW9DJjR/LXH5JizCZ/cwvn/tQ8X6BrapnGpoOU/Sk4xADxeoZPcDH1MapDi3WpCAuj Qe8H2y4miJx5V9zqutkFJbAzXG96vja9vYYHHJKBJq/Wfki5lzl0hRV9Xzrq7oggfZxY fIaPGLzHwnz1/vNGgwlfIqu1UizJOohoxucf8gYNO/dZjqwuzq13xdLQnUBLKYRqLEZf cDGbbtOXM+c/K6ojoAxr99O3KUvzhSR2fFbQ2f1U+KawuwZW/VJft2zpBu5DGiYtOila jd3jd85yj9A+abLsB7wIuYmQuBXybP5SnxSsWF5IH5EdhX8lSsc2mC7KQlkZdxtcS2sB p7VA== 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=bnmQlT+Wb04r5lr9xJaS/d5RcywdcTh0PU5dekz5Zvo=; b=H2A8aJkmx3F7KAZGf3LZGr42/bmHC0iuIT9kX/oBTJOOo9n8UlAlFTLiChG2DmQ/9v 0FvEworpvIf9rkNB0vGHLIVBIQlMFCb53MWWG8gOgcrrcPAh5T7jHlzYc0KWY6Lyc+Dh mNrTJH2bvRKo41W9injudRLqCQ1KCGfC1aBr7IZGwBjyylI1KsdOWPfrUlS/nQmXLFtl vAnIcuAf9qXuC1yvhEY72Z8TpjWRX6a026+1KmmIsLmaB3EuXaoAR7Mq6J2sVaysaMZ4 DCi1iwh0X87VR9gX8gxKjhJ9qNplLYODktdnNmur9HXYfuwwiTJGgpIWp79xVehB/edk RY+Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microchip.com header.s=mchp header.b=JMp47GQv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=microchip.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id lu32-20020a170906fae000b007adc4a0aeb5si4725085ejb.873.2022.12.12.03.27.27; Mon, 12 Dec 2022 03:27:50 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@microchip.com header.s=mchp header.b=JMp47GQv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=microchip.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232058AbiLLLYi (ORCPT + 99 others); Mon, 12 Dec 2022 06:24:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37424 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231302AbiLLLYF (ORCPT ); Mon, 12 Dec 2022 06:24:05 -0500 Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.154.123]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E19B6F4; Mon, 12 Dec 2022 03:23:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1670844218; x=1702380218; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=4hyjin04xcLN2c4aQwMYUFRysfBo+OuGNZ4sZbmy7iY=; b=JMp47GQvRETmeC+FBbsA7kdC7NNXbHechA4zaW6WGEJ4k4POLpM6fh8P tR9voUcrl2HeLUwYUszFbbjCaqtq09xAy7ft+dENyjCWTfphUojT4HKDn mHYwMCZrfKDjuJvdZTrT3fpilAhFSt/3ccnF3q/eDQxKW1xDY4dLZlZpk 7Abr8ezx/pTbHvpvJbw6k9brh0CNiGiRdWWzcjzOwyw4QH6+Q6xUqk/Zh xkKrALvOnrRsNm4yiEmICZuuLW3Ds2j08kUoYNxoRPQw4bQYRUt/prQ1b 8kj2eZ+glSjl6d/VTxkzyPoSXIxq0hrCVcN9AzY9XKEiZ9EvPsRrEZM66 g==; X-IronPort-AV: E=Sophos;i="5.96,238,1665471600"; d="scan'208";a="127662353" Received: from unknown (HELO email.microchip.com) ([170.129.1.10]) by esa6.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 12 Dec 2022 04:23:38 -0700 Received: from chn-vm-ex04.mchp-main.com (10.10.85.152) by chn-vm-ex03.mchp-main.com (10.10.85.151) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.16; Mon, 12 Dec 2022 04:23:38 -0700 Received: from localhost.localdomain (10.10.115.15) by chn-vm-ex04.mchp-main.com (10.10.85.152) with Microsoft SMTP Server id 15.1.2507.16 via Frontend Transport; Mon, 12 Dec 2022 04:23:35 -0700 From: Claudiu Beznea To: , , , , , , , CC: , , , Claudiu Beznea Subject: [PATCH v2 2/2] net: macb: use phylink_suspend()/phylink_resume() Date: Mon, 12 Dec 2022 13:28:45 +0200 Message-ID: <20221212112845.73290-3-claudiu.beznea@microchip.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20221212112845.73290-1-claudiu.beznea@microchip.com> References: <20221212112845.73290-1-claudiu.beznea@microchip.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1752007412139040724?= X-GMAIL-MSGID: =?utf-8?q?1752007412139040724?= Use phylink_suspend() and phylink_resume() for macb driver instead of phylink_start()/phylink_stop(). This helps on fixing commit bf0ad1893442 ("net: macb: Specify PHY PM management done by MAC"). Commit bf0ad1893442 ("net: macb: Specify PHY PM management done by MAC") signals to PHY layer that the PHY PM management is done by the MAC driver itself. In case this is done the mdio_bus_phy_suspend() and mdio_bus_phy_resume() will return just at its beginning letting the MAC driver to handle the PHY power management. AT91 devices (e.g. SAMA7G5, SAMA5D2) has a special power saving mode called backup and self-refresh where most of the SoCs parts are shutdown on suspend and RAM is switched to self-refresh. The rail powering the on-board ethernet PHY could also be closed. For scenarios where backup and self-refresh is used the MACB driver needs to re-initialize the PHY device itself when resuming. Otherwise there is poor or missing connectivity (e.g. SAMA7G5-EK uses KSZ9131 in RGMII mode which needs its DLL settings to satisfy RGMII timings). For this call phylink_suspend()/phylink_resume() on suspend/resume path. The patch has been tested on SAMA7G5EK (with KSZ9131 and KSZ8081 PHYs) and SAM9X60EK (with KSZ8081 PHY) boards. Fixes: bf0ad1893442 ("net: macb: Specify PHY PM management done by MAC") Signed-off-by: Claudiu Beznea --- This patch depends on patch 1/2 from this series. For proper backporting to older kernel (in case this series is integrated as is) please add the Depends-on tag on this patch after patch 1/2 is integrated in networking tree. Thank you, Claudiu Beznea drivers/net/ethernet/cadence/macb_main.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/drivers/net/ethernet/cadence/macb_main.c b/drivers/net/ethernet/cadence/macb_main.c index 95667b979fab..bcd394093d1c 100644 --- a/drivers/net/ethernet/cadence/macb_main.c +++ b/drivers/net/ethernet/cadence/macb_main.c @@ -5142,9 +5142,13 @@ static int __maybe_unused macb_suspend(struct device *dev) napi_disable(&queue->napi_tx); } - if (!(bp->wol & MACB_WOL_ENABLED)) { + if (bp->wol & MACB_WOL_ENABLED) { rtnl_lock(); - phylink_stop(bp->phylink); + phylink_suspend(bp->phylink, true); + rtnl_unlock(); + } else { + rtnl_lock(); + phylink_suspend(bp->phylink, false); phy_exit(bp->sgmii_phy); rtnl_unlock(); spin_lock_irqsave(&bp->lock, flags); @@ -5209,13 +5213,6 @@ static int __maybe_unused macb_resume(struct device *dev) spin_unlock_irqrestore(&bp->lock, flags); disable_irq_wake(bp->queues[0].irq); - - /* Now make sure we disable phy before moving - * to common restore path - */ - rtnl_lock(); - phylink_stop(bp->phylink); - rtnl_unlock(); } for (q = 0, queue = bp->queues; q < bp->num_queues; @@ -5238,7 +5235,7 @@ static int __maybe_unused macb_resume(struct device *dev) if (!device_may_wakeup(&bp->dev->dev)) phy_init(bp->sgmii_phy); - phylink_start(bp->phylink); + phylink_resume(bp->phylink); rtnl_unlock(); netif_device_attach(netdev);