View | Details | Raw Unified | Return to bug 274092 | Differences between
and this patch

Collapse All | Expand All

(-)b/sys/dev/usb/net/if_smsc.c (-3 / +66 lines)
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
#ifdef FDT
1544
static bool
1545
smsc_get_smsc95xx_macaddr(char* bootargs, size_t bootargs_len, struct usb_ether *ue)
1546
{
1547
	int values[6];
1548
	int i;
1549
	char* p;
1550
1551
	p = strnstr(bootargs, BOOTARGS_SMSC95XX, bootargs_len);
1552
1553
	if (p == NULL || 6 != sscanf(p, BOOTARGS_SMSC95XX "=%x:%x:%x:%x:%x:%x%*c",
1554
			&values[0], &values[1], &values[2],
1555
			&values[3], &values[4], &values[5])) {
1556
		smsc_err_printf((struct smsc_softc *)ue->ue_sc, "invalid mac from bootargs '%s'.\n", p);
1557
		return false;
1558
	}
1559
1560
	for (i = 0; i < ETHER_ADDR_LEN; ++i)
1561
		ue->ue_eaddr[i] = values[i];
1562
1563
	smsc_dbg_printf((struct smsc_softc *)ue->ue_sc, "bootargs mac=%x:%x:%x:%x:%x:%x.\n",
1564
		ue->ue_eaddr[0], ue->ue_eaddr[1], ue->ue_eaddr[2],
1565
		ue->ue_eaddr[3], ue->ue_eaddr[4], ue->ue_eaddr[5]);
1566
	return true;
1567
}
1568
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_byname(device_get_nameunit(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
(-)b/sys/net/ethernet.h (+1 lines)
Lines 448-453 struct mbuf *ether_vlanencap_proto(struct mbuf *, uint16_t, uint16_t); Link Here
448
bool	ether_8021q_frame(struct mbuf **mp, struct ifnet *ife,
448
bool	ether_8021q_frame(struct mbuf **mp, struct ifnet *ife,
449
		struct ifnet *p, const struct ether_8021q_tag *);
449
		struct ifnet *p, const struct ether_8021q_tag *);
450
void	ether_gen_addr(struct ifnet *ifp, struct ether_addr *hwaddr);
450
void	ether_gen_addr(struct ifnet *ifp, struct ether_addr *hwaddr);
451
void	ether_gen_addr_byname(const char *nameunit, struct ether_addr *hwaddr);
451
452
452
static __inline struct mbuf *ether_vlanencap(struct mbuf *m, uint16_t tag)
453
static __inline struct mbuf *ether_vlanencap(struct mbuf *m, uint16_t tag)
453
{
454
{
(-)b/sys/net/if_ethersubr.c (-2 / +7 lines)
Lines 1489-1495 ether_8021q_frame(struct mbuf **mp, struct ifnet *ife, struct ifnet *p, Link Here
1489
 * allocate non-locally-administered addresses.
1489
 * allocate non-locally-administered addresses.
1490
 */
1490
 */
1491
void
1491
void
1492
ether_gen_addr(struct ifnet *ifp, struct ether_addr *hwaddr)
1492
ether_gen_addr_byname(const char *nameunit, struct ether_addr *hwaddr)
1493
{
1493
{
1494
	SHA1_CTX ctx;
1494
	SHA1_CTX ctx;
1495
	char *buf;
1495
	char *buf;
Lines 1508-1514 ether_gen_addr(struct ifnet *ifp, struct ether_addr *hwaddr) Link Here
1508
	/* If each (vnet) jail would also have a unique hostuuid this would not
1508
	/* If each (vnet) jail would also have a unique hostuuid this would not
1509
	 * be necessary. */
1509
	 * be necessary. */
1510
	getjailname(curthread->td_ucred, jailname, sizeof(jailname));
1510
	getjailname(curthread->td_ucred, jailname, sizeof(jailname));
1511
	sz = asprintf(&buf, M_TEMP, "%s-%s-%s", uuid, if_name(ifp),
1511
	sz = asprintf(&buf, M_TEMP, "%s-%s-%s", uuid, nameunit,
1512
	    jailname);
1512
	    jailname);
1513
	if (sz < 0) {
1513
	if (sz < 0) {
1514
		/* Fall back to a random mac address. */
1514
		/* Fall back to a random mac address. */
Lines 1537-1541 ether_gen_addr(struct ifnet *ifp, struct ether_addr *hwaddr) Link Here
1537
	hwaddr->octet[0] |= 0x02;
1537
	hwaddr->octet[0] |= 0x02;
1538
}
1538
}
1539
1539
1540
void
1541
ether_gen_addr(struct ifnet *ifp, struct ether_addr *hwaddr) {
1542
	ether_gen_addr_byname(if_name(ifp), hwaddr);
1543
}
1544
1540
DECLARE_MODULE(ether, ether_mod, SI_SUB_INIT_IF, SI_ORDER_ANY);
1545
DECLARE_MODULE(ether, ether_mod, SI_SUB_INIT_IF, SI_ORDER_ANY);
1541
MODULE_VERSION(ether, 1);
1546
MODULE_VERSION(ether, 1);

Return to bug 274092