Skip to content

Commit 31ad75e

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 - Add macro in header + minor formatting Added TLP_MAX_DWS in the diag header to be used in the structure defining the maximum in the dword data. Fixed some small issues with format. - add max dword macro to switchtec.h Removed refences to max tlp dword macro from the cli/diag.c and diag.h to add the macro in switchtec header and include in diag.h. Reformatted the name to be more inline with the current naming scheme of the switchtec macros.
1 parent 432cdbb commit 31ad75e

File tree

4 files changed

+20
-8
lines changed

4 files changed

+20
-8
lines changed

cli/diag.c

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2030,13 +2030,21 @@ static int convert_str_to_dwords(char *str, uint32_t **dwords, int *num_dwords)
20302030
{
20312031
*num_dwords = 0;
20322032
const char *ptr = str;
2033+
int dword_len = 0;
20332034
while (*ptr != '\0') {
20342035
if (*ptr == '0' && *(ptr + 1) == 'x') {
20352036
(*num_dwords)++;
20362037
ptr += 2;
2038+
dword_len = 0;
20372039
}
2038-
while (*ptr != ' ' && *ptr != '\0')
2040+
while (*ptr != ' ' && *ptr != '\0') {
20392041
ptr++;
2042+
dword_len++;
2043+
}
2044+
if (dword_len > 8) {
2045+
printf("Entered dword longer than allowed\n");
2046+
return -1;
2047+
}
20402048
if (*ptr == ' ')
20412049
ptr++;
20422050
}
@@ -2088,7 +2096,7 @@ static int tlp_inject (int argc, char **argv)
20882096
"Enable the ecrc to be included at the end of the input data (Default: disabled)"},
20892097
{"tlp_data", 'd', "\"DW0 DW1 ... DW131\"", CFG_STRING,
20902098
&cfg.raw_tlp_data, required_argument,
2091-
"DWs to be sent as part of the raw TLP (Maximum 132 DWs)"},
2099+
"DWs to be sent as part of the raw TLP (Maximum 132 DWs). Every DW must start with \'0x\'"},
20922100
{NULL}
20932101
};
20942102

@@ -2104,8 +2112,9 @@ static int tlp_inject (int argc, char **argv)
21042112
fprintf(stderr, "Error with tlp data provided \n");
21052113
return -1;
21062114
}
2107-
if (num_dwords > 132) {
2108-
fprintf(stderr, "TLP data cannot exceed 132 dwords \n");
2115+
if (num_dwords > SWITCHTEC_DIAG_MAX_TLP_DWORDS) {
2116+
fprintf(stderr, "TLP data cannot exceed %d dwords \n",
2117+
SWITCHTEC_DIAG_MAX_TLP_DWORDS);
21092118
free(raw_tlp_dwords);
21102119
return -1;
21112120
}

inc/switchtec/diag.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
#ifndef LIBSWITCHTEC_DIAG_H
2626
#define LIBSWITCHTEC_DIAG_H
2727

28+
#include "switchtec.h"
29+
2830
#include <stdint.h>
2931

3032
/**
@@ -284,7 +286,7 @@ struct switchtec_tlp_inject_in {
284286
uint32_t tlp_type;
285287
uint32_t tlp_length;
286288
uint32_t ecrc;
287-
uint32_t raw_tlp_data[132];
289+
uint32_t raw_tlp_data[SWITCHTEC_DIAG_MAX_TLP_DWORDS];
288290
};
289291

290292
#endif

inc/switchtec/switchtec.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ struct switchtec_dev;
6666
#define SWITCHTEC_PAX_ID_MASK 0x1f
6767
#define SWITCHTEC_PAX_ID_LOCAL SWITCHTEC_PAX_ID_MASK
6868

69+
#define SWITCHTEC_DIAG_MAX_TLP_DWORDS 132
70+
6971
#ifdef __CHECKER__
7072
#define __gas __attribute__((noderef, address_space(1)))
7173
#else

lib/diag.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1225,9 +1225,8 @@ int switchtec_tlp_inject(struct switchtec_dev * dev, int port_id, int tlp_type,
12251225
.tlp_length = tlp_length,
12261226
.ecrc = ecrc
12271227
};
1228-
for (int i = 0; i < tlp_in.tlp_length; i++)
1229-
{
1230-
tlp_in.raw_tlp_data[i] = *(raw_tlp_data + i);
1228+
for (int i = 0; i < tlp_in.tlp_length; i++) {
1229+
tlp_in.raw_tlp_data[i] = htole32(*(raw_tlp_data + i));
12311230
}
12321231
free(raw_tlp_data);
12331232

0 commit comments

Comments
 (0)