debugfs.c 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757
  1. /*
  2. * Copyright (c) 2012-2016 Qualcomm Atheros, 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 <linux/module.h>
  17. #include <linux/debugfs.h>
  18. #include <linux/seq_file.h>
  19. #include <linux/pci.h>
  20. #include <linux/rtnetlink.h>
  21. #include <linux/power_supply.h>
  22. #include "wil6210.h"
  23. #include "wmi.h"
  24. #include "txrx.h"
  25. #include "pmc.h"
  26. /* Nasty hack. Better have per device instances */
  27. static u32 mem_addr;
  28. static u32 dbg_txdesc_index;
  29. static u32 dbg_vring_index; /* 24+ for Rx, 0..23 for Tx */
  30. u32 vring_idle_trsh = 16; /* HW fetches up to 16 descriptors at once */
  31. enum dbg_off_type {
  32. doff_u32 = 0,
  33. doff_x32 = 1,
  34. doff_ulong = 2,
  35. doff_io32 = 3,
  36. doff_u8 = 4
  37. };
  38. /* offset to "wil" */
  39. struct dbg_off {
  40. const char *name;
  41. umode_t mode;
  42. ulong off;
  43. enum dbg_off_type type;
  44. };
  45. static void wil_print_vring(struct seq_file *s, struct wil6210_priv *wil,
  46. const char *name, struct vring *vring,
  47. char _s, char _h)
  48. {
  49. void __iomem *x = wmi_addr(wil, vring->hwtail);
  50. u32 v;
  51. seq_printf(s, "VRING %s = {\n", name);
  52. seq_printf(s, " pa = %pad\n", &vring->pa);
  53. seq_printf(s, " va = 0x%p\n", vring->va);
  54. seq_printf(s, " size = %d\n", vring->size);
  55. seq_printf(s, " swtail = %d\n", vring->swtail);
  56. seq_printf(s, " swhead = %d\n", vring->swhead);
  57. seq_printf(s, " hwtail = [0x%08x] -> ", vring->hwtail);
  58. if (x) {
  59. v = readl(x);
  60. seq_printf(s, "0x%08x = %d\n", v, v);
  61. } else {
  62. seq_puts(s, "???\n");
  63. }
  64. if (vring->va && (vring->size <= (1 << WIL_RING_SIZE_ORDER_MAX))) {
  65. uint i;
  66. for (i = 0; i < vring->size; i++) {
  67. volatile struct vring_tx_desc *d = &vring->va[i].tx;
  68. if ((i % 128) == 0 && (i != 0))
  69. seq_puts(s, "\n");
  70. seq_printf(s, "%c", (d->dma.status & BIT(0)) ?
  71. _s : (vring->ctx[i].skb ? _h : 'h'));
  72. }
  73. seq_puts(s, "\n");
  74. }
  75. seq_puts(s, "}\n");
  76. }
  77. static int wil_vring_debugfs_show(struct seq_file *s, void *data)
  78. {
  79. uint i;
  80. struct wil6210_priv *wil = s->private;
  81. wil_print_vring(s, wil, "rx", &wil->vring_rx, 'S', '_');
  82. for (i = 0; i < ARRAY_SIZE(wil->vring_tx); i++) {
  83. struct vring *vring = &wil->vring_tx[i];
  84. struct vring_tx_data *txdata = &wil->vring_tx_data[i];
  85. if (vring->va) {
  86. int cid = wil->vring2cid_tid[i][0];
  87. int tid = wil->vring2cid_tid[i][1];
  88. u32 swhead = vring->swhead;
  89. u32 swtail = vring->swtail;
  90. int used = (vring->size + swhead - swtail)
  91. % vring->size;
  92. int avail = vring->size - used - 1;
  93. char name[10];
  94. char sidle[10];
  95. /* performance monitoring */
  96. cycles_t now = get_cycles();
  97. uint64_t idle = txdata->idle * 100;
  98. uint64_t total = now - txdata->begin;
  99. if (total != 0) {
  100. do_div(idle, total);
  101. snprintf(sidle, sizeof(sidle), "%3d%%",
  102. (int)idle);
  103. } else {
  104. snprintf(sidle, sizeof(sidle), "N/A");
  105. }
  106. txdata->begin = now;
  107. txdata->idle = 0ULL;
  108. snprintf(name, sizeof(name), "tx_%2d", i);
  109. if (cid < WIL6210_MAX_CID)
  110. seq_printf(s,
  111. "\n%pM CID %d TID %d 1x%s BACK([%u] %u TU A%s) [%3d|%3d] idle %s\n",
  112. wil->sta[cid].addr, cid, tid,
  113. txdata->dot1x_open ? "+" : "-",
  114. txdata->agg_wsize,
  115. txdata->agg_timeout,
  116. txdata->agg_amsdu ? "+" : "-",
  117. used, avail, sidle);
  118. else
  119. seq_printf(s,
  120. "\nBroadcast 1x%s [%3d|%3d] idle %s\n",
  121. txdata->dot1x_open ? "+" : "-",
  122. used, avail, sidle);
  123. wil_print_vring(s, wil, name, vring, '_', 'H');
  124. }
  125. }
  126. return 0;
  127. }
  128. static int wil_vring_seq_open(struct inode *inode, struct file *file)
  129. {
  130. return single_open(file, wil_vring_debugfs_show, inode->i_private);
  131. }
  132. static const struct file_operations fops_vring = {
  133. .open = wil_vring_seq_open,
  134. .release = single_release,
  135. .read = seq_read,
  136. .llseek = seq_lseek,
  137. };
  138. static void wil_seq_hexdump(struct seq_file *s, void *p, int len,
  139. const char *prefix)
  140. {
  141. seq_hex_dump(s, prefix, DUMP_PREFIX_NONE, 16, 1, p, len, false);
  142. }
  143. static void wil_print_ring(struct seq_file *s, const char *prefix,
  144. void __iomem *off)
  145. {
  146. struct wil6210_priv *wil = s->private;
  147. struct wil6210_mbox_ring r;
  148. int rsize;
  149. uint i;
  150. wil_halp_vote(wil);
  151. wil_memcpy_fromio_32(&r, off, sizeof(r));
  152. wil_mbox_ring_le2cpus(&r);
  153. /*
  154. * we just read memory block from NIC. This memory may be
  155. * garbage. Check validity before using it.
  156. */
  157. rsize = r.size / sizeof(struct wil6210_mbox_ring_desc);
  158. seq_printf(s, "ring %s = {\n", prefix);
  159. seq_printf(s, " base = 0x%08x\n", r.base);
  160. seq_printf(s, " size = 0x%04x bytes -> %d entries\n", r.size, rsize);
  161. seq_printf(s, " tail = 0x%08x\n", r.tail);
  162. seq_printf(s, " head = 0x%08x\n", r.head);
  163. seq_printf(s, " entry size = %d\n", r.entry_size);
  164. if (r.size % sizeof(struct wil6210_mbox_ring_desc)) {
  165. seq_printf(s, " ??? size is not multiple of %zd, garbage?\n",
  166. sizeof(struct wil6210_mbox_ring_desc));
  167. goto out;
  168. }
  169. if (!wmi_addr(wil, r.base) ||
  170. !wmi_addr(wil, r.tail) ||
  171. !wmi_addr(wil, r.head)) {
  172. seq_puts(s, " ??? pointers are garbage?\n");
  173. goto out;
  174. }
  175. for (i = 0; i < rsize; i++) {
  176. struct wil6210_mbox_ring_desc d;
  177. struct wil6210_mbox_hdr hdr;
  178. size_t delta = i * sizeof(d);
  179. void __iomem *x = wil->csr + HOSTADDR(r.base) + delta;
  180. wil_memcpy_fromio_32(&d, x, sizeof(d));
  181. seq_printf(s, " [%2x] %s %s%s 0x%08x", i,
  182. d.sync ? "F" : "E",
  183. (r.tail - r.base == delta) ? "t" : " ",
  184. (r.head - r.base == delta) ? "h" : " ",
  185. le32_to_cpu(d.addr));
  186. if (0 == wmi_read_hdr(wil, d.addr, &hdr)) {
  187. u16 len = le16_to_cpu(hdr.len);
  188. seq_printf(s, " -> %04x %04x %04x %02x\n",
  189. le16_to_cpu(hdr.seq), len,
  190. le16_to_cpu(hdr.type), hdr.flags);
  191. if (len <= MAX_MBOXITEM_SIZE) {
  192. unsigned char databuf[MAX_MBOXITEM_SIZE];
  193. void __iomem *src = wmi_buffer(wil, d.addr) +
  194. sizeof(struct wil6210_mbox_hdr);
  195. /*
  196. * No need to check @src for validity -
  197. * we already validated @d.addr while
  198. * reading header
  199. */
  200. wil_memcpy_fromio_32(databuf, src, len);
  201. wil_seq_hexdump(s, databuf, len, " : ");
  202. }
  203. } else {
  204. seq_puts(s, "\n");
  205. }
  206. }
  207. out:
  208. seq_puts(s, "}\n");
  209. wil_halp_unvote(wil);
  210. }
  211. static int wil_mbox_debugfs_show(struct seq_file *s, void *data)
  212. {
  213. struct wil6210_priv *wil = s->private;
  214. wil_print_ring(s, "tx", wil->csr + HOST_MBOX +
  215. offsetof(struct wil6210_mbox_ctl, tx));
  216. wil_print_ring(s, "rx", wil->csr + HOST_MBOX +
  217. offsetof(struct wil6210_mbox_ctl, rx));
  218. return 0;
  219. }
  220. static int wil_mbox_seq_open(struct inode *inode, struct file *file)
  221. {
  222. return single_open(file, wil_mbox_debugfs_show, inode->i_private);
  223. }
  224. static const struct file_operations fops_mbox = {
  225. .open = wil_mbox_seq_open,
  226. .release = single_release,
  227. .read = seq_read,
  228. .llseek = seq_lseek,
  229. };
  230. static int wil_debugfs_iomem_x32_set(void *data, u64 val)
  231. {
  232. writel(val, (void __iomem *)data);
  233. wmb(); /* make sure write propagated to HW */
  234. return 0;
  235. }
  236. static int wil_debugfs_iomem_x32_get(void *data, u64 *val)
  237. {
  238. *val = readl((void __iomem *)data);
  239. return 0;
  240. }
  241. DEFINE_SIMPLE_ATTRIBUTE(fops_iomem_x32, wil_debugfs_iomem_x32_get,
  242. wil_debugfs_iomem_x32_set, "0x%08llx\n");
  243. static struct dentry *wil_debugfs_create_iomem_x32(const char *name,
  244. umode_t mode,
  245. struct dentry *parent,
  246. void *value)
  247. {
  248. return debugfs_create_file(name, mode, parent, value,
  249. &fops_iomem_x32);
  250. }
  251. static int wil_debugfs_ulong_set(void *data, u64 val)
  252. {
  253. *(ulong *)data = val;
  254. return 0;
  255. }
  256. static int wil_debugfs_ulong_get(void *data, u64 *val)
  257. {
  258. *val = *(ulong *)data;
  259. return 0;
  260. }
  261. DEFINE_SIMPLE_ATTRIBUTE(wil_fops_ulong, wil_debugfs_ulong_get,
  262. wil_debugfs_ulong_set, "0x%llx\n");
  263. static struct dentry *wil_debugfs_create_ulong(const char *name, umode_t mode,
  264. struct dentry *parent,
  265. ulong *value)
  266. {
  267. return debugfs_create_file(name, mode, parent, value, &wil_fops_ulong);
  268. }
  269. /**
  270. * wil6210_debugfs_init_offset - create set of debugfs files
  271. * @wil - driver's context, used for printing
  272. * @dbg - directory on the debugfs, where files will be created
  273. * @base - base address used in address calculation
  274. * @tbl - table with file descriptions. Should be terminated with empty element.
  275. *
  276. * Creates files accordingly to the @tbl.
  277. */
  278. static void wil6210_debugfs_init_offset(struct wil6210_priv *wil,
  279. struct dentry *dbg, void *base,
  280. const struct dbg_off * const tbl)
  281. {
  282. int i;
  283. for (i = 0; tbl[i].name; i++) {
  284. struct dentry *f;
  285. switch (tbl[i].type) {
  286. case doff_u32:
  287. f = debugfs_create_u32(tbl[i].name, tbl[i].mode, dbg,
  288. base + tbl[i].off);
  289. break;
  290. case doff_x32:
  291. f = debugfs_create_x32(tbl[i].name, tbl[i].mode, dbg,
  292. base + tbl[i].off);
  293. break;
  294. case doff_ulong:
  295. f = wil_debugfs_create_ulong(tbl[i].name, tbl[i].mode,
  296. dbg, base + tbl[i].off);
  297. break;
  298. case doff_io32:
  299. f = wil_debugfs_create_iomem_x32(tbl[i].name,
  300. tbl[i].mode, dbg,
  301. base + tbl[i].off);
  302. break;
  303. case doff_u8:
  304. f = debugfs_create_u8(tbl[i].name, tbl[i].mode, dbg,
  305. base + tbl[i].off);
  306. break;
  307. default:
  308. f = ERR_PTR(-EINVAL);
  309. }
  310. if (IS_ERR_OR_NULL(f))
  311. wil_err(wil, "Create file \"%s\": err %ld\n",
  312. tbl[i].name, PTR_ERR(f));
  313. }
  314. }
  315. static const struct dbg_off isr_off[] = {
  316. {"ICC", S_IRUGO | S_IWUSR, offsetof(struct RGF_ICR, ICC), doff_io32},
  317. {"ICR", S_IRUGO | S_IWUSR, offsetof(struct RGF_ICR, ICR), doff_io32},
  318. {"ICM", S_IRUGO | S_IWUSR, offsetof(struct RGF_ICR, ICM), doff_io32},
  319. {"ICS", S_IWUSR, offsetof(struct RGF_ICR, ICS), doff_io32},
  320. {"IMV", S_IRUGO | S_IWUSR, offsetof(struct RGF_ICR, IMV), doff_io32},
  321. {"IMS", S_IWUSR, offsetof(struct RGF_ICR, IMS), doff_io32},
  322. {"IMC", S_IWUSR, offsetof(struct RGF_ICR, IMC), doff_io32},
  323. {},
  324. };
  325. static int wil6210_debugfs_create_ISR(struct wil6210_priv *wil,
  326. const char *name,
  327. struct dentry *parent, u32 off)
  328. {
  329. struct dentry *d = debugfs_create_dir(name, parent);
  330. if (IS_ERR_OR_NULL(d))
  331. return -ENODEV;
  332. wil6210_debugfs_init_offset(wil, d, (void * __force)wil->csr + off,
  333. isr_off);
  334. return 0;
  335. }
  336. static const struct dbg_off pseudo_isr_off[] = {
  337. {"CAUSE", S_IRUGO, HOSTADDR(RGF_DMA_PSEUDO_CAUSE), doff_io32},
  338. {"MASK_SW", S_IRUGO, HOSTADDR(RGF_DMA_PSEUDO_CAUSE_MASK_SW), doff_io32},
  339. {"MASK_FW", S_IRUGO, HOSTADDR(RGF_DMA_PSEUDO_CAUSE_MASK_FW), doff_io32},
  340. {},
  341. };
  342. static int wil6210_debugfs_create_pseudo_ISR(struct wil6210_priv *wil,
  343. struct dentry *parent)
  344. {
  345. struct dentry *d = debugfs_create_dir("PSEUDO_ISR", parent);
  346. if (IS_ERR_OR_NULL(d))
  347. return -ENODEV;
  348. wil6210_debugfs_init_offset(wil, d, (void * __force)wil->csr,
  349. pseudo_isr_off);
  350. return 0;
  351. }
  352. static const struct dbg_off lgc_itr_cnt_off[] = {
  353. {"TRSH", S_IRUGO | S_IWUSR, HOSTADDR(RGF_DMA_ITR_CNT_TRSH), doff_io32},
  354. {"DATA", S_IRUGO | S_IWUSR, HOSTADDR(RGF_DMA_ITR_CNT_DATA), doff_io32},
  355. {"CTL", S_IRUGO | S_IWUSR, HOSTADDR(RGF_DMA_ITR_CNT_CRL), doff_io32},
  356. {},
  357. };
  358. static const struct dbg_off tx_itr_cnt_off[] = {
  359. {"TRSH", S_IRUGO | S_IWUSR, HOSTADDR(RGF_DMA_ITR_TX_CNT_TRSH),
  360. doff_io32},
  361. {"DATA", S_IRUGO | S_IWUSR, HOSTADDR(RGF_DMA_ITR_TX_CNT_DATA),
  362. doff_io32},
  363. {"CTL", S_IRUGO | S_IWUSR, HOSTADDR(RGF_DMA_ITR_TX_CNT_CTL),
  364. doff_io32},
  365. {"IDL_TRSH", S_IRUGO | S_IWUSR, HOSTADDR(RGF_DMA_ITR_TX_IDL_CNT_TRSH),
  366. doff_io32},
  367. {"IDL_DATA", S_IRUGO | S_IWUSR, HOSTADDR(RGF_DMA_ITR_TX_IDL_CNT_DATA),
  368. doff_io32},
  369. {"IDL_CTL", S_IRUGO | S_IWUSR, HOSTADDR(RGF_DMA_ITR_TX_IDL_CNT_CTL),
  370. doff_io32},
  371. {},
  372. };
  373. static const struct dbg_off rx_itr_cnt_off[] = {
  374. {"TRSH", S_IRUGO | S_IWUSR, HOSTADDR(RGF_DMA_ITR_RX_CNT_TRSH),
  375. doff_io32},
  376. {"DATA", S_IRUGO | S_IWUSR, HOSTADDR(RGF_DMA_ITR_RX_CNT_DATA),
  377. doff_io32},
  378. {"CTL", S_IRUGO | S_IWUSR, HOSTADDR(RGF_DMA_ITR_RX_CNT_CTL),
  379. doff_io32},
  380. {"IDL_TRSH", S_IRUGO | S_IWUSR, HOSTADDR(RGF_DMA_ITR_RX_IDL_CNT_TRSH),
  381. doff_io32},
  382. {"IDL_DATA", S_IRUGO | S_IWUSR, HOSTADDR(RGF_DMA_ITR_RX_IDL_CNT_DATA),
  383. doff_io32},
  384. {"IDL_CTL", S_IRUGO | S_IWUSR, HOSTADDR(RGF_DMA_ITR_RX_IDL_CNT_CTL),
  385. doff_io32},
  386. {},
  387. };
  388. static int wil6210_debugfs_create_ITR_CNT(struct wil6210_priv *wil,
  389. struct dentry *parent)
  390. {
  391. struct dentry *d, *dtx, *drx;
  392. d = debugfs_create_dir("ITR_CNT", parent);
  393. if (IS_ERR_OR_NULL(d))
  394. return -ENODEV;
  395. dtx = debugfs_create_dir("TX", d);
  396. drx = debugfs_create_dir("RX", d);
  397. if (IS_ERR_OR_NULL(dtx) || IS_ERR_OR_NULL(drx))
  398. return -ENODEV;
  399. wil6210_debugfs_init_offset(wil, d, (void * __force)wil->csr,
  400. lgc_itr_cnt_off);
  401. wil6210_debugfs_init_offset(wil, dtx, (void * __force)wil->csr,
  402. tx_itr_cnt_off);
  403. wil6210_debugfs_init_offset(wil, drx, (void * __force)wil->csr,
  404. rx_itr_cnt_off);
  405. return 0;
  406. }
  407. static int wil_memread_debugfs_show(struct seq_file *s, void *data)
  408. {
  409. struct wil6210_priv *wil = s->private;
  410. void __iomem *a = wmi_buffer(wil, cpu_to_le32(mem_addr));
  411. if (a)
  412. seq_printf(s, "[0x%08x] = 0x%08x\n", mem_addr, readl(a));
  413. else
  414. seq_printf(s, "[0x%08x] = INVALID\n", mem_addr);
  415. return 0;
  416. }
  417. static int wil_memread_seq_open(struct inode *inode, struct file *file)
  418. {
  419. return single_open(file, wil_memread_debugfs_show, inode->i_private);
  420. }
  421. static const struct file_operations fops_memread = {
  422. .open = wil_memread_seq_open,
  423. .release = single_release,
  424. .read = seq_read,
  425. .llseek = seq_lseek,
  426. };
  427. static ssize_t wil_read_file_ioblob(struct file *file, char __user *user_buf,
  428. size_t count, loff_t *ppos)
  429. {
  430. enum { max_count = 4096 };
  431. struct wil_blob_wrapper *wil_blob = file->private_data;
  432. loff_t pos = *ppos;
  433. size_t available = wil_blob->blob.size;
  434. void *buf;
  435. size_t ret;
  436. if (pos < 0)
  437. return -EINVAL;
  438. if (pos >= available || !count)
  439. return 0;
  440. if (count > available - pos)
  441. count = available - pos;
  442. if (count > max_count)
  443. count = max_count;
  444. buf = kmalloc(count, GFP_KERNEL);
  445. if (!buf)
  446. return -ENOMEM;
  447. wil_memcpy_fromio_halp_vote(wil_blob->wil, buf,
  448. (const volatile void __iomem *)
  449. wil_blob->blob.data + pos, count);
  450. ret = copy_to_user(user_buf, buf, count);
  451. kfree(buf);
  452. if (ret == count)
  453. return -EFAULT;
  454. count -= ret;
  455. *ppos = pos + count;
  456. return count;
  457. }
  458. static const struct file_operations fops_ioblob = {
  459. .read = wil_read_file_ioblob,
  460. .open = simple_open,
  461. .llseek = default_llseek,
  462. };
  463. static
  464. struct dentry *wil_debugfs_create_ioblob(const char *name,
  465. umode_t mode,
  466. struct dentry *parent,
  467. struct wil_blob_wrapper *wil_blob)
  468. {
  469. return debugfs_create_file(name, mode, parent, wil_blob, &fops_ioblob);
  470. }
  471. /*---reset---*/
  472. static ssize_t wil_write_file_reset(struct file *file, const char __user *buf,
  473. size_t len, loff_t *ppos)
  474. {
  475. struct wil6210_priv *wil = file->private_data;
  476. struct net_device *ndev = wil_to_ndev(wil);
  477. /**
  478. * BUG:
  479. * this code does NOT sync device state with the rest of system
  480. * use with care, debug only!!!
  481. */
  482. rtnl_lock();
  483. dev_close(ndev);
  484. ndev->flags &= ~IFF_UP;
  485. rtnl_unlock();
  486. wil_reset(wil, true);
  487. return len;
  488. }
  489. static const struct file_operations fops_reset = {
  490. .write = wil_write_file_reset,
  491. .open = simple_open,
  492. };
  493. /*---write channel 1..4 to rxon for it, 0 to rxoff---*/
  494. static ssize_t wil_write_file_rxon(struct file *file, const char __user *buf,
  495. size_t len, loff_t *ppos)
  496. {
  497. struct wil6210_priv *wil = file->private_data;
  498. int rc;
  499. long channel;
  500. bool on;
  501. char *kbuf = memdup_user_nul(buf, len);
  502. if (IS_ERR(kbuf))
  503. return PTR_ERR(kbuf);
  504. rc = kstrtol(kbuf, 0, &channel);
  505. kfree(kbuf);
  506. if (rc)
  507. return rc;
  508. if ((channel < 0) || (channel > 4)) {
  509. wil_err(wil, "Invalid channel %ld\n", channel);
  510. return -EINVAL;
  511. }
  512. on = !!channel;
  513. if (on) {
  514. rc = wmi_set_channel(wil, (int)channel);
  515. if (rc)
  516. return rc;
  517. }
  518. rc = wmi_rxon(wil, on);
  519. if (rc)
  520. return rc;
  521. return len;
  522. }
  523. static const struct file_operations fops_rxon = {
  524. .write = wil_write_file_rxon,
  525. .open = simple_open,
  526. };
  527. /* block ack control, write:
  528. * - "add <ringid> <agg_size> <timeout>" to trigger ADDBA
  529. * - "del_tx <ringid> <reason>" to trigger DELBA for Tx side
  530. * - "del_rx <CID> <TID> <reason>" to trigger DELBA for Rx side
  531. */
  532. static ssize_t wil_write_back(struct file *file, const char __user *buf,
  533. size_t len, loff_t *ppos)
  534. {
  535. struct wil6210_priv *wil = file->private_data;
  536. int rc;
  537. char *kbuf = kmalloc(len + 1, GFP_KERNEL);
  538. char cmd[9];
  539. int p1, p2, p3;
  540. if (!kbuf)
  541. return -ENOMEM;
  542. rc = simple_write_to_buffer(kbuf, len, ppos, buf, len);
  543. if (rc != len) {
  544. kfree(kbuf);
  545. return rc >= 0 ? -EIO : rc;
  546. }
  547. kbuf[len] = '\0';
  548. rc = sscanf(kbuf, "%8s %d %d %d", cmd, &p1, &p2, &p3);
  549. kfree(kbuf);
  550. if (rc < 0)
  551. return rc;
  552. if (rc < 2)
  553. return -EINVAL;
  554. if (0 == strcmp(cmd, "add")) {
  555. if (rc < 3) {
  556. wil_err(wil, "BACK: add require at least 2 params\n");
  557. return -EINVAL;
  558. }
  559. if (rc < 4)
  560. p3 = 0;
  561. wmi_addba(wil, p1, p2, p3);
  562. } else if (0 == strcmp(cmd, "del_tx")) {
  563. if (rc < 3)
  564. p2 = WLAN_REASON_QSTA_LEAVE_QBSS;
  565. wmi_delba_tx(wil, p1, p2);
  566. } else if (0 == strcmp(cmd, "del_rx")) {
  567. if (rc < 3) {
  568. wil_err(wil,
  569. "BACK: del_rx require at least 2 params\n");
  570. return -EINVAL;
  571. }
  572. if (rc < 4)
  573. p3 = WLAN_REASON_QSTA_LEAVE_QBSS;
  574. wmi_delba_rx(wil, mk_cidxtid(p1, p2), p3);
  575. } else {
  576. wil_err(wil, "BACK: Unrecognized command \"%s\"\n", cmd);
  577. return -EINVAL;
  578. }
  579. return len;
  580. }
  581. static ssize_t wil_read_back(struct file *file, char __user *user_buf,
  582. size_t count, loff_t *ppos)
  583. {
  584. static const char text[] = "block ack control, write:\n"
  585. " - \"add <ringid> <agg_size> <timeout>\" to trigger ADDBA\n"
  586. "If missing, <timeout> defaults to 0\n"
  587. " - \"del_tx <ringid> <reason>\" to trigger DELBA for Tx side\n"
  588. " - \"del_rx <CID> <TID> <reason>\" to trigger DELBA for Rx side\n"
  589. "If missing, <reason> set to \"STA_LEAVING\" (36)\n";
  590. return simple_read_from_buffer(user_buf, count, ppos, text,
  591. sizeof(text));
  592. }
  593. static const struct file_operations fops_back = {
  594. .read = wil_read_back,
  595. .write = wil_write_back,
  596. .open = simple_open,
  597. };
  598. /* pmc control, write:
  599. * - "alloc <num descriptors> <descriptor_size>" to allocate PMC
  600. * - "free" to release memory allocated for PMC
  601. */
  602. static ssize_t wil_write_pmccfg(struct file *file, const char __user *buf,
  603. size_t len, loff_t *ppos)
  604. {
  605. struct wil6210_priv *wil = file->private_data;
  606. int rc;
  607. char *kbuf = kmalloc(len + 1, GFP_KERNEL);
  608. char cmd[9];
  609. int num_descs, desc_size;
  610. if (!kbuf)
  611. return -ENOMEM;
  612. rc = simple_write_to_buffer(kbuf, len, ppos, buf, len);
  613. if (rc != len) {
  614. kfree(kbuf);
  615. return rc >= 0 ? -EIO : rc;
  616. }
  617. kbuf[len] = '\0';
  618. rc = sscanf(kbuf, "%8s %d %d", cmd, &num_descs, &desc_size);
  619. kfree(kbuf);
  620. if (rc < 0)
  621. return rc;
  622. if (rc < 1) {
  623. wil_err(wil, "pmccfg: no params given\n");
  624. return -EINVAL;
  625. }
  626. if (0 == strcmp(cmd, "alloc")) {
  627. if (rc != 3) {
  628. wil_err(wil, "pmccfg: alloc requires 2 params\n");
  629. return -EINVAL;
  630. }
  631. wil_pmc_alloc(wil, num_descs, desc_size);
  632. } else if (0 == strcmp(cmd, "free")) {
  633. if (rc != 1) {
  634. wil_err(wil, "pmccfg: free does not have any params\n");
  635. return -EINVAL;
  636. }
  637. wil_pmc_free(wil, true);
  638. } else {
  639. wil_err(wil, "pmccfg: Unrecognized command \"%s\"\n", cmd);
  640. return -EINVAL;
  641. }
  642. return len;
  643. }
  644. static ssize_t wil_read_pmccfg(struct file *file, char __user *user_buf,
  645. size_t count, loff_t *ppos)
  646. {
  647. struct wil6210_priv *wil = file->private_data;
  648. char text[256];
  649. char help[] = "pmc control, write:\n"
  650. " - \"alloc <num descriptors> <descriptor_size>\" to allocate pmc\n"
  651. " - \"free\" to free memory allocated for pmc\n";
  652. sprintf(text, "Last command status: %d\n\n%s",
  653. wil_pmc_last_cmd_status(wil),
  654. help);
  655. return simple_read_from_buffer(user_buf, count, ppos, text,
  656. strlen(text) + 1);
  657. }
  658. static const struct file_operations fops_pmccfg = {
  659. .read = wil_read_pmccfg,
  660. .write = wil_write_pmccfg,
  661. .open = simple_open,
  662. };
  663. static const struct file_operations fops_pmcdata = {
  664. .open = simple_open,
  665. .read = wil_pmc_read,
  666. .llseek = wil_pmc_llseek,
  667. };
  668. /*---tx_mgmt---*/
  669. /* Write mgmt frame to this file to send it */
  670. static ssize_t wil_write_file_txmgmt(struct file *file, const char __user *buf,
  671. size_t len, loff_t *ppos)
  672. {
  673. struct wil6210_priv *wil = file->private_data;
  674. struct wiphy *wiphy = wil_to_wiphy(wil);
  675. struct wireless_dev *wdev = wil_to_wdev(wil);
  676. struct cfg80211_mgmt_tx_params params;
  677. int rc;
  678. void *frame = kmalloc(len, GFP_KERNEL);
  679. if (!frame)
  680. return -ENOMEM;
  681. if (copy_from_user(frame, buf, len)) {
  682. kfree(frame);
  683. return -EIO;
  684. }
  685. params.buf = frame;
  686. params.len = len;
  687. params.chan = wdev->preset_chandef.chan;
  688. rc = wil_cfg80211_mgmt_tx(wiphy, wdev, &params, NULL);
  689. kfree(frame);
  690. wil_info(wil, "%s() -> %d\n", __func__, rc);
  691. return len;
  692. }
  693. static const struct file_operations fops_txmgmt = {
  694. .write = wil_write_file_txmgmt,
  695. .open = simple_open,
  696. };
  697. /* Write WMI command (w/o mbox header) to this file to send it
  698. * WMI starts from wil6210_mbox_hdr_wmi header
  699. */
  700. static ssize_t wil_write_file_wmi(struct file *file, const char __user *buf,
  701. size_t len, loff_t *ppos)
  702. {
  703. struct wil6210_priv *wil = file->private_data;
  704. struct wmi_cmd_hdr *wmi;
  705. void *cmd;
  706. int cmdlen = len - sizeof(struct wmi_cmd_hdr);
  707. u16 cmdid;
  708. int rc, rc1;
  709. if (cmdlen < 0)
  710. return -EINVAL;
  711. wmi = kmalloc(len, GFP_KERNEL);
  712. if (!wmi)
  713. return -ENOMEM;
  714. rc = simple_write_to_buffer(wmi, len, ppos, buf, len);
  715. if (rc < 0) {
  716. kfree(wmi);
  717. return rc;
  718. }
  719. cmd = (cmdlen > 0) ? &wmi[1] : NULL;
  720. cmdid = le16_to_cpu(wmi->command_id);
  721. rc1 = wmi_send(wil, cmdid, cmd, cmdlen);
  722. kfree(wmi);
  723. wil_info(wil, "%s(0x%04x[%d]) -> %d\n", __func__, cmdid, cmdlen, rc1);
  724. return rc;
  725. }
  726. static const struct file_operations fops_wmi = {
  727. .write = wil_write_file_wmi,
  728. .open = simple_open,
  729. };
  730. static void wil_seq_print_skb(struct seq_file *s, struct sk_buff *skb)
  731. {
  732. int i = 0;
  733. int len = skb_headlen(skb);
  734. void *p = skb->data;
  735. int nr_frags = skb_shinfo(skb)->nr_frags;
  736. seq_printf(s, " len = %d\n", len);
  737. wil_seq_hexdump(s, p, len, " : ");
  738. if (nr_frags) {
  739. seq_printf(s, " nr_frags = %d\n", nr_frags);
  740. for (i = 0; i < nr_frags; i++) {
  741. const struct skb_frag_struct *frag =
  742. &skb_shinfo(skb)->frags[i];
  743. len = skb_frag_size(frag);
  744. p = skb_frag_address_safe(frag);
  745. seq_printf(s, " [%2d] : len = %d\n", i, len);
  746. wil_seq_hexdump(s, p, len, " : ");
  747. }
  748. }
  749. }
  750. /*---------Tx/Rx descriptor------------*/
  751. static int wil_txdesc_debugfs_show(struct seq_file *s, void *data)
  752. {
  753. struct wil6210_priv *wil = s->private;
  754. struct vring *vring;
  755. bool tx = (dbg_vring_index < WIL6210_MAX_TX_RINGS);
  756. vring = tx ? &wil->vring_tx[dbg_vring_index] : &wil->vring_rx;
  757. if (!vring->va) {
  758. if (tx)
  759. seq_printf(s, "No Tx[%2d] VRING\n", dbg_vring_index);
  760. else
  761. seq_puts(s, "No Rx VRING\n");
  762. return 0;
  763. }
  764. if (dbg_txdesc_index < vring->size) {
  765. /* use struct vring_tx_desc for Rx as well,
  766. * only field used, .dma.length, is the same
  767. */
  768. volatile struct vring_tx_desc *d =
  769. &vring->va[dbg_txdesc_index].tx;
  770. volatile u32 *u = (volatile u32 *)d;
  771. struct sk_buff *skb = vring->ctx[dbg_txdesc_index].skb;
  772. if (tx)
  773. seq_printf(s, "Tx[%2d][%3d] = {\n", dbg_vring_index,
  774. dbg_txdesc_index);
  775. else
  776. seq_printf(s, "Rx[%3d] = {\n", dbg_txdesc_index);
  777. seq_printf(s, " MAC = 0x%08x 0x%08x 0x%08x 0x%08x\n",
  778. u[0], u[1], u[2], u[3]);
  779. seq_printf(s, " DMA = 0x%08x 0x%08x 0x%08x 0x%08x\n",
  780. u[4], u[5], u[6], u[7]);
  781. seq_printf(s, " SKB = 0x%p\n", skb);
  782. if (skb) {
  783. skb_get(skb);
  784. wil_seq_print_skb(s, skb);
  785. kfree_skb(skb);
  786. }
  787. seq_puts(s, "}\n");
  788. } else {
  789. if (tx)
  790. seq_printf(s, "[%2d] TxDesc index (%d) >= size (%d)\n",
  791. dbg_vring_index, dbg_txdesc_index,
  792. vring->size);
  793. else
  794. seq_printf(s, "RxDesc index (%d) >= size (%d)\n",
  795. dbg_txdesc_index, vring->size);
  796. }
  797. return 0;
  798. }
  799. static int wil_txdesc_seq_open(struct inode *inode, struct file *file)
  800. {
  801. return single_open(file, wil_txdesc_debugfs_show, inode->i_private);
  802. }
  803. static const struct file_operations fops_txdesc = {
  804. .open = wil_txdesc_seq_open,
  805. .release = single_release,
  806. .read = seq_read,
  807. .llseek = seq_lseek,
  808. };
  809. /*---------beamforming------------*/
  810. static char *wil_bfstatus_str(u32 status)
  811. {
  812. switch (status) {
  813. case 0:
  814. return "Failed";
  815. case 1:
  816. return "OK";
  817. case 2:
  818. return "Retrying";
  819. default:
  820. return "??";
  821. }
  822. }
  823. static bool is_all_zeros(void * const x_, size_t sz)
  824. {
  825. /* if reply is all-0, ignore this CID */
  826. u32 *x = x_;
  827. int n;
  828. for (n = 0; n < sz / sizeof(*x); n++)
  829. if (x[n])
  830. return false;
  831. return true;
  832. }
  833. static int wil_bf_debugfs_show(struct seq_file *s, void *data)
  834. {
  835. int rc;
  836. int i;
  837. struct wil6210_priv *wil = s->private;
  838. struct wmi_notify_req_cmd cmd = {
  839. .interval_usec = 0,
  840. };
  841. struct {
  842. struct wmi_cmd_hdr wmi;
  843. struct wmi_notify_req_done_event evt;
  844. } __packed reply;
  845. for (i = 0; i < ARRAY_SIZE(wil->sta); i++) {
  846. u32 status;
  847. cmd.cid = i;
  848. rc = wmi_call(wil, WMI_NOTIFY_REQ_CMDID, &cmd, sizeof(cmd),
  849. WMI_NOTIFY_REQ_DONE_EVENTID, &reply,
  850. sizeof(reply), 20);
  851. /* if reply is all-0, ignore this CID */
  852. if (rc || is_all_zeros(&reply.evt, sizeof(reply.evt)))
  853. continue;
  854. status = le32_to_cpu(reply.evt.status);
  855. seq_printf(s, "CID %d {\n"
  856. " TSF = 0x%016llx\n"
  857. " TxMCS = %2d TxTpt = %4d\n"
  858. " SQI = %4d\n"
  859. " Status = 0x%08x %s\n"
  860. " Sectors(rx:tx) my %2d:%2d peer %2d:%2d\n"
  861. " Goodput(rx:tx) %4d:%4d\n"
  862. "}\n",
  863. i,
  864. le64_to_cpu(reply.evt.tsf),
  865. le16_to_cpu(reply.evt.bf_mcs),
  866. le32_to_cpu(reply.evt.tx_tpt),
  867. reply.evt.sqi,
  868. status, wil_bfstatus_str(status),
  869. le16_to_cpu(reply.evt.my_rx_sector),
  870. le16_to_cpu(reply.evt.my_tx_sector),
  871. le16_to_cpu(reply.evt.other_rx_sector),
  872. le16_to_cpu(reply.evt.other_tx_sector),
  873. le32_to_cpu(reply.evt.rx_goodput),
  874. le32_to_cpu(reply.evt.tx_goodput));
  875. }
  876. return 0;
  877. }
  878. static int wil_bf_seq_open(struct inode *inode, struct file *file)
  879. {
  880. return single_open(file, wil_bf_debugfs_show, inode->i_private);
  881. }
  882. static const struct file_operations fops_bf = {
  883. .open = wil_bf_seq_open,
  884. .release = single_release,
  885. .read = seq_read,
  886. .llseek = seq_lseek,
  887. };
  888. /*---------SSID------------*/
  889. static ssize_t wil_read_file_ssid(struct file *file, char __user *user_buf,
  890. size_t count, loff_t *ppos)
  891. {
  892. struct wil6210_priv *wil = file->private_data;
  893. struct wireless_dev *wdev = wil_to_wdev(wil);
  894. return simple_read_from_buffer(user_buf, count, ppos,
  895. wdev->ssid, wdev->ssid_len);
  896. }
  897. static ssize_t wil_write_file_ssid(struct file *file, const char __user *buf,
  898. size_t count, loff_t *ppos)
  899. {
  900. struct wil6210_priv *wil = file->private_data;
  901. struct wireless_dev *wdev = wil_to_wdev(wil);
  902. struct net_device *ndev = wil_to_ndev(wil);
  903. if (*ppos != 0) {
  904. wil_err(wil, "Unable to set SSID substring from [%d]\n",
  905. (int)*ppos);
  906. return -EINVAL;
  907. }
  908. if (count > sizeof(wdev->ssid)) {
  909. wil_err(wil, "SSID too long, len = %d\n", (int)count);
  910. return -EINVAL;
  911. }
  912. if (netif_running(ndev)) {
  913. wil_err(wil, "Unable to change SSID on running interface\n");
  914. return -EINVAL;
  915. }
  916. wdev->ssid_len = count;
  917. return simple_write_to_buffer(wdev->ssid, wdev->ssid_len, ppos,
  918. buf, count);
  919. }
  920. static const struct file_operations fops_ssid = {
  921. .read = wil_read_file_ssid,
  922. .write = wil_write_file_ssid,
  923. .open = simple_open,
  924. };
  925. /*---------temp------------*/
  926. static void print_temp(struct seq_file *s, const char *prefix, u32 t)
  927. {
  928. switch (t) {
  929. case 0:
  930. case ~(u32)0:
  931. seq_printf(s, "%s N/A\n", prefix);
  932. break;
  933. default:
  934. seq_printf(s, "%s %d.%03d\n", prefix, t / 1000, t % 1000);
  935. break;
  936. }
  937. }
  938. static int wil_temp_debugfs_show(struct seq_file *s, void *data)
  939. {
  940. struct wil6210_priv *wil = s->private;
  941. u32 t_m, t_r;
  942. int rc = wmi_get_temperature(wil, &t_m, &t_r);
  943. if (rc) {
  944. seq_puts(s, "Failed\n");
  945. return 0;
  946. }
  947. print_temp(s, "T_mac =", t_m);
  948. print_temp(s, "T_radio =", t_r);
  949. return 0;
  950. }
  951. static int wil_temp_seq_open(struct inode *inode, struct file *file)
  952. {
  953. return single_open(file, wil_temp_debugfs_show, inode->i_private);
  954. }
  955. static const struct file_operations fops_temp = {
  956. .open = wil_temp_seq_open,
  957. .release = single_release,
  958. .read = seq_read,
  959. .llseek = seq_lseek,
  960. };
  961. /*---------freq------------*/
  962. static int wil_freq_debugfs_show(struct seq_file *s, void *data)
  963. {
  964. struct wil6210_priv *wil = s->private;
  965. struct wireless_dev *wdev = wil_to_wdev(wil);
  966. u16 freq = wdev->chandef.chan ? wdev->chandef.chan->center_freq : 0;
  967. seq_printf(s, "Freq = %d\n", freq);
  968. return 0;
  969. }
  970. static int wil_freq_seq_open(struct inode *inode, struct file *file)
  971. {
  972. return single_open(file, wil_freq_debugfs_show, inode->i_private);
  973. }
  974. static const struct file_operations fops_freq = {
  975. .open = wil_freq_seq_open,
  976. .release = single_release,
  977. .read = seq_read,
  978. .llseek = seq_lseek,
  979. };
  980. /*---------link------------*/
  981. static int wil_link_debugfs_show(struct seq_file *s, void *data)
  982. {
  983. struct wil6210_priv *wil = s->private;
  984. struct station_info sinfo;
  985. int i, rc;
  986. for (i = 0; i < ARRAY_SIZE(wil->sta); i++) {
  987. struct wil_sta_info *p = &wil->sta[i];
  988. char *status = "unknown";
  989. switch (p->status) {
  990. case wil_sta_unused:
  991. status = "unused ";
  992. break;
  993. case wil_sta_conn_pending:
  994. status = "pending ";
  995. break;
  996. case wil_sta_connected:
  997. status = "connected";
  998. break;
  999. }
  1000. seq_printf(s, "[%d] %pM %s\n", i, p->addr, status);
  1001. if (p->status == wil_sta_connected) {
  1002. rc = wil_cid_fill_sinfo(wil, i, &sinfo);
  1003. if (rc)
  1004. return rc;
  1005. seq_printf(s, " Tx_mcs = %d\n", sinfo.txrate.mcs);
  1006. seq_printf(s, " Rx_mcs = %d\n", sinfo.rxrate.mcs);
  1007. seq_printf(s, " SQ = %d\n", sinfo.signal);
  1008. }
  1009. }
  1010. return 0;
  1011. }
  1012. static int wil_link_seq_open(struct inode *inode, struct file *file)
  1013. {
  1014. return single_open(file, wil_link_debugfs_show, inode->i_private);
  1015. }
  1016. static const struct file_operations fops_link = {
  1017. .open = wil_link_seq_open,
  1018. .release = single_release,
  1019. .read = seq_read,
  1020. .llseek = seq_lseek,
  1021. };
  1022. /*---------info------------*/
  1023. static int wil_info_debugfs_show(struct seq_file *s, void *data)
  1024. {
  1025. struct wil6210_priv *wil = s->private;
  1026. struct net_device *ndev = wil_to_ndev(wil);
  1027. int is_ac = power_supply_is_system_supplied();
  1028. int rx = atomic_xchg(&wil->isr_count_rx, 0);
  1029. int tx = atomic_xchg(&wil->isr_count_tx, 0);
  1030. static ulong rxf_old, txf_old;
  1031. ulong rxf = ndev->stats.rx_packets;
  1032. ulong txf = ndev->stats.tx_packets;
  1033. unsigned int i;
  1034. /* >0 : AC; 0 : battery; <0 : error */
  1035. seq_printf(s, "AC powered : %d\n", is_ac);
  1036. seq_printf(s, "Rx irqs:packets : %8d : %8ld\n", rx, rxf - rxf_old);
  1037. seq_printf(s, "Tx irqs:packets : %8d : %8ld\n", tx, txf - txf_old);
  1038. rxf_old = rxf;
  1039. txf_old = txf;
  1040. #define CHECK_QSTATE(x) (state & BIT(__QUEUE_STATE_ ## x)) ? \
  1041. " " __stringify(x) : ""
  1042. for (i = 0; i < ndev->num_tx_queues; i++) {
  1043. struct netdev_queue *txq = netdev_get_tx_queue(ndev, i);
  1044. unsigned long state = txq->state;
  1045. seq_printf(s, "Tx queue[%i] state : 0x%lx%s%s%s\n", i, state,
  1046. CHECK_QSTATE(DRV_XOFF),
  1047. CHECK_QSTATE(STACK_XOFF),
  1048. CHECK_QSTATE(FROZEN)
  1049. );
  1050. }
  1051. #undef CHECK_QSTATE
  1052. return 0;
  1053. }
  1054. static int wil_info_seq_open(struct inode *inode, struct file *file)
  1055. {
  1056. return single_open(file, wil_info_debugfs_show, inode->i_private);
  1057. }
  1058. static const struct file_operations fops_info = {
  1059. .open = wil_info_seq_open,
  1060. .release = single_release,
  1061. .read = seq_read,
  1062. .llseek = seq_lseek,
  1063. };
  1064. /*---------recovery------------*/
  1065. /* mode = [manual|auto]
  1066. * state = [idle|pending|running]
  1067. */
  1068. static ssize_t wil_read_file_recovery(struct file *file, char __user *user_buf,
  1069. size_t count, loff_t *ppos)
  1070. {
  1071. struct wil6210_priv *wil = file->private_data;
  1072. char buf[80];
  1073. int n;
  1074. static const char * const sstate[] = {"idle", "pending", "running"};
  1075. n = snprintf(buf, sizeof(buf), "mode = %s\nstate = %s\n",
  1076. no_fw_recovery ? "manual" : "auto",
  1077. sstate[wil->recovery_state]);
  1078. n = min_t(int, n, sizeof(buf));
  1079. return simple_read_from_buffer(user_buf, count, ppos,
  1080. buf, n);
  1081. }
  1082. static ssize_t wil_write_file_recovery(struct file *file,
  1083. const char __user *buf_,
  1084. size_t count, loff_t *ppos)
  1085. {
  1086. struct wil6210_priv *wil = file->private_data;
  1087. static const char run_command[] = "run";
  1088. char buf[sizeof(run_command) + 1]; /* to detect "runx" */
  1089. ssize_t rc;
  1090. if (wil->recovery_state != fw_recovery_pending) {
  1091. wil_err(wil, "No recovery pending\n");
  1092. return -EINVAL;
  1093. }
  1094. if (*ppos != 0) {
  1095. wil_err(wil, "Offset [%d]\n", (int)*ppos);
  1096. return -EINVAL;
  1097. }
  1098. if (count > sizeof(buf)) {
  1099. wil_err(wil, "Input too long, len = %d\n", (int)count);
  1100. return -EINVAL;
  1101. }
  1102. rc = simple_write_to_buffer(buf, sizeof(buf) - 1, ppos, buf_, count);
  1103. if (rc < 0)
  1104. return rc;
  1105. buf[rc] = '\0';
  1106. if (0 == strcmp(buf, run_command))
  1107. wil_set_recovery_state(wil, fw_recovery_running);
  1108. else
  1109. wil_err(wil, "Bad recovery command \"%s\"\n", buf);
  1110. return rc;
  1111. }
  1112. static const struct file_operations fops_recovery = {
  1113. .read = wil_read_file_recovery,
  1114. .write = wil_write_file_recovery,
  1115. .open = simple_open,
  1116. };
  1117. /*---------Station matrix------------*/
  1118. static void wil_print_rxtid(struct seq_file *s, struct wil_tid_ampdu_rx *r)
  1119. {
  1120. int i;
  1121. u16 index = ((r->head_seq_num - r->ssn) & 0xfff) % r->buf_size;
  1122. unsigned long long drop_dup = r->drop_dup, drop_old = r->drop_old;
  1123. seq_printf(s, "([%2d] %3d TU) 0x%03x [", r->buf_size, r->timeout,
  1124. r->head_seq_num);
  1125. for (i = 0; i < r->buf_size; i++) {
  1126. if (i == index)
  1127. seq_printf(s, "%c", r->reorder_buf[i] ? 'O' : '|');
  1128. else
  1129. seq_printf(s, "%c", r->reorder_buf[i] ? '*' : '_');
  1130. }
  1131. seq_printf(s,
  1132. "] total %llu drop %llu (dup %llu + old %llu) last 0x%03x\n",
  1133. r->total, drop_dup + drop_old, drop_dup, drop_old,
  1134. r->ssn_last_drop);
  1135. }
  1136. static void wil_print_rxtid_crypto(struct seq_file *s, int tid,
  1137. struct wil_tid_crypto_rx *c)
  1138. {
  1139. int i;
  1140. for (i = 0; i < 4; i++) {
  1141. struct wil_tid_crypto_rx_single *cc = &c->key_id[i];
  1142. if (cc->key_set)
  1143. goto has_keys;
  1144. }
  1145. return;
  1146. has_keys:
  1147. if (tid < WIL_STA_TID_NUM)
  1148. seq_printf(s, " [%2d] PN", tid);
  1149. else
  1150. seq_puts(s, " [GR] PN");
  1151. for (i = 0; i < 4; i++) {
  1152. struct wil_tid_crypto_rx_single *cc = &c->key_id[i];
  1153. seq_printf(s, " [%i%s]%6phN", i, cc->key_set ? "+" : "-",
  1154. cc->pn);
  1155. }
  1156. seq_puts(s, "\n");
  1157. }
  1158. static int wil_sta_debugfs_show(struct seq_file *s, void *data)
  1159. __acquires(&p->tid_rx_lock) __releases(&p->tid_rx_lock)
  1160. {
  1161. struct wil6210_priv *wil = s->private;
  1162. int i, tid, mcs;
  1163. for (i = 0; i < ARRAY_SIZE(wil->sta); i++) {
  1164. struct wil_sta_info *p = &wil->sta[i];
  1165. char *status = "unknown";
  1166. switch (p->status) {
  1167. case wil_sta_unused:
  1168. status = "unused ";
  1169. break;
  1170. case wil_sta_conn_pending:
  1171. status = "pending ";
  1172. break;
  1173. case wil_sta_connected:
  1174. status = "connected";
  1175. break;
  1176. }
  1177. seq_printf(s, "[%d] %pM %s\n", i, p->addr, status);
  1178. if (p->status == wil_sta_connected) {
  1179. spin_lock_bh(&p->tid_rx_lock);
  1180. for (tid = 0; tid < WIL_STA_TID_NUM; tid++) {
  1181. struct wil_tid_ampdu_rx *r = p->tid_rx[tid];
  1182. struct wil_tid_crypto_rx *c =
  1183. &p->tid_crypto_rx[tid];
  1184. if (r) {
  1185. seq_printf(s, " [%2d] ", tid);
  1186. wil_print_rxtid(s, r);
  1187. }
  1188. wil_print_rxtid_crypto(s, tid, c);
  1189. }
  1190. wil_print_rxtid_crypto(s, WIL_STA_TID_NUM,
  1191. &p->group_crypto_rx);
  1192. spin_unlock_bh(&p->tid_rx_lock);
  1193. seq_printf(s,
  1194. "Rx invalid frame: non-data %lu, short %lu, large %lu, replay %lu\n",
  1195. p->stats.rx_non_data_frame,
  1196. p->stats.rx_short_frame,
  1197. p->stats.rx_large_frame,
  1198. p->stats.rx_replay);
  1199. seq_puts(s, "Rx/MCS:");
  1200. for (mcs = 0; mcs < ARRAY_SIZE(p->stats.rx_per_mcs);
  1201. mcs++)
  1202. seq_printf(s, " %lld",
  1203. p->stats.rx_per_mcs[mcs]);
  1204. seq_puts(s, "\n");
  1205. }
  1206. }
  1207. return 0;
  1208. }
  1209. static int wil_sta_seq_open(struct inode *inode, struct file *file)
  1210. {
  1211. return single_open(file, wil_sta_debugfs_show, inode->i_private);
  1212. }
  1213. static const struct file_operations fops_sta = {
  1214. .open = wil_sta_seq_open,
  1215. .release = single_release,
  1216. .read = seq_read,
  1217. .llseek = seq_lseek,
  1218. };
  1219. static ssize_t wil_read_file_led_cfg(struct file *file, char __user *user_buf,
  1220. size_t count, loff_t *ppos)
  1221. {
  1222. char buf[80];
  1223. int n;
  1224. n = snprintf(buf, sizeof(buf),
  1225. "led_id is set to %d, echo 1 to enable, 0 to disable\n",
  1226. led_id);
  1227. n = min_t(int, n, sizeof(buf));
  1228. return simple_read_from_buffer(user_buf, count, ppos,
  1229. buf, n);
  1230. }
  1231. static ssize_t wil_write_file_led_cfg(struct file *file,
  1232. const char __user *buf_,
  1233. size_t count, loff_t *ppos)
  1234. {
  1235. struct wil6210_priv *wil = file->private_data;
  1236. int val;
  1237. int rc;
  1238. rc = kstrtoint_from_user(buf_, count, 0, &val);
  1239. if (rc) {
  1240. wil_err(wil, "Invalid argument\n");
  1241. return rc;
  1242. }
  1243. wil_info(wil, "%s led %d\n", val ? "Enabling" : "Disabling", led_id);
  1244. rc = wmi_led_cfg(wil, val);
  1245. if (rc) {
  1246. wil_info(wil, "%s led %d failed\n",
  1247. val ? "Enabling" : "Disabling", led_id);
  1248. return rc;
  1249. }
  1250. return count;
  1251. }
  1252. static const struct file_operations fops_led_cfg = {
  1253. .read = wil_read_file_led_cfg,
  1254. .write = wil_write_file_led_cfg,
  1255. .open = simple_open,
  1256. };
  1257. /* led_blink_time, write:
  1258. * "<blink_on_slow> <blink_off_slow> <blink_on_med> <blink_off_med> <blink_on_fast> <blink_off_fast>
  1259. */
  1260. static ssize_t wil_write_led_blink_time(struct file *file,
  1261. const char __user *buf,
  1262. size_t len, loff_t *ppos)
  1263. {
  1264. int rc;
  1265. char *kbuf = kmalloc(len + 1, GFP_KERNEL);
  1266. if (!kbuf)
  1267. return -ENOMEM;
  1268. rc = simple_write_to_buffer(kbuf, len, ppos, buf, len);
  1269. if (rc != len) {
  1270. kfree(kbuf);
  1271. return rc >= 0 ? -EIO : rc;
  1272. }
  1273. kbuf[len] = '\0';
  1274. rc = sscanf(kbuf, "%d %d %d %d %d %d",
  1275. &led_blink_time[WIL_LED_TIME_SLOW].on_ms,
  1276. &led_blink_time[WIL_LED_TIME_SLOW].off_ms,
  1277. &led_blink_time[WIL_LED_TIME_MED].on_ms,
  1278. &led_blink_time[WIL_LED_TIME_MED].off_ms,
  1279. &led_blink_time[WIL_LED_TIME_FAST].on_ms,
  1280. &led_blink_time[WIL_LED_TIME_FAST].off_ms);
  1281. kfree(kbuf);
  1282. if (rc < 0)
  1283. return rc;
  1284. if (rc < 6)
  1285. return -EINVAL;
  1286. return len;
  1287. }
  1288. static ssize_t wil_read_led_blink_time(struct file *file, char __user *user_buf,
  1289. size_t count, loff_t *ppos)
  1290. {
  1291. static char text[400];
  1292. snprintf(text, sizeof(text),
  1293. "To set led blink on/off time variables write:\n"
  1294. "<blink_on_slow> <blink_off_slow> <blink_on_med> "
  1295. "<blink_off_med> <blink_on_fast> <blink_off_fast>\n"
  1296. "The current values are:\n"
  1297. "%d %d %d %d %d %d\n",
  1298. led_blink_time[WIL_LED_TIME_SLOW].on_ms,
  1299. led_blink_time[WIL_LED_TIME_SLOW].off_ms,
  1300. led_blink_time[WIL_LED_TIME_MED].on_ms,
  1301. led_blink_time[WIL_LED_TIME_MED].off_ms,
  1302. led_blink_time[WIL_LED_TIME_FAST].on_ms,
  1303. led_blink_time[WIL_LED_TIME_FAST].off_ms);
  1304. return simple_read_from_buffer(user_buf, count, ppos, text,
  1305. sizeof(text));
  1306. }
  1307. static const struct file_operations fops_led_blink_time = {
  1308. .read = wil_read_led_blink_time,
  1309. .write = wil_write_led_blink_time,
  1310. .open = simple_open,
  1311. };
  1312. /*---------FW capabilities------------*/
  1313. static int wil_fw_capabilities_debugfs_show(struct seq_file *s, void *data)
  1314. {
  1315. struct wil6210_priv *wil = s->private;
  1316. seq_printf(s, "fw_capabilities : %*pb\n", WMI_FW_CAPABILITY_MAX,
  1317. wil->fw_capabilities);
  1318. return 0;
  1319. }
  1320. static int wil_fw_capabilities_seq_open(struct inode *inode, struct file *file)
  1321. {
  1322. return single_open(file, wil_fw_capabilities_debugfs_show,
  1323. inode->i_private);
  1324. }
  1325. static const struct file_operations fops_fw_capabilities = {
  1326. .open = wil_fw_capabilities_seq_open,
  1327. .release = single_release,
  1328. .read = seq_read,
  1329. .llseek = seq_lseek,
  1330. };
  1331. /*---------FW version------------*/
  1332. static int wil_fw_version_debugfs_show(struct seq_file *s, void *data)
  1333. {
  1334. struct wil6210_priv *wil = s->private;
  1335. if (wil->fw_version[0])
  1336. seq_printf(s, "%s\n", wil->fw_version);
  1337. else
  1338. seq_puts(s, "N/A\n");
  1339. return 0;
  1340. }
  1341. static int wil_fw_version_seq_open(struct inode *inode, struct file *file)
  1342. {
  1343. return single_open(file, wil_fw_version_debugfs_show,
  1344. inode->i_private);
  1345. }
  1346. static const struct file_operations fops_fw_version = {
  1347. .open = wil_fw_version_seq_open,
  1348. .release = single_release,
  1349. .read = seq_read,
  1350. .llseek = seq_lseek,
  1351. };
  1352. /*----------------*/
  1353. static void wil6210_debugfs_init_blobs(struct wil6210_priv *wil,
  1354. struct dentry *dbg)
  1355. {
  1356. int i;
  1357. char name[32];
  1358. for (i = 0; i < ARRAY_SIZE(fw_mapping); i++) {
  1359. struct wil_blob_wrapper *wil_blob = &wil->blobs[i];
  1360. struct debugfs_blob_wrapper *blob = &wil_blob->blob;
  1361. const struct fw_map *map = &fw_mapping[i];
  1362. if (!map->name)
  1363. continue;
  1364. wil_blob->wil = wil;
  1365. blob->data = (void * __force)wil->csr + HOSTADDR(map->host);
  1366. blob->size = map->to - map->from;
  1367. snprintf(name, sizeof(name), "blob_%s", map->name);
  1368. wil_debugfs_create_ioblob(name, S_IRUGO, dbg, wil_blob);
  1369. }
  1370. }
  1371. /* misc files */
  1372. static const struct {
  1373. const char *name;
  1374. umode_t mode;
  1375. const struct file_operations *fops;
  1376. } dbg_files[] = {
  1377. {"mbox", S_IRUGO, &fops_mbox},
  1378. {"vrings", S_IRUGO, &fops_vring},
  1379. {"stations", S_IRUGO, &fops_sta},
  1380. {"desc", S_IRUGO, &fops_txdesc},
  1381. {"bf", S_IRUGO, &fops_bf},
  1382. {"ssid", S_IRUGO | S_IWUSR, &fops_ssid},
  1383. {"mem_val", S_IRUGO, &fops_memread},
  1384. {"reset", S_IWUSR, &fops_reset},
  1385. {"rxon", S_IWUSR, &fops_rxon},
  1386. {"tx_mgmt", S_IWUSR, &fops_txmgmt},
  1387. {"wmi_send", S_IWUSR, &fops_wmi},
  1388. {"back", S_IRUGO | S_IWUSR, &fops_back},
  1389. {"pmccfg", S_IRUGO | S_IWUSR, &fops_pmccfg},
  1390. {"pmcdata", S_IRUGO, &fops_pmcdata},
  1391. {"temp", S_IRUGO, &fops_temp},
  1392. {"freq", S_IRUGO, &fops_freq},
  1393. {"link", S_IRUGO, &fops_link},
  1394. {"info", S_IRUGO, &fops_info},
  1395. {"recovery", S_IRUGO | S_IWUSR, &fops_recovery},
  1396. {"led_cfg", S_IRUGO | S_IWUSR, &fops_led_cfg},
  1397. {"led_blink_time", S_IRUGO | S_IWUSR, &fops_led_blink_time},
  1398. {"fw_capabilities", S_IRUGO, &fops_fw_capabilities},
  1399. {"fw_version", S_IRUGO, &fops_fw_version},
  1400. };
  1401. static void wil6210_debugfs_init_files(struct wil6210_priv *wil,
  1402. struct dentry *dbg)
  1403. {
  1404. int i;
  1405. for (i = 0; i < ARRAY_SIZE(dbg_files); i++)
  1406. debugfs_create_file(dbg_files[i].name, dbg_files[i].mode, dbg,
  1407. wil, dbg_files[i].fops);
  1408. }
  1409. /* interrupt control blocks */
  1410. static const struct {
  1411. const char *name;
  1412. u32 icr_off;
  1413. } dbg_icr[] = {
  1414. {"USER_ICR", HOSTADDR(RGF_USER_USER_ICR)},
  1415. {"DMA_EP_TX_ICR", HOSTADDR(RGF_DMA_EP_TX_ICR)},
  1416. {"DMA_EP_RX_ICR", HOSTADDR(RGF_DMA_EP_RX_ICR)},
  1417. {"DMA_EP_MISC_ICR", HOSTADDR(RGF_DMA_EP_MISC_ICR)},
  1418. };
  1419. static void wil6210_debugfs_init_isr(struct wil6210_priv *wil,
  1420. struct dentry *dbg)
  1421. {
  1422. int i;
  1423. for (i = 0; i < ARRAY_SIZE(dbg_icr); i++)
  1424. wil6210_debugfs_create_ISR(wil, dbg_icr[i].name, dbg,
  1425. dbg_icr[i].icr_off);
  1426. }
  1427. #define WIL_FIELD(name, mode, type) { __stringify(name), mode, \
  1428. offsetof(struct wil6210_priv, name), type}
  1429. /* fields in struct wil6210_priv */
  1430. static const struct dbg_off dbg_wil_off[] = {
  1431. WIL_FIELD(privacy, S_IRUGO, doff_u32),
  1432. WIL_FIELD(status[0], S_IRUGO | S_IWUSR, doff_ulong),
  1433. WIL_FIELD(hw_version, S_IRUGO, doff_x32),
  1434. WIL_FIELD(recovery_count, S_IRUGO, doff_u32),
  1435. WIL_FIELD(ap_isolate, S_IRUGO, doff_u32),
  1436. WIL_FIELD(discovery_mode, S_IRUGO | S_IWUSR, doff_u8),
  1437. {},
  1438. };
  1439. static const struct dbg_off dbg_wil_regs[] = {
  1440. {"RGF_MAC_MTRL_COUNTER_0", S_IRUGO, HOSTADDR(RGF_MAC_MTRL_COUNTER_0),
  1441. doff_io32},
  1442. {"RGF_USER_USAGE_1", S_IRUGO, HOSTADDR(RGF_USER_USAGE_1), doff_io32},
  1443. {},
  1444. };
  1445. /* static parameters */
  1446. static const struct dbg_off dbg_statics[] = {
  1447. {"desc_index", S_IRUGO | S_IWUSR, (ulong)&dbg_txdesc_index, doff_u32},
  1448. {"vring_index", S_IRUGO | S_IWUSR, (ulong)&dbg_vring_index, doff_u32},
  1449. {"mem_addr", S_IRUGO | S_IWUSR, (ulong)&mem_addr, doff_u32},
  1450. {"vring_idle_trsh", S_IRUGO | S_IWUSR, (ulong)&vring_idle_trsh,
  1451. doff_u32},
  1452. {"led_polarity", S_IRUGO | S_IWUSR, (ulong)&led_polarity, doff_u8},
  1453. {},
  1454. };
  1455. int wil6210_debugfs_init(struct wil6210_priv *wil)
  1456. {
  1457. struct dentry *dbg = wil->debug = debugfs_create_dir(WIL_NAME,
  1458. wil_to_wiphy(wil)->debugfsdir);
  1459. if (IS_ERR_OR_NULL(dbg))
  1460. return -ENODEV;
  1461. wil_pmc_init(wil);
  1462. wil6210_debugfs_init_files(wil, dbg);
  1463. wil6210_debugfs_init_isr(wil, dbg);
  1464. wil6210_debugfs_init_blobs(wil, dbg);
  1465. wil6210_debugfs_init_offset(wil, dbg, wil, dbg_wil_off);
  1466. wil6210_debugfs_init_offset(wil, dbg, (void * __force)wil->csr,
  1467. dbg_wil_regs);
  1468. wil6210_debugfs_init_offset(wil, dbg, NULL, dbg_statics);
  1469. wil6210_debugfs_create_pseudo_ISR(wil, dbg);
  1470. wil6210_debugfs_create_ITR_CNT(wil, dbg);
  1471. return 0;
  1472. }
  1473. void wil6210_debugfs_remove(struct wil6210_priv *wil)
  1474. {
  1475. debugfs_remove_recursive(wil->debug);
  1476. wil->debug = NULL;
  1477. /* free pmc memory without sending command to fw, as it will
  1478. * be reset on the way down anyway
  1479. */
  1480. wil_pmc_free(wil, false);
  1481. }