debugfs.c 48 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934
  1. /*
  2. * Copyright (c) 2012-2017 Qualcomm Atheros, Inc.
  3. * Copyright (c) 2018, The Linux Foundation. All rights reserved.
  4. *
  5. * Permission to use, copy, modify, and/or distribute this software for any
  6. * purpose with or without fee is hereby granted, provided that the above
  7. * copyright notice and this permission notice appear in all copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  10. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  11. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  12. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  13. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  14. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  15. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  16. */
  17. #include <linux/module.h>
  18. #include <linux/debugfs.h>
  19. #include <linux/seq_file.h>
  20. #include <linux/pci.h>
  21. #include <linux/rtnetlink.h>
  22. #include <linux/power_supply.h>
  23. #include "wil6210.h"
  24. #include "wmi.h"
  25. #include "txrx.h"
  26. #include "pmc.h"
  27. /* Nasty hack. Better have per device instances */
  28. static u32 mem_addr;
  29. static u32 dbg_txdesc_index;
  30. static u32 dbg_vring_index; /* 24+ for Rx, 0..23 for Tx */
  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. int ret;
  215. ret = wil_pm_runtime_get(wil);
  216. if (ret < 0)
  217. return ret;
  218. wil_print_ring(s, "tx", wil->csr + HOST_MBOX +
  219. offsetof(struct wil6210_mbox_ctl, tx));
  220. wil_print_ring(s, "rx", wil->csr + HOST_MBOX +
  221. offsetof(struct wil6210_mbox_ctl, rx));
  222. wil_pm_runtime_put(wil);
  223. return 0;
  224. }
  225. static int wil_mbox_seq_open(struct inode *inode, struct file *file)
  226. {
  227. return single_open(file, wil_mbox_debugfs_show, inode->i_private);
  228. }
  229. static const struct file_operations fops_mbox = {
  230. .open = wil_mbox_seq_open,
  231. .release = single_release,
  232. .read = seq_read,
  233. .llseek = seq_lseek,
  234. };
  235. static int wil_debugfs_iomem_x32_set(void *data, u64 val)
  236. {
  237. struct wil_debugfs_iomem_data *d = (struct
  238. wil_debugfs_iomem_data *)data;
  239. struct wil6210_priv *wil = d->wil;
  240. int ret;
  241. ret = wil_pm_runtime_get(wil);
  242. if (ret < 0)
  243. return ret;
  244. writel(val, (void __iomem *)d->offset);
  245. wmb(); /* make sure write propagated to HW */
  246. wil_pm_runtime_put(wil);
  247. return 0;
  248. }
  249. static int wil_debugfs_iomem_x32_get(void *data, u64 *val)
  250. {
  251. struct wil_debugfs_iomem_data *d = (struct
  252. wil_debugfs_iomem_data *)data;
  253. struct wil6210_priv *wil = d->wil;
  254. int ret;
  255. ret = wil_pm_runtime_get(wil);
  256. if (ret < 0)
  257. return ret;
  258. *val = readl((void __iomem *)d->offset);
  259. wil_pm_runtime_put(wil);
  260. return 0;
  261. }
  262. DEFINE_SIMPLE_ATTRIBUTE(fops_iomem_x32, wil_debugfs_iomem_x32_get,
  263. wil_debugfs_iomem_x32_set, "0x%08llx\n");
  264. static struct dentry *wil_debugfs_create_iomem_x32(const char *name,
  265. umode_t mode,
  266. struct dentry *parent,
  267. void *value,
  268. struct wil6210_priv *wil)
  269. {
  270. struct dentry *file;
  271. struct wil_debugfs_iomem_data *data = &wil->dbg_data.data_arr[
  272. wil->dbg_data.iomem_data_count];
  273. data->wil = wil;
  274. data->offset = value;
  275. file = debugfs_create_file(name, mode, parent, data, &fops_iomem_x32);
  276. if (!IS_ERR_OR_NULL(file))
  277. wil->dbg_data.iomem_data_count++;
  278. return file;
  279. }
  280. static int wil_debugfs_ulong_set(void *data, u64 val)
  281. {
  282. *(ulong *)data = val;
  283. return 0;
  284. }
  285. static int wil_debugfs_ulong_get(void *data, u64 *val)
  286. {
  287. *val = *(ulong *)data;
  288. return 0;
  289. }
  290. DEFINE_SIMPLE_ATTRIBUTE(wil_fops_ulong, wil_debugfs_ulong_get,
  291. wil_debugfs_ulong_set, "0x%llx\n");
  292. static struct dentry *wil_debugfs_create_ulong(const char *name, umode_t mode,
  293. struct dentry *parent,
  294. ulong *value)
  295. {
  296. return debugfs_create_file(name, mode, parent, value, &wil_fops_ulong);
  297. }
  298. /**
  299. * wil6210_debugfs_init_offset - create set of debugfs files
  300. * @wil - driver's context, used for printing
  301. * @dbg - directory on the debugfs, where files will be created
  302. * @base - base address used in address calculation
  303. * @tbl - table with file descriptions. Should be terminated with empty element.
  304. *
  305. * Creates files accordingly to the @tbl.
  306. */
  307. static void wil6210_debugfs_init_offset(struct wil6210_priv *wil,
  308. struct dentry *dbg, void *base,
  309. const struct dbg_off * const tbl)
  310. {
  311. int i;
  312. for (i = 0; tbl[i].name; i++) {
  313. struct dentry *f;
  314. switch (tbl[i].type) {
  315. case doff_u32:
  316. f = debugfs_create_u32(tbl[i].name, tbl[i].mode, dbg,
  317. base + tbl[i].off);
  318. break;
  319. case doff_x32:
  320. f = debugfs_create_x32(tbl[i].name, tbl[i].mode, dbg,
  321. base + tbl[i].off);
  322. break;
  323. case doff_ulong:
  324. f = wil_debugfs_create_ulong(tbl[i].name, tbl[i].mode,
  325. dbg, base + tbl[i].off);
  326. break;
  327. case doff_io32:
  328. f = wil_debugfs_create_iomem_x32(tbl[i].name,
  329. tbl[i].mode, dbg,
  330. base + tbl[i].off,
  331. wil);
  332. break;
  333. case doff_u8:
  334. f = debugfs_create_u8(tbl[i].name, tbl[i].mode, dbg,
  335. base + tbl[i].off);
  336. break;
  337. default:
  338. f = ERR_PTR(-EINVAL);
  339. }
  340. if (IS_ERR_OR_NULL(f))
  341. wil_err(wil, "Create file \"%s\": err %ld\n",
  342. tbl[i].name, PTR_ERR(f));
  343. }
  344. }
  345. static const struct dbg_off isr_off[] = {
  346. {"ICC", 0644, offsetof(struct RGF_ICR, ICC), doff_io32},
  347. {"ICR", 0644, offsetof(struct RGF_ICR, ICR), doff_io32},
  348. {"ICM", 0644, offsetof(struct RGF_ICR, ICM), doff_io32},
  349. {"ICS", 0244, offsetof(struct RGF_ICR, ICS), doff_io32},
  350. {"IMV", 0644, offsetof(struct RGF_ICR, IMV), doff_io32},
  351. {"IMS", 0244, offsetof(struct RGF_ICR, IMS), doff_io32},
  352. {"IMC", 0244, offsetof(struct RGF_ICR, IMC), doff_io32},
  353. {},
  354. };
  355. static int wil6210_debugfs_create_ISR(struct wil6210_priv *wil,
  356. const char *name,
  357. struct dentry *parent, u32 off)
  358. {
  359. struct dentry *d = debugfs_create_dir(name, parent);
  360. if (IS_ERR_OR_NULL(d))
  361. return -ENODEV;
  362. wil6210_debugfs_init_offset(wil, d, (void * __force)wil->csr + off,
  363. isr_off);
  364. return 0;
  365. }
  366. static const struct dbg_off pseudo_isr_off[] = {
  367. {"CAUSE", 0444, HOSTADDR(RGF_DMA_PSEUDO_CAUSE), doff_io32},
  368. {"MASK_SW", 0444, HOSTADDR(RGF_DMA_PSEUDO_CAUSE_MASK_SW), doff_io32},
  369. {"MASK_FW", 0444, HOSTADDR(RGF_DMA_PSEUDO_CAUSE_MASK_FW), doff_io32},
  370. {},
  371. };
  372. static int wil6210_debugfs_create_pseudo_ISR(struct wil6210_priv *wil,
  373. struct dentry *parent)
  374. {
  375. struct dentry *d = debugfs_create_dir("PSEUDO_ISR", parent);
  376. if (IS_ERR_OR_NULL(d))
  377. return -ENODEV;
  378. wil6210_debugfs_init_offset(wil, d, (void * __force)wil->csr,
  379. pseudo_isr_off);
  380. return 0;
  381. }
  382. static const struct dbg_off lgc_itr_cnt_off[] = {
  383. {"TRSH", 0644, HOSTADDR(RGF_DMA_ITR_CNT_TRSH), doff_io32},
  384. {"DATA", 0644, HOSTADDR(RGF_DMA_ITR_CNT_DATA), doff_io32},
  385. {"CTL", 0644, HOSTADDR(RGF_DMA_ITR_CNT_CRL), doff_io32},
  386. {},
  387. };
  388. static const struct dbg_off tx_itr_cnt_off[] = {
  389. {"TRSH", 0644, HOSTADDR(RGF_DMA_ITR_TX_CNT_TRSH),
  390. doff_io32},
  391. {"DATA", 0644, HOSTADDR(RGF_DMA_ITR_TX_CNT_DATA),
  392. doff_io32},
  393. {"CTL", 0644, HOSTADDR(RGF_DMA_ITR_TX_CNT_CTL),
  394. doff_io32},
  395. {"IDL_TRSH", 0644, HOSTADDR(RGF_DMA_ITR_TX_IDL_CNT_TRSH),
  396. doff_io32},
  397. {"IDL_DATA", 0644, HOSTADDR(RGF_DMA_ITR_TX_IDL_CNT_DATA),
  398. doff_io32},
  399. {"IDL_CTL", 0644, HOSTADDR(RGF_DMA_ITR_TX_IDL_CNT_CTL),
  400. doff_io32},
  401. {},
  402. };
  403. static const struct dbg_off rx_itr_cnt_off[] = {
  404. {"TRSH", 0644, HOSTADDR(RGF_DMA_ITR_RX_CNT_TRSH),
  405. doff_io32},
  406. {"DATA", 0644, HOSTADDR(RGF_DMA_ITR_RX_CNT_DATA),
  407. doff_io32},
  408. {"CTL", 0644, HOSTADDR(RGF_DMA_ITR_RX_CNT_CTL),
  409. doff_io32},
  410. {"IDL_TRSH", 0644, HOSTADDR(RGF_DMA_ITR_RX_IDL_CNT_TRSH),
  411. doff_io32},
  412. {"IDL_DATA", 0644, HOSTADDR(RGF_DMA_ITR_RX_IDL_CNT_DATA),
  413. doff_io32},
  414. {"IDL_CTL", 0644, HOSTADDR(RGF_DMA_ITR_RX_IDL_CNT_CTL),
  415. doff_io32},
  416. {},
  417. };
  418. static int wil6210_debugfs_create_ITR_CNT(struct wil6210_priv *wil,
  419. struct dentry *parent)
  420. {
  421. struct dentry *d, *dtx, *drx;
  422. d = debugfs_create_dir("ITR_CNT", parent);
  423. if (IS_ERR_OR_NULL(d))
  424. return -ENODEV;
  425. dtx = debugfs_create_dir("TX", d);
  426. drx = debugfs_create_dir("RX", d);
  427. if (IS_ERR_OR_NULL(dtx) || IS_ERR_OR_NULL(drx))
  428. return -ENODEV;
  429. wil6210_debugfs_init_offset(wil, d, (void * __force)wil->csr,
  430. lgc_itr_cnt_off);
  431. wil6210_debugfs_init_offset(wil, dtx, (void * __force)wil->csr,
  432. tx_itr_cnt_off);
  433. wil6210_debugfs_init_offset(wil, drx, (void * __force)wil->csr,
  434. rx_itr_cnt_off);
  435. return 0;
  436. }
  437. static int wil_memread_debugfs_show(struct seq_file *s, void *data)
  438. {
  439. struct wil6210_priv *wil = s->private;
  440. void __iomem *a;
  441. int ret;
  442. ret = wil_pm_runtime_get(wil);
  443. if (ret < 0)
  444. return ret;
  445. a = wmi_buffer(wil, cpu_to_le32(mem_addr));
  446. if (a)
  447. seq_printf(s, "[0x%08x] = 0x%08x\n", mem_addr, readl(a));
  448. else
  449. seq_printf(s, "[0x%08x] = INVALID\n", mem_addr);
  450. wil_pm_runtime_put(wil);
  451. return 0;
  452. }
  453. static int wil_memread_seq_open(struct inode *inode, struct file *file)
  454. {
  455. return single_open(file, wil_memread_debugfs_show, inode->i_private);
  456. }
  457. static const struct file_operations fops_memread = {
  458. .open = wil_memread_seq_open,
  459. .release = single_release,
  460. .read = seq_read,
  461. .llseek = seq_lseek,
  462. };
  463. static ssize_t wil_read_file_ioblob(struct file *file, char __user *user_buf,
  464. size_t count, loff_t *ppos)
  465. {
  466. enum { max_count = 4096 };
  467. struct wil_blob_wrapper *wil_blob = file->private_data;
  468. struct wil6210_priv *wil = wil_blob->wil;
  469. loff_t pos = *ppos;
  470. size_t available = wil_blob->blob.size;
  471. void *buf;
  472. size_t ret;
  473. int rc;
  474. if (test_bit(wil_status_suspending, wil_blob->wil->status) ||
  475. test_bit(wil_status_suspended, wil_blob->wil->status))
  476. return 0;
  477. if (pos < 0)
  478. return -EINVAL;
  479. if (pos >= available || !count)
  480. return 0;
  481. if (count > available - pos)
  482. count = available - pos;
  483. if (count > max_count)
  484. count = max_count;
  485. buf = kmalloc(count, GFP_KERNEL);
  486. if (!buf)
  487. return -ENOMEM;
  488. rc = wil_pm_runtime_get(wil);
  489. if (rc < 0) {
  490. kfree(buf);
  491. return rc;
  492. }
  493. wil_memcpy_fromio_32(buf, (const void __iomem *)
  494. wil_blob->blob.data + pos, count);
  495. ret = copy_to_user(user_buf, buf, count);
  496. wil_pm_runtime_put(wil);
  497. kfree(buf);
  498. if (ret == count)
  499. return -EFAULT;
  500. count -= ret;
  501. *ppos = pos + count;
  502. return count;
  503. }
  504. static const struct file_operations fops_ioblob = {
  505. .read = wil_read_file_ioblob,
  506. .open = simple_open,
  507. .llseek = default_llseek,
  508. };
  509. static
  510. struct dentry *wil_debugfs_create_ioblob(const char *name,
  511. umode_t mode,
  512. struct dentry *parent,
  513. struct wil_blob_wrapper *wil_blob)
  514. {
  515. return debugfs_create_file(name, mode, parent, wil_blob, &fops_ioblob);
  516. }
  517. /*---reset---*/
  518. static ssize_t wil_write_file_reset(struct file *file, const char __user *buf,
  519. size_t len, loff_t *ppos)
  520. {
  521. struct wil6210_priv *wil = file->private_data;
  522. struct net_device *ndev = wil->main_ndev;
  523. /**
  524. * BUG:
  525. * this code does NOT sync device state with the rest of system
  526. * use with care, debug only!!!
  527. */
  528. rtnl_lock();
  529. dev_close(ndev);
  530. ndev->flags &= ~IFF_UP;
  531. rtnl_unlock();
  532. wil_reset(wil, true);
  533. return len;
  534. }
  535. static const struct file_operations fops_reset = {
  536. .write = wil_write_file_reset,
  537. .open = simple_open,
  538. };
  539. /*---write channel 1..4 to rxon for it, 0 to rxoff---*/
  540. static ssize_t wil_write_file_rxon(struct file *file, const char __user *buf,
  541. size_t len, loff_t *ppos)
  542. {
  543. struct wil6210_priv *wil = file->private_data;
  544. int rc;
  545. long channel;
  546. bool on;
  547. char *kbuf = memdup_user_nul(buf, len);
  548. if (IS_ERR(kbuf))
  549. return PTR_ERR(kbuf);
  550. rc = kstrtol(kbuf, 0, &channel);
  551. kfree(kbuf);
  552. if (rc)
  553. return rc;
  554. if ((channel < 0) || (channel > 4)) {
  555. wil_err(wil, "Invalid channel %ld\n", channel);
  556. return -EINVAL;
  557. }
  558. on = !!channel;
  559. if (on) {
  560. rc = wmi_set_channel(wil, (int)channel);
  561. if (rc)
  562. return rc;
  563. }
  564. rc = wmi_rxon(wil, on);
  565. if (rc)
  566. return rc;
  567. return len;
  568. }
  569. static const struct file_operations fops_rxon = {
  570. .write = wil_write_file_rxon,
  571. .open = simple_open,
  572. };
  573. /* block ack control, write:
  574. * - "add <ringid> <agg_size> <timeout>" to trigger ADDBA
  575. * - "del_tx <ringid> <reason>" to trigger DELBA for Tx side
  576. * - "del_rx <CID> <TID> <reason>" to trigger DELBA for Rx side
  577. */
  578. static ssize_t wil_write_back(struct file *file, const char __user *buf,
  579. size_t len, loff_t *ppos)
  580. {
  581. struct wil6210_priv *wil = file->private_data;
  582. int rc;
  583. char *kbuf = kmalloc(len + 1, GFP_KERNEL);
  584. char cmd[9];
  585. int p1, p2, p3;
  586. if (!kbuf)
  587. return -ENOMEM;
  588. rc = simple_write_to_buffer(kbuf, len, ppos, buf, len);
  589. if (rc != len) {
  590. kfree(kbuf);
  591. return rc >= 0 ? -EIO : rc;
  592. }
  593. kbuf[len] = '\0';
  594. rc = sscanf(kbuf, "%8s %d %d %d", cmd, &p1, &p2, &p3);
  595. kfree(kbuf);
  596. if (rc < 0)
  597. return rc;
  598. if (rc < 2)
  599. return -EINVAL;
  600. if ((strcmp(cmd, "add") == 0) ||
  601. (strcmp(cmd, "del_tx") == 0)) {
  602. struct vring_tx_data *txdata;
  603. if (p1 < 0 || p1 >= WIL6210_MAX_TX_RINGS) {
  604. wil_err(wil, "BACK: invalid ring id %d\n", p1);
  605. return -EINVAL;
  606. }
  607. txdata = &wil->vring_tx_data[p1];
  608. if (strcmp(cmd, "add") == 0) {
  609. if (rc < 3) {
  610. wil_err(wil, "BACK: add require at least 2 params\n");
  611. return -EINVAL;
  612. }
  613. if (rc < 4)
  614. p3 = 0;
  615. wmi_addba(wil, txdata->mid, p1, p2, p3);
  616. } else {
  617. if (rc < 3)
  618. p2 = WLAN_REASON_QSTA_LEAVE_QBSS;
  619. wmi_delba_tx(wil, txdata->mid, p1, p2);
  620. }
  621. } else if (strcmp(cmd, "del_rx") == 0) {
  622. struct wil_sta_info *sta;
  623. if (rc < 3) {
  624. wil_err(wil,
  625. "BACK: del_rx require at least 2 params\n");
  626. return -EINVAL;
  627. }
  628. if (p1 < 0 || p1 >= WIL6210_MAX_CID) {
  629. wil_err(wil, "BACK: invalid CID %d\n", p1);
  630. return -EINVAL;
  631. }
  632. if (rc < 4)
  633. p3 = WLAN_REASON_QSTA_LEAVE_QBSS;
  634. sta = &wil->sta[p1];
  635. wmi_delba_rx(wil, sta->mid, mk_cidxtid(p1, p2), p3);
  636. } else {
  637. wil_err(wil, "BACK: Unrecognized command \"%s\"\n", cmd);
  638. return -EINVAL;
  639. }
  640. return len;
  641. }
  642. static ssize_t wil_read_back(struct file *file, char __user *user_buf,
  643. size_t count, loff_t *ppos)
  644. {
  645. static const char text[] = "block ack control, write:\n"
  646. " - \"add <ringid> <agg_size> <timeout>\" to trigger ADDBA\n"
  647. "If missing, <timeout> defaults to 0\n"
  648. " - \"del_tx <ringid> <reason>\" to trigger DELBA for Tx side\n"
  649. " - \"del_rx <CID> <TID> <reason>\" to trigger DELBA for Rx side\n"
  650. "If missing, <reason> set to \"STA_LEAVING\" (36)\n";
  651. return simple_read_from_buffer(user_buf, count, ppos, text,
  652. sizeof(text));
  653. }
  654. static const struct file_operations fops_back = {
  655. .read = wil_read_back,
  656. .write = wil_write_back,
  657. .open = simple_open,
  658. };
  659. /* pmc control, write:
  660. * - "alloc <num descriptors> <descriptor_size>" to allocate PMC
  661. * - "free" to release memory allocated for PMC
  662. */
  663. static ssize_t wil_write_pmccfg(struct file *file, const char __user *buf,
  664. size_t len, loff_t *ppos)
  665. {
  666. struct wil6210_priv *wil = file->private_data;
  667. int rc;
  668. char *kbuf = kmalloc(len + 1, GFP_KERNEL);
  669. char cmd[9];
  670. int num_descs, desc_size;
  671. if (!kbuf)
  672. return -ENOMEM;
  673. rc = simple_write_to_buffer(kbuf, len, ppos, buf, len);
  674. if (rc != len) {
  675. kfree(kbuf);
  676. return rc >= 0 ? -EIO : rc;
  677. }
  678. kbuf[len] = '\0';
  679. rc = sscanf(kbuf, "%8s %d %d", cmd, &num_descs, &desc_size);
  680. kfree(kbuf);
  681. if (rc < 0)
  682. return rc;
  683. if (rc < 1) {
  684. wil_err(wil, "pmccfg: no params given\n");
  685. return -EINVAL;
  686. }
  687. if (0 == strcmp(cmd, "alloc")) {
  688. if (rc != 3) {
  689. wil_err(wil, "pmccfg: alloc requires 2 params\n");
  690. return -EINVAL;
  691. }
  692. wil_pmc_alloc(wil, num_descs, desc_size);
  693. } else if (0 == strcmp(cmd, "free")) {
  694. if (rc != 1) {
  695. wil_err(wil, "pmccfg: free does not have any params\n");
  696. return -EINVAL;
  697. }
  698. wil_pmc_free(wil, true);
  699. } else {
  700. wil_err(wil, "pmccfg: Unrecognized command \"%s\"\n", cmd);
  701. return -EINVAL;
  702. }
  703. return len;
  704. }
  705. static ssize_t wil_read_pmccfg(struct file *file, char __user *user_buf,
  706. size_t count, loff_t *ppos)
  707. {
  708. struct wil6210_priv *wil = file->private_data;
  709. char text[256];
  710. char help[] = "pmc control, write:\n"
  711. " - \"alloc <num descriptors> <descriptor_size>\" to allocate pmc\n"
  712. " - \"free\" to free memory allocated for pmc\n";
  713. sprintf(text, "Last command status: %d\n\n%s",
  714. wil_pmc_last_cmd_status(wil),
  715. help);
  716. return simple_read_from_buffer(user_buf, count, ppos, text,
  717. strlen(text) + 1);
  718. }
  719. static const struct file_operations fops_pmccfg = {
  720. .read = wil_read_pmccfg,
  721. .write = wil_write_pmccfg,
  722. .open = simple_open,
  723. };
  724. static const struct file_operations fops_pmcdata = {
  725. .open = simple_open,
  726. .read = wil_pmc_read,
  727. .llseek = wil_pmc_llseek,
  728. };
  729. /*---tx_mgmt---*/
  730. /* Write mgmt frame to this file to send it */
  731. static ssize_t wil_write_file_txmgmt(struct file *file, const char __user *buf,
  732. size_t len, loff_t *ppos)
  733. {
  734. struct wil6210_priv *wil = file->private_data;
  735. struct wiphy *wiphy = wil_to_wiphy(wil);
  736. struct wireless_dev *wdev = wil->main_ndev->ieee80211_ptr;
  737. struct cfg80211_mgmt_tx_params params;
  738. int rc;
  739. void *frame;
  740. if (!len)
  741. return -EINVAL;
  742. frame = memdup_user(buf, len);
  743. if (IS_ERR(frame))
  744. return PTR_ERR(frame);
  745. params.buf = frame;
  746. params.len = len;
  747. rc = wil_cfg80211_mgmt_tx(wiphy, wdev, &params, NULL);
  748. kfree(frame);
  749. wil_info(wil, "-> %d\n", rc);
  750. return len;
  751. }
  752. static const struct file_operations fops_txmgmt = {
  753. .write = wil_write_file_txmgmt,
  754. .open = simple_open,
  755. };
  756. /* Write WMI command (w/o mbox header) to this file to send it
  757. * WMI starts from wil6210_mbox_hdr_wmi header
  758. */
  759. static ssize_t wil_write_file_wmi(struct file *file, const char __user *buf,
  760. size_t len, loff_t *ppos)
  761. {
  762. struct wil6210_priv *wil = file->private_data;
  763. struct wil6210_vif *vif = ndev_to_vif(wil->main_ndev);
  764. struct wmi_cmd_hdr *wmi;
  765. void *cmd;
  766. int cmdlen = len - sizeof(struct wmi_cmd_hdr);
  767. u16 cmdid;
  768. int rc, rc1;
  769. if (cmdlen < 0)
  770. return -EINVAL;
  771. wmi = kmalloc(len, GFP_KERNEL);
  772. if (!wmi)
  773. return -ENOMEM;
  774. rc = simple_write_to_buffer(wmi, len, ppos, buf, len);
  775. if (rc < 0) {
  776. kfree(wmi);
  777. return rc;
  778. }
  779. cmd = (cmdlen > 0) ? &wmi[1] : NULL;
  780. cmdid = le16_to_cpu(wmi->command_id);
  781. rc1 = wmi_send(wil, cmdid, vif->mid, cmd, cmdlen);
  782. kfree(wmi);
  783. wil_info(wil, "0x%04x[%d] -> %d\n", cmdid, cmdlen, rc1);
  784. return rc;
  785. }
  786. static const struct file_operations fops_wmi = {
  787. .write = wil_write_file_wmi,
  788. .open = simple_open,
  789. };
  790. static void wil_seq_print_skb(struct seq_file *s, struct sk_buff *skb)
  791. {
  792. int i = 0;
  793. int len = skb_headlen(skb);
  794. void *p = skb->data;
  795. int nr_frags = skb_shinfo(skb)->nr_frags;
  796. seq_printf(s, " len = %d\n", len);
  797. wil_seq_hexdump(s, p, len, " : ");
  798. if (nr_frags) {
  799. seq_printf(s, " nr_frags = %d\n", nr_frags);
  800. for (i = 0; i < nr_frags; i++) {
  801. const struct skb_frag_struct *frag =
  802. &skb_shinfo(skb)->frags[i];
  803. len = skb_frag_size(frag);
  804. p = skb_frag_address_safe(frag);
  805. seq_printf(s, " [%2d] : len = %d\n", i, len);
  806. wil_seq_hexdump(s, p, len, " : ");
  807. }
  808. }
  809. }
  810. /*---------Tx/Rx descriptor------------*/
  811. static int wil_txdesc_debugfs_show(struct seq_file *s, void *data)
  812. {
  813. struct wil6210_priv *wil = s->private;
  814. struct vring *vring;
  815. bool tx = (dbg_vring_index < WIL6210_MAX_TX_RINGS);
  816. vring = tx ? &wil->vring_tx[dbg_vring_index] : &wil->vring_rx;
  817. if (!vring->va) {
  818. if (tx)
  819. seq_printf(s, "No Tx[%2d] VRING\n", dbg_vring_index);
  820. else
  821. seq_puts(s, "No Rx VRING\n");
  822. return 0;
  823. }
  824. if (dbg_txdesc_index < vring->size) {
  825. /* use struct vring_tx_desc for Rx as well,
  826. * only field used, .dma.length, is the same
  827. */
  828. volatile struct vring_tx_desc *d =
  829. &vring->va[dbg_txdesc_index].tx;
  830. volatile u32 *u = (volatile u32 *)d;
  831. struct sk_buff *skb = vring->ctx[dbg_txdesc_index].skb;
  832. if (tx)
  833. seq_printf(s, "Tx[%2d][%3d] = {\n", dbg_vring_index,
  834. dbg_txdesc_index);
  835. else
  836. seq_printf(s, "Rx[%3d] = {\n", dbg_txdesc_index);
  837. seq_printf(s, " MAC = 0x%08x 0x%08x 0x%08x 0x%08x\n",
  838. u[0], u[1], u[2], u[3]);
  839. seq_printf(s, " DMA = 0x%08x 0x%08x 0x%08x 0x%08x\n",
  840. u[4], u[5], u[6], u[7]);
  841. seq_printf(s, " SKB = 0x%p\n", skb);
  842. if (skb) {
  843. skb_get(skb);
  844. wil_seq_print_skb(s, skb);
  845. kfree_skb(skb);
  846. }
  847. seq_puts(s, "}\n");
  848. } else {
  849. if (tx)
  850. seq_printf(s, "[%2d] TxDesc index (%d) >= size (%d)\n",
  851. dbg_vring_index, dbg_txdesc_index,
  852. vring->size);
  853. else
  854. seq_printf(s, "RxDesc index (%d) >= size (%d)\n",
  855. dbg_txdesc_index, vring->size);
  856. }
  857. return 0;
  858. }
  859. static int wil_txdesc_seq_open(struct inode *inode, struct file *file)
  860. {
  861. return single_open(file, wil_txdesc_debugfs_show, inode->i_private);
  862. }
  863. static const struct file_operations fops_txdesc = {
  864. .open = wil_txdesc_seq_open,
  865. .release = single_release,
  866. .read = seq_read,
  867. .llseek = seq_lseek,
  868. };
  869. /*---------beamforming------------*/
  870. static char *wil_bfstatus_str(u32 status)
  871. {
  872. switch (status) {
  873. case 0:
  874. return "Failed";
  875. case 1:
  876. return "OK";
  877. case 2:
  878. return "Retrying";
  879. default:
  880. return "??";
  881. }
  882. }
  883. static bool is_all_zeros(void * const x_, size_t sz)
  884. {
  885. /* if reply is all-0, ignore this CID */
  886. u32 *x = x_;
  887. int n;
  888. for (n = 0; n < sz / sizeof(*x); n++)
  889. if (x[n])
  890. return false;
  891. return true;
  892. }
  893. static int wil_bf_debugfs_show(struct seq_file *s, void *data)
  894. {
  895. int rc;
  896. int i;
  897. struct wil6210_priv *wil = s->private;
  898. struct wil6210_vif *vif = ndev_to_vif(wil->main_ndev);
  899. struct wmi_notify_req_cmd cmd = {
  900. .interval_usec = 0,
  901. };
  902. struct {
  903. struct wmi_cmd_hdr wmi;
  904. struct wmi_notify_req_done_event evt;
  905. } __packed reply;
  906. memset(&reply, 0, sizeof(reply));
  907. for (i = 0; i < ARRAY_SIZE(wil->sta); i++) {
  908. u32 status;
  909. cmd.cid = i;
  910. rc = wmi_call(wil, WMI_NOTIFY_REQ_CMDID, vif->mid,
  911. &cmd, sizeof(cmd),
  912. WMI_NOTIFY_REQ_DONE_EVENTID, &reply,
  913. sizeof(reply), 20);
  914. /* if reply is all-0, ignore this CID */
  915. if (rc || is_all_zeros(&reply.evt, sizeof(reply.evt)))
  916. continue;
  917. status = le32_to_cpu(reply.evt.status);
  918. seq_printf(s, "CID %d {\n"
  919. " TSF = 0x%016llx\n"
  920. " TxMCS = %2d TxTpt = %4d\n"
  921. " SQI = %4d\n"
  922. " RSSI = %4d\n"
  923. " Status = 0x%08x %s\n"
  924. " Sectors(rx:tx) my %2d:%2d peer %2d:%2d\n"
  925. " Goodput(rx:tx) %4d:%4d\n"
  926. "}\n",
  927. i,
  928. le64_to_cpu(reply.evt.tsf),
  929. le16_to_cpu(reply.evt.bf_mcs),
  930. le32_to_cpu(reply.evt.tx_tpt),
  931. reply.evt.sqi,
  932. reply.evt.rssi,
  933. status, wil_bfstatus_str(status),
  934. le16_to_cpu(reply.evt.my_rx_sector),
  935. le16_to_cpu(reply.evt.my_tx_sector),
  936. le16_to_cpu(reply.evt.other_rx_sector),
  937. le16_to_cpu(reply.evt.other_tx_sector),
  938. le32_to_cpu(reply.evt.rx_goodput),
  939. le32_to_cpu(reply.evt.tx_goodput));
  940. }
  941. return 0;
  942. }
  943. static int wil_bf_seq_open(struct inode *inode, struct file *file)
  944. {
  945. return single_open(file, wil_bf_debugfs_show, inode->i_private);
  946. }
  947. static const struct file_operations fops_bf = {
  948. .open = wil_bf_seq_open,
  949. .release = single_release,
  950. .read = seq_read,
  951. .llseek = seq_lseek,
  952. };
  953. /*---------temp------------*/
  954. static void print_temp(struct seq_file *s, const char *prefix, u32 t)
  955. {
  956. switch (t) {
  957. case 0:
  958. case ~(u32)0:
  959. seq_printf(s, "%s N/A\n", prefix);
  960. break;
  961. default:
  962. seq_printf(s, "%s %d.%03d\n", prefix, t / 1000, t % 1000);
  963. break;
  964. }
  965. }
  966. static int wil_temp_debugfs_show(struct seq_file *s, void *data)
  967. {
  968. struct wil6210_priv *wil = s->private;
  969. u32 t_m, t_r;
  970. int rc = wmi_get_temperature(wil, &t_m, &t_r);
  971. if (rc) {
  972. seq_puts(s, "Failed\n");
  973. return 0;
  974. }
  975. print_temp(s, "T_mac =", t_m);
  976. print_temp(s, "T_radio =", t_r);
  977. return 0;
  978. }
  979. static int wil_temp_seq_open(struct inode *inode, struct file *file)
  980. {
  981. return single_open(file, wil_temp_debugfs_show, inode->i_private);
  982. }
  983. static const struct file_operations fops_temp = {
  984. .open = wil_temp_seq_open,
  985. .release = single_release,
  986. .read = seq_read,
  987. .llseek = seq_lseek,
  988. };
  989. /*---------freq------------*/
  990. static int wil_freq_debugfs_show(struct seq_file *s, void *data)
  991. {
  992. struct wil6210_priv *wil = s->private;
  993. struct wireless_dev *wdev = wil->main_ndev->ieee80211_ptr;
  994. u16 freq = wdev->chandef.chan ? wdev->chandef.chan->center_freq : 0;
  995. seq_printf(s, "Freq = %d\n", freq);
  996. return 0;
  997. }
  998. static int wil_freq_seq_open(struct inode *inode, struct file *file)
  999. {
  1000. return single_open(file, wil_freq_debugfs_show, inode->i_private);
  1001. }
  1002. static const struct file_operations fops_freq = {
  1003. .open = wil_freq_seq_open,
  1004. .release = single_release,
  1005. .read = seq_read,
  1006. .llseek = seq_lseek,
  1007. };
  1008. /*---------link------------*/
  1009. static int wil_link_debugfs_show(struct seq_file *s, void *data)
  1010. {
  1011. struct wil6210_priv *wil = s->private;
  1012. struct station_info *sinfo;
  1013. int i, rc = 0;
  1014. sinfo = kzalloc(sizeof(*sinfo), GFP_KERNEL);
  1015. if (!sinfo)
  1016. return -ENOMEM;
  1017. for (i = 0; i < ARRAY_SIZE(wil->sta); i++) {
  1018. struct wil_sta_info *p = &wil->sta[i];
  1019. char *status = "unknown";
  1020. struct wil6210_vif *vif;
  1021. u8 mid;
  1022. switch (p->status) {
  1023. case wil_sta_unused:
  1024. status = "unused ";
  1025. break;
  1026. case wil_sta_conn_pending:
  1027. status = "pending ";
  1028. break;
  1029. case wil_sta_connected:
  1030. status = "connected";
  1031. break;
  1032. }
  1033. mid = (p->status != wil_sta_unused) ? p->mid : U8_MAX;
  1034. seq_printf(s, "[%d][MID %d] %pM %s\n",
  1035. i, mid, p->addr, status);
  1036. if (p->status != wil_sta_connected)
  1037. continue;
  1038. vif = (mid < wil->max_vifs) ? wil->vifs[mid] : NULL;
  1039. if (vif) {
  1040. rc = wil_cid_fill_sinfo(vif, i, sinfo);
  1041. if (rc)
  1042. goto out;
  1043. seq_printf(s, " Tx_mcs = %d\n", sinfo->txrate.mcs);
  1044. seq_printf(s, " Rx_mcs = %d\n", sinfo->rxrate.mcs);
  1045. seq_printf(s, " SQ = %d\n", sinfo->signal);
  1046. } else {
  1047. seq_puts(s, " INVALID MID\n");
  1048. }
  1049. }
  1050. out:
  1051. kfree(sinfo);
  1052. return rc;
  1053. }
  1054. static int wil_link_seq_open(struct inode *inode, struct file *file)
  1055. {
  1056. return single_open(file, wil_link_debugfs_show, inode->i_private);
  1057. }
  1058. static const struct file_operations fops_link = {
  1059. .open = wil_link_seq_open,
  1060. .release = single_release,
  1061. .read = seq_read,
  1062. .llseek = seq_lseek,
  1063. };
  1064. /*---------info------------*/
  1065. static int wil_info_debugfs_show(struct seq_file *s, void *data)
  1066. {
  1067. struct wil6210_priv *wil = s->private;
  1068. struct net_device *ndev = wil->main_ndev;
  1069. int is_ac = power_supply_is_system_supplied();
  1070. int rx = atomic_xchg(&wil->isr_count_rx, 0);
  1071. int tx = atomic_xchg(&wil->isr_count_tx, 0);
  1072. static ulong rxf_old, txf_old;
  1073. ulong rxf = ndev->stats.rx_packets;
  1074. ulong txf = ndev->stats.tx_packets;
  1075. unsigned int i;
  1076. /* >0 : AC; 0 : battery; <0 : error */
  1077. seq_printf(s, "AC powered : %d\n", is_ac);
  1078. seq_printf(s, "Rx irqs:packets : %8d : %8ld\n", rx, rxf - rxf_old);
  1079. seq_printf(s, "Tx irqs:packets : %8d : %8ld\n", tx, txf - txf_old);
  1080. rxf_old = rxf;
  1081. txf_old = txf;
  1082. #define CHECK_QSTATE(x) (state & BIT(__QUEUE_STATE_ ## x)) ? \
  1083. " " __stringify(x) : ""
  1084. for (i = 0; i < ndev->num_tx_queues; i++) {
  1085. struct netdev_queue *txq = netdev_get_tx_queue(ndev, i);
  1086. unsigned long state = txq->state;
  1087. seq_printf(s, "Tx queue[%i] state : 0x%lx%s%s%s\n", i, state,
  1088. CHECK_QSTATE(DRV_XOFF),
  1089. CHECK_QSTATE(STACK_XOFF),
  1090. CHECK_QSTATE(FROZEN)
  1091. );
  1092. }
  1093. #undef CHECK_QSTATE
  1094. return 0;
  1095. }
  1096. static int wil_info_seq_open(struct inode *inode, struct file *file)
  1097. {
  1098. return single_open(file, wil_info_debugfs_show, inode->i_private);
  1099. }
  1100. static const struct file_operations fops_info = {
  1101. .open = wil_info_seq_open,
  1102. .release = single_release,
  1103. .read = seq_read,
  1104. .llseek = seq_lseek,
  1105. };
  1106. /*---------recovery------------*/
  1107. /* mode = [manual|auto]
  1108. * state = [idle|pending|running]
  1109. */
  1110. static ssize_t wil_read_file_recovery(struct file *file, char __user *user_buf,
  1111. size_t count, loff_t *ppos)
  1112. {
  1113. struct wil6210_priv *wil = file->private_data;
  1114. char buf[80];
  1115. int n;
  1116. static const char * const sstate[] = {"idle", "pending", "running"};
  1117. n = snprintf(buf, sizeof(buf), "mode = %s\nstate = %s\n",
  1118. no_fw_recovery ? "manual" : "auto",
  1119. sstate[wil->recovery_state]);
  1120. n = min_t(int, n, sizeof(buf));
  1121. return simple_read_from_buffer(user_buf, count, ppos,
  1122. buf, n);
  1123. }
  1124. static ssize_t wil_write_file_recovery(struct file *file,
  1125. const char __user *buf_,
  1126. size_t count, loff_t *ppos)
  1127. {
  1128. struct wil6210_priv *wil = file->private_data;
  1129. static const char run_command[] = "run";
  1130. char buf[sizeof(run_command) + 1]; /* to detect "runx" */
  1131. ssize_t rc;
  1132. if (wil->recovery_state != fw_recovery_pending) {
  1133. wil_err(wil, "No recovery pending\n");
  1134. return -EINVAL;
  1135. }
  1136. if (*ppos != 0) {
  1137. wil_err(wil, "Offset [%d]\n", (int)*ppos);
  1138. return -EINVAL;
  1139. }
  1140. if (count > sizeof(buf)) {
  1141. wil_err(wil, "Input too long, len = %d\n", (int)count);
  1142. return -EINVAL;
  1143. }
  1144. rc = simple_write_to_buffer(buf, sizeof(buf) - 1, ppos, buf_, count);
  1145. if (rc < 0)
  1146. return rc;
  1147. buf[rc] = '\0';
  1148. if (0 == strcmp(buf, run_command))
  1149. wil_set_recovery_state(wil, fw_recovery_running);
  1150. else
  1151. wil_err(wil, "Bad recovery command \"%s\"\n", buf);
  1152. return rc;
  1153. }
  1154. static const struct file_operations fops_recovery = {
  1155. .read = wil_read_file_recovery,
  1156. .write = wil_write_file_recovery,
  1157. .open = simple_open,
  1158. };
  1159. /*---------Station matrix------------*/
  1160. static void wil_print_rxtid(struct seq_file *s, struct wil_tid_ampdu_rx *r)
  1161. {
  1162. int i;
  1163. u16 index = ((r->head_seq_num - r->ssn) & 0xfff) % r->buf_size;
  1164. unsigned long long drop_dup = r->drop_dup, drop_old = r->drop_old;
  1165. seq_printf(s, "([%2d]) 0x%03x [", r->buf_size, r->head_seq_num);
  1166. for (i = 0; i < r->buf_size; i++) {
  1167. if (i == index)
  1168. seq_printf(s, "%c", r->reorder_buf[i] ? 'O' : '|');
  1169. else
  1170. seq_printf(s, "%c", r->reorder_buf[i] ? '*' : '_');
  1171. }
  1172. seq_printf(s,
  1173. "] total %llu drop %llu (dup %llu + old %llu) last 0x%03x\n",
  1174. r->total, drop_dup + drop_old, drop_dup, drop_old,
  1175. r->ssn_last_drop);
  1176. }
  1177. static void wil_print_rxtid_crypto(struct seq_file *s, int tid,
  1178. struct wil_tid_crypto_rx *c)
  1179. {
  1180. int i;
  1181. for (i = 0; i < 4; i++) {
  1182. struct wil_tid_crypto_rx_single *cc = &c->key_id[i];
  1183. if (cc->key_set)
  1184. goto has_keys;
  1185. }
  1186. return;
  1187. has_keys:
  1188. if (tid < WIL_STA_TID_NUM)
  1189. seq_printf(s, " [%2d] PN", tid);
  1190. else
  1191. seq_puts(s, " [GR] PN");
  1192. for (i = 0; i < 4; i++) {
  1193. struct wil_tid_crypto_rx_single *cc = &c->key_id[i];
  1194. seq_printf(s, " [%i%s]%6phN", i, cc->key_set ? "+" : "-",
  1195. cc->pn);
  1196. }
  1197. seq_puts(s, "\n");
  1198. }
  1199. static int wil_sta_debugfs_show(struct seq_file *s, void *data)
  1200. __acquires(&p->tid_rx_lock) __releases(&p->tid_rx_lock)
  1201. {
  1202. struct wil6210_priv *wil = s->private;
  1203. int i, tid, mcs;
  1204. for (i = 0; i < ARRAY_SIZE(wil->sta); i++) {
  1205. struct wil_sta_info *p = &wil->sta[i];
  1206. char *status = "unknown";
  1207. u8 aid = 0;
  1208. u8 mid;
  1209. switch (p->status) {
  1210. case wil_sta_unused:
  1211. status = "unused ";
  1212. break;
  1213. case wil_sta_conn_pending:
  1214. status = "pending ";
  1215. break;
  1216. case wil_sta_connected:
  1217. status = "connected";
  1218. aid = p->aid;
  1219. break;
  1220. }
  1221. mid = (p->status != wil_sta_unused) ? p->mid : U8_MAX;
  1222. seq_printf(s, "[%d] %pM %s MID %d AID %d\n", i, p->addr, status,
  1223. mid, aid);
  1224. if (p->status == wil_sta_connected) {
  1225. spin_lock_bh(&p->tid_rx_lock);
  1226. for (tid = 0; tid < WIL_STA_TID_NUM; tid++) {
  1227. struct wil_tid_ampdu_rx *r = p->tid_rx[tid];
  1228. struct wil_tid_crypto_rx *c =
  1229. &p->tid_crypto_rx[tid];
  1230. if (r) {
  1231. seq_printf(s, " [%2d] ", tid);
  1232. wil_print_rxtid(s, r);
  1233. }
  1234. wil_print_rxtid_crypto(s, tid, c);
  1235. }
  1236. wil_print_rxtid_crypto(s, WIL_STA_TID_NUM,
  1237. &p->group_crypto_rx);
  1238. spin_unlock_bh(&p->tid_rx_lock);
  1239. seq_printf(s,
  1240. "Rx invalid frame: non-data %lu, short %lu, large %lu, replay %lu\n",
  1241. p->stats.rx_non_data_frame,
  1242. p->stats.rx_short_frame,
  1243. p->stats.rx_large_frame,
  1244. p->stats.rx_replay);
  1245. seq_puts(s, "Rx/MCS:");
  1246. for (mcs = 0; mcs < ARRAY_SIZE(p->stats.rx_per_mcs);
  1247. mcs++)
  1248. seq_printf(s, " %lld",
  1249. p->stats.rx_per_mcs[mcs]);
  1250. seq_puts(s, "\n");
  1251. }
  1252. }
  1253. return 0;
  1254. }
  1255. static int wil_sta_seq_open(struct inode *inode, struct file *file)
  1256. {
  1257. return single_open(file, wil_sta_debugfs_show, inode->i_private);
  1258. }
  1259. static const struct file_operations fops_sta = {
  1260. .open = wil_sta_seq_open,
  1261. .release = single_release,
  1262. .read = seq_read,
  1263. .llseek = seq_lseek,
  1264. };
  1265. static int wil_mids_debugfs_show(struct seq_file *s, void *data)
  1266. {
  1267. struct wil6210_priv *wil = s->private;
  1268. struct wil6210_vif *vif;
  1269. struct net_device *ndev;
  1270. int i;
  1271. mutex_lock(&wil->vif_mutex);
  1272. for (i = 0; i < wil->max_vifs; i++) {
  1273. vif = wil->vifs[i];
  1274. if (vif) {
  1275. ndev = vif_to_ndev(vif);
  1276. seq_printf(s, "[%d] %pM %s\n", i, ndev->dev_addr,
  1277. ndev->name);
  1278. } else {
  1279. seq_printf(s, "[%d] unused\n", i);
  1280. }
  1281. }
  1282. mutex_unlock(&wil->vif_mutex);
  1283. return 0;
  1284. }
  1285. static int wil_mids_seq_open(struct inode *inode, struct file *file)
  1286. {
  1287. return single_open(file, wil_mids_debugfs_show, inode->i_private);
  1288. }
  1289. static const struct file_operations fops_mids = {
  1290. .open = wil_mids_seq_open,
  1291. .release = single_release,
  1292. .read = seq_read,
  1293. .llseek = seq_lseek,
  1294. };
  1295. static ssize_t wil_read_file_led_cfg(struct file *file, char __user *user_buf,
  1296. size_t count, loff_t *ppos)
  1297. {
  1298. char buf[80];
  1299. int n;
  1300. n = snprintf(buf, sizeof(buf),
  1301. "led_id is set to %d, echo 1 to enable, 0 to disable\n",
  1302. led_id);
  1303. n = min_t(int, n, sizeof(buf));
  1304. return simple_read_from_buffer(user_buf, count, ppos,
  1305. buf, n);
  1306. }
  1307. static ssize_t wil_write_file_led_cfg(struct file *file,
  1308. const char __user *buf_,
  1309. size_t count, loff_t *ppos)
  1310. {
  1311. struct wil6210_priv *wil = file->private_data;
  1312. int val;
  1313. int rc;
  1314. rc = kstrtoint_from_user(buf_, count, 0, &val);
  1315. if (rc) {
  1316. wil_err(wil, "Invalid argument\n");
  1317. return rc;
  1318. }
  1319. wil_info(wil, "%s led %d\n", val ? "Enabling" : "Disabling", led_id);
  1320. rc = wmi_led_cfg(wil, val);
  1321. if (rc) {
  1322. wil_info(wil, "%s led %d failed\n",
  1323. val ? "Enabling" : "Disabling", led_id);
  1324. return rc;
  1325. }
  1326. return count;
  1327. }
  1328. static const struct file_operations fops_led_cfg = {
  1329. .read = wil_read_file_led_cfg,
  1330. .write = wil_write_file_led_cfg,
  1331. .open = simple_open,
  1332. };
  1333. /* led_blink_time, write:
  1334. * "<blink_on_slow> <blink_off_slow> <blink_on_med> <blink_off_med> <blink_on_fast> <blink_off_fast>
  1335. */
  1336. static ssize_t wil_write_led_blink_time(struct file *file,
  1337. const char __user *buf,
  1338. size_t len, loff_t *ppos)
  1339. {
  1340. int rc;
  1341. char *kbuf = kmalloc(len + 1, GFP_KERNEL);
  1342. if (!kbuf)
  1343. return -ENOMEM;
  1344. rc = simple_write_to_buffer(kbuf, len, ppos, buf, len);
  1345. if (rc != len) {
  1346. kfree(kbuf);
  1347. return rc >= 0 ? -EIO : rc;
  1348. }
  1349. kbuf[len] = '\0';
  1350. rc = sscanf(kbuf, "%d %d %d %d %d %d",
  1351. &led_blink_time[WIL_LED_TIME_SLOW].on_ms,
  1352. &led_blink_time[WIL_LED_TIME_SLOW].off_ms,
  1353. &led_blink_time[WIL_LED_TIME_MED].on_ms,
  1354. &led_blink_time[WIL_LED_TIME_MED].off_ms,
  1355. &led_blink_time[WIL_LED_TIME_FAST].on_ms,
  1356. &led_blink_time[WIL_LED_TIME_FAST].off_ms);
  1357. kfree(kbuf);
  1358. if (rc < 0)
  1359. return rc;
  1360. if (rc < 6)
  1361. return -EINVAL;
  1362. return len;
  1363. }
  1364. static ssize_t wil_read_led_blink_time(struct file *file, char __user *user_buf,
  1365. size_t count, loff_t *ppos)
  1366. {
  1367. static char text[400];
  1368. snprintf(text, sizeof(text),
  1369. "To set led blink on/off time variables write:\n"
  1370. "<blink_on_slow> <blink_off_slow> <blink_on_med> "
  1371. "<blink_off_med> <blink_on_fast> <blink_off_fast>\n"
  1372. "The current values are:\n"
  1373. "%d %d %d %d %d %d\n",
  1374. led_blink_time[WIL_LED_TIME_SLOW].on_ms,
  1375. led_blink_time[WIL_LED_TIME_SLOW].off_ms,
  1376. led_blink_time[WIL_LED_TIME_MED].on_ms,
  1377. led_blink_time[WIL_LED_TIME_MED].off_ms,
  1378. led_blink_time[WIL_LED_TIME_FAST].on_ms,
  1379. led_blink_time[WIL_LED_TIME_FAST].off_ms);
  1380. return simple_read_from_buffer(user_buf, count, ppos, text,
  1381. sizeof(text));
  1382. }
  1383. static const struct file_operations fops_led_blink_time = {
  1384. .read = wil_read_led_blink_time,
  1385. .write = wil_write_led_blink_time,
  1386. .open = simple_open,
  1387. };
  1388. /*---------FW capabilities------------*/
  1389. static int wil_fw_capabilities_debugfs_show(struct seq_file *s, void *data)
  1390. {
  1391. struct wil6210_priv *wil = s->private;
  1392. seq_printf(s, "fw_capabilities : %*pb\n", WMI_FW_CAPABILITY_MAX,
  1393. wil->fw_capabilities);
  1394. return 0;
  1395. }
  1396. static int wil_fw_capabilities_seq_open(struct inode *inode, struct file *file)
  1397. {
  1398. return single_open(file, wil_fw_capabilities_debugfs_show,
  1399. inode->i_private);
  1400. }
  1401. static const struct file_operations fops_fw_capabilities = {
  1402. .open = wil_fw_capabilities_seq_open,
  1403. .release = single_release,
  1404. .read = seq_read,
  1405. .llseek = seq_lseek,
  1406. };
  1407. /*---------FW version------------*/
  1408. static int wil_fw_version_debugfs_show(struct seq_file *s, void *data)
  1409. {
  1410. struct wil6210_priv *wil = s->private;
  1411. if (wil->fw_version[0])
  1412. seq_printf(s, "%s\n", wil->fw_version);
  1413. else
  1414. seq_puts(s, "N/A\n");
  1415. return 0;
  1416. }
  1417. static int wil_fw_version_seq_open(struct inode *inode, struct file *file)
  1418. {
  1419. return single_open(file, wil_fw_version_debugfs_show,
  1420. inode->i_private);
  1421. }
  1422. static const struct file_operations fops_fw_version = {
  1423. .open = wil_fw_version_seq_open,
  1424. .release = single_release,
  1425. .read = seq_read,
  1426. .llseek = seq_lseek,
  1427. };
  1428. /*---------suspend_stats---------*/
  1429. static ssize_t wil_write_suspend_stats(struct file *file,
  1430. const char __user *buf,
  1431. size_t len, loff_t *ppos)
  1432. {
  1433. struct wil6210_priv *wil = file->private_data;
  1434. memset(&wil->suspend_stats, 0, sizeof(wil->suspend_stats));
  1435. return len;
  1436. }
  1437. static ssize_t wil_read_suspend_stats(struct file *file,
  1438. char __user *user_buf,
  1439. size_t count, loff_t *ppos)
  1440. {
  1441. struct wil6210_priv *wil = file->private_data;
  1442. char *text;
  1443. int n, ret, text_size = 500;
  1444. text = kmalloc(text_size, GFP_KERNEL);
  1445. if (!text)
  1446. return -ENOMEM;
  1447. n = snprintf(text, text_size,
  1448. "Radio on suspend statistics:\n"
  1449. "successful suspends:%ld failed suspends:%ld\n"
  1450. "successful resumes:%ld failed resumes:%ld\n"
  1451. "rejected by device:%ld\n"
  1452. "Radio off suspend statistics:\n"
  1453. "successful suspends:%ld failed suspends:%ld\n"
  1454. "successful resumes:%ld failed resumes:%ld\n"
  1455. "General statistics:\n"
  1456. "rejected by host:%ld\n",
  1457. wil->suspend_stats.r_on.successful_suspends,
  1458. wil->suspend_stats.r_on.failed_suspends,
  1459. wil->suspend_stats.r_on.successful_resumes,
  1460. wil->suspend_stats.r_on.failed_resumes,
  1461. wil->suspend_stats.rejected_by_device,
  1462. wil->suspend_stats.r_off.successful_suspends,
  1463. wil->suspend_stats.r_off.failed_suspends,
  1464. wil->suspend_stats.r_off.successful_resumes,
  1465. wil->suspend_stats.r_off.failed_resumes,
  1466. wil->suspend_stats.rejected_by_host);
  1467. n = min_t(int, n, text_size);
  1468. ret = simple_read_from_buffer(user_buf, count, ppos, text, n);
  1469. kfree(text);
  1470. return ret;
  1471. }
  1472. static const struct file_operations fops_suspend_stats = {
  1473. .read = wil_read_suspend_stats,
  1474. .write = wil_write_suspend_stats,
  1475. .open = simple_open,
  1476. };
  1477. /*----------------*/
  1478. static void wil6210_debugfs_init_blobs(struct wil6210_priv *wil,
  1479. struct dentry *dbg)
  1480. {
  1481. int i;
  1482. char name[32];
  1483. for (i = 0; i < ARRAY_SIZE(fw_mapping); i++) {
  1484. struct wil_blob_wrapper *wil_blob = &wil->blobs[i];
  1485. struct debugfs_blob_wrapper *blob = &wil_blob->blob;
  1486. const struct fw_map *map = &fw_mapping[i];
  1487. if (!map->name)
  1488. continue;
  1489. wil_blob->wil = wil;
  1490. blob->data = (void * __force)wil->csr + HOSTADDR(map->host);
  1491. blob->size = map->to - map->from;
  1492. snprintf(name, sizeof(name), "blob_%s", map->name);
  1493. wil_debugfs_create_ioblob(name, 0444, dbg, wil_blob);
  1494. }
  1495. }
  1496. /* misc files */
  1497. static const struct {
  1498. const char *name;
  1499. umode_t mode;
  1500. const struct file_operations *fops;
  1501. } dbg_files[] = {
  1502. {"mbox", 0444, &fops_mbox},
  1503. {"vrings", 0444, &fops_vring},
  1504. {"stations", 0444, &fops_sta},
  1505. {"mids", 0444, &fops_mids},
  1506. {"desc", 0444, &fops_txdesc},
  1507. {"bf", 0444, &fops_bf},
  1508. {"mem_val", 0644, &fops_memread},
  1509. {"reset", 0244, &fops_reset},
  1510. {"rxon", 0244, &fops_rxon},
  1511. {"tx_mgmt", 0244, &fops_txmgmt},
  1512. {"wmi_send", 0244, &fops_wmi},
  1513. {"back", 0644, &fops_back},
  1514. {"pmccfg", 0644, &fops_pmccfg},
  1515. {"pmcdata", 0444, &fops_pmcdata},
  1516. {"temp", 0444, &fops_temp},
  1517. {"freq", 0444, &fops_freq},
  1518. {"link", 0444, &fops_link},
  1519. {"info", 0444, &fops_info},
  1520. {"recovery", 0644, &fops_recovery},
  1521. {"led_cfg", 0644, &fops_led_cfg},
  1522. {"led_blink_time", 0644, &fops_led_blink_time},
  1523. {"fw_capabilities", 0444, &fops_fw_capabilities},
  1524. {"fw_version", 0444, &fops_fw_version},
  1525. {"suspend_stats", 0644, &fops_suspend_stats},
  1526. };
  1527. static void wil6210_debugfs_init_files(struct wil6210_priv *wil,
  1528. struct dentry *dbg)
  1529. {
  1530. int i;
  1531. for (i = 0; i < ARRAY_SIZE(dbg_files); i++)
  1532. debugfs_create_file(dbg_files[i].name, dbg_files[i].mode, dbg,
  1533. wil, dbg_files[i].fops);
  1534. }
  1535. /* interrupt control blocks */
  1536. static const struct {
  1537. const char *name;
  1538. u32 icr_off;
  1539. } dbg_icr[] = {
  1540. {"USER_ICR", HOSTADDR(RGF_USER_USER_ICR)},
  1541. {"DMA_EP_TX_ICR", HOSTADDR(RGF_DMA_EP_TX_ICR)},
  1542. {"DMA_EP_RX_ICR", HOSTADDR(RGF_DMA_EP_RX_ICR)},
  1543. {"DMA_EP_MISC_ICR", HOSTADDR(RGF_DMA_EP_MISC_ICR)},
  1544. };
  1545. static void wil6210_debugfs_init_isr(struct wil6210_priv *wil,
  1546. struct dentry *dbg)
  1547. {
  1548. int i;
  1549. for (i = 0; i < ARRAY_SIZE(dbg_icr); i++)
  1550. wil6210_debugfs_create_ISR(wil, dbg_icr[i].name, dbg,
  1551. dbg_icr[i].icr_off);
  1552. }
  1553. #define WIL_FIELD(name, mode, type) { __stringify(name), mode, \
  1554. offsetof(struct wil6210_priv, name), type}
  1555. /* fields in struct wil6210_priv */
  1556. static const struct dbg_off dbg_wil_off[] = {
  1557. WIL_FIELD(status[0], 0644, doff_ulong),
  1558. WIL_FIELD(hw_version, 0444, doff_x32),
  1559. WIL_FIELD(recovery_count, 0444, doff_u32),
  1560. WIL_FIELD(discovery_mode, 0644, doff_u8),
  1561. WIL_FIELD(chip_revision, 0444, doff_u8),
  1562. WIL_FIELD(abft_len, 0644, doff_u8),
  1563. WIL_FIELD(wakeup_trigger, 0644, doff_u8),
  1564. WIL_FIELD(vring_idle_trsh, 0644, doff_u32),
  1565. {},
  1566. };
  1567. static const struct dbg_off dbg_wil_regs[] = {
  1568. {"RGF_MAC_MTRL_COUNTER_0", 0444, HOSTADDR(RGF_MAC_MTRL_COUNTER_0),
  1569. doff_io32},
  1570. {"RGF_USER_USAGE_1", 0444, HOSTADDR(RGF_USER_USAGE_1), doff_io32},
  1571. {},
  1572. };
  1573. /* static parameters */
  1574. static const struct dbg_off dbg_statics[] = {
  1575. {"desc_index", 0644, (ulong)&dbg_txdesc_index, doff_u32},
  1576. {"vring_index", 0644, (ulong)&dbg_vring_index, doff_u32},
  1577. {"mem_addr", 0644, (ulong)&mem_addr, doff_u32},
  1578. {"led_polarity", 0644, (ulong)&led_polarity, doff_u8},
  1579. {},
  1580. };
  1581. static const int dbg_off_count = 4 * (ARRAY_SIZE(isr_off) - 1) +
  1582. ARRAY_SIZE(dbg_wil_regs) - 1 +
  1583. ARRAY_SIZE(pseudo_isr_off) - 1 +
  1584. ARRAY_SIZE(lgc_itr_cnt_off) - 1 +
  1585. ARRAY_SIZE(tx_itr_cnt_off) - 1 +
  1586. ARRAY_SIZE(rx_itr_cnt_off) - 1;
  1587. int wil6210_debugfs_init(struct wil6210_priv *wil)
  1588. {
  1589. struct dentry *dbg = wil->debug = debugfs_create_dir(WIL_NAME,
  1590. wil_to_wiphy(wil)->debugfsdir);
  1591. if (IS_ERR_OR_NULL(dbg))
  1592. return -ENODEV;
  1593. wil->dbg_data.data_arr = kcalloc(dbg_off_count,
  1594. sizeof(struct wil_debugfs_iomem_data),
  1595. GFP_KERNEL);
  1596. if (!wil->dbg_data.data_arr) {
  1597. debugfs_remove_recursive(dbg);
  1598. wil->debug = NULL;
  1599. return -ENOMEM;
  1600. }
  1601. wil->dbg_data.iomem_data_count = 0;
  1602. wil_pmc_init(wil);
  1603. wil6210_debugfs_init_files(wil, dbg);
  1604. wil6210_debugfs_init_isr(wil, dbg);
  1605. wil6210_debugfs_init_blobs(wil, dbg);
  1606. wil6210_debugfs_init_offset(wil, dbg, wil, dbg_wil_off);
  1607. wil6210_debugfs_init_offset(wil, dbg, (void * __force)wil->csr,
  1608. dbg_wil_regs);
  1609. wil6210_debugfs_init_offset(wil, dbg, NULL, dbg_statics);
  1610. wil6210_debugfs_create_pseudo_ISR(wil, dbg);
  1611. wil6210_debugfs_create_ITR_CNT(wil, dbg);
  1612. return 0;
  1613. }
  1614. void wil6210_debugfs_remove(struct wil6210_priv *wil)
  1615. {
  1616. debugfs_remove_recursive(wil->debug);
  1617. wil->debug = NULL;
  1618. kfree(wil->dbg_data.data_arr);
  1619. /* free pmc memory without sending command to fw, as it will
  1620. * be reset on the way down anyway
  1621. */
  1622. wil_pmc_free(wil, false);
  1623. }