summaryrefslogtreecommitdiffstats
path: root/src/udev/udev-builtin-net_id.c
diff options
context:
space:
mode:
authorDimitri John Ledkov <xnox@ubuntu.com>2017-05-17 15:28:35 +0200
committerLennart Poettering <lennart@poettering.net>2017-05-17 15:28:35 +0200
commitc20e6de897b2378bc3f936e1e265d2d2e2450a73 (patch)
tree36c27cbaff7c3269140fad57f0d6e5b2ca70154c /src/udev/udev-builtin-net_id.c
parentcalendarspec: parse unix timestamps (@...) (#5947) (diff)
downloadsystemd-c20e6de897b2378bc3f936e1e265d2d2e2450a73.tar.xz
systemd-c20e6de897b2378bc3f936e1e265d2d2e2450a73.zip
udev: net_id add support for platform bus (ACPI, mostly arm64) devices (#5933)
Fixes: #5894
Diffstat (limited to 'src/udev/udev-builtin-net_id.c')
-rw-r--r--src/udev/udev-builtin-net_id.c63
1 files changed, 63 insertions, 0 deletions
diff --git a/src/udev/udev-builtin-net_id.c b/src/udev/udev-builtin-net_id.c
index dcbfba359f..f385fe9565 100644
--- a/src/udev/udev-builtin-net_id.c
+++ b/src/udev/udev-builtin-net_id.c
@@ -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)