Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys Simplify device property handling by moving it into the ...
details: https://anonhg.NetBSD.org/src/rev/01f0eb27c06a
branches: trunk
changeset: 332203:01f0eb27c06a
user: martin <martin%NetBSD.org@localhost>
date: Thu Sep 11 06:56:05 2014 +0000
description:
Simplify device property handling by moving it into the core driver.
Overriding the MAC address now works again.
diffstat:
sys/arch/arm/allwinner/awin_gige.c | 16 ++--------------
sys/dev/ic/dwc_gmac.c | 30 ++++++++++++++++++++----------
sys/dev/ic/dwc_gmac_var.h | 2 +-
3 files changed, 23 insertions(+), 25 deletions(-)
diffs (131 lines):
diff -r 26329c067eb7 -r 01f0eb27c06a sys/arch/arm/allwinner/awin_gige.c
--- a/sys/arch/arm/allwinner/awin_gige.c Thu Sep 11 04:05:52 2014 +0000
+++ b/sys/arch/arm/allwinner/awin_gige.c Thu Sep 11 06:56:05 2014 +0000
@@ -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 @@
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 @@
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_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)
{
diff -r 26329c067eb7 -r 01f0eb27c06a sys/dev/ic/dwc_gmac.c
--- a/sys/dev/ic/dwc_gmac.c Thu Sep 11 04:05:52 2014 +0000
+++ b/sys/dev/ic/dwc_gmac.c Thu Sep 11 06:56:05 2014 +0000
@@ -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 @@
#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 @@
enaddr[3] = (maclo >> 24) & 0x0ff;
enaddr[4] = machi & 0x0ff;
enaddr[5] = (machi >> 8) & 0x0ff;
- ep = enaddr;
}
/*
@@ -124,7 +134,7 @@
*/
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));
diff -r 26329c067eb7 -r 01f0eb27c06a sys/dev/ic/dwc_gmac_var.h
--- a/sys/dev/ic/dwc_gmac_var.h Thu Sep 11 04:05:52 2014 +0000
+++ b/sys/dev/ic/dwc_gmac_var.h Thu Sep 11 06:56:05 2014 +0000
@@ -87,5 +87,5 @@
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*);
Home |
Main Index |
Thread Index |
Old Index