udev: net_id add support for platform bus (ACPI, mostly arm64) devices (#5933)

Fixes: #5894
This commit is contained in:
Dimitri John Ledkov 2017-05-17 14:28:35 +01:00 committed by Lennart Poettering
parent d80e5b74e8
commit c20e6de897
1 changed files with 63 additions and 0 deletions

View File

@ -46,6 +46,7 @@
* [P<domain>]p<bus>s<slot>[f<function>][u<port>][..][c<config>][i<interface>]
* USB port number chain
* v<slot> - VIO slot number (IBM PowerVM)
* a<vendor><model>i<instance> Platform bus ACPI instance id
*
* All multi-function PCI devices will carry the [f<function>] number in the
* device name, including the function 0 device.
@ -124,6 +125,7 @@ enum netname_type{
NET_VIRTIO,
NET_CCW,
NET_VIO,
NET_PLATFORM,
};
struct netnames {
@ -142,6 +144,7 @@ struct netnames {
char bcma_core[IFNAMSIZ];
char ccw_busid[IFNAMSIZ];
char vio_slot[IFNAMSIZ];
char platform_path[IFNAMSIZ];
};
/* skip intermediate virtio devices */
@ -349,6 +352,56 @@ static int names_vio(struct udev_device *dev, struct netnames *names) {
return 0;
}
#define _PLATFORM_TEST "/sys/devices/platform/vvvvPPPP"
#define _PLATFORM_PATTERN4 "/sys/devices/platform/%4s%4x:%2x/net/eth%u"
#define _PLATFORM_PATTERN3 "/sys/devices/platform/%3s%4x:%2x/net/eth%u"
static int names_platform(struct udev_device *dev, struct netnames *names, bool test) {
struct udev_device *parent;
char vendor[5];
unsigned model, instance, ethid;
const char *syspath, *pattern, *validchars;
/* check if our direct parent is a platform device with no other bus in-between */
parent = udev_device_get_parent(dev);
if (!parent)
return -ENOENT;
if (!streq_ptr("platform", udev_device_get_subsystem(parent)))
return -ENOENT;
syspath = udev_device_get_syspath(dev);
/* syspath is too short, to have a valid ACPI instance */
if (strlen(syspath) < sizeof _PLATFORM_TEST)
return -EINVAL;
/* Vendor ID can be either PNP ID (3 chars A-Z) or ACPI ID (4 chars A-Z and numerals) */
if (syspath[sizeof _PLATFORM_TEST - 1] == ':') {
pattern = _PLATFORM_PATTERN4;
validchars = UPPERCASE_LETTERS DIGITS;
} else {
pattern = _PLATFORM_PATTERN3;
validchars = UPPERCASE_LETTERS;
}
/* Platform devices are named after ACPI table match, and instance id
* eg. "/sys/devices/platform/HISI00C2:00");
* The Vendor (3 or 4 char), followed by hexdecimal model number : instance id.
*/
if (sscanf(syspath, pattern, vendor, &model, &instance, &ethid) != 4)
return -EINVAL;
if (!in_charset(vendor, validchars))
return -ENOENT;
ascii_strlower(vendor);
xsprintf(names->platform_path, "a%s%xi%u", vendor, model, instance);
names->type = NET_PLATFORM;
return 0;
}
static int names_pci(struct udev_device *dev, struct netnames *names) {
struct udev_device *parent;
@ -631,6 +684,16 @@ static int builtin_net_id(struct udev_device *dev, int argc, char *argv[], bool
goto out;
}
/* get ACPI path names for ARM64 platform devices */
err = names_platform(dev, &names, test);
if (err >= 0 && names.type == NET_PLATFORM) {
char str[IFNAMSIZ];
if (snprintf(str, sizeof(str), "%s%s", prefix, names.platform_path) < (int)sizeof(str))
udev_builtin_add_property(dev, test, "ID_NET_NAME_PATH", str);
goto out;
}
/* get PCI based path names, we compose only PCI based paths */
err = names_pci(dev, &names);
if (err < 0)