Skip to content

Commit abe110c

Browse files
sivaprasad6541igaw
authored andcommitted
nvme: plot eye chart data and hex dumping VS eye data
-Fixed segmentation fault issue in JSON output format for VS Eye data -Added support to hex dump VS Eye data in both normal and JSON formats -This enables customers to decode the raw eye chart data if needed -Ensured compatibility with existing d() and obj_d() hex dump utilities -Addressed all the review comments that are given as part of PR #2828 Signed-off-by: Sivaprasad Gutha <[email protected]>
1 parent 36c5ff7 commit abe110c

File tree

4 files changed

+121
-24
lines changed

4 files changed

+121
-24
lines changed

nvme-print-json.c

Lines changed: 88 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2124,23 +2124,60 @@ static char *json_eom_printable_eye(struct nvme_eom_lane_desc *lane,
21242124
struct json_object *r)
21252125
{
21262126
char *eye = (char *)lane->eye_desc;
2127-
char *printable = malloc(lane->nrows * lane->ncols + lane->ncols);
2128-
char *printable_start = printable;
2129-
int i, j;
2127+
uint16_t nrows = le16_to_cpu(lane->nrows);
2128+
uint16_t ncols = le16_to_cpu(lane->ncols);
2129+
struct json_object *eye_array = NULL;
2130+
char *printable_start = NULL;
2131+
char *printable = NULL;
2132+
2133+
if (nrows == 0 || ncols == 0)
2134+
return NULL;
2135+
2136+
eye_array = json_create_array();
2137+
if (!eye_array)
2138+
return NULL;
2139+
2140+
/*
2141+
* Allocate buffer for full printable string (with newlines)
2142+
* +1 for null terminator
2143+
*/
2144+
printable = malloc(nrows * ncols + nrows + 1);
2145+
printable_start = printable;
21302146

21312147
if (!printable)
2132-
goto exit;
2148+
goto fail_free_eye_array;
21332149

2134-
for (i = 0; i < lane->nrows; i++) {
2135-
for (j = 0; j < lane->ncols; j++, printable++)
2136-
sprintf(printable, "%c", eye[i * lane->ncols + j]);
2137-
sprintf(printable++, "\n");
2150+
for (int i = 0; i < nrows; i++) {
2151+
char *row = malloc(ncols + 1);
2152+
2153+
if (!row)
2154+
goto fail_free_eye_printable;
2155+
2156+
for (int j = 0; j < ncols; j++) {
2157+
char ch = eye[i * ncols + j];
2158+
*printable++ = ch;
2159+
row[j] = ch;
2160+
}
2161+
2162+
*printable++ = '\n';
2163+
row[ncols] = '\0';
2164+
2165+
array_add_str(eye_array, row);
2166+
free(row);
21382167
}
21392168

2140-
obj_add_str(r, "printable_eye", printable_start);
2169+
*printable = '\0';
2170+
2171+
obj_add_array(r, "printable_eye", eye_array);
21412172

2142-
exit:
21432173
return printable_start;
2174+
2175+
fail_free_eye_printable:
2176+
free(printable);
2177+
fail_free_eye_array:
2178+
json_free_object(eye_array);
2179+
2180+
return NULL;
21442181
}
21452182

21462183
static void json_phy_rx_eom_descs(struct nvme_phy_rx_eom_log *log,
@@ -2155,7 +2192,20 @@ static void json_phy_rx_eom_descs(struct nvme_phy_rx_eom_log *log,
21552192

21562193
for (i = 0; i < num_descs; i++) {
21572194
struct nvme_eom_lane_desc *desc = p;
2158-
struct json_object *jdesc = json_create_object();
2195+
_cleanup_free_ char *hexstr = NULL;
2196+
unsigned char *vsdata = NULL;
2197+
unsigned int vsdataoffset = 0;
2198+
uint16_t nrows, ncols, edlen;
2199+
struct json_object *jdesc;
2200+
char *hexdata;
2201+
2202+
jdesc = json_create_object();
2203+
if (!desc)
2204+
return;
2205+
2206+
nrows = le16_to_cpu(desc->nrows);
2207+
ncols = le16_to_cpu(desc->ncols);
2208+
edlen = le16_to_cpu(desc->edlen);
21592209

21602210
obj_add_uint(jdesc, "lid", desc->mstatus);
21612211
obj_add_uint(jdesc, "lane", desc->lane);
@@ -2164,14 +2214,36 @@ static void json_phy_rx_eom_descs(struct nvme_phy_rx_eom_log *log,
21642214
obj_add_uint(jdesc, "bottom", le16_to_cpu(desc->bottom));
21652215
obj_add_uint(jdesc, "left", le16_to_cpu(desc->left));
21662216
obj_add_uint(jdesc, "right", le16_to_cpu(desc->right));
2167-
obj_add_uint(jdesc, "nrows", le16_to_cpu(desc->nrows));
2168-
obj_add_uint(jdesc, "ncols", le16_to_cpu(desc->ncols));
2169-
obj_add_uint(jdesc, "edlen", le16_to_cpu(desc->edlen));
2217+
obj_add_uint(jdesc, "nrows", nrows);
2218+
obj_add_uint(jdesc, "ncols", ncols);
2219+
obj_add_uint(jdesc, "edlen", edlen);
21702220

21712221
if (NVME_EOM_ODP_PEFP(log->odp))
2172-
allocated_eyes[i] = json_eom_printable_eye(desc, r);
2222+
allocated_eyes[i] = json_eom_printable_eye(desc, jdesc);
2223+
2224+
if (edlen == 0)
2225+
continue;
2226+
2227+
/* 2 hex chars + space per byte */
2228+
hexstr = malloc(edlen * 3 + 1);
2229+
2230+
if (!hexstr) {
2231+
json_free_object(jdesc);
2232+
return;
2233+
}
2234+
2235+
/* Hex dump Vendor Specific Eye Data */
2236+
vsdataoffset = (nrows * ncols) + sizeof(struct nvme_eom_lane_desc);
2237+
vsdata = (unsigned char *)((unsigned char *)desc + vsdataoffset);
2238+
2239+
hexdata = hexstr;
2240+
2241+
for (int offset = 0; offset < edlen; offset++)
2242+
hexdata += sprintf(hexdata, "%02X ", vsdata[offset]);
2243+
/* remove trailing space */
2244+
*(hexdata - 1) = '\0';
21732245

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

21762248
array_add_obj(descs, jdesc);
21772249

nvme-print-stdout.c

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -776,9 +776,9 @@ static void stdout_eom_printable_eye(struct nvme_eom_lane_desc *lane)
776776
char *eye = (char *)lane->eye_desc;
777777
int i, j;
778778

779-
for (i = 0; i < lane->nrows; i++) {
780-
for (j = 0; j < lane->ncols; j++)
781-
printf("%c", eye[i * lane->ncols + j]);
779+
for (i = 0; i < le16_to_cpu(lane->nrows); i++) {
780+
for (j = 0; j < le16_to_cpu(lane->ncols); j++)
781+
printf("%c", eye[i * le16_to_cpu(lane->ncols) + j]);
782782
printf("\n");
783783
}
784784
}
@@ -790,6 +790,13 @@ static void stdout_phy_rx_eom_descs(struct nvme_phy_rx_eom_log *log)
790790

791791
for (i = 0; i < log->nd; i++) {
792792
struct nvme_eom_lane_desc *desc = p;
793+
unsigned char *vsdata = NULL;
794+
unsigned int vsdataoffset = 0;
795+
uint16_t nrows, ncols, edlen;
796+
797+
nrows = le16_to_cpu(desc->nrows);
798+
ncols = le16_to_cpu(desc->ncols);
799+
edlen = le16_to_cpu(desc->edlen);
793800

794801
printf("Measurement Status: %s\n",
795802
desc->mstatus ? "Successful" : "Not Successful");
@@ -799,14 +806,28 @@ static void stdout_phy_rx_eom_descs(struct nvme_phy_rx_eom_log *log)
799806
printf("Bottom: %u\n", le16_to_cpu(desc->bottom));
800807
printf("Left: %u\n", le16_to_cpu(desc->left));
801808
printf("Right: %u\n", le16_to_cpu(desc->right));
802-
printf("Number of Rows: %u\n", le16_to_cpu(desc->nrows));
803-
printf("Number of Columns: %u\n", le16_to_cpu(desc->ncols));
804-
printf("Eye Data Length: %u\n", le16_to_cpu(desc->edlen));
809+
printf("Number of Rows: %u\n", nrows);
810+
printf("Number of Columns: %u\n", ncols);
811+
printf("Eye Data Length: %u\n", desc->edlen);
805812

806813
if (NVME_EOM_ODP_PEFP(log->odp))
807814
stdout_eom_printable_eye(desc);
808815

809816
/* Eye Data field is vendor specific */
817+
if (edlen == 0)
818+
continue;
819+
820+
/* Hex dump Vendor Specific Eye Data */
821+
vsdata = malloc(edlen);
822+
if (!vsdata)
823+
return;
824+
825+
vsdataoffset = (nrows * ncols) + sizeof(struct nvme_eom_lane_desc);
826+
vsdata = (unsigned char *)((unsigned char *)desc + vsdataoffset);
827+
printf("Eye Data:\n");
828+
d(vsdata, edlen, 16, 1);
829+
printf("\n");
830+
free(vsdata);
810831

811832
p += log->dsize;
812833
}

plugins/micron/micron-nvme.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
*
55
* @file: micron-nvme.c
66
* @brief: This module contains all the constructs needed for micron nvme-cli plugin.
7-
* @authors:Chaithanya Shoba <[email protected]>,
7+
* @authors:Hanumanthu H <[email protected]>
8+
* Chaithanya Shoba <[email protected]>
9+
* Sivaprasad Gutha <[email protected]>
810
*/
911

1012
#include <stdio.h>

plugins/micron/micron-nvme.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
*
44
* @file: micron-nvme.h
55
* @brief: This module contains all the constructs needed for micron nvme-cli plugin.
6-
* @authors:Chaithanya Shoba <[email protected]>,
6+
* @authors:Hanumanthu H <[email protected]>
7+
* Chaithanya Shoba <[email protected]>
8+
* Sivaprasad Gutha <[email protected]>
79
*/
810

911
#undef CMD_INC_FILE

0 commit comments

Comments
 (0)