iwl-debugfs.c 83 KB

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