From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.0 required=3.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DB772C43381 for ; Fri, 22 Feb 2019 22:15:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9D01920675 for ; Fri, 22 Feb 2019 22:15:02 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=netronome-com.20150623.gappssmtp.com header.i=@netronome-com.20150623.gappssmtp.com header.b="MaOnuvOo" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726428AbfBVWPB (ORCPT ); Fri, 22 Feb 2019 17:15:01 -0500 Received: from mail-qt1-f196.google.com ([209.85.160.196]:38150 "EHLO mail-qt1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726296AbfBVWPA (ORCPT ); Fri, 22 Feb 2019 17:15:00 -0500 Received: by mail-qt1-f196.google.com with SMTP id s1so4338533qte.5 for ; Fri, 22 Feb 2019 14:14:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=netronome-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=rKFFOpRD6RHrNcQZB5rD7Qzcx45BDi7aKCzIl/VDvs4=; b=MaOnuvOoIR/QSWwPCFETdUks3yGLf91l9XtsT+d+AcJ/Xg4FJU6AMWI9wEr+lltnXE FKJStQCZSKu6oiX/11NyiuQsDbd2c2Ss/xj1CZRBhVWNTPJAxs17bBQFVz3CXK7hP5HM Fn+A88YTfEDMhlsJf+jnzqgaQisCbJsx5kyjMk0lccfiO+tXf10pQXpX+bCAzl75Oh8Y QWnOIjXeDeA0xQ9DKl8P9nhDhbyTXVNNLFmqcE/pKUM9w4Do3j3Lc2IAhIzX2KXo3NCQ zHL6FUURgeBxFaxs25N744nB7z6A6iP9Ryz9SBwv5D/+Xn4QSRQH7jwvb+u/J1BUENhW DhWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=rKFFOpRD6RHrNcQZB5rD7Qzcx45BDi7aKCzIl/VDvs4=; b=qE9Bf665Oc7Ar1A5vP5VdvcZNc3W0yKZdT9/Il8R/nj86+df1JjwnnYjZCrN6R3Ato EHyG00+8+AXcu47KkZJB7HGEcipg+iYZZt33hzraey3+izzRQX+oO/U5mX6sOwad1wVr 1yURFSYPdOcSfHZONlPTU7D4ebyleWzdCM5B9l7OGfQ8sEjMEGW83xLha9oWT5cS1BZ6 OxAjGXi4GVNHL9lka/JxWPnx/5iply825MPBDe9lmxoixlZjPT+MbIKA1dAfw3nQ5z0U kD6ZWrWBPn7ndD+OMYnHSu/5MlWkhLynt0f/g9jTSbTE4Aio0EoLD1NLY2L6LoNSYaS/ h5gQ== X-Gm-Message-State: AHQUAubAk8AKPBsMqI4uDkjlQgGuDFrNbbpWDWzBUS8afUQ8F0FTl5KK YGweF4lL0tLZ1IF1xZW5dPJZmg== X-Google-Smtp-Source: AHgI3IboAXTvmwbezA0JCVTRAWJ6TZM8GcACidTLI/jGdGx+U41GxZEavgZArevR6+UXJ/4PXL8YzQ== X-Received: by 2002:ac8:3273:: with SMTP id y48mr5053990qta.67.1550873698641; Fri, 22 Feb 2019 14:14:58 -0800 (PST) Received: from jkicinski-Precision-T1700.netronome.com ([66.60.152.14]) by smtp.gmail.com with ESMTPSA id j66sm2707211qkj.27.2019.02.22.14.14.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 22 Feb 2019 14:14:58 -0800 (PST) From: Jakub Kicinski To: davem@davemloft.net, jiri@resnulli.us Cc: mkubecek@suse.cz, andrew@lunn.ch, f.fainelli@gmail.com, netdev@vger.kernel.org, oss-drivers@netronome.com, Jakub Kicinski Subject: [PATCH net-next v3 2/6] devlink: create a special NDO for getting the devlink instance Date: Fri, 22 Feb 2019 14:07:53 -0800 Message-Id: <20190222220758.7117-3-jakub.kicinski@netronome.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20190222220758.7117-1-jakub.kicinski@netronome.com> References: <20190222220758.7117-1-jakub.kicinski@netronome.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org 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) Suggested-by: Jiri Pirko Signed-off-by: Jakub Kicinski Reviewed-by: Florian Fainelli --- include/linux/netdevice.h | 6 ++++ include/net/devlink.h | 9 ++++++ net/core/devlink.c | 58 ++++++++++----------------------------- 3 files changed, 30 insertions(+), 43 deletions(-) diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index aab4d9f6613d..eebcef6b8191 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -940,6 +940,8 @@ struct dev_ifalias { char ifalias[]; }; +struct devlink; + /* * This structure defines the management hooks for network devices. * The following hooks can be defined; unless noted otherwise, they are @@ -1248,6 +1250,9 @@ struct dev_ifalias { * that got dropped are freed/returned via xdp_return_frame(). * Returns negative number, means general error invoking ndo, meaning * no frames were xmit'ed and core-caller will free all frames. + * struct devlink *(*ndo_get_devlink)(struct net_device *dev); + * Get devlink instance associated with a given netdev. + * Called with a reference on the device only, rtnl_lock is not held. */ struct net_device_ops { int (*ndo_init)(struct net_device *dev); @@ -1446,6 +1451,7 @@ struct net_device_ops { u32 flags); int (*ndo_xsk_async_xmit)(struct net_device *dev, u32 queue_id); + struct devlink * (*ndo_get_devlink)(struct net_device *dev); }; /** 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) diff --git a/net/core/devlink.c b/net/core/devlink.c index 05e04ea0a5c7..a13055160be0 100644 --- a/net/core/devlink.c +++ b/net/core/devlink.c @@ -6397,9 +6397,6 @@ static void __devlink_compat_running_version(struct devlink *devlink, struct sk_buff *msg; int rem, err; - if (!devlink->ops->info_get) - return; - msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); if (!msg) return; @@ -6431,55 +6428,30 @@ static void __devlink_compat_running_version(struct devlink *devlink, void devlink_compat_running_version(struct net_device *dev, char *buf, size_t len) { - struct devlink_port *devlink_port; struct devlink *devlink; - mutex_lock(&devlink_mutex); - list_for_each_entry(devlink, &devlink_list, list) { - mutex_lock(&devlink->lock); - list_for_each_entry(devlink_port, &devlink->port_list, list) { - if (devlink_port->type == DEVLINK_PORT_TYPE_ETH && - devlink_port->type_dev == dev) { - __devlink_compat_running_version(devlink, - buf, len); - mutex_unlock(&devlink->lock); - goto out; - } - } - mutex_unlock(&devlink->lock); - } -out: - mutex_unlock(&devlink_mutex); + devlink = netdev_to_devlink(dev); + if (!devlink || !devlink->ops || !devlink->ops->info_get) + return; + + mutex_lock(&devlink->lock); + __devlink_compat_running_version(devlink, buf, len); + mutex_unlock(&devlink->lock); } int devlink_compat_flash_update(struct net_device *dev, const char *file_name) { - struct devlink_port *devlink_port; struct devlink *devlink; + int ret; - mutex_lock(&devlink_mutex); - list_for_each_entry(devlink, &devlink_list, list) { - mutex_lock(&devlink->lock); - list_for_each_entry(devlink_port, &devlink->port_list, list) { - int ret = -EOPNOTSUPP; - - if (devlink_port->type != DEVLINK_PORT_TYPE_ETH || - devlink_port->type_dev != dev) - continue; - - mutex_unlock(&devlink_mutex); - if (devlink->ops->flash_update) - ret = devlink->ops->flash_update(devlink, - file_name, - NULL, NULL); - mutex_unlock(&devlink->lock); - return ret; - } - mutex_unlock(&devlink->lock); - } - mutex_unlock(&devlink_mutex); + devlink = netdev_to_devlink(dev); + if (!devlink || !devlink->ops || !devlink->ops->flash_update) + return -EOPNOTSUPP; - return -EOPNOTSUPP; + mutex_lock(&devlink->lock); + ret = devlink->ops->flash_update(devlink, file_name, NULL, NULL); + mutex_unlock(&devlink->lock); + return ret; } static int __init devlink_init(void) -- 2.19.2