Merge branch 'perf-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel...
[cris-mirror.git] / drivers / net / wireless / ath / ath10k / debugfs_sta.c
blob9955fea0802a80a90abc7cde88373e9474f96339
1 /*
2 * Copyright (c) 2014 Qualcomm Atheros, Inc.
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.
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.
17 #include "core.h"
18 #include "wmi-ops.h"
19 #include "debug.h"
21 static void ath10k_sta_update_extd_stats_rx_duration(struct ath10k *ar,
22 struct ath10k_fw_stats *stats)
24 struct ath10k_fw_extd_stats_peer *peer;
25 struct ieee80211_sta *sta;
26 struct ath10k_sta *arsta;
28 rcu_read_lock();
29 list_for_each_entry(peer, &stats->peers_extd, list) {
30 sta = ieee80211_find_sta_by_ifaddr(ar->hw, peer->peer_macaddr,
31 NULL);
32 if (!sta)
33 continue;
34 arsta = (struct ath10k_sta *)sta->drv_priv;
35 arsta->rx_duration += (u64)peer->rx_duration;
37 rcu_read_unlock();
40 static void ath10k_sta_update_stats_rx_duration(struct ath10k *ar,
41 struct ath10k_fw_stats *stats)
43 struct ath10k_fw_stats_peer *peer;
44 struct ieee80211_sta *sta;
45 struct ath10k_sta *arsta;
47 rcu_read_lock();
48 list_for_each_entry(peer, &stats->peers, list) {
49 sta = ieee80211_find_sta_by_ifaddr(ar->hw, peer->peer_macaddr,
50 NULL);
51 if (!sta)
52 continue;
53 arsta = (struct ath10k_sta *)sta->drv_priv;
54 arsta->rx_duration += (u64)peer->rx_duration;
56 rcu_read_unlock();
59 void ath10k_sta_update_rx_duration(struct ath10k *ar,
60 struct ath10k_fw_stats *stats)
62 if (stats->extended)
63 ath10k_sta_update_extd_stats_rx_duration(ar, stats);
64 else
65 ath10k_sta_update_stats_rx_duration(ar, stats);
68 void ath10k_sta_statistics(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
69 struct ieee80211_sta *sta,
70 struct station_info *sinfo)
72 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
73 struct ath10k *ar = arsta->arvif->ar;
75 if (!ath10k_peer_stats_enabled(ar))
76 return;
78 sinfo->rx_duration = arsta->rx_duration;
79 sinfo->filled |= 1ULL << NL80211_STA_INFO_RX_DURATION;
82 static ssize_t ath10k_dbg_sta_read_aggr_mode(struct file *file,
83 char __user *user_buf,
84 size_t count, loff_t *ppos)
86 struct ieee80211_sta *sta = file->private_data;
87 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
88 struct ath10k *ar = arsta->arvif->ar;
89 char buf[32];
90 int len = 0;
92 mutex_lock(&ar->conf_mutex);
93 len = scnprintf(buf, sizeof(buf) - len, "aggregation mode: %s\n",
94 (arsta->aggr_mode == ATH10K_DBG_AGGR_MODE_AUTO) ?
95 "auto" : "manual");
96 mutex_unlock(&ar->conf_mutex);
98 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
101 static ssize_t ath10k_dbg_sta_write_aggr_mode(struct file *file,
102 const char __user *user_buf,
103 size_t count, loff_t *ppos)
105 struct ieee80211_sta *sta = file->private_data;
106 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
107 struct ath10k *ar = arsta->arvif->ar;
108 u32 aggr_mode;
109 int ret;
111 if (kstrtouint_from_user(user_buf, count, 0, &aggr_mode))
112 return -EINVAL;
114 if (aggr_mode >= ATH10K_DBG_AGGR_MODE_MAX)
115 return -EINVAL;
117 mutex_lock(&ar->conf_mutex);
118 if ((ar->state != ATH10K_STATE_ON) ||
119 (aggr_mode == arsta->aggr_mode)) {
120 ret = count;
121 goto out;
124 ret = ath10k_wmi_addba_clear_resp(ar, arsta->arvif->vdev_id, sta->addr);
125 if (ret) {
126 ath10k_warn(ar, "failed to clear addba session ret: %d\n", ret);
127 goto out;
130 arsta->aggr_mode = aggr_mode;
131 out:
132 mutex_unlock(&ar->conf_mutex);
133 return ret;
136 static const struct file_operations fops_aggr_mode = {
137 .read = ath10k_dbg_sta_read_aggr_mode,
138 .write = ath10k_dbg_sta_write_aggr_mode,
139 .open = simple_open,
140 .owner = THIS_MODULE,
141 .llseek = default_llseek,
144 static ssize_t ath10k_dbg_sta_write_addba(struct file *file,
145 const char __user *user_buf,
146 size_t count, loff_t *ppos)
148 struct ieee80211_sta *sta = file->private_data;
149 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
150 struct ath10k *ar = arsta->arvif->ar;
151 u32 tid, buf_size;
152 int ret;
153 char buf[64];
155 simple_write_to_buffer(buf, sizeof(buf) - 1, ppos, user_buf, count);
157 /* make sure that buf is null terminated */
158 buf[sizeof(buf) - 1] = '\0';
160 ret = sscanf(buf, "%u %u", &tid, &buf_size);
161 if (ret != 2)
162 return -EINVAL;
164 /* Valid TID values are 0 through 15 */
165 if (tid > HTT_DATA_TX_EXT_TID_MGMT - 2)
166 return -EINVAL;
168 mutex_lock(&ar->conf_mutex);
169 if ((ar->state != ATH10K_STATE_ON) ||
170 (arsta->aggr_mode != ATH10K_DBG_AGGR_MODE_MANUAL)) {
171 ret = count;
172 goto out;
175 ret = ath10k_wmi_addba_send(ar, arsta->arvif->vdev_id, sta->addr,
176 tid, buf_size);
177 if (ret) {
178 ath10k_warn(ar, "failed to send addba request: vdev_id %u peer %pM tid %u buf_size %u\n",
179 arsta->arvif->vdev_id, sta->addr, tid, buf_size);
182 ret = count;
183 out:
184 mutex_unlock(&ar->conf_mutex);
185 return ret;
188 static const struct file_operations fops_addba = {
189 .write = ath10k_dbg_sta_write_addba,
190 .open = simple_open,
191 .owner = THIS_MODULE,
192 .llseek = default_llseek,
195 static ssize_t ath10k_dbg_sta_write_addba_resp(struct file *file,
196 const char __user *user_buf,
197 size_t count, loff_t *ppos)
199 struct ieee80211_sta *sta = file->private_data;
200 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
201 struct ath10k *ar = arsta->arvif->ar;
202 u32 tid, status;
203 int ret;
204 char buf[64];
206 simple_write_to_buffer(buf, sizeof(buf) - 1, ppos, user_buf, count);
208 /* make sure that buf is null terminated */
209 buf[sizeof(buf) - 1] = '\0';
211 ret = sscanf(buf, "%u %u", &tid, &status);
212 if (ret != 2)
213 return -EINVAL;
215 /* Valid TID values are 0 through 15 */
216 if (tid > HTT_DATA_TX_EXT_TID_MGMT - 2)
217 return -EINVAL;
219 mutex_lock(&ar->conf_mutex);
220 if ((ar->state != ATH10K_STATE_ON) ||
221 (arsta->aggr_mode != ATH10K_DBG_AGGR_MODE_MANUAL)) {
222 ret = count;
223 goto out;
226 ret = ath10k_wmi_addba_set_resp(ar, arsta->arvif->vdev_id, sta->addr,
227 tid, status);
228 if (ret) {
229 ath10k_warn(ar, "failed to send addba response: vdev_id %u peer %pM tid %u status%u\n",
230 arsta->arvif->vdev_id, sta->addr, tid, status);
232 ret = count;
233 out:
234 mutex_unlock(&ar->conf_mutex);
235 return ret;
238 static const struct file_operations fops_addba_resp = {
239 .write = ath10k_dbg_sta_write_addba_resp,
240 .open = simple_open,
241 .owner = THIS_MODULE,
242 .llseek = default_llseek,
245 static ssize_t ath10k_dbg_sta_write_delba(struct file *file,
246 const char __user *user_buf,
247 size_t count, loff_t *ppos)
249 struct ieee80211_sta *sta = file->private_data;
250 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
251 struct ath10k *ar = arsta->arvif->ar;
252 u32 tid, initiator, reason;
253 int ret;
254 char buf[64];
256 simple_write_to_buffer(buf, sizeof(buf) - 1, ppos, user_buf, count);
258 /* make sure that buf is null terminated */
259 buf[sizeof(buf) - 1] = '\0';
261 ret = sscanf(buf, "%u %u %u", &tid, &initiator, &reason);
262 if (ret != 3)
263 return -EINVAL;
265 /* Valid TID values are 0 through 15 */
266 if (tid > HTT_DATA_TX_EXT_TID_MGMT - 2)
267 return -EINVAL;
269 mutex_lock(&ar->conf_mutex);
270 if ((ar->state != ATH10K_STATE_ON) ||
271 (arsta->aggr_mode != ATH10K_DBG_AGGR_MODE_MANUAL)) {
272 ret = count;
273 goto out;
276 ret = ath10k_wmi_delba_send(ar, arsta->arvif->vdev_id, sta->addr,
277 tid, initiator, reason);
278 if (ret) {
279 ath10k_warn(ar, "failed to send delba: vdev_id %u peer %pM tid %u initiator %u reason %u\n",
280 arsta->arvif->vdev_id, sta->addr, tid, initiator,
281 reason);
283 ret = count;
284 out:
285 mutex_unlock(&ar->conf_mutex);
286 return ret;
289 static const struct file_operations fops_delba = {
290 .write = ath10k_dbg_sta_write_delba,
291 .open = simple_open,
292 .owner = THIS_MODULE,
293 .llseek = default_llseek,
296 void ath10k_sta_add_debugfs(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
297 struct ieee80211_sta *sta, struct dentry *dir)
299 debugfs_create_file("aggr_mode", S_IRUGO | S_IWUSR, dir, sta,
300 &fops_aggr_mode);
301 debugfs_create_file("addba", S_IWUSR, dir, sta, &fops_addba);
302 debugfs_create_file("addba_resp", S_IWUSR, dir, sta, &fops_addba_resp);
303 debugfs_create_file("delba", S_IWUSR, dir, sta, &fops_delba);