debugfs.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615
  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. ap_sta_id != IWL_MVM_STATION_COUNT) {
  284. struct ieee80211_sta *sta;
  285. struct iwl_mvm_sta *mvm_sta;
  286. sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[ap_sta_id],
  287. lockdep_is_held(&mvm->mutex));
  288. mvm_sta = (void *)sta->drv_priv;
  289. pos += scnprintf(buf+pos, bufsz-pos,
  290. "ap_sta_id %d - reduced Tx power %d\n",
  291. ap_sta_id, mvm_sta->bt_reduced_txpower);
  292. }
  293. rcu_read_lock();
  294. chanctx_conf = rcu_dereference(vif->chanctx_conf);
  295. if (chanctx_conf) {
  296. pos += scnprintf(buf+pos, bufsz-pos,
  297. "idle rx chains %d, active rx chains: %d\n",
  298. chanctx_conf->rx_chains_static,
  299. chanctx_conf->rx_chains_dynamic);
  300. }
  301. rcu_read_unlock();
  302. mutex_unlock(&mvm->mutex);
  303. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  304. }
  305. #define BT_MBOX_MSG(_notif, _num, _field) \
  306. ((le32_to_cpu((_notif)->mbox_msg[(_num)]) & BT_MBOX##_num##_##_field)\
  307. >> BT_MBOX##_num##_##_field##_POS)
  308. #define BT_MBOX_PRINT(_num, _field, _end) \
  309. pos += scnprintf(buf + pos, bufsz - pos, \
  310. "\t%s: %d%s", \
  311. #_field, \
  312. BT_MBOX_MSG(notif, _num, _field), \
  313. true ? "\n" : ", ");
  314. static ssize_t iwl_dbgfs_bt_notif_read(struct file *file, char __user *user_buf,
  315. size_t count, loff_t *ppos)
  316. {
  317. struct iwl_mvm *mvm = file->private_data;
  318. struct iwl_bt_coex_profile_notif *notif = &mvm->last_bt_notif;
  319. char *buf;
  320. int ret, pos = 0, bufsz = sizeof(char) * 1024;
  321. buf = kmalloc(bufsz, GFP_KERNEL);
  322. if (!buf)
  323. return -ENOMEM;
  324. mutex_lock(&mvm->mutex);
  325. pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw0:\n");
  326. BT_MBOX_PRINT(0, LE_SLAVE_LAT, false);
  327. BT_MBOX_PRINT(0, LE_PROF1, false);
  328. BT_MBOX_PRINT(0, LE_PROF2, false);
  329. BT_MBOX_PRINT(0, LE_PROF_OTHER, false);
  330. BT_MBOX_PRINT(0, CHL_SEQ_N, false);
  331. BT_MBOX_PRINT(0, INBAND_S, false);
  332. BT_MBOX_PRINT(0, LE_MIN_RSSI, false);
  333. BT_MBOX_PRINT(0, LE_SCAN, false);
  334. BT_MBOX_PRINT(0, LE_ADV, false);
  335. BT_MBOX_PRINT(0, LE_MAX_TX_POWER, false);
  336. BT_MBOX_PRINT(0, OPEN_CON_1, true);
  337. pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw1:\n");
  338. BT_MBOX_PRINT(1, BR_MAX_TX_POWER, false);
  339. BT_MBOX_PRINT(1, IP_SR, false);
  340. BT_MBOX_PRINT(1, LE_MSTR, false);
  341. BT_MBOX_PRINT(1, AGGR_TRFC_LD, false);
  342. BT_MBOX_PRINT(1, MSG_TYPE, false);
  343. BT_MBOX_PRINT(1, SSN, true);
  344. pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw2:\n");
  345. BT_MBOX_PRINT(2, SNIFF_ACT, false);
  346. BT_MBOX_PRINT(2, PAG, false);
  347. BT_MBOX_PRINT(2, INQUIRY, false);
  348. BT_MBOX_PRINT(2, CONN, false);
  349. BT_MBOX_PRINT(2, SNIFF_INTERVAL, false);
  350. BT_MBOX_PRINT(2, DISC, false);
  351. BT_MBOX_PRINT(2, SCO_TX_ACT, false);
  352. BT_MBOX_PRINT(2, SCO_RX_ACT, false);
  353. BT_MBOX_PRINT(2, ESCO_RE_TX, false);
  354. BT_MBOX_PRINT(2, SCO_DURATION, true);
  355. pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw3:\n");
  356. BT_MBOX_PRINT(3, SCO_STATE, false);
  357. BT_MBOX_PRINT(3, SNIFF_STATE, false);
  358. BT_MBOX_PRINT(3, A2DP_STATE, false);
  359. BT_MBOX_PRINT(3, ACL_STATE, false);
  360. BT_MBOX_PRINT(3, MSTR_STATE, false);
  361. BT_MBOX_PRINT(3, OBX_STATE, false);
  362. BT_MBOX_PRINT(3, OPEN_CON_2, false);
  363. BT_MBOX_PRINT(3, TRAFFIC_LOAD, false);
  364. BT_MBOX_PRINT(3, CHL_SEQN_LSB, false);
  365. BT_MBOX_PRINT(3, INBAND_P, false);
  366. BT_MBOX_PRINT(3, MSG_TYPE_2, false);
  367. BT_MBOX_PRINT(3, SSN_2, false);
  368. BT_MBOX_PRINT(3, UPDATE_REQUEST, true);
  369. pos += scnprintf(buf+pos, bufsz-pos, "bt_status = %d\n",
  370. notif->bt_status);
  371. pos += scnprintf(buf+pos, bufsz-pos, "bt_open_conn = %d\n",
  372. notif->bt_open_conn);
  373. pos += scnprintf(buf+pos, bufsz-pos, "bt_traffic_load = %d\n",
  374. notif->bt_traffic_load);
  375. pos += scnprintf(buf+pos, bufsz-pos, "bt_agg_traffic_load = %d\n",
  376. notif->bt_agg_traffic_load);
  377. pos += scnprintf(buf+pos, bufsz-pos, "bt_ci_compliance = %d\n",
  378. notif->bt_ci_compliance);
  379. mutex_unlock(&mvm->mutex);
  380. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  381. kfree(buf);
  382. return ret;
  383. }
  384. #undef BT_MBOX_PRINT
  385. static ssize_t iwl_dbgfs_fw_restart_write(struct file *file,
  386. const char __user *user_buf,
  387. size_t count, loff_t *ppos)
  388. {
  389. struct iwl_mvm *mvm = file->private_data;
  390. bool restart_fw = iwlwifi_mod_params.restart_fw;
  391. int ret;
  392. iwlwifi_mod_params.restart_fw = true;
  393. mutex_lock(&mvm->mutex);
  394. /* take the return value to make compiler happy - it will fail anyway */
  395. ret = iwl_mvm_send_cmd_pdu(mvm, REPLY_ERROR, CMD_SYNC, 0, NULL);
  396. mutex_unlock(&mvm->mutex);
  397. iwlwifi_mod_params.restart_fw = restart_fw;
  398. return count;
  399. }
  400. #define MVM_DEBUGFS_READ_FILE_OPS(name) \
  401. static const struct file_operations iwl_dbgfs_##name##_ops = { \
  402. .read = iwl_dbgfs_##name##_read, \
  403. .open = simple_open, \
  404. .llseek = generic_file_llseek, \
  405. }
  406. #define MVM_DEBUGFS_READ_WRITE_FILE_OPS(name) \
  407. static const struct file_operations iwl_dbgfs_##name##_ops = { \
  408. .write = iwl_dbgfs_##name##_write, \
  409. .read = iwl_dbgfs_##name##_read, \
  410. .open = simple_open, \
  411. .llseek = generic_file_llseek, \
  412. };
  413. #define MVM_DEBUGFS_WRITE_FILE_OPS(name) \
  414. static const struct file_operations iwl_dbgfs_##name##_ops = { \
  415. .write = iwl_dbgfs_##name##_write, \
  416. .open = simple_open, \
  417. .llseek = generic_file_llseek, \
  418. };
  419. #define MVM_DEBUGFS_ADD_FILE(name, parent, mode) do { \
  420. if (!debugfs_create_file(#name, mode, parent, mvm, \
  421. &iwl_dbgfs_##name##_ops)) \
  422. goto err; \
  423. } while (0)
  424. #define MVM_DEBUGFS_ADD_FILE_VIF(name, parent, mode) do { \
  425. if (!debugfs_create_file(#name, mode, parent, vif, \
  426. &iwl_dbgfs_##name##_ops)) \
  427. goto err; \
  428. } while (0)
  429. /* Device wide debugfs entries */
  430. MVM_DEBUGFS_WRITE_FILE_OPS(tx_flush);
  431. MVM_DEBUGFS_WRITE_FILE_OPS(sta_drain);
  432. MVM_DEBUGFS_READ_WRITE_FILE_OPS(sram);
  433. MVM_DEBUGFS_READ_FILE_OPS(stations);
  434. MVM_DEBUGFS_READ_FILE_OPS(bt_notif);
  435. MVM_DEBUGFS_WRITE_FILE_OPS(power_down_allow);
  436. MVM_DEBUGFS_WRITE_FILE_OPS(power_down_d3_allow);
  437. MVM_DEBUGFS_WRITE_FILE_OPS(fw_restart);
  438. /* Interface specific debugfs entries */
  439. MVM_DEBUGFS_READ_FILE_OPS(mac_params);
  440. int iwl_mvm_dbgfs_register(struct iwl_mvm *mvm, struct dentry *dbgfs_dir)
  441. {
  442. char buf[100];
  443. mvm->debugfs_dir = dbgfs_dir;
  444. MVM_DEBUGFS_ADD_FILE(tx_flush, mvm->debugfs_dir, S_IWUSR);
  445. MVM_DEBUGFS_ADD_FILE(sta_drain, mvm->debugfs_dir, S_IWUSR);
  446. MVM_DEBUGFS_ADD_FILE(sram, mvm->debugfs_dir, S_IWUSR | S_IRUSR);
  447. MVM_DEBUGFS_ADD_FILE(stations, dbgfs_dir, S_IRUSR);
  448. MVM_DEBUGFS_ADD_FILE(bt_notif, dbgfs_dir, S_IRUSR);
  449. MVM_DEBUGFS_ADD_FILE(power_down_allow, mvm->debugfs_dir, S_IWUSR);
  450. MVM_DEBUGFS_ADD_FILE(power_down_d3_allow, mvm->debugfs_dir, S_IWUSR);
  451. MVM_DEBUGFS_ADD_FILE(fw_restart, mvm->debugfs_dir, S_IWUSR);
  452. /*
  453. * Create a symlink with mac80211. It will be removed when mac80211
  454. * exists (before the opmode exists which removes the target.)
  455. */
  456. snprintf(buf, 100, "../../%s/%s",
  457. dbgfs_dir->d_parent->d_parent->d_name.name,
  458. dbgfs_dir->d_parent->d_name.name);
  459. if (!debugfs_create_symlink("iwlwifi", mvm->hw->wiphy->debugfsdir, buf))
  460. goto err;
  461. return 0;
  462. err:
  463. IWL_ERR(mvm, "Can't create the mvm debugfs directory\n");
  464. return -ENOMEM;
  465. }
  466. void iwl_mvm_vif_dbgfs_register(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
  467. {
  468. struct dentry *dbgfs_dir = vif->debugfs_dir;
  469. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  470. char buf[100];
  471. if (!dbgfs_dir)
  472. return;
  473. mvmvif->dbgfs_dir = debugfs_create_dir("iwlmvm", dbgfs_dir);
  474. mvmvif->dbgfs_data = mvm;
  475. if (!mvmvif->dbgfs_dir) {
  476. IWL_ERR(mvm, "Failed to create debugfs directory under %s\n",
  477. dbgfs_dir->d_name.name);
  478. return;
  479. }
  480. MVM_DEBUGFS_ADD_FILE_VIF(mac_params, mvmvif->dbgfs_dir,
  481. S_IRUSR);
  482. /*
  483. * Create symlink for convenience pointing to interface specific
  484. * debugfs entries for the driver. For example, under
  485. * /sys/kernel/debug/iwlwifi/0000\:02\:00.0/iwlmvm/
  486. * find
  487. * netdev:wlan0 -> ../../../ieee80211/phy0/netdev:wlan0/iwlmvm/
  488. */
  489. snprintf(buf, 100, "../../../%s/%s/%s/%s",
  490. dbgfs_dir->d_parent->d_parent->d_name.name,
  491. dbgfs_dir->d_parent->d_name.name,
  492. dbgfs_dir->d_name.name,
  493. mvmvif->dbgfs_dir->d_name.name);
  494. mvmvif->dbgfs_slink = debugfs_create_symlink(dbgfs_dir->d_name.name,
  495. mvm->debugfs_dir, buf);
  496. if (!mvmvif->dbgfs_slink)
  497. IWL_ERR(mvm, "Can't create debugfs symbolic link under %s\n",
  498. dbgfs_dir->d_name.name);
  499. return;
  500. err:
  501. IWL_ERR(mvm, "Can't create debugfs entity\n");
  502. }
  503. void iwl_mvm_vif_dbgfs_clean(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
  504. {
  505. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  506. debugfs_remove(mvmvif->dbgfs_slink);
  507. mvmvif->dbgfs_slink = NULL;
  508. debugfs_remove_recursive(mvmvif->dbgfs_dir);
  509. mvmvif->dbgfs_dir = NULL;
  510. }