Skip to contentSkip to conversation

net: enc28j60: use of_get_ethdev_address

PATCH In review Rosen Penev 2 participants 3 messages Apr 27

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: enc28j60: use of_get_ethdev_address

Since this is an OF only driver, of_ instead of device_ allows nvmem to be used to specify the MAC address.

Add EPROBE_DEFER handling for NVMEM.

---
 drivers/net/ethernet/microchip/enc28j60.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/net/ethernet/microchip/enc28j60.c +5 -1
index d6c9491537e4..2b9b4163e419 100644
@@ -24,6 +24,7 @@
 #include <linux/skbuff.h>
 #include <linux/delay.h>
 #include <linux/spi/spi.h>
+#include <linux/of_net.h>
 
 #include "enc28j60_hw.h"
 
@@ -1554,7 +1555,10 @@ static int enc28j60_probe(struct spi_device *spi)
 		goto error_irq;
 	}
 
-	if (device_get_ethdev_address(&spi->dev, dev))
+	ret = of_get_ethdev_address(spi->dev.of_node, dev);
+	if (ret == -EPROBE_DEFER)
+		return ret;
+	if (ret)
 		eth_hw_addr_random(dev);
 	enc28j60_set_hw_macaddr(dev);
 
Signature · 1 line
2.54.0
#1 lore raw
Quoted 2 lines · Rosen Penev

Since this is an OF only driver, of_ instead of device_ allows nvmem to be used to specify the MAC address.

Now that is usual, somebody converting device_ to of_. It is normally the other way around, for not particularly good reasons. Nice.

drivers/net/ethernet/microchip/enc28j60.c static int enc28j60_probe(struct spi_device *spi) · line 1560

Quoted 4 lines
drivers/net/ethernet/microchip/enc28j60.c +3 -1
-	if (device_get_ethdev_address(&spi->dev, dev))
+	ret = of_get_ethdev_address(spi->dev.of_node, dev);
+	if (ret == -EPROBE_DEFER)
+		return ret;

/**
* device_get_mac_address - Get the MAC for a given device
* @dev: Pointer to the device
* @addr: Address of buffer to store the MAC in
*/
int device_get_mac_address(struct device *dev, char *addr)

{
	if (!fwnode_get_mac_address(dev_fwnode(dev), addr))
		return 0;

	return nvmem_get_mac_address(dev, addr);
}

EXPORT_SYMBOL(device_get_mac_address);

This appears to support nvmem. Would device_get_mac_address() actually work? I'm not against swapping to of_get_ethdev_address, but the commit message should be accurate.

Andrew

#2 lore raw
Quoted 25 lines · Andrew Lunn
Quoted 2 lines · Rosen Penev

Since this is an OF only driver, of_ instead of device_ allows nvmem to be used to specify the MAC address.

Now that is usual, somebody converting device_ to of_. It is normally the other way around, for not particularly good reasons. Nice.

drivers/net/ethernet/microchip/enc28j60.c static int enc28j60_probe(struct spi_device *spi) · line 1560

Quoted 4 lines
drivers/net/ethernet/microchip/enc28j60.c +3 -1
-     if (device_get_ethdev_address(&spi->dev, dev))
+     ret = of_get_ethdev_address(spi->dev.of_node, dev);
+     if (ret == -EPROBE_DEFER)
+             return ret;

/**
* device_get_mac_address - Get the MAC for a given device
* @dev: Pointer to the device
* @addr: Address of buffer to store the MAC in
*/
int device_get_mac_address(struct device *dev, char *addr)

{
        if (!fwnode_get_mac_address(dev_fwnode(dev), addr))
                return 0;

        return nvmem_get_mac_address(dev, addr);
}
Quoted 5 lines

EXPORT_SYMBOL(device_get_mac_address);

This appears to support nvmem. Would device_get_mac_address() actually work? I'm not against swapping to of_get_ethdev_address, but the commit message should be accurate.

I seem to have missed
https://lore.kernel.org/all/[email protected]/

Quoted 2 lines

Andrew