From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM03-DM3-obe.outbound.protection.outlook.com (mail-dm3nam03on0050.outbound.protection.outlook.com [104.47.41.50]) by dpdk.org (Postfix) with ESMTP id 0C0F65688 for ; Sun, 9 Apr 2017 09:48:40 +0200 (CEST) Received: from BN6PR03CA0045.namprd03.prod.outlook.com (10.175.124.31) by CY4PR03MB3110.namprd03.prod.outlook.com (10.171.245.151) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1005.10; Sun, 9 Apr 2017 07:48:38 +0000 Received: from BY2FFO11FD014.protection.gbl (2a01:111:f400:7c0c::179) by BN6PR03CA0045.outlook.office365.com (2603:10b6:404:10c::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1019.17 via Frontend Transport; Sun, 9 Apr 2017 07:48:37 +0000 Authentication-Results: spf=fail (sender IP is 192.88.168.50) smtp.mailfrom=nxp.com; intel.com; dkim=none (message not signed) header.d=none;intel.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 BY2FFO11FD014.mail.protection.outlook.com (10.1.14.76) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.1.1019.14 via Frontend Transport; Sun, 9 Apr 2017 07:48:37 +0000 Received: from DTS-02.ap.freescale.net (DTS-02.ap.freescale.net [10.232.132.223]) by tx30smr01.am.freescale.net (8.14.3/8.14.0) with ESMTP id v397mBLR024015; Sun, 9 Apr 2017 00:48:34 -0700 From: Hemant Agrawal To: , CC: , , Date: Sun, 9 Apr 2017 13:20:11 +0530 Message-ID: <1491724224-6319-9-git-send-email-hemant.agrawal@nxp.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1491724224-6319-1-git-send-email-hemant.agrawal@nxp.com> References: <1489754838-1455-1-git-send-email-hemant.agrawal@nxp.com> <1491724224-6319-1-git-send-email-hemant.agrawal@nxp.com> X-EOPAttributedMessage: 0 X-Matching-Connectors: 131361977175000643; (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)(39380400002)(39410400002)(39400400002)(39450400003)(39840400002)(39860400002)(39850400002)(2980300002)(1109001)(1110001)(339900001)(3190300001)(189002)(199003)(9170700003)(305945005)(8656002)(54906002)(189998001)(356003)(5660300001)(575784001)(77096006)(105606002)(4326008)(5003940100001)(104016004)(47776003)(53936002)(36756003)(48376002)(33646002)(38730400002)(76176999)(86362001)(50986999)(106466001)(8676002)(8936002)(85426001)(50466002)(81166006)(2950100002)(2906002)(6666003)(50226002); DIR:OUT; SFP:1101; SCL:1; SRVR:CY4PR03MB3110; H:tx30smr01.am.freescale.net; FPR:; SPF:Fail; MLV:ovrnspm; MX:1; A:1; PTR:InfoDomainNonexistent; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; BY2FFO11FD014; 1:jNeSBa2zoeQwSdESHMvE5aif5UOnyfNdEmuSPAZDq6NV8BU7KqNf1OR+yglMw0xEFxs96X4QAiCh6GZY0v16NACwaOtwHGI3SClEIuI+hzKxN0mgx4SzK0R4q/EGXgRh6th8Lpwp62l45y11QsqT/OACEzKE1LuJBL8oLYIRUlKTKe+XKmagWdNpWIexUzBxilFszvsLzEKy6d7C53gSnjGasRe8jE1Llx2YAPQtCjGBhlf7hPFfK5WNu7dXfm5cljP6FpG+yupKdYpVycmcnhTidT5LUdxUlLfxN6Gwd69Qqo+9rMgHva61EBXAJAA+Otnjvm9ynjIDxejzNl2bBc2RE6kC+AONVkxvwyOyERL6+ih3YdGr/xVVTcY9QkRyjfTCvf6Nrvx2gyU/hgX8zrXR0pk2It+jL3sWsQrcqLQTTM45LSB204OV+kF1EY060GJUSofxpVOIOp+0Y7EV81iEUpKqwxhL/cQ2ep4mefzZ4/DX50AcKXE14KsG5u9Kc1POmhuq2ibHB7pS0sYubTCmrteU1eIy83Q5qwEPSE/FvzGyaO1HEqSNf2QDvwEC+AalvoZOe8KaPKutscF3cN+1sS8zs6njDzKAH5DQ6bJnspdx1m/Nwi8mRSGqRGgLwhoJ75yHPsa/PevkMARMNFRhOihIj9kWQFXyB2wfyGwhnFbwrm+L+6OJPNnyJpAE MIME-Version: 1.0 Content-Type: text/plain X-MS-Office365-Filtering-Correlation-Id: 360c69ab-8115-4fe5-4643-08d47f1cd4f9 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(201703131430075)(201703131517081); SRVR:CY4PR03MB3110; X-Microsoft-Exchange-Diagnostics: 1; CY4PR03MB3110; 3:wbcyRV0gRk/sPZceGNptHi2lrYKbK9TIBokKOXxH3GatIgG6o8ljcqiSmRfZsHB+cpYrW4OoS31E/Q9B82o0LMkhDlqwVD9Rig66fhO073r7cOwQB1RCRQdt7ybJVBe9elVjrM9mCNd1FI0UjVHIQcP/4G/a9X+1MLKfzu5wiwR9bneVrwmmxca4vNBmjJwkl+YD4l/tVBO2rC2M/mv92uHo7CZGRTaYDwCuQbMjx32NuykG+eIzO4bfODIaZeo9Z1zGXTRPT6BqnFgNTHAg+YmzWLYyuId91zR+05oxO/QC0DMMQkj4NwLprSz14x5wqRCvBE+SHwmpsFLwIrpX9MhKj9fAGoBUCIZ5nW+eKgfhmDMiY7EkbHdWnzTawNh+Fh/U0Gmoom94NyZlf67EtvDfILa21xckB4WMeW/Q8QOA51/pYfty2EnP9sjW23Nh; 25:toduxr8dUqL6mIpKNna7bDx7VwnylIokNN90uAO3yQnhmJwTbYyHDc62HuacHnYFB5Ka2/X+QC2Ajyx8p3EbkKL2pJDivOPNLhdRo63dhpBmiHgBGJy2+K8ZEPUG06NsFRK2Jre2r5QIbX1gUamv5gYd8kjb+7KhPgwaI273bJ5fEZU0PZP2Ds6OvFF6iJ34hHs2e6caTsbE4ic0KeHXRiyTna2hl3leUoibLln4nDcN3jEvNPZhwcONnJS0frevm7Rggsg51w6jjJ9T+XGKVpzGGEqxmWTJXRlWRlOw4HicmhTRazbjBLFYDJY2isHa31DB4kzcUqqIYBahwoXufUrVF9urF5KUXABK2Fga5uTofHIM2TRFcn78OX4rXJpp3bVR+9TxjLDX8lK6L8e0g6RBN7+tL6FZMbj7GyUwwxWXCdj0Xb4CWyy06Y8s5wl+6hytKwbWZWBKa2xFvpDoYw== X-Microsoft-Exchange-Diagnostics: 1; CY4PR03MB3110; 31:30ICtpYuI5m5pC+yHPSRAsda+dLD+PCMdDE8dqeuS5SNcR8oNySTweiamEVwhjbqGsezPzDYLF3q8QjH9NHzc0ZFizod7WKr4f0dSTR9/WRGdRw4YWfXj1yFpL6T0xrNg+02Bxk6ITF7F+Pe2rU++L48kWnhBbi0tIC4rkyRceTraKplKZ0ETVRH9yhp9sk6PPwfR/wZQlT/huvZ/Dv/bey3D7UbUIpEFAeLHRjKzVPn90Vx5rOdZYTCFBy19FKXwNo2nOvsy+8eirBM+MJWAw== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(185117386973197)(275809806118684)(21532816269658); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6095135)(601004)(2401047)(8121501046)(13015025)(13017025)(5005006)(13018025)(13024025)(13023025)(93006095)(93001095)(3002001)(10201501046)(6055026)(6096035)(20161123563025)(20161123561025)(20161123565025)(20161123556025)(201703131430075)(201703131433075)(201703131448075)(201703161259075); SRVR:CY4PR03MB3110; BCL:0; PCL:0; RULEID:(400006); SRVR:CY4PR03MB3110; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; CY4PR03MB3110; 4:iPb5Ziz7McdydEdGpMuh/ZEj0OG80bkc8/OsiS/jrZ?= =?us-ascii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FVY5RVaURlEBdYu2gzeZZ/y/joQJonXVpHtE40nXmRL/1?= =?us-ascii?Q?IX30j4wRvuoZjApJa2c/Dk0TdtZSCluPXvyb64rQ=3D=3D?= X-Forefront-PRVS: 02723F29C4 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; CY4PR03MB3110; 23:8wYAuzaqN/Oaxvx/w71G6v6payZukL7jzvQh25amq?= =?us-ascii?Q?auQY+63THd9vD4u+4IKP+7UUHV/AMpqREjJowVb2pHevDHfAU3nwKo6elcBn?= =?us-ascii?Q?DqzERaweC3MbJ1XjH+ytbK3bAfaDJnaJeMRuwMAI4+3PmhcZPbDK68CyC049?= =?us-ascii?Q?5ZQvkQsiWiTUG6ntrERMjg5vi2BL8VUG9HUgPW+6q73oJRlZ56zNNHcJBOiF?= =?us-ascii?Q?UoyLCcVvYlsR264IeBwxmlpf1n4uyJAKX2bZz8Wz0pJiJC7+PmDW13ymXd4U?= =?us-ascii?Q?3WxmwEj6HmCGsSh76LxeckPe2sIiFE4Ue1kC0opURl0/E0tdD/ks2YwOoDHl?= =?us-ascii?Q?FKfX9unlTlaEl+yrP9mlWxcq5e6Hsaj7K2HiVY0RjOREY6neRWY3Aam0LN98?= =?us-ascii?Q?yAbysUNiMyKTESCiYnFBUT1Hpjae20VTNhRCM5v8V3iOdIhNIgVYaUsQTE8M?= =?us-ascii?Q?KX0ST87GLxK01d86JNtiyQDGYkLW5VpJzAbnU0bKwTAnzP49kXU1S3/ocbOf?= =?us-ascii?Q?pLzBolmcsnDNuh7708B7gJ6j1mNVEDUj+wydcmsitJjtOiqcabTIbPNLGEjT?= =?us-ascii?Q?HC3oe340OSTjNMytNr00JubVvsRyZyvinQ/Esi9Oim7XxSI6wzmITEZsPZmb?= =?us-ascii?Q?SZ1E4V+ViL2P1REUZnJzaVQvoPucJ/gykNLOwBu/EkzFwk8MFWafRextPMkW?= =?us-ascii?Q?E8GVf6CokVhUVcCxUjQ9Lsb3tYL1M11z8MRk/d7Ki6mHJ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IE2K7Jv15GC+LtEkw==; 5:J/U7FwUZbWbm2bQs3MPzujnzmytgwk+WNa/yV54PhA21KM/NQ6mJ3x80o+baVwA2LMs7UJHScMvL4egeKxKPX6DrYyocYAgrcioWuV84oK0amA+bdbOD1UDU7KXBYSlhjKgxNm1AAjFJc7Ngi6oG9VATUfnssp3Y6dGnXtNKLvPwf0u5ZdiwTK9o9DhB3MT1; 24:xvT0ALgqMR666ARHRpcyWcBH6WooDNrGRqDrP/LY69nT5Sj45Q25tYMO+bjbKjRutrWDrMuVMX39tXHbOyoqmTNctbnGFKC6uc6/a1enrmA= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; CY4PR03MB3110; 7:MyoDiHW08qu/nI4skIRcOFhecV1og6nsjv/kxKKAjp03rhPqUQNHCGsPh+O+/G8vhK7NZL5UO8aRu/FOeHA1UwqzW1nE9kcTYyEwG6755F4oDVdqsKbbkOH7EOYeitPWvnBATebBPf38hsi3kGxt8b9TY3zCJZwdhvlSkEYXA8FsP5vq0VFjBJuGE1O0/Fb0IfKLKnxvVuhBJx30RblkJfBdAx4nBvmWFeGPusDEHOEAaszklmloilYoJSddWQrsAniTA7J0eu9qfiPbfwNhk2UuvltW3TY4bVWVYqAqJHLYSrFqtjfR5tYzcutlZNmss2IT6zlycZ/zyC90PLFIVw== X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Apr 2017 07:48:37.3128 (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: CY4PR03MB3110 Subject: [dpdk-dev] [PATCH v3 08/21] 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: Sun, 09 Apr 2017 07:48:40 -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 | 16 + drivers/bus/fslmc/fslmc_vfio.c | 463 ++++++++++++++++++++++++++++ drivers/bus/fslmc/fslmc_vfio.h | 74 +++++ drivers/bus/fslmc/rte_bus_fslmc_version.map | 1 + 5 files changed, 555 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 9810e53..45b545c 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 include $(RTE_SDK)/mk/rte.lib.mk diff --git a/drivers/bus/fslmc/fslmc_bus.c b/drivers/bus/fslmc/fslmc_bus.c index 7848207..b24642d 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,21 @@ struct rte_fslmc_bus rte_fslmc_bus; static int rte_fslmc_scan(void) { + int ret; + + ret = fslmc_vfio_setup_group(); + if (ret) { + FSLMC_BUS_LOG(ERR, "fslmc: Unable to setup VFIO"); + return ret; + } + + ret = fslmc_vfio_process_group(); + if (ret) { + 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..8223e48 --- /dev/null +++ b/drivers/bus/fslmc/fslmc_vfio.c @@ -0,0 +1,463 @@ +/*- + * 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"); + closedir(d); + 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); + d = NULL; + 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: + if (d) + closedir(d); + if (rte_mcp_ptr_list) { + free(rte_mcp_ptr_list); + rte_mcp_ptr_list = NULL; + } + + 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 -EOPNOTSUPP; + } + + /* 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 -EOPNOTSUPP; + } + + /* if negative, something failed */ + if (ret < 0) + return ret; + + 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 */ + ret = vfio_get_group_fd(groupid); + if (ret < 0) + return ret; + group->fd = ret; + + /* + * at this point, we know that this group is viable (meaning, + * all devices are either bound to VFIO or not bound to anything) + */ + + ret = ioctl(group->fd, VFIO_GROUP_GET_STATUS, &status); + if (ret) { + FSLMC_VFIO_LOG(ERR, " VFIO error getting group status"); + close(group->fd); + return ret; + } + + if (!(status.flags & VFIO_GROUP_FLAGS_VIABLE)) { + FSLMC_VFIO_LOG(ERR, "VFIO group not viable"); + close(group->fd); + return -EPERM; + } + /* 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 */ + ret = vfio_connect_container(group); + if (ret) { + FSLMC_VFIO_LOG(ERR, "VFIO error connecting container" + " with groupid %d", groupid); + close(group->fd); + return ret; + } + } + + /* 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: *; }; -- 2.1.4