iwl-debugfs.c 49 KB

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