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 9C25EC282CA for ; Tue, 29 Jan 2019 03:34:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5ADB3214DA for ; Tue, 29 Jan 2019 03:34:43 +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="rC7jwNI6" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727388AbfA2Dem (ORCPT ); Mon, 28 Jan 2019 22:34:42 -0500 Received: from mail-qk1-f193.google.com ([209.85.222.193]:33950 "EHLO mail-qk1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727041AbfA2Del (ORCPT ); Mon, 28 Jan 2019 22:34:41 -0500 Received: by mail-qk1-f193.google.com with SMTP id q8so10779586qke.1 for ; Mon, 28 Jan 2019 19:34:41 -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=6EwyJMk0obsep3hPuD+OTpMIf3GVMaAcKT5/IJQSeas=; b=rC7jwNI6Yu2xzze55Nx6GlnBYm5epuQHcgR5eCR4IGXqFfFc0tGEgueODqifc40pkn a/rqZodrmgD8S3T8V9wpJkVIpf38QzSXS8TbyOjfIk/vpqYSUxsoT2AttgUBdHo6D31V NwflEEtAn5c+k0kq3T74Bh0elnz6cEqK37r9S/HGeMiObyKD4Czi36YjR9WXjXjPeYXD B/Ws3AuTXepGAa+fySZn08ImAdZengbgT1neEz74r+oT66QCSKrTWMP1eeouxi/IXN7I bVBui3SIILyD41gcFuoiAH7S96nyXBERuBOQulhbN8A1iEY35VW4R4LtEeZoPgdZnBLo N1UA== 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=6EwyJMk0obsep3hPuD+OTpMIf3GVMaAcKT5/IJQSeas=; b=iRqQy59MGrMayUvSox9nrJK5JNCBIT3mtQg8geEs1JI+5u7AQE58Ojy1e/hZ7mvhWY l06tbEbabUbxkvvRCdg7PAEcqJokt8c3WrvxGsvR9VpksiGFx/IIwkvmaan2jCG3WBAU wKz2Ubq7XkX/sGAKjiIzQsDJ+2+AM2NtyRqPlE2FqoHrXkGSS3K1bO+nSAXvR9T6rm0D 3ftJ4rpcYL0HmxP0k1+TQ/hKPdV+RAJu0nNxPcVqQZ7fM7fVPwrUB9XP8ul7+EG8L0d1 qJE0vbS1Qj7JFTY334aN1uM8hvaiyyud6XocZYHf6VzY5AdOynGka4YnXfpNs94tBin1 uhgw== X-Gm-Message-State: AJcUukcTaWAkBc1Gzw7Mk9JKQzh7J4mU0VqM0XyphWCDI2jkX4Bp6ybR EDraUXsSrZ7fzAqcjhrLp3mY2A== X-Google-Smtp-Source: ALg8bN4+cyL4mGh/WKnvV8PwGTraGQz2eYhnn+QcPxJ4gm5oR1BQ9rjn8dIVRRdMUyoDPC5YOL9igg== X-Received: by 2002:a37:660f:: with SMTP id a15mr21587903qkc.328.1548732880437; Mon, 28 Jan 2019 19:34:40 -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.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 28 Jan 2019 19:34:39 -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 2/7] devlink: add version reporting to devlink info API Date: Mon, 28 Jan 2019 19:34:15 -0800 Message-Id: <20190129033420.27235-3-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 ethtool -i has a few fixed-size fields which can be used to report firmware version and expansion ROM version. Unfortunately, modern hardware has more firmware components. There is usually some datapath microcode, management controller, PXE drivers, and a CPLD load. Running ethtool -i on modern controllers reveals the fact that vendors cram multiple values into firmware version field. Here are some examples from systems I could lay my hands on quickly: tg3: "FFV20.2.17 bc 5720-v1.39" i40e: "6.01 0x800034a4 1.1747.0" nfp: "0.0.3.5 0.25 sriov-2.1.16 nic" Add a new devlink API to allow retrieving multiple versions, and provide user-readable name for those versions. While at it break down the versions into three categories: - fixed - this is the board/fixed component version, usually vendors report information like the board version in the PCI VPD, but it will benefit from naming and common API as well; - running - this is the running firmware version; - stored - this is firmware in the flash, after firmware update this value will reflect the flashed version, while the running version may only be updated after reboot. RFCv2: - remove the nesting in attr DEVLINK_ATTR_INFO_VERSIONS (now versions are mixed with other info attrs)l - have the driver report versions from the same callback as other info. Signed-off-by: Jakub Kicinski --- include/net/devlink.h | 18 ++++++++++++++++ include/uapi/linux/devlink.h | 5 +++++ net/core/devlink.c | 40 ++++++++++++++++++++++++++++++++++++ 3 files changed, 63 insertions(+) diff --git a/include/net/devlink.h b/include/net/devlink.h index d8d425028d55..f53ace3ac4b3 100644 --- a/include/net/devlink.h +++ b/include/net/devlink.h @@ -419,6 +419,12 @@ enum devlink_param_generic_id { .validate = _validate, \ } +enum devlink_version_type { + DEVLINK_VERSION_FIXED, + DEVLINK_VERSION_STORED, + DEVLINK_VERSION_RUNNING, +}; + struct devlink_region; struct devlink_info_req; @@ -590,6 +596,10 @@ int devlink_info_report_serial_number(struct devlink_info_req *req, const char *sn); int devlink_info_report_driver_name(struct devlink_info_req *req, const char *name); +int devlink_info_report_version(struct devlink_info_req *req, + enum devlink_version_type type, + const char *version_name, + const char *version_value); #else @@ -862,6 +872,14 @@ devlink_info_report_serial_number(struct devlink_info_req *req, const char *sn) { return 0; } + +static inline int +devlink_info_report_version(struct devlink_info_req *req, + enum devlink_version_type type, + const char *version_name, const char *version_value) +{ + return 0; +} #endif #endif /* _NET_DEVLINK_H_ */ diff --git a/include/uapi/linux/devlink.h b/include/uapi/linux/devlink.h index c4b5d923f59f..e8d449a203ec 100644 --- a/include/uapi/linux/devlink.h +++ b/include/uapi/linux/devlink.h @@ -289,6 +289,11 @@ enum devlink_attr { DEVLINK_ATTR_INFO_DRV_NAME, /* string */ DEVLINK_ATTR_INFO_SERIAL_NUMBER, /* string */ + DEVLINK_ATTR_INFO_VERSION_FIXED, /* nested */ + DEVLINK_ATTR_INFO_VERSION_RUNNING, /* nested */ + DEVLINK_ATTR_INFO_VERSION_STORED, /* nested */ + DEVLINK_ATTR_INFO_VERSION_NAME, /* string */ + DEVLINK_ATTR_INFO_VERSION_VALUE, /* string */ /* add new attributes above here, update the policy in devlink.c */ diff --git a/net/core/devlink.c b/net/core/devlink.c index 844e086ff038..f0c5f9bd96b7 100644 --- a/net/core/devlink.c +++ b/net/core/devlink.c @@ -3615,6 +3615,46 @@ int devlink_info_report_serial_number(struct devlink_info_req *req, } EXPORT_SYMBOL_GPL(devlink_info_report_serial_number); +int devlink_info_report_version(struct devlink_info_req *req, + enum devlink_version_type type, + const char *version_name, + const char *version_value) +{ + static const enum devlink_attr type2attr[] = { + [DEVLINK_VERSION_FIXED] = DEVLINK_ATTR_INFO_VERSION_FIXED, + [DEVLINK_VERSION_STORED] = DEVLINK_ATTR_INFO_VERSION_STORED, + [DEVLINK_VERSION_RUNNING] = DEVLINK_ATTR_INFO_VERSION_RUNNING, + }; + struct nlattr *nest; + int err; + + if (type >= ARRAY_SIZE(type2attr) || !type2attr[type]) + return -EINVAL; + + nest = nla_nest_start(req->msg, type2attr[type]); + if (!nest) + return -EMSGSIZE; + + err = nla_put_string(req->msg, DEVLINK_ATTR_INFO_VERSION_NAME, + version_name); + if (err) + goto nla_put_failure; + + err = nla_put_string(req->msg, DEVLINK_ATTR_INFO_VERSION_VALUE, + version_value); + if (err) + goto nla_put_failure; + + nla_nest_end(req->msg, nest); + + return 0; + +nla_put_failure: + nla_nest_cancel(req->msg, nest); + return err; +} +EXPORT_SYMBOL_GPL(devlink_info_report_version); + static int devlink_nl_info_fill(struct sk_buff *msg, struct devlink *devlink, enum devlink_command cmd, u32 portid, -- 2.19.2