Skip to contentSkip to conversation

net: mdio: Add mdio_free() and mdio_unregister() API

PATCH Superseded Bin Meng 3 participants 19 messages Sep 4, 2015 – Sep 11, 2015 Network drivers

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Bin Meng

author
#0 lore raw

PATCH 1/5 net: mdio: Add mdio_free() and mdio_unregister() API

Currently there is no API to uninitialize mdio. Add two APIs for this.

---

 common/miiphyutil.c | 19 +++++++++++++++++++
 include/miiphy.h    |  2 ++
 2 files changed, 21 insertions(+)
common/miiphyutil.c +19 -0
index c88c28a..e499b58 100644
@@ -152,6 +152,11 @@ struct mii_dev *mdio_alloc(void)
 	return bus;
 }
 
+void mdio_free(struct mii_dev *bus)
+{
+	free(bus);
+}
+
 int mdio_register(struct mii_dev *bus)
 {
 	if (!bus || !bus->name || !bus->read || !bus->write)
@@ -173,6 +178,20 @@ int mdio_register(struct mii_dev *bus)
 	return 0;
 }
 
+int mdio_unregister(struct mii_dev *bus)
+{
+	if (!bus)
+		return 0;
+
+	/* delete it from the list */
+	list_del(&bus->link);
+
+	if (current_mii == bus)
+		current_mii = NULL;
+
+	return 0;
+}
+
 void mdio_list_devices(void)
 {
 	struct list_head *entry;
include/miiphy.h +2 -0
index 088797e..af12274 100644
@@ -59,7 +59,9 @@ struct phy_device *mdio_phydev_for_ethname(const char *devname);
 void miiphy_listdev(void);
 
 struct mii_dev *mdio_alloc(void);
+void mdio_free(struct mii_dev *bus);
 int mdio_register(struct mii_dev *bus);
+int mdio_unregister(struct mii_dev *bus);
 void mdio_list_devices(void);
 
 #ifdef CONFIG_BITBANGMII
Signature · 1 line
1.8.2.1
author
#1 lore raw

PATCH 1/5 net: mdio: Add mdio_free() and mdio_unregister() API

Hi Joe,

Quoted 51 lines · Bin Meng

Currently there is no API to uninitialize mdio. Add two APIs for this.

---

 common/miiphyutil.c | 19 +++++++++++++++++++
 include/miiphy.h    |  2 ++
 2 files changed, 21 insertions(+)
common/miiphyutil.c +19 -0
index c88c28a..e499b58 100644
@@ -152,6 +152,11 @@ struct mii_dev *mdio_alloc(void)
        return bus;
 }
 
+void mdio_free(struct mii_dev *bus)
+{
+       free(bus);
+}
+
 int mdio_register(struct mii_dev *bus)
 {
        if (!bus || !bus->name || !bus->read || !bus->write)
@@ -173,6 +178,20 @@ int mdio_register(struct mii_dev *bus)
        return 0;
 }
 
+int mdio_unregister(struct mii_dev *bus)
+{
+       if (!bus)
+               return 0;
+
+       /* delete it from the list */
+       list_del(&bus->link);
+
+       if (current_mii == bus)
+               current_mii = NULL;
+
+       return 0;
+}
+
 void mdio_list_devices(void)
 {
        struct list_head *entry;
include/miiphy.h +0 -0
index 088797e..af12274 100644

include/miiphy.h struct phy_device *mdio_phydev_for_ethname(const char *devname);

Quoted 10 lines
include/miiphy.h +2 -1
@@ -59,7 +59,9 @@ struct phy_device *mdio_phydev_for_ethname(const char *devname);
 void miiphy_listdev(void);
 
 struct mii_dev *mdio_alloc(void);
+void mdio_free(struct mii_dev *bus);
 int mdio_register(struct mii_dev *bus);
+int mdio_unregister(struct mii_dev *bus);
 void mdio_list_devices(void);
 
 #ifdef CONFIG_BITBANGMII
--

Ping?

Regards,
Bin

author
#2 lore raw

PATCH 2/5 net: designware: Add driver remove support

In reply to Bin Meng

In designware_eth_probe(), some additional resources are allocated (eg: mdio, phy). We should free these in the driver remove phase. Add designware_eth_remove() to clean it up.

---

 drivers/net/designware.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
drivers/net/designware.c +12 -0
index d45340c..d2aedb0 100644
@@ -609,6 +609,17 @@ static int designware_eth_probe(struct udevice *dev)
 	return ret;
 }
 
