18c2ecf20Sopenharmony_ci/* 28c2ecf20Sopenharmony_ci * Copyright (c) 2013 Qualcomm Atheros, Inc. 38c2ecf20Sopenharmony_ci * 48c2ecf20Sopenharmony_ci * Permission to use, copy, modify, and/or distribute this software for any 58c2ecf20Sopenharmony_ci * purpose with or without fee is hereby granted, provided that the above 68c2ecf20Sopenharmony_ci * copyright notice and this permission notice appear in all copies. 78c2ecf20Sopenharmony_ci * 88c2ecf20Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 98c2ecf20Sopenharmony_ci * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 108c2ecf20Sopenharmony_ci * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 118c2ecf20Sopenharmony_ci * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 128c2ecf20Sopenharmony_ci * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 138c2ecf20Sopenharmony_ci * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 148c2ecf20Sopenharmony_ci * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 158c2ecf20Sopenharmony_ci */ 168c2ecf20Sopenharmony_ci 178c2ecf20Sopenharmony_ci#include "ath9k.h" 188c2ecf20Sopenharmony_ci 198c2ecf20Sopenharmony_ci/*************/ 208c2ecf20Sopenharmony_ci/* node_aggr */ 218c2ecf20Sopenharmony_ci/*************/ 228c2ecf20Sopenharmony_ci 238c2ecf20Sopenharmony_cistatic ssize_t read_file_node_aggr(struct file *file, char __user *user_buf, 248c2ecf20Sopenharmony_ci size_t count, loff_t *ppos) 258c2ecf20Sopenharmony_ci{ 268c2ecf20Sopenharmony_ci struct ath_node *an = file->private_data; 278c2ecf20Sopenharmony_ci struct ath_softc *sc = an->sc; 288c2ecf20Sopenharmony_ci struct ath_atx_tid *tid; 298c2ecf20Sopenharmony_ci struct ath_txq *txq; 308c2ecf20Sopenharmony_ci u32 len = 0, size = 4096; 318c2ecf20Sopenharmony_ci char *buf; 328c2ecf20Sopenharmony_ci size_t retval; 338c2ecf20Sopenharmony_ci int tidno; 348c2ecf20Sopenharmony_ci 358c2ecf20Sopenharmony_ci buf = kzalloc(size, GFP_KERNEL); 368c2ecf20Sopenharmony_ci if (buf == NULL) 378c2ecf20Sopenharmony_ci return -ENOMEM; 388c2ecf20Sopenharmony_ci 398c2ecf20Sopenharmony_ci if (!an->sta->ht_cap.ht_supported) { 408c2ecf20Sopenharmony_ci len = scnprintf(buf, size, "%s\n", 418c2ecf20Sopenharmony_ci "HT not supported"); 428c2ecf20Sopenharmony_ci goto exit; 438c2ecf20Sopenharmony_ci } 448c2ecf20Sopenharmony_ci 458c2ecf20Sopenharmony_ci len = scnprintf(buf, size, "Max-AMPDU: %d\n", 468c2ecf20Sopenharmony_ci an->maxampdu); 478c2ecf20Sopenharmony_ci len += scnprintf(buf + len, size - len, "MPDU Density: %d\n\n", 488c2ecf20Sopenharmony_ci an->mpdudensity); 498c2ecf20Sopenharmony_ci 508c2ecf20Sopenharmony_ci len += scnprintf(buf + len, size - len, 518c2ecf20Sopenharmony_ci "\n%3s%11s%10s%10s%10s%10s%9s%6s%8s\n", 528c2ecf20Sopenharmony_ci "TID", "SEQ_START", "SEQ_NEXT", "BAW_SIZE", 538c2ecf20Sopenharmony_ci "BAW_HEAD", "BAW_TAIL", "BAR_IDX", "SCHED", "PAUSED"); 548c2ecf20Sopenharmony_ci 558c2ecf20Sopenharmony_ci for (tidno = 0; tidno < IEEE80211_NUM_TIDS; tidno++) { 568c2ecf20Sopenharmony_ci tid = ath_node_to_tid(an, tidno); 578c2ecf20Sopenharmony_ci txq = tid->txq; 588c2ecf20Sopenharmony_ci ath_txq_lock(sc, txq); 598c2ecf20Sopenharmony_ci if (tid->active) { 608c2ecf20Sopenharmony_ci len += scnprintf(buf + len, size - len, 618c2ecf20Sopenharmony_ci "%3d%11d%10d%10d%10d%10d%9d%6d\n", 628c2ecf20Sopenharmony_ci tid->tidno, 638c2ecf20Sopenharmony_ci tid->seq_start, 648c2ecf20Sopenharmony_ci tid->seq_next, 658c2ecf20Sopenharmony_ci tid->baw_size, 668c2ecf20Sopenharmony_ci tid->baw_head, 678c2ecf20Sopenharmony_ci tid->baw_tail, 688c2ecf20Sopenharmony_ci tid->bar_index, 698c2ecf20Sopenharmony_ci !list_empty(&tid->list)); 708c2ecf20Sopenharmony_ci } 718c2ecf20Sopenharmony_ci ath_txq_unlock(sc, txq); 728c2ecf20Sopenharmony_ci } 738c2ecf20Sopenharmony_ciexit: 748c2ecf20Sopenharmony_ci retval = simple_read_from_buffer(user_buf, count, ppos, buf, len); 758c2ecf20Sopenharmony_ci kfree(buf); 768c2ecf20Sopenharmony_ci 778c2ecf20Sopenharmony_ci return retval; 788c2ecf20Sopenharmony_ci} 798c2ecf20Sopenharmony_ci 808c2ecf20Sopenharmony_cistatic const struct file_operations fops_node_aggr = { 818c2ecf20Sopenharmony_ci .read = read_file_node_aggr, 828c2ecf20Sopenharmony_ci .open = simple_open, 838c2ecf20Sopenharmony_ci .owner = THIS_MODULE, 848c2ecf20Sopenharmony_ci .llseek = default_llseek, 858c2ecf20Sopenharmony_ci}; 868c2ecf20Sopenharmony_ci 878c2ecf20Sopenharmony_ci/*************/ 888c2ecf20Sopenharmony_ci/* node_recv */ 898c2ecf20Sopenharmony_ci/*************/ 908c2ecf20Sopenharmony_ci 918c2ecf20Sopenharmony_civoid ath_debug_rate_stats(struct ath_softc *sc, 928c2ecf20Sopenharmony_ci struct ath_rx_status *rs, 938c2ecf20Sopenharmony_ci struct sk_buff *skb) 948c2ecf20Sopenharmony_ci{ 958c2ecf20Sopenharmony_ci struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data; 968c2ecf20Sopenharmony_ci struct ath_hw *ah = sc->sc_ah; 978c2ecf20Sopenharmony_ci struct ieee80211_rx_status *rxs; 988c2ecf20Sopenharmony_ci struct ath_rx_rate_stats *rstats; 998c2ecf20Sopenharmony_ci struct ieee80211_sta *sta; 1008c2ecf20Sopenharmony_ci struct ath_node *an; 1018c2ecf20Sopenharmony_ci 1028c2ecf20Sopenharmony_ci if (!ieee80211_is_data(hdr->frame_control)) 1038c2ecf20Sopenharmony_ci return; 1048c2ecf20Sopenharmony_ci 1058c2ecf20Sopenharmony_ci rcu_read_lock(); 1068c2ecf20Sopenharmony_ci 1078c2ecf20Sopenharmony_ci sta = ieee80211_find_sta_by_ifaddr(sc->hw, hdr->addr2, NULL); 1088c2ecf20Sopenharmony_ci if (!sta) 1098c2ecf20Sopenharmony_ci goto exit; 1108c2ecf20Sopenharmony_ci 1118c2ecf20Sopenharmony_ci an = (struct ath_node *) sta->drv_priv; 1128c2ecf20Sopenharmony_ci rstats = &an->rx_rate_stats; 1138c2ecf20Sopenharmony_ci rxs = IEEE80211_SKB_RXCB(skb); 1148c2ecf20Sopenharmony_ci 1158c2ecf20Sopenharmony_ci if (IS_HT_RATE(rs->rs_rate)) { 1168c2ecf20Sopenharmony_ci if (rxs->rate_idx >= ARRAY_SIZE(rstats->ht_stats)) 1178c2ecf20Sopenharmony_ci goto exit; 1188c2ecf20Sopenharmony_ci 1198c2ecf20Sopenharmony_ci if (rxs->bw == RATE_INFO_BW_40) 1208c2ecf20Sopenharmony_ci rstats->ht_stats[rxs->rate_idx].ht40_cnt++; 1218c2ecf20Sopenharmony_ci else 1228c2ecf20Sopenharmony_ci rstats->ht_stats[rxs->rate_idx].ht20_cnt++; 1238c2ecf20Sopenharmony_ci 1248c2ecf20Sopenharmony_ci if (rxs->enc_flags & RX_ENC_FLAG_SHORT_GI) 1258c2ecf20Sopenharmony_ci rstats->ht_stats[rxs->rate_idx].sgi_cnt++; 1268c2ecf20Sopenharmony_ci else 1278c2ecf20Sopenharmony_ci rstats->ht_stats[rxs->rate_idx].lgi_cnt++; 1288c2ecf20Sopenharmony_ci 1298c2ecf20Sopenharmony_ci goto exit; 1308c2ecf20Sopenharmony_ci } 1318c2ecf20Sopenharmony_ci 1328c2ecf20Sopenharmony_ci if (IS_CCK_RATE(rs->rs_rate)) { 1338c2ecf20Sopenharmony_ci if (rxs->enc_flags & RX_ENC_FLAG_SHORTPRE) 1348c2ecf20Sopenharmony_ci rstats->cck_stats[rxs->rate_idx].cck_sp_cnt++; 1358c2ecf20Sopenharmony_ci else 1368c2ecf20Sopenharmony_ci rstats->cck_stats[rxs->rate_idx].cck_lp_cnt++; 1378c2ecf20Sopenharmony_ci 1388c2ecf20Sopenharmony_ci goto exit; 1398c2ecf20Sopenharmony_ci } 1408c2ecf20Sopenharmony_ci 1418c2ecf20Sopenharmony_ci if (IS_OFDM_RATE(rs->rs_rate)) { 1428c2ecf20Sopenharmony_ci if (ah->curchan->chan->band == NL80211_BAND_2GHZ) 1438c2ecf20Sopenharmony_ci rstats->ofdm_stats[rxs->rate_idx - 4].ofdm_cnt++; 1448c2ecf20Sopenharmony_ci else 1458c2ecf20Sopenharmony_ci rstats->ofdm_stats[rxs->rate_idx].ofdm_cnt++; 1468c2ecf20Sopenharmony_ci } 1478c2ecf20Sopenharmony_ciexit: 1488c2ecf20Sopenharmony_ci rcu_read_unlock(); 1498c2ecf20Sopenharmony_ci} 1508c2ecf20Sopenharmony_ci 1518c2ecf20Sopenharmony_ci#define PRINT_CCK_RATE(str, i, sp) \ 1528c2ecf20Sopenharmony_ci do { \ 1538c2ecf20Sopenharmony_ci len += scnprintf(buf + len, size - len, \ 1548c2ecf20Sopenharmony_ci "%11s : %10u\n", \ 1558c2ecf20Sopenharmony_ci str, \ 1568c2ecf20Sopenharmony_ci (sp) ? rstats->cck_stats[i].cck_sp_cnt : \ 1578c2ecf20Sopenharmony_ci rstats->cck_stats[i].cck_lp_cnt); \ 1588c2ecf20Sopenharmony_ci } while (0) 1598c2ecf20Sopenharmony_ci 1608c2ecf20Sopenharmony_ci#define PRINT_OFDM_RATE(str, i) \ 1618c2ecf20Sopenharmony_ci do { \ 1628c2ecf20Sopenharmony_ci len += scnprintf(buf + len, size - len, \ 1638c2ecf20Sopenharmony_ci "%11s : %10u\n", \ 1648c2ecf20Sopenharmony_ci str, \ 1658c2ecf20Sopenharmony_ci rstats->ofdm_stats[i].ofdm_cnt); \ 1668c2ecf20Sopenharmony_ci } while (0) 1678c2ecf20Sopenharmony_ci 1688c2ecf20Sopenharmony_cistatic ssize_t read_file_node_recv(struct file *file, char __user *user_buf, 1698c2ecf20Sopenharmony_ci size_t count, loff_t *ppos) 1708c2ecf20Sopenharmony_ci{ 1718c2ecf20Sopenharmony_ci struct ath_node *an = file->private_data; 1728c2ecf20Sopenharmony_ci struct ath_softc *sc = an->sc; 1738c2ecf20Sopenharmony_ci struct ath_hw *ah = sc->sc_ah; 1748c2ecf20Sopenharmony_ci struct ath_rx_rate_stats *rstats; 1758c2ecf20Sopenharmony_ci struct ieee80211_sta *sta = an->sta; 1768c2ecf20Sopenharmony_ci enum nl80211_band band; 1778c2ecf20Sopenharmony_ci u32 len = 0, size = 4096; 1788c2ecf20Sopenharmony_ci char *buf; 1798c2ecf20Sopenharmony_ci size_t retval; 1808c2ecf20Sopenharmony_ci int i; 1818c2ecf20Sopenharmony_ci 1828c2ecf20Sopenharmony_ci buf = kzalloc(size, GFP_KERNEL); 1838c2ecf20Sopenharmony_ci if (buf == NULL) 1848c2ecf20Sopenharmony_ci return -ENOMEM; 1858c2ecf20Sopenharmony_ci 1868c2ecf20Sopenharmony_ci band = ah->curchan->chan->band; 1878c2ecf20Sopenharmony_ci rstats = &an->rx_rate_stats; 1888c2ecf20Sopenharmony_ci 1898c2ecf20Sopenharmony_ci if (!sta->ht_cap.ht_supported) 1908c2ecf20Sopenharmony_ci goto legacy; 1918c2ecf20Sopenharmony_ci 1928c2ecf20Sopenharmony_ci len += scnprintf(buf + len, size - len, 1938c2ecf20Sopenharmony_ci "%24s%10s%10s%10s\n", 1948c2ecf20Sopenharmony_ci "HT20", "HT40", "SGI", "LGI"); 1958c2ecf20Sopenharmony_ci 1968c2ecf20Sopenharmony_ci for (i = 0; i < 24; i++) { 1978c2ecf20Sopenharmony_ci len += scnprintf(buf + len, size - len, 1988c2ecf20Sopenharmony_ci "%8s%3u : %10u%10u%10u%10u\n", 1998c2ecf20Sopenharmony_ci "MCS", i, 2008c2ecf20Sopenharmony_ci rstats->ht_stats[i].ht20_cnt, 2018c2ecf20Sopenharmony_ci rstats->ht_stats[i].ht40_cnt, 2028c2ecf20Sopenharmony_ci rstats->ht_stats[i].sgi_cnt, 2038c2ecf20Sopenharmony_ci rstats->ht_stats[i].lgi_cnt); 2048c2ecf20Sopenharmony_ci } 2058c2ecf20Sopenharmony_ci 2068c2ecf20Sopenharmony_ci len += scnprintf(buf + len, size - len, "\n"); 2078c2ecf20Sopenharmony_ci 2088c2ecf20Sopenharmony_cilegacy: 2098c2ecf20Sopenharmony_ci if (band == NL80211_BAND_2GHZ) { 2108c2ecf20Sopenharmony_ci PRINT_CCK_RATE("CCK-1M/LP", 0, false); 2118c2ecf20Sopenharmony_ci PRINT_CCK_RATE("CCK-2M/LP", 1, false); 2128c2ecf20Sopenharmony_ci PRINT_CCK_RATE("CCK-5.5M/LP", 2, false); 2138c2ecf20Sopenharmony_ci PRINT_CCK_RATE("CCK-11M/LP", 3, false); 2148c2ecf20Sopenharmony_ci 2158c2ecf20Sopenharmony_ci PRINT_CCK_RATE("CCK-2M/SP", 1, true); 2168c2ecf20Sopenharmony_ci PRINT_CCK_RATE("CCK-5.5M/SP", 2, true); 2178c2ecf20Sopenharmony_ci PRINT_CCK_RATE("CCK-11M/SP", 3, true); 2188c2ecf20Sopenharmony_ci } 2198c2ecf20Sopenharmony_ci 2208c2ecf20Sopenharmony_ci PRINT_OFDM_RATE("OFDM-6M", 0); 2218c2ecf20Sopenharmony_ci PRINT_OFDM_RATE("OFDM-9M", 1); 2228c2ecf20Sopenharmony_ci PRINT_OFDM_RATE("OFDM-12M", 2); 2238c2ecf20Sopenharmony_ci PRINT_OFDM_RATE("OFDM-18M", 3); 2248c2ecf20Sopenharmony_ci PRINT_OFDM_RATE("OFDM-24M", 4); 2258c2ecf20Sopenharmony_ci PRINT_OFDM_RATE("OFDM-36M", 5); 2268c2ecf20Sopenharmony_ci PRINT_OFDM_RATE("OFDM-48M", 6); 2278c2ecf20Sopenharmony_ci PRINT_OFDM_RATE("OFDM-54M", 7); 2288c2ecf20Sopenharmony_ci 2298c2ecf20Sopenharmony_ci retval = simple_read_from_buffer(user_buf, count, ppos, buf, len); 2308c2ecf20Sopenharmony_ci kfree(buf); 2318c2ecf20Sopenharmony_ci 2328c2ecf20Sopenharmony_ci return retval; 2338c2ecf20Sopenharmony_ci} 2348c2ecf20Sopenharmony_ci 2358c2ecf20Sopenharmony_ci#undef PRINT_OFDM_RATE 2368c2ecf20Sopenharmony_ci#undef PRINT_CCK_RATE 2378c2ecf20Sopenharmony_ci 2388c2ecf20Sopenharmony_cistatic const struct file_operations fops_node_recv = { 2398c2ecf20Sopenharmony_ci .read = read_file_node_recv, 2408c2ecf20Sopenharmony_ci .open = simple_open, 2418c2ecf20Sopenharmony_ci .owner = THIS_MODULE, 2428c2ecf20Sopenharmony_ci .llseek = default_llseek, 2438c2ecf20Sopenharmony_ci}; 2448c2ecf20Sopenharmony_ci 2458c2ecf20Sopenharmony_civoid ath9k_sta_add_debugfs(struct ieee80211_hw *hw, 2468c2ecf20Sopenharmony_ci struct ieee80211_vif *vif, 2478c2ecf20Sopenharmony_ci struct ieee80211_sta *sta, 2488c2ecf20Sopenharmony_ci struct dentry *dir) 2498c2ecf20Sopenharmony_ci{ 2508c2ecf20Sopenharmony_ci struct ath_node *an = (struct ath_node *)sta->drv_priv; 2518c2ecf20Sopenharmony_ci 2528c2ecf20Sopenharmony_ci debugfs_create_file("node_aggr", 0444, dir, an, &fops_node_aggr); 2538c2ecf20Sopenharmony_ci debugfs_create_file("node_recv", 0444, dir, an, &fops_node_recv); 2548c2ecf20Sopenharmony_ci} 255