mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Louis-Alexis Eyraud <louisalexis.eyraud@collabora.com>
To: Maxime Chevallier <maxime.chevallier@bootlin.com>,
	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>,
	Richard Cochran	 <richardcochran@gmail.com>,
	Matthias Brugger <matthias.bgg@gmail.com>,
	 AngeloGioacchino Del Regno
	<angelogioacchino.delregno@collabora.com>,
	Biao Huang <biao.huang@mediatek.com>,
	Maxime Coquelin	 <mcoquelin.stm32@gmail.com>,
	Alexandre Torgue <alexandre.torgue@foss.st.com>
Cc: kernel@collabora.com, netdev@vger.kernel.org,
	devicetree@vger.kernel.org, 	linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
		linux-mediatek@lists.infradead.org,
	linux-stm32@st-md-mailman.stormreply.com
Subject: Re: [PATCH net-next v2 2/7] net: stmmac: mediatek: simplify TX/RX delay handling in mt8195_set_delay
Date: Wed, 07 Oct 2026 17:16:31 +0200	[thread overview]
Message-ID: <1af4b5461a80219d00a4be853c9111d60fe18f79.camel@collabora.com> (raw)
In-Reply-To: <47b9d9a2-18cb-4726-82f7-772d108b2ee8@bootlin.com>

Hi Maxime,

On Sun, 2026-10-04 at 15:43 +0200, Maxime Chevallier wrote:
> Hey,
> 
> On 9/24/26 09:23, Louis-Alexis Eyraud wrote:
> > The mt8195_set_delay function modifies at its beginning the TX and
> > RX
> > internal delay variables, located in the driver data, by dividing
> > them by a constant (290) and restores their original values by
> > multiplying them again at the function end. It is done in order to
> > convert them into a step value, used by the hardware registers for
> > setting these delays.
> > 
> > But this is rather pointless to modify the driver data for that,
> > while
> > it could be done locally in the function. The original delay values
> > cannot be used anymore (if needed) during mt8195_set_delay
> > processing.
> > Finally, they are altered after the function call if they are not a
> > multiple of 290.
> > 
> > So, simplify these delay variable handling by using local variables
> > to
> > convert them into the register value and use those in the write
> > calls.
> > Also, remove the two private conversion functions, that are not
> > useful
> > anymore and add definitions for MT8195 RX/TX delay maximum and
> > divider
> > values.
> > 
> > Signed-off-by: Louis-Alexis Eyraud
> > <louisalexis.eyraud@collabora.com>
> 
> Looking at this, seems like the 2712 support could benefit from the
> same
> cleanups you've done with the weird division / remultiplication.
> 
> That can be a separate cleanup though.
> 
> Maxime
> 
thanks for the review.

I'll add an additional patch to do the same cleanup for MT2712
in v3.

Regards,
Louis-Alexis