+static int designware_eth_remove(struct udevice *dev)
+{
+	struct dw_eth_dev *priv = dev_get_priv(dev);
+
+	free(priv->phydev);
+	mdio_unregister(priv->bus);
+	mdio_free(priv->bus);
+
+	return 0;
+}
+
 static const struct eth_ops designware_eth_ops = {
 	.start			= designware_eth_start,
 	.send			= designware_eth_send,
@@ -649,6 +660,7 @@ U_BOOT_DRIVER(eth_designware) = {
 	.ofdata_to_platdata = designware_eth_ofdata_to_platdata,
 	.bind	= designware_eth_bind,
 	.probe	= designware_eth_probe,
+	.remove	= designware_eth_remove,
 	.ops	= &designware_eth_ops,
 	.priv_auto_alloc_size = sizeof(struct dw_eth_dev),
 	.platdata_auto_alloc_size = sizeof(struct eth_pdata),
Signature · 1 line
1.8.2.1
#3 lore raw

PATCH 2/5 net: designware: Add driver remove support

Quoted 9 lines · Bin Meng

In designware_eth_probe(), some additional resources are allocated (eg: mdio, phy). We should free these in the driver remove phase. Add designware_eth_remove() to clean it up.

---

 drivers/net/designware.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
author
#4 lore raw

PATCH 3/5 net: pch_gbe: Add driver remove support

In reply to Bin Meng

In pch_gbe_probe(), some additional resources are allocated (eg: mdio, phy). We should free these in the driver remove phase. Add pch_gbe_remove() to clean it up.

---

 drivers/net/pch_gbe.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
drivers/net/pch_gbe.c +12 -0
index 004fcf8..dfc0100 100644
@@ -452,6 +452,17 @@ int pch_gbe_probe(struct udevice *dev)
 	return pch_gbe_phy_init(dev);
 }
 
+int pch_gbe_remove(struct udevice *dev)
+{
+	struct pch_gbe_priv *priv = dev_get_priv(dev);
+
+	free(priv->phydev);
+	mdio_unregister(priv->bus);
+	mdio_free(priv->bus);
+
+	return 0;
+}
+
 static const struct eth_ops pch_gbe_ops = {
 	.start = pch_gbe_start,
 	.send = pch_gbe_send,
@@ -470,6 +481,7 @@ U_BOOT_DRIVER(eth_pch_gbe) = {
 	.id = UCLASS_ETH,
 	.of_match = pch_gbe_ids,
 	.probe = pch_gbe_probe,
+	.remove = pch_gbe_remove,
 	.ops = &pch_gbe_ops,
 	.priv_auto_alloc_size = sizeof(struct pch_gbe_priv),
 	.platdata_auto_alloc_size = sizeof(struct eth_pdata),
Signature · 1 line
1.8.2.1
#5 lore raw

PATCH 3/5 net: pch_gbe: Add driver remove support

Quoted 10 lines · Bin Meng

In pch_gbe_probe(), some additional resources are allocated (eg: mdio, phy). We should free these in the driver remove phase. Add pch_gbe_remove() to clean it up.

---

 drivers/net/pch_gbe.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
Quoted 2 lines
author
#6 lore raw

PATCH 4/5 dm: core: Remove the call to device_free()

In reply to Bin Meng

When something goes wrong during device_probe(), we just need do device_remove() which calls device_free() internally.

---

 drivers/core/device.c | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)
drivers/core/device.c +2 -7
index a6cd936..061a7ef 100644
@@ -316,19 +316,14 @@ int device_probe_child(struct udevice *dev, void *parent_priv)
 
 	ret = uclass_post_probe_device(dev);
 	if (ret)
-		goto fail_uclass;
+		goto fail;
 
 	return 0;
-fail_uclass:
+fail:
 	if (device_remove(dev)) {
 		dm_warn("%s: Device '%s' failed to remove on error path\n",
 			__func__, dev->name);
 	}
-fail:
-	dev->flags &= ~DM_FLAG_ACTIVATED;
-
-	dev->seq = -1;
-	device_free(dev);
 
 	return ret;
 }
Signature · 1 line
1.8.2.1
#7 lore raw

PATCH 4/5 dm: core: Remove the call to device_free()

Hi Bin,

Quoted 26 lines · Bin Meng

When something goes wrong during device_probe(), we just need do device_remove() which calls device_free() internally.

---

 drivers/core/device.c | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)
