iwl-debugfs.c 68 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097
  1. /******************************************************************************
  2. *
  3. * GPL LICENSE SUMMARY
  4. *
  5. * Copyright(c) 2008 - 2009 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/kernel.h>
  29. #include <linux/module.h>
  30. #include <linux/debugfs.h>
  31. #include <linux/ieee80211.h>
  32. #include <net/mac80211.h>
  33. #include "iwl-dev.h"
  34. #include "iwl-debug.h"
  35. #include "iwl-core.h"
  36. #include "iwl-io.h"
  37. #include "iwl-calib.h"
  38. /* create and remove of files */
  39. #define DEBUGFS_ADD_DIR(name, parent) do { \
  40. dbgfs->dir_##name = debugfs_create_dir(#name, parent); \
  41. if (!(dbgfs->dir_##name)) \
  42. goto err; \
  43. } while (0)
  44. #define DEBUGFS_ADD_FILE(name, parent, mode) do { \
  45. dbgfs->dbgfs_##parent##_files.file_##name = \
  46. debugfs_create_file(#name, mode, \
  47. dbgfs->dir_##parent, priv, \
  48. &iwl_dbgfs_##name##_ops); \
  49. if (!(dbgfs->dbgfs_##parent##_files.file_##name)) \
  50. goto err; \
  51. } while (0)
  52. #define DEBUGFS_ADD_BOOL(name, parent, ptr) do { \
  53. dbgfs->dbgfs_##parent##_files.file_##name = \
  54. debugfs_create_bool(#name, S_IWUSR | S_IRUSR, \
  55. dbgfs->dir_##parent, ptr); \
  56. if (IS_ERR(dbgfs->dbgfs_##parent##_files.file_##name) \
  57. || !dbgfs->dbgfs_##parent##_files.file_##name) \
  58. goto err; \
  59. } while (0)
  60. #define DEBUGFS_ADD_X32(name, parent, ptr) do { \
  61. dbgfs->dbgfs_##parent##_files.file_##name = \
  62. debugfs_create_x32(#name, S_IRUSR, dbgfs->dir_##parent, ptr); \
  63. if (IS_ERR(dbgfs->dbgfs_##parent##_files.file_##name) \
  64. || !dbgfs->dbgfs_##parent##_files.file_##name) \
  65. goto err; \
  66. } while (0)
  67. #define DEBUGFS_REMOVE(name) do { \
  68. debugfs_remove(name); \
  69. name = NULL; \
  70. } while (0);
  71. /* file operation */
  72. #define DEBUGFS_READ_FUNC(name) \
  73. static ssize_t iwl_dbgfs_##name##_read(struct file *file, \
  74. char __user *user_buf, \
  75. size_t count, loff_t *ppos);
  76. #define DEBUGFS_WRITE_FUNC(name) \
  77. static ssize_t iwl_dbgfs_##name##_write(struct file *file, \
  78. const char __user *user_buf, \
  79. size_t count, loff_t *ppos);
  80. static int iwl_dbgfs_open_file_generic(struct inode *inode, struct file *file)
  81. {
  82. file->private_data = inode->i_private;
  83. return 0;
  84. }
  85. #define DEBUGFS_READ_FILE_OPS(name) \
  86. DEBUGFS_READ_FUNC(name); \
  87. static const struct file_operations iwl_dbgfs_##name##_ops = { \
  88. .read = iwl_dbgfs_##name##_read, \
  89. .open = iwl_dbgfs_open_file_generic, \
  90. };
  91. #define DEBUGFS_WRITE_FILE_OPS(name) \
  92. DEBUGFS_WRITE_FUNC(name); \
  93. static const struct file_operations iwl_dbgfs_##name##_ops = { \
  94. .write = iwl_dbgfs_##name##_write, \
  95. .open = iwl_dbgfs_open_file_generic, \
  96. };
  97. #define DEBUGFS_READ_WRITE_FILE_OPS(name) \
  98. DEBUGFS_READ_FUNC(name); \
  99. DEBUGFS_WRITE_FUNC(name); \
  100. static const struct file_operations iwl_dbgfs_##name##_ops = { \
  101. .write = iwl_dbgfs_##name##_write, \
  102. .read = iwl_dbgfs_##name##_read, \
  103. .open = iwl_dbgfs_open_file_generic, \
  104. };
  105. static ssize_t iwl_dbgfs_tx_statistics_read(struct file *file,
  106. char __user *user_buf,
  107. size_t count, loff_t *ppos) {
  108. struct iwl_priv *priv = file->private_data;
  109. char *buf;
  110. int pos = 0;
  111. int cnt;
  112. ssize_t ret;
  113. const size_t bufsz = 100 +
  114. sizeof(char) * 50 * (MANAGEMENT_MAX + CONTROL_MAX);
  115. buf = kzalloc(bufsz, GFP_KERNEL);
  116. if (!buf)
  117. return -ENOMEM;
  118. pos += scnprintf(buf + pos, bufsz - pos, "Management:\n");
  119. for (cnt = 0; cnt < MANAGEMENT_MAX; cnt++) {
  120. pos += scnprintf(buf + pos, bufsz - pos,
  121. "\t%25s\t\t: %u\n",
  122. get_mgmt_string(cnt),
  123. priv->tx_stats.mgmt[cnt]);
  124. }
  125. pos += scnprintf(buf + pos, bufsz - pos, "Control\n");
  126. for (cnt = 0; cnt < CONTROL_MAX; cnt++) {
  127. pos += scnprintf(buf + pos, bufsz - pos,
  128. "\t%25s\t\t: %u\n",
  129. get_ctrl_string(cnt),
  130. priv->tx_stats.ctrl[cnt]);
  131. }
  132. pos += scnprintf(buf + pos, bufsz - pos, "Data:\n");
  133. pos += scnprintf(buf + pos, bufsz - pos, "\tcnt: %u\n",
  134. priv->tx_stats.data_cnt);
  135. pos += scnprintf(buf + pos, bufsz - pos, "\tbytes: %llu\n",
  136. priv->tx_stats.data_bytes);
  137. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  138. kfree(buf);
  139. return ret;
  140. }
  141. static ssize_t iwl_dbgfs_clear_traffic_statistics_write(struct file *file,
  142. const char __user *user_buf,
  143. size_t count, loff_t *ppos)
  144. {
  145. struct iwl_priv *priv = file->private_data;
  146. u32 clear_flag;
  147. char buf[8];
  148. int buf_size;
  149. memset(buf, 0, sizeof(buf));
  150. buf_size = min(count, sizeof(buf) - 1);
  151. if (copy_from_user(buf, user_buf, buf_size))
  152. return -EFAULT;
  153. if (sscanf(buf, "%x", &clear_flag) != 1)
  154. return -EFAULT;
  155. iwl_clear_traffic_stats(priv);
  156. return count;
  157. }
  158. static ssize_t iwl_dbgfs_rx_statistics_read(struct file *file,
  159. char __user *user_buf,
  160. size_t count, loff_t *ppos) {
  161. struct iwl_priv *priv = file->private_data;
  162. char *buf;
  163. int pos = 0;
  164. int cnt;
  165. ssize_t ret;
  166. const size_t bufsz = 100 +
  167. sizeof(char) * 50 * (MANAGEMENT_MAX + CONTROL_MAX);
  168. buf = kzalloc(bufsz, GFP_KERNEL);
  169. if (!buf)
  170. return -ENOMEM;
  171. pos += scnprintf(buf + pos, bufsz - pos, "Management:\n");
  172. for (cnt = 0; cnt < MANAGEMENT_MAX; cnt++) {
  173. pos += scnprintf(buf + pos, bufsz - pos,
  174. "\t%25s\t\t: %u\n",
  175. get_mgmt_string(cnt),
  176. priv->rx_stats.mgmt[cnt]);
  177. }
  178. pos += scnprintf(buf + pos, bufsz - pos, "Control:\n");
  179. for (cnt = 0; cnt < CONTROL_MAX; cnt++) {
  180. pos += scnprintf(buf + pos, bufsz - pos,
  181. "\t%25s\t\t: %u\n",
  182. get_ctrl_string(cnt),
  183. priv->rx_stats.ctrl[cnt]);
  184. }
  185. pos += scnprintf(buf + pos, bufsz - pos, "Data:\n");
  186. pos += scnprintf(buf + pos, bufsz - pos, "\tcnt: %u\n",
  187. priv->rx_stats.data_cnt);
  188. pos += scnprintf(buf + pos, bufsz - pos, "\tbytes: %llu\n",
  189. priv->rx_stats.data_bytes);
  190. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  191. kfree(buf);
  192. return ret;
  193. }
  194. #define BYTE1_MASK 0x000000ff;
  195. #define BYTE2_MASK 0x0000ffff;
  196. #define BYTE3_MASK 0x00ffffff;
  197. static ssize_t iwl_dbgfs_sram_read(struct file *file,
  198. char __user *user_buf,
  199. size_t count, loff_t *ppos)
  200. {
  201. u32 val;
  202. char *buf;
  203. ssize_t ret;
  204. int i;
  205. int pos = 0;
  206. struct iwl_priv *priv = file->private_data;
  207. size_t bufsz;
  208. /* default is to dump the entire data segment */
  209. if (!priv->dbgfs->sram_offset && !priv->dbgfs->sram_len) {
  210. priv->dbgfs->sram_offset = 0x800000;
  211. if (priv->ucode_type == UCODE_INIT)
  212. priv->dbgfs->sram_len = priv->ucode_init_data.len;
  213. else
  214. priv->dbgfs->sram_len = priv->ucode_data.len;
  215. }
  216. bufsz = 30 + priv->dbgfs->sram_len * sizeof(char) * 10;
  217. buf = kmalloc(bufsz, GFP_KERNEL);
  218. if (!buf)
  219. return -ENOMEM;
  220. pos += scnprintf(buf + pos, bufsz - pos, "sram_len: 0x%x\n",
  221. priv->dbgfs->sram_len);
  222. pos += scnprintf(buf + pos, bufsz - pos, "sram_offset: 0x%x\n",
  223. priv->dbgfs->sram_offset);
  224. for (i = priv->dbgfs->sram_len; i > 0; i -= 4) {
  225. val = iwl_read_targ_mem(priv, priv->dbgfs->sram_offset + \
  226. priv->dbgfs->sram_len - i);
  227. if (i < 4) {
  228. switch (i) {
  229. case 1:
  230. val &= BYTE1_MASK;
  231. break;
  232. case 2:
  233. val &= BYTE2_MASK;
  234. break;
  235. case 3:
  236. val &= BYTE3_MASK;
  237. break;
  238. }
  239. }
  240. if (!(i % 16))
  241. pos += scnprintf(buf + pos, bufsz - pos, "\n");
  242. pos += scnprintf(buf + pos, bufsz - pos, "0x%08x ", val);
  243. }
  244. pos += scnprintf(buf + pos, bufsz - pos, "\n");
  245. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  246. kfree(buf);
  247. return ret;
  248. }
  249. static ssize_t iwl_dbgfs_sram_write(struct file *file,
  250. const char __user *user_buf,
  251. size_t count, loff_t *ppos)
  252. {
  253. struct iwl_priv *priv = file->private_data;
  254. char buf[64];
  255. int buf_size;
  256. u32 offset, len;
  257. memset(buf, 0, sizeof(buf));
  258. buf_size = min(count, sizeof(buf) - 1);
  259. if (copy_from_user(buf, user_buf, buf_size))
  260. return -EFAULT;
  261. if (sscanf(buf, "%x,%x", &offset, &len) == 2) {
  262. priv->dbgfs->sram_offset = offset;
  263. priv->dbgfs->sram_len = len;
  264. } else {
  265. priv->dbgfs->sram_offset = 0;
  266. priv->dbgfs->sram_len = 0;
  267. }
  268. return count;
  269. }
  270. static ssize_t iwl_dbgfs_stations_read(struct file *file, char __user *user_buf,
  271. size_t count, loff_t *ppos)
  272. {
  273. struct iwl_priv *priv = file->private_data;
  274. struct iwl_station_entry *station;
  275. int max_sta = priv->hw_params.max_stations;
  276. char *buf;
  277. int i, j, pos = 0;
  278. ssize_t ret;
  279. /* Add 30 for initial string */
  280. const size_t bufsz = 30 + sizeof(char) * 500 * (priv->num_stations);
  281. buf = kmalloc(bufsz, GFP_KERNEL);
  282. if (!buf)
  283. return -ENOMEM;
  284. pos += scnprintf(buf + pos, bufsz - pos, "num of stations: %d\n\n",
  285. priv->num_stations);
  286. for (i = 0; i < max_sta; i++) {
  287. station = &priv->stations[i];
  288. if (station->used) {
  289. pos += scnprintf(buf + pos, bufsz - pos,
  290. "station %d:\ngeneral data:\n", i+1);
  291. pos += scnprintf(buf + pos, bufsz - pos, "id: %u\n",
  292. station->sta.sta.sta_id);
  293. pos += scnprintf(buf + pos, bufsz - pos, "mode: %u\n",
  294. station->sta.mode);
  295. pos += scnprintf(buf + pos, bufsz - pos,
  296. "flags: 0x%x\n",
  297. station->sta.station_flags_msk);
  298. pos += scnprintf(buf + pos, bufsz - pos, "tid data:\n");
  299. pos += scnprintf(buf + pos, bufsz - pos,
  300. "seq_num\t\ttxq_id");
  301. pos += scnprintf(buf + pos, bufsz - pos,
  302. "\tframe_count\twait_for_ba\t");
  303. pos += scnprintf(buf + pos, bufsz - pos,
  304. "start_idx\tbitmap0\t");
  305. pos += scnprintf(buf + pos, bufsz - pos,
  306. "bitmap1\trate_n_flags");
  307. pos += scnprintf(buf + pos, bufsz - pos, "\n");
  308. for (j = 0; j < MAX_TID_COUNT; j++) {
  309. pos += scnprintf(buf + pos, bufsz - pos,
  310. "[%d]:\t\t%u", j,
  311. station->tid[j].seq_number);
  312. pos += scnprintf(buf + pos, bufsz - pos,
  313. "\t%u\t\t%u\t\t%u\t\t",
  314. station->tid[j].agg.txq_id,
  315. station->tid[j].agg.frame_count,
  316. station->tid[j].agg.wait_for_ba);
  317. pos += scnprintf(buf + pos, bufsz - pos,
  318. "%u\t%llu\t%u",
  319. station->tid[j].agg.start_idx,
  320. (unsigned long long)station->tid[j].agg.bitmap,
  321. station->tid[j].agg.rate_n_flags);
  322. pos += scnprintf(buf + pos, bufsz - pos, "\n");
  323. }
  324. pos += scnprintf(buf + pos, bufsz - pos, "\n");
  325. }
  326. }
  327. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  328. kfree(buf);
  329. return ret;
  330. }
  331. static ssize_t iwl_dbgfs_nvm_read(struct file *file,
  332. char __user *user_buf,
  333. size_t count,
  334. loff_t *ppos)
  335. {
  336. ssize_t ret;
  337. struct iwl_priv *priv = file->private_data;
  338. int pos = 0, ofs = 0, buf_size = 0;
  339. const u8 *ptr;
  340. char *buf;
  341. u16 eeprom_ver;
  342. size_t eeprom_len = priv->cfg->eeprom_size;
  343. buf_size = 4 * eeprom_len + 256;
  344. if (eeprom_len % 16) {
  345. IWL_ERR(priv, "NVM size is not multiple of 16.\n");
  346. return -ENODATA;
  347. }
  348. ptr = priv->eeprom;
  349. if (!ptr) {
  350. IWL_ERR(priv, "Invalid EEPROM/OTP memory\n");
  351. return -ENOMEM;
  352. }
  353. /* 4 characters for byte 0xYY */
  354. buf = kzalloc(buf_size, GFP_KERNEL);
  355. if (!buf) {
  356. IWL_ERR(priv, "Can not allocate Buffer\n");
  357. return -ENOMEM;
  358. }
  359. eeprom_ver = iwl_eeprom_query16(priv, EEPROM_VERSION);
  360. pos += scnprintf(buf + pos, buf_size - pos, "NVM Type: %s, "
  361. "version: 0x%x\n",
  362. (priv->nvm_device_type == NVM_DEVICE_TYPE_OTP)
  363. ? "OTP" : "EEPROM", eeprom_ver);
  364. for (ofs = 0 ; ofs < eeprom_len ; ofs += 16) {
  365. pos += scnprintf(buf + pos, buf_size - pos, "0x%.4x ", ofs);
  366. hex_dump_to_buffer(ptr + ofs, 16 , 16, 2, buf + pos,
  367. buf_size - pos, 0);
  368. pos += strlen(buf + pos);
  369. if (buf_size - pos > 0)
  370. buf[pos++] = '\n';
  371. }
  372. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  373. kfree(buf);
  374. return ret;
  375. }
  376. static ssize_t iwl_dbgfs_log_event_read(struct file *file,
  377. char __user *user_buf,
  378. size_t count, loff_t *ppos)
  379. {
  380. struct iwl_priv *priv = file->private_data;
  381. char *buf;
  382. int pos = 0;
  383. ssize_t ret = -ENOMEM;
  384. pos = priv->cfg->ops->lib->dump_nic_event_log(priv, true, &buf, true);
  385. if (pos && buf) {
  386. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  387. kfree(buf);
  388. }
  389. return ret;
  390. }
  391. static ssize_t iwl_dbgfs_log_event_write(struct file *file,
  392. const char __user *user_buf,
  393. size_t count, loff_t *ppos)
  394. {
  395. struct iwl_priv *priv = file->private_data;
  396. u32 event_log_flag;
  397. char buf[8];
  398. int buf_size;
  399. memset(buf, 0, sizeof(buf));
  400. buf_size = min(count, sizeof(buf) - 1);
  401. if (copy_from_user(buf, user_buf, buf_size))
  402. return -EFAULT;
  403. if (sscanf(buf, "%d", &event_log_flag) != 1)
  404. return -EFAULT;
  405. if (event_log_flag == 1)
  406. priv->cfg->ops->lib->dump_nic_event_log(priv, true,
  407. NULL, false);
  408. return count;
  409. }
  410. static ssize_t iwl_dbgfs_channels_read(struct file *file, char __user *user_buf,
  411. size_t count, loff_t *ppos)
  412. {
  413. struct iwl_priv *priv = file->private_data;
  414. struct ieee80211_channel *channels = NULL;
  415. const struct ieee80211_supported_band *supp_band = NULL;
  416. int pos = 0, i, bufsz = PAGE_SIZE;
  417. char *buf;
  418. ssize_t ret;
  419. if (!test_bit(STATUS_GEO_CONFIGURED, &priv->status))
  420. return -EAGAIN;
  421. buf = kzalloc(bufsz, GFP_KERNEL);
  422. if (!buf) {
  423. IWL_ERR(priv, "Can not allocate Buffer\n");
  424. return -ENOMEM;
  425. }
  426. supp_band = iwl_get_hw_mode(priv, IEEE80211_BAND_2GHZ);
  427. if (supp_band) {
  428. channels = supp_band->channels;
  429. pos += scnprintf(buf + pos, bufsz - pos,
  430. "Displaying %d channels in 2.4GHz band 802.11bg):\n",
  431. supp_band->n_channels);
  432. for (i = 0; i < supp_band->n_channels; i++)
  433. pos += scnprintf(buf + pos, bufsz - pos,
  434. "%d: %ddBm: BSS%s%s, %s.\n",
  435. ieee80211_frequency_to_channel(
  436. channels[i].center_freq),
  437. channels[i].max_power,
  438. channels[i].flags & IEEE80211_CHAN_RADAR ?
  439. " (IEEE 802.11h required)" : "",
  440. ((channels[i].flags & IEEE80211_CHAN_NO_IBSS)
  441. || (channels[i].flags &
  442. IEEE80211_CHAN_RADAR)) ? "" :
  443. ", IBSS",
  444. channels[i].flags &
  445. IEEE80211_CHAN_PASSIVE_SCAN ?
  446. "passive only" : "active/passive");
  447. }
  448. supp_band = iwl_get_hw_mode(priv, IEEE80211_BAND_5GHZ);
  449. if (supp_band) {
  450. channels = supp_band->channels;
  451. pos += scnprintf(buf + pos, bufsz - pos,
  452. "Displaying %d channels in 5.2GHz band (802.11a)\n",
  453. supp_band->n_channels);
  454. for (i = 0; i < supp_band->n_channels; i++)
  455. pos += scnprintf(buf + pos, bufsz - pos,
  456. "%d: %ddBm: BSS%s%s, %s.\n",
  457. ieee80211_frequency_to_channel(
  458. channels[i].center_freq),
  459. channels[i].max_power,
  460. channels[i].flags & IEEE80211_CHAN_RADAR ?
  461. " (IEEE 802.11h required)" : "",
  462. ((channels[i].flags & IEEE80211_CHAN_NO_IBSS)
  463. || (channels[i].flags &
  464. IEEE80211_CHAN_RADAR)) ? "" :
  465. ", IBSS",
  466. channels[i].flags &
  467. IEEE80211_CHAN_PASSIVE_SCAN ?
  468. "passive only" : "active/passive");
  469. }
  470. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  471. kfree(buf);
  472. return ret;
  473. }
  474. static ssize_t iwl_dbgfs_status_read(struct file *file,
  475. char __user *user_buf,
  476. size_t count, loff_t *ppos) {
  477. struct iwl_priv *priv = file->private_data;
  478. char buf[512];
  479. int pos = 0;
  480. const size_t bufsz = sizeof(buf);
  481. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_HCMD_ACTIVE:\t %d\n",
  482. test_bit(STATUS_HCMD_ACTIVE, &priv->status));
  483. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_HCMD_SYNC_ACTIVE: %d\n",
  484. test_bit(STATUS_HCMD_SYNC_ACTIVE, &priv->status));
  485. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_INT_ENABLED:\t %d\n",
  486. test_bit(STATUS_INT_ENABLED, &priv->status));
  487. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_RF_KILL_HW:\t %d\n",
  488. test_bit(STATUS_RF_KILL_HW, &priv->status));
  489. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_CT_KILL:\t\t %d\n",
  490. test_bit(STATUS_CT_KILL, &priv->status));
  491. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_INIT:\t\t %d\n",
  492. test_bit(STATUS_INIT, &priv->status));
  493. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_ALIVE:\t\t %d\n",
  494. test_bit(STATUS_ALIVE, &priv->status));
  495. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_READY:\t\t %d\n",
  496. test_bit(STATUS_READY, &priv->status));
  497. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_TEMPERATURE:\t %d\n",
  498. test_bit(STATUS_TEMPERATURE, &priv->status));
  499. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_GEO_CONFIGURED:\t %d\n",
  500. test_bit(STATUS_GEO_CONFIGURED, &priv->status));
  501. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_EXIT_PENDING:\t %d\n",
  502. test_bit(STATUS_EXIT_PENDING, &priv->status));
  503. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_STATISTICS:\t %d\n",
  504. test_bit(STATUS_STATISTICS, &priv->status));
  505. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_SCANNING:\t %d\n",
  506. test_bit(STATUS_SCANNING, &priv->status));
  507. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_SCAN_ABORTING:\t %d\n",
  508. test_bit(STATUS_SCAN_ABORTING, &priv->status));
  509. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_SCAN_HW:\t\t %d\n",
  510. test_bit(STATUS_SCAN_HW, &priv->status));
  511. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_POWER_PMI:\t %d\n",
  512. test_bit(STATUS_POWER_PMI, &priv->status));
  513. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_FW_ERROR:\t %d\n",
  514. test_bit(STATUS_FW_ERROR, &priv->status));
  515. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_MODE_PENDING:\t %d\n",
  516. test_bit(STATUS_MODE_PENDING, &priv->status));
  517. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  518. }
  519. static ssize_t iwl_dbgfs_interrupt_read(struct file *file,
  520. char __user *user_buf,
  521. size_t count, loff_t *ppos) {
  522. struct iwl_priv *priv = file->private_data;
  523. int pos = 0;
  524. int cnt = 0;
  525. char *buf;
  526. int bufsz = 24 * 64; /* 24 items * 64 char per item */
  527. ssize_t ret;
  528. buf = kzalloc(bufsz, GFP_KERNEL);
  529. if (!buf) {
  530. IWL_ERR(priv, "Can not allocate Buffer\n");
  531. return -ENOMEM;
  532. }
  533. pos += scnprintf(buf + pos, bufsz - pos,
  534. "Interrupt Statistics Report:\n");
  535. pos += scnprintf(buf + pos, bufsz - pos, "HW Error:\t\t\t %u\n",
  536. priv->isr_stats.hw);
  537. pos += scnprintf(buf + pos, bufsz - pos, "SW Error:\t\t\t %u\n",
  538. priv->isr_stats.sw);
  539. if (priv->isr_stats.sw > 0) {
  540. pos += scnprintf(buf + pos, bufsz - pos,
  541. "\tLast Restarting Code: 0x%X\n",
  542. priv->isr_stats.sw_err);
  543. }
  544. #ifdef CONFIG_IWLWIFI_DEBUG
  545. pos += scnprintf(buf + pos, bufsz - pos, "Frame transmitted:\t\t %u\n",
  546. priv->isr_stats.sch);
  547. pos += scnprintf(buf + pos, bufsz - pos, "Alive interrupt:\t\t %u\n",
  548. priv->isr_stats.alive);
  549. #endif
  550. pos += scnprintf(buf + pos, bufsz - pos,
  551. "HW RF KILL switch toggled:\t %u\n",
  552. priv->isr_stats.rfkill);
  553. pos += scnprintf(buf + pos, bufsz - pos, "CT KILL:\t\t\t %u\n",
  554. priv->isr_stats.ctkill);
  555. pos += scnprintf(buf + pos, bufsz - pos, "Wakeup Interrupt:\t\t %u\n",
  556. priv->isr_stats.wakeup);
  557. pos += scnprintf(buf + pos, bufsz - pos,
  558. "Rx command responses:\t\t %u\n",
  559. priv->isr_stats.rx);
  560. for (cnt = 0; cnt < REPLY_MAX; cnt++) {
  561. if (priv->isr_stats.rx_handlers[cnt] > 0)
  562. pos += scnprintf(buf + pos, bufsz - pos,
  563. "\tRx handler[%36s]:\t\t %u\n",
  564. get_cmd_string(cnt),
  565. priv->isr_stats.rx_handlers[cnt]);
  566. }
  567. pos += scnprintf(buf + pos, bufsz - pos, "Tx/FH interrupt:\t\t %u\n",
  568. priv->isr_stats.tx);
  569. pos += scnprintf(buf + pos, bufsz - pos, "Unexpected INTA:\t\t %u\n",
  570. priv->isr_stats.unhandled);
  571. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  572. kfree(buf);
  573. return ret;
  574. }
  575. static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
  576. const char __user *user_buf,
  577. size_t count, loff_t *ppos)
  578. {
  579. struct iwl_priv *priv = file->private_data;
  580. char buf[8];
  581. int buf_size;
  582. u32 reset_flag;
  583. memset(buf, 0, sizeof(buf));
  584. buf_size = min(count, sizeof(buf) - 1);
  585. if (copy_from_user(buf, user_buf, buf_size))
  586. return -EFAULT;
  587. if (sscanf(buf, "%x", &reset_flag) != 1)
  588. return -EFAULT;
  589. if (reset_flag == 0)
  590. iwl_clear_isr_stats(priv);
  591. return count;
  592. }
  593. static ssize_t iwl_dbgfs_qos_read(struct file *file, char __user *user_buf,
  594. size_t count, loff_t *ppos)
  595. {
  596. struct iwl_priv *priv = file->private_data;
  597. int pos = 0, i;
  598. char buf[256];
  599. const size_t bufsz = sizeof(buf);
  600. ssize_t ret;
  601. for (i = 0; i < AC_NUM; i++) {
  602. pos += scnprintf(buf + pos, bufsz - pos,
  603. "\tcw_min\tcw_max\taifsn\ttxop\n");
  604. pos += scnprintf(buf + pos, bufsz - pos,
  605. "AC[%d]\t%u\t%u\t%u\t%u\n", i,
  606. priv->qos_data.def_qos_parm.ac[i].cw_min,
  607. priv->qos_data.def_qos_parm.ac[i].cw_max,
  608. priv->qos_data.def_qos_parm.ac[i].aifsn,
  609. priv->qos_data.def_qos_parm.ac[i].edca_txop);
  610. }
  611. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  612. return ret;
  613. }
  614. static ssize_t iwl_dbgfs_led_read(struct file *file, char __user *user_buf,
  615. size_t count, loff_t *ppos)
  616. {
  617. struct iwl_priv *priv = file->private_data;
  618. int pos = 0;
  619. char buf[256];
  620. const size_t bufsz = sizeof(buf);
  621. ssize_t ret;
  622. pos += scnprintf(buf + pos, bufsz - pos,
  623. "allow blinking: %s\n",
  624. (priv->allow_blinking) ? "True" : "False");
  625. if (priv->allow_blinking) {
  626. pos += scnprintf(buf + pos, bufsz - pos,
  627. "Led blinking rate: %u\n",
  628. priv->last_blink_rate);
  629. pos += scnprintf(buf + pos, bufsz - pos,
  630. "Last blink time: %lu\n",
  631. priv->last_blink_time);
  632. }
  633. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  634. return ret;
  635. }
  636. static ssize_t iwl_dbgfs_thermal_throttling_read(struct file *file,
  637. char __user *user_buf,
  638. size_t count, loff_t *ppos)
  639. {
  640. struct iwl_priv *priv = file->private_data;
  641. struct iwl_tt_mgmt *tt = &priv->thermal_throttle;
  642. struct iwl_tt_restriction *restriction;
  643. char buf[100];
  644. int pos = 0;
  645. const size_t bufsz = sizeof(buf);
  646. ssize_t ret;
  647. pos += scnprintf(buf + pos, bufsz - pos,
  648. "Thermal Throttling Mode: %s\n",
  649. tt->advanced_tt ? "Advance" : "Legacy");
  650. pos += scnprintf(buf + pos, bufsz - pos,
  651. "Thermal Throttling State: %d\n",
  652. tt->state);
  653. if (tt->advanced_tt) {
  654. restriction = tt->restriction + tt->state;
  655. pos += scnprintf(buf + pos, bufsz - pos,
  656. "Tx mode: %d\n",
  657. restriction->tx_stream);
  658. pos += scnprintf(buf + pos, bufsz - pos,
  659. "Rx mode: %d\n",
  660. restriction->rx_stream);
  661. pos += scnprintf(buf + pos, bufsz - pos,
  662. "HT mode: %d\n",
  663. restriction->is_ht);
  664. }
  665. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  666. return ret;
  667. }
  668. static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
  669. const char __user *user_buf,
  670. size_t count, loff_t *ppos)
  671. {
  672. struct iwl_priv *priv = file->private_data;
  673. char buf[8];
  674. int buf_size;
  675. int ht40;
  676. memset(buf, 0, sizeof(buf));
  677. buf_size = min(count, sizeof(buf) - 1);
  678. if (copy_from_user(buf, user_buf, buf_size))
  679. return -EFAULT;
  680. if (sscanf(buf, "%d", &ht40) != 1)
  681. return -EFAULT;
  682. if (!iwl_is_associated(priv))
  683. priv->disable_ht40 = ht40 ? true : false;
  684. else {
  685. IWL_ERR(priv, "Sta associated with AP - "
  686. "Change to 40MHz channel support is not allowed\n");
  687. return -EINVAL;
  688. }
  689. return count;
  690. }
  691. static ssize_t iwl_dbgfs_disable_ht40_read(struct file *file,
  692. char __user *user_buf,
  693. size_t count, loff_t *ppos)
  694. {
  695. struct iwl_priv *priv = file->private_data;
  696. char buf[100];
  697. int pos = 0;
  698. const size_t bufsz = sizeof(buf);
  699. ssize_t ret;
  700. pos += scnprintf(buf + pos, bufsz - pos,
  701. "11n 40MHz Mode: %s\n",
  702. priv->disable_ht40 ? "Disabled" : "Enabled");
  703. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  704. return ret;
  705. }
  706. static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
  707. const char __user *user_buf,
  708. size_t count, loff_t *ppos)
  709. {
  710. struct iwl_priv *priv = file->private_data;
  711. char buf[8];
  712. int buf_size;
  713. int value;
  714. memset(buf, 0, sizeof(buf));
  715. buf_size = min(count, sizeof(buf) - 1);
  716. if (copy_from_user(buf, user_buf, buf_size))
  717. return -EFAULT;
  718. if (sscanf(buf, "%d", &value) != 1)
  719. return -EINVAL;
  720. /*
  721. * Our users expect 0 to be "CAM", but 0 isn't actually
  722. * valid here. However, let's not confuse them and present
  723. * IWL_POWER_INDEX_1 as "1", not "0".
  724. */
  725. if (value == 0)
  726. return -EINVAL;
  727. else if (value > 0)
  728. value -= 1;
  729. if (value != -1 && (value < 0 || value >= IWL_POWER_NUM))
  730. return -EINVAL;
  731. if (!iwl_is_ready_rf(priv))
  732. return -EAGAIN;
  733. priv->power_data.debug_sleep_level_override = value;
  734. iwl_power_update_mode(priv, true);
  735. return count;
  736. }
  737. static ssize_t iwl_dbgfs_sleep_level_override_read(struct file *file,
  738. char __user *user_buf,
  739. size_t count, loff_t *ppos)
  740. {
  741. struct iwl_priv *priv = file->private_data;
  742. char buf[10];
  743. int pos, value;
  744. const size_t bufsz = sizeof(buf);
  745. /* see the write function */
  746. value = priv->power_data.debug_sleep_level_override;
  747. if (value >= 0)
  748. value += 1;
  749. pos = scnprintf(buf, bufsz, "%d\n", value);
  750. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  751. }
  752. static ssize_t iwl_dbgfs_current_sleep_command_read(struct file *file,
  753. char __user *user_buf,
  754. size_t count, loff_t *ppos)
  755. {
  756. struct iwl_priv *priv = file->private_data;
  757. char buf[200];
  758. int pos = 0, i;
  759. const size_t bufsz = sizeof(buf);
  760. struct iwl_powertable_cmd *cmd = &priv->power_data.sleep_cmd;
  761. pos += scnprintf(buf + pos, bufsz - pos,
  762. "flags: %#.2x\n", le16_to_cpu(cmd->flags));
  763. pos += scnprintf(buf + pos, bufsz - pos,
  764. "RX/TX timeout: %d/%d usec\n",
  765. le32_to_cpu(cmd->rx_data_timeout),
  766. le32_to_cpu(cmd->tx_data_timeout));
  767. for (i = 0; i < IWL_POWER_VEC_SIZE; i++)
  768. pos += scnprintf(buf + pos, bufsz - pos,
  769. "sleep_interval[%d]: %d\n", i,
  770. le32_to_cpu(cmd->sleep_interval[i]));
  771. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  772. }
  773. DEBUGFS_READ_WRITE_FILE_OPS(sram);
  774. DEBUGFS_READ_WRITE_FILE_OPS(log_event);
  775. DEBUGFS_READ_FILE_OPS(nvm);
  776. DEBUGFS_READ_FILE_OPS(stations);
  777. DEBUGFS_READ_FILE_OPS(channels);
  778. DEBUGFS_READ_FILE_OPS(status);
  779. DEBUGFS_READ_WRITE_FILE_OPS(interrupt);
  780. DEBUGFS_READ_FILE_OPS(qos);
  781. DEBUGFS_READ_FILE_OPS(led);
  782. DEBUGFS_READ_FILE_OPS(thermal_throttling);
  783. DEBUGFS_READ_WRITE_FILE_OPS(disable_ht40);
  784. DEBUGFS_READ_WRITE_FILE_OPS(sleep_level_override);
  785. DEBUGFS_READ_FILE_OPS(current_sleep_command);
  786. static ssize_t iwl_dbgfs_traffic_log_read(struct file *file,
  787. char __user *user_buf,
  788. size_t count, loff_t *ppos)
  789. {
  790. struct iwl_priv *priv = file->private_data;
  791. int pos = 0, ofs = 0;
  792. int cnt = 0, entry;
  793. struct iwl_tx_queue *txq;
  794. struct iwl_queue *q;
  795. struct iwl_rx_queue *rxq = &priv->rxq;
  796. char *buf;
  797. int bufsz = ((IWL_TRAFFIC_ENTRIES * IWL_TRAFFIC_ENTRY_SIZE * 64) * 2) +
  798. (priv->cfg->num_of_queues * 32 * 8) + 400;
  799. const u8 *ptr;
  800. ssize_t ret;
  801. if (!priv->txq) {
  802. IWL_ERR(priv, "txq not ready\n");
  803. return -EAGAIN;
  804. }
  805. buf = kzalloc(bufsz, GFP_KERNEL);
  806. if (!buf) {
  807. IWL_ERR(priv, "Can not allocate buffer\n");
  808. return -ENOMEM;
  809. }
  810. pos += scnprintf(buf + pos, bufsz - pos, "Tx Queue\n");
  811. for (cnt = 0; cnt < priv->hw_params.max_txq_num; cnt++) {
  812. txq = &priv->txq[cnt];
  813. q = &txq->q;
  814. pos += scnprintf(buf + pos, bufsz - pos,
  815. "q[%d]: read_ptr: %u, write_ptr: %u\n",
  816. cnt, q->read_ptr, q->write_ptr);
  817. }
  818. if (priv->tx_traffic && (iwl_debug_level & IWL_DL_TX)) {
  819. ptr = priv->tx_traffic;
  820. pos += scnprintf(buf + pos, bufsz - pos,
  821. "Tx Traffic idx: %u\n", priv->tx_traffic_idx);
  822. for (cnt = 0, ofs = 0; cnt < IWL_TRAFFIC_ENTRIES; cnt++) {
  823. for (entry = 0; entry < IWL_TRAFFIC_ENTRY_SIZE / 16;
  824. entry++, ofs += 16) {
  825. pos += scnprintf(buf + pos, bufsz - pos,
  826. "0x%.4x ", ofs);
  827. hex_dump_to_buffer(ptr + ofs, 16, 16, 2,
  828. buf + pos, bufsz - pos, 0);
  829. pos += strlen(buf + pos);
  830. if (bufsz - pos > 0)
  831. buf[pos++] = '\n';
  832. }
  833. }
  834. }
  835. pos += scnprintf(buf + pos, bufsz - pos, "Rx Queue\n");
  836. pos += scnprintf(buf + pos, bufsz - pos,
  837. "read: %u, write: %u\n",
  838. rxq->read, rxq->write);
  839. if (priv->rx_traffic && (iwl_debug_level & IWL_DL_RX)) {
  840. ptr = priv->rx_traffic;
  841. pos += scnprintf(buf + pos, bufsz - pos,
  842. "Rx Traffic idx: %u\n", priv->rx_traffic_idx);
  843. for (cnt = 0, ofs = 0; cnt < IWL_TRAFFIC_ENTRIES; cnt++) {
  844. for (entry = 0; entry < IWL_TRAFFIC_ENTRY_SIZE / 16;
  845. entry++, ofs += 16) {
  846. pos += scnprintf(buf + pos, bufsz - pos,
  847. "0x%.4x ", ofs);
  848. hex_dump_to_buffer(ptr + ofs, 16, 16, 2,
  849. buf + pos, bufsz - pos, 0);
  850. pos += strlen(buf + pos);
  851. if (bufsz - pos > 0)
  852. buf[pos++] = '\n';
  853. }
  854. }
  855. }
  856. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  857. kfree(buf);
  858. return ret;
  859. }
  860. static ssize_t iwl_dbgfs_traffic_log_write(struct file *file,
  861. const char __user *user_buf,
  862. size_t count, loff_t *ppos)
  863. {
  864. struct iwl_priv *priv = file->private_data;
  865. char buf[8];
  866. int buf_size;
  867. int traffic_log;
  868. memset(buf, 0, sizeof(buf));
  869. buf_size = min(count, sizeof(buf) - 1);
  870. if (copy_from_user(buf, user_buf, buf_size))
  871. return -EFAULT;
  872. if (sscanf(buf, "%d", &traffic_log) != 1)
  873. return -EFAULT;
  874. if (traffic_log == 0)
  875. iwl_reset_traffic_log(priv);
  876. return count;
  877. }
  878. static ssize_t iwl_dbgfs_tx_queue_read(struct file *file,
  879. char __user *user_buf,
  880. size_t count, loff_t *ppos) {
  881. struct iwl_priv *priv = file->private_data;
  882. struct iwl_tx_queue *txq;
  883. struct iwl_queue *q;
  884. char *buf;
  885. int pos = 0;
  886. int cnt;
  887. int ret;
  888. const size_t bufsz = sizeof(char) * 64 * priv->cfg->num_of_queues;
  889. if (!priv->txq) {
  890. IWL_ERR(priv, "txq not ready\n");
  891. return -EAGAIN;
  892. }
  893. buf = kzalloc(bufsz, GFP_KERNEL);
  894. if (!buf)
  895. return -ENOMEM;
  896. for (cnt = 0; cnt < priv->hw_params.max_txq_num; cnt++) {
  897. txq = &priv->txq[cnt];
  898. q = &txq->q;
  899. pos += scnprintf(buf + pos, bufsz - pos,
  900. "hwq %.2d: read=%u write=%u stop=%d"
  901. " swq_id=%#.2x (ac %d/hwq %d)\n",
  902. cnt, q->read_ptr, q->write_ptr,
  903. !!test_bit(cnt, priv->queue_stopped),
  904. txq->swq_id,
  905. txq->swq_id & 0x80 ? txq->swq_id & 3 :
  906. txq->swq_id,
  907. txq->swq_id & 0x80 ? (txq->swq_id >> 2) &
  908. 0x1f : txq->swq_id);
  909. if (cnt >= 4)
  910. continue;
  911. /* for the ACs, display the stop count too */
  912. pos += scnprintf(buf + pos, bufsz - pos,
  913. " stop-count: %d\n",
  914. atomic_read(&priv->queue_stop_count[cnt]));
  915. }
  916. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  917. kfree(buf);
  918. return ret;
  919. }
  920. static ssize_t iwl_dbgfs_rx_queue_read(struct file *file,
  921. char __user *user_buf,
  922. size_t count, loff_t *ppos) {
  923. struct iwl_priv *priv = file->private_data;
  924. struct iwl_rx_queue *rxq = &priv->rxq;
  925. char buf[256];
  926. int pos = 0;
  927. const size_t bufsz = sizeof(buf);
  928. pos += scnprintf(buf + pos, bufsz - pos, "read: %u\n",
  929. rxq->read);
  930. pos += scnprintf(buf + pos, bufsz - pos, "write: %u\n",
  931. rxq->write);
  932. pos += scnprintf(buf + pos, bufsz - pos, "free_count: %u\n",
  933. rxq->free_count);
  934. pos += scnprintf(buf + pos, bufsz - pos, "closed_rb_num: %u\n",
  935. le16_to_cpu(rxq->rb_stts->closed_rb_num) & 0x0FFF);
  936. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  937. }
  938. static int iwl_dbgfs_statistics_flag(struct iwl_priv *priv, char *buf,
  939. int bufsz)
  940. {
  941. int p = 0;
  942. p += scnprintf(buf + p, bufsz - p,
  943. "Statistics Flag(0x%X):\n",
  944. le32_to_cpu(priv->statistics.flag));
  945. if (le32_to_cpu(priv->statistics.flag) & UCODE_STATISTICS_CLEAR_MSK)
  946. p += scnprintf(buf + p, bufsz - p,
  947. "\tStatistics have been cleared\n");
  948. p += scnprintf(buf + p, bufsz - p,
  949. "\tOperational Frequency: %s\n",
  950. (le32_to_cpu(priv->statistics.flag) &
  951. UCODE_STATISTICS_FREQUENCY_MSK)
  952. ? "2.4 GHz" : "5.2 GHz");
  953. p += scnprintf(buf + p, bufsz - p,
  954. "\tTGj Narrow Band: %s\n",
  955. (le32_to_cpu(priv->statistics.flag) &
  956. UCODE_STATISTICS_NARROW_BAND_MSK)
  957. ? "enabled" : "disabled");
  958. return p;
  959. }
  960. static ssize_t iwl_dbgfs_ucode_rx_stats_read(struct file *file,
  961. char __user *user_buf,
  962. size_t count, loff_t *ppos)
  963. {
  964. struct iwl_priv *priv = file->private_data;
  965. int pos = 0;
  966. char *buf;
  967. int bufsz = sizeof(struct statistics_rx_phy) * 20 +
  968. sizeof(struct statistics_rx_non_phy) * 20 +
  969. sizeof(struct statistics_rx_ht_phy) * 20 + 400;
  970. ssize_t ret;
  971. struct statistics_rx_phy *ofdm, *accum_ofdm;
  972. struct statistics_rx_phy *cck, *accum_cck;
  973. struct statistics_rx_non_phy *general, *accum_general;
  974. struct statistics_rx_ht_phy *ht, *accum_ht;
  975. if (!iwl_is_alive(priv))
  976. return -EAGAIN;
  977. /* make request to uCode to retrieve statistics information */
  978. mutex_lock(&priv->mutex);
  979. ret = iwl_send_statistics_request(priv, CMD_SYNC, false);
  980. mutex_unlock(&priv->mutex);
  981. if (ret) {
  982. IWL_ERR(priv,
  983. "Error sending statistics request: %zd\n", ret);
  984. return -EAGAIN;
  985. }
  986. buf = kzalloc(bufsz, GFP_KERNEL);
  987. if (!buf) {
  988. IWL_ERR(priv, "Can not allocate Buffer\n");
  989. return -ENOMEM;
  990. }
  991. /* the statistic information display here is based on
  992. * the last statistics notification from uCode
  993. * might not reflect the current uCode activity
  994. */
  995. ofdm = &priv->statistics.rx.ofdm;
  996. cck = &priv->statistics.rx.cck;
  997. general = &priv->statistics.rx.general;
  998. ht = &priv->statistics.rx.ofdm_ht;
  999. accum_ofdm = &priv->accum_statistics.rx.ofdm;
  1000. accum_cck = &priv->accum_statistics.rx.cck;
  1001. accum_general = &priv->accum_statistics.rx.general;
  1002. accum_ht = &priv->accum_statistics.rx.ofdm_ht;
  1003. pos += iwl_dbgfs_statistics_flag(priv, buf, bufsz);
  1004. pos += scnprintf(buf + pos, bufsz - pos, "Statistics_Rx - OFDM:\n");
  1005. pos += scnprintf(buf + pos, bufsz - pos,
  1006. "\t\t\tcurrent\t\t\taccumulative\n");
  1007. pos += scnprintf(buf + pos, bufsz - pos, "ina_cnt:\t\t%u\t\t\t%u\n",
  1008. le32_to_cpu(ofdm->ina_cnt), accum_ofdm->ina_cnt);
  1009. pos += scnprintf(buf + pos, bufsz - pos, "fina_cnt:\t\t%u\t\t\t%u\n",
  1010. le32_to_cpu(ofdm->fina_cnt), accum_ofdm->fina_cnt);
  1011. pos += scnprintf(buf + pos, bufsz - pos, "plcp_err:\t\t%u\t\t\t%u\n",
  1012. le32_to_cpu(ofdm->plcp_err), accum_ofdm->plcp_err);
  1013. pos += scnprintf(buf + pos, bufsz - pos, "crc32_err:\t\t%u\t\t\t%u\n",
  1014. le32_to_cpu(ofdm->crc32_err), accum_ofdm->crc32_err);
  1015. pos += scnprintf(buf + pos, bufsz - pos,
  1016. "overrun_err:\t\t%u\t\t\t%u\n",
  1017. le32_to_cpu(ofdm->overrun_err),
  1018. accum_ofdm->overrun_err);
  1019. pos += scnprintf(buf + pos, bufsz - pos,
  1020. "early_overrun_err:\t%u\t\t\t%u\n",
  1021. le32_to_cpu(ofdm->early_overrun_err),
  1022. accum_ofdm->early_overrun_err);
  1023. pos += scnprintf(buf + pos, bufsz - pos, "crc32_good:\t\t%u\t\t\t%u\n",
  1024. le32_to_cpu(ofdm->crc32_good),
  1025. accum_ofdm->crc32_good);
  1026. pos += scnprintf(buf + pos, bufsz - pos,
  1027. "false_alarm_cnt:\t%u\t\t\t%u\n",
  1028. le32_to_cpu(ofdm->false_alarm_cnt),
  1029. accum_ofdm->false_alarm_cnt);
  1030. pos += scnprintf(buf + pos, bufsz - pos,
  1031. "fina_sync_err_cnt:\t%u\t\t\t%u\n",
  1032. le32_to_cpu(ofdm->fina_sync_err_cnt),
  1033. accum_ofdm->fina_sync_err_cnt);
  1034. pos += scnprintf(buf + pos, bufsz - pos,
  1035. "sfd_timeout:\t\t%u\t\t\t%u\n",
  1036. le32_to_cpu(ofdm->sfd_timeout),
  1037. accum_ofdm->sfd_timeout);
  1038. pos += scnprintf(buf + pos, bufsz - pos,
  1039. "fina_timeout:\t\t%u\t\t\t%u\n",
  1040. le32_to_cpu(ofdm->fina_timeout),
  1041. accum_ofdm->fina_timeout);
  1042. pos += scnprintf(buf + pos, bufsz - pos,
  1043. "unresponded_rts:\t%u\t\t\t%u\n",
  1044. le32_to_cpu(ofdm->unresponded_rts),
  1045. accum_ofdm->unresponded_rts);
  1046. pos += scnprintf(buf + pos, bufsz - pos,
  1047. "rxe_frame_lmt_ovrun:\t%u\t\t\t%u\n",
  1048. le32_to_cpu(ofdm->rxe_frame_limit_overrun),
  1049. accum_ofdm->rxe_frame_limit_overrun);
  1050. pos += scnprintf(buf + pos, bufsz - pos,
  1051. "sent_ack_cnt:\t\t%u\t\t\t%u\n",
  1052. le32_to_cpu(ofdm->sent_ack_cnt),
  1053. accum_ofdm->sent_ack_cnt);
  1054. pos += scnprintf(buf + pos, bufsz - pos,
  1055. "sent_cts_cnt:\t\t%u\t\t\t%u\n",
  1056. le32_to_cpu(ofdm->sent_cts_cnt),
  1057. accum_ofdm->sent_cts_cnt);
  1058. pos += scnprintf(buf + pos, bufsz - pos,
  1059. "sent_ba_rsp_cnt:\t%u\t\t\t%u\n",
  1060. le32_to_cpu(ofdm->sent_ba_rsp_cnt),
  1061. accum_ofdm->sent_ba_rsp_cnt);
  1062. pos += scnprintf(buf + pos, bufsz - pos,
  1063. "dsp_self_kill:\t\t%u\t\t\t%u\n",
  1064. le32_to_cpu(ofdm->dsp_self_kill),
  1065. accum_ofdm->dsp_self_kill);
  1066. pos += scnprintf(buf + pos, bufsz - pos,
  1067. "mh_format_err:\t\t%u\t\t\t%u\n",
  1068. le32_to_cpu(ofdm->mh_format_err),
  1069. accum_ofdm->mh_format_err);
  1070. pos += scnprintf(buf + pos, bufsz - pos,
  1071. "re_acq_main_rssi_sum:\t%u\t\t\t%u\n",
  1072. le32_to_cpu(ofdm->re_acq_main_rssi_sum),
  1073. accum_ofdm->re_acq_main_rssi_sum);
  1074. pos += scnprintf(buf + pos, bufsz - pos, "Statistics_Rx - CCK:\n");
  1075. pos += scnprintf(buf + pos, bufsz - pos,
  1076. "\t\t\tcurrent\t\t\taccumulative\n");
  1077. pos += scnprintf(buf + pos, bufsz - pos, "ina_cnt:\t\t%u\t\t\t%u\n",
  1078. le32_to_cpu(cck->ina_cnt), accum_cck->ina_cnt);
  1079. pos += scnprintf(buf + pos, bufsz - pos, "fina_cnt:\t\t%u\t\t\t%u\n",
  1080. le32_to_cpu(cck->fina_cnt), accum_cck->fina_cnt);
  1081. pos += scnprintf(buf + pos, bufsz - pos, "plcp_err:\t\t%u\t\t\t%u\n",
  1082. le32_to_cpu(cck->plcp_err), accum_cck->plcp_err);
  1083. pos += scnprintf(buf + pos, bufsz - pos, "crc32_err:\t\t%u\t\t\t%u\n",
  1084. le32_to_cpu(cck->crc32_err), accum_cck->crc32_err);
  1085. pos += scnprintf(buf + pos, bufsz - pos,
  1086. "overrun_err:\t\t%u\t\t\t%u\n",
  1087. le32_to_cpu(cck->overrun_err),
  1088. accum_cck->overrun_err);
  1089. pos += scnprintf(buf + pos, bufsz - pos,
  1090. "early_overrun_err:\t%u\t\t\t%u\n",
  1091. le32_to_cpu(cck->early_overrun_err),
  1092. accum_cck->early_overrun_err);
  1093. pos += scnprintf(buf + pos, bufsz - pos, "crc32_good:\t\t%u\t\t\t%u\n",
  1094. le32_to_cpu(cck->crc32_good), accum_cck->crc32_good);
  1095. pos += scnprintf(buf + pos, bufsz - pos,
  1096. "false_alarm_cnt:\t%u\t\t\t%u\n",
  1097. le32_to_cpu(cck->false_alarm_cnt),
  1098. accum_cck->false_alarm_cnt);
  1099. pos += scnprintf(buf + pos, bufsz - pos,
  1100. "fina_sync_err_cnt:\t%u\t\t\t%u\n",
  1101. le32_to_cpu(cck->fina_sync_err_cnt),
  1102. accum_cck->fina_sync_err_cnt);
  1103. pos += scnprintf(buf + pos, bufsz - pos,
  1104. "sfd_timeout:\t\t%u\t\t\t%u\n",
  1105. le32_to_cpu(cck->sfd_timeout),
  1106. accum_cck->sfd_timeout);
  1107. pos += scnprintf(buf + pos, bufsz - pos,
  1108. "fina_timeout:\t\t%u\t\t\t%u\n",
  1109. le32_to_cpu(cck->fina_timeout),
  1110. accum_cck->fina_timeout);
  1111. pos += scnprintf(buf + pos, bufsz - pos,
  1112. "unresponded_rts:\t%u\t\t\t%u\n",
  1113. le32_to_cpu(cck->unresponded_rts),
  1114. accum_cck->unresponded_rts);
  1115. pos += scnprintf(buf + pos, bufsz - pos,
  1116. "rxe_frame_lmt_ovrun:\t%u\t\t\t%u\n",
  1117. le32_to_cpu(cck->rxe_frame_limit_overrun),
  1118. accum_cck->rxe_frame_limit_overrun);
  1119. pos += scnprintf(buf + pos, bufsz - pos,
  1120. "sent_ack_cnt:\t\t%u\t\t\t%u\n",
  1121. le32_to_cpu(cck->sent_ack_cnt),
  1122. accum_cck->sent_ack_cnt);
  1123. pos += scnprintf(buf + pos, bufsz - pos,
  1124. "sent_cts_cnt:\t\t%u\t\t\t%u\n",
  1125. le32_to_cpu(cck->sent_cts_cnt),
  1126. accum_cck->sent_cts_cnt);
  1127. pos += scnprintf(buf + pos, bufsz - pos,
  1128. "sent_ba_rsp_cnt:\t%u\t\t\t%u\n",
  1129. le32_to_cpu(cck->sent_ba_rsp_cnt),
  1130. accum_cck->sent_ba_rsp_cnt);
  1131. pos += scnprintf(buf + pos, bufsz - pos,
  1132. "dsp_self_kill:\t\t%u\t\t\t%u\n",
  1133. le32_to_cpu(cck->dsp_self_kill),
  1134. accum_cck->dsp_self_kill);
  1135. pos += scnprintf(buf + pos, bufsz - pos,
  1136. "mh_format_err:\t\t%u\t\t\t%u\n",
  1137. le32_to_cpu(cck->mh_format_err),
  1138. accum_cck->mh_format_err);
  1139. pos += scnprintf(buf + pos, bufsz - pos,
  1140. "re_acq_main_rssi_sum:\t%u\t\t\t%u\n",
  1141. le32_to_cpu(cck->re_acq_main_rssi_sum),
  1142. accum_cck->re_acq_main_rssi_sum);
  1143. pos += scnprintf(buf + pos, bufsz - pos, "Statistics_Rx - GENERAL:\n");
  1144. pos += scnprintf(buf + pos, bufsz - pos,
  1145. "\t\t\tcurrent\t\t\taccumulative\n");
  1146. pos += scnprintf(buf + pos, bufsz - pos, "bogus_cts:\t\t%u\t\t\t%u\n",
  1147. le32_to_cpu(general->bogus_cts),
  1148. accum_general->bogus_cts);
  1149. pos += scnprintf(buf + pos, bufsz - pos, "bogus_ack:\t\t%u\t\t\t%u\n",
  1150. le32_to_cpu(general->bogus_ack),
  1151. accum_general->bogus_ack);
  1152. pos += scnprintf(buf + pos, bufsz - pos,
  1153. "non_bssid_frames:\t%u\t\t\t%u\n",
  1154. le32_to_cpu(general->non_bssid_frames),
  1155. accum_general->non_bssid_frames);
  1156. pos += scnprintf(buf + pos, bufsz - pos,
  1157. "filtered_frames:\t%u\t\t\t%u\n",
  1158. le32_to_cpu(general->filtered_frames),
  1159. accum_general->filtered_frames);
  1160. pos += scnprintf(buf + pos, bufsz - pos,
  1161. "non_channel_beacons:\t%u\t\t\t%u\n",
  1162. le32_to_cpu(general->non_channel_beacons),
  1163. accum_general->non_channel_beacons);
  1164. pos += scnprintf(buf + pos, bufsz - pos,
  1165. "channel_beacons:\t%u\t\t\t%u\n",
  1166. le32_to_cpu(general->channel_beacons),
  1167. accum_general->channel_beacons);
  1168. pos += scnprintf(buf + pos, bufsz - pos,
  1169. "num_missed_bcon:\t%u\t\t\t%u\n",
  1170. le32_to_cpu(general->num_missed_bcon),
  1171. accum_general->num_missed_bcon);
  1172. pos += scnprintf(buf + pos, bufsz - pos,
  1173. "adc_rx_saturation_time:\t%u\t\t\t%u\n",
  1174. le32_to_cpu(general->adc_rx_saturation_time),
  1175. accum_general->adc_rx_saturation_time);
  1176. pos += scnprintf(buf + pos, bufsz - pos,
  1177. "ina_detect_search_tm:\t%u\t\t\t%u\n",
  1178. le32_to_cpu(general->ina_detection_search_time),
  1179. accum_general->ina_detection_search_time);
  1180. pos += scnprintf(buf + pos, bufsz - pos,
  1181. "beacon_silence_rssi_a:\t%u\t\t\t%u\n",
  1182. le32_to_cpu(general->beacon_silence_rssi_a),
  1183. accum_general->beacon_silence_rssi_a);
  1184. pos += scnprintf(buf + pos, bufsz - pos,
  1185. "beacon_silence_rssi_b:\t%u\t\t\t%u\n",
  1186. le32_to_cpu(general->beacon_silence_rssi_b),
  1187. accum_general->beacon_silence_rssi_b);
  1188. pos += scnprintf(buf + pos, bufsz - pos,
  1189. "beacon_silence_rssi_c:\t%u\t\t\t%u\n",
  1190. le32_to_cpu(general->beacon_silence_rssi_c),
  1191. accum_general->beacon_silence_rssi_c);
  1192. pos += scnprintf(buf + pos, bufsz - pos,
  1193. "interference_data_flag:\t%u\t\t\t%u\n",
  1194. le32_to_cpu(general->interference_data_flag),
  1195. accum_general->interference_data_flag);
  1196. pos += scnprintf(buf + pos, bufsz - pos,
  1197. "channel_load:\t\t%u\t\t\t%u\n",
  1198. le32_to_cpu(general->channel_load),
  1199. accum_general->channel_load);
  1200. pos += scnprintf(buf + pos, bufsz - pos,
  1201. "dsp_false_alarms:\t%u\t\t\t%u\n",
  1202. le32_to_cpu(general->dsp_false_alarms),
  1203. accum_general->dsp_false_alarms);
  1204. pos += scnprintf(buf + pos, bufsz - pos,
  1205. "beacon_rssi_a:\t\t%u\t\t\t%u\n",
  1206. le32_to_cpu(general->beacon_rssi_a),
  1207. accum_general->beacon_rssi_a);
  1208. pos += scnprintf(buf + pos, bufsz - pos,
  1209. "beacon_rssi_b:\t\t%u\t\t\t%u\n",
  1210. le32_to_cpu(general->beacon_rssi_b),
  1211. accum_general->beacon_rssi_b);
  1212. pos += scnprintf(buf + pos, bufsz - pos,
  1213. "beacon_rssi_c:\t\t%u\t\t\t%u\n",
  1214. le32_to_cpu(general->beacon_rssi_c),
  1215. accum_general->beacon_rssi_c);
  1216. pos += scnprintf(buf + pos, bufsz - pos,
  1217. "beacon_energy_a:\t%u\t\t\t%u\n",
  1218. le32_to_cpu(general->beacon_energy_a),
  1219. accum_general->beacon_energy_a);
  1220. pos += scnprintf(buf + pos, bufsz - pos,
  1221. "beacon_energy_b:\t%u\t\t\t%u\n",
  1222. le32_to_cpu(general->beacon_energy_b),
  1223. accum_general->beacon_energy_b);
  1224. pos += scnprintf(buf + pos, bufsz - pos,
  1225. "beacon_energy_c:\t%u\t\t\t%u\n",
  1226. le32_to_cpu(general->beacon_energy_c),
  1227. accum_general->beacon_energy_c);
  1228. pos += scnprintf(buf + pos, bufsz - pos, "Statistics_Rx - OFDM_HT:\n");
  1229. pos += scnprintf(buf + pos, bufsz - pos,
  1230. "\t\t\tcurrent\t\t\taccumulative\n");
  1231. pos += scnprintf(buf + pos, bufsz - pos, "plcp_err:\t\t%u\t\t\t%u\n",
  1232. le32_to_cpu(ht->plcp_err), accum_ht->plcp_err);
  1233. pos += scnprintf(buf + pos, bufsz - pos,
  1234. "overrun_err:\t\t%u\t\t\t%u\n",
  1235. le32_to_cpu(ht->overrun_err), accum_ht->overrun_err);
  1236. pos += scnprintf(buf + pos, bufsz - pos,
  1237. "early_overrun_err:\t%u\t\t\t%u\n",
  1238. le32_to_cpu(ht->early_overrun_err),
  1239. accum_ht->early_overrun_err);
  1240. pos += scnprintf(buf + pos, bufsz - pos, "crc32_good:\t\t%u\t\t\t%u\n",
  1241. le32_to_cpu(ht->crc32_good), accum_ht->crc32_good);
  1242. pos += scnprintf(buf + pos, bufsz - pos, "crc32_err:\t\t%u\t\t\t%u\n",
  1243. le32_to_cpu(ht->crc32_err), accum_ht->crc32_err);
  1244. pos += scnprintf(buf + pos, bufsz - pos,
  1245. "mh_format_err:\t\t%u\t\t\t%u\n",
  1246. le32_to_cpu(ht->mh_format_err),
  1247. accum_ht->mh_format_err);
  1248. pos += scnprintf(buf + pos, bufsz - pos,
  1249. "agg_crc32_good:\t\t%u\t\t\t%u\n",
  1250. le32_to_cpu(ht->agg_crc32_good),
  1251. accum_ht->agg_crc32_good);
  1252. pos += scnprintf(buf + pos, bufsz - pos,
  1253. "agg_mpdu_cnt:\t\t%u\t\t\t%u\n",
  1254. le32_to_cpu(ht->agg_mpdu_cnt),
  1255. accum_ht->agg_mpdu_cnt);
  1256. pos += scnprintf(buf + pos, bufsz - pos, "agg_cnt:\t\t%u\t\t\t%u\n",
  1257. le32_to_cpu(ht->agg_cnt), accum_ht->agg_cnt);
  1258. pos += scnprintf(buf + pos, bufsz - pos, "unsupport_mcs:\t\t%u\t\t\t%u\n",
  1259. le32_to_cpu(ht->unsupport_mcs),
  1260. accum_ht->unsupport_mcs);
  1261. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  1262. kfree(buf);
  1263. return ret;
  1264. }
  1265. static ssize_t iwl_dbgfs_ucode_tx_stats_read(struct file *file,
  1266. char __user *user_buf,
  1267. size_t count, loff_t *ppos)
  1268. {
  1269. struct iwl_priv *priv = file->private_data;
  1270. int pos = 0;
  1271. char *buf;
  1272. int bufsz = (sizeof(struct statistics_tx) * 24) + 250;
  1273. ssize_t ret;
  1274. struct statistics_tx *tx, *accum_tx;
  1275. if (!iwl_is_alive(priv))
  1276. return -EAGAIN;
  1277. /* make request to uCode to retrieve statistics information */
  1278. mutex_lock(&priv->mutex);
  1279. ret = iwl_send_statistics_request(priv, CMD_SYNC, false);
  1280. mutex_unlock(&priv->mutex);
  1281. if (ret) {
  1282. IWL_ERR(priv,
  1283. "Error sending statistics request: %zd\n", ret);
  1284. return -EAGAIN;
  1285. }
  1286. buf = kzalloc(bufsz, GFP_KERNEL);
  1287. if (!buf) {
  1288. IWL_ERR(priv, "Can not allocate Buffer\n");
  1289. return -ENOMEM;
  1290. }
  1291. /* the statistic information display here is based on
  1292. * the last statistics notification from uCode
  1293. * might not reflect the current uCode activity
  1294. */
  1295. tx = &priv->statistics.tx;
  1296. accum_tx = &priv->accum_statistics.tx;
  1297. pos += iwl_dbgfs_statistics_flag(priv, buf, bufsz);
  1298. pos += scnprintf(buf + pos, bufsz - pos, "Statistics_Tx:\n");
  1299. pos += scnprintf(buf + pos, bufsz - pos,
  1300. "\t\t\tcurrent\t\t\taccumulative\n");
  1301. pos += scnprintf(buf + pos, bufsz - pos, "preamble:\t\t\t%u\t\t\t%u\n",
  1302. le32_to_cpu(tx->preamble_cnt),
  1303. accum_tx->preamble_cnt);
  1304. pos += scnprintf(buf + pos, bufsz - pos,
  1305. "rx_detected_cnt:\t\t%u\t\t\t%u\n",
  1306. le32_to_cpu(tx->rx_detected_cnt),
  1307. accum_tx->rx_detected_cnt);
  1308. pos += scnprintf(buf + pos, bufsz - pos,
  1309. "bt_prio_defer_cnt:\t\t%u\t\t\t%u\n",
  1310. le32_to_cpu(tx->bt_prio_defer_cnt),
  1311. accum_tx->bt_prio_defer_cnt);
  1312. pos += scnprintf(buf + pos, bufsz - pos,
  1313. "bt_prio_kill_cnt:\t\t%u\t\t\t%u\n",
  1314. le32_to_cpu(tx->bt_prio_kill_cnt),
  1315. accum_tx->bt_prio_kill_cnt);
  1316. pos += scnprintf(buf + pos, bufsz - pos,
  1317. "few_bytes_cnt:\t\t\t%u\t\t\t%u\n",
  1318. le32_to_cpu(tx->few_bytes_cnt),
  1319. accum_tx->few_bytes_cnt);
  1320. pos += scnprintf(buf + pos, bufsz - pos,
  1321. "cts_timeout:\t\t\t%u\t\t\t%u\n",
  1322. le32_to_cpu(tx->cts_timeout), accum_tx->cts_timeout);
  1323. pos += scnprintf(buf + pos, bufsz - pos,
  1324. "ack_timeout:\t\t\t%u\t\t\t%u\n",
  1325. le32_to_cpu(tx->ack_timeout),
  1326. accum_tx->ack_timeout);
  1327. pos += scnprintf(buf + pos, bufsz - pos,
  1328. "expected_ack_cnt:\t\t%u\t\t\t%u\n",
  1329. le32_to_cpu(tx->expected_ack_cnt),
  1330. accum_tx->expected_ack_cnt);
  1331. pos += scnprintf(buf + pos, bufsz - pos,
  1332. "actual_ack_cnt:\t\t\t%u\t\t\t%u\n",
  1333. le32_to_cpu(tx->actual_ack_cnt),
  1334. accum_tx->actual_ack_cnt);
  1335. pos += scnprintf(buf + pos, bufsz - pos,
  1336. "dump_msdu_cnt:\t\t\t%u\t\t\t%u\n",
  1337. le32_to_cpu(tx->dump_msdu_cnt),
  1338. accum_tx->dump_msdu_cnt);
  1339. pos += scnprintf(buf + pos, bufsz - pos,
  1340. "abort_nxt_frame_mismatch:"
  1341. "\t%u\t\t\t%u\n",
  1342. le32_to_cpu(tx->burst_abort_next_frame_mismatch_cnt),
  1343. accum_tx->burst_abort_next_frame_mismatch_cnt);
  1344. pos += scnprintf(buf + pos, bufsz - pos,
  1345. "abort_missing_nxt_frame:"
  1346. "\t%u\t\t\t%u\n",
  1347. le32_to_cpu(tx->burst_abort_missing_next_frame_cnt),
  1348. accum_tx->burst_abort_missing_next_frame_cnt);
  1349. pos += scnprintf(buf + pos, bufsz - pos,
  1350. "cts_timeout_collision:\t\t%u\t\t\t%u\n",
  1351. le32_to_cpu(tx->cts_timeout_collision),
  1352. accum_tx->cts_timeout_collision);
  1353. pos += scnprintf(buf + pos, bufsz - pos,
  1354. "ack_ba_timeout_collision:\t%u\t\t\t%u\n",
  1355. le32_to_cpu(tx->ack_or_ba_timeout_collision),
  1356. accum_tx->ack_or_ba_timeout_collision);
  1357. pos += scnprintf(buf + pos, bufsz - pos,
  1358. "agg ba_timeout:\t\t\t%u\t\t\t%u\n",
  1359. le32_to_cpu(tx->agg.ba_timeout),
  1360. accum_tx->agg.ba_timeout);
  1361. pos += scnprintf(buf + pos, bufsz - pos,
  1362. "agg ba_resched_frames:\t\t%u\t\t\t%u\n",
  1363. le32_to_cpu(tx->agg.ba_reschedule_frames),
  1364. accum_tx->agg.ba_reschedule_frames);
  1365. pos += scnprintf(buf + pos, bufsz - pos,
  1366. "agg scd_query_agg_frame:\t%u\t\t\t%u\n",
  1367. le32_to_cpu(tx->agg.scd_query_agg_frame_cnt),
  1368. accum_tx->agg.scd_query_agg_frame_cnt);
  1369. pos += scnprintf(buf + pos, bufsz - pos,
  1370. "agg scd_query_no_agg:\t\t%u\t\t\t%u\n",
  1371. le32_to_cpu(tx->agg.scd_query_no_agg),
  1372. accum_tx->agg.scd_query_no_agg);
  1373. pos += scnprintf(buf + pos, bufsz - pos,
  1374. "agg scd_query_agg:\t\t%u\t\t\t%u\n",
  1375. le32_to_cpu(tx->agg.scd_query_agg),
  1376. accum_tx->agg.scd_query_agg);
  1377. pos += scnprintf(buf + pos, bufsz - pos,
  1378. "agg scd_query_mismatch:\t\t%u\t\t\t%u\n",
  1379. le32_to_cpu(tx->agg.scd_query_mismatch),
  1380. accum_tx->agg.scd_query_mismatch);
  1381. pos += scnprintf(buf + pos, bufsz - pos,
  1382. "agg frame_not_ready:\t\t%u\t\t\t%u\n",
  1383. le32_to_cpu(tx->agg.frame_not_ready),
  1384. accum_tx->agg.frame_not_ready);
  1385. pos += scnprintf(buf + pos, bufsz - pos,
  1386. "agg underrun:\t\t\t%u\t\t\t%u\n",
  1387. le32_to_cpu(tx->agg.underrun),
  1388. accum_tx->agg.underrun);
  1389. pos += scnprintf(buf + pos, bufsz - pos,
  1390. "agg bt_prio_kill:\t\t%u\t\t\t%u\n",
  1391. le32_to_cpu(tx->agg.bt_prio_kill),
  1392. accum_tx->agg.bt_prio_kill);
  1393. pos += scnprintf(buf + pos, bufsz - pos,
  1394. "agg rx_ba_rsp_cnt:\t\t%u\t\t\t%u\n",
  1395. le32_to_cpu(tx->agg.rx_ba_rsp_cnt),
  1396. accum_tx->agg.rx_ba_rsp_cnt);
  1397. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  1398. kfree(buf);
  1399. return ret;
  1400. }
  1401. static ssize_t iwl_dbgfs_ucode_general_stats_read(struct file *file,
  1402. char __user *user_buf,
  1403. size_t count, loff_t *ppos)
  1404. {
  1405. struct iwl_priv *priv = file->private_data;
  1406. int pos = 0;
  1407. char *buf;
  1408. int bufsz = sizeof(struct statistics_general) * 4 + 250;
  1409. ssize_t ret;
  1410. struct statistics_general *general, *accum_general;
  1411. struct statistics_dbg *dbg, *accum_dbg;
  1412. struct statistics_div *div, *accum_div;
  1413. if (!iwl_is_alive(priv))
  1414. return -EAGAIN;
  1415. /* make request to uCode to retrieve statistics information */
  1416. mutex_lock(&priv->mutex);
  1417. ret = iwl_send_statistics_request(priv, CMD_SYNC, false);
  1418. mutex_unlock(&priv->mutex);
  1419. if (ret) {
  1420. IWL_ERR(priv,
  1421. "Error sending statistics request: %zd\n", ret);
  1422. return -EAGAIN;
  1423. }
  1424. buf = kzalloc(bufsz, GFP_KERNEL);
  1425. if (!buf) {
  1426. IWL_ERR(priv, "Can not allocate Buffer\n");
  1427. return -ENOMEM;
  1428. }
  1429. /* the statistic information display here is based on
  1430. * the last statistics notification from uCode
  1431. * might not reflect the current uCode activity
  1432. */
  1433. general = &priv->statistics.general;
  1434. dbg = &priv->statistics.general.dbg;
  1435. div = &priv->statistics.general.div;
  1436. accum_general = &priv->accum_statistics.general;
  1437. accum_dbg = &priv->accum_statistics.general.dbg;
  1438. accum_div = &priv->accum_statistics.general.div;
  1439. pos += iwl_dbgfs_statistics_flag(priv, buf, bufsz);
  1440. pos += scnprintf(buf + pos, bufsz - pos, "Statistics_General:\n");
  1441. pos += scnprintf(buf + pos, bufsz - pos,
  1442. "\t\t\tcurrent\t\t\taccumulative\n");
  1443. pos += scnprintf(buf + pos, bufsz - pos, "temperature:\t\t\t%u\n",
  1444. le32_to_cpu(general->temperature));
  1445. pos += scnprintf(buf + pos, bufsz - pos, "temperature_m:\t\t\t%u\n",
  1446. le32_to_cpu(general->temperature_m));
  1447. pos += scnprintf(buf + pos, bufsz - pos,
  1448. "burst_check:\t\t\t%u\t\t\t%u\n",
  1449. le32_to_cpu(dbg->burst_check),
  1450. accum_dbg->burst_check);
  1451. pos += scnprintf(buf + pos, bufsz - pos,
  1452. "burst_count:\t\t\t%u\t\t\t%u\n",
  1453. le32_to_cpu(dbg->burst_count),
  1454. accum_dbg->burst_count);
  1455. pos += scnprintf(buf + pos, bufsz - pos,
  1456. "sleep_time:\t\t\t%u\t\t\t%u\n",
  1457. le32_to_cpu(general->sleep_time),
  1458. accum_general->sleep_time);
  1459. pos += scnprintf(buf + pos, bufsz - pos,
  1460. "slots_out:\t\t\t%u\t\t\t%u\n",
  1461. le32_to_cpu(general->slots_out),
  1462. accum_general->slots_out);
  1463. pos += scnprintf(buf + pos, bufsz - pos,
  1464. "slots_idle:\t\t\t%u\t\t\t%u\n",
  1465. le32_to_cpu(general->slots_idle),
  1466. accum_general->slots_idle);
  1467. pos += scnprintf(buf + pos, bufsz - pos, "ttl_timestamp:\t\t\t%u\n",
  1468. le32_to_cpu(general->ttl_timestamp));
  1469. pos += scnprintf(buf + pos, bufsz - pos, "tx_on_a:\t\t\t%u\t\t\t%u\n",
  1470. le32_to_cpu(div->tx_on_a), accum_div->tx_on_a);
  1471. pos += scnprintf(buf + pos, bufsz - pos, "tx_on_b:\t\t\t%u\t\t\t%u\n",
  1472. le32_to_cpu(div->tx_on_b), accum_div->tx_on_b);
  1473. pos += scnprintf(buf + pos, bufsz - pos,
  1474. "exec_time:\t\t\t%u\t\t\t%u\n",
  1475. le32_to_cpu(div->exec_time), accum_div->exec_time);
  1476. pos += scnprintf(buf + pos, bufsz - pos,
  1477. "probe_time:\t\t\t%u\t\t\t%u\n",
  1478. le32_to_cpu(div->probe_time), accum_div->probe_time);
  1479. pos += scnprintf(buf + pos, bufsz - pos,
  1480. "rx_enable_counter:\t\t%u\t\t\t%u\n",
  1481. le32_to_cpu(general->rx_enable_counter),
  1482. accum_general->rx_enable_counter);
  1483. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  1484. kfree(buf);
  1485. return ret;
  1486. }
  1487. static ssize_t iwl_dbgfs_sensitivity_read(struct file *file,
  1488. char __user *user_buf,
  1489. size_t count, loff_t *ppos) {
  1490. struct iwl_priv *priv = file->private_data;
  1491. int pos = 0;
  1492. int cnt = 0;
  1493. char *buf;
  1494. int bufsz = sizeof(struct iwl_sensitivity_data) * 4 + 100;
  1495. ssize_t ret;
  1496. struct iwl_sensitivity_data *data;
  1497. data = &priv->sensitivity_data;
  1498. buf = kzalloc(bufsz, GFP_KERNEL);
  1499. if (!buf) {
  1500. IWL_ERR(priv, "Can not allocate Buffer\n");
  1501. return -ENOMEM;
  1502. }
  1503. pos += scnprintf(buf + pos, bufsz - pos, "auto_corr_ofdm:\t\t\t %u\n",
  1504. data->auto_corr_ofdm);
  1505. pos += scnprintf(buf + pos, bufsz - pos,
  1506. "auto_corr_ofdm_mrc:\t\t %u\n",
  1507. data->auto_corr_ofdm_mrc);
  1508. pos += scnprintf(buf + pos, bufsz - pos, "auto_corr_ofdm_x1:\t\t %u\n",
  1509. data->auto_corr_ofdm_x1);
  1510. pos += scnprintf(buf + pos, bufsz - pos,
  1511. "auto_corr_ofdm_mrc_x1:\t\t %u\n",
  1512. data->auto_corr_ofdm_mrc_x1);
  1513. pos += scnprintf(buf + pos, bufsz - pos, "auto_corr_cck:\t\t\t %u\n",
  1514. data->auto_corr_cck);
  1515. pos += scnprintf(buf + pos, bufsz - pos, "auto_corr_cck_mrc:\t\t %u\n",
  1516. data->auto_corr_cck_mrc);
  1517. pos += scnprintf(buf + pos, bufsz - pos,
  1518. "last_bad_plcp_cnt_ofdm:\t\t %u\n",
  1519. data->last_bad_plcp_cnt_ofdm);
  1520. pos += scnprintf(buf + pos, bufsz - pos, "last_fa_cnt_ofdm:\t\t %u\n",
  1521. data->last_fa_cnt_ofdm);
  1522. pos += scnprintf(buf + pos, bufsz - pos,
  1523. "last_bad_plcp_cnt_cck:\t\t %u\n",
  1524. data->last_bad_plcp_cnt_cck);
  1525. pos += scnprintf(buf + pos, bufsz - pos, "last_fa_cnt_cck:\t\t %u\n",
  1526. data->last_fa_cnt_cck);
  1527. pos += scnprintf(buf + pos, bufsz - pos, "nrg_curr_state:\t\t\t %u\n",
  1528. data->nrg_curr_state);
  1529. pos += scnprintf(buf + pos, bufsz - pos, "nrg_prev_state:\t\t\t %u\n",
  1530. data->nrg_prev_state);
  1531. pos += scnprintf(buf + pos, bufsz - pos, "nrg_value:\t\t\t");
  1532. for (cnt = 0; cnt < 10; cnt++) {
  1533. pos += scnprintf(buf + pos, bufsz - pos, " %u",
  1534. data->nrg_value[cnt]);
  1535. }
  1536. pos += scnprintf(buf + pos, bufsz - pos, "\n");
  1537. pos += scnprintf(buf + pos, bufsz - pos, "nrg_silence_rssi:\t\t");
  1538. for (cnt = 0; cnt < NRG_NUM_PREV_STAT_L; cnt++) {
  1539. pos += scnprintf(buf + pos, bufsz - pos, " %u",
  1540. data->nrg_silence_rssi[cnt]);
  1541. }
  1542. pos += scnprintf(buf + pos, bufsz - pos, "\n");
  1543. pos += scnprintf(buf + pos, bufsz - pos, "nrg_silence_ref:\t\t %u\n",
  1544. data->nrg_silence_ref);
  1545. pos += scnprintf(buf + pos, bufsz - pos, "nrg_energy_idx:\t\t\t %u\n",
  1546. data->nrg_energy_idx);
  1547. pos += scnprintf(buf + pos, bufsz - pos, "nrg_silence_idx:\t\t %u\n",
  1548. data->nrg_silence_idx);
  1549. pos += scnprintf(buf + pos, bufsz - pos, "nrg_th_cck:\t\t\t %u\n",
  1550. data->nrg_th_cck);
  1551. pos += scnprintf(buf + pos, bufsz - pos,
  1552. "nrg_auto_corr_silence_diff:\t %u\n",
  1553. data->nrg_auto_corr_silence_diff);
  1554. pos += scnprintf(buf + pos, bufsz - pos, "num_in_cck_no_fa:\t\t %u\n",
  1555. data->num_in_cck_no_fa);
  1556. pos += scnprintf(buf + pos, bufsz - pos, "nrg_th_ofdm:\t\t\t %u\n",
  1557. data->nrg_th_ofdm);
  1558. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  1559. kfree(buf);
  1560. return ret;
  1561. }
  1562. static ssize_t iwl_dbgfs_chain_noise_read(struct file *file,
  1563. char __user *user_buf,
  1564. size_t count, loff_t *ppos) {
  1565. struct iwl_priv *priv = file->private_data;
  1566. int pos = 0;
  1567. int cnt = 0;
  1568. char *buf;
  1569. int bufsz = sizeof(struct iwl_chain_noise_data) * 4 + 100;
  1570. ssize_t ret;
  1571. struct iwl_chain_noise_data *data;
  1572. data = &priv->chain_noise_data;
  1573. buf = kzalloc(bufsz, GFP_KERNEL);
  1574. if (!buf) {
  1575. IWL_ERR(priv, "Can not allocate Buffer\n");
  1576. return -ENOMEM;
  1577. }
  1578. pos += scnprintf(buf + pos, bufsz - pos, "active_chains:\t\t\t %u\n",
  1579. data->active_chains);
  1580. pos += scnprintf(buf + pos, bufsz - pos, "chain_noise_a:\t\t\t %u\n",
  1581. data->chain_noise_a);
  1582. pos += scnprintf(buf + pos, bufsz - pos, "chain_noise_b:\t\t\t %u\n",
  1583. data->chain_noise_b);
  1584. pos += scnprintf(buf + pos, bufsz - pos, "chain_noise_c:\t\t\t %u\n",
  1585. data->chain_noise_c);
  1586. pos += scnprintf(buf + pos, bufsz - pos, "chain_signal_a:\t\t\t %u\n",
  1587. data->chain_signal_a);
  1588. pos += scnprintf(buf + pos, bufsz - pos, "chain_signal_b:\t\t\t %u\n",
  1589. data->chain_signal_b);
  1590. pos += scnprintf(buf + pos, bufsz - pos, "chain_signal_c:\t\t\t %u\n",
  1591. data->chain_signal_c);
  1592. pos += scnprintf(buf + pos, bufsz - pos, "beacon_count:\t\t\t %u\n",
  1593. data->beacon_count);
  1594. pos += scnprintf(buf + pos, bufsz - pos, "disconn_array:\t\t\t");
  1595. for (cnt = 0; cnt < NUM_RX_CHAINS; cnt++) {
  1596. pos += scnprintf(buf + pos, bufsz - pos, " %u",
  1597. data->disconn_array[cnt]);
  1598. }
  1599. pos += scnprintf(buf + pos, bufsz - pos, "\n");
  1600. pos += scnprintf(buf + pos, bufsz - pos, "delta_gain_code:\t\t");
  1601. for (cnt = 0; cnt < NUM_RX_CHAINS; cnt++) {
  1602. pos += scnprintf(buf + pos, bufsz - pos, " %u",
  1603. data->delta_gain_code[cnt]);
  1604. }
  1605. pos += scnprintf(buf + pos, bufsz - pos, "\n");
  1606. pos += scnprintf(buf + pos, bufsz - pos, "radio_write:\t\t\t %u\n",
  1607. data->radio_write);
  1608. pos += scnprintf(buf + pos, bufsz - pos, "state:\t\t\t\t %u\n",
  1609. data->state);
  1610. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  1611. kfree(buf);
  1612. return ret;
  1613. }
  1614. static ssize_t iwl_dbgfs_tx_power_read(struct file *file,
  1615. char __user *user_buf,
  1616. size_t count, loff_t *ppos) {
  1617. struct iwl_priv *priv = file->private_data;
  1618. char buf[128];
  1619. int pos = 0;
  1620. ssize_t ret;
  1621. const size_t bufsz = sizeof(buf);
  1622. struct statistics_tx *tx;
  1623. if (!iwl_is_alive(priv))
  1624. pos += scnprintf(buf + pos, bufsz - pos, "N/A\n");
  1625. else {
  1626. /* make request to uCode to retrieve statistics information */
  1627. mutex_lock(&priv->mutex);
  1628. ret = iwl_send_statistics_request(priv, CMD_SYNC, false);
  1629. mutex_unlock(&priv->mutex);
  1630. if (ret) {
  1631. IWL_ERR(priv, "Error sending statistics request: %zd\n",
  1632. ret);
  1633. return -EAGAIN;
  1634. }
  1635. tx = &priv->statistics.tx;
  1636. if (tx->tx_power.ant_a ||
  1637. tx->tx_power.ant_b ||
  1638. tx->tx_power.ant_c) {
  1639. pos += scnprintf(buf + pos, bufsz - pos,
  1640. "tx power: (1/2 dB step)\n");
  1641. if ((priv->cfg->valid_tx_ant & ANT_A) &&
  1642. tx->tx_power.ant_a)
  1643. pos += scnprintf(buf + pos, bufsz - pos,
  1644. "\tantenna A: 0x%X\n",
  1645. tx->tx_power.ant_a);
  1646. if ((priv->cfg->valid_tx_ant & ANT_B) &&
  1647. tx->tx_power.ant_b)
  1648. pos += scnprintf(buf + pos, bufsz - pos,
  1649. "\tantenna B: 0x%X\n",
  1650. tx->tx_power.ant_b);
  1651. if ((priv->cfg->valid_tx_ant & ANT_C) &&
  1652. tx->tx_power.ant_c)
  1653. pos += scnprintf(buf + pos, bufsz - pos,
  1654. "\tantenna C: 0x%X\n",
  1655. tx->tx_power.ant_c);
  1656. } else
  1657. pos += scnprintf(buf + pos, bufsz - pos, "N/A\n");
  1658. }
  1659. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  1660. }
  1661. static ssize_t iwl_dbgfs_power_save_status_read(struct file *file,
  1662. char __user *user_buf,
  1663. size_t count, loff_t *ppos)
  1664. {
  1665. struct iwl_priv *priv = file->private_data;
  1666. char buf[60];
  1667. int pos = 0;
  1668. const size_t bufsz = sizeof(buf);
  1669. u32 pwrsave_status;
  1670. pwrsave_status = iwl_read32(priv, CSR_GP_CNTRL) &
  1671. CSR_GP_REG_POWER_SAVE_STATUS_MSK;
  1672. pos += scnprintf(buf + pos, bufsz - pos, "Power Save Status: ");
  1673. pos += scnprintf(buf + pos, bufsz - pos, "%s\n",
  1674. (pwrsave_status == CSR_GP_REG_NO_POWER_SAVE) ? "none" :
  1675. (pwrsave_status == CSR_GP_REG_MAC_POWER_SAVE) ? "MAC" :
  1676. (pwrsave_status == CSR_GP_REG_PHY_POWER_SAVE) ? "PHY" :
  1677. "error");
  1678. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  1679. }
  1680. static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
  1681. const char __user *user_buf,
  1682. size_t count, loff_t *ppos)
  1683. {
  1684. struct iwl_priv *priv = file->private_data;
  1685. char buf[8];
  1686. int buf_size;
  1687. int clear;
  1688. memset(buf, 0, sizeof(buf));
  1689. buf_size = min(count, sizeof(buf) - 1);
  1690. if (copy_from_user(buf, user_buf, buf_size))
  1691. return -EFAULT;
  1692. if (sscanf(buf, "%d", &clear) != 1)
  1693. return -EFAULT;
  1694. /* make request to uCode to retrieve statistics information */
  1695. mutex_lock(&priv->mutex);
  1696. iwl_send_statistics_request(priv, CMD_SYNC, true);
  1697. mutex_unlock(&priv->mutex);
  1698. return count;
  1699. }
  1700. static ssize_t iwl_dbgfs_csr_write(struct file *file,
  1701. const char __user *user_buf,
  1702. size_t count, loff_t *ppos)
  1703. {
  1704. struct iwl_priv *priv = file->private_data;
  1705. char buf[8];
  1706. int buf_size;
  1707. int csr;
  1708. memset(buf, 0, sizeof(buf));
  1709. buf_size = min(count, sizeof(buf) - 1);
  1710. if (copy_from_user(buf, user_buf, buf_size))
  1711. return -EFAULT;
  1712. if (sscanf(buf, "%d", &csr) != 1)
  1713. return -EFAULT;
  1714. if (priv->cfg->ops->lib->dump_csr)
  1715. priv->cfg->ops->lib->dump_csr(priv);
  1716. return count;
  1717. }
  1718. static ssize_t iwl_dbgfs_ucode_tracing_read(struct file *file,
  1719. char __user *user_buf,
  1720. size_t count, loff_t *ppos) {
  1721. struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
  1722. int pos = 0;
  1723. char buf[128];
  1724. const size_t bufsz = sizeof(buf);
  1725. ssize_t ret;
  1726. pos += scnprintf(buf + pos, bufsz - pos, "ucode trace timer is %s\n",
  1727. priv->event_log.ucode_trace ? "On" : "Off");
  1728. pos += scnprintf(buf + pos, bufsz - pos, "non_wraps_count:\t\t %u\n",
  1729. priv->event_log.non_wraps_count);
  1730. pos += scnprintf(buf + pos, bufsz - pos, "wraps_once_count:\t\t %u\n",
  1731. priv->event_log.wraps_once_count);
  1732. pos += scnprintf(buf + pos, bufsz - pos, "wraps_more_count:\t\t %u\n",
  1733. priv->event_log.wraps_more_count);
  1734. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  1735. return ret;
  1736. }
  1737. static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
  1738. const char __user *user_buf,
  1739. size_t count, loff_t *ppos)
  1740. {
  1741. struct iwl_priv *priv = file->private_data;
  1742. char buf[8];
  1743. int buf_size;
  1744. int trace;
  1745. memset(buf, 0, sizeof(buf));
  1746. buf_size = min(count, sizeof(buf) - 1);
  1747. if (copy_from_user(buf, user_buf, buf_size))
  1748. return -EFAULT;
  1749. if (sscanf(buf, "%d", &trace) != 1)
  1750. return -EFAULT;
  1751. if (trace) {
  1752. priv->event_log.ucode_trace = true;
  1753. /* schedule the ucode timer to occur in UCODE_TRACE_PERIOD */
  1754. mod_timer(&priv->ucode_trace,
  1755. jiffies + msecs_to_jiffies(UCODE_TRACE_PERIOD));
  1756. } else {
  1757. priv->event_log.ucode_trace = false;
  1758. del_timer_sync(&priv->ucode_trace);
  1759. }
  1760. return count;
  1761. }
  1762. DEBUGFS_READ_FILE_OPS(rx_statistics);
  1763. DEBUGFS_READ_FILE_OPS(tx_statistics);
  1764. DEBUGFS_READ_WRITE_FILE_OPS(traffic_log);
  1765. DEBUGFS_READ_FILE_OPS(rx_queue);
  1766. DEBUGFS_READ_FILE_OPS(tx_queue);
  1767. DEBUGFS_READ_FILE_OPS(ucode_rx_stats);
  1768. DEBUGFS_READ_FILE_OPS(ucode_tx_stats);
  1769. DEBUGFS_READ_FILE_OPS(ucode_general_stats);
  1770. DEBUGFS_READ_FILE_OPS(sensitivity);
  1771. DEBUGFS_READ_FILE_OPS(chain_noise);
  1772. DEBUGFS_READ_FILE_OPS(tx_power);
  1773. DEBUGFS_READ_FILE_OPS(power_save_status);
  1774. DEBUGFS_WRITE_FILE_OPS(clear_ucode_statistics);
  1775. DEBUGFS_WRITE_FILE_OPS(clear_traffic_statistics);
  1776. DEBUGFS_WRITE_FILE_OPS(csr);
  1777. DEBUGFS_READ_WRITE_FILE_OPS(ucode_tracing);
  1778. /*
  1779. * Create the debugfs files and directories
  1780. *
  1781. */
  1782. int iwl_dbgfs_register(struct iwl_priv *priv, const char *name)
  1783. {
  1784. struct iwl_debugfs *dbgfs;
  1785. struct dentry *phyd = priv->hw->wiphy->debugfsdir;
  1786. int ret = 0;
  1787. dbgfs = kzalloc(sizeof(struct iwl_debugfs), GFP_KERNEL);
  1788. if (!dbgfs) {
  1789. ret = -ENOMEM;
  1790. goto err;
  1791. }
  1792. priv->dbgfs = dbgfs;
  1793. dbgfs->name = name;
  1794. dbgfs->dir_drv = debugfs_create_dir(name, phyd);
  1795. if (!dbgfs->dir_drv || IS_ERR(dbgfs->dir_drv)) {
  1796. ret = -ENOENT;
  1797. goto err;
  1798. }
  1799. DEBUGFS_ADD_DIR(data, dbgfs->dir_drv);
  1800. DEBUGFS_ADD_DIR(rf, dbgfs->dir_drv);
  1801. DEBUGFS_ADD_DIR(debug, dbgfs->dir_drv);
  1802. DEBUGFS_ADD_FILE(nvm, data, S_IRUSR);
  1803. DEBUGFS_ADD_FILE(sram, data, S_IWUSR | S_IRUSR);
  1804. DEBUGFS_ADD_FILE(log_event, data, S_IWUSR | S_IRUSR);
  1805. DEBUGFS_ADD_FILE(stations, data, S_IRUSR);
  1806. DEBUGFS_ADD_FILE(channels, data, S_IRUSR);
  1807. DEBUGFS_ADD_FILE(status, data, S_IRUSR);
  1808. DEBUGFS_ADD_FILE(interrupt, data, S_IWUSR | S_IRUSR);
  1809. DEBUGFS_ADD_FILE(qos, data, S_IRUSR);
  1810. DEBUGFS_ADD_FILE(led, data, S_IRUSR);
  1811. DEBUGFS_ADD_FILE(sleep_level_override, data, S_IWUSR | S_IRUSR);
  1812. DEBUGFS_ADD_FILE(current_sleep_command, data, S_IRUSR);
  1813. DEBUGFS_ADD_FILE(thermal_throttling, data, S_IRUSR);
  1814. DEBUGFS_ADD_FILE(disable_ht40, data, S_IWUSR | S_IRUSR);
  1815. DEBUGFS_ADD_FILE(rx_statistics, debug, S_IRUSR);
  1816. DEBUGFS_ADD_FILE(tx_statistics, debug, S_IRUSR);
  1817. DEBUGFS_ADD_FILE(traffic_log, debug, S_IWUSR | S_IRUSR);
  1818. DEBUGFS_ADD_FILE(rx_queue, debug, S_IRUSR);
  1819. DEBUGFS_ADD_FILE(tx_queue, debug, S_IRUSR);
  1820. DEBUGFS_ADD_FILE(tx_power, debug, S_IRUSR);
  1821. DEBUGFS_ADD_FILE(power_save_status, debug, S_IRUSR);
  1822. DEBUGFS_ADD_FILE(clear_ucode_statistics, debug, S_IWUSR);
  1823. DEBUGFS_ADD_FILE(clear_traffic_statistics, debug, S_IWUSR);
  1824. DEBUGFS_ADD_FILE(csr, debug, S_IWUSR);
  1825. if ((priv->hw_rev & CSR_HW_REV_TYPE_MSK) != CSR_HW_REV_TYPE_3945) {
  1826. DEBUGFS_ADD_FILE(ucode_rx_stats, debug, S_IRUSR);
  1827. DEBUGFS_ADD_FILE(ucode_tx_stats, debug, S_IRUSR);
  1828. DEBUGFS_ADD_FILE(ucode_general_stats, debug, S_IRUSR);
  1829. DEBUGFS_ADD_FILE(sensitivity, debug, S_IRUSR);
  1830. DEBUGFS_ADD_FILE(chain_noise, debug, S_IRUSR);
  1831. DEBUGFS_ADD_FILE(ucode_tracing, debug, S_IWUSR | S_IRUSR);
  1832. }
  1833. DEBUGFS_ADD_BOOL(disable_sensitivity, rf, &priv->disable_sens_cal);
  1834. DEBUGFS_ADD_BOOL(disable_chain_noise, rf,
  1835. &priv->disable_chain_noise_cal);
  1836. if (((priv->hw_rev & CSR_HW_REV_TYPE_MSK) == CSR_HW_REV_TYPE_4965) ||
  1837. ((priv->hw_rev & CSR_HW_REV_TYPE_MSK) == CSR_HW_REV_TYPE_3945))
  1838. DEBUGFS_ADD_BOOL(disable_tx_power, rf,
  1839. &priv->disable_tx_power_cal);
  1840. return 0;
  1841. err:
  1842. IWL_ERR(priv, "Can't open the debugfs directory\n");
  1843. iwl_dbgfs_unregister(priv);
  1844. return ret;
  1845. }
  1846. EXPORT_SYMBOL(iwl_dbgfs_register);
  1847. /**
  1848. * Remove the debugfs files and directories
  1849. *
  1850. */
  1851. void iwl_dbgfs_unregister(struct iwl_priv *priv)
  1852. {
  1853. if (!priv->dbgfs)
  1854. return;
  1855. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_sleep_level_override);
  1856. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_current_sleep_command);
  1857. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_nvm);
  1858. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_sram);
  1859. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_log_event);
  1860. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_stations);
  1861. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_channels);
  1862. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_status);
  1863. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_interrupt);
  1864. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_qos);
  1865. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_led);
  1866. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_thermal_throttling);
  1867. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_disable_ht40);
  1868. DEBUGFS_REMOVE(priv->dbgfs->dir_data);
  1869. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_debug_files.file_rx_statistics);
  1870. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_debug_files.file_tx_statistics);
  1871. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_debug_files.file_traffic_log);
  1872. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_debug_files.file_rx_queue);
  1873. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_debug_files.file_tx_queue);
  1874. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_debug_files.file_tx_power);
  1875. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_debug_files.file_power_save_status);
  1876. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_debug_files.
  1877. file_clear_ucode_statistics);
  1878. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_debug_files.
  1879. file_clear_traffic_statistics);
  1880. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_debug_files.file_csr);
  1881. if ((priv->hw_rev & CSR_HW_REV_TYPE_MSK) != CSR_HW_REV_TYPE_3945) {
  1882. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_debug_files.
  1883. file_ucode_rx_stats);
  1884. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_debug_files.
  1885. file_ucode_tx_stats);
  1886. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_debug_files.
  1887. file_ucode_general_stats);
  1888. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_debug_files.
  1889. file_sensitivity);
  1890. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_debug_files.
  1891. file_chain_noise);
  1892. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_debug_files.
  1893. file_ucode_tracing);
  1894. }
  1895. DEBUGFS_REMOVE(priv->dbgfs->dir_debug);
  1896. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_rf_files.file_disable_sensitivity);
  1897. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_rf_files.file_disable_chain_noise);
  1898. if (((priv->hw_rev & CSR_HW_REV_TYPE_MSK) == CSR_HW_REV_TYPE_4965) ||
  1899. ((priv->hw_rev & CSR_HW_REV_TYPE_MSK) == CSR_HW_REV_TYPE_3945))
  1900. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_rf_files.file_disable_tx_power);
  1901. DEBUGFS_REMOVE(priv->dbgfs->dir_rf);
  1902. DEBUGFS_REMOVE(priv->dbgfs->dir_drv);
  1903. kfree(priv->dbgfs);
  1904. priv->dbgfs = NULL;
  1905. }
  1906. EXPORT_SYMBOL(iwl_dbgfs_unregister);