30#define SWITCHTEC_LIB_CORE
32#include "switchtec_priv.h"
35#include "switchtec/mrpc.h"
36#include "switchtec/errors.h"
37#include "switchtec/log.h"
38#include "switchtec/endian.h"
39#include "switchtec/utils.h"
81 unsigned short device_id;
90 {0x8531, SWITCHTEC_GEN3, SWITCHTEC_PFX},
91 {0x8532, SWITCHTEC_GEN3, SWITCHTEC_PFX},
92 {0x8533, SWITCHTEC_GEN3, SWITCHTEC_PFX},
93 {0x8534, SWITCHTEC_GEN3, SWITCHTEC_PFX},
94 {0x8535, SWITCHTEC_GEN3, SWITCHTEC_PFX},
95 {0x8536, SWITCHTEC_GEN3, SWITCHTEC_PFX},
96 {0x8541, SWITCHTEC_GEN3, SWITCHTEC_PSX},
97 {0x8542, SWITCHTEC_GEN3, SWITCHTEC_PSX},
98 {0x8543, SWITCHTEC_GEN3, SWITCHTEC_PSX},
99 {0x8544, SWITCHTEC_GEN3, SWITCHTEC_PSX},
100 {0x8545, SWITCHTEC_GEN3, SWITCHTEC_PSX},
101 {0x8546, SWITCHTEC_GEN3, SWITCHTEC_PSX},
102 {0x8551, SWITCHTEC_GEN3, SWITCHTEC_PAX},
103 {0x8552, SWITCHTEC_GEN3, SWITCHTEC_PAX},
104 {0x8553, SWITCHTEC_GEN3, SWITCHTEC_PAX},
105 {0x8554, SWITCHTEC_GEN3, SWITCHTEC_PAX},
106 {0x8555, SWITCHTEC_GEN3, SWITCHTEC_PAX},
107 {0x8556, SWITCHTEC_GEN3, SWITCHTEC_PAX},
108 {0x8561, SWITCHTEC_GEN3, SWITCHTEC_PFXL},
109 {0x8562, SWITCHTEC_GEN3, SWITCHTEC_PFXL},
110 {0x8563, SWITCHTEC_GEN3, SWITCHTEC_PFXL},
111 {0x8564, SWITCHTEC_GEN3, SWITCHTEC_PFXL},
112 {0x8565, SWITCHTEC_GEN3, SWITCHTEC_PFXL},
113 {0x8566, SWITCHTEC_GEN3, SWITCHTEC_PFXL},
114 {0x8571, SWITCHTEC_GEN3, SWITCHTEC_PFXI},
115 {0x8572, SWITCHTEC_GEN3, SWITCHTEC_PFXI},
116 {0x8573, SWITCHTEC_GEN3, SWITCHTEC_PFXI},
117 {0x8574, SWITCHTEC_GEN3, SWITCHTEC_PFXI},
118 {0x8575, SWITCHTEC_GEN3, SWITCHTEC_PFXI},
119 {0x8576, SWITCHTEC_GEN3, SWITCHTEC_PFXI},
120 {0x4000, SWITCHTEC_GEN4, SWITCHTEC_PFX},
121 {0x4084, SWITCHTEC_GEN4, SWITCHTEC_PFX},
122 {0x4068, SWITCHTEC_GEN4, SWITCHTEC_PFX},
123 {0x4052, SWITCHTEC_GEN4, SWITCHTEC_PFX},
124 {0x4036, SWITCHTEC_GEN4, SWITCHTEC_PFX},
125 {0x4028, SWITCHTEC_GEN4, SWITCHTEC_PFX},
126 {0x4100, SWITCHTEC_GEN4, SWITCHTEC_PSX},
127 {0x4184, SWITCHTEC_GEN4, SWITCHTEC_PSX},
128 {0x4168, SWITCHTEC_GEN4, SWITCHTEC_PSX},
129 {0x4152, SWITCHTEC_GEN4, SWITCHTEC_PSX},
130 {0x4136, SWITCHTEC_GEN4, SWITCHTEC_PSX},
131 {0x4128, SWITCHTEC_GEN4, SWITCHTEC_PSX},
132 {0x4200, SWITCHTEC_GEN4, SWITCHTEC_PAX},
133 {0x4284, SWITCHTEC_GEN4, SWITCHTEC_PAX},
134 {0x4268, SWITCHTEC_GEN4, SWITCHTEC_PAX},
135 {0x4252, SWITCHTEC_GEN4, SWITCHTEC_PAX},
136 {0x4236, SWITCHTEC_GEN4, SWITCHTEC_PAX},
137 {0x4352, SWITCHTEC_GEN4, SWITCHTEC_PFXA},
138 {0x4336, SWITCHTEC_GEN4, SWITCHTEC_PFXA},
139 {0x4328, SWITCHTEC_GEN4, SWITCHTEC_PFXA},
140 {0x4452, SWITCHTEC_GEN4, SWITCHTEC_PSXA},
141 {0x4436, SWITCHTEC_GEN4, SWITCHTEC_PSXA},
142 {0x4428, SWITCHTEC_GEN4, SWITCHTEC_PSXA},
143 {0x4552, SWITCHTEC_GEN4, SWITCHTEC_PAXA},
144 {0x4536, SWITCHTEC_GEN4, SWITCHTEC_PAXA},
145 {0x4528, SWITCHTEC_GEN4, SWITCHTEC_PAXA},
146 {0x4228, SWITCHTEC_GEN4, SWITCHTEC_PAX},
147 {0x5000, SWITCHTEC_GEN5, SWITCHTEC_PFX},
148 {0x5084, SWITCHTEC_GEN5, SWITCHTEC_PFX},
149 {0x5068, SWITCHTEC_GEN5, SWITCHTEC_PFX},
150 {0x5052, SWITCHTEC_GEN5, SWITCHTEC_PFX},
151 {0x5036, SWITCHTEC_GEN5, SWITCHTEC_PFX},
152 {0x5028, SWITCHTEC_GEN5, SWITCHTEC_PFX},
153 {0x5100, SWITCHTEC_GEN5, SWITCHTEC_PSX},
154 {0x5184, SWITCHTEC_GEN5, SWITCHTEC_PSX},
155 {0x5168, SWITCHTEC_GEN5, SWITCHTEC_PSX},
156 {0x5152, SWITCHTEC_GEN5, SWITCHTEC_PSX},
157 {0x5136, SWITCHTEC_GEN5, SWITCHTEC_PSX},
158 {0x5128, SWITCHTEC_GEN5, SWITCHTEC_PSX},
159 {0x5200, SWITCHTEC_GEN5, SWITCHTEC_PAX},
160 {0x5284, SWITCHTEC_GEN5, SWITCHTEC_PAX},
161 {0x5268, SWITCHTEC_GEN5, SWITCHTEC_PAX},
162 {0x5252, SWITCHTEC_GEN5, SWITCHTEC_PAX},
163 {0x5236, SWITCHTEC_GEN5, SWITCHTEC_PAX},
164 {0x5228, SWITCHTEC_GEN5, SWITCHTEC_PAX},
165 {0x5300, SWITCHTEC_GEN5, SWITCHTEC_PFXA},
166 {0x5384, SWITCHTEC_GEN5, SWITCHTEC_PFXA},
167 {0x5368, SWITCHTEC_GEN5, SWITCHTEC_PFXA},
168 {0x5352, SWITCHTEC_GEN5, SWITCHTEC_PFXA},
169 {0x5336, SWITCHTEC_GEN5, SWITCHTEC_PFXA},
170 {0x5328, SWITCHTEC_GEN5, SWITCHTEC_PFXA},
171 {0x5400, SWITCHTEC_GEN5, SWITCHTEC_PSXA},
172 {0x5484, SWITCHTEC_GEN5, SWITCHTEC_PSXA},
173 {0x5468, SWITCHTEC_GEN5, SWITCHTEC_PSXA},
174 {0x5452, SWITCHTEC_GEN5, SWITCHTEC_PSXA},
175 {0x5436, SWITCHTEC_GEN5, SWITCHTEC_PSXA},
176 {0x5428, SWITCHTEC_GEN5, SWITCHTEC_PSXA},
177 {0x5500, SWITCHTEC_GEN5, SWITCHTEC_PAXA},
178 {0x5584, SWITCHTEC_GEN5, SWITCHTEC_PAXA},
179 {0x5568, SWITCHTEC_GEN5, SWITCHTEC_PAXA},
180 {0x5552, SWITCHTEC_GEN5, SWITCHTEC_PAXA},
181 {0x5536, SWITCHTEC_GEN5, SWITCHTEC_PAXA},
182 {0x5528, SWITCHTEC_GEN5, SWITCHTEC_PAXA},
186static int set_gen_variant(
struct switchtec_dev * dev)
191 dev->boot_phase = SWITCHTEC_BOOT_PHASE_FW;
192 dev->gen = SWITCHTEC_GEN_UNKNOWN;
193 dev->var = SWITCHTEC_VAR_UNKNOWN;
194 dev->device_id = dev->ops->get_device_id(dev);
196 switchtec_get_device_id_bl2(dev,
197 (
unsigned short *)&dev->device_id);
199 while (id->device_id) {
200 if (id->device_id == dev->device_id) {
210 dev->pax_id = SWITCHTEC_PAX_ID_LOCAL;
218static int set_local_pax_id(
struct switchtec_dev *dev)
220 unsigned char local_pax_id;
223 dev->local_pax_id = -1;
229 &local_pax_id,
sizeof(local_pax_id));
233 dev->local_pax_id = local_pax_id;
271 struct switchtec_dev *ret;
273 if (sscanf(device,
"%i@%i", &bus, &dev) == 2) {
274 ret = switchtec_open_i2c_by_adapter(bus, dev);
278 if (sscanf(device,
"%2049[^@]@%i", path, &dev) == 2) {
283 if (device[0] ==
'/' &&
284 sscanf(device,
"%2049[^:]:%i", path, &dev) == 2) {
289 if (strchr(device,
'/') || strchr(device,
'\\')) {
294 if (sscanf(device,
"%x:%x.%x", &bus, &dev, &func) == 3) {
299 if (sscanf(device,
"%x:%x:%x.%x", &domain, &bus, &dev, &func) == 4) {
304 if (sscanf(device,
"%2049[^:]:%i", path, &inst) == 2) {
310 idx = strtol(device, &endptr, 0);
311 if (!errno && endptr != device) {
316 if (sscanf(device,
"switchtec%d", &idx) == 1) {
330 snprintf(ret->name,
sizeof(ret->name),
"%s", device);
332 if (set_gen_variant(ret))
335 if (set_local_pax_id(ret))
350 return dev->device_id;
386 return dev->boot_phase;
408 return dev->partition;
411int switchtec_set_pax_id(
struct switchtec_dev *dev,
int pax_id)
416 if (pax_id == SWITCHTEC_PAX_ID_LOCAL)
417 dev->pax_id = dev->local_pax_id;
419 dev->pax_id = pax_id;
424static int compare_port_id(
const void *aa,
const void *bb)
432 return a->
log_id - b->log_id;
435static int compare_status(
const void *aa,
const void *bb)
439 return compare_port_id(&a->
port, &b->port);
449 case 0:
return "Normal Lane Ordering";
450 case 1:
return "x16 (Full) Lane Reversal";
451 case 2:
return "x2 Lane Reversal";
452 case 4:
return "x4 Lane Reversal";
453 case 8:
return "x8 Lane Reversal";
454 default:
return "Unknown Lane Ordering";
477 s->lanes[l] =
'0' + i;
479 s->lanes[l] =
'a' + i - 10;
499 uint64_t port_bitmap = 0;
514 uint8_t phys_port_id;
521 uint8_t linkup_linkrate;
527 ret =
switchtec_cmd(dev, MRPC_LNKSTAT, &port_bitmap,
sizeof(port_bitmap),
528 ports,
sizeof(ports));
533 for (i = 0; i < max_ports; i++) {
534 if ((ports[i].stk_id >> 4) > SWITCHTEC_MAX_STACKS)
539 s = *status = calloc(nr_ports,
sizeof(*s));
543 for (i = 0, p = 0; i < max_ports && p < nr_ports; i++) {
544 if ((ports[i].stk_id >> 4) > SWITCHTEC_MAX_STACKS)
556 s[p].
link_up = ports[i].linkup_linkrate >> 7;
557 s[p].
link_rate = ports[i].linkup_linkrate & 0x7F;
558 s[p].
ltssm = le16toh(ports[i].LTSSM);
559 s[p].
ltssm_str = switchtec_ltssm_str(s[p].ltssm, 1, dev);
565 generate_lane_str(&s[p]);
570 qsort(s, nr_ports,
sizeof(*s), compare_status);
585 for (i = 0; i < ports; i++) {
586 if (status[i].pci_bdf)
587 free(status[i].pci_bdf);
589 if (status[i].pci_bdf_path)
590 free(status[i].pci_bdf_path);
592 if (status[i].pci_dev)
593 free(status[i].pci_dev);
595 if (status[i].class_devices)
596 free(status[i].class_devices);
622 const char *msg =
"Unknown MRPC error";
625 if ((errno & (SWITCHTEC_ERRNO_MRPC_FLAG_BIT |
626 SWITCHTEC_ERRNO_GENERAL_FLAG_BIT)) == 0) {
628 return strerror(errno);
630 return platform_strerror();
633 if (errno & SWITCHTEC_ERRNO_GENERAL_FLAG_BIT) {
635 case SWITCHTEC_ERR_LOG_DEF_READ_ERROR:
636 msg =
"Error reading log definition file";
break;
637 case SWITCHTEC_ERR_BIN_LOG_READ_ERROR:
638 msg =
"Error reading binary log file";
break;
639 case SWITCHTEC_ERR_PARSED_LOG_WRITE_ERROR:
640 msg =
"Error writing parsed log file";
break;
641 case SWITCHTEC_ERR_LOG_DEF_DATA_INVAL:
642 msg =
"Invalid log definition data";
break;
643 case SWITCHTEC_ERR_INVALID_PORT:
644 msg =
"Invalid port specified";
break;
645 case SWITCHTEC_ERR_INVALID_LANE:
646 msg =
"Invalid lane specified";
break;
648 msg =
"Unknown Switchtec error";
break;
654 err = errno & ~SWITCHTEC_ERRNO_MRPC_FLAG_BIT;
657 case ERR_NO_AVAIL_MRPC_THREAD:
658 msg =
"No available MRPC handler thread";
break;
659 case ERR_HANDLER_THREAD_NOT_IDLE:
660 msg =
"The handler thread is not idle";
break;
661 case ERR_NO_BG_THREAD:
662 msg =
"No background thread run for the command";
break;
664 case ERR_REFCLK_SUBCMD_INVALID:
665 case ERR_STACKBIF_SUBCMD_INVALID:
666 case ERR_SUBCMD_INVALID: msg =
"Invalid subcommand";
break;
667 case ERR_CMD_INVALID: msg =
"Invalid command";
break;
668 case ERR_PARAM_INVALID: msg =
"Invalid parameter";
break;
669 case ERR_BAD_FW_STATE: msg =
"Bad firmware state";
break;
670 case ERR_MRPC_DENIED: msg =
"MRPC request denied";
break;
671 case ERR_MRPC_NO_PREV_DATA:
672 msg =
"No previous adaptation object data";
674 case ERR_REFCLK_STACK_ID_INVALID:
675 case ERR_STACKBIF_STACK_ID_INVALID:
676 case ERR_STACK_INVALID: msg =
"Invalid Stack";
break;
677 case ERR_LOOPBACK_PORT_INVALID:
678 case ERR_PORT_INVALID: msg =
"Invalid Port";
break;
679 case ERR_EVENT_INVALID: msg =
"Invalid Event";
break;
680 case ERR_RST_RULE_FAILED: msg =
"Reset rule search failed";
break;
681 case ERR_UART_NOT_SUPPORTED:
682 msg =
"UART interface not supported for this command";
break;
683 case ERR_XML_VERSION_MISMATCH:
684 msg =
"XML version mismatch between MAIN and CFG partition";
686 case ERR_ACCESS_REFUSED: msg =
"Access Refused";
break;
688 case ERR_STACKBIF_CODE_INVALID:
689 msg =
"Stack bifurcation code invalid";
break;
691 case ERR_STACKBIF_PORT_BOUND:
692 msg =
"Port already bound";
break;
699 case MRPC_PORTPARTP2P:
701 case ERR_PHYC_PORT_ARDY_BIND:
702 msg =
"Physical port already bound";
break;
703 case ERR_LOGC_PORT_ARDY_BIND:
704 msg =
"Logical bridge instance already bound";
break;
705 case ERR_BIND_PRTT_NOT_EXIST:
706 msg =
"Partition does not exist";
break;
707 case ERR_PHYC_PORT_NOT_EXIST:
708 msg =
"Physical port does not exist";
break;
709 case ERR_PHYC_PORT_DIS:
710 msg =
"Physical port disabled";
break;
711 case ERR_NO_LOGC_PORT:
712 msg =
"No logical bridge instance";
break;
713 case ERR_BIND_IN_PROGRESS:
714 msg =
"Bind/unbind in progress";
break;
715 case ERR_BIND_TGT_IS_USP:
716 msg =
"Bind/unbind target is USP";
break;
717 case ERR_BIND_SUBCMD_INVALID:
718 msg =
"Sub-command does not exist";
break;
719 case ERR_PHYC_PORT_LINK_ACT:
720 msg =
"Physical port link active";
break;
721 case ERR_LOGC_PORT_NOT_BIND_PHYC_PORT:
722 msg =
"Logical bridge not bind to physical port";
break;
723 case ERR_UNBIND_OPT_INVALID:
724 msg =
"Invalid unbind option";
break;
725 case ERR_BIND_CHECK_FAIL:
726 msg =
"Port bind checking failed";
break;
746 int is_mrpc = errno & SWITCHTEC_ERRNO_MRPC_FLAG_BIT;
747 int err = errno & ~SWITCHTEC_ERRNO_MRPC_FLAG_BIT;
750 fprintf(stderr,
"%s: %s (MRPC: 0x%x, error: 0x%x)\n",
753 fprintf(stderr,
"%s: %s\n", str, msg);
778 output,
sizeof(*output));
794 return switchtec_cmd(dev, MRPC_RESET, &subcmd,
sizeof(subcmd),
839 for (i = defs->
num_alloc; i < num_modules; i++)
859 *val = strtol(str, &endptr, 0);
861 if ((endptr == str) || (*endptr !=
'\0') || (errno != 0))
888 while (fgets(line,
sizeof(line), log_def_file)) {
895 line[strcspn(line,
"\r\n")] =
'\0';
901 tok = strtok(line,
" \t");
905 tok = strtok(NULL,
" \t");
910 errno = SWITCHTEC_ERR_LOG_DEF_DATA_INVAL;
911 goto err_free_log_defs;
923 tok = strtok(NULL,
" \t");
928 errno = SWITCHTEC_ERR_LOG_DEF_DATA_INVAL;
929 goto err_free_log_defs;
938 if (!fgets(line,
sizeof(line),
950 goto err_free_log_defs;
953 if (fgets(line,
sizeof(line), log_def_file) == NULL) {
954 errno = SWITCHTEC_ERR_LOG_DEF_READ_ERROR;
955 goto err_free_log_defs;
958 mod_defs->
entries[i] = strdup(line);
960 goto err_free_log_defs;
964 if (ferror(log_def_file)) {
965 errno = SWITCHTEC_ERR_LOG_DEF_READ_ERROR;
966 goto err_free_log_defs;
987 int num_entries_alloc;
1001 num_entries_alloc = 100;
1002 mod_defs->
entries = calloc(num_entries_alloc,
1005 goto err_free_log_defs;
1007 while (fgets(line,
sizeof(line), log_def_file)) {
1014 num_entries_alloc *= 2;
1016 (num_entries_alloc *
1019 goto err_free_log_defs;
1024 goto err_free_log_defs;
1029 if (ferror(log_def_file)) {
1030 errno = SWITCHTEC_ERR_LOG_DEF_READ_ERROR;
1031 goto err_free_log_defs;
1053 size_t count,
int init_entry_idx,
1056 FILE *log_file,
int ts_factor)
1060 int entry_idx = init_entry_idx;
1061 unsigned long long time;
1062 unsigned int nanos, micros, millis, secs, mins, hours, days;
1063 unsigned int entry_num;
1064 unsigned int mod_id;
1065 unsigned int log_sev = 0;
1066 const char *log_sev_strs[] = {
"DISABLED",
"HIGHEST",
"HIGH",
"MEDIUM",
1071 if (entry_idx == 0) {
1072 if (log_type == SWITCHTEC_LOG_PARSE_TYPE_APP || log_type == SWITCHTEC_LOG_PARSE_TYPE_FTDC)
1073 fputs(
" #|Timestamp |Module |Severity |Event ID |Event\n",
1076 fputs(
" #|Timestamp |Source |Event ID |Event\n",
1080 for (i = 0; i < count; i ++) {
1082 time = (((
unsigned long long)log_data[i].data[0] << 32) |
1083 log_data[i].data[1]) * ts_factor/100;
1084 nanos = time % 1000;
1086 micros = time % 1000;
1088 millis = time % 1000;
1097 if (log_type == SWITCHTEC_LOG_PARSE_TYPE_APP || log_type == SWITCHTEC_LOG_PARSE_TYPE_FTDC) {
1102 mod_id = (log_data[i].data[2] >> 16) & 0xFFF;
1103 log_sev = (log_data[i].data[2] >> 28) & 0xF;
1108 if (fprintf(log_file,
"(Invalid module ID: 0x%x)\n",
1110 goto ret_print_error;
1114 if (log_sev >= ARRAY_SIZE(log_sev_strs)) {
1115 if (fprintf(log_file,
"(Invalid log severity: %d)\n",
1117 goto ret_print_error;
1125 is_bl1 = (((log_data[i].data[2] >> 27) & 1) == 0);
1134 entry_num = log_data[i].data[2] & 0x0000FFFF;
1137 if (fprintf(log_file,
1138 "(Invalid log entry number: %d (module 0x%x))\n",
1139 entry_num, mod_id) < 0)
1140 goto ret_print_error;
1146 ret = fprintf(log_file,
1147 "%04d|xxxd xx:xx:xx.xxx,xxx,xxx|",
1150 ret = fprintf(log_file,
1151 "%04d|%03dd %02d:%02d:%02d.%03d,%03d,%03d|",
1152 entry_idx, days, hours, mins, secs,
1153 millis, micros, nanos);
1156 goto ret_print_error;
1158 if (log_type == SWITCHTEC_LOG_PARSE_TYPE_APP || log_type == SWITCHTEC_LOG_PARSE_TYPE_FTDC) {
1160 if (fprintf(log_file,
"%-12s |%-8s |0x%04x |",
1161 mod_defs->
mod_name, log_sev_strs[log_sev],
1163 goto ret_print_error;
1166 if (fprintf(log_file,
"%-6s |0x%04x |",
1167 (is_bl1 ?
"BL1" :
"BL2"), entry_num) < 0)
1168 goto ret_print_error;
1172 if (fprintf(log_file, mod_defs->
entries[entry_num],
1173 log_data[i].data[3], log_data[i].data[4],
1174 log_data[i].data[5], log_data[i].data[6],
1175 log_data[i].data[7]) < 0)
1176 goto ret_print_error;
1181 if (fflush(log_file) != 0)
1187 errno = SWITCHTEC_ERR_PARSED_LOG_WRITE_ERROR;
1191static int parse_def_header(FILE *log_def_file, uint32_t *fw_version,
1192 uint32_t *sdk_version)
1199 while (fgets(line,
sizeof(line), log_def_file)) {
1204 while (line[i] ==
' ' || line[i] ==
'#') i++;
1206 if (strncasecmp(line + i,
"SDK Version:", 12) == 0) {
1208 while (line[i] ==
' ') i++;
1209 sscanf(line + i,
"%i", (
int*)sdk_version);
1211 else if (strncasecmp(line + i,
"FW Version:", 11) == 0) {
1213 while (line[i] ==
' ') i++;
1214 sscanf(line + i,
"%i", (
int*)fw_version);
1218 rewind(log_def_file);
1222static int append_ftdc_log_header(
int fd, uint32_t sdk_def_version,
1223 uint32_t fw_def_version)
1226 char hdr_str_fmt[] =
"##########################################\n"
1227 "## Parsed with FTDC log file from definition:\n"
1228 "## FW def version %08x\n"
1229 "## SDK def version %08x\n"
1230 "##########################################\n\n";
1233 snprintf(hdr_str, 512, hdr_str_fmt, fw_def_version, sdk_def_version);
1234 ret = write(fd, hdr_str, strlen(hdr_str));
1239static int append_log_header(
int fd, uint32_t sdk_version,
1240 uint32_t fw_version,
int binary)
1245 uint32_t fw_version;
1246 uint32_t sdk_version;
1250 .magic = {
'S',
'W',
'M',
'C',
'L',
'O',
'G',
'F'},
1251 .fw_version = fw_version,
1252 .sdk_version = sdk_version
1254 char hdr_str_fmt[] =
"####################################\n"
1255 "## Parsed with definition file for\n"
1256 "## FW version %08x\n"
1257 "## SDK version %08x\n"
1258 "####################################\n\n";
1262 ret = write(fd, &header,
sizeof(header));
1264 snprintf(hdr_str, 512, hdr_str_fmt, fw_version, sdk_version);
1265 ret = write(fd, hdr_str, strlen(hdr_str));
1273 if (gen == SWITCHTEC_GEN_UNKNOWN)
1275 else if (gen == SWITCHTEC_GEN3)
1281static int log_a_to_file(
struct switchtec_dev *dev,
int sub_cmd_id,
1282 int fd, FILE *log_def_file,
1289 .sub_cmd_id = sub_cmd_id,
1293 .module_defs = NULL,
1297 uint32_t fw_version = 0;
1298 uint32_t sdk_version = 0;
1300 if (log_def_file != NULL) {
1301 ret = parse_def_header(log_def_file, &fw_version,
1313 while (res.hdr.remain) {
1317 goto ret_free_log_defs;
1318 if (res.hdr.overflow && info)
1321 if (dev->gen < SWITCHTEC_GEN5) {
1322 res.hdr.sdk_version = 0;
1323 res.hdr.fw_version = 0;
1327 info->def_fw_version = fw_version;
1328 info->def_sdk_version = sdk_version;
1329 info->log_fw_version = res.hdr.fw_version;
1330 info->log_sdk_version = res.hdr.sdk_version;
1333 if (res.hdr.sdk_version != sdk_version ||
1334 res.hdr.fw_version != fw_version) {
1335 if (info && log_def_file)
1336 info->version_mismatch =
true;
1340 append_log_header(fd, res.hdr.sdk_version,
1342 log_def_file == NULL? 1 : 0);
1345 if (log_def_file == NULL) {
1347 ret = write(fd, res.data,
1348 sizeof(*res.data) * res.hdr.count);
1352 log_file = fdopen(fd,
"w");
1354 goto ret_free_log_defs;
1359 SWITCHTEC_LOG_PARSE_TYPE_APP,
1361 get_ts_factor(dev->gen));
1363 goto ret_free_log_defs;
1365 entry_idx += res.hdr.count;
1368 read += le32toh(res.hdr.count);
1369 cmd.start = res.hdr.next_start;
1379static int log_b_to_file(
struct switchtec_dev *dev,
int sub_cmd_id,
int fd)
1385 .sub_cmd_id = sub_cmd_id,
1387 .length = htole32(
sizeof(res.data)),
1390 res.hdr.remain =
sizeof(res.data);
1392 while (res.hdr.remain) {
1398 ret = write(fd, res.data, res.hdr.length);
1402 read += le32toh(res.hdr.length);
1403 cmd.offset = htole32(read);
1409static int log_c_to_file(
struct switchtec_dev *dev,
int sub_cmd_id,
int fd)
1420 uint32_t nvlog_version;
1421 uint32_t thread_handle;
1422 uint32_t fw_version;
1423 uint32_t timestamp1;
1424 uint32_t timestamp2;
1427 cmd.subcmd = sub_cmd_id;
1430 &reply,
sizeof(reply));
1434 ret = write(fd, &reply,
sizeof(reply));
1441static int log_d_to_file(
struct switchtec_dev *dev,
int sub_cmd_id,
int fd)
1448 .sub_cmd_id = sub_cmd_id,
1452 uint32_t length =
sizeof(res.data);
1457 while ( !(res.data[1]) ) {
1458 ret =
switchtec_cmd(dev, MRPC_FTDC_LOG_DUMP, &cmd,
sizeof(cmd),
1463 ret = write(fd, res.data, (res.data[0]+1)*4);
1475static int log_ram_flash_to_file(
struct switchtec_dev *dev,
1476 int gen5_cmd,
int gen4_cmd,
int gen4_cmd_lgcy,
1477 int fd, FILE *log_def_file,
1483 return log_a_to_file(dev, gen5_cmd, fd, log_def_file,
1486 ret = log_a_to_file(dev, gen4_cmd, fd, log_def_file,
1495 (ERRNO_MRPC(errno) == ERR_LOGC_PORT_ARDY_BIND ||
1496 ERRNO_MRPC(errno) == ERR_SUBCMD_INVALID))
1497 ret = log_a_to_file(dev, gen4_cmd_lgcy, fd,
1498 log_def_file, info);
1518 memset(info, 0,
sizeof(*info));
1521 case SWITCHTEC_LOG_RAM:
1522 return log_ram_flash_to_file(dev,
1523 MRPC_FWLOGRD_RAM_GEN5,
1524 MRPC_FWLOGRD_RAM_WITH_FLAG,
1526 fd, log_def_file, info);
1527 case SWITCHTEC_LOG_FLASH:
1528 return log_ram_flash_to_file(dev,
1529 MRPC_FWLOGRD_FLASH_GEN5,
1530 MRPC_FWLOGRD_FLASH_WITH_FLAG,
1532 fd, log_def_file, info);
1533 case SWITCHTEC_LOG_FTDC:
1534 return log_d_to_file(dev, MRPC_FWLOGRD_RAM, fd);
1535 case SWITCHTEC_LOG_MEMLOG:
1536 return log_b_to_file(dev, MRPC_FWLOGRD_MEMLOG, fd);
1537 case SWITCHTEC_LOG_REGS:
1538 return log_b_to_file(dev, MRPC_FWLOGRD_REGS, fd);
1539 case SWITCHTEC_LOG_THRD_STACK:
1540 return log_b_to_file(dev, MRPC_FWLOGRD_THRD_STACK, fd);
1541 case SWITCHTEC_LOG_SYS_STACK:
1542 return log_b_to_file(dev, MRPC_FWLOGRD_SYS_STACK, fd);
1543 case SWITCHTEC_LOG_THRD:
1544 return log_b_to_file(dev, MRPC_FWLOGRD_THRD, fd);
1545 case SWITCHTEC_LOG_NVHDR:
1546 return log_c_to_file(dev, MRPC_FWLOGRD_NVHDR, fd);
1553static int parse_log_header(FILE *bin_log_file, uint32_t *fw_version,
1554 uint32_t *sdk_version)
1558 uint32_t fw_version;
1559 uint32_t sdk_version;
1564 char sig[8] = {
'S',
'W',
'M',
'C',
'L',
'O',
'G',
'F'};
1567 ret = fread(&header,
sizeof(header), 1, bin_log_file);
1573 if (memcmp(sig, header.magic, 8)) {
1574 rewind(bin_log_file);
1580 *fw_version = header.fw_version;
1581 *sdk_version = header.sdk_version;
1597 FILE *parsed_log_file,
1605 .module_defs = NULL,
1608 uint32_t fw_version_log = 0;
1609 uint32_t sdk_version_log = 0;
1610 uint32_t fw_version_def;
1611 uint32_t sdk_version_def;
1615 memset(info, 0,
sizeof(*info));
1617 if ((log_type != SWITCHTEC_LOG_PARSE_TYPE_APP) &&
1618 (log_type != SWITCHTEC_LOG_PARSE_TYPE_MAILBOX) &&
1619 (log_type != SWITCHTEC_LOG_PARSE_TYPE_FTDC)) {
1624 if (log_type != SWITCHTEC_LOG_PARSE_TYPE_FTDC)
1626 ret = parse_log_header(bin_log_file, &fw_version_log,
1632 ret = parse_def_header(log_def_file, &fw_version_def,
1637 if (log_type == SWITCHTEC_LOG_PARSE_TYPE_MAILBOX) {
1638 fw_version_log = fw_version_def;
1639 sdk_version_log = sdk_version_def;
1643 info->def_fw_version = fw_version_def;
1644 info->def_sdk_version = sdk_version_def;
1646 info->log_fw_version = fw_version_log;
1647 info->log_sdk_version = sdk_version_log;
1650 if (log_type == SWITCHTEC_LOG_PARSE_TYPE_APP || log_type == SWITCHTEC_LOG_PARSE_TYPE_FTDC)
1658 if (log_type != SWITCHTEC_LOG_PARSE_TYPE_FTDC)
1659 ret = append_log_header(fileno(parsed_log_file), sdk_version_log,
1662 ret = append_ftdc_log_header(fileno(parsed_log_file), sdk_version_def,
1669 while (fread(&log_data,
sizeof(
struct log_a_data), 1,
1670 bin_log_file) == 1) {
1676 if (gen_file != SWITCHTEC_GEN_UNKNOWN &&
1677 gen != SWITCHTEC_GEN_UNKNOWN) {
1679 info->gen_ignored =
true;
1680 }
else if (gen_file == SWITCHTEC_GEN_UNKNOWN &&
1681 gen == SWITCHTEC_GEN_UNKNOWN) {
1683 info->gen_unknown =
true;
1684 }
else if (gen != SWITCHTEC_GEN_UNKNOWN) {
1689 log_type, parsed_log_file,
1690 get_ts_factor(gen_file));
1692 goto ret_free_log_defs;
1697 if (ferror(bin_log_file)) {
1698 errno = SWITCHTEC_ERR_BIN_LOG_READ_ERROR;
1702 if (fw_version_def != fw_version_log ||
1703 sdk_version_def != sdk_version_log) {
1705 info->version_mismatch =
true;
1734 uint16_t end_of_data;
1737 uint16_t next_mod_id;
1738 uint8_t data[MRPC_MAX_DATA_LEN - 16];
1742 case SWITCHTEC_LOG_DEF_TYPE_APP:
1743 cmd.subcmd = MRPC_LOG_DEF_APP;
1746 case SWITCHTEC_LOG_DEF_TYPE_MAILBOX:
1747 cmd.subcmd = MRPC_LOG_DEF_MAILBOX;
1756 ret =
switchtec_cmd(dev, MRPC_LOG_DEF_GET, &cmd,
sizeof(cmd),
1757 &reply,
sizeof(reply));
1761 ret = fwrite(reply.data, reply.data_len, 1, file);
1765 cmd.idx = reply.next_idx;
1766 cmd.mod_id = reply.next_mod_id;
1767 }
while (!reply.end_of_data);
1778 ret = SWITCHTEC_GEN4;
1781 ret = SWITCHTEC_GEN5;
1784 ret = SWITCHTEC_GEN_UNKNOWN;
1805 uint32_t ping_dw = 0;
1807 struct get_dev_info_reply {
1809 uint32_t ping_reply;
1812 ping_dw = time(NULL);
1820 &reply,
sizeof(reply));
1822 if (ping_dw != ~reply.ping_reply)
1825 dev_info = le32toh(reply.dev_info);
1827 *phase = dev_info & 0xff;
1829 *rev = (dev_info >> 8) & 0x0f;
1831 *gen = map_to_gen((dev_info >> 12) & 0x0f);
1832 }
else if (errno == EBADMSG || ERRNO_MRPC(errno) == ERR_CMD_INVALID) {
1834 *phase = SWITCHTEC_BOOT_PHASE_FW;
1836 *gen = SWITCHTEC_GEN3;
1838 *rev = SWITCHTEC_REV_UNKNOWN;
1857 uint32_t sub_cmd_id;
1861 sub_cmd_id = MRPC_DIETEMP_SET_MEAS;
1863 sizeof(sub_cmd_id), NULL, 0);
1867 sub_cmd_id = MRPC_DIETEMP_GET;
1869 sizeof(sub_cmd_id), &temp,
sizeof(temp));
1873 sub_cmd_id = MRPC_DIETEMP_GET_GEN4;
1875 sizeof(sub_cmd_id), &temp,
sizeof(temp));
1879 sub_cmd_id = MRPC_DIETEMP_GET_GEN5;
1882 sizeof(sub_cmd_id), temps,
sizeof(temps));
1885 temp = (temps[0] + temps[1] + temps[2] + temps[3]) / 4;
1888 return le32toh(temp) / 100.;
1899 float *sensor_readings)
1902 uint32_t sub_cmd_id;
1905 if (nr_sensor <= 0 || !sensor_readings)
1909 sub_cmd_id = MRPC_DIETEMP_SET_MEAS;
1911 sizeof(sub_cmd_id), NULL, 0);
1915 sub_cmd_id = MRPC_DIETEMP_GET;
1917 sizeof(sub_cmd_id), &temp,
sizeof(temp));
1921 sensor_readings[0] = le32toh(temp) / 100.;
1924 sub_cmd_id = MRPC_DIETEMP_GET_GEN4;
1926 sizeof(sub_cmd_id), &temp,
sizeof(temp));
1930 sensor_readings[0] = le32toh(temp) / 100.;
1933 sub_cmd_id = MRPC_DIETEMP_GET_GEN5;
1938 sizeof(sub_cmd_id), temps,
sizeof(temps));
1942 for (i = 0; i < nr_sensor && i < 4; i++)
1943 sensor_readings[i] = le32toh(temps[i]) / 100.;
1949int switchtec_bind_info(
struct switchtec_dev *dev,
1953 .sub_cmd = MRPC_PORT_INFO,
1954 .phys_port_id = phy_port
1958 sizeof(sub_cmd_id), status,
sizeof(*status));
1961int switchtec_bind(
struct switchtec_dev *dev,
int par_id,
int log_port,
1967 .sub_cmd = MRPC_PORT_BIND,
1969 .log_port_id = log_port,
1970 .phys_port_id = phy_port
1974 sizeof(sub_cmd_id), &output,
sizeof(output));
1977int switchtec_unbind(
struct switchtec_dev *dev,
int par_id,
int log_port)
1982 .sub_cmd = MRPC_PORT_UNBIND,
1984 .log_port_id = log_port,
1989 sizeof(sub_cmd_id), &output,
sizeof(output));
1992static int __switchtec_calc_lane_id(
struct switchtec_status *port,
int lane_id)
1997 errno = SWITCHTEC_ERR_INVALID_LANE;
2018 default:
return lane;
2041 for (i = 0; i < ports; i++)
2046 errno = SWITCHTEC_ERR_INVALID_PORT;
2054 rc = __switchtec_calc_lane_id(&status[i], lane_id);
2071 int *phys_port_id,
int *port_lane_id,
2075 int ports, i, p, lane;
2082 if (lane_id >= 96) {
2083 if (dev->gen < SWITCHTEC_GEN5)
2084 p = lane_id - 96 + 48;
2086 p = lane_id - 96 + 56;
2088 for (i = 0; i < ports; i++)
2092 for (i = 0; i < ports; i++) {
2100 errno = SWITCHTEC_ERR_INVALID_PORT;
2112 if (
port->lane_reversal)
2116 *port_lane_id = lane;
2135 int lane_id,
int num_lanes,
int *lane_mask,
2139 int ports, i, l, lane;
2146 for (i = 0; i < ports; i++)
2151 errno = SWITCHTEC_ERR_INVALID_PORT;
2159 for (l = lane_id; l < lane_id + num_lanes; l++) {
2160 lane = __switchtec_calc_lane_id(&status[i], l);
2166 lane_mask[lane >> 5] |= 1 << (lane & 0x1F);
2184 if (dev->gen == SWITCHTEC_GEN4)
2185 return stack_id * 8 + port_id < 52;
2203 if (port_bif != 1 && port_bif != 2 && port_bif != 4 && port_bif != 8 &&
2209 if (dev->gen == SWITCHTEC_GEN4 && stack_id == 6)
2212 return (port_bif + 1) / 2;
2223 int port_bif[SWITCHTEC_PORTS_PER_STACK])
2226 .sub_cmd = MRPC_STACKBIF_GET,
2227 .stack_id = stack_id,
2231 ret =
switchtec_cmd(dev, MRPC_STACKBIF, &in,
sizeof(in), &out,
2236 for (i = 0; i < SWITCHTEC_PORTS_PER_STACK; i++) {
2242 switch (out.code & 0xF) {
2243 case 0x0: port_bif[i] = 0;
break;
2244 case 0x1: port_bif[i] = 2;
break;
2245 case 0x2: port_bif[i] = 4;
break;
2246 case 0x4: port_bif[i] = 8;
break;
2247 case 0x8: port_bif[i] = 16;
break;
2248 case 0xf: port_bif[i] = 1;
break;
2267 int port_bif[SWITCHTEC_PORTS_PER_STACK])
2270 .sub_cmd = MRPC_STACKBIF_SET,
2271 .stack_id = stack_id,
2275 for (i = 0; i < SWITCHTEC_PORTS_PER_STACK; i++) {
2276 switch (port_bif[i]) {
2277 case 0: in.code |= 0x0 << (i * 4);
break;
2278 case 1: in.code |= 0xf << (i * 4);
break;
2279 case 2: in.code |= 0x1 << (i * 4);
break;
2280 case 4: in.code |= 0x2 << (i * 4);
break;
2281 case 8: in.code |= 0x4 << (i * 4);
break;
2282 case 16: in.code |= 0x8 << (i * 4);
break;
2289 return switchtec_cmd(dev, MRPC_STACKBIF, &in,
sizeof(in), &out,
2305 .sub_cmd = MRPC_VGPIO_GET_VAL,
2306 .log_gpio_id = pin_id,
2314 *gpio_val = out.data;
2330 .sub_cmd = MRPC_VGPIO_SET_VAL,
2331 .log_gpio_id = pin_id,
2335 return switchtec_cmd(dev, MRPC_VGPIO, &in,
sizeof(in), NULL, 0);
2350 .sub_cmd = MRPC_VGPIO_GET_DIR,
2351 .log_gpio_id = pin_id,
2359 *direction = out.data;
2376 .sub_cmd = MRPC_VGPIO_GET_POL,
2377 .log_gpio_id = pin_id,
2385 *polarity = out.data;
2400 .sub_cmd = MRPC_VGPIO_DIS_INT,
2401 .log_gpio_id = pin_id,
2405 in.sub_cmd = MRPC_VGPIO_EN_INT;
2407 return switchtec_cmd(dev, MRPC_VGPIO, &in,
sizeof(in), NULL, 0);
2420 .sub_cmd = MRPC_VPGIO_GET_PIN_STS,
2424 ret =
switchtec_cmd(dev, MRPC_VGPIO, &in,
sizeof(in), &out,
sizeof(out));
2428 memcpy(values, out.pin_values,
sizeof(out.pin_values));
struct switchtec_dev * switchtec_open(const char *device)
Open a Switchtec device by string.
void switchtec_list_free(struct switchtec_device_info *devlist)
Free a list of device info structures allocated by switchtec_list().
struct switchtec_dev * switchtec_open_by_index(int index)
Open a switchtec device by index.
int switchtec_cmd(struct switchtec_dev *dev, uint32_t cmd, const void *payload, size_t payload_len, void *resp, size_t resp_len)
Execute an MRPC command.
void switchtec_perror(const char *str)
Print an error string to stdout.
int mrpc_error_cmd
The MRPC command ID when errno is set.
struct switchtec_dev * switchtec_open_i2c(const char *path, int i2c_addr)
Open a switchtec device behind an I2C device.
void switchtec_status_free(struct switchtec_status *status, int ports)
Free a list of status structures allocated by switchtec_status().
int switchtec_status(struct switchtec_dev *dev, struct switchtec_status **status)
Get the status of all the ports on a switchtec device.
struct switchtec_dev * switchtec_open_by_path(const char *path)
Open a switchtec device by path.
_PURE const char * switchtec_name(struct switchtec_dev *dev)
Get the string that was used to open the deviec.
const char * switchtec_strerror(void)
Return a message coresponding to the last error.
static const struct switchtec_device_id switchtec_device_id_tbl[]
Supported Switchtec device id table.
_PURE int switchtec_device_id(struct switchtec_dev *dev)
Get the device id of the device.
struct switchtec_dev * switchtec_open_eth(const char *ip, const int inst)
Open a switchtec device over ethernet.
_PURE enum switchtec_gen switchtec_gen(struct switchtec_dev *dev)
Get the generation of the device.
_PURE enum switchtec_variant switchtec_variant(struct switchtec_dev *dev)
Get the variant type of the device.
_PURE int switchtec_partition(struct switchtec_dev *dev)
Get the partiton number of the device that was opened.
struct switchtec_dev * switchtec_open_by_pci_addr(int domain, int bus, int device, int func)
Open a switchtec device by PCI address (BDF).
enum switchtec_gen switchtec_fw_version_to_gen(unsigned int version)
Extract generation information from FW version number.
int switchtec_stack_bif_width(struct switchtec_dev *dev, int stack_id, int port_bif)
Return the number of stack ports used for a given bifurcation.
int switchtec_calc_lane_mask(struct switchtec_dev *dev, int phys_port_id, int lane_id, int num_lanes, int *lane_mask, struct switchtec_status *port)
Calculate the lane mask for lanes within a physical port.
int switchtec_get_gpio(struct switchtec_dev *dev, int pin_id, int *gpio_val)
Get the GPIO pin value.
int switchtec_log_to_file(struct switchtec_dev *dev, enum switchtec_log_type type, int fd, FILE *log_def_file, struct switchtec_log_file_info *info)
Dump the Switchtec log data to a file.
int switchtec_set_gpio(struct switchtec_dev *dev, int pin_id, int gpio_val)
Set the GPIO pin value.
static int read_mailbox_log_defs(FILE *log_def_file, struct log_defs *defs)
Read a mailbox log definition file and store the definitions.
int switchtec_get_gpio_polarity_cfg(struct switchtec_dev *dev, int pin_id, int *polarity)
Get the GPIO pin polarity.
int switchtec_parse_log(FILE *bin_log_file, FILE *log_def_file, FILE *parsed_log_file, enum switchtec_log_parse_type log_type, enum switchtec_gen gen, struct switchtec_log_file_info *info)
Parse a binary app log or mailbox log to a text file.
float switchtec_die_temp(struct switchtec_dev *dev)
Get the die temperature of the switchtec device.
int switchtec_die_temps(struct switchtec_dev *dev, int nr_sensor, float *sensor_readings)
Get the die temperature sensor readings of the switchtec device.
int switchtec_get_stack_bif(struct switchtec_dev *dev, int stack_id, int port_bif[SWITCHTEC_PORTS_PER_STACK])
Get the bifurcation of ports in a stack.
static void free_log_defs(struct log_defs *defs)
Free log definition data.
bool switchtec_stack_bif_port_valid(struct switchtec_dev *dev, int stack_id, int port_id)
Return true if a port within a stack is valid.
int switchtec_hard_reset(struct switchtec_dev *dev)
Perform an MRPC hard reset command.
int switchtec_log_def_to_file(struct switchtec_dev *dev, enum switchtec_log_def_type type, FILE *file)
Dump the Switchtec log definition data to a file.
int switchtec_get_device_info(struct switchtec_dev *dev, enum switchtec_boot_phase *phase, enum switchtec_gen *gen, enum switchtec_rev *rev)
Get device generation, revision, and boot phase info.
static int read_app_log_defs(FILE *log_def_file, struct log_defs *defs)
Read an app log definition file and store the definitions.
static int realloc_log_defs(struct log_defs *defs, int num_modules)
Allocate / reallocate log definition data.
int switchtec_en_dis_interrupt(struct switchtec_dev *dev, int pin_id, int en)
Enable/Disable the GPIO pin interrupt.
int switchtec_echo(struct switchtec_dev *dev, uint32_t input, uint32_t *output)
Perform an MRPC echo command.
static bool parse_int(char *str, int *val)
Parse an integer from a string.
int switchtec_get_all_pin_sts(struct switchtec_dev *dev, uint32_t *values)
Get all GPIO pin status.
int switchtec_set_stack_bif(struct switchtec_dev *dev, int stack_id, int port_bif[SWITCHTEC_PORTS_PER_STACK])
Set the bifurcation of ports in a stack.
int switchtec_calc_lane_id(struct switchtec_dev *dev, int phys_port_id, int lane_id, struct switchtec_status *port)
Calculate the global lane ID for a lane within a physical port.
int switchtec_get_gpio_direction_cfg(struct switchtec_dev *dev, int pin_id, int *direction)
Get the GPIO pin direction.
int switchtec_calc_port_lane(struct switchtec_dev *dev, int lane_id, int *phys_port_id, int *port_lane_id, struct switchtec_status *port)
Calculate the port and lane within the port from a global lane ID.
static int write_parsed_log(struct log_a_data log_data[], size_t count, int init_entry_idx, struct log_defs *defs, enum switchtec_log_parse_type log_type, FILE *log_file, int ts_factor)
Parse an app log or mailbox log and write the results to a file.
Log definitions for all modules.
struct module_log_defs * module_defs
per-module log definitions
int num_alloc
number of modules allocated
Module-specific log definitions.
char * mod_name
module name
int num_entries
number of log entries
char ** entries
log entry array
Switchtec device id to generation/variant mapping.
Represents a Switchtec device in the switchtec_list() function.
Information about log file and log definition file.
unsigned char upstream
1 if this is an upstream port
unsigned char partition
Partition the port is in.
unsigned char stk_id
Port number within the stack.
unsigned char log_id
Logical port number.
unsigned char phys_id
Physical port number.
unsigned char stack
Stack number.
struct switchtec_port_id port
Port ID.
unsigned char link_up
1 if the link is up
unsigned char lane_reversal
Lane reversal.
unsigned int acs_ctrl
ACS Setting of the Port.
const char * lane_reversal_str
Lane reversal as a string.
unsigned char cfg_lnk_width
Configured link width.
unsigned char link_rate
Link rate/gen.
unsigned char first_act_lane
First active lane.
unsigned char neg_lnk_width
Negotiated link width.
uint16_t ltssm
Link state.
const char * ltssm_str
Link state as a string.
switchtec_log_parse_type
Log types to parse.
switchtec_rev
Device hardware revision.
switchtec_gen
The PCIe generations.
switchtec_log_def_type
Log definition data types.
switchtec_variant
The variant types of Switchtec device.
switchtec_log_type
Describe the type of logs too dump.
switchtec_boot_phase
Device boot phase.
static int switchtec_is_gen4(struct switchtec_dev *dev)
Return whether a Switchtec device is a Gen 4 device.
static int switchtec_max_supported_ports(struct switchtec_dev *dev)
Return the max number of ports of a Switchtec device.
static int switchtec_is_gen5(struct switchtec_dev *dev)
Return whether a Switchtec device is a Gen 5 device.
static int switchtec_is_pax_all(struct switchtec_dev *dev)
Return whether a Switchtec device is PAX(A).
static int switchtec_is_gen3(struct switchtec_dev *dev)
Return whether a Switchtec device is a Gen 3 device.