Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ocp: replace to use json_object_* macros to obj_* macros #2640

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions nvme-print-json.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,6 @@
#define array_add_obj json_array_add_value_object
#define array_add_str json_array_add_value_string

#define obj_add_array json_object_add_value_array
#define obj_add_int json_object_add_value_int
#define obj_add_obj json_object_add_value_object
#define obj_add_uint json_object_add_value_uint
#define obj_add_uint128 json_object_add_value_uint128
#define obj_add_uint64 json_object_add_value_uint64

static const uint8_t zero_uuid[16] = { 0 };
static struct print_ops json_print_ops;
static struct json_object *json_r;
Expand Down
7 changes: 7 additions & 0 deletions nvme-print.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ typedef struct nvme_effects_log_node {
#define STR_LEN 100

#define obj_add_str json_object_add_value_string
#define obj_add_int json_object_add_value_int
#define obj_add_uint json_object_add_value_uint
#define obj_add_uint64 json_object_add_value_uint64
#define obj_add_uint128 json_object_add_value_uint128
#define obj_add_obj json_object_add_value_object
#define obj_add_array json_object_add_value_array
#define obj_new_str_len json_object_new_string_len

void d(unsigned char *buf, int len, int width, int group);
void d_raw(unsigned char *buf, unsigned len);
Expand Down
2 changes: 1 addition & 1 deletion nvme.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "util/mem.h"
#include "util/argconfig.h"
#include "util/cleanup.h"
#include "util/types.h"

enum nvme_print_flags {
NORMAL = 0,
Expand Down Expand Up @@ -147,7 +148,6 @@ const char *nvme_select_to_string(int sel);

void d(unsigned char *buf, int len, int width, int group);
void d_raw(unsigned char *buf, unsigned len);
uint64_t int48_to_long(uint8_t *data);

int get_reg_size(int offset);
bool nvme_is_ctrl_reg(int offset);
Expand Down
3 changes: 2 additions & 1 deletion plugins/ocp/ocp-fw-activation-history.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*
* Authors: karl.dedow@solidigm.com
*/
#include <libnvme.h>
#include "common.h"
#include "linux/types.h"

Expand All @@ -18,7 +19,7 @@ struct __packed fw_activation_history_entry {
__u8 entry_length;
__le16 reserved1;
__le16 activation_count;
__le64 timestamp;
struct nvme_timestamp ts;
__le64 reserved2;
__le64 power_cycle_count;
char previous_fw[8];
Expand Down
746 changes: 338 additions & 408 deletions plugins/ocp/ocp-print-json.c

Large diffs are not rendered by default.

17 changes: 8 additions & 9 deletions plugins/ocp/ocp-print-stdout.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@ static void stdout_fw_activation_history(const struct fw_activation_history *fw_
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", "timestamp:", int48_to_long(entry->ts.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),
Expand Down Expand Up @@ -106,17 +105,17 @@ static void stdout_smart_extended_log(void *data, unsigned int version)
printf("SMART Cloud Attributes :-\n");

printf(" Physical media units written - %"PRIu64" %"PRIu64"\n",
(uint64_t)le64_to_cpu(*(uint64_t *)&log_data[SCAO_PMUW + 8] & 0xFFFFFFFFFFFFFFFF),
(uint64_t)le64_to_cpu(*(uint64_t *)&log_data[SCAO_PMUW] & 0xFFFFFFFFFFFFFFFF));
(uint64_t)le64_to_cpu(*(uint64_t *)&log_data[SCAO_PMUW + 8]),
(uint64_t)le64_to_cpu(*(uint64_t *)&log_data[SCAO_PMUW]));
printf(" Physical media units read - %"PRIu64" %"PRIu64"\n",
(uint64_t)le64_to_cpu(*(uint64_t *)&log_data[SCAO_PMUR + 8] & 0xFFFFFFFFFFFFFFFF),
(uint64_t)le64_to_cpu(*(uint64_t *)&log_data[SCAO_PMUR] & 0xFFFFFFFFFFFFFFFF));
(uint64_t)le64_to_cpu(*(uint64_t *)&log_data[SCAO_PMUR + 8]),
(uint64_t)le64_to_cpu(*(uint64_t *)&log_data[SCAO_PMUR]));
printf(" Bad user nand blocks - Raw %"PRIu64"\n",
(uint64_t)le64_to_cpu(*(uint64_t *)&log_data[SCAO_BUNBR] & 0x0000FFFFFFFFFFFF));
int48_to_long(&log_data[SCAO_BUNBR]));
printf(" Bad user nand blocks - Normalized %d\n",
(uint16_t)le16_to_cpu(*(uint16_t *)&log_data[SCAO_BUNBN]));
printf(" Bad system nand blocks - Raw %"PRIu64"\n",
(uint64_t)le64_to_cpu(*(uint64_t *)&log_data[SCAO_BSNBR] & 0x0000FFFFFFFFFFFF));
int48_to_long(&log_data[SCAO_BSNBR]));
printf(" Bad system nand blocks - Normalized %d\n",
(uint16_t)le16_to_cpu(*(uint16_t *)&log_data[SCAO_BSNBN]));
printf(" XOR recovery count %"PRIu64"\n",
Expand All @@ -132,7 +131,7 @@ static void stdout_smart_extended_log(void *data, unsigned int version)
printf(" System data percent used %d\n",
(__u8)log_data[SCAO_SDPU]);
printf(" Refresh counts %"PRIu64"\n",
(uint64_t)(le64_to_cpu(*(uint64_t *)&log_data[SCAO_RFSC]) & 0x00FFFFFFFFFFFFFF));
int56_to_long(&log_data[SCAO_RFSC]));
printf(" Max User data erase counts %"PRIu32"\n",
(uint32_t)le32_to_cpu(*(uint32_t *)&log_data[SCAO_MXUDEC]));
printf(" Min User data erase counts %"PRIu32"\n",
Expand Down
21 changes: 17 additions & 4 deletions util/types.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <string.h>
#include <locale.h>
#include <time.h>
#include <limits.h>

#include <ccan/endian/endian.h>

Expand Down Expand Up @@ -36,18 +37,30 @@ long double int128_to_double(__u8 *data)
return result;
}

uint64_t int48_to_long(__u8 *data)
static uint64_t int_to_long(int bits, const __u8 *data)
{
int i;
uint64_t result = 0;
int bytes = (bits + CHAR_BIT - 1) / CHAR_BIT;

for (i = 0; i < 6; i++) {
result *= 256;
result += data[5 - i];
for (i = 0; i < bytes; i++) {
result <<= CHAR_BIT;
result += data[bytes - 1 - i];
}

return result;
}

uint64_t int48_to_long(const __u8 *data)
{
return int_to_long(48, data);
}

uint64_t int56_to_long(const __u8 *data)
{
return int_to_long(56, data);
}

long double uint128_t_to_double(nvme_uint128_t data)
{
long double result = 0;
Expand Down
3 changes: 2 additions & 1 deletion util/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ typedef union nvme_uint128 nvme_uint128_t;

nvme_uint128_t le128_to_cpu(__u8 *data);
long double int128_to_double(__u8 *data);
uint64_t int48_to_long(__u8 *data);
uint64_t int48_to_long(const __u8 *data);
uint64_t int56_to_long(const __u8 *data);

char *uint128_t_to_string(nvme_uint128_t val);
char *uint128_t_to_l10n_string(nvme_uint128_t val);
Expand Down
Loading