debug.c 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810
  1. /*
  2. * Copyright (c) 2004-2011 Atheros Communications Inc.
  3. * Copyright (c) 2011-2012 Qualcomm Atheros, Inc.
  4. *
  5. * Permission to use, copy, modify, and/or distribute this software for any
  6. * purpose with or without fee is hereby granted, provided that the above
  7. * copyright notice and this permission notice appear in all copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  10. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  11. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  12. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  13. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  14. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  15. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  16. */
  17. #include "core.h"
  18. #include <linux/skbuff.h>
  19. #include <linux/fs.h>
  20. #include <linux/vmalloc.h>
  21. #include <linux/export.h>
  22. #include "debug.h"
  23. #include "target.h"
  24. struct ath6kl_fwlog_slot {
  25. __le32 timestamp;
  26. __le32 length;
  27. /* max ATH6KL_FWLOG_PAYLOAD_SIZE bytes */
  28. u8 payload[0];
  29. };
  30. #define ATH6KL_FWLOG_MAX_ENTRIES 20
  31. #define ATH6KL_FWLOG_VALID_MASK 0x1ffff
  32. int ath6kl_printk(const char *level, const char *fmt, ...)
  33. {
  34. struct va_format vaf;
  35. va_list args;
  36. int rtn;
  37. va_start(args, fmt);
  38. vaf.fmt = fmt;
  39. vaf.va = &args;
  40. rtn = printk("%sath6kl: %pV", level, &vaf);
  41. va_end(args);
  42. return rtn;
  43. }
  44. EXPORT_SYMBOL(ath6kl_printk);
  45. #ifdef CONFIG_ATH6KL_DEBUG
  46. void ath6kl_dbg(enum ATH6K_DEBUG_MASK mask, const char *fmt, ...)
  47. {
  48. struct va_format vaf;
  49. va_list args;
  50. if (!(debug_mask & mask))
  51. return;
  52. va_start(args, fmt);
  53. vaf.fmt = fmt;
  54. vaf.va = &args;
  55. ath6kl_printk(KERN_DEBUG, "%pV", &vaf);
  56. va_end(args);
  57. }
  58. EXPORT_SYMBOL(ath6kl_dbg);
  59. void ath6kl_dbg_dump(enum ATH6K_DEBUG_MASK mask,
  60. const char *msg, const char *prefix,
  61. const void *buf, size_t len)
  62. {
  63. if (debug_mask & mask) {
  64. if (msg)
  65. ath6kl_dbg(mask, "%s\n", msg);
  66. print_hex_dump_bytes(prefix, DUMP_PREFIX_OFFSET, buf, len);
  67. }
  68. }
  69. EXPORT_SYMBOL(ath6kl_dbg_dump);
  70. #define REG_OUTPUT_LEN_PER_LINE 25
  71. #define REGTYPE_STR_LEN 100
  72. struct ath6kl_diag_reg_info {
  73. u32 reg_start;
  74. u32 reg_end;
  75. const char *reg_info;
  76. };
  77. static const struct ath6kl_diag_reg_info diag_reg[] = {
  78. { 0x20000, 0x200fc, "General DMA and Rx registers" },
  79. { 0x28000, 0x28900, "MAC PCU register & keycache" },
  80. { 0x20800, 0x20a40, "QCU" },
  81. { 0x21000, 0x212f0, "DCU" },
  82. { 0x4000, 0x42e4, "RTC" },
  83. { 0x540000, 0x540000 + (256 * 1024), "RAM" },
  84. { 0x29800, 0x2B210, "Base Band" },
  85. { 0x1C000, 0x1C748, "Analog" },
  86. };
  87. void ath6kl_dump_registers(struct ath6kl_device *dev,
  88. struct ath6kl_irq_proc_registers *irq_proc_reg,
  89. struct ath6kl_irq_enable_reg *irq_enable_reg)
  90. {
  91. ath6kl_dbg(ATH6KL_DBG_IRQ, ("<------- Register Table -------->\n"));
  92. if (irq_proc_reg != NULL) {
  93. ath6kl_dbg(ATH6KL_DBG_IRQ,
  94. "Host Int status: 0x%x\n",
  95. irq_proc_reg->host_int_status);
  96. ath6kl_dbg(ATH6KL_DBG_IRQ,
  97. "CPU Int status: 0x%x\n",
  98. irq_proc_reg->cpu_int_status);
  99. ath6kl_dbg(ATH6KL_DBG_IRQ,
  100. "Error Int status: 0x%x\n",
  101. irq_proc_reg->error_int_status);
  102. ath6kl_dbg(ATH6KL_DBG_IRQ,
  103. "Counter Int status: 0x%x\n",
  104. irq_proc_reg->counter_int_status);
  105. ath6kl_dbg(ATH6KL_DBG_IRQ,
  106. "Mbox Frame: 0x%x\n",
  107. irq_proc_reg->mbox_frame);
  108. ath6kl_dbg(ATH6KL_DBG_IRQ,
  109. "Rx Lookahead Valid: 0x%x\n",
  110. irq_proc_reg->rx_lkahd_valid);
  111. ath6kl_dbg(ATH6KL_DBG_IRQ,
  112. "Rx Lookahead 0: 0x%x\n",
  113. irq_proc_reg->rx_lkahd[0]);
  114. ath6kl_dbg(ATH6KL_DBG_IRQ,
  115. "Rx Lookahead 1: 0x%x\n",
  116. irq_proc_reg->rx_lkahd[1]);
  117. if (dev->ar->mbox_info.gmbox_addr != 0) {
  118. /*
  119. * If the target supports GMBOX hardware, dump some
  120. * additional state.
  121. */
  122. ath6kl_dbg(ATH6KL_DBG_IRQ,
  123. "GMBOX Host Int status 2: 0x%x\n",
  124. irq_proc_reg->host_int_status2);
  125. ath6kl_dbg(ATH6KL_DBG_IRQ,
  126. "GMBOX RX Avail: 0x%x\n",
  127. irq_proc_reg->gmbox_rx_avail);
  128. ath6kl_dbg(ATH6KL_DBG_IRQ,
  129. "GMBOX lookahead alias 0: 0x%x\n",
  130. irq_proc_reg->rx_gmbox_lkahd_alias[0]);
  131. ath6kl_dbg(ATH6KL_DBG_IRQ,
  132. "GMBOX lookahead alias 1: 0x%x\n",
  133. irq_proc_reg->rx_gmbox_lkahd_alias[1]);
  134. }
  135. }
  136. if (irq_enable_reg != NULL) {
  137. ath6kl_dbg(ATH6KL_DBG_IRQ,
  138. "Int status Enable: 0x%x\n",
  139. irq_enable_reg->int_status_en);
  140. ath6kl_dbg(ATH6KL_DBG_IRQ, "Counter Int status Enable: 0x%x\n",
  141. irq_enable_reg->cntr_int_status_en);
  142. }
  143. ath6kl_dbg(ATH6KL_DBG_IRQ, "<------------------------------->\n");
  144. }
  145. static void dump_cred_dist(struct htc_endpoint_credit_dist *ep_dist)
  146. {
  147. ath6kl_dbg(ATH6KL_DBG_CREDIT,
  148. "--- endpoint: %d svc_id: 0x%X ---\n",
  149. ep_dist->endpoint, ep_dist->svc_id);
  150. ath6kl_dbg(ATH6KL_DBG_CREDIT, " dist_flags : 0x%X\n",
  151. ep_dist->dist_flags);
  152. ath6kl_dbg(ATH6KL_DBG_CREDIT, " cred_norm : %d\n",
  153. ep_dist->cred_norm);
  154. ath6kl_dbg(ATH6KL_DBG_CREDIT, " cred_min : %d\n",
  155. ep_dist->cred_min);
  156. ath6kl_dbg(ATH6KL_DBG_CREDIT, " credits : %d\n",
  157. ep_dist->credits);
  158. ath6kl_dbg(ATH6KL_DBG_CREDIT, " cred_assngd : %d\n",
  159. ep_dist->cred_assngd);
  160. ath6kl_dbg(ATH6KL_DBG_CREDIT, " seek_cred : %d\n",
  161. ep_dist->seek_cred);
  162. ath6kl_dbg(ATH6KL_DBG_CREDIT, " cred_sz : %d\n",
  163. ep_dist->cred_sz);
  164. ath6kl_dbg(ATH6KL_DBG_CREDIT, " cred_per_msg : %d\n",
  165. ep_dist->cred_per_msg);
  166. ath6kl_dbg(ATH6KL_DBG_CREDIT, " cred_to_dist : %d\n",
  167. ep_dist->cred_to_dist);
  168. ath6kl_dbg(ATH6KL_DBG_CREDIT, " txq_depth : %d\n",
  169. get_queue_depth(&ep_dist->htc_ep->txq));
  170. ath6kl_dbg(ATH6KL_DBG_CREDIT,
  171. "----------------------------------\n");
  172. }
  173. /* FIXME: move to htc.c */
  174. void dump_cred_dist_stats(struct htc_target *target)
  175. {
  176. struct htc_endpoint_credit_dist *ep_list;
  177. list_for_each_entry(ep_list, &target->cred_dist_list, list)
  178. dump_cred_dist(ep_list);
  179. ath6kl_dbg(ATH6KL_DBG_CREDIT,
  180. "credit distribution total %d free %d\n",
  181. target->credit_info->total_avail_credits,
  182. target->credit_info->cur_free_credits);
  183. }
  184. static int ath6kl_debugfs_open(struct inode *inode, struct file *file)
  185. {
  186. file->private_data = inode->i_private;
  187. return 0;
  188. }
  189. void ath6kl_debug_war(struct ath6kl *ar, enum ath6kl_war war)
  190. {
  191. switch (war) {
  192. case ATH6KL_WAR_INVALID_RATE:
  193. ar->debug.war_stats.invalid_rate++;
  194. break;
  195. }
  196. }
  197. static ssize_t read_file_war_stats(struct file *file, char __user *user_buf,
  198. size_t count, loff_t *ppos)
  199. {
  200. struct ath6kl *ar = file->private_data;
  201. char *buf;
  202. unsigned int len = 0, buf_len = 1500;
  203. ssize_t ret_cnt;
  204. buf = kzalloc(buf_len, GFP_KERNEL);
  205. if (!buf)
  206. return -ENOMEM;
  207. len += scnprintf(buf + len, buf_len - len, "\n");
  208. len += scnprintf(buf + len, buf_len - len, "%25s\n",
  209. "Workaround stats");
  210. len += scnprintf(buf + len, buf_len - len, "%25s\n\n",
  211. "=================");
  212. len += scnprintf(buf + len, buf_len - len, "%20s %10u\n",
  213. "Invalid rates", ar->debug.war_stats.invalid_rate);
  214. if (WARN_ON(len > buf_len))
  215. len = buf_len;
  216. ret_cnt = simple_read_from_buffer(user_buf, count, ppos, buf, len);
  217. kfree(buf);
  218. return ret_cnt;
  219. }
  220. static const struct file_operations fops_war_stats = {
  221. .read = read_file_war_stats,
  222. .open = ath6kl_debugfs_open,
  223. .owner = THIS_MODULE,
  224. .llseek = default_llseek,
  225. };
  226. void ath6kl_debug_fwlog_event(struct ath6kl *ar, const void *buf, size_t len)
  227. {
  228. struct ath6kl_fwlog_slot *slot;
  229. struct sk_buff *skb;
  230. size_t slot_len;
  231. if (WARN_ON(len > ATH6KL_FWLOG_PAYLOAD_SIZE))
  232. return;
  233. slot_len = sizeof(*slot) + len;
  234. skb = alloc_skb(slot_len, GFP_KERNEL);
  235. if (!skb)
  236. return;
  237. slot = (struct ath6kl_fwlog_slot *) skb_put(skb, slot_len);
  238. slot->timestamp = cpu_to_le32(jiffies);
  239. slot->length = cpu_to_le32(len);
  240. memcpy(slot->payload, buf, len);
  241. spin_lock(&ar->debug.fwlog_queue.lock);
  242. __skb_queue_tail(&ar->debug.fwlog_queue, skb);
  243. complete(&ar->debug.fwlog_completion);
  244. /* drop oldest entries */
  245. while (skb_queue_len(&ar->debug.fwlog_queue) >
  246. ATH6KL_FWLOG_MAX_ENTRIES) {
  247. skb = __skb_dequeue(&ar->debug.fwlog_queue);
  248. kfree_skb(skb);
  249. }
  250. spin_unlock(&ar->debug.fwlog_queue.lock);
  251. return;
  252. }
  253. static int ath6kl_fwlog_open(struct inode *inode, struct file *file)
  254. {
  255. struct ath6kl *ar = inode->i_private;
  256. if (ar->debug.fwlog_open)
  257. return -EBUSY;
  258. ar->debug.fwlog_open = true;
  259. file->private_data = inode->i_private;
  260. return 0;
  261. }
  262. static int ath6kl_fwlog_release(struct inode *inode, struct file *file)
  263. {
  264. struct ath6kl *ar = inode->i_private;
  265. ar->debug.fwlog_open = false;
  266. return 0;
  267. }
  268. static ssize_t ath6kl_fwlog_read(struct file *file, char __user *user_buf,
  269. size_t count, loff_t *ppos)
  270. {
  271. struct ath6kl *ar = file->private_data;
  272. struct sk_buff *skb;
  273. ssize_t ret_cnt;
  274. size_t len = 0;
  275. char *buf;
  276. buf = vmalloc(count);
  277. if (!buf)
  278. return -ENOMEM;
  279. /* read undelivered logs from firmware */
  280. ath6kl_read_fwlogs(ar);
  281. spin_lock(&ar->debug.fwlog_queue.lock);
  282. while ((skb = __skb_dequeue(&ar->debug.fwlog_queue))) {
  283. if (skb->len > count - len) {
  284. /* not enough space, put skb back and leave */
  285. __skb_queue_head(&ar->debug.fwlog_queue, skb);
  286. break;
  287. }
  288. memcpy(buf + len, skb->data, skb->len);
  289. len += skb->len;
  290. kfree_skb(skb);
  291. }
  292. spin_unlock(&ar->debug.fwlog_queue.lock);
  293. /* FIXME: what to do if len == 0? */
  294. ret_cnt = simple_read_from_buffer(user_buf, count, ppos, buf, len);
  295. vfree(buf);
  296. return ret_cnt;
  297. }
  298. static const struct file_operations fops_fwlog = {
  299. .open = ath6kl_fwlog_open,
  300. .release = ath6kl_fwlog_release,
  301. .read = ath6kl_fwlog_read,
  302. .owner = THIS_MODULE,
  303. .llseek = default_llseek,
  304. };
  305. static ssize_t ath6kl_fwlog_block_read(struct file *file,
  306. char __user *user_buf,
  307. size_t count,
  308. loff_t *ppos)
  309. {
  310. struct ath6kl *ar = file->private_data;
  311. struct sk_buff *skb;
  312. ssize_t ret_cnt;
  313. size_t len = 0, not_copied;
  314. char *buf;
  315. int ret;
  316. buf = vmalloc(count);
  317. if (!buf)
  318. return -ENOMEM;
  319. spin_lock(&ar->debug.fwlog_queue.lock);
  320. if (skb_queue_len(&ar->debug.fwlog_queue) == 0) {
  321. /* we must init under queue lock */
  322. init_completion(&ar->debug.fwlog_completion);
  323. spin_unlock(&ar->debug.fwlog_queue.lock);
  324. ret = wait_for_completion_interruptible(
  325. &ar->debug.fwlog_completion);
  326. if (ret == -ERESTARTSYS)
  327. return ret;
  328. spin_lock(&ar->debug.fwlog_queue.lock);
  329. }
  330. while ((skb = __skb_dequeue(&ar->debug.fwlog_queue))) {
  331. if (skb->len > count - len) {
  332. /* not enough space, put skb back and leave */
  333. __skb_queue_head(&ar->debug.fwlog_queue, skb);
  334. break;
  335. }
  336. memcpy(buf + len, skb->data, skb->len);
  337. len += skb->len;
  338. kfree_skb(skb);
  339. }
  340. spin_unlock(&ar->debug.fwlog_queue.lock);
  341. /* FIXME: what to do if len == 0? */
  342. not_copied = copy_to_user(user_buf, buf, len);
  343. if (not_copied != 0) {
  344. ret_cnt = -EFAULT;
  345. goto out;
  346. }
  347. *ppos = *ppos + len;
  348. ret_cnt = len;
  349. out:
  350. vfree(buf);
  351. return ret_cnt;
  352. }
  353. static const struct file_operations fops_fwlog_block = {
  354. .open = ath6kl_fwlog_open,
  355. .release = ath6kl_fwlog_release,
  356. .read = ath6kl_fwlog_block_read,
  357. .owner = THIS_MODULE,
  358. .llseek = default_llseek,
  359. };
  360. static ssize_t ath6kl_fwlog_mask_read(struct file *file, char __user *user_buf,
  361. size_t count, loff_t *ppos)
  362. {
  363. struct ath6kl *ar = file->private_data;
  364. char buf[16];
  365. int len;
  366. len = snprintf(buf, sizeof(buf), "0x%x\n", ar->debug.fwlog_mask);
  367. return simple_read_from_buffer(user_buf, count, ppos, buf, len);
  368. }
  369. static ssize_t ath6kl_fwlog_mask_write(struct file *file,
  370. const char __user *user_buf,
  371. size_t count, loff_t *ppos)
  372. {
  373. struct ath6kl *ar = file->private_data;
  374. int ret;
  375. ret = kstrtou32_from_user(user_buf, count, 0, &ar->debug.fwlog_mask);
  376. if (ret)
  377. return ret;
  378. ret = ath6kl_wmi_config_debug_module_cmd(ar->wmi,
  379. ATH6KL_FWLOG_VALID_MASK,
  380. ar->debug.fwlog_mask);
  381. if (ret)
  382. return ret;
  383. return count;
  384. }
  385. static const struct file_operations fops_fwlog_mask = {
  386. .open = ath6kl_debugfs_open,
  387. .read = ath6kl_fwlog_mask_read,
  388. .write = ath6kl_fwlog_mask_write,
  389. .owner = THIS_MODULE,
  390. .llseek = default_llseek,
  391. };
  392. static ssize_t read_file_tgt_stats(struct file *file, char __user *user_buf,
  393. size_t count, loff_t *ppos)
  394. {
  395. struct ath6kl *ar = file->private_data;
  396. struct ath6kl_vif *vif;
  397. struct target_stats *tgt_stats;
  398. char *buf;
  399. unsigned int len = 0, buf_len = 1500;
  400. int i;
  401. long left;
  402. ssize_t ret_cnt;
  403. vif = ath6kl_vif_first(ar);
  404. if (!vif)
  405. return -EIO;
  406. tgt_stats = &vif->target_stats;
  407. buf = kzalloc(buf_len, GFP_KERNEL);
  408. if (!buf)
  409. return -ENOMEM;
  410. if (down_interruptible(&ar->sem)) {
  411. kfree(buf);
  412. return -EBUSY;
  413. }
  414. set_bit(STATS_UPDATE_PEND, &vif->flags);
  415. if (ath6kl_wmi_get_stats_cmd(ar->wmi, 0)) {
  416. up(&ar->sem);
  417. kfree(buf);
  418. return -EIO;
  419. }
  420. left = wait_event_interruptible_timeout(ar->event_wq,
  421. !test_bit(STATS_UPDATE_PEND,
  422. &vif->flags), WMI_TIMEOUT);
  423. up(&ar->sem);
  424. if (left <= 0) {
  425. kfree(buf);
  426. return -ETIMEDOUT;
  427. }
  428. len += scnprintf(buf + len, buf_len - len, "\n");
  429. len += scnprintf(buf + len, buf_len - len, "%25s\n",
  430. "Target Tx stats");
  431. len += scnprintf(buf + len, buf_len - len, "%25s\n\n",
  432. "=================");
  433. len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
  434. "Ucast packets", tgt_stats->tx_ucast_pkt);
  435. len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
  436. "Bcast packets", tgt_stats->tx_bcast_pkt);
  437. len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
  438. "Ucast byte", tgt_stats->tx_ucast_byte);
  439. len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
  440. "Bcast byte", tgt_stats->tx_bcast_byte);
  441. len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
  442. "Rts success cnt", tgt_stats->tx_rts_success_cnt);
  443. for (i = 0; i < 4; i++)
  444. len += scnprintf(buf + len, buf_len - len,
  445. "%18s %d %10llu\n", "PER on ac",
  446. i, tgt_stats->tx_pkt_per_ac[i]);
  447. len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
  448. "Error", tgt_stats->tx_err);
  449. len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
  450. "Fail count", tgt_stats->tx_fail_cnt);
  451. len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
  452. "Retry count", tgt_stats->tx_retry_cnt);
  453. len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
  454. "Multi retry cnt", tgt_stats->tx_mult_retry_cnt);
  455. len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
  456. "Rts fail cnt", tgt_stats->tx_rts_fail_cnt);
  457. len += scnprintf(buf + len, buf_len - len, "%25s %10llu\n\n",
  458. "TKIP counter measure used",
  459. tgt_stats->tkip_cnter_measures_invoked);
  460. len += scnprintf(buf + len, buf_len - len, "%25s\n",
  461. "Target Rx stats");
  462. len += scnprintf(buf + len, buf_len - len, "%25s\n",
  463. "=================");
  464. len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
  465. "Ucast packets", tgt_stats->rx_ucast_pkt);
  466. len += scnprintf(buf + len, buf_len - len, "%20s %10d\n",
  467. "Ucast Rate", tgt_stats->rx_ucast_rate);
  468. len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
  469. "Bcast packets", tgt_stats->rx_bcast_pkt);
  470. len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
  471. "Ucast byte", tgt_stats->rx_ucast_byte);
  472. len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
  473. "Bcast byte", tgt_stats->rx_bcast_byte);
  474. len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
  475. "Fragmented pkt", tgt_stats->rx_frgment_pkt);
  476. len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
  477. "Error", tgt_stats->rx_err);
  478. len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
  479. "CRC Err", tgt_stats->rx_crc_err);
  480. len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
  481. "Key chache miss", tgt_stats->rx_key_cache_miss);
  482. len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
  483. "Decrypt Err", tgt_stats->rx_decrypt_err);
  484. len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
  485. "Duplicate frame", tgt_stats->rx_dupl_frame);
  486. len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
  487. "Tkip Mic failure", tgt_stats->tkip_local_mic_fail);
  488. len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
  489. "TKIP format err", tgt_stats->tkip_fmt_err);
  490. len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
  491. "CCMP format Err", tgt_stats->ccmp_fmt_err);
  492. len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n\n",
  493. "CCMP Replay Err", tgt_stats->ccmp_replays);
  494. len += scnprintf(buf + len, buf_len - len, "%25s\n",
  495. "Misc Target stats");
  496. len += scnprintf(buf + len, buf_len - len, "%25s\n",
  497. "=================");
  498. len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
  499. "Beacon Miss count", tgt_stats->cs_bmiss_cnt);
  500. len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
  501. "Num Connects", tgt_stats->cs_connect_cnt);
  502. len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
  503. "Num disconnects", tgt_stats->cs_discon_cnt);
  504. len += scnprintf(buf + len, buf_len - len, "%20s %10d\n",
  505. "Beacon avg rssi", tgt_stats->cs_ave_beacon_rssi);
  506. if (len > buf_len)
  507. len = buf_len;
  508. ret_cnt = simple_read_from_buffer(user_buf, count, ppos, buf, len);
  509. kfree(buf);
  510. return ret_cnt;
  511. }
  512. static const struct file_operations fops_tgt_stats = {
  513. .read = read_file_tgt_stats,
  514. .open = ath6kl_debugfs_open,
  515. .owner = THIS_MODULE,
  516. .llseek = default_llseek,
  517. };
  518. #define print_credit_info(fmt_str, ep_list_field) \
  519. (len += scnprintf(buf + len, buf_len - len, fmt_str, \
  520. ep_list->ep_list_field))
  521. #define CREDIT_INFO_DISPLAY_STRING_LEN 200
  522. #define CREDIT_INFO_LEN 128
  523. static ssize_t read_file_credit_dist_stats(struct file *file,
  524. char __user *user_buf,
  525. size_t count, loff_t *ppos)
  526. {
  527. struct ath6kl *ar = file->private_data;
  528. struct htc_target *target = ar->htc_target;
  529. struct htc_endpoint_credit_dist *ep_list;
  530. char *buf;
  531. unsigned int buf_len, len = 0;
  532. ssize_t ret_cnt;
  533. buf_len = CREDIT_INFO_DISPLAY_STRING_LEN +
  534. get_queue_depth(&target->cred_dist_list) * CREDIT_INFO_LEN;
  535. buf = kzalloc(buf_len, GFP_KERNEL);
  536. if (!buf)
  537. return -ENOMEM;
  538. len += scnprintf(buf + len, buf_len - len, "%25s%5d\n",
  539. "Total Avail Credits: ",
  540. target->credit_info->total_avail_credits);
  541. len += scnprintf(buf + len, buf_len - len, "%25s%5d\n",
  542. "Free credits :",
  543. target->credit_info->cur_free_credits);
  544. len += scnprintf(buf + len, buf_len - len,
  545. " Epid Flags Cred_norm Cred_min Credits Cred_assngd"
  546. " Seek_cred Cred_sz Cred_per_msg Cred_to_dist"
  547. " qdepth\n");
  548. list_for_each_entry(ep_list, &target->cred_dist_list, list) {
  549. print_credit_info(" %2d", endpoint);
  550. print_credit_info("%10x", dist_flags);
  551. print_credit_info("%8d", cred_norm);
  552. print_credit_info("%9d", cred_min);
  553. print_credit_info("%9d", credits);
  554. print_credit_info("%10d", cred_assngd);
  555. print_credit_info("%13d", seek_cred);
  556. print_credit_info("%12d", cred_sz);
  557. print_credit_info("%9d", cred_per_msg);
  558. print_credit_info("%14d", cred_to_dist);
  559. len += scnprintf(buf + len, buf_len - len, "%12d\n",
  560. get_queue_depth(&ep_list->htc_ep->txq));
  561. }
  562. if (len > buf_len)
  563. len = buf_len;
  564. ret_cnt = simple_read_from_buffer(user_buf, count, ppos, buf, len);
  565. kfree(buf);
  566. return ret_cnt;
  567. }
  568. static const struct file_operations fops_credit_dist_stats = {
  569. .read = read_file_credit_dist_stats,
  570. .open = ath6kl_debugfs_open,
  571. .owner = THIS_MODULE,
  572. .llseek = default_llseek,
  573. };
  574. static unsigned int print_endpoint_stat(struct htc_target *target, char *buf,
  575. unsigned int buf_len, unsigned int len,
  576. int offset, const char *name)
  577. {
  578. int i;
  579. struct htc_endpoint_stats *ep_st;
  580. u32 *counter;
  581. len += scnprintf(buf + len, buf_len - len, "%s:", name);
  582. for (i = 0; i < ENDPOINT_MAX; i++) {
  583. ep_st = &target->endpoint[i].ep_st;
  584. counter = ((u32 *) ep_st) + (offset / 4);
  585. len += scnprintf(buf + len, buf_len - len, " %u", *counter);
  586. }
  587. len += scnprintf(buf + len, buf_len - len, "\n");
  588. return len;
  589. }
  590. static ssize_t ath6kl_endpoint_stats_read(struct file *file,
  591. char __user *user_buf,
  592. size_t count, loff_t *ppos)
  593. {
  594. struct ath6kl *ar = file->private_data;
  595. struct htc_target *target = ar->htc_target;
  596. char *buf;
  597. unsigned int buf_len, len = 0;
  598. ssize_t ret_cnt;
  599. buf_len = sizeof(struct htc_endpoint_stats) / sizeof(u32) *
  600. (25 + ENDPOINT_MAX * 11);
  601. buf = kmalloc(buf_len, GFP_KERNEL);
  602. if (!buf)
  603. return -ENOMEM;
  604. #define EPSTAT(name) \
  605. len = print_endpoint_stat(target, buf, buf_len, len, \
  606. offsetof(struct htc_endpoint_stats, name), \
  607. #name)
  608. EPSTAT(cred_low_indicate);
  609. EPSTAT(tx_issued);
  610. EPSTAT(tx_pkt_bundled);
  611. EPSTAT(tx_bundles);
  612. EPSTAT(tx_dropped);
  613. EPSTAT(tx_cred_rpt);
  614. EPSTAT(cred_rpt_from_rx);
  615. EPSTAT(cred_rpt_from_other);
  616. EPSTAT(cred_rpt_ep0);
  617. EPSTAT(cred_from_rx);
  618. EPSTAT(cred_from_other);
  619. EPSTAT(cred_from_ep0);
  620. EPSTAT(cred_cosumd);
  621. EPSTAT(cred_retnd);
  622. EPSTAT(rx_pkts);
  623. EPSTAT(rx_lkahds);
  624. EPSTAT(rx_bundl);
  625. EPSTAT(rx_bundle_lkahd);
  626. EPSTAT(rx_bundle_from_hdr);
  627. EPSTAT(rx_alloc_thresh_hit);
  628. EPSTAT(rxalloc_thresh_byte);
  629. #undef EPSTAT
  630. if (len > buf_len)
  631. len = buf_len;
  632. ret_cnt = simple_read_from_buffer(user_buf, count, ppos, buf, len);
  633. kfree(buf);
  634. return ret_cnt;
  635. }
  636. static ssize_t ath6kl_endpoint_stats_write(struct file *file,
  637. const char __user *user_buf,
  638. size_t count, loff_t *ppos)
  639. {
  640. struct ath6kl *ar = file->private_data;
  641. struct htc_target *target = ar->htc_target;
  642. int ret, i;
  643. u32 val;
  644. struct htc_endpoint_stats *ep_st;
  645. ret = kstrtou32_from_user(user_buf, count, 0, &val);
  646. if (ret)
  647. return ret;
  648. if (val == 0) {
  649. for (i = 0; i < ENDPOINT_MAX; i++) {
  650. ep_st = &target->endpoint[i].ep_st;
  651. memset(ep_st, 0, sizeof(*ep_st));
  652. }
  653. }
  654. return count;
  655. }
  656. static const struct file_operations fops_endpoint_stats = {
  657. .open = ath6kl_debugfs_open,
  658. .read = ath6kl_endpoint_stats_read,
  659. .write = ath6kl_endpoint_stats_write,
  660. .owner = THIS_MODULE,
  661. .llseek = default_llseek,
  662. };
  663. static unsigned long ath6kl_get_num_reg(void)
  664. {
  665. int i;
  666. unsigned long n_reg = 0;
  667. for (i = 0; i < ARRAY_SIZE(diag_reg); i++)
  668. n_reg = n_reg +
  669. (diag_reg[i].reg_end - diag_reg[i].reg_start) / 4 + 1;
  670. return n_reg;
  671. }
  672. static bool ath6kl_dbg_is_diag_reg_valid(u32 reg_addr)
  673. {
  674. int i;
  675. for (i = 0; i < ARRAY_SIZE(diag_reg); i++) {
  676. if (reg_addr >= diag_reg[i].reg_start &&
  677. reg_addr <= diag_reg[i].reg_end)
  678. return true;
  679. }
  680. return false;
  681. }
  682. static ssize_t ath6kl_regread_read(struct file *file, char __user *user_buf,
  683. size_t count, loff_t *ppos)
  684. {
  685. struct ath6kl *ar = file->private_data;
  686. u8 buf[50];
  687. unsigned int len = 0;
  688. if (ar->debug.dbgfs_diag_reg)
  689. len += scnprintf(buf + len, sizeof(buf) - len, "0x%x\n",
  690. ar->debug.dbgfs_diag_reg);
  691. else
  692. len += scnprintf(buf + len, sizeof(buf) - len,
  693. "All diag registers\n");
  694. return simple_read_from_buffer(user_buf, count, ppos, buf, len);
  695. }
  696. static ssize_t ath6kl_regread_write(struct file *file,
  697. const char __user *user_buf,
  698. size_t count, loff_t *ppos)
  699. {
  700. struct ath6kl *ar = file->private_data;
  701. u8 buf[50];
  702. unsigned int len;
  703. unsigned long reg_addr;
  704. len = min(count, sizeof(buf) - 1);
  705. if (copy_from_user(buf, user_buf, len))
  706. return -EFAULT;
  707. buf[len] = '\0';
  708. if (strict_strtoul(buf, 0, &reg_addr))
  709. return -EINVAL;
  710. if ((reg_addr % 4) != 0)
  711. return -EINVAL;
  712. if (reg_addr && !ath6kl_dbg_is_diag_reg_valid(reg_addr))
  713. return -EINVAL;
  714. ar->debug.dbgfs_diag_reg = reg_addr;
  715. return count;
  716. }
  717. static const struct file_operations fops_diag_reg_read = {
  718. .read = ath6kl_regread_read,
  719. .write = ath6kl_regread_write,
  720. .open = ath6kl_debugfs_open,
  721. .owner = THIS_MODULE,
  722. .llseek = default_llseek,
  723. };
  724. static int ath6kl_regdump_open(struct inode *inode, struct file *file)
  725. {
  726. struct ath6kl *ar = inode->i_private;
  727. u8 *buf;
  728. unsigned long int reg_len;
  729. unsigned int len = 0, n_reg;
  730. u32 addr;
  731. __le32 reg_val;
  732. int i, status;
  733. /* Dump all the registers if no register is specified */
  734. if (!ar->debug.dbgfs_diag_reg)
  735. n_reg = ath6kl_get_num_reg();
  736. else
  737. n_reg = 1;
  738. reg_len = n_reg * REG_OUTPUT_LEN_PER_LINE;
  739. if (n_reg > 1)
  740. reg_len += REGTYPE_STR_LEN;
  741. buf = vmalloc(reg_len);
  742. if (!buf)
  743. return -ENOMEM;
  744. if (n_reg == 1) {
  745. addr = ar->debug.dbgfs_diag_reg;
  746. status = ath6kl_diag_read32(ar,
  747. TARG_VTOP(ar->target_type, addr),
  748. (u32 *)&reg_val);
  749. if (status)
  750. goto fail_reg_read;
  751. len += scnprintf(buf + len, reg_len - len,
  752. "0x%06x 0x%08x\n", addr, le32_to_cpu(reg_val));
  753. goto done;
  754. }
  755. for (i = 0; i < ARRAY_SIZE(diag_reg); i++) {
  756. len += scnprintf(buf + len, reg_len - len,
  757. "%s\n", diag_reg[i].reg_info);
  758. for (addr = diag_reg[i].reg_start;
  759. addr <= diag_reg[i].reg_end; addr += 4) {
  760. status = ath6kl_diag_read32(ar,
  761. TARG_VTOP(ar->target_type, addr),
  762. (u32 *)&reg_val);
  763. if (status)
  764. goto fail_reg_read;
  765. len += scnprintf(buf + len, reg_len - len,
  766. "0x%06x 0x%08x\n",
  767. addr, le32_to_cpu(reg_val));
  768. }
  769. }
  770. done:
  771. file->private_data = buf;
  772. return 0;
  773. fail_reg_read:
  774. ath6kl_warn("Unable to read memory:%u\n", addr);
  775. vfree(buf);
  776. return -EIO;
  777. }
  778. static ssize_t ath6kl_regdump_read(struct file *file, char __user *user_buf,
  779. size_t count, loff_t *ppos)
  780. {
  781. u8 *buf = file->private_data;
  782. return simple_read_from_buffer(user_buf, count, ppos, buf, strlen(buf));
  783. }
  784. static int ath6kl_regdump_release(struct inode *inode, struct file *file)
  785. {
  786. vfree(file->private_data);
  787. return 0;
  788. }
  789. static const struct file_operations fops_reg_dump = {
  790. .open = ath6kl_regdump_open,
  791. .read = ath6kl_regdump_read,
  792. .release = ath6kl_regdump_release,
  793. .owner = THIS_MODULE,
  794. .llseek = default_llseek,
  795. };
  796. static ssize_t ath6kl_lrssi_roam_write(struct file *file,
  797. const char __user *user_buf,
  798. size_t count, loff_t *ppos)
  799. {
  800. struct ath6kl *ar = file->private_data;
  801. unsigned long lrssi_roam_threshold;
  802. char buf[32];
  803. ssize_t len;
  804. len = min(count, sizeof(buf) - 1);
  805. if (copy_from_user(buf, user_buf, len))
  806. return -EFAULT;
  807. buf[len] = '\0';
  808. if (strict_strtoul(buf, 0, &lrssi_roam_threshold))
  809. return -EINVAL;
  810. ar->lrssi_roam_threshold = lrssi_roam_threshold;
  811. ath6kl_wmi_set_roam_lrssi_cmd(ar->wmi, ar->lrssi_roam_threshold);
  812. return count;
  813. }
  814. static ssize_t ath6kl_lrssi_roam_read(struct file *file,
  815. char __user *user_buf,
  816. size_t count, loff_t *ppos)
  817. {
  818. struct ath6kl *ar = file->private_data;
  819. char buf[32];
  820. unsigned int len;
  821. len = snprintf(buf, sizeof(buf), "%u\n", ar->lrssi_roam_threshold);
  822. return simple_read_from_buffer(user_buf, count, ppos, buf, len);
  823. }
  824. static const struct file_operations fops_lrssi_roam_threshold = {
  825. .read = ath6kl_lrssi_roam_read,
  826. .write = ath6kl_lrssi_roam_write,
  827. .open = ath6kl_debugfs_open,
  828. .owner = THIS_MODULE,
  829. .llseek = default_llseek,
  830. };
  831. static ssize_t ath6kl_regwrite_read(struct file *file,
  832. char __user *user_buf,
  833. size_t count, loff_t *ppos)
  834. {
  835. struct ath6kl *ar = file->private_data;
  836. u8 buf[32];
  837. unsigned int len = 0;
  838. len = scnprintf(buf, sizeof(buf), "Addr: 0x%x Val: 0x%x\n",
  839. ar->debug.diag_reg_addr_wr, ar->debug.diag_reg_val_wr);
  840. return simple_read_from_buffer(user_buf, count, ppos, buf, len);
  841. }
  842. static ssize_t ath6kl_regwrite_write(struct file *file,
  843. const char __user *user_buf,
  844. size_t count, loff_t *ppos)
  845. {
  846. struct ath6kl *ar = file->private_data;
  847. char buf[32];
  848. char *sptr, *token;
  849. unsigned int len = 0;
  850. u32 reg_addr, reg_val;
  851. len = min(count, sizeof(buf) - 1);
  852. if (copy_from_user(buf, user_buf, len))
  853. return -EFAULT;
  854. buf[len] = '\0';
  855. sptr = buf;
  856. token = strsep(&sptr, "=");
  857. if (!token)
  858. return -EINVAL;
  859. if (kstrtou32(token, 0, &reg_addr))
  860. return -EINVAL;
  861. if (!ath6kl_dbg_is_diag_reg_valid(reg_addr))
  862. return -EINVAL;
  863. if (kstrtou32(sptr, 0, &reg_val))
  864. return -EINVAL;
  865. ar->debug.diag_reg_addr_wr = reg_addr;
  866. ar->debug.diag_reg_val_wr = reg_val;
  867. if (ath6kl_diag_write32(ar, ar->debug.diag_reg_addr_wr,
  868. cpu_to_le32(ar->debug.diag_reg_val_wr)))
  869. return -EIO;
  870. return count;
  871. }
  872. static const struct file_operations fops_diag_reg_write = {
  873. .read = ath6kl_regwrite_read,
  874. .write = ath6kl_regwrite_write,
  875. .open = ath6kl_debugfs_open,
  876. .owner = THIS_MODULE,
  877. .llseek = default_llseek,
  878. };
  879. int ath6kl_debug_roam_tbl_event(struct ath6kl *ar, const void *buf,
  880. size_t len)
  881. {
  882. const struct wmi_target_roam_tbl *tbl;
  883. u16 num_entries;
  884. if (len < sizeof(*tbl))
  885. return -EINVAL;
  886. tbl = (const struct wmi_target_roam_tbl *) buf;
  887. num_entries = le16_to_cpu(tbl->num_entries);
  888. if (sizeof(*tbl) + num_entries * sizeof(struct wmi_bss_roam_info) >
  889. len)
  890. return -EINVAL;
  891. if (ar->debug.roam_tbl == NULL ||
  892. ar->debug.roam_tbl_len < (unsigned int) len) {
  893. kfree(ar->debug.roam_tbl);
  894. ar->debug.roam_tbl = kmalloc(len, GFP_ATOMIC);
  895. if (ar->debug.roam_tbl == NULL)
  896. return -ENOMEM;
  897. }
  898. memcpy(ar->debug.roam_tbl, buf, len);
  899. ar->debug.roam_tbl_len = len;
  900. if (test_bit(ROAM_TBL_PEND, &ar->flag)) {
  901. clear_bit(ROAM_TBL_PEND, &ar->flag);
  902. wake_up(&ar->event_wq);
  903. }
  904. return 0;
  905. }
  906. static ssize_t ath6kl_roam_table_read(struct file *file, char __user *user_buf,
  907. size_t count, loff_t *ppos)
  908. {
  909. struct ath6kl *ar = file->private_data;
  910. int ret;
  911. long left;
  912. struct wmi_target_roam_tbl *tbl;
  913. u16 num_entries, i;
  914. char *buf;
  915. unsigned int len, buf_len;
  916. ssize_t ret_cnt;
  917. if (down_interruptible(&ar->sem))
  918. return -EBUSY;
  919. set_bit(ROAM_TBL_PEND, &ar->flag);
  920. ret = ath6kl_wmi_get_roam_tbl_cmd(ar->wmi);
  921. if (ret) {
  922. up(&ar->sem);
  923. return ret;
  924. }
  925. left = wait_event_interruptible_timeout(
  926. ar->event_wq, !test_bit(ROAM_TBL_PEND, &ar->flag), WMI_TIMEOUT);
  927. up(&ar->sem);
  928. if (left <= 0)
  929. return -ETIMEDOUT;
  930. if (ar->debug.roam_tbl == NULL)
  931. return -ENOMEM;
  932. tbl = (struct wmi_target_roam_tbl *) ar->debug.roam_tbl;
  933. num_entries = le16_to_cpu(tbl->num_entries);
  934. buf_len = 100 + num_entries * 100;
  935. buf = kzalloc(buf_len, GFP_KERNEL);
  936. if (buf == NULL)
  937. return -ENOMEM;
  938. len = 0;
  939. len += scnprintf(buf + len, buf_len - len,
  940. "roam_mode=%u\n\n"
  941. "# roam_util bssid rssi rssidt last_rssi util bias\n",
  942. le16_to_cpu(tbl->roam_mode));
  943. for (i = 0; i < num_entries; i++) {
  944. struct wmi_bss_roam_info *info = &tbl->info[i];
  945. len += scnprintf(buf + len, buf_len - len,
  946. "%d %pM %d %d %d %d %d\n",
  947. a_sle32_to_cpu(info->roam_util), info->bssid,
  948. info->rssi, info->rssidt, info->last_rssi,
  949. info->util, info->bias);
  950. }
  951. if (len > buf_len)
  952. len = buf_len;
  953. ret_cnt = simple_read_from_buffer(user_buf, count, ppos, buf, len);
  954. kfree(buf);
  955. return ret_cnt;
  956. }
  957. static const struct file_operations fops_roam_table = {
  958. .read = ath6kl_roam_table_read,
  959. .open = ath6kl_debugfs_open,
  960. .owner = THIS_MODULE,
  961. .llseek = default_llseek,
  962. };
  963. static ssize_t ath6kl_force_roam_write(struct file *file,
  964. const char __user *user_buf,
  965. size_t count, loff_t *ppos)
  966. {
  967. struct ath6kl *ar = file->private_data;
  968. int ret;
  969. char buf[20];
  970. size_t len;
  971. u8 bssid[ETH_ALEN];
  972. int i;
  973. int addr[ETH_ALEN];
  974. len = min(count, sizeof(buf) - 1);
  975. if (copy_from_user(buf, user_buf, len))
  976. return -EFAULT;
  977. buf[len] = '\0';
  978. if (sscanf(buf, "%02x:%02x:%02x:%02x:%02x:%02x",
  979. &addr[0], &addr[1], &addr[2], &addr[3], &addr[4], &addr[5])
  980. != ETH_ALEN)
  981. return -EINVAL;
  982. for (i = 0; i < ETH_ALEN; i++)
  983. bssid[i] = addr[i];
  984. ret = ath6kl_wmi_force_roam_cmd(ar->wmi, bssid);
  985. if (ret)
  986. return ret;
  987. return count;
  988. }
  989. static const struct file_operations fops_force_roam = {
  990. .write = ath6kl_force_roam_write,
  991. .open = ath6kl_debugfs_open,
  992. .owner = THIS_MODULE,
  993. .llseek = default_llseek,
  994. };
  995. static ssize_t ath6kl_roam_mode_write(struct file *file,
  996. const char __user *user_buf,
  997. size_t count, loff_t *ppos)
  998. {
  999. struct ath6kl *ar = file->private_data;
  1000. int ret;
  1001. char buf[20];
  1002. size_t len;
  1003. enum wmi_roam_mode mode;
  1004. len = min(count, sizeof(buf) - 1);
  1005. if (copy_from_user(buf, user_buf, len))
  1006. return -EFAULT;
  1007. buf[len] = '\0';
  1008. if (len > 0 && buf[len - 1] == '\n')
  1009. buf[len - 1] = '\0';
  1010. if (strcasecmp(buf, "default") == 0)
  1011. mode = WMI_DEFAULT_ROAM_MODE;
  1012. else if (strcasecmp(buf, "bssbias") == 0)
  1013. mode = WMI_HOST_BIAS_ROAM_MODE;
  1014. else if (strcasecmp(buf, "lock") == 0)
  1015. mode = WMI_LOCK_BSS_MODE;
  1016. else
  1017. return -EINVAL;
  1018. ret = ath6kl_wmi_set_roam_mode_cmd(ar->wmi, mode);
  1019. if (ret)
  1020. return ret;
  1021. return count;
  1022. }
  1023. static const struct file_operations fops_roam_mode = {
  1024. .write = ath6kl_roam_mode_write,
  1025. .open = ath6kl_debugfs_open,
  1026. .owner = THIS_MODULE,
  1027. .llseek = default_llseek,
  1028. };
  1029. void ath6kl_debug_set_keepalive(struct ath6kl *ar, u8 keepalive)
  1030. {
  1031. ar->debug.keepalive = keepalive;
  1032. }
  1033. static ssize_t ath6kl_keepalive_read(struct file *file, char __user *user_buf,
  1034. size_t count, loff_t *ppos)
  1035. {
  1036. struct ath6kl *ar = file->private_data;
  1037. char buf[16];
  1038. int len;
  1039. len = snprintf(buf, sizeof(buf), "%u\n", ar->debug.keepalive);
  1040. return simple_read_from_buffer(user_buf, count, ppos, buf, len);
  1041. }
  1042. static ssize_t ath6kl_keepalive_write(struct file *file,
  1043. const char __user *user_buf,
  1044. size_t count, loff_t *ppos)
  1045. {
  1046. struct ath6kl *ar = file->private_data;
  1047. int ret;
  1048. u8 val;
  1049. ret = kstrtou8_from_user(user_buf, count, 0, &val);
  1050. if (ret)
  1051. return ret;
  1052. ret = ath6kl_wmi_set_keepalive_cmd(ar->wmi, 0, val);
  1053. if (ret)
  1054. return ret;
  1055. return count;
  1056. }
  1057. static const struct file_operations fops_keepalive = {
  1058. .open = ath6kl_debugfs_open,
  1059. .read = ath6kl_keepalive_read,
  1060. .write = ath6kl_keepalive_write,
  1061. .owner = THIS_MODULE,
  1062. .llseek = default_llseek,
  1063. };
  1064. void ath6kl_debug_set_disconnect_timeout(struct ath6kl *ar, u8 timeout)
  1065. {
  1066. ar->debug.disc_timeout = timeout;
  1067. }
  1068. static ssize_t ath6kl_disconnect_timeout_read(struct file *file,
  1069. char __user *user_buf,
  1070. size_t count, loff_t *ppos)
  1071. {
  1072. struct ath6kl *ar = file->private_data;
  1073. char buf[16];
  1074. int len;
  1075. len = snprintf(buf, sizeof(buf), "%u\n", ar->debug.disc_timeout);
  1076. return simple_read_from_buffer(user_buf, count, ppos, buf, len);
  1077. }
  1078. static ssize_t ath6kl_disconnect_timeout_write(struct file *file,
  1079. const char __user *user_buf,
  1080. size_t count, loff_t *ppos)
  1081. {
  1082. struct ath6kl *ar = file->private_data;
  1083. int ret;
  1084. u8 val;
  1085. ret = kstrtou8_from_user(user_buf, count, 0, &val);
  1086. if (ret)
  1087. return ret;
  1088. ret = ath6kl_wmi_disctimeout_cmd(ar->wmi, 0, val);
  1089. if (ret)
  1090. return ret;
  1091. return count;
  1092. }
  1093. static const struct file_operations fops_disconnect_timeout = {
  1094. .open = ath6kl_debugfs_open,
  1095. .read = ath6kl_disconnect_timeout_read,
  1096. .write = ath6kl_disconnect_timeout_write,
  1097. .owner = THIS_MODULE,
  1098. .llseek = default_llseek,
  1099. };
  1100. static ssize_t ath6kl_create_qos_write(struct file *file,
  1101. const char __user *user_buf,
  1102. size_t count, loff_t *ppos)
  1103. {
  1104. struct ath6kl *ar = file->private_data;
  1105. struct ath6kl_vif *vif;
  1106. char buf[200];
  1107. ssize_t len;
  1108. char *sptr, *token;
  1109. struct wmi_create_pstream_cmd pstream;
  1110. u32 val32;
  1111. u16 val16;
  1112. vif = ath6kl_vif_first(ar);
  1113. if (!vif)
  1114. return -EIO;
  1115. len = min(count, sizeof(buf) - 1);
  1116. if (copy_from_user(buf, user_buf, len))
  1117. return -EFAULT;
  1118. buf[len] = '\0';
  1119. sptr = buf;
  1120. token = strsep(&sptr, " ");
  1121. if (!token)
  1122. return -EINVAL;
  1123. if (kstrtou8(token, 0, &pstream.user_pri))
  1124. return -EINVAL;
  1125. token = strsep(&sptr, " ");
  1126. if (!token)
  1127. return -EINVAL;
  1128. if (kstrtou8(token, 0, &pstream.traffic_direc))
  1129. return -EINVAL;
  1130. token = strsep(&sptr, " ");
  1131. if (!token)
  1132. return -EINVAL;
  1133. if (kstrtou8(token, 0, &pstream.traffic_class))
  1134. return -EINVAL;
  1135. token = strsep(&sptr, " ");
  1136. if (!token)
  1137. return -EINVAL;
  1138. if (kstrtou8(token, 0, &pstream.traffic_type))
  1139. return -EINVAL;
  1140. token = strsep(&sptr, " ");
  1141. if (!token)
  1142. return -EINVAL;
  1143. if (kstrtou8(token, 0, &pstream.voice_psc_cap))
  1144. return -EINVAL;
  1145. token = strsep(&sptr, " ");
  1146. if (!token)
  1147. return -EINVAL;
  1148. if (kstrtou32(token, 0, &val32))
  1149. return -EINVAL;
  1150. pstream.min_service_int = cpu_to_le32(val32);
  1151. token = strsep(&sptr, " ");
  1152. if (!token)
  1153. return -EINVAL;
  1154. if (kstrtou32(token, 0, &val32))
  1155. return -EINVAL;
  1156. pstream.max_service_int = cpu_to_le32(val32);
  1157. token = strsep(&sptr, " ");
  1158. if (!token)
  1159. return -EINVAL;
  1160. if (kstrtou32(token, 0, &val32))
  1161. return -EINVAL;
  1162. pstream.inactivity_int = cpu_to_le32(val32);
  1163. token = strsep(&sptr, " ");
  1164. if (!token)
  1165. return -EINVAL;
  1166. if (kstrtou32(token, 0, &val32))
  1167. return -EINVAL;
  1168. pstream.suspension_int = cpu_to_le32(val32);
  1169. token = strsep(&sptr, " ");
  1170. if (!token)
  1171. return -EINVAL;
  1172. if (kstrtou32(token, 0, &val32))
  1173. return -EINVAL;
  1174. pstream.service_start_time = cpu_to_le32(val32);
  1175. token = strsep(&sptr, " ");
  1176. if (!token)
  1177. return -EINVAL;
  1178. if (kstrtou8(token, 0, &pstream.tsid))
  1179. return -EINVAL;
  1180. token = strsep(&sptr, " ");
  1181. if (!token)
  1182. return -EINVAL;
  1183. if (kstrtou16(token, 0, &val16))
  1184. return -EINVAL;
  1185. pstream.nominal_msdu = cpu_to_le16(val16);
  1186. token = strsep(&sptr, " ");
  1187. if (!token)
  1188. return -EINVAL;
  1189. if (kstrtou16(token, 0, &val16))
  1190. return -EINVAL;
  1191. pstream.max_msdu = cpu_to_le16(val16);
  1192. token = strsep(&sptr, " ");
  1193. if (!token)
  1194. return -EINVAL;
  1195. if (kstrtou32(token, 0, &val32))
  1196. return -EINVAL;
  1197. pstream.min_data_rate = cpu_to_le32(val32);
  1198. token = strsep(&sptr, " ");
  1199. if (!token)
  1200. return -EINVAL;
  1201. if (kstrtou32(token, 0, &val32))
  1202. return -EINVAL;
  1203. pstream.mean_data_rate = cpu_to_le32(val32);
  1204. token = strsep(&sptr, " ");
  1205. if (!token)
  1206. return -EINVAL;
  1207. if (kstrtou32(token, 0, &val32))
  1208. return -EINVAL;
  1209. pstream.peak_data_rate = cpu_to_le32(val32);
  1210. token = strsep(&sptr, " ");
  1211. if (!token)
  1212. return -EINVAL;
  1213. if (kstrtou32(token, 0, &val32))
  1214. return -EINVAL;
  1215. pstream.max_burst_size = cpu_to_le32(val32);
  1216. token = strsep(&sptr, " ");
  1217. if (!token)
  1218. return -EINVAL;
  1219. if (kstrtou32(token, 0, &val32))
  1220. return -EINVAL;
  1221. pstream.delay_bound = cpu_to_le32(val32);
  1222. token = strsep(&sptr, " ");
  1223. if (!token)
  1224. return -EINVAL;
  1225. if (kstrtou32(token, 0, &val32))
  1226. return -EINVAL;
  1227. pstream.min_phy_rate = cpu_to_le32(val32);
  1228. token = strsep(&sptr, " ");
  1229. if (!token)
  1230. return -EINVAL;
  1231. if (kstrtou32(token, 0, &val32))
  1232. return -EINVAL;
  1233. pstream.sba = cpu_to_le32(val32);
  1234. token = strsep(&sptr, " ");
  1235. if (!token)
  1236. return -EINVAL;
  1237. if (kstrtou32(token, 0, &val32))
  1238. return -EINVAL;
  1239. pstream.medium_time = cpu_to_le32(val32);
  1240. pstream.nominal_phy = le32_to_cpu(pstream.min_phy_rate) / 1000000;
  1241. ath6kl_wmi_create_pstream_cmd(ar->wmi, vif->fw_vif_idx, &pstream);
  1242. return count;
  1243. }
  1244. static const struct file_operations fops_create_qos = {
  1245. .write = ath6kl_create_qos_write,
  1246. .open = ath6kl_debugfs_open,
  1247. .owner = THIS_MODULE,
  1248. .llseek = default_llseek,
  1249. };
  1250. static ssize_t ath6kl_delete_qos_write(struct file *file,
  1251. const char __user *user_buf,
  1252. size_t count, loff_t *ppos)
  1253. {
  1254. struct ath6kl *ar = file->private_data;
  1255. struct ath6kl_vif *vif;
  1256. char buf[100];
  1257. ssize_t len;
  1258. char *sptr, *token;
  1259. u8 traffic_class;
  1260. u8 tsid;
  1261. vif = ath6kl_vif_first(ar);
  1262. if (!vif)
  1263. return -EIO;
  1264. len = min(count, sizeof(buf) - 1);
  1265. if (copy_from_user(buf, user_buf, len))
  1266. return -EFAULT;
  1267. buf[len] = '\0';
  1268. sptr = buf;
  1269. token = strsep(&sptr, " ");
  1270. if (!token)
  1271. return -EINVAL;
  1272. if (kstrtou8(token, 0, &traffic_class))
  1273. return -EINVAL;
  1274. token = strsep(&sptr, " ");
  1275. if (!token)
  1276. return -EINVAL;
  1277. if (kstrtou8(token, 0, &tsid))
  1278. return -EINVAL;
  1279. ath6kl_wmi_delete_pstream_cmd(ar->wmi, vif->fw_vif_idx,
  1280. traffic_class, tsid);
  1281. return count;
  1282. }
  1283. static const struct file_operations fops_delete_qos = {
  1284. .write = ath6kl_delete_qos_write,
  1285. .open = ath6kl_debugfs_open,
  1286. .owner = THIS_MODULE,
  1287. .llseek = default_llseek,
  1288. };
  1289. static ssize_t ath6kl_bgscan_int_write(struct file *file,
  1290. const char __user *user_buf,
  1291. size_t count, loff_t *ppos)
  1292. {
  1293. struct ath6kl *ar = file->private_data;
  1294. u16 bgscan_int;
  1295. char buf[32];
  1296. ssize_t len;
  1297. len = min(count, sizeof(buf) - 1);
  1298. if (copy_from_user(buf, user_buf, len))
  1299. return -EFAULT;
  1300. buf[len] = '\0';
  1301. if (kstrtou16(buf, 0, &bgscan_int))
  1302. return -EINVAL;
  1303. if (bgscan_int == 0)
  1304. bgscan_int = 0xffff;
  1305. ath6kl_wmi_scanparams_cmd(ar->wmi, 0, 0, 0, bgscan_int, 0, 0, 0, 3,
  1306. 0, 0, 0);
  1307. return count;
  1308. }
  1309. static const struct file_operations fops_bgscan_int = {
  1310. .write = ath6kl_bgscan_int_write,
  1311. .open = ath6kl_debugfs_open,
  1312. .owner = THIS_MODULE,
  1313. .llseek = default_llseek,
  1314. };
  1315. static ssize_t ath6kl_listen_int_write(struct file *file,
  1316. const char __user *user_buf,
  1317. size_t count, loff_t *ppos)
  1318. {
  1319. struct ath6kl *ar = file->private_data;
  1320. struct ath6kl_vif *vif;
  1321. u16 listen_interval;
  1322. char buf[32];
  1323. ssize_t len;
  1324. vif = ath6kl_vif_first(ar);
  1325. if (!vif)
  1326. return -EIO;
  1327. len = min(count, sizeof(buf) - 1);
  1328. if (copy_from_user(buf, user_buf, len))
  1329. return -EFAULT;
  1330. buf[len] = '\0';
  1331. if (kstrtou16(buf, 0, &listen_interval))
  1332. return -EINVAL;
  1333. if ((listen_interval < 1) || (listen_interval > 50))
  1334. return -EINVAL;
  1335. ar->listen_intvl_b = listen_interval;
  1336. ath6kl_wmi_listeninterval_cmd(ar->wmi, vif->fw_vif_idx, 0,
  1337. ar->listen_intvl_b);
  1338. return count;
  1339. }
  1340. static ssize_t ath6kl_listen_int_read(struct file *file,
  1341. char __user *user_buf,
  1342. size_t count, loff_t *ppos)
  1343. {
  1344. struct ath6kl *ar = file->private_data;
  1345. char buf[32];
  1346. int len;
  1347. len = scnprintf(buf, sizeof(buf), "%u\n", ar->listen_intvl_b);
  1348. return simple_read_from_buffer(user_buf, count, ppos, buf, len);
  1349. }
  1350. static const struct file_operations fops_listen_int = {
  1351. .read = ath6kl_listen_int_read,
  1352. .write = ath6kl_listen_int_write,
  1353. .open = ath6kl_debugfs_open,
  1354. .owner = THIS_MODULE,
  1355. .llseek = default_llseek,
  1356. };
  1357. static ssize_t ath6kl_power_params_write(struct file *file,
  1358. const char __user *user_buf,
  1359. size_t count, loff_t *ppos)
  1360. {
  1361. struct ath6kl *ar = file->private_data;
  1362. u8 buf[100];
  1363. unsigned int len = 0;
  1364. char *sptr, *token;
  1365. u16 idle_period, ps_poll_num, dtim,
  1366. tx_wakeup, num_tx;
  1367. len = min(count, sizeof(buf) - 1);
  1368. if (copy_from_user(buf, user_buf, len))
  1369. return -EFAULT;
  1370. buf[len] = '\0';
  1371. sptr = buf;
  1372. token = strsep(&sptr, " ");
  1373. if (!token)
  1374. return -EINVAL;
  1375. if (kstrtou16(token, 0, &idle_period))
  1376. return -EINVAL;
  1377. token = strsep(&sptr, " ");
  1378. if (!token)
  1379. return -EINVAL;
  1380. if (kstrtou16(token, 0, &ps_poll_num))
  1381. return -EINVAL;
  1382. token = strsep(&sptr, " ");
  1383. if (!token)
  1384. return -EINVAL;
  1385. if (kstrtou16(token, 0, &dtim))
  1386. return -EINVAL;
  1387. token = strsep(&sptr, " ");
  1388. if (!token)
  1389. return -EINVAL;
  1390. if (kstrtou16(token, 0, &tx_wakeup))
  1391. return -EINVAL;
  1392. token = strsep(&sptr, " ");
  1393. if (!token)
  1394. return -EINVAL;
  1395. if (kstrtou16(token, 0, &num_tx))
  1396. return -EINVAL;
  1397. ath6kl_wmi_pmparams_cmd(ar->wmi, 0, idle_period, ps_poll_num,
  1398. dtim, tx_wakeup, num_tx, 0);
  1399. return count;
  1400. }
  1401. static const struct file_operations fops_power_params = {
  1402. .write = ath6kl_power_params_write,
  1403. .open = ath6kl_debugfs_open,
  1404. .owner = THIS_MODULE,
  1405. .llseek = default_llseek,
  1406. };
  1407. int ath6kl_debug_init(struct ath6kl *ar)
  1408. {
  1409. skb_queue_head_init(&ar->debug.fwlog_queue);
  1410. init_completion(&ar->debug.fwlog_completion);
  1411. /*
  1412. * Actually we are lying here but don't know how to read the mask
  1413. * value from the firmware.
  1414. */
  1415. ar->debug.fwlog_mask = 0;
  1416. ar->debugfs_phy = debugfs_create_dir("ath6kl",
  1417. ar->wiphy->debugfsdir);
  1418. if (!ar->debugfs_phy)
  1419. return -ENOMEM;
  1420. debugfs_create_file("tgt_stats", S_IRUSR, ar->debugfs_phy, ar,
  1421. &fops_tgt_stats);
  1422. debugfs_create_file("credit_dist_stats", S_IRUSR, ar->debugfs_phy, ar,
  1423. &fops_credit_dist_stats);
  1424. debugfs_create_file("endpoint_stats", S_IRUSR | S_IWUSR,
  1425. ar->debugfs_phy, ar, &fops_endpoint_stats);
  1426. debugfs_create_file("fwlog", S_IRUSR, ar->debugfs_phy, ar,
  1427. &fops_fwlog);
  1428. debugfs_create_file("fwlog_block", S_IRUSR, ar->debugfs_phy, ar,
  1429. &fops_fwlog_block);
  1430. debugfs_create_file("fwlog_mask", S_IRUSR | S_IWUSR, ar->debugfs_phy,
  1431. ar, &fops_fwlog_mask);
  1432. debugfs_create_file("reg_addr", S_IRUSR | S_IWUSR, ar->debugfs_phy, ar,
  1433. &fops_diag_reg_read);
  1434. debugfs_create_file("reg_dump", S_IRUSR, ar->debugfs_phy, ar,
  1435. &fops_reg_dump);
  1436. debugfs_create_file("lrssi_roam_threshold", S_IRUSR | S_IWUSR,
  1437. ar->debugfs_phy, ar, &fops_lrssi_roam_threshold);
  1438. debugfs_create_file("reg_write", S_IRUSR | S_IWUSR,
  1439. ar->debugfs_phy, ar, &fops_diag_reg_write);
  1440. debugfs_create_file("war_stats", S_IRUSR, ar->debugfs_phy, ar,
  1441. &fops_war_stats);
  1442. debugfs_create_file("roam_table", S_IRUSR, ar->debugfs_phy, ar,
  1443. &fops_roam_table);
  1444. debugfs_create_file("force_roam", S_IWUSR, ar->debugfs_phy, ar,
  1445. &fops_force_roam);
  1446. debugfs_create_file("roam_mode", S_IWUSR, ar->debugfs_phy, ar,
  1447. &fops_roam_mode);
  1448. debugfs_create_file("keepalive", S_IRUSR | S_IWUSR, ar->debugfs_phy, ar,
  1449. &fops_keepalive);
  1450. debugfs_create_file("disconnect_timeout", S_IRUSR | S_IWUSR,
  1451. ar->debugfs_phy, ar, &fops_disconnect_timeout);
  1452. debugfs_create_file("create_qos", S_IWUSR, ar->debugfs_phy, ar,
  1453. &fops_create_qos);
  1454. debugfs_create_file("delete_qos", S_IWUSR, ar->debugfs_phy, ar,
  1455. &fops_delete_qos);
  1456. debugfs_create_file("bgscan_interval", S_IWUSR,
  1457. ar->debugfs_phy, ar, &fops_bgscan_int);
  1458. debugfs_create_file("listen_interval", S_IRUSR | S_IWUSR,
  1459. ar->debugfs_phy, ar, &fops_listen_int);
  1460. debugfs_create_file("power_params", S_IWUSR, ar->debugfs_phy, ar,
  1461. &fops_power_params);
  1462. return 0;
  1463. }
  1464. void ath6kl_debug_cleanup(struct ath6kl *ar)
  1465. {
  1466. skb_queue_purge(&ar->debug.fwlog_queue);
  1467. kfree(ar->debug.roam_tbl);
  1468. }
  1469. #endif