debugfs.c 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204
  1. /******************************************************************************
  2. *
  3. * This file is provided under a dual BSD/GPLv2 license. When using or
  4. * redistributing this file, you may do so under either license.
  5. *
  6. * GPL LICENSE SUMMARY
  7. *
  8. * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of version 2 of the GNU General Public License as
  12. * published by the Free Software Foundation.
  13. *
  14. * This program is distributed in the hope that it will be useful, but
  15. * WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
  22. * USA
  23. *
  24. * The full GNU General Public License is included in this distribution
  25. * in the file called COPYING.
  26. *
  27. * Contact Information:
  28. * Intel Linux Wireless <ilw@linux.intel.com>
  29. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  30. *
  31. * BSD LICENSE
  32. *
  33. * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
  34. * All rights reserved.
  35. *
  36. * Redistribution and use in source and binary forms, with or without
  37. * modification, are permitted provided that the following conditions
  38. * are met:
  39. *
  40. * * Redistributions of source code must retain the above copyright
  41. * notice, this list of conditions and the following disclaimer.
  42. * * Redistributions in binary form must reproduce the above copyright
  43. * notice, this list of conditions and the following disclaimer in
  44. * the documentation and/or other materials provided with the
  45. * distribution.
  46. * * Neither the name Intel Corporation nor the names of its
  47. * contributors may be used to endorse or promote products derived
  48. * from this software without specific prior written permission.
  49. *
  50. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  51. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  52. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  53. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  54. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  55. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  56. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  57. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  58. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  59. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  60. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  61. *
  62. *****************************************************************************/
  63. #include <linux/vmalloc.h>
  64. #include "mvm.h"
  65. #include "sta.h"
  66. #include "iwl-io.h"
  67. #include "debugfs.h"
  68. #include "iwl-fw-error-dump.h"
  69. static ssize_t iwl_dbgfs_tx_flush_write(struct iwl_mvm *mvm, char *buf,
  70. size_t count, loff_t *ppos)
  71. {
  72. int ret;
  73. u32 scd_q_msk;
  74. if (!mvm->ucode_loaded || mvm->cur_ucode != IWL_UCODE_REGULAR)
  75. return -EIO;
  76. if (sscanf(buf, "%x", &scd_q_msk) != 1)
  77. return -EINVAL;
  78. IWL_ERR(mvm, "FLUSHING queues: scd_q_msk = 0x%x\n", scd_q_msk);
  79. mutex_lock(&mvm->mutex);
  80. ret = iwl_mvm_flush_tx_path(mvm, scd_q_msk, true) ? : count;
  81. mutex_unlock(&mvm->mutex);
  82. return ret;
  83. }
  84. static ssize_t iwl_dbgfs_sta_drain_write(struct iwl_mvm *mvm, char *buf,
  85. size_t count, loff_t *ppos)
  86. {
  87. struct iwl_mvm_sta *mvmsta;
  88. int sta_id, drain, ret;
  89. if (!mvm->ucode_loaded || mvm->cur_ucode != IWL_UCODE_REGULAR)
  90. return -EIO;
  91. if (sscanf(buf, "%d %d", &sta_id, &drain) != 2)
  92. return -EINVAL;
  93. if (sta_id < 0 || sta_id >= IWL_MVM_STATION_COUNT)
  94. return -EINVAL;
  95. if (drain < 0 || drain > 1)
  96. return -EINVAL;
  97. mutex_lock(&mvm->mutex);
  98. mvmsta = iwl_mvm_sta_from_staid_protected(mvm, sta_id);
  99. if (!mvmsta)
  100. ret = -ENOENT;
  101. else
  102. ret = iwl_mvm_drain_sta(mvm, mvmsta, drain) ? : count;
  103. mutex_unlock(&mvm->mutex);
  104. return ret;
  105. }
  106. static int iwl_dbgfs_fw_error_dump_open(struct inode *inode, struct file *file)
  107. {
  108. struct iwl_mvm *mvm = inode->i_private;
  109. int ret;
  110. if (!mvm)
  111. return -EINVAL;
  112. mutex_lock(&mvm->mutex);
  113. if (!mvm->fw_error_dump) {
  114. ret = -ENODATA;
  115. goto out;
  116. }
  117. file->private_data = mvm->fw_error_dump;
  118. mvm->fw_error_dump = NULL;
  119. ret = 0;
  120. out:
  121. mutex_unlock(&mvm->mutex);
  122. return ret;
  123. }
  124. static ssize_t iwl_dbgfs_fw_error_dump_read(struct file *file,
  125. char __user *user_buf,
  126. size_t count, loff_t *ppos)
  127. {
  128. struct iwl_fw_error_dump_file *dump_file = file->private_data;
  129. return simple_read_from_buffer(user_buf, count, ppos,
  130. dump_file,
  131. le32_to_cpu(dump_file->file_len));
  132. }
  133. static int iwl_dbgfs_fw_error_dump_release(struct inode *inode,
  134. struct file *file)
  135. {
  136. vfree(file->private_data);
  137. return 0;
  138. }
  139. static ssize_t iwl_dbgfs_sram_read(struct file *file, char __user *user_buf,
  140. size_t count, loff_t *ppos)
  141. {
  142. struct iwl_mvm *mvm = file->private_data;
  143. const struct fw_img *img;
  144. unsigned int ofs, len;
  145. size_t ret;
  146. u8 *ptr;
  147. if (!mvm->ucode_loaded)
  148. return -EINVAL;
  149. /* default is to dump the entire data segment */
  150. img = &mvm->fw->img[mvm->cur_ucode];
  151. ofs = img->sec[IWL_UCODE_SECTION_DATA].offset;
  152. len = img->sec[IWL_UCODE_SECTION_DATA].len;
  153. if (mvm->dbgfs_sram_len) {
  154. ofs = mvm->dbgfs_sram_offset;
  155. len = mvm->dbgfs_sram_len;
  156. }
  157. ptr = kzalloc(len, GFP_KERNEL);
  158. if (!ptr)
  159. return -ENOMEM;
  160. iwl_trans_read_mem_bytes(mvm->trans, ofs, ptr, len);
  161. ret = simple_read_from_buffer(user_buf, count, ppos, ptr, len);
  162. kfree(ptr);
  163. return ret;
  164. }
  165. static ssize_t iwl_dbgfs_sram_write(struct iwl_mvm *mvm, char *buf,
  166. size_t count, loff_t *ppos)
  167. {
  168. const struct fw_img *img;
  169. u32 offset, len;
  170. u32 img_offset, img_len;
  171. if (!mvm->ucode_loaded)
  172. return -EINVAL;
  173. img = &mvm->fw->img[mvm->cur_ucode];
  174. img_offset = img->sec[IWL_UCODE_SECTION_DATA].offset;
  175. img_len = img->sec[IWL_UCODE_SECTION_DATA].len;
  176. if (sscanf(buf, "%x,%x", &offset, &len) == 2) {
  177. if ((offset & 0x3) || (len & 0x3))
  178. return -EINVAL;
  179. if (offset + len > img_offset + img_len)
  180. return -EINVAL;
  181. mvm->dbgfs_sram_offset = offset;
  182. mvm->dbgfs_sram_len = len;
  183. } else {
  184. mvm->dbgfs_sram_offset = 0;
  185. mvm->dbgfs_sram_len = 0;
  186. }
  187. return count;
  188. }
  189. static ssize_t iwl_dbgfs_stations_read(struct file *file, char __user *user_buf,
  190. size_t count, loff_t *ppos)
  191. {
  192. struct iwl_mvm *mvm = file->private_data;
  193. struct ieee80211_sta *sta;
  194. char buf[400];
  195. int i, pos = 0, bufsz = sizeof(buf);
  196. mutex_lock(&mvm->mutex);
  197. for (i = 0; i < IWL_MVM_STATION_COUNT; i++) {
  198. pos += scnprintf(buf + pos, bufsz - pos, "%.2d: ", i);
  199. sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[i],
  200. lockdep_is_held(&mvm->mutex));
  201. if (!sta)
  202. pos += scnprintf(buf + pos, bufsz - pos, "N/A\n");
  203. else if (IS_ERR(sta))
  204. pos += scnprintf(buf + pos, bufsz - pos, "%ld\n",
  205. PTR_ERR(sta));
  206. else
  207. pos += scnprintf(buf + pos, bufsz - pos, "%pM\n",
  208. sta->addr);
  209. }
  210. mutex_unlock(&mvm->mutex);
  211. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  212. }
  213. static ssize_t iwl_dbgfs_disable_power_off_read(struct file *file,
  214. char __user *user_buf,
  215. size_t count, loff_t *ppos)
  216. {
  217. struct iwl_mvm *mvm = file->private_data;
  218. char buf[64];
  219. int bufsz = sizeof(buf);
  220. int pos = 0;
  221. pos += scnprintf(buf+pos, bufsz-pos, "disable_power_off_d0=%d\n",
  222. mvm->disable_power_off);
  223. pos += scnprintf(buf+pos, bufsz-pos, "disable_power_off_d3=%d\n",
  224. mvm->disable_power_off_d3);
  225. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  226. }
  227. static ssize_t iwl_dbgfs_disable_power_off_write(struct iwl_mvm *mvm, char *buf,
  228. size_t count, loff_t *ppos)
  229. {
  230. int ret, val;
  231. if (!mvm->ucode_loaded)
  232. return -EIO;
  233. if (!strncmp("disable_power_off_d0=", buf, 21)) {
  234. if (sscanf(buf + 21, "%d", &val) != 1)
  235. return -EINVAL;
  236. mvm->disable_power_off = val;
  237. } else if (!strncmp("disable_power_off_d3=", buf, 21)) {
  238. if (sscanf(buf + 21, "%d", &val) != 1)
  239. return -EINVAL;
  240. mvm->disable_power_off_d3 = val;
  241. } else {
  242. return -EINVAL;
  243. }
  244. mutex_lock(&mvm->mutex);
  245. ret = iwl_mvm_power_update_device(mvm);
  246. mutex_unlock(&mvm->mutex);
  247. return ret ?: count;
  248. }
  249. #define BT_MBOX_MSG(_notif, _num, _field) \
  250. ((le32_to_cpu((_notif)->mbox_msg[(_num)]) & BT_MBOX##_num##_##_field)\
  251. >> BT_MBOX##_num##_##_field##_POS)
  252. #define BT_MBOX_PRINT(_num, _field, _end) \
  253. pos += scnprintf(buf + pos, bufsz - pos, \
  254. "\t%s: %d%s", \
  255. #_field, \
  256. BT_MBOX_MSG(notif, _num, _field), \
  257. true ? "\n" : ", ");
  258. static ssize_t iwl_dbgfs_bt_notif_read(struct file *file, char __user *user_buf,
  259. size_t count, loff_t *ppos)
  260. {
  261. struct iwl_mvm *mvm = file->private_data;
  262. struct iwl_bt_coex_profile_notif *notif = &mvm->last_bt_notif;
  263. char *buf;
  264. int ret, pos = 0, bufsz = sizeof(char) * 1024;
  265. buf = kmalloc(bufsz, GFP_KERNEL);
  266. if (!buf)
  267. return -ENOMEM;
  268. mutex_lock(&mvm->mutex);
  269. pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw0:\n");
  270. BT_MBOX_PRINT(0, LE_SLAVE_LAT, false);
  271. BT_MBOX_PRINT(0, LE_PROF1, false);
  272. BT_MBOX_PRINT(0, LE_PROF2, false);
  273. BT_MBOX_PRINT(0, LE_PROF_OTHER, false);
  274. BT_MBOX_PRINT(0, CHL_SEQ_N, false);
  275. BT_MBOX_PRINT(0, INBAND_S, false);
  276. BT_MBOX_PRINT(0, LE_MIN_RSSI, false);
  277. BT_MBOX_PRINT(0, LE_SCAN, false);
  278. BT_MBOX_PRINT(0, LE_ADV, false);
  279. BT_MBOX_PRINT(0, LE_MAX_TX_POWER, false);
  280. BT_MBOX_PRINT(0, OPEN_CON_1, true);
  281. pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw1:\n");
  282. BT_MBOX_PRINT(1, BR_MAX_TX_POWER, false);
  283. BT_MBOX_PRINT(1, IP_SR, false);
  284. BT_MBOX_PRINT(1, LE_MSTR, false);
  285. BT_MBOX_PRINT(1, AGGR_TRFC_LD, false);
  286. BT_MBOX_PRINT(1, MSG_TYPE, false);
  287. BT_MBOX_PRINT(1, SSN, true);
  288. pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw2:\n");
  289. BT_MBOX_PRINT(2, SNIFF_ACT, false);
  290. BT_MBOX_PRINT(2, PAG, false);
  291. BT_MBOX_PRINT(2, INQUIRY, false);
  292. BT_MBOX_PRINT(2, CONN, false);
  293. BT_MBOX_PRINT(2, SNIFF_INTERVAL, false);
  294. BT_MBOX_PRINT(2, DISC, false);
  295. BT_MBOX_PRINT(2, SCO_TX_ACT, false);
  296. BT_MBOX_PRINT(2, SCO_RX_ACT, false);
  297. BT_MBOX_PRINT(2, ESCO_RE_TX, false);
  298. BT_MBOX_PRINT(2, SCO_DURATION, true);
  299. pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw3:\n");
  300. BT_MBOX_PRINT(3, SCO_STATE, false);
  301. BT_MBOX_PRINT(3, SNIFF_STATE, false);
  302. BT_MBOX_PRINT(3, A2DP_STATE, false);
  303. BT_MBOX_PRINT(3, ACL_STATE, false);
  304. BT_MBOX_PRINT(3, MSTR_STATE, false);
  305. BT_MBOX_PRINT(3, OBX_STATE, false);
  306. BT_MBOX_PRINT(3, OPEN_CON_2, false);
  307. BT_MBOX_PRINT(3, TRAFFIC_LOAD, false);
  308. BT_MBOX_PRINT(3, CHL_SEQN_LSB, false);
  309. BT_MBOX_PRINT(3, INBAND_P, false);
  310. BT_MBOX_PRINT(3, MSG_TYPE_2, false);
  311. BT_MBOX_PRINT(3, SSN_2, false);
  312. BT_MBOX_PRINT(3, UPDATE_REQUEST, true);
  313. pos += scnprintf(buf+pos, bufsz-pos, "bt_status = %d\n",
  314. notif->bt_status);
  315. pos += scnprintf(buf+pos, bufsz-pos, "bt_open_conn = %d\n",
  316. notif->bt_open_conn);
  317. pos += scnprintf(buf+pos, bufsz-pos, "bt_traffic_load = %d\n",
  318. notif->bt_traffic_load);
  319. pos += scnprintf(buf+pos, bufsz-pos, "bt_agg_traffic_load = %d\n",
  320. notif->bt_agg_traffic_load);
  321. pos += scnprintf(buf+pos, bufsz-pos, "bt_ci_compliance = %d\n",
  322. notif->bt_ci_compliance);
  323. pos += scnprintf(buf+pos, bufsz-pos, "primary_ch_lut = %d\n",
  324. le32_to_cpu(notif->primary_ch_lut));
  325. pos += scnprintf(buf+pos, bufsz-pos, "secondary_ch_lut = %d\n",
  326. le32_to_cpu(notif->secondary_ch_lut));
  327. pos += scnprintf(buf+pos, bufsz-pos, "bt_activity_grading = %d\n",
  328. le32_to_cpu(notif->bt_activity_grading));
  329. pos += scnprintf(buf+pos, bufsz-pos,
  330. "antenna isolation = %d CORUN LUT index = %d\n",
  331. mvm->last_ant_isol, mvm->last_corun_lut);
  332. mutex_unlock(&mvm->mutex);
  333. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  334. kfree(buf);
  335. return ret;
  336. }
  337. #undef BT_MBOX_PRINT
  338. static ssize_t iwl_dbgfs_bt_cmd_read(struct file *file, char __user *user_buf,
  339. size_t count, loff_t *ppos)
  340. {
  341. struct iwl_mvm *mvm = file->private_data;
  342. struct iwl_bt_coex_ci_cmd *cmd = &mvm->last_bt_ci_cmd;
  343. char buf[256];
  344. int bufsz = sizeof(buf);
  345. int pos = 0;
  346. mutex_lock(&mvm->mutex);
  347. pos += scnprintf(buf+pos, bufsz-pos, "Channel inhibition CMD\n");
  348. pos += scnprintf(buf+pos, bufsz-pos,
  349. "\tPrimary Channel Bitmap 0x%016llx Fat: %d\n",
  350. le64_to_cpu(cmd->bt_primary_ci),
  351. !!cmd->co_run_bw_primary);
  352. pos += scnprintf(buf+pos, bufsz-pos,
  353. "\tSecondary Channel Bitmap 0x%016llx Fat: %d\n",
  354. le64_to_cpu(cmd->bt_secondary_ci),
  355. !!cmd->co_run_bw_secondary);
  356. pos += scnprintf(buf+pos, bufsz-pos, "BT Configuration CMD\n");
  357. pos += scnprintf(buf+pos, bufsz-pos, "\tACK Kill Mask 0x%08x\n",
  358. iwl_bt_ack_kill_msk[mvm->bt_kill_msk]);
  359. pos += scnprintf(buf+pos, bufsz-pos, "\tCTS Kill Mask 0x%08x\n",
  360. iwl_bt_cts_kill_msk[mvm->bt_kill_msk]);
  361. mutex_unlock(&mvm->mutex);
  362. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  363. }
  364. static ssize_t
  365. iwl_dbgfs_bt_tx_prio_write(struct iwl_mvm *mvm, char *buf,
  366. size_t count, loff_t *ppos)
  367. {
  368. u32 bt_tx_prio;
  369. if (sscanf(buf, "%u", &bt_tx_prio) != 1)
  370. return -EINVAL;
  371. if (bt_tx_prio > 4)
  372. return -EINVAL;
  373. mvm->bt_tx_prio = bt_tx_prio;
  374. return count;
  375. }
  376. #define PRINT_STATS_LE32(_str, _val) \
  377. pos += scnprintf(buf + pos, bufsz - pos, \
  378. fmt_table, _str, \
  379. le32_to_cpu(_val))
  380. static ssize_t iwl_dbgfs_fw_rx_stats_read(struct file *file,
  381. char __user *user_buf, size_t count,
  382. loff_t *ppos)
  383. {
  384. struct iwl_mvm *mvm = file->private_data;
  385. static const char *fmt_table = "\t%-30s %10u\n";
  386. static const char *fmt_header = "%-32s\n";
  387. int pos = 0;
  388. char *buf;
  389. int ret;
  390. /* 43 is the size of each data line, 33 is the size of each header */
  391. size_t bufsz =
  392. ((sizeof(struct mvm_statistics_rx) / sizeof(__le32)) * 43) +
  393. (4 * 33) + 1;
  394. struct mvm_statistics_rx_phy *ofdm;
  395. struct mvm_statistics_rx_phy *cck;
  396. struct mvm_statistics_rx_non_phy *general;
  397. struct mvm_statistics_rx_ht_phy *ht;
  398. buf = kzalloc(bufsz, GFP_KERNEL);
  399. if (!buf)
  400. return -ENOMEM;
  401. mutex_lock(&mvm->mutex);
  402. ofdm = &mvm->rx_stats.ofdm;
  403. cck = &mvm->rx_stats.cck;
  404. general = &mvm->rx_stats.general;
  405. ht = &mvm->rx_stats.ofdm_ht;
  406. pos += scnprintf(buf + pos, bufsz - pos, fmt_header,
  407. "Statistics_Rx - OFDM");
  408. PRINT_STATS_LE32("ina_cnt", ofdm->ina_cnt);
  409. PRINT_STATS_LE32("fina_cnt", ofdm->fina_cnt);
  410. PRINT_STATS_LE32("plcp_err", ofdm->plcp_err);
  411. PRINT_STATS_LE32("crc32_err", ofdm->crc32_err);
  412. PRINT_STATS_LE32("overrun_err", ofdm->overrun_err);
  413. PRINT_STATS_LE32("early_overrun_err", ofdm->early_overrun_err);
  414. PRINT_STATS_LE32("crc32_good", ofdm->crc32_good);
  415. PRINT_STATS_LE32("false_alarm_cnt", ofdm->false_alarm_cnt);
  416. PRINT_STATS_LE32("fina_sync_err_cnt", ofdm->fina_sync_err_cnt);
  417. PRINT_STATS_LE32("sfd_timeout", ofdm->sfd_timeout);
  418. PRINT_STATS_LE32("fina_timeout", ofdm->fina_timeout);
  419. PRINT_STATS_LE32("unresponded_rts", ofdm->unresponded_rts);
  420. PRINT_STATS_LE32("rxe_frame_lmt_overrun",
  421. ofdm->rxe_frame_limit_overrun);
  422. PRINT_STATS_LE32("sent_ack_cnt", ofdm->sent_ack_cnt);
  423. PRINT_STATS_LE32("sent_cts_cnt", ofdm->sent_cts_cnt);
  424. PRINT_STATS_LE32("sent_ba_rsp_cnt", ofdm->sent_ba_rsp_cnt);
  425. PRINT_STATS_LE32("dsp_self_kill", ofdm->dsp_self_kill);
  426. PRINT_STATS_LE32("mh_format_err", ofdm->mh_format_err);
  427. PRINT_STATS_LE32("re_acq_main_rssi_sum", ofdm->re_acq_main_rssi_sum);
  428. PRINT_STATS_LE32("reserved", ofdm->reserved);
  429. pos += scnprintf(buf + pos, bufsz - pos, fmt_header,
  430. "Statistics_Rx - CCK");
  431. PRINT_STATS_LE32("ina_cnt", cck->ina_cnt);
  432. PRINT_STATS_LE32("fina_cnt", cck->fina_cnt);
  433. PRINT_STATS_LE32("plcp_err", cck->plcp_err);
  434. PRINT_STATS_LE32("crc32_err", cck->crc32_err);
  435. PRINT_STATS_LE32("overrun_err", cck->overrun_err);
  436. PRINT_STATS_LE32("early_overrun_err", cck->early_overrun_err);
  437. PRINT_STATS_LE32("crc32_good", cck->crc32_good);
  438. PRINT_STATS_LE32("false_alarm_cnt", cck->false_alarm_cnt);
  439. PRINT_STATS_LE32("fina_sync_err_cnt", cck->fina_sync_err_cnt);
  440. PRINT_STATS_LE32("sfd_timeout", cck->sfd_timeout);
  441. PRINT_STATS_LE32("fina_timeout", cck->fina_timeout);
  442. PRINT_STATS_LE32("unresponded_rts", cck->unresponded_rts);
  443. PRINT_STATS_LE32("rxe_frame_lmt_overrun",
  444. cck->rxe_frame_limit_overrun);
  445. PRINT_STATS_LE32("sent_ack_cnt", cck->sent_ack_cnt);
  446. PRINT_STATS_LE32("sent_cts_cnt", cck->sent_cts_cnt);
  447. PRINT_STATS_LE32("sent_ba_rsp_cnt", cck->sent_ba_rsp_cnt);
  448. PRINT_STATS_LE32("dsp_self_kill", cck->dsp_self_kill);
  449. PRINT_STATS_LE32("mh_format_err", cck->mh_format_err);
  450. PRINT_STATS_LE32("re_acq_main_rssi_sum", cck->re_acq_main_rssi_sum);
  451. PRINT_STATS_LE32("reserved", cck->reserved);
  452. pos += scnprintf(buf + pos, bufsz - pos, fmt_header,
  453. "Statistics_Rx - GENERAL");
  454. PRINT_STATS_LE32("bogus_cts", general->bogus_cts);
  455. PRINT_STATS_LE32("bogus_ack", general->bogus_ack);
  456. PRINT_STATS_LE32("non_bssid_frames", general->non_bssid_frames);
  457. PRINT_STATS_LE32("filtered_frames", general->filtered_frames);
  458. PRINT_STATS_LE32("non_channel_beacons", general->non_channel_beacons);
  459. PRINT_STATS_LE32("channel_beacons", general->channel_beacons);
  460. PRINT_STATS_LE32("num_missed_bcon", general->num_missed_bcon);
  461. PRINT_STATS_LE32("adc_rx_saturation_time",
  462. general->adc_rx_saturation_time);
  463. PRINT_STATS_LE32("ina_detection_search_time",
  464. general->ina_detection_search_time);
  465. PRINT_STATS_LE32("beacon_silence_rssi_a",
  466. general->beacon_silence_rssi_a);
  467. PRINT_STATS_LE32("beacon_silence_rssi_b",
  468. general->beacon_silence_rssi_b);
  469. PRINT_STATS_LE32("beacon_silence_rssi_c",
  470. general->beacon_silence_rssi_c);
  471. PRINT_STATS_LE32("interference_data_flag",
  472. general->interference_data_flag);
  473. PRINT_STATS_LE32("channel_load", general->channel_load);
  474. PRINT_STATS_LE32("dsp_false_alarms", general->dsp_false_alarms);
  475. PRINT_STATS_LE32("beacon_rssi_a", general->beacon_rssi_a);
  476. PRINT_STATS_LE32("beacon_rssi_b", general->beacon_rssi_b);
  477. PRINT_STATS_LE32("beacon_rssi_c", general->beacon_rssi_c);
  478. PRINT_STATS_LE32("beacon_energy_a", general->beacon_energy_a);
  479. PRINT_STATS_LE32("beacon_energy_b", general->beacon_energy_b);
  480. PRINT_STATS_LE32("beacon_energy_c", general->beacon_energy_c);
  481. PRINT_STATS_LE32("num_bt_kills", general->num_bt_kills);
  482. PRINT_STATS_LE32("mac_id", general->mac_id);
  483. PRINT_STATS_LE32("directed_data_mpdu", general->directed_data_mpdu);
  484. pos += scnprintf(buf + pos, bufsz - pos, fmt_header,
  485. "Statistics_Rx - HT");
  486. PRINT_STATS_LE32("plcp_err", ht->plcp_err);
  487. PRINT_STATS_LE32("overrun_err", ht->overrun_err);
  488. PRINT_STATS_LE32("early_overrun_err", ht->early_overrun_err);
  489. PRINT_STATS_LE32("crc32_good", ht->crc32_good);
  490. PRINT_STATS_LE32("crc32_err", ht->crc32_err);
  491. PRINT_STATS_LE32("mh_format_err", ht->mh_format_err);
  492. PRINT_STATS_LE32("agg_crc32_good", ht->agg_crc32_good);
  493. PRINT_STATS_LE32("agg_mpdu_cnt", ht->agg_mpdu_cnt);
  494. PRINT_STATS_LE32("agg_cnt", ht->agg_cnt);
  495. PRINT_STATS_LE32("unsupport_mcs", ht->unsupport_mcs);
  496. mutex_unlock(&mvm->mutex);
  497. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  498. kfree(buf);
  499. return ret;
  500. }
  501. #undef PRINT_STAT_LE32
  502. static ssize_t iwl_dbgfs_frame_stats_read(struct iwl_mvm *mvm,
  503. char __user *user_buf, size_t count,
  504. loff_t *ppos,
  505. struct iwl_mvm_frame_stats *stats)
  506. {
  507. char *buff, *pos, *endpos;
  508. int idx, i;
  509. int ret;
  510. static const size_t bufsz = 1024;
  511. buff = kmalloc(bufsz, GFP_KERNEL);
  512. if (!buff)
  513. return -ENOMEM;
  514. spin_lock_bh(&mvm->drv_stats_lock);
  515. pos = buff;
  516. endpos = pos + bufsz;
  517. pos += scnprintf(pos, endpos - pos,
  518. "Legacy/HT/VHT\t:\t%d/%d/%d\n",
  519. stats->legacy_frames,
  520. stats->ht_frames,
  521. stats->vht_frames);
  522. pos += scnprintf(pos, endpos - pos, "20/40/80\t:\t%d/%d/%d\n",
  523. stats->bw_20_frames,
  524. stats->bw_40_frames,
  525. stats->bw_80_frames);
  526. pos += scnprintf(pos, endpos - pos, "NGI/SGI\t\t:\t%d/%d\n",
  527. stats->ngi_frames,
  528. stats->sgi_frames);
  529. pos += scnprintf(pos, endpos - pos, "SISO/MIMO2\t:\t%d/%d\n",
  530. stats->siso_frames,
  531. stats->mimo2_frames);
  532. pos += scnprintf(pos, endpos - pos, "FAIL/SCSS\t:\t%d/%d\n",
  533. stats->fail_frames,
  534. stats->success_frames);
  535. pos += scnprintf(pos, endpos - pos, "MPDUs agg\t:\t%d\n",
  536. stats->agg_frames);
  537. pos += scnprintf(pos, endpos - pos, "A-MPDUs\t\t:\t%d\n",
  538. stats->ampdu_count);
  539. pos += scnprintf(pos, endpos - pos, "Avg MPDUs/A-MPDU:\t%d\n",
  540. stats->ampdu_count > 0 ?
  541. (stats->agg_frames / stats->ampdu_count) : 0);
  542. pos += scnprintf(pos, endpos - pos, "Last Rates\n");
  543. idx = stats->last_frame_idx - 1;
  544. for (i = 0; i < ARRAY_SIZE(stats->last_rates); i++) {
  545. idx = (idx + 1) % ARRAY_SIZE(stats->last_rates);
  546. if (stats->last_rates[idx] == 0)
  547. continue;
  548. pos += scnprintf(pos, endpos - pos, "Rate[%d]: ",
  549. (int)(ARRAY_SIZE(stats->last_rates) - i));
  550. pos += rs_pretty_print_rate(pos, stats->last_rates[idx]);
  551. }
  552. spin_unlock_bh(&mvm->drv_stats_lock);
  553. ret = simple_read_from_buffer(user_buf, count, ppos, buff, pos - buff);
  554. kfree(buff);
  555. return ret;
  556. }
  557. static ssize_t iwl_dbgfs_drv_rx_stats_read(struct file *file,
  558. char __user *user_buf, size_t count,
  559. loff_t *ppos)
  560. {
  561. struct iwl_mvm *mvm = file->private_data;
  562. return iwl_dbgfs_frame_stats_read(mvm, user_buf, count, ppos,
  563. &mvm->drv_rx_stats);
  564. }
  565. static ssize_t iwl_dbgfs_fw_restart_write(struct iwl_mvm *mvm, char *buf,
  566. size_t count, loff_t *ppos)
  567. {
  568. int ret;
  569. mutex_lock(&mvm->mutex);
  570. /* allow one more restart that we're provoking here */
  571. if (mvm->restart_fw >= 0)
  572. mvm->restart_fw++;
  573. /* take the return value to make compiler happy - it will fail anyway */
  574. ret = iwl_mvm_send_cmd_pdu(mvm, REPLY_ERROR, 0, 0, NULL);
  575. mutex_unlock(&mvm->mutex);
  576. return count;
  577. }
  578. static ssize_t iwl_dbgfs_fw_nmi_write(struct iwl_mvm *mvm, char *buf,
  579. size_t count, loff_t *ppos)
  580. {
  581. iwl_force_nmi(mvm->trans);
  582. return count;
  583. }
  584. static ssize_t
  585. iwl_dbgfs_scan_ant_rxchain_read(struct file *file,
  586. char __user *user_buf,
  587. size_t count, loff_t *ppos)
  588. {
  589. struct iwl_mvm *mvm = file->private_data;
  590. int pos = 0;
  591. char buf[32];
  592. const size_t bufsz = sizeof(buf);
  593. /* print which antennas were set for the scan command by the user */
  594. pos += scnprintf(buf + pos, bufsz - pos, "Antennas for scan: ");
  595. if (mvm->scan_rx_ant & ANT_A)
  596. pos += scnprintf(buf + pos, bufsz - pos, "A");
  597. if (mvm->scan_rx_ant & ANT_B)
  598. pos += scnprintf(buf + pos, bufsz - pos, "B");
  599. if (mvm->scan_rx_ant & ANT_C)
  600. pos += scnprintf(buf + pos, bufsz - pos, "C");
  601. pos += scnprintf(buf + pos, bufsz - pos, " (%hhx)\n", mvm->scan_rx_ant);
  602. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  603. }
  604. static ssize_t
  605. iwl_dbgfs_scan_ant_rxchain_write(struct iwl_mvm *mvm, char *buf,
  606. size_t count, loff_t *ppos)
  607. {
  608. u8 scan_rx_ant;
  609. if (sscanf(buf, "%hhx", &scan_rx_ant) != 1)
  610. return -EINVAL;
  611. if (scan_rx_ant > ANT_ABC)
  612. return -EINVAL;
  613. if (scan_rx_ant & ~mvm->fw->valid_rx_ant)
  614. return -EINVAL;
  615. mvm->scan_rx_ant = scan_rx_ant;
  616. return count;
  617. }
  618. #define ADD_TEXT(...) pos += scnprintf(buf + pos, bufsz - pos, __VA_ARGS__)
  619. #ifdef CONFIG_IWLWIFI_BCAST_FILTERING
  620. static ssize_t iwl_dbgfs_bcast_filters_read(struct file *file,
  621. char __user *user_buf,
  622. size_t count, loff_t *ppos)
  623. {
  624. struct iwl_mvm *mvm = file->private_data;
  625. struct iwl_bcast_filter_cmd cmd;
  626. const struct iwl_fw_bcast_filter *filter;
  627. char *buf;
  628. int bufsz = 1024;
  629. int i, j, pos = 0;
  630. ssize_t ret;
  631. buf = kzalloc(bufsz, GFP_KERNEL);
  632. if (!buf)
  633. return -ENOMEM;
  634. mutex_lock(&mvm->mutex);
  635. if (!iwl_mvm_bcast_filter_build_cmd(mvm, &cmd)) {
  636. ADD_TEXT("None\n");
  637. mutex_unlock(&mvm->mutex);
  638. goto out;
  639. }
  640. mutex_unlock(&mvm->mutex);
  641. for (i = 0; cmd.filters[i].attrs[0].mask; i++) {
  642. filter = &cmd.filters[i];
  643. ADD_TEXT("Filter [%d]:\n", i);
  644. ADD_TEXT("\tDiscard=%d\n", filter->discard);
  645. ADD_TEXT("\tFrame Type: %s\n",
  646. filter->frame_type ? "IPv4" : "Generic");
  647. for (j = 0; j < ARRAY_SIZE(filter->attrs); j++) {
  648. const struct iwl_fw_bcast_filter_attr *attr;
  649. attr = &filter->attrs[j];
  650. if (!attr->mask)
  651. break;
  652. ADD_TEXT("\tAttr [%d]: offset=%d (from %s), mask=0x%x, value=0x%x reserved=0x%x\n",
  653. j, attr->offset,
  654. attr->offset_type ? "IP End" :
  655. "Payload Start",
  656. be32_to_cpu(attr->mask),
  657. be32_to_cpu(attr->val),
  658. le16_to_cpu(attr->reserved1));
  659. }
  660. }
  661. out:
  662. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  663. kfree(buf);
  664. return ret;
  665. }
  666. static ssize_t iwl_dbgfs_bcast_filters_write(struct iwl_mvm *mvm, char *buf,
  667. size_t count, loff_t *ppos)
  668. {
  669. int pos, next_pos;
  670. struct iwl_fw_bcast_filter filter = {};
  671. struct iwl_bcast_filter_cmd cmd;
  672. u32 filter_id, attr_id, mask, value;
  673. int err = 0;
  674. if (sscanf(buf, "%d %hhi %hhi %n", &filter_id, &filter.discard,
  675. &filter.frame_type, &pos) != 3)
  676. return -EINVAL;
  677. if (filter_id >= ARRAY_SIZE(mvm->dbgfs_bcast_filtering.cmd.filters) ||
  678. filter.frame_type > BCAST_FILTER_FRAME_TYPE_IPV4)
  679. return -EINVAL;
  680. for (attr_id = 0; attr_id < ARRAY_SIZE(filter.attrs);
  681. attr_id++) {
  682. struct iwl_fw_bcast_filter_attr *attr =
  683. &filter.attrs[attr_id];
  684. if (pos >= count)
  685. break;
  686. if (sscanf(&buf[pos], "%hhi %hhi %i %i %n",
  687. &attr->offset, &attr->offset_type,
  688. &mask, &value, &next_pos) != 4)
  689. return -EINVAL;
  690. attr->mask = cpu_to_be32(mask);
  691. attr->val = cpu_to_be32(value);
  692. if (mask)
  693. filter.num_attrs++;
  694. pos += next_pos;
  695. }
  696. mutex_lock(&mvm->mutex);
  697. memcpy(&mvm->dbgfs_bcast_filtering.cmd.filters[filter_id],
  698. &filter, sizeof(filter));
  699. /* send updated bcast filtering configuration */
  700. if (mvm->dbgfs_bcast_filtering.override &&
  701. iwl_mvm_bcast_filter_build_cmd(mvm, &cmd))
  702. err = iwl_mvm_send_cmd_pdu(mvm, BCAST_FILTER_CMD, 0,
  703. sizeof(cmd), &cmd);
  704. mutex_unlock(&mvm->mutex);
  705. return err ?: count;
  706. }
  707. static ssize_t iwl_dbgfs_bcast_filters_macs_read(struct file *file,
  708. char __user *user_buf,
  709. size_t count, loff_t *ppos)
  710. {
  711. struct iwl_mvm *mvm = file->private_data;
  712. struct iwl_bcast_filter_cmd cmd;
  713. char *buf;
  714. int bufsz = 1024;
  715. int i, pos = 0;
  716. ssize_t ret;
  717. buf = kzalloc(bufsz, GFP_KERNEL);
  718. if (!buf)
  719. return -ENOMEM;
  720. mutex_lock(&mvm->mutex);
  721. if (!iwl_mvm_bcast_filter_build_cmd(mvm, &cmd)) {
  722. ADD_TEXT("None\n");
  723. mutex_unlock(&mvm->mutex);
  724. goto out;
  725. }
  726. mutex_unlock(&mvm->mutex);
  727. for (i = 0; i < ARRAY_SIZE(cmd.macs); i++) {
  728. const struct iwl_fw_bcast_mac *mac = &cmd.macs[i];
  729. ADD_TEXT("Mac [%d]: discard=%d attached_filters=0x%x\n",
  730. i, mac->default_discard, mac->attached_filters);
  731. }
  732. out:
  733. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  734. kfree(buf);
  735. return ret;
  736. }
  737. static ssize_t iwl_dbgfs_bcast_filters_macs_write(struct iwl_mvm *mvm,
  738. char *buf, size_t count,
  739. loff_t *ppos)
  740. {
  741. struct iwl_bcast_filter_cmd cmd;
  742. struct iwl_fw_bcast_mac mac = {};
  743. u32 mac_id, attached_filters;
  744. int err = 0;
  745. if (!mvm->bcast_filters)
  746. return -ENOENT;
  747. if (sscanf(buf, "%d %hhi %i", &mac_id, &mac.default_discard,
  748. &attached_filters) != 3)
  749. return -EINVAL;
  750. if (mac_id >= ARRAY_SIZE(cmd.macs) ||
  751. mac.default_discard > 1 ||
  752. attached_filters >= BIT(ARRAY_SIZE(cmd.filters)))
  753. return -EINVAL;
  754. mac.attached_filters = cpu_to_le16(attached_filters);
  755. mutex_lock(&mvm->mutex);
  756. memcpy(&mvm->dbgfs_bcast_filtering.cmd.macs[mac_id],
  757. &mac, sizeof(mac));
  758. /* send updated bcast filtering configuration */
  759. if (mvm->dbgfs_bcast_filtering.override &&
  760. iwl_mvm_bcast_filter_build_cmd(mvm, &cmd))
  761. err = iwl_mvm_send_cmd_pdu(mvm, BCAST_FILTER_CMD, 0,
  762. sizeof(cmd), &cmd);
  763. mutex_unlock(&mvm->mutex);
  764. return err ?: count;
  765. }
  766. #endif
  767. #ifdef CONFIG_PM_SLEEP
  768. static ssize_t iwl_dbgfs_d3_sram_write(struct iwl_mvm *mvm, char *buf,
  769. size_t count, loff_t *ppos)
  770. {
  771. int store;
  772. if (sscanf(buf, "%d", &store) != 1)
  773. return -EINVAL;
  774. mvm->store_d3_resume_sram = store;
  775. return count;
  776. }
  777. static ssize_t iwl_dbgfs_d3_sram_read(struct file *file, char __user *user_buf,
  778. size_t count, loff_t *ppos)
  779. {
  780. struct iwl_mvm *mvm = file->private_data;
  781. const struct fw_img *img;
  782. int ofs, len, pos = 0;
  783. size_t bufsz, ret;
  784. char *buf;
  785. u8 *ptr = mvm->d3_resume_sram;
  786. img = &mvm->fw->img[IWL_UCODE_WOWLAN];
  787. len = img->sec[IWL_UCODE_SECTION_DATA].len;
  788. bufsz = len * 4 + 256;
  789. buf = kzalloc(bufsz, GFP_KERNEL);
  790. if (!buf)
  791. return -ENOMEM;
  792. pos += scnprintf(buf, bufsz, "D3 SRAM capture: %sabled\n",
  793. mvm->store_d3_resume_sram ? "en" : "dis");
  794. if (ptr) {
  795. for (ofs = 0; ofs < len; ofs += 16) {
  796. pos += scnprintf(buf + pos, bufsz - pos,
  797. "0x%.4x ", ofs);
  798. hex_dump_to_buffer(ptr + ofs, 16, 16, 1, buf + pos,
  799. bufsz - pos, false);
  800. pos += strlen(buf + pos);
  801. if (bufsz - pos > 0)
  802. buf[pos++] = '\n';
  803. }
  804. } else {
  805. pos += scnprintf(buf + pos, bufsz - pos,
  806. "(no data captured)\n");
  807. }
  808. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  809. kfree(buf);
  810. return ret;
  811. }
  812. #endif
  813. #define PRINT_MVM_REF(ref) do { \
  814. if (test_bit(ref, mvm->ref_bitmap)) \
  815. pos += scnprintf(buf + pos, bufsz - pos, \
  816. "\t(0x%lx) %s\n", \
  817. BIT(ref), #ref); \
  818. } while (0)
  819. static ssize_t iwl_dbgfs_d0i3_refs_read(struct file *file,
  820. char __user *user_buf,
  821. size_t count, loff_t *ppos)
  822. {
  823. struct iwl_mvm *mvm = file->private_data;
  824. int pos = 0;
  825. char buf[256];
  826. const size_t bufsz = sizeof(buf);
  827. pos += scnprintf(buf + pos, bufsz - pos, "taken mvm refs: 0x%lx\n",
  828. mvm->ref_bitmap[0]);
  829. PRINT_MVM_REF(IWL_MVM_REF_UCODE_DOWN);
  830. PRINT_MVM_REF(IWL_MVM_REF_SCAN);
  831. PRINT_MVM_REF(IWL_MVM_REF_ROC);
  832. PRINT_MVM_REF(IWL_MVM_REF_P2P_CLIENT);
  833. PRINT_MVM_REF(IWL_MVM_REF_AP_IBSS);
  834. PRINT_MVM_REF(IWL_MVM_REF_USER);
  835. PRINT_MVM_REF(IWL_MVM_REF_EXIT_WORK);
  836. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  837. }
  838. static ssize_t iwl_dbgfs_d0i3_refs_write(struct iwl_mvm *mvm, char *buf,
  839. size_t count, loff_t *ppos)
  840. {
  841. unsigned long value;
  842. int ret;
  843. bool taken;
  844. ret = kstrtoul(buf, 10, &value);
  845. if (ret < 0)
  846. return ret;
  847. mutex_lock(&mvm->mutex);
  848. taken = test_bit(IWL_MVM_REF_USER, mvm->ref_bitmap);
  849. if (value == 1 && !taken)
  850. iwl_mvm_ref(mvm, IWL_MVM_REF_USER);
  851. else if (value == 0 && taken)
  852. iwl_mvm_unref(mvm, IWL_MVM_REF_USER);
  853. else
  854. ret = -EINVAL;
  855. mutex_unlock(&mvm->mutex);
  856. if (ret < 0)
  857. return ret;
  858. return count;
  859. }
  860. #define MVM_DEBUGFS_WRITE_FILE_OPS(name, bufsz) \
  861. _MVM_DEBUGFS_WRITE_FILE_OPS(name, bufsz, struct iwl_mvm)
  862. #define MVM_DEBUGFS_READ_WRITE_FILE_OPS(name, bufsz) \
  863. _MVM_DEBUGFS_READ_WRITE_FILE_OPS(name, bufsz, struct iwl_mvm)
  864. #define MVM_DEBUGFS_ADD_FILE_ALIAS(alias, name, parent, mode) do { \
  865. if (!debugfs_create_file(alias, mode, parent, mvm, \
  866. &iwl_dbgfs_##name##_ops)) \
  867. goto err; \
  868. } while (0)
  869. #define MVM_DEBUGFS_ADD_FILE(name, parent, mode) \
  870. MVM_DEBUGFS_ADD_FILE_ALIAS(#name, name, parent, mode)
  871. static ssize_t
  872. iwl_dbgfs_prph_reg_read(struct file *file,
  873. char __user *user_buf,
  874. size_t count, loff_t *ppos)
  875. {
  876. struct iwl_mvm *mvm = file->private_data;
  877. int pos = 0;
  878. char buf[32];
  879. const size_t bufsz = sizeof(buf);
  880. if (!mvm->dbgfs_prph_reg_addr)
  881. return -EINVAL;
  882. pos += scnprintf(buf + pos, bufsz - pos, "Reg 0x%x: (0x%x)\n",
  883. mvm->dbgfs_prph_reg_addr,
  884. iwl_read_prph(mvm->trans, mvm->dbgfs_prph_reg_addr));
  885. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  886. }
  887. static ssize_t
  888. iwl_dbgfs_prph_reg_write(struct iwl_mvm *mvm, char *buf,
  889. size_t count, loff_t *ppos)
  890. {
  891. u8 args;
  892. u32 value;
  893. args = sscanf(buf, "%i %i", &mvm->dbgfs_prph_reg_addr, &value);
  894. /* if we only want to set the reg address - nothing more to do */
  895. if (args == 1)
  896. goto out;
  897. /* otherwise, make sure we have both address and value */
  898. if (args != 2)
  899. return -EINVAL;
  900. iwl_write_prph(mvm->trans, mvm->dbgfs_prph_reg_addr, value);
  901. out:
  902. return count;
  903. }
  904. MVM_DEBUGFS_READ_WRITE_FILE_OPS(prph_reg, 64);
  905. /* Device wide debugfs entries */
  906. MVM_DEBUGFS_WRITE_FILE_OPS(tx_flush, 16);
  907. MVM_DEBUGFS_WRITE_FILE_OPS(sta_drain, 8);
  908. MVM_DEBUGFS_READ_WRITE_FILE_OPS(sram, 64);
  909. MVM_DEBUGFS_READ_FILE_OPS(stations);
  910. MVM_DEBUGFS_READ_FILE_OPS(bt_notif);
  911. MVM_DEBUGFS_READ_FILE_OPS(bt_cmd);
  912. MVM_DEBUGFS_READ_WRITE_FILE_OPS(disable_power_off, 64);
  913. MVM_DEBUGFS_READ_FILE_OPS(fw_rx_stats);
  914. MVM_DEBUGFS_READ_FILE_OPS(drv_rx_stats);
  915. MVM_DEBUGFS_WRITE_FILE_OPS(fw_restart, 10);
  916. MVM_DEBUGFS_WRITE_FILE_OPS(fw_nmi, 10);
  917. MVM_DEBUGFS_WRITE_FILE_OPS(bt_tx_prio, 10);
  918. MVM_DEBUGFS_READ_WRITE_FILE_OPS(scan_ant_rxchain, 8);
  919. MVM_DEBUGFS_READ_WRITE_FILE_OPS(d0i3_refs, 8);
  920. static const struct file_operations iwl_dbgfs_fw_error_dump_ops = {
  921. .open = iwl_dbgfs_fw_error_dump_open,
  922. .read = iwl_dbgfs_fw_error_dump_read,
  923. .release = iwl_dbgfs_fw_error_dump_release,
  924. };
  925. #ifdef CONFIG_IWLWIFI_BCAST_FILTERING
  926. MVM_DEBUGFS_READ_WRITE_FILE_OPS(bcast_filters, 256);
  927. MVM_DEBUGFS_READ_WRITE_FILE_OPS(bcast_filters_macs, 256);
  928. #endif
  929. #ifdef CONFIG_PM_SLEEP
  930. MVM_DEBUGFS_READ_WRITE_FILE_OPS(d3_sram, 8);
  931. #endif
  932. int iwl_mvm_dbgfs_register(struct iwl_mvm *mvm, struct dentry *dbgfs_dir)
  933. {
  934. struct dentry *bcast_dir __maybe_unused;
  935. char buf[100];
  936. spin_lock_init(&mvm->drv_stats_lock);
  937. mvm->debugfs_dir = dbgfs_dir;
  938. MVM_DEBUGFS_ADD_FILE(tx_flush, mvm->debugfs_dir, S_IWUSR);
  939. MVM_DEBUGFS_ADD_FILE(sta_drain, mvm->debugfs_dir, S_IWUSR);
  940. MVM_DEBUGFS_ADD_FILE(sram, mvm->debugfs_dir, S_IWUSR | S_IRUSR);
  941. MVM_DEBUGFS_ADD_FILE(stations, dbgfs_dir, S_IRUSR);
  942. MVM_DEBUGFS_ADD_FILE(fw_error_dump, dbgfs_dir, S_IRUSR);
  943. MVM_DEBUGFS_ADD_FILE(bt_notif, dbgfs_dir, S_IRUSR);
  944. MVM_DEBUGFS_ADD_FILE(bt_cmd, dbgfs_dir, S_IRUSR);
  945. MVM_DEBUGFS_ADD_FILE(disable_power_off, mvm->debugfs_dir,
  946. S_IRUSR | S_IWUSR);
  947. MVM_DEBUGFS_ADD_FILE(fw_rx_stats, mvm->debugfs_dir, S_IRUSR);
  948. MVM_DEBUGFS_ADD_FILE(drv_rx_stats, mvm->debugfs_dir, S_IRUSR);
  949. MVM_DEBUGFS_ADD_FILE(fw_restart, mvm->debugfs_dir, S_IWUSR);
  950. MVM_DEBUGFS_ADD_FILE(fw_nmi, mvm->debugfs_dir, S_IWUSR);
  951. MVM_DEBUGFS_ADD_FILE(bt_tx_prio, mvm->debugfs_dir, S_IWUSR);
  952. MVM_DEBUGFS_ADD_FILE(scan_ant_rxchain, mvm->debugfs_dir,
  953. S_IWUSR | S_IRUSR);
  954. MVM_DEBUGFS_ADD_FILE(prph_reg, mvm->debugfs_dir, S_IWUSR | S_IRUSR);
  955. MVM_DEBUGFS_ADD_FILE(d0i3_refs, mvm->debugfs_dir, S_IRUSR | S_IWUSR);
  956. #ifdef CONFIG_IWLWIFI_BCAST_FILTERING
  957. if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_BCAST_FILTERING) {
  958. bcast_dir = debugfs_create_dir("bcast_filtering",
  959. mvm->debugfs_dir);
  960. if (!bcast_dir)
  961. goto err;
  962. if (!debugfs_create_bool("override", S_IRUSR | S_IWUSR,
  963. bcast_dir,
  964. &mvm->dbgfs_bcast_filtering.override))
  965. goto err;
  966. MVM_DEBUGFS_ADD_FILE_ALIAS("filters", bcast_filters,
  967. bcast_dir, S_IWUSR | S_IRUSR);
  968. MVM_DEBUGFS_ADD_FILE_ALIAS("macs", bcast_filters_macs,
  969. bcast_dir, S_IWUSR | S_IRUSR);
  970. }
  971. #endif
  972. #ifdef CONFIG_PM_SLEEP
  973. MVM_DEBUGFS_ADD_FILE(d3_sram, mvm->debugfs_dir, S_IRUSR | S_IWUSR);
  974. MVM_DEBUGFS_ADD_FILE(d3_test, mvm->debugfs_dir, S_IRUSR);
  975. if (!debugfs_create_bool("d3_wake_sysassert", S_IRUSR | S_IWUSR,
  976. mvm->debugfs_dir, &mvm->d3_wake_sysassert))
  977. goto err;
  978. #endif
  979. if (!debugfs_create_blob("nvm_hw", S_IRUSR,
  980. mvm->debugfs_dir, &mvm->nvm_hw_blob))
  981. goto err;
  982. if (!debugfs_create_blob("nvm_sw", S_IRUSR,
  983. mvm->debugfs_dir, &mvm->nvm_sw_blob))
  984. goto err;
  985. if (!debugfs_create_blob("nvm_calib", S_IRUSR,
  986. mvm->debugfs_dir, &mvm->nvm_calib_blob))
  987. goto err;
  988. if (!debugfs_create_blob("nvm_prod", S_IRUSR,
  989. mvm->debugfs_dir, &mvm->nvm_prod_blob))
  990. goto err;
  991. /*
  992. * Create a symlink with mac80211. It will be removed when mac80211
  993. * exists (before the opmode exists which removes the target.)
  994. */
  995. snprintf(buf, 100, "../../%s/%s",
  996. dbgfs_dir->d_parent->d_parent->d_name.name,
  997. dbgfs_dir->d_parent->d_name.name);
  998. if (!debugfs_create_symlink("iwlwifi", mvm->hw->wiphy->debugfsdir, buf))
  999. goto err;
  1000. return 0;
  1001. err:
  1002. IWL_ERR(mvm, "Can't create the mvm debugfs directory\n");
  1003. return -ENOMEM;
  1004. }