iwl-debugfs.c 84 KB

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