debug.c 43 KB

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