Message ID | 20210414230648.76129-8-tsbogend@alpha.franken.de (mailing list archive) |
---|---|
State | Superseded |
Delegated to: | Netdev Maintainers |
Headers | show |
Series | net: Korina improvements | expand |
> - memcpy(dev->dev_addr, mac_addr, ETH_ALEN); > + if (mac_addr) { > + ether_addr_copy(dev->dev_addr, mac_addr); > + } else { > + u8 ofmac[ETH_ALEN]; > + > + if (of_get_mac_address(pdev->dev.of_node, ofmac) == 0) > + ether_addr_copy(dev->dev_addr, ofmac); You should be able to skip the ether_addr_copy() by passing dev->dev_addr directly to of_get_mac_address(). > + else > + eth_hw_addr_random(dev); > + } > > lp->rx_irq = platform_get_irq_byname(pdev, "korina_rx"); > lp->tx_irq = platform_get_irq_byname(pdev, "korina_tx"); > @@ -1146,8 +1157,21 @@ static int korina_remove(struct platform_device *pdev) > return 0; > } > > +#ifdef CONFIG_OF > +static const struct of_device_id korina_match[] = { > + { > + .compatible = "idt,3243x-emac", You need to document this compatible somewhere under Documentation/devicetree/binding Andrew
On Fri, Apr 16, 2021 at 01:49:07AM +0200, Andrew Lunn wrote: > > - memcpy(dev->dev_addr, mac_addr, ETH_ALEN); > > + if (mac_addr) { > > + ether_addr_copy(dev->dev_addr, mac_addr); > > + } else { > > + u8 ofmac[ETH_ALEN]; > > + > > + if (of_get_mac_address(pdev->dev.of_node, ofmac) == 0) > > + ether_addr_copy(dev->dev_addr, ofmac); > > You should be able to skip the ether_addr_copy() by passing > dev->dev_addr directly to of_get_mac_address(). good point > > > + else > > + eth_hw_addr_random(dev); > > + } > > > > lp->rx_irq = platform_get_irq_byname(pdev, "korina_rx"); > > lp->tx_irq = platform_get_irq_byname(pdev, "korina_tx"); > > @@ -1146,8 +1157,21 @@ static int korina_remove(struct platform_device *pdev) > > return 0; > > } > > > > +#ifdef CONFIG_OF > > +static const struct of_device_id korina_match[] = { > > + { > > + .compatible = "idt,3243x-emac", > > You need to document this compatible somewhere under Documentation/devicetree/binding checkpatch hinted to put it in an extra patch, it's patch 10 of this series and looking at my inbox it didn't get through :-(. Thomas.
diff --git a/drivers/net/ethernet/korina.c b/drivers/net/ethernet/korina.c index 1d7dead17ac3..7646ccc9d7e8 100644 --- a/drivers/net/ethernet/korina.c +++ b/drivers/net/ethernet/korina.c @@ -43,6 +43,8 @@ #include <linux/ioport.h> #include <linux/iopoll.h> #include <linux/in.h> +#include <linux/of_device.h> +#include <linux/of_net.h> #include <linux/slab.h> #include <linux/string.h> #include <linux/delay.h> @@ -1066,7 +1068,16 @@ static int korina_probe(struct platform_device *pdev) SET_NETDEV_DEV(dev, &pdev->dev); lp = netdev_priv(dev); - memcpy(dev->dev_addr, mac_addr, ETH_ALEN); + if (mac_addr) { + ether_addr_copy(dev->dev_addr, mac_addr); + } else { + u8 ofmac[ETH_ALEN]; + + if (of_get_mac_address(pdev->dev.of_node, ofmac) == 0) + ether_addr_copy(dev->dev_addr, ofmac); + else + eth_hw_addr_random(dev); + } lp->rx_irq = platform_get_irq_byname(pdev, "korina_rx"); lp->tx_irq = platform_get_irq_byname(pdev, "korina_tx"); @@ -1146,8 +1157,21 @@ static int korina_remove(struct platform_device *pdev) return 0; } +#ifdef CONFIG_OF +static const struct of_device_id korina_match[] = { + { + .compatible = "idt,3243x-emac", + }, + { } +}; +MODULE_DEVICE_TABLE(of, korina_match); +#endif + static struct platform_driver korina_driver = { - .driver.name = "korina", + .driver = { + .name = "korina", + .of_match_table = of_match_ptr(korina_match), + }, .probe = korina_probe, .remove = korina_remove, };
If there is no mac address passed via platform data try to get it via device tree and fall back to a random mac address, if all fail. Signed-off-by: Thomas Bogendoerfer <tsbogend@alpha.franken.de> --- drivers/net/ethernet/korina.c | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-)