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
This commit is contained in:
parent
e92a9a8c52
commit
cef38d45bb
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=346052
@ -62,6 +62,9 @@ SYSCTL_INT(_hw_usb_ure, OID_AUTO, debug, CTLFLAG_RWTUN, &ure_debug, 0,
|
|||||||
"Debug level");
|
"Debug level");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define ETHER_IS_ZERO(addr) \
|
||||||
|
(!(addr[0] | addr[1] | addr[2] | addr[3] | addr[4] | addr[5]))
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Various supported device vendors/products.
|
* Various supported device vendors/products.
|
||||||
*/
|
*/
|
||||||
@ -673,12 +676,20 @@ ure_attach_post(struct usb_ether *ue)
|
|||||||
else
|
else
|
||||||
ure_rtl8153_init(sc);
|
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,
|
ure_read_mem(sc, URE_PLA_IDR, URE_MCU_TYPE_PLA,
|
||||||
ue->ue_eaddr, 8);
|
ue->ue_eaddr, 8);
|
||||||
else
|
else
|
||||||
ure_read_mem(sc, URE_PLA_BACKUP, URE_MCU_TYPE_PLA,
|
ure_read_mem(sc, URE_PLA_BACKUP, URE_MCU_TYPE_PLA,
|
||||||
ue->ue_eaddr, 8);
|
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
|
static int
|
||||||
@ -724,8 +735,10 @@ ure_init(struct usb_ether *ue)
|
|||||||
ure_reset(sc);
|
ure_reset(sc);
|
||||||
|
|
||||||
/* Set MAC address. */
|
/* 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,
|
ure_write_mem(sc, URE_PLA_IDR, URE_MCU_TYPE_PLA | URE_BYTE_EN_SIX_BYTES,
|
||||||
IF_LLADDR(ifp), 8);
|
IF_LLADDR(ifp), 8);
|
||||||
|
ure_write_1(sc, URE_PLA_CRWECR, URE_MCU_TYPE_PLA, URE_CRWECR_NORAML);
|
||||||
|
|
||||||
/* Reset the packet filter. */
|
/* Reset the packet filter. */
|
||||||
ure_write_2(sc, URE_PLA_FMC, URE_MCU_TYPE_PLA,
|
ure_write_2(sc, URE_PLA_FMC, URE_MCU_TYPE_PLA,
|
||||||
|
Loading…
Reference in New Issue
Block a user