Skip to content

Commit 81b418a

Browse files
Russell King (Oracle)kuba-moo
authored andcommitted
net: stmmac: dwmac-socfpga: use pcs_init/pcs_exit
Use the newly introduced pcs_init() and pcs_exit() operations to create and destroy the PCS instance at a more appropriate moment during the driver lifecycle, thereby avoiding publishing a network device to userspace that has not yet finished its PCS initialisation. There are other similar issues with this driver which remain unaddressed, but these are out of scope for this patch. Signed-off-by: Russell King (Oracle) <[email protected]> Reviewed-by: Maxime Chevallier <[email protected]> [rgantois: removed second parameters of new callbacks] Signed-off-by: Romain Gantois <[email protected]> Reviewed-by: Hariprasad Kelam <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent f0ef433 commit 81b418a

File tree

1 file changed

+53
-54
lines changed

1 file changed

+53
-54
lines changed

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

Lines changed: 53 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,56 @@ static int socfpga_gen10_set_phy_mode(struct socfpga_dwmac *dwmac)
379379
return 0;
380380
}
381381

382+
static int socfpga_dwmac_pcs_init(struct stmmac_priv *priv)
383+
{
384+
struct socfpga_dwmac *dwmac = priv->plat->bsp_priv;
385+
struct regmap_config pcs_regmap_cfg = {
386+
.reg_bits = 16,
387+
.val_bits = 16,
388+
.reg_shift = REGMAP_UPSHIFT(1),
389+
};
390+
struct mdio_regmap_config mrc;
391+
struct regmap *pcs_regmap;
392+
struct phylink_pcs *pcs;
393+
struct mii_bus *pcs_bus;
394+
395+
if (!dwmac->tse_pcs_base)
396+
return 0;
397+
398+
pcs_regmap = devm_regmap_init_mmio(priv->device, dwmac->tse_pcs_base,
399+
&pcs_regmap_cfg);
400+
if (IS_ERR(pcs_regmap))
401+
return PTR_ERR(pcs_regmap);
402+
403+
memset(&mrc, 0, sizeof(mrc));
404+
mrc.regmap = pcs_regmap;
405+
mrc.parent = priv->device;
406+
mrc.valid_addr = 0x0;
407+
mrc.autoscan = false;
408+
409+
/* Can't use ndev->name here because it will not have been initialised,
410+
* and in any case, the user can rename network interfaces at runtime.
411+
*/
412+
snprintf(mrc.name, MII_BUS_ID_SIZE, "%s-pcs-mii",
413+
dev_name(priv->device));
414+
pcs_bus = devm_mdio_regmap_register(priv->device, &mrc);
415+
if (IS_ERR(pcs_bus))
416+
return PTR_ERR(pcs_bus);
417+
418+
pcs = lynx_pcs_create_mdiodev(pcs_bus, 0);
419+
if (IS_ERR(pcs))
420+
return PTR_ERR(pcs);
421+
422+
priv->hw->phylink_pcs = pcs;
423+
return 0;
424+
}
425+
426+
static void socfpga_dwmac_pcs_exit(struct stmmac_priv *priv)
427+
{
428+
if (priv->hw->phylink_pcs)
429+
lynx_pcs_destroy(priv->hw->phylink_pcs);
430+
}
431+
382432
static int socfpga_dwmac_probe(struct platform_device *pdev)
383433
{
384434
struct plat_stmmacenet_data *plat_dat;
@@ -426,6 +476,8 @@ static int socfpga_dwmac_probe(struct platform_device *pdev)
426476
dwmac->ops = ops;
427477
plat_dat->bsp_priv = dwmac;
428478
plat_dat->fix_mac_speed = socfpga_dwmac_fix_mac_speed;
479+
plat_dat->pcs_init = socfpga_dwmac_pcs_init;
480+
plat_dat->pcs_exit = socfpga_dwmac_pcs_exit;
429481

430482
ret = stmmac_dvr_probe(&pdev->dev, plat_dat, &stmmac_res);
431483
if (ret)
@@ -444,48 +496,6 @@ static int socfpga_dwmac_probe(struct platform_device *pdev)
444496
if (ret)
445497
goto err_dvr_remove;
446498

447-
/* Create a regmap for the PCS so that it can be used by the PCS driver,
448-
* if we have such a PCS
449-
*/
450-
if (dwmac->tse_pcs_base) {
451-
struct regmap_config pcs_regmap_cfg;
452-
struct mdio_regmap_config mrc;
453-
struct regmap *pcs_regmap;
454-
struct mii_bus *pcs_bus;
455-
456-
memset(&pcs_regmap_cfg, 0, sizeof(pcs_regmap_cfg));
457-
memset(&mrc, 0, sizeof(mrc));
458-
459-
pcs_regmap_cfg.reg_bits = 16;
460-
pcs_regmap_cfg.val_bits = 16;
461-
pcs_regmap_cfg.reg_shift = REGMAP_UPSHIFT(1);
462-
463-
pcs_regmap = devm_regmap_init_mmio(&pdev->dev, dwmac->tse_pcs_base,
464-
&pcs_regmap_cfg);
465-
if (IS_ERR(pcs_regmap)) {
466-
ret = PTR_ERR(pcs_regmap);
467-
goto err_dvr_remove;
468-
}
469-
470-
mrc.regmap = pcs_regmap;
471-
mrc.parent = &pdev->dev;
472-
mrc.valid_addr = 0x0;
473-
mrc.autoscan = false;
474-
475-
snprintf(mrc.name, MII_BUS_ID_SIZE, "%s-pcs-mii", ndev->name);
476-
pcs_bus = devm_mdio_regmap_register(&pdev->dev, &mrc);
477-
if (IS_ERR(pcs_bus)) {
478-
ret = PTR_ERR(pcs_bus);
479-
goto err_dvr_remove;
480-
}
481-
482-
stpriv->hw->phylink_pcs = lynx_pcs_create_mdiodev(pcs_bus, 0);
483-
if (IS_ERR(stpriv->hw->phylink_pcs)) {
484-
ret = PTR_ERR(stpriv->hw->phylink_pcs);
485-
goto err_dvr_remove;
486-
}
487-
}
488-
489499
return 0;
490500

491501
err_dvr_remove:
@@ -494,17 +504,6 @@ static int socfpga_dwmac_probe(struct platform_device *pdev)
494504
return ret;
495505
}
496506

497-
static void socfpga_dwmac_remove(struct platform_device *pdev)
498-
{
499-
struct net_device *ndev = platform_get_drvdata(pdev);
500-
struct stmmac_priv *priv = netdev_priv(ndev);
501-
struct phylink_pcs *pcs = priv->hw->phylink_pcs;
502-
503-
stmmac_pltfr_remove(pdev);
504-
505-
lynx_pcs_destroy(pcs);
506-
}
507-
508507
#ifdef CONFIG_PM_SLEEP
509508
static int socfpga_dwmac_resume(struct device *dev)
510509
{
@@ -576,7 +575,7 @@ MODULE_DEVICE_TABLE(of, socfpga_dwmac_match);
576575

577576
static struct platform_driver socfpga_dwmac_driver = {
578577
.probe = socfpga_dwmac_probe,
579-
.remove_new = socfpga_dwmac_remove,
578+
.remove_new = stmmac_pltfr_remove,
580579
.driver = {
581580
.name = "socfpga-dwmac",
582581
.pm = &socfpga_dwmac_pm_ops,

0 commit comments

Comments
 (0)