mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Maxime Chevallier <maxime.chevallier@bootlin.com>
To: Inochi Amaoto <inochiama@gmail.com>,
	Han Gao <rabenda.cn@gmail.com>, Icenowy Zheng <uwu@icenowy.me>,
	Vivian Wang <wangruikang@iscas.ac.cn>, Yao Zi <ziyao@disroot.org>,
	Andrew Lunn <andrew+netdev@lunn.ch>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Rob Herring <robh@kernel.org>,
	Krzysztof Kozlowski <krzk+dt@kernel.org>,
	Conor Dooley <conor+dt@kernel.org>,
	Chen Wang <unicorn_wang@outlook.com>,
	Maxime Coquelin <mcoquelin.stm32@gmail.com>,
	Alexandre Torgue <alexandre.torgue@foss.st.com>,
	Heiner Kallweit <hkallweit1@gmail.com>,
	Russell King <linux@armlinux.org.uk>,
	"Russell King (Oracle)" <rmk+kernel@armlinux.org.uk>
Cc: netdev@vger.kernel.org, devicetree@vger.kernel.org,
	sophgo@lists.linux.dev, linux-kernel@vger.kernel.org,
	linux-stm32@st-md-mailman.stormreply.com,
	linux-arm-kernel@lists.infradead.org, Yixun Lan <dlan@gentoo.org>,
	Longbin Li <looong.bin@gmail.com>
Subject: Re: [PATCH v4 2/3] net: phy: Add helper for fixing RGMII PHY mode based on internal mac delay
Date: Wed, 29 Oct 2025 20:28:51 +0100	[thread overview]
Message-ID: <45ebd2eb-9b09-43fa-a451-29299b33f06a@bootlin.com> (raw)
In-Reply-To: <20251028003858.267040-3-inochiama@gmail.com>

Hi,

On 28/10/2025 01:38, Inochi Amaoto wrote:
> The "phy-mode" property of devicetree indicates whether the PCB has
> delay now, which means the mac needs to modify the PHY mode based
> on whether there is an internal delay in the mac.
> 
> This modification is similar for many ethernet drivers. To simplify
> code, define the helper phy_fix_phy_mode_for_mac_delays(speed, mac_txid,
> mac_rxid) to fix PHY mode based on whether mac adds internal delay.
> 
> Suggested-by: Russell King (Oracle) <linux@armlinux.org.uk>
> Signed-off-by: Inochi Amaoto <inochiama@gmail.com>

Name may be a bit long, but I'm not the best at naming stuff :)

I agree with the logic of that helper,

Reviewed-by: Maxime Chevallier <maxime.chevallier@bootlin.com>

Maxime

