return cryptodev;
}
-static inline int
-rte_cryptodev_create_unique_device_name(char *name, size_t size,
- struct rte_pci_device *pci_dev)
-{
- int ret;
-
- if ((name == NULL) || (pci_dev == NULL))
- return -EINVAL;
-
- ret = snprintf(name, size, "%d:%d.%d",
- pci_dev->addr.bus, pci_dev->addr.devid,
- pci_dev->addr.function);
- if (ret < 0)
- return ret;
- return 0;
-}
-
int
rte_cryptodev_pmd_release_device(struct rte_cryptodev *cryptodev)
{
if (cryptodrv == NULL)
return -ENODEV;
- /* Create unique Crypto device name using PCI address */
- rte_cryptodev_create_unique_device_name(cryptodev_name,
- sizeof(cryptodev_name), pci_dev);
+ rte_eal_pci_device_name(&pci_dev->addr, cryptodev_name,
+ sizeof(cryptodev_name));
cryptodev = rte_cryptodev_pmd_allocate(cryptodev_name, rte_socket_id());
if (cryptodev == NULL)
if (pci_dev == NULL)
return -EINVAL;
- /* Create unique device name using PCI address */
- rte_cryptodev_create_unique_device_name(cryptodev_name,
- sizeof(cryptodev_name), pci_dev);
+ rte_eal_pci_device_name(&pci_dev->addr, cryptodev_name,
+ sizeof(cryptodev_name));
cryptodev = rte_cryptodev_pmd_get_named_dev(cryptodev_name);
if (cryptodev == NULL)
return -1;
}
+int
+pci_update_device(const struct rte_pci_addr *addr)
+{
+ int fd;
+ struct pci_conf matches[2];
+ struct pci_match_conf match = {
+ .pc_sel = {
+ .pc_domain = addr->domain,
+ .pc_bus = addr->bus,
+ .pc_dev = addr->devid,
+ .pc_func = addr->function,
+ },
+ };
+ struct pci_conf_io conf_io = {
+ .pat_buf_len = 0,
+ .num_patterns = 1,
+ .patterns = &match,
+ .match_buf_len = sizeof(matches),
+ .matches = &matches[0],
+ };
+
+ fd = open("/dev/pci", O_RDONLY);
+ if (fd < 0) {
+ RTE_LOG(ERR, EAL, "%s(): error opening /dev/pci\n", __func__);
+ goto error;
+ }
+
+ if (ioctl(fd, PCIOCGETCONF, &conf_io) < 0) {
+ RTE_LOG(ERR, EAL, "%s(): error with ioctl on /dev/pci: %s\n",
+ __func__, strerror(errno));
+ goto error;
+ }
+
+ if (conf_io.num_matches != 1)
+ goto error;
+
+ if (pci_scan_one(fd, &matches[0]) < 0)
+ goto error;
+
+ close(fd);
+
+ return 0;
+
+error:
+ if (fd >= 0)
+ close(fd);
+ return -1;
+}
+
/* Read PCI config space. */
int rte_eal_pci_read_config(const struct rte_pci_device *dev,
void *buf, size_t len, off_t offset)
struct rte_pci_driver;
struct rte_pci_device;
+/**
+ * Update a pci device object by asking the kernel for the latest information.
+ *
+ * This function is private to EAL.
+ *
+ * @param addr
+ * The PCI Bus-Device-Function address to look for
+ * @return
+ * - 0 on success.
+ * - negative on error.
+ */
+int pci_update_device(const struct rte_pci_addr *addr);
+
/**
* Unbind kernel driver for this device
*
#include <stdint.h>
#include <inttypes.h>
+#include <rte_debug.h>
#include <rte_interrupts.h>
TAILQ_HEAD(pci_device_list, rte_pci_device); /**< PCI devices in D-linked Q. */
/** Formatting string for PCI device identifier: Ex: 0000:00:01.0 */
#define PCI_PRI_FMT "%.4" PRIx16 ":%.2" PRIx8 ":%.2" PRIx8 ".%" PRIx8
+#define PCI_PRI_STR_SIZE sizeof("XXXX:XX:XX.X")
/** Short formatting string, without domain, for PCI device: Ex: 00:01.0 */
#define PCI_SHORT_PRI_FMT "%.2" PRIx8 ":%.2" PRIx8 ".%" PRIx8
}
#undef GET_PCIADDR_FIELD
+/**
+ * Utility function to write a pci device name, this device name can later be
+ * used to retrieve the corresponding rte_pci_addr using eal_parse_pci_*
+ * BDF helpers.
+ *
+ * @param addr
+ * The PCI Bus-Device-Function address
+ * @param output
+ * The output buffer string
+ * @param size
+ * The output buffer size
+ */
+static inline void
+rte_eal_pci_device_name(const struct rte_pci_addr *addr,
+ char *output, size_t size)
+{
+ RTE_VERIFY(size >= PCI_PRI_STR_SIZE);
+ RTE_VERIFY(snprintf(output, size, PCI_PRI_FMT,
+ addr->domain, addr->bus,
+ addr->devid, addr->function) >= 0);
+}
+
/* Compare two PCI device addresses. */
/**
* Utility function to compare two PCI device addresses.
return 0;
}
+int
+pci_update_device(const struct rte_pci_addr *addr)
+{
+ char filename[PATH_MAX];
+
+ snprintf(filename, sizeof(filename), "%s/" PCI_PRI_FMT,
+ pci_get_sysfs_path(), addr->domain, addr->bus, addr->devid,
+ addr->function);
+
+ return pci_scan_one(filename, addr->domain, addr->bus, addr->devid,
+ addr->function);
+}
+
/*
* split up a pci address into its constituent parts.
*/
return eth_dev;
}
-static int
-rte_eth_dev_create_unique_device_name(char *name, size_t size,
- struct rte_pci_device *pci_dev)
-{
- int ret;
-
- ret = snprintf(name, size, "%d:%d.%d",
- pci_dev->addr.bus, pci_dev->addr.devid,
- pci_dev->addr.function);
- if (ret < 0)
- return ret;
- return 0;
-}
-
int
rte_eth_dev_release_port(struct rte_eth_dev *eth_dev)
{
eth_drv = (struct eth_driver *)pci_drv;
- /* Create unique Ethernet device name using PCI address */
- rte_eth_dev_create_unique_device_name(ethdev_name,
- sizeof(ethdev_name), pci_dev);
+ rte_eal_pci_device_name(&pci_dev->addr, ethdev_name,
+ sizeof(ethdev_name));
eth_dev = rte_eth_dev_allocate(ethdev_name, RTE_ETH_DEV_PCI);
if (eth_dev == NULL)
if (pci_dev == NULL)
return -EINVAL;
- /* Create unique Ethernet device name using PCI address */
- rte_eth_dev_create_unique_device_name(ethdev_name,
- sizeof(ethdev_name), pci_dev);
+ rte_eal_pci_device_name(&pci_dev->addr, ethdev_name,
+ sizeof(ethdev_name));
eth_dev = rte_eth_dev_allocated(ethdev_name);
if (eth_dev == NULL)