]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[smscusb] Fetch MAC from device tree for Raspberry Pi Model B+
authorMichael Brown <mcb30@ipxe.org>
Fri, 19 Jul 2019 18:15:33 +0000 (19:15 +0100)
committerMichael Brown <mcb30@ipxe.org>
Fri, 19 Jul 2019 18:15:33 +0000 (19:15 +0100)
Signed-off-by: Michael Brown <mcb30@ipxe.org>
src/drivers/net/lan78xx.c
src/drivers/net/smsc95xx.c
src/drivers/net/smscusb.c
src/drivers/net/smscusb.h

index 3f705203ee98e4abee422ff54866a7ca1219679c..a8cf574088587f3d9879281e9f000d3b767b85f0 100644 (file)
@@ -97,6 +97,10 @@ static int lan78xx_fetch_mac ( struct smscusb_device *smscusb ) {
        if ( ( rc = smscusb_otp_fetch_mac ( smscusb, LAN78XX_OTP_BASE ) ) == 0 )
                return 0;
 
+       /* Read MAC address from device tree, if present */
+       if ( ( rc = smscusb_fdt_fetch_mac ( smscusb ) ) == 0 )
+               return 0;
+
        /* Otherwise, generate a random MAC address */
        eth_random_addr ( netdev->hw_addr );
        DBGC ( smscusb, "LAN78XX %p using random MAC %s\n",
index 4ac3f42f0228579b4afe74b06556aa3173b78160..3ec49584def1a3afba25a97f9ea2ca7379856fbd 100644 (file)
@@ -33,7 +33,6 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
 #include <ipxe/profile.h>
 #include <ipxe/base16.h>
 #include <ipxe/smbios.h>
-#include <ipxe/fdt.h>
 #include "smsc95xx.h"
 
 /** @file
@@ -159,32 +158,6 @@ static int smsc95xx_vm3_fetch_mac ( struct smscusb_device *smscusb ) {
        return 0;
 }
 
-/**
- * Fetch MAC address from device tree
- *
- * @v smscusb          SMSC USB device
- * @ret rc             Return status code
- */
-static int smsc95xx_fdt_fetch_mac ( struct smscusb_device *smscusb ) {
-       struct net_device *netdev = smscusb->netdev;
-       unsigned int offset;
-       int rc;
-
-       /* Look for "ethernet[0]" alias */
-       if ( ( rc = fdt_alias ( "ethernet", &offset ) != 0 ) &&
-            ( rc = fdt_alias ( "ethernet0", &offset ) != 0 ) ) {
-               return rc;
-       }
-
-       /* Fetch MAC address */
-       if ( ( rc = fdt_mac ( offset, netdev ) ) != 0 )
-               return rc;
-
-       DBGC ( smscusb, "SMSC95XX %p using FDT MAC %s\n",
-              smscusb, eth_ntoa ( netdev->hw_addr ) );
-       return 0;
-}
-
 /**
  * Fetch MAC address
  *
@@ -200,8 +173,8 @@ static int smsc95xx_fetch_mac ( struct smscusb_device *smscusb ) {
                                               SMSC95XX_E2P_BASE ) ) == 0 )
                return 0;
 
-       /* Read MAC address from device tree */
-       if ( ( rc = smsc95xx_fdt_fetch_mac ( smscusb ) ) == 0 )
+       /* Read MAC address from device tree, if present */
+       if ( ( rc = smscusb_fdt_fetch_mac ( smscusb ) ) == 0 )
                return 0;
 
        /* Construct MAC address for Honeywell VM3, if applicable */
index 538d338c49a5672a4288a7fc086cbb96f7bf9cb2..c639c58c1cdeb456fc01e564e396103e20304663 100644 (file)
@@ -30,6 +30,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
 #include <ipxe/usbnet.h>
 #include <ipxe/ethernet.h>
 #include <ipxe/profile.h>
+#include <ipxe/fdt.h>
 #include "smscusb.h"
 
 /** @file
@@ -439,6 +440,39 @@ int smscusb_otp_fetch_mac ( struct smscusb_device *smscusb,
        return 0;
 }
 
+/******************************************************************************
+ *
+ * Device tree
+ *
+ ******************************************************************************
+ */
+
+/**
+ * Fetch MAC address from device tree
+ *
+ * @v smscusb          SMSC USB device
+ * @ret rc             Return status code
+ */
+int smscusb_fdt_fetch_mac ( struct smscusb_device *smscusb ) {
+       struct net_device *netdev = smscusb->netdev;
+       unsigned int offset;
+       int rc;
+
+       /* Look for "ethernet[0]" alias */
+       if ( ( rc = fdt_alias ( "ethernet", &offset ) != 0 ) &&
+            ( rc = fdt_alias ( "ethernet0", &offset ) != 0 ) ) {
+               return rc;
+       }
+
+       /* Fetch MAC address */
+       if ( ( rc = fdt_mac ( offset, netdev ) ) != 0 )
+               return rc;
+
+       DBGC ( smscusb, "SMSCUSB %p using FDT MAC %s\n",
+              smscusb, eth_ntoa ( netdev->hw_addr ) );
+       return 0;
+}
+
 /******************************************************************************
  *
  * MII access
index b5d9ad3fcc323a3d5b76f4fcc51dbb1874c2c6ae..e866bb7471270d7ec333709729174ed2a836f69d 100644 (file)
@@ -287,6 +287,7 @@ extern int smscusb_eeprom_fetch_mac ( struct smscusb_device *smscusb,
                                      unsigned int e2p_base );
 extern int smscusb_otp_fetch_mac ( struct smscusb_device *smscusb,
                                   unsigned int otp_base );
+extern int smscusb_fdt_fetch_mac ( struct smscusb_device *smscusb );
 extern int smscusb_mii_check_link ( struct smscusb_device *smscusb );
 extern int smscusb_mii_open ( struct smscusb_device *smscusb,
                              unsigned int phy_mask, unsigned int intrs );