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 D0EC0C282C7 for ; Tue, 29 Jan 2019 03:34:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 91678214DA for ; Tue, 29 Jan 2019 03:34:54 +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="dBhUKkRI" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727583AbfA2Dex (ORCPT ); Mon, 28 Jan 2019 22:34:53 -0500 Received: from mail-qk1-f193.google.com ([209.85.222.193]:39930 "EHLO mail-qk1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727574AbfA2Dev (ORCPT ); Mon, 28 Jan 2019 22:34:51 -0500 Received: by mail-qk1-f193.google.com with SMTP id c21so10752918qkl.6 for ; Mon, 28 Jan 2019 19:34:50 -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=TwFCcIYU6IhCf3F73pnJdFvitD3nmMghLrf/JTPVGiE=; b=dBhUKkRIXeD0yrnHU1P1T2f/Fvh7xNcPIXHd/FdSOy+/LC8qqxbTuqcRmiKz8+zcFX 8ubMbsc0vfpKFDJ/t/fELvxG3ACsNEtuYeZD2QAJlmsNqdvFldUZMNrUGyQxiwil0F2w 4jJmEBCrbQUIjl84XRceGwhfu5J+r0+KafYufKi8Ij2+Sxs6ah6AjcSwTjm/C5bgHgaf D6QRzJxQ5K1PiyJBPrc2TDHDzDHjHfNCDnF0pcjEVEQZ/lTeU1lW7k6TwKeu0Y3fQ40a syCP1rA8dKnb+B0Y/gXvN30Kth8QS0vXZe7pj+5smIlRw75UAqqpKnO88lEPPNv5M+PL Iysg== 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=TwFCcIYU6IhCf3F73pnJdFvitD3nmMghLrf/JTPVGiE=; b=IPKjk4lTiFF9ibehzcdflh5mtaTkoxQjKBfgKKeJhfbFr8Qzgpi0xgPsLvOT2hVs1N 04WrP4/+JK+jsV/+pfoJ7a/yQp2yOyc4SBFSavLNS37dRNiZOCAsdbh/sTEif6Q5s1xO b7Spks5pH4Tiue+jpwZqdoGOY0AkLksqdbLtupTSqNWyjDOwtfNMggm1R3zQprnFShOE j1bjxvpjTJMaqJuyd/TKQhJfIs9NULut9n5tlXdvZU7UXlEUOMHze5FS+s6wnN8bWJ/y AQ67ahjhJW7AlBOy4g2zmxi2QjSrmr7DN2JHwIKNxPK6GaiUreAumq/uE6tdTv9hRUgR zEgg== X-Gm-Message-State: AJcUukcXXoX1huVC9m5MBFC1bM63xFLAW0O4CH/1aCJwPPKZ1L2fWyCv ikl7OBcXnDhh32jA++7qN4ToNQ== X-Google-Smtp-Source: ALg8bN7Ed9gfGOYq1ZLrHaoFHPTtR+nH2X7r3oLq7IGPTlo4Dfn7c4uL80U5dTkExqjbsvvfqDGsmg== X-Received: by 2002:a37:cc4c:: with SMTP id r73mr21585357qki.120.1548732890131; Mon, 28 Jan 2019 19:34:50 -0800 (PST) Received: from jkicinski-Precision-T1700.netronome.com ([66.60.152.14]) by smtp.gmail.com with ESMTPSA id z18sm70505153qkz.96.2019.01.28.19.34.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 28 Jan 2019 19:34:49 -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 7/7] ethtool: add compat for devlink info Date: Mon, 28 Jan 2019 19:34:20 -0800 Message-Id: <20190129033420.27235-8-jakub.kicinski@netronome.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20190129033420.27235-1-jakub.kicinski@netronome.com> References: <20190129033420.27235-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. Signed-off-by: Jakub Kicinski --- include/net/devlink.h | 7 ++++++ net/core/devlink.c | 52 ++++++++++++++++++++++++++++++++++++++++++- net/core/ethtool.c | 7 ++++++ 3 files changed, 65 insertions(+), 1 deletion(-) diff --git a/include/net/devlink.h b/include/net/devlink.h index 14da3632e8fc..b047360b88a9 100644 --- a/include/net/devlink.h +++ b/include/net/devlink.h @@ -616,6 +616,8 @@ int devlink_info_report_version(struct devlink_info_req *req, enum devlink_version_type type, const char *version_name, const char *version_value); +void devlink_compat_running_versions(struct net_device *dev, + char *buf, size_t len); #else @@ -896,6 +898,11 @@ devlink_info_report_version(struct devlink_info_req *req, { return 0; } + +static inline void +devlink_compat_running_versions(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 f0c5f9bd96b7..99037bf15fb8 100644 --- a/net/core/devlink.c +++ b/net/core/devlink.c @@ -3598,12 +3598,18 @@ static int devlink_nl_cmd_region_read_dumpit(struct sk_buff *skb, } struct devlink_info_req { + bool compat; struct sk_buff *msg; + /* For compat call */ + char *buf; + size_t len; }; int devlink_info_report_driver_name(struct devlink_info_req *req, const char *name) { + if (req->compat) + return 0; return nla_put_string(req->msg, DEVLINK_ATTR_INFO_DRV_NAME, name); } EXPORT_SYMBOL_GPL(devlink_info_report_driver_name); @@ -3611,6 +3617,8 @@ EXPORT_SYMBOL_GPL(devlink_info_report_driver_name); int devlink_info_report_serial_number(struct devlink_info_req *req, const char *sn) { + if (req->compat) + return 0; return nla_put_string(req->msg, DEVLINK_ATTR_INFO_SERIAL_NUMBER, sn); } EXPORT_SYMBOL_GPL(devlink_info_report_serial_number); @@ -3626,7 +3634,15 @@ int devlink_info_report_version(struct devlink_info_req *req, [DEVLINK_VERSION_RUNNING] = DEVLINK_ATTR_INFO_VERSION_RUNNING, }; struct nlattr *nest; - int err; + int len, err; + + if (req->compat) { + if (type == DEVLINK_VERSION_RUNNING) { + len = strlcpy(req->buf, version_value, req->len); + req->len = max_t(size_t, 0, req->len - len); + } + return 0; + } if (type >= ARRAY_SIZE(type2attr) || !type2attr[type]) return -EINVAL; @@ -3672,6 +3688,7 @@ devlink_nl_info_fill(struct sk_buff *msg, struct devlink *devlink, if (devlink_nl_put_handle(msg, devlink)) goto err_cancel_msg; + memset(&req, 0, sizeof(req)); req.msg = msg; err = devlink->ops->info_get(devlink, &req, extack); if (err) @@ -4962,6 +4979,39 @@ int devlink_region_snapshot_create(struct devlink_region *region, u64 data_len, } EXPORT_SYMBOL_GPL(devlink_region_snapshot_create); +void devlink_compat_running_versions(struct net_device *dev, + char *buf, size_t len) +{ + struct devlink_port *devlink_port; + struct devlink_info_req req; + struct devlink *devlink; + bool found = false; + + 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) { + mutex_unlock(&devlink->lock); + found = true; + goto out; + } + } + mutex_unlock(&devlink->lock); + } +out: + if (found && devlink->ops->info_get) { + memset(&req, 0, sizeof(req)); + req.compat = true; + req.buf = buf; + req.len = len; + + devlink->ops->info_get(devlink, &req, NULL); + } + 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..176b17d11f08 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_versions(dev, info.fw_version, + ARRAY_SIZE(info.fw_version)); + rtnl_lock(); + if (copy_to_user(useraddr, &info, sizeof(info))) return -EFAULT; return 0; -- 2.19.2