Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp801803rwb; Mon, 26 Sep 2022 06:08:11 -0700 (PDT) X-Google-Smtp-Source: AMsMyM61QRvNRR8mzFY0VjqBEcMHqVGLHF0xExCHBUH6in5jag03MNLx4jsMGUg7bjcT8NgbBomq X-Received: by 2002:a17:906:fd82:b0:770:7e61:3707 with SMTP id xa2-20020a170906fd8200b007707e613707mr17641338ejb.143.1664197690921; Mon, 26 Sep 2022 06:08:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664197690; cv=none; d=google.com; s=arc-20160816; b=PRSu69stpyffrv4x4ot9pZG9X/FtCFBl070EiTmIGjZuZu+ouZM1tlaByh4EFyqopR 08zO6NYtGkGuW06GREHVHnNeaLfWu7FULm07XzxEmqA9UtL2xTKsiTP2FAM7y3O9xz5Q /m/QeNLPwiMmlN+svrmFr46SxNhCxFKWjxc+QSkETa1ScE8N+f8XejT5ZBMw0wzu7OVH I3E4eGK70DRdRXDnZcRVY1fQ8P9IPa3SuEg98BD6wRwfAq/1LTOwNWrOB6TNflotwfkh mC3O3Slw0B4x7i7pKBPQ0A0XoSrvsSz0VCkm8VdZCXgBRCaouv/IAE3bSMtcYR1Cd/sW MHRQ== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=YPcws61gjr8dJZn+xYsJxHJ6R9gGJvTE+mZq/+Jzm+o=; b=LzUT3scawvlVaTQ1jvWd/5O94BhpgngGOKWu0klir6dG9FrRJDNt3tniHLvU6jqLuD J2BbhVbDYqWHNaTizfRAkv4fObF3XjSZpl5sceDq4hPRVRIbgrBnAzlxCLwBl+lnArqz 9wfbT1LBz6N84aC3kyoa4IUlxGk8PlGaJI2o8dL5LTOBRwQnMlHBvkkSRI72PyPUHO92 NkgcyzDV6jybqMU+BTT0bluJaZv8XBCucV1L/xVu64v6/qvoDc001r4US/rxqF9pijfv m8ggHuqrFImEu6xj/g0fCn0XaSPQb7BkZOwdrMqJOuY8N1JFSd5hLtTrkD3imge5v2Kr OxWQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=PWS6jO3X; 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=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id jj1-20020a170907984100b00780e844b2f7si12748116ejc.481.2022.09.26.06.07.18; Mon, 26 Sep 2022 06:08:10 -0700 (PDT) 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=@linuxfoundation.org header.s=korg header.b=PWS6jO3X; 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=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239386AbiIZMMl (ORCPT + 99 others); Mon, 26 Sep 2022 08:12:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34030 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239301AbiIZMMQ (ORCPT ); Mon, 26 Sep 2022 08:12:16 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5348383BD0; Mon, 26 Sep 2022 03:58:05 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 6AFC360A36; Mon, 26 Sep 2022 10:47:46 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 658ECC433B5; Mon, 26 Sep 2022 10:47:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1664189265; bh=MaRHsgu6x1R5SWPGz555MhiLnxi/cADJmYE8LEBbTcc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PWS6jO3XDuYvAnxU7bsNFdGM1P6gRSPMX6fvq0kbL/qXErEmnsAWB8rjDCxogXCpB nDHhAUdJQpoJP7xV7Et4YniVdAnwscH8RWjkrXJNSv3TKSMCvFhccZBy3sMob8/0gE NfX7896VWOeLYcgtA7TLI+thx7PlorDSmnCh3nYk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Ioana Ciornei , Andrew Lunn , Paolo Abeni , Sasha Levin Subject: [PATCH 5.19 101/207] net: phy: aquantia: wait for the suspend/resume operations to finish Date: Mon, 26 Sep 2022 12:11:30 +0200 Message-Id: <20220926100811.109439140@linuxfoundation.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220926100806.522017616@linuxfoundation.org> References: <20220926100806.522017616@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,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 From: Ioana Ciornei [ Upstream commit ca2dccdeeb49a7e408112d681bf447984c845292 ] The Aquantia datasheet notes that after issuing a Processor-Intensive MDIO operation, like changing the low-power state of the device, the driver should wait for the operation to finish before issuing a new MDIO command. The new aqr107_wait_processor_intensive_op() function is added which can be used after these kind of MDIO operations. At the moment, we are only adding it at the end of the suspend/resume calls. The issue was identified on a board featuring the AQR113C PHY, on which commands like 'ip link (..) up / down' issued without any delays between them would render the link on the PHY to remain down. The issue was easy to reproduce with a one-liner: $ ip link set dev ethX down; ip link set dev ethX up; \ ip link set dev ethX down; ip link set dev ethX up; Fixes: ac9e81c230eb ("net: phy: aquantia: add suspend / resume callbacks for AQR107 family") Signed-off-by: Ioana Ciornei Reviewed-by: Andrew Lunn Link: https://lore.kernel.org/r/20220906130451.1483448-1-ioana.ciornei@nxp.com Signed-off-by: Paolo Abeni Signed-off-by: Sasha Levin --- drivers/net/phy/aquantia_main.c | 53 ++++++++++++++++++++++++++++++--- 1 file changed, 49 insertions(+), 4 deletions(-) diff --git a/drivers/net/phy/aquantia_main.c b/drivers/net/phy/aquantia_main.c index c7047f5d7a9b..8bc0957a0f6d 100644 --- a/drivers/net/phy/aquantia_main.c +++ b/drivers/net/phy/aquantia_main.c @@ -90,6 +90,9 @@ #define VEND1_GLOBAL_FW_ID_MAJOR GENMASK(15, 8) #define VEND1_GLOBAL_FW_ID_MINOR GENMASK(7, 0) +#define VEND1_GLOBAL_GEN_STAT2 0xc831 +#define VEND1_GLOBAL_GEN_STAT2_OP_IN_PROG BIT(15) + #define VEND1_GLOBAL_RSVD_STAT1 0xc885 #define VEND1_GLOBAL_RSVD_STAT1_FW_BUILD_ID GENMASK(7, 4) #define VEND1_GLOBAL_RSVD_STAT1_PROV_ID GENMASK(3, 0) @@ -124,6 +127,12 @@ #define VEND1_GLOBAL_INT_VEND_MASK_GLOBAL2 BIT(1) #define VEND1_GLOBAL_INT_VEND_MASK_GLOBAL3 BIT(0) +/* Sleep and timeout for checking if the Processor-Intensive + * MDIO operation is finished + */ +#define AQR107_OP_IN_PROG_SLEEP 1000 +#define AQR107_OP_IN_PROG_TIMEOUT 100000 + struct aqr107_hw_stat { const char *name; int reg; @@ -596,16 +605,52 @@ static void aqr107_link_change_notify(struct phy_device *phydev) phydev_info(phydev, "Aquantia 1000Base-T2 mode active\n"); } +static int aqr107_wait_processor_intensive_op(struct phy_device *phydev) +{ + int val, err; + + /* The datasheet notes to wait at least 1ms after issuing a + * processor intensive operation before checking. + * We cannot use the 'sleep_before_read' parameter of read_poll_timeout + * because that just determines the maximum time slept, not the minimum. + */ + usleep_range(1000, 5000); + + err = phy_read_mmd_poll_timeout(phydev, MDIO_MMD_VEND1, + VEND1_GLOBAL_GEN_STAT2, val, + !(val & VEND1_GLOBAL_GEN_STAT2_OP_IN_PROG), + AQR107_OP_IN_PROG_SLEEP, + AQR107_OP_IN_PROG_TIMEOUT, false); + if (err) { + phydev_err(phydev, "timeout: processor-intensive MDIO operation\n"); + return err; + } + + return 0; +} + static int aqr107_suspend(struct phy_device *phydev) { - return phy_set_bits_mmd(phydev, MDIO_MMD_VEND1, MDIO_CTRL1, - MDIO_CTRL1_LPOWER); + int err; + + err = phy_set_bits_mmd(phydev, MDIO_MMD_VEND1, MDIO_CTRL1, + MDIO_CTRL1_LPOWER); + if (err) + return err; + + return aqr107_wait_processor_intensive_op(phydev); } static int aqr107_resume(struct phy_device *phydev) { - return phy_clear_bits_mmd(phydev, MDIO_MMD_VEND1, MDIO_CTRL1, - MDIO_CTRL1_LPOWER); + int err; + + err = phy_clear_bits_mmd(phydev, MDIO_MMD_VEND1, MDIO_CTRL1, + MDIO_CTRL1_LPOWER); + if (err) + return err; + + return aqr107_wait_processor_intensive_op(phydev); } static int aqr107_probe(struct phy_device *phydev) -- 2.35.1