diff --git a/Kbuild b/Kbuild index 4168cce5b890..260e94f87e25 100644 --- a/Kbuild +++ b/Kbuild @@ -269,6 +269,9 @@ endif ifeq ($(CONFIG_WLAN_DEBUG_CRASH_INJECT), y) HDD_OBJS += $(HDD_SRC_DIR)/wlan_hdd_sysfs_crash_inject.o endif +ifeq ($(CONFIG_FEATURE_UNIT_TEST_SUSPEND), y) +HDD_OBJS += $(HDD_SRC_DIR)/wlan_hdd_sysfs_suspend_resume.o +endif endif ifeq ($(CONFIG_QCACLD_FEATURE_FW_STATE), y) diff --git a/core/hdd/inc/wlan_hdd_debugfs_unit_test.h b/core/hdd/inc/wlan_hdd_debugfs_unit_test.h index d2fac29d5bdf..0bb173b1e825 100644 --- a/core/hdd/inc/wlan_hdd_debugfs_unit_test.h +++ b/core/hdd/inc/wlan_hdd_debugfs_unit_test.h @@ -20,7 +20,7 @@ * DOC: wlan_hdd_debugfs_unit_test.h * * WLAN Host Device Driver implementation to create debugfs - * unit_test_host/unit_test_target/wlan_suspend/wlan_resume + * unit_test_host/unit_test_target */ #ifndef _WLAN_HDD_DEBUGFS_UNIT_TEST_H @@ -49,51 +49,6 @@ wlan_hdd_debugfs_unit_test_host_create(struct hdd_context *hdd_ctx) } #endif -#if defined(WLAN_DEBUGFS) && defined(WLAN_SUSPEND_RESUME_TEST) -/** - * wlan_hdd_debugfs_suspend_create() - API to create wlan_suspend - * @adapter: hdd adapter - * - * this file is created per adapter. - * file path: /sys/kernel/debug/wlan_xx/wlan_suspend - * (wlan_xx is adapter name) - * usage: - * echo [arg_0] [arg_1] > wlan_suspend - * arg_0 from enum wow_interface_pause - * arg_1 from enum wow_resume_trigger - * - * Return: 0 on success and errno on failure - */ -int wlan_hdd_debugfs_suspend_create(struct hdd_adapter *adapter); - -/** - * wlan_hdd_debugfs_resume_create() - API to create wlan_resume - * @adapter: hdd adapter - * - * this file is created per adapter. - * file path: /sys/kernel/debug/wlan_xx/wlan_resume - * (wlan_xx is adapter name) - * usage: - * echo > wlan_resume - * - * - * Return: 0 on success and errno on failure - */ -int wlan_hdd_debugfs_resume_create(struct hdd_adapter *adapter); -#else -static inline int -wlan_hdd_debugfs_suspend_create(struct hdd_adapter *adapter) -{ - return 0; -} - -static inline int -wlan_hdd_debugfs_resume_create(struct hdd_adapter *adapter) -{ - return 0; -} -#endif - #ifdef WLAN_DEBUGFS /** * hdd_debugfs_unit_test_target_create() - API to create unit_test_target file diff --git a/core/hdd/src/wlan_hdd_debugfs.c b/core/hdd/src/wlan_hdd_debugfs.c index 94adf03bb085..f7e4482f6e8a 100644 --- a/core/hdd/src/wlan_hdd_debugfs.c +++ b/core/hdd/src/wlan_hdd_debugfs.c @@ -559,12 +559,6 @@ QDF_STATUS hdd_debugfs_init(struct hdd_adapter *adapter) if (wlan_hdd_debugfs_unit_test_target_create(adapter)) return QDF_STATUS_E_FAILURE; - if (wlan_hdd_debugfs_suspend_create(adapter)) - return QDF_STATUS_E_FAILURE; - - if (wlan_hdd_debugfs_resume_create(adapter)) - return QDF_STATUS_E_FAILURE; - return QDF_STATUS_SUCCESS; } diff --git a/core/hdd/src/wlan_hdd_debugfs_unit_test.c b/core/hdd/src/wlan_hdd_debugfs_unit_test.c index b770fd7d62e5..681eb5c620e8 100644 --- a/core/hdd/src/wlan_hdd_debugfs_unit_test.c +++ b/core/hdd/src/wlan_hdd_debugfs_unit_test.c @@ -30,7 +30,6 @@ #include "wlan_hdd_debugfs_unit_test.h" #include "wlan_module_ids.h" #include "wma.h" -#include "wlan_hdd_power.h" /* strlen("5 1 1") + 1(\n) */ #define MIN_USER_COMMAND_SIZE_UNIT_TEST_TARGET 6 @@ -142,240 +141,6 @@ int wlan_hdd_debugfs_unit_test_host_create(struct hdd_context *hdd_ctx) } #endif /* WLAN_UNIT_TEST */ -#ifdef WLAN_SUSPEND_RESUME_TEST -#define MIN_USER_COMMAND_SIZE_SUSPEND 4 -#define MAX_USER_COMMAND_SIZE_SUSPEND 32 - -/** - * __wlan_hdd_write_suspend_debugfs() - * - suspend test debugfs handler - * - * @net_dev: net_device context used to register the debugfs file - * @buf: text being written to the debugfs - * @count: size of @buf - * @ppos: (unused) offset into the virtual file system - * - * Return: number of bytes processed - */ -static ssize_t __wlan_hdd_write_suspend_debugfs( - struct net_device *net_dev, - const char __user *buf, size_t count, - loff_t *ppos) -{ - struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(net_dev); - struct hdd_context *hdd_ctx; - char buf_local[MAX_USER_COMMAND_SIZE_SUSPEND + 1]; - char *sptr, *token; - int ret, pause_setting, resume_setting; - - if (hdd_validate_adapter(adapter)) { - hdd_err_rl("adapter validate fail"); - return -EINVAL; - } - - hdd_ctx = WLAN_HDD_GET_CTX(adapter); - ret = wlan_hdd_validate_context(hdd_ctx); - if (ret != 0) - return ret; - - if (!wlan_hdd_validate_modules_state(hdd_ctx)) - return -EINVAL; - - if (count < MIN_USER_COMMAND_SIZE_SUSPEND || - count > MAX_USER_COMMAND_SIZE_SUSPEND) { - hdd_err_rl("Command length (%zu) is invalid, expected [%d, %d]", - count, - MIN_USER_COMMAND_SIZE_SUSPEND, - MAX_USER_COMMAND_SIZE_SUSPEND); - return -EINVAL; - } - - /* Get command from user */ - if (copy_from_user(buf_local, buf, count)) - return -EFAULT; - - /* default 'echo' cmd takes new line character to here*/ - if (buf_local[count - 1] == '\n') - buf_local[count - 1] = '\0'; - else - buf_local[count] = '\0'; - sptr = buf_local; - hdd_nofl_info("unit_test: count %zu buf_local:(%s) net_devname %s", - count, buf_local, net_dev->name); - - /* Get pause_setting */ - token = strsep(&sptr, " "); - if (!token) - return -EINVAL; - if (kstrtou32(token, 0, &pause_setting)) - return -EINVAL; - - /* Get resume_setting */ - token = strsep(&sptr, " "); - if (!token) - return -EINVAL; - if (kstrtou32(token, 0, &resume_setting)) - return -EINVAL; - - hdd_nofl_info("unit_test: pause_setting %d, resume_setting %d", - pause_setting, resume_setting); - ret = hdd_wlan_fake_apps_suspend(hdd_ctx->wiphy, net_dev, - pause_setting, resume_setting); - if (ret != 0) { - hdd_err_rl("suspend test failed"); - return -EINVAL; - } - - return count; -} - -/** - * wlan_hdd_write_suspend_debugfs() - * - wrapper for __wlan_hdd_write_suspend_debugfs - * - * @file: file pointer - * @buf: buffer - * @count: count - * @ppos: position pointer - * - * Return: number of bytes processed or errno - */ -static ssize_t wlan_hdd_write_suspend_debugfs( - struct file *file, - const char __user *buf, - size_t count, loff_t *ppos) -{ - struct net_device *net_dev = file_inode(file)->i_private; - struct osif_vdev_sync *vdev_sync; - ssize_t errno_size; - - errno_size = osif_vdev_sync_op_start(net_dev, &vdev_sync); - if (errno_size) - return errno_size; - - errno_size = __wlan_hdd_write_suspend_debugfs( - net_dev, buf, count, ppos); - if (errno_size < 0) - hdd_err_rl("errno_size %zd", errno_size); - - osif_vdev_sync_op_stop(vdev_sync); - - return errno_size; -} - -static const struct file_operations fops_suspend_debugfs = { - .write = wlan_hdd_write_suspend_debugfs, - .owner = THIS_MODULE, - .llseek = default_llseek, -}; - -int wlan_hdd_debugfs_suspend_create(struct hdd_adapter *adapter) -{ - struct net_device *net_dev = adapter->dev; - - if (!debugfs_create_file("wlan_suspend", 00400 | 00200, - adapter->debugfs_phy, - net_dev, &fops_suspend_debugfs)) - return -EINVAL; - - return 0; -} - -/** - * __wlan_hdd_write_resume_debugfs() - * - resume test debugfs handler - * - * @net_dev: net_device context used to register the debugfs file - * @buf: text being written to the debugfs - * @count: size of @buf - * @ppos: (unused) offset into the virtual file system - * - * Return: number of bytes processed - */ -static ssize_t __wlan_hdd_write_resume_debugfs( - struct net_device *net_dev, - const char __user *buf, size_t count, - loff_t *ppos) -{ - struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(net_dev); - struct hdd_context *hdd_ctx; - int ret; - - if (hdd_validate_adapter(adapter)) { - hdd_err_rl("adapter validate fail"); - return -EINVAL; - } - - hdd_ctx = WLAN_HDD_GET_CTX(adapter); - ret = wlan_hdd_validate_context(hdd_ctx); - if (ret != 0) - return ret; - - if (!wlan_hdd_validate_modules_state(hdd_ctx)) - return -EINVAL; - - ret = hdd_wlan_fake_apps_resume(hdd_ctx->wiphy, net_dev); - if (ret != 0) { - hdd_err_rl("resume test failed"); - return -EINVAL; - } - - return count; -} - -/** - * wlan_hdd_write_resume_debugfs() - * - wrapper for __wlan_hdd_write_resume_debugfs - * - * @file: file pointer - * @buf: buffer - * @count: count - * @ppos: position pointer - * - * Return: number of bytes processed or errno - */ -static ssize_t wlan_hdd_write_resume_debugfs( - struct file *file, - const char __user *buf, - size_t count, loff_t *ppos) -{ - struct net_device *net_dev = file_inode(file)->i_private; - struct osif_vdev_sync *vdev_sync; - ssize_t errno_size; - - errno_size = osif_vdev_sync_op_start(net_dev, &vdev_sync); - if (errno_size) - return errno_size; - - errno_size = __wlan_hdd_write_resume_debugfs( - net_dev, buf, count, ppos); - if (errno_size < 0) - hdd_err_rl("errno_size %zd", errno_size); - - osif_vdev_sync_op_stop(vdev_sync); - - return errno_size; -} - -static const struct file_operations fops_resume_debugfs = { - .write = wlan_hdd_write_resume_debugfs, - .owner = THIS_MODULE, - .llseek = default_llseek, -}; - -int wlan_hdd_debugfs_resume_create(struct hdd_adapter *adapter) -{ - struct net_device *net_dev = adapter->dev; - - if (!debugfs_create_file("wlan_resume", 00400 | 00200, - adapter->debugfs_phy, - net_dev, &fops_resume_debugfs)) - return -EINVAL; - - return 0; -} -#endif - /** * __wlan_hdd_write_unit_test_target_debugfs() * - target unit test debugfs handler diff --git a/core/hdd/src/wlan_hdd_sysfs.c b/core/hdd/src/wlan_hdd_sysfs.c index 762a3e512754..5bd403c31a9c 100644 --- a/core/hdd/src/wlan_hdd_sysfs.c +++ b/core/hdd/src/wlan_hdd_sysfs.c @@ -40,7 +40,7 @@ #include #include #include "wlan_hdd_sysfs_crash_inject.h" - +#include "wlan_hdd_sysfs_suspend_resume.h" #define MAX_PSOC_ID_SIZE 10 @@ -614,11 +614,15 @@ hdd_sysfs_create_sta_adapter_root_obj(struct hdd_adapter *adapter) hdd_sysfs_create_bcn_reception_interface(adapter); hdd_sysfs_reassoc_create(adapter); hdd_sysfs_crash_inject_create(adapter); + hdd_sysfs_suspend_create(adapter); + hdd_sysfs_resume_create(adapter); } static void hdd_sysfs_destroy_sta_adapter_root_obj(struct hdd_adapter *adapter) { + hdd_sysfs_resume_destroy(adapter); + hdd_sysfs_suspend_destroy(adapter); hdd_sysfs_crash_inject_destroy(adapter); hdd_sysfs_reassoc_destroy(adapter); hdd_sysfs_destroy_bcn_reception_interface(adapter); @@ -628,11 +632,15 @@ static void hdd_sysfs_create_sap_adapter_root_obj(struct hdd_adapter *adapter) { hdd_sysfs_crash_inject_create(adapter); + hdd_sysfs_suspend_create(adapter); + hdd_sysfs_resume_create(adapter); } static void hdd_sysfs_destroy_sap_adapter_root_obj(struct hdd_adapter *adapter) { + hdd_sysfs_resume_destroy(adapter); + hdd_sysfs_suspend_destroy(adapter); hdd_sysfs_crash_inject_destroy(adapter); } diff --git a/core/hdd/src/wlan_hdd_sysfs_suspend_resume.c b/core/hdd/src/wlan_hdd_sysfs_suspend_resume.c new file mode 100644 index 000000000000..24097ce2444f --- /dev/null +++ b/core/hdd/src/wlan_hdd_sysfs_suspend_resume.c @@ -0,0 +1,199 @@ +/* + * Copyright (c) 2020, The Linux Foundation. All rights reserved. + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +/** + * DOC: wlan_hdd_sysfs_suspend_resume.c + * + * implementation for creating sysfs file wlan_suspend/wlan_resume + */ + +#include +#include "osif_vdev_sync.h" +#include "wlan_hdd_power.h" +#include "wlan_hdd_sysfs.h" +#include "wlan_hdd_sysfs_suspend_resume.h" + +static ssize_t __hdd_sysfs_suspend_store( + struct net_device *net_dev, + const char *buf, size_t count) +{ + struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(net_dev); + struct hdd_context *hdd_ctx; + char buf_local[MAX_SYSFS_USER_COMMAND_SIZE_LENGTH + 1]; + char *sptr, *token; + int ret, pause_setting, resume_setting; + + if (hdd_validate_adapter(adapter)) { + hdd_err_rl("adapter validate fail"); + return -EINVAL; + } + + hdd_ctx = WLAN_HDD_GET_CTX(adapter); + ret = wlan_hdd_validate_context(hdd_ctx); + if (ret != 0) + return ret; + + if (!wlan_hdd_validate_modules_state(hdd_ctx)) + return -EINVAL; + + ret = hdd_sysfs_validate_and_copy_buf(buf_local, sizeof(buf_local), + buf, count); + if (ret) { + hdd_err_rl("invalid input"); + return ret; + } + + hdd_nofl_info("wlan_suspend: count %zu buf_local:(%s) net_devname %s", + count, buf_local, net_dev->name); + + sptr = buf_local; + /* Get pause_setting */ + token = strsep(&sptr, " "); + if (!token) + return -EINVAL; + if (kstrtou32(token, 0, &pause_setting)) + return -EINVAL; + + /* Get resume_setting */ + token = strsep(&sptr, " "); + if (!token) + return -EINVAL; + if (kstrtou32(token, 0, &resume_setting)) + return -EINVAL; + + hdd_nofl_info("wlan_suspend: pause_setting %d, resume_setting %d", + pause_setting, resume_setting); + ret = hdd_wlan_fake_apps_suspend(hdd_ctx->wiphy, net_dev, + pause_setting, resume_setting); + if (ret != 0) { + hdd_err_rl("suspend test failed"); + return -EINVAL; + } + + return count; +} + +static ssize_t hdd_sysfs_suspend_store(struct device *dev, + struct device_attribute *attr, + char const *buf, size_t count) +{ + struct net_device *net_dev = container_of(dev, struct net_device, dev); + struct osif_vdev_sync *vdev_sync; + ssize_t errno_size; + + errno_size = osif_vdev_sync_op_start(net_dev, &vdev_sync); + if (errno_size) + return errno_size; + + errno_size = __hdd_sysfs_suspend_store( + net_dev, buf, count); + if (errno_size < 0) + hdd_err_rl("errno_size %zd", errno_size); + + osif_vdev_sync_op_stop(vdev_sync); + + return errno_size; +} + +static DEVICE_ATTR(wlan_suspend, 0220, + NULL, hdd_sysfs_suspend_store); + +int hdd_sysfs_suspend_create(struct hdd_adapter *adapter) +{ + int error; + + error = device_create_file(&adapter->dev->dev, &dev_attr_wlan_suspend); + if (error) + hdd_err("could not create wlan_suspend sysfs file"); + + return error; +} + +void hdd_sysfs_suspend_destroy(struct hdd_adapter *adapter) +{ + device_remove_file(&adapter->dev->dev, &dev_attr_wlan_suspend); +} + +static ssize_t __hdd_sysfs_resume_store( + struct net_device *net_dev, + const char *buf, size_t count) +{ + struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(net_dev); + struct hdd_context *hdd_ctx; + int ret; + + if (hdd_validate_adapter(adapter)) { + hdd_err_rl("adapter validate fail"); + return -EINVAL; + } + + hdd_ctx = WLAN_HDD_GET_CTX(adapter); + ret = wlan_hdd_validate_context(hdd_ctx); + if (ret != 0) + return ret; + + if (!wlan_hdd_validate_modules_state(hdd_ctx)) + return -EINVAL; + + ret = hdd_wlan_fake_apps_resume(hdd_ctx->wiphy, net_dev); + if (ret != 0) { + hdd_err_rl("resume test failed"); + return -EINVAL; + } + + return count; +} + +static ssize_t hdd_sysfs_resume_store(struct device *dev, + struct device_attribute *attr, + char const *buf, size_t count) +{ + struct net_device *net_dev = container_of(dev, struct net_device, dev); + struct osif_vdev_sync *vdev_sync; + ssize_t errno_size; + + errno_size = osif_vdev_sync_op_start(net_dev, &vdev_sync); + if (errno_size) + return errno_size; + + errno_size = __hdd_sysfs_resume_store( + net_dev, buf, count); + if (errno_size < 0) + hdd_err_rl("errno_size %zd", errno_size); + + osif_vdev_sync_op_stop(vdev_sync); + + return errno_size; +} + +static DEVICE_ATTR(wlan_resume, 0220, + NULL, hdd_sysfs_resume_store); + +int hdd_sysfs_resume_create(struct hdd_adapter *adapter) +{ + int error; + + error = device_create_file(&adapter->dev->dev, &dev_attr_wlan_resume); + if (error) + hdd_err("could not create wlan_resume sysfs file"); + + return error; +} + +void hdd_sysfs_resume_destroy(struct hdd_adapter *adapter) +{ + device_remove_file(&adapter->dev->dev, &dev_attr_wlan_resume); +} diff --git a/core/hdd/src/wlan_hdd_sysfs_suspend_resume.h b/core/hdd/src/wlan_hdd_sysfs_suspend_resume.h new file mode 100644 index 000000000000..09db3fe5979a --- /dev/null +++ b/core/hdd/src/wlan_hdd_sysfs_suspend_resume.h @@ -0,0 +1,98 @@ +/* + * Copyright (c) 2020, The Linux Foundation. All rights reserved. + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +/** + * DOC: wlan_hdd_sysfs_suspend_resume.h + * + * implementation for creating sysfs file crash_inject + */ + +#ifndef _WLAN_HDD_SYSFS_SUSPEND_RESUME_H +#define _WLAN_HDD_SYSFS_SUSPEND_RESUME_H + +#if defined(WLAN_SYSFS) && defined(WLAN_SUSPEND_RESUME_TEST) +/** + * hdd_sysfs_suspend_create() - API to create wlan_suspend + * @adapter: hdd adapter + * + * this file is created per adapter. + * file path: /sys/class/net/wlan_xx/wlan_suspend + * (wlan_xx is adapter name) + * usage: + * echo [arg_0] [arg_1] > wlan_suspend + * arg_0 from enum wow_interface_pause + * arg_1 from enum wow_resume_trigger + * + * Return: 0 on success and errno on failure + */ +int hdd_sysfs_suspend_create(struct hdd_adapter *adapter); + +/** + * hdd_sysfs_suspend_destroy() - + * API to destroy wlan_suspend sys file + * @adapter: pointer to adapter + * + * Return: none + */ +void hdd_sysfs_suspend_destroy(struct hdd_adapter *adapter); + +/** + * hdd_sysfs_resume_create() - API to create wlan_resume + * @adapter: hdd adapter + * + * this file is created per adapter. + * file path: /sys/class/net/wlan_xx/wlan_resume + * (wlan_xx is adapter name) + * usage: + * echo > wlan_resume + * + * + * Return: 0 on success and errno on failure + */ +int hdd_sysfs_resume_create(struct hdd_adapter *adapter); + +/** + * hdd_sysfs_resume_destroy() - + * API to destroy wlan_resume sys file + * @adapter: pointer to adapter + * + * Return: none + */ +void hdd_sysfs_resume_destroy(struct hdd_adapter *adapter); +#else +static inline int +hdd_sysfs_suspend_create(struct hdd_adapter *adapter) +{ + return 0; +} + +static inline void +hdd_sysfs_suspend_destroy(struct hdd_adapter *adapter) +{ +} + +static inline int +hdd_sysfs_resume_create(struct hdd_adapter *adapter) +{ + return 0; +} + +static inline void +hdd_sysfs_resume_destroy(struct hdd_adapter *adapter) +{ +} +#endif +#endif /* #ifndef _WLAN_HDD_SYSFS_SUSPEND_RESUME_H */