drivers/core/device.c +2 -2
index a6cd936..061a7ef 100644
@@ -316,19 +316,14 @@ int device_probe_child(struct udevice *dev, void *parent_priv)
 
        ret = uclass_post_probe_device(dev);
        if (ret)
-               goto fail_uclass;
+               goto fail;
 
        return 0;
-fail_uclass:
+fail:
        if (device_remove(dev)) {
                dm_warn("%s: Device '%s' failed to remove on error path\n",

drivers/core/device.c int device_probe_child(struct udevice *dev, void *parent_priv) · line 329

Quoted 10 lines
drivers/core/device.c +0 -5
                        __func__, dev->name);
        }
-fail:
-       dev->flags &= ~DM_FLAG_ACTIVATED;
-
-       dev->seq = -1;
-       device_free(dev);
 
        return ret;
 }

The problem is that in this case you end up calling functions that should not be called. For example uclass_pre_remove_device() will be called even if uclass_post_probe_device() was not.

There is definitely room for improvement here - we could/should call only those 'remove' functions that mirror the 'probe' ones we called. But that is quite a lot of code for little benefit.

Regards,
Simon

Quoted 2 lines
author
#8 lore raw

PATCH 4/5 dm: core: Remove the call to device_free()

Hi Simon,

Quoted 37 lines · Simon Glass

Hi Bin,

Quoted 34 lines · Bin Meng

When something goes wrong during device_probe(), we just need do device_remove() which calls device_free() internally.

---

 drivers/core/device.c | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)
drivers/core/device.c +2 -7
index a6cd936..061a7ef 100644
@@ -316,19 +316,14 @@ int device_probe_child(struct udevice *dev, void *parent_priv)
 
        ret = uclass_post_probe_device(dev);
        if (ret)
-               goto fail_uclass;
+               goto fail;
 
        return 0;
-fail_uclass:
+fail:
        if (device_remove(dev)) {
                dm_warn("%s: Device '%s' failed to remove on error path\n",
                        __func__, dev->name);
        }
-fail:
-       dev->flags &= ~DM_FLAG_ACTIVATED;
-
-       dev->seq = -1;
-       device_free(dev);
 
Quoted 8 lines

drivers/core/device.c int device_probe_child(struct udevice *dev, void *parent_priv) · line 329

Quoted 2 lines
drivers/core/device.c +0 -0
        return ret;
 }

The problem is that in this case you end up calling functions that should not be called. For example uclass_pre_remove_device() will be called even if uclass_post_probe_device() was not.

Yes, but doing uclass_pre_remove_device() should not bring any harm, given we already want to remove this device, right?

Quoted 4 lines

There is definitely room for improvement here - we could/should call only those 'remove' functions that mirror the 'probe' ones we called. But that is quite a lot of code for little benefit.

Regards,
Bin

#9 lore raw

PATCH 4/5 dm: core: Remove the call to device_free()

Hi Bin,

Quoted 49 lines · Bin Meng

Hi Simon,

Quoted 37 lines · Simon Glass

Hi Bin,

Quoted 34 lines · Bin Meng

When something goes wrong during device_probe(), we just need do device_remove() which calls device_free() internally.

