923a60
From 192545bc67fed763ac54761ca067b9c2f93ecdd1 Mon Sep 17 00:00:00 2001
923a60
From: =?UTF-8?q?Ji=C5=99=C3=AD=20P=C3=ADrko?= <jiri@resnulli.us>
923a60
Date: Wed, 2 Nov 2016 03:46:01 +0100
923a60
Subject: [PATCH] udev: net_id: add support for phys_port_name attribute
923a60
 (#4506)
923a60
923a60
Switch drivers uses phys_port_name attribute to pass front panel port
923a60
name to user. Use it to generate netdev names.
923a60
923a60
Signed-off-by: Jiri Pirko <jiri@mellanox.com>
923a60
923a60
Cherry-picked from: 4887b656c22af059d4e833de7b56544f24951184
923a60
Resolves: #1392426
923a60
---
923a60
 src/udev/udev-builtin-net_id.c | 24 ++++++++++++++++++------
923a60
 1 file changed, 18 insertions(+), 6 deletions(-)
923a60
923a60
diff --git a/src/udev/udev-builtin-net_id.c b/src/udev/udev-builtin-net_id.c
923a60
index 19e1f2631a..7c154355dd 100644
923a60
--- a/src/udev/udev-builtin-net_id.c
923a60
+++ b/src/udev/udev-builtin-net_id.c
923a60
@@ -38,7 +38,7 @@
923a60
  *   o<index>[d<dev_port>]                 -- on-board device index number
923a60
  *   s<slot>[f<function>][d<dev_port>]     -- hotplug slot index number
923a60
  *   x<MAC>                                -- MAC address
923a60
- *   [P<domain>]p<bus>s<slot>[f<function>][d<dev_id>/<dev_port>]
923a60
+ *   [P<domain>]p<bus>s<slot>[f<function>][n<phys_port_name>|d<dev_id>/<dev_port>]
923a60
  *                                         -- PCI geographical location
923a60
  *   [P<domain>]p<bus>s<slot>[f<function>][u<port>][..][c<config>][i<interface>]
923a60
  *                                         -- USB port number chain
923a60
@@ -134,7 +134,7 @@ static int dev_pci_onboard(struct udev_device *dev, struct netnames *names) {
923a60
         unsigned dev_port = 0;
923a60
         size_t l;
923a60
         char *s;
923a60
-        const char *attr;
923a60
+        const char *attr, *port_name;
923a60
         int idx;
923a60
 
923a60
         /* ACPI _DSM  -- device specific method for naming a PCI or PCI Express device */
923a60
@@ -161,10 +161,15 @@ static int dev_pci_onboard(struct udev_device *dev, struct netnames *names) {
923a60
         if (attr)
923a60
                 dev_port = strtol(attr, NULL, 10);
923a60
 
923a60
+        /* kernel provided front panel port name for multiple port PCI device */
923a60
+        port_name = udev_device_get_sysattr_value(dev, "phys_port_name");
923a60
+
923a60
         s = names->pci_onboard;
923a60
         l = sizeof(names->pci_onboard);
923a60
         l = strpcpyf(&s, l, "o%d", idx);
923a60
-        if (dev_port > 0)
923a60
+        if (port_name)
923a60
+                l = strpcpyf(&s, l, "n%s", port_name);
923a60
+        else if (dev_port > 0)
923a60
                 l = strpcpyf(&s, l, "d%d", dev_port);
923a60
         if (l == 0)
923a60
                 names->pci_onboard[0] = '\0';
923a60
@@ -199,7 +204,7 @@ static int dev_pci_slot(struct udev_device *dev, struct netnames *names) {
923a60
         unsigned domain, bus, slot, func, dev_id = 0;
923a60
         size_t l;
923a60
         char *s;
923a60
-        const char *attr;
923a60
+        const char *attr, *port_name;
923a60
         struct udev_device *pci = NULL;
923a60
         char slots[256], str[256];
923a60
         _cleanup_closedir_ DIR *dir = NULL;
923a60
@@ -220,6 +225,9 @@ static int dev_pci_slot(struct udev_device *dev, struct netnames *names) {
923a60
                 }
923a60
         }
923a60
 
923a60
+        /* kernel provided front panel port name for multiple port PCI device */
923a60
+        port_name = udev_device_get_sysattr_value(dev, "phys_port_name");
923a60
+
923a60
         /* compose a name based on the raw kernel's PCI bus, slot numbers */
923a60
         s = names->pci_path;
923a60
         l = sizeof(names->pci_path);
923a60
@@ -228,7 +236,9 @@ static int dev_pci_slot(struct udev_device *dev, struct netnames *names) {
923a60
         l = strpcpyf(&s, l, "p%us%u", bus, slot);
923a60
         if (func > 0 || is_pci_multifunction(names->pcidev))
923a60
                 l = strpcpyf(&s, l, "f%d", func);
923a60
-        if (dev_id > 0)
923a60
+        if (port_name)
923a60
+                l = strpcpyf(&s, l, "n%s", port_name);
923a60
+        else if (dev_id > 0)
923a60
                 l = strpcpyf(&s, l, "d%d", dev_id);
923a60
         if (l == 0)
923a60
                 names->pci_path[0] = '\0';
923a60
@@ -278,7 +288,9 @@ static int dev_pci_slot(struct udev_device *dev, struct netnames *names) {
923a60
                 l = strpcpyf(&s, l, "s%d", hotplug_slot);
923a60
                 if (func > 0 || is_pci_multifunction(names->pcidev))
923a60
                         l = strpcpyf(&s, l, "f%d", func);
923a60
-                if (dev_id > 0)
923a60
+                if (port_name)
923a60
+                        l = strpcpyf(&s, l, "n%s", port_name);
923a60
+                else if (dev_id > 0)
923a60
                         l = strpcpyf(&s, l, "d%d", dev_id);
923a60
                 if (l == 0)
923a60
                         names->pci_slot[0] = '\0';