Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge branch 'net-stmmac-dwmac-socfpga-cleanup-fix_mac_speed'

Maxime Chevallier says:

====================
net: stmmac: dwmac-socfpga: Cleanup .fix_mac_speed

This small series does a bit of cleanup in the dwmad-socfpga glue
driver, especially around the .fix_mac_speed() operation.

It's mostly about re-using existing helpers from the glue driver, as
well as reorganizing the code to make the local private structures a
little bit smaller.

No functionnal changes are intended, this was tested on cyclone V.
====================

Link: https://patch.msgid.link/20260324092102.687082-1-maxime.chevallier@bootlin.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

+28 -30
+28 -30
drivers/net/ethernet/stmicro/stmmac/dwmac-socfpga.c
··· 53 53 54 54 struct socfpga_dwmac; 55 55 struct socfpga_dwmac_ops { 56 - int (*set_phy_mode)(struct socfpga_dwmac *dwmac_priv); 56 + int (*set_phy_mode)(struct socfpga_dwmac *dwmac_priv, 57 + struct device *dev); 57 58 void (*setup_plat_dat)(struct socfpga_dwmac *dwmac_priv); 58 59 }; 59 60 60 61 struct socfpga_dwmac { 61 62 u32 reg_offset; 62 63 u32 reg_shift; 63 - struct device *dev; 64 64 struct plat_stmmacenet_data *plat_dat; 65 65 struct regmap *sys_mgr_base_addr; 66 66 struct reset_control *stmmac_rst; ··· 72 72 const struct socfpga_dwmac_ops *ops; 73 73 }; 74 74 75 + static phy_interface_t socfpga_get_plat_phymode(struct socfpga_dwmac *dwmac) 76 + { 77 + return dwmac->plat_dat->phy_interface; 78 + } 79 + 80 + static void socfpga_sgmii_config(struct socfpga_dwmac *dwmac, bool enable) 81 + { 82 + u16 val = enable ? SGMII_ADAPTER_ENABLE : SGMII_ADAPTER_DISABLE; 83 + 84 + writew(val, dwmac->sgmii_adapter_base + SGMII_ADAPTER_CTRL_REG); 85 + } 86 + 75 87 static void socfpga_dwmac_fix_mac_speed(void *bsp_priv, 76 88 phy_interface_t interface, int speed, 77 89 unsigned int mode) 78 90 { 79 91 struct socfpga_dwmac *dwmac = (struct socfpga_dwmac *)bsp_priv; 80 - struct stmmac_priv *priv = netdev_priv(dev_get_drvdata(dwmac->dev)); 81 - void __iomem *splitter_base = dwmac->splitter_base; 82 92 void __iomem *sgmii_adapter_base = dwmac->sgmii_adapter_base; 93 + phy_interface_t phymode = socfpga_get_plat_phymode(dwmac); 94 + void __iomem *splitter_base = dwmac->splitter_base; 83 95 u32 val; 84 96 85 97 if (sgmii_adapter_base) 86 - writew(SGMII_ADAPTER_DISABLE, 87 - sgmii_adapter_base + SGMII_ADAPTER_CTRL_REG); 98 + socfpga_sgmii_config(dwmac, false); 88 99 89 100 if (splitter_base) { 90 101 val = readl(splitter_base + EMAC_SPLITTER_CTRL_REG); ··· 117 106 writel(val, splitter_base + EMAC_SPLITTER_CTRL_REG); 118 107 } 119 108 120 - if ((priv->plat->phy_interface == PHY_INTERFACE_MODE_SGMII || 121 - priv->plat->phy_interface == PHY_INTERFACE_MODE_1000BASEX) && 122 - sgmii_adapter_base) 123 - writew(SGMII_ADAPTER_ENABLE, 124 - sgmii_adapter_base + SGMII_ADAPTER_CTRL_REG); 109 + if ((phymode == PHY_INTERFACE_MODE_SGMII || 110 + phymode == PHY_INTERFACE_MODE_1000BASEX) && sgmii_adapter_base) 111 + socfpga_sgmii_config(dwmac, true); 125 112 } 126 113 127 114 static int socfpga_dwmac_parse_data(struct socfpga_dwmac *dwmac, struct device *dev) ··· 243 234 dwmac->reg_offset = reg_offset; 244 235 dwmac->reg_shift = reg_shift; 245 236 dwmac->sys_mgr_base_addr = sys_mgr_base_addr; 246 - dwmac->dev = dev; 247 237 of_node_put(np_sgmii_adapter); 248 238 249 239 return 0; ··· 250 242 err_node_put: 251 243 of_node_put(np_sgmii_adapter); 252 244 return ret; 253 - } 254 - 255 - static int socfpga_get_plat_phymode(struct socfpga_dwmac *dwmac) 256 - { 257 - return dwmac->plat_dat->phy_interface; 258 - } 259 - 260 - static void socfpga_sgmii_config(struct socfpga_dwmac *dwmac, bool enable) 261 - { 262 - u16 val = enable ? SGMII_ADAPTER_ENABLE : SGMII_ADAPTER_DISABLE; 263 - 264 - writew(val, dwmac->sgmii_adapter_base + SGMII_ADAPTER_CTRL_REG); 265 245 } 266 246 267 247 static int socfpga_set_phy_mode_common(int phymode, u32 *val) ··· 381 385 return 0; 382 386 } 383 387 384 - static int socfpga_gen5_set_phy_mode(struct socfpga_dwmac *dwmac) 388 + static int socfpga_gen5_set_phy_mode(struct socfpga_dwmac *dwmac, 389 + struct device *dev) 385 390 { 386 391 struct regmap *sys_mgr_base_addr = dwmac->sys_mgr_base_addr; 387 - int phymode = socfpga_get_plat_phymode(dwmac); 392 + phy_interface_t phymode = socfpga_get_plat_phymode(dwmac); 388 393 u32 reg_offset = dwmac->reg_offset; 389 394 u32 reg_shift = dwmac->reg_shift; 390 395 u32 ctrl, val, module; 391 396 392 397 if (socfpga_set_phy_mode_common(phymode, &val)) { 393 - dev_err(dwmac->dev, "bad phy mode %d\n", phymode); 398 + dev_err(dev, "bad phy mode %d\n", phymode); 394 399 return -EINVAL; 395 400 } 396 401 ··· 440 443 return 0; 441 444 } 442 445 443 - static int socfpga_gen10_set_phy_mode(struct socfpga_dwmac *dwmac) 446 + static int socfpga_gen10_set_phy_mode(struct socfpga_dwmac *dwmac, 447 + struct device *dev) 444 448 { 445 449 struct regmap *sys_mgr_base_addr = dwmac->sys_mgr_base_addr; 446 - int phymode = socfpga_get_plat_phymode(dwmac); 450 + phy_interface_t phymode = socfpga_get_plat_phymode(dwmac); 447 451 u32 reg_offset = dwmac->reg_offset; 448 452 u32 reg_shift = dwmac->reg_shift; 449 453 u32 ctrl, val, module; ··· 553 555 { 554 556 struct socfpga_dwmac *dwmac = bsp_priv; 555 557 556 - return dwmac->ops->set_phy_mode(dwmac); 558 + return dwmac->ops->set_phy_mode(dwmac, dev); 557 559 } 558 560 559 561 static void socfpga_gen5_setup_plat_dat(struct socfpga_dwmac *dwmac)