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,URIBL_BLOCKED,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 EA946C169C4 for ; Thu, 31 Jan 2019 18:52:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B990F218AF for ; Thu, 31 Jan 2019 18:52:27 +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="bD3EtMGY" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728225AbfAaSwW (ORCPT ); Thu, 31 Jan 2019 13:52:22 -0500 Received: from mail-pl1-f193.google.com ([209.85.214.193]:42824 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728201AbfAaSwU (ORCPT ); Thu, 31 Jan 2019 13:52:20 -0500 Received: by mail-pl1-f193.google.com with SMTP id y1so1872786plp.9 for ; Thu, 31 Jan 2019 10:52:19 -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=QZt7KR/GoFF4zVkdwXzl1RmHnB+ETCVXsnfZ1mE+y1E=; b=bD3EtMGY8fKrhvV/9P5R1T0Jva0QISR/VMClmSDHmBAjk4yzGxUj/SD0V5MyYZQh4E uDK2+dOf7nEBCM+hJtr3ViOr+5+t9LOC7hvFWBxZPrxNaravHXli1LpeS+PUB2wGcvOj 31Xads0+5jyAJ+Gjsfb4XZv/T7H3xzdTZvqBF139xLfjY0urLVa+LRI9M557ZLHxyIZU cZA5Pj3vTJMng1gJJDqtWqslxjGZkd4/1oP+nPNYV0GUglYdnGjDkP4QAQR43rYlvASr 3EmW33abSUEnKHLrAigw9RRIJIWqkou+bbnM18x/kgd6TDrS9pBfKX2561hS/tMgyW8i t2Rg== 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=QZt7KR/GoFF4zVkdwXzl1RmHnB+ETCVXsnfZ1mE+y1E=; b=QZYv3QrrnQcQX3tSz8vTHvpOcCoNNcRokVEjWqnEWRDN6nk9QQVSOV6+4Q6F7o1sVT JAMG9w/JCLP4Z4/QsEfaP2Hrt565kbj54mfnoFpVkAGUx1D0eKqVy0b6ZgxDPQBertnR tz91PE9MR2YI5EEywCIf2JUb/874PbmJD79RpOJYAzyv2W8F+0GmtwaCfZeqauDyzZEP EanXOodL/Q62ZHky5ZEkNYUMyMSIMEVH2+1x9snkYcIj5OFwYSwUmZQZjR5xMLSC9BDW AFOFXQnJoF3Ef9nMWTc6yc5mQN7Ap+74bPJxQhPtlnUb/CCFb30CpQ0ygjD+3LfBLzJP tdJA== X-Gm-Message-State: AJcUukdEPA3Zw9W+tPE9httcnsSjsAaAU03E8DUGCM87ZumKohWYVMmg U+jBnr8mYWUvQDhZcPN+S87YvQ== X-Google-Smtp-Source: ALg8bN4Yl5i1JauAzvQLxWI9O+u2SVVN49oR2NMOe8WHWZI33bgWUXxvR4wEwGUYIeUtJe6Fwl7d5w== X-Received: by 2002:a17:902:780a:: with SMTP id p10mr36763162pll.54.1548960739223; Thu, 31 Jan 2019 10:52:19 -0800 (PST) Received: from jkicinski-Precision-T1700.netronome.com ([66.60.152.14]) by smtp.gmail.com with ESMTPSA id o4sm7726169pgs.12.2019.01.31.10.52.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 31 Jan 2019 10:52:18 -0800 (PST) From: Jakub Kicinski To: davem@davemloft.net Cc: netdev@vger.kernel.org, oss-drivers@netronome.com, jiri@resnulli.us, andrew@lunn.ch, f.fainelli@gmail.com, mkubecek@suse.cz, eugenem@fb.com, jonathan.lemon@gmail.com, Jakub Kicinski Subject: [PATCH net-next v4 8/8] ethtool: add compat for devlink info Date: Thu, 31 Jan 2019 10:50:47 -0800 Message-Id: <20190131185047.27685-9-jakub.kicinski@netronome.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20190131185047.27685-1-jakub.kicinski@netronome.com> References: <20190131185047.27685-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 If driver did not fill the fw_version field, try to call into the new devlink get_info op and collect the versions that way. We assume ethtool was always reporting running versions. v4: - use IS_REACHABLE() to avoid problems with DEVLINK=m (kbuildbot). v3 (Jiri): - do a dump and then parse it instead of special handling; - concatenate all versions (well, all that fit :)). Signed-off-by: Jakub Kicinski --- include/net/devlink.h | 10 +++++++ net/core/devlink.c | 63 +++++++++++++++++++++++++++++++++++++++++++ net/core/ethtool.c | 7 +++++ 3 files changed, 80 insertions(+) diff --git a/include/net/devlink.h b/include/net/devlink.h index 6b417f141fd6..1c8523920f66 100644 --- a/include/net/devlink.h +++ b/include/net/devlink.h @@ -972,4 +972,14 @@ devlink_info_version_running_put(struct devlink_info_req *req, } #endif +#if IS_REACHABLE(CONFIG_NET_DEVLINK) +void devlink_compat_running_version(struct net_device *dev, + char *buf, size_t len); +#else +static inline void +devlink_compat_running_version(struct net_device *dev, char *buf, size_t len) +{ +} +#endif + #endif /* _NET_DEVLINK_H_ */ diff --git a/net/core/devlink.c b/net/core/devlink.c index e31b6d617837..eb839d74bcc0 100644 --- a/net/core/devlink.c +++ b/net/core/devlink.c @@ -5278,6 +5278,69 @@ int devlink_region_snapshot_create(struct devlink_region *region, u64 data_len, } EXPORT_SYMBOL_GPL(devlink_region_snapshot_create); +static void __devlink_compat_running_version(struct devlink *devlink, + char *buf, size_t len) +{ + const struct nlattr *nlattr; + struct devlink_info_req req; + struct sk_buff *msg; + int rem, err; + + if (!devlink->ops->info_get) + return; + + msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); + if (!msg) + return; + + req.msg = msg; + err = devlink->ops->info_get(devlink, &req, NULL); + if (err) + goto free_msg; + + nla_for_each_attr(nlattr, (void *)msg->data, msg->len, rem) { + const struct nlattr *kv; + int rem_kv; + + if (nla_type(nlattr) != DEVLINK_ATTR_INFO_VERSION_RUNNING) + continue; + + nla_for_each_nested(kv, nlattr, rem_kv) { + if (nla_type(kv) != DEVLINK_ATTR_INFO_VERSION_VALUE) + continue; + + strlcat(buf, nla_data(kv), len); + strlcat(buf, " ", len); + } + } +free_msg: + nlmsg_free(msg); +} + +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); +} + static int __init devlink_module_init(void) { return genl_register_family(&devlink_nl_family); diff --git a/net/core/ethtool.c b/net/core/ethtool.c index 158264f7cfaf..197a4dfb712d 100644 --- a/net/core/ethtool.c +++ b/net/core/ethtool.c @@ -27,6 +27,7 @@ #include #include #include +#include #include /* @@ -803,6 +804,12 @@ static noinline_for_stack int ethtool_get_drvinfo(struct net_device *dev, if (ops->get_eeprom_len) info.eedump_len = ops->get_eeprom_len(dev); + rtnl_unlock(); + if (!info.fw_version[0]) + devlink_compat_running_version(dev, info.fw_version, + sizeof(info.fw_version)); + rtnl_lock(); + if (copy_to_user(useraddr, &info, sizeof(info))) return -EFAULT; return 0; -- 2.19.2