debug.c 42 KB

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