---

 drivers/core/device.c | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)
drivers/core/device.c +2 -7
index a6cd936..061a7ef 100644
@@ -316,19 +316,14 @@ int device_probe_child(struct udevice *dev, void *parent_priv)
 
        ret = uclass_post_probe_device(dev);
        if (ret)
-               goto fail_uclass;
+               goto fail;
 
        return 0;
-fail_uclass:
+fail:
        if (device_remove(dev)) {
                dm_warn("%s: Device '%s' failed to remove on error path\n",
                        __func__, dev->name);
        }
-fail:
-       dev->flags &= ~DM_FLAG_ACTIVATED;
-
-       dev->seq = -1;
-       device_free(dev);
 
Quoted 8 lines

drivers/core/device.c int device_probe_child(struct udevice *dev, void *parent_priv) · line 329

Quoted 2 lines
drivers/core/device.c +0 -0
        return ret;
 }

The problem is that in this case you end up calling functions that should not be called. For example uclass_pre_remove_device() will be called even if uclass_post_probe_device() was not.

Quoted 2 lines

Yes, but doing uclass_pre_remove_device() should not bring any harm, given we already want to remove this device, right?

That function is entitled to assume that the device was set up at least to the post_remove uclass state. Here that would not be try, so we are creating an entirely new test case.

Quoted 4 lines
Quoted 4 lines

There is definitely room for improvement here - we could/should call only those 'remove' functions that mirror the 'probe' ones we called. But that is quite a lot of code for little benefit.

Regards,
Simon

author
#10 lore raw

PATCH 4/5 dm: core: Remove the call to device_free()

Hi Simon,

Quoted 52 lines · Simon Glass

Hi Bin,

Quoted 49 lines · Bin Meng

Hi Simon,

Quoted 45 lines · Simon Glass

Hi Bin,

Quoted 26 lines · Bin Meng

When something goes wrong during device_probe(), we just need do device_remove() which calls device_free() internally.

---

 drivers/core/device.c | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)
drivers/core/device.c +2 -2
index a6cd936..061a7ef 100644
@@ -316,19 +316,14 @@ int device_probe_child(struct udevice *dev, void *parent_priv)
 
        ret = uclass_post_probe_device(dev);
        if (ret)
-               goto fail_uclass;
+               goto fail;
 
        return 0;
-fail_uclass:
+fail:
        if (device_remove(dev)) {
                dm_warn("%s: Device '%s' failed to remove on error path\n",

drivers/core/device.c int device_probe_child(struct udevice *dev, void *parent_priv) · line 329

Quoted 10 lines
drivers/core/device.c +0 -5
                        __func__, dev->name);
        }
-fail:
-       dev->flags &= ~DM_FLAG_ACTIVATED;
-
-       dev->seq = -1;
-       device_free(dev);
 
        return ret;
 }

The problem is that in this case you end up calling functions that should not be called. For example uclass_pre_remove_device() will be called even if uclass_post_probe_device() was not.

Quoted 12 lines
Quoted 2 lines

Yes, but doing uclass_pre_remove_device() should not bring any harm, given we already want to remove this device, right?

That function is entitled to assume that the device was set up at least to the post_remove uclass state. Here that would not be try, so we are creating an entirely new test case.

Quoted 4 lines
Quoted 4 lines

There is definitely room for improvement here - we could/should call only those 'remove' functions that mirror the 'probe' ones we called. But that is quite a lot of code for little benefit.

OK, will drop this.

Regards,
Bin

#11 lore raw

PATCH 4/5 dm: core: Remove the call to device_free()

Hi Bin,

Quoted 20 lines · Bin Meng

Hi Simon,

Quoted 16 lines · Simon Glass

Hi Bin,

Quoted 13 lines · Bin Meng

Hi Simon,

Quoted 10 lines · Simon Glass

Hi Bin,

Quoted 7 lines · Bin Meng

When something goes wrong during device_probe(), we just need do device_remove() which calls device_free() internally.

---

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

