From b473b0d23529cde6c825a592c035e9d910b19e21 Mon Sep 17 00:00:00 2001 From: Jakub Kicinski Date: Mon, 25 Feb 2019 19:34:03 -0800 Subject: devlink: create a special NDO for getting the devlink instance Instead of iterating over all devlink ports add a NDO which will return the devlink instance from the driver. v2: add the netdev_to_devlink() helper (Michal) v3: check that devlink has ops (Florian) v4: hold devlink_mutex (Jiri) Suggested-by: Jiri Pirko Signed-off-by: Jakub Kicinski Reviewed-by: Florian Fainelli Acked-by: Jiri Pirko Signed-off-by: David S. Miller --- include/net/devlink.h | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'include/net') diff --git a/include/net/devlink.h b/include/net/devlink.h index f9f7fe974652..7f5a0bdca228 100644 --- a/include/net/devlink.h +++ b/include/net/devlink.h @@ -538,6 +538,15 @@ static inline struct devlink *priv_to_devlink(void *priv) return container_of(priv, struct devlink, priv); } +static inline struct devlink *netdev_to_devlink(struct net_device *dev) +{ +#if IS_ENABLED(CONFIG_NET_DEVLINK) + if (dev->netdev_ops->ndo_get_devlink) + return dev->netdev_ops->ndo_get_devlink(dev); +#endif + return NULL; +} + struct ib_device; #if IS_ENABLED(CONFIG_NET_DEVLINK) -- cgit v1.2.3-59-g8ed1b