Switchtec Userspace  PROJECT_NUMBER = PROJECT_NUMBER=PROJECT_NUMBER = 2.2
Classes | Functions | Variables
Switchtec Management

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...
 

Detailed Description

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().

Function Documentation

_PURE enum switchtec_boot_phase switchtec_boot_phase ( struct switchtec_dev *  dev)

Get boot phase of the device.

Parameters
[in]devSwitchtec device handle
Returns
The boot phase of the device

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.

Parameters
[in]devSwitchtec 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.

Parameters
[in]devSwitchtec device handle
[in]cmdCommand ID
[in]payloadInput data
[in]payload_lenInput data length (in bytes)
[out]respOutput data
[in]resp_lenOutput data length (in bytes)
Returns
0 on success, negative on system error, positive on MRPC error

Definition at line 132 of file platform.c.

_PURE int switchtec_device_id ( struct switchtec_dev *  dev)

Get the device id of the device.

Parameters
[in]devSwitchtec device handle
Returns
The device id of the device

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.

Parameters
[in]devSwitchtec device handle
Returns
The generation of the device

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.

Parameters
[in]devSwitchtec device handle
[in,out]statusList of status structures
[in]portsNumber of ports (length of the status list)
Returns
0 on success, negative on failure

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.

Parameters
[in]devSwitchtec device handle
[in]bufString buffer to put the version in
[in]buflenMaximum 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.

Parameters
[in]devlistList 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.

Parameters
[in]devSwitchtec device handle
Returns
The name of the device as a string

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.

Parameters
[in]deviceA string representing the device to open
Returns
A switchtec_dev structure for use in other library functions or NULL if an error occurred.

The string can be specified as:

  • A path to the device (/dev/switchtec0)
  • An index (0, 1, etc)
  • An index with a 'switchtec' prefix (switchtec0)
  • A BDF (bus, device function) string (3:00.1)
  • An I2C device with slave number (/dev/i2c-1@0x20)
  • An I2C adapter number and slave number (0@0x20)
  • An I2C device delimited with a colon (/dev/i2c-1:0x20) (must start with a / so that it is distinguishable from a BDF)
  • A UART device (/dev/ttyUSB0)

Definition at line 188 of file switchtec.c.

struct switchtec_dev* switchtec_open_by_index ( int  index)

Open a switchtec device by index.

Parameters
[in]indexOrdinal index (0, 1, 2, 3...)
Returns
Switchtec device handle, NULL on failure

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.

Parameters
[in]pathPath to the switchtec device
Returns
Switchtec device handle, NULL on failure
struct switchtec_dev* switchtec_open_by_pci_addr ( int  domain,
int  bus,
int  device,
int  func 
)

Open a switchtec device by PCI address (BDF)

Parameters
[in]domainPCI domain of the device
[in]busPCI Bus Number
[in]devicePCI Device Number
[in]funcPCI Function Number
Returns
Switchtec device handle, NULL on failure
struct switchtec_dev* switchtec_open_i2c ( const char *  path,
int  i2c_addr 
)

Open a switchtec device behind an I2C device.

Parameters
[in]pathpath to I2C device
[in]i2c_addrI2C Slave Address
Returns
Switchtec device handle, NULL on failure
struct switchtec_dev* switchtec_open_uart ( int  fd)

Open a switchtec device behind a uart device.

Parameters
[in]fdfile descriptor to uart device
Returns
Switchtec device handle, NULL on failure
_PURE int switchtec_partition ( struct switchtec_dev *  dev)

Get the partiton number of the device that was opened.

Parameters
[in]devSwitchtec device handle
Returns
The partition number

Definition at line 325 of file switchtec.c.

void switchtec_perror ( const char *  str)

Print an error string to stdout.

Parameters
[in]strString 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.

Parameters
[in]devSwitchtec device handle
[out]statusA pointer to an allocated list of port statuses
Returns
The number of ports in the status list or a negative value on failure

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()

Parameters
[in]statusStatus structure list
[in]portsNumber 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.

Parameters
[in]devSwitchtec device handle
Returns
The variant type of the device

This is only valid if the device was opend with switchtec_open().

Definition at line 291 of file switchtec.c.

Variable Documentation

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.