debugfs.c 44 KB

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