Skip to content

Commit

Permalink
ocp: split ocp-fw-activation-history print codes
Browse files Browse the repository at this point in the history
Moved into print stdout and json files.

Signed-off-by: Tokunori Ikegami <[email protected]>
  • Loading branch information
ikegami-t committed Sep 27, 2024
1 parent 65ff8b8 commit a16c353
Show file tree
Hide file tree
Showing 7 changed files with 139 additions and 128 deletions.
2 changes: 1 addition & 1 deletion plugins/ocp/meson.build
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
sources += [
'plugins/ocp/ocp-utils.c',
'plugins/ocp/ocp-clear-features.c',
'plugins/ocp/ocp-fw-activation-history.c',
'plugins/ocp/ocp-hardware-component-log.c',
'plugins/ocp/ocp-print.c',
'plugins/ocp/ocp-print-stdout.c',
Expand All @@ -11,7 +12,6 @@ if json_c_dep.found()
sources += [
'plugins/ocp/ocp-nvme.c',
'plugins/ocp/ocp-smart-extended-log.c',
'plugins/ocp/ocp-fw-activation-history.c',
'plugins/ocp/ocp-telemetry-decode.c',
'plugins/ocp/ocp-print-json.c',
]
Expand Down
127 changes: 2 additions & 125 deletions plugins/ocp/ocp-fw-activation-history.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "nvme-print.h"

#include "ocp-utils.h"
#include "ocp-print.h"

static const unsigned char ocp_fw_activation_history_guid[16] = {
0x6D, 0x79, 0x9a, 0x76,
Expand All @@ -22,127 +23,6 @@ static const unsigned char ocp_fw_activation_history_guid[16] = {
0xac, 0xf3, 0x1c, 0xd1
};

struct __packed fw_activation_history_entry {
__u8 ver_num;
__u8 entry_length;
__u16 reserved1;
__u16 activation_count;
__u64 timestamp;
__u64 reserved2;
__u64 power_cycle_count;
char previous_fw[8];
char new_fw[8];
__u8 slot_number;
__u8 commit_action;
__u16 result;
__u8 reserved3[14];
};

struct __packed fw_activation_history {
__u8 log_id;
__u8 reserved1[3];
__u32 valid_entries;
struct fw_activation_history_entry entries[20];
__u8 reserved2[2790];
__u16 log_page_version;
__u64 log_page_guid[2];
};

static void ocp_fw_activation_history_normal(const struct fw_activation_history *fw_history)
{
printf("Firmware History Log:\n");

printf(" %-26s%d\n", "log identifier:", fw_history->log_id);
printf(" %-26s%d\n", "valid entries:", le32_to_cpu(fw_history->valid_entries));

printf(" entries:\n");

for (int index = 0; index < fw_history->valid_entries; index++) {
const struct fw_activation_history_entry *entry = &fw_history->entries[index];

printf(" entry[%d]:\n", le32_to_cpu(index));
printf(" %-22s%d\n", "version number:", entry->ver_num);
printf(" %-22s%d\n", "entry length:", entry->entry_length);
printf(" %-22s%d\n", "activation count:",
le16_to_cpu(entry->activation_count));
printf(" %-22s%"PRIu64"\n", "timestamp:",
(0x0000FFFFFFFFFFFF & le64_to_cpu(entry->timestamp)));
printf(" %-22s%"PRIu64"\n", "power cycle count:",
le64_to_cpu(entry->power_cycle_count));
printf(" %-22s%.*s\n", "previous firmware:", (int)sizeof(entry->previous_fw),
entry->previous_fw);
printf(" %-22s%.*s\n", "new firmware:", (int)sizeof(entry->new_fw),
entry->new_fw);
printf(" %-22s%d\n", "slot number:", entry->slot_number);
printf(" %-22s%d\n", "commit action type:", entry->commit_action);
printf(" %-22s%d\n", "result:", le16_to_cpu(entry->result));
}

printf(" %-26s%d\n", "log page version:",
le16_to_cpu(fw_history->log_page_version));

printf(" %-26s0x%"PRIx64"%"PRIx64"\n", "log page guid:",
le64_to_cpu(fw_history->log_page_guid[1]),
le64_to_cpu(fw_history->log_page_guid[0]));

printf("\n");
}

static void ocp_fw_activation_history_json(const struct fw_activation_history *fw_history)
{
struct json_object *root = json_create_object();

json_object_add_value_uint(root, "log identifier", fw_history->log_id);
json_object_add_value_uint(root, "valid entries", le32_to_cpu(fw_history->valid_entries));

struct json_object *entries = json_create_array();

for (int index = 0; index < fw_history->valid_entries; index++) {
const struct fw_activation_history_entry *entry = &fw_history->entries[index];
struct json_object *entry_obj = json_create_object();

json_object_add_value_uint(entry_obj, "version number", entry->ver_num);
json_object_add_value_uint(entry_obj, "entry length", entry->entry_length);
json_object_add_value_uint(entry_obj, "activation count",
le16_to_cpu(entry->activation_count));
json_object_add_value_uint64(entry_obj, "timestamp",
(0x0000FFFFFFFFFFFF & le64_to_cpu(entry->timestamp)));
json_object_add_value_uint(entry_obj, "power cycle count",
le64_to_cpu(entry->power_cycle_count));

struct json_object *fw = json_object_new_string_len(entry->previous_fw,
sizeof(entry->previous_fw));

json_object_add_value_object(entry_obj, "previous firmware", fw);

fw = json_object_new_string_len(entry->new_fw, sizeof(entry->new_fw));

json_object_add_value_object(entry_obj, "new firmware", fw);
json_object_add_value_uint(entry_obj, "slot number", entry->slot_number);
json_object_add_value_uint(entry_obj, "commit action type", entry->commit_action);
json_object_add_value_uint(entry_obj, "result", le16_to_cpu(entry->result));

json_array_add_value_object(entries, entry_obj);
}

json_object_add_value_array(root, "entries", entries);

json_object_add_value_uint(root, "log page version",
le16_to_cpu(fw_history->log_page_version));

char guid[2 * sizeof(fw_history->log_page_guid) + 3] = { 0 };

sprintf(guid, "0x%"PRIx64"%"PRIx64"",
le64_to_cpu(fw_history->log_page_guid[1]),
le64_to_cpu(fw_history->log_page_guid[0]));
json_object_add_value_string(root, "log page guid", guid);

json_print_object(root, NULL);
json_free_object(root);

printf("\n");
}

int ocp_fw_activation_history_log(int argc, char **argv, struct command *cmd,
struct plugin *plugin)
{
Expand Down Expand Up @@ -215,10 +95,7 @@ int ocp_fw_activation_history_log(int argc, char **argv, struct command *cmd,
return err;
}

if (print_flag == JSON)
ocp_fw_activation_history_json(&fw_history);
else if (print_flag == NORMAL)
ocp_fw_activation_history_normal(&fw_history);
ocp_fw_act_history(&fw_history, print_flag);
}

return err;
Expand Down
32 changes: 30 additions & 2 deletions plugins/ocp/ocp-fw-activation-history.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,42 @@
*
* Authors: [email protected]
*/
#include "common.h"
#include "linux/types.h"

#ifndef OCP_FIRMWARE_ACTIVATION_HISTORY_H
#define OCP_FIRMWARE_ACTIVATION_HISTORY_H

struct command;
struct plugin;

int ocp_fw_activation_history_log(int argc, char **argv,
struct command *cmd, struct plugin *plugin);
struct __packed fw_activation_history_entry {
__u8 ver_num;
__u8 entry_length;
__u16 reserved1;
__u16 activation_count;
__u64 timestamp;
__u64 reserved2;
__u64 power_cycle_count;
char previous_fw[8];
char new_fw[8];
__u8 slot_number;
__u8 commit_action;
__u16 result;
__u8 reserved3[14];
};

struct __packed fw_activation_history {
__u8 log_id;
__u8 reserved1[3];
__u32 valid_entries;
struct fw_activation_history_entry entries[20];
__u8 reserved2[2790];
__u16 log_page_version;
__u64 log_page_guid[2];
};

int ocp_fw_activation_history_log(int argc, char **argv, struct command *cmd,
struct plugin *plugin);

#endif
57 changes: 57 additions & 0 deletions plugins/ocp/ocp-print-json.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "nvme-print.h"
#include "ocp-print.h"
#include "ocp-hardware-component-log.h"
#include "ocp-fw-activation-history.h"

static void print_hwcomp_desc_json(struct hwcomp_desc_entry *e, struct json_object *r)
{
Expand Down Expand Up @@ -75,8 +76,64 @@ static void json_hwcomp_log(struct hwcomp_log *log, __u32 id, bool list)
json_print(r);
}

static void json_fw_activation_history(const struct fw_activation_history *fw_history)
{
struct json_object *root = json_create_object();

json_object_add_value_uint(root, "log identifier", fw_history->log_id);
json_object_add_value_uint(root, "valid entries", le32_to_cpu(fw_history->valid_entries));

struct json_object *entries = json_create_array();

for (int index = 0; index < fw_history->valid_entries; index++) {
const struct fw_activation_history_entry *entry = &fw_history->entries[index];
struct json_object *entry_obj = json_create_object();

json_object_add_value_uint(entry_obj, "version number", entry->ver_num);
json_object_add_value_uint(entry_obj, "entry length", entry->entry_length);
json_object_add_value_uint(entry_obj, "activation count",
le16_to_cpu(entry->activation_count));
json_object_add_value_uint64(entry_obj, "timestamp",
(0x0000FFFFFFFFFFFF & le64_to_cpu(entry->timestamp)));
json_object_add_value_uint(entry_obj, "power cycle count",
le64_to_cpu(entry->power_cycle_count));

struct json_object *fw = json_object_new_string_len(entry->previous_fw,
sizeof(entry->previous_fw));

json_object_add_value_object(entry_obj, "previous firmware", fw);

fw = json_object_new_string_len(entry->new_fw, sizeof(entry->new_fw));

json_object_add_value_object(entry_obj, "new firmware", fw);
json_object_add_value_uint(entry_obj, "slot number", entry->slot_number);
json_object_add_value_uint(entry_obj, "commit action type", entry->commit_action);
json_object_add_value_uint(entry_obj, "result", le16_to_cpu(entry->result));

json_array_add_value_object(entries, entry_obj);
}

json_object_add_value_array(root, "entries", entries);

json_object_add_value_uint(root, "log page version",
le16_to_cpu(fw_history->log_page_version));

char guid[2 * sizeof(fw_history->log_page_guid) + 3] = { 0 };

sprintf(guid, "0x%"PRIx64"%"PRIx64"",
le64_to_cpu(fw_history->log_page_guid[1]),
le64_to_cpu(fw_history->log_page_guid[0]));
json_object_add_value_string(root, "log page guid", guid);

json_print_object(root, NULL);
json_free_object(root);

printf("\n");
}

static struct ocp_print_ops json_print_ops = {
.hwcomp_log = json_hwcomp_log,
.fw_act_history = json_fw_activation_history,
};

struct ocp_print_ops *ocp_get_json_print_ops(nvme_print_flags_t flags)
Expand Down
42 changes: 42 additions & 0 deletions plugins/ocp/ocp-print-stdout.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "nvme-print.h"
#include "ocp-print.h"
#include "ocp-hardware-component-log.h"
#include "ocp-fw-activation-history.h"

static void print_hwcomp_desc(struct hwcomp_desc_entry *e, bool list, int num)
{
Expand Down Expand Up @@ -51,8 +52,49 @@ static void stdout_hwcomp_log(struct hwcomp_log *log, __u32 id, bool list)
}
}

static void stdout_fw_activation_history(const struct fw_activation_history *fw_history)
{
printf("Firmware History Log:\n");

printf(" %-26s%d\n", "log identifier:", fw_history->log_id);
printf(" %-26s%d\n", "valid entries:", le32_to_cpu(fw_history->valid_entries));

printf(" entries:\n");

for (int index = 0; index < fw_history->valid_entries; index++) {
const struct fw_activation_history_entry *entry = &fw_history->entries[index];

printf(" entry[%d]:\n", le32_to_cpu(index));
printf(" %-22s%d\n", "version number:", entry->ver_num);
printf(" %-22s%d\n", "entry length:", entry->entry_length);
printf(" %-22s%d\n", "activation count:",
le16_to_cpu(entry->activation_count));
printf(" %-22s%"PRIu64"\n", "timestamp:",
(0x0000FFFFFFFFFFFF & le64_to_cpu(entry->timestamp)));
printf(" %-22s%"PRIu64"\n", "power cycle count:",
le64_to_cpu(entry->power_cycle_count));
printf(" %-22s%.*s\n", "previous firmware:", (int)sizeof(entry->previous_fw),
entry->previous_fw);
printf(" %-22s%.*s\n", "new firmware:", (int)sizeof(entry->new_fw),
entry->new_fw);
printf(" %-22s%d\n", "slot number:", entry->slot_number);
printf(" %-22s%d\n", "commit action type:", entry->commit_action);
printf(" %-22s%d\n", "result:", le16_to_cpu(entry->result));
}

printf(" %-26s%d\n", "log page version:",
le16_to_cpu(fw_history->log_page_version));

printf(" %-26s0x%"PRIx64"%"PRIx64"\n", "log page guid:",
le64_to_cpu(fw_history->log_page_guid[1]),
le64_to_cpu(fw_history->log_page_guid[0]));

printf("\n");
}

static struct ocp_print_ops stdout_print_ops = {
.hwcomp_log = stdout_hwcomp_log,
.fw_act_history = stdout_fw_activation_history,
};

struct ocp_print_ops *ocp_get_stdout_print_ops(nvme_print_flags_t flags)
Expand Down
4 changes: 4 additions & 0 deletions plugins/ocp/ocp-print.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,7 @@ void ocp_show_hwcomp_log(struct hwcomp_log *log, __u32 id, bool list, nvme_print
ocp_print(hwcomp_log, flags, log, id, list);
}

void ocp_fw_act_history(const struct fw_activation_history *fw_history, nvme_print_flags_t flags)
{
ocp_print(fw_act_history, flags, fw_history);
}
3 changes: 3 additions & 0 deletions plugins/ocp/ocp-print.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
#define OCP_PRINT_H

#include "ocp-hardware-component-log.h"
#include "ocp-fw-activation-history.h"

struct ocp_print_ops {
void (*hwcomp_log)(struct hwcomp_log *log, __u32 id, bool list);
void (*fw_act_history)(const struct fw_activation_history *fw_history);
nvme_print_flags_t flags;
};

Expand All @@ -22,4 +24,5 @@ static inline struct ocp_print_ops *ocp_get_json_print_ops(nvme_print_flags_t fl
#endif /* !CONFIG_JSONC */

void ocp_show_hwcomp_log(struct hwcomp_log *log, __u32 id, bool list, nvme_print_flags_t flags);
void ocp_fw_act_history(const struct fw_activation_history *fw_history, nvme_print_flags_t flags);
#endif /* OCP_PRINT_H */

0 comments on commit a16c353

Please sign in to comment.