From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from vps0.lunn.ch (vps0.lunn.ch [156.67.10.101]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6E4FF2C327D; Mon, 20 Oct 2025 18:52:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=156.67.10.101 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760986340; cv=none; b=mj6JDuAFouhukhMd1/2mDftCTZGKmo5HyAGFahWoDTlwRO4/7OP5GRPo9e5+a0hCZOtPKfbECSymODTh7RMoY/eF3CmL6hk/ieDYeCk6SF1yv4TGxOtVHbJNceglOLeZCrb7h5HWMy0ALs1axSiNHUvqpOgwUQEcpnwbHhUob50= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760986340; c=relaxed/simple; bh=EQ8t7tB+D4tqgjE5FX3+AxWSSwDJe9Zy/EctcpllNj4=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=sub9IwwUn5ECZEIHYhAo1YM1aerpzSpeY2RG23jh1pCNLtulQe9JWUOCm8Cp0lkvsonOGVrhlVAegXgqk0FMg/Z2N+fshbrhkaz38jYsird556697cxt6pCKXcsZAkXuKxl9Hi70K68gxQ3k3YUzNKaT07v3DtI68xe+QtSo12M= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=lunn.ch; spf=pass smtp.mailfrom=lunn.ch; dkim=pass (1024-bit key) header.d=lunn.ch header.i=@lunn.ch header.b=Rn166uEX; arc=none smtp.client-ip=156.67.10.101 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=lunn.ch Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=lunn.ch Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=lunn.ch header.i=@lunn.ch header.b="Rn166uEX" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lunn.ch; s=20171124; h=In-Reply-To:Content-Disposition:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:From:Sender:Reply-To:Subject: Date:Message-ID:To:Cc:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Content-Disposition:In-Reply-To:References; bh=tvR/JOCDykbUtNBkJ2YheNXEBp8e8ja99yZKcJe41jk=; b=Rn166uEXHRAoxorCRcipzvbU/Y 9LYEOK9yuC6IL2lh2+2j0hi6aIl1fJxE2sNKydc1xihXpchLrcP9i5vDopTNPtE1+PhuYWignc4PL /6YlFTFIs3+FkMKTw723y1lHHMx/rp+8d1Cig0WScb12/aNttg/tNHV2+hjX5GnOcfbo=; Received: from andrew by vps0.lunn.ch with local (Exim 4.94.2) (envelope-from ) id 1vAuyu-00BY4z-B8; Mon, 20 Oct 2025 20:51:44 +0200 Date: Mon, 20 Oct 2025 20:51:44 +0200 From: Andrew Lunn To: Inochi Amaoto Cc: Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Chen Wang , Maxime Coquelin , Alexandre Torgue , Heiner Kallweit , Russell King , "Russell King (Oracle)" , Han Gao , Icenowy Zheng , Vivian Wang , Yao Zi , 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 , Longbin Li Subject: Re: [PATCH v2 2/3] net: phy: Add helper for fixing RGMII PHY mode based on internal mac delay Message-ID: <8da7450f-ef1a-4d8f-9081-a31585e2da19@lunn.ch> References: <20251020095500.1330057-1-inochiama@gmail.com> <20251020095500.1330057-3-inochiama@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20251020095500.1330057-3-inochiama@gmail.com> On Mon, Oct 20, 2025 at 05:54:58PM +0800, 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. > > Signed-off-by: Inochi Amaoto > --- > 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 > + */ I think a helper like this is a good idea. But there are a couple of things i don't like about this implementation. I don't like returning PHY_INTERFACE_MODE_NA on error. I would prefer -EINVAL. of_get_phy_mode() passed a phy_interface_t *, and returns an errno. The same would be good here. I find: phy_fix_phy_mode_for_mac_delays(interface, true, false) hard to read. You cannot see what these true/false mean. Which is Rx and which is Tx? Rather than true false, how about passing an PHY_INTERFACE_MODE_RGMII_* values? PHY_INTERFACE_MODE_RGMII_ID would indicate the MAC is doing both delays. PHY_INTERFACE_MODE_RGMII_RXID the MAC is implementing the RX delay? I'm open to other ideas here. Andrew