From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM03-BY2-obe.outbound.protection.outlook.com (mail-by2nam03on0060.outbound.protection.outlook.com [104.47.42.60]) by dpdk.org (Postfix) with ESMTP id 6C60569D4 for ; Fri, 24 Mar 2017 13:42:11 +0100 (CET) Received: from DM5PR03CA0045.namprd03.prod.outlook.com (10.174.189.162) by CY1PR03MB2266.namprd03.prod.outlook.com (10.166.207.18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.947.12; Fri, 24 Mar 2017 12:42:09 +0000 Received: from BN1AFFO11FD033.protection.gbl (2a01:111:f400:7c10::166) by DM5PR03CA0045.outlook.office365.com (2603:10b6:4:3b::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.991.14 via Frontend Transport; Fri, 24 Mar 2017 12:42:09 +0000 Authentication-Results: spf=fail (sender IP is 192.88.168.50) smtp.mailfrom=nxp.com; caviumnetworks.com; dkim=none (message not signed) header.d=none; caviumnetworks.com; dmarc=fail action=none header.from=nxp.com; Received-SPF: Fail (protection.outlook.com: domain of nxp.com does not designate 192.88.168.50 as permitted sender) receiver=protection.outlook.com; client-ip=192.88.168.50; helo=tx30smr01.am.freescale.net; Received: from tx30smr01.am.freescale.net (192.88.168.50) by BN1AFFO11FD033.mail.protection.outlook.com (10.58.52.246) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.1.977.7 via Frontend Transport; Fri, 24 Mar 2017 12:42:08 +0000 Received: from bf-netperf1.idc ([10.232.134.28]) by tx30smr01.am.freescale.net (8.14.3/8.14.0) with ESMTP id v2OCfacG031007; Fri, 24 Mar 2017 05:42:05 -0700 From: Hemant Agrawal To: CC: , , , , , Date: Fri, 24 Mar 2017 18:11:19 +0530 Message-ID: <1490359292-18773-10-git-send-email-hemant.agrawal@nxp.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1490359292-18773-1-git-send-email-hemant.agrawal@nxp.com> References: <1489754201-1027-1-git-send-email-hemant.agrawal@nxp.com> <1490359292-18773-1-git-send-email-hemant.agrawal@nxp.com> X-EOPAttributedMessage: 0 X-Matching-Connectors: 131348329288443812; (91ab9b29-cfa4-454e-5278-08d120cd25b8); () X-Forefront-Antispam-Report: CIP:192.88.168.50; IPV:NLI; CTRY:US; EFV:NLI; SFV:NSPM; SFS:(10009020)(6009001)(336005)(39840400002)(39850400002)(39400400002)(39860400002)(39380400002)(39450400003)(39410400002)(2980300002)(1110001)(1109001)(339900001)(189002)(199003)(9170700003)(104016004)(48376002)(54906002)(50226002)(86362001)(110136004)(4326008)(36756003)(189998001)(2906002)(8656002)(47776003)(575784001)(53936002)(85426001)(76176999)(105606002)(33646002)(50986999)(77096006)(6666003)(356003)(6916009)(81166006)(2351001)(38730400002)(305945005)(5003940100001)(106466001)(8676002)(8936002)(50466002)(5660300001)(2950100002); DIR:OUT; SFP:1101; SCL:1; SRVR:CY1PR03MB2266; H:tx30smr01.am.freescale.net; FPR:; SPF:Fail; MLV:ovrnspm; MX:1; A:1; PTR:InfoDomainNonexistent; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; BN1AFFO11FD033; 1:GQvPeKUeCU2ra6DwMY+B2ycFhZ+BzOGUsnPZfLCYxu0HAc/kEWZF/DfyZU2msB1/V+rqbonmq9+ZUOD5o89p+mgf+hpcz2Tol8XadcKrjNJsgWFpI4bOhP9nST4nkjN3euhGnqOU2FwSZOvgS8i5ubAU5xSD5rBWAeSmSrMnO+K+RzbhoBa1Ps1xWpradngd3nGSS8h5c4ekIgrIgZxfx7RPDODxRYo3HjdeEWiFpsIbyCX6nqv5OLS3/JlGoujkrNoCislCqr85FYIoU/99cOq58+h8YJwJH1HVItilFzG617oqe/laYStzT7OXk8ARVlRtO1vC4nBto19VfH2/t5XhgoXpe+xbwnXjsPjsOy4dDcOP/yt0DeQvD85/VnF1PIK5/JTcCDoMXNWglusWhCbOnKlcAEDIoIRDN78q0FwLziFkFPG6+jYOnUeSTHFNMqcmXP0PkZExm7OCOWbAN4L9r0G1VmEZx8F2ocutPYIbttKPUorYtoR8zlIU8biwxYf9fPPNAOs5ZncrzQHyGV93AA0Y8kTOopXYOziIxUJgtWmy61Ea36FOpgWFEHDXFi4zAsq+Imsb3urn+26D5VCnq2jAW7sRuu8gql5IQm9nZO8dytXYKfeSCO1EFWtMU0MCSlAjAxXjSRDeWUABnQ== MIME-Version: 1.0 Content-Type: text/plain X-MS-Office365-Filtering-Correlation-Id: c87b3b37-1c9c-42e7-c642-08d472b32f88 X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(22001);SRVR:CY1PR03MB2266; X-Microsoft-Exchange-Diagnostics: 1; CY1PR03MB2266; 3:U+T+wAHQWQ8uNC+ICv3ZtNYlG5HQ2DYSFeaPMR0zCpwtBe2thTZ4ZhsL/BJSf4GBudKzQxlkCVBFJvSh0/h0rvDznEqcBjKj88hvsaOBEYTx7Sud0KbfnGuZj1fMino4m/LAtEZ5302xAaxY26/0RzA3IJGmSvmuF3PE/wr9efQFCuij021pY8ZCDVdw1WQEge9yMq2EIjHu7rj4hGwpl7BYcq/CRtSXDTD5VNSZOcmoerAPyIjAsg4VUtS9/bSbX2KLAcCAyGLj8RDLQA4CLQKe8J4IXO8WnaXkUi1ZoMLsHTZJ79VxJyT3y7amm2thep4icA0cQq6E3NFqdTa4SKvPSyfYugvDivlRSJ119TkIGgFELL0TocZ8ohiLhLo6; 25:fokNZk/qtMdD33VbY4I42m19Qyu2pJ4DRC4D5s9ykep5LYQ63yVDe/uRiYunETm7TrfCkZCO7e+ZaWn/Sw2yDrKLOPexn+v4npMJ4piavPdkoEzQQF14vvGxGM4heWOGKOTje1wdhjJ7qYXgG4vRknbMmJOc3SghMiKVsZMHh7UYuw2XCoviZNKr6JAzhvOcfpHhmcsGAmfJwS/tp1sEfCIwEEo6X+QEJod26Amg3mdrp6dnhBQAgJq6AF8uWqt03oUQyU3WgtWSJg8LSZZYitKrXaTR7dT1B5x7h8tXdFHR7FwLxuJ/7S3TH8V1TNxLRjuXuTYBj2OUzX9VtWdKJ589wqzyII425FnM0hv3nqXSXsTcRI1KiBhrLfI35yHd+KivPRhnClOTGp7FCUeJqOGVgvGxJl2BRsxTTr9QPsTO27d5nmBxm7alM0NnIspSo53dpnJ4W5Ng2zRdpo51Fg== X-Microsoft-Exchange-Diagnostics: 1; CY1PR03MB2266; 31:FLVeuy0DP81NYLhuzu9F2j5e61X9XnCR24XWXbqSs7jZA7mlMKTS5eSqGyVdtPAPU2NKSDoRVPg2+aHtYPZdAou4Zeh8n4L/Xci7tynH5nPLjZldxhz6zjyh3AmKd2Pd6VkFJFDPoCiEZ3cHs9Ewr7UeyFAs5BywOqojGK2ImhVSm1EHfnho80H8WDVtle2zoo3denZXJfRjyFqPTuigXYhXlcTnBQqY8eetzPaRgo8upfZodx6fc3H95B/zXKlICJUf+h1F33eiV6Sd1d5TQSxmqLR8CxLNLrFTMyq3JZM= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(185117386973197)(275809806118684)(21532816269658); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6095060)(601004)(2401047)(13018025)(13017025)(8121501046)(5005006)(13024025)(13023025)(13015025)(3002001)(10201501046)(6055026)(6096035)(20161123565025)(20161123559025)(20161123556025)(20161123561025)(20161123563025); SRVR:CY1PR03MB2266; BCL:0; PCL:0; RULEID:(400006); SRVR:CY1PR03MB2266; X-Microsoft-Exchange-Diagnostics: 1; CY1PR03MB2266; 4:iJrOQ2TIDoQaasofz5QkasJGU2yAeLkfEP7DfpvphWA3Y4SI7RimQL7QfQFm5Mjj3XMGDrWzneqCPRYjulcw8o1fsETpY9UL5v0QeW6Kj3BWq+jKxzhI81hQpvicZrYwxZL3jebVhhysq1QEkdJWGE60SQ5x/ulctCEeOal7Y6DQIhV7JO7eSf5739LhIQl8PMXuYiJFY6ULniGzzchwUf3xbaCHysLRII5DQL+Kd5ztLb3D6bYEFMw3JJab/FCg+Vixx8kl88VMw53CTUvs4etJG3gf6PX54IIr46g7WNTAiqc9xAKNsdqGrXTjvjuk2IBLOBZhl95s8th+wH09X4psfLxsmK9WGNL4kEyI2rr1MatTjjxXHk8Cr0Ebyt6/F9dt6KGKh/Nh5ux4kuJ1Pk0JL/ndiBif9ZHlzPp//+lICZIh9rlunxpMg9Bpk2iPwh4OuzqD0ujKuzSwqrmFXNztwYA7F99YmU180Ufb73B6IFDIHHKtvBgVMhjhMrbduwU7GD/aheojOQEsSDr9BHkOuK9wo3XixTzrMSooeCAtSHKAr0xjccF3ZHoAaOk7ClG50ZEx0FI1LYJuneNVFVPw5RR9VmVX+r2+fIN/c63Kk6NlXUUBwW3YMsNoMVdrlU34jpb6EmZ03P6d9rs9+mErrNpfU5KSAKFKv2oBnjrwvhcgAQaNalmkNsJfsRsm89BEll5LB9vPUqw4BBtjf1SqAg5cV2rLWCPxGJjdR9S+le9LLjOQk4ck0x10cJ0jI+8j5TAV+wGr1cayJR8z6kjNImaa6lqFxekCF0ccDlKbgUGiH4uwxTdd+QlHEHDd X-Forefront-PRVS: 0256C18696 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; CY1PR03MB2266; 23:jYMDdGYhc8phVvEGnqBUgFRApdKpqYFATj2jpECdQ?= =?us-ascii?Q?yqiyo490r1rOtEHZW1+ABClnKcLicEfZleHX0VjczlmO8qkHEDwXvHxm74u6?= =?us-ascii?Q?nMvIFF21j4Qtdp94KWPJJXA0peX3+0879M3fLLTvZhOKauUtcW45tezLIl5O?= =?us-ascii?Q?PIw4OeU7ZT+S68LdsQmQUMWwzkbpSbsZFs8fcTDBXKyVbqE1fgVO5JBe2sSq?= =?us-ascii?Q?II5Bs/ggDqXRUhzehUyr/YY46K+TJYjfDF12F/icGpEjZvM755fE6EozdRKi?= =?us-ascii?Q?eO9Aa805J+T4axfSsFo528fqQrzQ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hzXMRteyMzLlySkZ6zrjq/r5tzBOGX5/mJkcNqvvoE92LssXJJ3bbaXDGVMKMsG76guRKq7Wu+Y4L8YxB97+8oqmstgCsxAGhtbk06mmTnkdAKay01tlkeGfepkdRJC8I5ti0G9hLZFiNoPR+2PoOpniAy6viLm1gMDH+r6tkMntFMv7jwwjw6zjW/yJttSssgBN1vHOb/+10aWnIqjN4r4+XH9AHiOG05cDZLkp86Q== X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Mar 2017 12:42:08.6415 (UTC) X-MS-Exchange-CrossTenant-Id: 5afe0b00-7697-4969-b663-5eab37d5f47e X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=5afe0b00-7697-4969-b663-5eab37d5f47e; Ip=[192.88.168.50]; Helo=[tx30smr01.am.freescale.net] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY1PR03MB2266 Subject: [dpdk-dev] [PATCH v2 09/22] bus/fslmc: add vfio support 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: Fri, 24 Mar 2017 12:42:12 -0000 Add support for using VFIO for dpaa2 based fsl-mc bus. There are some differences in the way vfio used for fsl-mc bus from the eal vfio. - The scanning of bus for individual objects on the basis of the DPRC container. - The use and mapping of MC portal for object access With the evolution of bus model, they canbe further aligned with eal vfio code. Signed-off-by: Hemant Agrawal --- drivers/bus/fslmc/Makefile | 1 + drivers/bus/fslmc/fslmc_bus.c | 10 + drivers/bus/fslmc/fslmc_vfio.c | 450 ++++++++++++++++++++++++++++ drivers/bus/fslmc/fslmc_vfio.h | 74 +++++ drivers/bus/fslmc/rte_bus_fslmc_version.map | 1 + 5 files changed, 536 insertions(+) create mode 100644 drivers/bus/fslmc/fslmc_vfio.c create mode 100644 drivers/bus/fslmc/fslmc_vfio.h diff --git a/drivers/bus/fslmc/Makefile b/drivers/bus/fslmc/Makefile index 2fd2382..2ca7067 100644 --- a/drivers/bus/fslmc/Makefile +++ b/drivers/bus/fslmc/Makefile @@ -67,6 +67,7 @@ SRCS-$(CONFIG_RTE_LIBRTE_FSLMC_BUS) += \ mc/dpio.c \ mc/mc_sys.c +SRCS-$(CONFIG_RTE_LIBRTE_FSLMC_BUS) += fslmc_vfio.c SRCS-$(CONFIG_RTE_LIBRTE_FSLMC_BUS) += fslmc_bus.c # library dependencies diff --git a/drivers/bus/fslmc/fslmc_bus.c b/drivers/bus/fslmc/fslmc_bus.c index 8a4f519..ee794e7 100644 --- a/drivers/bus/fslmc/fslmc_bus.c +++ b/drivers/bus/fslmc/fslmc_bus.c @@ -42,6 +42,7 @@ #include #include "rte_fslmc.h" +#include "fslmc_vfio.h" #define FSLMC_BUS_LOG(level, fmt, args...) \ RTE_LOG(level, EAL, "%s(): " fmt "\n", __func__, ##args) @@ -51,6 +52,15 @@ static int rte_fslmc_scan(void) { + if (fslmc_vfio_setup_group()) { + FSLMC_BUS_LOG(ERR, "fslmc: Unable to setup VFIO"); + return -1; + } + if (fslmc_vfio_process_group()) { + FSLMC_BUS_LOG(ERR, "fslmc: Unable to setup devices"); + return -1; + } + RTE_LOG(INFO, EAL, "fslmc: Bus scan completed\n"); return 0; } diff --git a/drivers/bus/fslmc/fslmc_vfio.c b/drivers/bus/fslmc/fslmc_vfio.c new file mode 100644 index 0000000..73db595 --- /dev/null +++ b/drivers/bus/fslmc/fslmc_vfio.c @@ -0,0 +1,450 @@ +/*- + * BSD LICENSE + * + * Copyright (c) 2015-2016 Freescale Semiconductor, Inc. All rights reserved. + * Copyright (c) 2016 NXP. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Freescale Semiconductor, Inc nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "rte_fslmc.h" +#include "fslmc_vfio.h" + +#define VFIO_MAX_CONTAINERS 1 + +#define FSLMC_VFIO_LOG(level, fmt, args...) \ + RTE_LOG(level, EAL, "%s(): " fmt "\n", __func__, ##args) + +/** Pathname of FSL-MC devices directory. */ +#define SYSFS_FSL_MC_DEVICES "/sys/bus/fsl-mc/devices" + +/* Number of VFIO containers & groups with in */ +static struct fslmc_vfio_group vfio_groups[VFIO_MAX_GRP]; +static struct fslmc_vfio_container vfio_containers[VFIO_MAX_CONTAINERS]; +static int container_device_fd; +void *(*rte_mcp_ptr_list); +static uint32_t mcp_id; + +static int vfio_connect_container(struct fslmc_vfio_group *vfio_group) +{ + struct fslmc_vfio_container *container; + int i, fd, ret; + + /* Try connecting to vfio container if already created */ + for (i = 0; i < VFIO_MAX_CONTAINERS; i++) { + container = &vfio_containers[i]; + if (!ioctl(vfio_group->fd, VFIO_GROUP_SET_CONTAINER, + &container->fd)) { + FSLMC_VFIO_LOG(INFO, "Container pre-exists with" + " FD[0x%x] for this group", + container->fd); + vfio_group->container = container; + return 0; + } + } + + /* Opens main vfio file descriptor which represents the "container" */ + fd = vfio_get_container_fd(); + if (fd < 0) { + FSLMC_VFIO_LOG(ERR, "Failed to open VFIO container"); + return -errno; + } + + /* Check whether support for SMMU type IOMMU present or not */ + if (ioctl(fd, VFIO_CHECK_EXTENSION, VFIO_TYPE1_IOMMU)) { + /* Connect group to container */ + ret = ioctl(vfio_group->fd, VFIO_GROUP_SET_CONTAINER, &fd); + if (ret) { + FSLMC_VFIO_LOG(ERR, "Failed to setup group container"); + close(fd); + return -errno; + } + + ret = ioctl(fd, VFIO_SET_IOMMU, VFIO_TYPE1_IOMMU); + if (ret) { + FSLMC_VFIO_LOG(ERR, "Failed to setup VFIO iommu"); + close(fd); + return -errno; + } + } else { + FSLMC_VFIO_LOG(ERR, "No supported IOMMU available"); + close(fd); + return -EINVAL; + } + + container = NULL; + for (i = 0; i < VFIO_MAX_CONTAINERS; i++) { + if (vfio_containers[i].used) + continue; + FSLMC_VFIO_LOG(DEBUG, "Unused container at index %d", i); + container = &vfio_containers[i]; + } + if (!container) { + FSLMC_VFIO_LOG(ERR, "No free container found"); + close(fd); + return -ENOMEM; + } + + container->used = 1; + container->fd = fd; + container->group_list[container->index] = vfio_group; + vfio_group->container = container; + container->index++; + return 0; +} + +int vfio_dmamap_mem_region(uint64_t vaddr, + uint64_t iova, + uint64_t size) +{ + struct fslmc_vfio_group *group; + struct vfio_iommu_type1_dma_map dma_map = { + .argsz = sizeof(dma_map), + .flags = VFIO_DMA_MAP_FLAG_READ | VFIO_DMA_MAP_FLAG_WRITE, + }; + + dma_map.vaddr = vaddr; + dma_map.size = size; + dma_map.iova = iova; + + /* SET DMA MAP for IOMMU */ + group = &vfio_groups[0]; + if (ioctl(group->container->fd, VFIO_IOMMU_MAP_DMA, &dma_map)) { + FSLMC_VFIO_LOG(ERR, "VFIO_IOMMU_MAP_DMA (errno = %d)", errno); + return -1; + } + return 0; +} + +static int64_t vfio_map_mcp_obj(struct fslmc_vfio_group *group, char *mcp_obj) +{ + int64_t v_addr = (int64_t)MAP_FAILED; + int32_t ret, mc_fd; + + struct vfio_device_info d_info = { .argsz = sizeof(d_info) }; + struct vfio_region_info reg_info = { .argsz = sizeof(reg_info) }; + + /* getting the mcp object's fd*/ + mc_fd = ioctl(group->fd, VFIO_GROUP_GET_DEVICE_FD, mcp_obj); + if (mc_fd < 0) { + FSLMC_VFIO_LOG(ERR, "error in VFIO get device %s fd from group" + " %d", mcp_obj, group->fd); + return v_addr; + } + + /* getting device info*/ + ret = ioctl(mc_fd, VFIO_DEVICE_GET_INFO, &d_info); + if (ret < 0) { + FSLMC_VFIO_LOG(ERR, "error in VFIO getting DEVICE_INFO"); + goto MC_FAILURE; + } + + /* getting device region info*/ + ret = ioctl(mc_fd, VFIO_DEVICE_GET_REGION_INFO, ®_info); + if (ret < 0) { + FSLMC_VFIO_LOG(ERR, "error in VFIO getting REGION_INFO"); + goto MC_FAILURE; + } + + FSLMC_VFIO_LOG(DEBUG, "region offset = %llx , region size = %llx", + reg_info.offset, reg_info.size); + + v_addr = (uint64_t)mmap(NULL, reg_info.size, + PROT_WRITE | PROT_READ, MAP_SHARED, + mc_fd, reg_info.offset); + +MC_FAILURE: + close(mc_fd); + + return v_addr; +} + +/* Following function shall fetch total available list of MC devices + * from VFIO container & populate private list of devices and other + * data structures + */ +int fslmc_vfio_process_group(void) +{ + struct fslmc_vfio_device *vdev; + struct vfio_device_info device_info = { .argsz = sizeof(device_info) }; + char *temp_obj, *object_type __rte_unused, *mcp_obj, *dev_name; + int32_t object_id, i, dev_fd; + DIR *d; + struct dirent *dir; + char path[PATH_MAX]; + int64_t v_addr; + int ndev_count; + struct fslmc_vfio_group *group = &vfio_groups[0]; + static int process_once; + + /* if already done once */ + if (process_once) { + FSLMC_VFIO_LOG(DEBUG, "Already scanned once - re-scan " + "not supported"); + return 0; + } + process_once = 0; + + sprintf(path, "/sys/kernel/iommu_groups/%d/devices", group->groupid); + + d = opendir(path); + if (!d) { + FSLMC_VFIO_LOG(ERR, "Unable to open directory %s", path); + return -1; + } + + /*Counting the number of devices in a group and getting the mcp ID*/ + ndev_count = 0; + mcp_obj = NULL; + while ((dir = readdir(d)) != NULL) { + if (dir->d_type == DT_LNK) { + ndev_count++; + if (!strncmp("dpmcp", dir->d_name, 5)) { + if (mcp_obj) + free(mcp_obj); + mcp_obj = malloc(sizeof(dir->d_name)); + if (!mcp_obj) { + FSLMC_VFIO_LOG(ERR, "mcp obj:Unable to" + " allocate memory"); + return -ENOMEM; + } + strcpy(mcp_obj, dir->d_name); + temp_obj = strtok(dir->d_name, "."); + temp_obj = strtok(NULL, "."); + sscanf(temp_obj, "%d", &mcp_id); + } + } + } + closedir(d); + + if (!mcp_obj) { + FSLMC_VFIO_LOG(ERR, "DPAA2 MCP Object not Found"); + return -ENODEV; + } + RTE_LOG(INFO, EAL, "fslmc: DPRC contains = %d devices\n", ndev_count); + + /* Allocate the memory depends upon number of objects in a group*/ + group->vfio_device = (struct fslmc_vfio_device *)malloc(ndev_count * + sizeof(struct fslmc_vfio_device)); + if (!(group->vfio_device)) { + FSLMC_VFIO_LOG(ERR, "vfio device: Unable to allocate memory\n"); + free(mcp_obj); + return -ENOMEM; + } + + /* Allocate memory for MC Portal list */ + rte_mcp_ptr_list = malloc(sizeof(void *) * 1); + if (!rte_mcp_ptr_list) { + FSLMC_VFIO_LOG(ERR, "portal list: Unable to allocate memory!"); + free(mcp_obj); + goto FAILURE; + } + + v_addr = vfio_map_mcp_obj(group, mcp_obj); + free(mcp_obj); + if (v_addr == (int64_t)MAP_FAILED) { + FSLMC_VFIO_LOG(ERR, "Error mapping region (errno = %d)", errno); + goto FAILURE; + } + + FSLMC_VFIO_LOG(DEBUG, "DPAA2 MC has VIR_ADD = %ld", v_addr); + + rte_mcp_ptr_list[0] = (void *)v_addr; + + d = opendir(path); + if (!d) { + FSLMC_VFIO_LOG(ERR, "Unable to open %s Directory", path); + goto FAILURE; + } + + i = 0; + FSLMC_VFIO_LOG(DEBUG, "DPAA2 - Parsing devices:"); + /* Parsing each object and initiating them*/ + while ((dir = readdir(d)) != NULL) { + if (dir->d_type != DT_LNK) + continue; + if (!strncmp("dprc", dir->d_name, 4) || + !strncmp("dpmcp", dir->d_name, 5)) + continue; + dev_name = malloc(sizeof(dir->d_name)); + if (!dev_name) { + FSLMC_VFIO_LOG(ERR, "name: Unable to allocate memory"); + goto FAILURE; + } + strcpy(dev_name, dir->d_name); + object_type = strtok(dir->d_name, "."); + temp_obj = strtok(NULL, "."); + sscanf(temp_obj, "%d", &object_id); + FSLMC_VFIO_LOG(DEBUG, " - %s ", dev_name); + + /* getting the device fd*/ + dev_fd = ioctl(group->fd, VFIO_GROUP_GET_DEVICE_FD, dev_name); + if (dev_fd < 0) { + FSLMC_VFIO_LOG(ERR, "VFIO_GROUP_GET_DEVICE_FD error" + " Device fd: %s, Group: %d", + dev_name, group->fd); + free(dev_name); + goto FAILURE; + } + + free(dev_name); + vdev = &group->vfio_device[group->object_index++]; + vdev->fd = dev_fd; + vdev->index = i; + i++; + /* Get Device inofrmation */ + if (ioctl(vdev->fd, VFIO_DEVICE_GET_INFO, &device_info)) { + FSLMC_VFIO_LOG(ERR, "DPAA2 VFIO_DEVICE_GET_INFO fail"); + goto FAILURE; + } + } + closedir(d); + + return 0; + +FAILURE: + free(group->vfio_device); + group->vfio_device = NULL; + return -1; +} + +int fslmc_vfio_setup_group(void) +{ + struct fslmc_vfio_group *group = NULL; + int groupid; + int ret, i; + char *container; + struct vfio_group_status status = { .argsz = sizeof(status) }; + + /* if already done once */ + if (container_device_fd) + return 0; + + container = getenv("DPRC"); + + if (container == NULL) { + FSLMC_VFIO_LOG(ERR, "VFIO container not set in env DPRC"); + return -1; + } + /* get group number */ + ret = vfio_get_group_no(SYSFS_FSL_MC_DEVICES, container, &groupid); + if (ret == 0) { + RTE_LOG(WARNING, EAL, "%s not managed by VFIO, skipping\n", + container); + return 1; + } + + /* if negative, something failed */ + if (ret < 0) + return -1; + + FSLMC_VFIO_LOG(DEBUG, "VFIO iommu group id = %d", groupid); + + /* Check if group already exists */ + for (i = 0; i < VFIO_MAX_GRP; i++) { + group = &vfio_groups[i]; + if (group->groupid == groupid) { + FSLMC_VFIO_LOG(ERR, "groupid already exists %d", + groupid); + return 0; + } + } + + /* get the actual group fd */ + group->fd = vfio_get_group_fd(groupid); + if (group->fd < 0) + return -1; + + /* + * at this point, we know that this group is viable (meaning, + * all devices are either bound to VFIO or not bound to anything) + */ + + if (ioctl(group->fd, VFIO_GROUP_GET_STATUS, &status)) { + FSLMC_VFIO_LOG(ERR, " VFIO error getting group status"); + close(group->fd); + return -1; + } + if (!(status.flags & VFIO_GROUP_FLAGS_VIABLE)) { + FSLMC_VFIO_LOG(ERR, "VFIO group not viable"); + close(group->fd); + return -1; + } + /* Since Group is VIABLE, Store the groupid */ + group->groupid = groupid; + + /* check if group does not have a container yet */ + if (!(status.flags & VFIO_GROUP_FLAGS_CONTAINER_SET)) { + /* Now connect this IOMMU group to given container */ + if (vfio_connect_container(group)) { + FSLMC_VFIO_LOG(ERR, "VFIO error connecting container" + " with groupid %d", groupid); + close(group->fd); + return -1; + } + } + + /* Get Device information */ + ret = ioctl(group->fd, VFIO_GROUP_GET_DEVICE_FD, container); + if (ret < 0) { + FSLMC_VFIO_LOG(ERR, "VFIO error getting device %s fd from" + " group %d", container, group->groupid); + return ret; + } + container_device_fd = ret; + FSLMC_VFIO_LOG(DEBUG, "VFIO Container FD is [0x%X]", + container_device_fd); + + return 0; +} diff --git a/drivers/bus/fslmc/fslmc_vfio.h b/drivers/bus/fslmc/fslmc_vfio.h new file mode 100644 index 0000000..5e58211 --- /dev/null +++ b/drivers/bus/fslmc/fslmc_vfio.h @@ -0,0 +1,74 @@ +/*- + * BSD LICENSE + * + * Copyright (c) 2015-2016 Freescale Semiconductor, Inc. All rights reserved. + * Copyright (c) 2016 NXP. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Freescale Semiconductor, Inc nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _FSLMC_VFIO_H_ +#define _FSLMC_VFIO_H_ + +#include "eal_vfio.h" + +#define DPAA2_VENDOR_ID 0x1957 +#define DPAA2_MC_DPNI_DEVID 7 +#define DPAA2_MC_DPSECI_DEVID 3 + +#define VFIO_MAX_GRP 1 + +typedef struct fslmc_vfio_device { + int fd; /* fslmc root container device ?? */ + int index; /*index of child object */ + struct fslmc_vfio_device *child; /* Child object */ +} fslmc_vfio_device; + +typedef struct fslmc_vfio_group { + int fd; /* /dev/vfio/"groupid" */ + int groupid; + struct fslmc_vfio_container *container; + int object_index; + struct fslmc_vfio_device *vfio_device; +} fslmc_vfio_group; + +typedef struct fslmc_vfio_container { + int fd; /* /dev/vfio/vfio */ + int used; + int index; /* index in group list */ + struct fslmc_vfio_group *group_list[VFIO_MAX_GRP]; +} fslmc_vfio_container; + +int vfio_dmamap_mem_region( + uint64_t vaddr, + uint64_t iova, + uint64_t size); + +int fslmc_vfio_setup_group(void); +int fslmc_vfio_process_group(void); + +#endif /* _FSLMC_VFIO_H_ */ diff --git a/drivers/bus/fslmc/rte_bus_fslmc_version.map b/drivers/bus/fslmc/rte_bus_fslmc_version.map index 67b0dc8..f64572f 100644 --- a/drivers/bus/fslmc/rte_bus_fslmc_version.map +++ b/drivers/bus/fslmc/rte_bus_fslmc_version.map @@ -36,6 +36,7 @@ DPDK_17.05 { qbman_swp_send_multiple; rte_fslmc_driver_register; rte_fslmc_driver_unregister; + rte_mcp_ptr_list; local: *; }; -- 1.9.1