18c2ecf20Sopenharmony_ci/* 28c2ecf20Sopenharmony_ci * Copyright (c) 2013 Eugene Krasnikov <k.eugene.e@gmail.com> 38c2ecf20Sopenharmony_ci * 48c2ecf20Sopenharmony_ci * Permission to use, copy, modify, and/or distribute this software for any 58c2ecf20Sopenharmony_ci * purpose with or without fee is hereby granted, provided that the above 68c2ecf20Sopenharmony_ci * copyright notice and this permission notice appear in all copies. 78c2ecf20Sopenharmony_ci * 88c2ecf20Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 98c2ecf20Sopenharmony_ci * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 108c2ecf20Sopenharmony_ci * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 118c2ecf20Sopenharmony_ci * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 128c2ecf20Sopenharmony_ci * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION 138c2ecf20Sopenharmony_ci * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 148c2ecf20Sopenharmony_ci * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 158c2ecf20Sopenharmony_ci */ 168c2ecf20Sopenharmony_ci 178c2ecf20Sopenharmony_ci#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 188c2ecf20Sopenharmony_ci 198c2ecf20Sopenharmony_ci#include <linux/debugfs.h> 208c2ecf20Sopenharmony_ci#include <linux/uaccess.h> 218c2ecf20Sopenharmony_ci#include "wcn36xx.h" 228c2ecf20Sopenharmony_ci#include "debug.h" 238c2ecf20Sopenharmony_ci#include "pmc.h" 248c2ecf20Sopenharmony_ci 258c2ecf20Sopenharmony_ci#ifdef CONFIG_WCN36XX_DEBUGFS 268c2ecf20Sopenharmony_ci 278c2ecf20Sopenharmony_cistatic ssize_t read_file_bool_bmps(struct file *file, char __user *user_buf, 288c2ecf20Sopenharmony_ci size_t count, loff_t *ppos) 298c2ecf20Sopenharmony_ci{ 308c2ecf20Sopenharmony_ci struct wcn36xx *wcn = file->private_data; 318c2ecf20Sopenharmony_ci struct wcn36xx_vif *vif_priv = NULL; 328c2ecf20Sopenharmony_ci struct ieee80211_vif *vif = NULL; 338c2ecf20Sopenharmony_ci char buf[3]; 348c2ecf20Sopenharmony_ci 358c2ecf20Sopenharmony_ci list_for_each_entry(vif_priv, &wcn->vif_list, list) { 368c2ecf20Sopenharmony_ci vif = wcn36xx_priv_to_vif(vif_priv); 378c2ecf20Sopenharmony_ci if (NL80211_IFTYPE_STATION == vif->type) { 388c2ecf20Sopenharmony_ci if (vif_priv->pw_state == WCN36XX_BMPS) 398c2ecf20Sopenharmony_ci buf[0] = '1'; 408c2ecf20Sopenharmony_ci else 418c2ecf20Sopenharmony_ci buf[0] = '0'; 428c2ecf20Sopenharmony_ci break; 438c2ecf20Sopenharmony_ci } 448c2ecf20Sopenharmony_ci } 458c2ecf20Sopenharmony_ci buf[1] = '\n'; 468c2ecf20Sopenharmony_ci buf[2] = 0x00; 478c2ecf20Sopenharmony_ci 488c2ecf20Sopenharmony_ci return simple_read_from_buffer(user_buf, count, ppos, buf, 2); 498c2ecf20Sopenharmony_ci} 508c2ecf20Sopenharmony_ci 518c2ecf20Sopenharmony_cistatic ssize_t write_file_bool_bmps(struct file *file, 528c2ecf20Sopenharmony_ci const char __user *user_buf, 538c2ecf20Sopenharmony_ci size_t count, loff_t *ppos) 548c2ecf20Sopenharmony_ci{ 558c2ecf20Sopenharmony_ci struct wcn36xx *wcn = file->private_data; 568c2ecf20Sopenharmony_ci struct wcn36xx_vif *vif_priv = NULL; 578c2ecf20Sopenharmony_ci struct ieee80211_vif *vif = NULL; 588c2ecf20Sopenharmony_ci 598c2ecf20Sopenharmony_ci char buf[32]; 608c2ecf20Sopenharmony_ci int buf_size; 618c2ecf20Sopenharmony_ci 628c2ecf20Sopenharmony_ci buf_size = min(count, (sizeof(buf)-1)); 638c2ecf20Sopenharmony_ci if (copy_from_user(buf, user_buf, buf_size)) 648c2ecf20Sopenharmony_ci return -EFAULT; 658c2ecf20Sopenharmony_ci 668c2ecf20Sopenharmony_ci switch (buf[0]) { 678c2ecf20Sopenharmony_ci case 'y': 688c2ecf20Sopenharmony_ci case 'Y': 698c2ecf20Sopenharmony_ci case '1': 708c2ecf20Sopenharmony_ci list_for_each_entry(vif_priv, &wcn->vif_list, list) { 718c2ecf20Sopenharmony_ci vif = wcn36xx_priv_to_vif(vif_priv); 728c2ecf20Sopenharmony_ci if (NL80211_IFTYPE_STATION == vif->type) { 738c2ecf20Sopenharmony_ci wcn36xx_enable_keep_alive_null_packet(wcn, vif); 748c2ecf20Sopenharmony_ci wcn36xx_pmc_enter_bmps_state(wcn, vif); 758c2ecf20Sopenharmony_ci } 768c2ecf20Sopenharmony_ci } 778c2ecf20Sopenharmony_ci break; 788c2ecf20Sopenharmony_ci case 'n': 798c2ecf20Sopenharmony_ci case 'N': 808c2ecf20Sopenharmony_ci case '0': 818c2ecf20Sopenharmony_ci list_for_each_entry(vif_priv, &wcn->vif_list, list) { 828c2ecf20Sopenharmony_ci vif = wcn36xx_priv_to_vif(vif_priv); 838c2ecf20Sopenharmony_ci if (NL80211_IFTYPE_STATION == vif->type) 848c2ecf20Sopenharmony_ci wcn36xx_pmc_exit_bmps_state(wcn, vif); 858c2ecf20Sopenharmony_ci } 868c2ecf20Sopenharmony_ci break; 878c2ecf20Sopenharmony_ci } 888c2ecf20Sopenharmony_ci 898c2ecf20Sopenharmony_ci return count; 908c2ecf20Sopenharmony_ci} 918c2ecf20Sopenharmony_ci 928c2ecf20Sopenharmony_cistatic const struct file_operations fops_wcn36xx_bmps = { 938c2ecf20Sopenharmony_ci .open = simple_open, 948c2ecf20Sopenharmony_ci .read = read_file_bool_bmps, 958c2ecf20Sopenharmony_ci .write = write_file_bool_bmps, 968c2ecf20Sopenharmony_ci}; 978c2ecf20Sopenharmony_ci 988c2ecf20Sopenharmony_cistatic ssize_t write_file_dump(struct file *file, 998c2ecf20Sopenharmony_ci const char __user *user_buf, 1008c2ecf20Sopenharmony_ci size_t count, loff_t *ppos) 1018c2ecf20Sopenharmony_ci{ 1028c2ecf20Sopenharmony_ci struct wcn36xx *wcn = file->private_data; 1038c2ecf20Sopenharmony_ci char buf[255], *tmp; 1048c2ecf20Sopenharmony_ci int buf_size; 1058c2ecf20Sopenharmony_ci u32 arg[WCN36xx_MAX_DUMP_ARGS]; 1068c2ecf20Sopenharmony_ci int i; 1078c2ecf20Sopenharmony_ci 1088c2ecf20Sopenharmony_ci memset(buf, 0, sizeof(buf)); 1098c2ecf20Sopenharmony_ci memset(arg, 0, sizeof(arg)); 1108c2ecf20Sopenharmony_ci 1118c2ecf20Sopenharmony_ci buf_size = min(count, (sizeof(buf) - 1)); 1128c2ecf20Sopenharmony_ci if (copy_from_user(buf, user_buf, buf_size)) 1138c2ecf20Sopenharmony_ci return -EFAULT; 1148c2ecf20Sopenharmony_ci 1158c2ecf20Sopenharmony_ci tmp = buf; 1168c2ecf20Sopenharmony_ci 1178c2ecf20Sopenharmony_ci for (i = 0; i < WCN36xx_MAX_DUMP_ARGS; i++) { 1188c2ecf20Sopenharmony_ci char *begin; 1198c2ecf20Sopenharmony_ci begin = strsep(&tmp, " "); 1208c2ecf20Sopenharmony_ci if (begin == NULL) 1218c2ecf20Sopenharmony_ci break; 1228c2ecf20Sopenharmony_ci 1238c2ecf20Sopenharmony_ci if (kstrtou32(begin, 0, &arg[i]) != 0) 1248c2ecf20Sopenharmony_ci break; 1258c2ecf20Sopenharmony_ci } 1268c2ecf20Sopenharmony_ci 1278c2ecf20Sopenharmony_ci wcn36xx_info("DUMP args is %d %d %d %d %d\n", arg[0], arg[1], arg[2], 1288c2ecf20Sopenharmony_ci arg[3], arg[4]); 1298c2ecf20Sopenharmony_ci wcn36xx_smd_dump_cmd_req(wcn, arg[0], arg[1], arg[2], arg[3], arg[4]); 1308c2ecf20Sopenharmony_ci 1318c2ecf20Sopenharmony_ci return count; 1328c2ecf20Sopenharmony_ci} 1338c2ecf20Sopenharmony_ci 1348c2ecf20Sopenharmony_cistatic const struct file_operations fops_wcn36xx_dump = { 1358c2ecf20Sopenharmony_ci .open = simple_open, 1368c2ecf20Sopenharmony_ci .write = write_file_dump, 1378c2ecf20Sopenharmony_ci}; 1388c2ecf20Sopenharmony_ci 1398c2ecf20Sopenharmony_ci#define ADD_FILE(name, mode, fop, priv_data) \ 1408c2ecf20Sopenharmony_ci do { \ 1418c2ecf20Sopenharmony_ci struct dentry *d; \ 1428c2ecf20Sopenharmony_ci d = debugfs_create_file(__stringify(name), \ 1438c2ecf20Sopenharmony_ci mode, dfs->rootdir, \ 1448c2ecf20Sopenharmony_ci priv_data, fop); \ 1458c2ecf20Sopenharmony_ci dfs->file_##name.dentry = d; \ 1468c2ecf20Sopenharmony_ci if (IS_ERR(d)) { \ 1478c2ecf20Sopenharmony_ci wcn36xx_warn("Create the debugfs entry failed");\ 1488c2ecf20Sopenharmony_ci dfs->file_##name.dentry = NULL; \ 1498c2ecf20Sopenharmony_ci } \ 1508c2ecf20Sopenharmony_ci } while (0) 1518c2ecf20Sopenharmony_ci 1528c2ecf20Sopenharmony_ci 1538c2ecf20Sopenharmony_civoid wcn36xx_debugfs_init(struct wcn36xx *wcn) 1548c2ecf20Sopenharmony_ci{ 1558c2ecf20Sopenharmony_ci struct wcn36xx_dfs_entry *dfs = &wcn->dfs; 1568c2ecf20Sopenharmony_ci 1578c2ecf20Sopenharmony_ci dfs->rootdir = debugfs_create_dir(KBUILD_MODNAME, 1588c2ecf20Sopenharmony_ci wcn->hw->wiphy->debugfsdir); 1598c2ecf20Sopenharmony_ci if (IS_ERR(dfs->rootdir)) { 1608c2ecf20Sopenharmony_ci wcn36xx_warn("Create the debugfs failed\n"); 1618c2ecf20Sopenharmony_ci dfs->rootdir = NULL; 1628c2ecf20Sopenharmony_ci } 1638c2ecf20Sopenharmony_ci 1648c2ecf20Sopenharmony_ci ADD_FILE(bmps_switcher, 0600, &fops_wcn36xx_bmps, wcn); 1658c2ecf20Sopenharmony_ci ADD_FILE(dump, 0200, &fops_wcn36xx_dump, wcn); 1668c2ecf20Sopenharmony_ci} 1678c2ecf20Sopenharmony_ci 1688c2ecf20Sopenharmony_civoid wcn36xx_debugfs_exit(struct wcn36xx *wcn) 1698c2ecf20Sopenharmony_ci{ 1708c2ecf20Sopenharmony_ci struct wcn36xx_dfs_entry *dfs = &wcn->dfs; 1718c2ecf20Sopenharmony_ci debugfs_remove_recursive(dfs->rootdir); 1728c2ecf20Sopenharmony_ci} 1738c2ecf20Sopenharmony_ci 1748c2ecf20Sopenharmony_ci#endif /* CONFIG_WCN36XX_DEBUGFS */ 175