From patchwork Wed Nov 30 11:11:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Clark Wang X-Patchwork-Id: 13059704 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 8FEB1C433FE for ; Wed, 30 Nov 2022 11:14:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=niMepFn6m3S4FUVzgC9pRazHg8zdYhfDJ7rsVD1C8sg=; b=mRcHBjECo9qU5Z zTYNiZT/fKt/SapszFzWRsVOo8WifnDI2WySZeWPsRIon2CLFHer4Z4mJFC2678udehH3EXCgGwtf qfwg7YDZrSqSZSsQI0SKWLtJk74gUrmsrz4q5OwyWLCq+dYWEGzCY95RjgKZGJTAEjiZGaMn8rxa1 boY9r5O2qC4nPcSzRLDnatxS5lY/4SWA54iGACax0DL0qrz9YzMYc/nMO6pQ0IgdNFEUc83zLPN/S POUZJGM2DbcVtDLTPnlFTLAyGyJ5Ij3n7yAki+Fu/Mh3Cpts14ij3Vg6AtHiT1i1o7xlOvs9BYb+e 5BLEQ7jA9x46CBaI6L4w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1p0L1Q-00FhWA-AH; Wed, 30 Nov 2022 11:13:00 +0000 Received: from mail-he1eur04on0631.outbound.protection.outlook.com ([2a01:111:f400:fe0d::631] helo=EUR04-HE1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1p0L1B-00FhMk-KA for linux-arm-kernel@lists.infradead.org; Wed, 30 Nov 2022 11:12:47 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=MqRrbahmEjd5U7jQ3Li8L+morFvDzn5rc7OQ2+xKVhQ+Jj3Rhk5/yafWGO58/t6o8GbhWsKbu/m6bHNIhxBAEw4RXzy75cPJ5y5cyLw9adzGrpMm8eO6qAlR1EXpZyzbM7OIIiVKPFkADBIdsuykrGjqG8Ae/hdvXS1cWYK/Yd340k9BfqtS5JfCANIZTzTlPNfvTGgWufS9y2J9/Hl52TOw/RXxA5hITpN3Ii51QkotWT7ocZqBVlkHrwzENcwhjC2UetBIHtq2QqVbgkPdKw6leEhpOth0/vvNMg2FOEQVNLXTCraGNAQwphmIar/JSzQ1yho6A3t5oeIYqYPmdw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=oOU8PEQY2yDwQEEQ63eF/ws2Gr3p7Lr0IH/5wwxzc0Y=; b=a1mMuuovz2aPMpu2NuvJUyglES2SOq3CDqmQkDO4mkxHZfTQYQ5IdZXSzATqeAi65ggTDYjB331Juz2j+8W/QCwFFYnUN6vhR2SLtH5/kKDKRHrZSFYVw/5mUBTz3DKP5AGa2N1MC13oKQ0Y4SKxJAMfhc1rdC7lRvjjvlPrkMWBKz2txujrPMiLkK4GcmnL0hlHy3f51s0aGMdCQ6TRSCJDLwCPoc4qoWyPzep3zz95A1KT6LHuapAhpLwLclZVuwH582voWhc0l9DEmolU51Qyxrk/aNJiWHlJr+w+XYQa6FEoFp1c1JUmN49LJdoz/sANAo8k6tVwQ2NvX3l3xw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=oOU8PEQY2yDwQEEQ63eF/ws2Gr3p7Lr0IH/5wwxzc0Y=; b=FnOicuBg28KcNcVycu1n8jbJlrskmqh1WJcuIiAoSUHt6pAHKKnHJHLnyzYAXky50eFG+d/Hxk6p2eQHrwPCM0EvV5MXfRY99LWNFCg19JTXA3RNxCfs4irtMzKFRjGCkgtGucfBRgvm1YWkClEPF+LD9DNsrOH3J7mMJuMjQPQ= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from HE1PR0402MB2939.eurprd04.prod.outlook.com (2603:10a6:3:db::18) by VI1PR04MB6783.eurprd04.prod.outlook.com (2603:10a6:803:130::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5857.20; Wed, 30 Nov 2022 11:12:40 +0000 Received: from HE1PR0402MB2939.eurprd04.prod.outlook.com ([fe80::7682:a2e6:b891:2f4d]) by HE1PR0402MB2939.eurprd04.prod.outlook.com ([fe80::7682:a2e6:b891:2f4d%10]) with mapi id 15.20.5857.023; Wed, 30 Nov 2022 11:12:39 +0000 From: Clark Wang To: linux@armlinux.org.uk, peppe.cavallaro@st.com, alexandre.torgue@foss.st.com, joabreu@synopsys.com, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, mcoquelin.stm32@gmail.com, andrew@lunn.ch, hkallweit1@gmail.com Cc: netdev@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/2] net: phylink: add sync flag mac_ready to fix resume issue with WoL enabled Date: Wed, 30 Nov 2022 19:11:47 +0800 Message-Id: <20221130111148.1064475-2-xiaoning.wang@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221130111148.1064475-1-xiaoning.wang@nxp.com> References: <20221130111148.1064475-1-xiaoning.wang@nxp.com> X-ClientProxiedBy: SI1PR02CA0020.apcprd02.prod.outlook.com (2603:1096:4:1f4::9) To HE1PR0402MB2939.eurprd04.prod.outlook.com (2603:10a6:3:db::18) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: HE1PR0402MB2939:EE_|VI1PR04MB6783:EE_ X-MS-Office365-Filtering-Correlation-Id: 69c0892a-3957-4eae-b407-08dad2c3cb37 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ZZW9cku3yhxTlk5ysohZ+c0h2Xj71qlSsZ1eQKXN1YK/TzDWaDVObVjNg6qvXem5tCDTcUJycaJS+xOaweq6cICFWyqV7dutlZLOiwS8W0NngzoCSpNtEYnd4Nhtswju1LfaQa5TJP293c4IQ95KrDCj3De6MvtkVLcEf9SMBxZOH53Nvmu9fshCYsrfkqWHVFZXjkYECh0+vfuFyzPGX3d+TgEJd484FOWP37t2IdlpozcZhM94kh/16p29tS/+wGq1YZ1oaHjbUBeSHop9Vg001+6ESJrY7gSHQzMYRwIKaiGYTTANrlxvgsVnwfBVIo/ImS7xfoAeO7/gjPAarxn8L1kAdBd4jqYDe05Y/ob5UDT1QHuXbKP3+dMf8r0/kBblhTx4cDOQt/9QSfc7qarpN3Sjxa+9nk0KSZg4rbE5/Jg8ISMIu3L0lsXnBwOQLdTboQ8wIlkXs3HIT/pNeSAZxPYcwFXeONMe+BtTObKLyjxIGxAp+/MnDWWbW7xpfS4zdAUWrnkUtUfW1iGvb9uNHt/Jo29TgyrdeoR43HqLYfAuXCNXvd/px7sJ1zUdmsttqEYWKViP6pgpvgIjIUK6O64LezdZQAUsCM845RxElikkUMN+Kyb51rwbB8+hPMRah6VVkAJgil3H+kFTQXC7O6HM6eFM0BbB6SqBOeipFz96SWoiVWmURqaL9pgCtfkmkw5yuOkQ6mH18yTmaw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:HE1PR0402MB2939.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(4636009)(136003)(376002)(346002)(396003)(39860400002)(366004)(451199015)(36756003)(921005)(41300700001)(7416002)(2906002)(38350700002)(478600001)(38100700002)(86362001)(83380400001)(66556008)(8676002)(6486002)(316002)(2616005)(66946007)(66476007)(8936002)(5660300002)(6666004)(26005)(186003)(1076003)(52116002)(6512007)(4326008)(6506007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: FLlFobYSEuJm4rUY8LqTrAj2ihCxLwJ3XyHPH719ZOu5nFaOltiHvXp93YL4PmoEZdy6pTsWNlG+76GmzXojhoDNNu7FL1OEC1lw7HBZXVyQnjnBotEtHpjWyUvE4Kdw5YTGgkxn4wxVUZAlK4Da9UDkODbn/TyIjEh1omYYvo0lIkydzJm9OkYF7GwtSTyakRy8tnq6BvwIWn/C42Eh/F1x7HoGgZRQ69f6Vqr4R+I8XXPyxmMD4mpOlV2p5AMzXUJE+KMQmPYK4JlpHh3mOEWHhaSZkJov0C/F+/KS9IbCemTbZD3eCXtSo3bbvwOwZCuPEb/a2rfUcPPOa9OCzmQSCRgse2NR7tOZTnPKDRfCKuejHCOTA4rA5TP3m2wqXNL4dvq7tUDNxFj9QB3HEuMo9AMbaJLMoLqClO1C0eOx0Fm72hLgijaL9XJ46lq/dR/76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lIeMy/QZLLvG5jBpesA3U3O/V11cTZDM5HYKqb5ZMrvy2fU4QXCLDxx0ZZ8Azd+3XEe X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 69c0892a-3957-4eae-b407-08dad2c3cb37 X-MS-Exchange-CrossTenant-AuthSource: HE1PR0402MB2939.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Nov 2022 11:12:39.8727 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: olX4FSS8GTb7KlUkGZAWZwTUQ6Hkn2/K4uz8tiLcw8yhObgMQh5ONDjlCRiYX3+jyxQ/1JVveahJO0ngbg+2uw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR04MB6783 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20221130_031245_715320_87660409 X-CRM114-Status: GOOD ( 20.85 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Issue we met: On some platforms, mac cannot work after resumed from the suspend with WoL enabled. The cause of the issue: 1. phylink_resolve() is in a workqueue which will not be executed immediately. This is the call sequence: phylink_resolve()->phylink_link_up()->pl->mac_ops->mac_link_up() For stmmac driver, mac_link_up() will set the correct speed/duplex... values which are from link_state. 2. In stmmac_resume(), it will call stmmac_hw_setup() after called the phylink_resume(). stmmac_core_init() is called in function stmmac_hw_setup(), which will reset the mac and set the speed/duplex... to default value. Conclusion: Because phylink_resolve() cannot determine when it is called, it cannot be guaranteed to be called after stmmac_core_init(). Once stmmac_core_init() is called after phylink_resolve(), the mac will be misconfigured and cannot be used. In order to solve this problem, the mac_ready flag is added to the phylink structure to synchronize the state of the mac in the phylink_resolve() function. To prevent the correct configuration from being overwritten. By default, mac_ready will be configured as true, that is, it will not affect other drivers that do not use this flag. Signed-off-by: Clark Wang --- drivers/net/phy/phylink.c | 36 ++++++++++++++++++++++++++++++++++++ include/linux/phylink.h | 2 ++ 2 files changed, 38 insertions(+) diff --git a/drivers/net/phy/phylink.c b/drivers/net/phy/phylink.c index 09cc65c0da93..312b47fdc12b 100644 --- a/drivers/net/phy/phylink.c +++ b/drivers/net/phy/phylink.c @@ -74,6 +74,7 @@ struct phylink { bool mac_link_dropped; bool using_mac_select_pcs; + bool mac_ready; struct sfp_bus *sfp_bus; bool sfp_may_have_phy; @@ -1276,6 +1277,12 @@ static void phylink_resolve(struct work_struct *w) bool retrigger = false; bool cur_link_state; + /* If mac is not ready, retrigger this work queue to wait it ready*/ + if (!pl->mac_ready) { + queue_work(system_power_efficient_wq, &pl->resolve); + return; + } + mutex_lock(&pl->state_mutex); if (pl->netdev) cur_link_state = netif_carrier_ok(ndev); @@ -1450,6 +1457,34 @@ static int phylink_register_sfp(struct phylink *pl, return ret; } +/** + * phylink_clear_mac_ready() - clear mac_ready flag + * @pl: a pointer to a &struct phylink returned from phylink_create() + * + * set mac_ready to false, which means the mac is not ready, + * if the pl->mac_ops->mac_link_up function in resolve is called at this time, + * the correct speed/duplex and other parameters set in this function will + * be reset to the default values by mac. + */ +void phylink_clear_mac_ready(struct phylink *pl) +{ + pl->mac_ready = false; +} +EXPORT_SYMBOL_GPL(phylink_clear_mac_ready); + +/** + * phylink_set_mac_ready() - set mac_ready flag + * @pl: a pointer to a &struct phylink returned from phylink_create() + * + * set mac_ready to true, which means the mac is ready now, can reslove the + * phylink and set the correct speed/duplex settings for mac. + */ +void phylink_set_mac_ready(struct phylink *pl) +{ + pl->mac_ready = true; +} +EXPORT_SYMBOL_GPL(phylink_set_mac_ready); + /** * phylink_create() - create a phylink instance * @config: a pointer to the target &struct phylink_config @@ -1518,6 +1553,7 @@ struct phylink *phylink_create(struct phylink_config *config, pl->link_config.duplex = DUPLEX_UNKNOWN; pl->link_config.an_enabled = true; pl->mac_ops = mac_ops; + pl->mac_ready = true; __set_bit(PHYLINK_DISABLE_STOPPED, &pl->phylink_disable_state); timer_setup(&pl->link_poll, phylink_fixed_poll, 0); diff --git a/include/linux/phylink.h b/include/linux/phylink.h index c492c26202b5..759c8041f3d2 100644 --- a/include/linux/phylink.h +++ b/include/linux/phylink.h @@ -570,6 +570,8 @@ void phylink_generic_validate(struct phylink_config *config, unsigned long *supported, struct phylink_link_state *state); +void phylink_clear_mac_ready(struct phylink *pl); +void phylink_set_mac_ready(struct phylink *pl); struct phylink *phylink_create(struct phylink_config *, struct fwnode_handle *, phy_interface_t iface, const struct phylink_mac_ops *mac_ops);