From c484fb35bf3edee3b12dc41dbbe49fff0e24c2c5 Mon Sep 17 00:00:00 2001 From: Adeel Raza Date: Fri, 27 Apr 2018 14:45:08 -0700 Subject: nvlink: add support for kernel tests Add support for NVLINK kernel test modules: - Create an NVLINK tests debugfs directory which will be used as the parent directory for all test related debugfs nodes - Export NVLINK logging APIs - Rename the NVLINK_DRV_NAME macros to NVLINK_MODULE_NAME. This was done because now the NVLINK logging APIs are being used by non-driver modules (i.e. tests) as well. - Export an ARM64 cache flush API - this API is needed by the Tegra loopback test Bug 2133882 Jira NVLINK-107 Change-Id: I587b704ff44327ee4d9767156cb87cbe27408e08 Signed-off-by: Adeel Raza Reviewed-on: https://git-master.nvidia.com/r/1704230 Reviewed-by: svc-mobile-coverity Reviewed-by: Automatic_Commit_Validation_User Reviewed-by: Krishna Reddy Reviewed-by: Petlozu Pravareshwar GVS: Gerrit_Virtual_Submit Reviewed-by: mobile promotions Tested-by: mobile promotions --- drivers/nvlink/nvlink-core.c | 59 +++++++++++++++++++++++++----- drivers/nvlink/t19x-nvlink-endpt-debugfs.c | 6 +-- drivers/nvlink/t19x-nvlink-endpt.c | 8 ++-- drivers/nvlink/t19x-nvlink-endpt.h | 2 +- 4 files changed, 58 insertions(+), 17 deletions(-) (limited to 'drivers/nvlink') diff --git a/drivers/nvlink/nvlink-core.c b/drivers/nvlink/nvlink-core.c index 5ff8c038f..7e0c0faa3 100644 --- a/drivers/nvlink/nvlink-core.c +++ b/drivers/nvlink/nvlink-core.c @@ -25,8 +25,11 @@ #include #include -#define NVLINK_DRV_NAME "nvlink-core" +#include + +#define NVLINK_MODULE_NAME "nvlink-core" #define NVLINK_DEBUGFS_ROOT "nvlink" +#define NVLINK_DEBUGFS_TESTS "tests" #define DEFAULT_LOOP_SLEEP_US 100 #define DEFAULT_LOOP_TIMEOUT_US 1000000 #define NVLINK_TRANSITION_HS_TIMEOUT_MS 2000 @@ -52,11 +55,25 @@ struct nvlink_core { struct mutex mutex; }; +/* + * We're exporting the NVLINK driver stack's logging APIs to the NVLINK kernel + * test modules. The logging APIs use nvlink_log_mask. Therefore, we have to + * export nvlink_log_mask along with the logging APIs. + */ u32 nvlink_log_mask = NVLINK_DEFAULT_LOG_MASK; +EXPORT_SYMBOL(nvlink_log_mask); #ifdef CONFIG_DEBUG_FS /* This is the root debugfs directory for the entire NVLINK driver stack */ -struct dentry *nvlink_debugfs; +struct dentry *nvlink_debugfs_root; + +/* + * This is the parent debugfs directory for NVLINK tests. We need to export this + * symbol so that the NVLINK kernel test modules can create their debugfs nodes + * under the correct path. + */ +struct dentry *nvlink_debugfs_tests; +EXPORT_SYMBOL(nvlink_debugfs_tests); #endif /* CONFIG_DEBUG_FS */ static struct nvlink_core nvlink_core; @@ -244,6 +261,20 @@ success: return ret; } +/* + * This is a wrapper function for an ARM64 cache flush API. This API is used in + * NVLINK kernel test modules. We've created this NVLINK wrapper because we + * don't want to directly export the ARM64 API. We want to minimize the exposure + * of this API outside of the kernel. By creating this NVLINK wrapper we're + * trying to ensure that only NVLINK kernel test modules will use this API + * outside of the kernel. + */ +void __nvlink_dma_flush_area(const void *ptr, size_t size) +{ + __dma_flush_area(ptr, size); +} +EXPORT_SYMBOL(__nvlink_dma_flush_area); + int nvlink_register_device(struct nvlink_device *ndev) { int ret = 0; @@ -1459,13 +1490,21 @@ void nvlink_core_debugfs_init(void) struct dentry *core_debugfs = NULL; struct dentry *debugfs_node = NULL; - nvlink_debugfs = debugfs_create_dir(NVLINK_DEBUGFS_ROOT, NULL); - if (!nvlink_debugfs) { + nvlink_debugfs_root = debugfs_create_dir(NVLINK_DEBUGFS_ROOT, NULL); + if (!nvlink_debugfs_root) { nvlink_err("Failed to create NVLINK debugfs root directory"); goto fail; } - core_debugfs = debugfs_create_dir(NVLINK_DRV_NAME, nvlink_debugfs); + nvlink_debugfs_tests = debugfs_create_dir(NVLINK_DEBUGFS_TESTS, + nvlink_debugfs_root); + if (!nvlink_debugfs_tests) { + nvlink_err("Failed to create NVLINK tests debugfs directory"); + goto fail; + } + + core_debugfs = debugfs_create_dir(NVLINK_MODULE_NAME, + nvlink_debugfs_root); if (!core_debugfs) { nvlink_err("Failed to create NVLINK core driver's debugfs directory"); goto fail; @@ -1484,14 +1523,16 @@ void nvlink_core_debugfs_init(void) fail: nvlink_err("Failed to create debugfs nodes"); - debugfs_remove_recursive(nvlink_debugfs); - nvlink_debugfs = NULL; + debugfs_remove_recursive(nvlink_debugfs_root); + nvlink_debugfs_root = NULL; + nvlink_debugfs_tests = NULL; } void nvlink_core_debugfs_deinit(void) { - debugfs_remove_recursive(nvlink_debugfs); - nvlink_debugfs = NULL; + debugfs_remove_recursive(nvlink_debugfs_root); + nvlink_debugfs_root = NULL; + nvlink_debugfs_tests = NULL; } #endif /* CONFIG_DEBUG_FS */ diff --git a/drivers/nvlink/t19x-nvlink-endpt-debugfs.c b/drivers/nvlink/t19x-nvlink-endpt-debugfs.c index 5eddc3f6b..d1bd3bb93 100644 --- a/drivers/nvlink/t19x-nvlink-endpt-debugfs.c +++ b/drivers/nvlink/t19x-nvlink-endpt-debugfs.c @@ -293,13 +293,13 @@ fail: void t19x_nvlink_endpt_debugfs_init(struct tnvlink_dev *tdev) { - if (!nvlink_debugfs) { + if (!nvlink_debugfs_root) { nvlink_err("Root NVLINK debugfs directory doesn't exist"); goto fail; } - tdev->tegra_debugfs = debugfs_create_dir(NVLINK_DRV_NAME, - nvlink_debugfs); + tdev->tegra_debugfs = debugfs_create_dir(NVLINK_MODULE_NAME, + nvlink_debugfs_root); if (!tdev->tegra_debugfs) { nvlink_err("Failed to create Tegra NVLINK endpoint driver's" " debugfs directory"); diff --git a/drivers/nvlink/t19x-nvlink-endpt.c b/drivers/nvlink/t19x-nvlink-endpt.c index 23b6dca97..617aba9da 100644 --- a/drivers/nvlink/t19x-nvlink-endpt.c +++ b/drivers/nvlink/t19x-nvlink-endpt.c @@ -1090,7 +1090,7 @@ static int t19x_nvlink_endpt_probe(struct platform_device *pdev) tdev->dev = &pdev->dev; tdev->class.owner = THIS_MODULE; - tdev->class.name = NVLINK_DRV_NAME; + tdev->class.name = NVLINK_MODULE_NAME; /* Create device node */ ret = class_register(&tdev->class); @@ -1118,7 +1118,7 @@ static int t19x_nvlink_endpt_probe(struct platform_device *pdev) NULL, tdev->dev_t, NULL, - NVLINK_DRV_NAME); + NVLINK_MODULE_NAME); if (IS_ERR(dev)) { nvlink_err("Failed to create device"); ret = PTR_ERR(dev); @@ -1368,7 +1368,7 @@ static struct platform_driver t19x_nvlink_endpt_pdrv = { .probe = t19x_nvlink_endpt_probe, .remove = t19x_nvlink_endpt_remove, .driver = { - .name = NVLINK_DRV_NAME, + .name = NVLINK_MODULE_NAME, #if IS_ENABLED(CONFIG_PM_SLEEP) .pm = &tegra_nvlink_pm_ops, #endif @@ -1397,6 +1397,6 @@ static void __exit t19x_nvlink_endpt_exit(void) module_init(t19x_nvlink_endpt_init); module_exit(t19x_nvlink_endpt_exit); -MODULE_ALIAS(NVLINK_DRV_NAME); +MODULE_ALIAS(NVLINK_MODULE_NAME); MODULE_DESCRIPTION("T19x NVLINK Endpoint Driver"); MODULE_LICENSE("GPL v2"); diff --git a/drivers/nvlink/t19x-nvlink-endpt.h b/drivers/nvlink/t19x-nvlink-endpt.h index 0243247c8..0add7e976 100644 --- a/drivers/nvlink/t19x-nvlink-endpt.h +++ b/drivers/nvlink/t19x-nvlink-endpt.h @@ -37,7 +37,7 @@ #include #include -#define NVLINK_DRV_NAME "t19x-nvlink-endpt" +#define NVLINK_MODULE_NAME "t19x-nvlink-endpt" #define NVLINK_IP_VERSION 2 /* NVLINK VERSION 2.0 */ #define DEFAULT_IS_NEA 0 -- cgit v1.2.2