From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <gowrishankar.m@linux.vnet.ibm.com>
Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com
 [148.163.156.1]) by dpdk.org (Postfix) with ESMTP id C25B269C3
 for <dev@dpdk.org>; Sat, 11 Feb 2017 04:28:00 +0100 (CET)
Received: from pps.filterd (m0098396.ppops.net [127.0.0.1])
 by mx0a-001b2d01.pphosted.com (8.16.0.20/8.16.0.20) with SMTP id
 v1B3Qhr3036555 for <dev@dpdk.org>; Fri, 10 Feb 2017 22:27:59 -0500
Received: from e23smtp09.au.ibm.com (e23smtp09.au.ibm.com [202.81.31.142])
 by mx0a-001b2d01.pphosted.com with ESMTP id 28hgtn5nw9-1
 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT)
 for <dev@dpdk.org>; Fri, 10 Feb 2017 22:27:59 -0500
Received: from localhost
 by e23smtp09.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only!
 Violators will be prosecuted
 for <dev@dpdk.org> from <gowrishankar.m@linux.vnet.ibm.com>;
 Sat, 11 Feb 2017 13:27:56 +1000
Received: from d23dlp01.au.ibm.com (202.81.31.203)
 by e23smtp09.au.ibm.com (202.81.31.206) with IBM ESMTP SMTP Gateway:
 Authorized Use Only! Violators will be prosecuted; 
 Sat, 11 Feb 2017 13:27:54 +1000
Received: from d23relay09.au.ibm.com (d23relay09.au.ibm.com [9.185.63.181])
 by d23dlp01.au.ibm.com (Postfix) with ESMTP id BB8BB2CE8046
 for <dev@dpdk.org>; Sat, 11 Feb 2017 14:27:53 +1100 (EST)
Received: from d23av01.au.ibm.com (d23av01.au.ibm.com [9.190.234.96])
 by d23relay09.au.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id
 v1B3Rj0Y25296910 for <dev@dpdk.org>; Sat, 11 Feb 2017 14:27:53 +1100
Received: from d23av01.au.ibm.com (localhost [127.0.0.1])
 by d23av01.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id
 v1B3RLpP001314 for <dev@dpdk.org>; Sat, 11 Feb 2017 14:27:21 +1100
Received: from [9.79.190.174] ([9.79.190.174])
 by d23av01.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id
 v1B3RJoA001110; Sat, 11 Feb 2017 14:27:20 +1100
References: <b89545d7530c68e4ab0fb4de05b4bf143e5c99a6.1486707309.git.gowrishankar.m@linux.vnet.ibm.com>
Cc: dev@dpdk.org, Chao Zhu <chaozhu@linux.vnet.ibm.com>,
 Anatoly Burakov <anatoly.burakov@intel.com>, Pradeep <pradeep@us.ibm.com>
To: Thomas Monjalon <thomas.monjalon@6wind.com>
From: gowrishankar muthukrishnan <gowrishankar.m@linux.vnet.ibm.com>
Date: Sat, 11 Feb 2017 08:56:59 +0530
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
 Thunderbird/45.7.0
MIME-Version: 1.0
In-Reply-To: <b89545d7530c68e4ab0fb4de05b4bf143e5c99a6.1486707309.git.gowrishankar.m@linux.vnet.ibm.com>
Content-Type: text/plain; charset=windows-1252; format=flowed
Content-Transfer-Encoding: 7bit
X-TM-AS-MML: disable
X-Content-Scanned: Fidelis XPS MAILER
x-cbid: 17021103-0052-0000-0000-000002154A0F
X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused
x-cbparentid: 17021103-0053-0000-0000-000007C26B4E
Message-Id: <7d8b0222-cb32-1e0b-5d4c-a0f30e90c9ce@linux.vnet.ibm.com>
X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, ,
 definitions=2017-02-11_02:, , signatures=0
X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0
 spamscore=0 suspectscore=0
 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam
 adjust=0 reason=mlx scancount=1 engine=8.0.1-1612050000
 definitions=main-1702110033
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 <dev.dpdk.org>
List-Unsubscribe: <http://dpdk.org/ml/options/dev>,
 <mailto:dev-request@dpdk.org?subject=unsubscribe>
