debugfs_sta.c 6.8 KB

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