debugfs.c 65 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607
  1. /*
  2. * Copyright (c) 2012-2017 Qualcomm Atheros, Inc.
  3. * Copyright (c) 2018, The Linux Foundation. All rights reserved.
  4. *
  5. * Permission to use, copy, modify, and/or distribute this software for any
  6. * purpose with or without fee is hereby granted, provided that the above
  7. * copyright notice and this permission notice appear in all copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  10. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  11. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  12. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  13. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  14. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  15. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  16. */
  17. #include <linux/module.h>
  18. #include <linux/debugfs.h>
  19. #include <linux/seq_file.h>
  20. #include <linux/pci.h>
  21. #include <linux/rtnetlink.h>
  22. #include <linux/power_supply.h>
  23. #include "wil6210.h"
  24. #include "wmi.h"
  25. #include "txrx.h"
  26. #include "pmc.h"
  27. /* Nasty hack. Better have per device instances */
  28. static u32 mem_addr;
  29. static u32 dbg_txdesc_index;
  30. static u32 dbg_ring_index; /* 24+ for Rx, 0..23 for Tx */
  31. static u32 dbg_status_msg_index;
  32. /* 0..wil->num_rx_status_rings-1 for Rx, wil->tx_sring_idx for Tx */
  33. static u32 dbg_sring_index;
  34. enum dbg_off_type {
  35. doff_u32 = 0,
  36. doff_x32 = 1,
  37. doff_ulong = 2,
  38. doff_io32 = 3,
  39. doff_u8 = 4
  40. };
  41. /* offset to "wil" */
  42. struct dbg_off {
  43. const char *name;
  44. umode_t mode;
  45. ulong off;
  46. enum dbg_off_type type;
  47. };
  48. static void wil_print_desc_edma(struct seq_file *s, struct wil6210_priv *wil,
  49. struct wil_ring *ring,
  50. char _s, char _h, int idx)
  51. {
  52. u8 num_of_descs;
  53. bool has_skb = false;
  54. if (ring->is_rx) {
  55. struct wil_rx_enhanced_desc *rx_d =
  56. (struct wil_rx_enhanced_desc *)
  57. &ring->va[idx].rx.enhanced;
  58. u16 buff_id = le16_to_cpu(rx_d->mac.buff_id);
  59. has_skb = wil->rx_buff_mgmt.buff_arr[buff_id].skb;
  60. seq_printf(s, "%c", (has_skb) ? _h : _s);
  61. } else {
  62. struct wil_tx_enhanced_desc *d =
  63. (struct wil_tx_enhanced_desc *)
  64. &ring->va[idx].tx.enhanced;
  65. num_of_descs = (u8)d->mac.d[2];
  66. has_skb = ring->ctx[idx].skb;
  67. if (num_of_descs >= 1)
  68. seq_printf(s, "%c", ring->ctx[idx].skb ? _h : _s);
  69. else
  70. /* num_of_descs == 0, it's a frag in a list of descs */
  71. seq_printf(s, "%c", has_skb ? 'h' : _s);
  72. }
  73. }
  74. static void wil_print_ring(struct seq_file *s, struct wil6210_priv *wil,
  75. const char *name, struct wil_ring *ring,
  76. char _s, char _h)
  77. {
  78. void __iomem *x = wmi_addr(wil, ring->hwtail);
  79. u32 v;
  80. seq_printf(s, "RING %s = {\n", name);
  81. seq_printf(s, " pa = %pad\n", &ring->pa);
  82. seq_printf(s, " va = 0x%p\n", ring->va);
  83. seq_printf(s, " size = %d\n", ring->size);
  84. if (wil->use_enhanced_dma_hw && ring->is_rx)
  85. seq_printf(s, " swtail = %u\n", *ring->edma_rx_swtail.va);
  86. else
  87. seq_printf(s, " swtail = %d\n", ring->swtail);
  88. seq_printf(s, " swhead = %d\n", ring->swhead);
  89. seq_printf(s, " hwtail = [0x%08x] -> ", ring->hwtail);
  90. if (x) {
  91. v = readl(x);
  92. seq_printf(s, "0x%08x = %d\n", v, v);
  93. } else {
  94. seq_puts(s, "???\n");
  95. }
  96. if (ring->va && (ring->size <= (1 << WIL_RING_SIZE_ORDER_MAX))) {
  97. uint i;
  98. for (i = 0; i < ring->size; i++) {
  99. if ((i % 128) == 0 && i != 0)
  100. seq_puts(s, "\n");
  101. if (wil->use_enhanced_dma_hw) {
  102. wil_print_desc_edma(s, wil, ring, _s, _h, i);
  103. } else {
  104. volatile struct vring_tx_desc *d =
  105. &ring->va[i].tx.legacy;
  106. seq_printf(s, "%c", (d->dma.status & BIT(0)) ?
  107. _s : (ring->ctx[i].skb ? _h : 'h'));
  108. }
  109. }
  110. seq_puts(s, "\n");
  111. }
  112. seq_puts(s, "}\n");
  113. }
  114. static int wil_ring_debugfs_show(struct seq_file *s, void *data)
  115. {
  116. uint i;
  117. struct wil6210_priv *wil = s->private;
  118. wil_print_ring(s, wil, "rx", &wil->ring_rx, 'S', '_');
  119. for (i = 0; i < ARRAY_SIZE(wil->ring_tx); i++) {
  120. struct wil_ring *ring = &wil->ring_tx[i];
  121. struct wil_ring_tx_data *txdata = &wil->ring_tx_data[i];
  122. if (ring->va) {
  123. int cid = wil->ring2cid_tid[i][0];
  124. int tid = wil->ring2cid_tid[i][1];
  125. u32 swhead = ring->swhead;
  126. u32 swtail = ring->swtail;
  127. int used = (ring->size + swhead - swtail)
  128. % ring->size;
  129. int avail = ring->size - used - 1;
  130. char name[10];
  131. char sidle[10];
  132. /* performance monitoring */
  133. cycles_t now = get_cycles();
  134. uint64_t idle = txdata->idle * 100;
  135. uint64_t total = now - txdata->begin;
  136. if (total != 0) {
  137. do_div(idle, total);
  138. snprintf(sidle, sizeof(sidle), "%3d%%",
  139. (int)idle);
  140. } else {
  141. snprintf(sidle, sizeof(sidle), "N/A");
  142. }
  143. txdata->begin = now;
  144. txdata->idle = 0ULL;
  145. snprintf(name, sizeof(name), "tx_%2d", i);
  146. if (cid < WIL6210_MAX_CID)
  147. seq_printf(s,
  148. "\n%pM CID %d TID %d 1x%s BACK([%u] %u TU A%s) [%3d|%3d] idle %s\n",
  149. wil->sta[cid].addr, cid, tid,
  150. txdata->dot1x_open ? "+" : "-",
  151. txdata->agg_wsize,
  152. txdata->agg_timeout,
  153. txdata->agg_amsdu ? "+" : "-",
  154. used, avail, sidle);
  155. else
  156. seq_printf(s,
  157. "\nBroadcast 1x%s [%3d|%3d] idle %s\n",
  158. txdata->dot1x_open ? "+" : "-",
  159. used, avail, sidle);
  160. wil_print_ring(s, wil, name, ring, '_', 'H');
  161. }
  162. }
  163. return 0;
  164. }
  165. static int wil_ring_seq_open(struct inode *inode, struct file *file)
  166. {
  167. return single_open(file, wil_ring_debugfs_show, inode->i_private);
  168. }
  169. static const struct file_operations fops_ring = {
  170. .open = wil_ring_seq_open,
  171. .release = single_release,
  172. .read = seq_read,
  173. .llseek = seq_lseek,
  174. };
  175. static void wil_print_sring(struct seq_file *s, struct wil6210_priv *wil,
  176. struct wil_status_ring *sring)
  177. {
  178. void __iomem *x = wmi_addr(wil, sring->hwtail);
  179. int sring_idx = sring - wil->srings;
  180. u32 v;
  181. seq_printf(s, "Status Ring %s [ %d ] = {\n",
  182. sring->is_rx ? "RX" : "TX", sring_idx);
  183. seq_printf(s, " pa = %pad\n", &sring->pa);
  184. seq_printf(s, " va = 0x%pK\n", sring->va);
  185. seq_printf(s, " size = %d\n", sring->size);
  186. seq_printf(s, " elem_size = %zu\n", sring->elem_size);
  187. seq_printf(s, " swhead = %d\n", sring->swhead);
  188. seq_printf(s, " hwtail = [0x%08x] -> ", sring->hwtail);
  189. if (x) {
  190. v = readl_relaxed(x);
  191. seq_printf(s, "0x%08x = %d\n", v, v);
  192. } else {
  193. seq_puts(s, "???\n");
  194. }
  195. seq_printf(s, " desc_rdy_pol = %d\n", sring->desc_rdy_pol);
  196. if (sring->va && (sring->size <= (1 << WIL_RING_SIZE_ORDER_MAX))) {
  197. uint i;
  198. for (i = 0; i < sring->size; i++) {
  199. u32 *sdword_0 =
  200. (u32 *)(sring->va + (sring->elem_size * i));
  201. if ((i % 128) == 0 && i != 0)
  202. seq_puts(s, "\n");
  203. if (i == sring->swhead)
  204. seq_printf(s, "%c", (*sdword_0 & BIT(31)) ?
  205. 'X' : 'x');
  206. else
  207. seq_printf(s, "%c", (*sdword_0 & BIT(31)) ?
  208. '1' : '0');
  209. }
  210. seq_puts(s, "\n");
  211. }
  212. seq_puts(s, "}\n");
  213. }
  214. static int wil_srings_debugfs_show(struct seq_file *s, void *data)
  215. {
  216. struct wil6210_priv *wil = s->private;
  217. int i = 0;
  218. for (i = 0; i < WIL6210_MAX_STATUS_RINGS; i++)
  219. if (wil->srings[i].va)
  220. wil_print_sring(s, wil, &wil->srings[i]);
  221. return 0;
  222. }
  223. static int wil_srings_seq_open(struct inode *inode, struct file *file)
  224. {
  225. return single_open(file, wil_srings_debugfs_show, inode->i_private);
  226. }
  227. static const struct file_operations fops_srings = {
  228. .open = wil_srings_seq_open,
  229. .release = single_release,
  230. .read = seq_read,
  231. .llseek = seq_lseek,
  232. };
  233. static void wil_seq_hexdump(struct seq_file *s, void *p, int len,
  234. const char *prefix)
  235. {
  236. seq_hex_dump(s, prefix, DUMP_PREFIX_NONE, 16, 1, p, len, false);
  237. }
  238. static void wil_print_mbox_ring(struct seq_file *s, const char *prefix,
  239. void __iomem *off)
  240. {
  241. struct wil6210_priv *wil = s->private;
  242. struct wil6210_mbox_ring r;
  243. int rsize;
  244. uint i;
  245. wil_halp_vote(wil);
  246. wil_memcpy_fromio_32(&r, off, sizeof(r));
  247. wil_mbox_ring_le2cpus(&r);
  248. /*
  249. * we just read memory block from NIC. This memory may be
  250. * garbage. Check validity before using it.
  251. */
  252. rsize = r.size / sizeof(struct wil6210_mbox_ring_desc);
  253. seq_printf(s, "ring %s = {\n", prefix);
  254. seq_printf(s, " base = 0x%08x\n", r.base);
  255. seq_printf(s, " size = 0x%04x bytes -> %d entries\n", r.size, rsize);
  256. seq_printf(s, " tail = 0x%08x\n", r.tail);
  257. seq_printf(s, " head = 0x%08x\n", r.head);
  258. seq_printf(s, " entry size = %d\n", r.entry_size);
  259. if (r.size % sizeof(struct wil6210_mbox_ring_desc)) {
  260. seq_printf(s, " ??? size is not multiple of %zd, garbage?\n",
  261. sizeof(struct wil6210_mbox_ring_desc));
  262. goto out;
  263. }
  264. if (!wmi_addr(wil, r.base) ||
  265. !wmi_addr(wil, r.tail) ||
  266. !wmi_addr(wil, r.head)) {
  267. seq_puts(s, " ??? pointers are garbage?\n");
  268. goto out;
  269. }
  270. for (i = 0; i < rsize; i++) {
  271. struct wil6210_mbox_ring_desc d;
  272. struct wil6210_mbox_hdr hdr;
  273. size_t delta = i * sizeof(d);
  274. void __iomem *x = wil->csr + HOSTADDR(r.base) + delta;
  275. wil_memcpy_fromio_32(&d, x, sizeof(d));
  276. seq_printf(s, " [%2x] %s %s%s 0x%08x", i,
  277. d.sync ? "F" : "E",
  278. (r.tail - r.base == delta) ? "t" : " ",
  279. (r.head - r.base == delta) ? "h" : " ",
  280. le32_to_cpu(d.addr));
  281. if (0 == wmi_read_hdr(wil, d.addr, &hdr)) {
  282. u16 len = le16_to_cpu(hdr.len);
  283. seq_printf(s, " -> %04x %04x %04x %02x\n",
  284. le16_to_cpu(hdr.seq), len,
  285. le16_to_cpu(hdr.type), hdr.flags);
  286. if (len <= MAX_MBOXITEM_SIZE) {
  287. unsigned char databuf[MAX_MBOXITEM_SIZE];
  288. void __iomem *src = wmi_buffer(wil, d.addr) +
  289. sizeof(struct wil6210_mbox_hdr);
  290. /*
  291. * No need to check @src for validity -
  292. * we already validated @d.addr while
  293. * reading header
  294. */
  295. wil_memcpy_fromio_32(databuf, src, len);
  296. wil_seq_hexdump(s, databuf, len, " : ");
  297. }
  298. } else {
  299. seq_puts(s, "\n");
  300. }
  301. }
  302. out:
  303. seq_puts(s, "}\n");
  304. wil_halp_unvote(wil);
  305. }
  306. static int wil_mbox_debugfs_show(struct seq_file *s, void *data)
  307. {
  308. struct wil6210_priv *wil = s->private;
  309. int ret;
  310. ret = wil_pm_runtime_get(wil);
  311. if (ret < 0)
  312. return ret;
  313. wil_print_mbox_ring(s, "tx", wil->csr + HOST_MBOX +
  314. offsetof(struct wil6210_mbox_ctl, tx));
  315. wil_print_mbox_ring(s, "rx", wil->csr + HOST_MBOX +
  316. offsetof(struct wil6210_mbox_ctl, rx));
  317. wil_pm_runtime_put(wil);
  318. return 0;
  319. }
  320. static int wil_mbox_seq_open(struct inode *inode, struct file *file)
  321. {
  322. return single_open(file, wil_mbox_debugfs_show, inode->i_private);
  323. }
  324. static const struct file_operations fops_mbox = {
  325. .open = wil_mbox_seq_open,
  326. .release = single_release,
  327. .read = seq_read,
  328. .llseek = seq_lseek,
  329. };
  330. static int wil_debugfs_iomem_x32_set(void *data, u64 val)
  331. {
  332. struct wil_debugfs_iomem_data *d = (struct
  333. wil_debugfs_iomem_data *)data;
  334. struct wil6210_priv *wil = d->wil;
  335. int ret;
  336. ret = wil_pm_runtime_get(wil);
  337. if (ret < 0)
  338. return ret;
  339. writel(val, (void __iomem *)d->offset);
  340. wmb(); /* make sure write propagated to HW */
  341. wil_pm_runtime_put(wil);
  342. return 0;
  343. }
  344. static int wil_debugfs_iomem_x32_get(void *data, u64 *val)
  345. {
  346. struct wil_debugfs_iomem_data *d = (struct
  347. wil_debugfs_iomem_data *)data;
  348. struct wil6210_priv *wil = d->wil;
  349. int ret;
  350. ret = wil_pm_runtime_get(wil);
  351. if (ret < 0)
  352. return ret;
  353. *val = readl((void __iomem *)d->offset);
  354. wil_pm_runtime_put(wil);
  355. return 0;
  356. }
  357. DEFINE_SIMPLE_ATTRIBUTE(fops_iomem_x32, wil_debugfs_iomem_x32_get,
  358. wil_debugfs_iomem_x32_set, "0x%08llx\n");
  359. static struct dentry *wil_debugfs_create_iomem_x32(const char *name,
  360. umode_t mode,
  361. struct dentry *parent,
  362. void *value,
  363. struct wil6210_priv *wil)
  364. {
  365. struct dentry *file;
  366. struct wil_debugfs_iomem_data *data = &wil->dbg_data.data_arr[
  367. wil->dbg_data.iomem_data_count];
  368. data->wil = wil;
  369. data->offset = value;
  370. file = debugfs_create_file(name, mode, parent, data, &fops_iomem_x32);
  371. if (!IS_ERR_OR_NULL(file))
  372. wil->dbg_data.iomem_data_count++;
  373. return file;
  374. }
  375. static int wil_debugfs_ulong_set(void *data, u64 val)
  376. {
  377. *(ulong *)data = val;
  378. return 0;
  379. }
  380. static int wil_debugfs_ulong_get(void *data, u64 *val)
  381. {
  382. *val = *(ulong *)data;
  383. return 0;
  384. }
  385. DEFINE_SIMPLE_ATTRIBUTE(wil_fops_ulong, wil_debugfs_ulong_get,
  386. wil_debugfs_ulong_set, "0x%llx\n");
  387. static struct dentry *wil_debugfs_create_ulong(const char *name, umode_t mode,
  388. struct dentry *parent,
  389. ulong *value)
  390. {
  391. return debugfs_create_file(name, mode, parent, value, &wil_fops_ulong);
  392. }
  393. /**
  394. * wil6210_debugfs_init_offset - create set of debugfs files
  395. * @wil - driver's context, used for printing
  396. * @dbg - directory on the debugfs, where files will be created
  397. * @base - base address used in address calculation
  398. * @tbl - table with file descriptions. Should be terminated with empty element.
  399. *
  400. * Creates files accordingly to the @tbl.
  401. */
  402. static void wil6210_debugfs_init_offset(struct wil6210_priv *wil,
  403. struct dentry *dbg, void *base,
  404. const struct dbg_off * const tbl)
  405. {
  406. int i;
  407. for (i = 0; tbl[i].name; i++) {
  408. struct dentry *f;
  409. switch (tbl[i].type) {
  410. case doff_u32:
  411. f = debugfs_create_u32(tbl[i].name, tbl[i].mode, dbg,
  412. base + tbl[i].off);
  413. break;
  414. case doff_x32:
  415. f = debugfs_create_x32(tbl[i].name, tbl[i].mode, dbg,
  416. base + tbl[i].off);
  417. break;
  418. case doff_ulong:
  419. f = wil_debugfs_create_ulong(tbl[i].name, tbl[i].mode,
  420. dbg, base + tbl[i].off);
  421. break;
  422. case doff_io32:
  423. f = wil_debugfs_create_iomem_x32(tbl[i].name,
  424. tbl[i].mode, dbg,
  425. base + tbl[i].off,
  426. wil);
  427. break;
  428. case doff_u8:
  429. f = debugfs_create_u8(tbl[i].name, tbl[i].mode, dbg,
  430. base + tbl[i].off);
  431. break;
  432. default:
  433. f = ERR_PTR(-EINVAL);
  434. }
  435. if (IS_ERR_OR_NULL(f))
  436. wil_err(wil, "Create file \"%s\": err %ld\n",
  437. tbl[i].name, PTR_ERR(f));
  438. }
  439. }
  440. static const struct dbg_off isr_off[] = {
  441. {"ICC", 0644, offsetof(struct RGF_ICR, ICC), doff_io32},
  442. {"ICR", 0644, offsetof(struct RGF_ICR, ICR), doff_io32},
  443. {"ICM", 0644, offsetof(struct RGF_ICR, ICM), doff_io32},
  444. {"ICS", 0244, offsetof(struct RGF_ICR, ICS), doff_io32},
  445. {"IMV", 0644, offsetof(struct RGF_ICR, IMV), doff_io32},
  446. {"IMS", 0244, offsetof(struct RGF_ICR, IMS), doff_io32},
  447. {"IMC", 0244, offsetof(struct RGF_ICR, IMC), doff_io32},
  448. {},
  449. };
  450. static int wil6210_debugfs_create_ISR(struct wil6210_priv *wil,
  451. const char *name,
  452. struct dentry *parent, u32 off)
  453. {
  454. struct dentry *d = debugfs_create_dir(name, parent);
  455. if (IS_ERR_OR_NULL(d))
  456. return -ENODEV;
  457. wil6210_debugfs_init_offset(wil, d, (void * __force)wil->csr + off,
  458. isr_off);
  459. return 0;
  460. }
  461. static const struct dbg_off pseudo_isr_off[] = {
  462. {"CAUSE", 0444, HOSTADDR(RGF_DMA_PSEUDO_CAUSE), doff_io32},
  463. {"MASK_SW", 0444, HOSTADDR(RGF_DMA_PSEUDO_CAUSE_MASK_SW), doff_io32},
  464. {"MASK_FW", 0444, HOSTADDR(RGF_DMA_PSEUDO_CAUSE_MASK_FW), doff_io32},
  465. {},
  466. };
  467. static int wil6210_debugfs_create_pseudo_ISR(struct wil6210_priv *wil,
  468. struct dentry *parent)
  469. {
  470. struct dentry *d = debugfs_create_dir("PSEUDO_ISR", parent);
  471. if (IS_ERR_OR_NULL(d))
  472. return -ENODEV;
  473. wil6210_debugfs_init_offset(wil, d, (void * __force)wil->csr,
  474. pseudo_isr_off);
  475. return 0;
  476. }
  477. static const struct dbg_off lgc_itr_cnt_off[] = {
  478. {"TRSH", 0644, HOSTADDR(RGF_DMA_ITR_CNT_TRSH), doff_io32},
  479. {"DATA", 0644, HOSTADDR(RGF_DMA_ITR_CNT_DATA), doff_io32},
  480. {"CTL", 0644, HOSTADDR(RGF_DMA_ITR_CNT_CRL), doff_io32},
  481. {},
  482. };
  483. static const struct dbg_off tx_itr_cnt_off[] = {
  484. {"TRSH", 0644, HOSTADDR(RGF_DMA_ITR_TX_CNT_TRSH),
  485. doff_io32},
  486. {"DATA", 0644, HOSTADDR(RGF_DMA_ITR_TX_CNT_DATA),
  487. doff_io32},
  488. {"CTL", 0644, HOSTADDR(RGF_DMA_ITR_TX_CNT_CTL),
  489. doff_io32},
  490. {"IDL_TRSH", 0644, HOSTADDR(RGF_DMA_ITR_TX_IDL_CNT_TRSH),
  491. doff_io32},
  492. {"IDL_DATA", 0644, HOSTADDR(RGF_DMA_ITR_TX_IDL_CNT_DATA),
  493. doff_io32},
  494. {"IDL_CTL", 0644, HOSTADDR(RGF_DMA_ITR_TX_IDL_CNT_CTL),
  495. doff_io32},
  496. {},
  497. };
  498. static const struct dbg_off rx_itr_cnt_off[] = {
  499. {"TRSH", 0644, HOSTADDR(RGF_DMA_ITR_RX_CNT_TRSH),
  500. doff_io32},
  501. {"DATA", 0644, HOSTADDR(RGF_DMA_ITR_RX_CNT_DATA),
  502. doff_io32},
  503. {"CTL", 0644, HOSTADDR(RGF_DMA_ITR_RX_CNT_CTL),
  504. doff_io32},
  505. {"IDL_TRSH", 0644, HOSTADDR(RGF_DMA_ITR_RX_IDL_CNT_TRSH),
  506. doff_io32},
  507. {"IDL_DATA", 0644, HOSTADDR(RGF_DMA_ITR_RX_IDL_CNT_DATA),
  508. doff_io32},
  509. {"IDL_CTL", 0644, HOSTADDR(RGF_DMA_ITR_RX_IDL_CNT_CTL),
  510. doff_io32},
  511. {},
  512. };
  513. static int wil6210_debugfs_create_ITR_CNT(struct wil6210_priv *wil,
  514. struct dentry *parent)
  515. {
  516. struct dentry *d, *dtx, *drx;
  517. d = debugfs_create_dir("ITR_CNT", parent);
  518. if (IS_ERR_OR_NULL(d))
  519. return -ENODEV;
  520. dtx = debugfs_create_dir("TX", d);
  521. drx = debugfs_create_dir("RX", d);
  522. if (IS_ERR_OR_NULL(dtx) || IS_ERR_OR_NULL(drx))
  523. return -ENODEV;
  524. wil6210_debugfs_init_offset(wil, d, (void * __force)wil->csr,
  525. lgc_itr_cnt_off);
  526. wil6210_debugfs_init_offset(wil, dtx, (void * __force)wil->csr,
  527. tx_itr_cnt_off);
  528. wil6210_debugfs_init_offset(wil, drx, (void * __force)wil->csr,
  529. rx_itr_cnt_off);
  530. return 0;
  531. }
  532. static int wil_memread_debugfs_show(struct seq_file *s, void *data)
  533. {
  534. struct wil6210_priv *wil = s->private;
  535. void __iomem *a;
  536. int ret;
  537. ret = wil_pm_runtime_get(wil);
  538. if (ret < 0)
  539. return ret;
  540. a = wmi_buffer(wil, cpu_to_le32(mem_addr));
  541. if (a)
  542. seq_printf(s, "[0x%08x] = 0x%08x\n", mem_addr, readl(a));
  543. else
  544. seq_printf(s, "[0x%08x] = INVALID\n", mem_addr);
  545. wil_pm_runtime_put(wil);
  546. return 0;
  547. }
  548. static int wil_memread_seq_open(struct inode *inode, struct file *file)
  549. {
  550. return single_open(file, wil_memread_debugfs_show, inode->i_private);
  551. }
  552. static const struct file_operations fops_memread = {
  553. .open = wil_memread_seq_open,
  554. .release = single_release,
  555. .read = seq_read,
  556. .llseek = seq_lseek,
  557. };
  558. static ssize_t wil_read_file_ioblob(struct file *file, char __user *user_buf,
  559. size_t count, loff_t *ppos)
  560. {
  561. enum { max_count = 4096 };
  562. struct wil_blob_wrapper *wil_blob = file->private_data;
  563. struct wil6210_priv *wil = wil_blob->wil;
  564. loff_t pos = *ppos;
  565. size_t available = wil_blob->blob.size;
  566. void *buf;
  567. size_t ret;
  568. int rc;
  569. if (test_bit(wil_status_suspending, wil_blob->wil->status) ||
  570. test_bit(wil_status_suspended, wil_blob->wil->status))
  571. return 0;
  572. if (pos < 0)
  573. return -EINVAL;
  574. if (pos >= available || !count)
  575. return 0;
  576. if (count > available - pos)
  577. count = available - pos;
  578. if (count > max_count)
  579. count = max_count;
  580. buf = kmalloc(count, GFP_KERNEL);
  581. if (!buf)
  582. return -ENOMEM;
  583. rc = wil_pm_runtime_get(wil);
  584. if (rc < 0) {
  585. kfree(buf);
  586. return rc;
  587. }
  588. wil_memcpy_fromio_32(buf, (const void __iomem *)
  589. wil_blob->blob.data + pos, count);
  590. ret = copy_to_user(user_buf, buf, count);
  591. wil_pm_runtime_put(wil);
  592. kfree(buf);
  593. if (ret == count)
  594. return -EFAULT;
  595. count -= ret;
  596. *ppos = pos + count;
  597. return count;
  598. }
  599. static const struct file_operations fops_ioblob = {
  600. .read = wil_read_file_ioblob,
  601. .open = simple_open,
  602. .llseek = default_llseek,
  603. };
  604. static
  605. struct dentry *wil_debugfs_create_ioblob(const char *name,
  606. umode_t mode,
  607. struct dentry *parent,
  608. struct wil_blob_wrapper *wil_blob)
  609. {
  610. return debugfs_create_file(name, mode, parent, wil_blob, &fops_ioblob);
  611. }
  612. /*---reset---*/
  613. static ssize_t wil_write_file_reset(struct file *file, const char __user *buf,
  614. size_t len, loff_t *ppos)
  615. {
  616. struct wil6210_priv *wil = file->private_data;
  617. struct net_device *ndev = wil->main_ndev;
  618. /**
  619. * BUG:
  620. * this code does NOT sync device state with the rest of system
  621. * use with care, debug only!!!
  622. */
  623. rtnl_lock();
  624. dev_close(ndev);
  625. ndev->flags &= ~IFF_UP;
  626. rtnl_unlock();
  627. wil_reset(wil, true);
  628. return len;
  629. }
  630. static const struct file_operations fops_reset = {
  631. .write = wil_write_file_reset,
  632. .open = simple_open,
  633. };
  634. /*---write channel 1..4 to rxon for it, 0 to rxoff---*/
  635. static ssize_t wil_write_file_rxon(struct file *file, const char __user *buf,
  636. size_t len, loff_t *ppos)
  637. {
  638. struct wil6210_priv *wil = file->private_data;
  639. int rc;
  640. long channel;
  641. bool on;
  642. char *kbuf = memdup_user_nul(buf, len);
  643. if (IS_ERR(kbuf))
  644. return PTR_ERR(kbuf);
  645. rc = kstrtol(kbuf, 0, &channel);
  646. kfree(kbuf);
  647. if (rc)
  648. return rc;
  649. if ((channel < 0) || (channel > 4)) {
  650. wil_err(wil, "Invalid channel %ld\n", channel);
  651. return -EINVAL;
  652. }
  653. on = !!channel;
  654. if (on) {
  655. rc = wmi_set_channel(wil, (int)channel);
  656. if (rc)
  657. return rc;
  658. }
  659. rc = wmi_rxon(wil, on);
  660. if (rc)
  661. return rc;
  662. return len;
  663. }
  664. static const struct file_operations fops_rxon = {
  665. .write = wil_write_file_rxon,
  666. .open = simple_open,
  667. };
  668. /* block ack control, write:
  669. * - "add <ringid> <agg_size> <timeout>" to trigger ADDBA
  670. * - "del_tx <ringid> <reason>" to trigger DELBA for Tx side
  671. * - "del_rx <CID> <TID> <reason>" to trigger DELBA for Rx side
  672. */
  673. static ssize_t wil_write_back(struct file *file, const char __user *buf,
  674. size_t len, loff_t *ppos)
  675. {
  676. struct wil6210_priv *wil = file->private_data;
  677. int rc;
  678. char *kbuf = kmalloc(len + 1, GFP_KERNEL);
  679. char cmd[9];
  680. int p1, p2, p3;
  681. if (!kbuf)
  682. return -ENOMEM;
  683. rc = simple_write_to_buffer(kbuf, len, ppos, buf, len);
  684. if (rc != len) {
  685. kfree(kbuf);
  686. return rc >= 0 ? -EIO : rc;
  687. }
  688. kbuf[len] = '\0';
  689. rc = sscanf(kbuf, "%8s %d %d %d", cmd, &p1, &p2, &p3);
  690. kfree(kbuf);
  691. if (rc < 0)
  692. return rc;
  693. if (rc < 2)
  694. return -EINVAL;
  695. if ((strcmp(cmd, "add") == 0) ||
  696. (strcmp(cmd, "del_tx") == 0)) {
  697. struct wil_ring_tx_data *txdata;
  698. if (p1 < 0 || p1 >= WIL6210_MAX_TX_RINGS) {
  699. wil_err(wil, "BACK: invalid ring id %d\n", p1);
  700. return -EINVAL;
  701. }
  702. txdata = &wil->ring_tx_data[p1];
  703. if (strcmp(cmd, "add") == 0) {
  704. if (rc < 3) {
  705. wil_err(wil, "BACK: add require at least 2 params\n");
  706. return -EINVAL;
  707. }
  708. if (rc < 4)
  709. p3 = 0;
  710. wmi_addba(wil, txdata->mid, p1, p2, p3);
  711. } else {
  712. if (rc < 3)
  713. p2 = WLAN_REASON_QSTA_LEAVE_QBSS;
  714. wmi_delba_tx(wil, txdata->mid, p1, p2);
  715. }
  716. } else if (strcmp(cmd, "del_rx") == 0) {
  717. struct wil_sta_info *sta;
  718. if (rc < 3) {
  719. wil_err(wil,
  720. "BACK: del_rx require at least 2 params\n");
  721. return -EINVAL;
  722. }
  723. if (p1 < 0 || p1 >= WIL6210_MAX_CID) {
  724. wil_err(wil, "BACK: invalid CID %d\n", p1);
  725. return -EINVAL;
  726. }
  727. if (rc < 4)
  728. p3 = WLAN_REASON_QSTA_LEAVE_QBSS;
  729. sta = &wil->sta[p1];
  730. wmi_delba_rx(wil, sta->mid, mk_cidxtid(p1, p2), p3);
  731. } else {
  732. wil_err(wil, "BACK: Unrecognized command \"%s\"\n", cmd);
  733. return -EINVAL;
  734. }
  735. return len;
  736. }
  737. static ssize_t wil_read_back(struct file *file, char __user *user_buf,
  738. size_t count, loff_t *ppos)
  739. {
  740. static const char text[] = "block ack control, write:\n"
  741. " - \"add <ringid> <agg_size> <timeout>\" to trigger ADDBA\n"
  742. "If missing, <timeout> defaults to 0\n"
  743. " - \"del_tx <ringid> <reason>\" to trigger DELBA for Tx side\n"
  744. " - \"del_rx <CID> <TID> <reason>\" to trigger DELBA for Rx side\n"
  745. "If missing, <reason> set to \"STA_LEAVING\" (36)\n";
  746. return simple_read_from_buffer(user_buf, count, ppos, text,
  747. sizeof(text));
  748. }
  749. static const struct file_operations fops_back = {
  750. .read = wil_read_back,
  751. .write = wil_write_back,
  752. .open = simple_open,
  753. };
  754. /* pmc control, write:
  755. * - "alloc <num descriptors> <descriptor_size>" to allocate PMC
  756. * - "free" to release memory allocated for PMC
  757. */
  758. static ssize_t wil_write_pmccfg(struct file *file, const char __user *buf,
  759. size_t len, loff_t *ppos)
  760. {
  761. struct wil6210_priv *wil = file->private_data;
  762. int rc;
  763. char *kbuf = kmalloc(len + 1, GFP_KERNEL);
  764. char cmd[9];
  765. int num_descs, desc_size;
  766. if (!kbuf)
  767. return -ENOMEM;
  768. rc = simple_write_to_buffer(kbuf, len, ppos, buf, len);
  769. if (rc != len) {
  770. kfree(kbuf);
  771. return rc >= 0 ? -EIO : rc;
  772. }
  773. kbuf[len] = '\0';
  774. rc = sscanf(kbuf, "%8s %d %d", cmd, &num_descs, &desc_size);
  775. kfree(kbuf);
  776. if (rc < 0)
  777. return rc;
  778. if (rc < 1) {
  779. wil_err(wil, "pmccfg: no params given\n");
  780. return -EINVAL;
  781. }
  782. if (0 == strcmp(cmd, "alloc")) {
  783. if (rc != 3) {
  784. wil_err(wil, "pmccfg: alloc requires 2 params\n");
  785. return -EINVAL;
  786. }
  787. wil_pmc_alloc(wil, num_descs, desc_size);
  788. } else if (0 == strcmp(cmd, "free")) {
  789. if (rc != 1) {
  790. wil_err(wil, "pmccfg: free does not have any params\n");
  791. return -EINVAL;
  792. }
  793. wil_pmc_free(wil, true);
  794. } else {
  795. wil_err(wil, "pmccfg: Unrecognized command \"%s\"\n", cmd);
  796. return -EINVAL;
  797. }
  798. return len;
  799. }
  800. static ssize_t wil_read_pmccfg(struct file *file, char __user *user_buf,
  801. size_t count, loff_t *ppos)
  802. {
  803. struct wil6210_priv *wil = file->private_data;
  804. char text[256];
  805. char help[] = "pmc control, write:\n"
  806. " - \"alloc <num descriptors> <descriptor_size>\" to allocate pmc\n"
  807. " - \"free\" to free memory allocated for pmc\n";
  808. sprintf(text, "Last command status: %d\n\n%s",
  809. wil_pmc_last_cmd_status(wil),
  810. help);
  811. return simple_read_from_buffer(user_buf, count, ppos, text,
  812. strlen(text) + 1);
  813. }
  814. static const struct file_operations fops_pmccfg = {
  815. .read = wil_read_pmccfg,
  816. .write = wil_write_pmccfg,
  817. .open = simple_open,
  818. };
  819. static const struct file_operations fops_pmcdata = {
  820. .open = simple_open,
  821. .read = wil_pmc_read,
  822. .llseek = wil_pmc_llseek,
  823. };
  824. /*---tx_mgmt---*/
  825. /* Write mgmt frame to this file to send it */
  826. static ssize_t wil_write_file_txmgmt(struct file *file, const char __user *buf,
  827. size_t len, loff_t *ppos)
  828. {
  829. struct wil6210_priv *wil = file->private_data;
  830. struct wiphy *wiphy = wil_to_wiphy(wil);
  831. struct wireless_dev *wdev = wil->main_ndev->ieee80211_ptr;
  832. struct cfg80211_mgmt_tx_params params;
  833. int rc;
  834. void *frame;
  835. if (!len)
  836. return -EINVAL;
  837. frame = memdup_user(buf, len);
  838. if (IS_ERR(frame))
  839. return PTR_ERR(frame);
  840. params.buf = frame;
  841. params.len = len;
  842. rc = wil_cfg80211_mgmt_tx(wiphy, wdev, &params, NULL);
  843. kfree(frame);
  844. wil_info(wil, "-> %d\n", rc);
  845. return len;
  846. }
  847. static const struct file_operations fops_txmgmt = {
  848. .write = wil_write_file_txmgmt,
  849. .open = simple_open,
  850. };
  851. /* Write WMI command (w/o mbox header) to this file to send it
  852. * WMI starts from wil6210_mbox_hdr_wmi header
  853. */
  854. static ssize_t wil_write_file_wmi(struct file *file, const char __user *buf,
  855. size_t len, loff_t *ppos)
  856. {
  857. struct wil6210_priv *wil = file->private_data;
  858. struct wil6210_vif *vif = ndev_to_vif(wil->main_ndev);
  859. struct wmi_cmd_hdr *wmi;
  860. void *cmd;
  861. int cmdlen = len - sizeof(struct wmi_cmd_hdr);
  862. u16 cmdid;
  863. int rc, rc1;
  864. if (cmdlen < 0)
  865. return -EINVAL;
  866. wmi = kmalloc(len, GFP_KERNEL);
  867. if (!wmi)
  868. return -ENOMEM;
  869. rc = simple_write_to_buffer(wmi, len, ppos, buf, len);
  870. if (rc < 0) {
  871. kfree(wmi);
  872. return rc;
  873. }
  874. cmd = (cmdlen > 0) ? &wmi[1] : NULL;
  875. cmdid = le16_to_cpu(wmi->command_id);
  876. rc1 = wmi_send(wil, cmdid, vif->mid, cmd, cmdlen);
  877. kfree(wmi);
  878. wil_info(wil, "0x%04x[%d] -> %d\n", cmdid, cmdlen, rc1);
  879. return rc;
  880. }
  881. static const struct file_operations fops_wmi = {
  882. .write = wil_write_file_wmi,
  883. .open = simple_open,
  884. };
  885. static void wil_seq_print_skb(struct seq_file *s, struct sk_buff *skb)
  886. {
  887. int i = 0;
  888. int len = skb_headlen(skb);
  889. void *p = skb->data;
  890. int nr_frags = skb_shinfo(skb)->nr_frags;
  891. seq_printf(s, " len = %d\n", len);
  892. wil_seq_hexdump(s, p, len, " : ");
  893. if (nr_frags) {
  894. seq_printf(s, " nr_frags = %d\n", nr_frags);
  895. for (i = 0; i < nr_frags; i++) {
  896. const struct skb_frag_struct *frag =
  897. &skb_shinfo(skb)->frags[i];
  898. len = skb_frag_size(frag);
  899. p = skb_frag_address_safe(frag);
  900. seq_printf(s, " [%2d] : len = %d\n", i, len);
  901. wil_seq_hexdump(s, p, len, " : ");
  902. }
  903. }
  904. }
  905. /*---------Tx/Rx descriptor------------*/
  906. static int wil_txdesc_debugfs_show(struct seq_file *s, void *data)
  907. {
  908. struct wil6210_priv *wil = s->private;
  909. struct wil_ring *ring;
  910. bool tx;
  911. int ring_idx = dbg_ring_index;
  912. int txdesc_idx = dbg_txdesc_index;
  913. volatile struct vring_tx_desc *d;
  914. volatile u32 *u;
  915. struct sk_buff *skb;
  916. if (wil->use_enhanced_dma_hw) {
  917. /* RX ring index == 0 */
  918. if (ring_idx >= WIL6210_MAX_TX_RINGS) {
  919. seq_printf(s, "invalid ring index %d\n", ring_idx);
  920. return 0;
  921. }
  922. tx = ring_idx > 0; /* desc ring 0 is reserved for RX */
  923. } else {
  924. /* RX ring index == WIL6210_MAX_TX_RINGS */
  925. if (ring_idx > WIL6210_MAX_TX_RINGS) {
  926. seq_printf(s, "invalid ring index %d\n", ring_idx);
  927. return 0;
  928. }
  929. tx = (ring_idx < WIL6210_MAX_TX_RINGS);
  930. }
  931. ring = tx ? &wil->ring_tx[ring_idx] : &wil->ring_rx;
  932. if (!ring->va) {
  933. if (tx)
  934. seq_printf(s, "No Tx[%2d] RING\n", ring_idx);
  935. else
  936. seq_puts(s, "No Rx RING\n");
  937. return 0;
  938. }
  939. if (txdesc_idx >= ring->size) {
  940. if (tx)
  941. seq_printf(s, "[%2d] TxDesc index (%d) >= size (%d)\n",
  942. ring_idx, txdesc_idx, ring->size);
  943. else
  944. seq_printf(s, "RxDesc index (%d) >= size (%d)\n",
  945. txdesc_idx, ring->size);
  946. return 0;
  947. }
  948. /* use struct vring_tx_desc for Rx as well,
  949. * only field used, .dma.length, is the same
  950. */
  951. d = &ring->va[txdesc_idx].tx.legacy;
  952. u = (volatile u32 *)d;
  953. skb = NULL;
  954. if (wil->use_enhanced_dma_hw) {
  955. if (tx) {
  956. skb = ring->ctx[txdesc_idx].skb;
  957. } else {
  958. struct wil_rx_enhanced_desc *rx_d =
  959. (struct wil_rx_enhanced_desc *)
  960. &ring->va[txdesc_idx].rx.enhanced;
  961. u16 buff_id = le16_to_cpu(rx_d->mac.buff_id);
  962. if (!wil_val_in_range(buff_id, 0,
  963. wil->rx_buff_mgmt.size)) {
  964. seq_printf(s, "invalid buff_id %d\n", buff_id);
  965. return 0;
  966. }
  967. skb = wil->rx_buff_mgmt.buff_arr[buff_id].skb;
  968. }
  969. } else {
  970. skb = ring->ctx[txdesc_idx].skb;
  971. }
  972. if (tx)
  973. seq_printf(s, "Tx[%2d][%3d] = {\n", ring_idx,
  974. txdesc_idx);
  975. else
  976. seq_printf(s, "Rx[%3d] = {\n", txdesc_idx);
  977. seq_printf(s, " MAC = 0x%08x 0x%08x 0x%08x 0x%08x\n",
  978. u[0], u[1], u[2], u[3]);
  979. seq_printf(s, " DMA = 0x%08x 0x%08x 0x%08x 0x%08x\n",
  980. u[4], u[5], u[6], u[7]);
  981. seq_printf(s, " SKB = 0x%p\n", skb);
  982. if (skb) {
  983. skb_get(skb);
  984. wil_seq_print_skb(s, skb);
  985. kfree_skb(skb);
  986. }
  987. seq_puts(s, "}\n");
  988. return 0;
  989. }
  990. static int wil_txdesc_seq_open(struct inode *inode, struct file *file)
  991. {
  992. return single_open(file, wil_txdesc_debugfs_show, inode->i_private);
  993. }
  994. static const struct file_operations fops_txdesc = {
  995. .open = wil_txdesc_seq_open,
  996. .release = single_release,
  997. .read = seq_read,
  998. .llseek = seq_lseek,
  999. };
  1000. /*---------Tx/Rx status message------------*/
  1001. static int wil_status_msg_debugfs_show(struct seq_file *s, void *data)
  1002. {
  1003. struct wil6210_priv *wil = s->private;
  1004. int sring_idx = dbg_sring_index;
  1005. struct wil_status_ring *sring;
  1006. bool tx = sring_idx == wil->tx_sring_idx ? 1 : 0;
  1007. u32 status_msg_idx = dbg_status_msg_index;
  1008. u32 *u;
  1009. if (sring_idx >= WIL6210_MAX_STATUS_RINGS) {
  1010. seq_printf(s, "invalid status ring index %d\n", sring_idx);
  1011. return 0;
  1012. }
  1013. sring = &wil->srings[sring_idx];
  1014. if (!sring->va) {
  1015. seq_printf(s, "No %cX status ring\n", tx ? 'T' : 'R');
  1016. return 0;
  1017. }
  1018. if (status_msg_idx >= sring->size) {
  1019. seq_printf(s, "%cxDesc index (%d) >= size (%d)\n",
  1020. tx ? 'T' : 'R', status_msg_idx, sring->size);
  1021. return 0;
  1022. }
  1023. u = sring->va + (sring->elem_size * status_msg_idx);
  1024. seq_printf(s, "%cx[%d][%3d] = {\n",
  1025. tx ? 'T' : 'R', sring_idx, status_msg_idx);
  1026. seq_printf(s, " 0x%08x 0x%08x 0x%08x 0x%08x\n",
  1027. u[0], u[1], u[2], u[3]);
  1028. if (!tx && !wil->use_compressed_rx_status)
  1029. seq_printf(s, " 0x%08x 0x%08x 0x%08x 0x%08x\n",
  1030. u[4], u[5], u[6], u[7]);
  1031. seq_puts(s, "}\n");
  1032. return 0;
  1033. }
  1034. static int wil_status_msg_seq_open(struct inode *inode, struct file *file)
  1035. {
  1036. return single_open(file, wil_status_msg_debugfs_show,
  1037. inode->i_private);
  1038. }
  1039. static const struct file_operations fops_status_msg = {
  1040. .open = wil_status_msg_seq_open,
  1041. .release = single_release,
  1042. .read = seq_read,
  1043. .llseek = seq_lseek,
  1044. };
  1045. static int wil_print_rx_buff(struct seq_file *s, struct list_head *lh)
  1046. {
  1047. struct wil_rx_buff *it;
  1048. int i = 0;
  1049. list_for_each_entry(it, lh, list) {
  1050. if ((i % 16) == 0 && i != 0)
  1051. seq_puts(s, "\n ");
  1052. seq_printf(s, "[%4d] ", it->id);
  1053. i++;
  1054. }
  1055. seq_printf(s, "\nNumber of buffers: %u\n", i);
  1056. return i;
  1057. }
  1058. static int wil_rx_buff_mgmt_debugfs_show(struct seq_file *s, void *data)
  1059. {
  1060. struct wil6210_priv *wil = s->private;
  1061. struct wil_rx_buff_mgmt *rbm = &wil->rx_buff_mgmt;
  1062. int num_active;
  1063. int num_free;
  1064. seq_printf(s, " size = %zu\n", rbm->size);
  1065. seq_printf(s, " free_list_empty_cnt = %lu\n",
  1066. rbm->free_list_empty_cnt);
  1067. /* Print active list */
  1068. seq_puts(s, " Active list:\n");
  1069. num_active = wil_print_rx_buff(s, &rbm->active);
  1070. seq_puts(s, "\n Free list:\n");
  1071. num_free = wil_print_rx_buff(s, &rbm->free);
  1072. seq_printf(s, " Total number of buffers: %u\n",
  1073. num_active + num_free);
  1074. return 0;
  1075. }
  1076. static int wil_rx_buff_mgmt_seq_open(struct inode *inode, struct file *file)
  1077. {
  1078. return single_open(file, wil_rx_buff_mgmt_debugfs_show,
  1079. inode->i_private);
  1080. }
  1081. static const struct file_operations fops_rx_buff_mgmt = {
  1082. .open = wil_rx_buff_mgmt_seq_open,
  1083. .release = single_release,
  1084. .read = seq_read,
  1085. .llseek = seq_lseek,
  1086. };
  1087. /*---------beamforming------------*/
  1088. static char *wil_bfstatus_str(u32 status)
  1089. {
  1090. switch (status) {
  1091. case 0:
  1092. return "Failed";
  1093. case 1:
  1094. return "OK";
  1095. case 2:
  1096. return "Retrying";
  1097. default:
  1098. return "??";
  1099. }
  1100. }
  1101. static bool is_all_zeros(void * const x_, size_t sz)
  1102. {
  1103. /* if reply is all-0, ignore this CID */
  1104. u32 *x = x_;
  1105. int n;
  1106. for (n = 0; n < sz / sizeof(*x); n++)
  1107. if (x[n])
  1108. return false;
  1109. return true;
  1110. }
  1111. static int wil_bf_debugfs_show(struct seq_file *s, void *data)
  1112. {
  1113. int rc;
  1114. int i;
  1115. struct wil6210_priv *wil = s->private;
  1116. struct wil6210_vif *vif = ndev_to_vif(wil->main_ndev);
  1117. struct wmi_notify_req_cmd cmd = {
  1118. .interval_usec = 0,
  1119. };
  1120. struct {
  1121. struct wmi_cmd_hdr wmi;
  1122. struct wmi_notify_req_done_event evt;
  1123. } __packed reply;
  1124. memset(&reply, 0, sizeof(reply));
  1125. for (i = 0; i < ARRAY_SIZE(wil->sta); i++) {
  1126. u32 status;
  1127. cmd.cid = i;
  1128. rc = wmi_call(wil, WMI_NOTIFY_REQ_CMDID, vif->mid,
  1129. &cmd, sizeof(cmd),
  1130. WMI_NOTIFY_REQ_DONE_EVENTID, &reply,
  1131. sizeof(reply), 20);
  1132. /* if reply is all-0, ignore this CID */
  1133. if (rc || is_all_zeros(&reply.evt, sizeof(reply.evt)))
  1134. continue;
  1135. status = le32_to_cpu(reply.evt.status);
  1136. seq_printf(s, "CID %d {\n"
  1137. " TSF = 0x%016llx\n"
  1138. " TxMCS = %2d TxTpt = %4d\n"
  1139. " SQI = %4d\n"
  1140. " RSSI = %4d\n"
  1141. " Status = 0x%08x %s\n"
  1142. " Sectors(rx:tx) my %2d:%2d peer %2d:%2d\n"
  1143. " Goodput(rx:tx) %4d:%4d\n"
  1144. "}\n",
  1145. i,
  1146. le64_to_cpu(reply.evt.tsf),
  1147. le16_to_cpu(reply.evt.bf_mcs),
  1148. le32_to_cpu(reply.evt.tx_tpt),
  1149. reply.evt.sqi,
  1150. reply.evt.rssi,
  1151. status, wil_bfstatus_str(status),
  1152. le16_to_cpu(reply.evt.my_rx_sector),
  1153. le16_to_cpu(reply.evt.my_tx_sector),
  1154. le16_to_cpu(reply.evt.other_rx_sector),
  1155. le16_to_cpu(reply.evt.other_tx_sector),
  1156. le32_to_cpu(reply.evt.rx_goodput),
  1157. le32_to_cpu(reply.evt.tx_goodput));
  1158. }
  1159. return 0;
  1160. }
  1161. static int wil_bf_seq_open(struct inode *inode, struct file *file)
  1162. {
  1163. return single_open(file, wil_bf_debugfs_show, inode->i_private);
  1164. }
  1165. static const struct file_operations fops_bf = {
  1166. .open = wil_bf_seq_open,
  1167. .release = single_release,
  1168. .read = seq_read,
  1169. .llseek = seq_lseek,
  1170. };
  1171. /*---------temp------------*/
  1172. static void print_temp(struct seq_file *s, const char *prefix, s32 t)
  1173. {
  1174. switch (t) {
  1175. case 0:
  1176. case ~(u32)0:
  1177. seq_printf(s, "%s N/A\n", prefix);
  1178. break;
  1179. default:
  1180. seq_printf(s, "%s %s%d.%03d\n", prefix, (t < 0 ? "-" : ""),
  1181. abs(t / 1000), abs(t % 1000));
  1182. break;
  1183. }
  1184. }
  1185. static int wil_temp_debugfs_show(struct seq_file *s, void *data)
  1186. {
  1187. struct wil6210_priv *wil = s->private;
  1188. s32 t_m, t_r;
  1189. int rc = wmi_get_temperature(wil, &t_m, &t_r);
  1190. if (rc) {
  1191. seq_puts(s, "Failed\n");
  1192. return 0;
  1193. }
  1194. print_temp(s, "T_mac =", t_m);
  1195. print_temp(s, "T_radio =", t_r);
  1196. return 0;
  1197. }
  1198. static int wil_temp_seq_open(struct inode *inode, struct file *file)
  1199. {
  1200. return single_open(file, wil_temp_debugfs_show, inode->i_private);
  1201. }
  1202. static const struct file_operations fops_temp = {
  1203. .open = wil_temp_seq_open,
  1204. .release = single_release,
  1205. .read = seq_read,
  1206. .llseek = seq_lseek,
  1207. };
  1208. /*---------freq------------*/
  1209. static int wil_freq_debugfs_show(struct seq_file *s, void *data)
  1210. {
  1211. struct wil6210_priv *wil = s->private;
  1212. struct wireless_dev *wdev = wil->main_ndev->ieee80211_ptr;
  1213. u16 freq = wdev->chandef.chan ? wdev->chandef.chan->center_freq : 0;
  1214. seq_printf(s, "Freq = %d\n", freq);
  1215. return 0;
  1216. }
  1217. static int wil_freq_seq_open(struct inode *inode, struct file *file)
  1218. {
  1219. return single_open(file, wil_freq_debugfs_show, inode->i_private);
  1220. }
  1221. static const struct file_operations fops_freq = {
  1222. .open = wil_freq_seq_open,
  1223. .release = single_release,
  1224. .read = seq_read,
  1225. .llseek = seq_lseek,
  1226. };
  1227. /*---------link------------*/
  1228. static int wil_link_debugfs_show(struct seq_file *s, void *data)
  1229. {
  1230. struct wil6210_priv *wil = s->private;
  1231. struct station_info *sinfo;
  1232. int i, rc = 0;
  1233. sinfo = kzalloc(sizeof(*sinfo), GFP_KERNEL);
  1234. if (!sinfo)
  1235. return -ENOMEM;
  1236. for (i = 0; i < ARRAY_SIZE(wil->sta); i++) {
  1237. struct wil_sta_info *p = &wil->sta[i];
  1238. char *status = "unknown";
  1239. struct wil6210_vif *vif;
  1240. u8 mid;
  1241. switch (p->status) {
  1242. case wil_sta_unused:
  1243. status = "unused ";
  1244. break;
  1245. case wil_sta_conn_pending:
  1246. status = "pending ";
  1247. break;
  1248. case wil_sta_connected:
  1249. status = "connected";
  1250. break;
  1251. }
  1252. mid = (p->status != wil_sta_unused) ? p->mid : U8_MAX;
  1253. seq_printf(s, "[%d][MID %d] %pM %s\n",
  1254. i, mid, p->addr, status);
  1255. if (p->status != wil_sta_connected)
  1256. continue;
  1257. vif = (mid < wil->max_vifs) ? wil->vifs[mid] : NULL;
  1258. if (vif) {
  1259. rc = wil_cid_fill_sinfo(vif, i, sinfo);
  1260. if (rc)
  1261. goto out;
  1262. seq_printf(s, " Tx_mcs = %d\n", sinfo->txrate.mcs);
  1263. seq_printf(s, " Rx_mcs = %d\n", sinfo->rxrate.mcs);
  1264. seq_printf(s, " SQ = %d\n", sinfo->signal);
  1265. } else {
  1266. seq_puts(s, " INVALID MID\n");
  1267. }
  1268. }
  1269. out:
  1270. kfree(sinfo);
  1271. return rc;
  1272. }
  1273. static int wil_link_seq_open(struct inode *inode, struct file *file)
  1274. {
  1275. return single_open(file, wil_link_debugfs_show, inode->i_private);
  1276. }
  1277. static const struct file_operations fops_link = {
  1278. .open = wil_link_seq_open,
  1279. .release = single_release,
  1280. .read = seq_read,
  1281. .llseek = seq_lseek,
  1282. };
  1283. /*---------info------------*/
  1284. static int wil_info_debugfs_show(struct seq_file *s, void *data)
  1285. {
  1286. struct wil6210_priv *wil = s->private;
  1287. struct net_device *ndev = wil->main_ndev;
  1288. int is_ac = power_supply_is_system_supplied();
  1289. int rx = atomic_xchg(&wil->isr_count_rx, 0);
  1290. int tx = atomic_xchg(&wil->isr_count_tx, 0);
  1291. static ulong rxf_old, txf_old;
  1292. ulong rxf = ndev->stats.rx_packets;
  1293. ulong txf = ndev->stats.tx_packets;
  1294. unsigned int i;
  1295. /* >0 : AC; 0 : battery; <0 : error */
  1296. seq_printf(s, "AC powered : %d\n", is_ac);
  1297. seq_printf(s, "Rx irqs:packets : %8d : %8ld\n", rx, rxf - rxf_old);
  1298. seq_printf(s, "Tx irqs:packets : %8d : %8ld\n", tx, txf - txf_old);
  1299. rxf_old = rxf;
  1300. txf_old = txf;
  1301. #define CHECK_QSTATE(x) (state & BIT(__QUEUE_STATE_ ## x)) ? \
  1302. " " __stringify(x) : ""
  1303. for (i = 0; i < ndev->num_tx_queues; i++) {
  1304. struct netdev_queue *txq = netdev_get_tx_queue(ndev, i);
  1305. unsigned long state = txq->state;
  1306. seq_printf(s, "Tx queue[%i] state : 0x%lx%s%s%s\n", i, state,
  1307. CHECK_QSTATE(DRV_XOFF),
  1308. CHECK_QSTATE(STACK_XOFF),
  1309. CHECK_QSTATE(FROZEN)
  1310. );
  1311. }
  1312. #undef CHECK_QSTATE
  1313. return 0;
  1314. }
  1315. static int wil_info_seq_open(struct inode *inode, struct file *file)
  1316. {
  1317. return single_open(file, wil_info_debugfs_show, inode->i_private);
  1318. }
  1319. static const struct file_operations fops_info = {
  1320. .open = wil_info_seq_open,
  1321. .release = single_release,
  1322. .read = seq_read,
  1323. .llseek = seq_lseek,
  1324. };
  1325. /*---------recovery------------*/
  1326. /* mode = [manual|auto]
  1327. * state = [idle|pending|running]
  1328. */
  1329. static ssize_t wil_read_file_recovery(struct file *file, char __user *user_buf,
  1330. size_t count, loff_t *ppos)
  1331. {
  1332. struct wil6210_priv *wil = file->private_data;
  1333. char buf[80];
  1334. int n;
  1335. static const char * const sstate[] = {"idle", "pending", "running"};
  1336. n = snprintf(buf, sizeof(buf), "mode = %s\nstate = %s\n",
  1337. no_fw_recovery ? "manual" : "auto",
  1338. sstate[wil->recovery_state]);
  1339. n = min_t(int, n, sizeof(buf));
  1340. return simple_read_from_buffer(user_buf, count, ppos,
  1341. buf, n);
  1342. }
  1343. static ssize_t wil_write_file_recovery(struct file *file,
  1344. const char __user *buf_,
  1345. size_t count, loff_t *ppos)
  1346. {
  1347. struct wil6210_priv *wil = file->private_data;
  1348. static const char run_command[] = "run";
  1349. char buf[sizeof(run_command) + 1]; /* to detect "runx" */
  1350. ssize_t rc;
  1351. if (wil->recovery_state != fw_recovery_pending) {
  1352. wil_err(wil, "No recovery pending\n");
  1353. return -EINVAL;
  1354. }
  1355. if (*ppos != 0) {
  1356. wil_err(wil, "Offset [%d]\n", (int)*ppos);
  1357. return -EINVAL;
  1358. }
  1359. if (count > sizeof(buf)) {
  1360. wil_err(wil, "Input too long, len = %d\n", (int)count);
  1361. return -EINVAL;
  1362. }
  1363. rc = simple_write_to_buffer(buf, sizeof(buf) - 1, ppos, buf_, count);
  1364. if (rc < 0)
  1365. return rc;
  1366. buf[rc] = '\0';
  1367. if (0 == strcmp(buf, run_command))
  1368. wil_set_recovery_state(wil, fw_recovery_running);
  1369. else
  1370. wil_err(wil, "Bad recovery command \"%s\"\n", buf);
  1371. return rc;
  1372. }
  1373. static const struct file_operations fops_recovery = {
  1374. .read = wil_read_file_recovery,
  1375. .write = wil_write_file_recovery,
  1376. .open = simple_open,
  1377. };
  1378. /*---------Station matrix------------*/
  1379. static void wil_print_rxtid(struct seq_file *s, struct wil_tid_ampdu_rx *r)
  1380. {
  1381. int i;
  1382. u16 index = ((r->head_seq_num - r->ssn) & 0xfff) % r->buf_size;
  1383. unsigned long long drop_dup = r->drop_dup, drop_old = r->drop_old;
  1384. unsigned long long drop_dup_mcast = r->drop_dup_mcast;
  1385. seq_printf(s, "([%2d]) 0x%03x [", r->buf_size, r->head_seq_num);
  1386. for (i = 0; i < r->buf_size; i++) {
  1387. if (i == index)
  1388. seq_printf(s, "%c", r->reorder_buf[i] ? 'O' : '|');
  1389. else
  1390. seq_printf(s, "%c", r->reorder_buf[i] ? '*' : '_');
  1391. }
  1392. seq_printf(s,
  1393. "] total %llu drop %llu (dup %llu + old %llu + dup mcast %llu) last 0x%03x\n",
  1394. r->total, drop_dup + drop_old + drop_dup_mcast, drop_dup,
  1395. drop_old, drop_dup_mcast, r->ssn_last_drop);
  1396. }
  1397. static void wil_print_rxtid_crypto(struct seq_file *s, int tid,
  1398. struct wil_tid_crypto_rx *c)
  1399. {
  1400. int i;
  1401. for (i = 0; i < 4; i++) {
  1402. struct wil_tid_crypto_rx_single *cc = &c->key_id[i];
  1403. if (cc->key_set)
  1404. goto has_keys;
  1405. }
  1406. return;
  1407. has_keys:
  1408. if (tid < WIL_STA_TID_NUM)
  1409. seq_printf(s, " [%2d] PN", tid);
  1410. else
  1411. seq_puts(s, " [GR] PN");
  1412. for (i = 0; i < 4; i++) {
  1413. struct wil_tid_crypto_rx_single *cc = &c->key_id[i];
  1414. seq_printf(s, " [%i%s]%6phN", i, cc->key_set ? "+" : "-",
  1415. cc->pn);
  1416. }
  1417. seq_puts(s, "\n");
  1418. }
  1419. static int wil_sta_debugfs_show(struct seq_file *s, void *data)
  1420. __acquires(&p->tid_rx_lock) __releases(&p->tid_rx_lock)
  1421. {
  1422. struct wil6210_priv *wil = s->private;
  1423. int i, tid, mcs;
  1424. for (i = 0; i < ARRAY_SIZE(wil->sta); i++) {
  1425. struct wil_sta_info *p = &wil->sta[i];
  1426. char *status = "unknown";
  1427. u8 aid = 0;
  1428. u8 mid;
  1429. switch (p->status) {
  1430. case wil_sta_unused:
  1431. status = "unused ";
  1432. break;
  1433. case wil_sta_conn_pending:
  1434. status = "pending ";
  1435. break;
  1436. case wil_sta_connected:
  1437. status = "connected";
  1438. aid = p->aid;
  1439. break;
  1440. }
  1441. mid = (p->status != wil_sta_unused) ? p->mid : U8_MAX;
  1442. seq_printf(s, "[%d] %pM %s MID %d AID %d\n", i, p->addr, status,
  1443. mid, aid);
  1444. if (p->status == wil_sta_connected) {
  1445. spin_lock_bh(&p->tid_rx_lock);
  1446. for (tid = 0; tid < WIL_STA_TID_NUM; tid++) {
  1447. struct wil_tid_ampdu_rx *r = p->tid_rx[tid];
  1448. struct wil_tid_crypto_rx *c =
  1449. &p->tid_crypto_rx[tid];
  1450. if (r) {
  1451. seq_printf(s, " [%2d] ", tid);
  1452. wil_print_rxtid(s, r);
  1453. }
  1454. wil_print_rxtid_crypto(s, tid, c);
  1455. }
  1456. wil_print_rxtid_crypto(s, WIL_STA_TID_NUM,
  1457. &p->group_crypto_rx);
  1458. spin_unlock_bh(&p->tid_rx_lock);
  1459. seq_printf(s,
  1460. "Rx invalid frame: non-data %lu, short %lu, large %lu, replay %lu\n",
  1461. p->stats.rx_non_data_frame,
  1462. p->stats.rx_short_frame,
  1463. p->stats.rx_large_frame,
  1464. p->stats.rx_replay);
  1465. seq_printf(s,
  1466. "mic error %lu, key error %lu, amsdu error %lu, csum error %lu\n",
  1467. p->stats.rx_mic_error,
  1468. p->stats.rx_key_error,
  1469. p->stats.rx_amsdu_error,
  1470. p->stats.rx_csum_err);
  1471. seq_puts(s, "Rx/MCS:");
  1472. for (mcs = 0; mcs < ARRAY_SIZE(p->stats.rx_per_mcs);
  1473. mcs++)
  1474. seq_printf(s, " %lld",
  1475. p->stats.rx_per_mcs[mcs]);
  1476. seq_puts(s, "\n");
  1477. }
  1478. }
  1479. return 0;
  1480. }
  1481. static int wil_sta_seq_open(struct inode *inode, struct file *file)
  1482. {
  1483. return single_open(file, wil_sta_debugfs_show, inode->i_private);
  1484. }
  1485. static const struct file_operations fops_sta = {
  1486. .open = wil_sta_seq_open,
  1487. .release = single_release,
  1488. .read = seq_read,
  1489. .llseek = seq_lseek,
  1490. };
  1491. static int wil_mids_debugfs_show(struct seq_file *s, void *data)
  1492. {
  1493. struct wil6210_priv *wil = s->private;
  1494. struct wil6210_vif *vif;
  1495. struct net_device *ndev;
  1496. int i;
  1497. mutex_lock(&wil->vif_mutex);
  1498. for (i = 0; i < wil->max_vifs; i++) {
  1499. vif = wil->vifs[i];
  1500. if (vif) {
  1501. ndev = vif_to_ndev(vif);
  1502. seq_printf(s, "[%d] %pM %s\n", i, ndev->dev_addr,
  1503. ndev->name);
  1504. } else {
  1505. seq_printf(s, "[%d] unused\n", i);
  1506. }
  1507. }
  1508. mutex_unlock(&wil->vif_mutex);
  1509. return 0;
  1510. }
  1511. static int wil_mids_seq_open(struct inode *inode, struct file *file)
  1512. {
  1513. return single_open(file, wil_mids_debugfs_show, inode->i_private);
  1514. }
  1515. static const struct file_operations fops_mids = {
  1516. .open = wil_mids_seq_open,
  1517. .release = single_release,
  1518. .read = seq_read,
  1519. .llseek = seq_lseek,
  1520. };
  1521. static int wil_tx_latency_debugfs_show(struct seq_file *s, void *data)
  1522. __acquires(&p->tid_rx_lock) __releases(&p->tid_rx_lock)
  1523. {
  1524. struct wil6210_priv *wil = s->private;
  1525. int i, bin;
  1526. for (i = 0; i < ARRAY_SIZE(wil->sta); i++) {
  1527. struct wil_sta_info *p = &wil->sta[i];
  1528. char *status = "unknown";
  1529. u8 aid = 0;
  1530. u8 mid;
  1531. if (!p->tx_latency_bins)
  1532. continue;
  1533. switch (p->status) {
  1534. case wil_sta_unused:
  1535. status = "unused ";
  1536. break;
  1537. case wil_sta_conn_pending:
  1538. status = "pending ";
  1539. break;
  1540. case wil_sta_connected:
  1541. status = "connected";
  1542. aid = p->aid;
  1543. break;
  1544. }
  1545. mid = (p->status != wil_sta_unused) ? p->mid : U8_MAX;
  1546. seq_printf(s, "[%d] %pM %s MID %d AID %d\n", i, p->addr, status,
  1547. mid, aid);
  1548. if (p->status == wil_sta_connected) {
  1549. u64 num_packets = 0;
  1550. u64 tx_latency_avg = p->stats.tx_latency_total_us;
  1551. seq_puts(s, "Tx/Latency bin:");
  1552. for (bin = 0; bin < WIL_NUM_LATENCY_BINS; bin++) {
  1553. seq_printf(s, " %lld",
  1554. p->tx_latency_bins[bin]);
  1555. num_packets += p->tx_latency_bins[bin];
  1556. }
  1557. seq_puts(s, "\n");
  1558. if (!num_packets)
  1559. continue;
  1560. do_div(tx_latency_avg, num_packets);
  1561. seq_printf(s, "Tx/Latency min/avg/max (us): %d/%lld/%d",
  1562. p->stats.tx_latency_min_us,
  1563. tx_latency_avg,
  1564. p->stats.tx_latency_max_us);
  1565. seq_puts(s, "\n");
  1566. }
  1567. }
  1568. return 0;
  1569. }
  1570. static int wil_tx_latency_seq_open(struct inode *inode, struct file *file)
  1571. {
  1572. return single_open(file, wil_tx_latency_debugfs_show,
  1573. inode->i_private);
  1574. }
  1575. static ssize_t wil_tx_latency_write(struct file *file, const char __user *buf,
  1576. size_t len, loff_t *ppos)
  1577. {
  1578. struct seq_file *s = file->private_data;
  1579. struct wil6210_priv *wil = s->private;
  1580. int val, rc, i;
  1581. bool enable;
  1582. rc = kstrtoint_from_user(buf, len, 0, &val);
  1583. if (rc) {
  1584. wil_err(wil, "Invalid argument\n");
  1585. return rc;
  1586. }
  1587. if (val == 1)
  1588. /* default resolution */
  1589. val = 500;
  1590. if (val && (val < 50 || val > 1000)) {
  1591. wil_err(wil, "Invalid resolution %d\n", val);
  1592. return -EINVAL;
  1593. }
  1594. enable = !!val;
  1595. if (wil->tx_latency == enable)
  1596. return len;
  1597. wil_info(wil, "%s TX latency measurements (resolution %dusec)\n",
  1598. enable ? "Enabling" : "Disabling", val);
  1599. if (enable) {
  1600. size_t sz = sizeof(u64) * WIL_NUM_LATENCY_BINS;
  1601. wil->tx_latency_res = val;
  1602. for (i = 0; i < ARRAY_SIZE(wil->sta); i++) {
  1603. struct wil_sta_info *sta = &wil->sta[i];
  1604. kfree(sta->tx_latency_bins);
  1605. sta->tx_latency_bins = kzalloc(sz, GFP_KERNEL);
  1606. if (!sta->tx_latency_bins)
  1607. return -ENOMEM;
  1608. sta->stats.tx_latency_min_us = U32_MAX;
  1609. sta->stats.tx_latency_max_us = 0;
  1610. sta->stats.tx_latency_total_us = 0;
  1611. }
  1612. }
  1613. wil->tx_latency = enable;
  1614. return len;
  1615. }
  1616. static const struct file_operations fops_tx_latency = {
  1617. .open = wil_tx_latency_seq_open,
  1618. .release = single_release,
  1619. .read = seq_read,
  1620. .write = wil_tx_latency_write,
  1621. .llseek = seq_lseek,
  1622. };
  1623. static void wil_link_stats_print_basic(struct wil6210_vif *vif,
  1624. struct seq_file *s,
  1625. struct wmi_link_stats_basic *basic)
  1626. {
  1627. char per[5] = "?";
  1628. if (basic->per_average != 0xff)
  1629. snprintf(per, sizeof(per), "%d%%", basic->per_average);
  1630. seq_printf(s, "CID %d {\n"
  1631. "\tTxMCS %d TxTpt %d\n"
  1632. "\tGoodput(rx:tx) %d:%d\n"
  1633. "\tRxBcastFrames %d\n"
  1634. "\tRSSI %d SQI %d SNR %d PER %s\n"
  1635. "\tRx RFC %d Ant num %d\n"
  1636. "\tSectors(rx:tx) my %d:%d peer %d:%d\n"
  1637. "}\n",
  1638. basic->cid,
  1639. basic->bf_mcs, le32_to_cpu(basic->tx_tpt),
  1640. le32_to_cpu(basic->rx_goodput),
  1641. le32_to_cpu(basic->tx_goodput),
  1642. le32_to_cpu(basic->rx_bcast_frames),
  1643. basic->rssi, basic->sqi, basic->snr, per,
  1644. basic->selected_rfc, basic->rx_effective_ant_num,
  1645. basic->my_rx_sector, basic->my_tx_sector,
  1646. basic->other_rx_sector, basic->other_tx_sector);
  1647. }
  1648. static void wil_link_stats_print_global(struct wil6210_priv *wil,
  1649. struct seq_file *s,
  1650. struct wmi_link_stats_global *global)
  1651. {
  1652. seq_printf(s, "Frames(rx:tx) %d:%d\n"
  1653. "BA Frames(rx:tx) %d:%d\n"
  1654. "Beacons %d\n"
  1655. "Rx Errors (MIC:CRC) %d:%d\n"
  1656. "Tx Errors (no ack) %d\n",
  1657. le32_to_cpu(global->rx_frames),
  1658. le32_to_cpu(global->tx_frames),
  1659. le32_to_cpu(global->rx_ba_frames),
  1660. le32_to_cpu(global->tx_ba_frames),
  1661. le32_to_cpu(global->tx_beacons),
  1662. le32_to_cpu(global->rx_mic_errors),
  1663. le32_to_cpu(global->rx_crc_errors),
  1664. le32_to_cpu(global->tx_fail_no_ack));
  1665. }
  1666. static void wil_link_stats_debugfs_show_vif(struct wil6210_vif *vif,
  1667. struct seq_file *s)
  1668. {
  1669. struct wil6210_priv *wil = vif_to_wil(vif);
  1670. struct wmi_link_stats_basic *stats;
  1671. int i;
  1672. if (!vif->fw_stats_ready) {
  1673. seq_puts(s, "no statistics\n");
  1674. return;
  1675. }
  1676. seq_printf(s, "TSF %lld\n", vif->fw_stats_tsf);
  1677. for (i = 0; i < ARRAY_SIZE(wil->sta); i++) {
  1678. if (wil->sta[i].status == wil_sta_unused)
  1679. continue;
  1680. if (wil->sta[i].mid != vif->mid)
  1681. continue;
  1682. stats = &wil->sta[i].fw_stats_basic;
  1683. wil_link_stats_print_basic(vif, s, stats);
  1684. }
  1685. }
  1686. static int wil_link_stats_debugfs_show(struct seq_file *s, void *data)
  1687. {
  1688. struct wil6210_priv *wil = s->private;
  1689. struct wil6210_vif *vif;
  1690. int i, rc;
  1691. rc = mutex_lock_interruptible(&wil->vif_mutex);
  1692. if (rc)
  1693. return rc;
  1694. /* iterate over all MIDs and show per-cid statistics. Then show the
  1695. * global statistics
  1696. */
  1697. for (i = 0; i < wil->max_vifs; i++) {
  1698. vif = wil->vifs[i];
  1699. seq_printf(s, "MID %d ", i);
  1700. if (!vif) {
  1701. seq_puts(s, "unused\n");
  1702. continue;
  1703. }
  1704. wil_link_stats_debugfs_show_vif(vif, s);
  1705. }
  1706. mutex_unlock(&wil->vif_mutex);
  1707. return 0;
  1708. }
  1709. static int wil_link_stats_seq_open(struct inode *inode, struct file *file)
  1710. {
  1711. return single_open(file, wil_link_stats_debugfs_show, inode->i_private);
  1712. }
  1713. static ssize_t wil_link_stats_write(struct file *file, const char __user *buf,
  1714. size_t len, loff_t *ppos)
  1715. {
  1716. struct seq_file *s = file->private_data;
  1717. struct wil6210_priv *wil = s->private;
  1718. int cid, interval, rc, i;
  1719. struct wil6210_vif *vif;
  1720. char *kbuf = kmalloc(len + 1, GFP_KERNEL);
  1721. if (!kbuf)
  1722. return -ENOMEM;
  1723. rc = simple_write_to_buffer(kbuf, len, ppos, buf, len);
  1724. if (rc != len) {
  1725. kfree(kbuf);
  1726. return rc >= 0 ? -EIO : rc;
  1727. }
  1728. kbuf[len] = '\0';
  1729. /* specify cid (use -1 for all cids) and snapshot interval in ms */
  1730. rc = sscanf(kbuf, "%d %d", &cid, &interval);
  1731. kfree(kbuf);
  1732. if (rc < 0)
  1733. return rc;
  1734. if (rc < 2 || interval < 0)
  1735. return -EINVAL;
  1736. wil_info(wil, "request link statistics, cid %d interval %d\n",
  1737. cid, interval);
  1738. rc = mutex_lock_interruptible(&wil->vif_mutex);
  1739. if (rc)
  1740. return rc;
  1741. for (i = 0; i < wil->max_vifs; i++) {
  1742. vif = wil->vifs[i];
  1743. if (!vif)
  1744. continue;
  1745. rc = wmi_link_stats_cfg(vif, WMI_LINK_STATS_TYPE_BASIC,
  1746. (cid == -1 ? 0xff : cid), interval);
  1747. if (rc)
  1748. wil_err(wil, "link statistics failed for mid %d\n", i);
  1749. }
  1750. mutex_unlock(&wil->vif_mutex);
  1751. return len;
  1752. }
  1753. static const struct file_operations fops_link_stats = {
  1754. .open = wil_link_stats_seq_open,
  1755. .release = single_release,
  1756. .read = seq_read,
  1757. .write = wil_link_stats_write,
  1758. .llseek = seq_lseek,
  1759. };
  1760. static int
  1761. wil_link_stats_global_debugfs_show(struct seq_file *s, void *data)
  1762. {
  1763. struct wil6210_priv *wil = s->private;
  1764. if (!wil->fw_stats_global.ready)
  1765. return 0;
  1766. seq_printf(s, "TSF %lld\n", wil->fw_stats_global.tsf);
  1767. wil_link_stats_print_global(wil, s, &wil->fw_stats_global.stats);
  1768. return 0;
  1769. }
  1770. static int
  1771. wil_link_stats_global_seq_open(struct inode *inode, struct file *file)
  1772. {
  1773. return single_open(file, wil_link_stats_global_debugfs_show,
  1774. inode->i_private);
  1775. }
  1776. static ssize_t
  1777. wil_link_stats_global_write(struct file *file, const char __user *buf,
  1778. size_t len, loff_t *ppos)
  1779. {
  1780. struct seq_file *s = file->private_data;
  1781. struct wil6210_priv *wil = s->private;
  1782. int interval, rc;
  1783. struct wil6210_vif *vif = ndev_to_vif(wil->main_ndev);
  1784. /* specify snapshot interval in ms */
  1785. rc = kstrtoint_from_user(buf, len, 0, &interval);
  1786. if (rc || interval < 0) {
  1787. wil_err(wil, "Invalid argument\n");
  1788. return -EINVAL;
  1789. }
  1790. wil_info(wil, "request global link stats, interval %d\n", interval);
  1791. rc = wmi_link_stats_cfg(vif, WMI_LINK_STATS_TYPE_GLOBAL, 0, interval);
  1792. if (rc)
  1793. wil_err(wil, "global link stats failed %d\n", rc);
  1794. return rc ? rc : len;
  1795. }
  1796. static const struct file_operations fops_link_stats_global = {
  1797. .open = wil_link_stats_global_seq_open,
  1798. .release = single_release,
  1799. .read = seq_read,
  1800. .write = wil_link_stats_global_write,
  1801. .llseek = seq_lseek,
  1802. };
  1803. static ssize_t wil_read_file_led_cfg(struct file *file, char __user *user_buf,
  1804. size_t count, loff_t *ppos)
  1805. {
  1806. char buf[80];
  1807. int n;
  1808. n = snprintf(buf, sizeof(buf),
  1809. "led_id is set to %d, echo 1 to enable, 0 to disable\n",
  1810. led_id);
  1811. n = min_t(int, n, sizeof(buf));
  1812. return simple_read_from_buffer(user_buf, count, ppos,
  1813. buf, n);
  1814. }
  1815. static ssize_t wil_write_file_led_cfg(struct file *file,
  1816. const char __user *buf_,
  1817. size_t count, loff_t *ppos)
  1818. {
  1819. struct wil6210_priv *wil = file->private_data;
  1820. int val;
  1821. int rc;
  1822. rc = kstrtoint_from_user(buf_, count, 0, &val);
  1823. if (rc) {
  1824. wil_err(wil, "Invalid argument\n");
  1825. return rc;
  1826. }
  1827. wil_info(wil, "%s led %d\n", val ? "Enabling" : "Disabling", led_id);
  1828. rc = wmi_led_cfg(wil, val);
  1829. if (rc) {
  1830. wil_info(wil, "%s led %d failed\n",
  1831. val ? "Enabling" : "Disabling", led_id);
  1832. return rc;
  1833. }
  1834. return count;
  1835. }
  1836. static const struct file_operations fops_led_cfg = {
  1837. .read = wil_read_file_led_cfg,
  1838. .write = wil_write_file_led_cfg,
  1839. .open = simple_open,
  1840. };
  1841. /* led_blink_time, write:
  1842. * "<blink_on_slow> <blink_off_slow> <blink_on_med> <blink_off_med> <blink_on_fast> <blink_off_fast>
  1843. */
  1844. static ssize_t wil_write_led_blink_time(struct file *file,
  1845. const char __user *buf,
  1846. size_t len, loff_t *ppos)
  1847. {
  1848. int rc;
  1849. char *kbuf = kmalloc(len + 1, GFP_KERNEL);
  1850. if (!kbuf)
  1851. return -ENOMEM;
  1852. rc = simple_write_to_buffer(kbuf, len, ppos, buf, len);
  1853. if (rc != len) {
  1854. kfree(kbuf);
  1855. return rc >= 0 ? -EIO : rc;
  1856. }
  1857. kbuf[len] = '\0';
  1858. rc = sscanf(kbuf, "%d %d %d %d %d %d",
  1859. &led_blink_time[WIL_LED_TIME_SLOW].on_ms,
  1860. &led_blink_time[WIL_LED_TIME_SLOW].off_ms,
  1861. &led_blink_time[WIL_LED_TIME_MED].on_ms,
  1862. &led_blink_time[WIL_LED_TIME_MED].off_ms,
  1863. &led_blink_time[WIL_LED_TIME_FAST].on_ms,
  1864. &led_blink_time[WIL_LED_TIME_FAST].off_ms);
  1865. kfree(kbuf);
  1866. if (rc < 0)
  1867. return rc;
  1868. if (rc < 6)
  1869. return -EINVAL;
  1870. return len;
  1871. }
  1872. static ssize_t wil_read_led_blink_time(struct file *file, char __user *user_buf,
  1873. size_t count, loff_t *ppos)
  1874. {
  1875. static char text[400];
  1876. snprintf(text, sizeof(text),
  1877. "To set led blink on/off time variables write:\n"
  1878. "<blink_on_slow> <blink_off_slow> <blink_on_med> "
  1879. "<blink_off_med> <blink_on_fast> <blink_off_fast>\n"
  1880. "The current values are:\n"
  1881. "%d %d %d %d %d %d\n",
  1882. led_blink_time[WIL_LED_TIME_SLOW].on_ms,
  1883. led_blink_time[WIL_LED_TIME_SLOW].off_ms,
  1884. led_blink_time[WIL_LED_TIME_MED].on_ms,
  1885. led_blink_time[WIL_LED_TIME_MED].off_ms,
  1886. led_blink_time[WIL_LED_TIME_FAST].on_ms,
  1887. led_blink_time[WIL_LED_TIME_FAST].off_ms);
  1888. return simple_read_from_buffer(user_buf, count, ppos, text,
  1889. sizeof(text));
  1890. }
  1891. static const struct file_operations fops_led_blink_time = {
  1892. .read = wil_read_led_blink_time,
  1893. .write = wil_write_led_blink_time,
  1894. .open = simple_open,
  1895. };
  1896. /*---------FW capabilities------------*/
  1897. static int wil_fw_capabilities_debugfs_show(struct seq_file *s, void *data)
  1898. {
  1899. struct wil6210_priv *wil = s->private;
  1900. seq_printf(s, "fw_capabilities : %*pb\n", WMI_FW_CAPABILITY_MAX,
  1901. wil->fw_capabilities);
  1902. return 0;
  1903. }
  1904. static int wil_fw_capabilities_seq_open(struct inode *inode, struct file *file)
  1905. {
  1906. return single_open(file, wil_fw_capabilities_debugfs_show,
  1907. inode->i_private);
  1908. }
  1909. static const struct file_operations fops_fw_capabilities = {
  1910. .open = wil_fw_capabilities_seq_open,
  1911. .release = single_release,
  1912. .read = seq_read,
  1913. .llseek = seq_lseek,
  1914. };
  1915. /*---------FW version------------*/
  1916. static int wil_fw_version_debugfs_show(struct seq_file *s, void *data)
  1917. {
  1918. struct wil6210_priv *wil = s->private;
  1919. if (wil->fw_version[0])
  1920. seq_printf(s, "%s\n", wil->fw_version);
  1921. else
  1922. seq_puts(s, "N/A\n");
  1923. return 0;
  1924. }
  1925. static int wil_fw_version_seq_open(struct inode *inode, struct file *file)
  1926. {
  1927. return single_open(file, wil_fw_version_debugfs_show,
  1928. inode->i_private);
  1929. }
  1930. static const struct file_operations fops_fw_version = {
  1931. .open = wil_fw_version_seq_open,
  1932. .release = single_release,
  1933. .read = seq_read,
  1934. .llseek = seq_lseek,
  1935. };
  1936. /*---------suspend_stats---------*/
  1937. static ssize_t wil_write_suspend_stats(struct file *file,
  1938. const char __user *buf,
  1939. size_t len, loff_t *ppos)
  1940. {
  1941. struct wil6210_priv *wil = file->private_data;
  1942. memset(&wil->suspend_stats, 0, sizeof(wil->suspend_stats));
  1943. return len;
  1944. }
  1945. static ssize_t wil_read_suspend_stats(struct file *file,
  1946. char __user *user_buf,
  1947. size_t count, loff_t *ppos)
  1948. {
  1949. struct wil6210_priv *wil = file->private_data;
  1950. char *text;
  1951. int n, ret, text_size = 500;
  1952. text = kmalloc(text_size, GFP_KERNEL);
  1953. if (!text)
  1954. return -ENOMEM;
  1955. n = snprintf(text, text_size,
  1956. "Radio on suspend statistics:\n"
  1957. "successful suspends:%ld failed suspends:%ld\n"
  1958. "successful resumes:%ld failed resumes:%ld\n"
  1959. "rejected by device:%ld\n"
  1960. "Radio off suspend statistics:\n"
  1961. "successful suspends:%ld failed suspends:%ld\n"
  1962. "successful resumes:%ld failed resumes:%ld\n"
  1963. "General statistics:\n"
  1964. "rejected by host:%ld\n",
  1965. wil->suspend_stats.r_on.successful_suspends,
  1966. wil->suspend_stats.r_on.failed_suspends,
  1967. wil->suspend_stats.r_on.successful_resumes,
  1968. wil->suspend_stats.r_on.failed_resumes,
  1969. wil->suspend_stats.rejected_by_device,
  1970. wil->suspend_stats.r_off.successful_suspends,
  1971. wil->suspend_stats.r_off.failed_suspends,
  1972. wil->suspend_stats.r_off.successful_resumes,
  1973. wil->suspend_stats.r_off.failed_resumes,
  1974. wil->suspend_stats.rejected_by_host);
  1975. n = min_t(int, n, text_size);
  1976. ret = simple_read_from_buffer(user_buf, count, ppos, text, n);
  1977. kfree(text);
  1978. return ret;
  1979. }
  1980. static const struct file_operations fops_suspend_stats = {
  1981. .read = wil_read_suspend_stats,
  1982. .write = wil_write_suspend_stats,
  1983. .open = simple_open,
  1984. };
  1985. /*---------compressed_rx_status---------*/
  1986. static ssize_t wil_compressed_rx_status_write(struct file *file,
  1987. const char __user *buf,
  1988. size_t len, loff_t *ppos)
  1989. {
  1990. struct seq_file *s = file->private_data;
  1991. struct wil6210_priv *wil = s->private;
  1992. int compressed_rx_status;
  1993. int rc;
  1994. rc = kstrtoint_from_user(buf, len, 0, &compressed_rx_status);
  1995. if (rc) {
  1996. wil_err(wil, "Invalid argument\n");
  1997. return rc;
  1998. }
  1999. if (wil_has_active_ifaces(wil, true, false)) {
  2000. wil_err(wil, "cannot change edma config after iface is up\n");
  2001. return -EPERM;
  2002. }
  2003. wil_info(wil, "%sable compressed_rx_status\n",
  2004. compressed_rx_status ? "En" : "Dis");
  2005. wil->use_compressed_rx_status = compressed_rx_status;
  2006. return len;
  2007. }
  2008. static int
  2009. wil_compressed_rx_status_show(struct seq_file *s, void *data)
  2010. {
  2011. struct wil6210_priv *wil = s->private;
  2012. seq_printf(s, "%d\n", wil->use_compressed_rx_status);
  2013. return 0;
  2014. }
  2015. static int
  2016. wil_compressed_rx_status_seq_open(struct inode *inode, struct file *file)
  2017. {
  2018. return single_open(file, wil_compressed_rx_status_show,
  2019. inode->i_private);
  2020. }
  2021. static const struct file_operations fops_compressed_rx_status = {
  2022. .open = wil_compressed_rx_status_seq_open,
  2023. .release = single_release,
  2024. .read = seq_read,
  2025. .write = wil_compressed_rx_status_write,
  2026. .llseek = seq_lseek,
  2027. };
  2028. /*----------------*/
  2029. static void wil6210_debugfs_init_blobs(struct wil6210_priv *wil,
  2030. struct dentry *dbg)
  2031. {
  2032. int i;
  2033. char name[32];
  2034. for (i = 0; i < ARRAY_SIZE(fw_mapping); i++) {
  2035. struct wil_blob_wrapper *wil_blob = &wil->blobs[i];
  2036. struct debugfs_blob_wrapper *blob = &wil_blob->blob;
  2037. const struct fw_map *map = &fw_mapping[i];
  2038. if (!map->name)
  2039. continue;
  2040. wil_blob->wil = wil;
  2041. blob->data = (void * __force)wil->csr + HOSTADDR(map->host);
  2042. blob->size = map->to - map->from;
  2043. snprintf(name, sizeof(name), "blob_%s", map->name);
  2044. wil_debugfs_create_ioblob(name, 0444, dbg, wil_blob);
  2045. }
  2046. }
  2047. /* misc files */
  2048. static const struct {
  2049. const char *name;
  2050. umode_t mode;
  2051. const struct file_operations *fops;
  2052. } dbg_files[] = {
  2053. {"mbox", 0444, &fops_mbox},
  2054. {"rings", 0444, &fops_ring},
  2055. {"stations", 0444, &fops_sta},
  2056. {"mids", 0444, &fops_mids},
  2057. {"desc", 0444, &fops_txdesc},
  2058. {"bf", 0444, &fops_bf},
  2059. {"mem_val", 0644, &fops_memread},
  2060. {"reset", 0244, &fops_reset},
  2061. {"rxon", 0244, &fops_rxon},
  2062. {"tx_mgmt", 0244, &fops_txmgmt},
  2063. {"wmi_send", 0244, &fops_wmi},
  2064. {"back", 0644, &fops_back},
  2065. {"pmccfg", 0644, &fops_pmccfg},
  2066. {"pmcdata", 0444, &fops_pmcdata},
  2067. {"temp", 0444, &fops_temp},
  2068. {"freq", 0444, &fops_freq},
  2069. {"link", 0444, &fops_link},
  2070. {"info", 0444, &fops_info},
  2071. {"recovery", 0644, &fops_recovery},
  2072. {"led_cfg", 0644, &fops_led_cfg},
  2073. {"led_blink_time", 0644, &fops_led_blink_time},
  2074. {"fw_capabilities", 0444, &fops_fw_capabilities},
  2075. {"fw_version", 0444, &fops_fw_version},
  2076. {"suspend_stats", 0644, &fops_suspend_stats},
  2077. {"compressed_rx_status", 0644, &fops_compressed_rx_status},
  2078. {"srings", 0444, &fops_srings},
  2079. {"status_msg", 0444, &fops_status_msg},
  2080. {"rx_buff_mgmt", 0444, &fops_rx_buff_mgmt},
  2081. {"tx_latency", 0644, &fops_tx_latency},
  2082. {"link_stats", 0644, &fops_link_stats},
  2083. {"link_stats_global", 0644, &fops_link_stats_global},
  2084. };
  2085. static void wil6210_debugfs_init_files(struct wil6210_priv *wil,
  2086. struct dentry *dbg)
  2087. {
  2088. int i;
  2089. for (i = 0; i < ARRAY_SIZE(dbg_files); i++)
  2090. debugfs_create_file(dbg_files[i].name, dbg_files[i].mode, dbg,
  2091. wil, dbg_files[i].fops);
  2092. }
  2093. /* interrupt control blocks */
  2094. static const struct {
  2095. const char *name;
  2096. u32 icr_off;
  2097. } dbg_icr[] = {
  2098. {"USER_ICR", HOSTADDR(RGF_USER_USER_ICR)},
  2099. {"DMA_EP_TX_ICR", HOSTADDR(RGF_DMA_EP_TX_ICR)},
  2100. {"DMA_EP_RX_ICR", HOSTADDR(RGF_DMA_EP_RX_ICR)},
  2101. {"DMA_EP_MISC_ICR", HOSTADDR(RGF_DMA_EP_MISC_ICR)},
  2102. };
  2103. static void wil6210_debugfs_init_isr(struct wil6210_priv *wil,
  2104. struct dentry *dbg)
  2105. {
  2106. int i;
  2107. for (i = 0; i < ARRAY_SIZE(dbg_icr); i++)
  2108. wil6210_debugfs_create_ISR(wil, dbg_icr[i].name, dbg,
  2109. dbg_icr[i].icr_off);
  2110. }
  2111. #define WIL_FIELD(name, mode, type) { __stringify(name), mode, \
  2112. offsetof(struct wil6210_priv, name), type}
  2113. /* fields in struct wil6210_priv */
  2114. static const struct dbg_off dbg_wil_off[] = {
  2115. WIL_FIELD(status[0], 0644, doff_ulong),
  2116. WIL_FIELD(hw_version, 0444, doff_x32),
  2117. WIL_FIELD(recovery_count, 0444, doff_u32),
  2118. WIL_FIELD(discovery_mode, 0644, doff_u8),
  2119. WIL_FIELD(chip_revision, 0444, doff_u8),
  2120. WIL_FIELD(abft_len, 0644, doff_u8),
  2121. WIL_FIELD(wakeup_trigger, 0644, doff_u8),
  2122. WIL_FIELD(ring_idle_trsh, 0644, doff_u32),
  2123. WIL_FIELD(num_rx_status_rings, 0644, doff_u8),
  2124. WIL_FIELD(rx_status_ring_order, 0644, doff_u32),
  2125. WIL_FIELD(tx_status_ring_order, 0644, doff_u32),
  2126. WIL_FIELD(rx_buff_id_count, 0644, doff_u32),
  2127. WIL_FIELD(amsdu_en, 0644, doff_u8),
  2128. {},
  2129. };
  2130. static const struct dbg_off dbg_wil_regs[] = {
  2131. {"RGF_MAC_MTRL_COUNTER_0", 0444, HOSTADDR(RGF_MAC_MTRL_COUNTER_0),
  2132. doff_io32},
  2133. {"RGF_USER_USAGE_1", 0444, HOSTADDR(RGF_USER_USAGE_1), doff_io32},
  2134. {},
  2135. };
  2136. /* static parameters */
  2137. static const struct dbg_off dbg_statics[] = {
  2138. {"desc_index", 0644, (ulong)&dbg_txdesc_index, doff_u32},
  2139. {"ring_index", 0644, (ulong)&dbg_ring_index, doff_u32},
  2140. {"mem_addr", 0644, (ulong)&mem_addr, doff_u32},
  2141. {"led_polarity", 0644, (ulong)&led_polarity, doff_u8},
  2142. {"status_index", 0644, (ulong)&dbg_status_msg_index, doff_u32},
  2143. {"sring_index", 0644, (ulong)&dbg_sring_index, doff_u32},
  2144. {},
  2145. };
  2146. static const int dbg_off_count = 4 * (ARRAY_SIZE(isr_off) - 1) +
  2147. ARRAY_SIZE(dbg_wil_regs) - 1 +
  2148. ARRAY_SIZE(pseudo_isr_off) - 1 +
  2149. ARRAY_SIZE(lgc_itr_cnt_off) - 1 +
  2150. ARRAY_SIZE(tx_itr_cnt_off) - 1 +
  2151. ARRAY_SIZE(rx_itr_cnt_off) - 1;
  2152. int wil6210_debugfs_init(struct wil6210_priv *wil)
  2153. {
  2154. struct dentry *dbg = wil->debug = debugfs_create_dir(WIL_NAME,
  2155. wil_to_wiphy(wil)->debugfsdir);
  2156. if (IS_ERR_OR_NULL(dbg))
  2157. return -ENODEV;
  2158. wil->dbg_data.data_arr = kcalloc(dbg_off_count,
  2159. sizeof(struct wil_debugfs_iomem_data),
  2160. GFP_KERNEL);
  2161. if (!wil->dbg_data.data_arr) {
  2162. debugfs_remove_recursive(dbg);
  2163. wil->debug = NULL;
  2164. return -ENOMEM;
  2165. }
  2166. wil->dbg_data.iomem_data_count = 0;
  2167. wil_pmc_init(wil);
  2168. wil6210_debugfs_init_files(wil, dbg);
  2169. wil6210_debugfs_init_isr(wil, dbg);
  2170. wil6210_debugfs_init_blobs(wil, dbg);
  2171. wil6210_debugfs_init_offset(wil, dbg, wil, dbg_wil_off);
  2172. wil6210_debugfs_init_offset(wil, dbg, (void * __force)wil->csr,
  2173. dbg_wil_regs);
  2174. wil6210_debugfs_init_offset(wil, dbg, NULL, dbg_statics);
  2175. wil6210_debugfs_create_pseudo_ISR(wil, dbg);
  2176. wil6210_debugfs_create_ITR_CNT(wil, dbg);
  2177. return 0;
  2178. }
  2179. void wil6210_debugfs_remove(struct wil6210_priv *wil)
  2180. {
  2181. int i;
  2182. debugfs_remove_recursive(wil->debug);
  2183. wil->debug = NULL;
  2184. kfree(wil->dbg_data.data_arr);
  2185. for (i = 0; i < ARRAY_SIZE(wil->sta); i++)
  2186. kfree(wil->sta[i].tx_latency_bins);
  2187. /* free pmc memory without sending command to fw, as it will
  2188. * be reset on the way down anyway
  2189. */
  2190. wil_pmc_free(wil, false);
  2191. }