debugfs.c 63 KB

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