|
|
95b418 |
From f4ce18acd42d27c8aaa090004989d81b40334715 Mon Sep 17 00:00:00 2001
|
|
|
95b418 |
From: Gowrishankar Muthukrishnan <gowrishankar.m@linux.vnet.ibm.com>
|
|
|
95b418 |
Date: Wed, 3 May 2017 12:00:27 +0530
|
|
|
95b418 |
Subject: [PATCH 2/2] eal/ppc: support sPAPR IOMMU for vfio-pci
|
|
|
95b418 |
|
|
|
95b418 |
Below changes adds pci probing support for vfio-pci devices in power8.
|
|
|
95b418 |
|
|
|
95b418 |
Signed-off-by: Gowrishankar Muthukrishnan <gowrishankar.m@linux.vnet.ibm.com>
|
|
|
95b418 |
Acked-by: Anatoly Burakov <anatoly.burakov@intel.com>
|
|
|
95b418 |
Acked-by: Chao Zhu <chaozhu@linux.vnet.ibm.com>
|
|
|
95b418 |
---
|
|
|
95b418 |
doc/guides/rel_notes/release_16_11.rst | 4 ++
|
|
|
95b418 |
lib/librte_eal/linuxapp/eal/eal_vfio.c | 90 ++++++++++++++++++++++++++++++++++
|
|
|
95b418 |
lib/librte_eal/linuxapp/eal/eal_vfio.h | 25 ++++++++++
|
|
|
95b418 |
3 files changed, 119 insertions(+)
|
|
|
95b418 |
|
|
|
95b418 |
diff --git a/doc/guides/rel_notes/release_16_11.rst b/doc/guides/rel_notes/release_16_11.rst
|
|
|
95b418 |
index 6186337..1e12002 100644
|
|
|
95b418 |
--- a/doc/guides/rel_notes/release_16_11.rst
|
|
|
95b418 |
+++ b/doc/guides/rel_notes/release_16_11.rst
|
|
|
95b418 |
@@ -159,6 +159,10 @@ New Features
|
|
|
95b418 |
|
|
|
95b418 |
i40e PMD and its vector PMD enabled by default in powerpc.
|
|
|
95b418 |
|
|
|
95b418 |
+* **Added powerpc support in pci probing for vfio-pci devices.**
|
|
|
95b418 |
+
|
|
|
95b418 |
+ sPAPR IOMMU based pci probing enabled for vfio-pci devices.
|
|
|
95b418 |
+
|
|
|
95b418 |
Resolved Issues
|
|
|
95b418 |
---------------
|
|
|
95b418 |
|
|
|
95b418 |
diff --git a/lib/librte_eal/linuxapp/eal/eal_vfio.c b/lib/librte_eal/linuxapp/eal/eal_vfio.c
|
|
|
95b418 |
index 702f7a2..9377a66 100644
|
|
|
95b418 |
--- a/lib/librte_eal/linuxapp/eal/eal_vfio.c
|
|
|
95b418 |
+++ b/lib/librte_eal/linuxapp/eal/eal_vfio.c
|
|
|
95b418 |
@@ -50,12 +50,15 @@
|
|
|
95b418 |
static struct vfio_config vfio_cfg;
|
|
|
95b418 |
|
|
|
95b418 |
static int vfio_type1_dma_map(int);
|
|
|
95b418 |
+static int vfio_spapr_dma_map(int);
|
|
|
95b418 |
static int vfio_noiommu_dma_map(int);
|
|
|
95b418 |
|
|
|
95b418 |
/* IOMMU types we support */
|
|
|
95b418 |
static const struct vfio_iommu_type iommu_types[] = {
|
|
|
95b418 |
/* x86 IOMMU, otherwise known as type 1 */
|
|
|
95b418 |
{ RTE_VFIO_TYPE1, "Type 1", &vfio_type1_dma_map},
|
|
|
95b418 |
+ /* ppc64 IOMMU, otherwise known as spapr */
|
|
|
95b418 |
+ { RTE_VFIO_SPAPR, "sPAPR", &vfio_spapr_dma_map},
|
|
|
95b418 |
/* IOMMU-less mode */
|
|
|
95b418 |
{ RTE_VFIO_NOIOMMU, "No-IOMMU", &vfio_noiommu_dma_map},
|
|
|
95b418 |
};
|
|
|
95b418 |
@@ -540,6 +543,93 @@ int vfio_setup_device(const char *sysfs_base, const char *dev_addr,
|
|
|
95b418 |
}
|
|
|
95b418 |
|
|
|
95b418 |
static int
|
|
|
95b418 |
+vfio_spapr_dma_map(int vfio_container_fd)
|
|
|
95b418 |
+{
|
|
|
95b418 |
+ const struct rte_memseg *ms = rte_eal_get_physmem_layout();
|
|
|
95b418 |
+ int i, ret;
|
|
|
95b418 |
+
|
|
|
95b418 |
+ struct vfio_iommu_spapr_register_memory reg = {
|
|
|
95b418 |
+ .argsz = sizeof(reg),
|
|
|
95b418 |
+ .flags = 0
|
|
|
95b418 |
+ };
|
|
|
95b418 |
+ struct vfio_iommu_spapr_tce_info info = {
|
|
|
95b418 |
+ .argsz = sizeof(info),
|
|
|
95b418 |
+ };
|
|
|
95b418 |
+ struct vfio_iommu_spapr_tce_create create = {
|
|
|
95b418 |
+ .argsz = sizeof(create),
|
|
|
95b418 |
+ };
|
|
|
95b418 |
+ struct vfio_iommu_spapr_tce_remove remove = {
|
|
|
95b418 |
+ .argsz = sizeof(remove),
|
|
|
95b418 |
+ };
|
|
|
95b418 |
+
|
|
|
95b418 |
+ /* query spapr iommu info */
|
|
|
95b418 |
+ ret = ioctl(vfio_container_fd, VFIO_IOMMU_SPAPR_TCE_GET_INFO, &info;;
|
|
|
95b418 |
+ if (ret) {
|
|
|
95b418 |
+ RTE_LOG(ERR, EAL, " cannot get iommu info, "
|
|
|
95b418 |
+ "error %i (%s)\n", errno, strerror(errno));
|
|
|
95b418 |
+ return -1;
|
|
|
95b418 |
+ }
|
|
|
95b418 |
+
|
|
|
95b418 |
+ /* remove default DMA of 32 bit window */
|
|
|
95b418 |
+ remove.start_addr = info.dma32_window_start;
|
|
|
95b418 |
+ ret = ioctl(vfio_container_fd, VFIO_IOMMU_SPAPR_TCE_REMOVE, &remove);
|
|
|
95b418 |
+ if (ret) {
|
|
|
95b418 |
+ RTE_LOG(ERR, EAL, " cannot remove default DMA window, "
|
|
|
95b418 |
+ "error %i (%s)\n", errno, strerror(errno));
|
|
|
95b418 |
+ return -1;
|
|
|
95b418 |
+ }
|
|
|
95b418 |
+
|
|
|
95b418 |
+ /* calculate window size based on number of hugepages configured */
|
|
|
95b418 |
+ create.window_size = rte_eal_get_physmem_size();
|
|
|
95b418 |
+ create.page_shift = __builtin_ctzll(ms->hugepage_sz);
|
|
|
95b418 |
+ create.levels = 2;
|
|
|
95b418 |
+
|
|
|
95b418 |
+ ret = ioctl(vfio_container_fd, VFIO_IOMMU_SPAPR_TCE_CREATE, &create);
|
|
|
95b418 |
+ if (ret) {
|
|
|
95b418 |
+ RTE_LOG(ERR, EAL, " cannot create new DMA window, "
|
|
|
95b418 |
+ "error %i (%s)\n", errno, strerror(errno));
|
|
|
95b418 |
+ return -1;
|
|
|
95b418 |
+ }
|
|
|
95b418 |
+
|
|
|
95b418 |
+ /* map all DPDK segments for DMA. use 1:1 PA to IOVA mapping */
|
|
|
95b418 |
+ for (i = 0; i < RTE_MAX_MEMSEG; i++) {
|
|
|
95b418 |
+ struct vfio_iommu_type1_dma_map dma_map;
|
|
|
95b418 |
+
|
|
|
95b418 |
+ if (ms[i].addr == NULL)
|
|
|
95b418 |
+ break;
|
|
|
95b418 |
+
|
|
|
95b418 |
+ reg.vaddr = (uintptr_t) ms[i].addr;
|
|
|
95b418 |
+ reg.size = ms[i].len;
|
|
|
95b418 |
+ ret = ioctl(vfio_container_fd,
|
|
|
95b418 |
+ VFIO_IOMMU_SPAPR_REGISTER_MEMORY, ®);
|
|
|
95b418 |
+ if (ret) {
|
|
|
95b418 |
+ RTE_LOG(ERR, EAL, " cannot register vaddr for IOMMU, "
|
|
|
95b418 |
+ "error %i (%s)\n", errno, strerror(errno));
|
|
|
95b418 |
+ return -1;
|
|
|
95b418 |
+ }
|
|
|
95b418 |
+
|
|
|
95b418 |
+ memset(&dma_map, 0, sizeof(dma_map));
|
|
|
95b418 |
+ dma_map.argsz = sizeof(struct vfio_iommu_type1_dma_map);
|
|
|
95b418 |
+ dma_map.vaddr = ms[i].addr_64;
|
|
|
95b418 |
+ dma_map.size = ms[i].len;
|
|
|
95b418 |
+ dma_map.iova = ms[i].phys_addr;
|
|
|
95b418 |
+ dma_map.flags = VFIO_DMA_MAP_FLAG_READ |
|
|
|
95b418 |
+ VFIO_DMA_MAP_FLAG_WRITE;
|
|
|
95b418 |
+
|
|
|
95b418 |
+ ret = ioctl(vfio_container_fd, VFIO_IOMMU_MAP_DMA, &dma_map);
|
|
|
95b418 |
+
|
|
|
95b418 |
+ if (ret) {
|
|
|
95b418 |
+ RTE_LOG(ERR, EAL, " cannot set up DMA remapping, "
|
|
|
95b418 |
+ "error %i (%s)\n", errno, strerror(errno));
|
|
|
95b418 |
+ return -1;
|
|
|
95b418 |
+ }
|
|
|
95b418 |
+
|
|
|
95b418 |
+ }
|
|
|
95b418 |
+
|
|
|
95b418 |
+ return 0;
|
|
|
95b418 |
+}
|
|
|
95b418 |
+
|
|
|
95b418 |
+static int
|
|
|
95b418 |
vfio_noiommu_dma_map(int __rte_unused vfio_container_fd)
|
|
|
95b418 |
{
|
|
|
95b418 |
/* No-IOMMU mode does not need DMA mapping */
|
|
|
95b418 |
diff --git a/lib/librte_eal/linuxapp/eal/eal_vfio.h b/lib/librte_eal/linuxapp/eal/eal_vfio.h
|
|
|
95b418 |
index 29f7f3e..ac31a4f 100644
|
|
|
95b418 |
--- a/lib/librte_eal/linuxapp/eal/eal_vfio.h
|
|
|
95b418 |
+++ b/lib/librte_eal/linuxapp/eal/eal_vfio.h
|
|
|
95b418 |
@@ -54,6 +54,31 @@
|
|
|
95b418 |
|
|
|
95b418 |
#define RTE_VFIO_TYPE1 VFIO_TYPE1_IOMMU
|
|
|
95b418 |
|
|
|
95b418 |
+#ifndef VFIO_SPAPR_TCE_v2_IOMMU
|
|
|
95b418 |
+#define RTE_VFIO_SPAPR 7
|
|
|
95b418 |
+#define VFIO_IOMMU_SPAPR_REGISTER_MEMORY _IO(VFIO_TYPE, VFIO_BASE + 17)
|
|
|
95b418 |
+#define VFIO_IOMMU_SPAPR_TCE_CREATE _IO(VFIO_TYPE, VFIO_BASE + 19)
|
|
|
95b418 |
+#define VFIO_IOMMU_SPAPR_TCE_REMOVE _IO(VFIO_TYPE, VFIO_BASE + 20)
|
|
|
95b418 |
+struct vfio_iommu_spapr_register_memory {
|
|
|
95b418 |
+ uint32_t argsz;
|
|
|
95b418 |
+ uint32_t flags;
|
|
|
95b418 |
+ uint64_t vaddr;
|
|
|
95b418 |
+ uint64_t size;
|
|
|
95b418 |
+};
|
|
|
95b418 |
+struct vfio_iommu_spapr_tce_create {
|
|
|
95b418 |
+ uint32_t argsz;
|
|
|
95b418 |
+ uint32_t page_shift;
|
|
|
95b418 |
+ uint64_t window_size;
|
|
|
95b418 |
+ uint32_t levels;
|
|
|
95b418 |
+};
|
|
|
95b418 |
+struct vfio_iommu_spapr_tce_remove {
|
|
|
95b418 |
+ uint32_t argsz;
|
|
|
95b418 |
+ uint64_t start_addr;
|
|
|
95b418 |
+};
|
|
|
95b418 |
+#else
|
|
|
95b418 |
+#define RTE_VFIO_SPAPR VFIO_SPAPR_TCE_v2_IOMMU
|
|
|
95b418 |
+#endif
|
|
|
95b418 |
+
|
|
|
95b418 |
#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 5, 0)
|
|
|
95b418 |
#define RTE_VFIO_NOIOMMU 8
|
|
|
95b418 |
#else
|
|
|
95b418 |
--
|
|
|
95b418 |
1.9.1
|
|
|
95b418 |
|