debugfs.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685
  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 - 2013 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 - 2013 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. struct iwl_dbgfs_mvm_ctx {
  67. struct iwl_mvm *mvm;
  68. struct ieee80211_vif *vif;
  69. };
  70. static ssize_t iwl_dbgfs_tx_flush_write(struct file *file,
  71. const char __user *user_buf,
  72. size_t count, loff_t *ppos)
  73. {
  74. struct iwl_mvm *mvm = file->private_data;
  75. char buf[16];
  76. int buf_size, ret;
  77. u32 scd_q_msk;
  78. if (!mvm->ucode_loaded || mvm->cur_ucode != IWL_UCODE_REGULAR)
  79. return -EIO;
  80. memset(buf, 0, sizeof(buf));
  81. buf_size = min(count, sizeof(buf) - 1);
  82. if (copy_from_user(buf, user_buf, buf_size))
  83. return -EFAULT;
  84. if (sscanf(buf, "%x", &scd_q_msk) != 1)
  85. return -EINVAL;
  86. IWL_ERR(mvm, "FLUSHING queues: scd_q_msk = 0x%x\n", scd_q_msk);
  87. mutex_lock(&mvm->mutex);
  88. ret = iwl_mvm_flush_tx_path(mvm, scd_q_msk, true) ? : count;
  89. mutex_unlock(&mvm->mutex);
  90. return ret;
  91. }
  92. static ssize_t iwl_dbgfs_sta_drain_write(struct file *file,
  93. const char __user *user_buf,
  94. size_t count, loff_t *ppos)
  95. {
  96. struct iwl_mvm *mvm = file->private_data;
  97. struct ieee80211_sta *sta;
  98. char buf[8];
  99. int buf_size, sta_id, drain, ret;
  100. if (!mvm->ucode_loaded || mvm->cur_ucode != IWL_UCODE_REGULAR)
  101. return -EIO;
  102. memset(buf, 0, sizeof(buf));
  103. buf_size = min(count, sizeof(buf) - 1);
  104. if (copy_from_user(buf, user_buf, buf_size))
  105. return -EFAULT;
  106. if (sscanf(buf, "%d %d", &sta_id, &drain) != 2)
  107. return -EINVAL;
  108. mutex_lock(&mvm->mutex);
  109. sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[sta_id],
  110. lockdep_is_held(&mvm->mutex));
  111. if (IS_ERR_OR_NULL(sta))
  112. ret = -ENOENT;
  113. else
  114. ret = iwl_mvm_drain_sta(mvm, (void *)sta->drv_priv, drain) ? :
  115. count;
  116. mutex_unlock(&mvm->mutex);
  117. return ret;
  118. }
  119. static ssize_t iwl_dbgfs_sram_read(struct file *file, char __user *user_buf,
  120. size_t count, loff_t *ppos)
  121. {
  122. struct iwl_mvm *mvm = file->private_data;
  123. const struct fw_img *img;
  124. int ofs, len, pos = 0;
  125. size_t bufsz, ret;
  126. char *buf;
  127. u8 *ptr;
  128. if (!mvm->ucode_loaded)
  129. return -EINVAL;
  130. /* default is to dump the entire data segment */
  131. if (!mvm->dbgfs_sram_offset && !mvm->dbgfs_sram_len) {
  132. img = &mvm->fw->img[mvm->cur_ucode];
  133. ofs = img->sec[IWL_UCODE_SECTION_DATA].offset;
  134. len = img->sec[IWL_UCODE_SECTION_DATA].len;
  135. } else {
  136. ofs = mvm->dbgfs_sram_offset;
  137. len = mvm->dbgfs_sram_len;
  138. }
  139. bufsz = len * 4 + 256;
  140. buf = kzalloc(bufsz, GFP_KERNEL);
  141. if (!buf)
  142. return -ENOMEM;
  143. ptr = kzalloc(len, GFP_KERNEL);
  144. if (!ptr) {
  145. kfree(buf);
  146. return -ENOMEM;
  147. }
  148. pos += scnprintf(buf + pos, bufsz - pos, "sram_len: 0x%x\n", len);
  149. pos += scnprintf(buf + pos, bufsz - pos, "sram_offset: 0x%x\n", ofs);
  150. iwl_trans_read_mem_bytes(mvm->trans, ofs, ptr, len);
  151. for (ofs = 0; ofs < len; ofs += 16) {
  152. pos += scnprintf(buf + pos, bufsz - pos, "0x%.4x ", ofs);
  153. hex_dump_to_buffer(ptr + ofs, 16, 16, 1, buf + pos,
  154. bufsz - pos, false);
  155. pos += strlen(buf + pos);
  156. if (bufsz - pos > 0)
  157. buf[pos++] = '\n';
  158. }
  159. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  160. kfree(buf);
  161. kfree(ptr);
  162. return ret;
  163. }
  164. static ssize_t iwl_dbgfs_sram_write(struct file *file,
  165. const char __user *user_buf, size_t count,
  166. loff_t *ppos)
  167. {
  168. struct iwl_mvm *mvm = file->private_data;
  169. char buf[64];
  170. int buf_size;
  171. u32 offset, len;
  172. memset(buf, 0, sizeof(buf));
  173. buf_size = min(count, sizeof(buf) - 1);
  174. if (copy_from_user(buf, user_buf, buf_size))
  175. return -EFAULT;
  176. if (sscanf(buf, "%x,%x", &offset, &len) == 2) {
  177. if ((offset & 0x3) || (len & 0x3))
  178. return -EINVAL;
  179. mvm->dbgfs_sram_offset = offset;
  180. mvm->dbgfs_sram_len = len;
  181. } else {
  182. mvm->dbgfs_sram_offset = 0;
  183. mvm->dbgfs_sram_len = 0;
  184. }
  185. return count;
  186. }
  187. static ssize_t iwl_dbgfs_stations_read(struct file *file, char __user *user_buf,
  188. size_t count, loff_t *ppos)
  189. {
  190. struct iwl_mvm *mvm = file->private_data;
  191. struct ieee80211_sta *sta;
  192. char buf[400];
  193. int i, pos = 0, bufsz = sizeof(buf);
  194. mutex_lock(&mvm->mutex);
  195. for (i = 0; i < IWL_MVM_STATION_COUNT; i++) {
  196. pos += scnprintf(buf + pos, bufsz - pos, "%.2d: ", i);
  197. sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[i],
  198. lockdep_is_held(&mvm->mutex));
  199. if (!sta)
  200. pos += scnprintf(buf + pos, bufsz - pos, "N/A\n");
  201. else if (IS_ERR(sta))
  202. pos += scnprintf(buf + pos, bufsz - pos, "%ld\n",
  203. PTR_ERR(sta));
  204. else
  205. pos += scnprintf(buf + pos, bufsz - pos, "%pM\n",
  206. sta->addr);
  207. }
  208. mutex_unlock(&mvm->mutex);
  209. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  210. }
  211. static ssize_t iwl_dbgfs_power_down_allow_write(struct file *file,
  212. const char __user *user_buf,
  213. size_t count, loff_t *ppos)
  214. {
  215. struct iwl_mvm *mvm = file->private_data;
  216. char buf[8] = {};
  217. int allow;
  218. if (!mvm->ucode_loaded)
  219. return -EIO;
  220. if (copy_from_user(buf, user_buf, sizeof(buf)))
  221. return -EFAULT;
  222. if (sscanf(buf, "%d", &allow) != 1)
  223. return -EINVAL;
  224. IWL_DEBUG_POWER(mvm, "%s device power down\n",
  225. allow ? "allow" : "prevent");
  226. /*
  227. * TODO: Send REPLY_DEBUG_CMD (0xf0) when FW support it
  228. */
  229. return count;
  230. }
  231. static ssize_t iwl_dbgfs_power_down_d3_allow_write(struct file *file,
  232. const char __user *user_buf,
  233. size_t count, loff_t *ppos)
  234. {
  235. struct iwl_mvm *mvm = file->private_data;
  236. char buf[8] = {};
  237. int allow;
  238. if (copy_from_user(buf, user_buf, sizeof(buf)))
  239. return -EFAULT;
  240. if (sscanf(buf, "%d", &allow) != 1)
  241. return -EINVAL;
  242. IWL_DEBUG_POWER(mvm, "%s device power down in d3\n",
  243. allow ? "allow" : "prevent");
  244. /*
  245. * TODO: When WoWLAN FW alive notification happens, driver will send
  246. * REPLY_DEBUG_CMD setting power_down_allow flag according to
  247. * mvm->prevent_power_down_d3
  248. */
  249. mvm->prevent_power_down_d3 = !allow;
  250. return count;
  251. }
  252. static ssize_t iwl_dbgfs_mac_params_read(struct file *file,
  253. char __user *user_buf,
  254. size_t count, loff_t *ppos)
  255. {
  256. struct ieee80211_vif *vif = file->private_data;
  257. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  258. struct iwl_mvm *mvm = mvmvif->dbgfs_data;
  259. u8 ap_sta_id;
  260. struct ieee80211_chanctx_conf *chanctx_conf;
  261. char buf[512];
  262. int bufsz = sizeof(buf);
  263. int pos = 0;
  264. int i;
  265. mutex_lock(&mvm->mutex);
  266. ap_sta_id = mvmvif->ap_sta_id;
  267. pos += scnprintf(buf+pos, bufsz-pos, "mac id/color: %d / %d\n",
  268. mvmvif->id, mvmvif->color);
  269. pos += scnprintf(buf+pos, bufsz-pos, "bssid: %pM\n",
  270. vif->bss_conf.bssid);
  271. pos += scnprintf(buf+pos, bufsz-pos, "QoS:\n");
  272. for (i = 0; i < ARRAY_SIZE(mvmvif->queue_params); i++) {
  273. pos += scnprintf(buf+pos, bufsz-pos,
  274. "\t%d: txop:%d - cw_min:%d - cw_max = %d - aifs = %d upasd = %d\n",
  275. i, mvmvif->queue_params[i].txop,
  276. mvmvif->queue_params[i].cw_min,
  277. mvmvif->queue_params[i].cw_max,
  278. mvmvif->queue_params[i].aifs,
  279. mvmvif->queue_params[i].uapsd);
  280. }
  281. if (vif->type == NL80211_IFTYPE_STATION &&
  282. ap_sta_id != IWL_MVM_STATION_COUNT) {
  283. struct ieee80211_sta *sta;
  284. struct iwl_mvm_sta *mvm_sta;
  285. sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[ap_sta_id],
  286. lockdep_is_held(&mvm->mutex));
  287. mvm_sta = (void *)sta->drv_priv;
  288. pos += scnprintf(buf+pos, bufsz-pos,
  289. "ap_sta_id %d - reduced Tx power %d\n",
  290. ap_sta_id, mvm_sta->bt_reduced_txpower);
  291. }
  292. rcu_read_lock();
  293. chanctx_conf = rcu_dereference(vif->chanctx_conf);
  294. if (chanctx_conf) {
  295. pos += scnprintf(buf+pos, bufsz-pos,
  296. "idle rx chains %d, active rx chains: %d\n",
  297. chanctx_conf->rx_chains_static,
  298. chanctx_conf->rx_chains_dynamic);
  299. }
  300. rcu_read_unlock();
  301. mutex_unlock(&mvm->mutex);
  302. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  303. }
  304. #define BT_MBOX_MSG(_notif, _num, _field) \
  305. ((le32_to_cpu((_notif)->mbox_msg[(_num)]) & BT_MBOX##_num##_##_field)\
  306. >> BT_MBOX##_num##_##_field##_POS)
  307. #define BT_MBOX_PRINT(_num, _field, _end) \
  308. pos += scnprintf(buf + pos, bufsz - pos, \
  309. "\t%s: %d%s", \
  310. #_field, \
  311. BT_MBOX_MSG(notif, _num, _field), \
  312. true ? "\n" : ", ");
  313. static ssize_t iwl_dbgfs_bt_notif_read(struct file *file, char __user *user_buf,
  314. size_t count, loff_t *ppos)
  315. {
  316. struct iwl_mvm *mvm = file->private_data;
  317. struct iwl_bt_coex_profile_notif *notif = &mvm->last_bt_notif;
  318. char *buf;
  319. int ret, pos = 0, bufsz = sizeof(char) * 1024;
  320. buf = kmalloc(bufsz, GFP_KERNEL);
  321. if (!buf)
  322. return -ENOMEM;
  323. mutex_lock(&mvm->mutex);
  324. pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw0:\n");
  325. BT_MBOX_PRINT(0, LE_SLAVE_LAT, false);
  326. BT_MBOX_PRINT(0, LE_PROF1, false);
  327. BT_MBOX_PRINT(0, LE_PROF2, false);
  328. BT_MBOX_PRINT(0, LE_PROF_OTHER, false);
  329. BT_MBOX_PRINT(0, CHL_SEQ_N, false);
  330. BT_MBOX_PRINT(0, INBAND_S, false);
  331. BT_MBOX_PRINT(0, LE_MIN_RSSI, false);
  332. BT_MBOX_PRINT(0, LE_SCAN, false);
  333. BT_MBOX_PRINT(0, LE_ADV, false);
  334. BT_MBOX_PRINT(0, LE_MAX_TX_POWER, false);
  335. BT_MBOX_PRINT(0, OPEN_CON_1, true);
  336. pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw1:\n");
  337. BT_MBOX_PRINT(1, BR_MAX_TX_POWER, false);
  338. BT_MBOX_PRINT(1, IP_SR, false);
  339. BT_MBOX_PRINT(1, LE_MSTR, false);
  340. BT_MBOX_PRINT(1, AGGR_TRFC_LD, false);
  341. BT_MBOX_PRINT(1, MSG_TYPE, false);
  342. BT_MBOX_PRINT(1, SSN, true);
  343. pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw2:\n");
  344. BT_MBOX_PRINT(2, SNIFF_ACT, false);
  345. BT_MBOX_PRINT(2, PAG, false);
  346. BT_MBOX_PRINT(2, INQUIRY, false);
  347. BT_MBOX_PRINT(2, CONN, false);
  348. BT_MBOX_PRINT(2, SNIFF_INTERVAL, false);
  349. BT_MBOX_PRINT(2, DISC, false);
  350. BT_MBOX_PRINT(2, SCO_TX_ACT, false);
  351. BT_MBOX_PRINT(2, SCO_RX_ACT, false);
  352. BT_MBOX_PRINT(2, ESCO_RE_TX, false);
  353. BT_MBOX_PRINT(2, SCO_DURATION, true);
  354. pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw3:\n");
  355. BT_MBOX_PRINT(3, SCO_STATE, false);
  356. BT_MBOX_PRINT(3, SNIFF_STATE, false);
  357. BT_MBOX_PRINT(3, A2DP_STATE, false);
  358. BT_MBOX_PRINT(3, ACL_STATE, false);
  359. BT_MBOX_PRINT(3, MSTR_STATE, false);
  360. BT_MBOX_PRINT(3, OBX_STATE, false);
  361. BT_MBOX_PRINT(3, OPEN_CON_2, false);
  362. BT_MBOX_PRINT(3, TRAFFIC_LOAD, false);
  363. BT_MBOX_PRINT(3, CHL_SEQN_LSB, false);
  364. BT_MBOX_PRINT(3, INBAND_P, false);
  365. BT_MBOX_PRINT(3, MSG_TYPE_2, false);
  366. BT_MBOX_PRINT(3, SSN_2, false);
  367. BT_MBOX_PRINT(3, UPDATE_REQUEST, true);
  368. pos += scnprintf(buf+pos, bufsz-pos, "bt_status = %d\n",
  369. notif->bt_status);
  370. pos += scnprintf(buf+pos, bufsz-pos, "bt_open_conn = %d\n",
  371. notif->bt_open_conn);
  372. pos += scnprintf(buf+pos, bufsz-pos, "bt_traffic_load = %d\n",
  373. notif->bt_traffic_load);
  374. pos += scnprintf(buf+pos, bufsz-pos, "bt_agg_traffic_load = %d\n",
  375. notif->bt_agg_traffic_load);
  376. pos += scnprintf(buf+pos, bufsz-pos, "bt_ci_compliance = %d\n",
  377. notif->bt_ci_compliance);
  378. mutex_unlock(&mvm->mutex);
  379. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  380. kfree(buf);
  381. return ret;
  382. }
  383. #undef BT_MBOX_PRINT
  384. static ssize_t iwl_dbgfs_fw_restart_write(struct file *file,
  385. const char __user *user_buf,
  386. size_t count, loff_t *ppos)
  387. {
  388. struct iwl_mvm *mvm = file->private_data;
  389. bool restart_fw = iwlwifi_mod_params.restart_fw;
  390. int ret;
  391. iwlwifi_mod_params.restart_fw = true;
  392. mutex_lock(&mvm->mutex);
  393. /* take the return value to make compiler happy - it will fail anyway */
  394. ret = iwl_mvm_send_cmd_pdu(mvm, REPLY_ERROR, CMD_SYNC, 0, NULL);
  395. mutex_unlock(&mvm->mutex);
  396. iwlwifi_mod_params.restart_fw = restart_fw;
  397. return count;
  398. }
  399. #ifdef CONFIG_PM_SLEEP
  400. static ssize_t iwl_dbgfs_d3_sram_write(struct file *file,
  401. const char __user *user_buf,
  402. size_t count, loff_t *ppos)
  403. {
  404. struct iwl_mvm *mvm = file->private_data;
  405. char buf[8] = {};
  406. int store;
  407. if (copy_from_user(buf, user_buf, sizeof(buf)))
  408. return -EFAULT;
  409. if (sscanf(buf, "%d", &store) != 1)
  410. return -EINVAL;
  411. mvm->store_d3_resume_sram = store;
  412. return count;
  413. }
  414. static ssize_t iwl_dbgfs_d3_sram_read(struct file *file, char __user *user_buf,
  415. size_t count, loff_t *ppos)
  416. {
  417. struct iwl_mvm *mvm = file->private_data;
  418. const struct fw_img *img;
  419. int ofs, len, pos = 0;
  420. size_t bufsz, ret;
  421. char *buf;
  422. u8 *ptr = mvm->d3_resume_sram;
  423. img = &mvm->fw->img[IWL_UCODE_WOWLAN];
  424. len = img->sec[IWL_UCODE_SECTION_DATA].len;
  425. bufsz = len * 4 + 256;
  426. buf = kzalloc(bufsz, GFP_KERNEL);
  427. if (!buf)
  428. return -ENOMEM;
  429. pos += scnprintf(buf, bufsz, "D3 SRAM capture: %sabled\n",
  430. mvm->store_d3_resume_sram ? "en" : "dis");
  431. if (ptr) {
  432. for (ofs = 0; ofs < len; ofs += 16) {
  433. pos += scnprintf(buf + pos, bufsz - pos,
  434. "0x%.4x ", ofs);
  435. hex_dump_to_buffer(ptr + ofs, 16, 16, 1, buf + pos,
  436. bufsz - pos, false);
  437. pos += strlen(buf + pos);
  438. if (bufsz - pos > 0)
  439. buf[pos++] = '\n';
  440. }
  441. } else {
  442. pos += scnprintf(buf + pos, bufsz - pos,
  443. "(no data captured)\n");
  444. }
  445. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  446. kfree(buf);
  447. return ret;
  448. }
  449. #endif
  450. #define MVM_DEBUGFS_READ_FILE_OPS(name) \
  451. static const struct file_operations iwl_dbgfs_##name##_ops = { \
  452. .read = iwl_dbgfs_##name##_read, \
  453. .open = simple_open, \
  454. .llseek = generic_file_llseek, \
  455. }
  456. #define MVM_DEBUGFS_READ_WRITE_FILE_OPS(name) \
  457. static const struct file_operations iwl_dbgfs_##name##_ops = { \
  458. .write = iwl_dbgfs_##name##_write, \
  459. .read = iwl_dbgfs_##name##_read, \
  460. .open = simple_open, \
  461. .llseek = generic_file_llseek, \
  462. };
  463. #define MVM_DEBUGFS_WRITE_FILE_OPS(name) \
  464. static const struct file_operations iwl_dbgfs_##name##_ops = { \
  465. .write = iwl_dbgfs_##name##_write, \
  466. .open = simple_open, \
  467. .llseek = generic_file_llseek, \
  468. };
  469. #define MVM_DEBUGFS_ADD_FILE(name, parent, mode) do { \
  470. if (!debugfs_create_file(#name, mode, parent, mvm, \
  471. &iwl_dbgfs_##name##_ops)) \
  472. goto err; \
  473. } while (0)
  474. #define MVM_DEBUGFS_ADD_FILE_VIF(name, parent, mode) do { \
  475. if (!debugfs_create_file(#name, mode, parent, vif, \
  476. &iwl_dbgfs_##name##_ops)) \
  477. goto err; \
  478. } while (0)
  479. /* Device wide debugfs entries */
  480. MVM_DEBUGFS_WRITE_FILE_OPS(tx_flush);
  481. MVM_DEBUGFS_WRITE_FILE_OPS(sta_drain);
  482. MVM_DEBUGFS_READ_WRITE_FILE_OPS(sram);
  483. MVM_DEBUGFS_READ_FILE_OPS(stations);
  484. MVM_DEBUGFS_READ_FILE_OPS(bt_notif);
  485. MVM_DEBUGFS_WRITE_FILE_OPS(power_down_allow);
  486. MVM_DEBUGFS_WRITE_FILE_OPS(power_down_d3_allow);
  487. MVM_DEBUGFS_WRITE_FILE_OPS(fw_restart);
  488. #ifdef CONFIG_PM_SLEEP
  489. MVM_DEBUGFS_READ_WRITE_FILE_OPS(d3_sram);
  490. #endif
  491. /* Interface specific debugfs entries */
  492. MVM_DEBUGFS_READ_FILE_OPS(mac_params);
  493. int iwl_mvm_dbgfs_register(struct iwl_mvm *mvm, struct dentry *dbgfs_dir)
  494. {
  495. char buf[100];
  496. mvm->debugfs_dir = dbgfs_dir;
  497. MVM_DEBUGFS_ADD_FILE(tx_flush, mvm->debugfs_dir, S_IWUSR);
  498. MVM_DEBUGFS_ADD_FILE(sta_drain, mvm->debugfs_dir, S_IWUSR);
  499. MVM_DEBUGFS_ADD_FILE(sram, mvm->debugfs_dir, S_IWUSR | S_IRUSR);
  500. MVM_DEBUGFS_ADD_FILE(stations, dbgfs_dir, S_IRUSR);
  501. MVM_DEBUGFS_ADD_FILE(bt_notif, dbgfs_dir, S_IRUSR);
  502. MVM_DEBUGFS_ADD_FILE(power_down_allow, mvm->debugfs_dir, S_IWUSR);
  503. MVM_DEBUGFS_ADD_FILE(power_down_d3_allow, mvm->debugfs_dir, S_IWUSR);
  504. MVM_DEBUGFS_ADD_FILE(fw_restart, mvm->debugfs_dir, S_IWUSR);
  505. #ifdef CONFIG_PM_SLEEP
  506. MVM_DEBUGFS_ADD_FILE(d3_sram, mvm->debugfs_dir, S_IRUSR | S_IWUSR);
  507. #endif
  508. /*
  509. * Create a symlink with mac80211. It will be removed when mac80211
  510. * exists (before the opmode exists which removes the target.)
  511. */
  512. snprintf(buf, 100, "../../%s/%s",
  513. dbgfs_dir->d_parent->d_parent->d_name.name,
  514. dbgfs_dir->d_parent->d_name.name);
  515. if (!debugfs_create_symlink("iwlwifi", mvm->hw->wiphy->debugfsdir, buf))
  516. goto err;
  517. return 0;
  518. err:
  519. IWL_ERR(mvm, "Can't create the mvm debugfs directory\n");
  520. return -ENOMEM;
  521. }
  522. void iwl_mvm_vif_dbgfs_register(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
  523. {
  524. struct dentry *dbgfs_dir = vif->debugfs_dir;
  525. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  526. char buf[100];
  527. if (!dbgfs_dir)
  528. return;
  529. mvmvif->dbgfs_dir = debugfs_create_dir("iwlmvm", dbgfs_dir);
  530. mvmvif->dbgfs_data = mvm;
  531. if (!mvmvif->dbgfs_dir) {
  532. IWL_ERR(mvm, "Failed to create debugfs directory under %s\n",
  533. dbgfs_dir->d_name.name);
  534. return;
  535. }
  536. MVM_DEBUGFS_ADD_FILE_VIF(mac_params, mvmvif->dbgfs_dir,
  537. S_IRUSR);
  538. /*
  539. * Create symlink for convenience pointing to interface specific
  540. * debugfs entries for the driver. For example, under
  541. * /sys/kernel/debug/iwlwifi/0000\:02\:00.0/iwlmvm/
  542. * find
  543. * netdev:wlan0 -> ../../../ieee80211/phy0/netdev:wlan0/iwlmvm/
  544. */
  545. snprintf(buf, 100, "../../../%s/%s/%s/%s",
  546. dbgfs_dir->d_parent->d_parent->d_name.name,
  547. dbgfs_dir->d_parent->d_name.name,
  548. dbgfs_dir->d_name.name,
  549. mvmvif->dbgfs_dir->d_name.name);
  550. mvmvif->dbgfs_slink = debugfs_create_symlink(dbgfs_dir->d_name.name,
  551. mvm->debugfs_dir, buf);
  552. if (!mvmvif->dbgfs_slink)
  553. IWL_ERR(mvm, "Can't create debugfs symbolic link under %s\n",
  554. dbgfs_dir->d_name.name);
  555. return;
  556. err:
  557. IWL_ERR(mvm, "Can't create debugfs entity\n");
  558. }
  559. void iwl_mvm_vif_dbgfs_clean(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
  560. {
  561. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  562. debugfs_remove(mvmvif->dbgfs_slink);
  563. mvmvif->dbgfs_slink = NULL;
  564. debugfs_remove_recursive(mvmvif->dbgfs_dir);
  565. mvmvif->dbgfs_dir = NULL;
  566. }