debugfs.c 39 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550
  1. /*
  2. * Copyright (c) 2012-2015 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 < 1025)) {
  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 % 64) == 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 = kmalloc(len + 1, GFP_KERNEL);
  494. if (!kbuf)
  495. return -ENOMEM;
  496. if (copy_from_user(kbuf, buf, len)) {
  497. kfree(kbuf);
  498. return -EIO;
  499. }
  500. kbuf[len] = '\0';
  501. rc = kstrtol(kbuf, 0, &channel);
  502. kfree(kbuf);
  503. if (rc)
  504. return rc;
  505. if ((channel < 0) || (channel > 4)) {
  506. wil_err(wil, "Invalid channel %ld\n", channel);
  507. return -EINVAL;
  508. }
  509. on = !!channel;
  510. if (on) {
  511. rc = wmi_set_channel(wil, (int)channel);
  512. if (rc)
  513. return rc;
  514. }
  515. rc = wmi_rxon(wil, on);
  516. if (rc)
  517. return rc;
  518. return len;
  519. }
  520. static const struct file_operations fops_rxon = {
  521. .write = wil_write_file_rxon,
  522. .open = simple_open,
  523. };
  524. /* block ack control, write:
  525. * - "add <ringid> <agg_size> <timeout>" to trigger ADDBA
  526. * - "del_tx <ringid> <reason>" to trigger DELBA for Tx side
  527. * - "del_rx <CID> <TID> <reason>" to trigger DELBA for Rx side
  528. */
  529. static ssize_t wil_write_back(struct file *file, const char __user *buf,
  530. size_t len, loff_t *ppos)
  531. {
  532. struct wil6210_priv *wil = file->private_data;
  533. int rc;
  534. char *kbuf = kmalloc(len + 1, GFP_KERNEL);
  535. char cmd[9];
  536. int p1, p2, p3;
  537. if (!kbuf)
  538. return -ENOMEM;
  539. rc = simple_write_to_buffer(kbuf, len, ppos, buf, len);
  540. if (rc != len) {
  541. kfree(kbuf);
  542. return rc >= 0 ? -EIO : rc;
  543. }
  544. kbuf[len] = '\0';
  545. rc = sscanf(kbuf, "%8s %d %d %d", cmd, &p1, &p2, &p3);
  546. kfree(kbuf);
  547. if (rc < 0)
  548. return rc;
  549. if (rc < 2)
  550. return -EINVAL;
  551. if (0 == strcmp(cmd, "add")) {
  552. if (rc < 3) {
  553. wil_err(wil, "BACK: add require at least 2 params\n");
  554. return -EINVAL;
  555. }
  556. if (rc < 4)
  557. p3 = 0;
  558. wmi_addba(wil, p1, p2, p3);
  559. } else if (0 == strcmp(cmd, "del_tx")) {
  560. if (rc < 3)
  561. p2 = WLAN_REASON_QSTA_LEAVE_QBSS;
  562. wmi_delba_tx(wil, p1, p2);
  563. } else if (0 == strcmp(cmd, "del_rx")) {
  564. if (rc < 3) {
  565. wil_err(wil,
  566. "BACK: del_rx require at least 2 params\n");
  567. return -EINVAL;
  568. }
  569. if (rc < 4)
  570. p3 = WLAN_REASON_QSTA_LEAVE_QBSS;
  571. wmi_delba_rx(wil, mk_cidxtid(p1, p2), p3);
  572. } else {
  573. wil_err(wil, "BACK: Unrecognized command \"%s\"\n", cmd);
  574. return -EINVAL;
  575. }
  576. return len;
  577. }
  578. static ssize_t wil_read_back(struct file *file, char __user *user_buf,
  579. size_t count, loff_t *ppos)
  580. {
  581. static const char text[] = "block ack control, write:\n"
  582. " - \"add <ringid> <agg_size> <timeout>\" to trigger ADDBA\n"
  583. "If missing, <timeout> defaults to 0\n"
  584. " - \"del_tx <ringid> <reason>\" to trigger DELBA for Tx side\n"
  585. " - \"del_rx <CID> <TID> <reason>\" to trigger DELBA for Rx side\n"
  586. "If missing, <reason> set to \"STA_LEAVING\" (36)\n";
  587. return simple_read_from_buffer(user_buf, count, ppos, text,
  588. sizeof(text));
  589. }
  590. static const struct file_operations fops_back = {
  591. .read = wil_read_back,
  592. .write = wil_write_back,
  593. .open = simple_open,
  594. };
  595. /* pmc control, write:
  596. * - "alloc <num descriptors> <descriptor_size>" to allocate PMC
  597. * - "free" to release memory allocated for PMC
  598. */
  599. static ssize_t wil_write_pmccfg(struct file *file, const char __user *buf,
  600. size_t len, loff_t *ppos)
  601. {
  602. struct wil6210_priv *wil = file->private_data;
  603. int rc;
  604. char *kbuf = kmalloc(len + 1, GFP_KERNEL);
  605. char cmd[9];
  606. int num_descs, desc_size;
  607. if (!kbuf)
  608. return -ENOMEM;
  609. rc = simple_write_to_buffer(kbuf, len, ppos, buf, len);
  610. if (rc != len) {
  611. kfree(kbuf);
  612. return rc >= 0 ? -EIO : rc;
  613. }
  614. kbuf[len] = '\0';
  615. rc = sscanf(kbuf, "%8s %d %d", cmd, &num_descs, &desc_size);
  616. kfree(kbuf);
  617. if (rc < 0)
  618. return rc;
  619. if (rc < 1) {
  620. wil_err(wil, "pmccfg: no params given\n");
  621. return -EINVAL;
  622. }
  623. if (0 == strcmp(cmd, "alloc")) {
  624. if (rc != 3) {
  625. wil_err(wil, "pmccfg: alloc requires 2 params\n");
  626. return -EINVAL;
  627. }
  628. wil_pmc_alloc(wil, num_descs, desc_size);
  629. } else if (0 == strcmp(cmd, "free")) {
  630. if (rc != 1) {
  631. wil_err(wil, "pmccfg: free does not have any params\n");
  632. return -EINVAL;
  633. }
  634. wil_pmc_free(wil, true);
  635. } else {
  636. wil_err(wil, "pmccfg: Unrecognized command \"%s\"\n", cmd);
  637. return -EINVAL;
  638. }
  639. return len;
  640. }
  641. static ssize_t wil_read_pmccfg(struct file *file, char __user *user_buf,
  642. size_t count, loff_t *ppos)
  643. {
  644. struct wil6210_priv *wil = file->private_data;
  645. char text[256];
  646. char help[] = "pmc control, write:\n"
  647. " - \"alloc <num descriptors> <descriptor_size>\" to allocate pmc\n"
  648. " - \"free\" to free memory allocated for pmc\n";
  649. sprintf(text, "Last command status: %d\n\n%s",
  650. wil_pmc_last_cmd_status(wil),
  651. help);
  652. return simple_read_from_buffer(user_buf, count, ppos, text,
  653. strlen(text) + 1);
  654. }
  655. static const struct file_operations fops_pmccfg = {
  656. .read = wil_read_pmccfg,
  657. .write = wil_write_pmccfg,
  658. .open = simple_open,
  659. };
  660. static const struct file_operations fops_pmcdata = {
  661. .open = simple_open,
  662. .read = wil_pmc_read,
  663. .llseek = wil_pmc_llseek,
  664. };
  665. /*---tx_mgmt---*/
  666. /* Write mgmt frame to this file to send it */
  667. static ssize_t wil_write_file_txmgmt(struct file *file, const char __user *buf,
  668. size_t len, loff_t *ppos)
  669. {
  670. struct wil6210_priv *wil = file->private_data;
  671. struct wiphy *wiphy = wil_to_wiphy(wil);
  672. struct wireless_dev *wdev = wil_to_wdev(wil);
  673. struct cfg80211_mgmt_tx_params params;
  674. int rc;
  675. void *frame = kmalloc(len, GFP_KERNEL);
  676. if (!frame)
  677. return -ENOMEM;
  678. if (copy_from_user(frame, buf, len)) {
  679. kfree(frame);
  680. return -EIO;
  681. }
  682. params.buf = frame;
  683. params.len = len;
  684. params.chan = wdev->preset_chandef.chan;
  685. rc = wil_cfg80211_mgmt_tx(wiphy, wdev, &params, NULL);
  686. kfree(frame);
  687. wil_info(wil, "%s() -> %d\n", __func__, rc);
  688. return len;
  689. }
  690. static const struct file_operations fops_txmgmt = {
  691. .write = wil_write_file_txmgmt,
  692. .open = simple_open,
  693. };
  694. /* Write WMI command (w/o mbox header) to this file to send it
  695. * WMI starts from wil6210_mbox_hdr_wmi header
  696. */
  697. static ssize_t wil_write_file_wmi(struct file *file, const char __user *buf,
  698. size_t len, loff_t *ppos)
  699. {
  700. struct wil6210_priv *wil = file->private_data;
  701. struct wil6210_mbox_hdr_wmi *wmi;
  702. void *cmd;
  703. int cmdlen = len - sizeof(struct wil6210_mbox_hdr_wmi);
  704. u16 cmdid;
  705. int rc, rc1;
  706. if (cmdlen <= 0)
  707. return -EINVAL;
  708. wmi = kmalloc(len, GFP_KERNEL);
  709. if (!wmi)
  710. return -ENOMEM;
  711. rc = simple_write_to_buffer(wmi, len, ppos, buf, len);
  712. if (rc < 0) {
  713. kfree(wmi);
  714. return rc;
  715. }
  716. cmd = &wmi[1];
  717. cmdid = le16_to_cpu(wmi->id);
  718. rc1 = wmi_send(wil, cmdid, cmd, cmdlen);
  719. kfree(wmi);
  720. wil_info(wil, "%s(0x%04x[%d]) -> %d\n", __func__, cmdid, cmdlen, rc1);
  721. return rc;
  722. }
  723. static const struct file_operations fops_wmi = {
  724. .write = wil_write_file_wmi,
  725. .open = simple_open,
  726. };
  727. static void wil_seq_print_skb(struct seq_file *s, struct sk_buff *skb)
  728. {
  729. int i = 0;
  730. int len = skb_headlen(skb);
  731. void *p = skb->data;
  732. int nr_frags = skb_shinfo(skb)->nr_frags;
  733. seq_printf(s, " len = %d\n", len);
  734. wil_seq_hexdump(s, p, len, " : ");
  735. if (nr_frags) {
  736. seq_printf(s, " nr_frags = %d\n", nr_frags);
  737. for (i = 0; i < nr_frags; i++) {
  738. const struct skb_frag_struct *frag =
  739. &skb_shinfo(skb)->frags[i];
  740. len = skb_frag_size(frag);
  741. p = skb_frag_address_safe(frag);
  742. seq_printf(s, " [%2d] : len = %d\n", i, len);
  743. wil_seq_hexdump(s, p, len, " : ");
  744. }
  745. }
  746. }
  747. /*---------Tx/Rx descriptor------------*/
  748. static int wil_txdesc_debugfs_show(struct seq_file *s, void *data)
  749. {
  750. struct wil6210_priv *wil = s->private;
  751. struct vring *vring;
  752. bool tx = (dbg_vring_index < WIL6210_MAX_TX_RINGS);
  753. vring = tx ? &wil->vring_tx[dbg_vring_index] : &wil->vring_rx;
  754. if (!vring->va) {
  755. if (tx)
  756. seq_printf(s, "No Tx[%2d] VRING\n", dbg_vring_index);
  757. else
  758. seq_puts(s, "No Rx VRING\n");
  759. return 0;
  760. }
  761. if (dbg_txdesc_index < vring->size) {
  762. /* use struct vring_tx_desc for Rx as well,
  763. * only field used, .dma.length, is the same
  764. */
  765. volatile struct vring_tx_desc *d =
  766. &vring->va[dbg_txdesc_index].tx;
  767. volatile u32 *u = (volatile u32 *)d;
  768. struct sk_buff *skb = vring->ctx[dbg_txdesc_index].skb;
  769. if (tx)
  770. seq_printf(s, "Tx[%2d][%3d] = {\n", dbg_vring_index,
  771. dbg_txdesc_index);
  772. else
  773. seq_printf(s, "Rx[%3d] = {\n", dbg_txdesc_index);
  774. seq_printf(s, " MAC = 0x%08x 0x%08x 0x%08x 0x%08x\n",
  775. u[0], u[1], u[2], u[3]);
  776. seq_printf(s, " DMA = 0x%08x 0x%08x 0x%08x 0x%08x\n",
  777. u[4], u[5], u[6], u[7]);
  778. seq_printf(s, " SKB = 0x%p\n", skb);
  779. if (skb) {
  780. skb_get(skb);
  781. wil_seq_print_skb(s, skb);
  782. kfree_skb(skb);
  783. }
  784. seq_puts(s, "}\n");
  785. } else {
  786. if (tx)
  787. seq_printf(s, "[%2d] TxDesc index (%d) >= size (%d)\n",
  788. dbg_vring_index, dbg_txdesc_index,
  789. vring->size);
  790. else
  791. seq_printf(s, "RxDesc index (%d) >= size (%d)\n",
  792. dbg_txdesc_index, vring->size);
  793. }
  794. return 0;
  795. }
  796. static int wil_txdesc_seq_open(struct inode *inode, struct file *file)
  797. {
  798. return single_open(file, wil_txdesc_debugfs_show, inode->i_private);
  799. }
  800. static const struct file_operations fops_txdesc = {
  801. .open = wil_txdesc_seq_open,
  802. .release = single_release,
  803. .read = seq_read,
  804. .llseek = seq_lseek,
  805. };
  806. /*---------beamforming------------*/
  807. static char *wil_bfstatus_str(u32 status)
  808. {
  809. switch (status) {
  810. case 0:
  811. return "Failed";
  812. case 1:
  813. return "OK";
  814. case 2:
  815. return "Retrying";
  816. default:
  817. return "??";
  818. }
  819. }
  820. static bool is_all_zeros(void * const x_, size_t sz)
  821. {
  822. /* if reply is all-0, ignore this CID */
  823. u32 *x = x_;
  824. int n;
  825. for (n = 0; n < sz / sizeof(*x); n++)
  826. if (x[n])
  827. return false;
  828. return true;
  829. }
  830. static int wil_bf_debugfs_show(struct seq_file *s, void *data)
  831. {
  832. int rc;
  833. int i;
  834. struct wil6210_priv *wil = s->private;
  835. struct wmi_notify_req_cmd cmd = {
  836. .interval_usec = 0,
  837. };
  838. struct {
  839. struct wil6210_mbox_hdr_wmi wmi;
  840. struct wmi_notify_req_done_event evt;
  841. } __packed reply;
  842. for (i = 0; i < ARRAY_SIZE(wil->sta); i++) {
  843. u32 status;
  844. cmd.cid = i;
  845. rc = wmi_call(wil, WMI_NOTIFY_REQ_CMDID, &cmd, sizeof(cmd),
  846. WMI_NOTIFY_REQ_DONE_EVENTID, &reply,
  847. sizeof(reply), 20);
  848. /* if reply is all-0, ignore this CID */
  849. if (rc || is_all_zeros(&reply.evt, sizeof(reply.evt)))
  850. continue;
  851. status = le32_to_cpu(reply.evt.status);
  852. seq_printf(s, "CID %d {\n"
  853. " TSF = 0x%016llx\n"
  854. " TxMCS = %2d TxTpt = %4d\n"
  855. " SQI = %4d\n"
  856. " Status = 0x%08x %s\n"
  857. " Sectors(rx:tx) my %2d:%2d peer %2d:%2d\n"
  858. " Goodput(rx:tx) %4d:%4d\n"
  859. "}\n",
  860. i,
  861. le64_to_cpu(reply.evt.tsf),
  862. le16_to_cpu(reply.evt.bf_mcs),
  863. le32_to_cpu(reply.evt.tx_tpt),
  864. reply.evt.sqi,
  865. status, wil_bfstatus_str(status),
  866. le16_to_cpu(reply.evt.my_rx_sector),
  867. le16_to_cpu(reply.evt.my_tx_sector),
  868. le16_to_cpu(reply.evt.other_rx_sector),
  869. le16_to_cpu(reply.evt.other_tx_sector),
  870. le32_to_cpu(reply.evt.rx_goodput),
  871. le32_to_cpu(reply.evt.tx_goodput));
  872. }
  873. return 0;
  874. }
  875. static int wil_bf_seq_open(struct inode *inode, struct file *file)
  876. {
  877. return single_open(file, wil_bf_debugfs_show, inode->i_private);
  878. }
  879. static const struct file_operations fops_bf = {
  880. .open = wil_bf_seq_open,
  881. .release = single_release,
  882. .read = seq_read,
  883. .llseek = seq_lseek,
  884. };
  885. /*---------SSID------------*/
  886. static ssize_t wil_read_file_ssid(struct file *file, char __user *user_buf,
  887. size_t count, loff_t *ppos)
  888. {
  889. struct wil6210_priv *wil = file->private_data;
  890. struct wireless_dev *wdev = wil_to_wdev(wil);
  891. return simple_read_from_buffer(user_buf, count, ppos,
  892. wdev->ssid, wdev->ssid_len);
  893. }
  894. static ssize_t wil_write_file_ssid(struct file *file, const char __user *buf,
  895. size_t count, loff_t *ppos)
  896. {
  897. struct wil6210_priv *wil = file->private_data;
  898. struct wireless_dev *wdev = wil_to_wdev(wil);
  899. struct net_device *ndev = wil_to_ndev(wil);
  900. if (*ppos != 0) {
  901. wil_err(wil, "Unable to set SSID substring from [%d]\n",
  902. (int)*ppos);
  903. return -EINVAL;
  904. }
  905. if (count > sizeof(wdev->ssid)) {
  906. wil_err(wil, "SSID too long, len = %d\n", (int)count);
  907. return -EINVAL;
  908. }
  909. if (netif_running(ndev)) {
  910. wil_err(wil, "Unable to change SSID on running interface\n");
  911. return -EINVAL;
  912. }
  913. wdev->ssid_len = count;
  914. return simple_write_to_buffer(wdev->ssid, wdev->ssid_len, ppos,
  915. buf, count);
  916. }
  917. static const struct file_operations fops_ssid = {
  918. .read = wil_read_file_ssid,
  919. .write = wil_write_file_ssid,
  920. .open = simple_open,
  921. };
  922. /*---------temp------------*/
  923. static void print_temp(struct seq_file *s, const char *prefix, u32 t)
  924. {
  925. switch (t) {
  926. case 0:
  927. case ~(u32)0:
  928. seq_printf(s, "%s N/A\n", prefix);
  929. break;
  930. default:
  931. seq_printf(s, "%s %d.%03d\n", prefix, t / 1000, t % 1000);
  932. break;
  933. }
  934. }
  935. static int wil_temp_debugfs_show(struct seq_file *s, void *data)
  936. {
  937. struct wil6210_priv *wil = s->private;
  938. u32 t_m, t_r;
  939. int rc = wmi_get_temperature(wil, &t_m, &t_r);
  940. if (rc) {
  941. seq_puts(s, "Failed\n");
  942. return 0;
  943. }
  944. print_temp(s, "T_mac =", t_m);
  945. print_temp(s, "T_radio =", t_r);
  946. return 0;
  947. }
  948. static int wil_temp_seq_open(struct inode *inode, struct file *file)
  949. {
  950. return single_open(file, wil_temp_debugfs_show, inode->i_private);
  951. }
  952. static const struct file_operations fops_temp = {
  953. .open = wil_temp_seq_open,
  954. .release = single_release,
  955. .read = seq_read,
  956. .llseek = seq_lseek,
  957. };
  958. /*---------freq------------*/
  959. static int wil_freq_debugfs_show(struct seq_file *s, void *data)
  960. {
  961. struct wil6210_priv *wil = s->private;
  962. struct wireless_dev *wdev = wil_to_wdev(wil);
  963. u16 freq = wdev->chandef.chan ? wdev->chandef.chan->center_freq : 0;
  964. seq_printf(s, "Freq = %d\n", freq);
  965. return 0;
  966. }
  967. static int wil_freq_seq_open(struct inode *inode, struct file *file)
  968. {
  969. return single_open(file, wil_freq_debugfs_show, inode->i_private);
  970. }
  971. static const struct file_operations fops_freq = {
  972. .open = wil_freq_seq_open,
  973. .release = single_release,
  974. .read = seq_read,
  975. .llseek = seq_lseek,
  976. };
  977. /*---------link------------*/
  978. static int wil_link_debugfs_show(struct seq_file *s, void *data)
  979. {
  980. struct wil6210_priv *wil = s->private;
  981. struct station_info sinfo;
  982. int i, rc;
  983. for (i = 0; i < ARRAY_SIZE(wil->sta); i++) {
  984. struct wil_sta_info *p = &wil->sta[i];
  985. char *status = "unknown";
  986. switch (p->status) {
  987. case wil_sta_unused:
  988. status = "unused ";
  989. break;
  990. case wil_sta_conn_pending:
  991. status = "pending ";
  992. break;
  993. case wil_sta_connected:
  994. status = "connected";
  995. break;
  996. }
  997. seq_printf(s, "[%d] %pM %s\n", i, p->addr, status);
  998. if (p->status == wil_sta_connected) {
  999. rc = wil_cid_fill_sinfo(wil, i, &sinfo);
  1000. if (rc)
  1001. return rc;
  1002. seq_printf(s, " Tx_mcs = %d\n", sinfo.txrate.mcs);
  1003. seq_printf(s, " Rx_mcs = %d\n", sinfo.rxrate.mcs);
  1004. seq_printf(s, " SQ = %d\n", sinfo.signal);
  1005. }
  1006. }
  1007. return 0;
  1008. }
  1009. static int wil_link_seq_open(struct inode *inode, struct file *file)
  1010. {
  1011. return single_open(file, wil_link_debugfs_show, inode->i_private);
  1012. }
  1013. static const struct file_operations fops_link = {
  1014. .open = wil_link_seq_open,
  1015. .release = single_release,
  1016. .read = seq_read,
  1017. .llseek = seq_lseek,
  1018. };
  1019. /*---------info------------*/
  1020. static int wil_info_debugfs_show(struct seq_file *s, void *data)
  1021. {
  1022. struct wil6210_priv *wil = s->private;
  1023. struct net_device *ndev = wil_to_ndev(wil);
  1024. int is_ac = power_supply_is_system_supplied();
  1025. int rx = atomic_xchg(&wil->isr_count_rx, 0);
  1026. int tx = atomic_xchg(&wil->isr_count_tx, 0);
  1027. static ulong rxf_old, txf_old;
  1028. ulong rxf = ndev->stats.rx_packets;
  1029. ulong txf = ndev->stats.tx_packets;
  1030. unsigned int i;
  1031. /* >0 : AC; 0 : battery; <0 : error */
  1032. seq_printf(s, "AC powered : %d\n", is_ac);
  1033. seq_printf(s, "Rx irqs:packets : %8d : %8ld\n", rx, rxf - rxf_old);
  1034. seq_printf(s, "Tx irqs:packets : %8d : %8ld\n", tx, txf - txf_old);
  1035. rxf_old = rxf;
  1036. txf_old = txf;
  1037. #define CHECK_QSTATE(x) (state & BIT(__QUEUE_STATE_ ## x)) ? \
  1038. " " __stringify(x) : ""
  1039. for (i = 0; i < ndev->num_tx_queues; i++) {
  1040. struct netdev_queue *txq = netdev_get_tx_queue(ndev, i);
  1041. unsigned long state = txq->state;
  1042. seq_printf(s, "Tx queue[%i] state : 0x%lx%s%s%s\n", i, state,
  1043. CHECK_QSTATE(DRV_XOFF),
  1044. CHECK_QSTATE(STACK_XOFF),
  1045. CHECK_QSTATE(FROZEN)
  1046. );
  1047. }
  1048. #undef CHECK_QSTATE
  1049. return 0;
  1050. }
  1051. static int wil_info_seq_open(struct inode *inode, struct file *file)
  1052. {
  1053. return single_open(file, wil_info_debugfs_show, inode->i_private);
  1054. }
  1055. static const struct file_operations fops_info = {
  1056. .open = wil_info_seq_open,
  1057. .release = single_release,
  1058. .read = seq_read,
  1059. .llseek = seq_lseek,
  1060. };
  1061. /*---------recovery------------*/
  1062. /* mode = [manual|auto]
  1063. * state = [idle|pending|running]
  1064. */
  1065. static ssize_t wil_read_file_recovery(struct file *file, char __user *user_buf,
  1066. size_t count, loff_t *ppos)
  1067. {
  1068. struct wil6210_priv *wil = file->private_data;
  1069. char buf[80];
  1070. int n;
  1071. static const char * const sstate[] = {"idle", "pending", "running"};
  1072. n = snprintf(buf, sizeof(buf), "mode = %s\nstate = %s\n",
  1073. no_fw_recovery ? "manual" : "auto",
  1074. sstate[wil->recovery_state]);
  1075. n = min_t(int, n, sizeof(buf));
  1076. return simple_read_from_buffer(user_buf, count, ppos,
  1077. buf, n);
  1078. }
  1079. static ssize_t wil_write_file_recovery(struct file *file,
  1080. const char __user *buf_,
  1081. size_t count, loff_t *ppos)
  1082. {
  1083. struct wil6210_priv *wil = file->private_data;
  1084. static const char run_command[] = "run";
  1085. char buf[sizeof(run_command) + 1]; /* to detect "runx" */
  1086. ssize_t rc;
  1087. if (wil->recovery_state != fw_recovery_pending) {
  1088. wil_err(wil, "No recovery pending\n");
  1089. return -EINVAL;
  1090. }
  1091. if (*ppos != 0) {
  1092. wil_err(wil, "Offset [%d]\n", (int)*ppos);
  1093. return -EINVAL;
  1094. }
  1095. if (count > sizeof(buf)) {
  1096. wil_err(wil, "Input too long, len = %d\n", (int)count);
  1097. return -EINVAL;
  1098. }
  1099. rc = simple_write_to_buffer(buf, sizeof(buf) - 1, ppos, buf_, count);
  1100. if (rc < 0)
  1101. return rc;
  1102. buf[rc] = '\0';
  1103. if (0 == strcmp(buf, run_command))
  1104. wil_set_recovery_state(wil, fw_recovery_running);
  1105. else
  1106. wil_err(wil, "Bad recovery command \"%s\"\n", buf);
  1107. return rc;
  1108. }
  1109. static const struct file_operations fops_recovery = {
  1110. .read = wil_read_file_recovery,
  1111. .write = wil_write_file_recovery,
  1112. .open = simple_open,
  1113. };
  1114. /*---------Station matrix------------*/
  1115. static void wil_print_rxtid(struct seq_file *s, struct wil_tid_ampdu_rx *r)
  1116. {
  1117. int i;
  1118. u16 index = ((r->head_seq_num - r->ssn) & 0xfff) % r->buf_size;
  1119. unsigned long long drop_dup = r->drop_dup, drop_old = r->drop_old;
  1120. seq_printf(s, "([%2d] %3d TU) 0x%03x [", r->buf_size, r->timeout,
  1121. r->head_seq_num);
  1122. for (i = 0; i < r->buf_size; i++) {
  1123. if (i == index)
  1124. seq_printf(s, "%c", r->reorder_buf[i] ? 'O' : '|');
  1125. else
  1126. seq_printf(s, "%c", r->reorder_buf[i] ? '*' : '_');
  1127. }
  1128. seq_printf(s,
  1129. "] total %llu drop %llu (dup %llu + old %llu) last 0x%03x\n",
  1130. r->total, drop_dup + drop_old, drop_dup, drop_old,
  1131. r->ssn_last_drop);
  1132. }
  1133. static int wil_sta_debugfs_show(struct seq_file *s, void *data)
  1134. __acquires(&p->tid_rx_lock) __releases(&p->tid_rx_lock)
  1135. {
  1136. struct wil6210_priv *wil = s->private;
  1137. int i, tid, mcs;
  1138. for (i = 0; i < ARRAY_SIZE(wil->sta); i++) {
  1139. struct wil_sta_info *p = &wil->sta[i];
  1140. char *status = "unknown";
  1141. switch (p->status) {
  1142. case wil_sta_unused:
  1143. status = "unused ";
  1144. break;
  1145. case wil_sta_conn_pending:
  1146. status = "pending ";
  1147. break;
  1148. case wil_sta_connected:
  1149. status = "connected";
  1150. break;
  1151. }
  1152. seq_printf(s, "[%d] %pM %s\n", i, p->addr, status);
  1153. if (p->status == wil_sta_connected) {
  1154. spin_lock_bh(&p->tid_rx_lock);
  1155. for (tid = 0; tid < WIL_STA_TID_NUM; tid++) {
  1156. struct wil_tid_ampdu_rx *r = p->tid_rx[tid];
  1157. if (r) {
  1158. seq_printf(s, "[%2d] ", tid);
  1159. wil_print_rxtid(s, r);
  1160. }
  1161. }
  1162. spin_unlock_bh(&p->tid_rx_lock);
  1163. seq_printf(s,
  1164. "Rx invalid frame: non-data %lu, short %lu, large %lu\n",
  1165. p->stats.rx_non_data_frame,
  1166. p->stats.rx_short_frame,
  1167. p->stats.rx_large_frame);
  1168. seq_puts(s, "Rx/MCS:");
  1169. for (mcs = 0; mcs < ARRAY_SIZE(p->stats.rx_per_mcs);
  1170. mcs++)
  1171. seq_printf(s, " %lld",
  1172. p->stats.rx_per_mcs[mcs]);
  1173. seq_puts(s, "\n");
  1174. }
  1175. }
  1176. return 0;
  1177. }
  1178. static int wil_sta_seq_open(struct inode *inode, struct file *file)
  1179. {
  1180. return single_open(file, wil_sta_debugfs_show, inode->i_private);
  1181. }
  1182. static const struct file_operations fops_sta = {
  1183. .open = wil_sta_seq_open,
  1184. .release = single_release,
  1185. .read = seq_read,
  1186. .llseek = seq_lseek,
  1187. };
  1188. /*----------------*/
  1189. static void wil6210_debugfs_init_blobs(struct wil6210_priv *wil,
  1190. struct dentry *dbg)
  1191. {
  1192. int i;
  1193. char name[32];
  1194. for (i = 0; i < ARRAY_SIZE(fw_mapping); i++) {
  1195. struct debugfs_blob_wrapper *blob = &wil->blobs[i];
  1196. const struct fw_map *map = &fw_mapping[i];
  1197. if (!map->name)
  1198. continue;
  1199. blob->data = (void * __force)wil->csr + HOSTADDR(map->host);
  1200. blob->size = map->to - map->from;
  1201. snprintf(name, sizeof(name), "blob_%s", map->name);
  1202. wil_debugfs_create_ioblob(name, S_IRUGO, dbg, blob);
  1203. }
  1204. }
  1205. /* misc files */
  1206. static const struct {
  1207. const char *name;
  1208. umode_t mode;
  1209. const struct file_operations *fops;
  1210. } dbg_files[] = {
  1211. {"mbox", S_IRUGO, &fops_mbox},
  1212. {"vrings", S_IRUGO, &fops_vring},
  1213. {"stations", S_IRUGO, &fops_sta},
  1214. {"desc", S_IRUGO, &fops_txdesc},
  1215. {"bf", S_IRUGO, &fops_bf},
  1216. {"ssid", S_IRUGO | S_IWUSR, &fops_ssid},
  1217. {"mem_val", S_IRUGO, &fops_memread},
  1218. {"reset", S_IWUSR, &fops_reset},
  1219. {"rxon", S_IWUSR, &fops_rxon},
  1220. {"tx_mgmt", S_IWUSR, &fops_txmgmt},
  1221. {"wmi_send", S_IWUSR, &fops_wmi},
  1222. {"back", S_IRUGO | S_IWUSR, &fops_back},
  1223. {"pmccfg", S_IRUGO | S_IWUSR, &fops_pmccfg},
  1224. {"pmcdata", S_IRUGO, &fops_pmcdata},
  1225. {"temp", S_IRUGO, &fops_temp},
  1226. {"freq", S_IRUGO, &fops_freq},
  1227. {"link", S_IRUGO, &fops_link},
  1228. {"info", S_IRUGO, &fops_info},
  1229. {"recovery", S_IRUGO | S_IWUSR, &fops_recovery},
  1230. };
  1231. static void wil6210_debugfs_init_files(struct wil6210_priv *wil,
  1232. struct dentry *dbg)
  1233. {
  1234. int i;
  1235. for (i = 0; i < ARRAY_SIZE(dbg_files); i++)
  1236. debugfs_create_file(dbg_files[i].name, dbg_files[i].mode, dbg,
  1237. wil, dbg_files[i].fops);
  1238. }
  1239. /* interrupt control blocks */
  1240. static const struct {
  1241. const char *name;
  1242. u32 icr_off;
  1243. } dbg_icr[] = {
  1244. {"USER_ICR", HOSTADDR(RGF_USER_USER_ICR)},
  1245. {"DMA_EP_TX_ICR", HOSTADDR(RGF_DMA_EP_TX_ICR)},
  1246. {"DMA_EP_RX_ICR", HOSTADDR(RGF_DMA_EP_RX_ICR)},
  1247. {"DMA_EP_MISC_ICR", HOSTADDR(RGF_DMA_EP_MISC_ICR)},
  1248. };
  1249. static void wil6210_debugfs_init_isr(struct wil6210_priv *wil,
  1250. struct dentry *dbg)
  1251. {
  1252. int i;
  1253. for (i = 0; i < ARRAY_SIZE(dbg_icr); i++)
  1254. wil6210_debugfs_create_ISR(wil, dbg_icr[i].name, dbg,
  1255. dbg_icr[i].icr_off);
  1256. }
  1257. #define WIL_FIELD(name, mode, type) { __stringify(name), mode, \
  1258. offsetof(struct wil6210_priv, name), type}
  1259. /* fields in struct wil6210_priv */
  1260. static const struct dbg_off dbg_wil_off[] = {
  1261. WIL_FIELD(privacy, S_IRUGO, doff_u32),
  1262. WIL_FIELD(status[0], S_IRUGO | S_IWUSR, doff_ulong),
  1263. WIL_FIELD(fw_version, S_IRUGO, doff_u32),
  1264. WIL_FIELD(hw_version, S_IRUGO, doff_x32),
  1265. WIL_FIELD(recovery_count, S_IRUGO, doff_u32),
  1266. WIL_FIELD(ap_isolate, S_IRUGO, doff_u32),
  1267. {},
  1268. };
  1269. static const struct dbg_off dbg_wil_regs[] = {
  1270. {"RGF_MAC_MTRL_COUNTER_0", S_IRUGO, HOSTADDR(RGF_MAC_MTRL_COUNTER_0),
  1271. doff_io32},
  1272. {"RGF_USER_USAGE_1", S_IRUGO, HOSTADDR(RGF_USER_USAGE_1), doff_io32},
  1273. {},
  1274. };
  1275. /* static parameters */
  1276. static const struct dbg_off dbg_statics[] = {
  1277. {"desc_index", S_IRUGO | S_IWUSR, (ulong)&dbg_txdesc_index, doff_u32},
  1278. {"vring_index", S_IRUGO | S_IWUSR, (ulong)&dbg_vring_index, doff_u32},
  1279. {"mem_addr", S_IRUGO | S_IWUSR, (ulong)&mem_addr, doff_u32},
  1280. {"vring_idle_trsh", S_IRUGO | S_IWUSR, (ulong)&vring_idle_trsh,
  1281. doff_u32},
  1282. {},
  1283. };
  1284. int wil6210_debugfs_init(struct wil6210_priv *wil)
  1285. {
  1286. struct dentry *dbg = wil->debug = debugfs_create_dir(WIL_NAME,
  1287. wil_to_wiphy(wil)->debugfsdir);
  1288. if (IS_ERR_OR_NULL(dbg))
  1289. return -ENODEV;
  1290. wil_pmc_init(wil);
  1291. wil6210_debugfs_init_files(wil, dbg);
  1292. wil6210_debugfs_init_isr(wil, dbg);
  1293. wil6210_debugfs_init_blobs(wil, dbg);
  1294. wil6210_debugfs_init_offset(wil, dbg, wil, dbg_wil_off);
  1295. wil6210_debugfs_init_offset(wil, dbg, (void * __force)wil->csr,
  1296. dbg_wil_regs);
  1297. wil6210_debugfs_init_offset(wil, dbg, NULL, dbg_statics);
  1298. wil6210_debugfs_create_pseudo_ISR(wil, dbg);
  1299. wil6210_debugfs_create_ITR_CNT(wil, dbg);
  1300. return 0;
  1301. }
  1302. void wil6210_debugfs_remove(struct wil6210_priv *wil)
  1303. {
  1304. debugfs_remove_recursive(wil->debug);
  1305. wil->debug = NULL;
  1306. /* free pmc memory without sending command to fw, as it will
  1307. * be reset on the way down anyway
  1308. */
  1309. wil_pmc_free(wil, false);
  1310. }