Skip to content

Commit 50f2570

Browse files
committed
Merge branch 'net-stmmac-socfpga-fix-init-ordering-and-cleanups'
Russell King says: ==================== net: stmmac: socfpga: fix init ordering and cleanups This series fixes the init ordering of the socfpga probe function. The standard rule is to do all setup before publishing any device, and socfpga violates that. I can see no reason for this, but these patches have not been tested on hardware. Address this by moving the initialisation of dwmac->stmmac_rst along with all the other dwmac initialisers - there's no reason for this to be late as plat_dat->stmmac_rst has already been populated. Next, replace the call to ops->set_phy_mode() with an init function socfpga_dwmac_init() which will then be linked in to plat_dat->init. Then, add this to plat_dat->init, and switch to stmmac_pltfr_pm_ops from the private ops. The runtime suspend/resume socfpga implementations are identical to the platform ones, but misses the noirq versions which this will add. Before we swap the order of socfpga_dwmac_init() and stmmac_dvr_probe(), we need to change the way the interface is obtained, as that uses driver data and the struct net_device which haven't been initialised. Save a pointer to plat_dat in the socfpga private data, and use that to get the interface mode. We can then swap the order of the init and probe functions. Finally, convert to devm_stmmac_pltfr_probe() by moving the call to ops->set_phy_mode() into an init function appropriately populating plat_dat->init. ==================== Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
2 parents 544456b + 1dbefd5 commit 50f2570

File tree

1 file changed

+19
-67
lines changed

1 file changed

+19
-67
lines changed

drivers/net/ethernet/stmicro/stmmac/dwmac-socfpga.c

