debug.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. /*
  2. * Copyright (c) 2013 Eugene Krasnikov <k.eugene.e@gmail.com>
  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. #ifdef CONFIG_WCN36XX_DEBUGFS
  23. static int wcn36xx_debugfs_open(struct inode *inode, struct file *file)
  24. {
  25. file->private_data = inode->i_private;
  26. return 0;
  27. }
  28. static ssize_t read_file_bool_bmps(struct file *file, char __user *user_buf,
  29. size_t count, loff_t *ppos)
  30. {
  31. struct wcn36xx *wcn = file->private_data;
  32. struct wcn36xx_vif *vif_priv = NULL;
  33. struct ieee80211_vif *vif = NULL;
  34. char buf[3];
  35. list_for_each_entry(vif_priv, &wcn->vif_list, list) {
  36. vif = container_of((void *)vif_priv,
  37. struct ieee80211_vif,
  38. drv_priv);
  39. if (NL80211_IFTYPE_STATION == vif->type) {
  40. if (vif_priv->pw_state == WCN36XX_BMPS)
  41. buf[0] = '1';
  42. else
  43. buf[0] = '0';
  44. break;
  45. }
  46. }
  47. buf[1] = '\n';
  48. buf[2] = 0x00;
  49. return simple_read_from_buffer(user_buf, count, ppos, buf, 2);
  50. }
  51. static ssize_t write_file_bool_bmps(struct file *file,
  52. const char __user *user_buf,
  53. size_t count, loff_t *ppos)
  54. {
  55. struct wcn36xx *wcn = file->private_data;
  56. struct wcn36xx_vif *vif_priv = NULL;
  57. struct ieee80211_vif *vif = NULL;
  58. char buf[32];
  59. int buf_size;
  60. buf_size = min(count, (sizeof(buf)-1));
  61. if (copy_from_user(buf, user_buf, buf_size))
  62. return -EFAULT;
  63. switch (buf[0]) {
  64. case 'y':
  65. case 'Y':
  66. case '1':
  67. list_for_each_entry(vif_priv, &wcn->vif_list, list) {
  68. vif = container_of((void *)vif_priv,
  69. struct ieee80211_vif,
  70. drv_priv);
  71. if (NL80211_IFTYPE_STATION == vif->type) {
  72. wcn36xx_enable_keep_alive_null_packet(wcn, vif);
  73. wcn36xx_pmc_enter_bmps_state(wcn, vif);
  74. }
  75. }
  76. break;
  77. case 'n':
  78. case 'N':
  79. case '0':
  80. list_for_each_entry(vif_priv, &wcn->vif_list, list) {
  81. vif = container_of((void *)vif_priv,
  82. struct ieee80211_vif,
  83. drv_priv);
  84. if (NL80211_IFTYPE_STATION == vif->type)
  85. wcn36xx_pmc_exit_bmps_state(wcn, vif);
  86. }
  87. break;
  88. }
  89. return count;
  90. }
  91. static const struct file_operations fops_wcn36xx_bmps = {
  92. .open = wcn36xx_debugfs_open,
  93. .read = read_file_bool_bmps,
  94. .write = write_file_bool_bmps,
  95. };
  96. static ssize_t write_file_dump(struct file *file,
  97. const char __user *user_buf,
  98. size_t count, loff_t *ppos)
  99. {
  100. struct wcn36xx *wcn = file->private_data;
  101. char buf[255], *tmp;
  102. int buf_size;
  103. u32 arg[WCN36xx_MAX_DUMP_ARGS];
  104. int i;
  105. memset(buf, 0, sizeof(buf));
  106. memset(arg, 0, sizeof(arg));
  107. buf_size = min(count, (sizeof(buf) - 1));
  108. if (copy_from_user(buf, user_buf, buf_size))
  109. return -EFAULT;
  110. tmp = buf;
  111. for (i = 0; i < WCN36xx_MAX_DUMP_ARGS; i++) {
  112. char *begin;
  113. begin = strsep(&tmp, " ");
  114. if (begin == NULL)
  115. break;
  116. if (kstrtoul(begin, 0, (unsigned long *)(arg + i)) != 0)
  117. break;
  118. }
  119. wcn36xx_info("DUMP args is %d %d %d %d %d\n", arg[0], arg[1], arg[2],
  120. arg[3], arg[4]);
  121. wcn36xx_smd_dump_cmd_req(wcn, arg[0], arg[1], arg[2], arg[3], arg[4]);
  122. return count;
  123. }
  124. static const struct file_operations fops_wcn36xx_dump = {
  125. .open = wcn36xx_debugfs_open,
  126. .write = write_file_dump,
  127. };
  128. #define ADD_FILE(name, mode, fop, priv_data) \
  129. do { \
  130. struct dentry *d; \
  131. d = debugfs_create_file(__stringify(name), \
  132. mode, dfs->rootdir, \
  133. priv_data, fop); \
  134. dfs->file_##name.dentry = d; \
  135. if (IS_ERR(d)) { \
  136. wcn36xx_warn("Create the debugfs entry failed");\
  137. dfs->file_##name.dentry = NULL; \
  138. } \
  139. } while (0)
  140. void wcn36xx_debugfs_init(struct wcn36xx *wcn)
  141. {
  142. struct wcn36xx_dfs_entry *dfs = &wcn->dfs;
  143. dfs->rootdir = debugfs_create_dir(KBUILD_MODNAME,
  144. wcn->hw->wiphy->debugfsdir);
  145. if (IS_ERR(dfs->rootdir)) {
  146. wcn36xx_warn("Create the debugfs failed\n");
  147. dfs->rootdir = NULL;
  148. }
  149. ADD_FILE(bmps_switcher, S_IRUSR | S_IWUSR,
  150. &fops_wcn36xx_bmps, wcn);
  151. ADD_FILE(dump, S_IWUSR, &fops_wcn36xx_dump, wcn);
  152. }
  153. void wcn36xx_debugfs_exit(struct wcn36xx *wcn)
  154. {
  155. struct wcn36xx_dfs_entry *dfs = &wcn->dfs;
  156. debugfs_remove_recursive(dfs->rootdir);
  157. }
  158. #endif /* CONFIG_WCN36XX_DEBUGFS */