Commit | Line | Data |
---|---|---|
ec8aa669 FF |
1 | /* |
2 | * Copyright (C) 2010 Felix Fietkau <nbd@openwrt.org> | |
3 | * | |
4 | * This program is free software; you can redistribute it and/or modify | |
5 | * it under the terms of the GNU General Public License version 2 as | |
6 | * published by the Free Software Foundation. | |
7 | */ | |
8 | #include <linux/netdevice.h> | |
9 | #include <linux/types.h> | |
10 | #include <linux/skbuff.h> | |
11 | #include <linux/debugfs.h> | |
12 | #include <linux/ieee80211.h> | |
bc3b2d7f | 13 | #include <linux/export.h> |
ec8aa669 FF |
14 | #include <net/mac80211.h> |
15 | #include "rc80211_minstrel.h" | |
16 | #include "rc80211_minstrel_ht.h" | |
17 | ||
a0497f9f FF |
18 | static char * |
19 | minstrel_ht_stats_dump(struct minstrel_ht_sta *mi, int i, char *p) | |
20 | { | |
a0497f9f FF |
21 | const struct mcs_group *mg; |
22 | unsigned int j, tp, prob, eprob; | |
23 | char htmode = '2'; | |
24 | char gimode = 'L'; | |
25 | ||
26 | if (!mi->groups[i].supported) | |
27 | return p; | |
28 | ||
29 | mg = &minstrel_mcs_groups[i]; | |
30 | if (mg->flags & IEEE80211_TX_RC_40_MHZ_WIDTH) | |
31 | htmode = '4'; | |
9208247d KB |
32 | else if (mg->flags & IEEE80211_TX_RC_80_MHZ_WIDTH) |
33 | htmode = '8'; | |
a0497f9f FF |
34 | if (mg->flags & IEEE80211_TX_RC_SHORT_GI) |
35 | gimode = 'S'; | |
36 | ||
37 | for (j = 0; j < MCS_GROUP_RATES; j++) { | |
38 | struct minstrel_rate_stats *mr = &mi->groups[i].rates[j]; | |
39 | static const int bitrates[4] = { 10, 20, 55, 110 }; | |
40 | int idx = i * MCS_GROUP_RATES + j; | |
41 | ||
42 | if (!(mi->groups[i].supported & BIT(j))) | |
43 | continue; | |
44 | ||
8a0ee4fe | 45 | if (i == MINSTREL_CCK_GROUP) |
9208247d KB |
46 | p += sprintf(p, " CCK/%cP ", j < 4 ? 'L' : 'S'); |
47 | else if (i >= MINSTREL_VHT_GROUP_0) | |
48 | p += sprintf(p, "VHT%c0/%cGI ", htmode, gimode); | |
a0497f9f | 49 | else |
9208247d | 50 | p += sprintf(p, " HT%c0/%cGI ", htmode, gimode); |
a0497f9f | 51 | |
5935839a TH |
52 | *(p++) = (idx == mi->max_tp_rate[0]) ? 'A' : ' '; |
53 | *(p++) = (idx == mi->max_tp_rate[1]) ? 'B' : ' '; | |
54 | *(p++) = (idx == mi->max_tp_rate[2]) ? 'C' : ' '; | |
55 | *(p++) = (idx == mi->max_tp_rate[3]) ? 'D' : ' '; | |
a0497f9f FF |
56 | *(p++) = (idx == mi->max_prob_rate) ? 'P' : ' '; |
57 | ||
8a0ee4fe | 58 | if (i == MINSTREL_CCK_GROUP) { |
a0497f9f | 59 | int r = bitrates[j % 4]; |
9208247d KB |
60 | p += sprintf(p, " %2u.%1uM ", r / 10, r % 10); |
61 | } else if (i >= MINSTREL_VHT_GROUP_0) { | |
62 | p += sprintf(p, " MCS%-1u/%1u", j, mg->streams); | |
a0497f9f | 63 | } else { |
9208247d | 64 | p += sprintf(p, " MCS%-2u ", (mg->streams - 1) * 8 + j); |
a0497f9f FF |
65 | } |
66 | ||
67 | tp = mr->cur_tp / 10; | |
68 | prob = MINSTREL_TRUNC(mr->cur_prob * 1000); | |
69 | eprob = MINSTREL_TRUNC(mr->probability * 1000); | |
70 | ||
11b2357d KB |
71 | p += sprintf(p, " %4u.%1u %3u.%1u %3u.%1u " |
72 | "%3u %4u(%4u) %9llu(%9llu)\n", | |
a0497f9f FF |
73 | tp / 10, tp % 10, |
74 | eprob / 10, eprob % 10, | |
75 | prob / 10, prob % 10, | |
76 | mr->retry_count, | |
77 | mr->last_success, | |
78 | mr->last_attempts, | |
79 | (unsigned long long)mr->succ_hist, | |
80 | (unsigned long long)mr->att_hist); | |
81 | } | |
82 | ||
83 | return p; | |
84 | } | |
85 | ||
ec8aa669 FF |
86 | static int |
87 | minstrel_ht_stats_open(struct inode *inode, struct file *file) | |
88 | { | |
89 | struct minstrel_ht_sta_priv *msp = inode->i_private; | |
90 | struct minstrel_ht_sta *mi = &msp->ht; | |
91 | struct minstrel_debugfs_info *ms; | |
a0497f9f | 92 | unsigned int i; |
ec8aa669 FF |
93 | char *p; |
94 | int ret; | |
95 | ||
96 | if (!msp->is_ht) { | |
97 | inode->i_private = &msp->legacy; | |
98 | ret = minstrel_stats_open(inode, file); | |
99 | inode->i_private = msp; | |
100 | return ret; | |
101 | } | |
102 | ||
9208247d | 103 | ms = kmalloc(32768, GFP_KERNEL); |
ec8aa669 FF |
104 | if (!ms) |
105 | return -ENOMEM; | |
106 | ||
107 | file->private_data = ms; | |
108 | p = ms->buf; | |
9208247d | 109 | p += sprintf(p, " type rate tpt eprob *prob " |
11b2357d KB |
110 | "ret *ok(*cum) ok( cum)\n"); |
111 | ||
8a0ee4fe KB |
112 | p = minstrel_ht_stats_dump(mi, MINSTREL_CCK_GROUP, p); |
113 | for (i = 0; i < MINSTREL_CCK_GROUP; i++) | |
a0497f9f | 114 | p = minstrel_ht_stats_dump(mi, i, p); |
9208247d KB |
115 | for (i++; i < ARRAY_SIZE(mi->groups); i++) |
116 | p = minstrel_ht_stats_dump(mi, i, p); | |
ec8aa669 | 117 | |
ec8aa669 FF |
118 | p += sprintf(p, "\nTotal packet count:: ideal %d " |
119 | "lookaround %d\n", | |
120 | max(0, (int) mi->total_packets - (int) mi->sample_packets), | |
121 | mi->sample_packets); | |
122 | p += sprintf(p, "Average A-MPDU length: %d.%d\n", | |
123 | MINSTREL_TRUNC(mi->avg_ampdu_len), | |
124 | MINSTREL_TRUNC(mi->avg_ampdu_len * 10) % 10); | |
125 | ms->len = p - ms->buf; | |
126 | ||
9208247d | 127 | WARN_ON(ms->len + sizeof(*ms) > 32768); |
11b2357d | 128 | |
a0572d93 | 129 | return nonseekable_open(inode, file); |
ec8aa669 FF |
130 | } |
131 | ||
132 | static const struct file_operations minstrel_ht_stat_fops = { | |
133 | .owner = THIS_MODULE, | |
134 | .open = minstrel_ht_stats_open, | |
135 | .read = minstrel_stats_read, | |
136 | .release = minstrel_stats_release, | |
a0572d93 | 137 | .llseek = no_llseek, |
ec8aa669 FF |
138 | }; |
139 | ||
140 | void | |
141 | minstrel_ht_add_sta_debugfs(void *priv, void *priv_sta, struct dentry *dir) | |
142 | { | |
143 | struct minstrel_ht_sta_priv *msp = priv_sta; | |
144 | ||
145 | msp->dbg_stats = debugfs_create_file("rc_stats", S_IRUGO, dir, msp, | |
146 | &minstrel_ht_stat_fops); | |
147 | } | |
148 | ||
149 | void | |
150 | minstrel_ht_remove_sta_debugfs(void *priv, void *priv_sta) | |
151 | { | |
152 | struct minstrel_ht_sta_priv *msp = priv_sta; | |
153 | ||
154 | debugfs_remove(msp->dbg_stats); | |
155 | } |