Lines changed: 19 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ struct socfpga_dwmac {
5050
u32 reg_offset;
5151
u32 reg_shift;
5252
struct device *dev;
53+
struct plat_stmmacenet_data *plat_dat;
5354
struct regmap *sys_mgr_base_addr;
5455
struct reset_control *stmmac_rst;
5556
struct reset_control *stmmac_ocp_rst;
@@ -233,10 +234,7 @@ static int socfpga_dwmac_parse_data(struct socfpga_dwmac *dwmac, struct device *
233234

234235
static int socfpga_get_plat_phymode(struct socfpga_dwmac *dwmac)
235236
{
236-
struct net_device *ndev = dev_get_drvdata(dwmac->dev);
237-
struct stmmac_priv *priv = netdev_priv(ndev);
238-
239-
return priv->plat->mac_interface;
237+
return dwmac->plat_dat->mac_interface;
240238
}
241239

242240
static void socfpga_sgmii_config(struct socfpga_dwmac *dwmac, bool enable)
@@ -435,15 +433,20 @@ static struct phylink_pcs *socfpga_dwmac_select_pcs(struct stmmac_priv *priv,
435433
return priv->hw->phylink_pcs;
436434
}
437435

436+
static int socfpga_dwmac_init(struct platform_device *pdev, void *bsp_priv)
437+
{
438+
struct socfpga_dwmac *dwmac = bsp_priv;
439+
440+
return dwmac->ops->set_phy_mode(dwmac);
441+
}
442+
438443
static int socfpga_dwmac_probe(struct platform_device *pdev)
439444
{
440445
struct plat_stmmacenet_data *plat_dat;
441446
struct stmmac_resources stmmac_res;
442447
struct device *dev = &pdev->dev;
443448
int ret;
444449
struct socfpga_dwmac *dwmac;
445-
struct net_device *ndev;
446-
struct stmmac_priv *stpriv;
447450
const struct socfpga_dwmac_ops *ops;
448451

449452
ops = device_get_match_data(&pdev->dev);
@@ -479,76 +482,26 @@ static int socfpga_dwmac_probe(struct platform_device *pdev)
479482
return ret;
480483
}
481484

485+
/* The socfpga driver needs to control the stmmac reset to set the phy
486+
* mode. Create a copy of the core reset handle so it can be used by
487+
* the driver later.
488+
*/
489+
dwmac->stmmac_rst = plat_dat->stmmac_rst;
482490
dwmac->ops = ops;
491+
dwmac->plat_dat = plat_dat;
492+
483493
plat_dat->bsp_priv = dwmac;
484494
plat_dat->fix_mac_speed = socfpga_dwmac_fix_mac_speed;
495+
plat_dat->init = socfpga_dwmac_init;
485496
plat_dat->pcs_init = socfpga_dwmac_pcs_init;
486497
plat_dat->pcs_exit = socfpga_dwmac_pcs_exit;
487498
plat_dat->select_pcs = socfpga_dwmac_select_pcs;
488499
plat_dat->has_gmac = true;
489500

490501
plat_dat->riwt_off = 1;
491502

492-
ret = stmmac_dvr_probe(&pdev->dev, plat_dat, &stmmac_res);
493-
if (ret)
494-
return ret;
495-
496-
ndev = platform_get_drvdata(pdev);
497-
stpriv = netdev_priv(ndev);
498-
499-
/* The socfpga driver needs to control the stmmac reset to set the phy
500-
* mode. Create a copy of the core reset handle so it can be used by
501-
* the driver later.
502-
*/
503-
dwmac->stmmac_rst = stpriv->plat->stmmac_rst;
504-
505-
ret = ops->set_phy_mode(dwmac);
506-
if (ret)
507-
goto err_dvr_remove;
508-
509-
return 0;
510-
511-
err_dvr_remove:
512-
stmmac_dvr_remove(&pdev->dev);
513-
514-
return ret;
515-
}
516-
517-
#ifdef CONFIG_PM_SLEEP
518-
static int socfpga_dwmac_resume(struct device *dev)
519-
{
520-
struct net_device *ndev = dev_get_drvdata(dev);
521-
struct stmmac_priv *priv = netdev_priv(ndev);
522-
struct socfpga_dwmac *dwmac_priv = get_stmmac_bsp_priv(dev);
523-
524-
dwmac_priv->ops->set_phy_mode(priv->plat->bsp_priv);
525-
526-
return stmmac_resume(dev);
503+
return devm_stmmac_pltfr_probe(pdev, plat_dat, &stmmac_res);
527504
}
528-
#endif /* CONFIG_PM_SLEEP */
529-
530-
static int __maybe_unused socfpga_dwmac_runtime_suspend(struct device *dev)
531-
{
532-
struct net_device *ndev = dev_get_drvdata(dev);
533-
struct stmmac_priv *priv = netdev_priv(ndev);
534-
535-
stmmac_bus_clks_config(priv, false);
536-
537-
return 0;
538-
}
539-
540-
static int __maybe_unused socfpga_dwmac_runtime_resume(struct device *dev)
541-
{
542-
struct net_device *ndev = dev_get_drvdata(dev);
543-
struct stmmac_priv *priv = netdev_priv(ndev);
544-
545-
return stmmac_bus_clks_config(priv, true);
546-
}
547-
548-
static const struct dev_pm_ops socfpga_dwmac_pm_ops = {
549-
SET_SYSTEM_SLEEP_PM_OPS(stmmac_suspend, socfpga_dwmac_resume)
550-
SET_RUNTIME_PM_OPS(socfpga_dwmac_runtime_suspend, socfpga_dwmac_runtime_resume, NULL)
551-
};
552505

553506
static const struct socfpga_dwmac_ops socfpga_gen5_ops = {
554507
.set_phy_mode = socfpga_gen5_set_phy_mode,
@@ -567,10 +520,9 @@ MODULE_DEVICE_TABLE(of, socfpga_dwmac_match);
567520

568521
static struct platform_driver socfpga_dwmac_driver = {
569522
.probe = socfpga_dwmac_probe,
570-
.remove = stmmac_pltfr_remove,
571523
.driver = {
572524
.name = "socfpga-dwmac",
573-
.pm = &socfpga_dwmac_pm_ops,
525+
.pm = &stmmac_pltfr_pm_ops,
574526
.of_match_table = socfpga_dwmac_match,
575527
},
576528
};

0 commit comments

Comments
 (0)