Skip to content
Closed
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
89 changes: 74 additions & 15 deletions nvme-print-json.c
Original file line number Diff line number Diff line change
Expand Up @@ -2124,22 +2124,56 @@ static char *json_eom_printable_eye(struct nvme_eom_lane_desc *lane,
struct json_object *r)
{
char *eye = (char *)lane->eye_desc;
char *printable = malloc(lane->nrows * lane->ncols + lane->ncols);
char *printable_start = printable;
int i, j;
uint16_t nrows = le16_to_cpu(lane->nrows);
uint16_t ncols = le16_to_cpu(lane->ncols);
char *printable = NULL;
char *printable_start = NULL;
struct json_object *eye_array = json_create_array();

if (nrows == 0 || ncols == 0)
return NULL;

/*
* Allocate buffer for full printable string (with newlines)
* +1 for null terminator
*/
printable = malloc(nrows * ncols + nrows + 1);
printable_start = printable;

if (!printable)
goto exit;
return NULL;

if (!eye_array) {
free(printable);
return NULL;
}

for (int i = 0; i < nrows; i++) {
char *row = malloc(ncols + 1);

if (!row) {
/* Cleanup on failure */
free(printable_start);
return NULL;
}

for (i = 0; i < lane->nrows; i++) {
for (j = 0; j < lane->ncols; j++, printable++)
sprintf(printable, "%c", eye[i * lane->ncols + j]);
sprintf(printable++, "\n");
for (int j = 0; j < ncols; j++) {
char ch = eye[i * ncols + j];
*printable++ = ch;
row[j] = ch;
}

*printable++ = '\n';
row[ncols] = '\0';

array_add_str(eye_array, row);
free(row);
}

obj_add_str(r, "printable_eye", printable_start);
*printable = '\0';

obj_add_array(r, "printable_eye", eye_array);

exit:
return printable_start;
}

Expand All @@ -2155,7 +2189,12 @@ static void json_phy_rx_eom_descs(struct nvme_phy_rx_eom_log *log,

for (i = 0; i < num_descs; i++) {
struct nvme_eom_lane_desc *desc = p;
unsigned char *vsdata = NULL;
unsigned int vsdataoffset = 0;
struct json_object *jdesc = json_create_object();
uint16_t nrows = le16_to_cpu(desc->nrows);
uint16_t ncols = le16_to_cpu(desc->ncols);
uint16_t edlen = le16_to_cpu(desc->edlen);

obj_add_uint(jdesc, "lid", desc->mstatus);
obj_add_uint(jdesc, "lane", desc->lane);
Expand All @@ -2164,14 +2203,34 @@ static void json_phy_rx_eom_descs(struct nvme_phy_rx_eom_log *log,
obj_add_uint(jdesc, "bottom", le16_to_cpu(desc->bottom));
obj_add_uint(jdesc, "left", le16_to_cpu(desc->left));
obj_add_uint(jdesc, "right", le16_to_cpu(desc->right));
obj_add_uint(jdesc, "nrows", le16_to_cpu(desc->nrows));
obj_add_uint(jdesc, "ncols", le16_to_cpu(desc->ncols));
obj_add_uint(jdesc, "edlen", le16_to_cpu(desc->edlen));
obj_add_uint(jdesc, "nrows", nrows);
obj_add_uint(jdesc, "ncols", ncols);
obj_add_uint(jdesc, "edlen", edlen);

if (NVME_EOM_ODP_PEFP(log->odp))
allocated_eyes[i] = json_eom_printable_eye(desc, r);
allocated_eyes[i] = json_eom_printable_eye(desc, jdesc);

if (edlen == 0)
continue;

/* 2 hex chars + space per byte */
_cleanup_free_ char *hexstr = malloc(edlen * 3 + 1);

if (!hexstr)
return;

/* Hex dump Vendor Specific Eye Data */
vsdataoffset = (nrows * ncols) + sizeof(struct nvme_eom_lane_desc);
vsdata = (unsigned char *)((unsigned char *)desc + vsdataoffset);

char *hexdata = hexstr;

for (int offset = 0; offset < edlen; offset++)
hexdata += sprintf(hexdata, "%02X ", vsdata[offset]);
/* remove trailing space */
*(hexdata - 1) = '\0';

/* Eye Data field is vendor specific, doesn't map to JSON */
obj_add_str(jdesc, "vsdata_hex", hexstr);

array_add_obj(descs, jdesc);

Expand Down
27 changes: 21 additions & 6 deletions nvme-print-stdout.c
Original file line number Diff line number Diff line change
Expand Up @@ -776,9 +776,9 @@ static void stdout_eom_printable_eye(struct nvme_eom_lane_desc *lane)
char *eye = (char *)lane->eye_desc;
int i, j;

for (i = 0; i < lane->nrows; i++) {
for (j = 0; j < lane->ncols; j++)
printf("%c", eye[i * lane->ncols + j]);
for (i = 0; i < le16_to_cpu(lane->nrows); i++) {
for (j = 0; j < le16_to_cpu(lane->ncols); j++)
printf("%c", eye[i * le16_to_cpu(lane->ncols) + j]);
printf("\n");
}
}
Expand All @@ -790,6 +790,11 @@ static void stdout_phy_rx_eom_descs(struct nvme_phy_rx_eom_log *log)

for (i = 0; i < log->nd; i++) {
struct nvme_eom_lane_desc *desc = p;
unsigned char *vsdata = NULL;
unsigned int vsdataoffset = 0;
uint16_t nrows = le16_to_cpu(desc->nrows);
uint16_t ncols = le16_to_cpu(desc->ncols);
uint16_t edlen = le16_to_cpu(desc->edlen);

printf("Measurement Status: %s\n",
desc->mstatus ? "Successful" : "Not Successful");
Expand All @@ -799,14 +804,24 @@ static void stdout_phy_rx_eom_descs(struct nvme_phy_rx_eom_log *log)
printf("Bottom: %u\n", le16_to_cpu(desc->bottom));
printf("Left: %u\n", le16_to_cpu(desc->left));
printf("Right: %u\n", le16_to_cpu(desc->right));
printf("Number of Rows: %u\n", le16_to_cpu(desc->nrows));
printf("Number of Columns: %u\n", le16_to_cpu(desc->ncols));
printf("Eye Data Length: %u\n", le16_to_cpu(desc->edlen));
printf("Number of Rows: %u\n", nrows);
printf("Number of Columns: %u\n", ncols);
printf("Eye Data Length: %u\n", desc->edlen);

if (NVME_EOM_ODP_PEFP(log->odp))
stdout_eom_printable_eye(desc);

/* Eye Data field is vendor specific */
if (edlen == 0)
continue;

/* Hex dump Vendor Specific Eye Data */
vsdata = malloc(edlen);
vsdataoffset = (nrows * ncols) + sizeof(struct nvme_eom_lane_desc);
vsdata = (unsigned char *)((unsigned char *)desc + vsdataoffset);
printf("Eye Data:\n");
d(vsdata, edlen, 16, 1);
printf("\n");

p += log->dsize;
}
Expand Down
4 changes: 3 additions & 1 deletion plugins/micron/micron-nvme.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
*
* @file: micron-nvme.c
* @brief: This module contains all the constructs needed for micron nvme-cli plugin.
* @authors:Chaithanya Shoba <[email protected]>,
* @authors:Hanumanthu H <[email protected]>
* Chaithanya Shoba <[email protected]>
* Sivaprasad Gutha <[email protected]>
*/

#include <stdio.h>
Expand Down
4 changes: 3 additions & 1 deletion plugins/micron/micron-nvme.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
*
* @file: micron-nvme.h
* @brief: This module contains all the constructs needed for micron nvme-cli plugin.
* @authors:Chaithanya Shoba <[email protected]>,
* @authors:Hanumanthu H <[email protected]>
* Chaithanya Shoba <[email protected]>
* Sivaprasad Gutha <[email protected]>
*/

#undef CMD_INC_FILE
Expand Down