iwl-debugfs.c 80 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454
  1. /******************************************************************************
  2. *
  3. * GPL LICENSE SUMMARY
  4. *
  5. * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of version 2 of the GNU General Public License as
  9. * published by the Free Software Foundation.
  10. *
  11. * This program is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
  19. * USA
  20. *
  21. * The full GNU General Public License is included in this distribution
  22. * in the file called LICENSE.GPL.
  23. *
  24. * Contact Information:
  25. * Intel Linux Wireless <ilw@linux.intel.com>
  26. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  27. *****************************************************************************/
  28. #include <linux/slab.h>
  29. #include <linux/kernel.h>
  30. #include <linux/module.h>
  31. #include <linux/debugfs.h>
  32. #include <linux/ieee80211.h>
  33. #include <net/mac80211.h>
  34. #include "iwl-dev.h"
  35. #include "iwl-debug.h"
  36. #include "iwl-core.h"
  37. #include "iwl-io.h"
  38. #include "iwl-agn.h"
  39. /* create and remove of files */
  40. #define DEBUGFS_ADD_FILE(name, parent, mode) do { \
  41. if (!debugfs_create_file(#name, mode, parent, priv, \
  42. &iwl_dbgfs_##name##_ops)) \
  43. goto err; \
  44. } while (0)
  45. #define DEBUGFS_ADD_BOOL(name, parent, ptr) do { \
  46. struct dentry *__tmp; \
  47. __tmp = debugfs_create_bool(#name, S_IWUSR | S_IRUSR, \
  48. parent, ptr); \
  49. if (IS_ERR(__tmp) || !__tmp) \
  50. goto err; \
  51. } while (0)
  52. #define DEBUGFS_ADD_X32(name, parent, ptr) do { \
  53. struct dentry *__tmp; \
  54. __tmp = debugfs_create_x32(#name, S_IWUSR | S_IRUSR, \
  55. parent, ptr); \
  56. if (IS_ERR(__tmp) || !__tmp) \
  57. goto err; \
  58. } while (0)
  59. /* file operation */
  60. #define DEBUGFS_READ_FUNC(name) \
  61. static ssize_t iwl_dbgfs_##name##_read(struct file *file, \
  62. char __user *user_buf, \
  63. size_t count, loff_t *ppos);
  64. #define DEBUGFS_WRITE_FUNC(name) \
  65. static ssize_t iwl_dbgfs_##name##_write(struct file *file, \
  66. const char __user *user_buf, \
  67. size_t count, loff_t *ppos);
  68. static int iwl_dbgfs_open_file_generic(struct inode *inode, struct file *file)
  69. {
  70. file->private_data = inode->i_private;
  71. return 0;
  72. }
  73. #define DEBUGFS_READ_FILE_OPS(name) \
  74. DEBUGFS_READ_FUNC(name); \
  75. static const struct file_operations iwl_dbgfs_##name##_ops = { \
  76. .read = iwl_dbgfs_##name##_read, \
  77. .open = iwl_dbgfs_open_file_generic, \
  78. .llseek = generic_file_llseek, \
  79. };
  80. #define DEBUGFS_WRITE_FILE_OPS(name) \
  81. DEBUGFS_WRITE_FUNC(name); \
  82. static const struct file_operations iwl_dbgfs_##name##_ops = { \
  83. .write = iwl_dbgfs_##name##_write, \
  84. .open = iwl_dbgfs_open_file_generic, \
  85. .llseek = generic_file_llseek, \
  86. };
  87. #define DEBUGFS_READ_WRITE_FILE_OPS(name) \
  88. DEBUGFS_READ_FUNC(name); \
  89. DEBUGFS_WRITE_FUNC(name); \
  90. static const struct file_operations iwl_dbgfs_##name##_ops = { \
  91. .write = iwl_dbgfs_##name##_write, \
  92. .read = iwl_dbgfs_##name##_read, \
  93. .open = iwl_dbgfs_open_file_generic, \
  94. .llseek = generic_file_llseek, \
  95. };
  96. static ssize_t iwl_dbgfs_tx_statistics_read(struct file *file,
  97. char __user *user_buf,
  98. size_t count, loff_t *ppos) {
  99. struct iwl_priv *priv = file->private_data;
  100. char *buf;
  101. int pos = 0;
  102. int cnt;
  103. ssize_t ret;
  104. const size_t bufsz = 100 +
  105. sizeof(char) * 50 * (MANAGEMENT_MAX + CONTROL_MAX);
  106. buf = kzalloc(bufsz, GFP_KERNEL);
  107. if (!buf)
  108. return -ENOMEM;
  109. pos += scnprintf(buf + pos, bufsz - pos, "Management:\n");
  110. for (cnt = 0; cnt < MANAGEMENT_MAX; cnt++) {
  111. pos += scnprintf(buf + pos, bufsz - pos,
  112. "\t%25s\t\t: %u\n",
  113. get_mgmt_string(cnt),
  114. priv->tx_stats.mgmt[cnt]);
  115. }
  116. pos += scnprintf(buf + pos, bufsz - pos, "Control\n");
  117. for (cnt = 0; cnt < CONTROL_MAX; cnt++) {
  118. pos += scnprintf(buf + pos, bufsz - pos,
  119. "\t%25s\t\t: %u\n",
  120. get_ctrl_string(cnt),
  121. priv->tx_stats.ctrl[cnt]);
  122. }
  123. pos += scnprintf(buf + pos, bufsz - pos, "Data:\n");
  124. pos += scnprintf(buf + pos, bufsz - pos, "\tcnt: %u\n",
  125. priv->tx_stats.data_cnt);
  126. pos += scnprintf(buf + pos, bufsz - pos, "\tbytes: %llu\n",
  127. priv->tx_stats.data_bytes);
  128. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  129. kfree(buf);
  130. return ret;
  131. }
  132. static ssize_t iwl_dbgfs_clear_traffic_statistics_write(struct file *file,
  133. const char __user *user_buf,
  134. size_t count, loff_t *ppos)
  135. {
  136. struct iwl_priv *priv = file->private_data;
  137. u32 clear_flag;
  138. char buf[8];
  139. int buf_size;
  140. memset(buf, 0, sizeof(buf));
  141. buf_size = min(count, sizeof(buf) - 1);
  142. if (copy_from_user(buf, user_buf, buf_size))
  143. return -EFAULT;
  144. if (sscanf(buf, "%x", &clear_flag) != 1)
  145. return -EFAULT;
  146. iwl_clear_traffic_stats(priv);
  147. return count;
  148. }
  149. static ssize_t iwl_dbgfs_rx_statistics_read(struct file *file,
  150. char __user *user_buf,
  151. size_t count, loff_t *ppos) {
  152. struct iwl_priv *priv = file->private_data;
  153. char *buf;
  154. int pos = 0;
  155. int cnt;
  156. ssize_t ret;
  157. const size_t bufsz = 100 +
  158. sizeof(char) * 50 * (MANAGEMENT_MAX + CONTROL_MAX);
  159. buf = kzalloc(bufsz, GFP_KERNEL);
  160. if (!buf)
  161. return -ENOMEM;
  162. pos += scnprintf(buf + pos, bufsz - pos, "Management:\n");
  163. for (cnt = 0; cnt < MANAGEMENT_MAX; cnt++) {
  164. pos += scnprintf(buf + pos, bufsz - pos,
  165. "\t%25s\t\t: %u\n",
  166. get_mgmt_string(cnt),
  167. priv->rx_stats.mgmt[cnt]);
  168. }
  169. pos += scnprintf(buf + pos, bufsz - pos, "Control:\n");
  170. for (cnt = 0; cnt < CONTROL_MAX; cnt++) {
  171. pos += scnprintf(buf + pos, bufsz - pos,
  172. "\t%25s\t\t: %u\n",
  173. get_ctrl_string(cnt),
  174. priv->rx_stats.ctrl[cnt]);
  175. }
  176. pos += scnprintf(buf + pos, bufsz - pos, "Data:\n");
  177. pos += scnprintf(buf + pos, bufsz - pos, "\tcnt: %u\n",
  178. priv->rx_stats.data_cnt);
  179. pos += scnprintf(buf + pos, bufsz - pos, "\tbytes: %llu\n",
  180. priv->rx_stats.data_bytes);
  181. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  182. kfree(buf);
  183. return ret;
  184. }
  185. static ssize_t iwl_dbgfs_sram_read(struct file *file,
  186. char __user *user_buf,
  187. size_t count, loff_t *ppos)
  188. {
  189. u32 val = 0;
  190. char *buf;
  191. ssize_t ret;
  192. int i = 0;
  193. bool device_format = false;
  194. int offset = 0;
  195. int len = 0;
  196. int pos = 0;
  197. int sram;
  198. struct iwl_priv *priv = file->private_data;
  199. size_t bufsz;
  200. /* default is to dump the entire data segment */
  201. if (!priv->dbgfs_sram_offset && !priv->dbgfs_sram_len) {
  202. priv->dbgfs_sram_offset = 0x800000;
  203. if (priv->ucode_type == IWL_UCODE_INIT)
  204. priv->dbgfs_sram_len = priv->ucode_init.data.len;
  205. else
  206. priv->dbgfs_sram_len = priv->ucode_rt.data.len;
  207. }
  208. len = priv->dbgfs_sram_len;
  209. if (len == -4) {
  210. device_format = true;
  211. len = 4;
  212. }
  213. bufsz = 50 + len * 4;
  214. buf = kmalloc(bufsz, GFP_KERNEL);
  215. if (!buf)
  216. return -ENOMEM;
  217. pos += scnprintf(buf + pos, bufsz - pos, "sram_len: 0x%x\n",
  218. len);
  219. pos += scnprintf(buf + pos, bufsz - pos, "sram_offset: 0x%x\n",
  220. priv->dbgfs_sram_offset);
  221. /* adjust sram address since reads are only on even u32 boundaries */
  222. offset = priv->dbgfs_sram_offset & 0x3;
  223. sram = priv->dbgfs_sram_offset & ~0x3;
  224. /* read the first u32 from sram */
  225. val = iwl_read_targ_mem(bus(priv), sram);
  226. for (; len; len--) {
  227. /* put the address at the start of every line */
  228. if (i == 0)
  229. pos += scnprintf(buf + pos, bufsz - pos,
  230. "%08X: ", sram + offset);
  231. if (device_format)
  232. pos += scnprintf(buf + pos, bufsz - pos,
  233. "%02x", (val >> (8 * (3 - offset))) & 0xff);
  234. else
  235. pos += scnprintf(buf + pos, bufsz - pos,
  236. "%02x ", (val >> (8 * offset)) & 0xff);
  237. /* if all bytes processed, read the next u32 from sram */
  238. if (++offset == 4) {
  239. sram += 4;
  240. offset = 0;
  241. val = iwl_read_targ_mem(bus(priv), sram);
  242. }
  243. /* put in extra spaces and split lines for human readability */
  244. if (++i == 16) {
  245. i = 0;
  246. pos += scnprintf(buf + pos, bufsz - pos, "\n");
  247. } else if (!(i & 7)) {
  248. pos += scnprintf(buf + pos, bufsz - pos, " ");
  249. } else if (!(i & 3)) {
  250. pos += scnprintf(buf + pos, bufsz - pos, " ");
  251. }
  252. }
  253. if (i)
  254. pos += scnprintf(buf + pos, bufsz - pos, "\n");
  255. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  256. kfree(buf);
  257. return ret;
  258. }
  259. static ssize_t iwl_dbgfs_sram_write(struct file *file,
  260. const char __user *user_buf,
  261. size_t count, loff_t *ppos)
  262. {
  263. struct iwl_priv *priv = file->private_data;
  264. char buf[64];
  265. int buf_size;
  266. u32 offset, len;
  267. memset(buf, 0, sizeof(buf));
  268. buf_size = min(count, sizeof(buf) - 1);
  269. if (copy_from_user(buf, user_buf, buf_size))
  270. return -EFAULT;
  271. if (sscanf(buf, "%x,%x", &offset, &len) == 2) {
  272. priv->dbgfs_sram_offset = offset;
  273. priv->dbgfs_sram_len = len;
  274. } else if (sscanf(buf, "%x", &offset) == 1) {
  275. priv->dbgfs_sram_offset = offset;
  276. priv->dbgfs_sram_len = -4;
  277. } else {
  278. priv->dbgfs_sram_offset = 0;
  279. priv->dbgfs_sram_len = 0;
  280. }
  281. return count;
  282. }
  283. static ssize_t iwl_dbgfs_wowlan_sram_read(struct file *file,
  284. char __user *user_buf,
  285. size_t count, loff_t *ppos)
  286. {
  287. struct iwl_priv *priv = file->private_data;
  288. if (!priv->wowlan_sram)
  289. return -ENODATA;
  290. return simple_read_from_buffer(user_buf, count, ppos,
  291. priv->wowlan_sram,
  292. priv->ucode_wowlan.data.len);
  293. }
  294. static ssize_t iwl_dbgfs_stations_read(struct file *file, char __user *user_buf,
  295. size_t count, loff_t *ppos)
  296. {
  297. struct iwl_priv *priv = file->private_data;
  298. struct iwl_station_entry *station;
  299. struct iwl_tid_data *tid_data;
  300. int max_sta = hw_params(priv).max_stations;
  301. char *buf;
  302. int i, j, pos = 0;
  303. ssize_t ret;
  304. /* Add 30 for initial string */
  305. const size_t bufsz = 30 + sizeof(char) * 500 * (priv->num_stations);
  306. buf = kmalloc(bufsz, GFP_KERNEL);
  307. if (!buf)
  308. return -ENOMEM;
  309. pos += scnprintf(buf + pos, bufsz - pos, "num of stations: %d\n\n",
  310. priv->num_stations);
  311. for (i = 0; i < max_sta; i++) {
  312. station = &priv->stations[i];
  313. if (!station->used)
  314. continue;
  315. pos += scnprintf(buf + pos, bufsz - pos,
  316. "station %d - addr: %pM, flags: %#x\n",
  317. i, station->sta.sta.addr,
  318. station->sta.station_flags_msk);
  319. pos += scnprintf(buf + pos, bufsz - pos,
  320. "TID\tseq_num\ttxq_id\ttfds\trate_n_flags\n");
  321. for (j = 0; j < IWL_MAX_TID_COUNT; j++) {
  322. tid_data = &priv->shrd->tid_data[i][j];
  323. pos += scnprintf(buf + pos, bufsz - pos,
  324. "%d:\t%#x\t%#x\t%u\t%#x",
  325. j, tid_data->seq_number,
  326. tid_data->agg.txq_id,
  327. tid_data->tfds_in_queue,
  328. tid_data->agg.rate_n_flags);
  329. if (tid_data->agg.wait_for_ba)
  330. pos += scnprintf(buf + pos, bufsz - pos,
  331. " - waitforba");
  332. pos += scnprintf(buf + pos, bufsz - pos, "\n");
  333. }
  334. pos += scnprintf(buf + pos, bufsz - pos, "\n");
  335. }
  336. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  337. kfree(buf);
  338. return ret;
  339. }
  340. static ssize_t iwl_dbgfs_nvm_read(struct file *file,
  341. char __user *user_buf,
  342. size_t count,
  343. loff_t *ppos)
  344. {
  345. ssize_t ret;
  346. struct iwl_priv *priv = file->private_data;
  347. int pos = 0, ofs = 0, buf_size = 0;
  348. const u8 *ptr;
  349. char *buf;
  350. u16 eeprom_ver;
  351. size_t eeprom_len = priv->cfg->base_params->eeprom_size;
  352. buf_size = 4 * eeprom_len + 256;
  353. if (eeprom_len % 16) {
  354. IWL_ERR(priv, "NVM size is not multiple of 16.\n");
  355. return -ENODATA;
  356. }
  357. ptr = priv->eeprom;
  358. if (!ptr) {
  359. IWL_ERR(priv, "Invalid EEPROM/OTP memory\n");
  360. return -ENOMEM;
  361. }
  362. /* 4 characters for byte 0xYY */
  363. buf = kzalloc(buf_size, GFP_KERNEL);
  364. if (!buf) {
  365. IWL_ERR(priv, "Can not allocate Buffer\n");
  366. return -ENOMEM;
  367. }
  368. eeprom_ver = iwl_eeprom_query16(priv, EEPROM_VERSION);
  369. pos += scnprintf(buf + pos, buf_size - pos, "NVM Type: %s, "
  370. "version: 0x%x\n",
  371. (priv->nvm_device_type == NVM_DEVICE_TYPE_OTP)
  372. ? "OTP" : "EEPROM", eeprom_ver);
  373. for (ofs = 0 ; ofs < eeprom_len ; ofs += 16) {
  374. pos += scnprintf(buf + pos, buf_size - pos, "0x%.4x ", ofs);
  375. hex_dump_to_buffer(ptr + ofs, 16 , 16, 2, buf + pos,
  376. buf_size - pos, 0);
  377. pos += strlen(buf + pos);
  378. if (buf_size - pos > 0)
  379. buf[pos++] = '\n';
  380. }
  381. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  382. kfree(buf);
  383. return ret;
  384. }
  385. static ssize_t iwl_dbgfs_channels_read(struct file *file, char __user *user_buf,
  386. size_t count, loff_t *ppos)
  387. {
  388. struct iwl_priv *priv = file->private_data;
  389. struct ieee80211_channel *channels = NULL;
  390. const struct ieee80211_supported_band *supp_band = NULL;
  391. int pos = 0, i, bufsz = PAGE_SIZE;
  392. char *buf;
  393. ssize_t ret;
  394. if (!test_bit(STATUS_GEO_CONFIGURED, &priv->shrd->status))
  395. return -EAGAIN;
  396. buf = kzalloc(bufsz, GFP_KERNEL);
  397. if (!buf) {
  398. IWL_ERR(priv, "Can not allocate Buffer\n");
  399. return -ENOMEM;
  400. }
  401. supp_band = iwl_get_hw_mode(priv, IEEE80211_BAND_2GHZ);
  402. if (supp_band) {
  403. channels = supp_band->channels;
  404. pos += scnprintf(buf + pos, bufsz - pos,
  405. "Displaying %d channels in 2.4GHz band 802.11bg):\n",
  406. supp_band->n_channels);
  407. for (i = 0; i < supp_band->n_channels; i++)
  408. pos += scnprintf(buf + pos, bufsz - pos,
  409. "%d: %ddBm: BSS%s%s, %s.\n",
  410. channels[i].hw_value,
  411. channels[i].max_power,
  412. channels[i].flags & IEEE80211_CHAN_RADAR ?
  413. " (IEEE 802.11h required)" : "",
  414. ((channels[i].flags & IEEE80211_CHAN_NO_IBSS)
  415. || (channels[i].flags &
  416. IEEE80211_CHAN_RADAR)) ? "" :
  417. ", IBSS",
  418. channels[i].flags &
  419. IEEE80211_CHAN_PASSIVE_SCAN ?
  420. "passive only" : "active/passive");
  421. }
  422. supp_band = iwl_get_hw_mode(priv, IEEE80211_BAND_5GHZ);
  423. if (supp_band) {
  424. channels = supp_band->channels;
  425. pos += scnprintf(buf + pos, bufsz - pos,
  426. "Displaying %d channels in 5.2GHz band (802.11a)\n",
  427. supp_band->n_channels);
  428. for (i = 0; i < supp_band->n_channels; i++)
  429. pos += scnprintf(buf + pos, bufsz - pos,
  430. "%d: %ddBm: BSS%s%s, %s.\n",
  431. channels[i].hw_value,
  432. channels[i].max_power,
  433. channels[i].flags & IEEE80211_CHAN_RADAR ?
  434. " (IEEE 802.11h required)" : "",
  435. ((channels[i].flags & IEEE80211_CHAN_NO_IBSS)
  436. || (channels[i].flags &
  437. IEEE80211_CHAN_RADAR)) ? "" :
  438. ", IBSS",
  439. channels[i].flags &
  440. IEEE80211_CHAN_PASSIVE_SCAN ?
  441. "passive only" : "active/passive");
  442. }
  443. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  444. kfree(buf);
  445. return ret;
  446. }
  447. static ssize_t iwl_dbgfs_status_read(struct file *file,
  448. char __user *user_buf,
  449. size_t count, loff_t *ppos) {
  450. struct iwl_priv *priv = file->private_data;
  451. char buf[512];
  452. int pos = 0;
  453. const size_t bufsz = sizeof(buf);
  454. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_HCMD_ACTIVE:\t %d\n",
  455. test_bit(STATUS_HCMD_ACTIVE, &priv->shrd->status));
  456. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_INT_ENABLED:\t %d\n",
  457. test_bit(STATUS_INT_ENABLED, &priv->shrd->status));
  458. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_RF_KILL_HW:\t %d\n",
  459. test_bit(STATUS_RF_KILL_HW, &priv->shrd->status));
  460. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_CT_KILL:\t\t %d\n",
  461. test_bit(STATUS_CT_KILL, &priv->shrd->status));
  462. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_INIT:\t\t %d\n",
  463. test_bit(STATUS_INIT, &priv->shrd->status));
  464. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_ALIVE:\t\t %d\n",
  465. test_bit(STATUS_ALIVE, &priv->shrd->status));
  466. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_READY:\t\t %d\n",
  467. test_bit(STATUS_READY, &priv->shrd->status));
  468. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_TEMPERATURE:\t %d\n",
  469. test_bit(STATUS_TEMPERATURE, &priv->shrd->status));
  470. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_GEO_CONFIGURED:\t %d\n",
  471. test_bit(STATUS_GEO_CONFIGURED, &priv->shrd->status));
  472. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_EXIT_PENDING:\t %d\n",
  473. test_bit(STATUS_EXIT_PENDING, &priv->shrd->status));
  474. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_STATISTICS:\t %d\n",
  475. test_bit(STATUS_STATISTICS, &priv->shrd->status));
  476. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_SCANNING:\t %d\n",
  477. test_bit(STATUS_SCANNING, &priv->shrd->status));
  478. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_SCAN_ABORTING:\t %d\n",
  479. test_bit(STATUS_SCAN_ABORTING, &priv->shrd->status));
  480. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_SCAN_HW:\t\t %d\n",
  481. test_bit(STATUS_SCAN_HW, &priv->shrd->status));
  482. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_POWER_PMI:\t %d\n",
  483. test_bit(STATUS_POWER_PMI, &priv->shrd->status));
  484. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_FW_ERROR:\t %d\n",
  485. test_bit(STATUS_FW_ERROR, &priv->shrd->status));
  486. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  487. }
  488. static ssize_t iwl_dbgfs_rx_handlers_read(struct file *file,
  489. char __user *user_buf,
  490. size_t count, loff_t *ppos) {
  491. struct iwl_priv *priv = file->private_data;
  492. int pos = 0;
  493. int cnt = 0;
  494. char *buf;
  495. int bufsz = 24 * 64; /* 24 items * 64 char per item */
  496. ssize_t ret;
  497. buf = kzalloc(bufsz, GFP_KERNEL);
  498. if (!buf) {
  499. IWL_ERR(priv, "Can not allocate Buffer\n");
  500. return -ENOMEM;
  501. }
  502. for (cnt = 0; cnt < REPLY_MAX; cnt++) {
  503. if (priv->rx_handlers_stats[cnt] > 0)
  504. pos += scnprintf(buf + pos, bufsz - pos,
  505. "\tRx handler[%36s]:\t\t %u\n",
  506. get_cmd_string(cnt),
  507. priv->rx_handlers_stats[cnt]);
  508. }
  509. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  510. kfree(buf);
  511. return ret;
  512. }
  513. static ssize_t iwl_dbgfs_rx_handlers_write(struct file *file,
  514. const char __user *user_buf,
  515. size_t count, loff_t *ppos)
  516. {
  517. struct iwl_priv *priv = file->private_data;
  518. char buf[8];
  519. int buf_size;
  520. u32 reset_flag;
  521. memset(buf, 0, sizeof(buf));
  522. buf_size = min(count, sizeof(buf) - 1);
  523. if (copy_from_user(buf, user_buf, buf_size))
  524. return -EFAULT;
  525. if (sscanf(buf, "%x", &reset_flag) != 1)
  526. return -EFAULT;
  527. if (reset_flag == 0)
  528. memset(&priv->rx_handlers_stats[0], 0,
  529. sizeof(priv->rx_handlers_stats));
  530. return count;
  531. }
  532. static ssize_t iwl_dbgfs_qos_read(struct file *file, char __user *user_buf,
  533. size_t count, loff_t *ppos)
  534. {
  535. struct iwl_priv *priv = file->private_data;
  536. struct iwl_rxon_context *ctx;
  537. int pos = 0, i;
  538. char buf[256 * NUM_IWL_RXON_CTX];
  539. const size_t bufsz = sizeof(buf);
  540. for_each_context(priv, ctx) {
  541. pos += scnprintf(buf + pos, bufsz - pos, "context %d:\n",
  542. ctx->ctxid);
  543. for (i = 0; i < AC_NUM; i++) {
  544. pos += scnprintf(buf + pos, bufsz - pos,
  545. "\tcw_min\tcw_max\taifsn\ttxop\n");
  546. pos += scnprintf(buf + pos, bufsz - pos,
  547. "AC[%d]\t%u\t%u\t%u\t%u\n", i,
  548. ctx->qos_data.def_qos_parm.ac[i].cw_min,
  549. ctx->qos_data.def_qos_parm.ac[i].cw_max,
  550. ctx->qos_data.def_qos_parm.ac[i].aifsn,
  551. ctx->qos_data.def_qos_parm.ac[i].edca_txop);
  552. }
  553. pos += scnprintf(buf + pos, bufsz - pos, "\n");
  554. }
  555. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  556. }
  557. static ssize_t iwl_dbgfs_thermal_throttling_read(struct file *file,
  558. char __user *user_buf,
  559. size_t count, loff_t *ppos)
  560. {
  561. struct iwl_priv *priv = file->private_data;
  562. struct iwl_tt_mgmt *tt = &priv->thermal_throttle;
  563. struct iwl_tt_restriction *restriction;
  564. char buf[100];
  565. int pos = 0;
  566. const size_t bufsz = sizeof(buf);
  567. pos += scnprintf(buf + pos, bufsz - pos,
  568. "Thermal Throttling Mode: %s\n",
  569. tt->advanced_tt ? "Advance" : "Legacy");
  570. pos += scnprintf(buf + pos, bufsz - pos,
  571. "Thermal Throttling State: %d\n",
  572. tt->state);
  573. if (tt->advanced_tt) {
  574. restriction = tt->restriction + tt->state;
  575. pos += scnprintf(buf + pos, bufsz - pos,
  576. "Tx mode: %d\n",
  577. restriction->tx_stream);
  578. pos += scnprintf(buf + pos, bufsz - pos,
  579. "Rx mode: %d\n",
  580. restriction->rx_stream);
  581. pos += scnprintf(buf + pos, bufsz - pos,
  582. "HT mode: %d\n",
  583. restriction->is_ht);
  584. }
  585. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  586. }
  587. static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
  588. const char __user *user_buf,
  589. size_t count, loff_t *ppos)
  590. {
  591. struct iwl_priv *priv = file->private_data;
  592. char buf[8];
  593. int buf_size;
  594. int ht40;
  595. memset(buf, 0, sizeof(buf));
  596. buf_size = min(count, sizeof(buf) - 1);
  597. if (copy_from_user(buf, user_buf, buf_size))
  598. return -EFAULT;
  599. if (sscanf(buf, "%d", &ht40) != 1)
  600. return -EFAULT;
  601. if (!iwl_is_any_associated(priv))
  602. priv->disable_ht40 = ht40 ? true : false;
  603. else {
  604. IWL_ERR(priv, "Sta associated with AP - "
  605. "Change to 40MHz channel support is not allowed\n");
  606. return -EINVAL;
  607. }
  608. return count;
  609. }
  610. static ssize_t iwl_dbgfs_disable_ht40_read(struct file *file,
  611. char __user *user_buf,
  612. size_t count, loff_t *ppos)
  613. {
  614. struct iwl_priv *priv = file->private_data;
  615. char buf[100];
  616. int pos = 0;
  617. const size_t bufsz = sizeof(buf);
  618. pos += scnprintf(buf + pos, bufsz - pos,
  619. "11n 40MHz Mode: %s\n",
  620. priv->disable_ht40 ? "Disabled" : "Enabled");
  621. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  622. }
  623. static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
  624. const char __user *user_buf,
  625. size_t count, loff_t *ppos)
  626. {
  627. struct iwl_priv *priv = file->private_data;
  628. char buf[8];
  629. int buf_size;
  630. int value;
  631. memset(buf, 0, sizeof(buf));
  632. buf_size = min(count, sizeof(buf) - 1);
  633. if (copy_from_user(buf, user_buf, buf_size))
  634. return -EFAULT;
  635. if (sscanf(buf, "%d", &value) != 1)
  636. return -EINVAL;
  637. /*
  638. * Our users expect 0 to be "CAM", but 0 isn't actually
  639. * valid here. However, let's not confuse them and present
  640. * IWL_POWER_INDEX_1 as "1", not "0".
  641. */
  642. if (value == 0)
  643. return -EINVAL;
  644. else if (value > 0)
  645. value -= 1;
  646. if (value != -1 && (value < 0 || value >= IWL_POWER_NUM))
  647. return -EINVAL;
  648. if (!iwl_is_ready_rf(priv->shrd))
  649. return -EAGAIN;
  650. priv->power_data.debug_sleep_level_override = value;
  651. mutex_lock(&priv->shrd->mutex);
  652. iwl_power_update_mode(priv, true);
  653. mutex_unlock(&priv->shrd->mutex);
  654. return count;
  655. }
  656. static ssize_t iwl_dbgfs_sleep_level_override_read(struct file *file,
  657. char __user *user_buf,
  658. size_t count, loff_t *ppos)
  659. {
  660. struct iwl_priv *priv = file->private_data;
  661. char buf[10];
  662. int pos, value;
  663. const size_t bufsz = sizeof(buf);
  664. /* see the write function */
  665. value = priv->power_data.debug_sleep_level_override;
  666. if (value >= 0)
  667. value += 1;
  668. pos = scnprintf(buf, bufsz, "%d\n", value);
  669. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  670. }
  671. static ssize_t iwl_dbgfs_current_sleep_command_read(struct file *file,
  672. char __user *user_buf,
  673. size_t count, loff_t *ppos)
  674. {
  675. struct iwl_priv *priv = file->private_data;
  676. char buf[200];
  677. int pos = 0, i;
  678. const size_t bufsz = sizeof(buf);
  679. struct iwl_powertable_cmd *cmd = &priv->power_data.sleep_cmd;
  680. pos += scnprintf(buf + pos, bufsz - pos,
  681. "flags: %#.2x\n", le16_to_cpu(cmd->flags));
  682. pos += scnprintf(buf + pos, bufsz - pos,
  683. "RX/TX timeout: %d/%d usec\n",
  684. le32_to_cpu(cmd->rx_data_timeout),
  685. le32_to_cpu(cmd->tx_data_timeout));
  686. for (i = 0; i < IWL_POWER_VEC_SIZE; i++)
  687. pos += scnprintf(buf + pos, bufsz - pos,
  688. "sleep_interval[%d]: %d\n", i,
  689. le32_to_cpu(cmd->sleep_interval[i]));
  690. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  691. }
  692. DEBUGFS_READ_WRITE_FILE_OPS(sram);
  693. DEBUGFS_READ_FILE_OPS(wowlan_sram);
  694. DEBUGFS_READ_FILE_OPS(nvm);
  695. DEBUGFS_READ_FILE_OPS(stations);
  696. DEBUGFS_READ_FILE_OPS(channels);
  697. DEBUGFS_READ_FILE_OPS(status);
  698. DEBUGFS_READ_WRITE_FILE_OPS(rx_handlers);
  699. DEBUGFS_READ_FILE_OPS(qos);
  700. DEBUGFS_READ_FILE_OPS(thermal_throttling);
  701. DEBUGFS_READ_WRITE_FILE_OPS(disable_ht40);
  702. DEBUGFS_READ_WRITE_FILE_OPS(sleep_level_override);
  703. DEBUGFS_READ_FILE_OPS(current_sleep_command);
  704. static const char *fmt_value = " %-30s %10u\n";
  705. static const char *fmt_hex = " %-30s 0x%02X\n";
  706. static const char *fmt_table = " %-30s %10u %10u %10u %10u\n";
  707. static const char *fmt_header =
  708. "%-32s current cumulative delta max\n";
  709. static int iwl_statistics_flag(struct iwl_priv *priv, char *buf, int bufsz)
  710. {
  711. int p = 0;
  712. u32 flag;
  713. flag = le32_to_cpu(priv->statistics.flag);
  714. p += scnprintf(buf + p, bufsz - p, "Statistics Flag(0x%X):\n", flag);
  715. if (flag & UCODE_STATISTICS_CLEAR_MSK)
  716. p += scnprintf(buf + p, bufsz - p,
  717. "\tStatistics have been cleared\n");
  718. p += scnprintf(buf + p, bufsz - p, "\tOperational Frequency: %s\n",
  719. (flag & UCODE_STATISTICS_FREQUENCY_MSK)
  720. ? "2.4 GHz" : "5.2 GHz");
  721. p += scnprintf(buf + p, bufsz - p, "\tTGj Narrow Band: %s\n",
  722. (flag & UCODE_STATISTICS_NARROW_BAND_MSK)
  723. ? "enabled" : "disabled");
  724. return p;
  725. }
  726. static ssize_t iwl_dbgfs_ucode_rx_stats_read(struct file *file,
  727. char __user *user_buf,
  728. size_t count, loff_t *ppos)
  729. {
  730. struct iwl_priv *priv = file->private_data;
  731. int pos = 0;
  732. char *buf;
  733. int bufsz = sizeof(struct statistics_rx_phy) * 40 +
  734. sizeof(struct statistics_rx_non_phy) * 40 +
  735. sizeof(struct statistics_rx_ht_phy) * 40 + 400;
  736. ssize_t ret;
  737. struct statistics_rx_phy *ofdm, *accum_ofdm, *delta_ofdm, *max_ofdm;
  738. struct statistics_rx_phy *cck, *accum_cck, *delta_cck, *max_cck;
  739. struct statistics_rx_non_phy *general, *accum_general;
  740. struct statistics_rx_non_phy *delta_general, *max_general;
  741. struct statistics_rx_ht_phy *ht, *accum_ht, *delta_ht, *max_ht;
  742. if (!iwl_is_alive(priv->shrd))
  743. return -EAGAIN;
  744. buf = kzalloc(bufsz, GFP_KERNEL);
  745. if (!buf) {
  746. IWL_ERR(priv, "Can not allocate Buffer\n");
  747. return -ENOMEM;
  748. }
  749. /*
  750. * the statistic information display here is based on
  751. * the last statistics notification from uCode
  752. * might not reflect the current uCode activity
  753. */
  754. ofdm = &priv->statistics.rx_ofdm;
  755. cck = &priv->statistics.rx_cck;
  756. general = &priv->statistics.rx_non_phy;
  757. ht = &priv->statistics.rx_ofdm_ht;
  758. accum_ofdm = &priv->accum_stats.rx_ofdm;
  759. accum_cck = &priv->accum_stats.rx_cck;
  760. accum_general = &priv->accum_stats.rx_non_phy;
  761. accum_ht = &priv->accum_stats.rx_ofdm_ht;
  762. delta_ofdm = &priv->delta_stats.rx_ofdm;
  763. delta_cck = &priv->delta_stats.rx_cck;
  764. delta_general = &priv->delta_stats.rx_non_phy;
  765. delta_ht = &priv->delta_stats.rx_ofdm_ht;
  766. max_ofdm = &priv->max_delta_stats.rx_ofdm;
  767. max_cck = &priv->max_delta_stats.rx_cck;
  768. max_general = &priv->max_delta_stats.rx_non_phy;
  769. max_ht = &priv->max_delta_stats.rx_ofdm_ht;
  770. pos += iwl_statistics_flag(priv, buf, bufsz);
  771. pos += scnprintf(buf + pos, bufsz - pos,
  772. fmt_header, "Statistics_Rx - OFDM:");
  773. pos += scnprintf(buf + pos, bufsz - pos,
  774. fmt_table, "ina_cnt:",
  775. le32_to_cpu(ofdm->ina_cnt),
  776. accum_ofdm->ina_cnt,
  777. delta_ofdm->ina_cnt, max_ofdm->ina_cnt);
  778. pos += scnprintf(buf + pos, bufsz - pos,
  779. fmt_table, "fina_cnt:",
  780. le32_to_cpu(ofdm->fina_cnt), accum_ofdm->fina_cnt,
  781. delta_ofdm->fina_cnt, max_ofdm->fina_cnt);
  782. pos += scnprintf(buf + pos, bufsz - pos,
  783. fmt_table, "plcp_err:",
  784. le32_to_cpu(ofdm->plcp_err), accum_ofdm->plcp_err,
  785. delta_ofdm->plcp_err, max_ofdm->plcp_err);
  786. pos += scnprintf(buf + pos, bufsz - pos,
  787. fmt_table, "crc32_err:",
  788. le32_to_cpu(ofdm->crc32_err), accum_ofdm->crc32_err,
  789. delta_ofdm->crc32_err, max_ofdm->crc32_err);
  790. pos += scnprintf(buf + pos, bufsz - pos,
  791. fmt_table, "overrun_err:",
  792. le32_to_cpu(ofdm->overrun_err),
  793. accum_ofdm->overrun_err, delta_ofdm->overrun_err,
  794. max_ofdm->overrun_err);
  795. pos += scnprintf(buf + pos, bufsz - pos,
  796. fmt_table, "early_overrun_err:",
  797. le32_to_cpu(ofdm->early_overrun_err),
  798. accum_ofdm->early_overrun_err,
  799. delta_ofdm->early_overrun_err,
  800. max_ofdm->early_overrun_err);
  801. pos += scnprintf(buf + pos, bufsz - pos,
  802. fmt_table, "crc32_good:",
  803. le32_to_cpu(ofdm->crc32_good),
  804. accum_ofdm->crc32_good, delta_ofdm->crc32_good,
  805. max_ofdm->crc32_good);
  806. pos += scnprintf(buf + pos, bufsz - pos,
  807. fmt_table, "false_alarm_cnt:",
  808. le32_to_cpu(ofdm->false_alarm_cnt),
  809. accum_ofdm->false_alarm_cnt,
  810. delta_ofdm->false_alarm_cnt,
  811. max_ofdm->false_alarm_cnt);
  812. pos += scnprintf(buf + pos, bufsz - pos,
  813. fmt_table, "fina_sync_err_cnt:",
  814. le32_to_cpu(ofdm->fina_sync_err_cnt),
  815. accum_ofdm->fina_sync_err_cnt,
  816. delta_ofdm->fina_sync_err_cnt,
  817. max_ofdm->fina_sync_err_cnt);
  818. pos += scnprintf(buf + pos, bufsz - pos,
  819. fmt_table, "sfd_timeout:",
  820. le32_to_cpu(ofdm->sfd_timeout),
  821. accum_ofdm->sfd_timeout, delta_ofdm->sfd_timeout,
  822. max_ofdm->sfd_timeout);
  823. pos += scnprintf(buf + pos, bufsz - pos,
  824. fmt_table, "fina_timeout:",
  825. le32_to_cpu(ofdm->fina_timeout),
  826. accum_ofdm->fina_timeout, delta_ofdm->fina_timeout,
  827. max_ofdm->fina_timeout);
  828. pos += scnprintf(buf + pos, bufsz - pos,
  829. fmt_table, "unresponded_rts:",
  830. le32_to_cpu(ofdm->unresponded_rts),
  831. accum_ofdm->unresponded_rts,
  832. delta_ofdm->unresponded_rts,
  833. max_ofdm->unresponded_rts);
  834. pos += scnprintf(buf + pos, bufsz - pos,
  835. fmt_table, "rxe_frame_lmt_ovrun:",
  836. le32_to_cpu(ofdm->rxe_frame_limit_overrun),
  837. accum_ofdm->rxe_frame_limit_overrun,
  838. delta_ofdm->rxe_frame_limit_overrun,
  839. max_ofdm->rxe_frame_limit_overrun);
  840. pos += scnprintf(buf + pos, bufsz - pos,
  841. fmt_table, "sent_ack_cnt:",
  842. le32_to_cpu(ofdm->sent_ack_cnt),
  843. accum_ofdm->sent_ack_cnt, delta_ofdm->sent_ack_cnt,
  844. max_ofdm->sent_ack_cnt);
  845. pos += scnprintf(buf + pos, bufsz - pos,
  846. fmt_table, "sent_cts_cnt:",
  847. le32_to_cpu(ofdm->sent_cts_cnt),
  848. accum_ofdm->sent_cts_cnt, delta_ofdm->sent_cts_cnt,
  849. max_ofdm->sent_cts_cnt);
  850. pos += scnprintf(buf + pos, bufsz - pos,
  851. fmt_table, "sent_ba_rsp_cnt:",
  852. le32_to_cpu(ofdm->sent_ba_rsp_cnt),
  853. accum_ofdm->sent_ba_rsp_cnt,
  854. delta_ofdm->sent_ba_rsp_cnt,
  855. max_ofdm->sent_ba_rsp_cnt);
  856. pos += scnprintf(buf + pos, bufsz - pos,
  857. fmt_table, "dsp_self_kill:",
  858. le32_to_cpu(ofdm->dsp_self_kill),
  859. accum_ofdm->dsp_self_kill,
  860. delta_ofdm->dsp_self_kill,
  861. max_ofdm->dsp_self_kill);
  862. pos += scnprintf(buf + pos, bufsz - pos,
  863. fmt_table, "mh_format_err:",
  864. le32_to_cpu(ofdm->mh_format_err),
  865. accum_ofdm->mh_format_err,
  866. delta_ofdm->mh_format_err,
  867. max_ofdm->mh_format_err);
  868. pos += scnprintf(buf + pos, bufsz - pos,
  869. fmt_table, "re_acq_main_rssi_sum:",
  870. le32_to_cpu(ofdm->re_acq_main_rssi_sum),
  871. accum_ofdm->re_acq_main_rssi_sum,
  872. delta_ofdm->re_acq_main_rssi_sum,
  873. max_ofdm->re_acq_main_rssi_sum);
  874. pos += scnprintf(buf + pos, bufsz - pos,
  875. fmt_header, "Statistics_Rx - CCK:");
  876. pos += scnprintf(buf + pos, bufsz - pos,
  877. fmt_table, "ina_cnt:",
  878. le32_to_cpu(cck->ina_cnt), accum_cck->ina_cnt,
  879. delta_cck->ina_cnt, max_cck->ina_cnt);
  880. pos += scnprintf(buf + pos, bufsz - pos,
  881. fmt_table, "fina_cnt:",
  882. le32_to_cpu(cck->fina_cnt), accum_cck->fina_cnt,
  883. delta_cck->fina_cnt, max_cck->fina_cnt);
  884. pos += scnprintf(buf + pos, bufsz - pos,
  885. fmt_table, "plcp_err:",
  886. le32_to_cpu(cck->plcp_err), accum_cck->plcp_err,
  887. delta_cck->plcp_err, max_cck->plcp_err);
  888. pos += scnprintf(buf + pos, bufsz - pos,
  889. fmt_table, "crc32_err:",
  890. le32_to_cpu(cck->crc32_err), accum_cck->crc32_err,
  891. delta_cck->crc32_err, max_cck->crc32_err);
  892. pos += scnprintf(buf + pos, bufsz - pos,
  893. fmt_table, "overrun_err:",
  894. le32_to_cpu(cck->overrun_err),
  895. accum_cck->overrun_err, delta_cck->overrun_err,
  896. max_cck->overrun_err);
  897. pos += scnprintf(buf + pos, bufsz - pos,
  898. fmt_table, "early_overrun_err:",
  899. le32_to_cpu(cck->early_overrun_err),
  900. accum_cck->early_overrun_err,
  901. delta_cck->early_overrun_err,
  902. max_cck->early_overrun_err);
  903. pos += scnprintf(buf + pos, bufsz - pos,
  904. fmt_table, "crc32_good:",
  905. le32_to_cpu(cck->crc32_good), accum_cck->crc32_good,
  906. delta_cck->crc32_good, max_cck->crc32_good);
  907. pos += scnprintf(buf + pos, bufsz - pos,
  908. fmt_table, "false_alarm_cnt:",
  909. le32_to_cpu(cck->false_alarm_cnt),
  910. accum_cck->false_alarm_cnt,
  911. delta_cck->false_alarm_cnt, max_cck->false_alarm_cnt);
  912. pos += scnprintf(buf + pos, bufsz - pos,
  913. fmt_table, "fina_sync_err_cnt:",
  914. le32_to_cpu(cck->fina_sync_err_cnt),
  915. accum_cck->fina_sync_err_cnt,
  916. delta_cck->fina_sync_err_cnt,
  917. max_cck->fina_sync_err_cnt);
  918. pos += scnprintf(buf + pos, bufsz - pos,
  919. fmt_table, "sfd_timeout:",
  920. le32_to_cpu(cck->sfd_timeout),
  921. accum_cck->sfd_timeout, delta_cck->sfd_timeout,
  922. max_cck->sfd_timeout);
  923. pos += scnprintf(buf + pos, bufsz - pos,
  924. fmt_table, "fina_timeout:",
  925. le32_to_cpu(cck->fina_timeout),
  926. accum_cck->fina_timeout, delta_cck->fina_timeout,
  927. max_cck->fina_timeout);
  928. pos += scnprintf(buf + pos, bufsz - pos,
  929. fmt_table, "unresponded_rts:",
  930. le32_to_cpu(cck->unresponded_rts),
  931. accum_cck->unresponded_rts, delta_cck->unresponded_rts,
  932. max_cck->unresponded_rts);
  933. pos += scnprintf(buf + pos, bufsz - pos,
  934. fmt_table, "rxe_frame_lmt_ovrun:",
  935. le32_to_cpu(cck->rxe_frame_limit_overrun),
  936. accum_cck->rxe_frame_limit_overrun,
  937. delta_cck->rxe_frame_limit_overrun,
  938. max_cck->rxe_frame_limit_overrun);
  939. pos += scnprintf(buf + pos, bufsz - pos,
  940. fmt_table, "sent_ack_cnt:",
  941. le32_to_cpu(cck->sent_ack_cnt),
  942. accum_cck->sent_ack_cnt, delta_cck->sent_ack_cnt,
  943. max_cck->sent_ack_cnt);
  944. pos += scnprintf(buf + pos, bufsz - pos,
  945. fmt_table, "sent_cts_cnt:",
  946. le32_to_cpu(cck->sent_cts_cnt),
  947. accum_cck->sent_cts_cnt, delta_cck->sent_cts_cnt,
  948. max_cck->sent_cts_cnt);
  949. pos += scnprintf(buf + pos, bufsz - pos,
  950. fmt_table, "sent_ba_rsp_cnt:",
  951. le32_to_cpu(cck->sent_ba_rsp_cnt),
  952. accum_cck->sent_ba_rsp_cnt,
  953. delta_cck->sent_ba_rsp_cnt,
  954. max_cck->sent_ba_rsp_cnt);
  955. pos += scnprintf(buf + pos, bufsz - pos,
  956. fmt_table, "dsp_self_kill:",
  957. le32_to_cpu(cck->dsp_self_kill),
  958. accum_cck->dsp_self_kill, delta_cck->dsp_self_kill,
  959. max_cck->dsp_self_kill);
  960. pos += scnprintf(buf + pos, bufsz - pos,
  961. fmt_table, "mh_format_err:",
  962. le32_to_cpu(cck->mh_format_err),
  963. accum_cck->mh_format_err, delta_cck->mh_format_err,
  964. max_cck->mh_format_err);
  965. pos += scnprintf(buf + pos, bufsz - pos,
  966. fmt_table, "re_acq_main_rssi_sum:",
  967. le32_to_cpu(cck->re_acq_main_rssi_sum),
  968. accum_cck->re_acq_main_rssi_sum,
  969. delta_cck->re_acq_main_rssi_sum,
  970. max_cck->re_acq_main_rssi_sum);
  971. pos += scnprintf(buf + pos, bufsz - pos,
  972. fmt_header, "Statistics_Rx - GENERAL:");
  973. pos += scnprintf(buf + pos, bufsz - pos,
  974. fmt_table, "bogus_cts:",
  975. le32_to_cpu(general->bogus_cts),
  976. accum_general->bogus_cts, delta_general->bogus_cts,
  977. max_general->bogus_cts);
  978. pos += scnprintf(buf + pos, bufsz - pos,
  979. fmt_table, "bogus_ack:",
  980. le32_to_cpu(general->bogus_ack),
  981. accum_general->bogus_ack, delta_general->bogus_ack,
  982. max_general->bogus_ack);
  983. pos += scnprintf(buf + pos, bufsz - pos,
  984. fmt_table, "non_bssid_frames:",
  985. le32_to_cpu(general->non_bssid_frames),
  986. accum_general->non_bssid_frames,
  987. delta_general->non_bssid_frames,
  988. max_general->non_bssid_frames);
  989. pos += scnprintf(buf + pos, bufsz - pos,
  990. fmt_table, "filtered_frames:",
  991. le32_to_cpu(general->filtered_frames),
  992. accum_general->filtered_frames,
  993. delta_general->filtered_frames,
  994. max_general->filtered_frames);
  995. pos += scnprintf(buf + pos, bufsz - pos,
  996. fmt_table, "non_channel_beacons:",
  997. le32_to_cpu(general->non_channel_beacons),
  998. accum_general->non_channel_beacons,
  999. delta_general->non_channel_beacons,
  1000. max_general->non_channel_beacons);
  1001. pos += scnprintf(buf + pos, bufsz - pos,
  1002. fmt_table, "channel_beacons:",
  1003. le32_to_cpu(general->channel_beacons),
  1004. accum_general->channel_beacons,
  1005. delta_general->channel_beacons,
  1006. max_general->channel_beacons);
  1007. pos += scnprintf(buf + pos, bufsz - pos,
  1008. fmt_table, "num_missed_bcon:",
  1009. le32_to_cpu(general->num_missed_bcon),
  1010. accum_general->num_missed_bcon,
  1011. delta_general->num_missed_bcon,
  1012. max_general->num_missed_bcon);
  1013. pos += scnprintf(buf + pos, bufsz - pos,
  1014. fmt_table, "adc_rx_saturation_time:",
  1015. le32_to_cpu(general->adc_rx_saturation_time),
  1016. accum_general->adc_rx_saturation_time,
  1017. delta_general->adc_rx_saturation_time,
  1018. max_general->adc_rx_saturation_time);
  1019. pos += scnprintf(buf + pos, bufsz - pos,
  1020. fmt_table, "ina_detect_search_tm:",
  1021. le32_to_cpu(general->ina_detection_search_time),
  1022. accum_general->ina_detection_search_time,
  1023. delta_general->ina_detection_search_time,
  1024. max_general->ina_detection_search_time);
  1025. pos += scnprintf(buf + pos, bufsz - pos,
  1026. fmt_table, "beacon_silence_rssi_a:",
  1027. le32_to_cpu(general->beacon_silence_rssi_a),
  1028. accum_general->beacon_silence_rssi_a,
  1029. delta_general->beacon_silence_rssi_a,
  1030. max_general->beacon_silence_rssi_a);
  1031. pos += scnprintf(buf + pos, bufsz - pos,
  1032. fmt_table, "beacon_silence_rssi_b:",
  1033. le32_to_cpu(general->beacon_silence_rssi_b),
  1034. accum_general->beacon_silence_rssi_b,
  1035. delta_general->beacon_silence_rssi_b,
  1036. max_general->beacon_silence_rssi_b);
  1037. pos += scnprintf(buf + pos, bufsz - pos,
  1038. fmt_table, "beacon_silence_rssi_c:",
  1039. le32_to_cpu(general->beacon_silence_rssi_c),
  1040. accum_general->beacon_silence_rssi_c,
  1041. delta_general->beacon_silence_rssi_c,
  1042. max_general->beacon_silence_rssi_c);
  1043. pos += scnprintf(buf + pos, bufsz - pos,
  1044. fmt_table, "interference_data_flag:",
  1045. le32_to_cpu(general->interference_data_flag),
  1046. accum_general->interference_data_flag,
  1047. delta_general->interference_data_flag,
  1048. max_general->interference_data_flag);
  1049. pos += scnprintf(buf + pos, bufsz - pos,
  1050. fmt_table, "channel_load:",
  1051. le32_to_cpu(general->channel_load),
  1052. accum_general->channel_load,
  1053. delta_general->channel_load,
  1054. max_general->channel_load);
  1055. pos += scnprintf(buf + pos, bufsz - pos,
  1056. fmt_table, "dsp_false_alarms:",
  1057. le32_to_cpu(general->dsp_false_alarms),
  1058. accum_general->dsp_false_alarms,
  1059. delta_general->dsp_false_alarms,
  1060. max_general->dsp_false_alarms);
  1061. pos += scnprintf(buf + pos, bufsz - pos,
  1062. fmt_table, "beacon_rssi_a:",
  1063. le32_to_cpu(general->beacon_rssi_a),
  1064. accum_general->beacon_rssi_a,
  1065. delta_general->beacon_rssi_a,
  1066. max_general->beacon_rssi_a);
  1067. pos += scnprintf(buf + pos, bufsz - pos,
  1068. fmt_table, "beacon_rssi_b:",
  1069. le32_to_cpu(general->beacon_rssi_b),
  1070. accum_general->beacon_rssi_b,
  1071. delta_general->beacon_rssi_b,
  1072. max_general->beacon_rssi_b);
  1073. pos += scnprintf(buf + pos, bufsz - pos,
  1074. fmt_table, "beacon_rssi_c:",
  1075. le32_to_cpu(general->beacon_rssi_c),
  1076. accum_general->beacon_rssi_c,
  1077. delta_general->beacon_rssi_c,
  1078. max_general->beacon_rssi_c);
  1079. pos += scnprintf(buf + pos, bufsz - pos,
  1080. fmt_table, "beacon_energy_a:",
  1081. le32_to_cpu(general->beacon_energy_a),
  1082. accum_general->beacon_energy_a,
  1083. delta_general->beacon_energy_a,
  1084. max_general->beacon_energy_a);
  1085. pos += scnprintf(buf + pos, bufsz - pos,
  1086. fmt_table, "beacon_energy_b:",
  1087. le32_to_cpu(general->beacon_energy_b),
  1088. accum_general->beacon_energy_b,
  1089. delta_general->beacon_energy_b,
  1090. max_general->beacon_energy_b);
  1091. pos += scnprintf(buf + pos, bufsz - pos,
  1092. fmt_table, "beacon_energy_c:",
  1093. le32_to_cpu(general->beacon_energy_c),
  1094. accum_general->beacon_energy_c,
  1095. delta_general->beacon_energy_c,
  1096. max_general->beacon_energy_c);
  1097. pos += scnprintf(buf + pos, bufsz - pos,
  1098. fmt_header, "Statistics_Rx - OFDM_HT:");
  1099. pos += scnprintf(buf + pos, bufsz - pos,
  1100. fmt_table, "plcp_err:",
  1101. le32_to_cpu(ht->plcp_err), accum_ht->plcp_err,
  1102. delta_ht->plcp_err, max_ht->plcp_err);
  1103. pos += scnprintf(buf + pos, bufsz - pos,
  1104. fmt_table, "overrun_err:",
  1105. le32_to_cpu(ht->overrun_err), accum_ht->overrun_err,
  1106. delta_ht->overrun_err, max_ht->overrun_err);
  1107. pos += scnprintf(buf + pos, bufsz - pos,
  1108. fmt_table, "early_overrun_err:",
  1109. le32_to_cpu(ht->early_overrun_err),
  1110. accum_ht->early_overrun_err,
  1111. delta_ht->early_overrun_err,
  1112. max_ht->early_overrun_err);
  1113. pos += scnprintf(buf + pos, bufsz - pos,
  1114. fmt_table, "crc32_good:",
  1115. le32_to_cpu(ht->crc32_good), accum_ht->crc32_good,
  1116. delta_ht->crc32_good, max_ht->crc32_good);
  1117. pos += scnprintf(buf + pos, bufsz - pos,
  1118. fmt_table, "crc32_err:",
  1119. le32_to_cpu(ht->crc32_err), accum_ht->crc32_err,
  1120. delta_ht->crc32_err, max_ht->crc32_err);
  1121. pos += scnprintf(buf + pos, bufsz - pos,
  1122. fmt_table, "mh_format_err:",
  1123. le32_to_cpu(ht->mh_format_err),
  1124. accum_ht->mh_format_err,
  1125. delta_ht->mh_format_err, max_ht->mh_format_err);
  1126. pos += scnprintf(buf + pos, bufsz - pos,
  1127. fmt_table, "agg_crc32_good:",
  1128. le32_to_cpu(ht->agg_crc32_good),
  1129. accum_ht->agg_crc32_good,
  1130. delta_ht->agg_crc32_good, max_ht->agg_crc32_good);
  1131. pos += scnprintf(buf + pos, bufsz - pos,
  1132. fmt_table, "agg_mpdu_cnt:",
  1133. le32_to_cpu(ht->agg_mpdu_cnt),
  1134. accum_ht->agg_mpdu_cnt,
  1135. delta_ht->agg_mpdu_cnt, max_ht->agg_mpdu_cnt);
  1136. pos += scnprintf(buf + pos, bufsz - pos,
  1137. fmt_table, "agg_cnt:",
  1138. le32_to_cpu(ht->agg_cnt), accum_ht->agg_cnt,
  1139. delta_ht->agg_cnt, max_ht->agg_cnt);
  1140. pos += scnprintf(buf + pos, bufsz - pos,
  1141. fmt_table, "unsupport_mcs:",
  1142. le32_to_cpu(ht->unsupport_mcs),
  1143. accum_ht->unsupport_mcs,
  1144. delta_ht->unsupport_mcs, max_ht->unsupport_mcs);
  1145. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  1146. kfree(buf);
  1147. return ret;
  1148. }
  1149. static ssize_t iwl_dbgfs_ucode_tx_stats_read(struct file *file,
  1150. char __user *user_buf,
  1151. size_t count, loff_t *ppos)
  1152. {
  1153. struct iwl_priv *priv = file->private_data;
  1154. int pos = 0;
  1155. char *buf;
  1156. int bufsz = (sizeof(struct statistics_tx) * 48) + 250;
  1157. ssize_t ret;
  1158. struct statistics_tx *tx, *accum_tx, *delta_tx, *max_tx;
  1159. if (!iwl_is_alive(priv->shrd))
  1160. return -EAGAIN;
  1161. buf = kzalloc(bufsz, GFP_KERNEL);
  1162. if (!buf) {
  1163. IWL_ERR(priv, "Can not allocate Buffer\n");
  1164. return -ENOMEM;
  1165. }
  1166. /* the statistic information display here is based on
  1167. * the last statistics notification from uCode
  1168. * might not reflect the current uCode activity
  1169. */
  1170. tx = &priv->statistics.tx;
  1171. accum_tx = &priv->accum_stats.tx;
  1172. delta_tx = &priv->delta_stats.tx;
  1173. max_tx = &priv->max_delta_stats.tx;
  1174. pos += iwl_statistics_flag(priv, buf, bufsz);
  1175. pos += scnprintf(buf + pos, bufsz - pos,
  1176. fmt_header, "Statistics_Tx:");
  1177. pos += scnprintf(buf + pos, bufsz - pos,
  1178. fmt_table, "preamble:",
  1179. le32_to_cpu(tx->preamble_cnt),
  1180. accum_tx->preamble_cnt,
  1181. delta_tx->preamble_cnt, max_tx->preamble_cnt);
  1182. pos += scnprintf(buf + pos, bufsz - pos,
  1183. fmt_table, "rx_detected_cnt:",
  1184. le32_to_cpu(tx->rx_detected_cnt),
  1185. accum_tx->rx_detected_cnt,
  1186. delta_tx->rx_detected_cnt, max_tx->rx_detected_cnt);
  1187. pos += scnprintf(buf + pos, bufsz - pos,
  1188. fmt_table, "bt_prio_defer_cnt:",
  1189. le32_to_cpu(tx->bt_prio_defer_cnt),
  1190. accum_tx->bt_prio_defer_cnt,
  1191. delta_tx->bt_prio_defer_cnt,
  1192. max_tx->bt_prio_defer_cnt);
  1193. pos += scnprintf(buf + pos, bufsz - pos,
  1194. fmt_table, "bt_prio_kill_cnt:",
  1195. le32_to_cpu(tx->bt_prio_kill_cnt),
  1196. accum_tx->bt_prio_kill_cnt,
  1197. delta_tx->bt_prio_kill_cnt,
  1198. max_tx->bt_prio_kill_cnt);
  1199. pos += scnprintf(buf + pos, bufsz - pos,
  1200. fmt_table, "few_bytes_cnt:",
  1201. le32_to_cpu(tx->few_bytes_cnt),
  1202. accum_tx->few_bytes_cnt,
  1203. delta_tx->few_bytes_cnt, max_tx->few_bytes_cnt);
  1204. pos += scnprintf(buf + pos, bufsz - pos,
  1205. fmt_table, "cts_timeout:",
  1206. le32_to_cpu(tx->cts_timeout), accum_tx->cts_timeout,
  1207. delta_tx->cts_timeout, max_tx->cts_timeout);
  1208. pos += scnprintf(buf + pos, bufsz - pos,
  1209. fmt_table, "ack_timeout:",
  1210. le32_to_cpu(tx->ack_timeout),
  1211. accum_tx->ack_timeout,
  1212. delta_tx->ack_timeout, max_tx->ack_timeout);
  1213. pos += scnprintf(buf + pos, bufsz - pos,
  1214. fmt_table, "expected_ack_cnt:",
  1215. le32_to_cpu(tx->expected_ack_cnt),
  1216. accum_tx->expected_ack_cnt,
  1217. delta_tx->expected_ack_cnt,
  1218. max_tx->expected_ack_cnt);
  1219. pos += scnprintf(buf + pos, bufsz - pos,
  1220. fmt_table, "actual_ack_cnt:",
  1221. le32_to_cpu(tx->actual_ack_cnt),
  1222. accum_tx->actual_ack_cnt,
  1223. delta_tx->actual_ack_cnt,
  1224. max_tx->actual_ack_cnt);
  1225. pos += scnprintf(buf + pos, bufsz - pos,
  1226. fmt_table, "dump_msdu_cnt:",
  1227. le32_to_cpu(tx->dump_msdu_cnt),
  1228. accum_tx->dump_msdu_cnt,
  1229. delta_tx->dump_msdu_cnt,
  1230. max_tx->dump_msdu_cnt);
  1231. pos += scnprintf(buf + pos, bufsz - pos,
  1232. fmt_table, "abort_nxt_frame_mismatch:",
  1233. le32_to_cpu(tx->burst_abort_next_frame_mismatch_cnt),
  1234. accum_tx->burst_abort_next_frame_mismatch_cnt,
  1235. delta_tx->burst_abort_next_frame_mismatch_cnt,
  1236. max_tx->burst_abort_next_frame_mismatch_cnt);
  1237. pos += scnprintf(buf + pos, bufsz - pos,
  1238. fmt_table, "abort_missing_nxt_frame:",
  1239. le32_to_cpu(tx->burst_abort_missing_next_frame_cnt),
  1240. accum_tx->burst_abort_missing_next_frame_cnt,
  1241. delta_tx->burst_abort_missing_next_frame_cnt,
  1242. max_tx->burst_abort_missing_next_frame_cnt);
  1243. pos += scnprintf(buf + pos, bufsz - pos,
  1244. fmt_table, "cts_timeout_collision:",
  1245. le32_to_cpu(tx->cts_timeout_collision),
  1246. accum_tx->cts_timeout_collision,
  1247. delta_tx->cts_timeout_collision,
  1248. max_tx->cts_timeout_collision);
  1249. pos += scnprintf(buf + pos, bufsz - pos,
  1250. fmt_table, "ack_ba_timeout_collision:",
  1251. le32_to_cpu(tx->ack_or_ba_timeout_collision),
  1252. accum_tx->ack_or_ba_timeout_collision,
  1253. delta_tx->ack_or_ba_timeout_collision,
  1254. max_tx->ack_or_ba_timeout_collision);
  1255. pos += scnprintf(buf + pos, bufsz - pos,
  1256. fmt_table, "agg ba_timeout:",
  1257. le32_to_cpu(tx->agg.ba_timeout),
  1258. accum_tx->agg.ba_timeout,
  1259. delta_tx->agg.ba_timeout,
  1260. max_tx->agg.ba_timeout);
  1261. pos += scnprintf(buf + pos, bufsz - pos,
  1262. fmt_table, "agg ba_resched_frames:",
  1263. le32_to_cpu(tx->agg.ba_reschedule_frames),
  1264. accum_tx->agg.ba_reschedule_frames,
  1265. delta_tx->agg.ba_reschedule_frames,
  1266. max_tx->agg.ba_reschedule_frames);
  1267. pos += scnprintf(buf + pos, bufsz - pos,
  1268. fmt_table, "agg scd_query_agg_frame:",
  1269. le32_to_cpu(tx->agg.scd_query_agg_frame_cnt),
  1270. accum_tx->agg.scd_query_agg_frame_cnt,
  1271. delta_tx->agg.scd_query_agg_frame_cnt,
  1272. max_tx->agg.scd_query_agg_frame_cnt);
  1273. pos += scnprintf(buf + pos, bufsz - pos,
  1274. fmt_table, "agg scd_query_no_agg:",
  1275. le32_to_cpu(tx->agg.scd_query_no_agg),
  1276. accum_tx->agg.scd_query_no_agg,
  1277. delta_tx->agg.scd_query_no_agg,
  1278. max_tx->agg.scd_query_no_agg);
  1279. pos += scnprintf(buf + pos, bufsz - pos,
  1280. fmt_table, "agg scd_query_agg:",
  1281. le32_to_cpu(tx->agg.scd_query_agg),
  1282. accum_tx->agg.scd_query_agg,
  1283. delta_tx->agg.scd_query_agg,
  1284. max_tx->agg.scd_query_agg);
  1285. pos += scnprintf(buf + pos, bufsz - pos,
  1286. fmt_table, "agg scd_query_mismatch:",
  1287. le32_to_cpu(tx->agg.scd_query_mismatch),
  1288. accum_tx->agg.scd_query_mismatch,
  1289. delta_tx->agg.scd_query_mismatch,
  1290. max_tx->agg.scd_query_mismatch);
  1291. pos += scnprintf(buf + pos, bufsz - pos,
  1292. fmt_table, "agg frame_not_ready:",
  1293. le32_to_cpu(tx->agg.frame_not_ready),
  1294. accum_tx->agg.frame_not_ready,
  1295. delta_tx->agg.frame_not_ready,
  1296. max_tx->agg.frame_not_ready);
  1297. pos += scnprintf(buf + pos, bufsz - pos,
  1298. fmt_table, "agg underrun:",
  1299. le32_to_cpu(tx->agg.underrun),
  1300. accum_tx->agg.underrun,
  1301. delta_tx->agg.underrun, max_tx->agg.underrun);
  1302. pos += scnprintf(buf + pos, bufsz - pos,
  1303. fmt_table, "agg bt_prio_kill:",
  1304. le32_to_cpu(tx->agg.bt_prio_kill),
  1305. accum_tx->agg.bt_prio_kill,
  1306. delta_tx->agg.bt_prio_kill,
  1307. max_tx->agg.bt_prio_kill);
  1308. pos += scnprintf(buf + pos, bufsz - pos,
  1309. fmt_table, "agg rx_ba_rsp_cnt:",
  1310. le32_to_cpu(tx->agg.rx_ba_rsp_cnt),
  1311. accum_tx->agg.rx_ba_rsp_cnt,
  1312. delta_tx->agg.rx_ba_rsp_cnt,
  1313. max_tx->agg.rx_ba_rsp_cnt);
  1314. if (tx->tx_power.ant_a || tx->tx_power.ant_b || tx->tx_power.ant_c) {
  1315. pos += scnprintf(buf + pos, bufsz - pos,
  1316. "tx power: (1/2 dB step)\n");
  1317. if ((priv->cfg->valid_tx_ant & ANT_A) && tx->tx_power.ant_a)
  1318. pos += scnprintf(buf + pos, bufsz - pos,
  1319. fmt_hex, "antenna A:",
  1320. tx->tx_power.ant_a);
  1321. if ((priv->cfg->valid_tx_ant & ANT_B) && tx->tx_power.ant_b)
  1322. pos += scnprintf(buf + pos, bufsz - pos,
  1323. fmt_hex, "antenna B:",
  1324. tx->tx_power.ant_b);
  1325. if ((priv->cfg->valid_tx_ant & ANT_C) && tx->tx_power.ant_c)
  1326. pos += scnprintf(buf + pos, bufsz - pos,
  1327. fmt_hex, "antenna C:",
  1328. tx->tx_power.ant_c);
  1329. }
  1330. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  1331. kfree(buf);
  1332. return ret;
  1333. }
  1334. static ssize_t iwl_dbgfs_ucode_general_stats_read(struct file *file,
  1335. char __user *user_buf,
  1336. size_t count, loff_t *ppos)
  1337. {
  1338. struct iwl_priv *priv = file->private_data;
  1339. int pos = 0;
  1340. char *buf;
  1341. int bufsz = sizeof(struct statistics_general) * 10 + 300;
  1342. ssize_t ret;
  1343. struct statistics_general_common *general, *accum_general;
  1344. struct statistics_general_common *delta_general, *max_general;
  1345. struct statistics_dbg *dbg, *accum_dbg, *delta_dbg, *max_dbg;
  1346. struct statistics_div *div, *accum_div, *delta_div, *max_div;
  1347. if (!iwl_is_alive(priv->shrd))
  1348. return -EAGAIN;
  1349. buf = kzalloc(bufsz, GFP_KERNEL);
  1350. if (!buf) {
  1351. IWL_ERR(priv, "Can not allocate Buffer\n");
  1352. return -ENOMEM;
  1353. }
  1354. /* the statistic information display here is based on
  1355. * the last statistics notification from uCode
  1356. * might not reflect the current uCode activity
  1357. */
  1358. general = &priv->statistics.common;
  1359. dbg = &priv->statistics.common.dbg;
  1360. div = &priv->statistics.common.div;
  1361. accum_general = &priv->accum_stats.common;
  1362. accum_dbg = &priv->accum_stats.common.dbg;
  1363. accum_div = &priv->accum_stats.common.div;
  1364. delta_general = &priv->delta_stats.common;
  1365. max_general = &priv->max_delta_stats.common;
  1366. delta_dbg = &priv->delta_stats.common.dbg;
  1367. max_dbg = &priv->max_delta_stats.common.dbg;
  1368. delta_div = &priv->delta_stats.common.div;
  1369. max_div = &priv->max_delta_stats.common.div;
  1370. pos += iwl_statistics_flag(priv, buf, bufsz);
  1371. pos += scnprintf(buf + pos, bufsz - pos,
  1372. fmt_header, "Statistics_General:");
  1373. pos += scnprintf(buf + pos, bufsz - pos,
  1374. fmt_value, "temperature:",
  1375. le32_to_cpu(general->temperature));
  1376. pos += scnprintf(buf + pos, bufsz - pos,
  1377. fmt_value, "temperature_m:",
  1378. le32_to_cpu(general->temperature_m));
  1379. pos += scnprintf(buf + pos, bufsz - pos,
  1380. fmt_value, "ttl_timestamp:",
  1381. le32_to_cpu(general->ttl_timestamp));
  1382. pos += scnprintf(buf + pos, bufsz - pos,
  1383. fmt_table, "burst_check:",
  1384. le32_to_cpu(dbg->burst_check),
  1385. accum_dbg->burst_check,
  1386. delta_dbg->burst_check, max_dbg->burst_check);
  1387. pos += scnprintf(buf + pos, bufsz - pos,
  1388. fmt_table, "burst_count:",
  1389. le32_to_cpu(dbg->burst_count),
  1390. accum_dbg->burst_count,
  1391. delta_dbg->burst_count, max_dbg->burst_count);
  1392. pos += scnprintf(buf + pos, bufsz - pos,
  1393. fmt_table, "wait_for_silence_timeout_count:",
  1394. le32_to_cpu(dbg->wait_for_silence_timeout_cnt),
  1395. accum_dbg->wait_for_silence_timeout_cnt,
  1396. delta_dbg->wait_for_silence_timeout_cnt,
  1397. max_dbg->wait_for_silence_timeout_cnt);
  1398. pos += scnprintf(buf + pos, bufsz - pos,
  1399. fmt_table, "sleep_time:",
  1400. le32_to_cpu(general->sleep_time),
  1401. accum_general->sleep_time,
  1402. delta_general->sleep_time, max_general->sleep_time);
  1403. pos += scnprintf(buf + pos, bufsz - pos,
  1404. fmt_table, "slots_out:",
  1405. le32_to_cpu(general->slots_out),
  1406. accum_general->slots_out,
  1407. delta_general->slots_out, max_general->slots_out);
  1408. pos += scnprintf(buf + pos, bufsz - pos,
  1409. fmt_table, "slots_idle:",
  1410. le32_to_cpu(general->slots_idle),
  1411. accum_general->slots_idle,
  1412. delta_general->slots_idle, max_general->slots_idle);
  1413. pos += scnprintf(buf + pos, bufsz - pos,
  1414. fmt_table, "tx_on_a:",
  1415. le32_to_cpu(div->tx_on_a), accum_div->tx_on_a,
  1416. delta_div->tx_on_a, max_div->tx_on_a);
  1417. pos += scnprintf(buf + pos, bufsz - pos,
  1418. fmt_table, "tx_on_b:",
  1419. le32_to_cpu(div->tx_on_b), accum_div->tx_on_b,
  1420. delta_div->tx_on_b, max_div->tx_on_b);
  1421. pos += scnprintf(buf + pos, bufsz - pos,
  1422. fmt_table, "exec_time:",
  1423. le32_to_cpu(div->exec_time), accum_div->exec_time,
  1424. delta_div->exec_time, max_div->exec_time);
  1425. pos += scnprintf(buf + pos, bufsz - pos,
  1426. fmt_table, "probe_time:",
  1427. le32_to_cpu(div->probe_time), accum_div->probe_time,
  1428. delta_div->probe_time, max_div->probe_time);
  1429. pos += scnprintf(buf + pos, bufsz - pos,
  1430. fmt_table, "rx_enable_counter:",
  1431. le32_to_cpu(general->rx_enable_counter),
  1432. accum_general->rx_enable_counter,
  1433. delta_general->rx_enable_counter,
  1434. max_general->rx_enable_counter);
  1435. pos += scnprintf(buf + pos, bufsz - pos,
  1436. fmt_table, "num_of_sos_states:",
  1437. le32_to_cpu(general->num_of_sos_states),
  1438. accum_general->num_of_sos_states,
  1439. delta_general->num_of_sos_states,
  1440. max_general->num_of_sos_states);
  1441. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  1442. kfree(buf);
  1443. return ret;
  1444. }
  1445. static ssize_t iwl_dbgfs_ucode_bt_stats_read(struct file *file,
  1446. char __user *user_buf,
  1447. size_t count, loff_t *ppos)
  1448. {
  1449. struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
  1450. int pos = 0;
  1451. char *buf;
  1452. int bufsz = (sizeof(struct statistics_bt_activity) * 24) + 200;
  1453. ssize_t ret;
  1454. struct statistics_bt_activity *bt, *accum_bt;
  1455. if (!iwl_is_alive(priv->shrd))
  1456. return -EAGAIN;
  1457. if (!priv->bt_enable_flag)
  1458. return -EINVAL;
  1459. /* make request to uCode to retrieve statistics information */
  1460. mutex_lock(&priv->shrd->mutex);
  1461. ret = iwl_send_statistics_request(priv, CMD_SYNC, false);
  1462. mutex_unlock(&priv->shrd->mutex);
  1463. if (ret) {
  1464. IWL_ERR(priv,
  1465. "Error sending statistics request: %zd\n", ret);
  1466. return -EAGAIN;
  1467. }
  1468. buf = kzalloc(bufsz, GFP_KERNEL);
  1469. if (!buf) {
  1470. IWL_ERR(priv, "Can not allocate Buffer\n");
  1471. return -ENOMEM;
  1472. }
  1473. /*
  1474. * the statistic information display here is based on
  1475. * the last statistics notification from uCode
  1476. * might not reflect the current uCode activity
  1477. */
  1478. bt = &priv->statistics.bt_activity;
  1479. accum_bt = &priv->accum_stats.bt_activity;
  1480. pos += iwl_statistics_flag(priv, buf, bufsz);
  1481. pos += scnprintf(buf + pos, bufsz - pos, "Statistics_BT:\n");
  1482. pos += scnprintf(buf + pos, bufsz - pos,
  1483. "\t\t\tcurrent\t\t\taccumulative\n");
  1484. pos += scnprintf(buf + pos, bufsz - pos,
  1485. "hi_priority_tx_req_cnt:\t\t%u\t\t\t%u\n",
  1486. le32_to_cpu(bt->hi_priority_tx_req_cnt),
  1487. accum_bt->hi_priority_tx_req_cnt);
  1488. pos += scnprintf(buf + pos, bufsz - pos,
  1489. "hi_priority_tx_denied_cnt:\t%u\t\t\t%u\n",
  1490. le32_to_cpu(bt->hi_priority_tx_denied_cnt),
  1491. accum_bt->hi_priority_tx_denied_cnt);
  1492. pos += scnprintf(buf + pos, bufsz - pos,
  1493. "lo_priority_tx_req_cnt:\t\t%u\t\t\t%u\n",
  1494. le32_to_cpu(bt->lo_priority_tx_req_cnt),
  1495. accum_bt->lo_priority_tx_req_cnt);
  1496. pos += scnprintf(buf + pos, bufsz - pos,
  1497. "lo_priority_tx_denied_cnt:\t%u\t\t\t%u\n",
  1498. le32_to_cpu(bt->lo_priority_tx_denied_cnt),
  1499. accum_bt->lo_priority_tx_denied_cnt);
  1500. pos += scnprintf(buf + pos, bufsz - pos,
  1501. "hi_priority_rx_req_cnt:\t\t%u\t\t\t%u\n",
  1502. le32_to_cpu(bt->hi_priority_rx_req_cnt),
  1503. accum_bt->hi_priority_rx_req_cnt);
  1504. pos += scnprintf(buf + pos, bufsz - pos,
  1505. "hi_priority_rx_denied_cnt:\t%u\t\t\t%u\n",
  1506. le32_to_cpu(bt->hi_priority_rx_denied_cnt),
  1507. accum_bt->hi_priority_rx_denied_cnt);
  1508. pos += scnprintf(buf + pos, bufsz - pos,
  1509. "lo_priority_rx_req_cnt:\t\t%u\t\t\t%u\n",
  1510. le32_to_cpu(bt->lo_priority_rx_req_cnt),
  1511. accum_bt->lo_priority_rx_req_cnt);
  1512. pos += scnprintf(buf + pos, bufsz - pos,
  1513. "lo_priority_rx_denied_cnt:\t%u\t\t\t%u\n",
  1514. le32_to_cpu(bt->lo_priority_rx_denied_cnt),
  1515. accum_bt->lo_priority_rx_denied_cnt);
  1516. pos += scnprintf(buf + pos, bufsz - pos,
  1517. "(rx)num_bt_kills:\t\t%u\t\t\t%u\n",
  1518. le32_to_cpu(priv->statistics.num_bt_kills),
  1519. priv->statistics.accum_num_bt_kills);
  1520. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  1521. kfree(buf);
  1522. return ret;
  1523. }
  1524. static ssize_t iwl_dbgfs_reply_tx_error_read(struct file *file,
  1525. char __user *user_buf,
  1526. size_t count, loff_t *ppos)
  1527. {
  1528. struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
  1529. int pos = 0;
  1530. char *buf;
  1531. int bufsz = (sizeof(struct reply_tx_error_statistics) * 24) +
  1532. (sizeof(struct reply_agg_tx_error_statistics) * 24) + 200;
  1533. ssize_t ret;
  1534. if (!iwl_is_alive(priv->shrd))
  1535. return -EAGAIN;
  1536. buf = kzalloc(bufsz, GFP_KERNEL);
  1537. if (!buf) {
  1538. IWL_ERR(priv, "Can not allocate Buffer\n");
  1539. return -ENOMEM;
  1540. }
  1541. pos += scnprintf(buf + pos, bufsz - pos, "Statistics_TX_Error:\n");
  1542. pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t\t%u\n",
  1543. iwl_get_tx_fail_reason(TX_STATUS_POSTPONE_DELAY),
  1544. priv->reply_tx_stats.pp_delay);
  1545. pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
  1546. iwl_get_tx_fail_reason(TX_STATUS_POSTPONE_FEW_BYTES),
  1547. priv->reply_tx_stats.pp_few_bytes);
  1548. pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
  1549. iwl_get_tx_fail_reason(TX_STATUS_POSTPONE_BT_PRIO),
  1550. priv->reply_tx_stats.pp_bt_prio);
  1551. pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
  1552. iwl_get_tx_fail_reason(TX_STATUS_POSTPONE_QUIET_PERIOD),
  1553. priv->reply_tx_stats.pp_quiet_period);
  1554. pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
  1555. iwl_get_tx_fail_reason(TX_STATUS_POSTPONE_CALC_TTAK),
  1556. priv->reply_tx_stats.pp_calc_ttak);
  1557. pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t%u\n",
  1558. iwl_get_tx_fail_reason(
  1559. TX_STATUS_FAIL_INTERNAL_CROSSED_RETRY),
  1560. priv->reply_tx_stats.int_crossed_retry);
  1561. pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
  1562. iwl_get_tx_fail_reason(TX_STATUS_FAIL_SHORT_LIMIT),
  1563. priv->reply_tx_stats.short_limit);
  1564. pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
  1565. iwl_get_tx_fail_reason(TX_STATUS_FAIL_LONG_LIMIT),
  1566. priv->reply_tx_stats.long_limit);
  1567. pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
  1568. iwl_get_tx_fail_reason(TX_STATUS_FAIL_FIFO_UNDERRUN),
  1569. priv->reply_tx_stats.fifo_underrun);
  1570. pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
  1571. iwl_get_tx_fail_reason(TX_STATUS_FAIL_DRAIN_FLOW),
  1572. priv->reply_tx_stats.drain_flow);
  1573. pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
  1574. iwl_get_tx_fail_reason(TX_STATUS_FAIL_RFKILL_FLUSH),
  1575. priv->reply_tx_stats.rfkill_flush);
  1576. pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
  1577. iwl_get_tx_fail_reason(TX_STATUS_FAIL_LIFE_EXPIRE),
  1578. priv->reply_tx_stats.life_expire);
  1579. pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
  1580. iwl_get_tx_fail_reason(TX_STATUS_FAIL_DEST_PS),
  1581. priv->reply_tx_stats.dest_ps);
  1582. pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
  1583. iwl_get_tx_fail_reason(TX_STATUS_FAIL_HOST_ABORTED),
  1584. priv->reply_tx_stats.host_abort);
  1585. pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
  1586. iwl_get_tx_fail_reason(TX_STATUS_FAIL_BT_RETRY),
  1587. priv->reply_tx_stats.pp_delay);
  1588. pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
  1589. iwl_get_tx_fail_reason(TX_STATUS_FAIL_STA_INVALID),
  1590. priv->reply_tx_stats.sta_invalid);
  1591. pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
  1592. iwl_get_tx_fail_reason(TX_STATUS_FAIL_FRAG_DROPPED),
  1593. priv->reply_tx_stats.frag_drop);
  1594. pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
  1595. iwl_get_tx_fail_reason(TX_STATUS_FAIL_TID_DISABLE),
  1596. priv->reply_tx_stats.tid_disable);
  1597. pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
  1598. iwl_get_tx_fail_reason(TX_STATUS_FAIL_FIFO_FLUSHED),
  1599. priv->reply_tx_stats.fifo_flush);
  1600. pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t%u\n",
  1601. iwl_get_tx_fail_reason(
  1602. TX_STATUS_FAIL_INSUFFICIENT_CF_POLL),
  1603. priv->reply_tx_stats.insuff_cf_poll);
  1604. pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
  1605. iwl_get_tx_fail_reason(TX_STATUS_FAIL_PASSIVE_NO_RX),
  1606. priv->reply_tx_stats.fail_hw_drop);
  1607. pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t%u\n",
  1608. iwl_get_tx_fail_reason(
  1609. TX_STATUS_FAIL_NO_BEACON_ON_RADAR),
  1610. priv->reply_tx_stats.sta_color_mismatch);
  1611. pos += scnprintf(buf + pos, bufsz - pos, "UNKNOWN:\t\t\t%u\n",
  1612. priv->reply_tx_stats.unknown);
  1613. pos += scnprintf(buf + pos, bufsz - pos,
  1614. "\nStatistics_Agg_TX_Error:\n");
  1615. pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
  1616. iwl_get_agg_tx_fail_reason(AGG_TX_STATE_UNDERRUN_MSK),
  1617. priv->reply_agg_tx_stats.underrun);
  1618. pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
  1619. iwl_get_agg_tx_fail_reason(AGG_TX_STATE_BT_PRIO_MSK),
  1620. priv->reply_agg_tx_stats.bt_prio);
  1621. pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
  1622. iwl_get_agg_tx_fail_reason(AGG_TX_STATE_FEW_BYTES_MSK),
  1623. priv->reply_agg_tx_stats.few_bytes);
  1624. pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
  1625. iwl_get_agg_tx_fail_reason(AGG_TX_STATE_ABORT_MSK),
  1626. priv->reply_agg_tx_stats.abort);
  1627. pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t%u\n",
  1628. iwl_get_agg_tx_fail_reason(
  1629. AGG_TX_STATE_LAST_SENT_TTL_MSK),
  1630. priv->reply_agg_tx_stats.last_sent_ttl);
  1631. pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t%u\n",
  1632. iwl_get_agg_tx_fail_reason(
  1633. AGG_TX_STATE_LAST_SENT_TRY_CNT_MSK),
  1634. priv->reply_agg_tx_stats.last_sent_try);
  1635. pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t%u\n",
  1636. iwl_get_agg_tx_fail_reason(
  1637. AGG_TX_STATE_LAST_SENT_BT_KILL_MSK),
  1638. priv->reply_agg_tx_stats.last_sent_bt_kill);
  1639. pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
  1640. iwl_get_agg_tx_fail_reason(AGG_TX_STATE_SCD_QUERY_MSK),
  1641. priv->reply_agg_tx_stats.scd_query);
  1642. pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t%u\n",
  1643. iwl_get_agg_tx_fail_reason(
  1644. AGG_TX_STATE_TEST_BAD_CRC32_MSK),
  1645. priv->reply_agg_tx_stats.bad_crc32);
  1646. pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
  1647. iwl_get_agg_tx_fail_reason(AGG_TX_STATE_RESPONSE_MSK),
  1648. priv->reply_agg_tx_stats.response);
  1649. pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
  1650. iwl_get_agg_tx_fail_reason(AGG_TX_STATE_DUMP_TX_MSK),
  1651. priv->reply_agg_tx_stats.dump_tx);
  1652. pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
  1653. iwl_get_agg_tx_fail_reason(AGG_TX_STATE_DELAY_TX_MSK),
  1654. priv->reply_agg_tx_stats.delay_tx);
  1655. pos += scnprintf(buf + pos, bufsz - pos, "UNKNOWN:\t\t\t%u\n",
  1656. priv->reply_agg_tx_stats.unknown);
  1657. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  1658. kfree(buf);
  1659. return ret;
  1660. }
  1661. static ssize_t iwl_dbgfs_sensitivity_read(struct file *file,
  1662. char __user *user_buf,
  1663. size_t count, loff_t *ppos) {
  1664. struct iwl_priv *priv = file->private_data;
  1665. int pos = 0;
  1666. int cnt = 0;
  1667. char *buf;
  1668. int bufsz = sizeof(struct iwl_sensitivity_data) * 4 + 100;
  1669. ssize_t ret;
  1670. struct iwl_sensitivity_data *data;
  1671. data = &priv->sensitivity_data;
  1672. buf = kzalloc(bufsz, GFP_KERNEL);
  1673. if (!buf) {
  1674. IWL_ERR(priv, "Can not allocate Buffer\n");
  1675. return -ENOMEM;
  1676. }
  1677. pos += scnprintf(buf + pos, bufsz - pos, "auto_corr_ofdm:\t\t\t %u\n",
  1678. data->auto_corr_ofdm);
  1679. pos += scnprintf(buf + pos, bufsz - pos,
  1680. "auto_corr_ofdm_mrc:\t\t %u\n",
  1681. data->auto_corr_ofdm_mrc);
  1682. pos += scnprintf(buf + pos, bufsz - pos, "auto_corr_ofdm_x1:\t\t %u\n",
  1683. data->auto_corr_ofdm_x1);
  1684. pos += scnprintf(buf + pos, bufsz - pos,
  1685. "auto_corr_ofdm_mrc_x1:\t\t %u\n",
  1686. data->auto_corr_ofdm_mrc_x1);
  1687. pos += scnprintf(buf + pos, bufsz - pos, "auto_corr_cck:\t\t\t %u\n",
  1688. data->auto_corr_cck);
  1689. pos += scnprintf(buf + pos, bufsz - pos, "auto_corr_cck_mrc:\t\t %u\n",
  1690. data->auto_corr_cck_mrc);
  1691. pos += scnprintf(buf + pos, bufsz - pos,
  1692. "last_bad_plcp_cnt_ofdm:\t\t %u\n",
  1693. data->last_bad_plcp_cnt_ofdm);
  1694. pos += scnprintf(buf + pos, bufsz - pos, "last_fa_cnt_ofdm:\t\t %u\n",
  1695. data->last_fa_cnt_ofdm);
  1696. pos += scnprintf(buf + pos, bufsz - pos,
  1697. "last_bad_plcp_cnt_cck:\t\t %u\n",
  1698. data->last_bad_plcp_cnt_cck);
  1699. pos += scnprintf(buf + pos, bufsz - pos, "last_fa_cnt_cck:\t\t %u\n",
  1700. data->last_fa_cnt_cck);
  1701. pos += scnprintf(buf + pos, bufsz - pos, "nrg_curr_state:\t\t\t %u\n",
  1702. data->nrg_curr_state);
  1703. pos += scnprintf(buf + pos, bufsz - pos, "nrg_prev_state:\t\t\t %u\n",
  1704. data->nrg_prev_state);
  1705. pos += scnprintf(buf + pos, bufsz - pos, "nrg_value:\t\t\t");
  1706. for (cnt = 0; cnt < 10; cnt++) {
  1707. pos += scnprintf(buf + pos, bufsz - pos, " %u",
  1708. data->nrg_value[cnt]);
  1709. }
  1710. pos += scnprintf(buf + pos, bufsz - pos, "\n");
  1711. pos += scnprintf(buf + pos, bufsz - pos, "nrg_silence_rssi:\t\t");
  1712. for (cnt = 0; cnt < NRG_NUM_PREV_STAT_L; cnt++) {
  1713. pos += scnprintf(buf + pos, bufsz - pos, " %u",
  1714. data->nrg_silence_rssi[cnt]);
  1715. }
  1716. pos += scnprintf(buf + pos, bufsz - pos, "\n");
  1717. pos += scnprintf(buf + pos, bufsz - pos, "nrg_silence_ref:\t\t %u\n",
  1718. data->nrg_silence_ref);
  1719. pos += scnprintf(buf + pos, bufsz - pos, "nrg_energy_idx:\t\t\t %u\n",
  1720. data->nrg_energy_idx);
  1721. pos += scnprintf(buf + pos, bufsz - pos, "nrg_silence_idx:\t\t %u\n",
  1722. data->nrg_silence_idx);
  1723. pos += scnprintf(buf + pos, bufsz - pos, "nrg_th_cck:\t\t\t %u\n",
  1724. data->nrg_th_cck);
  1725. pos += scnprintf(buf + pos, bufsz - pos,
  1726. "nrg_auto_corr_silence_diff:\t %u\n",
  1727. data->nrg_auto_corr_silence_diff);
  1728. pos += scnprintf(buf + pos, bufsz - pos, "num_in_cck_no_fa:\t\t %u\n",
  1729. data->num_in_cck_no_fa);
  1730. pos += scnprintf(buf + pos, bufsz - pos, "nrg_th_ofdm:\t\t\t %u\n",
  1731. data->nrg_th_ofdm);
  1732. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  1733. kfree(buf);
  1734. return ret;
  1735. }
  1736. static ssize_t iwl_dbgfs_chain_noise_read(struct file *file,
  1737. char __user *user_buf,
  1738. size_t count, loff_t *ppos) {
  1739. struct iwl_priv *priv = file->private_data;
  1740. int pos = 0;
  1741. int cnt = 0;
  1742. char *buf;
  1743. int bufsz = sizeof(struct iwl_chain_noise_data) * 4 + 100;
  1744. ssize_t ret;
  1745. struct iwl_chain_noise_data *data;
  1746. data = &priv->chain_noise_data;
  1747. buf = kzalloc(bufsz, GFP_KERNEL);
  1748. if (!buf) {
  1749. IWL_ERR(priv, "Can not allocate Buffer\n");
  1750. return -ENOMEM;
  1751. }
  1752. pos += scnprintf(buf + pos, bufsz - pos, "active_chains:\t\t\t %u\n",
  1753. data->active_chains);
  1754. pos += scnprintf(buf + pos, bufsz - pos, "chain_noise_a:\t\t\t %u\n",
  1755. data->chain_noise_a);
  1756. pos += scnprintf(buf + pos, bufsz - pos, "chain_noise_b:\t\t\t %u\n",
  1757. data->chain_noise_b);
  1758. pos += scnprintf(buf + pos, bufsz - pos, "chain_noise_c:\t\t\t %u\n",
  1759. data->chain_noise_c);
  1760. pos += scnprintf(buf + pos, bufsz - pos, "chain_signal_a:\t\t\t %u\n",
  1761. data->chain_signal_a);
  1762. pos += scnprintf(buf + pos, bufsz - pos, "chain_signal_b:\t\t\t %u\n",
  1763. data->chain_signal_b);
  1764. pos += scnprintf(buf + pos, bufsz - pos, "chain_signal_c:\t\t\t %u\n",
  1765. data->chain_signal_c);
  1766. pos += scnprintf(buf + pos, bufsz - pos, "beacon_count:\t\t\t %u\n",
  1767. data->beacon_count);
  1768. pos += scnprintf(buf + pos, bufsz - pos, "disconn_array:\t\t\t");
  1769. for (cnt = 0; cnt < NUM_RX_CHAINS; cnt++) {
  1770. pos += scnprintf(buf + pos, bufsz - pos, " %u",
  1771. data->disconn_array[cnt]);
  1772. }
  1773. pos += scnprintf(buf + pos, bufsz - pos, "\n");
  1774. pos += scnprintf(buf + pos, bufsz - pos, "delta_gain_code:\t\t");
  1775. for (cnt = 0; cnt < NUM_RX_CHAINS; cnt++) {
  1776. pos += scnprintf(buf + pos, bufsz - pos, " %u",
  1777. data->delta_gain_code[cnt]);
  1778. }
  1779. pos += scnprintf(buf + pos, bufsz - pos, "\n");
  1780. pos += scnprintf(buf + pos, bufsz - pos, "radio_write:\t\t\t %u\n",
  1781. data->radio_write);
  1782. pos += scnprintf(buf + pos, bufsz - pos, "state:\t\t\t\t %u\n",
  1783. data->state);
  1784. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  1785. kfree(buf);
  1786. return ret;
  1787. }
  1788. static ssize_t iwl_dbgfs_power_save_status_read(struct file *file,
  1789. char __user *user_buf,
  1790. size_t count, loff_t *ppos)
  1791. {
  1792. struct iwl_priv *priv = file->private_data;
  1793. char buf[60];
  1794. int pos = 0;
  1795. const size_t bufsz = sizeof(buf);
  1796. u32 pwrsave_status;
  1797. pwrsave_status = iwl_read32(bus(priv), CSR_GP_CNTRL) &
  1798. CSR_GP_REG_POWER_SAVE_STATUS_MSK;
  1799. pos += scnprintf(buf + pos, bufsz - pos, "Power Save Status: ");
  1800. pos += scnprintf(buf + pos, bufsz - pos, "%s\n",
  1801. (pwrsave_status == CSR_GP_REG_NO_POWER_SAVE) ? "none" :
  1802. (pwrsave_status == CSR_GP_REG_MAC_POWER_SAVE) ? "MAC" :
  1803. (pwrsave_status == CSR_GP_REG_PHY_POWER_SAVE) ? "PHY" :
  1804. "error");
  1805. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  1806. }
  1807. static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
  1808. const char __user *user_buf,
  1809. size_t count, loff_t *ppos)
  1810. {
  1811. struct iwl_priv *priv = file->private_data;
  1812. char buf[8];
  1813. int buf_size;
  1814. int clear;
  1815. memset(buf, 0, sizeof(buf));
  1816. buf_size = min(count, sizeof(buf) - 1);
  1817. if (copy_from_user(buf, user_buf, buf_size))
  1818. return -EFAULT;
  1819. if (sscanf(buf, "%d", &clear) != 1)
  1820. return -EFAULT;
  1821. /* make request to uCode to retrieve statistics information */
  1822. mutex_lock(&priv->shrd->mutex);
  1823. iwl_send_statistics_request(priv, CMD_SYNC, true);
  1824. mutex_unlock(&priv->shrd->mutex);
  1825. return count;
  1826. }
  1827. static ssize_t iwl_dbgfs_ucode_tracing_read(struct file *file,
  1828. char __user *user_buf,
  1829. size_t count, loff_t *ppos) {
  1830. struct iwl_priv *priv = file->private_data;
  1831. int pos = 0;
  1832. char buf[128];
  1833. const size_t bufsz = sizeof(buf);
  1834. pos += scnprintf(buf + pos, bufsz - pos, "ucode trace timer is %s\n",
  1835. priv->event_log.ucode_trace ? "On" : "Off");
  1836. pos += scnprintf(buf + pos, bufsz - pos, "non_wraps_count:\t\t %u\n",
  1837. priv->event_log.non_wraps_count);
  1838. pos += scnprintf(buf + pos, bufsz - pos, "wraps_once_count:\t\t %u\n",
  1839. priv->event_log.wraps_once_count);
  1840. pos += scnprintf(buf + pos, bufsz - pos, "wraps_more_count:\t\t %u\n",
  1841. priv->event_log.wraps_more_count);
  1842. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  1843. }
  1844. static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
  1845. const char __user *user_buf,
  1846. size_t count, loff_t *ppos)
  1847. {
  1848. struct iwl_priv *priv = file->private_data;
  1849. char buf[8];
  1850. int buf_size;
  1851. int trace;
  1852. memset(buf, 0, sizeof(buf));
  1853. buf_size = min(count, sizeof(buf) - 1);
  1854. if (copy_from_user(buf, user_buf, buf_size))
  1855. return -EFAULT;
  1856. if (sscanf(buf, "%d", &trace) != 1)
  1857. return -EFAULT;
  1858. if (trace) {
  1859. priv->event_log.ucode_trace = true;
  1860. /* schedule the ucode timer to occur in UCODE_TRACE_PERIOD */
  1861. mod_timer(&priv->ucode_trace,
  1862. jiffies + msecs_to_jiffies(UCODE_TRACE_PERIOD));
  1863. } else {
  1864. priv->event_log.ucode_trace = false;
  1865. del_timer_sync(&priv->ucode_trace);
  1866. }
  1867. return count;
  1868. }
  1869. static ssize_t iwl_dbgfs_rxon_flags_read(struct file *file,
  1870. char __user *user_buf,
  1871. size_t count, loff_t *ppos) {
  1872. struct iwl_priv *priv = file->private_data;
  1873. int len = 0;
  1874. char buf[20];
  1875. len = sprintf(buf, "0x%04X\n",
  1876. le32_to_cpu(priv->contexts[IWL_RXON_CTX_BSS].active.flags));
  1877. return simple_read_from_buffer(user_buf, count, ppos, buf, len);
  1878. }
  1879. static ssize_t iwl_dbgfs_rxon_filter_flags_read(struct file *file,
  1880. char __user *user_buf,
  1881. size_t count, loff_t *ppos) {
  1882. struct iwl_priv *priv = file->private_data;
  1883. int len = 0;
  1884. char buf[20];
  1885. len = sprintf(buf, "0x%04X\n",
  1886. le32_to_cpu(priv->contexts[IWL_RXON_CTX_BSS].active.filter_flags));
  1887. return simple_read_from_buffer(user_buf, count, ppos, buf, len);
  1888. }
  1889. static ssize_t iwl_dbgfs_missed_beacon_read(struct file *file,
  1890. char __user *user_buf,
  1891. size_t count, loff_t *ppos) {
  1892. struct iwl_priv *priv = file->private_data;
  1893. int pos = 0;
  1894. char buf[12];
  1895. const size_t bufsz = sizeof(buf);
  1896. pos += scnprintf(buf + pos, bufsz - pos, "%d\n",
  1897. priv->missed_beacon_threshold);
  1898. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  1899. }
  1900. static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
  1901. const char __user *user_buf,
  1902. size_t count, loff_t *ppos)
  1903. {
  1904. struct iwl_priv *priv = file->private_data;
  1905. char buf[8];
  1906. int buf_size;
  1907. int missed;
  1908. memset(buf, 0, sizeof(buf));
  1909. buf_size = min(count, sizeof(buf) - 1);
  1910. if (copy_from_user(buf, user_buf, buf_size))
  1911. return -EFAULT;
  1912. if (sscanf(buf, "%d", &missed) != 1)
  1913. return -EINVAL;
  1914. if (missed < IWL_MISSED_BEACON_THRESHOLD_MIN ||
  1915. missed > IWL_MISSED_BEACON_THRESHOLD_MAX)
  1916. priv->missed_beacon_threshold =
  1917. IWL_MISSED_BEACON_THRESHOLD_DEF;
  1918. else
  1919. priv->missed_beacon_threshold = missed;
  1920. return count;
  1921. }
  1922. static ssize_t iwl_dbgfs_plcp_delta_read(struct file *file,
  1923. char __user *user_buf,
  1924. size_t count, loff_t *ppos) {
  1925. struct iwl_priv *priv = file->private_data;
  1926. int pos = 0;
  1927. char buf[12];
  1928. const size_t bufsz = sizeof(buf);
  1929. pos += scnprintf(buf + pos, bufsz - pos, "%u\n",
  1930. priv->cfg->base_params->plcp_delta_threshold);
  1931. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  1932. }
  1933. static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
  1934. const char __user *user_buf,
  1935. size_t count, loff_t *ppos) {
  1936. struct iwl_priv *priv = file->private_data;
  1937. char buf[8];
  1938. int buf_size;
  1939. int plcp;
  1940. memset(buf, 0, sizeof(buf));
  1941. buf_size = min(count, sizeof(buf) - 1);
  1942. if (copy_from_user(buf, user_buf, buf_size))
  1943. return -EFAULT;
  1944. if (sscanf(buf, "%d", &plcp) != 1)
  1945. return -EINVAL;
  1946. if ((plcp < IWL_MAX_PLCP_ERR_THRESHOLD_MIN) ||
  1947. (plcp > IWL_MAX_PLCP_ERR_THRESHOLD_MAX))
  1948. priv->cfg->base_params->plcp_delta_threshold =
  1949. IWL_MAX_PLCP_ERR_THRESHOLD_DISABLE;
  1950. else
  1951. priv->cfg->base_params->plcp_delta_threshold = plcp;
  1952. return count;
  1953. }
  1954. static ssize_t iwl_dbgfs_force_reset_read(struct file *file,
  1955. char __user *user_buf,
  1956. size_t count, loff_t *ppos) {
  1957. struct iwl_priv *priv = file->private_data;
  1958. int i, pos = 0;
  1959. char buf[300];
  1960. const size_t bufsz = sizeof(buf);
  1961. struct iwl_force_reset *force_reset;
  1962. for (i = 0; i < IWL_MAX_FORCE_RESET; i++) {
  1963. force_reset = &priv->force_reset[i];
  1964. pos += scnprintf(buf + pos, bufsz - pos,
  1965. "Force reset method %d\n", i);
  1966. pos += scnprintf(buf + pos, bufsz - pos,
  1967. "\tnumber of reset request: %d\n",
  1968. force_reset->reset_request_count);
  1969. pos += scnprintf(buf + pos, bufsz - pos,
  1970. "\tnumber of reset request success: %d\n",
  1971. force_reset->reset_success_count);
  1972. pos += scnprintf(buf + pos, bufsz - pos,
  1973. "\tnumber of reset request reject: %d\n",
  1974. force_reset->reset_reject_count);
  1975. pos += scnprintf(buf + pos, bufsz - pos,
  1976. "\treset duration: %lu\n",
  1977. force_reset->reset_duration);
  1978. }
  1979. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  1980. }
  1981. static ssize_t iwl_dbgfs_force_reset_write(struct file *file,
  1982. const char __user *user_buf,
  1983. size_t count, loff_t *ppos) {
  1984. struct iwl_priv *priv = file->private_data;
  1985. char buf[8];
  1986. int buf_size;
  1987. int reset, ret;
  1988. memset(buf, 0, sizeof(buf));
  1989. buf_size = min(count, sizeof(buf) - 1);
  1990. if (copy_from_user(buf, user_buf, buf_size))
  1991. return -EFAULT;
  1992. if (sscanf(buf, "%d", &reset) != 1)
  1993. return -EINVAL;
  1994. switch (reset) {
  1995. case IWL_RF_RESET:
  1996. case IWL_FW_RESET:
  1997. ret = iwl_force_reset(priv, reset, true);
  1998. break;
  1999. default:
  2000. return -EINVAL;
  2001. }
  2002. return ret ? ret : count;
  2003. }
  2004. static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file,
  2005. const char __user *user_buf,
  2006. size_t count, loff_t *ppos) {
  2007. struct iwl_priv *priv = file->private_data;
  2008. char buf[8];
  2009. int buf_size;
  2010. int flush;
  2011. memset(buf, 0, sizeof(buf));
  2012. buf_size = min(count, sizeof(buf) - 1);
  2013. if (copy_from_user(buf, user_buf, buf_size))
  2014. return -EFAULT;
  2015. if (sscanf(buf, "%d", &flush) != 1)
  2016. return -EINVAL;
  2017. if (iwl_is_rfkill(priv->shrd))
  2018. return -EFAULT;
  2019. iwlagn_dev_txfifo_flush(priv, IWL_DROP_ALL);
  2020. return count;
  2021. }
  2022. static ssize_t iwl_dbgfs_wd_timeout_write(struct file *file,
  2023. const char __user *user_buf,
  2024. size_t count, loff_t *ppos) {
  2025. struct iwl_priv *priv = file->private_data;
  2026. char buf[8];
  2027. int buf_size;
  2028. int timeout;
  2029. memset(buf, 0, sizeof(buf));
  2030. buf_size = min(count, sizeof(buf) - 1);
  2031. if (copy_from_user(buf, user_buf, buf_size))
  2032. return -EFAULT;
  2033. if (sscanf(buf, "%d", &timeout) != 1)
  2034. return -EINVAL;
  2035. if (timeout < 0 || timeout > IWL_MAX_WD_TIMEOUT)
  2036. timeout = IWL_DEF_WD_TIMEOUT;
  2037. priv->cfg->base_params->wd_timeout = timeout;
  2038. iwl_setup_watchdog(priv);
  2039. return count;
  2040. }
  2041. static ssize_t iwl_dbgfs_bt_traffic_read(struct file *file,
  2042. char __user *user_buf,
  2043. size_t count, loff_t *ppos) {
  2044. struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
  2045. int pos = 0;
  2046. char buf[200];
  2047. const size_t bufsz = sizeof(buf);
  2048. if (!priv->bt_enable_flag) {
  2049. pos += scnprintf(buf + pos, bufsz - pos, "BT coex disabled\n");
  2050. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  2051. }
  2052. pos += scnprintf(buf + pos, bufsz - pos, "BT enable flag: 0x%x\n",
  2053. priv->bt_enable_flag);
  2054. pos += scnprintf(buf + pos, bufsz - pos, "BT in %s mode\n",
  2055. priv->bt_full_concurrent ? "full concurrency" : "3-wire");
  2056. pos += scnprintf(buf + pos, bufsz - pos, "BT status: %s, "
  2057. "last traffic notif: %d\n",
  2058. priv->bt_status ? "On" : "Off", priv->last_bt_traffic_load);
  2059. pos += scnprintf(buf + pos, bufsz - pos, "ch_announcement: %d, "
  2060. "kill_ack_mask: %x, kill_cts_mask: %x\n",
  2061. priv->bt_ch_announce, priv->kill_ack_mask,
  2062. priv->kill_cts_mask);
  2063. pos += scnprintf(buf + pos, bufsz - pos, "bluetooth traffic load: ");
  2064. switch (priv->bt_traffic_load) {
  2065. case IWL_BT_COEX_TRAFFIC_LOAD_CONTINUOUS:
  2066. pos += scnprintf(buf + pos, bufsz - pos, "Continuous\n");
  2067. break;
  2068. case IWL_BT_COEX_TRAFFIC_LOAD_HIGH:
  2069. pos += scnprintf(buf + pos, bufsz - pos, "High\n");
  2070. break;
  2071. case IWL_BT_COEX_TRAFFIC_LOAD_LOW:
  2072. pos += scnprintf(buf + pos, bufsz - pos, "Low\n");
  2073. break;
  2074. case IWL_BT_COEX_TRAFFIC_LOAD_NONE:
  2075. default:
  2076. pos += scnprintf(buf + pos, bufsz - pos, "None\n");
  2077. break;
  2078. }
  2079. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  2080. }
  2081. static ssize_t iwl_dbgfs_protection_mode_read(struct file *file,
  2082. char __user *user_buf,
  2083. size_t count, loff_t *ppos)
  2084. {
  2085. struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
  2086. int pos = 0;
  2087. char buf[40];
  2088. const size_t bufsz = sizeof(buf);
  2089. if (priv->cfg->ht_params)
  2090. pos += scnprintf(buf + pos, bufsz - pos,
  2091. "use %s for aggregation\n",
  2092. (priv->cfg->ht_params->use_rts_for_aggregation) ?
  2093. "rts/cts" : "cts-to-self");
  2094. else
  2095. pos += scnprintf(buf + pos, bufsz - pos, "N/A");
  2096. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  2097. }
  2098. static ssize_t iwl_dbgfs_protection_mode_write(struct file *file,
  2099. const char __user *user_buf,
  2100. size_t count, loff_t *ppos) {
  2101. struct iwl_priv *priv = file->private_data;
  2102. char buf[8];
  2103. int buf_size;
  2104. int rts;
  2105. if (!priv->cfg->ht_params)
  2106. return -EINVAL;
  2107. memset(buf, 0, sizeof(buf));
  2108. buf_size = min(count, sizeof(buf) - 1);
  2109. if (copy_from_user(buf, user_buf, buf_size))
  2110. return -EFAULT;
  2111. if (sscanf(buf, "%d", &rts) != 1)
  2112. return -EINVAL;
  2113. if (rts)
  2114. priv->cfg->ht_params->use_rts_for_aggregation = true;
  2115. else
  2116. priv->cfg->ht_params->use_rts_for_aggregation = false;
  2117. return count;
  2118. }
  2119. DEBUGFS_READ_FILE_OPS(rx_statistics);
  2120. DEBUGFS_READ_FILE_OPS(tx_statistics);
  2121. DEBUGFS_READ_FILE_OPS(ucode_rx_stats);
  2122. DEBUGFS_READ_FILE_OPS(ucode_tx_stats);
  2123. DEBUGFS_READ_FILE_OPS(ucode_general_stats);
  2124. DEBUGFS_READ_FILE_OPS(sensitivity);
  2125. DEBUGFS_READ_FILE_OPS(chain_noise);
  2126. DEBUGFS_READ_FILE_OPS(power_save_status);
  2127. DEBUGFS_WRITE_FILE_OPS(clear_ucode_statistics);
  2128. DEBUGFS_WRITE_FILE_OPS(clear_traffic_statistics);
  2129. DEBUGFS_READ_WRITE_FILE_OPS(ucode_tracing);
  2130. DEBUGFS_READ_WRITE_FILE_OPS(missed_beacon);
  2131. DEBUGFS_READ_WRITE_FILE_OPS(plcp_delta);
  2132. DEBUGFS_READ_WRITE_FILE_OPS(force_reset);
  2133. DEBUGFS_READ_FILE_OPS(rxon_flags);
  2134. DEBUGFS_READ_FILE_OPS(rxon_filter_flags);
  2135. DEBUGFS_WRITE_FILE_OPS(txfifo_flush);
  2136. DEBUGFS_READ_FILE_OPS(ucode_bt_stats);
  2137. DEBUGFS_WRITE_FILE_OPS(wd_timeout);
  2138. DEBUGFS_READ_FILE_OPS(bt_traffic);
  2139. DEBUGFS_READ_WRITE_FILE_OPS(protection_mode);
  2140. DEBUGFS_READ_FILE_OPS(reply_tx_error);
  2141. /*
  2142. * Create the debugfs files and directories
  2143. *
  2144. */
  2145. int iwl_dbgfs_register(struct iwl_priv *priv, const char *name)
  2146. {
  2147. struct dentry *phyd = priv->hw->wiphy->debugfsdir;
  2148. struct dentry *dir_drv, *dir_data, *dir_rf, *dir_debug;
  2149. dir_drv = debugfs_create_dir(name, phyd);
  2150. if (!dir_drv)
  2151. return -ENOMEM;
  2152. priv->debugfs_dir = dir_drv;
  2153. dir_data = debugfs_create_dir("data", dir_drv);
  2154. if (!dir_data)
  2155. goto err;
  2156. dir_rf = debugfs_create_dir("rf", dir_drv);
  2157. if (!dir_rf)
  2158. goto err;
  2159. dir_debug = debugfs_create_dir("debug", dir_drv);
  2160. if (!dir_debug)
  2161. goto err;
  2162. DEBUGFS_ADD_FILE(nvm, dir_data, S_IRUSR);
  2163. DEBUGFS_ADD_FILE(sram, dir_data, S_IWUSR | S_IRUSR);
  2164. DEBUGFS_ADD_FILE(wowlan_sram, dir_data, S_IRUSR);
  2165. DEBUGFS_ADD_FILE(stations, dir_data, S_IRUSR);
  2166. DEBUGFS_ADD_FILE(channels, dir_data, S_IRUSR);
  2167. DEBUGFS_ADD_FILE(status, dir_data, S_IRUSR);
  2168. DEBUGFS_ADD_FILE(rx_handlers, dir_data, S_IWUSR | S_IRUSR);
  2169. DEBUGFS_ADD_FILE(qos, dir_data, S_IRUSR);
  2170. DEBUGFS_ADD_FILE(sleep_level_override, dir_data, S_IWUSR | S_IRUSR);
  2171. DEBUGFS_ADD_FILE(current_sleep_command, dir_data, S_IRUSR);
  2172. DEBUGFS_ADD_FILE(thermal_throttling, dir_data, S_IRUSR);
  2173. DEBUGFS_ADD_FILE(disable_ht40, dir_data, S_IWUSR | S_IRUSR);
  2174. DEBUGFS_ADD_FILE(rx_statistics, dir_debug, S_IRUSR);
  2175. DEBUGFS_ADD_FILE(tx_statistics, dir_debug, S_IRUSR);
  2176. DEBUGFS_ADD_FILE(power_save_status, dir_debug, S_IRUSR);
  2177. DEBUGFS_ADD_FILE(clear_ucode_statistics, dir_debug, S_IWUSR);
  2178. DEBUGFS_ADD_FILE(clear_traffic_statistics, dir_debug, S_IWUSR);
  2179. DEBUGFS_ADD_FILE(missed_beacon, dir_debug, S_IWUSR);
  2180. DEBUGFS_ADD_FILE(plcp_delta, dir_debug, S_IWUSR | S_IRUSR);
  2181. DEBUGFS_ADD_FILE(force_reset, dir_debug, S_IWUSR | S_IRUSR);
  2182. DEBUGFS_ADD_FILE(ucode_rx_stats, dir_debug, S_IRUSR);
  2183. DEBUGFS_ADD_FILE(ucode_tx_stats, dir_debug, S_IRUSR);
  2184. DEBUGFS_ADD_FILE(ucode_general_stats, dir_debug, S_IRUSR);
  2185. DEBUGFS_ADD_FILE(txfifo_flush, dir_debug, S_IWUSR);
  2186. DEBUGFS_ADD_FILE(protection_mode, dir_debug, S_IWUSR | S_IRUSR);
  2187. DEBUGFS_ADD_FILE(sensitivity, dir_debug, S_IRUSR);
  2188. DEBUGFS_ADD_FILE(chain_noise, dir_debug, S_IRUSR);
  2189. DEBUGFS_ADD_FILE(ucode_tracing, dir_debug, S_IWUSR | S_IRUSR);
  2190. DEBUGFS_ADD_FILE(ucode_bt_stats, dir_debug, S_IRUSR);
  2191. DEBUGFS_ADD_FILE(reply_tx_error, dir_debug, S_IRUSR);
  2192. DEBUGFS_ADD_FILE(rxon_flags, dir_debug, S_IWUSR);
  2193. DEBUGFS_ADD_FILE(rxon_filter_flags, dir_debug, S_IWUSR);
  2194. DEBUGFS_ADD_FILE(wd_timeout, dir_debug, S_IWUSR);
  2195. if (iwl_advanced_bt_coexist(priv))
  2196. DEBUGFS_ADD_FILE(bt_traffic, dir_debug, S_IRUSR);
  2197. DEBUGFS_ADD_BOOL(disable_sensitivity, dir_rf,
  2198. &priv->disable_sens_cal);
  2199. DEBUGFS_ADD_BOOL(disable_chain_noise, dir_rf,
  2200. &priv->disable_chain_noise_cal);
  2201. if (iwl_trans_dbgfs_register(trans(priv), dir_debug))
  2202. goto err;
  2203. return 0;
  2204. err:
  2205. IWL_ERR(priv, "Can't create the debugfs directory\n");
  2206. iwl_dbgfs_unregister(priv);
  2207. return -ENOMEM;
  2208. }
  2209. /**
  2210. * Remove the debugfs files and directories
  2211. *
  2212. */
  2213. void iwl_dbgfs_unregister(struct iwl_priv *priv)
  2214. {
  2215. if (!priv->debugfs_dir)
  2216. return;
  2217. debugfs_remove_recursive(priv->debugfs_dir);
  2218. priv->debugfs_dir = NULL;
  2219. }