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