blob: c10cec5650c6abf1808c739eb8913c2ce2fb66ee [file] [log] [blame]
Sujith88b126a2008-11-28 22:19:02 +05301/*
Sujith Manoharan5b681382011-05-17 13:36:18 +05302 * Copyright (c) 2008-2011 Atheros Communications Inc.
Sujith88b126a2008-11-28 22:19:02 +05303 *
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.
7 *
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.
15 */
16
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090017#include <linux/slab.h>
Vasanthakumar Thiagarajan582d0062011-03-01 05:30:55 -080018#include <linux/vmalloc.h>
Paul Gortmakeree40fa02011-05-27 16:14:23 -040019#include <linux/export.h>
Simon Wunderliche93d0832013-01-08 14:48:58 +010020#include <linux/relay.h>
Gabor Juhos52103112009-03-06 09:57:39 +010021#include <asm/unaligned.h>
22
Sujith394cf0a2009-02-09 13:26:54 +053023#include "ath9k.h"
Sujith88b126a2008-11-28 22:19:02 +053024
Luis R. Rodriguez475a6e42009-09-23 23:06:59 -040025#define REG_WRITE_D(_ah, _reg, _val) \
26 ath9k_hw_common(_ah)->ops->write((_ah), (_val), (_reg))
27#define REG_READ_D(_ah, _reg) \
28 ath9k_hw_common(_ah)->ops->read((_ah), (_reg))
29
Sujith2a163c62008-11-28 22:21:08 +053030
Vasanthakumar Thiagarajan582d0062011-03-01 05:30:55 -080031static ssize_t ath9k_debugfs_read_buf(struct file *file, char __user *user_buf,
32 size_t count, loff_t *ppos)
33{
34 u8 *buf = file->private_data;
35 return simple_read_from_buffer(user_buf, count, ppos, buf, strlen(buf));
36}
37
38static int ath9k_debugfs_release_buf(struct inode *inode, struct file *file)
39{
40 vfree(file->private_data);
41 return 0;
42}
43
Felix Fietkaua830df02009-11-23 22:33:27 +010044#ifdef CONFIG_ATH_DEBUG
45
Jeff Hansen24939282009-05-27 12:48:29 +000046static ssize_t read_file_debug(struct file *file, char __user *user_buf,
47 size_t count, loff_t *ppos)
48{
49 struct ath_softc *sc = file->private_data;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -070050 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Jeff Hansen24939282009-05-27 12:48:29 +000051 char buf[32];
Vasanthakumar Thiagarajan581f7252009-06-02 19:28:55 +053052 unsigned int len;
53
Dan Carpenter2b87f3a2010-05-14 15:24:37 +020054 len = sprintf(buf, "0x%08x\n", common->debug_mask);
Jeff Hansen24939282009-05-27 12:48:29 +000055 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
56}
57
58static ssize_t write_file_debug(struct file *file, const char __user *user_buf,
59 size_t count, loff_t *ppos)
60{
61 struct ath_softc *sc = file->private_data;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -070062 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Jeff Hansen24939282009-05-27 12:48:29 +000063 unsigned long mask;
64 char buf[32];
Vasanthakumar Thiagarajan581f7252009-06-02 19:28:55 +053065 ssize_t len;
66
67 len = min(count, sizeof(buf) - 1);
68 if (copy_from_user(buf, user_buf, len))
Dan Carpenter04236062010-05-14 15:25:39 +020069 return -EFAULT;
Vasanthakumar Thiagarajan581f7252009-06-02 19:28:55 +053070
71 buf[len] = '\0';
Jingoo Han27d7f472013-05-31 21:24:06 +000072 if (kstrtoul(buf, 0, &mask))
Vasanthakumar Thiagarajan581f7252009-06-02 19:28:55 +053073 return -EINVAL;
74
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -070075 common->debug_mask = mask;
Jeff Hansen24939282009-05-27 12:48:29 +000076 return count;
77}
78
79static const struct file_operations fops_debug = {
80 .read = read_file_debug,
81 .write = write_file_debug,
Stephen Boyd234e3402012-04-05 14:25:11 -070082 .open = simple_open,
Arnd Bergmann6038f372010-08-15 18:52:59 +020083 .owner = THIS_MODULE,
84 .llseek = default_llseek,
Jeff Hansen24939282009-05-27 12:48:29 +000085};
86
Felix Fietkaua830df02009-11-23 22:33:27 +010087#endif
88
Pavel Roskin991a0982010-01-29 17:22:26 -050089#define DMA_BUF_LEN 1024
90
Felix Fietkau15340692010-05-11 17:23:01 +020091static ssize_t read_file_tx_chainmask(struct file *file, char __user *user_buf,
92 size_t count, loff_t *ppos)
93{
94 struct ath_softc *sc = file->private_data;
Felix Fietkau82b2d332011-09-03 01:40:23 +020095 struct ath_hw *ah = sc->sc_ah;
Felix Fietkau15340692010-05-11 17:23:01 +020096 char buf[32];
97 unsigned int len;
98
Felix Fietkau82b2d332011-09-03 01:40:23 +020099 len = sprintf(buf, "0x%08x\n", ah->txchainmask);
Felix Fietkau15340692010-05-11 17:23:01 +0200100 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
101}
102
103static ssize_t write_file_tx_chainmask(struct file *file, const char __user *user_buf,
104 size_t count, loff_t *ppos)
105{
106 struct ath_softc *sc = file->private_data;
Felix Fietkau82b2d332011-09-03 01:40:23 +0200107 struct ath_hw *ah = sc->sc_ah;
Felix Fietkau15340692010-05-11 17:23:01 +0200108 unsigned long mask;
109 char buf[32];
110 ssize_t len;
111
112 len = min(count, sizeof(buf) - 1);
113 if (copy_from_user(buf, user_buf, len))
Dan Carpenter04236062010-05-14 15:25:39 +0200114 return -EFAULT;
Felix Fietkau15340692010-05-11 17:23:01 +0200115
116 buf[len] = '\0';
Jingoo Han27d7f472013-05-31 21:24:06 +0000117 if (kstrtoul(buf, 0, &mask))
Felix Fietkau15340692010-05-11 17:23:01 +0200118 return -EINVAL;
119
Felix Fietkau82b2d332011-09-03 01:40:23 +0200120 ah->txchainmask = mask;
121 ah->caps.tx_chainmask = mask;
Felix Fietkau15340692010-05-11 17:23:01 +0200122 return count;
123}
124
125static const struct file_operations fops_tx_chainmask = {
126 .read = read_file_tx_chainmask,
127 .write = write_file_tx_chainmask,
Stephen Boyd234e3402012-04-05 14:25:11 -0700128 .open = simple_open,
Arnd Bergmann6038f372010-08-15 18:52:59 +0200129 .owner = THIS_MODULE,
130 .llseek = default_llseek,
Felix Fietkau15340692010-05-11 17:23:01 +0200131};
132
133
134static ssize_t read_file_rx_chainmask(struct file *file, char __user *user_buf,
135 size_t count, loff_t *ppos)
136{
137 struct ath_softc *sc = file->private_data;
Felix Fietkau82b2d332011-09-03 01:40:23 +0200138 struct ath_hw *ah = sc->sc_ah;
Felix Fietkau15340692010-05-11 17:23:01 +0200139 char buf[32];
140 unsigned int len;
141
Felix Fietkau82b2d332011-09-03 01:40:23 +0200142 len = sprintf(buf, "0x%08x\n", ah->rxchainmask);
Felix Fietkau15340692010-05-11 17:23:01 +0200143 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
144}
145
146static ssize_t write_file_rx_chainmask(struct file *file, const char __user *user_buf,
147 size_t count, loff_t *ppos)
148{
149 struct ath_softc *sc = file->private_data;
Felix Fietkau82b2d332011-09-03 01:40:23 +0200150 struct ath_hw *ah = sc->sc_ah;
Felix Fietkau15340692010-05-11 17:23:01 +0200151 unsigned long mask;
152 char buf[32];
153 ssize_t len;
154
155 len = min(count, sizeof(buf) - 1);
156 if (copy_from_user(buf, user_buf, len))
Dan Carpenter04236062010-05-14 15:25:39 +0200157 return -EFAULT;
Felix Fietkau15340692010-05-11 17:23:01 +0200158
159 buf[len] = '\0';
Jingoo Han27d7f472013-05-31 21:24:06 +0000160 if (kstrtoul(buf, 0, &mask))
Felix Fietkau15340692010-05-11 17:23:01 +0200161 return -EINVAL;
162
Felix Fietkau82b2d332011-09-03 01:40:23 +0200163 ah->rxchainmask = mask;
164 ah->caps.rx_chainmask = mask;
Felix Fietkau15340692010-05-11 17:23:01 +0200165 return count;
166}
167
168static const struct file_operations fops_rx_chainmask = {
169 .read = read_file_rx_chainmask,
170 .write = write_file_rx_chainmask,
Stephen Boyd234e3402012-04-05 14:25:11 -0700171 .open = simple_open,
Arnd Bergmann6038f372010-08-15 18:52:59 +0200172 .owner = THIS_MODULE,
173 .llseek = default_llseek,
Felix Fietkau15340692010-05-11 17:23:01 +0200174};
175
Sujith Manoharan6e4d2912013-06-03 09:19:28 +0530176static ssize_t read_file_ani(struct file *file, char __user *user_buf,
Mohammed Shafi Shajakhan05c0be22011-05-26 10:56:15 +0530177 size_t count, loff_t *ppos)
178{
179 struct ath_softc *sc = file->private_data;
180 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Sujith Manoharan6e4d2912013-06-03 09:19:28 +0530181 struct ath_hw *ah = sc->sc_ah;
182 unsigned int len = 0, size = 1024;
183 ssize_t retval = 0;
184 char *buf;
Mohammed Shafi Shajakhan05c0be22011-05-26 10:56:15 +0530185
Sujith Manoharan6e4d2912013-06-03 09:19:28 +0530186 buf = kzalloc(size, GFP_KERNEL);
187 if (buf == NULL)
188 return -ENOMEM;
189
190 if (common->disable_ani) {
191 len += snprintf(buf + len, size - len, "%s: %s\n",
192 "ANI", "DISABLED");
193 goto exit;
194 }
195
196 len += snprintf(buf + len, size - len, "%15s: %s\n",
197 "ANI", "ENABLED");
198 len += snprintf(buf + len, size - len, "%15s: %u\n",
199 "ANI RESET", ah->stats.ast_ani_reset);
200 len += snprintf(buf + len, size - len, "%15s: %u\n",
201 "SPUR UP", ah->stats.ast_ani_spurup);
202 len += snprintf(buf + len, size - len, "%15s: %u\n",
203 "SPUR DOWN", ah->stats.ast_ani_spurup);
204 len += snprintf(buf + len, size - len, "%15s: %u\n",
205 "OFDM WS-DET ON", ah->stats.ast_ani_ofdmon);
206 len += snprintf(buf + len, size - len, "%15s: %u\n",
207 "OFDM WS-DET OFF", ah->stats.ast_ani_ofdmoff);
208 len += snprintf(buf + len, size - len, "%15s: %u\n",
209 "MRC-CCK ON", ah->stats.ast_ani_ccklow);
210 len += snprintf(buf + len, size - len, "%15s: %u\n",
211 "MRC-CCK OFF", ah->stats.ast_ani_cckhigh);
212 len += snprintf(buf + len, size - len, "%15s: %u\n",
213 "FIR-STEP UP", ah->stats.ast_ani_stepup);
214 len += snprintf(buf + len, size - len, "%15s: %u\n",
215 "FIR-STEP DOWN", ah->stats.ast_ani_stepdown);
216 len += snprintf(buf + len, size - len, "%15s: %u\n",
217 "INV LISTENTIME", ah->stats.ast_ani_lneg_or_lzero);
218 len += snprintf(buf + len, size - len, "%15s: %u\n",
219 "OFDM ERRORS", ah->stats.ast_ani_ofdmerrs);
220 len += snprintf(buf + len, size - len, "%15s: %u\n",
221 "CCK ERRORS", ah->stats.ast_ani_cckerrs);
222exit:
223 if (len > size)
224 len = size;
225
226 retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
227 kfree(buf);
228
229 return retval;
Mohammed Shafi Shajakhan05c0be22011-05-26 10:56:15 +0530230}
231
Sujith Manoharan6e4d2912013-06-03 09:19:28 +0530232static ssize_t write_file_ani(struct file *file,
233 const char __user *user_buf,
234 size_t count, loff_t *ppos)
Mohammed Shafi Shajakhan05c0be22011-05-26 10:56:15 +0530235{
236 struct ath_softc *sc = file->private_data;
237 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Sujith Manoharan6e4d2912013-06-03 09:19:28 +0530238 unsigned long ani;
Mohammed Shafi Shajakhan05c0be22011-05-26 10:56:15 +0530239 char buf[32];
240 ssize_t len;
241
242 len = min(count, sizeof(buf) - 1);
243 if (copy_from_user(buf, user_buf, len))
244 return -EFAULT;
245
246 buf[len] = '\0';
John W. Linville3899ba92013-06-11 14:48:32 -0400247 if (kstrtoul(buf, 0, &ani))
Mohammed Shafi Shajakhan05c0be22011-05-26 10:56:15 +0530248 return -EINVAL;
249
Sujith Manoharan6e4d2912013-06-03 09:19:28 +0530250 if (ani < 0 || ani > 1)
251 return -EINVAL;
Mohammed Shafi Shajakhan05c0be22011-05-26 10:56:15 +0530252
Sujith Manoharan6e4d2912013-06-03 09:19:28 +0530253 common->disable_ani = !ani;
254
255 if (common->disable_ani) {
Sujith Manoharan781b14a2012-06-04 20:23:55 +0530256 clear_bit(SC_OP_ANI_RUN, &sc->sc_flags);
Sujith Manoharanda0d45f2012-07-17 17:16:29 +0530257 ath_stop_ani(sc);
Mohammed Shafi Shajakhan05c0be22011-05-26 10:56:15 +0530258 } else {
Sujith Manoharanda0d45f2012-07-17 17:16:29 +0530259 ath_check_ani(sc);
Mohammed Shafi Shajakhan05c0be22011-05-26 10:56:15 +0530260 }
261
262 return count;
263}
264
Sujith Manoharan6e4d2912013-06-03 09:19:28 +0530265static const struct file_operations fops_ani = {
266 .read = read_file_ani,
267 .write = write_file_ani,
Stephen Boyd234e3402012-04-05 14:25:11 -0700268 .open = simple_open,
Mohammed Shafi Shajakhan05c0be22011-05-26 10:56:15 +0530269 .owner = THIS_MODULE,
270 .llseek = default_llseek,
271};
Felix Fietkau15340692010-05-11 17:23:01 +0200272
Sujith Manoharan36e88252013-08-06 12:44:15 +0530273#ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
274
Sujith Manoharan63081302013-08-04 14:21:55 +0530275static ssize_t read_file_bt_ant_diversity(struct file *file,
276 char __user *user_buf,
277 size_t count, loff_t *ppos)
Sujith Manoharan302a3c32012-09-26 07:55:18 +0530278{
279 struct ath_softc *sc = file->private_data;
280 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
281 char buf[32];
282 unsigned int len;
283
Sujith Manoharan63081302013-08-04 14:21:55 +0530284 len = sprintf(buf, "%d\n", common->bt_ant_diversity);
Sujith Manoharan302a3c32012-09-26 07:55:18 +0530285 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
286}
287
Sujith Manoharan63081302013-08-04 14:21:55 +0530288static ssize_t write_file_bt_ant_diversity(struct file *file,
289 const char __user *user_buf,
290 size_t count, loff_t *ppos)
Sujith Manoharan302a3c32012-09-26 07:55:18 +0530291{
292 struct ath_softc *sc = file->private_data;
293 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Sujith Manoharan3f2da952013-08-04 14:21:56 +0530294 struct ath9k_hw_capabilities *pCap = &sc->sc_ah->caps;
Sujith Manoharan63081302013-08-04 14:21:55 +0530295 unsigned long bt_ant_diversity;
Sujith Manoharan302a3c32012-09-26 07:55:18 +0530296 char buf[32];
297 ssize_t len;
298
299 len = min(count, sizeof(buf) - 1);
300 if (copy_from_user(buf, user_buf, len))
301 return -EFAULT;
302
Sujith Manoharan3f2da952013-08-04 14:21:56 +0530303 if (!(pCap->hw_caps & ATH9K_HW_CAP_BT_ANT_DIV))
304 goto exit;
305
Sujith Manoharan302a3c32012-09-26 07:55:18 +0530306 buf[len] = '\0';
Sujith Manoharan63081302013-08-04 14:21:55 +0530307 if (kstrtoul(buf, 0, &bt_ant_diversity))
Sujith Manoharan302a3c32012-09-26 07:55:18 +0530308 return -EINVAL;
309
Sujith Manoharan63081302013-08-04 14:21:55 +0530310 common->bt_ant_diversity = !!bt_ant_diversity;
Sujith Manoharan302a3c32012-09-26 07:55:18 +0530311 ath9k_ps_wakeup(sc);
Sujith Manoharan047dc3a2013-08-05 15:08:26 +0530312 ath9k_hw_set_bt_ant_diversity(sc->sc_ah, common->bt_ant_diversity);
Sujith Manoharan63081302013-08-04 14:21:55 +0530313 ath_dbg(common, CONFIG, "Enable WLAN/BT RX Antenna diversity: %d\n",
314 common->bt_ant_diversity);
Sujith Manoharan302a3c32012-09-26 07:55:18 +0530315 ath9k_ps_restore(sc);
Sujith Manoharan3f2da952013-08-04 14:21:56 +0530316exit:
Sujith Manoharan302a3c32012-09-26 07:55:18 +0530317 return count;
318}
319
Sujith Manoharan63081302013-08-04 14:21:55 +0530320static const struct file_operations fops_bt_ant_diversity = {
321 .read = read_file_bt_ant_diversity,
322 .write = write_file_bt_ant_diversity,
Sujith Manoharan302a3c32012-09-26 07:55:18 +0530323 .open = simple_open,
324 .owner = THIS_MODULE,
325 .llseek = default_llseek,
326};
327
Sujith Manoharan36e88252013-08-06 12:44:15 +0530328#endif
329
Sujith Manoharane3d52912013-08-01 20:57:06 +0530330void ath9k_debug_stat_ant(struct ath_softc *sc,
331 struct ath_hw_antcomb_conf *div_ant_conf,
332 int main_rssi_avg, int alt_rssi_avg)
333{
334 struct ath_antenna_stats *as_main = &sc->debug.stats.ant_stats[ANT_MAIN];
335 struct ath_antenna_stats *as_alt = &sc->debug.stats.ant_stats[ANT_ALT];
336
337 as_main->lna_attempt_cnt[div_ant_conf->main_lna_conf]++;
338 as_alt->lna_attempt_cnt[div_ant_conf->alt_lna_conf]++;
339
340 as_main->rssi_avg = main_rssi_avg;
341 as_alt->rssi_avg = alt_rssi_avg;
342}
343
Sujith Manoharan4eba10c2013-07-29 16:04:49 +0530344static ssize_t read_file_antenna_diversity(struct file *file,
345 char __user *user_buf,
346 size_t count, loff_t *ppos)
347{
348 struct ath_softc *sc = file->private_data;
349 struct ath_hw *ah = sc->sc_ah;
350 struct ath9k_hw_capabilities *pCap = &ah->caps;
351 struct ath_antenna_stats *as_main = &sc->debug.stats.ant_stats[ANT_MAIN];
352 struct ath_antenna_stats *as_alt = &sc->debug.stats.ant_stats[ANT_ALT];
Sujith Manoharane3d52912013-08-01 20:57:06 +0530353 struct ath_hw_antcomb_conf div_ant_conf;
Sujith Manoharan4eba10c2013-07-29 16:04:49 +0530354 unsigned int len = 0, size = 1024;
355 ssize_t retval = 0;
356 char *buf;
Sujith Manoharane3d52912013-08-01 20:57:06 +0530357 char *lna_conf_str[4] = {"LNA1_MINUS_LNA2",
358 "LNA2",
359 "LNA1",
360 "LNA1_PLUS_LNA2"};
Sujith Manoharan4eba10c2013-07-29 16:04:49 +0530361
362 buf = kzalloc(size, GFP_KERNEL);
363 if (buf == NULL)
364 return -ENOMEM;
365
366 if (!(pCap->hw_caps & ATH9K_HW_CAP_ANT_DIV_COMB)) {
367 len += snprintf(buf + len, size - len, "%s\n",
368 "Antenna Diversity Combining is disabled");
369 goto exit;
370 }
371
Sujith Manoharane3d52912013-08-01 20:57:06 +0530372 ath9k_ps_wakeup(sc);
373 ath9k_hw_antdiv_comb_conf_get(ah, &div_ant_conf);
374 len += snprintf(buf + len, size - len, "Current MAIN config : %s\n",
375 lna_conf_str[div_ant_conf.main_lna_conf]);
376 len += snprintf(buf + len, size - len, "Current ALT config : %s\n",
377 lna_conf_str[div_ant_conf.alt_lna_conf]);
378 len += snprintf(buf + len, size - len, "Average MAIN RSSI : %d\n",
379 as_main->rssi_avg);
380 len += snprintf(buf + len, size - len, "Average ALT RSSI : %d\n\n",
381 as_alt->rssi_avg);
382 ath9k_ps_restore(sc);
383
384 len += snprintf(buf + len, size - len, "Packet Receive Cnt:\n");
385 len += snprintf(buf + len, size - len, "-------------------\n");
386
Sujith Manoharan4eba10c2013-07-29 16:04:49 +0530387 len += snprintf(buf + len, size - len, "%30s%15s\n",
388 "MAIN", "ALT");
Sujith Manoharane3d52912013-08-01 20:57:06 +0530389 len += snprintf(buf + len, size - len, "%-14s:%15d%15d\n",
390 "TOTAL COUNT",
Sujith Manoharan4eba10c2013-07-29 16:04:49 +0530391 as_main->recv_cnt,
392 as_alt->recv_cnt);
Sujith Manoharane3d52912013-08-01 20:57:06 +0530393 len += snprintf(buf + len, size - len, "%-14s:%15d%15d\n",
Sujith Manoharan4eba10c2013-07-29 16:04:49 +0530394 "LNA1",
Sujith Manoharane3d52912013-08-01 20:57:06 +0530395 as_main->lna_recv_cnt[ATH_ANT_DIV_COMB_LNA1],
396 as_alt->lna_recv_cnt[ATH_ANT_DIV_COMB_LNA1]);
397 len += snprintf(buf + len, size - len, "%-14s:%15d%15d\n",
Sujith Manoharan4eba10c2013-07-29 16:04:49 +0530398 "LNA2",
Sujith Manoharane3d52912013-08-01 20:57:06 +0530399 as_main->lna_recv_cnt[ATH_ANT_DIV_COMB_LNA2],
400 as_alt->lna_recv_cnt[ATH_ANT_DIV_COMB_LNA2]);
401 len += snprintf(buf + len, size - len, "%-14s:%15d%15d\n",
Sujith Manoharan4eba10c2013-07-29 16:04:49 +0530402 "LNA1 + LNA2",
Sujith Manoharane3d52912013-08-01 20:57:06 +0530403 as_main->lna_recv_cnt[ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2],
404 as_alt->lna_recv_cnt[ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2]);
405 len += snprintf(buf + len, size - len, "%-14s:%15d%15d\n",
Sujith Manoharan4eba10c2013-07-29 16:04:49 +0530406 "LNA1 - LNA2",
Sujith Manoharane3d52912013-08-01 20:57:06 +0530407 as_main->lna_recv_cnt[ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2],
408 as_alt->lna_recv_cnt[ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2]);
409
410 len += snprintf(buf + len, size - len, "\nLNA Config Attempts:\n");
411 len += snprintf(buf + len, size - len, "--------------------\n");
412
413 len += snprintf(buf + len, size - len, "%30s%15s\n",
414 "MAIN", "ALT");
415 len += snprintf(buf + len, size - len, "%-14s:%15d%15d\n",
416 "LNA1",
417 as_main->lna_attempt_cnt[ATH_ANT_DIV_COMB_LNA1],
418 as_alt->lna_attempt_cnt[ATH_ANT_DIV_COMB_LNA1]);
419 len += snprintf(buf + len, size - len, "%-14s:%15d%15d\n",
420 "LNA2",
421 as_main->lna_attempt_cnt[ATH_ANT_DIV_COMB_LNA2],
422 as_alt->lna_attempt_cnt[ATH_ANT_DIV_COMB_LNA2]);
423 len += snprintf(buf + len, size - len, "%-14s:%15d%15d\n",
424 "LNA1 + LNA2",
425 as_main->lna_attempt_cnt[ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2],
426 as_alt->lna_attempt_cnt[ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2]);
427 len += snprintf(buf + len, size - len, "%-14s:%15d%15d\n",
428 "LNA1 - LNA2",
429 as_main->lna_attempt_cnt[ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2],
430 as_alt->lna_attempt_cnt[ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2]);
431
Sujith Manoharan4eba10c2013-07-29 16:04:49 +0530432exit:
433 if (len > size)
434 len = size;
435
436 retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
437 kfree(buf);
438
439 return retval;
440}
441
442static const struct file_operations fops_antenna_diversity = {
443 .read = read_file_antenna_diversity,
444 .open = simple_open,
445 .owner = THIS_MODULE,
446 .llseek = default_llseek,
447};
448
Sujith2a163c62008-11-28 22:21:08 +0530449static ssize_t read_file_dma(struct file *file, char __user *user_buf,
450 size_t count, loff_t *ppos)
451{
452 struct ath_softc *sc = file->private_data;
Sujithcbe61d82009-02-09 13:27:12 +0530453 struct ath_hw *ah = sc->sc_ah;
Pavel Roskin991a0982010-01-29 17:22:26 -0500454 char *buf;
455 int retval;
Sujith2a163c62008-11-28 22:21:08 +0530456 unsigned int len = 0;
457 u32 val[ATH9K_NUM_DMA_DEBUG_REGS];
458 int i, qcuOffset = 0, dcuOffset = 0;
459 u32 *qcuBase = &val[0], *dcuBase = &val[4];
460
Pavel Roskin991a0982010-01-29 17:22:26 -0500461 buf = kmalloc(DMA_BUF_LEN, GFP_KERNEL);
462 if (!buf)
Dan Carpenter04236062010-05-14 15:25:39 +0200463 return -ENOMEM;
Pavel Roskin991a0982010-01-29 17:22:26 -0500464
Sujith7cf4a2e2009-08-26 11:11:57 +0530465 ath9k_ps_wakeup(sc);
466
Luis R. Rodriguez475a6e42009-09-23 23:06:59 -0400467 REG_WRITE_D(ah, AR_MACMISC,
Sujith2a163c62008-11-28 22:21:08 +0530468 ((AR_MACMISC_DMA_OBS_LINE_8 << AR_MACMISC_DMA_OBS_S) |
469 (AR_MACMISC_MISC_OBS_BUS_1 <<
470 AR_MACMISC_MISC_OBS_BUS_MSB_S)));
471
Pavel Roskin991a0982010-01-29 17:22:26 -0500472 len += snprintf(buf + len, DMA_BUF_LEN - len,
Sujith2a163c62008-11-28 22:21:08 +0530473 "Raw DMA Debug values:\n");
474
475 for (i = 0; i < ATH9K_NUM_DMA_DEBUG_REGS; i++) {
476 if (i % 4 == 0)
Pavel Roskin991a0982010-01-29 17:22:26 -0500477 len += snprintf(buf + len, DMA_BUF_LEN - len, "\n");
Sujith2a163c62008-11-28 22:21:08 +0530478
Luis R. Rodriguez475a6e42009-09-23 23:06:59 -0400479 val[i] = REG_READ_D(ah, AR_DMADBG_0 + (i * sizeof(u32)));
Pavel Roskin991a0982010-01-29 17:22:26 -0500480 len += snprintf(buf + len, DMA_BUF_LEN - len, "%d: %08x ",
Sujith2a163c62008-11-28 22:21:08 +0530481 i, val[i]);
482 }
483
Pavel Roskin991a0982010-01-29 17:22:26 -0500484 len += snprintf(buf + len, DMA_BUF_LEN - len, "\n\n");
485 len += snprintf(buf + len, DMA_BUF_LEN - len,
Sujith2a163c62008-11-28 22:21:08 +0530486 "Num QCU: chain_st fsp_ok fsp_st DCU: chain_st\n");
487
488 for (i = 0; i < ATH9K_NUM_QUEUES; i++, qcuOffset += 4, dcuOffset += 5) {
489 if (i == 8) {
490 qcuOffset = 0;
491 qcuBase++;
492 }
493
494 if (i == 6) {
495 dcuOffset = 0;
496 dcuBase++;
497 }
498
Pavel Roskin991a0982010-01-29 17:22:26 -0500499 len += snprintf(buf + len, DMA_BUF_LEN - len,
Sujith2a163c62008-11-28 22:21:08 +0530500 "%2d %2x %1x %2x %2x\n",
501 i, (*qcuBase & (0x7 << qcuOffset)) >> qcuOffset,
502 (*qcuBase & (0x8 << qcuOffset)) >> (qcuOffset + 3),
503 val[2] & (0x7 << (i * 3)) >> (i * 3),
504 (*dcuBase & (0x1f << dcuOffset)) >> dcuOffset);
505 }
506
Pavel Roskin991a0982010-01-29 17:22:26 -0500507 len += snprintf(buf + len, DMA_BUF_LEN - len, "\n");
Sujith2a163c62008-11-28 22:21:08 +0530508
Pavel Roskin991a0982010-01-29 17:22:26 -0500509 len += snprintf(buf + len, DMA_BUF_LEN - len,
Sujith2a163c62008-11-28 22:21:08 +0530510 "qcu_stitch state: %2x qcu_fetch state: %2x\n",
511 (val[3] & 0x003c0000) >> 18, (val[3] & 0x03c00000) >> 22);
Pavel Roskin991a0982010-01-29 17:22:26 -0500512 len += snprintf(buf + len, DMA_BUF_LEN - len,
Sujith2a163c62008-11-28 22:21:08 +0530513 "qcu_complete state: %2x dcu_complete state: %2x\n",
514 (val[3] & 0x1c000000) >> 26, (val[6] & 0x3));
Pavel Roskin991a0982010-01-29 17:22:26 -0500515 len += snprintf(buf + len, DMA_BUF_LEN - len,
Sujith2a163c62008-11-28 22:21:08 +0530516 "dcu_arb state: %2x dcu_fp state: %2x\n",
517 (val[5] & 0x06000000) >> 25, (val[5] & 0x38000000) >> 27);
Pavel Roskin991a0982010-01-29 17:22:26 -0500518 len += snprintf(buf + len, DMA_BUF_LEN - len,
Sujith2a163c62008-11-28 22:21:08 +0530519 "chan_idle_dur: %3d chan_idle_dur_valid: %1d\n",
520 (val[6] & 0x000003fc) >> 2, (val[6] & 0x00000400) >> 10);
Pavel Roskin991a0982010-01-29 17:22:26 -0500521 len += snprintf(buf + len, DMA_BUF_LEN - len,
Sujith2a163c62008-11-28 22:21:08 +0530522 "txfifo_valid_0: %1d txfifo_valid_1: %1d\n",
523 (val[6] & 0x00000800) >> 11, (val[6] & 0x00001000) >> 12);
Pavel Roskin991a0982010-01-29 17:22:26 -0500524 len += snprintf(buf + len, DMA_BUF_LEN - len,
Sujith2a163c62008-11-28 22:21:08 +0530525 "txfifo_dcu_num_0: %2d txfifo_dcu_num_1: %2d\n",
526 (val[6] & 0x0001e000) >> 13, (val[6] & 0x001e0000) >> 17);
527
Frans Pop60ece402010-03-24 19:46:30 +0100528 len += snprintf(buf + len, DMA_BUF_LEN - len, "pcu observe: 0x%x\n",
Luis R. Rodriguez475a6e42009-09-23 23:06:59 -0400529 REG_READ_D(ah, AR_OBS_BUS_1));
Pavel Roskin991a0982010-01-29 17:22:26 -0500530 len += snprintf(buf + len, DMA_BUF_LEN - len,
Frans Pop60ece402010-03-24 19:46:30 +0100531 "AR_CR: 0x%x\n", REG_READ_D(ah, AR_CR));
Sujith2a163c62008-11-28 22:21:08 +0530532
Sujith7cf4a2e2009-08-26 11:11:57 +0530533 ath9k_ps_restore(sc);
534
Dan Carpenter2b87f3a2010-05-14 15:24:37 +0200535 if (len > DMA_BUF_LEN)
536 len = DMA_BUF_LEN;
537
Pavel Roskin991a0982010-01-29 17:22:26 -0500538 retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
539 kfree(buf);
540 return retval;
Sujith2a163c62008-11-28 22:21:08 +0530541}
542
543static const struct file_operations fops_dma = {
544 .read = read_file_dma,
Stephen Boyd234e3402012-04-05 14:25:11 -0700545 .open = simple_open,
Arnd Bergmann6038f372010-08-15 18:52:59 +0200546 .owner = THIS_MODULE,
547 .llseek = default_llseek,
Sujith2a163c62008-11-28 22:21:08 +0530548};
549
Sujith817e11d2008-12-07 21:42:44 +0530550
551void ath_debug_stat_interrupt(struct ath_softc *sc, enum ath9k_int status)
552{
553 if (status)
Sujith17d79042009-02-09 13:27:03 +0530554 sc->debug.stats.istats.total++;
Luis R. Rodrigueza9616f42010-04-15 17:39:30 -0400555 if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) {
556 if (status & ATH9K_INT_RXLP)
557 sc->debug.stats.istats.rxlp++;
558 if (status & ATH9K_INT_RXHP)
559 sc->debug.stats.istats.rxhp++;
Luis R. Rodriguez08578b82010-05-13 13:33:44 -0400560 if (status & ATH9K_INT_BB_WATCHDOG)
561 sc->debug.stats.istats.bb_watchdog++;
Luis R. Rodrigueza9616f42010-04-15 17:39:30 -0400562 } else {
563 if (status & ATH9K_INT_RX)
564 sc->debug.stats.istats.rxok++;
565 }
Sujith817e11d2008-12-07 21:42:44 +0530566 if (status & ATH9K_INT_RXEOL)
Sujith17d79042009-02-09 13:27:03 +0530567 sc->debug.stats.istats.rxeol++;
Sujith817e11d2008-12-07 21:42:44 +0530568 if (status & ATH9K_INT_RXORN)
Sujith17d79042009-02-09 13:27:03 +0530569 sc->debug.stats.istats.rxorn++;
Sujith817e11d2008-12-07 21:42:44 +0530570 if (status & ATH9K_INT_TX)
Sujith17d79042009-02-09 13:27:03 +0530571 sc->debug.stats.istats.txok++;
Sujith817e11d2008-12-07 21:42:44 +0530572 if (status & ATH9K_INT_TXURN)
Sujith17d79042009-02-09 13:27:03 +0530573 sc->debug.stats.istats.txurn++;
Sujith817e11d2008-12-07 21:42:44 +0530574 if (status & ATH9K_INT_RXPHY)
Sujith17d79042009-02-09 13:27:03 +0530575 sc->debug.stats.istats.rxphyerr++;
Sujith817e11d2008-12-07 21:42:44 +0530576 if (status & ATH9K_INT_RXKCM)
Sujith17d79042009-02-09 13:27:03 +0530577 sc->debug.stats.istats.rx_keycache_miss++;
Sujith817e11d2008-12-07 21:42:44 +0530578 if (status & ATH9K_INT_SWBA)
Sujith17d79042009-02-09 13:27:03 +0530579 sc->debug.stats.istats.swba++;
Sujith817e11d2008-12-07 21:42:44 +0530580 if (status & ATH9K_INT_BMISS)
Sujith17d79042009-02-09 13:27:03 +0530581 sc->debug.stats.istats.bmiss++;
Sujith817e11d2008-12-07 21:42:44 +0530582 if (status & ATH9K_INT_BNR)
Sujith17d79042009-02-09 13:27:03 +0530583 sc->debug.stats.istats.bnr++;
Sujith817e11d2008-12-07 21:42:44 +0530584 if (status & ATH9K_INT_CST)
Sujith17d79042009-02-09 13:27:03 +0530585 sc->debug.stats.istats.cst++;
Sujith817e11d2008-12-07 21:42:44 +0530586 if (status & ATH9K_INT_GTT)
Sujith17d79042009-02-09 13:27:03 +0530587 sc->debug.stats.istats.gtt++;
Sujith817e11d2008-12-07 21:42:44 +0530588 if (status & ATH9K_INT_TIM)
Sujith17d79042009-02-09 13:27:03 +0530589 sc->debug.stats.istats.tim++;
Sujith817e11d2008-12-07 21:42:44 +0530590 if (status & ATH9K_INT_CABEND)
Sujith17d79042009-02-09 13:27:03 +0530591 sc->debug.stats.istats.cabend++;
Sujith817e11d2008-12-07 21:42:44 +0530592 if (status & ATH9K_INT_DTIMSYNC)
Sujith17d79042009-02-09 13:27:03 +0530593 sc->debug.stats.istats.dtimsync++;
Sujith817e11d2008-12-07 21:42:44 +0530594 if (status & ATH9K_INT_DTIM)
Sujith17d79042009-02-09 13:27:03 +0530595 sc->debug.stats.istats.dtim++;
Mohammed Shafi Shajakhan6dde1aa2011-04-22 17:27:01 +0530596 if (status & ATH9K_INT_TSFOOR)
597 sc->debug.stats.istats.tsfoor++;
Sujith Manoharan97ba5152012-06-04 16:27:41 +0530598 if (status & ATH9K_INT_MCI)
599 sc->debug.stats.istats.mci++;
Mohammed Shafi Shajakhanc9e6e982012-09-07 15:54:13 +0530600 if (status & ATH9K_INT_GENTIMER)
601 sc->debug.stats.istats.gen_timer++;
Sujith817e11d2008-12-07 21:42:44 +0530602}
603
604static ssize_t read_file_interrupt(struct file *file, char __user *user_buf,
605 size_t count, loff_t *ppos)
606{
607 struct ath_softc *sc = file->private_data;
Sujith817e11d2008-12-07 21:42:44 +0530608 unsigned int len = 0;
Ben Greear462e58f2012-04-12 10:04:00 -0700609 int rv;
610 int mxlen = 4000;
611 char *buf = kmalloc(mxlen, GFP_KERNEL);
612 if (!buf)
613 return -ENOMEM;
614
615#define PR_IS(a, s) \
616 do { \
617 len += snprintf(buf + len, mxlen - len, \
618 "%21s: %10u\n", a, \
619 sc->debug.stats.istats.s); \
620 } while (0)
Sujith817e11d2008-12-07 21:42:44 +0530621
Luis R. Rodrigueza9616f42010-04-15 17:39:30 -0400622 if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) {
Ben Greear462e58f2012-04-12 10:04:00 -0700623 PR_IS("RXLP", rxlp);
624 PR_IS("RXHP", rxhp);
625 PR_IS("WATHDOG", bb_watchdog);
Luis R. Rodrigueza9616f42010-04-15 17:39:30 -0400626 } else {
Ben Greear462e58f2012-04-12 10:04:00 -0700627 PR_IS("RX", rxok);
Luis R. Rodrigueza9616f42010-04-15 17:39:30 -0400628 }
Ben Greear462e58f2012-04-12 10:04:00 -0700629 PR_IS("RXEOL", rxeol);
630 PR_IS("RXORN", rxorn);
631 PR_IS("TX", txok);
632 PR_IS("TXURN", txurn);
633 PR_IS("MIB", mib);
634 PR_IS("RXPHY", rxphyerr);
635 PR_IS("RXKCM", rx_keycache_miss);
636 PR_IS("SWBA", swba);
637 PR_IS("BMISS", bmiss);
638 PR_IS("BNR", bnr);
639 PR_IS("CST", cst);
640 PR_IS("GTT", gtt);
641 PR_IS("TIM", tim);
642 PR_IS("CABEND", cabend);
643 PR_IS("DTIMSYNC", dtimsync);
644 PR_IS("DTIM", dtim);
645 PR_IS("TSFOOR", tsfoor);
Sujith Manoharan97ba5152012-06-04 16:27:41 +0530646 PR_IS("MCI", mci);
Mohammed Shafi Shajakhanc9e6e982012-09-07 15:54:13 +0530647 PR_IS("GENTIMER", gen_timer);
Ben Greear462e58f2012-04-12 10:04:00 -0700648 PR_IS("TOTAL", total);
Sujith817e11d2008-12-07 21:42:44 +0530649
Ben Greear462e58f2012-04-12 10:04:00 -0700650 len += snprintf(buf + len, mxlen - len,
651 "SYNC_CAUSE stats:\n");
Mohammed Shafi Shajakhan6dde1aa2011-04-22 17:27:01 +0530652
Ben Greear462e58f2012-04-12 10:04:00 -0700653 PR_IS("Sync-All", sync_cause_all);
654 PR_IS("RTC-IRQ", sync_rtc_irq);
655 PR_IS("MAC-IRQ", sync_mac_irq);
656 PR_IS("EEPROM-Illegal-Access", eeprom_illegal_access);
657 PR_IS("APB-Timeout", apb_timeout);
658 PR_IS("PCI-Mode-Conflict", pci_mode_conflict);
659 PR_IS("HOST1-Fatal", host1_fatal);
660 PR_IS("HOST1-Perr", host1_perr);
661 PR_IS("TRCV-FIFO-Perr", trcv_fifo_perr);
662 PR_IS("RADM-CPL-EP", radm_cpl_ep);
663 PR_IS("RADM-CPL-DLLP-Abort", radm_cpl_dllp_abort);
664 PR_IS("RADM-CPL-TLP-Abort", radm_cpl_tlp_abort);
665 PR_IS("RADM-CPL-ECRC-Err", radm_cpl_ecrc_err);
666 PR_IS("RADM-CPL-Timeout", radm_cpl_timeout);
667 PR_IS("Local-Bus-Timeout", local_timeout);
668 PR_IS("PM-Access", pm_access);
669 PR_IS("MAC-Awake", mac_awake);
670 PR_IS("MAC-Asleep", mac_asleep);
671 PR_IS("MAC-Sleep-Access", mac_sleep_access);
Dan Carpenter2b87f3a2010-05-14 15:24:37 +0200672
Ben Greear462e58f2012-04-12 10:04:00 -0700673 if (len > mxlen)
674 len = mxlen;
675
676 rv = simple_read_from_buffer(user_buf, count, ppos, buf, len);
677 kfree(buf);
678 return rv;
Sujith817e11d2008-12-07 21:42:44 +0530679}
680
681static const struct file_operations fops_interrupt = {
682 .read = read_file_interrupt,
Stephen Boyd234e3402012-04-05 14:25:11 -0700683 .open = simple_open,
Arnd Bergmann6038f372010-08-15 18:52:59 +0200684 .owner = THIS_MODULE,
685 .llseek = default_llseek,
Sujith817e11d2008-12-07 21:42:44 +0530686};
687
Sujithfec247c2009-07-27 12:08:16 +0530688static ssize_t read_file_xmit(struct file *file, char __user *user_buf,
689 size_t count, loff_t *ppos)
690{
691 struct ath_softc *sc = file->private_data;
692 char *buf;
Sujith Manoharan78ef7312012-11-21 18:13:11 +0530693 unsigned int len = 0, size = 2048;
Sujithfec247c2009-07-27 12:08:16 +0530694 ssize_t retval = 0;
695
696 buf = kzalloc(size, GFP_KERNEL);
697 if (buf == NULL)
Dan Carpenter04236062010-05-14 15:25:39 +0200698 return -ENOMEM;
Sujithfec247c2009-07-27 12:08:16 +0530699
Sujith Manoharan78ef7312012-11-21 18:13:11 +0530700 len += sprintf(buf, "%30s %10s%10s%10s\n\n",
Ben Greear7f010c92011-01-09 23:11:49 -0800701 "BE", "BK", "VI", "VO");
Sujithfec247c2009-07-27 12:08:16 +0530702
703 PR("MPDUs Queued: ", queued);
704 PR("MPDUs Completed: ", completed);
Felix Fietkau5a6f78a2011-05-31 21:21:41 +0200705 PR("MPDUs XRetried: ", xretries);
Sujithfec247c2009-07-27 12:08:16 +0530706 PR("Aggregates: ", a_aggr);
Ben Greearbda8add2011-01-09 23:11:48 -0800707 PR("AMPDUs Queued HW:", a_queued_hw);
708 PR("AMPDUs Queued SW:", a_queued_sw);
Sujithfec247c2009-07-27 12:08:16 +0530709 PR("AMPDUs Completed:", a_completed);
710 PR("AMPDUs Retried: ", a_retries);
711 PR("AMPDUs XRetried: ", a_xretries);
Ben Greear4d900382013-03-04 15:31:16 -0800712 PR("TXERR Filtered: ", txerr_filtered);
Sujithfec247c2009-07-27 12:08:16 +0530713 PR("FIFO Underrun: ", fifo_underrun);
714 PR("TXOP Exceeded: ", xtxop);
715 PR("TXTIMER Expiry: ", timer_exp);
716 PR("DESC CFG Error: ", desc_cfg_err);
717 PR("DATA Underrun: ", data_underrun);
718 PR("DELIM Underrun: ", delim_underrun);
Ben Greear99c15bf2010-10-01 12:26:30 -0700719 PR("TX-Pkts-All: ", tx_pkts_all);
720 PR("TX-Bytes-All: ", tx_bytes_all);
Sujith Manoharan78ef7312012-11-21 18:13:11 +0530721 PR("HW-put-tx-buf: ", puttxbuf);
722 PR("HW-tx-start: ", txstart);
723 PR("HW-tx-proc-desc: ", txprocdesc);
Ben Greeara5a0bca2012-04-03 09:16:55 -0700724 PR("TX-Failed: ", txfailed);
Sujithfec247c2009-07-27 12:08:16 +0530725
Ben Greear7f010c92011-01-09 23:11:49 -0800726 if (len > size)
727 len = size;
728
729 retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
730 kfree(buf);
731
732 return retval;
733}
734
Felix Fietkau18fcf1c2013-08-06 14:18:05 +0200735static ssize_t print_queue(struct ath_softc *sc, struct ath_txq *txq,
736 char *buf, ssize_t size)
737{
738 ssize_t len = 0;
739
740 ath_txq_lock(sc, txq);
741
742 len += snprintf(buf + len, size - len, "%s: %d ",
743 "qnum", txq->axq_qnum);
744 len += snprintf(buf + len, size - len, "%s: %2d ",
745 "qdepth", txq->axq_depth);
746 len += snprintf(buf + len, size - len, "%s: %2d ",
747 "ampdu-depth", txq->axq_ampdu_depth);
748 len += snprintf(buf + len, size - len, "%s: %3d ",
749 "pending", txq->pending_frames);
750 len += snprintf(buf + len, size - len, "%s: %d\n",
751 "stopped", txq->stopped);
752
753 ath_txq_unlock(sc, txq);
754 return len;
755}
756
Sujith Manoharanc0b74872012-11-21 18:13:12 +0530757static ssize_t read_file_queues(struct file *file, char __user *user_buf,
758 size_t count, loff_t *ppos)
759{
760 struct ath_softc *sc = file->private_data;
761 struct ath_txq *txq;
762 char *buf;
763 unsigned int len = 0, size = 1024;
764 ssize_t retval = 0;
765 int i;
766 char *qname[4] = {"VO", "VI", "BE", "BK"};
767
768 buf = kzalloc(size, GFP_KERNEL);
769 if (buf == NULL)
770 return -ENOMEM;
771
772 for (i = 0; i < IEEE80211_NUM_ACS; i++) {
773 txq = sc->tx.txq_map[i];
Felix Fietkau18fcf1c2013-08-06 14:18:05 +0200774 len += snprintf(buf + len, size - len, "(%s): ", qname[i]);
775 len += print_queue(sc, txq, buf + len, size - len);
Sujith Manoharanc0b74872012-11-21 18:13:12 +0530776 }
777
Felix Fietkau18fcf1c2013-08-06 14:18:05 +0200778 len += snprintf(buf + len, size - len, "(CAB): ");
779 len += print_queue(sc, sc->beacon.cabq, buf + len, size - len);
780
Sujith Manoharanc0b74872012-11-21 18:13:12 +0530781 if (len > size)
782 len = size;
783
784 retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
785 kfree(buf);
786
787 return retval;
788}
789
Ben Greear55f6d0f2011-01-17 11:54:50 -0800790static ssize_t read_file_misc(struct file *file, char __user *user_buf,
791 size_t count, loff_t *ppos)
792{
793 struct ath_softc *sc = file->private_data;
794 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Ben Greear55f6d0f2011-01-17 11:54:50 -0800795 struct ieee80211_hw *hw = sc->hw;
Sujith Manoharan6bcf6f62012-02-16 11:51:02 +0530796 struct ath9k_vif_iter_data iter_data;
797 char buf[512];
798 unsigned int len = 0;
Ben Greear55f6d0f2011-01-17 11:54:50 -0800799 ssize_t retval = 0;
Ben Greear55f6d0f2011-01-17 11:54:50 -0800800 unsigned int reg;
Sujith Manoharan6bcf6f62012-02-16 11:51:02 +0530801 u32 rxfilter;
Ben Greear55f6d0f2011-01-17 11:54:50 -0800802
Sujith Manoharan6bcf6f62012-02-16 11:51:02 +0530803 len += snprintf(buf + len, sizeof(buf) - len,
804 "BSSID: %pM\n", common->curbssid);
805 len += snprintf(buf + len, sizeof(buf) - len,
806 "BSSID-MASK: %pM\n", common->bssidmask);
807 len += snprintf(buf + len, sizeof(buf) - len,
808 "OPMODE: %s\n", ath_opmode_to_string(sc->sc_ah->opmode));
Ben Greear55f6d0f2011-01-17 11:54:50 -0800809
Rajkumar Manoharan79d2b152011-05-16 18:23:23 +0530810 ath9k_ps_wakeup(sc);
Sujith Manoharan6bcf6f62012-02-16 11:51:02 +0530811 rxfilter = ath9k_hw_getrxfilter(sc->sc_ah);
Rajkumar Manoharan79d2b152011-05-16 18:23:23 +0530812 ath9k_ps_restore(sc);
Sujith Manoharan6bcf6f62012-02-16 11:51:02 +0530813
814 len += snprintf(buf + len, sizeof(buf) - len,
815 "RXFILTER: 0x%x", rxfilter);
816
817 if (rxfilter & ATH9K_RX_FILTER_UCAST)
818 len += snprintf(buf + len, sizeof(buf) - len, " UCAST");
819 if (rxfilter & ATH9K_RX_FILTER_MCAST)
820 len += snprintf(buf + len, sizeof(buf) - len, " MCAST");
821 if (rxfilter & ATH9K_RX_FILTER_BCAST)
822 len += snprintf(buf + len, sizeof(buf) - len, " BCAST");
823 if (rxfilter & ATH9K_RX_FILTER_CONTROL)
824 len += snprintf(buf + len, sizeof(buf) - len, " CONTROL");
825 if (rxfilter & ATH9K_RX_FILTER_BEACON)
826 len += snprintf(buf + len, sizeof(buf) - len, " BEACON");
827 if (rxfilter & ATH9K_RX_FILTER_PROM)
828 len += snprintf(buf + len, sizeof(buf) - len, " PROM");
829 if (rxfilter & ATH9K_RX_FILTER_PROBEREQ)
830 len += snprintf(buf + len, sizeof(buf) - len, " PROBEREQ");
831 if (rxfilter & ATH9K_RX_FILTER_PHYERR)
832 len += snprintf(buf + len, sizeof(buf) - len, " PHYERR");
833 if (rxfilter & ATH9K_RX_FILTER_MYBEACON)
834 len += snprintf(buf + len, sizeof(buf) - len, " MYBEACON");
835 if (rxfilter & ATH9K_RX_FILTER_COMP_BAR)
836 len += snprintf(buf + len, sizeof(buf) - len, " COMP_BAR");
837 if (rxfilter & ATH9K_RX_FILTER_PSPOLL)
838 len += snprintf(buf + len, sizeof(buf) - len, " PSPOLL");
839 if (rxfilter & ATH9K_RX_FILTER_PHYRADAR)
840 len += snprintf(buf + len, sizeof(buf) - len, " PHYRADAR");
841 if (rxfilter & ATH9K_RX_FILTER_MCAST_BCAST_ALL)
842 len += snprintf(buf + len, sizeof(buf) - len, " MCAST_BCAST_ALL");
843 if (rxfilter & ATH9K_RX_FILTER_CONTROL_WRAPPER)
844 len += snprintf(buf + len, sizeof(buf) - len, " CONTROL_WRAPPER");
845
846 len += snprintf(buf + len, sizeof(buf) - len, "\n");
Ben Greear55f6d0f2011-01-17 11:54:50 -0800847
848 reg = sc->sc_ah->imask;
Ben Greear55f6d0f2011-01-17 11:54:50 -0800849
Sujith Manoharan6bcf6f62012-02-16 11:51:02 +0530850 len += snprintf(buf + len, sizeof(buf) - len, "INTERRUPT-MASK: 0x%x", reg);
851
852 if (reg & ATH9K_INT_SWBA)
853 len += snprintf(buf + len, sizeof(buf) - len, " SWBA");
854 if (reg & ATH9K_INT_BMISS)
855 len += snprintf(buf + len, sizeof(buf) - len, " BMISS");
856 if (reg & ATH9K_INT_CST)
857 len += snprintf(buf + len, sizeof(buf) - len, " CST");
858 if (reg & ATH9K_INT_RX)
859 len += snprintf(buf + len, sizeof(buf) - len, " RX");
860 if (reg & ATH9K_INT_RXHP)
861 len += snprintf(buf + len, sizeof(buf) - len, " RXHP");
862 if (reg & ATH9K_INT_RXLP)
863 len += snprintf(buf + len, sizeof(buf) - len, " RXLP");
864 if (reg & ATH9K_INT_BB_WATCHDOG)
865 len += snprintf(buf + len, sizeof(buf) - len, " BB_WATCHDOG");
866
867 len += snprintf(buf + len, sizeof(buf) - len, "\n");
868
869 ath9k_calculate_iter_data(hw, NULL, &iter_data);
870
871 len += snprintf(buf + len, sizeof(buf) - len,
872 "VIF-COUNTS: AP: %i STA: %i MESH: %i WDS: %i"
Sujith Manoharanbcf6f962012-03-14 14:40:38 +0530873 " ADHOC: %i TOTAL: %hi BEACON-VIF: %hi\n",
Ben Greear55f6d0f2011-01-17 11:54:50 -0800874 iter_data.naps, iter_data.nstations, iter_data.nmeshes,
Sujith Manoharanbcf6f962012-03-14 14:40:38 +0530875 iter_data.nwds, iter_data.nadhocs,
Ben Greear55f6d0f2011-01-17 11:54:50 -0800876 sc->nvifs, sc->nbcnvifs);
877
Sujith Manoharan6bcf6f62012-02-16 11:51:02 +0530878 if (len > sizeof(buf))
879 len = sizeof(buf);
Ben Greear55f6d0f2011-01-17 11:54:50 -0800880
881 retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
Ben Greear55f6d0f2011-01-17 11:54:50 -0800882 return retval;
883}
884
Sujith Manoharanf8b815d2012-02-16 11:51:11 +0530885static ssize_t read_file_reset(struct file *file, char __user *user_buf,
886 size_t count, loff_t *ppos)
887{
888 struct ath_softc *sc = file->private_data;
889 char buf[512];
890 unsigned int len = 0;
891
892 len += snprintf(buf + len, sizeof(buf) - len,
893 "%17s: %2d\n", "Baseband Hang",
894 sc->debug.stats.reset[RESET_TYPE_BB_HANG]);
895 len += snprintf(buf + len, sizeof(buf) - len,
896 "%17s: %2d\n", "Baseband Watchdog",
897 sc->debug.stats.reset[RESET_TYPE_BB_WATCHDOG]);
898 len += snprintf(buf + len, sizeof(buf) - len,
899 "%17s: %2d\n", "Fatal HW Error",
900 sc->debug.stats.reset[RESET_TYPE_FATAL_INT]);
901 len += snprintf(buf + len, sizeof(buf) - len,
902 "%17s: %2d\n", "TX HW error",
903 sc->debug.stats.reset[RESET_TYPE_TX_ERROR]);
904 len += snprintf(buf + len, sizeof(buf) - len,
905 "%17s: %2d\n", "TX Path Hang",
906 sc->debug.stats.reset[RESET_TYPE_TX_HANG]);
907 len += snprintf(buf + len, sizeof(buf) - len,
908 "%17s: %2d\n", "PLL RX Hang",
909 sc->debug.stats.reset[RESET_TYPE_PLL_HANG]);
Rajkumar Manoharanb88083b2012-11-20 18:30:00 +0530910 len += snprintf(buf + len, sizeof(buf) - len,
911 "%17s: %2d\n", "MCI Reset",
912 sc->debug.stats.reset[RESET_TYPE_MCI]);
Sujith Manoharanf8b815d2012-02-16 11:51:11 +0530913
914 if (len > sizeof(buf))
915 len = sizeof(buf);
916
917 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
918}
919
Felix Fietkau066dae92010-11-07 14:59:39 +0100920void ath_debug_stat_tx(struct ath_softc *sc, struct ath_buf *bf,
Felix Fietkau55797b12011-09-14 21:24:16 +0200921 struct ath_tx_status *ts, struct ath_txq *txq,
922 unsigned int flags)
Sujithfec247c2009-07-27 12:08:16 +0530923{
Felix Fietkau5bec3e52011-01-24 21:29:25 +0100924 int qnum = txq->axq_qnum;
Felix Fietkau066dae92010-11-07 14:59:39 +0100925
926 TX_STAT_INC(qnum, tx_pkts_all);
927 sc->debug.stats.txstats[qnum].tx_bytes_all += bf->bf_mpdu->len;
Ben Greear99c15bf2010-10-01 12:26:30 -0700928
Sujithfec247c2009-07-27 12:08:16 +0530929 if (bf_isampdu(bf)) {
Felix Fietkau156369f2011-12-14 22:08:04 +0100930 if (flags & ATH_TX_ERROR)
Felix Fietkau066dae92010-11-07 14:59:39 +0100931 TX_STAT_INC(qnum, a_xretries);
Sujithfec247c2009-07-27 12:08:16 +0530932 else
Felix Fietkau066dae92010-11-07 14:59:39 +0100933 TX_STAT_INC(qnum, a_completed);
Sujithfec247c2009-07-27 12:08:16 +0530934 } else {
Felix Fietkau55797b12011-09-14 21:24:16 +0200935 if (ts->ts_status & ATH9K_TXERR_XRETRY)
Felix Fietkau5a6f78a2011-05-31 21:21:41 +0200936 TX_STAT_INC(qnum, xretries);
937 else
938 TX_STAT_INC(qnum, completed);
Sujithfec247c2009-07-27 12:08:16 +0530939 }
940
Ben Greear4d900382013-03-04 15:31:16 -0800941 if (ts->ts_status & ATH9K_TXERR_FILT)
942 TX_STAT_INC(qnum, txerr_filtered);
Felix Fietkaudb1a0522010-03-29 20:07:11 -0700943 if (ts->ts_status & ATH9K_TXERR_FIFO)
Felix Fietkau066dae92010-11-07 14:59:39 +0100944 TX_STAT_INC(qnum, fifo_underrun);
Felix Fietkaudb1a0522010-03-29 20:07:11 -0700945 if (ts->ts_status & ATH9K_TXERR_XTXOP)
Felix Fietkau066dae92010-11-07 14:59:39 +0100946 TX_STAT_INC(qnum, xtxop);
Felix Fietkaudb1a0522010-03-29 20:07:11 -0700947 if (ts->ts_status & ATH9K_TXERR_TIMER_EXPIRED)
Felix Fietkau066dae92010-11-07 14:59:39 +0100948 TX_STAT_INC(qnum, timer_exp);
Felix Fietkaudb1a0522010-03-29 20:07:11 -0700949 if (ts->ts_flags & ATH9K_TX_DESC_CFG_ERR)
Felix Fietkau066dae92010-11-07 14:59:39 +0100950 TX_STAT_INC(qnum, desc_cfg_err);
Felix Fietkaudb1a0522010-03-29 20:07:11 -0700951 if (ts->ts_flags & ATH9K_TX_DATA_UNDERRUN)
Felix Fietkau066dae92010-11-07 14:59:39 +0100952 TX_STAT_INC(qnum, data_underrun);
Felix Fietkaudb1a0522010-03-29 20:07:11 -0700953 if (ts->ts_flags & ATH9K_TX_DELIM_UNDERRUN)
Felix Fietkau066dae92010-11-07 14:59:39 +0100954 TX_STAT_INC(qnum, delim_underrun);
Sujithfec247c2009-07-27 12:08:16 +0530955}
956
957static const struct file_operations fops_xmit = {
958 .read = read_file_xmit,
Stephen Boyd234e3402012-04-05 14:25:11 -0700959 .open = simple_open,
Arnd Bergmann6038f372010-08-15 18:52:59 +0200960 .owner = THIS_MODULE,
961 .llseek = default_llseek,
Sujithfec247c2009-07-27 12:08:16 +0530962};
Jouni Malinen39d89cd2009-03-03 19:23:40 +0200963
Sujith Manoharanc0b74872012-11-21 18:13:12 +0530964static const struct file_operations fops_queues = {
965 .read = read_file_queues,
966 .open = simple_open,
967 .owner = THIS_MODULE,
968 .llseek = default_llseek,
969};
970
Ben Greear55f6d0f2011-01-17 11:54:50 -0800971static const struct file_operations fops_misc = {
972 .read = read_file_misc,
Stephen Boyd234e3402012-04-05 14:25:11 -0700973 .open = simple_open,
Ben Greear55f6d0f2011-01-17 11:54:50 -0800974 .owner = THIS_MODULE,
975 .llseek = default_llseek,
976};
977
Sujith Manoharanf8b815d2012-02-16 11:51:11 +0530978static const struct file_operations fops_reset = {
979 .read = read_file_reset,
Stephen Boyd234e3402012-04-05 14:25:11 -0700980 .open = simple_open,
Sujith Manoharanf8b815d2012-02-16 11:51:11 +0530981 .owner = THIS_MODULE,
982 .llseek = default_llseek,
983};
984
Sujith1395d3f2010-01-08 10:36:11 +0530985static ssize_t read_file_recv(struct file *file, char __user *user_buf,
986 size_t count, loff_t *ppos)
987{
988#define PHY_ERR(s, p) \
Sujith Manoharan42032142012-02-16 11:51:23 +0530989 len += snprintf(buf + len, size - len, "%22s : %10u\n", s, \
Sujith1395d3f2010-01-08 10:36:11 +0530990 sc->debug.stats.rxstats.phy_err_stats[p]);
991
Ben Greear24a07312012-04-12 10:03:59 -0700992#define RXS_ERR(s, e) \
993 do { \
994 len += snprintf(buf + len, size - len, \
995 "%22s : %10u\n", s, \
996 sc->debug.stats.rxstats.e); \
997 } while (0)
998
Sujith1395d3f2010-01-08 10:36:11 +0530999 struct ath_softc *sc = file->private_data;
1000 char *buf;
Sujith Manoharan42032142012-02-16 11:51:23 +05301001 unsigned int len = 0, size = 1600;
Sujith1395d3f2010-01-08 10:36:11 +05301002 ssize_t retval = 0;
1003
1004 buf = kzalloc(size, GFP_KERNEL);
1005 if (buf == NULL)
Dan Carpenter04236062010-05-14 15:25:39 +02001006 return -ENOMEM;
Sujith1395d3f2010-01-08 10:36:11 +05301007
Ben Greear24a07312012-04-12 10:03:59 -07001008 RXS_ERR("CRC ERR", crc_err);
1009 RXS_ERR("DECRYPT CRC ERR", decrypt_crc_err);
1010 RXS_ERR("PHY ERR", phy_err);
1011 RXS_ERR("MIC ERR", mic_err);
1012 RXS_ERR("PRE-DELIM CRC ERR", pre_delim_crc_err);
1013 RXS_ERR("POST-DELIM CRC ERR", post_delim_crc_err);
1014 RXS_ERR("DECRYPT BUSY ERR", decrypt_busy_err);
1015 RXS_ERR("RX-LENGTH-ERR", rx_len_err);
1016 RXS_ERR("RX-OOM-ERR", rx_oom_err);
1017 RXS_ERR("RX-RATE-ERR", rx_rate_err);
Ben Greear24a07312012-04-12 10:03:59 -07001018 RXS_ERR("RX-TOO-MANY-FRAGS", rx_too_many_frags_err);
Sujith1395d3f2010-01-08 10:36:11 +05301019
Sujith Manoharan42032142012-02-16 11:51:23 +05301020 PHY_ERR("UNDERRUN ERR", ATH9K_PHYERR_UNDERRUN);
1021 PHY_ERR("TIMING ERR", ATH9K_PHYERR_TIMING);
1022 PHY_ERR("PARITY ERR", ATH9K_PHYERR_PARITY);
1023 PHY_ERR("RATE ERR", ATH9K_PHYERR_RATE);
1024 PHY_ERR("LENGTH ERR", ATH9K_PHYERR_LENGTH);
1025 PHY_ERR("RADAR ERR", ATH9K_PHYERR_RADAR);
1026 PHY_ERR("SERVICE ERR", ATH9K_PHYERR_SERVICE);
1027 PHY_ERR("TOR ERR", ATH9K_PHYERR_TOR);
1028 PHY_ERR("OFDM-TIMING ERR", ATH9K_PHYERR_OFDM_TIMING);
1029 PHY_ERR("OFDM-SIGNAL-PARITY ERR", ATH9K_PHYERR_OFDM_SIGNAL_PARITY);
1030 PHY_ERR("OFDM-RATE ERR", ATH9K_PHYERR_OFDM_RATE_ILLEGAL);
1031 PHY_ERR("OFDM-LENGTH ERR", ATH9K_PHYERR_OFDM_LENGTH_ILLEGAL);
1032 PHY_ERR("OFDM-POWER-DROP ERR", ATH9K_PHYERR_OFDM_POWER_DROP);
1033 PHY_ERR("OFDM-SERVICE ERR", ATH9K_PHYERR_OFDM_SERVICE);
1034 PHY_ERR("OFDM-RESTART ERR", ATH9K_PHYERR_OFDM_RESTART);
1035 PHY_ERR("FALSE-RADAR-EXT ERR", ATH9K_PHYERR_FALSE_RADAR_EXT);
1036 PHY_ERR("CCK-TIMING ERR", ATH9K_PHYERR_CCK_TIMING);
1037 PHY_ERR("CCK-HEADER-CRC ERR", ATH9K_PHYERR_CCK_HEADER_CRC);
1038 PHY_ERR("CCK-RATE ERR", ATH9K_PHYERR_CCK_RATE_ILLEGAL);
1039 PHY_ERR("CCK-SERVICE ERR", ATH9K_PHYERR_CCK_SERVICE);
1040 PHY_ERR("CCK-RESTART ERR", ATH9K_PHYERR_CCK_RESTART);
1041 PHY_ERR("CCK-LENGTH ERR", ATH9K_PHYERR_CCK_LENGTH_ILLEGAL);
1042 PHY_ERR("CCK-POWER-DROP ERR", ATH9K_PHYERR_CCK_POWER_DROP);
1043 PHY_ERR("HT-CRC ERR", ATH9K_PHYERR_HT_CRC_ERROR);
1044 PHY_ERR("HT-LENGTH ERR", ATH9K_PHYERR_HT_LENGTH_ILLEGAL);
1045 PHY_ERR("HT-RATE ERR", ATH9K_PHYERR_HT_RATE_ILLEGAL);
1046
Ben Greear24a07312012-04-12 10:03:59 -07001047 RXS_ERR("RX-Pkts-All", rx_pkts_all);
1048 RXS_ERR("RX-Bytes-All", rx_bytes_all);
1049 RXS_ERR("RX-Beacons", rx_beacons);
1050 RXS_ERR("RX-Frags", rx_frags);
Simon Wunderlich9b99e662013-01-23 17:38:05 +01001051 RXS_ERR("RX-Spectral", rx_spectral);
Ben Greear99c15bf2010-10-01 12:26:30 -07001052
Dan Carpenter2b87f3a2010-05-14 15:24:37 +02001053 if (len > size)
1054 len = size;
1055
Sujith1395d3f2010-01-08 10:36:11 +05301056 retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
1057 kfree(buf);
1058
1059 return retval;
1060
Ben Greear24a07312012-04-12 10:03:59 -07001061#undef RXS_ERR
Sujith1395d3f2010-01-08 10:36:11 +05301062#undef PHY_ERR
1063}
1064
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -07001065void ath_debug_stat_rx(struct ath_softc *sc, struct ath_rx_status *rs)
Sujith1395d3f2010-01-08 10:36:11 +05301066{
Sujith1395d3f2010-01-08 10:36:11 +05301067#define RX_PHY_ERR_INC(c) sc->debug.stats.rxstats.phy_err_stats[c]++
1068
Ben Greear99c15bf2010-10-01 12:26:30 -07001069 RX_STAT_INC(rx_pkts_all);
1070 sc->debug.stats.rxstats.rx_bytes_all += rs->rs_datalen;
1071
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -07001072 if (rs->rs_status & ATH9K_RXERR_CRC)
Sujith1395d3f2010-01-08 10:36:11 +05301073 RX_STAT_INC(crc_err);
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -07001074 if (rs->rs_status & ATH9K_RXERR_DECRYPT)
Sujith1395d3f2010-01-08 10:36:11 +05301075 RX_STAT_INC(decrypt_crc_err);
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -07001076 if (rs->rs_status & ATH9K_RXERR_MIC)
Sujith1395d3f2010-01-08 10:36:11 +05301077 RX_STAT_INC(mic_err);
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -07001078 if (rs->rs_status & ATH9K_RX_DELIM_CRC_PRE)
Sujith1395d3f2010-01-08 10:36:11 +05301079 RX_STAT_INC(pre_delim_crc_err);
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -07001080 if (rs->rs_status & ATH9K_RX_DELIM_CRC_POST)
Sujith1395d3f2010-01-08 10:36:11 +05301081 RX_STAT_INC(post_delim_crc_err);
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -07001082 if (rs->rs_status & ATH9K_RX_DECRYPT_BUSY)
Sujith1395d3f2010-01-08 10:36:11 +05301083 RX_STAT_INC(decrypt_busy_err);
1084
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -07001085 if (rs->rs_status & ATH9K_RXERR_PHY) {
Sujith1395d3f2010-01-08 10:36:11 +05301086 RX_STAT_INC(phy_err);
Sujith Manoharandbb07f02012-02-16 11:52:25 +05301087 if (rs->rs_phyerr < ATH9K_PHYERR_MAX)
1088 RX_PHY_ERR_INC(rs->rs_phyerr);
Sujith1395d3f2010-01-08 10:36:11 +05301089 }
1090
Sujith1395d3f2010-01-08 10:36:11 +05301091#undef RX_PHY_ERR_INC
1092}
1093
1094static const struct file_operations fops_recv = {
1095 .read = read_file_recv,
Stephen Boyd234e3402012-04-05 14:25:11 -07001096 .open = simple_open,
Arnd Bergmann6038f372010-08-15 18:52:59 +02001097 .owner = THIS_MODULE,
1098 .llseek = default_llseek,
Sujith1395d3f2010-01-08 10:36:11 +05301099};
1100
Simon Wunderliche93d0832013-01-08 14:48:58 +01001101static ssize_t read_file_spec_scan_ctl(struct file *file, char __user *user_buf,
1102 size_t count, loff_t *ppos)
1103{
1104 struct ath_softc *sc = file->private_data;
1105 char *mode = "";
1106 unsigned int len;
1107
1108 switch (sc->spectral_mode) {
1109 case SPECTRAL_DISABLED:
1110 mode = "disable";
1111 break;
1112 case SPECTRAL_BACKGROUND:
1113 mode = "background";
1114 break;
1115 case SPECTRAL_CHANSCAN:
1116 mode = "chanscan";
1117 break;
1118 case SPECTRAL_MANUAL:
1119 mode = "manual";
1120 break;
1121 }
1122 len = strlen(mode);
1123 return simple_read_from_buffer(user_buf, count, ppos, mode, len);
1124}
1125
1126static ssize_t write_file_spec_scan_ctl(struct file *file,
1127 const char __user *user_buf,
1128 size_t count, loff_t *ppos)
1129{
1130 struct ath_softc *sc = file->private_data;
1131 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
1132 char buf[32];
1133 ssize_t len;
1134
1135 len = min(count, sizeof(buf) - 1);
1136 if (copy_from_user(buf, user_buf, len))
1137 return -EFAULT;
1138
1139 buf[len] = '\0';
1140
1141 if (strncmp("trigger", buf, 7) == 0) {
1142 ath9k_spectral_scan_trigger(sc->hw);
1143 } else if (strncmp("background", buf, 9) == 0) {
1144 ath9k_spectral_scan_config(sc->hw, SPECTRAL_BACKGROUND);
1145 ath_dbg(common, CONFIG, "spectral scan: background mode enabled\n");
1146 } else if (strncmp("chanscan", buf, 8) == 0) {
1147 ath9k_spectral_scan_config(sc->hw, SPECTRAL_CHANSCAN);
1148 ath_dbg(common, CONFIG, "spectral scan: channel scan mode enabled\n");
1149 } else if (strncmp("manual", buf, 6) == 0) {
1150 ath9k_spectral_scan_config(sc->hw, SPECTRAL_MANUAL);
1151 ath_dbg(common, CONFIG, "spectral scan: manual mode enabled\n");
1152 } else if (strncmp("disable", buf, 7) == 0) {
1153 ath9k_spectral_scan_config(sc->hw, SPECTRAL_DISABLED);
1154 ath_dbg(common, CONFIG, "spectral scan: disabled\n");
1155 } else {
1156 return -EINVAL;
1157 }
1158
1159 return count;
1160}
1161
1162static const struct file_operations fops_spec_scan_ctl = {
1163 .read = read_file_spec_scan_ctl,
1164 .write = write_file_spec_scan_ctl,
1165 .open = simple_open,
1166 .owner = THIS_MODULE,
1167 .llseek = default_llseek,
1168};
1169
Simon Wunderlich04ccd4a2013-01-23 17:38:04 +01001170static ssize_t read_file_spectral_short_repeat(struct file *file,
1171 char __user *user_buf,
1172 size_t count, loff_t *ppos)
1173{
1174 struct ath_softc *sc = file->private_data;
1175 char buf[32];
1176 unsigned int len;
1177
1178 len = sprintf(buf, "%d\n", sc->spec_config.short_repeat);
1179 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1180}
1181
1182static ssize_t write_file_spectral_short_repeat(struct file *file,
1183 const char __user *user_buf,
1184 size_t count, loff_t *ppos)
1185{
1186 struct ath_softc *sc = file->private_data;
1187 unsigned long val;
1188 char buf[32];
1189 ssize_t len;
1190
1191 len = min(count, sizeof(buf) - 1);
1192 if (copy_from_user(buf, user_buf, len))
1193 return -EFAULT;
1194
1195 buf[len] = '\0';
1196 if (kstrtoul(buf, 0, &val))
1197 return -EINVAL;
1198
1199 if (val < 0 || val > 1)
1200 return -EINVAL;
1201
1202 sc->spec_config.short_repeat = val;
1203 return count;
1204}
1205
1206static const struct file_operations fops_spectral_short_repeat = {
1207 .read = read_file_spectral_short_repeat,
1208 .write = write_file_spectral_short_repeat,
1209 .open = simple_open,
1210 .owner = THIS_MODULE,
1211 .llseek = default_llseek,
1212};
1213
1214static ssize_t read_file_spectral_count(struct file *file,
1215 char __user *user_buf,
1216 size_t count, loff_t *ppos)
1217{
1218 struct ath_softc *sc = file->private_data;
1219 char buf[32];
1220 unsigned int len;
1221
1222 len = sprintf(buf, "%d\n", sc->spec_config.count);
1223 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1224}
1225
1226static ssize_t write_file_spectral_count(struct file *file,
1227 const char __user *user_buf,
1228 size_t count, loff_t *ppos)
1229{
1230 struct ath_softc *sc = file->private_data;
1231 unsigned long val;
1232 char buf[32];
1233 ssize_t len;
1234
1235 len = min(count, sizeof(buf) - 1);
1236 if (copy_from_user(buf, user_buf, len))
1237 return -EFAULT;
1238
1239 buf[len] = '\0';
1240 if (kstrtoul(buf, 0, &val))
1241 return -EINVAL;
1242
1243 if (val < 0 || val > 255)
1244 return -EINVAL;
1245
1246 sc->spec_config.count = val;
1247 return count;
1248}
1249
1250static const struct file_operations fops_spectral_count = {
1251 .read = read_file_spectral_count,
1252 .write = write_file_spectral_count,
1253 .open = simple_open,
1254 .owner = THIS_MODULE,
1255 .llseek = default_llseek,
1256};
1257
1258static ssize_t read_file_spectral_period(struct file *file,
1259 char __user *user_buf,
1260 size_t count, loff_t *ppos)
1261{
1262 struct ath_softc *sc = file->private_data;
1263 char buf[32];
1264 unsigned int len;
1265
1266 len = sprintf(buf, "%d\n", sc->spec_config.period);
1267 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1268}
1269
1270static ssize_t write_file_spectral_period(struct file *file,
1271 const char __user *user_buf,
1272 size_t count, loff_t *ppos)
1273{
1274 struct ath_softc *sc = file->private_data;
1275 unsigned long val;
1276 char buf[32];
1277 ssize_t len;
1278
1279 len = min(count, sizeof(buf) - 1);
1280 if (copy_from_user(buf, user_buf, len))
1281 return -EFAULT;
1282
1283 buf[len] = '\0';
1284 if (kstrtoul(buf, 0, &val))
1285 return -EINVAL;
1286
1287 if (val < 0 || val > 255)
1288 return -EINVAL;
1289
1290 sc->spec_config.period = val;
1291 return count;
1292}
1293
1294static const struct file_operations fops_spectral_period = {
1295 .read = read_file_spectral_period,
1296 .write = write_file_spectral_period,
1297 .open = simple_open,
1298 .owner = THIS_MODULE,
1299 .llseek = default_llseek,
1300};
1301
1302static ssize_t read_file_spectral_fft_period(struct file *file,
1303 char __user *user_buf,
1304 size_t count, loff_t *ppos)
1305{
1306 struct ath_softc *sc = file->private_data;
1307 char buf[32];
1308 unsigned int len;
1309
1310 len = sprintf(buf, "%d\n", sc->spec_config.fft_period);
1311 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1312}
1313
1314static ssize_t write_file_spectral_fft_period(struct file *file,
1315 const char __user *user_buf,
1316 size_t count, loff_t *ppos)
1317{
1318 struct ath_softc *sc = file->private_data;
1319 unsigned long val;
1320 char buf[32];
1321 ssize_t len;
1322
1323 len = min(count, sizeof(buf) - 1);
1324 if (copy_from_user(buf, user_buf, len))
1325 return -EFAULT;
1326
1327 buf[len] = '\0';
1328 if (kstrtoul(buf, 0, &val))
1329 return -EINVAL;
1330
1331 if (val < 0 || val > 15)
1332 return -EINVAL;
1333
1334 sc->spec_config.fft_period = val;
1335 return count;
1336}
1337
1338static const struct file_operations fops_spectral_fft_period = {
1339 .read = read_file_spectral_fft_period,
1340 .write = write_file_spectral_fft_period,
1341 .open = simple_open,
1342 .owner = THIS_MODULE,
1343 .llseek = default_llseek,
1344};
1345
Simon Wunderliche93d0832013-01-08 14:48:58 +01001346static struct dentry *create_buf_file_handler(const char *filename,
1347 struct dentry *parent,
1348 umode_t mode,
1349 struct rchan_buf *buf,
1350 int *is_global)
1351{
1352 struct dentry *buf_file;
1353
1354 buf_file = debugfs_create_file(filename, mode, parent, buf,
1355 &relay_file_operations);
1356 *is_global = 1;
1357 return buf_file;
1358}
1359
1360static int remove_buf_file_handler(struct dentry *dentry)
1361{
1362 debugfs_remove(dentry);
1363
1364 return 0;
1365}
1366
1367void ath_debug_send_fft_sample(struct ath_softc *sc,
1368 struct fft_sample_tlv *fft_sample_tlv)
1369{
Sven Eckelmann4ab0b0a2013-01-23 20:12:39 +01001370 int length;
Simon Wunderliche93d0832013-01-08 14:48:58 +01001371 if (!sc->rfs_chan_spec_scan)
1372 return;
1373
Sven Eckelmann4ab0b0a2013-01-23 20:12:39 +01001374 length = __be16_to_cpu(fft_sample_tlv->length) +
1375 sizeof(*fft_sample_tlv);
1376 relay_write(sc->rfs_chan_spec_scan, fft_sample_tlv, length);
Simon Wunderliche93d0832013-01-08 14:48:58 +01001377}
1378
1379static struct rchan_callbacks rfs_spec_scan_cb = {
1380 .create_buf_file = create_buf_file_handler,
1381 .remove_buf_file = remove_buf_file_handler,
1382};
1383
1384
Felix Fietkau9bff0bc2010-05-11 17:23:02 +02001385static ssize_t read_file_regidx(struct file *file, char __user *user_buf,
1386 size_t count, loff_t *ppos)
1387{
1388 struct ath_softc *sc = file->private_data;
1389 char buf[32];
1390 unsigned int len;
1391
Dan Carpenter2b87f3a2010-05-14 15:24:37 +02001392 len = sprintf(buf, "0x%08x\n", sc->debug.regidx);
Felix Fietkau9bff0bc2010-05-11 17:23:02 +02001393 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1394}
1395
1396static ssize_t write_file_regidx(struct file *file, const char __user *user_buf,
1397 size_t count, loff_t *ppos)
1398{
1399 struct ath_softc *sc = file->private_data;
1400 unsigned long regidx;
1401 char buf[32];
1402 ssize_t len;
1403
1404 len = min(count, sizeof(buf) - 1);
1405 if (copy_from_user(buf, user_buf, len))
Dan Carpenter04236062010-05-14 15:25:39 +02001406 return -EFAULT;
Felix Fietkau9bff0bc2010-05-11 17:23:02 +02001407
1408 buf[len] = '\0';
Jingoo Han27d7f472013-05-31 21:24:06 +00001409 if (kstrtoul(buf, 0, &regidx))
Felix Fietkau9bff0bc2010-05-11 17:23:02 +02001410 return -EINVAL;
1411
1412 sc->debug.regidx = regidx;
1413 return count;
1414}
1415
1416static const struct file_operations fops_regidx = {
1417 .read = read_file_regidx,
1418 .write = write_file_regidx,
Stephen Boyd234e3402012-04-05 14:25:11 -07001419 .open = simple_open,
Arnd Bergmann6038f372010-08-15 18:52:59 +02001420 .owner = THIS_MODULE,
1421 .llseek = default_llseek,
Felix Fietkau9bff0bc2010-05-11 17:23:02 +02001422};
1423
1424static ssize_t read_file_regval(struct file *file, char __user *user_buf,
1425 size_t count, loff_t *ppos)
1426{
1427 struct ath_softc *sc = file->private_data;
1428 struct ath_hw *ah = sc->sc_ah;
1429 char buf[32];
1430 unsigned int len;
1431 u32 regval;
1432
Rajkumar Manoharan79d2b152011-05-16 18:23:23 +05301433 ath9k_ps_wakeup(sc);
Felix Fietkau9bff0bc2010-05-11 17:23:02 +02001434 regval = REG_READ_D(ah, sc->debug.regidx);
Rajkumar Manoharan79d2b152011-05-16 18:23:23 +05301435 ath9k_ps_restore(sc);
Dan Carpenter2b87f3a2010-05-14 15:24:37 +02001436 len = sprintf(buf, "0x%08x\n", regval);
Felix Fietkau9bff0bc2010-05-11 17:23:02 +02001437 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1438}
1439
1440static ssize_t write_file_regval(struct file *file, const char __user *user_buf,
1441 size_t count, loff_t *ppos)
1442{
1443 struct ath_softc *sc = file->private_data;
1444 struct ath_hw *ah = sc->sc_ah;
1445 unsigned long regval;
1446 char buf[32];
1447 ssize_t len;
1448
1449 len = min(count, sizeof(buf) - 1);
1450 if (copy_from_user(buf, user_buf, len))
Dan Carpenter04236062010-05-14 15:25:39 +02001451 return -EFAULT;
Felix Fietkau9bff0bc2010-05-11 17:23:02 +02001452
1453 buf[len] = '\0';
Jingoo Han27d7f472013-05-31 21:24:06 +00001454 if (kstrtoul(buf, 0, &regval))
Felix Fietkau9bff0bc2010-05-11 17:23:02 +02001455 return -EINVAL;
1456
Rajkumar Manoharan79d2b152011-05-16 18:23:23 +05301457 ath9k_ps_wakeup(sc);
Felix Fietkau9bff0bc2010-05-11 17:23:02 +02001458 REG_WRITE_D(ah, sc->debug.regidx, regval);
Rajkumar Manoharan79d2b152011-05-16 18:23:23 +05301459 ath9k_ps_restore(sc);
Felix Fietkau9bff0bc2010-05-11 17:23:02 +02001460 return count;
1461}
1462
1463static const struct file_operations fops_regval = {
1464 .read = read_file_regval,
1465 .write = write_file_regval,
Stephen Boyd234e3402012-04-05 14:25:11 -07001466 .open = simple_open,
Arnd Bergmann6038f372010-08-15 18:52:59 +02001467 .owner = THIS_MODULE,
1468 .llseek = default_llseek,
Felix Fietkau9bff0bc2010-05-11 17:23:02 +02001469};
1470
Vasanthakumar Thiagarajan582d0062011-03-01 05:30:55 -08001471#define REGDUMP_LINE_SIZE 20
1472
1473static int open_file_regdump(struct inode *inode, struct file *file)
1474{
1475 struct ath_softc *sc = inode->i_private;
1476 unsigned int len = 0;
1477 u8 *buf;
1478 int i;
1479 unsigned long num_regs, regdump_len, max_reg_offset;
1480
1481 max_reg_offset = AR_SREV_9300_20_OR_LATER(sc->sc_ah) ? 0x16bd4 : 0xb500;
1482 num_regs = max_reg_offset / 4 + 1;
1483 regdump_len = num_regs * REGDUMP_LINE_SIZE + 1;
1484 buf = vmalloc(regdump_len);
1485 if (!buf)
1486 return -ENOMEM;
1487
1488 ath9k_ps_wakeup(sc);
1489 for (i = 0; i < num_regs; i++)
1490 len += scnprintf(buf + len, regdump_len - len,
1491 "0x%06x 0x%08x\n", i << 2, REG_READ(sc->sc_ah, i << 2));
1492 ath9k_ps_restore(sc);
1493
1494 file->private_data = buf;
1495
1496 return 0;
1497}
1498
1499static const struct file_operations fops_regdump = {
1500 .open = open_file_regdump,
1501 .read = ath9k_debugfs_read_buf,
1502 .release = ath9k_debugfs_release_buf,
1503 .owner = THIS_MODULE,
1504 .llseek = default_llseek,/* read accesses f_pos */
1505};
1506
Rajkumar Manoharand069a462011-08-13 10:28:18 +05301507static ssize_t read_file_dump_nfcal(struct file *file, char __user *user_buf,
1508 size_t count, loff_t *ppos)
1509{
1510 struct ath_softc *sc = file->private_data;
1511 struct ath_hw *ah = sc->sc_ah;
1512 struct ath9k_nfcal_hist *h = sc->caldata.nfCalHist;
1513 struct ath_common *common = ath9k_hw_common(ah);
1514 struct ieee80211_conf *conf = &common->hw->conf;
1515 u32 len = 0, size = 1500;
1516 u32 i, j;
1517 ssize_t retval = 0;
1518 char *buf;
1519 u8 chainmask = (ah->rxchainmask << 3) | ah->rxchainmask;
1520 u8 nread;
1521
1522 buf = kzalloc(size, GFP_KERNEL);
1523 if (!buf)
1524 return -ENOMEM;
1525
1526 len += snprintf(buf + len, size - len,
1527 "Channel Noise Floor : %d\n", ah->noise);
1528 len += snprintf(buf + len, size - len,
1529 "Chain | privNF | # Readings | NF Readings\n");
1530 for (i = 0; i < NUM_NF_READINGS; i++) {
1531 if (!(chainmask & (1 << i)) ||
1532 ((i >= AR5416_MAX_CHAINS) && !conf_is_ht40(conf)))
1533 continue;
1534
1535 nread = AR_PHY_CCA_FILTERWINDOW_LENGTH - h[i].invalidNFcount;
1536 len += snprintf(buf + len, size - len, " %d\t %d\t %d\t\t",
1537 i, h[i].privNF, nread);
1538 for (j = 0; j < nread; j++)
1539 len += snprintf(buf + len, size - len,
1540 " %d", h[i].nfCalBuffer[j]);
1541 len += snprintf(buf + len, size - len, "\n");
1542 }
1543
1544 if (len > size)
1545 len = size;
1546
1547 retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
1548 kfree(buf);
1549
1550 return retval;
1551}
1552
1553static const struct file_operations fops_dump_nfcal = {
1554 .read = read_file_dump_nfcal,
Stephen Boyd234e3402012-04-05 14:25:11 -07001555 .open = simple_open,
Rajkumar Manoharand069a462011-08-13 10:28:18 +05301556 .owner = THIS_MODULE,
1557 .llseek = default_llseek,
1558};
1559
Rajkumar Manoharan580f0102011-07-29 17:38:12 +05301560static ssize_t read_file_base_eeprom(struct file *file, char __user *user_buf,
1561 size_t count, loff_t *ppos)
1562{
1563 struct ath_softc *sc = file->private_data;
1564 struct ath_hw *ah = sc->sc_ah;
1565 u32 len = 0, size = 1500;
1566 ssize_t retval = 0;
1567 char *buf;
1568
1569 buf = kzalloc(size, GFP_KERNEL);
1570 if (!buf)
1571 return -ENOMEM;
1572
1573 len = ah->eep_ops->dump_eeprom(ah, true, buf, len, size);
1574
1575 retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
1576 kfree(buf);
1577
1578 return retval;
1579}
1580
1581static const struct file_operations fops_base_eeprom = {
1582 .read = read_file_base_eeprom,
Stephen Boyd234e3402012-04-05 14:25:11 -07001583 .open = simple_open,
Rajkumar Manoharan580f0102011-07-29 17:38:12 +05301584 .owner = THIS_MODULE,
1585 .llseek = default_llseek,
1586};
1587
Rajkumar Manoharan3f4c4bd2011-07-29 17:38:13 +05301588static ssize_t read_file_modal_eeprom(struct file *file, char __user *user_buf,
1589 size_t count, loff_t *ppos)
1590{
1591 struct ath_softc *sc = file->private_data;
1592 struct ath_hw *ah = sc->sc_ah;
1593 u32 len = 0, size = 6000;
1594 char *buf;
1595 size_t retval;
1596
1597 buf = kzalloc(size, GFP_KERNEL);
1598 if (buf == NULL)
1599 return -ENOMEM;
1600
1601 len = ah->eep_ops->dump_eeprom(ah, false, buf, len, size);
1602
1603 retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
1604 kfree(buf);
1605
1606 return retval;
1607}
1608
1609static const struct file_operations fops_modal_eeprom = {
1610 .read = read_file_modal_eeprom,
Stephen Boyd234e3402012-04-05 14:25:11 -07001611 .open = simple_open,
Rajkumar Manoharan3f4c4bd2011-07-29 17:38:13 +05301612 .owner = THIS_MODULE,
1613 .llseek = default_llseek,
1614};
1615
Rajkumar Manoharan4df50ca2012-10-25 17:16:54 +05301616#ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
1617static ssize_t read_file_btcoex(struct file *file, char __user *user_buf,
1618 size_t count, loff_t *ppos)
1619{
1620 struct ath_softc *sc = file->private_data;
1621 u32 len = 0, size = 1500;
1622 char *buf;
1623 size_t retval;
1624
1625 buf = kzalloc(size, GFP_KERNEL);
1626 if (buf == NULL)
1627 return -ENOMEM;
1628
Sujith Manoharanac46ba42012-11-19 14:24:46 +05301629 if (!sc->sc_ah->common.btcoex_enabled) {
1630 len = snprintf(buf, size, "%s\n",
1631 "BTCOEX is disabled");
1632 goto exit;
1633 }
Rajkumar Manoharan4df50ca2012-10-25 17:16:54 +05301634
Sujith Manoharanac46ba42012-11-19 14:24:46 +05301635 len = ath9k_dump_btcoex(sc, buf, size);
1636exit:
Rajkumar Manoharan4df50ca2012-10-25 17:16:54 +05301637 retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
1638 kfree(buf);
1639
1640 return retval;
1641}
1642
1643static const struct file_operations fops_btcoex = {
1644 .read = read_file_btcoex,
1645 .open = simple_open,
1646 .owner = THIS_MODULE,
1647 .llseek = default_llseek,
1648};
1649#endif
1650
Sujith Manoharana145daf2012-11-28 15:08:54 +05301651static ssize_t read_file_node_stat(struct file *file, char __user *user_buf,
1652 size_t count, loff_t *ppos)
1653{
1654 struct ath_node *an = file->private_data;
1655 struct ath_softc *sc = an->sc;
1656 struct ath_atx_tid *tid;
1657 struct ath_atx_ac *ac;
1658 struct ath_txq *txq;
1659 u32 len = 0, size = 4096;
1660 char *buf;
1661 size_t retval;
1662 int tidno, acno;
1663
1664 buf = kzalloc(size, GFP_KERNEL);
1665 if (buf == NULL)
1666 return -ENOMEM;
1667
1668 if (!an->sta->ht_cap.ht_supported) {
1669 len = snprintf(buf, size, "%s\n",
1670 "HT not supported");
1671 goto exit;
1672 }
1673
1674 len = snprintf(buf, size, "Max-AMPDU: %d\n",
1675 an->maxampdu);
1676 len += snprintf(buf + len, size - len, "MPDU Density: %d\n\n",
1677 an->mpdudensity);
1678
1679 len += snprintf(buf + len, size - len,
1680 "%2s%7s\n", "AC", "SCHED");
1681
1682 for (acno = 0, ac = &an->ac[acno];
1683 acno < IEEE80211_NUM_ACS; acno++, ac++) {
1684 txq = ac->txq;
1685 ath_txq_lock(sc, txq);
1686 len += snprintf(buf + len, size - len,
1687 "%2d%7d\n",
1688 acno, ac->sched);
1689 ath_txq_unlock(sc, txq);
1690 }
1691
1692 len += snprintf(buf + len, size - len,
1693 "\n%3s%11s%10s%10s%10s%10s%9s%6s%8s\n",
1694 "TID", "SEQ_START", "SEQ_NEXT", "BAW_SIZE",
1695 "BAW_HEAD", "BAW_TAIL", "BAR_IDX", "SCHED", "PAUSED");
1696
1697 for (tidno = 0, tid = &an->tid[tidno];
1698 tidno < IEEE80211_NUM_TIDS; tidno++, tid++) {
1699 txq = tid->ac->txq;
1700 ath_txq_lock(sc, txq);
1701 len += snprintf(buf + len, size - len,
1702 "%3d%11d%10d%10d%10d%10d%9d%6d%8d\n",
1703 tid->tidno, tid->seq_start, tid->seq_next,
1704 tid->baw_size, tid->baw_head, tid->baw_tail,
1705 tid->bar_index, tid->sched, tid->paused);
1706 ath_txq_unlock(sc, txq);
1707 }
1708exit:
1709 retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
1710 kfree(buf);
1711
1712 return retval;
1713}
1714
1715static const struct file_operations fops_node_stat = {
1716 .read = read_file_node_stat,
1717 .open = simple_open,
1718 .owner = THIS_MODULE,
1719 .llseek = default_llseek,
1720};
1721
1722void ath9k_sta_add_debugfs(struct ieee80211_hw *hw,
1723 struct ieee80211_vif *vif,
1724 struct ieee80211_sta *sta,
1725 struct dentry *dir)
1726{
1727 struct ath_node *an = (struct ath_node *)sta->drv_priv;
1728 an->node_stat = debugfs_create_file("node_stat", S_IRUGO,
1729 dir, an, &fops_node_stat);
1730}
1731
1732void ath9k_sta_remove_debugfs(struct ieee80211_hw *hw,
1733 struct ieee80211_vif *vif,
1734 struct ieee80211_sta *sta,
1735 struct dentry *dir)
1736{
1737 struct ath_node *an = (struct ath_node *)sta->drv_priv;
1738 debugfs_remove(an->node_stat);
1739}
1740
Sujith Manoharanc175db82012-11-28 15:08:52 +05301741/* Ethtool support for get-stats */
1742
1743#define AMKSTR(nm) #nm "_BE", #nm "_BK", #nm "_VI", #nm "_VO"
1744static const char ath9k_gstrings_stats[][ETH_GSTRING_LEN] = {
1745 "tx_pkts_nic",
1746 "tx_bytes_nic",
1747 "rx_pkts_nic",
1748 "rx_bytes_nic",
1749 AMKSTR(d_tx_pkts),
1750 AMKSTR(d_tx_bytes),
1751 AMKSTR(d_tx_mpdus_queued),
1752 AMKSTR(d_tx_mpdus_completed),
1753 AMKSTR(d_tx_mpdu_xretries),
1754 AMKSTR(d_tx_aggregates),
1755 AMKSTR(d_tx_ampdus_queued_hw),
1756 AMKSTR(d_tx_ampdus_queued_sw),
1757 AMKSTR(d_tx_ampdus_completed),
1758 AMKSTR(d_tx_ampdu_retries),
1759 AMKSTR(d_tx_ampdu_xretries),
1760 AMKSTR(d_tx_fifo_underrun),
1761 AMKSTR(d_tx_op_exceeded),
1762 AMKSTR(d_tx_timer_expiry),
1763 AMKSTR(d_tx_desc_cfg_err),
1764 AMKSTR(d_tx_data_underrun),
1765 AMKSTR(d_tx_delim_underrun),
Ben Greear18c45b12013-03-04 15:31:17 -08001766 "d_rx_crc_err",
Sujith Manoharanc175db82012-11-28 15:08:52 +05301767 "d_rx_decrypt_crc_err",
1768 "d_rx_phy_err",
1769 "d_rx_mic_err",
1770 "d_rx_pre_delim_crc_err",
1771 "d_rx_post_delim_crc_err",
1772 "d_rx_decrypt_busy_err",
1773
1774 "d_rx_phyerr_radar",
1775 "d_rx_phyerr_ofdm_timing",
1776 "d_rx_phyerr_cck_timing",
1777
1778};
1779#define ATH9K_SSTATS_LEN ARRAY_SIZE(ath9k_gstrings_stats)
1780
1781void ath9k_get_et_strings(struct ieee80211_hw *hw,
1782 struct ieee80211_vif *vif,
1783 u32 sset, u8 *data)
1784{
1785 if (sset == ETH_SS_STATS)
1786 memcpy(data, *ath9k_gstrings_stats,
1787 sizeof(ath9k_gstrings_stats));
1788}
1789
1790int ath9k_get_et_sset_count(struct ieee80211_hw *hw,
1791 struct ieee80211_vif *vif, int sset)
1792{
1793 if (sset == ETH_SS_STATS)
1794 return ATH9K_SSTATS_LEN;
1795 return 0;
1796}
1797
1798#define AWDATA(elem) \
1799 do { \
1800 data[i++] = sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_BE)].elem; \
1801 data[i++] = sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_BK)].elem; \
1802 data[i++] = sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_VI)].elem; \
1803 data[i++] = sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_VO)].elem; \
1804 } while (0)
1805
1806#define AWDATA_RX(elem) \
1807 do { \
1808 data[i++] = sc->debug.stats.rxstats.elem; \
1809 } while (0)
1810
1811void ath9k_get_et_stats(struct ieee80211_hw *hw,
1812 struct ieee80211_vif *vif,
1813 struct ethtool_stats *stats, u64 *data)
1814{
1815 struct ath_softc *sc = hw->priv;
1816 int i = 0;
1817
1818 data[i++] = (sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_BE)].tx_pkts_all +
1819 sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_BK)].tx_pkts_all +
1820 sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_VI)].tx_pkts_all +
1821 sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_VO)].tx_pkts_all);
1822 data[i++] = (sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_BE)].tx_bytes_all +
1823 sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_BK)].tx_bytes_all +
1824 sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_VI)].tx_bytes_all +
1825 sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_VO)].tx_bytes_all);
1826 AWDATA_RX(rx_pkts_all);
1827 AWDATA_RX(rx_bytes_all);
1828
1829 AWDATA(tx_pkts_all);
1830 AWDATA(tx_bytes_all);
1831 AWDATA(queued);
1832 AWDATA(completed);
1833 AWDATA(xretries);
1834 AWDATA(a_aggr);
1835 AWDATA(a_queued_hw);
1836 AWDATA(a_queued_sw);
1837 AWDATA(a_completed);
1838 AWDATA(a_retries);
1839 AWDATA(a_xretries);
1840 AWDATA(fifo_underrun);
1841 AWDATA(xtxop);
1842 AWDATA(timer_exp);
1843 AWDATA(desc_cfg_err);
1844 AWDATA(data_underrun);
1845 AWDATA(delim_underrun);
1846
Ben Greear18c45b12013-03-04 15:31:17 -08001847 AWDATA_RX(crc_err);
Sujith Manoharanc175db82012-11-28 15:08:52 +05301848 AWDATA_RX(decrypt_crc_err);
1849 AWDATA_RX(phy_err);
1850 AWDATA_RX(mic_err);
1851 AWDATA_RX(pre_delim_crc_err);
1852 AWDATA_RX(post_delim_crc_err);
1853 AWDATA_RX(decrypt_busy_err);
1854
1855 AWDATA_RX(phy_err_stats[ATH9K_PHYERR_RADAR]);
1856 AWDATA_RX(phy_err_stats[ATH9K_PHYERR_OFDM_TIMING]);
1857 AWDATA_RX(phy_err_stats[ATH9K_PHYERR_CCK_TIMING]);
1858
1859 WARN_ON(i != ATH9K_SSTATS_LEN);
1860}
1861
Sujith Manoharanaf690092013-05-10 18:41:06 +05301862void ath9k_deinit_debug(struct ath_softc *sc)
1863{
1864 if (config_enabled(CONFIG_ATH9K_DEBUGFS) && sc->rfs_chan_spec_scan) {
1865 relay_close(sc->rfs_chan_spec_scan);
1866 sc->rfs_chan_spec_scan = NULL;
1867 }
1868}
1869
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001870int ath9k_init_debug(struct ath_hw *ah)
Sujith88b126a2008-11-28 22:19:02 +05301871{
Luis R. Rodriguezbc974f42009-09-28 02:54:40 -04001872 struct ath_common *common = ath9k_hw_common(ah);
1873 struct ath_softc *sc = (struct ath_softc *) common->priv;
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001874
Ben Greeareb272442010-11-29 14:13:22 -08001875 sc->debug.debugfs_phy = debugfs_create_dir("ath9k",
1876 sc->hw->wiphy->debugfsdir);
Sujith17d79042009-02-09 13:27:03 +05301877 if (!sc->debug.debugfs_phy)
Felix Fietkauc8a72c02010-05-11 17:23:00 +02001878 return -ENOMEM;
Sujith826d2682008-11-28 22:20:23 +05301879
Felix Fietkaua830df02009-11-23 22:33:27 +01001880#ifdef CONFIG_ATH_DEBUG
Felix Fietkauc70cab12011-03-19 13:55:37 +01001881 debugfs_create_file("debug", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
1882 sc, &fops_debug);
Felix Fietkaua830df02009-11-23 22:33:27 +01001883#endif
Zefir Kurtisi29942bc2011-12-14 20:16:34 -08001884
1885 ath9k_dfs_init_debug(sc);
1886
Felix Fietkauc70cab12011-03-19 13:55:37 +01001887 debugfs_create_file("dma", S_IRUSR, sc->debug.debugfs_phy, sc,
1888 &fops_dma);
1889 debugfs_create_file("interrupt", S_IRUSR, sc->debug.debugfs_phy, sc,
1890 &fops_interrupt);
Felix Fietkauc70cab12011-03-19 13:55:37 +01001891 debugfs_create_file("xmit", S_IRUSR, sc->debug.debugfs_phy, sc,
1892 &fops_xmit);
Sujith Manoharanc0b74872012-11-21 18:13:12 +05301893 debugfs_create_file("queues", S_IRUSR, sc->debug.debugfs_phy, sc,
1894 &fops_queues);
Felix Fietkau7702e782012-07-15 19:53:35 +02001895 debugfs_create_u32("qlen_bk", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
Sujith Manoharanbea843c2012-11-21 18:13:10 +05301896 &sc->tx.txq_max_pending[IEEE80211_AC_BK]);
Felix Fietkau7702e782012-07-15 19:53:35 +02001897 debugfs_create_u32("qlen_be", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
Sujith Manoharanbea843c2012-11-21 18:13:10 +05301898 &sc->tx.txq_max_pending[IEEE80211_AC_BE]);
Felix Fietkau7702e782012-07-15 19:53:35 +02001899 debugfs_create_u32("qlen_vi", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
Sujith Manoharanbea843c2012-11-21 18:13:10 +05301900 &sc->tx.txq_max_pending[IEEE80211_AC_VI]);
Felix Fietkau7702e782012-07-15 19:53:35 +02001901 debugfs_create_u32("qlen_vo", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
Sujith Manoharanbea843c2012-11-21 18:13:10 +05301902 &sc->tx.txq_max_pending[IEEE80211_AC_VO]);
Felix Fietkauc70cab12011-03-19 13:55:37 +01001903 debugfs_create_file("misc", S_IRUSR, sc->debug.debugfs_phy, sc,
1904 &fops_misc);
Sujith Manoharanf8b815d2012-02-16 11:51:11 +05301905 debugfs_create_file("reset", S_IRUSR, sc->debug.debugfs_phy, sc,
1906 &fops_reset);
Felix Fietkauc70cab12011-03-19 13:55:37 +01001907 debugfs_create_file("recv", S_IRUSR, sc->debug.debugfs_phy, sc,
1908 &fops_recv);
1909 debugfs_create_file("rx_chainmask", S_IRUSR | S_IWUSR,
1910 sc->debug.debugfs_phy, sc, &fops_rx_chainmask);
1911 debugfs_create_file("tx_chainmask", S_IRUSR | S_IWUSR,
1912 sc->debug.debugfs_phy, sc, &fops_tx_chainmask);
Sujith Manoharan6e4d2912013-06-03 09:19:28 +05301913 debugfs_create_file("ani", S_IRUSR | S_IWUSR,
1914 sc->debug.debugfs_phy, sc, &fops_ani);
Felix Fietkau74673db2012-09-08 15:24:17 +02001915 debugfs_create_bool("paprd", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
1916 &sc->sc_ah->config.enable_paprd);
Felix Fietkauc70cab12011-03-19 13:55:37 +01001917 debugfs_create_file("regidx", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
1918 sc, &fops_regidx);
1919 debugfs_create_file("regval", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
1920 sc, &fops_regval);
1921 debugfs_create_bool("ignore_extcca", S_IRUSR | S_IWUSR,
1922 sc->debug.debugfs_phy,
1923 &ah->config.cwm_ignore_extcca);
1924 debugfs_create_file("regdump", S_IRUSR, sc->debug.debugfs_phy, sc,
1925 &fops_regdump);
Rajkumar Manoharand069a462011-08-13 10:28:18 +05301926 debugfs_create_file("dump_nfcal", S_IRUSR, sc->debug.debugfs_phy, sc,
1927 &fops_dump_nfcal);
Rajkumar Manoharan580f0102011-07-29 17:38:12 +05301928 debugfs_create_file("base_eeprom", S_IRUSR, sc->debug.debugfs_phy, sc,
1929 &fops_base_eeprom);
Rajkumar Manoharan3f4c4bd2011-07-29 17:38:13 +05301930 debugfs_create_file("modal_eeprom", S_IRUSR, sc->debug.debugfs_phy, sc,
1931 &fops_modal_eeprom);
Simon Wunderliche93d0832013-01-08 14:48:58 +01001932 sc->rfs_chan_spec_scan = relay_open("spectral_scan",
1933 sc->debug.debugfs_phy,
Zefir Kurtisi55f39e62013-03-22 12:58:23 +01001934 1024, 256, &rfs_spec_scan_cb,
Simon Wunderliche93d0832013-01-08 14:48:58 +01001935 NULL);
1936 debugfs_create_file("spectral_scan_ctl", S_IRUSR | S_IWUSR,
1937 sc->debug.debugfs_phy, sc,
1938 &fops_spec_scan_ctl);
Simon Wunderlich04ccd4a2013-01-23 17:38:04 +01001939 debugfs_create_file("spectral_short_repeat", S_IRUSR | S_IWUSR,
1940 sc->debug.debugfs_phy, sc,
1941 &fops_spectral_short_repeat);
1942 debugfs_create_file("spectral_count", S_IRUSR | S_IWUSR,
1943 sc->debug.debugfs_phy, sc, &fops_spectral_count);
1944 debugfs_create_file("spectral_period", S_IRUSR | S_IWUSR,
1945 sc->debug.debugfs_phy, sc, &fops_spectral_period);
1946 debugfs_create_file("spectral_fft_period", S_IRUSR | S_IWUSR,
1947 sc->debug.debugfs_phy, sc,
1948 &fops_spectral_fft_period);
Felix Fietkau691680b2011-03-19 13:55:38 +01001949 debugfs_create_u32("gpio_mask", S_IRUSR | S_IWUSR,
1950 sc->debug.debugfs_phy, &sc->sc_ah->gpio_mask);
Felix Fietkau691680b2011-03-19 13:55:38 +01001951 debugfs_create_u32("gpio_val", S_IRUSR | S_IWUSR,
1952 sc->debug.debugfs_phy, &sc->sc_ah->gpio_val);
Sujith Manoharan4eba10c2013-07-29 16:04:49 +05301953 debugfs_create_file("antenna_diversity", S_IRUSR,
1954 sc->debug.debugfs_phy, sc, &fops_antenna_diversity);
Rajkumar Manoharan4df50ca2012-10-25 17:16:54 +05301955#ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
Sujith Manoharan36e88252013-08-06 12:44:15 +05301956 debugfs_create_file("bt_ant_diversity", S_IRUSR | S_IWUSR,
1957 sc->debug.debugfs_phy, sc, &fops_bt_ant_diversity);
Rajkumar Manoharan4df50ca2012-10-25 17:16:54 +05301958 debugfs_create_file("btcoex", S_IRUSR, sc->debug.debugfs_phy, sc,
1959 &fops_btcoex);
1960#endif
Sujith826d2682008-11-28 22:20:23 +05301961 return 0;
Sujith88b126a2008-11-28 22:19:02 +05301962}