iwl-debugfs.c 85 KB

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