blob: b96119f813bfb1fd57ce0954d86021348abd30ac [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
Sujith Manoharan6e4d2912013-06-03 09:19:28 +0530205 if (ani < 0 || ani > 1)
206 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
Sujith2a163c62008-11-28 22:21:08 +0530404static ssize_t read_file_dma(struct file *file, char __user *user_buf,
405 size_t count, loff_t *ppos)
406{
407 struct ath_softc *sc = file->private_data;
Sujithcbe61d82009-02-09 13:27:12 +0530408 struct ath_hw *ah = sc->sc_ah;
Pavel Roskin991a0982010-01-29 17:22:26 -0500409 char *buf;
410 int retval;
Sujith2a163c62008-11-28 22:21:08 +0530411 unsigned int len = 0;
412 u32 val[ATH9K_NUM_DMA_DEBUG_REGS];
413 int i, qcuOffset = 0, dcuOffset = 0;
414 u32 *qcuBase = &val[0], *dcuBase = &val[4];
415
Pavel Roskin991a0982010-01-29 17:22:26 -0500416 buf = kmalloc(DMA_BUF_LEN, GFP_KERNEL);
417 if (!buf)
Dan Carpenter04236062010-05-14 15:25:39 +0200418 return -ENOMEM;
Pavel Roskin991a0982010-01-29 17:22:26 -0500419
Sujith7cf4a2e2009-08-26 11:11:57 +0530420 ath9k_ps_wakeup(sc);
421
Luis R. Rodriguez475a6e42009-09-23 23:06:59 -0400422 REG_WRITE_D(ah, AR_MACMISC,
Sujith2a163c62008-11-28 22:21:08 +0530423 ((AR_MACMISC_DMA_OBS_LINE_8 << AR_MACMISC_DMA_OBS_S) |
424 (AR_MACMISC_MISC_OBS_BUS_1 <<
425 AR_MACMISC_MISC_OBS_BUS_MSB_S)));
426
Zefir Kurtisi5e88ba62013-09-05 14:11:57 +0200427 len += scnprintf(buf + len, DMA_BUF_LEN - len,
428 "Raw DMA Debug values:\n");
Sujith2a163c62008-11-28 22:21:08 +0530429
430 for (i = 0; i < ATH9K_NUM_DMA_DEBUG_REGS; i++) {
431 if (i % 4 == 0)
Zefir Kurtisi5e88ba62013-09-05 14:11:57 +0200432 len += scnprintf(buf + len, DMA_BUF_LEN - len, "\n");
Sujith2a163c62008-11-28 22:21:08 +0530433
Luis R. Rodriguez475a6e42009-09-23 23:06:59 -0400434 val[i] = REG_READ_D(ah, AR_DMADBG_0 + (i * sizeof(u32)));
Zefir Kurtisi5e88ba62013-09-05 14:11:57 +0200435 len += scnprintf(buf + len, DMA_BUF_LEN - len, "%d: %08x ",
436 i, val[i]);
Sujith2a163c62008-11-28 22:21:08 +0530437 }
438
Zefir Kurtisi5e88ba62013-09-05 14:11:57 +0200439 len += scnprintf(buf + len, DMA_BUF_LEN - len, "\n\n");
440 len += scnprintf(buf + len, DMA_BUF_LEN - len,
441 "Num QCU: chain_st fsp_ok fsp_st DCU: chain_st\n");
Sujith2a163c62008-11-28 22:21:08 +0530442
443 for (i = 0; i < ATH9K_NUM_QUEUES; i++, qcuOffset += 4, dcuOffset += 5) {
444 if (i == 8) {
445 qcuOffset = 0;
446 qcuBase++;
447 }
448
449 if (i == 6) {
450 dcuOffset = 0;
451 dcuBase++;
452 }
453
Zefir Kurtisi5e88ba62013-09-05 14:11:57 +0200454 len += scnprintf(buf + len, DMA_BUF_LEN - len,
455 "%2d %2x %1x %2x %2x\n",
456 i, (*qcuBase & (0x7 << qcuOffset)) >> qcuOffset,
457 (*qcuBase & (0x8 << qcuOffset)) >> (qcuOffset + 3),
458 val[2] & (0x7 << (i * 3)) >> (i * 3),
459 (*dcuBase & (0x1f << dcuOffset)) >> dcuOffset);
Sujith2a163c62008-11-28 22:21:08 +0530460 }
461
Zefir Kurtisi5e88ba62013-09-05 14:11:57 +0200462 len += scnprintf(buf + len, DMA_BUF_LEN - len, "\n");
Sujith2a163c62008-11-28 22:21:08 +0530463
Zefir Kurtisi5e88ba62013-09-05 14:11:57 +0200464 len += scnprintf(buf + len, DMA_BUF_LEN - len,
Sujith2a163c62008-11-28 22:21:08 +0530465 "qcu_stitch state: %2x qcu_fetch state: %2x\n",
466 (val[3] & 0x003c0000) >> 18, (val[3] & 0x03c00000) >> 22);
Zefir Kurtisi5e88ba62013-09-05 14:11:57 +0200467 len += scnprintf(buf + len, DMA_BUF_LEN - len,
Sujith2a163c62008-11-28 22:21:08 +0530468 "qcu_complete state: %2x dcu_complete state: %2x\n",
469 (val[3] & 0x1c000000) >> 26, (val[6] & 0x3));
Zefir Kurtisi5e88ba62013-09-05 14:11:57 +0200470 len += scnprintf(buf + len, DMA_BUF_LEN - len,
Sujith2a163c62008-11-28 22:21:08 +0530471 "dcu_arb state: %2x dcu_fp state: %2x\n",
472 (val[5] & 0x06000000) >> 25, (val[5] & 0x38000000) >> 27);
Zefir Kurtisi5e88ba62013-09-05 14:11:57 +0200473 len += scnprintf(buf + len, DMA_BUF_LEN - len,
Sujith2a163c62008-11-28 22:21:08 +0530474 "chan_idle_dur: %3d chan_idle_dur_valid: %1d\n",
475 (val[6] & 0x000003fc) >> 2, (val[6] & 0x00000400) >> 10);
Zefir Kurtisi5e88ba62013-09-05 14:11:57 +0200476 len += scnprintf(buf + len, DMA_BUF_LEN - len,
Sujith2a163c62008-11-28 22:21:08 +0530477 "txfifo_valid_0: %1d txfifo_valid_1: %1d\n",
478 (val[6] & 0x00000800) >> 11, (val[6] & 0x00001000) >> 12);
Zefir Kurtisi5e88ba62013-09-05 14:11:57 +0200479 len += scnprintf(buf + len, DMA_BUF_LEN - len,
Sujith2a163c62008-11-28 22:21:08 +0530480 "txfifo_dcu_num_0: %2d txfifo_dcu_num_1: %2d\n",
481 (val[6] & 0x0001e000) >> 13, (val[6] & 0x001e0000) >> 17);
482
Zefir Kurtisi5e88ba62013-09-05 14:11:57 +0200483 len += scnprintf(buf + len, DMA_BUF_LEN - len, "pcu observe: 0x%x\n",
484 REG_READ_D(ah, AR_OBS_BUS_1));
485 len += scnprintf(buf + len, DMA_BUF_LEN - len,
486 "AR_CR: 0x%x\n", REG_READ_D(ah, AR_CR));
Sujith2a163c62008-11-28 22:21:08 +0530487
Sujith7cf4a2e2009-08-26 11:11:57 +0530488 ath9k_ps_restore(sc);
489
Dan Carpenter2b87f3a2010-05-14 15:24:37 +0200490 if (len > DMA_BUF_LEN)
491 len = DMA_BUF_LEN;
492
Pavel Roskin991a0982010-01-29 17:22:26 -0500493 retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
494 kfree(buf);
495 return retval;
Sujith2a163c62008-11-28 22:21:08 +0530496}
497
498static const struct file_operations fops_dma = {
499 .read = read_file_dma,
Stephen Boyd234e3402012-04-05 14:25:11 -0700500 .open = simple_open,
Arnd Bergmann6038f372010-08-15 18:52:59 +0200501 .owner = THIS_MODULE,
502 .llseek = default_llseek,
Sujith2a163c62008-11-28 22:21:08 +0530503};
504
Sujith817e11d2008-12-07 21:42:44 +0530505
506void ath_debug_stat_interrupt(struct ath_softc *sc, enum ath9k_int status)
507{
508 if (status)
Sujith17d79042009-02-09 13:27:03 +0530509 sc->debug.stats.istats.total++;
Luis R. Rodrigueza9616f42010-04-15 17:39:30 -0400510 if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) {
511 if (status & ATH9K_INT_RXLP)
512 sc->debug.stats.istats.rxlp++;
513 if (status & ATH9K_INT_RXHP)
514 sc->debug.stats.istats.rxhp++;
Luis R. Rodriguez08578b82010-05-13 13:33:44 -0400515 if (status & ATH9K_INT_BB_WATCHDOG)
516 sc->debug.stats.istats.bb_watchdog++;
Luis R. Rodrigueza9616f42010-04-15 17:39:30 -0400517 } else {
518 if (status & ATH9K_INT_RX)
519 sc->debug.stats.istats.rxok++;
520 }
Sujith817e11d2008-12-07 21:42:44 +0530521 if (status & ATH9K_INT_RXEOL)
Sujith17d79042009-02-09 13:27:03 +0530522 sc->debug.stats.istats.rxeol++;
Sujith817e11d2008-12-07 21:42:44 +0530523 if (status & ATH9K_INT_RXORN)
Sujith17d79042009-02-09 13:27:03 +0530524 sc->debug.stats.istats.rxorn++;
Sujith817e11d2008-12-07 21:42:44 +0530525 if (status & ATH9K_INT_TX)
Sujith17d79042009-02-09 13:27:03 +0530526 sc->debug.stats.istats.txok++;
Sujith817e11d2008-12-07 21:42:44 +0530527 if (status & ATH9K_INT_TXURN)
Sujith17d79042009-02-09 13:27:03 +0530528 sc->debug.stats.istats.txurn++;
Sujith817e11d2008-12-07 21:42:44 +0530529 if (status & ATH9K_INT_RXPHY)
Sujith17d79042009-02-09 13:27:03 +0530530 sc->debug.stats.istats.rxphyerr++;
Sujith817e11d2008-12-07 21:42:44 +0530531 if (status & ATH9K_INT_RXKCM)
Sujith17d79042009-02-09 13:27:03 +0530532 sc->debug.stats.istats.rx_keycache_miss++;
Sujith817e11d2008-12-07 21:42:44 +0530533 if (status & ATH9K_INT_SWBA)
Sujith17d79042009-02-09 13:27:03 +0530534 sc->debug.stats.istats.swba++;
Sujith817e11d2008-12-07 21:42:44 +0530535 if (status & ATH9K_INT_BMISS)
Sujith17d79042009-02-09 13:27:03 +0530536 sc->debug.stats.istats.bmiss++;
Sujith817e11d2008-12-07 21:42:44 +0530537 if (status & ATH9K_INT_BNR)
Sujith17d79042009-02-09 13:27:03 +0530538 sc->debug.stats.istats.bnr++;
Sujith817e11d2008-12-07 21:42:44 +0530539 if (status & ATH9K_INT_CST)
Sujith17d79042009-02-09 13:27:03 +0530540 sc->debug.stats.istats.cst++;
Sujith817e11d2008-12-07 21:42:44 +0530541 if (status & ATH9K_INT_GTT)
Sujith17d79042009-02-09 13:27:03 +0530542 sc->debug.stats.istats.gtt++;
Sujith817e11d2008-12-07 21:42:44 +0530543 if (status & ATH9K_INT_TIM)
Sujith17d79042009-02-09 13:27:03 +0530544 sc->debug.stats.istats.tim++;
Sujith817e11d2008-12-07 21:42:44 +0530545 if (status & ATH9K_INT_CABEND)
Sujith17d79042009-02-09 13:27:03 +0530546 sc->debug.stats.istats.cabend++;
Sujith817e11d2008-12-07 21:42:44 +0530547 if (status & ATH9K_INT_DTIMSYNC)
Sujith17d79042009-02-09 13:27:03 +0530548 sc->debug.stats.istats.dtimsync++;
Sujith817e11d2008-12-07 21:42:44 +0530549 if (status & ATH9K_INT_DTIM)
Sujith17d79042009-02-09 13:27:03 +0530550 sc->debug.stats.istats.dtim++;
Mohammed Shafi Shajakhan6dde1aa2011-04-22 17:27:01 +0530551 if (status & ATH9K_INT_TSFOOR)
552 sc->debug.stats.istats.tsfoor++;
Sujith Manoharan97ba5152012-06-04 16:27:41 +0530553 if (status & ATH9K_INT_MCI)
554 sc->debug.stats.istats.mci++;
Mohammed Shafi Shajakhanc9e6e982012-09-07 15:54:13 +0530555 if (status & ATH9K_INT_GENTIMER)
556 sc->debug.stats.istats.gen_timer++;
Sujith817e11d2008-12-07 21:42:44 +0530557}
558
559static ssize_t read_file_interrupt(struct file *file, char __user *user_buf,
560 size_t count, loff_t *ppos)
561{
562 struct ath_softc *sc = file->private_data;
Sujith817e11d2008-12-07 21:42:44 +0530563 unsigned int len = 0;
Ben Greear462e58f2012-04-12 10:04:00 -0700564 int rv;
565 int mxlen = 4000;
566 char *buf = kmalloc(mxlen, GFP_KERNEL);
567 if (!buf)
568 return -ENOMEM;
569
570#define PR_IS(a, s) \
571 do { \
Zefir Kurtisi5e88ba62013-09-05 14:11:57 +0200572 len += scnprintf(buf + len, mxlen - len, \
573 "%21s: %10u\n", a, \
574 sc->debug.stats.istats.s); \
Ben Greear462e58f2012-04-12 10:04:00 -0700575 } while (0)
Sujith817e11d2008-12-07 21:42:44 +0530576
Luis R. Rodrigueza9616f42010-04-15 17:39:30 -0400577 if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) {
Ben Greear462e58f2012-04-12 10:04:00 -0700578 PR_IS("RXLP", rxlp);
579 PR_IS("RXHP", rxhp);
580 PR_IS("WATHDOG", bb_watchdog);
Luis R. Rodrigueza9616f42010-04-15 17:39:30 -0400581 } else {
Ben Greear462e58f2012-04-12 10:04:00 -0700582 PR_IS("RX", rxok);
Luis R. Rodrigueza9616f42010-04-15 17:39:30 -0400583 }
Ben Greear462e58f2012-04-12 10:04:00 -0700584 PR_IS("RXEOL", rxeol);
585 PR_IS("RXORN", rxorn);
586 PR_IS("TX", txok);
587 PR_IS("TXURN", txurn);
588 PR_IS("MIB", mib);
589 PR_IS("RXPHY", rxphyerr);
590 PR_IS("RXKCM", rx_keycache_miss);
591 PR_IS("SWBA", swba);
592 PR_IS("BMISS", bmiss);
593 PR_IS("BNR", bnr);
594 PR_IS("CST", cst);
595 PR_IS("GTT", gtt);
596 PR_IS("TIM", tim);
597 PR_IS("CABEND", cabend);
598 PR_IS("DTIMSYNC", dtimsync);
599 PR_IS("DTIM", dtim);
600 PR_IS("TSFOOR", tsfoor);
Sujith Manoharan97ba5152012-06-04 16:27:41 +0530601 PR_IS("MCI", mci);
Mohammed Shafi Shajakhanc9e6e982012-09-07 15:54:13 +0530602 PR_IS("GENTIMER", gen_timer);
Ben Greear462e58f2012-04-12 10:04:00 -0700603 PR_IS("TOTAL", total);
Sujith817e11d2008-12-07 21:42:44 +0530604
Zefir Kurtisi5e88ba62013-09-05 14:11:57 +0200605 len += scnprintf(buf + len, mxlen - len,
606 "SYNC_CAUSE stats:\n");
Mohammed Shafi Shajakhan6dde1aa2011-04-22 17:27:01 +0530607
Ben Greear462e58f2012-04-12 10:04:00 -0700608 PR_IS("Sync-All", sync_cause_all);
609 PR_IS("RTC-IRQ", sync_rtc_irq);
610 PR_IS("MAC-IRQ", sync_mac_irq);
611 PR_IS("EEPROM-Illegal-Access", eeprom_illegal_access);
612 PR_IS("APB-Timeout", apb_timeout);
613 PR_IS("PCI-Mode-Conflict", pci_mode_conflict);
614 PR_IS("HOST1-Fatal", host1_fatal);
615 PR_IS("HOST1-Perr", host1_perr);
616 PR_IS("TRCV-FIFO-Perr", trcv_fifo_perr);
617 PR_IS("RADM-CPL-EP", radm_cpl_ep);
618 PR_IS("RADM-CPL-DLLP-Abort", radm_cpl_dllp_abort);
619 PR_IS("RADM-CPL-TLP-Abort", radm_cpl_tlp_abort);
620 PR_IS("RADM-CPL-ECRC-Err", radm_cpl_ecrc_err);
621 PR_IS("RADM-CPL-Timeout", radm_cpl_timeout);
622 PR_IS("Local-Bus-Timeout", local_timeout);
623 PR_IS("PM-Access", pm_access);
624 PR_IS("MAC-Awake", mac_awake);
625 PR_IS("MAC-Asleep", mac_asleep);
626 PR_IS("MAC-Sleep-Access", mac_sleep_access);
Dan Carpenter2b87f3a2010-05-14 15:24:37 +0200627
Ben Greear462e58f2012-04-12 10:04:00 -0700628 if (len > mxlen)
629 len = mxlen;
630
631 rv = simple_read_from_buffer(user_buf, count, ppos, buf, len);
632 kfree(buf);
633 return rv;
Sujith817e11d2008-12-07 21:42:44 +0530634}
635
636static const struct file_operations fops_interrupt = {
637 .read = read_file_interrupt,
Stephen Boyd234e3402012-04-05 14:25:11 -0700638 .open = simple_open,
Arnd Bergmann6038f372010-08-15 18:52:59 +0200639 .owner = THIS_MODULE,
640 .llseek = default_llseek,
Sujith817e11d2008-12-07 21:42:44 +0530641};
642
Sujithfec247c2009-07-27 12:08:16 +0530643static ssize_t read_file_xmit(struct file *file, char __user *user_buf,
644 size_t count, loff_t *ppos)
645{
646 struct ath_softc *sc = file->private_data;
647 char *buf;
Sujith Manoharan78ef7312012-11-21 18:13:11 +0530648 unsigned int len = 0, size = 2048;
Sujithfec247c2009-07-27 12:08:16 +0530649 ssize_t retval = 0;
650
651 buf = kzalloc(size, GFP_KERNEL);
652 if (buf == NULL)
Dan Carpenter04236062010-05-14 15:25:39 +0200653 return -ENOMEM;
Sujithfec247c2009-07-27 12:08:16 +0530654
Sujith Manoharan78ef7312012-11-21 18:13:11 +0530655 len += sprintf(buf, "%30s %10s%10s%10s\n\n",
Ben Greear7f010c92011-01-09 23:11:49 -0800656 "BE", "BK", "VI", "VO");
Sujithfec247c2009-07-27 12:08:16 +0530657
658 PR("MPDUs Queued: ", queued);
659 PR("MPDUs Completed: ", completed);
Felix Fietkau5a6f78a2011-05-31 21:21:41 +0200660 PR("MPDUs XRetried: ", xretries);
Sujithfec247c2009-07-27 12:08:16 +0530661 PR("Aggregates: ", a_aggr);
Ben Greearbda8add2011-01-09 23:11:48 -0800662 PR("AMPDUs Queued HW:", a_queued_hw);
663 PR("AMPDUs Queued SW:", a_queued_sw);
Sujithfec247c2009-07-27 12:08:16 +0530664 PR("AMPDUs Completed:", a_completed);
665 PR("AMPDUs Retried: ", a_retries);
666 PR("AMPDUs XRetried: ", a_xretries);
Ben Greear4d900382013-03-04 15:31:16 -0800667 PR("TXERR Filtered: ", txerr_filtered);
Sujithfec247c2009-07-27 12:08:16 +0530668 PR("FIFO Underrun: ", fifo_underrun);
669 PR("TXOP Exceeded: ", xtxop);
670 PR("TXTIMER Expiry: ", timer_exp);
671 PR("DESC CFG Error: ", desc_cfg_err);
672 PR("DATA Underrun: ", data_underrun);
673 PR("DELIM Underrun: ", delim_underrun);
Ben Greear99c15bf2010-10-01 12:26:30 -0700674 PR("TX-Pkts-All: ", tx_pkts_all);
675 PR("TX-Bytes-All: ", tx_bytes_all);
Sujith Manoharan78ef7312012-11-21 18:13:11 +0530676 PR("HW-put-tx-buf: ", puttxbuf);
677 PR("HW-tx-start: ", txstart);
678 PR("HW-tx-proc-desc: ", txprocdesc);
Ben Greeara5a0bca2012-04-03 09:16:55 -0700679 PR("TX-Failed: ", txfailed);
Sujithfec247c2009-07-27 12:08:16 +0530680
Ben Greear7f010c92011-01-09 23:11:49 -0800681 if (len > size)
682 len = size;
683
684 retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
685 kfree(buf);
686
687 return retval;
688}
689
Felix Fietkau18fcf1c2013-08-06 14:18:05 +0200690static ssize_t print_queue(struct ath_softc *sc, struct ath_txq *txq,
691 char *buf, ssize_t size)
692{
693 ssize_t len = 0;
694
695 ath_txq_lock(sc, txq);
696
Zefir Kurtisi5e88ba62013-09-05 14:11:57 +0200697 len += scnprintf(buf + len, size - len, "%s: %d ",
698 "qnum", txq->axq_qnum);
699 len += scnprintf(buf + len, size - len, "%s: %2d ",
700 "qdepth", txq->axq_depth);
701 len += scnprintf(buf + len, size - len, "%s: %2d ",
702 "ampdu-depth", txq->axq_ampdu_depth);
703 len += scnprintf(buf + len, size - len, "%s: %3d ",
704 "pending", txq->pending_frames);
705 len += scnprintf(buf + len, size - len, "%s: %d\n",
706 "stopped", txq->stopped);
Felix Fietkau18fcf1c2013-08-06 14:18:05 +0200707
708 ath_txq_unlock(sc, txq);
709 return len;
710}
711
Sujith Manoharanc0b74872012-11-21 18:13:12 +0530712static ssize_t read_file_queues(struct file *file, char __user *user_buf,
713 size_t count, loff_t *ppos)
714{
715 struct ath_softc *sc = file->private_data;
716 struct ath_txq *txq;
717 char *buf;
Joe Perches2120ac92014-02-21 14:46:43 -0800718 unsigned int len = 0;
719 const unsigned int size = 1024;
Sujith Manoharanc0b74872012-11-21 18:13:12 +0530720 ssize_t retval = 0;
721 int i;
Joe Perches2120ac92014-02-21 14:46:43 -0800722 static const char *qname[4] = {
723 "VO", "VI", "BE", "BK"
724 };
Sujith Manoharanc0b74872012-11-21 18:13:12 +0530725
726 buf = kzalloc(size, GFP_KERNEL);
727 if (buf == NULL)
728 return -ENOMEM;
729
730 for (i = 0; i < IEEE80211_NUM_ACS; i++) {
731 txq = sc->tx.txq_map[i];
Zefir Kurtisi5e88ba62013-09-05 14:11:57 +0200732 len += scnprintf(buf + len, size - len, "(%s): ", qname[i]);
Felix Fietkau18fcf1c2013-08-06 14:18:05 +0200733 len += print_queue(sc, txq, buf + len, size - len);
Sujith Manoharanc0b74872012-11-21 18:13:12 +0530734 }
735
Zefir Kurtisi5e88ba62013-09-05 14:11:57 +0200736 len += scnprintf(buf + len, size - len, "(CAB): ");
Felix Fietkau18fcf1c2013-08-06 14:18:05 +0200737 len += print_queue(sc, sc->beacon.cabq, buf + len, size - len);
738
Sujith Manoharanc0b74872012-11-21 18:13:12 +0530739 if (len > size)
740 len = size;
741
742 retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
743 kfree(buf);
744
745 return retval;
746}
747
Ben Greear55f6d0f2011-01-17 11:54:50 -0800748static ssize_t read_file_misc(struct file *file, char __user *user_buf,
749 size_t count, loff_t *ppos)
750{
751 struct ath_softc *sc = file->private_data;
752 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Ben Greear55f6d0f2011-01-17 11:54:50 -0800753 struct ieee80211_hw *hw = sc->hw;
Sujith Manoharan6bcf6f62012-02-16 11:51:02 +0530754 struct ath9k_vif_iter_data iter_data;
755 char buf[512];
756 unsigned int len = 0;
Ben Greear55f6d0f2011-01-17 11:54:50 -0800757 ssize_t retval = 0;
Ben Greear55f6d0f2011-01-17 11:54:50 -0800758 unsigned int reg;
Sujith Manoharan6bcf6f62012-02-16 11:51:02 +0530759 u32 rxfilter;
Ben Greear55f6d0f2011-01-17 11:54:50 -0800760
Zefir Kurtisi5e88ba62013-09-05 14:11:57 +0200761 len += scnprintf(buf + len, sizeof(buf) - len,
762 "BSSID: %pM\n", common->curbssid);
763 len += scnprintf(buf + len, sizeof(buf) - len,
764 "BSSID-MASK: %pM\n", common->bssidmask);
765 len += scnprintf(buf + len, sizeof(buf) - len,
766 "OPMODE: %s\n",
767 ath_opmode_to_string(sc->sc_ah->opmode));
Ben Greear55f6d0f2011-01-17 11:54:50 -0800768
Rajkumar Manoharan79d2b152011-05-16 18:23:23 +0530769 ath9k_ps_wakeup(sc);
Sujith Manoharan6bcf6f62012-02-16 11:51:02 +0530770 rxfilter = ath9k_hw_getrxfilter(sc->sc_ah);
Rajkumar Manoharan79d2b152011-05-16 18:23:23 +0530771 ath9k_ps_restore(sc);
Sujith Manoharan6bcf6f62012-02-16 11:51:02 +0530772
Zefir Kurtisi5e88ba62013-09-05 14:11:57 +0200773 len += scnprintf(buf + len, sizeof(buf) - len,
774 "RXFILTER: 0x%x", rxfilter);
Sujith Manoharan6bcf6f62012-02-16 11:51:02 +0530775
776 if (rxfilter & ATH9K_RX_FILTER_UCAST)
Zefir Kurtisi5e88ba62013-09-05 14:11:57 +0200777 len += scnprintf(buf + len, sizeof(buf) - len, " UCAST");
Sujith Manoharan6bcf6f62012-02-16 11:51:02 +0530778 if (rxfilter & ATH9K_RX_FILTER_MCAST)
Zefir Kurtisi5e88ba62013-09-05 14:11:57 +0200779 len += scnprintf(buf + len, sizeof(buf) - len, " MCAST");
Sujith Manoharan6bcf6f62012-02-16 11:51:02 +0530780 if (rxfilter & ATH9K_RX_FILTER_BCAST)
Zefir Kurtisi5e88ba62013-09-05 14:11:57 +0200781 len += scnprintf(buf + len, sizeof(buf) - len, " BCAST");
Sujith Manoharan6bcf6f62012-02-16 11:51:02 +0530782 if (rxfilter & ATH9K_RX_FILTER_CONTROL)
Zefir Kurtisi5e88ba62013-09-05 14:11:57 +0200783 len += scnprintf(buf + len, sizeof(buf) - len, " CONTROL");
Sujith Manoharan6bcf6f62012-02-16 11:51:02 +0530784 if (rxfilter & ATH9K_RX_FILTER_BEACON)
Zefir Kurtisi5e88ba62013-09-05 14:11:57 +0200785 len += scnprintf(buf + len, sizeof(buf) - len, " BEACON");
Sujith Manoharan6bcf6f62012-02-16 11:51:02 +0530786 if (rxfilter & ATH9K_RX_FILTER_PROM)
Zefir Kurtisi5e88ba62013-09-05 14:11:57 +0200787 len += scnprintf(buf + len, sizeof(buf) - len, " PROM");
Sujith Manoharan6bcf6f62012-02-16 11:51:02 +0530788 if (rxfilter & ATH9K_RX_FILTER_PROBEREQ)
Zefir Kurtisi5e88ba62013-09-05 14:11:57 +0200789 len += scnprintf(buf + len, sizeof(buf) - len, " PROBEREQ");
Sujith Manoharan6bcf6f62012-02-16 11:51:02 +0530790 if (rxfilter & ATH9K_RX_FILTER_PHYERR)
Zefir Kurtisi5e88ba62013-09-05 14:11:57 +0200791 len += scnprintf(buf + len, sizeof(buf) - len, " PHYERR");
Sujith Manoharan6bcf6f62012-02-16 11:51:02 +0530792 if (rxfilter & ATH9K_RX_FILTER_MYBEACON)
Zefir Kurtisi5e88ba62013-09-05 14:11:57 +0200793 len += scnprintf(buf + len, sizeof(buf) - len, " MYBEACON");
Sujith Manoharan6bcf6f62012-02-16 11:51:02 +0530794 if (rxfilter & ATH9K_RX_FILTER_COMP_BAR)
Zefir Kurtisi5e88ba62013-09-05 14:11:57 +0200795 len += scnprintf(buf + len, sizeof(buf) - len, " COMP_BAR");
Sujith Manoharan6bcf6f62012-02-16 11:51:02 +0530796 if (rxfilter & ATH9K_RX_FILTER_PSPOLL)
Zefir Kurtisi5e88ba62013-09-05 14:11:57 +0200797 len += scnprintf(buf + len, sizeof(buf) - len, " PSPOLL");
Sujith Manoharan6bcf6f62012-02-16 11:51:02 +0530798 if (rxfilter & ATH9K_RX_FILTER_PHYRADAR)
Zefir Kurtisi5e88ba62013-09-05 14:11:57 +0200799 len += scnprintf(buf + len, sizeof(buf) - len, " PHYRADAR");
Sujith Manoharan6bcf6f62012-02-16 11:51:02 +0530800 if (rxfilter & ATH9K_RX_FILTER_MCAST_BCAST_ALL)
Zefir Kurtisi5e88ba62013-09-05 14:11:57 +0200801 len += scnprintf(buf + len, sizeof(buf) - len, " MCAST_BCAST_ALL");
Sujith Manoharan6bcf6f62012-02-16 11:51:02 +0530802 if (rxfilter & ATH9K_RX_FILTER_CONTROL_WRAPPER)
Zefir Kurtisi5e88ba62013-09-05 14:11:57 +0200803 len += scnprintf(buf + len, sizeof(buf) - len, " CONTROL_WRAPPER");
Sujith Manoharan6bcf6f62012-02-16 11:51:02 +0530804
Zefir Kurtisi5e88ba62013-09-05 14:11:57 +0200805 len += scnprintf(buf + len, sizeof(buf) - len, "\n");
Ben Greear55f6d0f2011-01-17 11:54:50 -0800806
807 reg = sc->sc_ah->imask;
Ben Greear55f6d0f2011-01-17 11:54:50 -0800808
Zefir Kurtisi5e88ba62013-09-05 14:11:57 +0200809 len += scnprintf(buf + len, sizeof(buf) - len,
810 "INTERRUPT-MASK: 0x%x", reg);
Sujith Manoharan6bcf6f62012-02-16 11:51:02 +0530811
812 if (reg & ATH9K_INT_SWBA)
Zefir Kurtisi5e88ba62013-09-05 14:11:57 +0200813 len += scnprintf(buf + len, sizeof(buf) - len, " SWBA");
Sujith Manoharan6bcf6f62012-02-16 11:51:02 +0530814 if (reg & ATH9K_INT_BMISS)
Zefir Kurtisi5e88ba62013-09-05 14:11:57 +0200815 len += scnprintf(buf + len, sizeof(buf) - len, " BMISS");
Sujith Manoharan6bcf6f62012-02-16 11:51:02 +0530816 if (reg & ATH9K_INT_CST)
Zefir Kurtisi5e88ba62013-09-05 14:11:57 +0200817 len += scnprintf(buf + len, sizeof(buf) - len, " CST");
Sujith Manoharan6bcf6f62012-02-16 11:51:02 +0530818 if (reg & ATH9K_INT_RX)
Zefir Kurtisi5e88ba62013-09-05 14:11:57 +0200819 len += scnprintf(buf + len, sizeof(buf) - len, " RX");
Sujith Manoharan6bcf6f62012-02-16 11:51:02 +0530820 if (reg & ATH9K_INT_RXHP)
Zefir Kurtisi5e88ba62013-09-05 14:11:57 +0200821 len += scnprintf(buf + len, sizeof(buf) - len, " RXHP");
Sujith Manoharan6bcf6f62012-02-16 11:51:02 +0530822 if (reg & ATH9K_INT_RXLP)
Zefir Kurtisi5e88ba62013-09-05 14:11:57 +0200823 len += scnprintf(buf + len, sizeof(buf) - len, " RXLP");
Sujith Manoharan6bcf6f62012-02-16 11:51:02 +0530824 if (reg & ATH9K_INT_BB_WATCHDOG)
Zefir Kurtisi5e88ba62013-09-05 14:11:57 +0200825 len += scnprintf(buf + len, sizeof(buf) - len, " BB_WATCHDOG");
Sujith Manoharan6bcf6f62012-02-16 11:51:02 +0530826
Zefir Kurtisi5e88ba62013-09-05 14:11:57 +0200827 len += scnprintf(buf + len, sizeof(buf) - len, "\n");
Sujith Manoharan6bcf6f62012-02-16 11:51:02 +0530828
829 ath9k_calculate_iter_data(hw, NULL, &iter_data);
830
Zefir Kurtisi5e88ba62013-09-05 14:11:57 +0200831 len += scnprintf(buf + len, sizeof(buf) - len,
832 "VIF-COUNTS: AP: %i STA: %i MESH: %i WDS: %i"
833 " ADHOC: %i TOTAL: %hi BEACON-VIF: %hi\n",
834 iter_data.naps, iter_data.nstations, iter_data.nmeshes,
835 iter_data.nwds, iter_data.nadhocs,
836 sc->nvifs, sc->nbcnvifs);
Ben Greear55f6d0f2011-01-17 11:54:50 -0800837
Sujith Manoharan6bcf6f62012-02-16 11:51:02 +0530838 if (len > sizeof(buf))
839 len = sizeof(buf);
Ben Greear55f6d0f2011-01-17 11:54:50 -0800840
841 retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
Ben Greear55f6d0f2011-01-17 11:54:50 -0800842 return retval;
843}
844
Sujith Manoharanf8b815d2012-02-16 11:51:11 +0530845static ssize_t read_file_reset(struct file *file, char __user *user_buf,
846 size_t count, loff_t *ppos)
847{
848 struct ath_softc *sc = file->private_data;
849 char buf[512];
850 unsigned int len = 0;
851
Zefir Kurtisi5e88ba62013-09-05 14:11:57 +0200852 len += scnprintf(buf + len, sizeof(buf) - len,
853 "%17s: %2d\n", "Baseband Hang",
854 sc->debug.stats.reset[RESET_TYPE_BB_HANG]);
855 len += scnprintf(buf + len, sizeof(buf) - len,
856 "%17s: %2d\n", "Baseband Watchdog",
857 sc->debug.stats.reset[RESET_TYPE_BB_WATCHDOG]);
858 len += scnprintf(buf + len, sizeof(buf) - len,
859 "%17s: %2d\n", "Fatal HW Error",
860 sc->debug.stats.reset[RESET_TYPE_FATAL_INT]);
861 len += scnprintf(buf + len, sizeof(buf) - len,
862 "%17s: %2d\n", "TX HW error",
863 sc->debug.stats.reset[RESET_TYPE_TX_ERROR]);
864 len += scnprintf(buf + len, sizeof(buf) - len,
865 "%17s: %2d\n", "TX Path Hang",
866 sc->debug.stats.reset[RESET_TYPE_TX_HANG]);
867 len += scnprintf(buf + len, sizeof(buf) - len,
868 "%17s: %2d\n", "PLL RX Hang",
869 sc->debug.stats.reset[RESET_TYPE_PLL_HANG]);
870 len += scnprintf(buf + len, sizeof(buf) - len,
Felix Fietkau443626e52014-02-21 11:45:36 +0100871 "%17s: %2d\n", "MAC Hang",
872 sc->debug.stats.reset[RESET_TYPE_MAC_HANG]);
873 len += scnprintf(buf + len, sizeof(buf) - len,
874 "%17s: %2d\n", "Stuck Beacon",
875 sc->debug.stats.reset[RESET_TYPE_BEACON_STUCK]);
876 len += scnprintf(buf + len, sizeof(buf) - len,
Zefir Kurtisi5e88ba62013-09-05 14:11:57 +0200877 "%17s: %2d\n", "MCI Reset",
878 sc->debug.stats.reset[RESET_TYPE_MCI]);
Sujith Manoharanf8b815d2012-02-16 11:51:11 +0530879
880 if (len > sizeof(buf))
881 len = sizeof(buf);
882
883 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
884}
885
Felix Fietkau066dae92010-11-07 14:59:39 +0100886void ath_debug_stat_tx(struct ath_softc *sc, struct ath_buf *bf,
Felix Fietkau55797b12011-09-14 21:24:16 +0200887 struct ath_tx_status *ts, struct ath_txq *txq,
888 unsigned int flags)
Sujithfec247c2009-07-27 12:08:16 +0530889{
Felix Fietkau5bec3e52011-01-24 21:29:25 +0100890 int qnum = txq->axq_qnum;
Felix Fietkau066dae92010-11-07 14:59:39 +0100891
892 TX_STAT_INC(qnum, tx_pkts_all);
893 sc->debug.stats.txstats[qnum].tx_bytes_all += bf->bf_mpdu->len;
Ben Greear99c15bf2010-10-01 12:26:30 -0700894
Sujithfec247c2009-07-27 12:08:16 +0530895 if (bf_isampdu(bf)) {
Felix Fietkau156369f2011-12-14 22:08:04 +0100896 if (flags & ATH_TX_ERROR)
Felix Fietkau066dae92010-11-07 14:59:39 +0100897 TX_STAT_INC(qnum, a_xretries);
Sujithfec247c2009-07-27 12:08:16 +0530898 else
Felix Fietkau066dae92010-11-07 14:59:39 +0100899 TX_STAT_INC(qnum, a_completed);
Sujithfec247c2009-07-27 12:08:16 +0530900 } else {
Felix Fietkau55797b12011-09-14 21:24:16 +0200901 if (ts->ts_status & ATH9K_TXERR_XRETRY)
Felix Fietkau5a6f78a2011-05-31 21:21:41 +0200902 TX_STAT_INC(qnum, xretries);
903 else
904 TX_STAT_INC(qnum, completed);
Sujithfec247c2009-07-27 12:08:16 +0530905 }
906
Ben Greear4d900382013-03-04 15:31:16 -0800907 if (ts->ts_status & ATH9K_TXERR_FILT)
908 TX_STAT_INC(qnum, txerr_filtered);
Felix Fietkaudb1a0522010-03-29 20:07:11 -0700909 if (ts->ts_status & ATH9K_TXERR_FIFO)
Felix Fietkau066dae92010-11-07 14:59:39 +0100910 TX_STAT_INC(qnum, fifo_underrun);
Felix Fietkaudb1a0522010-03-29 20:07:11 -0700911 if (ts->ts_status & ATH9K_TXERR_XTXOP)
Felix Fietkau066dae92010-11-07 14:59:39 +0100912 TX_STAT_INC(qnum, xtxop);
Felix Fietkaudb1a0522010-03-29 20:07:11 -0700913 if (ts->ts_status & ATH9K_TXERR_TIMER_EXPIRED)
Felix Fietkau066dae92010-11-07 14:59:39 +0100914 TX_STAT_INC(qnum, timer_exp);
Felix Fietkaudb1a0522010-03-29 20:07:11 -0700915 if (ts->ts_flags & ATH9K_TX_DESC_CFG_ERR)
Felix Fietkau066dae92010-11-07 14:59:39 +0100916 TX_STAT_INC(qnum, desc_cfg_err);
Felix Fietkaudb1a0522010-03-29 20:07:11 -0700917 if (ts->ts_flags & ATH9K_TX_DATA_UNDERRUN)
Felix Fietkau066dae92010-11-07 14:59:39 +0100918 TX_STAT_INC(qnum, data_underrun);
Felix Fietkaudb1a0522010-03-29 20:07:11 -0700919 if (ts->ts_flags & ATH9K_TX_DELIM_UNDERRUN)
Felix Fietkau066dae92010-11-07 14:59:39 +0100920 TX_STAT_INC(qnum, delim_underrun);
Sujithfec247c2009-07-27 12:08:16 +0530921}
922
923static const struct file_operations fops_xmit = {
924 .read = read_file_xmit,
Stephen Boyd234e3402012-04-05 14:25:11 -0700925 .open = simple_open,
Arnd Bergmann6038f372010-08-15 18:52:59 +0200926 .owner = THIS_MODULE,
927 .llseek = default_llseek,
Sujithfec247c2009-07-27 12:08:16 +0530928};
Jouni Malinen39d89cd2009-03-03 19:23:40 +0200929
Sujith Manoharanc0b74872012-11-21 18:13:12 +0530930static const struct file_operations fops_queues = {
931 .read = read_file_queues,
932 .open = simple_open,
933 .owner = THIS_MODULE,
934 .llseek = default_llseek,
935};
936
Ben Greear55f6d0f2011-01-17 11:54:50 -0800937static const struct file_operations fops_misc = {
938 .read = read_file_misc,
Stephen Boyd234e3402012-04-05 14:25:11 -0700939 .open = simple_open,
Ben Greear55f6d0f2011-01-17 11:54:50 -0800940 .owner = THIS_MODULE,
941 .llseek = default_llseek,
942};
943
Sujith Manoharanf8b815d2012-02-16 11:51:11 +0530944static const struct file_operations fops_reset = {
945 .read = read_file_reset,
Stephen Boyd234e3402012-04-05 14:25:11 -0700946 .open = simple_open,
Sujith Manoharanf8b815d2012-02-16 11:51:11 +0530947 .owner = THIS_MODULE,
948 .llseek = default_llseek,
949};
950
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -0700951void ath_debug_stat_rx(struct ath_softc *sc, struct ath_rx_status *rs)
Sujith1395d3f2010-01-08 10:36:11 +0530952{
Oleksij Rempelb5a0c862014-05-11 10:04:36 +0200953 ath9k_cmn_debug_stat_rx(&sc->debug.stats.rxstats, rs);
Sujith1395d3f2010-01-08 10:36:11 +0530954}
955
Sujith Manoharanc3b9f9e2014-01-13 07:29:29 +0530956static ssize_t read_file_phy_err(struct file *file, char __user *user_buf,
957 size_t count, loff_t *ppos)
958{
959#define PHY_ERR(s, p) \
960 len += scnprintf(buf + len, size - len, "%22s : %10u\n", s, \
961 sc->debug.stats.rxstats.phy_err_stats[p]);
962
963 struct ath_softc *sc = file->private_data;
964 char *buf;
965 unsigned int len = 0, size = 1600;
966 ssize_t retval = 0;
967
968 buf = kzalloc(size, GFP_KERNEL);
969 if (buf == NULL)
970 return -ENOMEM;
971
972 PHY_ERR("UNDERRUN ERR", ATH9K_PHYERR_UNDERRUN);
973 PHY_ERR("TIMING ERR", ATH9K_PHYERR_TIMING);
974 PHY_ERR("PARITY ERR", ATH9K_PHYERR_PARITY);
975 PHY_ERR("RATE ERR", ATH9K_PHYERR_RATE);
976 PHY_ERR("LENGTH ERR", ATH9K_PHYERR_LENGTH);
977 PHY_ERR("RADAR ERR", ATH9K_PHYERR_RADAR);
978 PHY_ERR("SERVICE ERR", ATH9K_PHYERR_SERVICE);
979 PHY_ERR("TOR ERR", ATH9K_PHYERR_TOR);
980 PHY_ERR("OFDM-TIMING ERR", ATH9K_PHYERR_OFDM_TIMING);
981 PHY_ERR("OFDM-SIGNAL-PARITY ERR", ATH9K_PHYERR_OFDM_SIGNAL_PARITY);
982 PHY_ERR("OFDM-RATE ERR", ATH9K_PHYERR_OFDM_RATE_ILLEGAL);
983 PHY_ERR("OFDM-LENGTH ERR", ATH9K_PHYERR_OFDM_LENGTH_ILLEGAL);
984 PHY_ERR("OFDM-POWER-DROP ERR", ATH9K_PHYERR_OFDM_POWER_DROP);
985 PHY_ERR("OFDM-SERVICE ERR", ATH9K_PHYERR_OFDM_SERVICE);
986 PHY_ERR("OFDM-RESTART ERR", ATH9K_PHYERR_OFDM_RESTART);
987 PHY_ERR("FALSE-RADAR-EXT ERR", ATH9K_PHYERR_FALSE_RADAR_EXT);
988 PHY_ERR("CCK-TIMING ERR", ATH9K_PHYERR_CCK_TIMING);
989 PHY_ERR("CCK-HEADER-CRC ERR", ATH9K_PHYERR_CCK_HEADER_CRC);
990 PHY_ERR("CCK-RATE ERR", ATH9K_PHYERR_CCK_RATE_ILLEGAL);
991 PHY_ERR("CCK-SERVICE ERR", ATH9K_PHYERR_CCK_SERVICE);
992 PHY_ERR("CCK-RESTART ERR", ATH9K_PHYERR_CCK_RESTART);
993 PHY_ERR("CCK-LENGTH ERR", ATH9K_PHYERR_CCK_LENGTH_ILLEGAL);
994 PHY_ERR("CCK-POWER-DROP ERR", ATH9K_PHYERR_CCK_POWER_DROP);
995 PHY_ERR("HT-CRC ERR", ATH9K_PHYERR_HT_CRC_ERROR);
996 PHY_ERR("HT-LENGTH ERR", ATH9K_PHYERR_HT_LENGTH_ILLEGAL);
997 PHY_ERR("HT-RATE ERR", ATH9K_PHYERR_HT_RATE_ILLEGAL);
998
999 if (len > size)
1000 len = size;
1001
1002 retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
1003 kfree(buf);
1004
1005 return retval;
1006
1007#undef PHY_ERR
1008}
1009
1010static const struct file_operations fops_phy_err = {
1011 .read = read_file_phy_err,
1012 .open = simple_open,
1013 .owner = THIS_MODULE,
1014 .llseek = default_llseek,
1015};
1016
Felix Fietkau9bff0bc2010-05-11 17:23:02 +02001017static ssize_t read_file_regidx(struct file *file, char __user *user_buf,
1018 size_t count, loff_t *ppos)
1019{
1020 struct ath_softc *sc = file->private_data;
1021 char buf[32];
1022 unsigned int len;
1023
Dan Carpenter2b87f3a2010-05-14 15:24:37 +02001024 len = sprintf(buf, "0x%08x\n", sc->debug.regidx);
Felix Fietkau9bff0bc2010-05-11 17:23:02 +02001025 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1026}
1027
1028static ssize_t write_file_regidx(struct file *file, const char __user *user_buf,
1029 size_t count, loff_t *ppos)
1030{
1031 struct ath_softc *sc = file->private_data;
1032 unsigned long regidx;
1033 char buf[32];
1034 ssize_t len;
1035
1036 len = min(count, sizeof(buf) - 1);
1037 if (copy_from_user(buf, user_buf, len))
Dan Carpenter04236062010-05-14 15:25:39 +02001038 return -EFAULT;
Felix Fietkau9bff0bc2010-05-11 17:23:02 +02001039
1040 buf[len] = '\0';
Jingoo Han27d7f472013-05-31 21:24:06 +00001041 if (kstrtoul(buf, 0, &regidx))
Felix Fietkau9bff0bc2010-05-11 17:23:02 +02001042 return -EINVAL;
1043
1044 sc->debug.regidx = regidx;
1045 return count;
1046}
1047
1048static const struct file_operations fops_regidx = {
1049 .read = read_file_regidx,
1050 .write = write_file_regidx,
Stephen Boyd234e3402012-04-05 14:25:11 -07001051 .open = simple_open,
Arnd Bergmann6038f372010-08-15 18:52:59 +02001052 .owner = THIS_MODULE,
1053 .llseek = default_llseek,
Felix Fietkau9bff0bc2010-05-11 17:23:02 +02001054};
1055
1056static ssize_t read_file_regval(struct file *file, char __user *user_buf,
1057 size_t count, loff_t *ppos)
1058{
1059 struct ath_softc *sc = file->private_data;
1060 struct ath_hw *ah = sc->sc_ah;
1061 char buf[32];
1062 unsigned int len;
1063 u32 regval;
1064
Rajkumar Manoharan79d2b152011-05-16 18:23:23 +05301065 ath9k_ps_wakeup(sc);
Felix Fietkau9bff0bc2010-05-11 17:23:02 +02001066 regval = REG_READ_D(ah, sc->debug.regidx);
Rajkumar Manoharan79d2b152011-05-16 18:23:23 +05301067 ath9k_ps_restore(sc);
Dan Carpenter2b87f3a2010-05-14 15:24:37 +02001068 len = sprintf(buf, "0x%08x\n", regval);
Felix Fietkau9bff0bc2010-05-11 17:23:02 +02001069 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1070}
1071
1072static ssize_t write_file_regval(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 struct ath_hw *ah = sc->sc_ah;
1077 unsigned long regval;
1078 char buf[32];
1079 ssize_t len;
1080
1081 len = min(count, sizeof(buf) - 1);
1082 if (copy_from_user(buf, user_buf, len))
Dan Carpenter04236062010-05-14 15:25:39 +02001083 return -EFAULT;
Felix Fietkau9bff0bc2010-05-11 17:23:02 +02001084
1085 buf[len] = '\0';
Jingoo Han27d7f472013-05-31 21:24:06 +00001086 if (kstrtoul(buf, 0, &regval))
Felix Fietkau9bff0bc2010-05-11 17:23:02 +02001087 return -EINVAL;
1088
Rajkumar Manoharan79d2b152011-05-16 18:23:23 +05301089 ath9k_ps_wakeup(sc);
Felix Fietkau9bff0bc2010-05-11 17:23:02 +02001090 REG_WRITE_D(ah, sc->debug.regidx, regval);
Rajkumar Manoharan79d2b152011-05-16 18:23:23 +05301091 ath9k_ps_restore(sc);
Felix Fietkau9bff0bc2010-05-11 17:23:02 +02001092 return count;
1093}
1094
1095static const struct file_operations fops_regval = {
1096 .read = read_file_regval,
1097 .write = write_file_regval,
Stephen Boyd234e3402012-04-05 14:25:11 -07001098 .open = simple_open,
Arnd Bergmann6038f372010-08-15 18:52:59 +02001099 .owner = THIS_MODULE,
1100 .llseek = default_llseek,
Felix Fietkau9bff0bc2010-05-11 17:23:02 +02001101};
1102
Vasanthakumar Thiagarajan582d0062011-03-01 05:30:55 -08001103#define REGDUMP_LINE_SIZE 20
1104
1105static int open_file_regdump(struct inode *inode, struct file *file)
1106{
1107 struct ath_softc *sc = inode->i_private;
1108 unsigned int len = 0;
1109 u8 *buf;
1110 int i;
1111 unsigned long num_regs, regdump_len, max_reg_offset;
1112
1113 max_reg_offset = AR_SREV_9300_20_OR_LATER(sc->sc_ah) ? 0x16bd4 : 0xb500;
1114 num_regs = max_reg_offset / 4 + 1;
1115 regdump_len = num_regs * REGDUMP_LINE_SIZE + 1;
1116 buf = vmalloc(regdump_len);
1117 if (!buf)
1118 return -ENOMEM;
1119
1120 ath9k_ps_wakeup(sc);
1121 for (i = 0; i < num_regs; i++)
1122 len += scnprintf(buf + len, regdump_len - len,
1123 "0x%06x 0x%08x\n", i << 2, REG_READ(sc->sc_ah, i << 2));
1124 ath9k_ps_restore(sc);
1125
1126 file->private_data = buf;
1127
1128 return 0;
1129}
1130
1131static const struct file_operations fops_regdump = {
1132 .open = open_file_regdump,
1133 .read = ath9k_debugfs_read_buf,
1134 .release = ath9k_debugfs_release_buf,
1135 .owner = THIS_MODULE,
1136 .llseek = default_llseek,/* read accesses f_pos */
1137};
1138
Rajkumar Manoharand069a462011-08-13 10:28:18 +05301139static ssize_t read_file_dump_nfcal(struct file *file, char __user *user_buf,
1140 size_t count, loff_t *ppos)
1141{
1142 struct ath_softc *sc = file->private_data;
1143 struct ath_hw *ah = sc->sc_ah;
1144 struct ath9k_nfcal_hist *h = sc->caldata.nfCalHist;
1145 struct ath_common *common = ath9k_hw_common(ah);
1146 struct ieee80211_conf *conf = &common->hw->conf;
1147 u32 len = 0, size = 1500;
1148 u32 i, j;
1149 ssize_t retval = 0;
1150 char *buf;
1151 u8 chainmask = (ah->rxchainmask << 3) | ah->rxchainmask;
1152 u8 nread;
1153
1154 buf = kzalloc(size, GFP_KERNEL);
1155 if (!buf)
1156 return -ENOMEM;
1157
Zefir Kurtisi5e88ba62013-09-05 14:11:57 +02001158 len += scnprintf(buf + len, size - len,
1159 "Channel Noise Floor : %d\n", ah->noise);
1160 len += scnprintf(buf + len, size - len,
1161 "Chain | privNF | # Readings | NF Readings\n");
Rajkumar Manoharand069a462011-08-13 10:28:18 +05301162 for (i = 0; i < NUM_NF_READINGS; i++) {
1163 if (!(chainmask & (1 << i)) ||
1164 ((i >= AR5416_MAX_CHAINS) && !conf_is_ht40(conf)))
1165 continue;
1166
1167 nread = AR_PHY_CCA_FILTERWINDOW_LENGTH - h[i].invalidNFcount;
Zefir Kurtisi5e88ba62013-09-05 14:11:57 +02001168 len += scnprintf(buf + len, size - len, " %d\t %d\t %d\t\t",
1169 i, h[i].privNF, nread);
Rajkumar Manoharand069a462011-08-13 10:28:18 +05301170 for (j = 0; j < nread; j++)
Zefir Kurtisi5e88ba62013-09-05 14:11:57 +02001171 len += scnprintf(buf + len, size - len,
1172 " %d", h[i].nfCalBuffer[j]);
1173 len += scnprintf(buf + len, size - len, "\n");
Rajkumar Manoharand069a462011-08-13 10:28:18 +05301174 }
1175
1176 if (len > size)
1177 len = size;
1178
1179 retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
1180 kfree(buf);
1181
1182 return retval;
1183}
1184
1185static const struct file_operations fops_dump_nfcal = {
1186 .read = read_file_dump_nfcal,
Stephen Boyd234e3402012-04-05 14:25:11 -07001187 .open = simple_open,
Rajkumar Manoharand069a462011-08-13 10:28:18 +05301188 .owner = THIS_MODULE,
1189 .llseek = default_llseek,
1190};
1191
Rajkumar Manoharan4df50ca2012-10-25 17:16:54 +05301192#ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
1193static ssize_t read_file_btcoex(struct file *file, char __user *user_buf,
1194 size_t count, loff_t *ppos)
1195{
1196 struct ath_softc *sc = file->private_data;
1197 u32 len = 0, size = 1500;
1198 char *buf;
1199 size_t retval;
1200
1201 buf = kzalloc(size, GFP_KERNEL);
1202 if (buf == NULL)
1203 return -ENOMEM;
1204
Sujith Manoharanac46ba42012-11-19 14:24:46 +05301205 if (!sc->sc_ah->common.btcoex_enabled) {
Zefir Kurtisi5e88ba62013-09-05 14:11:57 +02001206 len = scnprintf(buf, size, "%s\n",
1207 "BTCOEX is disabled");
Sujith Manoharanac46ba42012-11-19 14:24:46 +05301208 goto exit;
1209 }
Rajkumar Manoharan4df50ca2012-10-25 17:16:54 +05301210
Sujith Manoharanac46ba42012-11-19 14:24:46 +05301211 len = ath9k_dump_btcoex(sc, buf, size);
1212exit:
Rajkumar Manoharan4df50ca2012-10-25 17:16:54 +05301213 retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
1214 kfree(buf);
1215
1216 return retval;
1217}
1218
1219static const struct file_operations fops_btcoex = {
1220 .read = read_file_btcoex,
1221 .open = simple_open,
1222 .owner = THIS_MODULE,
1223 .llseek = default_llseek,
1224};
1225#endif
1226
Sujith Manoharanc175db82012-11-28 15:08:52 +05301227/* Ethtool support for get-stats */
1228
1229#define AMKSTR(nm) #nm "_BE", #nm "_BK", #nm "_VI", #nm "_VO"
1230static const char ath9k_gstrings_stats[][ETH_GSTRING_LEN] = {
1231 "tx_pkts_nic",
1232 "tx_bytes_nic",
1233 "rx_pkts_nic",
1234 "rx_bytes_nic",
1235 AMKSTR(d_tx_pkts),
1236 AMKSTR(d_tx_bytes),
1237 AMKSTR(d_tx_mpdus_queued),
1238 AMKSTR(d_tx_mpdus_completed),
1239 AMKSTR(d_tx_mpdu_xretries),
1240 AMKSTR(d_tx_aggregates),
1241 AMKSTR(d_tx_ampdus_queued_hw),
1242 AMKSTR(d_tx_ampdus_queued_sw),
1243 AMKSTR(d_tx_ampdus_completed),
1244 AMKSTR(d_tx_ampdu_retries),
1245 AMKSTR(d_tx_ampdu_xretries),
1246 AMKSTR(d_tx_fifo_underrun),
1247 AMKSTR(d_tx_op_exceeded),
1248 AMKSTR(d_tx_timer_expiry),
1249 AMKSTR(d_tx_desc_cfg_err),
1250 AMKSTR(d_tx_data_underrun),
1251 AMKSTR(d_tx_delim_underrun),
Ben Greear18c45b12013-03-04 15:31:17 -08001252 "d_rx_crc_err",
Sujith Manoharanc175db82012-11-28 15:08:52 +05301253 "d_rx_decrypt_crc_err",
1254 "d_rx_phy_err",
1255 "d_rx_mic_err",
1256 "d_rx_pre_delim_crc_err",
1257 "d_rx_post_delim_crc_err",
1258 "d_rx_decrypt_busy_err",
1259
1260 "d_rx_phyerr_radar",
1261 "d_rx_phyerr_ofdm_timing",
1262 "d_rx_phyerr_cck_timing",
1263
1264};
1265#define ATH9K_SSTATS_LEN ARRAY_SIZE(ath9k_gstrings_stats)
1266
1267void ath9k_get_et_strings(struct ieee80211_hw *hw,
1268 struct ieee80211_vif *vif,
1269 u32 sset, u8 *data)
1270{
1271 if (sset == ETH_SS_STATS)
1272 memcpy(data, *ath9k_gstrings_stats,
1273 sizeof(ath9k_gstrings_stats));
1274}
1275
1276int ath9k_get_et_sset_count(struct ieee80211_hw *hw,
1277 struct ieee80211_vif *vif, int sset)
1278{
1279 if (sset == ETH_SS_STATS)
1280 return ATH9K_SSTATS_LEN;
1281 return 0;
1282}
1283
1284#define AWDATA(elem) \
1285 do { \
1286 data[i++] = sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_BE)].elem; \
1287 data[i++] = sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_BK)].elem; \
1288 data[i++] = sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_VI)].elem; \
1289 data[i++] = sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_VO)].elem; \
1290 } while (0)
1291
1292#define AWDATA_RX(elem) \
1293 do { \
1294 data[i++] = sc->debug.stats.rxstats.elem; \
1295 } while (0)
1296
1297void ath9k_get_et_stats(struct ieee80211_hw *hw,
1298 struct ieee80211_vif *vif,
1299 struct ethtool_stats *stats, u64 *data)
1300{
1301 struct ath_softc *sc = hw->priv;
1302 int i = 0;
1303
1304 data[i++] = (sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_BE)].tx_pkts_all +
1305 sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_BK)].tx_pkts_all +
1306 sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_VI)].tx_pkts_all +
1307 sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_VO)].tx_pkts_all);
1308 data[i++] = (sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_BE)].tx_bytes_all +
1309 sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_BK)].tx_bytes_all +
1310 sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_VI)].tx_bytes_all +
1311 sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_VO)].tx_bytes_all);
1312 AWDATA_RX(rx_pkts_all);
1313 AWDATA_RX(rx_bytes_all);
1314
1315 AWDATA(tx_pkts_all);
1316 AWDATA(tx_bytes_all);
1317 AWDATA(queued);
1318 AWDATA(completed);
1319 AWDATA(xretries);
1320 AWDATA(a_aggr);
1321 AWDATA(a_queued_hw);
1322 AWDATA(a_queued_sw);
1323 AWDATA(a_completed);
1324 AWDATA(a_retries);
1325 AWDATA(a_xretries);
1326 AWDATA(fifo_underrun);
1327 AWDATA(xtxop);
1328 AWDATA(timer_exp);
1329 AWDATA(desc_cfg_err);
1330 AWDATA(data_underrun);
1331 AWDATA(delim_underrun);
1332
Ben Greear18c45b12013-03-04 15:31:17 -08001333 AWDATA_RX(crc_err);
Sujith Manoharanc175db82012-11-28 15:08:52 +05301334 AWDATA_RX(decrypt_crc_err);
1335 AWDATA_RX(phy_err);
1336 AWDATA_RX(mic_err);
1337 AWDATA_RX(pre_delim_crc_err);
1338 AWDATA_RX(post_delim_crc_err);
1339 AWDATA_RX(decrypt_busy_err);
1340
1341 AWDATA_RX(phy_err_stats[ATH9K_PHYERR_RADAR]);
1342 AWDATA_RX(phy_err_stats[ATH9K_PHYERR_OFDM_TIMING]);
1343 AWDATA_RX(phy_err_stats[ATH9K_PHYERR_CCK_TIMING]);
1344
1345 WARN_ON(i != ATH9K_SSTATS_LEN);
1346}
1347
Sujith Manoharanaf690092013-05-10 18:41:06 +05301348void ath9k_deinit_debug(struct ath_softc *sc)
1349{
Sujith Manoharanf65c0822013-12-18 09:53:18 +05301350 ath9k_spectral_deinit_debug(sc);
Sujith Manoharanaf690092013-05-10 18:41:06 +05301351}
1352
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001353int ath9k_init_debug(struct ath_hw *ah)
Sujith88b126a2008-11-28 22:19:02 +05301354{
Luis R. Rodriguezbc974f42009-09-28 02:54:40 -04001355 struct ath_common *common = ath9k_hw_common(ah);
1356 struct ath_softc *sc = (struct ath_softc *) common->priv;
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001357
Ben Greeareb272442010-11-29 14:13:22 -08001358 sc->debug.debugfs_phy = debugfs_create_dir("ath9k",
1359 sc->hw->wiphy->debugfsdir);
Sujith17d79042009-02-09 13:27:03 +05301360 if (!sc->debug.debugfs_phy)
Felix Fietkauc8a72c02010-05-11 17:23:00 +02001361 return -ENOMEM;
Sujith826d2682008-11-28 22:20:23 +05301362
Felix Fietkaua830df02009-11-23 22:33:27 +01001363#ifdef CONFIG_ATH_DEBUG
Felix Fietkauc70cab12011-03-19 13:55:37 +01001364 debugfs_create_file("debug", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
1365 sc, &fops_debug);
Felix Fietkaua830df02009-11-23 22:33:27 +01001366#endif
Zefir Kurtisi29942bc2011-12-14 20:16:34 -08001367
1368 ath9k_dfs_init_debug(sc);
Sujith Manoharanef6b19e2013-10-24 12:04:39 +05301369 ath9k_tx99_init_debug(sc);
Sujith Manoharanf65c0822013-12-18 09:53:18 +05301370 ath9k_spectral_init_debug(sc);
Zefir Kurtisi29942bc2011-12-14 20:16:34 -08001371
Felix Fietkauc70cab12011-03-19 13:55:37 +01001372 debugfs_create_file("dma", S_IRUSR, sc->debug.debugfs_phy, sc,
1373 &fops_dma);
1374 debugfs_create_file("interrupt", S_IRUSR, sc->debug.debugfs_phy, sc,
1375 &fops_interrupt);
Felix Fietkauc70cab12011-03-19 13:55:37 +01001376 debugfs_create_file("xmit", S_IRUSR, sc->debug.debugfs_phy, sc,
1377 &fops_xmit);
Sujith Manoharanc0b74872012-11-21 18:13:12 +05301378 debugfs_create_file("queues", S_IRUSR, sc->debug.debugfs_phy, sc,
1379 &fops_queues);
Felix Fietkau7702e782012-07-15 19:53:35 +02001380 debugfs_create_u32("qlen_bk", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
Sujith Manoharanbea843c2012-11-21 18:13:10 +05301381 &sc->tx.txq_max_pending[IEEE80211_AC_BK]);
Felix Fietkau7702e782012-07-15 19:53:35 +02001382 debugfs_create_u32("qlen_be", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
Sujith Manoharanbea843c2012-11-21 18:13:10 +05301383 &sc->tx.txq_max_pending[IEEE80211_AC_BE]);
Felix Fietkau7702e782012-07-15 19:53:35 +02001384 debugfs_create_u32("qlen_vi", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
Sujith Manoharanbea843c2012-11-21 18:13:10 +05301385 &sc->tx.txq_max_pending[IEEE80211_AC_VI]);
Felix Fietkau7702e782012-07-15 19:53:35 +02001386 debugfs_create_u32("qlen_vo", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
Sujith Manoharanbea843c2012-11-21 18:13:10 +05301387 &sc->tx.txq_max_pending[IEEE80211_AC_VO]);
Felix Fietkauc70cab12011-03-19 13:55:37 +01001388 debugfs_create_file("misc", S_IRUSR, sc->debug.debugfs_phy, sc,
1389 &fops_misc);
Sujith Manoharanf8b815d2012-02-16 11:51:11 +05301390 debugfs_create_file("reset", S_IRUSR, sc->debug.debugfs_phy, sc,
1391 &fops_reset);
Oleksij Rempel87ea9b02014-05-11 10:04:37 +02001392
1393 ath9k_cmn_debug_recv(sc->debug.debugfs_phy, &sc->debug.stats.rxstats);
1394
Sujith Manoharanc3b9f9e2014-01-13 07:29:29 +05301395 debugfs_create_file("phy_err", S_IRUSR, sc->debug.debugfs_phy, sc,
1396 &fops_phy_err);
Felix Fietkauca6d4a72013-08-13 12:33:27 +02001397 debugfs_create_u8("rx_chainmask", S_IRUSR, sc->debug.debugfs_phy,
1398 &ah->rxchainmask);
1399 debugfs_create_u8("tx_chainmask", S_IRUSR, sc->debug.debugfs_phy,
1400 &ah->txchainmask);
Sujith Manoharan6e4d2912013-06-03 09:19:28 +05301401 debugfs_create_file("ani", S_IRUSR | S_IWUSR,
1402 sc->debug.debugfs_phy, sc, &fops_ani);
Felix Fietkau74673db2012-09-08 15:24:17 +02001403 debugfs_create_bool("paprd", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
1404 &sc->sc_ah->config.enable_paprd);
Felix Fietkauc70cab12011-03-19 13:55:37 +01001405 debugfs_create_file("regidx", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
1406 sc, &fops_regidx);
1407 debugfs_create_file("regval", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
1408 sc, &fops_regval);
1409 debugfs_create_bool("ignore_extcca", S_IRUSR | S_IWUSR,
1410 sc->debug.debugfs_phy,
1411 &ah->config.cwm_ignore_extcca);
1412 debugfs_create_file("regdump", S_IRUSR, sc->debug.debugfs_phy, sc,
1413 &fops_regdump);
Rajkumar Manoharand069a462011-08-13 10:28:18 +05301414 debugfs_create_file("dump_nfcal", S_IRUSR, sc->debug.debugfs_phy, sc,
1415 &fops_dump_nfcal);
Oleksij Rempelf2c3c952014-05-11 10:04:31 +02001416
Oleksij Rempel29bf8012014-05-11 10:04:33 +02001417 ath9k_cmn_debug_base_eeprom(sc->debug.debugfs_phy, sc->sc_ah);
Oleksij Rempelf2c3c952014-05-11 10:04:31 +02001418 ath9k_cmn_debug_modal_eeprom(sc->debug.debugfs_phy, sc->sc_ah);
1419
Felix Fietkau691680b2011-03-19 13:55:38 +01001420 debugfs_create_u32("gpio_mask", S_IRUSR | S_IWUSR,
1421 sc->debug.debugfs_phy, &sc->sc_ah->gpio_mask);
Felix Fietkau691680b2011-03-19 13:55:38 +01001422 debugfs_create_u32("gpio_val", S_IRUSR | S_IWUSR,
1423 sc->debug.debugfs_phy, &sc->sc_ah->gpio_val);
Sujith Manoharan4eba10c2013-07-29 16:04:49 +05301424 debugfs_create_file("antenna_diversity", S_IRUSR,
1425 sc->debug.debugfs_phy, sc, &fops_antenna_diversity);
Rajkumar Manoharan4df50ca2012-10-25 17:16:54 +05301426#ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
Sujith Manoharan36e88252013-08-06 12:44:15 +05301427 debugfs_create_file("bt_ant_diversity", S_IRUSR | S_IWUSR,
1428 sc->debug.debugfs_phy, sc, &fops_bt_ant_diversity);
Rajkumar Manoharan4df50ca2012-10-25 17:16:54 +05301429 debugfs_create_file("btcoex", S_IRUSR, sc->debug.debugfs_phy, sc,
1430 &fops_btcoex);
1431#endif
Luis R. Rodriguez89f927a2013-10-14 17:42:11 -07001432
Sujith826d2682008-11-28 22:20:23 +05301433 return 0;
Sujith88b126a2008-11-28 22:19:02 +05301434}