* [PATCHv2 net-next 0/8]
@ 2024-09-03 19:42 Rosen Penev
2024-09-03 19:42 ` [PATCHv2 net-next 1/8] net: ibm: emac: use devm for alloc_etherdev Rosen Penev
` (7 more replies)
0 siblings, 8 replies; 12+ messages in thread
From: Rosen Penev @ 2024-09-03 19:42 UTC (permalink / raw)
To: netdev
Cc: davem, edumazet, kuba, pabeni, linux-kernel, jacob.e.keller,
horms, sd, chunkeey
It's a very old driver with a lot of potential for cleaning up code to
modern standards. This was a simple one dealing with mostly the probe
function and adding some devm to it.
v2: removed the waiting code in favor of EPROBE_DEFER.
Rosen Penev (8):
net: ibm: emac: use devm for alloc_etherdev
net: ibm: emac: manage emac_irq with devm
net: ibm: emac: use devm for of_iomap
net: ibm: emac: remove mii_bus with devm
net: ibm: emac: use devm for register_netdev
net: ibm: emac: use netdev's phydev directly
net: ibm: emac: replace of_get_property
net: ibm: emac: remove all waiting code
drivers/net/ethernet/ibm/emac/core.c | 227 ++++++++++-----------------
drivers/net/ethernet/ibm/emac/core.h | 4 -
2 files changed, 79 insertions(+), 152 deletions(-)
--
2.46.0
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCHv2 net-next 1/8] net: ibm: emac: use devm for alloc_etherdev
2024-09-03 19:42 [PATCHv2 net-next 0/8] Rosen Penev
@ 2024-09-03 19:42 ` Rosen Penev
2024-09-03 19:42 ` [PATCHv2 net-next 2/8] net: ibm: emac: manage emac_irq with devm Rosen Penev
` (6 subsequent siblings)
7 siblings, 0 replies; 12+ messages in thread
From: Rosen Penev @ 2024-09-03 19:42 UTC (permalink / raw)
To: netdev
Cc: davem, edumazet, kuba, pabeni, linux-kernel, jacob.e.keller,
horms, sd, chunkeey
Allows to simplify the code slightly. This is safe to do as free_netdev
gets called last.
Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
drivers/net/ethernet/ibm/emac/core.c | 9 +++------
1 file changed, 3 insertions(+), 6 deletions(-)
diff --git a/drivers/net/ethernet/ibm/emac/core.c b/drivers/net/ethernet/ibm/emac/core.c
index a19d098f2e2b..348702f462bd 100644
--- a/drivers/net/ethernet/ibm/emac/core.c
+++ b/drivers/net/ethernet/ibm/emac/core.c
@@ -3053,7 +3053,7 @@ static int emac_probe(struct platform_device *ofdev)
/* Allocate our net_device structure */
err = -ENOMEM;
- ndev = alloc_etherdev(sizeof(struct emac_instance));
+ ndev = devm_alloc_etherdev(&ofdev->dev, sizeof(struct emac_instance));
if (!ndev)
goto err_gone;
@@ -3072,7 +3072,7 @@ static int emac_probe(struct platform_device *ofdev)
/* Init various config data based on device-tree */
err = emac_init_config(dev);
if (err)
- goto err_free;
+ goto err_gone;
/* Get interrupts. EMAC irq is mandatory, WOL irq is optional */
dev->emac_irq = irq_of_parse_and_map(np, 0);
@@ -3080,7 +3080,7 @@ static int emac_probe(struct platform_device *ofdev)
if (!dev->emac_irq) {
printk(KERN_ERR "%pOF: Can't map main interrupt\n", np);
err = -ENODEV;
- goto err_free;
+ goto err_gone;
}
ndev->irq = dev->emac_irq;
@@ -3239,8 +3239,6 @@ static int emac_probe(struct platform_device *ofdev)
irq_dispose_mapping(dev->wol_irq);
if (dev->emac_irq)
irq_dispose_mapping(dev->emac_irq);
- err_free:
- free_netdev(ndev);
err_gone:
/* if we were on the bootlist, remove us as we won't show up and
* wake up all waiters to notify them in case they were waiting
@@ -3289,7 +3287,6 @@ static void emac_remove(struct platform_device *ofdev)
if (dev->emac_irq)
irq_dispose_mapping(dev->emac_irq);
- free_netdev(dev->ndev);
}
/* XXX Features in here should be replaced by properties... */
--
2.46.0
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCHv2 net-next 2/8] net: ibm: emac: manage emac_irq with devm
2024-09-03 19:42 [PATCHv2 net-next 0/8] Rosen Penev
2024-09-03 19:42 ` [PATCHv2 net-next 1/8] net: ibm: emac: use devm for alloc_etherdev Rosen Penev
@ 2024-09-03 19:42 ` Rosen Penev
2024-09-03 19:42 ` [PATCHv2 net-next 3/8] net: ibm: emac: use devm for of_iomap Rosen Penev
` (5 subsequent siblings)
7 siblings, 0 replies; 12+ messages in thread
From: Rosen Penev @ 2024-09-03 19:42 UTC (permalink / raw)
To: netdev
Cc: davem, edumazet, kuba, pabeni, linux-kernel, jacob.e.keller,
horms, sd, chunkeey
It's the last to go in remove. Safe to let devm handle it.
Also move request_irq to probe for clarity. It's removed in _remove not
close.
Use dev_err_probe instead of printk. Handles EPROBE_DEFER automatically.
Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
v2: used dev_err_probe
drivers/net/ethernet/ibm/emac/core.c | 27 +++++++++------------------
1 file changed, 9 insertions(+), 18 deletions(-)
diff --git a/drivers/net/ethernet/ibm/emac/core.c b/drivers/net/ethernet/ibm/emac/core.c
index 348702f462bd..4e260abbaa56 100644
--- a/drivers/net/ethernet/ibm/emac/core.c
+++ b/drivers/net/ethernet/ibm/emac/core.c
@@ -1228,18 +1228,10 @@ static void emac_print_link_status(struct emac_instance *dev)
static int emac_open(struct net_device *ndev)
{
struct emac_instance *dev = netdev_priv(ndev);
- int err, i;
+ int i;
DBG(dev, "open" NL);
- /* Setup error IRQ handler */
- err = request_irq(dev->emac_irq, emac_irq, 0, "EMAC", dev);
- if (err) {
- printk(KERN_ERR "%s: failed to request IRQ %d\n",
- ndev->name, dev->emac_irq);
- return err;
- }
-
/* Allocate RX ring */
for (i = 0; i < NUM_RX_BUFF; ++i)
if (emac_alloc_rx_skb(dev, i)) {
@@ -1293,8 +1285,6 @@ static int emac_open(struct net_device *ndev)
return 0;
oom:
emac_clean_rx_ring(dev);
- free_irq(dev->emac_irq, dev);
-
return -ENOMEM;
}
@@ -1408,8 +1398,6 @@ static int emac_close(struct net_device *ndev)
emac_clean_tx_ring(dev);
emac_clean_rx_ring(dev);
- free_irq(dev->emac_irq, dev);
-
netif_carrier_off(ndev);
return 0;
@@ -3082,6 +3070,14 @@ static int emac_probe(struct platform_device *ofdev)
err = -ENODEV;
goto err_gone;
}
+
+ /* Setup error IRQ handler */
+ err = devm_request_irq(&ofdev->dev, dev->emac_irq, emac_irq, 0, "EMAC", dev);
+ if (err) {
+ dev_err_probe(&ofdev->dev, err, "failed to request IRQ %d", dev->emac_irq);
+ goto err_gone;
+ }
+
ndev->irq = dev->emac_irq;
/* Map EMAC regs */
@@ -3237,8 +3233,6 @@ static int emac_probe(struct platform_device *ofdev)
err_irq_unmap:
if (dev->wol_irq)
irq_dispose_mapping(dev->wol_irq);
- if (dev->emac_irq)
- irq_dispose_mapping(dev->emac_irq);
err_gone:
/* if we were on the bootlist, remove us as we won't show up and
* wake up all waiters to notify them in case they were waiting
@@ -3284,9 +3278,6 @@ static void emac_remove(struct platform_device *ofdev)
if (dev->wol_irq)
irq_dispose_mapping(dev->wol_irq);
- if (dev->emac_irq)
- irq_dispose_mapping(dev->emac_irq);
-
}
/* XXX Features in here should be replaced by properties... */
--
2.46.0
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCHv2 net-next 3/8] net: ibm: emac: use devm for of_iomap
2024-09-03 19:42 [PATCHv2 net-next 0/8] Rosen Penev
2024-09-03 19:42 ` [PATCHv2 net-next 1/8] net: ibm: emac: use devm for alloc_etherdev Rosen Penev
2024-09-03 19:42 ` [PATCHv2 net-next 2/8] net: ibm: emac: manage emac_irq with devm Rosen Penev
@ 2024-09-03 19:42 ` Rosen Penev
2024-09-03 19:42 ` [PATCHv2 net-next 4/8] net: ibm: emac: remove mii_bus with devm Rosen Penev
` (4 subsequent siblings)
7 siblings, 0 replies; 12+ messages in thread
From: Rosen Penev @ 2024-09-03 19:42 UTC (permalink / raw)
To: netdev
Cc: davem, edumazet, kuba, pabeni, linux-kernel, jacob.e.keller,
horms, sd, chunkeey
Allows removing manual iounmap.
Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
drivers/net/ethernet/ibm/emac/core.c | 13 ++++---------
1 file changed, 4 insertions(+), 9 deletions(-)
diff --git a/drivers/net/ethernet/ibm/emac/core.c b/drivers/net/ethernet/ibm/emac/core.c
index 4e260abbaa56..459f893a0a56 100644
--- a/drivers/net/ethernet/ibm/emac/core.c
+++ b/drivers/net/ethernet/ibm/emac/core.c
@@ -3082,10 +3082,9 @@ static int emac_probe(struct platform_device *ofdev)
/* Map EMAC regs */
// TODO : platform_get_resource() and devm_ioremap_resource()
- dev->emacp = of_iomap(np, 0);
- if (dev->emacp == NULL) {
- printk(KERN_ERR "%pOF: Can't map device registers!\n", np);
- err = -ENOMEM;
+ dev->emacp = devm_of_iomap(&ofdev->dev, np, 0, NULL);
+ if (!dev->emacp) {
+ err = dev_err_probe(&ofdev->dev, -ENOMEM, "can't map device registers");
goto err_irq_unmap;
}
@@ -3095,7 +3094,7 @@ static int emac_probe(struct platform_device *ofdev)
printk(KERN_ERR
"%pOF: Timeout waiting for dependent devices\n", np);
/* display more info about what's missing ? */
- goto err_reg_unmap;
+ goto err_irq_unmap;
}
dev->mal = platform_get_drvdata(dev->mal_dev);
if (dev->mdio_dev != NULL)
@@ -3228,8 +3227,6 @@ static int emac_probe(struct platform_device *ofdev)
mal_unregister_commac(dev->mal, &dev->commac);
err_rel_deps:
emac_put_deps(dev);
- err_reg_unmap:
- iounmap(dev->emacp);
err_irq_unmap:
if (dev->wol_irq)
irq_dispose_mapping(dev->wol_irq);
@@ -3274,8 +3271,6 @@ static void emac_remove(struct platform_device *ofdev)
mal_unregister_commac(dev->mal, &dev->commac);
emac_put_deps(dev);
- iounmap(dev->emacp);
-
if (dev->wol_irq)
irq_dispose_mapping(dev->wol_irq);
}
--
2.46.0
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCHv2 net-next 4/8] net: ibm: emac: remove mii_bus with devm
2024-09-03 19:42 [PATCHv2 net-next 0/8] Rosen Penev
` (2 preceding siblings ...)
2024-09-03 19:42 ` [PATCHv2 net-next 3/8] net: ibm: emac: use devm for of_iomap Rosen Penev
@ 2024-09-03 19:42 ` Rosen Penev
2024-09-05 10:12 ` Paolo Abeni
2024-09-03 19:42 ` [PATCHv2 net-next 5/8] net: ibm: emac: use devm for register_netdev Rosen Penev
` (3 subsequent siblings)
7 siblings, 1 reply; 12+ messages in thread
From: Rosen Penev @ 2024-09-03 19:42 UTC (permalink / raw)
To: netdev
Cc: davem, edumazet, kuba, pabeni, linux-kernel, jacob.e.keller,
horms, sd, chunkeey
Switching to devm management of mii_bus allows to remove
mdiobus_unregister calls and thus avoids needing a mii_bus global struct
member.
Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
drivers/net/ethernet/ibm/emac/core.c | 32 +++++++++++-----------------
drivers/net/ethernet/ibm/emac/core.h | 1 -
2 files changed, 13 insertions(+), 20 deletions(-)
diff --git a/drivers/net/ethernet/ibm/emac/core.c b/drivers/net/ethernet/ibm/emac/core.c
index 459f893a0a56..4cf8af9052bf 100644
--- a/drivers/net/ethernet/ibm/emac/core.c
+++ b/drivers/net/ethernet/ibm/emac/core.c
@@ -2580,6 +2580,7 @@ static const struct mii_phy_ops emac_dt_mdio_phy_ops = {
static int emac_dt_mdio_probe(struct emac_instance *dev)
{
+ struct mii_bus *bus;
struct device_node *mii_np;
int res;
@@ -2594,23 +2595,23 @@ static int emac_dt_mdio_probe(struct emac_instance *dev)
goto put_node;
}
- dev->mii_bus = devm_mdiobus_alloc(&dev->ofdev->dev);
- if (!dev->mii_bus) {
+ bus = devm_mdiobus_alloc(&dev->ofdev->dev);
+ if (!bus) {
res = -ENOMEM;
goto put_node;
}
- dev->mii_bus->priv = dev->ndev;
- dev->mii_bus->parent = dev->ndev->dev.parent;
- dev->mii_bus->name = "emac_mdio";
- dev->mii_bus->read = &emac_mii_bus_read;
- dev->mii_bus->write = &emac_mii_bus_write;
- dev->mii_bus->reset = &emac_mii_bus_reset;
- snprintf(dev->mii_bus->id, MII_BUS_ID_SIZE, "%s", dev->ofdev->name);
- res = of_mdiobus_register(dev->mii_bus, mii_np);
+ bus->priv = dev->ndev;
+ bus->parent = dev->ndev->dev.parent;
+ bus->name = "emac_mdio";
+ bus->read = &emac_mii_bus_read;
+ bus->write = &emac_mii_bus_write;
+ bus->reset = &emac_mii_bus_reset;
+ snprintf(bus->id, MII_BUS_ID_SIZE, "%s", dev->ofdev->name);
+ res = devm_of_mdiobus_register(&dev->ofdev->dev, bus, mii_np);
if (res) {
dev_err(&dev->ofdev->dev, "cannot register MDIO bus %s (%d)",
- dev->mii_bus->name, res);
+ bus->name, res);
}
put_node:
@@ -2656,8 +2657,6 @@ static int emac_dt_phy_probe(struct emac_instance *dev)
res = emac_dt_mdio_probe(dev);
if (!res) {
res = emac_dt_phy_connect(dev, phy_handle);
- if (res)
- mdiobus_unregister(dev->mii_bus);
}
}
@@ -2697,10 +2696,8 @@ static int emac_init_phy(struct emac_instance *dev)
res = of_phy_register_fixed_link(np);
dev->phy_dev = of_phy_find_device(np);
- if (res || !dev->phy_dev) {
- mdiobus_unregister(dev->mii_bus);
+ if (res || !dev->phy_dev)
return res ? res : -EINVAL;
- }
emac_adjust_link(dev->ndev);
put_device(&dev->phy_dev->mdio.dev);
}
@@ -3262,9 +3259,6 @@ static void emac_remove(struct platform_device *ofdev)
if (dev->phy_dev)
phy_disconnect(dev->phy_dev);
- if (dev->mii_bus)
- mdiobus_unregister(dev->mii_bus);
-
busy_phy_map &= ~(1 << dev->phy.address);
DBG(dev, "busy_phy_map now %#x" NL, busy_phy_map);
diff --git a/drivers/net/ethernet/ibm/emac/core.h b/drivers/net/ethernet/ibm/emac/core.h
index 295516b07662..f4bd4cd8ac4a 100644
--- a/drivers/net/ethernet/ibm/emac/core.h
+++ b/drivers/net/ethernet/ibm/emac/core.h
@@ -189,7 +189,6 @@ struct emac_instance {
struct mutex mdio_lock;
/* Device-tree based phy configuration */
- struct mii_bus *mii_bus;
struct phy_device *phy_dev;
/* ZMII infos if any */
--
2.46.0
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCHv2 net-next 5/8] net: ibm: emac: use devm for register_netdev
2024-09-03 19:42 [PATCHv2 net-next 0/8] Rosen Penev
` (3 preceding siblings ...)
2024-09-03 19:42 ` [PATCHv2 net-next 4/8] net: ibm: emac: remove mii_bus with devm Rosen Penev
@ 2024-09-03 19:42 ` Rosen Penev
2024-09-03 19:42 ` [PATCHv2 net-next 6/8] net: ibm: emac: use netdev's phydev directly Rosen Penev
` (2 subsequent siblings)
7 siblings, 0 replies; 12+ messages in thread
From: Rosen Penev @ 2024-09-03 19:42 UTC (permalink / raw)
To: netdev
Cc: davem, edumazet, kuba, pabeni, linux-kernel, jacob.e.keller,
horms, sd, chunkeey
Cleans it up automatically. No need to handle manually.
Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
drivers/net/ethernet/ibm/emac/core.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/drivers/net/ethernet/ibm/emac/core.c b/drivers/net/ethernet/ibm/emac/core.c
index 4cf8af9052bf..45984e420488 100644
--- a/drivers/net/ethernet/ibm/emac/core.c
+++ b/drivers/net/ethernet/ibm/emac/core.c
@@ -3179,7 +3179,7 @@ static int emac_probe(struct platform_device *ofdev)
netif_carrier_off(ndev);
- err = register_netdev(ndev);
+ err = devm_register_netdev(&ofdev->dev, ndev);
if (err) {
printk(KERN_ERR "%pOF: failed to register net device (%d)!\n",
np, err);
@@ -3245,8 +3245,6 @@ static void emac_remove(struct platform_device *ofdev)
DBG(dev, "remove" NL);
- unregister_netdev(dev->ndev);
-
cancel_work_sync(&dev->reset_work);
if (emac_has_feature(dev, EMAC_FTR_HAS_TAH))
--
2.46.0
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCHv2 net-next 6/8] net: ibm: emac: use netdev's phydev directly
2024-09-03 19:42 [PATCHv2 net-next 0/8] Rosen Penev
` (4 preceding siblings ...)
2024-09-03 19:42 ` [PATCHv2 net-next 5/8] net: ibm: emac: use devm for register_netdev Rosen Penev
@ 2024-09-03 19:42 ` Rosen Penev
2024-09-05 10:10 ` Paolo Abeni
2024-09-03 19:42 ` [PATCHv2 net-next 7/8] net: ibm: emac: replace of_get_property Rosen Penev
2024-09-03 19:42 ` [PATCHv2 net-next 8/8] net: ibm: emac: remove all waiting code Rosen Penev
7 siblings, 1 reply; 12+ messages in thread
From: Rosen Penev @ 2024-09-03 19:42 UTC (permalink / raw)
To: netdev
Cc: davem, edumazet, kuba, pabeni, linux-kernel, jacob.e.keller,
horms, sd, chunkeey
Avoids having to use own struct member.
Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
drivers/net/ethernet/ibm/emac/core.c | 47 +++++++++++++---------------
drivers/net/ethernet/ibm/emac/core.h | 3 --
2 files changed, 21 insertions(+), 29 deletions(-)
diff --git a/drivers/net/ethernet/ibm/emac/core.c b/drivers/net/ethernet/ibm/emac/core.c
index 45984e420488..121db9611cd9 100644
--- a/drivers/net/ethernet/ibm/emac/core.c
+++ b/drivers/net/ethernet/ibm/emac/core.c
@@ -2459,7 +2459,7 @@ static int emac_read_uint_prop(struct device_node *np, const char *name,
static void emac_adjust_link(struct net_device *ndev)
{
struct emac_instance *dev = netdev_priv(ndev);
- struct phy_device *phy = dev->phy_dev;
+ struct phy_device *phy = ndev->phydev;
dev->phy.autoneg = phy->autoneg;
dev->phy.speed = phy->speed;
@@ -2510,22 +2510,20 @@ static int emac_mdio_phy_start_aneg(struct mii_phy *phy,
static int emac_mdio_setup_aneg(struct mii_phy *phy, u32 advertise)
{
struct net_device *ndev = phy->dev;
- struct emac_instance *dev = netdev_priv(ndev);
phy->autoneg = AUTONEG_ENABLE;
phy->advertising = advertise;
- return emac_mdio_phy_start_aneg(phy, dev->phy_dev);
+ return emac_mdio_phy_start_aneg(phy, ndev->phydev);
}
static int emac_mdio_setup_forced(struct mii_phy *phy, int speed, int fd)
{
struct net_device *ndev = phy->dev;
- struct emac_instance *dev = netdev_priv(ndev);
phy->autoneg = AUTONEG_DISABLE;
phy->speed = speed;
phy->duplex = fd;
- return emac_mdio_phy_start_aneg(phy, dev->phy_dev);
+ return emac_mdio_phy_start_aneg(phy, ndev->phydev);
}
static int emac_mdio_poll_link(struct mii_phy *phy)
@@ -2534,20 +2532,19 @@ static int emac_mdio_poll_link(struct mii_phy *phy)
struct emac_instance *dev = netdev_priv(ndev);
int res;
- res = phy_read_status(dev->phy_dev);
+ res = phy_read_status(ndev->phydev);
if (res) {
dev_err(&dev->ofdev->dev, "link update failed (%d).", res);
return ethtool_op_get_link(ndev);
}
- return dev->phy_dev->link;
+ return ndev->phydev->link;
}
static int emac_mdio_read_link(struct mii_phy *phy)
{
struct net_device *ndev = phy->dev;
- struct emac_instance *dev = netdev_priv(ndev);
- struct phy_device *phy_dev = dev->phy_dev;
+ struct phy_device *phy_dev = ndev->phydev;
int res;
res = phy_read_status(phy_dev);
@@ -2564,10 +2561,9 @@ static int emac_mdio_read_link(struct mii_phy *phy)
static int emac_mdio_init_phy(struct mii_phy *phy)
{
struct net_device *ndev = phy->dev;
- struct emac_instance *dev = netdev_priv(ndev);
- phy_start(dev->phy_dev);
- return phy_init_hw(dev->phy_dev);
+ phy_start(ndev->phydev);
+ return phy_init_hw(ndev->phydev);
}
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)
static int emac_dt_phy_connect(struct emac_instance *dev,
struct device_node *phy_handle)
{
+ struct phy_device *phy_dev = dev->ndev->phydev;
+
dev->phy.def = devm_kzalloc(&dev->ofdev->dev, sizeof(*dev->phy.def),
GFP_KERNEL);
if (!dev->phy.def)
return -ENOMEM;
- dev->phy_dev = of_phy_connect(dev->ndev, phy_handle, &emac_adjust_link,
+ phy_dev = of_phy_connect(dev->ndev, phy_handle, &emac_adjust_link,
0, dev->phy_mode);
- if (!dev->phy_dev) {
+ if (!phy_dev) {
dev_err(&dev->ofdev->dev, "failed to connect to PHY.\n");
return -ENODEV;
}
- dev->phy.def->phy_id = dev->phy_dev->drv->phy_id;
- dev->phy.def->phy_id_mask = dev->phy_dev->drv->phy_id_mask;
- dev->phy.def->name = dev->phy_dev->drv->name;
+ dev->phy.def->phy_id = phy_dev->drv->phy_id;
+ dev->phy.def->phy_id_mask = phy_dev->drv->phy_id_mask;
+ dev->phy.def->name = phy_dev->drv->name;
dev->phy.def->ops = &emac_dt_mdio_phy_ops;
ethtool_convert_link_mode_to_legacy_u32(&dev->phy.features,
- dev->phy_dev->supported);
- dev->phy.address = dev->phy_dev->mdio.addr;
- dev->phy.mode = dev->phy_dev->interface;
+ phy_dev->supported);
+ dev->phy.address = phy_dev->mdio.addr;
+ dev->phy.mode = phy_dev->interface;
return 0;
}
@@ -2695,11 +2693,11 @@ static int emac_init_phy(struct emac_instance *dev)
return res;
res = of_phy_register_fixed_link(np);
- dev->phy_dev = of_phy_find_device(np);
- if (res || !dev->phy_dev)
+ ndev->phydev = of_phy_find_device(np);
+ if (res || !ndev->phydev)
return res ? res : -EINVAL;
emac_adjust_link(dev->ndev);
- put_device(&dev->phy_dev->mdio.dev);
+ put_device(&ndev->phydev->mdio.dev);
}
return 0;
}
@@ -3254,9 +3252,6 @@ static void emac_remove(struct platform_device *ofdev)
if (emac_has_feature(dev, EMAC_FTR_HAS_ZMII))
zmii_detach(dev->zmii_dev, dev->zmii_port);
- if (dev->phy_dev)
- phy_disconnect(dev->phy_dev);
-
busy_phy_map &= ~(1 << dev->phy.address);
DBG(dev, "busy_phy_map now %#x" NL, busy_phy_map);
diff --git a/drivers/net/ethernet/ibm/emac/core.h b/drivers/net/ethernet/ibm/emac/core.h
index f4bd4cd8ac4a..b820a4f6e8c7 100644
--- a/drivers/net/ethernet/ibm/emac/core.h
+++ b/drivers/net/ethernet/ibm/emac/core.h
@@ -188,9 +188,6 @@ struct emac_instance {
struct emac_instance *mdio_instance;
struct mutex mdio_lock;
- /* Device-tree based phy configuration */
- struct phy_device *phy_dev;
-
/* ZMII infos if any */
u32 zmii_ph;
u32 zmii_port;
--
2.46.0
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCHv2 net-next 7/8] net: ibm: emac: replace of_get_property
2024-09-03 19:42 [PATCHv2 net-next 0/8] Rosen Penev
` (5 preceding siblings ...)
2024-09-03 19:42 ` [PATCHv2 net-next 6/8] net: ibm: emac: use netdev's phydev directly Rosen Penev
@ 2024-09-03 19:42 ` Rosen Penev
2024-09-03 19:42 ` [PATCHv2 net-next 8/8] net: ibm: emac: remove all waiting code Rosen Penev
7 siblings, 0 replies; 12+ messages in thread
From: Rosen Penev @ 2024-09-03 19:42 UTC (permalink / raw)
To: netdev
Cc: davem, edumazet, kuba, pabeni, linux-kernel, jacob.e.keller,
horms, sd, chunkeey
of_property_read_u32 can be used.
Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
drivers/net/ethernet/ibm/emac/core.c | 20 +++++++++-----------
1 file changed, 9 insertions(+), 11 deletions(-)
diff --git a/drivers/net/ethernet/ibm/emac/core.c b/drivers/net/ethernet/ibm/emac/core.c
index 121db9611cd9..6db76eeb4d9b 100644
--- a/drivers/net/ethernet/ibm/emac/core.c
+++ b/drivers/net/ethernet/ibm/emac/core.c
@@ -2444,15 +2444,14 @@ static int emac_wait_deps(struct emac_instance *dev)
static int emac_read_uint_prop(struct device_node *np, const char *name,
u32 *val, int fatal)
{
- int len;
- const u32 *prop = of_get_property(np, name, &len);
- if (prop == NULL || len < sizeof(u32)) {
+ int err;
+
+ err = of_property_read_u32(np, name, val);
+ if (err) {
if (fatal)
- printk(KERN_ERR "%pOF: missing %s property\n",
- np, name);
- return -ENODEV;
+ pr_err("%pOF: missing %s property", np, name);
+ return err;
}
- *val = *prop;
return 0;
}
@@ -3298,16 +3297,15 @@ static void __init emac_make_bootlist(void)
/* Collect EMACs */
while((np = of_find_all_nodes(np)) != NULL) {
- const u32 *idx;
+ u32 idx;
if (of_match_node(emac_match, np) == NULL)
continue;
if (of_property_read_bool(np, "unused"))
continue;
- idx = of_get_property(np, "cell-index", NULL);
- if (idx == NULL)
+ if (of_property_read_u32(np, "cell-index", &idx))
continue;
- cell_indices[i] = *idx;
+ cell_indices[i] = idx;
emac_boot_list[i++] = of_node_get(np);
if (i >= EMAC_BOOT_LIST_SIZE) {
of_node_put(np);
--
2.46.0
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCHv2 net-next 8/8] net: ibm: emac: remove all waiting code
2024-09-03 19:42 [PATCHv2 net-next 0/8] Rosen Penev
` (6 preceding siblings ...)
2024-09-03 19:42 ` [PATCHv2 net-next 7/8] net: ibm: emac: replace of_get_property Rosen Penev
@ 2024-09-03 19:42 ` Rosen Penev
2024-09-05 10:27 ` Paolo Abeni
7 siblings, 1 reply; 12+ messages in thread
From: Rosen Penev @ 2024-09-03 19:42 UTC (permalink / raw)
To: netdev
Cc: davem, edumazet, kuba, pabeni, linux-kernel, jacob.e.keller,
horms, sd, chunkeey
EPROBE_DEFER, which probably wasn't available when this driver was
written, can be used instead of waiting manually.
Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
drivers/net/ethernet/ibm/emac/core.c | 77 ++++++++--------------------
1 file changed, 20 insertions(+), 57 deletions(-)
diff --git a/drivers/net/ethernet/ibm/emac/core.c b/drivers/net/ethernet/ibm/emac/core.c
index 6db76eeb4d9b..21401a8cb32c 100644
--- a/drivers/net/ethernet/ibm/emac/core.c
+++ b/drivers/net/ethernet/ibm/emac/core.c
@@ -32,7 +32,6 @@
#include <linux/ethtool.h>
#include <linux/mii.h>
#include <linux/bitops.h>
-#include <linux/workqueue.h>
#include <linux/of.h>
#include <linux/of_address.h>
#include <linux/of_irq.h>
@@ -96,11 +95,6 @@ MODULE_LICENSE("GPL");
static u32 busy_phy_map;
static DEFINE_MUTEX(emac_phy_map_lock);
-/* This is the wait queue used to wait on any event related to probe, that
- * is discovery of MALs, other EMACs, ZMII/RGMIIs, etc...
- */
-static DECLARE_WAIT_QUEUE_HEAD(emac_probe_wait);
-
/* Having stable interface names is a doomed idea. However, it would be nice
* if we didn't have completely random interface names at boot too :-) It's
* just a matter of making everybody's life easier. Since we are doing
@@ -116,9 +110,6 @@ static DECLARE_WAIT_QUEUE_HEAD(emac_probe_wait);
#define EMAC_BOOT_LIST_SIZE 4
static struct device_node *emac_boot_list[EMAC_BOOT_LIST_SIZE];
-/* How long should I wait for dependent devices ? */
-#define EMAC_PROBE_DEP_TIMEOUT (HZ * 5)
-
/* I don't want to litter system log with timeout errors
* when we have brain-damaged PHY.
*/
@@ -973,8 +964,6 @@ static void __emac_set_multicast_list(struct emac_instance *dev)
* we need is just to stop RX channel. This seems to work on all
* tested SoCs. --ebs
*
- * If we need the full reset, we might just trigger the workqueue
- * and do it async... a bit nasty but should work --BenH
*/
dev->mcast_pending = 0;
emac_rx_disable(dev);
@@ -2378,7 +2367,9 @@ static int emac_check_deps(struct emac_instance *dev,
if (deps[i].drvdata != NULL)
there++;
}
- return there == EMAC_DEP_COUNT;
+ if (there != EMAC_DEP_COUNT)
+ return -EPROBE_DEFER;
+ return 0;
}
static void emac_put_deps(struct emac_instance *dev)
@@ -2390,19 +2381,6 @@ static void emac_put_deps(struct emac_instance *dev)
platform_device_put(dev->tah_dev);
}
-static int emac_of_bus_notify(struct notifier_block *nb, unsigned long action,
- void *data)
-{
- /* We are only intereted in device addition */
- if (action == BUS_NOTIFY_BOUND_DRIVER)
- wake_up_all(&emac_probe_wait);
- return 0;
-}
-
-static struct notifier_block emac_of_bus_notifier = {
- .notifier_call = emac_of_bus_notify
-};
-
static int emac_wait_deps(struct emac_instance *dev)
{
struct emac_depentry deps[EMAC_DEP_COUNT];
@@ -2419,26 +2397,25 @@ static int emac_wait_deps(struct emac_instance *dev)
deps[EMAC_DEP_MDIO_IDX].phandle = dev->mdio_ph;
if (dev->blist && dev->blist > emac_boot_list)
deps[EMAC_DEP_PREV_IDX].phandle = 0xffffffffu;
- bus_register_notifier(&platform_bus_type, &emac_of_bus_notifier);
- wait_event_timeout(emac_probe_wait,
- emac_check_deps(dev, deps),
- EMAC_PROBE_DEP_TIMEOUT);
- bus_unregister_notifier(&platform_bus_type, &emac_of_bus_notifier);
- err = emac_check_deps(dev, deps) ? 0 : -ENODEV;
+
+ err = emac_check_deps(dev, deps);
+ if (err)
+ return err;
+
for (i = 0; i < EMAC_DEP_COUNT; i++) {
of_node_put(deps[i].node);
- if (err)
- platform_device_put(deps[i].ofdev);
- }
- if (err == 0) {
- dev->mal_dev = deps[EMAC_DEP_MAL_IDX].ofdev;
- dev->zmii_dev = deps[EMAC_DEP_ZMII_IDX].ofdev;
- dev->rgmii_dev = deps[EMAC_DEP_RGMII_IDX].ofdev;
- dev->tah_dev = deps[EMAC_DEP_TAH_IDX].ofdev;
- dev->mdio_dev = deps[EMAC_DEP_MDIO_IDX].ofdev;
+ platform_device_put(deps[i].ofdev);
}
+
+ dev->mal_dev = deps[EMAC_DEP_MAL_IDX].ofdev;
+ dev->zmii_dev = deps[EMAC_DEP_ZMII_IDX].ofdev;
+ dev->rgmii_dev = deps[EMAC_DEP_RGMII_IDX].ofdev;
+ dev->tah_dev = deps[EMAC_DEP_TAH_IDX].ofdev;
+ dev->mdio_dev = deps[EMAC_DEP_MDIO_IDX].ofdev;
+
platform_device_put(deps[EMAC_DEP_PREV_IDX].ofdev);
- return err;
+
+ return 0;
}
static int emac_read_uint_prop(struct device_node *np, const char *name,
@@ -3084,12 +3061,8 @@ static int emac_probe(struct platform_device *ofdev)
/* Wait for dependent devices */
err = emac_wait_deps(dev);
- if (err) {
- printk(KERN_ERR
- "%pOF: Timeout waiting for dependent devices\n", np);
- /* display more info about what's missing ? */
+ if (err)
goto err_irq_unmap;
- }
dev->mal = platform_get_drvdata(dev->mal_dev);
if (dev->mdio_dev != NULL)
dev->mdio_instance = platform_get_drvdata(dev->mdio_dev);
@@ -3189,10 +3162,6 @@ static int emac_probe(struct platform_device *ofdev)
wmb();
platform_set_drvdata(ofdev, dev);
- /* There's a new kid in town ! Let's tell everybody */
- wake_up_all(&emac_probe_wait);
-
-
printk(KERN_INFO "%s: EMAC-%d %pOF, MAC %pM\n",
ndev->name, dev->cell_index, np, ndev->dev_addr);
@@ -3225,14 +3194,8 @@ static int emac_probe(struct platform_device *ofdev)
if (dev->wol_irq)
irq_dispose_mapping(dev->wol_irq);
err_gone:
- /* if we were on the bootlist, remove us as we won't show up and
- * wake up all waiters to notify them in case they were waiting
- * on us
- */
- if (blist) {
+ if (blist)
*blist = NULL;
- wake_up_all(&emac_probe_wait);
- }
return err;
}
--
2.46.0
^ permalink raw reply related [flat|nested] 12+ messages in thread
* Re: [PATCHv2 net-next 6/8] net: ibm: emac: use netdev's phydev directly
2024-09-03 19:42 ` [PATCHv2 net-next 6/8] net: ibm: emac: use netdev's phydev directly Rosen Penev
@ 2024-09-05 10:10 ` Paolo Abeni
0 siblings, 0 replies; 12+ messages in thread
From: Paolo Abeni @ 2024-09-05 10:10 UTC (permalink / raw)
To: Rosen Penev, netdev
Cc: davem, edumazet, kuba, linux-kernel, jacob.e.keller, horms, sd,
chunkeey
Hi,
On 9/3/24 21:42, Rosen Penev wrote:
> @@ -2622,26 +2618,28 @@ static int emac_dt_mdio_probe(struct emac_instance *dev)
> static int emac_dt_phy_connect(struct emac_instance *dev,
> struct device_node *phy_handle)
> {
> + struct phy_device *phy_dev = dev->ndev->phydev;
The above assignment looks confusing/not needed, as 'phy_dev' will be
initialized a few line later and not used in between.
Cheers,
Paolo
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCHv2 net-next 4/8] net: ibm: emac: remove mii_bus with devm
2024-09-03 19:42 ` [PATCHv2 net-next 4/8] net: ibm: emac: remove mii_bus with devm Rosen Penev
@ 2024-09-05 10:12 ` Paolo Abeni
0 siblings, 0 replies; 12+ messages in thread
From: Paolo Abeni @ 2024-09-05 10:12 UTC (permalink / raw)
To: Rosen Penev, netdev
Cc: davem, edumazet, kuba, linux-kernel, jacob.e.keller, horms, sd,
chunkeey
On 9/3/24 21:42, Rosen Penev wrote:
> diff --git a/drivers/net/ethernet/ibm/emac/core.c b/drivers/net/ethernet/ibm/emac/core.c
> index 459f893a0a56..4cf8af9052bf 100644
> --- a/drivers/net/ethernet/ibm/emac/core.c
> +++ b/drivers/net/ethernet/ibm/emac/core.c
> @@ -2580,6 +2580,7 @@ static const struct mii_phy_ops emac_dt_mdio_phy_ops = {
>
> static int emac_dt_mdio_probe(struct emac_instance *dev)
> {
> + struct mii_bus *bus;
> struct device_node *mii_np;
> int res;
Minor nit: please respect the reverse xmas tree above.
Thanks,
Paolo
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCHv2 net-next 8/8] net: ibm: emac: remove all waiting code
2024-09-03 19:42 ` [PATCHv2 net-next 8/8] net: ibm: emac: remove all waiting code Rosen Penev
@ 2024-09-05 10:27 ` Paolo Abeni
0 siblings, 0 replies; 12+ messages in thread
From: Paolo Abeni @ 2024-09-05 10:27 UTC (permalink / raw)
To: Rosen Penev, netdev
Cc: davem, edumazet, kuba, linux-kernel, jacob.e.keller, horms, sd,
chunkeey
On 9/3/24 21:42, Rosen Penev wrote:
[...]
> static int emac_wait_deps(struct emac_instance *dev)
Possibly rename the function to something else, as it does not wait anymore?
> @@ -2419,26 +2397,25 @@ static int emac_wait_deps(struct emac_instance *dev)
> deps[EMAC_DEP_MDIO_IDX].phandle = dev->mdio_ph;
> if (dev->blist && dev->blist > emac_boot_list)
> deps[EMAC_DEP_PREV_IDX].phandle = 0xffffffffu;
> - bus_register_notifier(&platform_bus_type, &emac_of_bus_notifier);
> - wait_event_timeout(emac_probe_wait,
> - emac_check_deps(dev, deps),
> - EMAC_PROBE_DEP_TIMEOUT);
> - bus_unregister_notifier(&platform_bus_type, &emac_of_bus_notifier);
> - err = emac_check_deps(dev, deps) ? 0 : -ENODEV;
> +
> + err = emac_check_deps(dev, deps);
> + if (err)
> + return err;
> +
> for (i = 0; i < EMAC_DEP_COUNT; i++) {
> of_node_put(deps[i].node);
> - if (err)
> - platform_device_put(deps[i].ofdev);
> - }
> - if (err == 0) {
> - dev->mal_dev = deps[EMAC_DEP_MAL_IDX].ofdev;
> - dev->zmii_dev = deps[EMAC_DEP_ZMII_IDX].ofdev;
> - dev->rgmii_dev = deps[EMAC_DEP_RGMII_IDX].ofdev;
> - dev->tah_dev = deps[EMAC_DEP_TAH_IDX].ofdev;
> - dev->mdio_dev = deps[EMAC_DEP_MDIO_IDX].ofdev;
> + platform_device_put(deps[i].ofdev);
I'm likely lost, but AFAICS after the patch, on success
platform_device_put() is invoked unconditionally on each deps[] entry,
while before it was called only on failure?!?
/P
^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2024-09-05 10:27 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-09-03 19:42 [PATCHv2 net-next 0/8] Rosen Penev
2024-09-03 19:42 ` [PATCHv2 net-next 1/8] net: ibm: emac: use devm for alloc_etherdev Rosen Penev
2024-09-03 19:42 ` [PATCHv2 net-next 2/8] net: ibm: emac: manage emac_irq with devm Rosen Penev
2024-09-03 19:42 ` [PATCHv2 net-next 3/8] net: ibm: emac: use devm for of_iomap Rosen Penev
2024-09-03 19:42 ` [PATCHv2 net-next 4/8] net: ibm: emac: remove mii_bus with devm Rosen Penev
2024-09-05 10:12 ` Paolo Abeni
2024-09-03 19:42 ` [PATCHv2 net-next 5/8] net: ibm: emac: use devm for register_netdev Rosen Penev
2024-09-03 19:42 ` [PATCHv2 net-next 6/8] net: ibm: emac: use netdev's phydev directly Rosen Penev
2024-09-05 10:10 ` Paolo Abeni
2024-09-03 19:42 ` [PATCHv2 net-next 7/8] net: ibm: emac: replace of_get_property Rosen Penev
2024-09-03 19:42 ` [PATCHv2 net-next 8/8] net: ibm: emac: remove all waiting code Rosen Penev
2024-09-05 10:27 ` Paolo Abeni
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).