iwl-debugfs.c 83 KB

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