30#include "../switchtec_priv.h"
33#include "switchtec/gas_mrpc.h"
34#include "switchtec/errors.h"
68 int device,
int func);
106 dev->ops->close(dev);
135 if (sum->img.active && sum->img.active->running) {
136 running_img = sum->img.active;
137 }
else if (sum->img.inactive && sum->img.inactive->running) {
138 running_img = sum->img.inactive;
145 strncpy(buf, running_img->
version, buflen);
146 buf[buflen - 1] =
'\0';
161 if (!dev->ops->get_device_version)
164 return dev->ops->get_device_version(dev, res);
179 const void *payload,
size_t payload_len,
void *resp,
184 cmd &= SWITCHTEC_CMD_MASK;
186 cmd |= dev->pax_id << SWITCHTEC_PAX_ID_SHIFT;
188 ret = dev->ops->cmd(dev, cmd, payload, payload_len, resp, resp_len);
191 errno |= SWITCHTEC_ERRNO_MRPC_FLAG_BIT;
213 if (!dev->ops->get_devices)
216 return dev->ops->get_devices(dev, status, ports);
229 int *partition,
int *port)
231 return dev->ops->pff_to_port(dev, pff, partition, port);
246 return dev->ops->port_to_pff(dev, partition, port, pff);
273 return dev->ops->gas_map(dev, writeable, map_size);
284 if (!dev->ops->gas_unmap)
287 dev->ops->gas_unmap(dev, map);
300 enum switchtec_fw_image_part_id_gen3 part)
302 return dev->ops->flash_part(dev, info, part);
315 return dev->ops->event_summary(dev, sum);
330 int index,
int flags,
333 return dev->ops->event_ctl(dev, e, index, flags, data);
346 if (!dev->ops->event_wait) {
351 return dev->ops->event_wait(dev, timeout_ms);
361int gas_read8(
struct switchtec_dev *dev, uint8_t __gas *addr, uint8_t *val)
363 if (dev->pax_id != dev->local_pax_id)
364 return gas_mrpc_read8(dev, addr, val);
366 *val = __gas_read8(dev, addr);
378int gas_read16(
struct switchtec_dev *dev, uint16_t __gas *addr, uint16_t *val)
380 if (dev->pax_id != dev->local_pax_id)
381 return gas_mrpc_read16(dev, addr, val);
383 *val = __gas_read16(dev, addr);
395int gas_read32(
struct switchtec_dev *dev, uint32_t __gas *addr, uint32_t *val)
397 if (dev->pax_id != dev->local_pax_id)
398 return gas_mrpc_read32(dev, addr, val);
400 *val = __gas_read32(dev, addr);
412int gas_read64(
struct switchtec_dev *dev, uint64_t __gas *addr, uint64_t *val)
414 if (dev->pax_id != dev->local_pax_id)
415 return gas_mrpc_read64(dev, addr, val);
417 *val = __gas_read64(dev, addr);
428void gas_write8(
struct switchtec_dev *dev, uint8_t val, uint8_t __gas *addr)
430 if (dev->pax_id != dev->local_pax_id)
431 gas_mrpc_write8(dev, val, addr);
433 __gas_write8(dev, val, addr);
442void gas_write16(
struct switchtec_dev *dev, uint16_t val, uint16_t __gas *addr)
444 if (dev->pax_id != dev->local_pax_id)
445 gas_mrpc_write16(dev, val, addr);
447 __gas_write16(dev, val, addr);
456void gas_write32(
struct switchtec_dev *dev, uint32_t val, uint32_t __gas *addr)
458 if (dev->pax_id != dev->local_pax_id)
459 gas_mrpc_write32(dev, val, addr);
461 __gas_write32(dev, val, addr);
470void gas_write64(
struct switchtec_dev *dev, uint64_t val, uint64_t __gas *addr)
472 if (dev->pax_id != dev->local_pax_id)
473 gas_mrpc_write64(dev, val, addr);
475 __gas_write64(dev, val, addr);
486 const void *src,
size_t n)
488 if (dev->pax_id != dev->local_pax_id)
491 __memcpy_to_gas(dev, dest, src, n);
503 const void __gas *src,
size_t n)
505 if (dev->pax_id != dev->local_pax_id)
508 __memcpy_from_gas(dev, dest, src, n);
521 const void __gas *src,
size_t n)
523 if (dev->pax_id != dev->local_pax_id)
526 return __write_from_gas(dev, fd, src, n);
struct switchtec_dev * switchtec_open_uart(int fd)
Open a switchtec device behind a uart device.
int switchtec_list(struct switchtec_device_info **devlist)
List all the switchtec devices in the system.
struct switchtec_dev * switchtec_open_by_index(int index)
Open a switchtec device by index.
int switchtec_cmd(struct switchtec_dev *dev, uint32_t cmd, const void *payload, size_t payload_len, void *resp, size_t resp_len)
Execute an MRPC command.
void switchtec_close(struct switchtec_dev *dev)
Close a Switchtec device handle.
int mrpc_error_cmd
The MRPC command ID when errno is set.
struct switchtec_dev * switchtec_open_i2c(const char *path, int i2c_addr)
Open a switchtec device behind an I2C device.
struct switchtec_dev * switchtec_open_by_path(const char *path)
Open a switchtec device by path.
struct switchtec_dev * switchtec_open_eth(const char *ip, const int inst)
Open a switchtec device over ethernet.
int switchtec_get_devices(struct switchtec_dev *dev, struct switchtec_status *status, int ports)
Populate an already retrieved switchtec_status structure list with information about the devices plug...
int switchtec_get_device_version(struct switchtec_dev *dev, int *res)
Get the minor version number as a user readable int.
int switchtec_get_fw_version(struct switchtec_dev *dev, char *buf, size_t buflen)
Get the firmware version as a user readable string.
struct switchtec_dev * switchtec_open_by_pci_addr(int domain, int bus, int device, int func)
Open a switchtec device by PCI address (BDF).
int switchtec_event_ctl(struct switchtec_dev *dev, enum switchtec_event_id e, int index, int flags, uint32_t data[5])
Enable, disable and clear events or retrieve event data.
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.
int switchtec_event_wait(struct switchtec_dev *dev, int timeout_ms)
Wait for any event to occur (typically just an interrupt).
void switchtec_fw_part_summary_free(struct switchtec_fw_part_summary *summary)
Free a firmware part summary data structure.
int switchtec_flash_part(struct switchtec_dev *dev, struct switchtec_fw_image_info *info, enum switchtec_fw_image_part_id_gen3 part)
Retrieve information about a flash partition.
void gas_mrpc_memcpy_to_gas(struct switchtec_dev *dev, void __gas *dest, const void *src, size_t n)
Copy data to the GAS using MRPC commands.
int gas_mrpc_memcpy_from_gas(struct switchtec_dev *dev, void *dest, const void __gas *src, size_t n)
Copy data from the GAS using MRPC commands.
ssize_t gas_mrpc_write_from_gas(struct switchtec_dev *dev, int fd, const void __gas *src, size_t n)
Call write() with data from the GAS using an MRPC command.
void memcpy_to_gas(struct switchtec_dev *dev, void __gas *dest, const void *src, size_t n)
Copy data to the GAS.
ssize_t write_from_gas(struct switchtec_dev *dev, int fd, const void __gas *src, size_t n)
Call write() with data from the GAS.
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.
void gas_write16(struct switchtec_dev *dev, uint16_t val, uint16_t __gas *addr)
Write a uint16_t to the GAS.
void switchtec_gas_unmap(struct switchtec_dev *dev, gasptr_t map)
Unmap the GAS region mapped with.
void gas_write64(struct switchtec_dev *dev, uint64_t val, uint64_t __gas *addr)
Write a uint64_t to the GAS.
void gas_write32(struct switchtec_dev *dev, uint32_t val, uint32_t __gas *addr)
Write a uint32_t to the GAS.
void gas_write8(struct switchtec_dev *dev, uint8_t val, uint8_t __gas *addr)
Write a uint8_t to the GAS.
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.
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.
Represents a Switchtec device in the switchtec_list() function.
Information about a firmware image or partition.
char version[32]
Firmware/Config version.
switchtec_event_id
Enumeration of all possible events.
__gas struct switchtec_gas * gasptr_t
Shortform for a pointer to the GAS register space.
static int switchtec_is_gen6(struct switchtec_dev *dev)
Return whether a Switchtec device is a Gen 6 device.