diff options
Diffstat (limited to 'net/mac80211/debugfs.c')
-rw-r--r-- | net/mac80211/debugfs.c | 168 |
1 files changed, 168 insertions, 0 deletions
diff --git a/net/mac80211/debugfs.c b/net/mac80211/debugfs.c index 5c090e41d9bb..fa16e54980a1 100644 --- a/net/mac80211/debugfs.c +++ b/net/mac80211/debugfs.c | |||
@@ -17,6 +17,172 @@ | |||
17 | 17 | ||
18 | #define DEBUGFS_FORMAT_BUFFER_SIZE 100 | 18 | #define DEBUGFS_FORMAT_BUFFER_SIZE 100 |
19 | 19 | ||
20 | #define TX_LATENCY_BIN_DELIMTER_C ',' | ||
21 | #define TX_LATENCY_BIN_DELIMTER_S "," | ||
22 | #define TX_LATENCY_BINS_DISABLED "enable(bins disabled)\n" | ||
23 | #define TX_LATENCY_DISABLED "disable\n" | ||
24 | |||
25 | |||
26 | /* | ||
27 | * Display if Tx latency statistics & bins are enabled/disabled | ||
28 | */ | ||
29 | static ssize_t sta_tx_latency_stat_read(struct file *file, | ||
30 | char __user *userbuf, | ||
31 | size_t count, loff_t *ppos) | ||
32 | { | ||
33 | struct ieee80211_local *local = file->private_data; | ||
34 | struct ieee80211_tx_latency_bin_ranges *tx_latency; | ||
35 | char *buf; | ||
36 | int bufsz, i, ret; | ||
37 | int pos = 0; | ||
38 | |||
39 | rcu_read_lock(); | ||
40 | |||
41 | tx_latency = rcu_dereference(local->tx_latency); | ||
42 | |||
43 | if (tx_latency && tx_latency->n_ranges) { | ||
44 | bufsz = tx_latency->n_ranges * 15; | ||
45 | buf = kzalloc(bufsz, GFP_ATOMIC); | ||
46 | if (!buf) | ||
47 | goto err; | ||
48 | |||
49 | for (i = 0; i < tx_latency->n_ranges; i++) | ||
50 | pos += scnprintf(buf + pos, bufsz - pos, "%d,", | ||
51 | tx_latency->ranges[i]); | ||
52 | pos += scnprintf(buf + pos, bufsz - pos, "\n"); | ||
53 | } else if (tx_latency) { | ||
54 | bufsz = sizeof(TX_LATENCY_BINS_DISABLED) + 1; | ||
55 | buf = kzalloc(bufsz, GFP_ATOMIC); | ||
56 | if (!buf) | ||
57 | goto err; | ||
58 | |||
59 | pos += scnprintf(buf + pos, bufsz - pos, "%s\n", | ||
60 | TX_LATENCY_BINS_DISABLED); | ||
61 | } else { | ||
62 | bufsz = sizeof(TX_LATENCY_DISABLED) + 1; | ||
63 | buf = kzalloc(bufsz, GFP_ATOMIC); | ||
64 | if (!buf) | ||
65 | goto err; | ||
66 | |||
67 | pos += scnprintf(buf + pos, bufsz - pos, "%s\n", | ||
68 | TX_LATENCY_DISABLED); | ||
69 | } | ||
70 | |||
71 | rcu_read_unlock(); | ||
72 | |||
73 | ret = simple_read_from_buffer(userbuf, count, ppos, buf, pos); | ||
74 | kfree(buf); | ||
75 | |||
76 | return ret; | ||
77 | err: | ||
78 | rcu_read_unlock(); | ||
79 | return -ENOMEM; | ||
80 | } | ||
81 | |||
82 | /* | ||
83 | * Receive input from user regarding Tx latency statistics | ||
84 | * The input should indicate if Tx latency statistics and bins are | ||
85 | * enabled/disabled. | ||
86 | * If bins are enabled input should indicate the amount of different bins and | ||
87 | * their ranges. Each bin will count how many Tx frames transmitted within the | ||
88 | * appropriate latency. | ||
89 | * Legal input is: | ||
90 | * a) "enable(bins disabled)" - to enable only general statistics | ||
91 | * b) "a,b,c,d,...z" - to enable general statistics and bins, where all are | ||
92 | * numbers and a < b < c < d.. < z | ||
93 | * c) "disable" - disable all statistics | ||
94 | * NOTE: must configure Tx latency statistics bins before stations connected. | ||
95 | */ | ||
96 | |||
97 | static ssize_t sta_tx_latency_stat_write(struct file *file, | ||
98 | const char __user *userbuf, | ||
99 | size_t count, loff_t *ppos) | ||
100 | { | ||
101 | struct ieee80211_local *local = file->private_data; | ||
102 | char buf[128] = {}; | ||
103 | char *bins = buf; | ||
104 | char *token; | ||
105 | int buf_size, i, alloc_size; | ||
106 | int prev_bin = 0; | ||
107 | int n_ranges = 0; | ||
108 | int ret = count; | ||
109 | struct ieee80211_tx_latency_bin_ranges *tx_latency; | ||
110 | |||
111 | if (sizeof(buf) <= count) | ||
112 | return -EINVAL; | ||
113 | buf_size = count; | ||
114 | if (copy_from_user(buf, userbuf, buf_size)) | ||
115 | return -EFAULT; | ||
116 | |||
117 | mutex_lock(&local->sta_mtx); | ||
118 | |||
119 | /* cannot change config once we have stations */ | ||
120 | if (local->num_sta) | ||
121 | goto unlock; | ||
122 | |||
123 | tx_latency = | ||
124 | rcu_dereference_protected(local->tx_latency, | ||
125 | lockdep_is_held(&local->sta_mtx)); | ||
126 | |||
127 | /* disable Tx statistics */ | ||
128 | if (!strcmp(buf, TX_LATENCY_DISABLED)) { | ||
129 | if (!tx_latency) | ||
130 | goto unlock; | ||
131 | rcu_assign_pointer(local->tx_latency, NULL); | ||
132 | synchronize_rcu(); | ||
133 | kfree(tx_latency); | ||
134 | goto unlock; | ||
135 | } | ||
136 | |||
137 | /* Tx latency already enabled */ | ||
138 | if (tx_latency) | ||
139 | goto unlock; | ||
140 | |||
141 | if (strcmp(TX_LATENCY_BINS_DISABLED, buf)) { | ||
142 | /* check how many bins and between what ranges user requested */ | ||
143 | token = buf; | ||
144 | while (*token != '\0') { | ||
145 | if (*token == TX_LATENCY_BIN_DELIMTER_C) | ||
146 | n_ranges++; | ||
147 | token++; | ||
148 | } | ||
149 | n_ranges++; | ||
150 | } | ||
151 | |||
152 | alloc_size = sizeof(struct ieee80211_tx_latency_bin_ranges) + | ||
153 | n_ranges * sizeof(u32); | ||
154 | tx_latency = kzalloc(alloc_size, GFP_ATOMIC); | ||
155 | if (!tx_latency) { | ||
156 | ret = -ENOMEM; | ||
157 | goto unlock; | ||
158 | } | ||
159 | tx_latency->n_ranges = n_ranges; | ||
160 | for (i = 0; i < n_ranges; i++) { /* setting bin ranges */ | ||
161 | token = strsep(&bins, TX_LATENCY_BIN_DELIMTER_S); | ||
162 | sscanf(token, "%d", &tx_latency->ranges[i]); | ||
163 | /* bins values should be in ascending order */ | ||
164 | if (prev_bin >= tx_latency->ranges[i]) { | ||
165 | ret = -EINVAL; | ||
166 | kfree(tx_latency); | ||
167 | goto unlock; | ||
168 | } | ||
169 | prev_bin = tx_latency->ranges[i]; | ||
170 | } | ||
171 | rcu_assign_pointer(local->tx_latency, tx_latency); | ||
172 | |||
173 | unlock: | ||
174 | mutex_unlock(&local->sta_mtx); | ||
175 | |||
176 | return ret; | ||
177 | } | ||
178 | |||
179 | static const struct file_operations stats_tx_latency_ops = { | ||
180 | .write = sta_tx_latency_stat_write, | ||
181 | .read = sta_tx_latency_stat_read, | ||
182 | .open = simple_open, | ||
183 | .llseek = generic_file_llseek, | ||
184 | }; | ||
185 | |||
20 | int mac80211_format_buffer(char __user *userbuf, size_t count, | 186 | int mac80211_format_buffer(char __user *userbuf, size_t count, |
21 | loff_t *ppos, char *fmt, ...) | 187 | loff_t *ppos, char *fmt, ...) |
22 | { | 188 | { |
@@ -315,4 +481,6 @@ void debugfs_hw_add(struct ieee80211_local *local) | |||
315 | DEBUGFS_DEVSTATS_ADD(dot11RTSFailureCount); | 481 | DEBUGFS_DEVSTATS_ADD(dot11RTSFailureCount); |
316 | DEBUGFS_DEVSTATS_ADD(dot11FCSErrorCount); | 482 | DEBUGFS_DEVSTATS_ADD(dot11FCSErrorCount); |
317 | DEBUGFS_DEVSTATS_ADD(dot11RTSSuccessCount); | 483 | DEBUGFS_DEVSTATS_ADD(dot11RTSSuccessCount); |
484 | |||
485 | DEBUGFS_DEVSTATS_ADD(tx_latency); | ||
318 | } | 486 | } |