debugfs_sta.c 8.4 KB

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