From: Tokunori Ikegami Date: Sat, 3 Jun 2023 12:59:21 +0000 (+0900) Subject: plugins/memblaze: Fix memblaze-nvme.c linux kernel check patch errors and warnings X-Git-Tag: v2.5~45 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=25a1ecf0a14ca52df9c76e52929bc6320000b5f3;p=users%2Fsagi%2Fnvme-cli.git plugins/memblaze: Fix memblaze-nvme.c linux kernel check patch errors and warnings Note: Still the remaining warning messages are not fixed as same with nvme.c. WARNING: quoted string split across lines + "This performs a selective firmware download, which allows the user to " + "select which firmware binary to update for 9200 devices. This requires a power cycle once the " WARNING: quoted string split across lines + "select which firmware binary to update for 9200 devices. This requires a power cycle once the " + "update completes. The options available are:\n\n" Signed-off-by: Tokunori Ikegami --- diff --git a/plugins/memblaze/memblaze-nvme.c b/plugins/memblaze/memblaze-nvme.c index 4dc06da8..795c47d5 100644 --- a/plugins/memblaze/memblaze-nvme.c +++ b/plugins/memblaze/memblaze-nvme.c @@ -19,10 +19,10 @@ #include "memblaze-utils.h" enum { - // feature id + /* feature id */ MB_FEAT_POWER_MGMT = 0x02, MB_FEAT_HIGH_LATENCY = 0xE1, - // log id + /* log id */ GLP_ID_VU_GET_READ_LATENCY_HISTOGRAM = 0xC1, GLP_ID_VU_GET_WRITE_LATENCY_HISTOGRAM = 0xC2, GLP_ID_VU_GET_HIGH_LATENCY_LOG = 0xC3, @@ -32,9 +32,9 @@ enum { #define LOG_PAGE_SIZE (0x1000) #define DO_PRINT_FLAG (1) #define NOT_PRINT_FLAG (0) -#define FID_C1_LOG_FILENAME "log_c1.csv" -#define FID_C2_LOG_FILENAME "log_c2.csv" -#define FID_C3_LOG_FILENAME "log_c3.csv" +#define FID_C1_LOG_FILENAME "log_c1.csv" +#define FID_C2_LOG_FILENAME "log_c2.csv" +#define FID_C3_LOG_FILENAME "log_c3.csv" /* * Return -1 if @fw1 < @fw2 @@ -64,16 +64,16 @@ static int compare_fw_version(const char *fw1, const char *fw2) * 1: new intel format * 0: old memblaze format * *******************************************************/ -#define MEMBLAZE_FORMAT (0) +#define MEMBLAZE_FORMAT (0) #define INTEL_FORMAT (1) -// 2.13 = papaya +/* 2.13 = papaya */ #define IS_PAPAYA(str) (!strcmp(str, "2.13")) -// 2.83 = raisin +/* 2.83 = raisin */ #define IS_RAISIN(str) (!strcmp(str, "2.83")) -// 2.94 = kumquat -#define IS_KUMQUAT(str) (!strcmp(str, "2.94")) -// 0.60 = loquat +/* 2.94 = kumquat */ +#define IS_KUMQUAT(str) (!strcmp(str, "2.94")) +/* 0.60 = loquat */ #define IS_LOQUAT(str) (!strcmp(str, "0.60")) #define STR_VER_SIZE (5) @@ -81,14 +81,12 @@ static int compare_fw_version(const char *fw1, const char *fw2) int getlogpage_format_type(char *model_name) { int logpage_format_type = INTEL_FORMAT; - const char *boundary_model_name1 = "P"; // MEMBLAZE P7936DT0640M00 - const char *boundary_model_name2 = "P5920"; // Use INTEL_FORMAT from Raisin P5920. - if (0 == strncmp(model_name, boundary_model_name1, strlen(boundary_model_name1))) - { + const char *boundary_model_name1 = "P"; /* MEMBLAZE P7936DT0640M00 */ + const char *boundary_model_name2 = "P5920"; /* Use INTEL_FORMAT from Raisin P5920. */ + + if (!strncmp(model_name, boundary_model_name1, strlen(boundary_model_name1))) { if (strncmp(model_name, boundary_model_name2, strlen(boundary_model_name2)) < 0) - { logpage_format_type = MEMBLAZE_FORMAT; - } } return logpage_format_type; } @@ -96,6 +94,7 @@ int getlogpage_format_type(char *model_name) static __u32 item_id_2_u32(struct nvme_memblaze_smart_log_item *item) { __le32 __id = 0; + memcpy(&__id, item->id, 3); return le32_to_cpu(__id); } @@ -103,6 +102,7 @@ static __u32 item_id_2_u32(struct nvme_memblaze_smart_log_item *item) static __u64 raw_2_u64(const __u8 *buf, size_t len) { __le64 val = 0; + memcpy(&val, buf, len); return le64_to_cpu(val); } @@ -160,7 +160,7 @@ static void show_memblaze_smart_log_new(struct nvme_memblaze_smart_log *s, get_memblaze_new_smart_info(smart, RAISIN_SI_VD_THERMAL_THROTTLE_STATUS, nm, raw); printf("%-32s: %3d%% %u%%%s%"PRIu64"\n", "thermal_throttle_status", *nm, - *raw, ", cnt: ", int48_to_long(raw+1)); + *raw, ", cnt: ", int48_to_long(raw+1)); get_memblaze_new_smart_info(smart, RAISIN_SI_VD_RETRY_BUFF_OVERFLOW_COUNT, nm, raw); printf("%-32s: %3d%% %"PRIu64"\n", "retry_buffer_overflow_count", *nm, int48_to_long(raw)); @@ -182,15 +182,15 @@ static void show_memblaze_smart_log_new(struct nvme_memblaze_smart_log *s, get_memblaze_new_smart_info(smart, RAISIN_SI_VD_TEMPT_SINCE_BORN, nm, raw); printf("%-32s: %3d%% %s%u%s%u%s%u\n", "tempt_since_born", *nm, - "max: ", *(__u16 *)raw, ", min: ", *(__u16 *)(raw+2), ", curr: ", *(__u16 *)(raw+4)); + "max: ", *(__u16 *)raw, ", min: ", *(__u16 *)(raw+2), ", curr: ", *(__u16 *)(raw+4)); get_memblaze_new_smart_info(smart, RAISIN_SI_VD_POWER_CONSUMPTION, nm, raw); printf("%-32s: %3d%% %s%u%s%u%s%u\n", "power_consumption", *nm, - "max: ", *(__u16 *)raw, ", min: ", *(__u16 *)(raw+2), ", curr: ", *(__u16 *)(raw+4)); + "max: ", *(__u16 *)raw, ", min: ", *(__u16 *)(raw+2), ", curr: ", *(__u16 *)(raw+4)); get_memblaze_new_smart_info(smart, RAISIN_SI_VD_TEMPT_SINCE_BOOTUP, nm, raw); printf("%-32s: %3d%% %s%u%s%u%s%u\n", "tempt_since_bootup", *nm, "max: ", *(__u16 *)raw, - ", min: ", *(__u16 *)(raw+2), ", curr: ", *(__u16 *)(raw+4)); + ", min: ", *(__u16 *)(raw+2), ", curr: ", *(__u16 *)(raw+4)); get_memblaze_new_smart_info(smart, RAISIN_SI_VD_READ_FAIL, nm, raw); printf("%-32s: %3d%% %"PRIu64"\n", "read_fail_count", *nm, int48_to_long(raw)); @@ -216,94 +216,94 @@ static void show_memblaze_smart_log_old(struct nvme_memblaze_smart_log *smart, printf("Additional Smart Log for NVME device:%s namespace-id:%x\n", devname, nsid); - printf("Total write in GB since last factory reset : %"PRIu64"\n", - int48_to_long(smart->items[TOTAL_WRITE].rawval)); - printf("Total read in GB since last factory reset : %"PRIu64"\n", - int48_to_long(smart->items[TOTAL_READ].rawval)); + printf("Total write in GB since last factory reset : %"PRIu64"\n", + int48_to_long(smart->items[TOTAL_WRITE].rawval)); + printf("Total read in GB since last factory reset : %"PRIu64"\n", + int48_to_long(smart->items[TOTAL_READ].rawval)); - printf("Thermal throttling status[1:HTP in progress] : %u\n", - smart->items[THERMAL_THROTTLE].thermal_throttle.on); - printf("Total thermal throttling minutes since power on : %u\n", - smart->items[THERMAL_THROTTLE].thermal_throttle.count); + printf("Thermal throttling status[1:HTP in progress] : %u\n", + smart->items[THERMAL_THROTTLE].thermal_throttle.on); + printf("Total thermal throttling minutes since power on : %u\n", + smart->items[THERMAL_THROTTLE].thermal_throttle.count); - printf("Maximum temperature in kelvins since last factory reset : %u\n", - le16_to_cpu(smart->items[TEMPT_SINCE_RESET].temperature.max)); - printf("Minimum temperature in kelvins since last factory reset : %u\n", - le16_to_cpu(smart->items[TEMPT_SINCE_RESET].temperature.min)); + printf("Maximum temperature in kelvins since last factory reset : %u\n", + le16_to_cpu(smart->items[TEMPT_SINCE_RESET].temperature.max)); + printf("Minimum temperature in kelvins since last factory reset : %u\n", + le16_to_cpu(smart->items[TEMPT_SINCE_RESET].temperature.min)); if (compare_fw_version(fw_ver, "0.09.0300") != 0) { - printf("Maximum temperature in kelvins since power on : %u\n", - le16_to_cpu(smart->items[TEMPT_SINCE_BOOTUP].temperature_p.max)); - printf("Minimum temperature in kelvins since power on : %u\n", - le16_to_cpu(smart->items[TEMPT_SINCE_BOOTUP].temperature_p.min)); + printf("Maximum temperature in kelvins since power on : %u\n", + le16_to_cpu(smart->items[TEMPT_SINCE_BOOTUP].temperature_p.max)); + printf("Minimum temperature in kelvins since power on : %u\n", + le16_to_cpu(smart->items[TEMPT_SINCE_BOOTUP].temperature_p.min)); } - printf("Current temperature in kelvins : %u\n", - le16_to_cpu(smart->items[TEMPT_SINCE_RESET].temperature.curr)); + printf("Current temperature in kelvins : %u\n", + le16_to_cpu(smart->items[TEMPT_SINCE_RESET].temperature.curr)); - printf("Maximum power in watt since power on : %u\n", - le16_to_cpu(smart->items[POWER_CONSUMPTION].power.max)); - printf("Minimum power in watt since power on : %u\n", - le16_to_cpu(smart->items[POWER_CONSUMPTION].power.min)); - printf("Current power in watt : %u\n", - le16_to_cpu(smart->items[POWER_CONSUMPTION].power.curr)); + printf("Maximum power in watt since power on : %u\n", + le16_to_cpu(smart->items[POWER_CONSUMPTION].power.max)); + printf("Minimum power in watt since power on : %u\n", + le16_to_cpu(smart->items[POWER_CONSUMPTION].power.min)); + printf("Current power in watt : %u\n", + le16_to_cpu(smart->items[POWER_CONSUMPTION].power.curr)); item = &smart->items[POWER_LOSS_PROTECTION]; if (item_id_2_u32(item) == 0xEC) - printf("Power loss protection normalized value : %u\n", - item->power_loss_protection.curr); + printf("Power loss protection normalized value : %u\n", + item->power_loss_protection.curr); item = &smart->items[WEARLEVELING_COUNT]; if (item_id_2_u32(item) == 0xAD) { - printf("Percentage of wearleveling count left : %u\n", - le16_to_cpu(item->nmval)); - printf("Wearleveling count min erase cycle : %u\n", - le16_to_cpu(item->wearleveling_count.min)); - printf("Wearleveling count max erase cycle : %u\n", - le16_to_cpu(item->wearleveling_count.max)); - printf("Wearleveling count avg erase cycle : %u\n", - le16_to_cpu(item->wearleveling_count.avg)); + printf("Percentage of wearleveling count left : %u\n", + le16_to_cpu(item->nmval)); + printf("Wearleveling count min erase cycle : %u\n", + le16_to_cpu(item->wearleveling_count.min)); + printf("Wearleveling count max erase cycle : %u\n", + le16_to_cpu(item->wearleveling_count.max)); + printf("Wearleveling count avg erase cycle : %u\n", + le16_to_cpu(item->wearleveling_count.avg)); } item = &smart->items[HOST_WRITE]; if (item_id_2_u32(item) == 0xF5) - printf("Total host write in GiB since device born : %llu\n", - (unsigned long long)raw_2_u64(item->rawval, sizeof(item->rawval))); + printf("Total host write in GiB since device born : %llu\n", + (unsigned long long)raw_2_u64(item->rawval, sizeof(item->rawval))); item = &smart->items[THERMAL_THROTTLE_CNT]; if (item_id_2_u32(item) == 0xEB) - printf("Thermal throttling count since device born : %u\n", - item->thermal_throttle_cnt.cnt); + printf("Thermal throttling count since device born : %u\n", + item->thermal_throttle_cnt.cnt); item = &smart->items[CORRECT_PCIE_PORT0]; if (item_id_2_u32(item) == 0xED) - printf("PCIE Correctable Error Count of Port0 : %llu\n", - (unsigned long long)raw_2_u64(item->rawval, sizeof(item->rawval))); + printf("PCIE Correctable Error Count of Port0 : %llu\n", + (unsigned long long)raw_2_u64(item->rawval, sizeof(item->rawval))); item = &smart->items[CORRECT_PCIE_PORT1]; if (item_id_2_u32(item) == 0xEE) - printf("PCIE Correctable Error Count of Port1 : %llu\n", - (unsigned long long)raw_2_u64(item->rawval, sizeof(item->rawval))); + printf("PCIE Correctable Error Count of Port1 : %llu\n", + (unsigned long long)raw_2_u64(item->rawval, sizeof(item->rawval))); item = &smart->items[REBUILD_FAIL]; if (item_id_2_u32(item) == 0xEF) - printf("End-to-End Error Detection Count : %llu\n", - (unsigned long long)raw_2_u64(item->rawval, sizeof(item->rawval))); + printf("End-to-End Error Detection Count : %llu\n", + (unsigned long long)raw_2_u64(item->rawval, sizeof(item->rawval))); item = &smart->items[ERASE_FAIL]; if (item_id_2_u32(item) == 0xF0) - printf("Erase Fail Count : %llu\n", - (unsigned long long)raw_2_u64(item->rawval, sizeof(item->rawval))); + printf("Erase Fail Count : %llu\n", + (unsigned long long)raw_2_u64(item->rawval, sizeof(item->rawval))); item = &smart->items[PROGRAM_FAIL]; if (item_id_2_u32(item) == 0xF1) - printf("Program Fail Count : %llu\n", - (unsigned long long)raw_2_u64(item->rawval, sizeof(item->rawval))); + printf("Program Fail Count : %llu\n", + (unsigned long long)raw_2_u64(item->rawval, sizeof(item->rawval))); item = &smart->items[READ_FAIL]; if (item_id_2_u32(item) == 0xF2) - printf("Read Fail Count : %llu\n", - (unsigned long long)raw_2_u64(item->rawval, sizeof(item->rawval))); + printf("Read Fail Count : %llu\n", + (unsigned long long)raw_2_u64(item->rawval, sizeof(item->rawval))); - if ( IS_PAPAYA(fw_ver_local) ) { + if (IS_PAPAYA(fw_ver_local)) { struct nvme_p4_smart_log *s = (struct nvme_p4_smart_log *)smart; __u8 *nm = malloc(NM_SIZE * sizeof(__u8)); __u8 *raw = malloc(RAW_SIZE * sizeof(__u8)); @@ -354,17 +354,13 @@ static int show_memblaze_smart_log(int fd, __u32 nsid, const char *devname, return err; snprintf(fw_ver, sizeof(fw_ver), "%c.%c%c.%c%c%c%c", - ctrl.fr[0], ctrl.fr[1], ctrl.fr[2], ctrl.fr[3], - ctrl.fr[4], ctrl.fr[5], ctrl.fr[6]); + ctrl.fr[0], ctrl.fr[1], ctrl.fr[2], ctrl.fr[3], + ctrl.fr[4], ctrl.fr[5], ctrl.fr[6]); - if (getlogpage_format_type(ctrl.mn)) // Intel Format & new format - { + if (getlogpage_format_type(ctrl.mn)) /* Intel Format & new format */ show_memblaze_smart_log_new(smart, nsid, devname); - } - else // Memblaze Format & old format - { + else /* Memblaze Format & old format */ show_memblaze_smart_log_old(smart, nsid, devname, fw_ver); - } return err; } @@ -379,13 +375,13 @@ int parse_params(char *str, int number, ...) while (number > 0) { c = strtok(str, ","); - if ( c == NULL) { + if (!c) { printf("No enough parameters. abort...\n"); va_end(argp); return 1; } - if (isalnum((int)*c) == 0) { + if (!isalnum((int)*c)) { printf("%s is not a valid number\n", c); va_end(argp); return 1; @@ -396,7 +392,8 @@ int parse_params(char *str, int number, ...) if (str) { str = strchr(str, ','); - if (str) { str++; } + if (str) + str++; } number--; } @@ -408,8 +405,8 @@ int parse_params(char *str, int number, ...) static int mb_get_additional_smart_log(int argc, char **argv, struct command *cmd, struct plugin *plugin) { struct nvme_memblaze_smart_log smart_log; - char *desc = "Get Memblaze vendor specific additional smart log (optionally, "\ - "for the specified namespace), and show it."; + char *desc = + "Get Memblaze vendor specific additional smart log (optionally, for the specified namespace), and show it."; const char *namespace = "(optional) desired namespace"; const char *raw = "dump output in binary format"; struct nvme_dev *dev; @@ -437,9 +434,8 @@ static int mb_get_additional_smart_log(int argc, char **argv, struct command *cm sizeof(smart_log), &smart_log); if (!err) { if (!cfg.raw_binary) - err = show_memblaze_smart_log(dev_fd(dev), - cfg.namespace_id, - dev->name, &smart_log); + err = show_memblaze_smart_log(dev_fd(dev), cfg.namespace_id, dev->name, + &smart_log); else d_raw((unsigned char *)&smart_log, sizeof(smart_log)); } @@ -453,10 +449,14 @@ static int mb_get_additional_smart_log(int argc, char **argv, struct command *cm static char *mb_feature_to_string(int feature) { switch (feature) { - case MB_FEAT_POWER_MGMT: return "Memblaze power management"; - case MB_FEAT_HIGH_LATENCY: return "Memblaze high latency log"; - case MB_FEAT_CLEAR_ERRORLOG: return "Memblaze clear error log"; - default: return "Unknown"; + case MB_FEAT_POWER_MGMT: + return "Memblaze power management"; + case MB_FEAT_HIGH_LATENCY: + return "Memblaze high latency log"; + case MB_FEAT_CLEAR_ERRORLOG: + return "Memblaze clear error log"; + default: + return "Unknown"; } } @@ -490,14 +490,12 @@ static int mb_get_powermanager_status(int argc, char **argv, struct command *cmd .result = &result, }; err = nvme_get_features(&args); - if (err < 0) { + if (err < 0) perror("get-feature"); - } - if (!err) { + if (!err) printf("get-feature:0x%02x (%s), %s value: %#08x\n", feature_id, - mb_feature_to_string(feature_id), - nvme_select_to_string(0), result); - } else if (err > 0) + mb_feature_to_string(feature_id), nvme_select_to_string(0), result); + else if (err > 0) nvme_show_status(err); dev_close(dev); return err; @@ -550,13 +548,12 @@ static int mb_set_powermanager_status(int argc, char **argv, struct command *cmd .result = &result, }; err = nvme_set_features(&args); - if (err < 0) { + if (err < 0) perror("set-feature"); - } - if (!err) { + if (!err) printf("set-feature:%02x (%s), value:%#08x\n", cfg.feature_id, - mb_feature_to_string(cfg.feature_id), cfg.value); - } else if (err > 0) + mb_feature_to_string(cfg.feature_id), cfg.value); + else if (err > 0) nvme_show_status(err); dev_close(dev); @@ -568,10 +565,10 @@ static int mb_set_powermanager_status(int argc, char **argv, struct command *cmd #define MB_FEAT_HIGH_LATENCY_VALUE_SHIFT (15) static int mb_set_high_latency_log(int argc, char **argv, struct command *cmd, struct plugin *plugin) { - const char *desc = "Set Memblaze high latency log\n"\ - " input parameter p1,p2\n"\ - " p1 value: 0 is disable, 1 is enable\n"\ - " p2 value: 1 .. 5000 ms"; + const char *desc = "Set Memblaze high latency log\n" + " input parameter p1,p2\n" + " p1 value: 0 is disable, 1 is enable\n" + " p2 value: 1 .. 5000 ms"; const char *param = "input parameters"; int param1 = 0, param2 = 0; struct nvme_dev *dev; @@ -580,18 +577,18 @@ static int mb_set_high_latency_log(int argc, char **argv, struct command *cmd, s struct config { __u32 feature_id; - char * param; + char *param; __u32 value; }; struct config cfg = { - .feature_id = MB_FEAT_HIGH_LATENCY, - .param = "0,0", - .value = 0, + .feature_id = MB_FEAT_HIGH_LATENCY, + .param = "0,0", + .value = 0, }; OPT_ARGS(opts) = { - OPT_LIST("param", 'p', &cfg.param, param), + OPT_LIST("param", 'p', &cfg.param, param), OPT_END() }; @@ -602,18 +599,18 @@ static int mb_set_high_latency_log(int argc, char **argv, struct command *cmd, s if (parse_params(cfg.param, 2, ¶m1, ¶m2)) { printf("setfeature: invalid formats %s\n", cfg.param); dev_close(dev); - return EINVAL; + return -EINVAL; } if ((param1 == 1) && (param2 < P2MIN || param2 > P2MAX)) { printf("setfeature: invalid high io latency threshold %d\n", param2); dev_close(dev); - return EINVAL; + return -EINVAL; } cfg.value = (param1 << MB_FEAT_HIGH_LATENCY_VALUE_SHIFT) | param2; struct nvme_set_features_args args = { - .args_size = sizeof(args), - .fd = dev_fd(dev), + .args_size = sizeof(args), + .fd = dev_fd(dev), .fid = cfg.feature_id, .nsid = 0, .cdw11 = cfg.value, @@ -621,19 +618,18 @@ static int mb_set_high_latency_log(int argc, char **argv, struct command *cmd, s .save = false, .uuidx = 0, .cdw15 = 0, - .data_len = 0, + .data_len = 0, .data = NULL, - .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, + .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, .result = &result, }; err = nvme_set_features(&args); - if (err < 0) { + if (err < 0) perror("set-feature"); - } - if (!err) { + if (!err) printf("set-feature:0x%02X (%s), value:%#08x\n", cfg.feature_id, - mb_feature_to_string(cfg.feature_id), cfg.value); - } else if (err > 0) + mb_feature_to_string(cfg.feature_id), cfg.value); + else if (err > 0) nvme_show_status(err); dev_close(dev); @@ -649,11 +645,11 @@ static int glp_high_latency_show_bar(FILE *fdi, int print) return 0; } -/* High latency log page definiton +/* + * High latency log page definiton * Total 32 bytes */ -typedef struct -{ +struct log_page_high_latency { __u8 port; __u8 revision; __u16 rsvd; @@ -666,22 +662,20 @@ typedef struct __u16 numLBA; __u16 timestampH; __u32 timestampL; -} log_page_high_latency_t; /* total 32 bytes */ +}; /* total 32 bytes */ static int find_deadbeef(char *buf) { - if (((*(buf + 0) & 0xff) == 0xef) && ((*(buf + 1) & 0xff) == 0xbe) && \ - ((*(buf + 2) & 0xff) == 0xad) && ((*(buf + 3) & 0xff) == 0xde)) - { + if (((*(buf + 0) & 0xff) == 0xef) && ((*(buf + 1) & 0xff) == 0xbe) && + ((*(buf + 2) & 0xff) == 0xad) && ((*(buf + 3) & 0xff) == 0xde)) return 1; - } return 0; } #define TIME_STR_SIZE (44) static int glp_high_latency(FILE *fdi, char *buf, int buflen, int print) { - log_page_high_latency_t *logEntry; + struct log_page_high_latency *logEntry; char string[TIME_STR_SIZE]; int i, entrySize; __u64 timestamp; @@ -689,24 +683,19 @@ static int glp_high_latency(FILE *fdi, char *buf, int buflen, int print) struct tm *t = NULL; int millisec = 0; - if (find_deadbeef(buf)) return 0; + if (find_deadbeef(buf)) + return 0; - entrySize = sizeof(log_page_high_latency_t); - for (i = 0; i < buflen; i += entrySize) - { - logEntry = (log_page_high_latency_t *)(buf + i); + entrySize = sizeof(struct log_page_high_latency); + for (i = 0; i < buflen; i += entrySize) { + logEntry = (struct log_page_high_latency *)(buf + i); if (logEntry->latency == 0 && logEntry->revision == 0) - { return 1; - } - if (0 == logEntry->timestampH) // generate host time string - { + if (!logEntry->timestampH) { /* generate host time string */ snprintf(string, sizeof(string), "%d", logEntry->timestampL); - } - else // sort - { + } else { /* sort */ timestamp = logEntry->timestampH; timestamp = timestamp << 32; timestamp += logEntry->timestampL; @@ -714,23 +703,22 @@ static int glp_high_latency(FILE *fdi, char *buf, int buflen, int print) millisec = timestamp % 1000; t = gmtime(&tt); snprintf(string, sizeof(string), "%4d%02d%02d--%02d:%02d:%02d.%03d UTC", - 1900 + t->tm_year, 1 + t->tm_mon, t->tm_mday, t->tm_hour, t->tm_min, t->tm_sec, millisec); + 1900 + t->tm_year, 1 + t->tm_mon, t->tm_mday, t->tm_hour, + t->tm_min, t->tm_sec, millisec); } - if (fdi) { + if (fdi) fprintf(fdi, "%-32s %-7x %-6x %-6x %-8x %4x%08x %-8x %-d\n", string, logEntry->opcode, logEntry->sqe, logEntry->cid, logEntry->nsid, (__u32)(logEntry->sLBA >> 32), (__u32)logEntry->sLBA, logEntry->numLBA, logEntry->latency); - } if (print) - { printf("%-32s %-7x %-6x %-6x %-8x %4x%08x %-8x %-d\n", - string, logEntry->opcode, logEntry->sqe, logEntry->cid, logEntry->nsid, - (__u32)(logEntry->sLBA >> 32), (__u32)logEntry->sLBA, logEntry->numLBA, logEntry->latency); - } + string, logEntry->opcode, logEntry->sqe, logEntry->cid, + logEntry->nsid, (__u32)(logEntry->sLBA >> 32), (__u32)logEntry->sLBA, + logEntry->numLBA, logEntry->latency); } return 1; } @@ -758,16 +746,18 @@ static int mb_high_latency_log_print(int argc, char **argv, struct command *cmd, sizeof(buf), &buf); while (1) { - if (!glp_high_latency(fdi, buf, LOG_PAGE_SIZE, DO_PRINT_FLAG)) break; + if (!glp_high_latency(fdi, buf, LOG_PAGE_SIZE, DO_PRINT_FLAG)) + break; err = nvme_get_log_simple(dev_fd(dev), GLP_ID_VU_GET_HIGH_LATENCY_LOG, - sizeof(buf), &buf); - if ( err) { - nvme_show_status(err); + sizeof(buf), &buf); + if (err) { + nvme_show_status(err); break; } } - if (NULL != fdi) fclose(fdi); + if (fdi) + fclose(fdi); dev_close(dev); return err; } @@ -788,7 +778,7 @@ static int mb_selective_download(int argc, char **argv, struct command *cmd, str const char *desc = "This performs a selective firmware download, which allows the user to " "select which firmware binary to update for 9200 devices. This requires a power cycle once the " - "update completes. The options available are: \n\n" + "update completes. The options available are:\n\n" "OOB - This updates the OOB and main firmware\n" "EEP - This updates the eeprom and main firmware\n" "ALL - This updates the eeprom, OOB, and main firmware"; @@ -796,18 +786,18 @@ static int mb_selective_download(int argc, char **argv, struct command *cmd, str const char *select = "FW Select (e.g., --select=OOB, EEP, ALL)"; int xfer = 4096; void *fw_buf; - int selectNo,fw_fd,fw_size,err,offset = 0; + int selectNo, fw_fd, fw_size, err, offset = 0; struct nvme_dev *dev; struct stat sb; int i; struct config { - char *fw; - char *select; + char *fw; + char *select; }; struct config cfg = { - .fw = "", + .fw = "", .select = "\0", }; @@ -827,15 +817,14 @@ static int mb_selective_download(int argc, char **argv, struct command *cmd, str goto out; } - for (i = 0; i < 3; i++) { + for (i = 0; i < 3; i++) cfg.select[i] = toupper(cfg.select[i]); - } - if (strncmp(cfg.select,"OOB", 3) == 0) { + if (!strncmp(cfg.select, "OOB", 3)) { selectNo = 18; - } else if (strncmp(cfg.select,"EEP", 3) == 0) { + } else if (!strncmp(cfg.select, "EEP", 3)) { selectNo = 10; - } else if (strncmp(cfg.select,"ALL", 3) == 0) { + } else if (!strncmp(cfg.select, "ALL", 3)) { selectNo = 26; } else { fprintf(stderr, "Invalid select flag\n"); @@ -902,7 +891,7 @@ static int mb_selective_download(int argc, char **argv, struct command *cmd, str err = memblaze_fw_commit(dev_fd(dev), selectNo); - if(err == 0x10B || err == 0x20B) { + if (err == 0x10B || err == 0x20B) { err = 0; fprintf(stderr, "Update successful! Please power cycle for changes to take effect\n"); } @@ -943,71 +932,54 @@ int io_latency_histogram(char *file, char *buf, int print, int logid) unsigned int *revision = (unsigned int *)buf; if (logid == GLP_ID_VU_GET_READ_LATENCY_HISTOGRAM) - { fPRINT_PARAM1("Memblaze IO Read Command Latency Histogram\n"); - } else if (logid == GLP_ID_VU_GET_WRITE_LATENCY_HISTOGRAM) - { fPRINT_PARAM1("Memblaze IO Write Command Latency Histogram\n"); - } fPRINT_PARAM2("Major Revision : %d\n", revision[1]); fPRINT_PARAM2("Minor Revision : %d\n", revision[0]); buf += 8; - if (revision[1] == 1 && revision[0] == 0) - { + if (revision[1] == 1 && revision[0] == 0) { fPRINT_PARAM1("--------------------------------------------------\n"); - fPRINT_PARAM1("Bucket Start End Value \n"); + fPRINT_PARAM1("Bucket Start End Value\n"); fPRINT_PARAM1("--------------------------------------------------\n"); index = 0; strcpy(unit[0], "us"); strcpy(unit[1], "us"); - for (i = 0; i < 32; i++, index++) - { - if (i == 31) - { + for (i = 0; i < 32; i++, index++) { + if (i == 31) { strcpy(unit[1], "ms"); - ioLatencyHistogramOutput(fdi, index, i * 32, 1, unit[0], unit[1], (unsigned int *)buf, print); - } - else - { - ioLatencyHistogramOutput(fdi, index, i * 32, (i + 1) * 32, unit[0], unit[1], (unsigned int *)buf, - print); + ioLatencyHistogramOutput(fdi, index, i * 32, 1, unit[0], unit[1], + (unsigned int *)buf, print); + } else { + ioLatencyHistogramOutput(fdi, index, i * 32, (i + 1) * 32, unit[0], + unit[1], (unsigned int *)buf, print); } } strcpy(unit[0], "ms"); strcpy(unit[1], "ms"); for (i = 1; i < 32; i++, index++) - { ioLatencyHistogramOutput(fdi, index, i, i + 1, unit[0], unit[1], (unsigned int *)buf, print); - } - for (i = 1; i < 32; i++, index++) - { - if (i == 31) - { + for (i = 1; i < 32; i++, index++) { + if (i == 31) { strcpy(unit[1], "s"); - ioLatencyHistogramOutput(fdi, index, i * 32, 1, unit[0], unit[1], (unsigned int *)buf, print); - } - else - { - ioLatencyHistogramOutput(fdi, index, i * 32, (i + 1) * 32, unit[0], unit[1], (unsigned int *)buf, - print); + ioLatencyHistogramOutput(fdi, index, i * 32, 1, unit[0], unit[1], + (unsigned int *)buf, print); + } else { + ioLatencyHistogramOutput(fdi, index, i * 32, (i + 1) * 32, unit[0], + unit[1], (unsigned int *)buf, print); } } strcpy(unit[0], "s"); strcpy(unit[1], "s"); for (i = 1; i < 4; i++, index++) - { ioLatencyHistogramOutput(fdi, index, i, i + 1, unit[0], unit[1], (unsigned int *)buf, print); - } ioLatencyHistogramOutput(fdi, index, i, 0x7FFFFFFF, unit[0], unit[1], (unsigned int *)buf, print); - } - else - { + } else { fPRINT_PARAM1("Unsupported io latency histogram revision\n"); } @@ -1035,7 +1007,7 @@ static int mb_lat_stats_log_print(int argc, char **argv, struct command *cmd, st }; OPT_ARGS(opts) = { - OPT_FLAG("write", 'w', &cfg.write, write), + OPT_FLAG("write", 'w', &cfg.write, write), OPT_END() }; @@ -1047,7 +1019,8 @@ static int mb_lat_stats_log_print(int argc, char **argv, struct command *cmd, st sizeof(stats), &stats); if (!err) io_latency_histogram(cfg.write ? f2 : f1, stats, DO_PRINT_FLAG, - cfg.write ? GLP_ID_VU_GET_WRITE_LATENCY_HISTOGRAM : GLP_ID_VU_GET_READ_LATENCY_HISTOGRAM); + cfg.write ? GLP_ID_VU_GET_WRITE_LATENCY_HISTOGRAM : + GLP_ID_VU_GET_READ_LATENCY_HISTOGRAM); else nvme_show_status(err); @@ -1085,7 +1058,7 @@ static int memblaze_clear_error_log(int argc, char **argv, struct command *cmd, struct nvme_set_features_args args = { .args_size = sizeof(args), - .fd = dev_fd(dev), + .fd = dev_fd(dev), .fid = cfg.feature_id, .nsid = 0, .cdw11 = cfg.value, @@ -1096,15 +1069,14 @@ static int memblaze_clear_error_log(int argc, char **argv, struct command *cmd, .data_len = 0, .data = NULL, .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, - .result = &result, + .result = &result, }; err = nvme_set_features(&args); - if (err < 0) { + if (err < 0) perror("set-feature"); - } - if (!err) { + if (!err) printf("set-feature:%02x (%s), value:%#08x\n", cfg.feature_id, mb_feature_to_string(cfg.feature_id), cfg.value); - } else if (err > 0) + else if (err > 0) nvme_show_status(err); dev_close(dev); diff --git a/plugins/memblaze/memblaze-utils.h b/plugins/memblaze/memblaze-utils.h index 316cd367..dd89189f 100644 --- a/plugins/memblaze/memblaze-utils.h +++ b/plugins/memblaze/memblaze-utils.h @@ -198,24 +198,20 @@ struct nvme_p4_smart_log printf("=Memblaze= %s[%d]-%s():%d=%s\n", \ __FILE__, __LINE__, __func__, ip, argv[ip]); }while(0) -#define fPRINT_PARAM1(format) \ - { \ - do { \ - if (fdi) \ - fprintf(fdi, format); \ - if (print) \ - printf(format); \ - } while (0); \ - } +#define fPRINT_PARAM1(format) \ + do { \ + if (fdi) \ + fprintf(fdi, format); \ + if (print) \ + printf(format); \ + } while (0) -#define fPRINT_PARAM2(format, value) \ - { \ - do { \ - if (fdi) \ - fprintf(fdi, format, value); \ - if (print) \ - printf(format, value); \ - } while (0); \ - } +#define fPRINT_PARAM2(format, value) \ + do { \ + if (fdi) \ + fprintf(fdi, format, value); \ + if (print) \ + printf(format, value); \ + } while (0) #endif // __MEMBLAZE_UTILS_H__