From: Dave Jiang <dave.jiang@intel.com>
To: Vishal Verma <vishal.l.verma@intel.com>, linux-cxl@vger.kernel.org
Cc: nvdimm@lists.linux.dev,
Alison Schofield <alison.schofield@intel.com>,
Ira Weiny <ira.weiny@intel.com>,
Dan Williams <dan.j.williams@intel.com>
Subject: Re: [PATCH ndctl 2/5] cxl/list: print firmware info in memdev listings
Date: Fri, 19 May 2023 11:21:55 -0700 [thread overview]
Message-ID: <3cd9e4d0-98be-4d12-63e8-8730182cf7a5@intel.com> (raw)
In-Reply-To: <20230405-vv-fw_update-v1-2-722a7a5baea3@intel.com>
On 4/21/23 8:10 PM, Vishal Verma wrote:
> Add libcxl APIs to send a 'Get Firmware Info' mailbox command, and
> accessors for its data fields. Add a json representation of this data,
> and add an option to cxl-list to display it under memdev listings.
>
> Cc: Dan Williams <dan.j.williams@intel.com>
> Signed-off-by: Vishal Verma <vishal.l.verma@intel.com>
Reviewed-by: Dave Jiang <dave.jiang@intel.com>
Just a small nit below.
> ---
> cxl/lib/private.h | 21 +++++++++++++
> cxl/lib/libcxl.c | 90 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
> cxl/filter.h | 3 ++
> cxl/libcxl.h | 7 +++++
> cxl/json.c | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++
> cxl/list.c | 3 ++
> cxl/lib/libcxl.sym | 6 ++++
> 7 files changed, 214 insertions(+)
>
> diff --git a/cxl/lib/private.h b/cxl/lib/private.h
> index d648992..590d719 100644
> --- a/cxl/lib/private.h
> +++ b/cxl/lib/private.h
> @@ -9,6 +9,7 @@
> #include <ccan/endian/endian.h>
> #include <ccan/short_types/short_types.h>
> #include <util/size.h>
> +#include <util/bitmap.h>
>
> #define CXL_EXPORT __attribute__ ((visibility("default")))
>
> @@ -233,6 +234,26 @@ struct cxl_cmd_get_health_info {
> le32 pmem_errors;
> } __attribute__((packed));
>
> +/* CXL 3.0 8.2.9.3.1 Get Firmware Info */
> +struct cxl_cmd_get_fw_info {
> + u8 num_slots;
> + u8 slot_info;
> + u8 activation_cap;
> + u8 reserved[13];
> + char slot_1_revision[0x10];
> + char slot_2_revision[0x10];
> + char slot_3_revision[0x10];
> + char slot_4_revision[0x10];
> +} __attribute__((packed));
> +
> +#define CXL_FW_INFO_CUR_SLOT_MASK GENMASK(2, 0)
> +#define CXL_FW_INFO_NEXT_SLOT_MASK GENMASK(5, 3)
> +#define CXL_FW_INFO_NEXT_SLOT_SHIFT (3)
> +#define CXL_FW_INFO_HAS_LIVE_ACTIVATE BIT(0)
> +
> +#define CXL_FW_VERSION_STR_LEN 16
> +#define CXL_FW_MAX_SLOTS 4
> +
> /* CXL 3.0 8.2.9.8.3.2 Get Alert Configuration */
> struct cxl_cmd_get_alert_config {
> u8 valid_alerts;
> diff --git a/cxl/lib/libcxl.c b/cxl/lib/libcxl.c
> index 59e5bdb..75490fd 100644
> --- a/cxl/lib/libcxl.c
> +++ b/cxl/lib/libcxl.c
> @@ -3917,6 +3917,96 @@ CXL_EXPORT struct cxl_cmd *cxl_cmd_new_set_partition(struct cxl_memdev *memdev,
> return cmd;
> }
>
> +CXL_EXPORT struct cxl_cmd *cxl_cmd_new_get_fw_info(struct cxl_memdev *memdev)
> +{
> + return cxl_cmd_new_generic(memdev, CXL_MEM_COMMAND_ID_GET_FW_INFO);
> +}
> +
> +static struct cxl_cmd_get_fw_info *cmd_to_get_fw_info(struct cxl_cmd *cmd)
> +{
> + if (cxl_cmd_validate_status(cmd, CXL_MEM_COMMAND_ID_GET_FW_INFO))
> + return NULL;
> +
> + return cmd->output_payload;
> +}
> +
> +CXL_EXPORT unsigned int cxl_cmd_fw_info_get_num_slots(struct cxl_cmd *cmd)
> +{
> + struct cxl_cmd_get_fw_info *c = cmd_to_get_fw_info(cmd);
> +
> + if (!c)
> + return 0;
> +
> + return c->num_slots;
> +}
> +
> +CXL_EXPORT unsigned int cxl_cmd_fw_info_get_active_slot(struct cxl_cmd *cmd)
> +{
> + struct cxl_cmd_get_fw_info *c = cmd_to_get_fw_info(cmd);
> +
> + if (!c)
> + return 0;
> +
> + return c->slot_info & CXL_FW_INFO_CUR_SLOT_MASK;
> +}
> +
> +CXL_EXPORT unsigned int cxl_cmd_fw_info_get_staged_slot(struct cxl_cmd *cmd)
> +{
> + struct cxl_cmd_get_fw_info *c = cmd_to_get_fw_info(cmd);
> +
> + if (!c)
> + return 0;
> +
> + return (c->slot_info & CXL_FW_INFO_NEXT_SLOT_MASK) >>
> + CXL_FW_INFO_NEXT_SLOT_SHIFT;
> +}
> +
> +CXL_EXPORT bool cxl_cmd_fw_info_get_online_activate_capable(struct cxl_cmd *cmd)
> +{
> + struct cxl_cmd_get_fw_info *c = cmd_to_get_fw_info(cmd);
> +
> + if (!c)
> + return false;
> +
> + return !!(c->activation_cap & CXL_FW_INFO_HAS_LIVE_ACTIVATE);
> +}
> +
> +CXL_EXPORT int cxl_cmd_fw_info_get_fw_ver(struct cxl_cmd *cmd, int slot,
> + char *buf, unsigned int len)
> +{
> + struct cxl_cmd_get_fw_info *c = cmd_to_get_fw_info(cmd);
> + char *fw_ver;
> +
> + if (!c)
> + return -ENXIO;
> + if (!len)
> + return -EINVAL;
> +
> + switch(slot) {
> + case 1:
> + fw_ver = &c->slot_1_revision[0];
Just a nit. You can just do
fw_ver = c->slot_1_revision;
DJ
> + break;
> + case 2:
> + fw_ver = &c->slot_2_revision[0];
> + break;
> + case 3:
> + fw_ver = &c->slot_3_revision[0];
> + break;
> + case 4:
> + fw_ver = &c->slot_4_revision[0];
> + break;
> + default:
> + return -EINVAL;
> + }
> +
> + if (fw_ver[0] == 0)
> + return -ENOENT;
> +
> + memcpy(buf, fw_ver, min(len, (unsigned int)CXL_FW_VERSION_STR_LEN));
> +
> + return 0;
> +}
> +
> CXL_EXPORT int cxl_cmd_submit(struct cxl_cmd *cmd)
> {
> struct cxl_memdev *memdev = cmd->memdev;
> diff --git a/cxl/filter.h b/cxl/filter.h
> index 595cde7..3f65990 100644
> --- a/cxl/filter.h
> +++ b/cxl/filter.h
> @@ -27,6 +27,7 @@ struct cxl_filter_params {
> bool human;
> bool health;
> bool partition;
> + bool fw;
> bool alert_config;
> bool dax;
> int verbose;
> @@ -81,6 +82,8 @@ static inline unsigned long cxl_filter_to_flags(struct cxl_filter_params *param)
> flags |= UTIL_JSON_TARGETS;
> if (param->partition)
> flags |= UTIL_JSON_PARTITION;
> + if (param->fw)
> + flags |= UTIL_JSON_FIRMWARE;
> if (param->alert_config)
> flags |= UTIL_JSON_ALERT_CONFIG;
> if (param->dax)
> diff --git a/cxl/libcxl.h b/cxl/libcxl.h
> index 54d9f10..99e1b76 100644
> --- a/cxl/libcxl.h
> +++ b/cxl/libcxl.h
> @@ -68,6 +68,13 @@ int cxl_memdev_read_label(struct cxl_memdev *memdev, void *buf, size_t length,
> size_t offset);
> int cxl_memdev_write_label(struct cxl_memdev *memdev, void *buf, size_t length,
> size_t offset);
> +struct cxl_cmd *cxl_cmd_new_get_fw_info(struct cxl_memdev *memdev);
> +unsigned int cxl_cmd_fw_info_get_num_slots(struct cxl_cmd *cmd);
> +unsigned int cxl_cmd_fw_info_get_active_slot(struct cxl_cmd *cmd);
> +unsigned int cxl_cmd_fw_info_get_staged_slot(struct cxl_cmd *cmd);
> +bool cxl_cmd_fw_info_get_online_activate_capable(struct cxl_cmd *cmd);
> +int cxl_cmd_fw_info_get_fw_ver(struct cxl_cmd *cmd, int slot, char *buf,
> + unsigned int len);
>
> #define cxl_memdev_foreach(ctx, memdev) \
> for (memdev = cxl_memdev_get_first(ctx); \
> diff --git a/cxl/json.c b/cxl/json.c
> index e87bdd4..e6bb061 100644
> --- a/cxl/json.c
> +++ b/cxl/json.c
> @@ -12,6 +12,84 @@
> #include "json.h"
> #include "../daxctl/json.h"
>
> +#define CXL_FW_VERSION_STR_LEN 16
> +#define CXL_FW_MAX_SLOTS 4
> +
> +static struct json_object *util_cxl_memdev_fw_to_json(
> + struct cxl_memdev *memdev, unsigned long flags)
> +{
> + struct json_object *jobj;
> + struct json_object *jfw;
> + u32 field, num_slots;
> + struct cxl_cmd *cmd;
> + int rc, i;
> +
> + jfw = json_object_new_object();
> + if (!jfw)
> + return NULL;
> + if (!memdev)
> + goto err_jobj;
> +
> + cmd = cxl_cmd_new_get_fw_info(memdev);
> + if (!cmd)
> + goto err_jobj;
> +
> + rc = cxl_cmd_submit(cmd);
> + if (rc < 0)
> + goto err_cmd;
> + rc = cxl_cmd_get_mbox_status(cmd);
> + if (rc != 0)
> + goto err_cmd;
> +
> + /* fw_info fields */
> + num_slots = cxl_cmd_fw_info_get_num_slots(cmd);
> + jobj = json_object_new_int(num_slots);
> + if (jobj)
> + json_object_object_add(jfw, "num_slots", jobj);
> +
> + field = cxl_cmd_fw_info_get_active_slot(cmd);
> + jobj = json_object_new_int(field);
> + if (jobj)
> + json_object_object_add(jfw, "active_slot", jobj);
> +
> + field = cxl_cmd_fw_info_get_staged_slot(cmd);
> + if (field > 0 && field <= num_slots) {
> + jobj = json_object_new_int(field);
> + if (jobj)
> + json_object_object_add(jfw, "staged_slot", jobj);
> + }
> +
> + rc = cxl_cmd_fw_info_get_online_activate_capable(cmd);
> + jobj = json_object_new_boolean(rc);
> + if (jobj)
> + json_object_object_add(jfw, "online_activate_capable", jobj);
> +
> + for (i = 1; i <= CXL_FW_MAX_SLOTS; i++) {
> + char fw_ver[CXL_FW_VERSION_STR_LEN + 1];
> + char jkey[16];
> +
> + rc = cxl_cmd_fw_info_get_fw_ver(cmd, i, fw_ver,
> + CXL_FW_VERSION_STR_LEN);
> + if (rc)
> + continue;
> + fw_ver[CXL_FW_VERSION_STR_LEN] = 0;
> + snprintf(jkey, 16, "slot_%d_version", i);
> + jobj = json_object_new_string(fw_ver);
> + if (jobj)
> + json_object_object_add(jfw, jkey, jobj);
> + }
> +
> + cxl_cmd_unref(cmd);
> + return jfw;
> +
> +err_cmd:
> + cxl_cmd_unref(cmd);
> +err_jobj:
> + json_object_put(jfw);
> + return NULL;
> +
> +}
> +
> static struct json_object *util_cxl_memdev_health_to_json(
> struct cxl_memdev *memdev, unsigned long flags)
> {
> @@ -552,6 +630,12 @@ struct json_object *util_cxl_memdev_to_json(struct cxl_memdev *memdev,
> json_object_object_add(jdev, "partition_info", jobj);
> }
>
> + if (flags & UTIL_JSON_FIRMWARE) {
> + jobj = util_cxl_memdev_fw_to_json(memdev, flags);
> + if (jobj)
> + json_object_object_add(jdev, "firmware", jobj);
> + }
> +
> json_object_set_userdata(jdev, memdev, NULL);
> return jdev;
> }
> diff --git a/cxl/list.c b/cxl/list.c
> index c01154e..93ba51e 100644
> --- a/cxl/list.c
> +++ b/cxl/list.c
> @@ -53,6 +53,8 @@ static const struct option options[] = {
> "include memory device health information"),
> OPT_BOOLEAN('I', "partition", ¶m.partition,
> "include memory device partition information"),
> + OPT_BOOLEAN('F', "firmware", ¶m.fw,
> + "include memory device firmware information"),
> OPT_BOOLEAN('A', "alert-config", ¶m.alert_config,
> "include alert configuration information"),
> OPT_INCR('v', "verbose", ¶m.verbose, "increase output detail"),
> @@ -116,6 +118,7 @@ int cmd_list(int argc, const char **argv, struct cxl_ctx *ctx)
> case 3:
> param.health = true;
> param.partition = true;
> + param.fw = true;
> param.alert_config = true;
> param.dax = true;
> /* fallthrough */
> diff --git a/cxl/lib/libcxl.sym b/cxl/lib/libcxl.sym
> index 1c6177c..16a8671 100644
> --- a/cxl/lib/libcxl.sym
> +++ b/cxl/lib/libcxl.sym
> @@ -248,4 +248,10 @@ global:
> cxl_region_get_mode;
> cxl_decoder_create_ram_region;
> cxl_region_get_daxctl_region;
> + cxl_cmd_new_get_fw_info;
> + cxl_cmd_fw_info_get_num_slots;
> + cxl_cmd_fw_info_get_active_slot;
> + cxl_cmd_fw_info_get_staged_slot;
> + cxl_cmd_fw_info_get_online_activate_capable;
> + cxl_cmd_fw_info_get_fw_ver;
> } LIBCXL_4;
>
next prev parent reply other threads:[~2023-05-19 18:21 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-22 3:09 [PATCH ndctl 0/5] cxl: firmware update support for libcxl and cxl-cli Vishal Verma
2023-04-22 3:09 ` [PATCH ndctl 1/5] cxl/memdev.c: allow filtering memdevs by bus Vishal Verma
2023-05-19 17:57 ` Dave Jiang
2023-04-22 3:10 ` [PATCH ndctl 2/5] cxl/list: print firmware info in memdev listings Vishal Verma
2023-05-19 18:21 ` Dave Jiang [this message]
2023-04-22 3:10 ` [PATCH ndctl 3/5] cxl/fw_loader: add APIs to get current state of the FW loader mechanism Vishal Verma
2023-05-19 18:49 ` Dave Jiang
2023-04-22 3:10 ` [PATCH ndctl 4/5] cxl: add an update-firmware command Vishal Verma
2023-04-24 23:14 ` Verma, Vishal L
2023-05-19 18:57 ` Dave Jiang
2023-04-22 3:10 ` [PATCH ndctl 5/5] test/cxl-update-firmware: add a unit test for firmware update Vishal Verma
2023-05-19 19:00 ` Dave Jiang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=3cd9e4d0-98be-4d12-63e8-8730182cf7a5@intel.com \
--to=dave.jiang@intel.com \
--cc=alison.schofield@intel.com \
--cc=dan.j.williams@intel.com \
--cc=ira.weiny@intel.com \
--cc=linux-cxl@vger.kernel.org \
--cc=nvdimm@lists.linux.dev \
--cc=vishal.l.verma@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox