Source-Changes-HG archive

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

[src/netbsd-9]: src/sys/dev/usb Pull up following revision(s) (requested by b...



details:   https://anonhg.NetBSD.org/src/rev/4bd05a197ce5
branches:  netbsd-9
changeset: 843395:4bd05a197ce5
user:      martin <martin%NetBSD.org@localhost>
date:      Thu Oct 17 18:53:25 2019 +0000

description:
Pull up following revision(s) (requested by bad in ticket #343):

        sys/dev/usb/if_ure.c: revision 1.32
        sys/dev/usb/if_ure.c: revision 1.33

read mac address of ure version 4c10 from URE_PLA_IDR, save as 4c00.
from ganbold@freebsd r346052.
XXX pullup-9

 -

allocate a random mac address if on-chip mac is all zeroes.
helps ure(4) on NanoPi R1.
partly from ganbold@freebsd r346052.
XXX pullup-9

diffstat:

 sys/dev/usb/if_ure.c |  22 +++++++++++++++++++---
 1 files changed, 19 insertions(+), 3 deletions(-)

diffs (70 lines):

diff -r 0d794f57bfce -r 4bd05a197ce5 sys/dev/usb/if_ure.c
--- a/sys/dev/usb/if_ure.c      Thu Oct 17 18:48:55 2019 +0000
+++ b/sys/dev/usb/if_ure.c      Thu Oct 17 18:53:25 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_ure.c,v 1.14.2.1 2019/09/01 13:00:36 martin Exp $   */
+/*     $NetBSD: if_ure.c,v 1.14.2.2 2019/10/17 18:53:25 martin Exp $   */
 /*     $OpenBSD: if_ure.c,v 1.10 2018/11/02 21:32:30 jcs Exp $ */
 
 /*-
@@ -30,7 +30,7 @@
 /* RealTek RTL8152/RTL8153 10/100/Gigabit USB Ethernet device */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_ure.c,v 1.14.2.1 2019/09/01 13:00:36 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_ure.c,v 1.14.2.2 2019/10/17 18:53:25 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -38,6 +38,7 @@
 #endif
 
 #include <sys/param.h>
+#include <sys/cprng.h>
 
 #include <net/route.h>
 
@@ -66,6 +67,9 @@
 #define DPRINTFN(n, x)
 #endif
 
+#define ETHER_IS_ZERO(addr) \
+       (!(addr[0] | addr[1] | addr[2] | addr[3] | addr[4] | addr[5]))
+
 static const struct usb_devno ure_devs[] = {
        { USB_VENDOR_REALTEK, USB_PRODUCT_REALTEK_RTL8152 },
        { USB_VENDOR_REALTEK, USB_PRODUCT_REALTEK_RTL8153 }
@@ -848,6 +852,7 @@
        uint16_t ver;
        uint8_t eaddr[8]; /* 2byte padded */
        char *devinfop;
+       uint32_t maclo, machi;
 
        aprint_naive("\n");
        aprint_normal("\n");
@@ -941,13 +946,24 @@
        else
                ure_rtl8153_init(un);
 
-       if (un->un_flags & URE_FLAG_VER_4C00)
+       if ((un->un_flags & URE_FLAG_VER_4C00) ||
+           (un->un_flags & URE_FLAG_VER_4C10))
                ure_read_mem(un, URE_PLA_IDR, URE_MCU_TYPE_PLA, eaddr,
                    sizeof(eaddr));
        else
                ure_read_mem(un, URE_PLA_BACKUP, URE_MCU_TYPE_PLA, eaddr,
                    sizeof(eaddr));
        usbnet_unlock(un);
+       if (ETHER_IS_ZERO(eaddr)) {
+               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;
+       }
        memcpy(un->un_eaddr, eaddr, sizeof un->un_eaddr);
 
        struct ifnet *ifp = usbnet_ifp(un);



Home | Main Index | Thread Index | Old Index