Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 18 Jan 2009 12:28:45 +0000 (UTC)
From:      Stanislav Sedov <stas@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-7@freebsd.org
Subject:   svn commit: r187391 - in stable/7/sys: . arm/at91 contrib/pf dev/ath/ath_hal dev/cxgb
Message-ID:  <200901181228.n0ICSjnT073457@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: stas
Date: Sun Jan 18 12:28:45 2009
New Revision: 187391
URL: http://svn.freebsd.org/changeset/base/187391

Log:
  - Merge r182477:
    Try to look for MAC address in all SA registers, not only in the
    first one. U-boot, for example, uses the second register to store
    MAC.[1]
    Use random MAC address if none configured instead of failing.
  
  Submitted by:	Bjorn Konig <bkoenig@alpha-tierchen.de> [1]

Modified:
  stable/7/sys/   (props changed)
  stable/7/sys/arm/at91/if_ate.c
  stable/7/sys/contrib/pf/   (props changed)
  stable/7/sys/dev/ath/ath_hal/   (props changed)
  stable/7/sys/dev/cxgb/   (props changed)

Modified: stable/7/sys/arm/at91/if_ate.c
==============================================================================
--- stable/7/sys/arm/at91/if_ate.c	Sun Jan 18 12:16:45 2009	(r187390)
+++ stable/7/sys/arm/at91/if_ate.c	Sun Jan 18 12:28:45 2009	(r187391)
@@ -170,7 +170,8 @@ ate_attach(device_t dev)
 	struct sysctl_ctx_list *sctx;
 	struct sysctl_oid *soid;
 	int err;
-	u_char eaddr[6];
+	u_char eaddr[ETHER_ADDR_LEN];
+	uint32_t rnd;
 
 	sc->dev = dev;
 	err = ate_activate(dev);
@@ -191,8 +192,23 @@ ate_attach(device_t dev)
 	callout_init_mtx(&sc->tick_ch, &sc->sc_mtx, 0);
 
 	if ((err = ate_get_mac(sc, eaddr)) != 0) {
-		device_printf(dev, "No MAC address set\n");
-		goto out;
+		/*
+		 * No MAC address configured. Generate the fake one.
+		 */
+		if  (bootverbose)
+			device_printf(dev,
+			    "Generating fake ethernet address.\n");
+		rnd = arc4random();
+
+		/*
+		 * Set OUI to Atmel.
+		 */
+		eaddr[0] = 0x00;
+		eaddr[1] = 0x04;
+		eaddr[2] = 0x25;
+		eaddr[3] = (rnd >> 16) & 0xff;
+		eaddr[4] = (rnd >> 8) & 0xff;
+		eaddr[5] = rnd & 0xff;
 	}
 	ate_set_mac(sc, eaddr);
 
@@ -586,24 +602,29 @@ ate_set_mac(struct ate_softc *sc, u_char
 static int
 ate_get_mac(struct ate_softc *sc, u_char *eaddr)
 {
+	bus_size_t sa_low_reg[] = { ETH_SA1L, ETH_SA2L, ETH_SA3L, ETH_SA4L };
+	bus_size_t sa_high_reg[] = { ETH_SA1H, ETH_SA2H, ETH_SA3H, ETH_SA4H };
 	uint32_t low, high;
+	int i;
 
 	/*
 	 * The boot loader setup the MAC with an address, if one is set in
-	 * the loader.  The TSC loader will also set the MAC address in a
-	 * similar way.  Grab the MAC address from the SA1[HL] registers.
+	 * the loader. Grab one MAC address from the SA[1-4][HL] registers.
 	 */
-	low = RD4(sc, ETH_SA1L);
-	high =  RD4(sc, ETH_SA1H);
-	if ((low | (high & 0xffff)) == 0)
-		return (ENXIO);
-	eaddr[0] = low & 0xff;
-	eaddr[1] = (low >> 8) & 0xff;
-	eaddr[2] = (low >> 16) & 0xff;
-	eaddr[3] = (low >> 24) & 0xff;
-	eaddr[4] = high & 0xff;
-	eaddr[5] = (high >> 8) & 0xff;
-	return (0);
+	for (i = 0; i < 4; i++) {
+		low = RD4(sc, sa_low_reg[i]);
+		high = RD4(sc, sa_high_reg[i]);
+		if ((low | (high & 0xffff)) != 0) {
+			eaddr[0] = low & 0xff;
+			eaddr[1] = (low >> 8) & 0xff;
+			eaddr[2] = (low >> 16) & 0xff;
+			eaddr[3] = (low >> 24) & 0xff;
+			eaddr[4] = high & 0xff;
+			eaddr[5] = (high >> 8) & 0xff;
+			return (0);
+		}
+	}
+	return (ENXIO);
 }
 
 static void



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