Date: Tue, 9 Apr 2019 13:54:09 +0000 (UTC) From: Ganbold Tsagaankhuu <ganbold@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r346052 - head/sys/dev/usb/net Message-ID: <201904091354.x39Ds9e6070857@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: ganbold Date: Tue Apr 9 13:54:08 2019 New Revision: 346052 URL: https://svnweb.freebsd.org/changeset/base/346052 Log: In some cases like NanoPI R1, its second USB ethernet RTL8152 (chip version URE_CHIP_VER_4C10) doesn't have hardwired MAC address, in other words, it is all zeros. This commit fixes it by setting random MAC address when MAC address is all zeros. Reviewed by: kevlo Differential Revision: https://reviews.freebsd.org/D19856 Modified: head/sys/dev/usb/net/if_ure.c Modified: head/sys/dev/usb/net/if_ure.c ============================================================================== --- head/sys/dev/usb/net/if_ure.c Tue Apr 9 12:28:12 2019 (r346051) +++ head/sys/dev/usb/net/if_ure.c Tue Apr 9 13:54:08 2019 (r346052) @@ -62,6 +62,9 @@ SYSCTL_INT(_hw_usb_ure, OID_AUTO, debug, CTLFLAG_RWTUN "Debug level"); #endif +#define ETHER_IS_ZERO(addr) \ + (!(addr[0] | addr[1] | addr[2] | addr[3] | addr[4] | addr[5])) + /* * Various supported device vendors/products. */ @@ -673,12 +676,20 @@ ure_attach_post(struct usb_ether *ue) else ure_rtl8153_init(sc); - if (sc->sc_chip & URE_CHIP_VER_4C00) + if ((sc->sc_chip & URE_CHIP_VER_4C00) || + (sc->sc_chip & URE_CHIP_VER_4C10)) ure_read_mem(sc, URE_PLA_IDR, URE_MCU_TYPE_PLA, ue->ue_eaddr, 8); else ure_read_mem(sc, URE_PLA_BACKUP, URE_MCU_TYPE_PLA, ue->ue_eaddr, 8); + + if (ETHER_IS_ZERO(sc->sc_ue.ue_eaddr)) { + device_printf(sc->sc_ue.ue_dev, "MAC assigned randomly\n"); + arc4rand(sc->sc_ue.ue_eaddr, ETHER_ADDR_LEN, 0); + sc->sc_ue.ue_eaddr[0] &= ~0x01; /* unicast */ + sc->sc_ue.ue_eaddr[0] |= 0x02; /* locally administered */ + } } static int @@ -724,8 +735,10 @@ ure_init(struct usb_ether *ue) ure_reset(sc); /* Set MAC address. */ + ure_write_1(sc, URE_PLA_CRWECR, URE_MCU_TYPE_PLA, URE_CRWECR_CONFIG); ure_write_mem(sc, URE_PLA_IDR, URE_MCU_TYPE_PLA | URE_BYTE_EN_SIX_BYTES, IF_LLADDR(ifp), 8); + ure_write_1(sc, URE_PLA_CRWECR, URE_MCU_TYPE_PLA, URE_CRWECR_NORAML); /* Reset the packet filter. */ ure_write_2(sc, URE_PLA_FMC, URE_MCU_TYPE_PLA,
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201904091354.x39Ds9e6070857>