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(device_t dev, char* bootargs, size_t bootargs_len, struct usb_ether *ue) |
1545 |
{ |
1546 |
int values[6]; |
1547 |
int i; |
1548 |
char* p; |
1549 |
|
1550 |
device_printf(dev, "sizeof(*bootargs)=%lu %lu\n", bootargs_len, strnlen(bootargs, bootargs_len)); |
1551 |
p = strnstr(bootargs, BOOTARGS_SMSC95XX, bootargs_len); |
1552 |
device_printf(dev, "mac1=%s. %lu\n", p, strlen(BOOTARGS_SMSC95XX)); |
1553 |
|
1554 |
if (6 != sscanf(p, BOOTARGS_SMSC95XX "=%x:%x:%x:%x:%x:%x%*c", |
1555 |
&values[0], &values[1], &values[2], |
1556 |
&values[3], &values[4], &values[5])) { |
1557 |
device_printf(dev, "invalid mac from bootargs '%s'.\n", p); |
1558 |
return false; |
1559 |
} |
1560 |
|
1561 |
for (i = 0; i < ETHER_ADDR_LEN; ++i) |
1562 |
ue->ue_eaddr[i] = values[i]; |
1563 |
|
1564 |
printf("mac=%x:%x:%x:%x:%x:%x.\n", |
1565 |
ue->ue_eaddr[0], ue->ue_eaddr[1], ue->ue_eaddr[2], |
1566 |
ue->ue_eaddr[3], ue->ue_eaddr[4], ue->ue_eaddr[5]); |
1567 |
return true; |
1568 |
} |
1569 |
|
1570 |
/** |
1571 |
* Raspberry Pi is known to pass smsc95xx.macaddr=XX:XX:XX:XX:XX:XX via bootargs. |
1572 |
*/ |
1573 |
static int |
1574 |
smsc_bootargs_get_mac_addr(device_t dev, struct usb_ether *ue) { |
1575 |
char bootargs[2048]; /* early stack supposedly big enough */ |
1576 |
phandle_t node; |
1577 |
|
1578 |
/* only use bootargs for the first device to prevent duplicate mac addresses */ |
1579 |
device_printf(dev, "unit=%d\n", device_get_unit(dev)); |
1580 |
if (device_get_unit(dev) != 0) |
1581 |
return 1; |
1582 |
node = OF_finddevice("/chosen"); |
1583 |
if (node == -1) |
1584 |
return 1; |
1585 |
device_printf(dev, "/chosen found\n"); |
1586 |
if (OF_getproplen(node, "bootargs") > sizeof(bootargs)) { |
1587 |
device_printf(dev, "bootargs too large for buffer"); |
1588 |
return 1; |
1589 |
} |
1590 |
if (OF_getprop(node, "bootargs", bootargs, sizeof(bootargs)) == -1) |
1591 |
return 1; |
1592 |
device_printf(dev, "bootargs: %s.\n", bootargs); |
1593 |
if (!smsc_get_smsc95xx_macaddr(dev, bootargs, sizeof(bootargs), ue)) |
1594 |
return 1; |
1595 |
device_printf(dev, "Ethernet address found in bootargs %x:%x:%x:%x:%x:%x.\n", |
1596 |
ue->ue_eaddr[0], ue->ue_eaddr[1], ue->ue_eaddr[2], |
1597 |
ue->ue_eaddr[3], ue->ue_eaddr[4], ue->ue_eaddr[5]); |
1598 |
return 0; |
1599 |
} |
1600 |
|
1541 |
/** |
1601 |
/** |
1542 |
* smsc_attach_post - Called after the driver attached to the USB interface |
1602 |
* smsc_attach_post - Called after the driver attached to the USB interface |
1543 |
* @ue: the USB ethernet device |
1603 |
* @ue: the USB ethernet device |
Lines 1552-1564
static void
Link Here
|
1552 |
smsc_attach_post(struct usb_ether *ue) |
1612 |
smsc_attach_post(struct usb_ether *ue) |
1553 |
{ |
1613 |
{ |
1554 |
struct smsc_softc *sc = uether_getsc(ue); |
1614 |
struct smsc_softc *sc = uether_getsc(ue); |
1555 |
uint32_t mac_h, mac_l; |
|
|
1556 |
int err; |
1557 |
|
1615 |
|
1558 |
smsc_dbg_printf(sc, "smsc_attach_post\n"); |
1616 |
smsc_dbg_printf(sc, "smsc_attach_post\n"); |
1559 |
|
1617 |
|
1560 |
/* Setup some of the basics */ |
1618 |
/* Setup some of the basics */ |
1561 |
sc->sc_phyno = 1; |
1619 |
sc->sc_phyno = 1; |
|
|
1620 |
} |
1621 |
|
1622 |
static void |
1623 |
smsc_ether_set_addr(struct usb_ether *ue) |
1624 |
{ |
1625 |
struct smsc_softc *sc = uether_getsc(ue); |
1626 |
struct ether_addr eaddr; |
1627 |
uint32_t mac_h, mac_l; |
1628 |
int err; |
1629 |
int i; |
1562 |
|
1630 |
|
1563 |
/* Attempt to get the mac address, if an EEPROM is not attached this |
1631 |
/* Attempt to get the mac address, if an EEPROM is not attached this |
1564 |
* will just return FF:FF:FF:FF:FF:FF, so in such cases we invent a MAC |
1632 |
* will just return FF:FF:FF:FF:FF:FF, so in such cases we invent a MAC |
Lines 1585-1595
smsc_attach_post(struct usb_ether *ue)
Link Here
|
1585 |
#ifdef FDT |
1653 |
#ifdef FDT |
1586 |
if ((err != 0) || (!ETHER_IS_VALID(sc->sc_ue.ue_eaddr))) |
1654 |
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); |
1655 |
err = usb_fdt_get_mac_addr(sc->sc_ue.ue_dev, &sc->sc_ue); |
|
|
1656 |
#endif |
1657 |
#if 0 |
1658 |
if ((err != 0) || (!ETHER_IS_VALID(sc->sc_ue.ue_eaddr))) { |
1659 |
err = smsc_bootargs_get_mac_addr(sc->sc_ue.ue_dev, &sc->sc_ue); |
1660 |
} |
1588 |
#endif |
1661 |
#endif |
1589 |
if ((err != 0) || (!ETHER_IS_VALID(sc->sc_ue.ue_eaddr))) { |
1662 |
if ((err != 0) || (!ETHER_IS_VALID(sc->sc_ue.ue_eaddr))) { |
1590 |
read_random(sc->sc_ue.ue_eaddr, ETHER_ADDR_LEN); |
1663 |
device_printf(ue->ue_dev, "No MAC address found. Using ether_gen_addr(). %p\n", ue->ue_ifp); |
1591 |
sc->sc_ue.ue_eaddr[0] &= ~0x01; /* unicast */ |
1664 |
ether_gen_addr(ue->ue_ifp, &eaddr); |
1592 |
sc->sc_ue.ue_eaddr[0] |= 0x02; /* locally administered */ |
1665 |
for (i = 0; i < ETHER_ADDR_LEN; i++) |
|
|
1666 |
sc->sc_ue.ue_eaddr[i] = eaddr.octet[i]; |
1593 |
} |
1667 |
} |
1594 |
} |
1668 |
} |
1595 |
|
1669 |
|
Lines 1615-1620
smsc_attach_post_sub(struct usb_ether *ue)
Link Here
|
1615 |
if_t ifp; |
1689 |
if_t ifp; |
1616 |
int error; |
1690 |
int error; |
1617 |
|
1691 |
|
|
|
1692 |
smsc_ether_set_addr(ue); |
1618 |
sc = uether_getsc(ue); |
1693 |
sc = uether_getsc(ue); |
1619 |
ifp = ue->ue_ifp; |
1694 |
ifp = ue->ue_ifp; |
1620 |
if_setflags(ifp, IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST); |
1695 |
if_setflags(ifp, IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST); |