debug.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. /*
  2. * Copyright (c) 2013 Eugene Krasnikov <[email protected]>
  3. *
  4. * Permission to use, copy, modify, and/or distribute this software for any
  5. * purpose with or without fee is hereby granted, provided that the above
  6. * copyright notice and this permission notice appear in all copies.
  7. *
  8. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  9. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  10. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
  11. * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  12. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
  13. * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  14. * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  17. #include <linux/debugfs.h>
  18. #include <linux/uaccess.h>
  19. #include "wcn36xx.h"
  20. #include "debug.h"
  21. #include "pmc.h"
  22. #include "firmware.h"
  23. #ifdef CONFIG_WCN36XX_DEBUGFS
  24. static ssize_t read_file_bool_bmps(struct file *file, char __user *user_buf,
  25. size_t count, loff_t *ppos)
  26. {
  27. struct wcn36xx *wcn = file->private_data;
  28. struct wcn36xx_vif *vif_priv = NULL;
  29. struct ieee80211_vif *vif = NULL;
  30. char buf[3];
  31. list_for_each_entry(vif_priv, &wcn->vif_list, list) {
  32. vif = wcn36xx_priv_to_vif(vif_priv);
  33. if (NL80211_IFTYPE_STATION == vif->type) {
  34. if (vif_priv->pw_state == WCN36XX_BMPS)
  35. buf[0] = '1';
  36. else
  37. buf[0] = '0';
  38. break;
  39. }
  40. }
  41. buf[1] = '\n';
  42. buf[2] = 0x00;
  43. return simple_read_from_buffer(user_buf, count, ppos, buf, 2);
  44. }
  45. static ssize_t write_file_bool_bmps(struct file *file,
  46. const char __user *user_buf,
  47. size_t count, loff_t *ppos)
  48. {
  49. struct wcn36xx *wcn = file->private_data;
  50. struct wcn36xx_vif *vif_priv = NULL;
  51. struct ieee80211_vif *vif = NULL;
  52. char buf[32];
  53. int buf_size;
  54. buf_size = min(count, (sizeof(buf)-1));
  55. if (copy_from_user(buf, user_buf, buf_size))
  56. return -EFAULT;
  57. switch (buf[0]) {
  58. case 'y':
  59. case 'Y':
  60. case '1':
  61. list_for_each_entry(vif_priv, &wcn->vif_list, list) {
  62. vif = wcn36xx_priv_to_vif(vif_priv);
  63. if (NL80211_IFTYPE_STATION == vif->type) {
  64. wcn36xx_enable_keep_alive_null_packet(wcn, vif);
  65. wcn36xx_pmc_enter_bmps_state(wcn, vif);
  66. }
  67. }
  68. break;
  69. case 'n':
  70. case 'N':
  71. case '0':
  72. list_for_each_entry(vif_priv, &wcn->vif_list, list) {
  73. vif = wcn36xx_priv_to_vif(vif_priv);
  74. if (NL80211_IFTYPE_STATION == vif->type)
  75. wcn36xx_pmc_exit_bmps_state(wcn, vif);
  76. }
  77. break;
  78. }
  79. return count;
  80. }
  81. static const struct file_operations fops_wcn36xx_bmps = {
  82. .open = simple_open,
  83. .read = read_file_bool_bmps,
  84. .write = write_file_bool_bmps,
  85. };
  86. static ssize_t write_file_dump(struct file *file,
  87. const char __user *user_buf,
  88. size_t count, loff_t *ppos)
  89. {
  90. struct wcn36xx *wcn = file->private_data;
  91. char buf[255], *tmp;
  92. int buf_size;
  93. u32 arg[WCN36xx_MAX_DUMP_ARGS];
  94. int i;
  95. memset(buf, 0, sizeof(buf));
  96. memset(arg, 0, sizeof(arg));
  97. buf_size = min(count, (sizeof(buf) - 1));
  98. if (copy_from_user(buf, user_buf, buf_size))
  99. return -EFAULT;
  100. tmp = buf;
  101. for (i = 0; i < WCN36xx_MAX_DUMP_ARGS; i++) {
  102. char *begin;
  103. begin = strsep(&tmp, " ");
  104. if (begin == NULL)
  105. break;
  106. if (kstrtos32(begin, 0, &arg[i]) != 0)
  107. break;
  108. }
  109. wcn36xx_info("DUMP args is %d %d %d %d %d\n", arg[0], arg[1], arg[2],
  110. arg[3], arg[4]);
  111. wcn36xx_smd_dump_cmd_req(wcn, arg[0], arg[1], arg[2], arg[3], arg[4]);
  112. return count;
  113. }
  114. static const struct file_operations fops_wcn36xx_dump = {
  115. .open = simple_open,
  116. .write = write_file_dump,
  117. };
  118. static ssize_t read_file_firmware_feature_caps(struct file *file,
  119. char __user *user_buf,
  120. size_t count, loff_t *ppos)
  121. {
  122. struct wcn36xx *wcn = file->private_data;
  123. size_t len = 0, buf_len = 2048;
  124. char *buf;
  125. int i;
  126. int ret;
  127. buf = kzalloc(buf_len, GFP_KERNEL);
  128. if (!buf)
  129. return -ENOMEM;
  130. mutex_lock(&wcn->hal_mutex);
  131. for (i = 0; i < MAX_FEATURE_SUPPORTED; i++) {
  132. if (wcn36xx_firmware_get_feat_caps(wcn->fw_feat_caps, i)) {
  133. len += scnprintf(buf + len, buf_len - len, "%s\n",
  134. wcn36xx_firmware_get_cap_name(i));
  135. }
  136. if (len >= buf_len)
  137. break;
  138. }
  139. mutex_unlock(&wcn->hal_mutex);
  140. ret = simple_read_from_buffer(user_buf, count, ppos, buf, len);
  141. kfree(buf);
  142. return ret;
  143. }
  144. static const struct file_operations fops_wcn36xx_firmware_feat_caps = {
  145. .open = simple_open,
  146. .read = read_file_firmware_feature_caps,
  147. };
  148. #define ADD_FILE(name, mode, fop, priv_data) \
  149. do { \
  150. struct dentry *d; \
  151. d = debugfs_create_file(__stringify(name), \
  152. mode, dfs->rootdir, \
  153. priv_data, fop); \
  154. dfs->file_##name.dentry = d; \
  155. if (IS_ERR(d)) { \
  156. wcn36xx_warn("Create the debugfs entry failed");\
  157. dfs->file_##name.dentry = NULL; \
  158. } \
  159. } while (0)
  160. void wcn36xx_debugfs_init(struct wcn36xx *wcn)
  161. {
  162. struct wcn36xx_dfs_entry *dfs = &wcn->dfs;
  163. dfs->rootdir = debugfs_create_dir(KBUILD_MODNAME,
  164. wcn->hw->wiphy->debugfsdir);
  165. if (IS_ERR(dfs->rootdir)) {
  166. wcn36xx_warn("Create the debugfs failed\n");
  167. dfs->rootdir = NULL;
  168. }
  169. ADD_FILE(bmps_switcher, 0600, &fops_wcn36xx_bmps, wcn);
  170. ADD_FILE(dump, 0200, &fops_wcn36xx_dump, wcn);
  171. ADD_FILE(firmware_feat_caps, 0200,
  172. &fops_wcn36xx_firmware_feat_caps, wcn);
  173. }
  174. void wcn36xx_debugfs_exit(struct wcn36xx *wcn)
  175. {
  176. struct wcn36xx_dfs_entry *dfs = &wcn->dfs;
  177. debugfs_remove_recursive(dfs->rootdir);
  178. }
  179. #endif /* CONFIG_WCN36XX_DEBUGFS */