iwl-debugfs.c 84 KB

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