debug.c 39 KB

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