debug.c 33 KB

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