Skip to content

Commit

Permalink
plugins/solidigm: Added OCP 2.0 vs-drive-info command.
Browse files Browse the repository at this point in the history
Signed-off-by: Leonardo da Cunha <[email protected]>
  • Loading branch information
lgdacunh authored and igaw committed Dec 11, 2023
1 parent b60d1f6 commit 10b742e
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 1 deletion.
1 change: 1 addition & 0 deletions plugins/solidigm/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ sources += [
'plugins/solidigm/solidigm-internal-logs.c',
'plugins/solidigm/solidigm-market-log.c',
'plugins/solidigm/solidigm-temp-stats.c',
'plugins/solidigm/solidigm-get-drive-info.c',
]
subdir('solidigm-telemetry')

79 changes: 79 additions & 0 deletions plugins/solidigm/solidigm-get-drive-info.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* Copyright (c) 2023 Solidigm.
*
* Authors: [email protected]
*/

#include <errno.h>
#include "nvme-print.h"
#include "nvme-wrap.h"
#include "common.h"

int sldgm_get_drive_info(int argc, char **argv, struct command *cmd, struct plugin *plugin)
{
_cleanup_nvme_dev_ struct nvme_dev *dev = NULL;
const char *desc = "Get drive HW information";
const char *FTL_unit_size_str = "FTL_unit_size";
char *output_format = "normal";
enum nvme_print_flags flags;
nvme_root_t r;
nvme_ctrl_t c;
nvme_ns_t n;
struct nvme_id_ns ns = { 0 };
__u8 flbaf_inUse;
__u16 lba_size;
__u16 ftl_unit_size;
int err;

OPT_ARGS(opts) = {
OPT_FMT("output-format", 'o', &output_format, "normal|json"),
OPT_END()
};

err = parse_and_open(&dev, argc, argv, desc, opts);
if (err)
return err;

err = validate_output_format(output_format, &flags);
if ((err < 0) || !(flags == NORMAL || flags == JSON)) {
nvme_show_error("Invalid output format");
return err;
}

r = nvme_scan(NULL);
c = nvme_scan_ctrl(r, dev->name);
n = c ? nvme_ctrl_first_ns(c) : nvme_scan_namespace(dev->name);
if (!n) {
nvme_show_error("solidigm-vs-drive-info: drive missing namespace");
return -EINVAL;
}

err = nvme_ns_identify(n, &ns);
if (err) {
nvme_show_error("identify namespace: %s", nvme_strerror(errno));
return err;
}

if (!(ns.nsfeat & 0x10)) {
nvme_show_error("solidigm-vs-drive-info: performance options not available");
return -EINVAL;
}

nvme_id_ns_flbas_to_lbaf_inuse(ns.flbas, &flbaf_inUse);
lba_size = 1 << ns.lbaf[flbaf_inUse].ds;
ftl_unit_size = (le16_to_cpu(ns.npwg) + 1) * lba_size / 1024;

if (flags == JSON) {
struct json_object *root = json_create_object();

json_object_add_value_int(root, FTL_unit_size_str, ftl_unit_size);
json_print_object(root, NULL);
printf("\n");
json_free_object(root);
} else {
printf("%s: %d\n", FTL_unit_size_str, ftl_unit_size);
}

return err;
}
8 changes: 8 additions & 0 deletions plugins/solidigm/solidigm-get-drive-info.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/* SPDX-License-Identifier: GPL-2.0-or-later */
/*
* Copyright (c) 2023 Solidigm.
*
* Author: [email protected]
*/

int sldgm_get_drive_info(int argc, char **argv, struct command *cmd, struct plugin *plugin);
6 changes: 6 additions & 0 deletions plugins/solidigm/solidigm-nvme.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "solidigm-log-page-dir.h"
#include "solidigm-market-log.h"
#include "solidigm-temp-stats.h"
#include "solidigm-get-drive-info.h"

#include "plugins/ocp/ocp-clear-features.h"
#include "plugins/ocp/ocp-smart-extended-log.h"
Expand Down Expand Up @@ -94,3 +95,8 @@ static int get_temp_stats_log(int argc, char **argv, struct command *cmd, struct
{
return sldgm_get_temp_stats_log(argc, argv, cmd, plugin);
}

static int get_drive_info(int argc, char **argv, struct command *cmd, struct plugin *plugin)
{
return sldgm_get_drive_info(argc, argv, cmd, plugin);
}
3 changes: 2 additions & 1 deletion plugins/solidigm/solidigm-nvme.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

#include "cmd.h"

#define SOLIDIGM_PLUGIN_VERSION "0.18"
#define SOLIDIGM_PLUGIN_VERSION "0.19"

PLUGIN(NAME("solidigm", "Solidigm vendor specific extensions", SOLIDIGM_PLUGIN_VERSION),
COMMAND_LIST(
Expand All @@ -30,6 +30,7 @@ PLUGIN(NAME("solidigm", "Solidigm vendor specific extensions", SOLIDIGM_PLUGIN_V
ENTRY("vs-fw-activate-history", "Get firmware activation history log (redirects to ocp plug-in)", fw_activation_history)
ENTRY("log-page-directory", "Retrieve log page directory", get_log_page_directory_log)
ENTRY("temp-stats", "Retrieve Temperature Statistics log", get_temp_stats_log)
ENTRY("vs-drive-info", "Retrieve drive information", get_drive_info)
)
);

Expand Down

0 comments on commit 10b742e

Please sign in to comment.