From patchwork Thu Jun 9 00:28:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 12874737 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 919FDC43334 for ; Thu, 9 Jun 2022 00:30:26 +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=l0jscaeCmb16S1KIn1HXb3J0cwlTBpZL9i69oAy3Jtg=; b=u6NAf+7zuROaNw 0nTZy/ku5jDK384pc7ocD5hCMW41Wb6/D9YXU5/0gyJufel1cdtQ71MVQUwN8JZfrvVdvVO5B9zcf bsxg+YmYsTW0B+lldKlQ/RdgoZ6n0YZJB5ExzLOcknGts55IQSrpnfNnj2cBPgIZStiV4g2fkmw/T j2UFTBKMN1Z8nb7A9yRw1bg528fDjcQJWmOXVTRzz/USEv1mvkP55SBeVCC7w8T3DVL9CLVP29zO2 kN+UI3+huX6hEUDTC+QrXxhvUKlKy8GcISiAy0ympjSW8nobvTWT7koHN3arKjbSgvif7u5Y7KSPp /0I8YBO1iFZ62551bvDQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nz62y-00FKLN-IS; Thu, 09 Jun 2022 00:29:12 +0000 Received: from mail-ej1-x629.google.com ([2a00:1450:4864:20::629]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nz62n-00FKIz-6Z for linux-arm-kernel@lists.infradead.org; Thu, 09 Jun 2022 00:29:02 +0000 Received: by mail-ej1-x629.google.com with SMTP id h23so33401501ejj.12 for ; Wed, 08 Jun 2022 17:28:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=iZYilu8fPT/X0/rC3yI2GAgJU7tXE0lBGVOQjpp6qfg=; b=Eh/MIYG2mfr8DWBEbA8RjQdvZyriooYS+sRRTbmbx0KeybrKZe2Gds8SidizZcl0uF Zwc0bNBw5DWZ/f3vwVvZ028NZj5qUltbENvd+jrl5410z2/pp3tbV02gdER9psqVPkf5 /fSDZi+VeSIs3ktCmBGrGjWyOVJwfAY3zzDz4vyQHi9dB/lb9GO6VdrTPW0I5nu2DEWi 1YgxaJEhnXrWpmMWwcu5TnUutF/t/br69v1D52bMEi89GFcZyXWxcdOIHAwuLeCKPey3 cy8VMJXGmdGls+p7Fz4gC4vTljIMM3kIwsZtbx90SBiBSt3oxn+FeahKrNRNb1q6RBkf LYrg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=iZYilu8fPT/X0/rC3yI2GAgJU7tXE0lBGVOQjpp6qfg=; b=OG6itpu5Dnr6Siqq3NJjJXM8ppoGPMJ5UGoaxU1Qi0KA8pqMKn7dBdNSMqa+WaI3V5 Lvuqjr/IzTCLrTdjAaQ9Anp0J3q7E/R8E6ti+p2JEfc0/lPZ/c2RPA5SYDKvqRM1UD47 IZrXCr62N2MQioP1IpYp+dAjc+MZIp9D3f6d00akEAvsZ3A7OZo9zfqAftfR5BXZOR9U RzXmy8zL2m2Zt1HShgQ6qCtrT7zs3o5BPD3COLWYgJC1HP+o5NVYkIIrwgnv0jjk5Wmw Vh9gyAtHwyEZczcFukhQkbpGGlgN0mDeqHKvscORZkoWiMhRDTM4BNiWcFgTlzTEgLH2 d4/Q== X-Gm-Message-State: AOAM530+cIQz8069e4hRKYTe8/4NKthfEH6xb7VYZxwLd7Op/uTOe54o +UAbwLxKfGCOr3Kr3ufK7pI= X-Google-Smtp-Source: ABdhPJz+2lELdvabfIWbfohoHH9dl6Q+0YhytqLPBbaw5WQ97ArKPw0ZDiQDPP9b2Y9CzTJCpKNLEg== X-Received: by 2002:a17:906:4784:b0:6ff:34ea:d824 with SMTP id cw4-20020a170906478400b006ff34ead824mr34687999ejc.526.1654734534147; Wed, 08 Jun 2022 17:28:54 -0700 (PDT) Received: from localhost.localdomain (93-42-70-190.ip85.fastwebnet.it. [93.42.70.190]) by smtp.googlemail.com with ESMTPSA id g22-20020aa7c596000000b0042deea0e961sm13110325edq.67.2022.06.08.17.28.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Jun 2022 17:28:53 -0700 (PDT) From: Christian 'Ansuel' Marangi To: Giuseppe Cavallaro , Alexandre Torgue , Jose Abreu , "David S. Miller" , Jakub Kicinski , Paolo Abeni , Maxime Coquelin , netdev@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Christian 'Ansuel' Marangi , Mark Mentovai Subject: [net-next PATCH 2/2] net: ethernet: stmmac: reset force speed bit for ipq806x Date: Thu, 9 Jun 2022 02:28:31 +0200 Message-Id: <20220609002831.24236-2-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220609002831.24236-1-ansuelsmth@gmail.com> References: <20220609002831.24236-1-ansuelsmth@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220608_172901_284184_49F554A7 X-CRM114-Status: GOOD ( 19.12 ) 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 Some bootloader may set the force speed regs even if the actual interface should use autonegotiation between PCS and PHY. This cause the complete malfuction of the interface. To fix this correctly reset the force speed regs if a fixed-link is not defined in the DTS. With a fixed-link node correctly configure the forced speed regs to handle any misconfiguration by the bootloader. Reported-by: Mark Mentovai Co-developed-by: Mark Mentovai Signed-off-by: Mark Mentovai Signed-off-by: Christian 'Ansuel' Marangi --- .../ethernet/stmicro/stmmac/dwmac-ipq806x.c | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-ipq806x.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-ipq806x.c index 832f442254d8..0f2f2bc6873d 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-ipq806x.c +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-ipq806x.c @@ -66,6 +66,17 @@ #define NSS_COMMON_CLK_DIV_SGMII_100 4 #define NSS_COMMON_CLK_DIV_SGMII_10 49 +#define QSGMII_PCS_ALL_CH_CTL 0x80 +#define QSGMII_PCS_CH_SPEED_FORCE BIT(1) +#define QSGMII_PCS_CH_SPEED_10 0x0 +#define QSGMII_PCS_CH_SPEED_100 BIT(2) +#define QSGMII_PCS_CH_SPEED_1000 BIT(3) +#define QSGMII_PCS_CH_SPEED_MASK (QSGMII_PCS_CH_SPEED_FORCE | \ + QSGMII_PCS_CH_SPEED_10 | \ + QSGMII_PCS_CH_SPEED_100 | \ + QSGMII_PCS_CH_SPEED_1000) +#define QSGMII_PCS_CH_SPEED_SHIFT(x) ((x) * 4) + #define QSGMII_PCS_CAL_LCKDT_CTL 0x120 #define QSGMII_PCS_CAL_LCKDT_CTL_RST BIT(19) @@ -253,6 +264,56 @@ static void ipq806x_gmac_fix_mac_speed(void *priv, unsigned int speed) ipq806x_gmac_set_speed(gmac, speed); } +static int +ipq806x_gmac_configure_qsgmii_pcs_speed(struct ipq806x_gmac *gmac) +{ + struct platform_device *pdev = gmac->pdev; + struct device *dev = &pdev->dev; + struct device_node *dn; + int link_speed; + int val = 0; + int ret; + + /* Some bootloader may apply wrong configuration and cause + * not functioning port. If fixed link is not set, + * reset the force speed bit. + */ + if (!of_phy_is_fixed_link(pdev->dev.of_node)) + goto write; + + dn = of_get_child_by_name(pdev->dev.of_node, "fixed-link"); + ret = of_property_read_u32(dn, "speed", &link_speed); + if (ret) { + dev_err(dev, "found fixed-link node with no speed"); + return ret; + } + + of_node_put(dn); + + val = QSGMII_PCS_CH_SPEED_FORCE; + + switch (link_speed) { + case SPEED_1000: + val |= QSGMII_PCS_CH_SPEED_1000; + break; + case SPEED_100: + val |= QSGMII_PCS_CH_SPEED_100; + break; + case SPEED_10: + val |= QSGMII_PCS_CH_SPEED_10; + break; + } + +write: + regmap_update_bits(gmac->qsgmii_csr, QSGMII_PCS_ALL_CH_CTL, + QSGMII_PCS_CH_SPEED_MASK << + QSGMII_PCS_CH_SPEED_SHIFT(gmac->id), + val << + QSGMII_PCS_CH_SPEED_SHIFT(gmac->id)); + + return 0; +} + static const struct soc_device_attribute ipq806x_gmac_soc_v1[] = { { .revision = "1.*", @@ -400,6 +461,10 @@ static int ipq806x_gmac_probe(struct platform_device *pdev) err = ipq806x_gmac_configure_qsgmii_params(gmac); if (err) goto err_remove_config_dt; + + err = ipq806x_gmac_configure_qsgmii_pcs_speed(gmac); + if (err) + goto err_remove_config_dt; } plat_dat->has_gmac = true;