debugfs.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743
  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 "mvm.h"
  64. #include "sta.h"
  65. #include "iwl-io.h"
  66. #include "iwl-prph.h"
  67. #include "debugfs.h"
  68. static ssize_t iwl_dbgfs_tx_flush_write(struct iwl_mvm *mvm, char *buf,
  69. size_t count, loff_t *ppos)
  70. {
  71. int ret;
  72. u32 scd_q_msk;
  73. if (!mvm->ucode_loaded || mvm->cur_ucode != IWL_UCODE_REGULAR)
  74. return -EIO;
  75. if (sscanf(buf, "%x", &scd_q_msk) != 1)
  76. return -EINVAL;
  77. IWL_ERR(mvm, "FLUSHING queues: scd_q_msk = 0x%x\n", scd_q_msk);
  78. mutex_lock(&mvm->mutex);
  79. ret = iwl_mvm_flush_tx_path(mvm, scd_q_msk, true) ? : count;
  80. mutex_unlock(&mvm->mutex);
  81. return ret;
  82. }
  83. static ssize_t iwl_dbgfs_sta_drain_write(struct iwl_mvm *mvm, char *buf,
  84. size_t count, loff_t *ppos)
  85. {
  86. struct ieee80211_sta *sta;
  87. int sta_id, drain, ret;
  88. if (!mvm->ucode_loaded || mvm->cur_ucode != IWL_UCODE_REGULAR)
  89. return -EIO;
  90. if (sscanf(buf, "%d %d", &sta_id, &drain) != 2)
  91. return -EINVAL;
  92. if (sta_id < 0 || sta_id >= IWL_MVM_STATION_COUNT)
  93. return -EINVAL;
  94. if (drain < 0 || drain > 1)
  95. return -EINVAL;
  96. mutex_lock(&mvm->mutex);
  97. sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[sta_id],
  98. lockdep_is_held(&mvm->mutex));
  99. if (IS_ERR_OR_NULL(sta))
  100. ret = -ENOENT;
  101. else
  102. ret = iwl_mvm_drain_sta(mvm, (void *)sta->drv_priv, drain) ? :
  103. count;
  104. mutex_unlock(&mvm->mutex);
  105. return ret;
  106. }
  107. static ssize_t iwl_dbgfs_sram_read(struct file *file, char __user *user_buf,
  108. size_t count, loff_t *ppos)
  109. {
  110. struct iwl_mvm *mvm = file->private_data;
  111. const struct fw_img *img;
  112. unsigned int ofs, len;
  113. size_t ret;
  114. u8 *ptr;
  115. if (!mvm->ucode_loaded)
  116. return -EINVAL;
  117. /* default is to dump the entire data segment */
  118. img = &mvm->fw->img[mvm->cur_ucode];
  119. ofs = img->sec[IWL_UCODE_SECTION_DATA].offset;
  120. len = img->sec[IWL_UCODE_SECTION_DATA].len;
  121. if (mvm->dbgfs_sram_len) {
  122. ofs = mvm->dbgfs_sram_offset;
  123. len = mvm->dbgfs_sram_len;
  124. }
  125. ptr = kzalloc(len, GFP_KERNEL);
  126. if (!ptr)
  127. return -ENOMEM;
  128. iwl_trans_read_mem_bytes(mvm->trans, ofs, ptr, len);
  129. ret = simple_read_from_buffer(user_buf, count, ppos, ptr, len);
  130. kfree(ptr);
  131. return ret;
  132. }
  133. static ssize_t iwl_dbgfs_sram_write(struct iwl_mvm *mvm, char *buf,
  134. size_t count, loff_t *ppos)
  135. {
  136. const struct fw_img *img;
  137. u32 offset, len;
  138. u32 img_offset, img_len;
  139. if (!mvm->ucode_loaded)
  140. return -EINVAL;
  141. img = &mvm->fw->img[mvm->cur_ucode];
  142. img_offset = img->sec[IWL_UCODE_SECTION_DATA].offset;
  143. img_len = img->sec[IWL_UCODE_SECTION_DATA].len;
  144. if (sscanf(buf, "%x,%x", &offset, &len) == 2) {
  145. if ((offset & 0x3) || (len & 0x3))
  146. return -EINVAL;
  147. if (offset + len > img_offset + img_len)
  148. return -EINVAL;
  149. mvm->dbgfs_sram_offset = offset;
  150. mvm->dbgfs_sram_len = len;
  151. } else {
  152. mvm->dbgfs_sram_offset = 0;
  153. mvm->dbgfs_sram_len = 0;
  154. }
  155. return count;
  156. }
  157. static ssize_t iwl_dbgfs_stations_read(struct file *file, char __user *user_buf,
  158. size_t count, loff_t *ppos)
  159. {
  160. struct iwl_mvm *mvm = file->private_data;
  161. struct ieee80211_sta *sta;
  162. char buf[400];
  163. int i, pos = 0, bufsz = sizeof(buf);
  164. mutex_lock(&mvm->mutex);
  165. for (i = 0; i < IWL_MVM_STATION_COUNT; i++) {
  166. pos += scnprintf(buf + pos, bufsz - pos, "%.2d: ", i);
  167. sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[i],
  168. lockdep_is_held(&mvm->mutex));
  169. if (!sta)
  170. pos += scnprintf(buf + pos, bufsz - pos, "N/A\n");
  171. else if (IS_ERR(sta))
  172. pos += scnprintf(buf + pos, bufsz - pos, "%ld\n",
  173. PTR_ERR(sta));
  174. else
  175. pos += scnprintf(buf + pos, bufsz - pos, "%pM\n",
  176. sta->addr);
  177. }
  178. mutex_unlock(&mvm->mutex);
  179. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  180. }
  181. static ssize_t iwl_dbgfs_disable_power_off_read(struct file *file,
  182. char __user *user_buf,
  183. size_t count, loff_t *ppos)
  184. {
  185. struct iwl_mvm *mvm = file->private_data;
  186. char buf[64];
  187. int bufsz = sizeof(buf);
  188. int pos = 0;
  189. pos += scnprintf(buf+pos, bufsz-pos, "disable_power_off_d0=%d\n",
  190. mvm->disable_power_off);
  191. pos += scnprintf(buf+pos, bufsz-pos, "disable_power_off_d3=%d\n",
  192. mvm->disable_power_off_d3);
  193. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  194. }
  195. static ssize_t iwl_dbgfs_disable_power_off_write(struct iwl_mvm *mvm, char *buf,
  196. size_t count, loff_t *ppos)
  197. {
  198. int ret, val;
  199. if (!mvm->ucode_loaded)
  200. return -EIO;
  201. if (!strncmp("disable_power_off_d0=", buf, 21)) {
  202. if (sscanf(buf + 21, "%d", &val) != 1)
  203. return -EINVAL;
  204. mvm->disable_power_off = val;
  205. } else if (!strncmp("disable_power_off_d3=", buf, 21)) {
  206. if (sscanf(buf + 21, "%d", &val) != 1)
  207. return -EINVAL;
  208. mvm->disable_power_off_d3 = val;
  209. } else {
  210. return -EINVAL;
  211. }
  212. mutex_lock(&mvm->mutex);
  213. ret = iwl_mvm_power_update_device_mode(mvm);
  214. mutex_unlock(&mvm->mutex);
  215. return ret ?: count;
  216. }
  217. #define BT_MBOX_MSG(_notif, _num, _field) \
  218. ((le32_to_cpu((_notif)->mbox_msg[(_num)]) & BT_MBOX##_num##_##_field)\
  219. >> BT_MBOX##_num##_##_field##_POS)
  220. #define BT_MBOX_PRINT(_num, _field, _end) \
  221. pos += scnprintf(buf + pos, bufsz - pos, \
  222. "\t%s: %d%s", \
  223. #_field, \
  224. BT_MBOX_MSG(notif, _num, _field), \
  225. true ? "\n" : ", ");
  226. static ssize_t iwl_dbgfs_bt_notif_read(struct file *file, char __user *user_buf,
  227. size_t count, loff_t *ppos)
  228. {
  229. struct iwl_mvm *mvm = file->private_data;
  230. struct iwl_bt_coex_profile_notif *notif = &mvm->last_bt_notif;
  231. char *buf;
  232. int ret, pos = 0, bufsz = sizeof(char) * 1024;
  233. buf = kmalloc(bufsz, GFP_KERNEL);
  234. if (!buf)
  235. return -ENOMEM;
  236. mutex_lock(&mvm->mutex);
  237. pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw0:\n");
  238. BT_MBOX_PRINT(0, LE_SLAVE_LAT, false);
  239. BT_MBOX_PRINT(0, LE_PROF1, false);
  240. BT_MBOX_PRINT(0, LE_PROF2, false);
  241. BT_MBOX_PRINT(0, LE_PROF_OTHER, false);
  242. BT_MBOX_PRINT(0, CHL_SEQ_N, false);
  243. BT_MBOX_PRINT(0, INBAND_S, false);
  244. BT_MBOX_PRINT(0, LE_MIN_RSSI, false);
  245. BT_MBOX_PRINT(0, LE_SCAN, false);
  246. BT_MBOX_PRINT(0, LE_ADV, false);
  247. BT_MBOX_PRINT(0, LE_MAX_TX_POWER, false);
  248. BT_MBOX_PRINT(0, OPEN_CON_1, true);
  249. pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw1:\n");
  250. BT_MBOX_PRINT(1, BR_MAX_TX_POWER, false);
  251. BT_MBOX_PRINT(1, IP_SR, false);
  252. BT_MBOX_PRINT(1, LE_MSTR, false);
  253. BT_MBOX_PRINT(1, AGGR_TRFC_LD, false);
  254. BT_MBOX_PRINT(1, MSG_TYPE, false);
  255. BT_MBOX_PRINT(1, SSN, true);
  256. pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw2:\n");
  257. BT_MBOX_PRINT(2, SNIFF_ACT, false);
  258. BT_MBOX_PRINT(2, PAG, false);
  259. BT_MBOX_PRINT(2, INQUIRY, false);
  260. BT_MBOX_PRINT(2, CONN, false);
  261. BT_MBOX_PRINT(2, SNIFF_INTERVAL, false);
  262. BT_MBOX_PRINT(2, DISC, false);
  263. BT_MBOX_PRINT(2, SCO_TX_ACT, false);
  264. BT_MBOX_PRINT(2, SCO_RX_ACT, false);
  265. BT_MBOX_PRINT(2, ESCO_RE_TX, false);
  266. BT_MBOX_PRINT(2, SCO_DURATION, true);
  267. pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw3:\n");
  268. BT_MBOX_PRINT(3, SCO_STATE, false);
  269. BT_MBOX_PRINT(3, SNIFF_STATE, false);
  270. BT_MBOX_PRINT(3, A2DP_STATE, false);
  271. BT_MBOX_PRINT(3, ACL_STATE, false);
  272. BT_MBOX_PRINT(3, MSTR_STATE, false);
  273. BT_MBOX_PRINT(3, OBX_STATE, false);
  274. BT_MBOX_PRINT(3, OPEN_CON_2, false);
  275. BT_MBOX_PRINT(3, TRAFFIC_LOAD, false);
  276. BT_MBOX_PRINT(3, CHL_SEQN_LSB, false);
  277. BT_MBOX_PRINT(3, INBAND_P, false);
  278. BT_MBOX_PRINT(3, MSG_TYPE_2, false);
  279. BT_MBOX_PRINT(3, SSN_2, false);
  280. BT_MBOX_PRINT(3, UPDATE_REQUEST, true);
  281. pos += scnprintf(buf+pos, bufsz-pos, "bt_status = %d\n",
  282. notif->bt_status);
  283. pos += scnprintf(buf+pos, bufsz-pos, "bt_open_conn = %d\n",
  284. notif->bt_open_conn);
  285. pos += scnprintf(buf+pos, bufsz-pos, "bt_traffic_load = %d\n",
  286. notif->bt_traffic_load);
  287. pos += scnprintf(buf+pos, bufsz-pos, "bt_agg_traffic_load = %d\n",
  288. notif->bt_agg_traffic_load);
  289. pos += scnprintf(buf+pos, bufsz-pos, "bt_ci_compliance = %d\n",
  290. notif->bt_ci_compliance);
  291. pos += scnprintf(buf+pos, bufsz-pos, "primary_ch_lut = %d\n",
  292. le32_to_cpu(notif->primary_ch_lut));
  293. pos += scnprintf(buf+pos, bufsz-pos, "secondary_ch_lut = %d\n",
  294. le32_to_cpu(notif->secondary_ch_lut));
  295. pos += scnprintf(buf+pos, bufsz-pos, "bt_activity_grading = %d\n",
  296. le32_to_cpu(notif->bt_activity_grading));
  297. mutex_unlock(&mvm->mutex);
  298. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  299. kfree(buf);
  300. return ret;
  301. }
  302. #undef BT_MBOX_PRINT
  303. static ssize_t iwl_dbgfs_bt_cmd_read(struct file *file, char __user *user_buf,
  304. size_t count, loff_t *ppos)
  305. {
  306. struct iwl_mvm *mvm = file->private_data;
  307. struct iwl_bt_coex_ci_cmd *cmd = &mvm->last_bt_ci_cmd;
  308. char buf[256];
  309. int bufsz = sizeof(buf);
  310. int pos = 0;
  311. mutex_lock(&mvm->mutex);
  312. pos += scnprintf(buf+pos, bufsz-pos, "Channel inhibition CMD\n");
  313. pos += scnprintf(buf+pos, bufsz-pos,
  314. "\tPrimary Channel Bitmap 0x%016llx Fat: %d\n",
  315. le64_to_cpu(cmd->bt_primary_ci),
  316. !!cmd->co_run_bw_primary);
  317. pos += scnprintf(buf+pos, bufsz-pos,
  318. "\tSecondary Channel Bitmap 0x%016llx Fat: %d\n",
  319. le64_to_cpu(cmd->bt_secondary_ci),
  320. !!cmd->co_run_bw_secondary);
  321. pos += scnprintf(buf+pos, bufsz-pos, "BT Configuration CMD\n");
  322. pos += scnprintf(buf+pos, bufsz-pos, "\tACK Kill Mask 0x%08x\n",
  323. iwl_bt_ack_kill_msk[mvm->bt_kill_msk]);
  324. pos += scnprintf(buf+pos, bufsz-pos, "\tCTS Kill Mask 0x%08x\n",
  325. iwl_bt_cts_kill_msk[mvm->bt_kill_msk]);
  326. mutex_unlock(&mvm->mutex);
  327. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  328. }
  329. #define PRINT_STATS_LE32(_str, _val) \
  330. pos += scnprintf(buf + pos, bufsz - pos, \
  331. fmt_table, _str, \
  332. le32_to_cpu(_val))
  333. static ssize_t iwl_dbgfs_fw_rx_stats_read(struct file *file,
  334. char __user *user_buf, size_t count,
  335. loff_t *ppos)
  336. {
  337. struct iwl_mvm *mvm = file->private_data;
  338. static const char *fmt_table = "\t%-30s %10u\n";
  339. static const char *fmt_header = "%-32s\n";
  340. int pos = 0;
  341. char *buf;
  342. int ret;
  343. /* 43 is the size of each data line, 33 is the size of each header */
  344. size_t bufsz =
  345. ((sizeof(struct mvm_statistics_rx) / sizeof(__le32)) * 43) +
  346. (4 * 33) + 1;
  347. struct mvm_statistics_rx_phy *ofdm;
  348. struct mvm_statistics_rx_phy *cck;
  349. struct mvm_statistics_rx_non_phy *general;
  350. struct mvm_statistics_rx_ht_phy *ht;
  351. buf = kzalloc(bufsz, GFP_KERNEL);
  352. if (!buf)
  353. return -ENOMEM;
  354. mutex_lock(&mvm->mutex);
  355. ofdm = &mvm->rx_stats.ofdm;
  356. cck = &mvm->rx_stats.cck;
  357. general = &mvm->rx_stats.general;
  358. ht = &mvm->rx_stats.ofdm_ht;
  359. pos += scnprintf(buf + pos, bufsz - pos, fmt_header,
  360. "Statistics_Rx - OFDM");
  361. PRINT_STATS_LE32("ina_cnt", ofdm->ina_cnt);
  362. PRINT_STATS_LE32("fina_cnt", ofdm->fina_cnt);
  363. PRINT_STATS_LE32("plcp_err", ofdm->plcp_err);
  364. PRINT_STATS_LE32("crc32_err", ofdm->crc32_err);
  365. PRINT_STATS_LE32("overrun_err", ofdm->overrun_err);
  366. PRINT_STATS_LE32("early_overrun_err", ofdm->early_overrun_err);
  367. PRINT_STATS_LE32("crc32_good", ofdm->crc32_good);
  368. PRINT_STATS_LE32("false_alarm_cnt", ofdm->false_alarm_cnt);
  369. PRINT_STATS_LE32("fina_sync_err_cnt", ofdm->fina_sync_err_cnt);
  370. PRINT_STATS_LE32("sfd_timeout", ofdm->sfd_timeout);
  371. PRINT_STATS_LE32("fina_timeout", ofdm->fina_timeout);
  372. PRINT_STATS_LE32("unresponded_rts", ofdm->unresponded_rts);
  373. PRINT_STATS_LE32("rxe_frame_lmt_overrun",
  374. ofdm->rxe_frame_limit_overrun);
  375. PRINT_STATS_LE32("sent_ack_cnt", ofdm->sent_ack_cnt);
  376. PRINT_STATS_LE32("sent_cts_cnt", ofdm->sent_cts_cnt);
  377. PRINT_STATS_LE32("sent_ba_rsp_cnt", ofdm->sent_ba_rsp_cnt);
  378. PRINT_STATS_LE32("dsp_self_kill", ofdm->dsp_self_kill);
  379. PRINT_STATS_LE32("mh_format_err", ofdm->mh_format_err);
  380. PRINT_STATS_LE32("re_acq_main_rssi_sum", ofdm->re_acq_main_rssi_sum);
  381. PRINT_STATS_LE32("reserved", ofdm->reserved);
  382. pos += scnprintf(buf + pos, bufsz - pos, fmt_header,
  383. "Statistics_Rx - CCK");
  384. PRINT_STATS_LE32("ina_cnt", cck->ina_cnt);
  385. PRINT_STATS_LE32("fina_cnt", cck->fina_cnt);
  386. PRINT_STATS_LE32("plcp_err", cck->plcp_err);
  387. PRINT_STATS_LE32("crc32_err", cck->crc32_err);
  388. PRINT_STATS_LE32("overrun_err", cck->overrun_err);
  389. PRINT_STATS_LE32("early_overrun_err", cck->early_overrun_err);
  390. PRINT_STATS_LE32("crc32_good", cck->crc32_good);
  391. PRINT_STATS_LE32("false_alarm_cnt", cck->false_alarm_cnt);
  392. PRINT_STATS_LE32("fina_sync_err_cnt", cck->fina_sync_err_cnt);
  393. PRINT_STATS_LE32("sfd_timeout", cck->sfd_timeout);
  394. PRINT_STATS_LE32("fina_timeout", cck->fina_timeout);
  395. PRINT_STATS_LE32("unresponded_rts", cck->unresponded_rts);
  396. PRINT_STATS_LE32("rxe_frame_lmt_overrun",
  397. cck->rxe_frame_limit_overrun);
  398. PRINT_STATS_LE32("sent_ack_cnt", cck->sent_ack_cnt);
  399. PRINT_STATS_LE32("sent_cts_cnt", cck->sent_cts_cnt);
  400. PRINT_STATS_LE32("sent_ba_rsp_cnt", cck->sent_ba_rsp_cnt);
  401. PRINT_STATS_LE32("dsp_self_kill", cck->dsp_self_kill);
  402. PRINT_STATS_LE32("mh_format_err", cck->mh_format_err);
  403. PRINT_STATS_LE32("re_acq_main_rssi_sum", cck->re_acq_main_rssi_sum);
  404. PRINT_STATS_LE32("reserved", cck->reserved);
  405. pos += scnprintf(buf + pos, bufsz - pos, fmt_header,
  406. "Statistics_Rx - GENERAL");
  407. PRINT_STATS_LE32("bogus_cts", general->bogus_cts);
  408. PRINT_STATS_LE32("bogus_ack", general->bogus_ack);
  409. PRINT_STATS_LE32("non_bssid_frames", general->non_bssid_frames);
  410. PRINT_STATS_LE32("filtered_frames", general->filtered_frames);
  411. PRINT_STATS_LE32("non_channel_beacons", general->non_channel_beacons);
  412. PRINT_STATS_LE32("channel_beacons", general->channel_beacons);
  413. PRINT_STATS_LE32("num_missed_bcon", general->num_missed_bcon);
  414. PRINT_STATS_LE32("adc_rx_saturation_time",
  415. general->adc_rx_saturation_time);
  416. PRINT_STATS_LE32("ina_detection_search_time",
  417. general->ina_detection_search_time);
  418. PRINT_STATS_LE32("beacon_silence_rssi_a",
  419. general->beacon_silence_rssi_a);
  420. PRINT_STATS_LE32("beacon_silence_rssi_b",
  421. general->beacon_silence_rssi_b);
  422. PRINT_STATS_LE32("beacon_silence_rssi_c",
  423. general->beacon_silence_rssi_c);
  424. PRINT_STATS_LE32("interference_data_flag",
  425. general->interference_data_flag);
  426. PRINT_STATS_LE32("channel_load", general->channel_load);
  427. PRINT_STATS_LE32("dsp_false_alarms", general->dsp_false_alarms);
  428. PRINT_STATS_LE32("beacon_rssi_a", general->beacon_rssi_a);
  429. PRINT_STATS_LE32("beacon_rssi_b", general->beacon_rssi_b);
  430. PRINT_STATS_LE32("beacon_rssi_c", general->beacon_rssi_c);
  431. PRINT_STATS_LE32("beacon_energy_a", general->beacon_energy_a);
  432. PRINT_STATS_LE32("beacon_energy_b", general->beacon_energy_b);
  433. PRINT_STATS_LE32("beacon_energy_c", general->beacon_energy_c);
  434. PRINT_STATS_LE32("num_bt_kills", general->num_bt_kills);
  435. PRINT_STATS_LE32("mac_id", general->mac_id);
  436. PRINT_STATS_LE32("directed_data_mpdu", general->directed_data_mpdu);
  437. pos += scnprintf(buf + pos, bufsz - pos, fmt_header,
  438. "Statistics_Rx - HT");
  439. PRINT_STATS_LE32("plcp_err", ht->plcp_err);
  440. PRINT_STATS_LE32("overrun_err", ht->overrun_err);
  441. PRINT_STATS_LE32("early_overrun_err", ht->early_overrun_err);
  442. PRINT_STATS_LE32("crc32_good", ht->crc32_good);
  443. PRINT_STATS_LE32("crc32_err", ht->crc32_err);
  444. PRINT_STATS_LE32("mh_format_err", ht->mh_format_err);
  445. PRINT_STATS_LE32("agg_crc32_good", ht->agg_crc32_good);
  446. PRINT_STATS_LE32("agg_mpdu_cnt", ht->agg_mpdu_cnt);
  447. PRINT_STATS_LE32("agg_cnt", ht->agg_cnt);
  448. PRINT_STATS_LE32("unsupport_mcs", ht->unsupport_mcs);
  449. mutex_unlock(&mvm->mutex);
  450. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  451. kfree(buf);
  452. return ret;
  453. }
  454. #undef PRINT_STAT_LE32
  455. static ssize_t iwl_dbgfs_fw_restart_write(struct iwl_mvm *mvm, char *buf,
  456. size_t count, loff_t *ppos)
  457. {
  458. int ret;
  459. mutex_lock(&mvm->mutex);
  460. /* allow one more restart that we're provoking here */
  461. if (mvm->restart_fw >= 0)
  462. mvm->restart_fw++;
  463. /* take the return value to make compiler happy - it will fail anyway */
  464. ret = iwl_mvm_send_cmd_pdu(mvm, REPLY_ERROR, CMD_SYNC, 0, NULL);
  465. mutex_unlock(&mvm->mutex);
  466. return count;
  467. }
  468. static ssize_t iwl_dbgfs_fw_nmi_write(struct iwl_mvm *mvm, char *buf,
  469. size_t count, loff_t *ppos)
  470. {
  471. iwl_write_prph(mvm->trans, DEVICE_SET_NMI_REG, 1);
  472. return count;
  473. }
  474. static ssize_t
  475. iwl_dbgfs_scan_ant_rxchain_read(struct file *file,
  476. char __user *user_buf,
  477. size_t count, loff_t *ppos)
  478. {
  479. struct iwl_mvm *mvm = file->private_data;
  480. int pos = 0;
  481. char buf[32];
  482. const size_t bufsz = sizeof(buf);
  483. /* print which antennas were set for the scan command by the user */
  484. pos += scnprintf(buf + pos, bufsz - pos, "Antennas for scan: ");
  485. if (mvm->scan_rx_ant & ANT_A)
  486. pos += scnprintf(buf + pos, bufsz - pos, "A");
  487. if (mvm->scan_rx_ant & ANT_B)
  488. pos += scnprintf(buf + pos, bufsz - pos, "B");
  489. if (mvm->scan_rx_ant & ANT_C)
  490. pos += scnprintf(buf + pos, bufsz - pos, "C");
  491. pos += scnprintf(buf + pos, bufsz - pos, " (%hhx)\n", mvm->scan_rx_ant);
  492. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  493. }
  494. static ssize_t
  495. iwl_dbgfs_scan_ant_rxchain_write(struct iwl_mvm *mvm, char *buf,
  496. size_t count, loff_t *ppos)
  497. {
  498. u8 scan_rx_ant;
  499. if (sscanf(buf, "%hhx", &scan_rx_ant) != 1)
  500. return -EINVAL;
  501. if (scan_rx_ant > ANT_ABC)
  502. return -EINVAL;
  503. if (scan_rx_ant & ~iwl_fw_valid_rx_ant(mvm->fw))
  504. return -EINVAL;
  505. mvm->scan_rx_ant = scan_rx_ant;
  506. return count;
  507. }
  508. #ifdef CONFIG_PM_SLEEP
  509. static ssize_t iwl_dbgfs_d3_sram_write(struct iwl_mvm *mvm, char *buf,
  510. size_t count, loff_t *ppos)
  511. {
  512. int store;
  513. if (sscanf(buf, "%d", &store) != 1)
  514. return -EINVAL;
  515. mvm->store_d3_resume_sram = store;
  516. return count;
  517. }
  518. static ssize_t iwl_dbgfs_d3_sram_read(struct file *file, char __user *user_buf,
  519. size_t count, loff_t *ppos)
  520. {
  521. struct iwl_mvm *mvm = file->private_data;
  522. const struct fw_img *img;
  523. int ofs, len, pos = 0;
  524. size_t bufsz, ret;
  525. char *buf;
  526. u8 *ptr = mvm->d3_resume_sram;
  527. img = &mvm->fw->img[IWL_UCODE_WOWLAN];
  528. len = img->sec[IWL_UCODE_SECTION_DATA].len;
  529. bufsz = len * 4 + 256;
  530. buf = kzalloc(bufsz, GFP_KERNEL);
  531. if (!buf)
  532. return -ENOMEM;
  533. pos += scnprintf(buf, bufsz, "D3 SRAM capture: %sabled\n",
  534. mvm->store_d3_resume_sram ? "en" : "dis");
  535. if (ptr) {
  536. for (ofs = 0; ofs < len; ofs += 16) {
  537. pos += scnprintf(buf + pos, bufsz - pos,
  538. "0x%.4x ", ofs);
  539. hex_dump_to_buffer(ptr + ofs, 16, 16, 1, buf + pos,
  540. bufsz - pos, false);
  541. pos += strlen(buf + pos);
  542. if (bufsz - pos > 0)
  543. buf[pos++] = '\n';
  544. }
  545. } else {
  546. pos += scnprintf(buf + pos, bufsz - pos,
  547. "(no data captured)\n");
  548. }
  549. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  550. kfree(buf);
  551. return ret;
  552. }
  553. #endif
  554. #define MVM_DEBUGFS_WRITE_FILE_OPS(name, bufsz) \
  555. _MVM_DEBUGFS_WRITE_FILE_OPS(name, bufsz, struct iwl_mvm)
  556. #define MVM_DEBUGFS_READ_WRITE_FILE_OPS(name, bufsz) \
  557. _MVM_DEBUGFS_READ_WRITE_FILE_OPS(name, bufsz, struct iwl_mvm)
  558. #define MVM_DEBUGFS_ADD_FILE(name, parent, mode) do { \
  559. if (!debugfs_create_file(#name, mode, parent, mvm, \
  560. &iwl_dbgfs_##name##_ops)) \
  561. goto err; \
  562. } while (0)
  563. /* Device wide debugfs entries */
  564. MVM_DEBUGFS_WRITE_FILE_OPS(tx_flush, 16);
  565. MVM_DEBUGFS_WRITE_FILE_OPS(sta_drain, 8);
  566. MVM_DEBUGFS_READ_WRITE_FILE_OPS(sram, 64);
  567. MVM_DEBUGFS_READ_FILE_OPS(stations);
  568. MVM_DEBUGFS_READ_FILE_OPS(bt_notif);
  569. MVM_DEBUGFS_READ_FILE_OPS(bt_cmd);
  570. MVM_DEBUGFS_READ_WRITE_FILE_OPS(disable_power_off, 64);
  571. MVM_DEBUGFS_READ_FILE_OPS(fw_rx_stats);
  572. MVM_DEBUGFS_WRITE_FILE_OPS(fw_restart, 10);
  573. MVM_DEBUGFS_WRITE_FILE_OPS(fw_nmi, 10);
  574. MVM_DEBUGFS_READ_WRITE_FILE_OPS(scan_ant_rxchain, 8);
  575. #ifdef CONFIG_PM_SLEEP
  576. MVM_DEBUGFS_READ_WRITE_FILE_OPS(d3_sram, 8);
  577. #endif
  578. int iwl_mvm_dbgfs_register(struct iwl_mvm *mvm, struct dentry *dbgfs_dir)
  579. {
  580. char buf[100];
  581. mvm->debugfs_dir = dbgfs_dir;
  582. MVM_DEBUGFS_ADD_FILE(tx_flush, mvm->debugfs_dir, S_IWUSR);
  583. MVM_DEBUGFS_ADD_FILE(sta_drain, mvm->debugfs_dir, S_IWUSR);
  584. MVM_DEBUGFS_ADD_FILE(sram, mvm->debugfs_dir, S_IWUSR | S_IRUSR);
  585. MVM_DEBUGFS_ADD_FILE(stations, dbgfs_dir, S_IRUSR);
  586. MVM_DEBUGFS_ADD_FILE(bt_notif, dbgfs_dir, S_IRUSR);
  587. MVM_DEBUGFS_ADD_FILE(bt_cmd, dbgfs_dir, S_IRUSR);
  588. if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_DEVICE_PS_CMD)
  589. MVM_DEBUGFS_ADD_FILE(disable_power_off, mvm->debugfs_dir,
  590. S_IRUSR | S_IWUSR);
  591. MVM_DEBUGFS_ADD_FILE(fw_rx_stats, mvm->debugfs_dir, S_IRUSR);
  592. MVM_DEBUGFS_ADD_FILE(fw_restart, mvm->debugfs_dir, S_IWUSR);
  593. MVM_DEBUGFS_ADD_FILE(fw_nmi, mvm->debugfs_dir, S_IWUSR);
  594. MVM_DEBUGFS_ADD_FILE(scan_ant_rxchain, mvm->debugfs_dir,
  595. S_IWUSR | S_IRUSR);
  596. #ifdef CONFIG_PM_SLEEP
  597. MVM_DEBUGFS_ADD_FILE(d3_sram, mvm->debugfs_dir, S_IRUSR | S_IWUSR);
  598. MVM_DEBUGFS_ADD_FILE(d3_test, mvm->debugfs_dir, S_IRUSR);
  599. if (!debugfs_create_bool("d3_wake_sysassert", S_IRUSR | S_IWUSR,
  600. mvm->debugfs_dir, &mvm->d3_wake_sysassert))
  601. goto err;
  602. #endif
  603. if (!debugfs_create_blob("nvm_hw", S_IRUSR,
  604. mvm->debugfs_dir, &mvm->nvm_hw_blob))
  605. goto err;
  606. if (!debugfs_create_blob("nvm_sw", S_IRUSR,
  607. mvm->debugfs_dir, &mvm->nvm_sw_blob))
  608. goto err;
  609. if (!debugfs_create_blob("nvm_calib", S_IRUSR,
  610. mvm->debugfs_dir, &mvm->nvm_calib_blob))
  611. goto err;
  612. if (!debugfs_create_blob("nvm_prod", S_IRUSR,
  613. mvm->debugfs_dir, &mvm->nvm_prod_blob))
  614. goto err;
  615. /*
  616. * Create a symlink with mac80211. It will be removed when mac80211
  617. * exists (before the opmode exists which removes the target.)
  618. */
  619. snprintf(buf, 100, "../../%s/%s",
  620. dbgfs_dir->d_parent->d_parent->d_name.name,
  621. dbgfs_dir->d_parent->d_name.name);
  622. if (!debugfs_create_symlink("iwlwifi", mvm->hw->wiphy->debugfsdir, buf))
  623. goto err;
  624. return 0;
  625. err:
  626. IWL_ERR(mvm, "Can't create the mvm debugfs directory\n");
  627. return -ENOMEM;
  628. }