From 35b3313e322b28a293eaaddf362844f934b9f436 Mon Sep 17 00:00:00 2001 From: Tetsuya Mukawa Date: Wed, 8 Jul 2015 19:34:52 +0900 Subject: [PATCH] pci: merge mapping functions for linux and bsd The patch consolidates below functions, and implemented in common eal code. - pci_map_device() - pci_unmap_device() Signed-off-by: Tetsuya Mukawa Acked-by: Bernard Iremonger Acked-by: David Marchand --- lib/librte_eal/bsdapp/eal/eal_pci.c | 3 ++ lib/librte_eal/common/eal_common_pci.c | 57 +++++++++++++++++++++++++ lib/librte_eal/common/eal_private.h | 19 +++++++++ lib/librte_eal/common/include/rte_pci.h | 1 + lib/librte_eal/linuxapp/eal/eal_pci.c | 53 ----------------------- lib/librte_ether/rte_ethdev.c | 1 + 6 files changed, 81 insertions(+), 53 deletions(-) diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c b/lib/librte_eal/bsdapp/eal/eal_pci.c index 51b1afd14a..4d89746d1b 100644 --- a/lib/librte_eal/bsdapp/eal/eal_pci.c +++ b/lib/librte_eal/bsdapp/eal/eal_pci.c @@ -241,6 +241,9 @@ pci_scan_one(int dev_pci_fd, struct pci_conf *conf) /* FreeBSD has no NUMA support (yet) */ dev->numa_node = 0; + /* FreeBSD has only one pass through driver */ + dev->kdrv = RTE_KDRV_NIC_UIO; + /* parse resources */ switch (conf->pc_hdr & PCIM_HDRTYPE) { case PCIM_HDRTYPE_NORMAL: diff --git a/lib/librte_eal/common/eal_common_pci.c b/lib/librte_eal/common/eal_common_pci.c index 81b8fd63cc..c0be2929d9 100644 --- a/lib/librte_eal/common/eal_common_pci.c +++ b/lib/librte_eal/common/eal_common_pci.c @@ -137,6 +137,63 @@ pci_unmap_resource(void *requested_addr, size_t size) requested_addr); } +/* Map pci device */ +int +pci_map_device(struct rte_pci_device *dev) +{ + int ret = -1; + + /* try mapping the NIC resources using VFIO if it exists */ + switch (dev->kdrv) { + case RTE_KDRV_VFIO: +#ifdef VFIO_PRESENT + if (pci_vfio_is_enabled()) + ret = pci_vfio_map_resource(dev); +#endif + break; + case RTE_KDRV_IGB_UIO: + case RTE_KDRV_UIO_GENERIC: + case RTE_KDRV_NIC_UIO: + /* map resources for devices that use uio */ + ret = pci_uio_map_resource(dev); + break; + default: + RTE_LOG(DEBUG, EAL, " Not managed by a supported kernel driver," + " skipped\n"); + ret = 1; + break; + } + + return ret; +} + +#ifdef RTE_LIBRTE_EAL_HOTPLUG +/* Unmap pci device */ +void +pci_unmap_device(struct rte_pci_device *dev) +{ + if (dev == NULL) + return; + + /* try unmapping the NIC resources using VFIO if it exists */ + switch (dev->kdrv) { + case RTE_KDRV_VFIO: + RTE_LOG(ERR, EAL, "Hotplug doesn't support vfio yet\n"); + break; + case RTE_KDRV_IGB_UIO: + case RTE_KDRV_UIO_GENERIC: + case RTE_KDRV_NIC_UIO: + /* unmap resources for devices that use uio */ + pci_uio_unmap_resource(dev); + break; + default: + RTE_LOG(DEBUG, EAL, " Not managed by a supported kernel driver," + " skipped\n"); + break; + } +} +#endif /* RTE_LIBRTE_EAL_HOTPLUG */ + /* * If vendor/device ID match, call the devinit() function of all * registered driver for the given device. Return -1 if initialization diff --git a/lib/librte_eal/common/eal_private.h b/lib/librte_eal/common/eal_private.h index d41cbe1750..36115a08f1 100644 --- a/lib/librte_eal/common/eal_private.h +++ b/lib/librte_eal/common/eal_private.h @@ -154,6 +154,25 @@ int rte_eal_ivshmem_obj_init(void); struct rte_pci_driver; struct rte_pci_device; +/** + * Map this device + * + * This function is private to EAL. + * + * @return + * 0 on success, negative on error + */ +int pci_map_device(struct rte_pci_device *dev); + +#ifdef RTE_LIBRTE_EAL_HOTPLUG +/** + * Unmap this device + * + * This function is private to EAL. + */ +void pci_unmap_device(struct rte_pci_device *dev); +#endif /* RTE_LIBRTE_EAL_HOTPLUG */ + /** * Map the PCI resource of a PCI device in virtual memory * diff --git a/lib/librte_eal/common/include/rte_pci.h b/lib/librte_eal/common/include/rte_pci.h index 0f16f2cd7a..6f80b19f12 100644 --- a/lib/librte_eal/common/include/rte_pci.h +++ b/lib/librte_eal/common/include/rte_pci.h @@ -148,6 +148,7 @@ enum rte_kernel_driver { RTE_KDRV_IGB_UIO, RTE_KDRV_VFIO, RTE_KDRV_UIO_GENERIC, + RTE_KDRV_NIC_UIO, }; /** diff --git a/lib/librte_eal/linuxapp/eal/eal_pci.c b/lib/librte_eal/linuxapp/eal/eal_pci.c index fc99eaa36b..7e8df7dd17 100644 --- a/lib/librte_eal/linuxapp/eal/eal_pci.c +++ b/lib/librte_eal/linuxapp/eal/eal_pci.c @@ -522,59 +522,6 @@ pci_config_space_set(struct rte_pci_device *dev) } #endif -static int -pci_map_device(struct rte_pci_device *dev) -{ - int ret = -1; - - /* try mapping the NIC resources using VFIO if it exists */ - switch (dev->kdrv) { - case RTE_KDRV_VFIO: -#ifdef VFIO_PRESENT - if (pci_vfio_is_enabled()) - ret = pci_vfio_map_resource(dev); -#endif - break; - case RTE_KDRV_IGB_UIO: - case RTE_KDRV_UIO_GENERIC: - /* map resources for devices that use uio */ - ret = pci_uio_map_resource(dev); - break; - default: - RTE_LOG(DEBUG, EAL, " Not managed by a supported kernel driver," - " skipped\n"); - ret = 1; - break; - } - - return ret; -} - -#ifdef RTE_LIBRTE_EAL_HOTPLUG -static void -pci_unmap_device(struct rte_pci_device *dev) -{ - if (dev == NULL) - return; - - /* try unmapping the NIC resources using VFIO if it exists */ - switch (dev->kdrv) { - case RTE_KDRV_VFIO: - RTE_LOG(ERR, EAL, "Hotplug doesn't support vfio yet\n"); - break; - case RTE_KDRV_IGB_UIO: - case RTE_KDRV_UIO_GENERIC: - /* unmap resources for devices that use uio */ - pci_uio_unmap_resource(dev); - break; - default: - RTE_LOG(DEBUG, EAL, " Not managed by a supported kernel driver," - " skipped\n"); - break; - } -} -#endif /* RTE_LIBRTE_EAL_HOTPLUG */ - /* * If vendor/device ID match, call the devinit() function of the * driver. diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c index 34ac677af7..7c133ef0ce 100644 --- a/lib/librte_ether/rte_ethdev.c +++ b/lib/librte_ether/rte_ethdev.c @@ -527,6 +527,7 @@ rte_eth_dev_is_detachable(uint8_t port_id) switch (rte_eth_devices[port_id].pci_dev->kdrv) { case RTE_KDRV_IGB_UIO: case RTE_KDRV_UIO_GENERIC: + case RTE_KDRV_NIC_UIO: break; case RTE_KDRV_VFIO: default: -- 2.20.1