debug.c 33 KB

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