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.
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;
29 list_for_each_entry(peer, &stats->peers_extd, list) {
30 sta = ieee80211_find_sta_by_ifaddr(ar->hw, peer->peer_macaddr,
34 arsta = (struct ath10k_sta *)sta->drv_priv;
35 arsta->rx_duration += (u64)peer->rx_duration;
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;
48 list_for_each_entry(peer, &stats->peers, list) {
49 sta = ieee80211_find_sta_by_ifaddr(ar->hw, peer->peer_macaddr,
53 arsta = (struct ath10k_sta *)sta->drv_priv;
54 arsta->rx_duration += (u64)peer->rx_duration;
59 void ath10k_sta_update_rx_duration(struct ath10k *ar,
60 struct ath10k_fw_stats *stats)
63 ath10k_sta_update_extd_stats_rx_duration(ar, stats);
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))
78 sinfo->rx_duration = arsta->rx_duration;
79 sinfo->filled |= 1ULL << NL80211_STA_INFO_RX_DURATION;
81 if (!arsta->txrate.legacy && !arsta->txrate.nss)
84 if (arsta->txrate.legacy) {
85 sinfo->txrate.legacy = arsta->txrate.legacy;
87 sinfo->txrate.mcs = arsta->txrate.mcs;
88 sinfo->txrate.nss = arsta->txrate.nss;
89 sinfo->txrate.bw = arsta->txrate.bw;
91 sinfo->txrate.flags = arsta->txrate.flags;
92 sinfo->filled |= 1ULL << NL80211_STA_INFO_TX_BITRATE;
95 static ssize_t ath10k_dbg_sta_read_aggr_mode(struct file *file,
96 char __user *user_buf,
97 size_t count, loff_t *ppos)
99 struct ieee80211_sta *sta = file->private_data;
100 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
101 struct ath10k *ar = arsta->arvif->ar;
105 mutex_lock(&ar->conf_mutex);
106 len = scnprintf(buf, sizeof(buf) - len, "aggregation mode: %s\n",
107 (arsta->aggr_mode == ATH10K_DBG_AGGR_MODE_AUTO) ?
109 mutex_unlock(&ar->conf_mutex);
111 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
114 static ssize_t ath10k_dbg_sta_write_aggr_mode(struct file *file,
115 const char __user *user_buf,
116 size_t count, loff_t *ppos)
118 struct ieee80211_sta *sta = file->private_data;
119 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
120 struct ath10k *ar = arsta->arvif->ar;
124 if (kstrtouint_from_user(user_buf, count, 0, &aggr_mode))
127 if (aggr_mode >= ATH10K_DBG_AGGR_MODE_MAX)
130 mutex_lock(&ar->conf_mutex);
131 if ((ar->state != ATH10K_STATE_ON) ||
132 (aggr_mode == arsta->aggr_mode)) {
137 ret = ath10k_wmi_addba_clear_resp(ar, arsta->arvif->vdev_id, sta->addr);
139 ath10k_warn(ar, "failed to clear addba session ret: %d\n", ret);
143 arsta->aggr_mode = aggr_mode;
145 mutex_unlock(&ar->conf_mutex);
149 static const struct file_operations fops_aggr_mode = {
150 .read = ath10k_dbg_sta_read_aggr_mode,
151 .write = ath10k_dbg_sta_write_aggr_mode,
153 .owner = THIS_MODULE,
154 .llseek = default_llseek,
157 static ssize_t ath10k_dbg_sta_write_addba(struct file *file,
158 const char __user *user_buf,
159 size_t count, loff_t *ppos)
161 struct ieee80211_sta *sta = file->private_data;
162 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
163 struct ath10k *ar = arsta->arvif->ar;
168 simple_write_to_buffer(buf, sizeof(buf) - 1, ppos, user_buf, count);
170 /* make sure that buf is null terminated */
171 buf[sizeof(buf) - 1] = '\0';
173 ret = sscanf(buf, "%u %u", &tid, &buf_size);
177 /* Valid TID values are 0 through 15 */
178 if (tid > HTT_DATA_TX_EXT_TID_MGMT - 2)
181 mutex_lock(&ar->conf_mutex);
182 if ((ar->state != ATH10K_STATE_ON) ||
183 (arsta->aggr_mode != ATH10K_DBG_AGGR_MODE_MANUAL)) {
188 ret = ath10k_wmi_addba_send(ar, arsta->arvif->vdev_id, sta->addr,
191 ath10k_warn(ar, "failed to send addba request: vdev_id %u peer %pM tid %u buf_size %u\n",
192 arsta->arvif->vdev_id, sta->addr, tid, buf_size);
197 mutex_unlock(&ar->conf_mutex);
201 static const struct file_operations fops_addba = {
202 .write = ath10k_dbg_sta_write_addba,
204 .owner = THIS_MODULE,
205 .llseek = default_llseek,
208 static ssize_t ath10k_dbg_sta_write_addba_resp(struct file *file,
209 const char __user *user_buf,
210 size_t count, loff_t *ppos)
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;
219 simple_write_to_buffer(buf, sizeof(buf) - 1, ppos, user_buf, count);
221 /* make sure that buf is null terminated */
222 buf[sizeof(buf) - 1] = '\0';
224 ret = sscanf(buf, "%u %u", &tid, &status);
228 /* Valid TID values are 0 through 15 */
229 if (tid > HTT_DATA_TX_EXT_TID_MGMT - 2)
232 mutex_lock(&ar->conf_mutex);
233 if ((ar->state != ATH10K_STATE_ON) ||
234 (arsta->aggr_mode != ATH10K_DBG_AGGR_MODE_MANUAL)) {
239 ret = ath10k_wmi_addba_set_resp(ar, arsta->arvif->vdev_id, sta->addr,
242 ath10k_warn(ar, "failed to send addba response: vdev_id %u peer %pM tid %u status%u\n",
243 arsta->arvif->vdev_id, sta->addr, tid, status);
247 mutex_unlock(&ar->conf_mutex);
251 static const struct file_operations fops_addba_resp = {
252 .write = ath10k_dbg_sta_write_addba_resp,
254 .owner = THIS_MODULE,
255 .llseek = default_llseek,
258 static ssize_t ath10k_dbg_sta_write_delba(struct file *file,
259 const char __user *user_buf,
260 size_t count, loff_t *ppos)
262 struct ieee80211_sta *sta = file->private_data;
263 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
264 struct ath10k *ar = arsta->arvif->ar;
265 u32 tid, initiator, reason;
269 simple_write_to_buffer(buf, sizeof(buf) - 1, ppos, user_buf, count);
271 /* make sure that buf is null terminated */
272 buf[sizeof(buf) - 1] = '\0';
274 ret = sscanf(buf, "%u %u %u", &tid, &initiator, &reason);
278 /* Valid TID values are 0 through 15 */
279 if (tid > HTT_DATA_TX_EXT_TID_MGMT - 2)
282 mutex_lock(&ar->conf_mutex);
283 if ((ar->state != ATH10K_STATE_ON) ||
284 (arsta->aggr_mode != ATH10K_DBG_AGGR_MODE_MANUAL)) {
289 ret = ath10k_wmi_delba_send(ar, arsta->arvif->vdev_id, sta->addr,
290 tid, initiator, reason);
292 ath10k_warn(ar, "failed to send delba: vdev_id %u peer %pM tid %u initiator %u reason %u\n",
293 arsta->arvif->vdev_id, sta->addr, tid, initiator,
298 mutex_unlock(&ar->conf_mutex);
302 static const struct file_operations fops_delba = {
303 .write = ath10k_dbg_sta_write_delba,
305 .owner = THIS_MODULE,
306 .llseek = default_llseek,
309 static ssize_t ath10k_dbg_sta_read_peer_debug_trigger(struct file *file,
310 char __user *user_buf,
314 struct ieee80211_sta *sta = file->private_data;
315 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
316 struct ath10k *ar = arsta->arvif->ar;
320 mutex_lock(&ar->conf_mutex);
321 len = scnprintf(buf, sizeof(buf) - len,
322 "Write 1 to once trigger the debug logs\n");
323 mutex_unlock(&ar->conf_mutex);
325 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
329 ath10k_dbg_sta_write_peer_debug_trigger(struct file *file,
330 const char __user *user_buf,
331 size_t count, loff_t *ppos)
333 struct ieee80211_sta *sta = file->private_data;
334 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
335 struct ath10k *ar = arsta->arvif->ar;
336 u8 peer_debug_trigger;
339 if (kstrtou8_from_user(user_buf, count, 0, &peer_debug_trigger))
342 if (peer_debug_trigger != 1)
345 mutex_lock(&ar->conf_mutex);
347 if (ar->state != ATH10K_STATE_ON) {
352 ret = ath10k_wmi_peer_set_param(ar, arsta->arvif->vdev_id, sta->addr,
353 WMI_PEER_DEBUG, peer_debug_trigger);
355 ath10k_warn(ar, "failed to set param to trigger peer tid logs for station ret: %d\n",
360 mutex_unlock(&ar->conf_mutex);
364 static const struct file_operations fops_peer_debug_trigger = {
366 .read = ath10k_dbg_sta_read_peer_debug_trigger,
367 .write = ath10k_dbg_sta_write_peer_debug_trigger,
368 .owner = THIS_MODULE,
369 .llseek = default_llseek,
372 void ath10k_sta_add_debugfs(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
373 struct ieee80211_sta *sta, struct dentry *dir)
375 debugfs_create_file("aggr_mode", 0644, dir, sta, &fops_aggr_mode);
376 debugfs_create_file("addba", 0200, dir, sta, &fops_addba);
377 debugfs_create_file("addba_resp", 0200, dir, sta, &fops_addba_resp);
378 debugfs_create_file("delba", 0200, dir, sta, &fops_delba);
379 debugfs_create_file("peer_debug_trigger", 0600, dir, sta,
380 &fops_peer_debug_trigger);