Skip to content

Commit d5a6069

Browse files
committed
Comment updates
Update user help format insert macro Added additional message in help text to let user know each dword must start with a 0x. Added a macro to handle the max amount of dwords per TLP request. Added check for dwords Added an additional check and error message to ensure that nothing greater than a dword is sent in each section of the tlp. Convert host byte order to le byte order
1 parent 432cdbb commit d5a6069

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

cli/diag.c

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ struct diag_common_cfg {
6565
"return the data for the previous link", \
6666
}
6767

68+
#define TLP_MAX_DWS 132
69+
6870
static int get_port(struct switchtec_dev *dev, int port_id,
6971
struct switchtec_status *port)
7072
{
@@ -2030,13 +2032,21 @@ static int convert_str_to_dwords(char *str, uint32_t **dwords, int *num_dwords)
20302032
{
20312033
*num_dwords = 0;
20322034
const char *ptr = str;
2035+
int dword_len = 0;
20332036
while (*ptr != '\0') {
20342037
if (*ptr == '0' && *(ptr + 1) == 'x') {
20352038
(*num_dwords)++;
20362039
ptr += 2;
2040+
dword_len = 0;
20372041
}
2038-
while (*ptr != ' ' && *ptr != '\0')
2042+
while (*ptr != ' ' && *ptr != '\0') {
20392043
ptr++;
2044+
dword_len++;
2045+
}
2046+
if (dword_len > 8) {
2047+
printf("Entered dword longer than allowed\n");
2048+
return -1;
2049+
}
20402050
if (*ptr == ' ')
20412051
ptr++;
20422052
}
@@ -2088,7 +2098,7 @@ static int tlp_inject (int argc, char **argv)
20882098
"Enable the ecrc to be included at the end of the input data (Default: disabled)"},
20892099
{"tlp_data", 'd', "\"DW0 DW1 ... DW131\"", CFG_STRING,
20902100
&cfg.raw_tlp_data, required_argument,
2091-
"DWs to be sent as part of the raw TLP (Maximum 132 DWs)"},
2101+
"DWs to be sent as part of the raw TLP (Maximum 132 DWs). Every DW must start with \'0x\'"},
20922102
{NULL}
20932103
};
20942104

@@ -2104,8 +2114,8 @@ static int tlp_inject (int argc, char **argv)
21042114
fprintf(stderr, "Error with tlp data provided \n");
21052115
return -1;
21062116
}
2107-
if (num_dwords > 132) {
2108-
fprintf(stderr, "TLP data cannot exceed 132 dwords \n");
2117+
if (num_dwords > TLP_MAX_DWS) {
2118+
fprintf(stderr, "TLP data cannot exceed %d dwords \n", TLP_MAX_DWS);
21092119
free(raw_tlp_dwords);
21102120
return -1;
21112121
}

lib/diag.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1227,7 +1227,7 @@ int switchtec_tlp_inject(struct switchtec_dev * dev, int port_id, int tlp_type,
12271227
};
12281228
for (int i = 0; i < tlp_in.tlp_length; i++)
12291229
{
1230-
tlp_in.raw_tlp_data[i] = *(raw_tlp_data + i);
1230+
tlp_in.raw_tlp_data[i] = htole32(*(raw_tlp_data + i));
12311231
}
12321232
free(raw_tlp_data);
12331233

0 commit comments

Comments
 (0)