diff --git a/Kbuild b/Kbuild index b415a7865275..99aeba7e428f 100644 --- a/Kbuild +++ b/Kbuild @@ -300,6 +300,9 @@ endif ifeq ($(CONFIG_WLAN_TXRX_FW_STATS), y) HDD_OBJS += $(HDD_SRC_DIR)/wlan_hdd_sysfs_txrx_fw_stats.o endif +ifeq ($(CONFIG_WLAN_TXRX_STATS), y) +HDD_OBJS += $(HDD_SRC_DIR)/wlan_hdd_sysfs_txrx_stats.o +endif endif ifeq ($(CONFIG_QCACLD_FEATURE_FW_STATE), y) @@ -2535,6 +2538,7 @@ cppflags-$(CONFIG_WLAN_SET_SCAN_CFG) += -DCONFIG_WLAN_SET_SCAN_CFG cppflags-$(CONFIG_WLAN_SET_MON_CHAN) += -DCONFIG_WLAN_SET_MON_CHAN cppflags-$(CONFIG_WLAN_SET_RADAR) += -DCONFIG_WLAN_SET_RADAR cppflags-$(CONFIG_WLAN_TXRX_FW_STATS) += -DCONFIG_WLAN_TXRX_FW_STATS +cppflags-$(CONFIG_WLAN_TXRX_STATS) += -DCONFIG_WLAN_TXRX_STATS cppflags-$(CONFIG_FEATURE_UNIT_TEST_SUSPEND) += -DWLAN_SUSPEND_RESUME_TEST cppflags-$(CONFIG_FEATURE_WLM_STATS) += -DFEATURE_WLM_STATS diff --git a/configs/default_defconfig b/configs/default_defconfig index 4cffafb920d9..8d93a1b22e46 100644 --- a/configs/default_defconfig +++ b/configs/default_defconfig @@ -186,6 +186,7 @@ ifeq ($(CONFIG_WLAN_SYSFS), y) CONFIG_WLAN_SET_MON_CHAN := y CONFIG_WLAN_SET_RADAR := y CONFIG_WLAN_TXRX_FW_STATS := y + CONFIG_WLAN_TXRX_STATS := y endif CONFIG_WLAN_POWER_DEBUG := y diff --git a/core/hdd/src/wlan_hdd_sysfs.c b/core/hdd/src/wlan_hdd_sysfs.c index 8670893e4f8e..98588bcc18b1 100644 --- a/core/hdd/src/wlan_hdd_sysfs.c +++ b/core/hdd/src/wlan_hdd_sysfs.c @@ -52,6 +52,7 @@ #include #include #include +#include #define MAX_PSOC_ID_SIZE 10 @@ -632,11 +633,13 @@ hdd_sysfs_create_sta_adapter_root_obj(struct hdd_adapter *adapter) hdd_sysfs_connect_info_interface_create(adapter); hdd_sysfs_wowl_add_ptrn_create(adapter); hdd_sysfs_txrx_fw_stats_create(adapter); + hdd_sysfs_txrx_stats_create(adapter); } static void hdd_sysfs_destroy_sta_adapter_root_obj(struct hdd_adapter *adapter) { + hdd_sysfs_txrx_stats_destroy(adapter); hdd_sysfs_txrx_fw_stats_destroy(adapter); hdd_sysfs_wowl_add_ptrn_destroy(adapter); hdd_sysfs_connect_info_interface_destroy(adapter); @@ -661,11 +664,13 @@ hdd_sysfs_create_sap_adapter_root_obj(struct hdd_adapter *adapter) hdd_sysfs_connect_info_interface_create(adapter); hdd_sysfs_set_radar_create(adapter); hdd_sysfs_txrx_fw_stats_create(adapter); + hdd_sysfs_txrx_stats_create(adapter); } static void hdd_sysfs_destroy_sap_adapter_root_obj(struct hdd_adapter *adapter) { + hdd_sysfs_txrx_stats_destroy(adapter); hdd_sysfs_txrx_fw_stats_destroy(adapter); hdd_sysfs_set_radar_destroy(adapter); hdd_sysfs_connect_info_interface_destroy(adapter); diff --git a/core/hdd/src/wlan_hdd_sysfs_txrx_stats.c b/core/hdd/src/wlan_hdd_sysfs_txrx_stats.c new file mode 100644 index 000000000000..1f8d39dbc9d6 --- /dev/null +++ b/core/hdd/src/wlan_hdd_sysfs_txrx_stats.c @@ -0,0 +1,153 @@ +/* + * Copyright (c) 2011-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_txrx_stats.c + * + * implementation for creating sysfs file txrx_stats + */ + +#include +#include +#include "osif_vdev_sync.h" +#include +#include +#include "cds_api.h" +#include "cdp_txrx_cmn_struct.h" +#include "cdp_txrx_cmn.h" + +static ssize_t +__hdd_sysfs_txrx_stats_store(struct net_device *net_dev, + char const *buf, size_t count) +{ + struct hdd_adapter *adapter = netdev_priv(net_dev); + char buf_local[MAX_SYSFS_USER_COMMAND_SIZE_LENGTH + 1]; + void *soc = cds_get_context(QDF_MODULE_ID_SOC); + struct cdp_txrx_stats_req req = {0}; + struct hdd_station_ctx *sta_ctx; + struct hdd_context *hdd_ctx; + char *sptr, *token; + uint32_t val1; + uint8_t val2; + 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; + + sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter); + 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; + } + + sptr = buf_local; + hdd_debug("txrx_stats: count %zu buf_local:(%s) net_devname %s", + count, buf_local, net_dev->name); + + /* Get val1 */ + token = strsep(&sptr, " "); + if (!token) + return -EINVAL; + if (kstrtou32(token, 0, &val1)) + return -EINVAL; + + /* Get val2 */ + token = strsep(&sptr, " "); + if (!token) + return -EINVAL; + if (kstrtou8(token, 0, &val2)) + return -EINVAL; + + req.stats = val1; + /* default value of secondary parameter is 0(mac_id) */ + req.mac_id = val2; + + hdd_debug("WE_SET_TXRX_STATS stats cmd: %d mac_id: %d", + req.stats, req.mac_id); + if (qdf_unlikely(!soc)) { + hdd_err("soc is NULL"); + return -EINVAL; + } + + if (val1 == CDP_TXRX_STATS_28) { + if (sta_ctx->conn_info.is_authenticated) { + hdd_debug("ap mac addr: %pM", + (void *)&sta_ctx->conn_info.bssid); + req.peer_addr = + (char *)&sta_ctx->conn_info.bssid; + } + } + ret = cdp_txrx_stats_request(soc, adapter->vdev_id, &req); + + if (ret) { + hdd_err_rl("failed to set txrx stats: %d", ret); + return ret; + } + + return count; +} + +static ssize_t +hdd_sysfs_txrx_stats_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_txrx_stats_store(net_dev, buf, count); + + osif_vdev_sync_op_stop(vdev_sync); + + return errno_size; +} + +static DEVICE_ATTR(txrx_stats, 0220, + NULL, hdd_sysfs_txrx_stats_store); + +int hdd_sysfs_txrx_stats_create(struct hdd_adapter *adapter) +{ + int error; + + error = device_create_file(&adapter->dev->dev, &dev_attr_txrx_stats); + if (error) + hdd_err("could not create txrx_stats sysfs file"); + + return error; +} + +void hdd_sysfs_txrx_stats_destroy(struct hdd_adapter *adapter) +{ + device_remove_file(&adapter->dev->dev, &dev_attr_txrx_stats); +} diff --git a/core/hdd/src/wlan_hdd_sysfs_txrx_stats.h b/core/hdd/src/wlan_hdd_sysfs_txrx_stats.h new file mode 100644 index 000000000000..827ac3ec3979 --- /dev/null +++ b/core/hdd/src/wlan_hdd_sysfs_txrx_stats.h @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2011-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_txrx_stats.h + * + * implementation for creating sysfs file txrx_stats + */ + +#ifndef _WLAN_HDD_SYSFS_TXRX_STATS_H +#define _WLAN_HDD_SYSFS_TXRX_STATS_H + +#if defined(WLAN_SYSFS) && defined(CONFIG_WLAN_TXRX_STATS) +/** + * wlan_hdd_sysfs_txrx_stats_create() - API to create txrx_stats + * @adapter: hdd adapter + * + * this file is created per adapter. + * file path: /sys/class/net/wlanxx/txrx_stats + * (wlanxx is adapter name) + * usage: + * echo [arg_0] [arg_1] > txrx_stats + * + * Return: 0 on success and errno on failure + */ +int hdd_sysfs_txrx_stats_create(struct hdd_adapter *adapter); + +/** + * hdd_sysfs_txrx_stats_destroy() - + * API to destroy txrx_stats + * @adapter: pointer to adapter + * + * Return: none + */ +void hdd_sysfs_txrx_stats_destroy(struct hdd_adapter *adapter); +#else +static inline int +hdd_sysfs_txrx_stats_create(struct hdd_adapter *adapter) +{ + return 0; +} + +static inline void +hdd_sysfs_txrx_stats_destroy(struct hdd_adapter *adapter) +{ +} +#endif +#endif /* #ifndef _WLAN_HDD_SYSFS_TXRX_STATS_H */