From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM03-BY2-obe.outbound.protection.outlook.com (mail-by2nam03on0057.outbound.protection.outlook.com [104.47.42.57]) by dpdk.org (Postfix) with ESMTP id 62501BB20 for ; Fri, 28 Oct 2016 14:31:13 +0200 (CEST) Received: from BY2PR03CA074.namprd03.prod.outlook.com (10.141.249.47) by SN2PR03MB2381.namprd03.prod.outlook.com (10.166.210.148) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.679.12; Fri, 28 Oct 2016 12:31:07 +0000 Received: from BL2FFO11FD052.protection.gbl (2a01:111:f400:7c09::168) by BY2PR03CA074.outlook.office365.com (2a01:111:e400:2c5d::47) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.679.12 via Frontend Transport; Fri, 28 Oct 2016 12:31:08 +0000 Authentication-Results: spf=fail (sender IP is 192.88.168.50) smtp.mailfrom=nxp.com; nxp.com; dkim=none (message not signed) header.d=none;nxp.com; dmarc=fail action=none header.from=nxp.com;nxp.com; dkim=none (message not signed) header.d=none; 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 BL2FFO11FD052.mail.protection.outlook.com (10.173.161.214) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.1.679.5 via Frontend Transport; Fri, 28 Oct 2016 12:31:07 +0000 Received: from Tophie.ap.freescale.net ([10.232.14.87]) by tx30smr01.am.freescale.net (8.14.3/8.14.0) with ESMTP id u9SCPEMS019399; Fri, 28 Oct 2016 05:31:04 -0700 From: Shreyansh Jain To: Date: Fri, 28 Oct 2016 17:56:33 +0530 Message-ID: <1477657598-826-17-git-send-email-shreyansh.jain@nxp.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1477657598-826-1-git-send-email-shreyansh.jain@nxp.com> References: <1477581467-12588-1-git-send-email-shreyansh.jain@nxp.com> <1477657598-826-1-git-send-email-shreyansh.jain@nxp.com> X-EOPAttributedMessage: 0 X-Matching-Connectors: 131221314675869601; (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)(7916002)(2980300002)(1110001)(1109001)(339900001)(189002)(199003)(105606002)(104016004)(36756003)(106466001)(586003)(50986999)(76176999)(92566002)(229853001)(2351001)(81156014)(81166006)(48376002)(50466002)(68736007)(97736004)(8936002)(50226002)(7846002)(47776003)(6666003)(305945005)(356003)(8666005)(4326007)(2906002)(5003940100001)(33646002)(19580405001)(19580395003)(77096005)(189998001)(86362001)(8676002)(5660300001)(87936001)(2950100002)(6916009)(85426001)(626004)(110136003)(403724002)(7059030); DIR:OUT; SFP:1101; SCL:1; SRVR:SN2PR03MB2381; H:tx30smr01.am.freescale.net; FPR:; SPF:Fail; PTR:InfoDomainNonexistent; MX:1; A:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; BL2FFO11FD052; 1:wqfCCVY6r0WlDJ3yGMmwomuC71BYuyBTNjTJyFqUA38bz45qyiJjYnlmMDru2YMtCELh7XgHZzIm5vwIjqisB5cuhfk3eIlA6Rc+mD1QvZZhI+TVSvgeVLdWOoozgRAZSE35ieCkLcszi5qdJvZK2xFGxKIKLT9LgCutH7DSzvK+Pb/cz0o9kOV0QPnpVxx6Zi4/Es1w1rKY70t2jbNWc1ZaN0R8bEbQkaXX5Sdwf9kLqKKGLXqcv1bJFAa3ztqiOLOihdsXnPrp/9IWKC35U9VIadglZkKW3CeborXp0MvLaepQgElxGmz1bX3d6srrSDAfDv+jAVCcACOyI85pnSzPLeLf55mUB+ar6tx8Pg00j4IfdhxxXw5YVSaTj8iR05lN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/2GSZzjkqLJ3vD6Fn9VEL4IdDKBdcAPut8AqUlKZSqLyjmbLzzbwGz7/Op9aPUMlBqyfjHK9wNSr9b3MgvoHdBvqcNWtW1lUc2bCekfQ6db0Yn0z/ZjekbFYnvZ9vpsY3d4AlRqaKj+XZahD6yKk5JbT+1n3EIYmFV1jEFDG7N/Vg8UAvmlQTAstScP+/l2SQtNI8sMCyjog66gg+jt8DsMCTkzV1WyYVW9wQAaLIGfU1KXR/SY+rB+vdJ0MdpteJR X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(185117386973197); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040176)(601004)(2401047)(13017025)(13015025)(13018025)(13024025)(5005006)(8121501046)(13023025)(3002001)(10201501046)(6055026); SRVR:SN2PR03MB2381; BCL:0; PCL:0; RULEID:(400006); SRVR:SN2PR03MB2381; X-Forefront-PRVS: 0109D382B0 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; SN2PR03MB2381; 23:s6dNASGR3HuuTIOaJgYvLXaVAHxUnPb2w0sf01uEj?= =?us-ascii?Q?84RVaxchTefUXRXSU07Lu025zgou0Z2eyWH4eTME7ImetIDUF5nmTqfHw687?= =?us-ascii?Q?2kFP3z4riGouSaKHV+2Vk/MRTiy2u5BgS/m1prFoUe5PnJmpzrGJcMkUWUy8?= =?us-ascii?Q?YV+5jNENmuuhc4t5Fuug/6XuDQh+EgIRuEHCpHK4l0gkMd3gTdOE1Z+6JiOq?= =?us-ascii?Q?9Asp7uKyDMNg4iQTuXOFPqVZA/fwOEwVTAHknjP6s2fPgBE3ASqBEFOUuuwh?= =?us-ascii?Q?Jq7zM1R8gBmlzesznEPKcBdTSJqI7h1kPId27sKIspb6Q2wdt9dnceDDds99?= =?us-ascii?Q?qivT3MJcCGgegh2bzH487WMeSY7EG4G1F/7N3KzLuFwfXzBWDtOCjd6md2Iq?= =?us-ascii?Q?W7w25vdD4k6wMjqG+/KRXCBQqeN4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x1RbpuR08mzYGLyk++sf8ubRDz431P0+I5zJHiFxov8/cNnmOeICJOJTb8WPJiH4SHGcNJMnuaUfG6S+MI1lKRY+AuOCLHHXM8zCslXvPdhpDnqvGhL8SK3kpPWwSnUfNzKi54duoFA5Qcp8yRx2P85cvRcHoigPdllgkHi2BGCnAXRlnac5gyW35kTibQ27J+D49/5CPqP9l2bKJ846ADI198wZnMm1o7XgMqFG2fab2cwTDO1vwqvZtcoTEa9YQzo; 5:ZyQk1d5JNurHOGGRAYeNMpPWy94O3Q+15VnvWy/Eve0NxZh4zClWk/FprbVdYANkwCBjC3YV+T7C0yi7G7swhbvk/aGSy4FAPeB2gLiVtBVm0GfrT1ILEdsEKSTwq5ba0JVqbwGuHBfJZwhkGusAdzDUat4VbI6RPPmPyeAsFavUmdlc2WXqV7cBq+0LSmLA; 24:QOkcV9PcdCn4rAmkInoJ2r76DltgWrtQ1/3JPZBGRUb5tLGe5BkEu0hrH8iI9MQVADFtak6yujyq4Q97NbktF9XmQAMWx2w5hRYIC9Jclto= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; SN2PR03MB2381; 7:iPSWU5Vse2N7p0qjqSL9VGcpTwQRqvMlJlYHVhWTfspMPX5EqTpapqo5y6/92Krs+ASnVp7UoRvLmvtfAesguzStKkYpPXHl2Zq5w0WfVf7OPZPjzdUZnNEGTqVlEUVR8M2SpEoQCPHjTrfKbxWQsoqYHepcZAFhka/OmbVHKD47KdVLDZF91ZeNZz7X072B6eGpZIYmrad80rHy77siCKQ9aUlpVMnPLrC1SbHGRTV4WJqWffokNsVXfuiorLstPPXf/89AFdeA6QZ1E0rHQ/NqNru/TaZOaT4Sn9QM2ALXv13bYHEtRd9zK2XIxN/qmroZnVAklzuMlE8WsTqHtUUv5q0DlbE/TO5v5BfmD4I= X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Oct 2016 12:31:07.3997 (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: SN2PR03MB2381 Cc: Shreyansh Jain , thomas.monjalon@6wind.com, viktorin@rehivetech.com Subject: [dpdk-dev] [PATCH v7 16/21] eal/soc: additional features for SoC X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 28 Oct 2016 12:31:14 -0000 From: Jan Viktorin Additional features introduced: - Find kernel driver through sysfs bindings - Dummy implementation for mapping to kernel driver - DMA coherency value from sysfs - Numa node number from sysfs - Support for updating device during probe if already registered Signed-off-by: Jan Viktorin [Shreyansh: merge multiple patches into single set] Signed-off-by: Shreyansh Jain --- lib/librte_eal/common/eal_common_soc.c | 30 ++++++++ lib/librte_eal/common/eal_private.h | 23 ++++++ lib/librte_eal/common/include/rte_soc.h | 28 +++++++ lib/librte_eal/linuxapp/eal/eal_soc.c | 129 ++++++++++++++++++++++++++++++++ 4 files changed, 210 insertions(+) diff --git a/lib/librte_eal/common/eal_common_soc.c b/lib/librte_eal/common/eal_common_soc.c index 44f5559..29c38e0 100644 --- a/lib/librte_eal/common/eal_common_soc.c +++ b/lib/librte_eal/common/eal_common_soc.c @@ -114,6 +114,26 @@ rte_eal_soc_probe_one_driver(struct rte_soc_driver *drv, return ret; } + if (!dev->is_dma_coherent) { + if (!(drv->drv_flags & RTE_SOC_DRV_ACCEPT_NONCC)) { + RTE_LOG(DEBUG, EAL, + " device is not DMA coherent, skipping\n"); + return 1; + } + } + + if (drv->drv_flags & RTE_SOC_DRV_NEED_MAPPING) { + /* map resources */ + ret = rte_eal_soc_map_device(dev); + if (ret) + return ret; + } else if (drv->drv_flags & RTE_SOC_DRV_FORCE_UNBIND + && rte_eal_process_type() == RTE_PROC_PRIMARY) { + /* unbind */ + if (soc_unbind_kernel_driver(dev) < 0) + return -1; + } + dev->driver = drv; RTE_VERIFY(drv->probe != NULL); return drv->probe(drv, dev); @@ -166,6 +186,10 @@ rte_eal_soc_detach_dev(struct rte_soc_driver *drv, if (drv->remove && (drv->remove(dev) < 0)) return -1; /* negative value is an error */ + if (drv->drv_flags & RTE_SOC_DRV_NEED_MAPPING) + /* unmap resources for devices */ + rte_eal_soc_unmap_device(dev); + /* clear driver structure */ dev->driver = NULL; @@ -241,6 +265,12 @@ rte_eal_soc_probe_one(const struct rte_soc_addr *addr) if (addr == NULL) return -1; + /* update current SoC device in global list, kernel bindings might have + * changed since last time we looked at it. + */ + if (soc_update_device(addr) < 0) + goto err_return; + TAILQ_FOREACH(dev, &soc_device_list, next) { if (rte_eal_compare_soc_addr(&dev->addr, addr)) continue; diff --git a/lib/librte_eal/common/eal_private.h b/lib/librte_eal/common/eal_private.h index d810f9f..30c648d 100644 --- a/lib/librte_eal/common/eal_private.h +++ b/lib/librte_eal/common/eal_private.h @@ -159,6 +159,29 @@ int pci_update_device(const struct rte_pci_addr *addr); int pci_unbind_kernel_driver(struct rte_pci_device *dev); /** + * Update a soc device object by asking the kernel for the latest information. + * + * This function is private to EAL. + * + * @param addr + * The SoC address to look for + * @return + * - 0 on success. + * - negative on error. + */ +int soc_update_device(const struct rte_soc_addr *addr); + +/** + * Unbind kernel driver for this device + * + * This function is private to EAL. + * + * @return + * 0 on success, negative on error + */ +int soc_unbind_kernel_driver(struct rte_soc_device *dev); + +/** * Map the PCI resource of a PCI device in virtual memory * * This function is private to EAL. diff --git a/lib/librte_eal/common/include/rte_soc.h b/lib/librte_eal/common/include/rte_soc.h index 8be3db7..d7f7ec8 100644 --- a/lib/librte_eal/common/include/rte_soc.h +++ b/lib/librte_eal/common/include/rte_soc.h @@ -46,9 +46,11 @@ extern "C" { #include #include +#include #include #include #include +#include #include #include @@ -63,6 +65,14 @@ extern struct soc_device_list soc_device_list; TAILQ_HEAD(soc_driver_list, rte_soc_driver); /**< SoC drivers in D-linked Q. */ TAILQ_HEAD(soc_device_list, rte_soc_device); /**< SoC devices in D-linked Q. */ +#define SOC_MAX_RESOURCE 6 + +struct rte_soc_resource { + uint64_t phys_addr; + uint64_t len; + void *addr; +}; + struct rte_soc_id { union { const char *compatible; /**< OF compatible specification */ @@ -84,8 +94,12 @@ struct rte_soc_device { struct rte_device device; /**< Inherit code device */ struct rte_soc_addr addr; /**< SoC device Location */ struct rte_soc_id *id; /**< SoC device ID list */ + struct rte_soc_resource mem_resource[SOC_MAX_RESOURCE]; struct rte_intr_handle intr_handle; /**< Interrupt handle */ struct rte_soc_driver *driver; /**< Associated driver */ + int numa_node; /**< NUMA node connection */ + int is_dma_coherent; /**< DMA coherent device */ + enum rte_kernel_driver kdrv; /**< Kernel driver */ }; struct rte_soc_driver; @@ -139,6 +153,8 @@ struct rte_soc_driver { #define RTE_SOC_DRV_INTR_LSC 0x0008 /** Device driver supports detaching capability */ #define RTE_SOC_DRV_DETACHABLE 0x0010 +/** Device driver accepts DMA non-coherent devices */ +#define RTE_SOC_DRV_ACCEPT_NONCC 0x0020 /** * Utility function to write a SoC device name, this device name can later be @@ -256,6 +272,18 @@ int rte_eal_soc_probe_one(const struct rte_soc_addr *addr); int rte_eal_soc_detach(const struct rte_soc_addr *addr); /** + * Map SoC device resources into userspace. + * + * This is called by the EAL if (drv_flags & RTE_SOC_DRV_NEED_MAPPING). + */ +int rte_eal_soc_map_device(struct rte_soc_device *dev); + +/** + * Unmap the device resources. + */ +void rte_eal_soc_unmap_device(struct rte_soc_device *dev); + +/** * Dump discovered SoC devices. * * @param f diff --git a/lib/librte_eal/linuxapp/eal/eal_soc.c b/lib/librte_eal/linuxapp/eal/eal_soc.c index d8dfe97..95f7565 100644 --- a/lib/librte_eal/linuxapp/eal/eal_soc.c +++ b/lib/librte_eal/linuxapp/eal/eal_soc.c @@ -63,6 +63,45 @@ soc_get_sysfs_path(void) return path; } +int +soc_unbind_kernel_driver(struct rte_soc_device *dev) +{ + char devpath[PATH_MAX]; + + snprintf(devpath, sizeof(devpath), "%s/%s", + soc_get_sysfs_path(), dev->addr.name); + + return rte_eal_unbind_kernel_driver(devpath, dev->addr.name); +} + +int +rte_eal_soc_map_device(struct rte_soc_device *dev) +{ + int ret = -1; + + /* try mapping the NIC resources using VFIO if it exists */ + switch (dev->kdrv) { + default: + RTE_LOG(DEBUG, EAL, + " Not managed by a supported kernel driver, skipped\n"); + ret = 1; + break; + } + + return ret; +} + +void +rte_eal_soc_unmap_device(struct rte_soc_device *dev) +{ + switch (dev->kdrv) { + default: + RTE_LOG(DEBUG, EAL, + " Not managed by a supported kernel driver, skipped\n"); + break; + } +} + static char * dev_read_uevent(const char *dirname) { @@ -260,6 +299,68 @@ dev_content_free(struct rte_soc_device *dev) } } +static int +dev_setup_associated_driver(struct rte_soc_device *dev, const char *dirname) +{ + char filename[PATH_MAX]; + char driver[PATH_MAX]; + int ret; + + /* parse driver */ + snprintf(filename, sizeof(filename), "%s/driver", dirname); + ret = rte_eal_get_kernel_driver_by_path(filename, driver); + if (ret < 0) { + RTE_LOG(ERR, EAL, "Fail to get kernel driver for %s\n", + dirname); + return 1; + } + + if (!ret) + dev->kdrv = RTE_KDRV_UNKNOWN; + else + dev->kdrv = RTE_KDRV_NONE; + + return 0; +} + +static int +dev_setup_numa_node(struct rte_soc_device *dev, const char *dirname) +{ + char filename[PATH_MAX]; + + /* if no NUMA support, set default to 0 */ + unsigned long tmp = 0; + int ret = 0; + + /* get numa node */ + snprintf(filename, sizeof(filename), "%s/numa_node", dirname); + + if (eal_parse_sysfs_value(filename, &tmp) < 0) + ret = 1; + + dev->numa_node = tmp; + return ret; +} + +static int +dev_detect_is_coherent(struct rte_soc_device *dev) +{ + char filename[PATH_MAX]; + FILE *f; + + if (dev->addr.fdt_path == NULL) + return 0; /* no way to detect */ + + snprintf(filename, sizeof(filename), "%s%s/dma-coherent", + "/proc/device-tree", dev->addr.fdt_path); + f = fopen(filename, "r"); + if (f == NULL) + return 0; + + fclose(f); + return 1; +} + /** * Scan one SoC sysfs entry, and fill the devices list from it. * We require to have the uevent file with records: OF_FULLNAME and @@ -299,6 +400,18 @@ soc_scan_one(const char *dirname, const char *name) goto fail; free(uevent); /* not needed anymore */ + ret = dev_setup_associated_driver(dev, dirname); + if (ret) + goto fail; + + ret = dev_setup_numa_node(dev, dirname); + if (ret < 0) + goto fail; + + dev->is_dma_coherent = dev_detect_is_coherent(dev); + RTE_LOG(DEBUG, EAL, " DMA %s\n", + dev->is_dma_coherent ? "coherent" : "non-coherent"); + /* device is valid, add in list (sorted) */ if (TAILQ_EMPTY(&soc_device_list)) { TAILQ_INSERT_TAIL(&soc_device_list, dev, next); @@ -313,6 +426,11 @@ soc_scan_one(const char *dirname, const char *name) if (ret < 0) { TAILQ_INSERT_BEFORE(dev2, dev, next); } else { /* already registered */ + dev2->kdrv = dev->kdrv; + dev2->is_dma_coherent = dev->is_dma_coherent; + memmove(dev2->mem_resource, dev->mem_resource, + sizeof(dev->mem_resource)); + dev_content_free(dev2); dev2->addr.fdt_path = dev->addr.fdt_path; dev2->id = dev->id; @@ -333,6 +451,17 @@ fail: } int +soc_update_device(const struct rte_soc_addr *addr) +{ + char filename[PATH_MAX]; + + snprintf(filename, sizeof(filename), "%s/%s", + soc_get_sysfs_path(), addr->name); + + return soc_scan_one(filename, addr->name); +} + +int rte_eal_soc_scan_platform_bus(void) { struct dirent *e; -- 2.7.4