Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp2988349pxb; Tue, 12 Oct 2021 18:20:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx0apVG+iwFDJYpkMr2QGHZWp+Gxodl4sD0/VFwfmAoe3r2/R3Ml4ViUmShFpmI8ZO4evs2 X-Received: by 2002:a05:6402:34d0:: with SMTP id w16mr5067667edc.98.1634088038533; Tue, 12 Oct 2021 18:20:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634088038; cv=none; d=google.com; s=arc-20160816; b=weO4mN4dn5SiTiNwhQjb0A2i3jdkm/VVJfgp/hHGGJlf/CtkeCrgRUBr/PrwqVIJ1W YA4wltxd64fuWkINtXVzOdR4sqheZYu9/lZI76EhjRhOfWe6OIseVyw3+VX3eb9g1M5b ApITjlkfEVjwCFM/3/vXf8Psxwl1YnB8zjO7+rea9BW9VMXYqZsEUhThHloAhVKCUguR i0lGx1TFXXgoSOzsWXXkKl+ZwyOYc5nsp+jZKbV4xouSrcR1E9Ypz+/LudDm1LyhUtnE iAVvplaieREcA1fWvXmZTg8RIQts+vmpjAs7yH2oO1dHfVkNbUJcxB+4KnuHRbScYH53 gDFg== 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:to:from :dkim-signature; bh=TuRIlkJdtqL0gPG5D7UDvqMp8AhmcdfXDRObs+gzAyw=; b=GLZqgRemM8KrR76o90W+cNY2SdTCGJNTecxvH34GalbhB/wtqGt35v2KPio+s09i4O yQm6oZC8hPTQgC8gxIdpUC2TOgdeecY/MQGa122t2Q659d7yrv1/i4PWwvdthoCZKbAp S04K5gQiwfbWrZegwTQl1FulxxbgT7I3iSsM1CcKf/nTS3ZORo4KFALd4W1T50ZZjQP+ E11SCHkSyqnGC2SlloY6zi+QVhbVno3qLp2NmEYTIBuls5QhlBBO9B390fU6EAad4OhR 6A3rXhMbSmvEkVOwtWK195vZ1ce1WFONMIfjSS60Qoyq4Lka4wmCOBRdy3ax5C+DkpJb r0kw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=pujEicU7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a9si17643995ejj.255.2021.10.12.18.20.15; Tue, 12 Oct 2021 18:20:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=pujEicU7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237265AbhJMBTY (ORCPT + 99 others); Tue, 12 Oct 2021 21:19:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37966 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237273AbhJMBSv (ORCPT ); Tue, 12 Oct 2021 21:18:51 -0400 Received: from mail-ed1-x531.google.com (mail-ed1-x531.google.com [IPv6:2a00:1450:4864:20::531]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 04EACC061773; Tue, 12 Oct 2021 18:16:42 -0700 (PDT) Received: by mail-ed1-x531.google.com with SMTP id r18so3057177edv.12; Tue, 12 Oct 2021 18:16:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=TuRIlkJdtqL0gPG5D7UDvqMp8AhmcdfXDRObs+gzAyw=; b=pujEicU7sjpgpK9WsE/u9Xuxn1NAZNkQp5a84kiKNv5td66MbUxJDHqP4ur4OlxjBf Qudke+TxpywctmzJKOWZtH9S6K6K5zWU835LcCMVKR5o9iEzErg4m2QHS63Ok1/LtYzT 4pmCvUQuDhHZgkj+RMP85osN5Uv+E5w8q7Gr/I5nohcSnxC9G01TslmXFIIccY0QiTRb oTbnJZ3np4A/VeGODexKvBf75AO6UJ0e1JE/+EUR19bB2vkhoz8y58OOkghMxePWWKIx Tkvxs4F8IQf7IwmAAcnXzYmvO28YtSa8ILuwsqfGX4dVuQHPQoag9lgHrZP915fTWbPE JAKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=TuRIlkJdtqL0gPG5D7UDvqMp8AhmcdfXDRObs+gzAyw=; b=47EEPHxthxv17XMbpQR1+fRrloYcVGDzn5T7ebJxs8eF8svWDuWzg+jgG7jtFN1sK9 TP6rOV7LPgh5lT7wFGA7uoDdqXEJM4WhLlLQjPHg63zdD0dasD74rfjdORQ5ZchZMZA1 Ay4hTjDn2wCCA6H9IJBXNs9t2TGm/uP59JJi0eBgEYJ/+mc+mY4NX+5a0/zKQchOwTYW Egfg1DSdwP/kaZ8eDWjN/IOHTbQ2MqvM6yKpW+2OZQ+T4Ir00rjgMqIbzwg01aFZijRY kw6ywv8LL4g9Nastf7PqhxImn16YCbIrVbRsDuNwDIGc/w9YEmeO6yla/zsQowIQLOdM 8wxA== X-Gm-Message-State: AOAM530xBAkZ2lxH5J/k7kvTJGnholBPZk+RoUSuyylRbX07aMnWhkQ7 z5UWUhg4R6helcQ1uBK9CRo= X-Received: by 2002:a17:906:c256:: with SMTP id bl22mr25439454ejb.459.1634087801422; Tue, 12 Oct 2021 18:16:41 -0700 (PDT) Received: from Ansuel-xps.localdomain (93-42-71-246.ip85.fastwebnet.it. [93.42.71.246]) by smtp.googlemail.com with ESMTPSA id v13sm6894630ede.79.2021.10.12.18.16.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Oct 2021 18:16:41 -0700 (PDT) From: Ansuel Smith To: Andrew Lunn , Vivien Didelot , Florian Fainelli , Vladimir Oltean , "David S. Miller" , Jakub Kicinski , Rob Herring , Andy Gross , Bjorn Andersson , Russell King , John Crispin , Ansuel Smith , netdev@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org Subject: [net-next PATCH v6 13/16] net: dsa: qca8k: set internal delay also for sgmii Date: Wed, 13 Oct 2021 03:16:19 +0200 Message-Id: <20211013011622.10537-14-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20211013011622.10537-1-ansuelsmth@gmail.com> References: <20211013011622.10537-1-ansuelsmth@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org QCA original code report port instability and sa that SGMII also require to set internal delay. Generalize the rgmii delay function and apply the advised value if they are not defined in DT. Signed-off-by: Ansuel Smith --- drivers/net/dsa/qca8k.c | 88 ++++++++++++++++++++++++++++------------- drivers/net/dsa/qca8k.h | 2 + 2 files changed, 62 insertions(+), 28 deletions(-) diff --git a/drivers/net/dsa/qca8k.c b/drivers/net/dsa/qca8k.c index fc42f86ca898..2937c6b73e8e 100644 --- a/drivers/net/dsa/qca8k.c +++ b/drivers/net/dsa/qca8k.c @@ -1004,6 +1004,7 @@ qca8k_parse_port_config(struct qca8k_priv *priv) case PHY_INTERFACE_MODE_RGMII_ID: case PHY_INTERFACE_MODE_RGMII_TXID: case PHY_INTERFACE_MODE_RGMII_RXID: + case PHY_INTERFACE_MODE_SGMII: delay = 0; if (!of_property_read_u32(port_dn, "tx-internal-delay-ps", &delay)) @@ -1036,8 +1037,13 @@ qca8k_parse_port_config(struct qca8k_priv *priv) priv->rgmii_rx_delay[cpu_port_index] = delay; - break; - case PHY_INTERFACE_MODE_SGMII: + /* Skip sgmii parsing for rgmii* mode */ + if (mode == PHY_INTERFACE_MODE_RGMII || + mode == PHY_INTERFACE_MODE_RGMII_ID || + mode == PHY_INTERFACE_MODE_RGMII_TXID || + mode == PHY_INTERFACE_MODE_RGMII_RXID) + break; + if (of_property_read_bool(port_dn, "qca,sgmii-txclk-falling-edge")) priv->sgmii_tx_clk_falling_edge = true; @@ -1261,13 +1267,54 @@ qca8k_setup(struct dsa_switch *ds) return 0; } +static void +qca8k_mac_config_setup_internal_delay(struct qca8k_priv *priv, int cpu_port_index, + u32 reg) +{ + u32 delay, val = 0; + int ret; + + /* Delay can be declared in 3 different way. + * Mode to rgmii and internal-delay standard binding defined + * rgmii-id or rgmii-tx/rx phy mode set. + * The parse logic set a delay different than 0 only when one + * of the 3 different way is used. In all other case delay is + * not enabled. With ID or TX/RXID delay is enabled and set + * to the default and recommended value. + */ + if (priv->rgmii_tx_delay[cpu_port_index]) { + delay = priv->rgmii_tx_delay[cpu_port_index]; + + val |= QCA8K_PORT_PAD_RGMII_TX_DELAY(delay) | + QCA8K_PORT_PAD_RGMII_TX_DELAY_EN; + } + + if (priv->rgmii_rx_delay[cpu_port_index]) { + delay = priv->rgmii_rx_delay[cpu_port_index]; + + val |= QCA8K_PORT_PAD_RGMII_RX_DELAY(delay) | + QCA8K_PORT_PAD_RGMII_RX_DELAY_EN; + } + + /* Set RGMII delay based on the selected values */ + ret = qca8k_rmw(priv, reg, + QCA8K_PORT_PAD_RGMII_TX_DELAY_MASK | + QCA8K_PORT_PAD_RGMII_RX_DELAY_MASK | + QCA8K_PORT_PAD_RGMII_TX_DELAY_EN | + QCA8K_PORT_PAD_RGMII_RX_DELAY_EN, + val); + if (ret) + dev_err(priv->dev, "Failed to set internal delay for CPU port%d", + cpu_port_index == QCA8K_CPU_PORT0 ? 0 : 6); +} + static void qca8k_phylink_mac_config(struct dsa_switch *ds, int port, unsigned int mode, const struct phylink_link_state *state) { struct qca8k_priv *priv = ds->priv; int cpu_port_index, ret; - u32 reg, val, delay; + u32 reg, val; switch (port) { case 0: /* 1st CPU port */ @@ -1316,32 +1363,10 @@ qca8k_phylink_mac_config(struct dsa_switch *ds, int port, unsigned int mode, case PHY_INTERFACE_MODE_RGMII_ID: case PHY_INTERFACE_MODE_RGMII_TXID: case PHY_INTERFACE_MODE_RGMII_RXID: - val = QCA8K_PORT_PAD_RGMII_EN; - - /* Delay can be declared in 3 different way. - * Mode to rgmii and internal-delay standard binding defined - * rgmii-id or rgmii-tx/rx phy mode set. - * The parse logic set a delay different than 0 only when one - * of the 3 different way is used. In all other case delay is - * not enabled. With ID or TX/RXID delay is enabled and set - * to the default and recommended value. - */ - if (priv->rgmii_tx_delay[cpu_port_index]) { - delay = priv->rgmii_tx_delay[cpu_port_index]; - - val |= QCA8K_PORT_PAD_RGMII_TX_DELAY(delay) | - QCA8K_PORT_PAD_RGMII_TX_DELAY_EN; - } - - if (priv->rgmii_rx_delay[cpu_port_index]) { - delay = priv->rgmii_rx_delay[cpu_port_index]; - - val |= QCA8K_PORT_PAD_RGMII_RX_DELAY(delay) | - QCA8K_PORT_PAD_RGMII_RX_DELAY_EN; - } + qca8k_write(priv, reg, QCA8K_PORT_PAD_RGMII_EN); - /* Set RGMII delay based on the selected values */ - qca8k_write(priv, reg, val); + /* Configure rgmii delay */ + qca8k_mac_config_setup_internal_delay(priv, cpu_port_index, reg); /* QCA8337 requires to set rgmii rx delay for all ports. * This is enabled through PORT5_PAD_CTRL for all ports, @@ -1412,6 +1437,13 @@ qca8k_phylink_mac_config(struct dsa_switch *ds, int port, unsigned int mode, QCA8K_PORT0_PAD_SGMII_RXCLK_FALLING_EDGE | QCA8K_PORT0_PAD_SGMII_TXCLK_FALLING_EDGE, val); + + /* From original code is reported port instability as SGMII also + * require delay set. Apply advised values here or take them from DT. + */ + if (state->interface == PHY_INTERFACE_MODE_SGMII) + qca8k_mac_config_setup_internal_delay(priv, cpu_port_index, reg); + break; default: dev_err(ds->dev, "xMII mode %s not supported for port %d\n", diff --git a/drivers/net/dsa/qca8k.h b/drivers/net/dsa/qca8k.h index 9c115cfe613b..c5ca6277b45b 100644 --- a/drivers/net/dsa/qca8k.h +++ b/drivers/net/dsa/qca8k.h @@ -39,7 +39,9 @@ #define QCA8K_REG_PORT5_PAD_CTRL 0x008 #define QCA8K_REG_PORT6_PAD_CTRL 0x00c #define QCA8K_PORT_PAD_RGMII_EN BIT(26) +#define QCA8K_PORT_PAD_RGMII_TX_DELAY_MASK GENMASK(23, 22) #define QCA8K_PORT_PAD_RGMII_TX_DELAY(x) ((x) << 22) +#define QCA8K_PORT_PAD_RGMII_RX_DELAY_MASK GENMASK(21, 20) #define QCA8K_PORT_PAD_RGMII_RX_DELAY(x) ((x) << 20) #define QCA8K_PORT_PAD_RGMII_TX_DELAY_EN BIT(25) #define QCA8K_PORT_PAD_RGMII_RX_DELAY_EN BIT(24) -- 2.32.0