debug.c 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809
  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. if (len > buf_len)
  504. len = buf_len;
  505. ret_cnt = simple_read_from_buffer(user_buf, count, ppos, buf, len);
  506. kfree(buf);
  507. return ret_cnt;
  508. }
  509. static const struct file_operations fops_tgt_stats = {
  510. .read = read_file_tgt_stats,
  511. .open = simple_open,
  512. .owner = THIS_MODULE,
  513. .llseek = default_llseek,
  514. };
  515. #define print_credit_info(fmt_str, ep_list_field) \
  516. (len += scnprintf(buf + len, buf_len - len, fmt_str, \
  517. ep_list->ep_list_field))
  518. #define CREDIT_INFO_DISPLAY_STRING_LEN 200
  519. #define CREDIT_INFO_LEN 128
  520. static ssize_t read_file_credit_dist_stats(struct file *file,
  521. char __user *user_buf,
  522. size_t count, loff_t *ppos)
  523. {
  524. struct ath6kl *ar = file->private_data;
  525. struct htc_target *target = ar->htc_target;
  526. struct htc_endpoint_credit_dist *ep_list;
  527. char *buf;
  528. unsigned int buf_len, len = 0;
  529. ssize_t ret_cnt;
  530. buf_len = CREDIT_INFO_DISPLAY_STRING_LEN +
  531. get_queue_depth(&target->cred_dist_list) * CREDIT_INFO_LEN;
  532. buf = kzalloc(buf_len, GFP_KERNEL);
  533. if (!buf)
  534. return -ENOMEM;
  535. len += scnprintf(buf + len, buf_len - len, "%25s%5d\n",
  536. "Total Avail Credits: ",
  537. target->credit_info->total_avail_credits);
  538. len += scnprintf(buf + len, buf_len - len, "%25s%5d\n",
  539. "Free credits :",
  540. target->credit_info->cur_free_credits);
  541. len += scnprintf(buf + len, buf_len - len,
  542. " Epid Flags Cred_norm Cred_min Credits Cred_assngd"
  543. " Seek_cred Cred_sz Cred_per_msg Cred_to_dist"
  544. " qdepth\n");
  545. list_for_each_entry(ep_list, &target->cred_dist_list, list) {
  546. print_credit_info(" %2d", endpoint);
  547. print_credit_info("%10x", dist_flags);
  548. print_credit_info("%8d", cred_norm);
  549. print_credit_info("%9d", cred_min);
  550. print_credit_info("%9d", credits);
  551. print_credit_info("%10d", cred_assngd);
  552. print_credit_info("%13d", seek_cred);
  553. print_credit_info("%12d", cred_sz);
  554. print_credit_info("%9d", cred_per_msg);
  555. print_credit_info("%14d", cred_to_dist);
  556. len += scnprintf(buf + len, buf_len - len, "%12d\n",
  557. get_queue_depth(&ep_list->htc_ep->txq));
  558. }
  559. if (len > buf_len)
  560. len = buf_len;
  561. ret_cnt = simple_read_from_buffer(user_buf, count, ppos, buf, len);
  562. kfree(buf);
  563. return ret_cnt;
  564. }
  565. static const struct file_operations fops_credit_dist_stats = {
  566. .read = read_file_credit_dist_stats,
  567. .open = simple_open,
  568. .owner = THIS_MODULE,
  569. .llseek = default_llseek,
  570. };
  571. static unsigned int print_endpoint_stat(struct htc_target *target, char *buf,
  572. unsigned int buf_len, unsigned int len,
  573. int offset, const char *name)
  574. {
  575. int i;
  576. struct htc_endpoint_stats *ep_st;
  577. u32 *counter;
  578. len += scnprintf(buf + len, buf_len - len, "%s:", name);
  579. for (i = 0; i < ENDPOINT_MAX; i++) {
  580. ep_st = &target->endpoint[i].ep_st;
  581. counter = ((u32 *) ep_st) + (offset / 4);
  582. len += scnprintf(buf + len, buf_len - len, " %u", *counter);
  583. }
  584. len += scnprintf(buf + len, buf_len - len, "\n");
  585. return len;
  586. }
  587. static ssize_t ath6kl_endpoint_stats_read(struct file *file,
  588. char __user *user_buf,
  589. size_t count, loff_t *ppos)
  590. {
  591. struct ath6kl *ar = file->private_data;
  592. struct htc_target *target = ar->htc_target;
  593. char *buf;
  594. unsigned int buf_len, len = 0;
  595. ssize_t ret_cnt;
  596. buf_len = sizeof(struct htc_endpoint_stats) / sizeof(u32) *
  597. (25 + ENDPOINT_MAX * 11);
  598. buf = kmalloc(buf_len, GFP_KERNEL);
  599. if (!buf)
  600. return -ENOMEM;
  601. #define EPSTAT(name) \
  602. do { \
  603. len = print_endpoint_stat(target, buf, buf_len, len, \
  604. offsetof(struct htc_endpoint_stats, \
  605. name), \
  606. #name); \
  607. } while (0)
  608. EPSTAT(cred_low_indicate);
  609. EPSTAT(tx_issued);
  610. EPSTAT(tx_pkt_bundled);
  611. EPSTAT(tx_bundles);
  612. EPSTAT(tx_dropped);
  613. EPSTAT(tx_cred_rpt);
  614. EPSTAT(cred_rpt_from_rx);
  615. EPSTAT(cred_rpt_from_other);
  616. EPSTAT(cred_rpt_ep0);
  617. EPSTAT(cred_from_rx);
  618. EPSTAT(cred_from_other);
  619. EPSTAT(cred_from_ep0);
  620. EPSTAT(cred_cosumd);
  621. EPSTAT(cred_retnd);
  622. EPSTAT(rx_pkts);
  623. EPSTAT(rx_lkahds);
  624. EPSTAT(rx_bundl);
  625. EPSTAT(rx_bundle_lkahd);
  626. EPSTAT(rx_bundle_from_hdr);
  627. EPSTAT(rx_alloc_thresh_hit);
  628. EPSTAT(rxalloc_thresh_byte);
  629. #undef EPSTAT
  630. if (len > buf_len)
  631. len = buf_len;
  632. ret_cnt = simple_read_from_buffer(user_buf, count, ppos, buf, len);
  633. kfree(buf);
  634. return ret_cnt;
  635. }
  636. static ssize_t ath6kl_endpoint_stats_write(struct file *file,
  637. const char __user *user_buf,
  638. size_t count, loff_t *ppos)
  639. {
  640. struct ath6kl *ar = file->private_data;
  641. struct htc_target *target = ar->htc_target;
  642. int ret, i;
  643. u32 val;
  644. struct htc_endpoint_stats *ep_st;
  645. ret = kstrtou32_from_user(user_buf, count, 0, &val);
  646. if (ret)
  647. return ret;
  648. if (val == 0) {
  649. for (i = 0; i < ENDPOINT_MAX; i++) {
  650. ep_st = &target->endpoint[i].ep_st;
  651. memset(ep_st, 0, sizeof(*ep_st));
  652. }
  653. }
  654. return count;
  655. }
  656. static const struct file_operations fops_endpoint_stats = {
  657. .open = simple_open,
  658. .read = ath6kl_endpoint_stats_read,
  659. .write = ath6kl_endpoint_stats_write,
  660. .owner = THIS_MODULE,
  661. .llseek = default_llseek,
  662. };
  663. static unsigned long ath6kl_get_num_reg(void)
  664. {
  665. int i;
  666. unsigned long n_reg = 0;
  667. for (i = 0; i < ARRAY_SIZE(diag_reg); i++)
  668. n_reg = n_reg +
  669. (diag_reg[i].reg_end - diag_reg[i].reg_start) / 4 + 1;
  670. return n_reg;
  671. }
  672. static bool ath6kl_dbg_is_diag_reg_valid(u32 reg_addr)
  673. {
  674. int i;
  675. for (i = 0; i < ARRAY_SIZE(diag_reg); i++) {
  676. if (reg_addr >= diag_reg[i].reg_start &&
  677. reg_addr <= diag_reg[i].reg_end)
  678. return true;
  679. }
  680. return false;
  681. }
  682. static ssize_t ath6kl_regread_read(struct file *file, char __user *user_buf,
  683. size_t count, loff_t *ppos)
  684. {
  685. struct ath6kl *ar = file->private_data;
  686. u8 buf[50];
  687. unsigned int len = 0;
  688. if (ar->debug.dbgfs_diag_reg)
  689. len += scnprintf(buf + len, sizeof(buf) - len, "0x%x\n",
  690. ar->debug.dbgfs_diag_reg);
  691. else
  692. len += scnprintf(buf + len, sizeof(buf) - len,
  693. "All diag registers\n");
  694. return simple_read_from_buffer(user_buf, count, ppos, buf, len);
  695. }
  696. static ssize_t ath6kl_regread_write(struct file *file,
  697. const char __user *user_buf,
  698. size_t count, loff_t *ppos)
  699. {
  700. struct ath6kl *ar = file->private_data;
  701. unsigned long reg_addr;
  702. if (kstrtoul_from_user(user_buf, count, 0, &reg_addr))
  703. return -EINVAL;
  704. if ((reg_addr % 4) != 0)
  705. return -EINVAL;
  706. if (reg_addr && !ath6kl_dbg_is_diag_reg_valid(reg_addr))
  707. return -EINVAL;
  708. ar->debug.dbgfs_diag_reg = reg_addr;
  709. return count;
  710. }
  711. static const struct file_operations fops_diag_reg_read = {
  712. .read = ath6kl_regread_read,
  713. .write = ath6kl_regread_write,
  714. .open = simple_open,
  715. .owner = THIS_MODULE,
  716. .llseek = default_llseek,
  717. };
  718. static int ath6kl_regdump_open(struct inode *inode, struct file *file)
  719. {
  720. struct ath6kl *ar = inode->i_private;
  721. u8 *buf;
  722. unsigned long int reg_len;
  723. unsigned int len = 0, n_reg;
  724. u32 addr;
  725. __le32 reg_val;
  726. int i, status;
  727. /* Dump all the registers if no register is specified */
  728. if (!ar->debug.dbgfs_diag_reg)
  729. n_reg = ath6kl_get_num_reg();
  730. else
  731. n_reg = 1;
  732. reg_len = n_reg * REG_OUTPUT_LEN_PER_LINE;
  733. if (n_reg > 1)
  734. reg_len += REGTYPE_STR_LEN;
  735. buf = vmalloc(reg_len);
  736. if (!buf)
  737. return -ENOMEM;
  738. if (n_reg == 1) {
  739. addr = ar->debug.dbgfs_diag_reg;
  740. status = ath6kl_diag_read32(ar,
  741. TARG_VTOP(ar->target_type, addr),
  742. (u32 *)&reg_val);
  743. if (status)
  744. goto fail_reg_read;
  745. len += scnprintf(buf + len, reg_len - len,
  746. "0x%06x 0x%08x\n", addr, le32_to_cpu(reg_val));
  747. goto done;
  748. }
  749. for (i = 0; i < ARRAY_SIZE(diag_reg); i++) {
  750. len += scnprintf(buf + len, reg_len - len,
  751. "%s\n", diag_reg[i].reg_info);
  752. for (addr = diag_reg[i].reg_start;
  753. addr <= diag_reg[i].reg_end; addr += 4) {
  754. status = ath6kl_diag_read32(ar,
  755. TARG_VTOP(ar->target_type, addr),
  756. (u32 *)&reg_val);
  757. if (status)
  758. goto fail_reg_read;
  759. len += scnprintf(buf + len, reg_len - len,
  760. "0x%06x 0x%08x\n",
  761. addr, le32_to_cpu(reg_val));
  762. }
  763. }
  764. done:
  765. file->private_data = buf;
  766. return 0;
  767. fail_reg_read:
  768. ath6kl_warn("Unable to read memory:%u\n", addr);
  769. vfree(buf);
  770. return -EIO;
  771. }
  772. static ssize_t ath6kl_regdump_read(struct file *file, char __user *user_buf,
  773. size_t count, loff_t *ppos)
  774. {
  775. u8 *buf = file->private_data;
  776. return simple_read_from_buffer(user_buf, count, ppos, buf, strlen(buf));
  777. }
  778. static int ath6kl_regdump_release(struct inode *inode, struct file *file)
  779. {
  780. vfree(file->private_data);
  781. return 0;
  782. }
  783. static const struct file_operations fops_reg_dump = {
  784. .open = ath6kl_regdump_open,
  785. .read = ath6kl_regdump_read,
  786. .release = ath6kl_regdump_release,
  787. .owner = THIS_MODULE,
  788. .llseek = default_llseek,
  789. };
  790. static ssize_t ath6kl_lrssi_roam_write(struct file *file,
  791. const char __user *user_buf,
  792. size_t count, loff_t *ppos)
  793. {
  794. struct ath6kl *ar = file->private_data;
  795. unsigned long lrssi_roam_threshold;
  796. if (kstrtoul_from_user(user_buf, count, 0, &lrssi_roam_threshold))
  797. return -EINVAL;
  798. ar->lrssi_roam_threshold = lrssi_roam_threshold;
  799. ath6kl_wmi_set_roam_lrssi_cmd(ar->wmi, ar->lrssi_roam_threshold);
  800. return count;
  801. }
  802. static ssize_t ath6kl_lrssi_roam_read(struct file *file,
  803. char __user *user_buf,
  804. size_t count, loff_t *ppos)
  805. {
  806. struct ath6kl *ar = file->private_data;
  807. char buf[32];
  808. unsigned int len;
  809. len = snprintf(buf, sizeof(buf), "%u\n", ar->lrssi_roam_threshold);
  810. return simple_read_from_buffer(user_buf, count, ppos, buf, len);
  811. }
  812. static const struct file_operations fops_lrssi_roam_threshold = {
  813. .read = ath6kl_lrssi_roam_read,
  814. .write = ath6kl_lrssi_roam_write,
  815. .open = simple_open,
  816. .owner = THIS_MODULE,
  817. .llseek = default_llseek,
  818. };
  819. static ssize_t ath6kl_regwrite_read(struct file *file,
  820. char __user *user_buf,
  821. size_t count, loff_t *ppos)
  822. {
  823. struct ath6kl *ar = file->private_data;
  824. u8 buf[32];
  825. unsigned int len = 0;
  826. len = scnprintf(buf, sizeof(buf), "Addr: 0x%x Val: 0x%x\n",
  827. ar->debug.diag_reg_addr_wr, ar->debug.diag_reg_val_wr);
  828. return simple_read_from_buffer(user_buf, count, ppos, buf, len);
  829. }
  830. static ssize_t ath6kl_regwrite_write(struct file *file,
  831. const char __user *user_buf,
  832. size_t count, loff_t *ppos)
  833. {
  834. struct ath6kl *ar = file->private_data;
  835. char buf[32];
  836. char *sptr, *token;
  837. unsigned int len = 0;
  838. u32 reg_addr, reg_val;
  839. len = min(count, sizeof(buf) - 1);
  840. if (copy_from_user(buf, user_buf, len))
  841. return -EFAULT;
  842. buf[len] = '\0';
  843. sptr = buf;
  844. token = strsep(&sptr, "=");
  845. if (!token)
  846. return -EINVAL;
  847. if (kstrtou32(token, 0, &reg_addr))
  848. return -EINVAL;
  849. if (!ath6kl_dbg_is_diag_reg_valid(reg_addr))
  850. return -EINVAL;
  851. if (kstrtou32(sptr, 0, &reg_val))
  852. return -EINVAL;
  853. ar->debug.diag_reg_addr_wr = reg_addr;
  854. ar->debug.diag_reg_val_wr = reg_val;
  855. if (ath6kl_diag_write32(ar, ar->debug.diag_reg_addr_wr,
  856. cpu_to_le32(ar->debug.diag_reg_val_wr)))
  857. return -EIO;
  858. return count;
  859. }
  860. static const struct file_operations fops_diag_reg_write = {
  861. .read = ath6kl_regwrite_read,
  862. .write = ath6kl_regwrite_write,
  863. .open = simple_open,
  864. .owner = THIS_MODULE,
  865. .llseek = default_llseek,
  866. };
  867. int ath6kl_debug_roam_tbl_event(struct ath6kl *ar, const void *buf,
  868. size_t len)
  869. {
  870. const struct wmi_target_roam_tbl *tbl;
  871. u16 num_entries;
  872. if (len < sizeof(*tbl))
  873. return -EINVAL;
  874. tbl = (const struct wmi_target_roam_tbl *) buf;
  875. num_entries = le16_to_cpu(tbl->num_entries);
  876. if (sizeof(*tbl) + num_entries * sizeof(struct wmi_bss_roam_info) >
  877. len)
  878. return -EINVAL;
  879. if (ar->debug.roam_tbl == NULL ||
  880. ar->debug.roam_tbl_len < (unsigned int) len) {
  881. kfree(ar->debug.roam_tbl);
  882. ar->debug.roam_tbl = kmalloc(len, GFP_ATOMIC);
  883. if (ar->debug.roam_tbl == NULL)
  884. return -ENOMEM;
  885. }
  886. memcpy(ar->debug.roam_tbl, buf, len);
  887. ar->debug.roam_tbl_len = len;
  888. if (test_bit(ROAM_TBL_PEND, &ar->flag)) {
  889. clear_bit(ROAM_TBL_PEND, &ar->flag);
  890. wake_up(&ar->event_wq);
  891. }
  892. return 0;
  893. }
  894. static ssize_t ath6kl_roam_table_read(struct file *file, char __user *user_buf,
  895. size_t count, loff_t *ppos)
  896. {
  897. struct ath6kl *ar = file->private_data;
  898. int ret;
  899. long left;
  900. struct wmi_target_roam_tbl *tbl;
  901. u16 num_entries, i;
  902. char *buf;
  903. unsigned int len, buf_len;
  904. ssize_t ret_cnt;
  905. if (down_interruptible(&ar->sem))
  906. return -EBUSY;
  907. set_bit(ROAM_TBL_PEND, &ar->flag);
  908. ret = ath6kl_wmi_get_roam_tbl_cmd(ar->wmi);
  909. if (ret) {
  910. up(&ar->sem);
  911. return ret;
  912. }
  913. left = wait_event_interruptible_timeout(
  914. ar->event_wq, !test_bit(ROAM_TBL_PEND, &ar->flag), WMI_TIMEOUT);
  915. up(&ar->sem);
  916. if (left <= 0)
  917. return -ETIMEDOUT;
  918. if (ar->debug.roam_tbl == NULL)
  919. return -ENOMEM;
  920. tbl = (struct wmi_target_roam_tbl *) ar->debug.roam_tbl;
  921. num_entries = le16_to_cpu(tbl->num_entries);
  922. buf_len = 100 + num_entries * 100;
  923. buf = kzalloc(buf_len, GFP_KERNEL);
  924. if (buf == NULL)
  925. return -ENOMEM;
  926. len = 0;
  927. len += scnprintf(buf + len, buf_len - len,
  928. "roam_mode=%u\n\n"
  929. "# roam_util bssid rssi rssidt last_rssi util bias\n",
  930. le16_to_cpu(tbl->roam_mode));
  931. for (i = 0; i < num_entries; i++) {
  932. struct wmi_bss_roam_info *info = &tbl->info[i];
  933. len += scnprintf(buf + len, buf_len - len,
  934. "%d %pM %d %d %d %d %d\n",
  935. a_sle32_to_cpu(info->roam_util), info->bssid,
  936. info->rssi, info->rssidt, info->last_rssi,
  937. info->util, info->bias);
  938. }
  939. if (len > buf_len)
  940. len = buf_len;
  941. ret_cnt = simple_read_from_buffer(user_buf, count, ppos, buf, len);
  942. kfree(buf);
  943. return ret_cnt;
  944. }
  945. static const struct file_operations fops_roam_table = {
  946. .read = ath6kl_roam_table_read,
  947. .open = simple_open,
  948. .owner = THIS_MODULE,
  949. .llseek = default_llseek,
  950. };
  951. static ssize_t ath6kl_force_roam_write(struct file *file,
  952. const char __user *user_buf,
  953. size_t count, loff_t *ppos)
  954. {
  955. struct ath6kl *ar = file->private_data;
  956. int ret;
  957. char buf[20];
  958. size_t len;
  959. u8 bssid[ETH_ALEN];
  960. int i;
  961. int addr[ETH_ALEN];
  962. len = min(count, sizeof(buf) - 1);
  963. if (copy_from_user(buf, user_buf, len))
  964. return -EFAULT;
  965. buf[len] = '\0';
  966. if (sscanf(buf, "%02x:%02x:%02x:%02x:%02x:%02x",
  967. &addr[0], &addr[1], &addr[2], &addr[3], &addr[4], &addr[5])
  968. != ETH_ALEN)
  969. return -EINVAL;
  970. for (i = 0; i < ETH_ALEN; i++)
  971. bssid[i] = addr[i];
  972. ret = ath6kl_wmi_force_roam_cmd(ar->wmi, bssid);
  973. if (ret)
  974. return ret;
  975. return count;
  976. }
  977. static const struct file_operations fops_force_roam = {
  978. .write = ath6kl_force_roam_write,
  979. .open = simple_open,
  980. .owner = THIS_MODULE,
  981. .llseek = default_llseek,
  982. };
  983. static ssize_t ath6kl_roam_mode_write(struct file *file,
  984. const char __user *user_buf,
  985. size_t count, loff_t *ppos)
  986. {
  987. struct ath6kl *ar = file->private_data;
  988. int ret;
  989. char buf[20];
  990. size_t len;
  991. enum wmi_roam_mode mode;
  992. len = min(count, sizeof(buf) - 1);
  993. if (copy_from_user(buf, user_buf, len))
  994. return -EFAULT;
  995. buf[len] = '\0';
  996. if (len > 0 && buf[len - 1] == '\n')
  997. buf[len - 1] = '\0';
  998. if (strcasecmp(buf, "default") == 0)
  999. mode = WMI_DEFAULT_ROAM_MODE;
  1000. else if (strcasecmp(buf, "bssbias") == 0)
  1001. mode = WMI_HOST_BIAS_ROAM_MODE;
  1002. else if (strcasecmp(buf, "lock") == 0)
  1003. mode = WMI_LOCK_BSS_MODE;
  1004. else
  1005. return -EINVAL;
  1006. ret = ath6kl_wmi_set_roam_mode_cmd(ar->wmi, mode);
  1007. if (ret)
  1008. return ret;
  1009. return count;
  1010. }
  1011. static const struct file_operations fops_roam_mode = {
  1012. .write = ath6kl_roam_mode_write,
  1013. .open = simple_open,
  1014. .owner = THIS_MODULE,
  1015. .llseek = default_llseek,
  1016. };
  1017. void ath6kl_debug_set_keepalive(struct ath6kl *ar, u8 keepalive)
  1018. {
  1019. ar->debug.keepalive = keepalive;
  1020. }
  1021. static ssize_t ath6kl_keepalive_read(struct file *file, char __user *user_buf,
  1022. size_t count, loff_t *ppos)
  1023. {
  1024. struct ath6kl *ar = file->private_data;
  1025. char buf[16];
  1026. int len;
  1027. len = snprintf(buf, sizeof(buf), "%u\n", ar->debug.keepalive);
  1028. return simple_read_from_buffer(user_buf, count, ppos, buf, len);
  1029. }
  1030. static ssize_t ath6kl_keepalive_write(struct file *file,
  1031. const char __user *user_buf,
  1032. size_t count, loff_t *ppos)
  1033. {
  1034. struct ath6kl *ar = file->private_data;
  1035. int ret;
  1036. u8 val;
  1037. ret = kstrtou8_from_user(user_buf, count, 0, &val);
  1038. if (ret)
  1039. return ret;
  1040. ret = ath6kl_wmi_set_keepalive_cmd(ar->wmi, 0, val);
  1041. if (ret)
  1042. return ret;
  1043. return count;
  1044. }
  1045. static const struct file_operations fops_keepalive = {
  1046. .open = simple_open,
  1047. .read = ath6kl_keepalive_read,
  1048. .write = ath6kl_keepalive_write,
  1049. .owner = THIS_MODULE,
  1050. .llseek = default_llseek,
  1051. };
  1052. void ath6kl_debug_set_disconnect_timeout(struct ath6kl *ar, u8 timeout)
  1053. {
  1054. ar->debug.disc_timeout = timeout;
  1055. }
  1056. static ssize_t ath6kl_disconnect_timeout_read(struct file *file,
  1057. char __user *user_buf,
  1058. size_t count, loff_t *ppos)
  1059. {
  1060. struct ath6kl *ar = file->private_data;
  1061. char buf[16];
  1062. int len;
  1063. len = snprintf(buf, sizeof(buf), "%u\n", ar->debug.disc_timeout);
  1064. return simple_read_from_buffer(user_buf, count, ppos, buf, len);
  1065. }
  1066. static ssize_t ath6kl_disconnect_timeout_write(struct file *file,
  1067. const char __user *user_buf,
  1068. size_t count, loff_t *ppos)
  1069. {
  1070. struct ath6kl *ar = file->private_data;
  1071. int ret;
  1072. u8 val;
  1073. ret = kstrtou8_from_user(user_buf, count, 0, &val);
  1074. if (ret)
  1075. return ret;
  1076. ret = ath6kl_wmi_disctimeout_cmd(ar->wmi, 0, val);
  1077. if (ret)
  1078. return ret;
  1079. return count;
  1080. }
  1081. static const struct file_operations fops_disconnect_timeout = {
  1082. .open = simple_open,
  1083. .read = ath6kl_disconnect_timeout_read,
  1084. .write = ath6kl_disconnect_timeout_write,
  1085. .owner = THIS_MODULE,
  1086. .llseek = default_llseek,
  1087. };
  1088. static ssize_t ath6kl_create_qos_write(struct file *file,
  1089. const char __user *user_buf,
  1090. size_t count, loff_t *ppos)
  1091. {
  1092. struct ath6kl *ar = file->private_data;
  1093. struct ath6kl_vif *vif;
  1094. char buf[200];
  1095. ssize_t len;
  1096. char *sptr, *token;
  1097. struct wmi_create_pstream_cmd pstream;
  1098. u32 val32;
  1099. u16 val16;
  1100. vif = ath6kl_vif_first(ar);
  1101. if (!vif)
  1102. return -EIO;
  1103. len = min(count, sizeof(buf) - 1);
  1104. if (copy_from_user(buf, user_buf, len))
  1105. return -EFAULT;
  1106. buf[len] = '\0';
  1107. sptr = buf;
  1108. token = strsep(&sptr, " ");
  1109. if (!token)
  1110. return -EINVAL;
  1111. if (kstrtou8(token, 0, &pstream.user_pri))
  1112. return -EINVAL;
  1113. token = strsep(&sptr, " ");
  1114. if (!token)
  1115. return -EINVAL;
  1116. if (kstrtou8(token, 0, &pstream.traffic_direc))
  1117. return -EINVAL;
  1118. token = strsep(&sptr, " ");
  1119. if (!token)
  1120. return -EINVAL;
  1121. if (kstrtou8(token, 0, &pstream.traffic_class))
  1122. return -EINVAL;
  1123. token = strsep(&sptr, " ");
  1124. if (!token)
  1125. return -EINVAL;
  1126. if (kstrtou8(token, 0, &pstream.traffic_type))
  1127. return -EINVAL;
  1128. token = strsep(&sptr, " ");
  1129. if (!token)
  1130. return -EINVAL;
  1131. if (kstrtou8(token, 0, &pstream.voice_psc_cap))
  1132. return -EINVAL;
  1133. token = strsep(&sptr, " ");
  1134. if (!token)
  1135. return -EINVAL;
  1136. if (kstrtou32(token, 0, &val32))
  1137. return -EINVAL;
  1138. pstream.min_service_int = cpu_to_le32(val32);
  1139. token = strsep(&sptr, " ");
  1140. if (!token)
  1141. return -EINVAL;
  1142. if (kstrtou32(token, 0, &val32))
  1143. return -EINVAL;
  1144. pstream.max_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.inactivity_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.suspension_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.service_start_time = cpu_to_le32(val32);
  1163. token = strsep(&sptr, " ");
  1164. if (!token)
  1165. return -EINVAL;
  1166. if (kstrtou8(token, 0, &pstream.tsid))
  1167. return -EINVAL;
  1168. token = strsep(&sptr, " ");
  1169. if (!token)
  1170. return -EINVAL;
  1171. if (kstrtou16(token, 0, &val16))
  1172. return -EINVAL;
  1173. pstream.nominal_msdu = cpu_to_le16(val16);
  1174. token = strsep(&sptr, " ");
  1175. if (!token)
  1176. return -EINVAL;
  1177. if (kstrtou16(token, 0, &val16))
  1178. return -EINVAL;
  1179. pstream.max_msdu = cpu_to_le16(val16);
  1180. token = strsep(&sptr, " ");
  1181. if (!token)
  1182. return -EINVAL;
  1183. if (kstrtou32(token, 0, &val32))
  1184. return -EINVAL;
  1185. pstream.min_data_rate = cpu_to_le32(val32);
  1186. token = strsep(&sptr, " ");
  1187. if (!token)
  1188. return -EINVAL;
  1189. if (kstrtou32(token, 0, &val32))
  1190. return -EINVAL;
  1191. pstream.mean_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.peak_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.max_burst_size = 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.delay_bound = 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.min_phy_rate = 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.sba = 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.medium_time = cpu_to_le32(val32);
  1228. pstream.nominal_phy = le32_to_cpu(pstream.min_phy_rate) / 1000000;
  1229. ath6kl_wmi_create_pstream_cmd(ar->wmi, vif->fw_vif_idx, &pstream);
  1230. return count;
  1231. }
  1232. static const struct file_operations fops_create_qos = {
  1233. .write = ath6kl_create_qos_write,
  1234. .open = simple_open,
  1235. .owner = THIS_MODULE,
  1236. .llseek = default_llseek,
  1237. };
  1238. static ssize_t ath6kl_delete_qos_write(struct file *file,
  1239. const char __user *user_buf,
  1240. size_t count, loff_t *ppos)
  1241. {
  1242. struct ath6kl *ar = file->private_data;
  1243. struct ath6kl_vif *vif;
  1244. char buf[100];
  1245. ssize_t len;
  1246. char *sptr, *token;
  1247. u8 traffic_class;
  1248. u8 tsid;
  1249. vif = ath6kl_vif_first(ar);
  1250. if (!vif)
  1251. return -EIO;
  1252. len = min(count, sizeof(buf) - 1);
  1253. if (copy_from_user(buf, user_buf, len))
  1254. return -EFAULT;
  1255. buf[len] = '\0';
  1256. sptr = buf;
  1257. token = strsep(&sptr, " ");
  1258. if (!token)
  1259. return -EINVAL;
  1260. if (kstrtou8(token, 0, &traffic_class))
  1261. return -EINVAL;
  1262. token = strsep(&sptr, " ");
  1263. if (!token)
  1264. return -EINVAL;
  1265. if (kstrtou8(token, 0, &tsid))
  1266. return -EINVAL;
  1267. ath6kl_wmi_delete_pstream_cmd(ar->wmi, vif->fw_vif_idx,
  1268. traffic_class, tsid);
  1269. return count;
  1270. }
  1271. static const struct file_operations fops_delete_qos = {
  1272. .write = ath6kl_delete_qos_write,
  1273. .open = simple_open,
  1274. .owner = THIS_MODULE,
  1275. .llseek = default_llseek,
  1276. };
  1277. static ssize_t ath6kl_bgscan_int_write(struct file *file,
  1278. const char __user *user_buf,
  1279. size_t count, loff_t *ppos)
  1280. {
  1281. struct ath6kl *ar = file->private_data;
  1282. u16 bgscan_int;
  1283. char buf[32];
  1284. ssize_t len;
  1285. len = min(count, sizeof(buf) - 1);
  1286. if (copy_from_user(buf, user_buf, len))
  1287. return -EFAULT;
  1288. buf[len] = '\0';
  1289. if (kstrtou16(buf, 0, &bgscan_int))
  1290. return -EINVAL;
  1291. if (bgscan_int == 0)
  1292. bgscan_int = 0xffff;
  1293. ath6kl_wmi_scanparams_cmd(ar->wmi, 0, 0, 0, bgscan_int, 0, 0, 0, 3,
  1294. 0, 0, 0);
  1295. return count;
  1296. }
  1297. static const struct file_operations fops_bgscan_int = {
  1298. .write = ath6kl_bgscan_int_write,
  1299. .open = simple_open,
  1300. .owner = THIS_MODULE,
  1301. .llseek = default_llseek,
  1302. };
  1303. static ssize_t ath6kl_listen_int_write(struct file *file,
  1304. const char __user *user_buf,
  1305. size_t count, loff_t *ppos)
  1306. {
  1307. struct ath6kl *ar = file->private_data;
  1308. struct ath6kl_vif *vif;
  1309. u16 listen_interval;
  1310. char buf[32];
  1311. ssize_t len;
  1312. vif = ath6kl_vif_first(ar);
  1313. if (!vif)
  1314. return -EIO;
  1315. len = min(count, sizeof(buf) - 1);
  1316. if (copy_from_user(buf, user_buf, len))
  1317. return -EFAULT;
  1318. buf[len] = '\0';
  1319. if (kstrtou16(buf, 0, &listen_interval))
  1320. return -EINVAL;
  1321. if ((listen_interval < 15) || (listen_interval > 3000))
  1322. return -EINVAL;
  1323. vif->listen_intvl_t = listen_interval;
  1324. ath6kl_wmi_listeninterval_cmd(ar->wmi, vif->fw_vif_idx,
  1325. vif->listen_intvl_t, 0);
  1326. return count;
  1327. }
  1328. static ssize_t ath6kl_listen_int_read(struct file *file,
  1329. char __user *user_buf,
  1330. size_t count, loff_t *ppos)
  1331. {
  1332. struct ath6kl *ar = file->private_data;
  1333. struct ath6kl_vif *vif;
  1334. char buf[32];
  1335. int len;
  1336. vif = ath6kl_vif_first(ar);
  1337. if (!vif)
  1338. return -EIO;
  1339. len = scnprintf(buf, sizeof(buf), "%u\n", vif->listen_intvl_t);
  1340. return simple_read_from_buffer(user_buf, count, ppos, buf, len);
  1341. }
  1342. static const struct file_operations fops_listen_int = {
  1343. .read = ath6kl_listen_int_read,
  1344. .write = ath6kl_listen_int_write,
  1345. .open = simple_open,
  1346. .owner = THIS_MODULE,
  1347. .llseek = default_llseek,
  1348. };
  1349. static ssize_t ath6kl_power_params_write(struct file *file,
  1350. const char __user *user_buf,
  1351. size_t count, loff_t *ppos)
  1352. {
  1353. struct ath6kl *ar = file->private_data;
  1354. u8 buf[100];
  1355. unsigned int len = 0;
  1356. char *sptr, *token;
  1357. u16 idle_period, ps_poll_num, dtim,
  1358. tx_wakeup, num_tx;
  1359. len = min(count, sizeof(buf) - 1);
  1360. if (copy_from_user(buf, user_buf, len))
  1361. return -EFAULT;
  1362. buf[len] = '\0';
  1363. sptr = buf;
  1364. token = strsep(&sptr, " ");
  1365. if (!token)
  1366. return -EINVAL;
  1367. if (kstrtou16(token, 0, &idle_period))
  1368. return -EINVAL;
  1369. token = strsep(&sptr, " ");
  1370. if (!token)
  1371. return -EINVAL;
  1372. if (kstrtou16(token, 0, &ps_poll_num))
  1373. return -EINVAL;
  1374. token = strsep(&sptr, " ");
  1375. if (!token)
  1376. return -EINVAL;
  1377. if (kstrtou16(token, 0, &dtim))
  1378. return -EINVAL;
  1379. token = strsep(&sptr, " ");
  1380. if (!token)
  1381. return -EINVAL;
  1382. if (kstrtou16(token, 0, &tx_wakeup))
  1383. return -EINVAL;
  1384. token = strsep(&sptr, " ");
  1385. if (!token)
  1386. return -EINVAL;
  1387. if (kstrtou16(token, 0, &num_tx))
  1388. return -EINVAL;
  1389. ath6kl_wmi_pmparams_cmd(ar->wmi, 0, idle_period, ps_poll_num,
  1390. dtim, tx_wakeup, num_tx, 0);
  1391. return count;
  1392. }
  1393. static const struct file_operations fops_power_params = {
  1394. .write = ath6kl_power_params_write,
  1395. .open = simple_open,
  1396. .owner = THIS_MODULE,
  1397. .llseek = default_llseek,
  1398. };
  1399. void ath6kl_debug_init(struct ath6kl *ar)
  1400. {
  1401. skb_queue_head_init(&ar->debug.fwlog_queue);
  1402. init_completion(&ar->debug.fwlog_completion);
  1403. /*
  1404. * Actually we are lying here but don't know how to read the mask
  1405. * value from the firmware.
  1406. */
  1407. ar->debug.fwlog_mask = 0;
  1408. }
  1409. /*
  1410. * Initialisation needs to happen in two stages as fwlog events can come
  1411. * before cfg80211 is initialised, and debugfs depends on cfg80211
  1412. * initialisation.
  1413. */
  1414. int ath6kl_debug_init_fs(struct ath6kl *ar)
  1415. {
  1416. ar->debugfs_phy = debugfs_create_dir("ath6kl",
  1417. ar->wiphy->debugfsdir);
  1418. if (!ar->debugfs_phy)
  1419. return -ENOMEM;
  1420. debugfs_create_file("tgt_stats", S_IRUSR, ar->debugfs_phy, ar,
  1421. &fops_tgt_stats);
  1422. debugfs_create_file("credit_dist_stats", S_IRUSR, ar->debugfs_phy, ar,
  1423. &fops_credit_dist_stats);
  1424. debugfs_create_file("endpoint_stats", S_IRUSR | S_IWUSR,
  1425. ar->debugfs_phy, ar, &fops_endpoint_stats);
  1426. debugfs_create_file("fwlog", S_IRUSR, ar->debugfs_phy, ar,
  1427. &fops_fwlog);
  1428. debugfs_create_file("fwlog_block", S_IRUSR, ar->debugfs_phy, ar,
  1429. &fops_fwlog_block);
  1430. debugfs_create_file("fwlog_mask", S_IRUSR | S_IWUSR, ar->debugfs_phy,
  1431. ar, &fops_fwlog_mask);
  1432. debugfs_create_file("reg_addr", S_IRUSR | S_IWUSR, ar->debugfs_phy, ar,
  1433. &fops_diag_reg_read);
  1434. debugfs_create_file("reg_dump", S_IRUSR, ar->debugfs_phy, ar,
  1435. &fops_reg_dump);
  1436. debugfs_create_file("lrssi_roam_threshold", S_IRUSR | S_IWUSR,
  1437. ar->debugfs_phy, ar, &fops_lrssi_roam_threshold);
  1438. debugfs_create_file("reg_write", S_IRUSR | S_IWUSR,
  1439. ar->debugfs_phy, ar, &fops_diag_reg_write);
  1440. debugfs_create_file("war_stats", S_IRUSR, ar->debugfs_phy, ar,
  1441. &fops_war_stats);
  1442. debugfs_create_file("roam_table", S_IRUSR, ar->debugfs_phy, ar,
  1443. &fops_roam_table);
  1444. debugfs_create_file("force_roam", S_IWUSR, ar->debugfs_phy, ar,
  1445. &fops_force_roam);
  1446. debugfs_create_file("roam_mode", S_IWUSR, ar->debugfs_phy, ar,
  1447. &fops_roam_mode);
  1448. debugfs_create_file("keepalive", S_IRUSR | S_IWUSR, ar->debugfs_phy, ar,
  1449. &fops_keepalive);
  1450. debugfs_create_file("disconnect_timeout", S_IRUSR | S_IWUSR,
  1451. ar->debugfs_phy, ar, &fops_disconnect_timeout);
  1452. debugfs_create_file("create_qos", S_IWUSR, ar->debugfs_phy, ar,
  1453. &fops_create_qos);
  1454. debugfs_create_file("delete_qos", S_IWUSR, ar->debugfs_phy, ar,
  1455. &fops_delete_qos);
  1456. debugfs_create_file("bgscan_interval", S_IWUSR,
  1457. ar->debugfs_phy, ar, &fops_bgscan_int);
  1458. debugfs_create_file("listen_interval", S_IRUSR | S_IWUSR,
  1459. ar->debugfs_phy, ar, &fops_listen_int);
  1460. debugfs_create_file("power_params", S_IWUSR, ar->debugfs_phy, ar,
  1461. &fops_power_params);
  1462. return 0;
  1463. }
  1464. void ath6kl_debug_cleanup(struct ath6kl *ar)
  1465. {
  1466. skb_queue_purge(&ar->debug.fwlog_queue);
  1467. kfree(ar->debug.roam_tbl);
  1468. }
  1469. #endif