drivers/core/device.c int device_probe_child(struct udevice *dev,

Quoted 8 lines
 drivers/core/device.c | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)
drivers/core/device.c +0 -0
index a6cd936..061a7ef 100644
@@ -316,19 +316,14 @@ int device_probe_child(struct udevice *dev,

void *parent_priv)

Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines

drivers/core/device.c int device_probe_child(struct udevice *dev, void *parent_priv)

Quoted 11 lines
drivers/core/device.c +2 -2
        ret = uclass_post_probe_device(dev);
        if (ret)
-               goto fail_uclass;
+               goto fail;
 
        return 0;
-fail_uclass:
+fail:
        if (device_remove(dev)) {
                dm_warn("%s: Device '%s' failed to remove on error

path\n",

Quoted 25 lines
Quoted 25 lines
Quoted 17 lines
Quoted 8 lines
Quoted 8 lines
drivers/core/device.c +0 -5
                        __func__, dev->name);
        }
-fail:
-       dev->flags &= ~DM_FLAG_ACTIVATED;
-
-       dev->seq = -1;
-       device_free(dev);
 
Quoted 8 lines

drivers/core/device.c int device_probe_child(struct udevice *dev, void *parent_priv) · line 329

Quoted 2 lines
drivers/core/device.c +0 -0
        return ret;
 }

The problem is that in this case you end up calling functions that should not be called. For example uclass_pre_remove_device() will be called even if uclass_post_probe_device() was not.

Quoted 2 lines

Yes, but doing uclass_pre_remove_device() should not bring any harm, given we already want to remove this device, right?

That function is entitled to assume that the device was set up at least to the post_remove uclass state. Here that would not be try, so we are creating an entirely new test case.

Quoted 1 line
Quoted 6 lines
Quoted 4 lines
Quoted 3 lines
Quoted 3 lines

There is definitely room for improvement here - we could/should call only those 'remove' functions that mirror the 'probe' ones we called. But that is quite a lot of code for little benefit.

OK, will drop this.

Sorry, that was complete gibberish.

That function is entitled to assume that the device was set up at least to the post_probe uclass state. Here that would not be true, so we are creating an entirely new test case.

Regards,
Simon

author
#12 lore raw

PATCH 5/5 dm: core: Remove unnecessary codes in uclass_pre_remove_device()

In reply to Bin Meng

dev->uclass->uc_drv->per_device_auto_alloc_size is to be freed in device_free(), so is dev->seq. Remove these unnecessary codes.

---

 drivers/core/uclass.c | 7 -------
 1 file changed, 7 deletions(-)
drivers/core/uclass.c +0 -7
index f63ff59..8b0fb88 100644
@@ -518,22 +518,15 @@ int uclass_post_probe_device(struct udevice *dev)
 #if CONFIG_IS_ENABLED(DM_DEVICE_REMOVE)
 int uclass_pre_remove_device(struct udevice *dev)
 {
-	struct uclass_driver *uc_drv;
 	struct uclass *uc;
 	int ret;
 
 	uc = dev->uclass;
-	uc_drv = uc->uc_drv;
 	if (uc->uc_drv->pre_remove) {
 		ret = uc->uc_drv->pre_remove(dev);
 		if (ret)
 			return ret;
 	}
-	if (uc_drv->per_device_auto_alloc_size) {
-		free(dev->uclass_priv);
-		dev->uclass_priv = NULL;
-	}
-	dev->seq = -1;
 
 	return 0;
 }
Signature · 1 line
1.8.2.1
#13 lore raw

PATCH 5/5 dm: core: Remove unnecessary codes in uclass_pre_remove_device()

Quoted 9 lines · Bin Meng

dev->uclass->uc_drv->per_device_auto_alloc_size is to be freed in device_free(), so is dev->seq. Remove these unnecessary codes.

---

 drivers/core/uclass.c | 7 -------
 1 file changed, 7 deletions(-)

Looks right to me.

#14 lore raw

PATCH 1/5 net: mdio: Add mdio_free() and mdio_unregister() API

In reply to Bin Meng

Hi Bin,

