Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev/ic Try to use the existing HW address programmed int...



details:   https://anonhg.NetBSD.org/src/rev/959e86c9cd86
branches:  trunk
changeset: 746354:959e86c9cd86
user:      jmcneill <jmcneill%NetBSD.org@localhost>
date:      Sun Mar 29 13:20:04 2020 +0000

description:
Try to use the existing HW address programmed into the device if possible.

diffstat:

 sys/dev/ic/bcmgenet.c |  40 +++++++++++++++++++++++++---------------
 1 files changed, 25 insertions(+), 15 deletions(-)

diffs (70 lines):

diff -r 5058191decb6 -r 959e86c9cd86 sys/dev/ic/bcmgenet.c
--- a/sys/dev/ic/bcmgenet.c     Sun Mar 29 13:04:15 2020 +0000
+++ b/sys/dev/ic/bcmgenet.c     Sun Mar 29 13:20:04 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: bcmgenet.c,v 1.4 2020/03/29 13:04:15 jmcneill Exp $ */
+/* $NetBSD: bcmgenet.c,v 1.5 2020/03/29 13:20:04 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2020 Jared McNeill <jmcneill%invisible.ca@localhost>
@@ -34,7 +34,7 @@
 #include "opt_ddb.h"
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: bcmgenet.c,v 1.4 2020/03/29 13:04:15 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: bcmgenet.c,v 1.5 2020/03/29 13:20:04 jmcneill Exp $");
 
 #include <sys/param.h>
 #include <sys/bus.h>
@@ -823,28 +823,38 @@
 genet_get_eaddr(struct genet_softc *sc, uint8_t *eaddr)
 {
        prop_dictionary_t prop = device_properties(sc->sc_dev);
-       uint32_t maclo, machi;
+       uint32_t maclo, machi, val;
        prop_data_t eaprop;
 
        eaprop = prop_dictionary_get(prop, "mac-address");
-       if (eaprop == NULL) {
-               /* Create one */
-               maclo = 0x00f2 | (cprng_strong32() & 0xffff0000);
-               machi = cprng_strong32() & 0xffff;
-
-               eaddr[0] = maclo & 0xff;
-               eaddr[1] = (maclo >> 8) & 0xff;
-               eaddr[2] = (maclo >> 16) & 0xff;
-               eaddr[3] = (maclo >> 24) & 0xff;
-               eaddr[4] = machi & 0xff;
-               eaddr[5] = (machi >> 8) & 0xff;
-       } else {
+       if (eaprop != NULL) {
                KASSERT(prop_object_type(eaprop) == PROP_TYPE_DATA);
                KASSERT(prop_data_size(eaprop) == ETHER_ADDR_LEN);
                memcpy(eaddr, prop_data_data_nocopy(eaprop),
                    ETHER_ADDR_LEN);
+               return;
+       }
+
+       maclo = machi = 0;
+
+       val = RD4(sc, GENET_SYS_RBUF_FLUSH_CTRL);
+       if ((val & GENET_SYS_RBUF_FLUSH_RESET) == 0) {
+               maclo = htobe32(RD4(sc, GENET_UMAC_MAC0));
+               machi = htobe16(RD4(sc, GENET_UMAC_MAC1) & 0xffff);
        }
 
+       if (maclo == 0 && machi == 0) {
+               /* Create one */
+               maclo = 0x00f2 | (cprng_strong32() & 0xffff0000);
+               machi = cprng_strong32() & 0xffff;
+       }
+
+       eaddr[0] = maclo & 0xff;
+       eaddr[1] = (maclo >> 8) & 0xff;
+       eaddr[2] = (maclo >> 16) & 0xff;
+       eaddr[3] = (maclo >> 24) & 0xff;
+       eaddr[4] = machi & 0xff;
+       eaddr[5] = (machi >> 8) & 0xff;
 }
 
 static int



Home | Main Index | Thread Index | Old Index