Received: by 2002:a05:6358:5282:b0:b5:90e7:25cb with SMTP id g2csp3796415rwa; Tue, 23 Aug 2022 10:13:49 -0700 (PDT) X-Google-Smtp-Source: AA6agR5KCfNOKWP/2Rx6pXVLo6DWaf4e6dN9qBe/NhP0am7rlngiGln7mDxrsAAXqtX1VPgKwyXV X-Received: by 2002:a17:902:7483:b0:172:e7ea:2545 with SMTP id h3-20020a170902748300b00172e7ea2545mr10717486pll.88.1661274829467; Tue, 23 Aug 2022 10:13:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661274829; cv=none; d=google.com; s=arc-20160816; b=K6EpBeO3seChEpMsa/KVqbaDVOY6seX0OYZReOPSkLgHJ0ZjLU5kmc8wP/aRWR4g9x kVKLtCfHm30VOPUeQLQ1PThjeigxDBlHpG3ukc5cf12CT1GjsTEp4PQph4gLJPYQEo3f Xb7Ndys0+6HU8YY3eAd2zQQUBEYzzr1OhzfYdpqzo/3m7uzvUnMHnSBBdbJGmKNS6Ppd BYvBJFeGsb3gwXk/K6GrrZA17bzbBIUQ6euTLqmaO43WG/sXqUKQz/XcNqR10vDtKxGz wiVTeYpwon9CtU/sZsDXOoR9Nam+aBvraObRGX667iUituZl0b5zZIqmyY9io9p7P5qS UK8A== 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=B6DzPRsUZD3BX7st5mrwg1j5KcZUXUd28krvVfkgAGo=; b=bdEqyzVOfk/OX4wy3t6gNtAjGyPEiimXjMBkCPJ1T9+r/HGKVdFeYZQUhpWp9eJ1Kr FYruKnnOVF81tfMTVaT9bFyRwJ6cBGuFIrlYxIThYXhDge1rJW/efAgvzi+x0Sc7NX6n 1L5CldSlTb9uiCtoR41Ggw4kth9+bCv6Qqc7dtxPMAGukciMPx2e/Y8zGPtkqHbEnZfR EPBMtCQ5Y6sdhk+IdB/nMtgCi1o+NINZlOcafGN55V5bQpE4729pEN3a6lo0Q3gZR9H0 dYgti9EeO3ha65ZtXH9xVCRHb6FtrjJuoNEFDaplVj0rHseigq3XCWgiUhsvnVtS28V0 gDQA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=mlkn26nH; 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=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t4-20020a17090a4e4400b001efbdf44c12si17153064pjl.97.2022.08.23.10.13.37; Tue, 23 Aug 2022 10:13:49 -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=@bootlin.com header.s=gm1 header.b=mlkn26nH; 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=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344031AbiHWRHt (ORCPT + 99 others); Tue, 23 Aug 2022 13:07:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50732 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343892AbiHWRG2 (ORCPT ); Tue, 23 Aug 2022 13:06:28 -0400 Received: from relay10.mail.gandi.net (relay10.mail.gandi.net [217.70.178.230]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EF4B2E3992; Tue, 23 Aug 2022 07:05:31 -0700 (PDT) Received: (Authenticated sender: maxime.chevallier@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id 127FB240004; Tue, 23 Aug 2022 14:05:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1661263530; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=B6DzPRsUZD3BX7st5mrwg1j5KcZUXUd28krvVfkgAGo=; b=mlkn26nHT8xgDfLXsM45ZguG7mU0caECQX8lOtsx4dWNzdLMa1GQsRljS31vH+R8Glz9nK mRMMMZJDMyrXOn4UrvCVgLfY5PvpiYGY+/bYsLnh7Zw/QfFsFYbXGyULYE7hq9OC+EXRp0 JyoBhYybXhjFK6WGLtcPn30BZhcpPayhQ5RzGW+PgSBLQ71HlyZ2fJiRiCqIpow2JQsrAx YDvK9yc2sgXgVyLVbpxrsm5TC2AwSDdMQujp/WlsX1VsgG8L7oEbYisfKTA7gClqHj+WYl OuBzRWJkdfKFcV8US/XGzVGu3Al+BV2b6UFtmk0fR7+TZnPw8LmkjRWNbjh+4g== From: Maxime Chevallier To: davem@davemloft.net Cc: Maxime Chevallier , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, thomas.petazzoni@bootlin.com, Andrew Lunn , Jakub Kicinski , Eric Dumazet , Paolo Abeni , Florian Fainelli , Heiner Kallweit , Russell King , linux-arm-kernel@lists.infradead.org Subject: [PATCH net-next 1/2] net: altera: tse: add a dedicated helper for reset Date: Tue, 23 Aug 2022 16:05:16 +0200 Message-Id: <20220823140517.3091239-2-maxime.chevallier@bootlin.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220823140517.3091239-1-maxime.chevallier@bootlin.com> References: <20220823140517.3091239-1-maxime.chevallier@bootlin.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE 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 Performing a soft reset on the PCS block for altera TSE re-initializes the decoding logic, and should be done when reconfiguring the link. Move the reset logic to a dedicated helper, to ease transition to phylink. Signed-off-by: Maxime Chevallier --- drivers/net/ethernet/altera/altera_tse_main.c | 35 +++++++++++-------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/drivers/net/ethernet/altera/altera_tse_main.c b/drivers/net/ethernet/altera/altera_tse_main.c index 8c5828582c21..ad59b0befc18 100644 --- a/drivers/net/ethernet/altera/altera_tse_main.c +++ b/drivers/net/ethernet/altera/altera_tse_main.c @@ -107,6 +107,25 @@ static int sgmii_pcs_scratch_test(struct altera_tse_private *priv, u16 value) return (sgmii_pcs_read(priv, SGMII_PCS_SCRATCH) == value); } +static int sgmii_pcs_reset(struct altera_tse_private *priv) +{ + u16 bmcr; + int i = 0; + + /* Reset PCS block */ + bmcr = sgmii_pcs_read(priv, MII_BMCR); + bmcr |= BMCR_RESET; + sgmii_pcs_write(priv, MII_BMCR, bmcr); + + for (i = 0; i < SGMII_PCS_SW_RESET_TIMEOUT; i++) { + if (!(sgmii_pcs_read(priv, MII_BMCR) & BMCR_RESET)) + return 0; + udelay(1); + } + + return -ETIMEDOUT; +} + /* MDIO specific functions */ static int altera_tse_mdio_read(struct mii_bus *bus, int mii_id, int regnum) @@ -1092,7 +1111,6 @@ static void tse_set_rx_mode(struct net_device *dev) static int init_sgmii_pcs(struct net_device *dev) { struct altera_tse_private *priv = netdev_priv(dev); - int n; unsigned int tmp_reg = 0; if (priv->phy_iface != PHY_INTERFACE_MODE_SGMII) @@ -1131,20 +1149,7 @@ static int init_sgmii_pcs(struct net_device *dev) tmp_reg |= (BMCR_SPEED1000 | BMCR_FULLDPLX | BMCR_ANENABLE); sgmii_pcs_write(priv, MII_BMCR, tmp_reg); - /* Reset PCS block */ - tmp_reg |= BMCR_RESET; - sgmii_pcs_write(priv, MII_BMCR, tmp_reg); - for (n = 0; n < SGMII_PCS_SW_RESET_TIMEOUT; n++) { - if (!(sgmii_pcs_read(priv, MII_BMCR) & BMCR_RESET)) { - netdev_info(dev, "SGMII PCS block initialised OK\n"); - return 0; - } - udelay(1); - } - - /* We failed to reset the block, return a timeout */ - netdev_err(dev, "SGMII PCS block reset failed.\n"); - return -ETIMEDOUT; + return sgmii_pcs_reset(priv); } /* Open and initialize the interface -- 2.37.2