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 A352FC169C4 for ; Thu, 31 Jan 2019 18:52:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6E416218EA for ; Thu, 31 Jan 2019 18:52:21 +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="x/XiVtgF" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728214AbfAaSwU (ORCPT ); Thu, 31 Jan 2019 13:52:20 -0500 Received: from mail-pf1-f193.google.com ([209.85.210.193]:45634 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728024AbfAaSwM (ORCPT ); Thu, 31 Jan 2019 13:52:12 -0500 Received: by mail-pf1-f193.google.com with SMTP id g62so1869734pfd.12 for ; Thu, 31 Jan 2019 10:52:12 -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=OCHkpA8d2u8kW2UuLvBnZYGEoOK0CXrtOyEyOIgO2Sc=; b=x/XiVtgFaWtAITbe6Vpk3RuEbphwElYTNra5mQG4jrJc94rZUZ11s82awIBfoMpQnD LUeeLfltl1J1CokPGcIMA1h7jlCI8nHKx/sQ6fF6hVJ8PSnL+xRvGaDQgKMyFh0KZ4gV NiL3o5T372pR0D05mdjwAlAXndAG6d/Ozoh+No4pZTtiCTcSwA+Cw6OdzFFGsaUHY9hL mVuHx33X4Ic8DUt/GYNyd4tPYYCjD3X7U989YxxuZQjfdOEfdsZ71WzvpqD7hWo0zcnD /VZ88PLyj/j2tvPxezgNnZ5hJTopK60zA67hgl9u4FtMG9TJlTNB0sLH7uA5JcQlV3l9 /Chw== 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=OCHkpA8d2u8kW2UuLvBnZYGEoOK0CXrtOyEyOIgO2Sc=; b=n02sWbnqGohYwGHkFWvx05QwOSIILEEeUcPF7WZIi5uGxDL/yr5p7xYmNd9zrRrkzl f1uDHhRQL4sSujEPV2SeD68oU7x97noFBOvIA81nnyZyFKRghhYlM2nxWLYg2b9jDYjd kqxCIXiXXApnwh5hsutW2ZNjuxIldDNXJeB2ewBFwrA/SMoXDfilYSTwQpvX2Q/6+GfO MvY0MiQ1JsKWduoLB4QDO2F9gEIzYXnlgc0ilEPFcegbZTtdXJ3mZZIMUsrE8SnTgZab RhqqKbIPkBSykXWY/p70wX2W4OPLWWBI0nC5n6tI4gXI4QmKZRjfiLV001LfTB7iDEUQ e9wQ== X-Gm-Message-State: AJcUukc7M0e1usUlDXdRj4cJfusI+PJFwZHilsYLaEsjTpo+L0SBDs5y T917ldTYOTO0fIrzg0BCfdR8gA== X-Google-Smtp-Source: ALg8bN7IBq6HgJU+ExHhLr5NX+yLEepyca7ODgS5V5PFiGNZX7OeJfpud6M8r+9u0PrI6HPlqgweVw== X-Received: by 2002:a62:4587:: with SMTP id n7mr35624073pfi.118.1548960731817; Thu, 31 Jan 2019 10:52:11 -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.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 31 Jan 2019 10:52:11 -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 2/8] devlink: add version reporting to devlink info API Date: Thu, 31 Jan 2019 10:50:41 -0800 Message-Id: <20190131185047.27685-3-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 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. v3: - add per-type helpers instead of using the special argument (Jiri). 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 Acked-by: Jiri Pirko --- include/net/devlink.h | 33 +++++++++++++++++++++ include/uapi/linux/devlink.h | 5 ++++ net/core/devlink.c | 57 ++++++++++++++++++++++++++++++++++++ 3 files changed, 95 insertions(+) diff --git a/include/net/devlink.h b/include/net/devlink.h index a6d0a530483d..6dc0ef964392 100644 --- a/include/net/devlink.h +++ b/include/net/devlink.h @@ -614,6 +614,15 @@ int devlink_info_serial_number_put(struct devlink_info_req *req, const char *sn); int devlink_info_driver_name_put(struct devlink_info_req *req, const char *name); +int devlink_info_version_fixed_put(struct devlink_info_req *req, + const char *version_name, + const char *version_value); +int devlink_info_version_stored_put(struct devlink_info_req *req, + const char *version_name, + const char *version_value); +int devlink_info_version_running_put(struct devlink_info_req *req, + const char *version_name, + const char *version_value); #else @@ -923,6 +932,30 @@ devlink_info_serial_number_put(struct devlink_info_req *req, const char *sn) { return 0; } + +static inline int +devlink_info_version_fixed_put(struct devlink_info_req *req, + const char *version_name, + const char *version_value) +{ + return 0; +} + +static inline int +devlink_info_version_stored_put(struct devlink_info_req *req, + const char *version_name, + const char *version_value) +{ + return 0; +} + +static inline int +devlink_info_version_running_put(struct devlink_info_req *req, + 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 142710d45093..7fffd879c328 100644 --- a/include/uapi/linux/devlink.h +++ b/include/uapi/linux/devlink.h @@ -294,6 +294,11 @@ enum devlink_attr { DEVLINK_ATTR_INFO_DRIVER_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 f456f6aa3d40..e31b6d617837 100644 --- a/net/core/devlink.c +++ b/net/core/devlink.c @@ -3730,6 +3730,63 @@ int devlink_info_serial_number_put(struct devlink_info_req *req, const char *sn) } EXPORT_SYMBOL_GPL(devlink_info_serial_number_put); +static int devlink_info_version_put(struct devlink_info_req *req, int attr, + const char *version_name, + const char *version_value) +{ + struct nlattr *nest; + int err; + + nest = nla_nest_start(req->msg, attr); + 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; +} + +int devlink_info_version_fixed_put(struct devlink_info_req *req, + const char *version_name, + const char *version_value) +{ + return devlink_info_version_put(req, DEVLINK_ATTR_INFO_VERSION_FIXED, + version_name, version_value); +} +EXPORT_SYMBOL_GPL(devlink_info_version_fixed_put); + +int devlink_info_version_stored_put(struct devlink_info_req *req, + const char *version_name, + const char *version_value) +{ + return devlink_info_version_put(req, DEVLINK_ATTR_INFO_VERSION_STORED, + version_name, version_value); +} +EXPORT_SYMBOL_GPL(devlink_info_version_stored_put); + +int devlink_info_version_running_put(struct devlink_info_req *req, + const char *version_name, + const char *version_value) +{ + return devlink_info_version_put(req, DEVLINK_ATTR_INFO_VERSION_RUNNING, + version_name, version_value); +} +EXPORT_SYMBOL_GPL(devlink_info_version_running_put); + static int devlink_nl_info_fill(struct sk_buff *msg, struct devlink *devlink, enum devlink_command cmd, u32 portid, -- 2.19.2