static inline int bond_pci_addr_cmp(const struct rte_device *dev, const void *_pci_addr) { struct rte_pci_device *pdev; const struct rte_pci_addr *paddr = _pci_addr; pdev = RTE_DEV_TO_PCI(*(struct rte_device **)(void *)&dev); return rte_eal_compare_pci_addr(&pdev->addr, paddr); }
static int pci_uio_map_secondary(struct rte_pci_device *dev) { int fd, i; struct mapped_pci_resource *uio_res; struct mapped_pci_res_list *uio_res_list = RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list); TAILQ_FOREACH(uio_res, uio_res_list, next) { /* skip this element if it doesn't match our PCI address */ if (rte_eal_compare_pci_addr(&uio_res->pci_addr, &dev->addr)) continue; for (i = 0; i != uio_res->nb_maps; i++) { /* * open devname, to mmap it */ fd = open(uio_res->maps[i].path, O_RDWR); if (fd < 0) { RTE_LOG(ERR, EAL, "Cannot open %s: %s\n", uio_res->maps[i].path, strerror(errno)); return -1; } void *mapaddr = pci_map_resource(uio_res->maps[i].addr, fd, (off_t)uio_res->maps[i].offset, (size_t)uio_res->maps[i].size, 0); if (mapaddr != uio_res->maps[i].addr) { if (mapaddr == MAP_FAILED) RTE_LOG(ERR, EAL, "Cannot mmap device resource file %s: %s\n", uio_res->maps[i].path, strerror(errno)); else RTE_LOG(ERR, EAL, "Cannot mmap device resource file %s to address: %p\n", uio_res->maps[i].path, uio_res->maps[i].addr); close(fd); return -1; } /* fd is not needed in slave process, close it */ close(fd); } return 0; } RTE_LOG(ERR, EAL, "Cannot find resource for device\n"); return 1; }
static struct mapped_pci_resource * pci_uio_find_resource(struct rte_pci_device *dev) { struct mapped_pci_resource *uio_res; struct mapped_pci_res_list *uio_res_list = RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list); if (dev == NULL) return NULL; TAILQ_FOREACH(uio_res, uio_res_list, next) { /* skip this element if it doesn't match our PCI address */ if (!rte_eal_compare_pci_addr(&uio_res->pci_addr, &dev->addr)) return uio_res; } return NULL; }