From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by dpdk.org (Postfix) with ESMTP id 266EE322C for ; Thu, 2 Mar 2017 16:19:10 +0100 (CET) Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 02 Mar 2017 07:19:02 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.35,231,1484035200"; d="scan'208";a="70835274" Received: from irsmsx108.ger.corp.intel.com ([163.33.3.3]) by orsmga005.jf.intel.com with ESMTP; 02 Mar 2017 07:19:00 -0800 Received: from irsmsx109.ger.corp.intel.com ([169.254.13.44]) by IRSMSX108.ger.corp.intel.com ([169.254.11.173]) with mapi id 14.03.0248.002; Thu, 2 Mar 2017 15:18:59 +0000 From: "Burakov, Anatoly" To: Gowrishankar , "dev@dpdk.org" CC: Chao Zhu , Thomas Monjalon , Pradeep Thread-Topic: [PATCH] eal: sPAPR IOMMU support in pci probing for vfio-pci in ppc64le Thread-Index: AQHSg2W3h7Vl5tkXWU6Pib/xwthH3KGBx0ng Date: Thu, 2 Mar 2017 15:18:59 +0000 Message-ID: References: In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [163.33.239.180] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Subject: Re: [dpdk-dev] [PATCH] eal: sPAPR IOMMU support in pci probing for vfio-pci in ppc64le X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 02 Mar 2017 15:19:11 -0000 > From: Gowrishankar [mailto:gowrishankar.m@linux.vnet.ibm.com] > Sent: Friday, February 10, 2017 6:18 AM > To: dev@dpdk.org > Cc: Chao Zhu ; Thomas Monjalon > ; Burakov, Anatoly > ; Pradeep ; > Gowrishankar Muthukrishnan > Subject: [PATCH] eal: sPAPR IOMMU support in pci probing for vfio-pci in > ppc64le >=20 > From: Gowrishankar Muthukrishnan >=20 > Below changes adds pci probing support for vfio-pci devices in power8. >=20 > Signed-off-by: Gowrishankar Muthukrishnan > > Acked-by: Chao Zhu > --- > lib/librte_eal/linuxapp/eal/eal_vfio.c | 88 > ++++++++++++++++++++++++++++++++++ > lib/librte_eal/linuxapp/eal/eal_vfio.h | 1 + > 2 files changed, 89 insertions(+) >=20 > diff --git a/lib/librte_eal/linuxapp/eal/eal_vfio.c > b/lib/librte_eal/linuxapp/eal/eal_vfio.c > index 702f7a2..1d4fea6 100644 > --- a/lib/librte_eal/linuxapp/eal/eal_vfio.c > +++ b/lib/librte_eal/linuxapp/eal/eal_vfio.c > @@ -50,12 +50,15 @@ > static struct vfio_config vfio_cfg; >=20 > static int vfio_type1_dma_map(int); > +static int vfio_spapr_dma_map(int); > static int vfio_noiommu_dma_map(int); >=20 > /* IOMMU types we support */ > static const struct vfio_iommu_type iommu_types[] =3D { > /* x86 IOMMU, otherwise known as type 1 */ > { RTE_VFIO_TYPE1, "Type 1", &vfio_type1_dma_map}, > + /* ppc64 IOMMU, otherwise known as spapr */ > + { RTE_VFIO_SPAPR, "sPAPR", &vfio_spapr_dma_map}, > /* IOMMU-less mode */ > { RTE_VFIO_NOIOMMU, "No-IOMMU", > &vfio_noiommu_dma_map}, }; @@ -540,6 +543,91 @@ int > vfio_setup_device(const char *sysfs_base, const char *dev_addr, } >=20 > static int > +vfio_spapr_dma_map(int vfio_container_fd) { > + const struct rte_memseg *ms =3D rte_eal_get_physmem_layout(); > + int i, ret; > + > + struct vfio_iommu_spapr_register_memory reg =3D { > + .argsz =3D sizeof(reg), > + .flags =3D 0 > + }; > + struct vfio_iommu_spapr_tce_info info =3D { > + .argsz =3D sizeof(info), > + }; > + struct vfio_iommu_spapr_tce_create create =3D { > + .argsz =3D sizeof(create), > + }; > + struct vfio_iommu_spapr_tce_remove remove =3D { > + .argsz =3D sizeof(remove), > + }; > + > + /* query spapr iommu info */ > + ret =3D ioctl(vfio_container_fd, VFIO_IOMMU_SPAPR_TCE_GET_INFO, > &info); > + if (ret) { > + RTE_LOG(ERR, EAL, " cannot get iommu info, " > + "error %i (%s)\n", errno, strerror(errno)); > + return -1; > + } > + > + /* remove default DMA of 32 bit window */ > + remove.start_addr =3D info.dma32_window_start; > + ret =3D ioctl(vfio_container_fd, VFIO_IOMMU_SPAPR_TCE_REMOVE, > &remove); > + if (ret) { > + RTE_LOG(ERR, EAL, " cannot remove default DMA window, " > + "error %i (%s)\n", errno, strerror(errno)); > + return -1; > + } > + > + /* calculate window size based on number of hugepages configured > */ > + create.window_size =3D rte_eal_get_physmem_size(); > + create.page_shift =3D __builtin_ctzll(ms->hugepage_sz); > + create.levels =3D 2; > + > + ret =3D ioctl(vfio_container_fd, VFIO_IOMMU_SPAPR_TCE_CREATE, > &create); > + if (ret) { > + RTE_LOG(ERR, EAL, " cannot create new DMA window, " > + "error %i (%s)\n", errno, strerror(errno)); > + return -1; > + } > + > + /* map all DPDK segments for DMA. use 1:1 PA to IOVA mapping */ > + for (i =3D 0; i < RTE_MAX_MEMSEG; i++) { > + struct vfio_iommu_type1_dma_map dma_map; > + > + if (ms[i].addr =3D=3D NULL) > + break; > + > + reg.vaddr =3D (uintptr_t) ms[i].addr; > + reg.size =3D ms[i].len; > + ret =3D ioctl(vfio_container_fd, > VFIO_IOMMU_SPAPR_REGISTER_MEMORY, ®); > + if (ret) { > + RTE_LOG(ERR, EAL, " cannot register vaddr for > IOMMU, " > + "error %i (%s)\n", errno, > strerror(errno)); > + return -1; > + } > + > + memset(&dma_map, 0, sizeof(dma_map)); > + dma_map.argsz =3D sizeof(struct > vfio_iommu_type1_dma_map); > + dma_map.vaddr =3D ms[i].addr_64; > + dma_map.size =3D ms[i].len; > + dma_map.iova =3D ms[i].phys_addr; > + dma_map.flags =3D VFIO_DMA_MAP_FLAG_READ | > VFIO_DMA_MAP_FLAG_WRITE; > + > + ret =3D ioctl(vfio_container_fd, VFIO_IOMMU_MAP_DMA, > &dma_map); > + > + if (ret) { > + RTE_LOG(ERR, EAL, " cannot set up DMA remapping, > " > + "error %i (%s)\n", errno, > strerror(errno)); > + return -1; > + } > + > + } > + > + return 0; > +} > + > +static int > vfio_noiommu_dma_map(int __rte_unused vfio_container_fd) { > /* No-IOMMU mode does not need DMA mapping */ diff --git > a/lib/librte_eal/linuxapp/eal/eal_vfio.h > b/lib/librte_eal/linuxapp/eal/eal_vfio.h > index 29f7f3e..533b854 100644 > --- a/lib/librte_eal/linuxapp/eal/eal_vfio.h > +++ b/lib/librte_eal/linuxapp/eal/eal_vfio.h > @@ -53,6 +53,7 @@ > #endif >=20 > #define RTE_VFIO_TYPE1 VFIO_TYPE1_IOMMU > +#define RTE_VFIO_SPAPR VFIO_SPAPR_TCE_v2_IOMMU Does this VFIO type exist for all kernel versions starting with 3.6? it may= be worth it to add kernel version a check, like NOIOMMU type has. >=20 > #if LINUX_VERSION_CODE < KERNEL_VERSION(4, 5, 0) #define > RTE_VFIO_NOIOMMU 8 > -- > 1.9.1