List-Archive: <http://dpdk.org/ml/archives/dev/>
List-Post: <mailto:dev@dpdk.org>
List-Help: <mailto:dev-request@dpdk.org?subject=help>
List-Subscribe: <http://dpdk.org/ml/listinfo/dev>,
 <mailto:dev-request@dpdk.org?subject=subscribe>
X-List-Received-Date: Sat, 11 Feb 2017 03:28:01 -0000

Hi Thomas,
I see rc3 out. Could this patch also go in 17.02 (rc4 ?).

This patch is ppc64le specific (w/o affecting other arch) and it enables 
pmd over vfio-pci be useful for this arch.

Thanks,
Gowrishankar

On Friday 10 February 2017 11:48 AM, Gowrishankar wrote:
> From: Gowrishankar Muthukrishnan <gowrishankar.m@linux.vnet.ibm.com>
>
> Below changes adds pci probing support for vfio-pci devices in power8.
>
> Signed-off-by: Gowrishankar Muthukrishnan <gowrishankar.m@linux.vnet.ibm.com>
> Acked-by: Chao Zhu <chaozhu@linux.vnet.ibm.com>
> ---
>   lib/librte_eal/linuxapp/eal/eal_vfio.c | 88 ++++++++++++++++++++++++++++++++++
>   lib/librte_eal/linuxapp/eal/eal_vfio.h |  1 +
>   2 files changed, 89 insertions(+)
>
> 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;
>
>   static int vfio_type1_dma_map(int);
> +static int vfio_spapr_dma_map(int);
>   static int vfio_noiommu_dma_map(int);
>
>   /* IOMMU types we support */
>   static const struct vfio_iommu_type iommu_types[] = {
>   	/* 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,
>   }
>
>   static int
> +vfio_spapr_dma_map(int vfio_container_fd)
> +{
> +	const struct rte_memseg *ms = rte_eal_get_physmem_layout();
> +	int i, ret;
> +
> +	struct vfio_iommu_spapr_register_memory reg = {
> +		.argsz = sizeof(reg),
> +		.flags = 0
> +	};
> +	struct vfio_iommu_spapr_tce_info info = {
> +		.argsz = sizeof(info),
> +	};
> +	struct vfio_iommu_spapr_tce_create create = {
> +		.argsz = sizeof(create),
> +	};
> +	struct vfio_iommu_spapr_tce_remove remove = {
> +		.argsz = sizeof(remove),
> +	};
> +
> +	/* query spapr iommu info */
> +	ret = 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 = info.dma32_window_start;
> +	ret = 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 = rte_eal_get_physmem_size();
> +	create.page_shift = __builtin_ctzll(ms->hugepage_sz);
> +	create.levels = 2;
> +
> +	ret = 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 = 0; i < RTE_MAX_MEMSEG; i++) {
> +		struct vfio_iommu_type1_dma_map dma_map;
> +
> +		if (ms[i].addr == NULL)
> +			break;
> +
> +		reg.vaddr = (uintptr_t) ms[i].addr;
> +		reg.size = ms[i].len;
> +		ret = ioctl(vfio_container_fd, VFIO_IOMMU_SPAPR_REGISTER_MEMORY, &reg);
> +		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 = sizeof(struct vfio_iommu_type1_dma_map);
> +		dma_map.vaddr = ms[i].addr_64;
> +		dma_map.size = ms[i].len;
> +		dma_map.iova = ms[i].phys_addr;
> +		dma_map.flags = VFIO_DMA_MAP_FLAG_READ | VFIO_DMA_MAP_FLAG_WRITE;
> +
> +		ret = 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
>
>   #define RTE_VFIO_TYPE1 VFIO_TYPE1_IOMMU
> +#define RTE_VFIO_SPAPR VFIO_SPAPR_TCE_v2_IOMMU
>
>   #if LINUX_VERSION_CODE < KERNEL_VERSION(4, 5, 0)
>   #define RTE_VFIO_NOIOMMU 8