debug.c 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922
  1. /*
  2. * Copyright (c) 2007-2008 Bruno Randolf <bruno@thinktube.com>
  3. *
  4. * This file is free software: you may copy, redistribute and/or modify it
  5. * under the terms of the GNU General Public License as published by the
  6. * Free Software Foundation, either version 2 of the License, or (at your
  7. * option) any later version.
  8. *
  9. * This file is distributed in the hope that it will be useful, but
  10. * WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. *
  17. *
  18. * This file incorporates work covered by the following copyright and
  19. * permission notice:
  20. *
  21. * Copyright (c) 2002-2005 Sam Leffler, Errno Consulting
  22. * Copyright (c) 2004-2005 Atheros Communications, Inc.
  23. * Copyright (c) 2006 Devicescape Software, Inc.
  24. * Copyright (c) 2007 Jiri Slaby <jirislaby@gmail.com>
  25. * Copyright (c) 2007 Luis R. Rodriguez <mcgrof@winlab.rutgers.edu>
  26. *
  27. * All rights reserved.
  28. *
  29. * Redistribution and use in source and binary forms, with or without
  30. * modification, are permitted provided that the following conditions
  31. * are met:
  32. * 1. Redistributions of source code must retain the above copyright
  33. * notice, this list of conditions and the following disclaimer,
  34. * without modification.
  35. * 2. Redistributions in binary form must reproduce at minimum a disclaimer
  36. * similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any
  37. * redistribution must be conditioned upon including a substantially
  38. * similar Disclaimer requirement for further binary redistribution.
  39. * 3. Neither the names of the above-listed copyright holders nor the names
  40. * of any contributors may be used to endorse or promote products derived
  41. * from this software without specific prior written permission.
  42. *
  43. * Alternatively, this software may be distributed under the terms of the
  44. * GNU General Public License ("GPL") version 2 as published by the Free
  45. * Software Foundation.
  46. *
  47. * NO WARRANTY
  48. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  49. * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  50. * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY
  51. * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
  52. * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY,
  53. * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  54. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  55. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
  56. * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  57. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  58. * THE POSSIBILITY OF SUCH DAMAGES.
  59. */
  60. #include "base.h"
  61. #include "debug.h"
  62. static unsigned int ath5k_debug;
  63. module_param_named(debug, ath5k_debug, uint, 0);
  64. #ifdef CONFIG_ATH5K_DEBUG
  65. #include <linux/seq_file.h>
  66. #include "reg.h"
  67. #include "ani.h"
  68. static struct dentry *ath5k_global_debugfs;
  69. static int ath5k_debugfs_open(struct inode *inode, struct file *file)
  70. {
  71. file->private_data = inode->i_private;
  72. return 0;
  73. }
  74. /* debugfs: registers */
  75. struct reg {
  76. const char *name;
  77. int addr;
  78. };
  79. #define REG_STRUCT_INIT(r) { #r, r }
  80. /* just a few random registers, might want to add more */
  81. static const struct reg regs[] = {
  82. REG_STRUCT_INIT(AR5K_CR),
  83. REG_STRUCT_INIT(AR5K_RXDP),
  84. REG_STRUCT_INIT(AR5K_CFG),
  85. REG_STRUCT_INIT(AR5K_IER),
  86. REG_STRUCT_INIT(AR5K_BCR),
  87. REG_STRUCT_INIT(AR5K_RTSD0),
  88. REG_STRUCT_INIT(AR5K_RTSD1),
  89. REG_STRUCT_INIT(AR5K_TXCFG),
  90. REG_STRUCT_INIT(AR5K_RXCFG),
  91. REG_STRUCT_INIT(AR5K_RXJLA),
  92. REG_STRUCT_INIT(AR5K_MIBC),
  93. REG_STRUCT_INIT(AR5K_TOPS),
  94. REG_STRUCT_INIT(AR5K_RXNOFRM),
  95. REG_STRUCT_INIT(AR5K_TXNOFRM),
  96. REG_STRUCT_INIT(AR5K_RPGTO),
  97. REG_STRUCT_INIT(AR5K_RFCNT),
  98. REG_STRUCT_INIT(AR5K_MISC),
  99. REG_STRUCT_INIT(AR5K_QCUDCU_CLKGT),
  100. REG_STRUCT_INIT(AR5K_ISR),
  101. REG_STRUCT_INIT(AR5K_PISR),
  102. REG_STRUCT_INIT(AR5K_SISR0),
  103. REG_STRUCT_INIT(AR5K_SISR1),
  104. REG_STRUCT_INIT(AR5K_SISR2),
  105. REG_STRUCT_INIT(AR5K_SISR3),
  106. REG_STRUCT_INIT(AR5K_SISR4),
  107. REG_STRUCT_INIT(AR5K_IMR),
  108. REG_STRUCT_INIT(AR5K_PIMR),
  109. REG_STRUCT_INIT(AR5K_SIMR0),
  110. REG_STRUCT_INIT(AR5K_SIMR1),
  111. REG_STRUCT_INIT(AR5K_SIMR2),
  112. REG_STRUCT_INIT(AR5K_SIMR3),
  113. REG_STRUCT_INIT(AR5K_SIMR4),
  114. REG_STRUCT_INIT(AR5K_DCM_ADDR),
  115. REG_STRUCT_INIT(AR5K_DCCFG),
  116. REG_STRUCT_INIT(AR5K_CCFG),
  117. REG_STRUCT_INIT(AR5K_CPC0),
  118. REG_STRUCT_INIT(AR5K_CPC1),
  119. REG_STRUCT_INIT(AR5K_CPC2),
  120. REG_STRUCT_INIT(AR5K_CPC3),
  121. REG_STRUCT_INIT(AR5K_CPCOVF),
  122. REG_STRUCT_INIT(AR5K_RESET_CTL),
  123. REG_STRUCT_INIT(AR5K_SLEEP_CTL),
  124. REG_STRUCT_INIT(AR5K_INTPEND),
  125. REG_STRUCT_INIT(AR5K_SFR),
  126. REG_STRUCT_INIT(AR5K_PCICFG),
  127. REG_STRUCT_INIT(AR5K_GPIOCR),
  128. REG_STRUCT_INIT(AR5K_GPIODO),
  129. REG_STRUCT_INIT(AR5K_SREV),
  130. };
  131. static void *reg_start(struct seq_file *seq, loff_t *pos)
  132. {
  133. return *pos < ARRAY_SIZE(regs) ? (void *)&regs[*pos] : NULL;
  134. }
  135. static void reg_stop(struct seq_file *seq, void *p)
  136. {
  137. /* nothing to do */
  138. }
  139. static void *reg_next(struct seq_file *seq, void *p, loff_t *pos)
  140. {
  141. ++*pos;
  142. return *pos < ARRAY_SIZE(regs) ? (void *)&regs[*pos] : NULL;
  143. }
  144. static int reg_show(struct seq_file *seq, void *p)
  145. {
  146. struct ath5k_softc *sc = seq->private;
  147. struct reg *r = p;
  148. seq_printf(seq, "%-25s0x%08x\n", r->name,
  149. ath5k_hw_reg_read(sc->ah, r->addr));
  150. return 0;
  151. }
  152. static const struct seq_operations register_seq_ops = {
  153. .start = reg_start,
  154. .next = reg_next,
  155. .stop = reg_stop,
  156. .show = reg_show
  157. };
  158. static int open_file_registers(struct inode *inode, struct file *file)
  159. {
  160. struct seq_file *s;
  161. int res;
  162. res = seq_open(file, &register_seq_ops);
  163. if (res == 0) {
  164. s = file->private_data;
  165. s->private = inode->i_private;
  166. }
  167. return res;
  168. }
  169. static const struct file_operations fops_registers = {
  170. .open = open_file_registers,
  171. .read = seq_read,
  172. .llseek = seq_lseek,
  173. .release = seq_release,
  174. .owner = THIS_MODULE,
  175. };
  176. /* debugfs: beacons */
  177. static ssize_t read_file_beacon(struct file *file, char __user *user_buf,
  178. size_t count, loff_t *ppos)
  179. {
  180. struct ath5k_softc *sc = file->private_data;
  181. struct ath5k_hw *ah = sc->ah;
  182. char buf[500];
  183. unsigned int len = 0;
  184. unsigned int v;
  185. u64 tsf;
  186. v = ath5k_hw_reg_read(sc->ah, AR5K_BEACON);
  187. len += snprintf(buf+len, sizeof(buf)-len,
  188. "%-24s0x%08x\tintval: %d\tTIM: 0x%x\n",
  189. "AR5K_BEACON", v, v & AR5K_BEACON_PERIOD,
  190. (v & AR5K_BEACON_TIM) >> AR5K_BEACON_TIM_S);
  191. len += snprintf(buf+len, sizeof(buf)-len, "%-24s0x%08x\n",
  192. "AR5K_LAST_TSTP", ath5k_hw_reg_read(sc->ah, AR5K_LAST_TSTP));
  193. len += snprintf(buf+len, sizeof(buf)-len, "%-24s0x%08x\n\n",
  194. "AR5K_BEACON_CNT", ath5k_hw_reg_read(sc->ah, AR5K_BEACON_CNT));
  195. v = ath5k_hw_reg_read(sc->ah, AR5K_TIMER0);
  196. len += snprintf(buf+len, sizeof(buf)-len, "%-24s0x%08x\tTU: %08x\n",
  197. "AR5K_TIMER0 (TBTT)", v, v);
  198. v = ath5k_hw_reg_read(sc->ah, AR5K_TIMER1);
  199. len += snprintf(buf+len, sizeof(buf)-len, "%-24s0x%08x\tTU: %08x\n",
  200. "AR5K_TIMER1 (DMA)", v, v >> 3);
  201. v = ath5k_hw_reg_read(sc->ah, AR5K_TIMER2);
  202. len += snprintf(buf+len, sizeof(buf)-len, "%-24s0x%08x\tTU: %08x\n",
  203. "AR5K_TIMER2 (SWBA)", v, v >> 3);
  204. v = ath5k_hw_reg_read(sc->ah, AR5K_TIMER3);
  205. len += snprintf(buf+len, sizeof(buf)-len, "%-24s0x%08x\tTU: %08x\n",
  206. "AR5K_TIMER3 (ATIM)", v, v);
  207. tsf = ath5k_hw_get_tsf64(sc->ah);
  208. len += snprintf(buf+len, sizeof(buf)-len,
  209. "TSF\t\t0x%016llx\tTU: %08x\n",
  210. (unsigned long long)tsf, TSF_TO_TU(tsf));
  211. return simple_read_from_buffer(user_buf, count, ppos, buf, len);
  212. }
  213. static ssize_t write_file_beacon(struct file *file,
  214. const char __user *userbuf,
  215. size_t count, loff_t *ppos)
  216. {
  217. struct ath5k_softc *sc = file->private_data;
  218. struct ath5k_hw *ah = sc->ah;
  219. char buf[20];
  220. if (copy_from_user(buf, userbuf, min(count, sizeof(buf))))
  221. return -EFAULT;
  222. if (strncmp(buf, "disable", 7) == 0) {
  223. AR5K_REG_DISABLE_BITS(ah, AR5K_BEACON, AR5K_BEACON_ENABLE);
  224. printk(KERN_INFO "debugfs disable beacons\n");
  225. } else if (strncmp(buf, "enable", 6) == 0) {
  226. AR5K_REG_ENABLE_BITS(ah, AR5K_BEACON, AR5K_BEACON_ENABLE);
  227. printk(KERN_INFO "debugfs enable beacons\n");
  228. }
  229. return count;
  230. }
  231. static const struct file_operations fops_beacon = {
  232. .read = read_file_beacon,
  233. .write = write_file_beacon,
  234. .open = ath5k_debugfs_open,
  235. .owner = THIS_MODULE,
  236. };
  237. /* debugfs: reset */
  238. static ssize_t write_file_reset(struct file *file,
  239. const char __user *userbuf,
  240. size_t count, loff_t *ppos)
  241. {
  242. struct ath5k_softc *sc = file->private_data;
  243. tasklet_schedule(&sc->restq);
  244. return count;
  245. }
  246. static const struct file_operations fops_reset = {
  247. .write = write_file_reset,
  248. .open = ath5k_debugfs_open,
  249. .owner = THIS_MODULE,
  250. };
  251. /* debugfs: debug level */
  252. static const struct {
  253. enum ath5k_debug_level level;
  254. const char *name;
  255. const char *desc;
  256. } dbg_info[] = {
  257. { ATH5K_DEBUG_RESET, "reset", "reset and initialization" },
  258. { ATH5K_DEBUG_INTR, "intr", "interrupt handling" },
  259. { ATH5K_DEBUG_MODE, "mode", "mode init/setup" },
  260. { ATH5K_DEBUG_XMIT, "xmit", "basic xmit operation" },
  261. { ATH5K_DEBUG_BEACON, "beacon", "beacon handling" },
  262. { ATH5K_DEBUG_CALIBRATE, "calib", "periodic calibration" },
  263. { ATH5K_DEBUG_TXPOWER, "txpower", "transmit power setting" },
  264. { ATH5K_DEBUG_LED, "led", "LED management" },
  265. { ATH5K_DEBUG_DUMP_RX, "dumprx", "print received skb content" },
  266. { ATH5K_DEBUG_DUMP_TX, "dumptx", "print transmit skb content" },
  267. { ATH5K_DEBUG_DUMPBANDS, "dumpbands", "dump bands" },
  268. { ATH5K_DEBUG_TRACE, "trace", "trace function calls" },
  269. { ATH5K_DEBUG_ANI, "ani", "adaptive noise immunity" },
  270. { ATH5K_DEBUG_ANY, "all", "show all debug levels" },
  271. };
  272. static ssize_t read_file_debug(struct file *file, char __user *user_buf,
  273. size_t count, loff_t *ppos)
  274. {
  275. struct ath5k_softc *sc = file->private_data;
  276. char buf[700];
  277. unsigned int len = 0;
  278. unsigned int i;
  279. len += snprintf(buf+len, sizeof(buf)-len,
  280. "DEBUG LEVEL: 0x%08x\n\n", sc->debug.level);
  281. for (i = 0; i < ARRAY_SIZE(dbg_info) - 1; i++) {
  282. len += snprintf(buf+len, sizeof(buf)-len,
  283. "%10s %c 0x%08x - %s\n", dbg_info[i].name,
  284. sc->debug.level & dbg_info[i].level ? '+' : ' ',
  285. dbg_info[i].level, dbg_info[i].desc);
  286. }
  287. len += snprintf(buf+len, sizeof(buf)-len,
  288. "%10s %c 0x%08x - %s\n", dbg_info[i].name,
  289. sc->debug.level == dbg_info[i].level ? '+' : ' ',
  290. dbg_info[i].level, dbg_info[i].desc);
  291. return simple_read_from_buffer(user_buf, count, ppos, buf, len);
  292. }
  293. static ssize_t write_file_debug(struct file *file,
  294. const char __user *userbuf,
  295. size_t count, loff_t *ppos)
  296. {
  297. struct ath5k_softc *sc = file->private_data;
  298. unsigned int i;
  299. char buf[20];
  300. if (copy_from_user(buf, userbuf, min(count, sizeof(buf))))
  301. return -EFAULT;
  302. for (i = 0; i < ARRAY_SIZE(dbg_info); i++) {
  303. if (strncmp(buf, dbg_info[i].name,
  304. strlen(dbg_info[i].name)) == 0) {
  305. sc->debug.level ^= dbg_info[i].level; /* toggle bit */
  306. break;
  307. }
  308. }
  309. return count;
  310. }
  311. static const struct file_operations fops_debug = {
  312. .read = read_file_debug,
  313. .write = write_file_debug,
  314. .open = ath5k_debugfs_open,
  315. .owner = THIS_MODULE,
  316. };
  317. /* debugfs: antenna */
  318. static ssize_t read_file_antenna(struct file *file, char __user *user_buf,
  319. size_t count, loff_t *ppos)
  320. {
  321. struct ath5k_softc *sc = file->private_data;
  322. char buf[700];
  323. unsigned int len = 0;
  324. unsigned int i;
  325. unsigned int v;
  326. len += snprintf(buf+len, sizeof(buf)-len, "antenna mode\t%d\n",
  327. sc->ah->ah_ant_mode);
  328. len += snprintf(buf+len, sizeof(buf)-len, "default antenna\t%d\n",
  329. sc->ah->ah_def_ant);
  330. len += snprintf(buf+len, sizeof(buf)-len, "tx antenna\t%d\n",
  331. sc->ah->ah_tx_ant);
  332. len += snprintf(buf+len, sizeof(buf)-len, "\nANTENNA\t\tRX\tTX\n");
  333. for (i = 1; i < ARRAY_SIZE(sc->stats.antenna_rx); i++) {
  334. len += snprintf(buf+len, sizeof(buf)-len,
  335. "[antenna %d]\t%d\t%d\n",
  336. i, sc->stats.antenna_rx[i], sc->stats.antenna_tx[i]);
  337. }
  338. len += snprintf(buf+len, sizeof(buf)-len, "[invalid]\t%d\t%d\n",
  339. sc->stats.antenna_rx[0], sc->stats.antenna_tx[0]);
  340. v = ath5k_hw_reg_read(sc->ah, AR5K_DEFAULT_ANTENNA);
  341. len += snprintf(buf+len, sizeof(buf)-len,
  342. "\nAR5K_DEFAULT_ANTENNA\t0x%08x\n", v);
  343. v = ath5k_hw_reg_read(sc->ah, AR5K_STA_ID1);
  344. len += snprintf(buf+len, sizeof(buf)-len,
  345. "AR5K_STA_ID1_DEFAULT_ANTENNA\t%d\n",
  346. (v & AR5K_STA_ID1_DEFAULT_ANTENNA) != 0);
  347. len += snprintf(buf+len, sizeof(buf)-len,
  348. "AR5K_STA_ID1_DESC_ANTENNA\t%d\n",
  349. (v & AR5K_STA_ID1_DESC_ANTENNA) != 0);
  350. len += snprintf(buf+len, sizeof(buf)-len,
  351. "AR5K_STA_ID1_RTS_DEF_ANTENNA\t%d\n",
  352. (v & AR5K_STA_ID1_RTS_DEF_ANTENNA) != 0);
  353. len += snprintf(buf+len, sizeof(buf)-len,
  354. "AR5K_STA_ID1_SELFGEN_DEF_ANT\t%d\n",
  355. (v & AR5K_STA_ID1_SELFGEN_DEF_ANT) != 0);
  356. v = ath5k_hw_reg_read(sc->ah, AR5K_PHY_AGCCTL);
  357. len += snprintf(buf+len, sizeof(buf)-len,
  358. "\nAR5K_PHY_AGCCTL_OFDM_DIV_DIS\t%d\n",
  359. (v & AR5K_PHY_AGCCTL_OFDM_DIV_DIS) != 0);
  360. v = ath5k_hw_reg_read(sc->ah, AR5K_PHY_RESTART);
  361. len += snprintf(buf+len, sizeof(buf)-len,
  362. "AR5K_PHY_RESTART_DIV_GC\t\t%x\n",
  363. (v & AR5K_PHY_RESTART_DIV_GC) >> AR5K_PHY_RESTART_DIV_GC_S);
  364. v = ath5k_hw_reg_read(sc->ah, AR5K_PHY_FAST_ANT_DIV);
  365. len += snprintf(buf+len, sizeof(buf)-len,
  366. "AR5K_PHY_FAST_ANT_DIV_EN\t%d\n",
  367. (v & AR5K_PHY_FAST_ANT_DIV_EN) != 0);
  368. return simple_read_from_buffer(user_buf, count, ppos, buf, len);
  369. }
  370. static ssize_t write_file_antenna(struct file *file,
  371. const char __user *userbuf,
  372. size_t count, loff_t *ppos)
  373. {
  374. struct ath5k_softc *sc = file->private_data;
  375. unsigned int i;
  376. char buf[20];
  377. if (copy_from_user(buf, userbuf, min(count, sizeof(buf))))
  378. return -EFAULT;
  379. if (strncmp(buf, "diversity", 9) == 0) {
  380. ath5k_hw_set_antenna_mode(sc->ah, AR5K_ANTMODE_DEFAULT);
  381. printk(KERN_INFO "ath5k debug: enable diversity\n");
  382. } else if (strncmp(buf, "fixed-a", 7) == 0) {
  383. ath5k_hw_set_antenna_mode(sc->ah, AR5K_ANTMODE_FIXED_A);
  384. printk(KERN_INFO "ath5k debugfs: fixed antenna A\n");
  385. } else if (strncmp(buf, "fixed-b", 7) == 0) {
  386. ath5k_hw_set_antenna_mode(sc->ah, AR5K_ANTMODE_FIXED_B);
  387. printk(KERN_INFO "ath5k debug: fixed antenna B\n");
  388. } else if (strncmp(buf, "clear", 5) == 0) {
  389. for (i = 0; i < ARRAY_SIZE(sc->stats.antenna_rx); i++) {
  390. sc->stats.antenna_rx[i] = 0;
  391. sc->stats.antenna_tx[i] = 0;
  392. }
  393. printk(KERN_INFO "ath5k debug: cleared antenna stats\n");
  394. }
  395. return count;
  396. }
  397. static const struct file_operations fops_antenna = {
  398. .read = read_file_antenna,
  399. .write = write_file_antenna,
  400. .open = ath5k_debugfs_open,
  401. .owner = THIS_MODULE,
  402. };
  403. /* debugfs: frameerrors */
  404. static ssize_t read_file_frameerrors(struct file *file, char __user *user_buf,
  405. size_t count, loff_t *ppos)
  406. {
  407. struct ath5k_softc *sc = file->private_data;
  408. struct ath5k_statistics *st = &sc->stats;
  409. char buf[700];
  410. unsigned int len = 0;
  411. int i;
  412. len += snprintf(buf+len, sizeof(buf)-len,
  413. "RX\n---------------------\n");
  414. len += snprintf(buf+len, sizeof(buf)-len, "CRC\t%d\t(%d%%)\n",
  415. st->rxerr_crc,
  416. st->rx_all_count > 0 ?
  417. st->rxerr_crc*100/st->rx_all_count : 0);
  418. len += snprintf(buf+len, sizeof(buf)-len, "PHY\t%d\t(%d%%)\n",
  419. st->rxerr_phy,
  420. st->rx_all_count > 0 ?
  421. st->rxerr_phy*100/st->rx_all_count : 0);
  422. for (i = 0; i < 32; i++) {
  423. if (st->rxerr_phy_code[i])
  424. len += snprintf(buf+len, sizeof(buf)-len,
  425. " phy_err[%d]\t%d\n",
  426. i, st->rxerr_phy_code[i]);
  427. }
  428. len += snprintf(buf+len, sizeof(buf)-len, "FIFO\t%d\t(%d%%)\n",
  429. st->rxerr_fifo,
  430. st->rx_all_count > 0 ?
  431. st->rxerr_fifo*100/st->rx_all_count : 0);
  432. len += snprintf(buf+len, sizeof(buf)-len, "decrypt\t%d\t(%d%%)\n",
  433. st->rxerr_decrypt,
  434. st->rx_all_count > 0 ?
  435. st->rxerr_decrypt*100/st->rx_all_count : 0);
  436. len += snprintf(buf+len, sizeof(buf)-len, "MIC\t%d\t(%d%%)\n",
  437. st->rxerr_mic,
  438. st->rx_all_count > 0 ?
  439. st->rxerr_mic*100/st->rx_all_count : 0);
  440. len += snprintf(buf+len, sizeof(buf)-len, "process\t%d\t(%d%%)\n",
  441. st->rxerr_proc,
  442. st->rx_all_count > 0 ?
  443. st->rxerr_proc*100/st->rx_all_count : 0);
  444. len += snprintf(buf+len, sizeof(buf)-len, "jumbo\t%d\t(%d%%)\n",
  445. st->rxerr_jumbo,
  446. st->rx_all_count > 0 ?
  447. st->rxerr_jumbo*100/st->rx_all_count : 0);
  448. len += snprintf(buf+len, sizeof(buf)-len, "[RX all\t%d]\n",
  449. st->rx_all_count);
  450. len += snprintf(buf+len, sizeof(buf)-len,
  451. "\nTX\n---------------------\n");
  452. len += snprintf(buf+len, sizeof(buf)-len, "retry\t%d\t(%d%%)\n",
  453. st->txerr_retry,
  454. st->tx_all_count > 0 ?
  455. st->txerr_retry*100/st->tx_all_count : 0);
  456. len += snprintf(buf+len, sizeof(buf)-len, "FIFO\t%d\t(%d%%)\n",
  457. st->txerr_fifo,
  458. st->tx_all_count > 0 ?
  459. st->txerr_fifo*100/st->tx_all_count : 0);
  460. len += snprintf(buf+len, sizeof(buf)-len, "filter\t%d\t(%d%%)\n",
  461. st->txerr_filt,
  462. st->tx_all_count > 0 ?
  463. st->txerr_filt*100/st->tx_all_count : 0);
  464. len += snprintf(buf+len, sizeof(buf)-len, "[TX all\t%d]\n",
  465. st->tx_all_count);
  466. return simple_read_from_buffer(user_buf, count, ppos, buf, len);
  467. }
  468. static ssize_t write_file_frameerrors(struct file *file,
  469. const char __user *userbuf,
  470. size_t count, loff_t *ppos)
  471. {
  472. struct ath5k_softc *sc = file->private_data;
  473. struct ath5k_statistics *st = &sc->stats;
  474. char buf[20];
  475. if (copy_from_user(buf, userbuf, min(count, sizeof(buf))))
  476. return -EFAULT;
  477. if (strncmp(buf, "clear", 5) == 0) {
  478. st->rxerr_crc = 0;
  479. st->rxerr_phy = 0;
  480. st->rxerr_fifo = 0;
  481. st->rxerr_decrypt = 0;
  482. st->rxerr_mic = 0;
  483. st->rxerr_proc = 0;
  484. st->rxerr_jumbo = 0;
  485. st->rx_all_count = 0;
  486. st->txerr_retry = 0;
  487. st->txerr_fifo = 0;
  488. st->txerr_filt = 0;
  489. st->tx_all_count = 0;
  490. printk(KERN_INFO "ath5k debug: cleared frameerrors stats\n");
  491. }
  492. return count;
  493. }
  494. static const struct file_operations fops_frameerrors = {
  495. .read = read_file_frameerrors,
  496. .write = write_file_frameerrors,
  497. .open = ath5k_debugfs_open,
  498. .owner = THIS_MODULE,
  499. };
  500. /* debugfs: ani */
  501. static ssize_t read_file_ani(struct file *file, char __user *user_buf,
  502. size_t count, loff_t *ppos)
  503. {
  504. struct ath5k_softc *sc = file->private_data;
  505. struct ath5k_statistics *st = &sc->stats;
  506. struct ath5k_ani_state *as = &sc->ani_state;
  507. char buf[700];
  508. unsigned int len = 0;
  509. len += snprintf(buf+len, sizeof(buf)-len,
  510. "HW has PHY error counters:\t%s\n",
  511. sc->ah->ah_capabilities.cap_has_phyerr_counters ?
  512. "yes" : "no");
  513. len += snprintf(buf+len, sizeof(buf)-len,
  514. "HW max spur immunity level:\t%d\n",
  515. as->max_spur_level);
  516. len += snprintf(buf+len, sizeof(buf)-len,
  517. "\nANI state\n--------------------------------------------\n");
  518. len += snprintf(buf+len, sizeof(buf)-len, "operating mode:\t\t\t");
  519. switch (as->ani_mode) {
  520. case ATH5K_ANI_MODE_OFF:
  521. len += snprintf(buf+len, sizeof(buf)-len, "OFF\n");
  522. break;
  523. case ATH5K_ANI_MODE_MANUAL_LOW:
  524. len += snprintf(buf+len, sizeof(buf)-len,
  525. "MANUAL LOW\n");
  526. break;
  527. case ATH5K_ANI_MODE_MANUAL_HIGH:
  528. len += snprintf(buf+len, sizeof(buf)-len,
  529. "MANUAL HIGH\n");
  530. break;
  531. case ATH5K_ANI_MODE_AUTO:
  532. len += snprintf(buf+len, sizeof(buf)-len, "AUTO\n");
  533. break;
  534. default:
  535. len += snprintf(buf+len, sizeof(buf)-len,
  536. "??? (not good)\n");
  537. break;
  538. }
  539. len += snprintf(buf+len, sizeof(buf)-len,
  540. "noise immunity level:\t\t%d\n",
  541. as->noise_imm_level);
  542. len += snprintf(buf+len, sizeof(buf)-len,
  543. "spur immunity level:\t\t%d\n",
  544. as->spur_level);
  545. len += snprintf(buf+len, sizeof(buf)-len, "firstep level:\t\t\t%d\n",
  546. as->firstep_level);
  547. len += snprintf(buf+len, sizeof(buf)-len,
  548. "OFDM weak signal detection:\t%s\n",
  549. as->ofdm_weak_sig ? "on" : "off");
  550. len += snprintf(buf+len, sizeof(buf)-len,
  551. "CCK weak signal detection:\t%s\n",
  552. as->cck_weak_sig ? "on" : "off");
  553. len += snprintf(buf+len, sizeof(buf)-len,
  554. "\nMIB INTERRUPTS:\t\t%u\n",
  555. st->mib_intr);
  556. len += snprintf(buf+len, sizeof(buf)-len,
  557. "beacon RSSI average:\t%d\n",
  558. sc->ah->ah_beacon_rssi_avg.avg);
  559. len += snprintf(buf+len, sizeof(buf)-len, "profcnt tx\t\t%u\t(%d%%)\n",
  560. as->pfc_tx,
  561. as->pfc_cycles > 0 ?
  562. as->pfc_tx*100/as->pfc_cycles : 0);
  563. len += snprintf(buf+len, sizeof(buf)-len, "profcnt rx\t\t%u\t(%d%%)\n",
  564. as->pfc_rx,
  565. as->pfc_cycles > 0 ?
  566. as->pfc_rx*100/as->pfc_cycles : 0);
  567. len += snprintf(buf+len, sizeof(buf)-len, "profcnt busy\t\t%u\t(%d%%)\n",
  568. as->pfc_busy,
  569. as->pfc_cycles > 0 ?
  570. as->pfc_busy*100/as->pfc_cycles : 0);
  571. len += snprintf(buf+len, sizeof(buf)-len, "profcnt cycles\t\t%u\n",
  572. as->pfc_cycles);
  573. len += snprintf(buf+len, sizeof(buf)-len,
  574. "listen time\t\t%d\tlast: %d\n",
  575. as->listen_time, as->last_listen);
  576. len += snprintf(buf+len, sizeof(buf)-len,
  577. "OFDM errors\t\t%u\tlast: %u\tsum: %u\n",
  578. as->ofdm_errors, as->last_ofdm_errors,
  579. as->sum_ofdm_errors);
  580. len += snprintf(buf+len, sizeof(buf)-len,
  581. "CCK errors\t\t%u\tlast: %u\tsum: %u\n",
  582. as->cck_errors, as->last_cck_errors,
  583. as->sum_cck_errors);
  584. len += snprintf(buf+len, sizeof(buf)-len,
  585. "AR5K_PHYERR_CNT1\t%x\t(=%d)\n",
  586. ath5k_hw_reg_read(sc->ah, AR5K_PHYERR_CNT1),
  587. ATH5K_ANI_OFDM_TRIG_HIGH - (ATH5K_PHYERR_CNT_MAX -
  588. ath5k_hw_reg_read(sc->ah, AR5K_PHYERR_CNT1)));
  589. len += snprintf(buf+len, sizeof(buf)-len,
  590. "AR5K_PHYERR_CNT2\t%x\t(=%d)\n",
  591. ath5k_hw_reg_read(sc->ah, AR5K_PHYERR_CNT2),
  592. ATH5K_ANI_CCK_TRIG_HIGH - (ATH5K_PHYERR_CNT_MAX -
  593. ath5k_hw_reg_read(sc->ah, AR5K_PHYERR_CNT2)));
  594. return simple_read_from_buffer(user_buf, count, ppos, buf, len);
  595. }
  596. static ssize_t write_file_ani(struct file *file,
  597. const char __user *userbuf,
  598. size_t count, loff_t *ppos)
  599. {
  600. struct ath5k_softc *sc = file->private_data;
  601. char buf[20];
  602. if (copy_from_user(buf, userbuf, min(count, sizeof(buf))))
  603. return -EFAULT;
  604. if (strncmp(buf, "sens-low", 8) == 0) {
  605. ath5k_ani_init(sc->ah, ATH5K_ANI_MODE_MANUAL_HIGH);
  606. } else if (strncmp(buf, "sens-high", 9) == 0) {
  607. ath5k_ani_init(sc->ah, ATH5K_ANI_MODE_MANUAL_LOW);
  608. } else if (strncmp(buf, "ani-off", 7) == 0) {
  609. ath5k_ani_init(sc->ah, ATH5K_ANI_MODE_OFF);
  610. } else if (strncmp(buf, "ani-on", 6) == 0) {
  611. ath5k_ani_init(sc->ah, ATH5K_ANI_MODE_AUTO);
  612. } else if (strncmp(buf, "noise-low", 9) == 0) {
  613. ath5k_ani_set_noise_immunity_level(sc->ah, 0);
  614. } else if (strncmp(buf, "noise-high", 10) == 0) {
  615. ath5k_ani_set_noise_immunity_level(sc->ah,
  616. ATH5K_ANI_MAX_NOISE_IMM_LVL);
  617. } else if (strncmp(buf, "spur-low", 8) == 0) {
  618. ath5k_ani_set_spur_immunity_level(sc->ah, 0);
  619. } else if (strncmp(buf, "spur-high", 9) == 0) {
  620. ath5k_ani_set_spur_immunity_level(sc->ah,
  621. sc->ani_state.max_spur_level);
  622. } else if (strncmp(buf, "fir-low", 7) == 0) {
  623. ath5k_ani_set_firstep_level(sc->ah, 0);
  624. } else if (strncmp(buf, "fir-high", 8) == 0) {
  625. ath5k_ani_set_firstep_level(sc->ah, ATH5K_ANI_MAX_FIRSTEP_LVL);
  626. } else if (strncmp(buf, "ofdm-off", 8) == 0) {
  627. ath5k_ani_set_ofdm_weak_signal_detection(sc->ah, false);
  628. } else if (strncmp(buf, "ofdm-on", 7) == 0) {
  629. ath5k_ani_set_ofdm_weak_signal_detection(sc->ah, true);
  630. } else if (strncmp(buf, "cck-off", 7) == 0) {
  631. ath5k_ani_set_cck_weak_signal_detection(sc->ah, false);
  632. } else if (strncmp(buf, "cck-on", 6) == 0) {
  633. ath5k_ani_set_cck_weak_signal_detection(sc->ah, true);
  634. }
  635. return count;
  636. }
  637. static const struct file_operations fops_ani = {
  638. .read = read_file_ani,
  639. .write = write_file_ani,
  640. .open = ath5k_debugfs_open,
  641. .owner = THIS_MODULE,
  642. };
  643. /* init */
  644. void
  645. ath5k_debug_init(void)
  646. {
  647. ath5k_global_debugfs = debugfs_create_dir("ath5k", NULL);
  648. }
  649. void
  650. ath5k_debug_init_device(struct ath5k_softc *sc)
  651. {
  652. sc->debug.level = ath5k_debug;
  653. sc->debug.debugfs_phydir = debugfs_create_dir(wiphy_name(sc->hw->wiphy),
  654. ath5k_global_debugfs);
  655. sc->debug.debugfs_debug = debugfs_create_file("debug",
  656. S_IWUSR | S_IRUSR,
  657. sc->debug.debugfs_phydir, sc, &fops_debug);
  658. sc->debug.debugfs_registers = debugfs_create_file("registers", S_IRUSR,
  659. sc->debug.debugfs_phydir, sc, &fops_registers);
  660. sc->debug.debugfs_beacon = debugfs_create_file("beacon",
  661. S_IWUSR | S_IRUSR,
  662. sc->debug.debugfs_phydir, sc, &fops_beacon);
  663. sc->debug.debugfs_reset = debugfs_create_file("reset", S_IWUSR,
  664. sc->debug.debugfs_phydir, sc, &fops_reset);
  665. sc->debug.debugfs_antenna = debugfs_create_file("antenna",
  666. S_IWUSR | S_IRUSR,
  667. sc->debug.debugfs_phydir, sc, &fops_antenna);
  668. sc->debug.debugfs_frameerrors = debugfs_create_file("frameerrors",
  669. S_IWUSR | S_IRUSR,
  670. sc->debug.debugfs_phydir, sc,
  671. &fops_frameerrors);
  672. sc->debug.debugfs_ani = debugfs_create_file("ani",
  673. S_IWUSR | S_IRUSR,
  674. sc->debug.debugfs_phydir, sc,
  675. &fops_ani);
  676. }
  677. void
  678. ath5k_debug_finish(void)
  679. {
  680. debugfs_remove(ath5k_global_debugfs);
  681. }
  682. void
  683. ath5k_debug_finish_device(struct ath5k_softc *sc)
  684. {
  685. debugfs_remove(sc->debug.debugfs_debug);
  686. debugfs_remove(sc->debug.debugfs_registers);
  687. debugfs_remove(sc->debug.debugfs_beacon);
  688. debugfs_remove(sc->debug.debugfs_reset);
  689. debugfs_remove(sc->debug.debugfs_antenna);
  690. debugfs_remove(sc->debug.debugfs_frameerrors);
  691. debugfs_remove(sc->debug.debugfs_ani);
  692. debugfs_remove(sc->debug.debugfs_phydir);
  693. }
  694. /* functions used in other places */
  695. void
  696. ath5k_debug_dump_bands(struct ath5k_softc *sc)
  697. {
  698. unsigned int b, i;
  699. if (likely(!(sc->debug.level & ATH5K_DEBUG_DUMPBANDS)))
  700. return;
  701. BUG_ON(!sc->sbands);
  702. for (b = 0; b < IEEE80211_NUM_BANDS; b++) {
  703. struct ieee80211_supported_band *band = &sc->sbands[b];
  704. char bname[6];
  705. switch (band->band) {
  706. case IEEE80211_BAND_2GHZ:
  707. strcpy(bname, "2 GHz");
  708. break;
  709. case IEEE80211_BAND_5GHZ:
  710. strcpy(bname, "5 GHz");
  711. break;
  712. default:
  713. printk(KERN_DEBUG "Band not supported: %d\n",
  714. band->band);
  715. return;
  716. }
  717. printk(KERN_DEBUG "Band %s: channels %d, rates %d\n", bname,
  718. band->n_channels, band->n_bitrates);
  719. printk(KERN_DEBUG " channels:\n");
  720. for (i = 0; i < band->n_channels; i++)
  721. printk(KERN_DEBUG " %3d %d %.4x %.4x\n",
  722. ieee80211_frequency_to_channel(
  723. band->channels[i].center_freq),
  724. band->channels[i].center_freq,
  725. band->channels[i].hw_value,
  726. band->channels[i].flags);
  727. printk(KERN_DEBUG " rates:\n");
  728. for (i = 0; i < band->n_bitrates; i++)
  729. printk(KERN_DEBUG " %4d %.4x %.4x %.4x\n",
  730. band->bitrates[i].bitrate,
  731. band->bitrates[i].hw_value,
  732. band->bitrates[i].flags,
  733. band->bitrates[i].hw_value_short);
  734. }
  735. }
  736. static inline void
  737. ath5k_debug_printrxbuf(struct ath5k_buf *bf, int done,
  738. struct ath5k_rx_status *rs)
  739. {
  740. struct ath5k_desc *ds = bf->desc;
  741. struct ath5k_hw_all_rx_desc *rd = &ds->ud.ds_rx;
  742. printk(KERN_DEBUG "R (%p %llx) %08x %08x %08x %08x %08x %08x %c\n",
  743. ds, (unsigned long long)bf->daddr,
  744. ds->ds_link, ds->ds_data,
  745. rd->rx_ctl.rx_control_0, rd->rx_ctl.rx_control_1,
  746. rd->u.rx_stat.rx_status_0, rd->u.rx_stat.rx_status_0,
  747. !done ? ' ' : (rs->rs_status == 0) ? '*' : '!');
  748. }
  749. void
  750. ath5k_debug_printrxbuffs(struct ath5k_softc *sc, struct ath5k_hw *ah)
  751. {
  752. struct ath5k_desc *ds;
  753. struct ath5k_buf *bf;
  754. struct ath5k_rx_status rs = {};
  755. int status;
  756. if (likely(!(sc->debug.level & ATH5K_DEBUG_RESET)))
  757. return;
  758. printk(KERN_DEBUG "rx queue %x, link %p\n",
  759. ath5k_hw_get_rxdp(ah), sc->rxlink);
  760. spin_lock_bh(&sc->rxbuflock);
  761. list_for_each_entry(bf, &sc->rxbuf, list) {
  762. ds = bf->desc;
  763. status = ah->ah_proc_rx_desc(ah, ds, &rs);
  764. if (!status)
  765. ath5k_debug_printrxbuf(bf, status == 0, &rs);
  766. }
  767. spin_unlock_bh(&sc->rxbuflock);
  768. }
  769. void
  770. ath5k_debug_dump_skb(struct ath5k_softc *sc,
  771. struct sk_buff *skb, const char *prefix, int tx)
  772. {
  773. char buf[16];
  774. if (likely(!((tx && (sc->debug.level & ATH5K_DEBUG_DUMP_TX)) ||
  775. (!tx && (sc->debug.level & ATH5K_DEBUG_DUMP_RX)))))
  776. return;
  777. snprintf(buf, sizeof(buf), "%s %s", wiphy_name(sc->hw->wiphy), prefix);
  778. print_hex_dump_bytes(buf, DUMP_PREFIX_NONE, skb->data,
  779. min(200U, skb->len));
  780. printk(KERN_DEBUG "\n");
  781. }
  782. void
  783. ath5k_debug_printtxbuf(struct ath5k_softc *sc, struct ath5k_buf *bf)
  784. {
  785. struct ath5k_desc *ds = bf->desc;
  786. struct ath5k_hw_5212_tx_desc *td = &ds->ud.ds_tx5212;
  787. struct ath5k_tx_status ts = {};
  788. int done;
  789. if (likely(!(sc->debug.level & ATH5K_DEBUG_RESET)))
  790. return;
  791. done = sc->ah->ah_proc_tx_desc(sc->ah, bf->desc, &ts);
  792. printk(KERN_DEBUG "T (%p %llx) %08x %08x %08x %08x %08x %08x %08x "
  793. "%08x %c\n", ds, (unsigned long long)bf->daddr, ds->ds_link,
  794. ds->ds_data, td->tx_ctl.tx_control_0, td->tx_ctl.tx_control_1,
  795. td->tx_ctl.tx_control_2, td->tx_ctl.tx_control_3,
  796. td->tx_stat.tx_status_0, td->tx_stat.tx_status_1,
  797. done ? ' ' : (ts.ts_status == 0) ? '*' : '!');
  798. }
  799. #endif /* ifdef CONFIG_ATH5K_DEBUG */