debugfs.c 37 KB

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