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