debug.c 32 KB

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