From b46d8c1c707af5114eea5262a7f7a5652a23c845 Mon Sep 17 00:00:00 2001 From: Marc Kleine-Budde Date: Sun, 28 Jun 2020 21:43:34 +0200 Subject: [PATCH] udev: spi: include chip select number in ID_PATH All devices behind a SPI controller have the same udev ID_PATH property. This is a problem for predicable network names for CAN controllers. CAN controllers, in contrast to Ethernet controllers, don't have a MAC Address, so there's no way to tell two CAN controllers on the same SPI host controller apart: $ udevadm info /sys/class/net/can0 P: /devices/platform/soc/fe204000.spi/spi_master/spi0/spi0.1/net/can0 L: 0 E: DEVPATH=/devices/platform/soc/fe204000.spi/spi_master/spi0/spi0.1/net/can0 E: INTERFACE=can0 E: IFINDEX=3 E: SUBSYSTEM=net E: USEC_INITIALIZED=11187199 E: ID_PATH=platform-fe204000.spi E: ID_PATH_TAG=platform-fe204000_spi E: SYSTEMD_ALIAS=/sys/subsystem/net/devices/can0 E: TAGS=:systemd: $ udevadm info /sys/class/net/can1 P: /devices/platform/soc/fe204000.spi/spi_master/spi0/spi0.0/net/can1 L: 0 E: DEVPATH=/devices/platform/soc/fe204000.spi/spi_master/spi0/spi0.0/net/can1 E: INTERFACE=can1 E: IFINDEX=4 E: SUBSYSTEM=net E: USEC_INITIALIZED=11192211 E: ID_PATH=platform-fe204000.spi E: ID_PATH_TAG=platform-fe204000_spi E: SYSTEMD_ALIAS=/sys/subsystem/net/devices/can1 E: TAGS=:systemd: With this the chip select number is added to the ID_PATH, to make predictable network names possible. $ sudo udevadm info /sys/class/net/can0 P: /devices/platform/soc/fe204000.spi/spi_master/spi0/spi0.1/net/can0 L: 0 E: DEVPATH=/devices/platform/soc/fe204000.spi/spi_master/spi0/spi0.1/net/can0 E: INTERFACE=can0 E: IFINDEX=3 E: SUBSYSTEM=net E: USEC_INITIALIZED=11187199 E: ID_PATH=platform-fe204000.spi-cs-1 E: ID_PATH_TAG=platform-fe204000_spi-cs-1 E: SYSTEMD_ALIAS=/sys/subsystem/net/devices/can0 E: TAGS=:systemd: $ sudo udevadm info /sys/class/net/can1 P: /devices/platform/soc/fe204000.spi/spi_master/spi0/spi0.0/net/can1 L: 0 E: DEVPATH=/devices/platform/soc/fe204000.spi/spi_master/spi0/spi0.0/net/can1 E: INTERFACE=can1 E: IFINDEX=4 E: SUBSYSTEM=net E: USEC_INITIALIZED=11192211 E: ID_PATH=platform-fe204000.spi-cs-0 E: ID_PATH_TAG=platform-fe204000_spi-cs-0 E: SYSTEMD_ALIAS=/sys/subsystem/net/devices/can1 E: TAGS=:systemd: --- src/udev/udev-builtin-path_id.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/udev/udev-builtin-path_id.c b/src/udev/udev-builtin-path_id.c index 48e9500548..6c020ac0ed 100644 --- a/src/udev/udev-builtin-path_id.c +++ b/src/udev/udev-builtin-path_id.c @@ -643,6 +643,13 @@ static int builtin_path_id(sd_device *dev, int argc, char *argv[], bool test) { supported_parent = true; supported_transport = true; } + } else if (streq(subsys, "spi")) { + const char *sysnum; + + if (sd_device_get_sysnum(parent, &sysnum) >= 0 && sysnum) { + path_prepend(&path, "cs-%s", sysnum); + parent = skip_subsystem(parent, "spi"); + } } if (!parent)