Skip to content

Commit baab9de

Browse files
nehebkuba-moo
authored andcommitted
net: ibm: emac: use netdev's phydev directly
Avoids having to use own struct member. Signed-off-by: Rosen Penev <[email protected]> Reviewed-by: Andrew Lunn <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent a4dd853 commit baab9de

File tree

2 files changed

+22
-30
lines changed

2 files changed

+22
-30
lines changed

drivers/net/ethernet/ibm/emac/core.c

Lines changed: 22 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2459,7 +2459,7 @@ static int emac_read_uint_prop(struct device_node *np, const char *name,
24592459
static void emac_adjust_link(struct net_device *ndev)
24602460
{
24612461
struct emac_instance *dev = netdev_priv(ndev);
2462-
struct phy_device *phy = dev->phy_dev;
2462+
struct phy_device *phy = ndev->phydev;
24632463

24642464
dev->phy.autoneg = phy->autoneg;
24652465
dev->phy.speed = phy->speed;
@@ -2510,22 +2510,20 @@ static int emac_mdio_phy_start_aneg(struct mii_phy *phy,
25102510
static int emac_mdio_setup_aneg(struct mii_phy *phy, u32 advertise)
25112511
{
25122512
struct net_device *ndev = phy->dev;
2513-
struct emac_instance *dev = netdev_priv(ndev);
25142513

25152514
phy->autoneg = AUTONEG_ENABLE;
25162515
phy->advertising = advertise;
2517-
return emac_mdio_phy_start_aneg(phy, dev->phy_dev);
2516+
return emac_mdio_phy_start_aneg(phy, ndev->phydev);
25182517
}
25192518

25202519
static int emac_mdio_setup_forced(struct mii_phy *phy, int speed, int fd)
25212520
{
25222521
struct net_device *ndev = phy->dev;
2523-
struct emac_instance *dev = netdev_priv(ndev);
25242522

25252523
phy->autoneg = AUTONEG_DISABLE;
25262524
phy->speed = speed;
25272525
phy->duplex = fd;
2528-
return emac_mdio_phy_start_aneg(phy, dev->phy_dev);
2526+
return emac_mdio_phy_start_aneg(phy, ndev->phydev);
25292527
}
25302528

25312529
static int emac_mdio_poll_link(struct mii_phy *phy)
@@ -2534,20 +2532,19 @@ static int emac_mdio_poll_link(struct mii_phy *phy)
25342532
struct emac_instance *dev = netdev_priv(ndev);
25352533
int res;
25362534

2537-
res = phy_read_status(dev->phy_dev);
2535+
res = phy_read_status(ndev->phydev);
25382536
if (res) {
25392537
dev_err(&dev->ofdev->dev, "link update failed (%d).", res);
25402538
return ethtool_op_get_link(ndev);
25412539
}
25422540

2543-
return dev->phy_dev->link;
2541+
return ndev->phydev->link;
25442542
}
25452543

25462544
static int emac_mdio_read_link(struct mii_phy *phy)
25472545
{
25482546
struct net_device *ndev = phy->dev;
2549-
struct emac_instance *dev = netdev_priv(ndev);
2550-
struct phy_device *phy_dev = dev->phy_dev;
2547+
struct phy_device *phy_dev = ndev->phydev;
25512548
int res;
25522549

25532550
res = phy_read_status(phy_dev);
@@ -2564,10 +2561,9 @@ static int emac_mdio_read_link(struct mii_phy *phy)
25642561
static int emac_mdio_init_phy(struct mii_phy *phy)
25652562
{
25662563
struct net_device *ndev = phy->dev;
2567-
struct emac_instance *dev = netdev_priv(ndev);
25682564

2569-
phy_start(dev->phy_dev);
2570-
return phy_init_hw(dev->phy_dev);
2565+
phy_start(ndev->phydev);
2566+
return phy_init_hw(ndev->phydev);
25712567
}
25722568

25732569
static const struct mii_phy_ops emac_dt_mdio_phy_ops = {
@@ -2622,26 +2618,28 @@ static int emac_dt_mdio_probe(struct emac_instance *dev)
26222618
static int emac_dt_phy_connect(struct emac_instance *dev,
26232619
struct device_node *phy_handle)
26242620
{
2621+
struct phy_device *phy_dev;
2622+
26252623
dev->phy.def = devm_kzalloc(&dev->ofdev->dev, sizeof(*dev->phy.def),
26262624
GFP_KERNEL);
26272625
if (!dev->phy.def)
26282626
return -ENOMEM;
26292627

2630-
dev->phy_dev = of_phy_connect(dev->ndev, phy_handle, &emac_adjust_link,
2631-
0, dev->phy_mode);
2632-
if (!dev->phy_dev) {
2628+
phy_dev = of_phy_connect(dev->ndev, phy_handle, &emac_adjust_link, 0,
2629+
dev->phy_mode);
2630+
if (!phy_dev) {
26332631
dev_err(&dev->ofdev->dev, "failed to connect to PHY.\n");
26342632
return -ENODEV;
26352633
}
26362634

2637-
dev->phy.def->phy_id = dev->phy_dev->drv->phy_id;
2638-
dev->phy.def->phy_id_mask = dev->phy_dev->drv->phy_id_mask;
2639-
dev->phy.def->name = dev->phy_dev->drv->name;
2635+
dev->phy.def->phy_id = phy_dev->drv->phy_id;
2636+
dev->phy.def->phy_id_mask = phy_dev->drv->phy_id_mask;
2637+
dev->phy.def->name = phy_dev->drv->name;
26402638
dev->phy.def->ops = &emac_dt_mdio_phy_ops;
26412639
ethtool_convert_link_mode_to_legacy_u32(&dev->phy.features,
2642-
dev->phy_dev->supported);
2643-
dev->phy.address = dev->phy_dev->mdio.addr;
2644-
dev->phy.mode = dev->phy_dev->interface;
2640+
phy_dev->supported);
2641+
dev->phy.address = phy_dev->mdio.addr;
2642+
dev->phy.mode = phy_dev->interface;
26452643
return 0;
26462644
}
26472645

@@ -2695,11 +2693,11 @@ static int emac_init_phy(struct emac_instance *dev)
26952693
return res;
26962694

26972695
res = of_phy_register_fixed_link(np);
2698-
dev->phy_dev = of_phy_find_device(np);
2699-
if (res || !dev->phy_dev)
2696+
ndev->phydev = of_phy_find_device(np);
2697+
if (res || !ndev->phydev)
27002698
return res ? res : -EINVAL;
27012699
emac_adjust_link(dev->ndev);
2702-
put_device(&dev->phy_dev->mdio.dev);
2700+
put_device(&ndev->phydev->mdio.dev);
27032701
}
27042702
return 0;
27052703
}
@@ -3257,9 +3255,6 @@ static void emac_remove(struct platform_device *ofdev)
32573255
if (emac_has_feature(dev, EMAC_FTR_HAS_ZMII))
32583256
zmii_detach(dev->zmii_dev, dev->zmii_port);
32593257

3260-
if (dev->phy_dev)
3261-
phy_disconnect(dev->phy_dev);
3262-
32633258
busy_phy_map &= ~(1 << dev->phy.address);
32643259
DBG(dev, "busy_phy_map now %#x" NL, busy_phy_map);
32653260

drivers/net/ethernet/ibm/emac/core.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,9 +188,6 @@ struct emac_instance {
188188
struct emac_instance *mdio_instance;
189189
struct mutex mdio_lock;
190190

191-
/* Device-tree based phy configuration */
192-
struct phy_device *phy_dev;
193-
194191
/* ZMII infos if any */
195192
u32 zmii_ph;
196193
u32 zmii_port;

0 commit comments

Comments
 (0)