Quoted 15 lines · Bin Meng

Currently there is no API to uninitialize mdio. Add two APIs for this.

---

 common/miiphyutil.c | 19 +++++++++++++++++++
 include/miiphy.h    |  2 ++
 2 files changed, 21 insertions(+)
common/miiphyutil.c +0 -0
index c88c28a..e499b58 100644

common/miiphyutil.c struct mii_dev *mdio_alloc(void) · line 158

Quoted 7 lines
common/miiphyutil.c +4 -0
@@ -152,6 +152,11 @@ struct mii_dev *mdio_alloc(void)
        return bus;
 }
 
+void mdio_free(struct mii_dev *bus)
+{
+       free(bus);
+}

Should this function be exported, or just called from mdio_unregister()?

Quoted 31 lines
common/miiphyutil.c +15 -0
+
 int mdio_register(struct mii_dev *bus)
 {
        if (!bus || !bus->name || !bus->read || !bus->write)
@@ -173,6 +178,20 @@ int mdio_register(struct mii_dev *bus)
        return 0;
 }
 
+int mdio_unregister(struct mii_dev *bus)
+{
+       if (!bus)
+               return 0;
+
+       /* delete it from the list */
+       list_del(&bus->link);
+
+       if (current_mii == bus)
+               current_mii = NULL;
+
+       return 0;
+}
+
 void mdio_list_devices(void)
 {
        struct list_head *entry;
include/miiphy.h +0 -0
index 088797e..af12274 100644

include/miiphy.h struct phy_device *mdio_phydev_for_ethname(const char *devname); · line 64

Quoted 6 lines
include/miiphy.h +2 -0
@@ -59,7 +59,9 @@ struct phy_device *mdio_phydev_for_ethname(const char *devname);
 void miiphy_listdev(void);
 
 struct mii_dev *mdio_alloc(void);
+void mdio_free(struct mii_dev *bus);
 int mdio_register(struct mii_dev *bus);
+int mdio_unregister(struct mii_dev *bus);

Function comments.

Quoted 7 lines
include/miiphy.h +0 -1
 void mdio_list_devices(void);
 
 #ifdef CONFIG_BITBANGMII
--

1.8.2.1

Regards,
Simon

author
#15 lore raw

PATCH 1/5 net: mdio: Add mdio_free() and mdio_unregister() API

Hi Simon,

Quoted 21 lines · Simon Glass

Hi Bin,

Quoted 18 lines · Bin Meng

Currently there is no API to uninitialize mdio. Add two APIs for this.

---

 common/miiphyutil.c | 19 +++++++++++++++++++
 include/miiphy.h    |  2 ++
 2 files changed, 21 insertions(+)
common/miiphyutil.c +0 -0
index c88c28a..e499b58 100644
@@ -152,6 +152,11 @@ struct mii_dev *mdio_alloc(void)
        return bus;
 }
 
Quoted 8 lines

common/miiphyutil.c struct mii_dev *mdio_alloc(void) · line 158

Quoted 4 lines
common/miiphyutil.c +4 -0
+void mdio_free(struct mii_dev *bus)
+{
+       free(bus);
+}

Should this function be exported, or just called from mdio_unregister()?

I created mdio_free() to keep API symmetry - there is an mdio_alloc() API already. IMHO we should remove mdio_alloc() API and move mdio_alloc() to inside mdio_register(), but did not do that way as that change is quite big (a bunch of ethernet drivers need update). What do you think?

Quoted 33 lines
Quoted 33 lines
common/miiphyutil.c +15 -0
+
 int mdio_register(struct mii_dev *bus)
 {
        if (!bus || !bus->name || !bus->read || !bus->write)
@@ -173,6 +178,20 @@ int mdio_register(struct mii_dev *bus)
        return 0;
 }
 
