Fix MAC address detection regression introduced by r324184
To accomodate all variaties of Pi DTS files floating around we look for MAC address property either in DTS node for USB ethernet (if it exists) or at predefined path ".../usb/hub/ethernet". After r324184 smsc_fdt_find_eth_node started to return node with compatibility string "usb424,ec00" as an eth node. In imported GNU dts files this node still does not have MAC address related property, and therefor following check for "mac-address" and "local-mac-address" fails. To make this logic more robust do not just search for the node but also make sure it has required property, so if node with accepted compatibility string exists but doesn't have the property we fall back to looking for hardoded path mentioned above.
This commit is contained in:
parent
12d3c1faac
commit
e96647dde8
@ -1637,6 +1637,37 @@ smsc_fdt_find_eth_node_by_path(phandle_t start)
|
||||
return (-1);
|
||||
}
|
||||
|
||||
/*
|
||||
* Look through known names that can contain mac address
|
||||
* return 0 if valid MAC address has been found
|
||||
*/
|
||||
static int
|
||||
smsc_fdt_read_mac_property(phandle_t node, unsigned char *mac)
|
||||
{
|
||||
int len;
|
||||
|
||||
/* Check if there is property */
|
||||
if ((len = OF_getproplen(node, "local-mac-address")) > 0) {
|
||||
if (len != ETHER_ADDR_LEN)
|
||||
return (EINVAL);
|
||||
|
||||
OF_getprop(node, "local-mac-address", mac,
|
||||
ETHER_ADDR_LEN);
|
||||
return (0);
|
||||
}
|
||||
|
||||
if ((len = OF_getproplen(node, "mac-address")) > 0) {
|
||||
if (len != ETHER_ADDR_LEN)
|
||||
return (EINVAL);
|
||||
|
||||
OF_getprop(node, "mac-address", mac,
|
||||
ETHER_ADDR_LEN);
|
||||
return (0);
|
||||
}
|
||||
|
||||
return (ENXIO);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get MAC address from FDT blob. Firmware or loader should fill
|
||||
* mac-address or local-mac-address property. Returns 0 if MAC address
|
||||
@ -1646,37 +1677,22 @@ static int
|
||||
smsc_fdt_find_mac(unsigned char *mac)
|
||||
{
|
||||
phandle_t node, root;
|
||||
int len;
|
||||
|
||||
root = OF_finddevice("/");
|
||||
node = smsc_fdt_find_eth_node(root);
|
||||
if (node != -1) {
|
||||
if (smsc_fdt_read_mac_property(node, mac) == 0)
|
||||
return (0);
|
||||
}
|
||||
|
||||
/*
|
||||
* If it's not FreeBSD FDT blob for RPi, try more
|
||||
* generic .../usb/hub/ethernet
|
||||
*/
|
||||
if (node == -1)
|
||||
node = smsc_fdt_find_eth_node_by_path(root);
|
||||
node = smsc_fdt_find_eth_node_by_path(root);
|
||||
|
||||
if (node != -1) {
|
||||
/* Check if there is property */
|
||||
if ((len = OF_getproplen(node, "local-mac-address")) > 0) {
|
||||
if (len != ETHER_ADDR_LEN)
|
||||
return (EINVAL);
|
||||
|
||||
OF_getprop(node, "local-mac-address", mac,
|
||||
ETHER_ADDR_LEN);
|
||||
return (0);
|
||||
}
|
||||
|
||||
if ((len = OF_getproplen(node, "mac-address")) > 0) {
|
||||
if (len != ETHER_ADDR_LEN)
|
||||
return (EINVAL);
|
||||
|
||||
OF_getprop(node, "mac-address", mac,
|
||||
ETHER_ADDR_LEN);
|
||||
return (0);
|
||||
}
|
||||
}
|
||||
if (node != -1)
|
||||
return smsc_fdt_read_mac_property(node, mac);
|
||||
|
||||
return (ENXIO);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user