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=-8.5 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_MUTT 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 0ED3EC282D7 for ; Wed, 30 Jan 2019 23:04:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A6B13218AF for ; Wed, 30 Jan 2019 23:04:21 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=resnulli-us.20150623.gappssmtp.com header.i=@resnulli-us.20150623.gappssmtp.com header.b="rZIfHAqJ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727165AbfA3XEU (ORCPT ); Wed, 30 Jan 2019 18:04:20 -0500 Received: from mail-wm1-f66.google.com ([209.85.128.66]:37284 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726198AbfA3XEU (ORCPT ); Wed, 30 Jan 2019 18:04:20 -0500 Received: by mail-wm1-f66.google.com with SMTP id g67so575752wmd.2 for ; Wed, 30 Jan 2019 15:04:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=resnulli-us.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=JFO40iBoF4xBM8eWlClAWhqX6qzel1Exy6gTSNbz120=; b=rZIfHAqJ/3oFzpVydqMQnsmlTIdga6dqP7qY+HSh2z1GCYVBZmAfs4OujPGCsTDcPW 9FzjeQd5C+SLIeaTHLqHaW17DtffxhfULn9nffD3rzQkG4qFTA6DS/QE/4Y8Ohm89iJK h4E013FtlL8eKnwJW7h4ga7xpcw0yqZdenxw0dzTexd0NlcwnS2btE0jvvutfH2wOwB3 vqWbObbjBVIebCeggmfO5mP01/r+J8XOUUG/f3qp1oxX8qzP/Pxm137ATUWWvxVK5Jt7 JNaCYB07HAcMBbEyVv7KK8jt7H1oPWuaxiP6T8KRRKYUyFEjPHNoJd42FGiAvEFCDybZ cHmw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=JFO40iBoF4xBM8eWlClAWhqX6qzel1Exy6gTSNbz120=; b=jHiwVFHCIXtrt4/UukExpVU/MGMX4E7RXIsmy60+a13ienWbcrUGfgyTJfbD4vdeRb ZYDCRY/YmCqaDp+AVOrQ9GZo2c4BtvQ54BOliI3YaH19LTV+KRg0kpmlRRK5eFQyNzKh vgX7rCqpvQhww2QvmK5cERBUP+Vrk99o7snfGdCcJiGWW2MYMZcnJoMT1krfsTiu6+Re 75ztWWU5RnFF7XSM31++eVhHfwtuHLmGE1oQNYCj5KC2akkChKlfGJzRx5ceUbh9IBvA Swequdw6U/eidFiREk/+chf5K50miA8Nks3zVK+jI4qZmO74na3fwE6h+P2FlY73bchx ktqg== X-Gm-Message-State: AJcUuke6L4DhAlwqXSzxa+yJKmb/Lx9CzSHI53MHFuXc6jMUZ7VAsn0q 6OwXkeuREipMBM1f2QKnLwizbqgXsfg= X-Google-Smtp-Source: ALg8bN42rhOgg7quyqt7uw9wvBW6ZzXLYeuKCMlddLZg/07rySXX99UUl9fjjUQw8mJXUD3TYjtDGw== X-Received: by 2002:a1c:b189:: with SMTP id a131mr27933250wmf.38.1548885797582; Wed, 30 Jan 2019 14:03:17 -0800 (PST) Received: from localhost (jirka.pirko.cz. [84.16.102.26]) by smtp.gmail.com with ESMTPSA id k128sm5263440wmd.37.2019.01.30.14.03.16 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 30 Jan 2019 14:03:17 -0800 (PST) Date: Wed, 30 Jan 2019 22:54:16 +0100 From: Jiri Pirko To: Jakub Kicinski Cc: davem@davemloft.net, netdev@vger.kernel.org, oss-drivers@netronome.com, andrew@lunn.ch, f.fainelli@gmail.com, mkubecek@suse.cz, eugenem@fb.com, jonathan.lemon@gmail.com Subject: Re: [PATCH net-next v2 2/7] devlink: add version reporting to devlink info API Message-ID: <20190130215416.GB349@nanopsycho.orion> References: <20190130190513.25718-1-jakub.kicinski@netronome.com> <20190130190513.25718-3-jakub.kicinski@netronome.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190130190513.25718-3-jakub.kicinski@netronome.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Wed, Jan 30, 2019 at 08:05:08PM CET, jakub.kicinski@netronome.com wrote: >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 5ef3570a3859..ec72638aa47f 100644 >--- a/include/net/devlink.h >+++ b/include/net/devlink.h >@@ -428,6 +428,12 @@ enum devlink_param_wol_types { > .validate = _validate, \ > } > >+enum devlink_version_type { devlink_info_version_type >+ DEVLINK_VERSION_FIXED, DEVLINK_INFO_VERSION_* >+ DEVLINK_VERSION_STORED, >+ DEVLINK_VERSION_RUNNING, >+}; >+ > struct devlink_region; > struct devlink_info_req; > >@@ -614,6 +620,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 > >@@ -923,6 +933,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 fd089baa7c50..a61b87c73c3f 100644 >--- a/include/uapi/linux/devlink.h >+++ b/include/uapi/linux/devlink.h >@@ -294,6 +294,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 1b941493fdff..e2027d3a5e40 100644 >--- a/net/core/devlink.c >+++ b/net/core/devlink.c >@@ -3732,6 +3732,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, devlink_info_version_put() >+ 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, I think it would be perhaps nice to have a set of wrappers: devlink_info_version_fixed_put() devlink_info_version_stored_put() devlink_info_version_running_put() And then have static devlink_info_version_put() which accepts ATTR value directly. Then you can avoid the intermediate enum, array and checks. >+ }; >+ 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 >