Switchtec Userspace
PROJECT_NUMBER = PROJECT_NUMBER=PROJECT_NUMBER = 2.2
|
Functions to list, open and perform basic operations on Switchtec devices. More...
Classes | |
struct | switchtec_device_id |
Switchtec device id to generation/variant mapping. More... | |
Functions | |
struct switchtec_dev * | switchtec_open (const char *device) |
Open a Switchtec device by string. More... | |
_PURE int | switchtec_device_id (struct switchtec_dev *dev) |
Get the device id of the device. More... | |
_PURE enum switchtec_gen | switchtec_gen (struct switchtec_dev *dev) |
Get the generation of the device. More... | |
_PURE enum switchtec_variant | switchtec_variant (struct switchtec_dev *dev) |
Get the variant type of the device. More... | |
_PURE enum switchtec_boot_phase | switchtec_boot_phase (struct switchtec_dev *dev) |
Get boot phase of the device. More... | |
_PURE const char * | switchtec_name (struct switchtec_dev *dev) |
Get the string that was used to open the deviec. More... | |
_PURE int | switchtec_partition (struct switchtec_dev *dev) |
Get the partiton number of the device that was opened. More... | |
int | switchtec_status (struct switchtec_dev *dev, struct switchtec_status **status) |
Get the status of all the ports on a switchtec device. More... | |
void | switchtec_status_free (struct switchtec_status *status, int ports) |
Free a list of status structures allocated by switchtec_status() More... | |
const char * | switchtec_strerror (void) |
Return a message coresponding to the last error. More... | |
void | switchtec_perror (const char *str) |
Print an error string to stdout. More... | |
struct switchtec_dev * | switchtec_open_by_path (const char *path) |
Open a switchtec device by path. More... | |
struct switchtec_dev * | switchtec_open_by_index (int index) |
Open a switchtec device by index. More... | |
struct switchtec_dev * | switchtec_open_by_pci_addr (int domain, int bus, int device, int func) |
Open a switchtec device by PCI address (BDF) More... | |
struct switchtec_dev * | switchtec_open_i2c (const char *path, int i2c_addr) |
Open a switchtec device behind an I2C device. More... | |
struct switchtec_dev * | switchtec_open_uart (int fd) |
Open a switchtec device behind a uart device. More... | |
void | switchtec_close (struct switchtec_dev *dev) |
Close a Switchtec device handle. More... | |
int | switchtec_list (struct switchtec_device_info **devlist) |
List all the switchtec devices in the system. More... | |
int | switchtec_get_fw_version (struct switchtec_dev *dev, char *buf, size_t buflen) |
Get the firmware version as a user readable string. More... | |
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. More... | |
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 plugged into the switch. More... | |
Variables | |
static const struct switchtec_device_id | switchtec_device_id_tbl [] |
Supported Switchtec device id table. | |
int | mrpc_error_cmd |
The MRPC command ID when errno is set. More... | |
Functions to list, open and perform basic operations on Switchtec devices.
switchtec_list() may be used to list all the devices in the system. The devices may then be opened using switchtec_open(). There are a number of other functions to open devices by more specific information but switchtec_open() is prefered and covers all cases.
MRPC commands may be submitted to an open switch handle with switchtec_cmd() and port status information may be retrieved with switchtec_status().
_PURE enum switchtec_boot_phase switchtec_boot_phase | ( | struct switchtec_dev * | dev | ) |
Get boot phase of the device.
[in] | dev | Switchtec device handle |
This is only valid if the device was opend with switchtec_open().
Definition at line 303 of file switchtec.c.
void switchtec_close | ( | struct switchtec_dev * | dev | ) |
Close a Switchtec device handle.
[in] | dev | Switchtec device handle to close |
Definition at line 91 of file platform.c.
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.
[in] | dev | Switchtec device handle |
[in] | cmd | Command ID |
[in] | payload | Input data |
[in] | payload_len | Input data length (in bytes) |
[out] | resp | Output data |
[in] | resp_len | Output data length (in bytes) |
Definition at line 132 of file platform.c.
_PURE int switchtec_device_id | ( | struct switchtec_dev * | dev | ) |
Get the device id of the device.
[in] | dev | Switchtec device handle |
This is only valid if the device was opend with switchtec_open().
Definition at line 267 of file switchtec.c.
_PURE enum switchtec_gen switchtec_gen | ( | struct switchtec_dev * | dev | ) |
Get the generation of the device.
[in] | dev | Switchtec device handle |
This is only valid if the device was opend with switchtec_open().
Definition at line 279 of file switchtec.c.
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 plugged into the switch.
[in] | dev | Switchtec device handle |
[in,out] | status | List of status structures |
[in] | ports | Number of ports (length of the status list) |
Note: this is only supported on the Linux platform. Other platforms will silently succeed but not populate any of the devices.
Definition at line 162 of file platform.c.
int switchtec_get_fw_version | ( | struct switchtec_dev * | dev, |
char * | buf, | ||
size_t | buflen | ||
) |
Get the firmware version as a user readable string.
[in] | dev | Switchtec device handle |
[in] | buf | String buffer to put the version in |
[in] | buflen | Maximum length of the string buffer |
Definition at line 115 of file platform.c.
int switchtec_list | ( | struct switchtec_device_info ** | devlist | ) |
List all the switchtec devices in the system.
[in] | devlist | List of devices, allocated by this function |
devlist
should be freed after use with free().
_PURE const char* switchtec_name | ( | struct switchtec_dev * | dev | ) |
Get the string that was used to open the deviec.
[in] | dev | Switchtec device handle |
This is only valid if the device was opend with switchtec_open().
Definition at line 315 of file switchtec.c.
struct switchtec_dev* switchtec_open | ( | const char * | device | ) |
Open a Switchtec device by string.
[in] | device | A string representing the device to open |
The string can be specified as:
Definition at line 188 of file switchtec.c.
struct switchtec_dev* switchtec_open_by_index | ( | int | index | ) |
Open a switchtec device by index.
[in] | index | Ordinal index (0, 1, 2, 3...) |
Note the index is not guaranteed to be constant especially considering hotplug events.
struct switchtec_dev* switchtec_open_by_path | ( | const char * | path | ) |
Open a switchtec device by path.
[in] | path | Path to the switchtec device |
struct switchtec_dev* switchtec_open_by_pci_addr | ( | int | domain, |
int | bus, | ||
int | device, | ||
int | func | ||
) |
Open a switchtec device by PCI address (BDF)
[in] | domain | PCI domain of the device |
[in] | bus | PCI Bus Number |
[in] | device | PCI Device Number |
[in] | func | PCI Function Number |
struct switchtec_dev* switchtec_open_i2c | ( | const char * | path, |
int | i2c_addr | ||
) |
Open a switchtec device behind an I2C device.
[in] | path | path to I2C device |
[in] | i2c_addr | I2C Slave Address |
struct switchtec_dev* switchtec_open_uart | ( | int | fd | ) |
Open a switchtec device behind a uart device.
[in] | fd | file descriptor to uart device |
_PURE int switchtec_partition | ( | struct switchtec_dev * | dev | ) |
Get the partiton number of the device that was opened.
[in] | dev | Switchtec device handle |
Definition at line 325 of file switchtec.c.
void switchtec_perror | ( | const char * | str | ) |
Print an error string to stdout.
[in] | str | String that will be prefixed to the error message |
This can be called after another switchtec function returned an error to find out what caused the problem.
Definition at line 592 of file switchtec.c.
int switchtec_status | ( | struct switchtec_dev * | dev, |
struct switchtec_status ** | status | ||
) |
Get the status of all the ports on a switchtec device.
[in] | dev | Switchtec device handle |
[out] | status | A pointer to an allocated list of port statuses |
This function a allocates memory for the number of ports in the system. The returned status
structure should be freed with the switchtec_status_free() function.
Definition at line 389 of file switchtec.c.
void switchtec_status_free | ( | struct switchtec_status * | status, |
int | ports | ||
) |
Free a list of status structures allocated by switchtec_status()
[in] | status | Status structure list |
[in] | ports | Number of ports in the list (as returned by switchtec_status()) |
Definition at line 470 of file switchtec.c.
const char* switchtec_strerror | ( | void | ) |
Return a message coresponding to the last error.
This can be called after another switchtec function returned an error to find out what caused the problem.
For MRPC errors (mrpc_error_cmd is not -1) that are unknown to this function, the string "Unknown MRPC error" are returned. Otherwise, either proper system error string or MRPC error string is returned.
Definition at line 509 of file switchtec.c.
_PURE enum switchtec_variant switchtec_variant | ( | struct switchtec_dev * | dev | ) |
Get the variant type of the device.
[in] | dev | Switchtec device handle |
This is only valid if the device was opend with switchtec_open().
Definition at line 291 of file switchtec.c.
int mrpc_error_cmd |
The MRPC command ID when errno is set.
If errno is for MRPC (with the SWITCHTEC_ERRNO_MRPC_FLAG_BIT set), this variable will be set to the corresponding MRPC command ID.
Definition at line 497 of file switchtec.c.