debugfs.c 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313
  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. kfree(frame);
  482. return -EIO;
  483. }
  484. params.buf = frame;
  485. params.len = len;
  486. params.chan = wdev->preset_chandef.chan;
  487. rc = wil_cfg80211_mgmt_tx(wiphy, wdev, &params, NULL);
  488. kfree(frame);
  489. wil_info(wil, "%s() -> %d\n", __func__, rc);
  490. return len;
  491. }
  492. static const struct file_operations fops_txmgmt = {
  493. .write = wil_write_file_txmgmt,
  494. .open = simple_open,
  495. };
  496. /* Write WMI command (w/o mbox header) to this file to send it
  497. * WMI starts from wil6210_mbox_hdr_wmi header
  498. */
  499. static ssize_t wil_write_file_wmi(struct file *file, const char __user *buf,
  500. size_t len, loff_t *ppos)
  501. {
  502. struct wil6210_priv *wil = file->private_data;
  503. struct wil6210_mbox_hdr_wmi *wmi;
  504. void *cmd;
  505. int cmdlen = len - sizeof(struct wil6210_mbox_hdr_wmi);
  506. u16 cmdid;
  507. int rc, rc1;
  508. if (cmdlen <= 0)
  509. return -EINVAL;
  510. wmi = kmalloc(len, GFP_KERNEL);
  511. if (!wmi)
  512. return -ENOMEM;
  513. rc = simple_write_to_buffer(wmi, len, ppos, buf, len);
  514. if (rc < 0) {
  515. kfree(wmi);
  516. return rc;
  517. }
  518. cmd = &wmi[1];
  519. cmdid = le16_to_cpu(wmi->id);
  520. rc1 = wmi_send(wil, cmdid, cmd, cmdlen);
  521. kfree(wmi);
  522. wil_info(wil, "%s(0x%04x[%d]) -> %d\n", __func__, cmdid, cmdlen, rc1);
  523. return rc;
  524. }
  525. static const struct file_operations fops_wmi = {
  526. .write = wil_write_file_wmi,
  527. .open = simple_open,
  528. };
  529. static void wil_seq_hexdump(struct seq_file *s, void *p, int len,
  530. const char *prefix)
  531. {
  532. char printbuf[16 * 3 + 2];
  533. int i = 0;
  534. while (i < len) {
  535. int l = min(len - i, 16);
  536. hex_dump_to_buffer(p + i, l, 16, 1, printbuf,
  537. sizeof(printbuf), false);
  538. seq_printf(s, "%s%s\n", prefix, printbuf);
  539. i += l;
  540. }
  541. }
  542. static void wil_seq_print_skb(struct seq_file *s, struct sk_buff *skb)
  543. {
  544. int i = 0;
  545. int len = skb_headlen(skb);
  546. void *p = skb->data;
  547. int nr_frags = skb_shinfo(skb)->nr_frags;
  548. seq_printf(s, " len = %d\n", len);
  549. wil_seq_hexdump(s, p, len, " : ");
  550. if (nr_frags) {
  551. seq_printf(s, " nr_frags = %d\n", nr_frags);
  552. for (i = 0; i < nr_frags; i++) {
  553. const struct skb_frag_struct *frag =
  554. &skb_shinfo(skb)->frags[i];
  555. len = skb_frag_size(frag);
  556. p = skb_frag_address_safe(frag);
  557. seq_printf(s, " [%2d] : len = %d\n", i, len);
  558. wil_seq_hexdump(s, p, len, " : ");
  559. }
  560. }
  561. }
  562. /*---------Tx/Rx descriptor------------*/
  563. static int wil_txdesc_debugfs_show(struct seq_file *s, void *data)
  564. {
  565. struct wil6210_priv *wil = s->private;
  566. struct vring *vring;
  567. bool tx = (dbg_vring_index < WIL6210_MAX_TX_RINGS);
  568. vring = tx ? &wil->vring_tx[dbg_vring_index] : &wil->vring_rx;
  569. if (!vring->va) {
  570. if (tx)
  571. seq_printf(s, "No Tx[%2d] VRING\n", dbg_vring_index);
  572. else
  573. seq_puts(s, "No Rx VRING\n");
  574. return 0;
  575. }
  576. if (dbg_txdesc_index < vring->size) {
  577. /* use struct vring_tx_desc for Rx as well,
  578. * only field used, .dma.length, is the same
  579. */
  580. volatile struct vring_tx_desc *d =
  581. &vring->va[dbg_txdesc_index].tx;
  582. volatile u32 *u = (volatile u32 *)d;
  583. struct sk_buff *skb = vring->ctx[dbg_txdesc_index].skb;
  584. if (tx)
  585. seq_printf(s, "Tx[%2d][%3d] = {\n", dbg_vring_index,
  586. dbg_txdesc_index);
  587. else
  588. seq_printf(s, "Rx[%3d] = {\n", dbg_txdesc_index);
  589. seq_printf(s, " MAC = 0x%08x 0x%08x 0x%08x 0x%08x\n",
  590. u[0], u[1], u[2], u[3]);
  591. seq_printf(s, " DMA = 0x%08x 0x%08x 0x%08x 0x%08x\n",
  592. u[4], u[5], u[6], u[7]);
  593. seq_printf(s, " SKB = 0x%p\n", skb);
  594. if (skb) {
  595. skb_get(skb);
  596. wil_seq_print_skb(s, skb);
  597. kfree_skb(skb);
  598. }
  599. seq_puts(s, "}\n");
  600. } else {
  601. if (tx)
  602. seq_printf(s, "[%2d] TxDesc index (%d) >= size (%d)\n",
  603. dbg_vring_index, dbg_txdesc_index,
  604. vring->size);
  605. else
  606. seq_printf(s, "RxDesc index (%d) >= size (%d)\n",
  607. dbg_txdesc_index, vring->size);
  608. }
  609. return 0;
  610. }
  611. static int wil_txdesc_seq_open(struct inode *inode, struct file *file)
  612. {
  613. return single_open(file, wil_txdesc_debugfs_show, inode->i_private);
  614. }
  615. static const struct file_operations fops_txdesc = {
  616. .open = wil_txdesc_seq_open,
  617. .release = single_release,
  618. .read = seq_read,
  619. .llseek = seq_lseek,
  620. };
  621. /*---------beamforming------------*/
  622. static char *wil_bfstatus_str(u32 status)
  623. {
  624. switch (status) {
  625. case 0:
  626. return "Failed";
  627. case 1:
  628. return "OK";
  629. case 2:
  630. return "Retrying";
  631. default:
  632. return "??";
  633. }
  634. }
  635. static bool is_all_zeros(void * const x_, size_t sz)
  636. {
  637. /* if reply is all-0, ignore this CID */
  638. u32 *x = x_;
  639. int n;
  640. for (n = 0; n < sz / sizeof(*x); n++)
  641. if (x[n])
  642. return false;
  643. return true;
  644. }
  645. static int wil_bf_debugfs_show(struct seq_file *s, void *data)
  646. {
  647. int rc;
  648. int i;
  649. struct wil6210_priv *wil = s->private;
  650. struct wmi_notify_req_cmd cmd = {
  651. .interval_usec = 0,
  652. };
  653. struct {
  654. struct wil6210_mbox_hdr_wmi wmi;
  655. struct wmi_notify_req_done_event evt;
  656. } __packed reply;
  657. for (i = 0; i < ARRAY_SIZE(wil->sta); i++) {
  658. u32 status;
  659. cmd.cid = i;
  660. rc = wmi_call(wil, WMI_NOTIFY_REQ_CMDID, &cmd, sizeof(cmd),
  661. WMI_NOTIFY_REQ_DONE_EVENTID, &reply,
  662. sizeof(reply), 20);
  663. /* if reply is all-0, ignore this CID */
  664. if (rc || is_all_zeros(&reply.evt, sizeof(reply.evt)))
  665. continue;
  666. status = le32_to_cpu(reply.evt.status);
  667. seq_printf(s, "CID %d {\n"
  668. " TSF = 0x%016llx\n"
  669. " TxMCS = %2d TxTpt = %4d\n"
  670. " SQI = %4d\n"
  671. " Status = 0x%08x %s\n"
  672. " Sectors(rx:tx) my %2d:%2d peer %2d:%2d\n"
  673. " Goodput(rx:tx) %4d:%4d\n"
  674. "}\n",
  675. i,
  676. le64_to_cpu(reply.evt.tsf),
  677. le16_to_cpu(reply.evt.bf_mcs),
  678. le32_to_cpu(reply.evt.tx_tpt),
  679. reply.evt.sqi,
  680. status, wil_bfstatus_str(status),
  681. le16_to_cpu(reply.evt.my_rx_sector),
  682. le16_to_cpu(reply.evt.my_tx_sector),
  683. le16_to_cpu(reply.evt.other_rx_sector),
  684. le16_to_cpu(reply.evt.other_tx_sector),
  685. le32_to_cpu(reply.evt.rx_goodput),
  686. le32_to_cpu(reply.evt.tx_goodput));
  687. }
  688. return 0;
  689. }
  690. static int wil_bf_seq_open(struct inode *inode, struct file *file)
  691. {
  692. return single_open(file, wil_bf_debugfs_show, inode->i_private);
  693. }
  694. static const struct file_operations fops_bf = {
  695. .open = wil_bf_seq_open,
  696. .release = single_release,
  697. .read = seq_read,
  698. .llseek = seq_lseek,
  699. };
  700. /*---------SSID------------*/
  701. static ssize_t wil_read_file_ssid(struct file *file, char __user *user_buf,
  702. size_t count, loff_t *ppos)
  703. {
  704. struct wil6210_priv *wil = file->private_data;
  705. struct wireless_dev *wdev = wil_to_wdev(wil);
  706. return simple_read_from_buffer(user_buf, count, ppos,
  707. wdev->ssid, wdev->ssid_len);
  708. }
  709. static ssize_t wil_write_file_ssid(struct file *file, const char __user *buf,
  710. size_t count, loff_t *ppos)
  711. {
  712. struct wil6210_priv *wil = file->private_data;
  713. struct wireless_dev *wdev = wil_to_wdev(wil);
  714. struct net_device *ndev = wil_to_ndev(wil);
  715. if (*ppos != 0) {
  716. wil_err(wil, "Unable to set SSID substring from [%d]\n",
  717. (int)*ppos);
  718. return -EINVAL;
  719. }
  720. if (count > sizeof(wdev->ssid)) {
  721. wil_err(wil, "SSID too long, len = %d\n", (int)count);
  722. return -EINVAL;
  723. }
  724. if (netif_running(ndev)) {
  725. wil_err(wil, "Unable to change SSID on running interface\n");
  726. return -EINVAL;
  727. }
  728. wdev->ssid_len = count;
  729. return simple_write_to_buffer(wdev->ssid, wdev->ssid_len, ppos,
  730. buf, count);
  731. }
  732. static const struct file_operations fops_ssid = {
  733. .read = wil_read_file_ssid,
  734. .write = wil_write_file_ssid,
  735. .open = simple_open,
  736. };
  737. /*---------temp------------*/
  738. static void print_temp(struct seq_file *s, const char *prefix, u32 t)
  739. {
  740. switch (t) {
  741. case 0:
  742. case ~(u32)0:
  743. seq_printf(s, "%s N/A\n", prefix);
  744. break;
  745. default:
  746. seq_printf(s, "%s %d.%03d\n", prefix, t / 1000, t % 1000);
  747. break;
  748. }
  749. }
  750. static int wil_temp_debugfs_show(struct seq_file *s, void *data)
  751. {
  752. struct wil6210_priv *wil = s->private;
  753. u32 t_m, t_r;
  754. int rc = wmi_get_temperature(wil, &t_m, &t_r);
  755. if (rc) {
  756. seq_puts(s, "Failed\n");
  757. return 0;
  758. }
  759. print_temp(s, "T_mac =", t_m);
  760. print_temp(s, "T_radio =", t_r);
  761. return 0;
  762. }
  763. static int wil_temp_seq_open(struct inode *inode, struct file *file)
  764. {
  765. return single_open(file, wil_temp_debugfs_show, inode->i_private);
  766. }
  767. static const struct file_operations fops_temp = {
  768. .open = wil_temp_seq_open,
  769. .release = single_release,
  770. .read = seq_read,
  771. .llseek = seq_lseek,
  772. };
  773. /*---------freq------------*/
  774. static int wil_freq_debugfs_show(struct seq_file *s, void *data)
  775. {
  776. struct wil6210_priv *wil = s->private;
  777. struct wireless_dev *wdev = wil_to_wdev(wil);
  778. u16 freq = wdev->chandef.chan ? wdev->chandef.chan->center_freq : 0;
  779. seq_printf(s, "Freq = %d\n", freq);
  780. return 0;
  781. }
  782. static int wil_freq_seq_open(struct inode *inode, struct file *file)
  783. {
  784. return single_open(file, wil_freq_debugfs_show, inode->i_private);
  785. }
  786. static const struct file_operations fops_freq = {
  787. .open = wil_freq_seq_open,
  788. .release = single_release,
  789. .read = seq_read,
  790. .llseek = seq_lseek,
  791. };
  792. /*---------link------------*/
  793. static int wil_link_debugfs_show(struct seq_file *s, void *data)
  794. {
  795. struct wil6210_priv *wil = s->private;
  796. struct station_info sinfo;
  797. int i, rc;
  798. for (i = 0; i < ARRAY_SIZE(wil->sta); i++) {
  799. struct wil_sta_info *p = &wil->sta[i];
  800. char *status = "unknown";
  801. switch (p->status) {
  802. case wil_sta_unused:
  803. status = "unused ";
  804. break;
  805. case wil_sta_conn_pending:
  806. status = "pending ";
  807. break;
  808. case wil_sta_connected:
  809. status = "connected";
  810. break;
  811. }
  812. seq_printf(s, "[%d] %pM %s%s\n", i, p->addr, status,
  813. (p->data_port_open ? " data_port_open" : ""));
  814. if (p->status == wil_sta_connected) {
  815. rc = wil_cid_fill_sinfo(wil, i, &sinfo);
  816. if (rc)
  817. return rc;
  818. seq_printf(s, " Tx_mcs = %d\n", sinfo.txrate.mcs);
  819. seq_printf(s, " Rx_mcs = %d\n", sinfo.rxrate.mcs);
  820. seq_printf(s, " SQ = %d\n", sinfo.signal);
  821. }
  822. }
  823. return 0;
  824. }
  825. static int wil_link_seq_open(struct inode *inode, struct file *file)
  826. {
  827. return single_open(file, wil_link_debugfs_show, inode->i_private);
  828. }
  829. static const struct file_operations fops_link = {
  830. .open = wil_link_seq_open,
  831. .release = single_release,
  832. .read = seq_read,
  833. .llseek = seq_lseek,
  834. };
  835. /*---------info------------*/
  836. static int wil_info_debugfs_show(struct seq_file *s, void *data)
  837. {
  838. struct wil6210_priv *wil = s->private;
  839. struct net_device *ndev = wil_to_ndev(wil);
  840. int is_ac = power_supply_is_system_supplied();
  841. int rx = atomic_xchg(&wil->isr_count_rx, 0);
  842. int tx = atomic_xchg(&wil->isr_count_tx, 0);
  843. static ulong rxf_old, txf_old;
  844. ulong rxf = ndev->stats.rx_packets;
  845. ulong txf = ndev->stats.tx_packets;
  846. unsigned int i;
  847. /* >0 : AC; 0 : battery; <0 : error */
  848. seq_printf(s, "AC powered : %d\n", is_ac);
  849. seq_printf(s, "Rx irqs:packets : %8d : %8ld\n", rx, rxf - rxf_old);
  850. seq_printf(s, "Tx irqs:packets : %8d : %8ld\n", tx, txf - txf_old);
  851. rxf_old = rxf;
  852. txf_old = txf;
  853. #define CHECK_QSTATE(x) (state & BIT(__QUEUE_STATE_ ## x)) ? \
  854. " " __stringify(x) : ""
  855. for (i = 0; i < ndev->num_tx_queues; i++) {
  856. struct netdev_queue *txq = netdev_get_tx_queue(ndev, i);
  857. unsigned long state = txq->state;
  858. seq_printf(s, "Tx queue[%i] state : 0x%lx%s%s%s\n", i, state,
  859. CHECK_QSTATE(DRV_XOFF),
  860. CHECK_QSTATE(STACK_XOFF),
  861. CHECK_QSTATE(FROZEN)
  862. );
  863. }
  864. #undef CHECK_QSTATE
  865. return 0;
  866. }
  867. static int wil_info_seq_open(struct inode *inode, struct file *file)
  868. {
  869. return single_open(file, wil_info_debugfs_show, inode->i_private);
  870. }
  871. static const struct file_operations fops_info = {
  872. .open = wil_info_seq_open,
  873. .release = single_release,
  874. .read = seq_read,
  875. .llseek = seq_lseek,
  876. };
  877. /*---------recovery------------*/
  878. /* mode = [manual|auto]
  879. * state = [idle|pending|running]
  880. */
  881. static ssize_t wil_read_file_recovery(struct file *file, char __user *user_buf,
  882. size_t count, loff_t *ppos)
  883. {
  884. struct wil6210_priv *wil = file->private_data;
  885. char buf[80];
  886. int n;
  887. static const char * const sstate[] = {"idle", "pending", "running"};
  888. n = snprintf(buf, sizeof(buf), "mode = %s\nstate = %s\n",
  889. no_fw_recovery ? "manual" : "auto",
  890. sstate[wil->recovery_state]);
  891. n = min_t(int, n, sizeof(buf));
  892. return simple_read_from_buffer(user_buf, count, ppos,
  893. buf, n);
  894. }
  895. static ssize_t wil_write_file_recovery(struct file *file,
  896. const char __user *buf_,
  897. size_t count, loff_t *ppos)
  898. {
  899. struct wil6210_priv *wil = file->private_data;
  900. static const char run_command[] = "run";
  901. char buf[sizeof(run_command) + 1]; /* to detect "runx" */
  902. ssize_t rc;
  903. if (wil->recovery_state != fw_recovery_pending) {
  904. wil_err(wil, "No recovery pending\n");
  905. return -EINVAL;
  906. }
  907. if (*ppos != 0) {
  908. wil_err(wil, "Offset [%d]\n", (int)*ppos);
  909. return -EINVAL;
  910. }
  911. if (count > sizeof(buf)) {
  912. wil_err(wil, "Input too long, len = %d\n", (int)count);
  913. return -EINVAL;
  914. }
  915. rc = simple_write_to_buffer(buf, sizeof(buf) - 1, ppos, buf_, count);
  916. if (rc < 0)
  917. return rc;
  918. buf[rc] = '\0';
  919. if (0 == strcmp(buf, run_command))
  920. wil_set_recovery_state(wil, fw_recovery_running);
  921. else
  922. wil_err(wil, "Bad recovery command \"%s\"\n", buf);
  923. return rc;
  924. }
  925. static const struct file_operations fops_recovery = {
  926. .read = wil_read_file_recovery,
  927. .write = wil_write_file_recovery,
  928. .open = simple_open,
  929. };
  930. /*---------Station matrix------------*/
  931. static void wil_print_rxtid(struct seq_file *s, struct wil_tid_ampdu_rx *r)
  932. {
  933. int i;
  934. u16 index = ((r->head_seq_num - r->ssn) & 0xfff) % r->buf_size;
  935. seq_printf(s, "0x%03x [", r->head_seq_num);
  936. for (i = 0; i < r->buf_size; i++) {
  937. if (i == index)
  938. seq_printf(s, "%c", r->reorder_buf[i] ? 'O' : '|');
  939. else
  940. seq_printf(s, "%c", r->reorder_buf[i] ? '*' : '_');
  941. }
  942. seq_printf(s, "] last drop 0x%03x\n", r->ssn_last_drop);
  943. }
  944. static int wil_sta_debugfs_show(struct seq_file *s, void *data)
  945. {
  946. struct wil6210_priv *wil = s->private;
  947. int i, tid;
  948. unsigned long flags;
  949. for (i = 0; i < ARRAY_SIZE(wil->sta); i++) {
  950. struct wil_sta_info *p = &wil->sta[i];
  951. char *status = "unknown";
  952. switch (p->status) {
  953. case wil_sta_unused:
  954. status = "unused ";
  955. break;
  956. case wil_sta_conn_pending:
  957. status = "pending ";
  958. break;
  959. case wil_sta_connected:
  960. status = "connected";
  961. break;
  962. }
  963. seq_printf(s, "[%d] %pM %s%s\n", i, p->addr, status,
  964. (p->data_port_open ? " data_port_open" : ""));
  965. if (p->status == wil_sta_connected) {
  966. spin_lock_irqsave(&p->tid_rx_lock, flags);
  967. for (tid = 0; tid < WIL_STA_TID_NUM; tid++) {
  968. struct wil_tid_ampdu_rx *r = p->tid_rx[tid];
  969. if (r) {
  970. seq_printf(s, "[%2d] ", tid);
  971. wil_print_rxtid(s, r);
  972. }
  973. }
  974. spin_unlock_irqrestore(&p->tid_rx_lock, flags);
  975. }
  976. }
  977. return 0;
  978. }
  979. static int wil_sta_seq_open(struct inode *inode, struct file *file)
  980. {
  981. return single_open(file, wil_sta_debugfs_show, inode->i_private);
  982. }
  983. static const struct file_operations fops_sta = {
  984. .open = wil_sta_seq_open,
  985. .release = single_release,
  986. .read = seq_read,
  987. .llseek = seq_lseek,
  988. };
  989. /*----------------*/
  990. static void wil6210_debugfs_init_blobs(struct wil6210_priv *wil,
  991. struct dentry *dbg)
  992. {
  993. int i;
  994. char name[32];
  995. for (i = 0; i < ARRAY_SIZE(fw_mapping); i++) {
  996. struct debugfs_blob_wrapper *blob = &wil->blobs[i];
  997. const struct fw_map *map = &fw_mapping[i];
  998. if (!map->name)
  999. continue;
  1000. blob->data = (void * __force)wil->csr + HOSTADDR(map->host);
  1001. blob->size = map->to - map->from;
  1002. snprintf(name, sizeof(name), "blob_%s", map->name);
  1003. wil_debugfs_create_ioblob(name, S_IRUGO, dbg, blob);
  1004. }
  1005. }
  1006. /* misc files */
  1007. static const struct {
  1008. const char *name;
  1009. umode_t mode;
  1010. const struct file_operations *fops;
  1011. } dbg_files[] = {
  1012. {"mbox", S_IRUGO, &fops_mbox},
  1013. {"vrings", S_IRUGO, &fops_vring},
  1014. {"stations", S_IRUGO, &fops_sta},
  1015. {"desc", S_IRUGO, &fops_txdesc},
  1016. {"bf", S_IRUGO, &fops_bf},
  1017. {"ssid", S_IRUGO | S_IWUSR, &fops_ssid},
  1018. {"mem_val", S_IRUGO, &fops_memread},
  1019. {"reset", S_IWUSR, &fops_reset},
  1020. {"rxon", S_IWUSR, &fops_rxon},
  1021. {"tx_mgmt", S_IWUSR, &fops_txmgmt},
  1022. {"wmi_send", S_IWUSR, &fops_wmi},
  1023. {"temp", S_IRUGO, &fops_temp},
  1024. {"freq", S_IRUGO, &fops_freq},
  1025. {"link", S_IRUGO, &fops_link},
  1026. {"info", S_IRUGO, &fops_info},
  1027. {"recovery", S_IRUGO | S_IWUSR, &fops_recovery},
  1028. };
  1029. static void wil6210_debugfs_init_files(struct wil6210_priv *wil,
  1030. struct dentry *dbg)
  1031. {
  1032. int i;
  1033. for (i = 0; i < ARRAY_SIZE(dbg_files); i++)
  1034. debugfs_create_file(dbg_files[i].name, dbg_files[i].mode, dbg,
  1035. wil, dbg_files[i].fops);
  1036. }
  1037. /* interrupt control blocks */
  1038. static const struct {
  1039. const char *name;
  1040. u32 icr_off;
  1041. } dbg_icr[] = {
  1042. {"USER_ICR", HOSTADDR(RGF_USER_USER_ICR)},
  1043. {"DMA_EP_TX_ICR", HOSTADDR(RGF_DMA_EP_TX_ICR)},
  1044. {"DMA_EP_RX_ICR", HOSTADDR(RGF_DMA_EP_RX_ICR)},
  1045. {"DMA_EP_MISC_ICR", HOSTADDR(RGF_DMA_EP_MISC_ICR)},
  1046. };
  1047. static void wil6210_debugfs_init_isr(struct wil6210_priv *wil,
  1048. struct dentry *dbg)
  1049. {
  1050. int i;
  1051. for (i = 0; i < ARRAY_SIZE(dbg_icr); i++)
  1052. wil6210_debugfs_create_ISR(wil, dbg_icr[i].name, dbg,
  1053. dbg_icr[i].icr_off);
  1054. }
  1055. #define WIL_FIELD(name, mode, type) { __stringify(name), mode, \
  1056. offsetof(struct wil6210_priv, name), type}
  1057. /* fields in struct wil6210_priv */
  1058. static const struct dbg_off dbg_wil_off[] = {
  1059. WIL_FIELD(secure_pcp, S_IRUGO | S_IWUSR, doff_u32),
  1060. WIL_FIELD(status, S_IRUGO | S_IWUSR, doff_ulong),
  1061. WIL_FIELD(fw_version, S_IRUGO, doff_u32),
  1062. WIL_FIELD(hw_version, S_IRUGO, doff_x32),
  1063. WIL_FIELD(recovery_count, S_IRUGO, doff_u32),
  1064. {},
  1065. };
  1066. static const struct dbg_off dbg_wil_regs[] = {
  1067. {"RGF_MAC_MTRL_COUNTER_0", S_IRUGO, HOSTADDR(RGF_MAC_MTRL_COUNTER_0),
  1068. doff_io32},
  1069. {"RGF_USER_USAGE_1", S_IRUGO, HOSTADDR(RGF_USER_USAGE_1), doff_io32},
  1070. {},
  1071. };
  1072. /* static parameters */
  1073. static const struct dbg_off dbg_statics[] = {
  1074. {"desc_index", S_IRUGO | S_IWUSR, (ulong)&dbg_txdesc_index, doff_u32},
  1075. {"vring_index", S_IRUGO | S_IWUSR, (ulong)&dbg_vring_index, doff_u32},
  1076. {"mem_addr", S_IRUGO | S_IWUSR, (ulong)&mem_addr, doff_u32},
  1077. {},
  1078. };
  1079. int wil6210_debugfs_init(struct wil6210_priv *wil)
  1080. {
  1081. struct dentry *dbg = wil->debug = debugfs_create_dir(WIL_NAME,
  1082. wil_to_wiphy(wil)->debugfsdir);
  1083. if (IS_ERR_OR_NULL(dbg))
  1084. return -ENODEV;
  1085. wil6210_debugfs_init_files(wil, dbg);
  1086. wil6210_debugfs_init_isr(wil, dbg);
  1087. wil6210_debugfs_init_blobs(wil, dbg);
  1088. wil6210_debugfs_init_offset(wil, dbg, wil, dbg_wil_off);
  1089. wil6210_debugfs_init_offset(wil, dbg, (void * __force)wil->csr,
  1090. dbg_wil_regs);
  1091. wil6210_debugfs_init_offset(wil, dbg, NULL, dbg_statics);
  1092. wil6210_debugfs_create_pseudo_ISR(wil, dbg);
  1093. wil6210_debugfs_create_ITR_CNT(wil, dbg);
  1094. return 0;
  1095. }
  1096. void wil6210_debugfs_remove(struct wil6210_priv *wil)
  1097. {
  1098. debugfs_remove_recursive(wil->debug);
  1099. wil->debug = NULL;
  1100. }