debugfs.c 17 KB

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