]> git.ipfire.org Git - people/arne_f/kernel.git/commitdiff
lan78xx: Read MAC address from DT if present
authorPhil Elwell <phil@raspberrypi.org>
Thu, 19 Apr 2018 16:59:38 +0000 (17:59 +0100)
committerArne Fitzenreiter <arne_f@ipfire.org>
Fri, 14 May 2021 13:17:20 +0000 (15:17 +0200)
There is a standard mechanism for locating and using a MAC address from
the Device Tree. Use this facility in the lan78xx driver to support
applications without programmed EEPROM or OTP. At the same time,
regularise the handling of the different address sources.

Signed-off-by: Phil Elwell <phil@raspberrypi.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/usb/lan78xx.c

index d6ffc92a634ec3f2113f01fa853d00e28994ccdc..c9e48bb16b7a9cf5bf3cbd9ea1fe210a4510c849 100644 (file)
@@ -1644,29 +1644,19 @@ static void lan78xx_init_mac_address(struct lan78xx_net *dev)
        addr[5] = (addr_hi >> 8) & 0xFF;
 
        if (!is_valid_ether_addr(addr)) {
-               /* maybe the boot loader passed the MAC address in devicetree */
-               mac_addr = of_get_mac_address(dev->udev->dev.of_node);
-               if (mac_addr) memcpy(addr, mac_addr, ETH_ALEN);
-               if (is_valid_ether_addr(addr)) {
+               if (!eth_platform_get_mac_address(&dev->udev->dev, addr)) {
+                       /* valid address present in Device Tree */
                        netif_dbg(dev, ifup, dev->net,
-                               "MAC address read from devicetree");
-               }
-
-               if (!is_valid_ether_addr(addr)) {
-                       /* reading mac address from EEPROM or OTP */
-                       if ((lan78xx_read_eeprom(dev, EEPROM_MAC_OFFSET, ETH_ALEN,
-                                        addr) == 0) ||
-                           (lan78xx_read_otp(dev, EEPROM_MAC_OFFSET, ETH_ALEN,
-                                             addr) == 0)) {
-                               if (is_valid_ether_addr(addr)) {
-                                       /* eeprom values are valid so use them */
-                                       netif_dbg(dev, ifup, dev->net,
-                                               "MAC address read from EEPROM");
-                               }
-                       }
-               }
-
-               if (!is_valid_ether_addr(addr)) {
+                                 "MAC address read from Device Tree");
+               } else if (((lan78xx_read_eeprom(dev, EEPROM_MAC_OFFSET,
+                                                ETH_ALEN, addr) == 0) ||
+                           (lan78xx_read_otp(dev, EEPROM_MAC_OFFSET,
+                                             ETH_ALEN, addr) == 0)) &&
+                          is_valid_ether_addr(addr)) {
+                       /* eeprom values are valid so use them */
+                       netif_dbg(dev, ifup, dev->net,
+                                 "MAC address read from EEPROM");
+               } else {
                        /* generate random MAC */
                        random_ether_addr(addr);
                        netif_dbg(dev, ifup, dev->net,