> ---
>  drivers/net/phy/phy-core.c | 43 ++++++++++++++++++++++++++++++++++++++
>  include/linux/phy.h        |  3 +++
>  2 files changed, 46 insertions(+)
> 
> diff --git a/drivers/net/phy/phy-core.c b/drivers/net/phy/phy-core.c
> index 605ca20ae192..4f258fb409da 100644
> --- a/drivers/net/phy/phy-core.c
> +++ b/drivers/net/phy/phy-core.c
> @@ -101,6 +101,49 @@ const char *phy_rate_matching_to_str(int rate_matching)
>  }
>  EXPORT_SYMBOL_GPL(phy_rate_matching_to_str);
>  
> +/**
> + * phy_fix_phy_mode_for_mac_delays - Convenience function for fixing PHY
> + * mode based on whether mac adds internal delay
> + *
> + * @interface: The current interface mode of the port
> + * @mac_txid: True if the mac adds internal tx delay
> + * @mac_rxid: True if the mac adds internal rx delay
> + *
> + * Return fixed PHY mode, or PHY_INTERFACE_MODE_NA if the interface can
> + * not apply the internal delay
> + */
> +phy_interface_t phy_fix_phy_mode_for_mac_delays(phy_interface_t interface,
> +						bool mac_txid, bool mac_rxid)
> +{
> +	if (!phy_interface_mode_is_rgmii(interface))
> +		return interface;
> +
> +	if (mac_txid && mac_rxid) {
> +		if (interface == PHY_INTERFACE_MODE_RGMII_ID)
> +			return PHY_INTERFACE_MODE_RGMII;
> +		return PHY_INTERFACE_MODE_NA;
> +	}
> +
> +	if (mac_txid) {
> +		if (interface == PHY_INTERFACE_MODE_RGMII_ID)
> +			return PHY_INTERFACE_MODE_RGMII_RXID;
> +		if (interface == PHY_INTERFACE_MODE_RGMII_TXID)
> +			return PHY_INTERFACE_MODE_RGMII;
> +		return PHY_INTERFACE_MODE_NA;
> +	}
> +
> +	if (mac_rxid) {
> +		if (interface == PHY_INTERFACE_MODE_RGMII_ID)
> +			return PHY_INTERFACE_MODE_RGMII_TXID;
> +		if (interface == PHY_INTERFACE_MODE_RGMII_RXID)
> +			return PHY_INTERFACE_MODE_RGMII;
> +		return PHY_INTERFACE_MODE_NA;
> +	}
> +
> +	return interface;
> +}
> +EXPORT_SYMBOL_GPL(phy_fix_phy_mode_for_mac_delays);
> +
>  /**
>   * phy_interface_num_ports - Return the number of links that can be carried by
>   *			     a given MAC-PHY physical link. Returns 0 if this is
> diff --git a/include/linux/phy.h b/include/linux/phy.h
> index 3c7634482356..0bc00a4cceb2 100644
> --- a/include/linux/phy.h
> +++ b/include/linux/phy.h
> @@ -1813,6 +1813,9 @@ static inline bool phy_is_pseudo_fixed_link(struct phy_device *phydev)
>  	return phydev->is_pseudo_fixed_link;
>  }
>  
> +phy_interface_t phy_fix_phy_mode_for_mac_delays(phy_interface_t interface,
> +						bool mac_txid, bool mac_rxid);
> +
>  int phy_save_page(struct phy_device *phydev);
>  int phy_select_page(struct phy_device *phydev, int page);
>  int phy_restore_page(struct phy_device *phydev, int oldpage, int ret);


  reply	other threads:[~2025-10-29 19:29 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-28  0:38 [PATCH v4 0/3] net: stmmac: dwmac-sophgo: Add phy interface filter Inochi Amaoto
2025-10-28  0:38 ` [PATCH v4 1/3] dt-bindings: net: sophgo,sg2044-dwmac: add phy mode restriction Inochi Amaoto
2025-10-28 19:22   ` Conor Dooley
2025-10-29  0:56     ` Inochi Amaoto
2025-10-29 17:54       ` Conor Dooley
2025-10-30  2:17         ` Inochi Amaoto
2025-10-28  0:38 ` [PATCH v4 2/3] net: phy: Add helper for fixing RGMII PHY mode based on internal mac delay Inochi Amaoto
2025-10-29 19:28   ` Maxime Chevallier [this message]
2025-10-28  0:38 ` [PATCH v4 3/3] net: stmmac: dwmac-sophgo: Add phy interface filter Inochi Amaoto
2025-10-30  0:49   ` Yixun Lan
2025-10-30  2:16     ` Inochi Amaoto

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=45ebd2eb-9b09-43fa-a451-29299b33f06a@bootlin.com \
    --to=maxime.chevallier@bootlin.com \
    --cc=alexandre.torgue@foss.st.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=conor+dt@kernel.org \
    --cc=davem@davemloft.net \
    --cc=devicetree@vger.kernel.org \
    --cc=dlan@gentoo.org \
    --cc=edumazet@google.com \
    --cc=hkallweit1@gmail.com \
    --cc=inochiama@gmail.com \
    --cc=krzk+dt@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-stm32@st-md-mailman.stormreply.com \
    --cc=linux@armlinux.org.uk \
    --cc=looong.bin@gmail.com \
    --cc=mcoquelin.stm32@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=rabenda.cn@gmail.com \
    --cc=rmk+kernel@armlinux.org.uk \
    --cc=robh@kernel.org \
    --cc=sophgo@lists.linux.dev \
    --cc=unicorn_wang@outlook.com \
    --cc=uwu@icenowy.me \
    --cc=wangruikang@iscas.ac.cn \
    --cc=ziyao@disroot.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

all inboxes | Powered by JetHome®