debug.c 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070
  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 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");
  452. len += snprintf(buf+len, sizeof(buf)-len, "\nopmode: %s (%d)\n",
  453. ath_opmode_to_string(sc->opmode), sc->opmode);
  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. #define CC_PRINT(_struct, _field) \
  626. _struct._field, \
  627. _struct.cycles > 0 ? \
  628. _struct._field*100/_struct.cycles : 0
  629. len += snprintf(buf+len, sizeof(buf)-len, "profcnt tx\t\t%u\t(%d%%)\n",
  630. CC_PRINT(as->last_cc, tx_frame));
  631. len += snprintf(buf+len, sizeof(buf)-len, "profcnt rx\t\t%u\t(%d%%)\n",
  632. CC_PRINT(as->last_cc, rx_frame));
  633. len += snprintf(buf+len, sizeof(buf)-len, "profcnt busy\t\t%u\t(%d%%)\n",
  634. CC_PRINT(as->last_cc, rx_busy));
  635. #undef CC_PRINT
  636. len += snprintf(buf+len, sizeof(buf)-len, "profcnt cycles\t\t%u\n",
  637. as->last_cc.cycles);
  638. len += snprintf(buf+len, sizeof(buf)-len,
  639. "listen time\t\t%d\tlast: %d\n",
  640. as->listen_time, as->last_listen);
  641. len += snprintf(buf+len, sizeof(buf)-len,
  642. "OFDM errors\t\t%u\tlast: %u\tsum: %u\n",
  643. as->ofdm_errors, as->last_ofdm_errors,
  644. as->sum_ofdm_errors);
  645. len += snprintf(buf+len, sizeof(buf)-len,
  646. "CCK errors\t\t%u\tlast: %u\tsum: %u\n",
  647. as->cck_errors, as->last_cck_errors,
  648. as->sum_cck_errors);
  649. len += snprintf(buf+len, sizeof(buf)-len,
  650. "AR5K_PHYERR_CNT1\t%x\t(=%d)\n",
  651. ath5k_hw_reg_read(sc->ah, AR5K_PHYERR_CNT1),
  652. ATH5K_ANI_OFDM_TRIG_HIGH - (ATH5K_PHYERR_CNT_MAX -
  653. ath5k_hw_reg_read(sc->ah, AR5K_PHYERR_CNT1)));
  654. len += snprintf(buf+len, sizeof(buf)-len,
  655. "AR5K_PHYERR_CNT2\t%x\t(=%d)\n",
  656. ath5k_hw_reg_read(sc->ah, AR5K_PHYERR_CNT2),
  657. ATH5K_ANI_CCK_TRIG_HIGH - (ATH5K_PHYERR_CNT_MAX -
  658. ath5k_hw_reg_read(sc->ah, AR5K_PHYERR_CNT2)));
  659. if (len > sizeof(buf))
  660. len = sizeof(buf);
  661. return simple_read_from_buffer(user_buf, count, ppos, buf, len);
  662. }
  663. static ssize_t write_file_ani(struct file *file,
  664. const char __user *userbuf,
  665. size_t count, loff_t *ppos)
  666. {
  667. struct ath5k_softc *sc = file->private_data;
  668. char buf[20];
  669. if (copy_from_user(buf, userbuf, min(count, sizeof(buf))))
  670. return -EFAULT;
  671. if (strncmp(buf, "sens-low", 8) == 0) {
  672. ath5k_ani_init(sc->ah, ATH5K_ANI_MODE_MANUAL_HIGH);
  673. } else if (strncmp(buf, "sens-high", 9) == 0) {
  674. ath5k_ani_init(sc->ah, ATH5K_ANI_MODE_MANUAL_LOW);
  675. } else if (strncmp(buf, "ani-off", 7) == 0) {
  676. ath5k_ani_init(sc->ah, ATH5K_ANI_MODE_OFF);
  677. } else if (strncmp(buf, "ani-on", 6) == 0) {
  678. ath5k_ani_init(sc->ah, ATH5K_ANI_MODE_AUTO);
  679. } else if (strncmp(buf, "noise-low", 9) == 0) {
  680. ath5k_ani_set_noise_immunity_level(sc->ah, 0);
  681. } else if (strncmp(buf, "noise-high", 10) == 0) {
  682. ath5k_ani_set_noise_immunity_level(sc->ah,
  683. ATH5K_ANI_MAX_NOISE_IMM_LVL);
  684. } else if (strncmp(buf, "spur-low", 8) == 0) {
  685. ath5k_ani_set_spur_immunity_level(sc->ah, 0);
  686. } else if (strncmp(buf, "spur-high", 9) == 0) {
  687. ath5k_ani_set_spur_immunity_level(sc->ah,
  688. sc->ani_state.max_spur_level);
  689. } else if (strncmp(buf, "fir-low", 7) == 0) {
  690. ath5k_ani_set_firstep_level(sc->ah, 0);
  691. } else if (strncmp(buf, "fir-high", 8) == 0) {
  692. ath5k_ani_set_firstep_level(sc->ah, ATH5K_ANI_MAX_FIRSTEP_LVL);
  693. } else if (strncmp(buf, "ofdm-off", 8) == 0) {
  694. ath5k_ani_set_ofdm_weak_signal_detection(sc->ah, false);
  695. } else if (strncmp(buf, "ofdm-on", 7) == 0) {
  696. ath5k_ani_set_ofdm_weak_signal_detection(sc->ah, true);
  697. } else if (strncmp(buf, "cck-off", 7) == 0) {
  698. ath5k_ani_set_cck_weak_signal_detection(sc->ah, false);
  699. } else if (strncmp(buf, "cck-on", 6) == 0) {
  700. ath5k_ani_set_cck_weak_signal_detection(sc->ah, true);
  701. }
  702. return count;
  703. }
  704. static const struct file_operations fops_ani = {
  705. .read = read_file_ani,
  706. .write = write_file_ani,
  707. .open = ath5k_debugfs_open,
  708. .owner = THIS_MODULE,
  709. };
  710. /* debugfs: queues etc */
  711. static ssize_t read_file_queue(struct file *file, char __user *user_buf,
  712. size_t count, loff_t *ppos)
  713. {
  714. struct ath5k_softc *sc = file->private_data;
  715. char buf[700];
  716. unsigned int len = 0;
  717. struct ath5k_txq *txq;
  718. struct ath5k_buf *bf, *bf0;
  719. int i, n;
  720. len += snprintf(buf+len, sizeof(buf)-len,
  721. "available txbuffers: %d\n", sc->txbuf_len);
  722. for (i = 0; i < ARRAY_SIZE(sc->txqs); i++) {
  723. txq = &sc->txqs[i];
  724. len += snprintf(buf+len, sizeof(buf)-len,
  725. "%02d: %ssetup\n", i, txq->setup ? "" : "not ");
  726. if (!txq->setup)
  727. continue;
  728. n = 0;
  729. spin_lock_bh(&txq->lock);
  730. list_for_each_entry_safe(bf, bf0, &txq->q, list)
  731. n++;
  732. spin_unlock_bh(&txq->lock);
  733. len += snprintf(buf+len, sizeof(buf)-len,
  734. " len: %d bufs: %d\n", txq->txq_len, n);
  735. len += snprintf(buf+len, sizeof(buf)-len,
  736. " stuck: %d\n", txq->txq_stuck);
  737. }
  738. if (len > sizeof(buf))
  739. len = sizeof(buf);
  740. return simple_read_from_buffer(user_buf, count, ppos, buf, len);
  741. }
  742. static ssize_t write_file_queue(struct file *file,
  743. const char __user *userbuf,
  744. size_t count, loff_t *ppos)
  745. {
  746. struct ath5k_softc *sc = file->private_data;
  747. char buf[20];
  748. if (copy_from_user(buf, userbuf, min(count, sizeof(buf))))
  749. return -EFAULT;
  750. if (strncmp(buf, "start", 5) == 0)
  751. ieee80211_wake_queues(sc->hw);
  752. else if (strncmp(buf, "stop", 4) == 0)
  753. ieee80211_stop_queues(sc->hw);
  754. return count;
  755. }
  756. static const struct file_operations fops_queue = {
  757. .read = read_file_queue,
  758. .write = write_file_queue,
  759. .open = ath5k_debugfs_open,
  760. .owner = THIS_MODULE,
  761. };
  762. void
  763. ath5k_debug_init_device(struct ath5k_softc *sc)
  764. {
  765. sc->debug.level = ath5k_debug;
  766. sc->debug.debugfs_phydir = debugfs_create_dir("ath5k",
  767. sc->hw->wiphy->debugfsdir);
  768. sc->debug.debugfs_debug = debugfs_create_file("debug",
  769. S_IWUSR | S_IRUSR,
  770. sc->debug.debugfs_phydir, sc, &fops_debug);
  771. sc->debug.debugfs_registers = debugfs_create_file("registers", S_IRUSR,
  772. sc->debug.debugfs_phydir, sc, &fops_registers);
  773. sc->debug.debugfs_beacon = debugfs_create_file("beacon",
  774. S_IWUSR | S_IRUSR,
  775. sc->debug.debugfs_phydir, sc, &fops_beacon);
  776. sc->debug.debugfs_reset = debugfs_create_file("reset", S_IWUSR,
  777. sc->debug.debugfs_phydir, sc, &fops_reset);
  778. sc->debug.debugfs_antenna = debugfs_create_file("antenna",
  779. S_IWUSR | S_IRUSR,
  780. sc->debug.debugfs_phydir, sc, &fops_antenna);
  781. sc->debug.debugfs_misc = debugfs_create_file("misc",
  782. S_IRUSR,
  783. sc->debug.debugfs_phydir, sc, &fops_misc);
  784. sc->debug.debugfs_frameerrors = debugfs_create_file("frameerrors",
  785. S_IWUSR | S_IRUSR,
  786. sc->debug.debugfs_phydir, sc,
  787. &fops_frameerrors);
  788. sc->debug.debugfs_ani = debugfs_create_file("ani",
  789. S_IWUSR | S_IRUSR,
  790. sc->debug.debugfs_phydir, sc,
  791. &fops_ani);
  792. sc->debug.debugfs_queue = debugfs_create_file("queue",
  793. S_IWUSR | S_IRUSR,
  794. sc->debug.debugfs_phydir, sc,
  795. &fops_queue);
  796. }
  797. void
  798. ath5k_debug_finish_device(struct ath5k_softc *sc)
  799. {
  800. debugfs_remove(sc->debug.debugfs_debug);
  801. debugfs_remove(sc->debug.debugfs_registers);
  802. debugfs_remove(sc->debug.debugfs_beacon);
  803. debugfs_remove(sc->debug.debugfs_reset);
  804. debugfs_remove(sc->debug.debugfs_antenna);
  805. debugfs_remove(sc->debug.debugfs_misc);
  806. debugfs_remove(sc->debug.debugfs_frameerrors);
  807. debugfs_remove(sc->debug.debugfs_ani);
  808. debugfs_remove(sc->debug.debugfs_queue);
  809. debugfs_remove(sc->debug.debugfs_phydir);
  810. }
  811. /* functions used in other places */
  812. void
  813. ath5k_debug_dump_bands(struct ath5k_softc *sc)
  814. {
  815. unsigned int b, i;
  816. if (likely(!(sc->debug.level & ATH5K_DEBUG_DUMPBANDS)))
  817. return;
  818. BUG_ON(!sc->sbands);
  819. for (b = 0; b < IEEE80211_NUM_BANDS; b++) {
  820. struct ieee80211_supported_band *band = &sc->sbands[b];
  821. char bname[6];
  822. switch (band->band) {
  823. case IEEE80211_BAND_2GHZ:
  824. strcpy(bname, "2 GHz");
  825. break;
  826. case IEEE80211_BAND_5GHZ:
  827. strcpy(bname, "5 GHz");
  828. break;
  829. default:
  830. printk(KERN_DEBUG "Band not supported: %d\n",
  831. band->band);
  832. return;
  833. }
  834. printk(KERN_DEBUG "Band %s: channels %d, rates %d\n", bname,
  835. band->n_channels, band->n_bitrates);
  836. printk(KERN_DEBUG " channels:\n");
  837. for (i = 0; i < band->n_channels; i++)
  838. printk(KERN_DEBUG " %3d %d %.4x %.4x\n",
  839. ieee80211_frequency_to_channel(
  840. band->channels[i].center_freq),
  841. band->channels[i].center_freq,
  842. band->channels[i].hw_value,
  843. band->channels[i].flags);
  844. printk(KERN_DEBUG " rates:\n");
  845. for (i = 0; i < band->n_bitrates; i++)
  846. printk(KERN_DEBUG " %4d %.4x %.4x %.4x\n",
  847. band->bitrates[i].bitrate,
  848. band->bitrates[i].hw_value,
  849. band->bitrates[i].flags,
  850. band->bitrates[i].hw_value_short);
  851. }
  852. }
  853. static inline void
  854. ath5k_debug_printrxbuf(struct ath5k_buf *bf, int done,
  855. struct ath5k_rx_status *rs)
  856. {
  857. struct ath5k_desc *ds = bf->desc;
  858. struct ath5k_hw_all_rx_desc *rd = &ds->ud.ds_rx;
  859. printk(KERN_DEBUG "R (%p %llx) %08x %08x %08x %08x %08x %08x %c\n",
  860. ds, (unsigned long long)bf->daddr,
  861. ds->ds_link, ds->ds_data,
  862. rd->rx_ctl.rx_control_0, rd->rx_ctl.rx_control_1,
  863. rd->rx_stat.rx_status_0, rd->rx_stat.rx_status_1,
  864. !done ? ' ' : (rs->rs_status == 0) ? '*' : '!');
  865. }
  866. void
  867. ath5k_debug_printrxbuffs(struct ath5k_softc *sc, struct ath5k_hw *ah)
  868. {
  869. struct ath5k_desc *ds;
  870. struct ath5k_buf *bf;
  871. struct ath5k_rx_status rs = {};
  872. int status;
  873. if (likely(!(sc->debug.level & ATH5K_DEBUG_DESC)))
  874. return;
  875. printk(KERN_DEBUG "rxdp %x, rxlink %p\n",
  876. ath5k_hw_get_rxdp(ah), sc->rxlink);
  877. spin_lock_bh(&sc->rxbuflock);
  878. list_for_each_entry(bf, &sc->rxbuf, list) {
  879. ds = bf->desc;
  880. status = ah->ah_proc_rx_desc(ah, ds, &rs);
  881. if (!status)
  882. ath5k_debug_printrxbuf(bf, status == 0, &rs);
  883. }
  884. spin_unlock_bh(&sc->rxbuflock);
  885. }
  886. void
  887. ath5k_debug_dump_skb(struct ath5k_softc *sc,
  888. struct sk_buff *skb, const char *prefix, int tx)
  889. {
  890. char buf[16];
  891. if (likely(!((tx && (sc->debug.level & ATH5K_DEBUG_DUMP_TX)) ||
  892. (!tx && (sc->debug.level & ATH5K_DEBUG_DUMP_RX)))))
  893. return;
  894. snprintf(buf, sizeof(buf), "%s %s", wiphy_name(sc->hw->wiphy), prefix);
  895. print_hex_dump_bytes(buf, DUMP_PREFIX_NONE, skb->data,
  896. min(200U, skb->len));
  897. printk(KERN_DEBUG "\n");
  898. }
  899. void
  900. ath5k_debug_printtxbuf(struct ath5k_softc *sc, struct ath5k_buf *bf)
  901. {
  902. struct ath5k_desc *ds = bf->desc;
  903. struct ath5k_hw_5212_tx_desc *td = &ds->ud.ds_tx5212;
  904. struct ath5k_tx_status ts = {};
  905. int done;
  906. if (likely(!(sc->debug.level & ATH5K_DEBUG_DESC)))
  907. return;
  908. done = sc->ah->ah_proc_tx_desc(sc->ah, bf->desc, &ts);
  909. printk(KERN_DEBUG "T (%p %llx) %08x %08x %08x %08x %08x %08x %08x "
  910. "%08x %c\n", ds, (unsigned long long)bf->daddr, ds->ds_link,
  911. ds->ds_data, td->tx_ctl.tx_control_0, td->tx_ctl.tx_control_1,
  912. td->tx_ctl.tx_control_2, td->tx_ctl.tx_control_3,
  913. td->tx_stat.tx_status_0, td->tx_stat.tx_status_1,
  914. done ? ' ' : (ts.ts_status == 0) ? '*' : '!');
  915. }
  916. #endif /* ifdef CONFIG_ATH5K_DEBUG */