Skip to contentSkip to conversation

net: stmmac: visconti: convert to set_clk_tx_rate() method

PATCH Superseded Russell King (Oracle) 3 participants 3 messages Apr 16, 2025 – Apr 17, 2025

Subsystems (5)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 net: stmmac: visconti: convert to set_clk_tx_rate() method

Convert visconti to use the set_clk_tx_rate() method. By doing so, the GMAC control register will already have been updated (unlike with the fix_mac_speed() method) so this code can be removed while porting to the set_clk_tx_rate() method.

There is also no need for the spinlock, and has never been - neither fix_mac_speed() nor set_clk_tx_rate() can be called by more than one thread at a time, so the lock does nothing useful.

---
v2: add Andrew's r-b (he doesn't mind it being preserved for simple fixes) fix build errors.

 .../ethernet/stmicro/stmmac/dwmac-visconti.c  | 23 +++++--------------
 1 file changed, 6 insertions(+), 17 deletions(-)
drivers/net/ethernet/stmicro/stmmac/dwmac-visconti.c +6 -17
index 33cf99797df5..3d08bc9f6854 100644
@@ -51,21 +51,14 @@ struct visconti_eth {
 	u32 phy_intf_sel;
 	struct clk *phy_ref_clk;
 	struct device *dev;
-	spinlock_t lock; /* lock to protect register update */
 };
 
-static void visconti_eth_fix_mac_speed(void *priv, int speed, unsigned int mode)
+static int visconti_eth_set_clk_tx_rate(void *bsp_priv, struct clk *clk_tx_i,
+					phy_interface_t interface, int speed)
 {
-	struct visconti_eth *dwmac = priv;
+	struct visconti_eth *dwmac = bsp_priv;
 	struct net_device *netdev = dev_get_drvdata(dwmac->dev);
 	unsigned int val, clk_sel_val = 0;
-	unsigned long flags;
-
-	spin_lock_irqsave(&dwmac->lock, flags);
-
-	/* adjust link */
-	val = readl(dwmac->reg + MAC_CTRL_REG);
-	val &= ~(GMAC_CONFIG_PS | GMAC_CONFIG_FES);
 
 	switch (speed) {
 	case SPEED_1000:
@@ -89,12 +82,9 @@ static void visconti_eth_fix_mac_speed(void *priv, int speed, unsigned int mode)
 	default:
 		/* No bit control */
 		netdev_err(netdev, "Unsupported speed request (%d)", speed);
-		spin_unlock_irqrestore(&dwmac->lock, flags);
-		return;
+		return -EINVAL;
 	}
 
-	writel(val, dwmac->reg + MAC_CTRL_REG);
-
 	/* Stop internal clock */
 	val = readl(dwmac->reg + REG_ETHER_CLOCK_SEL);
 	val &= ~(ETHER_CLK_SEL_RMII_CLK_EN | ETHER_CLK_SEL_RX_TX_CLK_EN);
@@ -136,7 +126,7 @@ static void visconti_eth_fix_mac_speed(void *priv, int speed, unsigned int mode)
 		break;
 	}
 
-	spin_unlock_irqrestore(&dwmac->lock, flags);
+	return 0;
 }
 
 static int visconti_eth_init_hw(struct platform_device *pdev, struct plat_stmmacenet_data *plat_dat)
@@ -228,11 +218,10 @@ static int visconti_eth_dwmac_probe(struct platform_device *pdev)
 	if (!dwmac)
 		return -ENOMEM;
 
-	spin_lock_init(&dwmac->lock);
 	dwmac->reg = stmmac_res.addr;
 	dwmac->dev = &pdev->dev;
 	plat_dat->bsp_priv = dwmac;
-	plat_dat->fix_mac_speed = visconti_eth_fix_mac_speed;
+	plat_dat->set_clk_tx_rate = visconti_eth_set_clk_tx_rate;
 
 	ret = visconti_eth_clock_probe(pdev, plat_dat);
 	if (ret)
Signature · 1 line
2.30.2
Reviewed-by on v2 1/1
#1 lore raw
Quoted 9 lines · Russell King (Oracle)

Convert visconti to use the set_clk_tx_rate() method. By doing so, the GMAC control register will already have been updated (unlike with the fix_mac_speed() method) so this code can be removed while porting to the set_clk_tx_rate() method.

There is also no need for the spinlock, and has never been - neither fix_mac_speed() nor set_clk_tx_rate() can be called by more than one thread at a time, so the lock does nothing useful.

Quoted 6 lines

---
v2: add Andrew's r-b (he doesn't mind it being preserved for simple fixes) fix build errors.

Acked-by on v2 1/1
#2 lore raw
In reply to Russell King (Oracle)
Quoted 25 lines

-----Original Message-----
From: Russell King <[email protected]> On Behalf Of Russell King (Oracle)
Sent: Wednesday, April 16, 2025 6:44 PM
To: Andrew Lunn <[email protected]>; Heiner Kallweit <[email protected]>
Cc: Alexandre Torgue <[email protected]>; Andrew Lunn <[email protected]>; David S. Miller <[email protected]>; Eric Dumazet <[email protected]>; Jakub Kicinski <[email protected]>; [email protected]; [email protected]; Maxime Coquelin <[email protected]>; [email protected]; iwamatsu nobuhiro(岩松 信洋 □DITC○CPT)
<[email protected]>; Paolo Abeni <[email protected]>
Subject: [PATCH net-next v2] net: stmmac: visconti: convert to set_clk_tx_rate() method

Convert visconti to use the set_clk_tx_rate() method. By doing so, the GMAC control register will already have been updated (unlike with the fix_mac_speed() method) so this code can be removed while porting to the set_clk_tx_rate() method.

There is also no need for the spinlock, and has never been - neither fix_mac_speed() nor set_clk_tx_rate() can be called by more than one thread at a time, so the lock does nothing useful.

Quoted 8 lines

---
v2: add Andrew's r-b (he doesn't mind it being preserved for simple fixes) fix build errors.

 .../ethernet/stmicro/stmmac/dwmac-visconti.c  | 23 +++++--------------
 1 file changed, 6 insertions(+), 17 deletions(-)

Best regards,
Nobuhiro