debug.c 43 KB

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