Switchtec Userspace  PROJECT_NUMBER = PROJECT_NUMBER=PROJECT_NUMBER = 2.2
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 
33 #include "mrpc.h"
34 #include "bind.h"
35 #include "portable.h"
36 #include "registers.h"
37 
38 #include <stdbool.h>
39 #include <stdlib.h>
40 #include <stdint.h>
41 #include <stdio.h>
42 
43 #ifdef __cplusplus
44 extern "C" {
45 #endif
46 
47 struct switchtec_dev;
48 
49 #define SWITCHTEC_MAX_PARTS 48
50 #define SWITCHTEC_MAX_PORTS 48
51 #define SWITCHTEC_MAX_STACKS 8
52 #define SWITCHTEC_MAX_EVENT_COUNTERS 64
53 #define SWITCHTEC_UNBOUND_PORT 255
54 #define SWITCHTEC_PFF_PORT_VEP 100
55 
56 #define SWITCHTEC_FLASH_BOOT_PART_START 0xa8000000
57 #define SWITCHTEC_FLASH_MAP0_PART_START 0xa8020000
58 #define SWITCHTEC_FLASH_MAP1_PART_START 0xa8040000
59 #define SWITCHTEC_FLASH_PART_LEN 0x10000
60 
61 #define SWITCHTEC_CMD_MASK 0xffff
62 #define SWITCHTEC_PAX_ID_SHIFT 18
63 #define SWITCHTEC_PAX_ID_MASK 0x1f
64 #define SWITCHTEC_PAX_ID_LOCAL SWITCHTEC_PAX_ID_MASK
65 
66 #ifdef __CHECKER__
67 #define __gas __attribute__((noderef, address_space(1)))
68 #else
69 #define __gas
70 #endif
71 
72 #define _PURE __attribute__ ((pure))
73 
77 typedef __gas struct switchtec_gas *gasptr_t;
78 #define SWITCHTEC_MAP_FAILED ((gasptr_t) -1)
79 
84  SWITCHTEC_GEN3,
85  SWITCHTEC_GEN4,
86  SWITCHTEC_GEN_UNKNOWN,
87 };
88 
93  SWITCHTEC_REVA = 0x0f,
94  SWITCHTEC_REVB = 0x00,
95  SWITCHTEC_REVC = 0x01,
96  SWITCHTEC_REV_UNKNOWN = 0xff
97 };
98 
103  SWITCHTEC_BOOT_PHASE_BL1 = 1,
104  SWITCHTEC_BOOT_PHASE_BL2,
105  SWITCHTEC_BOOT_PHASE_FW,
106  SWITCHTEC_BOOT_PHASE_UNKNOWN
107 };
108 
113  SWITCHTEC_PFX,
114  SWITCHTEC_PFXL,
115  SWITCHTEC_PFXI,
116  SWITCHTEC_PSX,
117  SWITCHTEC_PAX,
118  SWITCHTEC_VAR_UNKNOWN,
119 };
120 
125  char name[256];
126  char desc[256];
127  char pci_dev[256];
128  char product_id[32];
129  char product_rev[8];
130  char fw_version[32];
131  char path[PATH_MAX];
132 };
133 
138  unsigned char partition;
139 
140  unsigned char stack;
141  unsigned char upstream;
142  unsigned char stk_id;
143  unsigned char phys_id;
144  unsigned char log_id;
145 };
146 
154  struct switchtec_port_id port;
155  unsigned char cfg_lnk_width;
156  unsigned char neg_lnk_width;
157  unsigned char link_up;
158  unsigned char link_rate;
159  uint16_t ltssm;
160  const char *ltssm_str;
161  unsigned char lane_reversal;
162  const char *lane_reversal_str;
163  unsigned char first_act_lane;
164 
165  char *pci_bdf;
166  char *pci_bdf_path;
167 
168  char *pci_dev;
169  int vendor_id;
170  int device_id;
172  unsigned int acs_ctrl;
173 };
174 
179  SWITCHTEC_BW_TYPE_RAW = 0x0,
180  SWITCHTEC_BW_TYPE_PAYLOAD = 0x1,
181 };
182 
188  SWITCHTEC_LOG_RAM,
189  SWITCHTEC_LOG_FLASH,
190  SWITCHTEC_LOG_MEMLOG,
191  SWITCHTEC_LOG_REGS,
192  SWITCHTEC_LOG_SYS_STACK,
193  SWITCHTEC_LOG_THRD_STACK,
194  SWITCHTEC_LOG_THRD,
195  SWITCHTEC_LOG_NVHDR,
196 };
197 
198 enum switchtec_fw_type {
199  SWITCHTEC_FW_TYPE_UNKNOWN = 0,
200  SWITCHTEC_FW_TYPE_BOOT,
201  SWITCHTEC_FW_TYPE_MAP,
202  SWITCHTEC_FW_TYPE_IMG,
203  SWITCHTEC_FW_TYPE_CFG,
204  SWITCHTEC_FW_TYPE_NVLOG,
205  SWITCHTEC_FW_TYPE_SEEPROM,
206  SWITCHTEC_FW_TYPE_KEY,
207  SWITCHTEC_FW_TYPE_BL2,
208 };
209 
214  enum switchtec_gen gen;
215  unsigned long part_id;
216  enum switchtec_fw_type type;
217  char version[32];
218  size_t part_addr;
219  size_t part_len;
221  size_t image_len;
222  unsigned long image_crc;
223 
224  bool valid;
225  bool active;
226  bool running;
227  bool read_only;
228  bool redundant;
229 
230  struct switchtec_fw_image_info *next;
231  void *metadata;
232 
233  unsigned long secure_version;
234 };
235 
238  struct switchtec_fw_image_info *active, *inactive;
239  } boot, map, img, cfg, nvlog, seeprom, key, bl2;
240 
241  struct switchtec_fw_image_info *mult_cfg;
242 
243  int nr_info;
244  struct switchtec_fw_image_info all[];
245 };
246 
251  uint64_t global;
252  uint64_t part_bitmap;
253  unsigned local_part;
254 
256  unsigned part[SWITCHTEC_MAX_PARTS];
257 
259  unsigned pff[SWITCHTEC_MAX_PFF_CSR];
260 };
261 
266  SWITCHTEC_EVT_INVALID = -1,
267  SWITCHTEC_GLOBAL_EVT_STACK_ERROR,
268  SWITCHTEC_GLOBAL_EVT_PPU_ERROR,
269  SWITCHTEC_GLOBAL_EVT_ISP_ERROR,
270  SWITCHTEC_GLOBAL_EVT_SYS_RESET,
271  SWITCHTEC_GLOBAL_EVT_FW_EXC,
272  SWITCHTEC_GLOBAL_EVT_FW_NMI,
273  SWITCHTEC_GLOBAL_EVT_FW_NON_FATAL,
274  SWITCHTEC_GLOBAL_EVT_FW_FATAL,
275  SWITCHTEC_GLOBAL_EVT_TWI_MRPC_COMP,
276  SWITCHTEC_GLOBAL_EVT_TWI_MRPC_COMP_ASYNC,
277  SWITCHTEC_GLOBAL_EVT_CLI_MRPC_COMP,
278  SWITCHTEC_GLOBAL_EVT_CLI_MRPC_COMP_ASYNC,
279  SWITCHTEC_GLOBAL_EVT_GPIO_INT,
280  SWITCHTEC_GLOBAL_EVT_GFMS,
281  SWITCHTEC_PART_EVT_PART_RESET,
282  SWITCHTEC_PART_EVT_MRPC_COMP,
283  SWITCHTEC_PART_EVT_MRPC_COMP_ASYNC,
284  SWITCHTEC_PART_EVT_DYN_PART_BIND_COMP,
285  SWITCHTEC_PFF_EVT_AER_IN_P2P,
286  SWITCHTEC_PFF_EVT_AER_IN_VEP,
287  SWITCHTEC_PFF_EVT_DPC,
288  SWITCHTEC_PFF_EVT_CTS,
289  SWITCHTEC_PFF_EVT_UEC,
290  SWITCHTEC_PFF_EVT_HOTPLUG,
291  SWITCHTEC_PFF_EVT_IER,
292  SWITCHTEC_PFF_EVT_THRESH,
293  SWITCHTEC_PFF_EVT_POWER_MGMT,
294  SWITCHTEC_PFF_EVT_TLP_THROTTLING,
295  SWITCHTEC_PFF_EVT_FORCE_SPEED,
296  SWITCHTEC_PFF_EVT_CREDIT_TIMEOUT,
297  SWITCHTEC_PFF_EVT_LINK_STATE,
298  SWITCHTEC_MAX_EVENTS,
299 };
300 
301 /*********** Platform Functions ***********/
302 
303 struct switchtec_dev *switchtec_open(const char *device);
304 struct switchtec_dev *switchtec_open_by_path(const char *path);
305 struct switchtec_dev *switchtec_open_by_index(int index);
306 struct switchtec_dev *switchtec_open_by_pci_addr(int domain, int bus,
307  int device, int func);
308 struct switchtec_dev *switchtec_open_i2c(const char *path, int i2c_addr);
309 struct switchtec_dev *switchtec_open_i2c_by_adapter(int adapter, int i2c_addr);
310 struct switchtec_dev *switchtec_open_uart(int fd);
311 
312 void switchtec_close(struct switchtec_dev *dev);
313 int switchtec_list(struct switchtec_device_info **devlist);
314 int switchtec_get_fw_version(struct switchtec_dev *dev, char *buf,
315  size_t buflen);
316 int switchtec_cmd(struct switchtec_dev *dev, uint32_t cmd,
317  const void *payload, size_t payload_len, void *resp,
318  size_t resp_len);
319 int switchtec_get_devices(struct switchtec_dev *dev,
320  struct switchtec_status *status,
321  int ports);
322 int switchtec_pff_to_port(struct switchtec_dev *dev, int pff,
323  int *partition, int *port);
324 int switchtec_port_to_pff(struct switchtec_dev *dev, int partition,
325  int port, int *pff);
326 int switchtec_event_summary(struct switchtec_dev *dev,
327  struct switchtec_event_summary *sum);
328 int switchtec_event_check(struct switchtec_dev *dev,
329  struct switchtec_event_summary *check,
330  struct switchtec_event_summary *res);
331 int switchtec_event_ctl(struct switchtec_dev *dev,
332  enum switchtec_event_id e,
333  int index, int flags,
334  uint32_t data[5]);
335 int switchtec_event_wait(struct switchtec_dev *dev, int timeout_ms);
336 
337 /*********** Generic Accessors ***********/
338 
339 _PURE const char *switchtec_name(struct switchtec_dev *dev);
340 _PURE int switchtec_partition(struct switchtec_dev *dev);
341 _PURE int switchtec_device_id(struct switchtec_dev *dev);
342 _PURE enum switchtec_gen switchtec_gen(struct switchtec_dev *dev);
343 _PURE enum switchtec_variant switchtec_variant(struct switchtec_dev *dev);
344 _PURE enum switchtec_boot_phase
345 switchtec_boot_phase(struct switchtec_dev *dev);
346 int switchtec_set_pax_id(struct switchtec_dev *dev, int pax_id);
347 int switchtec_echo(struct switchtec_dev *dev, uint32_t input, uint32_t *output);
348 int switchtec_hard_reset(struct switchtec_dev *dev);
349 int switchtec_status(struct switchtec_dev *dev,
350  struct switchtec_status **status);
351 void switchtec_status_free(struct switchtec_status *status, int ports);
352 int switchtec_get_device_info(struct switchtec_dev *dev,
353  enum switchtec_boot_phase *phase,
354  enum switchtec_gen *gen,
355  enum switchtec_rev *rev);
356 const char *switchtec_strerror(void);
357 void switchtec_perror(const char *str);
358 int switchtec_log_to_file(struct switchtec_dev *dev,
359  enum switchtec_log_type type,
360  int fd);
361 float switchtec_die_temp(struct switchtec_dev *dev);
362 
366 static inline int switchtec_is_gen3(struct switchtec_dev *dev)
367 {
368  return switchtec_gen(dev) == SWITCHTEC_GEN3;
369 }
370 
374 static inline int switchtec_is_gen4(struct switchtec_dev *dev)
375 {
376  return switchtec_gen(dev) == SWITCHTEC_GEN4;
377 }
378 
382 static inline int switchtec_is_pfx(struct switchtec_dev *dev)
383 {
384  return switchtec_variant(dev) == SWITCHTEC_PFX;
385 }
386 
390 static inline int switchtec_is_pfxl(struct switchtec_dev *dev)
391 {
392  return switchtec_variant(dev) == SWITCHTEC_PFXL;
393 }
394 
398 static inline int switchtec_is_pfxi(struct switchtec_dev *dev)
399 {
400  return switchtec_variant(dev) == SWITCHTEC_PFXI;
401 }
402 
406 static inline int switchtec_is_pfx_all(struct switchtec_dev *dev)
407 {
408  return switchtec_is_pfx(dev) ||
409  switchtec_is_pfxl(dev) ||
410  switchtec_is_pfxi(dev);
411 }
412 
416 static inline int switchtec_is_psx(struct switchtec_dev *dev)
417 {
418  return switchtec_variant(dev) == SWITCHTEC_PSX;
419 }
420 
424 static inline int switchtec_is_psx_pfx_all(struct switchtec_dev *dev)
425 {
426  return switchtec_is_psx(dev) || switchtec_is_pfx_all(dev);
427 }
428 
432 static inline int switchtec_is_pax(struct switchtec_dev *dev)
433 {
434  return switchtec_variant(dev) == SWITCHTEC_PAX;
435 }
436 
440 static inline const char *switchtec_gen_str(struct switchtec_dev *dev)
441 {
442  const char *str;
443 
444  str = switchtec_is_gen3(dev) ? "GEN3" :
445  switchtec_is_gen4(dev) ? "GEN4" : "Unknown";
446 
447  return str;
448 }
449 
453 static inline const char *
455 {
456  switch (inf->gen) {
457  case SWITCHTEC_GEN3: return "GEN3";
458  case SWITCHTEC_GEN4: return "GEN4";
459  default: return "UNKNOWN";
460  }
461 }
462 
466 static inline const char *switchtec_variant_str(struct switchtec_dev *dev)
467 {
468  const char *str;
469 
470  str = switchtec_is_pfx(dev) ? "PFX" :
471  switchtec_is_pfxl(dev) ? "PFX-L" :
472  switchtec_is_pfxi(dev) ? "PFX-I" :
473  switchtec_is_psx(dev) ? "PSX" :
474  switchtec_is_pax(dev) ? "PAX" : "Unknown";
475 
476  return str;
477 }
478 
480 static const float switchtec_gen_transfers[] = {0, 2.5, 5, 8, 16};
482 static const float switchtec_gen_datarate[] = {0, 250, 500, 985, 1969};
483 
484 static inline const char *switchtec_ltssm_str(int ltssm, int show_minor)
485 {
486  if (!show_minor)
487  ltssm |= 0xFF00;
488 
489  switch(ltssm) {
490  case 0x0000: return "Detect (INACTIVE)";
491  case 0x0100: return "Detect (QUIET)";
492  case 0x0200: return "Detect (SPD_CHD0)";
493  case 0x0300: return "Detect (SPD_CHD1)";
494  case 0x0400: return "Detect (ACTIVE0)";
495  case 0x0500: return "Detect (ACTIVE1)";
496  case 0x0600: return "Detect (P1_TO_P0)";
497  case 0x0700: return "Detect (P0_TO_P1_0)";
498  case 0x0800: return "Detect (P0_TO_P1_1)";
499  case 0x0900: return "Detect (P0_TO_P1_2)";
500  case 0xFF00: return "Detect";
501  case 0x0001: return "Polling (INACTIVE)";
502  case 0x0101: return "Polling (ACTIVE_ENTRY)";
503  case 0x0201: return "Polling (ACTIVE)";
504  case 0x0301: return "Polling (CFG)";
505  case 0x0401: return "Polling (COMP)";
506  case 0x0501: return "Polling (COMP_ENTRY)";
507  case 0x0601: return "Polling (COMP_EIOS)";
508  case 0x0701: return "Polling (COMP_EIOS_ACK)";
509  case 0x0801: return "Polling (COMP_IDLE)";
510  case 0xFF01: return "Polling";
511  case 0x0002: return "Config (INACTIVE)";
512  case 0x0102: return "Config (US_LW_START)";
513  case 0x0202: return "Config (US_LW_ACCEPT)";
514  case 0x0302: return "Config (US_LN_WAIT)";
515  case 0x0402: return "Config (US_LN_ACCEPT)";
516  case 0x0502: return "Config (DS_LW_START)";
517  case 0x0602: return "Config (DS_LW_ACCEPT)";
518  case 0x0702: return "Config (DS_LN_WAIT)";
519  case 0x0802: return "Config (DS_LN_ACCEPT)";
520  case 0x0902: return "Config (COMPLETE)";
521  case 0x0A02: return "Config (IDLE)";
522  case 0xFF02: return "Config";
523  case 0x0003: return "L0 (INACTIVE)";
524  case 0x0103: return "L0 (L0)";
525  case 0x0203: return "L0 (TX_EL_IDLE)";
526  case 0x0303: return "L0 (TX_IDLE_MIN)";
527  case 0xFF03: return "L0";
528  case 0x0004: return "Recovery (INACTIVE)";
529  case 0x0104: return "Recovery (RCVR_LOCK)";
530  case 0x0204: return "Recovery (RCVR_CFG)";
531  case 0x0304: return "Recovery (IDLE)";
532  case 0x0404: return "Recovery (SPEED0)";
533  case 0x0504: return "Recovery (SPEED1)";
534  case 0x0604: return "Recovery (SPEED2)";
535  case 0x0704: return "Recovery (SPEED3)";
536  case 0x0804: return "Recovery (EQ_PH0)";
537  case 0x0904: return "Recovery (EQ_PH1)";
538  case 0x0A04: return "Recovery (EQ_PH2)";
539  case 0x0B04: return "Recovery (EQ_PH3)";
540  case 0xFF04: return "Recovery";
541  case 0x0005: return "Disable (INACTIVE)";
542  case 0x0105: return "Disable (DISABLE0)";
543  case 0x0205: return "Disable (DISABLE1)";
544  case 0x0305: return "Disable (DISABLE2)";
545  case 0x0405: return "Disable (DISABLE3)";
546  case 0xFF05: return "Disable";
547  case 0x0006: return "Loop Back (INACTIVE)";
548  case 0x0106: return "Loop Back (ENTRY)";
549  case 0x0206: return "Loop Back (ENTRY_EXIT)";
550  case 0x0306: return "Loop Back (EIOS)";
551  case 0x0406: return "Loop Back (EIOS_ACK)";
552  case 0x0506: return "Loop Back (IDLE)";
553  case 0x0606: return "Loop Back (ACTIVE)";
554  case 0x0706: return "Loop Back (EXIT0)";
555  case 0x0806: return "Loop Back (EXIT1)";
556  case 0xFF06: return "Loop Back";
557  case 0x0007: return "Hot Reset (INACTIVE)";
558  case 0x0107: return "Hot Reset (HOT_RESET)";
559  case 0x0207: return "Hot Reset (MASTER_UP)";
560  case 0x0307: return "Hot Reset (MASTER_DOWN)";
561  case 0xFF07: return "Hot Reset";
562  case 0x0008: return "TxL0s (INACTIVE)";
563  case 0x0108: return "TxL0s (IDLE)";
564  case 0x0208: return "TxL0s (T0_L0)";
565  case 0x0308: return "TxL0s (FTS0)";
566  case 0x0408: return "TxL0s (FTS1)";
567  case 0xFF08: return "TxL0s";
568  case 0x0009: return "L1 (INACTIVE)";
569  case 0x0109: return "L1 (IDLE)";
570  case 0x0209: return "L1 (SUBSTATE)";
571  case 0x0309: return "L1 (SPD_CHG1)";
572  case 0x0409: return "L1 (T0_L0)";
573  case 0xFF09: return "L1";
574  case 0x000A: return "L2 (INACTIVE)";
575  case 0x010A: return "L2 (IDLE)";
576  case 0x020A: return "L2 (TX_WAKE0)";
577  case 0x030A: return "L2 (TX_WAKE1)";
578  case 0x040A: return "L2 (EXIT)";
579  case 0x050A: return "L2 (SPEED)";
580  case 0xFF0A: return "L2";
581  default: return "UNKNOWN";
582  }
583 
584 }
585 
586 /*********** EVENT Handling ***********/
587 
593  SWITCHTEC_EVT_FLAG_CLEAR = 1 << 0,
594  SWITCHTEC_EVT_FLAG_EN_POLL = 1 << 1,
595  SWITCHTEC_EVT_FLAG_EN_LOG = 1 << 2,
596  SWITCHTEC_EVT_FLAG_EN_CLI = 1 << 3,
597  SWITCHTEC_EVT_FLAG_EN_FATAL = 1 << 4,
598  SWITCHTEC_EVT_FLAG_DIS_POLL = 1 << 5,
599  SWITCHTEC_EVT_FLAG_DIS_LOG = 1 << 6,
600  SWITCHTEC_EVT_FLAG_DIS_CLI = 1 << 7,
601  SWITCHTEC_EVT_FLAG_DIS_FATAL = 1 << 8,
602 };
603 
612  SWITCHTEC_EVT_IDX_LOCAL = -1,
613  SWITCHTEC_EVT_IDX_ALL = -2,
614 };
615 
621  SWITCHTEC_EVT_GLOBAL,
622  SWITCHTEC_EVT_PART,
623  SWITCHTEC_EVT_PFF,
624 };
625 
626 int switchtec_event_summary_set(struct switchtec_event_summary *sum,
627  enum switchtec_event_id e,
628  int index);
629 int switchtec_event_summary_test(struct switchtec_event_summary *sum,
630  enum switchtec_event_id e,
631  int index);
632 int switchtec_event_summary_iter(struct switchtec_event_summary *sum,
633  enum switchtec_event_id *e,
634  int *idx);
636  const char **name,
637  const char **desc);
638 int switchtec_event_wait_for(struct switchtec_dev *dev,
639  enum switchtec_event_id e, int index,
640  struct switchtec_event_summary *res,
641  int timeout_ms);
642 
643 /******** FIRMWARE Management ********/
644 
650  SWITCHTEC_DLSTAT_READY = 0,
651  SWITCHTEC_DLSTAT_INPROGRESS = 1,
652  SWITCHTEC_DLSTAT_HEADER_INCORRECT = 2,
653  SWITCHTEC_DLSTAT_OFFSET_INCORRECT = 3,
654  SWITCHTEC_DLSTAT_CRC_INCORRECT = 4,
655  SWITCHTEC_DLSTAT_LENGTH_INCORRECT = 5,
656  SWITCHTEC_DLSTAT_HARDWARE_ERR = 6,
657  SWITCHTEC_DLSTAT_COMPLETES = 7,
658  SWITCHTEC_DLSTAT_SUCCESS_FIRM_ACT = 8,
659  SWITCHTEC_DLSTAT_SUCCESS_DATA_ACT = 9,
660  SWITCHTEC_DLSTAT_DOWNLOAD_TIMEOUT = 14,
661 
662  SWITCHTEC_DLSTAT_NO_FILE = 0x7d009,
663 };
664 
669  SWITCHTEC_FW_RW = 0,
670  SWITCHTEC_FW_RO = 1,
671 };
672 
673 enum switchtec_fw_redundancy {
674  SWITCHTEC_FW_REDUNDANCY_SET = 1,
675  SWITCHTEC_FW_REDUNDANCY_CLEAR = 0,
676 };
677 
678 int switchtec_fw_toggle_active_partition(struct switchtec_dev *dev,
679  int toggle_bl2, int toggle_key,
680  int toggle_fw, int toggle_cfg);
681 int switchtec_fw_setup_redundancy(struct switchtec_dev *dev,
682  enum switchtec_fw_redundancy redund,
683  enum switchtec_fw_type type);
684 int switchtec_fw_write_fd(struct switchtec_dev *dev, int img_fd,
685  int dont_activate, int force,
686  void (*progress_callback)(int cur, int tot));
687 int switchtec_fw_write_file(struct switchtec_dev *dev, FILE *fimg,
688  int dont_activate, int force,
689  void (*progress_callback)(int cur, int tot));
690 int switchtec_fw_read_fd(struct switchtec_dev *dev, int fd,
691  unsigned long addr, size_t len,
692  void (*progress_callback)(int cur, int tot));
693 int switchtec_fw_body_read_fd(struct switchtec_dev *dev, int fd,
694  struct switchtec_fw_image_info *info,
695  void (*progress_callback)(int cur, int tot));
696 int switchtec_fw_read(struct switchtec_dev *dev, unsigned long addr,
697  size_t len, void *buf);
698 void switchtec_fw_perror(const char *s, int ret);
699 int switchtec_fw_file_info(int fd, struct switchtec_fw_image_info *info);
700 int switchtec_fw_file_secure_version_newer(struct switchtec_dev *dev,
701  int img_fd);
702 const char *switchtec_fw_image_type(const struct switchtec_fw_image_info *info);
704 switchtec_fw_part_summary(struct switchtec_dev *dev);
705 void switchtec_fw_part_summary_free(struct switchtec_fw_part_summary *summary);
706 int switchtec_fw_img_write_hdr(int fd, struct switchtec_fw_image_info *info);
707 int switchtec_fw_is_boot_ro(struct switchtec_dev *dev);
708 int switchtec_fw_set_boot_ro(struct switchtec_dev *dev,
709  enum switchtec_fw_ro ro);
710 int switchtec_bind_info(struct switchtec_dev *dev,
711  struct switchtec_bind_status_out *bind_status,
712  int phy_port);
713 int switchtec_bind(struct switchtec_dev *dev, int par_id,
714  int log_port, int phy_port);
715 int switchtec_unbind(struct switchtec_dev *dev, int par_id, int log_port);
716 /********** EVENT COUNTER *********/
717 
722  UNSUP_REQ_ERR = 1 << 0,
723  ECRC_ERR = 1 << 1,
724  MALFORM_TLP_ERR = 1 << 2,
725  RCVR_OFLOW_ERR = 1 << 3,
726  CMPLTR_ABORT_ERR = 1 << 4,
727  POISONED_TLP_ERR = 1 << 5,
728  SURPRISE_DOWN_ERR = 1 << 6,
730  HDR_LOG_OFLOW_ERR = 1 << 8,
731  UNCOR_INT_ERR = 1 << 9,
732  REPLAY_TMR_TIMEOUT = 1 << 10,
734  BAD_DLLP = 1 << 12,
735  BAD_TLP = 1 << 13,
736  RCVR_ERR = 1 << 14,
737  RCV_FATAL_MSG = 1 << 15,
738  RCV_NON_FATAL_MSG = 1 << 16,
739  RCV_CORR_MSG = 1 << 17,
740  NAK_RCVD = 1 << 18,
741  RULE_TABLE_HIT = 1 << 19,
742  POSTED_TLP = 1 << 20,
743  COMP_TLP = 1 << 21,
744  NON_POSTED_TLP = 1 << 22,
745 
760 
764  ALL = (1 << 23) - 1,
765 };
766 
771 extern const struct switchtec_evcntr_type_list {
772  enum switchtec_evcntr_type_mask mask;
773  const char *name;
774  const char *help;
776 
781  unsigned port_mask; //<! Mask of ports this counter counts
782 
785  int egress; //<! If 1, count egress, otherwise on ingress
786 
791  unsigned threshold;
792 };
793 
795 const char *switchtec_evcntr_type_str(int *type_mask);
796 int switchtec_evcntr_setup(struct switchtec_dev *dev, unsigned stack_id,
797  unsigned cntr_id,
798  struct switchtec_evcntr_setup *setup);
799 int switchtec_evcntr_get_setup(struct switchtec_dev *dev, unsigned stack_id,
800  unsigned cntr_id, unsigned nr_cntrs,
801  struct switchtec_evcntr_setup *res);
802 int switchtec_evcntr_get(struct switchtec_dev *dev, unsigned stack_id,
803  unsigned cntr_id, unsigned nr_cntrs, unsigned *res,
804  int clear);
805 int switchtec_evcntr_get_both(struct switchtec_dev *dev, unsigned stack_id,
806  unsigned cntr_id, unsigned nr_cntrs,
807  struct switchtec_evcntr_setup *setup,
808  unsigned *counts, int clear);
809 int switchtec_evcntr_wait(struct switchtec_dev *dev, int timeout_ms);
810 
811 /********** BANDWIDTH COUNTER *********/
812 
817  uint64_t time_us;
819  uint64_t posted;
820  uint64_t comp;
821  uint64_t nonposted;
822  } egress,
823  ingress;
824 };
825 
826 void switchtec_bwcntr_sub(struct switchtec_bwcntr_res *new_cntr,
827  struct switchtec_bwcntr_res *old_cntr);
828 int switchtec_bwcntr_set_many(struct switchtec_dev *dev, int nr_ports,
829  int * phys_port_ids,
830  enum switchtec_bw_type bw_type);
831 int switchtec_bwcntr_set_all(struct switchtec_dev *dev,
832  enum switchtec_bw_type bw_type);
833 int switchtec_bwcntr_many(struct switchtec_dev *dev, int nr_ports,
834  int *phys_port_ids, int clear,
835  struct switchtec_bwcntr_res *res);
836 int switchtec_bwcntr_all(struct switchtec_dev *dev, int clear,
837  struct switchtec_port_id **ports,
838  struct switchtec_bwcntr_res **res);
839 uint64_t switchtec_bwcntr_tot(struct switchtec_bwcntr_dir *d);
840 
841 /********** LATENCY COUNTER *********/
842 
843 #define SWITCHTEC_LAT_ALL_INGRESS 63
844 
845 int switchtec_lat_setup_many(struct switchtec_dev *dev, int nr_ports,
846  int *egress_port_ids, int *ingress_port_ids);
847 int switchtec_lat_setup(struct switchtec_dev *dev, int egress_port_id,
848  int ingress_port_id, int clear);
849 int switchtec_lat_get_many(struct switchtec_dev *dev, int nr_ports,
850  int clear, int *egress_port_ids,
851  int *cur_ns, int *max_ns);
852 int switchtec_lat_get(struct switchtec_dev *dev, int clear,
853  int egress_port_ids, int *cur_ns,
854  int *max_ns);
855 
856 /********** GLOBAL ADDRESS SPACE ACCESS *********/
857 
858 /*
859  * GAS map maps the hardware registers into user memory space.
860  * Needless to say, this can be very dangerous and should only
861  * be done if you know what you are doing. Any register accesses
862  * that use this will remain unsupported by Microsemi unless it's
863  * done within the switchtec user project or otherwise specified.
864  */
865 
866 gasptr_t switchtec_gas_map(struct switchtec_dev *dev, int writeable,
867  size_t *map_size);
868 void switchtec_gas_unmap(struct switchtec_dev *dev, gasptr_t map);
869 
870 #ifdef __cplusplus
871 }
872 #endif
873 
874 #endif
unsigned char cfg_lnk_width
Configured link width.
Definition: switchtec.h:155
unsigned char neg_lnk_width
Negotiated link width.
Definition: switchtec.h:156
Completion TLP.
Definition: switchtec.h:743
char product_rev[8]
Product revision.
Definition: switchtec.h:129
char * pci_dev
PCI BDF of the device on the port.
Definition: switchtec.h:168
unsigned int acs_ctrl
ACS Setting of the Port.
Definition: switchtec.h:172
ECRC Error.
Definition: switchtec.h:723
static int switchtec_is_pfxl(struct switchtec_dev *dev)
Return whether a Switchtec device is PFX-L.
Definition: switchtec.h:390
switchtec_evcntr_type_mask
Event counter type mask (may be or-d together)
Definition: switchtec.h:721
Bad TLP.
Definition: switchtec.h:735
void switchtec_status_free(struct switchtec_status *status, int ports)
Free a list of status structures allocated by switchtec_status()
Definition: switchtec.c:470
Unsupported Request Error.
Definition: switchtec.h:722
unsigned char upstream
1 if this is an upstream port
Definition: switchtec.h:141
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:397
unsigned char link_rate
Link rate/gen.
Definition: switchtec.h:158
Replay Timer Timeout.
Definition: switchtec.h:732
Rule Search Table Rule Hit.
Definition: switchtec.h:741
_PURE int switchtec_device_id(struct switchtec_dev *dev)
Get the device id of the device.
Definition: switchtec.c:267
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
size_t part_addr
Address of the partition.
Definition: switchtec.h:218
uint64_t switchtec_bwcntr_tot(struct switchtec_bwcntr_dir *d)
Get the total.
Definition: pmon.c:513
uint64_t comp
Completion TLP bytes.
Definition: switchtec.h:820
Uncorrectable Internal Error.
Definition: switchtec.h:731
uint64_t time_us
Time (in microseconds)
Definition: switchtec.h:817
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:181
Port identification.
Definition: switchtec.h:137
static const float switchtec_gen_transfers[]
Number of GT/s capable for each PCI generation or link_rate.
Definition: switchtec.h:480
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_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:196
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_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
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
Receive Correctable Error Message.
Definition: switchtec.h:739
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
static const char * switchtec_gen_str(struct switchtec_dev *dev)
Return the generation string of a Switchtec device.
Definition: switchtec.h:440
unsigned char partition
Partition the port is in.
Definition: switchtec.h:138
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:389
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
unsigned long image_crc
CRC checksum of the image.
Definition: switchtec.h:222
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
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:223
switchtec_gen
The PCIe generations.
Definition: switchtec.h:83
unsigned char stk_id
Port number within the stack.
Definition: switchtec.h:142
switchtec_event_id
Enumeration of all possible events.
Definition: switchtec.h:265
Bad DLLP.
Definition: switchtec.h:734
unsigned char first_act_lane
First active lane.
Definition: switchtec.h:163
Information about a firmware image or partition.
Definition: switchtec.h:213
switchtec_boot_phase
Device boot phase.
Definition: switchtec.h:102
int switchtec_fw_toggle_active_partition(struct switchtec_dev *dev, int toggle_bl2, int toggle_key, int toggle_fw, int toggle_cfg)
Toggle the active firmware partition for the main or configuration images.
Definition: fw.c:187
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
Mask indicating all possible errors.
Definition: switchtec.h:749
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
char * pci_bdf_path
PCI BDF path of the port.
Definition: switchtec.h:166
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
Malformed TLP Error.
Definition: switchtec.h:724
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:1452
Completer Abort Error.
Definition: switchtec.h:726
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
unsigned long part_id
Image partition ID.
Definition: switchtec.h:215
void switchtec_gas_unmap(struct switchtec_dev *dev, gasptr_t map)
Unmap the GAS region mapped with.
Definition: platform.c:235
Posted TLP.
Definition: switchtec.h:742
Structure used to setup an event counter.
Definition: switchtec.h:780
switchtec_bw_type
The types of bandwidth.
Definition: switchtec.h:178
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
Non-Posted TLP.
Definition: switchtec.h:744
__gas struct switchtec_gas * gasptr_t
Shortform for a pointer to the GAS register space.
Definition: switchtec.h:77
char product_id[32]
Product ID.
Definition: switchtec.h:128
int switchtec_list(struct switchtec_device_info **devlist)
List all the switchtec devices in the system.
unsigned char phys_id
Physical port number.
Definition: switchtec.h:143
Replay Number Rollover.
Definition: switchtec.h:733
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:162
Event summary bitmaps.
Definition: switchtec.h:250
int switchtec_evcntr_wait(struct switchtec_dev *dev, int timeout_ms)
Block until any event counter has reached its threshold.
Definition: pmon.c:325
static int switchtec_is_pax(struct switchtec_dev *dev)
Return whether a Switchtec device is PAX.
Definition: switchtec.h:432
size_t image_len
Length of the image.
Definition: switchtec.h:221
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:299
uint64_t part_bitmap
Bitmap of partitions with active events.
Definition: switchtec.h:252
int switchtec_evcntr_type_count(void)
Get the number of event counter types.
Definition: pmon.c:95
switchtec_log_type
Describe the type of logs too dump.
Definition: switchtec.h:187
static int switchtec_is_pfx(struct switchtec_dev *dev)
Return whether a Switchtec device is PFX.
Definition: switchtec.h:382
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&#39;s flash data into a file.
Definition: fw.c:1344
float switchtec_die_temp(struct switchtec_dev *dev)
Get the die temperature of the switchtec device.
Definition: switchtec.c:846
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
void switchtec_fw_perror(const char *s, int ret)
Print an error string to stdout.
Definition: fw.c:493
char path[PATH_MAX]
Path to the device.
Definition: switchtec.h:131
unsigned threshold
Threshold to count to before generating an interrupt.
Definition: switchtec.h:791
char desc[256]
Device description, if available.
Definition: switchtec.h:126
uint64_t nonposted
Non-Posted TLP bytes.
Definition: switchtec.h:821
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:454
static int switchtec_is_gen4(struct switchtec_dev *dev)
Return whether a Switchtec device is a Gen 4 device.
Definition: switchtec.h:374
_PURE int switchtec_partition(struct switchtec_dev *dev)
Get the partiton number of the device that was opened.
Definition: switchtec.c:325
NAK Received.
Definition: switchtec.h:740
unsigned char stack
Stack number.
Definition: switchtec.h:140
int switchtec_event_wait(struct switchtec_dev *dev, int timeout_ms)
Wait for any event to occur (typically just an interrupt)
Definition: platform.c:297
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&#39;s flash image body into a file.
Definition: fw.c:1393
const char * lane_reversal_str
Lane reversal as a string.
Definition: switchtec.h:162
int device_id
Device ID.
Definition: switchtec.h:170
const char * switchtec_strerror(void)
Return a message coresponding to the last error.
Definition: switchtec.c:509
int switchtec_echo(struct switchtec_dev *dev, uint32_t input, uint32_t *output)
Perform an MRPC echo command.
Definition: switchtec.c:623
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:716
enum switchtec_gen gen
Image generation.
Definition: switchtec.h:214
switchtec_fw_ro
Flag which indicates if a partition is read-only or not.
Definition: switchtec.h:668
static int switchtec_is_pfxi(struct switchtec_dev *dev)
Return whether a Switchtec device is PFX-I.
Definition: switchtec.h:398
Port status structure.
Definition: switchtec.h:153
void switchtec_fw_part_summary_free(struct switchtec_fw_part_summary *summary)
Free a firmware part summary data structure.
Definition: fw.c:1282
Mask indicating all event types.
Definition: switchtec.h:764
unsigned char lane_reversal
Lane reversal.
Definition: switchtec.h:161
size_t part_body_offset
Partition image body offset.
Definition: switchtec.h:220
int switchtec_fw_is_boot_ro(struct switchtec_dev *dev)
Check if the boot partition is marked as read-only.
Definition: fw.c:1476
int switchtec_fw_read(struct switchtec_dev *dev, unsigned long addr, size_t len, void *buf)
Read a Switchtec device&#39;s flash data.
Definition: fw.c:1300
char * class_devices
Comma seperated list of classes.
Definition: switchtec.h:171
switchtec_variant
The variant types of Switchtec device.
Definition: switchtec.h:112
const char * ltssm_str
Link state as a string.
Definition: switchtec.h:160
uint64_t global
Bitmap of global events.
Definition: switchtec.h:251
int switchtec_fw_file_info(int fd, struct switchtec_fw_image_info *info)
Retrieve information about a firmware image file.
Definition: fw.c:683
Header Log Overflow Error.
Definition: switchtec.h:730
Mask indicating all TLP types.
Definition: switchtec.h:759
Surprise Down Error.
Definition: switchtec.h:728
int switchtec_fw_setup_redundancy(struct switchtec_dev *dev, enum switchtec_fw_redundancy redund, enum switchtec_fw_type type)
Set or clear the redundancy flag of a partition type.
Definition: fw.c:249
switchtec_fw_dlstatus
Firmware update status.
Definition: switchtec.h:649
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:765
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:115
char pci_dev[256]
PCI BDF string.
Definition: switchtec.h:127
static int switchtec_is_psx_pfx_all(struct switchtec_dev *dev)
Return whether a Switchtec device is PFX or PSX.
Definition: switchtec.h:424
struct switchtec_dev * switchtec_open_uart(int fd)
Open a switchtec device behind a uart device.
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
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:1203
static int switchtec_is_pfx_all(struct switchtec_dev *dev)
Return whether a Switchtec device is PFX(L/I).
Definition: switchtec.h:406
struct switchtec_dev * switchtec_open_by_path(const char *path)
Open a switchtec device by path.
char fw_version[32]
Firmware version.
Definition: switchtec.h:130
size_t part_len
Length of the partition.
Definition: switchtec.h:219
switchtec_event_special
Special event indexes numbers.
Definition: switchtec.h:611
static int switchtec_is_gen3(struct switchtec_dev *dev)
Return whether a Switchtec device is a Gen 3 device.
Definition: switchtec.h:366
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
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:796
int vendor_id
Vendor ID.
Definition: switchtec.h:169
char name[256]
Device name, eg. switchtec0.
Definition: switchtec.h:125
switchtec_event_flags
Event control flags.
Definition: switchtec.h:592
switchtec_event_type
There are three event types indicated by this enumeration: global, partition and port function...
Definition: switchtec.h:620
void switchtec_perror(const char *str)
Print an error string to stdout.
Definition: switchtec.c:592
int switchtec_fw_set_boot_ro(struct switchtec_dev *dev, enum switchtec_fw_ro ro)
Set or clear a boot partition&#39;s read-only flag.
Definition: fw.c:1515
Poisoned TLP Error.
Definition: switchtec.h:727
Receive FATAL Error Message.
Definition: switchtec.h:737
switchtec_rev
Device hardware revision.
Definition: switchtec.h:92
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
struct switchtec_dev * switchtec_open(const char *device)
Open a Switchtec device by string.
Definition: switchtec.c:188
Null-terminated list of all event counter types with a name and help text.
Definition: switchtec.h:771
char * pci_bdf
PCI BDF of the port.
Definition: switchtec.h:165
_PURE const char * switchtec_name(struct switchtec_dev *dev)
Get the string that was used to open the deviec.
Definition: switchtec.c:315
int switchtec_log_to_file(struct switchtec_dev *dev, enum switchtec_log_type type, int fd)
Dump the Switchtec log data to a file.
Definition: switchtec.c:745
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_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_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:132
Receiver Error.
Definition: switchtec.h:736
Receiver Overflow Error.
Definition: switchtec.h:725
unsigned char log_id
Logical port number.
Definition: switchtec.h:144
Represents a Switchtec device in the switchtec_list() function.
Definition: switchtec.h:124
struct switchtec_dev * switchtec_open_i2c(const char *path, int i2c_addr)
Open a switchtec device behind an I2C device.
Data Link Protocol Error.
Definition: switchtec.h:729
struct switchtec_dev * switchtec_open_by_index(int index)
Open a switchtec device by index.
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:281
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:265
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_lat_setup(struct switchtec_dev *dev, int egress_port_id, int ingress_port_id, int clear)
Setup a latency counter.
Definition: pmon.c:557
Bandwidth counter result struct.
Definition: switchtec.h:816
unsigned local_part
Bitmap of events in the local partition.
Definition: switchtec.h:253
uint64_t posted
Posted TLP bytes.
Definition: switchtec.h:819
static const char * switchtec_variant_str(struct switchtec_dev *dev)
Return the variant string of a Switchtec device.
Definition: switchtec.h:466
unsigned char link_up
1 if the link is up
Definition: switchtec.h:157
int switchtec_hard_reset(struct switchtec_dev *dev)
Perform an MRPC hard reset command.
Definition: switchtec.c:639
Receive Non-FATAL Error Message.
Definition: switchtec.h:738
static int switchtec_is_psx(struct switchtec_dev *dev)
Return whether a Switchtec device is PSX.
Definition: switchtec.h:416
void switchtec_close(struct switchtec_dev *dev)
Close a Switchtec device handle.
Definition: platform.c:91
static const float switchtec_gen_datarate[]
Number of GB/s capable for each PCI generation or link_rate.
Definition: switchtec.h:482
uint16_t ltssm
Link state.
Definition: switchtec.h:159