iwl-debugfs.c 48 KB

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