Module Name:    src
Committed By:   martin
Date:           Thu Sep 11 06:56:05 UTC 2014

Modified Files:
        src/sys/arch/arm/allwinner: awin_gige.c
        src/sys/dev/ic: dwc_gmac.c dwc_gmac_var.h

Log Message:
Simplify device property handling by moving it into the core driver.
Overriding the MAC address now works again.


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/sys/arch/arm/allwinner/awin_gige.c
cvs rdiff -u -r1.4 -r1.5 src/sys/dev/ic/dwc_gmac.c
cvs rdiff -u -r1.2 -r1.3 src/sys/dev/ic/dwc_gmac_var.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/arm/allwinner/awin_gige.c
diff -u src/sys/arch/arm/allwinner/awin_gige.c:1.6 src/sys/arch/arm/allwinner/awin_gige.c:1.7
--- src/sys/arch/arm/allwinner/awin_gige.c:1.6	Tue Sep  9 10:03:43 2014
+++ src/sys/arch/arm/allwinner/awin_gige.c	Thu Sep 11 06:56:05 2014
@@ -31,7 +31,7 @@
 
 #include <sys/cdefs.h>
 
-__KERNEL_RCSID(1, "$NetBSD: awin_gige.c,v 1.6 2014/09/09 10:03:43 martin Exp $");
+__KERNEL_RCSID(1, "$NetBSD: awin_gige.c,v 1.7 2014/09/11 06:56:05 martin Exp $");
 
 #include <sys/param.h>
 #include <sys/bus.h>
