iwl-debugfs.c 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608
  1. /******************************************************************************
  2. *
  3. * GPL LICENSE SUMMARY
  4. *
  5. * Copyright(c) 2008 - 2010 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/ieee80211.h>
  29. #include <net/mac80211.h>
  30. #include "iwl-dev.h"
  31. #include "iwl-debug.h"
  32. #include "iwl-core.h"
  33. #include "iwl-io.h"
  34. #include "iwl-calib.h"
  35. /* create and remove of files */
  36. #define DEBUGFS_ADD_FILE(name, parent, mode) do { \
  37. if (!debugfs_create_file(#name, mode, parent, priv, \
  38. &iwl_dbgfs_##name##_ops)) \
  39. goto err; \
  40. } while (0)
  41. #define DEBUGFS_ADD_BOOL(name, parent, ptr) do { \
  42. struct dentry *__tmp; \
  43. __tmp = debugfs_create_bool(#name, S_IWUSR | S_IRUSR, \
  44. parent, ptr); \
  45. if (IS_ERR(__tmp) || !__tmp) \
  46. goto err; \
  47. } while (0)
  48. #define DEBUGFS_ADD_X32(name, parent, ptr) do { \
  49. struct dentry *__tmp; \
  50. __tmp = debugfs_create_x32(#name, S_IWUSR | S_IRUSR, \
  51. parent, ptr); \
  52. if (IS_ERR(__tmp) || !__tmp) \
  53. goto err; \
  54. } while (0)
  55. /* file operation */
  56. #define DEBUGFS_READ_FUNC(name) \
  57. static ssize_t iwl_dbgfs_##name##_read(struct file *file, \
  58. char __user *user_buf, \
  59. size_t count, loff_t *ppos);
  60. #define DEBUGFS_WRITE_FUNC(name) \
  61. static ssize_t iwl_dbgfs_##name##_write(struct file *file, \
  62. const char __user *user_buf, \
  63. size_t count, loff_t *ppos);
  64. static int iwl_dbgfs_open_file_generic(struct inode *inode, struct file *file)
  65. {
  66. file->private_data = inode->i_private;
  67. return 0;
  68. }
  69. #define DEBUGFS_READ_FILE_OPS(name) \
  70. DEBUGFS_READ_FUNC(name); \
  71. static const struct file_operations iwl_dbgfs_##name##_ops = { \
  72. .read = iwl_dbgfs_##name##_read, \
  73. .open = iwl_dbgfs_open_file_generic, \
  74. };
  75. #define DEBUGFS_WRITE_FILE_OPS(name) \
  76. DEBUGFS_WRITE_FUNC(name); \
  77. static const struct file_operations iwl_dbgfs_##name##_ops = { \
  78. .write = iwl_dbgfs_##name##_write, \
  79. .open = iwl_dbgfs_open_file_generic, \
  80. };
  81. #define DEBUGFS_READ_WRITE_FILE_OPS(name) \
  82. DEBUGFS_READ_FUNC(name); \
  83. DEBUGFS_WRITE_FUNC(name); \
  84. static const struct file_operations iwl_dbgfs_##name##_ops = { \
  85. .write = iwl_dbgfs_##name##_write, \
  86. .read = iwl_dbgfs_##name##_read, \
  87. .open = iwl_dbgfs_open_file_generic, \
  88. };
  89. static ssize_t iwl_dbgfs_tx_statistics_read(struct file *file,
  90. char __user *user_buf,
  91. size_t count, loff_t *ppos) {
  92. struct iwl_priv *priv = file->private_data;
  93. char *buf;
  94. int pos = 0;
  95. int cnt;
  96. ssize_t ret;
  97. const size_t bufsz = 100 +
  98. sizeof(char) * 50 * (MANAGEMENT_MAX + CONTROL_MAX);
  99. buf = kzalloc(bufsz, GFP_KERNEL);
  100. if (!buf)
  101. return -ENOMEM;
  102. pos += scnprintf(buf + pos, bufsz - pos, "Management:\n");
  103. for (cnt = 0; cnt < MANAGEMENT_MAX; cnt++) {
  104. pos += scnprintf(buf + pos, bufsz - pos,
  105. "\t%25s\t\t: %u\n",
  106. get_mgmt_string(cnt),
  107. priv->tx_stats.mgmt[cnt]);
  108. }
  109. pos += scnprintf(buf + pos, bufsz - pos, "Control\n");
  110. for (cnt = 0; cnt < CONTROL_MAX; cnt++) {
  111. pos += scnprintf(buf + pos, bufsz - pos,
  112. "\t%25s\t\t: %u\n",
  113. get_ctrl_string(cnt),
  114. priv->tx_stats.ctrl[cnt]);
  115. }
  116. pos += scnprintf(buf + pos, bufsz - pos, "Data:\n");
  117. pos += scnprintf(buf + pos, bufsz - pos, "\tcnt: %u\n",
  118. priv->tx_stats.data_cnt);
  119. pos += scnprintf(buf + pos, bufsz - pos, "\tbytes: %llu\n",
  120. priv->tx_stats.data_bytes);
  121. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  122. kfree(buf);
  123. return ret;
  124. }
  125. static ssize_t iwl_dbgfs_clear_traffic_statistics_write(struct file *file,
  126. const char __user *user_buf,
  127. size_t count, loff_t *ppos)
  128. {
  129. struct iwl_priv *priv = file->private_data;
  130. u32 clear_flag;
  131. char buf[8];
  132. int buf_size;
  133. memset(buf, 0, sizeof(buf));
  134. buf_size = min(count, sizeof(buf) - 1);
  135. if (copy_from_user(buf, user_buf, buf_size))
  136. return -EFAULT;
  137. if (sscanf(buf, "%x", &clear_flag) != 1)
  138. return -EFAULT;
  139. iwl_clear_traffic_stats(priv);
  140. return count;
  141. }
  142. static ssize_t iwl_dbgfs_rx_statistics_read(struct file *file,
  143. char __user *user_buf,
  144. size_t count, loff_t *ppos) {
  145. struct iwl_priv *priv = file->private_data;
  146. char *buf;
  147. int pos = 0;
  148. int cnt;
  149. ssize_t ret;
  150. const size_t bufsz = 100 +
  151. sizeof(char) * 50 * (MANAGEMENT_MAX + CONTROL_MAX);
  152. buf = kzalloc(bufsz, GFP_KERNEL);
  153. if (!buf)
  154. return -ENOMEM;
  155. pos += scnprintf(buf + pos, bufsz - pos, "Management:\n");
  156. for (cnt = 0; cnt < MANAGEMENT_MAX; cnt++) {
  157. pos += scnprintf(buf + pos, bufsz - pos,
  158. "\t%25s\t\t: %u\n",
  159. get_mgmt_string(cnt),
  160. priv->rx_stats.mgmt[cnt]);
  161. }
  162. pos += scnprintf(buf + pos, bufsz - pos, "Control:\n");
  163. for (cnt = 0; cnt < CONTROL_MAX; cnt++) {
  164. pos += scnprintf(buf + pos, bufsz - pos,
  165. "\t%25s\t\t: %u\n",
  166. get_ctrl_string(cnt),
  167. priv->rx_stats.ctrl[cnt]);
  168. }
  169. pos += scnprintf(buf + pos, bufsz - pos, "Data:\n");
  170. pos += scnprintf(buf + pos, bufsz - pos, "\tcnt: %u\n",
  171. priv->rx_stats.data_cnt);
  172. pos += scnprintf(buf + pos, bufsz - pos, "\tbytes: %llu\n",
  173. priv->rx_stats.data_bytes);
  174. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  175. kfree(buf);
  176. return ret;
  177. }
  178. #define BYTE1_MASK 0x000000ff;
  179. #define BYTE2_MASK 0x0000ffff;
  180. #define BYTE3_MASK 0x00ffffff;
  181. static ssize_t iwl_dbgfs_sram_read(struct file *file,
  182. char __user *user_buf,
  183. size_t count, loff_t *ppos)
  184. {
  185. u32 val;
  186. char *buf;
  187. ssize_t ret;
  188. int i;
  189. int pos = 0;
  190. struct iwl_priv *priv = file->private_data;
  191. size_t bufsz;
  192. /* default is to dump the entire data segment */
  193. if (!priv->dbgfs_sram_offset && !priv->dbgfs_sram_len) {
  194. priv->dbgfs_sram_offset = 0x800000;
  195. if (priv->ucode_type == UCODE_INIT)
  196. priv->dbgfs_sram_len = priv->ucode_init_data.len;
  197. else
  198. priv->dbgfs_sram_len = priv->ucode_data.len;
  199. }
  200. bufsz = 30 + priv->dbgfs_sram_len * sizeof(char) * 10;
  201. buf = kmalloc(bufsz, GFP_KERNEL);
  202. if (!buf)
  203. return -ENOMEM;
  204. pos += scnprintf(buf + pos, bufsz - pos, "sram_len: 0x%x\n",
  205. priv->dbgfs_sram_len);
  206. pos += scnprintf(buf + pos, bufsz - pos, "sram_offset: 0x%x\n",
  207. priv->dbgfs_sram_offset);
  208. for (i = priv->dbgfs_sram_len; i > 0; i -= 4) {
  209. val = iwl_read_targ_mem(priv, priv->dbgfs_sram_offset + \
  210. priv->dbgfs_sram_len - i);
  211. if (i < 4) {
  212. switch (i) {
  213. case 1:
  214. val &= BYTE1_MASK;
  215. break;
  216. case 2:
  217. val &= BYTE2_MASK;
  218. break;
  219. case 3:
  220. val &= BYTE3_MASK;
  221. break;
  222. }
  223. }
  224. if (!(i % 16))
  225. pos += scnprintf(buf + pos, bufsz - pos, "\n");
  226. pos += scnprintf(buf + pos, bufsz - pos, "0x%08x ", val);
  227. }
  228. pos += scnprintf(buf + pos, bufsz - pos, "\n");
  229. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  230. kfree(buf);
  231. return ret;
  232. }
  233. static ssize_t iwl_dbgfs_sram_write(struct file *file,
  234. const char __user *user_buf,
  235. size_t count, loff_t *ppos)
  236. {
  237. struct iwl_priv *priv = file->private_data;
  238. char buf[64];
  239. int buf_size;
  240. u32 offset, len;
  241. memset(buf, 0, sizeof(buf));
  242. buf_size = min(count, sizeof(buf) - 1);
  243. if (copy_from_user(buf, user_buf, buf_size))
  244. return -EFAULT;
  245. if (sscanf(buf, "%x,%x", &offset, &len) == 2) {
  246. priv->dbgfs_sram_offset = offset;
  247. priv->dbgfs_sram_len = len;
  248. } else {
  249. priv->dbgfs_sram_offset = 0;
  250. priv->dbgfs_sram_len = 0;
  251. }
  252. return count;
  253. }
  254. static ssize_t iwl_dbgfs_stations_read(struct file *file, char __user *user_buf,
  255. size_t count, loff_t *ppos)
  256. {
  257. struct iwl_priv *priv = file->private_data;
  258. struct iwl_station_entry *station;
  259. int max_sta = priv->hw_params.max_stations;
  260. char *buf;
  261. int i, j, pos = 0;
  262. ssize_t ret;
  263. /* Add 30 for initial string */
  264. const size_t bufsz = 30 + sizeof(char) * 500 * (priv->num_stations);
  265. buf = kmalloc(bufsz, GFP_KERNEL);
  266. if (!buf)
  267. return -ENOMEM;
  268. pos += scnprintf(buf + pos, bufsz - pos, "num of stations: %d\n\n",
  269. priv->num_stations);
  270. for (i = 0; i < max_sta; i++) {
  271. station = &priv->stations[i];
  272. if (!station->used)
  273. continue;
  274. pos += scnprintf(buf + pos, bufsz - pos,
  275. "station %d - addr: %pM, flags: %#x\n",
  276. i, station->sta.sta.addr,
  277. station->sta.station_flags_msk);
  278. pos += scnprintf(buf + pos, bufsz - pos,
  279. "TID\tseq_num\ttxq_id\tframes\ttfds\t");
  280. pos += scnprintf(buf + pos, bufsz - pos,
  281. "start_idx\tbitmap\t\t\trate_n_flags\n");
  282. for (j = 0; j < MAX_TID_COUNT; j++) {
  283. pos += scnprintf(buf + pos, bufsz - pos,
  284. "%d:\t%#x\t%#x\t%u\t%u\t%u\t\t%#.16llx\t%#x",
  285. j, station->tid[j].seq_number,
  286. station->tid[j].agg.txq_id,
  287. station->tid[j].agg.frame_count,
  288. station->tid[j].tfds_in_queue,
  289. station->tid[j].agg.start_idx,
  290. station->tid[j].agg.bitmap,
  291. station->tid[j].agg.rate_n_flags);
  292. if (station->tid[j].agg.wait_for_ba)
  293. pos += scnprintf(buf + pos, bufsz - pos,
  294. " - waitforba");
  295. pos += scnprintf(buf + pos, bufsz - pos, "\n");
  296. }
  297. pos += scnprintf(buf + pos, bufsz - pos, "\n");
  298. }
  299. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  300. kfree(buf);
  301. return ret;
  302. }
  303. static ssize_t iwl_dbgfs_nvm_read(struct file *file,
  304. char __user *user_buf,
  305. size_t count,
  306. loff_t *ppos)
  307. {
  308. ssize_t ret;
  309. struct iwl_priv *priv = file->private_data;
  310. int pos = 0, ofs = 0, buf_size = 0;
  311. const u8 *ptr;
  312. char *buf;
  313. u16 eeprom_ver;
  314. size_t eeprom_len = priv->cfg->eeprom_size;
  315. buf_size = 4 * eeprom_len + 256;
  316. if (eeprom_len % 16) {
  317. IWL_ERR(priv, "NVM size is not multiple of 16.\n");
  318. return -ENODATA;
  319. }
  320. ptr = priv->eeprom;
  321. if (!ptr) {
  322. IWL_ERR(priv, "Invalid EEPROM/OTP memory\n");
  323. return -ENOMEM;
  324. }
  325. /* 4 characters for byte 0xYY */
  326. buf = kzalloc(buf_size, GFP_KERNEL);
  327. if (!buf) {
  328. IWL_ERR(priv, "Can not allocate Buffer\n");
  329. return -ENOMEM;
  330. }
  331. eeprom_ver = iwl_eeprom_query16(priv, EEPROM_VERSION);
  332. pos += scnprintf(buf + pos, buf_size - pos, "NVM Type: %s, "
  333. "version: 0x%x\n",
  334. (priv->nvm_device_type == NVM_DEVICE_TYPE_OTP)
  335. ? "OTP" : "EEPROM", eeprom_ver);
  336. for (ofs = 0 ; ofs < eeprom_len ; ofs += 16) {
  337. pos += scnprintf(buf + pos, buf_size - pos, "0x%.4x ", ofs);
  338. hex_dump_to_buffer(ptr + ofs, 16 , 16, 2, buf + pos,
  339. buf_size - pos, 0);
  340. pos += strlen(buf + pos);
  341. if (buf_size - pos > 0)
  342. buf[pos++] = '\n';
  343. }
  344. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  345. kfree(buf);
  346. return ret;
  347. }
  348. static ssize_t iwl_dbgfs_log_event_read(struct file *file,
  349. char __user *user_buf,
  350. size_t count, loff_t *ppos)
  351. {
  352. struct iwl_priv *priv = file->private_data;
  353. char *buf;
  354. int pos = 0;
  355. ssize_t ret = -ENOMEM;
  356. ret = pos = priv->cfg->ops->lib->dump_nic_event_log(
  357. priv, true, &buf, true);
  358. if (buf) {
  359. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  360. kfree(buf);
  361. }
  362. return ret;
  363. }
  364. static ssize_t iwl_dbgfs_log_event_write(struct file *file,
  365. const char __user *user_buf,
  366. size_t count, loff_t *ppos)
  367. {
  368. struct iwl_priv *priv = file->private_data;
  369. u32 event_log_flag;
  370. char buf[8];
  371. int buf_size;
  372. memset(buf, 0, sizeof(buf));
  373. buf_size = min(count, sizeof(buf) - 1);
  374. if (copy_from_user(buf, user_buf, buf_size))
  375. return -EFAULT;
  376. if (sscanf(buf, "%d", &event_log_flag) != 1)
  377. return -EFAULT;
  378. if (event_log_flag == 1)
  379. priv->cfg->ops->lib->dump_nic_event_log(priv, true,
  380. NULL, false);
  381. return count;
  382. }
  383. static ssize_t iwl_dbgfs_channels_read(struct file *file, char __user *user_buf,
  384. size_t count, loff_t *ppos)
  385. {
  386. struct iwl_priv *priv = file->private_data;
  387. struct ieee80211_channel *channels = NULL;
  388. const struct ieee80211_supported_band *supp_band = NULL;
  389. int pos = 0, i, bufsz = PAGE_SIZE;
  390. char *buf;
  391. ssize_t ret;
  392. if (!test_bit(STATUS_GEO_CONFIGURED, &priv->status))
  393. return -EAGAIN;
  394. buf = kzalloc(bufsz, GFP_KERNEL);
  395. if (!buf) {
  396. IWL_ERR(priv, "Can not allocate Buffer\n");
  397. return -ENOMEM;
  398. }
  399. supp_band = iwl_get_hw_mode(priv, IEEE80211_BAND_2GHZ);
  400. if (supp_band) {
  401. channels = supp_band->channels;
  402. pos += scnprintf(buf + pos, bufsz - pos,
  403. "Displaying %d channels in 2.4GHz band 802.11bg):\n",
  404. supp_band->n_channels);
  405. for (i = 0; i < supp_band->n_channels; i++)
  406. pos += scnprintf(buf + pos, bufsz - pos,
  407. "%d: %ddBm: BSS%s%s, %s.\n",
  408. ieee80211_frequency_to_channel(
  409. channels[i].center_freq),
  410. channels[i].max_power,
  411. channels[i].flags & IEEE80211_CHAN_RADAR ?
  412. " (IEEE 802.11h required)" : "",
  413. ((channels[i].flags & IEEE80211_CHAN_NO_IBSS)
  414. || (channels[i].flags &
  415. IEEE80211_CHAN_RADAR)) ? "" :
  416. ", IBSS",
  417. channels[i].flags &
  418. IEEE80211_CHAN_PASSIVE_SCAN ?
  419. "passive only" : "active/passive");
  420. }
  421. supp_band = iwl_get_hw_mode(priv, IEEE80211_BAND_5GHZ);
  422. if (supp_band) {
  423. channels = supp_band->channels;
  424. pos += scnprintf(buf + pos, bufsz - pos,
  425. "Displaying %d channels in 5.2GHz band (802.11a)\n",
  426. supp_band->n_channels);
  427. for (i = 0; i < supp_band->n_channels; i++)
  428. pos += scnprintf(buf + pos, bufsz - pos,
  429. "%d: %ddBm: BSS%s%s, %s.\n",
  430. ieee80211_frequency_to_channel(
  431. channels[i].center_freq),
  432. channels[i].max_power,
  433. channels[i].flags & IEEE80211_CHAN_RADAR ?
  434. " (IEEE 802.11h required)" : "",
  435. ((channels[i].flags & IEEE80211_CHAN_NO_IBSS)
  436. || (channels[i].flags &
  437. IEEE80211_CHAN_RADAR)) ? "" :
  438. ", IBSS",
  439. channels[i].flags &
  440. IEEE80211_CHAN_PASSIVE_SCAN ?
  441. "passive only" : "active/passive");
  442. }
  443. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  444. kfree(buf);
  445. return ret;
  446. }
  447. static ssize_t iwl_dbgfs_status_read(struct file *file,
  448. char __user *user_buf,
  449. size_t count, loff_t *ppos) {
  450. struct iwl_priv *priv = file->private_data;
  451. char buf[512];
  452. int pos = 0;
  453. const size_t bufsz = sizeof(buf);
  454. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_HCMD_ACTIVE:\t %d\n",
  455. test_bit(STATUS_HCMD_ACTIVE, &priv->status));
  456. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_INT_ENABLED:\t %d\n",
  457. test_bit(STATUS_INT_ENABLED, &priv->status));
  458. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_RF_KILL_HW:\t %d\n",
  459. test_bit(STATUS_RF_KILL_HW, &priv->status));
  460. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_CT_KILL:\t\t %d\n",
  461. test_bit(STATUS_CT_KILL, &priv->status));
  462. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_INIT:\t\t %d\n",
  463. test_bit(STATUS_INIT, &priv->status));
  464. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_ALIVE:\t\t %d\n",
  465. test_bit(STATUS_ALIVE, &priv->status));
  466. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_READY:\t\t %d\n",
  467. test_bit(STATUS_READY, &priv->status));
  468. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_TEMPERATURE:\t %d\n",
  469. test_bit(STATUS_TEMPERATURE, &priv->status));
  470. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_GEO_CONFIGURED:\t %d\n",
  471. test_bit(STATUS_GEO_CONFIGURED, &priv->status));
  472. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_EXIT_PENDING:\t %d\n",
  473. test_bit(STATUS_EXIT_PENDING, &priv->status));
  474. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_STATISTICS:\t %d\n",
  475. test_bit(STATUS_STATISTICS, &priv->status));
  476. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_SCANNING:\t %d\n",
  477. test_bit(STATUS_SCANNING, &priv->status));
  478. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_SCAN_ABORTING:\t %d\n",
  479. test_bit(STATUS_SCAN_ABORTING, &priv->status));
  480. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_SCAN_HW:\t\t %d\n",
  481. test_bit(STATUS_SCAN_HW, &priv->status));
  482. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_POWER_PMI:\t %d\n",
  483. test_bit(STATUS_POWER_PMI, &priv->status));
  484. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_FW_ERROR:\t %d\n",
  485. test_bit(STATUS_FW_ERROR, &priv->status));
  486. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  487. }
  488. static ssize_t iwl_dbgfs_interrupt_read(struct file *file,
  489. char __user *user_buf,
  490. size_t count, loff_t *ppos) {
  491. struct iwl_priv *priv = file->private_data;
  492. int pos = 0;
  493. int cnt = 0;
  494. char *buf;
  495. int bufsz = 24 * 64; /* 24 items * 64 char per item */
  496. ssize_t ret;
  497. buf = kzalloc(bufsz, GFP_KERNEL);
  498. if (!buf) {
  499. IWL_ERR(priv, "Can not allocate Buffer\n");
  500. return -ENOMEM;
  501. }
  502. pos += scnprintf(buf + pos, bufsz - pos,
  503. "Interrupt Statistics Report:\n");
  504. pos += scnprintf(buf + pos, bufsz - pos, "HW Error:\t\t\t %u\n",
  505. priv->isr_stats.hw);
  506. pos += scnprintf(buf + pos, bufsz - pos, "SW Error:\t\t\t %u\n",
  507. priv->isr_stats.sw);
  508. if (priv->isr_stats.sw > 0) {
  509. pos += scnprintf(buf + pos, bufsz - pos,
  510. "\tLast Restarting Code: 0x%X\n",
  511. priv->isr_stats.sw_err);
  512. }
  513. #ifdef CONFIG_IWLWIFI_DEBUG
  514. pos += scnprintf(buf + pos, bufsz - pos, "Frame transmitted:\t\t %u\n",
  515. priv->isr_stats.sch);
  516. pos += scnprintf(buf + pos, bufsz - pos, "Alive interrupt:\t\t %u\n",
  517. priv->isr_stats.alive);
  518. #endif
  519. pos += scnprintf(buf + pos, bufsz - pos,
  520. "HW RF KILL switch toggled:\t %u\n",
  521. priv->isr_stats.rfkill);
  522. pos += scnprintf(buf + pos, bufsz - pos, "CT KILL:\t\t\t %u\n",
  523. priv->isr_stats.ctkill);
  524. pos += scnprintf(buf + pos, bufsz - pos, "Wakeup Interrupt:\t\t %u\n",
  525. priv->isr_stats.wakeup);
  526. pos += scnprintf(buf + pos, bufsz - pos,
  527. "Rx command responses:\t\t %u\n",
  528. priv->isr_stats.rx);
  529. for (cnt = 0; cnt < REPLY_MAX; cnt++) {
  530. if (priv->isr_stats.rx_handlers[cnt] > 0)
  531. pos += scnprintf(buf + pos, bufsz - pos,
  532. "\tRx handler[%36s]:\t\t %u\n",
  533. get_cmd_string(cnt),
  534. priv->isr_stats.rx_handlers[cnt]);
  535. }
  536. pos += scnprintf(buf + pos, bufsz - pos, "Tx/FH interrupt:\t\t %u\n",
  537. priv->isr_stats.tx);
  538. pos += scnprintf(buf + pos, bufsz - pos, "Unexpected INTA:\t\t %u\n",
  539. priv->isr_stats.unhandled);
  540. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  541. kfree(buf);
  542. return ret;
  543. }
  544. static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
  545. const char __user *user_buf,
  546. size_t count, loff_t *ppos)
  547. {
  548. struct iwl_priv *priv = file->private_data;
  549. char buf[8];
  550. int buf_size;
  551. u32 reset_flag;
  552. memset(buf, 0, sizeof(buf));
  553. buf_size = min(count, sizeof(buf) - 1);
  554. if (copy_from_user(buf, user_buf, buf_size))
  555. return -EFAULT;
  556. if (sscanf(buf, "%x", &reset_flag) != 1)
  557. return -EFAULT;
  558. if (reset_flag == 0)
  559. iwl_clear_isr_stats(priv);
  560. return count;
  561. }
  562. static ssize_t iwl_dbgfs_qos_read(struct file *file, char __user *user_buf,
  563. size_t count, loff_t *ppos)
  564. {
  565. struct iwl_priv *priv = file->private_data;
  566. int pos = 0, i;
  567. char buf[256];
  568. const size_t bufsz = sizeof(buf);
  569. for (i = 0; i < AC_NUM; i++) {
  570. pos += scnprintf(buf + pos, bufsz - pos,
  571. "\tcw_min\tcw_max\taifsn\ttxop\n");
  572. pos += scnprintf(buf + pos, bufsz - pos,
  573. "AC[%d]\t%u\t%u\t%u\t%u\n", i,
  574. priv->qos_data.def_qos_parm.ac[i].cw_min,
  575. priv->qos_data.def_qos_parm.ac[i].cw_max,
  576. priv->qos_data.def_qos_parm.ac[i].aifsn,
  577. priv->qos_data.def_qos_parm.ac[i].edca_txop);
  578. }
  579. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  580. }
  581. static ssize_t iwl_dbgfs_led_read(struct file *file, char __user *user_buf,
  582. size_t count, loff_t *ppos)
  583. {
  584. struct iwl_priv *priv = file->private_data;
  585. int pos = 0;
  586. char buf[256];
  587. const size_t bufsz = sizeof(buf);
  588. pos += scnprintf(buf + pos, bufsz - pos,
  589. "allow blinking: %s\n",
  590. (priv->allow_blinking) ? "True" : "False");
  591. if (priv->allow_blinking) {
  592. pos += scnprintf(buf + pos, bufsz - pos,
  593. "Led blinking rate: %u\n",
  594. priv->last_blink_rate);
  595. pos += scnprintf(buf + pos, bufsz - pos,
  596. "Last blink time: %lu\n",
  597. priv->last_blink_time);
  598. }
  599. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  600. }
  601. static ssize_t iwl_dbgfs_thermal_throttling_read(struct file *file,
  602. char __user *user_buf,
  603. size_t count, loff_t *ppos)
  604. {
  605. struct iwl_priv *priv = file->private_data;
  606. struct iwl_tt_mgmt *tt = &priv->thermal_throttle;
  607. struct iwl_tt_restriction *restriction;
  608. char buf[100];
  609. int pos = 0;
  610. const size_t bufsz = sizeof(buf);
  611. pos += scnprintf(buf + pos, bufsz - pos,
  612. "Thermal Throttling Mode: %s\n",
  613. tt->advanced_tt ? "Advance" : "Legacy");
  614. pos += scnprintf(buf + pos, bufsz - pos,
  615. "Thermal Throttling State: %d\n",
  616. tt->state);
  617. if (tt->advanced_tt) {
  618. restriction = tt->restriction + tt->state;
  619. pos += scnprintf(buf + pos, bufsz - pos,
  620. "Tx mode: %d\n",
  621. restriction->tx_stream);
  622. pos += scnprintf(buf + pos, bufsz - pos,
  623. "Rx mode: %d\n",
  624. restriction->rx_stream);
  625. pos += scnprintf(buf + pos, bufsz - pos,
  626. "HT mode: %d\n",
  627. restriction->is_ht);
  628. }
  629. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  630. }
  631. static ssize_t iwl_dbgfs_disable_ht40_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 ht40;
  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", &ht40) != 1)
  644. return -EFAULT;
  645. if (!iwl_is_associated(priv))
  646. priv->disable_ht40 = ht40 ? true : false;
  647. else {
  648. IWL_ERR(priv, "Sta associated with AP - "
  649. "Change to 40MHz channel support is not allowed\n");
  650. return -EINVAL;
  651. }
  652. return count;
  653. }
  654. static ssize_t iwl_dbgfs_disable_ht40_read(struct file *file,
  655. char __user *user_buf,
  656. size_t count, loff_t *ppos)
  657. {
  658. struct iwl_priv *priv = file->private_data;
  659. char buf[100];
  660. int pos = 0;
  661. const size_t bufsz = sizeof(buf);
  662. pos += scnprintf(buf + pos, bufsz - pos,
  663. "11n 40MHz Mode: %s\n",
  664. priv->disable_ht40 ? "Disabled" : "Enabled");
  665. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  666. }
  667. static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
  668. const char __user *user_buf,
  669. size_t count, loff_t *ppos)
  670. {
  671. struct iwl_priv *priv = file->private_data;
  672. char buf[8];
  673. int buf_size;
  674. int value;
  675. memset(buf, 0, sizeof(buf));
  676. buf_size = min(count, sizeof(buf) - 1);
  677. if (copy_from_user(buf, user_buf, buf_size))
  678. return -EFAULT;
  679. if (sscanf(buf, "%d", &value) != 1)
  680. return -EINVAL;
  681. /*
  682. * Our users expect 0 to be "CAM", but 0 isn't actually
  683. * valid here. However, let's not confuse them and present
  684. * IWL_POWER_INDEX_1 as "1", not "0".
  685. */
  686. if (value == 0)
  687. return -EINVAL;
  688. else if (value > 0)
  689. value -= 1;
  690. if (value != -1 && (value < 0 || value >= IWL_POWER_NUM))
  691. return -EINVAL;
  692. if (!iwl_is_ready_rf(priv))
  693. return -EAGAIN;
  694. priv->power_data.debug_sleep_level_override = value;
  695. mutex_lock(&priv->mutex);
  696. iwl_power_update_mode(priv, true);
  697. mutex_unlock(&priv->mutex);
  698. return count;
  699. }
  700. static ssize_t iwl_dbgfs_sleep_level_override_read(struct file *file,
  701. char __user *user_buf,
  702. size_t count, loff_t *ppos)
  703. {
  704. struct iwl_priv *priv = file->private_data;
  705. char buf[10];
  706. int pos, value;
  707. const size_t bufsz = sizeof(buf);
  708. /* see the write function */
  709. value = priv->power_data.debug_sleep_level_override;
  710. if (value >= 0)
  711. value += 1;
  712. pos = scnprintf(buf, bufsz, "%d\n", value);
  713. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  714. }
  715. static ssize_t iwl_dbgfs_current_sleep_command_read(struct file *file,
  716. char __user *user_buf,
  717. size_t count, loff_t *ppos)
  718. {
  719. struct iwl_priv *priv = file->private_data;
  720. char buf[200];
  721. int pos = 0, i;
  722. const size_t bufsz = sizeof(buf);
  723. struct iwl_powertable_cmd *cmd = &priv->power_data.sleep_cmd;
  724. pos += scnprintf(buf + pos, bufsz - pos,
  725. "flags: %#.2x\n", le16_to_cpu(cmd->flags));
  726. pos += scnprintf(buf + pos, bufsz - pos,
  727. "RX/TX timeout: %d/%d usec\n",
  728. le32_to_cpu(cmd->rx_data_timeout),
  729. le32_to_cpu(cmd->tx_data_timeout));
  730. for (i = 0; i < IWL_POWER_VEC_SIZE; i++)
  731. pos += scnprintf(buf + pos, bufsz - pos,
  732. "sleep_interval[%d]: %d\n", i,
  733. le32_to_cpu(cmd->sleep_interval[i]));
  734. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  735. }
  736. DEBUGFS_READ_WRITE_FILE_OPS(sram);
  737. DEBUGFS_READ_WRITE_FILE_OPS(log_event);
  738. DEBUGFS_READ_FILE_OPS(nvm);
  739. DEBUGFS_READ_FILE_OPS(stations);
  740. DEBUGFS_READ_FILE_OPS(channels);
  741. DEBUGFS_READ_FILE_OPS(status);
  742. DEBUGFS_READ_WRITE_FILE_OPS(interrupt);
  743. DEBUGFS_READ_FILE_OPS(qos);
  744. DEBUGFS_READ_FILE_OPS(led);
  745. DEBUGFS_READ_FILE_OPS(thermal_throttling);
  746. DEBUGFS_READ_WRITE_FILE_OPS(disable_ht40);
  747. DEBUGFS_READ_WRITE_FILE_OPS(sleep_level_override);
  748. DEBUGFS_READ_FILE_OPS(current_sleep_command);
  749. static ssize_t iwl_dbgfs_traffic_log_read(struct file *file,
  750. char __user *user_buf,
  751. size_t count, loff_t *ppos)
  752. {
  753. struct iwl_priv *priv = file->private_data;
  754. int pos = 0, ofs = 0;
  755. int cnt = 0, entry;
  756. struct iwl_tx_queue *txq;
  757. struct iwl_queue *q;
  758. struct iwl_rx_queue *rxq = &priv->rxq;
  759. char *buf;
  760. int bufsz = ((IWL_TRAFFIC_ENTRIES * IWL_TRAFFIC_ENTRY_SIZE * 64) * 2) +
  761. (priv->cfg->num_of_queues * 32 * 8) + 400;
  762. const u8 *ptr;
  763. ssize_t ret;
  764. if (!priv->txq) {
  765. IWL_ERR(priv, "txq not ready\n");
  766. return -EAGAIN;
  767. }
  768. buf = kzalloc(bufsz, GFP_KERNEL);
  769. if (!buf) {
  770. IWL_ERR(priv, "Can not allocate buffer\n");
  771. return -ENOMEM;
  772. }
  773. pos += scnprintf(buf + pos, bufsz - pos, "Tx Queue\n");
  774. for (cnt = 0; cnt < priv->hw_params.max_txq_num; cnt++) {
  775. txq = &priv->txq[cnt];
  776. q = &txq->q;
  777. pos += scnprintf(buf + pos, bufsz - pos,
  778. "q[%d]: read_ptr: %u, write_ptr: %u\n",
  779. cnt, q->read_ptr, q->write_ptr);
  780. }
  781. if (priv->tx_traffic && (iwl_debug_level & IWL_DL_TX)) {
  782. ptr = priv->tx_traffic;
  783. pos += scnprintf(buf + pos, bufsz - pos,
  784. "Tx Traffic idx: %u\n", priv->tx_traffic_idx);
  785. for (cnt = 0, ofs = 0; cnt < IWL_TRAFFIC_ENTRIES; cnt++) {
  786. for (entry = 0; entry < IWL_TRAFFIC_ENTRY_SIZE / 16;
  787. entry++, ofs += 16) {
  788. pos += scnprintf(buf + pos, bufsz - pos,
  789. "0x%.4x ", ofs);
  790. hex_dump_to_buffer(ptr + ofs, 16, 16, 2,
  791. buf + pos, bufsz - pos, 0);
  792. pos += strlen(buf + pos);
  793. if (bufsz - pos > 0)
  794. buf[pos++] = '\n';
  795. }
  796. }
  797. }
  798. pos += scnprintf(buf + pos, bufsz - pos, "Rx Queue\n");
  799. pos += scnprintf(buf + pos, bufsz - pos,
  800. "read: %u, write: %u\n",
  801. rxq->read, rxq->write);
  802. if (priv->rx_traffic && (iwl_debug_level & IWL_DL_RX)) {
  803. ptr = priv->rx_traffic;
  804. pos += scnprintf(buf + pos, bufsz - pos,
  805. "Rx Traffic idx: %u\n", priv->rx_traffic_idx);
  806. for (cnt = 0, ofs = 0; cnt < IWL_TRAFFIC_ENTRIES; cnt++) {
  807. for (entry = 0; entry < IWL_TRAFFIC_ENTRY_SIZE / 16;
  808. entry++, ofs += 16) {
  809. pos += scnprintf(buf + pos, bufsz - pos,
  810. "0x%.4x ", ofs);
  811. hex_dump_to_buffer(ptr + ofs, 16, 16, 2,
  812. buf + pos, bufsz - pos, 0);
  813. pos += strlen(buf + pos);
  814. if (bufsz - pos > 0)
  815. buf[pos++] = '\n';
  816. }
  817. }
  818. }
  819. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  820. kfree(buf);
  821. return ret;
  822. }
  823. static ssize_t iwl_dbgfs_traffic_log_write(struct file *file,
  824. const char __user *user_buf,
  825. size_t count, loff_t *ppos)
  826. {
  827. struct iwl_priv *priv = file->private_data;
  828. char buf[8];
  829. int buf_size;
  830. int traffic_log;
  831. memset(buf, 0, sizeof(buf));
  832. buf_size = min(count, sizeof(buf) - 1);
  833. if (copy_from_user(buf, user_buf, buf_size))
  834. return -EFAULT;
  835. if (sscanf(buf, "%d", &traffic_log) != 1)
  836. return -EFAULT;
  837. if (traffic_log == 0)
  838. iwl_reset_traffic_log(priv);
  839. return count;
  840. }
  841. static ssize_t iwl_dbgfs_tx_queue_read(struct file *file,
  842. char __user *user_buf,
  843. size_t count, loff_t *ppos) {
  844. struct iwl_priv *priv = file->private_data;
  845. struct iwl_tx_queue *txq;
  846. struct iwl_queue *q;
  847. char *buf;
  848. int pos = 0;
  849. int cnt;
  850. int ret;
  851. const size_t bufsz = sizeof(char) * 64 * priv->cfg->num_of_queues;
  852. if (!priv->txq) {
  853. IWL_ERR(priv, "txq not ready\n");
  854. return -EAGAIN;
  855. }
  856. buf = kzalloc(bufsz, GFP_KERNEL);
  857. if (!buf)
  858. return -ENOMEM;
  859. for (cnt = 0; cnt < priv->hw_params.max_txq_num; cnt++) {
  860. txq = &priv->txq[cnt];
  861. q = &txq->q;
  862. pos += scnprintf(buf + pos, bufsz - pos,
  863. "hwq %.2d: read=%u write=%u stop=%d"
  864. " swq_id=%#.2x (ac %d/hwq %d)\n",
  865. cnt, q->read_ptr, q->write_ptr,
  866. !!test_bit(cnt, priv->queue_stopped),
  867. txq->swq_id,
  868. txq->swq_id & 0x80 ? txq->swq_id & 3 :
  869. txq->swq_id,
  870. txq->swq_id & 0x80 ? (txq->swq_id >> 2) &
  871. 0x1f : txq->swq_id);
  872. if (cnt >= 4)
  873. continue;
  874. /* for the ACs, display the stop count too */
  875. pos += scnprintf(buf + pos, bufsz - pos,
  876. " stop-count: %d\n",
  877. atomic_read(&priv->queue_stop_count[cnt]));
  878. }
  879. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  880. kfree(buf);
  881. return ret;
  882. }
  883. static ssize_t iwl_dbgfs_rx_queue_read(struct file *file,
  884. char __user *user_buf,
  885. size_t count, loff_t *ppos) {
  886. struct iwl_priv *priv = file->private_data;
  887. struct iwl_rx_queue *rxq = &priv->rxq;
  888. char buf[256];
  889. int pos = 0;
  890. const size_t bufsz = sizeof(buf);
  891. pos += scnprintf(buf + pos, bufsz - pos, "read: %u\n",
  892. rxq->read);
  893. pos += scnprintf(buf + pos, bufsz - pos, "write: %u\n",
  894. rxq->write);
  895. pos += scnprintf(buf + pos, bufsz - pos, "free_count: %u\n",
  896. rxq->free_count);
  897. pos += scnprintf(buf + pos, bufsz - pos, "closed_rb_num: %u\n",
  898. le16_to_cpu(rxq->rb_stts->closed_rb_num) & 0x0FFF);
  899. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  900. }
  901. static ssize_t iwl_dbgfs_ucode_rx_stats_read(struct file *file,
  902. char __user *user_buf,
  903. size_t count, loff_t *ppos)
  904. {
  905. struct iwl_priv *priv = file->private_data;
  906. return priv->cfg->ops->lib->debugfs_ops.rx_stats_read(file,
  907. user_buf, count, ppos);
  908. }
  909. static ssize_t iwl_dbgfs_ucode_tx_stats_read(struct file *file,
  910. char __user *user_buf,
  911. size_t count, loff_t *ppos)
  912. {
  913. struct iwl_priv *priv = file->private_data;
  914. return priv->cfg->ops->lib->debugfs_ops.tx_stats_read(file,
  915. user_buf, count, ppos);
  916. }
  917. static ssize_t iwl_dbgfs_ucode_general_stats_read(struct file *file,
  918. char __user *user_buf,
  919. size_t count, loff_t *ppos)
  920. {
  921. struct iwl_priv *priv = file->private_data;
  922. return priv->cfg->ops->lib->debugfs_ops.general_stats_read(file,
  923. user_buf, count, ppos);
  924. }
  925. static ssize_t iwl_dbgfs_sensitivity_read(struct file *file,
  926. char __user *user_buf,
  927. size_t count, loff_t *ppos) {
  928. struct iwl_priv *priv = file->private_data;
  929. int pos = 0;
  930. int cnt = 0;
  931. char *buf;
  932. int bufsz = sizeof(struct iwl_sensitivity_data) * 4 + 100;
  933. ssize_t ret;
  934. struct iwl_sensitivity_data *data;
  935. data = &priv->sensitivity_data;
  936. buf = kzalloc(bufsz, GFP_KERNEL);
  937. if (!buf) {
  938. IWL_ERR(priv, "Can not allocate Buffer\n");
  939. return -ENOMEM;
  940. }
  941. pos += scnprintf(buf + pos, bufsz - pos, "auto_corr_ofdm:\t\t\t %u\n",
  942. data->auto_corr_ofdm);
  943. pos += scnprintf(buf + pos, bufsz - pos,
  944. "auto_corr_ofdm_mrc:\t\t %u\n",
  945. data->auto_corr_ofdm_mrc);
  946. pos += scnprintf(buf + pos, bufsz - pos, "auto_corr_ofdm_x1:\t\t %u\n",
  947. data->auto_corr_ofdm_x1);
  948. pos += scnprintf(buf + pos, bufsz - pos,
  949. "auto_corr_ofdm_mrc_x1:\t\t %u\n",
  950. data->auto_corr_ofdm_mrc_x1);
  951. pos += scnprintf(buf + pos, bufsz - pos, "auto_corr_cck:\t\t\t %u\n",
  952. data->auto_corr_cck);
  953. pos += scnprintf(buf + pos, bufsz - pos, "auto_corr_cck_mrc:\t\t %u\n",
  954. data->auto_corr_cck_mrc);
  955. pos += scnprintf(buf + pos, bufsz - pos,
  956. "last_bad_plcp_cnt_ofdm:\t\t %u\n",
  957. data->last_bad_plcp_cnt_ofdm);
  958. pos += scnprintf(buf + pos, bufsz - pos, "last_fa_cnt_ofdm:\t\t %u\n",
  959. data->last_fa_cnt_ofdm);
  960. pos += scnprintf(buf + pos, bufsz - pos,
  961. "last_bad_plcp_cnt_cck:\t\t %u\n",
  962. data->last_bad_plcp_cnt_cck);
  963. pos += scnprintf(buf + pos, bufsz - pos, "last_fa_cnt_cck:\t\t %u\n",
  964. data->last_fa_cnt_cck);
  965. pos += scnprintf(buf + pos, bufsz - pos, "nrg_curr_state:\t\t\t %u\n",
  966. data->nrg_curr_state);
  967. pos += scnprintf(buf + pos, bufsz - pos, "nrg_prev_state:\t\t\t %u\n",
  968. data->nrg_prev_state);
  969. pos += scnprintf(buf + pos, bufsz - pos, "nrg_value:\t\t\t");
  970. for (cnt = 0; cnt < 10; cnt++) {
  971. pos += scnprintf(buf + pos, bufsz - pos, " %u",
  972. data->nrg_value[cnt]);
  973. }
  974. pos += scnprintf(buf + pos, bufsz - pos, "\n");
  975. pos += scnprintf(buf + pos, bufsz - pos, "nrg_silence_rssi:\t\t");
  976. for (cnt = 0; cnt < NRG_NUM_PREV_STAT_L; cnt++) {
  977. pos += scnprintf(buf + pos, bufsz - pos, " %u",
  978. data->nrg_silence_rssi[cnt]);
  979. }
  980. pos += scnprintf(buf + pos, bufsz - pos, "\n");
  981. pos += scnprintf(buf + pos, bufsz - pos, "nrg_silence_ref:\t\t %u\n",
  982. data->nrg_silence_ref);
  983. pos += scnprintf(buf + pos, bufsz - pos, "nrg_energy_idx:\t\t\t %u\n",
  984. data->nrg_energy_idx);
  985. pos += scnprintf(buf + pos, bufsz - pos, "nrg_silence_idx:\t\t %u\n",
  986. data->nrg_silence_idx);
  987. pos += scnprintf(buf + pos, bufsz - pos, "nrg_th_cck:\t\t\t %u\n",
  988. data->nrg_th_cck);
  989. pos += scnprintf(buf + pos, bufsz - pos,
  990. "nrg_auto_corr_silence_diff:\t %u\n",
  991. data->nrg_auto_corr_silence_diff);
  992. pos += scnprintf(buf + pos, bufsz - pos, "num_in_cck_no_fa:\t\t %u\n",
  993. data->num_in_cck_no_fa);
  994. pos += scnprintf(buf + pos, bufsz - pos, "nrg_th_ofdm:\t\t\t %u\n",
  995. data->nrg_th_ofdm);
  996. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  997. kfree(buf);
  998. return ret;
  999. }
  1000. static ssize_t iwl_dbgfs_chain_noise_read(struct file *file,
  1001. char __user *user_buf,
  1002. size_t count, loff_t *ppos) {
  1003. struct iwl_priv *priv = file->private_data;
  1004. int pos = 0;
  1005. int cnt = 0;
  1006. char *buf;
  1007. int bufsz = sizeof(struct iwl_chain_noise_data) * 4 + 100;
  1008. ssize_t ret;
  1009. struct iwl_chain_noise_data *data;
  1010. data = &priv->chain_noise_data;
  1011. buf = kzalloc(bufsz, GFP_KERNEL);
  1012. if (!buf) {
  1013. IWL_ERR(priv, "Can not allocate Buffer\n");
  1014. return -ENOMEM;
  1015. }
  1016. pos += scnprintf(buf + pos, bufsz - pos, "active_chains:\t\t\t %u\n",
  1017. data->active_chains);
  1018. pos += scnprintf(buf + pos, bufsz - pos, "chain_noise_a:\t\t\t %u\n",
  1019. data->chain_noise_a);
  1020. pos += scnprintf(buf + pos, bufsz - pos, "chain_noise_b:\t\t\t %u\n",
  1021. data->chain_noise_b);
  1022. pos += scnprintf(buf + pos, bufsz - pos, "chain_noise_c:\t\t\t %u\n",
  1023. data->chain_noise_c);
  1024. pos += scnprintf(buf + pos, bufsz - pos, "chain_signal_a:\t\t\t %u\n",
  1025. data->chain_signal_a);
  1026. pos += scnprintf(buf + pos, bufsz - pos, "chain_signal_b:\t\t\t %u\n",
  1027. data->chain_signal_b);
  1028. pos += scnprintf(buf + pos, bufsz - pos, "chain_signal_c:\t\t\t %u\n",
  1029. data->chain_signal_c);
  1030. pos += scnprintf(buf + pos, bufsz - pos, "beacon_count:\t\t\t %u\n",
  1031. data->beacon_count);
  1032. pos += scnprintf(buf + pos, bufsz - pos, "disconn_array:\t\t\t");
  1033. for (cnt = 0; cnt < NUM_RX_CHAINS; cnt++) {
  1034. pos += scnprintf(buf + pos, bufsz - pos, " %u",
  1035. data->disconn_array[cnt]);
  1036. }
  1037. pos += scnprintf(buf + pos, bufsz - pos, "\n");
  1038. pos += scnprintf(buf + pos, bufsz - pos, "delta_gain_code:\t\t");
  1039. for (cnt = 0; cnt < NUM_RX_CHAINS; cnt++) {
  1040. pos += scnprintf(buf + pos, bufsz - pos, " %u",
  1041. data->delta_gain_code[cnt]);
  1042. }
  1043. pos += scnprintf(buf + pos, bufsz - pos, "\n");
  1044. pos += scnprintf(buf + pos, bufsz - pos, "radio_write:\t\t\t %u\n",
  1045. data->radio_write);
  1046. pos += scnprintf(buf + pos, bufsz - pos, "state:\t\t\t\t %u\n",
  1047. data->state);
  1048. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  1049. kfree(buf);
  1050. return ret;
  1051. }
  1052. static ssize_t iwl_dbgfs_power_save_status_read(struct file *file,
  1053. char __user *user_buf,
  1054. size_t count, loff_t *ppos)
  1055. {
  1056. struct iwl_priv *priv = file->private_data;
  1057. char buf[60];
  1058. int pos = 0;
  1059. const size_t bufsz = sizeof(buf);
  1060. u32 pwrsave_status;
  1061. pwrsave_status = iwl_read32(priv, CSR_GP_CNTRL) &
  1062. CSR_GP_REG_POWER_SAVE_STATUS_MSK;
  1063. pos += scnprintf(buf + pos, bufsz - pos, "Power Save Status: ");
  1064. pos += scnprintf(buf + pos, bufsz - pos, "%s\n",
  1065. (pwrsave_status == CSR_GP_REG_NO_POWER_SAVE) ? "none" :
  1066. (pwrsave_status == CSR_GP_REG_MAC_POWER_SAVE) ? "MAC" :
  1067. (pwrsave_status == CSR_GP_REG_PHY_POWER_SAVE) ? "PHY" :
  1068. "error");
  1069. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  1070. }
  1071. static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
  1072. const char __user *user_buf,
  1073. size_t count, loff_t *ppos)
  1074. {
  1075. struct iwl_priv *priv = file->private_data;
  1076. char buf[8];
  1077. int buf_size;
  1078. int clear;
  1079. memset(buf, 0, sizeof(buf));
  1080. buf_size = min(count, sizeof(buf) - 1);
  1081. if (copy_from_user(buf, user_buf, buf_size))
  1082. return -EFAULT;
  1083. if (sscanf(buf, "%d", &clear) != 1)
  1084. return -EFAULT;
  1085. /* make request to uCode to retrieve statistics information */
  1086. mutex_lock(&priv->mutex);
  1087. iwl_send_statistics_request(priv, CMD_SYNC, true);
  1088. mutex_unlock(&priv->mutex);
  1089. return count;
  1090. }
  1091. static ssize_t iwl_dbgfs_csr_write(struct file *file,
  1092. const char __user *user_buf,
  1093. size_t count, loff_t *ppos)
  1094. {
  1095. struct iwl_priv *priv = file->private_data;
  1096. char buf[8];
  1097. int buf_size;
  1098. int csr;
  1099. memset(buf, 0, sizeof(buf));
  1100. buf_size = min(count, sizeof(buf) - 1);
  1101. if (copy_from_user(buf, user_buf, buf_size))
  1102. return -EFAULT;
  1103. if (sscanf(buf, "%d", &csr) != 1)
  1104. return -EFAULT;
  1105. if (priv->cfg->ops->lib->dump_csr)
  1106. priv->cfg->ops->lib->dump_csr(priv);
  1107. return count;
  1108. }
  1109. static ssize_t iwl_dbgfs_ucode_tracing_read(struct file *file,
  1110. char __user *user_buf,
  1111. size_t count, loff_t *ppos) {
  1112. struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
  1113. int pos = 0;
  1114. char buf[128];
  1115. const size_t bufsz = sizeof(buf);
  1116. pos += scnprintf(buf + pos, bufsz - pos, "ucode trace timer is %s\n",
  1117. priv->event_log.ucode_trace ? "On" : "Off");
  1118. pos += scnprintf(buf + pos, bufsz - pos, "non_wraps_count:\t\t %u\n",
  1119. priv->event_log.non_wraps_count);
  1120. pos += scnprintf(buf + pos, bufsz - pos, "wraps_once_count:\t\t %u\n",
  1121. priv->event_log.wraps_once_count);
  1122. pos += scnprintf(buf + pos, bufsz - pos, "wraps_more_count:\t\t %u\n",
  1123. priv->event_log.wraps_more_count);
  1124. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  1125. }
  1126. static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
  1127. const char __user *user_buf,
  1128. size_t count, loff_t *ppos)
  1129. {
  1130. struct iwl_priv *priv = file->private_data;
  1131. char buf[8];
  1132. int buf_size;
  1133. int trace;
  1134. memset(buf, 0, sizeof(buf));
  1135. buf_size = min(count, sizeof(buf) - 1);
  1136. if (copy_from_user(buf, user_buf, buf_size))
  1137. return -EFAULT;
  1138. if (sscanf(buf, "%d", &trace) != 1)
  1139. return -EFAULT;
  1140. if (trace) {
  1141. priv->event_log.ucode_trace = true;
  1142. /* schedule the ucode timer to occur in UCODE_TRACE_PERIOD */
  1143. mod_timer(&priv->ucode_trace,
  1144. jiffies + msecs_to_jiffies(UCODE_TRACE_PERIOD));
  1145. } else {
  1146. priv->event_log.ucode_trace = false;
  1147. del_timer_sync(&priv->ucode_trace);
  1148. }
  1149. return count;
  1150. }
  1151. static ssize_t iwl_dbgfs_rxon_flags_read(struct file *file,
  1152. char __user *user_buf,
  1153. size_t count, loff_t *ppos) {
  1154. struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
  1155. int len = 0;
  1156. char buf[20];
  1157. len = sprintf(buf, "0x%04X\n", le32_to_cpu(priv->active_rxon.flags));
  1158. return simple_read_from_buffer(user_buf, count, ppos, buf, len);
  1159. }
  1160. static ssize_t iwl_dbgfs_rxon_filter_flags_read(struct file *file,
  1161. char __user *user_buf,
  1162. size_t count, loff_t *ppos) {
  1163. struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
  1164. int len = 0;
  1165. char buf[20];
  1166. len = sprintf(buf, "0x%04X\n",
  1167. le32_to_cpu(priv->active_rxon.filter_flags));
  1168. return simple_read_from_buffer(user_buf, count, ppos, buf, len);
  1169. }
  1170. static ssize_t iwl_dbgfs_fh_reg_read(struct file *file,
  1171. char __user *user_buf,
  1172. size_t count, loff_t *ppos)
  1173. {
  1174. struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
  1175. char *buf;
  1176. int pos = 0;
  1177. ssize_t ret = -EFAULT;
  1178. if (priv->cfg->ops->lib->dump_fh) {
  1179. ret = pos = priv->cfg->ops->lib->dump_fh(priv, &buf, true);
  1180. if (buf) {
  1181. ret = simple_read_from_buffer(user_buf,
  1182. count, ppos, buf, pos);
  1183. kfree(buf);
  1184. }
  1185. }
  1186. return ret;
  1187. }
  1188. static ssize_t iwl_dbgfs_missed_beacon_read(struct file *file,
  1189. char __user *user_buf,
  1190. size_t count, loff_t *ppos) {
  1191. struct iwl_priv *priv = file->private_data;
  1192. int pos = 0;
  1193. char buf[12];
  1194. const size_t bufsz = sizeof(buf);
  1195. pos += scnprintf(buf + pos, bufsz - pos, "%d\n",
  1196. priv->missed_beacon_threshold);
  1197. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  1198. }
  1199. static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
  1200. const char __user *user_buf,
  1201. size_t count, loff_t *ppos)
  1202. {
  1203. struct iwl_priv *priv = file->private_data;
  1204. char buf[8];
  1205. int buf_size;
  1206. int missed;
  1207. memset(buf, 0, sizeof(buf));
  1208. buf_size = min(count, sizeof(buf) - 1);
  1209. if (copy_from_user(buf, user_buf, buf_size))
  1210. return -EFAULT;
  1211. if (sscanf(buf, "%d", &missed) != 1)
  1212. return -EINVAL;
  1213. if (missed < IWL_MISSED_BEACON_THRESHOLD_MIN ||
  1214. missed > IWL_MISSED_BEACON_THRESHOLD_MAX)
  1215. priv->missed_beacon_threshold =
  1216. IWL_MISSED_BEACON_THRESHOLD_DEF;
  1217. else
  1218. priv->missed_beacon_threshold = missed;
  1219. return count;
  1220. }
  1221. static ssize_t iwl_dbgfs_plcp_delta_read(struct file *file,
  1222. char __user *user_buf,
  1223. size_t count, loff_t *ppos) {
  1224. struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
  1225. int pos = 0;
  1226. char buf[12];
  1227. const size_t bufsz = sizeof(buf);
  1228. pos += scnprintf(buf + pos, bufsz - pos, "%u\n",
  1229. priv->cfg->plcp_delta_threshold);
  1230. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  1231. }
  1232. static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
  1233. const char __user *user_buf,
  1234. size_t count, loff_t *ppos) {
  1235. struct iwl_priv *priv = file->private_data;
  1236. char buf[8];
  1237. int buf_size;
  1238. int plcp;
  1239. memset(buf, 0, sizeof(buf));
  1240. buf_size = min(count, sizeof(buf) - 1);
  1241. if (copy_from_user(buf, user_buf, buf_size))
  1242. return -EFAULT;
  1243. if (sscanf(buf, "%d", &plcp) != 1)
  1244. return -EINVAL;
  1245. if ((plcp <= IWL_MAX_PLCP_ERR_THRESHOLD_MIN) ||
  1246. (plcp > IWL_MAX_PLCP_ERR_THRESHOLD_MAX))
  1247. priv->cfg->plcp_delta_threshold =
  1248. IWL_MAX_PLCP_ERR_THRESHOLD_DEF;
  1249. else
  1250. priv->cfg->plcp_delta_threshold = plcp;
  1251. return count;
  1252. }
  1253. static ssize_t iwl_dbgfs_force_reset_read(struct file *file,
  1254. char __user *user_buf,
  1255. size_t count, loff_t *ppos) {
  1256. struct iwl_priv *priv = file->private_data;
  1257. int i, pos = 0;
  1258. char buf[300];
  1259. const size_t bufsz = sizeof(buf);
  1260. struct iwl_force_reset *force_reset;
  1261. for (i = 0; i < IWL_MAX_FORCE_RESET; i++) {
  1262. force_reset = &priv->force_reset[i];
  1263. pos += scnprintf(buf + pos, bufsz - pos,
  1264. "Force reset method %d\n", i);
  1265. pos += scnprintf(buf + pos, bufsz - pos,
  1266. "\tnumber of reset request: %d\n",
  1267. force_reset->reset_request_count);
  1268. pos += scnprintf(buf + pos, bufsz - pos,
  1269. "\tnumber of reset request success: %d\n",
  1270. force_reset->reset_success_count);
  1271. pos += scnprintf(buf + pos, bufsz - pos,
  1272. "\tnumber of reset request reject: %d\n",
  1273. force_reset->reset_reject_count);
  1274. pos += scnprintf(buf + pos, bufsz - pos,
  1275. "\treset duration: %lu\n",
  1276. force_reset->reset_duration);
  1277. }
  1278. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  1279. }
  1280. static ssize_t iwl_dbgfs_force_reset_write(struct file *file,
  1281. const char __user *user_buf,
  1282. size_t count, loff_t *ppos) {
  1283. struct iwl_priv *priv = file->private_data;
  1284. char buf[8];
  1285. int buf_size;
  1286. int reset, ret;
  1287. memset(buf, 0, sizeof(buf));
  1288. buf_size = min(count, sizeof(buf) - 1);
  1289. if (copy_from_user(buf, user_buf, buf_size))
  1290. return -EFAULT;
  1291. if (sscanf(buf, "%d", &reset) != 1)
  1292. return -EINVAL;
  1293. switch (reset) {
  1294. case IWL_RF_RESET:
  1295. case IWL_FW_RESET:
  1296. ret = iwl_force_reset(priv, reset);
  1297. break;
  1298. default:
  1299. return -EINVAL;
  1300. }
  1301. return ret ? ret : count;
  1302. }
  1303. DEBUGFS_READ_FILE_OPS(rx_statistics);
  1304. DEBUGFS_READ_FILE_OPS(tx_statistics);
  1305. DEBUGFS_READ_WRITE_FILE_OPS(traffic_log);
  1306. DEBUGFS_READ_FILE_OPS(rx_queue);
  1307. DEBUGFS_READ_FILE_OPS(tx_queue);
  1308. DEBUGFS_READ_FILE_OPS(ucode_rx_stats);
  1309. DEBUGFS_READ_FILE_OPS(ucode_tx_stats);
  1310. DEBUGFS_READ_FILE_OPS(ucode_general_stats);
  1311. DEBUGFS_READ_FILE_OPS(sensitivity);
  1312. DEBUGFS_READ_FILE_OPS(chain_noise);
  1313. DEBUGFS_READ_FILE_OPS(power_save_status);
  1314. DEBUGFS_WRITE_FILE_OPS(clear_ucode_statistics);
  1315. DEBUGFS_WRITE_FILE_OPS(clear_traffic_statistics);
  1316. DEBUGFS_WRITE_FILE_OPS(csr);
  1317. DEBUGFS_READ_WRITE_FILE_OPS(ucode_tracing);
  1318. DEBUGFS_READ_FILE_OPS(fh_reg);
  1319. DEBUGFS_READ_WRITE_FILE_OPS(missed_beacon);
  1320. DEBUGFS_READ_WRITE_FILE_OPS(plcp_delta);
  1321. DEBUGFS_READ_WRITE_FILE_OPS(force_reset);
  1322. DEBUGFS_READ_FILE_OPS(rxon_flags);
  1323. DEBUGFS_READ_FILE_OPS(rxon_filter_flags);
  1324. /*
  1325. * Create the debugfs files and directories
  1326. *
  1327. */
  1328. int iwl_dbgfs_register(struct iwl_priv *priv, const char *name)
  1329. {
  1330. struct dentry *phyd = priv->hw->wiphy->debugfsdir;
  1331. struct dentry *dir_drv, *dir_data, *dir_rf, *dir_debug;
  1332. dir_drv = debugfs_create_dir(name, phyd);
  1333. if (!dir_drv)
  1334. return -ENOMEM;
  1335. priv->debugfs_dir = dir_drv;
  1336. dir_data = debugfs_create_dir("data", dir_drv);
  1337. if (!dir_data)
  1338. goto err;
  1339. dir_rf = debugfs_create_dir("rf", dir_drv);
  1340. if (!dir_rf)
  1341. goto err;
  1342. dir_debug = debugfs_create_dir("debug", dir_drv);
  1343. if (!dir_debug)
  1344. goto err;
  1345. DEBUGFS_ADD_FILE(nvm, dir_data, S_IRUSR);
  1346. DEBUGFS_ADD_FILE(sram, dir_data, S_IWUSR | S_IRUSR);
  1347. DEBUGFS_ADD_FILE(log_event, dir_data, S_IWUSR | S_IRUSR);
  1348. DEBUGFS_ADD_FILE(stations, dir_data, S_IRUSR);
  1349. DEBUGFS_ADD_FILE(channels, dir_data, S_IRUSR);
  1350. DEBUGFS_ADD_FILE(status, dir_data, S_IRUSR);
  1351. DEBUGFS_ADD_FILE(interrupt, dir_data, S_IWUSR | S_IRUSR);
  1352. DEBUGFS_ADD_FILE(qos, dir_data, S_IRUSR);
  1353. DEBUGFS_ADD_FILE(led, dir_data, S_IRUSR);
  1354. if (!priv->cfg->broken_powersave) {
  1355. DEBUGFS_ADD_FILE(sleep_level_override, dir_data,
  1356. S_IWUSR | S_IRUSR);
  1357. DEBUGFS_ADD_FILE(current_sleep_command, dir_data, S_IRUSR);
  1358. }
  1359. DEBUGFS_ADD_FILE(thermal_throttling, dir_data, S_IRUSR);
  1360. DEBUGFS_ADD_FILE(disable_ht40, dir_data, S_IWUSR | S_IRUSR);
  1361. DEBUGFS_ADD_FILE(rx_statistics, dir_debug, S_IRUSR);
  1362. DEBUGFS_ADD_FILE(tx_statistics, dir_debug, S_IRUSR);
  1363. DEBUGFS_ADD_FILE(traffic_log, dir_debug, S_IWUSR | S_IRUSR);
  1364. DEBUGFS_ADD_FILE(rx_queue, dir_debug, S_IRUSR);
  1365. DEBUGFS_ADD_FILE(tx_queue, dir_debug, S_IRUSR);
  1366. DEBUGFS_ADD_FILE(power_save_status, dir_debug, S_IRUSR);
  1367. DEBUGFS_ADD_FILE(clear_ucode_statistics, dir_debug, S_IWUSR);
  1368. DEBUGFS_ADD_FILE(clear_traffic_statistics, dir_debug, S_IWUSR);
  1369. DEBUGFS_ADD_FILE(csr, dir_debug, S_IWUSR);
  1370. DEBUGFS_ADD_FILE(fh_reg, dir_debug, S_IRUSR);
  1371. DEBUGFS_ADD_FILE(missed_beacon, dir_debug, S_IWUSR);
  1372. DEBUGFS_ADD_FILE(plcp_delta, dir_debug, S_IWUSR | S_IRUSR);
  1373. DEBUGFS_ADD_FILE(force_reset, dir_debug, S_IWUSR | S_IRUSR);
  1374. DEBUGFS_ADD_FILE(ucode_rx_stats, dir_debug, S_IRUSR);
  1375. DEBUGFS_ADD_FILE(ucode_tx_stats, dir_debug, S_IRUSR);
  1376. DEBUGFS_ADD_FILE(ucode_general_stats, dir_debug, S_IRUSR);
  1377. if (priv->cfg->sensitivity_calib_by_driver)
  1378. DEBUGFS_ADD_FILE(sensitivity, dir_debug, S_IRUSR);
  1379. if (priv->cfg->chain_noise_calib_by_driver)
  1380. DEBUGFS_ADD_FILE(chain_noise, dir_debug, S_IRUSR);
  1381. if (priv->cfg->ucode_tracing)
  1382. DEBUGFS_ADD_FILE(ucode_tracing, dir_debug, S_IWUSR | S_IRUSR);
  1383. DEBUGFS_ADD_FILE(rxon_flags, dir_debug, S_IWUSR);
  1384. DEBUGFS_ADD_FILE(rxon_filter_flags, dir_debug, S_IWUSR);
  1385. if (priv->cfg->sensitivity_calib_by_driver)
  1386. DEBUGFS_ADD_BOOL(disable_sensitivity, dir_rf,
  1387. &priv->disable_sens_cal);
  1388. if (priv->cfg->chain_noise_calib_by_driver)
  1389. DEBUGFS_ADD_BOOL(disable_chain_noise, dir_rf,
  1390. &priv->disable_chain_noise_cal);
  1391. if (priv->cfg->tx_power_by_driver)
  1392. DEBUGFS_ADD_BOOL(disable_tx_power, dir_rf,
  1393. &priv->disable_tx_power_cal);
  1394. return 0;
  1395. err:
  1396. IWL_ERR(priv, "Can't create the debugfs directory\n");
  1397. iwl_dbgfs_unregister(priv);
  1398. return -ENOMEM;
  1399. }
  1400. EXPORT_SYMBOL(iwl_dbgfs_register);
  1401. /**
  1402. * Remove the debugfs files and directories
  1403. *
  1404. */
  1405. void iwl_dbgfs_unregister(struct iwl_priv *priv)
  1406. {
  1407. if (!priv->debugfs_dir)
  1408. return;
  1409. debugfs_remove_recursive(priv->debugfs_dir);
  1410. priv->debugfs_dir = NULL;
  1411. }
  1412. EXPORT_SYMBOL(iwl_dbgfs_unregister);