Lines 179-184
static const struct usb_device_id smsc_devs[] = {
Link Here
|
179 |
#define ETHER_IS_VALID(addr) \ |
179 |
#define ETHER_IS_VALID(addr) \ |
180 |
(!ETHER_IS_MULTICAST(addr) && !ETHER_IS_ZERO(addr)) |
180 |
(!ETHER_IS_MULTICAST(addr) && !ETHER_IS_ZERO(addr)) |
181 |
|
181 |
|
|
|
182 |
#define BOOTARGS_SMSC95XX "smsc95xx.macaddr" |
183 |
|
182 |
static device_probe_t smsc_probe; |
184 |
static device_probe_t smsc_probe; |
183 |
static device_attach_t smsc_attach; |
185 |
static device_attach_t smsc_attach; |
184 |
static device_detach_t smsc_detach; |
186 |
static device_detach_t smsc_detach; |
Lines 1538-1543
smsc_ioctl(if_t ifp, u_long cmd, caddr_t data)
Link Here
|
1538 |
return (rc); |
1540 |
return (rc); |
1539 |
} |
1541 |
} |
1540 |
|
1542 |
|
|
|
1543 |
static bool |
1544 |
smsc_get_smsc95xx_macaddr(char* bootargs, size_t bootargs_len, struct usb_ether *ue) |
1545 |
{ |
1546 |
int values[6]; |
1547 |
int i; |
1548 |
char* p; |
1549 |
|
1550 |
p = strnstr(bootargs, BOOTARGS_SMSC95XX, bootargs_len); |
1551 |
|
1552 |
if (6 != sscanf(p, BOOTARGS_SMSC95XX "=%x:%x:%x:%x:%x:%x%*c", |
1553 |
&values[0], &values[1], &values[2], |
1554 |
&values[3], &values[4], &values[5])) { |
1555 |
smsc_err_printf((struct smsc_softc *)ue->ue_sc, "invalid mac from bootargs '%s'.\n", p); |
1556 |
return false; |
1557 |
} |
1558 |
|
1559 |
for (i = 0; i < ETHER_ADDR_LEN; ++i) |
1560 |
ue->ue_eaddr[i] = values[i]; |
1561 |
|
1562 |
smsc_dbg_printf((struct smsc_softc *)ue->ue_sc, "bootargs mac=%x:%x:%x:%x:%x:%x.\n", |
1563 |
ue->ue_eaddr[0], ue->ue_eaddr[1], ue->ue_eaddr[2], |
1564 |
ue->ue_eaddr[3], ue->ue_eaddr[4], ue->ue_eaddr[5]); |
1565 |
return true; |
1566 |
} |
1567 |
|
1568 |
#ifdef FDT |
1569 |
/** |
1570 |
* Raspberry Pi is known to pass smsc95xx.macaddr=XX:XX:XX:XX:XX:XX via bootargs. |
1571 |
*/ |
1572 |
static int |
1573 |
smsc_bootargs_get_mac_addr(device_t dev, struct usb_ether *ue) { |
1574 |
char bootargs[2048]; /* early stack supposedly big enough */ |
1575 |
phandle_t node; |
1576 |
|
1577 |
/* only use bootargs for the first device to prevent duplicate mac addresses */ |
1578 |
if (device_get_unit(dev) != 0) |
1579 |
return 1; |
1580 |
node = OF_finddevice("/chosen"); |
1581 |
if (node == -1) |
1582 |
return 1; |
1583 |
if (OF_getproplen(node, "bootargs") > sizeof(bootargs)) { |
1584 |
smsc_err_printf((struct smsc_softc *)ue->ue_sc, "bootargs too large (%lu) for buffer", OF_getproplen(node, "bootargs")); |
1585 |
return 1; |
1586 |
} |
1587 |
if (OF_getprop(node, "bootargs", bootargs, sizeof(bootargs)) == -1) |
1588 |
return 1; |
1589 |
smsc_dbg_printf((struct smsc_softc *)ue->ue_sc, "bootargs: %s.\n", bootargs); |
1590 |
if (!smsc_get_smsc95xx_macaddr(bootargs, sizeof(bootargs), ue)) |
1591 |
return 1; |
1592 |
device_printf(dev, "Ethernet address found in bootargs %x:%x:%x:%x:%x:%x.\n", |
1593 |
ue->ue_eaddr[0], ue->ue_eaddr[1], ue->ue_eaddr[2], |
1594 |
ue->ue_eaddr[3], ue->ue_eaddr[4], ue->ue_eaddr[5]); |
1595 |
return 0; |
1596 |
} |
1597 |
#endif |
1598 |
|
1541 |
/** |
1599 |
/** |
1542 |
* smsc_attach_post - Called after the driver attached to the USB interface |
1600 |
* smsc_attach_post - Called after the driver attached to the USB interface |
1543 |
* @ue: the USB ethernet device |
1601 |
* @ue: the USB ethernet device |
Lines 1552-1559
static void
Link Here
|
1552 |
smsc_attach_post(struct usb_ether *ue) |
1610 |
smsc_attach_post(struct usb_ether *ue) |
1553 |
{ |
1611 |
{ |
1554 |
struct smsc_softc *sc = uether_getsc(ue); |
1612 |
struct smsc_softc *sc = uether_getsc(ue); |
|
|
1613 |
struct ether_addr eaddr; |
1555 |
uint32_t mac_h, mac_l; |
1614 |
uint32_t mac_h, mac_l; |
1556 |
int err; |
1615 |
int err; |
|
|
1616 |
int i; |
1557 |
|
1617 |
|
1558 |
smsc_dbg_printf(sc, "smsc_attach_post\n"); |
1618 |
smsc_dbg_printf(sc, "smsc_attach_post\n"); |
1559 |
|
1619 |
|
Lines 1585-1595
smsc_attach_post(struct usb_ether *ue)
Link Here
|
1585 |
#ifdef FDT |
1645 |
#ifdef FDT |
1586 |
if ((err != 0) || (!ETHER_IS_VALID(sc->sc_ue.ue_eaddr))) |
1646 |
if ((err != 0) || (!ETHER_IS_VALID(sc->sc_ue.ue_eaddr))) |
1587 |
err = usb_fdt_get_mac_addr(sc->sc_ue.ue_dev, &sc->sc_ue); |
1647 |
err = usb_fdt_get_mac_addr(sc->sc_ue.ue_dev, &sc->sc_ue); |
|
|
1648 |
if ((err != 0) || (!ETHER_IS_VALID(sc->sc_ue.ue_eaddr))) |
1649 |
err = smsc_bootargs_get_mac_addr(sc->sc_ue.ue_dev, &sc->sc_ue); |
1588 |
#endif |
1650 |
#endif |
1589 |
if ((err != 0) || (!ETHER_IS_VALID(sc->sc_ue.ue_eaddr))) { |
1651 |
if ((err != 0) || (!ETHER_IS_VALID(sc->sc_ue.ue_eaddr))) { |
1590 |
read_random(sc->sc_ue.ue_eaddr, ETHER_ADDR_LEN); |
1652 |
smsc_dbg_printf(sc, "No MAC address found. Using ether_gen_addr().\n"); |
1591 |
sc->sc_ue.ue_eaddr[0] &= ~0x01; /* unicast */ |
1653 |
ether_gen_addr_bydev(ue->ue_dev, &eaddr); |
1592 |
sc->sc_ue.ue_eaddr[0] |= 0x02; /* locally administered */ |
1654 |
for (i = 0; i < ETHER_ADDR_LEN; i++) |
|
|
1655 |
sc->sc_ue.ue_eaddr[i] = eaddr.octet[i]; |
1593 |
} |
1656 |
} |
1594 |
} |
1657 |
} |
1595 |
|
1658 |
|