debugfs.c 39 KB

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