debugfs.c 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309
  1. /*
  2. * Copyright (c) 2012-2014 Qualcomm Atheros, Inc.
  3. *
  4. * Permission to use, copy, modify, and/or distribute this software for any
  5. * purpose with or without fee is hereby granted, provided that the above
  6. * copyright notice and this permission notice appear in all copies.
  7. *
  8. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  9. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  10. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  11. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  12. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  13. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  14. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. #include <linux/module.h>
  17. #include <linux/debugfs.h>
  18. #include <linux/seq_file.h>
  19. #include <linux/pci.h>
  20. #include <linux/rtnetlink.h>
  21. #include <linux/power_supply.h>
  22. #include "wil6210.h"
  23. #include "wmi.h"
  24. #include "txrx.h"
  25. /* Nasty hack. Better have per device instances */
  26. static u32 mem_addr;
  27. static u32 dbg_txdesc_index;
  28. static u32 dbg_vring_index; /* 24+ for Rx, 0..23 for Tx */
  29. enum dbg_off_type {
  30. doff_u32 = 0,
  31. doff_x32 = 1,
  32. doff_ulong = 2,
  33. doff_io32 = 3,
  34. };
  35. /* offset to "wil" */
  36. struct dbg_off {
  37. const char *name;
  38. umode_t mode;
  39. ulong off;
  40. enum dbg_off_type type;
  41. };
  42. static void wil_print_vring(struct seq_file *s, struct wil6210_priv *wil,
  43. const char *name, struct vring *vring,
  44. char _s, char _h)
  45. {
  46. void __iomem *x = wmi_addr(wil, vring->hwtail);
  47. seq_printf(s, "VRING %s = {\n", name);
  48. seq_printf(s, " pa = %pad\n", &vring->pa);
  49. seq_printf(s, " va = 0x%p\n", vring->va);
  50. seq_printf(s, " size = %d\n", vring->size);
  51. seq_printf(s, " swtail = %d\n", vring->swtail);
  52. seq_printf(s, " swhead = %d\n", vring->swhead);
  53. seq_printf(s, " hwtail = [0x%08x] -> ", vring->hwtail);
  54. if (x)
  55. seq_printf(s, "0x%08x\n", ioread32(x));
  56. else
  57. seq_puts(s, "???\n");
  58. if (vring->va && (vring->size < 1025)) {
  59. uint i;
  60. for (i = 0; i < vring->size; i++) {
  61. volatile struct vring_tx_desc *d = &vring->va[i].tx;
  62. if ((i % 64) == 0 && (i != 0))
  63. seq_puts(s, "\n");
  64. seq_printf(s, "%c", (d->dma.status & BIT(0)) ?
  65. _s : (vring->ctx[i].skb ? _h : 'h'));
  66. }
  67. seq_puts(s, "\n");
  68. }
  69. seq_puts(s, "}\n");
  70. }
  71. static int wil_vring_debugfs_show(struct seq_file *s, void *data)
  72. {
  73. uint i;
  74. struct wil6210_priv *wil = s->private;
  75. wil_print_vring(s, wil, "rx", &wil->vring_rx, 'S', '_');
  76. for (i = 0; i < ARRAY_SIZE(wil->vring_tx); i++) {
  77. struct vring *vring = &wil->vring_tx[i];
  78. struct vring_tx_data *txdata = &wil->vring_tx_data[i];
  79. if (vring->va) {
  80. int cid = wil->vring2cid_tid[i][0];
  81. int tid = wil->vring2cid_tid[i][1];
  82. u32 swhead = vring->swhead;
  83. u32 swtail = vring->swtail;
  84. int used = (vring->size + swhead - swtail)
  85. % vring->size;
  86. int avail = vring->size - used - 1;
  87. char name[10];
  88. /* performance monitoring */
  89. cycles_t now = get_cycles();
  90. cycles_t idle = txdata->idle * 100;
  91. cycles_t total = now - txdata->begin;
  92. do_div(idle, total);
  93. txdata->begin = now;
  94. txdata->idle = 0ULL;
  95. snprintf(name, sizeof(name), "tx_%2d", i);
  96. seq_printf(s, "\n%pM CID %d TID %d [%3d|%3d] idle %3d%%\n",
  97. wil->sta[cid].addr, cid, tid, used, avail,
  98. (int)idle);
  99. wil_print_vring(s, wil, name, vring, '_', 'H');
  100. }
  101. }
  102. return 0;
  103. }
  104. static int wil_vring_seq_open(struct inode *inode, struct file *file)
  105. {
  106. return single_open(file, wil_vring_debugfs_show, inode->i_private);
  107. }
  108. static const struct file_operations fops_vring = {
  109. .open = wil_vring_seq_open,
  110. .release = single_release,
  111. .read = seq_read,
  112. .llseek = seq_lseek,
  113. };
  114. static void wil_print_ring(struct seq_file *s, const char *prefix,
  115. void __iomem *off)
  116. {
  117. struct wil6210_priv *wil = s->private;
  118. struct wil6210_mbox_ring r;
  119. int rsize;
  120. uint i;
  121. wil_memcpy_fromio_32(&r, off, sizeof(r));
  122. wil_mbox_ring_le2cpus(&r);
  123. /*
  124. * we just read memory block from NIC. This memory may be
  125. * garbage. Check validity before using it.
  126. */
  127. rsize = r.size / sizeof(struct wil6210_mbox_ring_desc);
  128. seq_printf(s, "ring %s = {\n", prefix);
  129. seq_printf(s, " base = 0x%08x\n", r.base);
  130. seq_printf(s, " size = 0x%04x bytes -> %d entries\n", r.size, rsize);
  131. seq_printf(s, " tail = 0x%08x\n", r.tail);
  132. seq_printf(s, " head = 0x%08x\n", r.head);
  133. seq_printf(s, " entry size = %d\n", r.entry_size);
  134. if (r.size % sizeof(struct wil6210_mbox_ring_desc)) {
  135. seq_printf(s, " ??? size is not multiple of %zd, garbage?\n",
  136. sizeof(struct wil6210_mbox_ring_desc));
  137. goto out;
  138. }
  139. if (!wmi_addr(wil, r.base) ||
  140. !wmi_addr(wil, r.tail) ||
  141. !wmi_addr(wil, r.head)) {
  142. seq_puts(s, " ??? pointers are garbage?\n");
  143. goto out;
  144. }
  145. for (i = 0; i < rsize; i++) {
  146. struct wil6210_mbox_ring_desc d;
  147. struct wil6210_mbox_hdr hdr;
  148. size_t delta = i * sizeof(d);
  149. void __iomem *x = wil->csr + HOSTADDR(r.base) + delta;
  150. wil_memcpy_fromio_32(&d, x, sizeof(d));
  151. seq_printf(s, " [%2x] %s %s%s 0x%08x", i,
  152. d.sync ? "F" : "E",
  153. (r.tail - r.base == delta) ? "t" : " ",
  154. (r.head - r.base == delta) ? "h" : " ",
  155. le32_to_cpu(d.addr));
  156. if (0 == wmi_read_hdr(wil, d.addr, &hdr)) {
  157. u16 len = le16_to_cpu(hdr.len);
  158. seq_printf(s, " -> %04x %04x %04x %02x\n",
  159. le16_to_cpu(hdr.seq), len,
  160. le16_to_cpu(hdr.type), hdr.flags);
  161. if (len <= MAX_MBOXITEM_SIZE) {
  162. int n = 0;
  163. char printbuf[16 * 3 + 2];
  164. unsigned char databuf[MAX_MBOXITEM_SIZE];
  165. void __iomem *src = wmi_buffer(wil, d.addr) +
  166. sizeof(struct wil6210_mbox_hdr);
  167. /*
  168. * No need to check @src for validity -
  169. * we already validated @d.addr while
  170. * reading header
  171. */
  172. wil_memcpy_fromio_32(databuf, src, len);
  173. while (n < len) {
  174. int l = min(len - n, 16);
  175. hex_dump_to_buffer(databuf + n, l,
  176. 16, 1, printbuf,
  177. sizeof(printbuf),
  178. false);
  179. seq_printf(s, " : %s\n", printbuf);
  180. n += l;
  181. }
  182. }
  183. } else {
  184. seq_puts(s, "\n");
  185. }
  186. }
  187. out:
  188. seq_puts(s, "}\n");
  189. }
  190. static int wil_mbox_debugfs_show(struct seq_file *s, void *data)
  191. {
  192. struct wil6210_priv *wil = s->private;
  193. wil_print_ring(s, "tx", wil->csr + HOST_MBOX +
  194. offsetof(struct wil6210_mbox_ctl, tx));
  195. wil_print_ring(s, "rx", wil->csr + HOST_MBOX +
  196. offsetof(struct wil6210_mbox_ctl, rx));
  197. return 0;
  198. }
  199. static int wil_mbox_seq_open(struct inode *inode, struct file *file)
  200. {
  201. return single_open(file, wil_mbox_debugfs_show, inode->i_private);
  202. }
  203. static const struct file_operations fops_mbox = {
  204. .open = wil_mbox_seq_open,
  205. .release = single_release,
  206. .read = seq_read,
  207. .llseek = seq_lseek,
  208. };
  209. static int wil_debugfs_iomem_x32_set(void *data, u64 val)
  210. {
  211. iowrite32(val, (void __iomem *)data);
  212. wmb(); /* make sure write propagated to HW */
  213. return 0;
  214. }
  215. static int wil_debugfs_iomem_x32_get(void *data, u64 *val)
  216. {
  217. *val = ioread32((void __iomem *)data);
  218. return 0;
  219. }
  220. DEFINE_SIMPLE_ATTRIBUTE(fops_iomem_x32, wil_debugfs_iomem_x32_get,
  221. wil_debugfs_iomem_x32_set, "0x%08llx\n");
  222. static struct dentry *wil_debugfs_create_iomem_x32(const char *name,
  223. umode_t mode,
  224. struct dentry *parent,
  225. void *value)
  226. {
  227. return debugfs_create_file(name, mode, parent, value,
  228. &fops_iomem_x32);
  229. }
  230. static int wil_debugfs_ulong_set(void *data, u64 val)
  231. {
  232. *(ulong *)data = val;
  233. return 0;
  234. }
  235. static int wil_debugfs_ulong_get(void *data, u64 *val)
  236. {
  237. *val = *(ulong *)data;
  238. return 0;
  239. }
  240. DEFINE_SIMPLE_ATTRIBUTE(wil_fops_ulong, wil_debugfs_ulong_get,
  241. wil_debugfs_ulong_set, "%llu\n");
  242. static struct dentry *wil_debugfs_create_ulong(const char *name, umode_t mode,
  243. struct dentry *parent,
  244. ulong *value)
  245. {
  246. return debugfs_create_file(name, mode, parent, value, &wil_fops_ulong);
  247. }
  248. /**
  249. * wil6210_debugfs_init_offset - create set of debugfs files
  250. * @wil - driver's context, used for printing
  251. * @dbg - directory on the debugfs, where files will be created
  252. * @base - base address used in address calculation
  253. * @tbl - table with file descriptions. Should be terminated with empty element.
  254. *
  255. * Creates files accordingly to the @tbl.
  256. */
  257. static void wil6210_debugfs_init_offset(struct wil6210_priv *wil,
  258. struct dentry *dbg, void *base,
  259. const struct dbg_off * const tbl)
  260. {
  261. int i;
  262. for (i = 0; tbl[i].name; i++) {
  263. struct dentry *f;
  264. switch (tbl[i].type) {
  265. case doff_u32:
  266. f = debugfs_create_u32(tbl[i].name, tbl[i].mode, dbg,
  267. base + tbl[i].off);
  268. break;
  269. case doff_x32:
  270. f = debugfs_create_x32(tbl[i].name, tbl[i].mode, dbg,
  271. base + tbl[i].off);
  272. break;
  273. case doff_ulong:
  274. f = wil_debugfs_create_ulong(tbl[i].name, tbl[i].mode,
  275. dbg, base + tbl[i].off);
  276. break;
  277. case doff_io32:
  278. f = wil_debugfs_create_iomem_x32(tbl[i].name,
  279. tbl[i].mode, dbg,
  280. base + tbl[i].off);
  281. break;
  282. default:
  283. f = ERR_PTR(-EINVAL);
  284. }
  285. if (IS_ERR_OR_NULL(f))
  286. wil_err(wil, "Create file \"%s\": err %ld\n",
  287. tbl[i].name, PTR_ERR(f));
  288. }
  289. }
  290. static const struct dbg_off isr_off[] = {
  291. {"ICC", S_IRUGO | S_IWUSR, offsetof(struct RGF_ICR, ICC), doff_io32},
  292. {"ICR", S_IRUGO | S_IWUSR, offsetof(struct RGF_ICR, ICR), doff_io32},
  293. {"ICM", S_IRUGO | S_IWUSR, offsetof(struct RGF_ICR, ICM), doff_io32},
  294. {"ICS", S_IWUSR, offsetof(struct RGF_ICR, ICS), doff_io32},
  295. {"IMV", S_IRUGO | S_IWUSR, offsetof(struct RGF_ICR, IMV), doff_io32},
  296. {"IMS", S_IWUSR, offsetof(struct RGF_ICR, IMS), doff_io32},
  297. {"IMC", S_IWUSR, offsetof(struct RGF_ICR, IMC), doff_io32},
  298. {},
  299. };
  300. static int wil6210_debugfs_create_ISR(struct wil6210_priv *wil,
  301. const char *name,
  302. struct dentry *parent, u32 off)
  303. {
  304. struct dentry *d = debugfs_create_dir(name, parent);
  305. if (IS_ERR_OR_NULL(d))
  306. return -ENODEV;
  307. wil6210_debugfs_init_offset(wil, d, (void * __force)wil->csr + off,
  308. isr_off);
  309. return 0;
  310. }
  311. static const struct dbg_off pseudo_isr_off[] = {
  312. {"CAUSE", S_IRUGO, HOSTADDR(RGF_DMA_PSEUDO_CAUSE), doff_io32},
  313. {"MASK_SW", S_IRUGO, HOSTADDR(RGF_DMA_PSEUDO_CAUSE_MASK_SW), doff_io32},
  314. {"MASK_FW", S_IRUGO, HOSTADDR(RGF_DMA_PSEUDO_CAUSE_MASK_FW), doff_io32},
  315. {},
  316. };
  317. static int wil6210_debugfs_create_pseudo_ISR(struct wil6210_priv *wil,
  318. struct dentry *parent)
  319. {
  320. struct dentry *d = debugfs_create_dir("PSEUDO_ISR", parent);
  321. if (IS_ERR_OR_NULL(d))
  322. return -ENODEV;
  323. wil6210_debugfs_init_offset(wil, d, (void * __force)wil->csr,
  324. pseudo_isr_off);
  325. return 0;
  326. }
  327. static const struct dbg_off itr_cnt_off[] = {
  328. {"TRSH", S_IRUGO | S_IWUSR, HOSTADDR(RGF_DMA_ITR_CNT_TRSH), doff_io32},
  329. {"DATA", S_IRUGO | S_IWUSR, HOSTADDR(RGF_DMA_ITR_CNT_DATA), doff_io32},
  330. {"CTL", S_IRUGO | S_IWUSR, HOSTADDR(RGF_DMA_ITR_CNT_CRL), doff_io32},
  331. {},
  332. };
  333. static int wil6210_debugfs_create_ITR_CNT(struct wil6210_priv *wil,
  334. struct dentry *parent)
  335. {
  336. struct dentry *d = debugfs_create_dir("ITR_CNT", parent);
  337. if (IS_ERR_OR_NULL(d))
  338. return -ENODEV;
  339. wil6210_debugfs_init_offset(wil, d, (void * __force)wil->csr,
  340. itr_cnt_off);
  341. return 0;
  342. }
  343. static int wil_memread_debugfs_show(struct seq_file *s, void *data)
  344. {
  345. struct wil6210_priv *wil = s->private;
  346. void __iomem *a = wmi_buffer(wil, cpu_to_le32(mem_addr));
  347. if (a)
  348. seq_printf(s, "[0x%08x] = 0x%08x\n", mem_addr, ioread32(a));
  349. else
  350. seq_printf(s, "[0x%08x] = INVALID\n", mem_addr);
  351. return 0;
  352. }
  353. static int wil_memread_seq_open(struct inode *inode, struct file *file)
  354. {
  355. return single_open(file, wil_memread_debugfs_show, inode->i_private);
  356. }
  357. static const struct file_operations fops_memread = {
  358. .open = wil_memread_seq_open,
  359. .release = single_release,
  360. .read = seq_read,
  361. .llseek = seq_lseek,
  362. };
  363. static ssize_t wil_read_file_ioblob(struct file *file, char __user *user_buf,
  364. size_t count, loff_t *ppos)
  365. {
  366. enum { max_count = 4096 };
  367. struct debugfs_blob_wrapper *blob = file->private_data;
  368. loff_t pos = *ppos;
  369. size_t available = blob->size;
  370. void *buf;
  371. size_t ret;
  372. if (pos < 0)
  373. return -EINVAL;
  374. if (pos >= available || !count)
  375. return 0;
  376. if (count > available - pos)
  377. count = available - pos;
  378. if (count > max_count)
  379. count = max_count;
  380. buf = kmalloc(count, GFP_KERNEL);
  381. if (!buf)
  382. return -ENOMEM;
  383. wil_memcpy_fromio_32(buf, (const volatile void __iomem *)blob->data +
  384. pos, count);
  385. ret = copy_to_user(user_buf, buf, count);
  386. kfree(buf);
  387. if (ret == count)
  388. return -EFAULT;
  389. count -= ret;
  390. *ppos = pos + count;
  391. return count;
  392. }
  393. static const struct file_operations fops_ioblob = {
  394. .read = wil_read_file_ioblob,
  395. .open = simple_open,
  396. .llseek = default_llseek,
  397. };
  398. static
  399. struct dentry *wil_debugfs_create_ioblob(const char *name,
  400. umode_t mode,
  401. struct dentry *parent,
  402. struct debugfs_blob_wrapper *blob)
  403. {
  404. return debugfs_create_file(name, mode, parent, blob, &fops_ioblob);
  405. }
  406. /*---reset---*/
  407. static ssize_t wil_write_file_reset(struct file *file, const char __user *buf,
  408. size_t len, loff_t *ppos)
  409. {
  410. struct wil6210_priv *wil = file->private_data;
  411. struct net_device *ndev = wil_to_ndev(wil);
  412. /**
  413. * BUG:
  414. * this code does NOT sync device state with the rest of system
  415. * use with care, debug only!!!
  416. */
  417. rtnl_lock();
  418. dev_close(ndev);
  419. ndev->flags &= ~IFF_UP;
  420. rtnl_unlock();
  421. wil_reset(wil);
  422. return len;
  423. }
  424. static const struct file_operations fops_reset = {
  425. .write = wil_write_file_reset,
  426. .open = simple_open,
  427. };
  428. /*---write channel 1..4 to rxon for it, 0 to rxoff---*/
  429. static ssize_t wil_write_file_rxon(struct file *file, const char __user *buf,
  430. size_t len, loff_t *ppos)
  431. {
  432. struct wil6210_priv *wil = file->private_data;
  433. int rc;
  434. long channel;
  435. bool on;
  436. char *kbuf = kmalloc(len + 1, GFP_KERNEL);
  437. if (!kbuf)
  438. return -ENOMEM;
  439. if (copy_from_user(kbuf, buf, len)) {
  440. kfree(kbuf);
  441. return -EIO;
  442. }
  443. kbuf[len] = '\0';
  444. rc = kstrtol(kbuf, 0, &channel);
  445. kfree(kbuf);
  446. if (rc)
  447. return rc;
  448. if ((channel < 0) || (channel > 4)) {
  449. wil_err(wil, "Invalid channel %ld\n", channel);
  450. return -EINVAL;
  451. }
  452. on = !!channel;
  453. if (on) {
  454. rc = wmi_set_channel(wil, (int)channel);
  455. if (rc)
  456. return rc;
  457. }
  458. rc = wmi_rxon(wil, on);
  459. if (rc)
  460. return rc;
  461. return len;
  462. }
  463. static const struct file_operations fops_rxon = {
  464. .write = wil_write_file_rxon,
  465. .open = simple_open,
  466. };
  467. /*---tx_mgmt---*/
  468. /* Write mgmt frame to this file to send it */
  469. static ssize_t wil_write_file_txmgmt(struct file *file, const char __user *buf,
  470. size_t len, loff_t *ppos)
  471. {
  472. struct wil6210_priv *wil = file->private_data;
  473. struct wiphy *wiphy = wil_to_wiphy(wil);
  474. struct wireless_dev *wdev = wil_to_wdev(wil);
  475. struct cfg80211_mgmt_tx_params params;
  476. int rc;
  477. void *frame = kmalloc(len, GFP_KERNEL);
  478. if (!frame)
  479. return -ENOMEM;
  480. if (copy_from_user(frame, buf, len))
  481. return -EIO;
  482. params.buf = frame;
  483. params.len = len;
  484. params.chan = wdev->preset_chandef.chan;
  485. rc = wil_cfg80211_mgmt_tx(wiphy, wdev, &params, NULL);
  486. kfree(frame);
  487. wil_info(wil, "%s() -> %d\n", __func__, rc);
  488. return len;
  489. }
  490. static const struct file_operations fops_txmgmt = {
  491. .write = wil_write_file_txmgmt,
  492. .open = simple_open,
  493. };
  494. /* Write WMI command (w/o mbox header) to this file to send it
  495. * WMI starts from wil6210_mbox_hdr_wmi header
  496. */
  497. static ssize_t wil_write_file_wmi(struct file *file, const char __user *buf,
  498. size_t len, loff_t *ppos)
  499. {
  500. struct wil6210_priv *wil = file->private_data;
  501. struct wil6210_mbox_hdr_wmi *wmi;
  502. void *cmd;
  503. int cmdlen = len - sizeof(struct wil6210_mbox_hdr_wmi);
  504. u16 cmdid;
  505. int rc, rc1;
  506. if (cmdlen <= 0)
  507. return -EINVAL;
  508. wmi = kmalloc(len, GFP_KERNEL);
  509. if (!wmi)
  510. return -ENOMEM;
  511. rc = simple_write_to_buffer(wmi, len, ppos, buf, len);
  512. if (rc < 0)
  513. return rc;
  514. cmd = &wmi[1];
  515. cmdid = le16_to_cpu(wmi->id);
  516. rc1 = wmi_send(wil, cmdid, cmd, cmdlen);
  517. kfree(wmi);
  518. wil_info(wil, "%s(0x%04x[%d]) -> %d\n", __func__, cmdid, cmdlen, rc1);
  519. return rc;
  520. }
  521. static const struct file_operations fops_wmi = {
  522. .write = wil_write_file_wmi,
  523. .open = simple_open,
  524. };
  525. static void wil_seq_hexdump(struct seq_file *s, void *p, int len,
  526. const char *prefix)
  527. {
  528. char printbuf[16 * 3 + 2];
  529. int i = 0;
  530. while (i < len) {
  531. int l = min(len - i, 16);
  532. hex_dump_to_buffer(p + i, l, 16, 1, printbuf,
  533. sizeof(printbuf), false);
  534. seq_printf(s, "%s%s\n", prefix, printbuf);
  535. i += l;
  536. }
  537. }
  538. static void wil_seq_print_skb(struct seq_file *s, struct sk_buff *skb)
  539. {
  540. int i = 0;
  541. int len = skb_headlen(skb);
  542. void *p = skb->data;
  543. int nr_frags = skb_shinfo(skb)->nr_frags;
  544. seq_printf(s, " len = %d\n", len);
  545. wil_seq_hexdump(s, p, len, " : ");
  546. if (nr_frags) {
  547. seq_printf(s, " nr_frags = %d\n", nr_frags);
  548. for (i = 0; i < nr_frags; i++) {
  549. const struct skb_frag_struct *frag =
  550. &skb_shinfo(skb)->frags[i];
  551. len = skb_frag_size(frag);
  552. p = skb_frag_address_safe(frag);
  553. seq_printf(s, " [%2d] : len = %d\n", i, len);
  554. wil_seq_hexdump(s, p, len, " : ");
  555. }
  556. }
  557. }
  558. /*---------Tx/Rx descriptor------------*/
  559. static int wil_txdesc_debugfs_show(struct seq_file *s, void *data)
  560. {
  561. struct wil6210_priv *wil = s->private;
  562. struct vring *vring;
  563. bool tx = (dbg_vring_index < WIL6210_MAX_TX_RINGS);
  564. vring = tx ? &wil->vring_tx[dbg_vring_index] : &wil->vring_rx;
  565. if (!vring->va) {
  566. if (tx)
  567. seq_printf(s, "No Tx[%2d] VRING\n", dbg_vring_index);
  568. else
  569. seq_puts(s, "No Rx VRING\n");
  570. return 0;
  571. }
  572. if (dbg_txdesc_index < vring->size) {
  573. /* use struct vring_tx_desc for Rx as well,
  574. * only field used, .dma.length, is the same
  575. */
  576. volatile struct vring_tx_desc *d =
  577. &vring->va[dbg_txdesc_index].tx;
  578. volatile u32 *u = (volatile u32 *)d;
  579. struct sk_buff *skb = vring->ctx[dbg_txdesc_index].skb;
  580. if (tx)
  581. seq_printf(s, "Tx[%2d][%3d] = {\n", dbg_vring_index,
  582. dbg_txdesc_index);
  583. else
  584. seq_printf(s, "Rx[%3d] = {\n", dbg_txdesc_index);
  585. seq_printf(s, " MAC = 0x%08x 0x%08x 0x%08x 0x%08x\n",
  586. u[0], u[1], u[2], u[3]);
  587. seq_printf(s, " DMA = 0x%08x 0x%08x 0x%08x 0x%08x\n",
  588. u[4], u[5], u[6], u[7]);
  589. seq_printf(s, " SKB = 0x%p\n", skb);
  590. if (skb) {
  591. skb_get(skb);
  592. wil_seq_print_skb(s, skb);
  593. kfree_skb(skb);
  594. }
  595. seq_puts(s, "}\n");
  596. } else {
  597. if (tx)
  598. seq_printf(s, "[%2d] TxDesc index (%d) >= size (%d)\n",
  599. dbg_vring_index, dbg_txdesc_index,
  600. vring->size);
  601. else
  602. seq_printf(s, "RxDesc index (%d) >= size (%d)\n",
  603. dbg_txdesc_index, vring->size);
  604. }
  605. return 0;
  606. }
  607. static int wil_txdesc_seq_open(struct inode *inode, struct file *file)
  608. {
  609. return single_open(file, wil_txdesc_debugfs_show, inode->i_private);
  610. }
  611. static const struct file_operations fops_txdesc = {
  612. .open = wil_txdesc_seq_open,
  613. .release = single_release,
  614. .read = seq_read,
  615. .llseek = seq_lseek,
  616. };
  617. /*---------beamforming------------*/
  618. static char *wil_bfstatus_str(u32 status)
  619. {
  620. switch (status) {
  621. case 0:
  622. return "Failed";
  623. case 1:
  624. return "OK";
  625. case 2:
  626. return "Retrying";
  627. default:
  628. return "??";
  629. }
  630. }
  631. static bool is_all_zeros(void * const x_, size_t sz)
  632. {
  633. /* if reply is all-0, ignore this CID */
  634. u32 *x = x_;
  635. int n;
  636. for (n = 0; n < sz / sizeof(*x); n++)
  637. if (x[n])
  638. return false;
  639. return true;
  640. }
  641. static int wil_bf_debugfs_show(struct seq_file *s, void *data)
  642. {
  643. int rc;
  644. int i;
  645. struct wil6210_priv *wil = s->private;
  646. struct wmi_notify_req_cmd cmd = {
  647. .interval_usec = 0,
  648. };
  649. struct {
  650. struct wil6210_mbox_hdr_wmi wmi;
  651. struct wmi_notify_req_done_event evt;
  652. } __packed reply;
  653. for (i = 0; i < ARRAY_SIZE(wil->sta); i++) {
  654. u32 status;
  655. cmd.cid = i;
  656. rc = wmi_call(wil, WMI_NOTIFY_REQ_CMDID, &cmd, sizeof(cmd),
  657. WMI_NOTIFY_REQ_DONE_EVENTID, &reply,
  658. sizeof(reply), 20);
  659. /* if reply is all-0, ignore this CID */
  660. if (rc || is_all_zeros(&reply.evt, sizeof(reply.evt)))
  661. continue;
  662. status = le32_to_cpu(reply.evt.status);
  663. seq_printf(s, "CID %d {\n"
  664. " TSF = 0x%016llx\n"
  665. " TxMCS = %2d TxTpt = %4d\n"
  666. " SQI = %4d\n"
  667. " Status = 0x%08x %s\n"
  668. " Sectors(rx:tx) my %2d:%2d peer %2d:%2d\n"
  669. " Goodput(rx:tx) %4d:%4d\n"
  670. "}\n",
  671. i,
  672. le64_to_cpu(reply.evt.tsf),
  673. le16_to_cpu(reply.evt.bf_mcs),
  674. le32_to_cpu(reply.evt.tx_tpt),
  675. reply.evt.sqi,
  676. status, wil_bfstatus_str(status),
  677. le16_to_cpu(reply.evt.my_rx_sector),
  678. le16_to_cpu(reply.evt.my_tx_sector),
  679. le16_to_cpu(reply.evt.other_rx_sector),
  680. le16_to_cpu(reply.evt.other_tx_sector),
  681. le32_to_cpu(reply.evt.rx_goodput),
  682. le32_to_cpu(reply.evt.tx_goodput));
  683. }
  684. return 0;
  685. }
  686. static int wil_bf_seq_open(struct inode *inode, struct file *file)
  687. {
  688. return single_open(file, wil_bf_debugfs_show, inode->i_private);
  689. }
  690. static const struct file_operations fops_bf = {
  691. .open = wil_bf_seq_open,
  692. .release = single_release,
  693. .read = seq_read,
  694. .llseek = seq_lseek,
  695. };
  696. /*---------SSID------------*/
  697. static ssize_t wil_read_file_ssid(struct file *file, char __user *user_buf,
  698. size_t count, loff_t *ppos)
  699. {
  700. struct wil6210_priv *wil = file->private_data;
  701. struct wireless_dev *wdev = wil_to_wdev(wil);
  702. return simple_read_from_buffer(user_buf, count, ppos,
  703. wdev->ssid, wdev->ssid_len);
  704. }
  705. static ssize_t wil_write_file_ssid(struct file *file, const char __user *buf,
  706. size_t count, loff_t *ppos)
  707. {
  708. struct wil6210_priv *wil = file->private_data;
  709. struct wireless_dev *wdev = wil_to_wdev(wil);
  710. struct net_device *ndev = wil_to_ndev(wil);
  711. if (*ppos != 0) {
  712. wil_err(wil, "Unable to set SSID substring from [%d]\n",
  713. (int)*ppos);
  714. return -EINVAL;
  715. }
  716. if (count > sizeof(wdev->ssid)) {
  717. wil_err(wil, "SSID too long, len = %d\n", (int)count);
  718. return -EINVAL;
  719. }
  720. if (netif_running(ndev)) {
  721. wil_err(wil, "Unable to change SSID on running interface\n");
  722. return -EINVAL;
  723. }
  724. wdev->ssid_len = count;
  725. return simple_write_to_buffer(wdev->ssid, wdev->ssid_len, ppos,
  726. buf, count);
  727. }
  728. static const struct file_operations fops_ssid = {
  729. .read = wil_read_file_ssid,
  730. .write = wil_write_file_ssid,
  731. .open = simple_open,
  732. };
  733. /*---------temp------------*/
  734. static void print_temp(struct seq_file *s, const char *prefix, u32 t)
  735. {
  736. switch (t) {
  737. case 0:
  738. case ~(u32)0:
  739. seq_printf(s, "%s N/A\n", prefix);
  740. break;
  741. default:
  742. seq_printf(s, "%s %d.%03d\n", prefix, t / 1000, t % 1000);
  743. break;
  744. }
  745. }
  746. static int wil_temp_debugfs_show(struct seq_file *s, void *data)
  747. {
  748. struct wil6210_priv *wil = s->private;
  749. u32 t_m, t_r;
  750. int rc = wmi_get_temperature(wil, &t_m, &t_r);
  751. if (rc) {
  752. seq_puts(s, "Failed\n");
  753. return 0;
  754. }
  755. print_temp(s, "T_mac =", t_m);
  756. print_temp(s, "T_radio =", t_r);
  757. return 0;
  758. }
  759. static int wil_temp_seq_open(struct inode *inode, struct file *file)
  760. {
  761. return single_open(file, wil_temp_debugfs_show, inode->i_private);
  762. }
  763. static const struct file_operations fops_temp = {
  764. .open = wil_temp_seq_open,
  765. .release = single_release,
  766. .read = seq_read,
  767. .llseek = seq_lseek,
  768. };
  769. /*---------freq------------*/
  770. static int wil_freq_debugfs_show(struct seq_file *s, void *data)
  771. {
  772. struct wil6210_priv *wil = s->private;
  773. struct wireless_dev *wdev = wil_to_wdev(wil);
  774. u16 freq = wdev->chandef.chan ? wdev->chandef.chan->center_freq : 0;
  775. seq_printf(s, "Freq = %d\n", freq);
  776. return 0;
  777. }
  778. static int wil_freq_seq_open(struct inode *inode, struct file *file)
  779. {
  780. return single_open(file, wil_freq_debugfs_show, inode->i_private);
  781. }
  782. static const struct file_operations fops_freq = {
  783. .open = wil_freq_seq_open,
  784. .release = single_release,
  785. .read = seq_read,
  786. .llseek = seq_lseek,
  787. };
  788. /*---------link------------*/
  789. static int wil_link_debugfs_show(struct seq_file *s, void *data)
  790. {
  791. struct wil6210_priv *wil = s->private;
  792. struct station_info sinfo;
  793. int i, rc;
  794. for (i = 0; i < ARRAY_SIZE(wil->sta); i++) {
  795. struct wil_sta_info *p = &wil->sta[i];
  796. char *status = "unknown";
  797. switch (p->status) {
  798. case wil_sta_unused:
  799. status = "unused ";
  800. break;
  801. case wil_sta_conn_pending:
  802. status = "pending ";
  803. break;
  804. case wil_sta_connected:
  805. status = "connected";
  806. break;
  807. }
  808. seq_printf(s, "[%d] %pM %s%s\n", i, p->addr, status,
  809. (p->data_port_open ? " data_port_open" : ""));
  810. if (p->status == wil_sta_connected) {
  811. rc = wil_cid_fill_sinfo(wil, i, &sinfo);
  812. if (rc)
  813. return rc;
  814. seq_printf(s, " Tx_mcs = %d\n", sinfo.txrate.mcs);
  815. seq_printf(s, " Rx_mcs = %d\n", sinfo.rxrate.mcs);
  816. seq_printf(s, " SQ = %d\n", sinfo.signal);
  817. }
  818. }
  819. return 0;
  820. }
  821. static int wil_link_seq_open(struct inode *inode, struct file *file)
  822. {
  823. return single_open(file, wil_link_debugfs_show, inode->i_private);
  824. }
  825. static const struct file_operations fops_link = {
  826. .open = wil_link_seq_open,
  827. .release = single_release,
  828. .read = seq_read,
  829. .llseek = seq_lseek,
  830. };
  831. /*---------info------------*/
  832. static int wil_info_debugfs_show(struct seq_file *s, void *data)
  833. {
  834. struct wil6210_priv *wil = s->private;
  835. struct net_device *ndev = wil_to_ndev(wil);
  836. int is_ac = power_supply_is_system_supplied();
  837. int rx = atomic_xchg(&wil->isr_count_rx, 0);
  838. int tx = atomic_xchg(&wil->isr_count_tx, 0);
  839. static ulong rxf_old, txf_old;
  840. ulong rxf = ndev->stats.rx_packets;
  841. ulong txf = ndev->stats.tx_packets;
  842. unsigned int i;
  843. /* >0 : AC; 0 : battery; <0 : error */
  844. seq_printf(s, "AC powered : %d\n", is_ac);
  845. seq_printf(s, "Rx irqs:packets : %8d : %8ld\n", rx, rxf - rxf_old);
  846. seq_printf(s, "Tx irqs:packets : %8d : %8ld\n", tx, txf - txf_old);
  847. rxf_old = rxf;
  848. txf_old = txf;
  849. #define CHECK_QSTATE(x) (state & BIT(__QUEUE_STATE_ ## x)) ? \
  850. " " __stringify(x) : ""
  851. for (i = 0; i < ndev->num_tx_queues; i++) {
  852. struct netdev_queue *txq = netdev_get_tx_queue(ndev, i);
  853. unsigned long state = txq->state;
  854. seq_printf(s, "Tx queue[%i] state : 0x%lx%s%s%s\n", i, state,
  855. CHECK_QSTATE(DRV_XOFF),
  856. CHECK_QSTATE(STACK_XOFF),
  857. CHECK_QSTATE(FROZEN)
  858. );
  859. }
  860. #undef CHECK_QSTATE
  861. return 0;
  862. }
  863. static int wil_info_seq_open(struct inode *inode, struct file *file)
  864. {
  865. return single_open(file, wil_info_debugfs_show, inode->i_private);
  866. }
  867. static const struct file_operations fops_info = {
  868. .open = wil_info_seq_open,
  869. .release = single_release,
  870. .read = seq_read,
  871. .llseek = seq_lseek,
  872. };
  873. /*---------recovery------------*/
  874. /* mode = [manual|auto]
  875. * state = [idle|pending|running]
  876. */
  877. static ssize_t wil_read_file_recovery(struct file *file, char __user *user_buf,
  878. size_t count, loff_t *ppos)
  879. {
  880. struct wil6210_priv *wil = file->private_data;
  881. char buf[80];
  882. int n;
  883. static const char * const sstate[] = {"idle", "pending", "running"};
  884. n = snprintf(buf, sizeof(buf), "mode = %s\nstate = %s\n",
  885. no_fw_recovery ? "manual" : "auto",
  886. sstate[wil->recovery_state]);
  887. n = min_t(int, n, sizeof(buf));
  888. return simple_read_from_buffer(user_buf, count, ppos,
  889. buf, n);
  890. }
  891. static ssize_t wil_write_file_recovery(struct file *file,
  892. const char __user *buf_,
  893. size_t count, loff_t *ppos)
  894. {
  895. struct wil6210_priv *wil = file->private_data;
  896. static const char run_command[] = "run";
  897. char buf[sizeof(run_command) + 1]; /* to detect "runx" */
  898. ssize_t rc;
  899. if (wil->recovery_state != fw_recovery_pending) {
  900. wil_err(wil, "No recovery pending\n");
  901. return -EINVAL;
  902. }
  903. if (*ppos != 0) {
  904. wil_err(wil, "Offset [%d]\n", (int)*ppos);
  905. return -EINVAL;
  906. }
  907. if (count > sizeof(buf)) {
  908. wil_err(wil, "Input too long, len = %d\n", (int)count);
  909. return -EINVAL;
  910. }
  911. rc = simple_write_to_buffer(buf, sizeof(buf) - 1, ppos, buf_, count);
  912. if (rc < 0)
  913. return rc;
  914. buf[rc] = '\0';
  915. if (0 == strcmp(buf, run_command))
  916. wil_set_recovery_state(wil, fw_recovery_running);
  917. else
  918. wil_err(wil, "Bad recovery command \"%s\"\n", buf);
  919. return rc;
  920. }
  921. static const struct file_operations fops_recovery = {
  922. .read = wil_read_file_recovery,
  923. .write = wil_write_file_recovery,
  924. .open = simple_open,
  925. };
  926. /*---------Station matrix------------*/
  927. static void wil_print_rxtid(struct seq_file *s, struct wil_tid_ampdu_rx *r)
  928. {
  929. int i;
  930. u16 index = ((r->head_seq_num - r->ssn) & 0xfff) % r->buf_size;
  931. seq_printf(s, "0x%03x [", r->head_seq_num);
  932. for (i = 0; i < r->buf_size; i++) {
  933. if (i == index)
  934. seq_printf(s, "%c", r->reorder_buf[i] ? 'O' : '|');
  935. else
  936. seq_printf(s, "%c", r->reorder_buf[i] ? '*' : '_');
  937. }
  938. seq_printf(s, "] last drop 0x%03x\n", r->ssn_last_drop);
  939. }
  940. static int wil_sta_debugfs_show(struct seq_file *s, void *data)
  941. {
  942. struct wil6210_priv *wil = s->private;
  943. int i, tid;
  944. unsigned long flags;
  945. for (i = 0; i < ARRAY_SIZE(wil->sta); i++) {
  946. struct wil_sta_info *p = &wil->sta[i];
  947. char *status = "unknown";
  948. switch (p->status) {
  949. case wil_sta_unused:
  950. status = "unused ";
  951. break;
  952. case wil_sta_conn_pending:
  953. status = "pending ";
  954. break;
  955. case wil_sta_connected:
  956. status = "connected";
  957. break;
  958. }
  959. seq_printf(s, "[%d] %pM %s%s\n", i, p->addr, status,
  960. (p->data_port_open ? " data_port_open" : ""));
  961. if (p->status == wil_sta_connected) {
  962. spin_lock_irqsave(&p->tid_rx_lock, flags);
  963. for (tid = 0; tid < WIL_STA_TID_NUM; tid++) {
  964. struct wil_tid_ampdu_rx *r = p->tid_rx[tid];
  965. if (r) {
  966. seq_printf(s, "[%2d] ", tid);
  967. wil_print_rxtid(s, r);
  968. }
  969. }
  970. spin_unlock_irqrestore(&p->tid_rx_lock, flags);
  971. }
  972. }
  973. return 0;
  974. }
  975. static int wil_sta_seq_open(struct inode *inode, struct file *file)
  976. {
  977. return single_open(file, wil_sta_debugfs_show, inode->i_private);
  978. }
  979. static const struct file_operations fops_sta = {
  980. .open = wil_sta_seq_open,
  981. .release = single_release,
  982. .read = seq_read,
  983. .llseek = seq_lseek,
  984. };
  985. /*----------------*/
  986. static void wil6210_debugfs_init_blobs(struct wil6210_priv *wil,
  987. struct dentry *dbg)
  988. {
  989. int i;
  990. char name[32];
  991. for (i = 0; i < ARRAY_SIZE(fw_mapping); i++) {
  992. struct debugfs_blob_wrapper *blob = &wil->blobs[i];
  993. const struct fw_map *map = &fw_mapping[i];
  994. if (!map->name)
  995. continue;
  996. blob->data = (void * __force)wil->csr + HOSTADDR(map->host);
  997. blob->size = map->to - map->from;
  998. snprintf(name, sizeof(name), "blob_%s", map->name);
  999. wil_debugfs_create_ioblob(name, S_IRUGO, dbg, blob);
  1000. }
  1001. }
  1002. /* misc files */
  1003. static const struct {
  1004. const char *name;
  1005. umode_t mode;
  1006. const struct file_operations *fops;
  1007. } dbg_files[] = {
  1008. {"mbox", S_IRUGO, &fops_mbox},
  1009. {"vrings", S_IRUGO, &fops_vring},
  1010. {"stations", S_IRUGO, &fops_sta},
  1011. {"desc", S_IRUGO, &fops_txdesc},
  1012. {"bf", S_IRUGO, &fops_bf},
  1013. {"ssid", S_IRUGO | S_IWUSR, &fops_ssid},
  1014. {"mem_val", S_IRUGO, &fops_memread},
  1015. {"reset", S_IWUSR, &fops_reset},
  1016. {"rxon", S_IWUSR, &fops_rxon},
  1017. {"tx_mgmt", S_IWUSR, &fops_txmgmt},
  1018. {"wmi_send", S_IWUSR, &fops_wmi},
  1019. {"temp", S_IRUGO, &fops_temp},
  1020. {"freq", S_IRUGO, &fops_freq},
  1021. {"link", S_IRUGO, &fops_link},
  1022. {"info", S_IRUGO, &fops_info},
  1023. {"recovery", S_IRUGO | S_IWUSR, &fops_recovery},
  1024. };
  1025. static void wil6210_debugfs_init_files(struct wil6210_priv *wil,
  1026. struct dentry *dbg)
  1027. {
  1028. int i;
  1029. for (i = 0; i < ARRAY_SIZE(dbg_files); i++)
  1030. debugfs_create_file(dbg_files[i].name, dbg_files[i].mode, dbg,
  1031. wil, dbg_files[i].fops);
  1032. }
  1033. /* interrupt control blocks */
  1034. static const struct {
  1035. const char *name;
  1036. u32 icr_off;
  1037. } dbg_icr[] = {
  1038. {"USER_ICR", HOSTADDR(RGF_USER_USER_ICR)},
  1039. {"DMA_EP_TX_ICR", HOSTADDR(RGF_DMA_EP_TX_ICR)},
  1040. {"DMA_EP_RX_ICR", HOSTADDR(RGF_DMA_EP_RX_ICR)},
  1041. {"DMA_EP_MISC_ICR", HOSTADDR(RGF_DMA_EP_MISC_ICR)},
  1042. };
  1043. static void wil6210_debugfs_init_isr(struct wil6210_priv *wil,
  1044. struct dentry *dbg)
  1045. {
  1046. int i;
  1047. for (i = 0; i < ARRAY_SIZE(dbg_icr); i++)
  1048. wil6210_debugfs_create_ISR(wil, dbg_icr[i].name, dbg,
  1049. dbg_icr[i].icr_off);
  1050. }
  1051. #define WIL_FIELD(name, mode, type) { __stringify(name), mode, \
  1052. offsetof(struct wil6210_priv, name), type}
  1053. /* fields in struct wil6210_priv */
  1054. static const struct dbg_off dbg_wil_off[] = {
  1055. WIL_FIELD(secure_pcp, S_IRUGO | S_IWUSR, doff_u32),
  1056. WIL_FIELD(status, S_IRUGO | S_IWUSR, doff_ulong),
  1057. WIL_FIELD(fw_version, S_IRUGO, doff_u32),
  1058. WIL_FIELD(hw_version, S_IRUGO, doff_x32),
  1059. WIL_FIELD(recovery_count, S_IRUGO, doff_u32),
  1060. {},
  1061. };
  1062. static const struct dbg_off dbg_wil_regs[] = {
  1063. {"RGF_MAC_MTRL_COUNTER_0", S_IRUGO, HOSTADDR(RGF_MAC_MTRL_COUNTER_0),
  1064. doff_io32},
  1065. {"RGF_USER_USAGE_1", S_IRUGO, HOSTADDR(RGF_USER_USAGE_1), doff_io32},
  1066. {},
  1067. };
  1068. /* static parameters */
  1069. static const struct dbg_off dbg_statics[] = {
  1070. {"desc_index", S_IRUGO | S_IWUSR, (ulong)&dbg_txdesc_index, doff_u32},
  1071. {"vring_index", S_IRUGO | S_IWUSR, (ulong)&dbg_vring_index, doff_u32},
  1072. {"mem_addr", S_IRUGO | S_IWUSR, (ulong)&mem_addr, doff_u32},
  1073. {},
  1074. };
  1075. int wil6210_debugfs_init(struct wil6210_priv *wil)
  1076. {
  1077. struct dentry *dbg = wil->debug = debugfs_create_dir(WIL_NAME,
  1078. wil_to_wiphy(wil)->debugfsdir);
  1079. if (IS_ERR_OR_NULL(dbg))
  1080. return -ENODEV;
  1081. wil6210_debugfs_init_files(wil, dbg);
  1082. wil6210_debugfs_init_isr(wil, dbg);
  1083. wil6210_debugfs_init_blobs(wil, dbg);
  1084. wil6210_debugfs_init_offset(wil, dbg, wil, dbg_wil_off);
  1085. wil6210_debugfs_init_offset(wil, dbg, (void * __force)wil->csr,
  1086. dbg_wil_regs);
  1087. wil6210_debugfs_init_offset(wil, dbg, NULL, dbg_statics);
  1088. wil6210_debugfs_create_pseudo_ISR(wil, dbg);
  1089. wil6210_debugfs_create_ITR_CNT(wil, dbg);
  1090. return 0;
  1091. }
  1092. void wil6210_debugfs_remove(struct wil6210_priv *wil)
  1093. {
  1094. debugfs_remove_recursive(wil->debug);
  1095. wil->debug = NULL;
  1096. }