/** * Parses a port identifier string to a port id by pci address, then by name, * and finally port id. */ static inline int parse_port_id(const char *port_str) { struct rte_pci_addr dev_addr; int port_id; /* try parsing as pci address, physical devices */ if (eal_parse_pci_DomBDF(port_str, &dev_addr) == 0) { port_id = find_port_id_by_pci_addr(&dev_addr); if (port_id < 0) return -1; } else { /* try parsing as device name, virtual devices */ port_id = find_port_id_by_dev_name(port_str); if (port_id < 0) { char *end; errno = 0; /* try parsing as port id */ port_id = strtol(port_str, &end, 10); if (*end != 0 || errno != 0) return -1; } } if (port_id < 0 || port_id > RTE_MAX_ETHPORTS) { RTE_LOG(ERR, PMD, "Invalid slave port value (%s) specified.\n", port_str); return -1; } return port_id; }
/** * Parses a port identifier string to a port id by pci address, then by name, * and finally port id. */ static inline int parse_port_id(const char *port_str) { struct rte_pci_addr dev_addr; struct rte_bus *pci_bus; struct rte_device *dev; int port_id; pci_bus = rte_bus_find_by_name("pci"); if (pci_bus == NULL) { RTE_LOG(ERR, PMD, "unable to find PCI bus\n"); return -1; } /* try parsing as pci address, physical devices */ if (pci_bus->parse(port_str, &dev_addr) == 0) { dev = pci_bus->find_device(NULL, bond_pci_addr_cmp, &dev_addr); if (dev == NULL) { RTE_LOG(ERR, PMD, "unable to find PCI device\n"); return -1; } port_id = find_port_id_by_pci_addr(&dev_addr); if (port_id < 0) return -1; } else { /* try parsing as device name, virtual devices */ port_id = find_port_id_by_dev_name(port_str); if (port_id < 0) { char *end; errno = 0; /* try parsing as port id */ port_id = strtol(port_str, &end, 10); if (*end != 0 || errno != 0) return -1; } } if (port_id < 0 || port_id > RTE_MAX_ETHPORTS) { RTE_BOND_LOG(ERR, "Slave port specified (%s) outside expected range", port_str); return -1; } return port_id; }