From: Maxime Chevallier <maxime.chevallier@bootlin.com>
To: Sneh Shah <quic_snehshah@quicinc.com>
Cc: Vinod Koul <vkoul@kernel.org>,
Bhupesh Sharma <bhupesh.sharma@linaro.org>,
Alexandre Torgue <alexandre.torgue@foss.st.com>,
Jose Abreu <joabreu@synopsys.com>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Maxime Coquelin <mcoquelin.stm32@gmail.com>,
netdev@vger.kernel.org, linux-arm-msm@vger.kernel.org,
linux-stm32@st-md-mailman.stormreply.com,
linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org,
Andrew Halaney <ahalaney@redhat.com>,
kernel@quicinc.com
Subject: Re: [PATCH net-next] net: stmmac: dwmac-qcom-ethqos: Add support for 2.5G SGMII
Date: Mon, 18 Dec 2023 15:21:12 +0100 [thread overview]
Message-ID: <20231218152112.4adc5961@device-28.home> (raw)
In-Reply-To: <20231218071118.21879-1-quic_snehshah@quicinc.com>
Hi,
On Mon, 18 Dec 2023 12:41:18 +0530
Sneh Shah <quic_snehshah@quicinc.com> wrote:
> Serdes phy needs to operate at 2500 mode for 2.5G speed and 1000
> mode for 1G/100M/10M speed.
> Added changes to configure serdes phy and mac based on link speed.
>
> Signed-off-by: Sneh Shah <quic_snehshah@quicinc.com>
> ---
> .../stmicro/stmmac/dwmac-qcom-ethqos.c | 31 +++++++++++++++++--
> 1 file changed, 29 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-qcom-ethqos.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-qcom-ethqos.c
> index d3bf42d0fceb..b3a28dc19161 100644
> --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-qcom-ethqos.c
> +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-qcom-ethqos.c
> @@ -21,6 +21,7 @@
> #define RGMII_IO_MACRO_CONFIG2 0x1C
> #define RGMII_IO_MACRO_DEBUG1 0x20
> #define EMAC_SYSTEM_LOW_POWER_DEBUG 0x28
> +#define ETHQOS_MAC_AN_CTRL 0xE0
>
> /* RGMII_IO_MACRO_CONFIG fields */
> #define RGMII_CONFIG_FUNC_CLK_EN BIT(30)
> @@ -78,6 +79,10 @@
> #define ETHQOS_MAC_CTRL_SPEED_MODE BIT(14)
> #define ETHQOS_MAC_CTRL_PORT_SEL BIT(15)
>
> +/*ETHQOS_MAC_AN_CTRL bits */
> +#define ETHQOS_MAC_AN_CTRL_RAN BIT(9)
> +#define ETHQOS_MAC_AN_CTRL_ANE BIT(12)
> +
> struct ethqos_emac_por {
> unsigned int offset;
> unsigned int value;
> @@ -109,6 +114,7 @@ struct qcom_ethqos {
> unsigned int num_por;
> bool rgmii_config_loopback_en;
> bool has_emac_ge_3;
> + unsigned int serdes_speed;
Looks like you are storing SPEED_XXX definitions here, which can be
negative in case of SPEED_UNKNOWN, so this should be an int.
> };
>
> static int rgmii_readl(struct qcom_ethqos *ethqos, unsigned int offset)
> @@ -600,27 +606,47 @@ static int ethqos_configure_rgmii(struct qcom_ethqos *ethqos)
>
> static int ethqos_configure_sgmii(struct qcom_ethqos *ethqos)
> {
> - int val;
> -
> + int val, mac_an_value;
> val = readl(ethqos->mac_base + MAC_CTRL_REG);
> + mac_an_value = readl(ethqos->mac_base + ETHQOS_MAC_AN_CTRL);
>
> switch (ethqos->speed) {
> + case SPEED_2500:
> + val &= ~ETHQOS_MAC_CTRL_PORT_SEL;
> + rgmii_updatel(ethqos, RGMII_CONFIG2_RGMII_CLK_SEL_CFG,
> + RGMII_CONFIG2_RGMII_CLK_SEL_CFG,
> + RGMII_IO_MACRO_CONFIG2);
> + if (ethqos->serdes_speed != SPEED_2500)
> + phy_set_speed(ethqos->serdes_phy, ethqos->speed);
> + mac_an_value &= ~ETHQOS_MAC_AN_CTRL_ANE;
> + break;
> case SPEED_1000:
> val &= ~ETHQOS_MAC_CTRL_PORT_SEL;
> rgmii_updatel(ethqos, RGMII_CONFIG2_RGMII_CLK_SEL_CFG,
> RGMII_CONFIG2_RGMII_CLK_SEL_CFG,
> RGMII_IO_MACRO_CONFIG2);
> + if (ethqos->serdes_speed != SPEED_1000)
> + phy_set_speed(ethqos->serdes_phy, ethqos->speed);
> + mac_an_value |= ETHQOS_MAC_AN_CTRL_RAN | ETHQOS_MAC_AN_CTRL_ANE;
> break;
> case SPEED_100:
> val |= ETHQOS_MAC_CTRL_PORT_SEL | ETHQOS_MAC_CTRL_SPEED_MODE;
> + if (ethqos->serdes_speed != SPEED_1000)
> + phy_set_speed(ethqos->serdes_phy, ethqos->speed);
I understand that SGMII's serdes always runs at 1000 / 2500, but this
check doesn't make much sense then, if the speed isn't 1000, then you
set the serdes PHY's speed to 100, and the assignment that comes after
that switch-case will also set the serdes speed to 100.
Also, if the serdes PHY really needs to be configured differently for
10/100/1000, then switching from speed 1000 to speed 100 for example
won't trigger a serdes PHY reconfiguration here.
My guess is that you want something like :
phy_set_speed(ethqos->serdes_phy, SPEED_1000)
and the assignment at the end of the switch-case should be
SPEED_1000/SPEED_2500 only (see the comment bellow).
> + mac_an_value |= ETHQOS_MAC_AN_CTRL_RAN | ETHQOS_MAC_AN_CTRL_ANE;
> break;
> case SPEED_10:
> val |= ETHQOS_MAC_CTRL_PORT_SEL;
> val &= ~ETHQOS_MAC_CTRL_SPEED_MODE;
> + if (ethqos->serdes_speed != SPEED_1000)
> + phy_set_speed(ethqos->serdes_phy, ethqos->speed);
Same remark here
> + mac_an_value |= ETHQOS_MAC_AN_CTRL_RAN | ETHQOS_MAC_AN_CTRL_ANE;
> break;
> }
>
> writel(val, ethqos->mac_base + MAC_CTRL_REG);
> + writel(mac_an_value, ethqos->mac_base + ETHQOS_MAC_AN_CTRL);
> + ethqos->serdes_speed = ethqos->speed;
Although the code will behave the same, as you are storing the true
serdes speed here, shouldn't it be either SPEED_1000 or SPEED_2500 ?
You'll end-up storing SPEED_10 / SPEED_100 should the link use these
speeds, which doesn't represent the true serdes speed.
This would spare serdes reconfigurations when alternating between
10/100/1000M speeds.
> return val;
> }
> @@ -789,6 +815,7 @@ static int qcom_ethqos_probe(struct platform_device *pdev)
> "Failed to get serdes phy\n");
>
> ethqos->speed = SPEED_1000;
> + ethqos->serdes_speed = SPEED_1000;
> ethqos_update_link_clk(ethqos, SPEED_1000);
> ethqos_set_func_clk_en(ethqos);
>
Thanks,
Maxime
next prev parent reply other threads:[~2023-12-18 14:21 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-18 7:11 [PATCH net-next] net: stmmac: dwmac-qcom-ethqos: Add support for 2.5G SGMII Sneh Shah
2023-12-18 14:21 ` Maxime Chevallier [this message]
2023-12-18 14:32 ` Sneh Shah
2023-12-18 16:20 ` Andrew Halaney
2023-12-18 16:31 ` Andrew Halaney
2023-12-20 7:32 ` Sneh Shah
2023-12-20 15:59 ` Andrew Halaney
2023-12-21 8:53 ` Sneh Shah
2023-12-21 14:30 ` Andrew Halaney
2023-12-21 16:58 ` [Linux-stm32] " Maxime Chevallier
2024-05-26 16:27 ` Russell King (Oracle)
2024-05-28 22:35 ` Andrew Halaney
2024-05-29 14:13 ` Sneh Shah
2024-05-29 14:28 ` Andrew Lunn
2024-05-29 20:13 ` Russell King (Oracle)
2024-06-03 11:15 ` Sneh Shah
2024-05-29 20:09 ` Russell King (Oracle)
2024-06-03 11:27 ` Sneh Shah
2024-06-03 13:12 ` Russell King (Oracle)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20231218152112.4adc5961@device-28.home \
--to=maxime.chevallier@bootlin.com \
--cc=ahalaney@redhat.com \
--cc=alexandre.torgue@foss.st.com \
--cc=bhupesh.sharma@linaro.org \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=joabreu@synopsys.com \
--cc=kernel@quicinc.com \
--cc=kuba@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-stm32@st-md-mailman.stormreply.com \
--cc=mcoquelin.stm32@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=quic_snehshah@quicinc.com \
--cc=vkoul@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).