debugfs_sta.c 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. /*
  2. * Copyright (c) 2014 Qualcomm Atheros, Inc.
  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
  11. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  12. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  13. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  14. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. #include "core.h"
  17. #include "wmi-ops.h"
  18. #include "debug.h"
  19. void ath10k_sta_update_rx_duration(struct ath10k *ar, struct list_head *head)
  20. { struct ieee80211_sta *sta;
  21. struct ath10k_fw_stats_peer *peer;
  22. struct ath10k_sta *arsta;
  23. rcu_read_lock();
  24. list_for_each_entry(peer, head, list) {
  25. sta = ieee80211_find_sta_by_ifaddr(ar->hw, peer->peer_macaddr,
  26. NULL);
  27. if (!sta)
  28. continue;
  29. arsta = (struct ath10k_sta *)sta->drv_priv;
  30. arsta->rx_duration += (u64)peer->rx_duration;
  31. }
  32. rcu_read_unlock();
  33. }
  34. static ssize_t ath10k_dbg_sta_read_aggr_mode(struct file *file,
  35. char __user *user_buf,
  36. size_t count, loff_t *ppos)
  37. {
  38. struct ieee80211_sta *sta = file->private_data;
  39. struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
  40. struct ath10k *ar = arsta->arvif->ar;
  41. char buf[32];
  42. int len = 0;
  43. mutex_lock(&ar->conf_mutex);
  44. len = scnprintf(buf, sizeof(buf) - len, "aggregation mode: %s\n",
  45. (arsta->aggr_mode == ATH10K_DBG_AGGR_MODE_AUTO) ?
  46. "auto" : "manual");
  47. mutex_unlock(&ar->conf_mutex);
  48. return simple_read_from_buffer(user_buf, count, ppos, buf, len);
  49. }
  50. static ssize_t ath10k_dbg_sta_write_aggr_mode(struct file *file,
  51. const char __user *user_buf,
  52. size_t count, loff_t *ppos)
  53. {
  54. struct ieee80211_sta *sta = file->private_data;
  55. struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
  56. struct ath10k *ar = arsta->arvif->ar;
  57. u32 aggr_mode;
  58. int ret;
  59. if (kstrtouint_from_user(user_buf, count, 0, &aggr_mode))
  60. return -EINVAL;
  61. if (aggr_mode >= ATH10K_DBG_AGGR_MODE_MAX)
  62. return -EINVAL;
  63. mutex_lock(&ar->conf_mutex);
  64. if ((ar->state != ATH10K_STATE_ON) ||
  65. (aggr_mode == arsta->aggr_mode)) {
  66. ret = count;
  67. goto out;
  68. }
  69. ret = ath10k_wmi_addba_clear_resp(ar, arsta->arvif->vdev_id, sta->addr);
  70. if (ret) {
  71. ath10k_warn(ar, "failed to clear addba session ret: %d\n", ret);
  72. goto out;
  73. }
  74. arsta->aggr_mode = aggr_mode;
  75. out:
  76. mutex_unlock(&ar->conf_mutex);
  77. return ret;
  78. }
  79. static const struct file_operations fops_aggr_mode = {
  80. .read = ath10k_dbg_sta_read_aggr_mode,
  81. .write = ath10k_dbg_sta_write_aggr_mode,
  82. .open = simple_open,
  83. .owner = THIS_MODULE,
  84. .llseek = default_llseek,
  85. };
  86. static ssize_t ath10k_dbg_sta_write_addba(struct file *file,
  87. const char __user *user_buf,
  88. size_t count, loff_t *ppos)
  89. {
  90. struct ieee80211_sta *sta = file->private_data;
  91. struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
  92. struct ath10k *ar = arsta->arvif->ar;
  93. u32 tid, buf_size;
  94. int ret;
  95. char buf[64];
  96. simple_write_to_buffer(buf, sizeof(buf) - 1, ppos, user_buf, count);
  97. /* make sure that buf is null terminated */
  98. buf[sizeof(buf) - 1] = '\0';
  99. ret = sscanf(buf, "%u %u", &tid, &buf_size);
  100. if (ret != 2)
  101. return -EINVAL;
  102. /* Valid TID values are 0 through 15 */
  103. if (tid > HTT_DATA_TX_EXT_TID_MGMT - 2)
  104. return -EINVAL;
  105. mutex_lock(&ar->conf_mutex);
  106. if ((ar->state != ATH10K_STATE_ON) ||
  107. (arsta->aggr_mode != ATH10K_DBG_AGGR_MODE_MANUAL)) {
  108. ret = count;
  109. goto out;
  110. }
  111. ret = ath10k_wmi_addba_send(ar, arsta->arvif->vdev_id, sta->addr,
  112. tid, buf_size);
  113. if (ret) {
  114. ath10k_warn(ar, "failed to send addba request: vdev_id %u peer %pM tid %u buf_size %u\n",
  115. arsta->arvif->vdev_id, sta->addr, tid, buf_size);
  116. }
  117. ret = count;
  118. out:
  119. mutex_unlock(&ar->conf_mutex);
  120. return ret;
  121. }
  122. static const struct file_operations fops_addba = {
  123. .write = ath10k_dbg_sta_write_addba,
  124. .open = simple_open,
  125. .owner = THIS_MODULE,
  126. .llseek = default_llseek,
  127. };
  128. static ssize_t ath10k_dbg_sta_write_addba_resp(struct file *file,
  129. const char __user *user_buf,
  130. size_t count, loff_t *ppos)
  131. {
  132. struct ieee80211_sta *sta = file->private_data;
  133. struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
  134. struct ath10k *ar = arsta->arvif->ar;
  135. u32 tid, status;
  136. int ret;
  137. char buf[64];
  138. simple_write_to_buffer(buf, sizeof(buf) - 1, ppos, user_buf, count);
  139. /* make sure that buf is null terminated */
  140. buf[sizeof(buf) - 1] = '\0';
  141. ret = sscanf(buf, "%u %u", &tid, &status);
  142. if (ret != 2)
  143. return -EINVAL;
  144. /* Valid TID values are 0 through 15 */
  145. if (tid > HTT_DATA_TX_EXT_TID_MGMT - 2)
  146. return -EINVAL;
  147. mutex_lock(&ar->conf_mutex);
  148. if ((ar->state != ATH10K_STATE_ON) ||
  149. (arsta->aggr_mode != ATH10K_DBG_AGGR_MODE_MANUAL)) {
  150. ret = count;
  151. goto out;
  152. }
  153. ret = ath10k_wmi_addba_set_resp(ar, arsta->arvif->vdev_id, sta->addr,
  154. tid, status);
  155. if (ret) {
  156. ath10k_warn(ar, "failed to send addba response: vdev_id %u peer %pM tid %u status%u\n",
  157. arsta->arvif->vdev_id, sta->addr, tid, status);
  158. }
  159. ret = count;
  160. out:
  161. mutex_unlock(&ar->conf_mutex);
  162. return ret;
  163. }
  164. static const struct file_operations fops_addba_resp = {
  165. .write = ath10k_dbg_sta_write_addba_resp,
  166. .open = simple_open,
  167. .owner = THIS_MODULE,
  168. .llseek = default_llseek,
  169. };
  170. static ssize_t ath10k_dbg_sta_write_delba(struct file *file,
  171. const char __user *user_buf,
  172. size_t count, loff_t *ppos)
  173. {
  174. struct ieee80211_sta *sta = file->private_data;
  175. struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
  176. struct ath10k *ar = arsta->arvif->ar;
  177. u32 tid, initiator, reason;
  178. int ret;
  179. char buf[64];
  180. simple_write_to_buffer(buf, sizeof(buf) - 1, ppos, user_buf, count);
  181. /* make sure that buf is null terminated */
  182. buf[sizeof(buf) - 1] = '\0';
  183. ret = sscanf(buf, "%u %u %u", &tid, &initiator, &reason);
  184. if (ret != 3)
  185. return -EINVAL;
  186. /* Valid TID values are 0 through 15 */
  187. if (tid > HTT_DATA_TX_EXT_TID_MGMT - 2)
  188. return -EINVAL;
  189. mutex_lock(&ar->conf_mutex);
  190. if ((ar->state != ATH10K_STATE_ON) ||
  191. (arsta->aggr_mode != ATH10K_DBG_AGGR_MODE_MANUAL)) {
  192. ret = count;
  193. goto out;
  194. }
  195. ret = ath10k_wmi_delba_send(ar, arsta->arvif->vdev_id, sta->addr,
  196. tid, initiator, reason);
  197. if (ret) {
  198. ath10k_warn(ar, "failed to send delba: vdev_id %u peer %pM tid %u initiator %u reason %u\n",
  199. arsta->arvif->vdev_id, sta->addr, tid, initiator,
  200. reason);
  201. }
  202. ret = count;
  203. out:
  204. mutex_unlock(&ar->conf_mutex);
  205. return ret;
  206. }
  207. static const struct file_operations fops_delba = {
  208. .write = ath10k_dbg_sta_write_delba,
  209. .open = simple_open,
  210. .owner = THIS_MODULE,
  211. .llseek = default_llseek,
  212. };
  213. static ssize_t ath10k_dbg_sta_read_rx_duration(struct file *file,
  214. char __user *user_buf,
  215. size_t count, loff_t *ppos)
  216. {
  217. struct ieee80211_sta *sta = file->private_data;
  218. struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
  219. char buf[100];
  220. int len = 0;
  221. len = scnprintf(buf, sizeof(buf),
  222. "%llu usecs\n", arsta->rx_duration);
  223. return simple_read_from_buffer(user_buf, count, ppos, buf, len);
  224. }
  225. static const struct file_operations fops_rx_duration = {
  226. .read = ath10k_dbg_sta_read_rx_duration,
  227. .open = simple_open,
  228. .owner = THIS_MODULE,
  229. .llseek = default_llseek,
  230. };
  231. void ath10k_sta_add_debugfs(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
  232. struct ieee80211_sta *sta, struct dentry *dir)
  233. {
  234. debugfs_create_file("aggr_mode", S_IRUGO | S_IWUSR, dir, sta,
  235. &fops_aggr_mode);
  236. debugfs_create_file("addba", S_IWUSR, dir, sta, &fops_addba);
  237. debugfs_create_file("addba_resp", S_IWUSR, dir, sta, &fops_addba_resp);
  238. debugfs_create_file("delba", S_IWUSR, dir, sta, &fops_delba);
  239. debugfs_create_file("rx_duration", S_IRUGO, dir, sta,
  240. &fops_rx_duration);
  241. }