Commit af3836df authored by Jiri Pirko's avatar Jiri Pirko Committed by David S. Miller

net: devlink: introduce devlink_compat_phys_port_name_get()

Introduce devlink_compat_phys_port_name_get() helper that
gets the physical port name for specified netdevice
according to devlink port attributes.
Call this helper from dev_get_phys_port_name()
in case ndo_get_phys_port_name is not defined.
Signed-off-by: default avatarJiri Pirko <jiri@mellanox.com>
Reviewed-by: default avatarJakub Kicinski <jakub.kicinski@netronome.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 5dc37bb9
...@@ -739,6 +739,8 @@ devlink_health_reporter_state_update(struct devlink_health_reporter *reporter, ...@@ -739,6 +739,8 @@ devlink_health_reporter_state_update(struct devlink_health_reporter *reporter,
void devlink_compat_running_version(struct net_device *dev, void devlink_compat_running_version(struct net_device *dev,
char *buf, size_t len); char *buf, size_t len);
int devlink_compat_flash_update(struct net_device *dev, const char *file_name); int devlink_compat_flash_update(struct net_device *dev, const char *file_name);
int devlink_compat_phys_port_name_get(struct net_device *dev,
char *name, size_t len);
#else #else
...@@ -753,6 +755,13 @@ devlink_compat_flash_update(struct net_device *dev, const char *file_name) ...@@ -753,6 +755,13 @@ devlink_compat_flash_update(struct net_device *dev, const char *file_name)
return -EOPNOTSUPP; return -EOPNOTSUPP;
} }
static inline int
devlink_compat_phys_port_name_get(struct net_device *dev,
char *name, size_t len)
{
return -EOPNOTSUPP;
}
#endif #endif
#endif /* _NET_DEVLINK_H_ */ #endif /* _NET_DEVLINK_H_ */
...@@ -146,6 +146,7 @@ ...@@ -146,6 +146,7 @@
#include <net/udp_tunnel.h> #include <net/udp_tunnel.h>
#include <linux/net_namespace.h> #include <linux/net_namespace.h>
#include <linux/indirect_call_wrapper.h> #include <linux/indirect_call_wrapper.h>
#include <net/devlink.h>
#include "net-sysfs.h" #include "net-sysfs.h"
...@@ -7877,10 +7878,14 @@ int dev_get_phys_port_name(struct net_device *dev, ...@@ -7877,10 +7878,14 @@ int dev_get_phys_port_name(struct net_device *dev,
char *name, size_t len) char *name, size_t len)
{ {
const struct net_device_ops *ops = dev->netdev_ops; const struct net_device_ops *ops = dev->netdev_ops;
int err;
if (!ops->ndo_get_phys_port_name) if (ops->ndo_get_phys_port_name) {
return -EOPNOTSUPP; err = ops->ndo_get_phys_port_name(dev, name, len);
return ops->ndo_get_phys_port_name(dev, name, len); if (err != -EOPNOTSUPP)
return err;
}
return devlink_compat_phys_port_name_get(dev, name, len);
} }
EXPORT_SYMBOL(dev_get_phys_port_name); EXPORT_SYMBOL(dev_get_phys_port_name);
......
...@@ -5414,8 +5414,8 @@ void devlink_port_attrs_set(struct devlink_port *devlink_port, ...@@ -5414,8 +5414,8 @@ void devlink_port_attrs_set(struct devlink_port *devlink_port,
} }
EXPORT_SYMBOL_GPL(devlink_port_attrs_set); EXPORT_SYMBOL_GPL(devlink_port_attrs_set);
int devlink_port_get_phys_port_name(struct devlink_port *devlink_port, static int __devlink_port_phys_port_name_get(struct devlink_port *devlink_port,
char *name, size_t len) char *name, size_t len)
{ {
struct devlink_port_attrs *attrs = &devlink_port->attrs; struct devlink_port_attrs *attrs = &devlink_port->attrs;
int n = 0; int n = 0;
...@@ -5445,6 +5445,12 @@ int devlink_port_get_phys_port_name(struct devlink_port *devlink_port, ...@@ -5445,6 +5445,12 @@ int devlink_port_get_phys_port_name(struct devlink_port *devlink_port,
return 0; return 0;
} }
int devlink_port_get_phys_port_name(struct devlink_port *devlink_port,
char *name, size_t len)
{
return __devlink_port_phys_port_name_get(devlink_port, name, len);
}
EXPORT_SYMBOL_GPL(devlink_port_get_phys_port_name); EXPORT_SYMBOL_GPL(devlink_port_get_phys_port_name);
int devlink_sb_register(struct devlink *devlink, unsigned int sb_index, int devlink_sb_register(struct devlink *devlink, unsigned int sb_index,
...@@ -6459,6 +6465,24 @@ int devlink_compat_flash_update(struct net_device *dev, const char *file_name) ...@@ -6459,6 +6465,24 @@ int devlink_compat_flash_update(struct net_device *dev, const char *file_name)
return ret; return ret;
} }
int devlink_compat_phys_port_name_get(struct net_device *dev,
char *name, size_t len)
{
struct devlink_port *devlink_port;
/* RTNL mutex is held here which ensures that devlink_port
* instance cannot disappear in the middle. No need to take
* any devlink lock as only permanent values are accessed.
*/
ASSERT_RTNL();
devlink_port = netdev_to_devlink_port(dev);
if (!devlink_port)
return -EOPNOTSUPP;
return __devlink_port_phys_port_name_get(devlink_port, name, len);
}
static int __init devlink_init(void) static int __init devlink_init(void)
{ {
return genl_register_family(&devlink_nl_family); return genl_register_family(&devlink_nl_family);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment