debug.c 4.4 KB

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