Switchtec Userspace PROJECT_NUMBER = 4.2
Loading...
Searching...
No Matches
switchtec.h
Go to the documentation of this file.
1/*
2 * Microsemi Switchtec(tm) PCIe Management Library
3 * Copyright (c) 2017, Microsemi Corporation
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included
13 * in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
19 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
20 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
21 * OTHER DEALINGS IN THE SOFTWARE.
22 *
23 */
24
25#ifndef LIBSWITCHTEC_SWITCHTEC_H
26#define LIBSWITCHTEC_SWITCHTEC_H
27
32
33#include "mrpc.h"
34#include "bind.h"
35#include "portable.h"
36#include "registers.h"
37#include "utils.h"
38#include "inject.h"
39
40#include <stdbool.h>
41#include <stdlib.h>
42#include <stdint.h>
43#include <stdio.h>
44
45#ifdef __cplusplus
46extern "C" {
47#endif
48
49struct switchtec_dev;
50
51#define SWITCHTEC_MAX_PARTS 48
52#define SWITCHTEC_MAX_PORTS 60
53#define SWITCHTEC_MAX_LANES 100
54#define SWITCHTEC_MAX_STACKS 8
55#define SWITCHTEC_PORTS_PER_STACK 8
56#define SWITCHTEC_MAX_EVENT_COUNTERS 64
57#define SWITCHTEC_UNBOUND_PORT 255
58#define SWITCHTEC_PFF_PORT_VEP 100
59
60#define SWITCHTEC_FLASH_BOOT_PART_START 0xa8000000
61#define SWITCHTEC_FLASH_MAP0_PART_START 0xa8020000
62#define SWITCHTEC_FLASH_MAP1_PART_START 0xa8040000
63#define SWITCHTEC_FLASH_PART_LEN 0x10000
64
65#define SWITCHTEC_CMD_MASK 0xffff
66#define SWITCHTEC_PAX_ID_SHIFT 18
67#define SWITCHTEC_PAX_ID_MASK 0x1f
68#define SWITCHTEC_PAX_ID_LOCAL SWITCHTEC_PAX_ID_MASK
69
70#define SWITCHTEC_DIAG_MAX_TLP_DWORDS 132
71
72#define SWITCHTEC_MAX_GPIO_PIN_VALS 30
73
74#ifdef __CHECKER__
75#define __gas __attribute__((noderef, address_space(1)))
76#else
77#define __gas
78#endif
79
80#define _PURE __attribute__ ((pure))
81
85typedef __gas struct switchtec_gas *gasptr_t;
86#define SWITCHTEC_MAP_FAILED ((gasptr_t) -1)
87
92 SWITCHTEC_GEN3,
93 SWITCHTEC_GEN4,
94 SWITCHTEC_GEN5,
95 SWITCHTEC_GEN_UNKNOWN,
96};
97
102 SWITCHTEC_REVA = 0x0f,
103 SWITCHTEC_REVB = 0x00,
104 SWITCHTEC_REVC = 0x01,
105 SWITCHTEC_REV_UNKNOWN = 0xff
106};
107
112 SWITCHTEC_BOOT_PHASE_BL1 = 1,
113 SWITCHTEC_BOOT_PHASE_BL2,
114 SWITCHTEC_BOOT_PHASE_FW,
115 SWITCHTEC_BOOT_PHASE_UNKNOWN
116};
117
122 SWITCHTEC_PART_TYPE_KEYMAN = 1,
123 SWITCHTEC_PART_TYPE_RC = 2,
124 SWITCHTEC_PART_TYPE_BL2 = 3,
125 SWITCHTEC_PART_TYPE_CFG = 4,
126 SWITCHTEC_PART_TYPE_FW = 5
127};
128
133 SWITCHTEC_PFX,
134 SWITCHTEC_PFXL,
135 SWITCHTEC_PFXI,
136 SWITCHTEC_PSX,
137 SWITCHTEC_PAX,
138 SWITCHTEC_PAXA,
139 SWITCHTEC_PFXA,
140 SWITCHTEC_PSXA,
141 SWITCHTEC_VAR_UNKNOWN,
142};
143
148 char name[256];
149 char desc[256];
150 char pci_dev[256];
151 char product_id[32];
152 char product_rev[8];
153 char fw_version[32];
154 char path[PATH_MAX];
155};
156
161 unsigned char partition;
163 unsigned char stack;
164 unsigned char upstream;
165 unsigned char stk_id;
166 unsigned char phys_id;
167 unsigned char log_id;
168};
169
178 unsigned char cfg_lnk_width;
179 unsigned char neg_lnk_width;
180 unsigned char link_up;
181 unsigned char link_rate;
182 uint16_t ltssm;
183 const char *ltssm_str;
184 unsigned char lane_reversal;
185 const char *lane_reversal_str;
186 unsigned char first_act_lane;
187 char lanes[17];
188
189 char *pci_bdf;
191
192 char *pci_dev;
196 unsigned int acs_ctrl;
197};
198
203 SWITCHTEC_BW_TYPE_RAW = 0x0,
204 SWITCHTEC_BW_TYPE_PAYLOAD = 0x1,
205};
206
212 SWITCHTEC_LOG_RAM,
213 SWITCHTEC_LOG_FLASH,
214 SWITCHTEC_LOG_FTDC,
215 SWITCHTEC_LOG_MEMLOG,
216 SWITCHTEC_LOG_REGS,
217 SWITCHTEC_LOG_SYS_STACK,
218 SWITCHTEC_LOG_THRD_STACK,
219 SWITCHTEC_LOG_THRD,
220 SWITCHTEC_LOG_NVHDR,
221};
222
227 SWITCHTEC_LOG_PARSE_TYPE_APP,
228 SWITCHTEC_LOG_PARSE_TYPE_MAILBOX,
229 SWITCHTEC_LOG_PARSE_TYPE_FTDC
230};
231
236 unsigned int log_fw_version;
237 unsigned int log_sdk_version;
238 unsigned int def_fw_version;
239 unsigned int def_sdk_version;
240 bool version_mismatch;
241 bool overflow;
242 bool gen_unknown;
243 bool gen_ignored;
244};
245
250 SWITCHTEC_LOG_DEF_TYPE_APP,
251 SWITCHTEC_LOG_DEF_TYPE_MAILBOX
252};
253
254enum switchtec_fw_type {
255 SWITCHTEC_FW_TYPE_UNKNOWN = 0,
256 SWITCHTEC_FW_TYPE_BOOT,
257 SWITCHTEC_FW_TYPE_MAP,
258 SWITCHTEC_FW_TYPE_IMG,
259 SWITCHTEC_FW_TYPE_CFG,
260 SWITCHTEC_FW_TYPE_NVLOG,
261 SWITCHTEC_FW_TYPE_SEEPROM,
262 SWITCHTEC_FW_TYPE_KEY,
263 SWITCHTEC_FW_TYPE_BL2,
264 SWITCHTEC_FW_TYPE_RIOT,
265};
266
272 unsigned long part_id;
273 enum switchtec_fw_type type;
274 char version[32];
275 size_t part_addr;
276 size_t part_len;
278 size_t image_len;
279 unsigned long image_crc;
280
281 bool valid;
282 bool active;
283 bool running;
284 bool read_only;
285
286 struct switchtec_fw_image_info *next;
287 void *metadata;
288
289 unsigned long secure_version;
290 bool signed_image;
291 uint8_t redundant;
292};
293
296 struct switchtec_fw_image_info *active, *inactive;
297 } boot, map, img, cfg, nvlog, seeprom, key, bl2, riot;
298
299 struct switchtec_fw_image_info *mult_cfg;
300
301 int nr_info;
302 struct switchtec_fw_image_info all[];
303};
304
309 uint64_t global;
310 uint64_t part_bitmap;
311 unsigned local_part;
312
314 unsigned part[SWITCHTEC_MAX_PARTS];
315
317 unsigned pff[SWITCHTEC_MAX_PFF_CSR];
318};
319
324 SWITCHTEC_EVT_INVALID = -1,
325 SWITCHTEC_GLOBAL_EVT_STACK_ERROR,
326 SWITCHTEC_GLOBAL_EVT_PPU_ERROR,
327 SWITCHTEC_GLOBAL_EVT_ISP_ERROR,
328 SWITCHTEC_GLOBAL_EVT_SYS_RESET,
329 SWITCHTEC_GLOBAL_EVT_FW_EXC,
330 SWITCHTEC_GLOBAL_EVT_FW_NMI,
331 SWITCHTEC_GLOBAL_EVT_FW_NON_FATAL,
332 SWITCHTEC_GLOBAL_EVT_FW_FATAL,
333 SWITCHTEC_GLOBAL_EVT_TWI_MRPC_COMP,
334 SWITCHTEC_GLOBAL_EVT_TWI_MRPC_COMP_ASYNC,
335 SWITCHTEC_GLOBAL_EVT_CLI_MRPC_COMP,
336 SWITCHTEC_GLOBAL_EVT_CLI_MRPC_COMP_ASYNC,
337 SWITCHTEC_GLOBAL_EVT_GPIO_INT,
338 SWITCHTEC_GLOBAL_EVT_GFMS,
339 SWITCHTEC_PART_EVT_PART_RESET,
340 SWITCHTEC_PART_EVT_MRPC_COMP,
341 SWITCHTEC_PART_EVT_MRPC_COMP_ASYNC,
342 SWITCHTEC_PART_EVT_DYN_PART_BIND_COMP,
343 SWITCHTEC_PFF_EVT_AER_IN_P2P,
344 SWITCHTEC_PFF_EVT_AER_IN_VEP,
345 SWITCHTEC_PFF_EVT_DPC,
346 SWITCHTEC_PFF_EVT_CTS,
347 SWITCHTEC_PFF_EVT_UEC,
348 SWITCHTEC_PFF_EVT_HOTPLUG,
349 SWITCHTEC_PFF_EVT_IER,
350 SWITCHTEC_PFF_EVT_THRESH,
351 SWITCHTEC_PFF_EVT_POWER_MGMT,
352 SWITCHTEC_PFF_EVT_TLP_THROTTLING,
353 SWITCHTEC_PFF_EVT_FORCE_SPEED,
354 SWITCHTEC_PFF_EVT_CREDIT_TIMEOUT,
355 SWITCHTEC_PFF_EVT_LINK_STATE,
356 SWITCHTEC_MAX_EVENTS,
357};
358
359/*********** Platform Functions ***********/
360
361struct switchtec_dev *switchtec_open(const char *device);
362struct switchtec_dev *switchtec_open_by_path(const char *path);
363struct switchtec_dev *switchtec_open_by_index(int index);
364struct switchtec_dev *switchtec_open_by_pci_addr(int domain, int bus,
365 int device, int func);
366struct switchtec_dev *switchtec_open_i2c(const char *path, int i2c_addr);
367struct switchtec_dev *switchtec_open_i2c_by_adapter(int adapter, int i2c_addr);
368struct switchtec_dev *switchtec_open_uart(int fd);
369struct switchtec_dev *switchtec_open_eth(const char *ip, const int inst);
370
371void switchtec_close(struct switchtec_dev *dev);
372int switchtec_list(struct switchtec_device_info **devlist);
373void switchtec_list_free(struct switchtec_device_info *devlist);
374int switchtec_get_fw_version(struct switchtec_dev *dev, char *buf,
375 size_t buflen);
376int switchtec_get_device_version(struct switchtec_dev *dev, int *res);
377int switchtec_cmd(struct switchtec_dev *dev, uint32_t cmd,
378 const void *payload, size_t payload_len, void *resp,
379 size_t resp_len);
380int switchtec_get_devices(struct switchtec_dev *dev,
381 struct switchtec_status *status,
382 int ports);
383int switchtec_pff_to_port(struct switchtec_dev *dev, int pff,
384 int *partition, int *port);
385int switchtec_port_to_pff(struct switchtec_dev *dev, int partition,
386 int port, int *pff);
387int switchtec_event_summary(struct switchtec_dev *dev,
388 struct switchtec_event_summary *sum);
389int switchtec_event_check(struct switchtec_dev *dev,
390 struct switchtec_event_summary *check,
391 struct switchtec_event_summary *res);
392int switchtec_event_ctl(struct switchtec_dev *dev,
393 enum switchtec_event_id e,
394 int index, int flags,
395 uint32_t data[5]);
396int switchtec_event_wait(struct switchtec_dev *dev, int timeout_ms);
397
398/*********** Generic Accessors ***********/
399
400_PURE const char *switchtec_name(struct switchtec_dev *dev);
401_PURE int switchtec_partition(struct switchtec_dev *dev);
402_PURE int switchtec_device_id(struct switchtec_dev *dev);
403_PURE enum switchtec_gen switchtec_gen(struct switchtec_dev *dev);
404_PURE enum switchtec_variant switchtec_variant(struct switchtec_dev *dev);
405_PURE enum switchtec_boot_phase
406switchtec_boot_phase(struct switchtec_dev *dev);
407int switchtec_set_pax_id(struct switchtec_dev *dev, int pax_id);
408int switchtec_echo(struct switchtec_dev *dev, uint32_t input, uint32_t *output);
409int switchtec_hard_reset(struct switchtec_dev *dev);
410int switchtec_status(struct switchtec_dev *dev,
411 struct switchtec_status **status);
412void switchtec_status_free(struct switchtec_status *status, int ports);
413int switchtec_get_device_info(struct switchtec_dev *dev,
414 enum switchtec_boot_phase *phase,
415 enum switchtec_gen *gen,
416 enum switchtec_rev *rev);
417const char *switchtec_strerror(void);
418void switchtec_perror(const char *str);
419int switchtec_log_to_file(struct switchtec_dev *dev,
420 enum switchtec_log_type type, int fd, FILE *log_def_file,
421 struct switchtec_log_file_info *info);
422int switchtec_parse_log(FILE *bin_log_file, FILE *log_def_file,
423 FILE *parsed_log_file,
424 enum switchtec_log_parse_type log_type,
425 enum switchtec_gen gen,
426 struct switchtec_log_file_info *info);
427int switchtec_log_def_to_file(struct switchtec_dev *dev,
428 enum switchtec_log_def_type type,
429 FILE* file);
430float switchtec_die_temp(struct switchtec_dev *dev);
431int switchtec_die_temps(struct switchtec_dev *dev, int nr_sensor,
432 float *sensor_readings);
433int switchtec_calc_lane_id(struct switchtec_dev *dev, int phys_port_id,
434 int lane_id, struct switchtec_status *port);
435int switchtec_calc_port_lane(struct switchtec_dev *dev, int lane_id,
436 int *phys_port_id, int *port_lane_id,
437 struct switchtec_status *port);
438int switchtec_calc_lane_mask(struct switchtec_dev *dev, int phys_port_id,
439 int lane_id, int num_lanes, int *lane_mask,
440 struct switchtec_status *port);
441
446
447int switchtec_inject_err_dllp(struct switchtec_dev *dev, int phys_port_id,
448 int data);
449int switchtec_inject_err_dllp_crc(struct switchtec_dev *dev, int phys_port_id,
450 int enable, uint16_t rate);
451int switchtec_inject_err_tlp_lcrc(struct switchtec_dev *dev, int phys_port_id,
452 int enable, uint8_t rate);
453int switchtec_inject_err_tlp_seq_num(struct switchtec_dev *dev, int phys_port_id);
454int switchtec_inject_err_ack_nack(struct switchtec_dev *dev, int phys_port_id,
455 uint16_t seq_num, uint8_t count);
456int switchtec_inject_err_cto(struct switchtec_dev *dev, int phys_port_id);
457
461static inline int switchtec_is_gen3(struct switchtec_dev *dev)
462{
463 return switchtec_gen(dev) == SWITCHTEC_GEN3;
464}
465
469static inline int switchtec_is_gen4(struct switchtec_dev *dev)
470{
471 return switchtec_gen(dev) == SWITCHTEC_GEN4;
472}
473
477static inline int switchtec_is_gen5(struct switchtec_dev *dev)
478{
479 return switchtec_gen(dev) == SWITCHTEC_GEN5;
480}
481
485static inline int switchtec_max_supported_ports(struct switchtec_dev *dev)
486{
487 return switchtec_is_gen5(dev) ? SWITCHTEC_MAX_PORTS :
488 switchtec_is_gen4(dev) ? 52 : 48;
489}
490
494static inline int switchtec_is_pfx(struct switchtec_dev *dev)
495{
496 return switchtec_variant(dev) == SWITCHTEC_PFX;
497}
498
502static inline int switchtec_is_pfxl(struct switchtec_dev *dev)
503{
504 return switchtec_variant(dev) == SWITCHTEC_PFXL;
505}
506
510static inline int switchtec_is_pfxi(struct switchtec_dev *dev)
511{
512 return switchtec_variant(dev) == SWITCHTEC_PFXI;
513}
514
518static inline int switchtec_is_pfxa(struct switchtec_dev *dev)
519{
520 return switchtec_variant(dev) == SWITCHTEC_PFXA;
521}
522
526static inline int switchtec_is_pfx_all(struct switchtec_dev *dev)
527{
528 return switchtec_is_pfx(dev) ||
529 switchtec_is_pfxl(dev) ||
530 switchtec_is_pfxi(dev) ||
532}
533
537static inline int switchtec_is_psx(struct switchtec_dev *dev)
538{
539 return switchtec_variant(dev) == SWITCHTEC_PSX;
540}
541
545static inline int switchtec_is_psxa(struct switchtec_dev *dev)
546{
547 return switchtec_variant(dev) == SWITCHTEC_PSXA;
548}
549
553static inline int switchtec_is_psx_all(struct switchtec_dev *dev)
554{
555 return switchtec_is_psx(dev) ||
557}
558
562static inline int switchtec_is_psx_pfx_all(struct switchtec_dev *dev)
563{
564 return switchtec_is_psx_all(dev) || switchtec_is_pfx_all(dev);
565}
566
570static inline int switchtec_is_pax(struct switchtec_dev *dev)
571{
572 return switchtec_variant(dev) == SWITCHTEC_PAX;
573}
574
578static inline int switchtec_is_paxa(struct switchtec_dev *dev)
579{
580 return switchtec_variant(dev) == SWITCHTEC_PAXA;
581}
582
586static inline int switchtec_is_pax_all(struct switchtec_dev *dev)
587{
588 return switchtec_is_pax(dev) || switchtec_is_paxa(dev);
589}
590
594static inline const char *switchtec_gen_str(struct switchtec_dev *dev)
595{
596 const char *str;
597
598 str = switchtec_is_gen3(dev) ? "GEN3" :
599 switchtec_is_gen4(dev) ? "GEN4" :
600 switchtec_is_gen5(dev) ? "GEN5" : "Unknown";
601
602 return str;
603}
604
608static inline const char *switchtec_rev_str(enum switchtec_rev rev)
609{
610 const char *str;
611
612 str = (rev == SWITCHTEC_REVA) ? "REVA" :
613 (rev == SWITCHTEC_REVB) ? "REVB" :
614 (rev == SWITCHTEC_REVC) ? "REVC" : "Unknown";
615
616 return str;
617}
618
622static inline const char *
624{
625 switch (inf->gen) {
626 case SWITCHTEC_GEN3: return "GEN3";
627 case SWITCHTEC_GEN4: return "GEN4";
628 case SWITCHTEC_GEN5: return "GEN5";
629 default: return "UNKNOWN";
630 }
631}
632
636static inline const char *switchtec_variant_str(struct switchtec_dev *dev)
637{
638 const char *str;
639
640 str = switchtec_is_pfx(dev) ? "PFX" :
641 switchtec_is_pfxl(dev) ? "PFX-L" :
642 switchtec_is_pfxi(dev) ? "PFX-I" :
643 switchtec_is_psx(dev) ? "PSX" :
644 switchtec_is_pax(dev) ? "PAX" :
645 switchtec_is_pfxa(dev) ? "PFX-A" :
646 switchtec_is_psxa(dev) ? "PSX-A" :
647 switchtec_is_paxa(dev) ? "PAX-A" : "Unknown";
648
649 return str;
650}
651
655static inline const char* switchtec_phase_id_str(
656 enum switchtec_boot_phase phase_id)
657{
658 switch(phase_id) {
659 case SWITCHTEC_BOOT_PHASE_BL1:
660 return "BL1";
661 case SWITCHTEC_BOOT_PHASE_BL2:
662 return "BL2";
663 case SWITCHTEC_BOOT_PHASE_FW:
664 return "Main Firmware";
665 default:
666 return "Unknown Phase";
667 }
668}
669
671static const float switchtec_gen_transfers[] = {0, 2.5, 5, 8, 16, 32};
673static const float switchtec_gen_datarate[] = {0, 250, 500, 985, 1969, 3938};
674
675static inline const char *switchtec_ltssm_str_gen4(int ltssm, int show_minor)
676{
677 if (!show_minor)
678 ltssm |= 0xFF00;
679
680 switch(ltssm) {
681 case 0x0000: return "Detect (INACTIVE)";
682 case 0x0100: return "Detect (QUIET)";
683 case 0x0200: return "Detect (SPD_CHD0)";
684 case 0x0300: return "Detect (SPD_CHD1)";
685 case 0x0400: return "Detect (ACTIVE0)";
686 case 0x0500: return "Detect (ACTIVE1)";
687 case 0x0600: return "Detect (P1_TO_P0)";
688 case 0x0700: return "Detect (P0_TO_P1_0)";
689 case 0x0800: return "Detect (P0_TO_P1_1)";
690 case 0x0900: return "Detect (P0_TO_P1_2)";
691 case 0xFF00: return "Detect";
692 case 0x0001: return "Polling (INACTIVE)";
693 case 0x0101: return "Polling (ACTIVE_ENTRY)";
694 case 0x0201: return "Polling (ACTIVE)";
695 case 0x0301: return "Polling (CFG)";
696 case 0x0401: return "Polling (COMP)";
697 case 0x0501: return "Polling (COMP_ENTRY)";
698 case 0x0601: return "Polling (COMP_EIOS)";
699 case 0x0701: return "Polling (COMP_EIOS_ACK)";
700 case 0x0801: return "Polling (COMP_IDLE)";
701 case 0xFF01: return "Polling";
702 case 0x0002: return "Config (INACTIVE)";
703 case 0x0102: return "Config (US_LW_START)";
704 case 0x0202: return "Config (US_LW_ACCEPT)";
705 case 0x0302: return "Config (US_LN_WAIT)";
706 case 0x0402: return "Config (US_LN_ACCEPT)";
707 case 0x0502: return "Config (DS_LW_START)";
708 case 0x0602: return "Config (DS_LW_ACCEPT)";
709 case 0x0702: return "Config (DS_LN_WAIT)";
710 case 0x0802: return "Config (DS_LN_ACCEPT)";
711 case 0x0902: return "Config (COMPLETE)";
712 case 0x0A02: return "Config (IDLE)";
713 case 0xFF02: return "Config";
714 case 0x0003: return "L0 (INACTIVE)";
715 case 0x0103: return "L0 (L0)";
716 case 0x0203: return "L0 (TX_EL_IDLE)";
717 case 0x0303: return "L0 (TX_IDLE_MIN)";
718 case 0xFF03: return "L0";
719 case 0x0004: return "Recovery (INACTIVE)";
720 case 0x0104: return "Recovery (RCVR_LOCK)";
721 case 0x0204: return "Recovery (RCVR_CFG)";
722 case 0x0304: return "Recovery (IDLE)";
723 case 0x0404: return "Recovery (SPEED0)";
724 case 0x0504: return "Recovery (SPEED1)";
725 case 0x0604: return "Recovery (SPEED2)";
726 case 0x0704: return "Recovery (SPEED3)";
727 case 0x0804: return "Recovery (EQ_PH0)";
728 case 0x0904: return "Recovery (EQ_PH1)";
729 case 0x0A04: return "Recovery (EQ_PH2)";
730 case 0x0B04: return "Recovery (EQ_PH3)";
731 case 0xFF04: return "Recovery";
732 case 0x0005: return "Disable (INACTIVE)";
733 case 0x0105: return "Disable (DISABLE0)";
734 case 0x0205: return "Disable (DISABLE1)";
735 case 0x0305: return "Disable (DISABLE2)";
736 case 0x0405: return "Disable (DISABLE3)";
737 case 0xFF05: return "Disable";
738 case 0x0006: return "Loop Back (INACTIVE)";
739 case 0x0106: return "Loop Back (ENTRY)";
740 case 0x0206: return "Loop Back (ENTRY_EXIT)";
741 case 0x0306: return "Loop Back (EIOS)";
742 case 0x0406: return "Loop Back (EIOS_ACK)";
743 case 0x0506: return "Loop Back (IDLE)";
744 case 0x0606: return "Loop Back (ACTIVE)";
745 case 0x0706: return "Loop Back (EXIT0)";
746 case 0x0806: return "Loop Back (EXIT1)";
747 case 0xFF06: return "Loop Back";
748 case 0x0007: return "Hot Reset (INACTIVE)";
749 case 0x0107: return "Hot Reset (HOT_RESET)";
750 case 0x0207: return "Hot Reset (MASTER_UP)";
751 case 0x0307: return "Hot Reset (MASTER_DOWN)";
752 case 0xFF07: return "Hot Reset";
753 case 0x0008: return "TxL0s (INACTIVE)";
754 case 0x0108: return "TxL0s (IDLE)";
755 case 0x0208: return "TxL0s (T0_L0)";
756 case 0x0308: return "TxL0s (FTS0)";
757 case 0x0408: return "TxL0s (FTS1)";
758 case 0xFF08: return "TxL0s";
759 case 0x0009: return "L1 (INACTIVE)";
760 case 0x0109: return "L1 (IDLE)";
761 case 0x0209: return "L1 (SUBSTATE)";
762 case 0x0309: return "L1 (SPD_CHG1)";
763 case 0x0409: return "L1 (T0_L0)";
764 case 0xFF09: return "L1";
765 case 0x000A: return "L2 (INACTIVE)";
766 case 0x010A: return "L2 (IDLE)";
767 case 0x020A: return "L2 (TX_WAKE0)";
768 case 0x030A: return "L2 (TX_WAKE1)";
769 case 0x040A: return "L2 (EXIT)";
770 case 0x050A: return "L2 (SPEED)";
771 case 0xFF0A: return "L2";
772 default: return "UNKNOWN";
773 }
774
775}
776
777static inline const char *switchtec_ltssm_str_gen5(int ltssm, int show_minor)
778{
779 if (!show_minor)
780 ltssm |= 0xFF00;
781
782 switch(ltssm) {
783 case 0x0000: return "Detect (INACTIVE)";
784 case 0x0100: return "Detect (QUIET)";
785 case 0x0200: return "Detect (SPD_CHG0)";
786 case 0x0300: return "Detect (SPD_CHG1)";
787 case 0x0400: return "Detect (ACTIVE0)";
788 case 0x0500: return "Detect (ACTIVE1)";
789 case 0x0600: return "Detect (ACTIVE2)";
790 case 0x0700: return "Detect (P1_TO_P0)";
791 case 0x0800: return "Detect (P0_TO_P1_0)";
792 case 0x0900: return "Detect (P0_TO_P1_1)";
793 case 0x0A00: return "Detect (P0_TO_P1_2)";
794 case 0xFF00: return "Detect";
795 case 0x0001: return "Polling (INACTIVE)";
796 case 0x0101: return "Polling (ACTIVE_ENTRY)";
797 case 0x0201: return "Polling (ACTIVE)";
798 case 0x0301: return "Polling (CFG)";
799 case 0x0401: return "Polling (COMP)";
800 case 0x0501: return "Polling (COMP_ENTRY)";
801 case 0x0601: return "Polling (COMP_EIOS)";
802 case 0x0701: return "Polling (COMP_EIOS_ACK)";
803 case 0x0801: return "Polling (COMP_IDLE)";
804 case 0xFF01: return "Polling";
805 case 0x0002: return "Config (INACTIVE)";
806 case 0x0102: return "Config (US_LW_START)";
807 case 0x0202: return "Config (US_LW_ACCEPT)";
808 case 0x0302: return "Config (US_LN_WAIT)";
809 case 0x0402: return "Config (US_LN_ACCEPT)";
810 case 0x0502: return "Config (DS_LW_START)";
811 case 0x0602: return "Config (DS_LW_ACCEPT)";
812 case 0x0702: return "Config (DS_LN_WAIT)";
813 case 0x0802: return "Config (DS_LN_ACCEPT)";
814 case 0x0902: return "Config (COMPLETE)";
815 case 0x0A02: return "Config (IDLE)";
816 case 0xFF02: return "Config";
817 case 0x0003: return "L0 (INACTIVE)";
818 case 0x0103: return "L0 (L0)";
819 case 0x0203: return "L0 (TX_EL_IDLE)";
820 case 0x0303: return "L0 (TX_IDLE_MIN)";
821 case 0xFF03: return "L0";
822 case 0x0004: return "Recovery (INACTIVE)";
823 case 0x0104: return "Recovery (RCVR_LOCK)";
824 case 0x0204: return "Recovery (RCVR_CFG)";
825 case 0x0304: return "Recovery (IDLE)";
826 case 0x0404: return "Recovery (SPEED0)";
827 case 0x0504: return "Recovery (SPEED1)";
828 case 0x0604: return "Recovery (SPEED2)";
829 case 0x0704: return "Recovery (SPEED3)";
830 case 0x0804: return "Recovery (EQ_PH0)";
831 case 0x0904: return "Recovery (EQ_PH1)";
832 case 0x0A04: return "Recovery (EQ_PH2)";
833 case 0x0B04: return "Recovery (EQ_PH3)";
834 case 0xFF04: return "Recovery";
835 case 0x0005: return "Disable (INACTIVE)";
836 case 0x0105: return "Disable (DISABLE0)";
837 case 0x0205: return "Disable (DISABLE1)";
838 case 0x0305: return "Disable (DISABLE2)";
839 case 0x0405: return "Disable (DISABLE3)";
840 case 0xFF05: return "Disable";
841 case 0x0006: return "Loop Back (INACTIVE)";
842 case 0x0106: return "Loop Back (ENTRY)";
843 case 0x0206: return "Loop Back (ENTRY_EXIT)";
844 case 0x0306: return "Loop Back (EIOS)";
845 case 0x0406: return "Loop Back (EIOS_ACK)";
846 case 0x0506: return "Loop Back (IDLE)";
847 case 0x0606: return "Loop Back (ACTIVE)";
848 case 0x0706: return "Loop Back (EXIT0)";
849 case 0x0806: return "Loop Back (EXIT1)";
850 case 0xFF06: return "Loop Back";
851 case 0x0007: return "Hot Reset (INACTIVE)";
852 case 0x0107: return "Hot Reset (HOT_RESET)";
853 case 0x0207: return "Hot Reset (MASTER_UP)";
854 case 0x0307: return "Hot Reset (MASTER_DOWN)";
855 case 0xFF07: return "Hot Reset";
856 case 0x0008: return "TxL0s (INACTIVE)";
857 case 0x0108: return "TxL0s (IDLE)";
858 case 0x0208: return "TxL0s (T0_L0)";
859 case 0x0308: return "TxL0s (FTS0)";
860 case 0x0408: return "TxL0s (FTS1)";
861 case 0xFF08: return "TxL0s";
862 case 0x0009: return "L1 (INACTIVE)";
863 case 0x0109: return "L1 (IDLE)";
864 case 0x0209: return "L1 (SUBSTATE)";
865 case 0x0309: return "L1 (TO_L0)";
866 case 0xFF09: return "L1";
867 case 0x000A: return "L2 (INACTIVE)";
868 case 0x010A: return "L2 (IDLE)";
869 case 0x020A: return "L2 (TX_WAKE0)";
870 case 0x030A: return "L2 (TX_WAKE1)";
871 case 0x040A: return "L2 (EXIT)";
872 case 0x050A: return "L2 (SPEED)";
873 case 0xFF0A: return "L2";
874 default: return "UNKNOWN";
875 }
876}
877
878static inline const char *switchtec_ltssm_str(int ltssm, int show_minor,
879 struct switchtec_dev *dev)
880{
881 if(switchtec_is_gen5(dev))
882 return switchtec_ltssm_str_gen5(ltssm, show_minor);
883 else
884 return switchtec_ltssm_str_gen4(ltssm, show_minor);
885}
886
887/*********** EVENT Handling ***********/
888
894 SWITCHTEC_EVT_FLAG_CLEAR = 1 << 0,
895 SWITCHTEC_EVT_FLAG_EN_POLL = 1 << 1,
896 SWITCHTEC_EVT_FLAG_EN_LOG = 1 << 2,
897 SWITCHTEC_EVT_FLAG_EN_CLI = 1 << 3,
898 SWITCHTEC_EVT_FLAG_EN_FATAL = 1 << 4,
899 SWITCHTEC_EVT_FLAG_DIS_POLL = 1 << 5,
900 SWITCHTEC_EVT_FLAG_DIS_LOG = 1 << 6,
901 SWITCHTEC_EVT_FLAG_DIS_CLI = 1 << 7,
902 SWITCHTEC_EVT_FLAG_DIS_FATAL = 1 << 8,
903};
904
913 SWITCHTEC_EVT_IDX_LOCAL = -1,
914 SWITCHTEC_EVT_IDX_ALL = -2,
915};
916
922 SWITCHTEC_EVT_GLOBAL,
923 SWITCHTEC_EVT_PART,
924 SWITCHTEC_EVT_PFF,
925};
926
928 enum switchtec_event_id e,
929 int index);
931 enum switchtec_event_id e,
932 int index);
934 enum switchtec_event_id *e,
935 int *idx);
937 const char **name,
938 const char **desc);
939int switchtec_event_wait_for(struct switchtec_dev *dev,
940 enum switchtec_event_id e, int index,
941 struct switchtec_event_summary *res,
942 int timeout_ms);
943
944/******** FIRMWARE Management ********/
945
951 SWITCHTEC_DLSTAT_READY = 0x0,
952 SWITCHTEC_DLSTAT_INPROGRESS = 0x1,
953 SWITCHTEC_DLSTAT_HEADER_INCORRECT = 0x2,
954 SWITCHTEC_DLSTAT_OFFSET_INCORRECT = 0x3,
955 SWITCHTEC_DLSTAT_CRC_INCORRECT = 0x4,
956 SWITCHTEC_DLSTAT_LENGTH_INCORRECT = 0x5,
957 SWITCHTEC_DLSTAT_HARDWARE_ERR = 0x6,
958 SWITCHTEC_DLSTAT_COMPLETES = 0x7,
959 SWITCHTEC_DLSTAT_SUCCESS_FIRM_ACT = 0x8,
960 SWITCHTEC_DLSTAT_SUCCESS_DATA_ACT = 0x9,
961 SWITCHTEC_DLSTAT_PACKAGE_TOO_SMALL = 0xa,
962 SWITCHTEC_DLSTAT_SIG_MEM_ALLOC = 0xb,
963 SWITCHTEC_DLSTAT_SEEPROM = 0xc,
964 SWITCHTEC_DLSTAT_READONLY_PARTITION = 0xd,
965 SWITCHTEC_DLSTAT_DOWNLOAD_TIMEOUT = 0xe,
966 SWITCHTEC_DLSTAT_SEEPROM_TWI_NOT_ENABLED = 0xf,
967 SWITCHTEC_DLSTAT_PROGRAM_RUNNING = 0x10,
968 SWITCHTEC_DLSTAT_NOT_ALLOWED = 0x11,
969 SWITCHTEC_DLSTAT_XML_MISMATCH_ACT = 0x12,
970 SWITCHTEC_DLSTAT_UNKNOWN_ACT = 0x13,
971
972 SWITCHTEC_DLSTAT_ERROR_PROGRAM = 0x1000,
973 SWITCHTEC_DLSTAT_ERROR_OFFSET = 0x1001,
974
975 SWITCHTEC_DLSTAT_NO_FILE = 0x7d009,
976};
977
982 SWITCHTEC_FW_RW = 0,
983 SWITCHTEC_FW_RO = 1,
984};
985
986int switchtec_fw_set_redundant_flag(struct switchtec_dev *dev,
987 int keyman, int riot,
988 int bl2, int cfg, int fw,
989 int set);
990int switchtec_fw_toggle_active_partition(struct switchtec_dev *dev,
991 int toggle_bl2, int toggle_key,
992 int toggle_fw, int toggle_cfg,
993 int toggle_riotcore);
994int switchtec_fw_write_fd(struct switchtec_dev *dev, int img_fd,
995 int dont_activate, int force,
996 void (*progress_callback)(int cur, int tot));
997int switchtec_fw_write_file(struct switchtec_dev *dev, FILE *fimg,
998 int dont_activate, int force,
999 void (*progress_callback)(int cur, int tot));
1000int switchtec_fw_read_fd(struct switchtec_dev *dev, int fd,
1001 unsigned long addr, size_t len,
1002 void (*progress_callback)(int cur, int tot));
1003int switchtec_fw_body_read_fd(struct switchtec_dev *dev, int fd,
1004 struct switchtec_fw_image_info *info,
1005 void (*progress_callback)(int cur, int tot));
1006int switchtec_fw_read(struct switchtec_dev *dev, unsigned long addr,
1007 size_t len, void *buf);
1008void switchtec_fw_perror(const char *s, int ret);
1009int switchtec_fw_file_info(int fd, struct switchtec_fw_image_info *info);
1010int switchtec_get_device_id_bl2(struct switchtec_dev *dev,
1011 unsigned short *device_id);
1012int switchtec_fw_file_secure_version_newer(struct switchtec_dev *dev,
1013 int img_fd);
1014const char *switchtec_fw_image_type(const struct switchtec_fw_image_info *info);
1016switchtec_fw_part_summary(struct switchtec_dev *dev);
1018int switchtec_fw_img_write_hdr(int fd, struct switchtec_fw_image_info *info);
1019int switchtec_fw_is_boot_ro(struct switchtec_dev *dev);
1020int switchtec_fw_set_boot_ro(struct switchtec_dev *dev,
1021 enum switchtec_fw_ro ro);
1022enum switchtec_gen switchtec_fw_version_to_gen(unsigned int version);
1023int switchtec_bind_info(struct switchtec_dev *dev,
1024 struct switchtec_bind_status_out *bind_status,
1025 int phy_port);
1026int switchtec_bind(struct switchtec_dev *dev, int par_id,
1027 int log_port, int phy_port);
1028int switchtec_unbind(struct switchtec_dev *dev, int par_id, int log_port);
1029bool switchtec_stack_bif_port_valid(struct switchtec_dev *dev, int stack_id,
1030 int port_id);
1031int switchtec_stack_bif_width(struct switchtec_dev *dev, int stack_id,
1032 int port_bif);
1033int switchtec_get_stack_bif(struct switchtec_dev *dev, int stack_id,
1034 int port_bif[SWITCHTEC_PORTS_PER_STACK]);
1035int switchtec_set_stack_bif(struct switchtec_dev *dev, int stack_id,
1036 int port_bif[SWITCHTEC_PORTS_PER_STACK]);
1037
1038/******** GPIO Management ********/
1039
1041 uint8_t sub_cmd;
1042 uint8_t resvd;
1043 uint16_t log_gpio_id;
1044 uint8_t data;
1045 uint8_t resvd1[3];
1046};
1047
1049 uint8_t sub_cmd;
1050 uint8_t resvd;
1051 uint16_t pin_num;
1052 uint32_t pin_values[SWITCHTEC_MAX_GPIO_PIN_VALS];
1053};
1054
1055int switchtec_get_gpio(struct switchtec_dev *dev, int pin_id,
1056 int *gpio_val);
1057int switchtec_set_gpio(struct switchtec_dev *dev, int pin_id,
1058 int gpio_val);
1059int switchtec_get_gpio_direction_cfg(struct switchtec_dev *dev, int pin_id,
1060 int *direction);
1061int switchtec_get_gpio_polarity_cfg(struct switchtec_dev *dev, int pin_id,
1062 int *polarity);
1063int switchtec_en_dis_interrupt(struct switchtec_dev *dev, int pin_id, int en);
1064int switchtec_get_all_pin_sts(struct switchtec_dev *dev, uint32_t *values);
1065
1066/********** EVENT COUNTER *********/
1067
1116
1121extern const struct switchtec_evcntr_type_list {
1123 const char *name;
1124 const char *help;
1126
1131 unsigned port_mask; //<! Mask of ports this counter counts
1132
1135 int egress; //<! If 1, count egress, otherwise on ingress
1136
1141 unsigned threshold;
1142};
1143
1145const char *switchtec_evcntr_type_str(int *type_mask);
1146int switchtec_evcntr_setup(struct switchtec_dev *dev, unsigned stack_id,
1147 unsigned cntr_id,
1148 struct switchtec_evcntr_setup *setup);
1149int switchtec_evcntr_get_setup(struct switchtec_dev *dev, unsigned stack_id,
1150 unsigned cntr_id, unsigned nr_cntrs,
1151 struct switchtec_evcntr_setup *res);
1152int switchtec_evcntr_get(struct switchtec_dev *dev, unsigned stack_id,
1153 unsigned cntr_id, unsigned nr_cntrs, unsigned *res,
1154 int clear);
1155int switchtec_evcntr_get_both(struct switchtec_dev *dev, unsigned stack_id,
1156 unsigned cntr_id, unsigned nr_cntrs,
1157 struct switchtec_evcntr_setup *setup,
1158 unsigned *counts, int clear);
1159int switchtec_evcntr_wait(struct switchtec_dev *dev, int timeout_ms);
1160
1161/********** BANDWIDTH COUNTER *********/
1162
1175
1176void switchtec_bwcntr_sub(struct switchtec_bwcntr_res *new_cntr,
1177 struct switchtec_bwcntr_res *old_cntr);
1178int switchtec_bwcntr_set_many(struct switchtec_dev *dev, int nr_ports,
1179 int * phys_port_ids,
1180 enum switchtec_bw_type bw_type);
1181int switchtec_bwcntr_set_all(struct switchtec_dev *dev,
1182 enum switchtec_bw_type bw_type);
1183int switchtec_bwcntr_many(struct switchtec_dev *dev, int nr_ports,
1184 int *phys_port_ids, int clear,
1185 struct switchtec_bwcntr_res *res);
1186int switchtec_bwcntr_all(struct switchtec_dev *dev, int clear,
1187 struct switchtec_port_id **ports,
1188 struct switchtec_bwcntr_res **res);
1189uint64_t switchtec_bwcntr_tot(struct switchtec_bwcntr_dir *d);
1190
1191/********** LATENCY COUNTER *********/
1192
1193#define SWITCHTEC_LAT_ALL_INGRESS 63
1194
1195int switchtec_lat_setup_many(struct switchtec_dev *dev, int nr_ports,
1196 int *egress_port_ids, int *ingress_port_ids);
1197int switchtec_lat_setup(struct switchtec_dev *dev, int egress_port_id,
1198 int ingress_port_id, int clear);
1199int switchtec_lat_get_many(struct switchtec_dev *dev, int nr_ports,
1200 int clear, int *egress_port_ids,
1201 int *cur_ns, int *max_ns);
1202int switchtec_lat_get(struct switchtec_dev *dev, int clear,
1203 int egress_port_ids, int *cur_ns,
1204 int *max_ns);
1205
1206/********** GLOBAL ADDRESS SPACE ACCESS *********/
1207
1208/*
1209 * GAS map maps the hardware registers into user memory space.
1210 * Needless to say, this can be very dangerous and should only
1211 * be done if you know what you are doing. Any register accesses
1212 * that use this will remain unsupported by Microsemi unless it's
1213 * done within the switchtec user project or otherwise specified.
1214 */
1215
1216gasptr_t switchtec_gas_map(struct switchtec_dev *dev, int writeable,
1217 size_t *map_size);
1218void switchtec_gas_unmap(struct switchtec_dev *dev, gasptr_t map);
1219
1220/********** DIAGNOSTIC FUNCTIONS *********/
1221
1222#define SWITCHTEC_DIAG_CROSS_HAIR_ALL_LANES -1
1223#define SWITCHTEC_DIAG_CROSS_HAIR_MAX_LANES 64
1224
1225enum switchtec_diag_cross_hair_state {
1226 SWITCHTEC_DIAG_CROSS_HAIR_DISABLED = 0,
1227 SWITCHTEC_DIAG_CROSS_HAIR_RESVD,
1228 SWITCHTEC_DIAG_CROSS_HAIR_WAITING,
1229 SWITCHTEC_DIAG_CROSS_HAIR_FIRST_ERROR_RIGHT,
1230 SWITCHTEC_DIAG_CROSS_HAIR_ERROR_FREE_RIGHT,
1231 SWITCHTEC_DIAG_CROSS_HAIR_FINAL_RIGHT,
1232 SWITCHTEC_DIAG_CROSS_HAIR_FIRST_ERROR_LEFT,
1233 SWITCHTEC_DIAG_CROSS_HAIR_ERROR_FREE_LEFT,
1234 SWITCHTEC_DIAG_CROSS_HAIR_FINAL_LEFT,
1235 SWITCHTEC_DIAG_CROSS_HAIR_FIRST_ERROR_TOP_RIGHT,
1236 SWITCHTEC_DIAG_CROSS_HAIR_ERROR_FREE_TOP_RIGHT,
1237 SWITCHTEC_DIAG_CROSS_HAIR_FINAL_TOP_RIGHT,
1238 SWITCHTEC_DIAG_CROSS_HAIR_FIRST_ERROR_BOT_RIGHT,
1239 SWITCHTEC_DIAG_CROSS_HAIR_ERROR_FREE_BOT_RIGHT,
1240 SWITCHTEC_DIAG_CROSS_HAIR_FINAL_BOT_RIGHT,
1241 SWITCHTEC_DIAG_CROSS_HAIR_FIRST_ERROR_TOP_LEFT,
1242 SWITCHTEC_DIAG_CROSS_HAIR_ERROR_FREE_TOP_LEFT,
1243 SWITCHTEC_DIAG_CROSS_HAIR_FINAL_TOP_LEFT,
1244 SWITCHTEC_DIAG_CROSS_HAIR_FIRST_ERROR_BOT_LEFT,
1245 SWITCHTEC_DIAG_CROSS_HAIR_ERROR_FREE_BOT_LEFT,
1246 SWITCHTEC_DIAG_CROSS_HAIR_FINAL_BOT_LEFT,
1247 SWITCHTEC_DIAG_CROSS_HAIR_DONE,
1248 SWITCHTEC_DIAG_CROSS_HAIR_ERROR,
1249};
1250
1252 enum switchtec_diag_cross_hair_state state;
1253 int lane_id;
1254
1255 union {
1256 struct {
1257 /* Valid when state is Error */
1258 int prev_state;
1259 int x_pos;
1260 int y_pos;
1261 };
1262 /* Valid when state is DONE */
1263 struct {
1264 int eye_left_lim;
1265 int eye_right_lim;
1266 int eye_bot_left_lim;
1267 int eye_bot_right_lim;
1268 int eye_top_left_lim;
1269 int eye_top_right_lim;
1270 };
1271 };
1272};
1273
1275 int port_id;
1276 int lane_id;
1277 int ctle;
1278 int target_amplitude;
1279 int speculative_dfe;
1280 int dynamic_dfe[7];
1281};
1282
1284 uint8_t lane_cnt;
1285 uint8_t reserved[3];
1286 struct {
1287 uint8_t pre;
1288 uint8_t post;
1289 } cursors[16];
1290};
1291
1293 uint8_t lane_cnt;
1294 uint8_t reserved[3];
1295 struct {
1296 uint8_t is_coef;
1297 uint8_t pre;
1298 uint8_t post;
1299 uint8_t preset;
1300 } cursors[16];
1301};
1302
1308
1318
1320 uint8_t cmd;
1321 uint8_t op_type;
1322 uint8_t phys_port_id;
1323 uint8_t lane_id;
1324 uint8_t dump_type;
1325 uint8_t prev_rate;
1326 uint8_t reserved[2];
1327};
1328
1330 uint8_t sub_cmd;
1331 uint8_t port_id;
1332 uint8_t dump_type;
1333 uint8_t prev_rate;
1334};
1335
1337 int lane_id;
1338 int step_cnt;
1339
1340 struct {
1341 int pre_cursor;
1342 int post_cursor;
1343 int fom;
1344 int pre_cursor_up;
1345 int post_cursor_up;
1346 int error_status;
1347 int active_status;
1348 int speed;
1349 } steps[126];
1350};
1351
1353 uint8_t lane_id;
1354 uint8_t step_cnt;
1355 uint8_t reserved[2];
1356
1357 struct {
1358 uint8_t pre_cursor;
1359 uint8_t post_cursor;
1360 uint16_t reserved_0;
1361 uint8_t reserved_1;
1362 uint8_t error_status;
1363 uint8_t active_status;
1364 uint8_t speed;
1365 } steps[25];
1366};
1367
1369 int fs;
1370 int lf;
1371};
1372
1374 uint8_t fs;
1375 uint8_t lf;
1376 uint8_t reserved[2];
1377};
1378
1380 uint8_t sub_cmd;
1381 uint8_t port_id;
1382 uint8_t lane_id;
1383 uint8_t dump_type;
1384 uint8_t prev_rate;
1385 uint8_t reserved[3];
1386};
1387
1389 int ctle2_rx_mode;
1390 int dtclk_5;
1391 int dtclk_8_6;
1392 int dtclk_9;
1393};
1394
1396 const char *tag;
1397 const char *desc;
1398 bool reserved;
1399};
1400
1401enum switchtec_diag_eye_data_mode {
1402 SWITCHTEC_DIAG_EYE_RAW,
1403 SWITCHTEC_DIAG_EYE_RATIO,
1404};
1405
1407 uint8_t sub_cmd;
1408 uint8_t resvd1[3];
1409};
1410
1412 uint8_t status;
1413 uint8_t resvd1[3];
1414};
1415
1417 uint8_t sub_cmd;
1418 uint8_t lane_id;
1419 uint8_t bin;
1420 uint8_t resvd1;
1421};
1422
1424 uint8_t num_phases;
1425 uint8_t resvd1[3];
1426 uint32_t resvd2;
1427 uint64_t ber_data[60];
1428};
1429
1430enum switchtec_diag_loopback_enable {
1431 SWITCHTEC_DIAG_LOOPBACK_RX_TO_TX = 1 << 0,
1432 SWITCHTEC_DIAG_LOOPBACK_TX_TO_RX = 1 << 1,
1433 SWITCHTEC_DIAG_LOOPBACK_LTSSM = 1 << 2,
1434};
1435
1436enum switchtec_diag_pattern {
1437 SWITCHTEC_DIAG_PATTERN_PRBS_7,
1438 SWITCHTEC_DIAG_PATTERN_PRBS_11,
1439 SWITCHTEC_DIAG_PATTERN_PRBS_23,
1440 SWITCHTEC_DIAG_PATTERN_PRBS_31,
1441 SWITCHTEC_DIAG_PATTERN_PRBS_9,
1442 SWITCHTEC_DIAG_PATTERN_PRBS_15,
1443 SWITCHTEC_DIAG_PATTERN_PRBS_DISABLED,
1444};
1445
1446enum switchtec_diag_pattern_gen5 {
1447 SWITCHTEC_DIAG_GEN_5_PATTERN_PRBS_7,
1448 SWITCHTEC_DIAG_GEN_5_PATTERN_PRBS_11,
1449 SWITCHTEC_DIAG_GEN_5_PATTERN_PRBS_23,
1450 SWITCHTEC_DIAG_GEN_5_PATTERN_PRBS_31,
1451 SWITCHTEC_DIAG_GEN_5_PATTERN_PRBS_9,
1452 SWITCHTEC_DIAG_GEN_5_PATTERN_PRBS_15,
1453 SWITCHTEC_DIAG_GEN_5_PATTERN_PRBS_5,
1454 SWITCHTEC_DIAG_GEN_5_PATTERN_PRBS_20,
1455 SWITCHTEC_DIAG_GEN_5_RESERVED_0,
1456 SWITCHTEC_DIAG_GEN_5_RESERVED_1,
1457 SWITCHTEC_DIAG_GEN_5_PATTERN_PRBS_DISABLED,
1458};
1459
1460enum switchtec_diag_pattern_link_rate {
1461 SWITCHTEC_DIAG_PAT_LINK_DISABLED = 0,
1462 SWITCHTEC_DIAG_PAT_LINK_GEN1 = 1,
1463 SWITCHTEC_DIAG_PAT_LINK_GEN2 = 2,
1464 SWITCHTEC_DIAG_PAT_LINK_GEN3 = 3,
1465 SWITCHTEC_DIAG_PAT_LINK_GEN4 = 4,
1466 SWITCHTEC_DIAG_PAT_LINK_GEN5 = 5,
1467};
1468
1469enum switchtec_diag_ltssm_speed {
1470 SWITCHTEC_DIAG_LTSSM_GEN1 = 0,
1471 SWITCHTEC_DIAG_LTSSM_GEN2 = 1,
1472 SWITCHTEC_DIAG_LTSSM_GEN3 = 2,
1473 SWITCHTEC_DIAG_LTSSM_GEN4 = 3,
1474 SWITCHTEC_DIAG_LTSSM_GEN5 = 4,
1475};
1476
1477enum switchtec_diag_end {
1478 SWITCHTEC_DIAG_LOCAL,
1479 SWITCHTEC_DIAG_FAR_END,
1480};
1481
1482enum switchtec_diag_link {
1483 SWITCHTEC_DIAG_LINK_CURRENT,
1484 SWITCHTEC_DIAG_LINK_PREVIOUS,
1485};
1486
1487enum switchtec_gen5_diag_eye_status {
1488 SWITCHTEC_GEN5_DIAG_EYE_STATUS_IDLE = 0,
1489 SWITCHTEC_GEN5_DIAG_EYE_STATUS_PENDING = 1,
1490 SWITCHTEC_GEN5_DIAG_EYE_STATUS_IN_PROGRESS = 2,
1491 SWITCHTEC_GEN5_DIAG_EYE_STATUS_DONE = 3,
1492 SWITCHTEC_GEN5_DIAG_EYE_STATUS_TIMEOUT = 4,
1493 SWITCHTEC_GEN5_DIAG_EYE_STATUS_ERROR = 5,
1494};
1495
1497 unsigned int timestamp;
1498 float link_rate;
1499 int link_state;
1500};
1501
1502int switchtec_diag_cross_hair_enable(struct switchtec_dev *dev, int lane_id);
1503int switchtec_diag_cross_hair_disable(struct switchtec_dev *dev);
1504int switchtec_diag_cross_hair_get(struct switchtec_dev *dev, int start_lane_id,
1505 int num_lanes, struct switchtec_diag_cross_hair *res);
1506
1507int switchtec_diag_eye_set_mode(struct switchtec_dev *dev,
1508 enum switchtec_diag_eye_data_mode mode);
1509int switchtec_diag_eye_read(struct switchtec_dev *dev, int lane_id, int bin,
1510 int* num_phases, double* ber_data);
1511int switchtec_diag_eye_start(struct switchtec_dev *dev, int lane_mask[4],
1512 struct range *x_range, struct range *y_range,
1513 int step_interval, int capture_depth);
1514int switchtec_diag_eye_fetch(struct switchtec_dev *dev, double *pixels,
1515 size_t pixel_cnt, int *lane_id);
1516int switchtec_diag_eye_cancel(struct switchtec_dev *dev);
1517
1518int switchtec_diag_loopback_set(struct switchtec_dev *dev, int port_id,
1519 int enable, int enable_parallel,
1520 int enable_external, int enable_ltssm,
1521 enum switchtec_diag_ltssm_speed ltssm_speed);
1522int switchtec_diag_loopback_get(struct switchtec_dev *dev, int port_id,
1523 int *enabled,
1524 enum switchtec_diag_ltssm_speed *ltssm_speed);
1525int switchtec_diag_pattern_gen_set(struct switchtec_dev *dev, int port_id,
1526 enum switchtec_diag_pattern type,
1527 enum switchtec_diag_pattern_link_rate
1528 link_speed);
1529int switchtec_diag_pattern_gen_get(struct switchtec_dev *dev, int port_id,
1530 enum switchtec_diag_pattern *type);
1531int switchtec_diag_pattern_mon_set(struct switchtec_dev *dev, int port_id,
1532 enum switchtec_diag_pattern type);
1533int switchtec_diag_pattern_mon_get(struct switchtec_dev *dev, int port_id,
1534 int lane_id,
1535 enum switchtec_diag_pattern *type,
1536 unsigned long long *err_cnt);
1537int switchtec_diag_pattern_inject(struct switchtec_dev *dev, int port_id,
1538 unsigned int err_cnt);
1539
1540int switchtec_diag_rcvr_obj(struct switchtec_dev *dev, int port_id,
1541 int lane_id, enum switchtec_diag_link link,
1542 struct switchtec_rcvr_obj *res);
1543int switchtec_diag_rcvr_ext(struct switchtec_dev *dev, int port_id,
1544 int lane_id, enum switchtec_diag_link link,
1545 struct switchtec_rcvr_ext *res);
1546
1547int switchtec_diag_port_eq_tx_coeff(struct switchtec_dev *dev, int port_id,
1548 int prev_speed, enum switchtec_diag_end end,
1549 enum switchtec_diag_link link,
1550 struct switchtec_port_eq_coeff *res);
1551int switchtec_diag_port_eq_tx_table(struct switchtec_dev *dev, int port_id,
1552 int prev_speed,
1553 enum switchtec_diag_link link,
1554 struct switchtec_port_eq_table *res);
1555int switchtec_diag_port_eq_tx_fslf(struct switchtec_dev *dev, int port_id,
1556 int prev_speed, int lane_id,
1557 enum switchtec_diag_end end,
1558 enum switchtec_diag_link link,
1559 struct switchtec_port_eq_tx_fslf *res);
1560
1561int switchtec_diag_perm_table(struct switchtec_dev *dev,
1562 struct switchtec_mrpc table[MRPC_MAX_ID]);
1563int switchtec_diag_refclk_ctl(struct switchtec_dev *dev, int stack_id, bool en);
1564int switchtec_diag_refclk_status(struct switchtec_dev *dev, uint8_t *stack_info);
1565int switchtec_diag_ltssm_clear(struct switchtec_dev *dev, int port);
1566int switchtec_diag_ltssm_log(struct switchtec_dev *dev,
1567 int port, int *log_count,
1568 struct switchtec_diag_ltssm_log *log_data);
1569int switchtec_tlp_inject(struct switchtec_dev * dev, int port_id, int tlp_type,
1570 int tlp_length, int ecrc, uint32_t * raw_tlp_data);
1571int switchtec_aer_event_gen(struct switchtec_dev *dev, int port_id,
1572 int aer_error_id, int trigger_event);
1573int switchtec_osa(struct switchtec_dev * dev, int stack_id, int operation);
1574int switchtec_osa_config_type(struct switchtec_dev * dev, int stack_id,
1575 int direction, int lane_mask, int link_rate,
1576 int os_types);
1577int switchtec_osa_config_misc(struct switchtec_dev * dev, int stack_id,
1578 int trigger_en);
1579int switchtec_osa_capture_control(struct switchtec_dev * dev, int stack_id,
1580 int lane_mask, int direction,
1581 int drop_single_os, int stop_mode,
1582 int snapshot_mode, int post_trigger,
1583 int os_types);
1584int switchtec_osa_dump_conf(struct switchtec_dev * dev, int stack_id);
1585int switchtec_osa_config_pattern(struct switchtec_dev * dev, int stack_id,
1586 int direction, int lane_mask,int link_rate,
1587 uint32_t * value_data, uint32_t * mask_data);
1588int switchtec_osa_capture_data(struct switchtec_dev * dev, int stack_id,
1589 int lane, int direction);
1590#ifdef __cplusplus
1591}
1592#endif
1593
1594#endif
struct switchtec_dev * switchtec_open(const char *device)
Open a Switchtec device by string.
Definition switchtec.c:263
void switchtec_list_free(struct switchtec_device_info *devlist)
Free a list of device info structures allocated by switchtec_list().
Definition switchtec.c:241
struct switchtec_dev * switchtec_open_uart(int fd)
Open a switchtec device behind a uart device.
int switchtec_list(struct switchtec_device_info **devlist)
List all the switchtec devices in the system.
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.
Definition platform.c:178
void switchtec_close(struct switchtec_dev *dev)
Close a Switchtec device handle.
Definition platform.c:101
void switchtec_perror(const char *str)
Print an error string to stdout.
Definition switchtec.c:743
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().
Definition switchtec.c:581
int switchtec_status(struct switchtec_dev *dev, struct switchtec_status **status)
Get the status of all the ports on a switchtec device.
Definition switchtec.c:496
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.
Definition switchtec.c:396
const char * switchtec_strerror(void)
Return a message coresponding to the last error.
Definition switchtec.c:620
_PURE int switchtec_device_id(struct switchtec_dev *dev)
Get the device id of the device.
Definition switchtec.c:348
struct switchtec_dev * switchtec_open_eth(const char *ip, const int inst)
Open a switchtec device over ethernet.
int switchtec_get_devices(struct switchtec_dev *dev, struct switchtec_status *status, int ports)
Populate an already retrieved switchtec_status structure list with information about the devices plug...
Definition platform.c:208
int switchtec_get_device_version(struct switchtec_dev *dev, int *res)
Get the minor version number as a user readable int.
Definition platform.c:159
_PURE int switchtec_partition(struct switchtec_dev *dev)
Get the partiton number of the device that was opened.
Definition switchtec.c:406
int switchtec_get_fw_version(struct switchtec_dev *dev, char *buf, size_t buflen)
Get the firmware version as a user readable string.
Definition platform.c:125
struct switchtec_dev * switchtec_open_by_pci_addr(int domain, int bus, int device, int func)
Open a switchtec device by PCI address (BDF).
int switchtec_event_ctl(struct switchtec_dev *dev, enum switchtec_event_id e, int index, int flags, uint32_t data[5])
Enable, disable and clear events or retrieve event data.
Definition platform.c:327
int switchtec_event_summary_iter(struct switchtec_event_summary *sum, enum switchtec_event_id *e, int *idx)
Iterate through all set bits in an event summary structure.
Definition events.c:248
enum switchtec_event_type switchtec_event_info(enum switchtec_event_id e, const char **name, const char **desc)
Get the name and description strings as well as the type (global, partition or pff) for a specific ev...
Definition events.c:343
int switchtec_event_wait_for(struct switchtec_dev *dev, enum switchtec_event_id e, int index, struct switchtec_event_summary *res, int timeout_ms)
Block until a specific event occurs.
Definition events.c:369
int switchtec_event_summary_set(struct switchtec_event_summary *sum, enum switchtec_event_id e, int index)
Set a bit corresponding to an event in a summary structure.
Definition events.c:175
int switchtec_event_summary(struct switchtec_dev *dev, struct switchtec_event_summary *sum)
Retrieve a summary of all the events that have occurred in the switch.
Definition platform.c:311
int switchtec_event_wait(struct switchtec_dev *dev, int timeout_ms)
Wait for any event to occur (typically just an interrupt).
Definition platform.c:343
int switchtec_event_summary_test(struct switchtec_event_summary *sum, enum switchtec_event_id e, int index)
Test if a bit corresponding to an event is set in a summary structure.
Definition events.c:219
int switchtec_event_check(struct switchtec_dev *dev, struct switchtec_event_summary *check, struct switchtec_event_summary *res)
Check if one or more events have occurred.
Definition events.c:297
enum switchtec_gen switchtec_fw_version_to_gen(unsigned int version)
Extract generation information from FW version number.
Definition fw.c:464
int switchtec_fw_img_write_hdr(int fd, struct switchtec_fw_image_info *info)
Write the header for a Switchtec firmware image file.
Definition fw.c:1896
int switchtec_fw_read(struct switchtec_dev *dev, unsigned long addr, size_t len, void *buf)
Read a Switchtec device's flash data.
Definition fw.c:1744
int switchtec_fw_body_read_fd(struct switchtec_dev *dev, int fd, struct switchtec_fw_image_info *info, void(*progress_callback)(int cur, int tot))
Read a Switchtec device's flash image body into a file.
Definition fw.c:1837
int switchtec_fw_file_secure_version_newer(struct switchtec_dev *dev, int img_fd)
Check if the secure version of an image file is newer than that of the image on device.
Definition fw.c:909
int switchtec_fw_read_fd(struct switchtec_dev *dev, int fd, unsigned long addr, size_t len, void(*progress_callback)(int cur, int tot))
Read a Switchtec device's flash data into a file.
Definition fw.c:1788
int switchtec_fw_is_boot_ro(struct switchtec_dev *dev)
Check if the boot partition is marked as read-only.
Definition fw.c:1921
int switchtec_fw_file_info(int fd, struct switchtec_fw_image_info *info)
Retrieve information about a firmware image file.
Definition fw.c:876
int switchtec_fw_write_fd(struct switchtec_dev *dev, int img_fd, int dont_activate, int force, void(*progress_callback)(int cur, int tot))
Write a firmware file to the switchtec device.
Definition fw.c:372
void switchtec_fw_perror(const char *s, int ret)
Print an error string to stdout.
Definition fw.c:588
int switchtec_fw_set_boot_ro(struct switchtec_dev *dev, enum switchtec_fw_ro ro)
Set or clear a boot partition's read-only flag.
Definition fw.c:1960
void switchtec_fw_part_summary_free(struct switchtec_fw_part_summary *summary)
Free a firmware part summary data structure.
Definition fw.c:1726
int switchtec_fw_set_redundant_flag(struct switchtec_dev *dev, int keyman, int riot, int bl2, int cfg, int fw, int set)
Set the redundant image flag for the specified image types.
Definition fw.c:281
int switchtec_fw_toggle_active_partition(struct switchtec_dev *dev, int toggle_bl2, int toggle_key, int toggle_fw, int toggle_cfg, int toggle_riotcore)
Toggle the active firmware partition for the main or configuration images.
Definition fw.c:310
const char * switchtec_fw_image_type(const struct switchtec_fw_image_info *info)
Return a string describing the type of a firmware image.
Definition fw.c:961
int switchtec_fw_write_file(struct switchtec_dev *dev, FILE *fimg, int dont_activate, int force, void(*progress_callback)(int cur, int tot))
Write a firmware file to the switchtec device.
Definition fw.c:492
struct switchtec_fw_part_summary * switchtec_fw_part_summary(struct switchtec_dev *dev)
Return firmware summary information structure for the flash partitfons in the device.
Definition fw.c:1634
gasptr_t switchtec_gas_map(struct switchtec_dev *dev, int writeable, size_t *map_size)
Map the GAS and return a pointer to access the gas.
Definition platform.c:269
void switchtec_gas_unmap(struct switchtec_dev *dev, gasptr_t map)
Unmap the GAS region mapped with.
Definition platform.c:281
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.
Definition switchtec.c:2197
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.
Definition switchtec.c:2134
int switchtec_get_gpio(struct switchtec_dev *dev, int pin_id, int *gpio_val)
Get the GPIO pin value.
Definition switchtec.c:2300
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.
Definition switchtec.c:1513
int switchtec_set_gpio(struct switchtec_dev *dev, int pin_id, int gpio_val)
Set the GPIO pin value.
Definition switchtec.c:2326
int switchtec_port_to_pff(struct switchtec_dev *dev, int partition, int port, int *pff)
Convert a partition and port number to a port function index.
Definition platform.c:242
int switchtec_get_gpio_polarity_cfg(struct switchtec_dev *dev, int pin_id, int *polarity)
Get the GPIO pin polarity.
Definition switchtec.c:2371
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.
Definition switchtec.c:1596
float switchtec_die_temp(struct switchtec_dev *dev)
Get the die temperature of the switchtec device.
Definition switchtec.c:1854
int switchtec_die_temps(struct switchtec_dev *dev, int nr_sensor, float *sensor_readings)
Get the die temperature sensor readings of the switchtec device.
Definition switchtec.c:1898
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.
Definition switchtec.c:2222
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.
Definition switchtec.c:2181
int switchtec_hard_reset(struct switchtec_dev *dev)
Perform an MRPC hard reset command.
Definition switchtec.c:790
int switchtec_pff_to_port(struct switchtec_dev *dev, int pff, int *partition, int *port)
Convert a port function index to a partition and port number.
Definition platform.c:227
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.
Definition switchtec.c:1721
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.
Definition switchtec.c:1799
int switchtec_en_dis_interrupt(struct switchtec_dev *dev, int pin_id, int en)
Enable/Disable the GPIO pin interrupt.
Definition switchtec.c:2397
int switchtec_echo(struct switchtec_dev *dev, uint32_t input, uint32_t *output)
Perform an MRPC echo command.
Definition switchtec.c:774
int switchtec_get_all_pin_sts(struct switchtec_dev *dev, uint32_t *values)
Get all GPIO pin status.
Definition switchtec.c:2416
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.
Definition switchtec.c:2266
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.
Definition switchtec.c:2030
int switchtec_get_gpio_direction_cfg(struct switchtec_dev *dev, int pin_id, int *direction)
Get the GPIO pin direction.
Definition switchtec.c:2345
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.
Definition switchtec.c:2070
const char * switchtec_evcntr_type_str(int *type_mask)
Get a string for the event indicated by lowest bit set in the type_mask.
Definition pmon.c:116
int switchtec_evcntr_type_count(void)
Get the number of event counter types.
Definition pmon.c:95
int switchtec_lat_get(struct switchtec_dev *dev, int clear, int egress_port_ids, int *cur_ns, int *max_ns)
Get a single latency counter result.
Definition pmon.c:633
void switchtec_bwcntr_sub(struct switchtec_bwcntr_res *new_cntr, struct switchtec_bwcntr_res *old_cntr)
Subtract all the values between two bwcntr result structures.
Definition pmon.c:339
int switchtec_evcntr_setup(struct switchtec_dev *dev, unsigned stack_id, unsigned cntr_id, struct switchtec_evcntr_setup *setup)
Setup an event counter performance monitor.
Definition pmon.c:139
int switchtec_bwcntr_set_all(struct switchtec_dev *dev, enum switchtec_bw_type bw_type)
Set bandwidth type for all the ports in the system.
Definition pmon.c:387
int switchtec_evcntr_wait(struct switchtec_dev *dev, int timeout_ms)
Block until any event counter has reached its threshold.
Definition pmon.c:325
int switchtec_evcntr_get_both(struct switchtec_dev *dev, unsigned stack_id, unsigned cntr_id, unsigned nr_cntrs, struct switchtec_evcntr_setup *setup, unsigned *counts, int clear)
Retrieve the current counts and setup information for one or more event counters.
Definition pmon.c:301
int switchtec_lat_setup(struct switchtec_dev *dev, int egress_port_id, int ingress_port_id, int clear)
Setup a latency counter.
Definition pmon.c:557
int switchtec_bwcntr_many(struct switchtec_dev *dev, int nr_ports, int *phys_port_ids, int clear, struct switchtec_bwcntr_res *res)
Retrieve the bandwidth counter results for a number of ports.
Definition pmon.c:419
int switchtec_bwcntr_all(struct switchtec_dev *dev, int clear, struct switchtec_port_id **ports, struct switchtec_bwcntr_res **res)
Retrieve the bandwidth counter results for all the ports in the system.
Definition pmon.c:473
uint64_t switchtec_bwcntr_tot(struct switchtec_bwcntr_dir *d)
Get the total.
Definition pmon.c:513
int switchtec_lat_get_many(struct switchtec_dev *dev, int nr_ports, int clear, int *egress_port_ids, int *cur_ns, int *max_ns)
Get a number of latency counter results.
Definition pmon.c:585
int switchtec_lat_setup_many(struct switchtec_dev *dev, int nr_ports, int *egress_port_ids, int *ingress_port_ids)
Setup a number of latency counters.
Definition pmon.c:527
int switchtec_evcntr_get(struct switchtec_dev *dev, unsigned stack_id, unsigned cntr_id, unsigned nr_cntrs, unsigned *res, int clear)
Retrieve the current counts for one or more event counters.
Definition pmon.c:257
int switchtec_bwcntr_set_many(struct switchtec_dev *dev, int nr_ports, int *phys_port_ids, enum switchtec_bw_type bw_type)
Set bandwidth type for a number of ports.
Definition pmon.c:359
int switchtec_evcntr_get_setup(struct switchtec_dev *dev, unsigned stack_id, unsigned cntr_id, unsigned nr_cntrs, struct switchtec_evcntr_setup *res)
Retrieve the setup information for one or more event counters.
Definition pmon.c:214
Definition utils.h:34
uint64_t comp
Completion TLP bytes.
Definition switchtec.h:1170
uint64_t nonposted
Non-Posted TLP bytes.
Definition switchtec.h:1171
Bandwidth counter result struct.
Definition switchtec.h:1166
struct switchtec_bwcntr_res::switchtec_bwcntr_dir ingress
Bandwidth into the port.
uint64_t time_us
Time (in microseconds).
Definition switchtec.h:1167
struct switchtec_bwcntr_res::switchtec_bwcntr_dir egress
Bandwidth out of the port.
Represents a Switchtec device in the switchtec_list() function.
Definition switchtec.h:147
char fw_version[32]
Firmware version.
Definition switchtec.h:153
char pci_dev[256]
PCI BDF string.
Definition switchtec.h:150
char desc[256]
Device description, if available.
Definition switchtec.h:149
char path[PATH_MAX]
Path to the device.
Definition switchtec.h:154
char name[256]
Device name, eg. switchtec0.
Definition switchtec.h:148
char product_id[32]
Product ID.
Definition switchtec.h:151
char product_rev[8]
Product revision.
Definition switchtec.h:152
Structure used to setup an event counter.
Definition switchtec.h:1130
unsigned threshold
Threshold to count to before generating an interrupt.
Definition switchtec.h:1141
enum switchtec_evcntr_type_mask type_mask
Event counter types to count.
Definition switchtec.h:1134
Null-terminated list of all event counter types with a name and help text.
Definition switchtec.h:1121
Event summary bitmaps.
Definition switchtec.h:308
uint64_t part_bitmap
Bitmap of partitions with active events.
Definition switchtec.h:310
uint64_t global
Bitmap of global events.
Definition switchtec.h:309
unsigned part[SWITCHTEC_MAX_PARTS]
Bitmap of events in each partition.
Definition switchtec.h:314
unsigned local_part
Bitmap of events in the local partition.
Definition switchtec.h:311
unsigned pff[SWITCHTEC_MAX_PFF_CSR]
Bitmap of events in each port function.
Definition switchtec.h:317
Information about a firmware image or partition.
Definition switchtec.h:270
enum switchtec_gen gen
Image generation.
Definition switchtec.h:271
size_t part_body_offset
Partition image body offset.
Definition switchtec.h:277
unsigned long image_crc
CRC checksum of the image.
Definition switchtec.h:279
char version[32]
Firmware/Config version.
Definition switchtec.h:274
size_t image_len
Length of the image.
Definition switchtec.h:278
unsigned long part_id
Image partition ID.
Definition switchtec.h:272
size_t part_addr
Address of the partition.
Definition switchtec.h:275
size_t part_len
Length of the partition.
Definition switchtec.h:276
enum switchtec_fw_type type
Image partition type.
Definition switchtec.h:273
Information about log file and log definition file.
Definition switchtec.h:235
Port identification.
Definition switchtec.h:160
unsigned char upstream
1 if this is an upstream port
Definition switchtec.h:164
unsigned char partition
Partition the port is in.
Definition switchtec.h:161
unsigned char stk_id
Port number within the stack.
Definition switchtec.h:165
unsigned char log_id
Logical port number.
Definition switchtec.h:167
unsigned char phys_id
Physical port number.
Definition switchtec.h:166
unsigned char stack
Stack number.
Definition switchtec.h:163
Port status structure.
Definition switchtec.h:176
struct switchtec_port_id port
Port ID.
Definition switchtec.h:177
unsigned char link_up
1 if the link is up
Definition switchtec.h:180
unsigned char lane_reversal
Lane reversal.
Definition switchtec.h:184
unsigned int acs_ctrl
ACS Setting of the Port.
Definition switchtec.h:196
const char * lane_reversal_str
Lane reversal as a string.
Definition switchtec.h:185
unsigned char cfg_lnk_width
Configured link width.
Definition switchtec.h:178
unsigned char link_rate
Link rate/gen.
Definition switchtec.h:181
unsigned char first_act_lane
First active lane.
Definition switchtec.h:186
int vendor_id
Vendor ID.
Definition switchtec.h:193
unsigned char neg_lnk_width
Negotiated link width.
Definition switchtec.h:179
uint16_t ltssm
Link state.
Definition switchtec.h:182
char * pci_bdf_path
PCI BDF path of the port.
Definition switchtec.h:190
char * pci_bdf
PCI BDF of the port.
Definition switchtec.h:189
int device_id
Device ID.
Definition switchtec.h:194
char * class_devices
Comma seperated list of classes.
Definition switchtec.h:195
char * pci_dev
PCI BDF of the device on the port.
Definition switchtec.h:192
const char * ltssm_str
Link state as a string.
Definition switchtec.h:183
switchtec_bw_type
The types of bandwidth.
Definition switchtec.h:202
int switchtec_diag_rcvr_ext(struct switchtec_dev *dev, int port_id, int lane_id, enum switchtec_diag_link link, struct switchtec_rcvr_ext *res)
Get the Extended Receiver Object.
Definition diag.c:1324
lane_eq_dump_type_enum
Definition switchtec.h:1303
@ LANE_EQ_DUMP_TYPE_NUM
Total number of dump types.
Definition switchtec.h:1306
@ LANE_EQ_DUMP_TYPE_PREV
Previous link-up settings.
Definition switchtec.h:1305
@ LANE_EQ_DUMP_TYPE_CURR
Current settings.
Definition switchtec.h:1304
static int switchtec_is_pfxl(struct switchtec_dev *dev)
Return whether a Switchtec device is PFX-L.
Definition switchtec.h:502
switchtec_log_parse_type
Log types to parse.
Definition switchtec.h:226
int switchtec_diag_cross_hair_disable(struct switchtec_dev *dev)
Disable active cross hair.
Definition diag.c:70
switchtec_event_id
Enumeration of all possible events.
Definition switchtec.h:323
int switchtec_diag_pattern_mon_get(struct switchtec_dev *dev, int port_id, int lane_id, enum switchtec_diag_pattern *type, unsigned long long *err_cnt)
Get Pattern Monitor.
Definition diag.c:709
int switchtec_diag_pattern_gen_get(struct switchtec_dev *dev, int port_id, enum switchtec_diag_pattern *type)
Get Pattern Generator set on port.
Definition diag.c:659
int switchtec_diag_port_eq_tx_table(struct switchtec_dev *dev, int port_id, int prev_speed, enum switchtec_diag_link link, struct switchtec_port_eq_table *res)
Get the far end TX equalization table.
Definition diag.c:1144
int switchtec_diag_port_eq_tx_fslf(struct switchtec_dev *dev, int port_id, int prev_speed, int lane_id, enum switchtec_diag_end end, enum switchtec_diag_link link, struct switchtec_port_eq_tx_fslf *res)
Get the equalization FS/LF.
Definition diag.c:1294
static int switchtec_is_psxa(struct switchtec_dev *dev)
Return whether a Switchtec device is PSX-A.
Definition switchtec.h:545
int switchtec_diag_loopback_get(struct switchtec_dev *dev, int port_id, int *enabled, enum switchtec_diag_ltssm_speed *ltssm_speed)
Setup Loopback Mode.
Definition diag.c:568
int switchtec_inject_err_dllp_crc(struct switchtec_dev *dev, int phys_port_id, int enable, uint16_t rate)
Inject a DLLP CRC error into a physical port.
Definition diag.c:1837
int switchtec_diag_eye_read(struct switchtec_dev *dev, int lane_id, int bin, int *num_phases, double *ber_data)
Start a PCIe Eye Read Gen5.
Definition diag.c:242
switchtec_fw_ro
Flag which indicates if a partition is read-only or not.
Definition switchtec.h:981
switchtec_rev
Device hardware revision.
Definition switchtec.h:101
int switchtec_diag_eye_fetch(struct switchtec_dev *dev, double *pixels, size_t pixel_cnt, int *lane_id)
Start a PCIe Eye Capture.
Definition diag.c:352
static int switchtec_is_psx_pfx_all(struct switchtec_dev *dev)
Return whether a Switchtec device is PFX or PSX.
Definition switchtec.h:562
switchtec_evcntr_type_mask
Event counter type mask (may be or-d together).
Definition switchtec.h:1071
@ ALL_TLPS
Mask indicating all TLP types.
Definition switchtec.h:1109
@ RCVR_ERR
Receiver Error.
Definition switchtec.h:1086
@ RCVR_OFLOW_ERR
Receiver Overflow Error.
Definition switchtec.h:1075
@ REPLAY_NUM_ROLLOVER
Replay Number Rollover.
Definition switchtec.h:1083
@ COMP_TLP
Completion TLP.
Definition switchtec.h:1093
@ BAD_TLP
Bad TLP.
Definition switchtec.h:1085
@ NON_POSTED_TLP
Non-Posted TLP.
Definition switchtec.h:1094
@ BAD_DLLP
Bad DLLP.
Definition switchtec.h:1084
@ SURPRISE_DOWN_ERR
Surprise Down Error.
Definition switchtec.h:1078
@ POISONED_TLP_ERR
Poisoned TLP Error.
Definition switchtec.h:1077
@ ALL_ERRORS
Mask indicating all possible errors.
Definition switchtec.h:1099
@ RCV_CORR_MSG
Receive Correctable Error Message.
Definition switchtec.h:1089
@ RCV_NON_FATAL_MSG
Receive Non-FATAL Error Message.
Definition switchtec.h:1088
@ NAK_RCVD
NAK Received.
Definition switchtec.h:1090
@ UNSUP_REQ_ERR
Unsupported Request Error.
Definition switchtec.h:1072
@ POSTED_TLP
Posted TLP.
Definition switchtec.h:1092
@ RULE_TABLE_HIT
Rule Search Table Rule Hit.
Definition switchtec.h:1091
@ ALL
Mask indicating all event types.
Definition switchtec.h:1114
@ ECRC_ERR
ECRC Error.
Definition switchtec.h:1073
@ REPLAY_TMR_TIMEOUT
Replay Timer Timeout.
Definition switchtec.h:1082
@ HDR_LOG_OFLOW_ERR
Header Log Overflow Error.
Definition switchtec.h:1080
@ DATA_LINK_PROTO_ERR
Data Link Protocol Error.
Definition switchtec.h:1079
@ UNCOR_INT_ERR
Uncorrectable Internal Error.
Definition switchtec.h:1081
@ CMPLTR_ABORT_ERR
Completer Abort Error.
Definition switchtec.h:1076
@ RCV_FATAL_MSG
Receive FATAL Error Message.
Definition switchtec.h:1087
@ MALFORM_TLP_ERR
Malformed TLP Error.
Definition switchtec.h:1074
int switchtec_diag_pattern_inject(struct switchtec_dev *dev, int port_id, unsigned int err_cnt)
Inject error into pattern generator.
Definition diag.c:748
static const char * switchtec_rev_str(enum switchtec_rev rev)
Return the revision string.
Definition switchtec.h:608
static const char * switchtec_gen_str(struct switchtec_dev *dev)
Return the generation string of a Switchtec device.
Definition switchtec.h:594
static int switchtec_is_pfxa(struct switchtec_dev *dev)
Return whether a Switchtec device is PFX-A.
Definition switchtec.h:518
static int switchtec_is_pfx_all(struct switchtec_dev *dev)
Return whether a Switchtec device is PFX(L/I/A).
Definition switchtec.h:526
static int switchtec_is_pfxi(struct switchtec_dev *dev)
Return whether a Switchtec device is PFX-I.
Definition switchtec.h:510
switchtec_gen
The PCIe generations.
Definition switchtec.h:91
int switchtec_diag_rcvr_obj(struct switchtec_dev *dev, int port_id, int lane_id, enum switchtec_diag_link link, struct switchtec_rcvr_obj *res)
Get the receiver object.
Definition diag.c:775
link_rate_enum
Definition switchtec.h:1309
@ PCIE_LINK_RATE_GEN3
Gen3, supports 2.5GT/s, 5GT/s, 8GT/s.
Definition switchtec.h:1313
@ PCIE_LINK_RATE_GEN1
Gen1, supports 2.5GT/s.
Definition switchtec.h:1311
@ PCIE_LINK_RATE_GEN4
Gen4, supports 2.5GT/s, 5GT/s, 8GT/s, 16GT/s.
Definition switchtec.h:1314
@ PCIE_LINK_RATE_NUM
Total number of PCIe generations.
Definition switchtec.h:1316
@ PCIE_LINK_RATE_GEN5
Gen5, supports 2.5GT/s, 5GT/s, 8GT/s, 16GT/s, 32GT/s.
Definition switchtec.h:1315
@ PCIE_LINK_RATE_GEN2
Gen2, supports 2.5GT/s, 5GT/s.
Definition switchtec.h:1312
@ PCIE_LINK_RATE_INV
Invalid.
Definition switchtec.h:1310
static int switchtec_is_psx(struct switchtec_dev *dev)
Return whether a Switchtec device is PSX.
Definition switchtec.h:537
int switchtec_diag_refclk_ctl(struct switchtec_dev *dev, int stack_id, bool en)
Control the refclk output for a stack.
Definition diag.c:1406
int switchtec_diag_perm_table(struct switchtec_dev *dev, struct switchtec_mrpc table[MRPC_MAX_ID])
Get the permission table.
Definition diag.c:1369
int switchtec_diag_ltssm_log(struct switchtec_dev *dev, int port, int *log_count, struct switchtec_diag_ltssm_log *log_data)
Determine the generation and call the related LTSSM log func.
Definition diag.c:1724
int switchtec_inject_err_ack_nack(struct switchtec_dev *dev, int phys_port_id, uint16_t seq_num, uint8_t count)
Inject an ACK to NACK error into a physical port.
Definition diag.c:1938
switchtec_log_def_type
Log definition data types.
Definition switchtec.h:249
__gas struct switchtec_gas * gasptr_t
Shortform for a pointer to the GAS register space.
Definition switchtec.h:85
switchtec_variant
The variant types of Switchtec device.
Definition switchtec.h:132
int switchtec_aer_event_gen(struct switchtec_dev *dev, int port_id, int aer_error_id, int trigger_event)
Call the aer event gen function to generate AER events.
Definition diag.c:1786
static const char * switchtec_phase_id_str(enum switchtec_boot_phase phase_id)
Return the phase string for a phase id.
Definition switchtec.h:655
int switchtec_diag_loopback_set(struct switchtec_dev *dev, int port_id, int enable, int enable_parallel, int enable_external, int enable_ltssm, enum switchtec_diag_ltssm_speed ltssm_speed)
Setup Loopback Mode.
Definition diag.c:534
int switchtec_diag_cross_hair_enable(struct switchtec_dev *dev, int lane_id)
Enable cross hair on specified lane.
Definition diag.c:53
switchtec_event_type
There are three event types indicated by this enumeration: global, partition and port function.
Definition switchtec.h:921
switchtec_log_type
Describe the type of logs too dump.
Definition switchtec.h:211
switchtec_event_special
Special event indexes numbers.
Definition switchtec.h:912
switchtec_boot_phase
Device boot phase.
Definition switchtec.h:111
static const float switchtec_gen_transfers[]
Number of GT/s capable for each PCI generation or link_rate.
Definition switchtec.h:671
int switchtec_diag_eye_cancel(struct switchtec_dev *dev)
Cancel in-progress eye capture.
Definition diag.c:412
int switchtec_diag_refclk_status(struct switchtec_dev *dev, uint8_t *stack_info)
Get the status of all stacks of the refclk.
Definition diag.c:1422
static int switchtec_is_gen4(struct switchtec_dev *dev)
Return whether a Switchtec device is a Gen 4 device.
Definition switchtec.h:469
static int switchtec_is_paxa(struct switchtec_dev *dev)
Return whether a Switchtec device is PAX-A.
Definition switchtec.h:578
static int switchtec_max_supported_ports(struct switchtec_dev *dev)
Return the max number of ports of a Switchtec device.
Definition switchtec.h:485
int switchtec_diag_pattern_gen_set(struct switchtec_dev *dev, int port_id, enum switchtec_diag_pattern type, enum switchtec_diag_pattern_link_rate link_speed)
Setup Pattern Generator.
Definition diag.c:635
int switchtec_diag_port_eq_tx_coeff(struct switchtec_dev *dev, int port_id, int prev_speed, enum switchtec_diag_end end, enum switchtec_diag_link link, struct switchtec_port_eq_coeff *res)
Get the port equalization TX coefficients.
Definition diag.c:1002
int switchtec_inject_err_dllp(struct switchtec_dev *dev, int phys_port_id, int data)
Return Link error injection command outputs for DLLP, DLLP_CRC, LCRC, SEQ_NUM, ACK_NACK,...
Definition diag.c:1814
int switchtec_diag_eye_set_mode(struct switchtec_dev *dev, enum switchtec_diag_eye_data_mode mode)
Set the data mode for the next Eye Capture.
Definition diag.c:221
int switchtec_diag_cross_hair_get(struct switchtec_dev *dev, int start_lane_id, int num_lanes, struct switchtec_diag_cross_hair *res)
Disable active cross hair.
Definition diag.c:88
int switchtec_inject_err_cto(struct switchtec_dev *dev, int phys_port_id)
Inject Credit Timeout error into a physical port.
Definition diag.c:1960
static int switchtec_is_pax(struct switchtec_dev *dev)
Return whether a Switchtec device is PAX.
Definition switchtec.h:570
static int switchtec_is_psx_all(struct switchtec_dev *dev)
Return whether a Switchtec device is PSX(A).
Definition switchtec.h:553
int switchtec_inject_err_tlp_seq_num(struct switchtec_dev *dev, int phys_port_id)
Inject a TLP Sequence Number error into a physical port.
Definition diag.c:1917
int switchtec_diag_ltssm_clear(struct switchtec_dev *dev, int port)
Call the LTSSM clear MRPC command.
Definition diag.c:1741
static int switchtec_is_gen5(struct switchtec_dev *dev)
Return whether a Switchtec device is a Gen 5 device.
Definition switchtec.h:477
static int switchtec_is_pfx(struct switchtec_dev *dev)
Return whether a Switchtec device is PFX.
Definition switchtec.h:494
switchtec_event_flags
Event control flags.
Definition switchtec.h:893
int switchtec_inject_err_tlp_lcrc(struct switchtec_dev *dev, int phys_port_id, int enable, uint8_t rate)
Inject a TLP LCRC error into a physical port.
Definition diag.c:1896
switchtec_fw_dlstatus
Firmware update status.
Definition switchtec.h:950
int switchtec_diag_pattern_mon_set(struct switchtec_dev *dev, int port_id, enum switchtec_diag_pattern type)
Setup Pattern Monitor.
Definition diag.c:688
static const char * switchtec_fw_image_gen_str(struct switchtec_fw_image_info *inf)
Return the generation string of a Switchtec fw image.
Definition switchtec.h:623
static const float switchtec_gen_datarate[]
Number of GB/s capable for each PCI generation or link_rate.
Definition switchtec.h:673
static int switchtec_is_pax_all(struct switchtec_dev *dev)
Return whether a Switchtec device is PAX(A).
Definition switchtec.h:586
static const char * switchtec_variant_str(struct switchtec_dev *dev)
Return the variant string of a Switchtec device.
Definition switchtec.h:636
int switchtec_diag_eye_start(struct switchtec_dev *dev, int lane_mask[4], struct range *x_range, struct range *y_range, int step_interval, int capture_depth)
Start a PCIe Eye Capture.
Definition diag.c:282
switchtec_parition_types
Device parition types GEN5.
Definition switchtec.h:121
static int switchtec_is_gen3(struct switchtec_dev *dev)
Return whether a Switchtec device is a Gen 3 device.
Definition switchtec.h:461