debugfs.c 44 KB

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