> 
> > ---
> >  .../net/ethernet/stmicro/stmmac/dwmac-mediatek.c   | 77
> > ++++++++++------------
> >  1 file changed, 36 insertions(+), 41 deletions(-)
> > 
> > diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-mediatek.c
> > b/drivers/net/ethernet/stmicro/stmmac/dwmac-mediatek.c
> > index 30ae0dba7fff..f7eb85110df0 100644
> > --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-mediatek.c
> > +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-mediatek.c
> > @@ -63,6 +63,11 @@
> >  #define MT8195_DLY_RMII_TXC_ENABLE	BIT(5)
> >  #define MT8195_DLY_RMII_TXC_STAGES	GENMASK(4, 0)
> >  
> > +#define MT8195_DLY_RXC_STAGE_DIV	290 /* 290ps per stage */
> > +#define MT8195_DLY_RXC_MAX		9280 /* 32 x 290ps */
> > +#define MT8195_DLY_TXC_STAGE_DIV	290 /* 290ps per stage */
> > +#define MT8195_DLY_TXC_MAX		9280 /* 32 x 290ps */
> > +
> >  struct mac_delay_struct {
> >  	u32 tx_delay;
> >  	u32 rx_delay;
> > @@ -293,39 +298,27 @@ static int mt8195_set_interface(struct
> > mediatek_dwmac_plat_data *plat,
> >  	return 0;
> >  }
> >  
> > -static void mt8195_delay_ps2stage(struct mediatek_dwmac_plat_data
> > *plat)
> > -{
> > -	struct mac_delay_struct *mac_delay = &plat->mac_delay;
> > -
> > -	/* 290ps per stage */
> > -	mac_delay->tx_delay /= 290;
> > -	mac_delay->rx_delay /= 290;
> > -}
> > -
> > -static void mt8195_delay_stage2ps(struct mediatek_dwmac_plat_data
> > *plat)
> > -{
> > -	struct mac_delay_struct *mac_delay = &plat->mac_delay;
> > -
> > -	/* 290ps per stage */
> > -	mac_delay->tx_delay *= 290;
> > -	mac_delay->rx_delay *= 290;
> > -}
> > -
> >  static int mt8195_set_delay(struct mediatek_dwmac_plat_data *plat)
> >  {
> >  	struct mac_delay_struct *mac_delay = &plat->mac_delay;
> > -	u32 gtxc_delay_val = 0, delay_val = 0, rmii_delay_val = 0;
> > -
> > -	mt8195_delay_ps2stage(plat);
> > +	u32 rx_delay_stage_val = mac_delay->rx_delay /
> > MT8195_DLY_RXC_STAGE_DIV;
> > +	u32 tx_delay_stage_val = mac_delay->tx_delay /
> > MT8195_DLY_TXC_STAGE_DIV;
> > +	u32 gtxc_delay_val = 0;
> > +	u32 rmii_delay_val = 0;
> > +	u32 delay_val = 0;
> >  
> >  	switch (plat->phy_mode) {
> >  	case PHY_INTERFACE_MODE_MII:
> > -		delay_val |= FIELD_PREP(MT8195_DLY_TXC_ENABLE,
> > !!mac_delay->tx_delay);
> > -		delay_val |= FIELD_PREP(MT8195_DLY_TXC_STAGES,
> > mac_delay->tx_delay);
> > +		delay_val |= FIELD_PREP(MT8195_DLY_TXC_ENABLE,
> > +					!!tx_delay_stage_val);
> > +		delay_val |= FIELD_PREP(MT8195_DLY_TXC_STAGES,
> > +					tx_delay_stage_val);
> >  		delay_val |= FIELD_PREP(MT8195_DLY_TXC_INV,
> > mac_delay->tx_inv);
> >  
> > -		delay_val |= FIELD_PREP(MT8195_DLY_RXC_ENABLE,
> > !!mac_delay->rx_delay);
> > -		delay_val |= FIELD_PREP(MT8195_DLY_RXC_STAGES,
> > mac_delay->rx_delay);
> > +		delay_val |= FIELD_PREP(MT8195_DLY_RXC_ENABLE,
> > +					!!rx_delay_stage_val);
> > +		delay_val |= FIELD_PREP(MT8195_DLY_RXC_STAGES,
> > +					rx_delay_stage_val);
> >  		delay_val |= FIELD_PREP(MT8195_DLY_RXC_INV,
> > mac_delay->rx_inv);
> >  		break;
> >  	case PHY_INTERFACE_MODE_RMII:
> > @@ -336,16 +329,16 @@ static int mt8195_set_delay(struct
> > mediatek_dwmac_plat_data *plat)
> >  			 * The ingress timing can be adjusted by
> > RMII_RXC delay macro circuit.
> >  			 */
> >  			rmii_delay_val |=
> > FIELD_PREP(MT8195_DLY_RMII_TXC_ENABLE,
> > -						     !!mac_delay-
> > >tx_delay);
> > +						    
> > !!tx_delay_stage_val);
> >  			rmii_delay_val |=
> > FIELD_PREP(MT8195_DLY_RMII_TXC_STAGES,
> > -						     mac_delay-
> > >tx_delay);
> > +						    
> > tx_delay_stage_val);
> >  			rmii_delay_val |=
> > FIELD_PREP(MT8195_DLY_RMII_TXC_INV,
> >  						     mac_delay-
> > >tx_inv);
> >  
> >  			rmii_delay_val |=
> > FIELD_PREP(MT8195_DLY_RMII_RXC_ENABLE,
> > -						     !!mac_delay-
> > >rx_delay);
> > +						    
> > !!rx_delay_stage_val);
> >  			rmii_delay_val |=
> > FIELD_PREP(MT8195_DLY_RMII_RXC_STAGES,
> > -						     mac_delay-
> > >rx_delay);
> > +						    
> > rx_delay_stage_val);
> >  			rmii_delay_val |=
> > FIELD_PREP(MT8195_DLY_RMII_RXC_INV,
> >  						     mac_delay-
> > >rx_inv);
> >  		} else {
> > @@ -361,9 +354,9 @@ static int mt8195_set_delay(struct
> > mediatek_dwmac_plat_data *plat)
> >  				 * by RXC delay macro circuit.
> >  				 */
> >  				delay_val |=
> > FIELD_PREP(MT8195_DLY_RXC_ENABLE,
> > -
> > 							!!mac_delay->rx_delay);
> > +							!!rx_delay
> > _stage_val);
> >  				delay_val |=
> > FIELD_PREP(MT8195_DLY_RXC_STAGES,
> > -							mac_delay-
> > >rx_delay);
> > +							rx_delay_s
> > tage_val);
> >  				delay_val |=
> > FIELD_PREP(MT8195_DLY_RXC_INV,
> >  							mac_delay-
> > >rx_inv);
> >  			} else {
> > @@ -372,9 +365,9 @@ static int mt8195_set_delay(struct
> > mediatek_dwmac_plat_data *plat)
> >  				 * by TXC delay macro circuit.
> >  				 */
> >  				delay_val |=
> > FIELD_PREP(MT8195_DLY_TXC_ENABLE,
> > -
> > 							!!mac_delay->rx_delay);
> > +							!!rx_delay
> > _stage_val);
> >  				delay_val |=
> > FIELD_PREP(MT8195_DLY_TXC_STAGES,
> > -							mac_delay-
> > >rx_delay);
> > +							rx_delay_s
> > tage_val);
> >  				delay_val |=
> > FIELD_PREP(MT8195_DLY_TXC_INV,
> >  							mac_delay-
> > >rx_inv);
> >  			}
> > @@ -384,12 +377,16 @@ static int mt8195_set_delay(struct
> > mediatek_dwmac_plat_data *plat)
> >  	case PHY_INTERFACE_MODE_RGMII_TXID:
> >  	case PHY_INTERFACE_MODE_RGMII_RXID:
> >  	case PHY_INTERFACE_MODE_RGMII_ID:
> > -		gtxc_delay_val |=
> > FIELD_PREP(MT8195_DLY_GTXC_ENABLE, !!mac_delay->tx_delay);
> > -		gtxc_delay_val |=
> > FIELD_PREP(MT8195_DLY_GTXC_STAGES, mac_delay->tx_delay);
> > +		gtxc_delay_val |=
> > FIELD_PREP(MT8195_DLY_GTXC_ENABLE,
> > +					    
> > !!tx_delay_stage_val);
> > +		gtxc_delay_val |=
> > FIELD_PREP(MT8195_DLY_GTXC_STAGES,
> > +					     tx_delay_stage_val);
> >  		gtxc_delay_val |= FIELD_PREP(MT8195_DLY_GTXC_INV,
> > mac_delay->tx_inv);
> >  
> > -		delay_val |= FIELD_PREP(MT8195_DLY_RXC_ENABLE,
> > !!mac_delay->rx_delay);
> > -		delay_val |= FIELD_PREP(MT8195_DLY_RXC_STAGES,
> > mac_delay->rx_delay);
> > +		delay_val |= FIELD_PREP(MT8195_DLY_RXC_ENABLE,
> > +					!!rx_delay_stage_val);
> > +		delay_val |= FIELD_PREP(MT8195_DLY_RXC_STAGES,
> > +					rx_delay_stage_val);
> >  		delay_val |= FIELD_PREP(MT8195_DLY_RXC_INV,
> > mac_delay->rx_inv);
> >  
> >  		break;
> > @@ -408,8 +405,6 @@ static int mt8195_set_delay(struct
> > mediatek_dwmac_plat_data *plat)
> >  	regmap_write(plat->peri_regmap, MT8195_PERI_ETH_CTRL1,
> > delay_val);
> >  	regmap_write(plat->peri_regmap, MT8195_PERI_ETH_CTRL2,
> > rmii_delay_val);
> >  
> > -	mt8195_delay_stage2ps(plat);
> > -
> >  	return 0;
> >  }
> >  
> > @@ -418,8 +413,8 @@ static const struct mediatek_dwmac_variant
> > mt8195_gmac_variant = {
> >  	.dwmac_set_delay = mt8195_set_delay,
> >  	.clk_list = mt8195_dwmac_clk_l,
> >  	.num_clks = ARRAY_SIZE(mt8195_dwmac_clk_l),
> > -	.rx_delay_max = 9280,
> > -	.tx_delay_max = 9280,
> > +	.rx_delay_max = MT8195_DLY_RXC_MAX,
> > +	.tx_delay_max = MT8195_DLY_TXC_MAX,
> >  	.dma_bit_mask = 35,
> >  };
> >  
> > 
> 

  reply	other threads:[~2026-10-07 15:17 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-24  7:23 [PATCH net-next v2 0/7] net/stmmac: Add Mediatek MT8189 support Louis-Alexis Eyraud
2026-09-24  7:23 ` [PATCH net-next v2 1/7] dt-bindings: net: mediatek-dwmac: add support for MT8189 SoC Louis-Alexis Eyraud
2026-09-28  8:03   ` netdev-bot+sashiko
2026-09-29  7:36   ` Krzysztof Kozlowski
2026-10-01 13:13     ` Louis-Alexis Eyraud
2026-09-24  7:23 ` [PATCH net-next v2 2/7] net: stmmac: mediatek: simplify TX/RX delay handling in mt8195_set_delay Louis-Alexis Eyraud
2026-10-04 13:36   ` Maxime Chevallier
2026-10-04 13:43   ` Maxime Chevallier
2026-10-07 15:16     ` Louis-Alexis Eyraud [this message]
2026-09-24  7:23 ` [PATCH net-next v2 3/7] net: stmmac: mediatek: add RX/TX delay stage divider in platform data Louis-Alexis Eyraud
2026-10-04 13:40   ` Maxime Chevallier
2026-09-24  7:23 ` [PATCH net-next v2 4/7] net: stmmac: mediatek: add PERI_ETH_CTRLx register offset " Louis-Alexis Eyraud
2026-09-24  7:23 ` [PATCH net-next v2 5/7] net: stmmac: mediatek: use TX clock phase shift in RGMII mode with 1Gbps speed Louis-Alexis Eyraud
2026-09-28  8:03   ` netdev-bot+sashiko
2026-09-24  7:23 ` [PATCH net-next v2 6/7] net: stmmac: mediatek: add support for TX clock output enable feature Louis-Alexis Eyraud
2026-09-24  7:23 ` [PATCH net-next v2 7/7] net: stmmac: mediatek: add support for MT8189 SoC Louis-Alexis Eyraud
2026-09-28  8:03   ` netdev-bot+sashiko

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=1af4b5461a80219d00a4be853c9111d60fe18f79.camel@collabora.com \
    --to=louisalexis.eyraud@collabora.com \
    --cc=alexandre.torgue@foss.st.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=angelogioacchino.delregno@collabora.com \
    --cc=biao.huang@mediatek.com \
    --cc=conor+dt@kernel.org \
    --cc=davem@davemloft.net \
    --cc=devicetree@vger.kernel.org \
    --cc=edumazet@google.com \
    --cc=kernel@collabora.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-mediatek@lists.infradead.org \
    --cc=linux-stm32@st-md-mailman.stormreply.com \
    --cc=matthias.bgg@gmail.com \
    --cc=maxime.chevallier@bootlin.com \
    --cc=mcoquelin.stm32@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=richardcochran@gmail.com \
    --cc=robh@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

all inboxes | Powered by JetHome®