debug.c 44 KB

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