debugfs.c 36 KB

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