### Get Event Counter Setup Source: https://microsemi.github.io/switchtec-user/pmon_8c_source.html Retrieves the setup configuration for event counters on a specified port. Use this to understand how event counters are configured before reading their values. ```c int switchtec_evcntr_get_setup(struct switchtec_dev *dev, unsigned stack_id, unsigned cntr_id, unsigned nr_cntrs, struct switchtec_evcntr_setup *res) { int ret; int i; struct pmon_event_counter_get_setup_result data[nr_cntrs]; if (res == NULL) { errno = EINVAL; return -errno; } ret = evcntr_get(dev, MRPC_PMON_GET_EV_COUNTER_SETUP, stack_id, cntr_id, nr_cntrs, data, sizeof(*data) * nr_cntrs, 0); if (ret) return ret; for (i = 0; i < nr_cntrs; i++) { res[i].port_mask = le32toh(data[i].mask) & 0xFF; res[i].type_mask = le32toh(data[i].mask) >> 8; res[i].egress = data[i].ieg; res[i].threshold = le32toh(data[i].thresh); } return nr_cntrs; } ``` -------------------------------- ### Get Both Event Counter Setup and Values Source: https://microsemi.github.io/switchtec-user/pmon_8c_source.html Combines retrieving event counter setup and their current values in a single call. Use this for efficiency when both pieces of information are needed. ```c 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) { int ret = 0; ret = switchtec_evcntr_get_setup(dev, stack_id, cntr_id, nr_cntrs, setup); if (ret < 0) return ret; return switchtec_evcntr_get(dev, stack_id, cntr_id, nr_cntrs, counts, clear); } ``` -------------------------------- ### switchtec_evcntr_get_setup Source: https://microsemi.github.io/switchtec-user/group__PMON.html Retrieves `nr_cntrs` counter values and setup structures sequentially starting at `cntr_id`. This is equivalent to calling switchtec_evcntr_get() and switchtec_evcntr_get_setup(). ```APIDOC ## switchtec_evcntr_get_setup ### Description Retrieves `nr_cntrs` setup structures sequentially starting at `cntr_id`. ### Method Not applicable (function call) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **dev** (struct switchtec_dev *) - Input - Switchtec device handle - **stack_id** (unsigned) - Input - Stack to setup this counter in - **cntr_id** (unsigned) - Input - First counter ID to retrieve - **nr_cntrs** (unsigned) - Input - Number of counters to retrieve - **res** (struct switchtec_evcntr_setup *) - Output - List of event counter setup structures (at least `nr_cntrs` elements) ### Returns 0 on success, error code on failure ``` -------------------------------- ### switchtec_evcntr_get_setup Source: https://microsemi.github.io/switchtec-user/globals_func.html Retrieves the setup information for event counters. ```APIDOC ## switchtec_evcntr_get_setup ### Description Retrieves the setup information for event counters. ### Method Not applicable (C function) ### Endpoint Not applicable (C function) ### Parameters - **id** (int) - Required - The ID of the event counter. - **setup** (struct switchtec_evcntr_setup *) - Required - Pointer to a structure to store the setup information. ### Request Example ```c struct switchtec_evcntr_setup setup_info; switchtec_evcntr_get_setup(5, &setup_info); ``` ### Response #### Success Response - **setup** (struct switchtec_evcntr_setup *) - Structure filled with the event counter setup information. ``` -------------------------------- ### PMON Event Counter Get Setup Result Structure Source: https://microsemi.github.io/switchtec-user/pmon_8h_source.html Structure to hold the result of getting PMON event counter setup. Contains mask, IEG, and threshold values. ```c struct pmon_event_counter_get_setup_result { uint32_t mask; uint8_t ieg; uint32_t thresh; }; ``` -------------------------------- ### switchtec_lat_setup Source: https://microsemi.github.io/switchtec-user/group__PMON.html Setup a latency counter. ```APIDOC ## switchtec_lat_setup ### Description Setup a latency counter. ### Method Not applicable (function call) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **dev** (struct switchtec_dev *) - Input - Switchtec device handle - **egress_port_id** (int) - Input - The port id for the egress of the TLP - **ingress_port_id** (int) - Input - The port id for the ingress of the TLP (may be SWITCHTEC_LAT_ALL_INGRESS for all ports) - **clear** (int) - Input - If non-zero, clear the latency counter ### Returns 1 on success, error code on failure ``` -------------------------------- ### switchtec_lat_setup_many Source: https://microsemi.github.io/switchtec-user/group__PMON.html Setup a number of latency counters. ```APIDOC ## switchtec_lat_setup_many ### Description Setup a number of latency counters. ### Method Not applicable (function call) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **dev** (struct switchtec_dev *) - Input - Switchtec device handle - **nr_ports** (int) - Input - Number of latency counters to setup - **egress_port_ids** (int *) - Input - A list of egress port ids for the counters to setup - **ingress_port_ids** (int *) - Input - A list of ingress port ids for the counters to setup ### Returns Not specified in source, assumed to be similar to `switchtec_lat_setup` (e.g., 1 on success, error code on failure) ``` -------------------------------- ### Setup Performance Monitoring Event Counter Source: https://microsemi.github.io/switchtec-user/pmon_8c_source.html Configures a performance monitoring event counter on a specified stack and counter ID. It takes a setup structure containing the event type mask, port mask, egress setting, and threshold. Input validation is performed to ensure the counter ID is within the valid range. ```c int switchtec_evcntr_setup(struct switchtec_dev *dev, unsigned stack_id, unsigned cntr_id, struct switchtec_evcntr_setup *setup) { struct pmon_event_counter_setup cmd = { .sub_cmd_id = MRPC_PMON_SETUP_EV_COUNTER, .stack_id = stack_id, .counter_id = cntr_id, .num_counters = 1, .counters = { [0] = { .mask = htole32((setup->type_mask << 8) | (setup->port_mask & 0xFF)), .ieg = setup->egress, .thresh = htole32(setup->threshold), }, }, }; if (cntr_id >= SWITCHTEC_MAX_EVENT_COUNTERS) { errno = EINVAL; return -errno; } return switchtec_cmd(dev, MRPC_PMON, &cmd, sizeof(cmd), NULL, 0); } ``` -------------------------------- ### switchtec_evcntr_get_both Source: https://microsemi.github.io/switchtec-user/group__PMON.html Retrieves both the setup information and current count values for one or more event counters. ```APIDOC ## switchtec_evcntr_get_both ### Description Retrieve the current counts and setup information for one or more event counters. ### Function Signature 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) ### Parameters * **dev** (struct switchtec_dev *) - Pointer to the Switchtec device structure. * **stack_id** (unsigned) - The ID of the stack. * **cntr_id** (unsigned) - The starting ID of the counters. * **nr_cntrs** (unsigned) - The number of counters. * **setup** (struct switchtec_evcntr_setup *) - Pointer to a structure to store the setup information. * **counts** (unsigned *) - Pointer to an array to store the current counts. * **clear** (int) - If non-zero, clears the counters after retrieving their values. ### Returns An integer status code. 0 on success, negative on error. ``` -------------------------------- ### Get Switchtec Device Interface Path on Windows Source: https://microsemi.github.io/switchtec-user/windows_8c_source.html Retrieves the device interface path for a Switchtec device. It uses SetupAPI functions and chops off the GUID part of the path. Requires device information structures. ```c static BOOL get_path(HDEVINFO devinfo, SP_DEVICE_INTERFACE_DATA *deviface, SP_DEVINFO_DATA *devdata, char *path, size_t path_size) { DWORD size; SP_DEVICE_INTERFACE_DETAIL_DATA *devdetail; BOOL status = TRUE; char *hash; devdata->cbSize = sizeof(SP_DEVINFO_DATA); SetupDiGetDeviceInterfaceDetail(devinfo, deviface, NULL, 0, &size, NULL); devdetail = malloc(size); if (!devdetail) { perror("Enumeration"); return FALSE; } devdetail->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA); status = SetupDiGetDeviceInterfaceDetail(devinfo, deviface, devdetail, size, NULL, devdata); if (!status) { platform_perror("SetupDiGetDeviceInterfaceDetail"); goto out; } strcpy_s(path, path_size, devdetail->DevicePath); /* Chop off the GUID */ hash = strrchr(path, '#'); if (hash) *hash = 0; out: free(devdetail); return status; } ``` -------------------------------- ### Get Firmware Version Source: https://microsemi.github.io/switchtec-user/gasops_8c_source.html Reads the firmware version and converts it to a string. Ensure the buffer is large enough. ```c int gasop_get_fw_version(struct switchtec_dev *dev, char *buf, size_t buflen) { long long ver; ver = gas_reg_read32(dev, sys_info.firmware_version); version_to_string(ver, buf, buflen); return 0; } ``` -------------------------------- ### PMON Latency Setup Structure Source: https://microsemi.github.io/switchtec-user/pmon_8h_source.html Structure for configuring latency monitoring. Specifies egress and ingress ports for latency measurements. ```c struct pmon_lat_setup { uint8_t sub_cmd_id; uint8_t count; struct { uint8_t egress; uint8_t ingress; } ports[SWITCHTEC_MAX_PORTS]; }; ``` -------------------------------- ### Get Event Summary Source: https://microsemi.github.io/switchtec-user/gasops_8c_source.html Retrieves global, partition, and PFF event summaries. Populates a switchtec_event_summary structure. ```c int gasop_event_summary(struct switchtec_dev *dev, struct switchtec_event_summary *sum) { int i; uint32_t reg; if (!sum) return 0; memset(sum, 0, sizeof(*sum)); sum->global = gas_reg_read32(dev, sw_event.global_summary); sum->part_bitmap = gas_reg_read64(dev, sw_event.part_event_bitmap); for (i = 0; i < dev->partition_count; i++) { reg = gas_reg_read32(dev, part_cfg[i].part_event_summary); sum->part[i] = reg; if (i == dev->partition) sum->local_part = reg; } for (i = 0; i < SWITCHTEC_MAX_PFF_CSR; i++) { reg = gas_reg_read16(dev, pff_csr[i].vendor_id); if (reg != MICROSEMI_VENDOR_ID) break; sum->pff[i] = gas_reg_read32(dev, pff_csr[i].pff_event_summary); } return 0; } ``` -------------------------------- ### PMON Event Counter Setup Structure Source: https://microsemi.github.io/switchtec-user/pmon_8h_source.html Defines the structure for setting up PMON event counters. Used to configure which events to count and their thresholds. ```c #pragma pack(push, 1) struct pmon_event_counter_setup { uint8_t sub_cmd_id; uint8_t stack_id; uint8_t counter_id; uint8_t num_counters; struct { uint32_t mask; uint8_t ieg; uint32_t thresh; } counters[63]; }; #pragma pack(pop) ``` -------------------------------- ### Get Firmware Image Partition Details Source: https://microsemi.github.io/switchtec-user/gasops_8c_source.html Retrieves information about a specific firmware image partition (image or config). Sets running and active flags. ```c int gasop_flash_part(struct switchtec_dev *dev, struct switchtec_fw_image_info *info, enum switchtec_fw_image_part_id_gen3 part) { struct flash_info_regs __gas *fi = &dev->gas_map->flash_info; struct sys_info_regs __gas *si = &dev->gas_map->sys_info; uint32_t active_addr = -1; int val; memset(info, 0, sizeof(*info)); switch (part) { case SWITCHTEC_FW_PART_ID_G3_IMG0: active_addr = __gas_read32(dev, &fi->active_img.address); set_fw_info_part(dev, info, &fi->img0); val = __gas_read16(dev, &si->img_running); if (val == SWITCHTEC_IMG0_RUNNING) info->running = true; break; case SWITCHTEC_FW_PART_ID_G3_IMG1: active_addr = __gas_read32(dev, &fi->active_img.address); set_fw_info_part(dev, info, &fi->img1); val = __gas_read16(dev, &si->img_running); if (val == SWITCHTEC_IMG1_RUNNING) info->running = true; break; case SWITCHTEC_FW_PART_ID_G3_DAT0: active_addr = __gas_read32(dev, &fi->active_cfg.address); set_fw_info_part(dev, info, &fi->cfg0); val = __gas_read16(dev, &si->cfg_running); if (val == SWITCHTEC_CFG0_RUNNING) info->running = true; break; case SWITCHTEC_FW_PART_ID_G3_DAT1: active_addr = __gas_read32(dev, &fi->active_cfg.address); set_fw_info_part(dev, info, &fi->cfg1); val = __gas_read16(dev, &si->cfg_running); if (val == SWITCHTEC_CFG1_RUNNING) info->running = true; break; case SWITCHTEC_FW_PART_ID_G3_NVLOG: set_fw_info_part(dev, info, &fi->nvlog); break; default: return -EINVAL; } if (info->part_addr == active_addr) info->active = true; return 0; } ``` -------------------------------- ### Setup Latency Counters Source: https://microsemi.github.io/switchtec-user/group__PMON.html Sets up a specified number of latency counters for given ingress and egress port IDs on a Switchtec device. ```APIDOC ## Setup Latency Counters ### Description Sets up a specified number of latency counters for given ingress and egress port IDs on a Switchtec device. ### Parameters #### Path Parameters - **dev** (Switchtec device handle) - Input - Switchtec device handle. - **nr_ports** (integer) - Input - Number of latency counters to setup. - **egress_port_ids** (list of port ids) - Input - A list of port ids for the egress of the TLP. - **ingress_port_ids** (list of port ids) - Input - A list of port ids for the ingress of the TLP (may be SWITCHTEC_LAT_ALL_INGRESS for all ports). ### Returns - **0** - On success. - **error code** - On failure. ``` -------------------------------- ### Get Switchtec Device Information Source: https://microsemi.github.io/switchtec-user/switchtec_8c_source.html Retrieves device information including boot phase, generation, and revision. Handles unsupported commands gracefully. ```c int switchtec_get_device_info(struct switchtec_dev *dev, enum switchtec_boot_phase *phase, enum switchtec_gen *gen, enum switchtec_rev *rev) { int ret; uint32_t ping_dw = 0; uint32_t dev_info; struct get_dev_info_reply { uint32_t dev_info; uint32_t ping_reply; } reply; ping_dw = time(NULL); ret = switchtec_cmd(dev, MRPC_GET_DEV_INFO, &ping_dw, sizeof(ping_dw), &reply, sizeof(reply)); if (ret == 0) { if (ping_dw != ~reply.ping_reply) return -1; dev_info = le32toh(reply.dev_info); if (phase) *phase = dev_info & 0xff; if (rev) *rev = (dev_info >> 8) & 0x0f; if (gen) *gen = map_to_gen((dev_info >> 12) & 0x0f); } else if (ERRNO_MRPC(errno) == ERR_MPRC_UNSUPPORTED) { if (phase) *phase = SWITCHTEC_BOOT_PHASE_FW; if (gen) *gen = SWITCHTEC_GEN3; if (rev) *rev = SWITCHTEC_REV_UNKNOWN; errno = 0; } else { return -1; } return 0; } ``` -------------------------------- ### Get Switchtec Boot Phase Source: https://microsemi.github.io/switchtec-user/switchtec_8h_source.html Returns the current boot phase of the Switchtec device. This is a pure function. ```c _PURE enum switchtec_boot_phase switchtec_boot_phase(struct switchtec_dev *dev); ``` -------------------------------- ### Open Switchtec Device by Path Source: https://microsemi.github.io/switchtec-user/platform_8c_source.html Opens a Switchtec device specified by its path. This is the primary way to get a handle to a device. ```c struct switchtec_dev *switchtec_open_by_path(const char *path); ``` -------------------------------- ### Get Firmware Image Type String Source: https://microsemi.github.io/switchtec-user/fw_8c.html Returns a human-readable string describing the type of a firmware image based on its information structure. ```c const char * switchtec_fw_image_type (const struct switchtec_fw_image_info *info) ``` -------------------------------- ### Get Device Information Source: https://microsemi.github.io/switchtec-user/switchtec_8h_source.html Retrieves comprehensive information about the Switchtec device, including boot phase, generation, and revision. ```c int switchtec_get_device_info(struct switchtec_dev *dev, enum switchtec_boot_phase *phase, enum switchtec_gen *gen, enum switchtec_rev *rev); ``` -------------------------------- ### Get Firmware Partition Summary Source: https://microsemi.github.io/switchtec-user/fw_8c.html Retrieves a summary of firmware information for all flash partitions on the Switchtec device. Returns a pointer to a switchtec_fw_part_summary structure. ```c struct switchtec_fw_part_summary * switchtec_fw_part_summary (struct switchtec_dev *dev) ``` -------------------------------- ### Get Switchtec Firmware Partition Info Source: https://microsemi.github.io/switchtec-user/linux_8c_source.html Retrieves information about a specific firmware partition, including its address, length, and status (active/running). ```c static int linux_flash_part(struct switchtec_dev *dev, struct switchtec_fw_image_info *info, enum switchtec_fw_image_part_id_gen3 part) { struct switchtec_linux *ldev = to_switchtec_linux(dev); struct switchtec_ioctl_flash_part_info ioctl_info = {0}; int ret; switch (part) { case SWITCHTEC_FW_PART_ID_G3_IMG0: ioctl_info.flash_partition = SWITCHTEC_IOCTL_PART_IMG0; break; case SWITCHTEC_FW_PART_ID_G3_IMG1: ioctl_info.flash_partition = SWITCHTEC_IOCTL_PART_IMG1; break; case SWITCHTEC_FW_PART_ID_G3_DAT0: ioctl_info.flash_partition = SWITCHTEC_IOCTL_PART_CFG0; break; case SWITCHTEC_FW_PART_ID_G3_DAT1: ioctl_info.flash_partition = SWITCHTEC_IOCTL_PART_CFG1; break; case SWITCHTEC_FW_PART_ID_G3_NVLOG: ioctl_info.flash_partition = SWITCHTEC_IOCTL_PART_NVLOG; break; default: return -EINVAL; } ret = ioctl(ldev->fd, SWITCHTEC_IOCTL_FLASH_PART_INFO, &ioctl_info); if (ret) return ret; info->part_addr = ioctl_info.address; info->part_len = ioctl_info.length; info->active = false; info->running = false; if (ioctl_info.active & SWITCHTEC_IOCTL_PART_ACTIVE) info->active = true; if (ioctl_info.active & SWITCHTEC_IOCTL_PART_RUNNING) info->running = true; return 0; } ``` -------------------------------- ### Set Bandwidth Counters for All Ports Source: https://microsemi.github.io/switchtec-user/pmon_8c_source.html Configures bandwidth counters for all available ports on the device. This is a convenient way to start monitoring all interfaces. ```c int switchtec_bwcntr_set_all(struct switchtec_dev *dev, enum switchtec_bw_type bw_type) { int ret, i; struct switchtec_status *status; int ids[SWITCHTEC_MAX_PORTS]; ret = switchtec_status(dev, &status); if (ret < 0) return ret; for (i = 0; i < ret; i++) { ids[i] = status[i].port.phys_id; } ret = switchtec_bwcntr_set_many(dev, ret, ids, bw_type); free(status); return ret; } ``` -------------------------------- ### Allocate and Initialize Firmware Partition Summary Source: https://microsemi.github.io/switchtec-user/fw_8c_source.html Allocates and initializes a structure to hold firmware partition information. It determines the number of partitions based on the device generation and populates the summary with partition IDs and metadata. ```c struct switchtec_fw_part_summary * switchtec_fw_part_summary(struct switchtec_dev *dev) { struct switchtec_fw_part_summary *summary; struct switchtec_fw_image_info **infp; struct switchtec_fw_part_type *type; int nr_info, nr_mcfg = 16; size_t st_sz; int ret, i; switch (dev->gen) { case SWITCHTEC_GEN3: nr_info = ARRAY_SIZE(switchtec_fw_partitions_gen3); break; case SWITCHTEC_GEN4: nr_info = ARRAY_SIZE(switchtec_fw_partitions_gen4); break; default: errno = EINVAL; return NULL; } st_sz = sizeof(*summary) + sizeof(*summary->all) * (nr_info + nr_mcfg); summary = malloc(st_sz); if (!summary) return NULL; memset(summary, 0, st_sz); summary->nr_info = nr_info; switch (dev->gen) { case SWITCHTEC_GEN3: for (i = 0; i < nr_info; i++) summary->all[i].part_id = switchtec_fw_partitions_gen3[i]; break; case SWITCHTEC_GEN4: for (i = 0; i < nr_info; i++) summary->all[i].part_id = switchtec_fw_partitions_gen4[i]; break; default: errno = EINVAL; return NULL; } ret = switchtec_fw_part_info(dev, nr_info, summary->all); if (ret != nr_info) { free(summary); return NULL; } ret = get_multicfg(dev, &summary->all[nr_info], &nr_mcfg); if (ret) { nr_mcfg = 0; errno = 0; } for (i = 0; i < nr_info; i++) { type = switchtec_fw_type_ptr(summary, &summary->all[i]); if (summary->all[i].active) type->active = &summary->all[i]; else type->inactive = &summary->all[i]; } infp = &summary->mult_cfg; for (; i < nr_info + nr_mcfg; i++) { *infp = &summary->all[i]; infp = &summary->all[i].next; } return summary; } ``` -------------------------------- ### switchtec_fw_setup_redundancy Source: https://microsemi.github.io/switchtec-user/globals_func.html Sets up firmware redundancy. ```APIDOC ## switchtec_fw_setup_redundancy ### Description Sets up firmware redundancy. ### Method Not applicable (C function) ### Endpoint Not applicable (C function) ### Parameters - **redundancy_mode** (int) - Required - The redundancy mode to set. ### Request Example ```c switchtec_fw_setup_redundancy(SWITCHTEC_FW_REDUNDANCY_MODE_ACTIVE_PASSIVE); ``` ### Response None ``` -------------------------------- ### Append GUID to Path Source: https://microsemi.github.io/switchtec-user/windows_8c_source.html Appends a GUID to a given path string, formatting it according to Windows conventions. ```c static void append_guid(const char *path, char *path_with_guid, size_t bufsize, const GUID *guid) { snprintf(path_with_guid, bufsize, "%s#{%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}", path, guid->Data1, guid->Data2, guid->Data3, guid->Data4[0], guid->Data4[1], guid->Data4[2], guid->Data4[3], guid->Data4[4], guid->Data4[5], guid->Data4[6], guid->Data4[7]); } ``` -------------------------------- ### switchtec_evcntr_get_setup Source: https://microsemi.github.io/switchtec-user/pmon_8c_source.html Retrieves the setup configuration for multiple event counters. It populates an array of switchtec_evcntr_setup structures with port mask, type mask, egress, and threshold information for each requested counter. ```APIDOC ## switchtec_evcntr_get_setup ### Description Retrieves the setup configuration for multiple event counters. It populates an array of switchtec_evcntr_setup structures with port mask, type mask, egress, and threshold information for each requested counter. ### Function Signature int switchtec_evcntr_get_setup(struct switchtec_dev *dev, unsigned stack_id, unsigned cntr_id, unsigned nr_cntrs, struct switchtec_evcntr_setup *res) ### Parameters #### Path Parameters * **dev** (struct switchtec_dev *) - Pointer to the Switchtec device structure. * **stack_id** (unsigned) - The stack ID for the event counters. * **cntr_id** (unsigned) - The starting counter ID. * **nr_cntrs** (unsigned) - The number of counters to retrieve setup for. * **res** (struct switchtec_evcntr_setup *) - Pointer to an array of switchtec_evcntr_setup structures to be populated with the results. ### Return Value Returns the number of counters for which setup was retrieved on success, or a negative error code on failure. ``` -------------------------------- ### Get Latency Measurement for a Single Port Source: https://microsemi.github.io/switchtec-user/pmon_8c_source.html A convenience function to get latency statistics for a single port. It calls `switchtec_lat_get_many` with the specified port ID. ```c int switchtec_lat_get(struct switchtec_dev *dev, int clear, int egress_port_ids, int *cur_ns, int *max_ns) { return switchtec_lat_get_many(dev, 1, clear, &egress_port_ids, cur_ns, max_ns); } ``` -------------------------------- ### switchtec_evcntr_setup Source: https://microsemi.github.io/switchtec-user/globals_func.html Configures an event counter. ```APIDOC ## switchtec_evcntr_setup ### Description Configures an event counter. ### Method Not applicable (C function) ### Endpoint Not applicable (C function) ### Parameters - **id** (int) - Required - The ID of the event counter. - **setup** (struct switchtec_evcntr_setup *) - Required - Pointer to a structure containing the setup configuration. ### Request Example ```c struct switchtec_evcntr_setup config; // Populate config structure switchtec_evcntr_setup(3, &config); ``` ### Response None ``` -------------------------------- ### GAS Read Command Example (Success Case 2) Source: https://microsemi.github.io/switchtec-user/linux-uart_8c_source.html Another successful GAS read example with a different offset and byte count. This command is essential for monitoring device status. ```bash gasrd -c -s 0x135c00 4 ``` -------------------------------- ### GAS Write Command Example (Success Case 2) Source: https://microsemi.github.io/switchtec-user/linux-uart_8c_source.html Another successful GAS write example, showing a different offset and CRC. This command is useful for configuring device registers. ```bash gaswr -c -s 0x135c10 0x00000008 0xbc ``` -------------------------------- ### switchtec_evcntr_setup Source: https://microsemi.github.io/switchtec-user/group__PMON.html Configures a specific event counter on a given stack and device. ```APIDOC ## switchtec_evcntr_setup ### Description Setup an event counter performance monitor. ### Function Signature int switchtec_evcntr_setup(struct switchtec_dev *dev, unsigned stack_id, unsigned cntr_id, struct switchtec_evcntr_setup *setup) ### Parameters * **dev** (struct switchtec_dev *) - Pointer to the Switchtec device structure. * **stack_id** (unsigned) - The ID of the stack to configure. * **cntr_id** (unsigned) - The ID of the counter to configure. * **setup** (struct switchtec_evcntr_setup *) - Pointer to the structure containing the setup configuration for the event counter. ### Returns An integer status code. 0 on success, negative on error. ``` -------------------------------- ### Example Class Definitions for Doxygen Graphing Source: https://microsemi.github.io/switchtec-user/graph_legend.html These C++ class definitions are used to illustrate how Doxygen generates inheritance and usage graphs. They include examples of documented, undocumented, templated, and inherited classes. ```cpp /*! Invisible class because of truncation */ class Invisible { }; /*! Truncated class, inheritance relation is hidden */ class Truncated : public Invisible { }; /* Class not documented with doxygen comments */ class Undocumented { }; /*! Class that is inherited using public inheritance */ class PublicBase : public Truncated { }; /*! A template class */ template class Templ { }; /*! Class that is inherited using protected inheritance */ class ProtectedBase { }; /*! Class that is inherited using private inheritance */ class PrivateBase { }; /*! Class that is used by the Inherited class */ class Used { }; /*! Super class that inherits a number of other classes */ class Inherited : public PublicBase, protected ProtectedBase, private PrivateBase, public Undocumented, public Templ { private: Used *m_usedClass; }; ``` -------------------------------- ### switchtec_lat_setup Source: https://microsemi.github.io/switchtec-user/globals_func.html Sets up a latency counter. ```APIDOC ## switchtec_lat_setup ### Description Sets up a latency counter. ### Method Not applicable (C function) ### Endpoint Not applicable (C function) ### Parameters - **id** (int) - Required - The ID of the latency counter. - **setup** (struct switchtec_lat_setup *) - Required - Pointer to a structure containing the setup configuration. ### Request Example ```c struct switchtec_lat_setup config; // Populate config structure switchtec_lat_setup(10, &config); ``` ### Response None ``` -------------------------------- ### switchtec_variant_str Source: https://microsemi.github.io/switchtec-user/globals_func.html Gets a string representation of the device variant. ```APIDOC ## switchtec_variant_str ### Description Gets a string representation of the device variant. ### Method Not applicable (C function) ### Endpoint Not applicable (C function) ### Parameters - **variant** (int) - Required - The variant number. ### Request Example ```c const char *variant_string = switchtec_variant_str(2); ``` ### Response #### Success Response - **variant_string** (const char *) - String representation of the variant. ``` -------------------------------- ### switchtec_lat_get_many Source: https://microsemi.github.io/switchtec-user/group__PMON.html Get a number of latency counter results. ```APIDOC ## switchtec_lat_get_many ### Description Get a number of latency counter results. Results are reported in nanoseconds. ### Method Not applicable (function call) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **dev** (struct switchtec_dev *) - Input - Switchtec device handle - **nr_ports** (int) - Input - Number of latency counters to retrieve - **clear** (int) - Input - If non-zero, clear the latency counters - **egress_port_ids** (int *) - Input - A list of port ids for the counters to return - **cur_ns** (int *) - Output - A list of current latency values - **max_ns** (int *) - Output - A list of maximum latency values ### Returns nr_ports on success, error code on failure ``` -------------------------------- ### switchtec_lat_setup_many Source: https://microsemi.github.io/switchtec-user/globals_func.html Sets up multiple latency counters. ```APIDOC ## switchtec_lat_setup_many ### Description Sets up multiple latency counters. ### Method Not applicable (C function) ### Endpoint Not applicable (C function) ### Parameters - **ids** (int *) - Required - Array of counter IDs to set up. - **count** (int) - Required - The number of counter IDs in the array. - **setup** (struct switchtec_lat_setup *) - Required - Array of setup configuration structures. ### Request Example ```c int ids[] = {10, 11}; struct switchtec_lat_setup configs[2]; // Populate configs array switchtec_lat_setup_many(ids, 2, configs); ``` ### Response None ``` -------------------------------- ### pmon_event_counter_setup Source: https://microsemi.github.io/switchtec-user/pmon_8h_source.html Sets up event counters for performance monitoring. This structure defines the sub-command ID, stack ID, counter ID, number of counters, and configuration for each counter including mask, interrupt enable group (IEG), and threshold. ```APIDOC ## Structure: pmon_event_counter_setup ### Description Configures performance monitoring event counters. Allows specifying which counters to monitor, their IDs, and associated parameters like masks and thresholds. ### Fields - **sub_cmd_id** (uint8_t) - Identifier for the sub-command. - **stack_id** (uint8_t) - The ID of the stack to configure. - **counter_id** (uint8_t) - The starting ID of the counters to configure. - **num_counters** (uint8_t) - The number of counters to configure. - **counters** (array[63]) - An array of counter configurations. Each element contains: - **mask** (uint32_t) - A mask for the counter. - **ieg** (uint8_t) - Interrupt Enable Group setting. - **thresh** (uint32_t) - The threshold value for the counter. ``` -------------------------------- ### switchtec_lat_get Source: https://microsemi.github.io/switchtec-user/group__PMON.html Get a single latency counter result. ```APIDOC ## switchtec_lat_get ### Description Get a single latency counter result. Results are reported in nanoseconds. ### Method Not applicable (function call) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **dev** (struct switchtec_dev *) - Input - Switchtec device handle - **clear** (int) - Input - If non-zero, clear the latency counter - **egress_port_ids** (int) - Input - The egress port of the latency counter to retrieve - **cur_ns** (int *) - Output - The current latency value - **max_ns** (int *) - Output - The maximum latency value ### Returns 1 on success, error code on failure ``` -------------------------------- ### switchtec_gen_str Source: https://microsemi.github.io/switchtec-user/globals_func.html Gets a string representation of the device generation. ```APIDOC ## switchtec_gen_str ### Description Gets a string representation of the device generation. ### Method Not applicable (C function) ### Endpoint Not applicable (C function) ### Parameters - **gen** (int) - Required - The generation number. ### Request Example ```c const char *gen_string = switchtec_gen_str(4); ``` ### Response #### Success Response - **gen_string** (const char *) - String representation of the generation. ``` -------------------------------- ### switchtec_die_temp Source: https://microsemi.github.io/switchtec-user/group__Misc.html Gets the die temperature of the Switchtec device. ```APIDOC ## switchtec_die_temp ### Description Gets the die temperature of the Switchtec device. ### Parameters #### Path Parameters - None #### Query Parameters - None #### Request Body - None ### Parameters - **dev** (struct switchtec_dev *) - in - Switchtec device handle ### Returns - The die temperature (in degrees Celsius) or a negative value on failure ### Definition `float switchtec_die_temp(struct switchtec_dev *dev)` ### Example ```c // Example usage not provided in source ``` ``` -------------------------------- ### Open Switchtec Device by Index on Windows Source: https://microsemi.github.io/switchtec-user/windows_8c_source.html Opens a Switchtec device by its index using SetupDiGetClassDevs and SetupDiEnumDeviceInterfaces. Retrieves the device path and then calls switchtec_open_by_path. Use when the device index is known. ```c struct switchtec_dev *switchtec_open_by_index(int index) { HDEVINFO devinfo; SP_DEVICE_INTERFACE_DATA deviface; SP_DEVINFO_DATA devdata; char path[MAX_PATH]; struct switchtec_dev *dev = NULL; BOOL status; devinfo = SetupDiGetClassDevs(&SWITCHTEC_INTERFACE_GUID, NULL, NULL, DIGCF_DEVICEINTERFACE | DIGCF_PRESENT); if (devinfo == INVALID_HANDLE_VALUE) return NULL; deviface.cbSize = sizeof(SP_DEVICE_INTERFACE_DATA); status = SetupDiEnumDeviceInterfaces(devinfo, NULL, &SWITCHTEC_INTERFACE_GUID, index, &deviface); if (!status) { errno = ENODEV; goto out; } status = get_path(devinfo, &deviface, &devdata, path, sizeof(path)); if (!status) goto out; dev = switchtec_open_by_path(path); out: SetupDiDestroyDeviceInfoList(devinfo); return dev; } ``` -------------------------------- ### switchtec_boot_resume Source: https://microsemi.github.io/switchtec-user/globals_func.html Resumes the boot process after a pause. ```APIDOC ## switchtec_boot_resume ### Description Resumes the boot process after a pause. ### Method Not applicable (C function) ### Endpoint Not applicable (C function) ### Parameters None ### Request Example ```c switchtec_boot_resume(); ``` ### Response None ``` -------------------------------- ### Getting Device Status Source: https://microsemi.github.io/switchtec-user/platform_8c_source.html Retrieves the status of Switchtec devices. ```APIDOC ## Get Devices Status ### Description Retrieves the status of Switchtec devices. ### Function * `switchtec_get_devices(struct switchtec_dev *dev, struct switchtec_status *status, int ports)`: Populates the `status` structure with device information. The `ports` argument specifies the number of ports to query. ``` -------------------------------- ### switchtec_get_device_info Source: https://microsemi.github.io/switchtec-user/group__Misc.html Retrieves the device generation, revision, and boot phase information. ```APIDOC ## switchtec_get_device_info ### Description Retrieves the device generation, revision, and boot phase information. ### Parameters #### Path Parameters - None #### Query Parameters - None #### Request Body - None ### Parameters - **dev** (struct switchtec_dev *) - in - Switchtec device handle - **phase** (enum switchtec_boot_phase *) - out - The current boot phase - **gen** (enum switchtec_gen *) - out - Device generation - **rev** (enum switchtec_rev *) - out - Device revision ### Returns - 0 on success, error code on failure ### Definition `int switchtec_get_device_info(struct switchtec_dev *dev, enum switchtec_boot_phase *phase, enum switchtec_gen *gen, enum switchtec_rev *rev)` ### Example ```c // Example usage not provided in source ``` ``` -------------------------------- ### switchtec_evcntr_type_str Source: https://microsemi.github.io/switchtec-user/globals_func.html Gets a string representation of an event counter type. ```APIDOC ## switchtec_evcntr_type_str ### Description Gets a string representation of an event counter type. ### Method Not applicable (C function) ### Endpoint Not applicable (C function) ### Parameters - **type** (int) - Required - The type of the event counter. ### Request Example ```c const char *type_name = switchtec_evcntr_type_str(1); ``` ### Response #### Success Response - **type_name** (const char *) - A string describing the event counter type. ``` -------------------------------- ### switchtec_evcntr_type_count Source: https://microsemi.github.io/switchtec-user/globals_func.html Gets the number of available event counter types. ```APIDOC ## switchtec_evcntr_type_count ### Description Gets the number of available event counter types. ### Method Not applicable (C function) ### Endpoint Not applicable (C function) ### Parameters None ### Request Example ```c int count = switchtec_evcntr_type_count(); ``` ### Response #### Success Response - **count** (int) - The number of available event counter types. ``` -------------------------------- ### Get Switchtec Device Variant Source: https://microsemi.github.io/switchtec-user/switchtec_8c_source.html Returns the variant of the Switchtec device. ```c _PURE enum switchtec_variant switchtec_variant(struct switchtec_dev *dev) { return dev->var; } ``` -------------------------------- ### Get Switchtec Device Generation Source: https://microsemi.github.io/switchtec-user/switchtec_8c_source.html Returns the generation of the Switchtec device. ```c _PURE enum switchtec_gen switchtec_gen(struct switchtec_dev *dev) { return dev->gen; } ``` -------------------------------- ### Free Firmware Partition Summary Source: https://microsemi.github.io/switchtec-user/fw_8c.html Frees the memory allocated for a firmware part summary data structure. Requires a pointer to the summary structure. ```c void switchtec_fw_part_summary_free (struct switchtec_fw_part_summary *summary) ``` -------------------------------- ### Get Device Status Source: https://microsemi.github.io/switchtec-user/group__Device.html Retrieves the status of all ports on a Switchtec device. ```APIDOC ## switchtec_status ### Description Gets the status of all ports on a Switchtec device. ### Method `switchtec_status` ### Parameters - **dev** (struct switchtec_dev *) - Required - A handle to the opened Switchtec device. - **status** (struct switchtec_status **) - Output - A pointer to a structure that will be populated with port status information. ### Return Value - Returns 0 on success, or a negative value on failure. ``` -------------------------------- ### gasop_flash_part Source: https://microsemi.github.io/switchtec-user/gasops_8h_source.html Flashes a firmware image partition. ```APIDOC ## gasop_flash_part ### Description Flashes a firmware image partition. ### Function Signature int gasop_flash_part(struct switchtec_dev *dev, struct switchtec_fw_image_info *info, enum switchtec_fw_image_part_id_gen3 part); ### Parameters - **dev** (struct switchtec_dev *) - Pointer to the switchtec device structure. - **info** (struct switchtec_fw_image_info *) - Pointer to the firmware image information. - **part** (enum switchtec_fw_image_part_id_gen3) - The firmware image partition ID. ``` -------------------------------- ### Get Performance Monitoring Event Counter Data Source: https://microsemi.github.io/switchtec-user/pmon_8c_source.html A generic function to retrieve performance monitoring event counter data. It supports getting raw counts or clearing them based on the `clear` parameter. Input validation checks for valid counter IDs, number of counters, and buffer sizes. ```c static int evcntr_get(struct switchtec_dev *dev, int sub_cmd, unsigned stack_id, unsigned cntr_id, unsigned nr_cntrs, void *res, size_t res_size, int clear) { int ret; struct pmon_event_counter_get cmd = { .sub_cmd_id = sub_cmd, .stack_id = stack_id, .counter_id = cntr_id, .num_counters = nr_cntrs, .read_clear = clear, }; if (res_size > MRPC_MAX_DATA_LEN || cntr_id >= SWITCHTEC_MAX_EVENT_COUNTERS || nr_cntrs > SWITCHTEC_MAX_EVENT_COUNTERS || cntr_id + nr_cntrs > SWITCHTEC_MAX_EVENT_COUNTERS) { errno = EINVAL; return -errno; } ``` -------------------------------- ### Get Switchtec Device Partition Source: https://microsemi.github.io/switchtec-user/switchtec_8c_source.html Returns the partition number of the Switchtec device. ```c _PURE int switchtec_partition(struct switchtec_dev *dev) { return dev->partition; } ``` -------------------------------- ### Get Firmware Partition Information Source: https://microsemi.github.io/switchtec-user/fw_8c.html Retrieves firmware information structures for a specified number of firmware partitions on the device. Requires the device handle and a pointer to an array for the info. ```c static int switchtec_fw_part_info (struct switchtec_dev *dev, int nr_info, struct switchtec_fw_image_info *info) ``` -------------------------------- ### Get Switchtec Variant Source: https://microsemi.github.io/switchtec-user/switchtec_8h_source.html Returns the variant of the Switchtec device. This is a pure function. ```c _PURE enum switchtec_variant switchtec_variant(struct switchtec_dev *dev); ``` -------------------------------- ### Get Switchtec Generation Source: https://microsemi.github.io/switchtec-user/switchtec_8h_source.html Returns the generation of the Switchtec device. This is a pure function. ```c _PURE enum switchtec_gen switchtec_gen(struct switchtec_dev *dev); ``` -------------------------------- ### Set Firmware Image Partition Information Source: https://microsemi.github.io/switchtec-user/gasops_8c_source.html Helper function to set partition address and length for firmware image info. ```c static void set_fw_info_part(struct switchtec_dev *dev, struct switchtec_fw_image_info *info, struct partition_info __gas *pi) { info->part_addr = __gas_read32(dev, &pi->address); info->part_len = __gas_read32(dev, &pi->length); } ``` -------------------------------- ### switchtec_evcntr_type_str Source: https://microsemi.github.io/switchtec-user/group__PMON.html Get a string for the event indicated by lowest bit set in the type_mask. ```APIDOC ## switchtec_evcntr_type_str ### Description Get a string for the event indicated by lowest bit set in the type_mask. Clears the lowest bit in `type_mask` and returns the string corresponding to that type. Thus, this function can be used in a loop to print a list of strings representing a bit mask of types. ### Method Not applicable (function call) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **type_mask** (int *) - Input/Output - Bitmask of types ### Returns Name string ``` -------------------------------- ### Switchtec Basic Device Operations Functions Source: https://microsemi.github.io/switchtec-user/dir_97aefd0d527b934f1d99a682da8fe6a9.html Includes core library functions for basic device operations with Switchtec. This file covers fundamental interactions like device initialization and configuration. ```c /* Switchtec core library functions for basic device operations. */ ``` -------------------------------- ### Count Switchtec Devices on Windows Source: https://microsemi.github.io/switchtec-user/windows_8c_source.html Enumerates and counts the number of Switchtec devices present on the system using Windows SetupAPI. Requires the SWITCHTEC_INTERFACE_GUID. ```c static int count_devices(void) { HDEVINFO devinfo; DWORD count = 0; SP_DEVICE_INTERFACE_DATA deviface; devinfo = SetupDiGetClassDevs(&SWITCHTEC_INTERFACE_GUID, NULL, NULL, DIGCF_DEVICEINTERFACE | DIGCF_PRESENT); deviface.cbSize = sizeof(SP_DEVICE_INTERFACE_DATA); while (SetupDiEnumDeviceInterfaces(devinfo, NULL, &SWITCHTEC_INTERFACE_GUID, count++, &deviface)); return count - 1; } ``` -------------------------------- ### Get Firmware Version Source: https://microsemi.github.io/switchtec-user/group__Device.html Retrieves the firmware version of the Switchtec device as a human-readable string. ```APIDOC ## switchtec_get_fw_version ### Description Gets the firmware version of the Switchtec device as a user-readable string. ### Method `switchtec_get_fw_version` ### Parameters - **dev** (struct switchtec_dev *) - Required - A handle to the opened Switchtec device. - **buf** (char *) - Output - A buffer to store the firmware version string. - **buflen** (size_t) - Required - The size of the buffer provided. ### Return Value - Returns 0 on success, or a negative value on failure. ``` -------------------------------- ### pmon_event_counter_get_setup_result Source: https://microsemi.github.io/switchtec-user/pmon_8h_source.html Retrieves the setup configuration for event counters. This structure holds the mask, interrupt enable group (IEG), and threshold for a configured event counter. ```APIDOC ## Structure: pmon_event_counter_get_setup_result ### Description Represents the configuration details retrieved for a performance monitoring event counter. ### Fields - **mask** (uint32_t) - The mask associated with the event counter. - **ieg** (uint8_t) - The Interrupt Enable Group setting for the counter. - **thresh** (uint32_t) - The threshold value configured for the counter. ```