debug.c 43 KB

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