blob: dbf8f495964217e1b5799fb165155ff3c88b4894 [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>
Gabor Juhos52103112009-03-06 09:57:39 +010020#include <asm/unaligned.h>
21
Sujith394cf0a2009-02-09 13:26:54 +053022#include "ath9k.h"
Sujith88b126a2008-11-28 22:19:02 +053023
Luis R. Rodriguez475a6e42009-09-23 23:06:59 -040024#define REG_WRITE_D(_ah, _reg, _val) \
25 ath9k_hw_common(_ah)->ops->write((_ah), (_val), (_reg))
26#define REG_READ_D(_ah, _reg) \
27 ath9k_hw_common(_ah)->ops->read((_ah), (_reg))
28
Felix Fietkau6a4d05d2013-12-19 18:01:48 +010029void ath9k_debug_sync_cause(struct ath_softc *sc, u32 sync_cause)
30{
31 if (sync_cause)
32 sc->debug.stats.istats.sync_cause_all++;
33 if (sync_cause & AR_INTR_SYNC_RTC_IRQ)
34 sc->debug.stats.istats.sync_rtc_irq++;
35 if (sync_cause & AR_INTR_SYNC_MAC_IRQ)
36 sc->debug.stats.istats.sync_mac_irq++;
37 if (sync_cause & AR_INTR_SYNC_EEPROM_ILLEGAL_ACCESS)
38 sc->debug.stats.istats.eeprom_illegal_access++;
39 if (sync_cause & AR_INTR_SYNC_APB_TIMEOUT)
40 sc->debug.stats.istats.apb_timeout++;
41 if (sync_cause & AR_INTR_SYNC_PCI_MODE_CONFLICT)
42 sc->debug.stats.istats.pci_mode_conflict++;
43 if (sync_cause & AR_INTR_SYNC_HOST1_FATAL)
44 sc->debug.stats.istats.host1_fatal++;
45 if (sync_cause & AR_INTR_SYNC_HOST1_PERR)
46 sc->debug.stats.istats.host1_perr++;
47 if (sync_cause & AR_INTR_SYNC_TRCV_FIFO_PERR)
48 sc->debug.stats.istats.trcv_fifo_perr++;
49 if (sync_cause & AR_INTR_SYNC_RADM_CPL_EP)
50 sc->debug.stats.istats.radm_cpl_ep++;
51 if (sync_cause & AR_INTR_SYNC_RADM_CPL_DLLP_ABORT)
52 sc->debug.stats.istats.radm_cpl_dllp_abort++;
53 if (sync_cause & AR_INTR_SYNC_RADM_CPL_TLP_ABORT)
54 sc->debug.stats.istats.radm_cpl_tlp_abort++;
55 if (sync_cause & AR_INTR_SYNC_RADM_CPL_ECRC_ERR)
56 sc->debug.stats.istats.radm_cpl_ecrc_err++;
57 if (sync_cause & AR_INTR_SYNC_RADM_CPL_TIMEOUT)
58 sc->debug.stats.istats.radm_cpl_timeout++;
59 if (sync_cause & AR_INTR_SYNC_LOCAL_TIMEOUT)
60 sc->debug.stats.istats.local_timeout++;
61 if (sync_cause & AR_INTR_SYNC_PM_ACCESS)
62 sc->debug.stats.istats.pm_access++;
63 if (sync_cause & AR_INTR_SYNC_MAC_AWAKE)
64 sc->debug.stats.istats.mac_awake++;
65 if (sync_cause & AR_INTR_SYNC_MAC_ASLEEP)
66 sc->debug.stats.istats.mac_asleep++;
67 if (sync_cause & AR_INTR_SYNC_MAC_SLEEP_ACCESS)
68 sc->debug.stats.istats.mac_sleep_access++;
69}
Sujith2a163c62008-11-28 22:21:08 +053070
Vasanthakumar Thiagarajan582d0062011-03-01 05:30:55 -080071static ssize_t ath9k_debugfs_read_buf(struct file *file, char __user *user_buf,
72 size_t count, loff_t *ppos)
73{
74 u8 *buf = file->private_data;
75 return simple_read_from_buffer(user_buf, count, ppos, buf, strlen(buf));
76}
77
78static int ath9k_debugfs_release_buf(struct inode *inode, struct file *file)
79{
80 vfree(file->private_data);
81 return 0;
82}
83
Felix Fietkaua830df02009-11-23 22:33:27 +010084#ifdef CONFIG_ATH_DEBUG
85
Jeff Hansen24939282009-05-27 12:48:29 +000086static ssize_t read_file_debug(struct file *file, char __user *user_buf,
87 size_t count, loff_t *ppos)
88{
89 struct ath_softc *sc = file->private_data;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -070090 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Jeff Hansen24939282009-05-27 12:48:29 +000091 char buf[32];
Vasanthakumar Thiagarajan581f7252009-06-02 19:28:55 +053092 unsigned int len;
93
Dan Carpenter2b87f3a2010-05-14 15:24:37 +020094 len = sprintf(buf, "0x%08x\n", common->debug_mask);
Jeff Hansen24939282009-05-27 12:48:29 +000095 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
96}
97
98static ssize_t write_file_debug(struct file *file, const char __user *user_buf,
99 size_t count, loff_t *ppos)
100{
101 struct ath_softc *sc = file->private_data;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700102 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Jeff Hansen24939282009-05-27 12:48:29 +0000103 unsigned long mask;
104 char buf[32];
Vasanthakumar Thiagarajan581f7252009-06-02 19:28:55 +0530105 ssize_t len;
106
107 len = min(count, sizeof(buf) - 1);
108 if (copy_from_user(buf, user_buf, len))
Dan Carpenter04236062010-05-14 15:25:39 +0200109 return -EFAULT;
Vasanthakumar Thiagarajan581f7252009-06-02 19:28:55 +0530110
111 buf[len] = '\0';
Jingoo Han27d7f472013-05-31 21:24:06 +0000112 if (kstrtoul(buf, 0, &mask))
Vasanthakumar Thiagarajan581f7252009-06-02 19:28:55 +0530113 return -EINVAL;
114
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700115 common->debug_mask = mask;
Jeff Hansen24939282009-05-27 12:48:29 +0000116 return count;
117}
118
119static const struct file_operations fops_debug = {
120 .read = read_file_debug,
121 .write = write_file_debug,
Stephen Boyd234e3402012-04-05 14:25:11 -0700122 .open = simple_open,
Arnd Bergmann6038f372010-08-15 18:52:59 +0200123 .owner = THIS_MODULE,
124 .llseek = default_llseek,
Jeff Hansen24939282009-05-27 12:48:29 +0000125};
126
Felix Fietkaua830df02009-11-23 22:33:27 +0100127#endif
128
Pavel Roskin991a0982010-01-29 17:22:26 -0500129#define DMA_BUF_LEN 1024
130
Felix Fietkau15340692010-05-11 17:23:01 +0200131
Sujith Manoharan6e4d2912013-06-03 09:19:28 +0530132static ssize_t read_file_ani(struct file *file, char __user *user_buf,
Mohammed Shafi Shajakhan05c0be22011-05-26 10:56:15 +0530133 size_t count, loff_t *ppos)
134{
135 struct ath_softc *sc = file->private_data;
136 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Sujith Manoharan6e4d2912013-06-03 09:19:28 +0530137 struct ath_hw *ah = sc->sc_ah;
Joe Perches2120ac92014-02-21 14:46:43 -0800138 unsigned int len = 0;
139 const unsigned int size = 1024;
Sujith Manoharan6e4d2912013-06-03 09:19:28 +0530140 ssize_t retval = 0;
141 char *buf;
Felix Fietkauabee4c82014-03-09 11:27:49 +0100142 int i;
143 struct {
144 const char *name;
145 unsigned int val;
146 } ani_info[] = {
147 { "ANI RESET", ah->stats.ast_ani_reset },
148 { "OFDM LEVEL", ah->ani.ofdmNoiseImmunityLevel },
149 { "CCK LEVEL", ah->ani.cckNoiseImmunityLevel },
150 { "SPUR UP", ah->stats.ast_ani_spurup },
151 { "SPUR DOWN", ah->stats.ast_ani_spurup },
152 { "OFDM WS-DET ON", ah->stats.ast_ani_ofdmon },
153 { "OFDM WS-DET OFF", ah->stats.ast_ani_ofdmoff },
154 { "MRC-CCK ON", ah->stats.ast_ani_ccklow },
155 { "MRC-CCK OFF", ah->stats.ast_ani_cckhigh },
156 { "FIR-STEP UP", ah->stats.ast_ani_stepup },
157 { "FIR-STEP DOWN", ah->stats.ast_ani_stepdown },
158 { "INV LISTENTIME", ah->stats.ast_ani_lneg_or_lzero },
159 { "OFDM ERRORS", ah->stats.ast_ani_ofdmerrs },
160 { "CCK ERRORS", ah->stats.ast_ani_cckerrs },
161 };
Mohammed Shafi Shajakhan05c0be22011-05-26 10:56:15 +0530162
Sujith Manoharan6e4d2912013-06-03 09:19:28 +0530163 buf = kzalloc(size, GFP_KERNEL);
164 if (buf == NULL)
165 return -ENOMEM;
166
Felix Fietkauabee4c82014-03-09 11:27:49 +0100167 len += scnprintf(buf + len, size - len, "%15s: %s\n", "ANI",
168 common->disable_ani ? "DISABLED" : "ENABLED");
Sujith Manoharan6e4d2912013-06-03 09:19:28 +0530169
Felix Fietkauabee4c82014-03-09 11:27:49 +0100170 if (common->disable_ani)
171 goto exit;
172
173 for (i = 0; i < ARRAY_SIZE(ani_info); i++)
174 len += scnprintf(buf + len, size - len, "%15s: %u\n",
175 ani_info[i].name, ani_info[i].val);
176
Sujith Manoharan6e4d2912013-06-03 09:19:28 +0530177exit:
178 if (len > size)
179 len = size;
180
181 retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
182 kfree(buf);
183
184 return retval;
Mohammed Shafi Shajakhan05c0be22011-05-26 10:56:15 +0530185}
186
Sujith Manoharan6e4d2912013-06-03 09:19:28 +0530187static ssize_t write_file_ani(struct file *file,
188 const char __user *user_buf,
189 size_t count, loff_t *ppos)
Mohammed Shafi Shajakhan05c0be22011-05-26 10:56:15 +0530190{
191 struct ath_softc *sc = file->private_data;
192 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Sujith Manoharan6e4d2912013-06-03 09:19:28 +0530193 unsigned long ani;
Mohammed Shafi Shajakhan05c0be22011-05-26 10:56:15 +0530194 char buf[32];
195 ssize_t len;
196
197 len = min(count, sizeof(buf) - 1);
198 if (copy_from_user(buf, user_buf, len))
199 return -EFAULT;
200
201 buf[len] = '\0';
John W. Linville3899ba92013-06-11 14:48:32 -0400202 if (kstrtoul(buf, 0, &ani))
Mohammed Shafi Shajakhan05c0be22011-05-26 10:56:15 +0530203 return -EINVAL;
204
Andrey Utkin3f557202014-07-17 16:56:37 +0300205 if (ani > 1)
Sujith Manoharan6e4d2912013-06-03 09:19:28 +0530206 return -EINVAL;
Mohammed Shafi Shajakhan05c0be22011-05-26 10:56:15 +0530207
Sujith Manoharan6e4d2912013-06-03 09:19:28 +0530208 common->disable_ani = !ani;
209
210 if (common->disable_ani) {
Oleksij Rempeleefa01d2014-02-27 11:40:46 +0100211 clear_bit(ATH_OP_ANI_RUN, &common->op_flags);
Sujith Manoharanda0d45f2012-07-17 17:16:29 +0530212 ath_stop_ani(sc);
Mohammed Shafi Shajakhan05c0be22011-05-26 10:56:15 +0530213 } else {
Sujith Manoharanda0d45f2012-07-17 17:16:29 +0530214 ath_check_ani(sc);
Mohammed Shafi Shajakhan05c0be22011-05-26 10:56:15 +0530215 }
216
217 return count;
218}
219
Sujith Manoharan6e4d2912013-06-03 09:19:28 +0530220static const struct file_operations fops_ani = {
221 .read = read_file_ani,
222 .write = write_file_ani,
Stephen Boyd234e3402012-04-05 14:25:11 -0700223 .open = simple_open,
Mohammed Shafi Shajakhan05c0be22011-05-26 10:56:15 +0530224 .owner = THIS_MODULE,
225 .llseek = default_llseek,
226};
Felix Fietkau15340692010-05-11 17:23:01 +0200227
Sujith Manoharan36e88252013-08-06 12:44:15 +0530228#ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
229
Sujith Manoharan63081302013-08-04 14:21:55 +0530230static ssize_t read_file_bt_ant_diversity(struct file *file,
231 char __user *user_buf,
232 size_t count, loff_t *ppos)
Sujith Manoharan302a3c32012-09-26 07:55:18 +0530233{
234 struct ath_softc *sc = file->private_data;
235 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
236 char buf[32];
237 unsigned int len;
238
Sujith Manoharan63081302013-08-04 14:21:55 +0530239 len = sprintf(buf, "%d\n", common->bt_ant_diversity);
Sujith Manoharan302a3c32012-09-26 07:55:18 +0530240 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
241}
242
Sujith Manoharan63081302013-08-04 14:21:55 +0530243static ssize_t write_file_bt_ant_diversity(struct file *file,
244 const char __user *user_buf,
245 size_t count, loff_t *ppos)
Sujith Manoharan302a3c32012-09-26 07:55:18 +0530246{
247 struct ath_softc *sc = file->private_data;
248 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Sujith Manoharan3f2da952013-08-04 14:21:56 +0530249 struct ath9k_hw_capabilities *pCap = &sc->sc_ah->caps;
Sujith Manoharan63081302013-08-04 14:21:55 +0530250 unsigned long bt_ant_diversity;
Sujith Manoharan302a3c32012-09-26 07:55:18 +0530251 char buf[32];
252 ssize_t len;
253
254 len = min(count, sizeof(buf) - 1);
255 if (copy_from_user(buf, user_buf, len))
256 return -EFAULT;
257
Sujith Manoharan3f2da952013-08-04 14:21:56 +0530258 if (!(pCap->hw_caps & ATH9K_HW_CAP_BT_ANT_DIV))
259 goto exit;
260
Sujith Manoharan302a3c32012-09-26 07:55:18 +0530261 buf[len] = '\0';
Sujith Manoharan63081302013-08-04 14:21:55 +0530262 if (kstrtoul(buf, 0, &bt_ant_diversity))
Sujith Manoharan302a3c32012-09-26 07:55:18 +0530263 return -EINVAL;
264
Sujith Manoharan63081302013-08-04 14:21:55 +0530265 common->bt_ant_diversity = !!bt_ant_diversity;
Sujith Manoharan302a3c32012-09-26 07:55:18 +0530266 ath9k_ps_wakeup(sc);
Sujith Manoharan047dc3a2013-08-05 15:08:26 +0530267 ath9k_hw_set_bt_ant_diversity(sc->sc_ah, common->bt_ant_diversity);
Sujith Manoharan63081302013-08-04 14:21:55 +0530268 ath_dbg(common, CONFIG, "Enable WLAN/BT RX Antenna diversity: %d\n",
269 common->bt_ant_diversity);
Sujith Manoharan302a3c32012-09-26 07:55:18 +0530270 ath9k_ps_restore(sc);
Sujith Manoharan3f2da952013-08-04 14:21:56 +0530271exit:
Sujith Manoharan302a3c32012-09-26 07:55:18 +0530272 return count;
273}
274
Sujith Manoharan63081302013-08-04 14:21:55 +0530275static const struct file_operations fops_bt_ant_diversity = {
276 .read = read_file_bt_ant_diversity,
277 .write = write_file_bt_ant_diversity,
Sujith Manoharan302a3c32012-09-26 07:55:18 +0530278 .open = simple_open,
279 .owner = THIS_MODULE,
280 .llseek = default_llseek,
281};
282
Sujith Manoharan36e88252013-08-06 12:44:15 +0530283#endif
284
Sujith Manoharane3d52912013-08-01 20:57:06 +0530285void ath9k_debug_stat_ant(struct ath_softc *sc,
286 struct ath_hw_antcomb_conf *div_ant_conf,
287 int main_rssi_avg, int alt_rssi_avg)
288{
289 struct ath_antenna_stats *as_main = &sc->debug.stats.ant_stats[ANT_MAIN];
290 struct ath_antenna_stats *as_alt = &sc->debug.stats.ant_stats[ANT_ALT];
291
292 as_main->lna_attempt_cnt[div_ant_conf->main_lna_conf]++;
293 as_alt->lna_attempt_cnt[div_ant_conf->alt_lna_conf]++;
294
295 as_main->rssi_avg = main_rssi_avg;
296 as_alt->rssi_avg = alt_rssi_avg;
297}
298
Sujith Manoharan4eba10c2013-07-29 16:04:49 +0530299static ssize_t read_file_antenna_diversity(struct file *file,
300 char __user *user_buf,
301 size_t count, loff_t *ppos)
302{
303 struct ath_softc *sc = file->private_data;
304 struct ath_hw *ah = sc->sc_ah;
305 struct ath9k_hw_capabilities *pCap = &ah->caps;
306 struct ath_antenna_stats *as_main = &sc->debug.stats.ant_stats[ANT_MAIN];
307 struct ath_antenna_stats *as_alt = &sc->debug.stats.ant_stats[ANT_ALT];
Sujith Manoharane3d52912013-08-01 20:57:06 +0530308 struct ath_hw_antcomb_conf div_ant_conf;
Joe Perches2120ac92014-02-21 14:46:43 -0800309 unsigned int len = 0;
310 const unsigned int size = 1024;
Sujith Manoharan4eba10c2013-07-29 16:04:49 +0530311 ssize_t retval = 0;
312 char *buf;
Joe Perches2120ac92014-02-21 14:46:43 -0800313 static const char *lna_conf_str[4] = {
314 "LNA1_MINUS_LNA2", "LNA2", "LNA1", "LNA1_PLUS_LNA2"
315 };
Sujith Manoharan4eba10c2013-07-29 16:04:49 +0530316
317 buf = kzalloc(size, GFP_KERNEL);
318 if (buf == NULL)
319 return -ENOMEM;
320
321 if (!(pCap->hw_caps & ATH9K_HW_CAP_ANT_DIV_COMB)) {
Zefir Kurtisi5e88ba62013-09-05 14:11:57 +0200322 len += scnprintf(buf + len, size - len, "%s\n",
323 "Antenna Diversity Combining is disabled");
Sujith Manoharan4eba10c2013-07-29 16:04:49 +0530324 goto exit;
325 }
326
Sujith Manoharane3d52912013-08-01 20:57:06 +0530327 ath9k_ps_wakeup(sc);
328 ath9k_hw_antdiv_comb_conf_get(ah, &div_ant_conf);
Zefir Kurtisi5e88ba62013-09-05 14:11:57 +0200329 len += scnprintf(buf + len, size - len, "Current MAIN config : %s\n",
330 lna_conf_str[div_ant_conf.main_lna_conf]);
331 len += scnprintf(buf + len, size - len, "Current ALT config : %s\n",
332 lna_conf_str[div_ant_conf.alt_lna_conf]);
333 len += scnprintf(buf + len, size - len, "Average MAIN RSSI : %d\n",
334 as_main->rssi_avg);
335 len += scnprintf(buf + len, size - len, "Average ALT RSSI : %d\n\n",
336 as_alt->rssi_avg);
Sujith Manoharane3d52912013-08-01 20:57:06 +0530337 ath9k_ps_restore(sc);
338
Zefir Kurtisi5e88ba62013-09-05 14:11:57 +0200339 len += scnprintf(buf + len, size - len, "Packet Receive Cnt:\n");
340 len += scnprintf(buf + len, size - len, "-------------------\n");
Sujith Manoharane3d52912013-08-01 20:57:06 +0530341
Zefir Kurtisi5e88ba62013-09-05 14:11:57 +0200342 len += scnprintf(buf + len, size - len, "%30s%15s\n",
343 "MAIN", "ALT");
344 len += scnprintf(buf + len, size - len, "%-14s:%15d%15d\n",
345 "TOTAL COUNT",
346 as_main->recv_cnt,
347 as_alt->recv_cnt);
348 len += scnprintf(buf + len, size - len, "%-14s:%15d%15d\n",
349 "LNA1",
350 as_main->lna_recv_cnt[ATH_ANT_DIV_COMB_LNA1],
351 as_alt->lna_recv_cnt[ATH_ANT_DIV_COMB_LNA1]);
352 len += scnprintf(buf + len, size - len, "%-14s:%15d%15d\n",
353 "LNA2",
354 as_main->lna_recv_cnt[ATH_ANT_DIV_COMB_LNA2],
355 as_alt->lna_recv_cnt[ATH_ANT_DIV_COMB_LNA2]);
356 len += scnprintf(buf + len, size - len, "%-14s:%15d%15d\n",
357 "LNA1 + LNA2",
358 as_main->lna_recv_cnt[ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2],
359 as_alt->lna_recv_cnt[ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2]);
360 len += scnprintf(buf + len, size - len, "%-14s:%15d%15d\n",
361 "LNA1 - LNA2",
362 as_main->lna_recv_cnt[ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2],
363 as_alt->lna_recv_cnt[ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2]);
Sujith Manoharane3d52912013-08-01 20:57:06 +0530364
Zefir Kurtisi5e88ba62013-09-05 14:11:57 +0200365 len += scnprintf(buf + len, size - len, "\nLNA Config Attempts:\n");
366 len += scnprintf(buf + len, size - len, "--------------------\n");
Sujith Manoharane3d52912013-08-01 20:57:06 +0530367
Zefir Kurtisi5e88ba62013-09-05 14:11:57 +0200368 len += scnprintf(buf + len, size - len, "%30s%15s\n",
369 "MAIN", "ALT");
370 len += scnprintf(buf + len, size - len, "%-14s:%15d%15d\n",
371 "LNA1",
372 as_main->lna_attempt_cnt[ATH_ANT_DIV_COMB_LNA1],
373 as_alt->lna_attempt_cnt[ATH_ANT_DIV_COMB_LNA1]);
374 len += scnprintf(buf + len, size - len, "%-14s:%15d%15d\n",
375 "LNA2",
376 as_main->lna_attempt_cnt[ATH_ANT_DIV_COMB_LNA2],
377 as_alt->lna_attempt_cnt[ATH_ANT_DIV_COMB_LNA2]);
378 len += scnprintf(buf + len, size - len, "%-14s:%15d%15d\n",
379 "LNA1 + LNA2",
380 as_main->lna_attempt_cnt[ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2],
381 as_alt->lna_attempt_cnt[ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2]);
382 len += scnprintf(buf + len, size - len, "%-14s:%15d%15d\n",
383 "LNA1 - LNA2",
384 as_main->lna_attempt_cnt[ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2],
385 as_alt->lna_attempt_cnt[ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2]);
Sujith Manoharane3d52912013-08-01 20:57:06 +0530386
Sujith Manoharan4eba10c2013-07-29 16:04:49 +0530387exit:
388 if (len > size)
389 len = size;
390
391 retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
392 kfree(buf);
393
394 return retval;
395}
396
397static const struct file_operations fops_antenna_diversity = {
398 .read = read_file_antenna_diversity,
399 .open = simple_open,
400 .owner = THIS_MODULE,
401 .llseek = default_llseek,
402};
403
Arend van Spriel631bee22014-11-09 11:31:59 +0100404static int read_file_dma(struct seq_file *file, void *data)
Sujith2a163c62008-11-28 22:21:08 +0530405{
Arend van Spriel4447d812014-12-27 14:13:00 +0100406 struct ieee80211_hw *hw = dev_get_drvdata(file->private);
407 struct ath_softc *sc = hw->priv;
Sujithcbe61d82009-02-09 13:27:12 +0530408 struct ath_hw *ah = sc->sc_ah;
Sujith2a163c62008-11-28 22:21:08 +0530409 u32 val[ATH9K_NUM_DMA_DEBUG_REGS];
410 int i, qcuOffset = 0, dcuOffset = 0;
411 u32 *qcuBase = &val[0], *dcuBase = &val[4];
412
Sujith7cf4a2e2009-08-26 11:11:57 +0530413 ath9k_ps_wakeup(sc);
414
Luis R. Rodriguez475a6e42009-09-23 23:06:59 -0400415 REG_WRITE_D(ah, AR_MACMISC,
Sujith2a163c62008-11-28 22:21:08 +0530416 ((AR_MACMISC_DMA_OBS_LINE_8 << AR_MACMISC_DMA_OBS_S) |
417 (AR_MACMISC_MISC_OBS_BUS_1 <<
418 AR_MACMISC_MISC_OBS_BUS_MSB_S)));
419
Arend van Spriel631bee22014-11-09 11:31:59 +0100420 seq_puts(file, "Raw DMA Debug values:\n");
Sujith2a163c62008-11-28 22:21:08 +0530421
422 for (i = 0; i < ATH9K_NUM_DMA_DEBUG_REGS; i++) {
423 if (i % 4 == 0)
Arend van Spriel631bee22014-11-09 11:31:59 +0100424 seq_puts(file, "\n");
Sujith2a163c62008-11-28 22:21:08 +0530425
Luis R. Rodriguez475a6e42009-09-23 23:06:59 -0400426 val[i] = REG_READ_D(ah, AR_DMADBG_0 + (i * sizeof(u32)));
Arend van Spriel631bee22014-11-09 11:31:59 +0100427 seq_printf(file, "%d: %08x ", i, val[i]);
Sujith2a163c62008-11-28 22:21:08 +0530428 }
429
Arend van Spriel631bee22014-11-09 11:31:59 +0100430 seq_puts(file, "\n\n");
431 seq_puts(file, "Num QCU: chain_st fsp_ok fsp_st DCU: chain_st\n");
Sujith2a163c62008-11-28 22:21:08 +0530432
433 for (i = 0; i < ATH9K_NUM_QUEUES; i++, qcuOffset += 4, dcuOffset += 5) {
434 if (i == 8) {
435 qcuOffset = 0;
436 qcuBase++;
437 }
438
439 if (i == 6) {
440 dcuOffset = 0;
441 dcuBase++;
442 }
443
Arend van Spriel631bee22014-11-09 11:31:59 +0100444 seq_printf(file, "%2d %2x %1x %2x %2x\n",
445 i, (*qcuBase & (0x7 << qcuOffset)) >> qcuOffset,
446 (*qcuBase & (0x8 << qcuOffset)) >> (qcuOffset + 3),
447 (val[2] & (0x7 << (i * 3))) >> (i * 3),
448 (*dcuBase & (0x1f << dcuOffset)) >> dcuOffset);
Sujith2a163c62008-11-28 22:21:08 +0530449 }
450
Arend van Spriel631bee22014-11-09 11:31:59 +0100451 seq_puts(file, "\n");
Sujith2a163c62008-11-28 22:21:08 +0530452
Arend van Spriel631bee22014-11-09 11:31:59 +0100453 seq_printf(file, "qcu_stitch state: %2x qcu_fetch state: %2x\n",
454 (val[3] & 0x003c0000) >> 18, (val[3] & 0x03c00000) >> 22);
455 seq_printf(file, "qcu_complete state: %2x dcu_complete state: %2x\n",
456 (val[3] & 0x1c000000) >> 26, (val[6] & 0x3));
457 seq_printf(file, "dcu_arb state: %2x dcu_fp state: %2x\n",
458 (val[5] & 0x06000000) >> 25, (val[5] & 0x38000000) >> 27);
459 seq_printf(file, "chan_idle_dur: %3d chan_idle_dur_valid: %1d\n",
460 (val[6] & 0x000003fc) >> 2, (val[6] & 0x00000400) >> 10);
461 seq_printf(file, "txfifo_valid_0: %1d txfifo_valid_1: %1d\n",
462 (val[6] & 0x00000800) >> 11, (val[6] & 0x00001000) >> 12);
463 seq_printf(file, "txfifo_dcu_num_0: %2d txfifo_dcu_num_1: %2d\n",
464 (val[6] & 0x0001e000) >> 13, (val[6] & 0x001e0000) >> 17);
Sujith2a163c62008-11-28 22:21:08 +0530465
Arend van Spriel631bee22014-11-09 11:31:59 +0100466 seq_printf(file, "pcu observe: 0x%x\n", REG_READ_D(ah, AR_OBS_BUS_1));
467 seq_printf(file, "AR_CR: 0x%x\n", REG_READ_D(ah, AR_CR));
Sujith2a163c62008-11-28 22:21:08 +0530468
Sujith7cf4a2e2009-08-26 11:11:57 +0530469 ath9k_ps_restore(sc);
470
Arend van Spriel631bee22014-11-09 11:31:59 +0100471 return 0;
472}
Dan Carpenter2b87f3a2010-05-14 15:24:37 +0200473
Sujith817e11d2008-12-07 21:42:44 +0530474void ath_debug_stat_interrupt(struct ath_softc *sc, enum ath9k_int status)
475{
476 if (status)
Sujith17d79042009-02-09 13:27:03 +0530477 sc->debug.stats.istats.total++;
Luis R. Rodrigueza9616f42010-04-15 17:39:30 -0400478 if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) {
479 if (status & ATH9K_INT_RXLP)
480 sc->debug.stats.istats.rxlp++;
481 if (status & ATH9K_INT_RXHP)
482 sc->debug.stats.istats.rxhp++;
Luis R. Rodriguez08578b82010-05-13 13:33:44 -0400483 if (status & ATH9K_INT_BB_WATCHDOG)
484 sc->debug.stats.istats.bb_watchdog++;
Luis R. Rodrigueza9616f42010-04-15 17:39:30 -0400485 } else {
486 if (status & ATH9K_INT_RX)
487 sc->debug.stats.istats.rxok++;
488 }
Sujith817e11d2008-12-07 21:42:44 +0530489 if (status & ATH9K_INT_RXEOL)
Sujith17d79042009-02-09 13:27:03 +0530490 sc->debug.stats.istats.rxeol++;
Sujith817e11d2008-12-07 21:42:44 +0530491 if (status & ATH9K_INT_RXORN)
Sujith17d79042009-02-09 13:27:03 +0530492 sc->debug.stats.istats.rxorn++;
Sujith817e11d2008-12-07 21:42:44 +0530493 if (status & ATH9K_INT_TX)
Sujith17d79042009-02-09 13:27:03 +0530494 sc->debug.stats.istats.txok++;
Sujith817e11d2008-12-07 21:42:44 +0530495 if (status & ATH9K_INT_TXURN)
Sujith17d79042009-02-09 13:27:03 +0530496 sc->debug.stats.istats.txurn++;
Sujith817e11d2008-12-07 21:42:44 +0530497 if (status & ATH9K_INT_RXPHY)
Sujith17d79042009-02-09 13:27:03 +0530498 sc->debug.stats.istats.rxphyerr++;
Sujith817e11d2008-12-07 21:42:44 +0530499 if (status & ATH9K_INT_RXKCM)
Sujith17d79042009-02-09 13:27:03 +0530500 sc->debug.stats.istats.rx_keycache_miss++;
Sujith817e11d2008-12-07 21:42:44 +0530501 if (status & ATH9K_INT_SWBA)
Sujith17d79042009-02-09 13:27:03 +0530502 sc->debug.stats.istats.swba++;
Sujith817e11d2008-12-07 21:42:44 +0530503 if (status & ATH9K_INT_BMISS)
Sujith17d79042009-02-09 13:27:03 +0530504 sc->debug.stats.istats.bmiss++;
Sujith817e11d2008-12-07 21:42:44 +0530505 if (status & ATH9K_INT_BNR)
Sujith17d79042009-02-09 13:27:03 +0530506 sc->debug.stats.istats.bnr++;
Sujith817e11d2008-12-07 21:42:44 +0530507 if (status & ATH9K_INT_CST)
Sujith17d79042009-02-09 13:27:03 +0530508 sc->debug.stats.istats.cst++;
Sujith817e11d2008-12-07 21:42:44 +0530509 if (status & ATH9K_INT_GTT)
Sujith17d79042009-02-09 13:27:03 +0530510 sc->debug.stats.istats.gtt++;
Sujith817e11d2008-12-07 21:42:44 +0530511 if (status & ATH9K_INT_TIM)
Sujith17d79042009-02-09 13:27:03 +0530512 sc->debug.stats.istats.tim++;
Sujith817e11d2008-12-07 21:42:44 +0530513 if (status & ATH9K_INT_CABEND)
Sujith17d79042009-02-09 13:27:03 +0530514 sc->debug.stats.istats.cabend++;
Sujith817e11d2008-12-07 21:42:44 +0530515 if (status & ATH9K_INT_DTIMSYNC)
Sujith17d79042009-02-09 13:27:03 +0530516 sc->debug.stats.istats.dtimsync++;
Sujith817e11d2008-12-07 21:42:44 +0530517 if (status & ATH9K_INT_DTIM)
Sujith17d79042009-02-09 13:27:03 +0530518 sc->debug.stats.istats.dtim++;
Mohammed Shafi Shajakhan6dde1aa2011-04-22 17:27:01 +0530519 if (status & ATH9K_INT_TSFOOR)
520 sc->debug.stats.istats.tsfoor++;
Sujith Manoharan97ba5152012-06-04 16:27:41 +0530521 if (status & ATH9K_INT_MCI)
522 sc->debug.stats.istats.mci++;
Mohammed Shafi Shajakhanc9e6e982012-09-07 15:54:13 +0530523 if (status & ATH9K_INT_GENTIMER)
524 sc->debug.stats.istats.gen_timer++;
Sujith817e11d2008-12-07 21:42:44 +0530525}
526
Arend van Spriel631bee22014-11-09 11:31:59 +0100527static int read_file_interrupt(struct seq_file *file, void *data)
Sujith817e11d2008-12-07 21:42:44 +0530528{
Arend van Spriel4447d812014-12-27 14:13:00 +0100529 struct ieee80211_hw *hw = dev_get_drvdata(file->private);
530 struct ath_softc *sc = hw->priv;
Ben Greear462e58f2012-04-12 10:04:00 -0700531
532#define PR_IS(a, s) \
533 do { \
Arend van Spriel631bee22014-11-09 11:31:59 +0100534 seq_printf(file, "%21s: %10u\n", a, \
535 sc->debug.stats.istats.s); \
Ben Greear462e58f2012-04-12 10:04:00 -0700536 } while (0)
Sujith817e11d2008-12-07 21:42:44 +0530537
Luis R. Rodrigueza9616f42010-04-15 17:39:30 -0400538 if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) {
Ben Greear462e58f2012-04-12 10:04:00 -0700539 PR_IS("RXLP", rxlp);
540 PR_IS("RXHP", rxhp);
541 PR_IS("WATHDOG", bb_watchdog);
Luis R. Rodrigueza9616f42010-04-15 17:39:30 -0400542 } else {
Ben Greear462e58f2012-04-12 10:04:00 -0700543 PR_IS("RX", rxok);
Luis R. Rodrigueza9616f42010-04-15 17:39:30 -0400544 }
Ben Greear462e58f2012-04-12 10:04:00 -0700545 PR_IS("RXEOL", rxeol);
546 PR_IS("RXORN", rxorn);
547 PR_IS("TX", txok);
548 PR_IS("TXURN", txurn);
549 PR_IS("MIB", mib);
550 PR_IS("RXPHY", rxphyerr);
551 PR_IS("RXKCM", rx_keycache_miss);
552 PR_IS("SWBA", swba);
553 PR_IS("BMISS", bmiss);
554 PR_IS("BNR", bnr);
555 PR_IS("CST", cst);
556 PR_IS("GTT", gtt);
557 PR_IS("TIM", tim);
558 PR_IS("CABEND", cabend);
559 PR_IS("DTIMSYNC", dtimsync);
560 PR_IS("DTIM", dtim);
561 PR_IS("TSFOOR", tsfoor);
Sujith Manoharan97ba5152012-06-04 16:27:41 +0530562 PR_IS("MCI", mci);
Mohammed Shafi Shajakhanc9e6e982012-09-07 15:54:13 +0530563 PR_IS("GENTIMER", gen_timer);
Ben Greear462e58f2012-04-12 10:04:00 -0700564 PR_IS("TOTAL", total);
Sujith817e11d2008-12-07 21:42:44 +0530565
Arend van Spriel631bee22014-11-09 11:31:59 +0100566 seq_puts(file, "SYNC_CAUSE stats:\n");
Mohammed Shafi Shajakhan6dde1aa2011-04-22 17:27:01 +0530567
Ben Greear462e58f2012-04-12 10:04:00 -0700568 PR_IS("Sync-All", sync_cause_all);
569 PR_IS("RTC-IRQ", sync_rtc_irq);
570 PR_IS("MAC-IRQ", sync_mac_irq);
571 PR_IS("EEPROM-Illegal-Access", eeprom_illegal_access);
572 PR_IS("APB-Timeout", apb_timeout);
573 PR_IS("PCI-Mode-Conflict", pci_mode_conflict);
574 PR_IS("HOST1-Fatal", host1_fatal);
575 PR_IS("HOST1-Perr", host1_perr);
576 PR_IS("TRCV-FIFO-Perr", trcv_fifo_perr);
577 PR_IS("RADM-CPL-EP", radm_cpl_ep);
578 PR_IS("RADM-CPL-DLLP-Abort", radm_cpl_dllp_abort);
579 PR_IS("RADM-CPL-TLP-Abort", radm_cpl_tlp_abort);
580 PR_IS("RADM-CPL-ECRC-Err", radm_cpl_ecrc_err);
581 PR_IS("RADM-CPL-Timeout", radm_cpl_timeout);
582 PR_IS("Local-Bus-Timeout", local_timeout);
583 PR_IS("PM-Access", pm_access);
584 PR_IS("MAC-Awake", mac_awake);
585 PR_IS("MAC-Asleep", mac_asleep);
586 PR_IS("MAC-Sleep-Access", mac_sleep_access);
Dan Carpenter2b87f3a2010-05-14 15:24:37 +0200587
Arend van Spriel631bee22014-11-09 11:31:59 +0100588 return 0;
589}
Ben Greear462e58f2012-04-12 10:04:00 -0700590
Arend van Spriel631bee22014-11-09 11:31:59 +0100591static int read_file_xmit(struct seq_file *file, void *data)
Sujithfec247c2009-07-27 12:08:16 +0530592{
Arend van Spriel4447d812014-12-27 14:13:00 +0100593 struct ieee80211_hw *hw = dev_get_drvdata(file->private);
594 struct ath_softc *sc = hw->priv;
Sujithfec247c2009-07-27 12:08:16 +0530595
Arend van Spriel631bee22014-11-09 11:31:59 +0100596 seq_printf(file, "%30s %10s%10s%10s\n\n", "BE", "BK", "VI", "VO");
Sujithfec247c2009-07-27 12:08:16 +0530597
598 PR("MPDUs Queued: ", queued);
599 PR("MPDUs Completed: ", completed);
Felix Fietkau5a6f78a2011-05-31 21:21:41 +0200600 PR("MPDUs XRetried: ", xretries);
Sujithfec247c2009-07-27 12:08:16 +0530601 PR("Aggregates: ", a_aggr);
Ben Greearbda8add2011-01-09 23:11:48 -0800602 PR("AMPDUs Queued HW:", a_queued_hw);
603 PR("AMPDUs Queued SW:", a_queued_sw);
Sujithfec247c2009-07-27 12:08:16 +0530604 PR("AMPDUs Completed:", a_completed);
605 PR("AMPDUs Retried: ", a_retries);
606 PR("AMPDUs XRetried: ", a_xretries);
Ben Greear4d900382013-03-04 15:31:16 -0800607 PR("TXERR Filtered: ", txerr_filtered);
Sujithfec247c2009-07-27 12:08:16 +0530608 PR("FIFO Underrun: ", fifo_underrun);
609 PR("TXOP Exceeded: ", xtxop);
610 PR("TXTIMER Expiry: ", timer_exp);
611 PR("DESC CFG Error: ", desc_cfg_err);
612 PR("DATA Underrun: ", data_underrun);
613 PR("DELIM Underrun: ", delim_underrun);
Ben Greear99c15bf2010-10-01 12:26:30 -0700614 PR("TX-Pkts-All: ", tx_pkts_all);
615 PR("TX-Bytes-All: ", tx_bytes_all);
Sujith Manoharan78ef7312012-11-21 18:13:11 +0530616 PR("HW-put-tx-buf: ", puttxbuf);
617 PR("HW-tx-start: ", txstart);
618 PR("HW-tx-proc-desc: ", txprocdesc);
Ben Greeara5a0bca2012-04-03 09:16:55 -0700619 PR("TX-Failed: ", txfailed);
Sujithfec247c2009-07-27 12:08:16 +0530620
Arend van Spriel631bee22014-11-09 11:31:59 +0100621 return 0;
Ben Greear7f010c92011-01-09 23:11:49 -0800622}
623
Arend van Spriel631bee22014-11-09 11:31:59 +0100624static void print_queue(struct ath_softc *sc, struct ath_txq *txq,
625 struct seq_file *file)
Felix Fietkau18fcf1c2013-08-06 14:18:05 +0200626{
Felix Fietkau18fcf1c2013-08-06 14:18:05 +0200627 ath_txq_lock(sc, txq);
628
Arend van Spriel631bee22014-11-09 11:31:59 +0100629 seq_printf(file, "%s: %d ", "qnum", txq->axq_qnum);
630 seq_printf(file, "%s: %2d ", "qdepth", txq->axq_depth);
631 seq_printf(file, "%s: %2d ", "ampdu-depth", txq->axq_ampdu_depth);
632 seq_printf(file, "%s: %3d ", "pending", txq->pending_frames);
633 seq_printf(file, "%s: %d\n", "stopped", txq->stopped);
Felix Fietkau18fcf1c2013-08-06 14:18:05 +0200634
635 ath_txq_unlock(sc, txq);
Felix Fietkau18fcf1c2013-08-06 14:18:05 +0200636}
637
Arend van Spriel631bee22014-11-09 11:31:59 +0100638static int read_file_queues(struct seq_file *file, void *data)
Sujith Manoharanc0b74872012-11-21 18:13:12 +0530639{
Arend van Spriel4447d812014-12-27 14:13:00 +0100640 struct ieee80211_hw *hw = dev_get_drvdata(file->private);
641 struct ath_softc *sc = hw->priv;
Sujith Manoharanc0b74872012-11-21 18:13:12 +0530642 struct ath_txq *txq;
Sujith Manoharanc0b74872012-11-21 18:13:12 +0530643 int i;
Joe Perches2120ac92014-02-21 14:46:43 -0800644 static const char *qname[4] = {
645 "VO", "VI", "BE", "BK"
646 };
Sujith Manoharanc0b74872012-11-21 18:13:12 +0530647
Sujith Manoharanc0b74872012-11-21 18:13:12 +0530648 for (i = 0; i < IEEE80211_NUM_ACS; i++) {
649 txq = sc->tx.txq_map[i];
Arend van Spriel631bee22014-11-09 11:31:59 +0100650 seq_printf(file, "(%s): ", qname[i]);
651 print_queue(sc, txq, file);
Sujith Manoharanc0b74872012-11-21 18:13:12 +0530652 }
653
Arend van Spriel631bee22014-11-09 11:31:59 +0100654 seq_puts(file, "(CAB): ");
655 print_queue(sc, sc->beacon.cabq, file);
Felix Fietkau18fcf1c2013-08-06 14:18:05 +0200656
Arend van Spriel631bee22014-11-09 11:31:59 +0100657 return 0;
Sujith Manoharanc0b74872012-11-21 18:13:12 +0530658}
659
Arend van Spriel631bee22014-11-09 11:31:59 +0100660static int read_file_misc(struct seq_file *file, void *data)
Ben Greear55f6d0f2011-01-17 11:54:50 -0800661{
Arend van Spriel4447d812014-12-27 14:13:00 +0100662 struct ieee80211_hw *hw = dev_get_drvdata(file->private);
663 struct ath_softc *sc = hw->priv;
Ben Greear55f6d0f2011-01-17 11:54:50 -0800664 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Sujith Manoharan6bcf6f62012-02-16 11:51:02 +0530665 struct ath9k_vif_iter_data iter_data;
Rajkumar Manoharan9a9c4fb2014-06-11 16:18:03 +0530666 struct ath_chanctx *ctx;
Ben Greear55f6d0f2011-01-17 11:54:50 -0800667 unsigned int reg;
Rajkumar Manoharan9a9c4fb2014-06-11 16:18:03 +0530668 u32 rxfilter, i;
Ben Greear55f6d0f2011-01-17 11:54:50 -0800669
Arend van Spriel631bee22014-11-09 11:31:59 +0100670 seq_printf(file, "BSSID: %pM\n", common->curbssid);
671 seq_printf(file, "BSSID-MASK: %pM\n", common->bssidmask);
672 seq_printf(file, "OPMODE: %s\n",
673 ath_opmode_to_string(sc->sc_ah->opmode));
Ben Greear55f6d0f2011-01-17 11:54:50 -0800674
Rajkumar Manoharan79d2b152011-05-16 18:23:23 +0530675 ath9k_ps_wakeup(sc);
Sujith Manoharan6bcf6f62012-02-16 11:51:02 +0530676 rxfilter = ath9k_hw_getrxfilter(sc->sc_ah);
Rajkumar Manoharan79d2b152011-05-16 18:23:23 +0530677 ath9k_ps_restore(sc);
Sujith Manoharan6bcf6f62012-02-16 11:51:02 +0530678
Arend van Spriel631bee22014-11-09 11:31:59 +0100679 seq_printf(file, "RXFILTER: 0x%x", rxfilter);
Sujith Manoharan6bcf6f62012-02-16 11:51:02 +0530680
681 if (rxfilter & ATH9K_RX_FILTER_UCAST)
Arend van Spriel631bee22014-11-09 11:31:59 +0100682 seq_puts(file, " UCAST");
Sujith Manoharan6bcf6f62012-02-16 11:51:02 +0530683 if (rxfilter & ATH9K_RX_FILTER_MCAST)
Arend van Spriel631bee22014-11-09 11:31:59 +0100684 seq_puts(file, " MCAST");
Sujith Manoharan6bcf6f62012-02-16 11:51:02 +0530685 if (rxfilter & ATH9K_RX_FILTER_BCAST)
Arend van Spriel631bee22014-11-09 11:31:59 +0100686 seq_puts(file, " BCAST");
Sujith Manoharan6bcf6f62012-02-16 11:51:02 +0530687 if (rxfilter & ATH9K_RX_FILTER_CONTROL)
Arend van Spriel631bee22014-11-09 11:31:59 +0100688 seq_puts(file, " CONTROL");
Sujith Manoharan6bcf6f62012-02-16 11:51:02 +0530689 if (rxfilter & ATH9K_RX_FILTER_BEACON)
Arend van Spriel631bee22014-11-09 11:31:59 +0100690 seq_puts(file, " BEACON");
Sujith Manoharan6bcf6f62012-02-16 11:51:02 +0530691 if (rxfilter & ATH9K_RX_FILTER_PROM)
Arend van Spriel631bee22014-11-09 11:31:59 +0100692 seq_puts(file, " PROM");
Sujith Manoharan6bcf6f62012-02-16 11:51:02 +0530693 if (rxfilter & ATH9K_RX_FILTER_PROBEREQ)
Arend van Spriel631bee22014-11-09 11:31:59 +0100694 seq_puts(file, " PROBEREQ");
Sujith Manoharan6bcf6f62012-02-16 11:51:02 +0530695 if (rxfilter & ATH9K_RX_FILTER_PHYERR)
Arend van Spriel631bee22014-11-09 11:31:59 +0100696 seq_puts(file, " PHYERR");
Sujith Manoharan6bcf6f62012-02-16 11:51:02 +0530697 if (rxfilter & ATH9K_RX_FILTER_MYBEACON)
Arend van Spriel631bee22014-11-09 11:31:59 +0100698 seq_puts(file, " MYBEACON");
Sujith Manoharan6bcf6f62012-02-16 11:51:02 +0530699 if (rxfilter & ATH9K_RX_FILTER_COMP_BAR)
Arend van Spriel631bee22014-11-09 11:31:59 +0100700 seq_puts(file, " COMP_BAR");
Sujith Manoharan6bcf6f62012-02-16 11:51:02 +0530701 if (rxfilter & ATH9K_RX_FILTER_PSPOLL)
Arend van Spriel631bee22014-11-09 11:31:59 +0100702 seq_puts(file, " PSPOLL");
Sujith Manoharan6bcf6f62012-02-16 11:51:02 +0530703 if (rxfilter & ATH9K_RX_FILTER_PHYRADAR)
Arend van Spriel631bee22014-11-09 11:31:59 +0100704 seq_puts(file, " PHYRADAR");
Sujith Manoharan6bcf6f62012-02-16 11:51:02 +0530705 if (rxfilter & ATH9K_RX_FILTER_MCAST_BCAST_ALL)
Arend van Spriel631bee22014-11-09 11:31:59 +0100706 seq_puts(file, " MCAST_BCAST_ALL");
Sujith Manoharan6bcf6f62012-02-16 11:51:02 +0530707 if (rxfilter & ATH9K_RX_FILTER_CONTROL_WRAPPER)
Arend van Spriel631bee22014-11-09 11:31:59 +0100708 seq_puts(file, " CONTROL_WRAPPER");
Sujith Manoharan6bcf6f62012-02-16 11:51:02 +0530709
Arend van Spriel631bee22014-11-09 11:31:59 +0100710 seq_puts(file, "\n");
Ben Greear55f6d0f2011-01-17 11:54:50 -0800711
712 reg = sc->sc_ah->imask;
Ben Greear55f6d0f2011-01-17 11:54:50 -0800713
Arend van Spriel631bee22014-11-09 11:31:59 +0100714 seq_printf(file, "INTERRUPT-MASK: 0x%x", reg);
Sujith Manoharan6bcf6f62012-02-16 11:51:02 +0530715
716 if (reg & ATH9K_INT_SWBA)
Arend van Spriel631bee22014-11-09 11:31:59 +0100717 seq_puts(file, " SWBA");
Sujith Manoharan6bcf6f62012-02-16 11:51:02 +0530718 if (reg & ATH9K_INT_BMISS)
Arend van Spriel631bee22014-11-09 11:31:59 +0100719 seq_puts(file, " BMISS");
Sujith Manoharan6bcf6f62012-02-16 11:51:02 +0530720 if (reg & ATH9K_INT_CST)
Arend van Spriel631bee22014-11-09 11:31:59 +0100721 seq_puts(file, " CST");
Sujith Manoharan6bcf6f62012-02-16 11:51:02 +0530722 if (reg & ATH9K_INT_RX)
Arend van Spriel631bee22014-11-09 11:31:59 +0100723 seq_puts(file, " RX");
Sujith Manoharan6bcf6f62012-02-16 11:51:02 +0530724 if (reg & ATH9K_INT_RXHP)
Arend van Spriel631bee22014-11-09 11:31:59 +0100725 seq_puts(file, " RXHP");
Sujith Manoharan6bcf6f62012-02-16 11:51:02 +0530726 if (reg & ATH9K_INT_RXLP)
Arend van Spriel631bee22014-11-09 11:31:59 +0100727 seq_puts(file, " RXLP");
Sujith Manoharan6bcf6f62012-02-16 11:51:02 +0530728 if (reg & ATH9K_INT_BB_WATCHDOG)
Arend van Spriel631bee22014-11-09 11:31:59 +0100729 seq_puts(file, " BB_WATCHDOG");
Sujith Manoharan6bcf6f62012-02-16 11:51:02 +0530730
Arend van Spriel631bee22014-11-09 11:31:59 +0100731 seq_puts(file, "\n");
Sujith Manoharan6bcf6f62012-02-16 11:51:02 +0530732
Rajkumar Manoharan9a9c4fb2014-06-11 16:18:03 +0530733 i = 0;
734 ath_for_each_chanctx(sc, ctx) {
Ben Greear325e1882014-11-04 15:22:49 -0800735 if (list_empty(&ctx->vifs))
Rajkumar Manoharan9a9c4fb2014-06-11 16:18:03 +0530736 continue;
737 ath9k_calculate_iter_data(sc, ctx, &iter_data);
Sujith Manoharan6bcf6f62012-02-16 11:51:02 +0530738
Arend van Spriel631bee22014-11-09 11:31:59 +0100739 seq_printf(file,
Linus Torvaldse6b5be22014-12-14 16:10:09 -0800740 "VIFS: CTX %i(%i) AP: %i STA: %i MESH: %i WDS: %i",
741 i++, (int)(ctx->assigned), iter_data.naps,
742 iter_data.nstations,
Arend van Spriel631bee22014-11-09 11:31:59 +0100743 iter_data.nmeshes, iter_data.nwds);
744 seq_printf(file, " ADHOC: %i TOTAL: %hi BEACON-VIF: %hi\n",
745 iter_data.nadhocs, sc->cur_chan->nvifs,
746 sc->nbcnvifs);
Rajkumar Manoharan9a9c4fb2014-06-11 16:18:03 +0530747 }
Ben Greear55f6d0f2011-01-17 11:54:50 -0800748
Arend van Spriel631bee22014-11-09 11:31:59 +0100749 return 0;
Ben Greear55f6d0f2011-01-17 11:54:50 -0800750}
751
Arend van Spriel631bee22014-11-09 11:31:59 +0100752static int read_file_reset(struct seq_file *file, void *data)
Sujith Manoharanf8b815d2012-02-16 11:51:11 +0530753{
Arend van Spriel4447d812014-12-27 14:13:00 +0100754 struct ieee80211_hw *hw = dev_get_drvdata(file->private);
755 struct ath_softc *sc = hw->priv;
Felix Fietkau70e535e2014-10-25 17:19:29 +0200756 static const char * const reset_cause[__RESET_TYPE_MAX] = {
757 [RESET_TYPE_BB_HANG] = "Baseband Hang",
758 [RESET_TYPE_BB_WATCHDOG] = "Baseband Watchdog",
759 [RESET_TYPE_FATAL_INT] = "Fatal HW Error",
760 [RESET_TYPE_TX_ERROR] = "TX HW error",
761 [RESET_TYPE_TX_GTT] = "Transmit timeout",
762 [RESET_TYPE_TX_HANG] = "TX Path Hang",
763 [RESET_TYPE_PLL_HANG] = "PLL RX Hang",
764 [RESET_TYPE_MAC_HANG] = "MAC Hang",
765 [RESET_TYPE_BEACON_STUCK] = "Stuck Beacon",
766 [RESET_TYPE_MCI] = "MCI Reset",
Felix Fietkau7b8aaea2014-10-25 17:19:30 +0200767 [RESET_TYPE_CALIBRATION] = "Calibration error",
Felix Fietkau70e535e2014-10-25 17:19:29 +0200768 };
Felix Fietkau70e535e2014-10-25 17:19:29 +0200769 int i;
Sujith Manoharanf8b815d2012-02-16 11:51:11 +0530770
Felix Fietkau70e535e2014-10-25 17:19:29 +0200771 for (i = 0; i < ARRAY_SIZE(reset_cause); i++) {
772 if (!reset_cause[i])
773 continue;
774
Linus Torvaldse6b5be22014-12-14 16:10:09 -0800775 seq_printf(file, "%17s: %2d\n", reset_cause[i],
776 sc->debug.stats.reset[i]);
Felix Fietkau70e535e2014-10-25 17:19:29 +0200777 }
Sujith Manoharanf8b815d2012-02-16 11:51:11 +0530778
Arend van Spriel631bee22014-11-09 11:31:59 +0100779 return 0;
Sujith Manoharanf8b815d2012-02-16 11:51:11 +0530780}
781
Felix Fietkau066dae92010-11-07 14:59:39 +0100782void ath_debug_stat_tx(struct ath_softc *sc, struct ath_buf *bf,
Felix Fietkau55797b12011-09-14 21:24:16 +0200783 struct ath_tx_status *ts, struct ath_txq *txq,
784 unsigned int flags)
Sujithfec247c2009-07-27 12:08:16 +0530785{
Felix Fietkau5bec3e52011-01-24 21:29:25 +0100786 int qnum = txq->axq_qnum;
Felix Fietkau066dae92010-11-07 14:59:39 +0100787
788 TX_STAT_INC(qnum, tx_pkts_all);
789 sc->debug.stats.txstats[qnum].tx_bytes_all += bf->bf_mpdu->len;
Ben Greear99c15bf2010-10-01 12:26:30 -0700790
Sujithfec247c2009-07-27 12:08:16 +0530791 if (bf_isampdu(bf)) {
Felix Fietkau156369f2011-12-14 22:08:04 +0100792 if (flags & ATH_TX_ERROR)
Felix Fietkau066dae92010-11-07 14:59:39 +0100793 TX_STAT_INC(qnum, a_xretries);
Sujithfec247c2009-07-27 12:08:16 +0530794 else
Felix Fietkau066dae92010-11-07 14:59:39 +0100795 TX_STAT_INC(qnum, a_completed);
Sujithfec247c2009-07-27 12:08:16 +0530796 } else {
Felix Fietkau55797b12011-09-14 21:24:16 +0200797 if (ts->ts_status & ATH9K_TXERR_XRETRY)
Felix Fietkau5a6f78a2011-05-31 21:21:41 +0200798 TX_STAT_INC(qnum, xretries);
799 else
800 TX_STAT_INC(qnum, completed);
Sujithfec247c2009-07-27 12:08:16 +0530801 }
802
Ben Greear4d900382013-03-04 15:31:16 -0800803 if (ts->ts_status & ATH9K_TXERR_FILT)
804 TX_STAT_INC(qnum, txerr_filtered);
Felix Fietkaudb1a0522010-03-29 20:07:11 -0700805 if (ts->ts_status & ATH9K_TXERR_FIFO)
Felix Fietkau066dae92010-11-07 14:59:39 +0100806 TX_STAT_INC(qnum, fifo_underrun);
Felix Fietkaudb1a0522010-03-29 20:07:11 -0700807 if (ts->ts_status & ATH9K_TXERR_XTXOP)
Felix Fietkau066dae92010-11-07 14:59:39 +0100808 TX_STAT_INC(qnum, xtxop);
Felix Fietkaudb1a0522010-03-29 20:07:11 -0700809 if (ts->ts_status & ATH9K_TXERR_TIMER_EXPIRED)
Felix Fietkau066dae92010-11-07 14:59:39 +0100810 TX_STAT_INC(qnum, timer_exp);
Felix Fietkaudb1a0522010-03-29 20:07:11 -0700811 if (ts->ts_flags & ATH9K_TX_DESC_CFG_ERR)
Felix Fietkau066dae92010-11-07 14:59:39 +0100812 TX_STAT_INC(qnum, desc_cfg_err);
Felix Fietkaudb1a0522010-03-29 20:07:11 -0700813 if (ts->ts_flags & ATH9K_TX_DATA_UNDERRUN)
Felix Fietkau066dae92010-11-07 14:59:39 +0100814 TX_STAT_INC(qnum, data_underrun);
Felix Fietkaudb1a0522010-03-29 20:07:11 -0700815 if (ts->ts_flags & ATH9K_TX_DELIM_UNDERRUN)
Felix Fietkau066dae92010-11-07 14:59:39 +0100816 TX_STAT_INC(qnum, delim_underrun);
Sujithfec247c2009-07-27 12:08:16 +0530817}
818
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -0700819void ath_debug_stat_rx(struct ath_softc *sc, struct ath_rx_status *rs)
Sujith1395d3f2010-01-08 10:36:11 +0530820{
Oleksij Rempelb5a0c862014-05-11 10:04:36 +0200821 ath9k_cmn_debug_stat_rx(&sc->debug.stats.rxstats, rs);
Sujith1395d3f2010-01-08 10:36:11 +0530822}
823
Felix Fietkau9bff0bc2010-05-11 17:23:02 +0200824static ssize_t read_file_regidx(struct file *file, char __user *user_buf,
Arend van Spriel631bee22014-11-09 11:31:59 +0100825 size_t count, loff_t *ppos)
Felix Fietkau9bff0bc2010-05-11 17:23:02 +0200826{
827 struct ath_softc *sc = file->private_data;
828 char buf[32];
829 unsigned int len;
830
Dan Carpenter2b87f3a2010-05-14 15:24:37 +0200831 len = sprintf(buf, "0x%08x\n", sc->debug.regidx);
Felix Fietkau9bff0bc2010-05-11 17:23:02 +0200832 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
833}
834
835static ssize_t write_file_regidx(struct file *file, const char __user *user_buf,
Arend van Spriel631bee22014-11-09 11:31:59 +0100836 size_t count, loff_t *ppos)
Felix Fietkau9bff0bc2010-05-11 17:23:02 +0200837{
838 struct ath_softc *sc = file->private_data;
839 unsigned long regidx;
840 char buf[32];
841 ssize_t len;
842
843 len = min(count, sizeof(buf) - 1);
844 if (copy_from_user(buf, user_buf, len))
Dan Carpenter04236062010-05-14 15:25:39 +0200845 return -EFAULT;
Felix Fietkau9bff0bc2010-05-11 17:23:02 +0200846
847 buf[len] = '\0';
Jingoo Han27d7f472013-05-31 21:24:06 +0000848 if (kstrtoul(buf, 0, &regidx))
Felix Fietkau9bff0bc2010-05-11 17:23:02 +0200849 return -EINVAL;
850
851 sc->debug.regidx = regidx;
852 return count;
853}
854
855static const struct file_operations fops_regidx = {
856 .read = read_file_regidx,
857 .write = write_file_regidx,
Stephen Boyd234e3402012-04-05 14:25:11 -0700858 .open = simple_open,
Arnd Bergmann6038f372010-08-15 18:52:59 +0200859 .owner = THIS_MODULE,
860 .llseek = default_llseek,
Felix Fietkau9bff0bc2010-05-11 17:23:02 +0200861};
862
863static ssize_t read_file_regval(struct file *file, char __user *user_buf,
Arend van Spriel631bee22014-11-09 11:31:59 +0100864 size_t count, loff_t *ppos)
Felix Fietkau9bff0bc2010-05-11 17:23:02 +0200865{
866 struct ath_softc *sc = file->private_data;
867 struct ath_hw *ah = sc->sc_ah;
868 char buf[32];
869 unsigned int len;
870 u32 regval;
871
Rajkumar Manoharan79d2b152011-05-16 18:23:23 +0530872 ath9k_ps_wakeup(sc);
Felix Fietkau9bff0bc2010-05-11 17:23:02 +0200873 regval = REG_READ_D(ah, sc->debug.regidx);
Rajkumar Manoharan79d2b152011-05-16 18:23:23 +0530874 ath9k_ps_restore(sc);
Dan Carpenter2b87f3a2010-05-14 15:24:37 +0200875 len = sprintf(buf, "0x%08x\n", regval);
Felix Fietkau9bff0bc2010-05-11 17:23:02 +0200876 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
877}
878
879static ssize_t write_file_regval(struct file *file, const char __user *user_buf,
Arend van Spriel631bee22014-11-09 11:31:59 +0100880 size_t count, loff_t *ppos)
Felix Fietkau9bff0bc2010-05-11 17:23:02 +0200881{
882 struct ath_softc *sc = file->private_data;
883 struct ath_hw *ah = sc->sc_ah;
884 unsigned long regval;
885 char buf[32];
886 ssize_t len;
887
888 len = min(count, sizeof(buf) - 1);
889 if (copy_from_user(buf, user_buf, len))
Dan Carpenter04236062010-05-14 15:25:39 +0200890 return -EFAULT;
Felix Fietkau9bff0bc2010-05-11 17:23:02 +0200891
892 buf[len] = '\0';
Jingoo Han27d7f472013-05-31 21:24:06 +0000893 if (kstrtoul(buf, 0, &regval))
Felix Fietkau9bff0bc2010-05-11 17:23:02 +0200894 return -EINVAL;
895
Rajkumar Manoharan79d2b152011-05-16 18:23:23 +0530896 ath9k_ps_wakeup(sc);
Felix Fietkau9bff0bc2010-05-11 17:23:02 +0200897 REG_WRITE_D(ah, sc->debug.regidx, regval);
Rajkumar Manoharan79d2b152011-05-16 18:23:23 +0530898 ath9k_ps_restore(sc);
Felix Fietkau9bff0bc2010-05-11 17:23:02 +0200899 return count;
900}
901
902static const struct file_operations fops_regval = {
903 .read = read_file_regval,
904 .write = write_file_regval,
Stephen Boyd234e3402012-04-05 14:25:11 -0700905 .open = simple_open,
Arnd Bergmann6038f372010-08-15 18:52:59 +0200906 .owner = THIS_MODULE,
907 .llseek = default_llseek,
Felix Fietkau9bff0bc2010-05-11 17:23:02 +0200908};
909
Vasanthakumar Thiagarajan582d0062011-03-01 05:30:55 -0800910#define REGDUMP_LINE_SIZE 20
911
912static int open_file_regdump(struct inode *inode, struct file *file)
913{
914 struct ath_softc *sc = inode->i_private;
915 unsigned int len = 0;
916 u8 *buf;
917 int i;
918 unsigned long num_regs, regdump_len, max_reg_offset;
919
920 max_reg_offset = AR_SREV_9300_20_OR_LATER(sc->sc_ah) ? 0x16bd4 : 0xb500;
921 num_regs = max_reg_offset / 4 + 1;
922 regdump_len = num_regs * REGDUMP_LINE_SIZE + 1;
923 buf = vmalloc(regdump_len);
924 if (!buf)
925 return -ENOMEM;
926
927 ath9k_ps_wakeup(sc);
928 for (i = 0; i < num_regs; i++)
929 len += scnprintf(buf + len, regdump_len - len,
930 "0x%06x 0x%08x\n", i << 2, REG_READ(sc->sc_ah, i << 2));
931 ath9k_ps_restore(sc);
932
933 file->private_data = buf;
934
935 return 0;
936}
937
938static const struct file_operations fops_regdump = {
939 .open = open_file_regdump,
940 .read = ath9k_debugfs_read_buf,
941 .release = ath9k_debugfs_release_buf,
942 .owner = THIS_MODULE,
943 .llseek = default_llseek,/* read accesses f_pos */
944};
945
Arend van Spriel631bee22014-11-09 11:31:59 +0100946static int read_file_dump_nfcal(struct seq_file *file, void *data)
Rajkumar Manoharand069a462011-08-13 10:28:18 +0530947{
Arend van Spriel4447d812014-12-27 14:13:00 +0100948 struct ieee80211_hw *hw = dev_get_drvdata(file->private);
949 struct ath_softc *sc = hw->priv;
Rajkumar Manoharand069a462011-08-13 10:28:18 +0530950 struct ath_hw *ah = sc->sc_ah;
Felix Fietkaub01459e2014-06-11 16:17:59 +0530951 struct ath9k_nfcal_hist *h = sc->cur_chan->caldata.nfCalHist;
Rajkumar Manoharand069a462011-08-13 10:28:18 +0530952 struct ath_common *common = ath9k_hw_common(ah);
953 struct ieee80211_conf *conf = &common->hw->conf;
Rajkumar Manoharand069a462011-08-13 10:28:18 +0530954 u32 i, j;
Rajkumar Manoharand069a462011-08-13 10:28:18 +0530955 u8 chainmask = (ah->rxchainmask << 3) | ah->rxchainmask;
956 u8 nread;
957
Arend van Spriel631bee22014-11-09 11:31:59 +0100958 seq_printf(file, "Channel Noise Floor : %d\n", ah->noise);
959 seq_puts(file, "Chain | privNF | # Readings | NF Readings\n");
Rajkumar Manoharand069a462011-08-13 10:28:18 +0530960 for (i = 0; i < NUM_NF_READINGS; i++) {
961 if (!(chainmask & (1 << i)) ||
962 ((i >= AR5416_MAX_CHAINS) && !conf_is_ht40(conf)))
963 continue;
964
965 nread = AR_PHY_CCA_FILTERWINDOW_LENGTH - h[i].invalidNFcount;
Arend van Spriel631bee22014-11-09 11:31:59 +0100966 seq_printf(file, " %d\t %d\t %d\t\t", i, h[i].privNF, nread);
Rajkumar Manoharand069a462011-08-13 10:28:18 +0530967 for (j = 0; j < nread; j++)
Arend van Spriel631bee22014-11-09 11:31:59 +0100968 seq_printf(file, " %d", h[i].nfCalBuffer[j]);
969 seq_puts(file, "\n");
Rajkumar Manoharand069a462011-08-13 10:28:18 +0530970 }
971
Arend van Spriel631bee22014-11-09 11:31:59 +0100972 return 0;
973}
Rajkumar Manoharand069a462011-08-13 10:28:18 +0530974
Arend van Spriel631bee22014-11-09 11:31:59 +0100975static int open_file_dump_nfcal(struct inode *inode, struct file *f)
976{
977 return single_open(f, read_file_dump_nfcal, inode->i_private);
Rajkumar Manoharand069a462011-08-13 10:28:18 +0530978}
979
980static const struct file_operations fops_dump_nfcal = {
Arend van Spriel631bee22014-11-09 11:31:59 +0100981 .read = seq_read,
982 .open = open_file_dump_nfcal,
Rajkumar Manoharand069a462011-08-13 10:28:18 +0530983 .owner = THIS_MODULE,
Arend van Spriel631bee22014-11-09 11:31:59 +0100984 .llseek = seq_lseek,
985 .release = single_release,
Rajkumar Manoharand069a462011-08-13 10:28:18 +0530986};
987
Rajkumar Manoharan4df50ca2012-10-25 17:16:54 +0530988#ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
989static ssize_t read_file_btcoex(struct file *file, char __user *user_buf,
990 size_t count, loff_t *ppos)
991{
992 struct ath_softc *sc = file->private_data;
993 u32 len = 0, size = 1500;
994 char *buf;
995 size_t retval;
996
997 buf = kzalloc(size, GFP_KERNEL);
998 if (buf == NULL)
999 return -ENOMEM;
1000
Sujith Manoharanac46ba42012-11-19 14:24:46 +05301001 if (!sc->sc_ah->common.btcoex_enabled) {
Zefir Kurtisi5e88ba62013-09-05 14:11:57 +02001002 len = scnprintf(buf, size, "%s\n",
1003 "BTCOEX is disabled");
Sujith Manoharanac46ba42012-11-19 14:24:46 +05301004 goto exit;
1005 }
Rajkumar Manoharan4df50ca2012-10-25 17:16:54 +05301006
Sujith Manoharanac46ba42012-11-19 14:24:46 +05301007 len = ath9k_dump_btcoex(sc, buf, size);
1008exit:
Rajkumar Manoharan4df50ca2012-10-25 17:16:54 +05301009 retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
1010 kfree(buf);
1011
1012 return retval;
1013}
1014
1015static const struct file_operations fops_btcoex = {
1016 .read = read_file_btcoex,
1017 .open = simple_open,
1018 .owner = THIS_MODULE,
1019 .llseek = default_llseek,
1020};
1021#endif
1022
Lorenzo Bianconi7a907442014-09-16 02:13:14 +02001023#ifdef CONFIG_ATH9K_DYNACK
1024static ssize_t read_file_ackto(struct file *file, char __user *user_buf,
1025 size_t count, loff_t *ppos)
1026{
1027 struct ath_softc *sc = file->private_data;
1028 struct ath_hw *ah = sc->sc_ah;
1029 char buf[32];
1030 unsigned int len;
1031
1032 len = sprintf(buf, "%u %c\n", ah->dynack.ackto,
1033 (ah->dynack.enabled) ? 'A' : 'S');
1034
1035 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1036}
1037
1038static const struct file_operations fops_ackto = {
1039 .read = read_file_ackto,
1040 .open = simple_open,
1041 .owner = THIS_MODULE,
1042 .llseek = default_llseek,
1043};
1044#endif
1045
Sujith Manoharan8b861712015-01-30 19:05:30 +05301046#ifdef CONFIG_ATH9K_WOW
1047
1048static ssize_t read_file_wow(struct file *file, char __user *user_buf,
1049 size_t count, loff_t *ppos)
1050{
1051 struct ath_softc *sc = file->private_data;
1052 unsigned int len = 0, size = 32;
1053 ssize_t retval;
1054 char *buf;
1055
1056 buf = kzalloc(size, GFP_KERNEL);
1057 if (!buf)
1058 return -ENOMEM;
1059
1060 len += scnprintf(buf + len, size - len, "WOW: %s\n",
1061 sc->force_wow ? "ENABLED" : "DISABLED");
1062
1063 if (len > size)
1064 len = size;
1065
1066 retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
1067 kfree(buf);
1068
1069 return retval;
1070}
1071
1072static ssize_t write_file_wow(struct file *file, const char __user *user_buf,
1073 size_t count, loff_t *ppos)
1074{
1075 struct ath_softc *sc = file->private_data;
1076 unsigned long val;
1077 char buf[32];
1078 ssize_t len;
1079
1080 len = min(count, sizeof(buf) - 1);
1081 if (copy_from_user(buf, user_buf, len))
1082 return -EFAULT;
1083
1084 buf[len] = '\0';
1085 if (kstrtoul(buf, 0, &val))
1086 return -EINVAL;
1087
1088 if (val != 1)
1089 return -EINVAL;
1090
1091 if (!sc->force_wow) {
1092 sc->force_wow = true;
1093 ath9k_init_wow(sc->hw);
1094 }
1095
1096 return count;
1097}
1098
1099static const struct file_operations fops_wow = {
1100 .read = read_file_wow,
1101 .write = write_file_wow,
1102 .open = simple_open,
1103 .owner = THIS_MODULE,
1104 .llseek = default_llseek,
1105};
1106
1107#endif
1108
Lorenzo Bianconi87183892014-12-19 00:18:13 +01001109static ssize_t read_file_tpc(struct file *file, char __user *user_buf,
1110 size_t count, loff_t *ppos)
1111{
1112 struct ath_softc *sc = file->private_data;
1113 struct ath_hw *ah = sc->sc_ah;
1114 unsigned int len = 0, size = 32;
1115 ssize_t retval;
1116 char *buf;
1117
1118 buf = kzalloc(size, GFP_KERNEL);
1119 if (!buf)
1120 return -ENOMEM;
1121
1122 len += scnprintf(buf + len, size - len, "%s\n",
1123 ah->tpc_enabled ? "ENABLED" : "DISABLED");
1124
1125 if (len > size)
1126 len = size;
1127
1128 retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
1129 kfree(buf);
1130
1131 return retval;
1132}
1133
1134static ssize_t write_file_tpc(struct file *file, const char __user *user_buf,
1135 size_t count, loff_t *ppos)
1136{
1137 struct ath_softc *sc = file->private_data;
1138 struct ath_hw *ah = sc->sc_ah;
1139 unsigned long val;
1140 char buf[32];
1141 ssize_t len;
1142 bool tpc_enabled;
1143
Lorenzo Bianconi87183892014-12-19 00:18:13 +01001144 len = min(count, sizeof(buf) - 1);
1145 if (copy_from_user(buf, user_buf, len))
1146 return -EFAULT;
1147
1148 buf[len] = '\0';
1149 if (kstrtoul(buf, 0, &val))
1150 return -EINVAL;
1151
1152 if (val < 0 || val > 1)
1153 return -EINVAL;
1154
1155 tpc_enabled = !!val;
1156
1157 if (tpc_enabled != ah->tpc_enabled) {
1158 ah->tpc_enabled = tpc_enabled;
Lorenzo Bianconi283dd112015-02-17 10:12:17 +01001159
1160 mutex_lock(&sc->mutex);
1161 ath9k_set_txpower(sc, NULL);
1162 mutex_unlock(&sc->mutex);
Lorenzo Bianconi87183892014-12-19 00:18:13 +01001163 }
1164
1165 return count;
1166}
1167
1168static const struct file_operations fops_tpc = {
1169 .read = read_file_tpc,
1170 .write = write_file_tpc,
1171 .open = simple_open,
1172 .owner = THIS_MODULE,
1173 .llseek = default_llseek,
1174};
1175
Sujith Manoharanc175db82012-11-28 15:08:52 +05301176/* Ethtool support for get-stats */
1177
1178#define AMKSTR(nm) #nm "_BE", #nm "_BK", #nm "_VI", #nm "_VO"
1179static const char ath9k_gstrings_stats[][ETH_GSTRING_LEN] = {
1180 "tx_pkts_nic",
1181 "tx_bytes_nic",
1182 "rx_pkts_nic",
1183 "rx_bytes_nic",
1184 AMKSTR(d_tx_pkts),
1185 AMKSTR(d_tx_bytes),
1186 AMKSTR(d_tx_mpdus_queued),
1187 AMKSTR(d_tx_mpdus_completed),
1188 AMKSTR(d_tx_mpdu_xretries),
1189 AMKSTR(d_tx_aggregates),
1190 AMKSTR(d_tx_ampdus_queued_hw),
1191 AMKSTR(d_tx_ampdus_queued_sw),
1192 AMKSTR(d_tx_ampdus_completed),
1193 AMKSTR(d_tx_ampdu_retries),
1194 AMKSTR(d_tx_ampdu_xretries),
1195 AMKSTR(d_tx_fifo_underrun),
1196 AMKSTR(d_tx_op_exceeded),
1197 AMKSTR(d_tx_timer_expiry),
1198 AMKSTR(d_tx_desc_cfg_err),
1199 AMKSTR(d_tx_data_underrun),
1200 AMKSTR(d_tx_delim_underrun),
Ben Greear18c45b12013-03-04 15:31:17 -08001201 "d_rx_crc_err",
Sujith Manoharanc175db82012-11-28 15:08:52 +05301202 "d_rx_decrypt_crc_err",
1203 "d_rx_phy_err",
1204 "d_rx_mic_err",
1205 "d_rx_pre_delim_crc_err",
1206 "d_rx_post_delim_crc_err",
1207 "d_rx_decrypt_busy_err",
1208
1209 "d_rx_phyerr_radar",
1210 "d_rx_phyerr_ofdm_timing",
1211 "d_rx_phyerr_cck_timing",
1212
1213};
1214#define ATH9K_SSTATS_LEN ARRAY_SIZE(ath9k_gstrings_stats)
1215
1216void ath9k_get_et_strings(struct ieee80211_hw *hw,
1217 struct ieee80211_vif *vif,
1218 u32 sset, u8 *data)
1219{
1220 if (sset == ETH_SS_STATS)
1221 memcpy(data, *ath9k_gstrings_stats,
1222 sizeof(ath9k_gstrings_stats));
1223}
1224
1225int ath9k_get_et_sset_count(struct ieee80211_hw *hw,
1226 struct ieee80211_vif *vif, int sset)
1227{
1228 if (sset == ETH_SS_STATS)
1229 return ATH9K_SSTATS_LEN;
1230 return 0;
1231}
1232
1233#define AWDATA(elem) \
1234 do { \
1235 data[i++] = sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_BE)].elem; \
1236 data[i++] = sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_BK)].elem; \
1237 data[i++] = sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_VI)].elem; \
1238 data[i++] = sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_VO)].elem; \
1239 } while (0)
1240
1241#define AWDATA_RX(elem) \
1242 do { \
1243 data[i++] = sc->debug.stats.rxstats.elem; \
1244 } while (0)
1245
1246void ath9k_get_et_stats(struct ieee80211_hw *hw,
1247 struct ieee80211_vif *vif,
1248 struct ethtool_stats *stats, u64 *data)
1249{
1250 struct ath_softc *sc = hw->priv;
1251 int i = 0;
1252
1253 data[i++] = (sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_BE)].tx_pkts_all +
1254 sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_BK)].tx_pkts_all +
1255 sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_VI)].tx_pkts_all +
1256 sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_VO)].tx_pkts_all);
1257 data[i++] = (sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_BE)].tx_bytes_all +
1258 sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_BK)].tx_bytes_all +
1259 sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_VI)].tx_bytes_all +
1260 sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_VO)].tx_bytes_all);
1261 AWDATA_RX(rx_pkts_all);
1262 AWDATA_RX(rx_bytes_all);
1263
1264 AWDATA(tx_pkts_all);
1265 AWDATA(tx_bytes_all);
1266 AWDATA(queued);
1267 AWDATA(completed);
1268 AWDATA(xretries);
1269 AWDATA(a_aggr);
1270 AWDATA(a_queued_hw);
1271 AWDATA(a_queued_sw);
1272 AWDATA(a_completed);
1273 AWDATA(a_retries);
1274 AWDATA(a_xretries);
1275 AWDATA(fifo_underrun);
1276 AWDATA(xtxop);
1277 AWDATA(timer_exp);
1278 AWDATA(desc_cfg_err);
1279 AWDATA(data_underrun);
1280 AWDATA(delim_underrun);
1281
Ben Greear18c45b12013-03-04 15:31:17 -08001282 AWDATA_RX(crc_err);
Sujith Manoharanc175db82012-11-28 15:08:52 +05301283 AWDATA_RX(decrypt_crc_err);
1284 AWDATA_RX(phy_err);
1285 AWDATA_RX(mic_err);
1286 AWDATA_RX(pre_delim_crc_err);
1287 AWDATA_RX(post_delim_crc_err);
1288 AWDATA_RX(decrypt_busy_err);
1289
1290 AWDATA_RX(phy_err_stats[ATH9K_PHYERR_RADAR]);
1291 AWDATA_RX(phy_err_stats[ATH9K_PHYERR_OFDM_TIMING]);
1292 AWDATA_RX(phy_err_stats[ATH9K_PHYERR_CCK_TIMING]);
1293
1294 WARN_ON(i != ATH9K_SSTATS_LEN);
1295}
1296
Sujith Manoharanaf690092013-05-10 18:41:06 +05301297void ath9k_deinit_debug(struct ath_softc *sc)
1298{
Oleksij Rempel67dc74f2014-11-06 08:53:30 +01001299 ath9k_cmn_spectral_deinit_debug(&sc->spec_priv);
Sujith Manoharanaf690092013-05-10 18:41:06 +05301300}
1301
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001302int ath9k_init_debug(struct ath_hw *ah)
Sujith88b126a2008-11-28 22:19:02 +05301303{
Luis R. Rodriguezbc974f42009-09-28 02:54:40 -04001304 struct ath_common *common = ath9k_hw_common(ah);
1305 struct ath_softc *sc = (struct ath_softc *) common->priv;
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001306
Ben Greeareb272442010-11-29 14:13:22 -08001307 sc->debug.debugfs_phy = debugfs_create_dir("ath9k",
1308 sc->hw->wiphy->debugfsdir);
Sujith17d79042009-02-09 13:27:03 +05301309 if (!sc->debug.debugfs_phy)
Felix Fietkauc8a72c02010-05-11 17:23:00 +02001310 return -ENOMEM;
Sujith826d2682008-11-28 22:20:23 +05301311
Felix Fietkaua830df02009-11-23 22:33:27 +01001312#ifdef CONFIG_ATH_DEBUG
Felix Fietkauc70cab12011-03-19 13:55:37 +01001313 debugfs_create_file("debug", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
1314 sc, &fops_debug);
Felix Fietkaua830df02009-11-23 22:33:27 +01001315#endif
Zefir Kurtisi29942bc2011-12-14 20:16:34 -08001316
1317 ath9k_dfs_init_debug(sc);
Sujith Manoharanef6b19e2013-10-24 12:04:39 +05301318 ath9k_tx99_init_debug(sc);
Oleksij Rempel67dc74f2014-11-06 08:53:30 +01001319 ath9k_cmn_spectral_init_debug(&sc->spec_priv, sc->debug.debugfs_phy);
Zefir Kurtisi29942bc2011-12-14 20:16:34 -08001320
Arend van Spriel4447d812014-12-27 14:13:00 +01001321 debugfs_create_devm_seqfile(sc->dev, "dma", sc->debug.debugfs_phy,
1322 read_file_dma);
1323 debugfs_create_devm_seqfile(sc->dev, "interrupt", sc->debug.debugfs_phy,
1324 read_file_interrupt);
1325 debugfs_create_devm_seqfile(sc->dev, "xmit", sc->debug.debugfs_phy,
1326 read_file_xmit);
1327 debugfs_create_devm_seqfile(sc->dev, "queues", sc->debug.debugfs_phy,
1328 read_file_queues);
Felix Fietkau7702e782012-07-15 19:53:35 +02001329 debugfs_create_u32("qlen_bk", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
Sujith Manoharanbea843c2012-11-21 18:13:10 +05301330 &sc->tx.txq_max_pending[IEEE80211_AC_BK]);
Felix Fietkau7702e782012-07-15 19:53:35 +02001331 debugfs_create_u32("qlen_be", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
Sujith Manoharanbea843c2012-11-21 18:13:10 +05301332 &sc->tx.txq_max_pending[IEEE80211_AC_BE]);
Felix Fietkau7702e782012-07-15 19:53:35 +02001333 debugfs_create_u32("qlen_vi", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
Sujith Manoharanbea843c2012-11-21 18:13:10 +05301334 &sc->tx.txq_max_pending[IEEE80211_AC_VI]);
Felix Fietkau7702e782012-07-15 19:53:35 +02001335 debugfs_create_u32("qlen_vo", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
Sujith Manoharanbea843c2012-11-21 18:13:10 +05301336 &sc->tx.txq_max_pending[IEEE80211_AC_VO]);
Arend van Spriel4447d812014-12-27 14:13:00 +01001337 debugfs_create_devm_seqfile(sc->dev, "misc", sc->debug.debugfs_phy,
1338 read_file_misc);
1339 debugfs_create_devm_seqfile(sc->dev, "reset", sc->debug.debugfs_phy,
1340 read_file_reset);
Oleksij Rempel87ea9b02014-05-11 10:04:37 +02001341
1342 ath9k_cmn_debug_recv(sc->debug.debugfs_phy, &sc->debug.stats.rxstats);
Oleksij Rempele02912c2014-05-11 10:04:39 +02001343 ath9k_cmn_debug_phy_err(sc->debug.debugfs_phy, &sc->debug.stats.rxstats);
Oleksij Rempel87ea9b02014-05-11 10:04:37 +02001344
Felix Fietkauca6d4a72013-08-13 12:33:27 +02001345 debugfs_create_u8("rx_chainmask", S_IRUSR, sc->debug.debugfs_phy,
1346 &ah->rxchainmask);
1347 debugfs_create_u8("tx_chainmask", S_IRUSR, sc->debug.debugfs_phy,
1348 &ah->txchainmask);
Sujith Manoharan6e4d2912013-06-03 09:19:28 +05301349 debugfs_create_file("ani", S_IRUSR | S_IWUSR,
1350 sc->debug.debugfs_phy, sc, &fops_ani);
Felix Fietkau74673db2012-09-08 15:24:17 +02001351 debugfs_create_bool("paprd", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
1352 &sc->sc_ah->config.enable_paprd);
Felix Fietkauc70cab12011-03-19 13:55:37 +01001353 debugfs_create_file("regidx", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
1354 sc, &fops_regidx);
1355 debugfs_create_file("regval", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
1356 sc, &fops_regval);
1357 debugfs_create_bool("ignore_extcca", S_IRUSR | S_IWUSR,
1358 sc->debug.debugfs_phy,
1359 &ah->config.cwm_ignore_extcca);
1360 debugfs_create_file("regdump", S_IRUSR, sc->debug.debugfs_phy, sc,
1361 &fops_regdump);
Arend van Spriel4447d812014-12-27 14:13:00 +01001362 debugfs_create_devm_seqfile(sc->dev, "dump_nfcal",
1363 sc->debug.debugfs_phy,
1364 read_file_dump_nfcal);
Oleksij Rempelf2c3c952014-05-11 10:04:31 +02001365
Oleksij Rempel29bf8012014-05-11 10:04:33 +02001366 ath9k_cmn_debug_base_eeprom(sc->debug.debugfs_phy, sc->sc_ah);
Oleksij Rempelf2c3c952014-05-11 10:04:31 +02001367 ath9k_cmn_debug_modal_eeprom(sc->debug.debugfs_phy, sc->sc_ah);
1368
Felix Fietkau691680b2011-03-19 13:55:38 +01001369 debugfs_create_u32("gpio_mask", S_IRUSR | S_IWUSR,
1370 sc->debug.debugfs_phy, &sc->sc_ah->gpio_mask);
Felix Fietkau691680b2011-03-19 13:55:38 +01001371 debugfs_create_u32("gpio_val", S_IRUSR | S_IWUSR,
1372 sc->debug.debugfs_phy, &sc->sc_ah->gpio_val);
Sujith Manoharan4eba10c2013-07-29 16:04:49 +05301373 debugfs_create_file("antenna_diversity", S_IRUSR,
1374 sc->debug.debugfs_phy, sc, &fops_antenna_diversity);
Rajkumar Manoharan4df50ca2012-10-25 17:16:54 +05301375#ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
Sujith Manoharan36e88252013-08-06 12:44:15 +05301376 debugfs_create_file("bt_ant_diversity", S_IRUSR | S_IWUSR,
1377 sc->debug.debugfs_phy, sc, &fops_bt_ant_diversity);
Rajkumar Manoharan4df50ca2012-10-25 17:16:54 +05301378 debugfs_create_file("btcoex", S_IRUSR, sc->debug.debugfs_phy, sc,
1379 &fops_btcoex);
1380#endif
Luis R. Rodriguez89f927a2013-10-14 17:42:11 -07001381
Sujith Manoharan8b861712015-01-30 19:05:30 +05301382#ifdef CONFIG_ATH9K_WOW
1383 debugfs_create_file("wow", S_IRUSR | S_IWUSR,
1384 sc->debug.debugfs_phy, sc, &fops_wow);
1385#endif
1386
Lorenzo Bianconi7a907442014-09-16 02:13:14 +02001387#ifdef CONFIG_ATH9K_DYNACK
1388 debugfs_create_file("ack_to", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
1389 sc, &fops_ackto);
1390#endif
Lorenzo Bianconi87183892014-12-19 00:18:13 +01001391 debugfs_create_file("tpc", S_IRUSR | S_IWUSR,
1392 sc->debug.debugfs_phy, sc, &fops_tpc);
Lorenzo Bianconi7a907442014-09-16 02:13:14 +02001393
Sujith826d2682008-11-28 22:20:23 +05301394 return 0;
Sujith88b126a2008-11-28 22:19:02 +05301395}