Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 20 May 2019 22:21:47 +0000 (UTC)
From:      Ian Lepore <ian@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r348018 - head/sys/dev/usb/net
Message-ID:  <201905202221.x4KMLlYe013204@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: ian
Date: Mon May 20 22:21:47 2019
New Revision: 348018
URL: https://svnweb.freebsd.org/changeset/base/348018

Log:
  A MAC adddress from FDT data should override anything stored in eeprom or
  OTP registers (because the user is in control of the fdt data).  Remove the
  early returns from the code that tries to find a good mac address, so that
  the execution always flows through the routine to get an address from FDT
  data last, when on FDT-enabled systems.

Modified:
  head/sys/dev/usb/net/if_muge.c

Modified: head/sys/dev/usb/net/if_muge.c
==============================================================================
--- head/sys/dev/usb/net/if_muge.c	Mon May 20 22:21:42 2019	(r348017)
+++ head/sys/dev/usb/net/if_muge.c	Mon May 20 22:21:47 2019	(r348018)
@@ -1484,36 +1484,36 @@ muge_set_mac_addr(struct usb_ether *ue)
 		ue->ue_eaddr[0] = (uint8_t)((mac_l) & 0xff);
 	}
 
-	/* If RX_ADDRx did not provide a valid MAC address, try EEPROM. */
+	/*
+	 * If RX_ADDRx did not provide a valid MAC address, try EEPROM.  If that
+	 * doesn't work, try OTP.  Whether any of these methods work or not, try
+	 * FDT data, because it is allowed to override the EEPROM/OTP values.
+	 */
 	if (ETHER_IS_VALID(ue->ue_eaddr)) {
 		muge_dbg_printf(sc, "MAC assigned from registers\n");
-		return;
+	} else if (lan78xx_eeprom_present(sc) && lan78xx_eeprom_read_raw(sc,
+	    ETH_E2P_MAC_OFFSET, ue->ue_eaddr, ETHER_ADDR_LEN) == 0 &&
+	    ETHER_IS_VALID(ue->ue_eaddr)) {
+		muge_dbg_printf(sc, "MAC assigned from EEPROM\n");
+	} else if (lan78xx_otp_read(sc, OTP_MAC_OFFSET, ue->ue_eaddr,
+	    ETHER_ADDR_LEN) == 0 && ETHER_IS_VALID(ue->ue_eaddr)) {
+		muge_dbg_printf(sc, "MAC assigned from OTP\n");
 	}
 
-	if ((lan78xx_eeprom_present(sc) &&
-	    lan78xx_eeprom_read_raw(sc, ETH_E2P_MAC_OFFSET,
-	    ue->ue_eaddr, ETHER_ADDR_LEN) == 0) ||
-	    (lan78xx_otp_read(sc, OTP_MAC_OFFSET,
-	    ue->ue_eaddr, ETHER_ADDR_LEN) == 0)) {
-		if (ETHER_IS_VALID(ue->ue_eaddr)) {
-			muge_dbg_printf(sc, "MAC read from EEPROM\n");
-			return;
-		}
-	}
-
 #ifdef FDT
 	/* ue->ue_eaddr modified only if config exists for this dev instance. */
 	usb_fdt_get_mac_addr(ue->ue_dev, ue);
 	if (ETHER_IS_VALID(ue->ue_eaddr)) {
-		muge_dbg_printf(sc, "MAC read from FDT data\n");
-		return;
+		muge_dbg_printf(sc, "MAC assigned from FDT data\n");
 	}
 #endif
 
-	muge_dbg_printf(sc, "MAC assigned randomly\n");
-	arc4rand(ue->ue_eaddr, ETHER_ADDR_LEN, 0);
-	ue->ue_eaddr[0] &= ~0x01;	/* unicast */
-	ue->ue_eaddr[0] |= 0x02;	/* locally administered */
+	if (!ETHER_IS_VALID(ue->ue_eaddr)) {
+		muge_dbg_printf(sc, "MAC assigned randomly\n");
+		arc4rand(ue->ue_eaddr, ETHER_ADDR_LEN, 0);
+		ue->ue_eaddr[0] &= ~0x01;	/* unicast */
+		ue->ue_eaddr[0] |= 0x02;	/* locally administered */
+	}
 }
 
 /**



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201905202221.x4KMLlYe013204>