@@ -92,11 +92,8 @@ awin_gige_attach(device_t parent, device
 	struct awin_gige_softc * const sc = device_private(self);
 	struct awinio_attach_args * const aio = aux;
 	const struct awin_locators * const loc = &aio->aio_loc;
-	prop_dictionary_t dict;
-	uint8_t enaddr[ETHER_ADDR_LEN], *ep = NULL;
 
 	sc->sc_core.sc_dev = self;
-	dict = device_properties(sc->sc_core.sc_dev);
 
 	awin_gpio_pinset_acquire(&awin_gige_gpio_pinset);
 
@@ -107,14 +104,6 @@ awin_gige_attach(device_t parent, device
 
 	aprint_naive("\n");
 	aprint_normal(": Gigabit Ethernet Controller\n");
-	
-	prop_data_t ea = dict ? prop_dictionary_get(dict, "mac-address") : NULL;
-	if (ea != NULL) {
-		KASSERT(prop_object_type(ea) == PROP_TYPE_DATA);
-		KASSERT(prop_data_size(ea) == ETHER_ADDR_LEN);
-		memcpy(enaddr, prop_data_data_nocopy(ea), ETHER_ADDR_LEN);
-		ep = enaddr;
-	}
 
 	/*
 	 * Interrupt handler
@@ -142,10 +131,9 @@ awin_gige_attach(device_t parent, device
 	awin_reg_set_clear(aio->aio_core_bst, aio->aio_ccm_bsh,
 	    AWIN_GMAC_CLK_REG, 2, 0);
 
-	dwc_gmac_attach(&sc->sc_core, ep, 2);
+	dwc_gmac_attach(&sc->sc_core, 2);
 }
 
-
 static int
 awin_gige_intr(void *arg)
 {

Index: src/sys/dev/ic/dwc_gmac.c
diff -u src/sys/dev/ic/dwc_gmac.c:1.4 src/sys/dev/ic/dwc_gmac.c:1.5
--- src/sys/dev/ic/dwc_gmac.c:1.4	Tue Sep  9 10:06:47 2014
+++ src/sys/dev/ic/dwc_gmac.c	Thu Sep 11 06:56:05 2014
@@ -39,7 +39,7 @@
 
 #include <sys/cdefs.h>
 
-__KERNEL_RCSID(1, "$NetBSD: dwc_gmac.c,v 1.4 2014/09/09 10:06:47 martin Exp $");
+__KERNEL_RCSID(1, "$NetBSD: dwc_gmac.c,v 1.5 2014/09/11 06:56:05 martin Exp $");
 
 #include "opt_inet.h"
 
@@ -92,22 +92,33 @@ static int dwc_gmac_ioctl(struct ifnet *
 #define RX_DESC_OFFSET(N)	((N)*sizeof(struct dwc_gmac_dev_dmadesc))
 
 void
-dwc_gmac_attach(struct dwc_gmac_softc *sc, uint8_t *ep, uint32_t mii_clk)
+dwc_gmac_attach(struct dwc_gmac_softc *sc, uint32_t mii_clk)
 {
 	uint8_t enaddr[ETHER_ADDR_LEN];
 	uint32_t maclo, machi;
 	struct mii_data * const mii = &sc->sc_mii;
 	struct ifnet * const ifp = &sc->sc_ec.ec_if;
+	prop_dictionary_t dict;
 
 	mutex_init(&sc->sc_mdio_lock, MUTEX_DEFAULT, IPL_NET);
 	sc->sc_mii_clk = mii_clk & 7;
 
-	/*
-	 * If the frontend did not pass in a pre-configured ethernet mac
-	 * address, try to read on from the current filter setup,
-	 * before resetting the chip.
-	 */
-	if (ep == NULL) {
+	dict = device_properties(sc->sc_dev);
+	prop_data_t ea = dict ? prop_dictionary_get(dict, "mac-address") : NULL;
+	if (ea != NULL) {
+		/*
+		 * If the MAC address is overriden by a device property,
+		 * use that.
+		 */
+		KASSERT(prop_object_type(ea) == PROP_TYPE_DATA);
+		KASSERT(prop_data_size(ea) == ETHER_ADDR_LEN);
+		memcpy(enaddr, prop_data_data_nocopy(ea), ETHER_ADDR_LEN);
+	} else {
+		/*
+		 * If we did not get an externaly configure address,
+		 * try to read one from the current filter setup,
+		 * before resetting the chip.
+		 */
 		maclo = bus_space_read_4(sc->sc_bst, sc->sc_bsh, AWIN_GMAC_MAC_ADDR0LO);
 		machi = bus_space_read_4(sc->sc_bst, sc->sc_bsh, AWIN_GMAC_MAC_ADDR0HI);
 		enaddr[0] = maclo & 0x0ff;
@@ -116,7 +127,6 @@ dwc_gmac_attach(struct dwc_gmac_softc *s
 		enaddr[3] = (maclo >> 24) & 0x0ff;
 		enaddr[4] = machi & 0x0ff;
 		enaddr[5] = (machi >> 8) & 0x0ff;
-		ep = enaddr;
 	}
 
 	/*
@@ -124,7 +134,7 @@ dwc_gmac_attach(struct dwc_gmac_softc *s
 	 */
 	if (dwc_gmac_reset(sc) != 0)
 		return;	/* not much to cleanup, haven't attached yet */
-	dwc_gmac_write_hwaddr(sc, ep);
+	dwc_gmac_write_hwaddr(sc, enaddr);
 	aprint_normal_dev(sc->sc_dev, "Ethernet address: %s\n",
 	    ether_sprintf(enaddr));
 

Index: src/sys/dev/ic/dwc_gmac_var.h
diff -u src/sys/dev/ic/dwc_gmac_var.h:1.2 src/sys/dev/ic/dwc_gmac_var.h:1.3
--- src/sys/dev/ic/dwc_gmac_var.h:1.2	Tue Sep  9 10:04:19 2014
+++ src/sys/dev/ic/dwc_gmac_var.h	Thu Sep 11 06:56:05 2014
@@ -87,5 +87,5 @@ struct dwc_gmac_softc {
 	uint16_t sc_mii_clk;
 };
 
-void dwc_gmac_attach(struct dwc_gmac_softc*, uint8_t*, uint32_t);
+void dwc_gmac_attach(struct dwc_gmac_softc*, uint32_t /*mii_clk*/);
 int dwc_gmac_intr(struct dwc_gmac_softc*);

Reply via email to