iwl-debugfs.c 85 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628
  1. /******************************************************************************
  2. *
  3. * GPL LICENSE SUMMARY
  4. *
  5. * Copyright(c) 2008 - 2012 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. struct iwl_trans *trans = trans(priv);
  210. priv->dbgfs_sram_offset = 0x800000;
  211. if (trans->shrd->ucode_type == IWL_UCODE_INIT)
  212. priv->dbgfs_sram_len = trans->ucode_init.data.len;
  213. else
  214. priv->dbgfs_sram_len = trans->ucode_rt.data.len;
  215. }
  216. len = priv->dbgfs_sram_len;
  217. if (len == -4) {
  218. device_format = true;
  219. len = 4;
  220. }
  221. bufsz = 50 + len * 4;
  222. buf = kmalloc(bufsz, GFP_KERNEL);
  223. if (!buf)
  224. return -ENOMEM;
  225. pos += scnprintf(buf + pos, bufsz - pos, "sram_len: 0x%x\n",
  226. len);
  227. pos += scnprintf(buf + pos, bufsz - pos, "sram_offset: 0x%x\n",
  228. priv->dbgfs_sram_offset);
  229. /* adjust sram address since reads are only on even u32 boundaries */
  230. offset = priv->dbgfs_sram_offset & 0x3;
  231. sram = priv->dbgfs_sram_offset & ~0x3;
  232. /* read the first u32 from sram */
  233. val = iwl_read_targ_mem(trans(priv), sram);
  234. for (; len; len--) {
  235. /* put the address at the start of every line */
  236. if (i == 0)
  237. pos += scnprintf(buf + pos, bufsz - pos,
  238. "%08X: ", sram + offset);
  239. if (device_format)
  240. pos += scnprintf(buf + pos, bufsz - pos,
  241. "%02x", (val >> (8 * (3 - offset))) & 0xff);
  242. else
  243. pos += scnprintf(buf + pos, bufsz - pos,
  244. "%02x ", (val >> (8 * offset)) & 0xff);
  245. /* if all bytes processed, read the next u32 from sram */
  246. if (++offset == 4) {
  247. sram += 4;
  248. offset = 0;
  249. val = iwl_read_targ_mem(trans(priv), sram);
  250. }
  251. /* put in extra spaces and split lines for human readability */
  252. if (++i == 16) {
  253. i = 0;
  254. pos += scnprintf(buf + pos, bufsz - pos, "\n");
  255. } else if (!(i & 7)) {
  256. pos += scnprintf(buf + pos, bufsz - pos, " ");
  257. } else if (!(i & 3)) {
  258. pos += scnprintf(buf + pos, bufsz - pos, " ");
  259. }
  260. }
  261. if (i)
  262. pos += scnprintf(buf + pos, bufsz - pos, "\n");
  263. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  264. kfree(buf);
  265. return ret;
  266. }
  267. static ssize_t iwl_dbgfs_sram_write(struct file *file,
  268. const char __user *user_buf,
  269. size_t count, loff_t *ppos)
  270. {
  271. struct iwl_priv *priv = file->private_data;
  272. char buf[64];
  273. int buf_size;
  274. u32 offset, len;
  275. memset(buf, 0, sizeof(buf));
  276. buf_size = min(count, sizeof(buf) - 1);
  277. if (copy_from_user(buf, user_buf, buf_size))
  278. return -EFAULT;
  279. if (sscanf(buf, "%x,%x", &offset, &len) == 2) {
  280. priv->dbgfs_sram_offset = offset;
  281. priv->dbgfs_sram_len = len;
  282. } else if (sscanf(buf, "%x", &offset) == 1) {
  283. priv->dbgfs_sram_offset = offset;
  284. priv->dbgfs_sram_len = -4;
  285. } else {
  286. priv->dbgfs_sram_offset = 0;
  287. priv->dbgfs_sram_len = 0;
  288. }
  289. return count;
  290. }
  291. static ssize_t iwl_dbgfs_wowlan_sram_read(struct file *file,
  292. char __user *user_buf,
  293. size_t count, loff_t *ppos)
  294. {
  295. struct iwl_priv *priv = file->private_data;
  296. if (!priv->wowlan_sram)
  297. return -ENODATA;
  298. return simple_read_from_buffer(user_buf, count, ppos,
  299. priv->wowlan_sram,
  300. trans(priv)->ucode_wowlan.data.len);
  301. }
  302. static ssize_t iwl_dbgfs_stations_read(struct file *file, char __user *user_buf,
  303. size_t count, loff_t *ppos)
  304. {
  305. struct iwl_priv *priv = file->private_data;
  306. struct iwl_station_entry *station;
  307. struct iwl_tid_data *tid_data;
  308. char *buf;
  309. int i, j, pos = 0;
  310. ssize_t ret;
  311. /* Add 30 for initial string */
  312. const size_t bufsz = 30 + sizeof(char) * 500 * (priv->num_stations);
  313. buf = kmalloc(bufsz, GFP_KERNEL);
  314. if (!buf)
  315. return -ENOMEM;
  316. pos += scnprintf(buf + pos, bufsz - pos, "num of stations: %d\n\n",
  317. priv->num_stations);
  318. for (i = 0; i < IWLAGN_STATION_COUNT; i++) {
  319. station = &priv->stations[i];
  320. if (!station->used)
  321. continue;
  322. pos += scnprintf(buf + pos, bufsz - pos,
  323. "station %d - addr: %pM, flags: %#x\n",
  324. i, station->sta.sta.addr,
  325. station->sta.station_flags_msk);
  326. pos += scnprintf(buf + pos, bufsz - pos,
  327. "TID\tseq_num\trate_n_flags\n");
  328. for (j = 0; j < IWL_MAX_TID_COUNT; j++) {
  329. tid_data = &priv->tid_data[i][j];
  330. pos += scnprintf(buf + pos, bufsz - pos,
  331. "%d:\t%#x\t%#x",
  332. j, tid_data->seq_number,
  333. tid_data->agg.rate_n_flags);
  334. if (tid_data->agg.wait_for_ba)
  335. pos += scnprintf(buf + pos, bufsz - pos,
  336. " - waitforba");
  337. pos += scnprintf(buf + pos, bufsz - pos, "\n");
  338. }
  339. pos += scnprintf(buf + pos, bufsz - pos, "\n");
  340. }
  341. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  342. kfree(buf);
  343. return ret;
  344. }
  345. static ssize_t iwl_dbgfs_nvm_read(struct file *file,
  346. char __user *user_buf,
  347. size_t count,
  348. loff_t *ppos)
  349. {
  350. ssize_t ret;
  351. struct iwl_priv *priv = file->private_data;
  352. int pos = 0, ofs = 0, buf_size = 0;
  353. const u8 *ptr;
  354. char *buf;
  355. u16 eeprom_ver;
  356. size_t eeprom_len = cfg(priv)->base_params->eeprom_size;
  357. buf_size = 4 * eeprom_len + 256;
  358. if (eeprom_len % 16) {
  359. IWL_ERR(priv, "NVM size is not multiple of 16.\n");
  360. return -ENODATA;
  361. }
  362. ptr = priv->shrd->eeprom;
  363. if (!ptr) {
  364. IWL_ERR(priv, "Invalid EEPROM/OTP memory\n");
  365. return -ENOMEM;
  366. }
  367. /* 4 characters for byte 0xYY */
  368. buf = kzalloc(buf_size, GFP_KERNEL);
  369. if (!buf) {
  370. IWL_ERR(priv, "Can not allocate Buffer\n");
  371. return -ENOMEM;
  372. }
  373. eeprom_ver = iwl_eeprom_query16(priv->shrd, EEPROM_VERSION);
  374. pos += scnprintf(buf + pos, buf_size - pos, "NVM Type: %s, "
  375. "version: 0x%x\n",
  376. (trans(priv)->nvm_device_type == NVM_DEVICE_TYPE_OTP)
  377. ? "OTP" : "EEPROM", eeprom_ver);
  378. for (ofs = 0 ; ofs < eeprom_len ; ofs += 16) {
  379. pos += scnprintf(buf + pos, buf_size - pos, "0x%.4x ", ofs);
  380. hex_dump_to_buffer(ptr + ofs, 16 , 16, 2, buf + pos,
  381. buf_size - pos, 0);
  382. pos += strlen(buf + pos);
  383. if (buf_size - pos > 0)
  384. buf[pos++] = '\n';
  385. }
  386. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  387. kfree(buf);
  388. return ret;
  389. }
  390. static ssize_t iwl_dbgfs_channels_read(struct file *file, char __user *user_buf,
  391. size_t count, loff_t *ppos)
  392. {
  393. struct iwl_priv *priv = file->private_data;
  394. struct ieee80211_channel *channels = NULL;
  395. const struct ieee80211_supported_band *supp_band = NULL;
  396. int pos = 0, i, bufsz = PAGE_SIZE;
  397. char *buf;
  398. ssize_t ret;
  399. if (!test_bit(STATUS_GEO_CONFIGURED, &priv->shrd->status))
  400. return -EAGAIN;
  401. buf = kzalloc(bufsz, GFP_KERNEL);
  402. if (!buf) {
  403. IWL_ERR(priv, "Can not allocate Buffer\n");
  404. return -ENOMEM;
  405. }
  406. supp_band = iwl_get_hw_mode(priv, IEEE80211_BAND_2GHZ);
  407. if (supp_band) {
  408. channels = supp_band->channels;
  409. pos += scnprintf(buf + pos, bufsz - pos,
  410. "Displaying %d channels in 2.4GHz band 802.11bg):\n",
  411. supp_band->n_channels);
  412. for (i = 0; i < supp_band->n_channels; i++)
  413. pos += scnprintf(buf + pos, bufsz - pos,
  414. "%d: %ddBm: BSS%s%s, %s.\n",
  415. channels[i].hw_value,
  416. channels[i].max_power,
  417. channels[i].flags & IEEE80211_CHAN_RADAR ?
  418. " (IEEE 802.11h required)" : "",
  419. ((channels[i].flags & IEEE80211_CHAN_NO_IBSS)
  420. || (channels[i].flags &
  421. IEEE80211_CHAN_RADAR)) ? "" :
  422. ", IBSS",
  423. channels[i].flags &
  424. IEEE80211_CHAN_PASSIVE_SCAN ?
  425. "passive only" : "active/passive");
  426. }
  427. supp_band = iwl_get_hw_mode(priv, IEEE80211_BAND_5GHZ);
  428. if (supp_band) {
  429. channels = supp_band->channels;
  430. pos += scnprintf(buf + pos, bufsz - pos,
  431. "Displaying %d channels in 5.2GHz band (802.11a)\n",
  432. supp_band->n_channels);
  433. for (i = 0; i < supp_band->n_channels; i++)
  434. pos += scnprintf(buf + pos, bufsz - pos,
  435. "%d: %ddBm: BSS%s%s, %s.\n",
  436. channels[i].hw_value,
  437. channels[i].max_power,
  438. channels[i].flags & IEEE80211_CHAN_RADAR ?
  439. " (IEEE 802.11h required)" : "",
  440. ((channels[i].flags & IEEE80211_CHAN_NO_IBSS)
  441. || (channels[i].flags &
  442. IEEE80211_CHAN_RADAR)) ? "" :
  443. ", IBSS",
  444. channels[i].flags &
  445. IEEE80211_CHAN_PASSIVE_SCAN ?
  446. "passive only" : "active/passive");
  447. }
  448. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  449. kfree(buf);
  450. return ret;
  451. }
  452. static ssize_t iwl_dbgfs_status_read(struct file *file,
  453. char __user *user_buf,
  454. size_t count, loff_t *ppos) {
  455. struct iwl_priv *priv = file->private_data;
  456. char buf[512];
  457. int pos = 0;
  458. const size_t bufsz = sizeof(buf);
  459. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_HCMD_ACTIVE:\t %d\n",
  460. test_bit(STATUS_HCMD_ACTIVE, &priv->shrd->status));
  461. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_INT_ENABLED:\t %d\n",
  462. test_bit(STATUS_INT_ENABLED, &priv->shrd->status));
  463. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_RF_KILL_HW:\t %d\n",
  464. test_bit(STATUS_RF_KILL_HW, &priv->shrd->status));
  465. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_CT_KILL:\t\t %d\n",
  466. test_bit(STATUS_CT_KILL, &priv->shrd->status));
  467. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_INIT:\t\t %d\n",
  468. test_bit(STATUS_INIT, &priv->shrd->status));
  469. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_ALIVE:\t\t %d\n",
  470. test_bit(STATUS_ALIVE, &priv->shrd->status));
  471. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_READY:\t\t %d\n",
  472. test_bit(STATUS_READY, &priv->shrd->status));
  473. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_TEMPERATURE:\t %d\n",
  474. test_bit(STATUS_TEMPERATURE, &priv->shrd->status));
  475. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_GEO_CONFIGURED:\t %d\n",
  476. test_bit(STATUS_GEO_CONFIGURED, &priv->shrd->status));
  477. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_EXIT_PENDING:\t %d\n",
  478. test_bit(STATUS_EXIT_PENDING, &priv->shrd->status));
  479. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_STATISTICS:\t %d\n",
  480. test_bit(STATUS_STATISTICS, &priv->shrd->status));
  481. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_SCANNING:\t %d\n",
  482. test_bit(STATUS_SCANNING, &priv->shrd->status));
  483. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_SCAN_ABORTING:\t %d\n",
  484. test_bit(STATUS_SCAN_ABORTING, &priv->shrd->status));
  485. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_SCAN_HW:\t\t %d\n",
  486. test_bit(STATUS_SCAN_HW, &priv->shrd->status));
  487. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_POWER_PMI:\t %d\n",
  488. test_bit(STATUS_POWER_PMI, &priv->shrd->status));
  489. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_FW_ERROR:\t %d\n",
  490. test_bit(STATUS_FW_ERROR, &priv->shrd->status));
  491. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  492. }
  493. static ssize_t iwl_dbgfs_rx_handlers_read(struct file *file,
  494. char __user *user_buf,
  495. size_t count, loff_t *ppos) {
  496. struct iwl_priv *priv = file->private_data;
  497. int pos = 0;
  498. int cnt = 0;
  499. char *buf;
  500. int bufsz = 24 * 64; /* 24 items * 64 char per item */
  501. ssize_t ret;
  502. buf = kzalloc(bufsz, GFP_KERNEL);
  503. if (!buf) {
  504. IWL_ERR(priv, "Can not allocate Buffer\n");
  505. return -ENOMEM;
  506. }
  507. for (cnt = 0; cnt < REPLY_MAX; cnt++) {
  508. if (priv->rx_handlers_stats[cnt] > 0)
  509. pos += scnprintf(buf + pos, bufsz - pos,
  510. "\tRx handler[%36s]:\t\t %u\n",
  511. get_cmd_string(cnt),
  512. priv->rx_handlers_stats[cnt]);
  513. }
  514. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  515. kfree(buf);
  516. return ret;
  517. }
  518. static ssize_t iwl_dbgfs_rx_handlers_write(struct file *file,
  519. const char __user *user_buf,
  520. size_t count, loff_t *ppos)
  521. {
  522. struct iwl_priv *priv = file->private_data;
  523. char buf[8];
  524. int buf_size;
  525. u32 reset_flag;
  526. memset(buf, 0, sizeof(buf));
  527. buf_size = min(count, sizeof(buf) - 1);
  528. if (copy_from_user(buf, user_buf, buf_size))
  529. return -EFAULT;
  530. if (sscanf(buf, "%x", &reset_flag) != 1)
  531. return -EFAULT;
  532. if (reset_flag == 0)
  533. memset(&priv->rx_handlers_stats[0], 0,
  534. sizeof(priv->rx_handlers_stats));
  535. return count;
  536. }
  537. static ssize_t iwl_dbgfs_qos_read(struct file *file, char __user *user_buf,
  538. size_t count, loff_t *ppos)
  539. {
  540. struct iwl_priv *priv = file->private_data;
  541. struct iwl_rxon_context *ctx;
  542. int pos = 0, i;
  543. char buf[256 * NUM_IWL_RXON_CTX];
  544. const size_t bufsz = sizeof(buf);
  545. for_each_context(priv, ctx) {
  546. pos += scnprintf(buf + pos, bufsz - pos, "context %d:\n",
  547. ctx->ctxid);
  548. for (i = 0; i < AC_NUM; i++) {
  549. pos += scnprintf(buf + pos, bufsz - pos,
  550. "\tcw_min\tcw_max\taifsn\ttxop\n");
  551. pos += scnprintf(buf + pos, bufsz - pos,
  552. "AC[%d]\t%u\t%u\t%u\t%u\n", i,
  553. ctx->qos_data.def_qos_parm.ac[i].cw_min,
  554. ctx->qos_data.def_qos_parm.ac[i].cw_max,
  555. ctx->qos_data.def_qos_parm.ac[i].aifsn,
  556. ctx->qos_data.def_qos_parm.ac[i].edca_txop);
  557. }
  558. pos += scnprintf(buf + pos, bufsz - pos, "\n");
  559. }
  560. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  561. }
  562. static ssize_t iwl_dbgfs_thermal_throttling_read(struct file *file,
  563. char __user *user_buf,
  564. size_t count, loff_t *ppos)
  565. {
  566. struct iwl_priv *priv = file->private_data;
  567. struct iwl_tt_mgmt *tt = &priv->thermal_throttle;
  568. struct iwl_tt_restriction *restriction;
  569. char buf[100];
  570. int pos = 0;
  571. const size_t bufsz = sizeof(buf);
  572. pos += scnprintf(buf + pos, bufsz - pos,
  573. "Thermal Throttling Mode: %s\n",
  574. tt->advanced_tt ? "Advance" : "Legacy");
  575. pos += scnprintf(buf + pos, bufsz - pos,
  576. "Thermal Throttling State: %d\n",
  577. tt->state);
  578. if (tt->advanced_tt) {
  579. restriction = tt->restriction + tt->state;
  580. pos += scnprintf(buf + pos, bufsz - pos,
  581. "Tx mode: %d\n",
  582. restriction->tx_stream);
  583. pos += scnprintf(buf + pos, bufsz - pos,
  584. "Rx mode: %d\n",
  585. restriction->rx_stream);
  586. pos += scnprintf(buf + pos, bufsz - pos,
  587. "HT mode: %d\n",
  588. restriction->is_ht);
  589. }
  590. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  591. }
  592. static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
  593. const char __user *user_buf,
  594. size_t count, loff_t *ppos)
  595. {
  596. struct iwl_priv *priv = file->private_data;
  597. char buf[8];
  598. int buf_size;
  599. int ht40;
  600. memset(buf, 0, sizeof(buf));
  601. buf_size = min(count, sizeof(buf) - 1);
  602. if (copy_from_user(buf, user_buf, buf_size))
  603. return -EFAULT;
  604. if (sscanf(buf, "%d", &ht40) != 1)
  605. return -EFAULT;
  606. if (!iwl_is_any_associated(priv))
  607. priv->disable_ht40 = ht40 ? true : false;
  608. else {
  609. IWL_ERR(priv, "Sta associated with AP - "
  610. "Change to 40MHz channel support is not allowed\n");
  611. return -EINVAL;
  612. }
  613. return count;
  614. }
  615. static ssize_t iwl_dbgfs_disable_ht40_read(struct file *file,
  616. char __user *user_buf,
  617. size_t count, loff_t *ppos)
  618. {
  619. struct iwl_priv *priv = file->private_data;
  620. char buf[100];
  621. int pos = 0;
  622. const size_t bufsz = sizeof(buf);
  623. pos += scnprintf(buf + pos, bufsz - pos,
  624. "11n 40MHz Mode: %s\n",
  625. priv->disable_ht40 ? "Disabled" : "Enabled");
  626. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  627. }
  628. static ssize_t iwl_dbgfs_temperature_read(struct file *file,
  629. char __user *user_buf,
  630. size_t count, loff_t *ppos)
  631. {
  632. struct iwl_priv *priv = file->private_data;
  633. char buf[8];
  634. int pos = 0;
  635. const size_t bufsz = sizeof(buf);
  636. pos += scnprintf(buf + pos, bufsz - pos, "%d\n", priv->temperature);
  637. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  638. }
  639. static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
  640. const char __user *user_buf,
  641. size_t count, loff_t *ppos)
  642. {
  643. struct iwl_priv *priv = file->private_data;
  644. char buf[8];
  645. int buf_size;
  646. int value;
  647. memset(buf, 0, sizeof(buf));
  648. buf_size = min(count, sizeof(buf) - 1);
  649. if (copy_from_user(buf, user_buf, buf_size))
  650. return -EFAULT;
  651. if (sscanf(buf, "%d", &value) != 1)
  652. return -EINVAL;
  653. /*
  654. * Our users expect 0 to be "CAM", but 0 isn't actually
  655. * valid here. However, let's not confuse them and present
  656. * IWL_POWER_INDEX_1 as "1", not "0".
  657. */
  658. if (value == 0)
  659. return -EINVAL;
  660. else if (value > 0)
  661. value -= 1;
  662. if (value != -1 && (value < 0 || value >= IWL_POWER_NUM))
  663. return -EINVAL;
  664. if (!iwl_is_ready_rf(priv->shrd))
  665. return -EAGAIN;
  666. priv->power_data.debug_sleep_level_override = value;
  667. mutex_lock(&priv->shrd->mutex);
  668. iwl_power_update_mode(priv, true);
  669. mutex_unlock(&priv->shrd->mutex);
  670. return count;
  671. }
  672. static ssize_t iwl_dbgfs_sleep_level_override_read(struct file *file,
  673. char __user *user_buf,
  674. size_t count, loff_t *ppos)
  675. {
  676. struct iwl_priv *priv = file->private_data;
  677. char buf[10];
  678. int pos, value;
  679. const size_t bufsz = sizeof(buf);
  680. /* see the write function */
  681. value = priv->power_data.debug_sleep_level_override;
  682. if (value >= 0)
  683. value += 1;
  684. pos = scnprintf(buf, bufsz, "%d\n", value);
  685. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  686. }
  687. static ssize_t iwl_dbgfs_current_sleep_command_read(struct file *file,
  688. char __user *user_buf,
  689. size_t count, loff_t *ppos)
  690. {
  691. struct iwl_priv *priv = file->private_data;
  692. char buf[200];
  693. int pos = 0, i;
  694. const size_t bufsz = sizeof(buf);
  695. struct iwl_powertable_cmd *cmd = &priv->power_data.sleep_cmd;
  696. pos += scnprintf(buf + pos, bufsz - pos,
  697. "flags: %#.2x\n", le16_to_cpu(cmd->flags));
  698. pos += scnprintf(buf + pos, bufsz - pos,
  699. "RX/TX timeout: %d/%d usec\n",
  700. le32_to_cpu(cmd->rx_data_timeout),
  701. le32_to_cpu(cmd->tx_data_timeout));
  702. for (i = 0; i < IWL_POWER_VEC_SIZE; i++)
  703. pos += scnprintf(buf + pos, bufsz - pos,
  704. "sleep_interval[%d]: %d\n", i,
  705. le32_to_cpu(cmd->sleep_interval[i]));
  706. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  707. }
  708. DEBUGFS_READ_WRITE_FILE_OPS(sram);
  709. DEBUGFS_READ_FILE_OPS(wowlan_sram);
  710. DEBUGFS_READ_FILE_OPS(nvm);
  711. DEBUGFS_READ_FILE_OPS(stations);
  712. DEBUGFS_READ_FILE_OPS(channels);
  713. DEBUGFS_READ_FILE_OPS(status);
  714. DEBUGFS_READ_WRITE_FILE_OPS(rx_handlers);
  715. DEBUGFS_READ_FILE_OPS(qos);
  716. DEBUGFS_READ_FILE_OPS(thermal_throttling);
  717. DEBUGFS_READ_WRITE_FILE_OPS(disable_ht40);
  718. DEBUGFS_READ_FILE_OPS(temperature);
  719. DEBUGFS_READ_WRITE_FILE_OPS(sleep_level_override);
  720. DEBUGFS_READ_FILE_OPS(current_sleep_command);
  721. static ssize_t iwl_dbgfs_traffic_log_read(struct file *file,
  722. char __user *user_buf,
  723. size_t count, loff_t *ppos)
  724. {
  725. struct iwl_priv *priv = file->private_data;
  726. int pos = 0, ofs = 0;
  727. int cnt = 0, entry;
  728. char *buf;
  729. int bufsz = ((IWL_TRAFFIC_ENTRIES * IWL_TRAFFIC_ENTRY_SIZE * 64) * 2) +
  730. (hw_params(priv).max_txq_num * 32 * 8) + 400;
  731. const u8 *ptr;
  732. ssize_t ret;
  733. buf = kzalloc(bufsz, GFP_KERNEL);
  734. if (!buf) {
  735. IWL_ERR(priv, "Can not allocate buffer\n");
  736. return -ENOMEM;
  737. }
  738. if (priv->tx_traffic &&
  739. (iwl_get_debug_level(priv->shrd) & IWL_DL_TX)) {
  740. ptr = priv->tx_traffic;
  741. pos += scnprintf(buf + pos, bufsz - pos,
  742. "Tx Traffic idx: %u\n", priv->tx_traffic_idx);
  743. for (cnt = 0, ofs = 0; cnt < IWL_TRAFFIC_ENTRIES; cnt++) {
  744. for (entry = 0; entry < IWL_TRAFFIC_ENTRY_SIZE / 16;
  745. entry++, ofs += 16) {
  746. pos += scnprintf(buf + pos, bufsz - pos,
  747. "0x%.4x ", ofs);
  748. hex_dump_to_buffer(ptr + ofs, 16, 16, 2,
  749. buf + pos, bufsz - pos, 0);
  750. pos += strlen(buf + pos);
  751. if (bufsz - pos > 0)
  752. buf[pos++] = '\n';
  753. }
  754. }
  755. }
  756. if (priv->rx_traffic &&
  757. (iwl_get_debug_level(priv->shrd) & IWL_DL_RX)) {
  758. ptr = priv->rx_traffic;
  759. pos += scnprintf(buf + pos, bufsz - pos,
  760. "Rx Traffic idx: %u\n", priv->rx_traffic_idx);
  761. for (cnt = 0, ofs = 0; cnt < IWL_TRAFFIC_ENTRIES; cnt++) {
  762. for (entry = 0; entry < IWL_TRAFFIC_ENTRY_SIZE / 16;
  763. entry++, ofs += 16) {
  764. pos += scnprintf(buf + pos, bufsz - pos,
  765. "0x%.4x ", ofs);
  766. hex_dump_to_buffer(ptr + ofs, 16, 16, 2,
  767. buf + pos, bufsz - pos, 0);
  768. pos += strlen(buf + pos);
  769. if (bufsz - pos > 0)
  770. buf[pos++] = '\n';
  771. }
  772. }
  773. }
  774. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  775. kfree(buf);
  776. return ret;
  777. }
  778. static ssize_t iwl_dbgfs_traffic_log_write(struct file *file,
  779. const char __user *user_buf,
  780. size_t count, loff_t *ppos)
  781. {
  782. struct iwl_priv *priv = file->private_data;
  783. char buf[8];
  784. int buf_size;
  785. int traffic_log;
  786. memset(buf, 0, sizeof(buf));
  787. buf_size = min(count, sizeof(buf) - 1);
  788. if (copy_from_user(buf, user_buf, buf_size))
  789. return -EFAULT;
  790. if (sscanf(buf, "%d", &traffic_log) != 1)
  791. return -EFAULT;
  792. if (traffic_log == 0)
  793. iwl_reset_traffic_log(priv);
  794. return count;
  795. }
  796. static const char *fmt_value = " %-30s %10u\n";
  797. static const char *fmt_hex = " %-30s 0x%02X\n";
  798. static const char *fmt_table = " %-30s %10u %10u %10u %10u\n";
  799. static const char *fmt_header =
  800. "%-32s current cumulative delta max\n";
  801. static int iwl_statistics_flag(struct iwl_priv *priv, char *buf, int bufsz)
  802. {
  803. int p = 0;
  804. u32 flag;
  805. flag = le32_to_cpu(priv->statistics.flag);
  806. p += scnprintf(buf + p, bufsz - p, "Statistics Flag(0x%X):\n", flag);
  807. if (flag & UCODE_STATISTICS_CLEAR_MSK)
  808. p += scnprintf(buf + p, bufsz - p,
  809. "\tStatistics have been cleared\n");
  810. p += scnprintf(buf + p, bufsz - p, "\tOperational Frequency: %s\n",
  811. (flag & UCODE_STATISTICS_FREQUENCY_MSK)
  812. ? "2.4 GHz" : "5.2 GHz");
  813. p += scnprintf(buf + p, bufsz - p, "\tTGj Narrow Band: %s\n",
  814. (flag & UCODE_STATISTICS_NARROW_BAND_MSK)
  815. ? "enabled" : "disabled");
  816. return p;
  817. }
  818. static ssize_t iwl_dbgfs_ucode_rx_stats_read(struct file *file,
  819. char __user *user_buf,
  820. size_t count, loff_t *ppos)
  821. {
  822. struct iwl_priv *priv = file->private_data;
  823. int pos = 0;
  824. char *buf;
  825. int bufsz = sizeof(struct statistics_rx_phy) * 40 +
  826. sizeof(struct statistics_rx_non_phy) * 40 +
  827. sizeof(struct statistics_rx_ht_phy) * 40 + 400;
  828. ssize_t ret;
  829. struct statistics_rx_phy *ofdm, *accum_ofdm, *delta_ofdm, *max_ofdm;
  830. struct statistics_rx_phy *cck, *accum_cck, *delta_cck, *max_cck;
  831. struct statistics_rx_non_phy *general, *accum_general;
  832. struct statistics_rx_non_phy *delta_general, *max_general;
  833. struct statistics_rx_ht_phy *ht, *accum_ht, *delta_ht, *max_ht;
  834. if (!iwl_is_alive(priv->shrd))
  835. return -EAGAIN;
  836. buf = kzalloc(bufsz, GFP_KERNEL);
  837. if (!buf) {
  838. IWL_ERR(priv, "Can not allocate Buffer\n");
  839. return -ENOMEM;
  840. }
  841. /*
  842. * the statistic information display here is based on
  843. * the last statistics notification from uCode
  844. * might not reflect the current uCode activity
  845. */
  846. ofdm = &priv->statistics.rx_ofdm;
  847. cck = &priv->statistics.rx_cck;
  848. general = &priv->statistics.rx_non_phy;
  849. ht = &priv->statistics.rx_ofdm_ht;
  850. accum_ofdm = &priv->accum_stats.rx_ofdm;
  851. accum_cck = &priv->accum_stats.rx_cck;
  852. accum_general = &priv->accum_stats.rx_non_phy;
  853. accum_ht = &priv->accum_stats.rx_ofdm_ht;
  854. delta_ofdm = &priv->delta_stats.rx_ofdm;
  855. delta_cck = &priv->delta_stats.rx_cck;
  856. delta_general = &priv->delta_stats.rx_non_phy;
  857. delta_ht = &priv->delta_stats.rx_ofdm_ht;
  858. max_ofdm = &priv->max_delta_stats.rx_ofdm;
  859. max_cck = &priv->max_delta_stats.rx_cck;
  860. max_general = &priv->max_delta_stats.rx_non_phy;
  861. max_ht = &priv->max_delta_stats.rx_ofdm_ht;
  862. pos += iwl_statistics_flag(priv, buf, bufsz);
  863. pos += scnprintf(buf + pos, bufsz - pos,
  864. fmt_header, "Statistics_Rx - OFDM:");
  865. pos += scnprintf(buf + pos, bufsz - pos,
  866. fmt_table, "ina_cnt:",
  867. le32_to_cpu(ofdm->ina_cnt),
  868. accum_ofdm->ina_cnt,
  869. delta_ofdm->ina_cnt, max_ofdm->ina_cnt);
  870. pos += scnprintf(buf + pos, bufsz - pos,
  871. fmt_table, "fina_cnt:",
  872. le32_to_cpu(ofdm->fina_cnt), accum_ofdm->fina_cnt,
  873. delta_ofdm->fina_cnt, max_ofdm->fina_cnt);
  874. pos += scnprintf(buf + pos, bufsz - pos,
  875. fmt_table, "plcp_err:",
  876. le32_to_cpu(ofdm->plcp_err), accum_ofdm->plcp_err,
  877. delta_ofdm->plcp_err, max_ofdm->plcp_err);
  878. pos += scnprintf(buf + pos, bufsz - pos,
  879. fmt_table, "crc32_err:",
  880. le32_to_cpu(ofdm->crc32_err), accum_ofdm->crc32_err,
  881. delta_ofdm->crc32_err, max_ofdm->crc32_err);
  882. pos += scnprintf(buf + pos, bufsz - pos,
  883. fmt_table, "overrun_err:",
  884. le32_to_cpu(ofdm->overrun_err),
  885. accum_ofdm->overrun_err, delta_ofdm->overrun_err,
  886. max_ofdm->overrun_err);
  887. pos += scnprintf(buf + pos, bufsz - pos,
  888. fmt_table, "early_overrun_err:",
  889. le32_to_cpu(ofdm->early_overrun_err),
  890. accum_ofdm->early_overrun_err,
  891. delta_ofdm->early_overrun_err,
  892. max_ofdm->early_overrun_err);
  893. pos += scnprintf(buf + pos, bufsz - pos,
  894. fmt_table, "crc32_good:",
  895. le32_to_cpu(ofdm->crc32_good),
  896. accum_ofdm->crc32_good, delta_ofdm->crc32_good,
  897. max_ofdm->crc32_good);
  898. pos += scnprintf(buf + pos, bufsz - pos,
  899. fmt_table, "false_alarm_cnt:",
  900. le32_to_cpu(ofdm->false_alarm_cnt),
  901. accum_ofdm->false_alarm_cnt,
  902. delta_ofdm->false_alarm_cnt,
  903. max_ofdm->false_alarm_cnt);
  904. pos += scnprintf(buf + pos, bufsz - pos,
  905. fmt_table, "fina_sync_err_cnt:",
  906. le32_to_cpu(ofdm->fina_sync_err_cnt),
  907. accum_ofdm->fina_sync_err_cnt,
  908. delta_ofdm->fina_sync_err_cnt,
  909. max_ofdm->fina_sync_err_cnt);
  910. pos += scnprintf(buf + pos, bufsz - pos,
  911. fmt_table, "sfd_timeout:",
  912. le32_to_cpu(ofdm->sfd_timeout),
  913. accum_ofdm->sfd_timeout, delta_ofdm->sfd_timeout,
  914. max_ofdm->sfd_timeout);
  915. pos += scnprintf(buf + pos, bufsz - pos,
  916. fmt_table, "fina_timeout:",
  917. le32_to_cpu(ofdm->fina_timeout),
  918. accum_ofdm->fina_timeout, delta_ofdm->fina_timeout,
  919. max_ofdm->fina_timeout);
  920. pos += scnprintf(buf + pos, bufsz - pos,
  921. fmt_table, "unresponded_rts:",
  922. le32_to_cpu(ofdm->unresponded_rts),
  923. accum_ofdm->unresponded_rts,
  924. delta_ofdm->unresponded_rts,
  925. max_ofdm->unresponded_rts);
  926. pos += scnprintf(buf + pos, bufsz - pos,
  927. fmt_table, "rxe_frame_lmt_ovrun:",
  928. le32_to_cpu(ofdm->rxe_frame_limit_overrun),
  929. accum_ofdm->rxe_frame_limit_overrun,
  930. delta_ofdm->rxe_frame_limit_overrun,
  931. max_ofdm->rxe_frame_limit_overrun);
  932. pos += scnprintf(buf + pos, bufsz - pos,
  933. fmt_table, "sent_ack_cnt:",
  934. le32_to_cpu(ofdm->sent_ack_cnt),
  935. accum_ofdm->sent_ack_cnt, delta_ofdm->sent_ack_cnt,
  936. max_ofdm->sent_ack_cnt);
  937. pos += scnprintf(buf + pos, bufsz - pos,
  938. fmt_table, "sent_cts_cnt:",
  939. le32_to_cpu(ofdm->sent_cts_cnt),
  940. accum_ofdm->sent_cts_cnt, delta_ofdm->sent_cts_cnt,
  941. max_ofdm->sent_cts_cnt);
  942. pos += scnprintf(buf + pos, bufsz - pos,
  943. fmt_table, "sent_ba_rsp_cnt:",
  944. le32_to_cpu(ofdm->sent_ba_rsp_cnt),
  945. accum_ofdm->sent_ba_rsp_cnt,
  946. delta_ofdm->sent_ba_rsp_cnt,
  947. max_ofdm->sent_ba_rsp_cnt);
  948. pos += scnprintf(buf + pos, bufsz - pos,
  949. fmt_table, "dsp_self_kill:",
  950. le32_to_cpu(ofdm->dsp_self_kill),
  951. accum_ofdm->dsp_self_kill,
  952. delta_ofdm->dsp_self_kill,
  953. max_ofdm->dsp_self_kill);
  954. pos += scnprintf(buf + pos, bufsz - pos,
  955. fmt_table, "mh_format_err:",
  956. le32_to_cpu(ofdm->mh_format_err),
  957. accum_ofdm->mh_format_err,
  958. delta_ofdm->mh_format_err,
  959. max_ofdm->mh_format_err);
  960. pos += scnprintf(buf + pos, bufsz - pos,
  961. fmt_table, "re_acq_main_rssi_sum:",
  962. le32_to_cpu(ofdm->re_acq_main_rssi_sum),
  963. accum_ofdm->re_acq_main_rssi_sum,
  964. delta_ofdm->re_acq_main_rssi_sum,
  965. max_ofdm->re_acq_main_rssi_sum);
  966. pos += scnprintf(buf + pos, bufsz - pos,
  967. fmt_header, "Statistics_Rx - CCK:");
  968. pos += scnprintf(buf + pos, bufsz - pos,
  969. fmt_table, "ina_cnt:",
  970. le32_to_cpu(cck->ina_cnt), accum_cck->ina_cnt,
  971. delta_cck->ina_cnt, max_cck->ina_cnt);
  972. pos += scnprintf(buf + pos, bufsz - pos,
  973. fmt_table, "fina_cnt:",
  974. le32_to_cpu(cck->fina_cnt), accum_cck->fina_cnt,
  975. delta_cck->fina_cnt, max_cck->fina_cnt);
  976. pos += scnprintf(buf + pos, bufsz - pos,
  977. fmt_table, "plcp_err:",
  978. le32_to_cpu(cck->plcp_err), accum_cck->plcp_err,
  979. delta_cck->plcp_err, max_cck->plcp_err);
  980. pos += scnprintf(buf + pos, bufsz - pos,
  981. fmt_table, "crc32_err:",
  982. le32_to_cpu(cck->crc32_err), accum_cck->crc32_err,
  983. delta_cck->crc32_err, max_cck->crc32_err);
  984. pos += scnprintf(buf + pos, bufsz - pos,
  985. fmt_table, "overrun_err:",
  986. le32_to_cpu(cck->overrun_err),
  987. accum_cck->overrun_err, delta_cck->overrun_err,
  988. max_cck->overrun_err);
  989. pos += scnprintf(buf + pos, bufsz - pos,
  990. fmt_table, "early_overrun_err:",
  991. le32_to_cpu(cck->early_overrun_err),
  992. accum_cck->early_overrun_err,
  993. delta_cck->early_overrun_err,
  994. max_cck->early_overrun_err);
  995. pos += scnprintf(buf + pos, bufsz - pos,
  996. fmt_table, "crc32_good:",
  997. le32_to_cpu(cck->crc32_good), accum_cck->crc32_good,
  998. delta_cck->crc32_good, max_cck->crc32_good);
  999. pos += scnprintf(buf + pos, bufsz - pos,
  1000. fmt_table, "false_alarm_cnt:",
  1001. le32_to_cpu(cck->false_alarm_cnt),
  1002. accum_cck->false_alarm_cnt,
  1003. delta_cck->false_alarm_cnt, max_cck->false_alarm_cnt);
  1004. pos += scnprintf(buf + pos, bufsz - pos,
  1005. fmt_table, "fina_sync_err_cnt:",
  1006. le32_to_cpu(cck->fina_sync_err_cnt),
  1007. accum_cck->fina_sync_err_cnt,
  1008. delta_cck->fina_sync_err_cnt,
  1009. max_cck->fina_sync_err_cnt);
  1010. pos += scnprintf(buf + pos, bufsz - pos,
  1011. fmt_table, "sfd_timeout:",
  1012. le32_to_cpu(cck->sfd_timeout),
  1013. accum_cck->sfd_timeout, delta_cck->sfd_timeout,
  1014. max_cck->sfd_timeout);
  1015. pos += scnprintf(buf + pos, bufsz - pos,
  1016. fmt_table, "fina_timeout:",
  1017. le32_to_cpu(cck->fina_timeout),
  1018. accum_cck->fina_timeout, delta_cck->fina_timeout,
  1019. max_cck->fina_timeout);
  1020. pos += scnprintf(buf + pos, bufsz - pos,
  1021. fmt_table, "unresponded_rts:",
  1022. le32_to_cpu(cck->unresponded_rts),
  1023. accum_cck->unresponded_rts, delta_cck->unresponded_rts,
  1024. max_cck->unresponded_rts);
  1025. pos += scnprintf(buf + pos, bufsz - pos,
  1026. fmt_table, "rxe_frame_lmt_ovrun:",
  1027. le32_to_cpu(cck->rxe_frame_limit_overrun),
  1028. accum_cck->rxe_frame_limit_overrun,
  1029. delta_cck->rxe_frame_limit_overrun,
  1030. max_cck->rxe_frame_limit_overrun);
  1031. pos += scnprintf(buf + pos, bufsz - pos,
  1032. fmt_table, "sent_ack_cnt:",
  1033. le32_to_cpu(cck->sent_ack_cnt),
  1034. accum_cck->sent_ack_cnt, delta_cck->sent_ack_cnt,
  1035. max_cck->sent_ack_cnt);
  1036. pos += scnprintf(buf + pos, bufsz - pos,
  1037. fmt_table, "sent_cts_cnt:",
  1038. le32_to_cpu(cck->sent_cts_cnt),
  1039. accum_cck->sent_cts_cnt, delta_cck->sent_cts_cnt,
  1040. max_cck->sent_cts_cnt);
  1041. pos += scnprintf(buf + pos, bufsz - pos,
  1042. fmt_table, "sent_ba_rsp_cnt:",
  1043. le32_to_cpu(cck->sent_ba_rsp_cnt),
  1044. accum_cck->sent_ba_rsp_cnt,
  1045. delta_cck->sent_ba_rsp_cnt,
  1046. max_cck->sent_ba_rsp_cnt);
  1047. pos += scnprintf(buf + pos, bufsz - pos,
  1048. fmt_table, "dsp_self_kill:",
  1049. le32_to_cpu(cck->dsp_self_kill),
  1050. accum_cck->dsp_self_kill, delta_cck->dsp_self_kill,
  1051. max_cck->dsp_self_kill);
  1052. pos += scnprintf(buf + pos, bufsz - pos,
  1053. fmt_table, "mh_format_err:",
  1054. le32_to_cpu(cck->mh_format_err),
  1055. accum_cck->mh_format_err, delta_cck->mh_format_err,
  1056. max_cck->mh_format_err);
  1057. pos += scnprintf(buf + pos, bufsz - pos,
  1058. fmt_table, "re_acq_main_rssi_sum:",
  1059. le32_to_cpu(cck->re_acq_main_rssi_sum),
  1060. accum_cck->re_acq_main_rssi_sum,
  1061. delta_cck->re_acq_main_rssi_sum,
  1062. max_cck->re_acq_main_rssi_sum);
  1063. pos += scnprintf(buf + pos, bufsz - pos,
  1064. fmt_header, "Statistics_Rx - GENERAL:");
  1065. pos += scnprintf(buf + pos, bufsz - pos,
  1066. fmt_table, "bogus_cts:",
  1067. le32_to_cpu(general->bogus_cts),
  1068. accum_general->bogus_cts, delta_general->bogus_cts,
  1069. max_general->bogus_cts);
  1070. pos += scnprintf(buf + pos, bufsz - pos,
  1071. fmt_table, "bogus_ack:",
  1072. le32_to_cpu(general->bogus_ack),
  1073. accum_general->bogus_ack, delta_general->bogus_ack,
  1074. max_general->bogus_ack);
  1075. pos += scnprintf(buf + pos, bufsz - pos,
  1076. fmt_table, "non_bssid_frames:",
  1077. le32_to_cpu(general->non_bssid_frames),
  1078. accum_general->non_bssid_frames,
  1079. delta_general->non_bssid_frames,
  1080. max_general->non_bssid_frames);
  1081. pos += scnprintf(buf + pos, bufsz - pos,
  1082. fmt_table, "filtered_frames:",
  1083. le32_to_cpu(general->filtered_frames),
  1084. accum_general->filtered_frames,
  1085. delta_general->filtered_frames,
  1086. max_general->filtered_frames);
  1087. pos += scnprintf(buf + pos, bufsz - pos,
  1088. fmt_table, "non_channel_beacons:",
  1089. le32_to_cpu(general->non_channel_beacons),
  1090. accum_general->non_channel_beacons,
  1091. delta_general->non_channel_beacons,
  1092. max_general->non_channel_beacons);
  1093. pos += scnprintf(buf + pos, bufsz - pos,
  1094. fmt_table, "channel_beacons:",
  1095. le32_to_cpu(general->channel_beacons),
  1096. accum_general->channel_beacons,
  1097. delta_general->channel_beacons,
  1098. max_general->channel_beacons);
  1099. pos += scnprintf(buf + pos, bufsz - pos,
  1100. fmt_table, "num_missed_bcon:",
  1101. le32_to_cpu(general->num_missed_bcon),
  1102. accum_general->num_missed_bcon,
  1103. delta_general->num_missed_bcon,
  1104. max_general->num_missed_bcon);
  1105. pos += scnprintf(buf + pos, bufsz - pos,
  1106. fmt_table, "adc_rx_saturation_time:",
  1107. le32_to_cpu(general->adc_rx_saturation_time),
  1108. accum_general->adc_rx_saturation_time,
  1109. delta_general->adc_rx_saturation_time,
  1110. max_general->adc_rx_saturation_time);
  1111. pos += scnprintf(buf + pos, bufsz - pos,
  1112. fmt_table, "ina_detect_search_tm:",
  1113. le32_to_cpu(general->ina_detection_search_time),
  1114. accum_general->ina_detection_search_time,
  1115. delta_general->ina_detection_search_time,
  1116. max_general->ina_detection_search_time);
  1117. pos += scnprintf(buf + pos, bufsz - pos,
  1118. fmt_table, "beacon_silence_rssi_a:",
  1119. le32_to_cpu(general->beacon_silence_rssi_a),
  1120. accum_general->beacon_silence_rssi_a,
  1121. delta_general->beacon_silence_rssi_a,
  1122. max_general->beacon_silence_rssi_a);
  1123. pos += scnprintf(buf + pos, bufsz - pos,
  1124. fmt_table, "beacon_silence_rssi_b:",
  1125. le32_to_cpu(general->beacon_silence_rssi_b),
  1126. accum_general->beacon_silence_rssi_b,
  1127. delta_general->beacon_silence_rssi_b,
  1128. max_general->beacon_silence_rssi_b);
  1129. pos += scnprintf(buf + pos, bufsz - pos,
  1130. fmt_table, "beacon_silence_rssi_c:",
  1131. le32_to_cpu(general->beacon_silence_rssi_c),
  1132. accum_general->beacon_silence_rssi_c,
  1133. delta_general->beacon_silence_rssi_c,
  1134. max_general->beacon_silence_rssi_c);
  1135. pos += scnprintf(buf + pos, bufsz - pos,
  1136. fmt_table, "interference_data_flag:",
  1137. le32_to_cpu(general->interference_data_flag),
  1138. accum_general->interference_data_flag,
  1139. delta_general->interference_data_flag,
  1140. max_general->interference_data_flag);
  1141. pos += scnprintf(buf + pos, bufsz - pos,
  1142. fmt_table, "channel_load:",
  1143. le32_to_cpu(general->channel_load),
  1144. accum_general->channel_load,
  1145. delta_general->channel_load,
  1146. max_general->channel_load);
  1147. pos += scnprintf(buf + pos, bufsz - pos,
  1148. fmt_table, "dsp_false_alarms:",
  1149. le32_to_cpu(general->dsp_false_alarms),
  1150. accum_general->dsp_false_alarms,
  1151. delta_general->dsp_false_alarms,
  1152. max_general->dsp_false_alarms);
  1153. pos += scnprintf(buf + pos, bufsz - pos,
  1154. fmt_table, "beacon_rssi_a:",
  1155. le32_to_cpu(general->beacon_rssi_a),
  1156. accum_general->beacon_rssi_a,
  1157. delta_general->beacon_rssi_a,
  1158. max_general->beacon_rssi_a);
  1159. pos += scnprintf(buf + pos, bufsz - pos,
  1160. fmt_table, "beacon_rssi_b:",
  1161. le32_to_cpu(general->beacon_rssi_b),
  1162. accum_general->beacon_rssi_b,
  1163. delta_general->beacon_rssi_b,
  1164. max_general->beacon_rssi_b);
  1165. pos += scnprintf(buf + pos, bufsz - pos,
  1166. fmt_table, "beacon_rssi_c:",
  1167. le32_to_cpu(general->beacon_rssi_c),
  1168. accum_general->beacon_rssi_c,
  1169. delta_general->beacon_rssi_c,
  1170. max_general->beacon_rssi_c);
  1171. pos += scnprintf(buf + pos, bufsz - pos,
  1172. fmt_table, "beacon_energy_a:",
  1173. le32_to_cpu(general->beacon_energy_a),
  1174. accum_general->beacon_energy_a,
  1175. delta_general->beacon_energy_a,
  1176. max_general->beacon_energy_a);
  1177. pos += scnprintf(buf + pos, bufsz - pos,
  1178. fmt_table, "beacon_energy_b:",
  1179. le32_to_cpu(general->beacon_energy_b),
  1180. accum_general->beacon_energy_b,
  1181. delta_general->beacon_energy_b,
  1182. max_general->beacon_energy_b);
  1183. pos += scnprintf(buf + pos, bufsz - pos,
  1184. fmt_table, "beacon_energy_c:",
  1185. le32_to_cpu(general->beacon_energy_c),
  1186. accum_general->beacon_energy_c,
  1187. delta_general->beacon_energy_c,
  1188. max_general->beacon_energy_c);
  1189. pos += scnprintf(buf + pos, bufsz - pos,
  1190. fmt_header, "Statistics_Rx - OFDM_HT:");
  1191. pos += scnprintf(buf + pos, bufsz - pos,
  1192. fmt_table, "plcp_err:",
  1193. le32_to_cpu(ht->plcp_err), accum_ht->plcp_err,
  1194. delta_ht->plcp_err, max_ht->plcp_err);
  1195. pos += scnprintf(buf + pos, bufsz - pos,
  1196. fmt_table, "overrun_err:",
  1197. le32_to_cpu(ht->overrun_err), accum_ht->overrun_err,
  1198. delta_ht->overrun_err, max_ht->overrun_err);
  1199. pos += scnprintf(buf + pos, bufsz - pos,
  1200. fmt_table, "early_overrun_err:",
  1201. le32_to_cpu(ht->early_overrun_err),
  1202. accum_ht->early_overrun_err,
  1203. delta_ht->early_overrun_err,
  1204. max_ht->early_overrun_err);
  1205. pos += scnprintf(buf + pos, bufsz - pos,
  1206. fmt_table, "crc32_good:",
  1207. le32_to_cpu(ht->crc32_good), accum_ht->crc32_good,
  1208. delta_ht->crc32_good, max_ht->crc32_good);
  1209. pos += scnprintf(buf + pos, bufsz - pos,
  1210. fmt_table, "crc32_err:",
  1211. le32_to_cpu(ht->crc32_err), accum_ht->crc32_err,
  1212. delta_ht->crc32_err, max_ht->crc32_err);
  1213. pos += scnprintf(buf + pos, bufsz - pos,
  1214. fmt_table, "mh_format_err:",
  1215. le32_to_cpu(ht->mh_format_err),
  1216. accum_ht->mh_format_err,
  1217. delta_ht->mh_format_err, max_ht->mh_format_err);
  1218. pos += scnprintf(buf + pos, bufsz - pos,
  1219. fmt_table, "agg_crc32_good:",
  1220. le32_to_cpu(ht->agg_crc32_good),
  1221. accum_ht->agg_crc32_good,
  1222. delta_ht->agg_crc32_good, max_ht->agg_crc32_good);
  1223. pos += scnprintf(buf + pos, bufsz - pos,
  1224. fmt_table, "agg_mpdu_cnt:",
  1225. le32_to_cpu(ht->agg_mpdu_cnt),
  1226. accum_ht->agg_mpdu_cnt,
  1227. delta_ht->agg_mpdu_cnt, max_ht->agg_mpdu_cnt);
  1228. pos += scnprintf(buf + pos, bufsz - pos,
  1229. fmt_table, "agg_cnt:",
  1230. le32_to_cpu(ht->agg_cnt), accum_ht->agg_cnt,
  1231. delta_ht->agg_cnt, max_ht->agg_cnt);
  1232. pos += scnprintf(buf + pos, bufsz - pos,
  1233. fmt_table, "unsupport_mcs:",
  1234. le32_to_cpu(ht->unsupport_mcs),
  1235. accum_ht->unsupport_mcs,
  1236. delta_ht->unsupport_mcs, max_ht->unsupport_mcs);
  1237. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  1238. kfree(buf);
  1239. return ret;
  1240. }
  1241. static ssize_t iwl_dbgfs_ucode_tx_stats_read(struct file *file,
  1242. char __user *user_buf,
  1243. size_t count, loff_t *ppos)
  1244. {
  1245. struct iwl_priv *priv = file->private_data;
  1246. int pos = 0;
  1247. char *buf;
  1248. int bufsz = (sizeof(struct statistics_tx) * 48) + 250;
  1249. ssize_t ret;
  1250. struct statistics_tx *tx, *accum_tx, *delta_tx, *max_tx;
  1251. if (!iwl_is_alive(priv->shrd))
  1252. return -EAGAIN;
  1253. buf = kzalloc(bufsz, GFP_KERNEL);
  1254. if (!buf) {
  1255. IWL_ERR(priv, "Can not allocate Buffer\n");
  1256. return -ENOMEM;
  1257. }
  1258. /* the statistic information display here is based on
  1259. * the last statistics notification from uCode
  1260. * might not reflect the current uCode activity
  1261. */
  1262. tx = &priv->statistics.tx;
  1263. accum_tx = &priv->accum_stats.tx;
  1264. delta_tx = &priv->delta_stats.tx;
  1265. max_tx = &priv->max_delta_stats.tx;
  1266. pos += iwl_statistics_flag(priv, buf, bufsz);
  1267. pos += scnprintf(buf + pos, bufsz - pos,
  1268. fmt_header, "Statistics_Tx:");
  1269. pos += scnprintf(buf + pos, bufsz - pos,
  1270. fmt_table, "preamble:",
  1271. le32_to_cpu(tx->preamble_cnt),
  1272. accum_tx->preamble_cnt,
  1273. delta_tx->preamble_cnt, max_tx->preamble_cnt);
  1274. pos += scnprintf(buf + pos, bufsz - pos,
  1275. fmt_table, "rx_detected_cnt:",
  1276. le32_to_cpu(tx->rx_detected_cnt),
  1277. accum_tx->rx_detected_cnt,
  1278. delta_tx->rx_detected_cnt, max_tx->rx_detected_cnt);
  1279. pos += scnprintf(buf + pos, bufsz - pos,
  1280. fmt_table, "bt_prio_defer_cnt:",
  1281. le32_to_cpu(tx->bt_prio_defer_cnt),
  1282. accum_tx->bt_prio_defer_cnt,
  1283. delta_tx->bt_prio_defer_cnt,
  1284. max_tx->bt_prio_defer_cnt);
  1285. pos += scnprintf(buf + pos, bufsz - pos,
  1286. fmt_table, "bt_prio_kill_cnt:",
  1287. le32_to_cpu(tx->bt_prio_kill_cnt),
  1288. accum_tx->bt_prio_kill_cnt,
  1289. delta_tx->bt_prio_kill_cnt,
  1290. max_tx->bt_prio_kill_cnt);
  1291. pos += scnprintf(buf + pos, bufsz - pos,
  1292. fmt_table, "few_bytes_cnt:",
  1293. le32_to_cpu(tx->few_bytes_cnt),
  1294. accum_tx->few_bytes_cnt,
  1295. delta_tx->few_bytes_cnt, max_tx->few_bytes_cnt);
  1296. pos += scnprintf(buf + pos, bufsz - pos,
  1297. fmt_table, "cts_timeout:",
  1298. le32_to_cpu(tx->cts_timeout), accum_tx->cts_timeout,
  1299. delta_tx->cts_timeout, max_tx->cts_timeout);
  1300. pos += scnprintf(buf + pos, bufsz - pos,
  1301. fmt_table, "ack_timeout:",
  1302. le32_to_cpu(tx->ack_timeout),
  1303. accum_tx->ack_timeout,
  1304. delta_tx->ack_timeout, max_tx->ack_timeout);
  1305. pos += scnprintf(buf + pos, bufsz - pos,
  1306. fmt_table, "expected_ack_cnt:",
  1307. le32_to_cpu(tx->expected_ack_cnt),
  1308. accum_tx->expected_ack_cnt,
  1309. delta_tx->expected_ack_cnt,
  1310. max_tx->expected_ack_cnt);
  1311. pos += scnprintf(buf + pos, bufsz - pos,
  1312. fmt_table, "actual_ack_cnt:",
  1313. le32_to_cpu(tx->actual_ack_cnt),
  1314. accum_tx->actual_ack_cnt,
  1315. delta_tx->actual_ack_cnt,
  1316. max_tx->actual_ack_cnt);
  1317. pos += scnprintf(buf + pos, bufsz - pos,
  1318. fmt_table, "dump_msdu_cnt:",
  1319. le32_to_cpu(tx->dump_msdu_cnt),
  1320. accum_tx->dump_msdu_cnt,
  1321. delta_tx->dump_msdu_cnt,
  1322. max_tx->dump_msdu_cnt);
  1323. pos += scnprintf(buf + pos, bufsz - pos,
  1324. fmt_table, "abort_nxt_frame_mismatch:",
  1325. le32_to_cpu(tx->burst_abort_next_frame_mismatch_cnt),
  1326. accum_tx->burst_abort_next_frame_mismatch_cnt,
  1327. delta_tx->burst_abort_next_frame_mismatch_cnt,
  1328. max_tx->burst_abort_next_frame_mismatch_cnt);
  1329. pos += scnprintf(buf + pos, bufsz - pos,
  1330. fmt_table, "abort_missing_nxt_frame:",
  1331. le32_to_cpu(tx->burst_abort_missing_next_frame_cnt),
  1332. accum_tx->burst_abort_missing_next_frame_cnt,
  1333. delta_tx->burst_abort_missing_next_frame_cnt,
  1334. max_tx->burst_abort_missing_next_frame_cnt);
  1335. pos += scnprintf(buf + pos, bufsz - pos,
  1336. fmt_table, "cts_timeout_collision:",
  1337. le32_to_cpu(tx->cts_timeout_collision),
  1338. accum_tx->cts_timeout_collision,
  1339. delta_tx->cts_timeout_collision,
  1340. max_tx->cts_timeout_collision);
  1341. pos += scnprintf(buf + pos, bufsz - pos,
  1342. fmt_table, "ack_ba_timeout_collision:",
  1343. le32_to_cpu(tx->ack_or_ba_timeout_collision),
  1344. accum_tx->ack_or_ba_timeout_collision,
  1345. delta_tx->ack_or_ba_timeout_collision,
  1346. max_tx->ack_or_ba_timeout_collision);
  1347. pos += scnprintf(buf + pos, bufsz - pos,
  1348. fmt_table, "agg ba_timeout:",
  1349. le32_to_cpu(tx->agg.ba_timeout),
  1350. accum_tx->agg.ba_timeout,
  1351. delta_tx->agg.ba_timeout,
  1352. max_tx->agg.ba_timeout);
  1353. pos += scnprintf(buf + pos, bufsz - pos,
  1354. fmt_table, "agg ba_resched_frames:",
  1355. le32_to_cpu(tx->agg.ba_reschedule_frames),
  1356. accum_tx->agg.ba_reschedule_frames,
  1357. delta_tx->agg.ba_reschedule_frames,
  1358. max_tx->agg.ba_reschedule_frames);
  1359. pos += scnprintf(buf + pos, bufsz - pos,
  1360. fmt_table, "agg scd_query_agg_frame:",
  1361. le32_to_cpu(tx->agg.scd_query_agg_frame_cnt),
  1362. accum_tx->agg.scd_query_agg_frame_cnt,
  1363. delta_tx->agg.scd_query_agg_frame_cnt,
  1364. max_tx->agg.scd_query_agg_frame_cnt);
  1365. pos += scnprintf(buf + pos, bufsz - pos,
  1366. fmt_table, "agg scd_query_no_agg:",
  1367. le32_to_cpu(tx->agg.scd_query_no_agg),
  1368. accum_tx->agg.scd_query_no_agg,
  1369. delta_tx->agg.scd_query_no_agg,
  1370. max_tx->agg.scd_query_no_agg);
  1371. pos += scnprintf(buf + pos, bufsz - pos,
  1372. fmt_table, "agg scd_query_agg:",
  1373. le32_to_cpu(tx->agg.scd_query_agg),
  1374. accum_tx->agg.scd_query_agg,
  1375. delta_tx->agg.scd_query_agg,
  1376. max_tx->agg.scd_query_agg);
  1377. pos += scnprintf(buf + pos, bufsz - pos,
  1378. fmt_table, "agg scd_query_mismatch:",
  1379. le32_to_cpu(tx->agg.scd_query_mismatch),
  1380. accum_tx->agg.scd_query_mismatch,
  1381. delta_tx->agg.scd_query_mismatch,
  1382. max_tx->agg.scd_query_mismatch);
  1383. pos += scnprintf(buf + pos, bufsz - pos,
  1384. fmt_table, "agg frame_not_ready:",
  1385. le32_to_cpu(tx->agg.frame_not_ready),
  1386. accum_tx->agg.frame_not_ready,
  1387. delta_tx->agg.frame_not_ready,
  1388. max_tx->agg.frame_not_ready);
  1389. pos += scnprintf(buf + pos, bufsz - pos,
  1390. fmt_table, "agg underrun:",
  1391. le32_to_cpu(tx->agg.underrun),
  1392. accum_tx->agg.underrun,
  1393. delta_tx->agg.underrun, max_tx->agg.underrun);
  1394. pos += scnprintf(buf + pos, bufsz - pos,
  1395. fmt_table, "agg bt_prio_kill:",
  1396. le32_to_cpu(tx->agg.bt_prio_kill),
  1397. accum_tx->agg.bt_prio_kill,
  1398. delta_tx->agg.bt_prio_kill,
  1399. max_tx->agg.bt_prio_kill);
  1400. pos += scnprintf(buf + pos, bufsz - pos,
  1401. fmt_table, "agg rx_ba_rsp_cnt:",
  1402. le32_to_cpu(tx->agg.rx_ba_rsp_cnt),
  1403. accum_tx->agg.rx_ba_rsp_cnt,
  1404. delta_tx->agg.rx_ba_rsp_cnt,
  1405. max_tx->agg.rx_ba_rsp_cnt);
  1406. if (tx->tx_power.ant_a || tx->tx_power.ant_b || tx->tx_power.ant_c) {
  1407. pos += scnprintf(buf + pos, bufsz - pos,
  1408. "tx power: (1/2 dB step)\n");
  1409. if ((cfg(priv)->valid_tx_ant & ANT_A) && tx->tx_power.ant_a)
  1410. pos += scnprintf(buf + pos, bufsz - pos,
  1411. fmt_hex, "antenna A:",
  1412. tx->tx_power.ant_a);
  1413. if ((cfg(priv)->valid_tx_ant & ANT_B) && tx->tx_power.ant_b)
  1414. pos += scnprintf(buf + pos, bufsz - pos,
  1415. fmt_hex, "antenna B:",
  1416. tx->tx_power.ant_b);
  1417. if ((cfg(priv)->valid_tx_ant & ANT_C) && tx->tx_power.ant_c)
  1418. pos += scnprintf(buf + pos, bufsz - pos,
  1419. fmt_hex, "antenna C:",
  1420. tx->tx_power.ant_c);
  1421. }
  1422. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  1423. kfree(buf);
  1424. return ret;
  1425. }
  1426. static ssize_t iwl_dbgfs_ucode_general_stats_read(struct file *file,
  1427. char __user *user_buf,
  1428. size_t count, loff_t *ppos)
  1429. {
  1430. struct iwl_priv *priv = file->private_data;
  1431. int pos = 0;
  1432. char *buf;
  1433. int bufsz = sizeof(struct statistics_general) * 10 + 300;
  1434. ssize_t ret;
  1435. struct statistics_general_common *general, *accum_general;
  1436. struct statistics_general_common *delta_general, *max_general;
  1437. struct statistics_dbg *dbg, *accum_dbg, *delta_dbg, *max_dbg;
  1438. struct statistics_div *div, *accum_div, *delta_div, *max_div;
  1439. if (!iwl_is_alive(priv->shrd))
  1440. return -EAGAIN;
  1441. buf = kzalloc(bufsz, GFP_KERNEL);
  1442. if (!buf) {
  1443. IWL_ERR(priv, "Can not allocate Buffer\n");
  1444. return -ENOMEM;
  1445. }
  1446. /* the statistic information display here is based on
  1447. * the last statistics notification from uCode
  1448. * might not reflect the current uCode activity
  1449. */
  1450. general = &priv->statistics.common;
  1451. dbg = &priv->statistics.common.dbg;
  1452. div = &priv->statistics.common.div;
  1453. accum_general = &priv->accum_stats.common;
  1454. accum_dbg = &priv->accum_stats.common.dbg;
  1455. accum_div = &priv->accum_stats.common.div;
  1456. delta_general = &priv->delta_stats.common;
  1457. max_general = &priv->max_delta_stats.common;
  1458. delta_dbg = &priv->delta_stats.common.dbg;
  1459. max_dbg = &priv->max_delta_stats.common.dbg;
  1460. delta_div = &priv->delta_stats.common.div;
  1461. max_div = &priv->max_delta_stats.common.div;
  1462. pos += iwl_statistics_flag(priv, buf, bufsz);
  1463. pos += scnprintf(buf + pos, bufsz - pos,
  1464. fmt_header, "Statistics_General:");
  1465. pos += scnprintf(buf + pos, bufsz - pos,
  1466. fmt_value, "temperature:",
  1467. le32_to_cpu(general->temperature));
  1468. pos += scnprintf(buf + pos, bufsz - pos,
  1469. fmt_value, "temperature_m:",
  1470. le32_to_cpu(general->temperature_m));
  1471. pos += scnprintf(buf + pos, bufsz - pos,
  1472. fmt_value, "ttl_timestamp:",
  1473. le32_to_cpu(general->ttl_timestamp));
  1474. pos += scnprintf(buf + pos, bufsz - pos,
  1475. fmt_table, "burst_check:",
  1476. le32_to_cpu(dbg->burst_check),
  1477. accum_dbg->burst_check,
  1478. delta_dbg->burst_check, max_dbg->burst_check);
  1479. pos += scnprintf(buf + pos, bufsz - pos,
  1480. fmt_table, "burst_count:",
  1481. le32_to_cpu(dbg->burst_count),
  1482. accum_dbg->burst_count,
  1483. delta_dbg->burst_count, max_dbg->burst_count);
  1484. pos += scnprintf(buf + pos, bufsz - pos,
  1485. fmt_table, "wait_for_silence_timeout_count:",
  1486. le32_to_cpu(dbg->wait_for_silence_timeout_cnt),
  1487. accum_dbg->wait_for_silence_timeout_cnt,
  1488. delta_dbg->wait_for_silence_timeout_cnt,
  1489. max_dbg->wait_for_silence_timeout_cnt);
  1490. pos += scnprintf(buf + pos, bufsz - pos,
  1491. fmt_table, "sleep_time:",
  1492. le32_to_cpu(general->sleep_time),
  1493. accum_general->sleep_time,
  1494. delta_general->sleep_time, max_general->sleep_time);
  1495. pos += scnprintf(buf + pos, bufsz - pos,
  1496. fmt_table, "slots_out:",
  1497. le32_to_cpu(general->slots_out),
  1498. accum_general->slots_out,
  1499. delta_general->slots_out, max_general->slots_out);
  1500. pos += scnprintf(buf + pos, bufsz - pos,
  1501. fmt_table, "slots_idle:",
  1502. le32_to_cpu(general->slots_idle),
  1503. accum_general->slots_idle,
  1504. delta_general->slots_idle, max_general->slots_idle);
  1505. pos += scnprintf(buf + pos, bufsz - pos,
  1506. fmt_table, "tx_on_a:",
  1507. le32_to_cpu(div->tx_on_a), accum_div->tx_on_a,
  1508. delta_div->tx_on_a, max_div->tx_on_a);
  1509. pos += scnprintf(buf + pos, bufsz - pos,
  1510. fmt_table, "tx_on_b:",
  1511. le32_to_cpu(div->tx_on_b), accum_div->tx_on_b,
  1512. delta_div->tx_on_b, max_div->tx_on_b);
  1513. pos += scnprintf(buf + pos, bufsz - pos,
  1514. fmt_table, "exec_time:",
  1515. le32_to_cpu(div->exec_time), accum_div->exec_time,
  1516. delta_div->exec_time, max_div->exec_time);
  1517. pos += scnprintf(buf + pos, bufsz - pos,
  1518. fmt_table, "probe_time:",
  1519. le32_to_cpu(div->probe_time), accum_div->probe_time,
  1520. delta_div->probe_time, max_div->probe_time);
  1521. pos += scnprintf(buf + pos, bufsz - pos,
  1522. fmt_table, "rx_enable_counter:",
  1523. le32_to_cpu(general->rx_enable_counter),
  1524. accum_general->rx_enable_counter,
  1525. delta_general->rx_enable_counter,
  1526. max_general->rx_enable_counter);
  1527. pos += scnprintf(buf + pos, bufsz - pos,
  1528. fmt_table, "num_of_sos_states:",
  1529. le32_to_cpu(general->num_of_sos_states),
  1530. accum_general->num_of_sos_states,
  1531. delta_general->num_of_sos_states,
  1532. max_general->num_of_sos_states);
  1533. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  1534. kfree(buf);
  1535. return ret;
  1536. }
  1537. static ssize_t iwl_dbgfs_ucode_bt_stats_read(struct file *file,
  1538. char __user *user_buf,
  1539. size_t count, loff_t *ppos)
  1540. {
  1541. struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
  1542. int pos = 0;
  1543. char *buf;
  1544. int bufsz = (sizeof(struct statistics_bt_activity) * 24) + 200;
  1545. ssize_t ret;
  1546. struct statistics_bt_activity *bt, *accum_bt;
  1547. if (!iwl_is_alive(priv->shrd))
  1548. return -EAGAIN;
  1549. if (!priv->bt_enable_flag)
  1550. return -EINVAL;
  1551. /* make request to uCode to retrieve statistics information */
  1552. mutex_lock(&priv->shrd->mutex);
  1553. ret = iwl_send_statistics_request(priv, CMD_SYNC, false);
  1554. mutex_unlock(&priv->shrd->mutex);
  1555. if (ret) {
  1556. IWL_ERR(priv,
  1557. "Error sending statistics request: %zd\n", ret);
  1558. return -EAGAIN;
  1559. }
  1560. buf = kzalloc(bufsz, GFP_KERNEL);
  1561. if (!buf) {
  1562. IWL_ERR(priv, "Can not allocate Buffer\n");
  1563. return -ENOMEM;
  1564. }
  1565. /*
  1566. * the statistic information display here is based on
  1567. * the last statistics notification from uCode
  1568. * might not reflect the current uCode activity
  1569. */
  1570. bt = &priv->statistics.bt_activity;
  1571. accum_bt = &priv->accum_stats.bt_activity;
  1572. pos += iwl_statistics_flag(priv, buf, bufsz);
  1573. pos += scnprintf(buf + pos, bufsz - pos, "Statistics_BT:\n");
  1574. pos += scnprintf(buf + pos, bufsz - pos,
  1575. "\t\t\tcurrent\t\t\taccumulative\n");
  1576. pos += scnprintf(buf + pos, bufsz - pos,
  1577. "hi_priority_tx_req_cnt:\t\t%u\t\t\t%u\n",
  1578. le32_to_cpu(bt->hi_priority_tx_req_cnt),
  1579. accum_bt->hi_priority_tx_req_cnt);
  1580. pos += scnprintf(buf + pos, bufsz - pos,
  1581. "hi_priority_tx_denied_cnt:\t%u\t\t\t%u\n",
  1582. le32_to_cpu(bt->hi_priority_tx_denied_cnt),
  1583. accum_bt->hi_priority_tx_denied_cnt);
  1584. pos += scnprintf(buf + pos, bufsz - pos,
  1585. "lo_priority_tx_req_cnt:\t\t%u\t\t\t%u\n",
  1586. le32_to_cpu(bt->lo_priority_tx_req_cnt),
  1587. accum_bt->lo_priority_tx_req_cnt);
  1588. pos += scnprintf(buf + pos, bufsz - pos,
  1589. "lo_priority_tx_denied_cnt:\t%u\t\t\t%u\n",
  1590. le32_to_cpu(bt->lo_priority_tx_denied_cnt),
  1591. accum_bt->lo_priority_tx_denied_cnt);
  1592. pos += scnprintf(buf + pos, bufsz - pos,
  1593. "hi_priority_rx_req_cnt:\t\t%u\t\t\t%u\n",
  1594. le32_to_cpu(bt->hi_priority_rx_req_cnt),
  1595. accum_bt->hi_priority_rx_req_cnt);
  1596. pos += scnprintf(buf + pos, bufsz - pos,
  1597. "hi_priority_rx_denied_cnt:\t%u\t\t\t%u\n",
  1598. le32_to_cpu(bt->hi_priority_rx_denied_cnt),
  1599. accum_bt->hi_priority_rx_denied_cnt);
  1600. pos += scnprintf(buf + pos, bufsz - pos,
  1601. "lo_priority_rx_req_cnt:\t\t%u\t\t\t%u\n",
  1602. le32_to_cpu(bt->lo_priority_rx_req_cnt),
  1603. accum_bt->lo_priority_rx_req_cnt);
  1604. pos += scnprintf(buf + pos, bufsz - pos,
  1605. "lo_priority_rx_denied_cnt:\t%u\t\t\t%u\n",
  1606. le32_to_cpu(bt->lo_priority_rx_denied_cnt),
  1607. accum_bt->lo_priority_rx_denied_cnt);
  1608. pos += scnprintf(buf + pos, bufsz - pos,
  1609. "(rx)num_bt_kills:\t\t%u\t\t\t%u\n",
  1610. le32_to_cpu(priv->statistics.num_bt_kills),
  1611. priv->statistics.accum_num_bt_kills);
  1612. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  1613. kfree(buf);
  1614. return ret;
  1615. }
  1616. static ssize_t iwl_dbgfs_reply_tx_error_read(struct file *file,
  1617. char __user *user_buf,
  1618. size_t count, loff_t *ppos)
  1619. {
  1620. struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
  1621. int pos = 0;
  1622. char *buf;
  1623. int bufsz = (sizeof(struct reply_tx_error_statistics) * 24) +
  1624. (sizeof(struct reply_agg_tx_error_statistics) * 24) + 200;
  1625. ssize_t ret;
  1626. if (!iwl_is_alive(priv->shrd))
  1627. return -EAGAIN;
  1628. buf = kzalloc(bufsz, GFP_KERNEL);
  1629. if (!buf) {
  1630. IWL_ERR(priv, "Can not allocate Buffer\n");
  1631. return -ENOMEM;
  1632. }
  1633. pos += scnprintf(buf + pos, bufsz - pos, "Statistics_TX_Error:\n");
  1634. pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t\t%u\n",
  1635. iwl_get_tx_fail_reason(TX_STATUS_POSTPONE_DELAY),
  1636. priv->reply_tx_stats.pp_delay);
  1637. pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
  1638. iwl_get_tx_fail_reason(TX_STATUS_POSTPONE_FEW_BYTES),
  1639. priv->reply_tx_stats.pp_few_bytes);
  1640. pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
  1641. iwl_get_tx_fail_reason(TX_STATUS_POSTPONE_BT_PRIO),
  1642. priv->reply_tx_stats.pp_bt_prio);
  1643. pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
  1644. iwl_get_tx_fail_reason(TX_STATUS_POSTPONE_QUIET_PERIOD),
  1645. priv->reply_tx_stats.pp_quiet_period);
  1646. pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
  1647. iwl_get_tx_fail_reason(TX_STATUS_POSTPONE_CALC_TTAK),
  1648. priv->reply_tx_stats.pp_calc_ttak);
  1649. pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t%u\n",
  1650. iwl_get_tx_fail_reason(
  1651. TX_STATUS_FAIL_INTERNAL_CROSSED_RETRY),
  1652. priv->reply_tx_stats.int_crossed_retry);
  1653. pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
  1654. iwl_get_tx_fail_reason(TX_STATUS_FAIL_SHORT_LIMIT),
  1655. priv->reply_tx_stats.short_limit);
  1656. pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
  1657. iwl_get_tx_fail_reason(TX_STATUS_FAIL_LONG_LIMIT),
  1658. priv->reply_tx_stats.long_limit);
  1659. pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
  1660. iwl_get_tx_fail_reason(TX_STATUS_FAIL_FIFO_UNDERRUN),
  1661. priv->reply_tx_stats.fifo_underrun);
  1662. pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
  1663. iwl_get_tx_fail_reason(TX_STATUS_FAIL_DRAIN_FLOW),
  1664. priv->reply_tx_stats.drain_flow);
  1665. pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
  1666. iwl_get_tx_fail_reason(TX_STATUS_FAIL_RFKILL_FLUSH),
  1667. priv->reply_tx_stats.rfkill_flush);
  1668. pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
  1669. iwl_get_tx_fail_reason(TX_STATUS_FAIL_LIFE_EXPIRE),
  1670. priv->reply_tx_stats.life_expire);
  1671. pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
  1672. iwl_get_tx_fail_reason(TX_STATUS_FAIL_DEST_PS),
  1673. priv->reply_tx_stats.dest_ps);
  1674. pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
  1675. iwl_get_tx_fail_reason(TX_STATUS_FAIL_HOST_ABORTED),
  1676. priv->reply_tx_stats.host_abort);
  1677. pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
  1678. iwl_get_tx_fail_reason(TX_STATUS_FAIL_BT_RETRY),
  1679. priv->reply_tx_stats.pp_delay);
  1680. pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
  1681. iwl_get_tx_fail_reason(TX_STATUS_FAIL_STA_INVALID),
  1682. priv->reply_tx_stats.sta_invalid);
  1683. pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
  1684. iwl_get_tx_fail_reason(TX_STATUS_FAIL_FRAG_DROPPED),
  1685. priv->reply_tx_stats.frag_drop);
  1686. pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
  1687. iwl_get_tx_fail_reason(TX_STATUS_FAIL_TID_DISABLE),
  1688. priv->reply_tx_stats.tid_disable);
  1689. pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
  1690. iwl_get_tx_fail_reason(TX_STATUS_FAIL_FIFO_FLUSHED),
  1691. priv->reply_tx_stats.fifo_flush);
  1692. pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t%u\n",
  1693. iwl_get_tx_fail_reason(
  1694. TX_STATUS_FAIL_INSUFFICIENT_CF_POLL),
  1695. priv->reply_tx_stats.insuff_cf_poll);
  1696. pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
  1697. iwl_get_tx_fail_reason(TX_STATUS_FAIL_PASSIVE_NO_RX),
  1698. priv->reply_tx_stats.fail_hw_drop);
  1699. pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t%u\n",
  1700. iwl_get_tx_fail_reason(
  1701. TX_STATUS_FAIL_NO_BEACON_ON_RADAR),
  1702. priv->reply_tx_stats.sta_color_mismatch);
  1703. pos += scnprintf(buf + pos, bufsz - pos, "UNKNOWN:\t\t\t%u\n",
  1704. priv->reply_tx_stats.unknown);
  1705. pos += scnprintf(buf + pos, bufsz - pos,
  1706. "\nStatistics_Agg_TX_Error:\n");
  1707. pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
  1708. iwl_get_agg_tx_fail_reason(AGG_TX_STATE_UNDERRUN_MSK),
  1709. priv->reply_agg_tx_stats.underrun);
  1710. pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
  1711. iwl_get_agg_tx_fail_reason(AGG_TX_STATE_BT_PRIO_MSK),
  1712. priv->reply_agg_tx_stats.bt_prio);
  1713. pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
  1714. iwl_get_agg_tx_fail_reason(AGG_TX_STATE_FEW_BYTES_MSK),
  1715. priv->reply_agg_tx_stats.few_bytes);
  1716. pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
  1717. iwl_get_agg_tx_fail_reason(AGG_TX_STATE_ABORT_MSK),
  1718. priv->reply_agg_tx_stats.abort);
  1719. pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t%u\n",
  1720. iwl_get_agg_tx_fail_reason(
  1721. AGG_TX_STATE_LAST_SENT_TTL_MSK),
  1722. priv->reply_agg_tx_stats.last_sent_ttl);
  1723. pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t%u\n",
  1724. iwl_get_agg_tx_fail_reason(
  1725. AGG_TX_STATE_LAST_SENT_TRY_CNT_MSK),
  1726. priv->reply_agg_tx_stats.last_sent_try);
  1727. pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t%u\n",
  1728. iwl_get_agg_tx_fail_reason(
  1729. AGG_TX_STATE_LAST_SENT_BT_KILL_MSK),
  1730. priv->reply_agg_tx_stats.last_sent_bt_kill);
  1731. pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
  1732. iwl_get_agg_tx_fail_reason(AGG_TX_STATE_SCD_QUERY_MSK),
  1733. priv->reply_agg_tx_stats.scd_query);
  1734. pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t%u\n",
  1735. iwl_get_agg_tx_fail_reason(
  1736. AGG_TX_STATE_TEST_BAD_CRC32_MSK),
  1737. priv->reply_agg_tx_stats.bad_crc32);
  1738. pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
  1739. iwl_get_agg_tx_fail_reason(AGG_TX_STATE_RESPONSE_MSK),
  1740. priv->reply_agg_tx_stats.response);
  1741. pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
  1742. iwl_get_agg_tx_fail_reason(AGG_TX_STATE_DUMP_TX_MSK),
  1743. priv->reply_agg_tx_stats.dump_tx);
  1744. pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
  1745. iwl_get_agg_tx_fail_reason(AGG_TX_STATE_DELAY_TX_MSK),
  1746. priv->reply_agg_tx_stats.delay_tx);
  1747. pos += scnprintf(buf + pos, bufsz - pos, "UNKNOWN:\t\t\t%u\n",
  1748. priv->reply_agg_tx_stats.unknown);
  1749. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  1750. kfree(buf);
  1751. return ret;
  1752. }
  1753. static ssize_t iwl_dbgfs_sensitivity_read(struct file *file,
  1754. char __user *user_buf,
  1755. size_t count, loff_t *ppos) {
  1756. struct iwl_priv *priv = file->private_data;
  1757. int pos = 0;
  1758. int cnt = 0;
  1759. char *buf;
  1760. int bufsz = sizeof(struct iwl_sensitivity_data) * 4 + 100;
  1761. ssize_t ret;
  1762. struct iwl_sensitivity_data *data;
  1763. data = &priv->sensitivity_data;
  1764. buf = kzalloc(bufsz, GFP_KERNEL);
  1765. if (!buf) {
  1766. IWL_ERR(priv, "Can not allocate Buffer\n");
  1767. return -ENOMEM;
  1768. }
  1769. pos += scnprintf(buf + pos, bufsz - pos, "auto_corr_ofdm:\t\t\t %u\n",
  1770. data->auto_corr_ofdm);
  1771. pos += scnprintf(buf + pos, bufsz - pos,
  1772. "auto_corr_ofdm_mrc:\t\t %u\n",
  1773. data->auto_corr_ofdm_mrc);
  1774. pos += scnprintf(buf + pos, bufsz - pos, "auto_corr_ofdm_x1:\t\t %u\n",
  1775. data->auto_corr_ofdm_x1);
  1776. pos += scnprintf(buf + pos, bufsz - pos,
  1777. "auto_corr_ofdm_mrc_x1:\t\t %u\n",
  1778. data->auto_corr_ofdm_mrc_x1);
  1779. pos += scnprintf(buf + pos, bufsz - pos, "auto_corr_cck:\t\t\t %u\n",
  1780. data->auto_corr_cck);
  1781. pos += scnprintf(buf + pos, bufsz - pos, "auto_corr_cck_mrc:\t\t %u\n",
  1782. data->auto_corr_cck_mrc);
  1783. pos += scnprintf(buf + pos, bufsz - pos,
  1784. "last_bad_plcp_cnt_ofdm:\t\t %u\n",
  1785. data->last_bad_plcp_cnt_ofdm);
  1786. pos += scnprintf(buf + pos, bufsz - pos, "last_fa_cnt_ofdm:\t\t %u\n",
  1787. data->last_fa_cnt_ofdm);
  1788. pos += scnprintf(buf + pos, bufsz - pos,
  1789. "last_bad_plcp_cnt_cck:\t\t %u\n",
  1790. data->last_bad_plcp_cnt_cck);
  1791. pos += scnprintf(buf + pos, bufsz - pos, "last_fa_cnt_cck:\t\t %u\n",
  1792. data->last_fa_cnt_cck);
  1793. pos += scnprintf(buf + pos, bufsz - pos, "nrg_curr_state:\t\t\t %u\n",
  1794. data->nrg_curr_state);
  1795. pos += scnprintf(buf + pos, bufsz - pos, "nrg_prev_state:\t\t\t %u\n",
  1796. data->nrg_prev_state);
  1797. pos += scnprintf(buf + pos, bufsz - pos, "nrg_value:\t\t\t");
  1798. for (cnt = 0; cnt < 10; cnt++) {
  1799. pos += scnprintf(buf + pos, bufsz - pos, " %u",
  1800. data->nrg_value[cnt]);
  1801. }
  1802. pos += scnprintf(buf + pos, bufsz - pos, "\n");
  1803. pos += scnprintf(buf + pos, bufsz - pos, "nrg_silence_rssi:\t\t");
  1804. for (cnt = 0; cnt < NRG_NUM_PREV_STAT_L; cnt++) {
  1805. pos += scnprintf(buf + pos, bufsz - pos, " %u",
  1806. data->nrg_silence_rssi[cnt]);
  1807. }
  1808. pos += scnprintf(buf + pos, bufsz - pos, "\n");
  1809. pos += scnprintf(buf + pos, bufsz - pos, "nrg_silence_ref:\t\t %u\n",
  1810. data->nrg_silence_ref);
  1811. pos += scnprintf(buf + pos, bufsz - pos, "nrg_energy_idx:\t\t\t %u\n",
  1812. data->nrg_energy_idx);
  1813. pos += scnprintf(buf + pos, bufsz - pos, "nrg_silence_idx:\t\t %u\n",
  1814. data->nrg_silence_idx);
  1815. pos += scnprintf(buf + pos, bufsz - pos, "nrg_th_cck:\t\t\t %u\n",
  1816. data->nrg_th_cck);
  1817. pos += scnprintf(buf + pos, bufsz - pos,
  1818. "nrg_auto_corr_silence_diff:\t %u\n",
  1819. data->nrg_auto_corr_silence_diff);
  1820. pos += scnprintf(buf + pos, bufsz - pos, "num_in_cck_no_fa:\t\t %u\n",
  1821. data->num_in_cck_no_fa);
  1822. pos += scnprintf(buf + pos, bufsz - pos, "nrg_th_ofdm:\t\t\t %u\n",
  1823. data->nrg_th_ofdm);
  1824. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  1825. kfree(buf);
  1826. return ret;
  1827. }
  1828. static ssize_t iwl_dbgfs_chain_noise_read(struct file *file,
  1829. char __user *user_buf,
  1830. size_t count, loff_t *ppos) {
  1831. struct iwl_priv *priv = file->private_data;
  1832. int pos = 0;
  1833. int cnt = 0;
  1834. char *buf;
  1835. int bufsz = sizeof(struct iwl_chain_noise_data) * 4 + 100;
  1836. ssize_t ret;
  1837. struct iwl_chain_noise_data *data;
  1838. data = &priv->chain_noise_data;
  1839. buf = kzalloc(bufsz, GFP_KERNEL);
  1840. if (!buf) {
  1841. IWL_ERR(priv, "Can not allocate Buffer\n");
  1842. return -ENOMEM;
  1843. }
  1844. pos += scnprintf(buf + pos, bufsz - pos, "active_chains:\t\t\t %u\n",
  1845. data->active_chains);
  1846. pos += scnprintf(buf + pos, bufsz - pos, "chain_noise_a:\t\t\t %u\n",
  1847. data->chain_noise_a);
  1848. pos += scnprintf(buf + pos, bufsz - pos, "chain_noise_b:\t\t\t %u\n",
  1849. data->chain_noise_b);
  1850. pos += scnprintf(buf + pos, bufsz - pos, "chain_noise_c:\t\t\t %u\n",
  1851. data->chain_noise_c);
  1852. pos += scnprintf(buf + pos, bufsz - pos, "chain_signal_a:\t\t\t %u\n",
  1853. data->chain_signal_a);
  1854. pos += scnprintf(buf + pos, bufsz - pos, "chain_signal_b:\t\t\t %u\n",
  1855. data->chain_signal_b);
  1856. pos += scnprintf(buf + pos, bufsz - pos, "chain_signal_c:\t\t\t %u\n",
  1857. data->chain_signal_c);
  1858. pos += scnprintf(buf + pos, bufsz - pos, "beacon_count:\t\t\t %u\n",
  1859. data->beacon_count);
  1860. pos += scnprintf(buf + pos, bufsz - pos, "disconn_array:\t\t\t");
  1861. for (cnt = 0; cnt < NUM_RX_CHAINS; cnt++) {
  1862. pos += scnprintf(buf + pos, bufsz - pos, " %u",
  1863. data->disconn_array[cnt]);
  1864. }
  1865. pos += scnprintf(buf + pos, bufsz - pos, "\n");
  1866. pos += scnprintf(buf + pos, bufsz - pos, "delta_gain_code:\t\t");
  1867. for (cnt = 0; cnt < NUM_RX_CHAINS; cnt++) {
  1868. pos += scnprintf(buf + pos, bufsz - pos, " %u",
  1869. data->delta_gain_code[cnt]);
  1870. }
  1871. pos += scnprintf(buf + pos, bufsz - pos, "\n");
  1872. pos += scnprintf(buf + pos, bufsz - pos, "radio_write:\t\t\t %u\n",
  1873. data->radio_write);
  1874. pos += scnprintf(buf + pos, bufsz - pos, "state:\t\t\t\t %u\n",
  1875. data->state);
  1876. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  1877. kfree(buf);
  1878. return ret;
  1879. }
  1880. static ssize_t iwl_dbgfs_power_save_status_read(struct file *file,
  1881. char __user *user_buf,
  1882. size_t count, loff_t *ppos)
  1883. {
  1884. struct iwl_priv *priv = file->private_data;
  1885. char buf[60];
  1886. int pos = 0;
  1887. const size_t bufsz = sizeof(buf);
  1888. u32 pwrsave_status;
  1889. pwrsave_status = iwl_read32(trans(priv), CSR_GP_CNTRL) &
  1890. CSR_GP_REG_POWER_SAVE_STATUS_MSK;
  1891. pos += scnprintf(buf + pos, bufsz - pos, "Power Save Status: ");
  1892. pos += scnprintf(buf + pos, bufsz - pos, "%s\n",
  1893. (pwrsave_status == CSR_GP_REG_NO_POWER_SAVE) ? "none" :
  1894. (pwrsave_status == CSR_GP_REG_MAC_POWER_SAVE) ? "MAC" :
  1895. (pwrsave_status == CSR_GP_REG_PHY_POWER_SAVE) ? "PHY" :
  1896. "error");
  1897. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  1898. }
  1899. static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
  1900. const char __user *user_buf,
  1901. size_t count, loff_t *ppos)
  1902. {
  1903. struct iwl_priv *priv = file->private_data;
  1904. char buf[8];
  1905. int buf_size;
  1906. int clear;
  1907. memset(buf, 0, sizeof(buf));
  1908. buf_size = min(count, sizeof(buf) - 1);
  1909. if (copy_from_user(buf, user_buf, buf_size))
  1910. return -EFAULT;
  1911. if (sscanf(buf, "%d", &clear) != 1)
  1912. return -EFAULT;
  1913. /* make request to uCode to retrieve statistics information */
  1914. mutex_lock(&priv->shrd->mutex);
  1915. iwl_send_statistics_request(priv, CMD_SYNC, true);
  1916. mutex_unlock(&priv->shrd->mutex);
  1917. return count;
  1918. }
  1919. static ssize_t iwl_dbgfs_ucode_tracing_read(struct file *file,
  1920. char __user *user_buf,
  1921. size_t count, loff_t *ppos) {
  1922. struct iwl_priv *priv = file->private_data;
  1923. int pos = 0;
  1924. char buf[128];
  1925. const size_t bufsz = sizeof(buf);
  1926. pos += scnprintf(buf + pos, bufsz - pos, "ucode trace timer is %s\n",
  1927. priv->event_log.ucode_trace ? "On" : "Off");
  1928. pos += scnprintf(buf + pos, bufsz - pos, "non_wraps_count:\t\t %u\n",
  1929. priv->event_log.non_wraps_count);
  1930. pos += scnprintf(buf + pos, bufsz - pos, "wraps_once_count:\t\t %u\n",
  1931. priv->event_log.wraps_once_count);
  1932. pos += scnprintf(buf + pos, bufsz - pos, "wraps_more_count:\t\t %u\n",
  1933. priv->event_log.wraps_more_count);
  1934. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  1935. }
  1936. static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
  1937. const char __user *user_buf,
  1938. size_t count, loff_t *ppos)
  1939. {
  1940. struct iwl_priv *priv = file->private_data;
  1941. char buf[8];
  1942. int buf_size;
  1943. int trace;
  1944. memset(buf, 0, sizeof(buf));
  1945. buf_size = min(count, sizeof(buf) - 1);
  1946. if (copy_from_user(buf, user_buf, buf_size))
  1947. return -EFAULT;
  1948. if (sscanf(buf, "%d", &trace) != 1)
  1949. return -EFAULT;
  1950. if (trace) {
  1951. priv->event_log.ucode_trace = true;
  1952. if (iwl_is_alive(priv->shrd)) {
  1953. /* start collecting data now */
  1954. mod_timer(&priv->ucode_trace, jiffies);
  1955. }
  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. cfg(priv)->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. cfg(priv)->base_params->plcp_delta_threshold =
  2042. IWL_MAX_PLCP_ERR_THRESHOLD_DISABLE;
  2043. else
  2044. cfg(priv)->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. cfg(priv)->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 (cfg(priv)->ht_params)
  2185. pos += scnprintf(buf + pos, bufsz - pos,
  2186. "use %s for aggregation\n",
  2187. (cfg(priv)->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 (!cfg(priv)->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. cfg(priv)->ht_params->use_rts_for_aggregation = true;
  2210. else
  2211. cfg(priv)->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. }