Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp5735564rwi; Sun, 23 Oct 2022 10:56:43 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5iGSJoZcPgHmdAXLE3xHmAkLtbEtWqogrE4BaCopCtmDCXzPMDuheTDhr/o9ImSxQQVx+p X-Received: by 2002:a17:90b:3715:b0:213:2d7:3164 with SMTP id mg21-20020a17090b371500b0021302d73164mr3598894pjb.191.1666547802814; Sun, 23 Oct 2022 10:56:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666547802; cv=none; d=google.com; s=arc-20160816; b=01UXPBpcgCSFJINrPXvg5y7tRGFm6WfRfUK0EvxjkK8C1+K/Zh72Zbi8jcetz2d4mL XpVbhOiHkJ/kuIsGDrxEW2ssSn31zFECjMVc09NQZFIXf7AhRtQ+v6hjamSI3kxhNSx5 /KN30JoAYvFFPOH9wyhy54PSa1fC1MXth7uTkJsyuKF+/2FQwturbmLXMzbu/eMU/ua8 og2lwqcOdwSMhiBdBtB6t/M/lYzR3tEiWExJsASOQQhw9rVMmq8PMr/uU/r2wGlSY++t SNPj7P32z96sJf6wnZThTprGGqZv8Hyn116YTrIf4dfyrJWOoPT2yS27kf2Uw0PVnhDu u6Vw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=152+j1ecdJ/pTxbDHF3JcWO1hEBXq3IkRPt0LcgCa1k=; b=OtxGv8iGSQUtiPtBE+4Cu3HNunA4mEXtrSf28kmJKIDhBIo8EBEpS18DYkbaK1Skly FVU42RBpke33RKAD6i6FAiEHjm67HbUTTvgPFloJCb0R+R7v/K7Mn/qG74Zt3phTyYQZ ewry+Xw2aQpSYr32l0qLm7GHjEhK1l1Q+yzD15nmlkqnt3tPxV3S9i5KipQoUBO4Odo1 AEHMKROWxwSjYbXmn5ilQqaYG9DxPQPWJ9jCvQAGuuuyRLh34tzdjAIh3Wi6Gd99Spgs DhEltoOLkw+vc6dY0oN9CK8sa8mp5g+JIGlVAT393EA8VLau28hfY7nqpGh8MXMi4Key pLkw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail (test mode) header.i=@armlinux.org.uk header.s=pandora-2019 header.b=pPoXbhHM; 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=fail (p=NONE sp=NONE dis=NONE) header.from=armlinux.org.uk Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y3-20020a1709029b8300b0017c2a42fc8csi29480773plp.270.2022.10.23.10.56.30; Sun, 23 Oct 2022 10:56:42 -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=fail (test mode) header.i=@armlinux.org.uk header.s=pandora-2019 header.b=pPoXbhHM; 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=fail (p=NONE sp=NONE dis=NONE) header.from=armlinux.org.uk Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230371AbiJWRxU (ORCPT + 99 others); Sun, 23 Oct 2022 13:53:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37042 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229728AbiJWRxS (ORCPT ); Sun, 23 Oct 2022 13:53:18 -0400 Received: from pandora.armlinux.org.uk (pandora.armlinux.org.uk [IPv6:2001:4d48:ad52:32c8:5054:ff:fe00:142]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F2B136B143; Sun, 23 Oct 2022 10:53:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=armlinux.org.uk; s=pandora-2019; h=Sender:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=152+j1ecdJ/pTxbDHF3JcWO1hEBXq3IkRPt0LcgCa1k=; b=pPoXbhHMdvPpU8DeMUjStDzBCX SHuaXIZ3Bku8RUSYvJMu5S+8tdYnEz9wsAT5dgdSd7f+AfYKY68AHt1o5Cy9p+AuUg0UAAHgNahdM Mli+le0876Z0UglZ5Vq6d9Bk/Knr6HZC1nBaPDoGePFRq+c0mPmvNuHoZlvJOkWzoRAqdMRnq+199 dWHwrDzUK75ly6A3SgzMa1D5AgcywfBJZzNT3H2+3zYTVmuhe67DoLIKkkSR/FI1aOrFbslWlZgIp 64iqMeGHjnSTkS8rzTnv1lNOHUtUPFX21FDLsIUU3ZCG5Lts5S88C6bea09kmm7OALkqSP0PpGqPB fZj1s/uA==; Received: from shell.armlinux.org.uk ([fd8f:7570:feb6:1:5054:ff:fe00:4ec]:34912) by pandora.armlinux.org.uk with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1omf9Z-0002Ao-QY; Sun, 23 Oct 2022 18:52:53 +0100 Received: from linux by shell.armlinux.org.uk with local (Exim 4.94.2) (envelope-from ) id 1omf9O-0006Gp-Ez; Sun, 23 Oct 2022 18:52:42 +0100 Date: Sun, 23 Oct 2022 18:52:42 +0100 From: "Russell King (Oracle)" To: Frank Wunderlich Cc: Frank Wunderlich , linux-mediatek@lists.infradead.org, Alexander Couzens , Felix Fietkau , John Crispin , Sean Wang , Mark Lee , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Matthias Brugger , netdev@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: Re: [PATCH v2] net: mtk_sgmii: implement mtk_pcs_ops Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Sender: Russell King (Oracle) X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_NONE 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 On Sun, Oct 23, 2022 at 06:41:45PM +0200, Frank Wunderlich wrote: > bootup: > > [ 1.098876] dev: 1 offset:0 0x81140 > [ 1.102699] dev: 1 offset:4 0x4d544950 > [ 1.106180] dev: 1 offset:8 0x1 > [ 1.109914] dev: 1 offset:32 0x3112001b > > after putting eth1 up: > > [ 32.566099] timer 0x186a0 > [ 32.623021] offset:0 0x2c1140 > [ 32.625653] offset:4 0x4d544950 > [ 32.628614] offset:8 0x40e041a0 > [ 32.631746] offset:32 0x3112011b Hi Frank, Based on this, could you give the following patch a try - it replaces my previous patch. Thanks. diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.h b/drivers/net/ethernet/mediatek/mtk_eth_soc.h index b52f3b0177ef..1a3eb3ecf7e3 100644 --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.h +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.h @@ -479,7 +479,7 @@ /* Register to programmable link timer, the unit in 2 * 8ns */ #define SGMSYS_PCS_LINK_TIMER 0x18 -#define SGMII_LINK_TIMER_DEFAULT (0x186a0 & GENMASK(19, 0)) +#define SGMII_LINK_TIMER_MASK GENMASK(19, 0) /* Register to control remote fault */ #define SGMSYS_SGMII_MODE 0x20 diff --git a/drivers/net/ethernet/mediatek/mtk_sgmii.c b/drivers/net/ethernet/mediatek/mtk_sgmii.c index 736839c84130..63736c52bab2 100644 --- a/drivers/net/ethernet/mediatek/mtk_sgmii.c +++ b/drivers/net/ethernet/mediatek/mtk_sgmii.c @@ -20,19 +20,40 @@ static struct mtk_pcs *pcs_to_mtk_pcs(struct phylink_pcs *pcs) } /* For SGMII interface mode */ -static int mtk_pcs_setup_mode_an(struct mtk_pcs *mpcs) +static int mtk_pcs_setup_mode_an(struct mtk_pcs *mpcs, + phy_interface_t interface, + const unsigned long *advertising) { - unsigned int val; + unsigned int val, link_timer; + int advertise; + bool changed; + + advertise = phylink_mii_c22_pcs_encode_advertisement(interface, + advertising); + if (advertise < 0) + return advertise; + + if (interface == PHY_INTERFACE_MODE_SGMII) + link_timer = 1600000 / 2 / 8; + else + link_timer = 10000000 / 2 / 8; /* Setup the link timer and QPHY power up inside SGMIISYS */ - regmap_write(mpcs->regmap, SGMSYS_PCS_LINK_TIMER, - SGMII_LINK_TIMER_DEFAULT); + regmap_write(mpcs->regmap, SGMSYS_PCS_LINK_TIMER, link_timer); regmap_read(mpcs->regmap, SGMSYS_SGMII_MODE, &val); + if (interface = == PHY_INTERFACE_MODE_SGMII) + val |= SGMII_IF_MODE_BIT0; + else + val &= ~SGMII_IF_MODE_BIT0; val |= SGMII_REMOTE_FAULT_DIS; regmap_write(mpcs->regmap, SGMSYS_SGMII_MODE, val); + regmap_update_bits_check(mpcs->regmap, SGMSYS_PCS_CONTROL_1 + 8, 0xffff, + advertise, &changed); + regmap_read(mpcs->regmap, SGMSYS_PCS_CONTROL_1, &val); + val |= SGMII_AN_ENABLE; val |= SGMII_AN_RESTART; regmap_write(mpcs->regmap, SGMSYS_PCS_CONTROL_1, val); @@ -40,7 +61,7 @@ static int mtk_pcs_setup_mode_an(struct mtk_pcs *mpcs) val &= ~SGMII_PHYA_PWD; regmap_write(mpcs->regmap, SGMSYS_QPHY_PWR_STATE_CTRL, val); - return 0; + return changed ? 1 : 0; } @@ -52,12 +73,6 @@ static int mtk_pcs_setup_mode_force(struct mtk_pcs *mpcs, { unsigned int val; - regmap_read(mpcs->regmap, mpcs->ana_rgc3, &val); - val &= ~RG_PHY_SPEED_MASK; - if (interface == PHY_INTERFACE_MODE_2500BASEX) - val |= RG_PHY_SPEED_3_125G; - regmap_write(mpcs->regmap, mpcs->ana_rgc3, val); - /* Disable SGMII AN */ regmap_read(mpcs->regmap, SGMSYS_PCS_CONTROL_1, &val); val &= ~SGMII_AN_ENABLE; @@ -83,13 +98,22 @@ static int mtk_pcs_config(struct phylink_pcs *pcs, unsigned int mode, bool permit_pause_to_mac) { struct mtk_pcs *mpcs = pcs_to_mtk_pcs(pcs); + unsigned int val; int err = 0; + if (interface == PHY_INTERFACE_MODE_2500BASEX) + val = RG_PHY_SPEED_3_125G; + else + val = 0; + + regmap_update_bits(mpcs->regmap, mpcs->ana_rgc3, + RG_PHY_SPEED_3_125G, val); + /* Setup SGMIISYS with the determined property */ - if (interface != PHY_INTERFACE_MODE_SGMII) + if (phylink_autoneg_inband(mode)) + err = mtk_pcs_setup_mode_an(mpcs, interface, advertising); + else if (interface != PHY_INTERFACE_MODE_SGMII) err = mtk_pcs_setup_mode_force(mpcs, interface); - else if (phylink_autoneg_inband(mode)) - err = mtk_pcs_setup_mode_an(mpcs); return err; } -- RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTP is here! 40Mbps down 10Mbps up. Decent connectivity at last!