debug.c 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093
  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. #include "../debug.h"
  63. static unsigned int ath5k_debug;
  64. module_param_named(debug, ath5k_debug, uint, 0);
  65. #ifdef CONFIG_ATH5K_DEBUG
  66. #include <linux/seq_file.h>
  67. #include "reg.h"
  68. #include "ani.h"
  69. static struct dentry *ath5k_global_debugfs;
  70. static int ath5k_debugfs_open(struct inode *inode, struct file *file)
  71. {
  72. file->private_data = inode->i_private;
  73. return 0;
  74. }
  75. /* debugfs: registers */
  76. struct reg {
  77. const char *name;
  78. int addr;
  79. };
  80. #define REG_STRUCT_INIT(r) { #r, r }
  81. /* just a few random registers, might want to add more */
  82. static const struct reg regs[] = {
  83. REG_STRUCT_INIT(AR5K_CR),
  84. REG_STRUCT_INIT(AR5K_RXDP),
  85. REG_STRUCT_INIT(AR5K_CFG),
  86. REG_STRUCT_INIT(AR5K_IER),
  87. REG_STRUCT_INIT(AR5K_BCR),
  88. REG_STRUCT_INIT(AR5K_RTSD0),
  89. REG_STRUCT_INIT(AR5K_RTSD1),
  90. REG_STRUCT_INIT(AR5K_TXCFG),
  91. REG_STRUCT_INIT(AR5K_RXCFG),
  92. REG_STRUCT_INIT(AR5K_RXJLA),
  93. REG_STRUCT_INIT(AR5K_MIBC),
  94. REG_STRUCT_INIT(AR5K_TOPS),
  95. REG_STRUCT_INIT(AR5K_RXNOFRM),
  96. REG_STRUCT_INIT(AR5K_TXNOFRM),
  97. REG_STRUCT_INIT(AR5K_RPGTO),
  98. REG_STRUCT_INIT(AR5K_RFCNT),
  99. REG_STRUCT_INIT(AR5K_MISC),
  100. REG_STRUCT_INIT(AR5K_QCUDCU_CLKGT),
  101. REG_STRUCT_INIT(AR5K_ISR),
  102. REG_STRUCT_INIT(AR5K_PISR),
  103. REG_STRUCT_INIT(AR5K_SISR0),
  104. REG_STRUCT_INIT(AR5K_SISR1),
  105. REG_STRUCT_INIT(AR5K_SISR2),
  106. REG_STRUCT_INIT(AR5K_SISR3),
  107. REG_STRUCT_INIT(AR5K_SISR4),
  108. REG_STRUCT_INIT(AR5K_IMR),
  109. REG_STRUCT_INIT(AR5K_PIMR),
  110. REG_STRUCT_INIT(AR5K_SIMR0),
  111. REG_STRUCT_INIT(AR5K_SIMR1),
  112. REG_STRUCT_INIT(AR5K_SIMR2),
  113. REG_STRUCT_INIT(AR5K_SIMR3),
  114. REG_STRUCT_INIT(AR5K_SIMR4),
  115. REG_STRUCT_INIT(AR5K_DCM_ADDR),
  116. REG_STRUCT_INIT(AR5K_DCCFG),
  117. REG_STRUCT_INIT(AR5K_CCFG),
  118. REG_STRUCT_INIT(AR5K_CPC0),
  119. REG_STRUCT_INIT(AR5K_CPC1),
  120. REG_STRUCT_INIT(AR5K_CPC2),
  121. REG_STRUCT_INIT(AR5K_CPC3),
  122. REG_STRUCT_INIT(AR5K_CPCOVF),
  123. REG_STRUCT_INIT(AR5K_RESET_CTL),
  124. REG_STRUCT_INIT(AR5K_SLEEP_CTL),
  125. REG_STRUCT_INIT(AR5K_INTPEND),
  126. REG_STRUCT_INIT(AR5K_SFR),
  127. REG_STRUCT_INIT(AR5K_PCICFG),
  128. REG_STRUCT_INIT(AR5K_GPIOCR),
  129. REG_STRUCT_INIT(AR5K_GPIODO),
  130. REG_STRUCT_INIT(AR5K_SREV),
  131. };
  132. static void *reg_start(struct seq_file *seq, loff_t *pos)
  133. {
  134. return *pos < ARRAY_SIZE(regs) ? (void *)&regs[*pos] : NULL;
  135. }
  136. static void reg_stop(struct seq_file *seq, void *p)
  137. {
  138. /* nothing to do */
  139. }
  140. static void *reg_next(struct seq_file *seq, void *p, loff_t *pos)
  141. {
  142. ++*pos;
  143. return *pos < ARRAY_SIZE(regs) ? (void *)&regs[*pos] : NULL;
  144. }
  145. static int reg_show(struct seq_file *seq, void *p)
  146. {
  147. struct ath5k_softc *sc = seq->private;
  148. struct reg *r = p;
  149. seq_printf(seq, "%-25s0x%08x\n", r->name,
  150. ath5k_hw_reg_read(sc->ah, r->addr));
  151. return 0;
  152. }
  153. static const struct seq_operations register_seq_ops = {
  154. .start = reg_start,
  155. .next = reg_next,
  156. .stop = reg_stop,
  157. .show = reg_show
  158. };
  159. static int open_file_registers(struct inode *inode, struct file *file)
  160. {
  161. struct seq_file *s;
  162. int res;
  163. res = seq_open(file, &register_seq_ops);
  164. if (res == 0) {
  165. s = file->private_data;
  166. s->private = inode->i_private;
  167. }
  168. return res;
  169. }
  170. static const struct file_operations fops_registers = {
  171. .open = open_file_registers,
  172. .read = seq_read,
  173. .llseek = seq_lseek,
  174. .release = seq_release,
  175. .owner = THIS_MODULE,
  176. };
  177. /* debugfs: beacons */
  178. static ssize_t read_file_beacon(struct file *file, char __user *user_buf,
  179. size_t count, loff_t *ppos)
  180. {
  181. struct ath5k_softc *sc = file->private_data;
  182. struct ath5k_hw *ah = sc->ah;
  183. char buf[500];
  184. unsigned int len = 0;
  185. unsigned int v;
  186. u64 tsf;
  187. v = ath5k_hw_reg_read(sc->ah, AR5K_BEACON);
  188. len += snprintf(buf+len, sizeof(buf)-len,
  189. "%-24s0x%08x\tintval: %d\tTIM: 0x%x\n",
  190. "AR5K_BEACON", v, v & AR5K_BEACON_PERIOD,
  191. (v & AR5K_BEACON_TIM) >> AR5K_BEACON_TIM_S);
  192. len += snprintf(buf+len, sizeof(buf)-len, "%-24s0x%08x\n",
  193. "AR5K_LAST_TSTP", ath5k_hw_reg_read(sc->ah, AR5K_LAST_TSTP));
  194. len += snprintf(buf+len, sizeof(buf)-len, "%-24s0x%08x\n\n",
  195. "AR5K_BEACON_CNT", ath5k_hw_reg_read(sc->ah, AR5K_BEACON_CNT));
  196. v = ath5k_hw_reg_read(sc->ah, AR5K_TIMER0);
  197. len += snprintf(buf+len, sizeof(buf)-len, "%-24s0x%08x\tTU: %08x\n",
  198. "AR5K_TIMER0 (TBTT)", v, v);
  199. v = ath5k_hw_reg_read(sc->ah, AR5K_TIMER1);
  200. len += snprintf(buf+len, sizeof(buf)-len, "%-24s0x%08x\tTU: %08x\n",
  201. "AR5K_TIMER1 (DMA)", v, v >> 3);
  202. v = ath5k_hw_reg_read(sc->ah, AR5K_TIMER2);
  203. len += snprintf(buf+len, sizeof(buf)-len, "%-24s0x%08x\tTU: %08x\n",
  204. "AR5K_TIMER2 (SWBA)", v, v >> 3);
  205. v = ath5k_hw_reg_read(sc->ah, AR5K_TIMER3);
  206. len += snprintf(buf+len, sizeof(buf)-len, "%-24s0x%08x\tTU: %08x\n",
  207. "AR5K_TIMER3 (ATIM)", v, v);
  208. tsf = ath5k_hw_get_tsf64(sc->ah);
  209. len += snprintf(buf+len, sizeof(buf)-len,
  210. "TSF\t\t0x%016llx\tTU: %08x\n",
  211. (unsigned long long)tsf, TSF_TO_TU(tsf));
  212. if (len > sizeof(buf))
  213. len = sizeof(buf);
  214. return simple_read_from_buffer(user_buf, count, ppos, buf, len);
  215. }
  216. static ssize_t write_file_beacon(struct file *file,
  217. const char __user *userbuf,
  218. size_t count, loff_t *ppos)
  219. {
  220. struct ath5k_softc *sc = file->private_data;
  221. struct ath5k_hw *ah = sc->ah;
  222. char buf[20];
  223. if (copy_from_user(buf, userbuf, min(count, sizeof(buf))))
  224. return -EFAULT;
  225. if (strncmp(buf, "disable", 7) == 0) {
  226. AR5K_REG_DISABLE_BITS(ah, AR5K_BEACON, AR5K_BEACON_ENABLE);
  227. printk(KERN_INFO "debugfs disable beacons\n");
  228. } else if (strncmp(buf, "enable", 6) == 0) {
  229. AR5K_REG_ENABLE_BITS(ah, AR5K_BEACON, AR5K_BEACON_ENABLE);
  230. printk(KERN_INFO "debugfs enable beacons\n");
  231. }
  232. return count;
  233. }
  234. static const struct file_operations fops_beacon = {
  235. .read = read_file_beacon,
  236. .write = write_file_beacon,
  237. .open = ath5k_debugfs_open,
  238. .owner = THIS_MODULE,
  239. };
  240. /* debugfs: reset */
  241. static ssize_t write_file_reset(struct file *file,
  242. const char __user *userbuf,
  243. size_t count, loff_t *ppos)
  244. {
  245. struct ath5k_softc *sc = file->private_data;
  246. ATH5K_DBG(sc, ATH5K_DEBUG_RESET, "debug file triggered reset\n");
  247. ieee80211_queue_work(sc->hw, &sc->reset_work);
  248. return count;
  249. }
  250. static const struct file_operations fops_reset = {
  251. .write = write_file_reset,
  252. .open = ath5k_debugfs_open,
  253. .owner = THIS_MODULE,
  254. };
  255. /* debugfs: debug level */
  256. static const struct {
  257. enum ath5k_debug_level level;
  258. const char *name;
  259. const char *desc;
  260. } dbg_info[] = {
  261. { ATH5K_DEBUG_RESET, "reset", "reset and initialization" },
  262. { ATH5K_DEBUG_INTR, "intr", "interrupt handling" },
  263. { ATH5K_DEBUG_MODE, "mode", "mode init/setup" },
  264. { ATH5K_DEBUG_XMIT, "xmit", "basic xmit operation" },
  265. { ATH5K_DEBUG_BEACON, "beacon", "beacon handling" },
  266. { ATH5K_DEBUG_CALIBRATE, "calib", "periodic calibration" },
  267. { ATH5K_DEBUG_TXPOWER, "txpower", "transmit power setting" },
  268. { ATH5K_DEBUG_LED, "led", "LED management" },
  269. { ATH5K_DEBUG_DUMP_RX, "dumprx", "print received skb content" },
  270. { ATH5K_DEBUG_DUMP_TX, "dumptx", "print transmit skb content" },
  271. { ATH5K_DEBUG_DUMPBANDS, "dumpbands", "dump bands" },
  272. { ATH5K_DEBUG_ANI, "ani", "adaptive noise immunity" },
  273. { ATH5K_DEBUG_DESC, "desc", "descriptor chains" },
  274. { ATH5K_DEBUG_ANY, "all", "show all debug levels" },
  275. };
  276. static ssize_t read_file_debug(struct file *file, char __user *user_buf,
  277. size_t count, loff_t *ppos)
  278. {
  279. struct ath5k_softc *sc = file->private_data;
  280. char buf[700];
  281. unsigned int len = 0;
  282. unsigned int i;
  283. len += snprintf(buf+len, sizeof(buf)-len,
  284. "DEBUG LEVEL: 0x%08x\n\n", sc->debug.level);
  285. for (i = 0; i < ARRAY_SIZE(dbg_info) - 1; i++) {
  286. len += snprintf(buf+len, sizeof(buf)-len,
  287. "%10s %c 0x%08x - %s\n", dbg_info[i].name,
  288. sc->debug.level & dbg_info[i].level ? '+' : ' ',
  289. dbg_info[i].level, dbg_info[i].desc);
  290. }
  291. len += snprintf(buf+len, sizeof(buf)-len,
  292. "%10s %c 0x%08x - %s\n", dbg_info[i].name,
  293. sc->debug.level == dbg_info[i].level ? '+' : ' ',
  294. dbg_info[i].level, dbg_info[i].desc);
  295. if (len > sizeof(buf))
  296. len = sizeof(buf);
  297. return simple_read_from_buffer(user_buf, count, ppos, buf, len);
  298. }
  299. static ssize_t write_file_debug(struct file *file,
  300. const char __user *userbuf,
  301. size_t count, loff_t *ppos)
  302. {
  303. struct ath5k_softc *sc = file->private_data;
  304. unsigned int i;
  305. char buf[20];
  306. if (copy_from_user(buf, userbuf, min(count, sizeof(buf))))
  307. return -EFAULT;
  308. for (i = 0; i < ARRAY_SIZE(dbg_info); i++) {
  309. if (strncmp(buf, dbg_info[i].name,
  310. strlen(dbg_info[i].name)) == 0) {
  311. sc->debug.level ^= dbg_info[i].level; /* toggle bit */
  312. break;
  313. }
  314. }
  315. return count;
  316. }
  317. static const struct file_operations fops_debug = {
  318. .read = read_file_debug,
  319. .write = write_file_debug,
  320. .open = ath5k_debugfs_open,
  321. .owner = THIS_MODULE,
  322. };
  323. /* debugfs: antenna */
  324. static ssize_t read_file_antenna(struct file *file, char __user *user_buf,
  325. size_t count, loff_t *ppos)
  326. {
  327. struct ath5k_softc *sc = file->private_data;
  328. char buf[700];
  329. unsigned int len = 0;
  330. unsigned int i;
  331. unsigned int v;
  332. len += snprintf(buf+len, sizeof(buf)-len, "antenna mode\t%d\n",
  333. sc->ah->ah_ant_mode);
  334. len += snprintf(buf+len, sizeof(buf)-len, "default antenna\t%d\n",
  335. sc->ah->ah_def_ant);
  336. len += snprintf(buf+len, sizeof(buf)-len, "tx antenna\t%d\n",
  337. sc->ah->ah_tx_ant);
  338. len += snprintf(buf+len, sizeof(buf)-len, "\nANTENNA\t\tRX\tTX\n");
  339. for (i = 1; i < ARRAY_SIZE(sc->stats.antenna_rx); i++) {
  340. len += snprintf(buf+len, sizeof(buf)-len,
  341. "[antenna %d]\t%d\t%d\n",
  342. i, sc->stats.antenna_rx[i], sc->stats.antenna_tx[i]);
  343. }
  344. len += snprintf(buf+len, sizeof(buf)-len, "[invalid]\t%d\t%d\n",
  345. sc->stats.antenna_rx[0], sc->stats.antenna_tx[0]);
  346. v = ath5k_hw_reg_read(sc->ah, AR5K_DEFAULT_ANTENNA);
  347. len += snprintf(buf+len, sizeof(buf)-len,
  348. "\nAR5K_DEFAULT_ANTENNA\t0x%08x\n", v);
  349. v = ath5k_hw_reg_read(sc->ah, AR5K_STA_ID1);
  350. len += snprintf(buf+len, sizeof(buf)-len,
  351. "AR5K_STA_ID1_DEFAULT_ANTENNA\t%d\n",
  352. (v & AR5K_STA_ID1_DEFAULT_ANTENNA) != 0);
  353. len += snprintf(buf+len, sizeof(buf)-len,
  354. "AR5K_STA_ID1_DESC_ANTENNA\t%d\n",
  355. (v & AR5K_STA_ID1_DESC_ANTENNA) != 0);
  356. len += snprintf(buf+len, sizeof(buf)-len,
  357. "AR5K_STA_ID1_RTS_DEF_ANTENNA\t%d\n",
  358. (v & AR5K_STA_ID1_RTS_DEF_ANTENNA) != 0);
  359. len += snprintf(buf+len, sizeof(buf)-len,
  360. "AR5K_STA_ID1_SELFGEN_DEF_ANT\t%d\n",
  361. (v & AR5K_STA_ID1_SELFGEN_DEF_ANT) != 0);
  362. v = ath5k_hw_reg_read(sc->ah, AR5K_PHY_AGCCTL);
  363. len += snprintf(buf+len, sizeof(buf)-len,
  364. "\nAR5K_PHY_AGCCTL_OFDM_DIV_DIS\t%d\n",
  365. (v & AR5K_PHY_AGCCTL_OFDM_DIV_DIS) != 0);
  366. v = ath5k_hw_reg_read(sc->ah, AR5K_PHY_RESTART);
  367. len += snprintf(buf+len, sizeof(buf)-len,
  368. "AR5K_PHY_RESTART_DIV_GC\t\t%x\n",
  369. (v & AR5K_PHY_RESTART_DIV_GC) >> AR5K_PHY_RESTART_DIV_GC_S);
  370. v = ath5k_hw_reg_read(sc->ah, AR5K_PHY_FAST_ANT_DIV);
  371. len += snprintf(buf+len, sizeof(buf)-len,
  372. "AR5K_PHY_FAST_ANT_DIV_EN\t%d\n",
  373. (v & AR5K_PHY_FAST_ANT_DIV_EN) != 0);
  374. v = ath5k_hw_reg_read(sc->ah, AR5K_PHY_ANT_SWITCH_TABLE_0);
  375. len += snprintf(buf+len, sizeof(buf)-len,
  376. "\nAR5K_PHY_ANT_SWITCH_TABLE_0\t0x%08x\n", v);
  377. v = ath5k_hw_reg_read(sc->ah, AR5K_PHY_ANT_SWITCH_TABLE_1);
  378. len += snprintf(buf+len, sizeof(buf)-len,
  379. "AR5K_PHY_ANT_SWITCH_TABLE_1\t0x%08x\n", v);
  380. if (len > sizeof(buf))
  381. len = sizeof(buf);
  382. return simple_read_from_buffer(user_buf, count, ppos, buf, len);
  383. }
  384. static ssize_t write_file_antenna(struct file *file,
  385. const char __user *userbuf,
  386. size_t count, loff_t *ppos)
  387. {
  388. struct ath5k_softc *sc = file->private_data;
  389. unsigned int i;
  390. char buf[20];
  391. if (copy_from_user(buf, userbuf, min(count, sizeof(buf))))
  392. return -EFAULT;
  393. if (strncmp(buf, "diversity", 9) == 0) {
  394. ath5k_hw_set_antenna_mode(sc->ah, AR5K_ANTMODE_DEFAULT);
  395. printk(KERN_INFO "ath5k debug: enable diversity\n");
  396. } else if (strncmp(buf, "fixed-a", 7) == 0) {
  397. ath5k_hw_set_antenna_mode(sc->ah, AR5K_ANTMODE_FIXED_A);
  398. printk(KERN_INFO "ath5k debugfs: fixed antenna A\n");
  399. } else if (strncmp(buf, "fixed-b", 7) == 0) {
  400. ath5k_hw_set_antenna_mode(sc->ah, AR5K_ANTMODE_FIXED_B);
  401. printk(KERN_INFO "ath5k debug: fixed antenna B\n");
  402. } else if (strncmp(buf, "clear", 5) == 0) {
  403. for (i = 0; i < ARRAY_SIZE(sc->stats.antenna_rx); i++) {
  404. sc->stats.antenna_rx[i] = 0;
  405. sc->stats.antenna_tx[i] = 0;
  406. }
  407. printk(KERN_INFO "ath5k debug: cleared antenna stats\n");
  408. }
  409. return count;
  410. }
  411. static const struct file_operations fops_antenna = {
  412. .read = read_file_antenna,
  413. .write = write_file_antenna,
  414. .open = ath5k_debugfs_open,
  415. .owner = THIS_MODULE,
  416. };
  417. /* debugfs: misc */
  418. static ssize_t read_file_misc(struct file *file, char __user *user_buf,
  419. size_t count, loff_t *ppos)
  420. {
  421. struct ath5k_softc *sc = file->private_data;
  422. char buf[700];
  423. unsigned int len = 0;
  424. u32 filt = ath5k_hw_get_rx_filter(sc->ah);
  425. const char *tmp;
  426. len += snprintf(buf+len, sizeof(buf)-len, "bssid-mask: %pM\n",
  427. sc->bssidmask);
  428. len += snprintf(buf+len, sizeof(buf)-len, "filter-flags: 0x%x ",
  429. filt);
  430. if (filt & AR5K_RX_FILTER_UCAST)
  431. len += snprintf(buf+len, sizeof(buf)-len, " UCAST");
  432. if (filt & AR5K_RX_FILTER_MCAST)
  433. len += snprintf(buf+len, sizeof(buf)-len, " MCAST");
  434. if (filt & AR5K_RX_FILTER_BCAST)
  435. len += snprintf(buf+len, sizeof(buf)-len, " BCAST");
  436. if (filt & AR5K_RX_FILTER_CONTROL)
  437. len += snprintf(buf+len, sizeof(buf)-len, " CONTROL");
  438. if (filt & AR5K_RX_FILTER_BEACON)
  439. len += snprintf(buf+len, sizeof(buf)-len, " BEACON");
  440. if (filt & AR5K_RX_FILTER_PROM)
  441. len += snprintf(buf+len, sizeof(buf)-len, " PROM");
  442. if (filt & AR5K_RX_FILTER_XRPOLL)
  443. len += snprintf(buf+len, sizeof(buf)-len, " XRPOLL");
  444. if (filt & AR5K_RX_FILTER_PROBEREQ)
  445. len += snprintf(buf+len, sizeof(buf)-len, " PROBEREQ");
  446. if (filt & AR5K_RX_FILTER_PHYERR_5212)
  447. len += snprintf(buf+len, sizeof(buf)-len, " PHYERR-5212");
  448. if (filt & AR5K_RX_FILTER_RADARERR_5212)
  449. len += snprintf(buf+len, sizeof(buf)-len, " RADARERR-5212");
  450. if (filt & AR5K_RX_FILTER_PHYERR_5211)
  451. snprintf(buf+len, sizeof(buf)-len, " PHYERR-5211");
  452. if (filt & AR5K_RX_FILTER_RADARERR_5211)
  453. len += snprintf(buf+len, sizeof(buf)-len, " RADARERR-5211\n");
  454. else
  455. len += snprintf(buf+len, sizeof(buf)-len, "\n");
  456. tmp = ath_opmode_to_string(sc->opmode);
  457. if (tmp)
  458. len += snprintf(buf+len, sizeof(buf)-len, "opmode: %s\n",
  459. tmp);
  460. else
  461. len += snprintf(buf+len, sizeof(buf)-len,
  462. "opmode: UNKNOWN-%i\n", sc->opmode);
  463. if (len > sizeof(buf))
  464. len = sizeof(buf);
  465. return simple_read_from_buffer(user_buf, count, ppos, buf, len);
  466. }
  467. static const struct file_operations fops_misc = {
  468. .read = read_file_misc,
  469. .open = ath5k_debugfs_open,
  470. .owner = THIS_MODULE,
  471. };
  472. /* debugfs: frameerrors */
  473. static ssize_t read_file_frameerrors(struct file *file, char __user *user_buf,
  474. size_t count, loff_t *ppos)
  475. {
  476. struct ath5k_softc *sc = file->private_data;
  477. struct ath5k_statistics *st = &sc->stats;
  478. char buf[700];
  479. unsigned int len = 0;
  480. int i;
  481. len += snprintf(buf+len, sizeof(buf)-len,
  482. "RX\n---------------------\n");
  483. len += snprintf(buf+len, sizeof(buf)-len, "CRC\t%d\t(%d%%)\n",
  484. st->rxerr_crc,
  485. st->rx_all_count > 0 ?
  486. st->rxerr_crc*100/st->rx_all_count : 0);
  487. len += snprintf(buf+len, sizeof(buf)-len, "PHY\t%d\t(%d%%)\n",
  488. st->rxerr_phy,
  489. st->rx_all_count > 0 ?
  490. st->rxerr_phy*100/st->rx_all_count : 0);
  491. for (i = 0; i < 32; i++) {
  492. if (st->rxerr_phy_code[i])
  493. len += snprintf(buf+len, sizeof(buf)-len,
  494. " phy_err[%d]\t%d\n",
  495. i, st->rxerr_phy_code[i]);
  496. }
  497. len += snprintf(buf+len, sizeof(buf)-len, "FIFO\t%d\t(%d%%)\n",
  498. st->rxerr_fifo,
  499. st->rx_all_count > 0 ?
  500. st->rxerr_fifo*100/st->rx_all_count : 0);
  501. len += snprintf(buf+len, sizeof(buf)-len, "decrypt\t%d\t(%d%%)\n",
  502. st->rxerr_decrypt,
  503. st->rx_all_count > 0 ?
  504. st->rxerr_decrypt*100/st->rx_all_count : 0);
  505. len += snprintf(buf+len, sizeof(buf)-len, "MIC\t%d\t(%d%%)\n",
  506. st->rxerr_mic,
  507. st->rx_all_count > 0 ?
  508. st->rxerr_mic*100/st->rx_all_count : 0);
  509. len += snprintf(buf+len, sizeof(buf)-len, "process\t%d\t(%d%%)\n",
  510. st->rxerr_proc,
  511. st->rx_all_count > 0 ?
  512. st->rxerr_proc*100/st->rx_all_count : 0);
  513. len += snprintf(buf+len, sizeof(buf)-len, "jumbo\t%d\t(%d%%)\n",
  514. st->rxerr_jumbo,
  515. st->rx_all_count > 0 ?
  516. st->rxerr_jumbo*100/st->rx_all_count : 0);
  517. len += snprintf(buf+len, sizeof(buf)-len, "[RX all\t%d]\n",
  518. st->rx_all_count);
  519. len += snprintf(buf+len, sizeof(buf)-len, "RX-all-bytes\t%d\n",
  520. st->rx_bytes_count);
  521. len += snprintf(buf+len, sizeof(buf)-len,
  522. "\nTX\n---------------------\n");
  523. len += snprintf(buf+len, sizeof(buf)-len, "retry\t%d\t(%d%%)\n",
  524. st->txerr_retry,
  525. st->tx_all_count > 0 ?
  526. st->txerr_retry*100/st->tx_all_count : 0);
  527. len += snprintf(buf+len, sizeof(buf)-len, "FIFO\t%d\t(%d%%)\n",
  528. st->txerr_fifo,
  529. st->tx_all_count > 0 ?
  530. st->txerr_fifo*100/st->tx_all_count : 0);
  531. len += snprintf(buf+len, sizeof(buf)-len, "filter\t%d\t(%d%%)\n",
  532. st->txerr_filt,
  533. st->tx_all_count > 0 ?
  534. st->txerr_filt*100/st->tx_all_count : 0);
  535. len += snprintf(buf+len, sizeof(buf)-len, "[TX all\t%d]\n",
  536. st->tx_all_count);
  537. len += snprintf(buf+len, sizeof(buf)-len, "TX-all-bytes\t%d\n",
  538. st->tx_bytes_count);
  539. if (len > sizeof(buf))
  540. len = sizeof(buf);
  541. return simple_read_from_buffer(user_buf, count, ppos, buf, len);
  542. }
  543. static ssize_t write_file_frameerrors(struct file *file,
  544. const char __user *userbuf,
  545. size_t count, loff_t *ppos)
  546. {
  547. struct ath5k_softc *sc = file->private_data;
  548. struct ath5k_statistics *st = &sc->stats;
  549. char buf[20];
  550. if (copy_from_user(buf, userbuf, min(count, sizeof(buf))))
  551. return -EFAULT;
  552. if (strncmp(buf, "clear", 5) == 0) {
  553. st->rxerr_crc = 0;
  554. st->rxerr_phy = 0;
  555. st->rxerr_fifo = 0;
  556. st->rxerr_decrypt = 0;
  557. st->rxerr_mic = 0;
  558. st->rxerr_proc = 0;
  559. st->rxerr_jumbo = 0;
  560. st->rx_all_count = 0;
  561. st->txerr_retry = 0;
  562. st->txerr_fifo = 0;
  563. st->txerr_filt = 0;
  564. st->tx_all_count = 0;
  565. printk(KERN_INFO "ath5k debug: cleared frameerrors stats\n");
  566. }
  567. return count;
  568. }
  569. static const struct file_operations fops_frameerrors = {
  570. .read = read_file_frameerrors,
  571. .write = write_file_frameerrors,
  572. .open = ath5k_debugfs_open,
  573. .owner = THIS_MODULE,
  574. };
  575. /* debugfs: ani */
  576. static ssize_t read_file_ani(struct file *file, char __user *user_buf,
  577. size_t count, loff_t *ppos)
  578. {
  579. struct ath5k_softc *sc = file->private_data;
  580. struct ath5k_statistics *st = &sc->stats;
  581. struct ath5k_ani_state *as = &sc->ani_state;
  582. char buf[700];
  583. unsigned int len = 0;
  584. len += snprintf(buf+len, sizeof(buf)-len,
  585. "HW has PHY error counters:\t%s\n",
  586. sc->ah->ah_capabilities.cap_has_phyerr_counters ?
  587. "yes" : "no");
  588. len += snprintf(buf+len, sizeof(buf)-len,
  589. "HW max spur immunity level:\t%d\n",
  590. as->max_spur_level);
  591. len += snprintf(buf+len, sizeof(buf)-len,
  592. "\nANI state\n--------------------------------------------\n");
  593. len += snprintf(buf+len, sizeof(buf)-len, "operating mode:\t\t\t");
  594. switch (as->ani_mode) {
  595. case ATH5K_ANI_MODE_OFF:
  596. len += snprintf(buf+len, sizeof(buf)-len, "OFF\n");
  597. break;
  598. case ATH5K_ANI_MODE_MANUAL_LOW:
  599. len += snprintf(buf+len, sizeof(buf)-len,
  600. "MANUAL LOW\n");
  601. break;
  602. case ATH5K_ANI_MODE_MANUAL_HIGH:
  603. len += snprintf(buf+len, sizeof(buf)-len,
  604. "MANUAL HIGH\n");
  605. break;
  606. case ATH5K_ANI_MODE_AUTO:
  607. len += snprintf(buf+len, sizeof(buf)-len, "AUTO\n");
  608. break;
  609. default:
  610. len += snprintf(buf+len, sizeof(buf)-len,
  611. "??? (not good)\n");
  612. break;
  613. }
  614. len += snprintf(buf+len, sizeof(buf)-len,
  615. "noise immunity level:\t\t%d\n",
  616. as->noise_imm_level);
  617. len += snprintf(buf+len, sizeof(buf)-len,
  618. "spur immunity level:\t\t%d\n",
  619. as->spur_level);
  620. len += snprintf(buf+len, sizeof(buf)-len, "firstep level:\t\t\t%d\n",
  621. as->firstep_level);
  622. len += snprintf(buf+len, sizeof(buf)-len,
  623. "OFDM weak signal detection:\t%s\n",
  624. as->ofdm_weak_sig ? "on" : "off");
  625. len += snprintf(buf+len, sizeof(buf)-len,
  626. "CCK weak signal detection:\t%s\n",
  627. as->cck_weak_sig ? "on" : "off");
  628. len += snprintf(buf+len, sizeof(buf)-len,
  629. "\nMIB INTERRUPTS:\t\t%u\n",
  630. st->mib_intr);
  631. len += snprintf(buf+len, sizeof(buf)-len,
  632. "beacon RSSI average:\t%d\n",
  633. sc->ah->ah_beacon_rssi_avg.avg);
  634. len += snprintf(buf+len, sizeof(buf)-len, "profcnt tx\t\t%u\t(%d%%)\n",
  635. as->pfc_tx,
  636. as->pfc_cycles > 0 ?
  637. as->pfc_tx*100/as->pfc_cycles : 0);
  638. len += snprintf(buf+len, sizeof(buf)-len, "profcnt rx\t\t%u\t(%d%%)\n",
  639. as->pfc_rx,
  640. as->pfc_cycles > 0 ?
  641. as->pfc_rx*100/as->pfc_cycles : 0);
  642. len += snprintf(buf+len, sizeof(buf)-len, "profcnt busy\t\t%u\t(%d%%)\n",
  643. as->pfc_busy,
  644. as->pfc_cycles > 0 ?
  645. as->pfc_busy*100/as->pfc_cycles : 0);
  646. len += snprintf(buf+len, sizeof(buf)-len, "profcnt cycles\t\t%u\n",
  647. as->pfc_cycles);
  648. len += snprintf(buf+len, sizeof(buf)-len,
  649. "listen time\t\t%d\tlast: %d\n",
  650. as->listen_time, as->last_listen);
  651. len += snprintf(buf+len, sizeof(buf)-len,
  652. "OFDM errors\t\t%u\tlast: %u\tsum: %u\n",
  653. as->ofdm_errors, as->last_ofdm_errors,
  654. as->sum_ofdm_errors);
  655. len += snprintf(buf+len, sizeof(buf)-len,
  656. "CCK errors\t\t%u\tlast: %u\tsum: %u\n",
  657. as->cck_errors, as->last_cck_errors,
  658. as->sum_cck_errors);
  659. len += snprintf(buf+len, sizeof(buf)-len,
  660. "AR5K_PHYERR_CNT1\t%x\t(=%d)\n",
  661. ath5k_hw_reg_read(sc->ah, AR5K_PHYERR_CNT1),
  662. ATH5K_ANI_OFDM_TRIG_HIGH - (ATH5K_PHYERR_CNT_MAX -
  663. ath5k_hw_reg_read(sc->ah, AR5K_PHYERR_CNT1)));
  664. len += snprintf(buf+len, sizeof(buf)-len,
  665. "AR5K_PHYERR_CNT2\t%x\t(=%d)\n",
  666. ath5k_hw_reg_read(sc->ah, AR5K_PHYERR_CNT2),
  667. ATH5K_ANI_CCK_TRIG_HIGH - (ATH5K_PHYERR_CNT_MAX -
  668. ath5k_hw_reg_read(sc->ah, AR5K_PHYERR_CNT2)));
  669. if (len > sizeof(buf))
  670. len = sizeof(buf);
  671. return simple_read_from_buffer(user_buf, count, ppos, buf, len);
  672. }
  673. static ssize_t write_file_ani(struct file *file,
  674. const char __user *userbuf,
  675. size_t count, loff_t *ppos)
  676. {
  677. struct ath5k_softc *sc = file->private_data;
  678. char buf[20];
  679. if (copy_from_user(buf, userbuf, min(count, sizeof(buf))))
  680. return -EFAULT;
  681. if (strncmp(buf, "sens-low", 8) == 0) {
  682. ath5k_ani_init(sc->ah, ATH5K_ANI_MODE_MANUAL_HIGH);
  683. } else if (strncmp(buf, "sens-high", 9) == 0) {
  684. ath5k_ani_init(sc->ah, ATH5K_ANI_MODE_MANUAL_LOW);
  685. } else if (strncmp(buf, "ani-off", 7) == 0) {
  686. ath5k_ani_init(sc->ah, ATH5K_ANI_MODE_OFF);
  687. } else if (strncmp(buf, "ani-on", 6) == 0) {
  688. ath5k_ani_init(sc->ah, ATH5K_ANI_MODE_AUTO);
  689. } else if (strncmp(buf, "noise-low", 9) == 0) {
  690. ath5k_ani_set_noise_immunity_level(sc->ah, 0);
  691. } else if (strncmp(buf, "noise-high", 10) == 0) {
  692. ath5k_ani_set_noise_immunity_level(sc->ah,
  693. ATH5K_ANI_MAX_NOISE_IMM_LVL);
  694. } else if (strncmp(buf, "spur-low", 8) == 0) {
  695. ath5k_ani_set_spur_immunity_level(sc->ah, 0);
  696. } else if (strncmp(buf, "spur-high", 9) == 0) {
  697. ath5k_ani_set_spur_immunity_level(sc->ah,
  698. sc->ani_state.max_spur_level);
  699. } else if (strncmp(buf, "fir-low", 7) == 0) {
  700. ath5k_ani_set_firstep_level(sc->ah, 0);
  701. } else if (strncmp(buf, "fir-high", 8) == 0) {
  702. ath5k_ani_set_firstep_level(sc->ah, ATH5K_ANI_MAX_FIRSTEP_LVL);
  703. } else if (strncmp(buf, "ofdm-off", 8) == 0) {
  704. ath5k_ani_set_ofdm_weak_signal_detection(sc->ah, false);
  705. } else if (strncmp(buf, "ofdm-on", 7) == 0) {
  706. ath5k_ani_set_ofdm_weak_signal_detection(sc->ah, true);
  707. } else if (strncmp(buf, "cck-off", 7) == 0) {
  708. ath5k_ani_set_cck_weak_signal_detection(sc->ah, false);
  709. } else if (strncmp(buf, "cck-on", 6) == 0) {
  710. ath5k_ani_set_cck_weak_signal_detection(sc->ah, true);
  711. }
  712. return count;
  713. }
  714. static const struct file_operations fops_ani = {
  715. .read = read_file_ani,
  716. .write = write_file_ani,
  717. .open = ath5k_debugfs_open,
  718. .owner = THIS_MODULE,
  719. };
  720. /* debugfs: queues etc */
  721. static ssize_t read_file_queue(struct file *file, char __user *user_buf,
  722. size_t count, loff_t *ppos)
  723. {
  724. struct ath5k_softc *sc = file->private_data;
  725. char buf[700];
  726. unsigned int len = 0;
  727. struct ath5k_txq *txq;
  728. struct ath5k_buf *bf, *bf0;
  729. int i, n;
  730. len += snprintf(buf+len, sizeof(buf)-len,
  731. "available txbuffers: %d\n", sc->txbuf_len);
  732. for (i = 0; i < ARRAY_SIZE(sc->txqs); i++) {
  733. txq = &sc->txqs[i];
  734. len += snprintf(buf+len, sizeof(buf)-len,
  735. "%02d: %ssetup\n", i, txq->setup ? "" : "not ");
  736. if (!txq->setup)
  737. continue;
  738. n = 0;
  739. spin_lock_bh(&txq->lock);
  740. list_for_each_entry_safe(bf, bf0, &txq->q, list)
  741. n++;
  742. spin_unlock_bh(&txq->lock);
  743. len += snprintf(buf+len, sizeof(buf)-len,
  744. " len: %d bufs: %d\n", txq->txq_len, n);
  745. len += snprintf(buf+len, sizeof(buf)-len,
  746. " stuck: %d\n", txq->txq_stuck);
  747. }
  748. if (len > sizeof(buf))
  749. len = sizeof(buf);
  750. return simple_read_from_buffer(user_buf, count, ppos, buf, len);
  751. }
  752. static ssize_t write_file_queue(struct file *file,
  753. const char __user *userbuf,
  754. size_t count, loff_t *ppos)
  755. {
  756. struct ath5k_softc *sc = file->private_data;
  757. char buf[20];
  758. if (copy_from_user(buf, userbuf, min(count, sizeof(buf))))
  759. return -EFAULT;
  760. if (strncmp(buf, "start", 5) == 0)
  761. ieee80211_wake_queues(sc->hw);
  762. else if (strncmp(buf, "stop", 4) == 0)
  763. ieee80211_stop_queues(sc->hw);
  764. return count;
  765. }
  766. static const struct file_operations fops_queue = {
  767. .read = read_file_queue,
  768. .write = write_file_queue,
  769. .open = ath5k_debugfs_open,
  770. .owner = THIS_MODULE,
  771. };
  772. /* init */
  773. void
  774. ath5k_debug_init(void)
  775. {
  776. ath5k_global_debugfs = debugfs_create_dir("ath5k", NULL);
  777. }
  778. void
  779. ath5k_debug_init_device(struct ath5k_softc *sc)
  780. {
  781. sc->debug.level = ath5k_debug;
  782. sc->debug.debugfs_phydir = debugfs_create_dir(wiphy_name(sc->hw->wiphy),
  783. ath5k_global_debugfs);
  784. sc->debug.debugfs_debug = debugfs_create_file("debug",
  785. S_IWUSR | S_IRUSR,
  786. sc->debug.debugfs_phydir, sc, &fops_debug);
  787. sc->debug.debugfs_registers = debugfs_create_file("registers", S_IRUSR,
  788. sc->debug.debugfs_phydir, sc, &fops_registers);
  789. sc->debug.debugfs_beacon = debugfs_create_file("beacon",
  790. S_IWUSR | S_IRUSR,
  791. sc->debug.debugfs_phydir, sc, &fops_beacon);
  792. sc->debug.debugfs_reset = debugfs_create_file("reset", S_IWUSR,
  793. sc->debug.debugfs_phydir, sc, &fops_reset);
  794. sc->debug.debugfs_antenna = debugfs_create_file("antenna",
  795. S_IWUSR | S_IRUSR,
  796. sc->debug.debugfs_phydir, sc, &fops_antenna);
  797. sc->debug.debugfs_misc = debugfs_create_file("misc",
  798. S_IRUSR,
  799. sc->debug.debugfs_phydir, sc, &fops_misc);
  800. sc->debug.debugfs_frameerrors = debugfs_create_file("frameerrors",
  801. S_IWUSR | S_IRUSR,
  802. sc->debug.debugfs_phydir, sc,
  803. &fops_frameerrors);
  804. sc->debug.debugfs_ani = debugfs_create_file("ani",
  805. S_IWUSR | S_IRUSR,
  806. sc->debug.debugfs_phydir, sc,
  807. &fops_ani);
  808. sc->debug.debugfs_queue = debugfs_create_file("queue",
  809. S_IWUSR | S_IRUSR,
  810. sc->debug.debugfs_phydir, sc,
  811. &fops_queue);
  812. }
  813. void
  814. ath5k_debug_finish(void)
  815. {
  816. debugfs_remove(ath5k_global_debugfs);
  817. }
  818. void
  819. ath5k_debug_finish_device(struct ath5k_softc *sc)
  820. {
  821. debugfs_remove(sc->debug.debugfs_debug);
  822. debugfs_remove(sc->debug.debugfs_registers);
  823. debugfs_remove(sc->debug.debugfs_beacon);
  824. debugfs_remove(sc->debug.debugfs_reset);
  825. debugfs_remove(sc->debug.debugfs_antenna);
  826. debugfs_remove(sc->debug.debugfs_misc);
  827. debugfs_remove(sc->debug.debugfs_frameerrors);
  828. debugfs_remove(sc->debug.debugfs_ani);
  829. debugfs_remove(sc->debug.debugfs_queue);
  830. debugfs_remove(sc->debug.debugfs_phydir);
  831. }
  832. /* functions used in other places */
  833. void
  834. ath5k_debug_dump_bands(struct ath5k_softc *sc)
  835. {
  836. unsigned int b, i;
  837. if (likely(!(sc->debug.level & ATH5K_DEBUG_DUMPBANDS)))
  838. return;
  839. BUG_ON(!sc->sbands);
  840. for (b = 0; b < IEEE80211_NUM_BANDS; b++) {
  841. struct ieee80211_supported_band *band = &sc->sbands[b];
  842. char bname[6];
  843. switch (band->band) {
  844. case IEEE80211_BAND_2GHZ:
  845. strcpy(bname, "2 GHz");
  846. break;
  847. case IEEE80211_BAND_5GHZ:
  848. strcpy(bname, "5 GHz");
  849. break;
  850. default:
  851. printk(KERN_DEBUG "Band not supported: %d\n",
  852. band->band);
  853. return;
  854. }
  855. printk(KERN_DEBUG "Band %s: channels %d, rates %d\n", bname,
  856. band->n_channels, band->n_bitrates);
  857. printk(KERN_DEBUG " channels:\n");
  858. for (i = 0; i < band->n_channels; i++)
  859. printk(KERN_DEBUG " %3d %d %.4x %.4x\n",
  860. ieee80211_frequency_to_channel(
  861. band->channels[i].center_freq),
  862. band->channels[i].center_freq,
  863. band->channels[i].hw_value,
  864. band->channels[i].flags);
  865. printk(KERN_DEBUG " rates:\n");
  866. for (i = 0; i < band->n_bitrates; i++)
  867. printk(KERN_DEBUG " %4d %.4x %.4x %.4x\n",
  868. band->bitrates[i].bitrate,
  869. band->bitrates[i].hw_value,
  870. band->bitrates[i].flags,
  871. band->bitrates[i].hw_value_short);
  872. }
  873. }
  874. static inline void
  875. ath5k_debug_printrxbuf(struct ath5k_buf *bf, int done,
  876. struct ath5k_rx_status *rs)
  877. {
  878. struct ath5k_desc *ds = bf->desc;
  879. struct ath5k_hw_all_rx_desc *rd = &ds->ud.ds_rx;
  880. printk(KERN_DEBUG "R (%p %llx) %08x %08x %08x %08x %08x %08x %c\n",
  881. ds, (unsigned long long)bf->daddr,
  882. ds->ds_link, ds->ds_data,
  883. rd->rx_ctl.rx_control_0, rd->rx_ctl.rx_control_1,
  884. rd->rx_stat.rx_status_0, rd->rx_stat.rx_status_1,
  885. !done ? ' ' : (rs->rs_status == 0) ? '*' : '!');
  886. }
  887. void
  888. ath5k_debug_printrxbuffs(struct ath5k_softc *sc, struct ath5k_hw *ah)
  889. {
  890. struct ath5k_desc *ds;
  891. struct ath5k_buf *bf;
  892. struct ath5k_rx_status rs = {};
  893. int status;
  894. if (likely(!(sc->debug.level & ATH5K_DEBUG_DESC)))
  895. return;
  896. printk(KERN_DEBUG "rxdp %x, rxlink %p\n",
  897. ath5k_hw_get_rxdp(ah), sc->rxlink);
  898. spin_lock_bh(&sc->rxbuflock);
  899. list_for_each_entry(bf, &sc->rxbuf, list) {
  900. ds = bf->desc;
  901. status = ah->ah_proc_rx_desc(ah, ds, &rs);
  902. if (!status)
  903. ath5k_debug_printrxbuf(bf, status == 0, &rs);
  904. }
  905. spin_unlock_bh(&sc->rxbuflock);
  906. }
  907. void
  908. ath5k_debug_dump_skb(struct ath5k_softc *sc,
  909. struct sk_buff *skb, const char *prefix, int tx)
  910. {
  911. char buf[16];
  912. if (likely(!((tx && (sc->debug.level & ATH5K_DEBUG_DUMP_TX)) ||
  913. (!tx && (sc->debug.level & ATH5K_DEBUG_DUMP_RX)))))
  914. return;
  915. snprintf(buf, sizeof(buf), "%s %s", wiphy_name(sc->hw->wiphy), prefix);
  916. print_hex_dump_bytes(buf, DUMP_PREFIX_NONE, skb->data,
  917. min(200U, skb->len));
  918. printk(KERN_DEBUG "\n");
  919. }
  920. void
  921. ath5k_debug_printtxbuf(struct ath5k_softc *sc, struct ath5k_buf *bf)
  922. {
  923. struct ath5k_desc *ds = bf->desc;
  924. struct ath5k_hw_5212_tx_desc *td = &ds->ud.ds_tx5212;
  925. struct ath5k_tx_status ts = {};
  926. int done;
  927. if (likely(!(sc->debug.level & ATH5K_DEBUG_DESC)))
  928. return;
  929. done = sc->ah->ah_proc_tx_desc(sc->ah, bf->desc, &ts);
  930. printk(KERN_DEBUG "T (%p %llx) %08x %08x %08x %08x %08x %08x %08x "
  931. "%08x %c\n", ds, (unsigned long long)bf->daddr, ds->ds_link,
  932. ds->ds_data, td->tx_ctl.tx_control_0, td->tx_ctl.tx_control_1,
  933. td->tx_ctl.tx_control_2, td->tx_ctl.tx_control_3,
  934. td->tx_stat.tx_status_0, td->tx_stat.tx_status_1,
  935. done ? ' ' : (ts.ts_status == 0) ? '*' : '!');
  936. }
  937. #endif /* ifdef CONFIG_ATH5K_DEBUG */