* [dpdk-dev] [PATCH] eal/vfio: export internal vfio functions @ 2018-03-14 8:00 Hemant Agrawal 2018-03-14 10:19 ` Burakov, Anatoly ` (2 more replies) 0 siblings, 3 replies; 27+ messages in thread From: Hemant Agrawal @ 2018-03-14 8:00 UTC (permalink / raw) To: dev, bruce.richardson; +Cc: thomas, anatoly.burakov, xiao.w.wang, junjie.j.chen This patch moves some of the internal vfio functions from eal_vfio.h to rte_vfio.h for common uses with "rte_" prefix. This patch also change the FSLMC bus usages from the internal VFIO functions to external ones with "rte_" prefix Signed-off-by: Hemant Agrawal <hemant.agrawal@nxp.com> --- This patch has some minor conflicts with "eal/vfio: add support for multiple container" https://dpdk.org/dev/patchwork/patch/35862/ however they can be resolved easily. drivers/bus/fslmc/Makefile | 1 - drivers/bus/fslmc/fslmc_vfio.c | 6 ++-- drivers/bus/fslmc/fslmc_vfio.h | 2 -- drivers/bus/fslmc/meson.build | 1 - lib/librte_eal/bsdapp/eal/eal.c | 20 +++++++++++ lib/librte_eal/common/include/rte_vfio.h | 47 ++++++++++++++++++++++++++ lib/librte_eal/linuxapp/eal/eal_vfio.c | 18 +++++----- lib/librte_eal/linuxapp/eal/eal_vfio.h | 21 ------------ lib/librte_eal/linuxapp/eal/eal_vfio_mp_sync.c | 4 +-- lib/librte_eal/rte_eal_version.map | 3 ++ 10 files changed, 84 insertions(+), 39 deletions(-) diff --git a/drivers/bus/fslmc/Makefile b/drivers/bus/fslmc/Makefile index 952b4c0..04814db 100644 --- a/drivers/bus/fslmc/Makefile +++ b/drivers/bus/fslmc/Makefile @@ -21,7 +21,6 @@ endif CFLAGS += -I$(RTE_SDK)/drivers/bus/fslmc CFLAGS += -I$(RTE_SDK)/drivers/bus/fslmc/mc CFLAGS += -I$(RTE_SDK)/drivers/bus/fslmc/qbman/include -CFLAGS += -I$(RTE_SDK)/lib/librte_eal/linuxapp/eal CFLAGS += -I$(RTE_SDK)/lib/librte_eal/common LDLIBS += -lrte_eal -lrte_mbuf -lrte_mempool -lrte_ring LDLIBS += -lrte_ethdev diff --git a/drivers/bus/fslmc/fslmc_vfio.c b/drivers/bus/fslmc/fslmc_vfio.c index e840ad6..4e1187e 100644 --- a/drivers/bus/fslmc/fslmc_vfio.c +++ b/drivers/bus/fslmc/fslmc_vfio.c @@ -94,7 +94,7 @@ fslmc_get_container_group(int *groupid) } /* get group number */ - ret = vfio_get_group_no(SYSFS_FSL_MC_DEVICES, g_container, groupid); + ret = rte_vfio_get_group_no(SYSFS_FSL_MC_DEVICES, g_container, groupid); if (ret <= 0) { FSLMC_VFIO_LOG(ERR, "Unable to find %s IOMMU group", g_container); @@ -128,7 +128,7 @@ vfio_connect_container(void) } /* Opens main vfio file descriptor which represents the "container" */ - fd = vfio_get_container_fd(); + fd = rte_vfio_get_container_fd(); if (fd < 0) { FSLMC_VFIO_LOG(ERR, "Failed to open VFIO container"); return -errno; @@ -627,7 +627,7 @@ fslmc_vfio_setup_group(void) } /* Get the actual group fd */ - ret = vfio_get_group_fd(groupid); + ret = rte_vfio_get_group_fd(groupid); if (ret < 0) return ret; vfio_group.fd = ret; diff --git a/drivers/bus/fslmc/fslmc_vfio.h b/drivers/bus/fslmc/fslmc_vfio.h index e8fb344..9e2c4fe 100644 --- a/drivers/bus/fslmc/fslmc_vfio.h +++ b/drivers/bus/fslmc/fslmc_vfio.h @@ -10,8 +10,6 @@ #include <rte_vfio.h> -#include "eal_vfio.h" - #define DPAA2_MC_DPNI_DEVID 7 #define DPAA2_MC_DPSECI_DEVID 3 #define DPAA2_MC_DPCON_DEVID 5 diff --git a/drivers/bus/fslmc/meson.build b/drivers/bus/fslmc/meson.build index e94340e..78f9d92 100644 --- a/drivers/bus/fslmc/meson.build +++ b/drivers/bus/fslmc/meson.build @@ -22,6 +22,5 @@ sources = files('fslmc_bus.c', allow_experimental_apis = true -includes += include_directories('../../../lib/librte_eal/linuxapp/eal') includes += include_directories('mc', 'qbman/include', 'portal') cflags += ['-D_GNU_SOURCE'] diff --git a/lib/librte_eal/bsdapp/eal/eal.c b/lib/librte_eal/bsdapp/eal/eal.c index 4eafcb5..29cac28 100644 --- a/lib/librte_eal/bsdapp/eal/eal.c +++ b/lib/librte_eal/bsdapp/eal/eal.c @@ -781,3 +781,23 @@ int rte_vfio_clear_group(__rte_unused int vfio_group_fd) { return 0; } + +int __rte_experimental +rte_vfio_get_group_no(__rte_unused const char *sysfs_base, + __rte_unused const char *dev_addr, + __rte_unused int *iommu_group_no) +{ + return -1; +} + +int __rte_experimental +rte_vfio_get_container_fd(void) +{ + return -1; +} + +int __rte_experimental +rte_vfio_get_group_fd(__rte_unused int iommu_group_no) +{ + return -1; +} diff --git a/lib/librte_eal/common/include/rte_vfio.h b/lib/librte_eal/common/include/rte_vfio.h index e981a62..a9665c6 100644 --- a/lib/librte_eal/common/include/rte_vfio.h +++ b/lib/librte_eal/common/include/rte_vfio.h @@ -28,6 +28,12 @@ #define VFIO_NOIOMMU_MODE \ "/sys/module/vfio/parameters/enable_unsafe_noiommu_mode" +#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 5, 0) +#define RTE_VFIO_NOIOMMU 8 +#else +#define RTE_VFIO_NOIOMMU VFIO_NOIOMMU_IOMMU +#endif + /** * Setup vfio_cfg for the device identified by its address. * It discovers the configured I/O MMU groups or sets a new one for the device. @@ -123,6 +129,47 @@ int rte_vfio_noiommu_is_enabled(void); int rte_vfio_clear_group(int vfio_group_fd); +/** + * Parse IOMMU group number for a device + * + * This function is only relevant to linux and will return + * an error on BSD. + * + * @return + * 1 on success + * 0 for non-existent group + * <0 for errors + */ +int __rte_experimental +rte_vfio_get_group_no(const char *sysfs_base, + const char *dev_addr, int *iommu_group_no); + +/** + * Open VFIO container fd or get an existing one + * + * This function is only relevant to linux and will return + * an error on BSD. + * + * @return + * > 0 container fd + * < 0 for errors + */ +int __rte_experimental +rte_vfio_get_container_fd(void); + +/** + * Open VFIO group fd or get an existing one + * + * This function is only relevant to linux and will return + * an error on BSD. + * + * @return + * > 0 group fd + * < 0 for errors + */ +int __rte_experimental +rte_vfio_get_group_fd(int iommu_group_no); + #endif /* VFIO_PRESENT */ #endif /* _RTE_VFIO_H_ */ diff --git a/lib/librte_eal/linuxapp/eal/eal_vfio.c b/lib/librte_eal/linuxapp/eal/eal_vfio.c index e44ae4d..3dc2c18 100644 --- a/lib/librte_eal/linuxapp/eal/eal_vfio.c +++ b/lib/librte_eal/linuxapp/eal/eal_vfio.c @@ -36,7 +36,7 @@ static const struct vfio_iommu_type iommu_types[] = { }; int -vfio_get_group_fd(int iommu_group_no) +rte_vfio_get_group_fd(int iommu_group_no) { int i; int vfio_group_fd; @@ -266,7 +266,7 @@ rte_vfio_setup_device(const char *sysfs_base, const char *dev_addr, int ret; /* get group number */ - ret = vfio_get_group_no(sysfs_base, dev_addr, &iommu_group_no); + ret = rte_vfio_get_group_no(sysfs_base, dev_addr, &iommu_group_no); if (ret == 0) { RTE_LOG(WARNING, EAL, " %s not managed by VFIO driver, skipping\n", dev_addr); @@ -278,7 +278,7 @@ rte_vfio_setup_device(const char *sysfs_base, const char *dev_addr, return -1; /* get the actual group fd */ - vfio_group_fd = vfio_get_group_fd(iommu_group_no); + vfio_group_fd = rte_vfio_get_group_fd(iommu_group_no); if (vfio_group_fd < 0) return -1; @@ -398,7 +398,7 @@ rte_vfio_release_device(const char *sysfs_base, const char *dev_addr, int ret; /* get group number */ - ret = vfio_get_group_no(sysfs_base, dev_addr, &iommu_group_no); + ret = rte_vfio_get_group_no(sysfs_base, dev_addr, &iommu_group_no); if (ret <= 0) { RTE_LOG(WARNING, EAL, " %s not managed by VFIO driver\n", dev_addr); @@ -407,9 +407,9 @@ rte_vfio_release_device(const char *sysfs_base, const char *dev_addr, } /* get the actual group fd */ - vfio_group_fd = vfio_get_group_fd(iommu_group_no); + vfio_group_fd = rte_vfio_get_group_fd(iommu_group_no); if (vfio_group_fd <= 0) { - RTE_LOG(INFO, EAL, "vfio_get_group_fd failed for %s\n", + RTE_LOG(INFO, EAL, "rte_vfio_get_group_fd failed for %s\n", dev_addr); return -1; } @@ -480,7 +480,7 @@ rte_vfio_enable(const char *modname) return 0; } - vfio_cfg.vfio_container_fd = vfio_get_container_fd(); + vfio_cfg.vfio_container_fd = rte_vfio_get_container_fd(); /* check if we have VFIO driver enabled */ if (vfio_cfg.vfio_container_fd != -1) { @@ -558,7 +558,7 @@ vfio_has_supported_extensions(int vfio_container_fd) } int -vfio_get_container_fd(void) +rte_vfio_get_container_fd(void) { int ret, vfio_container_fd; @@ -622,7 +622,7 @@ vfio_get_container_fd(void) } int -vfio_get_group_no(const char *sysfs_base, +rte_vfio_get_group_no(const char *sysfs_base, const char *dev_addr, int *iommu_group_no) { char linkname[PATH_MAX]; diff --git a/lib/librte_eal/linuxapp/eal/eal_vfio.h b/lib/librte_eal/linuxapp/eal/eal_vfio.h index 8059577..c72b76c 100644 --- a/lib/librte_eal/linuxapp/eal/eal_vfio.h +++ b/lib/librte_eal/linuxapp/eal/eal_vfio.h @@ -79,12 +79,6 @@ struct vfio_iommu_spapr_tce_info { #define RTE_VFIO_SPAPR VFIO_SPAPR_TCE_v2_IOMMU #endif -#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 5, 0) -#define RTE_VFIO_NOIOMMU 8 -#else -#define RTE_VFIO_NOIOMMU VFIO_NOIOMMU_IOMMU -#endif - #define VFIO_MAX_GROUPS RTE_MAX_VFIO_GROUPS /* @@ -133,21 +127,6 @@ vfio_set_iommu_type(int vfio_container_fd); int vfio_has_supported_extensions(int vfio_container_fd); -/* open container fd or get an existing one */ -int -vfio_get_container_fd(void); - -/* parse IOMMU group number for a device - * returns 1 on success, -1 for errors, 0 for non-existent group - */ -int -vfio_get_group_no(const char *sysfs_base, - const char *dev_addr, int *iommu_group_no); - -/* open group fd or get an existing one */ -int -vfio_get_group_fd(int iommu_group_no); - int vfio_mp_sync_setup(void); #define SOCKET_REQ_CONTAINER 0x100 diff --git a/lib/librte_eal/linuxapp/eal/eal_vfio_mp_sync.c b/lib/librte_eal/linuxapp/eal/eal_vfio_mp_sync.c index 7cc3c15..e19b571 100644 --- a/lib/librte_eal/linuxapp/eal/eal_vfio_mp_sync.c +++ b/lib/librte_eal/linuxapp/eal/eal_vfio_mp_sync.c @@ -267,7 +267,7 @@ vfio_mp_sync_thread(void __rte_unused * arg) switch (ret) { case SOCKET_REQ_CONTAINER: - fd = vfio_get_container_fd(); + fd = rte_vfio_get_container_fd(); if (fd < 0) vfio_mp_sync_send_request(conn_sock, SOCKET_ERR); else @@ -283,7 +283,7 @@ vfio_mp_sync_thread(void __rte_unused * arg) continue; } - fd = vfio_get_group_fd(vfio_data); + fd = rte_vfio_get_group_fd(vfio_data); if (fd < 0) vfio_mp_sync_send_request(conn_sock, SOCKET_ERR); diff --git a/lib/librte_eal/rte_eal_version.map b/lib/librte_eal/rte_eal_version.map index d123602..7522b2b 100644 --- a/lib/librte_eal/rte_eal_version.map +++ b/lib/librte_eal/rte_eal_version.map @@ -254,5 +254,8 @@ EXPERIMENTAL { rte_service_set_runstate_mapped_check; rte_service_set_stats_enable; rte_service_start_with_defaults; + rte_vfio_get_group_no; + rte_vfio_get_container_fd; + rte_vfio_get_group_fd; } DPDK_18.02; -- 2.7.4 ^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [dpdk-dev] [PATCH] eal/vfio: export internal vfio functions 2018-03-14 8:00 [dpdk-dev] [PATCH] eal/vfio: export internal vfio functions Hemant Agrawal @ 2018-03-14 10:19 ` Burakov, Anatoly 2018-03-27 15:53 ` Thomas Monjalon 2018-04-02 8:36 ` [dpdk-dev] [PATCH v2] " Hemant Agrawal 2 siblings, 0 replies; 27+ messages in thread From: Burakov, Anatoly @ 2018-03-14 10:19 UTC (permalink / raw) To: Hemant Agrawal, dev, bruce.richardson Cc: thomas, anatoly.burakov, xiao.w.wang, junjie.j.chen On 14-Mar-18 8:00 AM, Hemant Agrawal wrote: > This patch moves some of the internal vfio functions from > eal_vfio.h to rte_vfio.h for common uses with "rte_" prefix. > > This patch also change the FSLMC bus usages from the internal > VFIO functions to external ones with "rte_" prefix > > Signed-off-by: Hemant Agrawal <hemant.agrawal@nxp.com> > --- VFIO parts seem OK to me. Acked-by: Anatoly Burakov <anatoly.burakov@intel.com> -- Thanks, Anatoly ^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [dpdk-dev] [PATCH] eal/vfio: export internal vfio functions 2018-03-14 8:00 [dpdk-dev] [PATCH] eal/vfio: export internal vfio functions Hemant Agrawal 2018-03-14 10:19 ` Burakov, Anatoly @ 2018-03-27 15:53 ` Thomas Monjalon 2018-04-03 6:27 ` Hemant Agrawal 2018-04-02 8:36 ` [dpdk-dev] [PATCH v2] " Hemant Agrawal 2 siblings, 1 reply; 27+ messages in thread From: Thomas Monjalon @ 2018-03-27 15:53 UTC (permalink / raw) To: Hemant Agrawal Cc: dev, bruce.richardson, anatoly.burakov, xiao.w.wang, junjie.j.chen 14/03/2018 09:00, Hemant Agrawal: > This patch moves some of the internal vfio functions from > eal_vfio.h to rte_vfio.h for common uses with "rte_" prefix. > > This patch also change the FSLMC bus usages from the internal > VFIO functions to external ones with "rte_" prefix > > Signed-off-by: Hemant Agrawal <hemant.agrawal@nxp.com> > --- > --- a/lib/librte_eal/common/include/rte_vfio.h > +++ b/lib/librte_eal/common/include/rte_vfio.h > @@ -28,6 +28,12 @@ > +#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 5, 0) > +#define RTE_VFIO_NOIOMMU 8 > +#else > +#define RTE_VFIO_NOIOMMU VFIO_NOIOMMU_IOMMU > +#endif I know this is just a move of an existing code, but do you know why this check is against a version number (4.5.0), instead of #ifdef VFIO_NOIOMMU_IOMMU which would be backport-safe? > +/** > + * Parse IOMMU group number for a device > + * > + * This function is only relevant to linux and will return > + * an error on BSD. > + * > + * @return > + * 1 on success > + * 0 for non-existent group > + * <0 for errors > + */ > +int __rte_experimental > +rte_vfio_get_group_no(const char *sysfs_base, > + const char *dev_addr, int *iommu_group_no); > + > +/** > + * Open VFIO container fd or get an existing one > + * > + * This function is only relevant to linux and will return > + * an error on BSD. > + * > + * @return > + * > 0 container fd > + * < 0 for errors > + */ > +int __rte_experimental > +rte_vfio_get_container_fd(void); > + > +/** > + * Open VFIO group fd or get an existing one > + * > + * This function is only relevant to linux and will return > + * an error on BSD. > + * > + * @return > + * > 0 group fd > + * < 0 for errors > + */ > +int __rte_experimental > +rte_vfio_get_group_fd(int iommu_group_no); All these new functions should have some @param documentation. This file is not included in doxygen, probably because @file is missing. About the naming, are you sure about "group_no" instead of "group_num"? > --- a/lib/librte_eal/rte_eal_version.map > +++ b/lib/librte_eal/rte_eal_version.map > @@ -254,5 +254,8 @@ EXPERIMENTAL { > rte_service_set_runstate_mapped_check; > rte_service_set_stats_enable; > rte_service_start_with_defaults; > + rte_vfio_get_group_no; > + rte_vfio_get_container_fd; > + rte_vfio_get_group_fd; Please indent with tabs. ^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [dpdk-dev] [PATCH] eal/vfio: export internal vfio functions 2018-03-27 15:53 ` Thomas Monjalon @ 2018-04-03 6:27 ` Hemant Agrawal 2018-04-03 7:34 ` Thomas Monjalon 0 siblings, 1 reply; 27+ messages in thread From: Hemant Agrawal @ 2018-04-03 6:27 UTC (permalink / raw) To: Thomas Monjalon, Hemant Agrawal Cc: dev, bruce.richardson, anatoly.burakov, xiao.w.wang, junjie.j.chen Hi Thomas, On 3/27/2018 9:23 PM, Thomas Monjalon wrote: > 14/03/2018 09:00, Hemant Agrawal: >> This patch moves some of the internal vfio functions from >> eal_vfio.h to rte_vfio.h for common uses with "rte_" prefix. >> >> This patch also change the FSLMC bus usages from the internal >> VFIO functions to external ones with "rte_" prefix >> >> Signed-off-by: Hemant Agrawal <hemant.agrawal@nxp.com> >> --- >> --- a/lib/librte_eal/common/include/rte_vfio.h >> +++ b/lib/librte_eal/common/include/rte_vfio.h >> @@ -28,6 +28,12 @@ >> +#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 5, 0) >> +#define RTE_VFIO_NOIOMMU 8 >> +#else >> +#define RTE_VFIO_NOIOMMU VFIO_NOIOMMU_IOMMU >> +#endif > I know this is just a move of an existing code, > but do you know why this check is against a version number (4.5.0), > instead of #ifdef VFIO_NOIOMMU_IOMMU which would be backport-safe? Agreed. please check it in v3. >> +/** >> + * Parse IOMMU group number for a device >> + * >> + * This function is only relevant to linux and will return >> + * an error on BSD. >> + * >> + * @return >> + * 1 on success >> + * 0 for non-existent group >> + * <0 for errors >> + */ >> +int __rte_experimental >> +rte_vfio_get_group_no(const char *sysfs_base, >> + const char *dev_addr, int *iommu_group_no); >> + >> +/** >> + * Open VFIO container fd or get an existing one >> + * >> + * This function is only relevant to linux and will return >> + * an error on BSD. >> + * >> + * @return >> + * > 0 container fd >> + * < 0 for errors >> + */ >> +int __rte_experimental >> +rte_vfio_get_container_fd(void); >> + >> +/** >> + * Open VFIO group fd or get an existing one >> + * >> + * This function is only relevant to linux and will return >> + * an error on BSD. >> + * >> + * @return >> + * > 0 group fd >> + * < 0 for errors >> + */ >> +int __rte_experimental >> +rte_vfio_get_group_fd(int iommu_group_no); > All these new functions should have some @param documentation. added the @param > This file is not included in doxygen, probably because @file is missing. most of these functions are internal functions. do you think we should add it in doxygen as well? > > About the naming, are you sure about "group_no" instead of "group_num"? Agree, but this is already in many places. I feel this change will be unnecessary. > >> --- a/lib/librte_eal/rte_eal_version.map >> +++ b/lib/librte_eal/rte_eal_version.map >> @@ -254,5 +254,8 @@ EXPERIMENTAL { >> rte_service_set_runstate_mapped_check; >> rte_service_set_stats_enable; >> rte_service_start_with_defaults; >> + rte_vfio_get_group_no; >> + rte_vfio_get_container_fd; >> + rte_vfio_get_group_fd; > Please indent with tabs. > > done in v3 ^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [dpdk-dev] [PATCH] eal/vfio: export internal vfio functions 2018-04-03 6:27 ` Hemant Agrawal @ 2018-04-03 7:34 ` Thomas Monjalon 2018-04-03 8:34 ` Hemant Agrawal 0 siblings, 1 reply; 27+ messages in thread From: Thomas Monjalon @ 2018-04-03 7:34 UTC (permalink / raw) To: Hemant Agrawal Cc: dev, bruce.richardson, anatoly.burakov, xiao.w.wang, junjie.j.chen 03/04/2018 08:27, Hemant Agrawal: > On 3/27/2018 9:23 PM, Thomas Monjalon wrote: > > 14/03/2018 09:00, Hemant Agrawal: > >> This patch moves some of the internal vfio functions from > >> eal_vfio.h to rte_vfio.h for common uses with "rte_" prefix. > >> > >> This patch also change the FSLMC bus usages from the internal > >> VFIO functions to external ones with "rte_" prefix > >> > >> Signed-off-by: Hemant Agrawal <hemant.agrawal@nxp.com> > >> --- > >> --- a/lib/librte_eal/common/include/rte_vfio.h > >> +++ b/lib/librte_eal/common/include/rte_vfio.h > >> @@ -28,6 +28,12 @@ > >> +#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 5, 0) > >> +#define RTE_VFIO_NOIOMMU 8 > >> +#else > >> +#define RTE_VFIO_NOIOMMU VFIO_NOIOMMU_IOMMU > >> +#endif > > I know this is just a move of an existing code, > > but do you know why this check is against a version number (4.5.0), > > instead of #ifdef VFIO_NOIOMMU_IOMMU which would be backport-safe? > Agreed. please check it in v3. Yes, in v2. > >> +/** > >> + * Parse IOMMU group number for a device > >> + * > >> + * This function is only relevant to linux and will return > >> + * an error on BSD. > >> + * > >> + * @return > >> + * 1 on success > >> + * 0 for non-existent group > >> + * <0 for errors > >> + */ > >> +int __rte_experimental > >> +rte_vfio_get_group_no(const char *sysfs_base, > >> + const char *dev_addr, int *iommu_group_no); > >> + > >> +/** > >> + * Open VFIO container fd or get an existing one > >> + * > >> + * This function is only relevant to linux and will return > >> + * an error on BSD. > >> + * > >> + * @return > >> + * > 0 container fd > >> + * < 0 for errors > >> + */ > >> +int __rte_experimental > >> +rte_vfio_get_container_fd(void); > >> + > >> +/** > >> + * Open VFIO group fd or get an existing one > >> + * > >> + * This function is only relevant to linux and will return > >> + * an error on BSD. > >> + * > >> + * @return > >> + * > 0 group fd > >> + * < 0 for errors > >> + */ > >> +int __rte_experimental > >> +rte_vfio_get_group_fd(int iommu_group_no); > > > > All these new functions should have some @param documentation. > > added the @param > > > This file is not included in doxygen, probably because @file is missing. > > most of these functions are internal functions. do you think we should > add it in doxygen as well? I think yes. It is an exported header of EAL. The @file is missing to make it visible in doxygen. > > About the naming, are you sure about "group_no" instead of "group_num"? > > Agree, but this is already in many places. I feel this change will be > unnecessary. I don't see any other function using "_no". What about naming the function "rte_vfio_get_group_no" as "rte_vfio_get_group_num"? ^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [dpdk-dev] [PATCH] eal/vfio: export internal vfio functions 2018-04-03 7:34 ` Thomas Monjalon @ 2018-04-03 8:34 ` Hemant Agrawal 0 siblings, 0 replies; 27+ messages in thread From: Hemant Agrawal @ 2018-04-03 8:34 UTC (permalink / raw) To: Thomas Monjalon, Hemant Agrawal Cc: dev, bruce.richardson, anatoly.burakov, xiao.w.wang, junjie.j.chen On 4/3/2018 1:04 PM, Thomas Monjalon wrote: >>>> +/** >>>> + * Parse IOMMU group number for a device >>>> + * >>>> + * This function is only relevant to linux and will return >>>> + * an error on BSD. >>>> + * >>>> + * @return >>>> + * 1 on success >>>> + * 0 for non-existent group >>>> + * <0 for errors >>>> + */ >>>> +int __rte_experimental >>>> +rte_vfio_get_group_no(const char *sysfs_base, >>>> + const char *dev_addr, int *iommu_group_no); >>>> + >>>> +/** >>>> + * Open VFIO container fd or get an existing one >>>> + * >>>> + * This function is only relevant to linux and will return >>>> + * an error on BSD. >>>> + * >>>> + * @return >>>> + * > 0 container fd >>>> + * < 0 for errors >>>> + */ >>>> +int __rte_experimental >>>> +rte_vfio_get_container_fd(void); >>>> + >>>> +/** >>>> + * Open VFIO group fd or get an existing one >>>> + * >>>> + * This function is only relevant to linux and will return >>>> + * an error on BSD. >>>> + * >>>> + * @return >>>> + * > 0 group fd >>>> + * < 0 for errors >>>> + */ >>>> +int __rte_experimental >>>> +rte_vfio_get_group_fd(int iommu_group_no); >>> >>> All these new functions should have some @param documentation. >> >> added the @param >> >>> This file is not included in doxygen, probably because @file is missing. >> >> most of these functions are internal functions. do you think we should >> add it in doxygen as well? > > I think yes. It is an exported header of EAL. > The @file is missing to make it visible in doxygen. done. > >>> About the naming, are you sure about "group_no" instead of "group_num"? >> >> Agree, but this is already in many places. I feel this change will be >> unnecessary. > > I don't see any other function using "_no". > What about naming the function "rte_vfio_get_group_no" > as "rte_vfio_get_group_num"? > > done > ^ permalink raw reply [flat|nested] 27+ messages in thread
* [dpdk-dev] [PATCH v2] eal/vfio: export internal vfio functions 2018-03-14 8:00 [dpdk-dev] [PATCH] eal/vfio: export internal vfio functions Hemant Agrawal 2018-03-14 10:19 ` Burakov, Anatoly 2018-03-27 15:53 ` Thomas Monjalon @ 2018-04-02 8:36 ` Hemant Agrawal 2018-04-02 16:41 ` Thomas Monjalon 2018-04-03 8:28 ` [dpdk-dev] [PATCH v3 1/2] doc: add vfio api support Hemant Agrawal 2 siblings, 2 replies; 27+ messages in thread From: Hemant Agrawal @ 2018-04-02 8:36 UTC (permalink / raw) To: dev; +Cc: anatoly.burakov, thomas This patch moves some of the internal vfio functions from eal_vfio.h to rte_vfio.h for common uses with "rte_" prefix. This patch also change the FSLMC bus usages from the internal VFIO functions to external ones with "rte_" prefix Signed-off-by: Hemant Agrawal <hemant.agrawal@nxp.com> Acked-by: Anatoly Burakov <anatoly.burakov@intel.com> --- v2: handle Thomas's comment fix API documentation drivers/bus/fslmc/Makefile | 1 - drivers/bus/fslmc/fslmc_vfio.c | 6 +-- drivers/bus/fslmc/fslmc_vfio.h | 2 - drivers/bus/fslmc/meson.build | 1 - lib/librte_eal/bsdapp/eal/eal.c | 20 +++++++ lib/librte_eal/common/include/rte_vfio.h | 74 +++++++++++++++++++++++++- lib/librte_eal/linuxapp/eal/eal_vfio.c | 18 +++---- lib/librte_eal/linuxapp/eal/eal_vfio.h | 21 -------- lib/librte_eal/linuxapp/eal/eal_vfio_mp_sync.c | 4 +- lib/librte_eal/rte_eal_version.map | 3 ++ 10 files changed, 110 insertions(+), 40 deletions(-) diff --git a/drivers/bus/fslmc/Makefile b/drivers/bus/fslmc/Makefile index 952b4c0..04814db 100644 --- a/drivers/bus/fslmc/Makefile +++ b/drivers/bus/fslmc/Makefile @@ -21,7 +21,6 @@ endif CFLAGS += -I$(RTE_SDK)/drivers/bus/fslmc CFLAGS += -I$(RTE_SDK)/drivers/bus/fslmc/mc CFLAGS += -I$(RTE_SDK)/drivers/bus/fslmc/qbman/include -CFLAGS += -I$(RTE_SDK)/lib/librte_eal/linuxapp/eal CFLAGS += -I$(RTE_SDK)/lib/librte_eal/common LDLIBS += -lrte_eal -lrte_mbuf -lrte_mempool -lrte_ring LDLIBS += -lrte_ethdev diff --git a/drivers/bus/fslmc/fslmc_vfio.c b/drivers/bus/fslmc/fslmc_vfio.c index e840ad6..4e1187e 100644 --- a/drivers/bus/fslmc/fslmc_vfio.c +++ b/drivers/bus/fslmc/fslmc_vfio.c @@ -94,7 +94,7 @@ fslmc_get_container_group(int *groupid) } /* get group number */ - ret = vfio_get_group_no(SYSFS_FSL_MC_DEVICES, g_container, groupid); + ret = rte_vfio_get_group_no(SYSFS_FSL_MC_DEVICES, g_container, groupid); if (ret <= 0) { FSLMC_VFIO_LOG(ERR, "Unable to find %s IOMMU group", g_container); @@ -128,7 +128,7 @@ vfio_connect_container(void) } /* Opens main vfio file descriptor which represents the "container" */ - fd = vfio_get_container_fd(); + fd = rte_vfio_get_container_fd(); if (fd < 0) { FSLMC_VFIO_LOG(ERR, "Failed to open VFIO container"); return -errno; @@ -627,7 +627,7 @@ fslmc_vfio_setup_group(void) } /* Get the actual group fd */ - ret = vfio_get_group_fd(groupid); + ret = rte_vfio_get_group_fd(groupid); if (ret < 0) return ret; vfio_group.fd = ret; diff --git a/drivers/bus/fslmc/fslmc_vfio.h b/drivers/bus/fslmc/fslmc_vfio.h index e8fb344..9e2c4fe 100644 --- a/drivers/bus/fslmc/fslmc_vfio.h +++ b/drivers/bus/fslmc/fslmc_vfio.h @@ -10,8 +10,6 @@ #include <rte_vfio.h> -#include "eal_vfio.h" - #define DPAA2_MC_DPNI_DEVID 7 #define DPAA2_MC_DPSECI_DEVID 3 #define DPAA2_MC_DPCON_DEVID 5 diff --git a/drivers/bus/fslmc/meson.build b/drivers/bus/fslmc/meson.build index e94340e..78f9d92 100644 --- a/drivers/bus/fslmc/meson.build +++ b/drivers/bus/fslmc/meson.build @@ -22,6 +22,5 @@ sources = files('fslmc_bus.c', allow_experimental_apis = true -includes += include_directories('../../../lib/librte_eal/linuxapp/eal') includes += include_directories('mc', 'qbman/include', 'portal') cflags += ['-D_GNU_SOURCE'] diff --git a/lib/librte_eal/bsdapp/eal/eal.c b/lib/librte_eal/bsdapp/eal/eal.c index 4eafcb5..29cac28 100644 --- a/lib/librte_eal/bsdapp/eal/eal.c +++ b/lib/librte_eal/bsdapp/eal/eal.c @@ -781,3 +781,23 @@ int rte_vfio_clear_group(__rte_unused int vfio_group_fd) { return 0; } + +int __rte_experimental +rte_vfio_get_group_no(__rte_unused const char *sysfs_base, + __rte_unused const char *dev_addr, + __rte_unused int *iommu_group_no) +{ + return -1; +} + +int __rte_experimental +rte_vfio_get_container_fd(void) +{ + return -1; +} + +int __rte_experimental +rte_vfio_get_group_fd(__rte_unused int iommu_group_no) +{ + return -1; +} diff --git a/lib/librte_eal/common/include/rte_vfio.h b/lib/librte_eal/common/include/rte_vfio.h index 249095e..cfcc3d3 100644 --- a/lib/librte_eal/common/include/rte_vfio.h +++ b/lib/librte_eal/common/include/rte_vfio.h @@ -32,6 +32,13 @@ extern "C" { #endif +/* NOIOMMU is defined from kernel version 4.5 onwards */ +#ifdef VFIO_NOIOMMU_IOMMU +#define RTE_VFIO_NOIOMMU VFIO_NOIOMMU_IOMMU +#else +#define RTE_VFIO_NOIOMMU 8 +#endif + /** * Setup vfio_cfg for the device identified by its address. * It discovers the configured I/O MMU groups or sets a new one for the device. @@ -123,10 +130,75 @@ int rte_vfio_is_enabled(const char *modname); */ int rte_vfio_noiommu_is_enabled(void); -/* remove group fd from internal VFIO group fd array */ +/** + * Remove group fd from internal VFIO group fd array/ + * + * This function is only relevant to linux and will return + * an error on BSD. + * + * @param vfio_group_fd + * VFIO Grouup FD. + * + * @return + * 0 on success. + * <0 on failure. + */ int rte_vfio_clear_group(int vfio_group_fd); +/** + * Parse IOMMU group number for a device + * + * This function is only relevant to linux and will return + * an error on BSD. + * + * @param sysfs_base + * sysfs path prefix. + * + * @param dev_addr + * device location. + * + * @param iommu_group_no + * iommu group number + * + * @return + * >0 on success + * 0 for non-existent group or VFIO + * <0 for errors + */ +int __rte_experimental +rte_vfio_get_group_no(const char *sysfs_base, + const char *dev_addr, int *iommu_group_no); + +/** + * Open VFIO container fd or get an existing one + * + * This function is only relevant to linux and will return + * an error on BSD. + * + * @return + * > 0 container fd + * < 0 for errors + */ +int __rte_experimental +rte_vfio_get_container_fd(void); + +/** + * Open VFIO group fd or get an existing one + * + * This function is only relevant to linux and will return + * an error on BSD. + * + * @param iommu_group_no + * iommu group number + * + * @return + * > 0 group fd + * < 0 for errors + */ +int __rte_experimental +rte_vfio_get_group_fd(int iommu_group_no); + #ifdef __cplusplus } #endif diff --git a/lib/librte_eal/linuxapp/eal/eal_vfio.c b/lib/librte_eal/linuxapp/eal/eal_vfio.c index e44ae4d..3dc2c18 100644 --- a/lib/librte_eal/linuxapp/eal/eal_vfio.c +++ b/lib/librte_eal/linuxapp/eal/eal_vfio.c @@ -36,7 +36,7 @@ static const struct vfio_iommu_type iommu_types[] = { }; int -vfio_get_group_fd(int iommu_group_no) +rte_vfio_get_group_fd(int iommu_group_no) { int i; int vfio_group_fd; @@ -266,7 +266,7 @@ rte_vfio_setup_device(const char *sysfs_base, const char *dev_addr, int ret; /* get group number */ - ret = vfio_get_group_no(sysfs_base, dev_addr, &iommu_group_no); + ret = rte_vfio_get_group_no(sysfs_base, dev_addr, &iommu_group_no); if (ret == 0) { RTE_LOG(WARNING, EAL, " %s not managed by VFIO driver, skipping\n", dev_addr); @@ -278,7 +278,7 @@ rte_vfio_setup_device(const char *sysfs_base, const char *dev_addr, return -1; /* get the actual group fd */ - vfio_group_fd = vfio_get_group_fd(iommu_group_no); + vfio_group_fd = rte_vfio_get_group_fd(iommu_group_no); if (vfio_group_fd < 0) return -1; @@ -398,7 +398,7 @@ rte_vfio_release_device(const char *sysfs_base, const char *dev_addr, int ret; /* get group number */ - ret = vfio_get_group_no(sysfs_base, dev_addr, &iommu_group_no); + ret = rte_vfio_get_group_no(sysfs_base, dev_addr, &iommu_group_no); if (ret <= 0) { RTE_LOG(WARNING, EAL, " %s not managed by VFIO driver\n", dev_addr); @@ -407,9 +407,9 @@ rte_vfio_release_device(const char *sysfs_base, const char *dev_addr, } /* get the actual group fd */ - vfio_group_fd = vfio_get_group_fd(iommu_group_no); + vfio_group_fd = rte_vfio_get_group_fd(iommu_group_no); if (vfio_group_fd <= 0) { - RTE_LOG(INFO, EAL, "vfio_get_group_fd failed for %s\n", + RTE_LOG(INFO, EAL, "rte_vfio_get_group_fd failed for %s\n", dev_addr); return -1; } @@ -480,7 +480,7 @@ rte_vfio_enable(const char *modname) return 0; } - vfio_cfg.vfio_container_fd = vfio_get_container_fd(); + vfio_cfg.vfio_container_fd = rte_vfio_get_container_fd(); /* check if we have VFIO driver enabled */ if (vfio_cfg.vfio_container_fd != -1) { @@ -558,7 +558,7 @@ vfio_has_supported_extensions(int vfio_container_fd) } int -vfio_get_container_fd(void) +rte_vfio_get_container_fd(void) { int ret, vfio_container_fd; @@ -622,7 +622,7 @@ vfio_get_container_fd(void) } int -vfio_get_group_no(const char *sysfs_base, +rte_vfio_get_group_no(const char *sysfs_base, const char *dev_addr, int *iommu_group_no) { char linkname[PATH_MAX]; diff --git a/lib/librte_eal/linuxapp/eal/eal_vfio.h b/lib/librte_eal/linuxapp/eal/eal_vfio.h index 8059577..c72b76c 100644 --- a/lib/librte_eal/linuxapp/eal/eal_vfio.h +++ b/lib/librte_eal/linuxapp/eal/eal_vfio.h @@ -79,12 +79,6 @@ struct vfio_iommu_spapr_tce_info { #define RTE_VFIO_SPAPR VFIO_SPAPR_TCE_v2_IOMMU #endif -#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 5, 0) -#define RTE_VFIO_NOIOMMU 8 -#else -#define RTE_VFIO_NOIOMMU VFIO_NOIOMMU_IOMMU -#endif - #define VFIO_MAX_GROUPS RTE_MAX_VFIO_GROUPS /* @@ -133,21 +127,6 @@ vfio_set_iommu_type(int vfio_container_fd); int vfio_has_supported_extensions(int vfio_container_fd); -/* open container fd or get an existing one */ -int -vfio_get_container_fd(void); - -/* parse IOMMU group number for a device - * returns 1 on success, -1 for errors, 0 for non-existent group - */ -int -vfio_get_group_no(const char *sysfs_base, - const char *dev_addr, int *iommu_group_no); - -/* open group fd or get an existing one */ -int -vfio_get_group_fd(int iommu_group_no); - int vfio_mp_sync_setup(void); #define SOCKET_REQ_CONTAINER 0x100 diff --git a/lib/librte_eal/linuxapp/eal/eal_vfio_mp_sync.c b/lib/librte_eal/linuxapp/eal/eal_vfio_mp_sync.c index 7cc3c15..e19b571 100644 --- a/lib/librte_eal/linuxapp/eal/eal_vfio_mp_sync.c +++ b/lib/librte_eal/linuxapp/eal/eal_vfio_mp_sync.c @@ -267,7 +267,7 @@ vfio_mp_sync_thread(void __rte_unused * arg) switch (ret) { case SOCKET_REQ_CONTAINER: - fd = vfio_get_container_fd(); + fd = rte_vfio_get_container_fd(); if (fd < 0) vfio_mp_sync_send_request(conn_sock, SOCKET_ERR); else @@ -283,7 +283,7 @@ vfio_mp_sync_thread(void __rte_unused * arg) continue; } - fd = vfio_get_group_fd(vfio_data); + fd = rte_vfio_get_group_fd(vfio_data); if (fd < 0) vfio_mp_sync_send_request(conn_sock, SOCKET_ERR); diff --git a/lib/librte_eal/rte_eal_version.map b/lib/librte_eal/rte_eal_version.map index f331f54..23723d7 100644 --- a/lib/librte_eal/rte_eal_version.map +++ b/lib/librte_eal/rte_eal_version.map @@ -255,5 +255,8 @@ EXPERIMENTAL { rte_service_set_runstate_mapped_check; rte_service_set_stats_enable; rte_service_start_with_defaults; + rte_vfio_get_group_no; + rte_vfio_get_container_fd; + rte_vfio_get_group_fd; } DPDK_18.02; -- 2.7.4 ^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [dpdk-dev] [PATCH v2] eal/vfio: export internal vfio functions 2018-04-02 8:36 ` [dpdk-dev] [PATCH v2] " Hemant Agrawal @ 2018-04-02 16:41 ` Thomas Monjalon 2018-04-03 8:28 ` [dpdk-dev] [PATCH v3 1/2] doc: add vfio api support Hemant Agrawal 1 sibling, 0 replies; 27+ messages in thread From: Thomas Monjalon @ 2018-04-02 16:41 UTC (permalink / raw) To: Hemant Agrawal; +Cc: dev, anatoly.burakov 02/04/2018 10:36, Hemant Agrawal: > This patch moves some of the internal vfio functions from > eal_vfio.h to rte_vfio.h for common uses with "rte_" prefix. > > This patch also change the FSLMC bus usages from the internal > VFIO functions to external ones with "rte_" prefix > > Signed-off-by: Hemant Agrawal <hemant.agrawal@nxp.com> > Acked-by: Anatoly Burakov <anatoly.burakov@intel.com> > --- > v2: handle Thomas's comment > fix API documentation You did not reply to my questions and did not address everything. ^ permalink raw reply [flat|nested] 27+ messages in thread
* [dpdk-dev] [PATCH v3 1/2] doc: add vfio api support 2018-04-02 8:36 ` [dpdk-dev] [PATCH v2] " Hemant Agrawal 2018-04-02 16:41 ` Thomas Monjalon @ 2018-04-03 8:28 ` Hemant Agrawal 2018-04-03 8:28 ` [dpdk-dev] [PATCH v3 2/2] eal/vfio: export internal vfio functions Hemant Agrawal ` (2 more replies) 1 sibling, 3 replies; 27+ messages in thread From: Hemant Agrawal @ 2018-04-03 8:28 UTC (permalink / raw) To: dev; +Cc: anatoly.burakov, thomas Signed-off-by: Hemant Agrawal <hemant.agrawal@nxp.com> --- doc/api/doxy-api-index.md | 3 ++- doc/api/doxy-api.conf | 1 + lib/librte_eal/common/include/rte_vfio.h | 5 +++++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/doc/api/doxy-api-index.md b/doc/api/doxy-api-index.md index d77f205..12c1ebe 100644 --- a/doc/api/doxy-api-index.md +++ b/doc/api/doxy-api-index.md @@ -179,4 +179,5 @@ The public API headers are grouped by topics: [EAL config] (@ref rte_eal.h), [common] (@ref rte_common.h), [ABI compat] (@ref rte_compat.h), - [version] (@ref rte_version.h) + [version] (@ref rte_version.h), + [vfio] (@ref rte_vfio.h) diff --git a/doc/api/doxy-api.conf b/doc/api/doxy-api.conf index cda52fd..166612f 100644 --- a/doc/api/doxy-api.conf +++ b/doc/api/doxy-api.conf @@ -82,6 +82,7 @@ INPUT = doc/api/doxy-api-index.md \ FILE_PATTERNS = rte_*.h \ cmdline.h PREDEFINED = __DOXYGEN__ \ + VFIO_PRESENT \ __attribute__(x)= OPTIMIZE_OUTPUT_FOR_C = YES diff --git a/lib/librte_eal/common/include/rte_vfio.h b/lib/librte_eal/common/include/rte_vfio.h index 249095e..9b7b983 100644 --- a/lib/librte_eal/common/include/rte_vfio.h +++ b/lib/librte_eal/common/include/rte_vfio.h @@ -5,6 +5,11 @@ #ifndef _RTE_VFIO_H_ #define _RTE_VFIO_H_ +/** + * @file + * RTE VFIO. This library provides various VFIO related utility functions. + */ + /* * determine if VFIO is present on the system */ -- 2.7.4 ^ permalink raw reply [flat|nested] 27+ messages in thread
* [dpdk-dev] [PATCH v3 2/2] eal/vfio: export internal vfio functions 2018-04-03 8:28 ` [dpdk-dev] [PATCH v3 1/2] doc: add vfio api support Hemant Agrawal @ 2018-04-03 8:28 ` Hemant Agrawal 2018-04-03 10:16 ` [dpdk-dev] [PATCH v3 1/2] doc: add vfio api support Thomas Monjalon 2018-04-03 11:10 ` [dpdk-dev] [PATCH v4 " Hemant Agrawal 2 siblings, 0 replies; 27+ messages in thread From: Hemant Agrawal @ 2018-04-03 8:28 UTC (permalink / raw) To: dev; +Cc: anatoly.burakov, thomas This patch moves some of the internal vfio functions from eal_vfio.h to rte_vfio.h for common uses with "rte_" prefix. This patch also change the FSLMC bus usages from the internal VFIO functions to external ones with "rte_" prefix Signed-off-by: Hemant Agrawal <hemant.agrawal@nxp.com> Acked-by: Anatoly Burakov <anatoly.burakov@intel.com> --- drivers/bus/fslmc/Makefile | 1 - drivers/bus/fslmc/fslmc_vfio.c | 7 +-- drivers/bus/fslmc/fslmc_vfio.h | 2 - drivers/bus/fslmc/meson.build | 1 - lib/librte_eal/bsdapp/eal/eal.c | 20 +++++++ lib/librte_eal/common/include/rte_vfio.h | 75 +++++++++++++++++++++++++- lib/librte_eal/linuxapp/eal/eal_vfio.c | 38 ++++++------- lib/librte_eal/linuxapp/eal/eal_vfio.h | 21 -------- lib/librte_eal/linuxapp/eal/eal_vfio_mp_sync.c | 4 +- lib/librte_eal/rte_eal_version.map | 3 ++ 10 files changed, 122 insertions(+), 50 deletions(-) diff --git a/drivers/bus/fslmc/Makefile b/drivers/bus/fslmc/Makefile index 93870ba..3aa34e2 100644 --- a/drivers/bus/fslmc/Makefile +++ b/drivers/bus/fslmc/Makefile @@ -16,7 +16,6 @@ CFLAGS += $(WERROR_FLAGS) CFLAGS += -I$(RTE_SDK)/drivers/bus/fslmc CFLAGS += -I$(RTE_SDK)/drivers/bus/fslmc/mc CFLAGS += -I$(RTE_SDK)/drivers/bus/fslmc/qbman/include -CFLAGS += -I$(RTE_SDK)/lib/librte_eal/linuxapp/eal CFLAGS += -I$(RTE_SDK)/lib/librte_eal/common LDLIBS += -lrte_eal -lrte_mbuf -lrte_mempool -lrte_ring LDLIBS += -lrte_ethdev diff --git a/drivers/bus/fslmc/fslmc_vfio.c b/drivers/bus/fslmc/fslmc_vfio.c index 62499de..f3b2960 100644 --- a/drivers/bus/fslmc/fslmc_vfio.c +++ b/drivers/bus/fslmc/fslmc_vfio.c @@ -91,7 +91,8 @@ fslmc_get_container_group(int *groupid) } /* get group number */ - ret = vfio_get_group_no(SYSFS_FSL_MC_DEVICES, g_container, groupid); + ret = rte_vfio_get_group_num(SYSFS_FSL_MC_DEVICES, + g_container, groupid); if (ret <= 0) { DPAA2_BUS_ERR("Unable to find %s IOMMU group", g_container); return -1; @@ -124,7 +125,7 @@ vfio_connect_container(void) } /* Opens main vfio file descriptor which represents the "container" */ - fd = vfio_get_container_fd(); + fd = rte_vfio_get_container_fd(); if (fd < 0) { DPAA2_BUS_ERR("Failed to open VFIO container"); return -errno; @@ -620,7 +621,7 @@ fslmc_vfio_setup_group(void) } /* Get the actual group fd */ - ret = vfio_get_group_fd(groupid); + ret = rte_vfio_get_group_fd(groupid); if (ret < 0) return ret; vfio_group.fd = ret; diff --git a/drivers/bus/fslmc/fslmc_vfio.h b/drivers/bus/fslmc/fslmc_vfio.h index e8fb344..9e2c4fe 100644 --- a/drivers/bus/fslmc/fslmc_vfio.h +++ b/drivers/bus/fslmc/fslmc_vfio.h @@ -10,8 +10,6 @@ #include <rte_vfio.h> -#include "eal_vfio.h" - #define DPAA2_MC_DPNI_DEVID 7 #define DPAA2_MC_DPSECI_DEVID 3 #define DPAA2_MC_DPCON_DEVID 5 diff --git a/drivers/bus/fslmc/meson.build b/drivers/bus/fslmc/meson.build index e94340e..78f9d92 100644 --- a/drivers/bus/fslmc/meson.build +++ b/drivers/bus/fslmc/meson.build @@ -22,6 +22,5 @@ sources = files('fslmc_bus.c', allow_experimental_apis = true -includes += include_directories('../../../lib/librte_eal/linuxapp/eal') includes += include_directories('mc', 'qbman/include', 'portal') cflags += ['-D_GNU_SOURCE'] diff --git a/lib/librte_eal/bsdapp/eal/eal.c b/lib/librte_eal/bsdapp/eal/eal.c index 4eafcb5..ac23db5 100644 --- a/lib/librte_eal/bsdapp/eal/eal.c +++ b/lib/librte_eal/bsdapp/eal/eal.c @@ -781,3 +781,23 @@ int rte_vfio_clear_group(__rte_unused int vfio_group_fd) { return 0; } + +int __rte_experimental +rte_vfio_get_group_num(__rte_unused const char *sysfs_base, + __rte_unused const char *dev_addr, + __rte_unused int *iommu_group_num) +{ + return -1; +} + +int __rte_experimental +rte_vfio_get_container_fd(void) +{ + return -1; +} + +int __rte_experimental +rte_vfio_get_group_fd(__rte_unused int iommu_group_num) +{ + return -1; +} diff --git a/lib/librte_eal/common/include/rte_vfio.h b/lib/librte_eal/common/include/rte_vfio.h index 9b7b983..9369b42 100644 --- a/lib/librte_eal/common/include/rte_vfio.h +++ b/lib/librte_eal/common/include/rte_vfio.h @@ -37,6 +37,13 @@ extern "C" { #endif +/* NOIOMMU is defined from kernel version 4.5 onwards */ +#ifdef VFIO_NOIOMMU_IOMMU +#define RTE_VFIO_NOIOMMU VFIO_NOIOMMU_IOMMU +#else +#define RTE_VFIO_NOIOMMU 8 +#endif + /** * Setup vfio_cfg for the device identified by its address. * It discovers the configured I/O MMU groups or sets a new one for the device. @@ -128,10 +135,76 @@ int rte_vfio_is_enabled(const char *modname); */ int rte_vfio_noiommu_is_enabled(void); -/* remove group fd from internal VFIO group fd array */ +/** + * Remove group fd from internal VFIO group fd array/ + * + * This function is only relevant to linux and will return + * an error on BSD. + * + * @param vfio_group_fd + * VFIO Grouup FD. + * + * @return + * 0 on success. + * <0 on failure. + */ int rte_vfio_clear_group(int vfio_group_fd); +/** + * Parse IOMMU group number for a device + * + * This function is only relevant to linux and will return + * an error on BSD. + * + * @param sysfs_base + * sysfs path prefix. + * + * @param dev_addr + * device location. + * + * @param iommu_group_num + * iommu group number + * + * @return + * >0 on success + * 0 for non-existent group or VFIO + * <0 for errors + */ +int __rte_experimental +rte_vfio_get_group_num(const char *sysfs_base, + const char *dev_addr, + int *iommu_group_num); + +/** + * Open VFIO container fd or get an existing one + * + * This function is only relevant to linux and will return + * an error on BSD. + * + * @return + * > 0 container fd + * < 0 for errors + */ +int __rte_experimental +rte_vfio_get_container_fd(void); + +/** + * Open VFIO group fd or get an existing one + * + * This function is only relevant to linux and will return + * an error on BSD. + * + * @param iommu_group_num + * iommu group number + * + * @return + * > 0 group fd + * < 0 for errors + */ +int __rte_experimental +rte_vfio_get_group_fd(int iommu_group_num); + #ifdef __cplusplus } #endif diff --git a/lib/librte_eal/linuxapp/eal/eal_vfio.c b/lib/librte_eal/linuxapp/eal/eal_vfio.c index e44ae4d..9f75417 100644 --- a/lib/librte_eal/linuxapp/eal/eal_vfio.c +++ b/lib/librte_eal/linuxapp/eal/eal_vfio.c @@ -36,7 +36,7 @@ static const struct vfio_iommu_type iommu_types[] = { }; int -vfio_get_group_fd(int iommu_group_no) +rte_vfio_get_group_fd(int iommu_group_num) { int i; int vfio_group_fd; @@ -45,7 +45,7 @@ vfio_get_group_fd(int iommu_group_no) /* check if we already have the group descriptor open */ for (i = 0; i < VFIO_MAX_GROUPS; i++) - if (vfio_cfg.vfio_groups[i].group_no == iommu_group_no) + if (vfio_cfg.vfio_groups[i].group_no == iommu_group_num) return vfio_cfg.vfio_groups[i].fd; /* Lets see first if there is room for a new group */ @@ -70,7 +70,7 @@ vfio_get_group_fd(int iommu_group_no) if (internal_config.process_type == RTE_PROC_PRIMARY) { /* try regular group format */ snprintf(filename, sizeof(filename), - VFIO_GROUP_FMT, iommu_group_no); + VFIO_GROUP_FMT, iommu_group_num); vfio_group_fd = open(filename, O_RDWR); if (vfio_group_fd < 0) { /* if file not found, it's not an error */ @@ -82,7 +82,7 @@ vfio_get_group_fd(int iommu_group_no) /* special case: try no-IOMMU path as well */ snprintf(filename, sizeof(filename), - VFIO_NOIOMMU_GROUP_FMT, iommu_group_no); + VFIO_NOIOMMU_GROUP_FMT, iommu_group_num); vfio_group_fd = open(filename, O_RDWR); if (vfio_group_fd < 0) { if (errno != ENOENT) { @@ -95,7 +95,7 @@ vfio_get_group_fd(int iommu_group_no) /* noiommu group found */ } - cur_grp->group_no = iommu_group_no; + cur_grp->group_no = iommu_group_num; cur_grp->fd = vfio_group_fd; vfio_cfg.vfio_active_groups++; return vfio_group_fd; @@ -117,7 +117,7 @@ vfio_get_group_fd(int iommu_group_no) close(socket_fd); return -1; } - if (vfio_mp_sync_send_request(socket_fd, iommu_group_no) < 0) { + if (vfio_mp_sync_send_request(socket_fd, iommu_group_num) < 0) { RTE_LOG(ERR, EAL, " cannot send group number!\n"); close(socket_fd); return -1; @@ -132,7 +132,7 @@ vfio_get_group_fd(int iommu_group_no) /* if we got the fd, store it and return it */ if (vfio_group_fd > 0) { close(socket_fd); - cur_grp->group_no = iommu_group_no; + cur_grp->group_no = iommu_group_num; cur_grp->fd = vfio_group_fd; vfio_cfg.vfio_active_groups++; return vfio_group_fd; @@ -262,11 +262,11 @@ rte_vfio_setup_device(const char *sysfs_base, const char *dev_addr, .argsz = sizeof(group_status) }; int vfio_group_fd; - int iommu_group_no; + int iommu_group_num; int ret; /* get group number */ - ret = vfio_get_group_no(sysfs_base, dev_addr, &iommu_group_no); + ret = rte_vfio_get_group_num(sysfs_base, dev_addr, &iommu_group_num); if (ret == 0) { RTE_LOG(WARNING, EAL, " %s not managed by VFIO driver, skipping\n", dev_addr); @@ -278,7 +278,7 @@ rte_vfio_setup_device(const char *sysfs_base, const char *dev_addr, return -1; /* get the actual group fd */ - vfio_group_fd = vfio_get_group_fd(iommu_group_no); + vfio_group_fd = rte_vfio_get_group_fd(iommu_group_num); if (vfio_group_fd < 0) return -1; @@ -394,11 +394,11 @@ rte_vfio_release_device(const char *sysfs_base, const char *dev_addr, .argsz = sizeof(group_status) }; int vfio_group_fd; - int iommu_group_no; + int iommu_group_num; int ret; /* get group number */ - ret = vfio_get_group_no(sysfs_base, dev_addr, &iommu_group_no); + ret = rte_vfio_get_group_num(sysfs_base, dev_addr, &iommu_group_num); if (ret <= 0) { RTE_LOG(WARNING, EAL, " %s not managed by VFIO driver\n", dev_addr); @@ -407,9 +407,9 @@ rte_vfio_release_device(const char *sysfs_base, const char *dev_addr, } /* get the actual group fd */ - vfio_group_fd = vfio_get_group_fd(iommu_group_no); + vfio_group_fd = rte_vfio_get_group_fd(iommu_group_num); if (vfio_group_fd <= 0) { - RTE_LOG(INFO, EAL, "vfio_get_group_fd failed for %s\n", + RTE_LOG(INFO, EAL, "rte_vfio_get_group_fd failed for %s\n", dev_addr); return -1; } @@ -480,7 +480,7 @@ rte_vfio_enable(const char *modname) return 0; } - vfio_cfg.vfio_container_fd = vfio_get_container_fd(); + vfio_cfg.vfio_container_fd = rte_vfio_get_container_fd(); /* check if we have VFIO driver enabled */ if (vfio_cfg.vfio_container_fd != -1) { @@ -558,7 +558,7 @@ vfio_has_supported_extensions(int vfio_container_fd) } int -vfio_get_container_fd(void) +rte_vfio_get_container_fd(void) { int ret, vfio_container_fd; @@ -622,8 +622,8 @@ vfio_get_container_fd(void) } int -vfio_get_group_no(const char *sysfs_base, - const char *dev_addr, int *iommu_group_no) +rte_vfio_get_group_num(const char *sysfs_base, + const char *dev_addr, int *iommu_group_num) { char linkname[PATH_MAX]; char filename[PATH_MAX]; @@ -655,7 +655,7 @@ vfio_get_group_no(const char *sysfs_base, errno = 0; group_tok = tok[ret - 1]; end = group_tok; - *iommu_group_no = strtol(group_tok, &end, 10); + *iommu_group_num = strtol(group_tok, &end, 10); if ((end != group_tok && *end != '\0') || errno != 0) { RTE_LOG(ERR, EAL, " %s error parsing IOMMU number!\n", dev_addr); return -1; diff --git a/lib/librte_eal/linuxapp/eal/eal_vfio.h b/lib/librte_eal/linuxapp/eal/eal_vfio.h index 8059577..c72b76c 100644 --- a/lib/librte_eal/linuxapp/eal/eal_vfio.h +++ b/lib/librte_eal/linuxapp/eal/eal_vfio.h @@ -79,12 +79,6 @@ struct vfio_iommu_spapr_tce_info { #define RTE_VFIO_SPAPR VFIO_SPAPR_TCE_v2_IOMMU #endif -#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 5, 0) -#define RTE_VFIO_NOIOMMU 8 -#else -#define RTE_VFIO_NOIOMMU VFIO_NOIOMMU_IOMMU -#endif - #define VFIO_MAX_GROUPS RTE_MAX_VFIO_GROUPS /* @@ -133,21 +127,6 @@ vfio_set_iommu_type(int vfio_container_fd); int vfio_has_supported_extensions(int vfio_container_fd); -/* open container fd or get an existing one */ -int -vfio_get_container_fd(void); - -/* parse IOMMU group number for a device - * returns 1 on success, -1 for errors, 0 for non-existent group - */ -int -vfio_get_group_no(const char *sysfs_base, - const char *dev_addr, int *iommu_group_no); - -/* open group fd or get an existing one */ -int -vfio_get_group_fd(int iommu_group_no); - int vfio_mp_sync_setup(void); #define SOCKET_REQ_CONTAINER 0x100 diff --git a/lib/librte_eal/linuxapp/eal/eal_vfio_mp_sync.c b/lib/librte_eal/linuxapp/eal/eal_vfio_mp_sync.c index 7cc3c15..e19b571 100644 --- a/lib/librte_eal/linuxapp/eal/eal_vfio_mp_sync.c +++ b/lib/librte_eal/linuxapp/eal/eal_vfio_mp_sync.c @@ -267,7 +267,7 @@ vfio_mp_sync_thread(void __rte_unused * arg) switch (ret) { case SOCKET_REQ_CONTAINER: - fd = vfio_get_container_fd(); + fd = rte_vfio_get_container_fd(); if (fd < 0) vfio_mp_sync_send_request(conn_sock, SOCKET_ERR); else @@ -283,7 +283,7 @@ vfio_mp_sync_thread(void __rte_unused * arg) continue; } - fd = vfio_get_group_fd(vfio_data); + fd = rte_vfio_get_group_fd(vfio_data); if (fd < 0) vfio_mp_sync_send_request(conn_sock, SOCKET_ERR); diff --git a/lib/librte_eal/rte_eal_version.map b/lib/librte_eal/rte_eal_version.map index f331f54..f663b8b 100644 --- a/lib/librte_eal/rte_eal_version.map +++ b/lib/librte_eal/rte_eal_version.map @@ -255,5 +255,8 @@ EXPERIMENTAL { rte_service_set_runstate_mapped_check; rte_service_set_stats_enable; rte_service_start_with_defaults; + rte_vfio_get_group_num; + rte_vfio_get_container_fd; + rte_vfio_get_group_fd; } DPDK_18.02; -- 2.7.4 ^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [dpdk-dev] [PATCH v3 1/2] doc: add vfio api support 2018-04-03 8:28 ` [dpdk-dev] [PATCH v3 1/2] doc: add vfio api support Hemant Agrawal 2018-04-03 8:28 ` [dpdk-dev] [PATCH v3 2/2] eal/vfio: export internal vfio functions Hemant Agrawal @ 2018-04-03 10:16 ` Thomas Monjalon 2018-04-03 11:10 ` [dpdk-dev] [PATCH v4 " Hemant Agrawal 2 siblings, 0 replies; 27+ messages in thread From: Thomas Monjalon @ 2018-04-03 10:16 UTC (permalink / raw) To: Hemant Agrawal; +Cc: dev, anatoly.burakov 03/04/2018 10:28, Hemant Agrawal: > --- a/doc/api/doxy-api-index.md > +++ b/doc/api/doxy-api-index.md > @@ -179,4 +179,5 @@ The public API headers are grouped by topics: > [EAL config] (@ref rte_eal.h), > [common] (@ref rte_common.h), > [ABI compat] (@ref rte_compat.h), > - [version] (@ref rte_version.h) > + [version] (@ref rte_version.h), > + [vfio] (@ref rte_vfio.h) It would be more appropriate after rte_pci.h in "device" section. > diff --git a/doc/api/doxy-api.conf b/doc/api/doxy-api.conf > index cda52fd..166612f 100644 > --- a/doc/api/doxy-api.conf > +++ b/doc/api/doxy-api.conf > @@ -82,6 +82,7 @@ INPUT = doc/api/doxy-api-index.md \ > FILE_PATTERNS = rte_*.h \ > cmdline.h > PREDEFINED = __DOXYGEN__ \ > + VFIO_PRESENT \ > __attribute__(x)= The indent is not the same as other lines. ^ permalink raw reply [flat|nested] 27+ messages in thread
* [dpdk-dev] [PATCH v4 1/2] doc: add vfio api support 2018-04-03 8:28 ` [dpdk-dev] [PATCH v3 1/2] doc: add vfio api support Hemant Agrawal 2018-04-03 8:28 ` [dpdk-dev] [PATCH v3 2/2] eal/vfio: export internal vfio functions Hemant Agrawal 2018-04-03 10:16 ` [dpdk-dev] [PATCH v3 1/2] doc: add vfio api support Thomas Monjalon @ 2018-04-03 11:10 ` Hemant Agrawal 2018-04-03 11:10 ` [dpdk-dev] [PATCH v4 2/2] eal/vfio: export internal vfio functions Hemant Agrawal 2018-04-04 7:48 ` [dpdk-dev] [PATCH v5 1/2] doc: add vfio api support Hemant Agrawal 2 siblings, 2 replies; 27+ messages in thread From: Hemant Agrawal @ 2018-04-03 11:10 UTC (permalink / raw) To: dev; +Cc: anatoly.burakov, thomas Signed-off-by: Hemant Agrawal <hemant.agrawal@nxp.com> --- doc/api/doxy-api-index.md | 3 ++- doc/api/doxy-api.conf | 1 + lib/librte_eal/common/include/rte_vfio.h | 5 +++++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/doc/api/doxy-api-index.md b/doc/api/doxy-api-index.md index d77f205..d21f2d9 100644 --- a/doc/api/doxy-api-index.md +++ b/doc/api/doxy-api-index.md @@ -52,7 +52,8 @@ The public API headers are grouped by topics: [bitrate] (@ref rte_bitrate.h), [latency] (@ref rte_latencystats.h), [devargs] (@ref rte_devargs.h), - [PCI] (@ref rte_pci.h) + [PCI] (@ref rte_pci.h), + [vfio] (@ref rte_vfio.h) - **device specific**: [softnic] (@ref rte_eth_softnic.h), diff --git a/doc/api/doxy-api.conf b/doc/api/doxy-api.conf index cda52fd..ad8bdcf 100644 --- a/doc/api/doxy-api.conf +++ b/doc/api/doxy-api.conf @@ -82,6 +82,7 @@ INPUT = doc/api/doxy-api-index.md \ FILE_PATTERNS = rte_*.h \ cmdline.h PREDEFINED = __DOXYGEN__ \ + VFIO_PRESENT \ __attribute__(x)= OPTIMIZE_OUTPUT_FOR_C = YES diff --git a/lib/librte_eal/common/include/rte_vfio.h b/lib/librte_eal/common/include/rte_vfio.h index 249095e..9b7b983 100644 --- a/lib/librte_eal/common/include/rte_vfio.h +++ b/lib/librte_eal/common/include/rte_vfio.h @@ -5,6 +5,11 @@ #ifndef _RTE_VFIO_H_ #define _RTE_VFIO_H_ +/** + * @file + * RTE VFIO. This library provides various VFIO related utility functions. + */ + /* * determine if VFIO is present on the system */ -- 2.7.4 ^ permalink raw reply [flat|nested] 27+ messages in thread
* [dpdk-dev] [PATCH v4 2/2] eal/vfio: export internal vfio functions 2018-04-03 11:10 ` [dpdk-dev] [PATCH v4 " Hemant Agrawal @ 2018-04-03 11:10 ` Hemant Agrawal 2018-04-03 12:24 ` Thomas Monjalon 2018-04-03 15:23 ` Wang, Xiao W 2018-04-04 7:48 ` [dpdk-dev] [PATCH v5 1/2] doc: add vfio api support Hemant Agrawal 1 sibling, 2 replies; 27+ messages in thread From: Hemant Agrawal @ 2018-04-03 11:10 UTC (permalink / raw) To: dev; +Cc: anatoly.burakov, thomas This patch moves some of the internal vfio functions from eal_vfio.h to rte_vfio.h for common uses with "rte_" prefix. This patch also change the FSLMC bus usages from the internal VFIO functions to external ones with "rte_" prefix Signed-off-by: Hemant Agrawal <hemant.agrawal@nxp.com> Acked-by: Anatoly Burakov <anatoly.burakov@intel.com> --- drivers/bus/fslmc/Makefile | 1 - drivers/bus/fslmc/fslmc_vfio.c | 7 +-- drivers/bus/fslmc/fslmc_vfio.h | 2 - drivers/bus/fslmc/meson.build | 1 - lib/librte_eal/bsdapp/eal/eal.c | 20 +++++++ lib/librte_eal/common/include/rte_vfio.h | 75 +++++++++++++++++++++++++- lib/librte_eal/linuxapp/eal/eal_vfio.c | 38 ++++++------- lib/librte_eal/linuxapp/eal/eal_vfio.h | 21 -------- lib/librte_eal/linuxapp/eal/eal_vfio_mp_sync.c | 4 +- lib/librte_eal/rte_eal_version.map | 3 ++ 10 files changed, 122 insertions(+), 50 deletions(-) diff --git a/drivers/bus/fslmc/Makefile b/drivers/bus/fslmc/Makefile index 93870ba..3aa34e2 100644 --- a/drivers/bus/fslmc/Makefile +++ b/drivers/bus/fslmc/Makefile @@ -16,7 +16,6 @@ CFLAGS += $(WERROR_FLAGS) CFLAGS += -I$(RTE_SDK)/drivers/bus/fslmc CFLAGS += -I$(RTE_SDK)/drivers/bus/fslmc/mc CFLAGS += -I$(RTE_SDK)/drivers/bus/fslmc/qbman/include -CFLAGS += -I$(RTE_SDK)/lib/librte_eal/linuxapp/eal CFLAGS += -I$(RTE_SDK)/lib/librte_eal/common LDLIBS += -lrte_eal -lrte_mbuf -lrte_mempool -lrte_ring LDLIBS += -lrte_ethdev diff --git a/drivers/bus/fslmc/fslmc_vfio.c b/drivers/bus/fslmc/fslmc_vfio.c index 62499de..f3b2960 100644 --- a/drivers/bus/fslmc/fslmc_vfio.c +++ b/drivers/bus/fslmc/fslmc_vfio.c @@ -91,7 +91,8 @@ fslmc_get_container_group(int *groupid) } /* get group number */ - ret = vfio_get_group_no(SYSFS_FSL_MC_DEVICES, g_container, groupid); + ret = rte_vfio_get_group_num(SYSFS_FSL_MC_DEVICES, + g_container, groupid); if (ret <= 0) { DPAA2_BUS_ERR("Unable to find %s IOMMU group", g_container); return -1; @@ -124,7 +125,7 @@ vfio_connect_container(void) } /* Opens main vfio file descriptor which represents the "container" */ - fd = vfio_get_container_fd(); + fd = rte_vfio_get_container_fd(); if (fd < 0) { DPAA2_BUS_ERR("Failed to open VFIO container"); return -errno; @@ -620,7 +621,7 @@ fslmc_vfio_setup_group(void) } /* Get the actual group fd */ - ret = vfio_get_group_fd(groupid); + ret = rte_vfio_get_group_fd(groupid); if (ret < 0) return ret; vfio_group.fd = ret; diff --git a/drivers/bus/fslmc/fslmc_vfio.h b/drivers/bus/fslmc/fslmc_vfio.h index e8fb344..9e2c4fe 100644 --- a/drivers/bus/fslmc/fslmc_vfio.h +++ b/drivers/bus/fslmc/fslmc_vfio.h @@ -10,8 +10,6 @@ #include <rte_vfio.h> -#include "eal_vfio.h" - #define DPAA2_MC_DPNI_DEVID 7 #define DPAA2_MC_DPSECI_DEVID 3 #define DPAA2_MC_DPCON_DEVID 5 diff --git a/drivers/bus/fslmc/meson.build b/drivers/bus/fslmc/meson.build index e94340e..78f9d92 100644 --- a/drivers/bus/fslmc/meson.build +++ b/drivers/bus/fslmc/meson.build @@ -22,6 +22,5 @@ sources = files('fslmc_bus.c', allow_experimental_apis = true -includes += include_directories('../../../lib/librte_eal/linuxapp/eal') includes += include_directories('mc', 'qbman/include', 'portal') cflags += ['-D_GNU_SOURCE'] diff --git a/lib/librte_eal/bsdapp/eal/eal.c b/lib/librte_eal/bsdapp/eal/eal.c index 4eafcb5..ac23db5 100644 --- a/lib/librte_eal/bsdapp/eal/eal.c +++ b/lib/librte_eal/bsdapp/eal/eal.c @@ -781,3 +781,23 @@ int rte_vfio_clear_group(__rte_unused int vfio_group_fd) { return 0; } + +int __rte_experimental +rte_vfio_get_group_num(__rte_unused const char *sysfs_base, + __rte_unused const char *dev_addr, + __rte_unused int *iommu_group_num) +{ + return -1; +} + +int __rte_experimental +rte_vfio_get_container_fd(void) +{ + return -1; +} + +int __rte_experimental +rte_vfio_get_group_fd(__rte_unused int iommu_group_num) +{ + return -1; +} diff --git a/lib/librte_eal/common/include/rte_vfio.h b/lib/librte_eal/common/include/rte_vfio.h index 9b7b983..9369b42 100644 --- a/lib/librte_eal/common/include/rte_vfio.h +++ b/lib/librte_eal/common/include/rte_vfio.h @@ -37,6 +37,13 @@ extern "C" { #endif +/* NOIOMMU is defined from kernel version 4.5 onwards */ +#ifdef VFIO_NOIOMMU_IOMMU +#define RTE_VFIO_NOIOMMU VFIO_NOIOMMU_IOMMU +#else +#define RTE_VFIO_NOIOMMU 8 +#endif + /** * Setup vfio_cfg for the device identified by its address. * It discovers the configured I/O MMU groups or sets a new one for the device. @@ -128,10 +135,76 @@ int rte_vfio_is_enabled(const char *modname); */ int rte_vfio_noiommu_is_enabled(void); -/* remove group fd from internal VFIO group fd array */ +/** + * Remove group fd from internal VFIO group fd array/ + * + * This function is only relevant to linux and will return + * an error on BSD. + * + * @param vfio_group_fd + * VFIO Grouup FD. + * + * @return + * 0 on success. + * <0 on failure. + */ int rte_vfio_clear_group(int vfio_group_fd); +/** + * Parse IOMMU group number for a device + * + * This function is only relevant to linux and will return + * an error on BSD. + * + * @param sysfs_base + * sysfs path prefix. + * + * @param dev_addr + * device location. + * + * @param iommu_group_num + * iommu group number + * + * @return + * >0 on success + * 0 for non-existent group or VFIO + * <0 for errors + */ +int __rte_experimental +rte_vfio_get_group_num(const char *sysfs_base, + const char *dev_addr, + int *iommu_group_num); + +/** + * Open VFIO container fd or get an existing one + * + * This function is only relevant to linux and will return + * an error on BSD. + * + * @return + * > 0 container fd + * < 0 for errors + */ +int __rte_experimental +rte_vfio_get_container_fd(void); + +/** + * Open VFIO group fd or get an existing one + * + * This function is only relevant to linux and will return + * an error on BSD. + * + * @param iommu_group_num + * iommu group number + * + * @return + * > 0 group fd + * < 0 for errors + */ +int __rte_experimental +rte_vfio_get_group_fd(int iommu_group_num); + #ifdef __cplusplus } #endif diff --git a/lib/librte_eal/linuxapp/eal/eal_vfio.c b/lib/librte_eal/linuxapp/eal/eal_vfio.c index e44ae4d..9f75417 100644 --- a/lib/librte_eal/linuxapp/eal/eal_vfio.c +++ b/lib/librte_eal/linuxapp/eal/eal_vfio.c @@ -36,7 +36,7 @@ static const struct vfio_iommu_type iommu_types[] = { }; int -vfio_get_group_fd(int iommu_group_no) +rte_vfio_get_group_fd(int iommu_group_num) { int i; int vfio_group_fd; @@ -45,7 +45,7 @@ vfio_get_group_fd(int iommu_group_no) /* check if we already have the group descriptor open */ for (i = 0; i < VFIO_MAX_GROUPS; i++) - if (vfio_cfg.vfio_groups[i].group_no == iommu_group_no) + if (vfio_cfg.vfio_groups[i].group_no == iommu_group_num) return vfio_cfg.vfio_groups[i].fd; /* Lets see first if there is room for a new group */ @@ -70,7 +70,7 @@ vfio_get_group_fd(int iommu_group_no) if (internal_config.process_type == RTE_PROC_PRIMARY) { /* try regular group format */ snprintf(filename, sizeof(filename), - VFIO_GROUP_FMT, iommu_group_no); + VFIO_GROUP_FMT, iommu_group_num); vfio_group_fd = open(filename, O_RDWR); if (vfio_group_fd < 0) { /* if file not found, it's not an error */ @@ -82,7 +82,7 @@ vfio_get_group_fd(int iommu_group_no) /* special case: try no-IOMMU path as well */ snprintf(filename, sizeof(filename), - VFIO_NOIOMMU_GROUP_FMT, iommu_group_no); + VFIO_NOIOMMU_GROUP_FMT, iommu_group_num); vfio_group_fd = open(filename, O_RDWR); if (vfio_group_fd < 0) { if (errno != ENOENT) { @@ -95,7 +95,7 @@ vfio_get_group_fd(int iommu_group_no) /* noiommu group found */ } - cur_grp->group_no = iommu_group_no; + cur_grp->group_no = iommu_group_num; cur_grp->fd = vfio_group_fd; vfio_cfg.vfio_active_groups++; return vfio_group_fd; @@ -117,7 +117,7 @@ vfio_get_group_fd(int iommu_group_no) close(socket_fd); return -1; } - if (vfio_mp_sync_send_request(socket_fd, iommu_group_no) < 0) { + if (vfio_mp_sync_send_request(socket_fd, iommu_group_num) < 0) { RTE_LOG(ERR, EAL, " cannot send group number!\n"); close(socket_fd); return -1; @@ -132,7 +132,7 @@ vfio_get_group_fd(int iommu_group_no) /* if we got the fd, store it and return it */ if (vfio_group_fd > 0) { close(socket_fd); - cur_grp->group_no = iommu_group_no; + cur_grp->group_no = iommu_group_num; cur_grp->fd = vfio_group_fd; vfio_cfg.vfio_active_groups++; return vfio_group_fd; @@ -262,11 +262,11 @@ rte_vfio_setup_device(const char *sysfs_base, const char *dev_addr, .argsz = sizeof(group_status) }; int vfio_group_fd; - int iommu_group_no; + int iommu_group_num; int ret; /* get group number */ - ret = vfio_get_group_no(sysfs_base, dev_addr, &iommu_group_no); + ret = rte_vfio_get_group_num(sysfs_base, dev_addr, &iommu_group_num); if (ret == 0) { RTE_LOG(WARNING, EAL, " %s not managed by VFIO driver, skipping\n", dev_addr); @@ -278,7 +278,7 @@ rte_vfio_setup_device(const char *sysfs_base, const char *dev_addr, return -1; /* get the actual group fd */ - vfio_group_fd = vfio_get_group_fd(iommu_group_no); + vfio_group_fd = rte_vfio_get_group_fd(iommu_group_num); if (vfio_group_fd < 0) return -1; @@ -394,11 +394,11 @@ rte_vfio_release_device(const char *sysfs_base, const char *dev_addr, .argsz = sizeof(group_status) }; int vfio_group_fd; - int iommu_group_no; + int iommu_group_num; int ret; /* get group number */ - ret = vfio_get_group_no(sysfs_base, dev_addr, &iommu_group_no); + ret = rte_vfio_get_group_num(sysfs_base, dev_addr, &iommu_group_num); if (ret <= 0) { RTE_LOG(WARNING, EAL, " %s not managed by VFIO driver\n", dev_addr); @@ -407,9 +407,9 @@ rte_vfio_release_device(const char *sysfs_base, const char *dev_addr, } /* get the actual group fd */ - vfio_group_fd = vfio_get_group_fd(iommu_group_no); + vfio_group_fd = rte_vfio_get_group_fd(iommu_group_num); if (vfio_group_fd <= 0) { - RTE_LOG(INFO, EAL, "vfio_get_group_fd failed for %s\n", + RTE_LOG(INFO, EAL, "rte_vfio_get_group_fd failed for %s\n", dev_addr); return -1; } @@ -480,7 +480,7 @@ rte_vfio_enable(const char *modname) return 0; } - vfio_cfg.vfio_container_fd = vfio_get_container_fd(); + vfio_cfg.vfio_container_fd = rte_vfio_get_container_fd(); /* check if we have VFIO driver enabled */ if (vfio_cfg.vfio_container_fd != -1) { @@ -558,7 +558,7 @@ vfio_has_supported_extensions(int vfio_container_fd) } int -vfio_get_container_fd(void) +rte_vfio_get_container_fd(void) { int ret, vfio_container_fd; @@ -622,8 +622,8 @@ vfio_get_container_fd(void) } int -vfio_get_group_no(const char *sysfs_base, - const char *dev_addr, int *iommu_group_no) +rte_vfio_get_group_num(const char *sysfs_base, + const char *dev_addr, int *iommu_group_num) { char linkname[PATH_MAX]; char filename[PATH_MAX]; @@ -655,7 +655,7 @@ vfio_get_group_no(const char *sysfs_base, errno = 0; group_tok = tok[ret - 1]; end = group_tok; - *iommu_group_no = strtol(group_tok, &end, 10); + *iommu_group_num = strtol(group_tok, &end, 10); if ((end != group_tok && *end != '\0') || errno != 0) { RTE_LOG(ERR, EAL, " %s error parsing IOMMU number!\n", dev_addr); return -1; diff --git a/lib/librte_eal/linuxapp/eal/eal_vfio.h b/lib/librte_eal/linuxapp/eal/eal_vfio.h index 8059577..c72b76c 100644 --- a/lib/librte_eal/linuxapp/eal/eal_vfio.h +++ b/lib/librte_eal/linuxapp/eal/eal_vfio.h @@ -79,12 +79,6 @@ struct vfio_iommu_spapr_tce_info { #define RTE_VFIO_SPAPR VFIO_SPAPR_TCE_v2_IOMMU #endif -#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 5, 0) -#define RTE_VFIO_NOIOMMU 8 -#else -#define RTE_VFIO_NOIOMMU VFIO_NOIOMMU_IOMMU -#endif - #define VFIO_MAX_GROUPS RTE_MAX_VFIO_GROUPS /* @@ -133,21 +127,6 @@ vfio_set_iommu_type(int vfio_container_fd); int vfio_has_supported_extensions(int vfio_container_fd); -/* open container fd or get an existing one */ -int -vfio_get_container_fd(void); - -/* parse IOMMU group number for a device - * returns 1 on success, -1 for errors, 0 for non-existent group - */ -int -vfio_get_group_no(const char *sysfs_base, - const char *dev_addr, int *iommu_group_no); - -/* open group fd or get an existing one */ -int -vfio_get_group_fd(int iommu_group_no); - int vfio_mp_sync_setup(void); #define SOCKET_REQ_CONTAINER 0x100 diff --git a/lib/librte_eal/linuxapp/eal/eal_vfio_mp_sync.c b/lib/librte_eal/linuxapp/eal/eal_vfio_mp_sync.c index 7cc3c15..e19b571 100644 --- a/lib/librte_eal/linuxapp/eal/eal_vfio_mp_sync.c +++ b/lib/librte_eal/linuxapp/eal/eal_vfio_mp_sync.c @@ -267,7 +267,7 @@ vfio_mp_sync_thread(void __rte_unused * arg) switch (ret) { case SOCKET_REQ_CONTAINER: - fd = vfio_get_container_fd(); + fd = rte_vfio_get_container_fd(); if (fd < 0) vfio_mp_sync_send_request(conn_sock, SOCKET_ERR); else @@ -283,7 +283,7 @@ vfio_mp_sync_thread(void __rte_unused * arg) continue; } - fd = vfio_get_group_fd(vfio_data); + fd = rte_vfio_get_group_fd(vfio_data); if (fd < 0) vfio_mp_sync_send_request(conn_sock, SOCKET_ERR); diff --git a/lib/librte_eal/rte_eal_version.map b/lib/librte_eal/rte_eal_version.map index f331f54..f663b8b 100644 --- a/lib/librte_eal/rte_eal_version.map +++ b/lib/librte_eal/rte_eal_version.map @@ -255,5 +255,8 @@ EXPERIMENTAL { rte_service_set_runstate_mapped_check; rte_service_set_stats_enable; rte_service_start_with_defaults; + rte_vfio_get_group_num; + rte_vfio_get_container_fd; + rte_vfio_get_group_fd; } DPDK_18.02; -- 2.7.4 ^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [dpdk-dev] [PATCH v4 2/2] eal/vfio: export internal vfio functions 2018-04-03 11:10 ` [dpdk-dev] [PATCH v4 2/2] eal/vfio: export internal vfio functions Hemant Agrawal @ 2018-04-03 12:24 ` Thomas Monjalon 2018-04-03 12:59 ` Hemant Agrawal 2018-04-03 15:23 ` Wang, Xiao W 1 sibling, 1 reply; 27+ messages in thread From: Thomas Monjalon @ 2018-04-03 12:24 UTC (permalink / raw) To: Hemant Agrawal; +Cc: dev, anatoly.burakov 03/04/2018 13:10, Hemant Agrawal: > --- a/lib/librte_eal/rte_eal_version.map > +++ b/lib/librte_eal/rte_eal_version.map > @@ -255,5 +255,8 @@ EXPERIMENTAL { > rte_service_set_runstate_mapped_check; > rte_service_set_stats_enable; > rte_service_start_with_defaults; > + rte_vfio_get_group_num; > + rte_vfio_get_container_fd; > + rte_vfio_get_group_fd; The alphabetical order is messed. I can fix it on apply. ^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [dpdk-dev] [PATCH v4 2/2] eal/vfio: export internal vfio functions 2018-04-03 12:24 ` Thomas Monjalon @ 2018-04-03 12:59 ` Hemant Agrawal 0 siblings, 0 replies; 27+ messages in thread From: Hemant Agrawal @ 2018-04-03 12:59 UTC (permalink / raw) To: Thomas Monjalon, Hemant Agrawal; +Cc: dev, anatoly.burakov On 4/3/2018 5:54 PM, Thomas Monjalon wrote: > 03/04/2018 13:10, Hemant Agrawal: >> --- a/lib/librte_eal/rte_eal_version.map >> +++ b/lib/librte_eal/rte_eal_version.map >> @@ -255,5 +255,8 @@ EXPERIMENTAL { >> rte_service_set_runstate_mapped_check; >> rte_service_set_stats_enable; >> rte_service_start_with_defaults; >> + rte_vfio_get_group_num; >> + rte_vfio_get_container_fd; >> + rte_vfio_get_group_fd; > > The alphabetical order is messed. > I can fix it on apply. > > Thanks! ^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [dpdk-dev] [PATCH v4 2/2] eal/vfio: export internal vfio functions 2018-04-03 11:10 ` [dpdk-dev] [PATCH v4 2/2] eal/vfio: export internal vfio functions Hemant Agrawal 2018-04-03 12:24 ` Thomas Monjalon @ 2018-04-03 15:23 ` Wang, Xiao W 2018-04-04 6:47 ` Hemant Agrawal 1 sibling, 1 reply; 27+ messages in thread From: Wang, Xiao W @ 2018-04-03 15:23 UTC (permalink / raw) To: Hemant Agrawal, dev; +Cc: Burakov, Anatoly, thomas Hi Hemant, > -----Original Message----- > From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Hemant Agrawal > Sent: Tuesday, April 3, 2018 7:10 PM > To: dev@dpdk.org > Cc: Burakov, Anatoly <anatoly.burakov@intel.com>; thomas@monjalon.net > Subject: [dpdk-dev] [PATCH v4 2/2] eal/vfio: export internal vfio functions > > This patch moves some of the internal vfio functions from > eal_vfio.h to rte_vfio.h for common uses with "rte_" prefix. > > This patch also change the FSLMC bus usages from the internal > VFIO functions to external ones with "rte_" prefix > > Signed-off-by: Hemant Agrawal <hemant.agrawal@nxp.com> > Acked-by: Anatoly Burakov <anatoly.burakov@intel.com> > --- > drivers/bus/fslmc/Makefile | 1 - > drivers/bus/fslmc/fslmc_vfio.c | 7 +-- > drivers/bus/fslmc/fslmc_vfio.h | 2 - > drivers/bus/fslmc/meson.build | 1 - > lib/librte_eal/bsdapp/eal/eal.c | 20 +++++++ > lib/librte_eal/common/include/rte_vfio.h | 75 > +++++++++++++++++++++++++- > lib/librte_eal/linuxapp/eal/eal_vfio.c | 38 ++++++------- > lib/librte_eal/linuxapp/eal/eal_vfio.h | 21 -------- > lib/librte_eal/linuxapp/eal/eal_vfio_mp_sync.c | 4 +- > lib/librte_eal/rte_eal_version.map | 3 ++ > 10 files changed, 122 insertions(+), 50 deletions(-) > > diff --git a/drivers/bus/fslmc/Makefile b/drivers/bus/fslmc/Makefile > index 93870ba..3aa34e2 100644 > --- a/drivers/bus/fslmc/Makefile > +++ b/drivers/bus/fslmc/Makefile > @@ -16,7 +16,6 @@ CFLAGS += $(WERROR_FLAGS) > CFLAGS += -I$(RTE_SDK)/drivers/bus/fslmc > CFLAGS += -I$(RTE_SDK)/drivers/bus/fslmc/mc > CFLAGS += -I$(RTE_SDK)/drivers/bus/fslmc/qbman/include > -CFLAGS += -I$(RTE_SDK)/lib/librte_eal/linuxapp/eal > CFLAGS += -I$(RTE_SDK)/lib/librte_eal/common > LDLIBS += -lrte_eal -lrte_mbuf -lrte_mempool -lrte_ring > LDLIBS += -lrte_ethdev > diff --git a/drivers/bus/fslmc/fslmc_vfio.c b/drivers/bus/fslmc/fslmc_vfio.c > index 62499de..f3b2960 100644 > --- a/drivers/bus/fslmc/fslmc_vfio.c > +++ b/drivers/bus/fslmc/fslmc_vfio.c > @@ -91,7 +91,8 @@ fslmc_get_container_group(int *groupid) > } > > /* get group number */ > - ret = vfio_get_group_no(SYSFS_FSL_MC_DEVICES, g_container, > groupid); > + ret = rte_vfio_get_group_num(SYSFS_FSL_MC_DEVICES, > + g_container, groupid); > if (ret <= 0) { > DPAA2_BUS_ERR("Unable to find %s IOMMU group", > g_container); > return -1; > @@ -124,7 +125,7 @@ vfio_connect_container(void) > } > > /* Opens main vfio file descriptor which represents the "container" */ > - fd = vfio_get_container_fd(); > + fd = rte_vfio_get_container_fd(); > if (fd < 0) { > DPAA2_BUS_ERR("Failed to open VFIO container"); > return -errno; > @@ -620,7 +621,7 @@ fslmc_vfio_setup_group(void) > } > > /* Get the actual group fd */ > - ret = vfio_get_group_fd(groupid); > + ret = rte_vfio_get_group_fd(groupid); > if (ret < 0) > return ret; > vfio_group.fd = ret; > diff --git a/drivers/bus/fslmc/fslmc_vfio.h b/drivers/bus/fslmc/fslmc_vfio.h > index e8fb344..9e2c4fe 100644 > --- a/drivers/bus/fslmc/fslmc_vfio.h > +++ b/drivers/bus/fslmc/fslmc_vfio.h > @@ -10,8 +10,6 @@ > > #include <rte_vfio.h> > > -#include "eal_vfio.h" > - > #define DPAA2_MC_DPNI_DEVID 7 > #define DPAA2_MC_DPSECI_DEVID 3 > #define DPAA2_MC_DPCON_DEVID 5 > diff --git a/drivers/bus/fslmc/meson.build b/drivers/bus/fslmc/meson.build > index e94340e..78f9d92 100644 > --- a/drivers/bus/fslmc/meson.build > +++ b/drivers/bus/fslmc/meson.build > @@ -22,6 +22,5 @@ sources = files('fslmc_bus.c', > > allow_experimental_apis = true > > -includes += include_directories('../../../lib/librte_eal/linuxapp/eal') > includes += include_directories('mc', 'qbman/include', 'portal') > cflags += ['-D_GNU_SOURCE'] > diff --git a/lib/librte_eal/bsdapp/eal/eal.c b/lib/librte_eal/bsdapp/eal/eal.c > index 4eafcb5..ac23db5 100644 > --- a/lib/librte_eal/bsdapp/eal/eal.c > +++ b/lib/librte_eal/bsdapp/eal/eal.c > @@ -781,3 +781,23 @@ int rte_vfio_clear_group(__rte_unused int > vfio_group_fd) > { > return 0; > } > + > +int __rte_experimental > +rte_vfio_get_group_num(__rte_unused const char *sysfs_base, > + __rte_unused const char *dev_addr, > + __rte_unused int *iommu_group_num) > +{ > + return -1; > +} > + > +int __rte_experimental > +rte_vfio_get_container_fd(void) > +{ > + return -1; > +} > + > +int __rte_experimental > +rte_vfio_get_group_fd(__rte_unused int iommu_group_num) > +{ > + return -1; > +} No function declarations for the above 3 global API. I guess compile will fail in BSD. You may include the rte_vfio.h in this file, and remove the dummy prototype. My previous patch "eal/vfio: add support for multiple container" does this too. BRs, Xiao ^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [dpdk-dev] [PATCH v4 2/2] eal/vfio: export internal vfio functions 2018-04-03 15:23 ` Wang, Xiao W @ 2018-04-04 6:47 ` Hemant Agrawal 0 siblings, 0 replies; 27+ messages in thread From: Hemant Agrawal @ 2018-04-04 6:47 UTC (permalink / raw) To: Wang, Xiao W, dev; +Cc: Burakov, Anatoly, thomas > Hi Hemant, > > > -----Original Message----- > > From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Hemant Agrawal > > Sent: Tuesday, April 3, 2018 7:10 PM > > To: dev@dpdk.org > > Cc: Burakov, Anatoly <anatoly.burakov@intel.com>; thomas@monjalon.net > > Subject: [dpdk-dev] [PATCH v4 2/2] eal/vfio: export internal vfio > > functions > > > > This patch moves some of the internal vfio functions from eal_vfio.h > > to rte_vfio.h for common uses with "rte_" prefix. > > > > This patch also change the FSLMC bus usages from the internal VFIO > > functions to external ones with "rte_" prefix > > > > Signed-off-by: Hemant Agrawal <hemant.agrawal@nxp.com> > > Acked-by: Anatoly Burakov <anatoly.burakov@intel.com> > > --- > > drivers/bus/fslmc/Makefile | 1 - > > drivers/bus/fslmc/fslmc_vfio.c | 7 +-- > > drivers/bus/fslmc/fslmc_vfio.h | 2 - > > drivers/bus/fslmc/meson.build | 1 - > > lib/librte_eal/bsdapp/eal/eal.c | 20 +++++++ > > lib/librte_eal/common/include/rte_vfio.h | 75 > > +++++++++++++++++++++++++- > > lib/librte_eal/linuxapp/eal/eal_vfio.c | 38 ++++++------- > > lib/librte_eal/linuxapp/eal/eal_vfio.h | 21 -------- > > lib/librte_eal/linuxapp/eal/eal_vfio_mp_sync.c | 4 +- > > lib/librte_eal/rte_eal_version.map | 3 ++ > > 10 files changed, 122 insertions(+), 50 deletions(-) > > > > diff --git a/drivers/bus/fslmc/Makefile b/drivers/bus/fslmc/Makefile > > index 93870ba..3aa34e2 100644 > > --- a/drivers/bus/fslmc/Makefile > > +++ b/drivers/bus/fslmc/Makefile > > @@ -16,7 +16,6 @@ CFLAGS += $(WERROR_FLAGS) CFLAGS += > > -I$(RTE_SDK)/drivers/bus/fslmc CFLAGS += > > -I$(RTE_SDK)/drivers/bus/fslmc/mc CFLAGS += > > -I$(RTE_SDK)/drivers/bus/fslmc/qbman/include > > -CFLAGS += -I$(RTE_SDK)/lib/librte_eal/linuxapp/eal > > CFLAGS += -I$(RTE_SDK)/lib/librte_eal/common > > LDLIBS += -lrte_eal -lrte_mbuf -lrte_mempool -lrte_ring LDLIBS += > > -lrte_ethdev diff --git a/drivers/bus/fslmc/fslmc_vfio.c > > b/drivers/bus/fslmc/fslmc_vfio.c index 62499de..f3b2960 100644 > > --- a/drivers/bus/fslmc/fslmc_vfio.c > > +++ b/drivers/bus/fslmc/fslmc_vfio.c > > @@ -91,7 +91,8 @@ fslmc_get_container_group(int *groupid) > > } > > > > /* get group number */ > > - ret = vfio_get_group_no(SYSFS_FSL_MC_DEVICES, g_container, > > groupid); > > + ret = rte_vfio_get_group_num(SYSFS_FSL_MC_DEVICES, > > + g_container, groupid); > > if (ret <= 0) { > > DPAA2_BUS_ERR("Unable to find %s IOMMU group", > g_container); > > return -1; > > @@ -124,7 +125,7 @@ vfio_connect_container(void) > > } > > > > /* Opens main vfio file descriptor which represents the "container" */ > > - fd = vfio_get_container_fd(); > > + fd = rte_vfio_get_container_fd(); > > if (fd < 0) { > > DPAA2_BUS_ERR("Failed to open VFIO container"); > > return -errno; > > @@ -620,7 +621,7 @@ fslmc_vfio_setup_group(void) > > } > > > > /* Get the actual group fd */ > > - ret = vfio_get_group_fd(groupid); > > + ret = rte_vfio_get_group_fd(groupid); > > if (ret < 0) > > return ret; > > vfio_group.fd = ret; > > diff --git a/drivers/bus/fslmc/fslmc_vfio.h > > b/drivers/bus/fslmc/fslmc_vfio.h index e8fb344..9e2c4fe 100644 > > --- a/drivers/bus/fslmc/fslmc_vfio.h > > +++ b/drivers/bus/fslmc/fslmc_vfio.h > > @@ -10,8 +10,6 @@ > > > > #include <rte_vfio.h> > > > > -#include "eal_vfio.h" > > - > > #define DPAA2_MC_DPNI_DEVID 7 > > #define DPAA2_MC_DPSECI_DEVID 3 > > #define DPAA2_MC_DPCON_DEVID 5 > > diff --git a/drivers/bus/fslmc/meson.build > > b/drivers/bus/fslmc/meson.build index e94340e..78f9d92 100644 > > --- a/drivers/bus/fslmc/meson.build > > +++ b/drivers/bus/fslmc/meson.build > > @@ -22,6 +22,5 @@ sources = files('fslmc_bus.c', > > > > allow_experimental_apis = true > > > > -includes += > > include_directories('../../../lib/librte_eal/linuxapp/eal') > > includes += include_directories('mc', 'qbman/include', 'portal') > > cflags += ['-D_GNU_SOURCE'] diff --git > > a/lib/librte_eal/bsdapp/eal/eal.c b/lib/librte_eal/bsdapp/eal/eal.c > > index 4eafcb5..ac23db5 100644 > > --- a/lib/librte_eal/bsdapp/eal/eal.c > > +++ b/lib/librte_eal/bsdapp/eal/eal.c > > @@ -781,3 +781,23 @@ int rte_vfio_clear_group(__rte_unused int > > vfio_group_fd) > > { > > return 0; > > } > > + > > +int __rte_experimental > > +rte_vfio_get_group_num(__rte_unused const char *sysfs_base, > > + __rte_unused const char *dev_addr, > > + __rte_unused int *iommu_group_num) { > > + return -1; > > +} > > + > > +int __rte_experimental > > +rte_vfio_get_container_fd(void) > > +{ > > + return -1; > > +} > > + > > +int __rte_experimental > > +rte_vfio_get_group_fd(__rte_unused int iommu_group_num) { > > + return -1; > > +} > > No function declarations for the above 3 global API. I guess compile will fail in > BSD. > You may include the rte_vfio.h in this file, and remove the dummy prototype. > My previous patch "eal/vfio: add support for multiple container" does this too. > [Hemant] Just saw it. Fixing it. > BRs, > Xiao ^ permalink raw reply [flat|nested] 27+ messages in thread
* [dpdk-dev] [PATCH v5 1/2] doc: add vfio api support 2018-04-03 11:10 ` [dpdk-dev] [PATCH v4 " Hemant Agrawal 2018-04-03 11:10 ` [dpdk-dev] [PATCH v4 2/2] eal/vfio: export internal vfio functions Hemant Agrawal @ 2018-04-04 7:48 ` Hemant Agrawal 2018-04-04 7:48 ` [dpdk-dev] [PATCH v5 2/2] eal/vfio: export internal vfio functions Hemant Agrawal 2018-04-12 6:23 ` [dpdk-dev] [PATCH v6 1/2] doc: add vfio api support Hemant Agrawal 1 sibling, 2 replies; 27+ messages in thread From: Hemant Agrawal @ 2018-04-04 7:48 UTC (permalink / raw) To: dev; +Cc: anatoly.burakov, thomas Signed-off-by: Hemant Agrawal <hemant.agrawal@nxp.com> --- doc/api/doxy-api-index.md | 3 ++- doc/api/doxy-api.conf | 1 + lib/librte_eal/common/include/rte_vfio.h | 5 +++++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/doc/api/doxy-api-index.md b/doc/api/doxy-api-index.md index d77f205..d21f2d9 100644 --- a/doc/api/doxy-api-index.md +++ b/doc/api/doxy-api-index.md @@ -52,7 +52,8 @@ The public API headers are grouped by topics: [bitrate] (@ref rte_bitrate.h), [latency] (@ref rte_latencystats.h), [devargs] (@ref rte_devargs.h), - [PCI] (@ref rte_pci.h) + [PCI] (@ref rte_pci.h), + [vfio] (@ref rte_vfio.h) - **device specific**: [softnic] (@ref rte_eth_softnic.h), diff --git a/doc/api/doxy-api.conf b/doc/api/doxy-api.conf index cda52fd..ad8bdcf 100644 --- a/doc/api/doxy-api.conf +++ b/doc/api/doxy-api.conf @@ -82,6 +82,7 @@ INPUT = doc/api/doxy-api-index.md \ FILE_PATTERNS = rte_*.h \ cmdline.h PREDEFINED = __DOXYGEN__ \ + VFIO_PRESENT \ __attribute__(x)= OPTIMIZE_OUTPUT_FOR_C = YES diff --git a/lib/librte_eal/common/include/rte_vfio.h b/lib/librte_eal/common/include/rte_vfio.h index 249095e..9b7b983 100644 --- a/lib/librte_eal/common/include/rte_vfio.h +++ b/lib/librte_eal/common/include/rte_vfio.h @@ -5,6 +5,11 @@ #ifndef _RTE_VFIO_H_ #define _RTE_VFIO_H_ +/** + * @file + * RTE VFIO. This library provides various VFIO related utility functions. + */ + /* * determine if VFIO is present on the system */ -- 2.7.4 ^ permalink raw reply [flat|nested] 27+ messages in thread
* [dpdk-dev] [PATCH v5 2/2] eal/vfio: export internal vfio functions 2018-04-04 7:48 ` [dpdk-dev] [PATCH v5 1/2] doc: add vfio api support Hemant Agrawal @ 2018-04-04 7:48 ` Hemant Agrawal 2018-04-05 9:03 ` Wang, Xiao W 2018-04-11 21:25 ` Thomas Monjalon 2018-04-12 6:23 ` [dpdk-dev] [PATCH v6 1/2] doc: add vfio api support Hemant Agrawal 1 sibling, 2 replies; 27+ messages in thread From: Hemant Agrawal @ 2018-04-04 7:48 UTC (permalink / raw) To: dev; +Cc: anatoly.burakov, thomas This patch moves some of the internal vfio functions from eal_vfio.h to rte_vfio.h for common uses with "rte_" prefix. This patch also change the FSLMC bus usages from the internal VFIO functions to external ones with "rte_" prefix Signed-off-by: Hemant Agrawal <hemant.agrawal@nxp.com> Acked-by: Anatoly Burakov <anatoly.burakov@intel.com> --- v5: fix the bsd compilation drivers/bus/fslmc/Makefile | 1 - drivers/bus/fslmc/fslmc_vfio.c | 7 +-- drivers/bus/fslmc/fslmc_vfio.h | 2 - drivers/bus/fslmc/meson.build | 1 - lib/librte_eal/bsdapp/eal/eal.c | 24 +++++++++ lib/librte_eal/common/include/rte_vfio.h | 75 +++++++++++++++++++++++++- lib/librte_eal/linuxapp/eal/eal_vfio.c | 39 +++++++------- lib/librte_eal/linuxapp/eal/eal_vfio.h | 21 -------- lib/librte_eal/linuxapp/eal/eal_vfio_mp_sync.c | 4 +- lib/librte_eal/rte_eal_version.map | 3 ++ 10 files changed, 127 insertions(+), 50 deletions(-) diff --git a/drivers/bus/fslmc/Makefile b/drivers/bus/fslmc/Makefile index 93870ba..3aa34e2 100644 --- a/drivers/bus/fslmc/Makefile +++ b/drivers/bus/fslmc/Makefile @@ -16,7 +16,6 @@ CFLAGS += $(WERROR_FLAGS) CFLAGS += -I$(RTE_SDK)/drivers/bus/fslmc CFLAGS += -I$(RTE_SDK)/drivers/bus/fslmc/mc CFLAGS += -I$(RTE_SDK)/drivers/bus/fslmc/qbman/include -CFLAGS += -I$(RTE_SDK)/lib/librte_eal/linuxapp/eal CFLAGS += -I$(RTE_SDK)/lib/librte_eal/common LDLIBS += -lrte_eal -lrte_mbuf -lrte_mempool -lrte_ring LDLIBS += -lrte_ethdev diff --git a/drivers/bus/fslmc/fslmc_vfio.c b/drivers/bus/fslmc/fslmc_vfio.c index 62499de..f3b2960 100644 --- a/drivers/bus/fslmc/fslmc_vfio.c +++ b/drivers/bus/fslmc/fslmc_vfio.c @@ -91,7 +91,8 @@ fslmc_get_container_group(int *groupid) } /* get group number */ - ret = vfio_get_group_no(SYSFS_FSL_MC_DEVICES, g_container, groupid); + ret = rte_vfio_get_group_num(SYSFS_FSL_MC_DEVICES, + g_container, groupid); if (ret <= 0) { DPAA2_BUS_ERR("Unable to find %s IOMMU group", g_container); return -1; @@ -124,7 +125,7 @@ vfio_connect_container(void) } /* Opens main vfio file descriptor which represents the "container" */ - fd = vfio_get_container_fd(); + fd = rte_vfio_get_container_fd(); if (fd < 0) { DPAA2_BUS_ERR("Failed to open VFIO container"); return -errno; @@ -620,7 +621,7 @@ fslmc_vfio_setup_group(void) } /* Get the actual group fd */ - ret = vfio_get_group_fd(groupid); + ret = rte_vfio_get_group_fd(groupid); if (ret < 0) return ret; vfio_group.fd = ret; diff --git a/drivers/bus/fslmc/fslmc_vfio.h b/drivers/bus/fslmc/fslmc_vfio.h index e8fb344..9e2c4fe 100644 --- a/drivers/bus/fslmc/fslmc_vfio.h +++ b/drivers/bus/fslmc/fslmc_vfio.h @@ -10,8 +10,6 @@ #include <rte_vfio.h> -#include "eal_vfio.h" - #define DPAA2_MC_DPNI_DEVID 7 #define DPAA2_MC_DPSECI_DEVID 3 #define DPAA2_MC_DPCON_DEVID 5 diff --git a/drivers/bus/fslmc/meson.build b/drivers/bus/fslmc/meson.build index e94340e..78f9d92 100644 --- a/drivers/bus/fslmc/meson.build +++ b/drivers/bus/fslmc/meson.build @@ -22,6 +22,5 @@ sources = files('fslmc_bus.c', allow_experimental_apis = true -includes += include_directories('../../../lib/librte_eal/linuxapp/eal') includes += include_directories('mc', 'qbman/include', 'portal') cflags += ['-D_GNU_SOURCE'] diff --git a/lib/librte_eal/bsdapp/eal/eal.c b/lib/librte_eal/bsdapp/eal/eal.c index 4eafcb5..e2f2df1 100644 --- a/lib/librte_eal/bsdapp/eal/eal.c +++ b/lib/librte_eal/bsdapp/eal/eal.c @@ -746,6 +746,10 @@ int rte_vfio_enable(const char *modname); int rte_vfio_is_enabled(const char *modname); int rte_vfio_noiommu_is_enabled(void); int rte_vfio_clear_group(int vfio_group_fd); +int rte_vfio_get_group_num(const char *sysfs_base, const char *dev_addr, + int *iommu_group_num); +int rte_vfio_get_container_fd(void); +int rte_vfio_get_group_fd(int iommu_group_num); int rte_vfio_setup_device(__rte_unused const char *sysfs_base, __rte_unused const char *dev_addr, @@ -781,3 +785,23 @@ int rte_vfio_clear_group(__rte_unused int vfio_group_fd) { return 0; } + +int __rte_experimental +rte_vfio_get_group_num(__rte_unused const char *sysfs_base, + __rte_unused const char *dev_addr, + __rte_unused int *iommu_group_num) +{ + return -1; +} + +int __rte_experimental +rte_vfio_get_container_fd(void) +{ + return -1; +} + +int __rte_experimental +rte_vfio_get_group_fd(__rte_unused int iommu_group_num) +{ + return -1; +} diff --git a/lib/librte_eal/common/include/rte_vfio.h b/lib/librte_eal/common/include/rte_vfio.h index 9b7b983..9369b42 100644 --- a/lib/librte_eal/common/include/rte_vfio.h +++ b/lib/librte_eal/common/include/rte_vfio.h @@ -37,6 +37,13 @@ extern "C" { #endif +/* NOIOMMU is defined from kernel version 4.5 onwards */ +#ifdef VFIO_NOIOMMU_IOMMU +#define RTE_VFIO_NOIOMMU VFIO_NOIOMMU_IOMMU +#else +#define RTE_VFIO_NOIOMMU 8 +#endif + /** * Setup vfio_cfg for the device identified by its address. * It discovers the configured I/O MMU groups or sets a new one for the device. @@ -128,10 +135,76 @@ int rte_vfio_is_enabled(const char *modname); */ int rte_vfio_noiommu_is_enabled(void); -/* remove group fd from internal VFIO group fd array */ +/** + * Remove group fd from internal VFIO group fd array/ + * + * This function is only relevant to linux and will return + * an error on BSD. + * + * @param vfio_group_fd + * VFIO Grouup FD. + * + * @return + * 0 on success. + * <0 on failure. + */ int rte_vfio_clear_group(int vfio_group_fd); +/** + * Parse IOMMU group number for a device + * + * This function is only relevant to linux and will return + * an error on BSD. + * + * @param sysfs_base + * sysfs path prefix. + * + * @param dev_addr + * device location. + * + * @param iommu_group_num + * iommu group number + * + * @return + * >0 on success + * 0 for non-existent group or VFIO + * <0 for errors + */ +int __rte_experimental +rte_vfio_get_group_num(const char *sysfs_base, + const char *dev_addr, + int *iommu_group_num); + +/** + * Open VFIO container fd or get an existing one + * + * This function is only relevant to linux and will return + * an error on BSD. + * + * @return + * > 0 container fd + * < 0 for errors + */ +int __rte_experimental +rte_vfio_get_container_fd(void); + +/** + * Open VFIO group fd or get an existing one + * + * This function is only relevant to linux and will return + * an error on BSD. + * + * @param iommu_group_num + * iommu group number + * + * @return + * > 0 group fd + * < 0 for errors + */ +int __rte_experimental +rte_vfio_get_group_fd(int iommu_group_num); + #ifdef __cplusplus } #endif diff --git a/lib/librte_eal/linuxapp/eal/eal_vfio.c b/lib/librte_eal/linuxapp/eal/eal_vfio.c index e44ae4d..6021872 100644 --- a/lib/librte_eal/linuxapp/eal/eal_vfio.c +++ b/lib/librte_eal/linuxapp/eal/eal_vfio.c @@ -36,7 +36,7 @@ static const struct vfio_iommu_type iommu_types[] = { }; int -vfio_get_group_fd(int iommu_group_no) +rte_vfio_get_group_fd(int iommu_group_num) { int i; int vfio_group_fd; @@ -45,7 +45,7 @@ vfio_get_group_fd(int iommu_group_no) /* check if we already have the group descriptor open */ for (i = 0; i < VFIO_MAX_GROUPS; i++) - if (vfio_cfg.vfio_groups[i].group_no == iommu_group_no) + if (vfio_cfg.vfio_groups[i].group_no == iommu_group_num) return vfio_cfg.vfio_groups[i].fd; /* Lets see first if there is room for a new group */ @@ -70,7 +70,7 @@ vfio_get_group_fd(int iommu_group_no) if (internal_config.process_type == RTE_PROC_PRIMARY) { /* try regular group format */ snprintf(filename, sizeof(filename), - VFIO_GROUP_FMT, iommu_group_no); + VFIO_GROUP_FMT, iommu_group_num); vfio_group_fd = open(filename, O_RDWR); if (vfio_group_fd < 0) { /* if file not found, it's not an error */ @@ -82,7 +82,8 @@ vfio_get_group_fd(int iommu_group_no) /* special case: try no-IOMMU path as well */ snprintf(filename, sizeof(filename), - VFIO_NOIOMMU_GROUP_FMT, iommu_group_no); + VFIO_NOIOMMU_GROUP_FMT, + iommu_group_num); vfio_group_fd = open(filename, O_RDWR); if (vfio_group_fd < 0) { if (errno != ENOENT) { @@ -95,7 +96,7 @@ vfio_get_group_fd(int iommu_group_no) /* noiommu group found */ } - cur_grp->group_no = iommu_group_no; + cur_grp->group_no = iommu_group_num; cur_grp->fd = vfio_group_fd; vfio_cfg.vfio_active_groups++; return vfio_group_fd; @@ -117,7 +118,7 @@ vfio_get_group_fd(int iommu_group_no) close(socket_fd); return -1; } - if (vfio_mp_sync_send_request(socket_fd, iommu_group_no) < 0) { + if (vfio_mp_sync_send_request(socket_fd, iommu_group_num) < 0) { RTE_LOG(ERR, EAL, " cannot send group number!\n"); close(socket_fd); return -1; @@ -132,7 +133,7 @@ vfio_get_group_fd(int iommu_group_no) /* if we got the fd, store it and return it */ if (vfio_group_fd > 0) { close(socket_fd); - cur_grp->group_no = iommu_group_no; + cur_grp->group_no = iommu_group_num; cur_grp->fd = vfio_group_fd; vfio_cfg.vfio_active_groups++; return vfio_group_fd; @@ -262,11 +263,11 @@ rte_vfio_setup_device(const char *sysfs_base, const char *dev_addr, .argsz = sizeof(group_status) }; int vfio_group_fd; - int iommu_group_no; + int iommu_group_num; int ret; /* get group number */ - ret = vfio_get_group_no(sysfs_base, dev_addr, &iommu_group_no); + ret = rte_vfio_get_group_num(sysfs_base, dev_addr, &iommu_group_num); if (ret == 0) { RTE_LOG(WARNING, EAL, " %s not managed by VFIO driver, skipping\n", dev_addr); @@ -278,7 +279,7 @@ rte_vfio_setup_device(const char *sysfs_base, const char *dev_addr, return -1; /* get the actual group fd */ - vfio_group_fd = vfio_get_group_fd(iommu_group_no); + vfio_group_fd = rte_vfio_get_group_fd(iommu_group_num); if (vfio_group_fd < 0) return -1; @@ -394,11 +395,11 @@ rte_vfio_release_device(const char *sysfs_base, const char *dev_addr, .argsz = sizeof(group_status) }; int vfio_group_fd; - int iommu_group_no; + int iommu_group_num; int ret; /* get group number */ - ret = vfio_get_group_no(sysfs_base, dev_addr, &iommu_group_no); + ret = rte_vfio_get_group_num(sysfs_base, dev_addr, &iommu_group_num); if (ret <= 0) { RTE_LOG(WARNING, EAL, " %s not managed by VFIO driver\n", dev_addr); @@ -407,9 +408,9 @@ rte_vfio_release_device(const char *sysfs_base, const char *dev_addr, } /* get the actual group fd */ - vfio_group_fd = vfio_get_group_fd(iommu_group_no); + vfio_group_fd = rte_vfio_get_group_fd(iommu_group_num); if (vfio_group_fd <= 0) { - RTE_LOG(INFO, EAL, "vfio_get_group_fd failed for %s\n", + RTE_LOG(INFO, EAL, "rte_vfio_get_group_fd failed for %s\n", dev_addr); return -1; } @@ -480,7 +481,7 @@ rte_vfio_enable(const char *modname) return 0; } - vfio_cfg.vfio_container_fd = vfio_get_container_fd(); + vfio_cfg.vfio_container_fd = rte_vfio_get_container_fd(); /* check if we have VFIO driver enabled */ if (vfio_cfg.vfio_container_fd != -1) { @@ -558,7 +559,7 @@ vfio_has_supported_extensions(int vfio_container_fd) } int -vfio_get_container_fd(void) +rte_vfio_get_container_fd(void) { int ret, vfio_container_fd; @@ -622,8 +623,8 @@ vfio_get_container_fd(void) } int -vfio_get_group_no(const char *sysfs_base, - const char *dev_addr, int *iommu_group_no) +rte_vfio_get_group_num(const char *sysfs_base, + const char *dev_addr, int *iommu_group_num) { char linkname[PATH_MAX]; char filename[PATH_MAX]; @@ -655,7 +656,7 @@ vfio_get_group_no(const char *sysfs_base, errno = 0; group_tok = tok[ret - 1]; end = group_tok; - *iommu_group_no = strtol(group_tok, &end, 10); + *iommu_group_num = strtol(group_tok, &end, 10); if ((end != group_tok && *end != '\0') || errno != 0) { RTE_LOG(ERR, EAL, " %s error parsing IOMMU number!\n", dev_addr); return -1; diff --git a/lib/librte_eal/linuxapp/eal/eal_vfio.h b/lib/librte_eal/linuxapp/eal/eal_vfio.h index 8059577..c72b76c 100644 --- a/lib/librte_eal/linuxapp/eal/eal_vfio.h +++ b/lib/librte_eal/linuxapp/eal/eal_vfio.h @@ -79,12 +79,6 @@ struct vfio_iommu_spapr_tce_info { #define RTE_VFIO_SPAPR VFIO_SPAPR_TCE_v2_IOMMU #endif -#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 5, 0) -#define RTE_VFIO_NOIOMMU 8 -#else -#define RTE_VFIO_NOIOMMU VFIO_NOIOMMU_IOMMU -#endif - #define VFIO_MAX_GROUPS RTE_MAX_VFIO_GROUPS /* @@ -133,21 +127,6 @@ vfio_set_iommu_type(int vfio_container_fd); int vfio_has_supported_extensions(int vfio_container_fd); -/* open container fd or get an existing one */ -int -vfio_get_container_fd(void); - -/* parse IOMMU group number for a device - * returns 1 on success, -1 for errors, 0 for non-existent group - */ -int -vfio_get_group_no(const char *sysfs_base, - const char *dev_addr, int *iommu_group_no); - -/* open group fd or get an existing one */ -int -vfio_get_group_fd(int iommu_group_no); - int vfio_mp_sync_setup(void); #define SOCKET_REQ_CONTAINER 0x100 diff --git a/lib/librte_eal/linuxapp/eal/eal_vfio_mp_sync.c b/lib/librte_eal/linuxapp/eal/eal_vfio_mp_sync.c index 7cc3c15..e19b571 100644 --- a/lib/librte_eal/linuxapp/eal/eal_vfio_mp_sync.c +++ b/lib/librte_eal/linuxapp/eal/eal_vfio_mp_sync.c @@ -267,7 +267,7 @@ vfio_mp_sync_thread(void __rte_unused * arg) switch (ret) { case SOCKET_REQ_CONTAINER: - fd = vfio_get_container_fd(); + fd = rte_vfio_get_container_fd(); if (fd < 0) vfio_mp_sync_send_request(conn_sock, SOCKET_ERR); else @@ -283,7 +283,7 @@ vfio_mp_sync_thread(void __rte_unused * arg) continue; } - fd = vfio_get_group_fd(vfio_data); + fd = rte_vfio_get_group_fd(vfio_data); if (fd < 0) vfio_mp_sync_send_request(conn_sock, SOCKET_ERR); diff --git a/lib/librte_eal/rte_eal_version.map b/lib/librte_eal/rte_eal_version.map index f331f54..60871cc 100644 --- a/lib/librte_eal/rte_eal_version.map +++ b/lib/librte_eal/rte_eal_version.map @@ -255,5 +255,8 @@ EXPERIMENTAL { rte_service_set_runstate_mapped_check; rte_service_set_stats_enable; rte_service_start_with_defaults; + rte_vfio_get_container_fd; + rte_vfio_get_group_fd; + rte_vfio_get_group_num; } DPDK_18.02; -- 2.7.4 ^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [dpdk-dev] [PATCH v5 2/2] eal/vfio: export internal vfio functions 2018-04-04 7:48 ` [dpdk-dev] [PATCH v5 2/2] eal/vfio: export internal vfio functions Hemant Agrawal @ 2018-04-05 9:03 ` Wang, Xiao W 2018-04-05 10:22 ` Thomas Monjalon 2018-04-11 21:25 ` Thomas Monjalon 1 sibling, 1 reply; 27+ messages in thread From: Wang, Xiao W @ 2018-04-05 9:03 UTC (permalink / raw) To: Hemant Agrawal, dev; +Cc: Burakov, Anatoly, thomas Hi Hemant, > -----Original Message----- > From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Hemant Agrawal > Sent: Wednesday, April 4, 2018 3:49 PM > To: dev@dpdk.org > Cc: Burakov, Anatoly <anatoly.burakov@intel.com>; thomas@monjalon.net > Subject: [dpdk-dev] [PATCH v5 2/2] eal/vfio: export internal vfio functions > > This patch moves some of the internal vfio functions from > eal_vfio.h to rte_vfio.h for common uses with "rte_" prefix. > > This patch also change the FSLMC bus usages from the internal > VFIO functions to external ones with "rte_" prefix > > Signed-off-by: Hemant Agrawal <hemant.agrawal@nxp.com> > Acked-by: Anatoly Burakov <anatoly.burakov@intel.com> > --- > v5: fix the bsd compilation > > drivers/bus/fslmc/Makefile | 1 - > drivers/bus/fslmc/fslmc_vfio.c | 7 +-- > drivers/bus/fslmc/fslmc_vfio.h | 2 - > drivers/bus/fslmc/meson.build | 1 - > lib/librte_eal/bsdapp/eal/eal.c | 24 +++++++++ > lib/librte_eal/common/include/rte_vfio.h | 75 > +++++++++++++++++++++++++- > lib/librte_eal/linuxapp/eal/eal_vfio.c | 39 +++++++------- > lib/librte_eal/linuxapp/eal/eal_vfio.h | 21 -------- > lib/librte_eal/linuxapp/eal/eal_vfio_mp_sync.c | 4 +- > lib/librte_eal/rte_eal_version.map | 3 ++ > 10 files changed, 127 insertions(+), 50 deletions(-) > > diff --git a/drivers/bus/fslmc/Makefile b/drivers/bus/fslmc/Makefile > index 93870ba..3aa34e2 100644 > --- a/drivers/bus/fslmc/Makefile > +++ b/drivers/bus/fslmc/Makefile > @@ -16,7 +16,6 @@ CFLAGS += $(WERROR_FLAGS) > CFLAGS += -I$(RTE_SDK)/drivers/bus/fslmc > CFLAGS += -I$(RTE_SDK)/drivers/bus/fslmc/mc > CFLAGS += -I$(RTE_SDK)/drivers/bus/fslmc/qbman/include > -CFLAGS += -I$(RTE_SDK)/lib/librte_eal/linuxapp/eal > CFLAGS += -I$(RTE_SDK)/lib/librte_eal/common > LDLIBS += -lrte_eal -lrte_mbuf -lrte_mempool -lrte_ring > LDLIBS += -lrte_ethdev > diff --git a/drivers/bus/fslmc/fslmc_vfio.c b/drivers/bus/fslmc/fslmc_vfio.c > index 62499de..f3b2960 100644 > --- a/drivers/bus/fslmc/fslmc_vfio.c > +++ b/drivers/bus/fslmc/fslmc_vfio.c > @@ -91,7 +91,8 @@ fslmc_get_container_group(int *groupid) > } > > /* get group number */ > - ret = vfio_get_group_no(SYSFS_FSL_MC_DEVICES, g_container, > groupid); > + ret = rte_vfio_get_group_num(SYSFS_FSL_MC_DEVICES, > + g_container, groupid); > if (ret <= 0) { > DPAA2_BUS_ERR("Unable to find %s IOMMU group", > g_container); > return -1; > @@ -124,7 +125,7 @@ vfio_connect_container(void) > } > > /* Opens main vfio file descriptor which represents the "container" */ > - fd = vfio_get_container_fd(); > + fd = rte_vfio_get_container_fd(); > if (fd < 0) { > DPAA2_BUS_ERR("Failed to open VFIO container"); > return -errno; > @@ -620,7 +621,7 @@ fslmc_vfio_setup_group(void) > } > > /* Get the actual group fd */ > - ret = vfio_get_group_fd(groupid); > + ret = rte_vfio_get_group_fd(groupid); > if (ret < 0) > return ret; > vfio_group.fd = ret; > diff --git a/drivers/bus/fslmc/fslmc_vfio.h b/drivers/bus/fslmc/fslmc_vfio.h > index e8fb344..9e2c4fe 100644 > --- a/drivers/bus/fslmc/fslmc_vfio.h > +++ b/drivers/bus/fslmc/fslmc_vfio.h > @@ -10,8 +10,6 @@ > > #include <rte_vfio.h> > > -#include "eal_vfio.h" > - > #define DPAA2_MC_DPNI_DEVID 7 > #define DPAA2_MC_DPSECI_DEVID 3 > #define DPAA2_MC_DPCON_DEVID 5 > diff --git a/drivers/bus/fslmc/meson.build b/drivers/bus/fslmc/meson.build > index e94340e..78f9d92 100644 > --- a/drivers/bus/fslmc/meson.build > +++ b/drivers/bus/fslmc/meson.build > @@ -22,6 +22,5 @@ sources = files('fslmc_bus.c', > > allow_experimental_apis = true > > -includes += include_directories('../../../lib/librte_eal/linuxapp/eal') > includes += include_directories('mc', 'qbman/include', 'portal') > cflags += ['-D_GNU_SOURCE'] > diff --git a/lib/librte_eal/bsdapp/eal/eal.c b/lib/librte_eal/bsdapp/eal/eal.c > index 4eafcb5..e2f2df1 100644 > --- a/lib/librte_eal/bsdapp/eal/eal.c > +++ b/lib/librte_eal/bsdapp/eal/eal.c > @@ -746,6 +746,10 @@ int rte_vfio_enable(const char *modname); > int rte_vfio_is_enabled(const char *modname); > int rte_vfio_noiommu_is_enabled(void); > int rte_vfio_clear_group(int vfio_group_fd); > +int rte_vfio_get_group_num(const char *sysfs_base, const char *dev_addr, > + int *iommu_group_num); > +int rte_vfio_get_container_fd(void); > +int rte_vfio_get_group_fd(int iommu_group_num); Considering the "group_no" field defined in eal_vfio.h, will "iommu_group_num" cause inconsistency In naming? /* * we don't need to store device fd's anywhere since they can be obtained from * the group fd via an ioctl() call. */ struct vfio_group { int group_no; int fd; int devices; }; BRs, Xiao ^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [dpdk-dev] [PATCH v5 2/2] eal/vfio: export internal vfio functions 2018-04-05 9:03 ` Wang, Xiao W @ 2018-04-05 10:22 ` Thomas Monjalon 2018-04-05 10:35 ` Wang, Xiao W 0 siblings, 1 reply; 27+ messages in thread From: Thomas Monjalon @ 2018-04-05 10:22 UTC (permalink / raw) To: Wang, Xiao W; +Cc: Hemant Agrawal, dev, Burakov, Anatoly 05/04/2018 11:03, Wang, Xiao W: > > +int rte_vfio_get_group_num(const char *sysfs_base, const char *dev_addr, > > + int *iommu_group_num); > > +int rte_vfio_get_container_fd(void); > > +int rte_vfio_get_group_fd(int iommu_group_num); > > Considering the "group_no" field defined in eal_vfio.h, will "iommu_group_num" cause inconsistency > In naming? I asked to change the function name to "num" because it is more meaningful. "group_no" field is private? Can it be renamed? ^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [dpdk-dev] [PATCH v5 2/2] eal/vfio: export internal vfio functions 2018-04-05 10:22 ` Thomas Monjalon @ 2018-04-05 10:35 ` Wang, Xiao W 0 siblings, 0 replies; 27+ messages in thread From: Wang, Xiao W @ 2018-04-05 10:35 UTC (permalink / raw) To: Thomas Monjalon; +Cc: Hemant Agrawal, dev, Burakov, Anatoly Yes, it's private. We could do that if really needed. BRs, Xiao > -----Original Message----- > From: Thomas Monjalon [mailto:thomas@monjalon.net] > Sent: Thursday, April 5, 2018 6:23 PM > To: Wang, Xiao W <xiao.w.wang@intel.com> > Cc: Hemant Agrawal <hemant.agrawal@nxp.com>; dev@dpdk.org; Burakov, > Anatoly <anatoly.burakov@intel.com> > Subject: Re: [dpdk-dev] [PATCH v5 2/2] eal/vfio: export internal vfio functions > > 05/04/2018 11:03, Wang, Xiao W: > > > > +int rte_vfio_get_group_num(const char *sysfs_base, const char > *dev_addr, > > > + int *iommu_group_num); > > > +int rte_vfio_get_container_fd(void); > > > +int rte_vfio_get_group_fd(int iommu_group_num); > > > > Considering the "group_no" field defined in eal_vfio.h, will > "iommu_group_num" cause inconsistency > > In naming? > > I asked to change the function name to "num" because it is more meaningful. > "group_no" field is private? Can it be renamed? > ^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [dpdk-dev] [PATCH v5 2/2] eal/vfio: export internal vfio functions 2018-04-04 7:48 ` [dpdk-dev] [PATCH v5 2/2] eal/vfio: export internal vfio functions Hemant Agrawal 2018-04-05 9:03 ` Wang, Xiao W @ 2018-04-11 21:25 ` Thomas Monjalon 2018-04-12 6:26 ` Hemant Agrawal 1 sibling, 1 reply; 27+ messages in thread From: Thomas Monjalon @ 2018-04-11 21:25 UTC (permalink / raw) To: Hemant Agrawal; +Cc: dev, anatoly.burakov 04/04/2018 09:48, Hemant Agrawal: > This patch moves some of the internal vfio functions from > eal_vfio.h to rte_vfio.h for common uses with "rte_" prefix. > > This patch also change the FSLMC bus usages from the internal > VFIO functions to external ones with "rte_" prefix > > Signed-off-by: Hemant Agrawal <hemant.agrawal@nxp.com> > Acked-by: Anatoly Burakov <anatoly.burakov@intel.com> > --- > v5: fix the bsd compilation > > drivers/bus/fslmc/Makefile | 1 - > drivers/bus/fslmc/fslmc_vfio.c | 7 +-- > drivers/bus/fslmc/fslmc_vfio.h | 2 - > drivers/bus/fslmc/meson.build | 1 - > lib/librte_eal/bsdapp/eal/eal.c | 24 +++++++++ > lib/librte_eal/common/include/rte_vfio.h | 75 +++++++++++++++++++++++++- > lib/librte_eal/linuxapp/eal/eal_vfio.c | 39 +++++++------- > lib/librte_eal/linuxapp/eal/eal_vfio.h | 21 -------- > lib/librte_eal/linuxapp/eal/eal_vfio_mp_sync.c | 4 +- > lib/librte_eal/rte_eal_version.map | 3 ++ > 10 files changed, 127 insertions(+), 50 deletions(-) Please, could you rebase on HEAD (on top of Anatoly's patches)? ^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [dpdk-dev] [PATCH v5 2/2] eal/vfio: export internal vfio functions 2018-04-11 21:25 ` Thomas Monjalon @ 2018-04-12 6:26 ` Hemant Agrawal 0 siblings, 0 replies; 27+ messages in thread From: Hemant Agrawal @ 2018-04-12 6:26 UTC (permalink / raw) To: Thomas Monjalon, Hemant Agrawal; +Cc: dev, anatoly.burakov > Please, could you rebase on HEAD (on top of Anatoly's patches)? > done > > ^ permalink raw reply [flat|nested] 27+ messages in thread
* [dpdk-dev] [PATCH v6 1/2] doc: add vfio api support 2018-04-04 7:48 ` [dpdk-dev] [PATCH v5 1/2] doc: add vfio api support Hemant Agrawal 2018-04-04 7:48 ` [dpdk-dev] [PATCH v5 2/2] eal/vfio: export internal vfio functions Hemant Agrawal @ 2018-04-12 6:23 ` Hemant Agrawal 2018-04-12 6:23 ` [dpdk-dev] [PATCH v6 2/2] eal/vfio: export internal vfio functions Hemant Agrawal 1 sibling, 1 reply; 27+ messages in thread From: Hemant Agrawal @ 2018-04-12 6:23 UTC (permalink / raw) To: dev; +Cc: anatoly.burakov, thomas Signed-off-by: Hemant Agrawal <hemant.agrawal@nxp.com> --- doc/api/doxy-api-index.md | 3 ++- doc/api/doxy-api.conf | 1 + lib/librte_eal/common/include/rte_vfio.h | 5 +++++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/doc/api/doxy-api-index.md b/doc/api/doxy-api-index.md index 2f04619..d5ccbe8 100644 --- a/doc/api/doxy-api-index.md +++ b/doc/api/doxy-api-index.md @@ -52,7 +52,8 @@ The public API headers are grouped by topics: [bitrate] (@ref rte_bitrate.h), [latency] (@ref rte_latencystats.h), [devargs] (@ref rte_devargs.h), - [PCI] (@ref rte_pci.h) + [PCI] (@ref rte_pci.h), + [vfio] (@ref rte_vfio.h) - **device specific**: [softnic] (@ref rte_eth_softnic.h), diff --git a/doc/api/doxy-api.conf b/doc/api/doxy-api.conf index cda52fd..ad8bdcf 100644 --- a/doc/api/doxy-api.conf +++ b/doc/api/doxy-api.conf @@ -82,6 +82,7 @@ INPUT = doc/api/doxy-api-index.md \ FILE_PATTERNS = rte_*.h \ cmdline.h PREDEFINED = __DOXYGEN__ \ + VFIO_PRESENT \ __attribute__(x)= OPTIMIZE_OUTPUT_FOR_C = YES diff --git a/lib/librte_eal/common/include/rte_vfio.h b/lib/librte_eal/common/include/rte_vfio.h index d26ab01..f363cac 100644 --- a/lib/librte_eal/common/include/rte_vfio.h +++ b/lib/librte_eal/common/include/rte_vfio.h @@ -5,6 +5,11 @@ #ifndef _RTE_VFIO_H_ #define _RTE_VFIO_H_ +/** + * @file + * RTE VFIO. This library provides various VFIO related utility functions. + */ + /* * determine if VFIO is present on the system */ -- 2.7.4 ^ permalink raw reply [flat|nested] 27+ messages in thread
* [dpdk-dev] [PATCH v6 2/2] eal/vfio: export internal vfio functions 2018-04-12 6:23 ` [dpdk-dev] [PATCH v6 1/2] doc: add vfio api support Hemant Agrawal @ 2018-04-12 6:23 ` Hemant Agrawal 2018-04-12 23:09 ` Thomas Monjalon 0 siblings, 1 reply; 27+ messages in thread From: Hemant Agrawal @ 2018-04-12 6:23 UTC (permalink / raw) To: dev; +Cc: anatoly.burakov, thomas This patch moves some of the internal vfio functions from eal_vfio.h to rte_vfio.h for common uses with "rte_" prefix. This patch also change the FSLMC bus usages from the internal VFIO functions to external ones with "rte_" prefix Signed-off-by: Hemant Agrawal <hemant.agrawal@nxp.com> Acked-by: Anatoly Burakov <anatoly.burakov@intel.com> --- v6: rebase on latest master drivers/bus/fslmc/Makefile | 1 - drivers/bus/fslmc/fslmc_vfio.c | 7 +-- drivers/bus/fslmc/fslmc_vfio.h | 2 - drivers/bus/fslmc/meson.build | 1 - lib/librte_eal/bsdapp/eal/eal.c | 20 +++++++ lib/librte_eal/common/include/rte_vfio.h | 74 +++++++++++++++++++++++++- lib/librte_eal/linuxapp/eal/eal_vfio.c | 45 ++++++++-------- lib/librte_eal/linuxapp/eal/eal_vfio.h | 23 +------- lib/librte_eal/linuxapp/eal/eal_vfio_mp_sync.c | 4 +- lib/librte_eal/rte_eal_version.map | 3 ++ 10 files changed, 126 insertions(+), 54 deletions(-) diff --git a/drivers/bus/fslmc/Makefile b/drivers/bus/fslmc/Makefile index 93870ba..3aa34e2 100644 --- a/drivers/bus/fslmc/Makefile +++ b/drivers/bus/fslmc/Makefile @@ -16,7 +16,6 @@ CFLAGS += $(WERROR_FLAGS) CFLAGS += -I$(RTE_SDK)/drivers/bus/fslmc CFLAGS += -I$(RTE_SDK)/drivers/bus/fslmc/mc CFLAGS += -I$(RTE_SDK)/drivers/bus/fslmc/qbman/include -CFLAGS += -I$(RTE_SDK)/lib/librte_eal/linuxapp/eal CFLAGS += -I$(RTE_SDK)/lib/librte_eal/common LDLIBS += -lrte_eal -lrte_mbuf -lrte_mempool -lrte_ring LDLIBS += -lrte_ethdev diff --git a/drivers/bus/fslmc/fslmc_vfio.c b/drivers/bus/fslmc/fslmc_vfio.c index 625fa7c..4036e82 100644 --- a/drivers/bus/fslmc/fslmc_vfio.c +++ b/drivers/bus/fslmc/fslmc_vfio.c @@ -91,7 +91,8 @@ fslmc_get_container_group(int *groupid) } /* get group number */ - ret = vfio_get_group_no(SYSFS_FSL_MC_DEVICES, g_container, groupid); + ret = rte_vfio_get_group_num(SYSFS_FSL_MC_DEVICES, + g_container, groupid); if (ret <= 0) { DPAA2_BUS_ERR("Unable to find %s IOMMU group", g_container); return -1; @@ -124,7 +125,7 @@ vfio_connect_container(void) } /* Opens main vfio file descriptor which represents the "container" */ - fd = vfio_get_container_fd(); + fd = rte_vfio_get_container_fd(); if (fd < 0) { DPAA2_BUS_ERR("Failed to open VFIO container"); return -errno; @@ -726,7 +727,7 @@ fslmc_vfio_setup_group(void) } /* Get the actual group fd */ - ret = vfio_get_group_fd(groupid); + ret = rte_vfio_get_group_fd(groupid); if (ret < 0) return ret; vfio_group.fd = ret; diff --git a/drivers/bus/fslmc/fslmc_vfio.h b/drivers/bus/fslmc/fslmc_vfio.h index e8fb344..9e2c4fe 100644 --- a/drivers/bus/fslmc/fslmc_vfio.h +++ b/drivers/bus/fslmc/fslmc_vfio.h @@ -10,8 +10,6 @@ #include <rte_vfio.h> -#include "eal_vfio.h" - #define DPAA2_MC_DPNI_DEVID 7 #define DPAA2_MC_DPSECI_DEVID 3 #define DPAA2_MC_DPCON_DEVID 5 diff --git a/drivers/bus/fslmc/meson.build b/drivers/bus/fslmc/meson.build index e94340e..78f9d92 100644 --- a/drivers/bus/fslmc/meson.build +++ b/drivers/bus/fslmc/meson.build @@ -22,6 +22,5 @@ sources = files('fslmc_bus.c', allow_experimental_apis = true -includes += include_directories('../../../lib/librte_eal/linuxapp/eal') includes += include_directories('mc', 'qbman/include', 'portal') cflags += ['-D_GNU_SOURCE'] diff --git a/lib/librte_eal/bsdapp/eal/eal.c b/lib/librte_eal/bsdapp/eal/eal.c index 727adc5..bfbec0d 100644 --- a/lib/librte_eal/bsdapp/eal/eal.c +++ b/lib/librte_eal/bsdapp/eal/eal.c @@ -818,3 +818,23 @@ rte_vfio_dma_unmap(uint64_t __rte_unused vaddr, uint64_t __rte_unused iova, { return -1; } + +int __rte_experimental +rte_vfio_get_group_num(__rte_unused const char *sysfs_base, + __rte_unused const char *dev_addr, + __rte_unused int *iommu_group_num) +{ + return -1; +} + +int __rte_experimental +rte_vfio_get_container_fd(void) +{ + return -1; +} + +int __rte_experimental +rte_vfio_get_group_fd(__rte_unused int iommu_group_num) +{ + return -1; +} diff --git a/lib/librte_eal/common/include/rte_vfio.h b/lib/librte_eal/common/include/rte_vfio.h index f363cac..c4a2e60 100644 --- a/lib/librte_eal/common/include/rte_vfio.h +++ b/lib/librte_eal/common/include/rte_vfio.h @@ -37,6 +37,13 @@ extern "C" { #endif +/* NOIOMMU is defined from kernel version 4.5 onwards */ +#ifdef VFIO_NOIOMMU_IOMMU +#define RTE_VFIO_NOIOMMU VFIO_NOIOMMU_IOMMU +#else +#define RTE_VFIO_NOIOMMU 8 +#endif + /** * Setup vfio_cfg for the device identified by its address. * It discovers the configured I/O MMU groups or sets a new one for the device. @@ -128,7 +135,19 @@ int rte_vfio_is_enabled(const char *modname); */ int rte_vfio_noiommu_is_enabled(void); -/* remove group fd from internal VFIO group fd array */ +/** + * Remove group fd from internal VFIO group fd array/ + * + * This function is only relevant to linux and will return + * an error on BSD. + * + * @param vfio_group_fd + * VFIO Grouup FD. + * + * @return + * 0 on success. + * <0 on failure. + */ int rte_vfio_clear_group(int vfio_group_fd); @@ -170,8 +189,61 @@ rte_vfio_dma_map(uint64_t vaddr, uint64_t iova, uint64_t len); * 0 if success. * -1 on error. */ + int __rte_experimental rte_vfio_dma_unmap(uint64_t vaddr, uint64_t iova, uint64_t len); +/** + * Parse IOMMU group number for a device + * + * This function is only relevant to linux and will return + * an error on BSD. + * + * @param sysfs_base + * sysfs path prefix. + * + * @param dev_addr + * device location. + * + * @param iommu_group_num + * iommu group number + * + * @return + * >0 on success + * 0 for non-existent group or VFIO + * <0 for errors + */ +int __rte_experimental +rte_vfio_get_group_num(const char *sysfs_base, + const char *dev_addr, int *iommu_group_num); + +/** + * Open VFIO container fd or get an existing one + * + * This function is only relevant to linux and will return + * an error on BSD. + * + * @return + * > 0 container fd + * < 0 for errors + */ +int __rte_experimental +rte_vfio_get_container_fd(void); + +/** + * Open VFIO group fd or get an existing one + * + * This function is only relevant to linux and will return + * an error on BSD. + * + * @param iommu_group_num + * iommu group number + * + * @return + * > 0 group fd + * < 0 for errors + */ +int __rte_experimental +rte_vfio_get_group_fd(int iommu_group_num); #ifdef __cplusplus } diff --git a/lib/librte_eal/linuxapp/eal/eal_vfio.c b/lib/librte_eal/linuxapp/eal/eal_vfio.c index 589d7d4..984b1a1 100644 --- a/lib/librte_eal/linuxapp/eal/eal_vfio.c +++ b/lib/librte_eal/linuxapp/eal/eal_vfio.c @@ -284,7 +284,7 @@ compact_user_maps(void) } int -vfio_get_group_fd(int iommu_group_no) +rte_vfio_get_group_fd(int iommu_group_num) { int i; int vfio_group_fd; @@ -293,7 +293,7 @@ vfio_get_group_fd(int iommu_group_no) /* check if we already have the group descriptor open */ for (i = 0; i < VFIO_MAX_GROUPS; i++) - if (vfio_cfg.vfio_groups[i].group_no == iommu_group_no) + if (vfio_cfg.vfio_groups[i].group_num == iommu_group_num) return vfio_cfg.vfio_groups[i].fd; /* Lets see first if there is room for a new group */ @@ -304,7 +304,7 @@ vfio_get_group_fd(int iommu_group_no) /* Now lets get an index for the new group */ for (i = 0; i < VFIO_MAX_GROUPS; i++) - if (vfio_cfg.vfio_groups[i].group_no == -1) { + if (vfio_cfg.vfio_groups[i].group_num == -1) { cur_grp = &vfio_cfg.vfio_groups[i]; break; } @@ -318,7 +318,7 @@ vfio_get_group_fd(int iommu_group_no) if (internal_config.process_type == RTE_PROC_PRIMARY) { /* try regular group format */ snprintf(filename, sizeof(filename), - VFIO_GROUP_FMT, iommu_group_no); + VFIO_GROUP_FMT, iommu_group_num); vfio_group_fd = open(filename, O_RDWR); if (vfio_group_fd < 0) { /* if file not found, it's not an error */ @@ -330,7 +330,8 @@ vfio_get_group_fd(int iommu_group_no) /* special case: try no-IOMMU path as well */ snprintf(filename, sizeof(filename), - VFIO_NOIOMMU_GROUP_FMT, iommu_group_no); + VFIO_NOIOMMU_GROUP_FMT, + iommu_group_num); vfio_group_fd = open(filename, O_RDWR); if (vfio_group_fd < 0) { if (errno != ENOENT) { @@ -343,7 +344,7 @@ vfio_get_group_fd(int iommu_group_no) /* noiommu group found */ } - cur_grp->group_no = iommu_group_no; + cur_grp->group_num = iommu_group_num; cur_grp->fd = vfio_group_fd; vfio_cfg.vfio_active_groups++; return vfio_group_fd; @@ -365,7 +366,7 @@ vfio_get_group_fd(int iommu_group_no) close(socket_fd); return -1; } - if (vfio_mp_sync_send_request(socket_fd, iommu_group_no) < 0) { + if (vfio_mp_sync_send_request(socket_fd, iommu_group_num) < 0) { RTE_LOG(ERR, EAL, " cannot send group number!\n"); close(socket_fd); return -1; @@ -380,7 +381,7 @@ vfio_get_group_fd(int iommu_group_no) /* if we got the fd, store it and return it */ if (vfio_group_fd > 0) { close(socket_fd); - cur_grp->group_no = iommu_group_no; + cur_grp->group_num = iommu_group_num; cur_grp->fd = vfio_group_fd; vfio_cfg.vfio_active_groups++; return vfio_group_fd; @@ -487,7 +488,7 @@ rte_vfio_clear_group(int vfio_group_fd) i = get_vfio_group_idx(vfio_group_fd); if (i < 0) return -1; - vfio_cfg.vfio_groups[i].group_no = -1; + vfio_cfg.vfio_groups[i].group_num = -1; vfio_cfg.vfio_groups[i].fd = -1; vfio_cfg.vfio_groups[i].devices = 0; vfio_cfg.vfio_active_groups--; @@ -544,11 +545,11 @@ rte_vfio_setup_device(const char *sysfs_base, const char *dev_addr, .argsz = sizeof(group_status) }; int vfio_group_fd; - int iommu_group_no; + int iommu_group_num; int i, ret; /* get group number */ - ret = vfio_get_group_no(sysfs_base, dev_addr, &iommu_group_no); + ret = rte_vfio_get_group_num(sysfs_base, dev_addr, &iommu_group_num); if (ret == 0) { RTE_LOG(WARNING, EAL, " %s not managed by VFIO driver, skipping\n", dev_addr); @@ -560,7 +561,7 @@ rte_vfio_setup_device(const char *sysfs_base, const char *dev_addr, return -1; /* get the actual group fd */ - vfio_group_fd = vfio_get_group_fd(iommu_group_no); + vfio_group_fd = rte_vfio_get_group_fd(iommu_group_num); if (vfio_group_fd < 0) return -1; @@ -733,7 +734,7 @@ rte_vfio_release_device(const char *sysfs_base, const char *dev_addr, .argsz = sizeof(group_status) }; int vfio_group_fd; - int iommu_group_no; + int iommu_group_num; int ret; /* we don't want any DMA mapping messages to come while we're detaching @@ -743,7 +744,7 @@ rte_vfio_release_device(const char *sysfs_base, const char *dev_addr, rte_rwlock_read_lock(mem_lock); /* get group number */ - ret = vfio_get_group_no(sysfs_base, dev_addr, &iommu_group_no); + ret = rte_vfio_get_group_num(sysfs_base, dev_addr, &iommu_group_num); if (ret <= 0) { RTE_LOG(WARNING, EAL, " %s not managed by VFIO driver\n", dev_addr); @@ -753,9 +754,9 @@ rte_vfio_release_device(const char *sysfs_base, const char *dev_addr, } /* get the actual group fd */ - vfio_group_fd = vfio_get_group_fd(iommu_group_no); + vfio_group_fd = rte_vfio_get_group_fd(iommu_group_num); if (vfio_group_fd <= 0) { - RTE_LOG(INFO, EAL, "vfio_get_group_fd failed for %s\n", + RTE_LOG(INFO, EAL, "rte_vfio_get_group_fd failed for %s\n", dev_addr); ret = -1; goto out; @@ -818,7 +819,7 @@ rte_vfio_enable(const char *modname) for (i = 0; i < VFIO_MAX_GROUPS; i++) { vfio_cfg.vfio_groups[i].fd = -1; - vfio_cfg.vfio_groups[i].group_no = -1; + vfio_cfg.vfio_groups[i].group_num = -1; vfio_cfg.vfio_groups[i].devices = 0; } @@ -841,7 +842,7 @@ rte_vfio_enable(const char *modname) return 0; } - vfio_cfg.vfio_container_fd = vfio_get_container_fd(); + vfio_cfg.vfio_container_fd = rte_vfio_get_container_fd(); /* check if we have VFIO driver enabled */ if (vfio_cfg.vfio_container_fd != -1) { @@ -919,7 +920,7 @@ vfio_has_supported_extensions(int vfio_container_fd) } int -vfio_get_container_fd(void) +rte_vfio_get_container_fd(void) { int ret, vfio_container_fd; @@ -983,8 +984,8 @@ vfio_get_container_fd(void) } int -vfio_get_group_no(const char *sysfs_base, - const char *dev_addr, int *iommu_group_no) +rte_vfio_get_group_num(const char *sysfs_base, + const char *dev_addr, int *iommu_group_num) { char linkname[PATH_MAX]; char filename[PATH_MAX]; @@ -1016,7 +1017,7 @@ vfio_get_group_no(const char *sysfs_base, errno = 0; group_tok = tok[ret - 1]; end = group_tok; - *iommu_group_no = strtol(group_tok, &end, 10); + *iommu_group_num = strtol(group_tok, &end, 10); if ((end != group_tok && *end != '\0') || errno != 0) { RTE_LOG(ERR, EAL, " %s error parsing IOMMU number!\n", dev_addr); return -1; diff --git a/lib/librte_eal/linuxapp/eal/eal_vfio.h b/lib/librte_eal/linuxapp/eal/eal_vfio.h index 549f442..c788bba 100644 --- a/lib/librte_eal/linuxapp/eal/eal_vfio.h +++ b/lib/librte_eal/linuxapp/eal/eal_vfio.h @@ -81,12 +81,6 @@ struct vfio_iommu_spapr_tce_info { #define RTE_VFIO_SPAPR VFIO_SPAPR_TCE_v2_IOMMU #endif -#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 5, 0) -#define RTE_VFIO_NOIOMMU 8 -#else -#define RTE_VFIO_NOIOMMU VFIO_NOIOMMU_IOMMU -#endif - #define VFIO_MAX_GROUPS RTE_MAX_VFIO_GROUPS /* @@ -103,7 +97,7 @@ int vfio_mp_sync_connect_to_primary(void); * the group fd via an ioctl() call. */ struct vfio_group { - int group_no; + int group_num; int fd; int devices; }; @@ -145,21 +139,6 @@ vfio_set_iommu_type(int vfio_container_fd); int vfio_has_supported_extensions(int vfio_container_fd); -/* open container fd or get an existing one */ -int -vfio_get_container_fd(void); - -/* parse IOMMU group number for a device - * returns 1 on success, -1 for errors, 0 for non-existent group - */ -int -vfio_get_group_no(const char *sysfs_base, - const char *dev_addr, int *iommu_group_no); - -/* open group fd or get an existing one */ -int -vfio_get_group_fd(int iommu_group_no); - int vfio_mp_sync_setup(void); #define SOCKET_REQ_CONTAINER 0x100 diff --git a/lib/librte_eal/linuxapp/eal/eal_vfio_mp_sync.c b/lib/librte_eal/linuxapp/eal/eal_vfio_mp_sync.c index 7cc3c15..e19b571 100644 --- a/lib/librte_eal/linuxapp/eal/eal_vfio_mp_sync.c +++ b/lib/librte_eal/linuxapp/eal/eal_vfio_mp_sync.c @@ -267,7 +267,7 @@ vfio_mp_sync_thread(void __rte_unused * arg) switch (ret) { case SOCKET_REQ_CONTAINER: - fd = vfio_get_container_fd(); + fd = rte_vfio_get_container_fd(); if (fd < 0) vfio_mp_sync_send_request(conn_sock, SOCKET_ERR); else @@ -283,7 +283,7 @@ vfio_mp_sync_thread(void __rte_unused * arg) continue; } - fd = vfio_get_group_fd(vfio_data); + fd = rte_vfio_get_group_fd(vfio_data); if (fd < 0) vfio_mp_sync_send_request(conn_sock, SOCKET_ERR); diff --git a/lib/librte_eal/rte_eal_version.map b/lib/librte_eal/rte_eal_version.map index 2b5b1dc..603c744 100644 --- a/lib/librte_eal/rte_eal_version.map +++ b/lib/librte_eal/rte_eal_version.map @@ -286,5 +286,8 @@ EXPERIMENTAL { rte_socket_id_by_idx; rte_vfio_dma_map; rte_vfio_dma_unmap; + rte_vfio_get_container_fd; + rte_vfio_get_group_fd; + rte_vfio_get_group_num; } DPDK_18.02; -- 2.7.4 ^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [dpdk-dev] [PATCH v6 2/2] eal/vfio: export internal vfio functions 2018-04-12 6:23 ` [dpdk-dev] [PATCH v6 2/2] eal/vfio: export internal vfio functions Hemant Agrawal @ 2018-04-12 23:09 ` Thomas Monjalon 0 siblings, 0 replies; 27+ messages in thread From: Thomas Monjalon @ 2018-04-12 23:09 UTC (permalink / raw) To: Hemant Agrawal; +Cc: dev, anatoly.burakov 12/04/2018 08:23, Hemant Agrawal: > This patch moves some of the internal vfio functions from > eal_vfio.h to rte_vfio.h for common uses with "rte_" prefix. > > This patch also change the FSLMC bus usages from the internal > VFIO functions to external ones with "rte_" prefix > > Signed-off-by: Hemant Agrawal <hemant.agrawal@nxp.com> > Acked-by: Anatoly Burakov <anatoly.burakov@intel.com> Applied, thanks ^ permalink raw reply [flat|nested] 27+ messages in thread
end of thread, other threads:[~2018-04-12 23:09 UTC | newest] Thread overview: 27+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2018-03-14 8:00 [dpdk-dev] [PATCH] eal/vfio: export internal vfio functions Hemant Agrawal 2018-03-14 10:19 ` Burakov, Anatoly 2018-03-27 15:53 ` Thomas Monjalon 2018-04-03 6:27 ` Hemant Agrawal 2018-04-03 7:34 ` Thomas Monjalon 2018-04-03 8:34 ` Hemant Agrawal 2018-04-02 8:36 ` [dpdk-dev] [PATCH v2] " Hemant Agrawal 2018-04-02 16:41 ` Thomas Monjalon 2018-04-03 8:28 ` [dpdk-dev] [PATCH v3 1/2] doc: add vfio api support Hemant Agrawal 2018-04-03 8:28 ` [dpdk-dev] [PATCH v3 2/2] eal/vfio: export internal vfio functions Hemant Agrawal 2018-04-03 10:16 ` [dpdk-dev] [PATCH v3 1/2] doc: add vfio api support Thomas Monjalon 2018-04-03 11:10 ` [dpdk-dev] [PATCH v4 " Hemant Agrawal 2018-04-03 11:10 ` [dpdk-dev] [PATCH v4 2/2] eal/vfio: export internal vfio functions Hemant Agrawal 2018-04-03 12:24 ` Thomas Monjalon 2018-04-03 12:59 ` Hemant Agrawal 2018-04-03 15:23 ` Wang, Xiao W 2018-04-04 6:47 ` Hemant Agrawal 2018-04-04 7:48 ` [dpdk-dev] [PATCH v5 1/2] doc: add vfio api support Hemant Agrawal 2018-04-04 7:48 ` [dpdk-dev] [PATCH v5 2/2] eal/vfio: export internal vfio functions Hemant Agrawal 2018-04-05 9:03 ` Wang, Xiao W 2018-04-05 10:22 ` Thomas Monjalon 2018-04-05 10:35 ` Wang, Xiao W 2018-04-11 21:25 ` Thomas Monjalon 2018-04-12 6:26 ` Hemant Agrawal 2018-04-12 6:23 ` [dpdk-dev] [PATCH v6 1/2] doc: add vfio api support Hemant Agrawal 2018-04-12 6:23 ` [dpdk-dev] [PATCH v6 2/2] eal/vfio: export internal vfio functions Hemant Agrawal 2018-04-12 23:09 ` Thomas Monjalon
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).