debug.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469
  1. /*
  2. * Copyright (c) 2007 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 "debug.h"
  61. #include "base.h"
  62. static unsigned int ath5k_debug;
  63. module_param_named(debug, ath5k_debug, uint, 0);
  64. #if ATH5K_DEBUG
  65. #include <linux/seq_file.h>
  66. #include "reg.h"
  67. static struct dentry *ath5k_global_debugfs;
  68. static int ath5k_debugfs_open(struct inode *inode, struct file *file)
  69. {
  70. file->private_data = inode->i_private;
  71. return 0;
  72. }
  73. /* debugfs: registers */
  74. struct reg {
  75. char *name;
  76. int addr;
  77. };
  78. #define REG_STRUCT_INIT(r) { #r, r }
  79. /* just a few random registers, might want to add more */
  80. static struct reg regs[] = {
  81. REG_STRUCT_INIT(AR5K_CR),
  82. REG_STRUCT_INIT(AR5K_RXDP),
  83. REG_STRUCT_INIT(AR5K_CFG),
  84. REG_STRUCT_INIT(AR5K_IER),
  85. REG_STRUCT_INIT(AR5K_BCR),
  86. REG_STRUCT_INIT(AR5K_RTSD0),
  87. REG_STRUCT_INIT(AR5K_RTSD1),
  88. REG_STRUCT_INIT(AR5K_TXCFG),
  89. REG_STRUCT_INIT(AR5K_RXCFG),
  90. REG_STRUCT_INIT(AR5K_RXJLA),
  91. REG_STRUCT_INIT(AR5K_MIBC),
  92. REG_STRUCT_INIT(AR5K_TOPS),
  93. REG_STRUCT_INIT(AR5K_RXNOFRM),
  94. REG_STRUCT_INIT(AR5K_TXNOFRM),
  95. REG_STRUCT_INIT(AR5K_RPGTO),
  96. REG_STRUCT_INIT(AR5K_RFCNT),
  97. REG_STRUCT_INIT(AR5K_MISC),
  98. REG_STRUCT_INIT(AR5K_QCUDCU_CLKGT),
  99. REG_STRUCT_INIT(AR5K_ISR),
  100. REG_STRUCT_INIT(AR5K_PISR),
  101. REG_STRUCT_INIT(AR5K_SISR0),
  102. REG_STRUCT_INIT(AR5K_SISR1),
  103. REG_STRUCT_INIT(AR5K_SISR2),
  104. REG_STRUCT_INIT(AR5K_SISR3),
  105. REG_STRUCT_INIT(AR5K_SISR4),
  106. REG_STRUCT_INIT(AR5K_IMR),
  107. REG_STRUCT_INIT(AR5K_PIMR),
  108. REG_STRUCT_INIT(AR5K_SIMR0),
  109. REG_STRUCT_INIT(AR5K_SIMR1),
  110. REG_STRUCT_INIT(AR5K_SIMR2),
  111. REG_STRUCT_INIT(AR5K_SIMR3),
  112. REG_STRUCT_INIT(AR5K_SIMR4),
  113. REG_STRUCT_INIT(AR5K_DCM_ADDR),
  114. REG_STRUCT_INIT(AR5K_DCCFG),
  115. REG_STRUCT_INIT(AR5K_CCFG),
  116. REG_STRUCT_INIT(AR5K_CPC0),
  117. REG_STRUCT_INIT(AR5K_CPC1),
  118. REG_STRUCT_INIT(AR5K_CPC2),
  119. REG_STRUCT_INIT(AR5K_CPC3),
  120. REG_STRUCT_INIT(AR5K_CPCORN),
  121. REG_STRUCT_INIT(AR5K_RESET_CTL),
  122. REG_STRUCT_INIT(AR5K_SLEEP_CTL),
  123. REG_STRUCT_INIT(AR5K_INTPEND),
  124. REG_STRUCT_INIT(AR5K_SFR),
  125. REG_STRUCT_INIT(AR5K_PCICFG),
  126. REG_STRUCT_INIT(AR5K_GPIOCR),
  127. REG_STRUCT_INIT(AR5K_GPIODO),
  128. REG_STRUCT_INIT(AR5K_SREV),
  129. };
  130. static void *reg_start(struct seq_file *seq, loff_t *pos)
  131. {
  132. return *pos < ARRAY_SIZE(regs) ? &regs[*pos] : NULL;
  133. }
  134. static void reg_stop(struct seq_file *seq, void *p)
  135. {
  136. /* nothing to do */
  137. }
  138. static void *reg_next(struct seq_file *seq, void *p, loff_t *pos)
  139. {
  140. ++*pos;
  141. return *pos < ARRAY_SIZE(regs) ? &regs[*pos] : NULL;
  142. }
  143. static int reg_show(struct seq_file *seq, void *p)
  144. {
  145. struct ath5k_softc *sc = seq->private;
  146. struct reg *r = p;
  147. seq_printf(seq, "%-25s0x%08x\n", r->name,
  148. ath5k_hw_reg_read(sc->ah, r->addr));
  149. return 0;
  150. }
  151. static struct seq_operations register_seq_ops = {
  152. .start = reg_start,
  153. .next = reg_next,
  154. .stop = reg_stop,
  155. .show = reg_show
  156. };
  157. static int open_file_registers(struct inode *inode, struct file *file)
  158. {
  159. struct seq_file *s;
  160. int res;
  161. res = seq_open(file, &register_seq_ops);
  162. if (res == 0) {
  163. s = file->private_data;
  164. s->private = inode->i_private;
  165. }
  166. return res;
  167. }
  168. static const struct file_operations fops_registers = {
  169. .open = open_file_registers,
  170. .read = seq_read,
  171. .llseek = seq_lseek,
  172. .release = seq_release,
  173. .owner = THIS_MODULE,
  174. };
  175. /* debugfs: TSF */
  176. static ssize_t read_file_tsf(struct file *file, char __user *user_buf,
  177. size_t count, loff_t *ppos)
  178. {
  179. struct ath5k_softc *sc = file->private_data;
  180. char buf[100];
  181. snprintf(buf, 100, "0x%016llx\n", ath5k_hw_get_tsf64(sc->ah));
  182. return simple_read_from_buffer(user_buf, count, ppos, buf, 19);
  183. }
  184. static ssize_t write_file_tsf(struct file *file,
  185. const char __user *userbuf,
  186. size_t count, loff_t *ppos)
  187. {
  188. struct ath5k_softc *sc = file->private_data;
  189. if (strncmp(userbuf, "reset", 5) == 0) {
  190. ath5k_hw_reset_tsf(sc->ah);
  191. printk(KERN_INFO "debugfs reset TSF\n");
  192. }
  193. return count;
  194. }
  195. static const struct file_operations fops_tsf = {
  196. .read = read_file_tsf,
  197. .write = write_file_tsf,
  198. .open = ath5k_debugfs_open,
  199. .owner = THIS_MODULE,
  200. };
  201. /* debugfs: beacons */
  202. static ssize_t read_file_beacon(struct file *file, char __user *user_buf,
  203. size_t count, loff_t *ppos)
  204. {
  205. struct ath5k_softc *sc = file->private_data;
  206. struct ath5k_hw *ah = sc->ah;
  207. char buf[1000];
  208. int len = 0;
  209. unsigned int v;
  210. u64 tsf;
  211. v = ath5k_hw_reg_read(sc->ah, AR5K_BEACON);
  212. len += snprintf(buf+len, sizeof(buf)-len,
  213. "%-24s0x%08x\tintval: %d\tTIM: 0x%x\n",
  214. "AR5K_BEACON", v, v & AR5K_BEACON_PERIOD,
  215. (v & AR5K_BEACON_TIM) >> AR5K_BEACON_TIM_S);
  216. len += snprintf(buf+len, sizeof(buf)-len, "%-24s0x%08x\n",
  217. "AR5K_LAST_TSTP", ath5k_hw_reg_read(sc->ah, AR5K_LAST_TSTP));
  218. len += snprintf(buf+len, sizeof(buf)-len, "%-24s0x%08x\n\n",
  219. "AR5K_BEACON_CNT", ath5k_hw_reg_read(sc->ah, AR5K_BEACON_CNT));
  220. v = ath5k_hw_reg_read(sc->ah, AR5K_TIMER0);
  221. len += snprintf(buf+len, sizeof(buf)-len, "%-24s0x%08x\tTU: %08x\n",
  222. "AR5K_TIMER0 (TBTT)", v, v);
  223. v = ath5k_hw_reg_read(sc->ah, AR5K_TIMER1);
  224. len += snprintf(buf+len, sizeof(buf)-len, "%-24s0x%08x\tTU: %08x\n",
  225. "AR5K_TIMER1 (DMA)", v, v >> 3);
  226. v = ath5k_hw_reg_read(sc->ah, AR5K_TIMER2);
  227. len += snprintf(buf+len, sizeof(buf)-len, "%-24s0x%08x\tTU: %08x\n",
  228. "AR5K_TIMER2 (SWBA)", v, v >> 3);
  229. v = ath5k_hw_reg_read(sc->ah, AR5K_TIMER3);
  230. len += snprintf(buf+len, sizeof(buf)-len, "%-24s0x%08x\tTU: %08x\n",
  231. "AR5K_TIMER3 (ATIM)", v, v);
  232. tsf = ath5k_hw_get_tsf64(sc->ah);
  233. len += snprintf(buf+len, sizeof(buf)-len,
  234. "TSF\t\t0x%016llx\tTU: %08x\n", tsf, TSF_TO_TU(tsf));
  235. return simple_read_from_buffer(user_buf, count, ppos, buf, len);
  236. }
  237. static ssize_t write_file_beacon(struct file *file,
  238. const char __user *userbuf,
  239. size_t count, loff_t *ppos)
  240. {
  241. struct ath5k_softc *sc = file->private_data;
  242. struct ath5k_hw *ah = sc->ah;
  243. if (strncmp(userbuf, "disable", 7) == 0) {
  244. AR5K_REG_DISABLE_BITS(ah, AR5K_BEACON, AR5K_BEACON_ENABLE);
  245. printk(KERN_INFO "debugfs disable beacons\n");
  246. } else if (strncmp(userbuf, "enable", 6) == 0) {
  247. AR5K_REG_ENABLE_BITS(ah, AR5K_BEACON, AR5K_BEACON_ENABLE);
  248. printk(KERN_INFO "debugfs enable beacons\n");
  249. }
  250. return count;
  251. }
  252. static const struct file_operations fops_beacon = {
  253. .read = read_file_beacon,
  254. .write = write_file_beacon,
  255. .open = ath5k_debugfs_open,
  256. .owner = THIS_MODULE,
  257. };
  258. /* debugfs: reset */
  259. static ssize_t write_file_reset(struct file *file,
  260. const char __user *userbuf,
  261. size_t count, loff_t *ppos)
  262. {
  263. struct ath5k_softc *sc = file->private_data;
  264. tasklet_schedule(&sc->restq);
  265. return count;
  266. }
  267. static const struct file_operations fops_reset = {
  268. .write = write_file_reset,
  269. .open = ath5k_debugfs_open,
  270. .owner = THIS_MODULE,
  271. };
  272. /* init */
  273. void
  274. ath5k_debug_init(void)
  275. {
  276. ath5k_global_debugfs = debugfs_create_dir("ath5k", NULL);
  277. }
  278. void
  279. ath5k_debug_init_device(struct ath5k_softc *sc)
  280. {
  281. sc->debug.level = ath5k_debug;
  282. sc->debug.debugfs_phydir = debugfs_create_dir(wiphy_name(sc->hw->wiphy),
  283. ath5k_global_debugfs);
  284. sc->debug.debugfs_debug = debugfs_create_u32("debug",
  285. 0666, sc->debug.debugfs_phydir, &sc->debug.level);
  286. sc->debug.debugfs_registers = debugfs_create_file("registers", 0444,
  287. sc->debug.debugfs_phydir,
  288. sc, &fops_registers);
  289. sc->debug.debugfs_tsf = debugfs_create_file("tsf", 0666,
  290. sc->debug.debugfs_phydir,
  291. sc, &fops_tsf);
  292. sc->debug.debugfs_beacon = debugfs_create_file("beacon", 0666,
  293. sc->debug.debugfs_phydir,
  294. sc, &fops_beacon);
  295. sc->debug.debugfs_reset = debugfs_create_file("reset", 0222,
  296. sc->debug.debugfs_phydir,
  297. sc, &fops_reset);
  298. }
  299. void
  300. ath5k_debug_finish(void)
  301. {
  302. debugfs_remove(ath5k_global_debugfs);
  303. }
  304. void
  305. ath5k_debug_finish_device(struct ath5k_softc *sc)
  306. {
  307. debugfs_remove(sc->debug.debugfs_debug);
  308. debugfs_remove(sc->debug.debugfs_registers);
  309. debugfs_remove(sc->debug.debugfs_tsf);
  310. debugfs_remove(sc->debug.debugfs_beacon);
  311. debugfs_remove(sc->debug.debugfs_reset);
  312. debugfs_remove(sc->debug.debugfs_phydir);
  313. }
  314. /* functions used in other places */
  315. void
  316. ath5k_debug_dump_modes(struct ath5k_softc *sc, struct ieee80211_hw_mode *modes)
  317. {
  318. unsigned int m, i;
  319. if (likely(!(sc->debug.level & ATH5K_DEBUG_DUMPMODES)))
  320. return;
  321. for (m = 0; m < NUM_DRIVER_MODES; m++) {
  322. printk(KERN_DEBUG "Mode %u: channels %d, rates %d\n", m,
  323. modes[m].num_channels, modes[m].num_rates);
  324. printk(KERN_DEBUG " channels:\n");
  325. for (i = 0; i < modes[m].num_channels; i++)
  326. printk(KERN_DEBUG " %3d %d %.4x %.4x\n",
  327. modes[m].channels[i].chan,
  328. modes[m].channels[i].freq,
  329. modes[m].channels[i].val,
  330. modes[m].channels[i].flag);
  331. printk(KERN_DEBUG " rates:\n");
  332. for (i = 0; i < modes[m].num_rates; i++)
  333. printk(KERN_DEBUG " %4d %.4x %.4x %.4x\n",
  334. modes[m].rates[i].rate,
  335. modes[m].rates[i].val,
  336. modes[m].rates[i].flags,
  337. modes[m].rates[i].val2);
  338. }
  339. }
  340. static inline void
  341. ath5k_debug_printrxbuf(struct ath5k_buf *bf, int done)
  342. {
  343. struct ath5k_desc *ds = bf->desc;
  344. printk(KERN_DEBUG "R (%p %llx) %08x %08x %08x %08x %08x %08x %c\n",
  345. ds, (unsigned long long)bf->daddr,
  346. ds->ds_link, ds->ds_data, ds->ds_ctl0, ds->ds_ctl1,
  347. ds->ds_hw[0], ds->ds_hw[1],
  348. !done ? ' ' : (ds->ds_rxstat.rs_status == 0) ? '*' : '!');
  349. }
  350. void
  351. ath5k_debug_printrxbuffs(struct ath5k_softc *sc, struct ath5k_hw *ah)
  352. {
  353. struct ath5k_desc *ds;
  354. struct ath5k_buf *bf;
  355. int status;
  356. if (likely(!(sc->debug.level &
  357. (ATH5K_DEBUG_RESET | ATH5K_DEBUG_FATAL))))
  358. return;
  359. printk(KERN_DEBUG "rx queue %x, link %p\n",
  360. ath5k_hw_get_rx_buf(ah), sc->rxlink);
  361. spin_lock_bh(&sc->rxbuflock);
  362. list_for_each_entry(bf, &sc->rxbuf, list) {
  363. ds = bf->desc;
  364. status = ah->ah_proc_rx_desc(ah, ds);
  365. if (!status || (sc->debug.level & ATH5K_DEBUG_FATAL))
  366. ath5k_debug_printrxbuf(bf, status == 0);
  367. }
  368. spin_unlock_bh(&sc->rxbuflock);
  369. }
  370. void
  371. ath5k_debug_dump_skb(struct ath5k_softc *sc,
  372. struct sk_buff *skb, const char *prefix, int tx)
  373. {
  374. char buf[16];
  375. if (likely(!((tx && (sc->debug.level & ATH5K_DEBUG_DUMP_TX)) ||
  376. (!tx && (sc->debug.level & ATH5K_DEBUG_DUMP_RX)))))
  377. return;
  378. snprintf(buf, sizeof(buf), "%s %s", wiphy_name(sc->hw->wiphy), prefix);
  379. print_hex_dump_bytes(buf, DUMP_PREFIX_NONE, skb->data,
  380. min(200U, skb->len));
  381. printk(KERN_DEBUG "\n");
  382. }
  383. void
  384. ath5k_debug_printtxbuf(struct ath5k_softc *sc,
  385. struct ath5k_buf *bf, int done)
  386. {
  387. struct ath5k_desc *ds = bf->desc;
  388. if (likely(!(sc->debug.level & ATH5K_DEBUG_RESET)))
  389. return;
  390. printk(KERN_DEBUG "T (%p %llx) %08x %08x %08x %08x %08x %08x %08x "
  391. "%08x %c\n", ds, (unsigned long long)bf->daddr, ds->ds_link,
  392. ds->ds_data, ds->ds_ctl0, ds->ds_ctl1,
  393. ds->ds_hw[0], ds->ds_hw[1], ds->ds_hw[2], ds->ds_hw[3],
  394. !done ? ' ' : (ds->ds_txstat.ts_status == 0) ? '*' : '!');
  395. }
  396. #endif /* if ATH5K_DEBUG */