Skip to content

Commit 43097ad

Browse files
nvme: eye chart plotting and dump VS eye data
- Addressing review comments Signed-off-by: Sivaprasad Gutha <sivaprasad6541@gmail.com>
1 parent 1b18547 commit 43097ad

File tree

2 files changed

+36
-26
lines changed

2 files changed

+36
-26
lines changed

nvme-print-json.c

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2126,19 +2126,23 @@ static char *json_eom_printable_eye(struct nvme_eom_lane_desc *lane,
21262126
char *eye = (char *)lane->eye_desc;
21272127
uint16_t nrows = le16_to_cpu(lane->nrows);
21282128
uint16_t ncols = le16_to_cpu(lane->ncols);
2129+
char *printable = NULL;
2130+
char *printable_start = NULL;
2131+
struct json_object *eye_array = json_create_array();
21292132

21302133
if (nrows == 0 || ncols == 0)
21312134
return NULL;
21322135

2133-
// Allocate buffer for full printable string (with newlines)
2134-
char *printable = malloc(nrows * ncols + nrows + 1); // +1 for null terminator
2135-
char *printable_start = printable;
2136+
/*
2137+
* Allocate buffer for full printable string (with newlines)
2138+
* +1 for null terminator
2139+
*/
2140+
printable = malloc(nrows * ncols + nrows + 1);
2141+
printable_start = printable;
21362142

21372143
if (!printable)
21382144
return NULL;
21392145

2140-
struct json_object *eye_array = json_create_array();
2141-
21422146
if (!eye_array) {
21432147
free(printable);
21442148
return NULL;
@@ -2148,7 +2152,7 @@ static char *json_eom_printable_eye(struct nvme_eom_lane_desc *lane,
21482152
char *row = malloc(ncols + 1);
21492153

21502154
if (!row) {
2151-
// Cleanup on failure
2155+
/* Cleanup on failure */
21522156
free(printable_start);
21532157
return NULL;
21542158
}
@@ -2188,6 +2192,9 @@ static void json_phy_rx_eom_descs(struct nvme_phy_rx_eom_log *log,
21882192
unsigned char *vsdata = NULL;
21892193
unsigned int vsdataoffset = 0;
21902194
struct json_object *jdesc = json_create_object();
2195+
uint16_t nrows = le16_to_cpu(desc->nrows);
2196+
uint16_t ncols = le16_to_cpu(desc->ncols);
2197+
uint16_t edlen = le16_to_cpu(desc->edlen);
21912198

21922199
obj_add_uint(jdesc, "lid", desc->mstatus);
21932200
obj_add_uint(jdesc, "lane", desc->lane);
@@ -2196,31 +2203,32 @@ static void json_phy_rx_eom_descs(struct nvme_phy_rx_eom_log *log,
21962203
obj_add_uint(jdesc, "bottom", le16_to_cpu(desc->bottom));
21972204
obj_add_uint(jdesc, "left", le16_to_cpu(desc->left));
21982205
obj_add_uint(jdesc, "right", le16_to_cpu(desc->right));
2199-
obj_add_uint(jdesc, "nrows", le16_to_cpu(desc->nrows));
2200-
obj_add_uint(jdesc, "ncols", le16_to_cpu(desc->ncols));
2201-
obj_add_uint(jdesc, "edlen", le16_to_cpu(desc->edlen));
2206+
obj_add_uint(jdesc, "nrows", nrows);
2207+
obj_add_uint(jdesc, "ncols", ncols);
2208+
obj_add_uint(jdesc, "edlen", edlen);
22022209

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

2206-
if (desc->edlen == 0)
2213+
if (edlen == 0)
22072214
continue;
22082215

2209-
/* Hex dump Vendor Specific Eye Data*/
2210-
vsdataoffset = (le16_to_cpu(desc->nrows) * le16_to_cpu(desc->ncols)) +
2211-
sizeof(struct nvme_eom_lane_desc);
2212-
vsdata = (unsigned char *)((unsigned char *)desc + vsdataoffset);
2213-
// 2 hex chars + space per byte
2214-
_cleanup_free_ char *hexstr = malloc(le16_to_cpu(desc->edlen) * 3 + 1);
2216+
/* 2 hex chars + space per byte */
2217+
_cleanup_free_ char *hexstr = malloc(edlen * 3 + 1);
22152218

22162219
if (!hexstr)
22172220
return;
22182221

2222+
/* Hex dump Vendor Specific Eye Data */
2223+
vsdataoffset = (nrows * ncols) + sizeof(struct nvme_eom_lane_desc);
2224+
vsdata = (unsigned char *)((unsigned char *)desc + vsdataoffset);
2225+
22192226
char *hexdata = hexstr;
22202227

2221-
for (int offset = 0; offset < le16_to_cpu(desc->edlen); offset++)
2228+
for (int offset = 0; offset < edlen; offset++)
22222229
hexdata += sprintf(hexdata, "%02X ", vsdata[offset]);
2223-
*(hexdata - 1) = '\0'; // remove trailing space
2230+
/* remove trailing space */
2231+
*(hexdata - 1) = '\0';
22242232

22252233
obj_add_str(jdesc, "vsdata_hex", hexstr);
22262234

nvme-print-stdout.c

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -792,6 +792,9 @@ static void stdout_phy_rx_eom_descs(struct nvme_phy_rx_eom_log *log)
792792
struct nvme_eom_lane_desc *desc = p;
793793
unsigned char *vsdata = NULL;
794794
unsigned int vsdataoffset = 0;
795+
uint16_t nrows = le16_to_cpu(desc->nrows);
796+
uint16_t ncols = le16_to_cpu(desc->ncols);
797+
uint16_t edlen = le16_to_cpu(desc->edlen);
795798

796799
printf("Measurement Status: %s\n",
797800
desc->mstatus ? "Successful" : "Not Successful");
@@ -801,24 +804,23 @@ static void stdout_phy_rx_eom_descs(struct nvme_phy_rx_eom_log *log)
801804
printf("Bottom: %u\n", le16_to_cpu(desc->bottom));
802805
printf("Left: %u\n", le16_to_cpu(desc->left));
803806
printf("Right: %u\n", le16_to_cpu(desc->right));
804-
printf("Number of Rows: %u\n", le16_to_cpu(desc->nrows));
805-
printf("Number of Columns: %u\n", le16_to_cpu(desc->ncols));
806-
printf("Eye Data Length: %u\n", le16_to_cpu(desc->edlen));
807+
printf("Number of Rows: %u\n", nrows);
808+
printf("Number of Columns: %u\n", ncols);
809+
printf("Eye Data Length: %u\n", desc->edlen);
807810

808811
if (NVME_EOM_ODP_PEFP(log->odp))
809812
stdout_eom_printable_eye(desc);
810813

811814
/* Eye Data field is vendor specific */
812-
if (le16_to_cpu(desc->edlen) == 0)
815+
if (edlen == 0)
813816
continue;
814817

815818
/* Hex dump Vendor Specific Eye Data */
816-
vsdata = malloc(le16_to_cpu(desc->edlen));
817-
vsdataoffset = (le16_to_cpu(desc->nrows) * le16_to_cpu(desc->ncols)) +
818-
sizeof(struct nvme_eom_lane_desc);
819+
vsdata = malloc(edlen);
820+
vsdataoffset = (nrows * ncols) + sizeof(struct nvme_eom_lane_desc);
819821
vsdata = (unsigned char *)((unsigned char *)desc + vsdataoffset);
820822
printf("Eye Data:\n");
821-
d(vsdata, le16_to_cpu(desc->edlen), 16, 1);
823+
d(vsdata, edlen, 16, 1);
822824
printf("\n");
823825

824826
p += log->dsize;

0 commit comments

Comments
 (0)