debugfs.c 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927
  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. for (i = 0; i < ARRAY_SIZE(wil->sta); i++) {
  907. u32 status;
  908. cmd.cid = i;
  909. rc = wmi_call(wil, WMI_NOTIFY_REQ_CMDID, vif->mid,
  910. &cmd, sizeof(cmd),
  911. WMI_NOTIFY_REQ_DONE_EVENTID, &reply,
  912. sizeof(reply), 20);
  913. /* if reply is all-0, ignore this CID */
  914. if (rc || is_all_zeros(&reply.evt, sizeof(reply.evt)))
  915. continue;
  916. status = le32_to_cpu(reply.evt.status);
  917. seq_printf(s, "CID %d {\n"
  918. " TSF = 0x%016llx\n"
  919. " TxMCS = %2d TxTpt = %4d\n"
  920. " SQI = %4d\n"
  921. " RSSI = %4d\n"
  922. " Status = 0x%08x %s\n"
  923. " Sectors(rx:tx) my %2d:%2d peer %2d:%2d\n"
  924. " Goodput(rx:tx) %4d:%4d\n"
  925. "}\n",
  926. i,
  927. le64_to_cpu(reply.evt.tsf),
  928. le16_to_cpu(reply.evt.bf_mcs),
  929. le32_to_cpu(reply.evt.tx_tpt),
  930. reply.evt.sqi,
  931. reply.evt.rssi,
  932. status, wil_bfstatus_str(status),
  933. le16_to_cpu(reply.evt.my_rx_sector),
  934. le16_to_cpu(reply.evt.my_tx_sector),
  935. le16_to_cpu(reply.evt.other_rx_sector),
  936. le16_to_cpu(reply.evt.other_tx_sector),
  937. le32_to_cpu(reply.evt.rx_goodput),
  938. le32_to_cpu(reply.evt.tx_goodput));
  939. }
  940. return 0;
  941. }
  942. static int wil_bf_seq_open(struct inode *inode, struct file *file)
  943. {
  944. return single_open(file, wil_bf_debugfs_show, inode->i_private);
  945. }
  946. static const struct file_operations fops_bf = {
  947. .open = wil_bf_seq_open,
  948. .release = single_release,
  949. .read = seq_read,
  950. .llseek = seq_lseek,
  951. };
  952. /*---------temp------------*/
  953. static void print_temp(struct seq_file *s, const char *prefix, u32 t)
  954. {
  955. switch (t) {
  956. case 0:
  957. case ~(u32)0:
  958. seq_printf(s, "%s N/A\n", prefix);
  959. break;
  960. default:
  961. seq_printf(s, "%s %d.%03d\n", prefix, t / 1000, t % 1000);
  962. break;
  963. }
  964. }
  965. static int wil_temp_debugfs_show(struct seq_file *s, void *data)
  966. {
  967. struct wil6210_priv *wil = s->private;
  968. u32 t_m, t_r;
  969. int rc = wmi_get_temperature(wil, &t_m, &t_r);
  970. if (rc) {
  971. seq_puts(s, "Failed\n");
  972. return 0;
  973. }
  974. print_temp(s, "T_mac =", t_m);
  975. print_temp(s, "T_radio =", t_r);
  976. return 0;
  977. }
  978. static int wil_temp_seq_open(struct inode *inode, struct file *file)
  979. {
  980. return single_open(file, wil_temp_debugfs_show, inode->i_private);
  981. }
  982. static const struct file_operations fops_temp = {
  983. .open = wil_temp_seq_open,
  984. .release = single_release,
  985. .read = seq_read,
  986. .llseek = seq_lseek,
  987. };
  988. /*---------freq------------*/
  989. static int wil_freq_debugfs_show(struct seq_file *s, void *data)
  990. {
  991. struct wil6210_priv *wil = s->private;
  992. struct wireless_dev *wdev = wil->main_ndev->ieee80211_ptr;
  993. u16 freq = wdev->chandef.chan ? wdev->chandef.chan->center_freq : 0;
  994. seq_printf(s, "Freq = %d\n", freq);
  995. return 0;
  996. }
  997. static int wil_freq_seq_open(struct inode *inode, struct file *file)
  998. {
  999. return single_open(file, wil_freq_debugfs_show, inode->i_private);
  1000. }
  1001. static const struct file_operations fops_freq = {
  1002. .open = wil_freq_seq_open,
  1003. .release = single_release,
  1004. .read = seq_read,
  1005. .llseek = seq_lseek,
  1006. };
  1007. /*---------link------------*/
  1008. static int wil_link_debugfs_show(struct seq_file *s, void *data)
  1009. {
  1010. struct wil6210_priv *wil = s->private;
  1011. struct station_info sinfo;
  1012. int i, rc;
  1013. for (i = 0; i < ARRAY_SIZE(wil->sta); i++) {
  1014. struct wil_sta_info *p = &wil->sta[i];
  1015. char *status = "unknown";
  1016. struct wil6210_vif *vif;
  1017. u8 mid;
  1018. switch (p->status) {
  1019. case wil_sta_unused:
  1020. status = "unused ";
  1021. break;
  1022. case wil_sta_conn_pending:
  1023. status = "pending ";
  1024. break;
  1025. case wil_sta_connected:
  1026. status = "connected";
  1027. break;
  1028. }
  1029. mid = (p->status != wil_sta_unused) ? p->mid : U8_MAX;
  1030. seq_printf(s, "[%d][MID %d] %pM %s\n",
  1031. i, mid, p->addr, status);
  1032. if (p->status != wil_sta_connected)
  1033. continue;
  1034. vif = (mid < wil->max_vifs) ? wil->vifs[mid] : NULL;
  1035. if (vif) {
  1036. rc = wil_cid_fill_sinfo(vif, i, &sinfo);
  1037. if (rc)
  1038. return rc;
  1039. seq_printf(s, " Tx_mcs = %d\n", sinfo.txrate.mcs);
  1040. seq_printf(s, " Rx_mcs = %d\n", sinfo.rxrate.mcs);
  1041. seq_printf(s, " SQ = %d\n", sinfo.signal);
  1042. } else {
  1043. seq_puts(s, " INVALID MID\n");
  1044. }
  1045. }
  1046. return 0;
  1047. }
  1048. static int wil_link_seq_open(struct inode *inode, struct file *file)
  1049. {
  1050. return single_open(file, wil_link_debugfs_show, inode->i_private);
  1051. }
  1052. static const struct file_operations fops_link = {
  1053. .open = wil_link_seq_open,
  1054. .release = single_release,
  1055. .read = seq_read,
  1056. .llseek = seq_lseek,
  1057. };
  1058. /*---------info------------*/
  1059. static int wil_info_debugfs_show(struct seq_file *s, void *data)
  1060. {
  1061. struct wil6210_priv *wil = s->private;
  1062. struct net_device *ndev = wil->main_ndev;
  1063. int is_ac = power_supply_is_system_supplied();
  1064. int rx = atomic_xchg(&wil->isr_count_rx, 0);
  1065. int tx = atomic_xchg(&wil->isr_count_tx, 0);
  1066. static ulong rxf_old, txf_old;
  1067. ulong rxf = ndev->stats.rx_packets;
  1068. ulong txf = ndev->stats.tx_packets;
  1069. unsigned int i;
  1070. /* >0 : AC; 0 : battery; <0 : error */
  1071. seq_printf(s, "AC powered : %d\n", is_ac);
  1072. seq_printf(s, "Rx irqs:packets : %8d : %8ld\n", rx, rxf - rxf_old);
  1073. seq_printf(s, "Tx irqs:packets : %8d : %8ld\n", tx, txf - txf_old);
  1074. rxf_old = rxf;
  1075. txf_old = txf;
  1076. #define CHECK_QSTATE(x) (state & BIT(__QUEUE_STATE_ ## x)) ? \
  1077. " " __stringify(x) : ""
  1078. for (i = 0; i < ndev->num_tx_queues; i++) {
  1079. struct netdev_queue *txq = netdev_get_tx_queue(ndev, i);
  1080. unsigned long state = txq->state;
  1081. seq_printf(s, "Tx queue[%i] state : 0x%lx%s%s%s\n", i, state,
  1082. CHECK_QSTATE(DRV_XOFF),
  1083. CHECK_QSTATE(STACK_XOFF),
  1084. CHECK_QSTATE(FROZEN)
  1085. );
  1086. }
  1087. #undef CHECK_QSTATE
  1088. return 0;
  1089. }
  1090. static int wil_info_seq_open(struct inode *inode, struct file *file)
  1091. {
  1092. return single_open(file, wil_info_debugfs_show, inode->i_private);
  1093. }
  1094. static const struct file_operations fops_info = {
  1095. .open = wil_info_seq_open,
  1096. .release = single_release,
  1097. .read = seq_read,
  1098. .llseek = seq_lseek,
  1099. };
  1100. /*---------recovery------------*/
  1101. /* mode = [manual|auto]
  1102. * state = [idle|pending|running]
  1103. */
  1104. static ssize_t wil_read_file_recovery(struct file *file, char __user *user_buf,
  1105. size_t count, loff_t *ppos)
  1106. {
  1107. struct wil6210_priv *wil = file->private_data;
  1108. char buf[80];
  1109. int n;
  1110. static const char * const sstate[] = {"idle", "pending", "running"};
  1111. n = snprintf(buf, sizeof(buf), "mode = %s\nstate = %s\n",
  1112. no_fw_recovery ? "manual" : "auto",
  1113. sstate[wil->recovery_state]);
  1114. n = min_t(int, n, sizeof(buf));
  1115. return simple_read_from_buffer(user_buf, count, ppos,
  1116. buf, n);
  1117. }
  1118. static ssize_t wil_write_file_recovery(struct file *file,
  1119. const char __user *buf_,
  1120. size_t count, loff_t *ppos)
  1121. {
  1122. struct wil6210_priv *wil = file->private_data;
  1123. static const char run_command[] = "run";
  1124. char buf[sizeof(run_command) + 1]; /* to detect "runx" */
  1125. ssize_t rc;
  1126. if (wil->recovery_state != fw_recovery_pending) {
  1127. wil_err(wil, "No recovery pending\n");
  1128. return -EINVAL;
  1129. }
  1130. if (*ppos != 0) {
  1131. wil_err(wil, "Offset [%d]\n", (int)*ppos);
  1132. return -EINVAL;
  1133. }
  1134. if (count > sizeof(buf)) {
  1135. wil_err(wil, "Input too long, len = %d\n", (int)count);
  1136. return -EINVAL;
  1137. }
  1138. rc = simple_write_to_buffer(buf, sizeof(buf) - 1, ppos, buf_, count);
  1139. if (rc < 0)
  1140. return rc;
  1141. buf[rc] = '\0';
  1142. if (0 == strcmp(buf, run_command))
  1143. wil_set_recovery_state(wil, fw_recovery_running);
  1144. else
  1145. wil_err(wil, "Bad recovery command \"%s\"\n", buf);
  1146. return rc;
  1147. }
  1148. static const struct file_operations fops_recovery = {
  1149. .read = wil_read_file_recovery,
  1150. .write = wil_write_file_recovery,
  1151. .open = simple_open,
  1152. };
  1153. /*---------Station matrix------------*/
  1154. static void wil_print_rxtid(struct seq_file *s, struct wil_tid_ampdu_rx *r)
  1155. {
  1156. int i;
  1157. u16 index = ((r->head_seq_num - r->ssn) & 0xfff) % r->buf_size;
  1158. unsigned long long drop_dup = r->drop_dup, drop_old = r->drop_old;
  1159. seq_printf(s, "([%2d] %3d TU) 0x%03x [", r->buf_size, r->timeout,
  1160. r->head_seq_num);
  1161. for (i = 0; i < r->buf_size; i++) {
  1162. if (i == index)
  1163. seq_printf(s, "%c", r->reorder_buf[i] ? 'O' : '|');
  1164. else
  1165. seq_printf(s, "%c", r->reorder_buf[i] ? '*' : '_');
  1166. }
  1167. seq_printf(s,
  1168. "] total %llu drop %llu (dup %llu + old %llu) last 0x%03x\n",
  1169. r->total, drop_dup + drop_old, drop_dup, drop_old,
  1170. r->ssn_last_drop);
  1171. }
  1172. static void wil_print_rxtid_crypto(struct seq_file *s, int tid,
  1173. struct wil_tid_crypto_rx *c)
  1174. {
  1175. int i;
  1176. for (i = 0; i < 4; i++) {
  1177. struct wil_tid_crypto_rx_single *cc = &c->key_id[i];
  1178. if (cc->key_set)
  1179. goto has_keys;
  1180. }
  1181. return;
  1182. has_keys:
  1183. if (tid < WIL_STA_TID_NUM)
  1184. seq_printf(s, " [%2d] PN", tid);
  1185. else
  1186. seq_puts(s, " [GR] PN");
  1187. for (i = 0; i < 4; i++) {
  1188. struct wil_tid_crypto_rx_single *cc = &c->key_id[i];
  1189. seq_printf(s, " [%i%s]%6phN", i, cc->key_set ? "+" : "-",
  1190. cc->pn);
  1191. }
  1192. seq_puts(s, "\n");
  1193. }
  1194. static int wil_sta_debugfs_show(struct seq_file *s, void *data)
  1195. __acquires(&p->tid_rx_lock) __releases(&p->tid_rx_lock)
  1196. {
  1197. struct wil6210_priv *wil = s->private;
  1198. int i, tid, mcs;
  1199. for (i = 0; i < ARRAY_SIZE(wil->sta); i++) {
  1200. struct wil_sta_info *p = &wil->sta[i];
  1201. char *status = "unknown";
  1202. u8 aid = 0;
  1203. u8 mid;
  1204. switch (p->status) {
  1205. case wil_sta_unused:
  1206. status = "unused ";
  1207. break;
  1208. case wil_sta_conn_pending:
  1209. status = "pending ";
  1210. break;
  1211. case wil_sta_connected:
  1212. status = "connected";
  1213. aid = p->aid;
  1214. break;
  1215. }
  1216. mid = (p->status != wil_sta_unused) ? p->mid : U8_MAX;
  1217. seq_printf(s, "[%d] %pM %s MID %d AID %d\n", i, p->addr, status,
  1218. mid, aid);
  1219. if (p->status == wil_sta_connected) {
  1220. spin_lock_bh(&p->tid_rx_lock);
  1221. for (tid = 0; tid < WIL_STA_TID_NUM; tid++) {
  1222. struct wil_tid_ampdu_rx *r = p->tid_rx[tid];
  1223. struct wil_tid_crypto_rx *c =
  1224. &p->tid_crypto_rx[tid];
  1225. if (r) {
  1226. seq_printf(s, " [%2d] ", tid);
  1227. wil_print_rxtid(s, r);
  1228. }
  1229. wil_print_rxtid_crypto(s, tid, c);
  1230. }
  1231. wil_print_rxtid_crypto(s, WIL_STA_TID_NUM,
  1232. &p->group_crypto_rx);
  1233. spin_unlock_bh(&p->tid_rx_lock);
  1234. seq_printf(s,
  1235. "Rx invalid frame: non-data %lu, short %lu, large %lu, replay %lu\n",
  1236. p->stats.rx_non_data_frame,
  1237. p->stats.rx_short_frame,
  1238. p->stats.rx_large_frame,
  1239. p->stats.rx_replay);
  1240. seq_puts(s, "Rx/MCS:");
  1241. for (mcs = 0; mcs < ARRAY_SIZE(p->stats.rx_per_mcs);
  1242. mcs++)
  1243. seq_printf(s, " %lld",
  1244. p->stats.rx_per_mcs[mcs]);
  1245. seq_puts(s, "\n");
  1246. }
  1247. }
  1248. return 0;
  1249. }
  1250. static int wil_sta_seq_open(struct inode *inode, struct file *file)
  1251. {
  1252. return single_open(file, wil_sta_debugfs_show, inode->i_private);
  1253. }
  1254. static const struct file_operations fops_sta = {
  1255. .open = wil_sta_seq_open,
  1256. .release = single_release,
  1257. .read = seq_read,
  1258. .llseek = seq_lseek,
  1259. };
  1260. static int wil_mids_debugfs_show(struct seq_file *s, void *data)
  1261. {
  1262. struct wil6210_priv *wil = s->private;
  1263. struct wil6210_vif *vif;
  1264. struct net_device *ndev;
  1265. int i;
  1266. mutex_lock(&wil->vif_mutex);
  1267. for (i = 0; i < wil->max_vifs; i++) {
  1268. vif = wil->vifs[i];
  1269. if (vif) {
  1270. ndev = vif_to_ndev(vif);
  1271. seq_printf(s, "[%d] %pM %s\n", i, ndev->dev_addr,
  1272. ndev->name);
  1273. } else {
  1274. seq_printf(s, "[%d] unused\n", i);
  1275. }
  1276. }
  1277. mutex_unlock(&wil->vif_mutex);
  1278. return 0;
  1279. }
  1280. static int wil_mids_seq_open(struct inode *inode, struct file *file)
  1281. {
  1282. return single_open(file, wil_mids_debugfs_show, inode->i_private);
  1283. }
  1284. static const struct file_operations fops_mids = {
  1285. .open = wil_mids_seq_open,
  1286. .release = single_release,
  1287. .read = seq_read,
  1288. .llseek = seq_lseek,
  1289. };
  1290. static ssize_t wil_read_file_led_cfg(struct file *file, char __user *user_buf,
  1291. size_t count, loff_t *ppos)
  1292. {
  1293. char buf[80];
  1294. int n;
  1295. n = snprintf(buf, sizeof(buf),
  1296. "led_id is set to %d, echo 1 to enable, 0 to disable\n",
  1297. led_id);
  1298. n = min_t(int, n, sizeof(buf));
  1299. return simple_read_from_buffer(user_buf, count, ppos,
  1300. buf, n);
  1301. }
  1302. static ssize_t wil_write_file_led_cfg(struct file *file,
  1303. const char __user *buf_,
  1304. size_t count, loff_t *ppos)
  1305. {
  1306. struct wil6210_priv *wil = file->private_data;
  1307. int val;
  1308. int rc;
  1309. rc = kstrtoint_from_user(buf_, count, 0, &val);
  1310. if (rc) {
  1311. wil_err(wil, "Invalid argument\n");
  1312. return rc;
  1313. }
  1314. wil_info(wil, "%s led %d\n", val ? "Enabling" : "Disabling", led_id);
  1315. rc = wmi_led_cfg(wil, val);
  1316. if (rc) {
  1317. wil_info(wil, "%s led %d failed\n",
  1318. val ? "Enabling" : "Disabling", led_id);
  1319. return rc;
  1320. }
  1321. return count;
  1322. }
  1323. static const struct file_operations fops_led_cfg = {
  1324. .read = wil_read_file_led_cfg,
  1325. .write = wil_write_file_led_cfg,
  1326. .open = simple_open,
  1327. };
  1328. /* led_blink_time, write:
  1329. * "<blink_on_slow> <blink_off_slow> <blink_on_med> <blink_off_med> <blink_on_fast> <blink_off_fast>
  1330. */
  1331. static ssize_t wil_write_led_blink_time(struct file *file,
  1332. const char __user *buf,
  1333. size_t len, loff_t *ppos)
  1334. {
  1335. int rc;
  1336. char *kbuf = kmalloc(len + 1, GFP_KERNEL);
  1337. if (!kbuf)
  1338. return -ENOMEM;
  1339. rc = simple_write_to_buffer(kbuf, len, ppos, buf, len);
  1340. if (rc != len) {
  1341. kfree(kbuf);
  1342. return rc >= 0 ? -EIO : rc;
  1343. }
  1344. kbuf[len] = '\0';
  1345. rc = sscanf(kbuf, "%d %d %d %d %d %d",
  1346. &led_blink_time[WIL_LED_TIME_SLOW].on_ms,
  1347. &led_blink_time[WIL_LED_TIME_SLOW].off_ms,
  1348. &led_blink_time[WIL_LED_TIME_MED].on_ms,
  1349. &led_blink_time[WIL_LED_TIME_MED].off_ms,
  1350. &led_blink_time[WIL_LED_TIME_FAST].on_ms,
  1351. &led_blink_time[WIL_LED_TIME_FAST].off_ms);
  1352. kfree(kbuf);
  1353. if (rc < 0)
  1354. return rc;
  1355. if (rc < 6)
  1356. return -EINVAL;
  1357. return len;
  1358. }
  1359. static ssize_t wil_read_led_blink_time(struct file *file, char __user *user_buf,
  1360. size_t count, loff_t *ppos)
  1361. {
  1362. static char text[400];
  1363. snprintf(text, sizeof(text),
  1364. "To set led blink on/off time variables write:\n"
  1365. "<blink_on_slow> <blink_off_slow> <blink_on_med> "
  1366. "<blink_off_med> <blink_on_fast> <blink_off_fast>\n"
  1367. "The current values are:\n"
  1368. "%d %d %d %d %d %d\n",
  1369. led_blink_time[WIL_LED_TIME_SLOW].on_ms,
  1370. led_blink_time[WIL_LED_TIME_SLOW].off_ms,
  1371. led_blink_time[WIL_LED_TIME_MED].on_ms,
  1372. led_blink_time[WIL_LED_TIME_MED].off_ms,
  1373. led_blink_time[WIL_LED_TIME_FAST].on_ms,
  1374. led_blink_time[WIL_LED_TIME_FAST].off_ms);
  1375. return simple_read_from_buffer(user_buf, count, ppos, text,
  1376. sizeof(text));
  1377. }
  1378. static const struct file_operations fops_led_blink_time = {
  1379. .read = wil_read_led_blink_time,
  1380. .write = wil_write_led_blink_time,
  1381. .open = simple_open,
  1382. };
  1383. /*---------FW capabilities------------*/
  1384. static int wil_fw_capabilities_debugfs_show(struct seq_file *s, void *data)
  1385. {
  1386. struct wil6210_priv *wil = s->private;
  1387. seq_printf(s, "fw_capabilities : %*pb\n", WMI_FW_CAPABILITY_MAX,
  1388. wil->fw_capabilities);
  1389. return 0;
  1390. }
  1391. static int wil_fw_capabilities_seq_open(struct inode *inode, struct file *file)
  1392. {
  1393. return single_open(file, wil_fw_capabilities_debugfs_show,
  1394. inode->i_private);
  1395. }
  1396. static const struct file_operations fops_fw_capabilities = {
  1397. .open = wil_fw_capabilities_seq_open,
  1398. .release = single_release,
  1399. .read = seq_read,
  1400. .llseek = seq_lseek,
  1401. };
  1402. /*---------FW version------------*/
  1403. static int wil_fw_version_debugfs_show(struct seq_file *s, void *data)
  1404. {
  1405. struct wil6210_priv *wil = s->private;
  1406. if (wil->fw_version[0])
  1407. seq_printf(s, "%s\n", wil->fw_version);
  1408. else
  1409. seq_puts(s, "N/A\n");
  1410. return 0;
  1411. }
  1412. static int wil_fw_version_seq_open(struct inode *inode, struct file *file)
  1413. {
  1414. return single_open(file, wil_fw_version_debugfs_show,
  1415. inode->i_private);
  1416. }
  1417. static const struct file_operations fops_fw_version = {
  1418. .open = wil_fw_version_seq_open,
  1419. .release = single_release,
  1420. .read = seq_read,
  1421. .llseek = seq_lseek,
  1422. };
  1423. /*---------suspend_stats---------*/
  1424. static ssize_t wil_write_suspend_stats(struct file *file,
  1425. const char __user *buf,
  1426. size_t len, loff_t *ppos)
  1427. {
  1428. struct wil6210_priv *wil = file->private_data;
  1429. memset(&wil->suspend_stats, 0, sizeof(wil->suspend_stats));
  1430. return len;
  1431. }
  1432. static ssize_t wil_read_suspend_stats(struct file *file,
  1433. char __user *user_buf,
  1434. size_t count, loff_t *ppos)
  1435. {
  1436. struct wil6210_priv *wil = file->private_data;
  1437. char *text;
  1438. int n, ret, text_size = 500;
  1439. text = kmalloc(text_size, GFP_KERNEL);
  1440. if (!text)
  1441. return -ENOMEM;
  1442. n = snprintf(text, text_size,
  1443. "Radio on suspend statistics:\n"
  1444. "successful suspends:%ld failed suspends:%ld\n"
  1445. "successful resumes:%ld failed resumes:%ld\n"
  1446. "rejected by device:%ld\n"
  1447. "Radio off suspend statistics:\n"
  1448. "successful suspends:%ld failed suspends:%ld\n"
  1449. "successful resumes:%ld failed resumes:%ld\n"
  1450. "General statistics:\n"
  1451. "rejected by host:%ld\n",
  1452. wil->suspend_stats.r_on.successful_suspends,
  1453. wil->suspend_stats.r_on.failed_suspends,
  1454. wil->suspend_stats.r_on.successful_resumes,
  1455. wil->suspend_stats.r_on.failed_resumes,
  1456. wil->suspend_stats.rejected_by_device,
  1457. wil->suspend_stats.r_off.successful_suspends,
  1458. wil->suspend_stats.r_off.failed_suspends,
  1459. wil->suspend_stats.r_off.successful_resumes,
  1460. wil->suspend_stats.r_off.failed_resumes,
  1461. wil->suspend_stats.rejected_by_host);
  1462. n = min_t(int, n, text_size);
  1463. ret = simple_read_from_buffer(user_buf, count, ppos, text, n);
  1464. kfree(text);
  1465. return ret;
  1466. }
  1467. static const struct file_operations fops_suspend_stats = {
  1468. .read = wil_read_suspend_stats,
  1469. .write = wil_write_suspend_stats,
  1470. .open = simple_open,
  1471. };
  1472. /*----------------*/
  1473. static void wil6210_debugfs_init_blobs(struct wil6210_priv *wil,
  1474. struct dentry *dbg)
  1475. {
  1476. int i;
  1477. char name[32];
  1478. for (i = 0; i < ARRAY_SIZE(fw_mapping); i++) {
  1479. struct wil_blob_wrapper *wil_blob = &wil->blobs[i];
  1480. struct debugfs_blob_wrapper *blob = &wil_blob->blob;
  1481. const struct fw_map *map = &fw_mapping[i];
  1482. if (!map->name)
  1483. continue;
  1484. wil_blob->wil = wil;
  1485. blob->data = (void * __force)wil->csr + HOSTADDR(map->host);
  1486. blob->size = map->to - map->from;
  1487. snprintf(name, sizeof(name), "blob_%s", map->name);
  1488. wil_debugfs_create_ioblob(name, 0444, dbg, wil_blob);
  1489. }
  1490. }
  1491. /* misc files */
  1492. static const struct {
  1493. const char *name;
  1494. umode_t mode;
  1495. const struct file_operations *fops;
  1496. } dbg_files[] = {
  1497. {"mbox", 0444, &fops_mbox},
  1498. {"vrings", 0444, &fops_vring},
  1499. {"stations", 0444, &fops_sta},
  1500. {"mids", 0444, &fops_mids},
  1501. {"desc", 0444, &fops_txdesc},
  1502. {"bf", 0444, &fops_bf},
  1503. {"mem_val", 0644, &fops_memread},
  1504. {"reset", 0244, &fops_reset},
  1505. {"rxon", 0244, &fops_rxon},
  1506. {"tx_mgmt", 0244, &fops_txmgmt},
  1507. {"wmi_send", 0244, &fops_wmi},
  1508. {"back", 0644, &fops_back},
  1509. {"pmccfg", 0644, &fops_pmccfg},
  1510. {"pmcdata", 0444, &fops_pmcdata},
  1511. {"temp", 0444, &fops_temp},
  1512. {"freq", 0444, &fops_freq},
  1513. {"link", 0444, &fops_link},
  1514. {"info", 0444, &fops_info},
  1515. {"recovery", 0644, &fops_recovery},
  1516. {"led_cfg", 0644, &fops_led_cfg},
  1517. {"led_blink_time", 0644, &fops_led_blink_time},
  1518. {"fw_capabilities", 0444, &fops_fw_capabilities},
  1519. {"fw_version", 0444, &fops_fw_version},
  1520. {"suspend_stats", 0644, &fops_suspend_stats},
  1521. };
  1522. static void wil6210_debugfs_init_files(struct wil6210_priv *wil,
  1523. struct dentry *dbg)
  1524. {
  1525. int i;
  1526. for (i = 0; i < ARRAY_SIZE(dbg_files); i++)
  1527. debugfs_create_file(dbg_files[i].name, dbg_files[i].mode, dbg,
  1528. wil, dbg_files[i].fops);
  1529. }
  1530. /* interrupt control blocks */
  1531. static const struct {
  1532. const char *name;
  1533. u32 icr_off;
  1534. } dbg_icr[] = {
  1535. {"USER_ICR", HOSTADDR(RGF_USER_USER_ICR)},
  1536. {"DMA_EP_TX_ICR", HOSTADDR(RGF_DMA_EP_TX_ICR)},
  1537. {"DMA_EP_RX_ICR", HOSTADDR(RGF_DMA_EP_RX_ICR)},
  1538. {"DMA_EP_MISC_ICR", HOSTADDR(RGF_DMA_EP_MISC_ICR)},
  1539. };
  1540. static void wil6210_debugfs_init_isr(struct wil6210_priv *wil,
  1541. struct dentry *dbg)
  1542. {
  1543. int i;
  1544. for (i = 0; i < ARRAY_SIZE(dbg_icr); i++)
  1545. wil6210_debugfs_create_ISR(wil, dbg_icr[i].name, dbg,
  1546. dbg_icr[i].icr_off);
  1547. }
  1548. #define WIL_FIELD(name, mode, type) { __stringify(name), mode, \
  1549. offsetof(struct wil6210_priv, name), type}
  1550. /* fields in struct wil6210_priv */
  1551. static const struct dbg_off dbg_wil_off[] = {
  1552. WIL_FIELD(status[0], 0644, doff_ulong),
  1553. WIL_FIELD(hw_version, 0444, doff_x32),
  1554. WIL_FIELD(recovery_count, 0444, doff_u32),
  1555. WIL_FIELD(discovery_mode, 0644, doff_u8),
  1556. WIL_FIELD(chip_revision, 0444, doff_u8),
  1557. WIL_FIELD(abft_len, 0644, doff_u8),
  1558. WIL_FIELD(wakeup_trigger, 0644, doff_u8),
  1559. WIL_FIELD(vring_idle_trsh, 0644, doff_u32),
  1560. {},
  1561. };
  1562. static const struct dbg_off dbg_wil_regs[] = {
  1563. {"RGF_MAC_MTRL_COUNTER_0", 0444, HOSTADDR(RGF_MAC_MTRL_COUNTER_0),
  1564. doff_io32},
  1565. {"RGF_USER_USAGE_1", 0444, HOSTADDR(RGF_USER_USAGE_1), doff_io32},
  1566. {},
  1567. };
  1568. /* static parameters */
  1569. static const struct dbg_off dbg_statics[] = {
  1570. {"desc_index", 0644, (ulong)&dbg_txdesc_index, doff_u32},
  1571. {"vring_index", 0644, (ulong)&dbg_vring_index, doff_u32},
  1572. {"mem_addr", 0644, (ulong)&mem_addr, doff_u32},
  1573. {"led_polarity", 0644, (ulong)&led_polarity, doff_u8},
  1574. {},
  1575. };
  1576. static const int dbg_off_count = 4 * (ARRAY_SIZE(isr_off) - 1) +
  1577. ARRAY_SIZE(dbg_wil_regs) - 1 +
  1578. ARRAY_SIZE(pseudo_isr_off) - 1 +
  1579. ARRAY_SIZE(lgc_itr_cnt_off) - 1 +
  1580. ARRAY_SIZE(tx_itr_cnt_off) - 1 +
  1581. ARRAY_SIZE(rx_itr_cnt_off) - 1;
  1582. int wil6210_debugfs_init(struct wil6210_priv *wil)
  1583. {
  1584. struct dentry *dbg = wil->debug = debugfs_create_dir(WIL_NAME,
  1585. wil_to_wiphy(wil)->debugfsdir);
  1586. if (IS_ERR_OR_NULL(dbg))
  1587. return -ENODEV;
  1588. wil->dbg_data.data_arr = kcalloc(dbg_off_count,
  1589. sizeof(struct wil_debugfs_iomem_data),
  1590. GFP_KERNEL);
  1591. if (!wil->dbg_data.data_arr) {
  1592. debugfs_remove_recursive(dbg);
  1593. wil->debug = NULL;
  1594. return -ENOMEM;
  1595. }
  1596. wil->dbg_data.iomem_data_count = 0;
  1597. wil_pmc_init(wil);
  1598. wil6210_debugfs_init_files(wil, dbg);
  1599. wil6210_debugfs_init_isr(wil, dbg);
  1600. wil6210_debugfs_init_blobs(wil, dbg);
  1601. wil6210_debugfs_init_offset(wil, dbg, wil, dbg_wil_off);
  1602. wil6210_debugfs_init_offset(wil, dbg, (void * __force)wil->csr,
  1603. dbg_wil_regs);
  1604. wil6210_debugfs_init_offset(wil, dbg, NULL, dbg_statics);
  1605. wil6210_debugfs_create_pseudo_ISR(wil, dbg);
  1606. wil6210_debugfs_create_ITR_CNT(wil, dbg);
  1607. return 0;
  1608. }
  1609. void wil6210_debugfs_remove(struct wil6210_priv *wil)
  1610. {
  1611. debugfs_remove_recursive(wil->debug);
  1612. wil->debug = NULL;
  1613. kfree(wil->dbg_data.data_arr);
  1614. /* free pmc memory without sending command to fw, as it will
  1615. * be reset on the way down anyway
  1616. */
  1617. wil_pmc_free(wil, false);
  1618. }