+int mdio_unregister(struct mii_dev *bus)
+{
+       if (!bus)
+               return 0;
+
+       /* delete it from the list */
+       list_del(&bus->link);
+
+       if (current_mii == bus)
+               current_mii = NULL;
+
+       return 0;
+}
+
 void mdio_list_devices(void)
 {
        struct list_head *entry;
include/miiphy.h +0 -0
index 088797e..af12274 100644
@@ -59,7 +59,9 @@ struct phy_device *mdio_phydev_for_ethname(const char *devname);
 void miiphy_listdev(void);
 
Quoted 7 lines

include/miiphy.h struct phy_device *mdio_phydev_for_ethname(const char *devname); · line 64

Quoted 4 lines
include/miiphy.h +2 -0
 struct mii_dev *mdio_alloc(void);
+void mdio_free(struct mii_dev *bus);
 int mdio_register(struct mii_dev *bus);
+int mdio_unregister(struct mii_dev *bus);

Function comments.

OK

Quoted 6 lines

include/miiphy.h struct phy_device *mdio_phydev_for_ethname(const char *devname);

Quoted 6 lines
include/miiphy.h +0 -1
 void mdio_list_devices(void);
 
 #ifdef CONFIG_BITBANGMII
--

Regards,
Bin

#16 lore raw

PATCH 1/5 net: mdio: Add mdio_free() and mdio_unregister() API

In reply to Bin Meng

Hi Bin,

Quoted 1 line · Bin Meng

Currently there is no API to uninitialize mdio. Add two APIs for this.

Is this causing some failure in the short term? The plan is to move eth phy support to driver model in the next year. If it is not needed for a device to function then it would be nice to not spend effort on this API.

If it is needed short term, then the approach looks fine.

Cheers,
-Joe

Quoted 65 lines

---

 common/miiphyutil.c | 19 +++++++++++++++++++
 include/miiphy.h    |  2 ++
 2 files changed, 21 insertions(+)
common/miiphyutil.c +19 -0
index c88c28a..e499b58 100644
@@ -152,6 +152,11 @@ struct mii_dev *mdio_alloc(void)
        return bus;
 }
 
+void mdio_free(struct mii_dev *bus)
+{
+       free(bus);
+}
+
 int mdio_register(struct mii_dev *bus)
 {
        if (!bus || !bus->name || !bus->read || !bus->write)
@@ -173,6 +178,20 @@ int mdio_register(struct mii_dev *bus)
        return 0;
 }
 
+int mdio_unregister(struct mii_dev *bus)
+{
+       if (!bus)
+               return 0;
+
+       /* delete it from the list */
+       list_del(&bus->link);
+
+       if (current_mii == bus)
+               current_mii = NULL;
+
+       return 0;
+}
+
 void mdio_list_devices(void)
 {
        struct list_head *entry;
include/miiphy.h +2 -1
index 088797e..af12274 100644
@@ -59,7 +59,9 @@ struct phy_device *mdio_phydev_for_ethname(const char *devname);
 void miiphy_listdev(void);
 
 struct mii_dev *mdio_alloc(void);
+void mdio_free(struct mii_dev *bus);
 int mdio_register(struct mii_dev *bus);
+int mdio_unregister(struct mii_dev *bus);
 void mdio_list_devices(void);
 
 #ifdef CONFIG_BITBANGMII
--

1.8.2.1

_______________________________________________
U-Boot mailing list
U-Boot at lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot

author
#17 lore raw

PATCH 1/5 net: mdio: Add mdio_free() and mdio_unregister() API

Hi Joe,

Quoted 9 lines · Joe Hershberger

Hi Bin,

Quoted 1 line · Bin Meng

Currently there is no API to uninitialize mdio. Add two APIs for this.

Is this causing some failure in the short term? The plan is to move eth phy support to driver model in the next year. If it is not needed for a device to function then it would be nice to not spend effort on this API.

Good to know we have plan to convert PHY support to driver model.

Quoted 3 lines

If it is needed short term, then the approach looks fine.

Yes, it is needed, otherwise for ethernet device which depends on this PHY support it will fail to probe() for the 2nd time as the MDIO resource are not cleaned up.
In the future when we convert PHY support to driver model, we won't miss this part if these are added now.

[snip]

Regards,
Bin