Skip to content

Commit ace290c

Browse files
vigneshraja123717root
authored andcommitted
resolved code review comments
1 parent 56dbfba commit ace290c

File tree

6 files changed

+79
-140
lines changed

6 files changed

+79
-140
lines changed

cli/diag.c

Lines changed: 15 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1082,69 +1082,29 @@ static int crosshair(int argc, char **argv)
10821082
return ret;
10831083
}
10841084

1085-
int eye_observe_dev(struct switchtec_dev *dev, int port_id,
1085+
int eye_observe_dev(struct switchtec_dev *dev, unsigned int error_threshold,
10861086
int lane_id, int *gen)
10871087
{
10881088
int ret;
10891089
struct switchtec_diag_port_eye_data data_out;
1090-
unsigned int eye_data[6];
1090+
int eye_data[4];
10911091

1092-
ret = switchtec_diag_eye_start(dev, lane_id);
1092+
ret = switchtec_diag_eye_start(dev, lane_id, error_threshold);
10931093
if (ret) {
10941094
switchtec_perror("eye_start");
10951095
}
10961096

1097+
printf("started\n");
10971098
ret = switchtec_diag_eye_fetch(dev, &data_out);
10981099

1099-
data_out.eye_left = abs(data_out.eye_left);
1100-
data_out.eye_right = abs(data_out.eye_right);
1101-
data_out.eye_top_x1 = abs(data_out.eye_top_x1);
1102-
data_out.eye_bottom_x1 = abs(data_out.eye_bottom_x1);
1103-
1104-
printf("%d %d %d %d\n", data_out.eye_left, data_out.eye_right, data_out.eye_top_x1, data_out.eye_bottom_x1);
11051100
memcpy(&eye_data[0], &data_out, sizeof(struct switchtec_diag_port_eye_data));
1106-
graph_draw_eom_win(eye_data, 4,"Eye Observation Monitor","press q to quit");
1107-
return 0;
1108-
}
1109-
1110-
static int eye_graph(enum output_format fmt, struct range *X, struct range *Y,
1111-
double *pixels, const char *title,
1112-
struct switchtec_diag_cross_hair *ch)
1113-
{
1114-
size_t pixel_cnt = RANGE_CNT(X) * RANGE_CNT(Y);
1115-
int data[pixel_cnt], shades[pixel_cnt];
1116-
const struct crosshair_chars *chars;
1117-
struct crosshair_chars chars_curses;
1118-
char status[50], *status_ptr = NULL;
1119-
1120-
eye_graph_data(X, Y, pixels, data, shades);
1121-
1122-
if (ch) {
1123-
if (fmt == FMT_CURSES) {
1124-
graph_init();
1125-
chars_curses.hline = GRAPH_HLINE;
1126-
chars_curses.vline = GRAPH_VLINE;
1127-
chars_curses.plus = GRAPH_PLUS;
1128-
chars = &chars_curses;
1129-
} else {
1130-
chars = crosshair_text_chars();
1131-
}
1132-
1133-
crosshair_plot(X, Y, data, shades, ch, chars);
1134-
1135-
sprintf(status, " W2H=%d", crosshair_w2h(ch));
1136-
status_ptr = status;
1137-
}
1138-
1139-
if (fmt == FMT_TEXT) {
1140-
graph_draw_text(X, Y, data, title, 'T', 'V');
1141-
if (status_ptr)
1142-
printf("\n %s\n", status_ptr);
1143-
return 0;
1101+
1102+
if (!ret)
1103+
{
1104+
eye_plot_graph(eye_data);
11441105
}
1145-
1146-
return graph_draw_win(X, Y, data, shades, title, 'T', 'V',
1147-
status_ptr, NULL, NULL);
1106+
1107+
return 0;
11481108
}
11491109

11501110
#define CMD_DESC_EYE "Capture PCIe Eye Errors"
@@ -1156,14 +1116,14 @@ static int eye(int argc, char **argv)
11561116
static struct {
11571117
struct switchtec_dev *dev;
11581118
int fmt;
1159-
int port_id;
11601119
int lane_id;
1120+
unsigned int error_threshold;
11611121
int t_step, v_step;
11621122
} cfg = {
11631123
.fmt = FMT_DEFAULT,
1164-
.port_id = -1,
11651124
.lane_id = 0,
11661125
.t_step = 1,
1126+
.error_threshold = 4,
11671127
.v_step = 1,
11681128
};
11691129
const struct argconfig_options opts[] = {
@@ -1173,8 +1133,8 @@ static int eye(int argc, char **argv)
11731133
.choices=output_fmt_choices},
11741134
{"lane", 'l', "LANE_ID", CFG_NONNEGATIVE, &cfg.lane_id,
11751135
required_argument, "lane id within the port to observe"},
1176-
{"port", 'p', "PORT_ID", CFG_NONNEGATIVE, &cfg.port_id,
1177-
required_argument, "physical port ID to observe"},
1136+
{"error threshold", 't',"ERROR THRESHOLD", CFG_NONNEGATIVE, &cfg.error_threshold,
1137+
optional_argument, "Maximum allowed errors"},
11781138
{"t-step", 's', "NUM", CFG_NONNEGATIVE, &cfg.t_step,
11791139
required_argument, "time step (default 1)"},
11801140
{"v-step", 'S', "NUM", CFG_NONNEGATIVE, &cfg.v_step,
@@ -1184,7 +1144,7 @@ static int eye(int argc, char **argv)
11841144
argconfig_parse(argc, argv, CMD_DESC_EYE, opts, &cfg,
11851145
sizeof(cfg));
11861146

1187-
ret = eye_observe_dev(cfg.dev, cfg.port_id, cfg.lane_id, &gen);
1147+
ret = eye_observe_dev(cfg.dev, cfg.lane_id, cfg.error_threshold, &gen);
11881148

11891149
return ret;
11901150
}

cli/graph.c

Lines changed: 40 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -374,95 +374,57 @@ void graph_init(void)
374374
curses_initialized = true;
375375
}
376376

377-
void draw_eom_data(WINDOW *win, unsigned int *data, int count, int x_offset, int y_offset)
378-
{
379-
for (int i = 0; i < count; ++i) {
380-
int xl = data[i] + x_offset;
381-
int xr = data[i] + x_offset;
382-
int yt = data[i] + y_offset;
383-
int yb = data[i] + y_offset;
384-
385-
// Draw points
386-
mvwaddch(win, yt, xl, 'L'); // Left
387-
mvwaddch(win, yt, xr, 'R'); // Right
388-
mvwaddch(win, yt, xl, 'T'); // Top
389-
mvwaddch(win, yb, xl, 'B'); // Bottom
390-
391-
// Draw horizontal line (left to right at eye_top)
392-
for (int x = xl; x <= xr; ++x)
393-
mvwaddch(win, yt, x, '-');
394-
395-
// Draw vertical line (top to bottom at eye_left)
396-
for (int y = yt; y <= yb; ++y)
397-
mvwaddch(win, y, xl, '|');
398-
}
399-
wrefresh(win);
377+
void get_screen_coords(int x, int y, int *sx, int *sy) {
378+
*sx = x*X_SCALE + 5;
379+
*sy = y/Y_SCALE;
400380
}
401381

402-
int graph_draw_eom_win(unsigned int *data, int count, const char *title, char *status)
382+
void plot_point(int x, int y)
403383
{
404-
WINDOW *datawin, *stwin = NULL;
405-
const int x_off = 7, y_off = 4;
406-
int s_off;
407-
int c;
408-
printf("%d %d %d %d\n", data[0], data[1], data[2], data[3]);
409-
if (!isatty(STDOUT_FILENO)) {
410-
// Fallback to text output if not a terminal
411-
return 0;
412-
}
413-
414-
if (!curses_initialized) {
415-
initscr();
416-
curses_initialized = true;
417-
}
384+
printf("X %d Y %d\n", x, y);
385+
mvprintw(y/Y_SCALE, x*X_SCALE, "O (%d,%d)", x-Y_PRINT_OFFSET, y-X_PRINT_OFFSET);
386+
}
418387

388+
int eye_plot_graph(int *data)
389+
{
390+
initscr();
419391
noecho();
420-
cbreak();
421-
curs_set(0);
422-
keypad(stdscr, true);
423-
start_color();
424-
425-
if (status) {
426-
s_off = 2;
427-
stwin = newwin(2, 0, LINES - 2, 0);
428-
if (!stwin) {
429-
perror("Unable to create window");
430-
return 1;
431-
}
432-
} else {
433-
s_off = 0;
392+
curs_set(FALSE);
393+
// Draw axes
394+
for (int x = 0; x <= PLOT_WIDTH; ++x)
395+
mvaddch(0, (x*X_SCALE) + 5, '-'); // X-axis at the top
396+
for (int y = 0; y <= PLOT_HEIGHT; ++y)
397+
mvaddch(y/Y_SCALE, 5, '|'); // Y-axis at the left
398+
// Draw scale on X-axis
399+
for (int x = 0; x <= PLOT_WIDTH; x += 5)
400+
{
401+
mvaddch(0, (x*X_SCALE) + 5, '+');
402+
mvprintw(1, (x*X_SCALE) + 5, "%d", x);
434403
}
435-
436-
datawin = newwin(LINES - y_off - s_off, COLS - x_off, y_off, x_off);
437-
if (!datawin) {
438-
perror("Unable to create window");
439-
return 1;
404+
// Draw scale on Y-axis
405+
for (int y = 0; y <= PLOT_HEIGHT; y += 10) {
406+
mvaddch(y/Y_SCALE, 5, '+');
407+
mvprintw(y/Y_SCALE, 0, "%2d", y);
440408
}
441409

442-
// Main loop
443-
while (1) {
444-
werase(datawin);
445-
box(datawin, 0, 0);
446-
draw_eom_data(datawin, data, count, 0, 0);
447-
448-
if (stwin) {
449-
werase(stwin);
450-
mvwprintw(stwin, 0, 0, "%s", status);
451-
wrefresh(stwin);
452-
}
453-
454-
c = getch();
455-
if (c == 'q' || c == 'x')
456-
break;
457-
}
458-
459-
if (stwin)
460-
delwin(stwin);
461-
delwin(datawin);
410+
//Adjusting the eye points to plot from 0 to 42 for x-axis and 0 t0 100 for Y-axis
411+
//as ncurses library did not support negative ploting
412+
data[0] = data[0] + X_LAYOUT_SHIFT;
413+
data[1] = data[1] + X_LAYOUT_SHIFT;
414+
data[2] = data[2] + Y_LAYOUT_SHIFT;
415+
data[3] = data[3] + Y_LAYOUT_SHIFT;
416+
417+
// Plot some points (example)
418+
plot_point(data[0] + Y_PRINT_OFFSET, Y_LAYOUT_SHIFT + X_PRINT_OFFSET); // (10,5)
419+
plot_point(data[1] + Y_PRINT_OFFSET, Y_LAYOUT_SHIFT + X_PRINT_OFFSET); // (20,10)
420+
plot_point(X_LAYOUT_SHIFT + Y_PRINT_OFFSET, data[2] + X_PRINT_OFFSET); // (30,15)
421+
plot_point(X_LAYOUT_SHIFT + Y_PRINT_OFFSET, data[3] + X_PRINT_OFFSET); // (35,18)
422+
423+
refresh();
424+
getch();
462425
endwin();
463426
return 0;
464427
}
465-
466428
#else /* defined(HAVE_LIBCURSES) || defined(HAVE_LIBNCURSES) */
467429

468430
int graph_draw_win(struct range *X, struct range *Y, int *data, int *shades,

cli/graph.h

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,23 @@
5757
#define GRAPH_PLUS GRAPH_TEXT_PLUS
5858
#endif
5959

60+
#define PLOT_WIDTH 42
61+
#define PLOT_HEIGHT 100// Map data coordinates to screen coordinates (top-left origin)
62+
#define Y_SCALE 2
63+
#define X_SCALE 4
64+
#define X_PRINT_OFFSET 1
65+
#define Y_PRINT_OFFSET 2
66+
#define X_LAYOUT_SHIFT 21
67+
#define Y_LAYOUT_SHIFT 50
68+
6069
struct range;
6170

71+
typedef struct {
72+
int x;
73+
int y;
74+
}point_t;
75+
76+
6277
typedef int graph_anim_fn(struct range *X, struct range *Y, int *data,
6378
int *shades, char *status, bool *redraw, void *opaque);
6479

@@ -69,6 +84,6 @@ int graph_draw_win(struct range *X, struct range *Y, int *data, int *shades,
6984
const char *title, char x_title, char y_title, char *status,
7085
graph_anim_fn *anim, void *opaque);
7186

72-
int graph_draw_eom_win(unsigned int *data, int count, const char *title, char *status);
87+
int eye_plot_graph(int *data);
7388

7489
#endif

inc/switchtec/switchtec.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1242,7 +1242,7 @@ int switchtec_diag_cross_hair_get(struct switchtec_dev *dev, int start_lane_id,
12421242

12431243
int switchtec_diag_eye_set_mode(struct switchtec_dev *dev,
12441244
enum switchtec_diag_eye_data_mode mode);
1245-
int switchtec_diag_eye_start(struct switchtec_dev *dev, int lane_id);
1245+
int switchtec_diag_eye_start(struct switchtec_dev *dev, int lane_id, unsigned int error_threshold);
12461246
int switchtec_diag_eye_fetch(struct switchtec_dev *dev, struct switchtec_diag_port_eye_data *data_out);
12471247
int switchtec_diag_eye_cancel(struct switchtec_dev *dev);
12481248

lib/diag.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,15 +165,15 @@ static int switchtec_diag_eye_cmd(struct switchtec_dev *dev, void *in,
165165
*
166166
* @return 0 on success, error code on failure
167167
*/
168-
int switchtec_diag_eye_start(struct switchtec_dev *dev, int lane)
168+
int switchtec_diag_eye_start(struct switchtec_dev *dev, int lane, unsigned int error_threshold)
169169
{
170170
int err;
171171
int ret;
172172
struct switchtec_diag_port_eye_start in = {
173173
.sub_cmd = MRPC_EYE_OBSERVE_START,
174174
.lane_id = lane,
175175
.target_ber_type = 0,
176-
.max_allowed_ber_errors = 4,
176+
.max_allowed_ber_errors = error_threshold,
177177
.confidence_lvl = 95,
178178
.x_step = 1,
179179
.y_step = 1,
@@ -231,6 +231,7 @@ int switchtec_diag_eye_fetch(struct switchtec_dev *dev, struct switchtec_diag_po
231231
if (ret)
232232
return ret;
233233

234+
printf("status %d\n", out.status);
234235
if(out.status > 9)
235236
{
236237
return ret;
@@ -255,7 +256,8 @@ int switchtec_diag_eye_fetch(struct switchtec_dev *dev, struct switchtec_diag_po
255256
}
256257
else
257258
{
258-
printf("EOM Status %s\n", diag_eom_status_string[out.status]);
259+
printf("EOM Status %s\n", diag_eom_status_string[out.status]);
260+
return -1;
259261
}
260262

261263
return 0;

lib/platform/gasops.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ static const struct no_retry_struct gasop_noretry_cmds[] = {
6666
[MRPC_SECURITY_CONFIG_SET_GEN5] = {1, 0, NULL},
6767
[MRPC_FW_TX] = {1, 1, fw_toggle_noretry_subcmds},
6868
};
69-
static const int gasop_noretry_cmds_count = sizeof(gasop_noretry_cmds) /
70-
sizeof(char);
69+
static const int gasop_noretry_cmds_count = (sizeof(gasop_noretry_cmds)) /
70+
(sizeof(char));
7171

7272
static inline bool gasop_is_no_retry_cmd(uint32_t cmd, int subcmd)
7373
{

0 commit comments

Comments
 (0)