Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp785853rwb; Mon, 26 Sep 2022 05:59:50 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6dSTcLt6Pc3jT0yIMfpEJPd7evAjd1ebju5eG6qRxaOw0a88s3q3qBAjJrwUJB7vIWmq2L X-Received: by 2002:a05:6a00:238c:b0:544:c42d:8a67 with SMTP id f12-20020a056a00238c00b00544c42d8a67mr23423926pfc.21.1664197190269; Mon, 26 Sep 2022 05:59:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664197190; cv=none; d=google.com; s=arc-20160816; b=uwuWOwKYsG7V7WWnwwtTAl5NNwRO5DLd3+PBrnkK+3Rnwz7Cf2JT9oHJEt0X0RjCrC +XACYl1ZQNvy5d79eGg9AbrBTS6uXXvhh+M2AoR6qvabh1fcHur227BxqrQCqv59DvbF wquWpc2mNDvlhtkeZYbqitXH/QjVBiSKxglOalXKNLS9Gu2az1ptx5j0/CqTWFvspYKR lhWx9bV92TUS4+1TYa5Upf8/Vl9aqvJQbsVr1TuR46sKPNXI20ebO5xNTwpoSZlvjf9g RKcZozszUZmU7s+ocI1Ta5TtHRKTKjcxnJWwh0ZTdYtr+JipAhogU7jCe/ju/yGdXVZ4 Knmg== 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=NtRTKEB37DwYhIVNmtU2wZW+F/kowg1E9Z93WuSLvZ0=; b=zkhoQ/gGyaUhbQqRduhZozQ4SV0ugPVZcLGaEj+D6ePx9MICtQ6z7LNkiNQDWNl8FR f3BKRtqL1KnRN/Vx7Ju3t2bcDQA/WWDbkh69F969bzrTu7LlQRXJI/nppoJ0QSsOwuDb mkyoLAYxrqvzk71l/zJuJcy6J2Wn7WnogyIXnNdszR0y0BbN/zNvsxJQEvWy3AWgtDwm N/g7iYjCjNdYWLq7dhgQWnV70wbyRNHApvIz54nXDmUgmvHMqAt2B2SXCoRpCDKFoGVu pdaor4SiGLKJDah8vl9s1/yqFUrGQAnfRFgGcAZRk/zR2olhNgZAfx/Sic2eqELcE03d Ud9g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=YN9RYezY; 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 q95-20020a17090a17e800b001fd7b0552b0si10186293pja.37.2022.09.26.05.59.38; Mon, 26 Sep 2022 05:59:50 -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=YN9RYezY; 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 S234428AbiIZLVa (ORCPT + 99 others); Mon, 26 Sep 2022 07:21:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44914 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235319AbiIZLTg (ORCPT ); Mon, 26 Sep 2022 07:19:36 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3E23E5300D; Mon, 26 Sep 2022 03:39:04 -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 ams.source.kernel.org (Postfix) with ESMTPS id DDAE7B80942; Mon, 26 Sep 2022 10:37:20 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 39252C433C1; Mon, 26 Sep 2022 10:37:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1664188639; bh=eugTPWA4tapPEbaTlrgjMVBwSsaEBg3CTel76hGAlhM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YN9RYezYVrwQSHHkitTOCGrm4JWA8pKQYxgOOCLQezCh4g5lcXmFoglWAXandmzTa kHErSsIGrpwdammrPBafWP8x7YtrlSzBY4pssRiADa55KhcxwlVEGzccf8hSkFMSAw MjNuN7D1De3LzXLapFfXX9mkBPGgVknA2+h65ymo= 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.15 073/148] net: phy: aquantia: wait for the suspend/resume operations to finish Date: Mon, 26 Sep 2022 12:11:47 +0200 Message-Id: <20220926100758.771162872@linuxfoundation.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220926100756.074519146@linuxfoundation.org> References: <20220926100756.074519146@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 3221224525ac..2f2765d7f84c 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; @@ -598,16 +607,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