debug.c 4.6 KB

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